OpenTTD Source  20241109-master-g5e4f8db7d6
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.

Macros

#define GetCompanyHQSize   GetAnimationFrame
 We encode the company HQ size in the animation stage.
 
#define IncreaseCompanyHQSize   IncreaseAnimationStage
 We encode the company HQ size in the animation stage.
 

Functions

ObjectType GetObjectType (Tile t)
 Gets the ObjectType of the given object tile. More...
 
void InitializeObjects ()
 Initialize/reset the objects.
 
void BuildObject (ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8_t view)
 Actually build the object. More...
 
static void IncreaseAnimationStage (TileIndex tile)
 Increase the animation stage of a whole structure. More...
 
void UpdateCompanyHQ (TileIndex tile, uint score)
 Update the CompanyHQ to the state associated with the given score. More...
 
void UpdateObjectColours (const Company *c)
 Updates the colour of the object whenever a company changes. More...
 
CommandCost CheckBuildableTile (TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge)
 Checks if the given tile is buildable, flat and has a certain height. More...
 
static CommandCost ClearTile_Object (TileIndex tile, DoCommandFlag flags)
 
CommandCost CmdBuildObject (DoCommandFlag flags, TileIndex tile, ObjectType type, uint8_t view)
 Build an object object. More...
 
CommandCost CmdBuildObjectArea (DoCommandFlag flags, TileIndex tile, TileIndex start_tile, ObjectType type, uint8_t view, bool diagonal)
 Construct multiple objects in an area. More...
 
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. More...
 
ClearedObjectAreaFindClearedObject (TileIndex tile)
 Find the entry in _cleared_object_areas which occupies a certain tile. More...
 
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 HasTransmitter (TileIndex tile, void *)
 Helper function for CircularTileSearch. More...
 
static bool TryBuildLightHouse ()
 Try to build a lighthouse. More...
 
static bool TryBuildTransmitter ()
 Try to build a transmitter. More...
 
void GenerateObjects ()
 
static void ChangeTileOwner_Object (TileIndex tile, Owner old_owner, Owner new_owner)
 
static CommandCost TerraformTile_Object (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 

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

◆ BuildObject()

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

Actually build the object.

Parameters
typeThe type of object to build.
tileThe tile to build the northern tile of the object on.
ownerThe owner of the object.
townTown the tile is related with.
viewThe 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 Object::build_date, CalcClosestTownFromTile(), Object::colour, TimerGameCalendar::date, GB(), ObjectSpec::Get(), HasBit(), Object::location, OWNER_NONE, ObjectSpec::size, Object::town, Object::type, and Object::view.

Referenced by TownActionBuildStatue(), and TryBuildTransmitter().

◆ CheckBuildableTile()

CommandCost CheckBuildableTile ( TileIndex  tile,
uint  invalid_dirs,
int &  allowed_z,
bool  allow_steep,
bool  check_bridge = true 
)

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

Parameters
tileTileIndex to check.
invalid_dirsProhibited directions for slopes (set of DiagDirection).
allowed_zHeight allowed for the tile. If allowed_z is negative, it will be set to the height of this tile.
allow_steepWhether steep slopes are allowed.
check_bridgeCheck for the existence of a bridge.
Returns
The cost in case of success, or an error code if it failed.

Definition at line 803 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(), HasBit(), IsBridgeAbove(), IsSteepSlope(), return_cmd_error, and SLOPE_FLAT.

Referenced by CheckFlatLandAirport(), and CheckFlatLandRoadStop().

◆ CmdBuildObject()

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

Build an object object.

Parameters
flagstype of operation
tiletile where the object will be located
typethe object type to build
viewthe view for the object
Returns
the cost of this operation or an error

Definition at line 210 of file object_cmd.cpp.

References CMD_ERROR, EXPENSES_CONSTRUCTION, and ObjectSpec::Get().

◆ CmdBuildObjectArea()

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

Construct multiple objects in an area.

Parameters
flagsof operation to conduct
tileend tile of area dragging
start_tilestart tile of area dragging
typethe object type to build
viewthe view for the object
diagonalWhether to use the Orthogonal (0) or Diagonal (1) iterator.
Returns
the cost of this operation or an error

Definition at line 391 of file object_cmd.cpp.

References _current_company, CommandCost::AddCost(), CompanyProperties::build_object_limit, CMD_ERROR, TileIterator::Create(), DC_EXEC, EXPENSES_CONSTRUCTION, CommandCost::Failed(), GB(), ObjectSpec::Get(), GetAvailableMoneyForCommand(), CommandCost::GetCost(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), INVALID_TILE, OBJECT_SIZE_1X1, Map::Size(), ObjectSpec::size, and ObjectSpec::views.

◆ FindClearedObject()

ClearedObjectArea* FindClearedObject ( TileIndex  tile)

Find the entry in _cleared_object_areas which occupies a certain tile.

Parameters
tileTile of interest
Returns
Occupying entry, or nullptr if none

Definition at line 531 of file object_cmd.cpp.

Referenced by CmdTerraformLand().

◆ GetObjectType()

ObjectType GetObjectType ( Tile  t)

Gets the ObjectType of the given object tile.

Parameters
tthe 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().

◆ HasTransmitter()

static bool HasTransmitter ( TileIndex  tile,
void *   
)
static

Helper function for CircularTileSearch.

Parameters
tileThe tile to check.
Returns
True iff the tile has a radio tower.

Definition at line 751 of file object_cmd.cpp.

References IsObjectTypeTile(), and OBJECT_TRANSMITTER.

Referenced by TryBuildTransmitter().

◆ IncreaseAnimationStage()

static void IncreaseAnimationStage ( TileIndex  tile)
static

Increase the animation stage of a whole structure.

Parameters
tileThe tile of the structure.

Definition at line 145 of file object_cmd.cpp.

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

◆ ReallyClearObjectTile()

static void ReallyClearObjectTile ( Object o)
static

Perform the actual removal of the object from the map.

Parameters
oThe object to really clear.

Definition at line 513 of file object_cmd.cpp.

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

◆ TryBuildLightHouse()

static bool TryBuildLightHouse ( )
static

Try to build a lighthouse.

Returns
True iff building a lighthouse succeeded.

Definition at line 760 of file object_cmd.cpp.

References Map::MaxX(), and Map::MaxY().

◆ TryBuildTransmitter()

static bool TryBuildTransmitter ( )
static

Try to build a transmitter.

Returns
True iff a transmitter was built.

Definition at line 802 of file object_cmd.cpp.

References BuildObject(), CircularTileSearch(), HasTransmitter(), IsBridgeAbove(), 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
tileThe (northern) tile of the company HQ, or INVALID_TILE.
scoreThe current (performance) score of the company.

Definition at line 164 of file object_cmd.cpp.

References GetCompanyHQSize, IncreaseCompanyHQSize, and INVALID_TILE.

◆ UpdateObjectColours()

Variable Documentation

◆ _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,
}

Definition at line 58 of file landscape.cpp.