33#include "table/strings.h"
50 this->entity_overrides.resize(this->
max_offset);
51 std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
52 this->grfid_overrides.resize(this->
max_offset);
67 if (this->entity_overrides[entity_type] != this->
invalid_id)
return;
68 this->entity_overrides[entity_type] = local_id;
69 this->grfid_overrides[entity_type] = grfid;
81 std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
82 std::fill(this->grfid_overrides.begin(), this->grfid_overrides.end(), uint32_t());
112 uint16_t
id = this->
GetID(grf_local_id, grfid);
124 if (CheckValidNewID(
id) && map->
entity_id == 0 && map->
grfid == 0) {
142 return this->
mappings[entity_id].grfid;
152 return this->
mappings[entity_id].substitute_id;
162 HouseID house_id = this->
AddEntityID(hs.grf_prop.local_id, hs.grf_prop.grfid, hs.grf_prop.subst_id);
165 GrfMsg(1,
"House.SetEntitySpec: Too many houses allocated. Ignoring.");
172 if (house_id >= house_specs.size()) house_specs.resize(house_id + 1);
173 house_specs[house_id] = std::move(hs);
179 if (this->entity_overrides[i] != house_specs[house_id].grf_prop.local_id || this->grfid_overrides[i] != house_specs[house_id].grf_prop.grfid)
continue;
183 this->grfid_overrides[i] = 0;
200 if (this->entity_overrides[
id] == grf_local_id && this->grfid_overrides[
id] == grfid)
return id;
251 IndustryType ind_id = this->
GetID(inds.grf_prop.local_id, inds.grf_prop.grfid);
258 ind_id = this->
AddEntityID(inds.grf_prop.local_id, inds.grf_prop.grfid, inds.grf_prop.subst_id);
263 GrfMsg(1,
"Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
268 _industry_specs[ind_id] = std::move(inds);
270 _industry_specs[ind_id].
enabled =
true;
275 IndustryGfx indt_id = this->
AddEntityID(its.grf_prop.local_id, its.grf_prop.grfid, its.grf_prop.subst_id);
278 GrfMsg(1,
"IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
282 _industry_tile_specs[indt_id] = std::move(its);
288 if (this->entity_overrides[i] != _industry_tile_specs[indt_id].grf_prop.local_id || this->grfid_overrides[i] != _industry_tile_specs[indt_id].grf_prop.grfid)
continue;
291 overridden_its->
enabled =
false;
293 this->grfid_overrides[i] = 0;
306 ObjectType type = this->
GetID(spec.grf_prop.local_id, spec.grf_prop.grfid);
317 GrfMsg(1,
"Object.SetEntitySpec: Too many objects allocated. Ignoring.");
340 case LandscapeType::Arctic: {
395 default: NOT_REACHED();
397 return has_snow ? 4 : 0;
413 int8_t x =
GB(parameter, 0, 4);
414 int8_t y =
GB(parameter, 4, 4);
416 if (signed_offsets && x >= 8) x -= 16;
417 if (signed_offsets && y >= 8) y -= 16;
421 if (axis ==
AXIS_Y) std::swap(x, y);
448 return tile_type << 24 | ClampTo<uint8_t>(z) << 16 | terrain_type << 8 | tileh;
473 auto get_newgrf_text = [&grffile](
GRFStringID text_id, std::span<const int32_t> textstack) {
487 if (cb_res < 0x400) {
491 case 0x400:
return res;
494 case 0x401: res =
CommandCost(default_error);
break;
496 case 0x402: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
break;
497 case 0x403: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
break;
498 case 0x404: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_ABOVE_SNOW_LINE);
break;
499 case 0x405: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_BELOW_SNOW_LINE);
break;
500 case 0x406: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_SEA);
break;
501 case 0x407: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_CANAL);
break;
502 case 0x408: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_RIVER);
break;
503 case 0x40F: res = get_newgrf_text(
static_cast<GRFStringID>(textstack[0]), textstack.subspan(1));
break;
524 GetEncodedString(STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT, std::monostate{}, cbid, cb_res),
547 if (grffile->grf_version < 8)
return cb_res != 0;
566 if (grffile->grf_version < 8)
return GB(cb_res, 0, 8) != 0;
578 assert(this->seq.empty());
580 this->seq.resize(num_sprites, {});
588 assert(this->registers.empty());
590 this->registers.resize(1 + this->seq.size(), {});
603SpriteLayoutProcessor::SpriteLayoutProcessor(
const NewGRFSpriteLayout &raw_layout, uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage,
bool separate_ground) :
604 raw_layout(&raw_layout), separate_ground(separate_ground)
606 this->result_seq.reserve(this->raw_layout->seq.size() + 1);
611 copy.image = this->raw_layout->
ground;
612 copy.
delta_z =
static_cast<int8_t
>(0x80);
614 this->result_seq.insert(this->result_seq.end(), this->raw_layout->seq.begin(), this->raw_layout->seq.end());
618 const TileLayoutRegisters *regs = this->raw_layout->registers.empty() ? nullptr : this->raw_layout->registers.data();
622 if (regs !=
nullptr) flags = regs->
flags;
627 SetBit(this->var10_values, var10);
633 result.image.sprite += ground ? newgrf_ground_offset : newgrf_offset;
636 result.image.sprite += orig_offset;
643 SetBit(this->var10_values, var10);
649 result.image.sprite += ground ? newgrf_ground_offset : newgrf_offset;
655 if (regs !=
nullptr) regs++;
603SpriteLayoutProcessor::SpriteLayoutProcessor(
const NewGRFSpriteLayout &raw_layout, uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage,
bool separate_ground) : {
…}
667 assert(this->raw_layout !=
nullptr);
668 const TileLayoutRegisters *regs = this->raw_layout->registers.empty() ? nullptr : this->raw_layout->registers.data();
672 if (regs !=
nullptr) flags = regs->
flags;
678 if (var10 == resolved_var10) {
681 result.image.sprite = 0;
685 int16_t offset =
static_cast<int16_t
>(
object.GetRegister(regs->
sprite));
687 result.image.sprite += offset;
689 result.image.sprite = SPR_IMG_QUERY;
693 if (result.IsParentSprite()) {
695 result.delta_x +=
object.GetRegister(regs->delta.
parent[0]);
696 result.delta_y +=
object.GetRegister(regs->delta.
parent[1]);
711 if (var10 == resolved_var10) {
715 int16_t offset =
static_cast<int16_t
>(
object.GetRegister(regs->
palette));
717 result.image.pal += offset;
719 result.image.sprite = SPR_IMG_QUERY;
720 result.image.pal = PAL_NONE;
727 if (regs !=
nullptr) regs++;
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
Common return value for all commands.
void SetEncodedMessage(EncodedString &&message)
Set the encoded message string.
void SetEntitySpec(HouseSpec &&hs)
Install the specs into the HouseSpecs array It will find itself the proper slot on which it will go.
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.
uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const override
Return the ID (if ever available) of a previously inserted entity.
void SetEntitySpec(IndustrySpec &&inds)
Method to install the new industry data in its proper slot The slot assignment is internal of this me...
void SetEntitySpec(ObjectSpec &&spec)
Method to install the new object data in its proper slot The slot assignment is internal of this meth...
uint32_t GetGRFID(uint16_t entity_id) const
Gives the GRFID of the file the entity belongs to.
void ResetMapping()
Resets the mapping, which is used while initializing game.
uint16_t max_entities
what is the amount of entities, old and new summed
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
uint16_t invalid_id
ID used to detected invalid entities.
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...
OverrideManagerBase(uint16_t offset, uint16_t maximum, uint16_t invalid)
Constructor of generic class.
std::vector< EntityIDMapping > mappings
mapping of ids from grf files. Public out of convenience
void ResetOverride()
Resets the override, which is used while initializing game.
uint16_t GetSubstituteID(uint16_t entity_id) const
Gives the substitute of the entity, as specified by the grf file.
uint16_t max_offset
what is the length of the original entity's array of specs
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.
void ProcessRegisters(const struct ResolverObject &object, uint8_t resolved_var10, uint32_t resolved_sprite)
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
Map accessors for 'clear' tiles.
bool IsSnowTile(Tile t)
Test if a tile is covered with snow.
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
Definition of stuff that is very close to a company, like the company struct itself.
Functions related to companies.
bool IsLocalCompany()
Is the current company the local company?
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Axis
Allow incrementing of DiagDirDiff variables.
@ INVALID_AXIS
Flag for an invalid Axis.
Functions related to errors.
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
definition of HouseSpec and accessors
uint16_t HouseID
OpenTTD ID of house types.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Functions related to OTTD's landscape.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span< const int32_t > textstack, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
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 ...
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
TileContext
Context for tile accesses.
@ TCX_UPPER_HALFTILE
Querying information about the upper part of a tile with halftile foundation.
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
TileLayoutFlags
Flags to enable register usage in sprite layouts.
@ TLF_BB_Z_OFFSET
Add signed offset to bounding box Z positions from register TileLayoutRegisters::delta....
@ TLF_SPRITE
Add signed offset to sprite from register TileLayoutRegisters::sprite.
@ TLF_CHILD_X_OFFSET
Add signed offset to child sprite X positions from register TileLayoutRegisters::delta....
@ TLF_DODRAW
Only draw sprite if value of register TileLayoutRegisters::dodraw is non-zero.
@ 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_BB_XY_OFFSET
Add signed offset to bounding box X and Y positions from register TileLayoutRegisters::delta....
@ 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_PALETTE_VAR10
Resolve palette with a specific value in variable 10.
@ TLF_SPRITE_VAR10
Resolve sprite with a specific value in variable 10.
@ TLF_PALETTE
Add signed offset to palette from register TileLayoutRegisters::palette.
@ TLF_CHILD_Y_OFFSET
Add signed offset to child sprite Y positions from register TileLayoutRegisters::delta....
uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Functions to find and configure NewGRFs.
@ UnknownCbResult
A callback returned an unknown/invalid result.
std::vector< ObjectSpec > _object_specs
All the object specifications.
Functions related to NewGRF objects.
StringID GetGRFStringID(uint32_t grfid, GRFStringID stringid)
Returns the index for this stringid associated with its grfID.
std::vector< StringParameter > GetGRFSringTextStackParameters(const GRFFile *grffile, StringID stringid, std::span< const int32_t > textstack)
Process the text ref stack for a GRF String and return its parameters.
Header of Action 04 "universal holder" structure and functions.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
uint16_t ObjectType
Types of objects.
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
RailGroundType
The ground 'under' the rail.
@ RAIL_GROUND_ICE_DESERT
Icy or sandy.
@ RAIL_GROUND_HALF_SNOW
Snow only on higher part of slope (steep or one corner raised)
bool IsOnSnowOrDesert(Tile t)
Check if a road tile has snow/desert.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
Maps accessors for stations.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
bool IsRoadWaypointTile(Tile t)
Is this tile a station tile and a road waypoint?
Definition of base types and functions in a cross-platform compatible way.
static void StrMakeValid(Builder &builder, StringConsumer &consumer, StringValidationSettings settings)
Copies the valid (UTF-8) characters from consumer to the builder.
Functions related to low-level strings.
EncodedString GetEncodedStringWithArgs(StringID str, std::span< const StringParameter > params)
Encode a string with its parameters into an encoded string.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
int8_t delta_z
0x80 identifies child sprites
PalSpriteID ground
Palette and sprite for the ground.
Maps an entity id stored on the map to a GRF file.
uint16_t substitute_id
The (original) entity ID to use if this GRF is not available.
uint32_t grfid
The GRF ID of the file the entity belongs to.
uint16_t entity_id
The entity ID within the GRF file.
Information about GRF, used in the game and (part of it) in savegames.
GRFBugs grf_bugs
NOSAVE: bugs in this GRF in this run,.
std::string GetName() const
Get the name of this grf.
const struct GRFFile * grffile
grf file that introduced this entity
uint32_t grfid
grfid that introduced this entity.
void SetGRFFile(const struct GRFFile *grffile)
Set the NewGRF file, and its grfid, associated with grf props.
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
Dynamic data of a loaded NewGRF.
LandscapeType landscape
the landscape we're currently in
GameCreationSettings game_creation
settings used during the creation of a game (map)
SubstituteGRFFileProps grf_prop
Properties related the the grf file.
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Defines the data structure for constructing industry.
SubstituteGRFFileProps grf_prop
properties related to the grf file
bool enabled
entity still available (by default true).newgrf can disable it, though
Defines the data structure of each individual tile of an industry.
SubstituteGRFFileProps grf_prop
properties related to the grf file
bool enabled
entity still available (by default true).newgrf can disable it, though
Information about a particular livery.
Colours colour2
Second colour, for vehicles with 2CC support.
Colours colour1
First colour, for all vehicles.
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
NewGRF supplied spritelayout.
void Allocate(uint num_sprites)
Allocate a spritelayout for num_sprites building sprites.
void AllocateRegisters()
Allocate memory for register modifiers.
Allow incrementing of ObjectClassID variables.
static Titem * Get(auto index)
Returns Titem with given index.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Interface for SpriteGroup-s to access the gamestate.
uint16_t override_id
id of the entity been replaced by
Additional modifiers for items in sprite layouts.
uint8_t parent[3]
Registers for signed offsets for the bounding box position of parent sprites.
TileLayoutFlags flags
Flags defining which members are valid and to be used.
uint8_t dodraw
Register deciding whether the sprite shall be drawn at all. Non-zero means drawing.
uint16_t max_sprite_offset
Maximum offset to add to the sprite. (limited by size of the spriteset)
uint8_t palette
Register specifying a signed offset for the palette.
uint8_t sprite_var10
Value for variable 10 when resolving the sprite.
uint16_t max_palette_offset
Maximum offset to add to the palette. (limited by size of the spriteset)
uint8_t palette_var10
Value for variable 10 when resolving the palette.
uint8_t child[2]
Registers for signed offsets for the position of child sprites.
uint8_t sprite
Register specifying a signed offset for the sprite.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
TileType
The different types of tiles.
@ MP_TREES
Tile got trees.
@ MP_ROAD
A tile with road (or tram tracks)
@ MP_STATION
A tile of a station.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ MP_HOUSE
A house by a town.
@ MP_INDUSTRY
Part of an industry.
@ MP_VOID
Invisible tiles at the SW and SE border.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Map accessors for tree tiles.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
TreeGround
Enumeration for ground types of tiles with trees.
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
uint GetTreeDensity(Tile t)
Returns the 'density' of a tile with trees.
Functions that have tunnels and bridges in common.
bool HasTunnelBridgeSnowOrDesert(Tile t)
Tunnel: Is this tunnel entrance in a snowy or desert area? Bridge: Does the bridge ramp lie in a snow...
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.