OpenTTD Source: src/vehicle_cmd.h Source File

OpenTTD Source 13.1

vehicle_cmd.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef VEHICLE_CMD_H
11 #define VEHICLE_CMD_H
12
13 #include "command_type.h"
14 #include "engine_type.h"
15 #include "vehicle_type.h"
16 #include "vehiclelist.h"
17 #include "cargo_type.h"
18
19 std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id);
20 CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id);
21 std::tuple<CommandCost, uint, uint16, CargoArray> CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8 num_vehicles);
22 CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli);
23 CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16 serv_int, bool is_custom, bool is_percent);
24 CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::string &text);
25 std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders);
26 CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool evaluate_startstop_cb);
27 CommandCost CmdMassStartStopVehicle(DoCommandFlag flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli);
28 CommandCost CmdDepotSellAllVehicles(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type);
29 CommandCost CmdDepotMassAutoReplace(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type);
30
31 DEF_CMD_TRAIT(CMD_BUILD_VEHICLE, CmdBuildVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION)
32 DEF_CMD_TRAIT(CMD_SELL_VEHICLE, CmdSellVehicle, CMD_CLIENT_ID | CMD_LOCATION, CMDT_VEHICLE_CONSTRUCTION)
33 DEF_CMD_TRAIT(CMD_REFIT_VEHICLE, CmdRefitVehicle, CMD_LOCATION, CMDT_VEHICLE_CONSTRUCTION)
34 DEF_CMD_TRAIT(CMD_SEND_VEHICLE_TO_DEPOT, CmdSendVehicleToDepot, 0, CMDT_VEHICLE_MANAGEMENT)
35 DEF_CMD_TRAIT(CMD_CHANGE_SERVICE_INT, CmdChangeServiceInt, 0, CMDT_VEHICLE_MANAGEMENT)
36 DEF_CMD_TRAIT(CMD_RENAME_VEHICLE, CmdRenameVehicle, 0, CMDT_OTHER_MANAGEMENT)
37 DEF_CMD_TRAIT(CMD_CLONE_VEHICLE, CmdCloneVehicle, CMD_NO_TEST, CMDT_VEHICLE_CONSTRUCTION) // NewGRF callbacks influence building and refitting making it impossible to correctly estimate the cost
38 DEF_CMD_TRAIT(CMD_START_STOP_VEHICLE, CmdStartStopVehicle, CMD_LOCATION, CMDT_VEHICLE_MANAGEMENT)
39 DEF_CMD_TRAIT(CMD_MASS_START_STOP, CmdMassStartStopVehicle, 0, CMDT_VEHICLE_MANAGEMENT)
40 DEF_CMD_TRAIT(CMD_DEPOT_SELL_ALL_VEHICLES, CmdDepotSellAllVehicles, 0, CMDT_VEHICLE_CONSTRUCTION)
41 DEF_CMD_TRAIT(CMD_DEPOT_MASS_AUTOREPLACE, CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION)
42
43 void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, CargoArray);
44 void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool);
45
46 template <typename Tcont, typename Titer>
47 inline EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const VehicleListIdentifier &vli)
48 {
49 return buffer << vli.type << vli.vtype << vli.company << vli.index;
50 }
51
52 inline EndianBufferReader &operator >>(EndianBufferReader &buffer, VehicleListIdentifier &vli)
53 {
54 return buffer >> vli.type >> vli.vtype >> vli.company >> vli.index;
55 }
56
57 template <typename Tcont, typename Titer>
58 inline EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const CargoArray &cargo_array)
59 {
60 for (CargoID c = 0; c < NUM_CARGO; c++) {
61 buffer << cargo_array[c];
62 }
63 return buffer;
64 }
65
66 inline EndianBufferReader &operator >>(EndianBufferReader &buffer, CargoArray &cargo_array)
67 {
68 for (CargoID c = 0; c < NUM_CARGO; c++) {
69 buffer >> cargo_array[c];
70 }
71 return buffer;
72 }
73
74 #endif /* VEHICLE_CMD_H */
CmdBuildVehicle
std::tuple< CommandCost, VehicleID, uint, uint16, CargoArray > CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id)
Build a vehicle.
Definition: vehicle_cmd.cpp:87
CmdDepotSellAllVehicles
CommandCost CmdDepotSellAllVehicles(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
Sells all vehicles in a depot.
Definition: vehicle_cmd.cpp:681
VehicleListIdentifier::company
CompanyID company
The company associated with this list.
Definition: vehiclelist.h:32
Commands
Commands
List of commands.
Definition: command_type.h:176
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:29
CMDT_VEHICLE_CONSTRUCTION
@ CMDT_VEHICLE_CONSTRUCTION
Construction, modification (incl. refit) and destruction of vehicles.
Definition: command_type.h:396
vehiclelist.h
CMD_LOCATION
@ CMD_LOCATION
the command has implicit location argument.
Definition: command_type.h:389
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
CmdSendVehicleToDepot
CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli)
Send a vehicle to the depot.
Definition: vehicle_cmd.cpp:1038
CMD_CHANGE_SERVICE_INT
@ CMD_CHANGE_SERVICE_INT
change the server interval of a vehicle
Definition: command_type.h:232
CmdRenameVehicle
CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::string &text)
Give a custom name to your vehicle.
Definition: vehicle_cmd.cpp:1060
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:355
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
DepotCommand
DepotCommand
Flags for goto depot commands.
Definition: vehicle_type.h:65
CmdSellVehicle
CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
Sell a vehicle.
Definition: vehicle_cmd.cpp:216
CommandCost
Common return value for all commands.
Definition: command_type.h:24
CMDT_OTHER_MANAGEMENT
@ CMDT_OTHER_MANAGEMENT
Renaming stuff, changing company colours, placing signs, etc.
Definition: command_type.h:400
CcStartStopVehicle
void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool)
This is the Callback method after attempting to start/stop a vehicle.
Definition: vehicle_gui.cpp:2789
EndianBufferReader
Endian-aware buffer adapter that always reads values in little endian order.
Definition: endian_buffer.hpp:120
cargo_type.h
do_start
bool do_start
flag for starting playback of next_file at next opportunity
Definition: dmusic.cpp:126
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:47
CmdCloneVehicle
std::tuple< CommandCost, VehicleID > CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders)
Clone a vehicle.
Definition: vehicle_cmd.cpp:817
CMD_CLONE_VEHICLE
@ CMD_CLONE_VEHICLE
clone a vehicle
Definition: command_type.h:316
CMD_SEND_VEHICLE_TO_DEPOT
@ CMD_SEND_VEHICLE_TO_DEPOT
send a vehicle to a depot
Definition: command_type.h:219
CMD_MASS_START_STOP
@ CMD_MASS_START_STOP
start/stop all vehicles (in a depot)
Definition: command_type.h:318
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3359
CMD_CLIENT_ID
@ CMD_CLIENT_ID
set p2 with the ClientID of the sending client.
Definition: command_type.h:385
CMD_SELL_VEHICLE
@ CMD_SELL_VEHICLE
sell a vehicle
Definition: command_type.h:217
CMD_RENAME_VEHICLE
@ CMD_RENAME_VEHICLE
rename a whole vehicle
Definition: command_type.h:246
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
VehicleListIdentifier::index
uint32 index
A vehicle list type specific index.
Definition: vehiclelist.h:33
command_type.h
vehicle_type.h
CmdChangeServiceInt
CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16 serv_int, bool is_custom, bool is_percent)
Change the service interval of a vehicle.
Definition: vehicle_cmd.cpp:1098
CMDT_VEHICLE_MANAGEMENT
@ CMDT_VEHICLE_MANAGEMENT
Stopping, starting, sending to depot, turning around, replace orders etc.
Definition: command_type.h:398
CMD_START_STOP_VEHICLE
@ CMD_START_STOP_VEHICLE
start or stop a vehicle
Definition: command_type.h:317
engine_type.h
CMD_DEPOT_SELL_ALL_VEHICLES
@ CMD_DEPOT_SELL_ALL_VEHICLES
sell all vehicles which are in a given depot
Definition: command_type.h:320
VehicleListIdentifier::vtype
VehicleType vtype
The vehicle type associated with this list.
Definition: vehiclelist.h:31
VehicleListIdentifier::type
VehicleListType type
The type of vehicle list.
Definition: vehiclelist.h:30
CmdStartStopVehicle
CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool evaluate_startstop_cb)
Start/Stop a vehicle.
Definition: vehicle_cmd.cpp:563
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
CMD_NO_TEST
@ CMD_NO_TEST
the command's output may differ between test and execute due to town rating changes etc.
Definition: command_type.h:383
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
CMD_DEPOT_MASS_AUTOREPLACE
@ CMD_DEPOT_MASS_AUTOREPLACE
force the autoreplace to take action in a given depot
Definition: command_type.h:321
CMD_BUILD_VEHICLE
@ CMD_BUILD_VEHICLE
build a vehicle
Definition: command_type.h:216
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
EndianBufferWriter
Endian-aware buffer adapter that always writes values in little endian order.
Definition: endian_buffer.hpp:28
CMD_REFIT_VEHICLE
@ CMD_REFIT_VEHICLE
refit the cargo space of a vehicle
Definition: command_type.h:218
CmdMassStartStopVehicle
CommandCost CmdMassStartStopVehicle(DoCommandFlag flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli)
Starts or stops a lot of vehicles.
Definition: vehicle_cmd.cpp:645
CmdRefitVehicle
std::tuple< CommandCost, uint, uint16, CargoArray > CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8 num_vehicles)
Refits a vehicle to the specified cargo type.
Definition: vehicle_cmd.cpp:481
CmdDepotMassAutoReplace
CommandCost CmdDepotMassAutoReplace(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
Autoreplace all vehicles in the depot.
Definition: vehicle_cmd.cpp:715