38 #include "table/strings.h" 117 assert(o->
town != NULL);
148 #define GetCompanyHQSize GetAnimationFrame 150 #define IncreaseCompanyHQSize IncreaseAnimationStage 162 (val = 0, score < 170) ||
163 (val++, score < 350) ||
164 (val++, score < 520) ||
165 (val++, score < 720) ||
180 FOR_ALL_OBJECTS(obj) {
183 if (owner != c->
index)
continue;
189 const Livery *l = c->livery;
212 uint8
view =
GB(p2, 0, 2);
224 int size_x =
GB(spec->
size,
HasBit(view, 0) ? 4 : 0, 4);
225 int size_y =
GB(spec->
size,
HasBit(view, 0) ? 0 : 4, 4);
276 if (ret.
Failed())
return ret;
294 if (cost.
Failed())
return cost;
359 static void DrawTile_Object(
TileInfo *ti)
378 dts = &_objects[
type];
385 case SPR_FLAT_BARE_LAND: DrawClearLandTile(ti, 0);
break;
386 case SPR_FLAT_1_THIRD_GRASS_TILE: DrawClearLandTile(ti, 1);
break;
387 case SPR_FLAT_2_THIRD_GRASS_TILE: DrawClearLandTile(ti, 2);
break;
388 case SPR_FLAT_GRASS_TILE: DrawClearLandTile(ti, 3);
break;
399 dtss->image.
sprite, palette,
400 ti->
x + dtss->
delta_x, ti->
y + dtss->delta_y,
401 dtss->size_x, dtss->size_y,
402 dtss->size_z, ti->
z + dtss->
delta_z,
414 static int GetSlopePixelZ_Object(
TileIndex tile, uint x, uint y)
441 MakeWaterKeepingClass(tile_cur,
GetTileOwner(tile_cur));
459 if (coa->area.Intersects(ta))
return coa;
488 }
else if (_game_mode == GM_EDITOR) {
536 cleared_area->
area = ta;
543 static void AddAcceptedCargo_Object(
TileIndex tile,
CargoArray &acceptance, uint32 *always_accepted)
555 acceptance[CT_PASSENGERS] +=
max(1U, level);
556 SetBit(*always_accepted, CT_PASSENGERS);
562 acceptance[CT_MAIL] +=
max(1U, level / 2);
563 SetBit(*always_accepted, CT_MAIL);
579 static void TileLoop_Object(
TileIndex tile)
603 if (
GB(r, 0, 8) < (256 / 4 / (6 - level))) {
604 uint amt =
GB(r, 0, 8) / 8 / 4 + 1;
612 if (
GB(r, 8, 8) < (196 / 4 / (6 - level))) {
613 uint amt =
GB(r, 8, 8) / 8 / 4 + 1;
625 static bool ClickTile_Object(
TileIndex tile)
633 static void AnimateTile_Object(
TileIndex tile)
660 int perimeter = (
GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
662 for (dir =
DIAGDIR_NE; perimeter > 0; dir++) {
678 for (
int j = 0; j < 19; j++) {
709 void GenerateObjects()
715 uint num_water_tiles = 0;
717 for (uint x = 0; x <
MapMaxX(); x++) {
721 for (uint y = 1; y <
MapMaxY() - 1; y++) {
773 bool do_clear =
false;
837 GetSlopePixelZ_Object,
839 AddAcceptedCargo_Object,
841 GetTileTrackStatus_Object,
845 ChangeTileOwner_Object,
848 GetFoundation_Object,
849 TerraformTile_Object,
don't allow building on structures
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Functions/types related to NewGRF debugging.
do not change town rating
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
uint32 PaletteID
The number of the palette.
#define RandomTile()
Get a valid random tile.
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
Object wants 2CC colour mapping.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
ObjectFlags flags
Flags/settings related to the object.
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Tile information, used while rendering the tile.
CompanyMask statues
which companies have a statue?
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
bool IsAvailable() const
Check whether the object is available at this time.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Generate objects (radio tower, light houses)
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
static Titem * Get(size_t index)
Returns Titem with given index.
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
const char * grf
newGRF used for the tile contents
Town * town
Town the object is built in.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Slope tileh
Slope of the tile.
static const ObjectType OBJECT_STATUE
Statue in towns.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
static uint ScaleByMapSize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map...
Functions related to vehicles.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Date build_date
Date of construction.
static uint TileX(TileIndex tile)
Get the X component of a tile.
byte colour
Colour of the object, for display purpose.
Object can not be removed.
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height) ...
const T * Begin() const
Get the pointer to the first item (const)
Object()
Make sure the object isn't zeroed.
Tile description for the 'land area information' tool.
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Tindex index
Index of this pool item.
Northeast, upper right on your monitor.
#define GetCompanyHQSize
We encode the company HQ size in the animation stage.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Allow incrementing of ObjectClassID variables.
Object get automatically removed (like "owned land").
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static bool TryBuildLightHouse()
Try to build a lighthouse.
Simple vector template class.
#define IncreaseCompanyHQSize
We encode the company HQ size in the animation stage.
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
Functions related to world/map generation.
Contains objects such as transmitters and owned land.
static void ReallyClearObjectTile(Object *o)
Perform the actual removal of the object from the map.
Common return value for all commands.
static void IncreaseAnimationStage(TileIndex tile)
Increase the animation stage of a whole structure.
Callback done for each tile of an object to check the slope.
static T max(const T a, const T b)
Returns the maximum of two values.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
void MultiplyCost(int factor)
Multiplies the cost of the command by the given factor.
uint16 w
The width of the area.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
const T * End() const
Get the pointer behind the last valid item (const)
CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Owner owner[4]
Name of the owner(s)
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
static bool IsObjectType(TileIndex t, ObjectType type)
Check whether the object on a tile is of a specific type.
T * Append(uint to_add=1)
Append an item and return it.
Functions related to (drawing on) viewports.
Pseudo random number generator.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
Functions related to NewGRF objects.
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.
Base class for cargo packets.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
Sprites to use and how to display them for object tiles.
uint x
X position of the tile in unit coordinates.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
bool enabled
Is this spec enabled?
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Foundation
Enumeration for Foundations.
Types related to cheating.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
TileIndex tile
Tile index.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Object can only be built in game.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static uint16 counts[NUM_OBJECTS]
Number of objects per type ingame.
Ground palette sprite of a tile, together with its sprite layout.
Money GetClearCost() const
Get the cost for clearing a structure of this type.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
DoCommandFlag
List of flags for a command.
Object can only be constructed in the scenario editor.
#define foreach_draw_tile_seq(idx, list)
Iterate through all DrawTileSeqStructs in DrawTileSprites.
bool Succeeded() const
Did this command succeed?
Keeps track of removed objects during execution/testruns of commands.
Triggered when the object is built (for all tiles at the same time).
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
Map accessors for object tiles.
A number of safeguards to prevent using unsafe methods.
bool value
tells if the bool cheat is active or not
Source/destination are company headquarters.
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.
uint16 callback_mask
Bitmask of requested/allowed callbacks.
TileArea area
The area of the object.
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
uint y
Y position of the tile in unit coordinates.
An object, such as transmitter, on the map.
uint8 views
The number of views.
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Information about a particular livery.
Represents the covered area of e.g.
GUI Functions related to companies.
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8 view)
Actually build the object.
When object is cleared a positive income is generated instead of a cost.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
don't allow building on water
Map accessor functions for bridges.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
static const ObjectType OBJECT_OWNED_LAND
Owned land 'flag'.
The tile has no ownership.
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build an object object.
Object can not be on land, implicitly sets OBJECT_FLAG_BUILT_ON_WATER.
DiagDirection
Enumeration for diagonal directions.
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
static bool EconomyIsInRecession()
Is the economy in recession?
decide the colour of the building
uint16 ObjectType
Types of objects.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Functions related to autoslope.
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
decides slope suitability
bool Failed() const
Did this command fail?
byte colour2
Second colour, for vehicles with 2CC support.
Object has animated tiles.
Maximum number of companies.
Functions to find and configure NewGRFs.
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.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Triggered every 256 ticks (for all tiles at the same time).
Base class for all pools.
StringID name
The name for this object.
Functions related to clear (MP_CLEAR) land.
TileIndex tile
The base tile of the area.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
static uint ScaleByMapSize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map...
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
static bool TryBuildTransmitter()
Try to build a transmitter.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
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.
execute the given command
PalSpriteID ground
Palette and sprite for the ground.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
static uint MapSize()
Get the size of the map.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Class for storing amounts of cargo.
bool _generating_world
Whether we are generating the map or not.
Object count is roughly scaled by water amount at edges.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Town authority; Window numbers:
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
CompanyByte _current_company
Company currently doing an action.
Set of callback functions for performing tile operations of a given tile type.
uint32 TileIndex
The index/ID of a Tile.
Functions related to objects.
static void ResetTypeCounts()
Resets object counts.
static size_t GetNumItems()
Returns number of valid items in the pool.
A town owns the tile, or a town is expanding.
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
int UpdateCompanyRatingAndValue(Company *c, bool update)
if update is set to true, the economy is updated with this score (also the house is updated...
void UpdateCompanyHQ(TileIndex tile, uint score)
Update the CompanyHQ to the state associated with the given score.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Cheat magic_bulldozer
dynamite industries, objects
int8 delta_z
0x80 identifies child sprites
The tile has no foundation, the slope remains unchanged.
TileArea location
Location of the object.
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
ObjectType type
Type of the object.
Slope
Enumeration for the slope-type.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
uint8 generate_amount
Number of objects which are attempted to be generated per 256^2 map during world generation.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
Functions related to OTTD's landscape.
other objects such as transmitters and lighthouses
void InitializeObjects()
Initialize/reset the objects.
Functions related to commands.
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.
Date build_date
Date of construction of tile contents.
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
ConstructionSettings construction
construction of things in-game
const char * GetName() const
Get the name of this grf.
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
const struct GRFFile * grffile
grf file that introduced this entity
StringID str
Description of the tile.
Object can be built on water (not required).
decides allowance of autosloping
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Object can built under a bridge.
byte colour1
First colour, for all vehicles.
Called to determine the colour of a town building.
static bool HasTransmitter(TileIndex tile, void *user)
Helper function for CircularTileSearch.
Triggered in the periodic tile loop.
A tile without any structures, i.e. grass, rocks, farm fields etc.
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
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...
int8 delta_x
0x80 is sequence terminator
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
Called to determine if one can alter the ground below an object tile.
byte view
The view setting for this object.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Functions related to water (management)
void UpdateObjectColours(const Company *c)
Updates the colour of the object whenever a company changes.
town rating does not disallow you from building
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
SpriteID sprite
The 'real' sprite.
Structure contains cached list of stations nearby.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Date _date
Current date in days (day counter)
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
uint16 h
The height of the area.
Company view; Window numbers:
The tile/execution is done by "water".
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
static void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
Make an Object tile.
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
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...
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
Used for industry tiles on land (also for oilrig if newgrf says so).
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Do not display foundations when on a slope.
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Cheats _cheats
All the cheats.
static bool IsObjectTypeTile(TileIndex t, ObjectType type)
Check whether a tile is a object tile of a specific type.
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.