Go to the documentation of this file.
39 #include "table/strings.h"
118 assert(o->
town !=
nullptr);
129 if (remove) RemoveDockingTile(t);
151 #define GetCompanyHQSize GetAnimationFrame
153 #define IncreaseCompanyHQSize IncreaseAnimationStage
165 if (score >= 170) val++;
166 if (score >= 350) val++;
167 if (score >= 520) val++;
168 if (score >= 720) val++;
184 if (owner != c->
index)
continue;
190 const Livery *l = c->livery;
222 int size_x =
GB(spec->
size,
HasBit(view, 0) ? 4 : 0, 4);
223 int size_y =
GB(spec->
size,
HasBit(view, 0) ? 0 : 4, 4);
284 if (ret.
Failed())
return ret;
302 if (cost.
Failed())
return cost;
314 uint build_object_size = 1;
353 build_object_size = size_x * size_y;
400 bool had_success =
false;
411 if (c !=
nullptr && limit-- <= 0)
break;
423 if (ret.
GetCost() > 0 && money < 0)
break;
430 return had_success ? cost : last_error;
435 static void DrawTile_Object(
TileInfo *ti)
454 dts = &_objects[type];
461 case SPR_FLAT_BARE_LAND: DrawClearLandTile(ti, 0);
break;
462 case SPR_FLAT_1_THIRD_GRASS_TILE: DrawClearLandTile(ti, 1);
break;
463 case SPR_FLAT_2_THIRD_GRASS_TILE: DrawClearLandTile(ti, 2);
break;
464 case SPR_FLAT_GRASS_TILE: DrawClearLandTile(ti, 3);
break;
475 dtss->image.
sprite, palette,
476 ti->
x + dtss->
delta_x, ti->
y + dtss->delta_y,
477 dtss->size_x, dtss->size_y,
478 dtss->size_z, ti->
z + dtss->
delta_z,
490 static int GetSlopePixelZ_Object(
TileIndex tile, uint x, uint y)
517 MakeWaterKeepingClass(tile_cur,
GetTileOwner(tile_cur));
522 std::vector<ClearedObjectArea> _cleared_object_areas;
534 if (coa.area.Intersects(ta))
return &coa;
563 }
else if (_game_mode == GM_EDITOR) {
612 _cleared_object_areas.push_back({tile, ta});
619 static void AddAcceptedCargo_Object(
TileIndex tile,
CargoArray &acceptance, CargoTypes *always_accepted)
631 acceptance[CT_PASSENGERS] += std::max(1U, level);
632 SetBit(*always_accepted, CT_PASSENGERS);
638 acceptance[CT_MAIL] += std::max(1U, level / 2);
639 SetBit(*always_accepted, CT_MAIL);
646 produced[CT_PASSENGERS]++;
663 static void TileLoop_Object(
TileIndex tile)
687 if (
GB(r, 0, 8) < (256 / 4 / (6 - level))) {
688 uint amt =
GB(r, 0, 8) / 8 / 4 + 1;
696 if (
GB(r, 8, 8) < (196 / 4 / (6 - level))) {
697 uint amt =
GB(r, 8, 8) / 8 / 4 + 1;
709 static bool ClickTile_Object(
TileIndex tile)
717 static void AnimateTile_Object(
TileIndex tile)
744 int perimeter = (
GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
746 for (dir =
DIAGDIR_NE; perimeter > 0; dir++) {
762 for (
int j = 0; j < 19; j++) {
793 void GenerateObjects()
799 uint num_water_tiles = 0;
801 for (uint x = 0; x <
MapMaxX(); x++) {
805 for (uint y = 1; y <
MapMaxY() - 1; y++) {
857 bool do_clear =
false;
922 GetSlopePixelZ_Object,
924 AddAcceptedCargo_Object,
926 GetTileTrackStatus_Object,
930 ChangeTileOwner_Object,
931 AddProducedCargo_Object,
933 GetFoundation_Object,
934 TerraformTile_Object,
@ OBJECT_FLAG_BUILT_ON_WATER
Object can be built on water (not required).
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
const char * grf
newGRF used for the tile contents
@ OBJECT_FLAG_ANIMATION
Object has animated tiles.
byte colour
Colour of the object, for display purpose.
@ CBID_OBJECT_COLOUR
Called to determine the colour of a town building.
Iterator to iterate over a diagonal area of the map.
Cheat magic_bulldozer
dynamite industries, objects
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Structure contains cached list of stations nearby.
@ OBJECT_FLAG_ONLY_IN_SCENEDIT
Object can only be constructed in the scenario editor.
@ OAT_256_TICKS
Triggered every 256 ticks (for all tiles at the same time).
static Titem * Get(size_t index)
Returns Titem with given index.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
@ CBID_OBJECT_LAND_SLOPE_CHECK
Callback done for each tile of an object to check the slope.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
@ OBJECT_FLAG_2CC_COLOUR
Object wants 2CC colour mapping.
Allow incrementing of ObjectClassID variables.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
uint x
X position of the tile in unit coordinates.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Tile information, used while rendering the tile.
CompanyMask statues
which companies have a statue?
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
void MultiplyCost(int factor)
Multiplies the cost of the command by the given factor.
Owner owner[4]
Name of the owner(s)
@ OBJECT_FLAG_CLEAR_INCOME
When object is cleared a positive income is generated instead of a cost.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
TileArea location
Location of the object.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, uint8 view)
Build an object object.
Tindex index
Index of this pool item.
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
bool IsAvailable() const
Check whether the object is available at this time.
#define GetCompanyHQSize
We encode the company HQ size in the animation stage.
Class for storing amounts of cargo.
SpriteID sprite
The 'real' sprite.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool TryBuildLightHouse()
Try to build a lighthouse.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
static const ObjectType OBJECT_STATUE
Statue in towns.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
uint y
Y position of the tile in unit coordinates.
@ DC_NO_WATER
don't allow building on water
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
@ WC_COMPANY
Company view; Window numbers:
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Owner
Enum for all companies/owners.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
@ DC_EXEC
execute the given command
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
Tile description for the 'land area information' tool.
uint16 callback_mask
Bitmask of requested/allowed callbacks.
DoCommandFlag
List of flags for a command.
Foundation
Enumeration for Foundations.
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
static void IncreaseAnimationStage(TileIndex tile)
Increase the animation stage of a whole structure.
Money GetClearCost() const
Get the cost for clearing a structure of this type.
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
bool Succeeded() const
Did this command succeed?
uint32 build_object_limit
Amount of tiles we can (still) build objects on (times 65536). Also applies to buying land.
#define IncreaseCompanyHQSize
We encode the company HQ size in the animation stage.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Slope tileh
Slope of the tile.
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
static void ReallyClearObjectTile(Object *o)
Perform the actual removal of the object from the map.
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Date build_date
Date of construction of tile contents.
PalSpriteID ground
Palette and sprite for the ground.
Slope
Enumeration for the slope-type.
Iterator to iterate over a tile area (rectangle) of the map.
@ OBJECT_FLAG_CANNOT_REMOVE
Object can not be removed.
int8 delta_x
0x80 is sequence terminator
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
static uint MapSize()
Get the size of the map.
@ EXPENSES_CONSTRUCTION
Construction costs.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Common return value for all commands.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Date _date
Current date in days (day counter)
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
int8 delta_z
0x80 identifies child sprites
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
Base class for tile iterators.
uint16 ObjectType
Types of objects.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
TransportType
Available types of transport.
Cheats _cheats
All the cheats.
byte view
The view setting for this object.
@ INVALID_OWNER
An invalid owner.
uint16 w
The width of the area.
bool Failed() const
Did this command fail?
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8 view)
Actually build the object.
@ WATER_CLASS_CANAL
Canal.
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
An object, such as transmitter, on the map.
Represents the covered area of e.g.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
#define foreach_draw_tile_seq(idx, list)
Iterate through all DrawTileSeqStructs in DrawTileSprites.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ CBM_OBJ_COLOUR
decide the colour of the building
ObjectType type
Type of the object.
@ MAX_COMPANIES
Maximum number of companies.
@ GWP_OBJECT
Generate objects (radio tower, light houses)
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
bool freeform_edges
allow terraforming the tiles at the map edges
Money GetCost() const
The costs as made up to this moment.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
int UpdateCompanyRatingAndValue(Company *c, bool update)
if update is set to true, the economy is updated with this score (also the house is updated,...
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
@ ST_HEADQUARTERS
Source/destination are company headquarters.
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
#define RandomTile()
Get a valid random tile.
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
Ground palette sprite of a tile, together with its sprite layout.
@ DC_NO_TEST_TOWN_RATING
town rating does not disallow you from building
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Money GetAvailableMoneyForCommand()
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
DiagDirection
Enumeration for diagonal directions.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
bool enabled
Is this spec enabled?
Set of callback functions for performing tile operations of a given tile type.
bool value
tells if the bool cheat is active or not
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
@ CBID_OBJECT_AUTOSLOPE
Called to determine if one can alter the ground below an object tile.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
@ OBJECT_FLAG_NOT_ON_LAND
Object can not be on land, implicitly sets OBJECT_FLAG_BUILT_ON_WATER.
uint16 h
The height of the area.
StringID name
The name for this object.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
static const ObjectType OBJECT_OWNED_LAND
Owned land 'flag'.
bool _generating_world
Whether we are generating the map or not.
@ OBJECT_FLAG_AUTOREMOVE
Object get automatically removed (like "owned land").
uint8 generate_amount
Number of objects which are attempted to be generated per 256^2 map during world generation.
static bool EconomyIsInRecession()
Is the economy in recession?
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
CompanyID _current_company
Company currently doing an action.
@ OAT_BUILT
Triggered when the object is built (for all tiles at the same time).
@ CBM_OBJ_SLOPE_CHECK
decides slope suitability
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static bool IsObjectTypeTile(TileIndex t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Base class for all pools.
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
static uint ScaleByMapSize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
@ OAT_TILELOOP
Triggered in the periodic tile loop.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static size_t GetNumItems()
Returns number of valid items in the pool.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
uint8 views
The number of views.
static bool TryBuildTransmitter()
Try to build a transmitter.
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
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.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
TileIndex tile
The base tile of the area.
uint32 PaletteID
The number of the palette.
@ CBM_OBJ_AUTOSLOPE
decides allowance of autosloping
@ OBJECT_FLAG_ALLOW_UNDER_BRIDGE
Object can built under a bridge.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
@ OWNER_NONE
The tile has no ownership.
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
Make an Object tile.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
StringID str
Description of the tile.
@ DC_AUTO
don't allow building on structures
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
static uint ScaleByMapSize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
@ DC_NO_MODIFY_TOWN_RATING
do not change town rating
void InitializeObjects()
Initialize/reset the objects.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
static void ResetTypeCounts()
Resets object counts.
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
void UpdateCompanyHQ(TileIndex tile, uint score)
Update the CompanyHQ to the state associated with the given score.
@ OBJECT_FLAG_HAS_NO_FOUNDATION
Do not display foundations when on a slope.
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
@ OBJECT_FLAG_SCALE_BY_WATER
Object count is roughly scaled by water amount at edges.
static bool HasTransmitter(TileIndex tile, void *user)
Helper function for CircularTileSearch.
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
TileIndex tile
Tile index.
ConstructionSettings construction
construction of things in-game
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Money GetBuildCost() const
Get the cost for building a structure of this type.
const struct GRFFile * grffile
grf file that introduced this entity
static const uint8 OBJECT_SIZE_1X1
The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X,...
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Keeps track of removed objects during execution/testruns of commands.
static uint16 counts[NUM_OBJECTS]
Number of objects per type ingame.
@ OWNER_WATER
The tile/execution is done by "water".
Date build_date
Date of construction.
Information about a particular livery.
Town * town
Town the object is built in.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
static bool IsObjectType(TileIndex t, ObjectType type)
Check whether the object on a tile is of a specific type.
void UpdateObjectColours(const Company *c)
Updates the colour of the object whenever a company changes.
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
CommandCost CmdBuildObjectArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, ObjectType type, uint8 view, bool diagonal)
Construct multiple objects in an area.
const char * GetName() const
Get the name of this grf.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
@ OBJECT_FLAG_ONLY_IN_GAME
Object can only be built in game.
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
byte colour2
Second colour, for vehicles with 2CC support.
ObjectFlags flags
Flags/settings related to the object.
byte colour1
First colour, for all vehicles.