﻿# 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
					}
				}
			}
		}
	}
}

# 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
		}

		### GAME RULE: DE JURE EMPIRES ###
		if = {
			limit = { NOT = { has_game_rule = default_empires } }
			mgr_empires_effect = yes
		}

		### GAME RULE: GOVERNMENTS ###
		#Ideally we would do this after shattered realms, but the game doesn't always recognize independent rulers until a day passes.
		if = {
			limit = { NOT = { has_game_rule = default_starting_governments } }
			every_ruler = {
				limit = { 
					OR = {
						is_independent_ruler = yes
						AND = { #Pope vassals
							liege = { has_government = theocracy_government }
							highest_held_title_tier >= tier_county
						}
					}
					OR = {
						NOT = { primary_title = { is_landless_type_title = yes } }
						NOT = { has_government = theocracy_government }
					}
				}
				randomize_government_and_holdings_effect = yes
			}
		}
		
		### GAME RULE: RANDOM REALMS ###
		### TO DO ###
		
		### GAME RULE: SHATTERED REALMS ###
		mgr_shattered_realms_effect = yes #built-in check for game rule

		### GAME RULE: RANDOM RULERS ###
		if = {
			limit = { has_game_rule = yes_random_rulers }
			mgr_randomize_rulers = yes
		}
		
		### GAME RULES FOR DOMAIN/VASSAL/KNIGHT/MAA/ETC LIMITS
		#We give every ruler a proper modifier. Needs to be re-applied when a character gains a new title
		every_ruler = { apply_limit_modifiers_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.
	}
}
