
###########################################
#                                         #
# Charlemagne Major Events                #             
#                                         #
# ID CM.500-CM.999                        #
#                                         #
###########################################

# Written by Tobias Bodlund

namespace = CM


# Fall of the Kingdom of the Lombards
narrative_event = {
	id = CM.502
	desc = EVTDESC_CM_502
	title = EVTTITLE_CM_502
	picture = GFX_evt_book_carolingian_script
	border = GFX_event_narrative_frame_war
	
	only_playable = yes
	has_global_flag = game_start_charlemagne

	major = yes
	
	trigger = {
		has_landed_title = k_italy
		NOT = { culture = lombard }
		NOT = { has_global_flag = fall_of_lombard_kingdom }
	}

	major_trigger = {
		capital_scope = {
			NOT = {
				distance = {
					where = 235 # Lombardy
					value = 800	# Same part of the world
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		set_global_flag = fall_of_lombard_kingdom
	}
	
	option = {
		name = EVTOPTA_CM_502
		trigger = {
			has_landed_title = k_italy
		}
		k_italy = {
			set_name = ""
			adjective = ""
			reset_coa = THIS
		}
	}
	option = {
		name = EVTOPTB_CM_502
		trigger = {
			NOT = { has_landed_title = k_italy }
			culture = lombard
		}
	}
	option = {
		name = EVTOPTC_CM_501
		trigger = {
			NOT = { has_landed_title = k_italy }
			NOT = { culture = lombard }
		}
	}
}

# Start of the Viking Age
narrative_event = {
	id = CM.503
	title = EVTTITLE_CM_503
	desc = EVTDESC_CM_503
	picture = GFX_evt_vikings_arriving_oldgods
	border = GFX_event_narrative_frame_war

	major = yes
	
	hide_from = yes
	
	only_playable = yes
	religion = catholic
	has_global_flag = game_start_charlemagne

	is_triggered_only = yes
	
	trigger = {
		year = 793
		NOT = { year = 867 }
		NOT = { has_global_flag = viking_age_started }
		controls_religion = yes # Let it happen for the Pope - he's always around
	}
	
	immediate = {
		set_global_flag = viking_age_started
		enable_prepared_invasion = norse_pagan
		enable_prepared_invasion = norse_pagan_reformed
		any_playable_ruler = {
			limit = { 
				liege = { character = PREV } #independent = yes and any_independent_ruler exclude revolts
				culture = norse
			}
			any_realm_province = {
				if = {
					limit = {
						port = yes
						culture = norse
					}
					change_tech = {
						technology = TECH_NAVAL
						value = 1
					}
				}
			}
			any_demesne_title = {
				if = {
					limit = {
						tier = BARON
						location = {
							port = yes
							culture = norse
						}
						owner = {
							is_feudal = yes
							culture = norse
						}
						NOT = { has_building = ca_shipyard_1 }
					}
					add_building = ca_shipyard_1
				}
				if = {
					limit = {
						tier = BARON
						location = {
							port = yes
							culture = norse
						}
						owner = {
							is_republic = yes
							culture = norse
						}
						NOT = { has_building = ct_shipyard_1 }
					}
					add_building = ct_shipyard_1
				}
				if = {
					limit = {
						tier = BARON
						location = {
							port = yes
							culture = norse
						}
						owner = {
							is_priest = yes
							culture = norse
						}
						NOT = { has_building = tp_shipyard_1 }
					}
					add_building = tp_shipyard_1
				}
				if = {
					limit = {
						tier = BARON
						location = {
							port = yes
							culture = norse
						}
						owner = {
							is_tribal = yes
							culture = norse
						}
						NOT = { has_building = tb_shipyard_1 }
					}
					add_building = tb_shipyard_1
				}
			}
			any_realm_lord = {
				any_demesne_title = {
					if = {
						limit = {
							tier = BARON
							location = {
								port = yes
								culture = norse
							}
							owner = {
								is_feudal = yes
								culture = norse
							}
							NOT = { has_building = ca_shipyard_1 }
						}
						add_building = ca_shipyard_1
					}
					if = {
						limit = {
							tier = BARON
							location = {
								port = yes
								culture = norse
							}
							owner = {
								is_republic = yes
								culture = norse
							}
							NOT = { has_building = ct_shipyard_1 }
						}
						add_building = ct_shipyard_1
					}
					if = {
						limit = {
							tier = BARON
							location = {
								port = yes
								culture = norse
							}
							owner = {
								is_priest = yes
								culture = norse
							}
							NOT = { has_building = tp_shipyard_1 }
						}
						add_building = tp_shipyard_1
					}
					if = {
						limit = {
							tier = BARON
							location = {
								port = yes
								culture = norse
							}
							owner = {
								is_tribal = yes
								culture = norse
							}
							NOT = { has_building = tb_shipyard_1 }
						}
						add_building = tb_shipyard_1
					}
				}
			}
		}
		any_playable_ruler = {
			limit = {
				ai = no
				capital_scope = {
					NOT = { region = world_india }
					NOT = { region = world_africa_west }
					NOT = { region = world_africa_east }
				}
			}
			chronicle = {
				entry = CHRONICLE_VIKING_AGE_BEGINS
				picture = GFX_evt_longships_at_sea_oldgods
			}
		}
	}

	option = {
		name = EVTOPTA_CM_503
		trigger = {
			NOT = { culture = norse }
			capital_scope = {
				NOT = { region = world_india }
				NOT = { region = world_africa_west }
				NOT = { region = world_africa_east }
			}
		}
		custom_tooltip = { text = viking_age_shipyards_and_tech_tooltip }
		custom_tooltip = { text = viking_age_cb_tooltip }
	}
	option = {
		name = EVTOPTB_CM_503
		trigger = {
			culture = norse
		}
		custom_tooltip = { text = viking_age_shipyards_and_tech_tooltip }
		custom_tooltip = { text = viking_age_cb_tooltip }
	}
	option = {
		name = EVTOPTC_CM_503
		trigger = {
			NOT = { culture = norse }
			capital_scope = {
				OR = {
					region = world_india
					region = world_africa_west
					region = world_africa_east
				}
			}
		}
		custom_tooltip = { text = viking_age_shipyards_and_tech_tooltip }
		custom_tooltip = { text = viking_age_cb_tooltip }
	}
}

# Notification of founding of the HRE
narrative_event = {
	id = CM.510
	title = EVTTITLE_CM_510
	desc = EVTDESC_CM_510
	picture = GFX_evt_found_hre

	major = yes
	
	is_triggered_only = yes
	
	major_trigger = {
		capital_scope = {
			e_hre = {
				holder_scope = {
					capital_scope = {
						NOT = {
							distance = {
								where = PREVPREVPREV
								distance = 1200
							}
						}
					}
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_CM_510
		trigger = {
			OR = {
				has_landed_title = e_hre
				AND = {
					dynasty = ROOT
					NOT = { is_rival = ROOT }
				}
			}
		}
	}
	option = {
		name = EVTOPTB_CM_510
		trigger = {
			NOT = { has_landed_title = e_hre }
			NOT = { has_landed_title = e_byzantium }
			OR = {
				NOT = { dynasty = ROOT }
				is_rival = ROOT
			}
			religion = ROOT
		}
	}
	option = {
		name = EVTOPTC_CM_510
		trigger = {
			NOT = { has_landed_title = e_byzantium }
			NOT = { religion = ROOT }
		}
	}
	option = {
		name = EVTOPTD_CM_510
		trigger = {
			has_landed_title = e_byzantium
			NOT = { has_landed_title = e_hre }
		}
	}
}
