From ff922f41dafe6ecf8565e220f360233a29569a7a Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 21 Jun 2016 18:56:29 +0100 Subject: [PATCH] Fix NewGRF vehicle variables 4A, FE and FF crashing with virtual trains. This is due to attempts to look up the rail type of the current tile. --- src/newgrf_engine.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 4aafa10f9f..99d8c8cc9d 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -623,6 +623,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, case 0x4A: { if (v->type != VEH_TRAIN) return 0; + if (Train::From(v)->IsVirtual()) return 0x1FF; RailType rt = GetTileRailType(v->tile); return (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) | GetReverseRailTypeTranslation(rt, object->ro.grffile); } @@ -716,9 +717,14 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, const Train *t = Train::From(v); bool is_powered_wagon = HasBit(t->flags, VRF_POWEREDWAGON); const Train *u = is_powered_wagon ? t->First() : t; // for powered wagons the engine defines the type of engine (i.e. railtype) - RailType railtype = GetRailType(v->tile); bool powered = t->IsEngine() || is_powered_wagon; - bool has_power = HasPowerOnRail(u->railtype, railtype); + bool has_power; + if (u->IsVirtual()) { + has_power = true; + } else { + RailType railtype = GetRailType(v->tile); + has_power = HasPowerOnRail(u->railtype, railtype); + } if (powered && has_power) SetBit(modflags, 5); if (powered && !has_power) SetBit(modflags, 6);