summaryrefslogtreecommitdiff
path: root/train_cmd.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-01 10:24:15 +0000
committerbjarni <bjarni@openttd.org>2006-09-01 10:24:15 +0000
commitd7e1d08d53d7d9885c747d7e1095d607f8f5cebe (patch)
treee86a7aeb29a672f565ab4b7aa38c5cb4a0010e93 /train_cmd.c
parent7d3685a8ad0661c43dda4deb8c2559226b3370fe (diff)
downloadopenttd-d7e1d08d53d7d9885c747d7e1095d607f8f5cebe.tar.xz
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
-Codechange: unified the code for mass goto depot to avoid duplicated code -Fix: Vehicles already on the way to depots will not be cancelled by mass goto depot (made it really hard to send all vehicles at once)
Diffstat (limited to 'train_cmd.c')
-rw-r--r--train_cmd.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/train_cmd.c b/train_cmd.c
index 3cc5521a3..603142ca4 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1925,32 +1925,31 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v, int max_distance)
* @param tile unused
* @param p1 train to send to the depot
* @param p2 various bitmasked elements
- * - p2 bit 0 - if bit 0 is set, then the train will only service at the depot. 0 Makes it stop inside
- * - p2 bit 1 - send all of shared orders to depot
+ * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
+ * - p2 bit 8-10 - VLW flag (for mass goto depot)
*/
int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Vehicle *v;
TrainFindDepotData tfdd;
- const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
- if (HASBIT(p2, 1) && (p2 & VLW_FLAGS) == VLW_STANDARD) {
- return SendAllVehiclesToDepot(VEH_Train, flags, HASBIT(p2, 0), _current_player);
+ if (p2 & DEPOT_MASS_SEND) {
+ /* Mass goto depot requested */
+ if (!ValidVLWFlags(p2 & VLW_FLAGS)) return CMD_ERROR;
+ return SendAllVehiclesToDepot(VEH_Train, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_FLAGS), p1);
}
- if (!IsValidVehicleID(p1)) return return_value;
+ if (!IsValidVehicleID(p1)) return CMD_ERROR;
v = GetVehicle(p1);
- if (v->type != VEH_Train || !CheckOwnership(v->owner)) return return_value;
-
- if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendTrainToDepot(tile, flags, v->next_shared->index, p2);
+ if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
- if (v->vehstatus & VS_CRASHED) return return_value;
+ if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
if (v->current_order.type == OT_GOTO_DEPOT) {
+ if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
if (flags & DC_EXEC) {
- if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not turn goto depot orders off
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
v->u.rail.days_since_order_progr = 0;
v->cur_order_index++;
@@ -1964,16 +1963,13 @@ int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
tfdd = FindClosestTrainDepot(v, 0);
- if (tfdd.best_length == (uint)-1) {
- if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not return error
- return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO);
- }
+ if (tfdd.best_length == (uint)-1) return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO);
if (flags & DC_EXEC) {
v->dest_tile = tfdd.tile;
v->current_order.type = OT_GOTO_DEPOT;
v->current_order.flags = OF_NON_STOP;
- if (!HASBIT(p2,0)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
+ if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
v->current_order.dest.depot = GetDepotByTile(tfdd.tile)->index;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
/* If there is no depot in front, reverse automatically */