OpenTTD Source: src/vehicle_cmd.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 "vehiclelist_cmd.h"
18#include "cargo_type.h"
19
20std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(DoCommandFlags flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoType cargo, ClientID client_id);
21 CommandCost CmdSellVehicle(DoCommandFlags flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id);
22std::tuple<CommandCost, uint, uint16_t, CargoArray> CmdRefitVehicle(DoCommandFlags flags, VehicleID veh_id, CargoType new_cargo_type, uint8_t new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles);
23 CommandCost CmdSendVehicleToDepot(DoCommandFlags flags, VehicleID veh_id, DepotCommandFlags depot_cmd, const VehicleListIdentifier &vli);
24 CommandCost CmdChangeServiceInt(DoCommandFlags flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent);
25 CommandCost CmdRenameVehicle(DoCommandFlags flags, VehicleID veh_id, const std::string &text);
26std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileIndex tile, VehicleID veh_id, bool share_orders);
27 CommandCost CmdStartStopVehicle(DoCommandFlags flags, VehicleID veh_id, bool evaluate_startstop_cb);
28 CommandCost CmdMassStartStopVehicle(DoCommandFlags flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli);
29 CommandCost CmdDepotSellAllVehicles(DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type);
30 CommandCost CmdDepotMassAutoReplace(DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type);
31
32DEF_CMD_TRAIT(CMD_BUILD_VEHICLE, CmdBuildVehicle, CommandFlag::ClientID, CommandType::VehicleConstruction)
33DEF_CMD_TRAIT(CMD_SELL_VEHICLE, CmdSellVehicle, CommandFlags({CommandFlag::ClientID, CommandFlag::Location}), CommandType::VehicleConstruction)
34DEF_CMD_TRAIT(CMD_REFIT_VEHICLE, CmdRefitVehicle, CommandFlag::Location, CommandType::VehicleConstruction)
35DEF_CMD_TRAIT(CMD_SEND_VEHICLE_TO_DEPOT, CmdSendVehicleToDepot, {}, CommandType::VehicleManagement)
36DEF_CMD_TRAIT(CMD_CHANGE_SERVICE_INT, CmdChangeServiceInt, {}, CommandType::VehicleManagement)
37DEF_CMD_TRAIT(CMD_RENAME_VEHICLE, CmdRenameVehicle, {}, CommandType::OtherManagement)
38DEF_CMD_TRAIT(CMD_CLONE_VEHICLE, CmdCloneVehicle, CommandFlag::NoTest, CommandType::VehicleConstruction) // NewGRF callbacks influence building and refitting making it impossible to correctly estimate the cost
39DEF_CMD_TRAIT(CMD_START_STOP_VEHICLE, CmdStartStopVehicle, CommandFlag::Location, CommandType::VehicleManagement)
40DEF_CMD_TRAIT(CMD_MASS_START_STOP, CmdMassStartStopVehicle, {}, CommandType::VehicleManagement)
41DEF_CMD_TRAIT(CMD_DEPOT_SELL_ALL_VEHICLES, CmdDepotSellAllVehicles, {}, CommandType::VehicleConstruction)
42DEF_CMD_TRAIT(CMD_DEPOT_MASS_AUTOREPLACE, CmdDepotMassAutoReplace, {}, CommandType::VehicleConstruction)
43
44void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray);
45void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool);
46
47template <typename Tcont, typename Titer>
48inline EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const CargoArray &cargo_array)
49{
50 for (const uint &amt : cargo_array) {
51 buffer << amt;
52 }
53 return buffer;
54}
55
56inline EndianBufferReader &operator >>(EndianBufferReader &buffer, CargoArray &cargo_array)
57{
58 for (uint &amt : cargo_array) {
59 buffer >> amt;
60 }
61 return buffer;
62}
63
64#endif /* VEHICLE_CMD_H */
cargo_type.h
Types related to cargoes...
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
CommandCost
Common return value for all commands.
Definition command_type.h:24
EndianBufferReader
Endian-aware buffer adapter that always reads values in little endian order.
Definition endian_buffer.hpp:145
EndianBufferWriter
Endian-aware buffer adapter that always writes values in little endian order.
Definition endian_buffer.hpp:24
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
command_type.h
Types related to commands.
CommandType::VehicleConstruction
@ VehicleConstruction
Construction, modification (incl. refit) and destruction of vehicles.
CommandType::OtherManagement
@ OtherManagement
Renaming stuff, changing company colours, placing signs, etc.
CommandType::VehicleManagement
@ VehicleManagement
Stopping, starting, sending to depot, turning around, replace orders etc.
CommandFlag::ClientID
@ ClientID
set p2 with the ClientID of the sending client.
CommandFlag::Location
@ Location
the command has implicit location argument.
CommandFlag::NoTest
@ NoTest
the command's output may differ between test and execute due to town rating changes etc.
Commands
Commands
List of commands.
Definition command_type.h:196
CMD_MASS_START_STOP
@ CMD_MASS_START_STOP
start/stop all vehicles (in a depot)
Definition command_type.h:349
CMD_SELL_VEHICLE
@ CMD_SELL_VEHICLE
sell a vehicle
Definition command_type.h:241
CMD_CLONE_VEHICLE
@ CMD_CLONE_VEHICLE
clone a vehicle
Definition command_type.h:347
CMD_BUILD_VEHICLE
@ CMD_BUILD_VEHICLE
build a vehicle
Definition command_type.h:240
CMD_DEPOT_SELL_ALL_VEHICLES
@ CMD_DEPOT_SELL_ALL_VEHICLES
sell all vehicles which are in a given depot
Definition command_type.h:351
CMD_REFIT_VEHICLE
@ CMD_REFIT_VEHICLE
refit the cargo space of a vehicle
Definition command_type.h:242
CMD_RENAME_VEHICLE
@ CMD_RENAME_VEHICLE
rename a whole vehicle
Definition command_type.h:274
CMD_DEPOT_MASS_AUTOREPLACE
@ CMD_DEPOT_MASS_AUTOREPLACE
force the autoreplace to take action in a given depot
Definition command_type.h:352
CMD_SEND_VEHICLE_TO_DEPOT
@ CMD_SEND_VEHICLE_TO_DEPOT
send a vehicle to a depot
Definition command_type.h:243
CMD_START_STOP_VEHICLE
@ CMD_START_STOP_VEHICLE
start or stop a vehicle
Definition command_type.h:348
CMD_CHANGE_SERVICE_INT
@ CMD_CHANGE_SERVICE_INT
change the server interval of a vehicle
Definition command_type.h:256
do_start
bool do_start
flag for starting playback of next_file at next opportunity
Definition dmusic.cpp:122
engine_type.h
Types related to engines.
ClientID
ClientID
'Unique' identifier to be given to clients
Definition network_type.h:43
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:111
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF >
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
VehicleListIdentifier
The information about a vehicle list.
Definition vehiclelist.h:32
CmdMassStartStopVehicle
CommandCost CmdMassStartStopVehicle(DoCommandFlags flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli)
Starts or stops a lot of vehicles.
Definition vehicle_cmd.cpp:666
CmdDepotSellAllVehicles
CommandCost CmdDepotSellAllVehicles(DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type)
Sells all vehicles in a depot.
Definition vehicle_cmd.cpp:700
CmdCloneVehicle
std::tuple< CommandCost, VehicleID > CmdCloneVehicle(DoCommandFlags flags, TileIndex tile, VehicleID veh_id, bool share_orders)
Clone a vehicle.
Definition vehicle_cmd.cpp:830
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:2921
CmdChangeServiceInt
CommandCost CmdChangeServiceInt(DoCommandFlags flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent)
Change the service interval of a vehicle.
Definition vehicle_cmd.cpp:1116
CmdSellVehicle
CommandCost CmdSellVehicle(DoCommandFlags flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
Sell a vehicle.
Definition vehicle_cmd.cpp:236
CmdSendVehicleToDepot
CommandCost CmdSendVehicleToDepot(DoCommandFlags flags, VehicleID veh_id, DepotCommandFlags depot_cmd, const VehicleListIdentifier &vli)
Send a vehicle to the depot.
Definition vehicle_cmd.cpp:1056
CmdRefitVehicle
std::tuple< CommandCost, uint, uint16_t, CargoArray > CmdRefitVehicle(DoCommandFlags flags, VehicleID veh_id, CargoType new_cargo_type, uint8_t new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles)
Refits a vehicle to the specified cargo type.
Definition vehicle_cmd.cpp:493
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
Definition vehicle_gui.cpp:3495
CmdRenameVehicle
CommandCost CmdRenameVehicle(DoCommandFlags flags, VehicleID veh_id, const std::string &text)
Give a custom name to your vehicle.
Definition vehicle_cmd.cpp:1078
CmdStartStopVehicle
CommandCost CmdStartStopVehicle(DoCommandFlags flags, VehicleID veh_id, bool evaluate_startstop_cb)
Start/Stop a vehicle.
Definition vehicle_cmd.cpp:575
CmdDepotMassAutoReplace
CommandCost CmdDepotMassAutoReplace(DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type)
Autoreplace all vehicles in the depot.
Definition vehicle_cmd.cpp:734
CmdBuildVehicle
std::tuple< CommandCost, VehicleID, uint, uint16_t, CargoArray > CmdBuildVehicle(DoCommandFlags flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoType cargo, ClientID client_id)
Build a vehicle.
Definition vehicle_cmd.cpp:100
vehicle_type.h
Types related to vehicles.
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
vehiclelist.h
Functions and type for generating vehicle lists.
vehiclelist_cmd.h
Functions and type for serializing vehicle lists.