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.
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user