# Author(s): Angriest Bird, Hiddengearz, Killerrabbit # Productivity definitions # Core productivity calculation and growth effects. Productivity utility helpers # (flat changes, world setup) live in 00_economic_system_utilities.txt. calculate_average_world_productivity = { clamp_variable = { var = global.world_population min = 0.001 } set_variable = { global.average_world_productivity = { value = global.cumulative_world_productivity divide = global.world_population multiply = 1000 } } # Bonus center: holds at 1000 until the world grows past it, then tracks the world average set_variable = { global.productivity_center = { value = global.average_world_productivity clamp = { min = 1000 max = 100000000 } } } set_variable = { global.cumulative_world_productivity = 0 } set_variable = { global.world_population = 0 } } productivity_growth_controlled_display_effect = { set_variable = { state_productivity_growth_scaled = { value = PREV.productivity_growth_scaled if = { limit = { value = PREV.productivity_growth_scaled greater_than = 0 } # Catch-up toward world average; clamp guards uninitialized (0) productivity_state_var div-by-zero multiply = { value = global.average_world_productivity divide = { value = productivity_state_var clamp = { min = 100 max = 100000 } } add = -1 multiply = 0.5 # control factor for the catch up effect add = 1 clamp = { min = 0 max = 2 } # cap catch-up so a far-behind nation grows at most 2x base } multiply = { value = 1 add = modifier@state_productivity_growth_modifier } } else = { multiply = productivity_state_var divide = { value = global.average_world_productivity clamp = { min = 100 max = 10000 } } } } } } productivity_growth_country_display_effect = { if = { limit = { NOT = { has_dynamic_modifier = { modifier = productivity_and_employment_modifier } } } add_dynamic_modifier = { modifier = productivity_and_employment_modifier } } set_variable = { productivity_growth_scaled = { value = modifier@productivity_growth_modifier multiply = 0.5 multiply = { value = 1 add = modifier@country_productivity_growth_modifier clamp = { min = 0 max = 100 } # maluses can slow growth to zero, not invert it } } } } update_employment_productivity_output_dynamic_modifier = { # productivity (P) and employment level (E) are supposed to behave as multiplicative factors of factories outputs (O) # (Outputs being counstruction speed for civilian factories, military output for mils and dockyard output for docks) # So if B is the base output and M the ingame modifier (production_speed_buildings_factor in the case of construction speed, for example) # The equation is O = B * (1 + M) * P * E # Unfortunately the game code doesn't allow such a direct multiplication to occur # Instead it is only possible to change the value of M by adding more bonuses or maluses so M = ( S + X ) # Where S is the sum of all ingame modifiers (from laws, techs, national content, etc) and X the value we need to determine # Therefore the following calcutions exist to determine the value of X that satisfy the following equation: # B * (1 + S) * P * E = B * (1 + S + X) # B is simplified out so P * E * (1 + S) -1 -S = X # We group the -1: P * E * (1 + S) -1 * (1 + S) = X # And finally group the (1 + S): X = (1 + S) * (P*E - 1) # This value of X we found is then applied to a dynamic modifier if = { limit = { OR = { NOT = { check_variable = { overall_productivity = last_productivity_check } } NOT = { check_variable = { industrial_complex_total = last_industrial_complex_total } } } } set_variable = { last_productivity_check = overall_productivity } set_variable = { last_industrial_complex_total = industrial_complex_total } #this section calculates the employment level assuming that all factories you receive from trade, leasing and other sources are at 100% employment if = { limit = { num_of_civilian_factories > 0 } set_variable = { construction_speed_output_var = { value = overall_productivity divide = global.productivity_center multiply = { value = industrial_complex_total multiply = civilian_factories_manpower_fulfillment add = { value = num_of_civilian_factories subtract = industrial_complex_total } divide = num_of_civilian_factories } add = -1 multiply = { value = modifier@production_speed_buildings_factor subtract = construction_speed_output_var add = 1 } } } } else = { set_variable = { construction_speed_output_var = 0 } } if = { limit = { num_of_military_factories > 0 } #this section calculates the employment level assuming that all factories you receive from trade, leasing and other sources are at 100% employment set_variable = { military_factories_output_var = { value = overall_productivity divide = global.productivity_center multiply = { value = military_factory_total multiply = military_factories_manpower_fulfillment add = { value = num_of_military_factories subtract = military_factory_total } divide = num_of_military_factories } add = -1 multiply = { value = modifier@industrial_capacity_factory subtract = military_factories_output_var add = 1 } } } } else = { set_variable = { military_factories_output_var = 0 } } if = { limit = { num_of_naval_factories > 0 } #this section calculates the employment level assuming that all factories you receive from trade, leasing and other sources are at 100% employment set_variable = { dockyards_output_var = { value = overall_productivity divide = global.productivity_center multiply = { value = naval_factory_total multiply = naval_factories_manpower_fulfillment add = { value = num_of_naval_factories subtract = naval_factory_total } divide = num_of_naval_factories } add = -1 multiply = { value = modifier@industrial_capacity_dockyard subtract = dockyards_output_var add = 1 } } } } else = { set_variable = { dockyards_output_var = 0 } } # Agricultural District Section set_variable = { agriculture_district_output_var = { value = overall_productivity divide = global.productivity_center add = -1 multiply = { value = modifier@production_speed_agriculture_district_factor subtract = agriculture_district_output_var add = -2 } } } # Display Effects if = { limit = { has_country_flag = disabled_economic_system } set_variable = { military_factories_output_var = 0 } set_variable = { agriculture_district_output_var = 0 } set_variable = { dockyards_output_var = 0 } } set_variable = { productivity_tax_effect_display = { value = overall_productivity divide = global.productivity_center add = -1 } } } } productivity_growth_effect = { productivity_growth_country_display_effect = yes #scales productivity growth based on comparison with global average and adds it to state productivity every_controlled_state = { productivity_growth_controlled_display_effect = yes add_to_variable = { productivity_state_var = state_productivity_growth_scaled } clamp_variable = { var = productivity_state_var min = 100 max = 100000 } # max cap prevents runaway overflow into overall_productivity } update_employment_productivity_output_dynamic_modifier = yes #updates variables for average world productivity add_to_variable = { var = global.cumulative_world_productivity value = { value = overall_productivity multiply = 0.001 multiply = population_total_m } } add_to_variable = { global.world_population = population_total_m } }