summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-27 22:44:39 +0000
committerbjarni <bjarni@openttd.org>2006-09-27 22:44:39 +0000
commit2579b68e34648c2e6ad27af133def17580c6334f (patch)
tree4c0ea810ffccd3059e9cb23c9f3a2a00d2ec033a /vehicle.c
parent64fa9a54e09bff801c467c73943ad9737c4ae2f9 (diff)
downloadopenttd-2579b68e34648c2e6ad27af133def17580c6334f.tar.xz
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
It's right below the sell button (sell whole chain button for trains) It's still missing a sprite. That one will be added as soon as anybody draws something we can use To make room for this button, all depots except train depots now opens with an additional row and can't be resized shorter than that
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/vehicle.c b/vehicle.c
index 760ff64f2..638fdec7a 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1626,6 +1626,58 @@ int32 CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
return return_value;
}
+/** Sells all vehicles in a depot
+* @param tile Tile of the depot where the depot is
+* @param p1 Vehicle type
+* @param p2 unused
+*/
+int32 CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+ Vehicle **engines = NULL;
+ Vehicle **wagons = NULL;
+ uint16 engine_list_length = 0;
+ uint16 engine_count = 0;
+ uint16 wagon_list_length = 0;
+ uint16 wagon_count = 0;
+
+ int32 cost = 0;
+ uint i, sell_command, total_number_vehicles;
+ byte vehicle_type = GB(p1, 0, 8);
+
+ switch (vehicle_type) {
+ case VEH_Train: sell_command = CMD_SELL_RAIL_WAGON; break;
+ case VEH_Road: sell_command = CMD_SELL_ROAD_VEH; break;
+ case VEH_Ship: sell_command = CMD_SELL_SHIP; break;
+ case VEH_Aircraft: sell_command = CMD_SELL_AIRCRAFT; break;
+ default: return CMD_ERROR;
+ }
+
+ /* Get the list of vehicles in the depot */
+ BuildDepotVehicleList(vehicle_type, tile, &engines, &engine_list_length, &engine_count,
+ &wagons, &wagon_list_length, &wagon_count);
+
+ total_number_vehicles = engine_count + wagon_count;
+ for (i = 0; i < total_number_vehicles; i++) {
+ const Vehicle *v;
+ int32 ret;
+
+ if (i < engine_count) {
+ v = engines[i];
+ } else {
+ v = wagons[i - engine_count];
+ }
+
+ ret = DoCommand(tile, v->index, 1, flags, sell_command);
+
+ if (!CmdFailed(ret)) cost += ret;
+ }
+
+ free(engines);
+ free(wagons);
+ if (cost == 0) return CMD_ERROR; // no vehicles to sell
+ return cost;
+}
+
/** Clone a vehicle. If it is a train, it will clone all the cars too
* @param tile tile of the depot where the cloned vehicle is build
* @param p1 the original vehicle's index