(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
This commit is contained in:
bjarni 2006-08-30 21:39:01 +00:00
parent 42682a70aa
commit 744840c3da
7 changed files with 87 additions and 21 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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;
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_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;
{
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;
}
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;
default: NOT_REACHED(); break;
}
break;
case 10: /* Right button */
ShowReplaceVehicleWindow(vehicle_type);