clear_unbinding_effect = {
	clr_character_flag = unbinding_cheap_open
	clr_character_flag = unbinding_middle_open
	clr_character_flag = unbinding_grand_open
	clr_character_flag = unbinding_cheap_festivities
	clr_character_flag = unbinding_middle_festivities
	clr_character_flag = unbinding_grand_festivities
	clr_character_flag = unbinding_festival_open
	clr_character_flag = festival_event_happened
	clr_character_flag = ancrel_remove_firedancers
	clr_character_flag = unbinding_festival
	clr_character_flag = do_not_disturb
	remove_character_modifier = holding_unbinding_festival
}

clear_nile_flooding_effect = {
	remove_province_modifier = VIET_nile_flood_good
	remove_province_modifier = VIET_nile_flood_great
	remove_province_modifier = VIET_nile_flood_overflow
	remove_province_modifier = VIET_nile_flood_poor
}

banish_to_monastery_effect = {
	# expand this to allow banishing to a random holy order
	# should one exist for the (liege's?) religion
	add_ascetic_trait_effect = yes
	liege = {
		random_realm_lord = {
			limit = { is_theocracy = yes }

			move_character = PREVPREV
		}
	}
}

# reduces prosperity by 3 levels, adding depopulation if necessary
devestate_province_effect = {
	decrease_prosperity_effect = yes
	decrease_prosperity_effect = yes
	decrease_prosperity_effect = yes
}

decrease_prosperity_effect = {
	### Depopulated Provinces
	if = {
		limit = { has_province_modifier = depopulated_2	}
		hidden_tooltip = { remove_province_modifier = depopulated_2 }
		add_province_modifier = { name = depopulated_3 duration = -1 }
		hidden_tooltip = {
			clr_province_flag = recent_depopulation_2
			set_province_flag = recent_depopulation_3
		}
	}
	if = {
		limit = { has_province_modifier = depopulated_1 }
		hidden_tooltip = { remove_province_modifier = depopulated_1 }
		add_province_modifier = { name = depopulated_2 duration = -1 }
		hidden_tooltip = {
			clr_province_flag = recent_depopulation_1
			set_province_flag = recent_depopulation_2
		}
	}

	### Unmodified Province
	if = {
		limit = {
			NOR = {
				is_prosperous_trigger = yes
				is_depopulated_trigger = yes
			}
		}
		add_province_modifier = { name = depopulated_1 duration = -1 }
		set_province_flag = recent_depopulation_1
	}

	### Prosperous Provinces
	if = {
		limit = { has_province_modifier = prosperity_modifier_1 }
		
		remove_province_modifier = prosperity_modifier_1
		hidden_tooltip = { set_variable = { which = prosperity_value value = 0 } }
	}
	if = {
		limit = { has_province_modifier = prosperity_modifier_2	}

		hidden_tooltip = { remove_province_modifier = prosperity_modifier_2 }
		add_province_modifier = { name = prosperity_modifier_1 duration = -1 }
		hidden_tooltip = { set_variable = { which = prosperity_value value = 100 } }
	}
	if = {
		limit = { has_province_modifier = prosperity_modifier_3 }

		hidden_tooltip = { remove_province_modifier = prosperity_modifier_3 }
		add_province_modifier = { name = prosperity_modifier_2 duration = -1 }
		hidden_tooltip = { set_variable = { which = prosperity_value value = 250 } }
	}
}

# requires event targets donor_province and receiver_province
# receiver_province must have province flag received_<one/two/three>_prosperity
random_province_conversion_from_colonists_effect = {
	event_target:receiver_province = {
		random_list = {
			15 = { # both religion and culture
				modifier = {
					factor = 1.2
					any_neighbor_province = {
						culture = event_target:donor_province
					}
				}
				modifier = {
					factor = 1.2
					any_neighbor_province = {
						religion = event_target:donor_province
					}
				}
				modifier = {
					factor = 2
					has_province_flag = received_two_prosperity
				}
				modifier = {
					factor = 5
					has_province_flag = received_three_prosperity
				}

				culture = event_target:donor_province
				religion = event_target:donor_province
			}
			20 = { # culture
				modifier = {
					factor = 1.2
					any_neighbor_province = {
						culture = event_target:donor_province
					}
				}
				modifier = {
					factor = 1.5
					has_province_flag = received_two_prosperity
				}
				modifier = {
					factor = 2
					has_province_flag = received_three_prosperity
				}

				culture = event_target:donor_province
			}
			25 = { # religion
				modifier = {
					factor = 1.2
					any_neighbor_province = {
						religion = event_target:donor_province
					}
				}
				modifier = {
					factor = 1.5
					has_province_flag = received_two_prosperity
				}
				modifier = {
					factor = 2
					has_province_flag = received_three_prosperity
				}

				religion = event_target:donor_province
			}
			50 = { # nothing!
			}
		}

		clr_province_flag = received_one_prosperity
		clr_province_flag = received_two_prosperity
		clr_province_flag = received_three_prosperity
	}
}

create_diplomacy_mystic_effect = {
	random_list = {
		25 = {
			create_character = {
				random_traits = no
				name = "Idunn"
				dna = chaehghfacw
				dynasty = none
				religion = norse_pagan
				culture = norse
				female = yes
				age = 17
				health = 15
				trait = grey_eminence
				trait = gregarious
				trait = mystic
				trait = lustful
				trait = charitable
				trait = fair
				trait = trusting
				trait = poet
			}
		}
		25 = {
			create_character = {
				random_traits = no
				name = "Nestor"
				dynasty = none
				religion = hellenic_pagan
				culture = greek
				female = no
				age = 62
				health = 15
				trait = grey_eminence
				trait = gregarious
				trait = mystic
				trait = charitable
				trait = fair
				trait = trusting
				trait = poet
			}
		}
	}
	new_character = {
		set_character_flag = eternal_life_mystic 

		will_not_marry_effect = yes

		if = {
			limit = {
				is_female = yes
			}
			give_nickname = nick_the_youthful
			set_character_flag = immortal_mystic_idunn
		} 
		else = {
			give_nickname = nick_the_wise
			set_character_flag = immortal_mystic_nestor
		}
		random_list = {
			90 = {
				set_character_flag = mystic_is_fraud
			}
			10 = {
				modifier = {
					factor = 1.4
					FROM = { diplomacy = 10 }
				}
				modifier = {
					factor = 1.4
					FROM = { diplomacy = 13 }
				}
				modifier = {
					factor = 1.4
					FROM = { diplomacy = 16 }
				}
				modifier = {
					factor = 1.4
					FROM = { diplomacy = 19 }
				}
				modifier = {
					factor = 1.4
					FROM = { diplomacy = 22 }
				}
				
				change_diplomacy = 6
			}
		}
		save_event_target_as = eternal_life_mystic
	}
}

create_martial_mystic_effect = {
	random_list = {
		25 = {
			create_character = {
				random_traits = no
				dynasty = none
				religion = west_african_pagan
				culture = manden
				female = yes
				age = 36
				health = 15
				trait = brilliant_strategist
				trait = mystic
				trait = robust
				trait = wroth
				trait = diligent
				trait = proud
				trait = brave
				trait = aggressive_leader
			}
		}
		25 = {
			create_character = {
				random_traits = no
				dynasty = none
				religion = celtic_pagan
				culture = gaulish
				female = no
				age = 36
				health = 15
				trait = brilliant_strategist
				trait = mystic
				trait = robust
				trait = wroth
				trait = diligent
				trait = proud
				trait = brave
				trait = light_foot_leader
			}
		}
		25 = {
			create_character = {
				random_traits = no
				dynasty = none
				religion = hellenic_pagan
				culture = greek
				female = no
				age = 31
				health = 15
				trait = brilliant_strategist
				trait = mystic
				trait = robust
				trait = wroth
				trait = diligent
				trait = proud
				trait = brave
				trait = heavy_infantry_leader
			}
		}
	}
	new_character = {
		set_character_flag = eternal_life_mystic 

		will_not_marry_effect = yes

		if = {
			limit = { culture = greek }
			give_nickname = nick_the_spartan
			set_character_flag = immortal_mystic_spartan
		} 
		else = {
			give_nickname = nick_the_fearless
			if = {
				limit = { culture = manden }
				set_character_flag = immortal_mystic_amina
			} else = {
				set_character_flag = immortal_mystic_gaul
			}
		}

		random_list = {
			50 = { add_scarred_high_effect = yes }
			50 = { add_trait = disfigured }
		}

		random_list = {
			90 = {
				set_character_flag = mystic_is_fraud
			}
			10 = {
				modifier = {
					factor = 1.4
					FROM = { martial = 10 }
				}
				modifier = {
					factor = 1.4
					FROM = { martial = 13 }
				}
				modifier = {
					factor = 1.4
					FROM = { martial = 16 }
				}
				modifier = {
					factor = 1.4
					FROM = { martial = 19 }
				}
				modifier = {
					factor = 1.4
					FROM = { martial = 22 }
				}
				
				change_martial = 6
			}
		}
		save_event_target_as = eternal_life_mystic
	}
}

create_intrigue_mystic_effect = {
	random_list = {
		25 = {
			create_character = {
				random_traits = no
				dynasty = none
				religion = hurufi
				culture = bedouin_arabic
				female = yes
				age = 72
				health = 15
				trait = elusive_shadow
				trait = mystic
				trait = hunchback
				trait = slothful
				trait = proud
				trait = paranoid
				trait = ambitious
				trait = deceitful
				trait = erudite		
			}
		}
		25 = {
			create_character = {
				name = "Cleopatra"
				random_traits = no
				dynasty = none
				religion = egyptian_pagan
				culture = egyptian_coptic
				female = yes
				age = 34
				health = 15
				trait = elusive_shadow
				trait = mystic
				trait = fair
				trait = proud
				trait = paranoid
				trait = ambitious
				trait = deceitful
				trait = erudite		
			}
		}
	}
	new_character = {
		set_character_flag = eternal_life_mystic 

		will_not_marry_effect = yes

		give_nickname = nick_the_alchemist

		if = {
			limit = { is_female = yes }
			set_character_flag = immortal_mystic_cleopatra
		} else = {
			set_character_flag = immortal_mystic_hunchback
		}

		random_list = {
			90 = {
				set_character_flag = mystic_is_fraud
			}
			10 = {
				modifier = {
					factor = 1.4
					FROM = { intrigue = 10 }
				}
				modifier = {
					factor = 1.4
					FROM = { intrigue = 13 }
				}
				modifier = {
					factor = 1.4
					FROM = { intrigue = 16 }
				}
				modifier = {
					factor = 1.4
					FROM = { intrigue = 19 }
				}
				modifier = {
					factor = 1.4
					FROM = { intrigue = 22 }
				}
				
				change_intrigue = 6
			}
		}
		save_event_target_as = eternal_life_mystic
	}
}

create_learning_mystic_effect = {
	random_list = {
		25 = {
			create_character = {
				random_traits = no
				dynasty = none
				religion = buddhist
				culture = sinhala
				female = yes
				age = 9
				health = 15
				trait = mystic
				trait = brahmin
				trait = theravada_buddhist
				trait = quick
				trait = fussy
				trait = conscientious
			}
		}
		25 = {
			create_character = {
				random_traits = no
				name = "Seneca"
				dynasty = none
				religion = promethean_pagan
				culture = roman
				female = no
				age = 72
				health = 15
				trait = mystic
				trait = genius
				trait = stoic
				trait = mastermind_theologian
				trait = chaste
				trait = diligent
			}
		}
		25 = {
			create_character = {
				random_traits = no
				name = "Lucan"
				dynasty = none
				religion = hellenic_pagan
				culture = roman
				female = no
				age = 25
				health = 15
				trait = poet
				trait = genius
				trait = mastermind_theologian
				trait = fair
				trait = stoic
				trait = diligent
				trait = proud
			}
		}
	}
	new_character = {
		set_character_flag = eternal_life_mystic 

		will_not_marry_effect = yes

		remove_trait = kshatriya
		remove_trait = vaishya
		remove_trait = vajrayana_buddhist
		remove_trait = mahayana_buddhist

		trigger_switch = {
			on_trigger = religion
			promethean_pagan = { give_nickname = nick_the_younger set_character_flag = immortal_mystic_lucan }
			hellenic_pagan = { give_nickname = nick_the_elder set_character_flag = immortal_mystic_seneca }
			buddhist = { give_nickname = nick_the_gentle set_character_flag = immortal_mystic_achala }
		}
		change_diplomacy = 2
		change_stewardship = 2
		change_intrigue = -1

		random_list = {
			90 = {
				set_character_flag = mystic_is_fraud
			}
			10 = {
				modifier = {
					factor = 1.4
					FROM = { learning = 10 }
				}
				modifier = {
					factor = 1.4
					FROM = { learning = 13 }
				}
				modifier = {
					factor = 1.4
					FROM = { learning = 16 }
				}
				modifier = {
					factor = 1.4
					FROM = { learning = 19 }
				}
				modifier = {
					factor = 1.4
					FROM = { learning = 22 }
				}
				
				change_learning = 15
			}
		}
		save_event_target_as = eternal_life_mystic
	}
}

# will set appropriate character flags
# if the target character has a
# "Borrowed from $holy_order" or "Expelled $holy_order" 
# character modifier. This makes generic holy order
# events actually work, without even uglier hacks
set_flag_for_holy_order_modifiers_effect = {
	# Extant Loan
	if = {
		limit = { has_character_modifier = borrowed_from_d_fianna }
		set_character_flag = borrowed_from_d_fianna
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_red_dragons }
		set_character_flag = borrowed_from_d_red_dragons
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_anubis }
		set_character_flag = borrowed_from_d_anubis
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_horus }
		set_character_flag = borrowed_from_d_horus
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_legio_hellenica }
		set_character_flag = borrowed_from_d_legio_hellenica
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_sacred_band }
		set_character_flag = borrowed_from_d_sacred_band
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_sickles }
		set_character_flag = borrowed_from_d_sickles
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_burning_blades }
		set_character_flag = borrowed_from_d_burning_blades
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_men_of_steel }
		set_character_flag = borrowed_from_d_men_of_steel
	}
	if = {
		limit = { has_character_modifier = borrowed_from_d_saint_boudicca }
		set_character_flag = borrowed_from_d_saint_boudicca
	}

	# Expelled from the Realm
	if = {
		limit = { has_character_modifier = expelled_d_fianna }
		set_character_flag = expelled_d_fianna
	}
	if = {
		limit = { has_character_modifier = expelled_d_red_dragons }
		set_character_flag = expelled_d_red_dragons
	}
	if = {
		limit = { has_character_modifier = expelled_d_anubis }
		set_character_flag = expelled_d_anubis
	}
	if = {
		limit = { has_character_modifier = expelled_d_horus }
		set_character_flag = expelled_d_horus
	}
	if = {
		limit = { has_character_modifier = expelled_d_legio_hellenica }
		set_character_flag = expelled_d_legio_hellenica
	}
	if = {
		limit = { has_character_modifier = expelled_d_sacred_band }
		set_character_flag = expelled_d_sacred_band
	}
	if = {
		limit = { has_character_modifier = expelled_d_sickles }
		set_character_flag = expelled_d_sickles
	}
	if = {
		limit = { has_character_modifier = expelled_d_burning_blades }
		set_character_flag = expelled_d_burning_blades
	}
	if = {
		limit = { has_character_modifier = expelled_d_men_of_steel }
		set_character_flag = expelled_d_men_of_steel
	}
	if = {
		limit = { has_character_modifier = expelled_d_saint_boudicca }
		set_character_flag = expelled_d_saint_boudicca
	}
}

# opposite of set_flag, this will check for the right
# flags and apply the corresponding modifier, if the
# character doesn't already have that modifier
set_character_modifier_for_holy_order_flags_effect = {
	# Extant Loan
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_fianna }
			has_character_flag = borrowed_from_d_fianna
		}
		add_character_modifier = { 
			name = borrowed_from_d_fianna
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_red_dragons }
			has_character_flag = borrowed_from_d_red_dragons
		}
		add_character_modifier = { 
			name = borrowed_from_d_red_dragons
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_anubis }
			has_character_flag = borrowed_from_d_anubis
		}
		add_character_modifier = { 
			name = borrowed_from_d_anubis
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_horus }
			has_character_flag = borrowed_from_d_horus
		}
		add_character_modifier = { 
			name = borrowed_from_d_horus
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_legio_hellenica }
			has_character_flag = borrowed_from_d_legio_hellenica
		}
		add_character_modifier = { 
			name = borrowed_from_d_legio_hellenica
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_sacred_band }
			has_character_flag = borrowed_from_d_sacred_band
		}
		add_character_modifier = { 
			name = borrowed_from_d_sacred_band
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_sickles }
			has_character_flag = borrowed_from_d_sickles
		}
		add_character_modifier = { 
			name = borrowed_from_d_sickles
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_burning_blades }
			has_character_flag = borrowed_from_d_burning_blades
		}
		add_character_modifier = { 
			name = borrowed_from_d_burning_blades
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_men_of_steel }
			has_character_flag = borrowed_from_d_men_of_steel
		}
		add_character_modifier = { 
			name = borrowed_from_d_men_of_steel
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = borrowed_from_d_saint_boudicca }
			has_character_flag = borrowed_from_d_saint_boudicca
		}
		add_character_modifier = { 
			name = borrowed_from_d_saint_boudicca
			duration = -1
			inherit = yes
		}
	}

	# Expelled from the Realm
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_fianna }
			has_character_flag = expelled_d_fianna
		}
		add_character_modifier = { 
			name = expelled_d_fianna
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_red_dragons }
			has_character_flag = expelled_d_red_dragons
		}
		add_character_modifier = { 
			name = expelled_d_red_dragons
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_anubis }
			has_character_flag = expelled_d_anubis
		}
		add_character_modifier = { 
			name = expelled_d_anubis
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_horus }
			has_character_flag = expelled_d_horus
		}
		add_character_modifier = { 
			name = expelled_d_horus
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_legio_hellenica }
			has_character_flag = expelled_d_legio_hellenica
		}
		add_character_modifier = { 
			name = expelled_d_legio_hellenica
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_sacred_band }
			has_character_flag = expelled_d_sacred_band
		}
		add_character_modifier = { 
			name = expelled_d_sacred_band
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_sickles }
			has_character_flag = expelled_d_sickles
		}
		add_character_modifier = { 
			name = expelled_d_sickles
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_burning_blades }
			has_character_flag = expelled_d_burning_blades
		}
		add_character_modifier = { 
			name = expelled_d_burning_blades
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_men_of_steel }
			has_character_flag = expelled_d_men_of_steel
		}
		add_character_modifier = { 
			name = expelled_d_men_of_steel
			duration = -1
			inherit = yes
		}
	}
	if = {
		limit = {
			NOT = { has_character_modifier = expelled_d_saint_boudicca }
			has_character_flag = expelled_d_saint_boudicca
		}
		add_character_modifier = { 
			name = expelled_d_saint_boudicca
			duration = -1
			inherit = yes
		}
	}	
}

# requires event_target:holy_order to be defined
clear_borrowed_from_holy_order_modifier_effect = {
	clr_character_flag = borrowed_from_@event_target:holy_order
	
	event_target:holy_order = {
		holder_scope = {
			trigger_switch = { 
				on_trigger = title
				d_fianna = { PREVPREV = { remove_character_modifier = borrowed_from_d_fianna } }
				d_red_dragons = { PREVPREV = { remove_character_modifier = borrowed_from_d_red_dragons } }
				d_anubis = { PREVPREV = { remove_character_modifier = borrowed_from_d_anubis } }
				d_horus = {	PREVPREV = { remove_character_modifier = borrowed_from_d_horus } }
				d_legio_hellenica = { PREVPREV = { remove_character_modifier = borrowed_from_d_legio_hellenica } }
				d_sacred_band = { PREVPREV = { remove_character_modifier = borrowed_from_d_sacred_band } }
				d_sickles = { PREVPREV = { remove_character_modifier = borrowed_from_d_sickles } }
				d_burning_blades = { PREVPREV = { remove_character_modifier = borrowed_from_d_burning_blades } }
				d_men_of_steel = { PREVPREV = { remove_character_modifier = borrowed_from_d_men_of_steel } }
				d_saint_boudicca = { PREVPREV = { remove_character_modifier = borrowed_from_d_saint_boudicca }}
			}
		}
	}
}

# requires event_target:holy_order to be defined
clear_expelled_holy_order_modifier_effect = {
	clr_character_flag = expelled_@event_target:holy_order
	
	event_target:holy_order = {
		holder_scope = {
			trigger_switch = { 
				on_trigger = title
				d_fianna = { PREVPREV = { remove_character_modifier = expelled_d_fianna } }
				d_red_dragons = { PREVPREV = { remove_character_modifier = expelled_d_red_dragons } }
				d_anubis = { PREVPREV = { remove_character_modifier = expelled_d_anubis } }
				d_horus = { PREVPREV = { remove_character_modifier = expelled_d_horus } }
				d_legio_hellenica = { PREVPREV = { remove_character_modifier = expelled_d_legio_hellenica } }
				d_sacred_band = { PREVPREV = { remove_character_modifier = expelled_d_sacred_band } }
				d_sickles = { PREVPREV = { remove_character_modifier = expelled_d_sickles } }
				d_burning_blades = { PREVPREV = { remove_character_modifier = expelled_d_burning_blades } }
				d_men_of_steel = { PREVPREV = { remove_character_modifier = expelled_d_men_of_steel } }
				d_saint_boudicca = { PREVPREV = { remove_character_modifier = expelled_d_saint_boudicca }}
			}
		}
	}
}

lower_temple_tax_obligation_effect = {
	if = {
		limit = { has_law = temple_tax_1 }
		add_law = temple_tax_0
	}
	if = {
		limit = { has_law = temple_tax_2 }
		add_law = temple_tax_1
	}
	if = {
		limit = { has_law = temple_tax_3 }
		add_law = temple_tax_2
	}
}

lower_temple_levy_obligation_effect = {
	if = {
		limit = { has_law = temple_contract_1 }
		add_law = temple_contract_0
	}
	if = {
		limit = { has_law = temple_contract_2 }
		add_law = temple_contract_1
	}
	if = {
		limit = { has_law = temple_contract_3 }
		add_law = temple_contract_2
	}
}

move_temple_obligations_toward_balanced_effect = {
	if = {
		limit = { has_law = tax_levy_law_theocracy_3 }
		add_law = tax_levy_law_theocracy_4
	}
	if = {
		limit = { has_law = tax_levy_law_theocracy_2 }
		add_law = tax_levy_law_theocracy_3
	}
	if = {
		limit = { has_law = tax_levy_law_theocracy_1 }
		add_law = tax_levy_law_theocracy_2
	}
	if = {
		limit = { has_law = tax_levy_law_theocracy_0 }
		add_law = tax_levy_law_theocracy_1
	}

	if = {
		limit = { has_law = tax_levy_law_theocracy_5 }
		add_law = tax_levy_law_theocracy_4
	}
	if = {
		limit = { has_law = tax_levy_law_theocracy_6 }
		add_law = tax_levy_law_theocracy_5
	}
	if = {
		limit = { has_law = tax_levy_law_theocracy_7 }
		add_law = tax_levy_law_theocracy_6
	}
	if = {
		limit = { has_law = tax_levy_law_theocracy_8 }
		add_law = tax_levy_law_theocracy_7
	}
}

give_random_tier_5_artifact_to_prev_effect = {
	random_list = {
		25 = {
			add_artifact = silver_hand_of_nuada
		}
		25 = {
			add_artifact = trident_of_britannia
		}
		25 = {
			add_artifact = helm_of_britannia
		}
		25 = {
			add_artifact = shield_of_britannia
		}
	}

	new_artifact = {
		set_creation_date = 1.1.1
		transfer_artifact = {
			from = PREV
			to = PREVPREV
		}
	}
}

give_random_tier_4_artifact_to_prev_effect = {
	random_list = {
		50 = {
			add_artifact = skull_of_brigid
		}
		50 = {
			add_artifact = horn_of_bran_galed
		}
	}

	new_artifact = {
		set_creation_date = 1.1.1
		transfer_artifact = {
			from = PREV
			to = PREVPREV
		}
	}
}

give_random_tier_3_artifact_to_prev_effect = {
	random_list = {
		25 = {
			add_artifact = tusk_of_torc_triath
		}
	}
	
	new_artifact = {
		set_creation_date = 1.1.1
		transfer_artifact = {
			from = PREV
			to = PREVPREV
		}
	}
}

give_random_tier_2_artifact_to_prev_effect = {
	random_list = {
		25 = {
			add_artifact = torque_of_boudicca
		}
		25 = {
			add_artifact = old_carnyx
		}
		25 = {
			add_artifact = horned_helm
		}
		25 = {
			add_artifact = battersea_shield
		}
	}
	
	new_artifact = {
		set_creation_date = 1.1.1
		transfer_artifact = {
			from = PREV
			to = PREVPREV
		}
	}
}

give_random_tier_1_artifact_to_prev_effect = {
	random_list = {
		10 = {
			add_artifact = famous_tongue
		}
		10 = {
			add_artifact = famous_head
		}
		10 = {
			add_artifact = infamous_tongue
		}
		10 = {
			add_artifact = famous_hand
		}
		10 = {
			add_artifact = famous_arm
		}
		10 = {
			add_artifact = famous_foot
		}
		10 = {
			add_artifact = famous_ancient_weapon
		}
	}

	new_artifact = {
		set_creation_date = 1.1.1
		transfer_artifact = {
			from = PREV
			to = PREVPREV
		}
	}
}

add_foreign_influence_minor_effect = {
	custom_tooltip = {
		text = foreign_influence_grows_minor_custom_tooltip
		hidden_tooltip = {
			change_variable = { which = foreign_influence value = 5 }
			if = {
				limit = {
					NOT = {
						has_province_modifier = acr_foreign_influence
					}
				}
				add_province_modifier = { name = acr_foreign_influence duration = -1 }
			}
		}
	}
}

add_foreign_influence_moderate_effect = {
	custom_tooltip = {
		text = foreign_influence_grows_moderate_custom_tooltip
		hidden_tooltip = {
			change_variable = { which = foreign_influence value = 10 }
			if = {
				limit = {
					NOT = {
						has_province_modifier = acr_foreign_influence
					}
				}
				add_province_modifier = { name = acr_foreign_influence duration = -1 }
			}
		}
	}
}

add_foreign_influence_major_effect = {
	custom_tooltip = {
		text = foreign_influence_grows_major_custom_tooltip
		hidden_tooltip = {
			change_variable = { which = foreign_influence value = 20 }
			if = {
				limit = {
					NOT = {
						has_province_modifier = acr_foreign_influence
					}
				}
				add_province_modifier = { name = acr_foreign_influence duration = -1 }
			}
		}
	}
}

subtract_foreign_influence_minor_effect = {
	custom_tooltip = {
		text = foreign_influence_declines_minor_custom_tooltip
		hidden_tooltip = {
			change_variable = { which = foreign_influence value = -5 }
			if = {
				limit = {
					NOT = { check_variable = { which = foreign_influence value = 1 } }
				}
				remove_province_modifier = acr_foreign_influence
				set_variable = { which = foreign_influence value = 0 }
			}
		}
	}
}

subtract_foreign_influence_moderate_effect = {
	custom_tooltip = {
		text = foreign_influence_declines_moderate_custom_tooltip
		hidden_tooltip = {
			change_variable = { which = foreign_influence value = -10 }
			if = {
				limit = {
					NOT = { check_variable = { which = foreign_influence value = 1 } }
				}
				remove_province_modifier = acr_foreign_influence
				set_variable = { which = foreign_influence value = 0 }
			}
		}
	}
}

subtract_foreign_influence_major_effect = {
	custom_tooltip = {
		text = foreign_influence_declines_major_custom_tooltip
		hidden_tooltip = {
			change_variable = { which = foreign_influence value = -20 }
			if = {
				limit = {
					NOT = { check_variable = { which = foreign_influence value = 1 } }
				}
				remove_province_modifier = acr_foreign_influence
				set_variable = { which = foreign_influence value = 0 }
			}
		}
	}
}

spawn_good_scholar_effect = {

	if = { 
		limit = { has_religion_feature = religion_matriarchal }
		create_random_priest = {
			random_traits = yes
			dynasty = actually_culture
			female = yes
			attributes = {
				diplomacy = 2
				learning = 8
				stewardship = 2
				intrigue = 2
				martial = 2
			}
		}
	}
	if = { 
		limit = { NOT = { has_religion_feature = religion_matriarchal } }
		create_random_priest = {
			random_traits = yes
			dynasty = actually_culture
			female = no
			attributes = {
				diplomacy = 2
				learning = 8
				stewardship = 2
				intrigue = 2
				martial = 2
			}
		}
	}
	new_character = {
		remove_trait = weak
		remove_trait = slow
		remove_trait = imbecile
		remove_trait = dull
		remove_trait = dwarf
		remove_trait = giant
		remove_trait = hunchback
		remove_trait = clubfooted
		remove_trait = craven
		remove_trait = paranoid
		
		remove_trait = mystic
		remove_trait = socializer
		remove_trait = gamer
		remove_trait = hedonist
		remove_trait = duelist
		remove_trait = hunter
		remove_trait = strategist
		remove_trait = administrator
		remove_trait = architect
		remove_trait = gardener
		remove_trait = schemer
		remove_trait = impaler
		remove_trait = seducer
		remove_trait = seductress
		remove_trait = theologian
		remove_trait = scholar
		
		remove_trait = detached_priest
		remove_trait = martial_cleric
		remove_trait = mastermind_theologian
		
		add_trait = scholarly_theologian

		random_list = {
			27 = {
				add_trait = shrewd
			}
			3 = {
				add_trait = quick
			}
			70 = {
				change_diplomacy = 1
			}
		}
		
		hidden_tooltip = {
			if = {
				limit = {
					has_dharmic_religion_trigger = yes
				}
				add_trait = brahmin
				character_event = { id = RoI.30121 }
			}
			if = {
				limit = {
					has_religion_feature = religion_no_leader
					religion_group = pagan_group
				}
				random_list = {  
					5 = {
						add_trait = pagan_branch_1
					}
					25 = {
						add_trait = pagan_branch_2
					}
					25 = {
						add_trait = pagan_branch_3
					}
					25 = {
						add_trait = pagan_branch_4
					}
				}
			}
		}
		set_character_flag = invited_soldier
		save_event_target_as = invited_character
	}
}

spawn_good_steward_effect = {

	if = { 
		limit = { has_religion_feature = religion_matriarchal }
		create_random_steward = {
			random_traits = yes
			dynasty = actually_culture
			female = yes
			attributes = {
				diplomacy = 2
				learning = 2
				stewardship = 8
				intrigue = 2
				martial = 2
			}
		}
	}
	if = { 
		limit = { NOT = { has_religion_feature = religion_matriarchal } }
		create_random_steward = {
			random_traits = yes
			dynasty = actually_culture
			female = no
			attributes = {
				diplomacy = 2
				learning = 4
				stewardship = 8
				intrigue = 2
				martial = 2
			}
		}
	}
	new_character = {
		remove_trait = weak
		remove_trait = slow
		remove_trait = imbecile
		remove_trait = dull
		remove_trait = dwarf
		remove_trait = giant
		remove_trait = hunchback
		remove_trait = clubfooted
		remove_trait = craven
		remove_trait = paranoid
		
		remove_trait = mystic
		remove_trait = socializer
		remove_trait = gamer
		remove_trait = hedonist
		remove_trait = duelist
		remove_trait = hunter
		remove_trait = strategist
		remove_trait = administrator
		remove_trait = architect
		remove_trait = gardener
		remove_trait = schemer
		remove_trait = impaler
		remove_trait = seducer
		remove_trait = seductress
		remove_trait = theologian
		remove_trait = scholar
		
		remove_trait = indulgent_wastrel
		remove_trait = thrifty_clerk
		remove_trait = midas_touched
		
		add_trait = scholarly_theologian

		random_list = {
			27 = {
				add_trait = shrewd
			}
			3 = {
				add_trait = quick
			}
			70 = {
				change_diplomacy = 1
			}
		}
		
		hidden_tooltip = {
			if = {
				limit = {
					has_dharmic_religion_trigger = yes
				}
				add_trait = brahmin
				character_event = { id = RoI.30121 }
			}
			if = {
				limit = {
					has_religion_feature = religion_no_leader
					religion_group = pagan_group
				}
				random_list = {  
					5 = {
						add_trait = pagan_branch_1
					}
					25 = {
						add_trait = pagan_branch_2
					}
					25 = {
						add_trait = pagan_branch_3
					}
					25 = {
						add_trait = pagan_branch_4
					}
				}
			}
		}
		set_character_flag = invited_soldier
		save_event_target_as = invited_character
	}
}

prev_takes_this_head_as_trophy_effect = {
	if = { # an honest-to-gods immortal person
		limit = {
			has_trait = immortal
		}
		PREV = { add_artifact = immortal_skull }
		new_artifact = {
			set_name = immortal_head_name
			set_description = immortal_head_desc
		}
	}
	else_if = { # the reborn alexander the great
		limit = {
			any_owned_bloodline = {
				has_bloodline_flag = bloodline_alexander
				founder = {
					character = PREVPREV
				}
			}
		}
		PREV = { add_artifact = alexanders_skull }
		new_artifact = {
			set_name = alexander_head_name
			set_description = alexander_head_desc
		}
	}
	else_if = { # Charlemagne, post-HRE
		limit = {
			character = 6392
			has_landed_title = e_hre
		}
		PREV = { add_artifact = karl_skull2 }
	}
	else_if = { # a religious head
		limit = {
			controls_religion = yes
		}
		PREV = { add_artifact = great_priest_skull }
		new_artifact = {
			set_name = great_priest_head_name
			set_description = great_priest_head_desc
		}
	}
	else_if = { # roman successor emperor
		limit = {
			OR = {
				has_landed_title = e_hre
				has_landed_title = e_latin_empire
				has_landed_title = e_byzantium
			}
		}
		PREV = { add_artifact = roman_pretender_skull }
		new_artifact = {
			set_name = roman_pretender_head_name
			set_description = roman_pretender_head_desc
		}
	}
	else_if = { # restored roman emperor
		limit = {
			has_landed_title = e_roman_empire
		}
		PREV = { add_artifact = true_roman_skull }
		new_artifact = {
			set_name = roman_head_name
			set_description = roman_head_desc
		}
	}
	else_if = { # William the Conqueror, so long as he's a king
		limit = {
			character = 140
			higher_real_tier_than = DUKE
		}
		PREV = { add_artifact = williams_skull }
		new_artifact = {
			set_name = williams_head_name
			set_description = williams_head_desc
		}
	}
	else_if = { # super famous, Exalted
		limit = {
			prestige > 5000
		}
		PREV = { add_artifact = prestige_skull2 }
		new_artifact = {
			set_name = prestige_head2_name
			set_description = prestige_head2_desc
		}
	}
	else_if = { # super pious, Sanctified
		limit = {
			piety > 5000
		}
		PREV = { add_artifact = piety_skull2 }
		new_artifact = {
			set_name = piety_head2_name
			set_description = piety_head2_desc
		}
	}
	else_if = { # porphyrogenitos
		limit = {
			has_trait = born_in_the_purple
		}
		PREV = { add_artifact = purple_skull }
		new_artifact = {
			set_name = purple_head_name
			set_description = purple_head_desc
		}
	}
	else_if = { # pretty famous
		limit = {
			prestige > 1000
		}
		PREV = { add_artifact = prestige_skull1 }
		new_artifact = {
			set_name = prestige_head1_name
			set_description = prestige_head1_desc
		}
	}
	else_if = { # pretty pious
		limit = {
			piety > 1000
		}
		PREV = { add_artifact = piety_skull1 }
		new_artifact ={
			set_name = piety_head1_name
			set_description = piety_head1_desc
		}
	}
	else = { # schmuck
		PREV = { add_artifact = schmuck_skull }
		new_artifact = {
			set_name = schmuck_head_name
		}
	}
}