changeset 4463:328c9fe06255 draft

(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button it's located in the vehicle list screen and does the same as in the shared orders window (send all vehicles in list to a depot) it will still not inform the player if a vehicle failed to find a depot, so don't take for granted that all of them go
author bjarni <bjarni@openttd.org>
date Wed, 30 Aug 2006 21:39:01 +0000
parents 9af2813b46ef
children 5e4d40ff21a7
files aircraft_cmd.c roadveh_cmd.c ship_cmd.c train_cmd.c vehicle.c vehicle.h vehicle_gui.c
diffstat 7 files changed, 86 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -501,6 +501,10 @@
 	Vehicle *v;
 	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
 
+	if (HASBIT(p2, 1) && (p2 & VLW_FLAGS) == VLW_STANDARD) {
+		return SendAllVehiclesToDepot(VEH_Aircraft, flags, HASBIT(p2, 0), _current_player);
+	}
+
 	if (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -367,6 +367,10 @@
 	const Depot *dep;
 	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
 
+	if (HASBIT(p2, 1) && (p2 & VLW_FLAGS) == VLW_STANDARD) {
+		return SendAllVehiclesToDepot(VEH_Road, flags, HASBIT(p2, 0), _current_player);
+	}
+
 	if (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -1005,6 +1005,10 @@
 	const Depot *dep;
 	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
 
+	if (HASBIT(p2, 1) && (p2 & VLW_FLAGS) == VLW_STANDARD) {
+		return SendAllVehiclesToDepot(VEH_Ship, flags, HASBIT(p2, 0), _current_player);
+	}
+
 	if (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1934,6 +1934,10 @@
 	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 (!IsValidVehicleID(p1)) return return_value;
 
 	v = GetVehicle(p1);
--- a/vehicle.c
+++ b/vehicle.c
@@ -1898,6 +1898,43 @@
 	_current_player = OWNER_NONE;
 }
 
+/** send all vehicles of type to depots
+* @param type type of vehicle
+* @param flags the flags used for DoCommand()
+* @param service should the vehicles only get service in the depots
+* @param owner PlayerID of owner of the vehicles to send
+* @return o for success and CMD_ERROR if no vehicle is able to go to depot
+*/
+int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner)
+{
+	const uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
+	if (flags & DC_EXEC) {
+	/* Send all the vehicles to a depot */
+		const Vehicle *v;
+		FOR_ALL_VEHICLES(v) {
+			if (v->type == type && v->owner == owner && (
+				(type == VEH_Train && IsFrontEngine(v)) ||
+				(type != VEH_Train && v->subtype <= subtype))) {
+				DoCommand(v->tile, v->index, service, flags, CMD_SEND_TO_DEPOT(type));
+			}
+		}
+	} else {
+	/* See if we can find a vehicle to send to a depot */
+		const Vehicle *v;
+		FOR_ALL_VEHICLES(v) {
+			if (v->type == type && v->owner == owner && (
+				(type == VEH_Train && IsFrontEngine(v)) ||
+				(type != VEH_Train && v->subtype <= subtype))) {
+				/* We found one vehicle to send to a depot. No need to search for more. The command is valid */
+				if (!DoCommand(v->tile, v->index, service, flags, CMD_SEND_TO_DEPOT(type))) return 0;
+			}
+		}
+
+		return CMD_ERROR;
+	}
+	return 0;
+}
+
 
 /** Give a custom name to your vehicle
  * @param tile unused
--- a/vehicle.h
+++ b/vehicle.h
@@ -314,6 +314,8 @@
 
 bool VehicleNeedsService(const Vehicle *v);
 
+int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner);
+
 typedef struct GetNewVehiclePosResult {
 	int x,y;
 	TileIndex old_tile;
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -1268,6 +1268,14 @@
 					SetDParam(0, p->name_1);
 					SetDParam(1, p->name_2);
 					SetDParam(2, w->vscroll.count);
+					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;
+					}
+
 					switch (vehicle_type) {
 						case VEH_Train:    w->widget[1].unkA = STR_881B_TRAINS;        break;
 						case VEH_Road:     w->widget[1].unkA = STR_9001_ROAD_VEHICLES; break;
@@ -1398,30 +1406,33 @@
 
 				case 9: /* Left button */
 					if (GB(w->window_number, 0, 8) /* OwnerID */ != _local_player) break;
+					{
+						uint16 window_type = w->window_number & VLW_FLAGS;
+						switch (window_type) {
+							case VLW_STANDARD:
+							case VLW_SHARED_ORDERS: {
+								/* Send to depot */
+								const Vehicle *v;
+								assert(vl->list_length != 0);
+								v = vl->sort_list[0];
+								DoCommandP(v->tile, v->index, window_type | _ctrl_pressed ? 3 : 2, NULL, CMD_SEND_TO_DEPOT(vehicle_type));
+								break;
+							}
 
-					switch (w->window_number & VLW_FLAGS) {
-						case VLW_SHARED_ORDERS: {
-							/* Send to depot */
-							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;
+							case VLW_STATION_LIST:
+								/* Build new Vehicle */
+								switch (vehicle_type) {
+									case VEH_Train:	   ShowBuildTrainWindow(0);    break;
+									case VEH_Road:     ShowBuildRoadVehWindow(0);  break;
+									case VEH_Ship:     ShowBuildShipWindow(0);     break;
+									case VEH_Aircraft: ShowBuildAircraftWindow(0); break;
+									default: NOT_REACHED(); break;
+								}
+								break;
+							default: NOT_REACHED(); break;
 						}
-						case VLW_STANDARD:
-						case VLW_STATION_LIST:
-							/* Build new Vehicle */
-							switch (vehicle_type) {
-								case VEH_Train:	   ShowBuildTrainWindow(0);    break;
-								case VEH_Road:     ShowBuildRoadVehWindow(0);  break;
-								case VEH_Ship:     ShowBuildShipWindow(0);     break;
-								case VEH_Aircraft: ShowBuildAircraftWindow(0); break;
-								default: NOT_REACHED(); break;
-							}
 						break;
-						default: NOT_REACHED(); break;
 					}
-					break;
 
 				case 10: /* Right button */
 					ShowReplaceVehicleWindow(vehicle_type);