namespace = HF

# Written by Joachim
# HF.49200 - HF.49299

### Clean up Events ###
# Clean up event post-Reconquista
character_event = {
	id = HF.49200
 	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
	
	}

	immediate = {
		clr_character_flag = currently_reconquering_mexico
		clr_global_flag = active_reconquista
		any_character = {
			limit = {
				has_character_flag = reconquista_beneficiary_flag
			}
			clr_character_flag = reconquista_beneficiary_flag
		}
		any_character = {
			limit = {
				has_character_flag = promised_reconquista_ally
			}
			clr_character_flag = promised_reconquista_ally
		}
		any_character = {
			limit = {
				has_character_flag = reconquista_adventurer
			}
			clr_character_flag = reconquista_adventurer
		}
		any_character = {
			limit = {
				has_character_flag = reconquista_sponsor
			}
			clr_character_flag = reconquista_sponsor
		}
		disband_event_forces = conscripted_reconquista_ships
		disband_event_forces = reconquista_event_troops_rabble
	}
}

# Clean up event for death in the Reconquista
character_event = {
	id = HF.49201
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		OR = {
			has_character_flag = currently_reconquering_mexico
			has_character_flag = ex_reconquistador
		}
	}

	immediate = {
		disband_event_forces = reconquista_event_troops
		disband_event_forces = reconquista_event_troops_rabble
		character_event = { id = HF.49200 }
	}
}

# Clean up event for religion conversion in the Reconquista
character_event = {
	id = HF.49202
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_character_flag = currently_reconquering_mexico
	}

	immediate = {
		disband_event_forces = reconquista_event_troops
		character_event = { id = HF.49200 }
	}
}

# Clean up event Reconquista Beneficiary dead
character_event = {
	id = HF.49203
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_character_flag = reconquista_beneficiary_flag
	}

	immediate = {
		clr_character_flag = reconquista_beneficiary_flag
	}
}

# Clean up event Reconquista Beneficiary religious conversion
character_event = {
	id = HF.49204
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_character_flag = reconquista_beneficiary_flag
		NOT = {
			religion_group = cult_of_saints
		}
	}

	immediate = {
		clr_character_flag = reconquista_beneficiary_flag
	}
}

# Clean up event Reconquista Beneficiary receive title
character_event = {
	id = HF.49205
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_character_flag = reconquista_beneficiary_flag
	}

	immediate = {
		clr_character_flag = reconquista_beneficiary_flag
	}
}

# Clean up event Reconquista Promised Ally religious conversion
character_event = {
	id = HF.49206
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_character_flag = promised_reconquista_ally
		NOT = {
			religion_group = cult_of_saints
		}
	}

	immediate = {
		clr_character_flag = promised_reconquista_ally
	}
}

# Clean up event if you don't wage a war in 2 years after starting preparations
character_event = {
	id = HF.49207
	desc = EVTDESC_HF_49207
	picture = GFX_evt_bad_news
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_character_modifier = reconquista_preparation_left
	}

	immediate = {
		if = {
			limit = {
				ai = no
			}
			remove_character_modifier = reconquista_preparation_left
			character_event = { id = HF.49200 }
			disband_event_forces = reconquista_event_troops
		}
		else = {
			set_character_flag = ai_reconquista_preparation_time_run_out
			character_event = { id = HF.49249 }
		}
	}

	option = {
		name = EVTOPTA_HF_49207
	}
}

# Clean up when an old ex-Reconquistador dies
character_event = {
	id = HF.49208
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_character_flag = ex_reconquistador
	}

	immediate = {
		disband_event_forces = reconquista_event_troops
		disband_event_forces = reconquista_event_troops_rabble
	}
}

### Allies Events ###
# Adding allies to the Reconquista
character_event = {
	id = HF.49210
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
	
	}

	immediate = {
		hidden_tooltip = {
			remove_character_modifier = reconquista_preparation_left
		}

		any_war = {
			limit = {
				OR = {
					using_cb = reconquista_jalisco
					using_cb = reconquista_michoacan
					using_cb = reconquista_mixteca
					using_cb = reconquista_oaxaca
					using_cb = reconquista_mexicoast
					using_cb = reconquista_mexico
					using_cb = reconquista_bajio
					using_cb = reconquista_chichimeca
					using_cb = reconquista_huasteca
				}
			}
			any_playable_ruler = {
				limit = {
					has_character_flag = promised_reconquista_ally
				}
				letter_event = { id = HF.49213 }
				join_attacker_wars = PREV
			}
		}
	}
}

# Sending letter about joining the Reconquista
character_event = {
	id = HF.49211
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
	
	}

	immediate = {
		FROM = {
			letter_event = { id = HF.49212 days = 3 }
		}
	}
}

# Receiving letter from ally joining the Reconquista
letter_event = {
	id = HF.49212
	desc = EVTDESC_HF_49212
	border = GFX_event_letter_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
	
	}

	immediate = {

	}

	option = {	
		name = EVTOPTA_HF_49212

		opinion = {
			name = opinion_grateful
			who = FROM
			years = 5
		}
	}
}

# Sending letters to promised allies, that the wars starts
letter_event = {
	id = HF.49213
	desc = EVTDESC_HF_49213
	is_triggered_only = yes
	trigger = {
		has_character_flag = promised_reconquista_ally
	}

	immediate = {
		clr_character_flag = promised_reconquista_ally
	}

	option = {
		name = EVTOPTA_HF_49213
	}
}

### Bloodline Events ###
# El Cid Bloodline
narrative_event = {
	id = HF.49220
	desc = EVTDESC_HF_49220
	title = EVTTITLE_HF_49220
	picture = GFX_evt_bloodlines
	border = GFX_event_narrative_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		NOT = {
			any_owned_bloodline = {
				has_bloodline_flag = reconquista_bloodline
				founder = {
					character = ROOT
				}
			}
		}
	}

	immediate = {

	}

	option = {	
		name = EVTOPTA_HF_49220

		if = {
			limit = {
				is_female = no
			}
			create_bloodline = {
				type = reconquista_cid_bloodline
			}
		}
		else = {
			create_bloodline = {
				type = reconquista_cid_bloodline
				inheritance = all_descendants
			}
		}
	}
}

# Reconquista Bloodline
narrative_event = {
	id = HF.49221
	desc = EVTDESC_HF_49221
	title = EVTTITLE_HF_49221 
	picture = GFX_evt_bloodlines
	border = GFX_event_narrative_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		NOT = {
			any_owned_bloodline = {
				has_bloodline_flag = reconquista_bloodline
				founder = {
					character = ROOT
				}
			}
		}
	}

	immediate = {

	}

	option = {	
		name = EVTOPTA_HF_49221
		#add_artifact = crown_wrapped_helmet
		if = {
			limit = {
				is_female = no
			}
			create_bloodline = {
				type = reconquista_bloodline
			}
		}
		else = {
			create_bloodline = {
				type = reconquista_bloodline
				inheritance = all_descendants
			}
		}
	}
}

### Mercenary Events ###
## Mercenary offering services ##
# Receive letter from Mercenary offering services against their own Religion
letter_event = {
	id = HF.49230
	desc = EVTDESC_HF_49230
	border = GFX_event_letter_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		reconquista_check_trigger = yes
	}

	option = {
		name = EVTOPTA_HF_49230

		if = {
			limit = {
				FROMFROM = {
					real_tier = COUNT
				}
			}
			transfer_scaled_wealth = { to = FROMFROM value = 0.25}
		}
		else_if = {
			limit = {
				FROMFROM = {
					real_tier = DUKE
				}
			}
			transfer_scaled_wealth = { to = FROMFROM value = 0.5 }
		}
		else_if = {
			limit = {
				FROMFROM = {
					real_tier = KING
				}
			}
			transfer_scaled_wealth = { to = FROMFROM value = 0.75 }
		}
		else_if = {
			limit = {
				FROMFROM = {
					real_tier = EMPEROR
				}
			}
			transfer_scaled_wealth = { to = FROMFROM value = 1 }
		}

		custom_tooltip = {
			text = join_reconquista_war_TT

			any_war = {
				limit = {
					OR = {
						using_cb = reconquista_jalisco
						using_cb = reconquista_michoacan
						using_cb = reconquista_mixteca
						using_cb = reconquista_oaxaca
						using_cb = reconquista_mexicoast
						using_cb = reconquista_mexico
						using_cb = reconquista_bajio
						using_cb = reconquista_chichimeca
						using_cb = reconquista_huasteca
					}
				}
				FROMFROM = {
					join_defender_wars = PREV
				}
				FROMFROM = {
					join_attacker_wars = PREV
				}
			}
		}

		FROMFROM = {
			letter_event = { id = HF.49231 days = 3 }
		}
	}

	option = {
		name = EVTOPTB_HF_49230 

		FROMFROM = {
			letter_event = { id = HF.49232 days = 3 }
		}
	}
}

# Mercenary receives letter agreeing to the terms
letter_event = {
	id = HF.49231
	desc = EVTDESC_HF_49231
	border = GFX_event_letter_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	option = {
		name = EVTOPTA_HF_49231
	}
}

# Mercenary receives letter rejecting the offer
letter_event = {
	id = HF.49232
	desc = EVTDESC_HF_49232
	border = GFX_event_letter_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	option = {
		name = EVTOPTA_HF_49232

		opinion = {
			modifier = insulted
			who = FROM
			years = 10
		}
	}
}

## Mercenary being offered a service ## 
# Receive letter from Lord/Lady about fighting their own religion
letter_event = {
	id = HF.49233
	desc = EVTDESC_HF_49233
	border = GFX_event_letter_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	option = {
		name = EVTOPTA_HF_49233

		if = {
			limit = {
				ROOT = {
					real_tier = COUNT
				}
			}
			transfer_scaled_wealth = { from = FROMFROM value = 0.25}
		}
		else_if = {
			limit = {
				ROOT = {
					real_tier = DUKE
				}
			}
			transfer_scaled_wealth = { from = FROMFROM value = 0.5 }
		}
		else_if = {
			limit = {
				ROOT = {
					real_tier = KING
				}
			}
			transfer_scaled_wealth = { from = FROMFROM value = 0.75 }
		}
		else_if = {
			limit = {
				ROOT = {
					real_tier = EMPEROR
				}
			}
			transfer_scaled_wealth = { from = FROMFROM value = 1 }
		}

		custom_tooltip = {
			text = join_reconquista_war_other_TT

			FROMFROM = {
				any_war = {
					limit = {
						OR = {
							using_cb = reconquista_jalisco
							using_cb = reconquista_michoacan
							using_cb = reconquista_mixteca
							using_cb = reconquista_oaxaca
							using_cb = reconquista_mexicoast
							using_cb = reconquista_mexico
							using_cb = reconquista_bajio
							using_cb = reconquista_chichimeca
							using_cb = reconquista_huasteca
						}
					}
					ROOT = {
						join_defender_wars = PREV
					}
					ROOT = {
						join_attacker_wars = PREV
					}
				}
			}
		}

		if = {
			limit = {
				trait = content
			}
			remove_trait = content
		}
		else_if = {
			limit = {
				NOT = {
					trait = ambitious
				}
			}
			add_trait = ambitious
		}
	}

	option = {
		name = EVTOPTB_HF_49233
	}
}

# Lord/Lady receives letter from Mercenary agreeing to the offer
letter_event = {
	id = HF.49234
	desc = EVTDESC_HF_49234
	border = GFX_event_letter_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	option = {
		name = EVTOPTA_HF_49234
	}
}

# Lord/Lady receives letter from Mercenary rejecting the offer
letter_event = {
	id = HF.49235
	desc = EVTDESC_HF_49235
	border = GFX_event_letter_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	option = {
		name = EVTOPTA_HF_49235
	}
}

## Monthly / Bi-monthly Reconquista Preparations Events ## 
# Tombola
character_event = {
	id = HF.49240
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_character_modifier = reconquista_preparation_duration
		not_reconquista_check_trigger = yes
		has_global_flag = active_reconquista
	}

	fail_trigger_effect = {
		character_event = { id = HF.49249 }
	}

	immediate = {
		random_list = {
			# Gain troops
			5 = {
				character_event = { id = HF.49241 }
			}
			#No Pope means you can't ask him for help.
			# Come across a great Commander to lead your troops
			2 = {
				trigger = {
					NOT = {
						has_character_modifier = reconquista_commander_event_cooldown
					}
				}
				character_event = { id = HF.49243 }
			}
			# Boats
			2 = {
				trigger = {
					NOT = {
						has_character_modifier = reconquista_boat_event_cooldown
					}
				}
				character_event = { id = HF.49244 }
			}
		}
	}

	after = {
		if = {
			limit = {
				has_character_flag = reconquista_adventurer
			}
			character_event = { id = HF.49240 days = 2 random = 5 }
		}
		else = {
			character_event = { id = HF.49240 days = 25 random = 20 }
		}
	}
}

# Reconquista Preparation Event - Gain troops
character_event = {
	id = HF.49241
	desc = EVTDESC_HF_49241
	picture = GFX_evt_large_army
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	# Invest some gold 
	option = {	
		name = EVTOPTA_HF_49241
		trigger = {
			NOT = {
				has_character_flag = reconquista_adventurer
			}
		}
		scaled_wealth = { value = -0.25 min = -25 max = -250 }
		custom_tooltip = {
			text = poorly_trained_troops_TT

			if = {
				limit = {
					NOT = {
						year = 900
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 300 300 }
						archers = { 100 100 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1000
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 400 400 }
						archers = { 150 150 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1100
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 500 500 }
						archers = { 200 200 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1200
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 600 600 }
						archers = { 250 250 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1300
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 700 700 }
						archers = { 300 300 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1400
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 800 800 }
						archers = { 350 350 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else = {
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 900 900 }
						archers = { 400 400 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
		}
	}
	# Invest quite a lot of gold
	option = {	
		name = EVTOPTB_HF_49241
		if = {
			limit = {
				NOT = {
					has_character_flag = reconquista_adventurer
				} 
			}
			scaled_wealth = { value = -0.5 min = -50 max = -500 }
		}
		custom_tooltip = {
			text = trained_troops_TT

			if = {
				limit = {
					NOT = {
						year = 900
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 300 300 }
						heavy_infantry = { 200 200 }
						archers = { 100 100 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1000
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 350 350 }
						heavy_infantry = { 250 250 }
						archers = { 150 150 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1100
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 400 400 }
						heavy_infantry = { 300 300 }
						archers = { 200 200 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1200
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 450 450 }
						heavy_infantry = { 350 350 }
						archers = { 250 250 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1300
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 500 500 }
						heavy_infantry = { 400 400 }
						archers = { 300 300 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1400
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 550 550 }
						heavy_infantry = { 450 450 }
						archers = { 350 350 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else = {
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 600 600 }
						heavy_infantry = { 500 500 }
						archers = { 400 400 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
		}
	}
	# Invest a crazy amount of gold
	option = {
		name = EVTOPTC_HF_49241
		trigger = {
			NOT = {
				has_character_flag = reconquista_adventurer
			} 
		}
		scaled_wealth = { value = -1 min = -100 max = -1000 }
		custom_tooltip = {
			text = well_trained_troops_TT

			if = {
				limit = {
					NOT = {
						year = 900
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						heavy_infantry = { 200 200 }
						pikemen = { 200 200 }
						light_cavalry = { 150 150 }
						archers = { 100 100 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1000
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						heavy_infantry = { 250 250 }
						pikemen = { 250 250 }
						light_cavalry = { 200 200 }
						archers = { 150 150 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1100
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						heavy_infantry = { 300 300 }
						pikemen = { 300 300 }
						light_cavalry = { 250 250 }
						archers = { 200 200 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1200
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						heavy_infantry = { 350 350 }
						pikemen = { 350 350 }
						light_cavalry = { 300 300 }
						archers = { 250 250 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1300
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						heavy_infantry = { 400 400 }
						pikemen = { 400 400 }
						light_cavalry = { 350 350 }
						archers = { 300 300 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1400
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						heavy_infantry = { 450 450 }
						pikemen = { 450 450 }
						light_cavalry = { 400 400 }
						archers = { 350 350 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else = {
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						heavy_infantry = { 500 500 }
						pikemen = { 500 500 }
						light_cavalry = { 450 450 }
						archers = { 400 400 }
					}
					earmark = reconquista_event_troops
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
		}
	}
	# Invest no gold and hope things work out
	option = {
		name = EVTOPTD_HF_49241
		trigger = {
			NOT = {
				has_character_flag = reconquista_adventurer
			}
		}
		prestige = -50
		custom_tooltip = {
			text = peasant_rabble_TT

			if = {
				limit = {
					NOT = {
						year = 900
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 300 300 }
					}
					earmark = reconquista_event_troops_rabble
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1000
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 400 400 }
					}
					earmark = reconquista_event_troops_rabble
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1100
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 500 500 }
					}
					earmark = reconquista_event_troops_rabble
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1200
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 600 600 }
					}
					earmark = reconquista_event_troops_rabble
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1300
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 700 700 }
					}
					earmark = reconquista_event_troops_rabble
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else_if = {
				limit = {
					NOT = {
						year = 1400
					}
				}
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 800 800 }
					}
					earmark = reconquista_event_troops_rabble
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
			else = {
				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = ROOT
					troops = {
						light_infantry = { 900 900 }
					}
					earmark = reconquista_event_troops_rabble
					attrition = 1
					maintenance_multiplier = 0
					reinforces = no
				}
			}
		}
	}
}

# Reconquista Preparation Event - Ask the Pope for aid (unused)

# Reconquista Preparation Event - Great Commander ahoy!
character_event = {
	id = HF.49243
	desc = EVTDESC_HF_49243
	picture = GFX_evt_dueling_knights_hf
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
	
	}

	immediate = {
		hidden_tooltip = {
			create_character = {
				dynasty = random
				culture = chilango
				religion = ROOT
				health = 5
				attributes = {
					martial = 4
					diplomacy = 0
					stewardship = 2
					intrigue = 0
					learning = 0
				}
			}

			new_character = {
				save_event_target_as = new_commander
				opinion = {
					modifier = opinion_loyal_servant
					who = ROOT
				}

				add_trait = brilliant_strategist
				# Randomize Culture
				random_list = {
					# Keep Chilango
					3 = {
					}
					# Other Mexican Cultures
					3 = {
						culture = jarocho
					}
					3 = {	
						culture = bravo
					}
					3 = {	
						culture = altiplanense
					}
					3 = {	
						culture = choyero
					}
					3 = {	
						culture = menomex
					}
					3 = {	
						culture = sonorense
					}
					3 = {
						culture = tapatio
					}
					3 = {
						culture = tejano
					}
					# Other close by cultures
					3 = {
						culture = chino
					}
					2 = {
						culture = sonorense
					}
					2 = {
						culture = neomexicano
					}
					2 = {
						culture = californiano
					}
					1 = {
						culture = cubano
					}
					1 = {
						culture = boricua
					}
					1 = {
						culture = texan
					}
					1 = {
						culture = deitsch
					}
				}
				# Some sort of huge
				random_list = {
					1 = {
						add_trait = strong
					}
					1 = {
						add_trait = robust
					}
				}
				# Some sort of lifestyle
				random_list = {
					1 = {
						add_trait = strategist
					}
					1 = {
						add_trait = duelist
					}
					1 = {
						add_trait = hunter
					}
				}
				# Some sort of good trait
				random_list = {
					1 = {
						add_trait = patient
					}
					1 = {
						add_trait = diligent 
					}
				}
				# Some sort of bad trait 
				random_list = {
					1 = {
						add_trait = proud
					}
					1 = {
						add_trait = envious
					}
				}
				# Some potential traits
				random = {
					chance = 40
					add_trait = ambitious
				}
				random = {
					chance = 40
					add_trait = brave
				}
				random = {
					chance = 40 
					add_trait = zealous
				}
				# One Commander trait 
				add_random_commander_trait_effect = yes
			}
		}
	}

	option = {	
		name = EVTOPTA_HF_49243
	}
	option = {	
		name = EVTOPTB_HF_49243

		trigger = {
			OR = { 
				NOT = { ROOT = { has_law = succ_byzantine_elective } } #Either not Imperial...
				NOT = { #...Or there are no valid vassal candidates that can be commanders.
					any_vassal = { 
						higher_real_tier_than = BARON
						NOT = { 
							primary_title = { temporary = yes } 
						}
						OR = {
							AND = {
								OR = {
									male_can_hold_minor_title_trigger = yes
									female_can_hold_minor_commander_title_trigger = yes
								}
								is_adult = yes
							}
							has_character_flag = special_marshal
						}
	
						prisoner = no
						NOT = { is_incapable = yes }
						NOT = { is_inaccessible_trigger = yes }
						NOT = { has_character_flag = guru }
						NOT = { has_character_modifier = refusing_to_lead }
						NOR = {
							has_job_title = job_chancellor
							has_job_title = job_marshal
							has_job_title = job_treasurer
							has_job_title = job_spymaster
							has_job_title = job_spiritual
							has_minor_title = title_commander
						}
					} 
				}
			}
			OR = {
				AND = {
					tier = COUNT
					NOT = {
						any_realm_character = {
							count = 2
							liege = { character = ROOT }
							has_minor_title = title_commander
						}
					}
				}
				AND = {
					tier = DUKE
					NOT = {
						any_realm_character = {
							count = 4
							liege = { character = ROOT }
							has_minor_title = title_commander
						}
					}
				}
				AND = {
					tier = KING
					is_nomadic = no
					NOT = {
						any_realm_character = {
							count = 6
							liege = { character = ROOT }
							has_minor_title = title_commander
						}
					}
				}
				AND = {
					tier = EMPEROR
					is_nomadic = no
					NOT = {
						any_realm_character = {
							count = 8
							liege = { character = ROOT }
							has_minor_title = title_commander
						}
					}
				}
				AND = {
					tier = KING
					is_nomadic = yes
					NOT = {
						any_realm_character = {
							count = 2
							liege = { character = ROOT }
							has_minor_title = title_commander
						}
					}
				}
				AND = {
					tier = EMPEROR
					is_nomadic = yes
					NOT = {
						any_realm_character = {
							count = 4
							liege = { character = ROOT }
							has_minor_title = title_commander
						}
					}
				}
			}
		}

		event_target:new_commander = {
			give_minor_title = title_commander
		}
	}
	option = {
		name = EVTOPTC_HF_49243 
		trigger = {
			NOT = {
				has_character_flag = reconquista_adventurer
			}
		}

		hidden_tooltip = {
			event_target:new_commander = { 
				death = {
					death_reason = death_missing
				}
			}
		}
	}

	after = {
		if = {
			limit = {
				has_character_flag = reconquista_adventurer
			}
			add_character_modifier = {
				name = reconquista_commander_event_cooldown
				hidden = yes
				days = 15
			}
		}
		else = {
			add_character_modifier = {
			name = reconquista_commander_event_cooldown
				hidden = yes
				months = 4
			}
		}
	}
}

# Reconquista Preparation Event - Boats!?
character_event = {
	id = HF.49244
	desc = EVTDESC_HF_49244
	picture = GFX_evt_ship_voyage_hf
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	option = {	
		name = EVTOPTA_HF_49244
		if = {
			limit = {
				NOT = {
					has_character_flag = reconquista_adventurer
				}
			}
			scaled_wealth = { value = -0.3 min = -30 max = -300 }
		}
		if = {
			limit = {
				NOT = {
					year = 850
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 10 10 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 950
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 20 20 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 1050
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 30 30 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year =1150
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 40 40 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 1250
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 50 50 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 1350
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 60 60 }
				}
			}
		}
		else = {
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 70 70 }
				}
			}
		}
	}
	option = {	
		name = EVTOPTB_HF_49244
		if = {
			limit = {
				NOT = {
					has_character_flag = reconquista_adventurer
				}
			}
			scaled_wealth = { value = -1 min = -100 max = -1000 }
		}
		prestige = 100
		if = {
			limit = {
				NOT = {
					year = 850
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 20 20 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 950
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 40 40 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 1050
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 60 60 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year =1150
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 80 80 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 1250
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 100 100 }
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					year = 1350
				}
			}
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 120 120 }
				}
			}
		}
		else = {
			spawn_fleet = {
				province = closest
				owner = ROOT
				earmark = conscripted_reconquista_ships
				troops = {
					galleys = { 140 140 }
				}
			}
		}
	}
	option = {
		name = EVTOPTC_HF_49244
		trigger = {
			NOT = {
				has_character_flag = reconquista_adventurer
			}
		}
	}

	after = {
		if = {
			limit = {
				has_character_flag = reconquista_adventurer
			}
			add_character_modifier = {
				name = reconquista_boat_event_cooldown
				hidden = yes
				months = 1
			}
		}
		else = {
			add_character_modifier = {
			name = reconquista_boat_event_cooldown
				hidden = yes
				months = 11
			}
		}
	}
}

# Reconquista Preparation Event - Preparations Finished
character_event = {
	id = HF.49249
	desc = EVTDESC_HF_49249
	picture = GFX_evt_mounted_knights_hf
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	trigger = {
		not_reconquista_check_trigger = yes
		has_global_flag = active_reconquista
	}

	option = {	
		name = EVTOPTA_HF_49249
	}

	after = {
		# Find suitable target for Reconquista Adventurers
		if = {
			limit = {
				OR = {
					has_character_flag = reconquista_adventurer
					has_character_flag = ai_reconquista_preparation_time_run_out
				}
			}
			hidden_tooltip = {
				# Chichimeca or Bajio is held by a Mesoamerican
				if = {
					limit = {
						any_province = {
							county = {
								OR = {
									region = custom_chichimeca
									region = custom_bajio
								}
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}	
							}
						}
					}
					random_list = {
						# Aragon
						1 = {
							trigger = {
								any_province = {
									county = {
										region = custom_chichimeca
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
							}
							random_province = {
								limit = {
									county = {
										region = custom_chichimeca
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
								owner = {
									if = {
										limit = {
											independent = yes
										}
										ROOT = {
											unsafe_war = {
												target = PREV
												casus_belli = reconquista_chichimeca
											}
										}
									}
									else = {
										top_liege = {
											ROOT = {
												unsafe_war = {
													target = PREV
													casus_belli = reconquista_chichimeca
												}
											}
										}
									}
								}
							}
						}
						# Navarra
						1 = {
							trigger = {
								any_province = {
									county = {
										region = custom_bajio
									}
									owner = {
										NOT = {
											religion_group = cult_of_saints
										}
										OR = {
											independent = yes
											NOT = {
												top_liege = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
							}
							random_province = {
								limit = {
									county = {
										region = custom_bajio
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
								owner = {
									if = {
										limit = {
											independent = yes
										}
										ROOT = {
											unsafe_war = {
												target = PREV
												casus_belli = reconquista_bajio
											}
										}
									}
									else = {
										top_liege = {
											ROOT = {
												unsafe_war = {
													target = PREV
													casus_belli = reconquista_bajio
												}
											}
										}
									}
								}
							}
						}
					}
				}
				# Kingdom of Mexico is held by a Mesoamerican
				else_if = {
					limit = {
						any_province = {
							county = {
								OR = {
									region = custom_mexicoast
									region = custom_mexico
									region = custom_huasteca
								}
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
					}
					random_list = {
						# Leon
						1 = {
							trigger = {
								any_province = {
									county = {
										region = custom_huasteca
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
							}
							random_province = {
								limit = {
									county = {
										region = custom_huasteca
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
								owner = {
									if = {
										limit = {
											independent = yes
										}
										ROOT = {
											unsafe_war = {
												target = PREV
												casus_belli = reconquista_huasteca
											}
										}
									}
									else = {
										top_liege = {
											ROOT = {
												unsafe_war = {
													target = PREV
													casus_belli = reconquista_huasteca
												}
											}
										}
									}
								}
							}
						}
						# Galicia
						1 = {
							trigger = {
								any_province = {
									county = {
										region = custom_mexicoast
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
							}
							random_province = {
								limit = {
									county = {
										region = custom_mexicoast
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
								owner = {
									if = {
										limit = {
											independent = yes
										}
										ROOT = {
											unsafe_war = {
												target = PREV
												casus_belli = reconquista_mexicoast
											}
										}
									}
									else = {
										top_liege = {
											ROOT = {
												unsafe_war = {
													target = PREV
													casus_belli = reconquista_mexicoast
												}
											}
										}
									}
								}
							}
						}
						# Castille
						1 = {
							trigger = {
								any_province = {
									county = {
										region = custom_mexico
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
							}
							random_province = {
								limit = {
									county = {
										region = custom_mexico
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
								owner = {
									if = {
										limit = {
											independent = yes
										}
										ROOT = {
											unsafe_war = {
												target = PREV
												casus_belli = reconquista_mexico
											}
										}
									}
									else = {
										top_liege = {
											ROOT = {
												unsafe_war = {
													target = PREV
													casus_belli = reconquista_mexico
												}
											}
										}
									}
								}
							}
						}
					}
				}
				# Jalisco or Colima is held by a Mesoamerican
				else_if = {
					limit = {
						any_province = {
							county = {
								region = custom_jalisco
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
					}
					random_list = {
						# Beja
						1 = {
							trigger = {
								any_province = {
									county = {
										region = custom_jalisco
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
							}
							random_province = {
								limit = {
									county = {
										region = custom_jalisco
									}
									owner = {
										OR = {
											AND = {
												independent = yes
												NOT = {
													religion_group = cult_of_saints
												}
											}
											top_liege = {
												NOT = {
													religion_group = cult_of_saints
												}
											}
										}
									}
								}
								owner = {
									if = {
										limit = {
											independent = yes
										}
										ROOT = {
											unsafe_war = {
												target = PREV
												casus_belli = reconquista_jalisco
											}
										}
									}
									else = {
										top_liege = {
											ROOT = {
												unsafe_war = {
													target = PREV
													casus_belli = reconquista_beja
												}
											}
										}
									}
								}
							}
						}
					}
				}
				# Michoacan is held by a Mesoamerican
				else_if = {
					limit = {
						any_province = {
							county = {
								region = custom_michoacan
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
					}
					random_province = {
						limit = {
							county = {
								region = custom_michoacan
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
						owner = {
							if = {
								limit = {
									independent = yes
								}
								ROOT = {
									unsafe_war = {
										target = PREV
										casus_belli = reconquista_michoacan
									}
								}
							}
							else = {
								top_liege = {
									ROOT = {
										unsafe_war = {
											target = PREV
											casus_belli = reconquista_michoacan
										}
									}
								}
							}
						}
					}
				}
				# Granada is held by a Mesoamerican
				else_if = {
					limit = {
						any_province = {
							county = {
								region = custom_mixteca
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
					}
					random_province = {
						limit = {
							county = {
								region = custom_mixteca
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
						owner = {
							if = {
								limit = {
									independent = yes
								}
								ROOT = {
									unsafe_war = {
										target = PREV
										casus_belli = reconquista_mixteca
									}
								}
							}
							else = {
								top_liege = {
									ROOT = {
										unsafe_war = {
											target = PREV
											casus_belli = reconquista_mixteca
										}
									}
								}
							}
						}
					}
				}
				# Oaxaca is held by a Mesoamerican
				else_if = {
					limit = {
						any_province = {
							county = {
								region = custom_oaxaca
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
					}
					random_province = {
						limit = {
							county = {
								region = custom_oaxaca
							}
							owner = {
								OR = {
									AND = {
										independent = yes
										NOT = {
											religion_group = cult_of_saints
										}
									}
									top_liege = {
										NOT = {
											religion_group = cult_of_saints
										}
									}
								}
							}
						}
						owner = {
							if = {
								limit = {
									independent = yes
								}
								ROOT = {
									unsafe_war = {
										target = PREV
										casus_belli = reconquista_oaxaca
									}
								}
							}
							else = {
								top_liege = {
									ROOT = {
										unsafe_war = {
											target = PREV
											casus_belli = reconquista_oaxaca
										}
									}
								}
							}
						}
					}
				}
				# End the Reconquista
				else = {
					primary_title = {
						destroy_landed_title = THIS
					}
					set_global_flag = reconquista_finished
					any_playable_ruler = {
						narrative_event = { id = HF.49452 }
					}
				}
			}
		}
		clr_character_flag = ai_reconquista_preparation_time_run_out
	}
}

## Reconquista Narrative Events ##
# A Mexican prepares Reconquista - Sent to all rulers in Mexico
narrative_event = {
	id = HF.49450
	desc = EVTDESC_HF_49450
	title = EVTTITLE_HF_49450
	picture = GFX_evt_large_army
	border = GFX_event_narrative_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		is_alternate_start = no
	}

	immediate = {

	}

	option = {
		name = EVTOPTA_HF_49450
		trigger = {
			religion_group = FROM
		}
	}

	option = {
		name = EVTOPTB_HF_49450
		trigger = {
			NOT = {
				religion_group = FROM
			}
		}
	}
}

# Empire of Mexico created
narrative_event = {
	id = HF.49451
	desc = EVTDESC_HF_49451
	title = EVTTITLE_HF_49451
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		is_alternate_start = no
		NOT = {
			has_global_flag = reconquista_finished
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = {
					has_global_flag = reconquista_finished
				}
			}
			set_global_flag = reconquista_finished
		}
	}

	option = {	
		name = EVTOPTA_HF_49451
		trigger = {
			religion_group = FROM
		}
	}

	option = {
		name = EVTOPTB_HF_49451
		trigger = {
			NOT = {
				religion_group = FROM
			}
		}
	}
}

# End of the Reconquista
narrative_event = {
	id = HF.49452
	desc = EVTDESC_HF_49452
	title = EVTTITLE_HF_49452
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		is_alternate_start = no
		NOT = {
			has_global_flag = reconquista_finished
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = {
					has_global_flag = reconquista_finished
				}
			}
			set_global_flag = reconquista_finished
		}
	}

	option = {	
		name = EVTOPTA_HF_49452
		trigger = {
			religion_group = cult_of_saints
		}
	}

	option = {
		name = EVTOPTB_HF_49451
		trigger = {
			NOT = {
				religion_group = cult_of_saints
			}
		}
	}
}

## Adventurer Reconquista ##
# Make a fitting adventurer
character_event = {
	id = HF.49460
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		has_game_rule = {
			name = reconquista
			value = on
		}
		war = no
		NOT = {
			has_global_flag = active_reconquista
		}
		any_demesne_title = {
			higher_tier_than = DUKE
			region = custom_empire_mexico
		}
		religion_group = cult_of_saints
		culture_group = mexicano
		NOT = {
			has_global_flag = reconquista_finished
		}
		OR = {
			AND = {
				random = 75
				any_province = {
					county = {
						OR = {
							region = custom_mexico
							region = custom_mexicoast
							region = custom_huasteca
							region = custom_jalisco
							region = custom_bajio
						}
					}
					owner = {
						OR = {
							AND = {
								independent = yes
								NOT = {
									religion_group = cult_of_saints
								}
							}
							top_liege = {
								NOT = {
									religion_group = cult_of_saints
								}
							}
						}
					}
				}
				tier = KING
			}
			AND = {
				random = 85
				any_province = {
					county = {
						OR = {
							region = custom_mexico
							region = custom_mexicoast
							region = custom_huasteca
							region = custom_jalisco
							region = custom_bajio
						}
					}
					owner = {
						OR = {
							AND = {
								independent = yes
								NOT = {
									religion_group = cult_of_saints
								}
							}
							top_liege = {
								NOT = {
									religion_group = cult_of_saints
								}
							}
						}
					}
				}
				tier = EMPEROR
			}
		}
		NOT = {
			has_character_modifier = reconquista_adventurer_cooldown
		}
	}

	immediate = {
		random_list = {
			1 = {
				create_character = {
					culture = ROOT
					religion = ROOT
					age = 24
					dynasty = random
					random_traits = yes
				}
			}
			1 = {
				create_character = {
					culture = ROOT
					religion = ROOT
					age = 24
					female = yes
					dynasty = random
					random_traits = yes
				}
			}
		}

		new_character = {
			wealth = 400 
			remove_trait = slow
			remove_trait = imbecile
			remove_trait = weak
			remove_trait = feeble
			random_list = {
				100 = {
					add_trait = genius
				}
				100 = {
					add_trait = shrewd
				}
				100 = {
					add_trait = quick
				}
				100 = {
					add_trait = strong
				}
				100 = {
					add_trait = robust
				}
				#1 = {
				#	trigger = { religion = sacred_heart }
 				#	add_artifact = crown_wrapped_helmet
				#}
			}
			add_random_commander_trait_effect = yes
			character_event = { id = HF.49461 }
		}
	}

	after = {
		set_global_flag = active_reconquista
		add_character_modifier = {
			name = reconquista_adventurer_cooldown
			hidden = yes
			years = 15
		}
	}
}

# Ping the adventurer 
character_event = {
	id = HF.49461
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	immediate = {
		set_character_flag = reconquista_adventurer
		FROM = {
			capital_scope = {
				save_event_target_as = host_capital
			}
		}

		create_title = {
			name = "RECONQUISTA_ADVENTURE_TITLE_NAME"
			adventurer = yes
			tier = DUKE
			landless = yes
			culture = ROOT
			holder = ROOT
		}
		spawn_unit = {
			owner = ROOT
			province = event_target:host_capital
			home = event_target:host_capital
			troops = {
				heavy_infantry = { 500 500 }
				pikemen = { 500 500 }
				light_cavalry = { 500 500 }
				archers = { 500 500 }
			}
			earmark = reconquista_event_troops
			attrition = 1
			maintenance_multiplier = 0
		}

		spawn_fleet = {
			province = closest
			owner = ROOT
			earmark = conscripted_reconquista_ships
			troops = {
				galleys = { 40 40 }
			}
		}

		if = {
			limit = {
				NOT = {
					has_character_flag = ex_reconquistador
				}
			}
			set_character_flag = ex_reconquistador
		}
		set_character_flag = currently_reconquering_mexico
		set_global_flag = active_reconquista

		add_character_modifier = {
			name = reconquista_preparation_duration
			hidden = yes
			months = 1
		}

		character_event = { id = HF.49240 days = 5 random = 5 }

		FROM = {
			letter_event = { id = HF.49462 }
		}
	}
}

# Letter event asking the ruler to back the adventurer's Reconquista campaign
character_event = {
	id = HF.49462
	desc = EVTDESC_HF_49462
	picture = GFX_evt_meeting_hf
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes
	has_dlc = "Holy Fury"

	option = {
		name = EVTOPTA_HF_49462
		piety = 50
		if = {
			limit = {
				NOT = {
					trait = ambitious
				}
			}
			add_trait = ambitious
		}
		set_character_flag = promised_reconquista_ally
		set_character_flag = reconquista_sponsor

		character_event = { id = HF.49463 days = 10 }
	}

	option = {
		name = EVTOPTB_HF_49462 
		trigger = {
			ai = no
		}
		piety = -50
	}
}

# Sponsor event
character_event = {
	id = HF.49463
	desc = EVTDESC_HF_49463
	picture = GFX_evt_council
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes
	trigger = {
		has_character_flag = reconquista_sponsor
	}

	immediate = {
		clr_character_flag = reconquista_sponsor
	}

	option = {	
		name = EVTOPTA_HF_49463
		trigger_switch = {
			on_trigger = tier
			baron = { prestige = -50 }
			count = { prestige = -100 }
			duke = { prestige = -200 }
			king = { prestige = -300 }
			emperor = { prestige = -500 }
		}
		custom_tooltip = {
			text = reconquista_renowned_sponsor_TT

			FROMFROM = {
				show_scope_change = no
				add_character_modifier = {
					name = renowned_sponsor
					years = 2
				}
			}
		}
	}
	option = {	
		name = EVTOPTB_HF_49463
		trigger_switch = {
			on_trigger = tier
			baron = { piety = -25 }
			count = { piety = -50 }
			duke = { piety = -100 }
			king = { piety = -200 }
			emperor = { piety = -300 }
		}
		custom_tooltip = {
			text = reconquista_pious_sponsor_TT

			FROMFROM = {
				show_scope_change = no
				add_character_modifier = {
					name = pious_sponsor
					years = 2
				}
			}
		}
	}
	option = {
		name = EVTOPTC_HF_49463
		scaled_wealth = { value = -1 min = -100 max = -1000 }
		custom_tooltip = {
			text = reconquista_wealthy_sponsor_TT

			FROMFROM = {
				show_scope_change = no
				add_character_modifier = {
					name = wealthy_sponsor
					years = 2
				}
			}
		}
	}
	option = {
		name = EVTOPTD_HF_49463
	}
}

## Flavour Events for Reconquista ##
# Tombola
character_event = {
	id = HF.49470
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	trigger = {
		religion_group = cult_of_saints
		location = {
			owner = {
				OR = {
					AND = {
						NOT = {
							religion_group = cult_of_saints
						}
						any_war = {
							OR = {
								using_cb = reconquista_jalisco
								using_cb = reconquista_michoacan
								using_cb = reconquista_mixteca
								using_cb = reconquista_oaxaca
								using_cb = reconquista_mexicoast
								using_cb = reconquista_mexico
								using_cb = reconquista_bajio
								using_cb = reconquista_chichimeca
								using_cb = reconquista_huasteca
							}
							any_defender = {
								character = PREVPREV
							}
						}
						independent = yes
					}
					top_liege = {
						NOT = {
							religion_group = cult_of_saints
						}
						any_war = {
							OR = {
								using_cb = reconquista_jalisco
								using_cb = reconquista_michoacan
								using_cb = reconquista_mixteca
								using_cb = reconquista_oaxaca
								using_cb = reconquista_mexicoast
								using_cb = reconquista_mexico
								using_cb = reconquista_bajio
								using_cb = reconquista_chichimeca
								using_cb = reconquista_huasteca
							}
							any_defender = {
								character = PREV
							}
						}
					}
				}
	
			}
		}
		any_war = {
			OR = {
				using_cb = reconquista_jalisco
				using_cb = reconquista_michoacan
				using_cb = reconquista_mixteca
				using_cb = reconquista_oaxaca
				using_cb = reconquista_mexicoast
				using_cb = reconquista_mexico
				using_cb = reconquista_bajio
				using_cb = reconquista_chichimeca
				using_cb = reconquista_huasteca
			}
			any_attacker = {
				character = ROOT
			}
		}
		prisoner = no
		age = 16
		in_command = yes
		NOT = {
			has_character_modifier = reconquista_flavor_cooldown
		}
	}

	immediate = {
		set_character_flag = reconquista_flavor
		crusade_flavor_event_tombola_effect = yes
	}

	after = {
		set_character_flag = reconquista_flavor
		add_character_modifier = {
			name = reconquista_flavor_cooldown
			hidden = yes
			days = 25
		}
	}
}

# Reconquista flavor event randomizer
character_event = {
	id = HF.49471
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	ai = no
	trigger = {
		any_war = {
			OR = {
				using_cb = reconquista_jalisco
				using_cb = reconquista_michoacan
				using_cb = reconquista_mixteca
				using_cb = reconquista_oaxaca
				using_cb = reconquista_mexicoast
				using_cb = reconquista_mexico
				using_cb = reconquista_bajio
				using_cb = reconquista_chichimeca
				using_cb = reconquista_huasteca
			}
			any_attacker = {
				character = ROOT
			}
		}
		religion_group = cult_of_saints
	}

	immediate = {
		random_list = {
			# Nothing happens
			3 = {}
			1 = {
				character_event = { id = HF.49470 days = 1 random = 15 }
			}
		}
	}
}

## Reconquista cooldown events for AI
# Cooldown timer
character_event = {
	id = HF.49480
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_global_flag = reconquista_ai_cooldown
		333 = {
			province_event = { id = HF.49481 }
		}
	}
}

# Ping province
province_event = {
	id = HF.49481
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		333 = {
			province_event = { id = HF.49482 days = 5475 }
		}
	}
}

# Cooldown finished
province_event = {
	id = HF.49482
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		clr_global_flag = reconquista_ai_cooldown
	}
}