#Remember to change the tooltips if the effects are changed
#State scope. Prev is target country.
POL_increase_danzig_control = {
	if = {
		limit = {
			has_dynamic_modifier = { modifier = international_city }
		}
		remove_dynamic_modifier = {
			modifier = international_city
		}
		add_dynamic_modifier = {
			modifier = international_city_2
		}
	}
	else_if = {
		limit = {
			has_dynamic_modifier = { modifier = international_city_2 }
		}
		remove_dynamic_modifier = {
			modifier = international_city_2
		}
		add_dynamic_modifier = {
			modifier = international_city_3
		}
	}
	else_if = {
		limit = {
			has_dynamic_modifier = { modifier = international_city_3 }
		}
		remove_dynamic_modifier = {
			modifier = international_city_3
		}
		add_dynamic_modifier = {
			modifier = international_city_4
		}
	}
	else_if = {
		limit = {
			has_dynamic_modifier = { modifier = international_city_4 }
		}
		add_compliance = 20
	}
}

POL_remove_danzig_effect = {
	remove_core_of = DNZ
	set_demilitarized_zone = no
	controller = { save_event_target_as = danzig_occupier }
	if = {
		limit = {
			has_resistance = yes
		}
		force_enable_resistance = { 
			clear = yes
			occupier = danzig_occupier
			occupied = DNZ
		}
		if = {
			limit = {
				NOT = { controller = { PREV = { is_core_of = PREV } } }
			}
			start_resistance = POL #swap resistance in Danzig to Poland if the occupier does not have a core there.
		}
	}
	if = {
		limit = {
			has_dynamic_modifier = { modifier =  international_city }
		}
		remove_dynamic_modifier = {
			modifier = international_city
		}
	}
	else_if = {
		limit = {
			has_dynamic_modifier = { modifier =  international_city_2 }
		}
		remove_dynamic_modifier = {
			modifier = international_city_2
		}
	}
	else_if = {
		limit = {
			has_dynamic_modifier = { modifier =  international_city_3 }
		}
		remove_dynamic_modifier = {
			modifier = international_city_3
		}
	}
	else_if = {
		limit = {
			has_dynamic_modifier = { modifier =  international_city_4 }
		}
		remove_dynamic_modifier = {
			modifier = international_city_4
		}
	}
}

POL_april_constitution_up = {
	if = {
		limit = {
			has_idea = POL_april_constitution_1
		}
		swap_ideas = {
			remove_idea = POL_april_constitution_1
			add_idea = POL_april_constitution_2
		}
	}
	else_if = {
		limit = {
			has_idea = POL_april_constitution_2
		}
		swap_ideas = {
			remove_idea = POL_april_constitution_2
			add_idea = POL_april_constitution_3
		}
	}
	else_if = {
		limit = {
			has_idea = POL_april_constitution_3
		}
		swap_ideas = {
			remove_idea = POL_april_constitution_3
			add_idea = POL_april_constitution_4
		}
	}
}

POL_april_constitution_remove = {
	if = {
		limit = {
			has_idea = POL_april_constitution_1
		}
		remove_ideas = POL_april_constitution_1
	}
	else_if = {
		limit = {
			has_idea = POL_april_constitution_2
		}
		remove_ideas = POL_april_constitution_2
	}
	else_if = {
		limit = {
			has_idea = POL_april_constitution_3
		}
		remove_ideas = POL_april_constitution_3
	}
	else_if = {
		limit = {
			has_idea = POL_april_constitution_4
		}
		remove_ideas = POL_april_constitution_4
	}
}

POL_sanation_left_opposition_up = {
	if = {
		limit = {
			has_idea = POL_sanation_left_opposition_1
		}
		swap_ideas = {
			remove_idea = POL_sanation_left_opposition_1
			add_idea = POL_sanation_left_opposition_2
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_2
		}
		swap_ideas = {
			remove_idea = POL_sanation_left_opposition_2
			add_idea = POL_sanation_left_opposition_3
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_3
		}
		swap_ideas = {
			remove_idea = POL_sanation_left_opposition_3
			add_idea = POL_sanation_left_opposition_4
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_4
		}
		remove_ideas = POL_sanation_left_opposition_4
		if = { #historically, Slawek committed suicide. On historical AI, the Left should be sidelined by the AI without any risk of civil war.
			limit = {
				is_historical_focus_on = yes
				is_ai = yes
			}
			country_event = {
				id = poland.19
			}
		}
		else = {
			random_list = {
				50 = {
					hidden_effect = {
						add_country_leader_role = {							
							character = "POL_walery_slawek"
							country_leader = {
								ideology=socialism
								traits = { left_sanationist_minister }
								expire="1965.1.1.1"
							}
							promote_leader = yes
						}
					}
					start_civil_war = {
						ideology = democratic
						size = 0.45
						keep_unit_leaders_trigger = {
							NOT = { has_trait = POL_sanation_left_leader }
						}
					}
					random_other_country = {
						limit = {
							original_tag = ROOT
							has_government = democratic
						}
						set_cosmetic_tag = POL_SANATION
						set_party_name = { 
							ideology = democratic 
							long_name = POL_POS_party_long
							name = POL_POS_party 
						}
					}
				}
				50 = {
					country_event = {
						id = poland.19
					}
				}
			}
		}
	}
}

POL_sanation_left_opposition_down = {
	if = {
		limit = {
			has_idea = POL_sanation_left_opposition_4
		}
		swap_ideas = {
			remove_idea = POL_sanation_left_opposition_4
			add_idea = POL_sanation_left_opposition_3
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_3
		}
		swap_ideas = {
			remove_idea = POL_sanation_left_opposition_3
			add_idea = POL_sanation_left_opposition_2
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_2
		}
		swap_ideas = {
			remove_idea = POL_sanation_left_opposition_2
			add_idea = POL_sanation_left_opposition_1
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_1
		}
		add_days_mission_timeout = {
			mission = POL_sanation_left_irritation
			days = 30
		}
	}
}

POL_sanation_left_opposition_remove = {
	if = {
		limit = {
			has_idea = POL_sanation_left_opposition_4
		}
		remove_ideas = POL_sanation_left_opposition_4
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_3
		}
		remove_ideas = POL_sanation_left_opposition_3
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_2
		}
		remove_ideas = POL_sanation_left_opposition_2
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_left_opposition_1
		}
		remove_ideas = POL_sanation_left_opposition_1
	}
}

POL_sanation_right_opposition_up = {
	if = {
		limit = {
			has_idea = POL_sanation_right_opposition_1
		}
		swap_ideas = {
			remove_idea = POL_sanation_right_opposition_1
			add_idea = POL_sanation_right_opposition_2
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_2
		}
		swap_ideas = {
			remove_idea = POL_sanation_right_opposition_2
			add_idea = POL_sanation_right_opposition_3
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_3
		}
		swap_ideas = {
			remove_idea = POL_sanation_right_opposition_3
			add_idea = POL_sanation_right_opposition_4
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_4
		}
		if = { #The sanation right will not start a civil war if it's AI and historical so we don't risk any unwanted Civil Wars there. Instead they'll simply keep the national spirit at it's highest level. The player and the Non-Historical AI will still get the CW 
			limit = {
				OR = {
					AND = {
						is_ai = yes 
						is_historical_focus_on = no
					}
					AND = {
						is_ai = no 
					}
				}
			}
			remove_ideas = POL_sanation_right_opposition_4 
			hidden_effect = {
				add_country_leader_role = {
					character = "POL_edward_rydzsmigly"
					country_leader = {
						ideology=falangism
						traits = { sanation_militarist_falangist }
						expire="1965.1.1.1"
					}
					promote_leader = yes
				}
			}
			start_civil_war = {
				ideology = fascism
				size = 0.5
				army_ratio = 0.25
				keep_unit_leaders_trigger = {
					NOT = { has_trait = POL_sanation_right_leader }
				}
			}
			random_other_country = {
				limit = {
					original_tag = ROOT
					has_government = fascism
				}
				set_party_name = { 
					ideology = fascism 
					long_name = POL_OZON_party_long
					name = POL_OZON_party
				}
				set_cosmetic_tag = POL_SANATION
			}
			hidden_effect = {
				promote_character = POL_boleslaw_piasecki #Make Piasecki ruler of the fascist party in regular Poland
			}
		}
	}
}

POL_sanation_right_opposition_down = {
	if = {
		limit = {
			has_idea = POL_sanation_right_opposition_4
		}
		swap_ideas = {
			remove_idea = POL_sanation_right_opposition_4
			add_idea = POL_sanation_right_opposition_3
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_3
		}
		swap_ideas = {
			remove_idea = POL_sanation_right_opposition_3
			add_idea = POL_sanation_right_opposition_2
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_2
		}
		swap_ideas = {
			remove_idea = POL_sanation_right_opposition_2
			add_idea = POL_sanation_right_opposition_1
		}
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_1
		}
		add_days_mission_timeout = {
			mission = POL_sanation_right_irritation
			days = 30
		}
	}
}

POL_sanation_right_opposition_remove = {
	if = {
		limit = {
			has_idea = POL_sanation_right_opposition_4
		}
		remove_ideas = POL_sanation_right_opposition_4
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_3
		}
		remove_ideas = POL_sanation_right_opposition_3
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_2
		}
		remove_ideas = POL_sanation_right_opposition_2
	}
	else_if = {
		limit = {
			has_idea = POL_sanation_right_opposition_1
		}
		remove_ideas = POL_sanation_right_opposition_1
	}
}

POL_monarchist_civil_war_effect = {
	set_variable = {
		var = civil_war_size_var
		value = 0
	}
	set_variable = {
		var = civil_war_size_var
		value = monarchist_support
	}
	divide_variable = {
		var = civil_war_size_var
		value = 100
	}
	if = {
		limit = {
			tag = LIT
		}
		if = {
			limit = {
				POL = {
					owns_state = 784
				}
			}
			transfer_state = 784
			start_civil_war = {
				ideology = neutrality
				size = civil_war_size_var
				keep_political_leader = yes
				states = { 784 }
				keep_unit_leaders_trigger = {
					NOT = { has_unit_leader_flag = POL_monarchy_sympathies_flag }
				}
			}
		}
		else = {
			start_civil_war = {
				ideology = neutrality
				size = civil_war_size_var
				keep_political_leader = yes
				keep_unit_leaders_trigger = {
					NOT = { has_unit_leader_flag = POL_monarchy_sympathies_flag }
				}
			}
		}

		random_other_country = {
			limit = {
				has_civil_war = yes
				original_tag = LIT
			}
			set_cosmetic_tag = LIT_KINGDOM
			set_country_flag = POL_lithuanian_personal_union_flag
		}
		if = {
			limit = {
				any_other_country = {
					original_tag = POL
					POL_is_valid_to_boost_monarchy = yes 
				}
			}
			every_other_country = {
				limit = {
					original_tag = POL
				}
				set_country_flag = attempted_royal_takeover_in_LIT
			}
		}
	}
	if = {
		limit = {
			tag = ROM
		}
		ROM = {
			set_country_flag = POL_non_michael_romania
		}
		start_civil_war = {
			ideology = neutrality
			size = civil_war_size_var
			keep_political_leader = yes
			keep_unit_leaders_trigger = {
				NOT = { has_unit_leader_flag = POL_monarchy_sympathies_flag }
			}
		}
		random_other_country = {
			limit = {
				has_civil_war = yes
				original_tag = ROM
			}
			set_cosmetic_tag = ROM_polish_loyalists
			set_country_flag = POL_romanian_personal_union_flag
		}
		if = {
			limit = {
				any_other_country = {
						original_tag = POL
						POL_is_valid_to_boost_monarchy = yes 
				}
			}
			every_other_country = {
				limit = {
					original_tag = POL
				}
				set_country_flag = attempted_royal_takeover_in_ROM
			}
		}
	}
	if = {
		limit = {
			tag = CZE
		}
		start_civil_war = {
			ideology = neutrality
			size = civil_war_size_var
			keep_unit_leaders_trigger = {
				NOT = { has_unit_leader_flag = POL_monarchy_sympathies_flag }
			}
		}
		random_other_country = {
			limit = {
				has_civil_war = yes
				original_tag = CZE
			}
			set_country_flag = POL_czech_personal_union_flag
		}
		if = {
			limit = {
				any_other_country = {
						original_tag = POL
						POL_is_valid_to_boost_monarchy = yes 
				}
			}
			every_other_country = {
				limit = {
					original_tag = POL
				}
				set_country_flag = attempted_royal_takeover_in_CZE
			}
		}
	}
	if = {
		limit = {
			tag = POL
		}
		start_civil_war = {
			ideology = neutrality
			size = civil_war_size_var
			keep_political_leader = yes
			keep_unit_leaders_trigger = {
				NOT = { has_unit_leader_flag = POL_monarchy_sympathies_flag }
			}
		}
		random_other_country = {
			limit = {
				has_civil_war = yes
				original_tag = POL
			}
			set_cosmetic_tag = POL_KINGDOM
			set_country_flag = LIT_poland_personal_union_flag
		}
		if = {
			limit = {
				any_other_country = {
						original_tag = LIT
						POL_is_valid_to_boost_monarchy = yes 
				}
			}
			every_other_country = {
				limit = {
					original_tag = LIT
				}
				set_country_flag = attempted_royal_takeover_in_POL
			}
		}
	}

}

POL_peasant_division_effect = {
	custom_effect_tooltip = POL_peasant_division_tt
	hidden_effect = {
		division_template = { 
			name = "Peasant Division"
			division_names_group = POL_INF_01
			is_locked = no
			regiments = { 
				infantry = { x = 0 y = 0 }
				infantry = { x = 1 y = 0 }
				infantry = { x = 2 y = 0 }
				infantry = { x = 3 y = 0 }

				infantry = { x = 0 y = 1 }
				infantry = { x = 1 y = 1 }
			}
			support = {
				
			}
		}
		random_owned_controlled_state = {
			create_unit = { 
				division = "name = \"1. Peasant Division\" division_template = \"Peasant Division\" start_experience_factor = 0.5" 
				owner = ROOT
			}
			create_unit = { 
				division = "name = \"2. Peasant Division\" division_template = \"Peasant Division\" start_experience_factor = 0.5" 
				owner = ROOT
			}
			create_unit = { 
				division = "name = \"3. Peasant Division\" division_template = \"Peasant Division\" start_experience_factor = 0.5" 
				owner = ROOT
			}
			create_unit = { 
				division = "name = \"4. Peasant Division\" division_template = \"Peasant Division\" start_experience_factor = 0.5" 
				owner = ROOT
			}
		}
	}
}

POL_become_german_puppet_effect = {
	GER = {
		if = {
			limit = {
				POL = {
					controls_state = 85
					owns_state = 85
				}
			}
			transfer_state = 85
		}
		if = {
			limit = {
				POL = {
					controls_state = 807
					owns_state = 807
				}
			}
			transfer_state = 807
		}
		if = {
			limit = {
				POL = {
					controls_state = 86
					owns_state = 86
				}
			}
			transfer_state = 86
		}
		if = {
			limit = {
				POL = {
					controls_state = 762
					owns_state = 762
				}
			}
			transfer_state = 762
		}
		85 = { add_core_of = GER } #Danzig
		86 = { add_core_of = GER } #Poznan
		807 = { add_core_of = GER } #Gdynia
		762 = { add_core_of = GER } #Upper Silesia
		if = {
			limit = {
				has_dlc = "Death or Dishonor"
			}
			set_autonomy = {
				target = POL
				autonomy_state = autonomy_reichsprotectorate
			}
		}
		else = {
			set_autonomy = {
				target = POL
				autonomy_state = autonomy_integrated_puppet
			}
		}
		add_to_faction = POL
	}
	hidden_effect = {
		GER = { #Reverse the AI strategy set at game start
			add_ai_strategy = {
			   type = alliance
			   id = POL
			   value = 2000
			}
		}
		POL = {
			add_ai_strategy = {
			   type = alliance
			   id = GER
			   value = 2000
			}
		}
	}
}

POL_divide_lithuania_effect = {
	188 = { add_core_of = GER }
	LIT = {
		every_owned_state = {
			limit = {
				OR = {
					is_core_of = GER
					is_claimed_by = GER
					state = 188
				}
			}
			GER = {
				transfer_state = PREV
			}
		}
	}
	POL = {
		annex_country = {
			target = LIT
			transfer_troops = no
		}
	}
}

POL_lithuania_wargoal_claims_effect = {
	188 = { add_core_of = GER }
	189 = { add_claim_by = POL }
	815 = { add_claim_by = POL }
	11 = { add_claim_by = POL }
	814 = { add_claim_by = POL }
	GER = {
		create_wargoal = {
			type = take_core_state
			generator = { 188 }
			target = LIT
		}
	}
}

POL_set_attempted_royal_takeover_flag = {
	hidden_effect = {
		if = {
			limit = { original_tag = POL }
			FROM = {
				set_country_flag = attempted_royal_takeover_in_POL
			}
		}
		else_if = {
			limit = { original_tag = LIT }
			FROM = {
				set_country_flag = attempted_royal_takeover_in_LIT
			}
		}
		else_if = {
			limit = { original_tag = ROM }
			FROM = {
				set_country_flag = attempted_royal_takeover_in_ROM
			}
		}
		else_if = {
			limit = { original_tag = CZE }
			FROM = {
				set_country_flag = attempted_royal_takeover_in_CZE
			}
		}
	}
}

POL_basic_form_commonwealth = {
	# Lithuania
	custom_effect_tooltip = form_country_lithuania_coring_states_tt
	hidden_effect = {
		11 = { add_core_of = ROOT }
		189 = { add_core_of = ROOT }
		188 = { add_core_of = ROOT }
		784 = { add_core_of = ROOT }
		814 = { add_core_of = ROOT }
		815 = { add_core_of = ROOT }
	}
	# Poland
	custom_effect_tooltip = form_country_poland_coring_states_tt
	hidden_effect = {
		66 = { add_core_of = ROOT }
		67 = { add_core_of = ROOT }
		85 = { add_core_of = ROOT }
		86 = { add_core_of = ROOT }
		87 = { add_core_of = ROOT }
		88 = { add_core_of = ROOT }
		90 = { add_core_of = ROOT }
		98 = { add_core_of = ROOT }
		10 = { add_core_of = ROOT }
		97 = { add_core_of = ROOT }
		92 = { add_core_of = ROOT }
		91 = { add_core_of = ROOT }
		89 = { add_core_of = ROOT }
		93 = { add_core_of = ROOT }
		1052 = { add_core_of = ROOT }
		94 = { add_core_of = ROOT }
		95 = { add_core_of = ROOT }
		96 = { add_core_of = ROOT }
		784 = { add_core_of = ROOT }
		5 = { add_core_of = ROOT }
		763 = { add_core_of = ROOT }
		207 = { add_core_of = ROOT }
		242 = { add_core_of = ROOT }
		206 = { add_core_of = ROOT }
		241 = { add_core_of = ROOT }
		243 = { add_core_of = ROOT }
		204 = { add_core_of = ROOT }
		194 = { add_core_of = ROOT }
		201 = { add_core_of = ROOT }
		199 = { add_core_of = ROOT }
		198 = { add_core_of = ROOT }
		202 = { add_core_of = ROOT }
		203 = { add_core_of = ROOT }
		193 = { add_core_of = ROOT }
		259 = { add_core_of = ROOT }
		762 = { add_core_of = ROOT }
		807 = { add_core_of = ROOT }
	}
	custom_effect_tooltip = form_country_latvia_coring_states_tt
	hidden_effect = {
		12 = { add_core_of = ROOT }
		190 = { add_core_of = ROOT }
		808 = { add_core_of = ROOT }
		809 = { add_core_of = ROOT }
		810 = { add_core_of = ROOT }
	}

	hidden_effect = {
		news_event = { id = wtt_news.57 hours = 6 }
		set_global_flag = form_commonwealth_flag
	}
}
