﻿convert_to_freehold_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_cerimonial_decision.dds"
	}
	decision_group_type = major
	desc = convert_to_administrative_decision_desc

	ai_check_interval = 36

	confirm_text = convert_to_freehold_decision_confirm

	is_shown = {
		
		has_character_flag = zz_valyria_freehold
		NOT = { 
			has_government = freehold_government
		}
		primary_title.tier >= tier_duchy
		trigger_if = {
			limit = { is_independent_ruler = no }
			liege = { government_allows = administrative }
		}
		trigger_else = {
			is_independent_ruler = yes
		}
	}

	is_valid = {
		has_ep3_dlc_trigger = yes
		is_ai = no
	}
	
	is_valid_showing_failures_only = {
		is_at_war = no
	}

	cost = {
		prestige = {
			value = 1000
			if = {
				limit = {
					is_ai = no
					primary_title.tier = tier_kingdom
				}
				multiply = 1.5
			}
			if = { # Much cheaper for vassals wanting to adopt their admin liege's government
				limit = {
					is_independent_ruler = no
				}
				multiply = 0.1
			}
		}
		gold = {
			value = 800
			if = {
				limit = { is_ai = no }
				#Realm size
				if = {
					limit = { root.realm_size >= 300 }
					multiply = 3.5
				}
				else_if = {
					limit = { root.realm_size >= 250 }
					multiply = 3
				}
				else_if = {
					limit = { root.realm_size >= 200 }
					multiply = 2.5
				}
				else_if = {
					limit = { root.realm_size >= 150 }
					multiply = 2
				}
				else_if = {
					limit = { root.realm_size >= 100 }
					multiply = 1.5
				}
			}
			#Era
			culture = {
				if = {
					limit = { has_cultural_era_or_later = culture_era_late_medieval }
					multiply = 1.75
				}
				else_if = {
					limit = { has_cultural_era_or_later = culture_era_high_medieval }
					multiply = 1.25
				}
				else_if = {
					limit = { has_cultural_era_or_later = culture_era_early_medieval }
					multiply = 1
				}
				else = {
					multiply = 0.75
				}
			}
			#Income
			if = {
				limit = { root.monthly_character_income >= 100 }
				multiply = 3
			}
			else_if = {
				limit = { root.monthly_character_income >= 80 }
				multiply = 2.5
			}
			else_if = {
				limit = { root.monthly_character_income >= 60 }
				multiply = 2
			}
			else_if = {
				limit = { root.monthly_character_income >= 40 }
				multiply = 1.5
			}
			else_if = {
				limit = { root.monthly_character_income >= 20 }
				multiply = 1.1
			}

			max = 3000
			
			if = { # Much cheaper for vassals wanting to adopt their admin liege's government
				limit = {
					is_independent_ruler = no
				}
				multiply = 0.1
			}
		}
	}
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		show_from_start = no

		item = { # Administrative
			value = go_freehold_government
			is_shown = {
				has_ep3_dlc_trigger = yes
			}
			is_valid = {
				top_liege = {
					NOR = {
						has_government = celestial_government
						has_government = meritocratic_government
						has_government = japan_administrative_government
					}
				}
			}
			current_description = go_freehold_government_desc
			localization = go_freehold_government_desc
			icon = "gfx/interface/icons/government_types/administrative_government.dds"
			ai_chance = {
				value = 10
			}
		}
	}

	effect = {
		save_scope_as = actor
		primary_title = { set_state_faith = root.faith }
		capital_county = { set_county_faith = root.faith }
		convert_to_administrative_from_feudalism_effect = { GOVERNMENT_TO_ADOPT = flag:freehold }
		

		if = {
			limit = {
				is_independent_ruler = yes
			}
			add_legitimacy_effect = { LEGITIMACY = admin_convert_legitimacy_value } #One Time Legitimacy Boost
		}
		trigger_event = zz_ep3_decisions_event.4060 #Also sends information event to human vassals
	}

	ai_potential = {
		always = no 
	}
}
