﻿namespace = balkan_culture


# Event to spawn Bosnian dynamically after the Kingdom has been formed
# balkan_culture.0001-0009													

balkan_culture.0001 = {
	scope = none
	hidden = yes

	immediate = {
		
		#Bosnian gets the innovations from Croatian and Serbian
		culture:bosnian = {
			reset_culture_creation_date = yes
			get_all_innovations_from = culture:croatian
			get_all_innovations_from = culture:slavonian
			get_all_innovations_from = culture:serbian

		}

		every_county = {
			limit = {
				culture = { has_cultural_pillar = heritage_south_slavic }
				title_province = {	
					geographical_region = custom_roman_illyricum
				}
			}
			add_to_list = bosnian_counties
		}

		every_in_list = {
			list = bosnian_counties

			# South Slavic Counties become Bosnian
			if = {
				limit = {
					culture = { has_cultural_pillar = heritage_south_slavic }
					county = {	
						OR = {
							this = title:c_usora
							this = title:c_soli
							this = title:c_vhrbosna
							this = title:c_donjikraji
							this = title:c_rama
						}
					}
				}
				set_county_culture = culture:bosnian

				# Croatian and Serbian Rulers switch culture; every courtier that is South Slavic flips along
				holder = {
					if = {
						limit = {
							culture = { has_cultural_pillar = heritage_south_slavic }
							capital_province = {
								geographical_region = ghw_region_balkans
							}
						}
						set_culture = culture:bosnian
						every_courtier = {
							limit = {
								culture = { has_cultural_pillar = heritage_south_slavic }
							}
							set_culture = culture:bosnian
						}
					}
				}
			}
		}

		every_player = {
			if = {
				limit = {
					is_ai = no
					save_temporary_scope_as = player
					any_in_list = {
						list = bosnian_counties
						holder = {
							is_within_diplo_range = { CHARACTER = scope:player }
						}
					}
				}
				trigger_event = balkan_culture.0002
			}
		}

	}

}

# Informative Event of the Shift
balkan_culture.0002 = {
	type = character_event
	title = balkan_culture.0002.t
	desc = balkan_culture.0002.desc
	theme = culture_change
	left_portrait = root

	option = {
		name = balkan_culture.0002.a
	}
	
}

balkan_culture.0003 = {
 	scope = none
 	hidden = yes

 	immediate = {

 		every_county = {
 			limit = {
 				culture = culture:abotrite
				title_province = {
					OR = {
						geographical_region = custom_hungary
						geographical_region = ghw_region_balkans
					}
				}
 			}
 			add_to_list = abotrite_counties
 		}
		
 		title:c_severin = {
			if = {
				limit = {
					culture = culture:severian
					holder = { NOT = { culture = culture:severian } }
				}
				set_county_culture = culture:vlach
				set_county_faith = faith:orthodox
			}
 		}
		
		title:c_visegrad = {
			if = {
				limit = {
					holder = { culture = culture:mogyer }
				}
				set_county_culture = culture:mogyer
				set_county_faith = faith:magyar_pagan
				change_development_level = -2
			}
 		}

 		every_in_list = {
 			list = abotrite_counties
			
 			if = {
 				limit = {
 					culture = culture:abotrite
 					county = {	
 						this = title:c_krasso
 					}
					holder = { NOT = { culture = culture:abotrite } }
 				}
 				set_county_culture = culture:vlach
				set_county_faith = faith:orthodox
 			}
			
			if = {
 				limit = {
 					culture = culture:abotrite
 					county = {	
 						this = title:c_szerem
 					}
					holder = { NOT = { culture = culture:abotrite } }
 				}
 				set_county_culture = culture:serbian
 			}
			
			if = {
 				limit = {
					holder = { culture = culture:mogyer }
 					culture = culture:abotrite
 				}
 				set_county_culture = culture:mogyer
				set_county_faith = faith:magyar_pagan
 			}
			
			else = {
				limit = {
 					culture = culture:abotrite
 				}
				set_county_culture = culture:serbian
			}
			
 		}

 	}

}

#I united the Illyrians
balkan_culture.0004 = {
	type = character_event
	title = balkan_culture.0004.t
	desc = balkan_culture.0004.desc
	theme = realm
	left_portrait = {
		character = root
		animation = personality_honorable
	}

	immediate = {
		
		hidden_effect = {
		
			#Illyrian gets the innovations from all Western South Slavic Cultures
		
			culture:illyrian_slavic = {
				reset_culture_creation_date = yes
				get_all_innovations_from = culture:carantanian
				get_all_innovations_from = culture:dudlebian
				get_all_innovations_from = culture:blatno_slavic
				get_all_innovations_from = culture:slavonian
				get_all_innovations_from = culture:pannonian
				get_all_innovations_from = culture:croatian
				get_all_innovations_from = culture:neretljanian
				get_all_innovations_from = culture:zachlumian
				get_all_innovations_from = culture:travunian
				get_all_innovations_from = culture:doclean
				get_all_innovations_from = culture:serbian
				get_all_innovations_from = culture:branichian
				get_all_innovations_from = culture:abotrite
			}

			every_county = {
				limit = {
					OR = {
						culture = culture:carantanian
						culture = culture:dudlebian
						culture = culture:blatno_slavic
						culture = culture:slavonian
						culture = culture:pannonian
						culture = culture:croatian
						culture = culture:neretljanian
						culture = culture:zachlumian
						culture = culture:travunian
						culture = culture:doclean
						culture = culture:serbian
						culture = culture:branichian
						culture = culture:abotrite
					}
					title_province = {	
						geographical_region = ce_custom_serbo_croatia
					}
				}
				add_to_list = illyrian_counties
			}

			every_in_list = {
				list = illyrian_counties

				# South Slavs become Illyrian
				if = {	
					limit = {
						OR = {
							culture = { has_cultural_pillar = heritage_south_slavic }
							target_is_de_facto_liege_or_above = root.primary_title
						}
						title_province = {	
							geographical_region = ce_custom_serbo_croatia
						}
					}
					random = {
						chance = 40
						set_county_culture = culture:illyrian_slavic
					}
				}

				# Characters flip along
				holder = {
					if = {
						limit = {
							culture = { has_cultural_pillar = heritage_south_slavic }
							NOT = { culture = culture:bulgarian }
						}
						set_culture = culture:illyrian_slavic
						every_courtier = {
							limit = {
								culture = { has_cultural_pillar = heritage_south_slavic }
								NOT = { culture = culture:bulgarian }
							}
							set_culture = culture:illyrian_slavic
						}
					}
					else = {
						limit = {
							culture = { has_cultural_pillar = heritage_south_slavic }
							capital_province = {
								geographical_region = custom_roman_illyricum
							}
						}
						set_culture = culture:illyrian_slavic
					}
				}
			}	
			add_character_flag = converted_culture_this_lifetime
			play_music_cue = "mx_cue_epic_sacral_moment"
		}
	}
	
	option = {
		name = balkan_culture.0004.a
	}
}

scripted_trigger illyrian_culture_shift_trigger = {
	tier = tier_county
	exists = holder
	title_province = {
		geographical_region = ce_custom_illyria
	}
	NOT = { exists = var:had_illyrian_county_conversion }
	NOT = { culture = holder.culture }
	culture = {
		NOR = {
			this = culture:illyrian_slavic
			any_parent_culture_or_above = {
				this = culture:illyrian_slavic
			}
		}
		has_cultural_pillar = heritage_south_slavic
	}
	any_neighboring_county = {
		culture = culture:illyrian_slavic
	}
}

#Spread of Illyrian
balkan_culture.0005 = {
	scope = none
	hidden = yes
	
	trigger = {
		culture = culture:illyrian_slavic
		any_held_title = {
			illyrian_culture_shift_trigger = yes
		}
	}

	immediate = {
		random_held_title = {
			limit = { illyrian_culture_shift_trigger = yes }
			set_variable = {
				name = had_illyrian_county_conversion
				value = yes
			}
			set_county_culture = culture:illyrian_slavic
		}
	}
}


####PANNONIAN FLAVOUR####

#Dunavian Kingdom
balkan_culture.0006 = {
	type = character_event
	title = balkan_culture.0006.t
	desc = balkan_culture.0006.desc
	theme = realm
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	
	option = { # We are the true heirs of Pannonia!
		name = balkan_culture.0006.a
		trigger = {
			OR = {
				AND = {
					has_title = title:d_szekesfehervar
					has_title = title:d_gyor
					has_title = title:d_somogy
					has_title = title:d_slavonia
					has_title = title:d_syrmia
				}
				completely_controls_region = ce_custom_roman_pannonia
			}
		}
		
		hidden_effect = {
		
			culture:pannonian = {
				get_all_innovations_from = culture:slavonian
				get_all_innovations_from = culture:abotrite
				reset_culture_creation_date = yes
				set_culture_name = {
                    noun = n_pannonian_noun
                    collective_noun = n_pannonian_collective_noun
                    prefix = n_pannonian_prefix
                }
			}
			
			culture:pannonian_romance = {
				set_culture_name = {
                    noun = n_pannonian_romance_noun
                    collective_noun = n_pannonian_romance_collective_noun
                    prefix = n_pannonian_romance_prefix
                }
			}
			
			culture:blatnohrader = {
				set_culture_name = {
					noun = n_blatnohrader_noun
					collective_noun = n_blatnohrader_collective_noun
					prefix = n_blatnohrader_prefix
				}
			}
			
			trigger_event = {
				id = balkan_culture.0007
				days = { 3650 7300 }
			}
			
			if = {
				limit = {
					NOT = { has_global_variable = abotrite_assimilation_happened }
				}
				title:k_hungary = {
					set_title_name = k_hungary_carpathia
				}
			}
			
 		}
		
		title:k_balaton = {
			save_scope_as = balaton_title
			hidden_effect = {
				set_title_name = k_balaton_pannoniae
			}
			custom_tooltip = establish_pannonian_culture_decision_effect.ttd
		}
		
		show_as_tooltip = {
			custom_tooltip = establish_pannonian_culture_decision_effect.tta
		}
	}
	
	option = { # Long live Dudlebia
		name = balkan_culture.0006.b
		trigger = {
			culture = culture:dudlebian
		}
		hidden_effect = {
		
			culture:dudlebian = {
				get_all_innovations_from = culture:slavonian
				get_all_innovations_from = culture:abotrite
				set_culture_name = {
					noun = n_dudlebian_noun
					collective_noun = n_dudlebian_collective_noun
					prefix = n_dudlebian_prefix
				}
			}
			
 		}
		
		title:k_balaton = {
			save_scope_as = balaton_title
			hidden_effect = {
				set_title_name = k_balaton_dudlebia
			}
			custom_tooltip = establish_pannonian_culture_decision_effect.tte
		}
		
		show_as_tooltip = {
			custom_tooltip = establish_pannonian_culture_decision_effect.ttb
		}
	}
	
	option = { # Long live Dunavia
		name = balkan_culture.0006.c
		trigger = {
			NOT = { culture = culture:dudlebian }
		}
		title:k_balaton = {
			save_scope_as = balaton_title
			hidden_effect = {
				set_title_name = k_balaton_dunavia
			}
			custom_tooltip = establish_pannonian_culture_decision_effect.ttf
		}
		
		hidden_effect = {
			trigger_event = {
				id = balkan_culture.0007
				days = { 3650 7300 }
			}
		}
		
		show_as_tooltip = {
			custom_tooltip = establish_pannonian_culture_decision_effect.ttc
		}
	}

}

#Dunavian Culture Event
balkan_culture.0007 = {
	scope = none
	hidden = yes

	immediate = {
	
		hidden_effect = {
		
			culture:pannonian = {
				reset_culture_creation_date = yes
				get_all_innovations_from = culture:dudlebian
				get_all_innovations_from = culture:blatno_slavic
				get_all_innovations_from = culture:slavonian
				get_all_innovations_from = culture:abotrite
			}
			
			title:c_visegrad = {
				if = {
					limit = {
						culture = culture:blatno_slavic
						holder = { NOT = { culture = culture:blatno_slavic } }
					}
					set_county_culture = culture:pannonian
				}
			}
		
			every_county = {
				limit = {
					OR = {
						culture = culture:dudlebian
						culture = culture:blatno_slavic
						culture = culture:slavonian
						culture = culture:abotrite
					}
					title_province = {	
						geographical_region = ce_custom_roman_pannonia
					}
				}
				add_to_list = pannonian_slavic_counties
			}
			
			every_in_list = {
				list = pannonian_slavic_counties

				# South Slavic Shift
				if = {
					limit = {
						OR = {
							culture = culture:dudlebian
							culture = culture:blatno_slavic
							culture = culture:slavonian
							culture = culture:abotrite
						}
					}
					random = {
						chance = 40
						modifier = {
							add = 60
							culture = culture:dudlebian
						}
						set_county_culture = culture:pannonian
					}

					# Rulers Flip Along
					holder = {
						if = {
							limit = {
								is_ai = yes
								OR = {
									culture = culture:dudlebian
									culture = culture:blatno_slavic
									culture = culture:slavonian
									culture = culture:abotrite
								}
								capital_province = {
									geographical_region = ce_custom_roman_pannonia
								}
							}
							set_culture = culture:pannonian
							every_courtier = {
								limit = {
									OR = {
										culture = culture:dudlebian
										culture = culture:blatno_slavic
										culture = culture:slavonian
										culture = culture:abotrite
									}
								}
								set_culture = culture:pannonian
							}
						}
					}
					
					#Convert spouse
					if = {
						limit = {
							is_married = yes
							any_spouse = { is_landed = no }
						}
						every_spouse = {
							set_culture = culture:pannonian
						}
					}
			
					if = {
						limit = {
							any_close_family_member = {
								is_landed = no
							}
						}
						every_close_family_member = {
							custom = all_family_members
							limit = {
								is_landed = no
							}
							set_culture = culture:pannonian
						}
					}

					#Convert appropriate vassals, and their family
					if = {
						limit = {
							OR = {
								any_vassal = {
									is_ai = yes
								}
								any_courtier = {
									is_ai = yes
								}			
							}
						}
						every_courtier = {
							limit = {
								is_ai = yes
							}
							set_culture = culture:pannonian
							if = {
								limit = { any_spouse = { is_landed = no } }
								every_spouse = {
									set_culture = culture:pannonian
								}
								if = {
									limit = {
										any_close_family_member = {
											is_landed = no
										}
									}
									every_close_family_member = {
										limit = {
											is_landed = no
										}
										set_culture = culture:pannonian
									}
								}
							}
						}
					}
				}
			}
			set_culture = culture:pannonian
		}
	}
	
}

scripted_trigger pannonian_culture_shift_trigger = {
	tier = tier_county
	exists = holder
	title_province = {
		geographical_region = ce_custom_roman_pannonia
	}
	NOT = { exists = var:had_pannonian_county_conversion }
	NOT = { culture = holder.culture }
	culture = {
		NOR = {
			this = culture:pannonian
			any_parent_culture_or_above = {
				this = culture:pannonian
			}
		}
		OR = {
			this = culture:blatno_slavic
			this = culture:slavonian
			this = culture:abotrite
		}
	}
	any_neighboring_county = {
		culture = culture:pannonian
	}
}

balkan_culture.0008 = {
	scope = none
	hidden = yes
	
	trigger = {
		culture = culture:pannonian
		any_held_title = {
			pannonian_culture_shift_trigger = yes
		}
	}

	immediate = {
		random_held_title = {
			limit = { pannonian_culture_shift_trigger = yes }
			set_variable = {
				name = had_pannonian_county_conversion
				value = yes
			}
			set_county_culture = culture:pannonian
		}
	}

}

scripted_trigger dudlebian_culture_shift_trigger = {
	tier = tier_county
	exists = holder
	title_province = {
		geographical_region = ce_custom_transdanubia
	}
	NOT = { exists = var:had_dudlebian_county_conversion }
	NOT = { culture = holder.culture }
	culture = {
		NOR = {
			this = culture:dudlebian
			any_parent_culture_or_above = {
				this = culture:dudlebian
			}
		}
		this = culture:dudlebian
	}
	any_neighboring_county = {
		culture = culture:dudlebian
	}
}

balkan_culture.0012 = {
	scope = none
	hidden = yes
	
	trigger = {
		culture = culture:dudlebian
		any_held_title = {
			dudlebian_culture_shift_trigger = yes
		}
	}

	immediate = {
		random_held_title = {
			limit = { dudlebian_culture_shift_trigger = yes }
			set_variable = {
				name = had_dudlebian_county_conversion
				value = yes
			}
			set_county_culture = culture:dudlebian
		}
	}

}

#### CROATIAN ASSIMILATION #### 

scripted_trigger croatian_culture_shift_trigger = {
	tier = tier_county
	exists = holder
	title_province = {
		geographical_region = ce_custom_royal_croatia
	}
	NOT = { exists = var:had_croatian_county_conversion }
	NOT = { exists = var:had_serbian_county_conversion }
	NOT = { exists = var:had_bosnian_county_conversion }
	NOT = { culture = holder.culture }
	culture = {
		NOR = {
			this = culture:croatian
			any_parent_culture_or_above = {
				this = culture:croatian
			}
		}
		has_cultural_pillar = heritage_south_slavic
	}
	any_neighboring_county = {
		culture = culture:croatian
	}
}

balkan_culture.0009 = {
	scope = none
	hidden = yes
	
	trigger = {
		culture = culture:croatian
		any_held_title = {
			croatian_culture_shift_trigger = yes
		}
	}

	immediate = {
		random_held_title = {
			limit = { croatian_culture_shift_trigger = yes }
			set_variable = {
				name = had_croatian_county_conversion
				value = yes
			}
			set_county_culture = culture:croatian
		}
	}

}

#### SERBIAN ASSIMILATION #### 

scripted_trigger serbian_culture_shift_trigger = {
	tier = tier_county
	exists = holder
	title_province = {
		geographical_region = ce_custom_royal_serbia
	}
	NOT = { exists = var:had_croatian_county_conversion }
	NOT = { exists = var:had_serbian_county_conversion }
	NOT = { exists = var:had_bosnian_county_conversion }
	NOT = { culture = holder.culture }
	culture = {
		NOR = {
			this = culture:serbian
			any_parent_culture_or_above = {
				this = culture:serbian
			}
		}
		has_cultural_pillar = heritage_south_slavic
	}
	any_neighboring_county = {
		culture = culture:serbian
	}
}

balkan_culture.0010 = {
	scope = none
	hidden = yes
	
	trigger = {
		culture = culture:serbian
		any_held_title = {
			serbian_culture_shift_trigger = yes
		}
	}

	immediate = {
		random_held_title = {
			limit = { serbian_culture_shift_trigger = yes }
			set_variable = {
				name = had_serbian_county_conversion
				value = yes
			}
			set_county_culture = culture:serbian
		}
	}

}

#### BOSNIAN ASSIMILATION #### 

scripted_trigger bosnian_culture_shift_trigger = {
	tier = tier_county
	exists = holder
	title_province = {
		geographical_region = ce_custom_bosnia
	}
	NOT = { exists = var:had_bosnian_county_conversion }
	NOT = { culture = holder.culture }
	culture = {
		NOR = {
			this = culture:bosnian
			any_parent_culture_or_above = {
				this = culture:bosnian
			}
		}
		has_cultural_pillar = heritage_south_slavic
	}
	any_neighboring_county = {
		culture = culture:bosnian
	}
}

balkan_culture.0011 = {
	scope = none
	hidden = yes
	
	trigger = {
		culture = culture:bosnian
		any_held_title = {
			bosnian_culture_shift_trigger = yes
		}
	}

	immediate = {
		random_held_title = {
			limit = { bosnian_culture_shift_trigger = yes }
			set_variable = {
				name = had_bosnian_county_conversion
				value = yes
			}
			set_county_culture = culture:bosnian
		}
	}

}