﻿# Called every Jan 1st
# Root does not exist
yearly_global_pulse = {
	on_actions = {
		ptt_intermezzo_seljuk_invasion_on_action
	}
}


ptt_intermezzo_seljuk_invasion_on_action = {
	trigger = { always = yes }
	effect = {
		# The Rise of the Seljuk
		if = { limit = { has_game_rule = never_seljuk_invasion } }
		else_if = { # Random Seljuk Invasion
			limit = {
				has_game_rule = random_seljuk_invasion
				NOR = {
					exists = global_var:ptt_seljuk_invasion_happened
				}
			}
			random = {
				chance = fp3_seljuk_chance_of_appearance
				modifier = {
					add = 1
					current_date > 965.1.1
				}
				modifier = {
					add = 1
					current_date > 985.1.1
				}
				modifier = {
					add = 2
					current_date > 1005.1.1
				}
				modifier = {
					factor = 0.25
					OR = {
						culture:turkish = { culture_number_of_counties = 0 }
						faith:ashari = { has_followers_trigger = no }
					}
				}
				set_global_variable = {
					name = ptt_seljuk_invasion_happened
					value = yes
				}
				debug_log = "Attempting to spawn seljuk invasion within 240 days"
				trigger_event = {
					id = fp3_story_cycle_seljuks_invasion_events.0001
					days = { 2 240 }
				}
			}
		}
		else_if = { # Historical Seljuk Invasion
			limit = {
				current_date < 1066.1.1
				current_date >= 970.1.1
				NOR = {
					exists = global_var:ptt_seljuk_invasion_happened
				}
			}
			random = {
				chance = fp3_seljuk_chance_of_appearance
				modifier = {
					add = 2
					current_date > 990.1.1
				}
				modifier = {
					add = 2
					current_date > 1010.1.1
				}
				modifier = {
					add = 15
					current_date > 1030.1.1
				}
				modifier = {
					add = 90
					current_date > 1060.1.1
				}
				modifier = {
					factor = 0.25
					OR = {
						culture:turkish = { culture_number_of_counties = 0 }
						faith:ashari = { has_followers_trigger = no }
					}
				}
				set_global_variable = {
					name = ptt_seljuk_invasion_happened
					value = yes
				}
				debug_log = "Attempting to spawn seljuk invasion within 240 days"
				trigger_event = {
					id = fp3_story_cycle_seljuks_invasion_events.0001
					days = { 2 240 }
				}
			}
		}
	}
}