Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New growth rate calculation #59

Merged
merged 1 commit into from Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions info.nut
Expand Up @@ -151,9 +151,9 @@ class MainClass extends GSInfo

AddSetting({ name = "supply_impacting_part",
description = "Expert: minimum supply percentage for TGR growth",
easy_value = 80,
easy_value = 20,
medium_value = 50,
hard_value = 20,
hard_value = 80,
custom_value = 50,
flags = CONFIG_INGAME, min_value = 0, max_value = 100, step_size = 5 });

Expand Down
22 changes: 10 additions & 12 deletions readme.txt
Expand Up @@ -134,7 +134,7 @@ supplied. If you deliver all the required cargo, you will have the
maximum growth rate for a town (its maximum growth rate depends on its
size). If you deliver only a part of cargo, growth rate will be
lower. If you only deliver 50% of the requirements, town growth rate
is arbitrarily set to maximum. If you deliver a larger part of
is arbitrarily set to minimum. If you deliver a larger part of
requirements, the town growth rate increases exponentially. Hence, the
town growth rate is at the same time progressive and exponential.

Expand Down Expand Up @@ -211,22 +211,20 @@ above. Expert settings should only be changed when having a decent
understanding of their impact. Changing them is harmless though and
they can safely be changed while the game is running:
- "town growth factor": this value changes the maximum town growth
rate of a town. Increasing it will result in *lower* town growth
rate (town growing slower) and decreasing it will result in faster
town growth.
- "minimum supply percentage for TGR growth": when calculating town
growth rate, the script scales the growth rate to the percentage of
required cargo supplied. But, by default, at least 50% of
requirements needs to be supplied for this to happen and hence, the
town growth rate is only scaled relatively to 50% until 100% of
supply. This setting allows to change that percentage. Also see:
http://dev.openttdcoop.org/projects/gs-rcg/wiki
rate of a town. Increasing it will result in slower town growth
and decreasing it will result in faster town growth. The value
represents the maximum town growth at 0 population.
- "minimum supply percentage for TGR growth": this value specifies the
minimum percentage of fulfillment of cargo categories for which the
growth rate is calculated. When this percentage is not fulfilled, the
lowest growth rate is used. The growth is still scaled to 100% of the
fulfillment.
- "TGR growth exponentiality factor": when the script scales the town
growth rate to the percentage of achieved requirement, this relation
is not linear but exponential. By increasing this setting you can
increase exponentiality. To put it simple: the higher is this
number, the more you need to approach a 100% supply to have a decent
growth. Also See: http://dev.openttdcoop.org/projects/gs-rcg/wiki
growth.
- "lowest TGR if requirements are not met": for some reason, when
requirements are not met at all for a town, but this still is under
active monitoring (because exchanging passengers), it is better not
Expand Down
24 changes: 13 additions & 11 deletions town.nut
Expand Up @@ -137,7 +137,7 @@ function GoalTown::MonthlyManageTown()
local new_town_growth_rate = null;
// Defining difficulty and calculation factors
local d_factor = GSController.GetSetting("goal_scale_factor") / 100.0;
local g_factor = GSController.GetSetting("town_growth_factor") / 100.0;
local g_factor = GSController.GetSetting("town_growth_factor");
local e_factor = GSController.GetSetting("exponentiality_factor");
local sup_imp_part = GSController.GetSetting("supply_impacting_part") / 100.0;
local lowest_tgr = GSController.GetSetting("lowest_town_growth_rate");
Expand Down Expand Up @@ -229,17 +229,19 @@ function GoalTown::MonthlyManageTown()
this.DebugCargoCatInfo(i) // Debug info: print stockpiled/supplied/goal per category
}

/* Here we calculate the number of days until the next
* growth. The important stuff happens here. Other possible
* formulas for calculating the new town growth rate are:
* new_town_growth_rate = (max_town_growth_rate * (1+(10/(1-goal_diff_percent)-10))).tointeger();
* new_town_growth_rate = (max_town_growth_rate/(1-goal_diff_percent*2)).tointeger();
*/
this.DebugGoalsResult(sum_goals, goal_diff, goal_diff_percent); // Debug info about general goal results
// Calculates new town growth rate based on missing cargo percentage
// Firstly a maximum growth rate for the town is calculated with g_factor
// being the growth rate at 0 population and exponentially increasing.
// An exponential extra growth is calculated based on missing cargo requirements.
// The max growth rate and difference between max growth rate and lowest growth rate
// multiplied by extra growth factor are combined into the resulting growth rate.
Log.Info("Goal diff: " + goal_diff_percent + "%", Log.LVL_DEBUG);
if (goal_diff_percent <= sup_imp_part) {
local max_town_growth_rate = g_factor * 50000 / (100 + cur_pop.tofloat());
new_town_growth_rate = (max_town_growth_rate
* (1 + (e_factor / (1 - goal_diff_percent) - e_factor))).tointeger();
local max_town_growth_rate = g_factor * exp(-cur_pop.tofloat()/10000);
max_town_growth_rate = max_town_growth_rate < 1 ? 1 : max_town_growth_rate;
local growth = 1 - (1 - exp(-e_factor * (1 - goal_diff_percent))) / (1 - exp(-e_factor));
new_town_growth_rate = (max_town_growth_rate + (lowest_tgr - max_town_growth_rate) * growth).tointeger();
Log.Info("max_growth_rate: " + max_town_growth_rate + ", growth: " + growth + ", new growth rate: " + new_town_growth_rate, Log.LVL_DEBUG);
}
else {
new_town_growth_rate = lowest_tgr;
Expand Down