OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
31 #include "table/strings.h"
48 entity_overrides = MallocT<uint16>(
max_offset);
49 for (
size_t i = 0; i <
max_offset; i++) entity_overrides[i] = invalid;
60 free(entity_overrides);
61 free(grfid_overrides);
76 if (entity_overrides[entity_type] !=
invalid_ID)
return;
77 entity_overrides[entity_type] = local_id;
78 grfid_overrides[entity_type] = grfid;
92 grfid_overrides[i] = 0;
125 uint16
id = this->
GetID(grf_local_id, grfid);
140 if (CheckValidNewID(
id) && map->
entity_id == 0 && map->
grfid == 0) {
181 grfmsg(1,
"House.SetEntitySpec: Too many houses allocated. Ignoring.");
185 MemCpyT(HouseSpec::Get(house_id), hs);
189 HouseSpec *overridden_hs = HouseSpec::Get(i);
195 grfid_overrides[i] = 0;
212 if (entity_overrides[
id] == grf_local_id && grfid_overrides[
id] == grfid)
return id;
275 grfmsg(1,
"Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
280 _industry_specs[ind_id] = *inds;
282 _industry_specs[ind_id].
enabled =
true;
285 void IndustryTileOverrideManager::SetEntitySpec(
const IndustryTileSpec *its)
290 grfmsg(1,
"IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
294 memcpy(&_industry_tile_specs[indt_id], its,
sizeof(*its));
303 overridden_its->
enabled =
false;
305 grfid_overrides[i] = 0;
329 grfmsg(1,
"Object.SetEntitySpec: Too many objects allocated. Ignoring.");
407 default: NOT_REACHED();
409 return has_snow ? 4 : 0;
425 int8 x =
GB(parameter, 0, 4);
426 int8 y =
GB(parameter, 4, 4);
428 if (signed_offsets && x >= 8) x -= 16;
429 if (signed_offsets && y >= 8) y -= 16;
458 return tile_type << 24 |
Clamp(z, 0, 0xFF) << 16 | terrain_type << 8 | tileh;
484 if (cb_res < 0x400) {
488 case 0x400:
return res;
491 case 0x401: res =
CommandCost(default_error);
break;
493 case 0x402: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
break;
494 case 0x403: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
break;
495 case 0x404: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_ABOVE_SNOW_LINE);
break;
496 case 0x405: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_BELOW_SNOW_LINE);
break;
497 case 0x406: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_SEA);
break;
498 case 0x407: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_CANAL);
break;
499 case 0x408: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_RIVER);
break;
532 GetString(buffer, STR_NEWGRF_BUGGY,
lastof(buffer));
533 Debug(grf, 0,
"{}", buffer + 3);
537 GetString(buffer, STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT,
lastof(buffer));
538 Debug(grf, 0,
"{}", buffer + 3);
554 if (grffile->grf_version < 8)
return cb_res != 0;
573 if (grffile->grf_version < 8)
return GB(cb_res, 0, 8) != 0;
588 assert(this->
seq ==
nullptr);
589 assert(source !=
nullptr);
596 MemCpyT(sprites, source, count);
608 if (source->registers !=
nullptr) {
614 MemCpyT(regs, source->registers, count);
615 this->registers = regs;
626 assert(this->
seq ==
nullptr);
638 assert(this->
seq !=
nullptr);
639 assert(this->registers ==
nullptr);
645 this->registers = CallocT<TileLayoutRegisters>(count);
663 uint32 var10_values = 0;
684 if (regs !=
nullptr) flags = regs->
flags;
689 SetBit(var10_values, var10);
695 result->image.
sprite +=
ground ? newgrf_ground_offset : newgrf_offset;
698 result->image.
sprite += orig_offset;
705 SetBit(var10_values, var10);
711 result->image.
sprite +=
ground ? newgrf_ground_offset : newgrf_offset;
717 if (regs !=
nullptr) regs++;
738 if (regs !=
nullptr) flags = regs->
flags;
744 if (var10 == resolved_var10) {
753 result->image.
sprite += offset;
755 result->image.
sprite = SPR_IMG_QUERY;
777 if (var10 == resolved_var10) {
783 result->image.
pal += offset;
785 result->image.
sprite = SPR_IMG_QUERY;
786 result->image.
pal = PAL_NONE;
793 if (regs !=
nullptr) regs++;
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ MP_HOUSE
A house by a town.
@ TCX_UPPER_HALFTILE
Querying information about the upper part of a tile with halftile foundation.
uint32 TileIndex
The index/ID of a Tile.
uint16 override
id of the entity been replaced by
static Titem * Get(size_t index)
Returns Titem with given index.
uint8 substitute_id
The (original) entity ID to use if this GRF is not available.
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.
@ RAIL_GROUND_HALF_SNOW
Snow only on higher part of slope (steep or one corner raised)
@ TLF_DODRAW
Only draw sprite if value of register TileLayoutRegisters::dodraw is non-zero.
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
uint32 PrepareLayout(uint32 orig_offset, uint32 newgrf_ground_offset, uint32 newgrf_offset, uint constr_stage, bool separate_ground) const
Prepares a sprite layout before resolving action-1-2-3 chains.
Allow incrementing of ObjectClassID variables.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
byte landscape
the landscape we're currently in
@ TLF_CHILD_X_OFFSET
Add signed offset to child sprite X positions from register TileLayoutRegisters::delta....
void CDECL grfmsg(int severity, const char *str,...)
Debug() function dedicated to newGRF debugging messages Function is essentially the same as Debug(grf...
uint8 sprite
Register specifying a signed offset for the sprite.
void AllocateRegisters()
Allocate memory for register modifiers.
virtual ~OverrideManagerBase()
Destructor of the generic class.
uint8 parent[3]
Registers for signed offsets for the bounding box position of parent sprites.
uint8 palette_var10
Value for variable 10 when resolving the palette.
SpriteID sprite
The 'real' sprite.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static uint GetTreeDensity(TileIndex t)
Returns the 'density' of a tile with trees.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
void ProcessRegisters(uint8 resolved_var10, uint32 resolved_sprite, bool separate_ground) const
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
@ MP_INDUSTRY
Part of an industry.
void Add(uint8 local_id, uint32 grfid, uint entity_type)
Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game...
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Owner
Enum for all companies/owners.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
@ TLF_BB_Z_OFFSET
Add signed offset to bounding box Z positions from register TileLayoutRegisters::delta....
@ MP_ROAD
A tile with road (or tram tracks)
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Additional modifiers for items in sprite layouts.
uint8 dodraw
Register deciding whether the sprite shall be drawn at all. Non-zero means drawing.
uint16 GetID(uint8 grf_local_id, uint32 grfid) const override
Return the ID (if ever available) of a previously inserted entity.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
GameCreationSettings game_creation
settings used during the creation of a game (map)
uint32 grfid
The GRF ID of the file the entity belongs to.
PalSpriteID ground
Palette and sprite for the ground.
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
Constructor of generic class.
int8 delta_x
0x80 is sequence terminator
uint32 grf_bugs
NOSAVE: bugs in this GRF in this run,.
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
void UseTextRefStack(const GRFFile *grffile, uint num_registers)
Activate usage of the NewGRF TextRefStack for the error message.
Common return value for all commands.
byte GetSnowLine()
Get the current snow line, either variable or static.
Information about GRF, used in the game and (part of it) in savegames.
int8 delta_z
0x80 identifies child sprites
@ TLF_BB_XY_OFFSET
Add signed offset to bounding box X and Y positions from register TileLayoutRegisters::delta....
void ResetMapping()
Resets the mapping, which is used while initializing game.
@ TLF_CHILD_Y_OFFSET
Add signed offset to child sprite Y positions from register TileLayoutRegisters::delta....
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
uint16 ObjectType
Types of objects.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
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.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
TileContext
Context for tile accesses.
uint8 child[2]
Registers for signed offsets for the position of child sprites.
NewGRF supplied spritelayout.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
void SetEntitySpec(ObjectSpec *spec)
Method to install the new object data in its proper slot The slot assignment is internal of this meth...
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
static bool IsSnowTile(TileIndex t)
Test if a tile is covered with snow.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
@ SPRITE_MODIFIER_CUSTOM_SPRITE
Set when a sprite originates from an Action 1.
bool enabled
entity still available (by default true).newgrf can disable it, though
static bool IsOnSnow(TileIndex t)
Check if a road tile has snow/desert.
Ground palette sprite of a tile, together with its sprite layout.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
static uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
Slope
Enumeration for the slope-type.
Maps an entity id stored on the map to a GRF file.
Defines the data structure for constructing industry.
static bool HasTunnelBridgeSnowOrDesert(TileIndex t)
Tunnel: Is this tunnel entrance in a snowy or desert area? Bridge: Does the bridge ramp lie in a snow...
GRFFileProps grf_prop
properties related to the grf file
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
@ GBUG_UNKNOWN_CB_RESULT
A callback returned an unknown/invalid result.
RailGroundType
The ground 'under' the rail.
@ MP_TREES
Tile got trees.
uint8 sprite_var10
Value for variable 10 when resolving the sprite.
bool _generating_world
Whether we are generating the map or not.
uint8 entity_id
The entity ID within the GRF file.
bool enabled
entity still available (by default true).newgrf can disable it, though
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
uint16 HouseID
OpenTTD ID of house types.
TreeGround
Enumeration for ground types of tiles with trees.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
uint16 max_new_entities
what is the amount of entities, old and new summed
uint8 palette
Register specifying a signed offset for the palette.
@ MP_VOID
Invisible tiles at the SW and SE border.
uint16 max_palette_offset
Maximum offset to add to the palette. (limited by size of the spriteset)
TileType
The different types of tiles.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
uint16 GetSubstituteID(uint16 entity_id) const
Gives the substitute of the entity, as specified by the grf file.
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) override
Method to find an entity ID and to mark it as reserved for the Industry to be included.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
@ MP_STATION
A tile of a station.
GRFFileProps grf_prop
properties related to the grf file
void ResetOverride()
Resets the override, which is used while initializing game.
TileLayoutFlags
Flags to enable register usage in sprite layouts.
EntityIDMapping * mapping_ID
mapping of ids from grf files. Public out of convenience
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
void Clone(const DrawTileSeqStruct *source)
Clone the building sprites of a spritelayout.
uint32 GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
void MakeTerminator()
Make this struct a sequence terminator.
TileLayoutFlags flags
Flags defining which members are valid and to be used.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
uint16 max_offset
what is the length of the original entity's array of specs
Axis
Allow incrementing of DiagDirDiff variables.
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
Reserves a place in the mapping array for an entity to be installed.
uint32 GetGRFID(uint16 entity_id) const
Gives the GRFID of the file the entity belongs to.
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
uint16 local_id
id defined by the grf file for this entity
PaletteID pal
The palette (use PAL_NONE) if not needed)
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
@ TLF_PALETTE_REG_FLAGS
Flags which require resolving the action-1-2-3 chain for the palette, even if it is no action-1 palet...
@ TLF_SPRITE
Add signed offset to sprite from register TileLayoutRegisters::sprite.
@ TLF_PALETTE
Add signed offset to palette from register TileLayoutRegisters::palette.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
const struct GRFFile * grffile
grf file that introduced this entity
static void Swap(T &a, T &b)
Type safe swap operation.
@ INVALID_AXIS
Flag for an invalid Axis.
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
void SetEntitySpec(IndustrySpec *inds)
Method to install the new industry data in its proper slot The slot assignment is internal of this me...
Defines the data structure of each individual tile of an industry.
@ TLF_PALETTE_VAR10
Resolve palette with a specific value in variable 10.
@ TLF_SPRITE_REG_FLAGS
Flags which require resolving the action-1-2-3 chain for the sprite, even if it is no action-1 sprite...
@ TLF_SPRITE_VAR10
Resolve sprite with a specific value in variable 10.
#define lastof(x)
Get the last element of an fixed size array.
Information about a particular livery.
static std::vector< DrawTileSeqStruct > result_seq
Temporary storage when preprocessing spritelayouts.
@ RAIL_GROUND_ICE_DESERT
Icy or sandy.
GRFFileProps grf_prop
Properties related the the grf file.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
void Allocate(uint num_sprites)
Allocate a spritelayout for num_sprites building sprites.
Dynamic data of a loaded NewGRF.
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
uint16 invalid_ID
ID used to detected invalid entities;.
const char * GetName() const
Get the name of this grf.
uint16 max_sprite_offset
Maximum offset to add to the sprite. (limited by size of the spriteset)
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
byte colour2
Second colour, for vehicles with 2CC support.
byte colour1
First colour, for all vehicles.
void SetEntitySpec(const HouseSpec *hs)
Install the specs into the HouseSpecs array It will find itself the proper slot on which it will go.
ObjectSpec _object_specs[NUM_OBJECTS]
All the object specifications.
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.