###########################################
#                                         #
# Horse Lords tournament events           #
# ID HL.7000-HL.7999                      #
#                                         #
###########################################

# Written by Tobias Bodlund

namespace = HL

# Invite warriors
character_event = {
	id = HL.7000
	desc = EVTDESC_HL_7000
	picture = GFX_evt_horsemanship
	border = GFX_event_normal_frame_war

	is_triggered_only = yes # hold_nomad_wargames, realm_decisions.txt

	option = {
		name = EVTOPTA_HL_7000

		custom_tooltip = {
			text = EVTTOOLTIP1_RoI_1000

			any_courtier_or_vassal = {
				limit = {
					block_general_event_trigger = no
					war = no

					trigger_if = {
						limit = { is_female = yes }
						has_character_flag = special_marshal
					}
				}

				letter_event = { id = HL.7001 }
			}

			any_close_relative = {
				limit = {
					block_general_event_trigger = no
					war = no
					NOT = { vassal_of = ROOT }

					trigger_if = {
						limit = { is_female = yes }
						has_character_flag = special_marshal
					}
				}

				letter_event = { id = HL.7001 }
			}
		}

		character_event = {
			id = HL.7020
			days = 20
		}
	}
}

# Warrior receives invitation
letter_event = {
	id = HL.7001
	desc = EVTDESC_HL_7001
	border = GFX_event_letter_frame_war

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HL_7001 # Accept invitation

		set_character_flag = do_not_disturb
		set_character_flag = attending_nomad_wargames

		character_event = {
			id = HL.7099 # Safety clearing of all flags and modifiers
			days = 60
		}

		ai_chance = { factor = 2 }
	}

	option = {
		name = EVTOPTB_RoI_1001 # Refuse invitation

		FROM = {
			show_scope_change = no

			opinion = {
				name = opinion_coward
				who = ROOT
				years = 2
			}

			letter_event = {
				id = HL.7002
				days = 3
				tooltip = EVTTOOLTIP1_RoI_2001
			}
		}

		ai_chance = {
			factor = 1

			trigger = {
				is_ruler = yes

				trigger_if = {
					limit = { is_nomadic = yes }

					opinion = {
						who = FROM
						value < 25
					}
				}
			}

			mult_modifier = {
				factor = 3

				combat_rating < 10
				is_nomadic = no
			}
		}
	}
}

# If warrior refuses to come
letter_event = {
	id = HL.7002
	desc = EVTDESC_HL_7002

	is_triggered_only = yes

	ai = no

	option = {
		name = I_SEE

		tooltip = {
			opinion = {
				name = opinion_coward
				who = FROM
				years = 2
			}
		}
	}
}

# Tournament begins - host
character_event = {
	id = HL.7020
	desc = EVTDESC_HL_7020
	picture = GFX_evt_horsemanship
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HL_7020

		character_event = {
			id = HL.7050 # Decide winner
			days = 5
		}

		character_event = {
			id = HL.7099 # Clearing all flags and modifiers after feast
			days = 30
		}

		any_realm_character = {
			limit = { has_character_flag = attending_nomad_wargames }

			character_event = { id = HL.7025 }

			character_event = {
				id = HL.7099 # Clearing all flags and modifiers after feast
				days = 30
			}
		}
	}
}

# Wargames begin - guest
character_event = {
	id = HL.7025
	desc = EVTDESC_HL_7025
	picture = GFX_evt_horsemanship
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_HL_7025
	}
}

# Wargames, decide winner
character_event = {
	id = HL.7050

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		random_realm_character = {
			limit = { has_character_flag = attending_nomad_wargames }

			preferred_limit = { combat_rating >= 130 }
			preferred_limit = { combat_rating >= 100 }
			preferred_limit = { combat_rating >=  70 }
			preferred_limit = { combat_rating >=  40 }
			preferred_limit = { combat_rating >=  10 }
			preferred_limit = { combat_rating >= -20 }
			preferred_limit = { combat_rating >= -50 }

			character_event = { id = HL.7055 } # Winner
		}
	}
}


# Wargames winner
character_event = {
	id = HL.7055
	desc = EVTDESC_HL_7055
	picture = GFX_evt_horsemanship
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HL_7055

		prestige = 200
		wealth = 30
		clr_character_flag = attending_nomad_wargames
		remove_do_not_disturb_effect = yes

		# Notify host and other participants about winner
		FROM = {
			character_event = { id = HL.7060 }

			any_realm_character = {
				limit = {
					has_character_flag = attending_nomad_tournament
					NOT = { character = ROOT }
				}

				character_event = { id = HL.7060 }
			}
		}
	}
}

# Notify host and other participants about winner
character_event = {
	id = HL.7060
	desc = EVTDESC_HL_7060
	picture = GFX_evt_horsemanship
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	immediate = {
		clr_character_flag = attending_nomad_wargames
		remove_do_not_disturb_effect = yes
	}

	option = {
		name = EVTOPTA_HL_7060

		tooltip = {
			FROM = {
				show_scope_change = no

				prestige = 200
				wealth = 30
			}
		}

		if = {
			limit = { has_character_modifier = holding_nomad_wargames }

			remove_character_modifier = holding_nomad_wargames

			add_character_modifier = {
				name = held_nomad_wargames
				years = 5
			}
		}
	}
}

# Clear all character flags and modifiers - safety catch
character_event = {
	id = HL.7099

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		remove_character_modifier = holding_nomad_wargames
		clr_character_flag = attending_nomad_wargames
		remove_do_not_disturb_effect = yes
	}
}