diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 7b4a9ca635..0736920872 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1352,6 +1352,9 @@ struct BuildVehicleWindow : Window { char text_buffer[2]; text_buffer[0] = 'R'; text_buffer[1] = this->cargo_filter[this->cargo_filter_criteria]; + if ((cmd & 0xFFFF) == CMD_BUILD_VEHICLE) { + cmd = (cmd & ~0xFFFF) | CMD_BUILD_VEHICLE_NT; + } DoCommandP(this->window_number, sel_eng, 0, cmd, callback, text_buffer, true, 2); } else { /* build only */ diff --git a/src/command.cpp b/src/command.cpp index 61848be595..84070993bc 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -285,6 +285,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdPlantTree, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_PLANT_TREE DEF_CMD(CmdBuildVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_BUILD_VEHICLE + DEF_CMD(CmdBuildVehicle, CMD_NO_TEST | CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_BUILD_VEHICLE_NT DEF_CMD(CmdSellVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_SELL_VEHICLE DEF_CMD(CmdRefitVehicle, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_REFIT_VEHICLE DEF_CMD(CmdSendVehicleToDepot, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_SEND_VEHICLE_TO_DEPOT diff --git a/src/command_type.h b/src/command_type.h index 56a4fbd100..ccb924b1f6 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -229,6 +229,7 @@ enum Commands { CMD_PLANT_TREE, ///< plant a tree CMD_BUILD_VEHICLE, ///< build a vehicle + CMD_BUILD_VEHICLE_NT, ///< build a vehicle (no test) 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 diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index ff17819419..e50ff5f713 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -177,6 +177,14 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint } } } + /* Since we can't estimate the cost of build and refitting a vehicle accurately we must + * check whether the company has enough money manually. */ + if (!CheckCompanyHasMoney(value)) { + if (flags & DC_EXEC) { + /* The vehicle has already been bought, so now it must be sold again. */ + DoCommand(tile, v->index, 0, flags, GetCmdSellVeh(type)); + } + } } return value;