OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
36 #include "table/strings.h"
115 assert(o->
town !=
nullptr);
146 #define GetCompanyHQSize GetAnimationFrame
148 #define IncreaseCompanyHQSize IncreaseAnimationStage
160 if (score >= 170) val++;
161 if (score >= 350) val++;
162 if (score >= 520) val++;
163 if (score >= 720) val++;
179 if (owner != c->
index)
continue;
185 const Livery *l = c->livery;
208 uint8 view =
GB(p2, 0, 2);
220 int size_x =
GB(spec->
size,
HasBit(view, 0) ? 4 : 0, 4);
221 int size_y =
GB(spec->
size,
HasBit(view, 0) ? 0 : 4, 4);
279 if (ret.
Failed())
return ret;
297 if (cost.
Failed())
return cost;
362 static void DrawTile_Object(
TileInfo *ti)
381 dts = &_objects[type];
388 case SPR_FLAT_BARE_LAND: DrawClearLandTile(ti, 0);
break;
389 case SPR_FLAT_1_THIRD_GRASS_TILE: DrawClearLandTile(ti, 1);
break;
390 case SPR_FLAT_2_THIRD_GRASS_TILE: DrawClearLandTile(ti, 2);
break;
391 case SPR_FLAT_GRASS_TILE: DrawClearLandTile(ti, 3);
break;
402 dtss->image.
sprite, palette,
403 ti->
x + dtss->
delta_x, ti->
y + dtss->delta_y,
404 dtss->size_x, dtss->size_y,
405 dtss->size_z, ti->
z + dtss->
delta_z,
417 static int GetSlopePixelZ_Object(
TileIndex tile, uint x, uint y)
444 MakeWaterKeepingClass(tile_cur,
GetTileOwner(tile_cur));
449 std::vector<ClearedObjectArea> _cleared_object_areas;
461 if (coa.area.Intersects(ta))
return &coa;
490 }
else if (_game_mode == GM_EDITOR) {
539 _cleared_object_areas.push_back({tile, ta});
546 static void AddAcceptedCargo_Object(
TileIndex tile,
CargoArray &acceptance, CargoTypes *always_accepted)
558 acceptance[CT_PASSENGERS] += std::max(1U, level);
559 SetBit(*always_accepted, CT_PASSENGERS);
565 acceptance[CT_MAIL] += std::max(1U, level / 2);
566 SetBit(*always_accepted, CT_MAIL);
573 produced[CT_PASSENGERS]++;
590 static void TileLoop_Object(
TileIndex tile)
614 if (
GB(r, 0, 8) < (256 / 4 / (6 - level))) {
615 uint amt =
GB(r, 0, 8) / 8 / 4 + 1;
623 if (
GB(r, 8, 8) < (196 / 4 / (6 - level))) {
624 uint amt =
GB(r, 8, 8) / 8 / 4 + 1;
636 static bool ClickTile_Object(
TileIndex tile)
644 static void AnimateTile_Object(
TileIndex tile)
671 int perimeter = (
GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
673 for (dir =
DIAGDIR_NE; perimeter > 0; dir++) {
689 for (
int j = 0; j < 19; j++) {
720 void GenerateObjects()
726 uint num_water_tiles = 0;
728 for (uint x = 0; x <
MapMaxX(); x++) {
732 for (uint y = 1; y <
MapMaxY() - 1; y++) {
784 bool do_clear =
false;
849 GetSlopePixelZ_Object,
851 AddAcceptedCargo_Object,
853 GetTileTrackStatus_Object,
857 ChangeTileOwner_Object,
858 AddProducedCargo_Object,
860 GetFoundation_Object,
861 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.
uint32 TileIndex
The index/ID of a Tile.
@ CBID_OBJECT_COLOUR
Called to determine the colour of a town building.
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.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
@ 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 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.
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 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.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
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:
TransportType
Available types of transport.
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.
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?
#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.
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
@ 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.
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...
uint16 ObjectType
Types of objects.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
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.
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
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.
@ 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.
Slope
Enumeration for the slope-type.
DiagDirection
Enumeration for diagonal directions.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
@ WATER_CLASS_CANAL
Canal.
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.
StringID str
Description of the tile.
@ DC_AUTO
don't allow building on structures
@ EXPENSES_PROPERTY
Property costs.
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.
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 const TileIndex INVALID_TILE
The very nice invalid tile marker.
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.
CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Build an object object.
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.
const struct GRFFile * grffile
grf file that introduced this entity
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.
@ CMD_LANDSCAPE_CLEAR
demolish a tile
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.
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.