OpenTTD Source 20250312-master-gcdcc6b491d
Town Struct Reference

Town data structure. More...

#include <town.h>

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

Public Member Functions

uint8_t GetPercentTransported (CargoType cargo_type) const
 
 Town (TileIndex tile=INVALID_TILE)
 Creates a new town.
 
 ~Town ()
 Destroy the town.
 
void InitializeLayout (TownLayout layout)
 Assign the town layout.
 
uint16_t MaxTownNoise () const
 Calculate the max town noise.
 
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, Tpool_type, Tcache >::PoolItem<&_town_pool >
void * operator new (size_t size)
 Allocates space for new Titem.
 
void * operator new (size_t size, Tindex index)
 Allocates space for new Titem with given index.
 
void * operator new (size_t, void *ptr)
 Allocates space for new Titem at given memory address.
 
void operator delete (void *p, size_t size)
 Marks Titem as free.
 

Static Public Member Functions

static TownGetByTile (TileIndex tile)
 
static TownGetRandom ()
 Return a random valid town.
 
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, Tpool_type, Tcache >::PoolItem<&_town_pool >
static bool CanAllocateItem (size_t n=1)
 Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
 
static bool CleaningPool ()
 Returns current state of pool cleaning - yes or no.
 
static bool IsValidID (auto index)
 Tests whether given index can be used to get valid (non-nullptr) Titem.
 
static Titem * Get (auto index)
 Returns Titem with given index.
 
static Titem * GetIfValid (auto index)
 Returns Titem with given index.
 
static size_t GetPoolSize ()
 Returns first unused index.
 
static size_t GetNumItems ()
 Returns number of valid items in the pool.
 
static void PostDestructor (size_t index)
 Dummy function called after destructor of each member.
 
static Pool::IterateWrapper< Titem > Iterate (size_t from=0)
 Returns an iterable ensemble of all valid Titem.
 

Data Fields

TileIndex xy = INVALID_TILE
 town center tile
 
TownCache cache {}
 Container for all cacheable data.
 
uint32_t townnamegrfid = 0
 
uint16_t townnametype = 0
 
uint32_t townnameparts = 0
 
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 = 0
 See TownFlags.
 
uint16_t noise_reached = 0
 level of noise that all the airports are generating
 
CompanyMask statues {}
 which companies have a statue?
 
CompanyMask have_ratings {}
 which companies have a rating
 
ReferenceThroughBaseContainer< std::array< uint8_t, MAX_COMPANIES > > unwanted {}
 how many months companies aren't wanted by towns (bribe)
 
CompanyID exclusivity = CompanyID::Invalid()
 which company has exclusivity
 
uint8_t exclusive_counter = 0
 months till the exclusivity expires
 
ReferenceThroughBaseContainer< std::array< int16_t, MAX_COMPANIES > > ratings {}
 ratings of each company for this town
 
std::array< TransportedCargoStat< uint32_t >, NUM_CARGOsupplied {}
 Cargo statistics about supplied cargo.
 
std::array< TransportedCargoStat< uint16_t >, NUM_TAEreceived {}
 Cargo statistics about received cargotypes.
 
std::array< uint32_t, NUM_TAEgoal {}
 Amount of cargo required for the town to grow.
 
EncodedString text {}
 General text with additional information.
 
StationList stations_near {}
 NOSAVE: List of nearby stations.
 
uint16_t time_until_rebuild = 0
 time until we rebuild a house
 
uint16_t grow_counter = 0
 counter to count when to grow, value is smaller than or equal to growth_rate
 
uint16_t growth_rate = 0
 town growth rate
 
uint8_t fund_buildings_months = 0
 fund buildings program in action?
 
uint8_t road_build_months = 0
 fund road reconstruction in action?
 
bool larger_town = false
 if this is a larger town and should grow more quickly
 
TownLayout layout {}
 town specific road layout
 
bool show_zone = false
 NOSAVE: mark town to show the local authority zone in the viewports.
 
std::vector< PersistentStorage * > psa_list {}
 
- Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::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, Tpool_type, Tcache >::PoolItem<&_town_pool >
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > Pool
 Type of the pool this item is going to be part of.
 

Detailed Description

Town data structure.

Definition at line 52 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 110 of file town.h.

◆ ~Town()

Member Function Documentation

◆ FillCachedName()

void Town::FillCachedName ( ) const
private

Definition at line 217 of file town_cmd.cpp.

◆ GetByTile()

static Town * Town::GetByTile ( TileIndex  tile)
inlinestatic

Definition at line 140 of file town.h.

◆ GetCachedName()

const std::string & Town::GetCachedName ( ) const
inline

Definition at line 133 of file town.h.

◆ GetPercentTransported()

uint8_t Town::GetPercentTransported ( CargoType  cargo_type) const
inline

Definition at line 83 of file town.h.

◆ GetRandom()

◆ 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 183 of file town_cmd.cpp.

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

Referenced by DoCreateTown().

◆ 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 123 of file town.h.

References _settings_game, cache, GameSettings::difficulty, GameSettings::economy, TownCache::population, DifficultySettings::town_council_tolerance, and EconomySettings::town_noise_population.

Referenced by CmdBuildAirport().

◆ PostDestructor()

void Town::PostDestructor ( size_t  index)
static

Invalidating of the "nearest town cache" has to be done after removing item from the pool.

Definition at line 168 of file town_cmd.cpp.

References CalcClosestTownFromTile(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::Iterate(), UpdateNearestTownForRoadTiles(), and WC_TOWN_DIRECTORY.

◆ UpdateVirtCoord()

Field Documentation

◆ cache

◆ cached_name

std::string Town::cached_name {}
mutable

NOSAVE: Cache of the resolved name of the town, if not using a custom town name.

Definition at line 62 of file town.h.

Referenced by CmdRenameTown().

◆ exclusive_counter

uint8_t Town::exclusive_counter = 0

◆ exclusivity

CompanyID Town::exclusivity = CompanyID::Invalid()

◆ flags

◆ fund_buildings_months

uint8_t Town::fund_buildings_months = 0

◆ goal

std::array<uint32_t, NUM_TAE> Town::goal {}

Amount of cargo required for the town to grow.

Definition at line 79 of file town.h.

Referenced by CmdTownCargoGoal(), DoCreateTown(), TownViewWindow::DrawWidget(), TownViewWindow::GetDesiredInfoHeight(), and UpdateTownGrowth().

◆ grow_counter

uint16_t Town::grow_counter = 0

counter to count when to grow, value is smaller than or equal to growth_rate

Definition at line 93 of file town.h.

Referenced by CmdTownGrowthRate(), DoCreateTown(), TownScopeResolver::GetVariable(), TownActionFundBuildings(), TownTickHandler(), and UpdateTownGrowCounter().

◆ growth_rate

◆ have_ratings

◆ larger_town

bool Town::larger_town = false

if this is a larger town and should grow more quickly

Definition at line 99 of file town.h.

Referenced by DoCreateTown(), GetNormalGrowthRate(), TownDirectoryWindow::GetTownString(), and TownScopeResolver::GetVariable().

◆ layout

◆ name

std::string Town::name {}

Custom town name. If empty, the town was not renamed and uses the generated name.

Definition at line 61 of file town.h.

Referenced by CmdFoundTown(), CmdRenameTown(), FormatString(), GenerateCompanyName(), IsUniqueTownName(), and MoveBuoysToWaypoints().

◆ noise_reached

uint16_t Town::noise_reached = 0

level of noise that all the airports are generating

Definition at line 66 of file town.h.

Referenced by CmdBuildAirport(), TownViewWindow::DrawWidget(), RemoveAirport(), and UpdateAirportsNoise().

◆ psa_list

std::vector<PersistentStorage *> Town::psa_list {}

Definition at line 104 of file town.h.

◆ ratings

◆ received

std::array<TransportedCargoStat<uint16_t>, NUM_TAE> Town::received {}

Cargo statistics about received cargotypes.

Definition at line 78 of file town.h.

Referenced by DeliverGoods(), TownViewWindow::DrawWidget(), TownScopeResolver::GetVariable(), and UpdateTownGrowth().

◆ road_build_months

uint8_t Town::road_build_months = 0

fund road reconstruction in action?

Definition at line 97 of file town.h.

Referenced by TownScopeResolver::GetVariable(), and TownActionRoadRebuild().

◆ show_zone

bool Town::show_zone = false

NOSAVE: mark town to show the local authority zone in the viewports.

Definition at line 102 of file town.h.

Referenced by DoCreateTown(), HighlightTownLocalAuthorityTiles(), TownAuthorityWindow::OnClick(), and TownAuthorityWindow::OnPaint().

◆ stations_near

StationList Town::stations_near {}

NOSAVE: List of nearby stations.

Definition at line 89 of file town.h.

Referenced by GetTileHighlightType(), MakeTownHouse(), Station::RecomputeCatchment(), and RemoveNearbyStations().

◆ statues

CompanyMask Town::statues {}

which companies have a statue?

Definition at line 68 of file town.h.

Referenced by DoCreateTown(), GetMaskOfTownActions(), TownScopeResolver::GetVariable(), and TownActionBuildStatue().

◆ supplied

std::array<TransportedCargoStat<uint32_t>, NUM_CARGO> Town::supplied {}

Cargo statistics about supplied cargo.

Definition at line 77 of file town.h.

Referenced by TownViewWindow::DrawWidget(), TownScopeResolver::GetVariable(), TownGenerateCargo(), and UpdateTownMaxPass().

◆ text

EncodedString Town::text {}

General text with additional information.

Definition at line 81 of file town.h.

Referenced by CmdTownSetText(), TownViewWindow::DrawWidget(), and TownViewWindow::GetDesiredInfoHeight().

◆ time_until_rebuild

uint16_t Town::time_until_rebuild = 0

time until we rebuild a house

Definition at line 91 of file town.h.

Referenced by DoCreateTown(), and TileLoop_Town().

◆ townnamegrfid

uint32_t Town::townnamegrfid = 0

Definition at line 58 of file town.h.

◆ townnameparts

uint32_t Town::townnameparts = 0

Definition at line 60 of file town.h.

◆ townnametype

uint16_t Town::townnametype = 0

Definition at line 59 of file town.h.

◆ unwanted

ReferenceThroughBaseContainer<std::array<uint8_t, MAX_COMPANIES> > Town::unwanted {}

how many months companies aren't wanted by towns (bribe)

Definition at line 72 of file town.h.

Referenced by GetMaskOfTownActions(), and TownActionBribe().

◆ xy


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