OpenTTD Source: src/newgrf_roadtype.h Source File

OpenTTD Source 1.11.0-RC1

newgrf_roadtype.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_ROADTYPE_H
11 #define NEWGRF_ROADTYPE_H
12
13 #include "road.h"
14 #include "newgrf_commons.h"
15 #include "newgrf_spritegroup.h"
16
18 struct RoadTypeScopeResolver : public ScopeResolver {
19 TileIndex tile;
20 TileContext context;
21 const RoadTypeInfo *rti;
22
23 RoadTypeScopeResolver(ResolverObject &ro, const RoadTypeInfo *rti, TileIndex tile, TileContext context);
24
25 /* virtual */ uint32 GetRandomBits() const;
26 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
27 };
28
30 struct RoadTypeResolverObject : public ResolverObject {
31 RoadTypeScopeResolver roadtype_scope;
32
33 RoadTypeResolverObject(const RoadTypeInfo *rti, TileIndex tile, TileContext context, RoadTypeSpriteGroup rtsg, uint32 param1 = 0, uint32 param2 = 0);
34
35 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
36 {
37 switch (scope) {
38 case VSG_SCOPE_SELF: return &this->roadtype_scope;
39 default: return ResolverObject::GetScope(scope, relative);
40 }
41 }
42
43 const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
44
45 GrfSpecFeature GetFeature() const override;
46 uint32 GetDebugID() const override;
47 };
48
49 SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context = TCX_NORMAL, uint *num_results = nullptr);
50
51 RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8 tracktype, const GRFFile *grffile);
52 uint8 GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile);
53
54 #endif /* NEWGRF_ROADTYPE_H */
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:100
RoadTypeInfo
Definition: road.h:75
newgrf_commons.h
RoadTypeScopeResolver::RoadTypeScopeResolver
RoadTypeScopeResolver(ResolverObject &ro, const RoadTypeInfo *rti, TileIndex tile, TileContext context)
Constructor of the roadtype scope resolvers.
Definition: newgrf_roadtype.cpp:89
RoadTypeResolverObject::RoadTypeResolverObject
RoadTypeResolverObject(const RoadTypeInfo *rti, TileIndex tile, TileContext context, RoadTypeSpriteGroup rtsg, uint32 param1=0, uint32 param2=0)
Resolver object for road types.
Definition: newgrf_roadtype.cpp:105
RoadTypeScopeResolver::context
TileContext context
Are we resolving sprites for the upper halftile, or on a bridge?
Definition: newgrf_roadtype.h:20
GetRoadTypeTranslation
RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8 tracktype, const GRFFile *grffile)
Translate an index to the GRF-local road/tramtype-translation table into a RoadType.
Definition: newgrf_roadtype.cpp:142
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:315
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:296
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:103
RoadTypeResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_roadtype.h:35
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
RoadTypeSpriteGroup
RoadTypeSpriteGroup
Sprite groups for a roadtype.
Definition: road.h:57
RoadTypeResolverObject::ResolveReal
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
Definition: newgrf_roadtype.cpp:61
RoadTypeScopeResolver
Resolver for the railtype scope.
Definition: newgrf_roadtype.h:18
TileContext
TileContext
Context for tile accesses.
Definition: newgrf_commons.h:24
RoadTypeResolverObject::GetDebugID
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_roadtype.cpp:78
TCX_NORMAL
@ TCX_NORMAL
Nothing special.
Definition: newgrf_commons.h:25
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:153
road.h
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
GetReverseRoadTypeTranslation
uint8 GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
Definition: newgrf_roadtype.cpp:172
newgrf_spritegroup.h
RoadTypeResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_roadtype.cpp:68
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
RoadTypeResolverObject
Resolver object for road types.
Definition: newgrf_roadtype.h:30
RealSpriteGroup
Definition: newgrf_spritegroup.h:79
RoadTypeScopeResolver::tile
TileIndex tile
Tracktile. For track on a bridge this is the southern bridgehead.
Definition: newgrf_roadtype.h:19
RoadTypeResolverObject::roadtype_scope
RoadTypeScopeResolver roadtype_scope
Resolver for the roadtype scope.
Definition: newgrf_roadtype.h:31
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:297
SpriteGroup
Definition: newgrf_spritegroup.h:57
GetCustomRoadSprite
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context=TCX_NORMAL, uint *num_results=nullptr)
Get the sprite to draw for the given tile.
Definition: newgrf_roadtype.cpp:120
RoadTypeScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Definition: newgrf_roadtype.cpp:25
RoadTypeScopeResolver::GetRandomBits
uint32 GetRandomBits() const
Get a few random bits.
Definition: newgrf_roadtype.cpp:19
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105