Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/release-windows.yml # src/autoreplace_gui.cpp # src/cargotype.cpp # src/company_base.h # src/company_cmd.cpp # src/company_gui.cpp # src/currency.h # src/date_gui.cpp # src/dropdown.cpp # src/dropdown_func.h # src/dropdown_type.h # src/game/game_gui.cpp # src/genworld.cpp # src/genworld_gui.cpp # src/ground_vehicle.hpp # src/group_gui.cpp # src/house.h # src/industry_gui.cpp # src/network/network_client.cpp # src/network/network_server.cpp # src/network/network_type.h # src/newgrf_class_func.h # src/newgrf_house.cpp # src/newgrf_roadstop.h # src/openttd.cpp # src/order_gui.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/screenshot_gui.cpp # src/settings_gui.cpp # src/settings_type.h # src/slider.cpp # src/smallmap_gui.cpp # src/station_cmd.cpp # src/stdafx.h # src/survey.cpp # src/tile_map.h # src/town_cmd.cpp # src/town_gui.cpp # src/vehicle.cpp # src/vehicle_gui.cpp # src/vehicle_gui_base.h
This commit is contained in:
@@ -2215,6 +2215,7 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi
|
||||
UpdateTownRadius(t);
|
||||
t->flags = 0;
|
||||
t->cache.population = 0;
|
||||
InitializeBuildingCounts(t);
|
||||
/* Spread growth across ticks so even if there are many
|
||||
* similar towns they're unlikely to grow all in one tick */
|
||||
t->grow_counter = t->index % TOWN_GROWTH_TICKS;
|
||||
@@ -3111,20 +3112,19 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
/* bits 0-4 are used
|
||||
* bits 11-15 are used
|
||||
* bits 5-10 are not used. */
|
||||
HouseID houses[NUM_HOUSES];
|
||||
uint num = 0;
|
||||
uint probs[NUM_HOUSES];
|
||||
static std::vector<std::pair<HouseID, uint>> probs;
|
||||
probs.clear();
|
||||
|
||||
uint probability_max = 0;
|
||||
|
||||
/* Generate a list of all possible houses that can be built. */
|
||||
for (uint i = 0; i < NUM_HOUSES; i++) {
|
||||
if (IsHouseTypeAllowed((HouseID)i, above_snowline, zone, false).Failed()) continue;
|
||||
if (IsAnotherHouseTypeAllowedInTown(t, (HouseID)i).Failed()) continue;
|
||||
for (const auto &hs : HouseSpec::Specs()) {
|
||||
if (IsHouseTypeAllowed(hs.Index(), above_snowline, zone, false).Failed()) continue;
|
||||
if (IsAnotherHouseTypeAllowedInTown(t, hs.Index()).Failed()) continue;
|
||||
|
||||
uint cur_prob = HouseSpec::Get(i)->probability;
|
||||
uint cur_prob = hs.probability;
|
||||
probability_max += cur_prob;
|
||||
probs[num] = cur_prob;
|
||||
houses[num++] = (HouseID)i;
|
||||
probs.emplace_back(std::make_pair(hs.Index(), cur_prob));
|
||||
}
|
||||
|
||||
TileIndex baseTile = tile;
|
||||
@@ -3139,18 +3139,17 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
|
||||
uint r = RandomRange(probability_max);
|
||||
uint i;
|
||||
for (i = 0; i < num; i++) {
|
||||
if (probs[i] > r) break;
|
||||
r -= probs[i];
|
||||
for (i = 0; i < probs.size(); i++) {
|
||||
if (probs[i].second > r) break;
|
||||
r -= probs[i].second;
|
||||
}
|
||||
|
||||
HouseID house = houses[i];
|
||||
probability_max -= probs[i];
|
||||
HouseID house = probs[i].first;
|
||||
probability_max -= probs[i].second;
|
||||
|
||||
/* remove tested house from the set */
|
||||
num--;
|
||||
houses[i] = houses[num];
|
||||
probs[i] = probs[num];
|
||||
probs[i] = probs.back();
|
||||
probs.pop_back();
|
||||
|
||||
CommandCost ret = CheckCanBuildHouse(house, t, false);
|
||||
if (ret.Failed()) continue;
|
||||
@@ -4578,17 +4577,3 @@ extern const TileTypeProcs _tile_type_town_procs = {
|
||||
GetFoundation_Town, // get_foundation_proc
|
||||
TerraformTile_Town, // terraform_tile_proc
|
||||
};
|
||||
|
||||
|
||||
HouseSpec _house_specs[NUM_HOUSES];
|
||||
|
||||
void ResetHouses()
|
||||
{
|
||||
ResetHouseClassIDs();
|
||||
|
||||
auto insert = std::copy(std::begin(_original_house_specs), std::end(_original_house_specs), std::begin(_house_specs));
|
||||
std::fill(insert, std::end(_house_specs), HouseSpec{});
|
||||
|
||||
/* Reset any overrides that have been set. */
|
||||
_house_mngr.ResetOverride();
|
||||
}
|
||||
|
Reference in New Issue
Block a user