on_actions = {
	
	on_startup = {
		effect = {
			CHI = {
				every_state = {
					limit = {
						OR = {
							is_core_of = CHI
							is_claimed_by = CHI
						}
						NOT = {
							is_in_array = {
								array = CHI.core_and_claimed_states
								value = THIS
							}
						}
					}

					add_to_array = { CHI.core_and_claimed_states = THIS }	
				}
			}
		}

		effect = {
			every_country = {
				limit = {
					OR = {
						original_tag = MON
						original_tag = TIB
						original_tag = TAN
					}
				}

				every_core_state = {
					add_to_array = { CHI.mtac_core_states = THIS }
				}
			}
		}
	

		effect = {
			every_country = {
				limit = {
					OR = {
						original_tag = BEL
						original_tag = FRA
						original_tag = ENG
						original_tag = ITA
						original_tag = JAP
						original_tag = HOL
						original_tag = POR
						original_tag = USA 
					}
				}

				add_to_array = { CHI.nine_power_treaty_signatories = THIS}
			}
		}

 
		# Soviet North Sakhalin - Resource Concessions to Japan
		effect = { 
			SOV = {
				give_resource_rights = { 
					receiver = JAP 
					state = 655 
				}
			}
		}

		effect = {
			every_country = {
				limit = {
					is_chinese_warlord = yes
				}
				
				add_to_array = { global.is_chinese_warlord = THIS } 
				set_variable = { press_warlord_to_become_puppet_political_power_cost = CHI.press_warlord_to_become_puppet_political_power_cost }
				set_variable = { press_warlord_to_become_puppet_influence_points_cost = CHI.press_warlord_to_become_puppet_influence_points_cost }
				set_variable = { press_warlord_to_become_puppet_influence_points_trigger = CHI.press_warlord_to_become_puppet_influence_points_trigger }

				#This is used for IntegrationDecisions
				set_variable = { CHI_warlord_integration_pp_cost = 50 }
			}

			YUN = {
				set_variable = { political_power_warlord_integration_cost = 100 }
			}
		}

		#JAPAN - Add Chinese States to an array for Strategic Offensives Decision purposes
		effect = {
			
			every_state = {
				limit = {
					owner = {
						is_literally_china = yes
						controls_state = PREV
					}
				}
				add_to_array = { 
					array = JAP.JAP_strategic_offensives_targets_array 
					value = THIS
				}
			}
			
		}

		#JAPAN - Launch event that notifies about Kodoha coup and advisor protection if 1936 start date, as well as the 1936 election
		effect = {
			
			IF = {
				limit = {
					date < "1936.2.2"
				}
				JAP = {
					# The Kodoha warning
					country_event = {
						id = SEA_japan_popup_events.10
						days = 2
					}	
					# The 1936 General Election
					country_event = {
						id = SEA_japan_popup_events.14
						days = 42
					}	
				}
			}
			
		}

		#KOREA/JAPAN - Set up the resistance DMs 
		effect = {
			every_state = {
				limit = {
					OR = {
						state = 1031
						state = 1030
						state = 1029
						state = 1028
						state = 527
					}
				}
				add_dynamic_modifier = {
					modifier = KOR_resistance_against_colonial_rule_dm
				}
			}
		}

		# Adding in the Great Wall province effect
		effect = {
			IF = {
				limit = { has_dlc = "No Compromise, No Surrender" }
				328 = { # Kirin
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 9848
						}
					}
				}
				716 = { # Liaoning
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 6910
							id = 6804
							id = 3849
							id = 11808
							id = 846
							id = 6951 #
							id = 11815
						}
					}
				}
				715 = { # Liaobei
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 916
						}
					}
				}
				609 = { # East Hebei
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 3900
							id = 3830
							id = 900
							id = 9905
							id = 11822
						}
					}
				}
				610 = { # Jehol
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 3934
							id = 6852
							id = 11855
							id = 6898
							id = 11886
							id = 6969
							id = 3955
						}
					}
				}
				1039 = { # Hebei-Chahar
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 9776
							id = 6904
							id = 1590
						}
					}
				}
				621 = { # Suiyuan
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 7158
						}
					}
				}
				615 = { # Shanxi
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 12432
							id = 10507
							id = 4074
							id = 1203
							id = 4469
							id = 12300
						}
					}
				}
				1046 = { # Yulin
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 7659
							id = 7314
						}
					}
				}
				608 = { # Beijing
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 4140 
							id = 1134
							id = 9843
						}
					}
				}
				614 = { # Hebei
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 10022
							id = 7109
							id = 7000 #
							id = 10053 #
							id = 4093
							id = 12062
						}
					}
				}
				607 = { # Henan
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 4058
						}
					}
				}
				622 = { # Shaanbei
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 10880
						}
					}
				}
				616 = { # Ningxia
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 8081
							id = 10724
							id = 8127
						}
					}
				}
				1044 = { # Wuwei
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 12776
							id = 12327
							id = 5100
						}
					}
				}
				756 = { # Jiuquan
					add_province_modifier = {
						static_modifiers = { the_great_wall }
						province = {
							id = 2028
							id = 7971
						}
					}
				}
			}
		}

		effect = {
			PRC = {
				every_core_state = {
					add_to_array = { global.PRC_starting_PRC_core_states = THIS }
				}
			}
		}
	}

	#	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
	on_state_control_changed = {

		effect = {
			if = {
				limit = {
					ROOT = {
						has_dynamic_modifier = {
							modifier = CHI_american_support
						}
					}
				}
				ROOT = {
					if = {
						limit = {
							has_completed_focus = CHI_the_hump_sea
							NOT = { 
								has_idea = CHI_the_hump_sea_hidden 
								any_enemy_country = {
									controls_state = 601
									controls_state = 434
									controls_state = 747
								}		
							}

						}

						add_ideas = CHI_the_hump_sea_hidden
					}

					if = {
						limit = {
							has_completed_focus = CHI_the_hanoi_route
							NOT = { 
								has_idea = CHI_the_hanoi_route_hidden 
								any_enemy_country = {
									controls_state = 325
									controls_state = 671
								}
							}
						}
						
						add_ideas = CHI_the_hanoi_route_hidden	
					}

					if = {
						limit = {
							has_completed_focus = CHI_the_burma_road
							NOT = { 
								has_idea = CHI_the_burma_road_hidden 
								any_enemy_country = {
									controls_state = 995
									controls_state = 640
									controls_state = 998
									controls_state = 434
									controls_state = 990
									controls_state = 432
									controls_state = 288
									controls_state = 997
									controls_state = 996	
								}
							}
						}
						add_ideas = CHI_the_burma_road_hidden
					}
				}
			}
			else_if = {
				limit = {
					ROOT = {
						has_dynamic_modifier = {
							modifier = CHI_soviet_support
						}
					}
				}

				ROOT = {
					if = {
						limit = {
							NOT = { 
								any_enemy_country = {
									controls_state = 617
									controls_state = 759
									controls_state = 755
									controls_state = 754
									controls_state = 283
								}		
							}

						}

						if = {
							limit = {
								has_completed_focus = CHI_the_northwest_highway
								NOT = { has_idea = CHI_northwest_highway_hidden }
							}
							add_ideas = CHI_northwest_highway_hidden
						}

						if = {
							limit = {
								has_completed_focus = CHI_facilitate_operation_zet
								NOT = { has_idea = CHI_operation_zet_hidden }
							}
							add_ideas = CHI_operation_zet_hidden
						}

						set_variable = { CHI_soviet_support_army_armor_attack_factor = CHI_soviet_support_army_armor_attack_factor_default }
						set_variable = { CHI_soviet_support_army_armor_speed_factor = CHI_soviet_support_army_armor_speed_factor_default }
						

					}
					else = {
						set_variable = { CHI_soviet_support_army_armor_attack_factor = 0 }
						set_variable = { CHI_soviet_support_army_armor_speed_factor = 0 }
					}
				}
			}
		}

		effect = {

			# For resetting Sonno Joui for Japan
			IF = {
				limit = {
					JAP = { has_idea = JAP_expel_the_barbarians }
					ROOT = {
						OR = {
							original_tag = JAP
							is_ally_with = JAP
						}
					}

					FROM = {
						has_war_with = JAP
					}

					FROM.FROM = {
						has_state_flag = can_renew_sonno_joi_flag	
					}
				}

				JAP = {
					remove_ideas = JAP_expel_the_barbarians
					add_timed_idea = {
						idea = JAP_expel_the_barbarians
						days = 365
					}
				}

				# It can only be renewed once per capital state, you will need to keep invading and sowballing to keep it 
				FROM.FROM = {
					clr_state_flag = can_renew_sonno_joi_flag	
				}
				
			}

		}

		effect = { # Trigger the han fuju flees event
			IF = {
				limit = {
					FROM.FROM = {
						state = 1038 #Jinan
						is_owned_by = SND
					}
					ROOT = {
						has_war_with = SND
						has_war_with = CHI
						OR = {
							original_tag = JAP
							AND = {
								original_tag = RNG
								is_ally_with = JAP
							}
							AND = {
								original_tag = MAN
								is_ally_with = JAP
							}
						}
					}
					FROM = {
						original_tag = SND
						is_subject = no
						is_in_faction_with = CHI 
						NOT = { 
							has_country_flag = SND_han_fuju_stays 
						}
					}
					NOT = { has_global_flag = jinan_has_fallen }
				}
				CHI = {
					country_event = {
						id = SEA_warlords.42
						hours = 6
					}
				}
			}
		}

		effect = { #BEL-inspired fall of Phillipines
			IF = {
				limit = {
					has_dlc = "No Compromise, No Surrender"
					FROM.FROM = {
						state = 327
					}
					FROM = {
						original_tag = PHI
						has_war = yes
						has_civil_war = no

						owns_state = 327
					}
				}
				FROM = {
					country_event = {
						id = SEA_PHI_political_events.54
						hours = 6
					}
				}
			}
		}

		#We need to switch out Guerilla Bases to Sabotage Operations because Guerillas only operate on non-core territory - but the fight doesn't stop just because the state changes hands!
		effect = {
			if = {
				limit = {
					has_dlc = "No Compromise, No Surrender"
					FROM.FROM = {
						OR = {
							is_core_of = PRC
							is_core_of = CHI
						}
						is_core_of = ROOT
						NOT = {
							has_dynamic_modifier = {
								modifier = PRC_anti_japanese_base
							}
						}
						OR = {
							has_dynamic_modifier = {
								modifier = PRC_guerilla_cells_active_1
							}
							has_dynamic_modifier = {
								modifier = PRC_guerilla_cells_active_2
							}
						}
					}
				}
				if = {
					limit = {
						FROM.FROM = {
							has_dynamic_modifier = {
								modifier = PRC_guerilla_cells_active_1
							}
						}
					}
					FROM.FROM = {
						remove_dynamic_modifier = {
							modifier = PRC_guerilla_cells_active_1
						}
						add_dynamic_modifier = {
							modifier = PRC_anti_japanese_base
						}
					}
				}
				else_if = {
					limit = {
						FROM.FROM = {
							has_dynamic_modifier = {
								modifier = PRC_guerilla_cells_active_2
							}
						}
					}
					FROM.FROM = {
						remove_dynamic_modifier = {
							modifier = PRC_guerilla_cells_active_2
						}
						add_dynamic_modifier = {
							modifier = PRC_anti_japanese_base
						}
					}
				}
			}
		}

		effect = {
			if = {
				limit = {
					FROM = {
						tag = CHI
					}
					FROM.FROM = {
						OR = {
							state = 743 #Qingdao
							state = 598 #Jiangsu
							state = 1034 #Suzhou
							state = 613 #Shanghai
							state = 596 #Zhejiand
							state = 595 #Fujian
						}
					}
				}
				CHI = {
					set_country_flag = CHI_lost_a_coastal_state
				}
			}
		}

		# Changing out the presidential palace building for  
		effect = {
			# New owner is CHI
			IF = {
				limit = {
					ROOT = { tag = CHI }
					FROM = { tag = PRC }
					FROM.FROM = { state = 1035 }
				}
				1035 = {
					remove_building = {
						type = landmark_nanjing_presidential_palace_prc
						level = 1
						province = 11913
					}
					add_building_construction = {
						type = landmark_nanjing_presidential_palace
						level = 1
						instant_build = yes
						province = 11913
					}
				}
			}
			IF = {
				limit = {
					ROOT = { tag = CHI }
					FROM = { NOT = { tag = PRC } }
					FROM.FROM = { state = 1035 }
				}
				1035 = {
					remove_building = {
						type = landmark_nanjing_presidential_palace_gen
						level = 1
						province = 11913
					}
					add_building_construction = {
						type = landmark_nanjing_presidential_palace
						level = 1
						instant_build = yes
						province = 11913
					}
				}
			}

			# New owner is PRC
			IF = {
				limit = {
					ROOT = { tag = PRC }
					FROM = { tag = CHI }
					FROM.FROM = { state = 1035 }
				}
				1035 = {
					remove_building = {
						type = landmark_nanjing_presidential_palace
						level = 1
						province = 11913
					}
					add_building_construction = {
						type = landmark_nanjing_presidential_palace_prc
						level = 1
						instant_build = yes
						province = 11913
					}
				}
			}
			IF = {
				limit = {
					ROOT = { tag = PRC }
					FROM = { NOT = { tag = CHI } }
					FROM.FROM = { state = 1035 }
				}
				1035 = {
					remove_building = {
						type = landmark_nanjing_presidential_palace_gen
						level = 1
						province = 11913
					}
					add_building_construction = {
						type = landmark_nanjing_presidential_palace_prc
						level = 1
						instant_build = yes
						province = 11913
					}
				}
			}

			# New owner is anyone, but CHI and PRC
			IF = {
				limit = {
					ROOT = { NOT = { tag = CHI } }
					FROM = { tag = PRC }
					FROM.FROM = { state = 1035 }
				}
				1035 = {
					remove_building = {
						type = landmark_nanjing_presidential_palace_prc
						level = 1
						province = 11913
					}
					add_building_construction = {
						type = landmark_nanjing_presidential_palace_gen
						level = 1
						instant_build = yes
						province = 11913
					}
				}
			}
			IF = {
				limit = {
					ROOT = { NOT = { tag = PRC } }
					FROM = { tag = CHI }
					FROM.FROM = { state = 1035 }
				}
				1035 = {
					remove_building = {
						type = landmark_nanjing_presidential_palace
						level = 1
						province = 11913
					}
					add_building_construction = {
						type = landmark_nanjing_presidential_palace_gen
						level = 1
						instant_build = yes
						province = 11913
					}
				}
			}
		}
	}

	# FROM is the country invited, THIS and ROOT are the faction leader.
	on_offer_join_faction = {

		effect = {
			IF = {
				limit = {
					ROOT = {
						original_tag = JAP
						has_completed_focus = JAP_educate_the_peasants
					}
				}
				ROOT = {
					JAP_one_more_member_increase_peasants_education_strength = yes
				}
				
			}
		}

		effect = { # Adding the correct stuff for puppets for German Mitteleuropa stuff
			IF = {
				limit = {
					ROOT = {
						original_tag = JAP
						OR = {
							has_completed_focus = JAP_the_flying_geese
							has_completed_focus = JAP_develop_the_yen_bloc
							has_completed_focus = JAP_ministry_of_greater_east_asia
						}
					}
				}

				JAP_setup_faction_wide_aoe_effects_root = yes

			}
		}

		effect = {
			#Remove JAP_POL_anti_soviet_pact if joining commie Soviet in faction
			IF = {
				limit = {
					original_tag = SOV
					has_government = communism
					FROM = {
						has_idea = JAP_POL_anti_soviet_pact
					}
				}
				FROM = {
					remove_ideas = JAP_POL_anti_soviet_pact
				}
			}
		}

		effect = {
			if = {
				limit = {
					ROOT = {
						original_tag = PRC
						has_completed_focus = PRC_asian_democratic_union
					}
				}
				ROOT = {
					PRC_increase_asian_democratic_union_modfier_strength = yes
				}
				FROM = {
					add_ideas = PRC_asian_democratic_union_idea
				}
			}
		}

	}

	#FROM is faction leader on join faction requests. THIS DOES NOT FIRE ON ADD_TO_FACTION EFFECT! USE ON_OFFER_JOIN_FACTION!
	on_join_faction = { 

		effect = {
			IF = {
				limit = {
					FROM = {
						original_tag = JAP
						has_completed_focus = JAP_educate_the_peasants
					}
				}
				FROM = {
					JAP_one_more_member_increase_peasants_education_strength = yes
				}
				
			}
		}

		effect = { # Adding the correct stuff for puppets for Japanese GEACPS stuff
			IF = {
				limit = {
					FROM = {
						original_tag = JAP
						OR = {
							has_completed_focus = JAP_the_flying_geese
							has_completed_focus = JAP_develop_the_yen_bloc
							has_completed_focus = JAP_ministry_of_greater_east_asia
						}
					}
				}

				JAP_setup_faction_wide_aoe_effects_from = yes

			}
		}

		effect = {
			#Remove JAP_POL_anti_soviet_pact if joining commie Soviet in faction
			IF = {
				limit = {
					has_idea = JAP_POL_anti_soviet_pact
					FROM = {
						original_tag = SOV
						has_government = communism
					}
				}
				remove_ideas = JAP_POL_anti_soviet_pact
			}
		}
		effect = {
			if = {
				limit = {
					FROM = {
						original_tag = PRC
						has_completed_focus = PRC_asian_democratic_union
					}
				}
				FROM = {
					PRC_increase_asian_democratic_union_modfier_strength = yes
				}
				ROOT = {
					add_ideas = PRC_asian_democratic_union_idea
				}
			}
		}
	}

	# ROOT is the nation being puppeted, FROM is the overlord. 	OBS: Trigger the following commands whenever a country is puppeted in a peace conference only.
	on_puppet = {

		effect = {
			IF = {
				limit = {
					FROM = {
						original_tag = JAP
						has_completed_focus = JAP_educate_the_peasants
					}
					ROOT = {
						NOT = { is_in_faction_with = FROM }
					}
				}
				FROM = {
					JAP_one_more_member_increase_peasants_education_strength = yes
				}
			}
				

			if = {
				limit = {
					FROM = { 
						original_tag = CHI
						has_completed_focus = CHI_appoint_sympathetic_judges 
					}

					ROOT = {
						is_chinese_warlord = yes
						NOT = { has_idea = idea_CHI_sympathetic_judges }
					}
				}

				ROOT = {
					add_ideas = idea_CHI_sympathetic_judges
				}
			}

			if = {
				limit = {
					FROM = { 
						original_tag = CHI
						has_completed_focus = CHI_take_control_of_the_executive_yuan 
					}

					ROOT = {
						is_chinese_warlord = yes
					}
				}

				every_subject_country = {
					limit = {
						is_chinese_warlord = yes
						NOT = { tag = ROOT }
					}

					add_autonomy_ratio = { 
						value = var:CHI.executive_yuan_autonomy_ratio
						localization = CHI_take_control_of_the_executive_yuan
					}
				}

			}
		}

		effect = { #Adding 
			if = {
				limit = {
					has_dlc = "No Compromise, No Surrender"
					ROOT = {
						is_chinese_warlord = yes
						
					}

					FROM = {
						original_tag = CHI
					}

					NOT = {
						is_in_array = {
							array = FROM.warlord_subjects
							value = ROOT
						}
					}
				}

				add_to_array = { FROM.warlord_subjects = ROOT }

				if = {
					limit = {
						FROM = {
							OR = {
								has_government = neutrality
								has_government = fascism
							}
						}
						ROOT = {
							NOT = { has_autonomy_state = autonomy_sea_integrated_warlord_subject }
							NOT = { has_autonomy_state = autonomy_sea_warlord_subject }
						}
					}
					FROM = {
						set_autonomy = {
							target=ROOT
							autonomy_state = autonomy_sea_warlord_subject
							freedom_level = 0.6 # 0-1 
							end_wars  = no # default yes. will not cancel non civil wars if set to no
							end_civil_wars = no # default yes. will not cancel civil wars if set to no
						}
					}
				}
			}
		}

		effect = { # Adding the correct stuff for puppets for Japanese GEACPS stuff
			IF = {
				limit = {
					FROM = {
						original_tag = JAP
						is_faction_leader = yes
						OR = {
							has_completed_focus = JAP_the_flying_geese
							has_completed_focus = JAP_develop_the_yen_bloc
							has_completed_focus = JAP_ministry_of_greater_east_asia
						}
					}
				}

				JAP_setup_faction_wide_aoe_effects_from = yes

			}
		}

		effect = {
			if = {
				limit = {
					FROM = {
						original_tag = PRC
						has_completed_focus = PRC_asian_democratic_union
						NOT = {
							is_in_faction_with = ROOT
						}
					}
				}
				FROM = {
					PRC_increase_asian_democratic_union_modfier_strength = yes
				}
				ROOT = {
					add_ideas = PRC_asian_democratic_union_idea
				}
			}
		}

		effect = {
			IF = {
				limit = {
					ROOT = {
						original_tag = JAP
					}
					FROM = {
						original_tag = USA
						has_government = democratic
					}
				}
				ROOT = {
					set_cosmetic_tag = JAP_us_occupation
				}
			}
		}

	}

	# FROM is the faction Leader, ROOT is the country leaving the faction 
	on_leave_faction = {


		effect = {
			IF = {
				limit = {
					FROM = {
						original_tag = JAP
						has_completed_focus = JAP_educate_the_peasants
					}
				}
				FROM = {
					JAP_one_less_member_decrease_peasants_education_strength = yes
				}
			}
		}

		effect = {	#PHI: return oil/advisors if no longer allied with USA/JAP
			if = {
				limit = {
					original_tag = PHI
				}
				if = {
					limit = {
						has_resources_rights = {
							state = 371
						}
						NOT = {
							is_ally_with = USA
						}
					}
					remove_resource_rights = 371
				}
				if = {
					limit = {
						has_character = JAP_kiyoshi_hasegawa
						NOT = {
							is_ally_with = JAP
						}
					}
					set_nationality = {
						target_country = JAP
						character = JAP_kiyoshi_hasegawa
					}
				}
			}
		}

		effect = {
			if = {
				limit = {
					FROM = {
						original_tag = PRC
						has_completed_focus = PRC_asian_democratic_union
					}
				}
				FROM = {
					PRC_decrease_asian_democratic_union_modfier_strength = yes
				}
				ROOT = {
					remove_ideas = PRC_asian_democratic_union_idea
				}
			}
		}

		effect = {
			if = {
				limit = {
					original_tag = PHI
					FROM = {
						original_tag = USA
					}
				}
				set_country_flag = {
					flag = PHI_recently_broke_USA_alliance
					days = 45
					value = 1
				}
			}
		}

	}

	# ROOT is the nation being released, FROM is the overlord. Trigger the following commands whenever puppeting through the occupied territories menu during peace time (or when releasing from non-core but owned territory).
	on_release_as_puppet = {

		effect = { # Adding the correct stuff for puppets for the Japanese GEACPS faction stuff
			IF = {
				limit = {
					FROM = {
						original_tag = JAP
						is_faction_leader = yes
						OR = {
							has_completed_focus = JAP_the_flying_geese
							has_completed_focus = JAP_develop_the_yen_bloc
							has_completed_focus = JAP_ministry_of_greater_east_asia
						}
					}
				}

				JAP_setup_faction_wide_aoe_effects_from = yes

			}
		}

	}

	on_ruling_party_change = {

		effect = {

			# To tie Philippine ideoloy with Japan's ideology
			IF = {
				limit = {
					original_tag = JAP 
				}
				PHI = {
					if = {
						limit = {
							has_dynamic_modifier = { modifier = PHI_japan_aligned_ideology } 
						}
						PHI_check_japanese_ideology_and_adapt = yes
					}
				}
			}

			if = {
				limit = {
					original_tag = PHI
				}
				PHI_refresh_ruling_ideology_drift = yes
			}
		}

		effect = {

			IF = {
				limit = {
					ROOT = {
						original_tag = JAP
					}
				}
				
				#NAVY MODIFIERS
				IF = {
					limit = {
						has_government = fascism
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_japanese_navy_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_japanese_navy_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_imperial_navy_dm
						}
					}
				}
				IF = {
					limit = {
						has_government = democratic
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_imperial_navy_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_imperial_navy_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_japanese_navy_dm
						}
					}
				}
				IF = {
					limit = {
						has_government = neutrality
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_japanese_navy_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_japanese_navy_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_imperial_navy_dm
						}
					}
				}
				IF = {
					limit = {
						has_government = communism
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_imperial_navy_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_imperial_navy_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_japanese_navy_dm
						}
					}
				}

				#ARMY MODIFIERS
				IF = {
					limit = {
						has_government = fascism
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_national_army_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_national_army_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_imperial_army_dm
						}
					}
				}
				IF = {
					limit = {
						has_government = democratic
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_imperial_army_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_imperial_army_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_national_army_dm
						}
					}
				}
				IF = {
					limit = {
						has_government = neutrality
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_national_army_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_national_army_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_imperial_army_dm
						}
					}
				}
				IF = {
					limit = {
						has_government = communism
					}
					IF =  {
						limit = {
							has_dynamic_modifier = { modifier = JAP_imperial_army_dm }
						}
						remove_dynamic_modifier = {
							modifier = JAP_imperial_army_dm
						}
						add_dynamic_modifier = {
							modifier = JAP_national_army_dm
						}
					}
				}

			}

		}

	}

	on_declare_war = {

		effect = {

			# Remove pact opinion modifiers if at war with Germany
			IF = {
				limit = {
					tag = JAP
					FROM = {
						has_idea = JAP_POL_anti_soviet_pact
					}
				}
				FROM = {
					remove_ideas = JAP_POL_anti_soviet_pact
				}
				JAP = {
					remove_ideas = JAP_POL_anti_soviet_pact
				}
			}

			#Call Anti-Soviet pact members to war
			IF = {
				limit = {
					ROOT = {
						original_tag = SOV
						has_government = communism
					}
					FROM = { has_idea = JAP_POL_anti_soviet_pact }
				}
				save_event_target_as = JAP_POL_anti_soviet_pact_aggressor
				FROM = {
					country_event = { id = SEA_japan_foreign_policy.85 days = 1 }
				}
			}

		}

	}

	#ROOT = attacking side
	#FROM = defending side
	#fired when two countries end up at war with each other (on_war is fired when a country goes to war against anyone and is not fired again when it enters war against another country unless it went to peace first)
	on_war_relation_added = {

		effect = {
			if = {
				limit = {
					OR = {
						AND = {
							ROOT = { 
								original_tag = CHI
							}
							is_in_array = {
									array = CHI.nine_power_treaty_signatories
									value = FROM
							}
						}

						AND = {
							is_in_array = {
									array = CHI.nine_power_treaty_signatories
									value = ROOT
							}
							FROM = {
								original_tag = CHI
							}
						}
					}
				}

				CHI = {
					every_enemy_country = {
						limit = {
							is_in_array = {
								array = CHI.nine_power_treaty_signatories
								value = ROOT
							}
						}


						remove_from_array = {
							array = CHI.nine_power_treaty_signatories
							value = THIS
						}

						CHI = {
							CHI_reduce_nine_power_malus = yes
						}
					}
				}

			}
		}

		#Add First Strike Principle, Kantai Kessen and Strike South for JAPAN
		effect = { 
			if = {
				limit = {
					ROOT = { 
						original_tag = JAP
						has_completed_focus = JAP_the_imperial_defense_plan
						NOT = {
							has_completed_focus = JAP_implement_army_reforms 
						}
						OR = { #If japan has one of these Ideas, there's no need to check for any other criteria
							NOT = {
								has_idea = JAP_first_strike_principle_1
							}
							NOT = {
								has_idea = JAP_first_strike_principle_2
							}
							NOT = {
								has_idea = JAP_first_strike_principle_3
							}
						}
						OR = {
							any_controlled_state = {
								any_neighbor_state = {
									controller = {
										original_tag = FROM
									}
								}
							}
							any_subject_country = {
								any_controlled_state = {
									any_neighbor_state = {
										controller = {
											original_tag = FROM
										}
									}
								}
							}
						}
					}
					FROM = { #Can't execute a precise strike if the Kwantung Army fumbles its way into a war.... again
						NOT = { has_country_flag = JAP_first_strike_principle_blocked }
					}
				}
				if = {
					limit = {
						NOT = { has_dynamic_modifier = { modifier = JAP_first_strike_principle_dm }}
					}
					add_dynamic_modifier = { modifier = JAP_first_strike_principle_dm }
				}
				if = {
					limit = {
						NOT = {
							has_idea = JAP_first_strike_principle_1
						}
					}
					set_variable = { JAP.JAP_first_strike_principle_target_1 = FROM }
					#The variable is cleared when the idea is removed within the idea
					set_country_flag = { 
						flag = JAP_first_strike_principle_remaining_days_1
						days = 89
					}
					ROOT = {
						add_timed_idea = {
						 	idea = JAP_first_strike_principle_1
						 	days = 90
						 }
					}
				}
				else_if = {
					limit = {
						NOT = {
							has_idea = JAP_first_strike_principle_2
						}
					}
					set_variable = { JAP.JAP_first_strike_principle_target_2 = FROM }
					#The variable is cleared when the idea is removed within the idea
					set_country_flag = { 
						flag = JAP_first_strike_principle_remaining_days_2
						days = 89
					}
					ROOT = {
						add_timed_idea = {
						 	idea = JAP_first_strike_principle_2
						 	days = 90
						 }
					}
				}
				else_if = {
					limit = {
						NOT = {
							has_idea = JAP_first_strike_principle_3
						}
					}
					set_variable = { JAP.JAP_first_strike_principle_target_3 = FROM }
					#The variable is cleared when the idea is removed within the idea
					set_country_flag = { 
						flag = JAP_first_strike_principle_remaining_days_3
						days = 89
					}
					ROOT = {
						add_timed_idea = {
						 	idea = JAP_first_strike_principle_3
						 	days = 90
						 }
					}
				}
			}
			if = {
				limit = {
					ROOT = { 
						original_tag = JAP
						has_completed_focus = JAP_the_imperial_defense_plan
						NOT = {
							has_completed_focus = JAP_implement_army_reforms 
						}
						OR = { #If japan has one of these Ideas, there's no need to check for any other criteria
							NOT = {
								has_idea = JAP_kantai_kessen_1
							}
							NOT = {
								has_idea = JAP_kantai_kessen_2
							}
							NOT = {
								has_idea = JAP_kantai_kessen_3
							}
						}
					}
					FROM = { #The enemy gotta have ships for Japan to even start thinking about taking them seriously, but any capital ships need to be sunk!
						has_navy_size = {
						    size > 0
						    type = capital_ship
						    archetype = ship_hull_heavy
						}
						NOT = { has_country_flag = JAP_kantai_kessen_blocked }
					}
				}
				if = {
					limit = {
						NOT = { has_dynamic_modifier = { modifier = JAP_kantai_kessen_dm }}
					}
					add_dynamic_modifier = { modifier = JAP_kantai_kessen_dm }
				}
				if = {
					limit = {
						NOT = {
							has_idea = JAP_kantai_kessen_1
						}
					}
					set_variable = { JAP.JAP_kantai_kessen_target_1 = FROM }
					#The variable is cleared when the idea is removed within the idea
					set_country_flag = { 
						flag = JAP_kantai_kessen_remaining_days_1
						days = 179
					}
					ROOT = {
						add_timed_idea = {
						 	idea = JAP_kantai_kessen_1
						 	days = 180
						 }
					}
				}
				else_if = {
					limit = {
						NOT = {
							has_idea = JAP_kantai_kessen_2
						}
					}
					set_variable = { JAP.JAP_kantai_kessen_target_2 = FROM }
					#The variable is cleared when the idea is removed within the idea
					set_country_flag = { 
						flag = JAP_kantai_kessen_remaining_days_2
						days = 179
					}
					ROOT = {
						add_timed_idea = {
						 	idea = JAP_kantai_kessen_2
						 	days = 180
						 }
					}
				}
				else_if = {
					limit = {
						NOT = {
							has_idea = JAP_kantai_kessen_3
						}
					}
					set_variable = { JAP.JAP_kantai_kessen_target_3 = FROM }
					#The variable is cleared when the idea is removed within the idea
					set_country_flag = { 
						flag = JAP_kantai_kessen_remaining_days_3
						days = 179
					}
					ROOT = {
						add_timed_idea = {
						 	idea = JAP_kantai_kessen_3
						 	days = 180
						 }
					}
				}
			}
			if = {
				limit = {
					ROOT = { 
						original_tag = JAP
						has_completed_focus = JAP_prepare_the_southern_front
						NOT = {
							has_country_flag = JAP_strike_south_idea_triggered_flag
						}
					}
					FROM = {
						any_controlled_state = {
							OR = { #Narrow down the search margin the game has to go through
								is_on_continent = australia
								is_on_continent = asia
							}
							OR = {
								is_core_of = PHI
								is_core_of = VIN
								is_core_of = CAM
								is_core_of = SIA
								is_core_of = MAL
								is_core_of = INS
								is_core_of = PNG
								is_core_of = TML
								is_core_of = BRN
								is_core_of = SAR
								is_core_of = SAB
								is_core_of = PLU
								is_core_of = FOR
							}
						}
					}
				}
				ROOT = {
					#set_country_flag = JAP_strike_south_idea_triggered_flag
					#add_timed_idea = {
					# 	idea = JAP_strike_south_idea
					# 	days = 180
					# }
				}
			}
		}

		effect = {
			if = { #Give Communist China some penalties for not fighting against the invaders! 
				limit = {
					has_dlc = "No Compromise, No Surrender"
					PRC = {
						is_subject = no
						NOT = {
							has_country_flag = PRC_passive_revolutionaries_flag
							has_idea = PRC_passive_revolutionaries_idea
							has_active_mission = PRC_the_peoples_doubt
						}
					}
					
					FROM = { #China, but not PRC, is attacked by an occupier
						is_literally_china_not_prc = yes
					}
					ROOT = {
						is_literally_china = no
					}
					PRC = {
						NOT = { has_war_with = ROOT }
					}
				}
				ROOT = {
					set_country_flag = PRC_invading_china_flag
				}
				PRC = {
					set_country_flag = PRC_passive_revolutionaries_flag
					country_event = { id = SEA_PRC_misc_events.101 days = 30 random_days = 10 }
				}
			}

			#Flip the Communist Infiltrated States to PRC
			if = {
				limit = {
					OR = {
						AND = {
							ROOT = {
								original_tag = PRC
							}
							FROM = {
								any_controlled_state = {
									is_core_of = PRC
									has_dynamic_modifier = {
										modifier = PRC_infiltrated_state_3
										scope = PRC 
									}		
								}
							}
						}
						AND = {
							FROM = {
								original_tag = PRC
							}
							ROOT = {
								any_controlled_state = {
									is_core_of = PRC
									has_dynamic_modifier = {
										modifier = PRC_infiltrated_state_3
										scope = PRC 
									}	
								}
							}
						}
					}
				}
				#log = "China at war!"
				ROOT = {
					division_template = {
						name = "Mínbīng" # Represents militia units
						division_names_group = PRC_MIL_02
						template_counter = 118

						regiments = {
							militia = { x = 0 y = 0 }
							militia = { x = 0 y = 1 }
							militia = { x = 1 y = 0 }
							militia = { x = 1 y = 1 }
							militia = { x = 2 y = 0 }
							militia = { x = 2 y = 1 }
						}
						priority = 1
					}
				}
				

				#ACHIEVEMENT CHECKS
				if = {
					limit = {
						is_ironman = yes #This only applies if you can get achievements
						PRC = {
							NOT = {
								any_enemy_country = {
									is_literally_china_not_prc = yes
									NOT = { tag = RNG }
								}
							}
							all_controlled_state = {
								OR = {
									state = 1046 #Yulin
									state = 622 #Shaanbei
									state = 1032 #Yan'an
								}
							}
							NOT = { has_country_flag = PRC_lock_master_infiltrator_flag } 
						}
					}
					FROM = {
						every_controlled_state = {
							limit = {
								is_core_of = PRC
								has_dynamic_modifier = {
									modifier = PRC_infiltrated_state_3
									scope = PRC 
								}	
							}

							add_to_temp_array = {
								array = PRC.PRC_infiltrated_states_array
								value = THIS
							}
						}
					}
					PRC = {
						if = {
							limit = {
								check_variable = { PRC_infiltrated_states_array^num > 4 } 
							}
							set_global_flag = achievement_PRC_master_infiltrator
						}
						set_country_flag = PRC_lock_master_infiltrator_flag
					}
				}
				
				if = {
					limit = {
						FROM = {
							NOT = {
								original_tag = PRC
							}
							any_controlled_state = {
								is_core_of = PRC
								has_dynamic_modifier = {
									modifier = PRC_infiltrated_state_3
									scope = PRC 
								}	
							}
						}
					}
					FROM = { ## Checks if all states are taken, fixes edge case with taking an entire nation resulting in not calling any allies
						if = {
							limit = {
								all_controlled_state = {
									is_core_of = PRC
									has_dynamic_modifier = {
										modifier = PRC_infiltrated_state_3
										scope = PRC 
									}	
								}
							}
							every_allied_country = {
								limit = {
									NOT = {
										has_war_with = PRC
									}
								}
								add_to_war = {
									targeted_alliance = PREV
									enemy = PRC
								}
							}
						}
					}
					#log = "PRC attacked!"
					FROM = {
						every_controlled_state = {
							limit = {
								is_core_of = PRC
								has_dynamic_modifier = {
									modifier = PRC_infiltrated_state_3
									scope = PRC 
								}	
							}
							transfer_state_to = ROOT
							create_unit = {
								division = "division_template = \"Mínbīng\" start_experience_factor = 0.5 start_equipment_factor = 0.5"
								owner = ROOT
								count = 2
							}
						}
					}
				}
				else_if = {
					limit = {
						ROOT = {
							NOT = {	
								original_tag = PRC
							}
							any_controlled_state = {
								is_core_of = PRC
								has_dynamic_modifier = {
									modifier = PRC_infiltrated_state_3
									scope = PRC 
								}	
							}
						}
					}
					FROM = { 
						division_template = {
							name = "Mínbīng" # Represents militia units
							division_names_group = PRC_MIL_02
							template_counter = 118

							regiments = {
								militia = { x = 0 y = 0 }
								militia = { x = 0 y = 1 }
								militia = { x = 1 y = 0 }
								militia = { x = 1 y = 1 }
								militia = { x = 2 y = 0 }
								militia = { x = 2 y = 1 }
							}
							priority = 1
						}
					}
					ROOT = { ## Checks if all states are taken, fixes edge case with taking an entire nation resulting in not calling any allies
						if = {
							limit = {
								all_controlled_state = {
									is_core_of = PRC
									has_dynamic_modifier = {
										modifier = PRC_infiltrated_state_3
										scope = PRC 
									}	
								}
							}
							every_allied_country = {
								limit = {
									NOT = {
										has_war_with = PRC
									}
								}
								add_to_war = {
									targeted_alliance = PREV
									enemy = PRC
								}
							}
						}
					}
					#log = "PRC defends!" 
					ROOT = {
						every_controlled_state = {
							limit = {
								is_core_of = PRC
								has_dynamic_modifier = {
									modifier = PRC_infiltrated_state_3
									scope = PRC 
								}	
							}
							transfer_state_to = FROM
							create_unit = {
								division = "division_template = \"Mínbīng\" start_experience_factor = 0.5 start_equipment_factor = 0.5"
								owner = ROOT
								count = 2
							}
						}
					}
				}
			}
			IF = { ## When war against CHI and PRC breaks out - some generals flip to PRC
				limit = {
					has_dlc = "No Compromise, No Surrender"
					OR = { 
						AND = {
							ROOT = {
								original_tag = PRC
							}
							FROM = {
								original_tag = CHI
							}
						}
						AND = {
							FROM = {
								original_tag = PRC
							}
							ROOT = {
								original_tag = CHI
							}
						}
					}
				}

				## array here of all not PRC, then check if has characters 
				every_country = {
					limit = {
					 	is_literally_china = yes
					 	NOT = { tag = PRC }
					 	NOT = {
					 		is_subject_of = PRC
					 		is_in_faction_with = PRC
					 	}
					 	any_character = {
							has_character_flag = can_flip_to_prc
						}
					}
					 country_event = {
						id = SEA_PRC_political_events.19 
						hours = 2
						random_hours = 3
					}
				}

				PRC = {
					country_event = {
						id = SEA_PRC_political_events.20
						days = 2
					}
				}
			}
			if = {				#Return McArthur for US civil war, which he can lead the CSA in
				limit = {
					OR = {
						ROOT = {
							original_tag = USA
							has_civil_war = yes
						}
						FROM = {
							original_tag = USA
							has_civil_war = yes
						}
					}
					PHI = {
						has_character = USA_douglas_macarthur
					}
				}
				USA = {
					PHI_recall_macarthur_for_leadership = yes
				}
			}
			if = {
				limit = {
					OR = {
						FROM = {
							original_tag = PHI
						}
						ROOT = {
							original_tag = PHI
						}
					}
					PHI = {
						has_war_with = USA
					}
				}
				PHI = {
					if = {
						limit = {
							has_character = USA_douglas_macarthur
							NOT = {		#for leadership he can be recalled automatically, but don't lose him as leader for military command
								has_country_leader = {
									character = USA_douglas_macarthur
									ruling_only = yes
								}
							}
						}
						set_nationality = {
							target_country = USA
							character = USA_douglas_macarthur
						}
					}
					if = {
						limit = {
							has_character = USA_dwight_d_eisenhower
						}
						USA = {
							country_event = SEA_PHI_political_events.52
						}
					}
				}
			}
		}

		effect = {
			if = {
				limit = {
					is_ironman = yes #This only applies if you can get achievements
					date < 1940.1.1
					NOT = { has_global_flag = achievement_PRC_battle_royale }
					OR = {
						AND = {
							ROOT = {
								OR = {
									tag = PRC
									tag = JAP
								}
							}
							FROM = {
								OR = {
									tag = PRC
									tag = JAP
								}
							}
						}
						AND = {
							ROOT = {
								OR = {
									tag = PRC
									tag = CHI
								}
							}
							FROM = {
								OR = {
									tag = PRC
									tag = CHI
								}
							}
						}
					}
				}
				if = {
					limit = {
						NOT = { has_global_flag = PRC_timed_window_for_war }
						PRC = {
							NOT = { has_country_flag = PRC_locK_timed_window_for_war }
							OR = {
								AND = {
									has_war_with = CHI
									NOT = { has_war_with = JAP }
								}
								AND = {
									has_war_with = JAP
									NOT = { has_war_with = CHI }
								}
							}
						}
					}
					set_global_flag = {
						flag = PRC_timed_window_for_war
						days = 90
						value = 1
					}
					PRC = { set_country_flag = PRC_locK_timed_window_for_war } #Lock the possibility to do all of this again
				}
				else_if = {
					limit = {
						has_global_flag = {
							flag = PRC_timed_window_for_war
							days > 0
						}
						PRC = {
							has_war_with = CHI	
							has_war_with = JAP
						}
					}
					set_global_flag = achievement_PRC_battle_royale
				}
			}
		}
	}

	on_monthly_JAP = {
		effect = {
			if = { #The Imperial Factions are making demands
				limit = { #there needs to be a strong enough faction for them to start demanding stuff
					JAP_any_faction_is_tier_3_at_least = yes
					JAP_imperial_influence_demands_ready = yes # Cooldown is done 
					check_variable = { JAP_num_of_faction_demands < 2 } #Don't have more than 2 Demands on going at the same time
				}
				if = { #We need to keep track of how many Mils and Dockyards Japan has, so the Zaibatsu can demand more Civs
					limit = {
						has_war = no
						NOT = { has_country_flag = JAP_zaibatsu_faction_demands_factories }
						NOT = { has_active_mission = JAP_zaibatsu_faction_demands_factories }
					}
					set_variable = { JAP_combined_military_factories_and_dockyards = 0 }
					add_to_variable = { JAP_combined_military_factories_and_dockyards = num_of_naval_factories }
					add_to_variable = { JAP_combined_military_factories_and_dockyards = num_of_military_factories }
					divide_variable = { JAP_combined_military_factories_and_dockyards = 2 }
				}

				random_list = {

					#Army Demands
					10 = { #Build Military Factories
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_army_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_army_faction_demands_factories
								num_of_military_factories > num_of_naval_factories
							}
						}
						modifier = {
							factor = 1.5
							JAP_army_faction_is_tier_4 = yes
						}
						modifier = { 
							factor = 2
							num_of_military_factories < num_of_naval_factories
						}
						modifier = { 
							factor = 2
							has_war = yes
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_army_faction_demands_factories
						country_event = { id = SEA_imperial_influence_events.110 days = 5 random_days = 10 }
					}
					10 = { #Appoint Chief of Army
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_army_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							amount_taken_ideas = {
								amount > 0
								slots = { army_chief }
							}
						}
						modifier = { 
							factor = 0
							has_country_flag = JAP_army_faction_demands_chief_of_army
						}
						modifier = {
							factor = 1.5
							JAP_army_faction_is_tier_4 = yes
						}
						modifier = { 
							factor = 2
							has_war = yes
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_army_faction_demands_chief_of_army
						country_event = { id = SEA_imperial_influence_events.120 days = 5 random_days = 10 }
					}
					10 = { #Change Conscription Laws
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_army_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_military_demands_conscription_law_change
								has_manpower > 249999
								has_idea = scraping_the_barrel
								has_war = no
								AND = {
									has_idea = all_adults_serve
									surrender_progress > 0.15
								}
							}
						}
						modifier = {
							factor = 1.5
							JAP_army_faction_is_tier_4 = yes
						}
						modifier = {
							factor = 1.5
							NOT = {
								has_idea = extensive_conscription
								has_idea = service_by_requirement
								has_idea = all_adults_serve
								has_idea = scraping_the_barrel
							}
						}
						modifier = {
							factor = 0.5
							has_idea = service_by_requirement
							has_idea = all_adults_serve
						}
						modifier = {
							factor = 3
							OR = {
								has_idea = disarmed_nation
								has_idea = volunteer_only
								has_idea = limited_conscription
							}
							has_war = yes
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_military_demands_conscription_law_change
						country_event = { id = SEA_imperial_influence_events.130 days = 5 random_days = 10 }
					}
					10 = { #Field more men
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_army_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							has_army_manpower = {
								size > 2000000
							}
						}
						modifier = {
							factor = 1.5
							JAP_army_faction_is_tier_4 = yes
						}
						modifier = { 
							factor = 1.5
							has_army_manpower = {
								size < 750000
							}
						}
						modifier = { 
							factor = 2
							has_war_with_major = yes
						}
						modifier = { 
							factor = 0
							has_country_flag = JAP_army_faction_demands_more_fielded_men 
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_army_faction_demands_more_fielded_men
						country_event = { id = SEA_imperial_influence_events.140 days = 5 random_days = 10 }
					}
					10 = { #More Trucks
						modifier = { #Army can't make any demands if they don't have enough Influence
							factor = 0
							JAP_army_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_army_faction_demands_trucks
								has_equipment = {
									motorized_equipment > 149
								}
							}
						}
						modifier = {
							factor = 1.5
							JAP_army_faction_is_tier_4 = yes
						}
						modifier = {
							factor = 1.5
							has_equipment = {
								motorized_equipment < 100
							}
						}
						modifier = { 
							factor = 2
							has_war = yes
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_army_faction_demands_trucks
						country_event = { id =  SEA_imperial_influence_events.150 days = 5 random_days = 10 }
					}
					10 = { #More Tanks
						modifier = { #Army can't make any demands if they don't have enough Influence
							factor = 0
							JAP_army_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							NOT = { has_completed_focus = JAP_rethink_armor_doctrine }
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_army_faction_demands_tanks
								AND = {
									NOT = { has_tech = basic_medium_tank_chassis }
									has_equipment = {
										light_tank_chassis > 949
									}
								}
								AND = {
									has_tech = basic_medium_tank_chassis
									has_equipment = {
										medium_tank_chassis > 249
									}
								}
							}
						}
						modifier = {
							factor = 1.5
							JAP_army_faction_is_tier_4 = yes
						}
						modifier = {
							factor = 1.5
							OR = {
								AND = {
									NOT = { has_tech = basic_medium_tank_chassis }
									has_equipment = {
										light_tank_chassis < 501
									}
								}
								AND = {
									has_tech = basic_medium_tank_chassis
									has_equipment = {
										medium_tank_chassis < 251
									}
								}
							}
						}
						modifier = { 
							factor = 1.5
							has_war = yes
						}
						modifier = { 
							factor = 1.75
							has_war_with = SOV
						}
						modifier = { 
							factor = 1.5
							has_war_with = USA
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_army_faction_demands_tanks
						country_event = { id = SEA_imperial_influence_events.160 days = 5 random_days = 10 }
					}
					10 = { #More Artillery
						modifier = { #Army can't make any demands if they don't have enough Influence
							factor = 0
							JAP_army_faction_is_tier_3_at_least = no
						}
						modifier = { # Army is less likely to ask this if you haven't specced into arty stuff yet 
							factor = 0.5
							NOT = { has_completed_focus = JAP_adopt_new_assault_doctrine }
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_army_faction_demands_artillery
								has_equipment = {
									artillery_equipment > 199
								}
							}
						}
						modifier = {
							factor = 1.5
							JAP_army_faction_is_tier_4 = yes
						}
						modifier = {
							factor = 1.5
							has_equipment = {
								artillery_equipment < 100
							}
						}
						modifier = { 
							factor = 2
							has_war = yes
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_army_faction_demands_artillery
						country_event = { id = SEA_imperial_influence_events.161 days = 5 random_days = 10 }
					}

					#Navy Demands
					10 = { #Build Dockyards
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_naval_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_army_faction_demands_dockyards
								num_of_naval_factories > num_of_military_factories
							}
						}
						modifier = {
							factor = 1.5
							JAP_naval_faction_is_tier_4 = yes
						}
						modifier = { 
							factor = 2
							num_of_naval_factories < num_of_military_factories
						}
						modifier = { 
							factor = 1.5
							has_war = yes
						}
						modifier = { 
							factor = 2
							has_war_with = USA
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_army_faction_demands_dockyards
						country_event = { id = SEA_imperial_influence_events.210 days = 5 random_days = 10 }
					}
					10 = { #Appoint Chief of Navy
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_naval_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							amount_taken_ideas = {
								amount > 0
								slots = { navy_chief }
							}
						}
						modifier = {
							factor = 1.5
							JAP_naval_faction_is_tier_4 = yes
						}
						modifier = { 
							factor = 2
							has_war = yes
						}
						modifier = { 
							factor = 0
							has_country_flag = JAP_naval_faction_demands_chief_of_navy_flag 
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_naval_faction_demands_chief_of_navy_flag
						country_event = { id = SEA_imperial_influence_events.220 days = 5 random_days = 10 }
					}
					10 = { #Change Conscription Laws
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_naval_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_military_demands_conscription_law_change
								has_manpower > 249999
								has_idea = scraping_the_barrel
								has_war = no
								AND = {
									has_idea = all_adults_serve
									surrender_progress > 0.15
								}
							}
						}
						modifier = {
							factor = 1.5
							JAP_naval_faction_is_tier_4 = yes
						}
						modifier = {
							factor = 1.5
							NOT = {
								has_idea = extensive_conscription
								has_idea = service_by_requirement
								has_idea = all_adults_serve
								has_idea = scraping_the_barrel
							}
						}
						modifier = {
							factor = 0.5
							has_idea = service_by_requirement
							has_idea = all_adults_serve
						}
						modifier = {
							factor = 2
							OR = {
								has_idea = disarmed_nation
								has_idea = volunteer_only
								has_idea = limited_conscription
							}
							has_war = yes
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_military_demands_conscription_law_change
						country_event = { id = SEA_imperial_influence_events.230 days = 5 random_days = 10 }
					}
					10 = { #Build Carriers
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_naval_faction_is_tier_3_at_least = no
						}
						modifier = {
							factor = 0
							OR = {
								NOT = {	has_completed_focus = JAP_focus_on_aircraft_carriers }
								has_country_flag = JAP_naval_faction_demands_carriers
								has_navy_size = {
									unit = carrier
									size > 17
								}
							}
						}
						modifier = {
							factor = 1.5
							has_navy_size = {
								unit = carrier
								size < 10
							}
						}
						modifier = { 
							factor = 1.5
							has_war_with_major = yes
						}
						modifier = { 
							factor = 1.5
							has_war_with = USA
						}
						modifier = { 
							factor = 1.5
							date > 1941.1.1
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_naval_faction_demands_carriers
						country_event = { id = SEA_imperial_influence_events.240 days = 5 random_days = 10 }
					}
					10 = { #Build Carriers and Battleships
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_naval_faction_is_tier_3_at_least = no
						}
						modifier = {
							factor = 0
							OR = {
								NOT = {	has_completed_focus = JAP_balanced_naval_approach }
								has_country_flag = JAP_naval_faction_demands_carriers
								has_country_flag = JAP_naval_faction_demands_battleships
								AND = {
									has_navy_size = {
										unit = carrier 
										size > 8
									}
									has_navy_size = {
										archetype = ship_hull_heavy
										size > 12
									}
								}
							}
						}
						modifier = {
							factor = 1.5
							has_navy_size = {
								unit = carrier 
								size < 8
							}
							has_navy_size = {
								archetype = ship_hull_heavy
								size < 12
							}
						}
						modifier = { 
							factor = 1.5
							has_war_with_major = yes
						}
						modifier = { 
							factor = 1.5
							has_war_with = USA
						}
						modifier = { 
							factor = 1.5
							date > 1941.1.1
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_naval_faction_demands_carriers
						set_country_flag = JAP_naval_faction_demands_battleships
						country_event = { id = SEA_imperial_influence_events.241 days = 5 random_days = 10 }
					}
					10 = { #Build Battleships
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_naval_faction_is_tier_3_at_least = no
						}
						modifier = {
							factor = 0
							OR = {
								NOT = {	has_completed_focus = JAP_sea_battleship_initiative }
								has_country_flag = JAP_naval_faction_demands_carriers
								has_country_flag = JAP_naval_faction_demands_battleships
								has_navy_size = {
									archetype = ship_hull_heavy
									size > 24
								}
							}
						}
						modifier = {
							factor = 1.5
							has_navy_size = {
								archetype = ship_hull_heavy
								size < 15
							}
						}
						modifier = { 
							factor = 1.5
							has_war_with_major = yes
						}
						modifier = { 
							factor = 1.5
							has_war_with = USA
						}
						modifier = { 
							factor = 1.5
							date > 1941.1.1
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_naval_faction_demands_battleships
						country_event = { id = SEA_imperial_influence_events.242 days = 5 random_days = 10 }
					}

					#Zaibatsu Demands
					10 = { #Build Civilian Factories
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_zaibatsu_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_war = yes
								has_country_flag = JAP_zaibatsu_faction_demands_factories
								num_of_civilian_factories > JAP_combined_military_factories_and_dockyards
							}
						}
						modifier = {
							factor = 1.5
							has_idea = JAP_zaibatsu_faction_tier_4
						}
						modifier = { 
							factor = 2
							num_of_civilian_factories < JAP_combined_military_factories_and_dockyards
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_zaibatsu_faction_demands_factories
						country_event = { id = SEA_imperial_influence_events.310 days = 5 random_days = 10 }
					}
					10 = { #Appoint Industrial Advisor
						modifier = { #Zaibatsus can't make any demands if they don't have enough Influence
							factor = 0
							JAP_zaibatsu_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								JAP_yosuke_matsuoka = {
									is_political_advisor = yes
								}
								JAP_koyata_iwasaki = {
									is_political_advisor = yes
								}
								JAP_chikuhei_nakajima = {
									is_political_advisor = yes
								}
								JAP_yoshisuke_aikawa = {
									is_political_advisor = yes
								}
								JAP_kenjiro_matsumoto = {
									is_political_advisor = yes
								}
							}
						}
						modifier = {
							factor = 1.5
							has_idea = JAP_zaibatsu_faction_tier_4
						}
						modifier = { 
							factor = 2
							date > 1940.1.1
							amount_taken_ideas = {
								amount < 3
								slots = { political_advisor }
							}
						}
						modifier = { 
							factor = 0
							has_country_flag = JAP_zaibatsu_faction_demands_industrial_advisor_flag 
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_zaibatsu_faction_demands_industrial_advisor_flag
						country_event = { id = SEA_imperial_influence_events.320 days = 5 random_days = 10 }
					}
					10 = { #Change Trade Laws
						modifier = { #Zaibatsus can't make any demands if they don't have enough Influence
							factor = 0
							JAP_zaibatsu_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_idea = civilian_economy
								has_war = yes
							}
						}
						modifier = {
							factor = 1.5
							has_idea = JAP_zaibatsu_faction_tier_4
						}
						modifier = {
							factor = 2
							NOT = {
								has_idea = free_trade
								has_idea = export_focus
							}
						}
						modifier = { 
							factor = 0
							has_country_flag = JAP_zaibatsu_faction_demands_trade_law_change 
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_zaibatsu_faction_demands_trade_law_change
						country_event = { id = SEA_imperial_influence_events.330 days = 5 random_days = 10 }
					}
					10 = { #Hire Industrial Company
						modifier = { #Zaibatsus can't make any demands if they don't have enough Influence
							factor = 0
							JAP_zaibatsu_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_country_flag = JAP_zaibatsu_faction_demands_industrial_company
								has_idea = sumitomo
								has_idea = mitsubishi_civilian
								has_idea = mitsui_bank
								has_idea = yasuda_zaibatsu
							}
						}
						modifier = {
							factor = 1.5
							has_idea = JAP_zaibatsu_faction_tier_4
						}
						modifier = { 
							factor = 2
							date > 1938.1.1
							amount_taken_ideas = {
								amount < 1
								slots = { industrial_concern }
							}
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_zaibatsu_faction_demands_industrial_company
						country_event = { id = SEA_imperial_influence_events.340 days = 5 random_days = 10 }
					}

					#Government Demands
					10 = { #Appoint Civilian Advisor
						modifier = { #Navy can't make any demands if they don't have enough Influence
							factor = 0
							JAP_government_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							amount_taken_ideas = {
								amount > 2
								slots = { political_advisor }
							}
						}
						modifier = {
							factor = 1.5
							has_idea = JAP_government_faction_tier_4
						}
						modifier = { 
							factor = 2
							date > 1941.1.1
							amount_taken_ideas = {
								amount < 3
								slots = { political_advisor }
							}
						}
						modifier = { 
							factor = 0
							has_country_flag = JAP_civic_faction_demands_civilian_advisor_appointment
						}
						
						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_civic_faction_demands_civilian_advisor_appointment
						country_event = { id = SEA_imperial_influence_events.420 days = 5 random_days = 10 }
					}
					10 = { #Change Trade Laws
						modifier = { #Government can't make any demands if they don't have enough Influence
							factor = 0
							JAP_government_faction_is_tier_3_at_least = no
						}
						modifier = { 
							factor = 0
							OR = {
								has_idea = free_trade
								has_war = yes
							}
						}
						modifier = {
							factor = 1.5
							has_idea = JAP_government_faction_tier_4
						}
						modifier = {
							factor = 2
							NOT = {
								has_idea = free_trade
								has_idea = export_focus
							}
						}
						modifier = { 
							factor = 0
							has_country_flag = JAP_civic_faction_demands_trade_law_change_flag 
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_civic_faction_demands_trade_law_change_flag
						country_event = { id = SEA_imperial_influence_events.430 days = 5 random_days = 10 }
					}
					10 = { #Limit the Army's Influence
						modifier = { #Government can't make any demands if they don't have enough Influence
							factor = 0
							JAP_government_faction_is_tier_3_at_least = no
						}
						modifier = {
							factor = 0
							OR = {
								has_country_flag = JAP_government_faction_demands_more_influence
								JAP_army_faction_is_tier_3_at_least = no
							}
						}
						modifier = {
							factor = 2
							has_idea = JAP_government_faction_tier_3
							JAP_army_faction_is_tier_3 = yes
						}
						modifier = {
							factor = 3
							has_idea = JAP_government_faction_tier_3
							JAP_army_faction_is_tier_4 = yes
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_government_faction_demands_more_influence
						country_event = { id = SEA_imperial_influence_events.440 days = 5 random_days = 10 }
					}
					10 = { #Limit the Navy's Influence
						modifier = { #Government can't make any demands if they don't have enough Influence
							factor = 0
							JAP_government_faction_is_tier_3_at_least = no
						}
						modifier = {
							factor = 0
							OR = {
								has_country_flag = JAP_government_faction_demands_more_influence
								JAP_naval_faction_is_tier_3_at_least = no
							}
						}
						modifier = {
							factor = 2
							has_idea = JAP_government_faction_tier_3
							JAP_naval_faction_is_tier_3 = yes
						}
						modifier = {
							factor = 3
							has_idea = JAP_government_faction_tier_3
							JAP_naval_faction_is_tier_4 = yes
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_government_faction_demands_more_influence
						country_event = { id = SEA_imperial_influence_events.450 days = 5 random_days = 10 }
					}
					10 = { #Limit the Zaibatus' Influence
						modifier = { #Government can't make any demands if they don't have enough Influence
							factor = 0
							JAP_government_faction_is_tier_3_at_least = no
						}
						modifier = {
							factor = 0
							OR = {
								has_country_flag = JAP_government_faction_demands_more_influence
								JAP_zaibatsu_faction_is_tier_3_at_least = no
							}
						}
						modifier = {
							factor = 2
							has_idea = JAP_government_faction_tier_3
							has_idea = JAP_zaibatsu_faction_tier_3
						}
						modifier = {
							factor = 3
							has_idea = JAP_government_faction_tier_3
							has_idea = JAP_zaibatsu_faction_tier_4
						}

						JAP_faction_demand_activation_effects = yes

						set_country_flag = JAP_government_faction_demands_more_influence
						country_event = { id = SEA_imperial_influence_events.460 days = 5 random_days = 10 }
					}
				}
			}
		}
	}
	
	on_monthly_CHI = {
		effect = {
			CHI_is_corruption_in_government_on_balance_good = yes
			CHI_update_claimed_and_core_states = yes

			if = {
				limit = {
					has_completed_focus = CHI_denounce_feudalism
				}

				every_subject_country = {
					limit = {
						is_literally_china = yes
						NOT = {
							is_in_array = {
								array = ROOT.warlord_subjects
								value = THIS
							}
						}
					}
					add_to_array = {
						array = ROOT.warlord_subjects
						value = THIS
					}
				}

				for_each_scope_loop = {
					array = ROOT.warlord_subjects

					if = {
						limit = {
							OR = {
								exists = no
								is_subject = no
								NOT = { is_ally_with = ROOT }
							}
						}
						remove_from_array = {
							array = ROOT.warlord_subjects
							value = THIS 
						}
					}
					
				}
				if = {
					limit = {
						
						check_variable = { warlord_subjects^num > 0 }
					}

					set_temp_variable = { t_warlord_subjects_pp_gain = warlord_subjects_pp_gain_base }
					multiply_temp_variable = { t_warlord_subjects_pp_gain = warlord_subjects^num }
					add_political_power = var:t_warlord_subjects_pp_gain
					log = "fwjaifjwai [var:t_warlord_subjects_pp_gain]"
				}
			}

		}
		effect = {
			IF = {
				limit = {
					has_dynamic_modifier = {
						modifier = CHI_soviet_support
					}
				}
				IF = {
					limit = {
						has_completed_focus = CHI_sell_lend_lease
					}
					add_cic = var:CHI_soviet_support_cic_amount
				}
			}
			IF = {
				limit = {
					has_dynamic_modifier = {
						modifier = CHI_american_support
					}
					NOT = {
						any_enemy_country = {
							OR = {
								controls_state = 325
								controls_state = 671
								controls_state = 995
								controls_state = 640
								controls_state = 998
								controls_state = 434
								controls_state = 990
								controls_state = 432
								controls_state = 288
								controls_state = 997
								controls_state = 996
								controls_state = 601
								controls_state = 434
								controls_state = 747
							}
						}
					}
				}

				add_cic = var:CHI_american_support_cic_amount
				if = {
					limit = {
						any_subject_country = {
							has_idea = CHI_chinese_economic_support_idea
						}
					}
					every_subject_country = {
						limit = {
							has_idea = CHI_chinese_economic_support_idea
						}
						add_cic = CHI.CHI_economic_support_cic_amount
					}
				}
			}
			IF = {
				limit = {
					has_dynamic_modifier = {
						modifier = CHI_american_reconstruction_support
					}
				}
				add_cic = var:CHI_american_reconstruction_support_cic_amount
			}
			IF = {
				limit = {
					has_dynamic_modifier = {
						modifier = CHI_foreign_economic_support
					}
				}
				add_cic = var:CHI_foreign_economic_support_cic_amount
			}

		}

		effect = {
			IF = {
				limit = {
					has_completed_focus = CHI_continue_the_ding_xian_experiment
					any_core_state = {
						NOT = { 
							has_dynamic_modifier = { modifier = CHI_electrification_and_mass_education_modifier }
						}
					}
				}

				IF = {
					limit = {
						check_variable = { CHI_electrification_cooldown > 0 }
					}
					set_variable = { CHI_electrification_cooldown = 0 }

					random_core_state = {
						limit = {
							has_dynamic_modifier = { modifier = CHI_electrification_and_mass_education_modifier }
							NOT = {
								OR = {
									is_island_state = yes
									has_state_category = large_island
									has_state_category = small_island
									has_state_category = tiny_island
								}
							}
						}
						random_neighbor_state = {
							limit = {
								NOT = {
									has_dynamic_modifier = { modifier = CHI_electrification_and_mass_education_modifier }
								}
								is_core_of = ROOT
								OWNER = {
									is_literally_china = yes
									NOT = {
										has_war_with = CHI
									}
								}
							}
							add_dynamic_modifier = { modifier = CHI_electrification_and_mass_education_modifier }
						}
					}
				}
				ELSE = {
					add_to_variable = { CHI_electrification_cooldown = 1 }
				}	
			}
		}

	}


	#ROOT is winner #FROM gets annexed - This will also fire on_annex
	on_civil_war_end = {

		effect = {
			# Give Japan a celebratory event when the democratic side wins the civil war 
			IF = {
				limit = {
					original_tag = JAP
					has_government = democratic
					has_completed_focus = JAP_revoke_the_peace_preservation_law
					FROM = {
						original_tag = JAP
						has_government = fascism 
					}
				}
				country_event = {
					id = SEA_japan_popup_events.24
					hours = 1
				}	
			}
		}

	}

	on_civil_war_end_before_annexation = {
		effect = {
			if = {
				limit = {
					FROM = {
						original_tag = SPR
						has_volunteers_amount_from = {
							tag = PHI
							count > 0
						}
					}
				}
				PHI = {
					set_country_flag = PHI_support_scw_faction_lost
				}
			}
			if = {
				limit = {
					original_tag = SPR
					has_volunteers_amount_from = {
						tag = PHI
						count > 0
					}
					NOT = {
						any_other_country = {
							original_tag = SPR
							NOT = {
								tag = FROM
							}
						}
					}
				}
				PHI = {
					set_country_flag = PHI_support_scw_faction_won
				}
			}
		}
	}



	on_capitulation = { # ROOT is capitulated country, FROM is winner

		effect = {
			#Yulbars Khan flees
			IF = {
				limit = {
					ROOT = {
						OR = {
							original_tag = KUM
							original_tag = KHM
						}
						has_character = KUM_yulbars_khan
						has_war_with = SIK
					}
				}
				IF = {
					limit = {
						original_tag = KUM
						is_subject_of = KHM
					}
					IF = {
						limit = {
							KHM = {
								has_capitulated = no
							}
						}
						KHM = {
							country_event = {
								id = SEA_warlords.10
								hours = 6
							}
						}
					}
					ELSE = {
						IF = {
							limit = {
								CHI = {
									exists = yes
								}
							}
							CHI = {
								country_event = {
									id = SEA_warlords.11
									hours = 6
								}
							}
						}
					}
				}
				ELSE_IF = {
					limit = {
						original_tag = KUM
						NOT = {
							is_subject_of = KHM
						}
					}
					IF = {
						limit = {
							CHI = {
								exists = yes
							}
						}
						CHI = {
							country_event = {
								id = SEA_warlords.11
								hours = 6
							}
						}
					}
				}
				ELSE = {
					IF = {
						limit = {
							CHI = {
								exists = yes
							}
						}
						CHI = {
							country_event = {
								id = SEA_warlords.11
								hours = 6
							}
						}
					}
				}
			}
		}

		# Ma Hongbin flees 
		effect = {

			IF = {
				limit = {
					ROOT = {
						original_tag = KHM
						has_character = XSM_ma_hongbin
					}
				}
				IF = {
					limit = {
						NXM = {
							exists = yes
						}
					}
					NXM = {
						country_event = {
							id = SEA_warlords.12
							hours = 6
						}
					}
				}
				ELSE_IF = {
					limit = {
						XSM = {
							exists = yes
						}
					}
					XSM = {
						country_event = {
							id = SEA_warlords.12
							hours = 6
						}
					}
				}
				ELSE_IF = {
					limit = {
						GSM = {
							exists = yes
						}
					}
					GSM = {
						country_event = {
							id = SEA_warlords.12
							hours = 6
						}
					}
				}
			}

		}

		# Mahmut Muhiti offers to return to Sinkiangi service 
		effect = {

			IF = {
				limit = {
					ROOT = {
						original_tag = KHM
						has_character = KHM_mahmut_muhiti
					}
					FROM = {
						original_tag = SIK
					}
				}
				SIK = {
					country_event = {
						id = SEA_warlords.13
						hours = 6
					}
				}
			}
		}

		# Ma Hushan flees with gold to India 
		effect = {

			IF = {
				limit = {
					ROOT = {
						original_tag = KHM
						has_character = KHM_ma_hushan
					}
					FROM = {
						original_tag = SIK
					}
					RAJ = {
						exists = yes
					}
				}
				RAJ = {
					country_event = {
						id = SEA_warlords.64
						hours = 12
					}
				}
			}
		}

		effect = {
			if = {
				limit = {
					ROOT = {
						original_tag = PHI
					}
				}
				if = {
					limit = {
						has_character = USA_douglas_macarthur
					}
					set_nationality = {
						target_country = USA
						character = USA_douglas_macarthur
					}
				}
				if = {
					limit = {
						has_character = USA_dwight_d_eisenhower
						NOT = {
							has_completed_focus = PHI_police_chief_eisenhower
						}
					}
					USA = {
						country_event = SEA_PHI_political_events.52
					}
				}
			}
		}

		effect = { # Trigger thedissolutuion of the HBC event
			IF = {
				limit = {
					ROOT = {
						original_tag = HBC
						is_ally_with = CHI
					}

					FROM = {
						has_war_with = HBC
						has_war_with = CHI
						OR = {
							original_tag = JAP
							AND = {
								original_tag = RNG
								is_ally_with = JAP
							}
							AND = {
								original_tag = MAN
								is_ally_with = JAP
							}
							AND = {
								original_tag = MEN
								is_ally_with = JAP
							}
						}
					}
					
					NOT = { has_global_flag = hbc_has_been_dissolved }
				}
				CHI = {
					country_event = {
						id = SEA_warlords.69 
						hours = 6
					}
				}
			}
		}

		#PRC capitulates
		effect = {
			IF = {
				limit = {
					ROOT = {
						original_tag = PRC
						owns_state = 1046
					}
					1046 = {
						has_dynamic_modifier = { modifier = PRC_the_yulin_garrison }
					}
				}
				1046 = {
					remove_dynamic_modifier = { modifier = PRC_the_yulin_garrison }
				}
			}
			IF = { #If PRC capitulates after having completed Burn the Paper tiger and is faction leader, then make China a major so they can continue the fight against Japan
				limit = {
					ROOT = {
						original_tag = PRC
						has_completed_focus = PRC_burn_the_paper_tigers
						is_faction_leader = yes
						is_in_faction_with = CHI
					}
					FROM = {
						OR = {
							original_tag = JAP
							is_in_faction_with = JAP
						}
					}
				}
				if = {
					limit = {
						CHI = {
							is_major = no
							is_subject = no
							exists = yes
							has_capitulated = no
						}
					}
					CHI = {
						set_faction_leader = yes
					}
				}
			}
		}

		# Three way civil war - demo Japan is defeated and should be annexed into com JAP 
		effect = {

			IF = {
				limit = {
					ROOT = {
						original_tag = JAP
						has_government = democratic
						has_country_flag = JAP_is_demo_in_three_way_cw_country_flag
					}
					FROM = {
						original_tag = JAP
					}
				}
				JAP = {
					annex_country = {
						target = ROOT
						transfer_troops = no 
					}	
				}
			}
		}

		# Remove nine-power treaty signatory
		effect = {
			IF = {
				limit = {
					is_in_array = {
						array = CHI.nine_power_treaty_signatories
						value = ROOT
					}
				}
				CHI = {
					country_event = {
						id = SEA_china.24
						hours = 8 	
						random_hours = 8 
					}
				}
			}
		}

		#ACHIEVEMENTS
		effect = {
			if = {
				limit = {
					is_ironman = yes #This only applies if you can get achievements
					has_global_flag = achievement_PRC_battle_royale
					FROM = {
						tag = PRC #using tag here instead of original_tag because that's what the achievement needs
					}
					ROOT = {
						OR = {
							tag = CHI
							tag = JAP
						}
					}
				}
				if = {
					limit = {
						ROOT = { tag = CHI}
					}
					FROM = { set_country_flag = PRC_capitulated_CHI }
				}
				if = {
					limit = {
						ROOT = { tag = JAP}
					}
					FROM = { set_country_flag = PRC_capitulated_JAP }
				}
			}
			if = {
				limit = {
					is_ironman = yes #This only applies if you can get achievements
					FROM = {
						tag = JAP #using tag here instead of original_tag because that's what the achievement needs
						has_government = democratic
					}
					ROOT = {
						tag = GER #using tag here instead of original_tag because that's what the achievement needs
						GER = {
							has_government = fascism
						}
					}
				}
				set_global_flag = achievement_JAP_capitulated_fascist_germany
			}
		}

	}


	on_subject_autonomy_level_change = {
		effect = {	#PHI: return oil/advisors if no longer allied with USA/JAP
			if = {
				limit = {
					original_tag = PHI
				}
				if = {
					limit = {
						has_resources_rights = {
							state = 371
						}
						NOT = {
							is_ally_with = USA
						}
					}
					remove_resource_rights = 371
				}
				if = {
					limit = {
						has_character = JAP_kiyoshi_hasegawa
						NOT = {
							is_ally_with = JAP
						}
					}
					set_nationality = {
						target_country = JAP
						character = JAP_kiyoshi_hasegawa
					}
				}
			}
		}
		effect = {	#JAP: lose US puppet cosmetic tag if no longer a US puppet 
			IF = {
				limit = {
					original_tag = JAP
					has_cosmetic_tag = JAP_us_occupation
				}
				drop_cosmetic_tag = yes
			}
		}
	}

	on_war = {
		effect = {
			if = {
				limit = {
					original_tag = PHI
				}
				PHI_update_war_flag = yes
			}
			set_country_flag = guardians_of_peace_been_at_war_flag
		}
	}

	on_peace = {
		effect = {
			if = {
				limit = {
					original_tag = PHI
				}
				PHI_update_war_flag = yes
			}
		}
	}

	on_new_term_election = {
		effect = {
			if = {
				limit = {
					original_tag = PHI
					has_government = democratic
					date < 1942.01.01
				}
				PHI = {
					country_event = SEA_PHI_political_events.63
				}
			}
		}
	}

	on_exile_government_reinstated = {
		effect = {
			if = {
				limit = {
					original_tag = PHI
					has_government = democratic
					date > 1943.1.1
				}
				set_country_flag = PHI_early_presidential_election
				country_event = {
					id = SEA_PHI_political_events.63
					days = 250
				}
			}
		}
	}

	on_uncapitulation = {
		effect = {		#feel free to remove this same block in exile_government_reinstated if the two always coincide
			if = {
				limit = {
					original_tag = PHI
					has_government = democratic
					date > 1943.1.1
				}
				set_country_flag = PHI_early_presidential_election
				country_event = {
					id = SEA_PHI_political_events.63
					days = 250
				}
			}
		}
	}

	# ROOT is winner, FROM is loser (called for all winners against all losers)
	on_before_peace_conference_start = {
		effect = {
			IF = {
				limit = {
					ROOT = { NOT = { has_country_flag = peace_winner_flag } }
				}
				set_country_flag = peace_winner_flag
			}
		}
	}

	# ROOT is the winner, FROM is the loser 
	on_peaceconference_ended = {

        effect = {
            FROM = {
                if = {    #This prevents the country capping again after just having been puppeted
                    limit = {
                        has_idea = BEL_surrender_ns
                    }
                    remove_ideas = BEL_surrender_ns
                }
            }
        }

        # CHI has lost and RNG has been validated as an actual China 
        effect = {
    		IF = {
    			limit = {
    				# The Reorganized National Government is a winner
    				ROOT = {
    					original_tag = RNG
    				}
    				# One of the losers if Nationalist China
    				FROM = {
    					original_tag = CHI 
    	 			}
    			}
    			FROM = {
    				every_core_state = {
    					add_core_of = ROOT
    				}
    			}
    		}
        }

        # Merging of Japanese puppet governments into one (ONLY WHEN JAPAN IS AN AI)
        effect = {
        	IF = {
        		limit = {
        			# Japan is a winner and has the RNG as their puppet 
        			ROOT = {
        				original_tag = JAP
        				is_ai = yes 
        				has_subject = RNG
        			}
        			# One of the losers if Nationalist China and has been puppeted by Japan 
        			FROM = {
        				original_tag = CHI 
        				is_subject_of = JAP
         			}
        		}
        		RNG = {
        			annex_country = {
        				target = FROM
        				transfer_troops = yes
        			}	
        		}
        	}
        }

    }



}
