summaryrefslogtreecommitdiff
path: root/src/town.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/town.h')
-rw-r--r--src/town.h37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/town.h b/src/town.h
index a672c2cee..9fcb07c5f 100644
--- a/src/town.h
+++ b/src/town.h
@@ -18,6 +18,7 @@
#include "newgrf_storage.h"
#include "cargotype.h"
#include "tilematrix_type.hpp"
+#include "cargodest_base.h"
#include <list>
template <typename T>
@@ -51,8 +52,9 @@ struct TownCache {
};
/** Town data structure. */
-struct Town : TownPool::PoolItem<&_town_pool> {
+struct Town : TownPool::PoolItem<&_town_pool>, CargoSourceSink {
TileIndex xy; ///< town center tile
+ TileIndex xy_aligned; ///< NOSAVE: Town centre aligned to the #AcceptanceMatrix grid.
TownCache cache; ///< Container for all cacheable data.
@@ -105,6 +107,10 @@ struct Town : TownPool::PoolItem<&_town_pool> {
std::list<PersistentStorage *> psa_list;
+ /* Current cargo acceptance and production. */
+ uint32 cargo_accepted_weights[NUM_CARGO]; ///< NOSAVE: Weight sum of accepting squares per cargo.
+ uint32 cargo_accepted_max_weight; ///< NOSAVE: Cached maximum weight for an accepting square.
+
/**
* Creates a new town.
* @param tile center tile of the town
@@ -116,6 +122,30 @@ struct Town : TownPool::PoolItem<&_town_pool> {
void InitializeLayout(TownLayout layout);
+ /* virtual */ SourceType GetType() const
+ {
+ return ST_TOWN;
+ }
+
+ /* virtual */ SourceID GetID() const
+ {
+ return this->index;
+ }
+
+ /* virtual */ bool AcceptsCargo(CargoID cid) const
+ {
+ return HasBit(this->cargo_accepted_total, cid);
+ }
+
+ /* virtual */ bool SuppliesCargo(CargoID cid) const
+ {
+ return HasBit(this->cargo_produced, cid);
+ }
+
+ /* virtual */ uint GetDestinationWeight(CargoID cid, byte weight_mod) const;
+ /* virtual */ void CreateSpecialLinks(CargoID cid);
+ /* virtual */ TileArea GetTileForDestination(CargoID cid);
+
/**
* Calculate the max town noise.
* The value is counted using the population divided by the content of the
@@ -137,7 +167,10 @@ struct Town : TownPool::PoolItem<&_town_pool> {
return Town::Get(GetTownIndex(tile));
}
- static Town *GetRandom();
+ /** Callback function for #Town::GetRandom. */
+ typedef bool (*EnumTownProc)(const Town *t, void *data);
+
+ static Town *GetRandom(EnumTownProc enum_proc = NULL, TownID skip = INVALID_TOWN, void *data = NULL);
static void PostDestructor(size_t index);
};