Import town cargo generation factor patch
Adjust whitespace http://www.tt-forums.net/viewtopic.php?f=33&t=46399&start=200#p1086221
This commit is contained in:

committed by
Jonathan G Rennison

parent
d4f2bcc545
commit
1c9801e6b6
@@ -1521,6 +1521,7 @@ STR_CONFIG_SETTING_TOWN_FOUNDING_HELPTEXT :Enabling this s
|
||||
STR_CONFIG_SETTING_TOWN_FOUNDING_FORBIDDEN :Forbidden
|
||||
STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED :Allowed
|
||||
STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED_CUSTOM_LAYOUT :Allowed, custom town layout
|
||||
STR_CONFIG_SETTING_TOWN_CARGO_FACTOR :{LTBLUE}Town cargo generation factor (less < 0 < more): {ORANGE}{STRING2}
|
||||
|
||||
STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT :In game placement of trees: {STRING2}
|
||||
STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_HELPTEXT :Control random appearance of trees during the game. This might affect industries which rely on tree growth, for example lumber mills
|
||||
|
@@ -1556,6 +1556,7 @@ static SettingEntry _settings_economy_towns[] = {
|
||||
SettingEntry("economy.town_growth_rate"),
|
||||
SettingEntry("economy.larger_towns"),
|
||||
SettingEntry("economy.initial_city_size"),
|
||||
SettingEntry("economy.town_cargo_factor"),
|
||||
};
|
||||
/** Towns sub-page */
|
||||
static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
|
||||
|
@@ -485,6 +485,7 @@ struct EconomySettings {
|
||||
bool station_noise_level; ///< build new airports when the town noise level is still within accepted limits
|
||||
uint16 town_noise_population[3]; ///< population to base decision on noise evaluation (@see town_council_tolerance)
|
||||
bool allow_town_level_crossings; ///< towns are allowed to build level crossings
|
||||
int8 town_cargo_factor; ///< power-of-two multiplier for town (passenger, mail) generation. May be negative.
|
||||
bool infrastructure_maintenance; ///< enable monthly maintenance fee for owner infrastructure
|
||||
};
|
||||
|
||||
|
@@ -712,6 +712,18 @@ str = STR_CONFIG_SETTING_SHORT_PATH_SATURATION
|
||||
strval = STR_CONFIG_SETTING_PERCENTAGE
|
||||
strhelp = STR_CONFIG_SETTING_SHORT_PATH_SATURATION_HELPTEXT
|
||||
|
||||
[SDT_VAR]
|
||||
base = GameSettings
|
||||
var = economy.town_cargo_factor
|
||||
type = SLE_INT8
|
||||
from = 160
|
||||
def = 0
|
||||
min = -16
|
||||
max = +8
|
||||
interval = 1
|
||||
str = STR_CONFIG_SETTING_TOWN_CARGO_FACTOR
|
||||
strval = STR_JUST_INT
|
||||
|
||||
; Vehicles
|
||||
|
||||
[SDT_VAR]
|
||||
|
@@ -436,6 +436,61 @@ static void MakeTownHouseBigger(TileIndex tile)
|
||||
if (flags & BUILDING_HAS_4_TILES) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cargo for a town (house).
|
||||
*
|
||||
* The amount of cargo should be and will be greater than zero.
|
||||
*
|
||||
* @param t current town
|
||||
* @param ct type of cargo to generate, usually CT_PASSENGERS or CT_MAIL
|
||||
* @param amount how many units of cargo
|
||||
* @param stations available stations for this house
|
||||
*/
|
||||
static void TownGenerateCargo (Town *t, CargoID ct, uint amount, StationFinder &stations)
|
||||
{
|
||||
// custom cargo generation factor
|
||||
int cf = _settings_game.economy.town_cargo_factor;
|
||||
|
||||
// when the economy flunctuates, everyone wants to stay at home
|
||||
if (EconomyIsInRecession()) {
|
||||
amount = (amount + 1) >> 1;
|
||||
}
|
||||
|
||||
// apply custom factor?
|
||||
if (cf < 0) {
|
||||
// approx (amount / 2^cf)
|
||||
// adjust with a constant offset of {(2 ^ cf) - 1} (i.e. add cf * 1-bits) before dividing to ensure that it doesn't become zero
|
||||
// this skews the curve a little so that isn't entirely exponential, but will still decrease
|
||||
amount = (amount + ((1 << -cf) - 1)) >> -cf;
|
||||
}
|
||||
|
||||
else if (cf > 0) {
|
||||
// approx (amount * 2^cf)
|
||||
// XXX: overflow?
|
||||
amount = amount << cf;
|
||||
}
|
||||
|
||||
// with the adjustments above, this should never happen
|
||||
assert(amount > 0);
|
||||
|
||||
// calculate for town stats
|
||||
const CargoSpec *cs = CargoSpec::Get(ct);
|
||||
switch (cs->town_effect) {
|
||||
case TE_PASSENGERS:
|
||||
t->supplied[CT_PASSENGERS].new_max += amount;
|
||||
t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amount, ST_TOWN, t->index, stations.GetStations());
|
||||
break;
|
||||
|
||||
case TE_MAIL:
|
||||
t->supplied[CT_MAIL].new_max += amount;
|
||||
t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amount, ST_TOWN, t->index, stations.GetStations());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tile callback function.
|
||||
*
|
||||
@@ -483,27 +538,20 @@ static void TileLoop_Town(TileIndex tile)
|
||||
uint amt = GB(callback, 0, 8);
|
||||
if (amt == 0) continue;
|
||||
|
||||
uint moved = MoveGoodsToStation(cargo, amt, ST_TOWN, t->index, stations.GetStations());
|
||||
|
||||
const CargoSpec *cs = CargoSpec::Get(cargo);
|
||||
t->supplied[cs->Index()].new_max += amt;
|
||||
t->supplied[cs->Index()].new_act += moved;
|
||||
// XXX: no economy flunctuation for GRF cargos?
|
||||
TownGenerateCargo(t, cargo, amt, stations);
|
||||
}
|
||||
} else {
|
||||
if (GB(r, 0, 8) < hs->population) {
|
||||
uint amt = GB(r, 0, 8) / 8 + 1;
|
||||
|
||||
if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
|
||||
t->supplied[CT_PASSENGERS].new_max += amt;
|
||||
t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, ST_TOWN, t->index, stations.GetStations());
|
||||
TownGenerateCargo(t, CT_PASSENGERS, amt, stations);
|
||||
}
|
||||
|
||||
if (GB(r, 8, 8) < hs->mail_generation) {
|
||||
uint amt = GB(r, 8, 8) / 8 + 1;
|
||||
|
||||
if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
|
||||
t->supplied[CT_MAIL].new_max += amt;
|
||||
t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations());
|
||||
TownGenerateCargo(t, CT_MAIL, amt, stations);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user