namespace = Plus

#reserved: Plus.1400 to Plus.1449

#######################################
# TEMPLE BUILDER EVENTS
#######################################

### TEMPLE BUILDING BEGINS

# Unlanded character with religious education decides to found a temple
character_event = {
	id = Plus.1400

	hide_window = yes
	
	min_age = 20
	max_age = 50
	capable_only = yes
	prisoner = no
	
	trigger = {
		is_ruler = no
		health = 4
		OR = {
			trait = detached_priest
			trait = martial_cleric
			trait = scholarly_theologian
			trait = mastermind_theologian
			learning = 8
		}
		OR = {
			is_female = no
			religion_allows_female_temple_holders = yes
		}
		liege = {
			war = no
			OR = {
				is_tribal = yes
				any_demesne_province = {
					has_province_modifier = new_buildings_timer
				}
			}
			religion = ROOT
			culture = ROOT
			any_demesne_province = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				OR = {
					has_province_modifier = new_buildings_timer
					owner = { is_tribal = yes }
				}
				NOR = {
					has_province_modifier = building_new_temple
					any_province_holding = { holding_type = temple }
				}
			}
			NOR = {
				has_character_modifier = temple_build_timer
				any_courtier = {
					is_ruler = no
					has_character_modifier = planning_new_temple
				}
			}
		}
		NOR = {
			trait = cynical
			trait = content
			trait = stressed
			trait = depressed
			trait = imbecile
			any_heir_title = { always = yes }
			has_character_modifier = planning_new_temple
			has_character_modifier = planning_claimant_adventure
			has_character_modifier = planning_duchy_adventure
			has_character_flag = claimant_adventurer
			has_character_flag = new_temple_builder
		}
	}
	
	mean_time_to_happen = {
		years = 40
		modifier = {
			factor = 0.25
			liege = {
				is_feudal = yes
				any_demesne_province = {
					religion = ROOT
					culture = ROOT
					num_of_empty_holdings = 1
					has_province_modifier = new_buildings_timer
					NOR = {
						has_province_modifier = building_new_temple
						any_province_holding = { holding_type = temple }
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			NOT = { year = 800 }
		}
		modifier = {
			factor = 0.75
			year = 900
		}
		modifier = {
			factor = 0.75
			year = 950
		}
		modifier = {
			factor = 0.75
			year = 1000
		}
		modifier = {
			factor = 0.75
			year = 1050
		}
		modifier = {
			factor = 0.75
			year = 1100
		}
		modifier = {
			factor = 0.75
			is_reformed_pagan_religion = yes
		}
		modifier = {
			factor = 0.75
			liege = { tier = DUKE }
		}
		modifier = {
			factor = 0.5
			liege = { higher_tier_than = DUKE }
		}
		modifier = {
			factor = 0.5
			liege = { has_character_flag = build_temple_tried_once }
		}
		modifier = {
			factor = 1.5
			liege = { trait = cynical }
		}
		modifier = {
			factor = 0.9
			has_character_modifier = estates_1
		}
		modifier = {
			factor = 0.9
			has_character_modifier = estates_2
		}
		modifier = {
			factor = 0.9
			has_character_modifier = estates_3
		}
		modifier = {
			factor = 0.9
			has_character_modifier = estates_4
		}
		modifier = {
			factor = 0.9
			has_character_modifier = estates_5
		}
		modifier = {
			factor = 0.5
			trait = zealous
		}
		modifier = {
			factor = 0.5
			trait = ambitious
		}
		modifier = {
			factor = 0.75
			trait = scholarly_theologian
		}
		modifier = {
			factor = 0.5
			trait = mastermind_theologian
		}
		modifier = {
			factor = 0.8
			trait = diligent
		}
		modifier = {
			factor = 0.8
			trait = proud
		}
		modifier = {
			factor = 1.5
			NOR = {
				trait = detached_priest
				trait = martial_cleric
				trait = scholarly_theologian
				trait = mastermind_theologian
			}
		}
		modifier = {
			factor = 1.2
			NOT = { learning = 8 }
		}
		modifier = {
			factor = 1.2
			trait = slothful
		}
		modifier = {
			factor = 1.2
			trait = humble
		}
		modifier = {
			factor = 1.5
			NOT = { diplomacy = 7 }
		}
		modifier = {
			factor = 0.8
			diplomacy = 12
		}
		modifier = {
			factor = 0.8
			learning = 12
		}
	}
	
	immediate = {
		set_character_flag = new_temple_builder
		add_character_modifier = {
			name = planning_new_temple
			duration = -1
		}
		if = {
			limit = { has_character_modifier = estates_1 }
			remove_character_modifier = estates_1
			wealth = 40
		}
		if = {
			limit = { has_character_modifier = estates_2 }
			remove_character_modifier = estates_2
			wealth = 80
		}
		if = {
			limit = { has_character_modifier = estates_3 }
			remove_character_modifier = estates_3
			wealth = 120
		}
		if = {
			limit = { has_character_modifier = estates_4 }
			remove_character_modifier = estates_4
			wealth = 160
		}
		if = {
			limit = { has_character_modifier = estates_5 }
			remove_character_modifier = estates_5
			wealth = 200
		}
		liege = {
			random_demesne_province = {
				limit = {
					is_capital = yes
					religion = ROOT
					culture = ROOT
					num_of_empty_holdings = 1
					OR = {
						has_province_modifier = new_buildings_timer
						owner = { is_tribal = yes }
					}
					NOR = {
						has_province_modifier = building_new_temple
						any_province_holding = { holding_type = temple }
					}
				}
				province_event = { id = Plus.1401 }
				break = yes
			}
			random_demesne_province = {
				limit = {
					religion = ROOT
					culture = ROOT
					num_of_empty_holdings = 1
					OR = {
						has_province_modifier = new_buildings_timer
						owner = { is_tribal = yes }
					}
					NOR = {
						has_province_modifier = building_new_temple
						any_province_holding = { holding_type = temple }
					}
				}
				province_event = { id = Plus.1401 }
			}
		}
	}
}

# Ping event for province where the temple is being built
province_event = {
	id = Plus.1401
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		set_province_flag = building_new_temple_check
		add_province_modifier = {
			name = building_new_temple
			duration = -1
		}
		FROM = {
			liege = {
				clr_character_flag = build_temple_tried_once
				character_event = { id = Plus.1402 }
				if = {
					limit = { is_tribal = yes }
					add_character_modifier = {
						name = temple_build_timer
						hidden = yes
						inherit = yes
						duration = 7300
					}
				}
			}
		}
	}
}

# Liege approached and asked for money to build the temple
character_event = {
	id = Plus.1402
	desc = EVTDESC_Plus_1402
	picture = GFX_evt_temple
	
	is_triggered_only = yes
	show_from_from = yes
	
	option = {
		name = EVTOPTA_Plus_1402 # Help him with cash
		trigger = {
			OR = {
				wealth = 50
				is_feudal = yes
			}
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.1
				has_character_modifier = ai_austerity
				is_tribal = yes
			}
			modifier = {
				factor = 0.25
				NOT = { wealth = 50 }
			}
			modifier = {
				factor = 2
				trait = ambitious
			}
			modifier = {
				factor = 2
				trait = charitable
			}
			modifier = {
				factor = 3
				trait = zealous
			}
		}
		if = {
			limit = {
				wealth = 50
				NOT = { wealth = 100 }
			}
			wealth = -50
			FROMFROM = { wealth = 50 }
		}
		if = {
			limit  = {
				wealth = 100
			}
			wealth = -100
			FROMFROM = { wealth = 100 }
		}
		piety = 25
		reverse_opinion = { who = FROMFROM modifier = opinion_helped_temple years = 50 }
	}
	option = {
		name = EVTOPTB_Plus_1402 # Help him with piety
		trigger = {
			piety = 100
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				trait = ambitious
			}
			modifier = {
				factor = 2
				trait = charitable
			}
			modifier = {
				factor = 3
				trait = zealous
			}
		}
		piety = -100
		FROMFROM = { wealth = 50 }
		reverse_opinion = { who = FROMFROM modifier = opinion_helped_temple years = 50 }
	}
	option = {
		name = EVTOPTC_Plus_1402 # Help him with prestige
		trigger = {
			prestige = 250
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				trait = ambitious
			}
			modifier = {
				factor = 2
				trait = charitable
			}
			modifier = {
				factor = 3
				trait = zealous
			}
		}
		prestige = -250
		FROMFROM = { wealth = 50 }
		reverse_opinion = { who = FROMFROM modifier = opinion_helped_temple years = 50 }
	}
	option = {
		name = EVTOPTD_Plus_1402 # Don't help him
		trigger = {
			OR = {
				wealth = 50
				is_feudal = yes
				piety = 100
				prestige = 250
			}
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 3
				trait = cynical
			}
			modifier = {
				factor = 2
				trait = greedy
			}
			modifier = {
				factor = 2
				trait = slothful
			}
			modifier = {
				factor = 2
				trait = content
			}
			modifier = {
				factor = 0.1
				is_feudal = yes
			}
		}
		piety = -50
		reverse_opinion = { who = FROMFROM modifier = opinion_refused_temple years = 50 }
		if = {
			limit = {
				FROMFROM = { wealth = 50 }
			}
			custom_tooltip = {
				text = TEMPLE_CONSTRUCTION_CONTINUES
			}
		}
		if = {
			limit = {
				FROMFROM = { NOT = { wealth = 50 } }
			}
			custom_tooltip = {
				text = TEMPLE_CONSTRUCTION_HALTS
				hidden_tooltip = {
					FROMFROM = {
						add_trait = depressed
						clr_character_flag = new_temple_builder
						remove_character_modifier = planning_new_temple
					}
					FROM = {
						clr_province_flag = building_new_temple_check
						remove_province_modifier = building_new_temple
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTE_Plus_1402 # I can't afford it
		trigger = {
			NOR = {
				wealth = 50
				is_feudal = yes
				piety = 100
				prestige = 250
			}
		}
		prestige = -25
		if = {
			limit = {
				FROMFROM = { wealth = 50 }
			}
			custom_tooltip = {
				text = TEMPLE_CONSTRUCTION_CONTINUES
			}
		}
		if = {
			limit = {
				FROMFROM = { NOT = { wealth = 50 } }
			}
			custom_tooltip = {
				text = TEMPLE_CONSTRUCTION_HALTS
				hidden_tooltip = {
					FROMFROM = {
						clr_character_flag = new_temple_builder
						remove_character_modifier = planning_new_temple
					}
					FROM = {
						clr_province_flag = building_new_temple_check
						remove_province_modifier = building_new_temple
					}
				}
			}
		}
	}
}

### TEMPLE BUILDING STOPS

# Character building the temple dies during construction
character_event = {
	id = Plus.1405
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_ruler = no
		has_character_modifier = planning_new_temple
	}
	
	immediate = {
		remove_character_modifier = planning_new_temple
		if = {
			limit = {
				liege = {
					any_demesne_province = { has_province_modifier = building_new_temple }
					NOT = {
						any_courtier = {
							is_ruler = no
							has_character_modifier = planning_new_temple
						}
					}
				}
			}
			liege = { character_event = { id = Plus.1406 days = 1 } }
		}
	}
}

# Liege notified that temple construction has stopped due to builder's death
character_event = {
	id = Plus.1406
	desc = EVTDESC_Plus_1406
	picture = GFX_evt_death
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1414 # Find someone else to continue construction
		trigger = {
			any_demesne_province = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				OR = {
					has_province_modifier = new_buildings_timer
					ROOT = { is_tribal = yes }
				}
				NOT = { any_province_holding = { holding_type = temple } }
			}
			NOT = {
				any_courtier = {
					is_ruler = no
					has_character_modifier = planning_new_temple
				}
			}
			any_courtier = {
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
		}
		ai_chance = {
			factor = 70
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = greedy
			}
			modifier = {
				factor = 0.5
				NOT = { wealth = 25 }
			}
			modifier = {
				factor = 0.75
				trait = slothful
			}
		}
		wealth = -25
		random_courtier = {
			limit = {
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
			set_character_flag = new_temple_builder
			add_character_modifier = {
				name = planning_new_temple
				duration = -1
			}
			hidden_tooltip = {
				opinion = { who = ROOT modifier = opinion_helped_temple years = 50 }
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
					wealth = 40
				}
				if = {
					limit = { has_character_modifier = estates_2 }
					remove_character_modifier = estates_2
					wealth = 80
				}
				if = {
					limit = { has_character_modifier = estates_3 }
					remove_character_modifier = estates_3
					wealth = 120
				}
				if = {
					limit = { has_character_modifier = estates_4 }
					remove_character_modifier = estates_4
					wealth = 160
				}
				if = {
					limit = { has_character_modifier = estates_5 }
					remove_character_modifier = estates_5
					wealth = 200
				}
			}
		}
	}	
	option = {
		name = EVTOPTB_Plus_1414 # There is nothing to be done
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				wealth = 100
			}
			modifier = {
				factor = 0.5
				trait = ambitious
			}
			modifier = {
				factor = 3
				has_character_modifier = ai_austerity
			}
		}
		set_character_flag = build_temple_tried_once
		hidden_tooltip = { remove_character_modifier = temple_build_timer }
		random_demesne_province = {
			limit = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				OR = {
					has_province_modifier = new_buildings_timer
					ROOT = { is_tribal = yes }
				}
				NOT = { any_province_holding = { holding_type = temple } }
			}
			clr_province_flag = building_new_temple_check
			remove_province_modifier = building_new_temple
		}
	}
}

# Character building the temple is no longer valid to do so
character_event = {
	id = Plus.1407
	
	hide_window = yes
	
	min_age = 16
	has_character_flag = new_temple_builder
	
	trigger = {
		has_character_modifier = planning_new_temple
		OR = {
			is_ruler = yes
			AND = {
				prisoner = yes
				imprisoned_days = 30
			}
			trait = incapable
		}
	}
	
	mean_time_to_happen = {
		days = 3
	}
	
	immediate = {
		clr_character_flag = new_temple_builder
		remove_character_modifier = planning_new_temple
		if = {
			limit = {
				liege = {
					any_demesne_province = { has_province_modifier = building_new_temple }
					NOT = {
						any_courtier = {
							is_ruler = no
							has_character_modifier = planning_new_temple
						}
					}
				}
			}
			piety = -50
			prestige = -50
			liege = { letter_event = { id = Plus.1408 } }
		}
	}
}

# Liege notified that temple building stopped because builder became a ruler
letter_event = {
	id = Plus.1408
	
	desc = {
		text = EVTDESC_Plus_1408_ruler
		trigger = {
			FROM = { is_ruler = yes }
		}
	}
	desc = {
		text = EVTDESC_Plus_1408_incapable
		trigger = {
			FROM = { trait = incapable }
		}
	}
	desc = {
		text = EVTDESC_Plus_1408_prison
		trigger = {
			FROM = {
				prisoner = yes
				imprisoned_days = 30
			}
		}
	}
	
	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1414 # Find someone else to continue construction
		trigger = {
			any_demesne_province = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				OR = {
					has_province_modifier = new_buildings_timer
					ROOT = { is_tribal = yes }
				}
				NOT = { any_province_holding = { holding_type = temple } }
			}
			NOT = {
				any_courtier = {
					is_ruler = no
					has_character_modifier = planning_new_temple
				}
			}
			any_courtier = {
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
		}
		ai_chance = {
			factor = 70
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = greedy
			}
			modifier = {
				factor = 0.5
				NOT = { wealth = 25 }
			}
			modifier = {
				factor = 0.75
				trait = slothful
			}
		}
		wealth = -25
		random_courtier = {
			limit = {
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
			set_character_flag = new_temple_builder
			add_character_modifier = {
				name = planning_new_temple
				duration = -1
			}
			hidden_tooltip = {
				opinion = { who = ROOT modifier = opinion_helped_temple years = 50 }
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
					wealth = 40
				}
				if = {
					limit = { has_character_modifier = estates_2 }
					remove_character_modifier = estates_2
					wealth = 80
				}
				if = {
					limit = { has_character_modifier = estates_3 }
					remove_character_modifier = estates_3
					wealth = 120
				}
				if = {
					limit = { has_character_modifier = estates_4 }
					remove_character_modifier = estates_4
					wealth = 160
				}
				if = {
					limit = { has_character_modifier = estates_5 }
					remove_character_modifier = estates_5
					wealth = 200
				}
			}
		}
	}	
	option = {
		name = EVTOPTB_Plus_1414 # There is nothing to be done
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				wealth = 100
			}
			modifier = {
				factor = 0.5
				trait = ambitious
			}
			modifier = {
				factor = 3
				has_character_modifier = ai_austerity
			}
		}
		set_character_flag = build_temple_tried_once
		hidden_tooltip = { remove_character_modifier = temple_build_timer }
		random_demesne_province = {
			limit = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				OR = {
					has_province_modifier = new_buildings_timer
					ROOT = { is_tribal = yes }
				}
				NOT = { any_province_holding = { holding_type = temple } }
			}
			clr_province_flag = building_new_temple_check
			remove_province_modifier = building_new_temple
		}
	}
}

# Temple building stops because liege/site is no longer valid
character_event = {
	id = Plus.1411
	
	hide_window = yes
	
	min_age = 16
	capable_only = yes
	has_character_flag = new_temple_builder
	prisoner = no
	
	trigger = {
		has_character_modifier = planning_new_temple
		liege = {
			OR = {
				NOT = { religion = ROOT }
				NOT = { culture = ROOT }
				NOT = {
					any_demesne_province = {
						religion = ROOT
						culture = ROOT
						num_of_empty_holdings = 1
						has_province_modifier = building_new_temple
						NOT = { any_province_holding = { holding_type = temple } }
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 3
	}
	
	immediate = {
		clr_character_flag = new_temple_builder
		remove_character_modifier = planning_new_temple
		piety = -50
		prestige = -50
		if = {
			limit = {
				liege = {
					any_demesne_province = { has_province_modifier = building_new_temple }
					NOT = {
						any_courtier = {
							is_ruler = no
							has_character_modifier = planning_new_temple
						}
					}
				}
			}
			if = {
				limit = {
					liege = {
						NOT = {
							any_demesne_province = {
								religion = ROOT
								culture = ROOT
								num_of_empty_holdings = 1
								has_province_modifier = building_new_temple
								NOT = { any_province_holding = { holding_type = temple } }
							}
						}
					}
				}
				liege = { letter_event = { id = Plus.1413 } }
				break = yes
			}
			liege = { character_event = { id = Plus.1412 } }
		}
	}
}

# Liege notified that temple building stopped because builder is no longer compatible
character_event = {
	id = Plus.1412
	desc = EVTDESC_Plus_1412
	picture = GFX_evt_temple
	
	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1414 # Find someone else to continue construction
		trigger = {
			any_demesne_province = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				NOT = { any_province_holding = { holding_type = temple } }
			}
			NOT = {
				any_courtier = {
					is_ruler = no
					has_character_modifier = planning_new_temple
				}
			}
			any_courtier = {
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
		}
		ai_chance = {
			factor = 70
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = greedy
			}
			modifier = {
				factor = 0.5
				NOT = { wealth = 25 }
			}
			modifier = {
				factor = 0.75
				trait = slothful
			}
		}
		wealth = -25
		random_courtier = {
			limit = {
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
			set_character_flag = new_temple_builder
			add_character_modifier = {
				name = planning_new_temple
				duration = -1
			}
			hidden_tooltip = {
				opinion = { who = ROOT modifier = opinion_helped_temple years = 50 }
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
					wealth = 40
				}
				if = {
					limit = { has_character_modifier = estates_2 }
					remove_character_modifier = estates_2
					wealth = 80
				}
				if = {
					limit = { has_character_modifier = estates_3 }
					remove_character_modifier = estates_3
					wealth = 120
				}
				if = {
					limit = { has_character_modifier = estates_4 }
					remove_character_modifier = estates_4
					wealth = 160
				}
				if = {
					limit = { has_character_modifier = estates_5 }
					remove_character_modifier = estates_5
					wealth = 200
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1414 # There is nothing to be done
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				wealth = 100
			}
			modifier = {
				factor = 0.5
				trait = ambitious
			}
			modifier = {
				factor = 3
				has_character_modifier = ai_austerity
			}
		}
		set_character_flag = build_temple_tried_once
		hidden_tooltip = { remove_character_modifier = temple_build_timer }
		random_demesne_province = {
			limit = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				NOT = { any_province_holding = { holding_type = temple } }
			}
			clr_province_flag = building_new_temple_check
			remove_province_modifier = building_new_temple
		}
	}
}

# Liege notified that temple building stopped because site is unsuitable
letter_event = {
	id = Plus.1413
	desc = EVTDESC_Plus_1413
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1413 # What about another site?
		trigger = {
			wealth = 25
			religion = FROM
			culture = FROM
			any_demesne_province = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				OR = {
					has_province_modifier = new_buildings_timer
					ROOT = { is_tribal = yes }
				}
				NOT = { any_province_holding = { holding_type = temple } }
			}
		}
		ai_chance = {
			factor = 70
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = greedy
			}
			modifier = {
				factor = 0.5
				NOT = { wealth = 25 }
			}
			modifier = {
				factor = 0.75
				trait = slothful
			}
		}
		wealth = -25
		random_demesne_province = {
			limit = {
				has_province_modifier = building_new_temple
				OR = {
					NOT = { religion = ROOT }
					NOT = { culture = ROOT }
					NOT = { num_of_empty_holdings = 1 }
					any_province_holding = { holding_type = temple }
				}
			}
			clr_province_flag = building_new_temple_check
			remove_province_modifier = building_new_temple
		}
		random_demesne_province = {
			limit = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				OR = {
					has_province_modifier = new_buildings_timer
					ROOT = { is_tribal = yes }
				}
				NOT = { has_province_modifier = building_new_temple }
				NOT = { any_province_holding = { holding_type = temple } }
			}
			set_province_flag = building_new_temple_check
			add_province_modifier = {
				name = building_new_temple
				duration = -1
			}
		}
		hidden_tooltip = {
			FROM = {
				wealth = 25
				opinion = { who = ROOT modifier = opinion_helped_temple years = 50 }
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1414 # There is nothing to be done
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				wealth = 100
			}
			modifier = {
				factor = 0.5
				trait = ambitious
			}
			modifier = {
				factor = 3
				has_character_modifier = ai_austerity
			}
		}
		set_character_flag = build_temple_tried_once
		hidden_tooltip = { remove_character_modifier = temple_build_timer }
		random_demesne_province = {
			limit = {
				has_province_modifier = building_new_temple
				OR = {
					NOT = { religion = ROOT }
					NOT = { culture = ROOT }
					NOT = { num_of_empty_holdings = 1 }
					any_province_holding = { holding_type = temple }
				}
			}
			clr_province_flag = building_new_temple_check
			remove_province_modifier = building_new_temple
		}
	}
}

# Temple building stops because there is no one to build it
province_event = {
	id = Plus.1414
	desc = EVTDESC_Plus_1414
	picture = GFX_evt_temple
	
	trigger = {
		has_province_modifier = building_new_temple
		owner = {
			NOT = {
				any_courtier = {
					is_ruler = no
					has_character_modifier = planning_new_temple
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 10
	}
	
	option = {
		name = EVTOPTA_Plus_1414 # Find someone else to continue construction
		trigger = {
			num_of_empty_holdings = 1
			NOT = { any_province_holding = { holding_type = temple } }
			owner = {
				religion = ROOT
				culture = ROOT
				any_courtier = {
					is_adult = yes
					prisoner = no
					religion = ROOT
					culture = ROOT
					is_ruler = no
					health = 4
					OR = {
						trait = detached_priest
						trait = martial_cleric
						trait = scholarly_theologian
						trait = mastermind_theologian
						AND = {
							learning = 8
							trait = zealous
						}
					}
					OR = {
						is_female = no
						religion_allows_female_temple_holders = yes
					}
					OR = {
						NOT = { dynasty = 0 }
						trait = ambitious
						trait = zealous
					}
					NOR = {
						trait = incapable
						trait = cynical
						trait = content
						trait = stressed
						trait = depressed
						trait = imbecile
						any_heir_title = { always = yes }
						has_character_modifier = planning_new_temple
						has_character_modifier = planning_claimant_adventure
						has_character_modifier = planning_duchy_adventure
						has_character_flag = claimant_adventurer
					}
				}
			}
		}
		ai_chance = {
			factor = 70
			modifier = {
				factor = 0.5
				owner = { trait = cynical }
			}
			modifier = {
				factor = 0.5
				owner = { trait = greedy }
			}
			modifier = {
				factor = 0.5
				owner = { NOT = { wealth = 25 } }
			}
			modifier = {
				factor = 0.75
				owner = { trait = slothful }
			}
		}
		owner = {
			piety = 25
			wealth = -25
			random_courtier = {
				limit = {
					is_adult = yes
					prisoner = no
					religion = ROOT
					culture = ROOT
					is_ruler = no
					health = 4
					OR = {
						trait = detached_priest
						trait = martial_cleric
						trait = scholarly_theologian
						trait = mastermind_theologian
						AND = {
							learning = 8
							trait = zealous
						}
					}
					OR = {
						is_female = no
						religion_allows_female_temple_holders = yes
					}
					OR = {
						NOT = { dynasty = 0 }
						trait = ambitious
						trait = zealous
					}
					NOR = {
						trait = incapable
						trait = cynical
						trait = content
						trait = stressed
						trait = depressed
						trait = imbecile
						any_heir_title = { always = yes }
						has_character_modifier = planning_new_temple
						has_character_modifier = planning_claimant_adventure
						has_character_modifier = planning_duchy_adventure
						has_character_flag = claimant_adventurer
					}
				}
				custom_tooltip = {
					text = WILL_CONTINUE_BUILDING_TEMPLE
					hidden_tooltip = {
						wealth = 25
						set_character_flag = new_temple_builder
						add_character_modifier = {
							name = planning_new_temple
							duration = -1
						}
						opinion = { who = ROOT modifier = opinion_helped_temple years = 50 }
						if = {
							limit = { has_character_modifier = estates_1 }
							remove_character_modifier = estates_1
							wealth = 40
						}
						if = {
							limit = { has_character_modifier = estates_2 }
							remove_character_modifier = estates_2
							wealth = 80
						}
						if = {
							limit = { has_character_modifier = estates_3 }
							remove_character_modifier = estates_3
							wealth = 120
						}
						if = {
							limit = { has_character_modifier = estates_4 }
							remove_character_modifier = estates_4
							wealth = 160
						}
						if = {
							limit = { has_character_modifier = estates_5 }
							remove_character_modifier = estates_5
							wealth = 200
						}
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1414 # There is nothing to be done
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				owner = { wealth = 100 }
			}
			modifier = {
				factor = 0.5
				owner = { trait = ambitious }
			}
			modifier = {
				factor = 3
				owner = { has_character_modifier = ai_austerity }
			}
		}
		clr_province_flag = building_new_temple_check
		remove_province_modifier = building_new_temple
		owner = { set_character_flag = build_temple_tried_once }
	}
}

# Temple encounters a problem during construction
character_event = {
	id = Plus.1420
	
	hide_window = yes
	
	min_age = 16
	capable_only = yes
	has_character_flag = new_temple_builder
	prisoner = no
	
	trigger = {
		has_character_modifier = planning_new_temple
		is_ruler = no
		liege = {
			religion = ROOT
			culture = ROOT
			any_demesne_province = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				had_province_flag = { flag = building_new_temple_check days = 365 }
				NOT = { any_province_holding = { holding_type = temple } }
			}
		}
		NOR = {
			trait = genius
			learning = 16
		}
		OR = {
			NOT = { has_character_flag = building_temple_delayed }
			had_character_flag = { flag = building_temple_delayed days = 365 }
		}
	}
	
	mean_time_to_happen = {
		years = 20
		modifier = {
			factor = 0.5
			liege = {
				any_realm_title = {
					location = { has_province_modifier = building_new_temple }
					is_occupied = yes
				}
			}
		}
		modifier = {
			factor = 0.5
			OR = {
				trait = lunatic
				trait = possessed
			}
		}
		modifier = {
			factor = 1.5
			OR = {
				trait = quick
				trait = shrewd
			}
		}
		modifier = {
			factor = 1.5
			trait = scholar
		}
		modifier = {
			factor = 0.8
			trait = gluttonous
		}
		modifier = {
			factor = 0.8
			trait = slothful
		}
		modifier = {
			factor = 0.8
			trait = wroth
		}
		modifier = {
			factor = 0.8
			trait = stressed
		}
		modifier = {
			factor = 0.8
			trait = depressed
		}
		modifier = {
			factor = 0.8
			trait = drunkard
		}
		modifier = {
			factor = 1.2
			trait = temperate
		}
		modifier = {
			factor = 1.2
			trait = diligent
		}
		modifier = {
			factor = 1.2
			trait = patient
		}
		modifier = {
			factor = 0.9
			NOT = { diplomacy = 7 }
		}
		modifier = {
			factor = 0.9
			NOT = { diplomacy = 5 }
		}
		modifier = {
			factor = 0.8
			NOT = { diplomacy = 3 }
		}
		modifier = {
			factor = 1.1
			diplomacy = 12
		}
		modifier = {
			factor = 1.1
			diplomacy = 14
		}
		modifier = {
			factor = 1.2
			diplomacy = 16
		}
		modifier = {
			factor = 0.9
			NOT = { learning = 8 }
		}
		modifier = {
			factor = 0.9
			NOT = { learning = 6 }
		}
		modifier = {
			factor = 0.8
			NOT = { learning = 4 }
		}
		modifier = {
			factor = 1.1
			learning = 10
		}
		modifier = {
			factor = 1.1
			learning = 12
		}
		modifier = {
			factor = 1.2
			learning = 14
		}
	}
	
	option = {
		#Pay for it myself
		trigger = {
			wealth = 50
		}
		set_character_flag = building_temple_delayed
		wealth = -50
	}
	
	option = {
		#Ask my liege for help
		trigger = {
			NOT = { wealth = 50 }
		}
		set_character_flag = building_temple_delayed
		liege = { letter_event = { id = Plus.1421 } }
	}
}

# Liege asked for money to continue construction
letter_event = {
	id = Plus.1421
	desc = EVTDESC_Plus_1421
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1421 #Help him out
		trigger = { wealth = 50 }
		ai_chance = {
			factor = 70
			modifier = {
				factor = 0.1
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = greedy
			}
			modifier = {
				factor = 0.75
				trait = slothful
			}
		}
		piety = 25
		wealth = -50
		reverse_opinion = { who = FROM modifier = opinion_helped_temple years = 50 }
	}
	option = {
		name = EVTOPTB_Plus_1421 #Refuse
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				wealth = 200
			}
			modifier = {
				factor = 0.5
				trait = ambitious
			}
			modifier = {
				factor = 5
				has_character_modifier = ai_austerity
			}
		}
		set_character_flag = build_temple_tried_once
		if = {
			limit = { wealth = 50 }
			piety = -25
		}
		prestige = -25
		reverse_opinion = { who = FROM modifier = opinion_refused_temple years = 50 }
		random_demesne_province = {
			limit = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				had_province_flag = { flag = building_new_temple_check days = 365 }
				NOT = { any_province_holding = { holding_type = temple } }
			}
			clr_province_flag = building_new_temple_check
			remove_province_modifier = building_new_temple
		}
		hidden_tooltip = {
			remove_character_modifier = temple_build_timer
			FROM = {
				remove_character_modifier = planning_new_temple
				clr_character_flag = new_temple_builder
			}
		}
	}
}

# Feudal liege asks for character to build temple
character_event = {
	id = Plus.1422
	desc = EVTDESC_Plus_1422
	picture = GFX_evt_temple
	
	is_triggered_only = yes
	
	immediate = {
		#first choice
		random_courtier = {
			limit = {
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
			save_event_target_as = first_temple_choice
		}
		#second choice
		random_courtier = {
			limit = {
				event_target:first_temple_choice = {
					NOT = { character = PREV }
				}
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
			save_event_target_as = second_temple_choice
		}
		#third choice
		random_courtier = {
			limit = {
				event_target:first_temple_choice = {
					NOT = { character = PREV }
				}
				event_target:second_temple_choice = {
					NOT = { character = PREV }
				}
				is_adult = yes
				prisoner = no
				religion = ROOT
				culture = ROOT
				is_ruler = no
				health = 4
				OR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						learning = 8
						trait = zealous
					}
				}
				OR = {
					is_female = no
					religion_allows_female_temple_holders = yes
				}
				OR = {
					NOT = { dynasty = 0 }
					trait = ambitious
					trait = zealous
				}
				NOR = {
					trait = incapable
					trait = cynical
					trait = content
					trait = stressed
					trait = depressed
					trait = imbecile
					any_heir_title = { always = yes }
					has_character_modifier = planning_new_temple
					has_character_modifier = planning_claimant_adventure
					has_character_modifier = planning_duchy_adventure
					has_character_flag = claimant_adventurer
				}
			}
			save_event_target_as = third_temple_choice
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1422 #First choice
		trigger = { event_target:first_temple_choice = { is_alive = yes } }
		event_target:first_temple_choice = {
			wealth = 100
			set_character_flag = new_temple_builder
			add_character_modifier = {
				name = planning_new_temple
				duration = -1
			}
			if = {
				limit = { has_character_modifier = estates_1 }
				remove_character_modifier = estates_1
				wealth = 40
			}
			if = {
				limit = { has_character_modifier = estates_2 }
				remove_character_modifier = estates_2
				wealth = 80
			}
			if = {
				limit = { has_character_modifier = estates_3 }
				remove_character_modifier = estates_3
				wealth = 120
			}
			if = {
				limit = { has_character_modifier = estates_4 }
				remove_character_modifier = estates_4
				wealth = 160
			}
			if = {
				limit = { has_character_modifier = estates_5 }
				remove_character_modifier = estates_5
				wealth = 200
			}
		}	
	}
	option = {
		name = EVTOPTB_Plus_1422 #Second choice
		trigger = { event_target:second_temple_choice = { is_alive = yes } }
		event_target:second_temple_choice = {
			wealth = 100
			set_character_flag = new_temple_builder
			add_character_modifier = {
				name = planning_new_temple
				duration = -1
			}
			if = {
				limit = { has_character_modifier = estates_1 }
				remove_character_modifier = estates_1
				wealth = 40
			}
			if = {
				limit = { has_character_modifier = estates_2 }
				remove_character_modifier = estates_2
				wealth = 80
			}
			if = {
				limit = { has_character_modifier = estates_3 }
				remove_character_modifier = estates_3
				wealth = 120
			}
			if = {
				limit = { has_character_modifier = estates_4 }
				remove_character_modifier = estates_4
				wealth = 160
			}
			if = {
				limit = { has_character_modifier = estates_5 }
				remove_character_modifier = estates_5
				wealth = 200
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_1422 #Third choice
		trigger = { event_target:third_temple_choice = { is_alive = yes } }
		event_target:third_temple_choice = {
			wealth = 100
			set_character_flag = new_temple_builder
			add_character_modifier = {
				name = planning_new_temple
				duration = -1
			}
			if = {
				limit = { has_character_modifier = estates_1 }
				remove_character_modifier = estates_1
				wealth = 40
			}
			if = {
				limit = { has_character_modifier = estates_2 }
				remove_character_modifier = estates_2
				wealth = 80
			}
			if = {
				limit = { has_character_modifier = estates_3 }
				remove_character_modifier = estates_3
				wealth = 120
			}
			if = {
				limit = { has_character_modifier = estates_4 }
				remove_character_modifier = estates_4
				wealth = 160
			}
			if = {
				limit = { has_character_modifier = estates_5 }
				remove_character_modifier = estates_5
				wealth = 200
			}
		}
	}
	option = {
		name = EVTOPTD_Plus_1422 #Maybe not
		trigger = { ai = no }
		wealth = 100
		piety = -25
		FROM = {
			location = {
				clr_province_flag = building_new_temple_check
				remove_province_modifier = building_new_temple
			}
		}
	}
}


### TEMPLE CONSTRUCTION COMPLETE

character_event = {
	id = Plus.1425
	
	hide_window = yes
	
	min_age = 16
	capable_only = yes
	has_character_flag = new_temple_builder
	prisoner = no
	
	trigger = {
		has_character_modifier = planning_new_temple
		is_ruler = no
		liege = {
			war = no
			religion = ROOT
			culture = ROOT
			any_demesne_province = {
				religion = ROOT
				culture = ROOT
				num_of_empty_holdings = 1
				has_province_modifier = building_new_temple
				NOT = { any_province_holding = { holding_type = temple } }
				OR = {
					AND = {
						ROOT = { NOT = { wealth = 50 } }
						had_province_flag = { flag = building_new_temple_check days = 3650 }
					}
					AND = {
						ROOT = {
							wealth = 50
							NOT = { wealth = 100 }
						}
						had_province_flag = { flag = building_new_temple_check days = 2750 }
					}
					AND = {
						ROOT = { wealth = 100 }
						had_province_flag = { flag = building_new_temple_check days = 1825 }
					}
					AND = {
						owner = { is_feudal = yes }
						had_province_flag = { flag = building_new_temple_check days = 1095 }
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 60
		modifier = {
			factor = 0.6
			is_feudal = yes
		}
	}
	
	immediate = {
		clr_character_flag = building_temple_delayed
		clr_character_flag = new_temple_builder
		remove_character_modifier = planning_new_temple
		liege = {
			random_demesne_province = {
				limit = {
					religion = PREV
					culture = PREV
					num_of_empty_holdings = 1
					has_province_modifier = building_new_temple
					NOT = { any_province_holding = { holding_type = temple } }
				}
				remove_province_modifier = building_new_temple
				clr_province_flag = building_new_temple_check
				build_holding = {
					type = temple
					holder = ROOT
				}
				ROOT = {
					set_defacto_liege = PREVPREV
					pf_liege_change_effect = yes
					piety = 50
				}
			}
			clr_character_flag = build_temple_tried_once
			character_event = { id = Plus.1426 days = 1 }
		}
	}
}

# Liege notified that the temple has been built
character_event = {
	id = Plus.1426
	desc = EVTDESC_Plus_1426
	picture = GFX_evt_temple
	
	is_triggered_only = yes
	
	option = {
		name = EXCELLENT
		prestige = 50
	}
}

#######################################
# CITY BUILDER EVENTS
#######################################

### CITY BUILDING BEGINS

# Steward finds a location for the city
character_event = {
	id = 940
	title = EVTNAME_Plus_1430
	desc = EVTDESC_Plus_1430
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_economy
	
	capable_only = yes
	prisoner = no
	
	trigger = {
		liege = { is_tribal = yes }
		has_job_action = action_settle_tribe
		location = {
			num_of_empty_holdings = 1
			NOT = { has_province_modifier = building_new_city }
			NOT = { any_province_holding = { holding_type = city } }
			county = { is_occupied = no }
			owner = {
				is_tribal = yes
				job_treasurer = { character = ROOT }
				culture = PREV
			}
		}
	}
	
	mean_time_to_happen = {
		months = 1000
		modifier = {
			factor = 1000
			liege = { is_tribal = no }
		}
		modifier = {
			factor = 1.5
			NOT = { year = 800 }
		}
		modifier = {
			factor = 0.75
			location = { is_capital = yes }
		}
		modifier = {
			factor = 1.1
			location = {
				NOR = {
					has_building = tb_shipyard_1
					has_building = tb_shipyard_2
					has_building = tb_shipyard_3
					has_building = tb_shipyard_4
				}
			}
		}
		modifier = {
			factor = 0.9
			location = { has_building = tb_shipyard_1 }
		}
		modifier = {
			factor = 0.8
			location = { has_building = tb_shipyard_2 }
		}
		modifier = {
			factor = 0.7
			location = { has_building = tb_shipyard_3 }
		}
		modifier = {
			factor = 0.6
			location = { has_building = tb_shipyard_4 }
		}
		modifier = {
			factor = 1.25
			location = {
				NOR = {
					has_building = tb_market_town_1
					has_building = tb_market_town_2
					has_building = tb_market_town_3
					has_building = tb_market_town_4
				}
			}
		}
		modifier = {
			factor = 0.8
			location = { has_building = tb_market_town_1 }
		}
		modifier = {
			factor = 0.65
			location = { has_building = tb_market_town_2 }
		}
		modifier = {
			factor = 0.5
			location = { has_building = tb_market_town_3 }
		}
		modifier = {
			factor = 0.4
			location = { has_building = tb_market_town_4 }
		}
		modifier = {
			factor = 1.25
			liege = {
				any_realm_title = {
					is_republic = yes
				}
			}
		}
		modifier = {
			factor = 1.25
			liege = {
				any_realm_title = {
					is_republic = yes
					count = 2
				}
			}
		}
		modifier = {
			factor = 1.25
			liege = {
				any_realm_title = {
					is_republic = yes
					count = 3
				}
			}
		}
		modifier = {
			factor = 1.25
			liege = { tier = COUNT }
		}
		modifier = {
			factor = 0.75
			liege = { higher_tier_than = DUKE }
		}
		modifier = {
			factor = 0.75
			liege = { higher_tier_than = KING }
		}
		modifier = {
			factor = 1.1
			NOT = { stewardship = 2 }
		}
		modifier = {
			factor = 1.1
			NOT = { stewardship = 3 }
		}
		modifier = {
			factor = 1.1
			NOT = { stewardship = 4 }
		}
		modifier = {
			factor = 1.1
			NOT = { stewardship = 5 }
		}
		modifier = {
			factor = 1.1
			NOT = { stewardship = 6 }
		}
		modifier = {
			factor = 1.1
			NOT = { stewardship = 7 }
		}
		modifier = {
			factor = 1.1
			NOT = { stewardship = 8 }
		}
		modifier = {
			factor = 0.9
			stewardship = 12
		}
		modifier = {
			factor = 0.9
			stewardship = 13
		}
		modifier = {
			factor = 0.9
			stewardship = 14
		}
		modifier = {
			factor = 0.9
			stewardship = 15
		}
		modifier = {
			factor = 0.9
			stewardship = 16
		}
		modifier = {
			factor = 0.9
			stewardship = 17
		}
		modifier = {
			factor = 0.9
			stewardship = 18
		}
		modifier = {
			factor = 0.9
			stewardship = 19
		}
		modifier = {
			factor = 0.9
			stewardship = 20
		}
		modifier = {
			factor = 0.9
			opinion = { who = liege value = 25 }
		}
		modifier = {
			factor = 0.9
			opinion = { who = liege value = 50 }
		}
		modifier = {
			factor = 0.9
			opinion = { who = liege value = 75 }
		}
		modifier = {
			factor = 1.1
			NOT = { opinion = { who = liege value = 0 } }
		}
		modifier = {
			factor = 1.1
			NOT = { opinion = { who = liege value = -25 } }
		}
		modifier = {
			factor = 1.1
			NOT = { opinion = { who = liege value = -50 } }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1430 # Tell my liege
		location = {
			save_event_target_as = new_city_location
		}
		liege = {
			character_event = { id = Plus.1431 tooltip = INFORM_LIEGE_BUILD_CITY }
		}
	}
}

# Liege decides whether to move forward with the city building
character_event = {
	id = Plus.1431
	desc = EVTDESC_Plus_1431
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_economy
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1431 #Build it with money
		trigger = { wealth = 0 }
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0.1
				NOT = { wealth = 25 }
			}
		}
		wealth = -75
		event_target:new_city_location = {
			set_province_flag = tribal_build_city
			add_province_modifier = {
				name = building_new_city
				duration = -1
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1431 #Build it with prestige
		trigger = { prestige = 0 }
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0.1
				NOT = { prestige = 100 }
			}
		}
		prestige = -250
		event_target:new_city_location = {
			set_province_flag = tribal_build_city
			add_province_modifier = {
				name = building_new_city
				duration = -1
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_1431 #Leave it for now
		ai_chance = {
			factor = 1
			modifier = {
				factor = 10
				NOT = { wealth = 25 }
				NOT = { prestige = 100 }
			}
			modifier = {
				factor = 0.5
				is_feudal = yes
			}
		}
	}
}

# Site is no longer valid
province_event = {
	id = Plus.1432
	
	hide_window = yes
	
	trigger = {
		has_province_modifier = building_new_city
		OR = {
			NOT = { num_of_empty_holdings = 1 }
			owner = { NOT = { culture = ROOT } }
			any_province_holding = { holding_type = city }
			owner = {
				is_tribal = no
				is_feudal = no
			}	
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		clr_province_flag = tribal_build_city
		clr_province_flag = tribal_build_city_problem
		clr_province_flag = tribal_build_city_merchants
		clr_province_flag = tribal_build_city_delayed
		remove_province_modifier = building_new_city
	}
}

# Site ruined due to occupation
province_event = {
	id = Plus.1433
	desc = EVTDESC_Plus_1433
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_economy
	
	trigger = {
		has_province_modifier = building_new_city
		county = { is_occupied = yes }
	}
	
	mean_time_to_happen = {
		months = 1
	}
	
	option = {
		name = CURSES
		clr_province_flag = tribal_build_city
		clr_province_flag = tribal_build_city_problem
		clr_province_flag = tribal_build_city_merchants
		clr_province_flag = tribal_build_city_delayed
		remove_province_modifier = building_new_city
	}
}

# Site encounters a problem
province_event = {
	id = Plus.1434
	desc = EVTDESC_Plus_1434
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_economy

	trigger = {
		has_province_modifier = building_new_city
		had_province_flag = { flag = tribal_build_city days = 365 }
		NOT = { has_province_flag = tribal_build_city_problem }
		county = { is_occupied = no }
	}
	
	mean_time_to_happen = {
		months = 100
		modifier = {
			factor = 0.5
			owner = {
				NOT = { any_courtier = { has_job_title = job_treasurer } }
			}
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 2 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 4 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 6 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 8 } }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 12 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 14 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 16 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 18 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 20 }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 2 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 4 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 6 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 8 } } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 12 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 14 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 16 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 18 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 20 } }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1434 # Give more cash
		trigger = {
			owner = { wealth = 0 }
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0.1
				owner = {
					NOT = { wealth = 75 }
				}
			}
		}
		set_province_flag = tribal_build_city_problem
		owner = { wealth = -75 }
	}
	option = {
		name = EVTOPTB_Plus_1434 # Get vassals to help
		trigger = {
			owner = { prestige = 0 }
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0.1
				owner = {
					NOT = { prestige = 250 }
				}
			}
		}
		set_province_flag = tribal_build_city_problem
		owner = { prestige = -250 }
	}
	option = {
		name = EVTOPTC_Plus_1434 # Abandon the city
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				owner = {
					OR = {
						wealth = 75
						prestige = 250
					}
				}
			}
		}
		owner = {
			prestige = -50
		}
		clr_province_flag = tribal_build_city
		clr_province_flag = tribal_build_city_merchants
		clr_province_flag = tribal_build_city_delayed
		remove_province_modifier = building_new_city
	}
}

# Site has dispute with workers
province_event = {
	id = Plus.1435
	desc = EVTDESC_Plus_1435
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_economy

	trigger = {
		has_province_modifier = building_new_city
		NOT = { has_province_modifier = peasant_unrest }
		had_province_flag = { flag = tribal_build_city days = 365 }
		county = { is_occupied = no }
	}
	
	mean_time_to_happen = {
		months = 75
		modifier = {
			factor = 0.5
			owner = {
				NOT = { any_courtier = { has_job_title = job_treasurer } }
			}
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 2 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 4 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 6 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 8 } }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 12 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 14 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 16 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 18 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 20 }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 2 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 4 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 6 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 8 } } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 12 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 14 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 16 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 18 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 20 } }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1435
		add_province_modifier = {
			name = peasant_unrest
			duration = 730
		}
	}
}

# Site has dispute with merchants
province_event = {
	id = Plus.1436
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_economy
	
	desc = {
		text = EVTDESC_Plus_1436_tribal
		trigger = {
			owner = { is_tribal = yes }
		}
	}
	desc = {
		text = EVTDESC_Plus_1436_feudal
		trigger = {
			owner = { is_tribal = no }
		}
	}

	trigger = {
		has_province_modifier = building_new_city
		NOT = { has_province_flag = tribal_build_city_merchants }
		had_province_flag = { flag = tribal_build_city days = 365 }
		county = { is_occupied = no }
	}

	mean_time_to_happen = {
		months = 75
		modifier = {
			factor = 0.75
			has_province_modifier = peasant_unrest
		}
		modifier = {
			factor = 0.5
			owner = {
				NOT = { any_courtier = { has_job_title = job_treasurer } }
			}
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 2 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 4 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 6 } }
		}
		modifier = {
			factor = 0.95
			owner = { NOT = { stewardship = 8 } }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 12 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 14 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 16 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 18 }
		}
		modifier = {
			factor = 1.05
			owner = { stewardship = 20 }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 2 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 4 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 6 } } }
		}
		modifier = {
			factor = 0.9
			owner = { any_courtier = { has_job_title = job_treasurer } }
			owner = { job_treasurer = { NOT = { stewardship = 8 } } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 12 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 14 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 16 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 18 } }
		}
		modifier = {
			factor = 1.1
			owner = { job_treasurer = { stewardship = 20 } }
		}
	}

	option = {
		name = EVTOPTA_Plus_1436 # I will negotiate with them
		trigger = {
			owner = { diplomacy = 12 }
		}
		ai_chance = {
			factor = 10
		}
		random_list = {
			50 = {
				modifier = {
					factor = 0.9
					owner = { diplomacy = 14 }
				}
				modifier = {
					factor = 0.9
					owner = { diplomacy = 16 }
				}
				modifier = {
					factor = 0.9
					owner = { diplomacy = 18 }
				}
				modifier = {
					factor = 0.9
					owner = { diplomacy = 20 }
				}
				modifier = {
					factor = 0.9
					owner = { diplomacy = 22 }
				}
				modifier = {
					factor = 0.9
					owner = { diplomacy = 24 }
				}
				custom_tooltip = { text = WORK_ON_CITY_DELAYED }
				set_province_flag = tribal_build_city_merchants
				set_province_flag = tribal_build_city_delayed
			}
			50 = {
				custom_tooltip = { text = WORK_ON_CITY_CONTINUES }
				set_province_flag = tribal_build_city_merchants
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1436 # Send the steward to negotiate with them
		trigger = {
			owner = {
				NOT = { diplomacy = 12 }
				any_courtier = { has_job_title = job_treasurer }
			}
		}
		ai_chance = {
			factor = 10
		}
		random_list = {
			50 = {
				modifier = {
					factor = 1.1
					owner = { job_treasurer = { NOT = { stewardship = 2 } } }
				}
				modifier = {
					factor = 1.1
					owner = { job_treasurer = { NOT = { stewardship = 4 } } }
				}
				modifier = {
					factor = 1.1
					owner = { job_treasurer = { NOT = { stewardship = 6 } } }
				}
				modifier = {
					factor = 1.1
					owner = { job_treasurer = { NOT = { stewardship = 8 } } }
				}
				modifier = {
					factor = 1.1
					owner = { job_treasurer = { NOT = { stewardship = 10 } } }
				}
				modifier = {
					factor = 0.9
					owner = { job_treasurer = { stewardship = 14 } }
				}
				modifier = {
					factor = 0.9
					owner = { job_treasurer = { stewardship = 16 } }
				}
				modifier = {
					factor = 0.9
					owner = { job_treasurer = { stewardship = 18 } }
				}
				modifier = {
					factor = 0.9
					owner = { job_treasurer = { stewardship = 20 } }
				}
				modifier = {
					factor = 0.9
					owner = { job_treasurer = { stewardship = 22 } }
				}
				modifier = {
					factor = 0.9
					owner = { job_treasurer = { stewardship = 24 } }
				}
				custom_tooltip = { text = WORK_ON_CITY_DELAYED }
				set_province_flag = tribal_build_city_merchants
				set_province_flag = tribal_build_city_delayed
			}
			50 = {
				custom_tooltip = { text = WORK_ON_CITY_CONTINUES }
				set_province_flag = tribal_build_city_merchants
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_1436 # Round them up and execute them
		trigger = {
			owner = {
				NOR = {
					trait = kind
					trait = just
				}
			}
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0
				owner = {
					NOR = {
						trait = cruel
						trait = impaler
						trait = greedy
					}
				}
			}
			modifier = {
				factor = 0
				owner = {
					OR = {
						trait = tyrant10
						trait = tyrant11
						trait = tyrant12
						trait = tyrant13
						trait = tyrant14
						trait = tyrant15
						trait = tyrant16
						trait = tyrant17
						trait = tyrant18
						trait = tyrant19
						trait = tyrant20
					}
				}
			}
		}
		owner = { prestige = 25 }
		if = {
			limit = { owner = { NOT = { trait = cruel } } }
			owner = {
				random = {
					chance = 30
					add_trait = cruel
				}
			}
		}
		owner = {
			tyrant_plus_1_effect = yes
		}
		custom_tooltip = { text = WORK_ON_CITY_CONTINUES }
		set_province_flag = tribal_build_city_merchants
	}
	option = {
		name = EVTOPTD_Plus_1436 # Pay them off
		trigger = {
			owner = { wealth = 50 }
		}
		ai_chance = {
			factor = 10
		}
		owner = {
			wealth = -50
		}
		custom_tooltip = { text = WORK_ON_CITY_CONTINUES }
		set_province_flag = tribal_build_city_merchants
	}
	option = {
		name = EVTOPTE_Plus_1436 # Abandon the city
		ai_chance = {
			factor = 1
		}
		owner = {
			prestige = -50
		}
		clr_province_flag = tribal_build_city
		clr_province_flag = tribal_build_city_problem
		remove_province_modifier = building_new_city
	}
}

### CITY CONSTRUCTION COMPLETE

# The city is finished construction
province_event = {
	id = Plus.1437
	desc = EVTDESC_Plus_1437
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_economy
	
	trigger = {
		has_province_modifier = building_new_city
		OR = {
			had_province_flag = { flag = tribal_build_city days = 2920 }
			AND = {
				owner = { is_feudal = yes }
				had_province_flag = { flag = tribal_build_city days = 1825 }
			}
		}
		num_of_empty_holdings = 1
		county = { is_occupied = no }
		NOT = { any_province_holding = { holding_type = city } }
		owner = {
			OR = {
				is_tribal = yes
				is_feudal = yes
			}
			culture = ROOT
		}
	}
	
	mean_time_to_happen = {
		months = 75
		modifier = {
			factor = 3
			has_province_flag = tribal_build_city_delayed
		}
		modifier = {
			factor = 0.75
			owner = { is_feudal = yes }
		}
		modifier = {
			factor = 0.5
			owner = {
				job_treasurer = {
					has_job_action = action_oversee_construction
					location = { province_id = ROOT }
				}
			}
		}
	}
	
	option = {
		name = EXCELLENT
		hidden_tooltip = {
			clr_province_flag = tribal_build_city
			clr_province_flag = tribal_build_city_problem
			clr_province_flag = tribal_build_city_merchants
			clr_province_flag = tribal_build_city_delayed
			remove_province_modifier = building_new_city
		}
		owner = {
			ROOT = {
				build_holding = {
					type = city
					holder = PREV
				}
			}
		}
	}
}

