############################
#
# Necroids Events
# Written by Gemma Thomson
#
############################

namespace = necroids

#How much more or less likely a given sacrifice result should be, if the number of Mortal Initiates is within each effect's stated bounds.
@sacrificeUpWeighting = 5
@sacrificeDownWeighting = 0.1

#Sacrifice: Togetherness (fired by edict)
country_event = {
	id = necroids.200
	title = necroids.200.name
	desc = necroids.200.desc
	picture = GFX_evt_alien_propaganda
	show_sound = event_death_cult
	location = capital_scope
	is_triggered_only = yes

	trigger = {
		is_spiritualist = yes
		OR = {
			has_valid_civic = civic_death_cult
			has_valid_civic = civic_death_cult_corporate
		}
	}

	immediate = {
		death_cult_sacrifice_effect = yes
	}

	option = {
		name = PRAISE
		add_modifier = {
			modifier = sacrifice_togetherness_mod
			days = 1800
			multiplier = sacrifice_result_mult
			time_multiplier = edict_length_modifiers
		}
		if = {
			limit = {
				check_variable = {
					which = sacrifice_result_mult
					value >= 0.05
				}
			}
			add_modifier = {
				modifier = sacrifice_death_priest_mod
				days = 1800
				time_multiplier = edict_length_modifiers
			}
		}
	}

	after = {
		hidden_effect = {
			every_subject = {
				limit = { has_country_flag = recent_overlord_sacrifice }
				remove_country_flag = recent_overlord_sacrifice
				add_modifier = {
					modifier = sacrifice_togetherness_mod_overlord
					days = 1800
				}
				create_message = {
					type = MESSAGE_OVERLORD_SACRIFICE
					localization = MESSAGE_OVERLORD_SACRIFICE_DESC
					days = 30
					target = prev.capital_scope
				}
			}
			clear_variable = sacrifice_result_mult
			clear_variable = edict_length_modifiers
		}
	}
}

#Sacrifice: Harmony (fired by edict)
country_event = {
	id = necroids.201
	title = necroids.201.name
	desc = necroids.201.desc
	picture = GFX_evt_alien_propaganda
	show_sound = event_death_cult
	location = capital_scope
	is_triggered_only = yes

	trigger = {
		is_spiritualist = yes
		OR = {
			has_valid_civic = civic_death_cult
			has_valid_civic = civic_death_cult_corporate
		}
	}

	immediate = {
		death_cult_sacrifice_effect = yes
	}

	option = {
		name = PRAISE
		add_modifier = {
			modifier = sacrifice_harmony_mod
			days = 1800
			multiplier = sacrifice_result_mult
			time_multiplier = edict_length_modifiers
		}
		if = {
			limit = {
				check_variable = {
					which = sacrifice_result_mult
					value >= 0.05
				}
			}
			add_modifier = {
				modifier = sacrifice_death_priest_mod
				days = 1800
				time_multiplier = edict_length_modifiers
			}
		}
	}

	after = {
		hidden_effect = {
			every_subject = {
				limit = { has_country_flag = recent_overlord_sacrifice }
				remove_country_flag = recent_overlord_sacrifice
				add_modifier = {
					modifier = sacrifice_harmony_mod_overlord
					days = 1800
				}
				create_message = {
					type = MESSAGE_OVERLORD_SACRIFICE
					localization = MESSAGE_OVERLORD_SACRIFICE_DESC
					days = 30
					target = prev.capital_scope
				}
			}
			clear_variable = sacrifice_result_mult
			clear_variable = edict_length_modifiers
		}
	}
}

#Sacrifice: Bounty (fired by edict)
country_event = {
	id = necroids.202
	title = necroids.202.name
	desc = necroids.202.desc
	picture = GFX_evt_alien_propaganda
	show_sound = event_death_cult
	location = capital_scope
	is_triggered_only = yes

	trigger = {
		is_spiritualist = yes
		OR = {
			has_valid_civic = civic_death_cult
			has_valid_civic = civic_death_cult_corporate
		}
	}


	immediate = {
		death_cult_sacrifice_effect = yes
	}

	option = {
		name = PRAISE
		add_modifier = {
			modifier = sacrifice_bounty_mod
			days = 1800
			multiplier = sacrifice_result_mult
			time_multiplier = edict_length_modifiers
		}
		if = {
			limit = {
				check_variable = {
					which = sacrifice_result_mult
					value >= 0.05
				}
			}
			add_modifier = {
				modifier = sacrifice_death_priest_mod
				days = 1800
				time_multiplier = edict_length_modifiers
			}
		}
	}

	after = {
		hidden_effect = {
			every_subject = {
				limit = { has_country_flag = recent_overlord_sacrifice }
				remove_country_flag = recent_overlord_sacrifice
				add_modifier = {
					modifier = sacrifice_bounty_mod_overlord
					days = 1800
				}
				create_message = {
					type = MESSAGE_OVERLORD_SACRIFICE
					localization = MESSAGE_OVERLORD_SACRIFICE_DESC
					days = 30
					target = prev.capital_scope
				}
			}
			clear_variable = sacrifice_result_mult
			clear_variable = edict_length_modifiers
		}
	}
}

# Fired by on_colony_monthly_pulse
carrier_event = { #Braiiiins
	id = necroids.250
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		check_modifier_value = {
			modifier = fake_pop_growth_mod
			value > 0
		}
		any_owned_species = {
			is_organic_species = yes
			NOT = { has_trait = trait_zombie }
		}
		owner = { has_valid_civic = civic_permanent_employment }
		has_building = building_posthumous_employment_center
	}

	immediate = {
		set_variable = {
			which = zombie_pop_amount
			value = 0
		}
		export_modifier_to_variable = {
			modifier = fake_pop_growth_mod
			variable = zombie_pop_amount
		}
		create_zombie_pop_group = {
			SIZE = zombie_pop_amount
		}
		clear_variable = zombie_pop_amount
	}
}

country_event = {
	id = necroids.255
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_valid_civic = civic_permanent_employment
	}

	immediate = {
		country_event = { id = necroids.260 days = 36000 random = 7200 }
	}
}

country_event = {
	id = necroids.260
	is_triggered_only = yes
	title = necroids.260.name
	desc = necroids.260.desc
	picture = GFX_evt_board_meeting
	show_sound = event_yellow_alert

	trigger = {
		has_valid_civic = civic_permanent_employment
		any_owned_pop_group = {
			has_trait = trait_zombie
		}
	}

	immediate = {
		random_owned_pop_group = {
			limit = {
				has_trait = trait_zombie
			}
			save_event_target_as = debt_free_zombie
		}
	}

	option = {
		allow = { is_authoritarian = no }
		name = necroids.260.a
		event_target:debt_free_zombie = {
			kill_single_pop = yes
		}
	}
	option = {
		name = necroids.260.b
		if = {
			limit = {
				is_authoritarian = no
			}
			add_modifier = {
				modifier = zombie_contract_manipulation
				days = -1
			}
		}
	}
}

carrier_event = {
	id = necroids.275
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		OR = {
			num_assigned_jobs = {
				job = overlord_reassigner
				value >= 100
			}
			num_assigned_jobs = {
				job = overlord_reassigner_drone
				value >= 100
			}
		}
	}

	immediate = {
		set_saved_date = {
			key = reemployment_center_timer
			days_from_present = 1800
			expires = 1800
		}
		create_zombie_pop_group = {
			SIZE = 100
		}
	}
}

# Cordyceptic Drones

country_event = {
	id = necroids.300
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_valid_civic = civic_hive_cordyceptic_drones
		from = {
			NOT = { is_country_type = default }
		}
		fromfromfrom = {
			can_be_reanimated = yes
		}
	}

	immediate = {
		fromfrom = {
			if = {
				limit = {
					has_component = "SUBSPACE_DRIVE"
				}
				solar_system = {
					if = {
						limit = {
							any_ship_in_system = {
								exists = owner
								owner = {
									is_same_value = root
								}
								is_ship_class = shipclass_military
								NOT = { has_component = "SUBSPACE_DRIVE" }
							}
						}
						random_ship_in_system = {
							limit = {
								exists = owner
								owner = {
									is_same_value = root
								}
								is_ship_class = shipclass_military
								NOT = { has_component = "SUBSPACE_DRIVE" }
							}
							fleet = {
								save_event_target_as = reanimating_fleet
							}
						}
					}
					else = {
						create_fleet = {
							effect = {
								set_owner = root
								save_event_target_as = reanimating_fleet
								set_location = prev
							}
						}
					}
				}
			}
			else = {
				fleet = {
					save_event_target_as = reanimating_fleet
				}
			}
		}
		fromfromfrom = {
			reanimate_space_fauna = {
				fleet = event_target:reanimating_fleet
			}
		}
	}
}

starbase_event = {
	id = necroids.305
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		OR = {
			has_starbase_building = cordyceptic_reanimation_facility
			has_starbase_module = waystation_cordyceptic_reanimation_facility
		}
		owner = {
			has_valid_civic = civic_hive_cordyceptic_drones
		}
	}
	immediate = {
		starbase_event = { id = necroids.305 days = 1800 }
		solar_system = {
			save_event_target_as = cordyceptic_reanimation_system
		}
		if = {
			limit = {
				solar_system = {
					OR = {
						has_star_flag = tiyanki_graveyard_system
						has_star_flag = tiyanki_spawn_system
					}
				}
			}
			owner = {
				create_fleet = {
					effect = {
						set_owner = root.owner
						while = {
							count = 5
							create_ship = {
								name = NAME_Reanimated_Tiyanki_Cow
								design = NAME_Reanimated_Tiyanki_Cow
								prefix = yes
							}
						}
						while = {
							count = 3
							create_ship = {
								name = NAME_Reanimated_Tiyanki_Bull
								design = NAME_Reanimated_Tiyanki_Bull
								prefix = yes
							}
						}
						while = {
							count = 8
							create_ship = {
								name = NAME_Reanimated_Tiyanki_Calf
								design = NAME_Reanimated_Tiyanki_Calf
								prefix = yes
							}
						}
						set_location = root.solar_system
					}
				}
			}
			owner = {
				create_message = {
					type = MESSAGE_REANIMATION_COMPLETE
					localization = MESSAGE_REANIMATION_COMPLETE_TIYANKI_DESC
					days = 30
					target = root
					variable = {
						type = name
						localization = SYSTEM
						scope = event_target:cordyceptic_reanimation_system
					}
				}
			}
		}
		else_if = {
			limit = {
				solar_system = {
					has_star_flag = amoeba_home_system
				}
			}
			owner = {
				create_fleet = {
					effect = {
						set_owner = root.owner
						while = {
							count = 12
							create_ship = {
								name = NAME_Reanimated_Great_Space_Organism
								design = NAME_Reanimated_Great_Space_Organism
								prefix = yes
							}
						}
						while = {
							count = 6
							create_ship = {
								name = NAME_Reanimated_Small_Space_Organism
								design = NAME_Reanimated_Small_Space_Organism
								prefix = yes
							}
						}
						set_location = root.solar_system
					}
				}
			}
			owner = {
				create_message = {
					type = MESSAGE_REANIMATION_COMPLETE
					localization = MESSAGE_REANIMATION_AMOEBA_TIYANKI_DESC
					days = 30
					target = root
					variable = {
						type = name
						localization = SYSTEM
						scope = event_target:cordyceptic_reanimation_system
					}
				}
			}
		}
	}
}

country_event = {
	id = necroids.310
	title = necroids.310.name
	desc = necroids.310.desc
	picture = GFX_evt_unspeakable_horror
	show_sound = event_whispering

	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		is_country_type = default
		has_valid_civic = civic_hive_cordyceptic_drones
		from = {
			is_country_type = swarm
		}
	}

	option = {
		name = necroids.310.a
	}
}

#Sacrifice: remove the Death Priest boon when the empire is no longer a Death Cult
country_event = {
	id = necroids.315
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_death_cult_empire = no
		has_modifier = sacrifice_death_priest_mod
	}

	immediate = {
		remove_modifier = sacrifice_death_priest_mod
	}
}
