# clr_artifact_flagsmodifiers_effect
# clr_artifact_searcher_effect
# add_artifact_search_payment_effect

# generate_mask_effect

# give_goldsmith_artifacts_tier_1_effect
# give_goldsmith_artifacts_tier_2_effect
# give_goldsmith_artifacts_tier_3_effect
# give_goldsmith_artifacts_tier_4_effect
# give_smith_artifacts_tier_1_effect
# give_smith_artifacts_tier_2_effect
# give_smith_artifacts_tier_3_optionA_effect
# give_smith_artifacts_tier_3_optionB_effect
# give_smith_artifacts_tier_3_optionC_effect
# give_smith_artifacts_tier_4_optionA_effect
# give_smith_artifacts_tier_4_optionB_effect
# give_smith_artifacts_tier_4_optionC_effect

# set_higher_quality_of_book_flags_effect
# set_lower_quality_of_book_flags_effect

# clear_smith_flags_effect
# clear_smith_employer_flags_effect

clr_artifact_flagsmodifiers_effect = {
	event_target:relic_ruler = {
		show_scope_change = no

		trigger_switch = {
			on_trigger = has_character_modifier

			relic_rumor_minor = { remove_character_modifier = relic_rumor_minor }
			relic_rumor_medium = { remove_character_modifier = relic_rumor_medium }
			relic_rumor_major  = { remove_character_modifier = relic_rumor_major }
		}
	}
	clr_artifact_searcher_effect = yes
}

clr_artifact_searcher_effect = {
	event_target:relic_ruler = {
		show_scope_change = no

		trigger_switch = {
			on_trigger = has_character_modifier

			pays_for_artifact_hunt_minor = { remove_character_modifier = pays_for_artifact_hunt_minor }
			pays_for_artifact_hunt_medium = { remove_character_modifier = pays_for_artifact_hunt_medium }
			pays_for_artifact_hunt_major = { remove_character_modifier = pays_for_artifact_hunt_major }
		}

		# From the progress events....
		trigger_switch = {
			on_trigger = has_character_modifier

			treasure_hunting_diplomats = { remove_character_modifier = treasure_hunting_diplomats }
			treasure_hunting_soldiers = { remove_character_modifier = treasure_hunting_soldiers }
			treasure_hunting_stewards = { remove_character_modifier = treasure_hunting_stewards }
			treasure_hunting_spies = { remove_character_modifier = treasure_hunting_spies }
			treasure_hunting_scholars = { remove_character_modifier = treasure_hunting_scholars }
		}

		clr_character_flag = they_asked_for_your_help
	}

	event_target:relic_hunter = {
		clr_character_flag = relic_hunter
	}
}

add_artifact_search_payment_effect = {
	trigger_switch = {
		on_trigger = has_character_modifier

		relic_rumor_minor = {
			add_character_modifier = {
				name = pays_for_artifact_hunt_minor
				duration = -1
			}
		}

		relic_rumor_medium = {
			add_character_modifier = {
				name = pays_for_artifact_hunt_medium
				duration = -1
			}
		}

		relic_rumor_major = {
			add_character_modifier = {
				name = pays_for_artifact_hunt_major
				duration = -1
			}
		}
	}
}

generate_mask_effect = {
	random_list = {
		20 = {
			add_artifact = crown_african_mask_1

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_1_random_a }
					20 = { set_name = crown_african_mask_1_random_b }
					20 = { set_name = crown_african_mask_1_random_c }
					20 = { set_name = crown_african_mask_1_random_d }
				}
			}
		}

		20 = {
			add_artifact = crown_african_mask_2

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_2_random_a }
					20 = { set_name = crown_african_mask_2_random_b }
					20 = { set_name = crown_african_mask_2_random_c }
					20 = { set_name = crown_african_mask_2_random_d }
				}
			}
		}

		20 = {
			add_artifact = crown_african_mask_3

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_3_random_a }
					20 = { set_name = crown_african_mask_3_random_b }
					20 = { set_name = crown_african_mask_3_random_c }
					20 = { set_name = crown_african_mask_3_random_d }
				}
			}
		}

		20 = {
			add_artifact = crown_african_mask_4

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_4_random_a }
					20 = { set_name = crown_african_mask_4_random_b }
					20 = { set_name = crown_african_mask_4_random_c }
					20 = { set_name = crown_african_mask_4_random_d }
				}
			}
		}

		20 = {
			add_artifact = crown_african_mask_5

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_5_random_a }
					20 = {
						trigger = {
							ROOT = {
								is_lowborn = no
							}
						}

						set_name = crown_african_mask_5_random_b
					}
					20 = { set_name = crown_african_mask_5_random_c }
					20 = { set_name = crown_african_mask_5_random_d }
				}
			}
		}

		20 = {
			add_artifact = crown_african_mask_6

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_6_random_a }
					20 = { set_name = crown_african_mask_6_random_b }
					20 = {
						trigger = {
							ROOT = {
								is_lowborn = no
							}
						}

						set_name = crown_african_mask_6_random_c
					}
					20 = { set_name = crown_african_mask_6_random_d }
				}
			}
		}

		20 = {
			add_artifact = crown_african_mask_7

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_7_random_a }
					20 = { set_name = crown_african_mask_7_random_b }
					20 = { set_name = crown_african_mask_7_random_c }
					20 = { set_name = crown_african_mask_7_random_d }
				}
			}
		}

		20 = {
			add_artifact = crown_african_mask_8

			new_artifact = {
				random_list = {
					# Randomize names to avoid too much repetition
					20 = { set_name = crown_african_mask_8_random_a }
					20 = { set_name = crown_african_mask_8_random_b }
					20 = { set_name = crown_african_mask_8_random_c }
					20 = { set_name = crown_african_mask_8_random_d }
				}
			}
		}
	}
}

give_goldsmith_artifacts_tier_1_effect = {
	if = {
		limit = {
			OR = {
				religion_group = christian
				religion_group = jewish_group
			}
		}
		add_artifact = the_lily_crown
		add_artifact = noble_scepter
		add_artifact = engraved_sword
	}
	else_if = {
		limit = {
			OR = {
				religion_group = muslim
				religion_openly_west_african_or_reformed_trigger = yes
			}
		}
		add_artifact = engraved_dagger
		add_artifact = silver_bracelets
	}
	else_if = {
		limit = {
			OR = {
				religion_group = indian_group
				religion_openly_bon_or_reformed_trigger = yes
			}
		}
		add_artifact = engraved_dagger
		add_artifact = collar_of_pearls
	}
	else_if = {
		limit = {
			OR = {
				religion_group = zoroastrian_group
				religion_openly_zun_or_reformed_trigger = yes
			}
		}
		add_artifact = circlet_of_twilight
		add_artifact = silver_staff
	}
	else_if = {
		limit = { religion_openly_norse_or_reformed_trigger = yes }
		add_artifact = iron_crown
		add_artifact = engraved_sword
	}
	### ACR ###
	else_if = {
		limit = { religion_openly_in_celtic_subgroup_trigger = yes }
		add_artifact = silver_torque
		add_artifact = engraved_sword
	}
	else = {
		add_artifact = engraved_crown
		add_artifact = ceremonial_axe
	}
}

give_goldsmith_artifacts_tier_2_effect = {
	if = {
		limit = {
			OR = {
				religion_group = christian
				religion_group = jewish_group
			}
		}
		add_artifact = crown_of_pearls
		add_artifact = ruby_scepter
		add_artifact = golden_sword
	}
	else_if = {
		limit = {
			OR = {
				religion_group = muslim
				religion_openly_west_african_or_reformed_trigger = yes
			}
		}
		add_artifact = bejeweled_dagger
		add_artifact = golden_bracelets
	}
	else_if = {
		limit = {
			OR = {
				religion_group = indian_group
				religion_openly_bon_or_reformed_trigger = yes
			}
		}
		add_artifact = bejeweled_dagger
		add_artifact = necklace_of_radiance
	}
	else_if = {
		limit = {
			OR = {
				religion_group = zoroastrian_group
				religion_openly_zun_or_reformed_trigger = yes
			}
		}
		add_artifact = circlet_of_the_heavens
		add_artifact = golden_staff
	}
	else_if = {
		limit = { religion_openly_norse_or_reformed_trigger = yes }
		add_artifact = crown_of_the_sea
		add_artifact = golden_sword
	}
	### ACR ###
	else_if = {
		limit = { religion_openly_in_celtic_subgroup_trigger = yes }
		add_artifact = golden_torque
		add_artifact = golden_sword
	}
	else = {
		add_artifact = amber_crown
		add_artifact = obsidian_axe
	}
}

give_goldsmith_artifacts_tier_3_effect = {
	if = {
		limit = {
			OR = {
				religion_group = christian
				religion_group = jewish_group
			}
		}
		add_artifact = crown_of_majesty
		add_artifact = emerald_scepter
		add_artifact = sword_of_heroes
	}
	else_if = {
		limit = {
			OR = {
				religion_group = muslim
				religion_openly_west_african_or_reformed_trigger = yes
			}
		}
		add_artifact = dagger_of_glory
		add_artifact = ruby_bracelets
	}
	else_if = {
		limit = {
			OR = {
				religion_group = indian_group
				religion_openly_bon_or_reformed_trigger = yes
			}
		}
		add_artifact = dagger_of_glory
		add_artifact = celestial_necklace
	}
	else_if = {
		limit = {
			OR = {
				religion_group = zoroastrian_group
				religion_openly_zun_or_reformed_trigger = yes
			}
		}
		add_artifact = circlet_of_the_heavens
		add_artifact = staff_of_majesty
	}
	else_if = {
		limit = { religion_openly_norse_or_reformed_trigger = yes }
		add_artifact = crown_of_crows
		add_artifact = sword_of_heroes
	}
	### ACR ###
	else_if = {
		limit = { religion_openly_in_celtic_subgroup_trigger = yes }
		add_artifact = jeweled_torque
		add_artifact = sword_of_heroes
	}
	else = {
		add_artifact = heros_crown
		add_artifact = axe_of_the_ancestors
	}
}

give_goldsmith_artifacts_tier_4_effect = {
	if = {
		limit = {
			OR = {
				religion_group = christian
				religion_group = jewish_group
			}
		}
		add_artifact = crown_of_majesty_2
		add_artifact = emerald_scepter_2
		add_artifact = sword_of_heroes_2
	}
	else_if = {
		limit = {
			OR = {
				religion_group = muslim
				religion_openly_west_african_or_reformed_trigger = yes
			}
		}
		add_artifact = dagger_of_glory_2
		add_artifact = ruby_bracelets_2
	}
	else_if = {
		limit = {
			OR = {
				religion_group = indian_group
				religion_openly_bon_or_reformed_trigger = yes
			}
		}
		add_artifact = dagger_of_glory_2
		add_artifact = celestial_necklace_2
	}
	else_if = {
		limit = {
			OR = {
				religion_group = zoroastrian_group
				religion_openly_zun_or_reformed_trigger = yes
			}
		}
		add_artifact = circlet_of_the_heavens_2
		add_artifact = staff_of_majesty_2
	}
	else_if = {
		limit = { religion_openly_norse_or_reformed_trigger = yes }
		add_artifact = crown_of_crows_2
		add_artifact = sword_of_heroes_2
	}
	### ACR ###
	else_if = {
		limit = { religion_openly_in_celtic_subgroup_trigger = yes }
		add_artifact = jeweled_torque_2
		add_artifact = sword_of_heroes_2
	}
	else = {
		add_artifact = heros_crown_2
		add_artifact = axe_of_the_ancestors_2
	}
}

give_smith_artifacts_tier_1_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }

		add_artifact = sword_tier_1_new
		set_character_flag = sword_tier_1

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_1
		}

		custom_tooltip = { text = MNM_9124_TT_SWORD }
	}
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }

		add_artifact = scimitar_tier_1_new
		set_character_flag = scimitar_tier_1

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_1
		}

		custom_tooltip = { text = MNM_9124_TT_SCIMITAR }
	}
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }

		add_artifact = lance_tier_1_new
		set_character_flag = lance_tier_1

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_1
		}

		custom_tooltip = { text = MNM_9124_TT_LANCE }
	}
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }

		add_artifact = axe_tier_1_new
		set_character_flag = axe_tier_1

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_1
		}

		custom_tooltip = { text = MNM_9124_TT_AXE }
	}
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }

		add_artifact = mace_tier_1_new
		set_character_flag = mace_tier_1

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_1
		}

		custom_tooltip = { text = MNM_9124_TT_MACE }
	}
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }

		add_artifact = bow_tier_1_new
		set_character_flag = bow_tier_1

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_1
		}

		custom_tooltip = { text = MNM_9124_TT_BOW }
	}
	if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }

		add_artifact = armor_tier_1
	}
}

give_smith_artifacts_tier_2_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }

		add_artifact = sword_tier_2_new
		set_character_flag = sword_tier_2

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_2
		}

		custom_tooltip = { text = MNM_9124_TT_SWORD }
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = zweihanded_sword } }
		hidden_effect = {
			add_artifact = zweihander_sword
		}
		set_character_flag = zweihanded_sword
		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_2
		}

		custom_tooltip = { text = MNM_9124_TT_SWORD }
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }

		add_artifact = scimitar_tier_2_new
		set_character_flag = scimitar_tier_2

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_2
		}

		custom_tooltip = { text = MNM_9124_TT_SCIMITAR }
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }

		add_artifact = lance_tier_2_new
		set_character_flag = lance_tier_2

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_2
		}

		custom_tooltip = { text = MNM_9124_TT_LANCE }
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }

		add_artifact = axe_tier_2_new
		set_character_flag = axe_tier_2

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_2
		}

		custom_tooltip = { text = MNM_9124_TT_AXE }
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }

		add_artifact = mace_tier_2_new
		set_character_flag = mace_tier_2

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_2
		}

		custom_tooltip = { text = MNM_9124_TT_MACE }
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }

		add_artifact = bow_tier_2_new
		set_character_flag = bow_tier_2

		new_artifact = {
			set_name = artifact_name
			set_description = artifact_description_smith_tier_2
		}

		custom_tooltip = { text = MNM_9124_TT_BOW }
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }

		add_artifact = armor_tier_2
	}
}

give_smith_artifacts_tier_3_optionA_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }
		add_artifact = sword_tier_3_heartseeker
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }
		add_artifact = scimitar_tier_3_golden
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }
		add_artifact = lance_tier_3_impaler
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }
		add_artifact = axe_tier_3_cleaver
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }
		add_artifact = mace_tier_3_foe_hammer
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }
		add_artifact = bow_tier_3_silent_wind
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }
		add_artifact = armor_tier_3_guardian
	}
}

give_smith_artifacts_tier_3_optionB_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }
		add_artifact = sword_tier_3_vengeance
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }
		add_artifact = scimitar_tier_3_fortune
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }
		add_artifact = lance_tier_3_trident
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }
		add_artifact = axe_tier_3_ravager
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }
		add_artifact = mace_tier_3_bone_breaker
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }
		add_artifact = bow_tier_3_lightning
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }
		add_artifact = armor_tier_3_champion
	}
}

give_smith_artifacts_tier_3_optionC_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }
		add_artifact = sword_tier_3_fury
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }
		add_artifact = scimitar_tier_3_conquest
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }
		add_artifact = lance_tier_3_piercer
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }
		add_artifact = axe_tier_3_marauder
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }
		add_artifact = mace_tier_3_shatterer
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }
		add_artifact = bow_tier_3_eagle
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }
		add_artifact = armor_tier_3_warden
	}
}

give_smith_artifacts_tier_4_optionA_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }
		add_artifact = sword_tier_4_heartseeker
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }
		add_artifact = scimitar_tier_4_golden
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }
		add_artifact = lance_tier_4_impaler
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }
		add_artifact = axe_tier_4_cleaver
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }
		add_artifact = mace_tier_4_foe_hammer
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }
		add_artifact = bow_tier_4_silent_wind
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }
		add_artifact = armor_tier_4_guardian
	}
}

give_smith_artifacts_tier_4_optionB_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }
		add_artifact = sword_tier_4_vengeance
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }
		add_artifact = scimitar_tier_4_fortune
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }
		add_artifact = lance_tier_4_trident
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }
		add_artifact = axe_tier_4_ravager
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }
		add_artifact = mace_tier_4_bone_breaker
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }
		add_artifact = bow_tier_4_lightning
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }
		add_artifact = armor_tier_4_champion
	}
}

give_smith_artifacts_tier_4_optionC_effect = {
	if = {
		limit = { event_target:smith = { has_character_flag = weapon_sword } }
		add_artifact = sword_tier_4_fury
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_scimitar } }
		add_artifact = scimitar_tier_4_conquest
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_lance } }
		add_artifact = lance_tier_4_piercer
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_axe } }
		add_artifact = axe_tier_4_marauder
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_mace } }
		add_artifact = mace_tier_4_shatterer
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = weapon_bow } }
		add_artifact = bow_tier_4_eagle
	}
	else_if = {
		limit = { event_target:smith = { has_character_flag = armor_set } }
		add_artifact = armor_tier_4_warden
	}
}

set_higher_quality_of_book_flags_effect = {
	if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		clr_character_flag = good_book_potential
	}
	else_if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = great_book_potential
	}
	else_if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		clr_character_flag = decent_book_potential
	}
	else_if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = great_book_potential
	}
	else_if = {
		limit = {
			has_character_flag = decent_book_potential
			NOT = { has_character_flag = good_book_potential }
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = good_book_potential
	}

	# Fallback in case flags have cleared somehow...
	else_if = {
		limit = {
			NOR = {
				has_character_flag = decent_book_potential
				has_character_flag = good_book_potential
				has_character_flag = great_book_potential
			}
		}
		set_character_flag = decent_book_potential
	}
}

set_lower_quality_of_book_flags_effect = {
	if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		clr_character_flag = good_book_potential
	}
	else_if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = decent_book_potential
	}
	else_if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		clr_character_flag = great_book_potential
	}
	else_if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		set_character_flag = decent_book_potential
	}
	else_if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			NOT = { has_character_flag = good_book_potential }
			has_character_flag = great_book_potential
		}
		set_character_flag = good_book_potential
	}

	# Fallback in case flags have cleared somehow...
	else_if = {
		limit = {
			NOR = {
				has_character_flag = decent_book_potential
				has_character_flag = good_book_potential
				has_character_flag = great_book_potential
			}
		}
		set_character_flag = decent_book_potential
	}
}

clear_smith_flags_effect = {
	clr_character_flag = goldsmith
	clr_character_flag = weaponsmith
	clr_character_flag = armorsmith
	clr_character_flag = ai_flag_refuse_marriage
	clr_character_flag = ai_flag_refuse_concubinage
	clr_character_flag = cannot_marry
	clr_character_flag = no_court_invites
	remove_character_modifier = will_not_marry
	remove_trait = cannot_marry
	clr_character_flag = weapon_sword
	clr_character_flag = weapon_scimitar
	clr_character_flag = weapon_lance
	clr_character_flag = weapon_axe
	clr_character_flag = weapon_mace
	clr_character_flag = weapon_bow
	clr_character_flag = armor_set
}

clear_smith_employer_flags_effect = {
	clr_character_flag = goldsmith
	clr_character_flag = weaponsmith
	clr_character_flag = armorsmith
	clr_character_flag = smith_complete
	clr_character_flag = smith_upgrade
	clr_character_flag = smith_steal
}