2009-08-21 22:21:05 +02: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 22:50:46 +01:00
|
|
|
/** @file command_func.h Functions related to commands. */
|
|
|
|
|
|
|
|
#ifndef COMMAND_FUNC_H
|
|
|
|
#define COMMAND_FUNC_H
|
|
|
|
|
|
|
|
#include "command_type.h"
|
2010-01-11 21:32:32 +01:00
|
|
|
#include "company_type.h"
|
2007-12-21 22:50:46 +01: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 15:39:49 +02:00
|
|
|
CommandCost DoCommand(DoCommandFlag flags, uint32 cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
|
2007-12-21 22:50:46 +01:00
|
|
|
|
2021-10-03 17:15:48 +02:00
|
|
|
bool DoCommandP(uint32 cmd, CommandCallback *callback, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
|
|
|
bool DoCommandP(uint32 cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
|
2009-01-08 15:55:28 +01:00
|
|
|
bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
|
2007-12-21 22:50:46 +01:00
|
|
|
|
2021-10-03 17:15:48 +02:00
|
|
|
CommandCost DoCommandPInternal(uint32 cmd, CommandCallback *callback, bool my_cmd, bool estimate_only, TileIndex tile, uint32 p1, uint32 p2, const std::string &text);
|
2010-01-11 21:39:38 +01:00
|
|
|
|
2021-10-03 17:15:48 +02:00
|
|
|
void NetworkSendCommand(uint32 cmd, CommandCallback *callback, CompanyID company, TileIndex tile, uint32 p1, uint32 p2, const std::string &text);
|
2007-12-21 22:50:46 +01:00
|
|
|
|
2007-12-21 23:50:51 +01:00
|
|
|
extern Money _additional_cash_required;
|
2007-12-21 22:50:46 +01:00
|
|
|
|
|
|
|
bool IsValidCommand(uint32 cmd);
|
2011-11-14 21:38:56 +01:00
|
|
|
CommandFlags GetCommandFlags(uint32 cmd);
|
2010-04-11 12:11:26 +02:00
|
|
|
const char *GetCommandName(uint32 cmd);
|
2007-12-21 22:50:46 +01:00
|
|
|
Money GetAvailableMoneyForCommand();
|
2010-12-07 22:08:35 +01:00
|
|
|
bool IsCommandAllowedWhilePaused(uint32 cmd);
|
|
|
|
|
2009-01-12 16:27:39 +01: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 21:38:56 +01:00
|
|
|
static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
|
2009-01-12 16:27:39 +01:00
|
|
|
{
|
2009-02-09 22:20:05 +01:00
|
|
|
DoCommandFlag flags = DC_NONE;
|
2009-01-12 16:27:39 +01:00
|
|
|
if (cmd_flags & CMD_NO_WATER) flags |= DC_NO_WATER;
|
|
|
|
if (cmd_flags & CMD_AUTO) flags |= DC_AUTO;
|
2009-01-21 03:31:55 +01:00
|
|
|
if (cmd_flags & CMD_ALL_TILES) flags |= DC_ALL_TILES;
|
2009-01-12 16:27:39 +01:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2010-01-11 19:46:09 +01:00
|
|
|
/*** All command callbacks that exist ***/
|
|
|
|
|
2011-11-30 00:21:42 +01:00
|
|
|
/* ai/ai_instance.cpp */
|
2010-01-11 19:46:09 +01:00
|
|
|
CommandCallback CcAI;
|
|
|
|
|
|
|
|
/* airport_gui.cpp */
|
|
|
|
CommandCallback CcBuildAirport;
|
|
|
|
|
|
|
|
/* bridge_gui.cpp */
|
|
|
|
CommandCallback CcBuildBridge;
|
|
|
|
|
|
|
|
/* dock_gui.cpp */
|
|
|
|
CommandCallback CcBuildDocks;
|
2021-02-20 19:01:04 +01:00
|
|
|
CommandCallback CcPlaySound_CONSTRUCTION_WATER;
|
2010-01-11 19:46:09 +01:00
|
|
|
|
|
|
|
/* depot_gui.cpp */
|
|
|
|
CommandCallback CcCloneVehicle;
|
|
|
|
|
2011-12-19 21:50:54 +01:00
|
|
|
/* game/game_instance.cpp */
|
|
|
|
CommandCallback CcGame;
|
|
|
|
|
2010-01-11 19:46:09 +01:00
|
|
|
/* group_gui.cpp */
|
|
|
|
CommandCallback CcCreateGroup;
|
2012-04-17 21:44:16 +02:00
|
|
|
CommandCallback CcAddVehicleNewGroup;
|
2010-01-11 19:46:09 +01:00
|
|
|
|
2010-03-14 20:59:45 +01:00
|
|
|
/* industry_gui.cpp */
|
|
|
|
CommandCallback CcBuildIndustry;
|
|
|
|
|
2010-01-11 19:46:09 +01:00
|
|
|
/* main_gui.cpp */
|
2016-05-22 12:07:48 +02:00
|
|
|
CommandCallback CcPlaySound_EXPLOSION;
|
2010-01-11 19:46:09 +01:00
|
|
|
CommandCallback CcPlaceSign;
|
|
|
|
CommandCallback CcTerraform;
|
|
|
|
|
|
|
|
/* rail_gui.cpp */
|
2021-02-20 19:01:04 +01:00
|
|
|
CommandCallback CcPlaySound_CONSTRUCTION_RAIL;
|
2010-01-11 19:46:09 +01:00
|
|
|
CommandCallback CcRailDepot;
|
|
|
|
CommandCallback CcStation;
|
|
|
|
CommandCallback CcBuildRailTunnel;
|
|
|
|
|
|
|
|
/* road_gui.cpp */
|
2021-02-20 19:01:04 +01:00
|
|
|
CommandCallback CcPlaySound_CONSTRUCTION_OTHER;
|
2010-01-11 19:46:09 +01:00
|
|
|
CommandCallback CcBuildRoadTunnel;
|
|
|
|
CommandCallback CcRoadDepot;
|
2010-02-24 22:45:23 +01:00
|
|
|
CommandCallback CcRoadStop;
|
2010-01-11 19:46:09 +01:00
|
|
|
|
|
|
|
/* train_gui.cpp */
|
|
|
|
CommandCallback CcBuildWagon;
|
|
|
|
|
|
|
|
/* town_gui.cpp */
|
|
|
|
CommandCallback CcFoundTown;
|
|
|
|
CommandCallback CcFoundRandomTown;
|
|
|
|
|
|
|
|
/* vehicle_gui.cpp */
|
2010-01-11 19:34:02 +01:00
|
|
|
CommandCallback CcBuildPrimaryVehicle;
|
2010-04-24 22:55:51 +02:00
|
|
|
CommandCallback CcStartStopVehicle;
|
2010-01-11 19:34:02 +01:00
|
|
|
|
2007-12-21 22:50:46 +01:00
|
|
|
#endif /* COMMAND_FUNC_H */
|