###############################
# Pop Faction Events
# by Maximilian Olbers
###############################

namespace = factions

# A faction is formed
pop_faction_event = {
	id = factions.1
	title = factions.1.title
	desc = {
		trigger = {
			text = factions.1.desc.start
			text = newline
			success_text = {
				text = factions.1.desc.imperialist
				is_pop_faction_type = imperialist
			}
			success_text = {
				text = factions.1.desc.isolationist
				is_pop_faction_type = isolationist
			}
			success_text = {
				text = factions.1.desc.progressive
				is_pop_faction_type = progressive
			}
			success_text = {
				text = factions.1.desc.prosperity
				is_pop_faction_type = prosperity
			}
			success_text = {
				text = factions.1.desc.supremacist
				is_pop_faction_type = supremacist
			}
			success_text = {
				text = factions.1.desc.technologist
				is_pop_faction_type = technologist
			}
			success_text = {
				text = factions.1.desc.totalitarian
				is_pop_faction_type = totalitarian
			}
			success_text = {
				text = factions.1.desc.traditionalist
				is_pop_faction_type = traditionalist
			}
			success_text = {
				text = factions.1.desc.xenoist
				is_pop_faction_type = xenoist
			}
			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
	
	trigger = {
		#NOT = {
		#	owner = { has_country_flag = first_faction }
		#}
	}
	
	after = {
		hidden_effect = { owner = { set_country_flag = first_faction } }
	}

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

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

	trigger = {
		is_country_type = default
		from = {
			OR = {
				is_country_type = guardian
				is_country_type = guardian_dragon
				is_country_type = guardian_stellarite
				is_country_type = guardian_wraith
				is_country_type = guardian_hiver
				is_country_type = guardian_horror
				is_country_type = guardian_fortress
				is_country_type = guardian_dreadnought
				is_country_type = guardian_sphere
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = killed_guardian
			days = 1440 # 20 year
		}
	}
}

# Established comms
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
		}
		from = {
			is_country_type = default
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = recent_comms_timed
			days = 720 # 10 years
		}
		from = {
			set_timed_country_flag = {
				flag = recent_comms_timed
				days = 720 # 10 years
			}
		}
	}
}

# 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 = 1440 # 20 years
		}
	}
}

# Beginning war as either attacker or defender
country_event = {
	id = factions.13
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		from = {
			if = {
				limit = { is_war_participant = { who = root side = attackers } }
				root = {
					set_timed_country_flag = {
						flag = entered_war_as_attacker
						days = 1440 # 20 years
					}
				}
				else = {
					if = {
						limit = { is_war_participant = { who = root side = defenders } }
						root = {
							set_timed_country_flag = {
								flag = entered_war_as_defender
								days = 1440 # 20 years
							}
						}
					}
				}
			}
		}
	}
}

# Imperialist frontier outpost demand
#ship_event = {
#	id = factions.220
#	hide_window = yes
#	is_triggered_only = yes
#
#	immediate = {
#		owner = {
#			set_timed_country_flag = {
#				flag = imperialist_frontier_outpost_timed_flag
#				days = 1440 # 20 years
#			}
#		}
#	}
#}

# Industrialist Recent Monster Extermination
# This = owner of fleet 1 (combatant)
# From = owner of fleet 2 (destroyed)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
country_event = {
	id = factions.330
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		from = {
			OR = {
				is_country_type = crystal
				is_country_type = drone
				is_country_type = amoeba
				is_country_type = cloud
				is_country_type = pirate
			}
		}
		fromfrom.solar_system = {
			has_star_flag = hostile_system
			# count_ skips dead ships
			count_ships = {
				count < 1
				limit = {
					exists = owner
					owner = {
						OR = {
							is_country_type = crystal
							is_country_type = drone
							is_country_type = amoeba
							is_country_type = cloud
							is_country_type = pirate
						}
					}
				}
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = recent_monster_extermination_timed
			days = 720 # 10 years
		}
	}
}

# Xenoist 1000

# Xenoist Uplift Demand
planet_event = {
	id = factions.1005
	hide_window = yes
	is_triggered_only = yes

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

# Notification event - other empire shifts ethics
country_event = {
	id = factions.2000
	title = factions.2000.title
	location = TargetFaction.Owner.capital_scope
	desc = {
		trigger = {
			text = factions.2000.desc.start
			text = newline
			success_text = {
				text = factions.2000.desc.imperialist
				event_target:TargetFaction = { is_pop_faction_type = imperialist }
			}
			success_text = {
				text = factions.2000.desc.isolationist
				event_target:TargetFaction = { is_pop_faction_type = isolationist }
			}
			success_text = {
				text = factions.2000.desc.progressive
				event_target:TargetFaction = { is_pop_faction_type = progressive }
			}
			success_text = {
				text = factions.2000.desc.prosperity
				event_target:TargetFaction = { is_pop_faction_type = prosperity }
			}
			success_text = {
				text = factions.2000.desc.supremacist
				event_target:TargetFaction = { is_pop_faction_type = supremacist }
			}
			success_text = {
				text = factions.2000.desc.technologist
				event_target:TargetFaction = { is_pop_faction_type = technologist }
			}
			success_text = {
				text = factions.2000.desc.totalitarian
				event_target:TargetFaction = { is_pop_faction_type = totalitarian }
			}
			success_text = {
				text = factions.2000.desc.traditionalist
				event_target:TargetFaction = { is_pop_faction_type = traditionalist }
			}
			success_text = {
				text = factions.2000.desc.xenoist
				event_target:TargetFaction = { is_pop_faction_type = xenoist }
			}
		}
	}

	picture = GFX_evt_alien_propaganda
	show_sound = event_factions

	is_triggered_only = yes

	option = {
		name = OK
	}
}