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);
|
|
|
|
|
2022-12-07 20:37:23 +00:00
|
|
|
CommandCost DoCommandEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, DoCommandFlag flags, uint32 cmd, const char *text = nullptr, const CommandAuxiliaryBase *aux_data = nullptr);
|
2007-12-21 21:50:46 +00:00
|
|
|
|
2020-10-17 13:42:46 +00:00
|
|
|
inline CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text = nullptr)
|
|
|
|
{
|
|
|
|
return DoCommandEx(tile, p1, p2, 0, flags, cmd, text, 0);
|
|
|
|
}
|
|
|
|
inline CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
|
|
|
|
{
|
2022-12-07 20:37:23 +00:00
|
|
|
return DoCommandEx(container->tile, container->p1, container->p2, container->p3, flags, container->cmd & CMD_ID_MASK, container->text.c_str(), container->aux_data.get());
|
2020-10-17 13:42:46 +00:00
|
|
|
}
|
2007-12-21 21:50:46 +00:00
|
|
|
|
2022-12-07 20:37:23 +00:00
|
|
|
bool DoCommandPEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, const CommandAuxiliaryBase *aux_data, bool my_cmd = true);
|
2010-01-11 20:39:38 +00:00
|
|
|
|
2020-10-17 13:42:46 +00:00
|
|
|
inline bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = nullptr, const char *text = nullptr, bool my_cmd = true)
|
|
|
|
{
|
|
|
|
return DoCommandPEx(tile, p1, p2, 0, cmd, callback, text, 0, my_cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool DoCommandP(const CommandContainer *container, bool my_cmd = true)
|
|
|
|
{
|
2022-12-07 20:37:23 +00:00
|
|
|
return DoCommandPEx(container->tile, container->p1, container->p2, container->p3, container->cmd, container->callback, container->text.c_str(), container->aux_data.get(), my_cmd);
|
2020-10-17 13:42:46 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 19:52:08 +00:00
|
|
|
CommandCost DoCommandPScript(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, bool asynchronous, const CommandAuxiliaryBase *aux_data);
|
2022-12-07 20:37:23 +00:00
|
|
|
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, const CommandAuxiliaryBase *aux_data);
|
2020-10-17 13:42:46 +00:00
|
|
|
|
2022-12-07 20:37:23 +00:00
|
|
|
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company, const CommandAuxiliaryBase *aux_data);
|
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
|
|
|
|
|
|
|
bool IsValidCommand(uint32 cmd);
|
2011-11-14 20:38:56 +00:00
|
|
|
CommandFlags GetCommandFlags(uint32 cmd);
|
2010-04-11 10:11:26 +00:00
|
|
|
const char *GetCommandName(uint32 cmd);
|
2007-12-21 21:50:46 +00:00
|
|
|
Money GetAvailableMoneyForCommand();
|
2010-12-07 21:08:35 +00:00
|
|
|
bool IsCommandAllowedWhilePaused(uint32 cmd);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-21 21:04:28 +00:00
|
|
|
void ClearCommandLog();
|
|
|
|
char *DumpCommandLog(char *buffer, const char *last);
|
|
|
|
|
2022-09-14 20:55:28 +00:00
|
|
|
void ExecuteCommandQueue();
|
|
|
|
void ClearCommandQueue();
|
|
|
|
void EnqueueDoCommandP(CommandContainer cmd);
|
|
|
|
|
2010-01-11 18:46:09 +00:00
|
|
|
/*** All command callbacks that exist ***/
|
|
|
|
|
2011-11-29 23:21:42 +00:00
|
|
|
/* ai/ai_instance.cpp */
|
2010-01-11 18:46:09 +00:00
|
|
|
CommandCallback CcAI;
|
|
|
|
|
|
|
|
/* airport_gui.cpp */
|
|
|
|
CommandCallback CcBuildAirport;
|
|
|
|
|
|
|
|
/* bridge_gui.cpp */
|
|
|
|
CommandCallback CcBuildBridge;
|
|
|
|
|
|
|
|
/* dock_gui.cpp */
|
|
|
|
CommandCallback CcBuildDocks;
|
2021-02-20 18:01:04 +00:00
|
|
|
CommandCallback CcPlaySound_CONSTRUCTION_WATER;
|
2010-01-11 18:46:09 +00:00
|
|
|
|
|
|
|
/* depot_gui.cpp */
|
|
|
|
CommandCallback CcCloneVehicle;
|
|
|
|
|
2011-12-19 20:50:54 +00:00
|
|
|
/* game/game_instance.cpp */
|
|
|
|
CommandCallback CcGame;
|
|
|
|
|
2010-01-11 18:46:09 +00:00
|
|
|
/* group_gui.cpp */
|
|
|
|
CommandCallback CcCreateGroup;
|
2012-04-17 19:44:16 +00:00
|
|
|
CommandCallback CcAddVehicleNewGroup;
|
2010-01-11 18:46:09 +00:00
|
|
|
|
2010-03-14 19:59:45 +00:00
|
|
|
/* industry_gui.cpp */
|
|
|
|
CommandCallback CcBuildIndustry;
|
|
|
|
|
2010-01-11 18:46:09 +00:00
|
|
|
/* main_gui.cpp */
|
2016-05-22 10:07:48 +00:00
|
|
|
CommandCallback CcPlaySound_EXPLOSION;
|
2010-01-11 18:46:09 +00:00
|
|
|
CommandCallback CcPlaceSign;
|
|
|
|
CommandCallback CcTerraform;
|
|
|
|
CommandCallback CcGiveMoney;
|
|
|
|
|
2015-08-02 18:37:42 +00:00
|
|
|
/* plans_gui.cpp */
|
|
|
|
CommandCallback CcAddPlan;
|
|
|
|
|
2010-01-11 18:46:09 +00:00
|
|
|
/* rail_gui.cpp */
|
2021-02-20 18:01:04 +00:00
|
|
|
CommandCallback CcPlaySound_CONSTRUCTION_RAIL;
|
2010-01-11 18:46:09 +00:00
|
|
|
CommandCallback CcRailDepot;
|
|
|
|
CommandCallback CcStation;
|
|
|
|
CommandCallback CcBuildRailTunnel;
|
|
|
|
|
|
|
|
/* road_gui.cpp */
|
2021-02-20 18:01:04 +00:00
|
|
|
CommandCallback CcPlaySound_CONSTRUCTION_OTHER;
|
2010-01-11 18:46:09 +00:00
|
|
|
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
|
|
|
|
2016-02-14 00:52:42 +00:00
|
|
|
/* tbtr_template_gui_create.cpp */
|
|
|
|
CommandCallback CcSetVirtualTrain;
|
2017-01-21 01:28:32 +00:00
|
|
|
CommandCallback CcVirtualTrainWagonsMoved;
|
2016-02-14 00:52:42 +00:00
|
|
|
CommandCallback CcDeleteVirtualTrain;
|
|
|
|
|
2016-02-15 18:54:37 +00:00
|
|
|
/* build_vehicle_gui.cpp */
|
2016-02-14 00:52:42 +00:00
|
|
|
CommandCallback CcAddVirtualEngine;
|
2020-09-08 22:56:38 +00:00
|
|
|
CommandCallback CcMoveNewVirtualEngine;
|
2016-02-14 00:52:42 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
/* schdispatch_gui.cpp */
|
|
|
|
CommandCallback CcAddNewSchDispatchSchedule;
|
|
|
|
|
2007-12-21 21:50:46 +00:00
|
|
|
#endif /* COMMAND_FUNC_H */
|