2007-12-21 21:50:46 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a command
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text = NULL);
|
|
|
|
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
|
2007-12-21 21:50:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a network safe DoCommand function
|
|
|
|
*/
|
2008-12-28 14:37:19 +00:00
|
|
|
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = NULL, const char *text = NULL, bool my_cmd = true);
|
2009-01-08 14:55:28 +00:00
|
|
|
bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
|
2007-12-21 21:50:46 +00:00
|
|
|
|
2010-01-11 20:39:38 +00:00
|
|
|
/** Internal helper function for DoCommandP. Do not use. */
|
|
|
|
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only);
|
|
|
|
|
2007-12-21 21:50:46 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
/**
|
|
|
|
* Send a command over the network
|
|
|
|
*/
|
2010-01-11 20:32:32 +00:00
|
|
|
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company);
|
2007-12-21 21:50:46 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2007-12-21 22:50:51 +00:00
|
|
|
extern Money _additional_cash_required;
|
2007-12-21 21:50:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a integer value belongs to a command.
|
|
|
|
*/
|
|
|
|
bool IsValidCommand(uint32 cmd);
|
|
|
|
/**
|
|
|
|
* Returns the flags from a given command.
|
|
|
|
*/
|
|
|
|
byte GetCommandFlags(uint32 cmd);
|
2010-04-11 10:11:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the name of a given command.
|
|
|
|
*/
|
|
|
|
const char *GetCommandName(uint32 cmd);
|
2007-12-21 21:50:46 +00:00
|
|
|
/**
|
|
|
|
* Returns the current money available which can be used for a command.
|
|
|
|
*/
|
|
|
|
Money GetAvailableMoneyForCommand();
|
|
|
|
|
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
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
static inline DoCommandFlag CommandFlagsToDCFlags(uint 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;
|
|
|
|
}
|
|
|
|
|
2010-01-11 18:46:09 +00:00
|
|
|
/*** All command callbacks that exist ***/
|
|
|
|
|
|
|
|
/* ai/ai_core.cpp */
|
|
|
|
CommandCallback CcAI;
|
|
|
|
|
|
|
|
/* airport_gui.cpp */
|
|
|
|
CommandCallback CcBuildAirport;
|
|
|
|
|
|
|
|
/* bridge_gui.cpp */
|
|
|
|
CommandCallback CcBuildBridge;
|
|
|
|
|
|
|
|
/* dock_gui.cpp */
|
|
|
|
CommandCallback CcBuildDocks;
|
|
|
|
CommandCallback CcBuildCanal;
|
|
|
|
|
|
|
|
/* depot_gui.cpp */
|
|
|
|
CommandCallback CcCloneVehicle;
|
|
|
|
|
|
|
|
/* group_gui.cpp */
|
|
|
|
CommandCallback CcCreateGroup;
|
|
|
|
|
2010-03-14 19:59:45 +00:00
|
|
|
/* industry_gui.cpp */
|
|
|
|
CommandCallback CcBuildIndustry;
|
|
|
|
|
2010-01-11 18:46:09 +00:00
|
|
|
/* main_gui.cpp */
|
|
|
|
CommandCallback CcPlaySound10;
|
|
|
|
CommandCallback CcPlaceSign;
|
|
|
|
CommandCallback CcTerraform;
|
|
|
|
CommandCallback CcGiveMoney;
|
|
|
|
|
|
|
|
/* rail_gui.cpp */
|
|
|
|
CommandCallback CcPlaySound1E;
|
|
|
|
CommandCallback CcRailDepot;
|
|
|
|
CommandCallback CcStation;
|
|
|
|
CommandCallback CcBuildRailTunnel;
|
|
|
|
|
|
|
|
/* road_gui.cpp */
|
|
|
|
CommandCallback CcPlaySound1D;
|
|
|
|
CommandCallback CcBuildRoadTunnel;
|
|
|
|
CommandCallback CcRoadDepot;
|
2010-02-24 21:45:23 +00:00
|
|
|
CommandCallback CcRoadStop;
|
2010-01-11 18:46:09 +00:00
|
|
|
|
|
|
|
/* train_gui.cpp */
|
|
|
|
CommandCallback CcBuildWagon;
|
|
|
|
|
|
|
|
/* town_gui.cpp */
|
|
|
|
CommandCallback CcFoundTown;
|
|
|
|
CommandCallback CcFoundRandomTown;
|
|
|
|
|
|
|
|
/* vehicle_gui.cpp */
|
2010-01-11 18:34:02 +00:00
|
|
|
CommandCallback CcBuildPrimaryVehicle;
|
2010-04-24 20:55:51 +00:00
|
|
|
CommandCallback CcStartStopVehicle;
|
2010-01-11 18:34:02 +00:00
|
|
|
|
2007-12-21 21:50:46 +00:00
|
|
|
#endif /* COMMAND_FUNC_H */
|