namespace = tgp_dynastic_cycle

### EVENT LIST ####################################################################
## 0001 - 0020	Internal Management Events
## 0021 - 0030	Invalidation Events
## 0051 - 0060	TGP situation Intro Events
## 0061 - 0070	Realm Shattering Events
## 0071	- 0300	situation Endings
## XXXX - XXXX	Event Name Here by Author Name Here
## 9980 - 9999	Integrity Validation Tools
###################################################################################

###################################
# TGP Maintenance Events
# By Joe Parkin
###################################

scripted_trigger tgp_dynastic_cycle_0001_valid_ai_situation_char_trigger = {
	# Basic checks.
	is_ai = yes
}

tgp_dynastic_cycle.0001 = {
	hidden = yes
	scope = situation

	# If the situation ends, break the loop.
	trigger = { exists = situation:dynastic_cycle }

	immediate = {
		# Cue this event up again for the next time around.
		trigger_event = {
			id = tgp_dynastic_cycle.0001
			years = { 3 5 }
		}
	}
}

###################################
# TGP Intro Events
# By Joe Parkin
###################################

tgp_dynastic_cycle.0051 = { # BOOKMARK EVENT
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0051.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
				desc = tgp_dynastic_cycle.0051.desc.advancement
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					}
				}
				desc = tgp_dynastic_cycle.0051.desc.expansion
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
				desc = tgp_dynastic_cycle.0051.desc.conquest
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
					}
				}
				desc = tgp_dynastic_cycle.0051.desc.corruption
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_chaos
					}
				}
				desc = tgp_dynastic_cycle.0051.desc.consolidation
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= { participant_group_type = hegemon_ruler }
				}
				desc = tgp_dynastic_cycle.0051.desc.emperor
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= { participant_group_type = advancement_movement }
				}
				desc = tgp_dynastic_cycle.0051.desc.advancement_movement
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= { participant_group_type = expansion_movement }
				}
				desc = tgp_dynastic_cycle.0051.desc.expansion_movement
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= { participant_group_type = pro_hegemon_movement }
				}
				desc = tgp_dynastic_cycle.0051.desc.pro_hegemon_movement
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= { participant_group_type = conservative_movement }
				}
				desc = tgp_dynastic_cycle.0051.desc.conservative_movement
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
				}
				desc = tgp_dynastic_cycle.0051.desc.unaligned_movement
			}
			desc = tgp_dynastic_cycle.0051.desc.interloper
		}
	}
	theme = dynastic_cycle
	trigger = { # we need to prevent this from firing for all players when a new player joins in MP
		is_ai = no
		is_player_tutorial_character = no
		NOT = { has_character_flag = tgp_dynastic_cycle_intro_event_flag }
		tgp_is_hegemon_or_below_in_dynastic_cycle_trigger = yes
 	}
 	#chaos
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				situation_current_phase = situation_dynastic_cycle_phase_chaos
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_chaos
	}
	#conquest & instability
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					situation_current_phase = situation_dynastic_cycle_phase_instability
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_instability
	}
	#expansion & advancement
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_stability
	}

	cooldown = { years = 100 }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	immediate = {
		play_music_cue = mx_cue_tgp_dynastic_cycle_start
		add_character_flag = tgp_dynastic_cycle_intro_event_flag
		save_scope_value_as = {
			name = start
			value = yes
		}
	}
	option = {
		name = {
			text = tgp_dynastic_cycle.0051.a.emperor
			trigger = { title:h_china.holder ?= root }
		}
		name = {
			text = tgp_dynastic_cycle.0051.a.involved
			trigger = {
				top_participant_group:dynastic_cycle ?= {
					NOR = {
						participant_group_type = hegemon_ruler
						participant_group_type = other_rulers
					}
				}
			}
		}
		name = {
			text = tgp_dynastic_cycle.0051.a.interloper
			trigger = {
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = other_rulers
				}
			}
		}
		clicksound = "event:/DLC/FP2/SFX/UI/fp2_struggle_start_select"
	}
}
tgp_dynastic_cycle.0052 = { # JOINED MOVEMENT - Unaligned
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0052.t
	desc = {
		desc = tgp_dynastic_cycle.0052.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
				desc = tgp_dynastic_cycle.0052.desc.advancement
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					}
				}
				desc = tgp_dynastic_cycle.0052.desc.expansion
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
				desc = tgp_dynastic_cycle.0052.desc.conquest
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
					}
				}
				desc = tgp_dynastic_cycle.0052.desc.instability
			}
		}
	}
	theme = dynastic_cycle
	trigger = {
		is_ai = no
		current_date_is_start_date_trigger = no
 	}
	#conquest & instability
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					situation_current_phase = situation_dynastic_cycle_phase_instability
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_instability
	}
	#expansion & advancement
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_stability
	}

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	immediate = {
		top_participant_group:dynastic_cycle = { save_scope_as = my_movement }
		custom_tooltip = intro_event_joined_movement
	}
	option = {
		name = tgp_dynastic_cycle.0052.a
		clicksound = "event:/DLC/FP2/SFX/UI/fp2_struggle_start_select"
	}
}
tgp_dynastic_cycle.0053 = { # JOINED MOVEMENT - Expansion
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0053.t
	desc = {
		desc = tgp_dynastic_cycle.0053.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
				desc = tgp_dynastic_cycle.0053.desc.advancement
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					}
				}
				desc = tgp_dynastic_cycle.0053.desc.expansion
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
				desc = tgp_dynastic_cycle.0053.desc.conquest
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
					}
				}
				desc = tgp_dynastic_cycle.0053.desc.instability
			}
		}
	}
	theme = dynastic_cycle
	trigger = {
		is_ai = no
		current_date_is_start_date_trigger = no
 	}
	#conquest & instability
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					situation_current_phase = situation_dynastic_cycle_phase_instability
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_instability
	}
	#expansion & advancement
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_stability
	}

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	immediate = {
		top_participant_group:dynastic_cycle = { save_scope_as = my_movement }
		custom_tooltip = intro_event_joined_movement
	}
	option = {
		name = tgp_dynastic_cycle.0053.a
		clicksound = "event:/DLC/FP2/SFX/UI/fp2_struggle_start_select"
	}
}
tgp_dynastic_cycle.0054 = { # JOINED MOVEMENT - Advancement
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0054.t
	desc = {
		desc = tgp_dynastic_cycle.0054.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
				desc = tgp_dynastic_cycle.0054.desc.advancement
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					}
				}
				desc = tgp_dynastic_cycle.0054.desc.expansion
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
				desc = tgp_dynastic_cycle.0054.desc.conquest
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
					}
				}
				desc = tgp_dynastic_cycle.0054.desc.instability
			}
		}
	}
	theme = dynastic_cycle
	trigger = {
		is_ai = no
		current_date_is_start_date_trigger = no
 	}
	#conquest & instability
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					situation_current_phase = situation_dynastic_cycle_phase_instability
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_instability
	}
	#expansion & advancement
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_stability
	}

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	immediate = {
		top_participant_group:dynastic_cycle = { save_scope_as = my_movement }
		custom_tooltip = intro_event_joined_movement
	}
	option = {
		name = tgp_dynastic_cycle.0054.a
		clicksound = "event:/DLC/FP2/SFX/UI/fp2_struggle_start_select"
	}
}
tgp_dynastic_cycle.0055 = { # JOINED MOVEMENT - Pro-Hegemon
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0055.t
	desc = {
		desc = tgp_dynastic_cycle.0055.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
				desc = tgp_dynastic_cycle.0055.desc.advancement
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					}
				}
				desc = tgp_dynastic_cycle.0055.desc.expansion
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
				desc = tgp_dynastic_cycle.0055.desc.conquest
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
					}
				}
				desc = tgp_dynastic_cycle.0055.desc.instability
			}
		}
	}
	theme = dynastic_cycle
	trigger = {
		is_ai = no
		current_date_is_start_date_trigger = no
 	}
	#conquest & instability
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					situation_current_phase = situation_dynastic_cycle_phase_instability
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_instability
	}
	#expansion & advancement
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_stability
	}


	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	immediate = {
		top_participant_group:dynastic_cycle = { save_scope_as = my_movement }
		custom_tooltip = intro_event_joined_movement
	}
	option = {
		name = tgp_dynastic_cycle.0055.a
		clicksound = "event:/DLC/FP2/SFX/UI/fp2_struggle_start_select"
	}
}
tgp_dynastic_cycle.0056 = { # JOINED MOVEMENT - Conservative
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0056.t
	desc = {
		desc = tgp_dynastic_cycle.0056.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
				desc = tgp_dynastic_cycle.0056.desc.advancement
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					}
				}
				desc = tgp_dynastic_cycle.0056.desc.expansion
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
				desc = tgp_dynastic_cycle.0056.desc.conquest
			}
			triggered_desc = {
				trigger = {
					situation:dynastic_cycle = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
					}
				}
				desc = tgp_dynastic_cycle.0056.desc.instability
			}
		}
	}
	theme = dynastic_cycle
	trigger = {
		is_ai = no
		current_date_is_start_date_trigger = no
 	}
	#conquest & instability
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					situation_current_phase = situation_dynastic_cycle_phase_instability
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_instability
	}
	#expansion & advancement
	override_background = {
		trigger = { 
			situation:dynastic_cycle = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
		}
		reference = tgp_fullscreen_dynastic_cycle_stability
	}

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	immediate = {
		top_participant_group:dynastic_cycle = { save_scope_as = my_movement }
		custom_tooltip = intro_event_joined_movement
	}
	option = {
		name = tgp_dynastic_cycle.0056.a
		clicksound = "event:/DLC/FP2/SFX/UI/fp2_struggle_start_select"
	}
}
### ENTER CONQUEST - NEW DYNASTY ### 0061 - 0070 ###

tgp_dynastic_cycle.0061 = {
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0061.t
	desc = tgp_dynastic_cycle.0061.desc
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_instability }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	trigger = {
		current_date_is_start_date_trigger = no
		situation:dynastic_cycle = { situation_current_phase = situation_dynastic_cycle_phase_instability_conquest }
	}

	immediate = {
		add_character_flag = tgp_dynastic_cycle_intro_event_flag
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
		save_scope_as = mandate_claimant
		show_as_tooltip = {
			tgp_claim_mandate_of_heaven_effect = yes
		}
		custom_tooltip = dynastic_cycle_entered_conquest_tt
	}

	option = {
		name = tgp_dynastic_cycle.0061.c
		show_as_tooltip = {
			situation:dynastic_cycle = {
				situation_top_sub_region = {
					change_phase = { phase = situation_dynastic_cycle_phase_instability_conquest }
				}
			}
		}
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_end"
	}

	after = {
		every_player = {
			limit = { tgp_does_this_player_care_about_the_dynastic_cycle = yes } # Needs to be checked before the situation ends due to race condition issues
			add_to_list = player_to_notify # Making a list so stuff is tiggered after the situation ends, to make extra sure I don't break anything.
		}
		every_in_list = { # Then we *actually* notify players, making sure the situation has already ended
			list = player_to_notify
			limit = {
				NOT = { this = root }
			}
			trigger_event = tgp_dynastic_cycle.0062
		}
	}
}

tgp_dynastic_cycle.0062 = { # Notification for relevant people
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0061.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					tgp_is_hegemon_or_below_in_dynastic_cycle_trigger = yes
				}
				desc = tgp_dynastic_cycle.0062.desc.involved
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = other_rulers
					}
				}
				desc = tgp_dynastic_cycle.0062.desc.interloper
			}
			desc = tgp_dynastic_cycle.0062.desc.uninvolved
		}
	}
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_instability }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	trigger = {
		is_ai = no
		NOT = { has_character_flag = situation_phase_notification }
	}

	immediate = {
		add_character_flag = situation_phase_notification
		show_as_tooltip = {
			scope:mandate_claimant = {
				tgp_claim_mandate_of_heaven_effect = yes
			}
			situation:dynastic_cycle = {
				switch = {
					trigger = situation_current_phase
					situation_dynastic_cycle_phase_stability_expansion = {
						situation_top_sub_region = {
							change_phase = { phase = situation_dynastic_cycle_phase_stability_expansion }
						}
					}
					situation_dynastic_cycle_phase_stability_advancement = {
						situation_top_sub_region = {
							change_phase = { phase = situation_dynastic_cycle_phase_stability_advancement }
						}
					}
					situation_dynastic_cycle_phase_stability_advancement = {
						situation_top_sub_region = {
							change_phase = { phase = situation_dynastic_cycle_phase_instability_conquest }
						}
					}
				}
			}
		}
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
	}

	option = {
		name = tgp_dynastic_cycle.0062.a
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_end"
		custom_tooltip = tgp_china_consolidation.remain_independent
	}

	option = {
		name = tgp_dynastic_cycle.0062.b
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_end"
		save_scope_as = actor
		title:h_china.holder = {
			save_scope_as = recipient
		}
		offer_fealty_interaction_effect = yes
	}

	after = {
		remove_character_flag = situation_phase_notification
	}
}

### ENTER STABILITY - EXISTING DYNASTY ### 0071 - 0080 ###

tgp_dynastic_cycle.0071 = {
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0071.t
	desc = tgp_dynastic_cycle.0071.desc
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_stability }

	cooldown = { days = 1 }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	trigger = {
		current_date_is_start_date_trigger = no
	}

	immediate = {
		if = {
			limit = {
				has_variable = new_son_of_heaven
			}
			save_scope_as = new_son_of_heaven
			show_as_tooltip = {
				tgp_claim_mandate_of_heaven_effect = yes
			}
		}
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
	}

	option = {
		name = tgp_dynastic_cycle.0071.a
		if = {
			limit = {
				OR = {
					has_variable = new_son_of_heaven
					situation:dynastic_cycle = {
						NOT = { situation_current_phase = situation_dynastic_cycle_phase_stability_advancement }
					}
				}
			}
			custom_tooltip = dynastic_cycle_entered_stability_advancement_tt
			situation:dynastic_cycle = {
				# Prevent dup entry in history.
				if = {
					limit = { NOT = { situation_current_phase = situation_dynastic_cycle_phase_stability_advancement } }
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_stability_advancement }
					}
				}
			}
			if = {
				limit = {
					trigger_if = {
						limit = {
							has_variable = new_son_of_heaven
						}
						has_variable = favor_era
						var:favor_era != flag:advancement
					}
					trigger_else = {
						situation:dynastic_cycle = {
							NOT = { situation_current_phase = situation_dynastic_cycle_phase_stability_advancement }
						}
					}
				}
				# Lose legitimacy, but only if it's not getting you into Chaos
				if = {
					limit = {
						legitimacy_level > 2
					}
					add_legitimacy = monumental_legitimacy_loss
				}
				situation:dynastic_cycle = {
					situation_participant_group:expansion_movement = {
						every_situation_group_participant = {
							custom = tgp_hegemon_picked_different_era_opinion_advancement_tt
							add_opinion = {
								modifier = tgp_hegemon_picked_different_era_opinion
								target = root
							}
						}
					}
					hidden_effect = {
						situation_participant_group:conservative_movement = {
							every_situation_group_participant = {
								add_opinion = {
									modifier = tgp_hegemon_picked_different_era_opinion
									target = root
								}
							}
						}
					}
				}
			}
		}
		else = {
			custom_tooltip = dynastic_cycle_entered_stability_advancement_past_tt
		}
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_start"
		ai_chance = {
			base = 0
			# no need to add any other modifiers here
			# if you want more add them to hegemon_favored_stability_phase_value instead
			modifier = {
				hegemon_favored_stability_phase_value >= 0
				add = 1
			}
			#in case the catalysts pushed to expansion, pick advancement only if you really wanted it
			modifier = {
				hegemon_favored_stability_phase_value >= 199
				situation:dynastic_cycle = { situation_current_phase = situation_dynastic_cycle_phase_stability_expansion }
				add = 1
			}
		}
	}

	option = {
		name = tgp_dynastic_cycle.0071.b
		if = {
			limit = {
				OR = {
					has_variable = new_son_of_heaven
					situation:dynastic_cycle = {
						NOT = { situation_current_phase = situation_dynastic_cycle_phase_stability_expansion }
					}
				}
			}
			custom_tooltip = dynastic_cycle_entered_stability_expansion_tt
			situation:dynastic_cycle = {
				situation_top_sub_region = {
					change_phase = { phase = situation_dynastic_cycle_phase_stability_expansion }
				}
			}
			if = {
				limit = {
					trigger_if = {
						limit = {
							has_variable = new_son_of_heaven
						}
						# You didn't do as what you promised before
						has_variable = favor_era
						var:favor_era != flag:expansion
					}
					# or you want change current phase
					trigger_else = {
						situation:dynastic_cycle = {
							NOT = { situation_current_phase = situation_dynastic_cycle_phase_stability_expansion }
						}
					}
				}
				# Lose legitimacy, but only if it's not getting you into Chaos
				if = {
					limit = {
						legitimacy_level > 2
					}
					add_legitimacy = monumental_legitimacy_loss
				}
				situation:dynastic_cycle = {
					situation_participant_group:advancement_movement = {
						every_situation_group_participant = {
							custom = tgp_hegemon_picked_different_era_opinion_expansion_tt
							add_opinion = {
								modifier = tgp_hegemon_picked_different_era_opinion
								target = root
							}
						}
					}
					hidden_effect = {
						situation_participant_group:conservative_movement = {
							every_situation_group_participant = {
								add_opinion = {
									modifier = tgp_hegemon_picked_different_era_opinion
									target = root
								}
							}
						}
					}
				}
			}
		}
		else = {
			custom_tooltip = dynastic_cycle_entered_stability_expansion_past_tt
		}
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_start"
		ai_chance = {
			base = 0
			# no need to add any other modifiers here
			# if you want more add them to hegemon_favored_stability_phase_value instead
			modifier = {
				hegemon_favored_stability_phase_value < 0
				add = 1
			}
			#in case the catalysts pushed to advancement, pick expansion only if you really wanted it
			modifier = {
				hegemon_favored_stability_phase_value < -199
				situation:dynastic_cycle = { situation_current_phase = situation_dynastic_cycle_phase_stability_advancement }
				add = 1
			}
		}
	}

	after = {
		every_player = {
			limit = { tgp_does_this_player_care_about_the_dynastic_cycle = yes } # Needs to be checked before the situation ends due to race condition issues
			add_to_list = player_to_notify # Making a list so stuff is tiggered after the situation ends, to make extra sure I don't break anything.
		}
		every_in_list = { # Then we *actually* notify players, making sure the situation has already ended
			list = player_to_notify
			limit = {
				NOT = { this = root }
			}
			trigger_event = tgp_dynastic_cycle.0072
		}
	}
}

tgp_dynastic_cycle.0072 = { # Notification for relevant people
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0071.t
	desc = {
		triggered_desc = {
			trigger = {
				situation:dynastic_cycle ?= {
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
			desc = tgp_dynastic_cycle.0072.desc.advancement
		}
		triggered_desc = {
			trigger = {
				situation:dynastic_cycle ?= {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
				}
			}
			desc = tgp_dynastic_cycle.0072.desc.expansion
		}
		triggered_desc = {
			trigger = {
				situation:dynastic_cycle ?= {
					situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
				}
			}
			desc = tgp_dynastic_cycle.0072.desc.conquest
		}
		desc = double_line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					tgp_is_hegemon_or_below_in_dynastic_cycle_trigger = yes
				}
				desc = tgp_dynastic_cycle.0072.desc.involved
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = other_rulers
					}
				}
				desc = tgp_dynastic_cycle.0072.desc.interloper
			}
			desc = tgp_dynastic_cycle.0072.desc.uninvolved
		}
	}
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_stability }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	trigger = {
		is_ai = no
		NOT = { has_character_flag = situation_phase_notification }
	}

	immediate = {
		add_character_flag = situation_phase_notification
		show_as_tooltip = {
			if = {
				limit = {
					exists = scope:new_son_of_heaven
				}
				scope:new_son_of_heaven = {
					tgp_claim_mandate_of_heaven_effect = yes
				}
			}
			situation:dynastic_cycle = {
				switch = {
					trigger = situation_current_phase
					situation_dynastic_cycle_phase_stability_expansion = {
						situation_top_sub_region = {
							change_phase = { phase = situation_dynastic_cycle_phase_stability_expansion }
						}
					}
					situation_dynastic_cycle_phase_stability_advancement = {
						situation_top_sub_region = {
							change_phase = { phase = situation_dynastic_cycle_phase_stability_advancement }
						}
					}
				}
			}
		}
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
	}

	option = {
		name = tgp_dynastic_cycle.0072.a
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_start"
		custom_tooltip = tgp_china_consolidation.remain_independent
	}

	option = {
		name = tgp_dynastic_cycle.0072.b
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_start"
		save_scope_as = actor
		title:h_china.holder = {
			save_scope_as = recipient
		}
		offer_fealty_interaction_effect = yes
	}

	after = {
		remove_character_flag = situation_phase_notification
	}
}

### ENTER CHAOS

tgp_dynastic_cycle.0081 = {
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0081.t
	desc = tgp_dynastic_cycle.0081.desc
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_chaos }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	trigger = {
		current_date_is_start_date_trigger = no
	}

	immediate = {
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
		custom_tooltip = dynastic_cycle_entered_chaos_tt
		every_player = {
			limit = { tgp_does_this_player_care_about_the_dynastic_cycle = yes } # Needs to be checked before the tgp_chaos_shattering_effect in case they get booted out of the Cycle from it
			add_to_list = player_to_notify
			# save variables to display correct desc in the follow up event
			if = {
				limit = {
					tgp_is_hegemon_or_below_in_dynastic_cycle_trigger = yes
				}
				set_variable = {
					name = involvement_in_cycle
					value = flag:involved
					days = 1
				}
			}
			else_if = {
				limit = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = other_rulers
					}
				}
				set_variable = {
					name = involvement_in_cycle
					value = flag:interloper
					days = 1
				}
			}
			else = {
				# don't need to save anything, there is a fallback desc	for it	
			}
		}
		tgp_chaos_shattering_effect = yes
		every_in_list = { # Then we *actually* notify players, making sure the Division already started
			list = player_to_notify
			limit = {
				NOT = { this = root }
			}
			trigger_event = tgp_dynastic_cycle.0082
		}
	}

	option = {
		name = tgp_dynastic_cycle.0081.a
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_end"
	}
}

tgp_dynastic_cycle.0082 = { # Notification for relevant people
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0081.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					var:involvement_in_cycle ?= flag:involved
				}
				desc = tgp_dynastic_cycle.0082.desc.involved
			}
			triggered_desc = {
				trigger = {
					var:involvement_in_cycle ?= flag:interloper
				}
				desc = tgp_dynastic_cycle.0082.desc.interloper
			}
			desc = tgp_dynastic_cycle.0082.desc.uninvolved
		}
	}
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_chaos }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	trigger = {
		is_ai = no
		NOT = { has_character_flag = situation_phase_notification }
	}

	immediate = {
		add_character_flag = situation_phase_notification
		save_scope_as = relevant_character
		custom_tooltip = dynastic_cycle_entered_chaos_tt
		custom_tooltip = dynastic_cycle_entered_chaos_hunagdi_tt
		show_as_tooltip = {
			switch = {
				trigger = root
				title:e_minister_chancellor.previous_holder = {
					destroy_title = title:e_minister_chancellor
				}
				title:e_minister_censor.previous_holder = {
					destroy_title = title:e_minister_censor
				}
				title:e_minister_grand_marshal.previous_holder = {
					destroy_title = title:e_minister_grand_marshal
				}
				title:e_minister_of_personnel.previous_holder = {
					destroy_title = title:e_minister_of_personnel
				}
				title:e_minister_of_revenue.previous_holder = {
					destroy_title = title:e_minister_of_revenue
				}
				title:e_minister_of_rites.previous_holder = {
					destroy_title = title:e_minister_of_rites
				}
				title:e_minister_of_war.previous_holder = {
					destroy_title = title:e_minister_of_war
				}
				title:e_minister_of_justice.previous_holder = {
					destroy_title = title:e_minister_of_justice
				}
				title:e_minister_of_works.previous_holder = {
					destroy_title = title:e_minister_of_works
				}
			}
		}
		save_scope_value_as = {
			name = chaos_new_vassals_count
			value = {
				every_in_list = {
					variable = chaos_new_vassals
					add = 1
				}
			}
		}
		save_scope_value_as = {
			name = chaos_new_tributaries_count
			value = {
				every_in_list = {
					variable = chaos_new_tributaries
					add = 1
				}
			}
		}
		if = {
			limit = {
				scope:chaos_new_vassals_count > 0
			}
			if = {
				limit = {
					has_variable = former_movement_leader
				}
				every_in_list = {
					variable = chaos_new_vassals
					custom = custom.chaos_new_vassals
					custom_tooltip = chaos_new_vassals_tt
				}
			}
			else = {
				every_in_list = {
					variable = chaos_new_vassals
					custom = custom.chaos_new_vassals_disciples
					custom_tooltip = chaos_new_vassals_tt
				}
			}
		}
		if = {
			limit = {
				scope:chaos_new_tributaries_count > 0
			}
			if = {
				limit = {
					has_variable = former_movement_leader
				}
				every_in_list = {
					variable = chaos_new_tributaries
					custom = custom.chaos_new_tributaries
					custom_tooltip = chaos_new_tributaries_tt
				}
			}
			else = {
				every_in_list = {
					variable = chaos_new_tributaries
					custom = custom.chaos_new_tributaries_disciples
					custom_tooltip = chaos_new_tributaries_tt
				}
			}
		}
	}

	option = {
		name = tgp_dynastic_cycle.0082.a
		clicksound = "event:/DLC/FP3/SFX/UI/Notifications/Toasts/struggle_end_positive"
		if = {
			limit = {
				top_liege = scope:relevant_character
			}
			custom_tooltip = dynastic_cycle_entered_chaos_became_independent_tt
		}
		else = {
			top_liege = {
				save_scope_as = new_top_liege
			}
			custom_tooltip = dynastic_cycle_entered_chaos_changed_top_liege_tt
		}
	}

	after = {
		remove_character_flag = situation_phase_notification
		clear_variable_list = chaos_new_vassals
		clear_variable_list = chaos_new_tributaries
	}
}

### ENTER INSTABILITY

tgp_dynastic_cycle.0091 = {
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0091.t
	desc = tgp_dynastic_cycle.0091.desc
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_instability }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}
	trigger = {
		current_date_is_start_date_trigger = no
	}

	immediate = {
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
		custom_tooltip = dynastic_cycle_entered_instability_tt
		every_player = {
			limit = { tgp_does_this_player_care_about_the_dynastic_cycle = yes } # Needs to be checked before the situation ends due to race condition issues
			add_to_list = player_to_notify # Making a list so stuff is tiggered after the situation ends, to make extra sure I don't break anything.
		}
		every_in_list = { # Then we *actually* notify players, making sure the situation has already ended
			list = player_to_notify
			limit = {
				NOT = { this = root }
			}
			trigger_event = tgp_dynastic_cycle.0092
		}
	}

	option = {
		name = tgp_dynastic_cycle.0091.a
		clicksound = "event:/DLC/EP4/MX/CueTracks/mx_mtgp_dynastic_cycle_end"
	}
}

tgp_dynastic_cycle.0092 = { # Notification for relevant people
	type = character_event
	window = fullscreen_event
	title = tgp_dynastic_cycle.0091.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					tgp_is_hegemon_or_below_in_dynastic_cycle_trigger = yes
				}
				desc = tgp_dynastic_cycle.0092.desc.involved
			}
			triggered_desc = {
				trigger = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = other_rulers
					}
				}
				desc = tgp_dynastic_cycle.0092.desc.interloper
			}
			desc = tgp_dynastic_cycle.0092.desc.uninvolved
		}
	}
	theme = dynastic_cycle
	override_background = { reference = tgp_fullscreen_dynastic_cycle_instability }

	widgets = {
		widget = {
 			gui = "event_window_widget_situation_info_dynastic_cycle"
 			container = "dynamic_content_widget"
 			controller = situation_info
 			setup_scope = { situation:dynastic_cycle = { save_scope_as = situation } }
		}
	}

	trigger = {
		is_ai = no
		NOT = { has_character_flag = situation_phase_notification }
	}

	immediate = {
		add_character_flag = situation_phase_notification
		show_as_tooltip = {
			situation:dynastic_cycle = {
				situation_top_sub_region = {
					change_phase = { phase = situation_dynastic_cycle_phase_instability }
				}
			}
		}
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
	}

	option = {
		name = tgp_dynastic_cycle.0092.a

		clicksound = "event:/DLC/FP3/SFX/UI/Notifications/Toasts/struggle_end_negative"
	}

	after = {
		remove_character_flag = situation_phase_notification
	}
}

###################################
# Integrity Validation Events
# By Joe Parkin
###################################

tgp_dynastic_cycle.9982 = { # Nav event, to make QA's life easier and avoid unecessary crashes
	type = character_event
	title = MENU
	desc = MENU

	orphan = yes
	theme = mental_break

	option = { # Dynamically start a situation
		trigger = { NOT = { exists = situation:dynastic_cycle } }
		name = FRONTEND_MP_GAME_SETUP_HOST_NEW_GAME

		random_ruler = {
			limit = {
				this = top_liege
				exists = location # TIL, we are somehow generating *a lot* of top lieges without a location set
				location = { geographical_region = world_asia_north_east }
			}
			primary_title = { save_scope_as = debug_emperor }
		}
		start_situation = {
			type = dynastic_cycle
			start_phase = situation_dynastic_cycle_phase_stability_advancement
		}

		send_interface_message = { # Informs you of who the "debug caliph" is
			type = event_martial_bad
			title = trait_beauty_bad_1_desc
			left_icon = scope:debug_emperor
			right_icon = scope:debug_emperor.holder
		}
	}
	option = { # Go forward in the situation flow
		name = dynn_Daflos_motto
		trigger = { exists = situation:dynastic_cycle }
		situation:dynastic_cycle = {
			switch = {
				trigger = situation_current_phase
				situation_dynastic_cycle_phase_stability_expansion = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_instability }
					}
				}
				situation_dynastic_cycle_phase_stability_advancement = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_instability }
					}
				}
				 situation_dynastic_cycle_phase_instability_conquest = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_instability }
					}
				}
				situation_dynastic_cycle_phase_instability = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_chaos }
					}
				}
				situation_dynastic_cycle_phase_chaos = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_stability }
					}
				}
			}
		}
	}
	option = { # Go backwards in the situation flow
		name = default_retreat
		trigger = { exists = situation:dynastic_cycle }
		show_as_unavailable = { always = yes }
		situation:dynastic_cycle = {
			switch = {
				trigger = situation_current_phase
				situation_dynastic_cycle_phase_stability_expansion = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_chaos }
					}
				}
				situation_dynastic_cycle_phase_stability_advancement = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_chaos }
					}
				}
				 situation_dynastic_cycle_phase_instability_conquest = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_chaos }
					}
				}
				situation_dynastic_cycle_phase_instability = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_stability }
					}
				}
				situation_dynastic_cycle_phase_chaos = {
					situation_top_sub_region = {
						change_phase = { phase = situation_dynastic_cycle_phase_instability }
					}
				}
			}
		}
	}
	option = { name = EXIT_TO_DESKTOP } # Exit event without doing anything
}

tgp_dynastic_cycle.9999 = {
	hidden = yes
	scope = character
	orphan = yes

	immediate = {
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		random_player = { save_scope_as = player }
		title:h_china = {
			every_in_de_jure_hierarchy = {
				limit = {
					exists = holder
					holder = { is_ai = yes }
					NOT = { holder.top_liege = scope:player }
				}
				holder = {
					if = {
						limit = { highest_held_title_tier = scope:player.highest_held_title_tier }
						every_held_title = {
							limit = { tier = scope:player.highest_held_title_tier }
							change_title_holder_include_vassals = {
								holder = scope:player
								change = scope:change
							}
						}
					}
					change_liege = {
						liege = scope:player
						change = scope:change
					}
				}
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
}

# This is a centralized middleman event to pass the actual renaming event through, because we run the original checks from on_actions, but when China shatters the gamestate can and does change between the on_action and the actual event running
tgp_dynastic_cycle.9000 = {
	hidden = yes

	trigger = {
		liege = root
		is_landed = yes
		tgp_chinese_naming_tier_trigger = yes
		NOT = { has_character_flag = received_chinese_hegemonic_ascension_event }
	}

	immediate = {
		if = {
			limit = {
				OR = {
					primary_title = {
						has_custom_title_name = no
					}
					dynasty != primary_title.previous_holder.dynasty
				}
			}
			add_character_flag = received_chinese_hegemonic_ascension_event
			trigger_event = {
				id = tgp_dynastic_cycle.9001
			}
		}
		else = {
			save_scope_as = already_has_custom_title_name
			if = {
				limit = {
					highest_held_title_tier = tier_hegemony
				}
				add_character_flag = received_chinese_hegemonic_ascension_event
				trigger_event = {
					id = tgp_dynastic_cycle.9002
				}
			}
			if = {
				limit = {
					is_ai = no
					has_title = title:h_china
				}
				add_achievement_global_variable_effect = {
					VARIABLE = finished_ep4_06_mandate_of_heaven_achievement_trigger
					VALUE = yes
				}
			}
			if = {
				limit = {
					has_title = title:h_china
					current_date >= 960.1.1
				}
				set_global_variable = {
					name = chinese_fashion_change
					value = 1
				}
			}
			remove_character_flag = received_chinese_hegemonic_ascension_event
		}
	}
}

scripted_effect tgp_ascension_rewards_effect = {
	if = {
		limit = {
			highest_held_title_tier = tier_hegemony
		}
		add_prestige = monumental_prestige_gain
		change_influence = massive_influence_gain
		add_legitimacy_effect = { LEGITIMACY = massive_legitimacy_gain }
	}
	if = {
		limit = {
			highest_held_title_tier = tier_empire
		}
		add_prestige = massive_prestige_gain
		change_influence = massive_influence_gain
		add_legitimacy_effect = { LEGITIMACY = massive_legitimacy_gain }
	}
	if = {
		limit = {
			highest_held_title_tier = tier_kingdom
		}
		add_prestige = major_prestige_gain
		change_influence = major_influence_gain
		add_legitimacy_effect = { LEGITIMACY = major_legitimacy_gain }
	}
	dynasty = {
		if = {
			limit = {
				root.highest_held_title_tier = tier_hegemony
			}
			add_dynasty_prestige = monumental_dynasty_prestige_gain
		}
		if = {
			limit = {
				root.highest_held_title_tier = tier_empire
			}
			add_dynasty_prestige = massive_dynasty_prestige_gain
		}
		if = {
			limit = {
				root.highest_held_title_tier = tier_kingdom
			}
			add_dynasty_prestige = major_dynasty_prestige_gain
		}
	}
}

tgp_dynastic_cycle.9001 = {
	type = character_event
	title = tgp_dynastic_cycle.9001.t
	desc = tgp_dynastic_cycle.9001.desc
	theme = dynastic_cycle

	left_portrait = {
		character = root
		animation = emperor
	}
	# tier check done in tgp_dynastic_cycle.9000
	#NAMING WIDGET
	widget = {
		gui = "event_window_widget_enter_text"
		container = "dynamic_birth_name"
		controller = {
			type = text
			data = {
				key = new_realm_title_name
				# Cultural
				default = {
					localization_key = dynn_title_nan
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_nan } }
				}
				default = {
					localization_key = dynn_title_he
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_he } }
				}
				default = {
					localization_key = dynn_title_zhuang_li
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_zhuang_li } }
				}
				default = {
					localization_key = dynn_title_bo
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_bo } }
				}
				default = {
					localization_key = dynn_title_zhen
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_zhen } }
				}
				default = {
					localization_key = dynn_title_rui
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_rui } }
				}
				default = {
					localization_key = dynn_title_li
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_li } }
				}
				default = {
					localization_key = dynn_title_fu
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_fu } }
				}
				default = {
					localization_key = dynn_title_yuan
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yuan } }
				}
				default = {
					localization_key = dynn_title_jurchen_jin
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_jurchen_jin } }
				}
				default = {
					localization_key = dynn_title_han_korea
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_han_korea } }
				}
				default = {
					localization_key = dynn_title_miao
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_miao } }
				}
				default = {
					localization_key = dynn_title_luo
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_luo } }
				}
				default = {
					localization_key = dynn_title_le
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_le } }
				}
				default = {
					localization_key = dynn_title_zhan
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_zhan } }
				}
				# Regional
				default = {
					localization_key = dynn_title_ba
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_ba } }
				}
				default = {
					localization_key = dynn_title_bao
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_bao } }
				}
				default = {
					localization_key = dynn_title_bi
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_bi } }
				}
				default = {
					localization_key = dynn_title_cai
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_cai } }
				}
				default = {
					localization_key = dynn_title_cao
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_cao } }
				}
				default = {
					localization_key = dynn_title_chen
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_chen } }
				}
				default = {
					localization_key = dynn_title_cheng
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_cheng } }
				}
				default = {
					localization_key = dynn_title_chu
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_chu } }
				}
				default = {
					localization_key = dynn_title_dai
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_dai } }
				}
				default = {
					localization_key = dynn_title_dao
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_dao } }
				}
				default = {
					localization_key = dynn_title_deng
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_deng } }
				}
				default = {
					localization_key = dynn_title_di
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_di } }
				}
				default = {
					localization_key = dynn_title_dian
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_dian } }
				}
				default = {
					localization_key = dynn_title_e
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_e } }
				}
				default = {
					localization_key = dynn_title_gan
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_gan } }
				}
				default = {
					localization_key = dynn_title_gui
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_gui } }
				}
				default = {
					localization_key = dynn_title_guo
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_guo } }
				}
				default = {
					localization_key = dynn_title_han
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_han } }
				}
				default = {
					localization_key = dynn_title_han_henan
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_han_henan } }
				}
				default = {
					localization_key = dynn_title_hua
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_hua } }
				}
				default = {
					localization_key = dynn_title_huai
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_huai } }
				}
				default = {
					localization_key = dynn_title_huang
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_huang } }
				}
				default = {
					localization_key = dynn_title_huo
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_huo } }
				}
				default = {
					localization_key = dynn_title_ji
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_ji } }
				}
				default = {
					localization_key = dynn_title_ji_hebei
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_ji_hebei } }
				}
				default = {
					localization_key = dynn_title_jiao
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_jiao } }
				}
				default = {
					localization_key = dynn_title_jin
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_jin } }
				}
				default = {
					localization_key = dynn_title_jing
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_jing } }
				}
				default = {
					localization_key = dynn_title_ju
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_ju } }
				}
				default = {
					localization_key = dynn_title_kang
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_kang } }
				}
				default = {
					localization_key = dynn_title_lai
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_lai } }
				}
				default = {
					localization_key = dynn_title_liang
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_liang } }
				}
				default = {
					localization_key = dynn_title_liang_west
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_liang_west } }
				}
				default = {
					localization_key = dynn_title_liao
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_liao } }
				}
				default = {
					localization_key = dynn_title_lu
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_lu } }
				}
				default = {
					localization_key = dynn_title_min
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_min } }
				}
				default = {
					localization_key = dynn_title_ou
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_ou } }
				}
				default = {
					localization_key = dynn_title_peng
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_peng } }
				}
				default = {
					localization_key = dynn_title_qi
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_qi } }
				}
				default = {
					localization_key = dynn_title_qi_guannei
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_qi_guannei } }
				}
				default = {
					localization_key = dynn_title_qian
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_qian } }
				}
				default = {
					localization_key = dynn_title_qin
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_qin } }
				}
				default = {
					localization_key = dynn_title_qiong
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_qiong } }
				}
				default = {
					localization_key = dynn_title_shang
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_shang } }
				}
				default = {
					localization_key = dynn_title_shen
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_shen } }
				}
				default = {
					localization_key = dynn_title_shu
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_shu } }
				}
				default = {
					localization_key = dynn_title_song
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_song } }
				}
				default = {
					localization_key = dynn_title_sui
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_sui } }
				}
				default = {
					localization_key = dynn_title_tan
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_tan } }
				}
				default = {
					localization_key = dynn_title_tang
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_tang } }
				}
				default = {
					localization_key = dynn_title_teng
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_teng } }
				}
				default = {
					localization_key = dynn_title_wei
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_wei } }
				}
				default = {
					localization_key = dynn_title_wey
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_wey } }
				}
				default = {
					localization_key = dynn_title_wu
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_wu } }
				}
				default = {
					localization_key = dynn_title_xi
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_xi } }
				}
				default = {
					localization_key = dynn_title_xia
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_xia } }
				}
				default = {
					localization_key = dynn_title_xiang
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_xiang } }
				}
				default = {
					localization_key = dynn_title_xing
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_xing } }
				}
				default = {
					localization_key = dynn_title_xu
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_xu } }
				}
				default = {
					localization_key = dynn_title_xu_shandong
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_xu_shandong } }
				}
				default = {
					localization_key = dynn_title_yan
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yan } }
				}
				default = {
					localization_key = dynn_title_yang
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yang } }
				}
				default = {
					localization_key = dynn_title_yin
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yin } }
				}
				default = {
					localization_key = dynn_title_ying
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_ying } }
				}
				default = {
					localization_key = dynn_title_yong
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yong } }
				}
				default = {
					localization_key = dynn_title_you
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_you } }
				}
				default = {
					localization_key = dynn_title_yu
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yu } }
				}
				default = {
					localization_key = dynn_title_yuan_ferghana
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yuan_ferghana } }
				}
				default = {
					localization_key = dynn_title_yue
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yue } }
				}
				default = {
					localization_key = dynn_title_yue_2
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_yue_2 } }
				}
				default = {
					localization_key = dynn_title_zhao
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_zhao } }
				}
				default = {
					localization_key = dynn_title_zheng
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_zheng } }
				}
				default = {
					localization_key = dynn_title_zhou
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_zhou } }
				}
				default = {
					localization_key = dynn_title_zou
					trigger = { is_target_in_variable_list = { name = realm_title_names target = flag:dynn_title_zou } }
				}
				### OTHER
				default = {
					localization_key = capital_duchy_name
					trigger = { exists = scope:duchy_name }
				}
				default = {
					localization_key = capital_kingdom_name
					trigger = { exists = scope:kingdom_name }
				}
			}
		}
		setup_scope = {
			root = { save_scope_as = text_target }
		}
	}

	immediate = {
		hidden_effect = {
			clear_variable_list = realm_title_names
			tgp_assign_china_realm_name_options_effect = yes
			if = {
				limit = {
					OR = {
						NOT = { has_variable_list = realm_title_names }
						variable_list_size = {
							name = realm_title_names
							value <= 1
						}
					}
				}
				capital_county ?= {
					duchy = {
						save_scope_as = duchy_name
					}
					if = {
						limit = {
							root.highest_held_title_tier >= tier_kingdom
						}
						kingdom = {
							save_scope_as = kingdom_name
						}
					}
				}
			}
		}
		if = {
			limit = { is_ai = yes }
			random_in_list = {
				variable = realm_title_names
				save_scope_as = new_realm_title_name
				root = {
					set_variable = {
						name = new_realm_title_name
						value = scope:new_realm_title_name
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = root.var:new_realm_title_name }
				}
				root = {
					set_variable = {
						name = new_realm_title_name
						value = flag:capital_duchy_name
					}
				}
			}
		}
		play_music_cue = mx_cue_tgp_dynastic_cycle_end
	}

	option = {
		name = tgp_dynastic_cycle.9001.a

		tgp_ascension_rewards_effect = yes
	}

	after = {
		clear_variable_list = realm_title_names

		if = {
			limit = {
				is_ai = yes
				NOT = { is_title_localization_key_used = dynn_title_yuan }
				highest_held_title_tier >= tier_empire
				culture = {
					has_cultural_pillar = heritage_mongolic
				}
			}
			primary_title = {
				set_title_name_dynamic = dynn_title_yuan
			}
		}
		else_if = {
			limit = {
				var:new_realm_title_name ?= flag:capital_duchy_name
			}
			primary_title = {
				set_title_name_dynamic = capital_duchy_name
			}
		}
		else_if = {
			limit = {
				var:new_realm_title_name ?= flag:capital_kingdom_name
			}
			primary_title = {
				set_title_name_dynamic = capital_kingdom_name
			}
		}
		else_if = {
			limit = {
				has_variable = new_realm_title_name
			}
			primary_title = {
				set_title_name_dynamic = new_realm_title_name_from_var
			}
		}
		else = {
			# We entered custom text into the pop up
			primary_title = {
				set_title_name_dynamic = new_realm_title_name_entered_text
			}
		}
		if = {
			limit = {
				highest_held_title_tier = tier_hegemony
			}
			trigger_event = {
				id = tgp_dynastic_cycle.9002
			}
		}
		if = {
			limit = {
				is_ai = no
				has_title = title:h_china
			}
			add_achievement_global_variable_effect = {
				VARIABLE = finished_ep4_06_mandate_of_heaven_achievement_trigger
				VALUE = yes
			}
		}
		if = {
			limit = {
				has_title = title:h_china
				current_date >= 960.1.1
			}
			set_global_variable = {
				name = chinese_fashion_change
				value = 1
			}
		}
		remove_character_flag = received_chinese_hegemonic_ascension_event
		create_artifact_dynastic_imperial_seal_effect = {
			OWNER = root
			SMITH = root
		}
	}
}

# "peace" changes
scripted_trigger china_transfered_peacefully_trigger= {
	title:h_china = {
		OR = {
			recent_history = { type = inheritance days = 7 }
			recent_history = { type = abdication days = 7 }
			recent_history = { type = granted days = 7 }
			recent_history = { type = usurped days = 7 }
			recent_history = { type = election days = 7 }
			recent_history = { type = faction_demand days = 7 }
			recent_history = { type = stepped_down days = 7 }
			recent_history = { type = appointment days = 7 }
			recent_history = { type = appointment_succession days = 7 }
		}
	}
}

tgp_dynastic_cycle.9002 = {
	type = character_event
	title = tgp_dynastic_cycle.9002.t
	desc = tgp_dynastic_cycle.9002.desc
	theme = dynastic_cycle
	left_portrait = {
		character = root
		animation = emperor
	}

	immediate = {
		if = {
			limit = {
				exists = scope:already_has_custom_title_name
			}
			tgp_ascension_rewards_effect = yes
		}
	}

	option = {
		name = tgp_dynastic_cycle.9002.green
		title:h_china = {
			set_title_color = { 0 60 60 }
		}

		tgp_set_wuking_element_effect = { ELEMENT = wood }

		ai_chance = {
			base = 0
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= yes
				situation:dynastic_cycle.var:wuking_element ?= flag:earth
			}
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= no
				situation:dynastic_cycle.var:wuking_element ?= flag:water
			}
			modifier = {
				add = 100
				dynasty.var:wuking_element ?= flag:wood
			}
		}
	}
	option = {
		name = tgp_dynastic_cycle.9002.red
		title:h_china = {
			set_title_color = { 125 0 0 }
		}

		tgp_set_wuking_element_effect = { ELEMENT = fire }

		ai_chance = {
			base = 0
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= yes
				situation:dynastic_cycle.var:wuking_element ?= flag:wood
			}
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= no
				situation:dynastic_cycle.var:wuking_element ?= flag:metal
			}
			modifier = {
				add = 100
				dynasty.var:wuking_element ?= flag:fire
			}
		}
	}
	option = {
		name = tgp_dynastic_cycle.9002.yellow
		title:h_china = {
			set_title_color = { 250 180 0 }
		}

		tgp_set_wuking_element_effect = { ELEMENT = earth }

		ai_chance = {
			base = 0
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= yes
				situation:dynastic_cycle.var:wuking_element ?= flag:fire
			}
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= no
				situation:dynastic_cycle.var:wuking_element ?= flag:water
			}
			modifier = {
				add = 100
				dynasty.var:wuking_element ?= flag:earth
			}
		}
	}
	option = {
		name = tgp_dynastic_cycle.9002.white
		title:h_china = {
			set_title_color = { 180 200 200 }
		}

		tgp_set_wuking_element_effect = { ELEMENT = metal }

		ai_chance = {
			base = 0
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= yes
				situation:dynastic_cycle.var:wuking_element ?= flag:earth
			}
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= no
				situation:dynastic_cycle.var:wuking_element ?= flag:wood
			}
			modifier = {
				add = 100
				dynasty.var:wuking_element ?= flag:metal
			}
		}
	}
	option = {
		name = tgp_dynastic_cycle.9002.black
		title:h_china = {
			set_title_color = { 15 15 15 }
		}

		tgp_set_wuking_element_effect = { ELEMENT = water }

		ai_chance = {
			base = 0
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= yes
				situation:dynastic_cycle.var:wuking_element ?= flag:metal
			}
			modifier = {
				add = 100
				NOT = { exists = dynasty.var:wuking_element }
				china_transfered_peacefully_trigger= no
				situation:dynastic_cycle.var:wuking_element ?= flag:fire
			}
			modifier = {
				add = 100
				dynasty.var:wuking_element ?= flag:water
			}
		}
	}
}
