set_cannot_marry_flag_effect = {
	add_trait = cannot_marry_trait
	if = {
		limit = {
			is_ruler = yes
			is_theocracy = no
			tier = BARON
		}
		if = {
			limit = {
				is_government_potential = theocracy_government
			}
			set_government_type = theocracy_government
		}
		else_if = {
			limit = {
				is_government_potential = republic_government
			}
			set_government_type = republic_government
		}
		else = {
			log = "(IMPORTANT) Can't block marriage of [This.GetBestName]"
		}
	}
}
# Set cannot_marry flag or find right spouse
set_cannot_marry_or_find_spouse_effect = {
	if = {
		limit = { require_cannot_marry_flag_trigger = yes }
		set_cannot_marry_flag_effect = yes
	}
	else_if = {
		limit = { can_marry_trigger = yes }
		# Finds right spouse
		character_event = { id = WCCLN.130 }
	}
	else = {
		set_cannot_marry_flag_effect = yes
	}
}

remove_racial_traits_effect = {
	# Fixes immortal age
	rejuvenate_effect = yes
	
	# Add new races always at the end
	if = { limit = { trait = creature_human 				} remove_trait = creature_human 				}
	if = { limit = { trait = creature_orc 					} remove_trait = creature_orc 				}
	if = { limit = { trait = creature_ogre 					} remove_trait = creature_ogre 				}
	if = { limit = { trait = creature_troll 				} remove_trait = creature_troll 				}
	if = { limit = { trait = creature_murloc 				} remove_trait = creature_murloc 				}
	if = { limit = { trait = creature_gnoll 				} remove_trait = creature_gnoll 				}
	if = { limit = { trait = creature_kobold 				} remove_trait = creature_kobold 				}
	if = { limit = { trait = creature_dwarf 				} remove_trait = creature_dwarf 				}
	if = { limit = { trait = creature_gnome 				} remove_trait = creature_gnome 				}

	# High elves
	if = { limit = { trait = creature_high_elf 				} remove_trait = creature_high_elf 			}
	if = { limit = { trait = creature_blood_elf 			} remove_trait = creature_blood_elf 			}

	if = { limit = { trait = creature_naga 					} remove_trait = creature_naga 				}

	# Red dragons
	if = { limit = { trait = creature_red_whelp 			} remove_trait = creature_red_whelp 			}
	if = { limit = { trait = creature_red_drake 			} remove_trait = creature_red_drake 			}
	if = { limit = { trait = creature_red_dragon 			} remove_trait = creature_red_dragon 			}
	if = { limit = { trait = creature_red_wyrm 				} remove_trait = creature_red_wyrm 			}

	# Blue dragons
	if = { limit = { trait = creature_blue_whelp 			} remove_trait = creature_blue_whelp 			}
	if = { limit = { trait = creature_blue_drake 			} remove_trait = creature_blue_drake 			}
	if = { limit = { trait = creature_blue_dragon 			} remove_trait = creature_blue_dragon 		}
	if = { limit = { trait = creature_blue_wyrm 			} remove_trait = creature_blue_wyrm 			}

	# Green dragons
	if = { limit = { trait = creature_green_whelp 			} remove_trait = creature_green_whelp 		}
	if = { limit = { trait = creature_green_drake 			} remove_trait = creature_green_drake 		}
	if = { limit = { trait = creature_green_dragon 			} remove_trait = creature_green_dragon 		}
	if = { limit = { trait = creature_green_wyrm 			} remove_trait = creature_green_wyrm 			}

	# Black dragons
	if = { limit = { trait = creature_black_whelp 			} remove_trait = creature_black_whelp 		}
	if = { limit = { trait = creature_black_drake 			} remove_trait = creature_black_drake 		}
	if = { limit = { trait = creature_black_dragon 			} remove_trait = creature_black_dragon 		}
	if = { limit = { trait = creature_black_wyrm 			} remove_trait = creature_black_wyrm 			}

	if = { limit = { trait = creature_goblin 				} remove_trait = creature_goblin 				}
	if = { limit = { trait = creature_pygmy 				} remove_trait = creature_pygmy 				}
	if = { limit = { trait = creature_hozen 				} remove_trait = creature_hozen 				}
	if = { limit = { trait = creature_draenei 				} remove_trait = creature_draenei 			}
	if = { limit = { trait = creature_arakkoa_corrupted 	} remove_trait = creature_arakkoa_corrupted 	}

	# Forms of undead
	if = { limit = { trait = creature_ghoul 				} remove_trait = creature_ghoul 				}
	if = { limit = { trait = creature_wraith 				} remove_trait = creature_wraith 				}
	if = { limit = { trait = creature_banshee 				} remove_trait = creature_banshee 			}
	if = { limit = { trait = creature_plague_eruptor 		} remove_trait = creature_plague_eruptor 		}
	if = { limit = { trait = creature_abomination 			} remove_trait = creature_abomination 		}
	if = { limit = { trait = creature_lich 					} remove_trait = creature_lich 				}
	if = { limit = { trait = creature_wickerman 			} remove_trait = creature_wickerman 		}
	if = { limit = { trait = creature_wicker_behemoth 		} remove_trait = creature_wicker_behemoth 		}
	if = { limit = { trait = creature_wicker_golem 			} remove_trait = creature_wicker_golem 				}

	# Demons
	if = { limit = { trait = creature_annihilan 			} remove_trait = creature_annihilan 			}
	if = { limit = { trait = creature_nathrezim				} remove_trait = creature_nathrezim			}
	if = { limit = { trait = creature_eredruin				} remove_trait = creature_eredruin			}
	if = { limit = { trait = creature_fel_orc				} remove_trait = creature_fel_orc				}
	if = { limit = { trait = creature_felblood_elf			} remove_trait = creature_felblood_elf		}
	if = { limit = { trait = creature_satyr					} remove_trait = creature_satyr				}
	if = { limit = { trait = creature_eredar				} remove_trait = creature_eredar				}
	if = { limit = { trait = creature_sayaadi				} remove_trait = creature_sayaadi				}
	if = { limit = { trait = creature_shivarra				} remove_trait = creature_shivarra			}
	if = { limit = { trait = creature_moarg					} remove_trait = creature_moarg				}
	if = { limit = { trait = creature_observer				} remove_trait = creature_observer			}
	if = { limit = { trait = creature_avatar_of_sargeras	} remove_trait = creature_avatar_of_sargeras	}
	if = { limit = { trait = creature_lothraxim				} remove_trait = creature_lothraxim			}

	# Elementals
	if = { limit = { trait = creature_air_elemental			} remove_trait = creature_air_elemental		}
	if = { limit = { trait = creature_earth_elemental		} remove_trait = creature_earth_elemental   	}
	if = { limit = { trait = creature_fire_elemental		} remove_trait = creature_fire_elemental		}
	if = { limit = { trait = creature_flamewaker			} remove_trait = creature_flamewaker			}
	if = { limit = { trait = creature_water_elemental		} remove_trait = creature_water_elemental   	}

	if = { limit = { trait = creature_iron_dwarf			} remove_trait = creature_iron_dwarf			}
	if = { limit = { trait = creature_vrykul				} remove_trait = creature_vrykul				}
	if = { limit = { trait = creature_tuskarr				} remove_trait = creature_tuskarr				}
	if = { limit = { trait = creature_magnataur				} remove_trait = creature_magnataur			}
	if = { limit = { trait = creature_furbolg				} remove_trait = creature_furbolg				}
	if = { limit = { trait = creature_gorloc				} remove_trait = creature_gorloc				}
	if = { limit = { trait = creature_watcher				} remove_trait = creature_watcher				}
	if = { limit = { trait = creature_wolvar				} remove_trait = creature_wolvar				}
	if = { limit = { trait = creature_taunka				} remove_trait = creature_taunka				}
	if = { limit = { trait = creature_kvaldir				} remove_trait = creature_kvaldir				}
	if = { limit = { trait = creature_nerubian				} remove_trait = creature_nerubian			}
	if = { limit = { trait = creature_harpy					} remove_trait = creature_harpy				}
	if = { limit = { trait = creature_mechagnome			} remove_trait = creature_mechagnome			}
	if = { limit = { trait = creature_earthen				} remove_trait = creature_earthen				}

	# Bronze dragons
	if = { limit = { trait = creature_bronze_whelp			} remove_trait = creature_bronze_whelp		}
	if = { limit = { trait = creature_bronze_drake			} remove_trait = creature_bronze_drake		}
	if = { limit = { trait = creature_bronze_dragon			} remove_trait = creature_bronze_dragon		}
	if = { limit = { trait = creature_bronze_wyrm			} remove_trait = creature_bronze_wyrm			}

	if = { limit = { trait = creature_giant				} remove_trait = creature_giant			}

	if = { limit = { trait = creature_nraqi					} remove_trait = creature_nraqi				}
	if = { limit = { trait = creature_cthraxxi				} remove_trait = creature_cthraxxi			}

	if = { limit = { trait = creature_night_elf				} remove_trait = creature_night_elf			}
	if = { limit = { trait = creature_tauren				} remove_trait = creature_tauren				}
	if = { limit = { trait = creature_centaur				} remove_trait = creature_centaur				}
	if = { limit = { trait = creature_quilboar				} remove_trait = creature_quilboar			}
	if = { limit = { trait = creature_tolvir				} remove_trait = creature_tolvir				}
	if = { limit = { trait = creature_qiraji				} remove_trait = creature_qiraji				}
	if = { limit = { trait = creature_dryad					} remove_trait = creature_dryad			}
	if = { limit = { trait = creature_frostnymph			} remove_trait = creature_frostnymph			}
	if = { limit = { trait = creature_highborne				} remove_trait = creature_highborne			}
	if = { limit = { trait = creature_stone_tolvir				} remove_trait = creature_stone_tolvir				}
	
	# Infinite dragons
	if = { limit = { trait = creature_infinite_whelp			} remove_trait = creature_infinite_whelp			}
	if = { limit = { trait = creature_infinite_drake			} remove_trait = creature_infinite_drake			}
	if = { limit = { trait = creature_infinite_dragon		} remove_trait = creature_infinite_dragon		}
	if = { limit = { trait = creature_infinite_wyrm			} remove_trait = creature_infinite_wyrm			}
	
	if = { limit = { trait = creature_old_god						} remove_trait = creature_old_god						}
	if = { limit = { trait = creature_vulpera						} remove_trait = creature_vulpera						}
	if = { limit = { trait = creature_sethrak						} remove_trait = creature_sethrak						}
	if = { limit = { trait = creature_titan_keeper				} remove_trait = creature_titan_keeper			}
	if = { limit = { trait = creature_titan							} remove_trait = creature_titan							}
	
	# Ancients
	if = { limit = { trait = creature_protector 					} remove_trait = creature_protector 					}
	if = { limit = { trait = creature_ancient_war				} remove_trait = creature_ancient_war				}
	if = { limit = { trait = creature_ancient_lore				} remove_trait = creature_ancient_lore			}
	if = { limit = { trait = creature_ancient_wind				} remove_trait = creature_ancient_wind			}
	
	# Pandaria
	if = { limit = { trait = creature_pandaren				} remove_trait = creature_pandaren			}
	if = { limit = { trait = creature_jinyu				} remove_trait = creature_jinyu			}
	if = { limit = { trait = creature_ankoan				} remove_trait = creature_ankoan			}	
	if = { limit = { trait = creature_mogu				} remove_trait = creature_mogu			}
	if = { limit = { trait = creature_saurok				} remove_trait = creature_saurok			}
	if = { limit = { trait = creature_grummle				} remove_trait = creature_grummle			}
	if = { limit = { trait = creature_mantid				} remove_trait = creature_mantid			}
	if = { limit = { trait = creature_yaungol				} remove_trait = creature_yaungol			}

	# Race-related traits
	if = { limit = { trait = twoheaded 									} remove_trait = twoheaded									}
	if = { limit = { trait = tentacle_arm_mutation 			} remove_trait = tentacle_arm_mutation			}
	if = { limit = { trait = chela_hand_mutation 				} remove_trait = chela_hand_mutation				}
	if = { limit = { trait = chitinous_growths_mutation 	} remove_trait = chitinous_growths_mutation	}
	if = { limit = { trait = spikes_mutation 						} remove_trait = spikes_mutation						}
	if = { limit = { trait = scales_mutation 						} remove_trait = scales_mutation						}
	if = { limit = { trait = eyes_mutation 							} remove_trait = eyes_mutation							}
}
tomb_generate_random_treasury_effect = {
	if = {
		limit = { has_province_flag = tomb_of_sargeras_flag }
		set_variable = { which = tomb_random_room value = 80010 }
	}
	if = {
		limit = { NOT = { has_province_flag = tomb_of_sargeras_flag } }
		random_list = {
			10 = { set_variable = { which = tomb_random_room value = 80000 } }
		}
	}
}
tomb_generate_random_room_effect = {
	random_list = {
		10 = {
			set_variable = { which = tomb_random_room value = 70 }
		}
		10 = {
			set_variable = { which = tomb_random_room value = 50 }
		}
		10 = {
			set_variable = { which = tomb_random_room value = 40 }
		}
		10 = {
			set_variable = { which = tomb_random_room value = 30 }
		}
		10 = {
			set_variable = { which = tomb_random_room value = 10 }
			modifier = { factor = 0 has_province_modifier = mysterious_cave }
		}
	}
}
chose_tomb_expedition_leader_effect = {
	if = {
		limit = {
			liege = { ai = no }
			ai = yes
			NOT = { has_character_flag = special_leader_of_expedition }
		}
		liege = { save_event_target_as = target_leader_of_expedition }
	}
	if = {
		limit = {
			OR = {
				liege = { ai = yes }
				ai = no
				has_character_flag = special_leader_of_expedition
			}
		}
		save_event_target_as = target_leader_of_expedition
	}
}
escape_from_tomb_effect = {
	remove_trait = travelling
	clr_character_flag = on_journey_to_tomb_flag

	if = {
		limit = {
			has_job_title = job_explorer
			has_job_action = action_survey
		}
		cancel_job_action = action_survey
	}
	clr_char_tomb_flags_and_modifiers_effect = yes
	clear_flags_with_prefix = WCTMB_
	event_target:target_tomb_location = { clr_prov_tomb_flags_and_modifiers_effect = yes }
	custom_tooltip = {
		text = escape_from_tomb_effect_tooltip
		hidden_tooltip = {
			character_event = { id = WCTMB.99900 }
		}
	}
}
clr_char_tomb_flags_and_modifiers_effect = {
	clear_flags_with_prefix = WCTMB_room_
}
clr_prov_tomb_flags_and_modifiers_effect = {
	hidden_effect = {
		clr_province_flag = expedition_is_in_tomb_flag
		set_variable = { which = tomb_expedition_location value = 0 }
		if = {
			limit = {
				OR = {
					event_target:target_explorer = { has_character_flag = got_to_treasure_flag }
					has_province_flag = tomb_of_sargeras_flag												# Tomb of Sargeras will be removed when you leave it
				}
			}
			if = {
				limit = { has_province_flag = tomb_of_sargeras_flag }
				clr_province_flag = tomb_of_sargeras_flag
			}
			if = {
				limit = { has_province_modifier = elven_tomb }
				remove_province_modifier = elven_tomb
			}
			if = {
				limit = { has_province_modifier = mysterious_cave }
				remove_province_modifier = mysterious_cave
			}
			if = {
				limit = { has_province_modifier = troll_ruins }
				remove_province_modifier = troll_ruins
			}
			if = {
				limit = { has_province_modifier = human_tomb }
				remove_province_modifier = human_tomb
			}
			if = {
				limit = { has_province_modifier = vrykul_barrow }
				remove_province_modifier = vrykul_barrow
			}
		}
	}
}
fire_next_tomb_event_effect = {
	custom_tooltip = {
		text = fire_next_tomb_event_effect_tooltip
		hidden_tooltip = {
			clr_char_tomb_flags_and_modifiers_effect = yes
			if = {
				limit = {
					OR = {
						event_target:target_leader_of_expedition = { ai = yes }
						event_target:target_tomb_location = { check_variable = { which = tomb_expedition_location value = 3 } }
					}
				}
				set_character_flag = got_to_treasure_flag
				if = {
					limit = { event_target:target_tomb_location = { has_province_flag = tomb_of_sargeras_flag } }
					narrative_event = { id = WCTMB.80010 }
				}
				# Random treasures
				random_list = {
					10 = { narrative_event = { id = WCTMB.80000 } }
				}
			}
			else = {
				event_target:target_tomb_location = { change_variable = { which = tomb_expedition_location value = 1 } }

				# Random rooms
				random_list = {
					10 = {
						set_character_flag = WCTMB_70_fired_flag
						narrative_event = { id = WCTMB.70 }
						modifier = {
							factor = 0
							has_character_flag = WCTMB_70_fired_flag
						}
					}
					10 = {
						set_character_flag = WCTMB_50_fired_flag
						narrative_event = { id = WCTMB.50 }
						modifier = {
							factor = 0
							has_character_flag = WCTMB_50_fired_flag
						}
					}
					10 = {
						set_character_flag = WCTMB_40_fired_flag
						narrative_event = { id = WCTMB.40 }
						modifier = {
							factor = 0
							has_character_flag = WCTMB_40_fired_flag
						}
					}
					10 = {
						set_character_flag = WCTMB_30_fired_flag
						narrative_event = { id = WCTMB.30 }
						modifier = {
							factor = 0
							has_character_flag = WCTMB_30_fired_flag
						}
					}
					10 = {
						set_character_flag = WCTMB_10_fired_flag
						narrative_event = { id = WCTMB.10 }
						modifier = {
							factor = 0
							has_character_flag = WCTMB_10_fired_flag
						}
					}
				}
			}
		}
	}
}
increase_colony = {
	if = {
		limit = { has_province_modifier = colony_3 }
		remove_province_modifier = colony_3
		county = { grant_title_no_opinion = ROOT }
	}
	else = {
		if = {
			limit = { has_province_modifier = colony_2 }
			remove_province_modifier = colony_2
			add_province_modifier = { name = colony_3 duration = -1 }
		}
		else = {
			if = {
				limit = { has_province_modifier = colony_1 }
				remove_province_modifier = colony_1
				add_province_modifier = { name = colony_2 duration = -1 }
			}
			else = {
				add_province_modifier = { name = colony_1 duration = -1 }
				holder_scope = { set_defacto_liege = ROOT }
			}
		}
	}
}
decrease_colony = {
	# if = {
		# limit = { has_province_modifier = colony_1 }
		# remove_province_modifier = colony_1
	# }
	if = {
		limit = { has_province_modifier = colony_2 }
		remove_province_modifier = colony_2
		add_province_modifier = { name = colony_1 duration = -1 }
	}
	if = {
		limit = { has_province_modifier = colony_3 }
		remove_province_modifier = colony_3
		add_province_modifier = { name = colony_2 duration = -1 }
	}
}

add_prev_useful_flesh = {
	if = {
		limit = {
			any_realm_wonder_upgrade = {
				has_wonder_upgrade = upgrade_plagueworks
				is_active = yes
			}
		}
		change_variable = { which = useful_flesh value = 4 }
	}
	if = {
		limit = { PREV = { is_large_humanoid_trigger = yes } }
		if = {
			limit = { PREV = { is_strong_trigger = yes } }
			change_variable = { which = useful_flesh value = 12 }
			PREV = { set_character_flag = brawny_corpse_flag }
		}
		else_if = {
			limit = { PREV = { is_weak_trigger = yes } }
			change_variable = { which = useful_flesh value = 8 }
			PREV = { set_character_flag = brawny_corpse_flag }
		}
		else = {
			change_variable = { which = useful_flesh value = 10 }
			PREV = { set_character_flag = brawny_corpse_flag }
		}
	}
	else_if = {
		limit = { PREV = { is_small_humanoid_trigger = yes } }
		if = {
			limit = { PREV = { is_strong_trigger = yes } }
			change_variable = { which = useful_flesh value = 4 }
			PREV = { set_character_flag = frail_corpse_flag }
		}
		else_if = {
			limit = { PREV = { is_weak_trigger = yes } }
			change_variable = { which = useful_flesh value = 2 }
			PREV = { set_character_flag = frail_corpse_flag }
		}
		else = {
			change_variable = { which = useful_flesh value = 3 }
			PREV = { set_character_flag = frail_corpse_flag }
		}
	}
	else_if = {
		limit = { PREV = { is_strong_trigger = yes } }
		change_variable = { which = useful_flesh value = 8 }
		PREV = { set_character_flag = brawny_corpse_flag }
	}
	else_if = {
		limit = { PREV = { is_weak_trigger = yes } }
		change_variable = { which = useful_flesh value = 4 }
		PREV = { set_character_flag = frail_corpse_flag }
	}
	else = {
		change_variable = { which = useful_flesh value = 6 }
		PREV = { set_character_flag = normal_corpse_flag }
	}
}

show_close_people_what_this_become_effect = {
	if = {	# Stops if character spawned as undead, demon, void being
		limit = { has_character_flag = no_show_what_become_flag }
		clr_character_flag = no_show_what_become_flag
	}
	else_if = {
		limit = {
			OR = {
				NOT = { has_character_flag = show_what_become_cooldown_flag }
				had_character_flag = { flag = show_what_become_cooldown_flag days = 365 }
			}
		}
		set_character_flag = show_what_become_cooldown_flag
		any_spouse = {
			limit = {
				NOT = { character = event_target:target_necromancer }	# This character turned THIS, so it already know
				NOT = { character = event_target:target_worried_spouse }
				NOT = { character = event_target:target_sick_spouse }
			}
			set_notification_type_of_prev_effect = yes
			character_event = { id = WCDAC.150 days = 2 } #Must be delayed
		}
		any_friend = {
			limit = {
				NOT = { character = event_target:target_necromancer }	# This character turned THIS, so it already know
				NOT = { character = event_target:target_worried_spouse }
				NOT = { character = event_target:target_sick_spouse }
				
				NOT = { is_married = PREV }
			}
			set_notification_type_of_prev_effect = yes
			character_event = { id = WCDAC.150 days = 2 } #Must be delayed
		}
		any_lover = {
			limit = {
				NOT = { character = event_target:target_necromancer }	# This character turned THIS, so it already know
				NOT = { character = event_target:target_worried_spouse }
				NOT = { character = event_target:target_sick_spouse }
				
				NOT = { is_married = PREV }
				NOT = { is_friend = PREV }
			}
			set_notification_type_of_prev_effect = yes
			character_event = { id = WCDAC.150 days = 2 } #Must be delayed
		}
		any_close_relative = {
			limit = {
				NOT = { character = event_target:target_necromancer }	# This character turned THIS, so it already know
				NOT = { character = event_target:target_worried_spouse }
				NOT = { character = event_target:target_sick_spouse }
				
				NOT = { is_married = PREV }
				NOT = { is_friend = PREV }
				NOT = { is_lover = PREV }
			}
			set_notification_type_of_prev_effect = yes
			character_event = { id = WCDAC.150 days = 2 } #Must be delayed
		}
		if = {		# ...liege is almost your family
			limit = {
				independent = no
				OR = {
					is_ruler = yes
					has_job_title = yes
					has_minor_title = yes
				}

				liege = {
					NOT = { character = event_target:target_necromancer }	# This character turned THIS, so it already know
					NOT = { character = event_target:target_worried_spouse }
					NOT = { character = event_target:target_sick_spouse }
					
					NOT = { is_married = PREV }
					NOT = { is_friend = PREV }
					NOT = { is_lover = PREV }
					NOT = { is_close_relative = PREV }
				}
			}
			liege = {
				set_notification_type_of_prev_effect = yes
				character_event = { id = WCDAC.150 days = 2 } #Must be delayed
			}
		}
	}
	clear_flags_with_prefix = show_notification_
}
# Copy notification type of PREV
set_notification_type_of_prev_effect = {
	if = {
		limit = { PREV = { has_character_flag = show_notification_undead_flag } }
		set_character_flag = show_notification_undead_flag
	}
	else_if = {
		limit = { PREV = { has_character_flag = show_notification_demon_flag } }
		set_character_flag = show_notification_demon_flag
	}
	else_if = {
		limit = { PREV = { has_character_flag = show_notification_void_flag } }
		set_character_flag = show_notification_void_flag
	}
	else_if = {
		limit = { PREV = { has_character_flag = show_notification_worgen_flag } }
		set_character_flag = show_notification_worgen_flag
	}
}

increase_vampiric_hunger_effect = {
	if = {
		limit = { has_character_modifier = moderate_blood_thirst }
		remove_character_modifier = moderate_blood_thirst
		add_character_modifier = { name = severe_blood_thirst duration = -1 }
	}
	else = {
		if = {
			limit = { has_character_modifier = minor_blood_thirst }
			remove_character_modifier = minor_blood_thirst
			add_character_modifier = { name = moderate_blood_thirst duration = -1 }
		}
		else = {
			if = {
				limit = {
					NOR = {
						has_character_modifier = severe_blood_thirst
						has_character_modifier = moderate_blood_thirst
						has_character_modifier = minor_blood_thirst
					}
				}
				add_character_modifier = { name = minor_blood_thirst duration = -1 }
			}
		}
	}
}
decrease_vampiric_hunger_effect = {
	if = {
		limit = { has_character_modifier = severe_blood_thirst }
		remove_character_modifier = severe_blood_thirst
		add_character_modifier = { name = moderate_blood_thirst duration = -1 }
	}
	else = {
		if = {
			limit = { has_character_modifier = moderate_blood_thirst }
			remove_character_modifier = moderate_blood_thirst
			add_character_modifier = { name = minor_blood_thirst duration = -1 }
		}
		else = {
			if = {
				limit = { has_character_modifier = minor_blood_thirst }
				remove_character_modifier = minor_blood_thirst
			}
		}
	}
}
become_intelligent_worget_effect = {
	add_trait = worgen
	hidden_effect = {
		# Notifies your family/spouse/friends/lovers
		set_character_flag = show_notification_worgen_flag	# Type of notification
		show_close_people_what_this_become_effect = yes
	}
}
become_mindless_worgen_effect = {
	add_trait = worgen
	add_trait = mindless_worgen
	hidden_effect = {
		character_event = { id = WCDRU.1000 days = 60 }			# Mindless worgen events

		# Notifies your family/spouse/friends/lovers
		set_character_flag = show_notification_worgen_flag	# Type of notification
		show_close_people_what_this_become_effect = yes
	}
}
return_to_twisting_nether_effect = {
	add_trait = in_twisting_nether
	hidden_effect = { character_event = { id = WCFEL.900 days = 1095 random = 730 } }
}
lose_corporeal_body_effect = {
	add_trait = lost_corporeal_body
	hidden_effect = { character_event = { id = WCUND.900 days = 182 random = 182 } }
}
drain_fel_source_effect = {
	if = {
		limit = {
			liege = { religion_group = fel_group }
		}
		if = { limit = { has_secret_religion = yes } clear_secret_religion = yes }
		religion = liege
	}
	else = {
		set_character_flag = consuming_fel_magic_flag
	}
	
	add_15_fel_corruption_effect = yes
	
	if = {
		limit = { is_ruler = yes }
		hidden_effect = {
			any_courtier_or_vassal = {
				limit = {
					OR = {
						ai = no
						NOT = { has_character_flag = ai_refused_dark_magic_flag }
					}
					is_unimportant_trigger = no
					prisoner = no

					is_susceptible_to_fel_corruption_trigger = yes
					is_high_elf_trigger = yes
					NOR = {
						religion_group = fel_group
						true_religion_group = fel_group
						has_character_flag = consuming_fel_magic_flag
					}
				}
				letter_event = { id = WCTHW.1065 }
			}
		}
	}
}
drain_void_source_effect = {
	if = {
		limit = {
			liege = { religion_group = void_group }
		}
		if = { limit = { has_secret_religion = yes } clear_secret_religion = yes }
		religion = liege
	}
	else = {
		set_character_flag = consuming_void_magic_flag
	}
	
	add_15_void_corruption_effect = yes
	
	if = {
		limit = { is_ruler = yes }
		hidden_effect = {
			any_courtier_or_vassal = {
				limit = {
					OR = {
						ai = no
						NOT = { has_character_flag = ai_refused_dark_magic_flag }
					}
					prisoner = no
					is_unimportant_trigger = no

					is_susceptible_to_void_corruption_trigger = yes
					is_high_elf_trigger = yes
					NOR = {
						religion_group = void_group
						true_religion_group = void_group
						has_character_flag = consuming_void_magic_flag
					}
				}
				letter_event = { id = WCTHW.1065 }
			}
		}
	}
}
add_xalatath_effect = {
	add_artifact = xalatath
	new_artifact = {
		set_creation_date = 1.1.1
	}
	hidden_effect = { character_event = { id = WCVOD.2030 days = 730 } }
}
destroy_xalatath_effect = {
	unsafe_destroy_artifact = xalatath
	hidden_effect = { 73 = { province_event = { id = WCVOD.2000 days = 30 } } }
}
prev_burn_evil_being_this_effect = {
	# If THIS is not ruler then execute
	# If THIS and PREV are AI then execute
	if = {
		limit = {
			OR = {
				is_ruler = no
				AND = {
					ai = yes
					PREV = { ai = yes }
				}
			}
		}
		if = {
			limit = { is_ruler = no }
			random_list = {
				80 = {
					custom_tooltip = {
						text = burn_evil_being_effect_tooltip
						death = { death_reason = death_execution_burning killer = PREV }
					}
					add_kinslayer_trait_to_prev_effect = yes
				}
				20 = {
					banish = yes
					
					is_good_intrigue_character_score = yes
					
					modifier = {
						factor = 0
						PREV = { ai = yes }		# AI always kill
					}
				}
			}
		}
		else = {
			any_demesne_title = {
				limit = {
					title_can_be_lost_trigger = yes
					lower_tier_than = DUKE
				}
				grant_title_no_opinion = { target = PREVPREV type = claim }
			}
			death = { death_reason = death_execution_burning killer = PREV }
		}
	}
	else = {
		reverse_opinion = { modifier = opinion_accused_apostate who = PREV years = 20 }
	}
}
drink_demon_blood_effect = {
	if = {
		limit = {
			NOT = { trait = being_demon }
			is_susceptible_to_fel_corruption_trigger = yes
		}
		add_character_modifier = { name = drank_demon_blood duration = 7300 }
		if = {
			limit = { NOT = { true_religion_group = fel_group } }
			if = {
				limit = {
					is_ruler = yes
					independent = yes
				}
				if = { limit = { has_secret_religion = yes } clear_secret_religion = yes }
				religion = burning_legion_religion
			}
			else_if = {
				limit = {
					OR = {
						is_ruler = no
						independent = no
					}
					liege = { OR = { religion = orcish_fel religion = burning_legion_religion } }
				}
				if = { limit = { has_secret_religion = yes } clear_secret_religion = yes }
				liege = { ROOT = { religion = PREV } }
			}
			else = {
				set_secret_religion = burning_legion_religion
			}
		}
		if = {
			limit = { is_ruler = yes }
			custom_tooltip = {
				text = EVTOPTB_WCFEL_9960_tooltip
				hidden_effect = {
					any_courtier_or_vassal = {
						limit = {
							is_unimportant_trigger = no
							prisoner = no

							NOT = { has_character_modifier = drank_demon_blood }

							NOT = { trait = being_demon }
							is_susceptible_to_fel_corruption_trigger = yes
						}
						character_event = { id = WCFEL.9961 days = 2 }
					}
				}
			}
		}

		add_35_fel_corruption_effect = yes
	}
}
set_evil_laws_to_title_effect = {
	if = {
		limit = {
			# is_law_allowed = succ_evil_elective
			is_law_potential = succ_evil_elective
			NOT = { has_law = succ_evil_elective }
		}
		add_law = { law = succ_evil_elective cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = crown_authority_4
			is_law_potential = crown_authority_4
			NOT = { has_law = crown_authority_4 }
		}
		add_law = { law = crown_authority_4 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = vice_royalty_0
			is_law_potential = vice_royalty_0
			NOT = { has_law = vice_royalty_0 }
		}
		add_law = { law = vice_royalty_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = law_voting_power_0
			is_law_potential = law_voting_power_0
			NOT = { has_law = law_voting_power_0 }
		}
		add_law = { law = law_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = war_voting_power_0
			is_law_potential = war_voting_power_0
			NOT = { has_law = war_voting_power_0 }
		}
		add_law = { law = war_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = revoke_title_voting_power_0
			is_law_potential = revoke_title_voting_power_0
			NOT = { has_law = revoke_title_voting_power_0 }
		}
		add_law = { law = revoke_title_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = imprison_voting_power_0
			is_law_potential = imprison_voting_power_0
			NOT = { has_law = imprison_voting_power_0 }
		}
		add_law = { law = imprison_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = grant_title_voting_power_0
			is_law_potential = grant_title_voting_power_0
			NOT = { has_law = grant_title_voting_power_0 }
		}
		add_law = { law = grant_title_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = banish_voting_power_0
			is_law_potential = banish_voting_power_0
			NOT = { has_law = banish_voting_power_0 }
		}
		add_law = { law = banish_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = execution_voting_power_0
			is_law_potential = execution_voting_power_0
			NOT = { has_law = execution_voting_power_0 }
		}
		add_law = { law = execution_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = succession_voting_power_0
			is_law_potential = succession_voting_power_0
			NOT = { has_law = succession_voting_power_0 }
		}
		add_law = { law = succession_voting_power_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = out_of_realm_inheritance_law_1
			is_law_potential = out_of_realm_inheritance_law_1
			NOT = { has_law = out_of_realm_inheritance_law_1 }
		}
		add_law = { law = out_of_realm_inheritance_law_1 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = vassal_wars_law_0
			is_law_potential = vassal_wars_law_0
			NOT = { has_law = vassal_wars_law_0 }
		}
		add_law = { law = vassal_wars_law_0 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = revoke_title_law_2
			is_law_potential = revoke_title_law_2
			NOT = { has_law = revoke_title_law_2 }
		}
		add_law = { law = revoke_title_law_2 cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = ze_administration_laws_1
			is_law_potential = ze_administration_laws_1
			NOT = { has_law = ze_administration_laws_1 }
		}
		add_law = { law = ze_administration_laws_1 cooldown = no opinion_effect = no }
	}
}
convert_to_target_undead_province_effect = {
	add_province_modifier = { name = undead_province duration = -1 }
	culture = event_target:target_province_holder
	religion = event_target:target_province_holder
}
spawn_horde_troops_effect = {
	custom_tooltip = {
		text = spawn_small_horde_troops_tooltip
		spawn_small_horde_troops_effect = yes
		if = {
			limit = {
				has_game_rule = {
					name = horde_invasion
					value = x0_5
				}
			}
			spawn_small_horde_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = horde_invasion
					value = default
				}
			}
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = horde_invasion
					value = x1_5
				}
			}
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = horde_invasion
					value = x2
				}
			}
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
			spawn_small_horde_troops_effect = yes
		}
	}
}
# DON'T USE it outside of spawn_horde_troops_effect
spawn_small_horde_troops_effect = {
	spawn_unit = {
		owner = THIS
		province = 73
		home = 73
		troops = {
			light_infantry = { 125 125 }
			heavy_infantry = { 550 550 }
			pikemen = { 150 150 }
			light_cavalry = { 75 75 }
			archers = { 250 250 }
		}
		attrition = 0
		maintenance = no
		earmark = horde_forces
	}
	spawn_fleet = {
		province = closest
		owner = THIS
		earmark = horde_forces
		troops = {
			galleys = { 25 25 }
		}
	}
}
spawn_legion_troops_effect = {
	custom_tooltip = {
		text = spawn_small_legion_troops_tooltip
		spawn_small_legion_troops_effect = yes
		if = {
			limit = {
				has_game_rule = {
					name = legion_invasion
					value = x0_5
				}
			}
			spawn_small_legion_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = legion_invasion
					value = default
				}
			}
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = legion_invasion
					value = x1_5
				}
			}
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = legion_invasion
					value = x2
				}
			}
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
			spawn_small_legion_troops_effect = yes
		}
	}
}
spawn_small_legion_troops_effect = {
	spawn_unit = {
		owner = THIS
		province = event_target:target_summoning_location
		home = event_target:target_summoning_location
		troops = {
			light_infantry = { 150 150 }
			heavy_infantry = { 750 750 }
			pikemen = { 350 350 }
			knights = { 50 50 }
			archers = { 100 100 }
			elite_infantry = { 125 125 }
		}
		attrition = 0
		maintenance = no
		earmark = legion_forces
	}
	spawn_unit = {
		owner = THIS
		province = event_target:target_summoning_location
		home = event_target:target_summoning_location
		troops = {
			siege_machines = { 125 125 }
		}
		attrition = 0
		maintenance = no
		earmark = legion_forces
	}
	spawn_fleet = {
		province = closest
		owner = THIS
		earmark = legion_forces
		troops = {
			galleys = { 35 35 }
		}
	}
}
spawn_scourge_troops_effect = {
	custom_tooltip = {
		text = spawn_small_scourge_troops_tooltip
		spawn_small_scourge_troops_effect = yes
		if = {
			limit = {
				has_game_rule = {
					name = scourge_invasion
					value = x0_5
				}
			}
			spawn_small_scourge_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = scourge_invasion
					value = default
				}
			}
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = scourge_invasion
					value = x1_5
				}
			}
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
		}
		if = {
			limit = {
				has_game_rule = {
					name = scourge_invasion
					value = x2
				}
			}
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
			spawn_small_scourge_troops_effect = yes
		}
	}
}
spawn_small_scourge_troops_effect = {
	spawn_unit = {
		province = capital_scope
		home = capital_scope
		owner = THIS
		troops = {
			pikemen = { 250 250 }
			archers = { 1000 1000 }
			undead = { 2750 2750 }
		}
		attrition = 0
		maintenance = no
	}
	spawn_fleet = {
		province = closest
		owner = THIS
		troops = {
			galleys = { 35 35 }
		}
	}
}
spawn_plague_troops_effect = {
	# Must be 100 in total
	spawn_small_plague_troops_effect = yes
	if = {
		limit = {
			has_game_rule = {
				name = scourge_invasion
				value = x0_5
			}
		}
		spawn_small_plague_troops_effect = yes
	}
	if = {
		limit = {
			has_game_rule = {
				name = scourge_invasion
				value = default
			}
		}
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
	}
	if = {
		limit = {
			has_game_rule = {
				name = scourge_invasion
				value = x1_5
			}
		}
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
	}
	if = {
		limit = {
			has_game_rule = {
				name = scourge_invasion
				value = x2
			}
		}
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
		spawn_small_plague_troops_effect = yes
	}
}
spawn_small_plague_troops_effect = {
	spawn_unit = {
		province = ROOT
		home = ROOT
		owner = THIS
		scaled_by_biggest_garrison = 0.25
		troops = {
			light_infantry = { 10 10 }
			archers = { 12 12 }
			undead = { 78 78 }
		}
		attrition = 0
		merge = yes
		maintenance = no
	}
}

spawn_colonial_troops_effect = {
	spawn_small_colonial_troops_effect = yes
	spawn_small_colonial_troops_effect = yes
}
spawn_small_colonial_troops_effect = {
	spawn_unit = {
		owner = THIS
		province = capital_scope
		home = capital_scope
		troops = {
			light_infantry = { 150 150 }
			heavy_infantry = { 750 750 }
			light_cavalry = { 300 300 }
			archers = { 450 450 }
		}
		attrition = 1.0
		maintenance = no
	}
	spawn_fleet = {
		province = closest # closest sea zone
		owner = THIS
		cannot_inherit = no
		troops = {
			galleys = { 30 30 }
		}
	}
}

set_scourge_government_effect = {
	set_government_type = scourge_government
	set_evil_government_laws_effect = yes
}
set_legion_government_effect = {
	set_government_type = legion_government
	set_evil_government_laws_effect = yes
}
set_black_pact_government_effect = {
	set_government_type = black_pact_government
	set_evil_government_laws_effect = yes
}
set_roman_imperial_government_effect = {
	any_demesne_title = {
		limit = {
			is_law_potential = succ_byzantine_elective
			NOT = { has_law = succ_byzantine_elective }
			is_imperial_title = yes
		}
		add_law = { law = succ_byzantine_elective cooldown = no opinion_effect = no }
	}
	set_government_type = roman_imperial_government
	recalc_succession = yes
}
set_evil_government_laws_effect = {
	any_demesne_title = {
		limit = { prevs_title_can_has_laws_trigger = yes }
		set_evil_laws_to_title_effect = yes
	}
	recalc_succession = yes
}
clear_evil_laws_effect = {
	if = {
		limit = {
			# is_law_allowed = succ_gavelkind
			is_law_potential = succ_gavelkind
			has_law = succ_evil_elective
		}
		add_law = { law = succ_gavelkind cooldown = no opinion_effect = no }
	}
	if = {
		limit = {
			# is_law_allowed = status_of_magic_1
			is_law_potential = status_of_magic_1
			has_law = status_of_magic_3
		}
		add_law = { law = status_of_magic_1 cooldown = no opinion_effect = no }
	}
}

set_tribal_government_effect = {
	set_government_type = tribal_government
}
set_tribal_monarchy_government_effect = {
	set_government_type = tribal_monarchy_government
}
set_feudal_government_effect = {
	set_government_type = feudal_government
}

add_5_mind_control_power_effect = {
	change_variable = { which = mind_control_power value = 5 }
	if = {
		limit = { check_variable = { which = mind_control_power value = 101 } }
		set_variable = { which = mind_control_power value = 100 }
	}
	character_event = { id = WCUND.1106 }		# Increases power of mind control
}
remove_5_mind_control_power_effect = {
	change_variable = { which = mind_control_power value = -5 }
	if = {
		limit = { NOT = { check_variable = { which = mind_control_power value = 0 } } }
		set_variable = { which = mind_control_power value = 0 }
	}
	character_event = { id = WCUND.1107 }		# Decreases power of mind control
}
remove_3_mind_control_power_effect = {
	change_variable = { which = mind_control_power value = -3 }
	if = {
		limit = { NOT = { check_variable = { which = mind_control_power value = 0 } } }
		set_variable = { which = mind_control_power value = 0 }
	}
	character_event = { id = WCUND.1107 }		# Decreases power of mind control
}

free_from_lich_king_effect = {
	if = {
		limit = { can_break_scourge_mind_control_trigger = yes }
		custom_tooltip = {
			text = free_from_lich_king_effect_tooltip
			character_event = { id = WCUND.1109 }
		}
	}
}
become_blood_elf_effect = {
	if = {
		limit = { trait = creature_high_elf }
		remove_trait = creature_high_elf
		add_trait = creature_blood_elf
	}
	if = {
		limit = { NOT = { culture = blood_elf } }
		culture = blood_elf
	}
}
convert_this_and_vassals_to_blood_elves_effect = {
	become_blood_elf_effect = yes
	hidden_effect = {
		if = {
			limit = { is_ruler = yes }
			any_demesne_province = {
				limit = { culture = high_elf }
				culture = blood_elf
			}
			any_courtier_or_vassal = {
				limit = {
					trait = creature_high_elf
					OR = {
						is_ruler = no
						tier = BARON
					}
				}
				convert_this_and_vassals_to_blood_elves_effect = yes
			}
		}
	}
}
remove_sunwells_effect = {
	clr_wonder_flag = wonder_lightwell_flag
	clr_wonder_flag = wonder_deathwell_flag
	clr_wonder_flag = wonder_felwell_flag
	clr_wonder_flag = wonder_voidwell_flag
}
add_sunwell_effect = {
	clr_global_flag = sunwell_is_being_restored_flag
	394 = {
		wonder = {
			remove_sunwells_effect = yes
			set_name = wonder_sunwell_sunwell
			set_wonder_damaged = no
		}
	}
}
add_lightwell_effect = {
	clr_global_flag = sunwell_is_being_restored_flag
	clr_global_flag = sunwell_naaru_spark_flag
	394 = {
		wonder = {
			remove_sunwells_effect = yes
			set_wonder_flag = wonder_lightwell_flag
			set_name = wonder_sunwell_sunwell
			set_wonder_damaged = no
		}
	}
}
add_deathwell_effect = {
	add_deathwell_no_restore_effect = yes
	394 = { wonder = { set_wonder_damaged = no } }
}
add_deathwell_no_restore_effect = {
	clr_global_flag = sunwell_is_being_restored_flag
	394 = {
		wonder = {
			remove_sunwells_effect = yes
			set_wonder_flag = wonder_deathwell_flag
			set_name = wonder_sunwell_deathwell
		}
	}
}
add_felwell_effect = {
	clr_global_flag = felwell_restoring_flag
	clr_global_flag = sunwell_is_being_restored_flag
	394 = {
		wonder = {
			remove_sunwells_effect = yes
			set_wonder_flag = wonder_felwell_flag
			set_name = wonder_sunwell_felwell
			set_wonder_damaged = no
		}
	}
}
add_voidwell_effect = {
	clr_global_flag = voidwell_restoring_flag
	clr_global_flag = sunwell_is_being_restored_flag
	394 = {
		wonder = {
			remove_sunwells_effect = yes
			set_wonder_flag = wonder_voidwell_flag
			set_name = wonder_sunwell_voidwell
		}
	}
}

add_max_depopulation_effect = {
	if = {
		limit = {
			has_dlc = "Reapers"

			NOT = { has_province_modifier = depopulated_3 }
			any_province_holding = {
				OR = {
					holding_type = city
					holding_type = temple
					holding_type = castle
					holding_type = tribal
				}
			}
		}
		hidden_effect = { set_variable = { which = prosperity_value value = 0 } }
		if = { limit = { has_province_modifier = prosperity_modifier_1 } remove_province_modifier = prosperity_modifier_1 }
		if = { limit = { has_province_modifier = prosperity_modifier_2 } remove_province_modifier = prosperity_modifier_2 }
		if = { limit = { has_province_modifier = prosperity_modifier_3 } remove_province_modifier = prosperity_modifier_3 }
		if = { limit = { has_province_modifier = depopulated_1 } remove_province_modifier = depopulated_1 }
		if = { limit = { has_province_modifier = depopulated_2 } remove_province_modifier = depopulated_2 }
		add_province_modifier = { name = depopulated_3 duration = -1 }
		hidden_effect = {
			clr_province_flag = recent_depopulation_1
			clr_province_flag = recent_depopulation_2
			set_province_flag = recent_depopulation_3
		}
	}
}

cancel_pregnancy_effect = {
	if = {
		limit = {
			is_pregnant = yes
		}
		hidden_effect = {
			remove_trait = pregnancy_finishing
			remove_trait = in_hiding
			remove_trait = travelling
			remove_character_modifier = mother_praying_health
			remove_character_modifier = mother_resting_health
			remove_character_modifier = mother_partying_health
			clr_character_flag = mother_asked_retirement 
			clr_character_flag = flag_mother_dark_rest
			clr_character_flag = mother_gossip_listening #Safety check, they should already have been removed
			clr_character_flag = mother_gossip_talking
			clr_character_flag = mother_gossip_trusting
			clr_character_flag = mother_gossip_plotting
			clr_character_flag = mother_gossip_envious
			clr_character_flag = mother_gossip_shy
			clr_character_flag = mother_gossip_learning
			clr_character_flag = mother_gossip_content
			clr_character_flag = mother_gossip_gluttonous
			remove_trait = hard_pregnancy

			character_event = { id = HFP.20597 days = 35 } #Clears persistent Physician targets. They are still on on_birth since post-partum complications may require their services.
		}
		
		if = { limit = { trait = pregnant } remove_trait = pregnant }
		cancel_pregnancy = yes
	}
}

remove_has_magical_withdrawal_trait_effect = {
	if = {
		limit = { trait = has_magical_withdrawal }
		remove_trait = has_magical_withdrawal
	}
}

# Adds default traits when new character spawns
add_default_traits = {
	if = {
		limit = {
			NOT = {
				has_game_rule = {
					name = stereotypical_traits
					value = off
				}
			}
			is_adult = yes
		}
		# chaste
		if = {
			limit = { prefer_chaste_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_lustful_effect = yes
				add_trait_silently_chaste_effect = yes
			}
		}
		
		# temperate
		if = {
			limit = { prefer_temperate_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_gluttonous_effect = yes
				add_trait_silently_temperate_effect = yes
			}
		}
		
		# charitable
		if = {
			limit = { prefer_charitable_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_greedy_effect = yes
				add_trait_silently_charitable_effect = yes
			}
		}
		
		# diligent
		if = {
			limit = { prefer_diligent_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_slothful_effect = yes
				add_trait_silently_diligent_effect = yes
			}
		}
		
		# patient
		if = {
			limit = { prefer_patient_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_wroth_effect = yes
				add_trait_silently_patient_effect = yes
			}
		}
		
		# kind
		if = {
			limit = { prefer_kind_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				if = { limit = { trait = envious } remove_trait = envious }
				remove_trait_silently_cruel_effect = yes
				add_trait_silently_kind_effect = yes
			}
		}
		
		# humble
		if = {
			limit = { prefer_humble_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_proud_effect = yes
				add_trait_silently_humble_effect = yes
			}
		}
		
		# lustful
		if = {
			limit = { prefer_lustful_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_chaste_effect = yes
				add_trait_silently_lustful_effect = yes
			}
		}
		
		# gluttonous
		if = {
			limit = { prefer_gluttonous_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_temperate_effect = yes
				add_trait_silently_gluttonous_effect = yes
			}
		}
		
		# greedy
		if = {
			limit = { prefer_greedy_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_charitable_effect = yes
				add_trait_silently_greedy_effect = yes
			}
		}
		
		# slothful
		if = {
			limit = { prefer_slothful_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_diligent_effect = yes
				add_trait_silently_slothful_effect = yes
			}
		}
		
		# wroth
		if = {
			limit = { prefer_wroth_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_patient_effect = yes
				add_trait_silently_wroth_effect = yes
			}
		}
		
		# envious
		if = {
			limit = { prefer_envious_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_kind_effect = yes
				add_trait_silently_envious_effect = yes
			}
		}
		
		# proud
		if = {
			limit = { prefer_proud_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_humble_effect = yes
				add_trait_silently_proud_effect = yes
			}
		}
		
		# ambitious
		if = {
			limit = { prefer_ambitious_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_content_effect = yes
				add_trait_silently_ambitious_effect = yes
			}
		}
		
		# arbitrary
		if = {
			limit = { prefer_arbitrary_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_just_effect = yes
				add_trait_silently_arbitrary_effect = yes
			}
		}
		
		# brave
		if = {
			limit = { prefer_brave_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_craven_effect = yes
				add_trait_silently_brave_effect = yes
			}
		}
		
		# content
		if = {
			limit = { prefer_content_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_ambitious_effect = yes
				add_trait_silently_content_effect = yes
			}
		}
		
		# craven
		if = {
			limit = { prefer_craven_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_brave_effect = yes
				add_trait_silently_craven_effect = yes
			}
		}
		
		# cruel
		if = {
			limit = { prefer_cruel_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_kind_effect = yes
				add_trait_silently_cruel_effect = yes
			}
		}
		
		# cynical
		if = {
			limit = { prefer_cynical_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_zealous_effect = yes
				add_trait_silently_cynical_effect = yes
			}
		}
		
		# deceitful
		if = {
			limit = { prefer_deceitful_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_honest_effect = yes
				add_trait_silently_deceitful_effect = yes
			}
		}
		
		# erudite
		if = {
			limit = { prefer_erudite_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				if = { limit = { NOT = { trait = erudite } } add_trait = erudite }
			}
		}
		
		# gregarious
		if = {
			limit = { prefer_gregarious_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_shy_effect = yes
				add_trait_silently_gregarious_effect = yes
			}
		}
		
		# honest
		if = {
			limit = { prefer_honest_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				if = { limit = { trait = deceitful } remove_trait = deceitful }
				add_trait_silently_honest_effect = yes
			}
		}
		
		# just
		if = {
			limit = { prefer_just_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				if = { limit = { trait = arbitrary } remove_trait = arbitrary }
				if = {
					limit = { 
						NOR = { 
							trait = just 
							trait = arbitrary
						}
					} 
					add_trait = just
				}
			}
		}
		
		# paranoid
		if = {
			limit = { prefer_paranoid_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_trusting_effect = yes
				if = {
					limit = { 
						NOR = { 
							trait = paranoid 
							trait = trusting
						}
					} 
					add_trait = paranoid
				}
			}
		}
		
		# shy
		if = {
			limit = { prefer_shy_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				remove_trait_silently_gregarious_effect = yes
				add_trait_silently_shy_effect = yes
			}
		}
		
		# stubborn
		if = {
			limit = { prefer_stubborn_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				if = { limit = { NOT = { trait = stubborn } } add_trait = stubborn }
			}
		}
		
		# trusting
		if = {
			limit = { prefer_trusting_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				if = { limit = { trait = paranoid } remove_trait = paranoid }
				if = {
					limit = { 
						NOR = { 
							trait = trusting 
							trait = paranoid
						}
					} 
					add_trait = trusting
				}
			}
		}
		
		# zealous
		if = {
			limit = { prefer_zealous_trait_trigger = yes }
			random = {
				chance = 20
				stereotypical_traits_game_rule_score = yes
				
				if = { limit = { trait = cynical } remove_trait = cynical }
				if = {
					limit = { 
						NOR = { 
							trait = zealous 
							trait = cynical
						}
					} 
					add_trait = zealous
				}
			}
		}
		
		# cannibal_trait
		if = {
			limit = { prefer_cannibal_trait_trigger = yes }
			random = {
				chance = 35
				stereotypical_traits_game_rule_score = yes
				
				additive_modifier = {
					value = 50
					evil_public_religion_trigger = yes
				}
				
				if = {
					limit = { NOT = { trait = cannibal_trait } } 
					add_trait = cannibal_trait
				}
			}
		}
	}
}

set_prev_gfx_effect = {
	PREV = {
		if = {
			limit = { placeholder_gfx_trigger = no }										# These graphical cultures can't get race trait, so...
			gfx_culture_scope = { save_event_target_as = target_gfx_culture }
		}
		else = { culture_scope = { save_event_target_as = target_gfx_culture } }		# ...only PREV's actual culture can be used
	}
	set_graphical_culture = event_target:target_gfx_culture
	# Stops from spawning of cool creatures like...
	# Two-headed ogres
	if = {
		limit = { graphical_culture = twoheadedogregfx }
		set_graphical_culture = ogre
	}
	# Qiraji emperors
	else_if = {
		limit = { graphical_culture = qirajiemperorgfx }
		set_graphical_culture = qiraji
	}
	# C'thraxxi
	else_if = {
		limit = { graphical_culture = cthraxxigfx }
		set_graphical_culture = nraqi
	}
	# Ancients
	else_if = {
		limit = {
			OR = {
				graphical_culture = protectorgfx
				graphical_culture = ancientwargfx
				graphical_culture = ancientloregfx
				graphical_culture = ancientwindgfx
			}
		}
		set_graphical_culture = night_elf
	}
	clear_event_target = target_gfx_culture
}

create_religious_head_effect = {
	custom_tooltip = {
		text = create_religious_head_effect_tooltip
		create_character = {
			dynasty = none
			culture = ROOT religion = ROOT
			attributes = {
				martial=5 diplomacy=5 stewardship=5 intrigue=5 learning=5
			}
			trait=mastermind_theologian
			trait=diligent trait=zealous trait=ambitious trait=humble
			age = 60
		}
		new_character = {
			save_event_target_as = target_religious_head
			
			character_event = { id = WCRAC.10 }		# Adds race traits
			add_class_religion_trait_effect = yes
			activate_title = { title = PREV status = yes }
			grant_title_no_opinion = PREV
			set_defacto_liege = ROOT
			
			narrative_event = { id = WCREL.10 }
		}
	}
}

plant_world_tree_effect = {
	event_target:target_druid = {
		show_scope_change = no
		if = {
			limit = { religion_group = druidism_group }
			religion_authority = { modifier = new_world_tree }
		}
	}
	event_target:target_title = {
		show_scope_change = no
		set_title_flag = world_tree_title_flag
		if = {
			limit = { title = b_nordrassil }
			add_building = tp_nordrassil
		}
		else = {
			add_building = tp_world_tree
		}
	}
	event_target:target_province = {
		show_scope_change = no
		if = {
			limit = { ROOT = { character = event_target:target_druid } }
			if = {
				limit = { NOT = { num_of_max_settlements = 6 } }
				add_holding_slot = 2
			}
			else_if = {
				limit = { NOT = { num_of_max_settlements = 7 } }
				add_holding_slot = 1
			}
		}
	}
}
corrupt_world_tree_effect = {
	event_target:target_corruptor = {
		show_scope_change = no
		if = {
			limit = { religion = old_gods_worship }
			religion_authority = { modifier = corrupted_world_tree_good }
		}
	}
	event_target:target_title = {
		show_scope_change = no
		if = {
			limit = { has_building = tp_world_tree }
			remove_building = tp_world_tree
		}
		if = {
			limit = { has_building = tp_nordrassil }
			remove_building = tp_nordrassil
			hidden_effect = {
				if = {
					limit = { NOT = { has_global_flag = night_elves_lost_immortality_flag } }
					set_global_flag = night_elves_lost_immortality_flag
					# Delayed notification event
					1921 = { province_event = { id = WCDRU.5500 days = 10 random = 10 } }
				}
			}
		}
		clr_title_flag = world_tree_title_flag
		set_title_flag = nightmare_tree_title_flag
		add_building = tp_nightmare_tree
	}
	event_target:target_province = {
		show_scope_change = no
		
		clr_province_flag = corrupt_world_tree_ongoing_flag
	}
}
burn_world_tree_effect = {
	event_target:target_arsonist = {
		if = {
			limit = { event_target:target_title = { has_title_flag = world_tree_title_flag } }
			add_character_modifier = { name = burned_world_tree_opinion years = 100 }
		}
	}
	event_target:target_title = {
		show_scope_change = no
		if = {
			limit = { has_building = tp_world_tree }
			remove_building = tp_world_tree
		}
		if = {
			limit = { has_building = tp_nordrassil }
			remove_building = tp_nordrassil
			hidden_effect = {
				if = {
					limit = { NOT = { has_global_flag = night_elves_lost_immortality_flag } }
					set_global_flag = night_elves_lost_immortality_flag
					# Delayed notification event
					1921 = { province_event = { id = WCDRU.5500 days = 10 random = 10 } }
				}
			}
		}
		if = {
			limit = { has_building = tp_nightmare_tree }
			remove_building = tp_nightmare_tree
		}
		clr_title_flag = world_tree_title_flag
		clr_title_flag = nightmare_tree_title_flag
	}
	event_target:target_province = {
		show_scope_change = no
		remove_province_modifier = world_tree_province_modifier
		clr_province_flag = corrupt_world_tree_ongoing_flag
		clr_province_flag = burn_world_tree_ongoing_flag
	}
}

### These effects are used to give lands to event_target:target_settler
# Give claim to event_target:target_settler if title holder is player or title if holder is AI
give_claim_or_title_to_target_settler_effect = {
	if = {
		limit = {
			holder_scope = {
				OR = {
					ai = no
					any_liege = { ai = no }
				}
			}
		}
		add_pressed_claim = event_target:target_settler
	}
	else = {
		grant_title_no_opinion = event_target:target_settler
	}
}
# target_settler build new holding or usurp existing one
build_or_give_holding_to_target_settler_effect = {
	hidden_effect = {
		if = {
			limit = { NOT = { num_of_max_settlements = 7 } }
			add_holding_slot = 1
		}
		if = {
			limit = { has_empty_holding = yes }
			if = {
				limit = { event_target:target_settler = { has_character_flag = prefer_temples_flag } }
				build_holding = { type = temple holder = event_target:target_settler }
			}
			else_if = {
				limit = { event_target:target_settler = { has_character_flag = prefer_cities_flag } }
				build_holding = { type = city holder = event_target:target_settler }
			}
			else = {
				build_holding = { type = castle holder = event_target:target_settler }
			}
		}
		else = {	# In case when new holding can't be created give just something to save from game over
			random_province_holding = {
				limit = { is_capital = no }
				preferred_limit = {
					holding_type = temple
					event_target:target_settler = { has_character_flag = prefer_temples_flag }
				}
				preferred_limit = {
					holding_type = city
					event_target:target_settler = { has_character_flag = prefer_cities_flag }
				}
				preferred_limit = {
					holding_type = castle
				}
				grant_title_no_opinion = event_target:target_settler
			}
		}
	}
}
# Sets culture and religion, upgrade holdings
cleanup_province_as_target_settler_effect = {
	hidden_effect = {
		location = {
			show_scope_change = no
			
			if = {
				limit = {
					has_province_modifier = undead_province
					event_target:target_settler = {
						NOT = {
							trait = being_undead

							religion_group = necromancy_group
						}
					}
				}
				remove_province_modifier = undead_province
			}
			remove_province_modifier = sold_off_land
            remove_province_modifier = thieves_guild
            remove_province_modifier = incompetent_rule
            remove_province_modifier = smugglers_ring
            remove_province_modifier = highway_robber_band
            remove_province_modifier = excessive_bureaucracy
            remove_province_modifier = peasant_unrest
            any_province_holding = {
                remove_holding_modifier = new_administration
                remove_holding_modifier = recently_conquered
                refill_holding_levy = yes
            }
			
			# Upgrade tribal if there's one
			if = {
				limit = { holder_scope = { character = event_target:target_settler } }
				upgrade_province_as_target_settler_effect = yes
			}
		
			culture = event_target:target_settler
			religion = event_target:target_settler
		}
	}
}
# Upgrade tribal if there's one as target_settler prefer
upgrade_province_as_target_settler_effect = {
	hidden_effect = {
		if = {
			limit = { any_province_holding = { holding_type = tribal } }
			random_province_holding = {
				limit = { holding_type = tribal }
				make_capital_holding = yes
				if = {
					limit = { event_target:target_settler = { has_character_flag = prefer_temples_flag } }
					convert_tribal_to_temple_effect = yes
				}
				else_if = {
					limit = { event_target:target_settler = { has_character_flag = prefer_cities_flag } }
					convert_tribal_to_city_effect = yes
				}
				else = {
					convert_tribal_to_castle_effect = yes
				}
			}
		}
	}
}
# target_settler and its people settle here
settle_as_target_settler_effect = {
	if = {
		limit = { holder_scope = { NOT = { character = event_target:target_settler } } }

		location = {
			show_scope_change = no
			
			# "Copy" techs of target_settler
			copy_target_settler_techs_effect = yes
			
			# event_target:target_settler build new holding or usurp existing one
			build_or_give_holding_to_target_settler_effect = yes
		}
		
		# Give claim to event_target:target_settler if title holder is player or title if holder is AI
		give_claim_or_title_to_target_settler_effect = yes
		
		# Sets culture and religion, upgrade holdings
		cleanup_province_as_target_settler_effect = yes
		
		# Used in scripted effects
		set_title_flag = new_title_flag	# Note: this flag isn't removed
	}
}
# Clear settler flags and other stuff
clear_settler_flag_effect = {
	hidden_effect = {
		event_target:target_settler = {
			clr_character_flag = prefer_temples_flag
			clr_character_flag = prefer_cities_flag
		}
	}
}
# If you're not independent ruler, gives old titles to liege
give_old_titles_to_heir_effect = {
	hidden_effect = {
		if = {
			limit = {
				is_ruler = yes
				independent = no
			}
			liege = { save_event_target_as = target_liege }
			# Picks who should be target_heir
			if = {
				limit = {
					any_dynasty_member = {
						is_alive = yes
						is_dying = no
						
						is_ruler = no
						
						religion = PREV
						culture = PREV
						
						can_resettle_trigger = yes
						same_sex = PREV
						is_heir = no
					}
				}
				random_dynasty_member = {
					limit = {
						is_alive = yes
						is_dying = no
						
						is_ruler = no
						
						religion = PREV
						culture = PREV
						
						can_resettle_trigger = yes
						same_sex = PREV
						is_heir = no
					}
					preferred_limit = {
						is_30_physical_age_trigger = no
					}
					preferred_limit = {
						is_40_physical_age_trigger = no
					}

					save_event_target_as = target_heir
				}
			}
			else = {
				liege = { save_event_target_as = target_heir }
			}
			
			# Gives titles
			any_demesne_title = {
				limit = {
					controls_religion = no 		# You still guide your people
					is_titular = no				# No one cares about titular titles, take them
					title_can_be_lost_trigger = yes
					NOT = { has_title_flag = new_title_flag }
					trigger_if = {
						limit = { tier = BARON }
						county = { NOT = { has_title_flag = new_title_flag } }
					}
				}
				grant_title_no_opinion = event_target:target_heir
				if = {
					limit = { tier = COUNT }
					location = {
						culture = event_target:target_heir
						religion = event_target:target_heir
					}
				}
			}
			# Transfers remaining vassals
			any_vassal = {
				limit = { dejure_liege_title = { NOT = { has_title_flag = new_title_flag } } }
				if = {
					limit = { lower_tier_than = event_target:target_heir }
					set_defacto_liege = event_target:target_heir
				}
				else = {
					set_defacto_liege = event_target:target_liege
				}
			}
			# Makes you independent
			set_defacto_liege = THIS
			# Enslave target_heir
			event_target:target_heir = {
				if = {
					limit = { NOT = { character = event_target:target_liege } }
					set_defacto_liege = event_target:target_liege
				}
			}
			
			clear_event_target = target_liege
			clear_event_target = target_heir
		}
	}
}
# Declares war against player
target_settler_declare_war_effect = {
	hidden_effect = {
		if = {
			limit = {
				holder_scope = {
					NOT = { character = event_target:target_settler }
					top_liege = { NOT = { character = event_target:target_settler } }
				}
			}
			holder_scope = {
				top_liege = {
					# If has 2 or more claims, claims all
					if = {
						limit = {
							event_target:target_settler = {
								can_use_cb = {
									target = PREV
									casus_belli = claim_all
									only_check_triggers = yes
								}
							}
						}
						reverse_unsafe_war = {
							target = event_target:target_settler
							casus_belli = claim_all
						}
					}
					else_if = {
						limit = {
							event_target:target_settler = {
								can_use_cb = {
									target = PREV
									casus_belli = claim
									thirdparty_title = PREVPREVPREV
									only_check_triggers = yes
								}
							}
						}
						reverse_unsafe_war = {
							target = event_target:target_settler
							casus_belli = claim
							thirdparty_title = PREVPREV
						}
					}
				}
			}
		}
	}
}
# "Copy" techs of target_settler
copy_target_settler_techs_effect = {
	if = {
		limit = {
			NOT = { event_target:target_techs = { always = yes } }
		}
		if = {
			limit = { event_target:target_settler = { is_landed = yes } }
			event_target:target_settler = { capital_scope = { save_event_target_as = target_techs } }
		}
		else = {
			event_target:target_settler = { location = { save_event_target_as = target_techs } }
		}
	}
	if = {
		limit = { 
			event_target:target_techs = { always = yes }
		}
		while = {
			count = 8
			limit = { NOT = { has_higher_tech_than = event_target:target_techs } }
			# Military advances
			change_tech = { technology = TECH_INFANTRY value = 1 }
			change_tech = { technology = TECH_CAVALRY value = 1 }
			change_tech = { technology = TECH_SKIRMISH value = 1 }
			change_tech = { technology = TECH_MELEE value = 1 }
			change_tech = { technology = TECH_SIEGE_EQUIPMENT value = 1 }
			change_tech = { technology = TECH_RECRUITMENT value = 1 }
			
			# Economy advances
			change_tech = { technology = TECH_CASTLE_CONSTRUCTION value = 1 }
			change_tech = { technology = TECH_CITY_CONSTRUCTION value = 1 }
			change_tech = { technology = TECH_FORTIFICATIONS_CONSTRUCTION value = 1 }
			change_tech = { technology = TECH_TRADE_PRACTICES value = 1 }
			change_tech = { technology = TECH_CONSTRUCTION value = 1 }
			change_tech = { technology = TECH_NAVAL value = 1 }
			
			# Culture advances
			change_tech = { technology = TECH_NOBLE_CUSTOMS value = 1 }
			change_tech = { technology = TECH_POPULAR_CUSTOMS value = 1 }
			change_tech = { technology = TECH_RELIGIOUS_CUSTOMS value = 1 }
			change_tech = { technology = TECH_MAJESTY value = 1 }
			change_tech = { technology = TECH_CULTURE_FLEX value = 1 }
			change_tech = { technology = TECH_LEGALISM value = 1 }
		}
	}
}

add_soul_shard_effect = {
	add_artifact = soul_shard
	if = {
		limit = {
			any_realm_wonder_upgrade = {
				has_wonder_upgrade = upgrade_soul_extractor
				is_active = yes
			}
		}
		random = {
			chance = 50
			add_artifact = soul_shard
		}
	}
}
add_inflow_of_the_fel_effect = {
	custom_tooltip = {
		text = add_inflow_of_the_fel_tooltip		# To make tooltip shorter
		hidden_effect = { remove_character_modifier = inflow_of_the_fel }
		add_character_modifier = { name = inflow_of_the_fel duration = 1825 }
	}
}
add_inflow_of_the_void_effect = {
	custom_tooltip = {
		text = add_inflow_of_the_void_tooltip		# To make tooltip shorter
		hidden_effect = { remove_character_modifier = inflow_of_the_void }
		add_character_modifier = { name = inflow_of_the_void duration = 1825 }
	}
}

add_blood_trait_effect = {
	if = {
		limit = {
			event_target:target_father = { always = yes }
			event_target:target_mother = { always = yes }
		}
		if = {
			limit = {
				event_target:target_father = {
					event_target:target_mother = {
						OR = {
							has_prev_race_trigger = no
							has_prev_blood_trigger = yes
						}
					}
				}
			}
			if = {
				limit = {
					NOT = { trait = creature_human }
					OR = {
						event_target:target_father = { trait = creature_human }
						event_target:target_mother = { trait = creature_human }
						AND = {
							event_target:target_father = { trait = blood_human }
							event_target:target_mother = { trait = blood_human }
						}
					}
				}
				add_trait = blood_human
			}
			else_if = {
				limit = {
					NOT = { is_orc_trigger = yes }
					OR = {
						event_target:target_father = { is_orc_trigger = yes }
						event_target:target_mother = { is_orc_trigger = yes }
						AND = {
							event_target:target_father = { trait = blood_orc }
							event_target:target_mother = { trait = blood_orc }
						}
					}
				}
				add_trait = blood_orc
			}
			else_if = {
				limit = {
					NOT = { trait = creature_ogre }
					OR = {
						event_target:target_father = { trait = creature_ogre }
						event_target:target_mother = { trait = creature_ogre }
						AND = {
							event_target:target_father = { trait = blood_ogre }
							event_target:target_mother = { trait = blood_ogre }
						}
					}
				}
				add_trait = blood_ogre

				# Orc-ogre hybrids look like brown orcs
				if = {
					limit = {
						OR = {
							graphical_culture = orcgfx
							graphical_culture = orcgraygfx
						}
					}
					set_graphical_culture = maghar
				}
			}
			else_if = {
				limit = {
					NOT = { is_high_elf_trigger = yes }
					OR = {
						event_target:target_father = { is_high_elf_trigger = yes }
						event_target:target_mother = { is_high_elf_trigger = yes }
						AND = {
							event_target:target_father = { trait = blood_high_elf }
							event_target:target_mother = { trait = blood_high_elf }
						}
					}
				}
				add_trait = blood_high_elf
			}
			else_if = {
				limit = {
					NOT = { is_eredar_trigger = yes }
					OR = {
						event_target:target_father = { is_eredar_trigger = yes }
						event_target:target_mother = { is_eredar_trigger = yes }
						AND = {
							event_target:target_father = { trait = blood_draenei }
							event_target:target_mother = { trait = blood_draenei }
						}
					}
				}
				add_trait = blood_draenei
			}
			else_if = {
				limit = {
					NOT = { trait = creature_vrykul }
					OR = {
						event_target:target_father = { trait = creature_vrykul }
						event_target:target_mother = { trait = creature_vrykul }
						AND = {
							event_target:target_father = { trait = blood_vrykul }
							event_target:target_mother = { trait = blood_vrykul }
						}
					}
				}
				add_trait = blood_vrykul
			}
			else_if = {
				limit = {
					NOT = { trait = creature_magnataur }
					OR = {
						event_target:target_father = { trait = creature_magnataur }
						event_target:target_mother = { trait = creature_magnataur }
						AND = {
							event_target:target_father = { trait = blood_magnataur }
							event_target:target_mother = { trait = blood_magnataur }
						}
					}
				}
				add_trait = blood_magnataur
			}
			else_if = {
				limit = {
					NOT = { trait = creature_taunka }
					OR = {
						event_target:target_father = { trait = creature_taunka }
						event_target:target_mother = { trait = creature_taunka }
						AND = {
							event_target:target_father = { trait = blood_taunka }
							event_target:target_mother = { trait = blood_taunka }
						}
					}
				}
				add_trait = blood_taunka
			}
			else_if = {
				limit = {
					NOT = { trait = creature_night_elf }
					OR = {
						event_target:target_father = { trait = creature_night_elf }
						event_target:target_mother = { trait = creature_night_elf }
						AND = {
							event_target:target_father = { trait = blood_night_elf }
							event_target:target_mother = { trait = blood_night_elf }
						}
					}
				}
				add_trait = blood_night_elf
			}
			else_if = {
				limit = {
					NOT = { trait = creature_tauren }
					OR = {
						event_target:target_father = { trait = creature_tauren }
						event_target:target_mother = { trait = creature_tauren }
						AND = {
							event_target:target_father = { trait = blood_tauren }
							event_target:target_mother = { trait = blood_tauren }
						}
					}
				}
				add_trait = blood_tauren
			}
			else_if = {
				limit = {
					NOT = { trait = creature_centaur }
					OR = {
						event_target:target_father = { trait = creature_centaur }
						event_target:target_mother = { trait = creature_centaur }
						AND = {
							event_target:target_father = { trait = blood_centaur }
							event_target:target_mother = { trait = blood_centaur }
						}
					}
				}
				add_trait = blood_centaur
			}
			else_if = {
				limit = {
					NOT = { trait = creature_frostnymph }
					OR = {
						event_target:target_father = { trait = creature_frostnymph }
						event_target:target_mother = { trait = creature_frostnymph }
						AND = {
							event_target:target_father = { trait = blood_frostnymph }
							event_target:target_mother = { trait = blood_frostnymph }
						}
					}
				}
				add_trait = blood_frostnymph
			}
			else_if = {
				limit = {
					NOT = {
						trait = creature_dryad
					}
					OR = {
						event_target:target_father = { trait = creature_dryad }
						event_target:target_mother = { trait = creature_dryad }
						AND = {
							event_target:target_father = { trait = blood_dryad }
							event_target:target_mother = { trait = blood_dryad }
						}
					}
				}
				add_trait = blood_dryad
			}
			else_if = {
				limit = {
					NOT = { trait = creature_highborne }
					OR = {
						event_target:target_father = { trait = creature_highborne }
						event_target:target_mother = { trait = creature_highborne }
						AND = {
							event_target:target_father = { trait = blood_highborne }
							event_target:target_mother = { trait = blood_highborne }
						}
					}
				}
				add_trait = blood_highborne
			}
			else_if = {
				limit = {
					NOT = { trait = creature_lothraxim }
					OR = {
						event_target:target_father = { trait = creature_lothraxim }
						event_target:target_mother = { trait = creature_lothraxim }
						AND = {
							event_target:target_father = { trait = blood_lothraxim }
							event_target:target_mother = { trait = blood_lothraxim }
						}
					}
				}
				add_trait = blood_lothraxim
			}
		}
	}
	# Mok'nathal has ogre blood even without parents
	else_if = {
		limit = {
			is_orc_trigger = yes
			culture = moknathal
		}
		add_trait = blood_ogre

		# Orc-ogre hybrids look like brown orcs
		if = {
			limit = {
				OR = {
					graphical_culture = orcgfx
					graphical_culture = orcgraygfx
				}
			}
			set_graphical_culture = maghar
		}
	}
	else_if = {
		limit = {
			trait = creature_human
			culture = tirassian
		}
		random = {
			chance = 5
			add_trait = blood_vrykul
		}
	}
}

# Fixes immortal age
rejuvenate_effect = {
	hidden_effect = {
		if = {
			limit = {
				# immortal = yes
				age = 40
			}
			log = "(IMMORTALITY) [This.GetBestName] is rejuvenated"

			export_to_variable = { which = "myAge" value = age }
			change_variable = { which = "myAge" value = -30 }
			set_variable = { which = "myNegativeAge" which = "myAge" }
			multiply_variable = { which = "myNegativeAge" value = -1 }
			
			add_age = "myNegativeAge"
			
			set_character_flag = rejuvenated_flag
		}
	}
}
add_age_back_effect = {
	hidden_effect = {
		if = {
			limit = { has_character_flag = rejuvenated_flag }
			log = "(IMMORTALITY) [This.GetBestName] gets age back"

			clr_character_flag = rejuvenated_flag
			
			add_age = "myAge"
			
			set_variable = { which = "myAge" value = 0 }
			set_variable = { which = "myNegativeAge" value = 0 }
		}
	}
}
clear_rejuvenate_effect = {
	clr_character_flag = rejuvenated_flag
	
	set_variable = { which = "myAge" value = 0 }
	set_variable = { which = "myNegativeAge" value = 0 }
}

ruler_sell_land_to_holy_order_effect = {
	event_target:target_ruler = {
		# Gives gold, piety or prestige
		if = {
			limit = {
				event_target:target_desired_title = { tier = DUKE }
				# Has more then 2 provinces in this duchy
				any_demesne_province = {
					count = 2
					de_jure_liege = event_target:target_desired_title
				}
			}
			if = {
				limit = { religion = event_target:target_order_leader }
				piety = 1000
			}
			else = { prestige = 1000 }
			wealth = 800
		}
		else = {
			if = {
				limit = { religion = event_target:target_order_leader }
				piety = 500
			}
			else = { prestige = 500 }
			wealth = 400
		}

		# Free vassals # Must be before title granting because otherwise ruler gets title of vassal when he lose all titles
		if = {
			limit = { is_ruler = yes }
			any_vassal = {
				limit = {
					NOT = { tier = BARON }
					any_demesne_title = {
						OR = {
							title = event_target:target_desired_title
							de_jure_liege_or_above = event_target:target_desired_title
						}
					}
				}
				show_scope_change = no

				# If ruler isn't independent, transfers vassals to top liege...
				if = {
					limit = {
						event_target:target_ruler = { independent = no }
					}
					set_defacto_liege = top_liege
				}
				# ...otherwise, make vassals independent
				else = {
					set_defacto_liege = THIS
				}
			}
		}
		
		if = {
			limit = {
				event_target:target_desired_title = { tier = DUKE }
			}

			event_target:target_desired_title = {
				show_scope_change = no
				any_direct_de_jure_vassal_title = {
					limit = { holder_scope = { character = event_target:target_ruler } }
					show_scope_change = no
					
					ruler_grant_land_to_holy_order_effect = yes
				}
			}
		}
		else = {
			event_target:target_desired_title = {
				show_scope_change = no

				if = {
					limit = { holder_scope = { character = event_target:target_ruler } }
					ruler_grant_land_to_holy_order_effect = yes
				}
			}
		}
	}
}
ruler_grant_land_to_holy_order_effect = {
	event_target:target_order_leader = {
		show_scope_change = no

		hidden_effect = {
			gain_settlements_under_title = {
				title = PREV
				enemy = event_target:target_ruler
			}
		}
		grant_title_no_opinion = PREV
	}
	
	# Sets culture and religion, upgrade holdings
	cleanup_province_as_target_settler_effect = yes
}

add_libram_of_justice_effect = {
	add_artifact = libram_of_justice
	new_artifact = {
		set_description = libram_of_justice_key
	}
	create_bloodline = {
		type = silver_hand_justice
	}
}
add_libram_of_retribution_effect = {
	add_artifact = libram_of_retribution
	new_artifact = {
		set_description = libram_of_retribution_key
	}
	create_bloodline = {
		type = silver_hand_retribution
	}
}
add_libram_of_protection_effect = {
	add_artifact = libram_of_protection
	new_artifact = {
		set_description = libram_of_protection_key
	}
	create_bloodline = {
		type = silver_hand_protection
	}
}
add_libram_of_holiness_effect = {
	add_artifact = libram_of_holiness
	new_artifact = {
		set_description = libram_of_holiness_key
	}
	create_bloodline = {
		type = silver_hand_holiness
	}
}
add_libram_of_compassion_effect = {
	add_artifact = libram_of_compassion
	new_artifact = {
		set_description = libram_of_compassion_key
	}
	create_bloodline = {
		type = silver_hand_compassion
	}
}

add_random_martial_education_effect = {
	random_list = {
		15 = {
			add_trait = misguided_warrior
		}
		35 = {
			add_trait = tough_soldier
		}
		35 = {
			add_trait = skilled_tactician
		}
		15 = {
			add_trait = brilliant_strategist
		}
	}
}
add_random_intrigue_education_effect = {
	random_list = {
		15 = {
			add_trait = amateurish_plotter
		}
		35 = {
			add_trait = flamboyant_schemer
		}
		35 = {
			add_trait = intricate_webweaver
		}
		15 = {
			add_trait = elusive_shadow
		}
	}
}
add_random_learning_education_effect = {
	random_list = {
		15 = {
			add_trait = detached_priest
		}
		35 = {
			add_trait = martial_cleric
		}
		35 = {
			add_trait = scholarly_theologian
		}
		15 = {
			add_trait = mastermind_theologian
		}
	}
}

spawn_heavy_sea_ravagers_effect = {
	random_list = {
		25 = {
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					light_infantry = { 15 15 }
					heavy_infantry = { 50 50 }
					pikemen = { 15 15 }
					archers = { 20 20 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 1.5
				maintenance = no
			}
		}
		40 = {
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					light_infantry = { 15 15 }
					heavy_infantry = { 50 50 }
					pikemen = { 15 15 }
					archers = { 20 20 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 2.25
				maintenance = no
			}
		}
		25 = {
			modifier = {
				factor = 5
				realm_size = 150
			}
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					light_infantry = { 15 15 }
					heavy_infantry = { 50 50 }
					pikemen = { 15 15 }
					archers = { 20 20 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 3
				maintenance = no
			}
		}
		10 = {
			modifier = {
				factor = 12.5
				realm_size = 150
			}
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					light_infantry = { 15 15 }
					heavy_infantry = { 50 50 }
					pikemen = { 15 15 }
					archers = { 20 20 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 3.75
				maintenance = no
			}
		}
	}
	spawn_fleet = {
		province = closest # closest sea zone
		owner = ROOT
		cannot_inherit = yes
		troops = {
			galleys = { 150 150 }
		}
	}
}
spawn_light_sea_ravagers_effect = {
	random_list = {
		25 = {
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					archers = { 30 30 }
					thralls = { 70 70 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 1.5
				maintenance = no
			}
		}
		40 = {
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					archers = { 30 30 }
					thralls = { 70 70 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 2.25
				maintenance = no
			}
		}
		25 = {
			modifier = {
				factor = 5
				realm_size = 150
			}
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					archers = { 30 30 }
					thralls = { 70 70 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 3
				maintenance = no
			}
		}
		10 = {
			modifier = {
				factor = 12.5
				realm_size = 150
			}
			# Must be 100 in total
			spawn_unit = {
				province = event_target:target_province
				home = event_target:target_province
				owner = ROOT
				troops = {
					archers = { 30 30 }
					thralls = { 70 70 }
				}
				attrition = 0
				scaled_by_biggest_garrison = 3.75
				maintenance = no
			}
		}
	}
	spawn_fleet = {
		province = closest # closest sea zone
		owner = ROOT
		cannot_inherit = yes
		troops = {
			galleys = { 150 150 }
		}
	}
}

# spawn_qiraji_troops_effect = {
	# custom_tooltip = {
		# text = spawn_small_qiraji_troops_tooltip
		# spawn_small_qiraji_troops_effect = yes
		# if = {
			# limit = {
				# has_game_rule = {
					# name = qiraji_invasion
					# value = x0_5
				# }
			# }
			# spawn_small_qiraji_troops_effect = yes
		# }
		# if = {
			# limit = {
				# has_game_rule = {
					# name = qiraji_invasion
					# value = default
				# }
			# }
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
		# }
		# if = {
			# limit = {
				# has_game_rule = {
					# name = qiraji_invasion
					# value = x1_5
				# }
			# }
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
		# }
		# if = {
			# limit = {
				# has_game_rule = {
					# name = qiraji_invasion
					# value = x2
				# }
			# }
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
			# spawn_small_qiraji_troops_effect = yes
		# }
	# }
# }
# spawn_small_qiraji_troops_effect = {
	# spawn_unit = {
		# owner = THIS
		# province = event_target:target_province
		# home = event_target:target_province
		# troops = {
			# light_infantry = { 250 250 }
			# knights = { 70 70 }
			# swarm = { 1000 1000 }
		# }
		# attrition = 0
		# maintenance = no
	# }
# }

spawn_pack_troops_effect = {
	# Must be 100 in total
	spawn_unit = {
		province = event_target:target_province
		home = event_target:target_province
		owner = THIS
		troops = {
			heavy_infantry = { 60 60 }
			animals = { 40 40 }
		}
		cannot_inherit = yes
		attrition = 0
		scaled_by_biggest_garrison = 1.5
		merge = yes
		can_toggle_looting = no
		is_looter = yes
		reinforces = yes
		maintenance = no
	}
}
spawn_bitten_troops_effect = {
	spawn_unit = {
		province = event_target:target_province
		home = event_target:target_province
		owner = THIS
		troops = {
			animals = { 1 1 }
		}
		cannot_inherit = yes
		attrition = 0
		scaled_by_biggest_garrison = 0.2
		merge = yes
		can_toggle_looting = no
		is_looter = yes
		reinforces = yes
		maintenance = no
	}
}

# Based of leave_council_position_effect
leave_council_position_no_opinion_effect = {
	liege = {
		set_character_flag = swapping_councillors
		add_character_modifier = {
			name = councillors_changed_jobs
			duration = 365
			hidden = yes
		}
	}

	if = {
		limit = { has_job_title = job_chancellor }
		remove_title = job_chancellor
	}
	if = {
		limit = { has_job_title = job_marshal }
		remove_title = job_marshal
	}
	if = {
		limit = { has_job_title = job_treasurer }
		remove_title = job_treasurer
	}
	if = {
		limit = { has_job_title = job_spymaster }
		remove_title = job_spymaster
	}
	if = {
		limit = { has_job_title = job_spiritual }
		remove_title = job_spiritual
	}
	if = {
		limit = { has_minor_title = title_councilmember_king }
		remove_title = title_councilmember_king
	}
	if = {
		limit = { has_minor_title = title_councilmember_emperor }
		remove_title = title_councilmember_emperor
	}
	
	# Warcraft
	if = {
		limit = { has_minor_title = title_shadow_council_member_1 }
		remove_title = title_shadow_council_member_1
	}
	if = {
		limit = { has_minor_title = title_shadow_council_member_2 }
		remove_title = title_shadow_council_member_2
	}
	if = {
		limit = { has_minor_title = title_shadow_council_member_3 }
		remove_title = title_shadow_council_member_3
	}

	liege = {
		clr_character_flag = swapping_councillors
	}
}

remove_offmap_power_effect = {
	remove_character_modifier = touch_of_chaos
	remove_character_modifier = touch_of_madness
	remove_character_modifier = dreams_of_deep
	remove_character_modifier = dreams_of_nyalotha
	remove_character_modifier = gaze_of_death
	remove_character_modifier = gaze_of_undeath
}

# Gives cannibal_trait to your courtiers
court_share_cannibal_trait_effect = {
	hidden_effect = {
		any_courtier = {
			limit = {
				is_adult = yes
				is_incapable = no
				prisoner = no
				is_inaccessible_trigger = no

				is_ruler = no

				religion = ROOT

				NOT = { trait = cannibal_trait }
			}
			random = {
				chance = 50
				add_trait = cannibal_trait
			}
		}
	}
}

# Clear mortal traits because you became immortal
clr_mortal_traits_effect = {
	if = {
		limit = {
			trait = infertile
			need_infertile_trait_trigger = no
		}
		remove_trait = infertile
	}
	if = {
		limit = { trait = infirm }
		remove_trait = infirm
	}
	if = {
		limit = { trait = incapable }
		remove_trait = incapable
	}
}

# Clears flags that undead gets during rising
clr_undead_raising_flags = {
	if = {
		limit = { has_character_flag = being_raised_flag }
		clr_character_flag = being_raised_flag
	}
	if = {
		limit = { has_character_flag = ask_for_dark_gift_used_flag }
		clr_character_flag = ask_for_dark_gift_used_flag
	}
}

# Clears flags that necromancer gets during rising
clr_necromancer_raising_flags = {
	if = {
		limit = {
			has_character_flag = raising_undead_flag
		}
		clr_character_flag = raising_undead_flag
	}
}

# Removes Mind Control modifiers
remove_mind_control_modifier_effect = {
	if = { limit = { has_character_modifier = mind_control_1 } remove_character_modifier = mind_control_1 }
	if = { limit = { has_character_modifier = mind_control_2 } remove_character_modifier = mind_control_2 }
	if = { limit = { has_character_modifier = mind_control_3 } remove_character_modifier = mind_control_3 }
	if = { limit = { has_character_modifier = mind_control_4 } remove_character_modifier = mind_control_4 }
}
# Increases stage of Mind Control and makes undead loyal
increase_mind_control_stage_effect = {
	hidden_effect = {
		# Changes religion of your provinces
		change_undead_demesne_provinces_religion_to_root_effect = yes
	}
	
	if = {
		limit = {
			NOR = {
				has_character_modifier = mind_control_1
				has_character_modifier = mind_control_2
				has_character_modifier = mind_control_3
				has_character_modifier = mind_control_4
			}
			has_landed_title = e_scourge
		}
		hidden_effect = { set_variable = { which = mind_control_power value = 100 } }
		add_character_modifier = { name = mind_control_1 duration = -1 }
		if = {
			limit = { has_landed_title = e_scourge }
			hidden_effect = {
				any_realm_character = {
					limit = {
						NOT = { character = ROOT }
					
						can_be_mind_controlled_by_scourge_trigger = yes
					}
					character_event = { id = WCUND.1108 days = 1 }		# Check religion
				}
			}
		}
	}
	else = {
		remove_mind_control_modifier_effect = yes
		if = {
			limit = {
				check_variable = { which = mind_control_power value = 75 }
				NOT = { has_character_modifier = mind_control_1 }
			}
			add_character_modifier = { name = mind_control_1 duration = -1 }
			if = {
				limit = { has_landed_title = e_scourge }
				hidden_effect = {
					any_realm_character = {
						limit = {
							NOT = { character = ROOT }
						
							can_be_mind_controlled_by_scourge_trigger = yes
						}
						character_event = { id = WCUND.1108 days = 1 }		# Check religion
					}
				}
			}
		}
		else_if = {
			limit = {
				check_variable = { which = mind_control_power value = 50 }
				NOT = { has_character_modifier = mind_control_2 }
			}
			add_character_modifier = { name = mind_control_2 duration = -1 }
			if = {
				limit = { has_landed_title = e_scourge }
				hidden_effect = {
					any_realm_character = {
						limit = {
							NOT = { character = ROOT }
						
							can_be_mind_controlled_by_scourge_trigger = yes
						}
						random = {
							chance = 66
							character_event = { id = WCUND.1108 days = 1 }		# Check religion
						}
					}
				}
			}
		}
		else = {
			add_character_modifier = { name = mind_control_3 duration = -1 }
			if = {
				limit = { has_landed_title = e_scourge }
				hidden_effect = {
					any_realm_character = {
						limit = {
							NOT = { character = ROOT }
						
							can_be_mind_controlled_by_scourge_trigger = yes
						}
						random = {
							chance = 33
							character_event = { id = WCUND.1108 days = 1 }		# Check religion
						}
					}
				}
			}
		}
	}
}
# Decreases stage of Mind Control and makes undead disloyal
decrease_mind_control_stage_effect = {
	remove_mind_control_modifier_effect = yes
	if = {
		limit = {
			NOT = { has_character_modifier = mind_control_4 }
			NOT = { check_variable = { which = mind_control_power value = 25 } }
		}
		add_character_modifier = { name = mind_control_4 duration = -1 }
		hidden_effect = {
			any_realm_lord = {
				limit = {
					NOT = { character = ROOT }
					
					NOT = { tier = BARON } #Barons stay loyal
					
					can_break_scourge_mind_control_trigger = yes
				}
				random = {
					chance = 100
					modifier = {
						factor = 0.1
						location = { region = world_northrend }
					}
					free_from_lich_king_effect = yes
				}
			}
		}
	}
	else_if = {
		limit = {
			NOT = { has_character_modifier = mind_control_3 }
			NOT = { check_variable = { which = mind_control_power value = 50 } }
		}
		add_character_modifier = { name = mind_control_3 duration = -1 }
		hidden_effect = {
			any_realm_lord = {
				limit = {
					NOT = { character = ROOT }
					
					NOT = { tier = BARON } #Barons stay loyal
					
					can_break_scourge_mind_control_trigger = yes
				}
				random = {
					chance = 66
					modifier = {
						factor = 0.1
						location = { region = world_northrend }
					}
					free_from_lich_king_effect = yes
				}
			}
		}
	}
	else = {
		add_character_modifier = { name = mind_control_2 duration = -1 }
		hidden_effect = {
			any_realm_lord = {
				limit = {
					NOT = { character = ROOT }
					
					NOT = { tier = BARON } #Barons stay loyal
					
					can_break_scourge_mind_control_trigger = yes
				}
				random = {
					chance = 33
					modifier = {
						factor = 0.1
						location = { region = world_northrend }
					}
					free_from_lich_king_effect = yes
				}
			}
		}
	}
}

support_scarlet_light_effect = {
	# Vassals of d_order_of_the_silver_hand become vassals of d_scarlet_crusade
	if = {
		limit = {
			is_landed = yes
			
			de_facto_liege = d_order_of_the_silver_hand
		}
		set_defacto_liege = d_scarlet_crusade
	}
	
	religion = scarlet_light
	if = {
		limit = { has_secret_religion = yes }
		clear_secret_religion = yes
	}
	if = {
		limit = { NOT = { trait = zealous } }
		add_trait = zealous
	}

	if = {
		limit = {
			is_landed = yes
			
			higher_real_tier_than = BARON
		}
		capital_scope = { 
			if = {
				limit = {
					NOT = { religion = scarlet_light }
					culture_group = human_group
					holder_scope = { character = PREVPREV }
				}
				religion = scarlet_light
			}
		}
		
		hidden_effect = {
			any_courtier_or_vassal = {
				limit = {
					OR = {
						is_ruler = no
						tier = BARON
					}
					
					religion = holy_light
					NOT = { religion = scarlet_light }
					OR = {
						trait = zealous
						has_evil_trait_trigger = yes
						
						is_close_relative = PREV	# Close relatives pick Scarlet religion
					}
				}
				religion = scarlet_light
				clear_secret_religion = yes
			}
		}
	}
}
support_argent_dawn_effect = {
	piety = 100
	
	# Vassals of d_order_of_the_silver_hand become vassals of d_argent_dawn
	if = {
		limit = {
			is_landed = yes
			
			de_facto_liege = d_order_of_the_silver_hand
			capital_scope = { region = world_eastern_kingdoms_lordaeron }
		}
		set_defacto_liege = d_argent_dawn
	}
}

# Creates d_argent_dawn
create_d_argent_dawn_effect = {
	# Picks Highlord
	# Raymond
	if = {
		limit = { c_60625 = { is_potential_argent_leader_trigger = yes } }
		c_60625 = { save_event_target_as = target_argent_highlord }
	}
	# Maxwell Tyrosus
	else_if = {
		limit = { c_60650 = { is_potential_argent_leader_trigger = yes } }
		c_60650 = { save_event_target_as = target_argent_highlord }
	}
	# Member of the Silver Hand
	else_if = {
		limit = {
			d_order_of_the_silver_hand = {
				has_holder = yes
				holder_scope = {
					any_courtier = {
						is_potential_argent_leader_trigger = yes
					}
				}
			}
		}
		d_order_of_the_silver_hand = {
			holder_scope = {
				random_courtier = {
					limit = { is_potential_argent_leader_trigger = yes }
					save_event_target_as = target_grand_crusader
				}
			}
		}
	}
	else = {
		create_character = {
			female = no
			dynasty = none
			culture=lordaeronian religion=holy_light
			trait=brilliant_strategist
			trait=creature_human
			trait=class_paladin_7
			trait=kind trait=just
			age = 50
		}
		new_character = { save_event_target_as = target_argent_highlord }
	}
	event_target:target_argent_highlord = {
		wealth = 500
		religion_authority = {
			modifier = religious_order_formed
			years = 10
		}
		
		activate_title = { title = d_argent_dawn status = yes }
		d_argent_dawn = { grant_title = PREV }
		set_defacto_liege = THIS
	}
}
# Creates d_scarlet_crusade
create_d_scarlet_crusade_effect = {
	# Picks Grand Crusader
	# Saidan Dathrohan
	if = {
		limit = { c_60021 = { is_potential_scarlet_leader_trigger = yes } }
		c_60021 = { save_event_target_as = target_grand_crusader }
	}
	# James Abbendis
	else_if = {
		limit = { c_60560 = { is_potential_scarlet_leader_trigger = yes } }
		c_60560 = { save_event_target_as = target_grand_crusader }
	}
	# Brigitte Abbendis
	else_if = {
		limit = { c_60561 = { is_potential_scarlet_leader_trigger = yes } }
		c_60561 = { save_event_target_as = target_grand_crusader }
	}
	# Member of the Silver Hand
	else_if = {
		limit = {
			d_order_of_the_silver_hand = {
				has_holder = yes
				holder_scope = {
					any_courtier = {
						is_potential_scarlet_leader_trigger = yes
					}
				}
			}
		}
		d_order_of_the_silver_hand = {
			holder_scope = {
				random_courtier = {
					limit = { is_potential_scarlet_leader_trigger = yes }
					save_event_target_as = target_grand_crusader
				}
			}
		}
	}
	# Spawned paladin
	else = {
		create_character = {
			female = no
			dynasty = none
			culture = lordaeronian religion = scarlet_light
			trait=brilliant_strategist
			trait=creature_human
			trait=class_paladin_7
			trait=wroth trait=zealous
			age = 50
		}
		new_character = { save_event_target_as = target_grand_crusader }
	}
	
	# Creates d_scarlet_crusade
	event_target:target_grand_crusader = {
		# Used in scripted effects
		save_event_target_as = target_settler
		
		religion = scarlet_light
		clear_secret_religion = yes
		
		wealth = 500
		religion_authority = {
			modifier = religious_order_formed
			years = 10
		}
		
		activate_title = { title = d_scarlet_crusade status = yes }
		d_scarlet_crusade = { grant_title = PREV }
		set_defacto_liege = THIS
		
		# Gives start lands
		c_whispering_gardens = {
			# event_target:target_settler and its people settle here
			settle_as_target_settler_effect = yes
		}
		d_hearthglen = {
			any_direct_de_jure_vassal_title = {
				# event_target:target_settler and its people settle here
				settle_as_target_settler_effect = yes
			}
		}
		
		c_whispering_gardens = {
			# Declares war against player
			target_settler_declare_war_effect = yes
		}
		
		clear_settler_flag_effect = yes
	}
}
# Creates d_church_scarlet_light
create_d_church_scarlet_light_effect = {
	# Picks Grand Inquisitor
	if = {
		limit = { c_60550 = { is_potential_scarlet_leader_trigger = yes } }
		c_60550 = { save_event_target_as = target_grand_inquisitor }
	}
	# Member of the Silver Hand
	else_if = {
		limit = {
			d_order_of_the_silver_hand = {
				has_holder = yes
				holder_scope = {
					any_courtier = {
						is_potential_scarlet_leader_trigger = yes
					}
				}
			}
		}
		d_order_of_the_silver_hand = {
			holder_scope = {
				random_courtier = {
					limit = { is_potential_scarlet_leader_trigger = yes }
					save_event_target_as = target_grand_inquisitor
				}
			}
		}
	}
	# Spawned priest
	else = {
		create_character = {
			dynasty = none
			culture = lordaeronian religion = scarlet_light
			trait=scholarly_theologian
			trait=creature_human
			trait=class_priest_6
			trait=wroth trait=zealous add_trait=ambitious
			age = 50
		}
		new_character = { save_event_target_as = target_grand_inquisitor }
	}
	
	# Creates d_church_scarlet_light
	event_target:target_grand_inquisitor = {
		religion = scarlet_light
		clear_secret_religion = yes
		
		wealth = 500
		
		activate_title = { title = d_church_scarlet_light status = yes }
		d_church_scarlet_light = { grant_title = PREV }
		set_defacto_liege = THIS
	}
}

# Creates temporary landless title to avoid game over
create_temporary_landless_title_effect = {
	create_title = {
		tier = DUKE
		landless = yes
		holder = THIS
		culture = THIS
	}
	new_title = {
		save_event_target_as = target_temporary_landless_title
	}
}
# Destroys title created in create_temporary_landless_title_effect
destroy_temporary_landless_title_effect = {
	event_target:target_temporary_landless_title = {
		activate_title = { title = THIS status = no }
		destroy_landed_title = THIS
	}
	clear_event_target = target_temporary_landless_title
}

# THIS abdicates titles and transfers wealth to PREV
this_abdicate_transfer_wealth_to_prev_effect = {
	if = {
		limit = { NOT = { has_character_flag = ongoing_abdication_flag } }
		save_event_target_as = target_ruler
		PREV = { save_event_target_as = target_heir }
		
		set_character_flag = ongoing_abdication_flag
	
		hidden_effect = {
			# Transfers wealth and artifacts
			event_target:target_heir = { wealth = event_target:target_ruler }
			clear_wealth = yes
			any_artifact = {
				transfer_artifact = { from = event_target:target_ruler to = event_target:target_heir }
			}
		}
		abdicate_to = PREV
		hidden_effect = {
			# Lose claims on target_heir titles
			any_claim = {
				limit = {
					holder_scope = { character = event_target:target_heir }
				}
				remove_claim = event_target:target_ruler
			}
			move_character = event_target:target_heir
		}
		
		clr_character_flag = ongoing_abdication_flag
		
		clear_event_target =  target_ruler
		clear_event_target =  target_heir
	}
}
this_abdicate_transfer_wealth_to_play_prev_effect = {
	if = {
		limit = { NOT = { has_character_flag = ongoing_abdication_flag } }
		save_event_target_as = target_ruler
		PREV = { save_event_target_as = target_heir }
		liege = { save_event_target_as = target_liege }
		
		set_character_flag = ongoing_abdication_flag
		
		hidden_effect = {
			# Transfers wealth and artifacts
			event_target:target_heir = {
				create_temporary_landless_title_effect = yes	# Creates temporary landless title to avoid game over
				wealth = event_target:target_ruler
			}
			clear_wealth = yes
			any_artifact = {
				transfer_artifact = { from = event_target:target_ruler to = event_target:target_heir }
			}
			set_player_character = event_target:target_heir	# THIS start playing PREV
		}
		abdicate_to = PREV
		hidden_effect = {
			# Lose claims on target_heir titles
			any_claim = {
				limit = {
					holder_scope = { character = event_target:target_heir }
				}
				remove_claim = event_target:target_ruler
			}
			move_character = event_target:target_heir
			event_target:target_heir = {
				destroy_temporary_landless_title_effect = yes	# Destroys title created in create_temporary_landless_title_effect
				set_defacto_liege = event_target:target_liege
			}
		}
		
		clr_character_flag = ongoing_abdication_flag
		
		clear_event_target = target_ruler
		clear_event_target = target_heir
		clear_event_target = target_liege
	}
}

fire_councilmember_king_effect = {
	any_courtier_or_vassal = {
		limit = { has_minor_title = title_councilmember_king }
		leave_council_position_no_opinion_effect = yes
	}
}
fire_councilmember_emperor_effect = {
	any_courtier_or_vassal = {
		limit = { has_minor_title = title_councilmember_emperor }
		leave_council_position_no_opinion_effect = yes
	}
}

add_artifact_frostmourne_effect = {
	save_global_event_target_as = target_frostmourne_holder
	add_artifact = frostmourne
	hidden_effect = {
		e_scourge = { holder_scope = { save_event_target_as = target_lich_king } }
		new_artifact = {
			set_creation_date = 591.11.1
			set_original_owner = event_target:target_lich_king
		}
		set_global_flag = frostmourne_spawned_flag
	}
}

free_scourge_from_legion_effect = {
	custom_tooltip = {
		text = you_are_no_longer_pawn_of_the_legion_tooltip
		clr_global_flag = scourge_is_under_legion_control_flag
	}
}

# Changes religion of your undead provinces
change_undead_demesne_provinces_religion_to_root_effect = {
	any_demesne_province = {
		limit = {
			NOT = { religion = ROOT }
			
			has_province_modifier = undead_province
		}
		religion = ROOT
	}
}

heal_wounds_effect = {
	if = { limit = { has_character_flag = pending_infection } clr_character_flag = pending_infection }
	if = {
		limit = { trait = severely_injured }
		remove_trait = severely_injured
		add_scarred_tiered_effect = yes
	}
	if = {
		limit = { trait = wounded }
		remove_trait = wounded
		add_scarred_tiered_effect = yes
	}
	if = {
		limit = { trait = infection }
		remove_trait = infection
	}
}

adventurers_easter_egg_effect = {
	if = {
		limit = {
			OR = {
				is_dragon_race_trigger = yes
				is_monster_being_trigger = yes
				is_dark_class_trigger = yes
				dark_public_religion_trigger = yes
			}
		}
		random = {
			chance = 1
			set_character_flag = adventurers_easter_egg_flag
		}
	}
}

# Holy Light religion gets bad authority
religious_split_holy_light_bad_effect = {
	d_church_of_the_holy_light = {
		show_scope_change = no
		holder_scope = {
			show_scope_change = no
			religion_authority = {
				modifier = religious_split_bad
				years = 10
			}
		}
	}
}
# Holy Light religion gets good authority
religious_split_scarlet_light_good_effect = {
	d_church_scarlet_light = {
		show_scope_change = no
		holder_scope = {
			show_scope_change = no
			religion_authority = {
				modifier = religious_split_good
				years = 10
			}
		}
	}
}
# Gives claims on western Lordaeron duchies
claim_western_lordaeron_effect = {
	# Silverpine
	add_pressed_claim = d_ambermill
	add_pressed_claim = d_deep_elem
	add_pressed_claim = d_lordamere
	add_pressed_claim = d_silverpine
	
	# Tirisfal
	add_pressed_claim = d_brill
	add_pressed_claim = d_lordaeron
	add_pressed_claim = d_whispering_gardens
	
	# Gilneas
	add_pressed_claim = d_crowvale
	
	# Andorhal
	add_pressed_claim = d_andorhal
	add_pressed_claim = d_hearthglen
	
	# Hillsbrad
	add_pressed_claim = d_hillsbrad
}

remove_old_gods_follower_modifier_effect = {
	if = { limit = { has_character_modifier = follower_of_cthun 		} remove_character_modifier = follower_of_cthun 		}
	if = { limit = { has_character_modifier = follower_of_yogg_saron 	} remove_character_modifier = follower_of_yogg_saron 	}
	if = { limit = { has_character_modifier = follower_of_yshaarj 		} remove_character_modifier = follower_of_yshaarj 		}
	if = { limit = { has_character_modifier = follower_of_nzoth 		} remove_character_modifier = follower_of_nzoth 		}
}

# Borrows 300 gold from PREV
this_borrows_300_gold_from_prev_effect = {
	this_borrows_300_effect = yes
	
	PREV = {
		wealth = -300
	
		add_character_modifier = { name = interest_payment_360_gold years = 10 inherit = yes stacking = yes }
	}
}
# target_borrower borrows 300 gold from target_moneylender
borrower_borrows_300_gold_from_moneylender_effect = {
	event_target:target_moneylender = {
		show_scope_change = no
		
		event_target:target_borrower = {
			this_borrows_300_gold_from_prev_effect = yes
		}
	}
}
# Borrows 300 gold from unknown moneylenders
this_borrows_300_effect = {
	wealth = 300
	
	add_character_modifier = { name = debt_360_gold duration = -1 inherit = yes }
}
# Clears flags and delayed events of borrowing decisions
clean_up_borrowing_effect = {
	clr_character_flag = ongoing_borrow_money_flag
	# Fallback: conversation fails in 4 months
	clear_delayed_event = { id = WCECO.150 }
}

#Gives money and moral authority
holy_order_start_pack_effect = {
	religion_authority = {
		modifier = religious_order_formed
		years = 10
	}
	wealth = 500
}
# Gives money, spawn commanders
for_war_start_pack_effect = {
	wealth = 500
	spawn_fantastic_commander_effect = yes
	spawn_great_commander_effect = yes
	spawn_great_commander_effect = yes
	spawn_good_commander_effect = yes
	spawn_good_commander_effect = yes
}

drust_spouse_becomes_undead_effect = {
	add_trait_undead_effect = yes			# This effect sets portrait
	religion = throsic		# Need to set undead religion before necromantic classes can be assigned
	if = {
		limit = {
			is_death_knight_class_trigger = no
			OR = {
				is_physical_class_trigger = yes
				is_combined_class_trigger = yes
			}
			potential_death_knight_trigger = yes
		}
		add_character_modifier = { name = training_self_death_knight duration = -1 }
		recount_experience_effect = yes
		add_class_trait_effect = yes
	}
	else_if = {
		limit = {
			is_necromancer_class_trigger = no
			is_magic_class_trigger = yes
			potential_necromancer_trigger = yes
		}
		add_character_modifier = { name = training_self_necromancer duration = -1 }
		recount_experience_effect = yes
		add_class_trait_effect = yes
	}
	else_if = {
		limit = {
			has_class_trait_trigger = no
			potential_necromancer_trigger = yes
			is_female = yes
		}
		add_trait = class_necromancer_4
	}
	else_if = {
		limit = {
			has_class_trait_trigger = no
			potential_death_knight_trigger = yes
			is_female = no
		}
		add_trait = class_death_knight_4
	}
}

add_laid_eggs_effect = {
	if = {
		limit = { immortal = yes }
		while = {
			limit = { always = yes }
			count = 2
			add_character_modifier = { name = laid_eggs stacking = yes duration = -1 }
		}
	}
	else = {
		add_character_modifier = { name = laid_eggs stacking = yes duration = -1 }
	}
}

prev_adopts_effect = {
	hidden_effect = {
		set_father = 0
		set_mother = 0
	}
	if = {
		limit = { PREV = { is_female = yes } }
		set_mother = PREV
	}
	else = {
		set_father = PREV
	}
	dynasty = PREV
	add_trait = adopted
}

forge_runeblade_cost_effect = {
	if = {
		limit = { trait = creature_nathrezim }
		wealth = -500
	}
	else = {
		piety = -500
	}
}

add_light_elune_branch_effect = {
	add_trait = light_elune_branch
	random_list = {
		10 = {
			trigger = { NOT = { trait = kind } }
			add_trait = kind
		}
		10 = {
			trigger = { NOT = { trait = charitable } }
			add_trait = charitable
		}
		10 = {
			trigger = { NOT = { trait = temperate } }
			add_trait = temperate
		}
	}
}
add_dark_elune_branch_effect = {
	add_trait = dark_elune_branch
	random_list = {
		10 = {
			trigger = { NOT = { trait = wroth } }
			add_trait = wroth
		}
		10 = {
			trigger = { NOT = { trait = just } }
			add_trait = just
		}
		10 = {
			trigger = { NOT = { trait = brave } }
			add_trait = brave
		}
	}
}

heal_magical_withdrawal_effect = {
	remove_has_magical_withdrawal_trait_effect = yes
	hidden_effect = {
		any_courtier_or_vassal = {
			limit = {
				is_playable = no
				
				trait = has_magical_withdrawal
			}
			remove_has_magical_withdrawal_trait_effect = yes
		}
	}
}

garona_hunt_chain_skip_effect = {
	clr_character_flag = hunted_by_garona
	
	event_target:target_garona = {
		remove_traveling_immunity_effect = yes
	}
}

add_traveling_immunity_effect = {
	add_trait = travelling
	diplomatic_immunity = yes
}
remove_traveling_immunity_effect = {
	remove_trait = travelling
	diplomatic_immunity = no
}

switch_to_random_non_evil_religion_effect = {
	if = {
		limit = { religion = burning_legion_religion }
		religion = illidari
	}
	else_if = {
		limit = { evil_public_religion_trigger = yes }
		random_list = {
			10 = { religion = shadowlander }
			10 = { religion = voidfarer }
			10 = { religion = forsaken_cult }
		}
	}
}
break_free_from_prev_invader_effect = {
	if = {
		limit = { PREV = { has_landed_title = e_scourge } }
		free_from_lich_king_effect = yes
	}
	if = {
		limit = {
			religion = PREV
			evil_public_religion_trigger = yes
		}
		switch_to_random_non_evil_religion_effect = yes
	}
}
break_free_from_from_invader_effect = {
	if = {
		limit = { FROM = { has_landed_title = e_scourge } }
		free_from_lich_king_effect = yes
	}
	if = {
		limit = {
			religion = FROM
			evil_public_religion_trigger = yes
		}
		switch_to_random_non_evil_religion_effect = yes
	}
}

unleash_old_god_effect = {
	clr_character_flag = freeing_old_god_flag
	
	if = {
		limit = { cthun_offmap_decisions_enabled_trigger = yes }
		
		# Gives gold
		wealth = 1000
		
		# Spawns troops
		spawn_cthun_invasion_troops_effect = yes
		spawn_cthun_invasion_troops_effect = yes
		spawn_cthun_invasion_troops_effect = yes
		spawn_cthun_invasion_troops_effect = yes
		#spawn_cthun_invasion_troops_effect = yes
		#spawn_cthun_invasion_troops_effect = yes
	}
	else_if = {
		limit = { nzoth_offmap_decisions_enabled_trigger = yes }
		
		# Gives gold
		wealth = 1000
		# Spawns troops
		spawn_nzoth_invasion_troops_effect = yes
		spawn_nzoth_invasion_troops_effect = yes
		spawn_nzoth_invasion_troops_effect = yes
		spawn_nzoth_invasion_troops_effect = yes
		#spawn_nzoth_invasion_troops_effect = yes
		#spawn_nzoth_invasion_troops_effect = yes
	}
	else_if = {
		limit = { yogg_saron_offmap_decisions_enabled_trigger = yes }
		
		# Gives gold
		wealth = 1000
		# Spawns troops
		spawn_yogg_saron_invasion_troops_effect = yes
		spawn_yogg_saron_invasion_troops_effect = yes
		spawn_yogg_saron_invasion_troops_effect = yes
		spawn_yogg_saron_invasion_troops_effect = yes
		#spawn_yogg_saron_invasion_troops_effect = yes
		#spawn_yogg_saron_invasion_troops_effect = yes
	}
	73 = { province_event = { id = WCOME.365 days = 360 random = 720 } }
}

#Imitates getting new body thus clears traits associated with it
get_new_body_effect = {
	# Rejuvenate
	hidden_effect = {
		rejuvenate_effect = yes
		clear_rejuvenate_effect = yes
	}
	
	# Remove maims and disabilities
	heal_all_maims_and_healable_disabilities_effect = yes
	
	# Remove wounds
	heal_wounds_effect = yes
	# Remove diseases
	heal_all_diseases = yes

	# Removed genetic
	remove_all_positive_congenital_traits_effect = yes
	remove_all_negative_congenital_traits_effect = yes
	remone_all_non_inheritable_positive_congenital_traits_effect = yes
	remone_all_non_inheritable_negative_congenital_traits_effect = yes

	# Remove weight
	remove_weight_effect = yes
}

remove_weight_effect = {
	if = {
		limit = { trait = is_fat }
		remove_trait = is_fat
	}
	if = {
		limit = { trait = is_malnourished }
		remove_trait = is_malnourished
	}
	remove_weight_modifier_effect = yes
	clear_fat_flags_effect = yes
	clear_malnourished_flags_effect = yes
}

assign_random_mantid_paragon_nickname_effect = {
	random_list = {
		10 = {
			trigger = {
				OR = {
					stewardship = 15
					diplomacy = 15
				}
			}
			give_nickname = nick_the_swarmkeeper
		}
		10 = {
			trigger = { learning = 15 }
			give_nickname = nick_the_lucid
		}
		#Generic
		5 = {
			give_nickname = nick_the_locust
		}
		10 = {
			trigger = { intrigue = 15 }
			give_nickname = nick_the_manipulator
		}
		10 = {
			trigger = { combat_rating = 75 }
			give_nickname = nick_the_wind_reaver
		}
		#Very rare
		1 = {
			give_nickname = nick_the_prime
		}
		10 = {
			trigger = { combat_rating = 75 }
			give_nickname = nick_the_unscathed
		}
		10 = {
			trigger = { martial = 15 }
			give_nickname = nick_the_bloodcaller
		}
		10 = {
			trigger = { martial = 15 }
			give_nickname = nick_the_deathcaller
		}
		10 = {
			trigger = { combat_rating = 75 }
			give_nickname = nick_the_dissector
		}
		10 = {
			trigger = { combat_rating = 75 }
			give_nickname = nick_the_bloodseeker
		}
		10 = {
			trigger = {
				OR = {
					intrigue = 15
					learning = 15
				}
			}
			give_nickname = nick_the_poisoned_mind
		}
	}
}

add_sleeping_immunity_effect = {
	add_trait = sleeping_trait
	diplomatic_immunity = yes
}
remove_sleeping_immunity_effect = {
	remove_trait = sleeping_trait
	diplomatic_immunity = no
}
put_to_sleep_paragon_effect = {
	add_sleeping_immunity_effect = yes
	set_character_flag = paragon_sleeping_flag
	character_event = { id = WCRAC.1015 years = 100 }
}
awaken_paragon_effect = {
	remove_sleeping_immunity_effect = yes
	clr_character_flag = paragon_sleeping_flag
}
# Tekahn's effects
become_stone_tolvir_old_gods_effect = {
	remove_trait = creature_tolvir
	add_trait = creature_stone_tolvir
	set_graphical_culture = stone_tolvir
	religion = old_gods_worship
}
become_stone_tolvir_voidfarer_effect = {
	remove_trait = creature_tolvir
	add_trait = creature_stone_tolvir
	set_graphical_culture = stone_tolvir
	religion = voidfarer
}
# Amathet effect
become_stone_tolvir_suntouched_effect = {
	remove_trait = creature_tolvir
	add_trait = creature_stone_tolvir
	set_graphical_culture = stone_tolvir
	religion = suntouched
}