mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-10 15:02:06 +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:
committed by
Peter Nelson
parent
5ed8f1203b
commit
126669e10d
@@ -35,7 +35,7 @@
|
|||||||
case 0x43: return TimerGameCalendar::date.base();
|
case 0x43: return TimerGameCalendar::date.base();
|
||||||
case 0x44: return to_underlying(HouseZone::TownEdge);
|
case 0x44: return to_underlying(HouseZone::TownEdge);
|
||||||
case 0x45: {
|
case 0x45: {
|
||||||
auto rt = GetRailTypeInfoIndex(this->rti);
|
RailType rt = this->rti->Index();
|
||||||
uint8_t local = GetReverseRailTypeTranslation(rt, this->ro.grffile);
|
uint8_t local = GetReverseRailTypeTranslation(rt, this->ro.grffile);
|
||||||
if (local == 0xFF) local = 0xFE;
|
if (local == 0xFF) local = 0xFE;
|
||||||
return 0xFFFF | local << 16;
|
return 0xFFFF | local << 16;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ uint32_t GetTrackTypes(TileIndex tile, const GRFFile *grffile)
|
|||||||
case 0x43: return TimerGameCalendar::date.base();
|
case 0x43: return TimerGameCalendar::date.base();
|
||||||
case 0x44: return to_underlying(HouseZone::TownEdge);
|
case 0x44: return to_underlying(HouseZone::TownEdge);
|
||||||
case 0x45: {
|
case 0x45: {
|
||||||
auto rt = GetRoadTypeInfoIndex(this->rti);
|
RoadType rt = this->rti->Index();
|
||||||
uint8_t local = GetReverseRoadTypeTranslation(rt, this->ro.grffile);
|
uint8_t local = GetReverseRoadTypeTranslation(rt, this->ro.grffile);
|
||||||
if (local == 0xFF) local = 0xFE;
|
if (local == 0xFF) local = 0xFE;
|
||||||
if (RoadTypeIsRoad(rt)) {
|
if (RoadTypeIsRoad(rt)) {
|
||||||
|
|||||||
12
src/rail.cpp
12
src/rail.cpp
@@ -19,6 +19,18 @@
|
|||||||
|
|
||||||
#include "safeguards.h"
|
#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.
|
* Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
|
||||||
*/
|
*/
|
||||||
|
|||||||
15
src/rail.h
15
src/rail.h
@@ -286,6 +286,8 @@ public:
|
|||||||
{
|
{
|
||||||
return 82 * this->fallback_railtype;
|
return 82 * this->fallback_railtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RailType Index() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -301,19 +303,6 @@ inline const RailTypeInfo *GetRailTypeInfo(RailType railtype)
|
|||||||
return &_railtypes[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.
|
* Returns all compatible railtypes for a set of railtypes.
|
||||||
* @param railtypes Set of railtypes to get the compatible railtypes from.
|
* @param railtypes Set of railtypes to get the compatible railtypes from.
|
||||||
|
|||||||
12
src/road.cpp
12
src/road.cpp
@@ -23,6 +23,18 @@
|
|||||||
|
|
||||||
#include "safeguards.h"
|
#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.
|
* Return if the tile is a valid tile for a crossing.
|
||||||
*
|
*
|
||||||
|
|||||||
15
src/road.h
15
src/road.h
@@ -185,6 +185,8 @@ public:
|
|||||||
{
|
{
|
||||||
return this->group[ROTSG_GROUND] != nullptr;
|
return this->group[ROTSG_GROUND] != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RoadType Index() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,19 +233,6 @@ inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
|
|||||||
return &_roadtypes[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
|
* 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
|
* RoadType. This would normally just be an equality check, but for electrified
|
||||||
|
|||||||
Reference in New Issue
Block a user