mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Add auxiliary data only command argument form
This commit is contained in:
parent
64d312d028
commit
78a42e3196
@ -614,6 +614,20 @@ DECLARE_ENUM_AS_BIT_SET(CommandLogEntryFlag)
|
||||
|
||||
extern uint32_t _frame_counter;
|
||||
|
||||
/**
|
||||
* This function mask the parameter with CMD_ID_MASK and returns
|
||||
* the argument mode which belongs to the given command.
|
||||
*
|
||||
* @param cmd The integer value of the command
|
||||
* @return The argument mode for this command
|
||||
*/
|
||||
static CommandArgMode GetCommandArgMode(uint32_t cmd)
|
||||
{
|
||||
assert(IsValidCommand(cmd));
|
||||
|
||||
return _command_proc_table[cmd & CMD_ID_MASK].mode;
|
||||
}
|
||||
|
||||
struct CommandLogEntry {
|
||||
std::string text;
|
||||
TileIndex tile;
|
||||
@ -684,10 +698,12 @@ static void DumpSubCommandLogEntry(char *&buffer, const char *last, const Comman
|
||||
fc(CLEF_ORDER_BACKUP, 'o'), fc(CLEF_RANDOM, 'r'), fc(CLEF_TWICE, '2'),
|
||||
script_fc(), fc(CLEF_AUX_DATA, 'b'), fc(CLEF_MY_CMD, 'm'), fc(CLEF_ONLY_SENDING, 's'),
|
||||
fc(CLEF_ESTIMATE_ONLY, 'e'), fc(CLEF_TEXT, 't'), fc(CLEF_GENERATING_WORLD, 'g'), fc(CLEF_CMD_FAILED, 'f'));
|
||||
buffer += seprintf(buffer, last, " %7d x %7d, p1: 0x%08X, p2: 0x%08X, ",
|
||||
TileX(entry.tile), TileY(entry.tile), entry.p1, entry.p2);
|
||||
if (entry.p3 != 0) {
|
||||
buffer += seprintf(buffer, last, "p3: 0x" OTTD_PRINTFHEX64PAD ", ", entry.p3);
|
||||
buffer += seprintf(buffer, last, " %7d x %7d, ", TileX(entry.tile), TileY(entry.tile));
|
||||
if (GetCommandArgMode(entry.cmd) != CMD_ARG_AUX) {
|
||||
buffer += seprintf(buffer, last, "p1: 0x%08X, p2: 0x%08X, ", entry.p1, entry.p2);
|
||||
if (entry.p3 != 0) {
|
||||
buffer += seprintf(buffer, last, "p3: 0x" OTTD_PRINTFHEX64PAD ", ", entry.p3);
|
||||
}
|
||||
}
|
||||
buffer += seprintf(buffer, last, "cc: %3u, lc: %3u, ", (uint) entry.current_company, (uint) entry.local_company);
|
||||
if (_network_server) {
|
||||
|
@ -36,8 +36,14 @@ CommandCost DoCommandEx(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, D
|
||||
|
||||
inline CommandCost DoCommand(TileIndex tile, uint32_t p1, uint32_t p2, DoCommandFlag flags, uint32_t cmd, const char *text = nullptr)
|
||||
{
|
||||
return DoCommandEx(tile, p1, p2, 0, flags, cmd, text, 0);
|
||||
return DoCommandEx(tile, p1, p2, 0, flags, cmd, text, nullptr);
|
||||
}
|
||||
|
||||
inline CommandCost DoCommandAux(TileIndex tile, const CommandAuxiliaryBase *aux_data, DoCommandFlag flags, uint32_t cmd)
|
||||
{
|
||||
return DoCommandEx(tile, 0, 0, 0, flags, cmd, nullptr, aux_data);
|
||||
}
|
||||
|
||||
inline CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
|
||||
{
|
||||
return DoCommandEx(container->tile, container->p1, container->p2, container->p3, flags, container->cmd & CMD_ID_MASK, container->text.c_str(), container->aux_data.get());
|
||||
@ -47,7 +53,12 @@ bool DoCommandPEx(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_
|
||||
|
||||
inline bool DoCommandP(TileIndex tile, uint32_t p1, uint32_t p2, uint32_t cmd, CommandCallback *callback = nullptr, const char *text = nullptr, bool my_cmd = true)
|
||||
{
|
||||
return DoCommandPEx(tile, p1, p2, 0, cmd, callback, text, 0, my_cmd);
|
||||
return DoCommandPEx(tile, p1, p2, 0, cmd, callback, text, nullptr, my_cmd);
|
||||
}
|
||||
|
||||
inline bool DoCommandPAux(TileIndex tile, const CommandAuxiliaryBase *aux_data, uint32_t cmd, CommandCallback *callback = nullptr, bool my_cmd = true)
|
||||
{
|
||||
return DoCommandPEx(tile, 0, 0, 0, cmd, callback, nullptr, aux_data, my_cmd);
|
||||
}
|
||||
|
||||
inline bool DoCommandP(const CommandContainer *container, bool my_cmd = true)
|
||||
|
@ -598,7 +598,7 @@ static_assert(CMD_END <= CMD_ID_MASK + 1);
|
||||
*
|
||||
* This enumeration defines flags for the _command_proc_table.
|
||||
*/
|
||||
enum CommandFlags {
|
||||
enum CommandFlags : uint16_t {
|
||||
CMD_SERVER = 0x001, ///< the command can only be initiated by the server
|
||||
CMD_SPECTATOR = 0x002, ///< the command may be initiated by a spectator
|
||||
CMD_OFFLINE = 0x004, ///< the command cannot be executed in a multiplayer game; single-player only
|
||||
@ -610,13 +610,18 @@ enum CommandFlags {
|
||||
CMD_DEITY = 0x100, ///< the command may be executed by COMPANY_DEITY
|
||||
CMD_STR_CTRL = 0x200, ///< the command's string may contain control strings
|
||||
CMD_NO_EST = 0x400, ///< the command is never estimated.
|
||||
CMD_PROCEX = 0x800, ///< the command proc function has extended parameters
|
||||
CMD_SERVER_NS = 0x1000, ///< the command can only be initiated by the server (this is not executed in spectator mode)
|
||||
CMD_LOG_AUX = 0x2000, ///< the command should be logged in the auxiliary log instead of the main log
|
||||
CMD_P1_TILE = 0x4000, ///< use p1 for money text and error tile
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(CommandFlags)
|
||||
|
||||
enum CommandArgMode : uint8_t {
|
||||
CMD_ARG_STD,
|
||||
CMD_ARG_EX,
|
||||
CMD_ARG_AUX,
|
||||
};
|
||||
|
||||
/** Types of commands we have. */
|
||||
enum CommandType {
|
||||
CMDT_LANDSCAPE_CONSTRUCTION, ///< Construction and destruction of objects on the map.
|
||||
@ -662,6 +667,7 @@ struct CommandAuxiliaryBase;
|
||||
*/
|
||||
typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text);
|
||||
typedef CommandCost CommandProcEx(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, uint64_t p3, const char *text, const CommandAuxiliaryBase *aux_data);
|
||||
typedef CommandCost CommandProcAux(TileIndex tile, DoCommandFlag flags, const CommandAuxiliaryBase *aux_data);
|
||||
|
||||
/**
|
||||
* Define a command with the flags which belongs to it.
|
||||
@ -673,21 +679,33 @@ struct Command {
|
||||
union {
|
||||
CommandProc *proc; ///< The procedure to actually execute
|
||||
CommandProcEx *procex; ///< The procedure to actually execute, extended parameters
|
||||
CommandProcAux *procaux; ///< The procedure to actually execute, only auxiliary parameter
|
||||
};
|
||||
const char *name; ///< A human readable name for the procedure
|
||||
CommandFlags flags; ///< The (command) flags to that apply to this command
|
||||
CommandType type; ///< The type of command.
|
||||
CommandArgMode mode; ///< The command argument mode
|
||||
|
||||
Command(CommandProc *proc, const char *name, CommandFlags flags, CommandType type)
|
||||
: proc(proc), name(name), flags(flags & ~CMD_PROCEX), type(type) {}
|
||||
: proc(proc), name(name), flags(flags), type(type), mode(CMD_ARG_STD) {}
|
||||
Command(CommandProcEx *procex, const char *name, CommandFlags flags, CommandType type)
|
||||
: procex(procex), name(name), flags(flags | CMD_PROCEX), type(type) {}
|
||||
: procex(procex), name(name), flags(flags), type(type), mode(CMD_ARG_EX) {}
|
||||
Command(CommandProcAux *procaux, const char *name, CommandFlags flags, CommandType type)
|
||||
: procaux(procaux), name(name), flags(flags), type(type), mode(CMD_ARG_AUX) {}
|
||||
|
||||
inline CommandCost Execute(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, uint64_t p3, const char *text, const CommandAuxiliaryBase *aux_data) const {
|
||||
if (this->flags & CMD_PROCEX) {
|
||||
return this->procex(tile, flags, p1, p2, p3, text, aux_data);
|
||||
} else {
|
||||
return this->proc(tile, flags, p1, p2, text);
|
||||
switch (this->mode) {
|
||||
case CMD_ARG_STD:
|
||||
return this->proc(tile, flags, p1, p2, text);
|
||||
|
||||
case CMD_ARG_EX:
|
||||
return this->procex(tile, flags, p1, p2, p3, text, aux_data);
|
||||
|
||||
case CMD_ARG_AUX:
|
||||
return this->procaux(tile, flags, aux_data);
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user