diff options
author | bjarni <bjarni@openttd.org> | 2006-08-29 23:39:57 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2006-08-29 23:39:57 +0000 |
commit | 386468dc72367e7669cf6349214a0ceaf4d3ea89 (patch) | |
tree | d40d87b7909a66cde4dabc692991518710af28ed | |
parent | 1305b2365f623b5de2e80ac8c30abc266cf02ff9 (diff) | |
download | openttd-386468dc72367e7669cf6349214a0ceaf4d3ea89.tar.xz |
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
this will try to send all vehicles in the list to depots/hangars
currently if one fails to find a depot, it will not tell the player
-rw-r--r-- | aircraft_cmd.c | 19 | ||||
-rw-r--r-- | lang/english.txt | 5 | ||||
-rw-r--r-- | roadveh_cmd.c | 19 | ||||
-rw-r--r-- | ship_cmd.c | 18 | ||||
-rw-r--r-- | train_cmd.c | 18 | ||||
-rw-r--r-- | vehicle.c | 7 | ||||
-rw-r--r-- | vehicle.h | 4 | ||||
-rw-r--r-- | vehicle_gui.c | 23 |
8 files changed, 88 insertions, 25 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c index ea532710e..8fa4240a0 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -493,20 +493,25 @@ int32 CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) * @param p1 vehicle ID to send to the hangar * @param p2 various bitmasked elements * - p2 bit 0 - aircraft will try to goto a hangar, but not stop there (service only) - * - p2 bit 1 - aircraft will try to locate another airport with a hangar if the target airport lacks one (used by helicopters for autorenew and autoreplace) + * - p2 bit 1 - send all of shared orders to depot + * - p2 bit 2 - aircraft will try to locate another airport with a hangar if the target airport lacks one (used by helicopters for autorenew and autoreplace) */ int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { Vehicle *v; + const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR; - if (!IsValidVehicleID(p1)) return CMD_ERROR; + if (!IsValidVehicleID(p1)) return return_value; v = GetVehicle(p1); - if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR; + if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return return_value; + + if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendAircraftToHangar(tile, flags, v->next_shared->index, p2); if (v->current_order.type == OT_GOTO_DEPOT && p2 == 0) { if (flags & DC_EXEC) { + if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not turn goto hangar orders off if (v->current_order.flags & OF_UNLOAD) v->cur_order_index++; v->current_order.type = OT_DUMMY; v->current_order.flags = 0; @@ -521,12 +526,12 @@ int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2 if (!IsValidStation(st) || st->airport_tile == 0 || GetAirport(st->airport_type)->nof_depots == 0) { StationID station; - if (!HASBIT(p2, 1)) return CMD_ERROR; + if (!HASBIT(p2, 2)) return return_value; // the aircraft has to search for a hangar on its own station = FindNearestHangar(v); next_airport_has_hangar = false; - if (station == INVALID_STATION) return CMD_ERROR; + if (station == INVALID_STATION) return return_value; st = GetStation(station); next_airport_index = station; @@ -538,7 +543,7 @@ int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2 if (!HASBIT(p2,0)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT); v->current_order.dest.station = next_airport_index; InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); - if (HASBIT(p2, 17) || (p2 == 0 && v->u.air.state == FLYING && !next_airport_has_hangar)) { + if (HASBIT(p2, 2) || (p2 == 0 && v->u.air.state == FLYING && !next_airport_has_hangar)) { // the aircraft is now heading for a different hangar than the next in the orders AircraftNextAirportPos_and_Order(v); v->u.air.targetairport = next_airport_index; @@ -1592,7 +1597,7 @@ static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass * HASBIT(GetEngine(v->engine_type)->player_avail, _local_player)) )) { _current_player = _local_player; - DoCommandP(v->tile, v->index, 3, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); + DoCommandP(v->tile, v->index, (1|(1 << 2)), NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); _current_player = OWNER_NONE; } } diff --git a/lang/english.txt b/lang/english.txt index 7228f124f..3c0211466 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -2863,6 +2863,11 @@ STR_SCHEDULED_SHIPS_TIP :{BLACK}Show all STR_VEH_WITH_SHARED_ORDERS_LIST :{WHITE}Shared orders of {COMMA} Vehicle{P "" s} STR_VEH_WITH_SHARED_ORDERS_LIST_TIP :{BLACK}Show all vehicles which have the same schedule +STR_SEND_TO_DEPOTS :{BLACK}Send to Depots +STR_SEND_TO_DEPOTS_TIP :{BLACK}Send all vehicles in the list to depots.{}Control-click will make them service only (instead of stopping) +STR_SEND_TO_HANGARS :{BLACK}Send to Hangars +STR_SEND_TO_HANGARS_TIP :{BLACK}Send all aircrafts in the list to hangars.{}Control-click will make them service only (instead of stopping) + STR_REPLACE_VEHICLES :{BLACK}Replace Vehicles STR_REPLACE_VEHICLES_WHITE :{WHITE}Replace {STRING} STR_REPLACE_VEHICLES_START :{BLACK}Start Replacing Vehicles diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 00843d65a..ec19b5e2e 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -357,24 +357,30 @@ static const Depot* FindClosestRoadDepot(const Vehicle* v) /** Send a road vehicle to the depot. * @param tile unused * @param p1 vehicle ID to send to the depot - * @param p2 if bit 0 is set, then the road vehicle will only service at the depot. 0 Makes it stop inside + * @param p2 various bitmasked elements + * - p2 bit 0 - if bit 0 is set, then the road vehicle will only service at the depot. 0 Makes it stop inside + * - p2 bit 1 - send all of shared orders to depot */ int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { Vehicle *v; const Depot *dep; + const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR; - if (!IsValidVehicleID(p1)) return CMD_ERROR; + if (!IsValidVehicleID(p1)) return return_value; v = GetVehicle(p1); - if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; + if (v->type != VEH_Road || !CheckOwnership(v->owner)) return return_value; - if (v->vehstatus & VS_CRASHED) return CMD_ERROR; + if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendRoadVehToDepot(tile, flags, v->next_shared->index, p2); + + if (v->vehstatus & VS_CRASHED) return return_value; /* If the current orders are already goto-depot */ if (v->current_order.type == OT_GOTO_DEPOT) { if (flags & DC_EXEC) { + if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not turn goto depot orders off /* If the orders to 'goto depot' are in the orders list (forced servicing), * then skip to the next order; effectively cancelling this forced service */ if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) @@ -388,7 +394,10 @@ int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } dep = FindClosestRoadDepot(v); - if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); + if (dep == NULL) { + if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not return error + return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); + } if (flags & DC_EXEC) { ClearSlot(v); diff --git a/ship_cmd.c b/ship_cmd.c index 94eeab5a6..2c49f5224 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -995,24 +995,30 @@ int32 CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) /** Send a ship to the depot. * @param tile unused * @param p1 vehicle ID to send to the depot - * @param p2 p2 if bit 0 is set, then the ship will only service at the depot. 0 Makes it stop inside + * @param p2 various bitmasked elements + * - p2 bit 0 - if bit 0 is set, then the ship will only service at the depot. 0 Makes it stop inside + * - p2 bit 1 - send all of shared orders to depot */ int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { Vehicle *v; const Depot *dep; + const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR; - if (!IsValidVehicleID(p1)) return CMD_ERROR; + if (!IsValidVehicleID(p1)) return return_value; v = GetVehicle(p1); - if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR; + if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return return_value; - if (v->vehstatus & VS_CRASHED) return CMD_ERROR; + if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendShipToDepot(tile, flags, v->next_shared->index, p2); + + if (v->vehstatus & VS_CRASHED) return return_value; /* If the current orders are already goto-depot */ if (v->current_order.type == OT_GOTO_DEPOT) { if (flags & DC_EXEC) { + if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not turn goto depot orders off /* If the orders to 'goto depot' are in the orders list (forced servicing), * then skip to the next order; effectively cancelling this forced service */ if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) @@ -1026,8 +1032,10 @@ int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } dep = FindClosestShipDepot(v); - if (dep == NULL) + if (dep == NULL) { + if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not return error return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT); + } if (flags & DC_EXEC) { v->dest_tile = dep->xy; diff --git a/train_cmd.c b/train_cmd.c index 021058ff6..9686595d8 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -1924,23 +1924,29 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v, int max_distance) /** Send a train to a depot * @param tile unused * @param p1 train to send to the depot - * @param p2 if bit 0 is set, then the train will only service at the depot. 0 Makes it stop inside + * @param p2 various bitmasked elements + * - p2 bit 0 - if bit 0 is set, then the train will only service at the depot. 0 Makes it stop inside + * - p2 bit 1 - send all of shared orders to depot */ int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { Vehicle *v; TrainFindDepotData tfdd; + const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR; - if (!IsValidVehicleID(p1)) return CMD_ERROR; + if (!IsValidVehicleID(p1)) return return_value; v = GetVehicle(p1); - if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; + if (v->type != VEH_Train || !CheckOwnership(v->owner)) return return_value; - if (v->vehstatus & VS_CRASHED) return CMD_ERROR; + if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendTrainToDepot(tile, flags, v->next_shared->index, p2); + + if (v->vehstatus & VS_CRASHED) return return_value; if (v->current_order.type == OT_GOTO_DEPOT) { if (flags & DC_EXEC) { + if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not turn goto depot orders off if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) { v->u.rail.days_since_order_progr = 0; v->cur_order_index++; @@ -1954,8 +1960,10 @@ int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } tfdd = FindClosestTrainDepot(v, 0); - if (tfdd.best_length == (uint)-1) + if (tfdd.best_length == (uint)-1) { + if (HASBIT(p2, 1)) return 0; // Mass ordering goto depot should not return error return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO); + } if (flags & DC_EXEC) { v->dest_tile = tfdd.tile; @@ -67,6 +67,13 @@ static const uint32 _veh_refit_proc_table[] = { CMD_REFIT_AIRCRAFT, }; +const uint32 _send_to_depot_proc_table[] = { + CMD_TRAIN_GOTO_DEPOT, + CMD_SEND_ROADVEH_TO_DEPOT, + CMD_SEND_SHIP_TO_DEPOT, + CMD_SEND_AIRCRAFT_TO_HANGAR, +}; + enum { /* Max vehicles: 64000 (512 * 125) */ @@ -460,4 +460,8 @@ PalSpriteID GetVehiclePalette(const Vehicle *v); * Best is to have a virtual value for it when it needs to change again */ #define STATUS_BAR 5 +#define CMD_SEND_TO_DEPOT(x) _send_to_depot_proc_table[ x - VEH_Train] + +extern const uint32 _send_to_depot_proc_table[]; + #endif /* VEHICLE_H */ diff --git a/vehicle_gui.c b/vehicle_gui.c index 1d7cfcc2b..3462b512b 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -1258,10 +1258,16 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) } SetDParam(0, w->vscroll.count); w->widget[1].unkA = STR_VEH_WITH_SHARED_ORDERS_LIST; - w->widget[9].unkA = STR_EMPTY; w->widget[10].unkA = STR_EMPTY; - SETBIT(w->disabled_state, 9); SETBIT(w->disabled_state, 10); + + 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; + } break; case VLW_STANDARD: @@ -1397,7 +1403,17 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) } } break; - case 9: /* Build new Vehicle */ + case 9: { /* Build new Vehicle */ + const uint16 window_type = w->window_number & VLW_FLAGS; + + if (window_type == VLW_SHARED_ORDERS) { + 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; + } + switch (vehicle_type) { case VEH_Train: assert(IsWindowOfPrototype(w, _player_trains_widgets)); @@ -1418,6 +1434,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) default: NOT_REACHED(); break; } break; + } case 10: { if (vehicle_type == VEH_Train && !IsWindowOfPrototype(w, _player_trains_widgets)) break; |