#example_mandate = {
#	
#	# This = Leader
#	valid = {
#		exists = pop_faction
#	}
#	
#	#parameters = {
#	##	name_of_parameter = type ( planet/pop/leader etc )
#	#	my_very_special_pop = pop
#	#}
#	
#	# This = Pop
#	# From = Leader
#	vote_weight = {
#		base = 10
#	}
#}
#
#test_mandate_2 = {
#	valid = {
#		owner = {
#			can_create_sector = parameter:sector_capital
#		}
#	}
#	
#	parameters = {
#		sector_capital = planet
#	}
#	
#	# This = Pop
#	# From = Leader
#	vote_weight = {
#		base = 10
#		modifier = {
#			add = 100
#			from = {
#				planet = {
#					is_same_value = parameter:sector_capital
#				}
#			}
#		}
#	}
#	
#	#This = Leader
#	on_leader_elected = {
#		owner = {
#			add_energy = 1337
#			create_sector = {
#				capital = parameter:sector_capital
#			}
#			#We probably want to make special projects from here
#		}
#	}
#	#This = Leader
#	on_leader_ousted = {
#		owner = {
#			add_energy = 1337
#		}
#	}
#}

# Planet Separatist Mandate - Grant independence to the planet
mandate_planet_separatist = {
	parameters = {
		planet = planet
	}
	
	valid = {
		exists = pop_faction
		pop_faction = { is_pop_faction_type = planet_separatists }
		parameter:planet = { is_capital = no }
	}
	
	vote_weight = {
		base = 0
		
		# Part of the faction
		modifier = {
			add = 60
			exists = pop_faction
			pop_faction = {
				is_pop_faction_type = planet_separatists
				check_pop_faction_parameter = {
					which = planet
					value = parameter:planet
				}
			}
		}
		
		# Xenophobes
		modifier = {
			add = 20
			not = {
				species = {
					from = {
						species = {
							is_same_value = prevprev
						}
					}
				}
			}
		}

		# Fanatic Xenophobes
		modifier = {
			add = 40
			not = {
				species = {
					from = {
						species = {
							is_same_value = prevprev
						}
					}
				}
			}
		}
	}
		
	on_leader_elected = {
		owner = {
			parameter:planet = {
				save_event_target_as = release_planet
			}
			begin_event_chain = {
				event_chain = mandate_separatist_chain
				target = this
			}
		}
		pop_faction = {
			set_pop_faction_flag = mandated_release
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
		pop_faction = {
			remove_pop_faction_flag = mandated_release
		}
	}	
}

# Emancipation Leader
mandate_emancipation = {
	valid = {
		owner = { any_owned_pop = { is_enslaved = yes } }
	}

	parameters = {}

	# This = Pop
	# From = Leader
	vote_weight = {
		base = 10
		# is slave
		modifier = {
			add = 90
			is_enslaved = yes
		}
		# same non-main species pop enslaved
		modifier = {
			add = 30
			owner = {
				any_owned_pop = {
					is_enslaved = yes
					is_same_species = root
					NOT = { is_same_species = owner_main_species }
				}
			}
		}
		# enslaved pop on planet, not collectivist
		modifier = {
			add = 20
			planet = {
				any_pop = {
					is_enslaved = yes
				}
			}
			NOT = {
				pop_has_ethic = ethic_fanatic_collectivist
				pop_has_ethic = ethic_collectivist
			}
		}
		# enslaved xenos, Xenophile
		modifier = {
			add = 20
			pop_has_ethic = ethic_xenophile
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# enslaved xenos, Fanatic Xenophile
		modifier = {
			add = 30
			pop_has_ethic = ethic_fanatic_xenophile
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# Fanatic Individualist
		modifier = {
			add = 30
			pop_has_ethic = ethic_fanatic_individualist
		}
		# Individualist
		modifier = {
			add = 20
			pop_has_ethic = ethic_individualist
		}
		# Fanatic Collectivist
		modifier = {
			add = -30
			pop_has_ethic = ethic_fanatic_collectivist
		}
		# Collectivist
		modifier = {
			add = -20
			pop_has_ethic = ethic_collectivist
		}
		# enslaved xenos, Xenophobe
		modifier = {
			add = -20
			pop_has_ethic = ethic_xenophobe
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# enslaved xenos, Fanatic Xenophobe
		modifier = {
			add = -30
			pop_has_ethic = ethic_fanatic_xenophobe
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# Decadent
		modifier = {
			add = -100
			pop_has_trait = trait_decadent
		}
	}

	# This = Leader
	on_leader_elected = {
		owner = {
			begin_event_chain = {
				event_chain = "mandate_emancipation_chain"
				target = this
			}
			country_event = { id = mandate.1 }

			# Detail event chain reward in comment here:
			# +300 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
	}
}

# Emancipation 2
mandate_emancipation2 = {
	valid = {
		owner = { any_owned_pop = { is_enslaved = yes } }
	}

	parameters = {}

	# This = Pop
	# From = Leader
	vote_weight = {
		base = 10
		# is slave
		modifier = {
			add = 90
			is_enslaved = yes
		}
		# same non-main species pop enslaved
		modifier = {
			add = 30
			owner = {
				any_owned_pop = {
					is_enslaved = yes
					is_same_species = root
					NOT = { is_same_species = owner_main_species }
				}
			}
		}
		# enslaved pop on planet, not collectivist
		modifier = {
			add = 20
			planet = {
				any_pop = {
					is_enslaved = yes
				}
			}
			NOT = {
				pop_has_ethic = ethic_fanatic_collectivist
				pop_has_ethic = ethic_collectivist
			}
		}
		# enslaved xenos, Xenophile
		modifier = {
			add = 20
			pop_has_ethic = ethic_xenophile
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# enslaved xenos, Fanatic Xenophile
		modifier = {
			add = 30
			pop_has_ethic = ethic_xenophile
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# Fanatic Individualist
		modifier = {
			add = 30
			pop_has_ethic = ethic_fanatic_individualist
		}
		# Individualist
		modifier = {
			add = 20
			pop_has_ethic = ethic_individualist
		}
		# Fanatic Collectivist
		modifier = {
			add = -30
			pop_has_ethic = ethic_fanatic_collectivist
		}
		# Collectivist
		modifier = {
			add = -20
			pop_has_ethic = ethic_collectivist
		}
		# enslaved xenos, Xenophobe
		modifier = {
			add = -20
			pop_has_ethic = ethic_xenophobe
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# enslaved xenos, Fanatic Xenophobe
		modifier = {
			add = -30
			pop_has_ethic = ethic_xenophobe
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					is_enslaved = yes
				}
			}
		}
		# Decadent
		modifier = {
			add = -100
			pop_has_trait = trait_decadent
		}
	}

	# This = Leader
	on_leader_elected = {
		owner = {
			country_event = { id = mandate.154 }
			country_event = { id = mandate.1 }
			# Detail event chain reward in comment here:
			# +300 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
	}
}

# Slaver, allow slavery
mandate_slaver = {
	valid = {
		owner = { has_technology = tech_ethical_equations }
	}

	parameters = {}

	# This = Pop
	# From = Leader
	vote_weight = {
		base = 10
		# Decadent
		modifier = {
			add = 50
			pop_has_trait = trait_decadent
		}
		# xeno pops in empire, xenophobe
		modifier = {
			add = 30
			is_same_species = root
			pop_has_ethic = ethic_xenophobe
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
				}
			}
		}
		# xeno pops in empire, fanatic xenophobe
		modifier = {
			add = 40
			is_same_species = root
			pop_has_ethic = ethic_fanatic_xenophobe
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
				}
			}
		}
		# Collectivist
		modifier = {
			add = 30
			pop_has_ethic = ethic_collectivist
		}
		# Fanatic Collectivist
		modifier = {
			add = 40
			pop_has_ethic = ethic_fanatic_collectivist
		}

		# Individualist
		modifier = {
			factor = 0.2
			pop_has_ethic = ethic_individualist
		}
		# Fanatic Individualist
		modifier = {
			factor = 0
			pop_has_ethic = ethic_fanatic_individualist
		}
		
		# Slavery is outlawed
		modifier = {
			factor = 0
			owner = {
				has_policy_flag = slavery_not_allowed
			}
		}		
	}

	# This = Leader
	on_leader_elected = {
		owner = {
			country_event = { id = mandate.1 }
			begin_event_chain = {
				event_chain = "mandate_slaver_chain"
				target = this
			}
			# Detail event chain reward in comment here:
			# +300 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
	}
}


#*** Orbital Researcher, build X research stations. on_building_research_station
mandate_orbital_researcher = {
	valid = {}
	parameters = {}

	vote_weight = {
		base = 20
		# Individualist
		modifier = {
			add = 20
			pop_has_ethic = ethic_individualist
		}
		# Fanatic Individualist
		modifier = {
			add = 40
			pop_has_ethic = ethic_fanatic_individualist
		}
		# Intelligant
		modifier = {
			add = 20
			pop_has_trait = trait_intelligent
		}
		# Naturally Inclined
		modifier = {
			add = 20
			OR = {
				pop_has_trait = trait_natural_engineers
				pop_has_trait = trait_natural_sociologists
				pop_has_trait = trait_natural_physicists
			}
		}
		# Low Research Income
		modifier = {
			add = 20
			owner = {
				OR = {
					has_monthly_income = {
						resource = engineering_research
						value < 16
					}
					has_monthly_income = {
						resource = physics_research
						value < 16
					}
					has_monthly_income = {
						resource = society_research
						value < 16
					}
				}
			}
		}
	}
	on_leader_elected = {
		owner = {
			begin_event_chain = {
				event_chain = "mandate_orbresearch_chain"
				target = this
			}
			country_event = { id = mandate.1 }
			# Detail event chain reward in comment here:
			# +300 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
	}
}

#*** Miner, build X mining stations. on_building_mining_station on-action
mandate_miner = {
	valid = {
		owner = { has_technology = tech_space_construction }
	}
	parameters = {}

	vote_weight = {
		base = 20
		# Materialist
		modifier = {
			add = 20
			pop_has_ethic = ethic_materialist
		}
		# Fanatic Materialist
		modifier = {
			add = 40
			pop_has_ethic = ethic_fanatic_materialist
		}
		# Industrious
		modifier = {
			add = 20
			pop_has_trait = trait_industrious
		}
		# Strong
		modifier = {
			add = 20
			OR = {
				pop_has_trait = trait_strong
			}
		}
		# Low Mineral Income
		modifier = {
			add = 20
			owner = {
				has_monthly_income = {
					resource = minerals
					value < 20
				}
			}
		}
		# Low Mineral Stockpiles
		modifier = {
			add = 20
			owner = {
				has_country_resource = {
					type = minerals
					amount < 400
				}
			}
		}
		# Similar ethics
		modifier = {
			add = 10
			opposing_ethics_divergence = {
				steps < 1
				who = from
			}
		}
	}

	on_leader_elected = {
		owner = {
			begin_event_chain = {
				event_chain = "mandate_miner_chain"
				target = this
			}
			country_event = { id = mandate.1 }
			# Detail event chain reward in comment here:
			# +300 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
	}
}

# Peacemaker Mandate, check if at peace in 4 years
mandate_peacemaker = {
	valid = {
		owner = {
			is_at_war = yes
			is_war_leader = yes
		}
	}

	parameters = {
		self = country
		enemy = country
	}

	vote_weight = {
		base = 20
		# Pacifist
		modifier = {
			add = 20
			pop_has_ethic = ethic_pacifist
		}
		# Fanatic Pacifist
		modifier = {
			add = 40
			pop_has_ethic = ethic_fanatic_pacifist
		}
		# No Federation
		modifier = {
			add = 10
			owner = {
				has_federation = no
			}
		}
		# No Allies
		modifier = {
			add = 30
			owner = {
				has_alliance = no
			}
		}
		# Xenophile
		modifier = {
			add = 20
			pop_has_ethic = ethic_xenophile
		}
		# Fanatic Xenophile
		modifier = {
			add = 30
			pop_has_ethic = ethic_fanatic_xenophile
		}
		# Militarist
		modifier = {
			add = -20
			pop_has_ethic = ethic_militarist
		}
		# Fanatic Pacifist
		modifier = {
			add = -40
			pop_has_ethic = ethic_fanatic_militarist
		}
	}

	on_leader_elected = {
		owner = {
			begin_event_chain = {
				event_chain = "mandate_peacemaker_chain"
				target = this
			}
			country_event = { id = mandate.1 }
			# Detail event chain reward in comment here:
			# +300 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.160 }
			#country_event = { id = mandate.2 }
		}
	}
}

#*** Shipwright, build X ships by year Y. count_ships trigger
mandate_shipwright = {

	valid = {}
	parameters = {}

	# This = Pop
	# From = Leader
	vote_weight = {
		base = 10
		# Militarist
		modifier = {
			add = 10
			pop_has_ethic = ethic_militarist
		}
		# Fanatic Materialist
		modifier = {
			add = 20
			pop_has_ethic = ethic_fanatic_militarist
		}
		# Few military ships
		modifier = {
			add = 15
			owner = {
				used_naval_capacity_percent < 0.3
			}
		}
		modifier = {
			factor = 2.1
			owner = {
				num_communications > 0
			}
		}
	}

	on_leader_elected = {
		owner = {
			begin_event_chain = {
				event_chain = "mandate_shipwright_chain"
				target = this
			}
			country_event = { id = mandate.1 }
			# Detail event chain reward in comment here:
			# +500 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.140 }
			#country_event = { id = mandate.2 }
		}
	}
}

#*** Xeno Purger, purge xenos from planet X. on_purge_complete
mandate_xenopurger = {
	valid = {
		owner = {
			any_owned_pop = {
				NOT = { is_same_species = owner_main_species }
			}
		}
	}

	parameters = {
		master = country
		planet = planet
	}

	# This = Pop
	# From = Leader
	vote_weight = {
		base = 20
		# Militarist
		modifier = {
			add = 10
			pop_has_ethic = ethic_militarist
		}
		# Fanatic Militarist
		modifier = {
			add = 20
			pop_has_ethic = ethic_militarist
		}
		# Xenophobe
		modifier = {
			add = 30
			pop_has_ethic = ethic_xenophobe
		}
		# Fanatic Xenophobe
		modifier = {
			add = 40
			pop_has_ethic = ethic_fanatic_xenophobe
		}
		# Other species repugnant
		modifier = {
			add = 30
			is_same_species = owner_main_species
			owner = {
				any_owned_pop = {
					NOT = { is_same_species = owner_main_species }
					pop_has_trait = trait_repugnant
				}
			}
		}	
	}

	on_leader_elected = {
		owner = {
			random_owned_planet = {
				limit = {
					any_pop = {
						NOT = { is_same_species = owner_main_species }
					}
				}
				save_event_target_as = purge_planet
				set_planet_flag = purge_planet
			}
			begin_event_chain = {
				event_chain = "mandate_xenopurge_chain"
				target = this
			}
			country_event = { id = mandate.1 }
			# Detail event chain reward in comment here:
			# +300 Influence
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
	}
}

# Nationalist Leader - Release nationalists X to parent empire
mandate_nationalist = {
	valid = {
		exists = pop_faction # is member of a faction
		pop_faction = { is_pop_faction_type = nationalist } # is nationalist
	}

	parameters = {
		country = country
	}

	# This = Pop
	# From = Leader
	vote_weight = {
		base = 15
		
		# Similar ethos to other empire
		modifier = {
			add = 15
			opposing_ethics_divergence = {
				steps < 2
				who = parameter:country
			}
		}
		
		# Lives on planet
		modifier = {
			factor = 2
			exists = pop_faction
			pop_faction = {
				is_pop_faction_type = nationalist
				check_pop_faction_parameter = {
					which = country
					value = parameter:country
				}
			}
		}
		
		# Is foreign pop
		modifier = {
			factor = 2
			is_same_species = parameter:country
		}
	}

	on_leader_elected = {
		owner = {
			parameter:country = { save_event_target_as = ceding_empire }
			begin_event_chain = {
				event_chain = mandate_nationalist_chain
				target = this
			}
			country_event = { id = mandate.1 }
			# Detail event chain reward in comment here:
			# +300 Influence
			# - Colony
			# + Positive relationship modifier with losing_country? TEMP?
		}
		pop_faction = {
			set_pop_faction_flag = mandated_ceding
		}
	}

	on_leader_ousted = {
		owner = {
			country_event = { id = mandate.2 }
		}
		pop_faction = {
			if = {
				limit = { has_pop_faction_flag = mandated_ceding }
				remove_pop_faction_flag = mandated_ceding
			}
		}
	}
}

# Uplifter, uplift species X on_uplift_completion on-action

# Slavery Proponent, enable slavery and enslave X pops

# Planet Builder, construct X number of buildings on planet Y by year Z

# Planet Builder variant, 0 free_building_tiles on planet X by year Y

# More Jobs, less than 3 pops unemployed by year X

# Fiscal Conservative, X energy in store by year Y

# Population Grower, 0 free_pop_tiles on planet X by year Y