﻿# Called every January 1st
# Root does not exist
yearly_global_pulse = {
	on_actions = {
		wanggiyan_invasion_on_action # 1115
		rajasa_invasion_on_action # 1293
		liao_invasion_on_action # 916
		ahom_invasion_on_action # 1228
	}
}

wanggiyan_invasion_on_action = { # 1115
	trigger = {
		current_date > 1100.1.1
		current_date < 1200.1.1
		game_start_date < 1115.1.1
		NOT = { has_game_rule = never_wanggiyan_invasion }
		exists = title:e_wanggiyan # update compatibility - new titles in old saves return false
		title:e_wanggiyan = { is_title_created = no }
		NOT = { # is set in story
			is_target_in_global_variable_list = {
				name = historicinvasions_story_started
				target = flag:wanggiyan_story_started
			}
		}
	}
	effect = {
		random = {
			chance = 0
			modifier = {
				add = 3
				current_date > 1100.1.1
			}
			modifier = {
				add = 5
				current_date > 1110.1.1
			}
			modifier = {
				add = 15
				current_date > 1115.1.1
			}
			modifier = {
				add = 30
				current_date > 1125.1.1
			}
			debug_log = "attempting to trigger wanggiyan story soon"
			trigger_event = {
				id = wanggiyan_invasion.0001
				days = { 2 240 } # keep this smaller than 1 year if the global variable is set in event .0001
			}
		}
	}
}

rajasa_invasion_on_action = { # 1293
	trigger = {
		current_date > 1275.1.1
		current_date < 1375.1.1
		game_start_date < 1293.1.1
		NOT = { has_game_rule = never_rajasa_invasion }
		exists = title:e_rajasa # update compatibility - new titles in old saves return false
		title:e_rajasa = { is_title_created = no }
		NOT = { # is set in story
			is_target_in_global_variable_list = {
				name = historicinvasions_story_started
				target = flag:rajasa_story_started
			}
		}
	}
	effect = {
		random = {
			chance = 0
			modifier = {
				add = 3
				current_date > 1275.1.1
			}
			modifier = {
				add = 5
				current_date > 1280.1.1
			}
			modifier = {
				add = 15
				current_date > 1290.1.1
			}
			modifier = {
				add = 30
				current_date > 1310.1.1
			}
			debug_log = "attempting to trigger rajasa story soon"
			trigger_event = {
				id = rajasa_invasion.0001
				days = { 2 240 } # keep this smaller than 1 year if the global variable is set in event .0001
			}
		}
	}
}

liao_invasion_on_action = { # 916
	trigger = {
		current_date > 895.1.1
		current_date < 995.1.1
		game_start_date < 916.1.1
		NOT = { has_game_rule = never_liao_invasion }
		exists = title:e_liao # update compatibility - new titles in old saves return false
		title:e_liao = { is_title_created = no }
		NOT = { # is set in story
			is_target_in_global_variable_list = {
				name = historicinvasions_story_started
				target = flag:liao_story_started
			}
		}
	}
	effect = {
		random = {
			chance = 0
			modifier = {
				add = 3
				current_date > 895.1.1
			}
			modifier = {
				add = 5
				current_date > 905.1.1
			}
			modifier = {
				add = 15
				current_date > 915.1.1
			}
			modifier = {
				add = 30
				current_date > 925.1.1
			}
			debug_log = "attempting to trigger liao story soon"
			trigger_event = {
				id = liao_invasion.0001
				days = { 2 240 } # keep this smaller than 1 year if the global variable is set in event .0001
			}
		}
	}
}

ahom_invasion_on_action = { # 1228
	trigger = {
		current_date > 1200.1.1
		current_date < 1300.1.1
		game_start_date < 1228.1.1
		NOT = { has_game_rule = never_ahom_invasion }
		exists = title:d_ahom # update compatibility - new titles in old saves return false
		title:d_ahom = { is_title_created = no }
		NOT = { # is set in story
			is_target_in_global_variable_list = {
				name = historicinvasions_story_started
				target = flag:ahom_story_started
			}
		}
	}
	effect = {
		random = {
			chance = 0
			modifier = {
				add = 3
				current_date > 1200.1.1
			}
			modifier = {
				add = 5
				current_date > 1210.1.1
			}
			modifier = {
				add = 15
				current_date > 1225.1.1
			}
			modifier = {
				add = 30
				current_date > 1245.1.1
			}
			debug_log = "attempting to trigger ahom story soon"
			trigger_event = {
				id = ahom_invasion.0001
				days = { 2 240 } # keep this smaller than 1 year if the global variable is set in event .0001
			}
		}
	}
}