33 #include "table/strings.h" 50 entity_overrides = MallocT<uint16>(
max_offset);
51 for (
size_t i = 0; i <
max_offset; i++) entity_overrides[i] = invalid;
62 free(entity_overrides);
63 free(grfid_overrides);
78 if (entity_overrides[entity_type] !=
invalid_ID)
return;
79 entity_overrides[entity_type] = local_id;
80 grfid_overrides[entity_type] = grfid;
94 grfid_overrides[i] = 0;
127 uint16
id = this->
GetID(grf_local_id, grfid);
142 if (CheckValidNewID(
id) && map->
entity_id == 0 && map->
grfid == 0) {
183 grfmsg(1,
"House.SetEntitySpec: Too many houses allocated. Ignoring.");
187 MemCpyT(HouseSpec::Get(house_id), hs);
191 HouseSpec *overridden_hs = HouseSpec::Get(i);
197 grfid_overrides[i] = 0;
214 if (entity_overrides[
id] == grf_local_id && grfid_overrides[
id] == grfid)
return id;
277 grfmsg(1,
"Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
282 memcpy(&_industry_specs[ind_id], inds,
sizeof(*inds));
284 _industry_specs[ind_id].
enabled =
true;
287 void IndustryTileOverrideManager::SetEntitySpec(
const IndustryTileSpec *its)
292 grfmsg(1,
"IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
296 memcpy(&_industry_tile_specs[indt_id], its,
sizeof(*its));
305 overridden_its->
enabled =
false;
307 grfid_overrides[i] = 0;
331 grfmsg(1,
"Object.SetEntitySpec: Too many objects allocated. Ignoring.");
338 memcpy(&_object_specs[type], spec,
sizeof(*spec));
339 ObjectClass::Assign(&_object_specs[type]);
409 default: NOT_REACHED();
411 return has_snow ? 4 : 0;
427 int8 x =
GB(parameter, 0, 4);
428 int8 y =
GB(parameter, 4, 4);
430 if (signed_offsets && x >= 8) x -= 16;
431 if (signed_offsets && y >= 8) y -= 16;
460 return tile_type << 24 |
Clamp(z, 0, 0xFF) << 16 | terrain_type << 8 | tileh;
486 if (cb_res < 0x400) {
490 case 0x400:
return res;
493 case 0x401: res =
CommandCost(default_error);
break;
495 case 0x402: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
break;
496 case 0x403: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
break;
497 case 0x404: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_ABOVE_SNOW_LINE);
break;
498 case 0x405: res =
CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_BELOW_SNOW_LINE);
break;
499 case 0x406: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_SEA);
break;
500 case 0x407: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_CANAL);
break;
501 case 0x408: res =
CommandCost(STR_ERROR_CAN_T_BUILD_ON_RIVER);
break;
534 GetString(buffer, STR_NEWGRF_BUGGY,
lastof(buffer));
535 DEBUG(grf, 0,
"%s", buffer + 3);
539 GetString(buffer, STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT,
lastof(buffer));
540 DEBUG(grf, 0,
"%s", buffer + 3);
556 if (grffile->grf_version < 8)
return cb_res != 0;
575 if (grffile->grf_version < 8)
return GB(cb_res, 0, 8) != 0;
590 assert(this->seq == NULL);
591 assert(source != NULL);
598 MemCpyT(sprites, source, count);
610 if (source->registers != NULL) {
616 MemCpyT(regs, source->registers, count);
617 this->registers = regs;
628 assert(this->seq == NULL);
640 assert(this->seq != NULL);
641 assert(this->registers == NULL);
647 this->registers = CallocT<TileLayoutRegisters>(count);
665 uint32 var10_values = 0;
670 result->image = ground;
677 *result_seq.Append() = *dtss;
687 if (regs != NULL) flags = regs->
flags;
692 SetBit(var10_values, var10);
698 result->image.
sprite += ground ? newgrf_ground_offset : newgrf_offset;
701 result->image.
sprite += orig_offset;
708 SetBit(var10_values, var10);
714 result->image.
sprite += ground ? newgrf_ground_offset : newgrf_offset;
720 if (regs != NULL) regs++;
741 if (regs != NULL) flags = regs->
flags;
747 if (var10 == resolved_var10) {
756 result->image.
sprite += offset;
758 result->image.
sprite = SPR_IMG_QUERY;
780 if (var10 == resolved_var10) {
786 result->image.
pal += offset;
788 result->image.
sprite = SPR_IMG_QUERY;
789 result->image.
pal = PAL_NONE;
796 if (regs != NULL) regs++;
Functions related to OTTD's strings.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static void Swap(T &a, T &b)
Type safe swap operation.
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.
void SetEntitySpec(ObjectSpec *spec)
Method to install the new object data in its proper slot The slot assignment is internal of this meth...
bool enabled
entity still available (by default true).newgrf can disable it, though
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Add signed offset to child sprite Y positions from register TileLayoutRegisters::delta.child[1].
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
byte landscape
the landscape we're currently in
Maps accessors for stations.
uint16 invalid_ID
ID used to detected invalid entities;.
static bool IsSnowTile(TileIndex t)
Test if a tile is covered with snow.
void Allocate(uint num_sprites)
Allocate a spritelayout for num_sprites building sprites.
TileLayoutFlags
Flags to enable register usage in sprite layouts.
static Titem * Get(size_t index)
Returns Titem with given index.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
TileType
The different types of tiles.
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
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.
Add signed offset to bounding box X and Y positions from register TileLayoutRegisters::delta.parent[0..1].
A tile with road (or tram tracks)
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
uint32 GetGRFID(uint16 entity_id) const
Gives the GRFID of the file the entity belongs to.
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...
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
A snow tile that is rough underneath.
uint16 max_palette_offset
Maximum offset to add to the palette. (limited by size of the spriteset)
Resolve sprite with a specific value in variable 10.
Flags which require resolving the action-1-2-3 chain for the sprite, even if it is no action-1 sprite...
Add signed offset to palette from register TileLayoutRegisters::palette.
void MakeTerminator()
Make this struct a sequence terminator.
void UseTextRefStack(const GRFFile *grffile, uint num_registers)
Activate usage of the NewGRF TextRefStack for the error message.
Add signed offset to sprite from register TileLayoutRegisters::sprite.
Allow incrementing of ObjectClassID variables.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static SmallVector< DrawTileSeqStruct, 8 > result_seq
Temporary storage when preprocessing spritelayouts.
#define lastof(x)
Get the last element of an fixed size array.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Map accessors for tree tiles.
Functions related to world/map generation.
Contains objects such as transmitters and owned land.
void AllocateRegisters()
Allocate memory for register modifiers.
Common return value for all commands.
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
Constructor of generic class.
uint16 HouseID
OpenTTD ID of house types.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
ObjectSpec _object_specs[NUM_OBJECTS]
All the object specifications.
Functions related to NewGRF objects.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
uint32 grfid
The GRF ID of the file the entity belongs to.
Snow only on higher part of slope (steep or one corner raised)
Only draw sprite if value of register TileLayoutRegisters::dodraw is non-zero.
Critical errors, the MessageBox is shown in all cases.
Querying information about stuff on the bridge (via some bridgehead).
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
static bool IsOnSnow(TileIndex t)
Check if a road tile has snow/desert.
Header of Action 04 "universal holder" structure and functions.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
uint8 palette_var10
Value for variable 10 when resolving the palette.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
void Clone(const DrawTileSeqStruct *source)
Clone the building sprites of a spritelayout.
uint16 max_new_entities
what is the amount of entities, old and new summed
Querying information about the upper part of a tile with halftile foundation.
uint32 grf_bugs
NOSAVE: bugs in this GRF in this run,.
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Functions related to errors.
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.
uint16 max_sprite_offset
Maximum offset to add to the sprite. (limited by size of the spriteset)
Information about GRF, used in the game and (part of it) in savegames.
Ground palette sprite of a tile, together with its sprite layout.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
uint8 substitute_id
The (original) entity ID to use if this GRF is not available.
definition of HouseSpec and accessors
Maps an entity id stored on the map to a GRF file.
virtual ~OverrideManagerBase()
Destructor of the generic class.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
#define foreach_draw_tile_seq(idx, list)
Iterate through all DrawTileSeqStructs in DrawTileSprites.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition of base types and functions in a cross-platform compatible way.
void SetEntitySpec(const HouseSpec *hs)
Install the specs into the HouseSpecs array It will find itself the proper slot on which it will go...
A number of safeguards to prevent using unsafe methods.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
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 Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Information about a particular livery.
uint8 sprite_var10
Value for variable 10 when resolving the sprite.
static uint GetTreeDensity(TileIndex t)
Returns the 'density' of a tile with trees.
Set when a sprite originates from an Action 1.
Defines the data structure for constructing industry.
uint8 sprite
Register specifying a signed offset for the sprite.
Add signed offset to bounding box Z positions from register TileLayoutRegisters::delta.parent[2].
bool enabled
entity still available (by default true).newgrf can disable it, though
GRFFileProps grf_prop
properties related to the grf file
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
A callback returned an unknown/invalid result.
GRFFileProps grf_prop
properties related to the grf file
uint16 ObjectType
Types of objects.
NewGRF supplied spritelayout.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
a desert or snow tile, depend on landscape
byte colour2
Second colour, for vehicles with 2CC support.
Flags which require resolving the action-1-2-3 chain for the palette, even if it is no action-1 palet...
Functions to find and configure NewGRFs.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
#define DEBUG(name, level,...)
Output a line of debugging information.
uint16 override
id of the entity been replaced by
uint8 entity_id
The entity ID within the GRF file.
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
Resolve palette with a specific value in variable 10.
Additional modifiers for items in sprite layouts.
EntityIDMapping * mapping_ID
mapping of ids from grf files. Public out of convenience
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...
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
uint8 child[2]
Registers for signed offsets for the position of child sprites.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
bool _generating_world
Whether we are generating the map or not.
Tunnel entry/exit and bridge heads.
Invisible tiles at the SW and SE border.
void ResetMapping()
Resets the mapping, which is used while initializing game.
uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
uint32 TileIndex
The index/ID of a Tile.
Map accessors for 'clear' tiles.
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
Add signed offset to child sprite X positions from register TileLayoutRegisters::delta.child[0].
int8 delta_z
0x80 identifies child sprites
void CDECL grfmsg(int severity, const char *str,...)
DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf...
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Slope
Enumeration for the slope-type.
uint32 GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
Functions related to OTTD's landscape.
byte GetSnowLine()
Get the current snow line, either variable or static.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
uint16 local_id
id defined by the grf file for this entity
RailGroundType
The ground 'under' the rail.
Functions that have tunnels and bridges in common.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
const char * GetName() const
Get the name of this grf.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
GRFFileProps grf_prop
Properties related the the grf file.
void ResetOverride()
Resets the override, which is used while initializing game.
const struct GRFFile * grffile
grf file that introduced this entity
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
byte colour1
First colour, for all vehicles.
static uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
GameCreationSettings game_creation
settings used during the creation of a game (map)
A tile without any structures, i.e. grass, rocks, farm fields etc.
Defines the data structure of each individual tile of an industry.
TreeGround
Enumeration for ground types of tiles with trees.
int8 delta_x
0x80 is sequence terminator
Owner
Enum for all companies/owners.
uint16 max_offset
what is the length of the original entity's array of specs
Flag for an invalid Axis.
SpriteID sprite
The 'real' sprite.
uint8 parent[3]
Registers for signed offsets for the bounding box position of parent sprites.
uint8 dodraw
Register deciding whether the sprite shall be drawn at all. Non-zero means drawing.
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
void SetEntitySpec(IndustrySpec *inds)
Method to install the new industry data in its proper slot The slot assignment is internal of this me...
Axis
Allow incrementing of DiagDirDiff variables.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
uint8 palette
Register specifying a signed offset for the palette.
TileLayoutFlags flags
Flags defining which members are valid and to be used.
uint16 GetSubstituteID(uint16 entity_id) const
Gives the substitute of the entity, as specified by the grf file.
Dynamic data of a loaded NewGRF.
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
Method to find an entity ID and to mark it as reserved for the Industry to be included.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
PaletteID pal
The palette (use PAL_NONE) if not needed)
TileContext
Context for tile accesses.