summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aircraft_cmd.c4
-rw-r--r--roadveh_cmd.c4
-rw-r--r--ship_cmd.c4
-rw-r--r--train_cmd.c4
-rw-r--r--vehicle.c37
-rw-r--r--vehicle.h2
-rw-r--r--vehicle_gui.c51
7 files changed, 86 insertions, 20 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 8fa4240a0..3b9e6c333 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -501,6 +501,10 @@ int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
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);
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index ec19b5e2e..f4801c7c3 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -367,6 +367,10 @@ int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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);
diff --git a/ship_cmd.c b/ship_cmd.c
index 2c49f5224..36d01dd82 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -1005,6 +1005,10 @@ int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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);
diff --git a/train_cmd.c b/train_cmd.c
index 9686595d8..3cc5521a3 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1934,6 +1934,10 @@ int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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);
diff --git a/vehicle.c b/vehicle.c
index 6b75e6418..0913c701c 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1898,6 +1898,43 @@ static void MaybeReplaceVehicle(Vehicle *v)
_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
diff --git a/vehicle.h b/vehicle.h
index 857323415..683e7acd1 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -314,6 +314,8 @@ int CheckTrainStoppedInDepot(const Vehicle *v);
bool VehicleNeedsService(const Vehicle *v);
+int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner);
+
typedef struct GetNewVehiclePosResult {
int x,y;
TileIndex old_tile;
diff --git a/vehicle_gui.c b/vehicle_gui.c
index bec8e1516..dd9b39154 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -1268,6 +1268,14 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
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 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
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);