﻿adopt_steppe_administration = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/tgp_great_project.dds"
	} 
	decision_group_type = nomad_major

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 60
		empire = 60
		hegemony = 0
	}

	desc = adopt_steppe_administration_desc
	selection_tooltip = adopt_steppe_administration_tooltip

	is_shown = {
		has_mpo_dlc_trigger = yes
		has_tgp_dlc_trigger = yes
		government_has_flag = government_is_nomadic
		OR = {
			highest_held_title_tier = tier_kingdom
			highest_held_title_tier = tier_empire
		}
		is_playable_character = yes
	}

	is_valid = {
		custom_tooltip = {
			text = you_are_the_culture_head
			culture = {
				culture_head = root
			}
		}
		OR = { # You need to already be on your way to imperial status, if not already there
			has_realm_law = nomadic_authority_4
			has_realm_law = nomadic_authority_5
		}
		custom_tooltip = {
			text = steppe_admin_kingdom_requirement
			any_realm_de_jure_kingdom = {
				count >= 3
				root = {
					completely_controls = prev
				}
				title_capital_county.title_province ?= {
					OR = {
						has_holding_type = castle_holding
						has_holding_type = city_holding
						has_holding_type = church_holding
						has_holding_type = temple_citadel_holding
					}
				}
			}
		}
		save_temporary_scope_value_as = {
			name = temp_num_tributaries
			value = sub_realm_with_tributaries_size
		}
		custom_tooltip = { # You need a total realm size big enough to impress
			text = steppe_admin_tributary_req
			sub_realm_with_tributaries_size >= 50
		}
		custom_tooltip = { # You need somewhere to get the idea to adopt Merit and examinations from
			text = steppe_admin_merit_req
			OR = {
				any_neighboring_top_liege_realm_owner = {
					AND = {
						government_has_flag = government_has_merit
						highest_held_title_tier >= tier_kingdom
					}
				}
				any_tributary = {
					AND = {
						government_has_flag = government_has_merit
						highest_held_title_tier >= tier_kingdom
					}			
				}
				any_vassal_or_below = {
					AND = {
						government_has_flag = government_has_merit
						highest_held_title_tier >= tier_kingdom
					}			
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		is_tributary = no
		is_available_adult = yes
		has_active_diarchy = no
	}

	cost = {
        gold = {
            value = 0
            if = {
                limit = {
                    has_treasury = no
                }
                add = massive_prestige_value # building an imperial palace isn't cheap, you know
           }
        }

        treasury = {
            value = 0
            if = {
                limit = {
                    has_treasury = yes
                }
                add = 500
            }
        }
		prestige = {
			value = monumental_prestige_value
		}
	}

	effect = {
		#GoK stops really being GoK
		gok_government_change_story_end_effect = yes
		if = {
			limit = {
				has_realm_law = nomadic_authority_4
			}
			add_character_flag = realm_law_4
		}
		else = {
			add_character_flag = realm_law_5
		}
		add_legitimacy_effect = { LEGITIMACY = massive_legitimacy_gain }
		dynasty = {
			add_dynasty_prestige = massive_dynasty_prestige_gain
		}
		save_scope_as = nomad_settling_down
		save_scope_value_as = {
			name = invading_herd_value
			value = domicile.herd
		}
		nomad_domicile_refund_treasury_or_gold_effect = yes # we pay you back for your domicile investments
		nomad_convert_herds_to_treasury_or_gold_special_troops_effect = yes # we pay you back for your herd investments
		nomad_to_steppe_admin_new_capital_effect = yes # we arrange a new capital for you the same way we would any other settling nomad
		change_government = steppe_admin_government
		give_noble_family_title = {
			name = noble_family_name
			tier = county
			article = DEFAULT_TITLE_NAME_ARTICLE
			government = steppe_admin_government
			save_scope_as = new_title
		}
		scope:new_title = {
			set_coa = holder.house
		}
		hidden_effect = {
			switch = {
				trigger = has_character_flag
				realm_law_4 = {
					add_realm_law_skip_effects = meritocratic_bureaucracy_2
					remove_character_flag = realm_law_4
				}
				realm_law_5 = {
					add_realm_law_skip_effects = meritocratic_bureaucracy_3
					remove_character_flag = realm_law_5
				}
			}
		}
		hidden_effect = { # We explain this in an earlier tooltip
			add_treasury_or_gold = {
				value = scope:domicile_refund_treasury_or_gold_value
				add = scope:nomad_convert_herds_to_treasury_or_gold_value
			}
		}
		if = {
			limit = {
				NOT = { government_has_flag = government_allows_nomad_domicile_titles }
				any_held_title = {
					is_nomad_title = yes
				}
			}
			every_held_title = {
				limit = {
					is_nomad_title = yes
				}
				root = {
					destroy_title = prev
				}
			}
		}
		custom_tooltip = {
			text = merit_based_vassals_convert_to_steppe_admin
			if = {
				limit = {
					any_vassal = {
						government_has_flag = government_has_merit
						NOT = { government_has_flag = government_is_steppe_admin }
					}
				}
				every_vassal = {
					limit = {
						government_has_flag = government_has_merit
						NOT = { government_has_flag = government_is_steppe_admin }
					}
					change_government = steppe_admin_government
				}
			}
		}
		hidden_effect = {
			every_tributary = {
				add_to_list = tributaries
			}
			every_in_list = {
				list = tributaries
				start_tributary_interaction_effect = { # to update their contract types for your new status
					TRIBUTARY = this
					SUZERAIN = root
				}
			}
		}
		hidden_effect = {
			generate_new_steppe_admin_families_effect = yes # we populate your noble families so you have some starting non-nomadic administrators
		}
	}

	ai_potential = {
		#AI greatest of khans shouldn't be doing this and ruining their GoKness
		NOR = {
			has_trait = greatest_of_khans
			any_owned_story = {
				OR = {
					story_type = story_mongol_invasion
					story_type = story_greatest_of_khans
				}
			}
		}
	}

	ai_will_do = {
		base = 100 # the bar to doing this is high enoug that if the AI can do it, the AI should do it
	}
}

### Return to the Steppe ###
return_to_the_steppe_decision = {
	picture = {
		reference = "gfx/interface/illustrations/event_story/mpo_steppe_region.dds"
	}
	decision_group_type = nomad_major

	desc = return_to_the_steppe_decision_desc
	selection_tooltip = return_to_the_steppe_decision_tooltip
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 72 # just in case there's an orphaned steppe admin kingdom somewhere
		empire = 72
		hegemony = 0
	}

	is_shown = {
		has_mpo_dlc_trigger = yes
		has_tgp_dlc_trigger = yes
		government_has_flag = government_is_steppe_admin
		is_independent_ruler = yes
		is_playable_character = yes
		NOT = {
			any_vassal_or_below = {
				is_ai = no # the gamestate could conceivably result in as situation where you could game over a player-vassal by doing this, so we just make sure it can't happen
			}
		}
	}

	is_valid = {
		has_trait = nomadic_philosophy # you need at least some connection to the steppe to want to go back to it
		custom_tooltip = {
			text = small_enough_realm_to_abandon
			any_realm_county = {
				count <= 10
				title_province = {
					OR = {
						has_holding_type = castle_holding
						has_holding_type = church_holding
						has_holding_type = city_holding
						has_holding_type = temple_citadel_holding
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		is_available = yes
		has_active_diarchy = no
	}

	cost = {
		prestige = {
			value = massive_prestige_value # this is already a escape hatch, so we don't want it to be too punishing
		}
	}

	effect = {
		custom_tooltip = {
			text = treasury_emptying_effect_desc
			empty_treasury_when_abandoning_landed_life_effect = yes # otherwise the treasury sticks around
		}
		refund_noble_family_domicile_buildings_effect = yes
		custom_tooltip = {
			text = nomadize_landless_noble_families
			refund_vassal_noble_families_and_make_them_nomads_effect = yes # for those who share your cultural heritage
		}
		custom_tooltip = {
			text = rehouse_landless_noble_families
			rehome_noble_families_to_compatible_liege_effect = yes # we find a new home for those who don't share your cultural heritage
		}
		custom_tooltip = {
			text = title_maa_regiments_will_be_destroyed
			if = {
				limit = {
					any_maa_regiment = {
						is_title_maa_regiment = yes
					}
				}
				every_maa_regiment = {
					limit = {
						is_title_maa_regiment = yes
					}
					destroy_maa_regiment = yes
				}
			}
		}
		change_government = nomad_government
		hidden_effect = {
			if = {
				limit = {
					exists = scope:current_treasury # saved in empty_treasury_when_abandoning_landed_life_effect
				}
				add_gold = {
					value = scope:current_treasury
				}
			}
		}
		custom_tooltip = {
			text = convert_steppe_admin_to_meritocratic_tooltip
			convert_steppe_admin_vassals_to_meritocratic_effect = yes
		}
		hidden_effect = {
			every_tributary = {
				add_to_list = tributaries
			}
			every_in_list = {
				list = tributaries
				start_tributary_interaction_effect = { # to update their contract types for your new status
					TRIBUTARY = this
					SUZERAIN = root
				}
			}
		}
	}

	ai_potential = {
		capital_county.title_province = {
			NOR = {
				has_holding_type = castle_holding
				has_holding_type = church_holding
				has_holding_type = city_holding
				has_holding_type = temple_citadel_holding
			}
		}
	}

	ai_will_do = {
		base = 100 # if the potential is met, the AI should do it
	}
}

### Adopt Meritocratic Government ###
convert_to_meritocratic_decision = {
	picture = {
		reference = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_stability.dds"
	} 
	decision_group_type = major

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 60
		empire = 60
		hegemony = 0
	}

	desc = convert_to_meritocratic_desc
	selection_tooltip = convert_to_meritocratic_tooltip

	is_shown = {
		has_tgp_dlc_trigger = yes
		government_has_flag = government_is_steppe_admin
		OR = {
			highest_held_title_tier = tier_kingdom # this isn't standard, but will cover some edge cases for orphaned steppe admin kingdoms
			highest_held_title_tier = tier_empire
		}
		any_sub_realm_county = {
			count > 0
			title_province = {
				OR = {
					has_holding_type = castle_holding
					has_holding_type = church_holding
					has_holding_type = city_holding
					has_holding_type = temple_citadel_holding
				}
			}
		}
		is_playable_character = yes
	}

	is_valid = {
		OR = {
			has_realm_law = meritocratic_bureaucracy_2
			has_realm_law = meritocratic_bureaucracy_3
		}
		save_temporary_scope_value_as = {
			name = temp_num_qualifying_counties
			value = temp_num_qualifying_counties_count
		}
		custom_tooltip = {
			text = convert_to_meritocratic_county_count
			any_sub_realm_county = {
				count >= 30
				holder = {
					is_governor_or_admin_count = yes
					government_has_flag = government_has_merit
				}
				title_province = {
					OR = {
						has_holding_type = castle_holding
						has_holding_type = church_holding
						has_holding_type = city_holding
						has_holding_type = temple_citadel_holding
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_adult = yes
		has_active_diarchy = no
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = monumental_gold_value
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = monumental_gold_value
			}
		}
		prestige = {
			value = massive_prestige_value
		}
		influence = {
			value = monumental_influence_value
		}
	}

	effect = {
		add_legitimacy_effect = { LEGITIMACY = monumental_legitimacy_gain }
		dynasty = {
			add_dynasty_prestige = monumental_dynasty_prestige_gain
		}
		tgp_domicile_conversion_when_changing_government_type = {
			NEW_DOMICILE_TYPE = east_asian_estate
			NEW_GOVERNMENT_TYPE = meritocratic_government
		}
		change_government = meritocratic_government
		hidden_effect = {
			every_tributary = {
				add_to_list = tributaries
			}
			every_in_list = {
				list = tributaries
				start_tributary_interaction_effect = {  # to update their contract types for your new status
					TRIBUTARY = this
					SUZERAIN = root
				}
			}
		}
		custom_tooltip = {
			text = steppe_admin_vassals_will_convert
			convert_steppe_admin_vassals_to_meritocratic_effect = yes
		}
		custom_tooltip = {
			text = non_merit_based_vassals_become_tributaries
			if = {
				limit = {
					any_vassal = {
						NOT = {
							government_has_flag = government_has_merit
						}
					}
				}
				create_title_and_vassal_change = {
					type = independency
					save_scope_as = change
					add_claim_on_loss = no
				}
				every_vassal = {
					limit = {
						NOT = {
							government_has_flag = government_has_merit
						}
					}
					add_to_list = soon_to_be_former_vassals
					becomes_independent = { change = scope:change }
				}
				resolve_title_and_vassal_change = scope:change
				every_in_list = {
					list = soon_to_be_former_vassals
					start_tributary_interaction_effect = {
						TRIBUTARY = this
						SUZERAIN = root
					}
				}
			}
		}
	}

	ai_potential = {
	}

	ai_will_do = {
		base = 0
		modifier = {
			add = 20
			NOT = { has_trait = nomadic_philosophy }
		}
		modifier = {
			add = 30
			has_trait = education_learning 
		}
		modifier = {
			add = 50
			has_religion = religion:confucianism_religion
		}
		modifier = {
			add = 30
			has_trait = confucian_education
		}
	}
}
