##############################
# Grand Archive - Situations #
##############################

# Voidworm country situation responsible for handling pulses
voidworm_country_situation = {
	picture = GFX_evt_situation_voidworm_plague
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_unknown
	category = neutral
	initial_progress = 0

	on_progress_complete = {
	}

	stages = {
		stage_1 = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_green
			end = 1
		}
	}

	approach = {
		name = approach_voidworm_plague_do_nothing
		icon = GFX_situation_approach_shrug
		icon_background = GFX_situation_approach_bg_yellow
		on_select = {
			custom_tooltip = deficit_approach_do_nothing_tooltip
		}
		default = yes
	}

	monthly_progress = {
		base = 0
	}

	on_monthly = {
		events = {
			grand_archive.2055
		}
	}
}

# Voidworms Galactic Plague
situation_voidworm_plague = {
	picture = GFX_evt_situation_voidworm_plague
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_unknown
	category = neutral
	situation_log_category = crises
	initial_progress = 0
	on_start = {
		if = {
			limit = {
				owner = {
					has_technology = tech_voidworm_immunity
				}
			}
			add_situation_progress = @vaccine_situation_advancement
		}
	}

	on_progress_complete = {
		custom_tooltip = finisher_effects_voidworm_plague
		hidden_effect = {
			destroy_situation = this
			owner = {
				set_country_flag = voidworms_bombardment_disabled
				country_event = { id = grand_archive.2500 }
				# Cleanup
				if = {
					limit = { has_modifier = public_distrust_modifier }
					remove_modifier = public_distrust_modifier
				}
				if = {
					limit = { has_modifier = test_subject_unwilling_modifier }
					remove_modifier = test_subject_unwilling_modifier
				}
				else_if = {
					limit = { has_modifier = test_subject_volunteer_modifier }
					remove_modifier = test_subject_volunteer_modifier
				}
				else_if = {
					limit = { has_modifier = test_subject_gestalt_modifier }
					remove_modifier = test_subject_gestalt_modifier
				}
				if = {
					limit = { has_special_project = VOIDWORM_GLANDS_PROJECT }
					abort_special_project =  { type = VOIDWORM_GLANDS_PROJECT }
				}
				else_if = {
					limit = { has_special_project = VOIDWORM_TITAN_DEBRIS_PROJECT }
					abort_special_project =  { type = VOIDWORM_TITAN_DEBRIS_PROJECT }
				}
			}

			if = {
				limit = {
					count_playable_country = {
						limit = { has_country_flag = voidworms_bombardment_disabled }
						count = all
					}
				}
				end_voidworms_crisis = yes
			}
		}
	}

	stages = {
		stage_1 = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_green
			end = 200
			custom_tooltip = stage_unknown_effects
		}
		stage_2 = {
			icon = GFX_situation_stage_2
			icon_background = GFX_situation_stage_frame_green
			end = 400
			on_first_enter = {
				inline_script = {
					script = grand_archive/voidworm_crisis_random_events
				}
			}
			custom_tooltip = stage_unknown_effects
		}
		stage_3 = {
			icon = GFX_situation_stage_3
			icon_background = GFX_situation_stage_frame_green
			end = 600
			on_first_enter = {
				inline_script = {
					script = grand_archive/voidworm_crisis_random_events
				}
			}
			custom_tooltip = stage_unknown_effects
		}
	}

	approach = {
		name = approach_voidworm_plague_do_nothing
		icon = GFX_situation_approach_shrug
		icon_background = GFX_situation_approach_bg_yellow
		allow = {
			custom_tooltip = {
				fail_text = too_early_to_change_approach
				OR = {
					NOT = { has_situation_flag = path_locked }
					current_situation_approach = approach_voidworm_plague_do_nothing
				}
			}
		}
		on_select = {
			custom_tooltip = approach_voidworm_plague_do_nothing_tt
			owner = {
				remove_country_flag = voidworms_spawn_disabled
			}
			hidden_effect = {
				situation_event = { id = grand_archive.2090 }
			}
			custom_tooltip = change_approach_will_temporarily_lock
		}
		default = yes
		ai_weight = {
			base = 0
		}
	}

	approach = {
		name = approach_voidworm_plague_support_fleets
		icon = GFX_situation_approach_fleet
		icon_background = GFX_situation_approach_bg_green
		allow = {
			custom_tooltip = {
				fail_text = too_early_to_change_approach
				OR = {
					NOT = { has_situation_flag = path_locked }
					current_situation_approach = approach_voidworm_plague_support_fleets
				}
			}
		}
		on_select = {
			custom_tooltip = approach_voidworm_plague_support_fleets_tt
			owner = {
				remove_country_flag = voidworms_spawn_disabled
			}
			hidden_effect = {
				situation_event = { id = grand_archive.2090 }
			}
			custom_tooltip = change_approach_will_temporarily_lock
		}
		custom_tooltip_with_modifiers = approach_voidworm_plague_support_fleets_tt
		modifier = {
			planet_jobs_alloys_produces_mult = 0.15
			damage_vs_country_type_voidworms_crisis_mult = 0.15
			country_consumer_goods_produces_mult = -0.1
			pop_happiness = -0.05
		}
		ai_weight = {
			base = 1
			modifier = {
				factor = 10
				owner = { is_militarist = yes }
			}
		}
	}

	approach = {
		name = approach_voidworm_plague_purge_infected_pops
		icon = GFX_situation_approach_this_is_fine
		icon_background = GFX_situation_approach_bg_green
		allow = {
			custom_tooltip = {
				fail_text = too_early_to_change_approach
				OR = {
					NOT = { has_situation_flag = path_locked }
					current_situation_approach = approach_voidworm_plague_purge_infected_pops
				}
			}
		}
		on_select = {
			custom_tooltip = approach_voidworm_plague_purge_infected_pops_tt
			owner = {
				set_country_flag = voidworms_spawn_disabled
			}
			hidden_effect = {
				situation_event = { id = grand_archive.2090 }
			}
			custom_tooltip = change_approach_will_temporarily_lock
		}
		custom_tooltip_with_modifiers = approach_voidworm_plague_purge_infected_pops_tt
		modifier = {
			voidworms_planet_orbital_bombardment_damage = -0.3
			pop_happiness = -0.10
		}
		ai_weight = {
			base = 1
			modifier = {
				factor = 10
				owner = { is_homicidal = yes }
			}
		}
	}

	approach = {
		name = approach_voidworm_plague_search_for_cure
		icon = GFX_situation_approach_research
		icon_background = GFX_situation_approach_bg_green
		allow = {
			custom_tooltip = {
				fail_text = too_early_to_change_approach
				OR = {
					NOT = { has_situation_flag = path_locked }
					current_situation_approach = approach_voidworm_plague_search_for_cure
				}
			}
		}
		on_select = {
			custom_tooltip = approach_voidworm_plague_search_for_cure_tt
			owner = {
				remove_country_flag = voidworms_spawn_disabled
			}
			hidden_effect = {
				situation_event = { id = grand_archive.2090 }
			}
			custom_tooltip = change_approach_will_temporarily_lock
		}
		modifier = {
			country_unity_produces_mult = 0.25
			country_society_research_produces_mult = -0.50
		}
		ai_weight = {
			base = 1
			modifier = {
				factor = 10
				owner = { is_pacifist = yes }
			}
		}
	}

	monthly_progress = {
		base = 0.5
		modifier = {
			add = 0.5
			desc = approach_voidworm_plague_support_fleets
			current_situation_approach = approach_voidworm_plague_support_fleets
		}
		modifier = {
			add = 0.7
			desc = approach_voidworm_plague_purge_infected_pops
			current_situation_approach = approach_voidworm_plague_purge_infected_pops
		}
		modifier = {
			add = 1.0
			desc = approach_voidworm_plague_search_for_cure
			current_situation_approach = approach_voidworm_plague_search_for_cure
		}
		modifier = {
			desc = BLANK_STRING
			add = 3.0
			owner = { is_ai = yes }
			count_playable_country = {
				limit = {
					owner = { is_ai = no }
					any_situation = { is_situation_type = situation_voidworm_plague }
				}
				count = 0
			}
		}
	}
}

# Treasure Hunters Sabotage
situation_sabotage = {
	picture = GFX_evt_treasure_trove_pirate_fleet
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_unknown
	situation_log_category = empire_concerns
	category = positive
	initial_progress = 25

	on_start = {
		create_black_needle_country = yes
		owner = {
			if = {
				limit = { is_nomadic = yes }
				if = {
					limit = {
						any_owned_nonprimary_starbase = {
							is_waystation_starbase = yes
						}
					}
					random_owned_nonprimary_starbase = {
						limit = { is_waystation_starbase = yes }
						weights = {
							base = 1
							modifier = {
								add = 2
								has_starbase_size = starbase_waystation_2
							}
							modifier = {
								add = 4
								has_starbase_size = starbase_waystation_3
							}
							modifier = {
								add = 5
								solar_system = {
									any_fleet_in_system = { is_arkship_fleet = yes }
								}
							}
						}
						create_sabotage_fleet = yes
						solar_system = {
							set_star_flag = available_for_sabotage
							set_star_flag = sabotage_pirate_fleet_spawn_check
						}
					}
				}
				else = {
					random_owned_fleet = {
						limit = {
							is_arkship_fleet = yes
							exists = solar_system
						}
						random_owned_ship = {
							weights = {
								base = 1
								modifier = {
									add = 20
									colony? = { is_capital = yes }
								}
								modifier = {
									add = 5
									colony? = { pop_amount > 500 }
								}
							}
							create_sabotage_fleet = yes
							solar_system = {
								set_star_flag = available_for_sabotage
								set_star_flag = sabotage_pirate_fleet_spawn_check
							}
						}
					}
				}
			}
			else = {
				capital_scope = {
					create_sabotage_fleet = yes
					solar_system = {
						set_star_flag = available_for_sabotage
						set_star_flag = sabotage_pirate_fleet_spawn_check
					}
				}
			}
		}
	}
	on_progress_complete = {
		custom_tooltip = finisher_effects_sabotage
		owner = {
			country_event = { id = grand_archive.8550 }
		}
		hidden_effect = { destroy_situation = this }
	}
	on_fail = {
		custom_tooltip = finisher_effects_sabotage_fail
		owner = {
			country_event = { id = grand_archive.8545 }
		}
		hidden_effect = { destroy_situation = this }
	}
	on_abort = {
		hidden_effect = { destroy_situation = this }
	}

	modifier = {
		planet_jobs_produces_mult = -0.25
		starbase_constructions_produces_mult = -0.25
		stations_produces_mult = -0.25
		logistic_growth_mult = -0.25
		planet_pop_assembly_mult = -0.25
		pop_happiness = -0.25
	}

	stages = {
		stage_1 = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_green
			end = 100
			custom_tooltip = stage_unknown_effects
		}
		stage_2 = {
			icon = GFX_situation_stage_2
			icon_background = GFX_situation_stage_frame_green
			end = 150
			on_first_enter = {
				owner = { country_event = { id = grand_archive.8520 } }
			}
			custom_tooltip = stage_unknown_effects
		}
	}

	approach = {
		name = approach_sabotage_do_nothing
		icon = GFX_situation_approach_this_is_fine
		icon_background = GFX_situation_approach_bg_red
		on_select = {
			custom_tooltip = approach_sabotage_do_nothing_tt
		}
		default = yes
	}

	approach = {
		name = approach_sabotage_purge
		icon = GFX_situation_approach_pop
		icon_background = GFX_situation_approach_bg_green
		on_select = {
			custom_tooltip = approach_sabotage_purge_tt
		}
		modifier = {
			country_energy_produces_mult = -0.25
			pop_happiness = -0.25
			country_unity_produces_mult = -0.25
		}
	}

	approach = {
		name = approach_sabotage_mitigate
		icon = GFX_situation_approach_balance_sheet
		icon_background = GFX_situation_approach_bg_green
		on_select = {
			custom_tooltip = approach_sabotage_mitigate_tt
		}
		modifier = {
			country_minerals_produces_mult = -0.1
			country_alloys_produces_mult = -0.1
			country_engineering_research_produces_mult = -0.1
		}
	}

	monthly_progress = {
		base = -0.5
		modifier = {
			add = 4.5
			desc = approach_sabotage_purge
			current_situation_approach = approach_sabotage_purge
		}
		modifier = {
			add = 2.5
			desc = approach_sabotage_mitigate
			current_situation_approach = approach_sabotage_mitigate
		}
	}

	on_monthly = {
		events = {
			grand_archive.8509
			grand_archive.8510
			grand_archive.8620
			grand_archive.8625
		}
	}
}

# Primal Calling Frenzied Voidworm
situation_frenzied_voidworms = {
	picture = GFX_evt_frenzied_voidworms
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_unknown
	situation_log_category = empire_concerns
	category = neutral
	initial_progress = 0

	on_start = {
		set_variable = {
			which = months_since_last_wave
			value = 0
		}
		set_variable = {
			which = frenzied_voidworms_hostility
			value = 0
		}
		set_variable = {
			which = frenzied_voidworms_strength
			value = 1
		}
	}

	on_progress_complete = {
		custom_tooltip = finisher_effects_frenzied_voidworms
		hidden_effect = {
			owner = {
				country_event = {
					id = grand_archive.1190
				}
			}
			if = {
				limit = {
					check_variable = {
						which = frenzied_voidworms_hostility
						value > @frenzied_hostility_pacified_threshold
					}
				}
				if = {
					limit = {
						check_variable = {
							which = frenzied_voidworms_hostility
							value >= @frenzied_hostility_hostile_threshold
						}
					}
					event_target:frenzied_voidworms_country = {
						set_country_flag = enraged_voidworms
					}
				}
				owner = {
					country_event = {
						id = grand_archive.1200
					}
				}
			}
			else = {
				owner = {
					country_event = {
						id = grand_archive.1220
					}
				}
			}
			destroy_situation = this
		}
	}

	on_abort = {
		owner = {
			country_event = {
				id = grand_archive.1190
			}
		}
	}

	stages = {
		stage_1 = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_green
			end = 300
			custom_tooltip = stage_unknown_effects
		}
	}

	approach = {
		name = approach_frenzied_voidworms_do_nothing
		icon = GFX_situation_approach_shrug
		icon_background = GFX_situation_approach_bg_yellow
		on_select = {
			custom_tooltip = approach_frenzied_voidworms_do_nothing_tt
			hidden_effect = {
				owner = {
					country_event = {
						id = grand_archive.1120
					}
				}
			}
		}
		default = yes
	}

	approach = {
		name = approach_frenzied_voidworms_hide_presence
		icon = GFX_situation_approach_suspicious
		icon_background = GFX_situation_approach_bg_yellow
		on_select = {
			custom_tooltip = approach_frenzied_voidworms_hide_presence_tt
			hidden_effect = {
				owner = {
					country_event = {
						id = grand_archive.1115
					}
				}
			}
		}
	}

	approach = {
		name = approach_frenzied_voidworms_stir_nests
		icon = GFX_situation_approach_fleet
		icon_background = GFX_situation_approach_bg_green
		on_select = {
			custom_tooltip = approach_frenzied_voidworms_stir_nests_tt
			hidden_effect = {
				owner = {
					country_event = {
						id = grand_archive.1120
					}
				}
			}
		}

		modifier = {
			country_base_energy_produces_add = -100
			country_society_research_produces_mult = 0.3
		}
	}

	approach = {
		name = approach_frenzied_voidworms_feed_nests
		icon = GFX_situation_approach_gift
		icon_background = GFX_situation_approach_bg_green
		on_select = {
			custom_tooltip = approach_frenzied_voidworms_feed_nests_tt
			hidden_effect = {
				owner = {
					country_event = {
						id = grand_archive.1120
					}
				}
			}
		}
		allow = {
			owner = { is_homicidal = no }
		}

		modifier = {
			country_base_minerals_produces_add = -100
		}
	}

	monthly_progress = {
		base = 1
		modifier = {
			add = 3
			desc = approach_frenzied_voidworms_hide_presence
			current_situation_approach = approach_frenzied_voidworms_hide_presence
		}
		modifier = {
			add = 3
			desc = approach_frenzied_voidworms_stir_nests
			current_situation_approach = approach_frenzied_voidworms_stir_nests
		}
		modifier = {
			add = 3
			desc = approach_frenzied_voidworms_feed_nests
			current_situation_approach = approach_frenzied_voidworms_feed_nests
		}
	}

	on_monthly = {
		events = {
			grand_archive.1150
		}
	}
}
