#refound_hist_cow_metropolis_decision
#found_generic_cow_metropolis_decision
#cow_convert_holding_to_metropolis_decision
#cow_ai_convert_holding_to_metropolis_decision

refound_hist_cow_metropolis_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_misc.dds"
	major = yes
	ai_check_interval = 120

	desc = refound_hist_cow_metropolis_decision_desc
	selection_tooltip = refound_hist_cow_metropolis_decision_tooltip

	is_shown = {
		any_sub_realm_barony = {
			OR = { # A place where Metropolises or great capitals historically existed early
				this = title:b_alexandria
				this = title:b_antiocheia
				this = title:b_baghdad
				this = title:b_constantinople
				this = title:b_cordoba
				this = title:b_roma
				this = title:b_jerusalem
			}
			title_province = {
				NOT = { exists = var:cow_metropolis }
				NOT = { has_holding_type = cow_metropolis_holding }
			}
		}
		NOT = {  # Can't spam click button - flag is cleared through any of the event options
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_repeatable_hist_cow_metropolis
			}
		}
		NOT = { has_game_rule = cow_all_holding_conversion_prohibited }
	}

	is_valid = {
		prestige_level >= 3
		highest_held_title_tier >= tier_kingdom
		is_at_war = no
		NOT = { has_government = tribal_government }
		culture = {
			has_innovation = innovation_city_planning
		}
		
		OR = {
			trigger_if = {
				limit = {
					any_sub_realm_barony = { this = title:b_alexandria }
					title:b_alexandria.title_province = { NOT = { exists = var:cow_metropolis } }
				}
				AND = {
					title:b_alexandria.county = { development_level >= bad_development_level }
					custom_description = {
						text = no_cow_metropolis_holding
						title:b_alexandria.title_province = { NOT = { has_holding_type = cow_metropolis_holding } }
					}
					title:b_alexandria.title_province = { has_ongoing_construction = no }
				}
			}
			trigger_if = {
				limit = {
					any_sub_realm_barony = { this = title:b_antiocheia }
					title:b_antiocheia.title_province = { NOT = { exists = var:cow_metropolis } }
				}
				AND = {
					title:b_antiocheia.county = { development_level >= bad_development_level }
					custom_description = {
						text = no_cow_metropolis_holding
						title:b_antiocheia.title_province = { NOT = { has_holding_type = cow_metropolis_holding } }
					}
					title:b_antiocheia.title_province = { has_ongoing_construction = no }
				}
			}
			trigger_if = {
				limit = {
					any_sub_realm_barony = { this = title:b_baghdad }
					title:b_baghdad.title_province = { NOT = { exists = var:cow_metropolis } }
				}
				AND = {
					title:b_baghdad.county = { development_level >= bad_development_level }
					custom_description = {
						text = no_cow_metropolis_holding
						title:b_baghdad.title_province = { NOT = { has_holding_type = cow_metropolis_holding } }
					}
					title:b_baghdad.title_province = { has_ongoing_construction = no }
				}
			}
			trigger_if = {
				limit = {
					any_sub_realm_barony = { this = title:b_constantinople }
					title:b_constantinople.title_province = { NOT = { exists = var:cow_metropolis } }
				}
				AND = {
					title:b_constantinople.county = { development_level >= bad_development_level }
					custom_description = {
						text = no_cow_metropolis_holding
						title:b_constantinople.title_province = { NOT = { has_holding_type = cow_metropolis_holding } }
					}
					title:b_constantinople.title_province = { has_ongoing_construction = no }
				}
			}
			trigger_if = {
				limit = {
					any_sub_realm_barony = { this = title:b_cordoba }
					title:b_cordoba.title_province = { NOT = { exists = var:cow_metropolis } }
				}
				AND = {
					title:b_cordoba.county = { development_level >= bad_development_level }
					custom_description = {
						text = no_cow_metropolis_holding
						title:b_cordoba.title_province = { NOT = { has_holding_type = cow_metropolis_holding } }
					}
					title:b_cordoba.title_province = { has_ongoing_construction = no }
				}
			}
			trigger_if = {
				limit = {
					any_sub_realm_barony = { this = title:b_roma }
					title:b_roma.title_province = { NOT = { exists = var:cow_metropolis } }
				}
				AND = {
					title:b_roma.county = { development_level >= bad_development_level }
					custom_description = {
						text = no_cow_metropolis_holding
						title:b_roma.title_province = { NOT = { has_holding_type = cow_metropolis_holding } }
					}
					title:b_roma.title_province = { has_ongoing_construction = no }
				}
			}
			trigger_if = {
				limit = {
					any_sub_realm_barony = { this = title:b_jerusalem }
					title:b_jerusalem.title_province = { NOT = { exists = var:cow_metropolis } }
				}
				AND = {
					title:b_jerusalem.county = { development_level >= bad_development_level }
					custom_description = {
						text = no_cow_metropolis_holding
						title:b_jerusalem.title_province = { NOT = { has_holding_type = cow_metropolis_holding } }
					}
					title:b_jerusalem.title_province = { has_ongoing_construction = no }
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_ruler = yes
		is_available_adult = yes
	}

	effect = {
		save_scope_as = refounder

		custom_tooltip = decision_reestablish_cow_metropolis_custom_tooltip
		
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:flag_repeatable_hist_cow_metropolis
		}

		trigger_event = cow_decisions.2001
		
		every_player = {
			limit = {
				NOT = { this = root }
				is_within_diplo_range = { CHARACTER = root }
			}
			trigger_event = cow_decisions.2002
		}
	}

	cost = {
		prestige = medium_prestige_value
	}
	
	ai_potential = {
		is_adult = yes
		is_independent_ruler = yes
		highest_held_title_tier = tier_kingdom
	}

	ai_will_do = {
		base = 100
	}
}

found_generic_cow_metropolis_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_misc.dds"
	major = yes
	ai_check_interval = 0

	desc = found_generic_cow_metropolis_decision_desc
	selection_tooltip = found_generic_cow_metropolis_decision_tooltip

	is_shown = {
		is_landed = yes
		capital_province = {
			NOT = { has_holding_type = cow_metropolis_holding }
		}
		NOT = {  #Can only do it once globally.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_constructed_generic_cow_metropolis
			}
		}
		NOT = { has_game_rule = cow_all_holding_conversion_prohibited }
	}
	

	is_valid = {
		prestige_level >= 4
		OR = {
			highest_held_title_tier = tier_empire
			AND = {
				prestige_level >= 5
				piety_level >= 5
				highest_held_title_tier = tier_kingdom
			}
		}
		is_at_war = no
		NOT = { has_government = tribal_government }
		culture = {
			has_innovation = innovation_city_planning
		}
		capital_province = {
			has_ongoing_construction = no
			NOT = { has_holding_type = cow_metropolis_holding }
			custom_description = {
				text = barony_is_not_hist_cow_metropolis_trigger_custom
				barony_is_valid_for_cow_metropolis_trigger = no
			}
			county = { development_level >= 30 }
		}
	}

	is_valid_showing_failures_only = {
		is_ruler = yes
		is_available_adult = yes
	}

	effect = {
		save_scope_as = founder

		custom_tooltip = decision_found_generic_cow_metropolis_custom_tooltip
		
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:flag_constructed_generic_cow_metropolis
		}
		
		trigger_event = cow_decisions.3001
		
		every_player = {
			limit = {
				NOT = { this = root }
				is_within_diplo_range = { CHARACTER = root }
			}
			trigger_event = cow_decisions.3002
		}
	}

	cost = {
		gold = {
			value = 1200
		}
		prestige = monumental_prestige_value
	}
	
	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 0
	}
}

cow_convert_holding_to_metropolis_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_misc.dds"
	major = yes
	ai_check_interval = 0

	is_shown = {
		is_landed = yes
		OR = { 
			has_game_rule = cow_only_legacy_holding_conversion
			has_game_rule = cow_regular_holding_conversion_allowed # TEMP SOLUTION
			has_game_rule = cow_every_holding_conversion_allowed
		}
	}

	widget = {
		# Name of the widget to use. Must be at the path <decision_view_widgets>/<widget_name>.gui
		gui = decision_view_widget_cow_convert_holding
		# Some widgets require a custom controller (see below). Default: default
		controller = create_holy_order
		barony_valid = {
			trigger_if = {
				limit = { exists = this }
				cow_barony_is_valid_for_metropolis_trigger = { CHARACTER = scope:ruler }
			}
			trigger_else = {
				custom_description = {
					text = "has_cow_metropolis_barony_selected"
					always = no
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war = no
	}

	is_valid = {
		custom_description = {
			text = "cow_is_king_or_emperor"
			highest_held_title_tier >= tier_kingdom
		}
		culture = {
			has_innovation = innovation_city_planning
		}
		is_at_war = no
		NOT = { has_government = tribal_government }
		custom_description = {
			text = "has_cow_eligble_barony_in_county"
			any_held_county = {
				any_in_de_jure_hierarchy = {
					cow_barony_is_valid_for_metropolis_trigger = { CHARACTER = scope:ruler }
				}
			}
		}
	}

	cost = {
		gold = {
			value = 11500
		}
	}

	effect = {
		scope:barony.title_province = {
			hidden_effect = {
				cow_refound_set_holding_lvl_flag_effect = yes
				cow_set_building_lvl_flag_effect = yes
			}
			set_holding_type = cow_metropolis_holding
			hidden_effect = {
				if = {
					limit = { barony_variable_holding_level_trigger = yes }
					cow_refound_add_holding_level_effect = yes
				}
				if = {
					limit = { barony_variable_building_level_trigger = yes }
					cow_add_building_lvl_effect = yes
				}
			}
		}
		
		# custom_tooltip = cow_convert_holding_to_metropolis_decision_effect_message
	}
	
	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 0
	}
}

cow_ai_convert_holding_to_metropolis_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_misc.dds"
	
	ai_check_interval = 120

	is_shown = {
		is_landed = yes
		is_ai = yes # AI ONLY
		capital_province = {
			NOT = { has_holding_type = cow_metropolis_holding }
		}
		highest_held_title_tier = tier_empire
		NOT = { has_game_rule = cow_all_holding_conversion_prohibited }
		NOT = { has_character_flag = flag_ai_cow_found_metropolis }
	}

	is_valid_showing_failures_only = {
		is_ruler = yes
		is_available_adult = yes
	}

	is_valid = {
		highest_held_title_tier = tier_empire
		culture = {
			has_innovation = innovation_city_planning
		}
		prestige_level >= 4
		gold >= 4000
		is_at_war = no
		is_ai = yes # AI ONLY
		NOT = { has_government = tribal_government }
		capital_province = {
			has_ongoing_construction = no
			NOT = { has_holding_type = cow_metropolis_holding }
			custom_description = {
				text = barony_is_not_hist_cow_metropolis_trigger_custom
				barony_is_valid_for_cow_metropolis_trigger = no
			}
		}
		NOT = { has_character_flag = flag_ai_cow_found_metropolis } # AI ONLY - SO NO NEED FOR DESC
	}

	cost = {
		gold = {
			value = 4000
		}
		prestige = monumental_prestige_value
	}

	effect = {
		save_scope_as = founder
		
		add_character_flag = flag_ai_cow_found_metropolis
		
		trigger_event = cow_decisions.3003
		
		every_player = {
			limit = {
				NOT = { this = root }
				is_within_diplo_range = { CHARACTER = root }
			}
			trigger_event = cow_decisions.3002
		}

	}
	
	ai_potential = {
		is_adult = yes
		is_independent_ruler = yes
		highest_held_title_tier = tier_empire
	}

	ai_will_do = {
		base = 100
	}
}