#Faction System
#ZVENO
BUL_zveno_low_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_low_loyalty_increase_tt
	add_to_variable = { BUL_zveno_loyalty = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_zveno_loyalty
		min = 0
		max = 100
	}
}
BUL_zveno_low_popularity_increase_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_low_popularity_increase_tt
	add_to_variable = { BUL_zveno_popularity = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_zveno_popularity
		min = 0
		max = 100
	}
}

BUL_zveno_medium_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_medium_loyalty_increase_tt
	add_to_variable = { BUL_zveno_loyalty = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_zveno_loyalty
		min = 0
		max = 100
	}
}
BUL_zveno_medium_popularity_increase_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_medium_popularity_increase_tt
	add_to_variable = { BUL_zveno_popularity = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_zveno_popularity
		min = 0
		max = 100
	}
}

BUL_zveno_high_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_high_loyalty_increase_tt
	add_to_variable = { BUL_zveno_loyalty = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_zveno_loyalty
		min = 0
		max = 100
	}
}
BUL_zveno_high_popularity_increase_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_high_popularity_increase_tt
	add_to_variable = { BUL_zveno_popularity = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_zveno_popularity
		min = 0
		max = 100
	}
}

BUL_zveno_low_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_low_loyalty_decrease_tt
	add_to_variable = { BUL_zveno_loyalty = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_zveno_loyalty
		min = 0
		max = 100
	}
}
BUL_zveno_low_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_low_popularity_decrease_tt
	add_to_variable = { BUL_zveno_popularity = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_zveno_popularity
		min = 0
		max = 100
	}
}

BUL_zveno_medium_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_medium_loyalty_decrease_tt
	add_to_variable = { BUL_zveno_loyalty = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_zveno_loyalty
		min = 0
		max = 100
	}
}
BUL_zveno_medium_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_medium_popularity_decrease_tt
	add_to_variable = { BUL_zveno_popularity = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_zveno_popularity
		min = 0
		max = 100
	}
}

BUL_zveno_high_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_high_loyalty_decrease_tt
	add_to_variable = { BUL_zveno_loyalty = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_zveno_loyalty
		min = 0
		max = 100
	}
}
BUL_zveno_high_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_zveno_tt
	custom_effect_tooltip = BUL_high_popularity_decrease_tt
	add_to_variable = { BUL_zveno_popularity = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_zveno_popularity
		min = 0
		max = 100
	}
}

#BROAD SOCIALISTS
BUL_bs_low_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_low_loyalty_increase_tt
	add_to_variable = { BUL_bs_loyalty = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_bs_loyalty
		min = 0
		max = 100
	}
}
BUL_bs_low_popularity_increase_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_low_popularity_increase_tt
	add_to_variable = { BUL_bs_popularity = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_bs_popularity
		min = 0
		max = 100
	}
}

BUL_bs_medium_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_medium_loyalty_increase_tt
	add_to_variable = { BUL_bs_loyalty = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_bs_loyalty
		min = 0
		max = 100
	}
}
BUL_bs_medium_popularity_increase_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_medium_popularity_increase_tt
	add_to_variable = { BUL_bs_popularity = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_bs_popularity
		min = 0
		max = 100
	}
}

BUL_bs_high_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_high_loyalty_increase_tt
	add_to_variable = { BUL_bs_loyalty = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_bs_loyalty
		min = 0
		max = 100
	}
}
BUL_bs_high_popularity_increase_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_high_popularity_increase_tt
	add_to_variable = { BUL_bs_popularity = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_bs_popularity
		min = 0
		max = 100
	}
}

BUL_bs_low_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_low_loyalty_decrease_tt
	add_to_variable = { BUL_bs_loyalty = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_bs_loyalty
		min = 0
		max = 100
	}
}
BUL_bs_low_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_low_popularity_decrease_tt
	add_to_variable = { BUL_bs_popularity = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_bs_popularity
		min = 0
		max = 100
	}
}

BUL_bs_medium_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_medium_loyalty_decrease_tt
	add_to_variable = { BUL_bs_loyalty = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_bs_loyalty
		min = 0
		max = 100
	}
}
BUL_bs_medium_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_medium_popularity_decrease_tt
	add_to_variable = { BUL_bs_popularity = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_bs_popularity
		min = 0
		max = 100
	}
}

BUL_bs_high_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_high_loyalty_decrease_tt
	add_to_variable = { BUL_bs_loyalty = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_bs_loyalty
		min = 0
		max = 100
	}
}
BUL_bs_high_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_bs_tt
	custom_effect_tooltip = BUL_high_popularity_decrease_tt
	add_to_variable = { BUL_bs_popularity = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_bs_popularity
		min = 0
		max = 100
	}
}

#AGRARIAN UNION
BUL_bzns_low_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_low_loyalty_increase_tt
	add_to_variable = { BUL_bzns_loyalty = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_bzns_loyalty
		min = 0
		max = 100
	}
}
BUL_bzns_low_popularity_increase_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_low_popularity_increase_tt
	add_to_variable = { BUL_bzns_popularity = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_bzns_popularity
		min = 0
		max = 100
	}
}

BUL_bzns_medium_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_medium_loyalty_increase_tt
	add_to_variable = { BUL_bzns_loyalty = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_bzns_loyalty
		min = 0
		max = 100
	}
}
BUL_bzns_medium_popularity_increase_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_medium_popularity_increase_tt
	add_to_variable = { BUL_bzns_popularity = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_bzns_popularity
		min = 0
		max = 100
	}
}

BUL_bzns_high_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_high_loyalty_increase_tt
	add_to_variable = { BUL_bzns_loyalty = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_bzns_loyalty
		min = 0
		max = 100
	}
}
BUL_bzns_high_popularity_increase_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_high_popularity_increase_tt
	add_to_variable = { BUL_bzns_popularity = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_bzns_popularity
		min = 0
		max = 100
	}
}

BUL_bzns_low_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_low_loyalty_decrease_tt
	add_to_variable = { BUL_bzns_loyalty = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_bzns_loyalty
		min = 0
		max = 100
	}
}
BUL_bzns_low_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_low_popularity_decrease_tt
	add_to_variable = { BUL_bzns_popularity = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_bzns_popularity
		min = 0
		max = 100
	}
}

BUL_bzns_medium_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_medium_loyalty_decrease_tt
	add_to_variable = { BUL_bzns_loyalty = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_bzns_loyalty
		min = 0
		max = 100
	}
}
BUL_bzns_medium_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_medium_popularity_decrease_tt
	add_to_variable = { BUL_bzns_popularity = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_bzns_popularity
		min = 0
		max = 100
	}
}

BUL_bzns_high_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_high_loyalty_decrease_tt
	add_to_variable = { BUL_bzns_loyalty = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_bzns_loyalty
		min = 0
		max = 100
	}
}
BUL_bzns_high_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_bzns_tt
	custom_effect_tooltip = BUL_high_popularity_decrease_tt
	add_to_variable = { BUL_bzns_popularity = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_bzns_popularity
		min = 0
		max = 100
	}
}

#NATIONAL SOCIAL MOVEMENT
BUL_nsm_low_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_low_loyalty_increase_tt
	add_to_variable = { BUL_nsm_loyalty = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_nsm_loyalty
		min = 0
		max = 100
	}
}
BUL_nsm_low_popularity_increase_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_low_popularity_increase_tt
	add_to_variable = { BUL_nsm_popularity = BUL_faction_low_increase }
	clamp_variable = {
		var = BUL_nsm_popularity
		min = 0
		max = 100
	}
}

BUL_nsm_medium_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_medium_loyalty_increase_tt
	add_to_variable = { BUL_nsm_loyalty = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_nsm_loyalty
		min = 0
		max = 100
	}
}
BUL_nsm_medium_popularity_increase_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_medium_popularity_increase_tt
	add_to_variable = { BUL_nsm_popularity = BUL_faction_medium_increase }
	clamp_variable = {
		var = BUL_nsm_popularity
		min = 0
		max = 100
	}
}

BUL_nsm_high_loyalty_increase_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_high_loyalty_increase_tt
	add_to_variable = { BUL_nsm_loyalty = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_nsm_loyalty
		min = 0
		max = 100
	}
}
BUL_nsm_high_popularity_increase_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_high_popularity_increase_tt
	add_to_variable = { BUL_nsm_popularity = BUL_faction_high_increase }
	clamp_variable = {
		var = BUL_nsm_popularity
		min = 0
		max = 100
	}
}

BUL_nsm_low_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_low_loyalty_decrease_tt
	add_to_variable = { BUL_nsm_loyalty = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_nsm_loyalty
		min = 0
		max = 100
	}
}
BUL_nsm_low_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_low_popularity_decrease_tt
	add_to_variable = { BUL_nsm_popularity = BUL_faction_low_decrease }
	clamp_variable = {
		var = BUL_nsm_popularity
		min = 0
		max = 100
	}
}

BUL_nsm_medium_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_medium_loyalty_decrease_tt
	add_to_variable = { BUL_nsm_loyalty = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_nsm_loyalty
		min = 0
		max = 100
	}
}
BUL_nsm_medium_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_medium_popularity_decrease_tt
	add_to_variable = { BUL_nsm_popularity = BUL_faction_medium_decrease }
	clamp_variable = {
		var = BUL_nsm_popularity
		min = 0
		max = 100
	}
}

BUL_nsm_high_loyalty_decrease_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_high_loyalty_decrease_tt
	add_to_variable = { BUL_nsm_loyalty = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_nsm_loyalty
		min = 0
		max = 100
	}
}
BUL_nsm_high_popularity_decrease_effect = {
	custom_effect_tooltip = BUL_nsm_tt
	custom_effect_tooltip = BUL_high_popularity_decrease_tt
	add_to_variable = { BUL_nsm_popularity = BUL_faction_high_decrease }
	clamp_variable = {
		var = BUL_nsm_popularity
		min = 0
		max = 100
	}
}

BUL_communists_try_to_form_ff_effect = {
	set_variable = { BUL_ff_forming_probability = -100 } #The Fatherland Front can only be formed if this variable becomes greater than 0 during this check

	if = { #Having war is relatively important
		limit = {
			has_war = yes
		}
		add_to_variable = { BUL_ff_forming_probability = 15 }
		if = { #Having war against SOV is significant
			limit = {
				has_war_with = SOV
				OR = {
					NOT = { has_country_flag = BUL_at_war_with_the_soviets_flag }
					has_country_flag = { flag = BUL_at_war_with_the_soviets_flag days > 180 }
				}	
			}
			add_to_variable = { BUL_ff_forming_probability = 10 }
			if = { #Having war against communist SOV is very important
				limit = {
					SOV = { has_government = communism }
				}
				add_to_variable = { BUL_ff_forming_probability = 50 }
			}
		}
	}

	if = { #An ally being at war with SOV is important
		limit = {
			any_allied_country = {
				has_war_with = SOV
			}
		}
		add_to_variable = { BUL_ff_forming_probability = 25 }
		if = { #If SOV is communist then it becomes very important
			limit = {
				SOV = { has_government = communism }
			}
			add_to_variable = { BUL_ff_forming_probability = 75 }
		}
	}

	if = { #Communist SOV controlling any neighbor state is relatively important
		limit = {
			any_neighbor_country = {
				tag = SOV
			}
			SOV = { has_government = communism }
		}
		add_to_variable = { BUL_ff_forming_probability = 15 }
		if= { #Neighbor SOV being at war with Bulgaria or her allies is critical
			limit = {
				OR = {
					any_allied_country = {
						has_war_with = SOV
					}
					has_war_with = SOV
				}			
			}
			add_to_variable = { BUL_ff_forming_probability = 100 }
		}
	}

	if = { #SOV being communist is relatively important
		limit = {
			SOV = { has_government = communism }
		}
		add_to_variable = { BUL_ff_forming_probability = 15 }
	}

	randomize_temp_variable = {
		var = BUL_random_ff_forming_chance
		distribution = binomial
		min = 0
		max = 100
	}

	if = {
		limit = {
			check_variable = {
				var = BUL_ff_forming_probability
				value = BUL_random_ff_forming_chance 
				compare = greater_than_or_equals 
			}
		}
		country_event = { id = bftb_bulgaria_fatherland_front.1 hours = 16 random_hours = 16 }
	}
	log = "Fatherland Front probability: [?BUL.BUL_ff_forming_probability]"
	log = "Fatherland Front Random chance: [?BUL.BUL_random_ff_forming_chance]"
}

BUL_ff_approaches_a_faction_effect = {

	randomize_variable = {
		var = BUL_random_ff_approaching_faction_chance
		distribution = binomial
		min = 0
		max = 100
	}
	log = "FF Approaches faction random chance: [?BUL.BUL_random_ff_approaching_faction_chance]"
}

BUL_ff_preventive_action_taken = {
	add_to_variable = { BUL_ff_preventive_actions_against_coup = BUL_ff_preventive_actions_base_value }
	clamp_variable = {
		var = BUL_ff_preventive_actions_against_coup
		min = 0
		max = BUL_ff_preventive_actions_cap_value #This caps the player's ability to prevent the coup
	}
	custom_effect_tooltip = BUL_ff_preventive_action_taken_tt
}

BUL_ff_tries_to_stage_a_coup_effect = {
	#Make sure the coup will start under the specific circumstances on historical
	if = {
		limit = {
			is_historical_focus_on = yes
			BUL_historical_requirements_met = yes
		}
		log = "Forced Fatherland Front coup"
		country_event = { id = bftb_bulgaria_fatherland_front.2 hours = 4 random_hours = 4 }
		set_country_flag = BUL_forced_ff_coup_flag
	}
	#If historical requirements not met, do a regular check
	else = {
		set_variable = { BUL_ff_coup_probability = -100 } #The coup will only happen if this variable becomes greater than 0 during this check

		if = { #Having war is relatively important
			limit = {
				has_war = yes
			}
			add_to_variable = { BUL_ff_coup_probability = 15 }
			if = { #Having war against SOV is significant
				limit = {
					has_war_with = SOV
					OR = {
						NOT = { has_country_flag = BUL_at_war_with_the_soviets_flag }
						has_country_flag = { flag = BUL_at_war_with_the_soviets_flag days > 180 }
					}
				}
				add_to_variable = { BUL_ff_coup_probability = 10 }
				if = { #Having war against communist SOV is very important
					limit = {
						SOV = { has_government = communism }
					}
					add_to_variable = { BUL_ff_coup_probability = 40 } #Prev 50
				}
			}
		}

		if = { #An ally being at war with SOV is important
			limit = {
				any_allied_country = {
					has_war_with = SOV
				}
			}
			add_to_variable = { BUL_ff_coup_probability = 10 } #Prev 25
			if = { #If SOV is communist then it becomes very important
				limit = {
					SOV = { has_government = communism }
				}
				add_to_variable = { BUL_ff_coup_probability = 15 } #Prev 75
			}
		}

		if = { #Communist SOV controlling any neighbor state is relatively important
			limit = {
				any_neighbor_country = {
					tag = SOV
				}
				has_government = communism
			}
			add_to_variable = { BUL_ff_coup_probability = 5 }
			if = { #SOV controls one of our key states
				limit = {
					SOV = {
						any_controlled_state = {
							has_state_flag = BUL_initial_bulgarian_state_flag
							is_in_home_area = yes
						}
					}
				}
				add_to_variable = { BUL_ff_coup_probability = 15 }
				if= { #Neighbor SOV being at war with Bulgaria or her allies is critical
					limit = {
						OR = {
							any_allied_country = {
								has_war_with = SOV
							}
							has_war_with = SOV
						}			
					}
					add_to_variable = { BUL_ff_coup_probability = 100 }
				}
			}
		}

		if = { #SOV conquering Germany
			limit = {
				SOV = {
					any_controlled_state = {
						is_core_of = GER
					}
				}
			}
			add_to_variable = { BUL_ff_coup_probability = 5 }
			if = { #SOV conquering initial German states
				limit = {
					SOV = {
						any_controlled_state = {
							is_core_of = GER
							NOT = {
								state = 188
								state = 763
								state = 5
								state = 807
								state = 85
							}
						}
					}
				}
				add_to_variable = { BUL_ff_coup_probability = 15 }
			}
		}

		if = { #BUL losing key territory
			limit = {
				any_state = {
					has_state_flag = BUL_initial_bulgarian_state_flag
					controller = {
						has_war_with = ROOT
					}
				}
			}
			add_to_variable = { BUL_ff_coup_probability = 15 }
		}

		if = { #SOV being communist is relatively important
			limit = {
				SOV = { has_government = communism }
			}
			add_to_variable = { BUL_ff_coup_probability = 10 } #Prev 15
		}

		randomize_temp_variable = {
			var = BUL_random_ff_coup_chance
			distribution = binomial
			min = 0
			max = 100
		}

		if = {
			limit = {
				check_variable = {
					var = BUL_ff_coup_probability
					value = BUL_random_ff_coup_chance 
					compare = greater_than_or_equals 
				}
			}
			country_event = { id = bftb_bulgaria_fatherland_front.2 hours = 4 random_hours = 4 }
		}
		log = "[GetDateText] - Fatherland Front coup probability: [?BUL.BUL_ff_coup_probability]"
		log = "[GetDateText] - Fatherland Front coup Random chance: [?BUL.BUL_random_ff_coup_chance]"
	}
}

BUL_start_ff_civil_war = {
	set_variable = { BUL_communist_support_before_cw = party_popularity@communism }
	set_variable = { BUL_ff_coup_size = 0.15 }
	#Default state
	if = {
		limit = {
			controls_state = 211
		}
		211 = { set_state_flag = BUL_ff_state_flag }
	}
	#Bonuses from BS
	if = {
		limit = {
			has_country_flag = BUL_bs_joined_ff_flag 
		}
		add_to_variable = { BUL_ff_coup_size = 0.05 }
		if = {
			limit = {
				NOT = { has_country_flag = BUL_bs_destroyed_flag }
				NOT = { has_country_flag = BUL_bs_integrated_flag }
			}
			add_to_variable = { BUL_ff_coup_size = 0.05 }
			212 = { set_state_flag = BUL_ff_state_flag }
		}
	}
	#Bonuses from BZNS
	if = {
		limit = {
			has_country_flag = BUL_bzns_joined_ff_flag 
		}
		add_to_variable = { BUL_ff_coup_size = 0.05 }
		if = {
			limit = {
				NOT = { has_country_flag = BUL_bzns_destroyed_flag }
				NOT = { has_country_flag = BUL_bzns_integrated_flag }
			}
			add_to_variable = { BUL_ff_coup_size = 0.05 }
			801 = { set_state_flag = BUL_ff_state_flag } 
		}
	}
	#Bonuses from Greek partisans
	if = {
		limit = {
			has_country_flag = BUL_ff_organized_greek_partisans_flag
		}
		every_controlled_state = {
			limit = {
				is_core_of = GRE
				is_core_of = BUL
			}
			set_state_flag = BUL_ff_state_flag
		}
		if = {
			limit = {
				NOT = { 
					any_controlled_state = {
						has_state_flag = BUL_ff_state_flag
						is_core_of = GRE
					}
				}
			}
			random_controlled_state = {
				limit = {
					is_core_of = GRE
				}
				set_state_flag = BUL_ff_state_flag
			}
		}
	}
	#Bonuses from Yugoslavian partisans
	if = {
		limit = {
			has_country_flag = BUL_ff_organized_yugoslavian_partisans_flag
		}
		every_controlled_state = {
			limit = {
				is_core_of = YUG
				is_core_of = BUL
				NOT = { state = 106 }
			}
			set_state_flag = BUL_ff_state_flag
		}
		if = {
			limit = {
				NOT = { 
					any_controlled_state = {
						is_core_of = YUG
						has_state_flag = BUL_ff_state_flag
					}
				}
			}
			random_controlled_state = {
				limit = {
					is_core_of = YUG
					NOT = { state = 106 }
				}
				set_state_flag = BUL_ff_state_flag
			}
		}
	}
	#Bonuses from ZVENO
	if = {
		limit = {
			has_country_flag = BUL_zveno_joined_ff_flag 
		}
		add_to_variable = { BUL_ff_coup_size = 0.1 }
		if = {
			limit = {
				NOT = { has_country_flag = BUL_zveno_destroyed_flag }
				NOT = { has_country_flag = BUL_zveno_integrated_flag }
			}
			add_to_variable = { BUL_ff_coup_size = 0.25 }
			48 = { set_state_flag = BUL_ff_state_flag } 
			#Manage capital for original BUL
			if = {
				limit = {
					any_owned_state = {
						is_core_of = ROOT
						NOT = { has_state_flag = BUL_ff_state_flag }
					}
				}
				random_owned_state = {
					limit = {
						is_core_of = ROOT
						NOT = { has_state_flag = BUL_ff_state_flag }
					}
					ROOT = { set_capital = { state = PREV } }
				}
			}
			else = {
				random_controlled_state = {
					limit = {
						NOT = { has_state_flag = BUL_ff_state_flag }
					}
					ROOT = { set_capital = { state = PREV } }
				}
			}
		}
	}

	log = "Fatherland coup size: [?BUL.BUL_ff_coup_size]"

	#Set FF capital based on the states they get in the split
	if = {
		limit = {
			48 = { has_state_flag = BUL_ff_state_flag } #Sofia is FF's capital
		}
		#START CIVIL WAR
		start_civil_war = {
			ideology = communism
			size = BUL_ff_coup_size
			capital = 48
			states = all
			states_filter = {
				has_state_flag = BUL_ff_state_flag
			}
		}
	}
	else_if = {
		limit = {
			212 = { has_state_flag = BUL_ff_state_flag } #Plovdiv is FF's capital
		}
		#START CIVIL WAR
		start_civil_war = {
			ideology = communism
			size = BUL_ff_coup_size
			capital = 212
			states = all
			states_filter = {
				has_state_flag = BUL_ff_state_flag
			}
		}
	}
	else = {	#Varna is FF's capital
		#START CIVIL WAR
		start_civil_war = {
			ideology = communism
			size = BUL_ff_coup_size
			capital = 211
			states = all
			states_filter = {
				has_state_flag = BUL_ff_state_flag
			}
		}
	}

	clr_country_flag = BUL_factions_unlocked_flag

	random_country = {
		limit = {
			original_tag = BUL
			has_government = communism
			NOT = { has_country_flag = BUL_ff_civil_war_flag }
		}
		set_country_flag = BUL_fatherland_front_flag
		set_cosmetic_tag = BUL_ff_bulgaria

		division_template = {
			name = "Fatherland Front Militia"
			priority = 1
			is_locked = yes
			division_names_group = BUL_INF_04
			regiments = {
				infantry = { x = 0 y = 0 }
				infantry = { x = 0 y = 1 }
				infantry = { x = 0 y = 2 }
			}
		}

		division_template = {
			name = "Fatherland Front Partisans"
			priority = 1
			is_locked = yes
			division_names_group = BUL_INF_06
			regiments = {
				infantry = { x = 0 y = 0 }
				infantry = { x = 0 y = 1 }
				infantry = { x = 0 y = 1 }
			}
		}

		#Spawn FATHERLAND FRONT MILITIAS
		#Cored states
		every_owned_state = {
			limit = {
				OR = {
					has_state_flag = BUL_initial_bulgarian_state_flag
					state = 803 #Southern Serbia
					state = 77 #Dobrudja
				}
			}
			create_unit = {
				division = "division_template = \"Fatherland Front Militia\" start_experience_factor = 0.25"  
				owner = PREV
			}
		}
		if = {
			limit = {
				check_variable = { BUL_communist_support_before_cw = 15 compare = greater_than_or_equals }
			}
			every_owned_state = {
				limit = {
					has_state_flag = BUL_initial_bulgarian_state_flag
				}
				create_unit = {
					division = "division_template = \"Fatherland Front Militia\" start_experience_factor = 0.15"  
					owner = PREV
				}
			}
			if = {
				limit = {
					check_variable = { BUL_communist_support_before_cw = 30 compare = greater_than_or_equals }
				}
				every_owned_state = {
					limit = {
						has_state_flag = BUL_initial_bulgarian_state_flag
					}
					create_unit = {
						division = "division_template = \"Fatherland Front Militia\" start_experience_factor = 0.1"  
						owner = PREV
					}
				}
			}
		}
		#Bonus from BS in the FF
		if = {
			limit = {
				has_country_flag = BUL_bs_joined_ff_flag 
				owns_state = 212
			}
			212 = {
				create_unit = {
					division = "division_template = \"Fatherland Front Militia\" start_experience_factor = 0.15"  
					owner = PREV
				}
				create_unit = {
					division = "division_template = \"Fatherland Front Militia\" start_experience_factor = 0.15"  
					owner = PREV
				}
			}
		}
		#Bonus from BZNS in the FF
		if = {
			limit = {
				has_country_flag = BUL_bs_joined_ff_flag 
				owns_state = 801
			}
			801 = {
				create_unit = {
					division = "division_template = \"Fatherland Front Militia\" start_experience_factor = 0.1"  
					owner = PREV
				}
				create_unit = {
					division = "division_template = \"Fatherland Front Militia\" start_experience_factor = 0.1"  
					owner = PREV
				}
			}
		}

		#Greek states
		if = {
			limit = { 
				ROOT = { has_country_flag = BUL_ff_organized_greek_partisans_flag }
			}
			#Greek controlled states
			every_owned_state = {
				limit = {
					has_state_flag = BUL_ff_state_flag
					is_core_of = GRE
				}
				create_unit = {
					division = "division_template = \"Fatherland Front Partisans\" start_experience_factor = 0.2" 
					owner = PREV
					count = 1
				}
			}
			#Greek non-controlled states
			random_state = {
				limit = {
					owner = { has_country_flag = BUL_ff_civil_war_flag }
					is_core_of = GRE
				}
				create_unit = {
					division = "division_template = \"Fatherland Front Partisans\" start_experience_factor = 0.4"
					owner = PREV
					allow_spawning_on_enemy_provs = yes
					count = 2
				}
			}
		}
		
		#Yugoslavian states
		if = {
			limit = { 
				ROOT = { has_country_flag = BUL_ff_organized_yugoslavian_partisans_flag }
			}
			#Yugoslavian controlled states
			every_owned_state = {
				limit = {
					has_state_flag = BUL_ff_state_flag
					is_core_of = YUG
				}
				create_unit = {
					division = "division_template = \"Fatherland Front Partisans\" start_experience_factor = 0.2" 
					owner = PREV
					count = 1
				}
			}
			#Yugoslavian non-controlled states
			random_state = {
				limit = {
					owner = { has_country_flag = BUL_ff_civil_war_flag }
					is_core_of = YUG
				}
				create_unit = {
					division = "division_template = \"Fatherland Front Partisans\" start_experience_factor = 0.4"
					owner = PREV
					allow_spawning_on_enemy_provs = yes
					count = 2
				}
			}
		}

		#Generals
		every_unit_leader = {
			limit = {
				NOT = { has_trait = trait_BUL_ff_sympathizer }
			}
			set_nationality = ROOT
		}
		ROOT = {
			every_unit_leader = {
				limit = {
					has_trait = trait_BUL_ff_sympathizer
				}
				set_nationality = PREV.PREV
			}
		}
		random_unit_leader = {
			limit = {
				has_id = 1203 #Hadzhipetkov
			}
			promote_leader = yes
		}

		#Operatives in the FF
		if = {
			limit = {
				has_dlc = "La Resistance"
			}
			every_operative = {
				limit = {
					has_trait = trait_BUL_tsar_loyalist
				}
				set_nationality = BUL
			}
		}
	}
	#Operatives in original BUL
	if = {
		limit = {
			has_dlc = "La Resistance"
		}
		every_operative = {
			limit = {
				has_trait = trait_BUL_ff_sympathizer
			}
			set_nationality = BUF
		}
		if = {
			limit = {
				has_country_flag = BUL_zveno_joined_ff_flag
			}
			every_operative = {
				limit = {
					has_trait = trait_BUL_zveno_member
				}
				set_nationality = BUF
			}
		}
	}

	#FF joins SOV's faction and wars and give Military Access
	if = {
		limit = {
			country_exists = SOV
			has_war_with = SOV
			SOV = { has_government = communism }
		}
		if = {
			limit = {
				SOV = { is_in_faction = yes }
			}
			SOV = {
				faction_leader = {
					add_to_faction = BUF
				}
			}
		}
		if = {
			limit = {
				any_country = {
					has_war_with = SOV
					is_in_faction_with = BUL
					NOT = {	has_country_flag = BUL_ff_civil_war_flag }
				}
			}
			every_country = {
				limit = {
					has_war_with = SOV
					is_in_faction_with = BUL
					NOT = {	has_country_flag = BUL_ff_civil_war_flag }
				}
				BUF = {
					add_to_war = { targeted_alliance = SOV enemy = PREV hostility_reason = asked_to_join }
				}
			}
		}
	}
	diplomatic_relation = {
		country = SOV
		relation = military_access
		active = yes
	}
	SOV = {
		diplomatic_relation = {
			country = BUF
			relation = military_access
			active = yes
		}
	}
}

BUL_get_random_bulgarian_destination_royal_visit = { #This works together with scripted loc
	random_list = {
		10 = {
			modifier = {
				factor = 0
				48 = { is_capital = yes } #No point on visiting your own city...
			}
			set_variable = { BUL_tsars_destination = 1 } # Sofia
		}
		10 = {
			set_variable = { BUL_tsars_destination = 2 } # Plovdiv
		}
		10 = {
			set_variable = { BUL_tsars_destination = 3 } # Ruse
		}
		10 = {
			set_variable = { BUL_tsars_destination = 4 } # Varna
		}
		10 = {
			set_variable = { BUL_tsars_destination = 5 } # Burgas
		}
		10 = {
			set_variable = { BUL_tsars_destination = 6 } # Vidin
		}
		10 = {
			set_variable = { BUL_tsars_destination = 7 } # Tarnovo
		}
		10 = {
			set_variable = { BUL_tsars_destination = 8 } # Stara Zagora
		}
		10 = {
			set_variable = { BUL_tsars_destination = 9 } # Haskovo
		}
		10 = {
			set_variable = { BUL_tsars_destination = 10 } # Shumen
		}
		10 = {
			set_variable = { BUL_tsars_destination = 11 } # Sliven
		}
		10 = {
			set_variable = { BUL_tsars_destination = 12 } # Yambol
		}
		10 = {
			set_variable = { BUL_tsars_destination = 13 } # Pleven
		}
		10 = {
			set_variable = { BUL_tsars_destination = 14 } # Dobrich
			modifier = {
				factor = 0
				NOT = {
					77 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
		10 = {
			set_variable = { BUL_tsars_destination = 15 } # Skopje
			modifier = {
				factor = 0
				NOT = {
					106 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
		10 = {
			set_variable = { BUL_tsars_destination = 16 } # Ohrid
			modifier = {
				factor = 0
				NOT = {
					106 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
		10 = {
			set_variable = { BUL_tsars_destination = 17 } # Leskovac
			modifier = {
				factor = 0
				NOT = {
					803 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
	}
}

BUL_get_random_bulgarian_destination_march = { #This works together with scripted loc
	random_list = {
		10 = {
			modifier = {
				factor = 0
				48 = { is_capital = yes } #No point on marching from Sofia to Sofia...
			}
			set_variable = { BUL_march_destination = 1 } # Sofia
		}
		10 = {
			set_variable = { BUL_march_destination = 2 } # Plovdiv
		}
		10 = {
			set_variable = { BUL_march_destination = 3 } # Ruse
		}
		10 = {
			set_variable = { BUL_march_destination = 4 } # Varna
		}
		10 = {
			set_variable = { BUL_march_destination = 5 } # Burgas
		}
		10 = {
			set_variable = { BUL_march_destination = 6 } # Vidin
		}
		10 = {
			set_variable = { BUL_march_destination = 7 } # Tarnovo
		}
		10 = {
			set_variable = { BUL_march_destination = 8 } # Stara Zagora
		}
		10 = {
			set_variable = { BUL_march_destination = 9 } # Haskovo
		}
		10 = {
			set_variable = { BUL_march_destination = 10 } # Shumen
		}
		10 = {
			set_variable = { BUL_march_destination = 11 } # Sliven
		}
		10 = {
			set_variable = { BUL_march_destination = 12 } # Yambol
		}
		10 = {
			set_variable = { BUL_march_destination = 13 } # Pleven
		}
		10 = {
			set_variable = { BUL_march_destination = 14 } # Dobrich
			modifier = {
				factor = 0
				NOT = {
					77 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
		10 = {
			set_variable = { BUL_march_destination = 15 } # Skopje
			modifier = {
				factor = 0
				NOT = {
					106 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
		10 = {
			set_variable = { BUL_march_destination = 16 } # Ohrid
			modifier = {
				factor = 0
				NOT = {
					106 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
		10 = {
			set_variable = { BUL_march_destination = 17 } # Leskovac
			modifier = {
				factor = 0
				NOT = {
					803 = {
						is_owned_by = BUL
						is_core_of = BUL
					}
				}
			}
		}
	}
}

BUL_replace_national_industrial_designer = {
	if = {
		limit = {
			has_idea =  BUL_petrol_ad
		}
		swap_ideas = {
			remove_idea = BUL_petrol_ad
			add_idea = BUL_petrol_ad_improved
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_ira
		}
		swap_ideas = {
			remove_idea = BUL_ira
			add_idea = BUL_ira_improved
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_pirin
		}
		swap_ideas = {
			remove_idea = BUL_pirin
			add_idea = BUL_pirin_improved
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_vulkan_cement
		}
		swap_ideas = {
			remove_idea = BUL_vulkan_cement
			add_idea = BUL_vulkan_cement_improved
		}
	}	
}

BUL_replace_national_naval_designer = {
	if = {
		limit = {
			has_idea = BUL_varna_naval_dockyard
		}
		custom_effect_tooltip = BUL_replace_national_naval_designer_tt
		hidden_effect = {
			swap_ideas = {
				remove_idea = BUL_varna_naval_dockyard
				add_idea = BUL_varna_naval_dockyard_improved
			}
		}
	}
	else = {
		custom_effect_tooltip = BUL_replace_national_naval_designer_tt
	}
}

BUL_replace_national_aircraft_designer = {
	if = {
		limit = {
			has_idea = BUL_dar
		}
		swap_ideas = {
			remove_idea = BUL_dar
			add_idea = BUL_dar_improved
		}
	}
	if = {
		limit = {
			has_idea = BUL_kaproni_bulgarski
		}
		swap_ideas = {
			remove_idea = BUL_kaproni_bulgarski
			add_idea = BUL_kaproni_bulgarski_improved
		}
	}
	if = {
		limit = {
			has_idea = BUL_dvf
		}
		swap_ideas = {
			remove_idea = BUL_dvf
			add_idea = BUL_dvf_improved
		}
	}
	if = {
		limit = {
			has_idea = BUL_dvf_sopot
		}
		swap_ideas = {
			remove_idea = BUL_dvf_sopot
			add_idea = BUL_dvf_sopot_improved
		}
	}
}

BUL_set_buz_faction_values = {
	set_country_flag = BUL_factions_unlocked_flag
	set_variable = { BUL_zveno_loyalty = 15 }
	set_variable = { BUL_zveno_popularity = 50 }
	set_variable = { BUL_bs_loyalty = 25 }
	set_variable = { BUL_bs_popularity = 60 }
	set_variable = { BUL_bzns_loyalty = 30 }
	set_variable = { BUL_bzns_popularity = 70 }
	set_variable = { BUL_nsm_loyalty = 60 }
	set_variable = { BUL_nsm_popularity = 40 }
	set_variable = { BUL_faction_interaction_cost_standard = 20 }
	set_variable = { BUL_broad_socialist_opression_cost_standard = 20 }
	set_variable = { BUL_faction_days_remove_very_low = 7 } #Allow Speech, Discredit, Repress
	set_variable = { BUL_faction_days_remove_low = 14 } #Joint Act, Ban Media, Anti-faction Speech
	set_variable = { BUL_faction_days_remove_medium = 21 } #Bolster Zveno, Imprison leaders
	set_variable = { BUL_faction_days_remove_high = 30 } #Legalize, Fund, Appoint, Raid, Destroy
	set_variable = { BUL_faction_days_remove_very_high = 60 } #Integrate
	set_variable = { BUL_faction_days_reenable_low = 7 } #Allow Speech, Discredit
	set_variable = { BUL_faction_days_reenable_medium = 14 } #Joint Act, Anti-faction Speech
	set_variable = { BUL_faction_days_reenable_high = 60 } #Fund
	set_variable = { BUL_faction_days_reenable_very_high = 120 } #Raid
	set_variable = { BUL_faction_low_increase = 5 }
	set_variable = { BUL_faction_medium_increase = 10 }
	set_variable = { BUL_faction_high_increase = 15 }
	set_variable = { BUL_faction_low_decrease = -5 }
	set_variable = { BUL_faction_medium_decrease = -10 }
	set_variable = { BUL_faction_high_decrease = -15 }
	set_variable = { BUL_ff_missions_base_days_to_add = 60 } #Base amount of days to be added to Impending FF Coup mission
	set_variable = { BUL_ff_missions_popularity_factor = 1 } #More popularity means more days to add
	set_variable = { BUL_ff_missions_loyalty_factor = 1 } #More loyalty means less days to add
	set_variable = { BUL_ff_preventive_actions_against_coup = 0 } #This will be used to reduce the chances of the FF staging the coup after they have planned it
	set_variable = { BUL_ff_preventive_actions_base_value = 5 } #The value added to the variable above every time a decision to prevent the coup is taken
	set_variable = { BUL_ff_preventive_actions_cap_value = 50 } #This is a cap to the player's ability to prevent the coup
	set_variable = { BUL_purchase_equipment_cost = 25 }
	set_variable = { BUL_foreign_military_agreements_cost = 50 }
	set_variable = { BUL_german_civ_industries_cost = 75 }
	set_variable = { BUL_british_civ_industries_cost = 75 }
	set_variable = { BUL_soviet_civ_industries_cost = 75 }
	set_variable = { BUL_foreign_industry_consumer_goods_modifier = 0 } #Used by Foreign Industry Dynamic Modifier
	set_variable = { BUL_foreign_industry_production_efficiency_modifier = -0.05 } #Used by Foreign Industry Dynamic Modifier
	set_variable = { BUL_foreign_industry_construction_speed_modifier = -0.1 } #Used by Foreign Industry Dynamic Modifier
	set_variable = { BUL_german_industrial_investments = 0 }
	set_variable = { BUL_british_industrial_investments = 0 }
	set_variable = { BUL_soviet_industrial_investments = 0 }
	set_variable = { BUL_industrial_investments_basic_cap = 3 }
	set_variable = { BUL_industrial_investments_medium_cap = 5 }
	set_variable = { BUL_industrial_investments_max_cap = 10 }
	#IMRO
	set_variable = { BUL_imro_garrisons_mp_value = 5000 }
	#Purchase foreign equipment
	set_variable = { BUL_quantity_purchased_infantry_equipment = 1000 }
	set_variable = { BUL_quantity_purchased_artillery = 100 }
	set_variable = { BUL_quantity_purchased_motorized = 100 }
	set_variable = { BUL_quantity_purchased_mechanized = 50 }
	set_variable = { BUL_quantity_purchased_armored_car = 50 }
	set_variable = { BUL_quantity_purchased_light_armor = 40 }
	set_variable = { BUL_quantity_purchased_medium_armor = 20 }
	set_variable = { BUL_quantity_purchased_heavy_armor = 10 }
	set_variable = { BUL_quantity_purchased_fighter = 40 }
	set_variable = { BUL_quantity_purchased_naval_bomber = 30 }
	set_variable = { BUL_quantity_purchased_tactical_bomber = 20 }
	#Plot Against Boris
	set_variable = { BUL_regicide_execution_time = 90 }
	#Free Balkan States dynamic modifier (NS)
	set_variable = { BUL_our_duty_in_the_balkans_consumer_goods_modifier = -0.03 }
	set_variable = { BUL_our_duty_in_the_balkans_stability_modifier = 0.05 }
	#Monthly extra chance of Boris dieing of "natural causes" (increased by 5 each month from 1943.1.1)
	set_variable = { BUL_tsar_boris_death_monthly_probability_factor = 0 }

	randomize_variable = {
		var = BUL_tsars_destination
		distribution = uniform
		min = 2
		max = 13
	}
	round_variable = BUL_tsars_destination
	randomize_variable = {
		var = BUL_march_destination
		distribution = uniform
		min = 2
		max = 13
	}
	round_variable = BUL_march_destination
}

#Adds hidden NS granting attack & defense bonuses against the appropriate country (FROM - scope comes from "The Anti-Capitalist Fight" or "Toppling Giants" Focus)
BUL_add_hidden_targeted_ns = {
	if = {
		limit = {
			original_tag = ENG
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_eng
		}
	}
	else_if = {
		limit = {
			original_tag = FRA
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_fra
		}
	}
	else_if = {
		limit = {
			original_tag = GER
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_ger
		}
	}
	else_if = {
		limit = {
			original_tag = ITA
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_ita
		}
	}
	else_if = {
		limit = {
			original_tag = SOV
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_sov
		}
	}
	else_if = {
		limit = {
			original_tag = POR
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_por
		}
	}
	else_if = {
		limit = {
			original_tag = SPR
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_spr
		}
	}
	else_if = {
		limit = {
			original_tag = IRE
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_ire
		}
	}
	else_if = {
		limit = {
			original_tag = HOL
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_hol
		}
	}
	else_if = {
		limit = {
			original_tag = BEL
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_bel
		}
	}
	else_if = {
		limit = {
			original_tag = LUX
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_lux
		}
	}
	else_if = {
		limit = {
			original_tag = SWI
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_swi
		}
	}
	else_if = {
		limit = {
			original_tag = AUS
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_aus
		}
	}
	else_if = {
		limit = {
			original_tag = CZE
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_cze
		}
	}
	else_if = {
		limit = {
			original_tag = HUN
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_hun
		}
	}
	else_if = {
		limit = {
			original_tag = YUG
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_yug
		}
	}
	else_if = {
		limit = {
			original_tag = ALB
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_alb
		}
	}
	else_if = {
		limit = {
			original_tag = GRE
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_gre
		}
	}
	else_if = {
		limit = {
			original_tag = TUR
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_tur
		}
	}
	else_if = {
		limit = {
			original_tag = ROM
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_rom
		}
	}
	else_if = {
		limit = {
			original_tag = POL
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_pol
		}
	}
	else_if = {
		limit = {
			original_tag = EST
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_est
		}
	}
	else_if = {
		limit = {
			original_tag = LAT
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_lat
		}
	}
	else_if = {
		limit = {
			original_tag = LIT
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_lit
		}
	}
	else_if = {
		limit = {
			original_tag = SWE
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_swe
		}
	}
	else_if = {
		limit = {
			original_tag = FIN
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_fin
		}
	}
	else_if = {
		limit = {
			original_tag = NOR
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_nor
		}
	}
	else_if = {
		limit = {
			original_tag = DEN
		}
		ROOT = {
			add_ideas = BUL_anti_capitalism_den
		}
	}
}

BUL_add_improved_prussia_of_the_balkans_ns = {
	if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_01
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_01
			add_idea = BUL_prussia_of_the_balkans_02
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_02
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_02
			add_idea = BUL_prussia_of_the_balkans_03
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_03
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_03
			add_idea = BUL_prussia_of_the_balkans_04
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_weakened_01
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_weakened_01
			add_idea = BUL_prussia_of_the_balkans_01
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_weakened_02
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_weakened_02
			add_idea = BUL_prussia_of_the_balkans_weakened_01
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_weakened_03
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_weakened_03
			add_idea = BUL_prussia_of_the_balkans_02
		}
	}
}

BUL_add_weakened_prussia_of_the_balkans_ns = {
	if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_01
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_01
			add_idea = BUL_prussia_of_the_balkans_weakened_01
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_02
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_02
			add_idea = BUL_prussia_of_the_balkans_01
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_03
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_03
			add_idea = BUL_prussia_of_the_balkans_02
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_weakened_01
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_weakened_01
			add_idea = BUL_prussia_of_the_balkans_weakened_02
		}
	}
	else_if = {
		limit = {
			has_idea = BUL_prussia_of_the_balkans_weakened_02
		}
		swap_ideas = {
			remove_idea = BUL_prussia_of_the_balkans_weakened_02
			add_idea = BUL_prussia_of_the_balkans_weakened_03
		}
	}
}

BUL_tsar_boris_may_die_effect = {
	set_variable = { BUL_tsar_boris_death_probability = -100 } #Boris may die only if this variable becomes greater than 0 during this check

	if = { #Having war against a major is relatively important
		limit = {
			any_enemy_country = {
				is_major = yes
			}
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 15 }
		if = { #Having war against main majors is significant
			limit = {
				OR = {
					has_war_with = SOV
					has_war_with = GER
					has_war_with = ENG
				}
			}
			add_to_variable = { BUL_tsar_boris_death_probability = 10 }
		}
	}

	if = { #An ally being at war with SOV while BUL is not is important
		limit = {
			any_allied_country = {
				has_war_with = SOV
			}
			BUL = { NOT = { has_war_with = SOV } }
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 25 }
	}

	if = { #Faction leader having different ideology is important
		limit = {
			any_allied_country = {
				is_faction_leader = yes
				NOT = { has_government = ROOT }
			}
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 25 }
	}

	if = { #Low Non-Aligned support is important
		limit = {
			neutrality < 0.1
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 25 }
	}
	else_if = {
		limit = {
			neutrality < 0.25
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 20 }
	}
	else_if = {
		limit = {
			neutrality < 0.5
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 15 }
	}

	if = { #Low Stability support is important
		limit = {
			has_stability < 0.1
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 50 }
	}
	else_if = {
		limit = {
			has_stability < 0.25
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 35 }
	}
	else_if = {
		limit = {
			has_stability < 0.5
		}
		add_to_variable = { BUL_tsar_boris_death_probability = 25 }
	}

	add_to_variable = { BUL_tsar_boris_death_probability = BUL_tsar_boris_death_monthly_probability_factor }

	randomize_temp_variable = {
		var = BUL_random_tsar_boris_death_chance
		distribution = binomial
		min = 0
		max = 100
	}

	if = {
		limit = {
			check_variable = {
				var = BUL_tsar_boris_death_probability
				value = BUL_random_tsar_boris_death_chance 
				compare = greater_than_or_equals 
			}
		}
		country_event = { id = bftb_bulgaria_tsar_boris.2 days = 15 random_days = 13 }
	}

	add_to_variable = { BUL_tsar_boris_death_monthly_probability_factor = 5 } #Increase 5% each month.
}

BUL_halve_faction_management_decision_times = {
	divide_variable = { BUL_faction_days_remove_very_low = 2 }
	round_variable = BUL_faction_days_remove_very_low
	divide_variable = { BUL_faction_days_remove_low = 2 }
	round_variable = BUL_faction_days_remove_low
	divide_variable = { BUL_faction_days_remove_medium = 2 }
	round_variable = BUL_faction_days_remove_medium
	divide_variable = { BUL_faction_days_remove_high = 2 }
	round_variable = BUL_faction_days_remove_high
	divide_variable = { BUL_faction_days_remove_very_high = 2 }
	round_variable = BUL_faction_days_remove_very_high
	divide_variable = { BUL_faction_days_reenable_low = 2 }
	round_variable = BUL_faction_days_reenable_low
	divide_variable = { BUL_faction_days_reenable_medium = 2 }
	round_variable = BUL_faction_days_reenable_medium
	divide_variable = { BUL_faction_days_reenable_high = 2 }
	round_variable = BUL_faction_days_reenable_high
	divide_variable = { BUL_faction_days_reenable_very_high = 2 }
	round_variable = BUL_faction_days_reenable_very_high
}

BUL_join_wars_of_from = {
	hidden_effect = {
		every_other_country = {
			limit = {
				has_war_with = FROM
				NOT = { is_in_faction_with = ROOT }
			}
			ROOT = {
				add_to_war = {
					targeted_alliance = FROM
					enemy = PREV
					hostility_reason = asked_to_join
				}
			}
		}
	}
}

BUL_remove_balkan_opinion_modifiers = { #Requires scoping to the other country joining Bulgaria's faction or being puppeted by Bulgaria
	hidden_effect = {
		remove_opinion_modifier = {
			target = BUL
			modifier = BFTB_balkan_pact_enemy
		}
		remove_opinion_modifier = {
			target = BUL
			modifier = BFTB_incongruous_neighbors
		}
		BUL = {
			remove_opinion_modifier = {
				target = PREV
				modifier = BFTB_incongruous_neighbors
			}
		}
	}
}

#Apply appropriate cosmetic tag so that 3D models change based on ideology
BUL_set_appropriate_cosmetic_tag = {
	if = {
		limit = { original_tag = BUL }
		if = {
			limit = { has_country_flag = BUL_tbe_flag }
			if = {
				limit = { has_government = communism }
				set_cosmetic_tag = TBE_third_bulgarian_empire_communism
			}
			else_if = {
				limit = { has_government = democratic }
				set_cosmetic_tag = TBE_third_bulgarian_empire_democratic
			}
			else_if = {
				limit = { has_government = fascism }
				set_cosmetic_tag = TBE_third_bulgarian_empire_fascism
			}
			else = {
				set_cosmetic_tag = TBE_third_bulgarian_empire_neutrality
			}
		}
		else_if = {
			limit = { has_country_flag = BUL_ubf_flag }
			if = {
				limit = { has_government = communism }
				set_cosmetic_tag = UBF_united_balkan_federation_communism
			}
			else_if = {
				limit = { has_government = democratic }
				set_cosmetic_tag = UBF_united_balkan_federation_democratic
			}
			else_if = {
				limit = { has_government = fascism }
				set_cosmetic_tag = UBF_united_balkan_federation_fascism
			}
			else = {
				set_cosmetic_tag = UBF_united_balkan_federation_neutrality
			}
		}
	}
}
