changeset 16076:5d9e762ad46e draft

(svn r20769) -Codechange: move some depot flags from p2 to p1 in CmdSendVehicleToDepot
author rubidium <rubidium@openttd.org>
date Wed, 08 Sep 2010 21:02:12 +0000
parents ab8c26c4d456
children f1fffbd6c714
files src/ai/api/ai_vehicle.cpp src/aircraft_cmd.cpp src/group_gui.cpp src/vehicle_cmd.cpp src/vehicle_gui.cpp src/vehicle_type.h
diffstat 6 files changed, 26 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/api/ai_vehicle.cpp
+++ b/src/ai/api/ai_vehicle.cpp
@@ -170,7 +170,7 @@
 {
 	EnforcePrecondition(false, IsValidVehicle(vehicle_id));
 
-	return AIObject::DoCommand(0, vehicle_id, DEPOT_SERVICE, GetCmdSendToDepot(::Vehicle::Get(vehicle_id)));
+	return AIObject::DoCommand(0, vehicle_id | DEPOT_SERVICE, 0, GetCmdSendToDepot(::Vehicle::Get(vehicle_id)));
 }
 
 /* static */ bool AIVehicle::IsInDepot(VehicleID vehicle_id)
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -1374,7 +1374,7 @@
 	/* Send the helicopter to a hangar if needed for replacement */
 	if (v->NeedsAutomaticServicing()) {
 		Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
-		DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
+		DoCommand(v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
 		cur_company.Restore();
 	}
 }
@@ -1424,7 +1424,7 @@
 	/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
 	if (v->NeedsAutomaticServicing()) {
 		Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
-		DoCommand(v->tile, v->index, DEPOT_SERVICE, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
+		DoCommand(v->tile, v->index | DEPOT_SERVICE, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
 		cur_company.Restore();
 	}
 }
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -573,12 +573,12 @@
 						ShowReplaceGroupVehicleWindow(this->group_sel, this->vehicle_type);
 						break;
 					case ADI_SERVICE: // Send for servicing
-						DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) |
-									this->vehicle_type << 11 | DEPOT_MASS_SEND | DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type));
+						DoCommandP(0, this->group_sel | DEPOT_MASS_SEND | DEPOT_SERVICE, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) |
+									this->vehicle_type << 11, GetCmdSendToDepot(this->vehicle_type));
 						break;
 					case ADI_DEPOT: // Send to Depots
-						DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) |
-									this->vehicle_type << 11 | DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type));
+						DoCommandP(0, this->group_sel | DEPOT_MASS_SEND, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) |
+									this->vehicle_type << 11, GetCmdSendToDepot(this->vehicle_type));
 						break;
 					case ADI_ADD_SHARED: // Add shared Vehicles
 						assert(Group::IsValidID(this->group_sel));
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -823,7 +823,7 @@
 	bool had_success = false;
 	for (uint i = 0; i < list.Length(); i++) {
 		const Vehicle *v = list[i];
-		CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
+		CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(type));
 
 		if (ret.Succeeded()) {
 			had_success = true;
@@ -843,7 +843,9 @@
  * Send a vehicle to the depot.
  * @param tile unused
  * @param flags for command type
- * @param p1 vehicle ID to send to the depot
+ * @param p1 bitmask
+ * - p1 0-20: bitvehicle ID to send to the depot
+ * - p1 bits 25-8  - DEPOT_ flags (see vehicle_type.h)
  * @param p2 various bitmasked elements
  * - p2 bit  0-3  - DEPOT_ flags (see vehicle.h)
  * - p2 bit  8-10 - VLW flag (for mass goto depot)
@@ -853,16 +855,16 @@
  */
 CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 {
-	if (p2 & DEPOT_MASS_SEND) {
+	if (p1 & DEPOT_MASS_SEND) {
 		/* Mass goto depot requested */
 		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
-		return SendAllVehiclesToDepot((VehicleType)GB(p2, 11, 2), flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
+		return SendAllVehiclesToDepot((VehicleType)GB(p2, 11, 2), flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), GB(p1, 0, 20));
 	}
 
-	Vehicle *v = Vehicle::GetIfValid(p1);
+	Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
 	if (v == NULL) return CMD_ERROR;
 
-	return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
+	return v->SendToDepot(flags, (DepotCommand)(p1 & DEPOT_COMMAND_MASK));
 }
 
 /**
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1306,12 +1306,12 @@
 						ShowReplaceGroupVehicleWindow(DEFAULT_GROUP, this->vehicle_type);
 						break;
 					case ADI_SERVICE: // Send for servicing
-						DoCommandP(0, GB(this->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */,
-							(this->window_number & VLW_MASK) | this->vehicle_type << 11 | DEPOT_MASS_SEND | DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type));
+						DoCommandP(0, GB(this->window_number, 16, 16) | DEPOT_MASS_SEND | DEPOT_SERVICE /* StationID or OrderID (depending on VLW) */,
+							(this->window_number & VLW_MASK) | this->vehicle_type << 11, GetCmdSendToDepot(this->vehicle_type));
 						break;
 					case ADI_DEPOT: // Send to Depots
-						DoCommandP(0, GB(this->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */,
-							(this->window_number & VLW_MASK) | this->vehicle_type << 11 | DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type));
+						DoCommandP(0, GB(this->window_number, 16, 16) | DEPOT_MASS_SEND /* StationID or OrderID (depending on VLW) */,
+							(this->window_number & VLW_MASK) | this->vehicle_type << 11, GetCmdSendToDepot(this->vehicle_type));
 						break;
 
 					default: NOT_REACHED();
@@ -2262,7 +2262,7 @@
 			}
 
 			case VVW_WIDGET_GOTO_DEPOT: // goto hangar
-				DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, GetCmdSendToDepot(v));
+				DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0U, GetCmdSendToDepot(v));
 				break;
 			case VVW_WIDGET_REFIT_VEH: // refit
 				ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this);
--- a/src/vehicle_type.h
+++ b/src/vehicle_type.h
@@ -54,14 +54,13 @@
 	VPF_YAPF = 2, ///< Yet Another PathFinder
 };
 
-/* Flags to add to p2 for goto depot commands
- * Note: bits 8-10 are used for VLW flags */
+/** Flags to add to p1 for goto depot commands. */
 enum DepotCommand {
-	DEPOT_SERVICE       = (1 << 0), ///< The vehicle will leave the depot right after arrival (serivce only)
-	DEPOT_MASS_SEND     = (1 << 1), ///< Tells that it's a mass send to depot command (type in VLW flag)
-	DEPOT_DONT_CANCEL   = (1 << 2), ///< Don't cancel current goto depot command if any
-	DEPOT_LOCATE_HANGAR = (1 << 3), ///< Find another airport if the target one lacks a hangar
-	DEPOT_COMMAND_MASK  = 0xF,
+	DEPOT_SERVICE       = (1U << 28), ///< The vehicle will leave the depot right after arrival (serivce only)
+	DEPOT_MASS_SEND     = (1U << 29), ///< Tells that it's a mass send to depot command (type in VLW flag)
+	DEPOT_DONT_CANCEL   = (1U << 30), ///< Don't cancel current goto depot command if any
+	DEPOT_LOCATE_HANGAR = (1U << 31), ///< Find another airport if the target one lacks a hangar
+	DEPOT_COMMAND_MASK  = 0xFU << 28,
 };
 
 static const uint MAX_LENGTH_VEHICLE_NAME_BYTES  =  31; ///< The maximum length of a vehicle name in bytes including '\0'