Show specific reason why vehicle cannot be ordered to a particular station
This commit is contained in:
@@ -4338,6 +4338,55 @@ bool CanVehicleUseStation(const Vehicle *v, const Station *st)
|
||||
return CanVehicleUseStation(v->engine_type, st);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reason string why this station can't be used by the given vehicle
|
||||
* @param v the vehicle to test
|
||||
* @param st the station to test for
|
||||
* @return true if and only if the vehicle can use this station.
|
||||
*/
|
||||
StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st)
|
||||
{
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN:
|
||||
return STR_ERROR_NO_RAIL_STATION;
|
||||
|
||||
case VEH_ROAD: {
|
||||
const RoadVehicle *rv = RoadVehicle::From(v);
|
||||
RoadStop *rs = st->GetPrimaryRoadStop(rv->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK);
|
||||
|
||||
StringID err = rv->IsBus() ? STR_ERROR_NO_BUS_STATION : STR_ERROR_NO_TRUCK_STATION;
|
||||
|
||||
for (; rs != nullptr; rs = rs->next) {
|
||||
/* The vehicle is articulated and can therefore not go to a standard road stop. */
|
||||
if (IsStandardRoadStopTile(rs->xy) && rv->HasArticulatedPart()) {
|
||||
err = STR_ERROR_NO_STOP_ARTIC_VEH;
|
||||
continue;
|
||||
}
|
||||
/* The vehicle cannot go to this roadstop (different roadtype) */
|
||||
if (!HasTileAnyRoadType(rs->xy, rv->compatible_roadtypes)) return STR_ERROR_NO_STOP_COMPATIBLE_ROAD_TYPE;
|
||||
|
||||
return INVALID_STRING_ID;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
case VEH_SHIP:
|
||||
return STR_ERROR_NO_DOCK;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
if ((st->facilities & FACIL_AIRPORT) == 0) return STR_ERROR_NO_AIRPORT;
|
||||
if (v->GetEngine()->u.air.subtype & AIR_CTOL) {
|
||||
return STR_ERROR_AIRPORT_NO_PLANES;
|
||||
} else {
|
||||
return STR_ERROR_AIRPORT_NO_HELIS;
|
||||
}
|
||||
|
||||
default:
|
||||
return INVALID_STRING_ID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the ground vehicle cache of the vehicle.
|
||||
* @pre The vehicle is a #GroundVehicle.
|
||||
|
Reference in New Issue
Block a user