je_caladeran_war_of_independence_spain = {
	icon = "gfx/interface/icons/event_icons/event_military.dds"
	complete = {
		c:QUI = {
			is_subject = yes
			is_at_war = no
		}
	}
	
	fail = {
		c:QUI = {
			is_subject = no
			is_at_war = no
		}
	}

    on_complete = {
		trigger_event = { id = dvg_spain.2 }
	}
	
    on_fail = {
		trigger_event = { id = dvg_spain.3 }
	}
	
	weight = 100
	should_be_pinned_by_default = yes
}

je_reconquer_new_spain = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"
	complete = {
		custom_tooltip = {
			text = dvg_reconquer_new_spain_tt
			OR = {
				AND = {
					exists = c:UCA
					c:UCA = {
						is_subject_of = ROOT
					}
					exists = c:MEX
					c:MEX = {
						is_subject_of = ROOT
					}
					exists = c:LUS
					c:LUS = {
						is_subject_of = ROOT
					}
				}
				AND = {
					exists = c:GCO
					c:GCO = {
						is_subject_of = ROOT
					}
					NOT = {
						exists = c:LUS
					}
					NOT = {
						exists = c:UCA
					}
				}
				AND = {
					exists = c:UCA
					c:UCA = {
						is_subject_of = ROOT
					}
					exists = c:MEX
					c:MEX = {
						is_subject_of = ROOT
					}
					NOT = {
						exists = c:LUS
					}
				}
				AND = {
					exists = c:UCA
					c:UCA = {
						is_subject_of = ROOT
					}
					exists = c:GCO
					c:GCO = {
						is_subject_of = ROOT
					}
					NOT = {
						exists = c:LUS
					}
				}
			}
		}
	}
	

	on_complete = {
		trigger_event = { id = dvg_spain.4 }
	}

	weight = 100
	should_be_pinned_by_default = yes
}

je_rebuild_spain = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"
	complete = {
		AND = {
			NOT = {
				has_law = law_type:law_serfdom
				has_law = law_type:law_land_based_taxation
			}
		}
	}
	
	fail = {
		OR = {
			AND = {
				year > 1848
				NOT = {
					has_modifier = dvg_army_reform_spain
				}
			}
			year > 1860
		}
	}


	on_complete = {
		trigger_event = { id = dvg_spain.5 }
		remove_modifier = dvg_fallen_kingdom
	}
	
    on_fail = {
		trigger_event = { id = dvg_spain.6 }
	}

	weight = 100
	should_be_pinned_by_default = yes
}

je_a_new_empire_in_an_old_world = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"
	complete = {
		custom_tooltip = {
			text = a_new_empire_in_an_old_world_tooltip
			OR = {
				has_variable = dvg_spain_africa
				has_variable = dvg_spain_india
			}
		}
	}

	on_complete = {
		custom_tooltip = {
			text = a_new_empire_in_an_old_world_remove_modifier_tooltip
			remove_modifier = dvg_fallen_kingdom_less_bad
		}
	}

	weight = 100
	should_be_pinned_by_default = yes
}

je_spanish_africa = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"
	complete = {
		AND = {
			owns_entire_state_region = STATE_INNER_MOROCCO
			owns_entire_state_region = STATE_MARRAKECH
			owns_entire_state_region = STATE_AL_RIF
			owns_entire_state_region = STATE_FEZ
			owns_entire_state_region = STATE_LINDI
			owns_entire_state_region = STATE_ZANZIBAR
			owns_entire_state_region = STATE_TANGANYIKA
			owns_entire_state_region = STATE_KENYA
			owns_entire_state_region = STATE_RIFT_VALLEY
			owns_entire_state_region = STATE_UGANDA
		}
	}

	on_complete = {
		set_variable = dvg_spain_africa
	}

	weight = 100
	should_be_pinned_by_default = yes
}

je_spanish_india = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"
	complete = {
		AND = {
			owns_entire_state_region = STATE_PEGU
			owns_entire_state_region = STATE_BURMA
			owns_entire_state_region = STATE_SHAN_STATES
			owns_entire_state_region = STATE_KACHIN
			owns_entire_state_region = STATE_ASSAM
			owns_entire_state_region = STATE_NORTH_BENGAL
			owns_entire_state_region = STATE_SOUTH_BENGAL
		}
	}

	on_complete = {
		set_variable = dvg_spain_india
		trigger_event = { id = dvg_spain.11 }
	}

	weight = 100
	should_be_pinned_by_default = yes
}

#je_spanish_china = {
#	icon = "gfx/interface/icons/event_icons/event_map.dds"
#	complete = {
#		AND = {
#			owns_entire_state_region = STATE_GUANGDONG
#			owns_entire_state_region = STATE_SHAOZHOU
#			owns_entire_state_region = STATE_GUANGXI
#			owns_entire_state_region = STATE_FUJIAN
#			owns_entire_state_region = STATE_JIANGXI
#			owns_entire_state_region = STATE_ZHEJIANG
#			owns_entire_state_region = STATE_FORMOSA
#			owns_entire_state_region = STATE_SUZHOU
#			owns_entire_state_region = STATE_NANJING
#			owns_entire_state_region = STATE_SOUTHERN_ANHUI
#		}
#	}
#
#	on_complete = {
#		set_variable = dvg_spain_china
#		trigger_event = { id = dvg_spain.X }
#	}
#
#	weight = 100
#	should_be_pinned_by_default = yes
#}

#je_unify_iberia = {
#	icon = "gfx/interface/icons/event_icons/event_map.dds"
#	complete = {
#		AND = {
#			has_variable = spain_iberia
#			owns_entire_state_region = STATE_NAVARRA
#			owns_entire_state_region = STATE_ARAGON
#			owns_entire_state_region = STATE_CATALONIA
#			owns_entire_state_region = STATE_VALENCIA
#			owns_entire_state_region = STATE_BALEARES
#			owns_entire_state_region = STATE_SARDINIA
#			owns_entire_state_region = STATE_CORSICA
#			NOT = {
#				exists = c:ARN
#			}
#		}
#	}
#
#	on_complete = {
#		trigger_event = { id = dvg_spain.Y }
#	}
#
#	weight = 100
#	should_be_pinned_by_default = yes
#}

je_integrate_castille = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"

	is_shown_when_inactive = {
		c:SPA = root
	}

	possible = {
		has_technology_researched = pan-nationalism
		is_subject = no
	}

	complete = {
		AND = {
			has_law = law_type:law_national_supremacy
			custom_tooltip = {
				text = dvg_own_castille_tt
				owns_entire_state_region = STATE_TOLEDO
				owns_entire_state_region = STATE_CASTILE
				owns_entire_state_region = STATE_ASTURIAS
				owns_entire_state_region = STATE_CARTAGENA
				owns_entire_state_region = STATE_GRANADA
				owns_entire_state_region = STATE_BADAJOZ
				owns_entire_state_region = STATE_ANDALUSIA
			}
			cu:spanish = {
				culture_secession_progress = {
					target = ROOT
					value < 0.4
				}
			}
			custom_tooltip = {
				text = dvg_spain_castille_tt
				OR = {
					has_variable = dvg_spain_castille
					year > 1860
				}#temp hotfix
			}
		}
	}
	
	fail = {
#		NOT = {
#			custom_tooltip = {
#				text = dvg_no_castille_tt
#				owns_entire_state_region = STATE_TOLEDO
#				owns_entire_state_region = STATE_CASTILE
#				owns_entire_state_region = STATE_ASTURIAS
#				owns_entire_state_region = STATE_CARTAGENA
#				owns_entire_state_region = STATE_GRANADA
#				owns_entire_state_region = STATE_BADAJOZ
#				owns_entire_state_region = STATE_ANDALUSIA
#			}
#			c:SPA = {
#				is_at_war = yes
#			}
#		}
	}


	on_complete = {
		custom_tooltip = {
			text = dvg_spain_castille_integrated_tt
			if = {
				limit = { has_variable = dvg_spain_end_castillian_mega }
				trigger_event = { id = dvg_spain.20 }
			}
			if = {
				limit = {
					NOT = {
						has_variable = dvg_spain_end_castillian_mega
					}
				}
				trigger_event = { id = dvg_spain.12 }
			}
		}
	}
	
    on_fail = {
	}

	weight = 100
}

je_integrate_portugal = { #make decision instead.
	icon = "gfx/interface/icons/event_icons/event_map.dds"

	is_shown_when_inactive = {
		c:SPA = root
	}

	possible = {
		has_technology_researched = pan-nationalism
		is_subject = no
	}

	complete = {
		AND = {
			has_law = law_type:law_national_supremacy
			custom_tooltip = {
				text = dvg_own_galicia_tt
				owns_entire_state_region = STATE_ESTREMADURA
				owns_entire_state_region = STATE_BEIRA
				owns_entire_state_region = STATE_ALENTEJO
				owns_entire_state_region = STATE_GALICIA
			}
			cu:galician = {
				culture_secession_progress = {
					target = ROOT
					value < 0.4
				}
			}
			custom_tooltip = {
				text = dvg_spain_galicia_tt
				OR = {
					has_variable = dvg_spain_galicia
					year > 1860
				}#temp hotfix
			}
		}
	}
	
	fail = {
#		NOT = {
#			custom_tooltip = {
#				text = dvg_no_galicia_tt
#				owns_entire_state_region = STATE_ESTREMADURA
#				owns_entire_state_region = STATE_BEIRA
#				owns_entire_state_region = STATE_ALENTEJO
#				owns_entire_state_region = STATE_GALICIA
#				c:SPA = {
#					is_at_war = yes
#				}
#			}
#		}
	}


	on_complete = {
		trigger_event = { id = dvg_spain.14 }
	}
	
    on_fail = {
	}

	weight = 100
}

je_army_reform_spain = {
	icon = "gfx/interface/icons/event_icons/event_military.dds"
	complete = {
		AND = {
			NOT = {
				has_law = law_type:law_peasant_levies
				has_law = law_type:law_national_militia
			}
			has_technology_researched = napoleonic_warfare
		}
		custom_tooltip = {
			text = dvg_spain_no_irregularstt
			NOT = {
				any_scope_building = {
					is_building_type = building_barracks
					OR = {
						has_active_production_method = pm_irregular_infantry
						has_active_production_method = pm_no_artillery
						has_active_production_method = pm_cannon_artillery
					}
				}
			}
		}
	}
	
	fail = {
		year > 1850
	}


	on_complete = {
		trigger_event = { id = dvg_spain.8 }
	}
	
	on_fail = {
		trigger_event = { id = dvg_spain.9 }
	}
	

	weight = 100
	should_be_pinned_by_default = yes
}

je_castillian_tensions = {
	icon = "gfx/interface/icons/event_icons/event_skull.dds"

	complete = {
		year > 1860
		custom_tooltip = {
			text =  dvg_spain_tensions_low_tt
			scope:journal_entry = {
				is_goal_complete = no
			}
		}
	}

	fail = {
		OR = {
			AND = {
				year < 1860
				custom_tooltip = {
					text =  dvg_spain_tensions_high_tt
					scope:journal_entry = {
						is_goal_complete = yes
					}
					has_variable = dvg_spain_castille
				}
			}
		}
	}
	
	on_yearly_pulse = {
		random_events = {
			45 = 0
			25 = dvg_spain.19 #Dilemma, recognition of Castillian Spanish?
			15 = dvg_spain.21 #Dilemma, status of the Crown of Castile
			35 = dvg_spain.22 #Generic
			10 = dvg_spain.23 #Mateo
		}
	}

	on_complete = {
		trigger_event = {
			id = dvg_spain.15
		}
	}

	on_fail = {
		trigger_event = { id = dvg_spain.13 }
	}

	current_value = {
		value = var:dvg_castillian_tensions_var
	}

	goal_add_value = {
		add = 5
	}

	progressbar = yes

	weight = 1000
	should_be_pinned_by_default = yes
}

je_keep_castillian_tensions_low = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"

	complete = {
		year > 1860
	}

	fail = {
		AND = {
			custom_tooltip = {
				text =  dvg_spain_keep_tensions_low_tt
				any_scope_state = {
					state_region = s:STATE_CARTAGENA
					turmoil > 0.4
				}
				any_scope_state = {
					state_region = s:STATE_TOLEDO
					turmoil > 0.4
				}
				any_scope_state = {
					state_region = s:STATE_CASTILE
					turmoil > 0.4
				}
				any_scope_state = {
					state_region = s:STATE_GRANADA
					turmoil > 0.4
				}
				any_scope_state = {
					state_region = s:STATE_ANDALUSIA
					turmoil > 0.4
				}
				any_scope_state = {
					state_region = s:STATE_BADAJOZ
					turmoil > 0.4
				}
				any_scope_state = {
					state_region = s:STATE_ASTURIAS
					turmoil > 0.4
				}
			}
		}
	}

	on_complete = {
	}

	on_fail = {
		change_variable = {
			name = dvg_castillian_tensions_var
			add = 1
		}
	}

	weight = 100
	should_be_pinned_by_default = yes
}

#je_urbanize_castile = {
#	icon = "gfx/interface/icons/event_icons/event_skull.dds"
#
#	complete = {
#		year > 1860
#	}
#
#	fail = {
#		AND = {
#			any_scope_state = {
#				state_region = s:STATE_CARTAGENA
#				turmoil > 0.4
#			}
#			any_scope_state = {
#				state_region = s:STATE_TOLEDO
#				turmoil > 0.4
#			}
#			any_scope_state = {
#				state_region = s:STATE_CASTILE
#				turmoil > 0.4
#			}
#			any_scope_state = {
#				state_region = s:STATE_GRANADA
#				turmoil > 0.4
#			}
#			any_scope_state = {
#				state_region = s:STATE_ANDALUSIA
#				turmoil > 0.4
#			}
#			any_scope_state = {
#				state_region = s:STATE_BADAJOZ
#				turmoil > 0.4
#			}
#			any_scope_state = {
#				state_region = s:STATE_ASTURIAS
#				turmoil > 0.4
#			}
#		}
#	}
#
#	on_complete = {
#	}
#
#	on_fail = {
#		change_variable = {
#			name = dvg_castillian_tensions_var
#			add = 1
#		}
#	}
#
#	weight = 100
#	should_be_pinned_by_default = yes
#}