18template <
typename Tproj>
19static uint16_t TownHistoryHelper(
const Town *t,
CargoLabel label, uint period, Tproj proj)
21 auto it = t->GetCargoSupplied(GetCargoTypeByLabel(label));
22 if (it == std::end(t->
supplied))
return 0;
24 return ClampTo<uint16_t>(std::invoke(proj, it->history[period]));
29 if (this->t ==
nullptr) {
42 case 0x41:
return this->t->
index.base();
47 uint32_t grfid =
static_cast<uint32_t
>(this->
ro.
GetRegister(0x100));
48 if (grfid == 0xFFFFFFFF) {
49 if (this->
ro.
grffile ==
nullptr)
return 0;
53 for (
auto &it : this->t->psa_list) {
54 if (it->grfid == grfid)
return it->GetValue(parameter);
61 case 0x80:
return this->t->
xy.base();
62 case 0x81:
return GB(this->t->
xy.base(), 8, 8);
66 case 0x92:
return this->t->
flags;
78 case 0x9E:
return this->t->
ratings[0];
79 case 0x9F:
return GB(this->t->
ratings[0], 8, 8);
80 case 0xA0:
return this->t->
ratings[1];
81 case 0xA1:
return GB(this->t->
ratings[1], 8, 8);
82 case 0xA2:
return this->t->
ratings[2];
83 case 0xA3:
return GB(this->t->
ratings[2], 8, 8);
84 case 0xA4:
return this->t->
ratings[3];
85 case 0xA5:
return GB(this->t->
ratings[3], 8, 8);
86 case 0xA6:
return this->t->
ratings[4];
87 case 0xA7:
return GB(this->t->
ratings[4], 8, 8);
88 case 0xA8:
return this->t->
ratings[5];
89 case 0xA9:
return GB(this->t->
ratings[5], 8, 8);
90 case 0xAA:
return this->t->
ratings[6];
91 case 0xAB:
return GB(this->t->
ratings[6], 8, 8);
92 case 0xAC:
return this->t->
ratings[7];
93 case 0xAD:
return GB(this->t->
ratings[7], 8, 8);
114 case 0xCA:
return this->t->GetPercentTransported(GetCargoTypeByLabel(
CT_PASSENGERS));
115 case 0xCB:
return this->t->GetPercentTransported(GetCargoTypeByLabel(CT_MAIL));
128 Debug(grf, 1,
"Unhandled town variable 0x{:X}", variable);
138 assert(this->t !=
nullptr);
143 uint32_t grfid =
static_cast<uint32_t
>(this->
ro.
GetRegister(0x100));
146 if (grfid == 0xFFFFFFFF) grfid = this->
ro.
grffile->grfid;
147 if (grfid != this->
ro.
grffile->grfid)
return;
150 for (
auto &it :
t->psa_list) {
151 if (it->grfid == grfid) {
152 it->StoreValue(pos, value);
161 t->psa_list.push_back(psa);
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static constexpr CargoLabel CT_PASSENGERS
Available types of cargo Labels may be re-used between different climates.
@ TAE_FOOD
Cargo behaves food/fizzy-drinks-like.
@ TAE_WATER
Cargo behaves water-like.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
static constexpr TimerGameTick::Ticks TOWN_GROWTH_TICKS
Cycle duration for towns trying to grow (this originates from the size of the town array in TTD).
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
@ GSF_FAKE_TOWNS
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
Functions to handle the town part of NewGRF towns.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of base types and functions in a cross-platform compatible way.
uint8_t larger_towns
the number of cities to build. These start off larger and grow twice as fast
Dynamic data of a loaded NewGRF.
EconomySettings economy
settings to change the economy
void StoreValue(uint pos, int32_t value)
Stores some value at a given position.
Class for pooled persistent storage of data.
Tindex index
Index of this pool item.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Interface for SpriteGroup-s to access the gamestate.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
int32_t GetRegister(uint i) const
Gets the value of a so-called newgrf "register".
ResolverObject & ro
Surrounding resolver object.
uint32_t population
Current population of people.
uint32_t num_houses
Amount of houses.
std::array< uint32_t, NUM_HOUSE_ZONES > squared_town_zone_radius
UpdateTownRadius updates this given the house count.
TownResolverObject(const struct GRFFile *grffile, Town *t, bool readonly)
Resolver for a town.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
bool readonly
When set, persistent storage of the town is read-only,.
void StorePSA(uint reg, int32_t value) override
Store a value into the persistent storage area (PSA).
Town * t
Town of the scope.
uint32_t transported
Total transported.
uint32_t production
Total produced.
bool larger_town
if this is a larger town and should grow more quickly
CompanyMask statues
which companies have a statue?
TileIndex xy
town center tile
uint8_t fund_buildings_months
fund buildings program in action?
SuppliedCargoes supplied
Cargo statistics about supplied cargo.
uint16_t grow_counter
counter to count when to grow, value is smaller than or equal to growth_rate
uint8_t flags
See TownFlags.
TownCache cache
Container for all cacheable data.
CompanyMask have_ratings
which companies have a rating
TypedIndexContainer< std::array< int16_t, MAX_COMPANIES >, CompanyID > ratings
ratings of each company for this town
uint16_t growth_rate
town growth rate
uint8_t road_build_months
fund road reconstruction in action?
std::array< TransportedCargoStat< uint16_t >, NUM_TAE > received
Cargo statistics about received cargotypes.
Definition of the tick-based game-timer.