﻿country_decisions = {
	# Adopt Necromancy, usual limits not applied so only direct costs in allow
	adopt_necro = {
		potential = {
			num_of_cities >= 1
			NOT = {
				RELIGION = undead_pantheon
			}
		}
		allow = {
			stability >= 50
			political_influence >= 200
			
		}
		effect = {
			change_religion_effect = {
				RELIGION = undead_pantheon
			}
		}
		ai_will_do = {
			base = 0
		}
	}

	# Create First Undead City, cost of holy site, in capital
	necro_capital = {
		potential = {
			RELIGION = undead_pantheon
			NOT = {
				has_variable = necro_capital_founded
			}
		}
		allow = {
			#cost of holy site, must be city
			stability >= 50
			political_influence >= 50
			treasury >= 300
			capital_scope = {
				OR = {
					has_city_status = yes
					has_province_rank = city_metropolis
				}
			}
			
		}
		effect = {
			set_variable = necro_capital_founded
			add_treasury = -300
			add_political_influence = -50
			add_stability = -30
			add_country_modifier = {
				name = necromancy_i
				duration = -1
			}
			capital_scope = {
				add_permanent_province_modifier = {
					name = undead_city
					duration = -1
				}
				#set new trade good, to allow rabble
				set_trade_goods = necromantic_energy
				#kill half the population, then convert and assimilate the rest. The 50 percent return rate is going to be the standard approach here.
				while = {
					count = {
						value = 0
						add = total_population
						divide = 2
					}
					random_pops_in_province = {
						kill_pop = yes
					}
				}
				every_pops_in_province = {
					limit = {
						NOT = { pop_culture = undead }
					}
					set_pop_culture = undead
				}
				every_pops_in_province = {
					limit = {
						NOT = { pop_religion = undead_pantheon }
					}
					set_pop_religion = undead_pantheon
				}
			}
		}
		ai_will_do = {
			base = 0
		}
	}
	#strengthen necromantic power via set of 4 decisions, order not required so OR and IF system to upgrade by steps
	#Integrate Undead.
	necro_strength1 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_i
				has_country_modifier = necromancy_ii
				has_country_modifier = necromancy_iii
				has_country_modifier = necromancy_iv
			}
			NOT = {
				has_variable = necro_strength1
			}
		}
		allow = {
			any_integrated_culture = { is_culture = undead }
		}
		effect = {
			set_variable = necro_strength1
			if = {
				limit = {
					has_country_modifier = necromancy_iv
				}
				remove_country_modifier = necromancy_iv
				add_country_modifier = {
					name = necromancy_v
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_iii
				}
				remove_country_modifier = necromancy_iii
				add_country_modifier = {
					name = necromancy_iv
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_ii
				}
				remove_country_modifier = necromancy_ii
				add_country_modifier = {
					name = necromancy_iii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_i
				}
				remove_country_modifier = necromancy_i
				add_country_modifier = {
					name = necromancy_ii
					duration = -1
				}
			}
		}
	}
	#Undead Legions. TODO register that it's units in legions.
	necro_strength2 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_i
				has_country_modifier = necromancy_ii
				has_country_modifier = necromancy_iii
				has_country_modifier = necromancy_iv
			}
			NOT = {
				has_variable = necro_strength2
			}
		}
		allow = {
			OR = {
				has_law = work_for_the_best
				has_law = standing_army_law
				has_law = republican_recruitment_2
				has_law = republican_recruitment_4
				has_law = punic_reforms
				has_law = marian_reforms
			}
			num_of_unit_type = {
				type = undead_rabble
				value >= 5
			}
		}
		effect = {
			set_variable = necro_strength2
			if = {
				limit = {
					has_country_modifier = necromancy_iv
				}
				remove_country_modifier = necromancy_iv
				add_country_modifier = {
					name = necromancy_v
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_iii
				}
				remove_country_modifier = necromancy_iii
				add_country_modifier = {
					name = necromancy_iv
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_ii
				}
				remove_country_modifier = necromancy_ii
				add_country_modifier = {
					name = necromancy_iii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_i
				}
				remove_country_modifier = necromancy_i
				add_country_modifier = {
					name = necromancy_ii
					duration = -1
				}
			}
		}
	}
	#Undead metropolis.
	necro_strength3 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_i
				has_country_modifier = necromancy_ii
				has_country_modifier = necromancy_iii
				has_country_modifier = necromancy_iv
			}
			NOT = {
				has_variable = necro_strength3
			}
		}
		allow = {
			capital_scope = {
				has_province_rank = city_metropolis
				has_province_modifier = undead_city
				total_population >= 80
			}
		}
		effect = {
			set_variable = necro_strength3
			if = {
				limit = {
					has_country_modifier = necromancy_iv
				}
				remove_country_modifier = necromancy_iv
				add_country_modifier = {
					name = necromancy_v
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_iii
				}
				remove_country_modifier = necromancy_iii
				add_country_modifier = {
					name = necromancy_iv
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_ii
				}
				remove_country_modifier = necromancy_ii
				add_country_modifier = {
					name = necromancy_iii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_i
				}
				remove_country_modifier = necromancy_i
				add_country_modifier = {
					name = necromancy_ii
					duration = -1
				}
			}
		}
	}
	#Necromantic Faith.
	necro_strength4 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_i
				has_country_modifier = necromancy_ii
				has_country_modifier = necromancy_iii
				has_country_modifier = necromancy_iv
			}
			NOT = {
				has_variable = necro_strength4
			}
		}
		allow = {
			AND = {
				custom_tooltip = {
					text = common_necromantic_faith_tooltip
					religion_pops_in_country = {
						target = undead_pantheon
						value >= 5
					}
				}
				custom_tooltip = {
					text = necro_pantheon_tooltip
					any_pantheon_deity = {
						count = 4
						deity_religion = undead_pantheon
					}
				}
				NOT = {
					has_country_modifier = recent_convert_modifier
				}
			}
		}
		effect = {
			set_variable = necro_strength4
			if = {
				limit = {
					has_country_modifier = necromancy_iv
				}
				remove_country_modifier = necromancy_iv
				add_country_modifier = {
					name = necromancy_v
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_iii
				}
				remove_country_modifier = necromancy_iii
				add_country_modifier = {
					name = necromancy_iv
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_ii
				}
				remove_country_modifier = necromancy_ii
				add_country_modifier = {
					name = necromancy_iii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_i
				}
				remove_country_modifier = necromancy_i
				add_country_modifier = {
					name = necromancy_ii
					duration = -1
				}
			}
		}
	}
	#Get multiple (10 or more) undead cities to advance.
	necro_strength5 = {
		potential = {
			RELIGION = undead_pantheon
			has_country_modifier = necromancy_v
		}
		allow = {
			any_owned_province = {
				count >= 10
				has_province_modifier = undead_city
			}
		}
		effect = {
			remove_country_modifier = necromancy_v
			add_country_modifier = {
				name = necromancy_vi
				duration = -1
			}
		}
	}
	#strengthen necromantic power via set of 4 decisions, order not required so OR and IF system to upgrade by steps
	#Necromantic Nexus, so lots of necromantic energy produced and a great work installed
	necro_strength6 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_vi
				has_country_modifier = necromancy_vii
				has_country_modifier = necromancy_viii
				has_country_modifier = necromancy_ix
			}
			NOT = {
				has_variable = necro_strength6
			}
		}
		allow = {
			capital_scope = {
				has_great_work = yes
				trade_goods = necromantic_energy
				num_goods_produced >= 5
			}
		}
		effect = {
			set_variable = necro_strength6
			if = {
				limit = {
					has_country_modifier = necromancy_ix
				}
				remove_country_modifier = necromancy_ix
				add_country_modifier = {
					name = necromancy_x
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_viii
				}
				remove_country_modifier = necromancy_viii
				add_country_modifier = {
					name = necromancy_ix
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vii
				}
				remove_country_modifier = necromancy_vii
				add_country_modifier = {
					name = necromancy_viii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vi
				}
				remove_country_modifier = necromancy_vi
				add_country_modifier = {
					name = necromancy_vii
					duration = -1
				}
			}
		}
	}
	#Necromantic exultation, immortal deified king
	necro_strength7 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_vi
				has_country_modifier = necromancy_vii
				has_country_modifier = necromancy_viii
				has_country_modifier = necromancy_ix
			}
			NOT = {
				has_variable = necro_strength7
			}
		}
		allow = {
			current_ruler = {
				is_deified = yes
				has_trait = lichking
			}
		}
		effect = {
			set_variable = necro_strength7
			if = {
				limit = {
					has_country_modifier = necromancy_ix
				}
				remove_country_modifier = necromancy_ix
				add_country_modifier = {
					name = necromancy_x
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_viii
				}
				remove_country_modifier = necromancy_viii
				add_country_modifier = {
					name = necromancy_ix
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vii
				}
				remove_country_modifier = necromancy_vii
				add_country_modifier = {
					name = necromancy_viii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vi
				}
				remove_country_modifier = necromancy_vi
				add_country_modifier = {
					name = necromancy_vii
					duration = -1
				}
			}
		}
	}
	#United in Necromancy, converting 1/3 of territories to Necromantic
	necro_strength8 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_vi
				has_country_modifier = necromancy_vii
				has_country_modifier = necromancy_viii
				has_country_modifier = necromancy_ix
			}
			NOT = {
				has_variable = necro_strength8
			}
		}
		allow = {
			any_owned_province = {
				count >= {
					value = num_of_cities
					divide = 3
				}
				dominant_province_religion = undead_pantheon
			}
		}
		effect = {
			set_variable = necro_strength8
			if = {
				limit = {
					has_country_modifier = necromancy_ix
				}
				remove_country_modifier = necromancy_ix
				add_country_modifier = {
					name = necromancy_x
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_viii
				}
				remove_country_modifier = necromancy_viii
				add_country_modifier = {
					name = necromancy_ix
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vii
				}
				remove_country_modifier = necromancy_vii
				add_country_modifier = {
					name = necromancy_viii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vi
				}
				remove_country_modifier = necromancy_vi
				add_country_modifier = {
					name = necromancy_vii
					duration = -1
				}
			}
		}
	}
	#Rural Expansion
	necro_strength9 = {
		potential = {
			RELIGION = undead_pantheon
			OR = {
				has_country_modifier = necromancy_vi
				has_country_modifier = necromancy_vii
				has_country_modifier = necromancy_viii
				has_country_modifier = necromancy_ix
			}
			NOT = {
				has_variable = necro_strength9
			}
		}
		allow = {
			always = yes
			any_owned_province = {
				count >= 10
				has_building = basic_settlement_infratructure_building
			}
			any_owned_province = {
				count >= 10
				has_building = slave_mine_building
			}
			any_owned_province = {
				count >= 10
				has_building = latifundia_building
			}
		}
		effect = {
			set_variable = necro_strength9
			if = {
				limit = {
					has_country_modifier = necromancy_ix
				}
				remove_country_modifier = necromancy_ix
				add_country_modifier = {
					name = necromancy_x
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_viii
				}
				remove_country_modifier = necromancy_viii
				add_country_modifier = {
					name = necromancy_ix
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vii
				}
				remove_country_modifier = necromancy_vii
				add_country_modifier = {
					name = necromancy_viii
					duration = -1
				}
			}
			if = {
				limit = {
					has_country_modifier = necromancy_vi
				}
				remove_country_modifier = necromancy_vi
				add_country_modifier = {
					name = necromancy_vii
					duration = -1
				}
			}
		}
	}
	#spells. Opens spell window
	necro_open_casting = {
		potential = {
			religion = undead_pantheon
		}
		allow = {
			always = yes
		}
		effect = {
			trigger_event = necro_spellcasting.1
		}
		ai_will_do = {
			base = 0
		}
	}
	# utility for testing effects.
	#money, stab, PI for getting the ball rolling
	necro_tester = {
		potential = {
			always = no
		}
		allow = {
			always = yes
		}
		effect = {
			add_treasury = 5000
			add_stability = 50
			add_political_influence = 400
		}
		ai_will_do = {
			base = 0
		}
	}
	#adding necromancy abilities
	necro_tester_2 = {
		potential = {
			always = no
		}
		allow = {
			always = yes
		}
		effect = {
			add_country_modifier = {
				name = necromancy_vi
				duration = -1
			}
		}
		ai_will_do = {
			base = 0
		}
	}
	#for deification
	necro_tester_3 = {
		potential = {
			always = no
		}
		allow = {
			always = yes
		}
		effect = {
			add_stability = 50
			add_political_influence = 50
			add_legitimacy = 50
			current_ruler = {
				add_popularity = 100
			}
			every_family = {
				add_prestige = 600
			}
		}
		ai_will_do = {
			base = 0
		}
	}
}



