#Byz_startup for april fools stuff
on_startup = {
	#BR
	if = {
		limit = {
			has_global_flag = byz_resurgence_loaded
		}
		set_global_flag = bt_april_storms_passed
	}
}
#April fools fun stuff
on_monarch_death = {
	#BT
	#if = {
	#	limit = {
	#		has_reform = tanistry_reform
	#		NOT = { has_country_flag = bt_abolition_of_tanistry_succession }
	#	}
	#	set_country_flag = bt_tanistry_king_just_died
	#	clr_country_flag = bt_tanistry_high_queen_reigning
	#	remove_country_modifier = bt_uncertainty_about_a_high_queen
	#	remove_country_modifier = bt_tanistry_underaged_heir
	#	remove_country_modifier = bt_tanistry_female_heir
	#	remove_country_modifier = bt_tanistry_waiting_on_heir
	#}
	#April Fools:
	if = {
		limit = {
			has_global_flag = bt_storms_a_brewin
		}
		CSC = {
			if = {
				limit = {
					has_ruler = "Chairman Meow I"
				}
				define_heir = {
					name = "HR"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 5
					dip = 5
					mil = 5
					age = 30
					claim = 95
				}
				add_heir_personality = immortal_personality
			}
			else_if = {
				limit = {
					has_ruler = "HR I"
				}
				define_heir = {
					name = "Dub"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 5
					dip = 3
					mil = 6
					age = 28
					claim = 95
				}
				add_heir_personality = immortal_personality
			}
			else_if = {
				limit = {
					has_ruler = "Dub I"
				}
				define_heir = {
					name = "neo"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 5
					dip = 4
					mil = 5
					age = 25
					claim = 95
				}
				add_heir_personality = immortal_personality
			}
			else_if = {
				limit = {
					has_ruler = "neo I"
				}
				define_heir = {
					name = "Chrysocyon"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 6
					dip = 6
					mil = 3
					age = 25
					claim = 95
				}
				add_heir_personality = immortal_personality
			}
			else_if = {
				limit = {
					has_ruler = "Chrysocyon I"
				}
				define_heir = {
					name = "Nikicaga"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 6
					dip = 4
					mil = 4
					age = 24
					claim = 95
				}
				add_heir_personality = immortal_personality
			}
			else_if = {
				limit = {
					has_ruler = "Nikicaga I"
				}
				define_heir = {
					name = "Math5615"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 4
					dip = 4
					mil = 4
					age = 26
					claim = 95
				}
				add_heir_personality = immortal_personality
			}
			else_if = { #Cycle resets
				limit = {
					has_ruler = "Math5615 I"
				}
				define_heir = {
					name = "Draocht"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 6
					dip = 4
					mil = 5
					age = 30
					claim = 95
				}
				add_heir_personality = immortal_personality
			}
			else = { 
				define_heir = {
					name = "Chairman Meow"
					dynasty = "of Beyond the Pale"
					culture = celtic_irish_culture
					religion = animism
					adm = 3
					dip = 6
					mil = 4
					age = 25
					claim = 95
				}
				add_heir_personality = immortal_personality
				
			}
		}
	}
}
#Byz_estates
on_five_year_pulse_2 = {
	random_events = {		
		#BR
		# Strategoi
		100 = strategoi_estate_events.1
		100 = strategoi_estate_events.2
		100 = strategoi_estate_events.3
		100 = strategoi_estate_events.4 #Bonus
		100 = strategoi_estate_events.5
		100 = strategoi_estate_events.6
		100 = strategoi_estate_events.7
		100 = strategoi_estate_events.8
		100 = strategoi_estate_events.9
		100 = strategoi_estate_events.10 
		100 = strategoi_estate_events.11 
		400 = strategoi_estate_events.12 #Demands
		100 = strategoi_estate_events.13
		100 = strategoi_estate_events.14 
		
		# Exarches
		50 = exarches_estate_events.1
		50 = exarches_estate_events.2
		50 = exarches_estate_events.3
		100 = exarches_estate_events.4
	}
}

on_main_war_won = {
	events = {
		strategoi_estate_events.31
	}
	
}

on_battle_won_unit = {
	#Up Byzantine Militarization on won battles
	if = {
		limit = {
			unit_owner = {
				has_government_mechanic = byzantine_militarization_mechanic
				check_variable = {	#Check so overrun will not increase Protostrategos Prominence
					which = land_units_lost
					value = 1
				}
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			set_variable = {
				which = monarch_kill
				which = land_units_killed
			}
			set_variable = {
				which = monarch_losses
				which = land_units_lost
			}
			divide_variable = {
				which = monarch_kill
				value = 1000
			}
			divide_variable = {
				which = monarch_losses
				value = 1000
			}
			change_variable = {	#in order to avoid division by 0
				which = monarch_losses
				value = 1
			}
			divide_variable = {
				which = monarch_kill
				which = monarch_losses
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_kill
						value = 1
					}
				}
				change_variable = {
					which = monarch_kill
					value = -1
				}
				add_byzantine_militarization = { value = 1 }
			}
			multiply_variable = {
				which = monarch_kill
				value = 10
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_kill
						value = 1
					}
				}
				change_variable = {
					which = monarch_kill
					value = -1
				}
				add_byzantine_militarization = { value = 0.1 }
			}
		}
	}
}

on_battle_lost_unit = {
	#Drop Byzantine Militarization on lost battles
	if = { #Using the same idea as Ottoman Decadence, but instead, it gives 10 times as much militarization based on the ratio of troops killed, instead of upping decadence from losing more troops than the enemy.
		limit = {
			unit_owner = {
				has_government_mechanic = byzantine_militarization_mechanic
				check_variable = {	#Check so overrun will not decrease Protostrategos Prominence
					which = land_units_killed
					value = 1
				}
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			set_variable = {
				which = monarch_kill
				which = land_units_killed
			}
			set_variable = {
				which = monarch_losses
				which = land_units_lost
			}
			divide_variable = {
				which = monarch_kill
				value = 1000
			}
			divide_variable = {
				which = monarch_losses
				value = 1000
			}
			change_variable = {	#in order to avoid division by 0
				which = monarch_losses
				value = 1
			}
			divide_variable = {
				which = monarch_kill
				which = monarch_losses
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_losses
						value = 1
					}
				}
				change_variable = {
					which = monarch_losses
					value = -1
				}
				add_government_power = { 
					mechanic_type = byzantine_militarization_mechanic 
					power_type = byzantine_militarization
					value = -1
				}
			}
			multiply_variable = {
				which = monarch_losses
				value = 10
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_losses
						value = 1
					}
				}
				change_variable = {
					which = monarch_losses
					value = -1
				}
				add_government_power = { 
					mechanic_type = byzantine_militarization_mechanic 
					power_type = byzantine_militarization
					value = -0.1
				}
			}
		}
	}
}