summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-08-30 21:39:01 +0000
committerbjarni <bjarni@openttd.org>2006-08-30 21:39:01 +0000
commit1d011b57d25b94028631a8ffa35c66b394c34916 (patch)
treee623f356bdcb29cc6664a3dd44ee29114e6db20e /vehicle.c
parentd5ebb2b359cfbf797d5b6de64099344341406c6b (diff)
downloadopenttd-1d011b57d25b94028631a8ffa35c66b394c34916.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
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c37
1 files changed, 37 insertions, 0 deletions
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