Defines | Functions | Variables

object_cmd.cpp File Reference

Handling of object tiles. More...

#include "stdafx.h"
#include "landscape.h"
#include "command_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 "sprite.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 "date_func.h"
#include "newgrf_debug.h"
#include "table/strings.h"
#include "table/object_land.h"

Go to the source code of this file.

Defines

#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

void InitializeObjects ()
 Initialize/reset the objects.
void BuildObject (ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8 view)
 Actually build the object.
static void IncreaseAnimationStage (TileIndex tile)
 Increase the animation stage of a whole structure.
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, uint invalid_dirs, int &allowed_z, bool check_bridge)
 Checks if the given tile is buildable, flat and has a certain height.
static CommandCost ClearTile_Object (TileIndex tile, DoCommandFlag flags)
CommandCost CmdBuildObject (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build an object object.
static Foundation GetFoundation_Object (TileIndex tile, Slope tileh)
static void DrawTile_Object (TileInfo *ti)
static uint GetSlopeZ_Object (TileIndex tile, uint x, uint y)
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, uint32 *always_accepted)
static void GetTileDesc_Object (TileIndex tile, TileDesc *td)
static void TileLoop_Object (TileIndex tile)
static TrackStatus GetTileTrackStatus_Object (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
static bool ClickTile_Object (TileIndex tile)
static void AnimateTile_Object (TileIndex tile)
static bool HasTransmitter (TileIndex tile, void *user)
 Helper function for CircularTileSearch.
void GenerateObjects ()
static void ChangeTileOwner_Object (TileIndex tile, Owner old_owner, Owner new_owner)
static CommandCost TerraformTile_Object (TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)

Variables

ObjectPool _object_pool ("Object")
SmallVector< ClearedObjectArea, 4 > _cleared_object_areas
const TileTypeProcs _tile_type_object_procs

Detailed Description

Handling of object tiles.

Definition in file object_cmd.cpp.


Define Documentation

#define GetCompanyHQSize   GetAnimationFrame

We encode the company HQ size in the animation stage.

Definition at line 125 of file object_cmd.cpp.

Referenced by UpdateCompanyHQ().

#define IncreaseCompanyHQSize   IncreaseAnimationStage

We encode the company HQ size in the animation stage.

Definition at line 127 of file object_cmd.cpp.

Referenced by UpdateCompanyHQ().


Function Documentation

void BuildObject ( ObjectType  type,
TileIndex  tile,
CompanyID  owner,
Town town,
uint8  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 71 of file object_cmd.cpp.

References _date, Object::build_date, CalcClosestTownFromTile(), CALLBACK_FAILED, ObjectSpec::callback_mask, CBID_OBJECT_COLOUR, CBM_OBJ_COLOUR, Object::colour, Livery::colour1, Livery::colour2, ObjectSpec::flags, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), ObjectSpec::Get(), GetObjectCallback(), GetWaterClass(), HasBit(), Object::IncTypeCount(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsWaterTile(), Object::location, MakeObject(), MarkTileDirtyByTile(), OAT_BUILT, OBJECT_FLAG_2CC_COLOUR, OBJECT_FLAG_ANIMATION, OWNER_NONE, ObjectSpec::size, TILE_AREA_LOOP, Object::town, TriggerObjectAnimation(), and Object::view.

Referenced by CmdBuildObject(), and TownActionBuildStatue().

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

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.
check_bridge Check for the existance of a bridge.
Returns:
The cost in case of success, or an error code if it failed.

Definition at line 679 of file station_cmd.cpp.

References _settings_game, CommandCost::AddCost(), ConstructionSettings::build_on_slopes, GameSettings::construction, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetTileSlope(), HasBit(), IsBridgeAbove(), IsSteepSlope(), MayHaveBridgeAbove(), return_cmd_error, SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, SLOPE_SW, and TILE_HEIGHT.

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

CommandCost CmdBuildObject ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build an object object.

Parameters:
tile tile where the object will be located
flags type of operation
p1 the object type to build
p2 the view for the object
text unused
Returns:
the cost of this operation or an error

Definition at line 183 of file object_cmd.cpp.

References _current_company, CommandCost::AddCost(), BuildObject(), CALLBACK_FAILED, ObjectSpec::callback_mask, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::CanAllocateItem(), CBID_OBJECT_LAND_SLOPE_CHECK, CBM_OBJ_SLOPE_CHECK, CheckBuildableTile(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, DC_EXEC, DC_NO_WATER, DoCommand(), EXPENSES_PROPERTY, CommandCost::Failed(), ObjectSpec::flags, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), ObjectSpec::Get(), GetBridgeHeight(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), GetObjectCallback(), GetSouthernBridgeEnd(), GetTileMaxZ(), GetTileSlope(), HasBit(), HasTileWaterGround(), ObjectSpec::height, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_TILE, ObjectSpec::IsAvailable(), IsBridgeAbove(), IsOwnedLand(), IsTileOwner(), IsTileType(), IsWaterTile(), CompanyProperties::location_of_HQ, MAX_COMPANIES, MayHaveBridgeAbove(), MP_OBJECT, OBJECT_FLAG_ALLOW_UNDER_BRIDGE, OBJECT_FLAG_BUILT_ON_WATER, OBJECT_FLAG_ONLY_IN_GAME, OBJECT_FLAG_ONLY_IN_SCENEDIT, OBJECT_HQ, OBJECT_LIGHTHOUSE, OBJECT_OWNED_LAND, OBJECT_STATUE, OBJECT_TRANSMITTER, OWNER_NONE, return_cmd_error, SetWindowDirty(), ObjectSpec::size, SLOPE_FLAT, TILE_AREA_LOOP, TILE_HEIGHT, TileX(), TileY(), UpdateCompanyHQ(), UpdateCompanyRatingAndValue(), and ObjectSpec::views.

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 NULL if none

Definition at line 402 of file object_cmd.cpp.

References SmallVector< T, S >::Begin(), and SmallVector< T, S >::End().

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

static bool HasTransmitter ( TileIndex  tile,
void *  user 
) [static]

Helper function for CircularTileSearch.

Parameters:
tile The tile to check.
user Ignored.
Returns:
True iff the tile has a radio tower.

Definition at line 590 of file object_cmd.cpp.

References IsTransmitterTile().

static void IncreaseAnimationStage ( TileIndex  tile  )  [static]

Increase the animation stage of a whole structure.

Parameters:
tile The tile of the structure.

Definition at line 115 of file object_cmd.cpp.

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

void InitializeObjects (  ) 

Initialize/reset the objects.

Definition at line 56 of file object_cmd.cpp.

References Object::ResetTypeCounts().

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

References Object::DecTypeCount(), DeleteNewGRFInspectWindow(), GetObjectType(), GetTileOwner(), Object::location, TileArea::tile, and TILE_AREA_LOOP.

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

References GetCompanyHQSize, IncreaseCompanyHQSize, and INVALID_TILE.

Referenced by CmdBuildObject(), and UpdateCompanyRatingAndValue().

void UpdateObjectColours ( const Company c  ) 

Variable Documentation

const TileTypeProcs _tile_type_object_procs
Initial value:
 {
  DrawTile_Object,             
  GetSlopeZ_Object,            
  ClearTile_Object,            
  AddAcceptedCargo_Object,     
  GetTileDesc_Object,          
  GetTileTrackStatus_Object,   
  ClickTile_Object,            
  AnimateTile_Object,          
  TileLoop_Object,             
  ChangeTileOwner_Object,      
  NULL,                        
  NULL,                        
  GetFoundation_Object,        
  TerraformTile_Object,        
}