is_potentially_communist_china = {
	OR = {
		original_tag = PRC
		original_tag = GXC
		original_tag = YUN
		original_tag = SHX
		original_tag = XSM
		original_tag = SIK
	}
}

is_current_communist_china = {
	tag = event_target:WTT_communist_china
}

PRC_can_increase_infiltration_in_state = {
	custom_trigger_tooltip = {
		tooltip = PRC_can_be_infiltrated
		OR = {
			NOT = { has_state_flag = PRC_infiltration_@ROOT }
			has_state_flag = {
				flag = PRC_infiltration_@ROOT
				value < 4
			}
		}
	}
}

PRC_uprising_is_available = {
	custom_trigger_tooltip = {
		tooltip = PRC_uprising_is_available
		event_target:WTT_current_china_leader = {
			any_controlled_state = {
				PRC_is_infiltrated_by_ROOT = yes
			}
		}
	}
}

PRC_is_infiltrated_by_PREV = {
	has_state_flag = {
		flag = PRC_infiltration_@PREV
		value > 0
	}
}

PRC_is_infiltrated_by_ROOT = {
	has_state_flag = {
		flag = PRC_infiltration_@ROOT
		value > 0
	}
}

PRC_is_not_infiltrating_a_state = {
	custom_trigger_tooltip = {
		tooltip = PRC_is_not_infiltrating_a_state
		NOT = {
			has_decision = PRC_infiltrate_gansu
			has_decision = PRC_infiltrate_shandong
			has_decision = PRC_infiltrate_jiangsu
			has_decision = PRC_infiltrate_henan
			has_decision = PRC_infiltrate_beijing
			has_decision = PRC_infiltrate_hebei
			has_decision = PRC_infiltrate_shanxi
			has_decision = PRC_infiltrate_suiyuan
			has_decision = PRC_infiltrate_xian
			has_decision = PRC_infiltrate_ordos

			#Anti Japan
			has_decision = PRC_infiltrate_east_hebei
			has_decision = PRC_infiltrate_jehol
			has_decision = PRC_infiltrate_south_chahar
			has_decision = PRC_infiltrate_chahar
			has_decision = PRC_infiltrate_heilungkiang
			has_decision = PRC_infiltrate_liaoning
		}
	}
}

#Trigger checks for a flag on the state, dynamically appending the country tag of one of china countries
has_any_PRC_infiltration_flag = {
	any_country = {
		is_potentially_communist_china = yes
		PREV = {
			has_state_flag = PRC_infiltration_@PREV
		}
	}
}

ROOT_any_state_infiltration_detected = {
	any_state = {
		is_controlled_by = ROOT
		has_state_flag = {
			flag = discovered_infiltration
			value > 0
		}
	}	
}

ROOT_any_anti_JAP_state_infiltration_detected = {
	any_state = {
		is_controlled_by_ROOT_or_subject = yes
		has_state_flag = {
			flag = discovered_infiltration
			value > 0
		}
	}	
}

PRC_has_low_popular_support = {
	if = {
		limit = {
			has_idea = PRC_low_popular_support_5
		}
		has_idea = PRC_low_popular_support_5
	}
	if = {
		limit = {
			has_idea = PRC_low_popular_support_4
		}
		has_idea = PRC_low_popular_support_4
	}
	if = {
		limit = {
			has_idea = PRC_low_popular_support_3
		}
		has_idea = PRC_low_popular_support_3
	}
	if = {
		limit = {
			has_idea = PRC_low_popular_support_2
		}
		has_idea = PRC_low_popular_support_2
	}
	if = {
		limit = {
			NOT = {
				has_idea = PRC_low_popular_support_1
				has_idea = PRC_low_popular_support_2
				has_idea = PRC_low_popular_support_3
				has_idea = PRC_low_popular_support_4
				has_idea = PRC_low_popular_support_5
			}
		}
		has_idea = PRC_low_popular_support_1
	}
}

#State scope
PRC_infiltration_uprising_PREV_will_spawn_troops_in_state = {
	is_controlled_by = event_target:WTT_current_china_leader			
	has_state_flag = {
		flag = PRC_infiltration_@PREV
		value > 2
	}
}

#State scope
PRC_infiltration_uprising_PREV_will_sabotage_state = {
	is_controlled_by = event_target:WTT_current_china_leader	
	OR = {
		has_state_flag = {
			flag = PRC_infiltration_@PREV
			value = 1
		}
		has_state_flag = {
			flag = PRC_infiltration_@PREV
			value = 2
		}
	}
}

PRC_any_nationalist_area_infiltrated_by_PREV = {
	OR = {
		283 = { PRC_is_infiltrated_by_PREV = yes }
		597 = { PRC_is_infiltrated_by_PREV = yes }
		598 = { PRC_is_infiltrated_by_PREV = yes }
		607 = { PRC_is_infiltrated_by_PREV = yes }
		608 = { PRC_is_infiltrated_by_PREV = yes }
		614 = { PRC_is_infiltrated_by_PREV = yes }
		615 = { PRC_is_infiltrated_by_PREV = yes }
		621 = { PRC_is_infiltrated_by_PREV = yes }
	}
}

#Country scope
PRC_all_nationalist_area_infiltration_discovered = {
	283 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	597 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	598 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	607 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	608 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	614 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	615 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	621 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
}

#Country scope
PRC_ROOT_war_with_controller_of_anti_japan_infiltrated_state = {
	OR = {
		609 = { PRC_is_infiltrated_by_PREV = yes CONTROLLER = { has_war_with = ROOT } }
		610 = { PRC_is_infiltrated_by_PREV = yes CONTROLLER = { has_war_with = ROOT } }
		611 = { PRC_is_infiltrated_by_PREV = yes CONTROLLER = { has_war_with = ROOT } }
		612 = { PRC_is_infiltrated_by_PREV = yes CONTROLLER = { has_war_with = ROOT } }
		714 = { PRC_is_infiltrated_by_PREV = yes CONTROLLER = { has_war_with = ROOT } }
		715 = { PRC_is_infiltrated_by_PREV = yes CONTROLLER = { has_war_with = ROOT } }
	}
}

#Country scope
PRC_all_anti_japan_infiltration_discovered = {
	609 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	610 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	611 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	612 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	714 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
	715 = {
		has_state_flag = discovered_infiltration
		PRC_is_infiltrated_by_PREV = yes
	}
}

PRC_japanese_state_available_for_infiltration_trigger = {
	OR = {
		CONTROLLER = {
			NOT = { has_war_with = ROOT }
			OR = {
				original_tag = MAN
				original_tag = MEN
				original_tag = JAP
			}
		}
		PRC_is_infiltrated_by_PREV = yes
	}
}