summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2010-07-16 19:02:59 +0000
committermichi_cc <michi_cc@openttd.org>2010-07-16 19:02:59 +0000
commit2a3ec78d9f35ad788dcaeab306f355d2e496c16d (patch)
tree07ff22d827fc7f060fda77149fda3b9afc979bd0 /src
parente809c05099b09bab8f23a4307e0088247478770c (diff)
downloadopenttd-2a3ec78d9f35ad788dcaeab306f355d2e496c16d.tar.xz
(svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_engine.cpp7
-rw-r--r--src/newgrf_railtype.cpp2
2 files changed, 8 insertions, 1 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 9b63ff6d9..e6f4105a7 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -26,6 +26,7 @@
#include "station_base.h"
#include "engine_base.h"
#include "company_base.h"
+#include "newgrf_railtype.h"
struct WagonOverride {
EngineID *train_id;
@@ -644,6 +645,12 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case 0x48: return Engine::Get(v->engine_type)->flags; // Vehicle Type Info
case 0x49: return v->build_year;
+ case 0x4A: {
+ if (v->type != VEH_TRAIN) return 0;
+ RailType rt = GetTileRailType(v->tile);
+ return (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) | GetReverseRailTypeTranslation(rt, object->grffile);
+ }
+
/* Variables which use the parameter */
case 0x60: // Count consist's engine ID occurance
//EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter);
diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp
index 114f31b7c..a0d66ec03 100644
--- a/src/newgrf_railtype.cpp
+++ b/src/newgrf_railtype.cpp
@@ -110,7 +110,7 @@ SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSp
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
{
/* No rail type table present, return rail type as-is */
- if (grffile->railtype_max == 0) return railtype;
+ if (grffile == NULL || grffile->railtype_max == 0) return railtype;
/* Look for a matching rail type label in the table */
RailTypeLabel label = GetRailTypeInfo(railtype)->label;