﻿namespace = pam_great_projects_events

########################### — By Laurence Kennedy
## pam_great_projects_events.0001 — Master mason joins court (hidden)
## pam_great_projects_events.0002 — Holy frescoes optional contribution (choose your holy scene)
## pam_great_projects_events.0003 — Stained glass optional contribution (choose your subject matter)
## pam_great_projects_events.0005 — The first stone laid (starting event after mandatory funding is done)
## pam_great_projects_events.0006 — Laid out with divine order (laying out the cathedral and proposing additions)
## pam_great_projects_events.0007 — The heaving ribs of heaven (inspired by the rib vaults)
## pam_great_projects_events.0008 — Casting the voice of God (bellcasting event chain start)
## pam_great_projects_events.0009 — And God spoke (bell cast success)
## pam_great_projects_events.0010 — A herald of doom (bell cast failure)
## pam_great_projects_events.0011 — As if by the Lord's hand (treadwheel crane)
## pam_great_projects_events.0012 — His unfailing love (west portal sermon)
## pam_great_projects_events.0013 — A different voice (cantoria)
## pam_great_projects_events.0020 — The crowning of the spires (completion of the GP)
############################

#Send master mason message, this keeps effect out of contribution tooltip
pam_great_projects_events.0001 = {
	hidden = yes
	immediate = {
		send_interface_message = {
			type = msg_great_project_reward
			title = cathedral_master_mason_joins_title_tt
			right_icon = scope:mason
			add_courtier = scope:mason
		}
	}
}

#Pick frescoes for your cathedral
pam_great_projects_events.0002 = {
	type = character_event
	title = pam_great_projects_events.0002.t
	desc = pam_great_projects_events.0002.desc
	left_portrait = {
		character = root
		animation = prayer_standing_eyes
	}
	right_portrait = {
		trigger = {
			exists = scope:religion_buddy
		}
		character = scope:religion_buddy
		animation = page_flipping
		camera = camera_event_left_forward
	}
	override_background = { reference = pam_cathedral_construction }
	theme = christian
	immediate = {
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
				 	basic_is_available_ai = yes
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = religion_buddy
			}
		}
	}
	
	#mystic XP
	option = { #option a
		trigger = {
			#These are triggered this way to avoid crowding option with trait icons
			trigger_if = {
				limit = {
					OR = {
						has_trait = lifestyle_mystic
						has_trait = theologian
					}
				}
				OR = {
					has_trait = lifestyle_mystic
					has_trait = theologian
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = possessed
						has_trait = lunatic
					}
				}
				OR = {
					has_trait = possessed
					has_trait = lunatic
				}
			}
			trigger_else = {
				OR = {
					has_trait = eccentric
					has_trait = witch
					has_trait = zealous
				}
			}
		}
		name = pam_great_projects_events.0002.a
		custom_tooltip = pam_great_projects_events.0002.mystic_xp
		scope:province = {
			set_variable = {
				name = cathedral_mystic_xp
			}
		}
		if = {
			limit = { has_trait = lifestyle_mystic }
			add_trait_xp = {
				trait = lifestyle_mystic
				value = {
					value = lifestyle_mystic_xp_gain_medium_value
					multiply = 1.5
				}
			}
		}
		ai_chance = {
			base = 500
		}
	}
	#scholar
	option = { #option b
		trigger = {
			trigger_if = {
				limit = {
					OR = {
						has_trait = lifestyle_scholar
						has_trait = shrewd
					}
				}
				OR = {
					has_trait = lifestyle_scholar
					has_trait = shrewd
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = devoted
						has_trait = patient
					}
				}
				OR = {
					has_trait = devoted
					has_trait = patient
				}
			}
			trigger_else = {
				OR = {
					has_lifestyle = learning_lifestyle
					has_trait = education_learning
				}
			}
			
		}
		name = pam_great_projects_events.0002.b
		custom_tooltip = pam_great_projects_events.0002.scholar_xp
		scope:province = {
			set_variable = {
				name = cathedral_scholar_xp
			}
		}
		if = {
			limit = { has_trait = lifestyle_scholar }
			add_trait_xp = {
				trait = lifestyle_scholar
				value = {
					value = scholar_xp_gain_minor_value
					multiply = 1.5
				}
			}
		}
		ai_chance = {
			base = 500
		}
	}
	#pilgrim XP
	option = { #option c
		trigger = {
			trigger_if = {
				limit = {
					OR = {
						has_trait = pilgrim
						has_trait = lifestyle_traveler
					}
				}
				OR = {
					has_trait = pilgrim
					has_trait = lifestyle_traveler
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = improvident
						has_trait = holy_warrior
					}
				}
				OR = {
					has_trait = improvident
					has_trait = holy_warrior
				}
			}
			trigger_else = {
				OR = {
					has_trait = diligent
					has_lifestyle = wanderer_lifestyle
				}
			}
		}
		name = pam_great_projects_events.0002.c
		custom_tooltip = pam_great_projects_events.0002.pilgrim_xp
		scope:province = {
			set_variable = {
				name = cathedral_pilgrim_xp
			}
		}
		if = {
			limit = { has_trait = pilgrim }
			add_trait_xp = {
				trait = pilgrim
				value = {
					value = pilgrim_xp_gain_minor_value
					multiply = 1.5
				}
			}
		}
		ai_chance = {
			base = 500
		}
	}
	#piety
	option = { #option d
		name = pam_great_projects_events.0002.d
		custom_tooltip = pam_great_projects_events.0002.piety
		scope:province = {
			set_variable = {
				name = cathedral_piety
			}
		}
		add_piety = {
			value = point_of_interest_piety_value
			multiply = 2
		}
		ai_chance = {
			base = 100
		}
	}
	#learning lifestyle xp gain
	option = { #option e
		name = pam_great_projects_events.0002.e
		custom_tooltip = pam_great_projects_events.0002.learning_xp
		scope:province = {
			set_variable = {
				name = cathedral_learning_xp
			}
		}
		if = {
			limit = { has_spiritual_fulfillment_type = christian_fulfillment }
			add_poi_learning_experience_effect_minor = yes
			change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		}
		else = {
			add_poi_learning_experience_effect = yes
		}
		ai_chance = {
			base = 100
		}
	}

	#stress loss
	option = { #option f
		name = pam_great_projects_events.0002.f
		custom_tooltip = pam_great_projects_events.0002.stress_loss
		scope:province = {
			set_variable = {
				name = cathedral_stress_loss
			}
		}
		stress_and_fulfillment_impact = { base = minor_stress_impact_loss }
		ai_chance = {
			base = 100
		}
	}
}

#Pick stained glass subject for your cathedral contribution
pam_great_projects_events.0003 = {
	type = character_event
	title = pam_great_projects_events.0003.t
	desc = pam_great_projects_events.0003.desc
	center_portrait = {
		character = scope:religion_buddy
		animation = admiration
		camera = camera_activity_horse
	}
	left_portrait = {
		character = root
		animation = throne_room_conversation_4
		camera = camera_event_center_pointing_right
	}
	right_portrait = {
		character = scope:glazier
		animation = personality_bold
		camera = camera_event_center_pointing_left
	}
	override_background = { reference = pam_cathedral_construction }
	window = big_event_window
	theme = christian
	widgets = {
		widget = {
			gui = event_window_widget_vfx_stained_glass
			container = background_shader_vfx_container
		}
	}
	immediate = {
		save_scope_as = contributor
		#Priest: cathedral owner, else court chaplain if you are owner, else local clergy
		if = {
			limit = {
				root != scope:owner
				scope:owner = {
					is_alive = yes
				}
			}
			scope:owner = {
				save_scope_as = religion_buddy
			}
		}
		else_if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					basic_is_available_ai = yes
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = religion_buddy
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:religion_buddy
				}
			}
			ordered_pool_character = {
				province = scope:province
				limit = {
					is_clergy = yes
					faith = scope:province.faith
					basic_is_available_ai = yes
					NOT = {
						this = root
					}
				}
				order_by = primary_title.tier
				save_scope_as = religion_buddy
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:religion_buddy
				}
			}
			create_character = {
				template = priest_character_template
				dynasty = none
				location = scope:province
				culture = scope:province.culture
				faith = scope:province.faith
				rite = scope:province.rite
				save_scope_as = religion_buddy
			}
			scope:religion_buddy = {
				add_character_flag = {
					flag = pam_great_projects_fake_priest
					days = 10
				}
			}
		}
		#Glazier: skilled local pool character, else temporary workshop hand
		ordered_pool_character = {
			province = scope:province
			limit = {
				learning >= high_skill_rating
				culture = scope:province.culture
				faith = scope:province.faith
				is_available_ai_adult = yes
				NOT = {
					this = root
				}
				trigger_if = {
					limit = {
						exists = scope:religion_buddy
					}
					NOT = {
						this = scope:religion_buddy
					}
				}
			}
			order_by = learning
			save_scope_as = glazier
		}
		if = {
			limit = {
				NOT = {
					exists = scope:glazier
				}
			}
			create_character = {
				template = generic_peasant_character
				dynasty = none
				location = scope:province
				culture = scope:province.culture
				faith = scope:province.faith
				rite = scope:province.rite
				learning = {
					min_template_high_skill
					max_template_high_skill
				}
				save_scope_as = glazier
			}
			scope:glazier = {
				add_character_flag = {
					flag = pam_great_projects_fake_glazier
					days = 10
				}
			}
		}
		character:saint_0001 = {
			save_scope_as = blessed_mary
		}
	}
	after = {
		scope:glazier ?= {
			if = {
				limit = {
					has_character_flag = pam_great_projects_fake_glazier
				}
				silent_disappearance_effect = yes
			}
		}
		scope:religion_buddy ?= {
			if = {
				limit = {
					has_character_flag = pam_great_projects_fake_priest
				}
				silent_disappearance_effect = yes
			}
		}
	}

	#kingship / Tree of Jesse
	option = { #option a
		trigger = {
			#These are triggered this way to avoid crowding option with trait icons
			trigger_if = {
				limit = {
					OR = {
						highest_held_title_tier >= tier_kingdom
						legitimacy_level <= 3
					}
				}
				OR = {
					highest_held_title_tier >= tier_kingdom
					legitimacy_level <= 3
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = ambitious
						has_trait = august
						has_trait = born_in_the_purple
					}
				}
				OR = {
					has_trait = ambitious
					has_trait = august
					has_trait = born_in_the_purple
				}
			}
			trigger_else = {
				OR = {
					has_trait = diplomat
					has_lifestyle = diplomacy_lifestyle
					has_trait = education_diplomacy_4
				}
			}
		}
		name = pam_great_projects_events.0003.a
		flavor = pam_great_projects_events.0003.a.flavor
		custom_tooltip = pam_great_projects_events.0003.a.tt
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		scope:province = {
			set_variable = {
				name = cathedral_glass_tree_of_jesse
			}
		}
		if = {
			limit = { exists = dynasty }
			dynasty = {
				add_dynasty_prestige = minor_dynasty_prestige_gain
			}
		}
		ai_chance = {
			base = 500
		}
	}
	#donor portrait / dynasty
	option = { #option b
		trigger = {
			dynasty ?= {
				#These are triggered this way to avoid crowding option with trait icons
				trigger_if = {
					limit = {
						root = {
							OR = {
								has_trait = arrogant
								has_trait = gregarious
								has_trait = lustful
							}
						}
					}
					root = {
						OR = {
							has_trait = arrogant
							has_trait = gregarious
							has_trait = lustful
						}
					}
				}
				trigger_else_if = {
					limit = {
						OR = {
							dynasty_prestige_level >= 2
							root = {
								is_dynast = yes
							}
							root = {
								has_trait = family_first
							}
						}
					}
					OR = {
						dynasty_prestige_level >= 2
						root = {
							is_dynast = yes
						}
						root = {
							has_trait = family_first
						}
					}
				}
				trigger_else = {
					OR = {
						root = {
							has_trait = generous
						}
						dynasty_prestige_level >= 1
					}
				}
			}
		}
		name = pam_great_projects_events.0003.b
		custom_tooltip = pam_great_projects_events.0003.b.tt
		scope:province = {
			set_variable = {
				name = cathedral_glass_dynasty
			}
		}
		add_prestige = minor_prestige_gain
		ai_chance = {
			base = 500
		}
	}
	#pilgrim miracles
	option = { #option c
		trigger = {
			#These are triggered this way to avoid crowding option with trait icons
			trigger_if = {
				limit = {
					OR = {
						has_trait = pilgrim
					}
				}
				OR = {
					has_trait = pilgrim
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = improvident
						has_trait = holy_warrior
					}
				}
				OR = {
					has_trait = improvident
					has_trait = holy_warrior
				}
			}
			trigger_else = {
				OR = {
					has_trait = diligent
					has_trait = fickle
				}
			}
		}
		name = pam_great_projects_events.0003.c
		custom_tooltip = pam_great_projects_events.0003.c.tt
		scope:province = {
			set_variable = {
				name = cathedral_glass_pilgrim
			}
		}
		if = {
			limit = { has_trait = pilgrim }
			add_trait_xp = {
				trait = pilgrim
				value = {
					value = pilgrim_xp_gain_minor_value
					multiply = 2
				}
			}
			add_piety = minor_piety_gain
		}
		ai_chance = {
			base = 500
		}
	}
	#Marian light
	option = { #option d
		trigger = {
			trigger_if = {
				limit = {
					OR = {
						rite = {
							rite_has_tenet = tenet_dulia
						}
						has_personal_tenet = tenet_dulia
					}
				}
				OR = {
					rite = {
						rite_has_tenet = tenet_dulia
					}
					has_personal_tenet = tenet_dulia
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = devoted
						has_trait = humble
					}
				}
				OR = {
					has_trait = devoted
					has_trait = humble
				}
			}
			trigger_else = {
				OR = {
					has_trait = temperate
					piety_level >= 4
				}
			}
		}
		name = pam_great_projects_events.0003.d
		flavor = pam_great_projects_events.0003.d.flavor
		custom_tooltip = pam_great_projects_events.0003.d.tt
		custom_tooltip = pam_great_projects_events.0003.d.dulia.tt
		scope:province = {
			set_variable = {
				name = cathedral_glass_marian_light
			}
		}
		stress_and_fulfillment_impact = { base = minor_stress_impact_loss }
		if = {
			limit = { has_spiritual_fulfillment_type = christian_fulfillment }
			if = {
				limit = { has_personal_tenet = tenet_dulia }
				change_spiritual_fulfillment = major_spiritual_fulfillment_value
			}
			else = {
				change_spiritual_fulfillment = medium_spiritual_fulfillment_value
			}
		}
		ai_chance = {
			base = 100
		}
	}
	#martyrdom cycle
	option = {
		trigger = {
			#These are triggered this way to avoid crowding option with trait icons
			trigger_if = {
				limit = {
					has_trait = zealous
				}
				has_trait = zealous
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = brave
						has_trait = stubborn
						has_trait = contrite
					}
				}
				OR = {
					has_trait = brave
					has_trait = stubborn
					has_trait = contrite
				}
			}
			trigger_else = {
				has_trait = theologian
			}
		}
		name = pam_great_projects_events.0003.e
		custom_tooltip = pam_great_projects_events.0003.e.tt
		scope:province = {
			set_variable = {
				name = cathedral_glass_martyrdom
			}
		}
		if = {
			limit = {
				has_trait = zealous
				has_spiritual_fulfillment_type = christian_fulfillment
			}
			add_piety = major_piety_gain
			stress_and_fulfillment_impact = { base = minor_stress_impact_loss }
		}
		scope:owner ?= {
			if = {
				limit = {
					this != root
				}
				send_interface_message = {
					type = msg_great_project_reward
					title = pam_great_projects_events.0003.e.owner_msg.title
					desc = pam_great_projects_events.0003.e.owner_msg.desc
					right_icon = scope:contributor
					add_piety = medium_piety_gain
					if = {
						limit = {
							has_spiritual_fulfillment_type = christian_fulfillment
						}
						change_spiritual_fulfillment = medium_spiritual_fulfillment_value
					}
				}
			}
			else = {
				add_piety = medium_piety_gain
				if = {
					limit = {
						has_spiritual_fulfillment_type = christian_fulfillment
					}
					change_spiritual_fulfillment = medium_spiritual_fulfillment_value
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = zealous
				add = 200
			}
		}
	}
}

# Building types are not event scopes, so the great project is saved for [cathedral_building.GetName]
scripted_effect pam_cathedral_save_finished_building_scope_effect = {
	if = {
		limit = { exists = scope:great_project }
		scope:great_project = {
			save_scope_as = cathedral_building
		}
	}
	else = {
		random_great_project = {
			limit = {
				OR = {
					great_project_type = pam_cathedral_01
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
				OR = {
					great_project_founder = root
					great_project_owner = root
				}
			}
			save_scope_as = great_project
			save_scope_as = cathedral_building
		}
	}
}

#Cathedral funded (starting event)
pam_great_projects_events.0005 = {
	type = character_event
	title = pam_great_projects_events.0005.t
	desc = {
		desc = pam_great_projects_events.0005.desc.intro
		triggered_desc = {
			trigger = {
				exists = scope:optional_contributor
			}
			desc = pam_great_projects_events.0005.desc.contributor
		}
		desc = pam_great_projects_events.0005.desc.outro 
	}
	center_portrait = {
		character = scope:owner
		animation = preaching
	}
	left_portrait = {
		trigger = {
			exists = scope:founder_not_owner
		}
		character = scope:founder_not_owner
		animation = prayer_standing_eyes
		camera = camera_event_center_pointing_right
	}
	right_portrait = {
		trigger = {
			exists = scope:contributor_or_realm_priest
			scope:contributor_or_realm_priest != scope:owner
		}
		character = scope:contributor_or_realm_priest
		animation = steward
		camera = camera_event_center_pointing_left
	}
	override_background = {
		reference = terrain_scope 
	}
	window = big_event_window
	theme = christian
	immediate = {
		play_music_cue = mx_cue_deus_hoc_vult
		pam_cathedral_save_finished_building_scope_effect = yes
		scope:province = { save_scope_as = background_terrain_scope }
		scope:founder = {
			if = {
				limit = {
					scope:owner != scope:founder
				}
				save_scope_as = founder_not_owner
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:founder_not_owner
				}
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
				 	basic_is_available_ai = yes
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = founder_not_owner
			}
		}
		scope:great_project = {
			every_contribution = {
				limit = {
					contribution_is_funded = yes
				}
				save_scope_as = contribution
				contributor ?= {
					if = {
						limit = {
							this != scope:owner
							this != scope:founder
							# The chaplain can stand in as founder_not_owner and also have funded a contribution; keep the portraits distinct
							trigger_if = {
								limit = { exists = scope:founder_not_owner }
								this != scope:founder_not_owner
							}
						}
						save_scope_as = optional_contributor
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:optional_contributor
				scope:optional_contributor != scope:owner
			}
			scope:optional_contributor = {
				save_scope_as = contributor_or_realm_priest
			}
		}
		else_if = {
			limit = {
				NOT = {
					exists = scope:optional_contributor	
				}
				exists = scope:founder_not_owner
				scope:founder_not_owner != cp:councillor_court_chaplain
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
				 	basic_is_available_ai = yes
				}
				cp:councillor_court_chaplain != scope:owner
			}
			cp:councillor_court_chaplain = {
				save_scope_as = contributor_or_realm_priest
			}
		}
	}
	
	#Option a)
	option = {
		name = pam_great_projects_events.0005.a
		if = {
			limit = {
				root = scope:founder
			}
			trigger_event = {
				id = pam_great_projects_events.0006
				days = 2
			}
		}
	}
}

#Ongoing Cathedral Construction Events

# Finds an architect type person to accompany you during cathedral construction events
scripted_effect pam_cathedral_save_architect_scope_effect = {
	if = {
		limit = {
			employs_court_position = royal_architect_court_position
			any_court_position_holder = {
				type = royal_architect_court_position
			}
		}
		random_court_position_holder = {
			type = royal_architect_court_position
			save_scope_as = architect
		}
	}
	else_if = {
		limit = {
			exists = cp:councillor_steward
			cp:councillor_steward = {
				basic_is_available_ai = yes
			}
		}
		cp:councillor_steward = {
			save_scope_as = architect
		}
	}
	else_if = {
		limit = {
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				basic_is_available_ai = yes
			}
		}
		cp:councillor_court_chaplain = {
			save_scope_as = architect
		}
	}
	else = {
		ordered_courtier = {
			limit = {
				would_be_valid_for_court_position = {
					employer = root
					court_position = royal_architect_court_position
				}
			}
			order_by = aptitude:royal_architect_court_position
			save_scope_as = architect
		}
	}
}
scripted_trigger pam_cathedral_has_architect_character_trigger = {
	OR = {
		AND = {
			employs_court_position = royal_architect_court_position
			any_court_position_holder = {
				type = royal_architect_court_position
			}
		}
		AND = {
			exists = cp:councillor_steward
			cp:councillor_steward = {
				basic_is_available_ai = yes
			}
		}
		AND = {
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				basic_is_available_ai = yes
			}
		}
		any_courtier = {
			would_be_valid_for_court_position = {
				employer = root
				court_position = royal_architect_court_position
			}
		}
	}
}
scripted_effect pam_cathedral_disappear_spare_event_npc_effect = {
	$CHARACTER$ = {
		if = {
			limit = {
				is_alive = yes
				is_imprisoned = no
				NOT = {
					is_courtier_of = root
				}
			}
			silent_disappearance_effect = yes
		}
	}
}
scripted_effect pam_cathedral_save_owner_scope_effect = {
	if = {
		limit = {
			NOT = {
				exists = scope:owner
			}
		}
		random_great_project = {
			limit = {
				OR = {
					great_project_type = pam_cathedral_01
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
				great_project_founder = root
			}
			great_project_owner = {
				save_scope_as = owner
			}
		}
	}
}
#Cathedral Layout and building options
pam_great_projects_events.0006 = {
	type = character_event
	title = pam_great_projects_events.0006.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:architect
				}
				desc = pam_great_projects_events.0006.desc.intro_architect
			}
			desc = pam_great_projects_events.0006.desc.intro_no_architect
		}
		desc = pam_great_projects_events.0006.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:architect
					stewardship >= scope:architect.stewardship
				}
				desc = pam_great_projects_events.0006.desc.steward_founder
			}
			triggered_desc = {
				trigger = {
					exists = scope:architect
					scope:architect.stewardship > stewardship
				}
				desc = pam_great_projects_events.0006.desc.steward_architect
			}
		}
		
		triggered_desc = {
			trigger = {
				exists = scope:architect
				scope:architect.stewardship > stewardship
			}
			desc = pam_great_projects_events.0006.desc.architect_explanation
		}
		desc = pam_great_projects_events.0006.desc.foundations
	}
	left_portrait = {
		character = root
		animation = survey
		camera = camera_body_right
	}
	right_portrait = {
		trigger = {
			exists = scope:architect
		}
		character = scope:architect
		animation = pointing
		camera = camera_event_left_to_the_left_pointing_in
	}
	#show the owner/archbishop if he is not in the other portraits 
	lower_center_portrait = {
		trigger = {
			exists = scope:owner
			scope:owner != root
			trigger_if = {
				limit = {
					exists = scope:architect
				}
				scope:owner != scope:architect
			}
		}
		character = scope:owner
		animation = personality_honorable
	}
	override_background = {
		reference = terrain_scope 
	}
	window = big_event_window
	theme = christian
	immediate = {
		scope:province = { save_scope_as = background_terrain_scope }
		pam_cathedral_save_owner_scope_effect = yes
		pam_cathedral_save_architect_scope_effect = yes
	}
	#Option a)
	option = {
		name = pam_great_projects_events.0006.a
		trigger = {
			root = scope:founder
			scope:owner = {
				domicile ?= {
					is_domicile_type = ecclesiastical_domicile
					domicile_building_has_free_internal_slot = ecclesiastical_domicile_main_01
					NOT = { has_domicile_building_or_higher = cathedral_crypt_01 }
					# This option adds the crypt, so hide it when the cathedral has no room
					domicile_building_has_free_internal_slot = cathedral_crypt_01
				}
			}
		}
		custom_tooltip = pam_great_projects_events.0006.a.tt
		scope:owner = {
			domicile = {
				add_domicile_building = cathedral_crypt_01
			}
		}
		if = {
			limit = {
				scope:owner != scope:founder
			}
			scope:founder = {
				add_character_modifier = {
					modifier = pam_cathedral_founder_crypt_modifier
					years = 5
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				government_has_flag = government_is_ecclesiastical
			}
		}
	}
	#Option b)
	option = {
		name = pam_great_projects_events.0006.b
		custom_tooltip = pam_great_projects_events.0006.b.tt
		scope:province = {
			set_variable = {
				name = cathedral_pilgrim_xp
			}
			set_variable = {
				name = cathedral_extended_nave
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 200
				OR = {
					has_trait = pilgrim
					has_trait = zealous
				}
			}
		}
	}
	#Option c)
	option = {
		name = pam_great_projects_events.0006.c
		add_piety = medium_piety_gain
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
		}
	}
}

#Ongoing Cathedral Building Events

#Cathedral Rib vault construction 
pam_great_projects_events.0007 = {
	type = character_event
	title = pam_great_projects_events.0007.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:architect
				}
				desc = pam_great_projects_events.0007.desc.intro_architect
			}
			desc = pam_great_projects_events.0007.desc.intro_no_architect
		}
		triggered_desc = {
			trigger = {
				exists = scope:architect
			}
			desc = pam_great_projects_events.0007.desc.architect
		}
		triggered_desc = {
			trigger = {
				exists = scope:architect
			}
			desc = pam_great_projects_events.0007.desc.architect_says
		}
		desc = pam_great_projects_events.0007.desc.outro
	}
	left_portrait = {
		character = root
		animation = throne_room_conversation_4
		camera = camera_body_right
	}
	right_portrait = {
		trigger = {
			exists = scope:architect
		}
		character = scope:architect
		animation = admiration
		camera = camera_body_left
	}
	override_background = { reference = pam_cathedral_construction }
	window = big_event_window
	theme = christian
	trigger = {
		any_great_project = {
			OR = {
				great_project_type = pam_cathedral_01
				great_project_type = pam_cathedral_02
				great_project_type = pam_cathedral_03
			}
			great_project_founder = root
			great_project_location ?= {
				NOT = {
					has_variable = early_construction_event
				}
			}
		}
	}
	immediate = {
		save_scope_as = founder
		random_great_project = {
			limit = {
				OR = {
					great_project_type = pam_cathedral_01
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
				great_project_founder = root
				great_project_location ?= {
					NOT = {
						has_variable = early_construction_event
					}
				}
			}
			great_project_location ?= {
				save_scope_as = province
				set_variable = {
					name = early_construction_event
				}
			}
		}
		pam_cathedral_save_architect_scope_effect = yes
	}
	#Option a)
	option = {
		name = pam_great_projects_events.0007.a
		custom_tooltip = pam_great_projects_events.0007.a.tt
		stress_and_fulfillment_impact = {
			lifestyle_mystic = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			content = minor_stress_impact_gain
		}
		add_learning_lifestyle_xp = minor_lifestyle_xp
		scope:province = {
			set_variable = {
				name = cathedral_mystic_xp
			}
			set_variable = {
				name = cathedral_stars_vault
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = content
			}
			modifier = {
				add = 150
				OR = {
					has_trait = lifestyle_mystic
					has_trait = zealous
				}
			}
			modifier = {
				add = 100
				has_trait = ambitious
			}
		}
	}
	#Option b)
	option = {
		name = pam_great_projects_events.0007.b
		stress_and_fulfillment_impact = {
			theologian = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			content = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		faith = {
		change_fervor = {
				value = trivial_fervor_value
				desc = fervor_gain_cathedral_jonah_sermon
			}
		}
		
		
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = arrogant
					has_trait = ambitious
				}
			}
			modifier = {
				add = 200
				OR = {
					has_trait = theologian
					has_trait = zealous
				}
			}
			modifier = {
				add = 100
				OR = {
					has_trait = humble
					has_trait = content
				}
			}
		}
	}
	#Option c)
	option = {
		name = pam_great_projects_events.0007.c
		add_piety = medium_piety_gain
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
		}
	}
}

#duel for option outcome of pam_great_projects_events.0008
scripted_effect pam_cathedral_bell_casting_resolution_effect = {
	scope:bell_maker_son = {
		duel = {
			skill = learning
			value = high_skill_rating
			localization = pam_cathedral_bell_casting_duel
			75 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
					min = -74
					max = 15
				}
				custom_tooltip = {
					text = pam_great_projects_events.0008.duel.success
					trigger_event = {
						id = pam_great_projects_events.0009
						days = { 5 10 }
					}
				}
			}
			25 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
					min = -24
				}
				custom_tooltip = {
					text = pam_great_projects_events.0008.duel.failure
					trigger_event = {
						id = pam_great_projects_events.0010
						days = { 5 10 }
					}
				}
			}
		}
	}
}
#Cathedral Belltower construction
pam_great_projects_events.0008 = {
	type = character_event
	title = pam_great_projects_events.0008.t
	desc = {
		desc = pam_great_projects_events.0008.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:architect
				}
				desc = pam_great_projects_events.0008.desc.architect
			}
			desc = pam_great_projects_events.0008.desc.no_architect
		}
		desc = pam_great_projects_events.0008.desc.need_bell
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = cathedral_bell_tragedy_version
					exists = scope:epidemic
				}
				desc = pam_great_projects_events.0008.desc.plague_named
			}
			triggered_desc = {
				trigger = {
					has_character_flag = cathedral_bell_tragedy_version
				}
				desc = pam_great_projects_events.0008.desc.plague_generic
			}
			desc = pam_great_projects_events.0008.desc.ordinary_body
		}
		triggered_desc = {
			trigger = {
				has_character_flag = cathedral_bell_tragedy_version
			}
			desc = pam_great_projects_events.0008.desc.outro
		}
	}
	center_portrait = {
		trigger = {
			exists = scope:architect
		}
		character = scope:architect
		animation = debating
		camera = camera_activity_horse
	}
	left_portrait = {
		character = root
		animation = throne_room_conversation_4
		camera = camera_event_center_pointing_right
	}
	right_portrait = {
		trigger = {
			exists = scope:bell_maker_son
		}
		character = scope:bell_maker_son
		animation = personality_bold
		camera = camera_event_center_pointing_left
	}
	#show the owner/archbishop if he is not in the other portraits
	lower_center_portrait = {
		trigger = {
			exists = scope:owner
			scope:owner != root
			trigger_if = {
				limit = {
					exists = scope:architect
				}
				scope:owner != scope:architect
			}
			trigger_if = {
				limit = {
					exists = scope:bell_maker_son
				}
				scope:owner != scope:bell_maker_son
			}
		}
		character = scope:owner
		animation = personality_honorable
	}
	override_background = { reference = pam_cathedral_construction }
	window = big_event_window
	theme = christian
	trigger = {
		any_great_project = {
			OR = {
				great_project_type = pam_cathedral_01
				great_project_type = pam_cathedral_02
				great_project_type = pam_cathedral_03
			}
			great_project_founder = root
			great_project_location ?= {
				NOT = {
					has_variable = cathedral_bell_casting_event
				}
			}
			great_project_owner = {
				domicile ?= {
					is_domicile_type = ecclesiastical_domicile
					has_domicile_building_or_higher = ecclesiastical_domicile_main_01
					NOT = { has_domicile_building_or_higher = cathedral_belltower_01 }
					# Every option here ends in a belltower, so don't offer the event with the cathedral full
					domicile_building_has_free_internal_slot = cathedral_belltower_01
				}
			}
		}
	}
	immediate = {
		save_scope_as = founder
		random_great_project = {
			limit = {
				OR = {
					great_project_type = pam_cathedral_01
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
				great_project_founder = root
				great_project_location ?= {
					NOT = {
						has_variable = cathedral_bell_casting_event
					}
				}
				great_project_owner = {
					domicile ?= {
						is_domicile_type = ecclesiastical_domicile
						has_domicile_building_or_higher = ecclesiastical_domicile_main_01
						NOT = { has_domicile_building_or_higher = cathedral_belltower_01 }
						domicile_building_has_free_internal_slot = cathedral_belltower_01
					}
				}
			}
			great_project_owner = {
				save_scope_as = owner
			}
			great_project_location ?= {
				save_scope_as = province
				set_variable = {
					name = cathedral_bell_casting_event
				}
				if = {
					limit = {
						any_province_epidemic = { }
					}
					random_province_epidemic = {
						save_scope_as = epidemic
					}
				}
			}
			save_scope_as = great_project
		}
		pam_cathedral_save_finished_building_scope_effect = yes
		pam_cathedral_save_architect_scope_effect = yes
		#find a bell_marker's son
		ordered_pool_character = {
			province = scope:province
			limit = {
				is_male = yes
				age >= 14
				age <= 22
				learning >= high_skill_rating
				culture = scope:province.culture
				faith = scope:province.faith
				is_available_ai_adult = yes
			}
			order_by = learning
			save_scope_as = bell_maker_son
		}
		#make one if there is none to be found in the pool
		if = {
			limit = {
				NOT = {
					exists = scope:bell_maker_son
				}
			}
			create_character = {
				template = generic_peasant_character
				age = { 14 22 }
				gender = male
				location = scope:province
				culture = scope:province.culture
				faith = scope:province.faith
				rite = scope:province.rite
				learning = {
					min_template_high_skill
					max_template_high_skill
				}
				save_scope_as = bell_maker_son
			}
		}
		#80/20 tragedy vs ordinary craftsman framing; only the tragedy path spends the deceased-father story
		random_list = {
			80 = {}
			20 = {
				add_character_flag = {
					flag = cathedral_bell_tragedy_version
					days = 90
				}
			}
		}
	}
	
	#Option aa) sadistic, whip his flesh off if he fails 
	option = {
		name = pam_great_projects_events.0008.aa
		trigger = {
			has_trait = sadistic
		}
		trait = sadistic
		custom_tooltip = pam_great_projects_events.0008.belltower_may.tt
		add_dread = medium_dread_gain
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		stress_and_fulfillment_impact = {
			sadistic = medium_stress_impact_loss
			just = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		add_character_flag = {
			flag = pam_cathedral_bell_dread_path
			days = 90
		}
		add_character_flag = {
			flag = pam_cathedral_bell_flay_path
			days = 90
		}
		pam_cathedral_bell_casting_resolution_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = just
					has_trait = compassionate
				}
			}
		}
	}
	#Option a) kill him if he fails 
	option = {
		name = pam_great_projects_events.0008.a
		trigger = {
			NOT = {
				has_trait = sadistic
			}
		}
		custom_tooltip = pam_great_projects_events.0008.a.tt
		custom_tooltip = pam_great_projects_events.0008.belltower_may.tt
		add_dread = medium_dread_gain
		stress_and_fulfillment_impact = {
			callous = minor_stress_impact_loss
			just = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		add_character_flag = {
			flag = pam_cathedral_bell_dread_path
			days = 90
		}
		pam_cathedral_bell_casting_resolution_effect = yes
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = just
					has_trait = compassionate
					has_trait = honest
					has_trait = forgiving
				}
			}
			modifier = {
				add = 150
				has_trait = callous
			}
		}
	}
	#Option b)
	option = {
		name = pam_great_projects_events.0008.b
		custom_tooltip = pam_great_projects_events.0008.b.tt
		custom_tooltip = pam_great_projects_events.0008.belltower_may.tt
		flavor = pam_great_projects_events.0008.b.flavor
		add_piety = massive_piety_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		add_character_flag = {
			flag = pam_cathedral_bell_faith_path
			days = 90
		}
		pam_cathedral_bell_casting_resolution_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = arrogant
				}
			}
			modifier = {
				add = 200
				OR = {
					has_trait = zealous
					has_trait = humble
				}
			}
		}
	}
	#Option c)
	option = {
		name = pam_great_projects_events.0008.c
		trigger = {
			scope:owner.domicile = {
				domicile_building_has_free_internal_slot = ecclesiastical_domicile_main_01
			}
		}
		scope:owner = {
			domicile = {
				add_domicile_building = cathedral_belltower_01
			}
		}
		hidden_effect = {
			pam_cathedral_disappear_spare_event_npc_effect = { CHARACTER = scope:bell_maker_son }
		}
		stress_impact = {
			base = medium_stress_impact_loss
		}
		ai_chance = {
			base = 75
			modifier = {
				add = 100
				has_trait = cynical
			}
		}
	}
}

#Cathedral bell successfully cast
pam_great_projects_events.0009 = {
	type = character_event
	title = pam_great_projects_events.0009.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:architect
				}
				desc = pam_great_projects_events.0009.desc.body.architect
			}
			desc = pam_great_projects_events.0009.desc.body
		}
		desc = pam_great_projects_events.0009.desc.success_end
	}
	center_portrait = {
		trigger = {
			exists = scope:architect
		}
		character = scope:architect
		animation = admiration
	}
	left_portrait = {
		character = root
		animation = happiness
		camera = camera_body_right
	}
	right_portrait = {
		trigger = {
			exists = scope:bell_maker_son
		}
		character = scope:bell_maker_son
		animation = divine_ecstasy
		camera = camera_body_left
	}
	override_background = { reference = pam_cathedral_construction }
	window = big_event_window
	theme = christian
	trigger = {
		exists = scope:bell_maker_son
		scope:bell_maker_son = {
			is_alive = yes
		}
		any_great_project = {
			OR = {
				great_project_type = pam_cathedral_01
				great_project_type = pam_cathedral_02
				great_project_type = pam_cathedral_03
			}
			great_project_founder = root
			great_project_location ?= {
				has_variable = cathedral_bell_casting_event
			}
		}
		scope:owner.domicile = {
			domicile_building_has_free_internal_slot = ecclesiastical_domicile_main_01
		}
	}
	immediate = {
		pam_cathedral_save_architect_scope_effect = yes
	}
	after = {
		remove_character_flag = pam_cathedral_bell_dread_path
		remove_character_flag = pam_cathedral_bell_flay_path
		remove_character_flag = pam_cathedral_bell_faith_path
		pam_cathedral_disappear_spare_event_npc_effect = { CHARACTER = scope:bell_maker_son }
	}
	option = {
		name = pam_great_projects_events.0009.a
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		add_stress = medium_stress_loss
		scope:owner = {
			domicile = {
				add_domicile_building = cathedral_belltower_02
			}
		}
		
		ai_chance = {
			base = 100
		}
	}
}

#Cathedral bell casting failed
pam_great_projects_events.0010 = {
	type = character_event
	title = pam_great_projects_events.0010.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:architect
				}
				desc = pam_great_projects_events.0009.desc.body.architect
			}
			desc = pam_great_projects_events.0009.desc.body
		}
		desc = pam_great_projects_events.0010.desc.failure_end
	}
	center_portrait = {
		trigger = {
			exists = scope:architect
		}
		character = scope:architect
		animation = worry
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_character_flag = pam_cathedral_bell_flay_path
			}
			animation = whipping
		}
		triggered_animation = {
			trigger = {
				has_character_flag = pam_cathedral_bell_dread_path
				NOT = {
					has_character_flag = pam_cathedral_bell_flay_path
				}
			}
			animation = chudan_no_kamae
		}
		animation = disgust
		camera = camera_body_right
	}
	right_portrait = {
		trigger = {
			exists = scope:bell_maker_son
		}
		character = scope:bell_maker_son
		animation = fear
		camera = camera_body_left
	}
	override_background = { reference = pam_cathedral_construction }
	window = big_event_window
	theme = christian
	trigger = {
		exists = scope:bell_maker_son
		scope:bell_maker_son = {
			is_alive = yes
		}
		any_great_project = {
			OR = {
				great_project_type = pam_cathedral_01
				great_project_type = pam_cathedral_02
				great_project_type = pam_cathedral_03
			}
			great_project_founder = root
			great_project_location ?= {
				has_variable = cathedral_bell_casting_event
			}
		}
	}
	immediate = {
		pam_cathedral_save_architect_scope_effect = yes
	}
	after = {
		remove_character_flag = pam_cathedral_bell_dread_path
		remove_character_flag = pam_cathedral_bell_flay_path
		remove_character_flag = pam_cathedral_bell_faith_path
		pam_cathedral_disappear_spare_event_npc_effect = { CHARACTER = scope:bell_maker_son }
	}
	#Option a) kill the boy
	option = {
		name = pam_great_projects_events.0010.a
		trigger = {
			has_character_flag = pam_cathedral_bell_dread_path
		}
		if = {
			limit = {
				has_character_flag = pam_cathedral_bell_flay_path
			}
			scope:bell_maker_son = {
				death = {
					killer = root
					death_reason = death_torture
				}
			}
		}
		else = {
			scope:bell_maker_son = {
				death = {
					killer = root
					death_reason = death_execution
				}
			}
		}
		add_dread = major_dread_gain
		stress_and_fulfillment_impact = {
			sadistic = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = compassionate
			}
			modifier = {
				add = 150
				has_trait = sadistic
			}
		}
	}
	#Option b) spare the boy
	option = {
		name = {
			trigger = {
				has_character_flag = pam_cathedral_bell_faith_path
			}
			text = pam_great_projects_events.0010.b.faith
		}
		name = pam_great_projects_events.0010.b
		show_as_tooltip = {
			add_courtier = scope:bell_maker_son
		}
		hidden_effect = {
			if = {
				limit = {
					scope:bell_maker_son = {
						NOT = {
							is_courtier_of = root
						}
					}
				}
				add_courtier = scope:bell_maker_son
			}
		}
		if = {
			limit = {
				exists = capital_county
			}
			capital_county = {
				add_county_modifier = {
					modifier = pam_cathedral_bell_cracked_lesson_modifier
					years = 10
				}
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			just = minor_stress_impact_loss
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 200
				has_trait = compassionate
			}
		}
	}
	#Option c) bronze torture device
	option = {
		name = pam_great_projects_events.0010.c
		trigger = {
			has_character_flag = pam_cathedral_bell_dread_path
		}
		custom_tooltip = pam_great_projects_events.0010.c.tt
		if = {
			limit = {
				OR = {
					has_perk = dreadful_perk
					has_character_flag = pam_cathedral_bell_dreadful_perk_reward
				}
			}
			custom_tooltip = pam_great_projects_events.0010.c.intrigue_xp.tt
		}
		scope:bell_maker_son = {
			death = {
				killer = root
				death_reason = death_torture
			}
		}
		add_dread = massive_dread_gain
		add_tyranny = medium_tyranny_gain
		if = {
			limit = {
				NOT = {
					has_perk = dreadful_perk
				}
				NOT = {
					has_character_flag = pam_cathedral_bell_dreadful_perk_reward
				}
			}
			add_perk = dreadful_perk
			add_character_flag = pam_cathedral_bell_dreadful_perk_reward
		}
		else = {
			add_intrigue_lifestyle_xp = major_lifestyle_xp
		}
		add_character_modifier = {
			modifier = pam_cathedral_bell_bronze_torture_implements_modifier
			years = 10
		}
		stress_and_fulfillment_impact = {
			sadistic = medium_stress_impact_loss
			torturer = medium_stress_impact_loss
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				add = 150
				OR = {
					has_trait = sadistic
					has_trait = torturer
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = just
					has_trait = honest
					has_trait = forgiving
				}
			}
		}
	}
	#Option d) faith path
	option = {
		name = pam_great_projects_events.0010.d
		trigger = {
			has_character_flag = pam_cathedral_bell_faith_path
		}
		add_piety = medium_piety_gain
		add_stress = medium_stress_loss
		stress_and_fulfillment_impact = {
			zealous = medium_stress_impact_loss
			humble = medium_stress_impact_loss
			cynical = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = arrogant
				}
			}
			modifier = {
				add = 200
				OR = {
					has_trait = zealous
					has_trait = humble
				}
			}
		}
	}
}

#Cathedral Treadwheel Crane
pam_great_projects_events.0011 = {
	type = character_event
	title = pam_great_projects_events.0011.t
	desc = {
		desc = pam_great_projects_events.0011.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:architect
				}
				desc = pam_great_projects_events.0011.desc.architect
			}
			desc = pam_great_projects_events.0011.desc.no_architect
		}
		desc = pam_great_projects_events.0011.desc.outro
	}
	left_portrait = {
		character = root
		animation = survey
		camera = camera_body_right
	}
	right_portrait = {
		trigger = {
			exists = scope:architect
		}
		character = scope:architect
		animation = pointing
		camera = camera_event_center_away_pointing_left_fov25
	}
	override_background = { reference = pam_cathedral_construction }
	window = big_event_window
	theme = christian
	trigger = {
		any_great_project = {
			OR = {
				great_project_type = pam_cathedral_01
				great_project_type = pam_cathedral_02
				great_project_type = pam_cathedral_03
			}
			great_project_founder = root
			great_project_location ?= {
				NOT = {
					has_variable = cathedral_treadwheel_crane_event
				}
			}
		}
	}
	immediate = {
		save_scope_as = founder
		random_great_project = {
			limit = {
				OR = {
					great_project_type = pam_cathedral_01
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
				great_project_founder = root
				great_project_location ?= {
					NOT = {
						has_variable = cathedral_treadwheel_crane_event
					}
				}
			}
			save_scope_as = great_project
			great_project_location ?= {
				save_scope_as = province
				set_variable = {
					name = cathedral_treadwheel_crane_event
				}
			}
		}
		pam_cathedral_save_finished_building_scope_effect = yes
		pam_cathedral_save_architect_scope_effect = yes
		if = {
			limit = {
				exists = capital_county
			}
			capital_county = {
				save_scope_as = capital_county
			}
		}
	}
	option = {
		name = pam_great_projects_events.0011.a
		custom_tooltip = pam_great_projects_events.0011.a.tt
		add_learning_lifestyle_xp = minor_lifestyle_xp
		culture = {
			add_fascination_progress = pam_cathedral_treadwheel_fascination_progress_value
		}
		stress_and_fulfillment_impact = {
			architect = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			patient = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				OR = {
					has_trait = architect
					has_trait = diligent
				}
			}
			modifier = {
				add = 100
				learning >= high_skill_rating
			}
		}
	}
	option = {
		name = pam_great_projects_events.0011.b
		trigger = {
			exists = scope:capital_county
		}
		add_stewardship_lifestyle_xp = minor_lifestyle_xp
		scope:capital_county = {
			add_county_modifier = {
				modifier = pam_cathedral_treadwheel_crane_modifier
				years = 10
			}
		}
		stress_and_fulfillment_impact = {
			ambitious = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				stewardship >= high_skill_rating
			}
			modifier = {
				add = 100
				has_trait = ambitious
			}
			modifier = {
				factor = 0
				has_trait = content
			}
		}
	}
	option = {
		name = pam_great_projects_events.0011.c
		add_piety = medium_piety_gain
		stress_impact = {
			base = medium_stress_impact_loss
		}
		ai_chance = {
			base = 50
		}
	}
}

#Cathedral cantoria / singing loft
pam_great_projects_events.0013 = {
	type = character_event
	title = pam_great_projects_events.0013.t
	desc = pam_great_projects_events.0013.desc
	
	left_portrait = {
		character = root
		animation = throne_room_conversation_4
		camera = camera_event_center_pointing_right
	}
	center_portrait = {
		character = scope:architect
		animation = ecstasy
		camera = camera_activity_horse
	}
	right_portrait = {
		character = scope:choir_boy
		animation = personality_bold
		camera = camera_event_center_pointing_left
	}
	override_background = {
		trigger = {
			scope:great_project ?= {
				OR = {
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
			}
		}
		reference = pam_gothic_cathedral_interior
	}
	override_background = { reference = pam_romanesque_church_interior }
	window = big_event_window
	theme = christian
	trigger = {
		pam_cathedral_has_architect_character_trigger = yes
		any_great_project = {
			OR = {
				great_project_type = pam_cathedral_01
				great_project_type = pam_cathedral_02
				great_project_type = pam_cathedral_03
			}
			great_project_founder = root
			great_project_location ?= {
				NOT = {
					has_variable = cathedral_cantoria_event
				}
			}
			great_project_owner = {
				domicile ?= {
					is_domicile_type = ecclesiastical_domicile
					has_domicile_building_or_higher = ecclesiastical_domicile_main_01
					NOT = { has_domicile_building_or_higher = cathedral_cantoria_01 }
					# The only option here adds the cantoria, so don't offer it with the cathedral full
					domicile_building_has_free_internal_slot = cathedral_cantoria_01
				}
			}
		}
	}
	immediate = {
		save_scope_as = founder
		random_great_project = {
			limit = {
				OR = {
					great_project_type = pam_cathedral_01
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
				great_project_founder = root
				great_project_location ?= {
					NOT = {
						has_variable = cathedral_cantoria_event
					}
				}
				great_project_owner = {
					domicile ?= {
						is_domicile_type = ecclesiastical_domicile
						has_domicile_building_or_higher = ecclesiastical_domicile_main_01
						NOT = { has_domicile_building_or_higher = cathedral_cantoria_01 }
						domicile_building_has_free_internal_slot = cathedral_cantoria_01
					}
				}
			}
			save_scope_as = great_project
			great_project_owner = {
				save_scope_as = owner
			}
			great_project_location ?= {
				save_scope_as = province
				set_variable = {
					name = cathedral_cantoria_event
				}
			}
		}
		pam_cathedral_save_architect_scope_effect = yes
		#find a choir boy; family_castration cultures bias young enough for the castrato option to be valid
		if = {
			limit = {
				culture = { has_cultural_parameter = family_castration }
			}
			ordered_pool_character = {
				province = scope:province
				limit = {
					is_male = yes
					age >= 8
					age <= 11
					diplomacy >= high_skill_rating
					culture = scope:province.culture
					faith = scope:province.faith
					basic_is_available_ai = yes
				}
				order_by = diplomacy
				save_scope_as = choir_boy
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:choir_boy }
			}
			ordered_pool_character = {
				province = scope:province
				limit = {
					is_male = yes
					age >= 8
					age <= 14
					diplomacy >= high_skill_rating
					culture = scope:province.culture
					faith = scope:province.faith
					basic_is_available_ai = yes
				}
				order_by = diplomacy
				save_scope_as = choir_boy
			}
		}
		#make one if there is none to be found in the pool
		if = {
			limit = {
				NOT = { exists = scope:choir_boy }
			}
			if = {
				limit = {
					culture = { has_cultural_parameter = family_castration }
				}
				create_character = {
					template = generic_peasant_character
					age = { 8 11 }
					gender = male
					location = scope:province
					culture = scope:province.culture
					faith = scope:province.faith
					rite = scope:province.rite
					trait = beauty_good_2
					diplomacy = {
						min_template_high_skill
						max_template_high_skill
					}
					learning = {
						min_template_high_skill
						max_template_high_skill
					}
					save_scope_as = choir_boy
				}
			}
			else = {
				create_character = {
					template = generic_peasant_character
					age = { 8 14 }
					gender = male
					location = scope:province
					culture = scope:province.culture
					faith = scope:province.faith
					rite = scope:province.rite
					trait = beauty_good_2
					diplomacy = {
						min_template_high_skill
						max_template_high_skill
					}
					learning = {
						min_template_high_skill
						max_template_high_skill
					}
					save_scope_as = choir_boy
				}
			}
		}
	}
	option = {
		name = pam_great_projects_events.0013.a
		trigger = {
			scope:owner.domicile = {
				domicile_building_has_free_internal_slot = ecclesiastical_domicile_main_01
			}
		}
		scope:owner = {
			domicile = {
				add_domicile_building = cathedral_cantoria_01
			}
		}
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				OR = {
					has_trait = zealous
					has_trait = ambitious
				}
			}
		}
	}
	option = {
		name = pam_great_projects_events.0013.b
		show_as_tooltip = {
			add_courtier = scope:choir_boy
		}
		hidden_effect = {
			add_courtier = scope:choir_boy
		}
		if = {
			limit = {
				has_royal_court = yes
			}
			change_current_court_grandeur = minor_court_grandeur_gain
		}
		add_prestige = minor_prestige_gain
		add_character_modifier = {
			modifier = pam_cathedral_famed_choir_boy_modifier
			years = 10
		}
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			modifier = {
				add = 150
				OR = {
					has_trait = gregarious
					has_trait = ambitious
				}
			}
			modifier = {
				factor = 0
				has_trait = shy
			}
		}
	}
	#castrato: family_castration cultures may cut a young enough choir boy so his voice is preserved
	option = {
		name = pam_great_projects_events.0013.castrato
		add_internal_flag = dangerous
		custom_tooltip = pam_great_projects_events.0013.castrato.tt
		trigger = {
			culture = {
				has_cultural_parameter = family_castration
			}
			exists = scope:choir_boy
			scope:choir_boy = {
				age < 12
				NOR = {
					has_trait = eunuch
					has_trait = beardless_eunuch
					has_trait = eunuch_1
				}
			}
		}
		save_scope_as = actor
		scope:choir_boy = {
			save_scope_as = recipient
		}
		scope:owner = {
			domicile = {
				add_domicile_building = cathedral_cantoria_01
			}
		}
		show_as_tooltip = {
			add_courtier = scope:choir_boy
		}
		hidden_effect = {
			add_courtier = scope:choir_boy
			scope:choir_boy = {
				ep3_child_castration_effect = yes
			}
		}
		scope:choir_boy = {
			add_stress = medium_stress_gain
		}
		add_piety = minor_piety_loss
		stress_and_fulfillment_impact = {
			callous = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			compassionate = major_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = just
					has_trait = forgiving
				}
			}
			modifier = {
				add = 150
				OR = {
					has_trait = callous
					has_trait = ambitious
					has_trait = sadistic
				}
			}
		}
	}
	option = {
		name = pam_great_projects_events.0013.c
		trigger = {
			OR = {
				has_trait = cynical
				has_trait = sadistic
				has_trait = callous
				has_trait = deceitful
				has_trait = paranoid
			}
		}
		show_as_tooltip = {
			if = {
				limit = {
					exists = scope:architect
				}
				imprison = {
					target = scope:architect
					type = dungeon
				}
			}
			if = {
				limit = {
					exists = scope:choir_boy
				}
				imprison = {
					target = scope:choir_boy
					type = dungeon
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					exists = scope:architect
				}
				rightfully_imprison_character_less_verbose_effect = {
					TARGET = scope:architect
					IMPRISONER = root
				}
			}
			if = {
				limit = {
					exists = scope:choir_boy
				}
				rightfully_imprison_character_less_verbose_effect = {
					TARGET = scope:choir_boy
					IMPRISONER = root
				}
			}
		}
		add_character_modifier = {
			modifier = pam_cathedral_cantoria_scam_modifier
			years = 5
		}
		add_dread = medium_dread_gain
		add_tyranny = minor_tyranny_gain
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 200
				OR = {
					has_trait = cynical
					has_trait = sadistic
					has_trait = callous
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = just
					has_trait = forgiving
				}
			}
		}
	}
	option = {
		name = pam_great_projects_events.0013.d
		stress_impact = {
			base = minor_stress_impact_loss
		}
		if = {
			limit = {
				has_spiritual_fulfillment_type = christian_fulfillment
			}
			change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		}
		stress_and_fulfillment_impact = {
			content = minor_stress_impact_loss
			humble = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 100
				OR = {
					has_trait = content
					has_trait = humble
				}
			}
		}
	}
	after = {
		pam_cathedral_disappear_spare_event_npc_effect = { CHARACTER = scope:choir_boy }
	}
}

#Owner (archbishop) Events (the owner can also be the founder, but this is to insure some theocratic rulers always get a couple events during the course of the cathedral being built)
scripted_effect pam_cathedral_apply_archdiocese_sermon_effect = {
	scope:archdiocese ?= {
		every_county_in_clerical_region = {
			limit = {
				faith = scope:owner.faith
			}
			add_county_modifier = {
				modifier = $COUNTY_MODIFIER$
				years = $DURATION$
			}
			holder = {
				if = {
					limit = {
						is_landed = yes
						faith = scope:owner.faith
						NOT = {
							this = scope:owner
						}
					}
					hidden_effect = {
						add_character_modifier = {
							modifier = $RULER_MODIFIER$
							years = $DURATION$
						}
						if = {
							limit = {
								is_ai = no
							}
							send_interface_toast = {
								type = event_toast_effect_neutral
								title = pam_cathedral_west_portal_sermon_toast
								left_icon = scope:owner
								right_icon = scope:province.barony
							}
						}
					}
				}
			}
		}
	}
}

#Cathedral west completed sermon (event for archbishop/owner)
pam_great_projects_events.0012 = {
	type = character_event
	title = pam_great_projects_events.0012.t
	desc = pam_great_projects_events.0012.desc
	left_portrait = {
		character = root
		animation = preaching
		camera = camera_body_right
	}
	right_portrait = {
		trigger = {
			exists = scope:religion_buddy
		}
		character = scope:religion_buddy
		animation = writing
		camera = camera_event_center_close_to_right
	}
	override_background = { reference = pam_romanesque_church_exterior }
	window = big_event_window
	theme = christian
	trigger = {
		OR = {
			faith.religion = religion:catholic_religion
			faith.religion = religion:protestant_religion
			faith.religion = religion:eastern_orthodox_religion
			faith.religion = religion:oriental_orthodox_religion
		}
		any_great_project = {
			OR = {
				great_project_type = pam_cathedral_01
				great_project_type = pam_cathedral_02
				great_project_type = pam_cathedral_03
			}
			great_project_location ?= {
				NOT = {
					has_variable = cathedral_west_portal_sermon_event
				}
				county ?= {
					clerical_region_title ?= {
						holder = root
					}
				}
			}
		}
	}
	immediate = {
		save_scope_as = owner
		random_great_project = {
			limit = {
				OR = {
					great_project_type = pam_cathedral_01
					great_project_type = pam_cathedral_02
					great_project_type = pam_cathedral_03
				}
				great_project_location ?= {
					NOT = {
						has_variable = cathedral_west_portal_sermon_event
					}
					county ?= {
						clerical_region_title ?= {
							holder = root
						}
					}
				}
			}
			save_scope_as = great_project
			great_project_founder = {
				save_scope_as = founder
			}
			great_project_location ?= {
				save_scope_as = province
				set_variable = {
					name = cathedral_west_portal_sermon_event
				}
			}
		}
		pam_cathedral_save_finished_building_scope_effect = yes
		scope:province.county ?= {
			clerical_region_title ?= {
				save_scope_as = archdiocese
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					basic_is_available_ai = yes
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = religion_buddy
			}
		}
	}
	option = { #option a) #sermon of peace
		trigger = {
			trigger_if = {
				limit = {
					OR = {
						has_trait = just
						has_trait = compassionate
					}
				}
				OR = {
					has_trait = just
					has_trait = compassionate
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = calm
						has_trait = forgiving
					}
				}
				OR = {
					has_trait = calm
					has_trait = forgiving
				}
			}
			trigger_else = {
				has_trait = humble
			}
		}
		name = pam_great_projects_events.0012.a
		flavor = pam_great_projects_events.0012.a.flavor
		custom_tooltip = pam_great_projects_events.0012.a.tt
		hidden_effect = {
			pam_cathedral_apply_archdiocese_sermon_effect = {
				COUNTY_MODIFIER = pam_cathedral_sermon_peace_county_modifier
				RULER_MODIFIER = pam_cathedral_sermon_peace_ruler_modifier
				DURATION = 10
			}
		}
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			just = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			calm = minor_stress_impact_loss
			forgiving = minor_stress_impact_loss
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				OR = {
					has_trait = just
					has_trait = compassionate
				}
			}
			modifier = {
				add = 75
				OR = {
					has_trait = calm
					has_trait = forgiving
				}
			}
		}
	}
	option = {
		trigger = {
			trigger_if = {
				limit = {
					OR = {
						has_trait = diligent
						has_trait = architect
					}
				}
				OR = {
					has_trait = diligent
					has_trait = architect
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = education_stewardship
						has_trait = patient
					}
				}
				OR = {
					has_trait = education_stewardship
					has_trait = patient
				}
			}
			trigger_else = {
				has_lifestyle = stewardship_lifestyle
			}
		}
		name = pam_great_projects_events.0012.b
		flavor = pam_great_projects_events.0012.b.flavor
		custom_tooltip = pam_great_projects_events.0012.b.tt
		hidden_effect = {
			pam_cathedral_apply_archdiocese_sermon_effect = {
				COUNTY_MODIFIER = pam_cathedral_sermon_diligence_county_modifier
				RULER_MODIFIER = pam_cathedral_sermon_diligence_ruler_modifier
				DURATION = 10
			}
		}
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			diligent = minor_stress_impact_loss
			architect = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				OR = {
					has_trait = diligent
					has_trait = architect
				}
			}
			modifier = {
				add = 75
				OR = {
					has_trait = education_stewardship
					has_trait = patient
				}
			}
		}
	}
	option = {
		trigger = {
			trigger_if = {
				limit = {
					OR = {
						has_trait = gregarious
						has_trait = trusting
					}
				}
				OR = {
					has_trait = gregarious
					has_trait = trusting
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = diplomat
						has_trait = education_diplomacy
					}
				}
				OR = {
					has_trait = diplomat
					has_trait = education_diplomacy
				}
			}
			trigger_else = {
				OR = {
					has_lifestyle = diplomacy_lifestyle
					has_trait = honest
				}
			}
		}
		name = pam_great_projects_events.0012.c
		flavor = pam_great_projects_events.0012.c.flavor
		custom_tooltip = pam_great_projects_events.0012.c.tt
		hidden_effect = {
			pam_cathedral_apply_archdiocese_sermon_effect = {
				COUNTY_MODIFIER = pam_cathedral_sermon_unity_county_modifier
				RULER_MODIFIER = pam_cathedral_sermon_unity_ruler_modifier
				DURATION = 10
			}
		}
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_loss
			trusting = minor_stress_impact_loss
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				OR = {
					has_trait = gregarious
					has_trait = trusting
				}
			}
			modifier = {
				add = 75
				OR = {
					has_trait = diplomat
					has_trait = education_diplomacy
				}
			}
		}
	}
	option = {
		trigger = {
			trigger_if = {
				limit = {
					has_trait = content
				}
				has_trait = content
			}
			trigger_else_if = {
				limit = {
					has_trait = temperate
				}
				has_trait = temperate
			}
			trigger_else = {
				has_trait = chaste
			}
		}
		name = pam_great_projects_events.0012.d
		flavor = pam_great_projects_events.0012.d.flavor
		custom_tooltip = pam_great_projects_events.0012.d.tt
		hidden_effect = {
			pam_cathedral_apply_archdiocese_sermon_effect = {
				COUNTY_MODIFIER = pam_cathedral_sermon_rejoice_county_modifier
				RULER_MODIFIER = pam_cathedral_sermon_rejoice_ruler_modifier
				DURATION = 10
			}
		}
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			content = minor_stress_impact_loss
			temperate = minor_stress_impact_loss
			chaste = minor_stress_impact_loss
			wrathful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				has_trait = content
			}
			modifier = {
				add = 75
				has_trait = temperate
			}
		}
	}
	option = {
		trigger = {
			trigger_if = {
				limit = {
					OR = {
						has_trait = zealous
						has_trait = theologian
					}
				}
				OR = {
					has_trait = zealous
					has_trait = theologian
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						has_trait = lifestyle_mystic
						has_trait = brave
					}
				}
				OR = {
					has_trait = lifestyle_mystic
					has_trait = brave
				}
			}
			trigger_else = {
				OR = {
					has_lifestyle = learning_lifestyle
					has_trait = ambitious
				}
			}
		}
		name = pam_great_projects_events.0012.e
		flavor = pam_great_projects_events.0012.e.flavor
		custom_tooltip = pam_great_projects_events.0012.e.tt
		hidden_effect = {
			pam_cathedral_apply_archdiocese_sermon_effect = {
				COUNTY_MODIFIER = pam_cathedral_sermon_perseverance_county_modifier
				RULER_MODIFIER = pam_cathedral_sermon_perseverance_ruler_modifier
				DURATION = 10
			}
		}
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			theologian = minor_stress_impact_loss
			brave = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 150
				OR = {
					has_trait = zealous
					has_trait = theologian
				}
			}
			modifier = {
				add = 75
				OR = {
					has_trait = lifestyle_mystic
					has_trait = brave
				}
			}
		}
	}
	option = {
		name = pam_great_projects_events.0012.f
		flavor = pam_great_projects_events.0012.f.flavor
		custom_tooltip = pam_great_projects_events.0012.f.tt
		hidden_effect = {
			pam_cathedral_apply_archdiocese_sermon_effect = {
				COUNTY_MODIFIER = pam_cathedral_sermon_charity_county_modifier
				RULER_MODIFIER = pam_cathedral_sermon_charity_ruler_modifier
				DURATION = 10
			}
		}
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			generous = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 150
				OR = {
					has_trait = compassionate
					has_trait = generous
				}
			}
			modifier = {
				add = -40
				OR = {
					has_trait = greedy
					has_trait = callous
				}
			}
		}
	}
}

#Cathedral Building Conclusion Event
pam_great_projects_events.0020 = {
	type = character_event
	title = pam_great_projects_events.0020.t
	desc = pam_great_projects_events.0020.desc
	center_portrait = {
		character = scope:owner
		animation = prayer_crossing
	}
	left_portrait = {
		trigger = {
			exists = scope:founder_not_owner
		}
		character = scope:founder_not_owner
		animation = prayer_standing_eyes
		camera = camera_event_center_close_to_right
	}
	right_portrait = {
		trigger = {
			exists = scope:contributor_or_realm_priest
			scope:contributor_or_realm_priest != scope:owner
		}
		character = scope:contributor_or_realm_priest
		animation = divine_ecstasy
		camera = camera_event_center_pointing_left
	}
	override_background = { reference = pam_romanesque_church_exterior }
	window = big_event_window
	theme = christian
	immediate = {
		play_music_cue = mx_cue_deus_hoc_vult
		pam_cathedral_save_finished_building_scope_effect = yes
		scope:founder = {
			if = {
				limit = {
					scope:owner != scope:founder
					is_alive = yes
				}
				save_scope_as = founder_not_owner
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:founder_not_owner
				}
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
				 	basic_is_available_ai = yes
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = founder_not_owner
			}
		}
		scope:great_project = {
			every_contribution = {
				limit = {
					contribution_is_funded = yes
				}
				save_scope_as = contribution
				contributor ?= {
					if = {
						limit = {
							this != scope:owner
							this != scope:founder
						}
						save_scope_as = optional_contributor
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:optional_contributor
				scope:optional_contributor != scope:owner
				is_alive = yes
			}
			scope:optional_contributor = {
				save_scope_as = contributor_or_realm_priest
			}
		}
		else_if = {
			limit = {
				NOT = {
					exists = scope:optional_contributor	
				}
				exists = scope:founder_not_owner
				scope:founder_not_owner != cp:councillor_court_chaplain
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
				 	basic_is_available_ai = yes
				}
				cp:councillor_court_chaplain != scope:owner
			}
			cp:councillor_court_chaplain = {
				save_scope_as = contributor_or_realm_priest
			}
		}
	}
	
	#Option a)
	option = {
		name = pam_great_projects_events.0020.a
	}
}

