(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place

pull/155/head
rubidium 15 years ago
parent 01eabc5f4c
commit f62b2f9c7e

@ -1074,23 +1074,15 @@ struct BuildVehicleWindow : Window {
case BUILD_VEHICLE_WIDGET_BUILD: { case BUILD_VEHICLE_WIDGET_BUILD: {
EngineID sel_eng = this->sel_engine; EngineID sel_eng = this->sel_engine;
if (sel_eng != INVALID_ENGINE) { if (sel_eng != INVALID_ENGINE) {
CommandCallback *callback;
switch (this->vehicle_type) { switch (this->vehicle_type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: case VEH_TRAIN: callback = (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco; break;
DoCommandP(this->window_number, sel_eng, 0, case VEH_ROAD: callback = CcBuildRoadVeh; break;
CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN), case VEH_SHIP: callback = CcBuildShip; break;
(RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco); case VEH_AIRCRAFT: callback = CcBuildAircraft; break;
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;
} }
DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback);
} }
break; break;
} }

@ -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 */ /* 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; 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; if (_docommand_recursive == 0) _error_message = INVALID_STRING_ID;

@ -914,7 +914,7 @@ struct DepotWindow : Window {
BackupVehicleOrders(v); 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; break;
default: default:

@ -25,30 +25,32 @@
/* Tables used in vehicle.h to find the right command for a certain vehicle type */ /* Tables used in vehicle.h to find the right command for a certain vehicle type */
const uint32 _veh_build_proc_table[] = { const uint32 _veh_build_proc_table[] = {
CMD_BUILD_RAIL_VEHICLE, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN),
CMD_BUILD_ROAD_VEH, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE),
CMD_BUILD_SHIP, CMD_BUILD_SHIP | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP),
CMD_BUILD_AIRCRAFT, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRCRAFT),
}; };
const uint32 _veh_sell_proc_table[] = { const uint32 _veh_sell_proc_table[] = {
CMD_SELL_RAIL_WAGON, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN),
CMD_SELL_ROAD_VEH, CMD_SELL_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE),
CMD_SELL_SHIP, CMD_SELL_SHIP | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP),
CMD_SELL_AIRCRAFT, CMD_SELL_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT),
}; };
const uint32 _veh_refit_proc_table[] = { const uint32 _veh_refit_proc_table[] = {
CMD_REFIT_RAIL_VEHICLE, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_TRAIN),
CMD_REFIT_ROAD_VEH, CMD_REFIT_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE),
CMD_REFIT_SHIP, CMD_REFIT_SHIP | CMD_MSG(STR_ERROR_CAN_T_REFIT_SHIP),
CMD_REFIT_AIRCRAFT, CMD_REFIT_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_REFIT_AIRCRAFT),
}; };
const uint32 _send_to_depot_proc_table[] = { const uint32 _send_to_depot_proc_table[] = {
CMD_SEND_TRAIN_TO_DEPOT, /* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */
CMD_SEND_ROADVEH_TO_DEPOT, CMD_SEND_TRAIN_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT) | CMD_NO_TEST_IF_IN_NETWORK,
CMD_SEND_SHIP_TO_DEPOT, CMD_SEND_ROADVEH_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT),
CMD_SEND_AIRCRAFT_TO_HANGAR, 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 /** Start/Stop a vehicle
@ -169,16 +171,8 @@ CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32
VehicleList list; VehicleList list;
CommandCost cost(EXPENSES_NEW_VEHICLES); CommandCost cost(EXPENSES_NEW_VEHICLES);
uint sell_command;
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
uint sell_command = GetCmdSendToDepot(vehicle_type);;
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;
}
/* Get the list of vehicles in the depot */ /* Get the list of vehicles in the depot */
BuildDepotVehicleList(vehicle_type, tile, &list, &list); BuildDepotVehicleList(vehicle_type, tile, &list, &list);

@ -366,7 +366,7 @@ struct RefitWindow : public Window {
const Vehicle *v = Vehicle::Get(this->window_number); const Vehicle *v = Vehicle::Get(this->window_number);
if (this->order == INVALID_VEH_ORDER_ID) { 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 { } else {
if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8 | this->order << 16, CMD_ORDER_REFIT)) delete this; 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. */ /** Command indices for the _vehicle_command_translation_table. */
enum VehicleCommandTranslation { enum VehicleCommandTranslation {
VCT_CMD_START_STOP = 0, VCT_CMD_START_STOP = 0,
VCT_CMD_GOTO_DEPOT,
VCT_CMD_CLONE_VEH, VCT_CMD_CLONE_VEH,
VCT_CMD_TURN_AROUND, 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_SHIP),
CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_AIRCRAFT) 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 { // 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_TRAIN),
CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE), CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE),
@ -1873,8 +1865,7 @@ struct VehicleViewWindow : Window {
} break; } break;
case VVW_WIDGET_GOTO_DEPOT: // goto hangar case VVW_WIDGET_GOTO_DEPOT: // goto hangar
DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, GetCmdSendToDepot(v));
_vehicle_command_translation_table[VCT_CMD_GOTO_DEPOT][v->type]);
break; break;
case VVW_WIDGET_REFIT_VEH: // refit case VVW_WIDGET_REFIT_VEH: // refit
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this); ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this);

Loading…
Cancel
Save