﻿
##################################################
# Convert Realm to Feudalism/Clan through Liege
# by Linnéa Thimrén
##################################################

# A more lenient decision to convert if your liege is feudal
convert_to_feudalism_liege_converted_decision = {
	picture = {
		trigger = {
			has_tgp_dlc_trigger = yes
			liege = {
				culture = { has_cultural_pillar = heritage_japonic }
			}
		}
		reference = "gfx/interface/illustrations/decisions/tgp_dominance.dds"
	}
	picture = {
		trigger = {
			liege = {
				government_has_flag = government_is_clan
			}
		}
		reference = "gfx/interface/illustrations/event_scenes/bp1_courtyard_mena.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	desc = convert_to_feudalism_liege_converted_decision_desc

	ai_check_interval_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	is_shown = {
		government_has_flag = government_is_tribal
		liege = {
			OR = {
				government_has_flag = government_is_japan_feudal
				government_has_flag = government_is_feudal
				government_has_flag = government_is_clan
			}
		}
	}

	is_valid = {
		OR = {
			has_realm_law = tribal_authority_1
			has_realm_law = tribal_authority_2
			has_realm_law = tribal_authority_3
		}
		custom_description = {
			text = faith_is_reformed
			subject = root
			faith = { NOT = { has_doctrine_parameter = unreformed } }
		}
		trigger_if = {
			limit = { government_has_flag = government_is_wanua }
			faith = { has_doctrine = doctrine_monotheist }
		}
		custom_description = {
			text = recent_conversion_to_tribalism
			NOT = { has_character_flag = just_converted_to_tribalism }
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = permafrost_feudal_ban
			NOT = { culture = { has_cultural_parameter = permafrost_cannot_become_feudal } }
		}
	}

	cost = {
		prestige = 150
	}
	
	effect = {
		trigger_event = major_decisions.0001
		save_scope_as = actor
		convert_whole_realm_to_feudalism_effect = yes
		hidden_effect = {
			every_vassal = {
				trigger_event = {
					id = major_decisions.0002
					days = 3
				}
			}
			create_noble_family_effect = { GOVERNMENT_GIVER = this }
			every_vassal = {
				limit = {
					highest_held_title_tier >= tier_county
					house.house_head ?= this
					government_has_flag = government_is_feudal
					NOT = {
						any_held_title = { is_noble_family_title = yes }
					}
				}
				create_noble_family_effect = { GOVERNMENT_GIVER = this }
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

# Convert from Clan if your liege is Feudal
convert_clan_to_feudalism_through_liege_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	desc = convert_clan_to_feudalism_through_liege_decision_desc

	ai_check_interval_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	is_shown = {
		government_has_flag = government_is_clan
		top_liege != this
		liege = {
			government_has_flag = government_is_feudal
		}
	}

	is_valid = {
		custom_description = {
			text = same_faith_as_liege
			OR = {
				religion = liege.religion
				faith = {
					faith_hostility_level = {
						target = root.liege.faith
						value >= faith_fully_accepted_level
					}
				}
			}
		}
		custom_description = {
			text = same_culture_as_liege
			OR = {
				culture = liege.culture
				culture = {
					cultural_acceptance = { target = root.liege.culture value >= 90 } # Essentially the same culture
				}
			}
		}
	}

	cost = {
		prestige = 150
	}
	
	effect = {
		trigger_event = major_decisions.0001
		save_scope_as = actor

		change_government = feudal_government

		hidden_effect = {
			every_vassal_or_below = {
				limit = { government_has_flag = government_is_clan }
				change_government = feudal_government
				trigger_event = {
					id = major_decisions.0002
					days = 3
				}
			}
			create_noble_family_effect = { GOVERNMENT_GIVER = this }
			every_vassal = {
				limit = {
					highest_held_title_tier >= tier_county
					house.house_head ?= this
					government_has_flag = government_is_feudal
					NOT = {
						any_held_title = { is_noble_family_title = yes }
					}
				}
				create_noble_family_effect = { GOVERNMENT_GIVER = this }
			}
		}
	}

	ai_potential = {
		prestige >= 150
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			opinion = {
				target = liege
				value >= 0
			}
		}
	}
}

##################################################
# Convert Realm to Feudalism/Clan
# by Linnéa Thimrén
##################################################

# A decision to feudalize the entire realm (wow!)
convert_whole_realm_to_feudalism_decision = {
	picture = {
		trigger = {
			has_tgp_dlc_trigger = yes
			liege = {
				culture = { has_cultural_pillar = heritage_japonic }
			}
		}
		reference = "gfx/interface/illustrations/decisions/tgp_dominance.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	desc = convert_whole_realm_to_feudalism_decision_desc

	ai_check_interval_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	is_shown = {
		government_has_flag = government_is_tribal
		OR = {
			top_liege = this
			AND = {
				top_liege != this
				liege = {
					NOR = {
						government_has_flag = government_is_feudal
						government_has_flag = government_is_clan
					}
				}
			}
		}
	}

	is_valid = {
		has_realm_law = tribal_authority_3
		custom_description = {
			text = faith_is_reformed
			subject = root
			faith = { NOT = { has_doctrine_parameter = unreformed } }
		}
		prestige_level >= 2
		capital_province.county = {
			development_level >= convert_to_feudalism_development_requirement
		}
		custom_description = { #You need to have 70% of all (non-regional/unique) tribal innovations!
			text = has_all_tribal_innovations
			subject = root.culture
			culture = {
				calc_true_if = {
					amount >= 9
					has_innovation = innovation_motte
					has_innovation = innovation_catapult
					has_innovation = innovation_barracks
					has_innovation = innovation_mustering_grounds
					has_innovation = innovation_bannus
					has_innovation = innovation_quilted_armor
					has_innovation = innovation_gavelkind
					has_innovation = innovation_crop_rotation
					has_innovation = innovation_city_planning
					has_innovation = innovation_casus_belli
					has_innovation = innovation_plenary_assemblies
					has_innovation = innovation_ledger
					has_innovation = innovation_development_01
					has_innovation = innovation_currency_01
				}
			}
		}
		trigger_if = {
			limit = { government_has_flag = government_is_wanua }
			faith = { has_doctrine = doctrine_monotheist }
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = permafrost_feudal_ban
			NOT = { culture = { has_cultural_parameter = permafrost_cannot_become_feudal } }
		}
	}

	cost = {
		prestige = 200
	}
	
	effect = {
		gain_legitimizing_legend_seed_tooltip_effect = yes
		add_character_flag = ready_to_receive_seed
		trigger_event = major_decisions.0001
		save_scope_as = actor
		convert_whole_realm_to_feudalism_effect = yes
		hidden_effect = {
			every_vassal = {
				trigger_event = {
					id = major_decisions.0002
					days = 3
				}
			}
			create_noble_family_effect = { GOVERNMENT_GIVER = this }
			every_vassal = {
				limit = {
					highest_held_title_tier >= tier_county
					house.house_head ?= this
					government_has_flag = government_is_feudal
					NOT = {
						any_held_title = { is_noble_family_title = yes }
					}
				}
				create_noble_family_effect = { GOVERNMENT_GIVER = this }
			}
		}
	}

	ai_potential = {
		NOT = { mpo_has_gok_mongol_empire_trigger = yes } #Stop the Mongols from slowing their conquest. 
	}

	ai_will_do = {
		base = 100
	}
}

##################################################
# Convert Realm to Feudalism (West African Pagan)
# by Ewan Cowhig Croft
##################################################

# A decision for West African pagans to feudalise without reforming.
convert_whole_realm_to_feudalism_west_african_pagan_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	desc = convert_whole_realm_to_feudalism_west_african_pagan_decision_desc

	ai_check_interval_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	is_shown = {
		# Only tribals need formalise.
		government_has_flag = government_is_tribal
		# Unreformed West African Pagans are our targets.
		faith_qualifies_for_west_african_pagan_feudalisation_trigger = yes
	}

	is_valid = {
		# Repeat the faith requirements, so that the player knows what's up.
		faith_qualifies_for_west_african_pagan_feudalisation_trigger = yes
		# Must have suitable authority.
		has_realm_law = tribal_authority_3
		# Independents only.
		top_liege = this
		# West Africans feudalise from large empires.
		calc_true_if = {
			amount >= 4
			realm_size >= minor_realm_size
			highest_held_title_tier >= tier_kingdom
			custom_tooltip = {
				text = convert_whole_realm_to_feudalism_west_african_pagan_decision.tt.vassal_count
				any_vassal = { count >= convert_whole_realm_to_feudalism_west_african_pagan_decision_vassal_count_value }
			}
			prestige_level >= high_prestige_level
			piety_level >= high_piety_level
			custom_tooltip = {
				text = convert_whole_realm_to_feudalism_west_african_pagan_decision.tt.wa_capital_development
				capital_county = {
					development_level >= convert_whole_realm_to_feudalism_west_african_pagan_decision_wa_capital_development_value
					title_province = { geographical_region = world_africa_west }
				}
			}
		}
		# You need to have 70% of all (non-regional/unique) tribal innovations!
		custom_description = {
			text = has_all_tribal_innovations
			subject = root.culture
			culture = {
				calc_true_if = {
					amount >= 9
					has_innovation = innovation_motte
					has_innovation = innovation_catapult
					has_innovation = innovation_barracks
					has_innovation = innovation_mustering_grounds
					has_innovation = innovation_bannus
					has_innovation = innovation_quilted_armor
					has_innovation = innovation_gavelkind
					has_innovation = innovation_crop_rotation
					has_innovation = innovation_city_planning
					has_innovation = innovation_casus_belli
					has_innovation = innovation_plenary_assemblies
					has_innovation = innovation_ledger
					has_innovation = innovation_development_01
					has_innovation = innovation_currency_01
				}
			}
		}
	}

	cost = { prestige = 500 }

	effect = {
		trigger_event = major_decisions.0001
		save_scope_as = actor
		convert_whole_realm_to_feudalism_effect = yes
		hidden_effect = {
			every_vassal = {
				trigger_event = {
					id = major_decisions.0002
					days = 3
				}
			}
			create_noble_family_effect = { GOVERNMENT_GIVER = this }
			every_vassal = {
				limit = {
					highest_held_title_tier >= tier_county
					house.house_head ?= this
					government_has_flag = government_is_feudal
					NOT = {
						any_held_title = { is_noble_family_title = yes }
					}
				}
				create_noble_family_effect = { GOVERNMENT_GIVER = this }
			}
		}
	}

	ai_potential = {
		# Cut down on checks for other tribals.
		exists = capital_county.title_province
		capital_county.title_province = { geographical_region = world_africa_west }
	}

	ai_will_do = {
		base = 100
	}
}