namespace = dpe_election_events

#Ideas and basic text for events 15, 20, 30, 40 and follow-ups are by Leylos

country_event = {
	id = dpe_election_events.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		NOT = {
			is_gestalt = yes
		}
		exists = ruler
	}

	immediate = {
		ruler = {
			set_timed_leader_flag = {
				flag = dpe_incumbent_ruler
				years = 1
			}
		}
	}
}

country_event = {
	id = dpe_election_events.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		#don't see what benefit there is to the AI having these events
		is_ai = no
		
		#remove if adding new events for other authorities
		is_democratic_authority = yes
		
		NOT = {
			is_gestalt = yes
		}
		ruler = {
			NOR = {
				has_leader_flag = dpe_incumbent_ruler
				has_ethic = ethic_egalitarian
			}
		}
		NOT = {
			has_country_flag = dpe_recent_election_scandal
		}

		count_pop_faction = {
			count > 2
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = dpe_recent_election_scandal
			years = 50
		}
		switch = {
			trigger = has_authority
			auth_democratic = {
				random_list = {
					1 = { #fallback if nothing else is possible
					}
					30 = {
						country_event = { id = dpe_election_events.10 days = 5 }

						modifier = {
							factor = 0
							NAND = {
								OR = {
									has_faction = supremacist
									has_faction = isolationist
								}
								ruler = {
									OR = {
										has_ethic = ethic_spiritualist
										has_ethic = ethic_authoritarian
										has_ethic = ethic_xenophobe
									}
								}
								NAND = {
									ruler = {
										has_ethic = ethic_spiritualist
									}
									is_spiritualist = yes
								}
							}
						}
						modifier = {
							factor = 0.25
							has_country_flag = dpe_has_had_trump
						}
					}
					10 = {
						country_event = { id = dpe_election_events.15 days = 5 }

						modifier = {
							factor = 0
							num_owned_planets = 1
						}
					}
				}
			}
			auth_strict_democratic = {
				random_list = {
					1 = { #fallback if nothing else is possible
					}
					30 = {
						country_event = { id = dpe_election_events.10 days = 5 }

						modifier = {
							factor = 0
							NAND = {
								OR = {
									has_faction = supremacist
									has_faction = isolationist
								}
								ruler = {
									OR = {
										has_ethic = ethic_spiritualist
										has_ethic = ethic_authoritarian
										has_ethic = ethic_xenophobe
									}
								}
								NAND = {
									ruler = {
										has_ethic = ethic_spiritualist
									}
									is_spiritualist = yes
								}
							}
						}
						modifier = {
							factor = 0.25
							has_country_flag = dpe_has_had_trump
						}
					}
					10 = {
						country_event = { id = dpe_election_events.15 days = 5 }

						modifier = {
							factor = 0
							num_owned_planets = 1
						}
					}
				}
			}
			auth_dict_democratic = {
				random_list = {
					1 = { #fallback if nothing else is possible
					}
					30 = {
						country_event = { id = dpe_election_events.10 days = 5 }

						modifier = {
							factor = 0
							NAND = {
								OR = {
									has_faction = supremacist
									has_faction = isolationist
								}
								ruler = {
									OR = {
										has_ethic = ethic_spiritualist
										has_ethic = ethic_authoritarian
										has_ethic = ethic_xenophobe
									}
								}
								NAND = {
									ruler = {
										has_ethic = ethic_spiritualist
									}
									is_spiritualist = yes
								}
							}
						}
						modifier = {
							factor = 0.25
							has_country_flag = dpe_has_had_trump
						}
					}
					10 = {
						country_event = { id = dpe_election_events.15 days = 5 }

						modifier = {
							factor = 0
							num_owned_planets = 1
						}
					}
				}
			}
			auth_direct_democratic = {
				random_list = {
					1 = { #fallback if nothing else is possible
					}
					30 = {
						country_event = { id = dpe_election_events.10 days = 5 }

						modifier = {
							factor = 0
							NAND = {
								OR = {
									has_faction = supremacist
									has_faction = isolationist
								}
								ruler = {
									OR = {
										has_ethic = ethic_spiritualist
										has_ethic = ethic_authoritarian
										has_ethic = ethic_xenophobe
									}
								}
								NAND = {
									ruler = {
										has_ethic = ethic_spiritualist
									}
									is_spiritualist = yes
								}
							}
						}
						modifier = {
							factor = 0.25
							has_country_flag = dpe_has_had_trump
						}
					}
					10 = {
						country_event = { id = dpe_election_events.15 days = 5 }

						modifier = {
							factor = 0
							num_owned_planets = 1
						}
					}
				}
			}
			#I have removed them for now as the current ideas are not good enough to be implemented without significant work
			auth_oligarchic = {
#				country_event = { id = dpe_election_events.20 days = 5 }
			}
			auth_dictatorial = {
#				country_event = { id = dpe_election_events.30 days = 5 }
			}
			auth_imperial = {
#				country_event = { id = dpe_election_events.40 days = 5 }
			}
			default = {
			}
		}
	}
}



#Trump
country_event = {
	id = dpe_election_events.10
	title = dpe_election_events.10.name
	desc = dpe_election_events.10.desc
	picture = GFX_evt_alien_segregation

	is_triggered_only = yes

	immediate = {
		set_country_flag = dpe_has_had_trump
	}

	option = { #Crackdown
		name = dpe_election_events.10.A

		add_modifier = { #+50% authoritarianism, +30% governing ethics, -25% unity
			modifier = dpe_political_crackdown
			days = 1800
		}

		every_pop_faction = {
			limit = {
				NOR = {
					is_pop_faction_type = isolationist
					is_pop_faction_type = supremacist
					is_pop_faction_type = traditionalist
					is_pop_faction_type = totalitarian
				}
			}
			add_modifier = { #-15% happiness
				modifier = dpe_political_crackdown_faction
				days = 1800
			}
		}

		allow = {
			NOT = {
				has_ethic = ethic_fanatic_egalitarian
			}
		}
	}
	option = { #Tolerate this
		name = dpe_election_events.10.B

		every_pop_faction = {
			limit = {
				NOR = {
					is_pop_faction_type = isolationist
					is_pop_faction_type = supremacist
					is_pop_faction_type = traditionalist
					is_pop_faction_type = totalitarian
				}
			}
			add_modifier = { #-10 happiness
				modifier = dpe_upset_intolerant_ruler_faction
				days = 1800
			}
		} 
	}
	
	option = { #Step down, new elections
		name = dpe_election_events.10.C

		custom_tooltip = CCREMOVERULER.tooltip

		ruler = {
			hidden_effect = {
				kill_leader = {
					show_notification = no
				}
			}
		} 
	}
}


#Election Fixing
country_event = {
	id = dpe_election_events.15
	title = dpe_election_events.15.name
	desc = dpe_election_events.15.desc
	picture = GFX_evt_arguing_senate

	is_triggered_only = yes

	immediate = {
		random_owned_leader = {
			limit = {
				is_councilor = no
				NOT = { is_same_value = root.ruler }
				NOT = { has_same_ethics = { SCOPE1 = this SCOPE2 = root.ruler } }
			}
			save_event_target_as = dpe_election_scandal_accuser
		}
		random_owned_planet = {
			limit = { NOT = { is_same_value = root.capital_scope } }
			save_event_target_as = dpe_election_scandal_planet
		}
	}

	option = {
		name = dpe_election_events.15.A

		add_modifier = { #governing ethics attraction -25%, -10% happiness, +50% authoritarianism
			modifier = dpe_disillusioned_with_democracy
			days = 3600
		}
	}
	option = {
		name = dpe_election_events.15.B

		hidden_effect = { ruler = { save_event_target_as = dpe_scandal_ruler } }
		
		random_list = {
			1 = { #name cleared
				custom_tooltip = dpe_election_events.15.B.1
				hidden_effect = { country_event = { id = dpe_election_events.16 days = 20 } }
			}
			1 = { #found guilty
				custom_tooltip = dpe_election_events.15.B.2
				hidden_effect = { country_event = { id = dpe_election_events.17 days = 20 } }
			}
		}
	}
}

country_event = {
	id = dpe_election_events.16
	title = dpe_election_events.16.name
	desc = dpe_election_events.16.desc
	picture = GFX_evt_arguing_senate

	is_triggered_only = yes

	trigger = {
		exists = event_target:dpe_scandal_ruler
		ruler = { is_same_value = event_target:dpe_scandal_ruler }
	}

	option = {
		name = dpe_election_events.16.option

		custom_tooltip = dpe_election_events.16.tooltip #[dpe_election_scandal_accuser.GetName] is removed from the game.

		event_target:dpe_election_scandal_accuser = {
			root = {
				random_pop_faction = {
					limit = { has_same_ethics = { SCOPE1 = this SCOPE2 = event_target:dpe_election_scandal_accuser } }
					add_modifier = {
						modifier = dpe_election_scandal_upset_faction
						years = 5
					}
				}
			}
			hidden_effect = { kill_leader = { show_notification = no } }
		}
	}
}

country_event = {
	id = dpe_election_events.17
	title = dpe_election_events.17.name
	desc = dpe_election_events.17.desc
	picture = GFX_evt_arguing_senate

	is_triggered_only = yes

	trigger = {
		exists = event_target:dpe_scandal_ruler
		ruler = { is_same_value = event_target:dpe_scandal_ruler }
	}

	option = {
		name = dpe_election_events.17.option

		custom_tooltip = CCREMOVERULER.tooltip

		add_modifier = {
			modifier = dpe_election_scandal_upset
			years = 10
		}
		hidden_effect = {
			ruler = {
				kill_leader = {
					show_notification = no
				}
			}
		}
	}
}



country_event = {
	id = dpe_election_events.80
	title = dpe_election_events.80.name
	desc = dpe_election_events.80.desc
	picture = GFX_evt_arguing_senate

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		NOT = {
			is_gestalt = yes
		}
		ruler? = {
			NOT = {
				has_leader_flag = dpe_incumbent_ruler
			}
		}
		NOT = {
			has_country_flag = dpe_recent_election_positive
		}

		any_pop_faction = {
			support > 0.1
			faction_approval < @cc_faction_danger_number
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = dpe_recent_election_positive
			years = 400
		}
	}

	option = {
		name = EXCELLENT

		add_modifier = {
			modifier = dpe_election_unifying_candidate
			years = 5
		}
		
		every_pop_faction = {
			limit = {
				faction_approval < @cc_faction_danger_number
			}
			add_modifier = {
				modifier = dpe_election_unifying_candidate_faction
				years = 5
			}
		}
	}
}
