OpenTTD Source: src/town_cmd.h File Reference

OpenTTD Source 15.0-RC2

Typedefs | Functions | Variables
town_cmd.h File Reference

Command definitions related to towns. More...

`#include "command_type.h"`
`#include "company_type.h"`
`#include "town.h"`
`#include "town_type.h"`

Go to the source code of this file.

## Typedefs
using | HouseID = uint16_t

## Functions
std::tuple< CommandCost, Money, TownID > | CmdFoundTown (DoCommandFlags flags, TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32_t townnameparts, const std::string &text)
| Create a new town.
CommandCost | CmdRenameTown (DoCommandFlags flags, TownID town_id, const std::string &text)
| Rename a town (server-only).
CommandCost | CmdDoTownAction (DoCommandFlags flags, TownID town_id, TownAction action)
| Do a town action.
CommandCost | CmdTownGrowthRate (DoCommandFlags flags, TownID town_id, uint16_t growth_rate)
| Change the growth rate of the town.
CommandCost | CmdTownRating (DoCommandFlags flags, TownID town_id, CompanyID company_id, int16_t rating)
| Change the rating of a company in a town.
CommandCost | CmdTownCargoGoal (DoCommandFlags flags, TownID town_id, TownAcceptanceEffect tae, uint32_t goal)
| Change the cargo goal of a town.
CommandCost | CmdTownSetText (DoCommandFlags flags, TownID town_id, const EncodedString &text)
| Set a custom text in the Town window.
CommandCost | CmdExpandTown (DoCommandFlags flags, TownID town_id, uint32_t grow_amount, TownExpandModes modes)
| Expand a town (scenario editor only).
CommandCost | CmdDeleteTown (DoCommandFlags flags, TownID town_id)
| Delete a town (scenario editor or worldgen only).
CommandCost | CmdPlaceHouse (DoCommandFlags flags, TileIndex tile, HouseID house, bool house_protected, bool replace)
| Place an individual house.
void | CcFoundRandomTown (Commands cmd, const CommandCost &result, Money, TownID town_id)

## Variables
CommandCallback | CcFoundTown

## Detailed Description

Command definitions related to towns.

Definition in file town_cmd.h.

## Typedef Documentation

## ◆ HouseID

using HouseID = uint16_t

Definition at line 19 of file town_cmd.h.

## Function Documentation

## ◆ CcFoundRandomTown()

void CcFoundRandomTown | ( | Commands | cmd,
|  | const CommandCost & | result,
|  | Money | ,
|  | TownID | town_id
| ) |  |

Definition at line 1066 of file town_gui.cpp.

## ◆ CmdDeleteTown()

CommandCost CmdDeleteTown | ( | DoCommandFlags | flags,
|  | TownID | town_id
| ) |  |

Delete a town (scenario editor or worldgen only).

Parameters

  flags | Type of operation.
  town_id | Town ID to delete.

Returns
  Empty cost or an error.

Definition at line 3286 of file town_cmd.cpp.

References _generating_world, Airport, AT_OILRIG, Town::cache, CMD_ERROR, Execute, CommandCost::Failed(), Industry::GetByTile(), Object::GetByTile(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), GetTileType(), GetTownIndex(), HasTownOwnedRoad(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsTileType(), Map::Iterate(), SpecializedStation< Waypoint, true >::Iterate(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_depot_pool >::Iterate(), TrackedViewportSign::kdtree_valid, MP_HOUSE, MP_INDUSTRY, MP_OBJECT, MP_ROAD, MP_TUNNELBRIDGE, OBJECT_STATUE, Kdtree< T, TxyFunc, CoordT, DistT >::Remove(), TownCache::sign, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TestTownOwnsBridge(), Industry::town, Object::town, and Object::type.

## ◆ CmdDoTownAction()

CommandCost CmdDoTownAction | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | TownAction | action
| ) |  |

Do a town action.

This performs an action such as advertising, building a statue, funding buildings, but also bribing the town-council

Parameters

  flags | type of operation
  town_id | town to do the action at
  action | action to perform,

See also
  _town_action_proc for the list of available actions

Returns
  the cost of this operation or an error

Definition at line 3719 of file town_cmd.cpp.

References _current_company, CMD_ERROR, Execute, EXPENSES_OTHER, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), GetMaskOfTownActions(), GetTownActionCost(), SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), to_underlying(), and WC_TOWN_AUTHORITY.

## ◆ CmdExpandTown()

CommandCost CmdExpandTown | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | uint32_t | grow_amount,
|  | TownExpandModes | modes
| ) |  |

Expand a town (scenario editor only).

Parameters

  flags | Type of operation.
  TownID | Town ID to expand.
  grow_amount | Amount to grow, or 0 to grow a random size up to the current amount of houses.

Returns
  Empty cost or an error.

Definition at line 3248 of file town_cmd.cpp.

References _current_company, Town::cache, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), GrowTown(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::None(), TownCache::num_houses, OWNER_DEITY, RandomRange(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateTownMaxPass(), and UpdateTownRadius().

## ◆ CmdFoundTown()

std::tuple< CommandCost, Money, TownID > CmdFoundTown | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | TownSize | size,
|  | bool | city,
|  | TownLayout | layout,
|  | bool | random_location,
|  | uint32_t | townnameparts,
|  | const std::string & | text
| ) |  |

Create a new town.

Parameters

  flags | The type of operation.
  tile | The coordinates where town is built.
  size | The size of the town (

See also
  TownSize).

Parameters

  city | Should we build a city?
  layout | The town road layout (

See also
  TownLayout).

Parameters

  random_location | Should we use a random location? (randomize `tile` )
  townnameparts | Town name parts.
  text | Custom name for the town. If empty, the town name parts will be used.

Returns
  The cost of this operation or an error.

Definition at line 2188 of file town_cmd.cpp.

References _current_company, _generating_world, _settings_game, AI::BroadcastNewEvent(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::CanAllocateItem(), CMD_ERROR, CreateRandomTown(), DoCreateTown(), GameSettings::economy, Execute, EXPENSES_OTHER, CommandCost::Failed(), EconomySettings::found_town, GameSettings::game_creation, GetAvailableMoneyForCommand(), CommandCost::GetCost(), GetEncodedString(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IndustryOpen, IsUniqueTownName(), lengthof, MAX_LENGTH_TOWN_NAME_CHARS, CommandCost::MultiplyCost(), Town::name, Game::NewEvent(), NUM_TLS, OWNER_DEITY, Backup< T >::Restore(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TF_CUSTOM_LAYOUT, TF_FORBIDDEN, EconomySettings::town_layout, GameCreationSettings::town_name, TownCanBePlacedHere(), TSZ_END, TSZ_LARGE, TSZ_RANDOM, UpdateNearestTownForRoadTiles(), Town::UpdateVirtCoord(), Utf8StringLength(), and VerifyTownName().

## ◆ CmdPlaceHouse()

CommandCost CmdPlaceHouse | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | HouseID | house,
|  | bool | is_protected,
|  | bool | replace
| ) |  |

Place an individual house.

Parameters

  flags | Type of operation.
  tile | Tile on which to place the house.
  HouseID | The HouseID of the house spec.
  is_protected | Whether the house is protected from the town upgrading it.
  replace | Whether to automatically demolish an existing house on this tile, if present.

Returns
  Empty cost or an error.

Definition at line 2938 of file town_cmd.cpp.

References _settings_game, OrthogonalTileArea::Add(), Auto, HouseSpec::building_flags, BuildTownHouse(), ClearTownHouse(), ClosestTownFromTile(), CMD_ERROR, DIAGDIR_SE, DIAGDIR_SW, GameSettings::economy, HouseSpec::enabled, Execute, HouseSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), GetTileMaxZ(), GetTileSlope(), GetTileType(), IsBridgeAbove(), IsSteepSlope(), MP_HOUSE, NoWater, EconomySettings::place_houses, Random, SLOPE_FLAT, HouseSpec::Specs(), CommandCost::Succeeded(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileAddByDiagDir(), and TileAddXY().

## ◆ CmdRenameTown()

CommandCost CmdRenameTown | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | const std::string & | text
| ) |  |

Rename a town (server-only).

Parameters

  flags | type of operation
  town_id | town ID to rename
  text | the new name or an empty string when resetting to the default

Returns
  the cost of this operation or an error

Definition at line 3084 of file town_cmd.cpp.

References Town::cached_name, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), IsUniqueTownName(), MAX_LENGTH_TOWN_NAME_CHARS, Town::name, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateAllStationVirtCoords(), Town::UpdateVirtCoord(), Utf8StringLength(), and WC_TOWN_DIRECTORY.

## ◆ CmdTownCargoGoal()

CommandCost CmdTownCargoGoal | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | TownAcceptanceEffect | tae,
|  | uint32_t | goal
| ) |  |

Change the cargo goal of a town.

Parameters

  flags | Type of operation.
  town_id | Town ID to cargo game of.
  tae | TownEffect to change the game of.
  goal | The new goal value.

Returns
  Empty cost or an error.

Definition at line 3134 of file town_cmd.cpp.

References _current_company, CMD_ERROR, Execute, FindFirstCargoWithTownAcceptanceEffect(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), Town::goal, InvalidateWindowData(), OWNER_DEITY, TAE_END, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateTownGrowth(), and WC_TOWN_VIEW.

## ◆ CmdTownGrowthRate()

CommandCost CmdTownGrowthRate | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | uint16_t | growth_rate
| ) |  |

Change the growth rate of the town.

Parameters

  flags | Type of operation.
  town_id | Town ID to cargo game of.
  growth_rate | Amount of days between growth, or TOWN_GROWTH_RATE_NONE, or 0 to reset custom growth rate.

Returns
  Empty cost or an error.

Definition at line 3185 of file town_cmd.cpp.

References _current_company, CMD_ERROR, CustomGrowth, Execute, Town::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), Town::grow_counter, Town::growth_rate, InvalidateWindowData(), OWNER_DEITY, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateTownGrowth(), and WC_TOWN_VIEW.

## ◆ CmdTownRating()

CommandCost CmdTownRating | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | CompanyID | company_id,
|  | int16_t | rating
| ) |  |

Change the rating of a company in a town.

Parameters

  flags | Type of operation.
  town_id | Town ID to change, bit 16..23 =
  company_id | Company ID to change.
  rating | New rating of company (signed int16_t).

Returns
  Empty cost or an error.

Definition at line 3223 of file town_cmd.cpp.

References _current_company, Clamp(), CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), OWNER_DEITY, Town::ratings, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and WC_TOWN_AUTHORITY.

## ◆ CmdTownSetText()

CommandCost CmdTownSetText | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | const EncodedString & | text
| ) |  |

Set a custom text in the Town window.

Parameters

  flags | Type of operation.
  town_id | Town ID to change the text of.
  text | The new text (empty to remove the text).

Returns
  Empty cost or an error.

Definition at line 3163 of file town_cmd.cpp.

References _current_company, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), OWNER_DEITY, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Town::text, and WC_TOWN_VIEW.

## Variable Documentation

## ◆ CcFoundTown

CommandCallback CcFoundTown

Definition at line 43 of file town_cmd.h.