Mercurial > hg > openttd
changeset 16075:ab8c26c4d456 draft
(svn r20768) -Codechange: unify send-to-depot commands
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 08 Sep 2010 18:55:58 +0000 |
parents | ada92e32c39e |
children | 5d9e762ad46e |
files | src/aircraft_cmd.cpp src/command.cpp src/command_type.h src/group_gui.cpp src/roadveh_cmd.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle_cmd.cpp src/vehicle_func.h src/vehicle_gui.cpp |
diffstat | 10 files changed, 42 insertions(+), 134 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -357,32 +357,6 @@ return true; } -/** - * Send an aircraft to the hangar. - * @param tile unused - * @param flags for command type - * @param p1 vehicle ID to send to the hangar - * @param p2 various bitmasked elements - * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) - * - p2 bit 8-10 - VLW flag (for mass goto depot) - * @param text unused - * @return the cost of this operation or an error - */ -CommandCost CmdSendAircraftToHangar(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) -{ - if (p2 & DEPOT_MASS_SEND) { - /* Mass goto depot requested */ - if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; - return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1); - } - - Aircraft *v = Aircraft::GetIfValid(p1); - if (v == NULL) return CMD_ERROR; - - return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); -} - - static void CheckIfAircraftNeedsService(Aircraft *v) { if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return; @@ -1093,7 +1067,7 @@ const Station *st = GetTargetAirportIfValid(v); if (st == NULL) { Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE); - CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); + CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); if (ret.Failed()) CrashAirplane(v); @@ -1400,7 +1374,7 @@ /* Send the helicopter to a hangar if needed for replacement */ if (v->NeedsAutomaticServicing()) { Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE); - DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); + DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); } } @@ -1450,7 +1424,7 @@ /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */ if (v->NeedsAutomaticServicing()) { Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE); - DoCommand(v->tile, v->index, DEPOT_SERVICE, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); + DoCommand(v->tile, v->index, DEPOT_SERVICE, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); } }
--- a/src/command.cpp +++ b/src/command.cpp @@ -83,8 +83,8 @@ CommandProc CmdBuildVehicle; CommandProc CmdSellVehicle; CommandProc CmdRefitVehicle; +CommandProc CmdSendVehicleToDepot; -CommandProc CmdSendTrainToDepot; CommandProc CmdForceTrainProceed; CommandProc CmdReverseTrainDirection; @@ -114,12 +114,9 @@ CommandProc CmdRenameStation; CommandProc CmdRenameDepot; -CommandProc CmdSendAircraftToHangar; - CommandProc CmdPlaceSign; CommandProc CmdRenameSign; -CommandProc CmdSendRoadVehToDepot; CommandProc CmdTurnRoadVeh; CommandProc CmdPause; @@ -137,8 +134,6 @@ CommandProc CmdChangeSetting; CommandProc CmdChangeCompanySetting; -CommandProc CmdSendShipToDepot; - CommandProc CmdOrderRefit; CommandProc CmdCloneOrder; @@ -224,9 +219,9 @@ DEF_CMD(CmdBuildVehicle, CMD_CLIENT_ID), // CMD_BUILD_VEHICLE DEF_CMD(CmdSellVehicle, CMD_CLIENT_ID), // CMD_SELL_VEHICLE DEF_CMD(CmdRefitVehicle, 0), // CMD_REFIT_VEHICLE + DEF_CMD(CmdSendVehicleToDepot, 0), // CMD_SEND_VEHICLE_TO_DEPOT DEF_CMD(CmdMoveRailVehicle, 0), // CMD_MOVE_RAIL_VEHICLE - DEF_CMD(CmdSendTrainToDepot, 0), // CMD_SEND_TRAIN_TO_DEPOT DEF_CMD(CmdForceTrainProceed, 0), // CMD_FORCE_TRAIN_PROCEED DEF_CMD(CmdReverseTrainDirection, 0), // CMD_REVERSE_TRAIN_DIRECTION @@ -256,12 +251,9 @@ DEF_CMD(CmdRenameStation, 0), // CMD_RENAME_STATION DEF_CMD(CmdRenameDepot, 0), // CMD_RENAME_DEPOT - DEF_CMD(CmdSendAircraftToHangar, 0), // CMD_SEND_AIRCRAFT_TO_HANGAR - DEF_CMD(CmdPlaceSign, 0), // CMD_PLACE_SIGN DEF_CMD(CmdRenameSign, 0), // CMD_RENAME_SIGN - DEF_CMD(CmdSendRoadVehToDepot, 0), // CMD_SEND_ROADVEH_TO_DEPOT DEF_CMD(CmdTurnRoadVeh, 0), // CMD_TURN_ROADVEH DEF_CMD(CmdPause, CMD_SERVER), // CMD_PAUSE @@ -276,8 +268,6 @@ DEF_CMD(CmdExpandTown, CMD_OFFLINE), // CMD_EXPAND_TOWN DEF_CMD(CmdDeleteTown, CMD_OFFLINE), // CMD_DELETE_TOWN - DEF_CMD(CmdSendShipToDepot, 0), // CMD_SEND_SHIP_TO_DEPOT - DEF_CMD(CmdOrderRefit, 0), // CMD_ORDER_REFIT DEF_CMD(CmdCloneOrder, 0), // CMD_CLONE_ORDER
--- a/src/command_type.h +++ b/src/command_type.h @@ -180,9 +180,9 @@ CMD_BUILD_VEHICLE, ///< build a vehicle CMD_SELL_VEHICLE, ///< sell a vehicle CMD_REFIT_VEHICLE, ///< refit the cargo space of a vehicle + CMD_SEND_VEHICLE_TO_DEPOT, ///< send a vehicle to a depot CMD_MOVE_RAIL_VEHICLE, ///< move a rail vehicle (in the depot) - CMD_SEND_TRAIN_TO_DEPOT, ///< send a train to a depot CMD_FORCE_TRAIN_PROCEED, ///< proceed a train to pass a red signal CMD_REVERSE_TRAIN_DIRECTION, ///< turn a train around @@ -211,12 +211,9 @@ CMD_RENAME_STATION, ///< rename a station CMD_RENAME_DEPOT, ///< rename a depot - CMD_SEND_AIRCRAFT_TO_HANGAR, ///< send an aircraft to a hanger - CMD_PLACE_SIGN, ///< place a sign CMD_RENAME_SIGN, ///< rename a sign - CMD_SEND_ROADVEH_TO_DEPOT, ///< send a road vehicle to the depot CMD_TURN_ROADVEH, ///< turn a road vehicle around CMD_PAUSE, ///< pause the game @@ -231,8 +228,6 @@ CMD_EXPAND_TOWN, ///< expand a town CMD_DELETE_TOWN, ///< delete a town - CMD_SEND_SHIP_TO_DEPOT, ///< send a ship to a depot - CMD_ORDER_REFIT, ///< change the refit informaction of an order (for "goto depot" ) CMD_CLONE_ORDER, ///< clone (and share) an order CMD_CLEAR_AREA, ///< clear an area
--- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -573,13 +573,12 @@ ShowReplaceGroupVehicleWindow(this->group_sel, this->vehicle_type); break; case ADI_SERVICE: // Send for servicing - DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) - | DEPOT_MASS_SEND - | DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type)); + DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) | + this->vehicle_type << 11 | DEPOT_MASS_SEND | DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type)); break; case ADI_DEPOT: // Send to Depots - DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) - | DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type)); + DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) | + this->vehicle_type << 11 | DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type)); break; case ADI_ADD_SHARED: // Add shared Vehicles assert(Group::IsValidID(this->group_sel));
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -311,31 +311,6 @@ } /** - * Send a road vehicle to the depot. - * @param tile unused - * @param flags operation to perform - * @param p1 vehicle ID to send to the depot - * @param p2 various bitmasked elements - * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) - * - p2 bit 8-10 - VLW flag (for mass goto depot) - * @param text unused - * @return the cost of this operation or an error - */ -CommandCost CmdSendRoadVehToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) -{ - if (p2 & DEPOT_MASS_SEND) { - /* Mass goto depot requested */ - if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; - return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1); - } - - RoadVehicle *v = RoadVehicle::GetIfValid(p1); - if (v == NULL) return CMD_ERROR; - - return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); -} - -/** * Turn a roadvehicle around. * @param tile unused * @param flags operation to perform
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -635,28 +635,3 @@ return true; } - -/** - * Send a ship to the depot. - * @param tile unused - * @param flags type of operation - * @param p1 vehicle ID to send to the depot - * @param p2 various bitmasked elements - * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) - * - p2 bit 8-10 - VLW flag (for mass goto depot) - * @param text unused - * @return the cost of this operation or an error - */ -CommandCost CmdSendShipToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) -{ - if (p2 & DEPOT_MASS_SEND) { - /* Mass goto depot requested */ - if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; - return SendAllVehiclesToDepot(VEH_SHIP, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1); - } - - Ship *v = Ship::GetIfValid(p1); - if (v == NULL) return CMD_ERROR; - - return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); -}
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1919,31 +1919,6 @@ return true; } -/** - * Send a train to a depot - * @param tile unused - * @param flags type of operation - * @param p1 train to send to the depot - * @param p2 various bitmasked elements - * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) - * - p2 bit 8-10 - VLW flag (for mass goto depot) - * @param text unused - * @return the cost of this operation or an error - */ -CommandCost CmdSendTrainToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) -{ - if (p2 & DEPOT_MASS_SEND) { - /* Mass goto depot requested */ - if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; - return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1); - } - - Train *v = Train::GetIfValid(p1); - if (v == NULL) return CMD_ERROR; - - return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); -} - static const int8 _vehicle_smoke_pos[8] = { 1, 1, 1, 0, -1, -1, -1, 0 };
--- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -58,10 +58,10 @@ const uint32 _send_to_depot_proc_table[] = { /* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */ - CMD_SEND_TRAIN_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT) | CMD_NO_TEST_IF_IN_NETWORK, - CMD_SEND_ROADVEH_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT), - CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT), - CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR), + CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT) | CMD_NO_TEST_IF_IN_NETWORK, + CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT), + CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT), + CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR), }; @@ -840,6 +840,32 @@ } /** + * Send a vehicle to the depot. + * @param tile unused + * @param flags for command type + * @param p1 vehicle ID to send to the depot + * @param p2 various bitmasked elements + * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) + * - p2 bit 8-10 - VLW flag (for mass goto depot) + * - p2 bit 10-11 - Vehicle type + * @param text unused + * @return the cost of this operation or an error + */ +CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +{ + if (p2 & DEPOT_MASS_SEND) { + /* Mass goto depot requested */ + if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; + return SendAllVehiclesToDepot((VehicleType)GB(p2, 11, 2), flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1); + } + + Vehicle *v = Vehicle::GetIfValid(p1); + if (v == NULL) return CMD_ERROR; + + return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); +} + +/** * Give a custom name to your vehicle * @param tile unused * @param flags type of operation
--- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -59,7 +59,6 @@ UnitID GetFreeUnitNumber(VehicleType type); -CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id); void VehicleEnterDepot(Vehicle *v); bool CanBuildVehicleInfrastructure(VehicleType type);
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1307,11 +1307,11 @@ break; case ADI_SERVICE: // Send for servicing DoCommandP(0, GB(this->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */, - (this->window_number & VLW_MASK) | DEPOT_MASS_SEND | DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type)); + (this->window_number & VLW_MASK) | this->vehicle_type << 11 | DEPOT_MASS_SEND | DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type)); break; case ADI_DEPOT: // Send to Depots DoCommandP(0, GB(this->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */, - (this->window_number & VLW_MASK) | DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type)); + (this->window_number & VLW_MASK) | this->vehicle_type << 11 | DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type)); break; default: NOT_REACHED();