OpenTTD Source 20260311-master-g511d3794ce
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)
 Tile callback function signature for clearing a tile.
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)
 Tile callback function signature for getting the foundation of a tile.
static void DrawTile_Object (TileInfo *ti)
 Tile callback function signature for drawing a tile and its contents to the screen.
static int GetSlopePixelZ_Object (TileIndex tile, uint x, uint y, bool ground_vehicle)
 Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
static void ReallyClearObjectTile (Object *o)
 Perform the actual removal of the object from the map.
ClearedObjectAreaFindClearedObject (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)
 Tile callback function signature for obtaining cargo acceptance of a tile.
static void AddProducedCargo_Object (TileIndex tile, CargoArray &produced)
 Tile callback function signature for obtaining the produced cargo of a tile.
static void GetTileDesc_Object (TileIndex tile, TileDesc &td)
 Tile callback function signature for obtaining a tile description.
static void TileLoop_Object (TileIndex tile)
 Tile callback function signature for running periodic tile updates.
static bool ClickTile_Object (TileIndex tile)
 Tile callback function signature for clicking a 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)
 Tile callback function signature for changing the owner of a tile.
static CommandCost TerraformTile_Object (TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
 Tile callback function signature of the terraforming callback.
static CommandCost CheckBuildAbove_Object (TileIndex tile, DoCommandFlags flags, Axis axis, int height)
 Tile callback function signature to test if a bridge can be built above a tile.

Variables

ObjectPool _object_pool ("Object")
std::vector< ClearedObjectArea_cleared_object_areas
const TileTypeProcs _tile_type_object_procs
 TileTypeProcs definitions for TileType::Object tiles.

Detailed Description

Handling of object tiles.

Definition in file object_cmd.cpp.

Function Documentation

◆ AddAcceptedCargo_Object()

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

Tile callback function signature for obtaining cargo acceptance of a tile.

Parameters
tileTile queried for its accepted cargo
acceptanceStorage destination of the cargo acceptance in 1/8
always_acceptedBitmask of always accepted cargo types
See also
AddAcceptedCargo

Definition at line 624 of file object_cmd.cpp.

References CT_PASSENGERS, GetCompanyHQSize(), IsObjectType(), IsValidCargoType(), OBJECT_HQ, and SetBit().

◆ AddProducedCargo_Object()

void AddProducedCargo_Object ( TileIndex tile,
CargoArray & produced )
static

Tile callback function signature for obtaining the produced cargo of a tile.

Parameters
tileTile being queried
producedDestination array for produced cargo
See also
AddProducedCargo

Definition at line 654 of file object_cmd.cpp.

References CT_PASSENGERS, IsObjectType(), IsValidCargoType(), and OBJECT_HQ.

◆ BuildObject()

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

◆ ChangeTileOwner_Object()

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

◆ 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
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 807 of file station_cmd.cpp.

References _price, _settings_game, CommandCost::AddCost(), BuildFoundation, CanBuildDepotByTileh(), 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()

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

Tile callback function signature to test if a bridge can be built above a tile.

Parameters
tileThe involved tile.
flagsCommand flags passed to the build command.
axisAxis of bridge being built.
heightAbsolute height of bridge platform.
Returns
Error code or extra cost for building bridge above the tile.
See also
CheckBuildAbove

Definition at line 940 of file object_cmd.cpp.

References AllowUnderBridge, ObjectSpec::flags, ObjectSpec::GetByTile(), GetTileMaxZ(), ObjectSpec::height, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ ClearTile_Object()

◆ ClickTile_Object()

bool ClickTile_Object ( TileIndex tile)
static

Tile callback function signature for clicking a tile.

Parameters
tileThe tile that was clicked.
Returns
Whether any action was taken.
See also
ClickTile

Definition at line 735 of file object_cmd.cpp.

References GetTileOwner(), IsObjectType(), OBJECT_HQ, and ShowCompany().

◆ CmdBuildObject()

CommandCost CmdBuildObject ( DoCommandFlags 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 _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, CBID_OBJECT_LAND_SLOPE_CHECK, CheckBuildableTile(), CheckOwnership(), ClearTile_Object(), CMD_ERROR, EnsureNoVehicleOnGround(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), ObjectSpec::flags, GB(), ObjectSpec::Get(), GetBridgeHeight(), ObjectSpec::GetBuildCost(), GetErrorMessageFromLocationCallbackResult(), GetObjectCallback(), GetSouthernBridgeEnd(), GetTileMaxZ(), GetTileOwner(), GetTileSlope(), GetTileSlopeZ(), ObjectSpec::grf_prop, GRFFilePropsBase::grffile, HasBit(), HasTileWaterGround(), ObjectSpec::height, INVALID_TILE, ObjectSpec::IsAvailable(), IsBridgeAbove(), IsInsideMM(), IsObjectType(), IsTileFlat(), IsTileOwner(), IsTileType(), IsValidTile(), IsWaterTile(), CompanyProperties::location_of_HQ, Map::MaxX(), Map::MaxY(), NotOnLand, NoWater, Object, OBJECT_HQ, OBJECT_LIGHTHOUSE, OBJECT_OWNED_LAND, OBJECT_STATUE, OBJECT_TRANSMITTER, OnlyInGame, OnlyInScenedit, OWNER_DEITY, OWNER_NONE, OWNER_WATER, 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
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 Diagonal or Orthogonal tile 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(), INVALID_TILE, OBJECT_SIZE_1X1, Map::Size(), ObjectSpec::size, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and ObjectSpec::views.

◆ DrawTile_Object()

◆ 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 532 of file object_cmd.cpp.

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

◆ GenerateObjects()

void GenerateObjects ( )

Definition at line 807 of file object_cmd.cpp.

◆ GetCompanyHQSize()

uint8_t GetCompanyHQSize ( TileIndex tile)
static

Get the size of the HQ.

Parameters
tileThe (northern) tile of the company HQ.
Returns
HQ size.

Definition at line 154 of file object_cmd.cpp.

References GetAnimationFrame().

Referenced by AddAcceptedCargo_Object(), DrawTile_Object(), TileLoop_Object(), and UpdateCompanyHQ().

◆ GetFoundation_Object()

Foundation GetFoundation_Object ( TileIndex tile,
Slope tileh )
static

Tile callback function signature for getting the foundation of a tile.

Parameters
tileThe tile to check.
tilehThe current slope.
Returns
The foundation that will be used.

Definition at line 443 of file object_cmd.cpp.

References ObjectSpec::flags, FlatteningFoundation(), FOUNDATION_NONE, ObjectSpec::Get(), GetObjectType(), HasNoFoundation, ObjectSpec::IsEnabled(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by DrawTile_Object().

◆ GetObjectType()

ObjectType GetObjectType ( Tile t)

Gets the ObjectType of the given object tile.

Parameters
tthe tile to get the type from.
Precondition
IsTileType(t, TileType::Object)
Returns
the type.

Definition at line 66 of file object_cmd.cpp.

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

Referenced by ChangeTileOwner_Object(), DrawTile_Object(), ObjectSpec::GetByTile(), GetFoundation_Object(), IsObjectType(), IsObjectTypeTile(), and TerraformTile_Object().

◆ GetSlopePixelZ_Object()

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

Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.

Parameters
tileThe queries tile for the Z coordinate.
xWorld X coordinate in tile "units".
yWorld Y coordinate in tile "units".
ground_vehicleWhether to get the Z coordinate of the ground vehicle, or the ground.
Returns
World Z coordinate at tile ground (vehicle) level, including slopes and foundations.
See also
GetSlopePixelZ

Definition at line 499 of file object_cmd.cpp.

References GetPartialPixelZ(), GetTileMaxPixelZ(), GetTilePixelSlope(), IsObjectType(), and OBJECT_OWNED_LAND.

◆ GetTileDesc_Object()

void GetTileDesc_Object ( TileIndex tile,
TileDesc & td )
static

Tile callback function signature for obtaining a tile description.

Parameters
tileTile being queried
tdStorage pointer for returned tile description
See also
GetTileDesc

Definition at line 666 of file object_cmd.cpp.

References Object::build_date, TileDesc::build_date, Object::GetByTile(), ObjectSpec::GetByTile(), GetGRFConfig(), GRFConfig::GetName(), GetTileOwner(), TileDesc::grf, ObjectSpec::grf_prop, GRFFilePropsBase::grfid, GRFFilePropsBase::HasGrfFile(), ObjectSpec::name, TileDesc::owner, and TileDesc::str.

◆ IncreaseCompanyHQSize()

void IncreaseCompanyHQSize ( TileIndex tile)
static

Increase the HQ size.

Parameters
tileThe (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()

void ReallyClearObjectTile ( Object * o)
static

Perform the actual removal of the object from the map.

Parameters
oThe object to really clear.

Definition at line 514 of file object_cmd.cpp.

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

Referenced by ChangeTileOwner_Object(), and ClearTile_Object().

◆ TerraformTile_Object()

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

Tile callback function signature of the terraforming callback.

The function is called when a tile is affected by a terraforming operation. It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype. With DoCommandFlag::Execute in flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).

Note
The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
Parameters
tileThe involved tile.
flagsCommand flags passed to the terraform command (DoCommandFlag::Execute, DoCommandFlag::QueryCost, etc.).
z_newTileZ after terraforming.
tileh_newSlope after terraforming.
Returns
Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
See also
TerraformTile

Definition at line 904 of file object_cmd.cpp.

References _price, Autoslope, AutoslopeEnabled(), BuildFoundation, CALLBACK_FAILED, ObjectSpec::callback_mask, CBID_OBJECT_AUTOSLOPE, CheckTileOwnership(), ConvertBooleanCallback(), EXPENSES_CONSTRUCTION, ObjectSpec::Get(), Object::GetByTile(), GetObjectCallback(), GetObjectType(), GetSlopeMaxZ(), GetTileMaxZ(), GetTileSlope(), ObjectSpec::grf_prop, GRFFilePropsBase::grffile, ObjectSpec::IsEnabled(), IsSteepSlope(), OBJECT_LIGHTHOUSE, OBJECT_OWNED_LAND, OBJECT_TRANSMITTER, CommandCost::Succeeded(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ TileLoop_Object()

◆ TryBuildLightHouse()

bool TryBuildLightHouse ( )
static

◆ TryBuildTransmitter()

bool TryBuildTransmitter ( )
static

Try to build a transmitter.

Returns
True iff a transmitter was built.

Definition at line 793 of file object_cmd.cpp.

References BuildObject(), Clear, IsBridgeAbove(), IsObjectTypeTile(), IsTileFlat(), IsTileType(), 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 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
cThe 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(), 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 525 of file object_cmd.cpp.

◆ _tile_type_object_procs

const TileTypeProcs _tile_type_object_procs
extern
Initial value:
= {
.draw_tile_proc = DrawTile_Object,
.get_slope_pixel_z_proc = GetSlopePixelZ_Object,
.clear_tile_proc = ClearTile_Object,
.add_accepted_cargo_proc = AddAcceptedCargo_Object,
.get_tile_desc_proc = GetTileDesc_Object,
.click_tile_proc = ClickTile_Object,
.animate_tile_proc = [](TileIndex tile) { AnimateNewObjectTile(tile); },
.tile_loop_proc = TileLoop_Object,
.change_tile_owner_proc = ChangeTileOwner_Object,
.add_produced_cargo_proc = AddProducedCargo_Object,
.get_foundation_proc = GetFoundation_Object,
.terraform_tile_proc = TerraformTile_Object,
.check_build_above_proc = CheckBuildAbove_Object,
}
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
static void DrawTile_Object(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y, bool ground_vehicle)
Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
static bool ClickTile_Object(TileIndex tile)
Tile callback function signature for clicking a tile.
static void AddProducedCargo_Object(TileIndex tile, CargoArray &produced)
Tile callback function signature for obtaining the produced cargo of a tile.
static CommandCost CheckBuildAbove_Object(TileIndex tile, DoCommandFlags flags, Axis axis, int height)
Tile callback function signature to test if a bridge can be built above a tile.
static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_owner)
Tile callback function signature for changing the owner of a tile.
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlags flags)
Tile callback function signature for clearing a tile.
static void GetTileDesc_Object(TileIndex tile, TileDesc &td)
Tile callback function signature for obtaining a tile description.
static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
Tile callback function signature for getting the foundation of a tile.
static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
Tile callback function signature for obtaining cargo acceptance of a tile.
static void TileLoop_Object(TileIndex tile)
Tile callback function signature for running periodic tile updates.
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.
Definition tile_type.h:92

TileTypeProcs definitions for TileType::Object tiles.

Definition at line 62 of file landscape.cpp.