########################################
# Events for Bavaria
#
# written by Johan Andersson
########################################

namespace = flavor_bav
normal_or_historical_nations = yes

#Cologne goes with Bavarian Archbishop
country_event = {
	id = flavor_bav.2
	title = flavor_bav.2.t
	desc = flavor_bav.2.d
	picture = POPE_PREACHING_eventPicture
	
	is_triggered_only = yes
	
	option = {	
		name = flavor_bav.2.a	
			
		KOL = {
			add_opinion = {
				who = root
				modifier = kol_bavarian_archbishop
			}				
		}
		add_papal_influence = 5
	}
}


# Opposition against Austria
country_event = {
	id = flavor_bav.3
	title = flavor_bav.3.t
	desc = flavor_bav.3.d
	picture = COURT_eventPicture

	trigger = {
		OR = {
			tag = BAV
			tag = ING
			tag = LBV
			tag = UBV
		}
		NOT = { has_country_flag = flavor_bav_3_happened }
		
		is_year = 1450
		NOT = { is_year = 1500 }
		is_lesser_in_union = no
		dynasty = "0000000000000"
		
		HAB = {
			exists = yes
			is_emperor = yes
			dynasty =  "0000000000"
		}
	}
	
	mean_time_to_happen = {
		months = 120
	}	

	immediate = {
		hidden_effect = {
			set_country_flag = flavor_bav_3_happened
		}
	}
	
	
	option = {	
		name = flavor_bav.3.a	
		HAB = {
			add_opinion = {
				who = ROOT
				modifier = bav_against_habsburg
			}
		}
		add_legitimacy = 5
		add_prestige = 5
	}

	option = {	
		name = flavor_bav.3.b	
		HAB = {
			add_opinion = {
				who = ROOT
				modifier = bav_reconcile_habsburg
			}
		}
		add_prestige = -25
	}		
}


#Johannes Aventinus
country_event = {
	id = flavor_bav.4
	title = flavor_bav.4.t
	desc = flavor_bav.4.d
	picture = INVENTION_eventPicture
	
	fire_only_once = yes

	trigger = {
		OR = {
			tag = BAV
			tag = ING
			tag = LBV
			tag = UBV
		}
		
		is_year = 1510
		NOT = { is_year = 1520 }
	}
	
	mean_time_to_happen = {
		months = 36
	}	
	
	
	option = {	
		name = flavor_bav.4.a
		add_years_of_income = -0.25
		add_prestige = 5
		add_legitimacy = 10
	}	
	option = {	
		name = flavor_bav.4.b
		add_prestige = -1
	}		
}


#Wilhelm IV invites the Jesuits into Bavaria
country_event = {
	id = flavor_bav.5
	title = flavor_bav.5.t
	desc = flavor_bav.5.d
	picture = RELIGION_eventPicture
	
	fire_only_once = yes

	trigger = {
		OR = {
			tag = BAV
			tag = ING
		}

		is_year = 1520
		NOT = { is_year = 1560 }
		is_religion_enabled = protestant
		religion = catholic
		dominant_religion = catholic
		has_country_modifier = counter_reformation
	}
	
	mean_time_to_happen = {
		months = 120
	}	
	
	
	option = {	
		name = flavor_bav.5.a
		add_papal_influence = 10
		add_country_modifier = {
			name = "bavarian_jesuits"
			duration = -1
		}
	}	
	option = {	
		name = flavor_bav.5.b
		trigger = {
			exists = PAP
		}
		PAP = {
			add_opinion = {
				who = ROOT
				modifier = bav_jesuits_rejected
			}
		}
		add_papal_influence = -10
	}		
}

#Splendor of Albert!
country_event = {
	id = flavor_bav.6
	title = flavor_bav.6.t
	desc = flavor_bav.6.d
	picture = IMPORTANT_STATUE_eventPicture
	
	fire_only_once = yes

	trigger = {
		OR = {
			tag = BAV
			tag = UBV
		}
		is_year = 1550
		NOT = { is_year = 1580 }
		owns = 65
	}	
	mean_time_to_happen = {
		months = 240
	}	
	option = {	
		name = flavor_bav.6.a
		add_years_of_income = -2.0
		add_prestige = 20
		add_legitimacy = 10
		65 = { add_base_tax = 1 }
	}	
	option = {	
		name = flavor_bav.6.b
		add_prestige = -5
	}	
}

########################################
# More Events for Bavaria
#
# by Pierre du Plessis
########################################

namespace = new_flavour_bav

#Transfer the Palatine Electorate to Bavaria
country_event = {
	id = new_flavour_bav.10
	title = new_flavour_bav.10.t
	desc = {
		desc = new_flavour_bav.10.d
		trigger = { NOT = { tag = from } }
	}
	desc = {
		desc = new_flavour_bav.10.d.bav
		trigger = { tag = from }
	}
	picture = HRE_eventPicture
	major = yes
	
	is_triggered_only = yes
	
	option = { #transfer the electorate
		name = new_flavour_bav.10.a	
		
		trigger = { NOT = { tag = from } }

		PAL = {
			tooltip = { elector = no }
			add_opinion = {
				who = root
				modifier = opinion_bav_repealed_electorate
			}
		}

		from = {
			hidden_effect = { country_event = { id = new_flavour_bav.101 } }
			tooltip = { elector = yes }
			add_opinion = {
				who = root
				modifier = opinion_bav_gave_electorate
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					NOT = {
						has_opinion = {
							who = from
							value = 0
						}
					}
					ai_attitude = {
						who = from
						attitude = attitude_threatened
					}
					ai_attitude = {
						who = from
						attitude = attitude_hostile
					}
					ai_attitude = {
						who = from
						attitude = attitude_outraged
					}
					ai_attitude = {
						who = from
						attitude = attitude_rivalry
					}
				}
			}
		}
	}
	option = { #transfer the electorate
		name = new_flavour_bav.10.a2
		
		trigger = { tag = from }

		PAL = {
			elector = no
			add_opinion = {
				who = root
				modifier = opinion_bav_repealed_electorate
			}
			add_liberty_desire = 50
		}

		elector = yes

		ai_chance = {
			factor = 1
		}
	}
	option = { #don't transfer the electorate
		name = new_flavour_bav.10.b
		
		trigger = { NOT = { tag = from } }

		from = {
			hidden_effect = { country_event = { id = new_flavour_bav.102 } }
			add_opinion = {
				who = root
				modifier = opinion_bav_refused_to_transfer_electorate
			}
		}
		
		custom_tooltip = legitimate_subject_elector_tt
		hidden_effect = {
			PAL = {
				add_country_modifier = {
					hidden = yes
					name = "legitimate_subject_elector_modifer"
					duration = -1
				}
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0.1
				OR = {
					alliance_with = from
					has_opinion = {
						who = from
						value = 120
					}
				}
			}
			modifier = {
				factor = 0.5
				has_opinion = {
					who = from
					value = 60
				}
			}
			modifier = {
				factor = 2
				OR = {
					NOT = {
						has_opinion = {
							who = from
							value = 60
						}
					}
					AND = {
						NOT = {
							ai_attitude = {
								who = from
								attitude = attitude_allied
							}
						}
						NOT = {
							ai_attitude = {
								who = from
								attitude = attitude_friendly
							}
						}
						NOT = {
							ai_attitude = {
								who = from
								attitude = attitude_protective
							}
						}
					}
				}
			}
		}
	}
	option = { #don't transfer the electorate
		name = new_flavour_bav.10.b2
		
		trigger = { tag = from }

		custom_tooltip = legitimate_subject_elector_tt
		hidden_effect = {
			PAL = {
				add_country_modifier = {
					hidden = yes
					name = "legitimate_subject_elector_modifer"
					duration = -1
				}
			}
		}

		ai_chance = {
			factor = 0
		}
	}
}

#For Bavaria: They said yes
country_event = {
	id = new_flavour_bav.101
	title = new_flavour_bav.101.name
	desc = new_flavour_bav.101.desc
	picture = HRE_eventPicture
	
	is_triggered_only = yes

	option = {
		name = new_flavour_bav.101.option
		
		PAL = {
			elector = no
		}
		elector = yes
	}
}

#For Bavaria: They said no
country_event = {
	id = new_flavour_bav.102
	title = new_flavour_bav.102.name
	desc = new_flavour_bav.102.desc
	picture = HRE_eventPicture
	
	is_triggered_only = yes

	option = {
		name = new_flavour_bav.102.option
	}
}


#The Cologne Secundogeniture
country_event = {
	id = new_flavour_bav.11
	title = new_flavour_bav.11.t
	desc = new_flavour_bav.11.d
	picture = PRINCE_BISHOP_RESIGN_eventPicture

	is_triggered_only = yes
	
	option = { #do it
		name = new_flavour_bav.11.a	

		KOL = {
			custom_tooltip = new_flavour_bav.11.A.tooltip
			set_country_flag = KOL_secondogeniture_of_BAV
			if = {
				limit = {
					religion = root
				}
				add_liberty_desire = 25
			}
			else = {
				change_religion = root
				add_liberty_desire = 75
			}
			hidden_effect = {
				add_country_modifier = {
					hidden = yes
					name = "legitimate_subject_elector_modifer"
					duration = -1
				}
			}

			define_ruler = {
				dynasty = ROOT
				culture = ROOT
				religion = ROOT
			}
			if = {
				limit = {
					has_heir = yes
				}
				hidden_effect = {
					kill_heir = {}
				}
			}
			if = {
				limit = { ai = no }
				country_event = { id = new_flavour_bav.110 }
			}
		}

		ai_chance = {
			factor = 1
		}
	}
	option = { #don't do it
		name = new_flavour_bav.11.b

		ai_chance = {
			factor = 0
		}
	}
}

#The Cologne Secundogeniture - notify Cologne
country_event = {
	id = new_flavour_bav.110
	title = new_flavour_bav.110.t
	desc = new_flavour_bav.110.d
	picture = PRINCE_BISHOP_RESIGN_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = UNFORTUNATE
		custom_tooltip = new_flavour_bav.110.A.tooltip
	}
}

#Make Ingolstadt produce beer
country_event = {
	id = new_flavour_bav.12
	title = new_flavour_bav.12.t
	desc = new_flavour_bav.12.d
	picture = TRADEGOODS_eventPicture
	
	mean_time_to_happen = {
		years = 60
	}

	fire_only_once = yes

	trigger = {
		owns_core_province = 2955
		primary_culture = bavarian
		is_year = 1510
		2955 = {
			trade_goods = wine
			has_building = farm_estate
			development = 15
		}
	}
	
	option = {	
		name = new_flavour_bav.12.a

		add_dip_power = -50
		2955 = {
			change_trade_goods = grain
			add_base_production = 1
			add_province_modifier = {
				name = ingolstadt_beer_city
				duration = -1
			}
		}
		ai_chance = {
			factor = 1
		}
	}
	option = {
		name = new_flavour_bav.12.b
		
		add_prestige = 20
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				NOT = {
					prestige = 0
				}
			}
			modifier = {
				factor = 5
				NOT = {
					prestige = -50
				}
			}
		}
	}
}


#Startup Event: The Bavarian Succession
country_event = {
	id = new_flavour_bav.13
	title = new_flavour_bav.13.name
	desc = new_flavour_bav.13.desc
	picture = BAD_WITH_MONARCH_eventPicture
	
	is_triggered_only = yes

	trigger = {
		exists = UBV
		exists = LBV
		exists = ING
	}
	
	option = {	
		name = new_flavour_bav.13.opt

		if = {
			limit = {
				NOT = { tag = UBV }
			}
			add_casus_belli = {
				type = cb_restore_personal_union
				target = UBV
				months = 1200
			}
		}
		if = {
			limit = {
				NOT = { tag = LBV }
			}
			add_casus_belli = {
				type = cb_restore_personal_union
				target = LBV
				months = 1200
			}
		}
		if = {
			limit = {
				NOT = { tag = ING }
			}
			add_casus_belli = {
				type = cb_restore_personal_union
				target = ING
				months = 1200
			}
		}
	}
}

#The Death of Ludwig VIII - Landshut
country_event = {
	id = new_flavour_bav.14
	title = new_flavour_bav.14.name
	desc = new_flavour_bav.14.desc
	picture = DEATH_OF_HEIR_eventPicture
	
	mean_time_to_happen = {
		years = 2
	}

	fire_only_once = yes

	trigger = {
		tag = LBV
		is_year = 1445
		NOT = { is_year = 1447 }
		is_subject = no
		government = monarchy
		dynasty = "0000000000000"
		exists = ING
		ING = {
			government = monarchy
			has_ruler = "000000 VIII"
			has_heir = no
			is_subject = no
			is_at_war = no
		}
	}

	option = {	
		name = new_flavour_bav.14.opt

		create_union = ING
	}
	
	after = {
		hidden_effect = {
			ING = { country_event = { id = new_flavour_bav.15 } }
	
			if = {
				limit = {
					exists = UBV
					UBV = {
						is_subject = no
					}
				}
				UBV = { country_event = { id = new_flavour_bav.16 days = 10 } }
			}
			if = {
				limit = {
					exists = ANS
					ANS = {
						is_subject = no
					}
				}
				ANS = { country_event = { id = new_flavour_bav.17 days = 15 } }
			}
		}
	}
}


#The Death of Ludwig VIII - Ingolstadt
country_event = {
	id = new_flavour_bav.15
	title = new_flavour_bav.15.name
	desc = new_flavour_bav.15.desc
	picture = DEATH_OF_HEIR_eventPicture
	
	is_triggered_only = yes

	option = {
		name = new_flavour_bav.15.opt
		tooltip = { from = { create_union = root } }
	}
}


#The Death of Ludwig VIII - Munich
country_event = {
	id = new_flavour_bav.16
	title = new_flavour_bav.16.name
	desc = new_flavour_bav.16.desc
	picture = DEATH_OF_HEIR_eventPicture
	
	is_triggered_only = yes

	option = {
		name = new_flavour_bav.16.opt
		tooltip = { from = { create_union = ING } }
	}
}

#The Death of Ludwig VIII - Ansbach
country_event = {
	id = new_flavour_bav.17
	title = new_flavour_bav.17.name
	desc = new_flavour_bav.17.desc
	picture = DEATH_OF_HEIR_eventPicture
	
	is_triggered_only = yes

	option = {
		name = new_flavour_bav.17.A
		
		add_years_of_income = 2.5

		ai_chance = { factor = 5 }
	}

	option = {
		name = new_flavour_bav.17.B
		
		ING = {
			every_owned_province = {
				add_claim = root
			}
		}

		ai_chance = {
			factor = 0.5 #useless
		}
	}

	option = {
		name = new_flavour_bav.17.C
		
		add_years_of_income = -2.5

		ING = {
			every_owned_province = {
				add_core = root
			}
		}

		hidden_effect = {
			from = { #Landshut
				country_event = { id = new_flavour_bav.171 }
			}
		}

		ai_chance = {
			factor = 1.5

			modifier = {
				factor = 0
				NOT = {
					years_of_income = 1.5
				}
			}
			modifier = {
				factor = 2
				years_of_income = 3
			}
		}
	}
}

#Landshut told that Ansbach has purchased the claims to the crown
country_event = {
	id = new_flavour_bav.171
	title = new_flavour_bav.171.name
	desc = new_flavour_bav.171.desc
	picture = DIPLOMACY_eventPicture
	
	is_triggered_only = yes

	option = {
		name = new_flavour_bav.171.A

		tooltip = {
			ING = {
				every_owned_province = {
					add_core = from
				}
			}
		}
	}
}

#The Religious Mandate
country_event = {
	id = new_flavour_bav.18
	title = new_flavour_bav.18.name
	desc = new_flavour_bav.18.desc
	picture = REFORM_eventPicture

	fire_only_once = yes
	
	mean_time_to_happen = {
		months = 60
	}

	trigger = {
		OR = {
			tag = BAV
			tag = UBV
			tag = LBV
			tag = ING
		}
		is_religion_enabled = protestant
		religion = catholic
		NOT = {
			had_global_flag = {
				flag = reformation_started
				days = 3650
			}
		}
		NOT = {
			employed_advisor = {
				religion = protestant
			}
		}
		has_regency = no
		any_owned_province = {
			religion = root
		}
	}

	option = { #Institute the Mandate	
		name = new_flavour_bav.18.a

		add_adm_power = -50

		add_country_modifier = {
			name = bav_religious_mandate_mod
			duration = -1
		}

		reduce_estate_church_loyalty_effect = yes

		ai_chance = {
			factor = 2
		}
	}
	option = { #Don't do it
		name = new_flavour_bav.18.b
		
		if = {
			limit = {
				any_owned_province = {
					is_capital = no
					NOT = { religion = protestant }
				}
			}
			random_owned_province = {
				limit = {
					is_capital = no
					religion = root
					NOT = { has_province_modifier = religious_zeal_at_conv }
					NOT = { has_province_modifier = expelled_minority }
				}
				change_religion = protestant
			}
			else = {
				random_owned_province = {
					limit = {
						religion = root
					}
					change_religion = protestant
				}
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}

#The Religious Mandate Expires
country_event = {
	id = new_flavour_bav.181
	title = new_flavour_bav.181.name
	desc = new_flavour_bav.181.desc
	picture = REFORM_eventPicture

	fire_only_once = yes

	trigger = {
		has_country_modifier = bav_religious_mandate_mod
		OR = {
			current_age = age_of_absolutism
			NOT = {
				any_country = {
					OR = {
						religion = protestant
						religion = reformed
					}
				}
			}
		}
		all_owned_province = {
			OR = {
				religion = root
				NOT = { religion_group = root }
			}
		}
		had_global_flag = {
			flag = reformation_started
			days = 18250
		}
	}
	
	mean_time_to_happen = {
		months = 6
	}

	option = {
		name = new_flavour_bav.181.A
		remove_country_modifier = bav_religious_mandate_mod
	}
}


#Hans Steininger's Beard
country_event = {
	id = new_flavour_bav.19
	title = new_flavour_bav.19.name
	desc = new_flavour_bav.19.desc
	picture = CITY_VIEW_eventPicture

	fire_only_once = yes
	
	mean_time_to_happen = {
		months = 90
	}

	trigger = {
		primary_culture = bavarian
		owns_core_province = 4760
		has_regency = no
		is_year = 1560
		NOT = { is_year = 1570 }
	}

	option = {	
		name = new_flavour_bav.19.a
		add_prestige = 10
	}
}


#The Theatinerkirche
country_event = {
	id = new_flavour_bav.20
	title = new_flavour_bav.20.name
	desc = new_flavour_bav.20.desc
	picture = CITY_VIEW_eventPicture

	fire_only_once = yes
	
	mean_time_to_happen = {
		months = 120
	}

	trigger = {
		tag = BAV
		government = monarchy
		has_government_attribute = heir
		has_regency = no
		has_consort = yes
		has_female_consort = yes
		has_heir = no
		is_year = 1650
		NOT = { is_year = 1680 }
		religion_group = christian
	}

	option = {	
		name = new_flavour_bav.20.a
		add_treasury = -80
		add_prestige = 10

		add_ruler_modifier = {
			name = bav_building_wife_church
			duration = -1
		}

		define_advisor = {
			type = artist
			skill = 3
			name = "Agostino Barelli"
			discount = yes
			culture = romagnan
		}

		custom_tooltip = new_flavour_bav.20.a.tooltip
		tooltip = {
			capital_scope = {
				if = {
					limit = {
						has_tax_building_trigger = no
						num_free_building_slots = 1
					}
					add_building = temple
				}
				else_if = {
					limit = {
						has_building = temple
					}
					remove_building = temple
					add_building = cathedral
				}
				else = {
					add_base_tax = 2
				}
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				treasury = 85
			}
			modifier = {
				factor = 0.5
				num_of_loans = 5
			}
			modifier = {
				factor = 0.5
				NOT = {
					monthly_income = 7
				}
			}
			modifier = {
				factor = 0
				OR = {
					is_bankrupt = yes
					is_in_large_debt = yes
					AND = {
						NOT = { monthly_income = 3 }
						NOT = { treasury = 70 }
					}
				}
			}
		}
	}
	
	option = {	
		name = new_flavour_bav.20.b

		add_prestige = -10
		
		add_ruler_modifier = {
			name = bav_woman_scorned_mod
			duration = -1
		}
	}
}

#The Theatinerkirche has been built
country_event = {
	id = new_flavour_bav.201
	title = new_flavour_bav.201.name
	desc = new_flavour_bav.201.desc
	picture = CITY_VIEW_eventPicture

	trigger = {
		has_ruler_modifier = bav_building_wife_church
		government = monarchy
		has_heir = yes
		heir_has_ruler_dynasty = yes
	}

	mean_time_to_happen = {
		years = 1
	}

	option = {
		name = new_flavour_bav.201.A
		capital_scope = {
			if = {
				limit = {
					has_tax_building_trigger = no
					num_free_building_slots = 1
				}
				add_building = temple
			}
			else_if = {
				limit = {
					has_building = temple
				}
				remove_building = temple
				add_building = cathedral
			}
			else = {
				add_base_tax = 2
			}
		}
		remove_country_modifier = bav_building_wife_church
	}
}

###The Sale of Regensburg Chain
#First Warning for Regensburg
country_event = {
	id = new_flavour_bav.21
	title = new_flavour_bav.21.name
	desc = new_flavour_bav.21.desc
	picture = CITY_VIEW_eventPicture

	fire_only_once = yes
	
	mean_time_to_happen = {
		years = 1
	}

	trigger = {
		tag = REG
		is_year = 1470
		has_reform = free_city
		emperor = {
			tag = HAB
			NOT = { dynasty = "0000000000000" }
		}
		OR = {
			exists = BAV
			exists = UBV
			exists = ING
			exists = LBV
			exists = PAL
		}
	}

	option = {
		name = new_flavour_bav.21.A

		add_treasury = -200

		HAB = {
			add_opinion = {
				who = root
				modifier = opinion_regensburg_paid
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					NOT = { treasury = 150 }
					num_of_loans = 5
				}
			}
		}
	}
	option = {
		name = new_flavour_bav.21.B

		hidden_effect = {
			set_country_flag = REG_warned_of_debts
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				treasury = 200
				NOT = { num_of_loans = 1 }
			}
		}
	}
}

#Habsburgs Demand Money (or not)
country_event = {
	id = new_flavour_bav.22
	title = new_flavour_bav.22.name
	desc = new_flavour_bav.22.desc
	picture = CITY_VIEW_eventPicture

	fire_only_once = yes
	
	mean_time_to_happen = {
		years = 10
	}

	trigger = {
		tag = HAB
		is_emperor = yes
		NOT = { dynasty = "0000000000000" }
		is_year = 1470
		NOT = { is_year = 1520 }
		is_at_war = yes
		exists = REG
		REG = {
			has_country_flag = REG_warned_of_debts
			has_reform = free_city
		}
		num_of_loans = 1
		
		OR = {
			exists = BAV
			exists = UBV
			exists = ING
			exists = LBV
			exists = PAL
		}
	}

	immediate = {
		hidden_effect = {
			random_enemy_country = {
				limit = {
					war_with = ROOT
					OR = {
						is_in_war = {
							attacker_leader = this
						}
						is_in_war = {
							defender_leader = this
						}
					}
				}
				save_event_target_as = emperors_enemy
			}
		}
	}

	option = {
		name = new_flavour_bav.22.A
		custom_tooltip = new_flavour_bav.22.A.tooltip
		tooltip = {
			add_treasury = 200
		}

		hidden_effect = {
			if = {
				limit = {
					exists = BAV
					BAV = {
						is_subject = no
						dynasty = "0000000000000"
						NOT = { is_rival = REG }
						NOT = { REG = { is_rival = prev } }
					}
				}
				BAV = {
					country_event = { id = new_flavour_bav.23 }
				}
			}
			else_if = {
				limit = {
					exists = UBV
					UBV = {
						is_subject = no
						dynasty = "0000000000000"
						NOT = { is_rival = REG }
						NOT = { REG = { is_rival = prev } }
					}
				}
				UBV = {
					country_event = { id = new_flavour_bav.23 }
				}
			}
			else_if = {
				limit = {
					exists = LBV
					LBV = {
						is_subject = no
						dynasty = "0000000000000"
						NOT = { is_rival = REG }
						NOT = { REG = { is_rival = prev } }
					}
				}
				LBV = {
					country_event = { id = new_flavour_bav.23 }
				}
			}
			else_if = {
				limit = {
					exists = ING
					ING = {
						is_subject = no
						dynasty = "0000000000000"
						NOT = { is_rival = REG }
						NOT = { REG = { is_rival = prev } }
					}
				}
				ING = {
					country_event = { id = new_flavour_bav.23 }
				}
			}
			else_if = {
				limit = {
					PAL = {
						is_subject = no
						dynasty = "0000000000000"
						NOT = { is_rival = REG }
						NOT = { REG = { is_rival = prev } }
					}
				}
				PAL = {
					country_event = { id = new_flavour_bav.23 }
				}
			}
			else = { REG = { country_event = { id = new_flavour_bav.24 } } }
		}
		tooltip = { REG = { country_event = { id = new_flavour_bav.24 } } }


		ai_chance = {
			factor = 1
		}
	}
	
	option = {
		name = new_flavour_bav.22.B

		add_imperial_influence = 5

		REG = {
			add_opinion = {
				who = root
				modifier = opinion_regensburg_no_money
			}
			country_event = { id = new_flavour_bav.26 }
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				num_of_loans = 5
			}
		}
	}
}


#Wittelsbachs Can Pay
country_event = {
	id = new_flavour_bav.23
	title = new_flavour_bav.23.name
	desc = new_flavour_bav.23.desc
	picture = CITY_VIEW_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.23.A
		custom_tooltip = new_flavour_bav.23.A.tooltip
		tooltip = {
			add_treasury = -200
	
			REG = {
				every_owned_province = {
					add_core = root
					cede_province = root
					if = {
						limit = {
							NOT = { is_claim = HAB }
							NOT = { is_core = HAB }
						}
						add_claim = HAB
					}
				}
			}
	
			HAB = {
				add_treasury = 200
				add_opinion = {
					who = root
					modifier = opinion_stole_free_city
				}
			}
		}

		set_country_flag = wittelsbach_will_pay_for_regensburg

		REG = { country_event = { id = new_flavour_bav.24 } }

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					num_of_loans = 5
					NOT = { treasury = 150 }
				}
			}
			modifier = {
				factor = 0.5
				NOT = { treasury = 200 }
			}
			modifier = {
				factor = 1.5
				treasury = 250
			}
			modifier = {
				factor = 2
				REG = {
					has_opinion = {
						who = root
						value = 80
					}
				}
			}
			modifier = {
				factor = 0.5
				REG = {
					NOT = {
						has_opinion = {
							who = root
							value = 0
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				REG = {
					NOT = {
						has_opinion = {
							who = root
							value = -40
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				HAB = {
					alliance_with = root
				}
			}
		}
	}
	option = {
		name = new_flavour_bav.23.B #No
		custom_tooltip = new_flavour_bav.23.B.tooltip

		hidden_effect = {
			if = {
				limit = { tag = BAV }
				if = {
					limit = {
						exists = UBV
						UBV = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					UBV = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else_if = {
					limit = {
						exists = LBV
						LBV = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					LBV = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else_if = {
					limit = {
						exists = ING
						ING = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					ING = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else_if = {
					limit = {
						exists = PAL
						PAL = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					PAL = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else = { REG = { country_event = { id = new_flavour_bav.24 } } }
			}
			else_if = {
				limit = { tag = UBV }
				if = {
					limit = {
						exists = LBV
						LBV = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					LBV = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else_if = {
					limit = {
						exists = ING
						ING = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					ING = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else_if = {
					limit = {
						exists = PAL
						PAL = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					PAL = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else = { REG = { country_event = { id = new_flavour_bav.24 } } }
			}
			else_if = {
				limit = { tag = LBV }
				if = {
					limit = {
						exists = ING
						ING = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					ING = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else_if = {
					limit = {
						exists = PAL
						PAL = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					PAL = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else = { REG = { country_event = { id = new_flavour_bav.24 } } }
			}
			else_if = {
				limit = { tag = ING }
				if = {
					limit = {
						exists = PAL
						PAL = {
							is_subject = no
							dynasty = "0000000000000"
							NOT = { is_rival = REG }
							NOT = { REG = { is_rival = prev } }
						}
					}
					PAL = {
						country_event = { id = new_flavour_bav.23 }
					}
				}
				else = { REG = { country_event = { id = new_flavour_bav.24 } } }
			}
			else = { REG = { country_event = { id = new_flavour_bav.24 } } }
		}
		tooltip = { REG = { country_event = { id = new_flavour_bav.24 } } }


		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				NOT = {
					REG = {
						has_opinion = {
							who = root
							value = 0
						}
					}
				}
			}
			modifier = {
				factor = 2
				NOT = {
					has_opinion = {
						who = HAB
						value = 0
					}
				}
			}
		}
	}
}


#Regensburg Pays or Not
country_event = {
	id = new_flavour_bav.24
	title = new_flavour_bav.24.name
	desc = {
		desc = new_flavour_bav.24.desc.default
		trigger = { NOT = { FROM = { has_country_flag = wittelsbach_will_pay_for_regensburg } } }
	}
	desc = {
		desc = new_flavour_bav.24.desc.wittelsbach
		trigger = { FROM = { has_country_flag = wittelsbach_will_pay_for_regensburg } }
	}
	picture = HRE_eventPicture

	fire_only_once = yes #just in case
	is_triggered_only = yes

	immediate = {
		hidden_effect = { set_country_flag = REG_pay_demanded }
	}

	option = { #Pay
		name = new_flavour_bav.24.A
		
		add_treasury = -200
		HAB = {
			tooltip = { add_treasury = 200 }
			add_opinion = {
				who = root
				modifier = opinion_regensburg_paid
			}
			hidden_effect = { country_event = { id = new_flavour_bav.2401 } }
		}

		if = {
			limit = {
				from = { has_country_flag = wittelsbach_will_pay_for_regensburg }
			}
			hidden_effect = { from = { country_event = { id = new_flavour_bav.2402 } } }
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					NOT = { treasury = 150 }
					num_of_loans = 5
				}
			}
		}
	}

	option = { #Default
		name = new_flavour_bav.24.B
		custom_tooltip = new_flavour_bav.24.B.tooltip
		
		change_government = theocracy
		add_government_reform = leading_clergy_reform

		add_stability = -3
		add_prestige = -100

		HAB = {
			add_opinion = {
				who = root
				modifier = opinion_regensburg_defaulted
			}
			hidden_effect = { country_event = { id = new_flavour_bav.2403 } }
		}
		add_opinion = {
			who = HAB
			modifier = opinion_regensburg_demand_too_much
		}

		if = {
			limit = {
				from = { has_country_flag = wittelsbach_will_pay_for_regensburg }
			}
			hidden_effect = { from = { country_event = { id = new_flavour_bav.2404 } } }
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					AND = {
						treasury = 150
						NOT = { num_of_loans = 5 }
					}
					AND = {
						from = { has_country_flag = wittelsbach_will_pay_for_regensburg }
						has_opinion = {
							who = from
							value = 80
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				from = { has_country_flag = wittelsbach_will_pay_for_regensburg }
			}
		}
	}

	option = { #Wittelsbach Bailout
		name = new_flavour_bav.24.C

		trigger = {
			from = { has_country_flag = wittelsbach_will_pay_for_regensburg }
		}
		
		if = {
			limit = { ai = no }
			custom_tooltip = new_flavour_bav.24.C.player_warning_tooltip
		}

		from = {
			tooltip = { add_treasury = -200 }
			hidden_effect = {
				save_event_target_as = regensburg_fromfrom
				country_event = { id = new_flavour_bav.2406 days = 1 }
			}
		}

		tooltip = {
			every_owned_province = {
				add_core = from
				cede_province = from
				if = {
					limit = {
						NOT = { is_claim = HAB }
						NOT = { is_core = HAB }
					}
					add_claim = HAB
				}
			}
		}

		HAB = {
			tooltip = {
				add_treasury = 200
				add_opinion = {
					who = from
					modifier = opinion_stole_free_city
				}
			}
			hidden_effect = { country_event = { id = new_flavour_bav.2405 } }
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				AND = {
					treasury = 150
					NOT = { num_of_loans = 5 }
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					has_opinion = {
						who = from
						value = 0
					}
				}
			}
			modifier = {
				factor = 0
				NOT = {
					has_opinion = {
						who = from
						value = -50
					}
				}
			}
			modifier = {
				factor = 1.5
				has_opinion = {
					who = from
					value = 50
				}
			}
			modifier = {
				factor = 2
				NOT = {
					has_opinion = {
						who = HAB
						value = 0
					}
				}
			}
			modifier = {
				factor = 0.5
				has_opinion = {
					who = HAB
					value = 100
				}
			}
		}
	}
}

#Emperor: They paid
country_event = {
	id = new_flavour_bav.2401
	title = new_flavour_bav.2401.name
	desc = new_flavour_bav.2401.desc
	picture = HRE_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.2401.opt
		add_treasury = 200
	}
}

#Bavarians: They paid
country_event = {
	id = new_flavour_bav.2402
	title = new_flavour_bav.2401.name
	desc = new_flavour_bav.2402.desc
	picture = HRE_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.2402.opt
	}
}

#Emperor: They defaulted
country_event = {
	id = new_flavour_bav.2403
	title = new_flavour_bav.2403.name
	desc = new_flavour_bav.2403.desc
	picture = HRE_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.2403.opt
		tooltip = {
			REG = {
				change_government = theocracy
				add_government_reform = leading_clergy_reform
		
				add_stability = -3
				add_prestige = -100
			}
		}
	}
}

#Bavarians: They defaulted
country_event = {
	id = new_flavour_bav.2404
	title = new_flavour_bav.2403.name
	desc = new_flavour_bav.2404.desc
	picture = HRE_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.2404.opt
		tooltip = {
			REG = {
				change_government = theocracy
				add_government_reform = leading_clergy_reform
		
				add_stability = -3
				add_prestige = -100
			}
		}
	}
}

#Emperor: They get ceded to Bavaria
country_event = {
	id = new_flavour_bav.2405
	title = new_flavour_bav.2405.name
	desc = new_flavour_bav.2405.desc
	picture = HRE_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.2405.opt
		add_treasury = 200
		tooltip = {
			from = {
				every_owned_province = {
					add_core = event_target:regensburg_fromfrom
					cede_province = event_target:regensburg_fromfrom
					if = {
						limit = {
							NOT = { is_claim = HAB }
							NOT = { is_core = HAB }
						}
						add_claim = HAB
					}
				}
			}
		}
	}
}

#Bavarians: They get ceded to us
country_event = {
	id = new_flavour_bav.2406
	title = new_flavour_bav.2405.name
	desc = new_flavour_bav.2406.desc
	picture = HRE_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.2406.opt
		add_treasury = -200
		HAB = {
			tooltip = { add_treasury = 200 }
			add_opinion = {
				who = root
				modifier = opinion_stole_free_city
			}
		}
		from = {
			every_owned_province = {
				add_core = root
				cede_province = root
				if = {
					limit = {
						NOT = { is_claim = HAB }
						NOT = { is_core = HAB }
					}
					add_claim = HAB
				}
			}
		}
	}
}



#Expires without having money demanded
country_event = {
	id = new_flavour_bav.25
	title = new_flavour_bav.25.name
	desc = new_flavour_bav.25.desc
	picture = CITY_VIEW_eventPicture

	fire_only_once = yes
	
	mean_time_to_happen = {
		years = 10
	}

	trigger = {
		tag = REG
		is_year = 1521
		has_reform = free_city
		emperor = {
			tag = HAB
		}
		NOT = { has_country_flag = REG_pay_demanded }
	}

	option = {
		name = new_flavour_bav.25.A

		add_treasury = -50
	}
}

#Money not demanded
country_event = {
	id = new_flavour_bav.26
	title = new_flavour_bav.26.name
	desc = new_flavour_bav.26.desc
	picture = CITY_VIEW_eventPicture

	is_triggered_only = yes

	option = {
		name = new_flavour_bav.26.A
	}
}


###End of that chain
#Bavaria Chafes under Denmark (second game age)
country_event = {
	id = new_flavour_bav.27
	title = new_flavour_bav.27.name
	desc = new_flavour_bav.27.desc
	picture = COURT_eventPicture

	fire_only_once = yes
	
	mean_time_to_happen = {
		years = 20
	}

	trigger = {
		tag = DAN
		current_age = age_of_reformation
		any_subject_country = {
			primary_culture = bavarian
			is_lesser_in_union = yes
			liberty_desire = 15
		}
	}

	immediate = {
		hidden_effect = {
			random_subject_country = {
				limit = {
					primary_culture = bavarian
					is_lesser_in_union = yes
					liberty_desire = 15
				}
				save_event_target_as = bavarian_lesser_union_member
			}
		}
	}

	option = {
		name = new_flavour_bav.27.A
		event_target:bavarian_lesser_union_member = {
			add_liberty_desire = 25

			capital_scope = {
				spawn_rebels = {
					leader = "Maximilian"
					leader_dynasty = "von Wittelsbach"
					type = pretender_rebels
					size = 3
					culture = bavarian
					religion = prev
				}
			}
		}
	}
}
