OpenTTD Source 20260206-master-g4d4e37dbf1
newgrf_railtype.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NEWGRF_RAILTYPE_H
11#define NEWGRF_RAILTYPE_H
12
13#include "rail.h"
14#include "newgrf_commons.h"
15#include "newgrf_spritegroup.h"
16
18struct RailTypeScopeResolver : public ScopeResolver {
21 const RailTypeInfo *rti;
22
31 : ScopeResolver(ro), tile(tile), context(context), rti(rti)
32 {
33 }
34
35 uint32_t GetRandomBits() const override;
36 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
37};
38
42
43 RailTypeResolverObject(const RailTypeInfo *rti, TileIndex tile, TileContext context, RailTypeSpriteGroup rtsg, uint32_t param1 = 0, uint32_t param2 = 0);
44
45 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override
46 {
47 switch (scope) {
48 case VSG_SCOPE_SELF: return &this->railtype_scope;
49 default: return ResolverObject::GetScope(scope, relative);
50 }
51 }
52
53 GrfSpecFeature GetFeature() const override;
54 uint32_t GetDebugID() const override;
55};
56
57SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context = TCX_NORMAL, uint *num_results = nullptr);
58SpriteID GetCustomSignalSprite(const RailTypeInfo *rti, TileIndex tile, SignalType type, SignalVariant var, SignalState state, bool gui = false);
59
60RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile);
61uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile);
62
63void ConvertRailTypes();
65void ClearRailTypeLabelList();
66
67#endif /* NEWGRF_RAILTYPE_H */
This struct contains all the info that is needed to draw and construct tracks.
Definition rail.h:115
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
GrfSpecFeature
Definition newgrf.h:71
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
TileContext
Context for tile accesses.
@ TCX_NORMAL
Nothing special.
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context=TCX_NORMAL, uint *num_results=nullptr)
Get the sprite to draw for the given tile.
void ConvertRailTypes()
Test if any saved rail type labels are different to the currently loaded rail types.
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
void SetCurrentRailTypeLabelList()
Populate railtype label list with current values.
SpriteID GetCustomSignalSprite(const RailTypeInfo *rti, TileIndex tile, SignalType type, SignalVariant var, SignalState state, bool gui=false)
Get the sprite to draw for a given signal.
RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile)
Translate an index to the GRF-local railtype-translation table into a RailType.
Action 2 handling.
VarSpriteGroupScope
@ VSG_SCOPE_SELF
Resolved object itself.
Rail specific functions.
RailTypeSpriteGroup
Sprite groups for a railtype.
Definition rail.h:40
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
SignalType
Type of signal, i.e.
Definition signal_type.h:23
SignalState
These are states in which a signal can be.
Definition signal_type.h:42
SignalVariant
Variant of the signal, i.e.
Definition signal_type.h:16
Dynamic data of a loaded NewGRF.
Definition newgrf.h:117
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
RailTypeResolverObject(const RailTypeInfo *rti, TileIndex tile, TileContext context, RailTypeSpriteGroup rtsg, uint32_t param1=0, uint32_t param2=0)
Resolver object for rail types.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
RailTypeScopeResolver railtype_scope
Resolver for the railtype scope.
Resolver for the railtype scope.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
RailTypeScopeResolver(ResolverObject &ro, const RailTypeInfo *rti, TileIndex tile, TileContext context)
Constructor of the railtype scope resolvers.
TileContext context
Are we resolving sprites for the upper halftile, or on a bridge?
uint32_t GetRandomBits() const override
Get a few random bits.
TileIndex tile
Tracktile. For track on a bridge this is the southern bridgehead.
Interface for SpriteGroup-s to access the gamestate.
ResolverObject(const GRFFile *grffile, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Resolver constructor.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
ResolverObject & ro
Surrounding resolver object.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92