decisions = {
	ai_austerity = {
		ai_check_interval = 3

		only_playable = yes

		potential = {
			ai = yes

			NOR = {
				has_character_modifier = ai_austerity
				has_character_modifier = ai_austerity_timer
			}
		}

		allow = {
			OR = {
				# Is an adventurer
				has_character_modifier = planning_claimant_adventure

				# Has a loan
				check_variable = {
					which = loan_amount
					value >= 49.5
				}

				# Needs to get crowned
				AND = {
					trait = uncrowned
					is_adult = yes
				}

				# Is excommunicated
				AND = {
					trigger_if = {
						limit = { has_character_flag = ask_for_repentance }

						had_character_flag = {
							flag = ask_for_repentance
							years >= 5
						}
					}

					rightful_religious_head_scope = {
						ROOT = { excommunicated_for = PREV }
					}
				}

				# Any part of the realm is occupied
				any_realm_title = {
					lower_real_tier_than = DUKE
					is_occupied = yes
				}

				# Losing a war
				any_war = {
					OR = {
						attacker = {
							character = ROOT
							war_score < -15
						}

						defender = {
							character = ROOT
							war_score >= 15
						}
					}
				}

				# King with enough titles to become emperor
				AND = {
					real_tier = KING
					num_of_king_titles >= 2
					realm_size >= 150
				}

				# Duke with enough titles to become king
				AND = {
					real_tier = DUKE
					num_of_duke_titles >= 2
				}

				# Has all the counties in a duchy and can create or usurp it
				any_realm_province = {
					held_under_PREV = yes

					duchy = {
						ROOT = { is_landed_title_allowed = PREV }

						trigger_if = {
							limit = { has_holder = yes }

							holder_scope = {
								NOR = {
									character = ROOT
									is_vassal_or_below_of = ROOT
									is_liege_or_above_of = ROOT
								}
							}
						}

						NOT = {
							any_direct_de_jure_vassal_title = {
								holder_scope = {
									NOR = {
										character = ROOT
										is_liege_or_above_of = ROOT
									}
								}
							}
						}
					}
				}
			}
		}

		effect = {
			add_character_modifier = {
				name = ai_austerity
				years = 10
				hidden = yes
			}

			add_character_modifier = {
				name = ai_austerity_timer
				years = 15
				hidden = yes
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	ai_austerity_baron = {
		ai_check_interval = 3

		only_rulers = yes

		potential = {
			real_tier = BARON
			is_republic = yes
			ai = yes
			is_patrician = no
			independent = no
			NOT = { is_child_of = liege }

			primary_title = {
				location = {
					is_coastal = yes
					TECH_TRADE_PRACTICES >= 1
				}
			}

			OR = {
				primary_title = {
					OR = {
						title = b_amalfi
						title = b_venezia
						title = b_genoa
						title = b_pisa
						title = b_ancona
						title = b_gaeta
						title = b_novgorod
						title = b_noli
						title = b_lubeck
					}
				}

				dejure_liege_title = {
					OR = {
						title = c_hamburg
						title = c_gotland
					}
				}

				primary_title = {
					location = {
						NOR = {
							duchy = { capital_scope = { province_id = PREVPREV } }
							kingdom = { capital_scope = { province_id = PREVPREV } }
						}
					}

					OR = {
						has_building = ct_port_3
						has_building = ct_port_4
						has_building = ct_port_5
					}
				}
			}

			NOR = {
				has_character_modifier = ai_austerity
				has_character_modifier = ai_austerity_timer
			}
		}

		allow = {
			trait = ambitious
			wealth >= 50
			prisoner = no
			is_adult = yes
			is_incapable = no
			is_dumb_trigger = no

			NOR = {
				trait = humble
				trait = craven
			}

			liege = {
				is_feudal = yes
				ai = yes

				ROOT = {
					primary_title = {
						dejure_liege_title = {
							current_heir = { NOT = { character = PREVPREVPREV } }
							holder_scope = { character = PREVPREVPREVPREV }
						}
					}
				}
			}
		}

		effect = {
			add_character_modifier = {
				name = ai_austerity
				years = 10
				hidden = yes
			}

			add_character_modifier = {
				name = ai_austerity_timer
				years = 15
				hidden = yes
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	ai_austerity_end = {
		ai_check_interval = 3

		only_playable = yes

		potential = {
			has_character_modifier = ai_austerity
			ai = yes
		}

		allow = {
			NOR = {
				# Is an adventurer
				has_character_modifier = planning_claimant_adventure

				# Has a loan
				check_variable = {
					which = loan_amount
					value >= 49.5
				}

				# Needs to get crowned
				AND = {
					trait = uncrowned
					is_adult = yes
				}

				# Is excommunicated
				AND = {
					trigger_if = {
						limit = { has_character_flag = ask_for_repentance }

						had_character_flag = {
							flag = ask_for_repentance
							years >= 5
						}
					}

					rightful_religious_head_scope = {
						ROOT = { excommunicated_for = PREV }
					}
				}

				# Any part of the realm is occupied
				any_realm_title = {
					lower_real_tier_than = DUKE
					is_occupied = yes
				}

				# Losing a war
				any_war = {
					OR = {
						attacker = {
							character = ROOT
							war_score < -15
						}

						defender = {
							character = ROOT
							war_score >= 15
						}
					}
				}

				# King with enough titles to become emperor
				AND = {
					real_tier = KING
					num_of_king_titles >= 2
					realm_size >= 150
				}

				# Duke with enough titles to become king
				AND = {
					real_tier = DUKE
					num_of_duke_titles >= 2
				}

				# Has all the counties in a duchy and can create or usurp it
				any_realm_province = {
					held_under_PREV = yes

					duchy = {
						ROOT = { is_landed_title_allowed = PREV }

						trigger_if = {
							limit = { has_holder = yes }

							holder_scope = {
								NOR = {
									character = ROOT
									is_vassal_or_below_of = ROOT
									is_liege_or_above_of = ROOT
								}
							}
						}

						NOT = {
							any_direct_de_jure_vassal_title = {
								holder_scope = {
									NOR = {
										character = ROOT
										is_liege_or_above_of = ROOT
									}
								}
							}
						}
					}
				}
			}
		}

		effect = {
			remove_character_modifier = ai_austerity
			remove_character_modifier = ai_austerity_timer
		}

		ai_will_do = {
			factor = 1
		}
	}
}