

# Gas Demand-Offer
# set_temp_variable = { temp_opinion = -+ # }


#############
#####EOC#####
#############
eoc_set_initial_values_budget = {
	set_variable = { military_budget_gdp_percentage = 5}
	set_variable = { healthcare_budget_gdp_percentage = 5}
	set_variable = { foreign_budget_gdp_percentage = 5}
	set_variable = { economy_budget_gdp_percentage = 5}
	set_variable = { work_budget_gdp_percentage = 5}
	set_variable = { eoc_treasury = 0.50}
	set_variable = { eoc_debt = 0 }
}


eoc_surplus_deficit_budget = {
		
	set_variable = {deficit_surplus = total_revenue}
	subtract_from_variable = { deficit_surplus = budget_expenditure }
	#multiply_variable = { deficit_surplus = -1}
	subtract_from_variable = { deficit_surplus = eoc_interests}

	eoc_debt_interests = yes

	if = {
		limit = {
			AND = {
				check_variable = { budget_expenditure > total_revenue }	
				check_variable = { eoc_treasury > deficit_surplus }
			}
		}
		if = {
			limit = {
				check_variable = { deficit_surplus > 0 }
			}
			add_to_variable = { eoc_treasury = deficit_surplus }
		}
		else_if = {
			limit = {
				check_variable = { deficit_surplus < 0 }
			}
			add_to_variable = { eoc_treasury = deficit_surplus }
		}
		
	}
	else_if = {
		limit = {
			AND = {
				check_variable = { budget_expenditure < total_revenue }	
				check_variable = { eoc_treasury > deficit_surplus }
			}
		}

		add_to_variable = { eoc_treasury = deficit_surplus }		
	}
	else_if = {
		limit = {
			AND = {
				check_variable = { budget_expenditure < total_revenue }	
				check_variable = { eoc_treasury < deficit_surplus }
			}
		}

		add_to_variable = { eoc_treasury = deficit_surplus }
	}	
	else_if = {
		limit = {
			AND = {
				check_variable = { budget_expenditure > total_revenue }	
				check_variable = { eoc_treasury < deficit_surplus }	
			}
		}
		add_to_variable = { eoc_debt = deficit_surplus}
		subtract_from_variable = { eoc_debt = eoc_treasury }
		set_variable = { eoc_treasury = 0}
	}
	clamp_variable = {
		var = eoc_treasury
		min = 0
		max = 2147483
	}	
	
}


eoc_calc_debt_info = {

	set_variable = {eoc_debt_percentage = eoc_debt}   	
	multiply_variable = {eoc_debt_percentage = 100}
	divide_variable = {eoc_debt_percentage = eoc_total_gdp}


}

eoc_debt_interests = {
	set_variable = { eoc_interests = 0.05 }
	multiply_variable = { eoc_interests = eoc_debt_percentage }
	set_variable = { eoc_interests_rate = eoc_interests }
	multiply_variable = { eoc_interests = eoc_debt }
	divide_variable = { eoc_interests = 100 }
	clamp_variable = {
		var = eoc_interests
		min = -1000
		max = 2147483
	}
	clamp_variable = {
		var = eoc_debt
		min = -1000
		max = 2147483
	}
		
}

eoc_pay_debt = {

	set_variable = { debt_pay5 = eoc_debt }
	set_variable = { debt_pay10 = eoc_debt }
	set_variable = { debt_pay20 = eoc_debt }
	set_variable = { debt_left = eoc_debt }
	
	multiply_variable = {debt_pay5 = 0.05 }
	multiply_variable = {debt_pay10 = 0.1 }
	multiply_variable = {debt_pay20 = 0.2 }
}

eoc_default = {

	if = {
		limit = { 
			check_variable = { eoc_debt_percentage >500 }
		}
		set_variable = { eoc_debt = 0 }
		add_to_variable = { eoc_percentage_primary_number = 2 }
		add_to_variable = { eoc_percentage_secondary_number = 3 }
		subtract_from_variable = { eoc_percentage_tertiary_number = 5 }
		add_timed_idea = {
			idea = default500
			days = 600
		}
	}
	else_if = {
		limit = { 
			check_variable = { eoc_debt_percentage >400 }
		}
		set_variable = { eoc_debt = 0 }
		add_to_variable = { eoc_percentage_primary_number = 1 }
		add_to_variable = { eoc_percentage_secondary_number = 3 }
		subtract_from_variable = { eoc_percentage_tertiary_number = 4 }
		add_timed_idea = {
			idea = default400
			days = 480
		}
	}
	else_if = {
		limit = { 
			check_variable = { eoc_debt_percentage >300 }
		}
		set_variable = { eoc_debt = 0 }
		add_to_variable = { eoc_percentage_primary_number = 1 }
		add_to_variable = { eoc_percentage_secondary_number = 2 }
		subtract_from_variable = { eoc_percentage_tertiary_number = 3 }
		add_timed_idea = {
			idea = default300
			days = 360
		}
	}
	else_if = {
		limit = { 
			check_variable = { eoc_debt_percentage >200 }
		}
		set_variable = { eoc_debt = 0 }
		add_to_variable = { eoc_percentage_primary_number = 1 }
		add_to_variable = { eoc_percentage_secondary_number = 1 }
		subtract_from_variable = { eoc_percentage_tertiary_number = 2 }		
		add_timed_idea = {
			idea = default200
			days = 240
		}
	}	
}

military_budget_updater = {

	if = {
		limit = { 
			check_variable = {
			var = military_budget_gdp_percentage
			value = 3
			compare = less_than_or_equals
			} 
		}
		set_variable = {multiplier_military_cost = 0.75}
	}	
	if = {
		limit = { 
			check_variable = {
			var = military_budget_gdp_percentage
			value = 5
			compare = less_than_or_equals
			} 
		}
		set_variable = {multiplier_military_cost = 1}
	}
	if = {
		limit = { 
			check_variable = {
			var = military_budget_gdp_percentage
			value = 5
			compare = greater_than
			} 
		}
		set_variable = {multiplier_military_cost = 1.25}
	}
	if = {
		limit = { 
			check_variable = {
			var = military_budget_gdp_percentage
			value = 10
			compare = greater_than_or_equals
			} 
		}
		set_variable = {multiplier_military_cost = 1.50}
	}
	if = {
		limit = { 
			check_variable = {
			var = military_budget_gdp_percentage
			value = 15
			compare = greater_than_or_equals
			} 
		}
		set_variable = {multiplier_military_cost = 2}
	}	
}





agency_budget = {

	set_variable = { eoc_agency_cost_total = 0}

	set_variable = { eoc_number_upgrades = agency_upgrade_number}
	set_variable = { eoc_number_operatives = num_of_operatives}

	set_variable = { eoc_cost_upgrades = 5 }
	set_variable = { eoc_cost_operatives = 10 }
	
	multiply_variable = {eoc_cost_upgrades = eoc_number_upgrades }
	multiply_variable = {eoc_cost_operatives = eoc_number_operatives }
	
	add_to_variable = { eoc_agency_cost_total = eoc_cost_upgrades}
	add_to_variable = { eoc_agency_cost_total = eoc_cost_operatives}	
	
	multiply_variable = { eoc_agency_cost_total = multiplier_military_cost}
	multiply_variable = { eoc_agency_cost_total = 2 }

	#Change to Billions
	divide_variable = { eoc_agency_cost_total = 1000}

	add_to_variable = {budget_expenditure = eoc_agency_cost_total}	
	add_to_variable = {eoc_cost_military_total = eoc_agency_cost_total}	
}


military_budget = {

	set_variable = { eoc_cost_army_total = 0}

	set_variable = { eoc_number_infantry = num_armies_with_type@infantry}
	set_variable = { eoc_number_cavalry = num_armies_with_type@cavalry}
	set_variable = { eoc_number_armored_light = num_armies_with_type@light_armor}
	set_variable = { eoc_number_armored_medium = num_armies_with_type@medium_armor}
	set_variable = { eoc_number_armored_heavy = num_armies_with_type@heavy_armor}
	set_variable = { eoc_number_armored_heavy_super = num_armies_with_type@super_heavy_armor}
	set_variable = { eoc_number_armored_modern = num_armies_with_type@modern_armor}	
	set_variable = { eoc_number_motorized = num_armies_with_type@motorized}	
	set_variable = { eoc_number_mechanized = num_armies_with_type@mechanized}		

	set_variable = {eoc_number_others = num_armies }
	subtract_from_variable = {eoc_number_others = eoc_number_motorized}
	subtract_from_variable = {eoc_number_others = eoc_number_mechanized}
	subtract_from_variable = {eoc_number_others = eoc_number_armored_modern}
	subtract_from_variable = {eoc_number_others = eoc_number_armored_heavy_super}
	subtract_from_variable = {eoc_number_others = eoc_number_armored_heavy}
	subtract_from_variable = {eoc_number_others = eoc_number_armored_medium}
	subtract_from_variable = {eoc_number_others = eoc_number_armored_light}
	subtract_from_variable = {eoc_number_others = eoc_number_cavalry}
	subtract_from_variable = {eoc_number_others = eoc_number_infantry}
	
	set_variable = { eoc_cost_infantry = 0.5 }
	set_variable = { eoc_cost_cavalry = 0.75 }
	set_variable = { eoc_cost_armored_light = 1 }
	set_variable = { eoc_cost_armored_medium = 1.25 }
	set_variable = { eoc_cost_armored_heavy = 1.5 }
	set_variable = { eoc_cost_armored_heavy_super = 1.75 }
	set_variable = { eoc_cost_armored_modern = 2 }
	set_variable = { eoc_cost_mechanized = 1.25 }
	set_variable = { eoc_cost_motorized = 1 }	
	set_variable = { eoc_cost_others = 0.5 }	
	
	multiply_variable = {eoc_cost_infantry = eoc_number_infantry }
	multiply_variable = {eoc_cost_cavalry = eoc_number_cavalry }
	multiply_variable = {eoc_cost_armored_light = eoc_number_armored_light }
	multiply_variable = {eoc_cost_armored_medium = eoc_number_armored_medium }
	multiply_variable = {eoc_cost_armored_heavy = eoc_number_armored_heavy }
	multiply_variable = {eoc_cost_armored_heavy_super = eoc_number_armored_heavy_super }
	multiply_variable = {eoc_cost_armored_modern = eoc_number_armored_modern }
	multiply_variable = {eoc_cost_mechanized = eoc_number_mechanized }
	multiply_variable = {eoc_cost_motorized = eoc_number_motorized }	
	multiply_variable = {eoc_cost_others = eoc_number_infantry }		
	
	
	add_to_variable = { eoc_cost_army_total = eoc_cost_infantry}
	add_to_variable = { eoc_cost_army_total = eoc_cost_cavalry}
	add_to_variable = { eoc_cost_army_total = eoc_cost_armored_light}
	add_to_variable = { eoc_cost_army_total = eoc_cost_armored_medium}
	add_to_variable = { eoc_cost_army_total = eoc_cost_armored_heavy}
	add_to_variable = { eoc_cost_army_total = eoc_cost_armored_heavy_super}
	add_to_variable = { eoc_cost_army_total = eoc_cost_armored_modern}	
	add_to_variable = { eoc_cost_army_total = eoc_cost_mechanized}	
	add_to_variable = { eoc_cost_army_total = eoc_cost_motorized}	
	add_to_variable = { eoc_cost_army_total = eoc_cost_others}	

	set_variable = { eoc_armored_cost_info = 0 }
	set_variable = { eoc_infantry_cost_info = 0 }
	set_variable = { eoc_mobile_cost_info = 0 }
	set_variable = { eoc_others_cost_info = 0 }
	
	
	add_to_variable = { eoc_infantry_cost_info = eoc_cost_infantry}
	
	add_to_variable = { eoc_armored_cost_info = eoc_cost_armored_light}
	add_to_variable = { eoc_armored_cost_info = eoc_cost_armored_medium}
	add_to_variable = { eoc_armored_cost_info = eoc_cost_armored_heavy}
	add_to_variable = { eoc_armored_cost_info = eoc_cost_armored_heavy_super}
	add_to_variable = { eoc_armored_cost_info = eoc_cost_armored_modern}	
	
	add_to_variable = { eoc_mobile_cost_info = eoc_cost_cavalry}
	add_to_variable = { eoc_mobile_cost_info = eoc_cost_mechanized}
	add_to_variable = { eoc_mobile_cost_info = eoc_cost_motorized}
	
	add_to_variable = { eoc_others_cost_info = eoc_cost_others}

	divide_variable = {eoc_infantry_cost_info = 1000}
	divide_variable = {eoc_armored_cost_info = 1000}
	divide_variable = {eoc_mobile_cost_info = 1000}
	divide_variable = {eoc_others_cost_info = 1000}

	multiply_variable = { eoc_infantry_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_armored_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_mobile_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_super_heavy_battleship_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_others_cost_info = multiplier_military_cost }

	multiply_variable = { eoc_infantry_cost_info = 2 }
	multiply_variable = { eoc_armored_cost_info = 2 }
	multiply_variable = { eoc_mobile_cost_info = 2 }
	multiply_variable = { eoc_super_heavy_battleship_cost_info = 2 }
	multiply_variable = { eoc_others_cost_info = 2 }


	multiply_variable = { eoc_cost_army_total = multiplier_military_cost}
	multiply_variable = { eoc_cost_army_total = 2 }
	
	#Change to Billions
	divide_variable = { eoc_cost_army_total = 1000}
	
	add_to_variable = {budget_expenditure = eoc_cost_army_total}	
	add_to_variable = {eoc_cost_military_total = eoc_cost_army_total}	
}


navy_budget = {

	set_variable = { eoc_cost_navy_total = 0}

	set_variable = { eoc_number_destroyer = num_ships_with_type@destroyer}
	set_variable = { eoc_number_cruiser = num_ships_with_type@light_cruiser}
	set_variable = { eoc_number_heavy_cruiser = num_ships_with_type@heavy_cruiser}
	set_variable = { eoc_number_battlecruiser = num_ships_with_type@battlecruiser}
	set_variable = { eoc_number_battleship = num_ships_with_type@battleship}
	set_variable = { eoc_number_super_heavy_battleship = num_ships_with_type@super_heavy_battleship}
	set_variable = { eoc_number_carrier = num_ships_with_type@carrier}	
	set_variable = { eoc_number_submarine = num_ships_with_type@submarine}		

	
	set_variable = { eoc_cost_submarine = 2 }
	set_variable = { eoc_cost_carrier = 10 }
	set_variable = { eoc_cost_super_heavy_battleship = 8 }
	set_variable = { eoc_cost_battleship = 7.5 }
	set_variable = { eoc_cost_battlecruiser = 6 }
	set_variable = { eoc_cost_heavy_cruiser = 4 }
	set_variable = { eoc_cost_cruiser = 3 }
	set_variable = { eoc_cost_destroyer = 2 }

	multiply_variable = {eoc_cost_submarine = eoc_number_submarine }
	multiply_variable = {eoc_cost_carrier = eoc_number_carrier }
	multiply_variable = {eoc_cost_super_heavy_battleship = eoc_number_super_heavy_battleship }
	multiply_variable = {eoc_cost_battleship = eoc_number_battleship }
	multiply_variable = {eoc_cost_battlecruiser = eoc_number_battlecruiser }
	multiply_variable = {eoc_cost_heavy_cruiser = eoc_number_heavy_cruiser }
	multiply_variable = {eoc_cost_cruiser = eoc_number_cruiser }
	multiply_variable = {eoc_cost_destroyer = eoc_number_destroyer }
	
	
	
	add_to_variable = { eoc_cost_navy_total = eoc_cost_submarine}
	add_to_variable = { eoc_cost_navy_total = eoc_cost_carrier}
	add_to_variable = { eoc_cost_navy_total = eoc_cost_super_heavy_battleship}
	add_to_variable = { eoc_cost_navy_total = eoc_cost_battleship}
	add_to_variable = { eoc_cost_navy_total = eoc_cost_battlecruiser}
	add_to_variable = { eoc_cost_navy_total = eoc_cost_heavy_cruiser}
	add_to_variable = { eoc_cost_navy_total = eoc_cost_cruiser}	
	add_to_variable = { eoc_cost_navy_total = eoc_cost_destroyer}	


	set_variable = { eoc_submarine_cost_info = 0 }
	set_variable = { eoc_carrier_cost_info = 0 }
	set_variable = { eoc_super_heavy_battleship_cost_info = 0 }
	set_variable = { eoc_battleship_cost_info = 0 }
	set_variable = { eoc_battlecruiser_cost_info = 0 }
	set_variable = { eoc_battlecruiser_cost_info = 0 }
	set_variable = { eoc_heavy_cruiser_cost_info = 0 }
	set_variable = { eoc_cruiser_cost_info = 0 }
	set_variable = { eoc_destroyer_cost_info = 0 }
	
	add_to_variable = { eoc_submarine_cost_info = eoc_cost_submarine}
	add_to_variable = { eoc_carrier_cost_info = eoc_cost_carrier}
	add_to_variable = { eoc_super_heavy_battleship_cost_info = eoc_cost_super_heavy_battleship}
	add_to_variable = { eoc_battleship_cost_info = eoc_cost_battleship}
	add_to_variable = { eoc_battlecruiser_cost_info = eoc_cost_battlecruiser}
	add_to_variable = { eoc_heavy_cruiser_cost_info = eoc_cost_heavy_cruiser}	
	add_to_variable = { eoc_cruiser_cost_info = eoc_cost_cruiser}
	add_to_variable = { eoc_destroyer_cost_info = eoc_cost_destroyer}


	divide_variable = {eoc_submarine_cost_info = 1000}
	divide_variable = {eoc_carrier_cost_info = 1000}
	divide_variable = {eoc_super_heavy_battleship_cost_info = 1000}
	divide_variable = {eoc_battleship_cost_info = 1000}
	divide_variable = {eoc_battlecruiser_cost_info = 1000}
	divide_variable = {eoc_heavy_cruiser_cost_info = 1000}
	divide_variable = {eoc_cruiser_cost_info = 1000}
	divide_variable = {eoc_destroyer_cost_info = 1000}

	multiply_variable = { eoc_submarine_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_carrier_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_super_heavy_battleship_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_battleship_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_battlecruiser_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_heavy_cruiser_cost_info = multiplier_military_cost }
	multiply_variable = { eoc_cruiser_cost_info = multiplier_military_cost }	
	multiply_variable = { eoc_destroyer_cost_info = multiplier_military_cost }	


	multiply_variable = { eoc_submarine_cost_info = 4 }
	multiply_variable = { eoc_carrier_cost_info = 4 }
	multiply_variable = { eoc_super_heavy_battleship_cost_info = 4 }
	multiply_variable = { eoc_battleship_cost_info = 4 }
	multiply_variable = { eoc_battlecruiser_cost_info = 4 }
	multiply_variable = { eoc_heavy_cruiser_cost_info = 4 }
	multiply_variable = { eoc_cruiser_cost_info = 4 }	
	multiply_variable = { eoc_destroyer_cost_info = 4 }	

	multiply_variable = { eoc_cost_navy_total = multiplier_military_cost}
	multiply_variable = { eoc_cost_navy_total = 4 }

	#Change to Billions
	divide_variable = { eoc_cost_navy_total = 1000}

	add_to_variable = {budget_expenditure = eoc_cost_navy_total}	
	add_to_variable = {eoc_cost_military_total = eoc_cost_navy_total}	
}



airforce_budget = {

	set_variable = { eoc_cost_airforce_total = 0}



	###BBA###

	set_variable = { eoc_number_fighter_frame = num_deployed_planes_with_type@small_plane_airframe}
	set_variable = { eoc_number_cas_frame = num_deployed_planes_with_type@small_plane_cas_airframe}
	set_variable = { eoc_number_naval_bomber_frame = num_deployed_planes_with_type@small_plane_naval_bomber_airframe}
	set_variable = { eoc_number_suicide_frame = num_deployed_planes_with_type@small_plane_suicide_airframe}
	
	set_variable = { eoc_number_tactical_bomber_frame = num_deployed_planes_with_type@medium_plane_airframe}
	set_variable = { eoc_number_interceptor_frame = num_deployed_planes_with_type@medium_plane_fighter_airframe}
	
	set_variable = { eoc_number_strategic_bomber_frame = num_deployed_planes_with_type@large_plane_airframe}	
	set_variable = { eoc_number_maritime_patrol_frame = num_deployed_planes_with_type@large_plane_maritime_patrol_plane_airframe}
	
	set_variable = { eoc_number_air_transport_frame = num_deployed_planes_with_type@air_transport}	
	set_variable = { eoc_number_missile_frame = num_deployed_planes_with_type@missile}
	

	
	
	set_variable = { eoc_number_jet_fighter_frame = num_deployed_planes_with_type@jet_fighter_equipment}
	set_variable = { eoc_number_jet_tac_bomber_frame = num_deployed_planes_with_type@jet_tac_bomber_equipment}
	set_variable = { eoc_number_jet_strat_bomber_frame = num_deployed_planes_with_type@jet_strat_bomber_equipment}
	
	set_variable = { eoc_number_cv_cas_frame = num_deployed_planes_with_type@cv_small_plane_cas_airframe}
	set_variable = { eoc_number_cv_naval_bomber_frame = num_deployed_planes_with_type@cv_small_plane_naval_bomber_airframe}
	set_variable = { eoc_number_cv_suicide_frame = num_deployed_planes_with_type@cv_small_plane_suicide_airframe}
	set_variable = { eoc_number_cv_small_frame = num_deployed_planes_with_type@cv_small_plane_airframe}		
		
		
	###Non BBA##					
		
	set_variable = { eoc_number_fighter = num_deployed_planes_with_type@fighter}
	set_variable = { eoc_number_cas = num_deployed_planes_with_type@cas}
	set_variable = { eoc_number_naval_bomber = num_deployed_planes_with_type@naval_bomber}
	set_variable = { eoc_number_interceptor = num_deployed_planes_with_type@interceptor}
	set_variable = { eoc_number_suicide = num_deployed_planes_with_type@suicide}
	set_variable = { eoc_number_tactical_bomber = num_deployed_planes_with_type@tactical_bomber}
	set_variable = { eoc_number_strategic_bomber = num_deployed_planes_with_type@strategic_bomber}	
	set_variable = { eoc_number_air_transport = num_deployed_planes_with_type@air_transport}	
	set_variable = { eoc_number_missile = num_deployed_planes_with_type@missile}		



	###BBA##


	set_variable = { eoc_cost_fighter_frame = 0.01 }
	set_variable = { eoc_cost_cas_frame = 0.15 }
	set_variable = { eoc_cost_naval_bomber_frame = 0.02 }
	set_variable = { eoc_cost_interceptor_frame = 0.004 }
	set_variable = { eoc_cost_suicide_frame = 0.005 }
	set_variable = { eoc_cost_tactical_bomber_frame = 0.005 }
	
	set_variable = { eoc_cost_strategic_bomber_frame = 0.8 }
	set_variable = { eoc_cost_maritime_patrol_frame = 0.08 }
	
	set_variable = { eoc_cost_air_transport_frame = 0.2 }	
	set_variable = { eoc_cost_missile_frame = 0.005 }
	
	set_variable = { eoc_cost_cv_small_frame = 0.01 }
	set_variable = { eoc_cost_cv_suicide_frame = 0.005 }
	set_variable = { eoc_cost_cv_naval_bomber_frame = 0.015 }
	set_variable = { eoc_cost_cv_cas_frame = 0.020 }
	
	set_variable = { eoc_cost_jet_fighter_frame = 0.02 }
	set_variable = { eoc_cost_jet_tac_bomber_frame = 0.06 }
	set_variable = { eoc_cost_jet_strat_bomber_frame = 0.12 }
	
	###NON BBA###
	multiply_variable = {eoc_cost_fighter = eoc_number_fighter }
	multiply_variable = {eoc_cost_cas = eoc_number_cas }
	multiply_variable = {eoc_cost_naval_bomber = eoc_number_naval_bomber }
	multiply_variable = {eoc_cost_suicide = eoc_number_suicide }
		
	multiply_variable = {eoc_cost_interceptor = eoc_number_interceptor }
	multiply_variable = {eoc_cost_tactical_bomber = eoc_number_tactical_bomber }
	
	multiply_variable = {eoc_cost_strategic_bomber = eoc_number_strategic_bomber }
	
	multiply_variable = {eoc_cost_missile = eoc_number_missile }
	multiply_variable = {eoc_cost_air_transport = eoc_number_air_transport }	
	
	
	###BBA###
	
	multiply_variable = {eoc_cost_fighter_frame = eoc_number_fighter_frame }
	multiply_variable = {eoc_cost_cas_frame = eoc_number_cas_frame }
	multiply_variable = {eoc_cost_naval_bomber_frame = eoc_number_naval_bomber_frame }
	multiply_variable = {eoc_cost_suicide_frame = eoc_number_suicide_frame }
	
	multiply_variable = {eoc_cost_tactical_bomber_frame = eoc_number_tactical_bomber_frame }
	multiply_variable = {eoc_cost_interceptor_frame = eoc_number_interceptor_frame }
	
	multiply_variable = {eoc_cost_missile_frame = eoc_number_missile_frame }
	multiply_variable = {eoc_cost_air_transport_frame = eoc_number_air_transport_frame }	
	
	multiply_variable = {eoc_cost_strategic_bomber_frame = eoc_number_strategic_bomber_frame }
	multiply_variable = {eoc_cost_maritime_patrol_frame = eoc_number_maritime_patrol_frame }
	
	multiply_variable = {eoc_cost_jet_fighter_frame = eoc_number_jet_fighter_frame }
	multiply_variable = {eoc_cost_jet_tac_bomber_frame = eoc_number_jet_tac_bomber_frame }
	multiply_variable = {eoc_cost_jet_strat_bomber_frame = eoc_number_jet_strat_bomber_frame }
	
	multiply_variable = {eoc_cost_cv_cas_frame = eoc_number_cv_cas_frame }
	multiply_variable = {eoc_cost_cv_naval_bomber_frame = eoc_number_cv_naval_bomber_frame }
	multiply_variable = {eoc_cost_cv_suicide_frame = eoc_number_cv_suicide_frame }
	multiply_variable = {eoc_cost_cv_small_frame = eoc_number_cv_small_frame }
	
	
	###BBA###	
	
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_fighter_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_cas_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_naval_bomber_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_interceptor_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_suicide_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_tactical_bomber_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_strategic_bomber_frame}	
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_missile_frame}	
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_air_transport_frame}	
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_maritime_patrol_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_jet_fighter_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_jet_tac_bomber_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_jet_strat_bomber_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_cv_cas_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_cv_naval_bomber_frame}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_cv_suicide_frame}	
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_cv_small_frame}	

	
	
	### NON BBA ###
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_fighter}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_cas}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_naval_bomber}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_interceptor}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_suicide}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_tactical_bomber}
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_strategic_bomber}	
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_missile}	
	add_to_variable = { eoc_cost_airforce_total = eoc_cost_air_transport}	




	multiply_variable = { eoc_cost_airforce_total = multiplier_military_cost}
	multiply_variable = { eoc_cost_airforce_total = 1 }

	#Change to Billions
	divide_variable = { eoc_cost_airforce_total = 1000}

	add_to_variable = {budget_expenditure = eoc_cost_airforce_total}	
	add_to_variable = {eoc_cost_military_total = eoc_cost_airforce_total}	
}


healthcare_budget = {

	set_variable = {eoc_country_population_budget = max_manpower_k}
	set_variable = { cost_healthcare_spending = eoc_country_population_budget}
	multiply_variable = {cost_healthcare_spending = healthcare_budget_gdp_percentage} 
	if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 1
				compare = less_than
			}
		}	
		divide_variable = { cost_healthcare_spending = 50 }
		multiply_variable = {cost_healthcare_spending = eoc_total_gdp_capita}
		divide_variable = { cost_healthcare_spending = 1 }
		#Change to Billions
		divide_variable = { cost_healthcare_spending = 500}	
	}
	else_if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 5
				compare = greater_than_or_equals
			}
		}
		divide_variable = { cost_healthcare_spending = 50 }
		multiply_variable = {cost_healthcare_spending = eoc_total_gdp_capita}
		divide_variable = { cost_healthcare_spending = 40 }
		#Change to Billions
		divide_variable = { cost_healthcare_spending = 1000}	
	}
	else_if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 1
				compare = greater_than_or_equals
			}
		}
		divide_variable = { cost_healthcare_spending = 50 }
		multiply_variable = {cost_healthcare_spending = eoc_total_gdp_capita}
		divide_variable = { cost_healthcare_spending = 50 }
		#Change to Billions
		divide_variable = { cost_healthcare_spending = 1000}	
	}
	
	
	
	
	
	clamp_variable = {
		var = cost_healthcare_spending
		min = 0
		max = 2147483
	}
	add_to_variable = {budget_expenditure = cost_healthcare_spending}
}


economy_budget = {

	set_variable = { cost_economy_spending = economy_budget_gdp_percentage}
	multiply_variable = { cost_economy_spending = eoc_total_gdp }
	divide_variable = { cost_economy_spending = 40}
	clamp_variable = {
		var = cost_economy_spending
		min = 0
		max = 2147483
	}	
	add_to_variable = {budget_expenditure = cost_economy_spending}
}

work_budget = {

	set_variable = { cost_work_spending = work_budget_gdp_percentage}
	if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 1
				compare = less_than
			}
		}
		multiply_variable = { cost_work_spending = eoc_total_gdp_capita }
		multiply_variable = { cost_work_spending = num_of_civilian_factories }
		divide_variable = { cost_work_spending = 1}
		#Change to Billions
		divide_variable = { cost_work_spending = 10}
	}
	else_if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 5
				compare = greater_than
			}
		}
		multiply_variable = { cost_work_spending = eoc_total_gdp_capita }
		multiply_variable = { cost_work_spending = num_of_civilian_factories }
		divide_variable = { cost_work_spending = 10}
		#Change to Billions
		divide_variable = { cost_work_spending = 1000}
	}
	else_if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 1
				compare = greater_than_or_equals
			}
		}
		multiply_variable = { cost_work_spending = eoc_total_gdp_capita }
		multiply_variable = { cost_work_spending = num_of_civilian_factories }
		divide_variable = { cost_work_spending = 1}
		#Change to Billions
		divide_variable = { cost_work_spending = 1000}
	}

	
	
	clamp_variable = {
		var = cost_work_spending
		min = 0
		max = 2147483
	}	
	
	add_to_variable = {budget_expenditure = cost_work_spending}
}

foreign_budget = {

	set_variable = { cost_foreign_spending = foreign_budget_gdp_percentage}
	multiply_variable = { cost_foreign_spending = eoc_total_gdp }
	
	if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 1
				compare = less_than
			}
		}	
		divide_variable = { cost_foreign_spending = 1}
		#Change to Billions
		divide_variable = { cost_foreign_spending = 100}
	}
	else_if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 5
				compare = greater_than_or_equals
			}
		}
		divide_variable = { cost_foreign_spending = 1}
		#Change to Billions
		divide_variable = { cost_foreign_spending = 100}
	}
	else_if = {
		limit = {
			check_variable = {
				var = eoc_total_gdp_capita
				value = 1
				compare = greater_than_or_equals
			}
		}
		#multiply_variable = { cost_foreign_spending = 10}
		#Change to Billions
		divide_variable = { cost_foreign_spending = 100}
	}
	
	
	clamp_variable = {
		var = cost_foreign_spending
		min = 0
		max = 2147482
	}
	
	add_to_variable = {budget_expenditure = cost_foreign_spending}	
}



military_budget_percentage = {

		set_variable = {eoc_cost_airforce_percentage = eoc_cost_airforce_total}
		set_variable = {eoc_cost_navy_percentage = eoc_cost_navy_total}
		set_variable = {eoc_cost_army_percentage = eoc_cost_army_total}
		set_variable = {eoc_cost_military_percentage_number = eoc_cost_military_total}
		set_variable = {eoc_agency_cost_percentage = eoc_agency_cost_total}


		multiply_variable = { eoc_agency_cost_percentage = 100}
		multiply_variable = { eoc_cost_airforce_percentage = 100}
		multiply_variable = { eoc_cost_navy_percentage = 100}
		multiply_variable = { eoc_cost_army_percentage = 100}
		
		divide_variable = { eoc_agency_cost_percentage = eoc_cost_military_total}
		divide_variable = { eoc_cost_airforce_percentage = eoc_cost_military_total}
		divide_variable = { eoc_cost_navy_percentage = eoc_cost_military_total}
		divide_variable = { eoc_cost_army_percentage = eoc_cost_military_total}
}


# Scripted GUI Pie Chart example by Yard1
# Feel free to use in your mods, but give credits to Yard1 (both in code, with comments; and on your download page)

# this creates a pie chart of popularities - can be easily adapted to show anything that adds up to 100%
create_pie_chart = {
	clear_array = pie_chart
	resize_array = {
		array = pie_chart
		value = 1 # 1 is value for neutrality frame, so we don't have to make a loop for it
		size = 100 # 100 pieces, each percent is one piece
	}
	set_temp_variable = { eoc_cost_airforce_percentage_temp = eoc_cost_airforce_percentage }
	#multiply_temp_variable = { eoc_cost_airforce_percentage_temp = 100 }
	round_temp_variable = eoc_cost_airforce_percentage_temp

	set_temp_variable = { eoc_cost_navy_percentage_temp = eoc_cost_navy_percentage }
	#multiply_temp_variable = { eoc_cost_navy_percentage_temp = 100 }
	round_temp_variable = eoc_cost_navy_percentage_temp 
	set_temp_variable = { ROOT.last_idx = eoc_cost_airforce_percentage_temp }
	add_to_temp_variable = { eoc_cost_navy_percentage_temp = ROOT.last_idx }
	for_loop_effect = {
		start = ROOT.last_idx
		end = eoc_cost_navy_percentage_temp
		set_variable = { pie_chart^v = 2 }
		add_to_variable = { ROOT.last_idx = 1 }
	}

	set_temp_variable = { eoc_cost_army_percentage_temp = eoc_cost_army_percentage }
	#multiply_temp_variable = { eoc_cost_army_percentage_temp = 100 }
	round_temp_variable = eoc_cost_army_percentage_temp
	add_to_temp_variable = { eoc_cost_army_percentage_temp = ROOT.last_idx }
	for_loop_effect = {
		start = ROOT.last_idx
		end = eoc_cost_army_percentage_temp
		set_variable = { pie_chart^v = 3 }
		add_to_variable = { ROOT.last_idx = 1 }
	}

	set_temp_variable = { eoc_agency_cost_percentage_temp = eoc_agency_cost_percentage }
	#multiply_temp_variable = { eoc_agency_cost_percentage_temp = 100 }
	round_temp_variable = eoc_agency_cost_percentage_temp 
	add_to_temp_variable = { eoc_agency_cost_percentage_temp = ROOT.last_idx }
	for_loop_effect = {
		start = ROOT.last_idx
		end = eoc_agency_cost_percentage_temp
		set_variable = { pie_chart^v = 4 }
	}

	clear_variable = ROOT.last_idx
	add_to_variable = { pie_chart_dirty = 1 }
}






total_budget = {
	set_variable = { eoc_cost_military_total = 0}
	set_variable = { budget_expenditure = 0 }
	military_budget = yes
	navy_budget = yes 
	airforce_budget = yes 
	agency_budget = yes
	military_budget_percentage = yes
	if = {
		limit = { is_ai = no }
		create_pie_chart = yes
	}
	healthcare_budget = yes
	economy_budget = yes
	work_budget = yes
	foreign_budget = yes
}