Base of the town class. More...
#include "core/pool_type.hpp"
#include "viewport_type.h"
#include "command_type.h"
#include "town_map.h"
#include "subsidy_type.h"
#include "openttd.h"
#include "table/strings.h"
#include "company_func.h"
#include "landscape.h"
#include "landscape_type.h"
Go to the source code of this file.
Data Structures | |
struct | BuildingCounts< T > |
struct | Town |
Town data structure. More... | |
Defines | |
#define | FOR_ALL_TOWNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start) |
#define | FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0) |
Typedefs | |
typedef Pool< Town, TownID, 64, 64000 > | TownPool |
Enumerations | |
enum | TownNeededForGrowth { GROWTH_STANDARD, GROWTH_NEED_STATION, GROWTH_NEED_MORE_PASS, GROWTH_NEED_MORE_MAIL, GROWTH_NEED_MORE_FOOD, GROWTH_NEED_MORE_WATER, GROWTH_NEED_MORE_GOODS, GROWTH_NEED_PASS, GROWTH_NEED_MAIL, GROWTH_NEED_FOOD, GROWTH_NEED_WATER, GROWTH_NEED_GOODS, GROWTH_SATISFIED } |
What is needed for town growth. More... | |
enum | TownRatingCheckType { ROAD_REMOVE = 0, TUNNELBRIDGE_REMOVE = 1, TOWN_RATING_CHECK_TYPE_COUNT } |
Action types that a company must ask permission for to a town authority. More... | |
enum | TownFlags { TOWN_IS_FUNDED = 0, TOWN_HAS_CHURCH = 1, TOWN_HAS_STADIUM = 2 } |
This enum is used in conjunction with town->flags. More... | |
enum | TownActions { TACT_NONE = 0x00, TACT_ADVERTISE_SMALL = 0x01, TACT_ADVERTISE_MEDIUM = 0x02, TACT_ADVERTISE_LARGE = 0x04, TACT_ROAD_REBUILD = 0x08, TACT_BUILD_STATUE = 0x10, TACT_FOUND_BUILDINGS = 0x20, TACT_BUY_RIGHTS = 0x40, TACT_BRIBE = 0x80, TACT_COUNT = 8, TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE, TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS, TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE, TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS } |
Town actions of a company. More... | |
Functions | |
uint32 | GetWorldPopulation () |
Determines the world population Basically, count population of all towns, one by one. | |
void | UpdateAllTownVirtCoords () |
Update the virtual coords needed to draw the town sign for all towns. | |
void | ShowTownViewWindow (TownID town) |
void | ExpandTown (Town *t) |
CommandCost | CheckforTownRating (DoCommandFlag flags, Town *t, TownRatingCheckType type) |
Does the town authority allow the (destructive) action of the current company? | |
TileIndexDiff | GetHouseNorthPart (HouseID &house) |
Determines if a given HouseID is part of a multitile house. | |
Town * | CalcClosestTownFromTile (TileIndex tile, uint threshold=UINT_MAX) |
Return the town closest to the given tile within threshold. | |
void | ResetHouses () |
void | ClearTownHouse (Town *t, TileIndex tile) |
void | UpdateTownGenCargo (Town *t) |
Calculates town generated cargo. | |
void | UpdateTownDemands (Town *t) |
Calculate demanded goods for towngrowth. | |
void | UpdateTownRadius (Town *t) |
CommandCost | CheckIfAuthorityAllowsNewStation (TileIndex tile, DoCommandFlag flags) |
Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile. | |
Town * | ClosestTownFromTile (TileIndex tile, uint threshold) |
Return the town closest (in distance or ownership) to a given tile, within a given threshold. | |
void | ChangeTownRating (Town *t, int add, int max, DoCommandFlag flags) |
Changes town rating of the current company. | |
HouseZonesBits | GetTownRadiusGroup (const Town *t, TileIndex tile) |
Returns the bit corresponding to the town zone of the specified tile. | |
void | SetTownRatingTestMode (bool mode) |
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings. | |
uint | GetMaskOfTownActions (int *nump, CompanyID cid, const Town *t) |
Get a list of available actions to do at a town. | |
bool | GenerateTowns (TownLayout layout) |
This function will generate a certain amount of towns, with a certain layout It can be called from the scenario editor (i.e. | |
template<class T > | |
void | MakeDefaultName (T *obj) |
Set the default name for a depot/waypoint. | |
Variables | |
static const uint | CUSTOM_TOWN_NUMBER_DIFFICULTY = 4 |
value for custom town number in difficulty settings | |
static const uint | CUSTOM_TOWN_MAX_NUMBER = 5000 |
this is the maximum number of towns a user can specify in customisation | |
static const uint | INVALID_TOWN = 0xFFFF |
TownPool | _town_pool |
static const uint8 | _difficulty_town_needed_for_growth [] |
How hard do we want the number of required cargo for the towns to be able to grow at max rate. | |
const byte | _town_action_costs [TACT_COUNT] |
Factor in the cost of each town action. | |
TownID | _new_town_id |
Base of the town class.
Definition in file town.h.
enum TownActions |
Town actions of a company.
enum TownFlags |
This enum is used in conjunction with town->flags.
IT simply states what bit is used for. It is pretty unrealistic (IMHO) to only have one church/stadium per town, NO MATTER the population of it. And there are 5 more bits available on flags...
TOWN_IS_FUNDED |
Town has received some funds for. |
TOWN_HAS_CHURCH |
There can be only one church by town. |
TOWN_HAS_STADIUM |
There can be only one stadium by town. |
enum TownNeededForGrowth |
enum TownRatingCheckType |
Action types that a company must ask permission for to a town authority.
Return the town closest to the given tile within threshold.
tile | Starting point of the search. | |
threshold | Biggest allowed distance to the town. |
NULL
if there is no such town.Definition at line 3172 of file town_cmd.cpp.
References DistanceManhattan().
Referenced by AfterLoadGame(), BuildObject(), ClosestTownFromTile(), CmdBuildRoad(), Town::PostDestructor(), RemoveRoad(), and UpdateNearestTownForRoadTiles().
void ChangeTownRating | ( | Town * | t, | |
int | add, | |||
int | max, | |||
DoCommandFlag | flags | |||
) |
Changes town rating of the current company.
t | Town to affect | |
add | Value to add | |
max | Minimum (add < 0) resp. maximum (add > 0) rating that should be achievable with this change. | |
flags | Command flags, especially DC_NO_MODIFY_TOWN_RATING is tested |
Definition at line 3276 of file town_cmd.cpp.
References _cheats, _current_company, DC_NO_MODIFY_TOWN_RATING, GetRating(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, Town::ratings, SetBit(), SetWindowDirty(), Town::UpdateVirtCoord(), and Cheat::value.
Referenced by CheckAllowRemoveRoad(), CmdPlantTree(), DoClearBridge(), and DoClearTunnel().
CommandCost CheckforTownRating | ( | DoCommandFlag | flags, | |
Town * | t, | |||
TownRatingCheckType | type | |||
) |
Does the town authority allow the (destructive) action of the current company?
flags | Checking flags of the command. | |
t | Town that must allow the company action. | |
type | Type of action that is wanted. |
Definition at line 3314 of file town_cmd.cpp.
References _cheats, _current_company, _settings_game, DC_NO_TEST_TOWN_RATING, GameSettings::difficulty, GetRating(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE, RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL, RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE, return_cmd_error, SetDParam(), DifficultySettings::town_council_tolerance, and Cheat::value.
Referenced by CheckAllowRemoveRoad(), DoClearBridge(), and DoClearTunnel().
CommandCost CheckIfAuthorityAllowsNewStation | ( | TileIndex | tile, | |
DoCommandFlag | flags | |||
) |
Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile.
tile | The tile where the station shall be constructed. | |
flags | Command flags. DC_NO_TEST_TOWN_RATING is tested. |
Definition at line 3151 of file town_cmd.cpp.
References _current_company, _settings_game, ClosestTownFromTile(), DC_NO_TEST_TOWN_RATING, EconomySettings::dist_local_authority, GameSettings::economy, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Town::ratings, return_cmd_error, and SetDParam().
Referenced by CmdBuildAirport(), CmdBuildDock(), CmdBuildRailStation(), and CmdBuildRoadStop().
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
tile | Starting point of the search. | |
threshold | Biggest allowed distance to the town. |
NULL
if there is no such town.Definition at line 3197 of file town_cmd.cpp.
References _generating_world, CalcClosestTownFromTile(), DistanceManhattan(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), GetTileType(), GetTownIndex(), HasTownOwnedRoad(), IsRoadDepot(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), MP_HOUSE, and MP_ROAD.
Referenced by AfterLoadGame(), CheckAllowRemoveRoad(), CheckIfAuthorityAllowsNewStation(), CheckIfCallBackAllowsCreation(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildDock(), CmdBuildRailStation(), CmdBuildRoadStop(), CmdDeleteTown(), CmdPlantTree(), CmdRemoveRoadStop(), DisasterTick_Big_Ufo(), DoClearBridge(), DoClearTunnel(), FindTownForIndustry(), GenerateCompanyName(), AITile::GetClosestTown(), GetNameOfOwner(), IndustryGetVariable(), MakeDefaultName(), ObjectGetVariable(), LandInfoWindow::OnInit(), and Town::~Town().
bool GenerateTowns | ( | TownLayout | layout | ) |
This function will generate a certain amount of towns, with a certain layout It can be called from the scenario editor (i.e.
: generate Random Towns) as well as from world creation.
layout | which towns will be set to, when created |
Definition at line 1934 of file town_cmd.cpp.
References _settings_game, _switch_mode_errorstr, Chance16(), GameCreationSettings::custom_town_number, CUSTOM_TOWN_NUMBER_DIFFICULTY, GameSettings::difficulty, GameSettings::economy, GameSettings::game_creation, GenerateTownName(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), GWP_TOWN, IncreaseGeneratingWorldProgress(), EconomySettings::larger_towns, DifficultySettings::number_towns, ScaleByMapSize(), SetGeneratingWorldProgress(), and TSZ_RANDOM.
Referenced by _GenerateWorld().
TileIndexDiff GetHouseNorthPart | ( | HouseID & | house | ) |
Determines if a given HouseID is part of a multitile house.
The given ID is set to the ID of the north tile and the TileDiff to the north tile is returned.
house | Is changed to the HouseID of the north tile of the same house |
Definition at line 2395 of file town_cmd.cpp.
References TileDiffXY().
Referenced by GetDistanceFromNearbyHouse(), SearchNearbyHouseClass(), SearchNearbyHouseGRFID(), SearchNearbyHouseID(), and UpdateHousesAndTowns().
Get a list of available actions to do at a town.
nump | if not NULL add put the number of available actions in it | |
cid | the company that is querying the town | |
t | the town that is queried |
Definition at line 2788 of file town_cmd.cpp.
References _settings_game, EconomySettings::bribe, COMPANY_SPECTATOR, GameSettings::economy, EconomySettings::exclusive_rights, EconomySettings::fund_roads, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), HasBit(), lengthof, Town::ratings, TACT_BRIBE, TACT_BUILD_STATUE, TACT_BUY_RIGHTS, TACT_ROAD_REBUILD, and Town::unwanted.
Referenced by CmdDoTownAction(), TownAuthorityWindow::DrawWidget(), AITown::IsActionAvailable(), TownAuthorityWindow::OnClick(), and TownAuthorityWindow::OnPaint().
Returns the bit corresponding to the town zone of the specified tile.
t | Town on which town zone is to be found | |
tile | TileIndex where town zone needs to be found |
Definition at line 1980 of file town_cmd.cpp.
References DistanceSquare().
Referenced by BuildTownHouse(), HouseGetVariable(), IndustryGetVariable(), and ObjectGetVariable().
uint32 GetWorldPopulation | ( | ) |
Determines the world population Basically, count population of all towns, one by one.
Definition at line 410 of file town_cmd.cpp.
Referenced by TownDirectoryWindow::SetStringParameters().
void MakeDefaultName | ( | T * | obj | ) |
Set the default name for a depot/waypoint.
T | The type/class to make a default name for |
obj | The object/instance we want to find the name for |
Definition at line 383 of file town.h.
References ClosestTownFromTile(), HasBit(), and SetBit().
Referenced by AfterLoadGame(), CmdBuildBuoy(), CmdBuildRailWaypoint(), CmdBuildRoadDepot(), CmdBuildShipDepot(), CmdBuildTrainDepot(), and CmdRenameDepot().
void SetTownRatingTestMode | ( | bool | mode | ) |
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings.
The function is safe to use in nested calls.
mode | Test mode switch (true means go to test-mode, false means leave test-mode). |
Definition at line 3238 of file town_cmd.cpp.
References SmallVector< SmallPair< T, U >, S >::Clear().
Referenced by DoCommand(), and DoCommandPInternal().
void UpdateAllTownVirtCoords | ( | ) |
Update the virtual coords needed to draw the town sign for all towns.
Definition at line 382 of file town_cmd.cpp.
References Town::UpdateVirtCoord().
Referenced by DoStartupNewCompany(), and UpdateAllVirtCoords().
void UpdateTownDemands | ( | Town * | t | ) |
Calculate demanded goods for towngrowth.
t | This town. |
Definition at line 1485 of file town_cmd.cpp.
References _date_daylength_factor, _difficulty_town_needed_for_growth, _settings_game, GameSettings::economy, EconomySettings::larger_town_growth_cargo, EconomySettings::town_cargo_factor, and EconomySettings::town_growth_cargo.
Referenced by AfterLoadGame(), CmdExpandTown(), DoCreateTown(), and TileLoop_Town().
void UpdateTownGenCargo | ( | Town * | t | ) |
Calculates town generated cargo.
t | This Town. |
Definition at line 1475 of file town_cmd.cpp.
Referenced by AfterLoadGame(), CmdExpandTown(), and DoCreateTown().
const uint8 _difficulty_town_needed_for_growth[] [static] |
{ 2, 2, 3, 4, 5, 6, 10, }
How hard do we want the number of required cargo for the towns to be able to grow at max rate.
Definition at line 44 of file town.h.
Referenced by UpdateTownDemands().
const byte _town_action_costs[TACT_COUNT] |
Factor in the cost of each town action.
Definition at line 2604 of file town_cmd.cpp.
Referenced by TownAuthorityWindow::DrawWidget(), and TownAuthorityWindow::UpdateWidgetSize().