OpenTTD Source: src/newgrf_roadtype.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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
30 RoadTypeScopeResolver(ResolverObject &ro, const RoadTypeInfo *rti, TileIndex tile, TileContext context)
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
40 struct RoadTypeResolverObject : public ResolverObject {
41 RoadTypeScopeResolver roadtype_scope;
42
43 RoadTypeResolverObject(const RoadTypeInfo *rti, TileIndex tile, TileContext context, RoadTypeSpriteGroup 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->roadtype_scope;
49 default: return ResolverObject::GetScope(scope, relative);
50 }
51 }
52
53 GrfSpecFeature GetFeature() const override;
54 uint32_t GetDebugID() const override;
55};
56
57 SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context = TCX_NORMAL, uint *num_results = nullptr);
58
59 RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8_t tracktype, const GRFFile *grffile);
60uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile);
61
62uint32_t GetTrackTypes(TileIndex tile, const GRFFile *grffile);
63
64void ConvertRoadTypes();
65void SetCurrentRoadTypeLabelList();
66void ClearRoadTypeLabelList();
67
68#endif /* NEWGRF_ROADTYPE_H */
RoadTypeInfo
Definition road.h:52
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
newgrf_commons.h
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
TileContext
TileContext
Context for tile accesses.
Definition newgrf_commons.h:24
TCX_NORMAL
@ TCX_NORMAL
Nothing special.
Definition newgrf_commons.h:25
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:149
SetCurrentRoadTypeLabelList
void SetCurrentRoadTypeLabelList()
Populate road type label list with current values.
Definition newgrf_roadtype.cpp:270
ConvertRoadTypes
void ConvertRoadTypes()
Test if any saved road type labels are different to the currently loaded road types.
Definition newgrf_roadtype.cpp:225
GetReverseRoadTypeTranslation
uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
Definition newgrf_roadtype.cpp:201
GetTrackTypes
uint32_t GetTrackTypes(TileIndex tile, const GRFFile *grffile)
Variable 0x45 of road-/tram-/rail-types to query track types on a tile.
Definition newgrf_roadtype.cpp:34
GetRoadTypeTranslation
RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8_t tracktype, const GRFFile *grffile)
Translate an index to the GRF-local road/tramtype-translation table into a RoadType.
Definition newgrf_roadtype.cpp:171
newgrf_spritegroup.h
Action 2 handling.
VarSpriteGroupScope
VarSpriteGroupScope
Definition newgrf_spritegroup.h:82
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition newgrf_spritegroup.h:85
road.h
Road specific functions.
RoadTypeSpriteGroup
RoadTypeSpriteGroup
Sprite groups for a roadtype.
Definition road.h:36
RoadTramType
RoadTramType
The different types of road type.
Definition road_type.h:37
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
Definition newgrf_spritegroup.cpp:133
RoadTypeResolverObject
Resolver object for road types.
Definition newgrf_roadtype.h:40
RoadTypeResolverObject::roadtype_scope
RoadTypeScopeResolver roadtype_scope
Resolver for the roadtype scope.
Definition newgrf_roadtype.h:41
RoadTypeResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_roadtype.cpp:120
RoadTypeResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
Definition newgrf_roadtype.h:45
RoadTypeResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_roadtype.cpp:110
RoadTypeScopeResolver
Resolver for the railtype scope.
Definition newgrf_roadtype.h:18
RoadTypeScopeResolver::context
TileContext context
Are we resolving sprites for the upper halftile, or on a bridge?
Definition newgrf_roadtype.h:20
RoadTypeScopeResolver::RoadTypeScopeResolver
RoadTypeScopeResolver(ResolverObject &ro, const RoadTypeInfo *rti, TileIndex tile, TileContext context)
Constructor of the roadtype scope resolvers.
Definition newgrf_roadtype.h:30
RoadTypeScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
Definition newgrf_roadtype.cpp:62
RoadTypeScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_roadtype.cpp:56
RoadTypeScopeResolver::tile
TileIndex tile
Tracktile. For track on a bridge this is the southern bridgehead.
Definition newgrf_roadtype.h:19
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition newgrf_spritegroup.h:269
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:270
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >