###############################################
# XENOMORPH DEFICIT SITUATIONS — 3_61 D2 REWRITE
# Full 4-stage vanilla-parity form (25/50/75/100). Penalties re-laddered onto
# valid generated category-resource modifiers [VETO: all values].
# Starter: monthly on_action (vanilla starter is engine-side for vanilla
# resources only). Default events: xeno_deficit.1/.2.
# Difficulty-scaling multipliers OMITTED — no locally attested difficulty
# trigger; see TODO.
###############################################

@xeno_bailout_base = 500
@xeno_bailout_abort = 150

situation_xenomorph_empty_clutch_reserves = {
	picture = GFX_evt_deficit
	category = negative
	fail_icon = GFX_situation_outcome_meh
	fail_icon_frame = GFX_situation_outcome_frame_green
	complete_icon = GFX_situation_outcome_bankrupcy
	complete_icon_frame = GFX_situation_outcome_frame_red

	on_start = {
		set_situation_flag = deficit_situation
		owner = {
			set_country_flag = xeno_sit_eggs_active
			country_event = { id = advisor.20 days = 10 random = 20 }
		}
	}

	initial_progress = 15

	stages = {
		xenomorph_empty_clutch_reserves_1 = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_red
			end = 25
			modifier = {
				logistic_growth_mult = -0.05
				planet_pop_assembly_mult = -0.05
				planet_xenomorph_royal_egg_layers_xenomorph_eggs_produces_mult = -0.05
				planet_xenomorph_brood_egg_layers_xenomorph_eggs_produces_mult = -0.05
				planet_xenomorph_brood_carriers_xenomorph_eggs_produces_mult = -0.05
				planet_stability_add = -2
			}
		}
		xenomorph_empty_clutch_reserves_2 = {
			icon = GFX_situation_stage_2
			icon_background = GFX_situation_stage_frame_red
			end = 50
			modifier = {
				logistic_growth_mult = -0.10
				planet_pop_assembly_mult = -0.10
				planet_xenomorph_royal_egg_layers_xenomorph_eggs_produces_mult = -0.10
				planet_xenomorph_brood_egg_layers_xenomorph_eggs_produces_mult = -0.10
				planet_xenomorph_brood_carriers_xenomorph_eggs_produces_mult = -0.10
				planet_stability_add = -4
			}
		}
		xenomorph_empty_clutch_reserves_3 = {
			icon = GFX_situation_stage_3
			icon_background = GFX_situation_stage_frame_red
			end = 75
			modifier = {
				logistic_growth_mult = -0.15
				planet_pop_assembly_mult = -0.20
				planet_xenomorph_royal_egg_layers_xenomorph_eggs_produces_mult = -0.20
				planet_xenomorph_brood_egg_layers_xenomorph_eggs_produces_mult = -0.20
				planet_xenomorph_brood_carriers_xenomorph_eggs_produces_mult = -0.20
				planet_xenomorph_host_breeders_xenomorph_offspring_produces_mult = -0.05
				planet_xenomorph_brood_carriers_xenomorph_offspring_produces_mult = -0.05
				planet_stability_add = -7
			}
		}
		xenomorph_empty_clutch_reserves_4 = {
			icon = GFX_situation_stage_4
			icon_background = GFX_situation_stage_frame_red
			end = 100
			modifier = {
				logistic_growth_mult = -0.25
				planet_pop_assembly_mult = -0.35
				planet_xenomorph_royal_egg_layers_xenomorph_eggs_produces_mult = -0.30
				planet_xenomorph_brood_egg_layers_xenomorph_eggs_produces_mult = -0.30
				planet_xenomorph_brood_carriers_xenomorph_eggs_produces_mult = -0.30
				planet_xenomorph_host_breeders_xenomorph_offspring_produces_mult = -0.10
				planet_xenomorph_brood_carriers_xenomorph_offspring_produces_mult = -0.10
				planet_stability_add = -10
				planet_amenities_no_happiness_add = -5
			}
		}
	}

	on_progress_complete = {
		country_defaulted_in_situation_tooltip = yes
		owner = {
			remove_country_flag = xeno_sit_eggs_active
			country_event = { id = xeno_deficit.1 }
		}
		destroy_situation = this
	}

	on_fail = {
		custom_tooltip = deficit_situation_finish_tooltip
		hidden_effect = {
			owner = { remove_country_flag = xeno_sit_eggs_active }
			destroy_situation = this
		}
	}

	on_abort = {
		# 3_62: flag cleanup + partial bailout [VETO value]
		owner = {
			remove_country_flag = xeno_sit_eggs_active
			add_resource = { xenomorph_eggs = @xeno_bailout_abort }
		}
	}

	monthly_progress = {
		base = 0
		modifier = {
			add = value:deficit_situation_progress_value|RESOURCE|xenomorph_eggs|
			desc = string_xenomorph_eggs_expenditures_greater_than_income
			owner = { has_actual_deficit = { RESOURCE = xenomorph_eggs } }
		}
		modifier = {
			subtract = 5
			desc = string_xenomorph_eggs_not_in_deficit
			owner = {
				resource_income_compare = {
					resource = xenomorph_eggs
					value >= 0
				}
			}
		}
		modifier = {
			subtract = 1
			desc = string_xenomorph_eggs_reserves
			owner = { has_negative_income_with_stockpile = { RESOURCE = xenomorph_eggs } }
		}
	}

	approach = {
		name = deficit_approach_do_nothing
		icon = GFX_situation_approach_this_is_fine
		icon_background = GFX_situation_approach_bg_yellow
		default = yes
		on_select = { custom_tooltip = deficit_approach_do_nothing_tooltip }
		ai_weight = { base = 1 }
	}
}

situation_xenomorph_immature_brood_collapse = {
	picture = GFX_evt_deficit
	category = negative
	fail_icon = GFX_situation_outcome_meh
	fail_icon_frame = GFX_situation_outcome_frame_green
	complete_icon = GFX_situation_outcome_bankrupcy
	complete_icon_frame = GFX_situation_outcome_frame_red

	on_start = {
		set_situation_flag = deficit_situation
		owner = {
			set_country_flag = xeno_sit_offspring_active
			country_event = { id = advisor.20 days = 10 random = 20 }
		}
	}

	initial_progress = 15

	stages = {
		xenomorph_immature_brood_collapse_1 = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_red
			end = 25
			modifier = {
				country_society_tech_research_speed = -0.05
				planet_xenomorph_host_breeders_xenomorph_offspring_produces_mult = -0.05
				planet_xenomorph_brood_carriers_xenomorph_offspring_produces_mult = -0.05
				planet_stability_add = -1
			}
		}
		xenomorph_immature_brood_collapse_2 = {
			icon = GFX_situation_stage_2
			icon_background = GFX_situation_stage_frame_red
			end = 50
			modifier = {
				country_society_tech_research_speed = -0.10
				planet_xenomorph_host_breeders_xenomorph_offspring_produces_mult = -0.10
				planet_xenomorph_brood_carriers_xenomorph_offspring_produces_mult = -0.10
				army_damage_mult = -0.05
				planet_stability_add = -3
			}
		}
		xenomorph_immature_brood_collapse_3 = {
			icon = GFX_situation_stage_3
			icon_background = GFX_situation_stage_frame_red
			end = 75
			modifier = {
				country_society_tech_research_speed = -0.15
				planet_xenomorph_host_breeders_xenomorph_offspring_produces_mult = -0.20
				planet_xenomorph_brood_carriers_xenomorph_offspring_produces_mult = -0.20
				army_damage_mult = -0.10
				planet_stability_add = -5
			}
		}
		xenomorph_immature_brood_collapse_4 = {
			icon = GFX_situation_stage_4
			icon_background = GFX_situation_stage_frame_red
			end = 100
			modifier = {
				country_society_tech_research_speed = -0.20
				planet_xenomorph_host_breeders_xenomorph_offspring_produces_mult = -0.30
				planet_xenomorph_brood_carriers_xenomorph_offspring_produces_mult = -0.30
				army_damage_mult = -0.15
				planet_stability_add = -8
			}
		}
	}

	on_progress_complete = {
		country_defaulted_in_situation_tooltip = yes
		owner = {
			remove_country_flag = xeno_sit_offspring_active
			country_event = { id = xeno_deficit.2 }
		}
		destroy_situation = this
	}

	on_fail = {
		custom_tooltip = deficit_situation_finish_tooltip
		hidden_effect = {
			owner = { remove_country_flag = xeno_sit_offspring_active }
			destroy_situation = this
		}
	}

	on_abort = {
		# 3_62: flag cleanup + partial bailout [VETO value]
		owner = {
			remove_country_flag = xeno_sit_offspring_active
			add_resource = { xenomorph_offspring = @xeno_bailout_abort }
		}
	}

	monthly_progress = {
		base = 0
		modifier = {
			add = value:deficit_situation_progress_value|RESOURCE|xenomorph_offspring|
			desc = string_xenomorph_offspring_expenditures_greater_than_income
			owner = { has_actual_deficit = { RESOURCE = xenomorph_offspring } }
		}
		modifier = {
			subtract = 5
			desc = string_xenomorph_offspring_not_in_deficit
			owner = {
				resource_income_compare = {
					resource = xenomorph_offspring
					value >= 0
				}
			}
		}
		modifier = {
			subtract = 1
			desc = string_xenomorph_offspring_reserves
			owner = { has_negative_income_with_stockpile = { RESOURCE = xenomorph_offspring } }
		}
	}

	approach = {
		name = deficit_approach_do_nothing
		icon = GFX_situation_approach_this_is_fine
		icon_background = GFX_situation_approach_bg_yellow
		default = yes
		on_select = { custom_tooltip = deficit_approach_do_nothing_tooltip }
		ai_weight = { base = 1 }
	}
}
