|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
32 #include "table/strings.h"
49 this->entity_overrides.resize(this->
max_offset);
50 std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
51 this->grfid_overrides.resize(this->
max_offset);
66 if (this->entity_overrides[entity_type] != this->
invalid_id)
return;
67 this->entity_overrides[entity_type] = local_id;
68 this->grfid_overrides[entity_type] = grfid;
80 std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
81 std::fill(this->grfid_overrides.begin(), this->grfid_overrides.end(), uint32_t());
111 uint16_t
id = this->
GetID(grf_local_id, grfid);
123 if (CheckValidNewID(
id) && map->
entity_id == 0 && map->
grfid == 0) {
141 return this->
mappings[entity_id].grfid;
151 return this->
mappings[entity_id].substitute_id;
164 GrfMsg(1,
"House.SetEntitySpec: Too many houses allocated. Ignoring.");
168 *HouseSpec::Get(house_id) = *hs;
172 HouseSpec *overridden_hs = HouseSpec::Get(i);
178 this->grfid_overrides[i] = 0;
195 if (this->entity_overrides[
id] == grf_local_id && this->grfid_overrides[
id] == grfid)
return id;
258 GrfMsg(1,
"Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
263 _industry_specs[ind_id] = *inds;
265 _industry_specs[ind_id].
enabled =
true;
268 void IndustryTileOverrideManager::SetEntitySpec(
const IndustryTileSpec *its)
273 GrfMsg(1,
"IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
277 _industry_tile_specs[indt_id] = *its;
286 overridden_its->
enabled =
false;
288 this->grfid_overrides[i] = 0;
312 GrfMsg(1,
"Object.SetEntitySpec: Too many objects allocated. Ignoring.");
390 default: NOT_REACHED();
392 return has_snow ? 4 : 0;
408 int8_t x =
GB(parameter, 0, 4);
409 int8_t y =
GB(parameter, 4, 4);
411 if (signed_offsets && x >= 8) x -= 16;
412 if (signed_offsets && y >= 8) y -= 16;
441 return tile_type << 24 | ClampTo<uint8_t>(z) << 16 | terrain_type << 8 | tileh;
467 if (cb_res < 0x400) {
471 case 0x400:
return res;
474 case 0x401: res =
CommandCost(default_error);
break;
476 case 0x402: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
break;
477 case 0x403: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
break;
478 case 0x404: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_ABOVE_SNOW_LINE);
break;
479 case 0x405: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_BELOW_SNOW_LINE);
break;
480 case 0x406: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_SEA);
break;
481 case 0x407: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_CANAL);
break;
482 case 0x408: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_RIVER);
break;
533 if (grffile->grf_version < 8)
return cb_res != 0;
552 if (grffile->grf_version < 8)
return GB(cb_res, 0, 8) != 0;
567 assert(this->
seq ==
nullptr);
568 assert(source !=
nullptr);
575 MemCpyT(sprites, source, count);
587 if (source->registers !=
nullptr) {
593 MemCpyT(regs, source->registers, count);
594 this->registers = regs;
605 assert(this->
seq ==
nullptr);
617 assert(this->
seq !=
nullptr);
618 assert(this->registers ==
nullptr);
624 this->registers = CallocT<TileLayoutRegisters>(count);
642 uint32_t var10_values = 0;
650 result->delta_z = (int8_t)0x80;
663 if (regs !=
nullptr) flags = regs->
flags;
668 SetBit(var10_values, var10);
674 result->image.sprite +=
ground ? newgrf_ground_offset : newgrf_offset;
677 result->image.sprite += orig_offset;
684 SetBit(var10_values, var10);
690 result->image.sprite +=
ground ? newgrf_ground_offset : newgrf_offset;
696 if (regs !=
nullptr) regs++;
717 if (regs !=
nullptr) flags = regs->
flags;
723 if (var10 == resolved_var10) {
726 result->image.sprite = 0;
732 result->image.sprite += offset;
734 result->image.sprite = SPR_IMG_QUERY;
738 if (result->IsParentSprite()) {
756 if (var10 == resolved_var10) {
762 result->image.pal += offset;
764 result->image.sprite = SPR_IMG_QUERY;
765 result->image.pal = PAL_NONE;
772 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_t GetGRFID(uint16_t entity_id) const
Gives the GRFID of the file the entity belongs to.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static Titem * Get(size_t index)
Returns Titem with given index.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
@ 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.
Allow incrementing of ObjectClassID variables.
uint8_t dodraw
Register deciding whether the sprite shall be drawn at all. Non-zero means drawing.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
constexpr void Swap(T &a, T &b)
Type safe swap operation.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
byte landscape
the landscape we're currently in
@ TLF_CHILD_X_OFFSET
Add signed offset to child sprite X positions from register TileLayoutRegisters::delta....
uint32_t grfid
The GRF ID of the file the entity belongs to.
uint16_t entity_id
The entity ID within the GRF file.
Axis
Allow incrementing of DiagDirDiff variables.
void AllocateRegisters()
Allocate memory for register modifiers.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id) override
Method to find an entity ID and to mark it as reserved for the Industry to be included.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
uint32_t grf_bugs
NOSAVE: bugs in this GRF in this run,.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
@ MP_INDUSTRY
Part of an industry.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
uint32_t GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
void ProcessRegisters(uint8_t resolved_var10, uint32_t resolved_sprite, bool separate_ground) const
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
std::vector< ObjectSpec > _object_specs
All the object specifications.
Owner
Enum for all companies/owners.
@ 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)
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Additional modifiers for items in sprite layouts.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
uint16_t invalid_id
ID used to detected invalid entities.
void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
PalSpriteID ground
Palette and sprite for the ground.
uint8_t sprite_var10
Value for variable 10 when resolving the sprite.
uint16_t override
id of the entity been replaced by
Slope
Enumeration for the slope-type.
uint8_t palette
Register specifying a signed offset for the palette.
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.
uint16_t ObjectType
Types of objects.
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
@ 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 HasTunnelBridgeSnowOrDesert(Tile t)
Tunnel: Is this tunnel entrance in a snowy or desert area? Bridge: Does the bridge ramp lie in a snow...
@ MP_OBJECT
Contains objects such as transmitters and owned land.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
uint16_t max_palette_offset
Maximum offset to add to the palette. (limited by size of the spriteset)
#define foreach_draw_tile_seq(idx, list)
Iterate through all DrawTileSeqStructs in DrawTileSprites.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
GameSettings _settings_game
Game settings of a running game or the scenario editor.
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
TileContext
Context for tile accesses.
NewGRF supplied spritelayout.
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)?
@ 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
Ground palette sprite of a tile, together with its sprite layout.
uint16_t GetSubstituteID(uint16_t entity_id) const
Gives the substitute of the entity, as specified by the grf file.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
OverrideManagerBase(uint16_t offset, uint16_t maximum, uint16_t invalid)
Constructor of generic class.
virtual uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id)
Reserves a place in the mapping array for an entity to be installed.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Maps an entity id stored on the map to a GRF file.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const override
Return the ID (if ever available) of a previously inserted entity.
Defines the data structure for constructing industry.
uint32_t PrepareLayout(uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage, bool separate_ground) const
Prepares a sprite layout before resolving action-1-2-3 chains.
GRFFileProps grf_prop
properties related to the grf file
@ GBUG_UNKNOWN_CB_RESULT
A callback returned an unknown/invalid result.
RailGroundType
The ground 'under' the rail.
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
uint16_t local_id
id defined by the grf file for this entity
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
@ MP_TREES
Tile got trees.
bool _generating_world
Whether we are generating the map or not.
bool enabled
entity still available (by default true).newgrf can disable it, though
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
TreeGround
Enumeration for ground types of tiles with trees.
@ MP_VOID
Invisible tiles at the SW and SE border.
@ INVALID_AXIS
Flag for an invalid Axis.
uint8_t parent[3]
Registers for signed offsets for the bounding box position of parent sprites.
Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
TileType
The different types of tiles.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
Colours colour1
First colour, for all vehicles.
@ MP_STATION
A tile of a station.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
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.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
uint16_t HouseID
OpenTTD ID of house types.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void Clone(const DrawTileSeqStruct *source)
Clone the building sprites of a spritelayout.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
uint8_t sprite
Register specifying a signed offset for the sprite.
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.
uint16_t max_entities
what is the amount of entities, old and new summed
uint8_t child[2]
Registers for signed offsets for the position of child sprites.
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
void Add(uint16_t local_id, uint32_t grfid, uint entity_type)
Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game...
bool IsSnowTile(Tile t)
Test if a tile is covered with snow.
uint16_t substitute_id
The (original) entity ID to use if this GRF is not available.
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
@ 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.
uint16_t max_offset
what is the length of the original entity's array of specs
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
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
std::vector< EntityIDMapping > mappings
mapping of ids from grf files. Public out of convenience
uint16_t max_sprite_offset
Maximum offset to add to the sprite. (limited by size of the spriteset)
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.
Colours colour2
Second colour, for vehicles with 2CC support.
@ 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...
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
@ TLF_SPRITE_VAR10
Resolve sprite with a specific value in variable 10.
Information about a particular livery.
static std::vector< DrawTileSeqStruct > result_seq
Temporary storage when preprocessing spritelayouts.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
@ RAIL_GROUND_ICE_DESERT
Icy or sandy.
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
GRFFileProps grf_prop
Properties related the the grf file.
uint GetTreeDensity(Tile t)
Returns the 'density' of a tile with trees.
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.
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
bool IsOnSnow(Tile t)
Check if a road tile has snow/desert.
const char * GetName() const
Get the name of this grf.
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
uint8_t palette_var10
Value for variable 10 when resolving the palette.
void SetEntitySpec(const HouseSpec *hs)
Install the specs into the HouseSpecs array It will find itself the proper slot on which it will go.
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.