OpenTTD Source: src/newgrf_railtype.h Source File

OpenTTD Source 12.0-beta1

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 <http://www.gnu.org/licenses/>.
6 */
7
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
18 struct RailTypeScopeResolver : public ScopeResolver {
19 TileIndex tile;
20 TileContext context;
21 const RailtypeInfo *rti;
22
29 RailTypeScopeResolver(ResolverObject &ro, const RailtypeInfo *rti, TileIndex tile, TileContext context)
30 : ScopeResolver(ro), tile(tile), context(context), rti(rti)
31 {
32 }
33
34 uint32 GetRandomBits() const override;
35 uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
36 };
37
39 struct RailTypeResolverObject : public ResolverObject {
40 RailTypeScopeResolver railtype_scope;
41
42 RailTypeResolverObject(const RailtypeInfo *rti, TileIndex tile, TileContext context, RailTypeSpriteGroup rtsg, uint32 param1 = 0, uint32 param2 = 0);
43
44 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
45 {
46 switch (scope) {
47 case VSG_SCOPE_SELF: return &this->railtype_scope;
48 default: return ResolverObject::GetScope(scope, relative);
49 }
50 }
51
52 GrfSpecFeature GetFeature() const override;
53 uint32 GetDebugID() const override;
54 };
55
56 SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context = TCX_NORMAL, uint *num_results = nullptr);
57 SpriteID GetCustomSignalSprite(const RailtypeInfo *rti, TileIndex tile, SignalType type, SignalVariant var, SignalState state, bool gui = false);
58
59 RailType GetRailTypeTranslation(uint8 railtype, const GRFFile *grffile);
60 uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile);
61
62 #endif /* NEWGRF_RAILTYPE_H */
GetRailTypeTranslation
RailType GetRailTypeTranslation(uint8 railtype, const GRFFile *grffile)
Translate an index to the GRF-local railtype-translation table into a RailType.
Definition: newgrf_railtype.cpp:140
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:97
RailTypeScopeResolver::context
TileContext context
Are we resolving sprites for the upper halftile, or on a bridge?
Definition: newgrf_railtype.h:20
RailTypeResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_railtype.h:44
newgrf_commons.h
RailTypeScopeResolver::GetRandomBits
uint32 GetRandomBits() const override
Get a few random bits.
Definition: newgrf_railtype.cpp:19
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
RailtypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
SignalState
SignalState
These are states in which a signal can be.
Definition: signal_type.h:44
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:288
RailTypeSpriteGroup
RailTypeSpriteGroup
Sprite groups for a railtype.
Definition: rail.h:46
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:100
SignalType
SignalType
Type of signal, i.e.
Definition: signal_type.h:23
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
GetCustomSignalSprite
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.
Definition: newgrf_railtype.cpp:120
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
RailTypeScopeResolver
Resolver for the railtype scope.
Definition: newgrf_railtype.h:18
TileContext
TileContext
Context for tile accesses.
Definition: newgrf_commons.h:24
RailTypeResolverObject::GetDebugID
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_railtype.cpp:66
TCX_NORMAL
@ TCX_NORMAL
Nothing special.
Definition: newgrf_commons.h:25
rail.h
RailTypeScopeResolver::tile
TileIndex tile
Tracktile. For track on a bridge this is the southern bridgehead.
Definition: newgrf_railtype.h:19
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:139
RailTypeScopeResolver::RailTypeScopeResolver
RailTypeScopeResolver(ResolverObject &ro, const RailtypeInfo *rti, TileIndex tile, TileContext context)
Constructor of the railtype scope resolvers.
Definition: newgrf_railtype.h:29
RailTypeScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
Definition: newgrf_railtype.cpp:25
RailTypeResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_railtype.cpp:61
RailTypeResolverObject::RailTypeResolverObject
RailTypeResolverObject(const RailtypeInfo *rti, TileIndex tile, TileContext context, RailTypeSpriteGroup rtsg, uint32 param1=0, uint32 param2=0)
Resolver object for rail types.
Definition: newgrf_railtype.cpp:80
newgrf_spritegroup.h
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
SignalVariant
SignalVariant
Variant of the signal, i.e.
Definition: signal_type.h:16
GetCustomRailSprite
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.
Definition: newgrf_railtype.cpp:95
RailTypeResolverObject
Resolver object for rail types.
Definition: newgrf_railtype.h:39
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
GetReverseRailTypeTranslation
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
Definition: newgrf_railtype.cpp:162
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
RailTypeResolverObject::railtype_scope
RailTypeScopeResolver railtype_scope
Resolver for the railtype scope.
Definition: newgrf_railtype.h:40