# Written by Pedro Santos

namespace = LT


#############################################################
# Time of Anarchy - Stephen usurps the throne of England    #
#############################################################

# Henry I dies, this is an **on_death** fired event
character_event = {
	id = LT.21100

	is_triggered_only = yes
	hide_window = yes

	only_playable = yes
	religion_group = christian
	only_independent = yes
	only_capable = yes
	min_age = 16
	prisoner = no

	trigger ={
		has_character_flag = is_king_henry_I 
		is_landed = yes
		NOT = { 
			any_child = { 
				is_heir = yes
				is_female = no
			}
		}
		#FIX
		is_feudal = yes
		tier = KING
		has_landed_title = k_england
		has_landed_title = c_middlesex
		any_child = { has_character_flag = is_matilda_daughter_of_Henry_I }
		any_realm_character = { #FIX
			has_character_flag = is_stephen
			is_alive = yes
		}
		#
	}

	immediate = {
		save_event_target_as = dead_king_henry
		any_child = {
			limit = { has_character_flag = is_matilda_daughter_of_Henry_I } 

			add_claim=k_england
			save_event_target_as = matilda
		}
		any_realm_character = { #FIX
			limit = {
				has_character_flag = is_stephen
			}
			hidden_tooltip = { narrative_event = { id = LT.21110 days = 1 } }
		}
	}
	option = { 
		name = EVTOPTA_LT_21100
	}
}

# Stephen must decide either to support Matilda or usurp the Throne
narrative_event = {
	id = LT.21110
	title = EVTTITLE_LT_21110
	desc = EVTDESC_LT_21110
	picture = GFX_evt_rival_rulers
	border = GFX_event_narrative_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_character_flag = is_stephen
		#FIX
		OR = {
			is_ruler = no
			is_feudal = yes
		}
		event_target:dead_king_henry = {
			any_child = {
				has_character_flag = is_matilda_daughter_of_Henry_I
				has_landed_title = k_england
				has_landed_title = c_middlesex
			}
		}
		#
	}
	
	option = {
		name = EVTOPTA_LT_21110 #Support Matilda
		ai_chance = { factor = 20 }
		trigger = {
			FROM = {
				any_child = { has_character_flag = is_matilda_daughter_of_Henry_I }
			}
		}

		k_england = {
			set_title_flag = stephen_supported_matilda
		}

		event_target:matilda = {
			narrative_event = { id = LT.21120 days = 1 }
		}
	}

	option = {
		name = EVTOPTB_LT_21110 #Usurp the throne
		ai_chance = { factor = 80 }
		#FIX
		if = {
			limit = {
				OR = {
					is_ruler = no
					is_feudal = yes
				}
				event_target:matilda = {
					has_landed_title = k_england
					has_landed_title = c_middlesex
				}
			}
		#
			d_normandy = {
				if = {
					limit = { holder_scope = { character = event_target:matilda } }
					usurp_title_plus_barony_if_unlanded_and_vassals = ROOT
					event_target:matilda = { add_claim = d_normandy } #FIX
				}
			}
			d_york = {
				if = {
					limit = { holder_scope = { character = event_target:matilda } }
					usurp_title_plus_barony_if_unlanded_and_vassals = ROOT
					event_target:matilda = { add_claim = d_york } #FIX
				}
			}
			d_lancaster = {
				if = {
					limit = { holder_scope = { character = event_target:matilda } }
					usurp_title_plus_barony_if_unlanded_and_vassals = ROOT
					event_target:matilda = { add_claim = d_lancaster } #FIX
				}
			}
			vassalize_or_take_under_title = {
				title = k_england
				enemy = event_target:matilda
				#same_religion = yes # Only vassalize rulers of my religion
				#is_religious = yes
				type = host
			}
			k_england = { 
				usurp_title_plus_barony_if_unlanded_and_vassals = ROOT
				event_target:matilda = { add_claim = k_england } #FIX
			}
			c_middlesex = {
				#FIX
				if = {
					limit = { holder_scope = { character = event_target:matilda } }
					usurp_title_plus_barony_if_unlanded_and_vassals = ROOT
					event_target:matilda = { add_claim = c_middlesex }
				}
				if = {
					limit = { holder_scope = { character = ROOT } }
				#
					ROOT = { capital = PREV }
				} #FIX
			}
			c_cornwall = {
				if = {
					limit = { holder_scope = { character = event_target:matilda } }
					usurp_title_plus_barony_if_unlanded_and_vassals = ROOT
					event_target:matilda = { add_claim = c_cornwall } #FIX
				}
			}
			set_name = "" 
			culture = "norman"

			hidden_effect = {
				event_target:matilda = {					
					narrative_event = { id = LT.21130 days = 2 }
					spouse = { 
						narrative_event = { id = LT.21131 days = 2 }
						save_event_target_as = matilda_spouse
					}
				}

				k_scotland = {
					holder_scope = {
						save_event_target_as = king_of_scotland
						#narrative_event = { id = LT.21132 days = 10 }
					}
				}
	
				any_playable_ruler = {
					limit = { ai = no }
					#narrative_event = { id = LT.21133 days = 10 } 
				}	
			}
		} #FIX
	}
}


#Matilda receives the news that Stephen and the other nobles support her
narrative_event = {
	id = LT.21120
	title = EVTTITLE_LT_21110
	desc = EVTDESC_LT_21120
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_diplomacy
	
	is_triggered_only = yes

	trigger = {
		has_character_flag = is_matilda_daughter_of_Henry_I #FIX
	}
	
	option = {
		name = EVTOPTA_LT_21120 #Great!

		opinion = {
					who = FROM
					modifier = opinion_loyal_vassal
					years = 10
				}
		spouse = { save_event_target_as = matilda_spouse }
		hidden_tooltip = { #broadcasting the news to all players
			any_playable_ruler = {
				limit = { ai = no }
				narrative_event = { id = LT.21121 days = 1 } 
			}
		}	
	}
}

#News of Matilde ascension to the throne are broadcast
narrative_event = {
	id = LT.21121
	title = EVTTITLE_LT_21110
	#desc = EVTDESC_LT_21121 #FIX
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_diplomacy
	
	is_triggered_only = yes
	#FIX
	desc = {
		trigger = { event_target:matilda_spouse = { is_alive = yes } }
		text = EVTDESC_LT_21121
	}
	desc = {
		trigger = { NOT =  { event_target:matilda_spouse = { is_alive = yes } } }
		text = EVTDESC_LT_21121_NO_SPOUSE
	}
	trigger = {
		event_target:matilda = {
			is_alive = yes
			has_landed_title = k_england
			is_feudal = yes
		}
	}
	#
	option = {
		name = EVTOPTA_LT_21121 #interesting
	}
}

# Matilda receives news that Stephen usurped her throne
narrative_event = {
	id = LT.21130
	title = EVTTITLE_LT_21110
	desc = EVTDESC_LT_21130
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_diplomacy
	
	is_triggered_only = yes
	trigger = { FROM = { has_landed_title = k_england } } #FIX
	option = {
		name = EVTOPTA_LT_21130 #I will fight
	}
}


# Matilda's spouse receives news that Stephen usurped her throne
narrative_event = {
	id = LT.21131
	title = EVTTITLE_LT_21110
	desc = EVTDESC_LT_21131
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_diplomacy
	
	is_triggered_only = yes

	trigger = {
		#FIX
		event_target:matilda = {
			is_alive = yes
			spouse = { character = ROOT }
			has_claim = k_england
		}
		FROM = { has_landed_title = k_england }
		#
	}
	
	option = {
		name = EVTOPTA_LT_21131 #I will fight
		ai_chance = { factor = 80 }
		#FIX
		if = {
			limit = {
				FROM = { has_landed_title = k_england }
				event_target:matilda = {
					is_alive = yes
					spouse = { character = ROOT }
					has_claim = k_england
				}
			}
		#
			k_england = {
				show_scope_change = no
				reverse_unsafe_war = { #FIX
					target = event_target:matilda
					casus_belli = other_claim
					thirdparty = ROOT
				}
			}
		} #FIX
	}
	option = {
		name = EVTOPTB_LT_21131 # Not now
		ai_chance = { factor = 20 }
		prestige = -100
	}
}



