|
OpenTTD Source 20260311-master-g511d3794ce
|
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. | |
| 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) |
| 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. | |
Handling of object tiles.
Definition in file object_cmd.cpp.
|
static |
Tile callback function signature for obtaining cargo acceptance of a tile.
| tile | Tile queried for its accepted cargo |
| acceptance | Storage destination of the cargo acceptance in 1/8 |
| always_accepted | Bitmask of always accepted cargo types |
Definition at line 624 of file object_cmd.cpp.
References CT_PASSENGERS, GetCompanyHQSize(), IsObjectType(), IsValidCargoType(), OBJECT_HQ, and SetBit().
|
static |
Tile callback function signature for obtaining the produced cargo of a tile.
| tile | Tile being queried |
| produced | Destination array for produced cargo |
Definition at line 654 of file object_cmd.cpp.
References CT_PASSENGERS, IsObjectType(), IsValidCargoType(), and OBJECT_HQ.
| void BuildObject | ( | ObjectType | type, |
| TileIndex | tile, | ||
| CompanyID | owner, | ||
| Town * | town, | ||
| uint8_t | view ) |
Actually build the object.
| 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. |
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(), ObjectSpec::Get(), GetObjectCallback(), GetWaterClass(), ObjectSpec::grf_prop, GRFFilePropsBase::grfid, HasBit(), HasTileWaterGround(), Object::IncTypeCount(), Invalid, InvalidateWaterRegion(), IsDockingTile(), IsTileOwner(), IsWaterTile(), MakeObject(), MarkTileDirtyByTile(), OWNER_NONE, OWNER_WATER, ObjectSpec::size, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Object::town, TriggerObjectAnimation(), and Uses2CC.
Referenced by CmdBuildObject(), TownActionBuildStatue(), TryBuildLightHouse(), and TryBuildTransmitter().
|
static |
Tile callback function signature for changing the owner of a tile.
| tile | The tile to process. |
| old_owner | The owner to replace. |
| new_owner | The owner to replace with. |
Definition at line 867 of file object_cmd.cpp.
References Canal, ChangeTileOwner(), Object::GetByTile(), GetObjectType(), GetWaterClass(), INVALID_OWNER, IsTileOwner(), NEW_OBJECT_OFFSET, OBJECT_OWNED_LAND, OBJECT_STATUE, ReallyClearObjectTile(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetTileOwner(), SetWindowDirty(), Town::statues, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Object::town, and WC_TOWN_AUTHORITY.
|
extern |
Checks if the given tile is buildable, flat and has a certain height.
| 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. |
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().
|
static |
Tile callback function signature to test if a bridge can be built above a tile.
| tile | The involved tile. |
| flags | Command flags passed to the build command. |
| axis | Axis of bridge being built. |
| height | Absolute height of bridge platform. |
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().
|
static |
Tile callback function signature for clearing a tile.
| tile | The tile to clear. |
| flags | The command flags. |
Definition at line 544 of file object_cmd.cpp.
References _cheats, _current_company, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Auto, Autoremove, CalculateCompanyValue(), CannotRemove, CheckTileOwnership(), ClearIncome, CMD_ERROR, Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), ObjectSpec::flags, ObjectSpec::Get(), Object::GetByTile(), ObjectSpec::GetClearCost(), GetTileOwner(), OrthogonalTileArea::h, Headquarters, INVALID_TILE, CargoPacket::InvalidateAllFrom(), IsTileOnWater(), Object::location, CompanyProperties::location_of_HQ, CommandCost::MultiplyCost(), NoWater, OBJECT_HQ, OBJECT_STATUE, OWNER_NONE, OWNER_TOWN, OWNER_WATER, ReallyClearObjectTile(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), SetWindowDirty(), Town::statues, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Object::town, Object::type, OrthogonalTileArea::w, WC_COMPANY, and WC_TOWN_AUTHORITY.
Referenced by CmdBuildObject().
|
static |
Tile callback function signature for clicking a tile.
| tile | The tile that was clicked. |
Definition at line 735 of file object_cmd.cpp.
References GetTileOwner(), IsObjectType(), OBJECT_HQ, and ShowCompany().
| CommandCost CmdBuildObject | ( | DoCommandFlags | flags, |
| TileIndex | tile, | ||
| ObjectType | type, | ||
| uint8_t | view ) |
Build an object object.
| flags | type of operation |
| tile | tile where the object will be located |
| type | the object type to build |
| view | the view for the object |
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.
| CommandCost CmdBuildObjectArea | ( | DoCommandFlags | flags, |
| TileIndex | tile, | ||
| TileIndex | start_tile, | ||
| ObjectType | type, | ||
| uint8_t | view, | ||
| bool | diagonal ) |
Construct multiple objects in an area.
| 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 Diagonal or Orthogonal tile iterator. |
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.
|
static |
Tile callback function signature for drawing a tile and its contents to the screen.
| ti | Information about the tile to draw |
Definition at line 450 of file object_cmd.cpp.
References AddSortableSpriteToDraw(), DrawBridgeMiddle(), DrawFoundation(), DrawGroundSprite(), DrawNewObjectTile(), ObjectSpec::flags, ObjectSpec::Get(), Object::GetByTile(), GetCompanyHQSize(), GetCompanyPalette(), GetFoundation_Object(), GetObjectType(), DrawTileSprites::GetSequence(), GetTileOwner(), DrawTileSprites::ground, HasNoFoundation, ObjectSpec::IsEnabled(), IsInvisibilitySet(), IsTransparencySet(), Object::location, NEW_OBJECT_OFFSET, OBJECT_HQ, OBJECT_TRANSMITTER, OWNER_NONE, PalSpriteID::sprite, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, TileInfo::tile, TileInfo::tileh, TileX(), TileY(), and TO_STRUCTURES.
| ClearedObjectArea * FindClearedObject | ( | TileIndex | tile | ) |
Find the entry in _cleared_object_areas which occupies a certain tile.
| tile | Tile of interest |
Definition at line 532 of file object_cmd.cpp.
Referenced by CmdBuildTunnel(), CmdLandscapeClear(), and CmdTerraformLand().
| void GenerateObjects | ( | ) |
Definition at line 807 of file object_cmd.cpp.
|
static |
Get the size of the HQ.
| tile | The (northern) tile of the company HQ. |
Definition at line 154 of file object_cmd.cpp.
References GetAnimationFrame().
Referenced by AddAcceptedCargo_Object(), DrawTile_Object(), TileLoop_Object(), and UpdateCompanyHQ().
|
static |
Tile callback function signature for getting the foundation of a tile.
| tile | The tile to check. |
| tileh | The current slope. |
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().
| ObjectType GetObjectType | ( | Tile | t | ) |
Gets the ObjectType of the given object tile.
| t | the tile to get the type from. |
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().
|
static |
Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
| tile | The queries tile for the Z coordinate. |
| x | World X coordinate in tile "units". |
| y | World Y coordinate in tile "units". |
| ground_vehicle | Whether to get the Z coordinate of the ground vehicle, or the ground. |
Definition at line 499 of file object_cmd.cpp.
References GetPartialPixelZ(), GetTileMaxPixelZ(), GetTilePixelSlope(), IsObjectType(), and OBJECT_OWNED_LAND.
Tile callback function signature for obtaining a tile description.
| tile | Tile being queried |
| td | Storage pointer for returned tile description |
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.
|
static |
Increase the HQ size.
| 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().
| void InitializeObjects | ( | ) |
Initialize/reset the objects.
Definition at line 73 of file object_cmd.cpp.
References Object::ResetTypeCounts().
|
static |
Perform the actual removal of the object from the map.
| o | The 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().
|
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).
| tile | The involved tile. |
| flags | Command flags passed to the terraform command (DoCommandFlag::Execute, DoCommandFlag::QueryCost, etc.). |
| z_new | TileZ after terraforming. |
| tileh_new | Slope after terraforming. |
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().
|
static |
Tile callback function signature for running periodic tile updates.
| tile | The tile to update. |
Definition at line 679 of file object_cmd.cpp.
References Animation, CT_PASSENGERS, EconomyIsInRecession(), ObjectSpec::flags, GB(), Object::GetByTile(), ObjectSpec::GetByTile(), GetCompanyHQSize(), StationFinder::GetStations(), GetTileOwner(), Headquarters, IsObjectType(), IsTileOnWater(), IsValidCargoType(), Object::location, OBJECT_HQ, ScaleByCargoScale(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, TileLoop, TileLoop_Water(), TileLoopNorth, TriggerObjectAnimation(), and TriggerObjectTileAnimation().
|
static |
Try to build a lighthouse.
Definition at line 748 of file object_cmd.cpp.
References AXIS_X, BuildObject(), Clear, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirToAxis(), GB(), GetWaterClass(), IsBridgeAbove(), IsObjectTypeTile(), IsTileFlat(), IsTileType(), IsValidTile(), Map::MaxX(), Map::MaxY(), OBJECT_LIGHTHOUSE, Sea, Map::Size(), TileOffsByDiagDir(), TileXY(), and Water.
|
static |
Try to build a transmitter.
Definition at line 793 of file object_cmd.cpp.
References BuildObject(), Clear, IsBridgeAbove(), IsObjectTypeTile(), IsTileFlat(), IsTileType(), OBJECT_TRANSMITTER, and RandomTile.
| void UpdateCompanyHQ | ( | TileIndex | tile, |
| uint | score ) |
Update the CompanyHQ to the state associated with the given score.
| 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().
| void UpdateObjectColours | ( | const Company * | c | ) |
Updates the colour of the object whenever a company changes.
| 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(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Uses2CC.
Referenced by CmdSetCompanyColour().
| std::vector<ClearedObjectArea> _cleared_object_areas |
Definition at line 525 of file object_cmd.cpp.
|
extern |
TileTypeProcs definitions for TileType::Object tiles.
Definition at line 62 of file landscape.cpp.