(svn r6229) -Feature: Shared order lists now got a "goto depot" button
authorbjarni
Tue, 29 Aug 2006 23:39:57 +0000
changeset 4451 66603f0f732e
parent 4450 d64008e0af99
child 4452 5c5414b229f3
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
this will try to send all vehicles in the list to depots/hangars
currently if one fails to find a depot, it will not tell the player
aircraft_cmd.c
lang/english.txt
roadveh_cmd.c
ship_cmd.c
train_cmd.c
vehicle.c
vehicle.h
vehicle_gui.c
--- a/aircraft_cmd.c	Tue Aug 29 22:47:38 2006 +0000
+++ b/aircraft_cmd.c	Tue Aug 29 23:39:57 2006 +0000
@@ -493,20 +493,25 @@
  * @param p1 vehicle ID to send to the hangar
  * @param p2 various bitmasked elements
  * - p2 bit 0 - aircraft will try to goto a hangar, but not stop there (service only)
- * - p2 bit 1 - aircraft will try to locate another airport with a hangar if the target airport lacks one (used by helicopters for autorenew and autoreplace)
+ * - p2 bit 1 - send all of shared orders to depot
+ * - p2 bit 2 - aircraft will try to locate another airport with a hangar if the target airport lacks one (used by helicopters for autorenew and autoreplace)
  */
 int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
+	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
 
-	if (!IsValidVehicleID(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
 
-	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
+	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return return_value;
+
+	if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendAircraftToHangar(tile, flags, v->next_shared->index, p2);
 
 	if (v->current_order.type == OT_GOTO_DEPOT && p2 == 0) {
 		if (flags & DC_EXEC) {
+			if (HASBIT(p2, 1)) return 0;	// Mass ordering goto depot should not turn goto hangar orders off
 			if (v->current_order.flags & OF_UNLOAD) v->cur_order_index++;
 			v->current_order.type = OT_DUMMY;
 			v->current_order.flags = 0;
@@ -521,12 +526,12 @@
 		if (!IsValidStation(st) || st->airport_tile == 0 || GetAirport(st->airport_type)->nof_depots == 0) {
 			StationID station;
 
-			if (!HASBIT(p2, 1)) return CMD_ERROR;
+			if (!HASBIT(p2, 2)) return return_value;
 			// the aircraft has to search for a hangar on its own
 			station = FindNearestHangar(v);
 
 			next_airport_has_hangar = false;
-			if (station == INVALID_STATION) return CMD_ERROR;
+			if (station == INVALID_STATION) return return_value;
 			st = GetStation(station);
 			next_airport_index = station;
 
@@ -538,7 +543,7 @@
 			if (!HASBIT(p2,0)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
 			v->current_order.dest.station = next_airport_index;
 			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
-			if (HASBIT(p2, 17) || (p2 == 0 && v->u.air.state == FLYING && !next_airport_has_hangar)) {
+			if (HASBIT(p2, 2) || (p2 == 0 && v->u.air.state == FLYING && !next_airport_has_hangar)) {
 			// the aircraft is now heading for a different hangar than the next in the orders
 				AircraftNextAirportPos_and_Order(v);
 				v->u.air.targetairport = next_airport_index;
@@ -1592,7 +1597,7 @@
 				HASBIT(GetEngine(v->engine_type)->player_avail, _local_player))
 			)) {
 		_current_player = _local_player;
-		DoCommandP(v->tile, v->index, 3, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
+		DoCommandP(v->tile, v->index, (1|(1 << 2)), NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
 		_current_player = OWNER_NONE;
 	}
 }
--- a/lang/english.txt	Tue Aug 29 22:47:38 2006 +0000
+++ b/lang/english.txt	Tue Aug 29 23:39:57 2006 +0000
@@ -2863,6 +2863,11 @@
 STR_VEH_WITH_SHARED_ORDERS_LIST                                 :{WHITE}Shared orders of {COMMA} Vehicle{P "" s}
 STR_VEH_WITH_SHARED_ORDERS_LIST_TIP                             :{BLACK}Show all vehicles which have the same schedule
 
+STR_SEND_TO_DEPOTS                                               :{BLACK}Send to Depots
+STR_SEND_TO_DEPOTS_TIP                                           :{BLACK}Send all vehicles in the list to depots.{}Control-click will make them service only (instead of stopping)
+STR_SEND_TO_HANGARS                                              :{BLACK}Send to Hangars
+STR_SEND_TO_HANGARS_TIP                                          :{BLACK}Send all aircrafts in the list to hangars.{}Control-click will make them service only (instead of stopping)
+
 STR_REPLACE_VEHICLES                                            :{BLACK}Replace Vehicles
 STR_REPLACE_VEHICLES_WHITE                                      :{WHITE}Replace {STRING}
 STR_REPLACE_VEHICLES_START                                      :{BLACK}Start Replacing Vehicles
--- a/roadveh_cmd.c	Tue Aug 29 22:47:38 2006 +0000
+++ b/roadveh_cmd.c	Tue Aug 29 23:39:57 2006 +0000
@@ -357,24 +357,30 @@
 /** Send a road vehicle to the depot.
  * @param tile unused
  * @param p1 vehicle ID to send to the depot
- * @param p2 if bit 0 is set, then the road vehicle will only service at the depot. 0 Makes it stop inside
+ * @param p2 various bitmasked elements
+ * - p2 bit 0 - if bit 0 is set, then the road vehicle will only service at the depot. 0 Makes it stop inside
+ * - p2 bit 1 - send all of shared orders to depot
  */
 int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 	const Depot *dep;
+	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
 
-	if (!IsValidVehicleID(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
 
-	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
+	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return return_value;
 
-	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
+	if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendRoadVehToDepot(tile, flags, v->next_shared->index, p2);
+
+	if (v->vehstatus & VS_CRASHED) return return_value;
 
 	/* If the current orders are already goto-depot */
 	if (v->current_order.type == OT_GOTO_DEPOT) {
 		if (flags & DC_EXEC) {
+			if (HASBIT(p2, 1)) return 0;	// Mass ordering goto depot should not turn goto depot orders off
 			/* If the orders to 'goto depot' are in the orders list (forced servicing),
 			 * then skip to the next order; effectively cancelling this forced service */
 			if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS))
@@ -388,7 +394,10 @@
 	}
 
 	dep = FindClosestRoadDepot(v);
-	if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
+	if (dep == NULL) {
+		if (HASBIT(p2, 1)) return 0;	// Mass ordering goto depot should not return error
+		return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
+	}
 
 	if (flags & DC_EXEC) {
 		ClearSlot(v);
--- a/ship_cmd.c	Tue Aug 29 22:47:38 2006 +0000
+++ b/ship_cmd.c	Tue Aug 29 23:39:57 2006 +0000
@@ -995,24 +995,30 @@
 /** Send a ship to the depot.
  * @param tile unused
  * @param p1 vehicle ID to send to the depot
- * @param p2 p2 if bit 0 is set, then the ship will only service at the depot. 0 Makes it stop inside
+ * @param p2 various bitmasked elements
+ * - p2 bit 0 - if bit 0 is set, then the ship will only service at the depot. 0 Makes it stop inside
+ * - p2 bit 1 - send all of shared orders to depot
  */
 int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 	const Depot *dep;
+	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
 
-	if (!IsValidVehicleID(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
 
-	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
+	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return return_value;
 
-	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
+	if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendShipToDepot(tile, flags, v->next_shared->index, p2);
+
+	if (v->vehstatus & VS_CRASHED) return return_value;
 
 	/* If the current orders are already goto-depot */
 	if (v->current_order.type == OT_GOTO_DEPOT) {
 		if (flags & DC_EXEC) {
+			if (HASBIT(p2, 1)) return 0;	// Mass ordering goto depot should not turn goto depot orders off
 			/* If the orders to 'goto depot' are in the orders list (forced servicing),
 			 * then skip to the next order; effectively cancelling this forced service */
 			if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS))
@@ -1026,8 +1032,10 @@
 	}
 
 	dep = FindClosestShipDepot(v);
-	if (dep == NULL)
+	if (dep == NULL) {
+		if (HASBIT(p2, 1)) return 0;	// Mass ordering goto depot should not return error
 		return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT);
+	}
 
 	if (flags & DC_EXEC) {
 		v->dest_tile = dep->xy;
--- a/train_cmd.c	Tue Aug 29 22:47:38 2006 +0000
+++ b/train_cmd.c	Tue Aug 29 23:39:57 2006 +0000
@@ -1924,23 +1924,29 @@
 /** Send a train to a depot
  * @param tile unused
  * @param p1 train to send to the depot
- * @param p2 if bit 0 is set, then the train will only service at the depot. 0 Makes it stop inside
+ * @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
  */
 int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 	TrainFindDepotData tfdd;
-
-	if (!IsValidVehicleID(p1)) return CMD_ERROR;
+	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
+
+	if (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
 
-	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
-
-	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
+	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->vehstatus & VS_CRASHED) return return_value;
 
 	if (v->current_order.type == OT_GOTO_DEPOT) {
 		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++;
@@ -1954,8 +1960,10 @@
 	}
 
 	tfdd = FindClosestTrainDepot(v, 0);
-	if (tfdd.best_length == (uint)-1)
+	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 (flags & DC_EXEC) {
 		v->dest_tile = tfdd.tile;
--- a/vehicle.c	Tue Aug 29 22:47:38 2006 +0000
+++ b/vehicle.c	Tue Aug 29 23:39:57 2006 +0000
@@ -67,6 +67,13 @@
 	CMD_REFIT_AIRCRAFT,
 };
 
+const uint32 _send_to_depot_proc_table[] = {
+	CMD_TRAIN_GOTO_DEPOT,
+	CMD_SEND_ROADVEH_TO_DEPOT,
+	CMD_SEND_SHIP_TO_DEPOT,
+	CMD_SEND_AIRCRAFT_TO_HANGAR,
+};
+
 
 enum {
 	/* Max vehicles: 64000 (512 * 125) */
--- a/vehicle.h	Tue Aug 29 22:47:38 2006 +0000
+++ b/vehicle.h	Tue Aug 29 23:39:57 2006 +0000
@@ -460,4 +460,8 @@
  * Best is to have a virtual value for it when it needs to change again */
 #define STATUS_BAR 5
 
+#define CMD_SEND_TO_DEPOT(x) _send_to_depot_proc_table[ x - VEH_Train]
+
+extern const uint32 _send_to_depot_proc_table[];
+
 #endif /* VEHICLE_H */
--- a/vehicle_gui.c	Tue Aug 29 22:47:38 2006 +0000
+++ b/vehicle_gui.c	Tue Aug 29 23:39:57 2006 +0000
@@ -1258,10 +1258,16 @@
 					}
 					SetDParam(0, w->vscroll.count);
 					w->widget[1].unkA  = STR_VEH_WITH_SHARED_ORDERS_LIST;
-					w->widget[9].unkA  = STR_EMPTY;
 					w->widget[10].unkA = STR_EMPTY;
-					SETBIT(w->disabled_state, 9);
 					SETBIT(w->disabled_state, 10);
+
+					if (vehicle_type == VEH_Aircraft) {
+						w->widget[9].unkA = STR_SEND_TO_HANGARS;
+						w->widget[9].tooltips = STR_SEND_TO_HANGARS_TIP;
+					} else {
+						w->widget[9].unkA = STR_SEND_TO_DEPOTS;
+						w->widget[9].tooltips = STR_SEND_TO_DEPOTS_TIP;
+					}
 					break;
 
 				case VLW_STANDARD:
@@ -1397,7 +1403,17 @@
 					}
 				} break;
 
-				case 9: /* Build new Vehicle */
+				case 9: { /* Build new Vehicle */
+					const uint16 window_type = w->window_number & VLW_FLAGS;
+
+					if (window_type == VLW_SHARED_ORDERS) {
+						const Vehicle *v;
+						assert(vl->list_length != 0);
+						v = vl->sort_list[0];
+						DoCommandP(v->tile, v->index, _ctrl_pressed ? 3 : 2, NULL, CMD_SEND_TO_DEPOT(vehicle_type));
+						break;
+					}
+
 					switch (vehicle_type) {
 						case VEH_Train:
 							assert(IsWindowOfPrototype(w, _player_trains_widgets));
@@ -1418,6 +1434,7 @@
 						default: NOT_REACHED(); break;
 					}
 					break;
+				}
 
 				case 10: {
 					if (vehicle_type == VEH_Train    && !IsWindowOfPrototype(w, _player_trains_widgets))   break;