OpenTTD Source: src/object_cmd.cpp File Reference

OpenTTD Source 15.0-RC2

Functions | Variables
object_cmd.cpp File Reference

Handling of object tiles. More...

`#include "stdafx.h"`
`#include "landscape.h"`
`#include "command_func.h"`
`#include "company_func.h"`
`#include "viewport_func.h"`
`#include "company_base.h"`
`#include "town.h"`
`#include "bridge_map.h"`
`#include "genworld.h"`
`#include "autoslope.h"`
`#include "clear_func.h"`
`#include "water.h"`
`#include "window_func.h"`
`#include "company_gui.h"`
`#include "cheat_type.h"`
`#include "object.h"`
`#include "cargopacket.h"`
`#include "core/random_func.hpp"`
`#include "core/pool_func.hpp"`
`#include "object_map.h"`
`#include "object_base.h"`
`#include "newgrf_config.h"`
`#include "newgrf_object.h"`
`#include "timer/timer_game_calendar.h"`
`#include "newgrf_debug.h"`
`#include "vehicle_func.h"`
`#include "station_func.h"`
`#include "object_cmd.h"`
`#include "landscape_cmd.h"`
`#include "pathfinder/water_regions.h"`
`#include "table/strings.h"`
`#include "table/object_land.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
ObjectType | GetObjectType (Tile t)
| Gets the ObjectType of the given object tile.
void | InitializeObjects ()
| Initialize/reset the objects.
void | BuildObject (ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8_t view)
| Actually build the object.
static void | IncreaseCompanyHQSize (TileIndex tile)
| Increase the HQ size.
static uint8_t | GetCompanyHQSize (TileIndex tile)
| Get the size of the HQ.
void | UpdateCompanyHQ (TileIndex tile, uint score)
| Update the CompanyHQ to the state associated with the given score.
void | UpdateObjectColours (const Company *c)
| Updates the colour of the object whenever a company changes.
CommandCost | CheckBuildableTile (TileIndex tile, DiagDirections invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge)
| Checks if the given tile is buildable, flat and has a certain height.
static CommandCost | ClearTile_Object (TileIndex tile, DoCommandFlags flags)
CommandCost | CmdBuildObject (DoCommandFlags flags, TileIndex tile, ObjectType type, uint8_t view)
| Build an object object.
CommandCost | CmdBuildObjectArea (DoCommandFlags flags, TileIndex tile, TileIndex start_tile, ObjectType type, uint8_t view, bool diagonal)
| Construct multiple objects in an area.
static Foundation | GetFoundation_Object (TileIndex tile, Slope tileh)
static void | DrawTile_Object (TileInfo *ti)
static int | GetSlopePixelZ_Object (TileIndex tile, uint x, uint y, bool)
static void | ReallyClearObjectTile (Object *o)
| Perform the actual removal of the object from the map.
ClearedObjectArea * | FindClearedObject (TileIndex tile)
| Find the entry in _cleared_object_areas which occupies a certain tile.
static void | AddAcceptedCargo_Object (TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
static void | AddProducedCargo_Object (TileIndex tile, CargoArray &produced)
static void | GetTileDesc_Object (TileIndex tile, TileDesc &td)
static void | TileLoop_Object (TileIndex tile)
static TrackStatus | GetTileTrackStatus_Object (TileIndex, TransportType, uint, DiagDirection)
static bool | ClickTile_Object (TileIndex tile)
static void | AnimateTile_Object (TileIndex tile)
static bool | TryBuildLightHouse ()
| Try to build a lighthouse.
static bool | TryBuildTransmitter ()
| Try to build a transmitter.
void | GenerateObjects ()
static void | ChangeTileOwner_Object (TileIndex tile, Owner old_owner, Owner new_owner)
static CommandCost | TerraformTile_Object (TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
static CommandCost | CheckBuildAbove_Object (TileIndex tile, DoCommandFlags flags, Axis, int height)

## Variables
ObjectPool | _object_pool ("Object")
std::vector< ClearedObjectArea > | _cleared_object_areas
const TileTypeProcs | _tile_type_object_procs

## Detailed Description

Handling of object tiles.

Definition in file object_cmd.cpp.

## Function Documentation

## ◆ AddAcceptedCargo_Object()

static void AddAcceptedCargo_Object | ( | TileIndex | tile,
|  | CargoArray & | acceptance,
|  | CargoTypes & | always_accepted
| ) |  |
| static

Definition at line 620 of file object_cmd.cpp.

## ◆ AddProducedCargo_Object()

static void AddProducedCargo_Object | ( | TileIndex | tile,
|  | CargoArray & | produced
| ) |  |
| static

Definition at line 649 of file object_cmd.cpp.

## ◆ AnimateTile_Object()

static void AnimateTile_Object | ( | TileIndex | tile | ) |
| static

Definition at line 740 of file object_cmd.cpp.

## ◆ BuildObject()

void BuildObject | ( | ObjectType | type,
|  | TileIndex | tile,
|  | CompanyID | owner,
|  | Town * | town,
|  | uint8_t | view
| ) |  |

Actually build the object.

Parameters

  type | The type of object to build.
  tile | The tile to build the northern tile of the object on.
  owner | The owner of the object.
  town | Town the tile is related with.
  view | The view for the object.

Precondition
  All preconditions for building the object at that location are met, e.g. slope and clearness of tiles are checked.

Definition at line 88 of file object_cmd.cpp.

References Animation, Built, CalcClosestTownFromTile(), CALLBACK_FAILED, ObjectSpec::callback_mask, Canal, CBID_OBJECT_COLOUR, ClearNeighbourNonFloodingStates(), Colour, Object::colour, TimerGameCalendar::date, DirtyCompanyInfrastructureWindows(), ErrorUnknownCallbackResult(), ObjectSpec::flags, GB(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), ObjectSpec::Get(), GetObjectCallback(), GetWaterClass(), ObjectSpec::grf_prop, GRFFilePropsBase::grfid, HasBit(), HasTileWaterGround(), Object::IncTypeCount(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Invalid, InvalidateWaterRegion(), IsDockingTile(), IsTileOwner(), IsWaterTile(), MakeObject(), MarkTileDirtyByTile(), OWNER_NONE, OWNER_WATER, Random, ObjectSpec::size, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Object::town, TriggerObjectAnimation(), and Uses2CC.

Referenced by CmdBuildObject(), TownActionBuildStatue(), TryBuildLightHouse(), and TryBuildTransmitter().

## ◆ ChangeTileOwner_Object()

static void ChangeTileOwner_Object | ( | TileIndex | tile,
|  | Owner | old_owner,
|  | Owner | new_owner
| ) |  |
| static

Definition at line 867 of file object_cmd.cpp.

## ◆ CheckBuildableTile()

CommandCost CheckBuildableTile | ( | TileIndex | tile,
|  | DiagDirections | invalid_dirs,
|  | int & | allowed_z,
|  | bool | allow_steep,
|  | bool | check_bridge = `true`
| ) |  |
| extern

Checks if the given tile is buildable, flat and has a certain height.

Parameters

  tile | TileIndex to check.
  invalid_dirs | Prohibited directions for slopes (set of DiagDirection).
  allowed_z | Height allowed for the tile. If allowed_z is negative, it will be set to the height of this tile.
  allow_steep | Whether steep slopes are allowed.
  check_bridge | Check for the existence of a bridge.

Returns
  The cost in case of success, or an error code if it failed.

Definition at line 789 of file station_cmd.cpp.

References _settings_game, CommandCost::AddCost(), ConstructionSettings::build_on_slopes, CanBuildDepotByTileh(), GameSettings::construction, DIAGDIR_BEGIN, DIAGDIR_END, EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetSlopeMaxZ(), GetTileSlopeZ(), IsBridgeAbove(), IsSteepSlope(), SLOPE_FLAT, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CheckFlatLandAirport(), CheckFlatLandRailStation(), CheckFlatLandRoadStop(), and CmdBuildObject().

## ◆ CheckBuildAbove_Object()

static CommandCost CheckBuildAbove_Object | ( | TileIndex | tile,
|  | DoCommandFlags | flags,
|  | Axis | ,
|  | int | height
| ) |  |
| static

Definition at line 938 of file object_cmd.cpp.

## ◆ ClearTile_Object()

static CommandCost ClearTile_Object | ( | TileIndex | tile,
|  | DoCommandFlags | flags
| ) |  |
| static

Definition at line 541 of file object_cmd.cpp.

## ◆ ClickTile_Object()

static bool ClickTile_Object | ( | TileIndex | tile | ) |
| static

Definition at line 732 of file object_cmd.cpp.

## ◆ CmdBuildObject()

CommandCost CmdBuildObject | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | ObjectType | type,
|  | uint8_t | view
| ) |  |

Build an object object.

Parameters

  flags | type of operation
  tile | tile where the object will be located
  type | the object type to build
  view | the view for the object

Returns
  the cost of this operation or an error

Definition at line 210 of file object_cmd.cpp.

References _current_company, _generating_world, _settings_game, CommandCost::AddCost(), AllowUnderBridge, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), CompanyProperties::build_object_limit, BuildObject(), BuiltOnWater, CALLBACK_FAILED, ObjectSpec::callback_mask, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::CanAllocateItem(), CBID_OBJECT_LAND_SLOPE_CHECK, CheckBuildableTile(), CheckOwnership(), CMD_ERROR, GameSettings::construction, EnsureNoVehicleOnGround(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), ObjectSpec::flags, ConstructionSettings::freeform_edges, GB(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), ObjectSpec::Get(), GetBridgeHeight(), ObjectSpec::GetBuildCost(), GetErrorMessageFromLocationCallbackResult(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), GetObjectCallback(), GetSouthernBridgeEnd(), GetTileMaxZ(), GetTileOwner(), GetTileSlope(), GetTileSlopeZ(), ObjectSpec::grf_prop, GRFFilePropsBase::grffile, HasBit(), HasTileWaterGround(), ObjectSpec::height, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, INVALID_TILE, ObjectSpec::IsAvailable(), IsBridgeAbove(), IsInsideMM(), IsObjectType(), IsTileFlat(), IsTileOwner(), IsTileType(), IsValidTile(), IsWaterTile(), CompanyProperties::location_of_HQ, Map::MaxX(), Map::MaxY(), MP_OBJECT, NotOnLand, NoWater, OBJECT_HQ, OBJECT_LIGHTHOUSE, OBJECT_OWNED_LAND, OBJECT_STATUE, OBJECT_TRANSMITTER, OnlyInGame, OnlyInScenedit, OWNER_DEITY, OWNER_NONE, OWNER_WATER, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), SetWindowDirty(), ObjectSpec::size, SLOPE_FLAT, SlopeCheck, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileX(), TileY(), ToggleBit(), UpdateCompanyHQ(), UpdateCompanyRatingAndValue(), ObjectSpec::views, ObjectSpec::WasEverAvailable(), and WC_COMPANY.

## ◆ CmdBuildObjectArea()

CommandCost CmdBuildObjectArea | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | TileIndex | start_tile,
|  | ObjectType | type,
|  | uint8_t | view,
|  | bool | diagonal
| ) |  |

Construct multiple objects in an area.

Parameters

  flags | of operation to conduct
  tile | end tile of area dragging
  start_tile | start tile of area dragging
  type | the object type to build
  view | the view for the object
  diagonal | Whether to use the Orthogonal (0) or Diagonal (1) iterator.

Returns
  the cost of this operation or an error

Definition at line 397 of file object_cmd.cpp.

References _current_company, CommandCost::AddCost(), CompanyProperties::build_object_limit, CMD_ERROR, TileIterator::Create(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), GB(), ObjectSpec::Get(), GetAvailableMoneyForCommand(), CommandCost::GetCost(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), INVALID_TILE, OBJECT_SIZE_1X1, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), Map::Size(), ObjectSpec::size, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and ObjectSpec::views.

## ◆ DrawTile_Object()

static void DrawTile_Object | ( | TileInfo * | ti | ) |
| static

Definition at line 444 of file object_cmd.cpp.

## ◆ FindClearedObject()

ClearedObjectArea * FindClearedObject | ( | TileIndex | tile | ) |

Find the entry in _cleared_object_areas which occupies a certain tile.

Parameters

  tile | Tile of interest

Returns
  Occupying entry, or nullptr if none

Definition at line 530 of file object_cmd.cpp.

Referenced by CmdBuildTunnel(), CmdLandscapeClear(), and CmdTerraformLand().

## ◆ GenerateObjects()

void GenerateObjects | ( |  | ) |

Definition at line 808 of file object_cmd.cpp.

## ◆ GetCompanyHQSize()

static uint8_t GetCompanyHQSize | ( | TileIndex | tile | ) |
| static

Get the size of the HQ.

Parameters

  tile | The (northern) tile of the company HQ.

Returns
  HQ size.

Definition at line 154 of file object_cmd.cpp.

References GetAnimationFrame().

Referenced by UpdateCompanyHQ().

## ◆ GetFoundation_Object()

static Foundation GetFoundation_Object | ( | TileIndex | tile,
|  | Slope | tileh
| ) |  |
| static

Definition at line 503 of file object_cmd.cpp.

## ◆ GetObjectType()

ObjectType GetObjectType | ( | Tile | t | ) |

Gets the ObjectType of the given object tile.

Parameters

  t | the tile to get the type from.

Precondition
  IsTileType(t, MP_OBJECT)

Returns
  the type.

Definition at line 66 of file object_cmd.cpp.

References Object::GetByTile(), IsTileType(), MP_OBJECT, and Object::type.

Referenced by ObjectSpec::GetByTile(), IsObjectType(), and IsObjectTypeTile().

## ◆ GetSlopePixelZ_Object()

static int GetSlopePixelZ_Object | ( | TileIndex | tile,
|  | uint | x,
|  | uint | y,
|  | bool |
| ) |  |
| static

Definition at line 492 of file object_cmd.cpp.

## ◆ GetTileDesc_Object()

static void GetTileDesc_Object | ( | TileIndex | tile,
|  | TileDesc & | td
| ) |  |
| static

Definition at line 660 of file object_cmd.cpp.

## ◆ GetTileTrackStatus_Object()

static TrackStatus GetTileTrackStatus_Object | ( | TileIndex | ,
|  | TransportType | ,
|  | uint | ,
|  | DiagDirection |
| ) |  |
| static

Definition at line 727 of file object_cmd.cpp.

## ◆ IncreaseCompanyHQSize()

static void IncreaseCompanyHQSize | ( | TileIndex | tile | ) |
| static

Increase the HQ size.

Parameters

  tile | The (northern) tile of the company HQ.

Definition at line 139 of file object_cmd.cpp.

References GetAnimationFrame(), Object::GetByTile(), Object::location, MarkTileDirtyByTile(), and SetAnimationFrame().

Referenced by UpdateCompanyHQ().

## ◆ InitializeObjects()

void InitializeObjects | ( |  | ) |

Initialize/reset the objects.

Definition at line 73 of file object_cmd.cpp.

References Object::ResetTypeCounts().

## ◆ ReallyClearObjectTile()

static void ReallyClearObjectTile | ( | Object * | o | ) |
| static

Perform the actual removal of the object from the map.

Parameters

  o | The object to really clear.

Definition at line 512 of file object_cmd.cpp.

References Object::DecTypeCount(), DeleteNewGRFInspectWindow(), GetTileOwner(), Object::location, and Object::type.

## ◆ TerraformTile_Object()

static CommandCost TerraformTile_Object | ( | TileIndex | tile,
|  | DoCommandFlags | flags,
|  | int | z_new,
|  | Slope | tileh_new
| ) |  |
| static

Definition at line 903 of file object_cmd.cpp.

## ◆ TileLoop_Object()

static void TileLoop_Object | ( | TileIndex | tile | ) |
| static

Definition at line 672 of file object_cmd.cpp.

## ◆ TryBuildLightHouse()

static bool TryBuildLightHouse | ( |  | ) |
| static

Try to build a lighthouse.

Returns
  True iff building a lighthouse succeeded.

Definition at line 749 of file object_cmd.cpp.

References AXIS_X, BuildObject(), DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirToAxis(), GB(), GetWaterClass(), IsBridgeAbove(), IsObjectTypeTile(), IsTileFlat(), IsTileType(), IsValidTile(), Map::MaxX(), Map::MaxY(), MP_CLEAR, MP_WATER, OBJECT_LIGHTHOUSE, Random, Sea, Map::Size(), TileOffsByDiagDir(), and TileXY().

## ◆ TryBuildTransmitter()

static bool TryBuildTransmitter | ( |  | ) |
| static

Try to build a transmitter.

Returns
  True iff a transmitter was built.

Definition at line 794 of file object_cmd.cpp.

References BuildObject(), IsBridgeAbove(), IsObjectTypeTile(), IsTileFlat(), IsTileType(), MP_CLEAR, OBJECT_TRANSMITTER, and RandomTile.

## ◆ UpdateCompanyHQ()

void UpdateCompanyHQ | ( | TileIndex | tile,
|  | uint | score
| ) |  |

Update the CompanyHQ to the state associated with the given score.

Parameters

  tile | The (northern) tile of the company HQ, or INVALID_TILE.
  score | The current (performance) score of the company.

Definition at line 165 of file object_cmd.cpp.

References GetCompanyHQSize(), IncreaseCompanyHQSize(), and INVALID_TILE.

Referenced by CmdBuildObject(), and UpdateCompanyRatingAndValue().

## ◆ UpdateObjectColours()

void UpdateObjectColours | ( | const Company * | c | ) |

Updates the colour of the object whenever a company changes.

Parameters

  c | The company the company colour changed of.

Definition at line 184 of file object_cmd.cpp.

References ObjectSpec::callback_mask, Colour, ObjectSpec::flags, ObjectSpec::GetByTile(), Company::GetCompanyRecolourOffset(), GetTileOwner(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::Iterate(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Uses2CC.

Referenced by CmdSetCompanyColour().

## Variable Documentation

## ◆ _cleared_object_areas

std::vector<ClearedObjectArea> _cleared_object_areas

Definition at line 523 of file object_cmd.cpp.

## ◆ _tile_type_object_procs

const TileTypeProcs _tile_type_object_procs
| extern

Initial value:
= {
DrawTile_Object,
GetSlopePixelZ_Object,
ClearTile_Object,
AddAcceptedCargo_Object,
GetTileDesc_Object,
GetTileTrackStatus_Object,
ClickTile_Object,
AnimateTile_Object,
TileLoop_Object,
ChangeTileOwner_Object,
AddProducedCargo_Object,
nullptr,
GetFoundation_Object,
TerraformTile_Object,
CheckBuildAbove_Object,
}

Definition at line 61 of file landscape.cpp.