﻿#EK NOTE: removed mentions of byzantium
pay_homage_decision = {
	ai_check_interval = 45
	#EK DISABLED: no Byzantium
	#picture = {
	#	trigger = {
	#		NOR = {
	#			government_has_flag = government_is_tribal
	#			government_has_flag = government_is_theocracy
	#			top_liege ?= { government_has_flag = government_is_tribal }
	#			top_liege ?= { government_has_flag = government_is_theocracy }
	#		}
	#		OR = {
	#			culture = { has_cultural_pillar = heritage_byzantine }
	#			top_liege ?= {
	#				OR = {
	#					culture = { has_cultural_pillar = heritage_byzantine }
	#					capital_barony ?= title:b_constantinople
	#					primary_title ?= title:e_byzantium
	#					primary_title ?= title:e_roman_empire
	#				}
	#			}
	#		}
	#	}
	#	reference = "gfx/interface/illustrations/decisions/ep3_cerimonial_decision.dds"
	#}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_knight_kneeling.dds"
	}
	decision_group_type = major

	cost = {
		prestige = standard_activity_cost
		gold = {
			value = 0
			if = {
				limit = {
					exists = scope:pay_homage_gold
					scope:pay_homage_gold = yes
				}
				add = medium_gold_value
			}
		}
	}

	is_shown = {
		is_landed = yes
		primary_title.tier >= tier_county
		is_independent_ruler = no
		liege ?= { has_royal_court = yes }
		has_dlc_feature = royal_court
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
		}
	}

	is_valid = {
		exists = liege
		custom_tooltip = {
			text = pay_homage_grace_valid_tt
			trigger_if = { # Has not paid homage to this liege before
				limit = {
					has_variable = pay_homage_grace
					exists = liege
				}
				NOT = { var:pay_homage_grace = liege }
			}
		}

	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		liege ?= { is_available_adult = yes }
		is_at_war_with_liege = no
		trigger_if = {
			limit = {
				is_ai = no
				has_royal_court = yes
			}
			has_spawned_court_events = no # should only be used for human players
		}
		trigger_if = { # Has not paid homage to this liege before
			limit = { 
				has_variable = pay_homage_grace
				exists = liege
			}
			custom_tooltip = {
				text = pay_homage_grace_tt
				NOT = { var:pay_homage_grace = liege }
			}
		}
		trigger_if = {
			limit = { is_ai = yes }
			NOT = {
				liege = { has_variable = pay_homage_cooldown }
			}
		}
	}

	widget = {
		gui = "decision_view_widget_pay_homage"
		controller = decision_option_list_controller
		decision_to_second_step_button = "PAY_HOMAGE_DECISION_NEXT_STEP_BUTTON"

		item = { # Submission
			value = pay_homage_submission
			is_valid = {}
			current_description = pay_homage_submission_desc
			localization = pay_homage_decision_option_submission
			icon = "gfx/interface/icons/icon_liege.dds"
			ai_chance = { # Always likely
				value = 50
				if = { # Generous vassals want to give gold if they can!
					limit = {
						ai_greed <= -50
						gold >= medium_gold_value
					}
					add = -50
				}
			}
		}

		item = { # Hook
			value = pay_homage_hook
			is_valid = {
				custom_tooltip = { # Liege does not already have a hook
					text = pay_homage_hook_tt
					NOT = {
						liege ?= { has_hook = prev } 
					}
				}
			}
			current_description = pay_homage_hook_desc
			localization = pay_homage_decision_option_hook
			icon = "gfx/interface/icons/message_feed/hook.dds"
			ai_chance = { # More likely if family
				value = 25
				if = {
					limit = {
						liege ?= { is_close_or_extended_family_of = prev }
					}
					add = 25
				}
				if = { # Certain AI's really do not want to be indebted
					limit = {
						OR = {
							has_trait = paranoid
							has_trait = arrogant
							ai_greed >= 50
						}
					}
					add = -50
				}
			}
		}

		item = { # Contract
			value = pay_homage_contract
			is_shown = { government_has_flag = government_is_feudal }
			is_valid = {
				custom_tooltip = { # Contract can be changed
					text = pay_homage_contract_modifiable_tt
					vassal_contract_has_modifiable_obligations = yes
				}
				custom_tooltip = { # Contract not at highest
					text = pay_homage_contract_increasable_tt
					OR = {
						vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
						vassal_contract_obligation_level_can_be_increased = feudal_government_levies
					}
				}
			}
			current_description = pay_homage_contract_desc
			localization = pay_homage_decision_option_contract
			icon = "gfx/interface/icons/message_feed/a_catch_all_councillor_icon.dds"
			ai_chance = { # More likely if contract is already lenient
				value = 10
				if = {
					limit = {
						OR = {
							vassal_contract_obligation_level:feudal_government_levies = feudal_levies_low_level
							vassal_contract_obligation_level:feudal_government_taxes = feudal_tax_low_level
						}
					}
					add = 40
				}
				else_if = {
					limit = {
						OR = {
							vassal_contract_obligation_level:feudal_government_levies = feudal_levies_exempt_level
							vassal_contract_obligation_level:feudal_government_taxes = feudal_tax_exempt_level
						}
					}
					add = 90
				}
				
				if = { # Certain AI's really do not want increased obligations
					limit = {
						OR = {
							has_trait = ambitious
							has_trait = arrogant
							ai_greed >= 50
						}
					}
					add = -50
				}
			}
		}

		item = { # Gold
			value = pay_homage_gold
			# Can afford gold homage
			is_valid = { gold >= medium_gold_value }
			current_description = pay_homage_gold_desc
			localization = pay_homage_decision_option_gold
			icon = "gfx/interface/icons/message_feed/money.dds"
			ai_chance = { # More likely if rich
				value = 50
				if = {
					limit = { short_term_gold > major_gold_value }
					add = 50
				}
				
				if = { # Certain AI's really do not want to part with gold
					limit = {
						ai_greed >= 50
					}
					add = -100
				}
			}
		}
	}

	effect = {
		set_variable = {
			name = homage_liege_scope
			value = liege
		}
		custom_tooltip = pay_homage_decision_effects
		custom_description_no_bullet = { text = pay_homage_gift_warning_effect }
		if = { # Gift
			limit = { scope:pay_homage_gold = yes }
			set_variable = {
				name = homage_type
				value = flag:homage_gold
			}
			# used for refunding if travel is canceled mid-way
			set_variable = {
				name = pay_homage_gold_value 
				value = medium_gold_value
			}
			custom_tooltip = pay_homage_decision_effects_gold
		}
		else_if = { # Hook
			limit = { scope:pay_homage_hook = yes }
			set_variable = {
				name = homage_type
				value = flag:homage_hook
			}
			custom_tooltip = pay_homage_decision_effects_hook
		}
		else_if = { # Contract
			limit = { scope:pay_homage_contract = yes }
			set_variable = {
				name = homage_type
				value = flag:homage_contract
			}
			if = {
				limit = {
					vassal_contract_obligation_level:feudal_government_levies < vassal_contract_obligation_level:feudal_government_taxes
					vassal_contract_obligation_level_can_be_increased = feudal_government_levies
				}
				custom_tooltip = pay_homage_decision_effects_contract_levies
			}
			else_if = {
				limit = {
					vassal_contract_obligation_level:feudal_government_taxes < vassal_contract_obligation_level:feudal_government_levies
					vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
				}
				custom_tooltip = pay_homage_decision_effects_contract_gold
			}
			else = {
				if = {
					limit = { vassal_contract_obligation_level_can_be_increased = feudal_government_taxes }
					custom_tooltip = pay_homage_decision_effects_contract_gold
				}
				else = { custom_tooltip = pay_homage_decision_effects_contract_gold }
			}
			hidden_effect = { set_subject_contract_modification_blocked = yes }
		}
		else = { # Submission
			set_variable = {
				name = homage_type
				value = flag:homage_submission
			}
		}
		show_as_tooltip = {
			switch = {
				trigger = has_trait
				shy = { add_stress = minor_stress_impact_gain }
				arrogant = { add_stress = minor_stress_impact_gain }
			}
		}
		save_scope_as = homage_vassal
		if = {
			limit = { exists = liege } # To stop errors
			liege = { save_scope_as = homage_liege }
		}
		start_travel_plan = {
			destination = liege.capital_province
			on_start_on_action = pay_homage_start
			on_travel_planner_cancel_on_action = pay_homage_travel_planner_exit
			on_arrival_event = pay_homage.9999
			on_arrival_destinations = all_but_last
		}
	}
	
	ai_potential = {
		is_at_war = no
	}

	ai_will_do = {
		base = 0
		modifier = {
			add = 50
			prestige > standard_activity_cost
		}
		modifier = { # AI's who can give gold are more likely
			add = 50
			gold >= medium_gold_value
			ai_greed < 50
			primary_title.tier > tier_county
		}
		modifier = {
			add = -50
			has_relation_rival = liege
		}
		modifier = {
			add = -25
			opinion = {
				target = liege
				value < 0
			}
		}
		modifier = { # Dukes/kings should be more weighted
			add = 25
			primary_title.tier >= tier_duchy
		}
		modifier = { # Barons should be less weighted
			add = -25
			primary_title.tier < tier_county
		}
	}
}
