﻿# Called from code after history generation
# Empty scope
on_game_start = {
	effect = {
		### 867 - WRATH OF THE NORTHMEN ###
		#Æthelred dying (probably)
		character:33358 = {
			if = {
				limit = {
					is_alive = yes
					is_landed = yes
				}
				trigger_event = {
					id = bookmark.0001
					days = { 365 730 }
				}
			}
		}

		#Alfred the Great becoming the Great
		character:7627 = {
			if = {
				limit = {
					is_alive = yes
					is_landed = yes
				}
				trigger_event = {
					id = bookmark.0002
					days = 1800 #~5 years
				}
			}
		}

		### 867 - THE GREAT ADVENTURERS ###
		character:251187 = {
			if = {
				limit = {
					is_alive = yes
					is_landed = yes
					AND = {
						character:251180 = { is_ai = yes }
						character:251181 = {
							is_ai = yes
							is_alive = yes
						}
					}
				}
				trigger_event = {
					id = bookmark.0101
					days = { 21 35 }
				}
			}
		}

		### HRE SETUP ###
		if = {
			limit = { exists = title:e_hre.holder }
			title:e_hre.holder = {
				every_vassal = {
					limit = {
						vassal_contract_has_modifiable_obligations = yes
					}
					vassal_contract_decrease_obligation_level = feudal_government_taxes
					vassal_contract_decrease_obligation_level = feudal_government_levies
				}
			}
		}

		#Set up Visigothic Codes.
		culture:occitan = { add_innovation = innovation_visigothic_codes }
		culture:basque = { add_innovation = innovation_visigothic_codes }
		culture:aragonese = { add_innovation = innovation_visigothic_codes }
		culture:catalan = { add_innovation = innovation_visigothic_codes }

		### RELIGIOUS THINGS ###
		religion:islam_religion = { # Set up Holy Site Buildings to be buildable in Holy Sites
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_mosque_01
					}
				}
			}
		}
		
		religion:christianity_religion = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_cathedral_01
					}
				}
			}
		}
		
		faith:old_bon = { # Has already been reformed into new bon.
			set_variable = { name = has_been_reformed }
		}

		every_religion_global = {
			limit = {
				OR = {
					this = religion:hinduism_religion
					this = religion:buddhism_religion
					this = religion:jainism_religion
					this = religion:tani_religion
					this = religion:bon_religion
				}
			}
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_indian_grand_temple_01
					}
				}
			}
		}
		
		every_religion_global = {
			limit = {
				is_in_family = rf_pagan
			}
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_pagan_grand_temple_01
					}
				}
			}
		}
		
		every_religion_global = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_other_grand_temple_01
					}
				}
			}
		}
		
		###IMPERIAL MOD###
		culture:greek = { add_innovation = innovation_roman_administration }
		#Fix republic mayors becoming patricians for some reason
		every_living_character = {
			limit = {
				is_ruler = yes
				has_government = patrician_government
				can_get_patrician_government_trigger = no
			}
			if = {
				limit = {
					capital_province = {
						has_holding_type = city_holding
					}
				}
				change_government = republic_government
			}	
			else_if = {
				limit = {
					can_get_military_command_trigger = yes
				}
				change_government = military_command
			}
			else = {
				change_government = feudal_government
			}
		}
		
		every_independent_ruler = {
			limit = { has_government = imperial_government }
			imperial_government_initialise_effect = yes
		}		
		###
	}
	events = {
		
	}
}

# Like on_game_start, except it is called once the host (or player, in single player) exits the lobby. Good for anything where you need to know who the players are, or what the game rules are
on_game_start_after_lobby = {
	effect = {
		### GAME RULE: VIEW ON SAME-SEX RELATIONS
		if = {
			limit = { has_game_rule = accepted_same_sex_relations }
			game_rule_accepted_same_sex_relations_effect = yes
		}

		### GAME RULE: RANDOM RULER PLACEMENT
		if = {
			limit = { NOT = { has_game_rule = random_ruler_placement_off } }
			game_rule_random_ruler_placement_effect = yes
		}

		### GAME RULE: RANDOMIZE FAITH
		if = {
			limit = { has_game_rule = randomized_faiths_on }
			game_rule_randomize_faith_effect = yes
		}

		### GAME RULE: FAITH ACCEPTANCE
		if = {
			limit = { has_game_rule = full_faith_acceptance }
			game_rule_faith_acceptance_effect = yes
		}

		### GAME RULE: GENDER EQUALITY ###
		if = {
			limit = { has_game_rule = full_gender_equality }
			game_rule_full_gender_equality_effect = yes
		}
		else_if = {
			limit = { has_game_rule = inversed_gender_equality }
			game_rule_inversed_gender_equality_effect = yes #todo fix
		}

		### GAME RULE: SEXUALITY DISTRIBUTION ###
		if = {
			limit = { NOT = { has_game_rule = sexuality_distribution_default } }
			game_rule_sexuality_distribution_effect = yes
		}

		### ACHIEVEMENT: FROM RAGS TO RICHES
		every_player = {
			limit = { highest_held_title_tier = tier_county }
			add_achievement_global_variable = {
				VARIABLE = achievement_rags_to_riches_valid
				VALUE = yes
			}
		}
	}

	events = {
		game_rule.1000	#Autopopulate families.
		game_rule.1011	#Hungarian Migration management.
	}
}
