|
@@ -52,13 +52,12 @@
|
|
|
#include "table/strings.h"
|
|
|
#include "table/town_land.h"
|
|
|
|
|
|
#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");
|
|
|
INSTANTIATE_POOL_METHODS(Town)
|
|
|
|
|
|
|
|
@@ -779,91 +778,12 @@ static TrackStatus GetTileTrackStatus_To
|
|
|
|
|
|
static void ChangeTileOwner_Town(TileIndex tile, Owner old_owner, Owner new_owner)
|
|
|
{
|
|
|
/* 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(tile, area) {
|
|
|
if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) {
|
|
|
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 UpdateTownCargoes(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.
|
|
|
* The area is composed of the square the tile is in, extended one square in all
|
|
|
* directions as the coverage area of a single station is bigger than just one square. */
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/** 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) return;
|
|
|
|
|
|
/* Update acceptance for each grid square. */
|
|
|
TILE_AREA_LOOP(tile, area) {
|
|
|
if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) {
|
|
|
UpdateTownCargoes(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)
|
|
|
{
|
|
|
if (HasBit(t->flags, TOWN_IS_GROWING)) {
|
|
|
int i = (int)t->grow_counter - 1;
|
|
@@ -2585,13 +2505,12 @@ static bool BuildTownHouse(Town *t, Tile
|
|
|
}
|
|
|
}
|
|
|
|
|
|
MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits);
|
|
|
UpdateTownRadius(t);
|
|
|
UpdateTownGrowthRate(t);
|
|
|
UpdateTownCargoes(t, tile);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
@@ -2670,15 +2589,12 @@ void ClearTownHouse(Town *t, TileIndex t
|
|
|
if (hs->building_flags & BUILDING_2_TILES_X) DoClearTownHouseHelper(tile + TileDiffXY(1, 0), t, ++house);
|
|
|
if (hs->building_flags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1), t, ++house);
|
|
|
|
|
|
RemoveNearbyStations(t, tile, hs->building_flags);
|
|
|
|
|
|
UpdateTownRadius(t);
|
|
|
|
|
|
/* Update cargo acceptance. */
|
|
|
UpdateTownCargoes(t, tile);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Rename a town (server-only).
|
|
|
* @param tile unused
|
|
|
* @param flags type of operation
|
|
@@ -3695,16 +3611,14 @@ void TownsMonthlyLoop()
|
|
|
}
|
|
|
|
|
|
UpdateTownAmounts(t);
|
|
|
UpdateTownGrowth(t);
|
|
|
UpdateTownRating(t);
|
|
|
UpdateTownUnwanted(t);
|
|
|
UpdateTownCargoes(t);
|
|
|
}
|
|
|
|
|
|
UpdateTownCargoBitmap();
|
|
|
}
|
|
|
|
|
|
void TownsYearlyLoop()
|
|
|
{
|
|
|
/* Increment house ages */
|
|
|
for (TileIndex t = 0; t < MapSize(); t++) {
|