﻿###########################
# Chinese Events
###########################

add_namespace = china

# Japanese Stage Border Incident
country_event = {
	id = china.1
	title = china.1.t
	desc = china.1.d
	picture = GFX_report_event_chinese_soldiers_fighting
	
	is_triggered_only = yes
	
	option = { # Breaking point!
		name = china.1.a
		ai_chance = { 
			base = 85
			modifier = {
				add = -15
				is_historical_focus_on = no
			}
		}
		effect_tooltip = {
			JAP = {
				add_war_support = 0.05
				country_event = { id = japan.1 }
			}
		}
		hidden_effect = {
			JAP = { country_event = { id = japan.1 } }
		}
	}
	option = { # Make more concessions
		name = china.1.b
		ai_chance = { 
			base = 15
			modifier = {
				add = -14
				is_historical_focus_on = yes
			}
		}
		trigger = {
			always = no
		}
		effect_tooltip = {
			JAP = {
				if = {
					limit = {
						country_exists = PGR
						PGR = {
							is_puppet_of = CHI
						}
					}
					puppet = PGR
					else = {
						transfer_state = 608
						transfer_state = 614
						transfer_state = 597
						transfer_state = 743
						if = {
							limit = {
								MEN = { is_subject_of = CHI }
								611 = { is_controlled_by = MEN }	
							}
							JAP = { 
								transfer_state = 611
							}
						}
					}
				}
				country_event = { id = japan.2 }
			}
		}
		hidden_effect = {
			if = {
				limit = {
					country_exists = PGR
				}
				PGR = {
					country_event = { id = kmt.349 }
				}
				set_global_flag = PGR_wait_bridge
			}
			if = {
				limit = {
					NOT = {
						country_exists = PGR
					}
				}
				JAP = {
					country_event = { id = japan.2 }
				}
			}
		}
	}
}

# Germany Withdraws Advisors
country_event = {
	id = china.2
	title = china.2.t
	desc = china.2.d
	picture = GFX_report_event_chinese_army_training
	
	is_triggered_only = yes
	
	option = {
		name = china.2.a
		remove_ideas = german_advisors
	}
}

# Chinese - German Relations Poor, Mission Recalled
country_event = {
	id = china.3
	title = china.3.t
	desc = china.3.d
	picture = GFX_report_event_chinese_soldiers
	
	is_triggered_only = yes
	
	option = {
		name = china.3.a
		if = {
			limit = {
				has_idea = german_advisors
			}
			remove_ideas = german_advisors
		}
	}
}

# China is at war with Germany, Advisors Detained
country_event = {
	id = china.4
	title = china.4.t
	desc = china.4.d
	picture = GFX_report_event_german_detained_china
	
	is_triggered_only = yes
	
	option = {
		name = china.4.a
	}
}

# Mao is gaining ground, loses his Cornered Fox trait
country_event = {
	id = china.5
	title = china.5.t
	desc = china.5.d
	picture = GFX_report_event_chinese_officers
	is_triggered_only = yes
	fire_only_once = yes
	
	option = {
		name = china.5.a
		remove_country_leader_trait = cornered_fox
	}
}

# Japan attacks - Chinese Popular Front forms
country_event = {
	id = china.101
	title = china.101.t
	desc = china.101.d
	picture = GFX_report_event_chinese_officers

	is_triggered_only = yes

	immediate = {
		set_country_flag = popular_front_fired
	}
	
	option = {
		ai_chance = { 
			base = 5
			modifier = { #Historically Cliques lived till 1949 aka communist takeover, so on historical they won't join
				factor = 0
				date < 1941.1.1 #if by any means Japan hasn't attacked yet, they can peacefully join now, just in case
				is_historical_focus_on = yes
			}
		}
		name = china.101.a
		effect_tooltip = {
			event_target:CHI_united_front_leader = {
				annex_country = { target = ROOT transfer_troops = yes }
			}
		}
		custom_effect_tooltip = GAME_OVER_TT
		hidden_effect = {
			event_target:CHI_united_front_leader = { country_event = china.103 }
			if = {
				limit = {
					ROOT = {
						tag = GXC
					}
				}
				GXC = {
					every_unit_leader = {
						set_nationality = event_target:CHI_united_front_leader
					}
					retire_country_leader = yes #probably to be improved as it should take into account other ideologies, especially if they lose and are puppeted
					
				}				
				event_target:CHI_united_front_leader = {
					set_country_flag = gxc_sumitted
				}
			}
			if = {
				limit = {
					ROOT = {
						tag = YUN
					}
				}
				YUN = {
					every_unit_leader = {
						set_nationality = event_target:CHI_united_front_leader
					}
					retire_country_leader = yes #probably to be improved as it should take into account other ideologies, especially if they lose and are puppeted					
				}				
				event_target:CHI_united_front_leader = {
					set_country_flag = yun_sumitted
				}
			}
			if = {
				limit = {
					ROOT = {
						tag = SHX
					}
				}
				SHX = {
					every_unit_leader = {
						set_nationality = event_target:CHI_united_front_leader
					}
					retire_country_leader = yes #probably to be improved as it should take into account other ideologies, especially if they lose and are puppeted					
				}					
				event_target:CHI_united_front_leader = {
					set_country_flag = shx_sumitted
				}
			}
			
			if = {
				limit = {
					ROOT = {
						tag = XSM
					}
				}
				XSM = {
					every_unit_leader = {
						set_nationality = event_target:CHI_united_front_leader
					}
					retire_country_leader = yes #probably to be improved as it should take into account other ideologies, especially if they lose and are puppeted					
				}
				event_target:CHI_united_front_leader = {set_country_flag = xsm_sumitted}
				
			}
		}
	}

	option = {
		ai_chance = { 
			base = 95
			modifier = { 
				factor = 100
				is_historical_focus_on = yes
			}
		}
		name = china.101.b
		event_target:CHI_united_front_leader = { 
			add_to_faction = ROOT 
			country_event = china.106
		}
		add_to_war = {
			targeted_alliance = event_target:CHI_united_front_leader
			enemy = JAP
		}
		add_ideas = KMT_united_front
	}

	option = {	#Nothing
		ai_chance = { 
			base = 5
			modifier = {
				add = 50
				ROOT = {
					has_completed_focus = CHI_opposition
				}
			}
			modifier = {	#on historical, do not refuse to join
				factor = 0
				date < 1941.1.1
				is_historical_focus_on = yes
			}
		}
		name = china.101.c
	}
}

# FROM joins China (annex)
country_event = {
	id = china.103
	title = china.103.t
	desc = china.103.d
	picture = GFX_report_event_chinese_army_training

	is_triggered_only = yes
	
	option = {
		name = china.103.a
		set_global_flag = CHI_unite_PRC
		annex_country = { target = FROM transfer_troops = yes }
	}
}

# PRC option to join China faction
country_event = {
	id = china.104
	title = china.104.t
	desc = china.104.d
	picture = GFX_report_event_chinese_army_training

	fire_only_once = yes
	is_triggered_only = yes
	
	option = {
		ai_chance = { base = 100 }
		name = china.104.a
		set_country_flag = PRC_joined_CHI_against_JAP
		event_target:CHI_united_front_leader = {
			country_event = china.106
			add_to_faction = ROOT
		}
		PRC = { add_opinion_modifier = { target = event_target:CHI_united_front_leader modifier = unstable_alliance } }
		event_target:CHI_united_front_leader = { add_opinion_modifier = { target = PRC modifier = unstable_alliance } }	
		add_to_war = {
			targeted_alliance = event_target:CHI_united_front_leader
			enemy = JAP
		}
		if = {
			limit = { NOT = { has_war_with = SOV } }
			custom_effect_tooltip = china.104_PRC_SOV_reinforcements
		}
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_completed_focus = PRC_found_our_nation
					}
				}
				drop_cosmetic_tag = yes
				set_cosmetic_tag = GCDsgn
				division_template = {
					name = "Erjinzhi Juntuán"			# Binary Infantry Corps
					division_names_group = PRC_INF_01
				
					regiments = {
						infantry = { x = 0 y = 0 }
						infantry = { x = 0 y = 1 }
						infantry = { x = 1 y = 0 }
						infantry = { x = 1 y = 1 }
					}
				}
				if = {
					limit = {
						OR = {
							controls_state = 621
							any_allied_country = {
								controls_state = 621
							}
						}
					}
					621 = {
						create_unit = { 
							division = "name = \"Su Jun Zhiyuanjun\" division_template = \"Erjinzhi Juntuán\""
							owner = ROOT
							count = 1
							allow_spawning_on_enemy_provs = yes
							prioritize_location = 2087
						}   
						create_unit = { 
							division = "name = \"Su Jun Zhiyuanjun\" division_template = \"Erjinzhi Juntuán\""
							owner = ROOT
							count = 3
							allow_spawning_on_enemy_provs = yes
							prioritize_location = 12609
						}   
						create_unit = { 
							division = "name = \"Su Jun Zhiyuanjun\" division_template = \"Erjinzhi Juntuán\""
							owner = ROOT
							count = 1
							allow_spawning_on_enemy_provs = yes
							prioritize_location = 12880
						}   
					}
				}
			}
		}
		add_ideas = KMT_united_front
		every_other_country = {
			limit = {
				OR = {
					tag = event_target:CHI_united_front_leader
					tag = SHX
					tag = XSM
					tag = YUN
					tag = GXC
				}
				NOT = {
					has_war_together_with = JAP
					is_in_faction_with = JAP
					is_puppet_of = JAP
				}
				has_war_with = ROOT
			}
			white_peace = ROOT
		}
	}

	#Nothing
	option = {
		ai_chance = { 
			base = 0
		}
		trigger = {
			NOT = {
				has_completed_focus = PRC_unite_against_the_jap
			}
		}
		name = china.104.b
		set_global_flag = PRC_no_join
	}
}

# China - Info that PRX has joined faction
country_event = {
	id = china.106
	title = china.106.t
	desc = china.106.d
	picture = GFX_report_event_chinese_army_training

	is_triggered_only = yes

	option = {
		name = china.106.a
		CHI = { 
			add_to_faction = FROM
		}
		FROM = {
			add_to_war = {
				targeted_alliance = CHI
				enemy = JAP
			}
		}
	}

}

# China and Japan no longer at war - Break up faction and Mao claims his part of China
country_event = {
	id = china.107
	title = china.107.t
	desc = {
		text = china.107.d_PRC_joined
		trigger = { 
			PRC = { 
				has_country_flag = PRC_joined_CHI_against_JAP 
			} 
		} 
	}
	desc = {
		text = china.107.d_PRC_refused
		trigger = { 
			PRC = { 
				NOT = { has_country_flag = PRC_joined_CHI_against_JAP } 
			} 
		}
	}

	picture = GFX_report_event_generic_sign_treaty1

	fire_only_once = yes

	trigger = {
					  
		tag = CHI
		PRC = {
			has_country_flag = PRC_joined_CHI_against_JAP
			is_puppet = no
			NOT = {
				has_war_with = JAP
			}
		}
		NOT = {
			has_war_with = JAP
		}
		is_puppet = no
	}

	mean_time_to_happen = {
		days = 10
	}
	
	immediate = { set_global_flag = no_longer_united }					   

	option = {
		name = china.107.a
		if = {
			limit = { NOT = { PRC = { has_country_flag = PRC_joined_CHI_against_JAP } } }
			dismantle_faction = yes
			PRC = { remove_opinion_modifier = { target = CHI modifier = unstable_alliance } }
			CHI = { remove_opinion_modifier = { target = PRC modifier = unstable_alliance } }			
		}

		if = {
			limit = {
				PRC = { has_country_flag = PRC_joined_CHI_against_JAP }
			}
			hidden_effect = {
				PRC = { country_event = { id = china.111 } }
			}
			effect_tooltip = {
				dismantle_faction = yes
				PRC = { remove_opinion_modifier = { target = CHI modifier = unstable_alliance } }
				CHI = { remove_opinion_modifier = { target = PRC modifier = unstable_alliance } }				
			}
		}
	}
}

# Restart Chinese civil war - Communist supporters reinforces the PRC army
country_event = {
	id = china.108
	title = china.108.t
	desc = china.108.d
	picture = GFX_report_event_chinese_army_training
	
	is_triggered_only = yes

	immediate = {
		set_global_flag = PRC_restart_chinese_civil_war
	}
	
	fire_only_once = yes

	option = {
		name = china.108.a
		custom_effect_tooltip = china.108_PRC_SOV_reinforcements_2
		hidden_effect = {
			add_equipment_to_stockpile = { type = artillery_equipment_1 amount = 200 producer = SOV }
			add_equipment_to_stockpile = { type = infantry_equipment_1 amount = 6000 producer = SOV }
			if = {
				limit = {
					OR = {
						controls_state = 621
						CHI = {
							OR = {
								controls_state = 621
								any_allied_country = {
									controls_state = 621
								}
							}
						}
					}
				}
				division_template = {
					name = "Erjinzhi Juntuán"			# Binary Infantry Corps
					division_names_group = PRC_INF_01
				
					regiments = {
						infantry = { x = 0 y = 0 }
						infantry = { x = 0 y = 1 }
						infantry = { x = 1 y = 0 }
						infantry = { x = 1 y = 1 }
					}
				}
				621 = {
					create_unit = { 
						division = "name = \"Su Jun Zhiyuanjun\" division_template = \"Erjinzhi Juntuán\""
						owner = ROOT
						count = 6
						allow_spawning_on_enemy_provs = yes
						prioritize_location = 2087
					}  
					create_unit = { 
						division = "name = \"Su Jun Zhiyuanjun\" division_template = \"Erjinzhi Juntuán\""
						owner = ROOT
						count = 6
						allow_spawning_on_enemy_provs = yes
						prioritize_location = 12609
					}
					create_unit = { 
						division = "name = \"Su Jun Zhiyuanjun\" division_template = \"Erjinzhi Juntuán\""
						owner = ROOT
						count = 4
						allow_spawning_on_enemy_provs = yes
						prioritize_location = 12331
					}
					create_unit = { 
						division = "name = \"Su Jun Zhiyuanjun\" division_template = \"Erjinzhi Juntuán\""
						owner = ROOT
						count = 4
						allow_spawning_on_enemy_provs = yes
						prioritize_location = 12880
					}
				}
			}
			set_global_flag = PRC_restart_CHI_war
			if = {
				limit = {
					NOT = {
						has_completed_focus = PRC_found_our_nation
					}
				}
				drop_cosmetic_tag = yes
				set_cosmetic_tag = GCDcivilwar
			}		 
		}
	}
}

# China and Japan no longer at war - Break up faction and Mao claims his part of China
country_event = {
	id = china.111
	title = china.111.t
	desc = china.111.d
	picture = GFX_report_event_generic_sign_treaty1

	is_triggered_only = yes

	option = {
		name = china.111.a
		CHI = { 
			dismantle_faction = yes
			hidden_effect = {
				remove_opinion_modifier = { target = PRC modifier = unstable_alliance }
			}
		}
		hidden_effect = {
			PRC = { remove_opinion_modifier = { target = CHI modifier = unstable_alliance } }
		}
		add_ideas = kmt_planning_the_civil_war
		CHI = {
			add_ideas = KMT_chinese_matter
		}
	}
}

#CHI event - PRC takes control of a CHI state - Communist uprising
country_event = {
	id = china.202
	title = china.202.t
	desc = china.202.d
	picture = GFX_report_event_chinese_soldiers

	trigger = {
		original_tag = CHI
		communism > 0.2
		has_government = neutrality
		has_idea = CHI_communist_uprisings
		PRC = {
			exists = yes
			has_government = communism
		}
	}

	mean_time_to_happen = {
		days = 270
		modifier = {
			factor = 0.5
			communism > 0.3
		}
	}

	immediate = {
		hidden_effect = {
			random_owned_controlled_state = {
				limit = {
					any_neighbor_state = {
						owner = { tag = PRC }
					}
				}
				save_event_target_as = CHI_communist_state
			}
		}
	}

	option = {
		name = china.202.a
		PRC = {
			transfer_state = event_target:CHI_communist_state
			country_event = { id = china.203 days = 1 }
		}
		add_popularity = {
			ideology = communism
			popularity = -0.15
		}
	}
}

#PRC event - takes control of a CHI state - Communist uprising
country_event = {
	id = china.203
	title = china.203.t
	desc = china.203.d
	picture = GFX_report_event_chinese_soldiers

	is_triggered_only = yes

	option = {
		name = china.203.a
		effect_tooltip = {
			CHI = {
				add_popularity = {
					ideology = communism
					popularity = -0.15
				}		
			}
		}
	}
}

#Move capital if PRC controls beijing or nanjing
country_event = {
	id = china.204
	title = china.204.t
	desc = china.204.d
	picture = GFX_report_event_chinese_soldiers

	fire_only_once = yes

	is_triggered_only = yes

	#Move to Beijing
	option = {
		name = china.204.a
		ai_chance = {
			base = 90
			modifier = {
				factor = 0
				NOT = { 608 = { is_controlled_by = PRC } }
			}
		}
		trigger = {
			controls_state = 608
		}
		transfer_state = 608
		set_capital = { state = 608 }
		set_country_flag = prc_capital_decided
		set_rule = {
			can_send_volunteers = yes
			can_puppet = yes
		}
	}

	#Move to Nanjing
	option = {
		name = china.204.b
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				NOT = { 613 = { is_controlled_by = PRC } }
			}
		}
		trigger = {
			controls_state = 613
		}
		transfer_state = 613
		set_capital = { state = 613 }
		set_country_flag = prc_capital_decided
		set_rule = {
			can_send_volunteers = yes
			can_puppet = yes
		}
	}

	#Stay where you are
	option = {
		name = china.204.c
		ai_chance = {
			base = 0
			modifier = {
				add = 1
				NOT = { 608 = { is_controlled_by = PRC } }
				NOT = { 613 = { is_controlled_by = PRC } }
			}			
		}
		trigger = {
			controls_state = 622
		}
		set_country_flag = prc_capital_decided
		set_rule = {
			can_send_volunteers = yes
			can_puppet = yes
		}
	}
}

