MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetVehicleCannotUseStationReason

Function GetVehicleCannotUseStationReason

src/vehicle.cpp:3092–3136  ·  view source on GitHub ↗

* 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 The string explaining why the vehicle cannot use the station. */

Source from the content-addressed store, hash-verified

3090 * @return The string explaining why the vehicle cannot use the station.
3091 */
3092StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st)
3093{
3094 switch (v->type) {
3095 case VEH_TRAIN:
3096 return STR_ERROR_NO_RAIL_STATION;
3097
3098 case VEH_ROAD: {
3099 const RoadVehicle *rv = RoadVehicle::From(v);
3100 RoadStop *rs = st->GetPrimaryRoadStop(rv->IsBus() ? RoadStopType::Bus : RoadStopType::Truck);
3101
3102 StringID err = rv->IsBus() ? STR_ERROR_NO_BUS_STATION : STR_ERROR_NO_TRUCK_STATION;
3103
3104 for (; rs != nullptr; rs = rs->next) {
3105 /* Articulated vehicles cannot use bay road stops, only drive-through. Make sure the vehicle can actually use this bay stop */
3106 if (HasTileAnyRoadType(rs->xy, rv->compatible_roadtypes) && IsBayRoadStopTile(rs->xy) && rv->HasArticulatedPart()) {
3107 err = STR_ERROR_NO_STOP_ARTICULATED_VEHICLE;
3108 continue;
3109 }
3110
3111 /* Bay stop errors take precedence, but otherwise the vehicle may not be compatible with the roadtype/tramtype of this station tile.
3112 * We give bay stop errors precedence because they are usually a bus sent to a tram station or vice versa. */
3113 if (!HasTileAnyRoadType(rs->xy, rv->compatible_roadtypes) && err != STR_ERROR_NO_STOP_ARTICULATED_VEHICLE) {
3114 err = RoadTypeIsRoad(rv->roadtype) ? STR_ERROR_NO_STOP_COMPATIBLE_ROAD_TYPE : STR_ERROR_NO_STOP_COMPATIBLE_TRAM_TYPE;
3115 continue;
3116 }
3117 }
3118
3119 return err;
3120 }
3121
3122 case VEH_SHIP:
3123 return STR_ERROR_NO_DOCK;
3124
3125 case VEH_AIRCRAFT:
3126 if (!st->facilities.Test(StationFacility::Airport)) return STR_ERROR_NO_AIRPORT;
3127 if (v->GetEngine()->VehInfo<AircraftVehicleInfo>().subtype & AIR_CTOL) {
3128 return STR_ERROR_AIRPORT_NO_PLANES;
3129 } else {
3130 return STR_ERROR_AIRPORT_NO_HELICOPTERS;
3131 }
3132
3133 default:
3134 return INVALID_STRING_ID;
3135 }
3136}
3137
3138/**
3139 * Access the ground vehicle cache of the vehicle.

Callers 2

CmdInsertOrderFunction · 0.85
CmdCloneOrderFunction · 0.85

Calls 8

HasTileAnyRoadTypeFunction · 0.85
IsBayRoadStopTileFunction · 0.85
RoadTypeIsRoadFunction · 0.85
IsBusMethod · 0.80
HasArticulatedPartMethod · 0.80
TestMethod · 0.80
GetPrimaryRoadStopMethod · 0.45
GetEngineMethod · 0.45

Tested by

no test coverage detected