mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21663) -Add: [NoAI]: AIRail::GetName() to get the name of a railtype
This commit is contained in:
parent
c986325763
commit
5b25e620dd
|
@ -1028,6 +1028,7 @@ function Regression::RailTypeList()
|
||||||
print(" ListDump:");
|
print(" ListDump:");
|
||||||
for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
|
for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
|
||||||
print(" RailType: " + i);
|
print(" RailType: " + i);
|
||||||
|
print(" GetName(): " + AIRail.GetName(i));
|
||||||
print(" IsRailTypeAvailable(): " + AIRail.IsRailTypeAvailable(i));
|
print(" IsRailTypeAvailable(): " + AIRail.IsRailTypeAvailable(i));
|
||||||
print(" GetMaxSpeed(): " + AIRail.GetMaxSpeed(i));
|
print(" GetMaxSpeed(): " + AIRail.GetMaxSpeed(i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7209,6 +7209,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
|
||||||
Count(): 1
|
Count(): 1
|
||||||
ListDump:
|
ListDump:
|
||||||
RailType: 0
|
RailType: 0
|
||||||
|
GetName(): Railway construction
|
||||||
IsRailTypeAvailable(): true
|
IsRailTypeAvailable(): true
|
||||||
GetMaxSpeed(): 0
|
GetMaxSpeed(): 0
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* \li AIIndustryType::INDUSTRYTYPE_TOWN
|
* \li AIIndustryType::INDUSTRYTYPE_TOWN
|
||||||
* \li AIIndustryType::INDUSTRYTYPE_UNKNOWN
|
* \li AIIndustryType::INDUSTRYTYPE_UNKNOWN
|
||||||
* \li AIOrder::IsVoidOrder
|
* \li AIOrder::IsVoidOrder
|
||||||
|
* \li AIRail::GetName
|
||||||
* \li AITown::IsCity
|
* \li AITown::IsCity
|
||||||
*
|
*
|
||||||
* API removals:
|
* API removals:
|
||||||
|
|
|
@ -19,6 +19,18 @@
|
||||||
#include "../../newgrf.h"
|
#include "../../newgrf.h"
|
||||||
#include "../../newgrf_generic.h"
|
#include "../../newgrf_generic.h"
|
||||||
#include "../../newgrf_station.h"
|
#include "../../newgrf_station.h"
|
||||||
|
#include "../../strings_func.h"
|
||||||
|
|
||||||
|
/* static */ char *AIRail::GetName(RailType rail_type)
|
||||||
|
{
|
||||||
|
if (!IsRailTypeAvailable(rail_type)) return NULL;
|
||||||
|
|
||||||
|
static const int len = 64;
|
||||||
|
char *railtype_name = MallocT<char>(len);
|
||||||
|
|
||||||
|
::GetString(railtype_name, GetRailTypeInfo((::RailType)rail_type)->strings.menu_text, &railtype_name[len - 1]);
|
||||||
|
return railtype_name;
|
||||||
|
}
|
||||||
|
|
||||||
/* static */ bool AIRail::IsRailTile(TileIndex tile)
|
/* static */ bool AIRail::IsRailTile(TileIndex tile)
|
||||||
{
|
{
|
||||||
|
|
|
@ -96,6 +96,18 @@ public:
|
||||||
BT_WAYPOINT, ///< Build a rail waypoint
|
BT_WAYPOINT, ///< Build a rail waypoint
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of a rail type.
|
||||||
|
* @param rail_type The rail type to get the name of.
|
||||||
|
* @pre IsRailTypeAvailable(rail_type).
|
||||||
|
* @return The name the rail type has.
|
||||||
|
* @note Since there is no string with only the name of the track, the text which
|
||||||
|
* is shown in the dropdown where you can chose a track type is returned. This
|
||||||
|
* means that the name could be something like "Maglev construction" instead
|
||||||
|
* of just "Maglev".
|
||||||
|
*/
|
||||||
|
static char *GetName(RailType rail_type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given tile is actually a tile with rail that can be
|
* Checks whether the given tile is actually a tile with rail that can be
|
||||||
* used to traverse a tile. This excludes rail depots but includes
|
* used to traverse a tile. This excludes rail depots but includes
|
||||||
|
|
|
@ -79,6 +79,7 @@ void SQAIRail_Register(Squirrel *engine)
|
||||||
AIError::RegisterErrorMapString(AIRail::ERR_NONUNIFORM_STATIONS_DISABLED, "ERR_NONUNIFORM_STATIONS_DISABLED");
|
AIError::RegisterErrorMapString(AIRail::ERR_NONUNIFORM_STATIONS_DISABLED, "ERR_NONUNIFORM_STATIONS_DISABLED");
|
||||||
AIError::RegisterErrorMapString(AIRail::ERR_RAILTYPE_DISALLOWS_CROSSING, "ERR_RAILTYPE_DISALLOWS_CROSSING");
|
AIError::RegisterErrorMapString(AIRail::ERR_RAILTYPE_DISALLOWS_CROSSING, "ERR_RAILTYPE_DISALLOWS_CROSSING");
|
||||||
|
|
||||||
|
SQAIRail.DefSQStaticMethod(engine, &AIRail::GetName, "GetName", 2, ".i");
|
||||||
SQAIRail.DefSQStaticMethod(engine, &AIRail::IsRailTile, "IsRailTile", 2, ".i");
|
SQAIRail.DefSQStaticMethod(engine, &AIRail::IsRailTile, "IsRailTile", 2, ".i");
|
||||||
SQAIRail.DefSQStaticMethod(engine, &AIRail::IsLevelCrossingTile, "IsLevelCrossingTile", 2, ".i");
|
SQAIRail.DefSQStaticMethod(engine, &AIRail::IsLevelCrossingTile, "IsLevelCrossingTile", 2, ".i");
|
||||||
SQAIRail.DefSQStaticMethod(engine, &AIRail::IsRailDepotTile, "IsRailDepotTile", 2, ".i");
|
SQAIRail.DefSQStaticMethod(engine, &AIRail::IsRailDepotTile, "IsRailDepotTile", 2, ".i");
|
||||||
|
|
Loading…
Reference in New Issue