#Category only allowed for CHI
CHI_anti_imperialism = {
	
	CHI_release_korea = {

		icon = generic_nationalism
		allowed = {
			original_tag = CHI
		}
		available = {
			country_exists = KOR
			country_exists = NKR
		}

		days_mission_timeout = 180

		fire_only_once = yes
		activation = {			
			owns_state = 525
			owns_state = 527
			owns_state = 917
			owns_state = 918
			owns_state = 919
			owns_state = 920
			KOR = {
				exists = no
			}
			NKR = {
				exists = no
			}
			has_completed_focus = CHI_commit_to_korean_independence
		}

		visible = {
			owns_state = 525
			owns_state = 527
			owns_state = 917
			owns_state = 918
			owns_state = 919
			owns_state = 920
			KOR = {
				exists = no
			}
			NKR = {
				exists = no
			}
			has_completed_focus = CHI_commit_to_korean_independence
		}
		complete_effect = {
			add_political_power = 50
		}
		timeout_effect = {
			add_stability = -0.1 #naughty
		}
	}
}

# NEW CATEGORY TO WORK WITH THE CHINESE NATIONAL FOCUS MOD

CHI_improve_the_army_situation = {
	CHI_improve_the_NRA = {

		icon = GFX_decision_icon_kuomintang

		custom_cost_text = chi_improve_the_nra_decision	
		custom_cost_trigger = {
			has_army_experience > 99
		}

		available = {
			has_army_experience > 99
		}

		cost = 0

		days_remove = 90
		
		ai_will_do = {
			factor = 500 #do it cause we need it!
		}

		visible = {
			OR = {
				has_idea = KMT_weak_army
				has_idea = KMT_weak_army_lesser
				has_idea = KMT_weak_army_lesserer
			}
		}
		remove_effect = {
			if = {
				limit = { has_idea = KMT_weak_army }
				swap_ideas = {
					remove_idea = KMT_weak_army
					add_idea = KMT_weak_army_lesser
				}
			}
			else_if = {
				limit = { has_idea = KMT_weak_army_lesser }
				swap_ideas = {
					remove_idea = KMT_weak_army_lesser
					add_idea = KMT_weak_army_lesserer
				}
			}
			else_if = {
				limit = { has_idea = KMT_weak_army_lesserer }
				remove_ideas = KMT_weak_army_lesserer
			}
		}
		complete_effect = {
			army_experience = -100
						
		}		
	}	
}

CHI_war_of_resistance = {

	CHI_prioritize_external_threat = {

		icon = hol_exchange_intelligence_data

		allowed = {
			original_tag = CHI
		}

		available = {
			has_defensive_war_with = JAP
			OR = {
				has_war_with = PRC
				has_war_with = GXC
				has_war_with = SHX
				has_war_with = XSM
				has_war_with = YUN
			}
		}

		visible = {
			has_defensive_war_with = JAP
			OR = {
				has_war_with = PRC
				has_war_with = GXC
				has_war_with = SHX
				has_war_with = XSM
				has_war_with = YUN
			}
		}

		cost = 0

		fire_only_once = yes

		ai_will_do = {
			factor = 100
		}

		days_remove = 14

		modifier = {
			political_power_gain = -0.25
		}
		complete_effect = {
			add_stability = -0.05
			add_war_support = 0.1
		}

		remove_effect = {
			every_country = {
				limit = {
					has_war_with = CHI
					OR = {
						tag = PRC
						tag = GXC
						tag = SHX
						tag = XSM
						tag = YUN
					}
				}
				country_event = { id = kmt.186 hours = 2 }
			}
		}
	}

	CHI_united_front_strategy = {

		icon = hol_draw_up_staff_plans

		allowed = {
			original_tag = CHI
		}

		available = {
			has_defensive_war_with = JAP
			has_completed_focus = KMT_external_defense
			NOT = { has_global_flag = CHI_unite }
			NOT = { has_global_flag = CHI_no_national_front_flag }
		}

		cost = 0

		fire_only_once = yes

		days_remove = 10

		ai_will_do = {
			factor = 500 #do it cause we need it!
		}

		modifier = {
			political_power_factor = -0.05
		}

		cancel_trigger = {
			OR = {
				is_in_faction = yes		#prevents faction betrayal
				has_war = no			#no war = no issue
			}
		}
		
		remove_effect = {
			if = {
				limit = {
					is_in_faction = no
				}
				set_rule = { can_create_factions = yes }
				create_faction = chinese_united_front
			}
			add_ideas = KMT_united_front
			#load_oob = "CHI_united_front"
			set_global_flag = CHI_unite
			set_global_flag = CHI_unite_PRC
			every_other_country = {
				limit = {
					is_subject_of = ROOT
				}
				add_to_faction = PREV
			}
			save_event_target_as = CHI_united_front_leader
			hidden_effect = {				#they all fire at the same, meaning that AI should not join some random wars against each other
				if = {
					limit = {
						OR = {
							AND = {
								event_target:CHI_united_front_leader = { has_country_flag = CHI_hostile_against_warlords }
								NOT = {
									has_global_flag = CHI_no_national_front_flag
								}
							}
							has_global_flag = CHI_unite_PRC
						}
						PRC = {
							exists = yes
							OR ={							#no release of subjects + calling warlord subjects in to prevent frontline exploits
								is_subject = no
								is_subject_of = ROOT
							}
							NOT = { has_war_with = ROOT }
							is_in_faction = no				#no faction betrayal
						}
					}
					PRC = {
						country_event = china.104
					}
				}
				if = {
					limit = {
						NOT = { has_country_flag = popular_front_fired }
						has_global_flag = CHI_unite
						NOT = { has_country_flag = CHI_hostile_against_warlords }
						JAP = { has_offensive_war = yes }							#a little extra check here
					}
					every_other_country = {
						limit = {
							OR = {
								tag = GXC
								tag = YUN
								tag = XSM
								tag = SHX	#no Sinkiang or Tunganistan - theycan use decisions later to join the struggle -	#Fantom
							}
							OR ={							#no release of subjects + calling warlord subjects in to prevent frontline exploits
								is_subject = no
								is_subject_of = ROOT
							}
							NOT = { has_war_with = ROOT }
							is_in_faction = no				#no faction betrayal
						}
						country_event = china.101
					}
				}
			}
		}
	}

	CHI_prepare_provisional_capital = {

		icon = SOV_place_hq

		allowed = {
			original_tag = CHI
		}

		visible = {
			controls_state = 605
		}

		available = {
			has_war = yes
			owns_state = 605
			has_full_control_of_state = 605
			613 = {
				OR ={
					NOT ={
						is_fully_controlled_by = ROOT
					}
					any_neighbor_state = {
						NOT ={
							is_controlled_by = ROOT
						}
					}
				}
			}
		}

		cost = 15

		fire_only_once = yes

		days_remove = 20

		highlight_states = {
 			highlight_state_targets = { state = 605 }
		}

		ai_will_do = {
			factor = 10
		}

		modifier = {
			consumer_goods_factor = 0.2
			
		}
		complete_effect = {
			add_war_support = 0.05				#we will fight until the end, hurra!
			605 = {
				add_building_construction = {
					type = supply_node
					level = 1
					province = 6999
					instant_build = yes
				}
			}
			add_victory_points = {
				province = 6999
				value = 5
			}
		}
		remove_effect = {
			# Chongqing - Xi'an
			build_railway = {
				path = { 6999 1893 11865 10144 7418 7406 7301 }
			}
			# Chongqing - Changsha
			build_railway = {
				path = { 6999 4431 1010 9939 1474 10006 7279 7101 10517 7097 }
			}
		}
	}
	
	CHI_Huayuankou_embankment_breach_incident = { #CHI_breach_the_yellow_river, but lets use the name we gave it:D - Fantom
		icon = GFX_decision_hol_inundate_water_lines
		
		available = {
			has_war = yes
			NOT = {
				has_full_control_of_state = 607
			}
			OR = {
				NOT = { controls_state = 608 }
				NOT = { controls_state = 614 }
				NOT = { controls_state = 597 }
				NOT = { controls_state = 598 }
				NOT = { controls_state = 606 }
			}
		}

		highlight_states = {
 			highlight_state_targets = { state = 607 } 
			highlight_provinces = {
				7656
				9958
				1004
			}
		}
		
		visible = {
			controls_state = 607
			is_literally_china = yes
			NOT = { has_global_flag = chi_yellow_river_blown } #So warlords don't do this too
		}
		
		fire_only_once = yes
		
		cost = 50	#originally 20

		ai_will_do = {
			base = 0
			#Pretty damn important
			modifier = {
				add = 25
				NOT = { controls_state = 608 }
			}
			modifier = {
				add = 25
				NOT = { controls_state = 614 }
			}
			modifier = {
				add = 25
				NOT = { controls_state = 597 }
			}
			modifier = {
				add = 25
				NOT = { controls_state = 598 }
			}
			modifier = {
				add = 25
				NOT = { controls_state = 606 }
			}
		}

		days_remove = 3
		
		complete_effect = {
			add_war_support = -0.05
		}

		remove_effect = {
			every_owned_state = {
				limit = {
					OR = {
						state = 606
						state = 607
						state = 598
						state = 597
					}
				}
				add_dynamic_modifier = {
					modifier = yellow_river_blown
					days = 730 
				}
				damage_building = {	#r56 effect - stuff get damaged too! - Fantom
					type = infrastructure
					damage = 4
				}
				damage_building = {
					type = industrial_complex
					damage = 1.5
				}
			}
			hidden_effect = { 
				news_event = { id = news.409 } 
				set_global_flag = chi_yellow_river_blown
			}
		}
	}

	CHI_scorched_earth_policy = {

		icon = generic_scorched_earth

		on_map_mode = map_only

		allowed = {
			is_literally_china = yes
		}

		available = {
			has_war = yes
			OR = {
				surrender_progress > 0.25
				focus_progress = {
					focus = KMT_lure_them_in_strategy
					progress > 0
				}
			}
		}

		custom_cost_text = r56_10_command_power_cost	
		custom_cost_trigger = {
			command_power > 9.99			
		}

		fire_only_once = yes

		state_target = yes

		target_trigger = {
			FROM = {
				is_owned_by = ROOT
				controller = {
					has_offensive_war_with = ROOT
					NOT = {
						has_full_control_of_state = FROM
					}
				}
				NOT = {
					has_state_flag = scorched
				}
			}
		}

		ai_will_do = {
			factor = 2
		}

		days_remove = 7

		complete_effect = {
			add_command_power = -10	
			add_war_support = -0.01
		}
		remove_effect = {
			FROM = {
				damage_building = {
					type = infrastructure
					damage = 2
				}
				damage_building = {
					type = rail_way
					damage = 2
				}
				damage_building = {
					type = industrial_complex
					damage = 1
				}
				damage_building = {
					type = arms_factory
					damage = 1
				}
				set_state_flag = scorched
			}
		}
	}

	CHI_redirect_investments_for_burma_road = {

		icon = generic_industry

		allowed = {
			is_literally_china = yes
		}

		available = {
			has_war = yes
			focus_progress = {
				focus = KMT_improve_burma_road
				progress > 0.25
			}
			NOT = {
				has_completed_focus = KMT_improve_burma_road
			}
		}

		visible = {
			focus_progress = {
				focus = KMT_improve_burma_road
				progress > 0
			}
		}

		cost = 10

		fire_only_once = yes

		ai_will_do = {
			factor = 1
		}

		days_remove = 15

		modifier = {
			consumer_goods_factor = 0.04
		}
		complete_effect = {
			set_country_flag = KMT_burma_rd_forts
			custom_effect_tooltip = KMT_burma_rd_forts_tt
		}

		remove_effect = {
			army_experience = 5
			add_war_support = 0.03
		}
	}

	CHI_join_united_front = {
		icon = icon_kuomintang
		available = {
			is_literally_china = yes
			CHI = {
				is_in_faction_with = PRC
			}
			OR = {
				PRC = {
					is_faction_leader = yes
				}
				CHI = {
					is_faction_leader = yes
				}
			}
			NOT = {
				OR = {
					has_war_with = CHI
					has_war_with = PRC
				}
			}
			is_in_faction = no
			NOT = {
				has_completed_focus = CHI_opposition
			}
			OR = {
				is_subject = no
				OVERLORD = {
					is_in_faction_with = event_target:WTT_current_china_leader
				}
			}
			if = {			#sort out your differences first, buddies
				limit = {
					OR = {
						original_tag = SIK
						original_tag = TNG
					}
				}
				NOT = {
					has_idea = GEN_personal_affair
				}
			}
		}
		visible = {
			is_literally_china = yes
			CHI = {
				is_in_faction_with = PRC
			}
			is_in_faction = no
			NOT = {							#sanity check - if event about China uniting has fired and you picked other option, you have sealed your fate
				has_country_flag = popular_front_fired
			}
			NOT = {							#you tried once, this will not work again
				has_country_flag = ROOT_tried_to_join_united_front
			}
		}
		cost = 25
		ai_will_do = {
			factor = 1
			modifier = {
				CHI = {
					has_war_with = JAP 
					has_defensive_war = yes
				}
				factor = 10
			}
			modifier = {
				PRC = {
					has_war_with = JAP 
					has_defensive_war = yes
				}
				factor = 10
			}
			modifier = {
				has_war_with = JAP
				factor = 500
			}
			modifier = {
				original_tag = SIK
				date < 1942.10.5
				factor = 0
			}
			modifier = {
				original_tag = TNG
				date < 1939.4.12
				factor = 0
			}
			modifier = {
				OR = {
					original_tag = SIK
					original_tag = TNG
				}
				has_war = yes
				factor = 0
			}
		}

		fire_only_once = yes

		complete_effect = {
			set_country_flag = ROOT_tried_to_join_united_front
			If = {
				limit = {
					CHI = {
						is_faction_leader = yes
					}
				}
				CHI = {
					country_event = china.106
				}
				add_ai_strategy = {
					type = alliance
					id = "CHI"
					value = 200
				}
			}
			else_if = {
				limit = {
					PRC = {
						is_faction_leader = yes
					}
				}
				PRC = {
					country_event = china.106
				}
				add_ai_strategy = {
					type = alliance
					id = "PRC"
					value = 200
				}
			}
		}
	}

	CHI_strife_for_survival = {

		icon = generic_civil_support

		allowed = {
			original_tag = CHI
		}

		available = {
			has_defensive_war = yes
			OR = {
				surrender_progress > 0.29
				AND = {
					608 = {
						controller = { has_war_with = ROOT }
					}
					613 = {
						controller = { has_war_with = ROOT }
					}
				}
			}
		}

		cost = 25

		fire_only_once = yes

		days_remove = 30

		ai_will_do = {
			factor = 500 #do it cause we need it!
		}

		modifier = {
			political_power_factor = -0.1
		}
		
		remove_effect = {
			add_ideas = KMT_fight_for_survival
		}
	}

	CHI_most_desperate_hours = {

		icon = generic_civil_support

		allowed = {
			original_tag = CHI
		}

		visible = {
			has_idea = KMT_fight_for_survival
		}

		available = {
			has_defensive_war = yes
			has_idea = KMT_fight_for_survival
			surrender_progress > 0.49
		}

		cost = 50

		fire_only_once = yes

		days_remove = 30

		ai_will_do = {
			factor = 500	#Do it!
		}

		modifier = {
			political_power_factor = -0.2
		}
		
		remove_effect = {
			swap_ideas = {
				remove_idea = KMT_fight_for_survival
				add_idea = KMT_fight_for_survival_2
			}
		}
	}
}

#completed "the Chinese Ports"
CHI_unequal_treaties = {
	CHI_dealing_with_trade_port_decision = {
		icon = {
			key = eng_trade_unions_support
			trigger = {
				FROM = {
					controller = {
						has_government = ROOT
					}
				}
			}
		}
		icon = {
			key = onmap_recruit_operative
			trigger = {
				FROM = {
					controller = {
						NOT = {
							has_government = ROOT
						}
					}
				}
			}
		}

		icon = onmap_recruit_operative

		allowed = {
			is_literally_china = yes
		}
		visible = {	#hide if you own those
			FROM = {
				NOT = {
					is_owned_by = ROOT
				}
			}
		}

		available = {
			is_subject = no
			has_completed_focus = KMT_trade_port_fascism
			FROM = {
				any_neighbor_state = {
					controller = {
						OR = {
							original_tag = ROOT
							is_in_faction_with = ROOT
							is_subject_of = ROOT
						}
					}
				}
			}
		}

		state_target = yes
		target_trigger = {
			FROM = {
				OR = {
					state = 728
					state = 729
					state = 326
					state = 743
					state = 745	#Dailan just in case smth weird happens and you get Manchuria. Concession anyway, so better get that too
				}
			}
		}

		cost = 25

		fire_only_once = yes

		days_remove = 14

		ai_will_do = {
			factor = 500	#Do it!
		}

		modifier = {
			command_power_gain = -0.5
		}
		
		remove_effect = {
			ROOT = {
				save_event_target_as = TAG_trying_to_get_the_port
			}
			FROM = {
				save_event_target_as = STATE_OF_THE_PORT
			}
			FROM = {
				controller = {
					save_event_target_as = TAG_someone_trying_to_steal_trade_port_from_us
				}
			}
			if = {
				limit = {
					FROM = {
						controller = {
							has_government = ROOT
						}
					}
				}
				FROM = {
					controller = {	
						country_event = {
							id = kmt.148 hours = 12
						}
					}
				}
			}
			else = {
				hidden_effect = {
					set_temp_variable = {
						var = coup_success_var
						value = stability@ROOT
					}
					set_temp_variable = {
						var = coup_fail_var
						value = 1
					}
					subtract_from_temp_variable = {
						var = coup_fail_var
						value = coup_success_var 
					}
				}
				custom_effect_tooltip = CHI_success_chance_depends_on_stability_tt
				random_list = {
					coup_success_var = {
						every_country = {
							limit = {
								OR = {
									original_tag = ROOT
									controls_state = FROM
								}
							}
							country_event = {
								id = kmt.146  ##success
							}
						}
					}
					coup_fail_var = {
						every_country = {
							limit = {
								OR = {
									original_tag = ROOT
									controls_state = FROM
								}
							}
							country_event = {
								id = kmt.147  ##fail
							}
						}
					}
				}
			}
		}
	}
}

#completed "Oust the colonisers"
CHI_liberation_of_asia = {
	CHI_liberate_country = {

		icon = generic_civil_support

		target_non_existing = yes
		#target_array = occupied_countries

		target_trigger = {
			FROM = {
				NOT = {
					is_literally_china = yes
					original_tag = FRI
				}
				any_state = {
					OR = {
						region = 190
						region = 153
						region = 31
						region = 141
						region = 189
						region = 142
						region = 188
						region = 187
						region = 158
						region = 159
						region = 93
						region = 167
						region = 160
						state = 323
						state = 1091
					}
					is_core_of = FROM
					is_controlled_by = ROOT
				}
			}
		}

		days_remove = 60

		fire_only_once = yes

		available = {
			FROM = {
				all_state = {
					compliance > 30
					OR = {
						is_fully_controlled_by = ROOT
						NOT = {
							is_core_of = FROM
							custom_trigger_tooltip = {
								tooltip = state_in_indochina_malaysia_indonesia_raj_tt
								AND = {
									region = 190
									region = 153
									region = 31
									region = 141
									region = 189
									region = 142
									region = 188
									region = 187
									region = 158
									region = 159
									region = 93
									region = 167
									region = 160
									state = 323
									state = 1091
								}
							}
						}
					}
				}
			}
		}
		
		modifier = {
			political_power_gain = -0.2
		}

		remove_effect = {
			release = FROM
			every_controlled_state = {
				limit = {
					is_core_of = FROM
				}
				FROM = {
					transfer_state = PREV
				}
			}
			FROM = {
				set_politics = {
					ruling_party = fascism
				}
				hidden_effect = {
					add_popularity = {
						ideology = fascism
						popularity = 0.5
					}
				}
			}
			every_country = {
				limit = {
					has_war_together_with = CHI
				}
				FROM = {
					give_military_access = PREV
				}
			}
			set_autonomy = {
				target = FROM
				autonomy_state = autonomy_wtt_imperial_protectorate
			}
			FROM = {
				division_template = {
					name = "Difang Minbing"
					priority = 2
					division_names_group = CHI_INF_01
					regiments = {
						militia = { x = 0 y = 0 }
						militia = { x = 0 y = 1 }
						militia = { x = 0 y = 2 }
		
						militia = { x = 1 y = 0 }
						militia = { x = 1 y = 1 }
					}
				}
			}
			custom_effect_tooltip = CHI_raises_five_miltiia_divisions_tt
			hidden_effect = {
				FROM = {
					random_controlled_state = {
						create_unit = {
							division = "name = \"1. Difang Minbing\" division_template = \"Difang Minbing\" start_experience_factor = 0.51" 
							owner = FROM
						}
						create_unit = {
							division = "name = \"2. Difang Minbing\" division_template = \"Difang Minbing\" start_experience_factor = 0.42" 
							owner = FROM
						}
						create_unit = {
							division = "name = \"3. Difang Minbing\" division_template = \"Difang Minbing\" start_experience_factor = 0.63" 
							owner = FROM
						}
						create_unit = {
							division = "name = \"4. Difang Minbing\" division_template = \"Difang Minbing\" start_experience_factor = 0.63" 
							owner = FROM
						}
						create_unit = {
							division = "name = \"5. Difang Minbing\" division_template = \"Difang Minbing\" start_experience_factor = 0.63" 
							owner = FROM
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 100	#hey, we are good guys!
		}
	}

	CHI_asia_decolonized = {
		icon = generic_political_discourse

		fire_only_once = yes

		available = {
			is_subject = no
			surrender_progress < 0.01
			all_state = {
				OR = {
					NOT = { 
						custom_trigger_tooltip = {
							tooltip = state_not_in_indochina_malaysia_indonesia_raj_tt
							OR = {
								region = 190
								region = 153
								region = 31
								region = 141
								region = 189
								region = 142
								region = 188
								region = 187
								region = 158
								region = 159
								region = 93
								region = 167
								region = 160
								state = 323
								state = 1091
							}
						}
					}
					is_controlled_by_ROOT_or_ally = yes
				}
			}
		}
		
		days_remove = 180

		modifier = {
			political_power_gain = -0.5
			stability_weekly = -0.002
		}

		remove_effect = {
			every_other_country = {
				limit = {
					has_war_with = ROOT
					is_subject = no
				}
				country_event = {id = kmt.266 }
			}
		}
	}
}

#Category allowed for all potential nationalist china
#Category visible when CHI_army_reform focus is completed
CHI_army_reform = {

	CHI_army_reform = {

		icon = generic_prepare_civil_war

		available = {
			has_army_experience > 99
			has_completed_focus = KMT_modernize_army
		}

		cost = 0
		ai_will_do = {
			factor = 500
		}
		days_remove = 90

		visible = {
			OR = {
				has_idea = CHI_army_corruption_1
				has_idea = CHI_army_corruption_2
				has_idea = CHI_army_corruption_3
			}
		}
		remove_effect = {
			if = {
				limit = { has_idea = CHI_army_corruption_1 }
				swap_ideas = {
					remove_idea = CHI_army_corruption_1
					add_idea = CHI_army_corruption_2
				}
			}
			else_if = {
				limit = { has_idea = CHI_army_corruption_2 }
				swap_ideas = {
					remove_idea = CHI_army_corruption_2
					add_idea = CHI_army_corruption_3
				}
			}
			else_if = {
				limit = { has_idea = CHI_army_corruption_3 }
				remove_ideas = CHI_army_corruption_3
			}
		}
		complete_effect = {
			army_experience = -100
			custom_effect_tooltip = 90_days_tt
						
		}		
	}

}

economy_decisions = {
	CHI_expand_industrial_capabilities = {

		icon = generic_construction

		allowed = {
			is_literally_china = yes
		}

		available = {
			command_power > 10
			if = {
				limit = {
					OR = {
						has_idea = incompetent_industry_real
						has_idea = incompetent_industry_real_navy
					}
				}
				has_tech = basic_machine_tools
				OR = {
					has_tech = concentrated_industry
					has_tech = dispersed_industry
				}
				has_tech = construction1
				OR = {
					AND = {
						num_of_factories > 40 #was 50
						has_war = no
					}
					AND = {
						num_of_factories > 50 #was 65
						has_defensive_war = yes
					}
					AND = {
						num_of_factories > 65 #was 75
						has_offensive_war = yes
					}
				}
				amount_research_slots > 2
			}
			if = {
				limit = {
					OR = {
						has_idea = incompetent_industry_real_2
						has_idea = incompetent_industry_real_2_navy
					}
				}
				has_tech = improved_machine_tools
				OR = {
					has_tech = concentrated_industry2
					has_tech = dispersed_industry2
				}
				has_tech = construction2
				OR = {
					AND = {
						num_of_factories > 70
						has_war = no
					}
					AND = {
						num_of_factories > 80
						has_defensive_war = yes
					}
					AND = {
						num_of_factories > 90
						has_offensive_war = yes
					}
				}
				amount_research_slots > 3
			}
			if = {
				limit = {
					OR = {
						has_idea = incompetent_industry_real_3
						has_idea = incompetent_industry_real_3_navy
					}
				}
				has_tech = advanced_machine_tools
				OR = {
					has_tech = concentrated_industry3
					has_tech = dispersed_industry3
				}
				has_tech = construction3
				OR = {
					AND = {
						num_of_factories > 90
						has_war = no
					}
					AND = {
						num_of_factories > 115
						has_defensive_war = yes
					}
					AND = {
						num_of_factories > 125
						has_offensive_war = yes
					}
				}
				has_idea = incompetent_industry_real_3
				amount_research_slots > 3
			}
			if = {
				limit = {
					OR = {
						has_idea = incompetent_industry_real_4
						has_idea = incompetent_industry_real_4_navy
					}
				}
				has_tech = assembly_line_production
				OR = {
					has_tech = concentrated_industry4
					has_tech = dispersed_industry4
				}
				has_tech = construction4
				OR = {
					AND = {
						num_of_factories > 110
						has_war = no
					}
					AND = {
						num_of_factories > 140
						has_defensive_war = yes
					}
					AND = {
						num_of_factories > 150
						has_offensive_war = yes
					}
				}
				has_idea = incompetent_industry_real_4
				amount_research_slots > 4
			}
			if = {
				limit = {
					OR = {
						has_idea = incompetent_industry_real_5
						has_idea = incompetent_industry_real_5_navy
					}
				}
				OR = {
					has_tech = flexible_line
					has_tech = streamlined_line
				}
				OR = {
					has_tech = concentrated_industry5
					has_tech = dispersed_industry5
				}
				has_tech = construction5
				OR = {
					AND = {
						num_of_factories > 130
						has_war = no
					}
					AND = {
						num_of_factories > 170
						has_defensive_war = yes
					}
					AND = {
						num_of_factories > 190
						has_offensive_war = yes
					}
				}
				has_idea = incompetent_industry_real_5
				amount_research_slots > 4
			}
		}

		visible = {
			OR = {
				has_idea = incompetent_industry_real_5
				has_idea = incompetent_industry_real_4
				has_idea = incompetent_industry_real_3
				has_idea = incompetent_industry_real_2
				has_idea = incompetent_industry_real
				has_idea = incompetent_industry_real_5_navy
				has_idea = incompetent_industry_real_4_navy
				has_idea = incompetent_industry_real_3_navy
				has_idea = incompetent_industry_real_2_navy
				has_idea = incompetent_industry_real_navy
			}
		}

		custom_cost_text = r56_10_command_power_cost
		custom_cost_trigger = {
			command_power > 10
		}

		ai_will_do = {
			factor = 750 #of course we want to have better industry!
		}

		days_remove = 30

		modifier = {
			consumer_goods_factor = 0.1
			political_power_gain = 0.15
		}

		complete_effect = {
			every_controlled_state = {
				limit = {
					is_core_of = ROOT
				}
				add_extra_state_shared_building_slots = 1
			}
		}

		remove_effect = {
			CHI_incompetent_industry_level_down = yes
		}
	}

	CHI_forced_loans = {

		icon = ger_mefo_bills

		available = {
			has_hyper_inflation = yes
		}

		cost = 100
		ai_will_do = {
			factor = 1
		}

		visible = {
			always = no
		}

		days_re_enable = 90

		complete_effect = {
			CHI_hyper_inflation_level_down = yes
			add_stability = -0.03
			add_war_support = -0.03
		}		
	}
}

war_measures = {

	CHI_scorched_earth_tactics = {
		icon = generic_scorched_earth
		allowed = {
			original_tag = CHI
		}
		available = {
			any_owned_state = {
				is_controlled_by = ROOT
				any_neighbor_state = {
					NOT = { is_fully_controlled_by = ROOT }
					controller = { has_war_with = CHI }
				}
			}
		}

		cost = 25

		ai_will_do = {
			factor = 1
		}

		visible = {			
			has_completed_focus = KMT_lure_them_in_strategy
		}

		days_re_enable = 30

		complete_effect = {
			every_owned_state = {
				limit = {
					is_controlled_by = ROOT
					infrastructure > 0
					any_neighbor_state = {
						NOT = { is_fully_controlled_by = ROOT }
						controller = { has_war_with = CHI }
					}
				}
				damage_building = {
					type = infrastructure
					damage = 3
				}
			}		
		}
	}
}


### #  # ###  #  #  ### ### ###  #   #    #### #   #  ##   ##  #  #  ##  ### ###  ##  #  #
 #  ## # #  # #  # #     #  #  #  # #     #    #   # #  # #  # #  # #  #  #   #  #  # ## #
 #  # ## #  # #  #   #   #  ###    #      ##    # #  #### #    #  # ####  #   #  #  # # ##
 #  #  # #  # #  #    #  #  #  #   #      #     # #  #  # #  # #  # #  #  #   #  #  # #  #
### #  # ###   ##  ###   #  #  #   #      ####   #   #  #  ##   ##  #  #  #  ###  ##  #  #

CHI_industrial_evacuations = {

	#Originally available for 283 591 592 593 594 595 596 597 598 599 600 602 606 607 608 613 614 616 620 743
	CHI_industrial_evacuations_from_FROM = { 
		icon = generic_scorched_earth
		available = {
			FROM = {
				OR = {
					arms_factory > 0
					industrial_complex > 0
				}
			}
		}
		highlight_states = {
			highlight_state_targets = {
				state = 283
				state = 591
				state = 592
				state = 593
				state = 594
				state = 595
				state = 596
				state = 597
				state = 598
				state = 599
				state = 600
				state = 602
				state = 606
				state = 607
				state = 608
				state = 613
				state = 614
				state = 616
				state = 620
				state = 743			
			}
		}
		on_map_mode = map_and_decisions_view

		state_target = yes
		target_root_trigger = {
			has_completed_focus = CHI_industrial_evacuations
		}
		target_trigger = {	#originally were 283 591 592 593 594 595 596 597 598 599 600 602 606 607 608 613 614 616 620 743
			FROM = {
				OR = {
					state = 283
					state = 591
					state = 592
					state = 593
					state = 594
					state = 595
					state = 596
					state = 597
					state = 598
					state = 599
					state = 600
					state = 602
					state = 606
					state = 607
					state = 608
					state = 613
					state = 614
					state = 616
					state = 620
					state = 743
				}
				is_controlled_by = ROOT
				OR ={
					NOT ={
						is_fully_controlled_by = ROOT
					}
					any_neighbor_state = {
						controller = {
							has_war_with = ROOT
						}
					}
				}
			}
		}
		visible = {
			has_completed_focus = CHI_industrial_evacuations	
		}

		fire_only_once = yes
		cost = 25

		days_remove = 15

		remove_effect = {
			if = {
				limit = {
					controls_state = FROM
				}
				FROM = {
					set_variable = {
						var = af_level
						value = arms_factory_level
					}
					set_variable = {
						var = af_to_move
						value = arms_factory_level
					}
					multiply_variable = {
						var = af_to_move
						value = global.CHI_industrial_evacuations_amount_factor
					}
	
					set_variable = {
						var = ic_level
						value = industrial_complex_level
					}
					set_variable = {
						var = ic_to_move
						value = industrial_complex_level
					}
					multiply_variable = {
						var = ic_to_move
						value = global.CHI_industrial_evacuations_amount_factor
					}
	
					custom_effect_tooltip = CHI_industrial_evacuations_remove_AF
					custom_effect_tooltip = CHI_industrial_evacuations_remove_IC
					hidden_effect = {				
						remove_building = {
							type = arms_factory
							level = af_level
						}
						remove_building = {
							type = industrial_complex
							level = ic_level
						}
					}
	
					#Move AF
					CONTROLLER = {
						random_owned_controlled_state = {
							prioritize = { 605 603 748 }
							limit = {
								is_fully_controlled_by = ROOT
								any_neighbor_state = {
									is_controlled_by = ROOT
								}
								free_building_slots = {
									building = arms_factory
									size > 2
									include_locked = yes
								}
							}
	
							custom_effect_tooltip = CHI_industrial_evacuations_add_AF						
							hidden_effect = {
								add_extra_state_shared_building_slots = af_to_move
								add_building_construction = {
									type = arms_factory
									level = af_to_move
									instant_build = yes
								}
								CONTROLLER = { set_country_flag = CHI_industrial_evacuations_moved_AF }
							}
						}
	
						#If no states are really safe or all safe are filled
						#Move to random controlled state
						if = {
							limit = {
								NOT = { has_country_flag = CHI_industrial_evacuations_moved_AF }
								NOT = {
									any_controlled_state = {
										is_fully_controlled_by = ROOT
										any_neighbor_state = {
											is_controlled_by = ROOT
										}
										free_building_slots = {
											building = arms_factory
											size > 2
											include_locked = yes
										}
									}
								}
							}
							random_owned_controlled_state = {
								prioritize = { 605 603 748 }
								limit = {
									is_controlled_by = ROOT
									free_building_slots = {
										building = arms_factory
										size > 2
										include_locked = yes
									}
								}
	
								custom_effect_tooltip = CHI_industrial_evacuations_add_AF						
								hidden_effect = {
									add_extra_state_shared_building_slots = af_to_move
									add_building_construction = {
										type = arms_factory
										level = af_to_move
										instant_build = yes
									}
								}
							}
						}
						clr_country_flag = CHI_industrial_evacuations_moved_AF
	
	
						#Move IC
						random_owned_controlled_state = {
							prioritize = { 605 603 748 }
							limit = {
								is_fully_controlled_by = ROOT
								any_neighbor_state = {
									is_controlled_by = ROOT
								}
								free_building_slots = {
									building = industrial_complex
									size > 2
									include_locked = yes
								}
							}
							
							custom_effect_tooltip = CHI_industrial_evacuations_add_IC
							hidden_effect = {
								add_extra_state_shared_building_slots = ic_to_move
								add_building_construction = {
									type = industrial_complex
									level = ic_to_move
									instant_build = yes
								}
								CONTROLLER = { set_country_flag = CHI_industrial_evacuations_moved_IC }
							}
						}
	
						#If no states are really safe or all safe are filled
						#Move to random controlled state
						if = {
							limit = {
								NOT = { has_country_flag = CHI_industrial_evacuations_moved_IC }
								NOT = {
									any_controlled_state = {
										is_fully_controlled_by = ROOT
										any_neighbor_state = {
											is_controlled_by = ROOT
										}
										free_building_slots = {
											building = industrial_complex
											size > 2
											include_locked = yes
										}
									}
								}
							}
							random_owned_controlled_state = {
								prioritize = { 605 603 748 }
								limit = {
									is_controlled_by = ROOT
									free_building_slots = {
										building = industrial_complex
										size > 2
										include_locked = yes
									}
								}
	
								custom_effect_tooltip = CHI_industrial_evacuations_add_IC
								hidden_effect = {
									add_extra_state_shared_building_slots = ic_to_move
									add_building_construction = {
										type = industrial_complex
										level = ic_to_move
										instant_build = yes
									}
								}
							}
						}
						clr_country_flag = CHI_industrial_evacuations_moved_IC
					}			
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}
}

#Broken unless focuses are reassigned
#Category allowed for all potential nationalist china
#Visible for nationalist china if has warlords as subjects
CHI_integrate_the_warlords = {
	
	CHI_integrate_the_army = {
		icon = generic_prepare_civil_war
		available = {
			FROM = { compare_autonomy_state < autonomy_colony }
			#NOT = {
			#	has_country_flag = CHI_integrate_the_army
			#}
		}

		visible = {
			FROM = { is_subject_of = ROOT }
			NOT = {
				has_country_flag = CHI_integrate_the_army
			}
		}
  
		cancel_if_not_visible = yes

		cost = 150

		# VPI by Yard1
		target_root_trigger = {
			has_completed_focus = KMT_warlord
		}
		target_array = subjects


		target_trigger = {
			FROM = {
				is_subject_of = ROOT
				OR = {
					tag = GXC
					tag = YUN
					tag = SHX
					tag = XSM
					tag = SIK
					tag = TNG
				}
			}
		}

		days_remove = 90
		fire_only_once = yes
		ai_will_do = {
			factor = 10
			modifier = {
				OR = {
					has_idea = CHI_warlord_integration_3
					has_idea = CHI_warlord_integration_4
					has_idea = CHI_warlord_integration_5
				}
				factor = 0
				#TODO_WTT_CODE need a trigger for daily increase of PP to see if it's okay to reduce	
			}
		}

		remove_effect = {
			FROM = { set_country_flag = CHI_integrate_the_army }

			CHI_warlord_integration_up = yes
			if = {
				limit = { FROM = { tag = GXC } }
				if = {
					limit = {
						FROM = {
							not = {
								has_completed_focus = CHI_personal_leadership
							}
						}
					}
					create_corps_commander = {
						name = "Li Zongren"
						portrait_path = "gfx/leaders/GXC/r56_portrait_GXC_Li_Zongren.dds"
						traits = { old_guard infantry_officer defensive_doctrine homeland_connoisseur }
						skill = 3
						attack_skill = 3
						defense_skill = 3
						planning_skill = 2
						logistics_skill = 2
					}
				}
				FROM = {
					every_unit_leader = {
						set_nationality = ROOT
					}
				}
			}
			else_if = {
				limit = { FROM = { tag = YUN } }
				if = {
					limit = {
						FROM = {
							not = {
								has_completed_focus = CHI_personal_leadership
							}
						}
					}
					create_corps_commander = {
						name = "Long Yun"
						portrait_path = "gfx/leaders/YUN/portrait_yun_long_yun.dds"
						traits = { politically_connected harsh_leader }			
						skill = 3
						attack_skill = 2
						defense_skill = 3
						planning_skill = 3
						logistics_skill = 2
					}
				}
				FROM = {
					every_unit_leader = {
						set_nationality = ROOT
					}
				}
			}
			else_if = {
				limit = { FROM = { tag = SHX } }
				if = {
					limit = {
						FROM = {
							not = {
								has_completed_focus = CHI_personal_leadership
							}
						}
					}
					create_corps_commander = {
						name = "Yan Xishan"
						portrait_path = "gfx/leaders/SHX/portrait_shx_yan_xishan.dds"
						traits = { offensive_doctrine }
						skill = 3
						attack_skill = 2
						defense_skill = 3
						planning_skill = 3
						logistics_skill = 2
					}
				}
				FROM = {
					every_unit_leader = {
						set_nationality = ROOT
					}
				}
			}
			else_if = {
				limit = { FROM = { tag = XSM } }
				if = {
					limit = {
						FROM = {
							not = {
								has_completed_focus = CHI_personal_leadership
							}
						}
					}
					create_corps_commander = {
						name = "Ma Bufang"
						gfx = GFX_portrait_xsm_ma_bufang
						traits = { cavalry_officer trait_cautious}
						skill = 3
						attack_skill = 4
						defense_skill = 2
						planning_skill = 2
						logistics_skill = 2
					}
				}
				FROM = {
					every_unit_leader = {
						set_nationality = ROOT
					}
				}
			}
			else_if = {
				limit = { FROM = { tag = SIK } }
				if = {
					limit = {
						FROM = {
							not = {
								has_completed_focus = CHI_personal_leadership
							}
						}
					}
					create_corps_commander = {
						name = "Sheng Shicai"
						gfx = GFX_portrait_sheng_shicai
						traits = { politically_connected } # Studied political economy, played Stalin and Chiang against one another
						skill = 3
						attack_skill = 2
						defense_skill = 4
						planning_skill = 2
						logistics_skill = 2
					}
				}
				FROM = {
					every_unit_leader = {
						set_nationality = ROOT
					}
				}
			}
		}
	}

	CHI_integrate_the_administration = {
		icon = generic_political_discourse
		available = {
			FROM = { 
				compare_autonomy_state < autonomy_colony 
			}
		}

		visible = {
			FROM = { 
				is_subject_of = ROOT 
				has_country_flag = CHI_integrate_the_army
				NOT = { has_country_flag = CHI_integrate_the_administration}
			}
		}
		cancel_if_not_visible = yes

		cost = 150

		# VPI by Yard1
		target_array = subjects
		target_trigger = {
			FROM = {
				has_country_flag = CHI_integrate_the_army
				is_subject_of = ROOT
				OR = {
					tag = GXC
					tag = YUN
					tag = SHX
					tag = XSM
					tag = SIK
				}
			}
		}
		fire_only_once = yes
		ai_will_do = {
			factor = 10
			modifier = {
				OR = {
					has_idea = CHI_warlord_integration_3
					has_idea = CHI_warlord_integration_4
					has_idea = CHI_warlord_integration_5
				}
				factor = 0
				#TODO_WTT_CODE need a trigger for daily increase of PP to see if it's okay to reduce
			}
		}

		days_remove = 90
		remove_effect = {
			FROM = {
				set_country_flag = CHI_integrate_the_administration
			}
			
			FROM = {
				every_state = {
					limit = { is_core_of = FROM }
					FROM = { remove_state_core = PREV }
				}
			}
		}
	}

	CHI_full_integration = {
		icon = oppression
		available = {
			FROM = {
				FROM = { compare_autonomy_state < autonomy_colony }
			}
		}

		visible = {
			FROM = { is_subject_of = ROOT }
		}
		cancel_if_not_visible = yes

		cost = 150

		# VPI by Yard1
		target_array = subjects

		target_trigger = {
			FROM = {
				has_country_flag = CHI_integrate_the_administration
				is_subject_of = ROOT
				OR = {
					tag = GXC
					tag = YUN
					tag = SHX
					tag = XSM
					tag = SIK
				}
			}
		}
		days_remove = 90

		remove_effect = {
			CHI_warlord_integration_down = yes
			annex_country = { target = FROM transfer_troops = yes }
		}
		fire_only_once = yes
		ai_will_do = {
			factor = 10			
		}
	}
}


### #  # ### ### #  ### ###   ##  ### ###  ##  #  #
 #  ## # #    #  #   #  #  # #  #  #   #  #  # ## #
 #  # ## ##   #  #   #  ###  ####  #   #  #  # # ##
 #  #  # #    #  #   #  #  # #  #  #   #  #  # #  #
### #  # #   ### ### #  #  # #  #  #  ###  ##  #  #

#Category allowed for all potential nationalist china
#Visible when another country had completed focus PRC_infiltration
@REMOVE_INFILTRATION_PP_COST = 10
CHI_communist_infiltration = {

	CHI_detect_infiltration = {
		icon = oppression
		available = {

		}	


		days_remove = 0
		days_re_enable = 30

		fixed_random_seed = no
	
		cost = 100

		ai_will_do = {
			base = 0
			modifier = {
				has_political_power < 150
				factor = 0
			}
			#Focus on political struggle first
			modifier = {
				factor = 0
				any_other_country = {
					has_country_flag = wtt_political_struggle
				}
			}
			modifier = {
				add = 75
				any_other_country = {
					is_potentially_communist_china = yes
					has_completed_focus = PRC_infiltration
					NOT = { has_country_flag = CHI_delay_sweep_for_communists }
				}
			}

			#Surely there must be commies somewhere
			modifier = {
				add = 85
				NOT = {
					OR = {
						283 = { has_state_flag = discovered_infiltration }
						597 = { has_state_flag = discovered_infiltration }
						598 = { has_state_flag = discovered_infiltration }
						607 = { has_state_flag = discovered_infiltration }
						608 = { has_state_flag = discovered_infiltration }
						614 = { has_state_flag = discovered_infiltration }
						615 = { has_state_flag = discovered_infiltration }
						621 = { has_state_flag = discovered_infiltration }
						744 = { has_state_flag = discovered_infiltration }
						746 = { has_state_flag = discovered_infiltration }
					}
				}
			}
		}
	
		complete_effect = {
			custom_effect_tooltip = CHI_detect_infiltration_tooltip
			hidden_effect = {
				country_event = wtt_infiltration.1
			}
		}
	}

	 CHI_communist_infiltration_in_FROM = {
		icon = infiltrate_state
		visible = { #TODO_WTT_CD merge the 2 visible triggers for all of these. Maybe for JAP as well.
			FROM = {
				is_controlled_by = ROOT
				has_any_PRC_infiltration_flag = yes
				has_state_flag = {
					flag = discovered_infiltration
					value > 0
				}
			}
		}
		available = {
			has_equipment = { infantry_equipment > 999 }
			OR = {
				command_power > 20
				command_power_daily > 0.5
			}
		}

		state_target = yes
		target_trigger = {
			FROM = {
				OR = {
					region = 164
					region = 165
					region = 143
					region = 155
					region = 144
					region = 200
					region = 155
					region = 155
				}
				controller = {
					tag = event_target:WTT_current_china_leader
				}
			}
		}

		on_map_mode = map_and_decisions_view
		
		modifier = {
			command_power_gain = -0.5
		}
		
		days_remove = 40	#shall take a bit longer to scout for them, giving PRC a change to get more
		

		ai_will_do = {
			base = 200	#Pretty damn important
		}

		cost = 10
		
		complete_effect = {
			add_equipment_to_stockpile = {
				type = infantry_equipment
				amount = -1000
			}
		}

		remove_effect = {
			FROM = {
				CHI_show_state_uprising_effect_after_infiltration_level_down = yes
				save_event_target_as = infiltrated_state
				CHI_infiltration_flag_down_2 = yes
			}
			event_target:WTT_communist_china = { country_event = wtt_infiltration.6 } 
		}
	}
}


###  ##  ###  ### ###  ##  #  #      ## #  # ###  ###   ##  ###  ### 
#   #  # #  # #    #  #    ## #     #   #  # #  # #  # #  # #  #  #  
##  #  # ###  ##   #  # ## # ##      #  #  # ###  ###  #  # ###   #  
#   #  # #  # #    #  #  # #  #       # #  # #    #    #  # #  #  #  
#    ##  #  # ### ###  ##  #  #     ##   ##  #    #     ##  #  #  #  

foreign_support = {
	CHI_flying_tigers = {
		icon = generic_air
		available = {
			has_equipment = { small_plane_airframe > 149 }
		}
		visible = {
			has_country_flag = CHI_flying_tigers
		}
		cost = 25
		ai_will_do = {
			factor = 1
		}
		fire_only_once = yes
		days_remove = -1
		complete_effect = {
			random_country = {
				limit = {
					has_completed_focus = CHI_invite_the_flying_tigers
				}
				custom_effect_tooltip = flying_tigers_tt
				hidden_effect = {
					USA = {
						send_equipment = {
							target = PREV
							type = small_plane_airframe
							amount = 150
		
						}
					}
				}
			}
			add_war_support = 0.05
		}
		modifier = {
			air_volunteer_cap = 100
		}
	}

	CHI_soviet_volunteer_group = {
		icon = generic_air
		available = {
			has_equipment = { small_plane_airframe > 99 }
			has_equipment = { tac_bomber_equipment > 49 }
		}
		visible = {
			has_country_flag = CHI_soviet_volunteer_group
		}
		cost = 25
		ai_will_do = {
			factor = 1
		}
		days_remove = -1
		fire_only_once = yes
		complete_effect = {
			random_country = {
				limit = {
					has_completed_focus = CHI_the_soviet_volunteer_group
				}
				custom_effect_tooltip = soviet_volunteers_tt
				hidden_effect = {
					SOV = {
						send_equipment = {
							target = PREV
							type = small_plane_airframe
							amount = 100
						}
					}
					SOV = {
						send_equipment = {
							target = PREV
							type = tac_bomber_equipment
							amount = 50
						}
					}
				}
			}
			add_war_support = 0.05	
		}
		modifier = {
			air_volunteer_cap = 100
		}
	}

	CHI_expand_the_burma_road = {
		icon = generic_construction
		allowed = {
			OR = {
				original_tag = ENG
				is_literally_china = yes
			}
		}

		available = { #WTT_TODO_CD: Make this tooltip not look like complete garbage
			if = {
				limit = {
					OR = {
						has_focus_tree = china_nationalist_focus
						#has_focus_tree = china_communist_focus 
					}
				}
				has_completed_focus = KMT_improve_burma_road
			}
			if = {
				limit = {
					has_focus_tree = british_focus
				}
				has_completed_focus = uk_burma_focus
			}
			
			288 = {
				CONTROLLER = {
					NOT = {
						has_war_with = ROOT
					}
				}
			}
			640 = {
				CONTROLLER = {
					NOT = {
						has_war_with = ROOT
					}
				}
			}
			325 = {
				CONTROLLER = {
					NOT = {
						has_war_with = ROOT
					}
				}
			}
			747 = {
				CONTROLLER = {
					NOT = {
						has_war_with = ROOT
					}
				}
			}

			any_state = {
				OR = {
					state = 288
					state = 640
					state = 325
					state = 747
				}
				CONTROLLER = {
					OR = {
						has_completed_focus = uk_burma_focus
						has_completed_focus = CHI_burma_road
						AND = {
							is_in_faction_with = ROOT
							has_completed_focus = uk_burma_focus
							has_completed_focus = CHI_burma_road
						}
						if = {
							limit = {
								is_subject = yes
							}
							OVERLORD = {
								OR = {
									has_completed_focus = uk_burma_focus
									has_completed_focus = CHI_burma_road
								}
							}
						}
					}
				}
			}
		}
		visible = {
			NOT = { has_global_flag = CHI_burma_3 }
			OR = {
				has_focus_tree = china_nationalist_focus
				has_focus_tree = china_communist_focus 
				has_focus_tree = british_focus
			}
			OR = {
				AND = {
					OR = {
						controls_state = 325
						325 = {
							CONTROLLER = {
								OR = {
									is_subject_of = ROOT
									is_in_faction_with = ROOT
								}
							}
						}
					}
				}
				AND = {
					controls_state = 288
					controls_state = 640
				}
				AND = {
					288 = { CONTROLLER = { is_in_faction_with = ROOT } }
					640 = { CONTROLLER = { is_in_faction_with = ROOT } }
				}
			}
		}
		days_re_enable = 360
		ai_will_do = {
			factor = 1
		}
		cost = 25
		days_remove = 60
		modifier = {
			civilian_factory_use = 2
		}
		complete_effect = {
			if = {
				limit = {
					has_war = no
					has_war_support < 0.6
				}
				add_war_support = 0.05
			}
		}
		remove_effect = {
			288 = {
				add_building_construction = {
					type = infrastructure
					level = 1
					instant_build = yes
				}
			}
			640 = {
				add_building_construction = {
					type = infrastructure
					level = 1
					instant_build = yes
				}
			}
			325 = {
				add_building_construction = {
					type = infrastructure
					level = 1
					instant_build = yes
				}
			}
			if = {
				limit = {
					has_global_flag = CHI_burma_2
				}
				set_global_flag = CHI_burma_3
			}
			if = {
				limit = {
					NOT = { has_global_flag = CHI_burma_2} # 
				}
				set_global_flag = CHI_burma_2
			}
			
			random_country = {
				limit = { check_variable = { CHI_burma_road > 0 } }
				add_to_variable = { var = CHI_burma_road value = 1 }

				#Country that had the burma road open
				add_offsite_building = { type = arms_factory level = 1 }
			}
		}
	}
	CHI_expand_the_ledo_road = {
		icon = generic_construction
		available = {
			any_country = {
				has_completed_focus = CHI_ledo_road
			}
			OR = {
				controls_state = 640
				640 = {
					CONTROLLER = {
						is_in_faction_with = ROOT
					}
				}
				controls_state = 325
				325 = {
					CONTROLLER = {
						OR = {
							AND = {
								is_subject = yes
								OVERLORD = {
									has_completed_focus = CHI_ledo_road
								}
							}
							AND = {
								is_in_faction_with = event_target:WTT_current_china_leader
								event_target:WTT_current_china_leader = {
									has_completed_focus = CHI_ledo_road
								}
							}
						}
					}
				}
			}
		}
		visible = {
			OR = {
				has_completed_focus = CHI_ledo_road
				controls_state = 640
				640 = {
					CONTROLLER = {
						is_in_faction_with = ROOT
					}
				}
			}
			NOT = {
				has_global_flag = CHI_ledo_3
			}
			any_country = {
				has_completed_focus = CHI_ledo_road
			}
		}
		days_re_enable = 360
		ai_will_do = {
			factor = 1
		}
		cost = 25
		days_remove = 60
		modifier = {
			civilian_factory_use = 2
		}

		remove_effect = {
			if = {
				limit = {
					has_global_flag = CHI_ledo_2
				}
				set_global_flag = CHI_ledo_3
			}
			if = {
				limit = {
					NOT = { has_global_flag = CHI_ledo_2} # 
				}
				set_global_flag = CHI_ledo_2
			}

			random_country = {
				limit = { check_variable = { CHI_ledo_road > 0 } }
				add_to_variable = { var = CHI_ledo_road value = 1 }

				#Country that had the ledo road open
				add_offsite_building = { type = arms_factory level = 1 }
			}
		}
	}
	CHI_expand_the_airlift = {
		icon = generic_construction
		available = {	
			OR = {
				434 = {
					CONTROLLER = {
						NOT = {
							has_war_with = CHI
						}
						is_in_faction_with = ROOT
					}
				}
				601 = {
					CONTROLLER = {
						OR = {
							has_completed_focus = CHI_the_hump
							is_in_faction_with = ROOT
						}
					}
				}
			}
		}
		visible = {
			OR = { 
				AND = {
					has_completed_focus = CHI_the_hump
					OR = {
						controls_state = 601
						601 = {
							CONTROLLER = {
								is_in_faction_with = ROOT
							}
						}
					}
				}
				AND = {
					controls_state = 434
					any_country = {
						has_completed_focus = CHI_the_hump
					}
				}
			}
			NOT = {
				has_global_flag = CHI_hump_3
			}
		}
		cost = 25
		days_re_enable = 360
		ai_will_do = {
			factor = 1
		}
		days_remove = 60
		modifier = {
			civilian_factory_use = 2
		}
		complete_effect = {
			if = {
				limit = {
					has_war = no
					has_war_support < 0.6
				}
				add_war_support = 0.05
			}
		}
		remove_effect = {
			434 = {
				add_building_construction = {
					type = air_base
					level = 1
					instant_build = yes
				}
			}
			601 = {
				add_building_construction = {
					type = air_base
					level = 1
					instant_build = yes
				}
			}
			if = {
				limit = {
					has_global_flag = CHI_hump_2
				}
				set_global_flag = CHI_hump_3 # Hump 3: Revenge of the Hump: The Humpening
			}
			if = {
				limit = {
					NOT = { has_global_flag = CHI_hump_2} # Hump 2: Hump Harder
				}
				set_global_flag = CHI_hump_2
			}
			601 = {
				CONTROLLER = {
					add_to_variable = { var = CHI_the_hump value = 1 }
					add_offsite_building = { type = arms_factory level = 1 }
				}
			}
		}
	}
}

political_actions = {

	CHI_suspend_the_inter_party_coordination_council = {
		icon = oppression
		available = {
			has_idea = CHI_inter_party_coordination_council
		}
		visible = {
			has_idea = CHI_inter_party_coordination_council
		}
		cost = 25
		complete_effect = {
			if = {
				limit = {
					NOT = {
						has_government = democratic
					}
				}
				add_stability = -0.05
			}
			remove_ideas = CHI_inter_party_coordination_council
		}
	}
	CHI_reinstate_the_inter_party_coordination_council = {
		icon = generic_political_discourse
		available = {
			NOT = { has_idea = CHI_inter_party_coordination_council }
			NOT = {
				has_government = democratic
			}
			has_completed_focus = KMT_universal_sufferage
		}
		visible = {
			NOT = { has_idea = CHI_inter_party_coordination_council }
			NOT = {
				has_government = democratic
			}
			has_completed_focus = KMT_universal_sufferage
		}
		cost = 25
		complete_effect = {
			add_ideas = CHI_inter_party_coordination_council
		}
	}
	CHI_move_the_capital = {
		allowed = {
			is_literally_china = yes
		}
		available = {
			has_war = no
			OR = {
				has_full_control_of_state = 608
				has_full_control_of_state = 613
			}
			capital_scope = {
				NOT = {
					OR = {
						state = 608
						state = 613
					}
				}
			}
		}
		visible = {
			has_war = no
			OR = {
				has_full_control_of_state = 608
				has_full_control_of_state = 613
			}
			capital_scope = {
				NOT = {
					OR = {
						state = 608
						state = 613
					}
				}
			}
		}
		cost = 50
		ai_will_do = {
			factor = 1
		}
		complete_effect = {
			country_event = wtt_china.204
		}
	}
}

CHI_weapons_purchases_category = {
	CHI_order_weapons_in_USA = {
	icon = generic_prepare_civil_war
		available = {

		}
		visible = {
			USA_can_sell_weapons_trigger = yes
		}
		days_remove = 60
		cost = 25
		ai_will_do = {
			factor = 10
			modifier = {
				has_equipment = {
					infantry_equipment < 1
				}
				factor = 50
			}
			modifier = {
				has_manpower < 10000
				factor = 0 #need to up conscription laws
			}
		}
		complete_effect = {
			USA = {
				add_offsite_building = { type = industrial_complex level = 2 }
			}
		}
		remove_effect = {
			add_equipment_to_stockpile = {
				type = infantry_equipment
				producer = USA
				amount = 2500
			}
			USA = {
				add_offsite_building = { type = industrial_complex level = -2 }
			}
		}
	}
	CHI_order_support_equipment_in_USA = {
		icon = generic_prepare_civil_war
		available = {

		}
		visible = {
			USA_can_sell_weapons_trigger = yes
		}
		days_remove = 60
		cost = 25
		ai_will_do = {
			factor = 5
			modifier = {
				has_equipment = {
					support_equipment < 1
				}
				factor = 50
			}
			modifier = {
				has_manpower < 10000
				factor = 0 #need to up conscription laws
			}
		}
		complete_effect = {
			USA = {
				add_offsite_building = { type = industrial_complex level = 2 }
			}
		}
		remove_effect = {
			add_equipment_to_stockpile = {
				type = support_equipment
				producer = USA
				amount = 75
			}
			USA = {
				add_offsite_building = { type = industrial_complex level = -2 }
			}
		}
	}
	CHI_order_artillery_in_USA = {
		icon = ger_military_buildup
		available = {

		}
		visible = {
			USA_can_sell_weapons_trigger = yes
		}
		days_remove = 60
		cost = 25
		ai_will_do = {
			factor = 5
			modifier = {
				has_equipment = {
					artillery_equipment < 1
				}
				factor = 50
			}
			modifier = {
				has_manpower < 10000
				factor = 0 #need to up conscription laws
			}
		}
		complete_effect = {
			USA = {
				add_offsite_building = { type = industrial_complex level = 2 }
			}
		}
		remove_effect = {
			add_equipment_to_stockpile = {
				type = artillery_equipment
				producer = USA
				amount = 100
			}
			USA = {
				add_offsite_building = { type = industrial_complex level = -2 }
			}
		}
	}
	CHI_order_tanks_in_USA = {
		icon = generic_tank
		visible = {
			USA_can_sell_weapons_trigger = yes
		}
		days_remove = 60
		cost = 50
		ai_will_do = {
			factor = 1
			modifier = {
				has_equipment = {
					light_tank_chassis < 10
				}
				factor = 5
			}
			modifier = {
				has_manpower < 10000
				factor = 0 #need to up conscription laws
			}
		}
		modifier = {
		}
		complete_effect = {
			USA = {
				add_offsite_building = { type = industrial_complex level = 5 }
			}
		}
		remove_effect = {
			if = {
				limit = {
					USA = { 
						OR = {
							has_tech = basic_light_tank 
							has_tech = basic_light_tank_chassis
						}
						NOT = { 
							has_tech = basic_medium_tank 
							has_tech = improved_medium_tank #needed because basic can be bypassed
							has_tech = basic_medium_tank_chassis
							has_tech = improved_medium_tank_chassis
						}
					}
				}
				add_equipment_to_stockpile = {
					type = light_tank_chassis
					producer = USA
					amount = 50
				}
			}
			else_if = {
				limit = {
					USA = {
						OR = {
							has_tech = basic_medium_tank
							has_tech = improved_medium_tank #needed because basic can be bypassed
							has_tech = basic_medium_tank_chassis
							has_tech = improved_medium_tank_chassis
						}
					}
				}
				add_equipment_to_stockpile = {
					type = medium_tank_chassis
					producer = USA
					amount = 50
				}
			}
			USA = {
				add_offsite_building = { type = industrial_complex level = -5 }
			}
		}
	}
	CHI_order_fighters_in_USA = {
		icon = generic_air
		available = {

		}
		visible = {
			USA_can_sell_weapons_trigger = yes
		}
		days_remove = 60
		cost = 50
		ai_will_do = {
			factor = 1
			modifier = {
				has_equipment = {
					small_plane_airframe < 1
				}
				factor = 5
			}
			modifier = {
				has_manpower < 10000
				factor = 0 #need to up conscription laws
			}
		}
		modifier = {
		}
		complete_effect = {
			USA = {
				add_offsite_building = { type = industrial_complex level = 5 }
			}
		}
		remove_effect = {
			add_equipment_to_stockpile = {
				type = small_plane_airframe
				producer = USA
				amount = 50
			}
			USA = {
				add_offsite_building = { type = industrial_complex level = -5 }
			}
		}
	}
	CHI_order_bombers_in_USA = {
		icon = generic_air
		available = {

		}
		visible = {
			USA_can_sell_weapons_trigger = yes
		}
		days_remove = 60
		cost = 50
		ai_will_do = {
			factor = 1
			modifier = {
				has_equipment = {
					tac_bomber_equipment < 1
				}
				factor = 5
			}
			modifier = {
				has_manpower < 10000
				factor = 0 #need to up conscription laws
			}
		}
		modifier = {

		}
		complete_effect = {
			USA = {
				add_offsite_building = { type = industrial_complex level = 5 }
			}
		}
		remove_effect = {
			add_equipment_to_stockpile = {
				type = medium_plane_airframe
				producer = USA
				amount = 25
			}
			USA = {
				add_offsite_building = { type = industrial_complex level = -5 }
			}
		}
	}
}

CHI_xian_incident = {
	CHI_instigate_xian_incident = {
		icon = generic_political_discourse
		available = {			
			NOT = {
				has_global_flag = CHI_xian_fired
			}
			CHI = {
				NOT = {
					is_in_faction_with = PRC
				}
				NOT = {
					has_war_with = PRC
				}
				NOT = {
					OR = {
						has_completed_focus = KMT_internal_stability
						has_completed_focus = KMT_external_defense
					}
				}
			}
			PRC = {
				NOT = {
					has_war_with = CHI
				}
				is_in_faction = no
			}
			NOT = {
				has_war_with = CHI
			}
			NOT = {
				has_war_with = PRC
			}
		}

		visible = {
			NOT = {
				has_global_flag = CHI_xian_fired
			}
			CHI = {
				NOT = {
					is_in_faction_with = PRC
				}
			}
			PRC = {
				NOT = {
					has_war_with = PRC
				}
			}
			is_literally_china = yes
			NOT = {
				OR = {
					original_tag = CHI
					original_tag = PRC
				}
			}
			event_target:WTT_current_china_leader = { tag = CHI }
		}
		cost = 25
		fire_only_once = yes
		ai_will_do = {
			factor = 1
			modifier = {
				threat > 0.1
				factor = 2
			}
			modifier = {
				NOT = { 	
					JAP = {
						has_completed_focus = JAP_greater_east_asian_co_prosperity_sphere
					}
				}
				factor = 0
			}
			modifier = {
				JAP = {
					NOT = {
						has_government = fascism
					}
				}
				factor = 0
			}
		}
		complete_effect = {
			set_country_flag = CHI_xian_instigator_flag
			set_global_flag = CHI_xian_fired
			CHI = {
				country_event = wtt_xian_incident.1
			}
		}
	}
}

operations = {
	
	CHI_overlordship_over_indochina = {
		icon = generic_operation
		allowed = {
			is_literally_china = yes
		}
		available = {
			controls_state = 671
			controls_state = 670
			controls_state = 286
			controls_state = 741
			controls_state = 924
			controls_state = 925
			controls_state = 926
			controls_state = 927
			controls_state = 928
		} 

		days_mission_timeout = 360

		fire_only_once = yes

		activation = {
			has_completed_focus = CHI_overlordship_over_indochina
		}
		
		complete_effect = {
			add_political_power = 50
			add_war_support = 0.05
			add_stability = 0.05
		}

		timeout_effect = {
			add_war_support = -0.1
		}
	}
}

prestigious_projects = {
	CHI_build_a_carrier = { 
		allowed = {
			is_literally_china = yes
		}
		icon = generic_naval
		available = {
			has_navy_size = { unit = carrier size > 0 }
		}

		days_mission_timeout = 720

		fire_only_once = yes
		is_good = no
		activation = {
			has_completed_focus = CHI_naval_aviation
		}
		
		complete_effect = {
			add_political_power = 100
			navy_experience = 30
			add_war_support = 0.05
		}

		timeout_effect = {
		
		}
	}
}

CHI_partisan_organization = {
	
	CHI_organize_beijing_partisans = {

		icon = GFX_decision_icon_kuomintang

		custom_cost_text = chi_improve_the_nra_decision	
		custom_cost_trigger = {
			command_power > 10
		}

		available = {
			NOT = {
				has_country_flag = CHI_currently_organizing_partisans
			}
			command_power > 10
		}

		cost = 0

		ai_will_do = {
			factor = 500
		}

		days_remove = 20

		days_re_enable = 30

		visible = {
			608 = {
				is_owned_by = ROOT
				controller = {
					has_war_with = ROOT
				}
			}
		}
		remove_effect = {
			608 = {
				create_unit = {
					division = "name = \"Beijing Youji Dui\" division_template = \"Dangpai\" start_experience_factor = 0.51 start_equipment_factor = 0.75"
					owner = ROOT
					prioritize_location = 12026
					allow_spawning_on_enemy_provs = yes
				}
				create_unit = {
					division = "name = \"Beijing Youji Dui\" division_template = \"Dangpai\" start_experience_factor = 0.51 start_equipment_factor = 0.75" 
					owner = ROOT
					prioritize_location = 11761
					allow_spawning_on_enemy_provs = yes
				}
			}
		}
		complete_effect = {
			set_country_flag = {
				flag = CHI_currently_organizing_partisans
				days = 30
			}
			add_command_power = -10
						
		}		
	}	
}
