#######################################
# Pop Faction Events
# by Maximilian Olbers & Gemma Thomson
#######################################

@RecentFactionsEventTimer = 500 # days until this empire should be eligible for most other 'Faction Reacts' events
@RecentCommsTimer = 3600 # 10 years, during which parties are considered to have established communications recently

namespace = factions

# A faction is formed - filter toast or event
pop_faction_event = {
	hide_window = yes
	id = factions.0
	is_triggered_only = yes

	trigger = {
		NOT = {
			owner = {
				has_origin = origin_broken_shackles
			}
		}
	}

	immediate = {

		owner = {
			every_owned_planet = {
				every_owned_pop_group = {
					force_faction_evaluation = yes
				}
			}
			if = {
				limit = {
					NOT = {
						has_country_flag = first_faction
					}
				}
				set_country_flag = first_faction
				from = { pop_faction_event = { id = factions.1 } }
			}
			else = {
				from = {
					switch = {
						trigger = is_pop_faction_type
						traditionalist = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_TRADITIONALIST
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						imperialist = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_IMPERIALIST
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						supremacist = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_SUPREMACIST
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						isolationist = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_ISOLATIONIST
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						totalitarian = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_TOTALITARIAN
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						progressive = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_PROGRESSIVE
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						prosperity = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_PROSPERITY
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						technologist = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_TECHNOLOGIST
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						xenoist = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_XENOIST
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
						manifesti = {
							root.owner = {
								create_faction_formed_message = {
									FACTION_TYPE = MESSAGE_FACTION_MANIFESTI
									FACTION_INTRO = factions.1.desc.start_short
								}
							}
						}
					}
				}
			}
		}

	}
}

# A faction is formed - toast
# A faction is formed - toast (standard version)
pop_faction_event = {
	id = factions.1
	title = factions.1.title
	desc = {
		trigger = {
			# Intro
			success_text = {
				text = factions.1.desc.start
				hidden:owner = { NOT = { has_origin = origin_unplugged } }
			}
			success_text = {
				text = factions.1.desc.unplugged_start
				hidden:owner = { has_origin = origin_unplugged }
			}
			text = newline
			# Body text (standard Factions with variants based on e.g. Origin)
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = imperialist
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = isolationist
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = progressive
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = prosperity
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = supremacist
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = technologist
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = totalitarian
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = traditionalist
			}
			inline_script = {
				script = pop_faction_types/faction1_desc
				FACTION = xenoist
			}
			# Body text (other, exempt Factions)
			success_text = {
				text = factions.1.desc.manifesti
				is_pop_faction_type = manifesti
			}
			# Outro
			success_text = {
				text = factions.1.desc.fire_cult
				is_pop_faction_type = fire_cult
			}
			success_text = {
				hidden:owner = { NOT = { has_country_flag = first_faction } }
				text = factions.1.desc.firstfinisher
			}
		}
	}
	picture = GFX_evt_galactic_senate
	show_sound = event_factions
	is_triggered_only = yes

	option = {
		name = OK
		hidden_effect = {
			owner = {
				every_owned_planet = {
					every_owned_pop_group = {
						force_faction_evaluation = yes
					}
				}
			}
		}
	}
}

# Killed Guardian
country_event = {
	id = factions.10
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		from = {
			is_guardian_country = yes
		}
	}

	immediate = {
		set_country_flag = killed_guardian
	}
}

# Established comms
# via on_post_communications_established | this = country which established the communications; from = country communications were established with
country_event = {
	id = factions.11
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			is_country_type = default
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
			is_country_type = marauder_raiders
			is_country_type = enclave
			AND = {
				is_country_type = primitive
				current_awareness_level = full
			}
		}
		from = {
			is_country_type = default
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = recent_comms_timed
			days = @RecentCommsTimer
		}
		from = {
			set_timed_country_flag = {
				flag = recent_comms_timed
				days = @RecentCommsTimer
			}
		}
	}
}

# Invaded primitives
country_event = {
	id = factions.12
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = { is_country_type = primitive }
		is_country_type = default
	}

	immediate = {
		set_timed_country_flag = {
			flag = recent_primitive_invasion
			days = 7200 # 20 years
		}
	}
}

# Beginning war as either attacker or defender. Fires from on_war_beginning (from = war) and on_entering_war (from = opposing leader).
country_event = {
	id = factions.13
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_war = {
			limit = {
				OR = {
					is_same_value = from
					any_war_participant = { is_same_value = from }
				}
			}
			if = {
				limit = { is_war_participant = { who = root side = attackers } }
				root = {
					set_timed_country_flag = {
						flag = entered_war_as_attacker
						days = 7200 # 20 years
					}
				}
			}
			else_if = {
				limit = { is_war_participant = { who = root side = defenders } }
				root = {
					set_timed_country_flag = {
						flag = entered_war_as_defender
						days = 7200 # 20 years
					}
				}
			}
		}
	}
}

# Remove Factions-specific modifiers if the world changes owners
# via on_colony_transfer = {}
carrier_event = {
	id = factions.15
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { has_modifier = planet_political_frontier }
			remove_modifier = planet_political_frontier
		}
		if = {
			limit = { has_modifier = planet_political_safezone }
			remove_modifier = planet_political_safezone
		}
		if = {
			limit = { has_modifier = planet_political_crackdown }
			remove_modifier = planet_political_crackdown
		}
		if = {
			limit = { has_modifier = planet_political_admittance }
			remove_modifier = planet_political_admittance
		}
	}
}

# Xenoist Uplift Demand
# via on_uplift_completion = {}
carrier_event = {
	id = factions.1005
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = {
			set_timed_country_flag = {
				flag = recent_uplift_timed
				days = 7200 # 20 years
			}
		}
	}
}

# Notification event - other empire shifts ethics
country_event = {
	id = factions.2000
	title = factions.2000.title
	location = event_target:TargetFaction.Owner.capital_scope

	picture = GFX_evt_alien_propaganda
	show_sound = event_factions
	hide_window = yes
	is_triggered_only = yes

	immediate = {

		event_target:TargetFaction = {
			switch = {
				trigger = is_pop_faction_type
				imperialist = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_IMPERIALIST
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				supremacist = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_SUPREMACIST
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				isolationist = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_ISOLATIONIST
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				totalitarian = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_TOTALITARIAN
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				progressive = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_PROGRESSIVE
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				prosperity = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_PROSPERITY
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				technologist = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_TECHNOLOGIST
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				xenoist = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_XENOIST
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
				fire_cult = {
					root = {
						create_faction_shifted_message = {
							FACTION_TYPE = MESSAGE_FACTION_EMBRACED_FIRE_CULT
							FACTION_INTRO = factions.2000.desc_short
						}
					}
				}
			}
		}
	}
}

# The PoliticaL Frontier
# via on_colony_[1/2]_years_old = {} | this = colony world
carrier_event = {
	id = factions.3000
	title = factions.3000.name
	desc = factions.3000.desc
	picture = GFX_evt_alien_propaganda
	show_sound = event_factions
	location = this
	is_triggered_only = yes

	trigger = {
		owner = {
			is_regular_empire = yes
			NOR = {
				has_country_flag = recent_factions_event
				has_country_flag = factions_political_frontier
			}
			count_pop_faction = {
				count > 1
			}
		}
	}

	immediate = {
		owner = {
			set_timed_country_flag = {
				flag = recent_factions_event
				days = @RecentFactionsEventTimer
			}
			set_country_flag = factions_political_frontier
		}
	}

	# Carry on (standard)
	option = {
		name = INTERESTING
		trigger = {
			owner = {
				NOR = {
					is_democratic_authority = yes
					is_authoritarian = yes
				}
			}
		}
		add_modifier = {
			modifier = planet_political_frontier
			years = 10
		}
	}
	# Carry on (Democracy)
	option = {
		name = factions.3000.a.demo
		trigger = {
			owner = {
				is_democratic_authority = yes
			}
		}
		add_modifier = {
			modifier = planet_political_frontier
			years = 10
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier1unityreward
				min = @tier1unitymin
				max = @tier1unitymax
			}
		}
		carrier_event = {
			id = factions.3010
			days = 200
		}
	}
	# Carry on (Authoritarian)
	option = {
		name = factions.3000.a.auth
		trigger = {
			owner = {
				is_authoritarian = yes
			}
		}
		add_modifier = {
			modifier = planet_political_frontier
			years = 5
		}
		carrier_event = {
			id = factions.3005
			days = 200
		}
	}
	# Shut this down (standard)
	option = {
		name = factions.3000.b
		trigger = {
			owner = {
				NOR = {
					is_democratic_authority = yes
					has_valid_civic = civic_police_state
					is_authoritarian = yes
				}
			}
		}
		add_modifier = {
			modifier = planet_political_safezone
			years = 10
		}
	}
	# Shut this down (Authoritarian)
	option = {
		name = factions.3000.b.auth
		trigger = {
			owner = {
				OR = {
					is_authoritarian = yes
					has_valid_civic = civic_police_state
				}
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = unity
					value >= 250
				}
			}
		}
		owner = {
			add_resource = {
				unity = -250
			}
		}
		add_modifier = {
			modifier = planet_political_crackdown
			years = 40
		}
	}
}

# The Political Frontier: Authoritarian Infiltration
# this = colony world
carrier_event = {
	id = factions.3005
	title = factions.3005.name
	desc = {
		trigger = {
			NOR = {
				has_carrier_flag = frontier_egalitarianism
				has_carrier_flag = frontier_alternatives
			}
		}
		text = factions.3005.desc.1
	}
	desc = {
		trigger = {
			has_carrier_flag = frontier_egalitarianism
		}
		text = factions.3005.desc.2
	}
	desc = {
		trigger = {
			has_carrier_flag = frontier_alternatives
		}
		text = factions.3005.desc.3
	}
	picture = {
		trigger = {
			NOR = {
				has_carrier_flag = frontier_egalitarianism
				has_carrier_flag = frontier_alternatives
			}
		}
		picture = GFX_evt_spymaster
	}
	picture = {
		trigger = {
			OR = {
				has_carrier_flag = frontier_egalitarianism
				has_carrier_flag = frontier_alternatives
			}
		}
		picture = GFX_evt_space_monster # tendrils
	}
	show_sound = event_factions
	location = this
	is_triggered_only = yes

	trigger = {
		has_modifier = planet_political_frontier # would have been removed if the planet changed owner since the preceding event
		owner = {
			count_pop_faction = {
				count > 1
			}
		}
	}

	immediate = {
		if = { # Egalitarianism has taken root
			limit = {
				count_owned_pop_amount = {
					limit = {
						is_egalitarian = yes
					}
					count > 0
				}
			}
			set_carrier_flag = frontier_egalitarianism
		}
		else_if = { # Other, unsupported ethics are present
			limit = {
				count_owned_pop_amount = {
					limit = {
						has_alternative_ethics = {
							THIS_SCOPE = this
							REF_SCOPE = root.owner
						}
					}
					count > 100
				}
			}
			set_carrier_flag = frontier_alternatives
		}
		# else: Political harmony
	}

	# Political harmony: acknowledge
	option = {
		name = EXCELLENT
		trigger = {
			NOR = {
				has_carrier_flag = frontier_egalitarianism
				has_carrier_flag = frontier_alternatives
			}
		}
		remove_modifier = planet_political_frontier
	}
	# Political harmony: commendations
	option = {
		name = factions.3005.a
		trigger = {
			NOR = {
				has_carrier_flag = frontier_egalitarianism
				has_carrier_flag = frontier_alternatives
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= 300
				}
			}
		}
		owner = {
			add_resource = {
				energy = -300
			}
			add_monthly_resource_mult = {
				resource = unity
				value = @tier1unityreward
				min = @tier1unitymin
				max = @tier1unitymax
			}
		}
		remove_modifier = planet_political_frontier
	}
	# Political deviance: useful insights
	option = {
		name = EXCELLENT
		trigger = {
			OR = {
				has_carrier_flag = frontier_egalitarianism
				has_carrier_flag = frontier_alternatives
			}
		}
		remove_modifier = planet_political_frontier
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
		add_modifier = { # planet modifier
			modifier = promoted_authoritarian
			years = 10
		}
	}
	# Political deviance: perhaps it's okay?
	option = {
		name = {
			trigger = { has_carrier_flag = frontier_egalitarianism }
			text = factions.3005.b
		}
		name = {
			trigger = { has_carrier_flag = frontier_alternatives }
			text = factions.3005.c
		}
		trigger = {
			OR = {
				has_carrier_flag = frontier_egalitarianism
				has_carrier_flag = frontier_alternatives
			}
			owner = {
				is_fanatic_authoritarian = no
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
		remove_modifier = planet_political_frontier
		add_modifier = { # planet modifier
			modifier = planet_political_admittance
			years = 30
		}
	}

	after = {
		remove_carrier_flag = frontier_egalitarianism
		remove_carrier_flag = frontier_alternatives
	}
}

# The Political Frontier: Democratic Report
# this = colony world
carrier_event = {
	id = factions.3010
	title = factions.3005.name
	desc = {
		trigger = {
			NOR = {
				has_carrier_flag = frontier_authoritarianism
				has_carrier_flag = frontier_discourse
			}
		}
		text = factions.3010.desc.1
	}
	desc = {
		trigger = {
			has_carrier_flag = frontier_authoritarianism
		}
		text = factions.3010.desc.2
	}
	desc = {
		trigger = {
			has_carrier_flag = frontier_discourse
		}
		text = factions.3010.desc.3
	}
	picture = {
		trigger = {
			NOT = { has_carrier_flag = frontier_authoritarianism }
		}
		picture = GFX_evt_civil_action
	}
	picture = {
		trigger = {
			has_carrier_flag = frontier_authoritarianism
		}
		picture = GFX_evt_space_monster # tendrils
	}
	show_sound = event_factions
	location = this
	is_triggered_only = yes

	trigger = {
		has_modifier = planet_political_frontier # would have been removed if the planet changed owner since the preceding event
		owner = {
			count_pop_faction = {
				count > 1
			}
		}
	}

	immediate = {
		if = { # Authoritarianism has taken root
			limit = {
				count_owned_pop_amount = {
					limit = {
						is_authoritarian = yes
					}
					count > 0
				}
			}
			set_carrier_flag = frontier_authoritarianism
		}
		else_if = { # Diverse ethics are present (mutually exclusive with above)
			limit = {
				count_owned_pop_amount = {
					limit = {
						has_alternative_ethics = {
							THIS_SCOPE = this
							REF_SCOPE = root.owner
						}
					}
					count >= 300
				}
			}
			set_carrier_flag = frontier_discourse
		}
		# else: Status quo
	}

	# Status quo: acknowledge
	option = {
		name = GOOD
		trigger = {
			NOR = {
				has_carrier_flag = frontier_authoritarianism
				has_carrier_flag = frontier_discourse
			}
		}
		remove_modifier = planet_political_frontier
	}
	# Status quo: encourage radical thought
	option = {
		name = factions.3010.a
		trigger = {
			NOR = {
				has_carrier_flag = frontier_authoritarianism
				has_carrier_flag = frontier_discourse
			}
		}
		remove_modifier = planet_political_frontier
		add_modifier = { # planet modifier
			modifier = planet_political_admittance
			years = 30
		}
	}
	# Diverse politics OR Authoritarianism taking root: useful insights
	option = {
		name = factions.3010.b
		trigger = {
			OR = {
				has_carrier_flag = frontier_discourse
				has_carrier_flag = frontier_authoritarianism
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		custom_tooltip = factions.3010.frontier.tt # informing that planet_political_frontier will remain in place
	}
	# Diverse politics OR Authoritarianism taking root: too risky
	option = {
		name = {
			trigger = { has_carrier_flag = frontier_authoritarianism }
			text = factions.3010.c
		}
		name = {
			trigger = { has_carrier_flag = frontier_discourse }
			text = factions.3010.d
		}
		trigger = {
			OR = {
				has_carrier_flag = frontier_discourse
				has_carrier_flag = frontier_authoritarianism
			}
			owner = {
				NOT = {
					is_fanatic_egalitarian = yes
				}
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		remove_modifier = planet_political_frontier
		add_modifier = { # planet modifier
			modifier = planet_political_safezone
			years = 20
		}
	}

	after = {
		remove_carrier_flag = frontier_authoritarianism
		remove_carrier_flag = frontier_discourse
	}
}

####################
# Manifesti Destiny
# By Gemma Thomson
####################

namespace = manifesti

# Triggered by chance from on_five_year_pulse = {}
carrier_event = {
	id = manifesti.1
	title = manifesti.1.name
	desc = manifesti.1.desc
	picture = GFX_evt_tradestation_interior
	show_sound = event_celebration
	location = root
	event_chain = manifesti_chain

	is_triggered_only = yes

	pre_triggers = {
		has_owner = yes
		is_occupied_flag = no
	}

	trigger = {
		years_passed > 10
		any_country = {
			NOT = { has_country_flag = manifesti_spawned }
		}
		owner = {
			is_ai = no
			is_regular_empire = yes
			num_communications > 1
			has_country_flag = Story7 #has finished first contact
			is_at_war = no
			NOR = {
				is_homicidal = yes
				is_fanatic = yes
				has_valid_civic = civic_warrior_culture #Keeps entertainers
				has_valid_civic = civic_dystopian_society
				has_origin = origin_legendary_leader
				has_origin = origin_legendary_leader_imperial
				has_origin = origin_legendary_leader_dictatorial
				has_origin = origin_common_ground
				has_country_flag = manifesti_spawned
			}
		}
		OR = {
			has_building = building_holo_theatres
			has_building = building_hyper_entertainment_forum
			has_building = building_autochthon_monument
			has_building = building_corporate_monument
			has_building = building_noble_estates
			has_building = building_commercial_zone
		}
	}

	immediate = {
		save_event_target_as = manifesti_world
		owner = {
			set_country_flag = manifesti_spawned
			random_list = {
				33 = { set_country_flag = manifesti_physics }
				33 = { set_country_flag = manifesti_society }
				33 = { set_country_flag = manifesti_engineering }
			}
		}
	}
	option = { # Take no action
		name = manifesti.1.a
		begin_event_chain = {
			event_chain = manifesti_chain
			target = owner
		}
		add_modifier = {
			modifier = planet_manifesti_polarization
			days = 1095
		}
		hidden_effect = {
			carrier_event = { id = manifesti.5 days = 59 }
		}
	}
	option = { # Encourage participation
		name = manifesti.1.b
		begin_event_chain = {
			event_chain = manifesti_chain
			target = owner
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier1unityreward
				min = @tier1unitymin
				max = @tier1unitymax
			}
		}
		add_modifier = {
			modifier = planet_manifesti_joy
			days = 720
		}
		hidden_effect = {
			carrier_event = { id = manifesti.5 days = 59 }
		}
	}
	option = { # Pacify the dissenters
		name = manifesti.1.c
		trigger = {
			owner = {
				has_ethic = ethic_authoritarian
			}
		}
		allow = {
			owner = {
				has_resource = { type = minerals amount >= 1000 }
			}
		}
		owner = {
			add_resource = { minerals = -1000 }
		}
		custom_tooltip = manifesti.1.tt
	}
	option = { # Authorize brute force
		name = manifesti.1.d
		trigger = {
			owner = {
				has_ethic = ethic_militarist
			}
		}
		allow = {
			owner = {
				has_resource = { type = energy amount >= 1000 }
			}
		}
		owner = {
			add_resource = { energy = -1000 }
		}
		custom_tooltip = manifesti.1.tt
	}
	option = { # Organize a counter protest
		name = manifesti.1.e
		trigger = {
			owner = {
				has_ethic = ethic_xenophile
			}
		}
		allow = {
			owner = {
				has_unity_times_empire_size = { VALUE = 1 }
				has_resource = { type = consumer_goods amount > 100 }
			}
		}
		owner = {
			add_unity_times_empire_size = { VALUE = -1 }
			add_resource = { consumer_goods = -100 }
		}
		custom_tooltip = manifesti.1.tt
	}
	option = { # Flood the streets with unity rallies
		name = manifesti.1.f
		trigger = {
			owner = {
				has_ethic = ethic_egalitarian
			}
		}
		allow = {
			owner = {
				has_unity_times_empire_size = { VALUE = 1 }
				has_resource = { type = influence amount > 50 }
			}
		}
		owner = {
			add_unity_times_empire_size = { VALUE = -1 }
			add_resource = { influence = -50 }
		}
		custom_tooltip = manifesti.1.tt
	}
option = { # Organize a counter protest
	name = manifesti.1.g
	trigger = {
		owner = {
			has_ethic = ethic_pacifist
		}
	}
	allow = {
		owner = {
			has_unity_times_empire_size = { VALUE = 2 }
		}
	}
	owner = {
		add_unity_times_empire_size = { VALUE = -2 }
	}
	custom_tooltip = manifesti.1.tt
	}
	option = { # Frame it as a distraction
	name = manifesti.1.h
		trigger = {
			owner = {
				OR = {
					has_ethic = ethic_materialist
					has_ethic = ethic_spiritualist
				}
			}
		}
		allow = {
			if = {
				limit = {
					owner = {
						has_ethic = ethic_materialist
					}
				}
				owner = {
					resource_stockpile_compare = { resource = alloys value > 100 }
					resource_stockpile_compare = { resource = energy value > 500 }
				}
			}
			if = {
				limit = {
					owner = {
						has_ethic = ethic_spiritualist
					}
				}
				owner = {
					resource_stockpile_compare = { resource = influence value > 100 }
				}
			}
		}
		owner = {
			if = {
				limit = {
					has_ethic = ethic_materialist
				}
				add_resource = { alloys = -100 }
				add_resource = { energy = -500 }
			}
			if = {
				limit = {
					has_ethic = ethic_spiritualist
				}
				add_resource = { influence = -100 }
			}
		}
		custom_tooltip = manifesti.1.tt
	}
}

# Protests cease; the group is named
carrier_event = {
	id = manifesti.5
	title = manifesti.5.name
	desc = manifesti.5.desc
	picture = GFX_evt_city_planet
	show_sound = event_cityscape
	location = root
	event_chain = manifesti_chain

	is_triggered_only = yes

	pre_triggers = {
		is_occupied_flag = no
	}

	trigger = {
		owner = { has_event_chain = "manifesti_chain" }
	}

	immediate = {
		owner = {
			add_event_chain_counter = {
				event_chain = "manifesti_chain"
				counter = "manifesti_rise"
				amount = 1
			}
			random_owned_planet = {
				limit = { pop_amount > 700 }
				save_event_target_as = manifesti_world #Can be the same world as ROOT if needs be
			}
			#Reroll manifesti tech for Crowdsourcing
			remove_country_flag = manifesti_physics
			remove_country_flag = manifesti_society
			remove_country_flag = manifesti_engineering
			random_list = {
				33 = { set_country_flag = manifesti_physics }
				33 = { set_country_flag = manifesti_society }
				33 = { set_country_flag = manifesti_engineering }
			}
		}
	}

	option = { # Let them have their fun
		name = manifesti.5.a
		if = {
			limit = {
				owner = {
					is_egalitarian = yes
				}
			}
			event_target:manifesti_world = {
				add_modifier = {
					modifier = planet_manifesti_egalitarian_attraction
					days = 1095
				}
			}
		}
		if = {
			limit = {
				owner = {
					is_pacifist = yes
				}
			}
			event_target:manifesti_world = {
				add_modifier = {
					modifier = planet_manifesti_pacifist_attraction
					days = 1095
				}
			}
		}
		if = {
			limit = {
				owner = {
					is_xenophile = yes
				}
			}
			event_target:manifesti_world = {
				add_modifier = {
					modifier = planet_manifesti_xenophile_attraction
					days = 1095
				}
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				carrier_event = { id = manifesti.15 days = 245 }
			}
		}
	}
	option = { # Declare Martial Law
		name = manifesti.5.b
		trigger = {
			owner = {
				is_militarist = yes
			}
		}
		allow = {
			NOR = {
				has_modifier = martial_law
				has_modifier = martial_law_knights
			}
			owner = {
				has_resource = { type = influence amount > 50 }
			}
		}
		owner = {
			add_resource = {
				influence = -50
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				set_carrier_flag = manifesti_militarist_successful
				carrier_event = { id = manifesti.10 days = 93 }
			}
		}
	}
	option = { # Melt down the projects for resources
		name = manifesti.5.c
		trigger = {
			owner = {
				is_materialist = yes
			}
		}
		allow = {
			owner = {
				has_resource = { type = influence amount > 50 }
			}
		}
		owner = {
			add_resource = {
				influence = -50
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				set_carrier_flag = manifesti_materialist_successful
				carrier_event = { id = manifesti.10 days = 93 }
			}
		}
	}
	option = { # Declare them messengers of the void
		name = manifesti.5.d
		trigger = {
			owner = {
				is_spiritualist = yes
			}
		}
		allow = {
			owner = {
				has_resource = { type = influence amount > 50 }
			}
		}
		owner = {
			add_resource = {
				influence = -50
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				set_carrier_flag = manifesti_spiritualist_successful
				carrier_event = { id = manifesti.10 days = 93 }
			}
		}
	}
	option = { # Disrupt planet wide communications
		name = manifesti.5.e
		trigger = {
			owner = {
				is_xenophobe = yes
			}
		}
		allow = {
			owner = {
				has_resource = { type = influence amount > 50 }
			}
		}
		owner = {
			add_resource = {
				influence = -50
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				set_carrier_flag = manifesti_xenophobe_successful
				carrier_event = { id = manifesti.10 days = 93 }
			}
		}
	}
	option = { # Locate and detain their families
		name = manifesti.5.f
		allow = {
			owner = {
				has_resource = { type = influence amount > 50 }
			}
		}
		owner = {
			add_resource = {
				influence = -50
			}
		}
		random_list = {
			25 = {
				modifier = {
					factor = 100
					owner = {
						is_authoritarian = yes
					}
				}
				event_target:manifesti_world = {
					set_carrier_flag = manifesti_authoritarian_successful
				}
				custom_tooltip = manifesti.5.f.tt1
			}
			75 = {
				event_target:manifesti_world = {
					set_carrier_flag = manifesti_violent_protests
				}
				custom_tooltip = manifesti.5.f.tt2
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				carrier_event = { id = manifesti.10 days = 93 }
			}
		}
	}
}

# Nipped in the Bud
carrier_event = {
	id = manifesti.10
	title = manifesti.10.name
	desc = {
		trigger = {
			has_carrier_flag = manifesti_militarist_successful
		}
		text = manifesti.10.desc_militarist
	}
	desc = {
		trigger = {
			has_carrier_flag = manifesti_materialist_successful
		}
		text = manifesti.10.desc_materialist
	}
	desc = {
		trigger = {
			has_carrier_flag = manifesti_spiritualist_successful
		}
		text = manifesti.10.desc_spiritualist
	}
	desc = {
		trigger = {
			has_carrier_flag = manifesti_xenophobe_successful
		}
		text = manifesti.10.desc_xenophobe
	}
	desc = {
		trigger = {
			has_carrier_flag = manifesti_authoritarian_successful
		}
		text = manifesti.10.desc_authoritarian
	}
	desc = {
		trigger = {
			has_carrier_flag = manifesti_dismantled_exhibition
		}
		text = manifesti.10.desc_dismantled_exhibition
	}
	desc = {
		trigger = {
			has_carrier_flag = manifesti_violent_protests
		}
		text = manifesti.10.desc_violent_protests
	}
	picture = GFX_evt_surreal_visions
	show_sound = event_mystic_reveal
	location = root
	event_chain = manifesti_chain

	is_triggered_only = yes

	pre_triggers = {
		is_occupied_flag = no
	}

	trigger = {
		owner = { has_event_chain = "manifesti_chain" }
	}

	immediate = {
		owner = {
			add_event_chain_counter = {
				event_chain = "manifesti_chain"
				counter = "manifesti_rise"
				amount = 1
			}
		}
	}

	option = {
		name = manifesti.10.a
		trigger = {
			NOT = {
				has_carrier_flag = manifesti_violent_protests
			}
		}
		switch = {
			trigger = has_carrier_flag
			manifesti_militarist_successful = {
				if = {
					limit = { has_knights_zone = yes }
					add_modifier = {
						modifier = martial_law_knights
						days = 3650
					}
				}
				else = {
					add_modifier = {
						modifier = martial_law
						days = 3650
					}
				}
				owner = {
					add_monthly_resource_mult = {
						resource = unity
						value = @tier3influencereward
						min = @tier3influencemin
						max = @tier3influencemax
					}
				}
			}
			manifesti_materialist_successful = {
				owner = {
					add_monthly_resource_mult = {
						resource = consumer_goods
						value = @tier2materialreward
						min = @tier2materialmin
						max = @tier2materialmax
					}
					add_resource = {
						alloys = -100
					}
				}
			}
			manifesti_spiritualist_successful = {
				owner = {
					create_leader = {
						name = random
						species = root
						class = scientist
						event_leader = yes
						set_age = 31
						randomize_traits = no
						background_ethic = ethic_xenophobe
						custom_description = manifesti_leader_desc
						effect = {
							set_skill = 6
						}
						traits = {
							1 = leader_trait_lavish_lifestyle
						}
					}
					last_created_leader = {
						save_global_event_target_as = manifesti_leader
						set_leader_flag = manifesti_divine_leader
						set_owner = root
					}
				}
			}
			manifesti_xenophobe_successful = {
				add_modifier = {
					modifier = planet_manifesti_network_disrupted
					days = 3650
				}
			}
			manifesti_authoritarian_successful = {
				add_modifier = {
					modifier = planet_manifesti_widespread_arrests
					days = 3650
				}
			}
			manifesti_dismantled_exhibition = {
				add_modifier = {
				modifier = planet_manifesti_exhibition_shutdown
				days = 3650
				}
			}
		}
		remove_modifier = planet_manifesti_joy
		owner = { end_event_chain = manifesti_chain }
	}
	option = {
		name = manifesti.10.b
		trigger = {
			has_carrier_flag = manifesti_violent_protests
		}
		remove_modifier = planet_manifesti_joy
		add_planet_devastation = 75
		owner = { end_event_chain = manifesti_chain }
	}
}

# Manifesti language takes root
carrier_event = {
	id = manifesti.15
	title = manifesti.15.name
	desc = manifesti.15.desc
	picture = GFX_evt_smugglers_in_bar
	show_sound = event_cityscape
	location = root
	event_chain = manifesti_chain

	is_triggered_only = yes

	trigger = {
		owner = { has_event_chain = "manifesti_chain" }
	}

	immediate = {
		owner = {
			add_event_chain_counter = {
				event_chain = "manifesti_chain"
				counter = "manifesti_rise"
				amount = 1
			}
			random_owned_planet = { #Manifesti spreads
				limit = {
					pop_amount > 700
				}
				save_event_target_as = manifesti_world #Can be the same world as ROOT if needs be
				add_modifier = { modifier = planet_manifesti_uslurp_mod days = 1095 }
			}
			#Reroll manifesti tech for Crowdsourcing
			remove_country_flag = manifesti_physics
			remove_country_flag = manifesti_society
			remove_country_flag = manifesti_engineering
			random_list = {
				33 = { set_country_flag = manifesti_physics }
				33 = { set_country_flag = manifesti_society }
				33 = { set_country_flag = manifesti_engineering }
			}
		}
	}

	option = { # Buy their silence
		name = manifesti.15.a
		allow = {
			owner = {
				has_resource = { type = energy amount >= 1000 }
			}
		}
		owner = {
			add_resource = { energy = -1000 }
		}

		hidden_effect = {
			event_target:manifesti_world = {
				remove_modifier = planet_manifesti_uslurp_mod
				carrier_event = { id = manifesti.20 days = 145 }
			}
		}
	}
	option = { # Withhold pay from nonconformists
		name = manifesti.15.b
		tooltip = {
			event_target:manifesti_world = {
				add_modifier = { modifier = planet_manifesti_uslurp_mod days = 1095 }
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				carrier_event = { id = manifesti.20 days = 145 }
			}
		}
	}
	option = { # Partake in the trend
		name = manifesti.15.c
		trigger = {
			owner = {
				is_egalitarian = yes
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				carrier_event = { id = manifesti.20 days = 145 }
			}
		}
	}
	option = { # Celebrate linguistic diversity
		name = manifesti.15.d
		trigger = {
			owner = {
				is_xenophile = yes
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				carrier_event = { id = manifesti.20 days = 145 }
			}
		}
	}
	option = { # Foster dialogue, not division
		name = manifesti.15.e
		trigger = {
			owner = {
				is_pacifist = yes
			}
		}
		hidden_effect = {
			event_target:manifesti_world = {
				carrier_event = { id = manifesti.20 days = 145 }
			}
		}
	}
}

# Manifesti exhibition
carrier_event = {
	id = manifesti.20
	title = manifesti.20.name
	desc = manifesti.20.desc
	picture = GFX_evt_surreal_visions
	show_sound = event_mystic_reveal
	location = root
	event_chain = manifesti_chain

	is_triggered_only = yes

	trigger = {
		owner = { has_event_chain = "manifesti_chain" }
	}

	immediate = {
		owner = {
			add_event_chain_counter = {
				event_chain = "manifesti_chain"
				counter = "manifesti_rise"
				amount = 1
			}
			#Reroll manifesti tech for Crowdsourcing
			remove_country_flag = manifesti_physics
			remove_country_flag = manifesti_society
			remove_country_flag = manifesti_engineering
			random_list = {
				33 = { set_country_flag = manifesti_physics }
				33 = { set_country_flag = manifesti_society }
				33 = { set_country_flag = manifesti_engineering }
			}
		}
	}

	option = { #Let them continue
		name = manifesti.20.a
		owner = {
			add_modifier = {
				modifier = manifesti_reflections_mod
				days = 720
			}
			give_specimen = { key = manifesti_piece }
		}
		hidden_effect = {
			carrier_event = { id = manifesti.25 days = 156 }
		}
	}
	option = { # exhibition dismantled
		name = manifesti.20.b
		set_carrier_flag = manifesti_dismantled_exhibition
		hidden_effect = {
			carrier_event = { id = manifesti.10 days = 93 }
		}
	}
}

# Rumours of a new faction
carrier_event = {
	id = manifesti.25
	title = manifesti.25.name
	desc = manifesti.25.desc
	picture = GFX_evt_announcement
	show_sound = event_factions
	location = owner.capital_scope
	is_triggered_only = yes
	event_chain = manifesti_chain

	trigger = {
		owner = { has_event_chain = "manifesti_chain" }
	}

	immediate = { }

	option = { # It was inevitable
		name = manifesti.25.a
		hidden_effect = {
			owner = {
				country_event = { id = manifesti.26 days = 20 } #Forces evaluation of the Manifesti faction
			}
		}
		custom_tooltip = manifesti.25.tt
	}
	option = { # Embrace it
		name = manifesti.25.b
		owner = {
			every_owned_planet = {
				add_modifier = {
				modifier = planet_manifesti_endorsed
				days = 3650
				}
			}
			hidden_effect = {
				country_event = { id = manifesti.26 days = 20 } #Forces evaluation of the Manifesti faction
			}
		}
		custom_tooltip = manifesti.25.tt
	}

	option = { # Declare them outlaws
		name = manifesti.25.c
		owner = {
			every_owned_planet = {
				add_modifier = {
				modifier = planet_manifesti_supressed
				days = 9125
				}
			}
		}
	}

	after = {
		owner = {
			set_timed_country_flag = { flag = manifesti_faction days = 955 } #Matches faction on_create, plus some of the evaluation event delay above
		}
	}
}

country_event = {
	id = manifesti.26
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		enable_faction_of_type = manifesti
	}
}

# Manifesti faction in decline (via faction on_destroy OR faction on_create + time delay | from = pop_faction )
country_event = {
	id = manifesti.30
	title = manifesti.30.name
	desc = manifesti.30.desc
	picture = GFX_evt_galactic_senate
	show_sound = event_factions
	location = capital_scope
	is_triggered_only = yes
	event_chain = manifesti_chain

	trigger = {
		OR = {
			NOT = {
				any_pop_faction = { is_pop_faction_type = manifesti }
			}
			any_pop_faction = {
				is_pop_faction_type = manifesti
				faction_approval < 0.35
			}
		}
		NOT = {
			has_country_flag = manifesti_decline
		}
	}

	immediate = {
		set_country_flag = manifesti_decline #Can force removal of the faction even if the timed "manifesti_faction" flag remains active
		every_owned_pop_group = {
			limit = {
				OR = { #Those eligible to join the faction (in lieu of a has_faction trigger for pops)
					is_egalitarian = yes
					is_xenophile = yes
					is_pacifist = yes
				}
			}
			set_pop_group_flag = manifesti_bored
		}
	}

	option = {
		name = manifesti.30.a
		add_modifier = {
			modifier = manifesti_sweet_dreams_mod
			days = 2880 #8 years
		}
		add_resource = { society_research = 1800 }
		end_event_chain = manifesti_chain
	}
	option = {
		name = manifesti.30.b
		exclusive_trigger = {
			OR = {
				is_authoritarian = yes
				is_militarist = yes
				is_xenophobe = yes
			}
		}
		add_modifier = {
			modifier = manifesti_sweet_dreams_mod
			days = 1440 #4 years
		}
		add_resource = { society_research = 1800 }
		end_event_chain = manifesti_chain
	}
}
