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

# Written by Tobias Bodlund

namespace = CM

# Fall of the Kingdom of the Avars
narrative_event = {
	id = CM.501
	desc = EVTDESC_CM_501
	title = EVTTITLE_CM_501
	picture = GFX_evt_throne_room
	border = GFX_event_narrative_frame_war
	
	only_playable = yes

	major = yes
	
	trigger = {
		has_landed_title = k_hungary
		NOT = { culture = avar }
		NOT = { culture = hungarian }
		NOT = { has_global_flag = avar_khaganate_renamed }
	}

	major_trigger = {
		capital_scope = {
			NOT = {
				distance = {
					where = 522 # Pest
					value = 600	# Same part of the world
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		set_global_flag = avar_khaganate_renamed
	}
	
	option = {
		name = EVTOPTA_CM_501
		trigger = {
			has_landed_title = k_hungary
		}
		k_hungary = {
			set_name = "KINGDOM_PANNONIA"
			adjective = "KINGDOM_PANNONIA_ADJ"
		}
	}
	option = {
		name = EVTOPTB_CM_501
		trigger = {
			NOT = { has_landed_title = k_hungary }
			culture = avar
		}
	}
	option = {
		name = EVTOPTC_CM_501
		trigger = {
			NOT = { has_landed_title = k_hungary }
			NOT = { culture = avar }
		}
	}
}

# 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
		}
		hidden_effect = { #FIX
			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 = {
		NOT = {
			has_alternate_start_parameter = { key = religion_names value = random }
		}
		year = 800
		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
		if = {
			limit = { NOT = { has_dlc = "Holy Fury" } }
			enable_prepared_invasion = norse_pagan_reformed ## Important Viking age effect
		}
		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_central }
					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_central }
				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_central
					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 }
		}
	}
}
