summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/build_vehicle_gui.cpp20
-rw-r--r--src/command.cpp3
-rw-r--r--src/depot_gui.cpp2
-rw-r--r--src/vehicle_cmd.cpp44
-rw-r--r--src/vehicle_gui.cpp13
5 files changed, 30 insertions, 52 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index d65d96b13..4e9e6483b 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -1074,23 +1074,15 @@ struct BuildVehicleWindow : Window {
case BUILD_VEHICLE_WIDGET_BUILD: {
EngineID sel_eng = this->sel_engine;
if (sel_eng != INVALID_ENGINE) {
+ CommandCallback *callback;
switch (this->vehicle_type) {
default: NOT_REACHED();
- case VEH_TRAIN:
- DoCommandP(this->window_number, sel_eng, 0,
- CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN),
- (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco);
- break;
- case VEH_ROAD:
- DoCommandP(this->window_number, sel_eng, 0, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE), CcBuildRoadVeh);
- break;
- case VEH_SHIP:
- DoCommandP(this->window_number, sel_eng, 0, CMD_BUILD_SHIP | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP), CcBuildShip);
- break;
- case VEH_AIRCRAFT:
- DoCommandP(this->window_number, sel_eng, 0, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRCRAFT), CcBuildAircraft);
- break;
+ case VEH_TRAIN: callback = (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco; break;
+ case VEH_ROAD: callback = CcBuildRoadVeh; break;
+ case VEH_SHIP: callback = CcBuildShip; break;
+ case VEH_AIRCRAFT: callback = CcBuildAircraft; break;
}
+ DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback);
}
break;
}
diff --git a/src/command.cpp b/src/command.cpp
index f6f3b2e2e..4b4ba50d8 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -402,7 +402,8 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
/* Do not even think about executing out-of-bounds tile-commands */
if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (flags & DC_ALL_TILES) == 0))) return CMD_ERROR;
- CommandProc *proc = _command_proc_table[cmd].proc;
+ /* Chop of any CMD_MSG or other flags; we don't need those here */
+ CommandProc *proc = _command_proc_table[cmd & CMD_ID_MASK].proc;
if (_docommand_recursive == 0) _error_message = INVALID_STRING_ID;
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 458911d36..457bcdc84 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -914,7 +914,7 @@ struct DepotWindow : Window {
BackupVehicleOrders(v);
}
- if (!DoCommandP(v->tile, v->index, sell_cmd, GetCmdSellVeh(v->type) | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN + v->type)) && is_engine) _backup_orders_tile = 0;
+ if (!DoCommandP(v->tile, v->index, sell_cmd, GetCmdSellVeh(v->type)) && is_engine) _backup_orders_tile = 0;
}
break;
default:
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 6bc2fde7a..3fcb06034 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -25,30 +25,32 @@
/* Tables used in vehicle.h to find the right command for a certain vehicle type */
const uint32 _veh_build_proc_table[] = {
- CMD_BUILD_RAIL_VEHICLE,
- CMD_BUILD_ROAD_VEH,
- CMD_BUILD_SHIP,
- CMD_BUILD_AIRCRAFT,
+ CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN),
+ CMD_BUILD_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE),
+ CMD_BUILD_SHIP | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP),
+ CMD_BUILD_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRCRAFT),
};
+
const uint32 _veh_sell_proc_table[] = {
- CMD_SELL_RAIL_WAGON,
- CMD_SELL_ROAD_VEH,
- CMD_SELL_SHIP,
- CMD_SELL_AIRCRAFT,
+ CMD_SELL_RAIL_WAGON | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN),
+ CMD_SELL_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE),
+ CMD_SELL_SHIP | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP),
+ CMD_SELL_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT),
};
const uint32 _veh_refit_proc_table[] = {
- CMD_REFIT_RAIL_VEHICLE,
- CMD_REFIT_ROAD_VEH,
- CMD_REFIT_SHIP,
- CMD_REFIT_AIRCRAFT,
+ CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_TRAIN),
+ CMD_REFIT_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE),
+ CMD_REFIT_SHIP | CMD_MSG(STR_ERROR_CAN_T_REFIT_SHIP),
+ CMD_REFIT_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_REFIT_AIRCRAFT),
};
const uint32 _send_to_depot_proc_table[] = {
- CMD_SEND_TRAIN_TO_DEPOT,
- CMD_SEND_ROADVEH_TO_DEPOT,
- CMD_SEND_SHIP_TO_DEPOT,
- CMD_SEND_AIRCRAFT_TO_HANGAR,
+ /* 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),
};
/** Start/Stop a vehicle
@@ -169,16 +171,8 @@ CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32
VehicleList list;
CommandCost cost(EXPENSES_NEW_VEHICLES);
- uint sell_command;
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
-
- switch (vehicle_type) {
- case VEH_TRAIN: sell_command = CMD_SELL_RAIL_WAGON; break;
- case VEH_ROAD: sell_command = CMD_SELL_ROAD_VEH; break;
- case VEH_SHIP: sell_command = CMD_SELL_SHIP; break;
- case VEH_AIRCRAFT: sell_command = CMD_SELL_AIRCRAFT; break;
- default: return CMD_ERROR;
- }
+ uint sell_command = GetCmdSendToDepot(vehicle_type);;
/* Get the list of vehicles in the depot */
BuildDepotVehicleList(vehicle_type, tile, &list, &list);
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 8265f4591..1ba7779e7 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -366,7 +366,7 @@ struct RefitWindow : public Window {
const Vehicle *v = Vehicle::Get(this->window_number);
if (this->order == INVALID_VEH_ORDER_ID) {
- if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8, GetCmdRefitVeh(v) | CMD_MSG(STR_ERROR_CAN_T_REFIT_TRAIN + v->type))) delete this;
+ if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8, GetCmdRefitVeh(v))) delete this;
} else {
if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8 | this->order << 16, CMD_ORDER_REFIT)) delete this;
}
@@ -1608,7 +1608,6 @@ static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102;
/** Command indices for the _vehicle_command_translation_table. */
enum VehicleCommandTranslation {
VCT_CMD_START_STOP = 0,
- VCT_CMD_GOTO_DEPOT,
VCT_CMD_CLONE_VEH,
VCT_CMD_TURN_AROUND,
};
@@ -1621,13 +1620,6 @@ static const uint32 _vehicle_command_translation_table[][4] = {
CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_SHIP),
CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_AIRCRAFT)
},
- { // VCT_CMD_GOTO_DEPOT
- /* 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)
- },
{ // VCT_CMD_CLONE_VEH
CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN),
CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE),
@@ -1873,8 +1865,7 @@ struct VehicleViewWindow : Window {
} break;
case VVW_WIDGET_GOTO_DEPOT: // goto hangar
- DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0,
- _vehicle_command_translation_table[VCT_CMD_GOTO_DEPOT][v->type]);
+ DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, GetCmdSendToDepot(v));
break;
case VVW_WIDGET_REFIT_VEH: // refit
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this);