add_namespace = VIN_nguyen_dynasty
add_namespace = nguyen_dynasty_succession

add_namespace = jarai

########## Nguyen Dynasty ##########
	# 1857 Start Date
	country_event = {
		id = VIN_nguyen_dynasty.1
		title = VIN_nguyen_dynasty.1.t
		desc = VIN_nguyen_dynasty.1.d
		picture = GFX_report_event_king_speech
	 
		is_triggered_only = yes
		fire_only_once = yes

		immediate = {
			hidden_effect = {
				country_event = { id = nguyen_dynasty_succession.1 days = 1 }
			}
		}

		option = {
			name = VIN_nguyen_dynasty.1.a
			add_political_power = -5
			set_temp_variable = { eoanb_prestige_change = 1 }
			eoanb_change_prestige_score = yes
			hidden_effect = {
				set_country_flag = VIN_Nguyen_Dynasty_Contendors_Dinh_Dao_Flag
				add_ideas = {
					VIN_Spirit_Dinh_Dao_Opposition1
				}
			}
		}
	}
	
	
########## Siam Conflicts ##########
	# country_event = {
	# 	id = nguyen_dynasty_siam_conflicts.1
	# 	title = nguyen_dynasty_siam_conflicts.1.t
	# 	desc = nguyen_dynasty_siam_conflicts.1.d
		
	# 	is_triggered_only = yes
	# 	fire_only_once = yes

	# 	trigger = {
	# 		country_exists = SIA
	# 	}

	# 	option = {
	# 		name = nguyen_dynasty_siam_conflicts.1.a
	# 		trigger = { tag = VIN }
	# 		hidden_effect = {
	# 			every_neighbor_country = { country_event = nguyen_dynasty_siam_conflicts.1 }
	# 		}
	# 	}
	# 	option = {
	# 		name = nguyen_dynasty_siam_conflicts.1.b
	# 		trigger = { tag = SIA }
	# 	}
	# 	option = {
	# 		name = nguyen_dynasty_siam_conflicts.1.c
	# 		trigger = { is_subject_of = SIA }
	# 	}
	# 	option = {
	# 		name = nguyen_dynasty_siam_conflicts.1.e
	# 		trigger = { is_subject_of = VIN }
	# 	}
	# 	option = {
	# 		name = nguyen_dynasty_siam_conflicts.1.f
	# 		trigger = { tag = QNG }
	# 	}
	# }
	
########## Qing Tribute ##########
	# country_event = {
	# 	id = nguyen_dynasty_tribute.1
	# 	title = nguyen_dynasty_tribute.1.t
	# 	desc = nguyen_dynasty_tribute.1.d
		
	# 	is_triggered_only = yes
	# 	fire_only_once = yes

	# 	trigger = {
	# 		country_exists = QNG
	# 	}

	# 	option = {
	# 		name = nguyen_dynasty_tribute.1.a
	# 	}
	# }
########## Catholic Missions ##########
	# country_event = {
	# 	id = nguyen_dynasty_catholic_missions.1
	# 	title = nguyen_dynasty_catholic_missions.1.t
	# 	desc = nguyen_dynasty_catholic_missions.1.d
		
	# 	is_triggered_only = yes
	# 	fire_only_once = yes

	# 	trigger = {
	# 		OR = {
	# 			country_exists = FRA
	# 			country_exists = SPR
	# 		}
	# 	}

	# 	option = {
	# 		name = nguyen_dynasty_catholic_missions.1.a
	# 	}
	# }

########## Nguyen succession ##########
	# Tuc Duc looks for an heir
	country_event = {
		id = nguyen_dynasty_succession.1
		title = nguyen_dynasty_succession.1.t
		desc = nguyen_dynasty_succession.1.d

		is_triggered_only = yes

		immediate = {
			VIN_Nguyen_Dynasty_No_Heir_Setup = yes
		}

		option = {
			name = nguyen_dynasty_succession.1.a
			hidden_effect = { country_event = nguyen_dynasty_succession.2 }
		}
	}

	country_event = {
		id = nguyen_dynasty_succession.2
		hidden = yes

		is_triggered_only = yes

		immediate = {
			if = {
				limit = { 
					has_government = autocracy
					#has_idea = absolute_monarchy
				}
				if = {
					limit = { 
						#has_idea = no_heir
						NOT = { has_country_flag = VIN_Nguyen_Dynasty_Heir_Give_Up }
					}
					random_list = {
						50 = {
							country_event = { id = nguyen_dynasty_succession.3 days = 25 random_days = 10 }
						}
						35 = {
							country_event = { id = nguyen_dynasty_succession.4 days = 25 random_days = 10 }
						}
						15 = {
							country_event = { id = nguyen_dynasty_succession.5 days = 25 random_days = 10 }
						}
					}
				}
				else_if = {
					limit = {
						#has_idea = no_heir
						has_country_flag = VIN_Nguyen_Dynasty_Heir_Give_Up
					}
					country_event = { id = nguyen_dynasty_succession.6 days = 50 }
				}
				#else_if = {
				#	limit = { 
				#		OR = {
				#			has_idea = nonfamily_heir 
				#			has_idea = weak_heir
				#		}
				#	}
					#country_event = { id = nguyen_dynasty_succession.10 days = 50 }
				#}
				#else_if = {
				#	limit = { has_idea = dethroned_heir }
				#	country_event = { id = nguyen_dynasty_succession.20 days = 50 }
				#}
				#else_if = {
				#	limit = { has_idea = non_monarchical_system }
				#	swap_ideas = {
				#		remove_idea = non_monarchical_system
				#		add_idea = no_heir
				#	}
				#}
				#else_if = {
				#	limit = { has_idea = has_heir }
				#	country_event = nguyen_dynasty_succession.99
				#}
			}
			else_if = {
				limit = { 
					has_government = autocracy
					#NOT = { has_idea = absolute_monarchy }
				}
			}
			#if = {
			#	limit = {
			#		NOT = { has_government = autocracy }
			#	}
			#	if = {
			#		limit = {
			#			OR = {
			#				has_idea = no_heir
			#				has_idea = dethroned_heir
			#				has_idea = nonfamily_heir
			#				has_idea = weak_heir
			#				has_idea = has_heir
			#			}
			#		}
			#		remove_ideas = no_heir
			#		remove_ideas = dethroned_heir
			#		remove_ideas = nonfamily_heir
			#		remove_ideas = weak_heir
			#		remove_ideas = has_heir
			#		add_ideas = non_monarchical_system
			#	}
			#	if = {
			#		limit = {
			#			OR = {
			#				has_idea = absolute_monarchy
			#				AND = {
			#					NOT = { has_government = fundamentalism }
			#					OR = {
			#						has_idea = constitutional_monarchy
			#						has_idea = parliamentary_monarchy
			#					}
			#				}
			#			}
			#		}
			#		remove_ideas = absolute_monarchy
			#		remove_ideas = constitutional_monarchy
			#		remove_ideas = parliamentary_monarchy
			#		if = {
			#			limit = { has_government = ideology_radical_socialism }
			#			random_list = {
			#				85 = {
			#					add_ideas = socialist_state
			#				}
			#				15 = {
			#					add_ideas = socialist_republic
			#				}
			#			}
			#		}
			#		else_if = {
			#			limit = { has_government = radical_democracy }
			#			random_list = {
			#				20 = {
			#					add_ideas = presidential_republic
			#				}
			#				40 = {
			#					add_ideas = totalitarian_dictatorship
			#				}
			#				40 = {
			#					add_ideas = revolutionary_government
			#				}
			#			}
			#		}
			#		else_if = {
			#			limit = { has_government = fundamentalism }
			#			random_list = {
			#				50 = {
			#					add_ideas = constitutional_monarchy
			#				}
			#				50 = {
			#					add_ideas = council_communism
			#				}
			#			}
			#		}
			#		else_if = {
			#			limit = { is_subject = no }
			#			random_list = {
			#				60 = {
			#					add_ideas = semi_presidential_republic
			#				}
			#				40 = {
			#					add_ideas = parliamentary_republic
			#				}
			#			}
			#		}
			#	}
			#}
		}
	}

	country_event = {
		id = nguyen_dynasty_succession.3
		title = nguyen_dynasty_succession.3.t
		desc = nguyen_dynasty_succession.3.d

		is_triggered_only = yes

		option = {
			name = nguyen_dynasty_succession.3.a
			ai_chance = { base = 25 }
			trigger = { check_variable = { VIN_Dynasty_Concubines_Count < 360 } }
			VIN_Nguyen_Dynasty_No_Heir_Update = yes
			hidden_effect = {
				country_event = nguyen_dynasty_succession.2
			}
		}
		option = {
			name = nguyen_dynasty_succession.3.b
			ai_chance = { base = 75 }
			trigger = { check_variable = { VIN_Dynasty_Concubines_Count > 299 } }
			hidden_effect = {
				set_country_flag = VIN_Nguyen_Dynasty_Heir_Give_Up
				country_event = nguyen_dynasty_succession.2
			}
		}
	}
	country_event = {
		id = nguyen_dynasty_succession.4
		title = nguyen_dynasty_succession.4.t
		desc = nguyen_dynasty_succession.4.d

		is_triggered_only = yes

		option = {
			name = nguyen_dynasty_succession.3.a
			ai_chance = { base = 25 }
			trigger = { check_variable = { VIN_Dynasty_Concubines_Count < 360 } }
			VIN_Nguyen_Dynasty_No_Heir_Update = yes
			hidden_effect = {
				country_event = nguyen_dynasty_succession.2
			}
		}
		option = {
			name = nguyen_dynasty_succession.3.b
			ai_chance = { base = 75 }
			trigger = { check_variable = { VIN_Dynasty_Concubines_Count > 299 } }
			hidden_effect = {
				set_country_flag = VIN_Nguyen_Dynasty_Heir_Give_Up
				country_event = nguyen_dynasty_succession.2
			}
		}
	}
	country_event = {
		id = nguyen_dynasty_succession.5
		title = nguyen_dynasty_succession.5.t
		desc = nguyen_dynasty_succession.5.d

		is_triggered_only = yes

		option = {
			name = nguyen_dynasty_succession.5.a
			ai_chance = { base = 25 }
			trigger = { check_variable = { VIN_Dynasty_Concubines_Count < 360 } }
			VIN_Nguyen_Dynasty_No_Heir_Update = yes
			hidden_effect = {
				country_event = nguyen_dynasty_succession.2
			}
		}
		option = {
			name = nguyen_dynasty_succession.5.b
			ai_chance = { base = 75 }
			trigger = { check_variable = { VIN_Dynasty_Concubines_Count > 299 } }
			hidden_effect = {
				set_country_flag = VIN_Nguyen_Dynasty_Heir_Give_Up
				country_event = nguyen_dynasty_succession.2
			}
		}
	}
	country_event = {
		id = nguyen_dynasty_succession.6
		title = nguyen_dynasty_succession.6.t
		desc = nguyen_dynasty_succession.6.d

		is_triggered_only = yes

		option = {
			name = nguyen_dynasty_succession.6.a
			#swap_ideas = {
			#	remove_idea = no_heir
			#	add_idea = weak_heir
			#}
			hidden_effect = { country_event = nguyen_dynasty_succession.2 }
		}
		option = {
			name = nguyen_dynasty_succession.6.b
			#swap_ideas = {
			#	remove_idea = no_heir
			#	add_idea = weak_heir
			#}
			hidden_effect = { country_event = nguyen_dynasty_succession.2 }
		}
		option = {
			name = nguyen_dynasty_succession.6.c
			#swap_ideas = {
			#	remove_idea = no_heir
			#	add_idea = weak_heir
			#}
			hidden_effect = { country_event = nguyen_dynasty_succession.2 }
		}
		option = {
			name = nguyen_dynasty_succession.6.d
			#swap_ideas = {
			#	remove_idea = no_heir
			#	add_idea = nonfamily_heir
			#}
			hidden_effect = { country_event = nguyen_dynasty_succession.2 }
		}
	}

############ debug
	country_event = {
		id = VIN_nguyen_dynasty.101
		title = VIN_nguyen_dynasty.101.t
		desc = VIN_nguyen_dynasty.101.t

		is_triggered_only = yes

		option = {
			name = VIN_nguyen_dynasty.101
			VNM = {
				transfer_state = 671
				transfer_state = 993
				transfer_state = 1337
				transfer_state = 992
				set_cosmetic_tag = FRA_tonkin_protect
				FRA = { puppet = PREV }
			}
			VIN = {
				transfer_state = 1353
				transfer_state = 1336
				transfer_state = 286
				transfer_state = 1173
				transfer_state = 286
				# transfer_state = 1173
				set_cosmetic_tag = FRA_annam_protect
				FRA = { puppet = PREV }
			}
			CCH = {
				transfer_state = 784
				transfer_state = 998
				set_cosmetic_tag = SPR_cochin_protect
				SPR = { puppet = PREV }
			}
			CAM = {
				transfer_state = 741
				transfer_state = 991
				transfer_state = 994
				transfer_state = 995
				741 = { set_demilitarized_zone = no }
				995 = { set_demilitarized_zone = no }
				set_cosmetic_tag = SPR_khmer_protect
				SPR = { puppet = PREV }
			}
			LAO = {
				transfer_state = 1351
				transfer_state = 670
				transfer_state = 1352
				transfer_state = 988
				set_cosmetic_tag = FRA_laos_protect
				FRA = { puppet = PREV }
			}
			SIA = { transfer_state = 990 }
		}
	}
	country_event = {
		id = VIN_nguyen_dynasty.102
		title = VIN_nguyen_dynasty.101.t
		desc = VIN_nguyen_dynasty.101.t

		is_triggered_only = yes

		option = {
			name = VIN_nguyen_dynasty.101.a
			VNM = {
				transfer_state = 671
				transfer_state = 993
				transfer_state = 1337
				transfer_state = 992
				set_cosmetic_tag = FRA_tonkin_protect
				FRA = { puppet = PREV }
			}
			VIN = {
				transfer_state = 1353
				transfer_state = 1336
				transfer_state = 286
				transfer_state = 1173
				transfer_state = 286
				transfer_state = 1173
				set_cosmetic_tag = FRA_annam_protect
				FRA = { puppet = PREV }
			}
			CCH = {
				transfer_state = 784
				transfer_state = 998
				set_cosmetic_tag = FRA_cochin_protect
				FRA = { puppet = PREV }
			}
			CAM = {
				transfer_state = 741
				transfer_state = 991
				transfer_state = 994
				transfer_state = 995
				transfer_state = 994
				transfer_state = 995
				set_cosmetic_tag = FRA_khmer_protect
				FRA = { puppet = PREV }
			}
			LAO = {
				transfer_state = 1351
				transfer_state = 670
				transfer_state = 1352
				transfer_state = 988
				set_cosmetic_tag = FRA_laos_protect
				FRA = { puppet = PREV }
			}
			SIA = { transfer_state = 990 }
		}
	}
	country_event = {
		id = VIN_nguyen_dynasty.103
		title = VIN_nguyen_dynasty.101.t
		desc = VIN_nguyen_dynasty.101.t

		is_triggered_only = yes

		option = {
			name = VIN_nguyen_dynasty.101.a
			if = {
				limit = { VIN = { is_subject_of = FRA } }
				VIN = {
					set_cosmetic_tag = FRA_indoc_protect
					FRA = { puppet = PREV }
					if = {
						limit = { VNM = { is_subject_of = FRA } }
						annex_country = {
							target = VNM
							transfer_troops = yes
						}
					}
					if = {
						limit = { LAO = { is_subject_of = FRA } }
						annex_country = {
							target = LAO
							transfer_troops = yes
						}
					}
					if = {
						limit = { CCH = { is_subject_of = FRA } }
						annex_country = {
							target = CCH
							transfer_troops = yes
						}
					}
					if = {
						limit = { CAM = { is_subject_of = FRA } }
						annex_country = {
							target = CAM
							transfer_troops = yes
						}
					}
				}
			}
			if = {
				limit = { CCH = { is_subject_of = SPR } }
				CCH = {
					set_cosmetic_tag = SPR_indoc_protect
					SPR = { puppet = PREV }
					if = {
						limit = { VNM = { is_subject_of = SPR } }
						annex_country = {
							target = VNM
							transfer_troops = yes
						}
					}
					if = {
						limit = { LAO = { is_subject_of = SPR } }
						annex_country = {
							target = LAO
							transfer_troops = yes
						}
					}
					if = {
						limit = { VNM = { is_subject_of = SPR } }
						annex_country = {
							target = CCH
							transfer_troops = yes
						}
					}
					if = {
						limit = { CAM = { is_subject_of = SPR } }
						annex_country = {
							target = CAM
							transfer_troops = yes
						}
					}
				}
			}
		}
	}

	country_event = {
		id = VIN_nguyen_dynasty.106
		hidden = yes

		is_triggered_only = yes
		
		immediate = {
			VIN_Cochinchina_Campaign_Investment_Remove = yes
		}
	}
	

	################ Jarai

country_event = {
	id = jarai.1
	title = jarai.1.t
	desc = jarai.1.d

	is_triggered_only = yes

	option = {
		name = jarai.1.a
	}
}