OpenTTD Source  20240519-master-g46d7586ab1
Town Struct Reference

Town data structure. More...

#include <town.h>

Inheritance diagram for Town:
Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >

Public Member Functions

uint8_t GetPercentTransported (CargoID cid) const
 
 Town (TileIndex tile=INVALID_TILE)
 Creates a new town. More...
 
 ~Town ()
 Destroy the town.
 
void InitializeLayout (TownLayout layout)
 Assign the town layout. More...
 
uint16_t MaxTownNoise () const
 Calculate the max town noise. More...
 
void UpdateVirtCoord ()
 Resize the sign (label) of the town after it changes population.
 
const std::string & GetCachedName () const
 
- Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >
void * operator new (size_t size)
 Allocates space for new Titem. More...
 
void * operator new (size_t size, size_t index)
 Allocates space for new Titem with given index. More...
 
void * operator new (size_t, void *ptr)
 Allocates space for new Titem at given memory address. More...
 
void operator delete (void *p)
 Marks Titem as free. More...
 

Static Public Member Functions

static TownGetByTile (TileIndex tile)
 
static TownGetRandom ()
 Return a random valid town. More...
 
static void PostDestructor (size_t index)
 Invalidating of the "nearest town cache" has to be done after removing item from the pool.
 
- Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >
static bool CanAllocateItem (size_t n=1)
 Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() More...
 
static bool CleaningPool ()
 Returns current state of pool cleaning - yes or no. More...
 
static bool IsValidID (size_t index)
 Tests whether given index can be used to get valid (non-nullptr) Titem. More...
 
static Titem * Get (size_t index)
 Returns Titem with given index. More...
 
static Titem * GetIfValid (size_t index)
 Returns Titem with given index. More...
 
static size_t GetPoolSize ()
 Returns first unused index. More...
 
static size_t GetNumItems ()
 Returns number of valid items in the pool. More...
 
static void PostDestructor ([[maybe_unused]] size_t index)
 Dummy function called after destructor of each member. More...
 
static Pool::IterateWrapper< Titem > Iterate (size_t from=0)
 Returns an iterable ensemble of all valid Titem. More...
 

Data Fields

TileIndex xy
 town center tile
 
TownCache cache
 Container for all cacheable data.
 
uint32_t townnamegrfid
 
uint16_t townnametype
 
uint32_t townnameparts
 
std::string name
 Custom town name. If empty, the town was not renamed and uses the generated name.
 
std::string cached_name
 NOSAVE: Cache of the resolved name of the town, if not using a custom town name.
 
uint8_t flags
 See TownFlags.
 
uint16_t noise_reached
 level of noise that all the airports are generating
 
CompanyMask statues
 which companies have a statue?
 
CompanyMask have_ratings
 which companies have a rating
 
uint8_t unwanted [MAX_COMPANIES]
 how many months companies aren't wanted by towns (bribe)
 
CompanyID exclusivity
 which company has exclusivity
 
uint8_t exclusive_counter
 months till the exclusivity expires
 
int16_t ratings [MAX_COMPANIES]
 ratings of each company for this town
 
TransportedCargoStat< uint32_t > supplied [NUM_CARGO]
 Cargo statistics about supplied cargo.
 
TransportedCargoStat< uint16_t > received [NUM_TAE]
 Cargo statistics about received cargotypes.
 
uint32_t goal [NUM_TAE]
 Amount of cargo required for the town to grow.
 
std::string text
 General text with additional information.
 
StationList stations_near
 NOSAVE: List of nearby stations.
 
uint16_t time_until_rebuild
 time until we rebuild a house
 
uint16_t grow_counter
 counter to count when to grow, value is smaller than or equal to growth_rate
 
uint16_t growth_rate
 town growth rate
 
uint8_t fund_buildings_months
 fund buildings program in action?
 
uint8_t road_build_months
 fund road reconstruction in action?
 
bool larger_town
 if this is a larger town and should grow more quickly
 
TownLayout layout
 town specific road layout
 
bool show_zone
 NOSAVE: mark town to show the local authority zone in the viewports.
 
std::list< PersistentStorage * > psa_list
 
- Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >
Tindex index
 Index of this pool item.
 

Private Member Functions

void FillCachedName () const
 

Additional Inherited Members

- Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero > Pool
 Type of the pool this item is going to be part of.
 

Detailed Description

Town data structure.

Definition at line 54 of file town.h.

Constructor & Destructor Documentation

◆ Town()

Town::Town ( TileIndex  tile = INVALID_TILE)
inline

Creates a new town.

Parameters
tilecenter tile of the town

Definition at line 112 of file town.h.

Member Function Documentation

◆ GetRandom()

Town * Town::GetRandom ( )
static

Return a random valid town.

Returns
A random town, or nullptr if there are no towns.

Definition at line 191 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), and RandomRange().

Referenced by FindSubsidyCargoDestination(), FindSubsidyPassengerRoute(), and FindSubsidyTownCargoRoute().

◆ InitializeLayout()

void Town::InitializeLayout ( TownLayout  layout)

Assign the town layout.

Parameters
layoutThe desired layout. If TL_RANDOM, we pick one based on TileHash.

Definition at line 177 of file town_cmd.cpp.

References layout, NUM_TLS, TileHash(), TileX(), TileY(), TL_RANDOM, and xy.

◆ MaxTownNoise()

uint16_t Town::MaxTownNoise ( ) const
inline

Calculate the max town noise.

The value is counted using the population divided by the content of the entry in town_noise_population corresponding to the town's tolerance.

Returns
the maximum noise level the town will tolerate.

Definition at line 125 of file town.h.


The documentation for this struct was generated from the following files: