sg_expand_basic_building = {
	category = sgcat_tutorial

	trigger = {
		any_scope_building = {
			is_under_construction = no
			is_farm_building = yes
		}
	}
	
	on_start = {
		start_tutorial_lesson = { tutorial_lesson = lesson_journal }
		
		if = {
			limit = {
				market_capital = {
					owner = ROOT
				}
			}
			save_scope_as = tutorial_state_target
		}
		else = {
			capital = {
				save_scope_as = tutorial_state_target
			}
		}

		if = {
			limit = {
				scope:tutorial_state_target = {
					any_scope_building = {
						is_under_construction = no
						is_farm_building = yes
					}					
				}
			}
			scope:tutorial_state_target = {
				random_scope_building = {
					limit = {	
						is_under_construction = no
						is_farm_building = yes
					}
					save_scope_as = tutorial_building_target
				}			
			}
		}
		else_if = {
			limit = {
				any_scope_state = {
					is_incorporated = yes
					any_scope_building = {
						is_under_construction = no
						is_farm_building = yes
					}					
				}				
			}
			
			random_scope_state = {
				limit = { 
					is_incorporated = yes
					any_scope_building = {
						is_under_construction = no
						is_farm_building = yes
					}
				}
				
				random_scope_building = {
					limit = {	
						is_under_construction = no
						is_farm_building = yes
					}
					save_scope_as = tutorial_building_target
				}					
			}			
		}
		else = {
			random_scope_building = {
				limit = {	
					is_under_construction = no
					is_farm_building = yes
				}
				save_scope_as = tutorial_building_target
			}
		}
		
		add_journal_entry = {
			type = je_tutorial_expand_basic_building
			objective_subgoal = sg_expand_basic_building
			target = scope:tutorial_building_target
		}			
	}
}

# Fix Budget Deficit
sg_fix_budget_deficit = {
	category = sgcat_tutorial
	is_repeatable = no

	unlocking_subgoals_all = {
		sg_expand_productive_building
	}

	trigger = {
		gold_reserves = 0
		weekly_net_fixed_income <= -1000 # Do not trigger this based on a tiny deficit that will self-correct
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_fix_budget_deficit
			objective_subgoal = sg_fix_budget_deficit
		}	
	}
}

# Change Production Method
sg_change_production_method = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_expand_basic_building
	}

	trigger = {
		any_scope_state = {
			OR = {
				AND = {
					can_activate_production_method = {
						building_type = building_rye_farm	
						production_method = pm_apple_orchards
					}	
				}
				AND = {
					can_activate_production_method = {
						building_type = building_wheat_farm	
						production_method = pm_citrus_orchards
					}
				}
				AND = {	
					can_activate_production_method = {
						building_type = building_rice_farm	
						production_method = pm_fig_orchards
					}
				}
				AND = {
					can_activate_production_method = {
						building_type = building_maize_farm	
						production_method = pm_citrus_orchards
					}
				}
				AND = {	
					can_activate_production_method = {
						building_type = building_millet_farm	
						production_method = pm_fig_orchards
					}
				}					
				AND = {
					can_activate_production_method = {
						building_type = building_logging_camp
						production_method = pm_saw_mills
					}
					market = { 
						mg:tools = { market_goods_delta >= 20 } 
					}	
				}
				AND = {
					can_activate_production_method = {
						building_type = building_livestock_ranch
						production_method = pm_butchering_tools
					}
					market = { 
						mg:tools = { market_goods_delta >= 10 } 
					}	
				}					
			}
		}			
	}
	
	on_start = {
		if = {
			limit = {
				market_capital = {
					owner = ROOT
				}
			}
			market_capital = {
				save_scope_as = tutorial_state_target
			}
		}
		else = {
			capital = {
				save_scope_as = tutorial_state_target
			}
		}

		if = {
			limit = {
				scope:tutorial_state_target = {
					can_activate_production_method = {
						building_type = building_rye_farm	
						production_method = pm_apple_orchards
					}						
				}
			}
			
			scope:tutorial_state_target = {
				b:building_rye_farm = { save_scope_as = tutorial_building_target }
			}					
		}	
		else_if = {
			limit = {
				scope:tutorial_state_target = {
					can_activate_production_method = {
						building_type = building_wheat_farm	
						production_method = pm_citrus_orchards
					}					
				}
			}
			
			scope:tutorial_state_target = {
				b:building_wheat_farm = { save_scope_as = tutorial_building_target }
			}				
		}
		else_if = {
			limit = {
				scope:tutorial_state_target = {
					can_activate_production_method = {
						building_type = building_maize_farm	
						production_method = pm_citrus_orchards
					}						
				}
			}
			
			scope:tutorial_state_target = {
				b:building_maize_farm = { save_scope_as = tutorial_building_target }
			}			
		}	
		else_if = {
			limit = {
				scope:tutorial_state_target = {
					can_activate_production_method = {
						building_type = building_rice_farm	
						production_method = pm_fig_orchards
					}					
				}
			}
			
			scope:tutorial_state_target = {
				b:building_rice_farm = { save_scope_as = tutorial_building_target }
			}					
		}
		else_if = {
			limit = {
				scope:tutorial_state_target = {
					can_activate_production_method = {
						building_type = building_millet_farm	
						production_method = pm_fig_orchards
					}					
				}
			}
			
			scope:tutorial_state_target = {
				b:building_millet_farm = { save_scope_as = tutorial_building_target }
			}					
		}			
		else_if = {
			limit = {
				scope:tutorial_state_target = {
					can_activate_production_method = {
						building_type = building_livestock_ranch
						production_method = pm_butchering_tools
					}
					market = { mg:tools = { market_goods_delta >= 10 } }						
				}
			}
			
			scope:tutorial_state_target = {
				b:building_livestock_ranch = { save_scope_as = tutorial_building_target }
			}					
		}	
		else_if = {
			limit = {
				scope:tutorial_state_target = {
					can_activate_production_method = {
						building_type = building_logging_camp
						production_method = pm_saw_mills
					}
					market = { mg:tools = { market_goods_delta >= 20 } }						
				}
			}
			
			scope:tutorial_state_target = {
				b:building_logging_camp = { save_scope_as = tutorial_building_target }
			}					
		}	
		else_if = {
			limit = {
				any_scope_state = {
					can_activate_production_method = {
						building_type = building_rye_farm	
						production_method = pm_apple_orchards 
					}					
				}
			}
			
			random_scope_state = {
				limit = {
					can_activate_production_method = {
						building_type = building_rye_farm	
						production_method = pm_apple_orchards 
					}					
				}
				
				b:building_rye_farm = { save_scope_as = tutorial_building_target }
			}					
		}	
		else_if = {
			limit = {
				any_scope_state = {
					can_activate_production_method = {
						building_type = building_wheat_farm	
						production_method = pm_citrus_orchards 
					}					
				}
			}
			
			random_scope_state = {
				limit = {
					can_activate_production_method = {
						building_type = building_wheat_farm	
						production_method = pm_citrus_orchards 
					}						
				}
				
				b:building_wheat_farm = { save_scope_as = tutorial_building_target }
			}				
		}
		else_if = {
			limit = {
				any_scope_state = {
					can_activate_production_method = {
						building_type = building_maize_farm	
						production_method = pm_citrus_orchards 
					}						
				}
			}
			
			random_scope_state = {
				limit = {
					can_activate_production_method = {
						building_type = building_maize_farm	
						production_method = pm_citrus_orchards 
					}					
				}
				
				b:building_maize_farm = { save_scope_as = tutorial_building_target }
			}			
		}	
		else_if = {
			limit = {
				any_scope_state = {
					can_activate_production_method = {
						building_type = building_rice_farm	
						production_method = pm_fig_orchards 
					}					
				}
			}
			
			random_scope_state = {
				limit = {
					can_activate_production_method = {
						building_type = building_rice_farm	
						production_method = pm_fig_orchards 
					}						
				}
				
				b:building_rice_farm = { save_scope_as = tutorial_building_target }
			}					
		}
		else_if = {
			limit = {
				any_scope_state = {
					can_activate_production_method = {
						building_type = building_millet_farm	
						production_method = pm_fig_orchards 
					}					
				}
			}
			
			random_scope_state = {
				limit = {
					can_activate_production_method = {
						building_type = building_millet_farm	
						production_method = pm_fig_orchards 
					}						
				}
				
				b:building_millet_farm = { save_scope_as = tutorial_building_target }
			}					
		}			
		else_if = {
			limit = {
				any_scope_state = {
					can_activate_production_method = {
						building_type = building_livestock_ranch
						production_method = pm_butchering_tools
					}
					market = { mg:tools = { market_goods_delta >= 10 } }						
				}
			}
			
			random_scope_state = {
				limit = {
					can_activate_production_method = {
						building_type = building_livestock_ranch
						production_method = pm_butchering_tools
					}
					market = { mg:tools = { market_goods_delta >= 10 } }						
				}
				
				b:building_livestock_ranch = { save_scope_as = tutorial_building_target }
			}					
		}	
		else_if = {
			limit = {
				any_scope_state = {
					can_activate_production_method = {
						building_type = building_logging_camp
						production_method = pm_saw_mills
					}
					market = { mg:tools = { market_goods_delta >= 20 } }						
				}
			}
			
			random_scope_state = {
				limit = {
					can_activate_production_method = {
						building_type = building_logging_camp
						production_method = pm_saw_mills
					}
					market = { mg:tools = { market_goods_delta >= 20 } }						
				}
				
				b:building_logging_camp = { save_scope_as = tutorial_building_target }
			}					
		}			
		
		add_journal_entry = {
			type = je_tutorial_change_production_method
			objective_subgoal = sg_change_production_method
			target = scope:tutorial_building_target
		}	
	}
}

# Expand Productive Building
sg_expand_productive_building = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_change_production_method
	}
	
	trigger = {
		any_scope_building = {
			is_buildable = yes
			is_under_construction = no
			is_government_funded = no
			is_subsidized = no
			earnings >= 8.0
		}
	}
	
	on_start = {
		if = {
			limit = {
				market_capital = {
					owner = ROOT
				}
			}
			save_scope_as = tutorial_state_target
		}
		else = {
			capital = {
				save_scope_as = tutorial_state_target
			}
		}

		if = {
			limit = {
				scope:tutorial_state_target = {
					any_scope_building = {
						is_buildable = yes
						is_under_construction = no
						is_government_funded = no
						is_subsidized = no
						earnings >= 8.0
					}
				}
			}
			
			scope:tutorial_state_target = {
				random_scope_building = {
					limit = {
						is_buildable = yes
						is_under_construction = no
						is_government_funded = no
						is_subsidized = no
						earnings >= 8.0
					}
					
					save_scope_as = tutorial_building_target 
				}				
			}				
		}				
		else_if = {
			limit = {
				any_scope_building = {
					is_buildable = yes
					is_under_construction = no
					is_government_funded = no
					is_subsidized = no
					earnings >= 8.0
				}
			}
			
			random_scope_building = {
				limit = {
					is_buildable = yes
					is_under_construction = no
					is_government_funded = no
					is_subsidized = no
					earnings >= 8.0
				}
				
				save_scope_as = tutorial_building_target 
			}				
		}		
		
		add_journal_entry = {
			type = je_tutorial_expand_productive_building
			objective_subgoal = sg_expand_productive_building
			target = scope:tutorial_building_target
		}	
	}
}

# Fix Unproductive Building
sg_fix_unproductive_building = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_expand_productive_building
	}

	trigger = {
		any_scope_state = {
			NOT = { state_infrastructure_balance < 0 }
			any_scope_building = {
				is_government_funded = no
				NOR = { 
					is_building_type = building_urban_center
					is_building_type = building_trade_center
					is_building_group = bg_monuments_hidden
				}
				is_under_construction = no
				is_subsidized = no
				is_subsistence_building = no
				earnings < 4.5
			}
		}
	}
	
	on_start = {
		if = {
			limit = {
				market_capital = {
					owner = ROOT
				}
			}
			save_scope_as = tutorial_state_target
		}
		else = {
			capital = {
				save_scope_as = tutorial_state_target
			}
		}
		
		if = {
			limit = {
				scope:tutorial_state_target = {
					any_scope_building = {
						NOT = { state_infrastructure_balance < 0 }
					}
					any_scope_building = {
						is_government_funded = no
						NOR = { 
							is_building_type = building_urban_center
							is_building_type = building_trade_center
							is_building_group = bg_monuments_hidden 
						}
						is_under_construction = no
						is_subsidized = no
						is_subsistence_building = no
						earnings < 4.5
					}
				}
			}
			
			scope:tutorial_state_target = {
				random_scope_building = {
					limit = {
						is_government_funded = no
						NOR = { 
							is_building_type = building_urban_center
							is_building_type = building_trade_center
							is_building_group = bg_monuments_hidden
						}
						is_under_construction = no
						is_subsidized = no
						is_subsistence_building = no
						earnings < 4.5
					}
					
					save_scope_as = tutorial_building_target 
				}				
			}				
		}				
		else_if = {
			limit = {
				any_scope_building = {
					is_government_funded = no
					NOR = { 
						is_building_type = building_urban_center
						is_building_type = building_trade_center
						is_building_group = bg_monuments_hidden
					}
					is_under_construction = no
					is_subsidized = no
					is_subsistence_building = no
					earnings < 4.5
				}
			}
			
			random_scope_building = {
				limit = {
					is_government_funded = no
					NOR = { 
						is_building_type = building_urban_center
						is_building_type = building_trade_center
						is_building_group = bg_monuments_hidden
					}
					is_under_construction = no
					is_subsidized = no
					is_subsistence_building = no
					earnings < 4.5
				}
				
				save_scope_as = tutorial_building_target 
			}				
		}
		
		add_journal_entry = {
			type = je_tutorial_fix_unproductive_building
			objective_subgoal = sg_fix_unproductive_building
			target = scope:tutorial_building_target
		}	
	}
}

# Bolster an Interest Group
sg_promote_ig = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_improve_consumer_goods_access
	}

	on_start = {
		add_journal_entry = {
			type = je_tutorial_promote_ig
			objective_subgoal = sg_promote_ig
		}	
	}
}

# Grow GDP
sg_grow_gdp = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_fix_unproductive_building
		sg_expand_productive_building
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_grow_gdp
			objective_subgoal = sg_grow_gdp
		}	
	}
}

# Improve Market Access by Decree
sg_increase_market_access_by_decree = {
	category = sgcat_tutorial

	unlocking_subgoals_any = {
		sg_expand_productive_building
	}

	trigger = {
		any_scope_state = {
			state_infrastructure_balance < 0
		}
	}

	on_start = {
		random_scope_state = {
			limit = {
				state_infrastructure_balance < 0
			}
			save_scope_as = tutorial_improve_market_state
		}

		add_journal_entry = {
			type = je_tutorial_increase_market_access_by_decree
			objective_subgoal = sg_increase_market_access_by_decree
			target = scope:tutorial_improve_market_state
		}
	}
}

# Improve Market Access by railways
sg_improve_market_access_with_railways = {
	category = sgcat_tutorial

	unlocking_subgoals_any = {
		sg_increase_market_access_by_decree
	}

	trigger = {
		any_scope_state = {
			state_infrastructure_balance < 0
		}
		has_technology_researched = railways
	}

	on_start = {
		random_scope_state = {
			limit = {
				state_infrastructure_balance < 0
			}
			save_scope_as = tutorial_improve_market_access_with_railways
		}

		add_journal_entry = {
			type = je_tutorial_improve_market_access_with_railways
			objective_subgoal = sg_improve_market_access_with_railways
			target = scope:tutorial_improve_market_access_with_railways
		}
	}
}

# Increase Immigration
sg_increase_immigration = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_increase_market_access_by_decree
	}

	trigger = {
		any_scope_state = {
			any_scope_building = {
				has_failed_hires = yes
			}
			available_jobs > 10000
		}
	}
	
	on_start = {
		random_scope_state = {
			limit = {
				any_scope_building = {
					has_failed_hires = yes
				}
				available_jobs > 10000
			}
			save_scope_as = tutorial_increase_immigration
		}

		add_journal_entry = {
			type = je_tutorial_increase_immigration
			objective_subgoal = sg_increase_immigration
			target = scope:tutorial_increase_immigration
		}
	}
}

# Spend Investment Pool
sg_expend_investment_pool = {
	category = sgcat_tutorial

	unlocking_subgoals_any = {
		sg_improve_market_access_with_railways
	}

	trigger = {
		investment_pool >= 10000
		NOR = {
			has_law = law_type:law_command_economy
			has_law = law_type:law_traditionalism
		}
	}

	on_start = {
		add_journal_entry = {
			type = je_tutorial_expend_investment_pool
			objective_subgoal = sg_expend_investment_pool
		}
	}
}

# Establish Trade Route
sg_establish_trade_route = {
	category = sgcat_tutorial

	unlocking_subgoals_any = {
		sg_expand_productive_building
	}
	
	# low chance to trigger each day unless sg_fix_unproductive_building is complete
	chance = {
		value = 0.02
		if = {
			limit = { has_completed_subgoal = sg_fix_unproductive_building }
			add = 1
		}
	}

	trigger = {
		market = {
			custom_tooltip = {
				text = suppress_localization_errors
				any_market_goods = {
					is_tradeable = yes
					market_goods_has_goods_shortage = yes
					root = {
						can_establish_any_import_route = prev.goods
					}
				}
			}
		}
	}
	
	on_start = {
		market = {
			ordered_market_goods = {
				limit = {
					is_tradeable = yes
					market_goods_has_goods_shortage = yes
					root = {
						can_establish_any_import_route = prev.goods
					}
				}
				order_by = { # reverse order
					value = 100
					subtract = num_import_trade_routes
				}
				save_scope_as = tutorial_establish_trade_route_goods
			}
		}

		add_journal_entry = {
			type = je_tutorial_establish_trade_route
			objective_subgoal = sg_establish_trade_route
			target = scope:tutorial_establish_trade_route_goods
		}
	}
}

# Improve Supply Network
sg_improve_supply_network = {
	category = sgcat_tutorial

	unlocking_subgoals_any = {
		sg_establish_trade_route
	}

	trigger = {
		supply_network_strength < 1
	}

	on_start = {
		add_journal_entry = {
			type = je_tutorial_improve_supply_network
			objective_subgoal = sg_improve_supply_network
		}
	}
}

# Improve Access to Consumer Goods
sg_improve_consumer_goods_access = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_establish_trade_route
	}

	trigger = {
		market_capital.market = {	
			OR = {
				mg:grain = { 
					market_goods_pricier > 0.25 
				}
				mg:fish = { 
					market_goods_pricier > 0.25 
				}
				mg:fabric = { 
					market_goods_pricier > 0.25 
				}
			}
		}
	}
	
	on_start = {
		market_capital.market = {
			if = {
				limit = {
					mg:grain = { 
						market_goods_pricier > 0.25 
					}
				}		
				mg:grain = { save_scope_as = tut_consumer_good_expensive }
			}
			else_if = {
				limit = {
					mg:fish = { 
						market_goods_pricier > 0.25
					}
				}		
				mg:fish = { save_scope_as = tut_consumer_good_expensive }
			}
			else_if = {
				limit = {
					mg:fabric = { 
						market_goods_pricier > 0.25
					}
				}	
				mg:fabric = { save_scope_as = tut_consumer_good_expensive }
			}
		}
		add_journal_entry = {
			type = je_tutorial_improve_consumer_goods_access
			objective_subgoal = sg_improve_consumer_goods_access
			target = scope:tut_consumer_good_expensive
		}
	}
}

# Make Interest Group Happy
sg_make_interest_group_happy = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_promote_ig
	}

	trigger = {
		any_interest_group = {
			ig_approval < 2 
			is_marginal = no
		}
	}
	
	on_start = {
		random_interest_group = {
			limit = {
				ig_approval < 2
				is_marginal = no
			}
			save_scope_as = tut_unhappy_ig
		}

		add_journal_entry = {
			type = je_tutorial_make_interest_group_happy
			objective_subgoal = sg_make_interest_group_happy
			target = scope:tut_unhappy_ig
		}
	}
}

sg_enact_institution_law = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_promote_ig
	}

	trigger = {
		or = {
			and = {
				has_law = law_type:law_no_home_affairs
			}
			and = {
				has_law = law_type:law_no_health_system
			}
			and = {
				has_law = law_type:law_no_police
			}
			and = {
				has_law = law_type:law_no_social_security
			}
			and = {
				has_law = law_type:law_no_schools
			}
			and = {
				has_law = law_type:law_no_colonial_affairs
			}
		}
	}
	
	on_start = {
		if = {
			limit = {
				has_law = law_type:law_no_schools
			}
			law_type:law_no_schools = {
				save_scope_as = tut_institution_lawtype
			}
		}

		else_if = {
			limit = {
				has_law = law_type:law_no_health_system
			}
			law_type:law_no_health_system = {
				save_scope_as = tut_institution_lawtype
			}
		}

		else_if = {
			limit = {
				has_law = law_type:law_no_police
			}
			law_type:law_no_police = {
				save_scope_as = tut_institution_lawtype
			}
		}

		else_if = {
			limit = {
				has_law = law_type:law_no_home_affairs
			}
			law_type:law_no_home_affairs = {
				save_scope_as = tut_institution_lawtype
			}
		}

		else_if = {
			limit = {
				has_law = law_type:law_no_social_security
			}
			law_type:law_no_social_security = {
				save_scope_as = tut_institution_lawtype
			}
		}

		else_if = {
			limit = {
				has_law = law_type:law_no_colonial_affairs
			}
			law_type:law_no_colonial_affairs = {
				save_scope_as = tut_institution_lawtype
			}
		}

		add_journal_entry = {
			type = je_tutorial_enact_institution_law
			objective_subgoal = sg_enact_institution_law
			target = scope:tut_institution_lawtype
		}
	}
}

# Reform Government
sg_reform_government = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_promote_ig
	}

	trigger = {
		government_legitimacy <= 40
	}
	
	on_start = {		
		add_journal_entry = {
			type = je_tutorial_reform_government
			objective_subgoal = sg_reform_government
		}
	}
}

# Increase Relations
sg_increase_relations = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_enact_institution_law
		sg_reform_government
	}

	trigger = {
		trigger_if = {
			any_country = {
				capital.region = {
					any_scope_interest_marker = {
						owner = root
					}
				}
				NOT = { this = ROOT }
				country_rank >= rank_value:major_power
			}
		}

		trigger_else_if = {
			any_country = {
				has_attitude = {
					who = ROOT
					attitude >= cautious
				}
				country_rank >= rank_value:major_power
			}
		}

		trigger_else_if = {
			any_country = {
				country_rank >= rank_value:major_power
			}
		}
	}
	
	on_start = {
		if = {
			random_country = {
				limit = {
					capital.region = {
						any_scope_interest_marker = {
							owner = root
						}
					}
					NOT = { this = ROOT }
					country_rank >= rank_value:major_power
				}
				save_scope_as = tut_increase_relations
			}
		}

		else_if = {
			random_country = {
				limit = {
					has_attitude = { 
						who = ROOT
						attitude >= cautious
					}
					country_rank >= rank_value:major_power
				}
				save_scope_as = tut_increase_relations
			}
		}

		else_if = {
			random_country = {
				limit = {
					country_rank >= rank_value:major_power
				}
				save_scope_as = tut_increase_relations
			}
		}
		
		add_journal_entry = {
			type = je_tutorial_increase_relations
			objective_subgoal = sg_increase_relations
			target = scope:tut_increase_relations
		}
	}
}

# Improve Rank
sg_improve_rank = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_increase_relations
	}

	# low chance to trigger each day unless sg_declare_an_interest is complete
	chance = {
		value = 0.02
		if = {
			limit = { has_completed_subgoal = sg_declare_an_interest }
			add = 1
		}
	}

	trigger = {
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_improve_rank
			objective_subgoal = sg_improve_rank
		}
	}
}

# Prevent a Revolution
sg_prevent_revolution = { #currently code bug displays trigger wrong
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_make_interest_group_happy
	}

	trigger = {
		any_civil_war = {
			civil_war_progress >= 0.15
			is_civil_war_type = revolution
		}
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_prevent_revolution
			objective_subgoal = sg_prevent_revolution
		}
	}
}

# Earn Obligation
sg_earn_obligation = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_increase_relations
	}

	trigger = {
		NOT = {
			any_country = { 
				owes_obligation_to = root
			}
		}
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_earn_obligation
			objective_subgoal = sg_earn_obligation
			target = scope:tut_earn_obligation
		}
	}
}

# Expand Military
sg_expand_military = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_declare_an_interest
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_expand_military
			objective_subgoal = sg_expand_military
		}
	}
}

# Increase Command Limit
sg_recruit_promote_commander = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_expand_military
	}

	trigger = {	
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_recruit_promote_commander
			objective_subgoal = sg_recruit_promote_commander
			target = scope:tut_command_commander
		}
	}
}

# Mobilize General
sg_mobilize_army = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_recruit_promote_commander
	}

	trigger = {
		is_at_war = yes
		any_scope_character = {
			has_role = general
			is_mobilized = no
		}
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_mobilize_army
			objective_subgoal = sg_mobilize_army
		}
	}
}

# Send General to Front
sg_send_general_to_front = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_mobilize_army
	}

	trigger = {	
		is_at_war = yes
		any_scope_character = {
			has_role = general
			is_mobilized = yes
			is_on_front = NO
		}
	}
	
	on_start = {
		random_scope_character = { 
			limit = {
				has_role = general
				is_mobilized = yes
				is_on_front = no
			}
			save_scope_as = tut_send_general_to_front
		}

		add_journal_entry = {
			type = je_tutorial_send_general_to_front
			objective_subgoal = sg_send_general_to_front
			target = scope:tut_send_general_to_front
		}
	}
}

# Convoy Raiding
sg_convoy_raiding = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_recruit_promote_commander
	}

	trigger = {	
		is_at_war = yes
		any_scope_character = {
			has_role = admiral
			NOT = { has_commander_order = raid_convoys }
		}
	}
	
	on_start = {
		random_scope_character = { 
			limit = {
				has_role = admiral
				NOT = { has_commander_order = raid_convoys }
			}
			save_scope_as = tut_convoy_raiding
		}
		
		add_journal_entry = {
			type = je_tutorial_convoy_raiding
			objective_subgoal = sg_convoy_raiding
			target = scope:tut_convoy_raiding
		}
	}
}

# Recover From Default
sg_recover_from_default = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
	}

	trigger = {
		in_default = yes
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_recover_from_default
			objective_subgoal = sg_recover_from_default
		}
	}
}

# Start Diplomatic Play
sg_start_diplomatic_play = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_recruit_promote_commander
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_start_diplomatic_play
			objective_subgoal = sg_start_diplomatic_play
		}
	}
}

# Is Target in Diplomatic Play
sg_is_play_target = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_declare_an_interest
	}

	trigger = {
		is_diplomatic_play_target = yes
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_is_play_target
			objective_subgoal = sg_is_play_target
		}
	}
}

# Fix Capacity Deficit
sg_capacity_deficit = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
	}

	trigger = {
		OR = {
			bureaucracy < -10
			authority < -10
			influence < -10
		}
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_capacity_deficit
			objective_subgoal = sg_capacity_deficit
		}
	}
}

sg_invest_into_an_institution = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_enact_institution_law
	}
	
	trigger = {
		OR = {
			institution:institution_schools = {
				investment < investment_max
			}
			institution:institution_health_system = {
				investment < investment_max
			}
			institution:institution_police = {
				investment < investment_max
			}
			institution:institution_social_security = {
				investment < investment_max
			}
			institution:institution_workplace_safety = {
				investment < investment_max
			}
			institution:institution_home_affairs = {
				investment < investment_max
			}
			institution:institution_colonial_affairs = {
				investment < investment_max
			}
		}
	}
	
	on_start = {
		if = {
			limit = {
				institution:institution_schools = {
					investment < investment_max
				}
			}
			institution:institution_schools = {
				save_scope_as = tut_institution
			}
		}

		else_if = {
			limit = {
				institution:institution_health_system = {
					investment < investment_max
				}
			}
			institution:institution_health_system = {
				save_scope_as = tut_institution
			}
		}

		else_if = {
			limit = {
				institution:institution_police = {
					investment < investment_max
				}
			}
			institution:institution_police = {
				save_scope_as = tut_institution
			}
		}

		else_if = {
			limit = {
				institution:institution_social_security = {
					investment < investment_max
				}
			}
			institution:institution_social_security = {
				save_scope_as = tut_institution
			}
		}

		else_if = {
			limit = {
				institution:institution_workplace_safety = {
					investment < investment_max
				}
			}
			institution:institution_workplace_safety = {
				save_scope_as = tut_institution
			}
		}

		else_if = {
			limit = {
				institution:institution_home_affairs = {
					investment < investment_max
				}
			}
			institution:institution_home_affairs = {
				save_scope_as = tut_institution
			}
		}
		
		else_if = {
			limit = {
				institution:institution_colonial_affairs = {
					investment < investment_max
				}
			}
			institution:institution_colonial_affairs = {
				save_scope_as = tut_institution
			}
		}
		
		add_journal_entry = {
			type = je_tutorial_invest_into_an_institution
			objective_subgoal = sg_invest_into_an_institution
			target = scope:tut_institution
		}
	}
}

# Incorporate State
sg_incorporate_state = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_invest_into_an_institution
	}

	trigger = {
		any_scope_state = {
			is_incorporated = no
			is_under_colonization = no
		}
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_incorporate_state
			objective_subgoal = sg_incorporate_state
		}
	}
}

# Colonize Region
sg_colonize_state = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_declare_an_interest
	}

	on_start = {
		add_journal_entry = {
			type = je_tutorial_colonize_state
			objective_subgoal = sg_colonize_state
		}
	}
}

# Make Peace
sg_make_peace = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_send_general_to_front
	}

	trigger = {
		is_at_war = yes
	}

	on_start = {
		add_journal_entry = {
			type = je_tutorial_make_peace
			objective_subgoal = sg_make_peace
		}
	}
}

# Reach end date
sg_reach_end_date = {
	category = sgcat_tutorial
	
	unlocking_subgoals_all = {
		sg_make_peace
	}

	on_start = {
		add_journal_entry = {
			type = je_tutorial_reach_end_date
			objective_subgoal = sg_reach_end_date
		}
	}
}

# Research Technology
sg_research_technology = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
	}

	trigger = {
		NOT = { is_researching_technology = any }
		has_researchable_technology = yes
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_research_technology
			objective_subgoal = sg_research_technology
		}
	}
}

# Declare an Interest
sg_declare_an_interest = {
	category = sgcat_tutorial
	
	unlocking_subgoals_any = {
		sg_increase_relations
	}

	trigger = {	
		has_decreasing_interests = NO
		num_declared_interests < max_num_declared_interests
	}
	
	on_start = {
		add_journal_entry = {
			type = je_tutorial_declare_an_interest
			objective_subgoal = sg_declare_an_interest
			target = scope:tut_declare_interest
		}
	}
}