# reconquista_aragon
# reconquista_balearic
# reconquista_beja
# reconquista_castille
# reconquista_cordoba
# reconquista_galicia
# reconquista_granada
# reconquista_leon
# reconquista_navarra
# reconquista_valencia


# All disabled in CK2Plus
### Reconquista Wars ###

# Aragon & Barcelona #
reconquista_aragon = {
	name = CB_NAME_RECONQUISTA_ARAGON
	war_name = WAR_NAME_RECONQUISTA_ARAGON
	diplo_view_region = custom_aragon
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CKPlus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_aragon
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_aragon
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_aragon
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_aragon
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			# Attacker
			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_aragon = { save_event_target_as = first_duchy_title }
		d_barcelona = { save_event_target_as = second_duchy_title }
		k_aragon = { save_event_target_as = reconquista_kingdom_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Balearic Islands #
reconquista_balearic = {
	name = CB_NAME_RECONQUISTA_BALEARIC
	war_name = WAR_NAME_RECONQUISTA_BALEARIC
	diplo_view_region = custom_balearic
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_balearic
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_balearic
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_balearic
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_balearic
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_mallorca = { save_event_target_as = first_duchy_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Beja & Algarve #
reconquista_beja = {
	name = CB_NAME_RECONQUISTA_BEJA
	war_name = WAR_NAME_RECONQUISTA_BEJA
	diplo_view_region = custom_beja
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_beja
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_beja
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_beja
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_beja
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			# Attacker
			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_beja = { save_event_target_as = first_duchy_title }
		d_algarve = { save_event_target_as = second_duchy_title }
		d_lisboa = { save_event_target_as = third_duchy_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Castille & Toledo #
reconquista_castille = {
	name = CB_NAME_RECONQUISTA_CASTILLE
	war_name = WAR_NAME_RECONQUISTA_CASTILLE
	diplo_view_region = custom_castille
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_castille
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_castille
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_castille
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_castille
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			# Attacker
			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_castilla = { save_event_target_as = first_duchy_title }
		d_toledo = { save_event_target_as = second_duchy_title }
		k_castille = { save_event_target_as = reconquista_kingdom_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Cordoba & Badajoz #
reconquista_cordoba = {
	name = CB_NAME_RECONQUISTA_CORDOBA
	war_name = WAR_NAME_RECONQUISTA_CORDOBA
	diplo_view_region = custom_cordoba
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_cordoba
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_cordoba
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_cordoba
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_cordoba
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_cordoba = { save_event_target_as = first_duchy_title }
		d_badajoz = { save_event_target_as = second_duchy_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Galicia & Porto #
reconquista_galicia = {
	name = CB_NAME_RECONQUISTA_GALICIA
	war_name = WAR_NAME_RECONQUISTA_GALICIA
	diplo_view_region = custom_galicia
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_galicia
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_galicia
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_galicia
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_galicia
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			# Attacker
			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_galicia = { save_event_target_as = first_duchy_title }
		d_portucale = { save_event_target_as = second_duchy_title }

		if = {
			limit = {
				k_galicia = {
					is_titular = no
				}
			}

			k_galicia = {
				save_event_target_as = reconquista_kingdom_title
			}
		}

		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Granada & Sevilla #
reconquista_granada = {
	name = CB_NAME_RECONQUISTA_GRANADA
	war_name = WAR_NAME_RECONQUISTA_GRANADA
	diplo_view_region = custom_granada
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_granada
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_granada
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_granada
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_granada
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_granada = { save_event_target_as = first_duchy_title }
		d_sevilla = { save_event_target_as = second_duchy_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Leon & Asturia #
reconquista_leon = {
	name = CB_NAME_RECONQUISTA_LEON
	war_name = WAR_NAME_RECONQUISTA_LEON
	diplo_view_region = custom_leon
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_leon
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_leon
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_leon
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_leon
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			# Attacker
			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_leon = { save_event_target_as = first_duchy_title }
		d_asturias = { save_event_target_as = second_duchy_title }

		if = {
			limit = {
				k_asturias = {
					is_titular = yes
				}
			}

			k_leon = {
				save_event_target_as = reconquista_kingdom_title
			}
		}
		else = {
			k_asturias = {
				save_event_target_as = reconquista_kingdom_title
			}
		}

		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}


# Navarra #
reconquista_navarra = {
	name = CB_NAME_RECONQUISTA_NAVARRA
	war_name = WAR_NAME_RECONQUISTA_NAVARRA
	diplo_view_region = custom_navarra
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_navarra
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_navarra
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_navarra
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_navarra
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_navarra = { save_event_target_as = first_duchy_title }
		k_navarra = { save_event_target_as = reconquista_kingdom_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Valencia & Murcia #
reconquista_valencia = {
	name = CB_NAME_RECONQUISTA_VALENCIA
	war_name = WAR_NAME_RECONQUISTA_VALENCIA
	diplo_view_region = custom_valencia
	sprite = 9
	truce_days = 3650
	battle_warscore_mult = 0.5
	# max_defender_occupation_score = 85
	sort_priority = 10000

	is_permanent = no # Disabled in CK2Plus
	is_holy_war = yes
	allow_whitepeace = no
	allowed_to_target_tributaries = yes
	can_ask_to_join_war = yes

	can_use_gui = {
		# Attacker
		ROOT = {
			prisoner = no
			is_adult = yes
		}
	}

	can_use = {
		always = no # Disabled in CK2Plus

		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
			not_reconquista_check_trigger = yes

			trigger_if = {
				limit = { ai = yes }
				NOT = { has_character_modifier = reconquista_preparation_duration }
			}

			any_realm_province = {
				held_under_PREV = yes

				trigger_if = {
					limit = {
						NOT = {
							any_neighbor_province = {
								region = custom_valencia
							}
						}
					}

					any_neighbor_province = {
						is_land = yes

						trigger_if = {
							limit = {
								any_neighbor_province = {
									region = custom_valencia
								}
							}

							NOT = {
								any_neighbor_province = {
									region = world_europe_west_iberia

									owner = {
										top_liege = {
											NOT = { religion_group = christian }
										}
									}
								}
							}
						}
						trigger_else = {
							any_neighbor_province = {
								is_land = yes

								any_neighbor_province = {
									region = custom_valencia
								}

								NOT = {
									any_neighbor_province = {
										region = world_europe_west_iberia

										owner = {
											top_liege = {
												NOT = { religion_group = christian }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		# Defender
		FROM = {
			any_realm_province = {
				region = custom_valencia
				held_under_PREV = yes
			}
		}
	}

	is_valid = {
		# Attacker
		ROOT = {
			has_character_flag = currently_reconquering_iberia
			NOT = { religion_group = FROM }
		}
	}

	on_add = {
		custom_tooltip = {
			text = add_allies_reconquista_TT

			attacker = {
				character_event = { id = HF.49210 } # Adding allies to the Reconquista
			}
		}
	}

	on_success = {
		d_valencia = { save_event_target_as = first_duchy_title }
		d_murcia = { save_event_target_as = second_duchy_title }
		reconquista_win_effect = yes
	}

	on_reverse_demand = {
		reconquista_lose_effect = yes
	}

	on_invalidation = {
		attacker = {
			character_event = { id = HF.49200 } # Clean up event post-Reconquista
		}
	}

	attacker_ai_victory_worth = {
		factor = -1
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 100
	}
}

