diff options
author | bjarni <bjarni@openttd.org> | 2006-08-30 21:39:01 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2006-08-30 21:39:01 +0000 |
commit | 744840c3daed0828e4fc8e3fca843a29bf6df7d8 (patch) | |
tree | e623f356bdcb29cc6664a3dd44ee29114e6db20e | |
parent | 42682a70aaa9426b271c76c7b5f69ae577ce22bc (diff) | |
download | openttd-744840c3daed0828e4fc8e3fca843a29bf6df7d8.tar.xz |
(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
-rw-r--r-- | aircraft_cmd.c | 4 | ||||
-rw-r--r-- | roadveh_cmd.c | 4 | ||||
-rw-r--r-- | ship_cmd.c | 4 | ||||
-rw-r--r-- | train_cmd.c | 4 | ||||
-rw-r--r-- | vehicle.c | 37 | ||||
-rw-r--r-- | vehicle.h | 2 | ||||
-rw-r--r-- | vehicle_gui.c | 51 |
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); @@ -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 @@ -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); |