Merge tag '14.0-beta1' into jgrpp

# Conflicts:
#	src/3rdparty/squirrel/squirrel/sqcompiler.cpp
#	src/aircraft.h
#	src/animated_tile.h
#	src/base_consist.h
#	src/cargotype.h
#	src/company_gui.cpp
#	src/console_cmds.cpp
#	src/core/overflowsafe_type.hpp
#	src/engine_gui.cpp
#	src/industry_gui.cpp
#	src/lang/english.txt
#	src/music/extmidi.cpp
#	src/network/core/network_game_info.cpp
#	src/network/network_server.cpp
#	src/newgrf.cpp
#	src/newgrf_industries.cpp
#	src/order_base.h
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/order_type.h
#	src/os/macosx/misc_osx.cpp
#	src/os/windows/crashlog_win.cpp
#	src/rail_gui.cpp
#	src/rail_gui.h
#	src/roadveh.h
#	src/roadveh_cmd.cpp
#	src/saveload/afterload.cpp
#	src/saveload/company_sl.cpp
#	src/saveload/saveload.cpp
#	src/saveload/saveload.h
#	src/saveload/saveload_error.hpp
#	src/script/api/script_town.cpp
#	src/settingsgen/settingsgen.cpp
#	src/ship.h
#	src/ship_cmd.cpp
#	src/smallmap_gui.cpp
#	src/spritecache.cpp
#	src/stdafx.h
#	src/strgen/strgen.cpp
#	src/strgen/strgen.h
#	src/table/settings/script_settings.ini
#	src/timetable_cmd.cpp
#	src/timetable_gui.cpp
#	src/town.h
#	src/town_cmd.cpp
#	src/town_cmd.h
#	src/town_gui.cpp
#	src/train.h
#	src/train_cmd.cpp
#	src/tree_cmd.cpp
#	src/vehicle.cpp
#	src/vehicle_base.h
#	src/vehicle_cmd.cpp
#	src/vehicle_gui.cpp
#	src/vehiclelist.cpp
#	src/waypoint_base.h
#	src/widget.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-18 20:58:18 +00:00
140 changed files with 1265 additions and 582 deletions

View File

@@ -679,6 +679,50 @@ static void TownGenerateCargo(Town *t, CargoID ct, uint amount, StationFinder &s
t->supplied[ct].new_act += MoveGoodsToStation(ct, amount, SourceType::Town, t->index, stations.GetStations());
}
/**
* Generate cargo for a house using the original algorithm.
* @param t The current town.
* @param tpe The town production effect.
* @param rate The town's product rate for this production.
* @param stations Available stations for this house.
*/
static void TownGenerateCargoOriginal(Town *t, TownProductionEffect tpe, uint8_t rate, StationFinder &stations)
{
for (const CargoSpec *cs : CargoSpec::town_production_cargoes[tpe]) {
uint32_t r = Random();
if (GB(r, 0, 8) < rate) {
CargoID cid = cs->Index();
uint amt = (GB(r, 0, 8) * cs->town_production_multiplier / TOWN_PRODUCTION_DIVISOR) / 8 + 1;
TownGenerateCargo(t, cid, amt, stations, true);
}
}
}
/**
* Generate cargo for a house using the binominal algorithm.
* @param t The current town.
* @param tpe The town production effect.
* @param rate The town's product rate for this production.
* @param stations Available stations for this house.
*/
static void TownGenerateCargoBinominal(Town *t, TownProductionEffect tpe, uint8_t rate, StationFinder &stations)
{
for (const CargoSpec *cs : CargoSpec::town_production_cargoes[tpe]) {
CargoID cid = cs->Index();
uint32_t r = Random();
/* Make a bitmask with up to 32 bits set, one for each potential pax. */
int genmax = (rate + 7) / 8;
uint32_t genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
/* Mask random value by potential pax and count number of actual pax. */
uint amt = CountBits(r & genmask) * cs->town_production_multiplier / TOWN_PRODUCTION_DIVISOR;
TownGenerateCargo(t, cid, amt, stations, true);
}
}
/**
* Tile callback function.
*
@@ -733,15 +777,8 @@ static void TileLoop_Town(TileIndex tile)
switch (_settings_game.economy.town_cargogen_mode) {
case TCGM_ORIGINAL:
/* Original (quadratic) cargo generation algorithm */
if (GB(r, 0, 8) < hs->population) {
uint amt = GB(r, 0, 8) / 8 + 1;
TownGenerateCargo(t, CT_PASSENGERS, amt, stations, true);
}
if (GB(r, 8, 8) < hs->mail_generation) {
uint amt = GB(r, 8, 8) / 8 + 1;
TownGenerateCargo(t, CT_MAIL, amt, stations, true);
}
TownGenerateCargoOriginal(t, TPE_PASSENGERS, hs->population, stations);
TownGenerateCargoOriginal(t, TPE_MAIL, hs->mail_generation, stations);
break;
case TCGM_BITCOUNT:
@@ -749,20 +786,8 @@ static void TileLoop_Town(TileIndex tile)
/* Reduce generation rate to a 1/4, using tile bits to spread out distribution.
* As tick counter is incremented by 256 between each call, we ignore the lower 8 bits. */
if (GB(_tick_counter, 8, 2) == GB(tile, 0, 2)) {
/* Make a bitmask with up to 32 bits set, one for each potential pax */
int genmax = (hs->population + 7) / 8;
uint32_t genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
/* Mask random value by potential pax and count number of actual pax */
uint amt = CountBits(r & genmask);
/* Adjust and apply */
TownGenerateCargo(t, CT_PASSENGERS, amt, stations, true);
/* Do the same for mail, with a fresh random */
r = Random();
genmax = (hs->mail_generation + 7) / 8;
genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
amt = CountBits(r & genmask);
TownGenerateCargo(t, CT_MAIL, amt, stations, true);
TownGenerateCargoBinominal(t, TPE_PASSENGERS, hs->population, stations);
TownGenerateCargoBinominal(t, TPE_MAIL, hs->mail_generation, stations);
}
break;
@@ -866,10 +891,14 @@ void AddProducedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &produce
}
} else {
if (hs->population > 0) {
produced[CT_PASSENGERS]++;
for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_PASSENGERS]) {
produced[cs->Index()]++;
}
}
if (hs->mail_generation > 0) {
produced[CT_MAIL]++;
for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_MAIL]) {
produced[cs->Index()]++;
}
}
}
}
@@ -1797,7 +1826,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
case TL_3X3_GRID: // Use 2x2 grid afterwards!
GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir));
FALLTHROUGH;
[[fallthrough]];
case TL_2X2_GRID:
rcmd = GetTownRoadGridElement(t1, tile, target_dir);
@@ -1806,7 +1835,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
case TL_BETTER_ROADS: // Use original afterwards!
GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir));
FALLTHROUGH;
[[fallthrough]];
case TL_ORIGINAL:
/* Allow a house at the edge. 60% chance or
@@ -2155,8 +2184,8 @@ void UpdateTownRadii()
void UpdateTownMaxPass(Town *t)
{
t->supplied[CT_PASSENGERS].old_max = t->cache.population >> 3;
t->supplied[CT_MAIL].old_max = t->cache.population >> 4;
t->supplied[CT_PASSENGERS].old_max = _town_cargo_scaler.Scale(t->cache.population >> 3);
t->supplied[CT_MAIL].old_max = _town_cargo_scaler.Scale(t->cache.population >> 4);
}
static void UpdateTownGrowthRate(Town *t);
@@ -2192,12 +2221,12 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi
/* Set the default cargo requirement for town growth */
switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC:
if (FindFirstCargoWithTownEffect(TE_FOOD) != nullptr) t->goal[TE_FOOD] = TOWN_GROWTH_WINTER;
if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_WINTER;
break;
case LT_TROPIC:
if (FindFirstCargoWithTownEffect(TE_FOOD) != nullptr) t->goal[TE_FOOD] = TOWN_GROWTH_DESERT;
if (FindFirstCargoWithTownEffect(TE_WATER) != nullptr) t->goal[TE_WATER] = TOWN_GROWTH_DESERT;
if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_DESERT;
if (FindFirstCargoWithTownAcceptanceEffect(TAE_WATER) != nullptr) t->goal[TAE_WATER] = TOWN_GROWTH_DESERT;
break;
}
@@ -3280,10 +3309,10 @@ CommandCost CmdRenameTownNonAdmin(TileIndex tile, DoCommandFlag flags, uint32_t
* @param effect Town effect of interest
* @return first active cargo slot with that effect
*/
const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect)
const CargoSpec *FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
{
for (const CargoSpec *cs : CargoSpec::Iterate()) {
if (cs->town_effect == effect) return cs;
if (cs->town_acceptance_effect == effect) return cs;
}
return nullptr;
}
@@ -3294,7 +3323,7 @@ const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect)
* @param flags Type of operation.
* @param p1 various bitstuffed elements
* - p1 = (bit 0 - 15) - Town ID to cargo game of.
* - p1 = (bit 16 - 23) - TownEffect to change the game of.
* - p1 = (bit 16 - 23) - TownAcceptanceEffect to change the game of.
* @param p2 The new goal value.
* @param text Unused.
* @return Empty cost or an error.
@@ -3303,19 +3332,19 @@ CommandCost CmdTownCargoGoal(TileIndex tile, DoCommandFlag flags, uint32_t p1, u
{
if (_current_company != OWNER_DEITY) return CMD_ERROR;
TownEffect te = (TownEffect)GB(p1, 16, 8);
if (te < TE_BEGIN || te >= TE_END) return CMD_ERROR;
TownAcceptanceEffect tae = (TownAcceptanceEffect)GB(p1, 16, 8);
if (tae < TAE_BEGIN || tae >= TAE_END) return CMD_ERROR;
uint16_t index = GB(p1, 0, 16);
Town *t = Town::GetIfValid(index);
if (t == nullptr) return CMD_ERROR;
/* Validate if there is a cargo which is the requested TownEffect */
const CargoSpec *cargo = FindFirstCargoWithTownEffect(te);
/* Validate if there is a cargo which is the requested TownAcceptanceEffect */
const CargoSpec *cargo = FindFirstCargoWithTownAcceptanceEffect(tae);
if (cargo == nullptr) return CMD_ERROR;
if (flags & DC_EXEC) {
t->goal[te] = p2;
t->goal[tae] = p2;
UpdateTownGrowth(t);
InvalidateWindowData(WC_TOWN_VIEW, index);
}
@@ -4195,7 +4224,7 @@ static void UpdateTownGrowth(Town *t)
if (t->fund_buildings_months == 0) {
/* Check if all goals are reached for this town to grow (given we are not funding it) */
for (int i = TE_BEGIN; i < TE_END; i++) {
for (int i = TAE_BEGIN; i < TAE_END; i++) {
switch (t->goal[i]) {
case TOWN_GROWTH_WINTER:
if (TileHeight(t->xy) >= GetSnowLine() && t->received[i].old_act == 0 && t->cache.population > 90) return;
@@ -4291,7 +4320,7 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold)
return town;
}
FALLTHROUGH;
[[fallthrough]];
case MP_HOUSE:
return Town::GetByTile(tile);