diff options
author | frosch <frosch@openttd.org> | 2010-04-17 14:47:56 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-04-17 14:47:56 +0000 |
commit | 5ecf2f7f8cb157d959c42b3396398f03d3f3fffb (patch) | |
tree | 28e2ecc16925389891a8adb0a05806f6f56e661c | |
parent | 2a5ddd0daea6e20c2c3de9e46ee0a0fe9973b502 (diff) | |
download | openttd-5ecf2f7f8cb157d959c42b3396398f03d3f3fffb.tar.xz |
(svn r19656) -Codechange/Fix: Report back if invalid vehicle lists are requested.
-rw-r--r-- | src/vehicle_cmd.cpp | 4 | ||||
-rw-r--r-- | src/vehiclelist.cpp | 11 | ||||
-rw-r--r-- | src/vehiclelist.h | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 1d3963162..6a72fbbff 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -144,7 +144,7 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 uint32 id = p1; uint16 window_type = p2 & VLW_MASK; - GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type); + if (!GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type)) return CMD_ERROR; } else { /* Get the list of vehicles in the depot */ BuildDepotVehicleList(vehicle_type, tile, &list, NULL); @@ -596,7 +596,7 @@ CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool s { VehicleList list; - GenerateVehicleSortList(&list, type, owner, id, vlw_flag); + if (!GenerateVehicleSortList(&list, type, owner, id, vlw_flag)) return CMD_ERROR; /* Send all the vehicles to a depot */ bool had_success = false; diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 848fba1a9..ce312ff09 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -76,8 +76,9 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine * <li>VLW_WAYPOINT_LIST: index of waypoint to generate a list for</li> * </ul> * @param window_type The type of window the list is for, using the VLW_ flags in vehicle_gui.h + * @return false if invalid list is requested */ -void GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, uint32 index, uint16 window_type) +bool GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, uint32 index, uint16 window_type) { list->Clear(); @@ -101,7 +102,10 @@ void GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, u case VLW_SHARED_ORDERS: /* Add all vehicles from this vehicle's shared order list */ - for (v = Vehicle::Get(index); v != NULL; v = v->NextShared()) { + v = Vehicle::GetIfValid(index); + if (v == NULL || v->type != type || !v->IsPrimaryVehicle()) return false; + + for (; v != NULL; v = v->NextShared()) { *list->Append() = v; } break; @@ -153,8 +157,9 @@ void GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, u } break; - default: NOT_REACHED(); + default: return false; } list->Compact(); + return true; } diff --git a/src/vehiclelist.h b/src/vehiclelist.h index 04caccb5a..18357b941 100644 --- a/src/vehiclelist.h +++ b/src/vehiclelist.h @@ -19,7 +19,7 @@ typedef SmallVector<const Vehicle *, 32> VehicleList; -void GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, uint32 index, uint16 window_type); +bool GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, uint32 index, uint16 window_type); void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine_list, VehicleList *wagon_list, bool individual_wagons = false); #endif /* VEHICLELIST_H */ |