namespace = Plus

#reserved: Plus.2750 to Plus.2799

#######################################
# NORMAN EVENTS
# Written by Rylock
#######################################

# Check if Rollo exists in 876
character_event = {
	id = Plus.2750
	
	hide_window = yes
	religion = miaphysite
	
	only_rulers = yes
	
	trigger = {
		controls_religion = yes
		year = 875
		NOT = { year = 890 }
		d_normandy = {
			OR = {
				has_holder = no
				is_contested = no
			}
			NOT = { has_title_flag = rollo_invades_normandy }
		}
		c_arques = {
			is_contested = no
			holder_scope = {
				NOR = {
					war = yes
					culture = norse
					religion = norse_pagan
					in_revolt = yes
					top_liege = {
						OR = {
							war = yes
							culture = norse
							religion = norse_pagan
							has_any_opinion_modifier = opinion_targeted_by_adventurer
							in_revolt = yes
						}
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 6
		modifier = {
			factor = 2
			NOT = { year = 876 }
		}
		modifier = {
			factor = 0.5
			year = 880
		}
		modifier = {
			factor = 0.5
			year = 885
		}
	}
	
	immediate = {
		d_normandy = { set_title_flag = rollo_invades_normandy }
		random_independent_ruler = {
			limit = { any_realm_character = { has_character_flag = is_rollo } }
			random_realm_character = {
				limit = {
					has_character_flag = is_rollo
					is_ruler = no
					prisoner = no
					is_ill = no
					health = 4
					religion = norse_pagan
					culture = norse
					NOR = {
						trait = content
						trait = craven
						trait = humble
						trait = depressed
						trait = imbecile
						is_maimed_trigger = yes
						trait = incapable
						trait = celibate
						trait = blinded
						trait = eunuch
						is_weak_trigger = yes
						any_liege = { holy_order = yes }
						any_liege = { mercenary = yes }
						any_spouse = { is_ruler = yes }
						any_heir_title = { always = yes }
					}
				}
				character_event = { id = Plus.2751 } # start the adventure
				break = yes
			}
		}
		random_playable_ruler = {
			limit = {
				OR = {
					AND = {
						has_landed_title = c_trondelag
						culture = norse
					}
					AND = {
						c_trondelag = { holder_scope = { NOT = { culture = norse } } }
						culture = norse
						capital_scope = {
							region = custom_norway
							port = yes
						}
					}
				}
			}
			create_random_soldier = {
				name = "Rollo"
				random_traits = no
				dynasty = random
				religion = norse_pagan
				culture = norse
				female = no
				age = 30
				attributes = {
					martial = 7
					diplomacy = 6
					intrigue = 8
					stewardship = 7
					learning = 5
				}
				health = 7
				trait = lustful
				trait = proud
				trait = strong
				trait = brave
				trait = viking
				trait = brilliant_strategist
			}
			new_character = {
				set_character_flag = is_rollo
				add_character_modifier = { name = barren hidden = yes duration = -1 } #so he won't marry
				character_event = { id = Plus.2751 } # start the adventure
			}
		}
	}
}

# Rollo begins his adventure for Normandy
character_event = {
	id = Plus.2751
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		prestige = 250
		remove_do_not_disturb_effect = yes
		set_character_flag = no_invasions
		add_trait = ambitious
		add_trait = adventurer
		
		# come out of hiding if necessary
		end_inaccessibility_effect = yes
		
		if = {
			limit = {
				c_arques = {
					holder_scope = {
						OR = {
							ai = no
							any_liege = { ai = no }
						}
					}
				}
			}
			liege = {
				capital_scope = {
					save_event_target_as = spawn_province
				}
			}
		}
		if = {
			limit = {
				c_arques = {
					holder_scope = {
						NOR = {
							ai = no
							any_liege = { ai = no }
						}
					}
				}
			}
			c_arques = {
				location = { 
					save_event_target_as = spawn_province
				}
			}
		}
		liege = {
			capital_scope = {
				c_arques = {
					holder_scope = {
						top_liege = {
							log = "[Root.GetBestName] has started their adventure against [This.GetBestName] for the Duchy of Normandy"
							ROOT = {
								set_defacto_liege = ROOT
								create_title = {
									tier = DUKE
									landless = yes
									temporary = yes
									culture = ROOT
									name = "CLAIMANT_ADVENTURE"
									holder = ROOT
									ruler = "LORD"
									ruler_female = "LADY"
								}
								
								set_character_flag = duchy_adventurer
								
								spawn_unit = {
									province = event_target:spawn_province
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.7
									match_min = 1000
									match_max = 50000
									attrition = 0.25
									disband_on_peace = yes
									reinforces = yes
								}
								spawn_unit = {
									province = event_target:spawn_province
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.4
									match_min = 1000
									match_max = 50000
									attrition = 0.25
									disband_on_peace = yes
									reinforces = yes
								}
								spawn_unit = {
									province = event_target:spawn_province
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.2
									match_min = 1000
									match_max = 50000
									attrition = 0.25
									disband_on_peace = yes
									reinforces = yes
								}
								spawn_unit = {
									province = event_target:spawn_province
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.2
									match_min = 1000
									match_max = 50000
									attrition = 0.25
									disband_on_peace = yes
									reinforces = yes
								}
								spawn_fleet = {
									province = closest # closest sea zone
									owner = ROOT
									disband_on_peace = yes
									troops = {
										galleys = { 500 500 }
									}
								}
								
								war = {
									target = PREV
									casus_belli = duchy_adventure
									thirdparty_title = PREVPREVPREV
									tier = DUKE
									infamy = 0
								}
							}
						}
					}
				}
			}
		}
		character_event = { id = Plus.2760 } # Notification
		# create some decent commanders
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			trait = tough_soldier
			age = 30
		}		
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 20
		}
		create_random_diplomat = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
		}
		create_random_priest = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 35
		}
		create_random_intriguer = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
		}
	}
}

# Rollo is successful!
# Fired from the duchy_adventure CB
character_event = {
	id = Plus.2752
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		prestige = 500
		
		# set Arques as capital, if it's not
		if = {
			limit = { has_landed_title = c_arques }
			c_arques = { ROOT = { capital = PREV } }
		}
		
		# prevent uprisings for the next 20 years
		any_realm_province = {
			add_province_modifier = {
				name = recent_county_uprising
				duration = 7300
			}
		}
		
		capital_scope = {
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 1800 1800 }
						light_cavalry = { 540 540 }
						heavy_infantry = { 310 310 }
						knights = { 55 55 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = rollo_event_troops
				}
			}
		}
	}
}

# Rollo converts to Christianity on his own
character_event = {
	id = Plus.2753
	desc = EVTDESC_Plus_2753
	picture = GFX_evt_viking_throneroom_oldgods
	
	only_independent = yes
	religion = norse_pagan
	only_men = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	war = no
	
	trigger = {
		OR = {
			culture = norse
			culture = norman
		}
		higher_tier_than = BARON
		capital_scope = {
			duchy = { title = d_normandy }
		}
		NOR = {
			is_inaccessible_trigger = yes
			has_character_flag = converted_religion
			d_normandy = { has_title_flag = norman_conversion }
			year = 1066
		}
		is_not_busy_trigger = yes
	}
	
	mean_time_to_happen = {
		months = 200
		modifier = {
			factor = 0.5
			age = 40
		}
		modifier = {
			factor = 0.5
			age = 45
		}
		modifier = {
			factor = 0.25
			age = 50
		}
	}
	
	immediate = {
		d_normandy = { set_title_flag = norman_conversion }
	}
	
	option = {
		name = EVTOPTA_Plus_2753 #Convert
		piety = -100
		religion_authority = { modifier = ruler_converted_from }
		if = {
			limit = { k_papal_state = { has_title_flag = schism_happened } }
			religion = catholic
		}
		if = {
			limit = { k_papal_state = { NOT = { has_title_flag = schism_happened } } }
			religion = chalcedonian
		}
		if = {
			limit = { NOT = { culture = norman } }
			culture = norman
		}
		if = {
			limit = { has_character_flag = is_rollo }
			if = {
				limit = {
					ai = yes
					is_married = yes
				}
				any_spouse = { remove_spouse = ROOT }
			}
			if = {
				limit = {
					ai = no
					is_married = yes
				}
				hidden_tooltip = { remove_character_modifier = barren }
			}
			if = {
				limit = { is_married = no }
				hidden_tooltip = { character_event = { id = Plus.2758 days = 1 } }
			}
		}
		hidden_tooltip = {
			religion_authority = { modifier = ruler_converted_to }
			if = {
				limit = { capital_scope = { culture = frankish } }
				capital_scope = { culture = norman }
			}
			any_courtier = {
				limit = { religion = norse_pagan }
				religion = ROOT
			}
			any_courtier = {
				limit = { culture = norse }
				culture = norman
			}
		}
		set_character_flag = converted_religion
	}
	option = {
		name = EVTOPTB_Plus_2753 #Refuse
		trigger = { ai = no }
		piety = 100
		add_trait = zealous
	}
}
	
# Rollo offers to kneel before an attacking Christian king
character_event = {
	id = Plus.2754
	desc = EVTDESC_Plus_2754
	picture = GFX_evt_viking_battle_oldgods
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	only_independent = yes
	religion = norse_pagan
	only_men = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	war = yes

	trigger = {
		OR = {
			culture = norse
			culture = norman
		}
		num_of_count_titles = 1
		lower_tier_than = KING
		capital_scope = {
			duchy = { title = d_normandy }
		}
		OR = {
			any_war = {
				war_score = 25
				defender = { character = ROOT }
				attacker = {
					OR = {
						AND = {
							religion_group = christian
							higher_tier_than = DUKE
						}
						any_liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
				}
			}
			any_war = {
				NOT = { war_score = -25 }
				attacker = { character = ROOT }
				defender = {
					OR = {
						AND = {
							religion_group = christian
							higher_tier_than = DUKE
						}
						any_liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
				}
			}
		}
		NOR = {
			has_character_flag = converted_religion
			d_normandy = { has_title_flag = norman_conversion }
			year = 1066
		}
	}

	immediate = {
		d_normandy = { set_title_flag = norman_conversion }
		any_war = {
			limit = {
				war_score = 25
				defender = { character = ROOT }
				attacker = {
					OR = {
						AND = {
							religion_group = christian
							higher_tier_than = DUKE
						}
						any_liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
				}
			}
			attacker = {
				if = {
					limit = {
						religion_group = christian
						higher_tier_than = DUKE
					}
					save_event_target_as = christian_liege
					break = yes
				}
				if = {
					limit = {
						liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
					liege = { save_event_target_as = christian_liege }
					break = yes
				}
				if = {
					limit = {
						top_liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
					top_liege = { save_event_target_as = christian_liege }
					break = yes
				}
			}
		}
		any_war = {
			limit = {
				NOT = { war_score = -25 }
				attacker = { character = ROOT }
				defender = {
					OR = {
						AND = {
							religion_group = christian
							higher_tier_than = DUKE
						}
						any_liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
				}
			}
			defender = {
				if = {
					limit = {
						religion_group = christian
						higher_tier_than = DUKE
					}
					save_event_target_as = christian_liege
					break = yes
				}
				if = {
					limit = {
						liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
					liege = { save_event_target_as = christian_liege }
					break = yes
				}
				if = {
					limit = {
						top_liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
					top_liege = { save_event_target_as = christian_liege }
					break = yes
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2754 #Kneel
		prestige = -200
		event_target:christian_liege = {
			letter_event = { id = Plus.2755 tooltip = OFFER_TO_KNEEL }
		}
	}
	option = {
		name = EVTOPTB_Plus_2754 #Kneel
		trigger = { ai = no }
		if = {
			limit = { NOT = { trait = proud } }
			add_trait = proud
		}
		if = {
			limit = { NOT = { trait = brave } }
			add_trait = brave
		}
	}
}

# Christian king receives offer to kneel
letter_event = {
	id = Plus.2755
	border = GFX_event_letter_frame_war
	
	desc = {
		text = EVTDESC_Plus_2755
		trigger = { FROM = { prisoner = no } }
	}
	desc = {
		text = EVTDESC_Plus_2755_prisoner
		trigger = { FROM = { prisoner = yes } }
	}
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_2755 #Accept his offer
		piety = 100
		prestige = 250
		any_war = {
			limit = {
				OR = {
					AND = {
						attacker = { character = FROM }
						defender = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
					}
					AND = {
						defender = { character = FROM }
						attacker = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
					}
				}
			}
			end_war = invalid
		}
		FROM = {
			if = {
				limit = { prisoner = yes }
				prisoner = no
			}
			set_defacto_liege = ROOT
			remove_opinion = { who = ROOT modifier = declared_war }
			narrative_event = { id = Plus.2756 tooltip = DEFENDER_KNEELS }
		}
	}
	option = {
		name = EVTOPTB_Plus_2755 #Refuse
		trigger = { ai = no }
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.2757 } }
		}
	}
}

# Rollo's offer is accepted
narrative_event = {
	id = Plus.2756
	title = EVTNAME_Plus_2756
	desc = EVTDESC_Plus_2756
	picture = GFX_evt_knight_kneeling
	border = GFX_event_narrative_frame_war
	
	is_triggered_only = yes
	major = yes
	hide_from = yes
	show_ROOT = yes
	
	major_trigger = {
		OR = {
			character = FROM
			is_liege_or_above = FROM
			character = ROOT
			is_liege_or_above = ROOT
			capital_scope = {
				NOT = {
					distance = {
						where = 97 # Arques
						value = 400	# Same part of the world
					}
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2756
		trigger = { character = ROOT }
		opinion = { who = FROM modifier = force_vassalized multiplier = 2 years = 100 }
		remove_opinion = { who = FROM modifier = declared_war }
		piety = -100
		religion_authority = { modifier = ruler_converted_from }
		religion = FROM
		if = {
			limit = { NOT = { culture = norman } }
			culture = norman
		}
		if = {
			limit = { d_normandy = { has_holder = no } }
			d_normandy = { gain_title = ROOT }
		}
		set_defacto_liege = FROM
		if = {
			limit = { has_character_flag = is_rollo }
			if = {
				limit = {
					ai = yes
					is_married = yes
				}
				any_spouse = { remove_spouse = ROOT }
			}
			if = {
				limit = {
					ai = no
					is_married = yes
				}
				hidden_tooltip = { remove_character_modifier = barren }
			}
			if = {
				limit = { is_married = no }
				hidden_tooltip = { character_event = { id = Plus.2758 days = 1 } }
			}
		}
		hidden_tooltip = {
			disband_event_forces = rollo_event_troops
			capital_scope = {
				ROOT = {
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 1600 1600 }
							light_cavalry = { 540 540 }
							heavy_infantry = { 210 210 }
							knights = { 55 55 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
					}
				}
			}
			religion_authority = { modifier = ruler_converted_to }
			if = {
				limit = { capital_scope = { culture = frankish } }
				capital_scope = { culture = norman }
			}
			any_courtier = {
				limit = { religion = norse_pagan }
				religion = ROOT
			}
			any_courtier = {
				limit = { culture = norse }
				culture = norman
			}
		}
		set_character_flag = converted_religion
	}
	option = {
		name = EVTOPTB_Plus_2756
		trigger = { character = FROM }
	}
	option = {
		name = I_SEE
		trigger = {
			NOR = {
				character = ROOT
				character = FROM
			}
		}
	}
}

# Rollo's offer is refused
letter_event = {
	id = Plus.2757
	desc = EVTDESC_Plus_2757
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = CURSES
	}
}

# Rollo marries Poppa once he converts
character_event = {
	id = Plus.2758
	desc = EVTDESC_Plus_2758
	picture = GFX_evt_marriage
	
	is_triggered_only = yes
	
	option = {
		name = EXCELLENT
		hidden_tooltip = { remove_character_modifier = barren }
		set_name = "Robert"
		any_child_even_if_dead = {
 			limit = { dynasty = ROOT }
 			dynasty = 752
 			any_child_even_if_dead = {
 				limit = { dynasty = ROOT }
 				dynasty = 752
 				any_child_even_if_dead = {
 					limit = { dynasty = ROOT }
 					dynasty = 752
 				}
 			}
 		}
		dynasty = 752
		create_random_priest = {
			name = "Poppa"
			female = yes
			random_traits = no
			dynasty = 100097
			age = 19
			attributes = {
				martial = 7
				diplomacy = 7
				intrigue = 5
				stewardship = 7
			}
			health = 7
			religion = ROOT
			culture = frankish
			trait = scholarly_theologian
			trait = kind
			trait = chaste
			trait = content
			trait = humble
			trait = fertile
		}
		new_character = {
			add_spouse = ROOT
			add_lover = ROOT
			opinion = { modifier = opinion_forced_consort who = ROOT years = 10 }
			create_character = {
				name = "William"
				random_traits = yes
				female = no
				age = 0
				culture = ROOT
				religion = ROOT
				dynasty = ROOT
				health = 7
			}
			new_character = {
				set_mother = PREV
				set_father = ROOT
			}
		}
		recalc_succession = yes
	}
}

# Rollo is imprisoned by a Christian king and offers to kneel
character_event = {
	id = Plus.2759
	
	is_triggered_only = yes
	hide_window = yes
	
	
	only_independent = yes
	religion = norse_pagan
	only_men = yes
	min_age = 16
	capable_only = yes
	prisoner = yes
	ai = yes
	war = yes

	trigger = {
		OR = {
			culture = norse
			culture = norman
		}
		num_of_count_titles = 1
		lower_tier_than = KING
		capital_scope = {
			duchy = { title = d_normandy }
		}
		host = {
			OR = {
				war_with = ROOT
				any_liege = { war_with = ROOT }
			}
			OR = {
				AND = {
					religion_group = christian
					higher_tier_than = DUKE
				}
				any_liege = {
					religion_group = christian
					higher_tier_than = DUKE
				}
			}
		}
		NOR = {
			has_character_flag = converted_religion
			d_normandy = { has_title_flag = norman_conversion }
			year = 1066
		}
	}
	
	immediate = {
		host = {
			if = {
				limit = {
					religion_group = christian
					higher_tier_than = DUKE
				}
				d_normandy = { set_title_flag = norman_conversion }
				letter_event = { id = Plus.2755 }
				break = yes
			}
			if = {
				limit = { ai = no }
				break = yes
			}
			if = {
				limit = {
					liege = {
						religion_group = christian
						higher_tier_than = DUKE
					}
				}
				d_normandy = { set_title_flag = norman_conversion }
				liege = { letter_event = { id = Plus.2755 } }
				break = yes
			}
			if = {
				limit = {
					liege = {
						liege = {
							religion_group = christian
							higher_tier_than = DUKE
						}
					}
				}
				d_normandy = { set_title_flag = norman_conversion }
				liege = { liege = { letter_event = { id = Plus.2755 } } }
				break = yes
			}
			if = {
				limit = {
					liege = {
						liege = {
							liege = {
								religion_group = christian
								higher_tier_than = DUKE
							}
						}
					}
				}
				d_normandy = { set_title_flag = norman_conversion }
				liege = { liege = { liege = { letter_event = { id = Plus.2755 } } } }
				break = yes
			}
			if = {
				limit = {
					top_liege = {
						religion_group = christian
						higher_tier_than = DUKE
					}
				}
				d_normandy = { set_title_flag = norman_conversion }
				top_liege = { letter_event = { id = Plus.2755 } }
				break = yes
			}
		}
	}
}

# Notification of Rollo's attack
character_event = {
	id = Plus.2760
	title = EVTNAME_Plus_2751
	picture = GFX_evt_viking_battle_oldgods
	border = GFX_event_normal_frame_war
	
	desc = {
		text = EVTDESC_Plus_2751
		trigger = {
			ROOT = { NOT = { has_landed_title = c_arques } }
		}
	}
	desc = {
		text = EVTDESC_Plus_2751_immediate
		trigger = {
			ROOT = { has_landed_title = c_arques }
		}
	}
	
	is_triggered_only = yes
	major = yes
	hide_from = yes
	show_ROOT = yes
	
	major_trigger = {
		OR = {
			culture = norse
			religion = norse_pagan
			has_landed_title = c_arques
			top_liege = { any_realm_lord = { has_landed_title = c_arques } }
			capital_scope = {
				NOT = {
					distance = {
						where = 97 # Arques
						value = 400	# Same part of the world
					}
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2751
		trigger = {
			OR = {
				culture = norse
				religion = norse_pagan
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_2751
		trigger = {
			OR = {
				top_liege = { any_realm_lord = { has_landed_title = c_arques } }
				has_landed_title = c_arques
			}
			NOR = {
				culture = norse
				religion = norse_pagan
			}
		}
	}
	option = {
		name = I_SEE
		trigger = {
			NOR = {
				culture = norse
				religion = norse_pagan
				has_landed_title = c_arques
				top_liege = { any_realm_lord = { has_landed_title = c_arques } }
			}
		}
	}	
}

