#Add to scripted triggers if more levels of hyper inflation is added
CHI_hyper_inflation_clear_all = {
	remove_ideas = {
		CHI_hyper_inflation_1
		CHI_hyper_inflation_2
		CHI_hyper_inflation_3
		CHI_hyper_inflation_4
		CHI_hyper_inflation_5
	}
}

#Important to put HIGHEST first
CHI_hyper_inflation_level_up = {
	# level 5 not relevant. Cannot go above.
	custom_effect_tooltip = CHI_inflation_up_tt
	if = {
		limit = { has_idea = CHI_hyper_inflation_4 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_4
			add_idea = CHI_hyper_inflation_5
		}
	}
	else_if = {
		limit = { has_idea = CHI_hyper_inflation_3 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_3
			add_idea = CHI_hyper_inflation_4
		}
	}
	else_if = {
		limit = { has_idea = CHI_hyper_inflation_2 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_2
			add_idea = CHI_hyper_inflation_3
		}
	}
	else_if = {
		limit = { has_idea = CHI_hyper_inflation_1 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_1
			add_idea = CHI_hyper_inflation_2
		}		
	}
	else_if = {
		limit = { NOT = { has_idea = CHI_hyper_inflation_1 } }
		add_ideas = CHI_hyper_inflation_1
	}
}

#Important to put LOWEST first
CHI_hyper_inflation_level_down = {
custom_effect_tooltip = CHI_inflation_down_tt
	if = {
		limit = { has_idea = CHI_hyper_inflation_1 }
		#Makes the tooltip clearer if player looks at the effect early in the game
		effect_tooltip = {
			swap_ideas = {
				remove_idea = CHI_hyper_inflation_1
				add_idea = CHI_hyper_inflation_none
			}
		}
		hidden_effect = { remove_ideas = CHI_hyper_inflation_1 }
	}
	if = {
		limit = { has_idea = CHI_hyper_inflation_2 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_2
			add_idea = CHI_hyper_inflation_1
		}
	}
	if = {
		limit = { has_idea = CHI_hyper_inflation_3 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_3
			add_idea = CHI_hyper_inflation_2
		}
	}
	if = {
		limit = { has_idea = CHI_hyper_inflation_4 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_4
			add_idea = CHI_hyper_inflation_3
		}
	}
	if = {
		limit = { has_idea = CHI_hyper_inflation_5 }
		swap_ideas = {
			remove_idea = CHI_hyper_inflation_5
			add_idea = CHI_hyper_inflation_4
		}
	}
}

# CHI_integrating_warlords #

CHI_warlord_integration_up = {
	if = {
		limit = {
			has_idea = CHI_warlord_integration_4
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_4
			add_idea = CHI_warlord_integration_5
		}
	}	
	else_if = {
		limit = {
			has_idea = CHI_warlord_integration_3
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_3
			add_idea = CHI_warlord_integration_4
		}
	}	
	else_if = {
		limit = {
			has_idea = CHI_warlord_integration_2
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_2
			add_idea = CHI_warlord_integration_3
		}
	}	
	else_if = {
		limit = {
			has_idea = CHI_warlord_integration_1
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_1
			add_idea = CHI_warlord_integration_2
		}
	}
	else = {
		add_ideas = CHI_warlord_integration_1
	}
}


CHI_warlord_integration_down = {
	if = {
		limit = {
			has_idea = CHI_warlord_integration_5
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_5
			add_idea = CHI_warlord_integration_4
		}
	}	
	else_if = {
		limit = {
			has_idea = CHI_warlord_integration_4
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_4
			add_idea = CHI_warlord_integration_3
		}
	}	
	else_if = {
		limit = {
			has_idea = CHI_warlord_integration_3
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_3
			add_idea = CHI_warlord_integration_2
		}
	}	
	else_if = {
		limit = {
			has_idea = CHI_warlord_integration_2
		}
		swap_ideas = {
			remove_idea = CHI_warlord_integration_2
			add_idea = CHI_warlord_integration_1
		}
	}
	else = {
		remove_ideas = CHI_warlord_integration_1
	}
}

#Could give more detailed info if needed
CHI_show_state_uprising_effect_after_infiltration_level_down = {
	custom_effect_tooltip = CHI_removed_infiltration
	if = {
		limit = {
			any_country = {
				is_potentially_communist_china = yes
				PREV = {
					has_state_flag = {
						flag = PRC_infiltration_@PREV
						value < 3
					}
				}
			}
		}
		custom_effect_tooltip = CHI_infiltration_not_detected
	}
	else_if = {
		limit = {
			any_country = {
				is_potentially_communist_china = yes
				PREV = {
					has_state_flag = {
						flag = PRC_infiltration_@PREV
						value > 2
					}
				}
			}
		}
		custom_effect_tooltip = PRC_infiltrate_uprising_header
		custom_effect_tooltip = PRC_infiltrate_uprising_effect_1
	}
}

#State scope
CHI_infiltration_flag_down_2 = {
	hidden_effect = {	
		every_country = {
			limit = { is_potentially_communist_china = yes }
			PREV = {
				modify_state_flag = {
					flag = PRC_infiltration_@PREV
					value = -2
				}
				if = {
					limit = {
						has_state_flag = {
							flag = PRC_infiltration_@PREV
							value < 1
						}
					}
					clr_state_flag = PRC_infiltration_@PREV
					clr_state_flag = discovered_infiltration
				}
			}
		}	
	}
}

CHI_unity_level_up = {
	if = {
		limit = {
			has_idea = CHI_chinese_unity_2
		}
		swap_ideas = {
			remove_idea = CHI_chinese_unity_2
			add_idea = CHI_chinese_unity_3
		}
	}
	if = {
		limit = {
			has_idea = CHI_chinese_unity_1
		}
		swap_ideas = {
			remove_idea = CHI_chinese_unity_1
			add_idea = CHI_chinese_unity_2
		}
	}
	if = {
		limit = {
			NOT = {
				OR = {
					has_idea = CHI_chinese_unity_1
					has_idea = CHI_chinese_unity_2
					has_idea = CHI_chinese_unity_3
				}
			}
		}
		add_ideas = CHI_chinese_unity_1
	}
}

CHI_unity_level_down = {
	if = {
		limit = {
			has_idea = CHI_chinese_unity_2
		}
		swap_ideas = {
			remove_idea = CHI_chinese_unity_2
			add_idea = CHI_chinese_unity_1
		}
	}
	else_if = {
		limit = {
			has_idea = CHI_chinese_unity_3
		}
		swap_ideas = {
			remove_idea = CHI_chinese_unity_3
			add_idea = CHI_chinese_unity_2
		}
	}
	else_if = {
		limit = {
			has_idea = CHI_chinese_unity_1
		}
		remove_ideas = CHI_chinese_unity_1
	}
}

CHI_set_ally_strat_on_current_leader = {
	if = {
		limit = {
			FROM = {
				tag = CHI
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "CHI"
            value = 200
        }
	}
	else_if = {
		limit = {
			FROM = {
				tag = SHX
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "SHX"
            value = 200
        }
	}
	else_if = {
		limit = {
			FROM = {
				tag = HCH
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "HCH"
            value = 200
        }
	}
	else_if = {
		limit = {
			FROM = {
				tag = SND
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "SND"
            value = 200
        }
	}
	else_if = {
		limit = {
			FROM = {
				tag = GXC
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "GXC"
            value = 200
        }
	}
	else_if = {
		limit = {
			FROM = {
				tag = YUN
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "YUN"
            value = 200
        }
	}
	else_if = {
		limit = {
			FROM = {
				tag = XSM
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "XSM"
            value = 200
        }
	}
	else_if = {
		limit = {
			FROM = {
				tag = SIK
			}
		}
		add_ai_strategy = {
            type = alliance
            id = "SIK"
            value = 200
        }
	}
}

CHI_negative_spirit_transfer = {
	if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_incompetent_officers }	
		}
		add_ideas = CHI_incompetent_officers
	}
	if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_nine_power_treaty }	
		}
		add_ideas = CHI_nine_power_treaty
	}
	if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_army_corruption_3 }	
		}
		add_ideas = CHI_army_corruption_3
	}
	else_if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_army_corruption_2 }	
		}
		add_ideas = CHI_army_corruption_2
	}
	else_if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_army_corruption_1 }	
		}
		add_ideas = CHI_army_corruption_1
	}
	if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_ineffective_bureaucracy }	
		}
		add_ideas = CHI_ineffective_bureaucracy
	}
	if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_hyper_inflation_none }	
		}
		add_ideas = CHI_hyper_inflation_none
	}
	else_if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_hyper_inflation_1 }	
		}
		add_ideas = CHI_hyper_inflation_1
	}
	else_if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_hyper_inflation_2 }	
		}
		add_ideas = CHI_hyper_inflation_2
	}
	else_if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_hyper_inflation_3 }	
		}
		add_ideas = CHI_hyper_inflation_3
	}
	else_if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_hyper_inflation_4 }	
		}
		add_ideas = CHI_hyper_inflation_4
	}
	else_if = {
		limit = {
			event_target:old_leader = { has_idea = CHI_hyper_inflation_5 }	
		}
		add_ideas = CHI_hyper_inflation_5
	}
}

CHI_no_longer_a_warlord_idea_removal = {
	if = {
		limit = {
			has_idea = CHI_warlord_state_idea
		}
		remove_ideas = {
			CHI_warlord_state_idea
		}
	}
	else_if = {
		limit = {
			has_idea = CHI_warlord_state_idea_2
		}
		remove_ideas = {
			CHI_warlord_state_idea_2
		}
	}
	else_if = {
		limit = {
			has_idea = CHI_warlord_state_idea_cav
		}
		remove_ideas = {
			CHI_warlord_state_idea_cav
		}
	}
	else_if = {
		limit = {
			has_idea = CHI_warlord_state_idea_mnt
		}
		remove_ideas = {
			CHI_warlord_state_idea_mnt
		}
	}

}



