1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

Codechange: Make GetRail/RoadTypeInfoIndex() a member method.

This follows a similar pattern used for cargoes, houses and objects.

Also fixes incorrect documentation of GetRoadTypeInfoIndex().
This commit is contained in:
Peter Nelson
2025-09-09 18:00:54 +01:00
committed by Peter Nelson
parent 5ed8f1203b
commit 126669e10d
6 changed files with 30 additions and 28 deletions

View File

@@ -35,7 +35,7 @@
case 0x43: return TimerGameCalendar::date.base();
case 0x44: return to_underlying(HouseZone::TownEdge);
case 0x45: {
auto rt = GetRailTypeInfoIndex(this->rti);
RailType rt = this->rti->Index();
uint8_t local = GetReverseRailTypeTranslation(rt, this->ro.grffile);
if (local == 0xFF) local = 0xFE;
return 0xFFFF | local << 16;

View File

@@ -69,7 +69,7 @@ uint32_t GetTrackTypes(TileIndex tile, const GRFFile *grffile)
case 0x43: return TimerGameCalendar::date.base();
case 0x44: return to_underlying(HouseZone::TownEdge);
case 0x45: {
auto rt = GetRoadTypeInfoIndex(this->rti);
RoadType rt = this->rti->Index();
uint8_t local = GetReverseRoadTypeTranslation(rt, this->ro.grffile);
if (local == 0xFF) local = 0xFE;
if (RoadTypeIsRoad(rt)) {

View File

@@ -19,6 +19,18 @@
#include "safeguards.h"
/**
* Get the RailType for this RailTypeInfo.
* @return RailType in static RailTypeInfo definitions.
*/
RailType RailTypeInfo::Index() const
{
extern RailTypeInfo _railtypes[RAILTYPE_END];
size_t index = this - _railtypes;
assert(index < RAILTYPE_END);
return static_cast<RailType>(index);
}
/**
* Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
*/

View File

@@ -286,6 +286,8 @@ public:
{
return 82 * this->fallback_railtype;
}
RailType Index() const;
};
@@ -301,19 +303,6 @@ inline const RailTypeInfo *GetRailTypeInfo(RailType railtype)
return &_railtypes[railtype];
}
/**
* Returns the railtype for a Railtype information.
* @param rti Pointer to static RailTypeInfo
* @return Railtype in static railtype definitions
*/
inline RailType GetRailTypeInfoIndex(const RailTypeInfo *rti)
{
extern RailTypeInfo _railtypes[RAILTYPE_END];
size_t index = rti - _railtypes;
assert(index < RAILTYPE_END && rti == _railtypes + index);
return static_cast<RailType>(index);
}
/**
* Returns all compatible railtypes for a set of railtypes.
* @param railtypes Set of railtypes to get the compatible railtypes from.

View File

@@ -23,6 +23,18 @@
#include "safeguards.h"
/**
* Get the RoadType for this RoadTypeInfo.
* @return RoadType in static RoadTypeInfo definitions.
*/
RoadType RoadTypeInfo::Index() const
{
extern RoadTypeInfo _roadtypes[ROADTYPE_END];
size_t index = this - _roadtypes;
assert(index < ROADTYPE_END);
return static_cast<RoadType>(index);
}
/**
* Return if the tile is a valid tile for a crossing.
*

View File

@@ -185,6 +185,8 @@ public:
{
return this->group[ROTSG_GROUND] != nullptr;
}
RoadType Index() const;
};
/**
@@ -231,19 +233,6 @@ inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
return &_roadtypes[roadtype];
}
/**
* Returns the railtype for a Railtype information.
* @param rti Pointer to static RailTypeInfo
* @return Railtype in static railtype definitions
*/
inline RoadType GetRoadTypeInfoIndex(const RoadTypeInfo *rti)
{
extern RoadTypeInfo _roadtypes[ROADTYPE_END];
size_t index = rti - _roadtypes;
assert(index < ROADTYPE_END && rti == _roadtypes + index);
return static_cast<RoadType>(index);
}
/**
* Checks if an engine of the given RoadType got power on a tile with a given
* RoadType. This would normally just be an equality check, but for electrified