# Function: update_state_category # Purpose: Updates the state category of the nation to improve to the next state category - Done once a year state_init_setup = { for_each_scope_loop = { array = global.states # Descending thresholds: first match wins, so each state sets its category # exactly once. States <= 300k keep their existing category (no else). if = { limit = { state_population_k > 65000 } set_state_category = state_18 } else_if = { limit = { state_population_k > 52000 } set_state_category = state_17 } else_if = { limit = { state_population_k > 42000 } set_state_category = state_16 } else_if = { limit = { state_population_k > 34000 } set_state_category = state_15 } else_if = { limit = { state_population_k > 27000 } set_state_category = state_14 } else_if = { limit = { state_population_k > 23000 } set_state_category = state_13 } else_if = { limit = { state_population_k > 19000 } set_state_category = state_12 } else_if = { limit = { state_population_k > 16000 } set_state_category = state_11 } else_if = { limit = { state_population_k > 13000 } set_state_category = state_10 } else_if = { limit = { state_population_k > 10500 } set_state_category = state_09 } else_if = { limit = { state_population_k > 8500 } set_state_category = state_08 } else_if = { limit = { state_population_k > 6800 } set_state_category = state_07 } else_if = { limit = { state_population_k > 5200 } set_state_category = state_06 } else_if = { limit = { state_population_k > 3800 } set_state_category = state_05 } else_if = { limit = { state_population_k > 2500 } set_state_category = state_04 } else_if = { limit = { state_population_k > 1500 } set_state_category = state_03 } else_if = { limit = { state_population_k > 800 } set_state_category = state_02 } else_if = { limit = { state_population_k > 300 } set_state_category = state_01 } } } # Set/Remove Improved Trade Agreement # sender_nation --- the nation sending the trade agreement # receiver_nation --- Nation retrieving the agreement # remove_agreement -- OPTIONAL (Set to 1) set_improved_trade_agreement = { if = { limit = { var:receiver_nation = { var:sender_nation = { NOT = { has_country_flag = trade_agreement@PREV } } } NOT = { check_variable = { remove_agreement = 1 } } } var:receiver_nation = { var:sender_nation = { add_opinion_modifier = { target = PREV modifier = mutual_trade_agreement } add_opinion_modifier = { target = PREV modifier = mutual_trade_opinion } reverse_add_opinion_modifier = { target = PREV modifier = mutual_trade_opinion } reverse_add_opinion_modifier = { target = PREV modifier = mutual_trade_agreement } hidden_effect = { add_to_variable = { signed_trade_agreements = 1 } set_country_flag = trade_agreement@PREV var:receiver_nation = { add_to_variable = { signed_trade_agreements = 1 } set_country_flag = trade_agreement@PREV } } } } custom_effect_tooltip = set_improved_trade_agreement_tt } if = { limit = { var:receiver_nation = { var:sender_nation = { has_country_flag = trade_agreement@PREV } } check_variable = { remove_agreement = 1 } } var:receiver_nation = { var:sender_nation = { remove_opinion_modifier = { target = PREV modifier = mutual_trade_agreement } remove_opinion_modifier = { target = PREV modifier = mutual_trade_opinion } add_opinion_modifier = { target = PREV modifier = broke_trade_agreement } clr_country_flag = trade_agreement@PREV add_to_variable = { signed_trade_agreements = -1 } var:receiver_nation = { remove_opinion_modifier = { target = PREV modifier = mutual_trade_agreement } remove_opinion_modifier = { target = PREV modifier = mutual_trade_opinion } add_opinion_modifier = { target = PREV modifier = broke_trade_agreement } clr_country_flag = trade_agreement@PREV add_to_variable = { signed_trade_agreements = -1 } } } } custom_effect_tooltip = remove_improved_trade_agreement_tt } } # ROOT = the country that was just puppeted, FROM = its new overlord. reapply_agreement_opinion_modifiers = { if = { limit = { has_country_flag = trade_agreement@FROM } add_opinion_modifier = { target = FROM modifier = mutual_trade_agreement } add_opinion_modifier = { target = FROM modifier = mutual_trade_opinion } reverse_add_opinion_modifier = { target = FROM modifier = mutual_trade_opinion } reverse_add_opinion_modifier = { target = FROM modifier = mutual_trade_agreement } } if = { limit = { has_country_flag = mutual_investment_treaty_@FROM } add_opinion_modifier = { target = FROM modifier = mutual_investment_treaty_opinion } add_opinion_modifier = { target = FROM modifier = mutual_investment_treaty_trade_opinion } reverse_add_opinion_modifier = { target = FROM modifier = mutual_investment_treaty_opinion } reverse_add_opinion_modifier = { target = FROM modifier = mutual_investment_treaty_trade_opinion } } } quarterly_inflation_calculation = { #Get and set the basic civilian economic growth for this quarter, and grab our old inflation rate set_temp_variable = { last_inflation_rate = inflation_rate_var } set_temp_variable = { gdpc_inflation_adjuster = { value = gdp_per_capita multiply = 0.01 multiply = last_quarter_gdpc_growth_rate } } if = { limit = { has_idea = depression } set_temp_variable = { cycle_inflation_adjustment = -0.035 } } else_if = { limit = { has_idea = recession } set_temp_variable = { cycle_inflation_adjustment = -0.025 } } else_if = { limit = { has_idea = stagnation } set_temp_variable = { cycle_inflation_adjustment = -0.015 } } else_if = { limit = { has_idea = stable_growth } set_temp_variable = { cycle_inflation_adjustment = 0 } } else_if = { limit = { has_idea = fast_growth } set_temp_variable = { cycle_inflation_adjustment = 0.015 } } else = { set_temp_variable = { cycle_inflation_adjustment = 0.025 } } set_temp_variable = { inflation_rate_adjuster = { value = last_quarter_gdpc_growth_rate multiply = { value = tax_rate multiply = 0.01 } subtract = { value = cb_policy_rate subtract = { value = inflation_rate_var multiply = 100 max = 2 } multiply = 0.003 } add = gdpc_inflation_adjuster add = { value = cycle_inflation_adjustment multiply = { value = display_expense multiply = 0.01 } } add = { value = treasury_rate multiply = -0.01 multiply = gdpc_inflation_adjuster } multiply = { value = 1 add = print_money_base_add } } } set_variable = { print_money_base_add = 0 } #Calculation of the quarterly rate finished, now move to calculate the yearly average off those numbers #Check to make sure the array has only 4 items, and add up the value set_temp_variable = { total_elements = year_quarter_inflation_tracker^num } if = { limit = { check_variable = { total_elements > 3 } } remove_from_array = { array = year_quarter_inflation_tracker index = 0 } } #Add this to the array, so we can average yearly inflation. this should stop rapid swings up and down, slowing movement add_to_array = { year_quarter_inflation_tracker = inflation_rate_adjuster } set_temp_variable = { new_inflation_rate = 0 } #Reset the tracker here; this will prevent divide by 0, and give the most current number before division set_temp_variable = { total_elements = year_quarter_inflation_tracker^num } for_each_loop = { array = year_quarter_inflation_tracker value = v add_to_temp_variable = { new_inflation_rate = v } } #Maximum inflation movement per quarter of 10%. This means that the max you can move in a year is 40% in either direction #This is a balance mechanic, both for gameplay, and for when you eat a whole country and your finances go crazy. On quick quarterly spike, and then back down #Hard cap inflation at -200% to 200% set_temp_variable = { new_inflation_rate = { value = new_inflation_rate divide = total_elements max = { value = last_inflation_rate subtract = 0.1 } min = { value = last_inflation_rate add = 0.1 } clamp = { min = -2 max = 2 } } } set_variable = { inflation_rate_var = new_inflation_rate } if = { limit = { is_debug = yes } log = "[GetDateText]: [THIS.GetName]: DEBUG: Inflation Update: Current Inflation Rate: [?THIS.inflation_rate_var|%]" log = "[GetDateText]: [THIS.GetName]: DEBUG: Inflation Update: Last Four Quarters: [?THIS.year_quarter_inflation_tracker^0|%] - [?THIS.year_quarter_inflation_tracker^1|%] - [?THIS.year_quarter_inflation_tracker^2|%] - [?THIS.year_quarter_inflation_tracker^3|%]" } calculate_inflation_effects = yes #AI-only: adjust cb_policy_rate once per quarter based on current inflation level #Uses the same 60-day cooldown flag as the player GUI buttons if = { limit = { is_ai = yes NOT = { has_country_flag = temp_cb_rate_changed } } if = { limit = { check_variable = { inflation_rate_var > 0.10 } check_variable = { cb_policy_rate < 20 } } add_to_variable = { cb_policy_rate = 1 } set_country_flag = { flag = temp_cb_rate_changed value = 1 days = 60 } } else_if = { limit = { check_variable = { inflation_rate_var > 0.05 } check_variable = { cb_policy_rate < 15 } } add_to_variable = { cb_policy_rate = 1 } set_country_flag = { flag = temp_cb_rate_changed value = 1 days = 60 } } else_if = { limit = { check_variable = { inflation_rate_var < 0.01 } check_variable = { cb_policy_rate > 1 } } subtract_from_variable = { cb_policy_rate = 1 } set_country_flag = { flag = temp_cb_rate_changed value = 1 days = 60 } } } } calculate_inflation_effects = { set_variable = { inflation_rate_prod_var = { value = inflation_rate_var multiply = 1.25 } } set_variable = { inflation_rate_econ_var = { value = inflation_rate_var multiply = 1.25 } } set_variable = { inflation_construction_speed_var = { value = inflation_rate_var multiply = 1.70 } } set_variable = { inflation_rate_output_var = { value = inflation_rate_var multiply = -1.35 } } set_variable = { trade_law_cost_var = { value = inflation_rate_var multiply = 1.5 } } set_variable = { inflation_goods_var = { value = inflation_rate_var multiply = -0.4 } } set_variable = { inflation_corruption_var = inflation_rate_var } # Combined inflation cost: economic rate + currency exchange pressure # Currency can reduce inflation but must not cause deflation set_variable = { inflation_cost_combined_var = { value = inflation_rate_var add = currency_inflation_feed clamp = { min = 0 max = 10000 } } } }