2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2007-12-21 21:50:46 +00:00
|
|
|
/** @file command_func.h Functions related to commands. */
|
|
|
|
|
|
|
|
#ifndef COMMAND_FUNC_H
|
|
|
|
#define COMMAND_FUNC_H
|
|
|
|
|
|
|
|
#include "command_type.h"
|
2010-01-11 20:32:32 +00:00
|
|
|
#include "company_type.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define a default return value for a failed command.
|
|
|
|
*
|
|
|
|
* This variable contains a CommandCost object with is declared as "failed".
|
|
|
|
* Other functions just need to return this error if there is an error,
|
|
|
|
* which doesn't need to specific by a StringID.
|
|
|
|
*/
|
|
|
|
static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns from a function with a specific StringID as error.
|
|
|
|
*
|
|
|
|
* This macro is used to return from a function. The parameter contains the
|
|
|
|
* StringID which will be returned.
|
|
|
|
*
|
|
|
|
* @param errcode The StringID to return
|
|
|
|
*/
|
|
|
|
#define return_cmd_error(errcode) return CommandCost(errcode);
|
|
|
|
|
2021-10-03 19:13:32 +00:00
|
|
|
CommandCost DoCommand(DoCommandFlag flags, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
|
2007-12-21 21:50:46 +00:00
|
|
|
|
2021-10-03 19:13:32 +00:00
|
|
|
bool DoCommandP(Commands cmd, StringID err_message, CommandCallback *callback, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
|
|
|
bool DoCommandP(Commands cmd, StringID err_message, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
|
|
|
bool DoCommandP(Commands cmd, CommandCallback *callback, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
|
|
|
bool DoCommandP(Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
|
|
|
bool DoCommandP(const CommandContainer *container, bool my_cmd = true, bool network_command = false);
|
2007-12-21 21:50:46 +00:00
|
|
|
|
2021-10-03 19:13:32 +00:00
|
|
|
CommandCost DoCommandPInternal(Commands cmd, StringID err_message, CommandCallback *callback, bool my_cmd, bool estimate_only, bool network_command, TileIndex tile, uint32 p1, uint32 p2, const std::string &text);
|
2010-01-11 20:39:38 +00:00
|
|
|
|
2021-10-03 19:13:32 +00:00
|
|
|
void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, TileIndex tile, uint32 p1, uint32 p2, const std::string &text);
|
2007-12-21 21:50:46 +00:00
|
|
|
|
2007-12-21 22:50:51 +00:00
|
|
|
extern Money _additional_cash_required;
|
2007-12-21 21:50:46 +00:00
|
|
|
|
2021-10-05 20:02:27 +00:00
|
|
|
bool IsValidCommand(Commands cmd);
|
2021-10-03 19:13:32 +00:00
|
|
|
CommandFlags GetCommandFlags(Commands cmd);
|
|
|
|
const char *GetCommandName(Commands cmd);
|
2007-12-21 21:50:46 +00:00
|
|
|
Money GetAvailableMoneyForCommand();
|
2021-10-05 20:02:27 +00:00
|
|
|
bool IsCommandAllowedWhilePaused(Commands cmd);
|
2010-12-07 21:08:35 +00:00
|
|
|
|
2009-01-12 15:27:39 +00:00
|
|
|
/**
|
|
|
|
* Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
|
|
|
|
* @param cmd_flags Flags from GetCommandFlags
|
|
|
|
* @return flags for DoCommand
|
|
|
|
*/
|
2011-11-14 20:38:56 +00:00
|
|
|
static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
|
2009-01-12 15:27:39 +00:00
|
|
|
{
|
2009-02-09 21:20:05 +00:00
|
|
|
DoCommandFlag flags = DC_NONE;
|
2009-01-12 15:27:39 +00:00
|
|
|
if (cmd_flags & CMD_NO_WATER) flags |= DC_NO_WATER;
|
|
|
|
if (cmd_flags & CMD_AUTO) flags |= DC_AUTO;
|
2009-01-21 02:31:55 +00:00
|
|
|
if (cmd_flags & CMD_ALL_TILES) flags |= DC_ALL_TILES;
|
2009-01-12 15:27:39 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2007-12-21 21:50:46 +00:00
|
|
|
#endif /* COMMAND_FUNC_H */
|