23 std::vector<T> id_count{};
24 std::vector<T> class_count{};
38extern TownPool _town_pool;
64struct Town : TownPool::PoolItem<&_town_pool> {
95 uint8_t PctTransported()
const
97 if (this->production == 0)
return 0;
102 struct SuppliedCargo {
106 SuppliedCargo() =
default;
107 SuppliedCargo(
CargoType cargo) : cargo(cargo) {}
116 struct AcceptedCargo {
139 inline SuppliedCargo &GetOrCreateCargoSupplied(
CargoType cargo)
142 auto it = std::ranges::lower_bound(this->supplied, cargo, std::less{}, &SuppliedCargo::cargo);
143 if (it == std::end(this->
supplied) || it->cargo != cargo) it = this->
supplied.emplace(it, cargo);
147 inline SuppliedCargoes::const_iterator GetCargoSupplied(
CargoType cargo)
const
150 auto it = std::ranges::lower_bound(this->
supplied, cargo, std::less{}, &SuppliedCargo::cargo);
151 if (it == std::end(this->
supplied) || it->cargo != cargo)
return std::end(this->
supplied);
164 if (it == std::end(this->accepted) || it->cargo != cargo) it = this->accepted.emplace(it, cargo);
177 if (it == std::end(this->accepted) || it->cargo != cargo)
return std::end(this->accepted);
181 inline uint8_t GetPercentTransported(
CargoType cargo_type)
const
183 auto it = this->GetCargoSupplied(cargo_type);
184 if (it == std::end(this->supplied))
return 0;
186 return it->history[LAST_MONTH].PctTransported();
204 std::vector<PersistentStorage *> psa_list{};
234 inline const std::string &GetCachedName()
const
236 if (!this->name.empty())
return this->name;
237 if (this->cached_name.empty()) this->FillCachedName();
238 return this->cached_name;
250 void FillCachedName()
const;
257void ShowTownViewWindow(TownID town);
258void ExpandTown(
Town *t);
260void RebuildTownKdtree();
264 TOWN_COUNCIL_LENIENT = 0,
265 TOWN_COUNCIL_TOLERANT = 1,
266 TOWN_COUNCIL_HOSTILE = 2,
267 TOWN_COUNCIL_PERMISSIVE = 3,
283 TDIWD_POPULATION_CHANGE,
338 assert(obj->name.empty() || obj->town_cn == UINT16_MAX);
359 T *lobj = T::GetIfValid(cid);
362 if (lobj !=
nullptr && obj != lobj) {
364 if (lobj->town == obj->town && lobj->IsOfType(obj)) {
366 uint i = (uint)lobj->town_cn - next;
376 }
while (
HasBit(used, 0));
387 if (cid == T::GetPoolSize()) cid = 0;
388 }
while (cid != idx);
390 obj->town_cn = (uint16_t)next;
397inline uint16_t TownTicksToGameTicks(uint16_t ticks)
405std::span<const DrawBuildingsTileStruct> GetTownDrawTileData();
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Types related to cargoes...
static constexpr CargoType INVALID_CARGO
Invalid marker for cargoes.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
CargoType
Cargo slots to indicate a cargo type within a game.
TownAcceptanceEffect
Town growth effect when delivering cargo.
@ End
End of town effects.
Common return value for all commands.
Container for an encoded string, created by GetEncodedString.
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).
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific type.
EnumBitSet< DoCommandFlag, uint16_t > DoCommandFlags
Bitset of DoCommandFlag elements.
#define T
Climate temperate.
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Types for storing historical data.
std::array< T, HISTORY_RECORDS > HistoryData
Container type for storing history data.
uint64_t ValidHistoryMask
Mask of valid history records.
HouseZone
Concentric rings of zoning around the centre of a town.
uint16_t HouseID
OpenTTD ID of house types.
int32_t TileIndexDiff
An offset value between two tiles.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
static auto operator<=>(const GUIBadgeClasses::Element &a, const GUIBadgeClasses::Element &b) noexcept
Compare two GUIBadgeClasses::Elements.
Functionality related to the temporary and persistent storage arrays for NewGRFs.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
RoadType
The different roadtypes we support.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
std::set< Station *, StationCompare > StationList
List of stations.
Class for storing amounts of cargo.
Specification of a cargo type.
static Town * Get(auto index)
Base class for all pools.
Data structure with cached data of towns.
uint32_t population
Current population of people.
uint32_t num_houses
Amount of houses.
TrackedViewportSign sign
Location of name sign, UpdateVirtCoord updates this.
BuildingCounts< uint16_t > building_counts
The number of each type of building in the town.
std::array< uint32_t, NUM_HOUSE_ZONES > squared_town_zone_radius
UpdateTownRadius updates this given the house count.
PartsOfSubsidy part_of_subsidy
Is this town a source/destination of a subsidy?
Storage for accepted cargo history.
AcceptedCargo(CargoType cargo)
Construct AcceptedCargo.
CargoType cargo
Cargo type of accepted cargo.
HistoryData< AcceptedHistory > history
Histor data of accepted cargo.
Individual data point for accepted cargo history.
uint32_t accepted
Total accepted.
uint32_t transported
Total transported.
uint32_t production
Total produced.
EncodedString text
General text with additional information.
bool larger_town
if this is a larger town and should grow more quickly
CompanyMask statues
which companies have a statue?
uint16_t time_until_rebuild
time until we rebuild a house
std::string cached_name
NOSAVE: Cache of the resolved name of the town, if not using a custom town name.
TileIndex xy
town center tile
uint8_t fund_buildings_months
fund buildings program in action?
uint16_t noise_reached
level of noise that all the airports are generating
SuppliedCargoes supplied
Cargo statistics about supplied cargo.
TownLayout layout
town specific road layout
AcceptedCargo & GetOrCreateCargoAccepted(CargoType cargo)
Get or create the storage for an accepted cargo.
uint16_t MaxTownNoise() const
Calculate the max town noise.
static Town * GetRandom()
Return a random valid town.
std::string name
Custom town name. If empty, the town was not renamed and uses the generated name.
Town(TownID index, TileIndex tile=INVALID_TILE)
Creates a new town.
GrfID townnamegrfid
NewGRF id that contains the name. O is not used.
uint16_t grow_counter
counter to count when to grow, value is smaller than or equal to growth_rate
std::vector< AcceptedCargo > AcceptedCargoes
Type for storage of all accepted cargo history.
uint32_t townnameparts
Random number that give unique town name when passed to generator.
TownFlags flags
See TownFlags.
TownCache cache
Container for all cacheable data.
TypedIndexContainer< std::array< uint8_t, MAX_COMPANIES >, CompanyID > unwanted
how many months companies aren't wanted by towns (bribe)
CompanyID exclusivity
which company has exclusivity
ValidHistoryMask valid_history
Mask of valid history records.
void InitializeLayout(TownLayout layout)
Assign the town layout.
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
uint8_t exclusive_counter
months till the exclusivity expires
void UpdateVirtCoord()
Resize the sign (label) of the town after it changes population.
AcceptedCargoes::const_iterator GetCargoAccepted(CargoType cargo) const
Get iterator to the storage for an accepted cargo.
EnumIndexArray< TransportedCargoStat< uint16_t >, TownAcceptanceEffect, TownAcceptanceEffect::End > received
Cargo statistics about received cargotypes.
CompanyMask have_ratings
which companies have a rating
AcceptedCargoes accepted
Cargo statistics about accepted cargo.
TypedIndexContainer< std::array< int16_t, MAX_COMPANIES >, CompanyID > ratings
ratings of each company for this town
std::vector< SuppliedCargo > SuppliedCargoes
Type for storage of all supplied cargo history.
uint16_t growth_rate
town growth rate
StationList stations_near
NOSAVE: List of nearby stations.
static void PostDestructor(size_t index)
Invalidating of the "nearest town cache" has to be done after removing item from the pool.
uint8_t road_build_months
fund road reconstruction in action?
EnumIndexArray< uint32_t, TownAcceptanceEffect, TownAcceptanceEffect::End > goal
Amount of cargo required for the town to grow.
uint16_t townnametype
The style of the name.
Specialised ViewportSign that tracks whether it is valid for entering into a Kdtree.
Basic types related to subsidies.
EnumBitSet< PartOfSubsidy, uint8_t > PartsOfSubsidy
Bitset of PartOfSubsidy elements.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition of the tick-based game-timer.
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount).
void ChangeTownRating(Town *t, int add, int max, DoCommandFlags flags)
Changes town rating of the current company.
void ResetHouses()
Reset and initialise house specs.
TownRatingCheckType
Action types that a company must ask permission for to a town authority.
@ TunnelBridgeRemove
Removal of a tunnel or bridge owned by the town.
@ RoadRemove
Removal of a road owned by the town.
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
uint GetDefaultTownsForMapSize()
Calculate the number of towns which should be on the map according to the current "town density" newg...
void ClearTownHouse(Town *t, TileIndex tile)
Clear a town house.
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
Get a list of available town authority actions.
const CargoSpec * FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
Determines the first cargo with a certain town effect.
EnumBitSet< TownFlag, uint8_t > TownFlags
Bitset of TownFlag elements.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount).
TownDirectoryInvalidateWindowData
Special values for town list window for the data parameter of InvalidateWindowData.
EnumBitSet< TownAction, uint8_t > TownActions
Bitset of TownAction elements.
bool GenerateTowns(TownLayout layout, std::optional< uint > number=std::nullopt)
Generate a number of towns with a given layout.
uint32_t GetWorldPopulation()
Get the total population, the sum of all towns in the world.
static const uint CUSTOM_TOWN_MAX_NUMBER
this is the maximum number of towns a user can specify in customisation
void UpdateTownMaxPass(Town *t)
Update the maximum amount of monthly passengers and mail for a town, based on its population.
CargoArray GetAcceptedCargoOfHouse(const HouseSpec *hs)
Get accepted cargo of a house prototype.
Town * TryGenerateNamedTownAroundTile(TileIndex target_tile, TownSize size, bool city, TownLayout layout, std::string_view name)
Try to generate a named town around a tile.
uint8_t GetTownActionCost(TownAction action)
Get cost factors for a TownAction.
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY
value for custom town number in difficulty settings
void ClearAllTownCachedNames()
Clear the cached_name of all towns.
RoadType GetTownRoadType()
Get the road type that towns should build at this current moment.
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
TownAction
Town actions of a company.
@ RoadRebuild
Rebuild the roads.
@ Bribe
Try to bribe the council.
@ AdvertiseLarge
Large advertising campaign.
@ BuildStatue
Build a statue.
@ BuyRights
Buy exclusive transport rights.
@ FundBuildings
Fund new buildings.
@ AdvertiseMedium
Medium advertising campaign.
@ AdvertiseSmall
Small advertising campaign.
CommandCost CheckforTownRating(DoCommandFlags flags, Town *t, TownRatingCheckType type)
Does the town authority allow the (destructive) action of the current company?
HouseZone GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
bool CheckTownRoadTypes()
Check if towns are able to build road.
static const uint16_t MAX_TOWN_GROWTH_TICKS
Max amount of original town ticks that still fit into uint16_t, about equal to UINT16_MAX / TOWN_GROW...
TownCouncilAttitudes
Settings for town council attitudes.
void SetTownRatingTestMode(bool mode)
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings...
void UpdateTownRadius(Town *t)
Update the cached town zone radii of a town, based on the number of houses.
TownFlag
Flags controlling various town behaviours.
@ HasChurch
There can be only one church by town.
@ CustomGrowth
Growth rate is controlled by GS.
@ HasStadium
There can be only one stadium by town.
@ IsGrowing
Conditions for town growth are met. Grow according to Town::growth_rate.
static const uint16_t TOWN_GROWTH_RATE_NONE
Special value for Town::growth_rate to disable town growth.
CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlags flags)
Checks whether the local authority allows construction of a new station (rail, road,...
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
TownID GetTownIndex(Tile t)
Get the index of which town this house/street is attached to.
TownSize
Supported initial town sizes.
Types related to viewports.