#########################################
#										#
# Cybernetic Creed Events & Situation	#
# Haig Morrison
#		 								#
#########################################

namespace = machine_age

#Pop To Celebrate Intergraded Cybernetics
country_event = {
	id = machine_age.90
	title = "machine_age.90.name"
	desc = "machine_age.90.desc"
	picture = GFX_evt_cybernetic_creed
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	trigger = {
		has_origin = origin_cybernetic_creed
		last_increased_tech = tech_integrated_cybernetics
		NOT = {
			has_country_flag = cyber_creed_integrated_cybernetics
		}
	}

	is_triggered_only = yes

	option = {
		name = "machine_age.90.a"
		custom_tooltip = machine_age.90.a.tooltip
		hidden_effect = {
			set_country_flag = cyber_creed_integrated_cybernetics
		}
	}
}

#Cyber Situation Start
country_event = {
	id = machine_age.100
	title = "machine_age.100.name"
	desc = "machine_age.100.desc"
	picture = GFX_evt_cyber_creed_2
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.100.a"
		owner = {
			start_situation = {
				type = situation_cybernetic_creed_cyberization
				target = root
			}
			set_country_flag = cyber_creed_stop_intro_events
		}
	}
}

#Choose Possible Approach
situation_event = {
	id = machine_age.1000
	title = "machine_age.1000.name"
	desc = "machine_age.1000.desc"
	picture = GFX_evt_cyber_creed_2
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	immediate = {
		set_situation_flag = cybernetic_creed_cyberization_funding
		#This flag pauses the situation while the player makes choices
		set_situation_flag = situation_cyberization_pause
	}

	option = {
		name = "machine_age.1000.a"
		custom_tooltip = "machine_age.1000.a.tooltip"
	}

	after = {
		remove_situation_flag = situation_cyberization_pause
	}
}

#Choose Your Creed
situation_event = {
	id = machine_age.1010
	title = "machine_age.1010.name"
	desc = "machine_age.1010.desc"
	picture = GFX_evt_cyber_creed_2
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	immediate = {
		#This flag pauses the situation while the player makes choices
		set_situation_flag = situation_cyberization_pause
	}

	option = {
		name = "machine_age.1010.a"
		custom_tooltip = "machine_age.1010.a.tooltip"
		hidden_effect = {
			owner = {
				set_country_flag = cybernetic_creed_construction
				capital_scope = {
					set_timed_carrier_flag = {
						flag = ignore_ai_building_limitations
						days = 1
					}
					remove_building = building_amphitheater_of_the_mind
					remove_building = building_sanctuary_of_toil
					remove_building = building_battlement_of_steel
					remove_building = building_forge_of_the_fellowship
					add_building = building_grand_forge_of_the_fellowship
					add_building = building_temple
					add_building = building_temple
					add_building = building_temple
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1010.b"
		custom_tooltip = "machine_age.1010.b.tooltip"
		hidden_effect = {
			owner = {
				set_country_flag = cybernetic_creed_war
				capital_scope = {
					set_timed_carrier_flag = {
						flag = ignore_ai_building_limitations
						days = 1
					}
					remove_building = building_amphitheater_of_the_mind
					remove_building = building_sanctuary_of_toil
					remove_building = building_battlement_of_steel
					remove_building = building_forge_of_the_fellowship
					add_building = building_grand_battlements_of_steel
					add_building = building_temple
					add_building = building_temple
					add_building = building_temple
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_militarist = yes }
			}
		}
	}

	option = {
		name = "machine_age.1010.c"
		custom_tooltip = "machine_age.1010.c.tooltip"
		hidden_effect = {
			owner = {
				set_country_flag = cybernetic_creed_research
				capital_scope = {
					set_timed_carrier_flag = {
						flag = ignore_ai_building_limitations
						days = 1
					}
					remove_building = building_amphitheater_of_the_mind
					remove_building = building_sanctuary_of_toil
					remove_building = building_battlement_of_steel
					remove_building = building_forge_of_the_fellowship
					add_building = building_grand_concert_hall_of_the_mind
					add_building = building_temple
					add_building = building_temple
					add_building = building_temple
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_materialist = yes }
			}
		}
	}

	option = {
		name = "machine_age.1010.d"
		custom_tooltip = "machine_age.1010.d.tooltip"
		hidden_effect = {
			owner = {
				set_country_flag = cybernetic_creed_labor
				capital_scope = {
					set_timed_carrier_flag = {
						flag = ignore_ai_building_limitations
						days = 1
					}
					remove_building = building_amphitheater_of_the_mind
					remove_building = building_sanctuary_of_toil
					remove_building = building_battlement_of_steel
					remove_building = building_forge_of_the_fellowship
					add_building = building_grand_cathedral_of_toil
					add_building = building_temple
					add_building = building_temple
					add_building = building_temple
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1010.e"
		custom_tooltip = "machine_age.1010.e.tooltip"
		hidden_effect = {
			owner = {
				set_country_flag = cybernetic_creed_general
				capital_scope = {
					set_timed_carrier_flag = {
						flag = ignore_ai_building_limitations
						days = 1
					}
					remove_building = building_amphitheater_of_the_mind
					remove_building = building_sanctuary_of_toil
					remove_building = building_battlement_of_steel
					remove_building = building_forge_of_the_fellowship
					add_building = building_the_united_sanctum_of_augmentation
					add_building = building_temple
					add_building = building_temple
					add_building = building_temple
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	after = {
		hidden_effect = {
			owner = {
				every_owned_planet = {
					every_owned_pop_group = {
						force_faction_evaluation = yes
					}
				}
				set_country_flag = first_faction
				remove_country_flag = suppress_vanilla_factions
				inline_script = traits/cybernetic_creed_heretic_outcome
			}
		}
		remove_situation_flag = situation_cyberization_pause
	}
}

#Deal with the Unchosen Creeds
situation_event = {
	id = machine_age.1020
	title = "machine_age.1020.name"
	desc = {
		trigger = {
			owner = {
				NOT = {
					has_country_flag = cybernetic_creed_general
				}
			}
		}
		text = machine_age.1020.desc.pickedacreed
	}
	desc = {
		trigger = {
			owner = {
				has_country_flag = cybernetic_creed_general
			}
		}
		text = machine_age.1020.desc.nocreed
	}
	picture = GFX_evt_cybernetic_creed
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	immediate = {
		#This flag pauses the situation while the player makes choices
		set_situation_flag = situation_cyberization_pause
	}

	option = {
		name = "machine_age.1020.a"
		custom_tooltip = "machine_age.1020.a.tooltip"
		hidden_effect = {
			random_list = {
				60 = {
					situation_event = { id = machine_age.1030 days = 90 }
				}
				40 = {
					situation_event = {	id = machine_age.1040 days = 90 }
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_fanatic = yes }
			}
		}
	}

	option = {
		name = "machine_age.1020.b"
		custom_tooltip = "machine_age.1020.b.tooltip"
		hidden_effect = {
			random_list = {
				20 = {
					situation_event = { id = machine_age.1040 days = 90 }
				}
				40 = {
					situation_event = {	id = machine_age.1050 days = 90 }
				}
				40 = {
					situation_event = {	id = machine_age.1060 days = 90 }
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	after = {
		remove_situation_flag = situation_cyberization_pause
	}
}

#The other Creeds are upset
situation_event = {
	id = machine_age.1030
	title = "machine_age.1030.name"
	desc = "machine_age.1030.desc"
	picture = GFX_evt_cyber_creed_2
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.1030.a"
		custom_tooltip = "machine_age.1030.a.tooltip"
		owner = {
			capital_scope = {
				add_modifier = {
					modifier = cybercreed_faithful_unrest
					days = 360
				}
			}
		}
		hidden_effect = {
			owner = {
				inline_script = traits/cybernetic_creed_heretic_outcome
			}
		}
	}
}

#Everyone is ok with converting
situation_event = {
	id = machine_age.1040
	title = "machine_age.1040.name"
	desc = "machine_age.1040.desc"
	picture = GFX_evt_cybernetic_creed
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.1040.a"
		custom_tooltip = "machine_age.1040.a.tooltip"
		owner = {
			capital_scope = {
				add_modifier = {
					modifier = cybercreed_unified_faith
					days = 360
				}
			}
		}
	}
}

#Tolerace Was Enough
situation_event = {
	id = machine_age.1050
	title = "machine_age.1050.name"
	desc = "machine_age.1050.desc"
	picture = GFX_evt_cybernetic_creed
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.1050.a"
		custom_tooltip = "machine_age.1050.a.tooltip"
	}
}

#The Intolerant Moderates
situation_event = {
	id = machine_age.1060
	title = "machine_age.1060.name"
	desc = "machine_age.1060.desc"
	picture = GFX_evt_cyber_creed_2
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.1060.a"
		custom_tooltip = "machine_age.1060.a.tooltip"
		owner = {
			capital_scope = {
				add_modifier = {
					modifier = cybercreed_moderates_ignored
					days = 360
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_fanatic = no }
			}
		}
	}

	option = {
		name = "machine_age.1060.b"
		custom_tooltip = "machine_age.1060.a.tooltip"
		owner = {
			capital_scope = {
				add_modifier = {
					modifier = cybercreed_creeds_absorbed
					days = 360
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_fanatic = yes }
			}
		}
	}
}

#The Tithe
situation_event = {
	id = machine_age.1070
	title = "machine_age.1070.name"
	desc = "machine_age.1070.desc"
	picture = GFX_evt_cybernetic_creed
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	immediate = {
		#This flag pauses the situation while the player makes choices
		set_situation_flag = situation_cyberization_pause
	}

	option = {
		name = "machine_age.1070.a"
		trigger = {
			owner = {
				has_civic = civic_mining_guilds
			}
		}
		custom_tooltip = "machine_age.1070.a.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_mining
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.b"
		trigger = {
			owner = {
				has_civic = civic_agrarian_idyll
			}
		}
		custom_tooltip = "machine_age.1070.b.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_farming
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.c"
		trigger = {
			owner = {
				OR = {
					has_country_flag = cybernetic_creed_general
					has_country_flag = cybernetic_creed_construction
				}
			}
		}
		custom_tooltip = "machine_age.1070.c.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_steel
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.d"
		trigger = {
			owner = {
				has_country_flag = cybernetic_creed_construction
			}
		}
		custom_tooltip = "machine_age.1070.d.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_construction
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.e"
		trigger = {
			owner = {
				OR = {
					has_country_flag = cybernetic_creed_general
					has_country_flag = cybernetic_creed_war
					has_civic = civic_warrior_culture
				}
			}
		}
		custom_tooltip = "machine_age.1070.e.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_army
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.f"
		trigger = {
			owner = {
				OR = {
					has_country_flag = cybernetic_creed_war
					has_civic = civic_distinguished_admiralty
				}
			}
		}
		custom_tooltip = "machine_age.1070.f.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_navy
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.g"
		trigger = {
			owner = {
				has_country_flag = cybernetic_creed_research
			}
		}
		custom_tooltip = "machine_age.1070.g.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_cybernetics
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.h"
		trigger = {
			owner = {
				OR = {
					has_country_flag = cybernetic_creed_general
					has_country_flag = cybernetic_creed_research
				}
			}
		}
		custom_tooltip = "machine_age.1070.h.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_research
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.i"
		trigger = {
			owner = {
				OR = {
					has_country_flag = cybernetic_creed_general
					has_country_flag = cybernetic_creed_labor
					has_civic = civic_shared_burden
				}
			}
		}
		custom_tooltip = "machine_age.1070.i.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_labor
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.j"
		trigger = {
			owner = {
				OR = {
					has_country_flag = cybernetic_creed_labor
					has_civic = civic_merchant_guilds
					is_megacorp = yes
				}
			}
		}
		custom_tooltip = "machine_age.1070.j.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_wealth
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.1070.k"
		trigger = {
			owner = {
				OR = {
					has_civic = civic_crafters
					has_country_flag = cybernetic_creed_construction
				}
			}
		}
		custom_tooltip = "machine_age.1070.k.tooltip"
		owner = {
			add_modifier = {
				modifier = cybercreed_tithe_craft
				days = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	after = {
		remove_situation_flag = situation_cyberization_pause
	}
}

#Let the Fusion Begin
situation_event = {
	id = machine_age.1075
	title = "machine_age.1075.name"
	desc = "machine_age.1075.desc"
	picture = GFX_evt_cybernetics
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	immediate = {
		owner = {
			# Make the Augmentation Center building available
			set_country_flag = augmentation_center_available
			set_country_flag = augmentation_center_needed
		}

		# When this flag is set, the situation is paused and an event is called each month in the situation to cyberize pops.
		set_situation_flag = cybernetic_creed_cyberization_ongoing

		#This flag pauses the situation while the player makes choices
		set_situation_flag = situation_cyberization_pause
	}

	#It is time
	option = {
		name = "machine_age.1075.a"
		custom_tooltip = "machine_age.1075.a.tooltip"
	}

	after = {
		remove_situation_flag = situation_cyberization_pause
	}
}

#The Creeds Final Form
situation_event = {
	id = machine_age.1090
	title = "machine_age.1090.name"
	desc = {
		trigger = {
			owner = {
				has_country_flag = cybernetic_creed_construction
			}
		}
		text = machine_age.1090.construction
	}
	desc = {
		trigger = {
			owner = {
				has_country_flag = cybernetic_creed_war
			}
		}
		text = machine_age.1090.war
	}
	desc = {
		trigger = {
			owner = {
				has_country_flag = cybernetic_creed_research
			}
		}
		text = machine_age.1090.research
	}
	desc = {
		trigger = {
			owner = {
				has_country_flag = cybernetic_creed_labor
			}
		}
		text = machine_age.1090.labor
	}
	picture = GFX_evt_cybernetic_creed
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = cybercreed_final_form
			set_country_flag = cybernetics_traditions_unlocked
			country_event = { id = timeline.79 }
			every_owned_pop_group = {
				limit = {
					has_trait = trait_cybernetic
					OR = {
						has_citizenship_type = { type = citizenship_full }
						has_citizenship_type = { type = citizenship_limited }
					}
				}
				owner = {
					switch = {
						trigger = has_country_flag
						cybernetic_creed_construction = {
							prev = {
								inline_script = traits/cybernetic_creed_construction_traits
							}
						}
						cybernetic_creed_war = {
							prev = {
								inline_script = traits/cybernetic_creed_war_traits
							}
						}
						cybernetic_creed_research = {
							prev = {
								inline_script = traits/cybernetic_creed_research_traits
							}
						}
						cybernetic_creed_labor = {
							prev = {
								inline_script = traits/cybernetic_creed_labor_traits
							}
						}
						cybernetic_creed_general = {
							prev = {
								modify_species = {
									species = this
									add_trait = trait_cyborg_ritualistic_implants
									add_traits_at_start_of_list = yes
								}
							}
						}
					}
				}
			}
		}
	}

	#Democratic
	option = {
		trigger = {
			owner = {
				is_democratic_authority = yes
			}
		}
		name = "machine_age.1090.a"
		custom_tooltip = "machine_age.1090.a.tooltip"
	}

	#Oligarchic
	option = {
		trigger = {
			owner = {
				is_oligarchic_authority = yes
			}
		}
		name = "machine_age.1090.a"
		custom_tooltip = "machine_age.1090.b.tooltip"
	}

	#Dictatorial
	option = {
		trigger = {
			owner = {
				is_dictatorial_authority = yes
			}
		}
		name = "machine_age.1090.a"
		custom_tooltip = "machine_age.1090.c.tooltip"
	}

	#Imperial
	option = {
		trigger = {
			owner = {
				is_imperial_authority = yes
			}
		}
		name = "machine_age.1090.a"
		custom_tooltip = "machine_age.1090.d.tooltip"
	}

	#Corperate
	option = {
		trigger = {
			owner = {
				is_megacorp = yes
			}
		}
		name = "machine_age.1090.a"
		custom_tooltip = "machine_age.1090.e.tooltip"
	}

	after = {
		owner = {
			end_event_chain = cybernetic_creed_chain
			set_country_flag = cyber_creed_finished_situation
			switch = {
				trigger = has_country_flag
				cybernetic_creed_construction = {
					add_modifier = {
						modifier = cybernetic_creed_construction_robot_points_modifier
						days = -1
					}
				}
				cybernetic_creed_war = {
					add_modifier = {
						modifier = cybernetic_creed_war_robot_points_modifier
						days = -1
					}
				}
				cybernetic_creed_research = {
					add_modifier = {
						modifier = cybernetic_creed_research_robot_points_modifier
						days = -1
					}
				}
				cybernetic_creed_labor = {
					add_modifier = {
						modifier = cybernetic_creed_labor_robot_points_modifier
						days = -1
					}
				}
			}
		}
		hidden_effect = {
			destroy_situation = this
		}
	}
}

#No Creeds, No Need
situation_event = {
	id = machine_age.1100
	title = "machine_age.1100.name"
	desc = "machine_age.1100.desc"
	picture = GFX_evt_cybernetic_creed
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = timeline.79 }
			set_country_flag = cybernetics_traditions_unlocked
		}
	}

	#Democratic
	option = {
		trigger = {
			owner = {
				is_democratic_authority = yes
			}
		}
		name = "machine_age.1100.a"
		custom_tooltip = "machine_age.1100.a.tooltip"
	}

	#Oligarchic
	option = {
		trigger = {
			owner = {
				is_oligarchic_authority = yes
			}
		}
		name = "machine_age.1100.a"
		custom_tooltip = "machine_age.1100.b.tooltip"
	}

	#Dictatorial
	option = {
		trigger = {
			owner = {
				is_dictatorial_authority = yes
			}
		}
		name = "machine_age.1100.a"
		custom_tooltip = "machine_age.1100.c.tooltip"
	}

	#Imperial
	option = {
		trigger = {
			owner = {
				is_imperial_authority = yes
			}
		}
		name = "machine_age.1100.a"
		custom_tooltip = "machine_age.1100.d.tooltip"
	}

	#Corporate
	option = {
		trigger = {
			owner = {
				is_megacorp = yes
			}
		}
		name = "machine_age.1100.a"
		custom_tooltip = "machine_age.1100.e.tooltip"
	}

	after = {
		owner = {
			add_modifier = {
				modifier = cyber_creed_no_creed_robot_points_modifier
				days = -1
			}
			end_event_chain = cybernetic_creed_chain
		}
		hidden_effect = {
			destroy_situation = this
			owner = {
				set_country_flag = can_genemod_cyborg_ritualistic_pops
				set_country_flag = cyber_creed_finished_situation
			}
		}
	}
}

#This event fires in the situation to create cyborg pops.
situation_event = {
	id = machine_age.2000
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_situation_flag = cybernetic_creed_cyberization_ongoing
		owner = {
			OR = {
				check_variable_arithmetic = { which = value:num_active_buildings|BUILDING|building_augmentation_center| value > 0 }
				check_variable_arithmetic = { which = value:num_active_buildings|BUILDING|building_augmentation_bazaars| value > 0 }
			}
		}
	}

	immediate = {
		owner = {
			weighted_random_owned_pop_group = {
				limit = {
					is_same_species = owner.species
					NOT = {	has_trait = trait_cybernetic }
					pop_group_size > 0
				}
				species = {
					if = {
						limit = {
							NOT = { exists = event_target:cybercreedspecies@root.owner }
						}
						create_cyber_creed_species_effect = yes
					}
				}
			}

			every_owned_pop_group = {
				limit = {
					exists = event_target:cyberspecies_current
					is_same_species = owner.species
					NOT = {	has_trait = trait_cybernetic }
					pop_group_size > 0
					pop_group_size < 5
				}
				owner = {
					cyberize_creed_pops_effect = {
						SINGLE_LOOP = yes
						TINY_GROUPS = yes
					}
				}
			}

			cyberize_creed_pops_effect = yes
			cyberize_creed_leaders_effect = yes
		}
		# Check if there are any pops left to cyberize, otherwise remove the cyberization flag to unpause the situation.
		if = {
			limit = {
				NOT = {
					owner = {
						any_owned_pop_group = {
							exists = event_target:cybercreedspecies@root.owner
							is_same_species = owner.species
							NOT = {	has_trait = trait_cybernetic }
						}
					}
				}
			}
			remove_situation_flag = cybernetic_creed_cyberization_ongoing
			owner = {
				set_country_flag = cybernetic_creed_cyberization_finished
				change_dominant_species = { species = event_target:cybercreedspecies@root.owner change_all = yes }
			}
		}
	}
}

#Cyber Creed Starting Events
#This event fires the other events on a two year pulse
event = {
	id = machine_age.2200
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		any_country = {
			has_origin = origin_cybernetic_creed
			NOT = {
				has_country_flag = cyber_creed_stop_intro_events
			}
		}
	}

	immediate = {
		every_country = {
			limit = {
				has_origin = origin_cybernetic_creed
				NOT = {
					has_country_flag = cyber_creed_stop_intro_events
				}
			}
			country_event = { id = machine_age.2201 days = 0 }
		}
	}
}

#First Month Creeds Are Formed
country_event = {
	id = machine_age.2150
	title = "machine_age.2150.name"
	desc = "machine_age.2150.desc"
	picture = GFX_evt_cyber_creed_2
	show_sound = event_factions
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = b_world_spawned
		}
	}

	option = {
		name = "machine_age.2150.a"
		custom_tooltip = machine_age.2150.a.tooltip
	}
}
#Control Event
country_event = {
	id = machine_age.2201
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		random_list = {
			20 = { }
			10 = {
				modifier = {
					factor = 0
					has_country_flag = cyber_creed_templar_defeat
				}
				country_event = { id = machine_age.2205 days = 90 random = 90 }
				set_country_flag = cyber_creed_templar_defeat
			}
			10 = {
				modifier = {
					factor = 0
					has_country_flag = cyber_creed_dead_fellowship_leader
				}
				country_event = { id = machine_age.2210 days = 90 random = 90 }
				set_country_flag = cyber_creed_dead_fellowship_leader
			}
			10 = {
				modifier = {
					factor = 0
					has_country_flag = cyber_creed_relic_found
				}
				country_event = { id = machine_age.2215 days = 90 random = 90 }
				set_country_flag = cyber_creed_relic_found
			}
			10 = {
				modifier = {
					factor = 0
					OR = {
						has_country_flag = cyber_creed_creed_insider
						num_owned_leaders < 2
					}
				}
				country_event = { id = machine_age.2220 days = 90 random = 90 }
				set_country_flag = cyber_creed_creed_insider
			}
			10 = {
				modifier = {
					factor = 0
					has_country_flag = cyber_creed_creed_pilgrimage
				}
				country_event = { id = machine_age.2225 days = 90 random = 90 }
				set_country_flag = cyber_creed_creed_pilgrimage
			}
			10 = {
				modifier = {
					factor = 0
					has_country_flag = cyber_creed_sing_science
				}
				country_event = { id = machine_age.2230 days = 90 random = 90 }
				set_country_flag = cyber_creed_sing_science
			}
		}
	}
}

#Templars don't want to talk about defeat
country_event = {
	id = machine_age.2205
	title = "machine_age.2205.name"
	desc = "machine_age.2205.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.2205.a"
		custom_tooltip = machine_age.2205.a.tooltip
		add_modifier = {
			modifier = cyber_creed_history_rewritten
			days = 3600
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_authoritarian = yes }
			}
		}
	}

	option = {
		name = "machine_age.2205.b"
		custom_tooltip = machine_age.2205.b.tooltip
		add_modifier = {
			modifier = cyber_creed_history_repeating
			days = 3600
		}
		ai_chance = {
			factor = 1
		}
	}
}

#The Fellowship Leader dies
country_event = {
	id = machine_age.2210
	title = "machine_age.2210.name"
	desc = "machine_age.2210.desc"
	picture = GFX_evt_coronation
	show_sound = event_factions
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.2210.a"
		custom_tooltip = machine_age.2210.a.tooltip
		add_modifier = {
			modifier = cyber_creed_state_funeral
			days = 3600
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_spiritualist = yes }
			}
		}
	}

	option = {
		name = "machine_age.2210.b"
		custom_tooltip = machine_age.2210.b.tooltip
		add_modifier = {
			modifier = cyber_creed_no_state_funeral
			days = 3600
		}
		ai_chance = {
			factor = 1
		}
	}
}

#A controversial Relic
country_event = {
	id = machine_age.2215
	title = "machine_age.2215.name"
	desc = "machine_age.2215.desc"
	picture = GFX_evt_ancient_records
	show_sound = event_mystic_reveal
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.2215.a"
		custom_tooltip = machine_age.2215.a.tooltip
		add_modifier = {
			modifier = cyber_creed_relics_truth
			days = 3600
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.2215.b"
		custom_tooltip = machine_age.2215.b.tooltip
		add_modifier = {
			modifier = cyber_creed_relics_hidden
			days = 3600
		}
		ai_chance = {
			factor = 1
		}
	}
}

#Pre event for machine_age.2221
country_event = {
	id = machine_age.2220
	fire_only_once = yes
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		random_owned_leader = {
			limit = {
				is_ruler = no
			}
			save_event_target_as = cyber_creed_undercover_leader
		}
		random_list = {
			25 = { set_country_flag = cyber_creed_undercover_leader_steel }
			25 = { set_country_flag = cyber_creed_undercover_leader_choir }
			25 = { set_country_flag = cyber_creed_undercover_leader_toil }
			25 = { set_country_flag = cyber_creed_undercover_leader_steel }
		}
		country_event = { id = machine_age.2221 days = 1 }
	}
}

#Leader is a Creed Agent
country_event = {
	id = machine_age.2221
	title = "machine_age.2221.name"
	desc = "machine_age.2221.desc"
	picture = GFX_evt_cover_blown
	show_sound = event_assembly_fight
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.2221.a"
		custom_tooltip = "machine_age.2221.a.tooltip"
		hidden_effect = {
			event_target:cyber_creed_undercover_leader = {
				kill_leader = { show_notification = no }
			}
		}
		add_modifier = {
			modifier = cyber_creed_leader_removed
			days = 1800
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.2221.b"
		hidden_effect = {
			event_target:cyber_creed_undercover_leader = {
				add_trait = {
					trait = leader_trait_fallible_2
					show_message = no
				}
			}
		}
		add_modifier = {
			modifier = cyber_creed_leader_stayed
			days = 1800
		}
		ai_chance = {
			factor = 1
		}
	}

	after = {
		hidden_effect = {
			remove_country_flag = cyber_creed_undercover_leader_steel
			remove_country_flag = cyber_creed_undercover_leader_choir
			remove_country_flag = cyber_creed_undercover_leader_toil
			remove_country_flag = cyber_creed_undercover_leader_steel
		}
	}
}

#Fellowship is on their pilgrimage
country_event = {
	id = machine_age.2225
	title = "machine_age.2225.name"
	desc = "machine_age.2225.desc"
	picture = GFX_evt_announcement
	show_sound = event_administrative_work
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.2225.a"
		custom_tooltip = machine_age.2225.a.tooltip
		add_modifier = {
			modifier = cyber_creed_pilgrimage_canceled
			days = 1800
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.2225.b"
		custom_tooltip = machine_age.2225.b.tooltip
		add_modifier = {
			modifier = cyber_creed_pilgrimage_allowed
			days = 1800
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_spiritualist = yes }
			}
		}
	}
}

#Choirmaster Demands more Science
country_event = {
	id = machine_age.2230
	title = "machine_age.2230.name"
	desc = "machine_age.2230.desc"
	picture = GFX_evt_alien_propaganda
	show_sound = event_planetary_riot
	event_chain = cybernetic_creed_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.2230.a"
		custom_tooltip = machine_age.2230.a.tooltip
		add_modifier = {
			modifier = cyber_creed_no_choirmaster_funding
			days = 3600
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.2230.b"
		custom_tooltip = machine_age.2230.b.tooltip
		add_modifier = {
			modifier = cyber_creed_low_choirmaster_funding
			days = 1800
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.2230.c"
		custom_tooltip = machine_age.2230.c.tooltip
		add_modifier = {
			modifier = cyber_creed_high_choirmaster_funding
			days = 3600
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = { is_materialist = yes }
			}
		}
	}
}

#############################################
#											#
#					 						#
# Synthetic Fertility Events & Situation	#
# Haig Morrison								#
#											#
#											#
#############################################

country_event = {
	id = machine_age.3100
	title = "machine_age.3100.name"
	desc = "machine_age.3100.desc"
	picture = GFX_evt_synth_fertility
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	trigger = {
		has_origin = origin_synthetic_fertility
	}

	immediate = {
		start_situation = {
			type = situation_synthetic_fertility_digitization
			target = root
		}
		begin_event_chain = {
			event_chain = "synthetic_fertility_chain"
			target = this
		}
	}

	option = {
		name = "machine_age.3100.a"
		add_tech_progress = { tech = tech_robotic_workers progress = 0.15 }
		add_tech_progress = { tech = tech_administrative_ai progress = 0.5 }
	}
}

country_event = {
	id = machine_age.3110
	title = "machine_age.3110.name"
	desc = "machine_age.3110.desc"
	picture = GFX_evt_synth_fertility
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	trigger = {
		has_origin = origin_synthetic_fertility
		has_technology = tech_robotic_workers
		NOT = {
			has_country_flag = origin_synthetic_fertility_robots
		}
	}

	immediate = {
		set_country_flag = origin_synthetic_fertility_robots
	}

	option = {
		name = "machine_age.3110.a"
		custom_tooltip = "machine_age.3110.a.tooltip"
		add_tech_option_or_research_effect = {
			TECH = tech_droid_workers
			PROGRESS = 0.20
			CATEGORY = engineering_research
		}
		hidden_effect = {
			create_built_robot_species = yes
			last_created_species = {
				save_global_event_target_as = synth_fert_surrogate@root.owner
				set_citizenship_type = {
					country = ROOT
					type = citizenship_full
					cooldown = yes
				}
			}
			random_owned_colony = {
				limit = {
					is_capital = yes
				}
				set_timed_carrier_flag = {
					flag = ignore_ai_building_limitations
					days = 1
				}
				remove_building = building_abandoned_gene_clinic
				add_building = building_robot_assembly_plant
				while = {
					count = 3
					create_pop_group = {
						species = last_created_species
					}
				}
			}
		}
	}
}

country_event = {
	id = machine_age.3115
	title = "machine_age.3115.name"
	desc = "machine_age.3115.desc"
	picture = GFX_evt_synth_fertility
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	trigger = {
		has_origin = origin_synthetic_fertility
		has_technology = tech_droid_workers
		NOT = {
			has_country_flag = origin_synthetic_fertility_droids
		}
	}

	immediate = {
		every_owned_species = {
			limit = {
				has_trait = trait_mechanical
			}
			set_colonization_controls = {
				country = ROOT
				type = colonization_control_no
				cooldown = yes
			}
			set_citizenship_type = {
				country = ROOT
				type = citizenship_full
				cooldown = yes
			}
			set_military_service_type = {
				country = ROOT
				type = military_service_full
				cooldown = yes
			}
		}
		set_country_flag = origin_synthetic_fertility_droids
	}

	option = {
		name = "machine_age.3115.a"
		add_tech_option_or_research_effect = {
			TECH = tech_synthetic_workers
			PROGRESS = 0.15
			CATEGORY = engineering_research
		}
	}
}

country_event = {
	id = machine_age.3120
	title = "machine_age.3120.name"
	desc = "machine_age.3120.desc"
	picture = GFX_evt_synth_fertility
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	trigger = {
		has_origin = origin_synthetic_fertility
		has_technology = tech_synthetic_workers
		NOT = {
			has_country_flag = origin_synthetic_fertility_synths
		}
	}

	immediate = {
		set_country_flag = origin_synthetic_fertility_synths
		give_technology = {
			tech = tech_synthetic_leaders
			message = no
		}
		every_owned_species = {
			limit = {
				has_trait = trait_mechanical
			}
			set_citizenship_type = {
				country = ROOT
				type = citizenship_full
				cooldown = yes
			}
			set_military_service_type = {
				country = ROOT
				type = military_service_full
				cooldown = yes
			}
		}
	}

	option = {
		name = "machine_age.3120.a"
	 	custom_tooltip = "machine_age.3120.a.tooltip"
	}
}

country_event = {
	id = machine_age.3125
	title = "machine_age.3125.name"
	desc = {
		trigger = {
			owner = {
				NOT = {
					has_country_flag = synthetic_fertility_no_bodies_left
				}
			}
		}
		text = machine_age.3125.desc
	}
	desc = {
		trigger = {
			owner = {
				has_country_flag = synthetic_fertility_no_bodies_left
			}
		}
		text = machine_age.3125.nobody.desc
	}
	picture = GFX_evt_synth_fertility
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	trigger = {
		has_origin = origin_synthetic_fertility
		has_tradition = tr_synthetics_adopt
		NOT = {
			has_country_flag = synthetics_traditions_unlocked
		}
	}

	immediate = {
		set_country_flag = origin_synthetic_fertility_synths
		random_situation = {
			limit = {
				is_situation_type = situation_synthetic_fertility_digitization
			}
			destroy_situation = this
		}
		if = {
			limit = {
				has_country_flag = synthetic_fertility_no_bodies_left
			}
			capital_scope = {
				create_synth_species_effect = yes
			}
			capital_scope = {
				create_pop_group = {
					species = event_target:synthspecies@root.owner
				}
			}
		}
	}

	option = {
		name = "synth.105.a"
		custom_tooltip = "synth.105.a.tt"
		owner = { set_country_flag = synth_focus_rulers }
		start_situation = {
			type = situation_synthetic_fertility_synthesization
			target = root
		}
	}
	option = {
		name = "synth.105.b"
		custom_tooltip = "synth.105.b.tt"
		owner = { set_country_flag = synth_focus_specialists }
		start_situation = {
			type = situation_synthetic_fertility_synthesization
			target = root
		}
	}
	option = {
		name = "synth.105.c"
		custom_tooltip = "synth.105.c.tt"
		owner = { set_country_flag = synth_focus_workers }
		start_situation = {
			type = situation_synthetic_fertility_synthesization
			target = root
		}
	}
	option = {
		name = "synth.105.d"
		custom_tooltip = "synth.105.d.tt"
		owner = { set_country_flag = synth_focus_upkeep }
		start_situation = {
			type = situation_synthetic_fertility_synthesization
			target = root
		}
	}
}

# A Synthetic Fertility empire that builds a new arkship before completing its synthetic ascension founds it with droids
colony_event = {
	id = machine_age.3130
	hide_window = yes
	is_triggered_only = yes
	event_chain = synthetic_fertility_chain

	trigger = {
		owner = {
			has_origin = origin_synthetic_fertility
			NOT = { has_country_flag = synthetics_traditions_unlocked }
		}
		exists = event_target:synth_fert_surrogate@root.owner
	}

	immediate = {
		every_owned_pop_group = {
			limit = {
				species = { is_robotic = no }
			}
			change_species = event_target:synth_fert_surrogate@root.owner
		}
	}
}

#Everyone is dead
situation_event = {
	id = machine_age.3200
	title = "machine_age.3200.name"
	desc = "machine_age.3200.desc"
	picture = GFX_evt_city_ruins
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	immediate = {
		destroy_situation = this
		owner = {
			set_country_flag = synthetic_fertility_no_bodies_left
			owner_main_species = {
				set_species_flag = holographic_appearance
			}
			every_owned_leader = {
				limit = {
					is_same_species = owner
					NOT = {
						has_trait = leader_trait_intemporal
					}
				}
				change_species = event_target:synth_fert_surrogate@root.owner
				add_trait = {
					trait = leader_trait_robotic_surrogate
					show_message = no
				}
				set_age = 1

			}
			random_owned_leader = {
				limit = {
					is_ruler = yes
					NOT = {
						has_trait = leader_trait_intemporal
					}
				}
				change_leader_portrait = event_target:synth_fert_surrogate@root.owner
				add_trait = {
					trait = leader_trait_robotic_surrogate
					show_message = no
				}
				set_age = 1
			}
			every_pool_leader = {
				limit = {
					is_same_species = owner
				}
				change_species = event_target:synth_fert_surrogate@root.owner
				add_trait = {
					trait = leader_trait_robotic_surrogate
					show_message = no
				}
				set_age = 1
			}
			refresh_portraits = character
		}
	}

	option = {
		name = UNDERSTOOD
	}
}

#Final Choice for the Pops and Identities
situation_event = {
	id = machine_age.3305
	title = "machine_age.3305.name"
	desc = "machine_age.3305.desc"
	picture = GFX_evt_virtual_world
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	option = {
		name = "machine_age.3305.a"
		custom_tooltip = "machine_age.3305.a.tooltip"
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.3305.b"
		custom_tooltip = "machine_age.3305.b.tooltip"
		hidden_effect = {
			owner = {
				divide_variable = {
					which = num_dead_identities
					value = 100
				}
				while = {
					limit = {
						any_owned_pop_group = {
							NOT = { is_same_species = owner.species }
							is_robot_pop_group = yes
						}
					}
					count = num_dead_identities
					weighted_random_owned_pop_group = {
						limit = {
							NOT = { is_same_species = owner.species }
							is_robot_pop_group = yes
						}
						change_species = event_target:synthspecies@root.owner
					}
					change_variable = {
						which = num_dead_identities
						value = -1
					}
				}
				while = {
					count = num_dead_identities
					capital_scope = {
						create_pop_group = {
							species = event_target:synthspecies@root.owner
						}
					}
					change_variable = {
						which = num_dead_identities
						value = -1
					}
				}
				set_country_flag = synthetic_fertility_no_identity_left_behind
				every_owned_planet = {
					remove_building = building_identity_repository
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	after = {
		hidden_effect = {
			owner = {
				every_owned_leader = {
					limit = {
						has_trait = leader_trait_robotic_surrogate
					}
					change_species = event_target:synthspecies@root.owner
					add_trait = {
						trait = leader_trait_synthetic
						show_message = no
					}
					set_age = 1
					remove_trait = leader_trait_robotic_surrogate
				}
				random_owned_leader = {
					limit = {
						is_ruler = yes
						NOT = {
							has_trait = leader_trait_intemporal
						}
					}
					change_leader_portrait = event_target:synthspecies@root.owner
					add_trait = {
						trait = leader_trait_synthetic
						show_message = no
					}
					set_age = 1
					remove_trait = leader_trait_robotic_surrogate
				}
				every_pool_leader = {
					limit = {
						has_trait = leader_trait_robotic_surrogate
					}
					change_species = event_target:synthspecies@root.owner
					add_trait = {
						trait = leader_trait_synthetic
						show_message = no
					}
					set_age = 1
					remove_trait = leader_trait_robotic_surrogate
				}
				every_envoy = {
					limit = {
						exists = species
						species = {
							is_robotic = no
							is_livestock = no
						}
					}
					change_species = event_target:synthspecies@root.owner
					change_leader_portrait = species
					set_age = 1
				}
				every_controlled_ship = {
					limit = {
						is_ship_class = shipclass_colonizer
						species = {
							is_robotic = no
							is_livestock = no
						}
					}
					change_species = event_target:synthspecies@root.owner
				}
				every_owned_army = {
					limit = {
						exists = species
						species = {
							is_robotic = no
							is_livestock = no
						}
						army_type = assault_army
					}
					modify_army = {
						name = random
						type = "robotic_army"
						species = event_target:synthspecies@root.owner
					}
				}
				every_owned_army = {
					limit = {
						exists = species
						exists = planet
						species = {
							is_robotic = no
							is_livestock = no
						}
						OR = {
							army_type = defense_army
							army_type = fanatic_guardian
						}
					}
					modify_army = {
						name = random
						type = "robotic_defense_army"
						species = event_target:synthspecies@root.owner
					}
				}
			}
		}
	}
}

#Time to make Babies
situation_event = {
	id = machine_age.3310
	title = "machine_age.3310.name"
	desc = "machine_age.3310.desc"
	picture = GFX_evt_synth_fertility
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = {
				id = machine_age.3315
				days = 7
			}
			give_technology = { tech = tech_identity_copy }
			set_country_flag = advanced_identity_creation
			set_country_flag = edict_subsidized_identity_backups
			set_country_flag = edict_optimized_identity_creation
		}
	}

	option = {
		name = "machine_age.3310.a"
		custom_tooltip = "machine_age.3310.building_tooltip.a.tt"
		hidden_effect = {
			owner = {
				add_research_option = tech_identity_fusion
			}
		}
		destroy_situation = this
		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = "machine_age.3310.b"
		custom_tooltip = "machine_age.3310.building_tooltip.b.tt"
		hidden_effect = {
			owner = {
				add_research_option = tech_identity_initialization
			}
		}
		destroy_situation = this
		ai_chance = {
			factor = 1
		}
	}
}

#Chain End
country_event = {
	id = machine_age.3315
	title = "machine_age.3315.name"
	desc = "machine_age.3315.desc"
	picture = GFX_evt_synth_fertility
	show_sound = event_radio_chatter
	event_chain = synthetic_fertility_chain

	is_triggered_only = yes

	immediate = {
		set_country_flag = synthetics_traditions_unlocked
		set_country_flag = synthetic_empire
		set_country_flag = upload_center_available
	}

	option = {
		name = "machine_age.3315.a"
		end_event_chain = "synthetic_fertility_chain"
		owner = {
			add_modifier = {
				modifier = synthetic_dawn
				days = -1
			}
		}
		custom_tooltip = machine_age.3315.a.tt
		owner_main_species = {
			change_species_characteristics = {
				add_trait = trait_robot_synthetic_dawn
			}
		}
		hidden_effect = {
			if = {
				limit = { has_active_tradition = tr_synthetics_finish }
				country_event = { id = synth.500 days = 180 }
			}
		}
	}
}

#Count the total pops at game start - this only works if the two variables don't match
situation_event = {
	id = machine_age.3320
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = {
			export_trigger_value_to_variable = {
				trigger = count_owned_pop_amount
				parameters = {
					limit = {
						has_trait = trait_pathogenic_genes
					}
				}
				variable = remaining_synth_fert_pops
			}
		}
	}
}

situation_event = {
	id = machine_age.3325
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = { #Check how many pops are still alive
			export_trigger_value_to_variable = {
				trigger = count_owned_pop_amount
				parameters = {
					limit = {
						has_trait = trait_pathogenic_genes
					}
				}
				variable = remaining_synth_fert_pops_month_check
			}
		}
		if = { #Update the situation pace in case of discrepancy
			limit = {
				owner = {
					check_variable_arithmetic = {
						which = remaining_synth_fert_pops
						subtract = remaining_synth_fert_pops_month_check
						value != 0
					}
				}
			}
			add_situation_progress = owner.value:num_synth_fert_check_the_dead
			owner = {
				set_variable = {
					which = remaining_synth_fert_pops
					value = remaining_synth_fert_pops_month_check
				}
			}
		}

		# Update the ID repository
		owner = {
			add_variable = {
				which = num_dead_identities
				value = value:num_synth_fert_upload_per_month
			}
			subtract_variable = {
				which = remaining_synth_fert_pops
				value = value:num_synth_fert_upload_per_month
			}

			while = {
				count = value:num_synth_fert_upload_per_month
				weighted_random_owned_pop_group = {
					limit = {
						has_trait = trait_pathogenic_genes
					}
					kill_pop_group = {
						pop_group = this
						amount = 1
					}
				}
			}
		}
	}
}

situation_event = {
	id = machine_age.3326
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		# Count all alive pathogenic pops
		owner = {
			export_trigger_value_to_variable = {
				trigger = count_owned_pop_amount
				parameters = {
					limit = {
						has_trait = trait_pathogenic_genes
					}
				}
				variable = remaining_synth_fert_pops_month_check
			}
		}

		# Upload all remaining to the ID repository
		owner = {
			add_variable = {
				which = num_dead_identities
				value = value:num_synth_fert_upload_final
			}

			while = {
				count = value:num_synth_fert_upload_final
				weighted_random_owned_pop_group = {
					limit = {
						has_trait = trait_pathogenic_genes
					}
					kill_pop_group = {
						pop_group = this
						amount = 1
					}
				}
			}
		}
	}
}

#Arc Welders
#Ideal system surveyed
ship_event = {
	id = machine_age.3400
	title = "machine_age.3400.name"
	desc = "machine_age.3400.desc"
	picture = GFX_evt_arc_crucible
	show_sound = event_ship_bridge
	location = from
	event_chain = ideal_furnace_chain

	is_triggered_only = yes

	trigger = {
		from = {
			has_star_flag = arc_welders_construction_system
		}
		NOT = {
			owner = {
				has_country_flag = surveyed_welders_system
			}
		}
	}

	immediate = {
		owner = {
			set_country_flag = surveyed_welders_system
			begin_event_chain = {
				event_chain = ideal_furnace_chain
				target = this
			}
			create_point_of_interest = {
				id = ideal_furnace_system
				name = "ideal_furnace_system_poi"
				desc = ideal_furnace_system_desc
				event_chain = ideal_furnace_chain
				location = from
			}
		}
	}

	option = {
		name = EXCELLENT
	}
}

#Second Furnace Built (first phase)
country_event = {
	id = machine_age.3405
	title = "machine_age.3405.name"
	desc = "machine_age.3405.desc"
	picture = GFX_evt_arc_crucible
	show_sound = event_celebration
	location = from
	event_chain = ideal_furnace_chain

	is_triggered_only = yes

	trigger = {
		has_origin = origin_arc_welders
		NOT = {
			has_country_flag = second_furnace_built
		}
		years_passed > 0
	}

	immediate = {
		set_country_flag = second_furnace_built
		remove_point_of_interest = ideal_furnace_system
	}

	option = {
		name = EXCELLENT
		add_monthly_resource_mult = {
			resource = unity
			value = @tier1unityreward
			min = @tier1unitymin
			max = @tier1unitymax
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier3researchreward
			min = @tier3researchmin
			max = @tier3researchmax
		}
		add_tech_progress = {
			tech = tech_mega_engineering
			progress = 0.05
		}
	}

	after = {
		end_event_chain = ideal_furnace_chain
	}
}

# Set variable for Arc Furnace
country_event = {
	id = machine_age.3410
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_origin = origin_arc_welders
	}

	immediate = {
		change_variable = {
			which = arc_furnace_counter
			value = 1
		}
	}
}
