Merge branch 'master' into jgrpp
# Conflicts: # CMakeLists.txt # cmake/CompileFlags.cmake # src/bridge_gui.cpp # src/saveload/afterload.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/saveload/town_sl.cpp # src/screenshot.cpp # src/screenshot.h # src/toolbar_gui.cpp # src/town.h # src/town_cmd.cpp
This commit is contained in:
@@ -60,7 +60,6 @@
|
||||
#include "safeguards.h"
|
||||
|
||||
TownID _new_town_id;
|
||||
CargoTypes _town_cargoes_accepted; ///< Bitmap of all cargoes accepted by houses.
|
||||
|
||||
/* Initialize the town-pool */
|
||||
TownPool _town_pool("Town");
|
||||
@@ -939,91 +938,6 @@ static void ChangeTileOwner_Town(TileIndex tile, Owner old_owner, Owner new_owne
|
||||
/* not used */
|
||||
}
|
||||
|
||||
/** Update the total cargo acceptance of the whole town.
|
||||
* @param t The town to update.
|
||||
*/
|
||||
void UpdateTownCargoTotal(Town *t)
|
||||
{
|
||||
t->cargo_accepted_total = 0;
|
||||
|
||||
const TileArea &area = t->cargo_accepted.GetArea();
|
||||
TILE_AREA_LOOP_STEP(tile, area, AcceptanceMatrix::GRID) {
|
||||
t->cargo_accepted_total |= t->cargo_accepted[tile];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update accepted town cargoes around a specific tile.
|
||||
* @param t The town to update.
|
||||
* @param start Update the values around this tile.
|
||||
* @param update_total Set to true if the total cargo acceptance should be updated.
|
||||
*/
|
||||
static void UpdateTownCargoesSingleGridArea(Town *t, TileIndex start, bool update_total = true)
|
||||
{
|
||||
CargoArray accepted, produced;
|
||||
CargoTypes dummy = 0;
|
||||
|
||||
/* Gather acceptance for all houses in an area around the start tile. */
|
||||
TileArea area = AcceptanceMatrix::GetAreaForTile(start, 1);
|
||||
TILE_AREA_LOOP(tile, area) {
|
||||
if (!IsTileType(tile, MP_HOUSE) || GetTownIndex(tile) != t->index) continue;
|
||||
|
||||
AddAcceptedCargo_Town(tile, accepted, &dummy);
|
||||
AddProducedCargo_Town(tile, produced);
|
||||
}
|
||||
|
||||
/* Create bitmap of produced and accepted cargoes. */
|
||||
CargoTypes acc = 0;
|
||||
for (uint cid = 0; cid < NUM_CARGO; cid++) {
|
||||
if (accepted[cid] >= 8) SetBit(acc, cid);
|
||||
if (produced[cid] > 0) SetBit(t->cargo_produced, cid);
|
||||
}
|
||||
t->cargo_accepted[start] = acc;
|
||||
|
||||
if (update_total) UpdateTownCargoTotal(t);
|
||||
}
|
||||
|
||||
static void UpdateTownCargoesHouse(Town *t, TileIndex start, bool x_two_tiles, bool y_two_tiles, bool update_total = true)
|
||||
{
|
||||
TileIndex lower = TileAddSaturating(start, -AcceptanceMatrix::GRID, -AcceptanceMatrix::GRID);
|
||||
TileIndex upper = TileAddSaturating(start, AcceptanceMatrix::GRID + (x_two_tiles ? 1 : 0), AcceptanceMatrix::GRID + (y_two_tiles ? 1 : 0));
|
||||
for (uint x = TileX(lower) & ~(AcceptanceMatrix::GRID - 1); x <= TileX(upper); x += AcceptanceMatrix::GRID) {
|
||||
for (uint y = TileY(lower) & ~(AcceptanceMatrix::GRID - 1); y <= TileY(upper); y += AcceptanceMatrix::GRID) {
|
||||
UpdateTownCargoesSingleGridArea(t, TileXY(x, y), false);
|
||||
}
|
||||
}
|
||||
if (update_total) UpdateTownCargoTotal(t);
|
||||
}
|
||||
|
||||
/** Update cargo acceptance for the complete town.
|
||||
* @param t The town to update.
|
||||
*/
|
||||
void UpdateTownCargoes(Town *t)
|
||||
{
|
||||
t->cargo_produced = 0;
|
||||
|
||||
const TileArea &area = t->cargo_accepted.GetArea();
|
||||
if (area.tile != INVALID_TILE) {
|
||||
/* Update acceptance for each grid square. */
|
||||
TILE_AREA_LOOP_STEP(tile, area, AcceptanceMatrix::GRID) {
|
||||
UpdateTownCargoesSingleGridArea(t, tile, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the total acceptance. */
|
||||
UpdateTownCargoTotal(t);
|
||||
}
|
||||
|
||||
/** Updates the bitmap of all cargoes accepted by houses. */
|
||||
void UpdateTownCargoBitmap()
|
||||
{
|
||||
_town_cargoes_accepted = 0;
|
||||
|
||||
for (const Town *town : Town::Iterate()) {
|
||||
_town_cargoes_accepted |= town->cargo_accepted_total;
|
||||
}
|
||||
}
|
||||
|
||||
static bool GrowTown(Town *t);
|
||||
|
||||
static void TownTickHandler(Town *t)
|
||||
@@ -2166,8 +2080,6 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
/* 't' can't be nullptr since 'random' is false outside scenedit */
|
||||
assert(!random);
|
||||
|
||||
UpdateTownCargoBitmap();
|
||||
|
||||
if (_current_company == OWNER_DEITY) {
|
||||
SetDParam(0, t->index);
|
||||
AddTileNewsItem(STR_NEWS_NEW_TOWN_UNSPONSORED, NT_INDUSTRY_OPEN, tile);
|
||||
@@ -2754,7 +2666,6 @@ static void DoBuildHouse(Town *t, TileIndex tile, HouseID house, byte random_bit
|
||||
MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits);
|
||||
UpdateTownRadius(t);
|
||||
UpdateTownGrowthRate(t);
|
||||
UpdateTownCargoesHouse(t, tile, hs->building_flags & BUILDING_2_TILES_X, hs->building_flags & BUILDING_2_TILES_Y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2961,9 +2872,6 @@ void ClearTownHouse(Town *t, TileIndex tile)
|
||||
RemoveNearbyStations(t, tile, hs->building_flags);
|
||||
|
||||
UpdateTownRadius(t);
|
||||
|
||||
/* Update cargo acceptance. */
|
||||
UpdateTownCargoesHouse(t, tile, hs->building_flags & BUILDING_2_TILES_X, hs->building_flags & BUILDING_2_TILES_Y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4024,10 +3932,8 @@ void TownsMonthlyLoop()
|
||||
UpdateTownGrowth(t);
|
||||
UpdateTownRating(t);
|
||||
UpdateTownUnwanted(t);
|
||||
UpdateTownCargoes(t);
|
||||
}
|
||||
|
||||
UpdateTownCargoBitmap();
|
||||
}
|
||||
|
||||
void TownsYearlyLoop()
|
||||
|
Reference in New Issue
Block a user