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/>.
*/
2008-05-06 15:11:33 +00:00
/** @file command.cpp Handling of commands. */
2007-02-23 11:50:43 +00:00
2004-08-09 17:04:08 +00:00
# include "stdafx.h"
2007-04-12 13:07:15 +00:00
# include "landscape.h"
2011-12-10 13:54:10 +00:00
# include "error.h"
2004-08-09 17:04:08 +00:00
# include "gui.h"
2007-12-21 21:50:46 +00:00
# include "command_func.h"
2010-08-18 17:06:45 +00:00
# include "network/network_type.h"
2007-01-02 17:34:03 +00:00
# include "network/network.h"
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
# include "genworld.h"
2007-12-21 19:49:27 +00:00
# include "strings_func.h"
2011-02-07 22:22:20 +00:00
# include "texteff.hpp"
2008-01-09 17:47:05 +00:00
# include "town.h"
2008-01-11 00:30:32 +00:00
# include "date_func.h"
2008-09-30 20:51:04 +00:00
# include "company_func.h"
# include "company_base.h"
2008-01-16 01:18:15 +00:00
# include "signal_func.h"
2010-06-05 13:32:42 +00:00
# include "core/backup_type.hpp"
2010-09-03 21:50:51 +00:00
# include "object_base.h"
2016-02-16 18:27:21 +00:00
# include "newgrf_text.h"
# include "string_func.h"
2016-02-17 19:45:24 +00:00
# include "scope_info.h"
2019-05-21 19:48:43 +00:00
# include "core/random_func.hpp"
2021-06-15 17:52:40 +00:00
# include "settings_func.h"
2021-08-28 11:51:06 +00:00
# include "signal_func.h"
2021-10-03 21:26:25 +00:00
# include "debug_settings.h"
# include "debug_desync.h"
2021-12-06 18:19:49 +00:00
# include "order_backup.h"
2017-02-21 21:04:28 +00:00
# include <array>
2004-08-09 17:04:08 +00:00
2008-01-13 01:21:35 +00:00
# include "table/strings.h"
2014-04-23 20:13:33 +00:00
# include "safeguards.h"
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildRailroadTrack ;
CommandProc CmdRemoveRailroadTrack ;
CommandProc CmdBuildSingleRail ;
CommandProc CmdRemoveSingleRail ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdLandscapeClear ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildBridge ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildRailStation ;
CommandProc CmdRemoveFromRailStation ;
CommandProc CmdConvertRail ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildSingleSignal ;
CommandProc CmdRemoveSingleSignal ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdTerraformLand ;
2004-08-09 17:04:08 +00:00
2010-08-08 10:59:30 +00:00
CommandProc CmdBuildObject ;
2018-11-23 19:07:13 +00:00
CommandProc CmdPurchaseLandArea ;
2020-09-14 22:19:45 +00:00
CommandProc CmdBuildObjectArea ;
2015-08-03 20:29:03 +00:00
CommandProc CmdBuildHouse ;
2010-01-11 22:46:00 +00:00
CommandProc CmdSellLandArea ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildTunnel ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildTrainDepot ;
2022-01-01 20:42:10 +00:00
CommandProcEx CmdBuildRailWaypoint ;
2022-02-09 02:11:55 +00:00
CommandProcEx CmdBuildRoadWaypoint ;
2010-01-11 22:46:00 +00:00
CommandProc CmdRenameWaypoint ;
2022-01-21 23:37:53 +00:00
CommandProc CmdSetWaypointLabelHidden ;
2010-01-11 22:46:00 +00:00
CommandProc CmdRemoveFromRailWaypoint ;
2004-08-09 17:04:08 +00:00
2022-02-09 02:11:55 +00:00
CommandProcEx CmdBuildRoadStop ;
2010-01-11 22:46:00 +00:00
CommandProc CmdRemoveRoadStop ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildLongRoad ;
CommandProc CmdRemoveLongRoad ;
CommandProc CmdBuildRoad ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildRoadDepot ;
2004-08-09 17:04:08 +00:00
2019-04-06 06:46:15 +00:00
CommandProc CmdConvertRoad ;
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildAirport ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildDock ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildShipDepot ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildBuoy ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdPlantTree ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdMoveRailVehicle ;
2004-08-09 17:04:08 +00:00
2020-10-17 13:42:46 +00:00
CommandProc CmdBuildVehicle ;
2010-08-17 23:55:22 +00:00
CommandProc CmdSellVehicle ;
2010-08-18 00:47:31 +00:00
CommandProc CmdRefitVehicle ;
2010-09-08 18:55:58 +00:00
CommandProc CmdSendVehicleToDepot ;
2014-09-07 16:12:58 +00:00
CommandProc CmdSetVehicleVisibility ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdForceTrainProceed ;
CommandProc CmdReverseTrainDirection ;
2004-08-09 17:04:08 +00:00
2010-08-18 20:48:38 +00:00
CommandProc CmdClearOrderBackup ;
2020-10-17 14:01:44 +00:00
CommandProcEx CmdModifyOrder ;
2010-01-11 22:46:00 +00:00
CommandProc CmdSkipToOrder ;
CommandProc CmdDeleteOrder ;
2020-10-17 14:01:44 +00:00
CommandProcEx CmdInsertOrder ;
2016-01-27 20:02:35 +00:00
CommandProc CmdMassChangeOrder ;
2010-01-11 22:46:00 +00:00
CommandProc CmdChangeServiceInt ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildIndustry ;
2020-12-22 13:21:31 +00:00
CommandProc CmdIndustryCtrl ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdSetCompanyManagerFace ;
CommandProc CmdSetCompanyColour ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdIncreaseLoan ;
CommandProc CmdDecreaseLoan ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdWantEnginePreview ;
2020-01-15 17:46:26 +00:00
CommandProc CmdEngineCtrl ;
2004-08-09 17:04:08 +00:00
2016-02-14 00:52:42 +00:00
CommandProc CmdSetVehicleUnitNumber ;
2010-01-11 22:46:00 +00:00
CommandProc CmdRenameVehicle ;
CommandProc CmdRenameEngine ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdRenameCompany ;
CommandProc CmdRenamePresident ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdRenameStation ;
2010-05-12 20:50:10 +00:00
CommandProc CmdRenameDepot ;
2004-08-09 17:04:08 +00:00
2020-03-22 13:49:22 +00:00
CommandProc CmdSetStationCargoAllowedSupply ;
2010-01-11 22:46:00 +00:00
CommandProc CmdPlaceSign ;
CommandProc CmdRenameSign ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdTurnRoadVeh ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdPause ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuyShareInCompany ;
CommandProc CmdSellShareInCompany ;
CommandProc CmdBuyCompany ;
2021-10-23 23:07:54 +00:00
CommandProc CmdDeclineBuyCompany ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdFoundTown ;
CommandProc CmdRenameTown ;
2021-03-14 16:44:15 +00:00
CommandProc CmdRenameTownNonAdmin ;
2010-01-11 22:46:00 +00:00
CommandProc CmdDoTownAction ;
2011-12-19 20:59:19 +00:00
CommandProc CmdTownGrowthRate ;
2020-01-04 16:31:52 +00:00
CommandProc CmdTownRating ;
2011-12-19 20:59:19 +00:00
CommandProc CmdTownCargoGoal ;
2011-12-19 21:00:55 +00:00
CommandProc CmdTownSetText ;
2010-08-02 21:06:06 +00:00
CommandProc CmdExpandTown ;
2010-08-02 21:07:23 +00:00
CommandProc CmdDeleteTown ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdChangeSetting ;
CommandProc CmdChangeCompanySetting ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdOrderRefit ;
CommandProc CmdCloneOrder ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdClearArea ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdGiveMoney ;
CommandProc CmdMoneyCheat ;
2020-04-14 21:04:41 +00:00
CommandProc CmdMoneyCheatAdmin ;
2013-09-21 13:07:42 +00:00
CommandProc CmdChangeBankBalance ;
2020-04-14 19:11:38 +00:00
CommandProc CmdCheatSetting ;
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildCanal ;
CommandProc CmdBuildLock ;
2004-08-09 17:04:08 +00:00
2011-12-19 21:01:12 +00:00
CommandProc CmdCreateSubsidy ;
2010-01-11 22:46:00 +00:00
CommandProc CmdCompanyCtrl ;
2011-12-19 21:01:03 +00:00
CommandProc CmdCustomNewsItem ;
2011-12-19 21:03:17 +00:00
CommandProc CmdCreateGoal ;
CommandProc CmdRemoveGoal ;
2013-05-26 19:54:43 +00:00
CommandProc CmdSetGoalText ;
CommandProc CmdSetGoalProgress ;
CommandProc CmdSetGoalCompleted ;
2012-01-03 16:36:24 +00:00
CommandProc CmdGoalQuestion ;
CommandProc CmdGoalQuestionAnswer ;
2013-06-09 12:19:09 +00:00
CommandProc CmdCreateStoryPage ;
CommandProc CmdCreateStoryPageElement ;
CommandProc CmdUpdateStoryPageElement ;
CommandProc CmdSetStoryPageTitle ;
2014-02-06 19:48:19 +00:00
CommandProc CmdSetStoryPageDate ;
2013-06-09 12:57:22 +00:00
CommandProc CmdShowStoryPage ;
2013-06-09 12:19:09 +00:00
CommandProc CmdRemoveStoryPage ;
2014-02-06 19:48:19 +00:00
CommandProc CmdRemoveStoryPageElement ;
2018-04-24 17:19:01 +00:00
CommandProc CmdScrollViewport ;
2020-05-22 20:22:55 +00:00
CommandProc CmdStoryPageButton ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdLevelLand ;
2004-08-09 17:04:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdBuildSignalTrack ;
CommandProc CmdRemoveSignalTrack ;
2004-08-15 20:23:42 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdSetAutoReplace ;
2004-12-27 18:18:44 +00:00
2016-02-14 00:52:42 +00:00
CommandProc CmdToggleReuseDepotVehicles ;
CommandProc CmdToggleKeepRemainingVehicles ;
CommandProc CmdToggleRefitAsTemplate ;
2018-10-18 17:34:22 +00:00
CommandProc CmdToggleTemplateReplaceOldOnly ;
2016-02-14 00:52:42 +00:00
CommandProc CmdVirtualTrainFromTemplateVehicle ;
CommandProc CmdVirtualTrainFromTrain ;
CommandProc CmdDeleteVirtualTrain ;
CommandProc CmdBuildVirtualRailVehicle ;
CommandProc CmdReplaceTemplateVehicle ;
CommandProc CmdTemplateVehicleFromTrain ;
CommandProc CmdDeleteTemplateVehicle ;
CommandProc CmdIssueTemplateReplacement ;
CommandProc CmdDeleteTemplateReplacement ;
2010-01-11 22:46:00 +00:00
CommandProc CmdCloneVehicle ;
2021-08-22 13:59:33 +00:00
CommandProc CmdCloneVehicleFromTemplate ;
2010-01-11 22:46:00 +00:00
CommandProc CmdStartStopVehicle ;
CommandProc CmdMassStartStopVehicle ;
CommandProc CmdAutoreplaceVehicle ;
2016-02-14 00:52:42 +00:00
CommandProc CmdTemplateReplaceVehicle ;
2010-01-11 22:46:00 +00:00
CommandProc CmdDepotSellAllVehicles ;
CommandProc CmdDepotMassAutoReplace ;
2005-07-31 13:08:08 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdCreateGroup ;
2014-04-08 21:09:06 +00:00
CommandProc CmdAlterGroup ;
2010-01-11 22:46:00 +00:00
CommandProc CmdDeleteGroup ;
2016-03-08 19:27:03 +00:00
CommandProc CmdCreateGroupFromList ;
2010-01-11 22:46:00 +00:00
CommandProc CmdAddVehicleGroup ;
CommandProc CmdAddSharedVehicleGroup ;
CommandProc CmdRemoveAllVehiclesGroup ;
2019-03-29 23:44:28 +00:00
CommandProc CmdSetGroupFlag ;
2019-01-31 13:57:44 +00:00
CommandProc CmdSetGroupLivery ;
2007-05-22 19:48:11 +00:00
2010-01-11 22:46:00 +00:00
CommandProc CmdMoveOrder ;
2020-11-02 20:10:44 +00:00
CommandProc CmdReverseOrderList ;
2020-10-12 22:48:54 +00:00
CommandProcEx CmdChangeTimetable ;
2016-03-02 22:36:21 +00:00
CommandProc CmdBulkChangeTimetable ;
2010-01-11 22:46:00 +00:00
CommandProc CmdSetVehicleOnTime ;
CommandProc CmdAutofillTimetable ;
2015-08-04 20:24:04 +00:00
CommandProc CmdAutomateTimetable ;
2016-05-07 00:15:46 +00:00
CommandProc CmdTimetableSeparation ;
2010-01-11 22:46:00 +00:00
CommandProc CmdSetTimetableStart ;
2007-09-10 15:21:14 +00:00
2012-04-17 19:43:18 +00:00
CommandProc CmdOpenCloseAirport ;
2015-07-21 23:28:53 +00:00
CommandProc CmdProgramSignalTraceRestrict ;
2017-03-30 20:14:14 +00:00
CommandProc CmdCreateTraceRestrictSlot ;
CommandProc CmdAlterTraceRestrictSlot ;
CommandProc CmdDeleteTraceRestrictSlot ;
CommandProc CmdAddVehicleTraceRestrictSlot ;
CommandProc CmdRemoveVehicleTraceRestrictSlot ;
2020-08-31 18:08:35 +00:00
CommandProc CmdCreateTraceRestrictCounter ;
CommandProc CmdAlterTraceRestrictCounter ;
CommandProc CmdDeleteTraceRestrictCounter ;
2015-07-21 23:28:53 +00:00
2014-01-14 20:32:07 +00:00
CommandProc CmdInsertSignalInstruction ;
CommandProc CmdModifySignalInstruction ;
CommandProc CmdRemoveSignalInstruction ;
2015-11-24 01:03:09 +00:00
CommandProc CmdSignalProgramMgmt ;
2014-01-14 20:32:07 +00:00
2017-05-29 18:37:08 +00:00
CommandProc CmdScheduledDispatch ;
2021-11-28 02:25:42 +00:00
CommandProcEx CmdScheduledDispatchAdd ;
2017-05-29 18:37:08 +00:00
CommandProc CmdScheduledDispatchRemove ;
CommandProc CmdScheduledDispatchSetDuration ;
2022-01-13 19:46:43 +00:00
CommandProcEx CmdScheduledDispatchSetStartDate ;
2017-05-29 18:37:08 +00:00
CommandProc CmdScheduledDispatchSetDelay ;
CommandProc CmdScheduledDispatchResetLastDispatch ;
2021-12-18 12:46:25 +00:00
CommandProc CmdScheduledDispatchClear ;
2022-01-13 19:46:43 +00:00
CommandProcEx CmdScheduledDispatchAddNewSchedule ;
CommandProc CmdScheduledDispatchRemoveSchedule ;
2017-05-29 18:37:08 +00:00
2015-08-02 18:37:42 +00:00
CommandProc CmdAddPlan ;
2019-03-03 20:54:29 +00:00
CommandProcEx CmdAddPlanLine ;
2015-08-02 18:37:42 +00:00
CommandProc CmdRemovePlan ;
CommandProc CmdRemovePlanLine ;
CommandProc CmdChangePlanVisibility ;
2020-11-06 18:23:05 +00:00
CommandProc CmdChangePlanColour ;
2018-04-10 13:29:22 +00:00
CommandProc CmdRenamePlan ;
2015-08-02 18:37:42 +00:00
2015-11-23 19:47:59 +00:00
CommandProc CmdDesyncCheck ;
2019-03-03 20:53:59 +00:00
# define DEF_CMD(proc, flags, type) Command(proc, #proc, (CommandFlags)flags, type)
2010-04-11 10:11:26 +00:00
2007-09-10 15:21:14 +00:00
/**
* The master command table
*
* This table contains all possible CommandProc functions with
2010-03-14 12:39:24 +00:00
* the flags which belongs to it . The indices are the same
2007-09-10 15:21:14 +00:00
* as the value from the CMD_ * enums .
*/
2005-05-14 19:25:18 +00:00
static const Command _command_proc_table [ ] = {
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdBuildRailroadTrack , CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_RAILROAD_TRACK
DEF_CMD ( CmdRemoveRailroadTrack , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_RAILROAD_TRACK
DEF_CMD ( CmdBuildSingleRail , CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_SINGLE_RAIL
DEF_CMD ( CmdRemoveSingleRail , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_SINGLE_RAIL
2019-09-03 20:50:58 +00:00
DEF_CMD ( CmdLandscapeClear , CMD_DEITY , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_LANDSCAPE_CLEAR
2011-12-19 21:02:33 +00:00
DEF_CMD ( CmdBuildBridge , CMD_DEITY | CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_BRIDGE
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdBuildRailStation , CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_RAIL_STATION
DEF_CMD ( CmdBuildTrainDepot , CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_TRAIN_DEPOT
DEF_CMD ( CmdBuildSingleSignal , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_SIGNALS
DEF_CMD ( CmdRemoveSingleSignal , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_SIGNALS
DEF_CMD ( CmdTerraformLand , CMD_ALL_TILES | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_TERRAFORM_LAND
2021-09-25 11:39:40 +00:00
DEF_CMD ( CmdBuildObject , CMD_DEITY | CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_OBJECT
2020-09-14 22:00:09 +00:00
DEF_CMD ( CmdPurchaseLandArea , CMD_NO_WATER | CMD_AUTO | CMD_NO_TEST , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_PURCHASE_LAND_AREA
2020-09-14 22:19:45 +00:00
DEF_CMD ( CmdBuildObjectArea , CMD_NO_WATER | CMD_AUTO | CMD_NO_TEST , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_OBJECT_AREA
2015-08-03 20:29:03 +00:00
DEF_CMD ( CmdBuildHouse , CMD_DEITY | CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_HOUSE
2011-12-19 21:02:33 +00:00
DEF_CMD ( CmdBuildTunnel , CMD_DEITY | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_TUNNEL
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdRemoveFromRailStation , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_FROM_RAIL_STATION
2016-04-01 19:27:19 +00:00
DEF_CMD ( CmdConvertRail , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_CONVERT_RAIL
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdBuildRailWaypoint , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_RAIL_WAYPOINT
2022-01-25 22:02:32 +00:00
DEF_CMD ( CmdBuildRoadWaypoint , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_ROAD_WAYPOINT
2013-11-24 19:46:16 +00:00
DEF_CMD ( CmdRenameWaypoint , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_WAYPOINT
2022-01-21 23:37:53 +00:00
DEF_CMD ( CmdSetWaypointLabelHidden , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_WAYPOINT_LABEL_HIDDEN
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdRemoveFromRailWaypoint , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_FROM_RAIL_WAYPOINT
DEF_CMD ( CmdBuildRoadStop , CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_ROAD_STOP
DEF_CMD ( CmdRemoveRoadStop , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_ROAD_STOP
2011-12-19 21:02:33 +00:00
DEF_CMD ( CmdBuildLongRoad , CMD_DEITY | CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_LONG_ROAD
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdRemoveLongRoad , CMD_NO_TEST | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_LONG_ROAD; towns may disallow removing road bits (as they are connected) in test, but in exec they're removed and thus removing is allowed.
2011-12-19 21:02:33 +00:00
DEF_CMD ( CmdBuildRoad , CMD_DEITY | CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_ROAD
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdBuildRoadDepot , CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_ROAD_DEPOT
2019-04-06 06:46:15 +00:00
DEF_CMD ( CmdConvertRoad , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_CONVERT_ROAD
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdBuildAirport , CMD_NO_WATER | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_AIRPORT
DEF_CMD ( CmdBuildDock , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_DOCK
DEF_CMD ( CmdBuildShipDepot , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_SHIP_DEPOT
DEF_CMD ( CmdBuildBuoy , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_BUOY
DEF_CMD ( CmdPlantTree , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_PLANT_TREE
DEF_CMD ( CmdBuildVehicle , CMD_CLIENT_ID , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_BUILD_VEHICLE
DEF_CMD ( CmdSellVehicle , CMD_CLIENT_ID , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_SELL_VEHICLE
DEF_CMD ( CmdRefitVehicle , 0 , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_REFIT_VEHICLE
DEF_CMD ( CmdSendVehicleToDepot , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_SEND_VEHICLE_TO_DEPOT
2014-09-07 16:12:58 +00:00
DEF_CMD ( CmdSetVehicleVisibility , 0 , CMDT_COMPANY_SETTING ) , // CMD_SET_VEHICLE_VISIBILITY
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdMoveRailVehicle , 0 , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_MOVE_RAIL_VEHICLE
DEF_CMD ( CmdForceTrainProceed , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_FORCE_TRAIN_PROCEED
DEF_CMD ( CmdReverseTrainDirection , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_REVERSE_TRAIN_DIRECTION
2014-08-03 14:26:32 +00:00
DEF_CMD ( CmdClearOrderBackup , CMD_CLIENT_ID , CMDT_SERVER_SETTING ) , // CMD_CLEAR_ORDER_BACKUP
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdModifyOrder , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_MODIFY_ORDER
DEF_CMD ( CmdSkipToOrder , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SKIP_TO_ORDER
DEF_CMD ( CmdDeleteOrder , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_DELETE_ORDER
DEF_CMD ( CmdInsertOrder , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_INSERT_ORDER
2016-01-27 20:02:35 +00:00
DEF_CMD ( CmdMassChangeOrder , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_MASS_CHANGE_ORDER
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdChangeServiceInt , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_CHANGE_SERVICE_INT
2012-10-22 18:56:21 +00:00
DEF_CMD ( CmdBuildIndustry , CMD_DEITY , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_INDUSTRY
2021-01-15 14:38:14 +00:00
DEF_CMD ( CmdIndustryCtrl , CMD_STR_CTRL | CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_INDUSTRY_CTRL
2020-12-22 13:21:31 +00:00
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdSetCompanyManagerFace , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_COMPANY_MANAGER_FACE
DEF_CMD ( CmdSetCompanyColour , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_COMPANY_COLOUR
DEF_CMD ( CmdIncreaseLoan , 0 , CMDT_MONEY_MANAGEMENT ) , // CMD_INCREASE_LOAN
DEF_CMD ( CmdDecreaseLoan , 0 , CMDT_MONEY_MANAGEMENT ) , // CMD_DECREASE_LOAN
DEF_CMD ( CmdWantEnginePreview , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_WANT_ENGINE_PREVIEW
2020-01-15 17:46:26 +00:00
DEF_CMD ( CmdEngineCtrl , CMD_DEITY , CMDT_VEHICLE_MANAGEMENT ) , // CMD_ENGINE_CTRL
2010-12-07 21:05:27 +00:00
2016-02-14 00:52:42 +00:00
DEF_CMD ( CmdSetVehicleUnitNumber , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_VEHICLE_UNIT_NUMBER
2013-06-27 19:56:54 +00:00
DEF_CMD ( CmdRenameVehicle , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_VEHICLE
DEF_CMD ( CmdRenameEngine , CMD_SERVER , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_ENGINE
2010-12-07 21:05:27 +00:00
2013-06-27 19:56:54 +00:00
DEF_CMD ( CmdRenameCompany , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_COMPANY
DEF_CMD ( CmdRenamePresident , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_PRESIDENT
2010-12-07 21:05:27 +00:00
2013-06-27 19:56:54 +00:00
DEF_CMD ( CmdRenameStation , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_STATION
DEF_CMD ( CmdRenameDepot , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_DEPOT
2010-12-07 21:05:27 +00:00
2020-03-22 13:49:22 +00:00
DEF_CMD ( CmdSetStationCargoAllowedSupply , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_STATION_CARGO_ALLOWED_SUPPLY
2020-11-21 12:51:22 +00:00
DEF_CMD ( CmdPlaceSign , CMD_LOG_AUX | CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_PLACE_SIGN
DEF_CMD ( CmdRenameSign , CMD_LOG_AUX | CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_SIGN
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdTurnRoadVeh , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_TURN_ROADVEH
2019-02-04 17:19:21 +00:00
DEF_CMD ( CmdPause , CMD_SERVER | CMD_NO_EST , CMDT_SERVER_SETTING ) , // CMD_PAUSE
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdBuyShareInCompany , 0 , CMDT_MONEY_MANAGEMENT ) , // CMD_BUY_SHARE_IN_COMPANY
DEF_CMD ( CmdSellShareInCompany , 0 , CMDT_MONEY_MANAGEMENT ) , // CMD_SELL_SHARE_IN_COMPANY
2021-10-23 23:07:54 +00:00
DEF_CMD ( CmdBuyCompany , 0 , CMDT_MONEY_MANAGEMENT ) , // CMD_BUY_COMPANY
DEF_CMD ( CmdDeclineBuyCompany , 0 , CMDT_MONEY_MANAGEMENT ) , // CMD_DECLINE_BUY_COMPANY
2010-12-07 21:05:27 +00:00
2013-09-19 18:48:05 +00:00
DEF_CMD ( CmdFoundTown , CMD_DEITY | CMD_NO_TEST , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_FOUND_TOWN; founding random town can fail only in exec run
DEF_CMD ( CmdRenameTown , CMD_DEITY | CMD_SERVER , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_TOWN
2021-03-14 16:44:15 +00:00
DEF_CMD ( CmdRenameTownNonAdmin , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_TOWN_NON_ADMIN
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdDoTownAction , 0 , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_DO_TOWN_ACTION
2020-10-08 21:39:23 +00:00
DEF_CMD ( CmdTownCargoGoal , CMD_LOG_AUX | CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_TOWN_CARGO_GOAL
DEF_CMD ( CmdTownGrowthRate , CMD_LOG_AUX | CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_TOWN_GROWTH_RATE
DEF_CMD ( CmdTownRating , CMD_LOG_AUX | CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_TOWN_RATING
DEF_CMD ( CmdTownSetText , CMD_LOG_AUX | CMD_STR_CTRL | CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_TOWN_SET_TEXT
2011-12-19 20:57:51 +00:00
DEF_CMD ( CmdExpandTown , CMD_DEITY , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_EXPAND_TOWN
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdDeleteTown , CMD_OFFLINE , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_DELETE_TOWN
DEF_CMD ( CmdOrderRefit , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_ORDER_REFIT
DEF_CMD ( CmdCloneOrder , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_CLONE_ORDER
DEF_CMD ( CmdClearArea , CMD_NO_TEST , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_CLEAR_AREA; destroying multi-tile houses makes town rating differ between test and execution
2020-04-14 21:04:41 +00:00
DEF_CMD ( CmdMoneyCheat , 0 , CMDT_CHEAT ) , // CMD_MONEY_CHEAT
DEF_CMD ( CmdMoneyCheatAdmin , CMD_SERVER_NS , CMDT_CHEAT ) , // CMD_MONEY_CHEAT_ADMIN
2013-09-21 13:07:42 +00:00
DEF_CMD ( CmdChangeBankBalance , CMD_DEITY , CMDT_MONEY_MANAGEMENT ) , // CMD_CHANGE_BANK_BALANCE
2020-04-14 19:11:38 +00:00
DEF_CMD ( CmdCheatSetting , CMD_SERVER , CMDT_CHEAT ) , // CMD_CHEAT_SETTING
2020-07-06 21:03:40 +00:00
DEF_CMD ( CmdBuildCanal , CMD_DEITY | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_CANAL
2011-12-19 21:01:12 +00:00
DEF_CMD ( CmdCreateSubsidy , CMD_DEITY , CMDT_OTHER_MANAGEMENT ) , // CMD_CREATE_SUBSIDY
2019-02-04 17:19:21 +00:00
DEF_CMD ( CmdCompanyCtrl , CMD_SPECTATOR | CMD_CLIENT_ID | CMD_NO_EST , CMDT_SERVER_SETTING ) , // CMD_COMPANY_CTRL
2021-06-30 16:14:27 +00:00
DEF_CMD ( CmdCustomNewsItem , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_CUSTOM_NEWS_ITEM
DEF_CMD ( CmdCreateGoal , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_CREATE_GOAL
DEF_CMD ( CmdRemoveGoal , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_REMOVE_GOAL
DEF_CMD ( CmdSetGoalText , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_GOAL_TEXT
DEF_CMD ( CmdSetGoalProgress , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_GOAL_PROGRESS
DEF_CMD ( CmdSetGoalCompleted , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_GOAL_COMPLETED
DEF_CMD ( CmdGoalQuestion , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_GOAL_QUESTION
DEF_CMD ( CmdGoalQuestionAnswer , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_GOAL_QUESTION_ANSWER
DEF_CMD ( CmdCreateStoryPage , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_CREATE_STORY_PAGE
DEF_CMD ( CmdCreateStoryPageElement , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_CREATE_STORY_PAGE_ELEMENT
DEF_CMD ( CmdUpdateStoryPageElement , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_UPDATE_STORY_PAGE_ELEMENT
DEF_CMD ( CmdSetStoryPageTitle , CMD_STR_CTRL | CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_STORY_PAGE_TITLE
DEF_CMD ( CmdSetStoryPageDate , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_SET_STORY_PAGE_DATE
DEF_CMD ( CmdShowStoryPage , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_SHOW_STORY_PAGE
DEF_CMD ( CmdRemoveStoryPage , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_REMOVE_STORY_PAGE
DEF_CMD ( CmdRemoveStoryPageElement , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_REMOVE_STORY_ELEMENT_PAGE
DEF_CMD ( CmdScrollViewport , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_SCROLL_VIEWPORT
DEF_CMD ( CmdStoryPageButton , CMD_DEITY | CMD_LOG_AUX , CMDT_OTHER_MANAGEMENT ) , // CMD_STORY_PAGE_BUTTON
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdLevelLand , CMD_ALL_TILES | CMD_NO_TEST | CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_LEVEL_LAND; test run might clear tiles multiple times, in execution that only happens once
DEF_CMD ( CmdBuildLock , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_LOCK
DEF_CMD ( CmdBuildSignalTrack , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_BUILD_SIGNAL_TRACK
DEF_CMD ( CmdRemoveSignalTrack , CMD_AUTO , CMDT_LANDSCAPE_CONSTRUCTION ) , // CMD_REMOVE_SIGNAL_TRACK
DEF_CMD ( CmdGiveMoney , 0 , CMDT_MONEY_MANAGEMENT ) , // CMD_GIVE_MONEY
DEF_CMD ( CmdChangeSetting , CMD_SERVER , CMDT_SERVER_SETTING ) , // CMD_CHANGE_SETTING
DEF_CMD ( CmdChangeCompanySetting , 0 , CMDT_COMPANY_SETTING ) , // CMD_CHANGE_COMPANY_SETTING
DEF_CMD ( CmdSetAutoReplace , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_SET_AUTOREPLACE
2016-02-14 00:52:42 +00:00
DEF_CMD ( CmdToggleReuseDepotVehicles , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_TOGGLE_REUSE_DEPOT_VEHICLES
DEF_CMD ( CmdToggleKeepRemainingVehicles , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_TOGGLE_KEEP_REMAINING_VEHICLES
DEF_CMD ( CmdToggleRefitAsTemplate , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_TOGGLE_REFIT_AS_TEMPLATE
2018-10-18 17:34:22 +00:00
DEF_CMD ( CmdToggleTemplateReplaceOldOnly , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_TOGGLE_TMPL_REPLACE_OLD_ONLY
2016-02-14 00:52:42 +00:00
2020-10-09 18:26:07 +00:00
DEF_CMD ( CmdVirtualTrainFromTemplateVehicle , CMD_CLIENT_ID | CMD_NO_TEST | CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_VIRTUAL_TRAIN_FROM_TEMPLATE_VEHICLE
DEF_CMD ( CmdVirtualTrainFromTrain , CMD_CLIENT_ID | CMD_NO_TEST | CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_VIRTUAL_TRAIN_FROM_TRAIN
DEF_CMD ( CmdDeleteVirtualTrain , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_DELETE_VIRTUAL_TRAIN
DEF_CMD ( CmdBuildVirtualRailVehicle , CMD_CLIENT_ID | CMD_NO_TEST | CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_BUILD_VIRTUAL_RAIL_VEHICLE
DEF_CMD ( CmdReplaceTemplateVehicle , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_REPLACE_TEMPLATE_VEHICLE
2016-02-14 00:52:42 +00:00
DEF_CMD ( CmdTemplateVehicleFromTrain , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_CLONE_TEMPLATE_VEHICLE_FROM_TRAIN
DEF_CMD ( CmdDeleteTemplateVehicle , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_DELETE_TEMPLATE_VEHICLE
DEF_CMD ( CmdIssueTemplateReplacement , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_ISSUE_TEMPLATE_REPLACEMENT
DEF_CMD ( CmdDeleteTemplateReplacement , CMD_ALL_TILES , CMDT_VEHICLE_MANAGEMENT ) , // CMD_DELETE_TEMPLATE_REPLACEMENT
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdCloneVehicle , CMD_NO_TEST , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_CLONE_VEHICLE; NewGRF callbacks influence building and refitting making it impossible to correctly estimate the cost
2021-08-22 13:59:33 +00:00
DEF_CMD ( CmdCloneVehicleFromTemplate , CMD_NO_TEST , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_CLONE_VEHICLE_FROM_TEMPLATE; NewGRF callbacks influence building and refitting making it impossible to correctly estimate the cost
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdStartStopVehicle , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_START_STOP_VEHICLE
DEF_CMD ( CmdMassStartStopVehicle , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_MASS_START_STOP
DEF_CMD ( CmdAutoreplaceVehicle , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_AUTOREPLACE_VEHICLE
2016-02-14 00:52:42 +00:00
DEF_CMD ( CmdTemplateReplaceVehicle , 0 , CMDT_VEHICLE_MANAGEMENT ) , // CMD_TEMPLATE_REPLACE_VEHICLE
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdDepotSellAllVehicles , 0 , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_DEPOT_SELL_ALL_VEHICLES
DEF_CMD ( CmdDepotMassAutoReplace , 0 , CMDT_VEHICLE_CONSTRUCTION ) , // CMD_DEPOT_MASS_AUTOREPLACE
DEF_CMD ( CmdCreateGroup , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_CREATE_GROUP
DEF_CMD ( CmdDeleteGroup , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_DELETE_GROUP
2014-04-08 21:09:06 +00:00
DEF_CMD ( CmdAlterGroup , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_ALTER_GROUP
2016-03-08 19:27:03 +00:00
DEF_CMD ( CmdCreateGroupFromList , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_CREATE_GROUP_FROM_LIST
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdAddVehicleGroup , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_ADD_VEHICLE_GROUP
DEF_CMD ( CmdAddSharedVehicleGroup , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_ADD_SHARE_VEHICLE_GROUP
DEF_CMD ( CmdRemoveAllVehiclesGroup , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_REMOVE_ALL_VEHICLES_GROUP
2019-03-29 23:44:28 +00:00
DEF_CMD ( CmdSetGroupFlag , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SET_GROUP_FLAG
2019-01-31 13:57:44 +00:00
DEF_CMD ( CmdSetGroupLivery , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SET_GROUP_LIVERY
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdMoveOrder , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_MOVE_ORDER
2020-11-02 20:10:44 +00:00
DEF_CMD ( CmdReverseOrderList , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_REVERSE_ORDER_LIST
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdChangeTimetable , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_CHANGE_TIMETABLE
2016-03-02 22:36:21 +00:00
DEF_CMD ( CmdBulkChangeTimetable , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_BULK_CHANGE_TIMETABLE
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdSetVehicleOnTime , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SET_VEHICLE_ON_TIME
DEF_CMD ( CmdAutofillTimetable , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_AUTOFILL_TIMETABLE
2015-11-30 19:48:44 +00:00
DEF_CMD ( CmdAutomateTimetable , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_AUTOMATE_TIMETABLE
2016-05-07 00:15:46 +00:00
DEF_CMD ( CmdTimetableSeparation , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_TIMETABLE_SEPARATION
2010-12-07 21:05:27 +00:00
DEF_CMD ( CmdSetTimetableStart , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SET_TIMETABLE_START
2012-04-17 19:43:18 +00:00
DEF_CMD ( CmdOpenCloseAirport , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_OPEN_CLOSE_AIRPORT
2015-07-21 23:28:53 +00:00
DEF_CMD ( CmdProgramSignalTraceRestrict , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_PROGRAM_TRACERESTRICT_SIGNAL
2017-03-30 20:14:14 +00:00
DEF_CMD ( CmdCreateTraceRestrictSlot , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_CREATE_TRACERESTRICT_SLOT
DEF_CMD ( CmdAlterTraceRestrictSlot , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_ALTER_TRACERESTRICT_SLOT
DEF_CMD ( CmdDeleteTraceRestrictSlot , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_DELETE_TRACERESTRICT_SLOT
DEF_CMD ( CmdAddVehicleTraceRestrictSlot , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_ADD_VEHICLE_TRACERESTRICT_SLOT
DEF_CMD ( CmdRemoveVehicleTraceRestrictSlot , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_REMOVE_VEHICLE_TRACERESTRICT_SLOT
2020-08-31 18:08:35 +00:00
DEF_CMD ( CmdCreateTraceRestrictCounter , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_CREATE_TRACERESTRICT_COUNTER
DEF_CMD ( CmdAlterTraceRestrictCounter , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_ALTER_TRACERESTRICT_COUNTER
DEF_CMD ( CmdDeleteTraceRestrictCounter , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_DELETE_TRACERESTRICT_COUNTER
2015-08-02 17:15:18 +00:00
2018-09-26 00:13:57 +00:00
DEF_CMD ( CmdInsertSignalInstruction , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_INSERT_SIGNAL_INSTRUCTION
DEF_CMD ( CmdModifySignalInstruction , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_MODIFY_SIGNAL_INSTRUCTION
DEF_CMD ( CmdRemoveSignalInstruction , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_REMOVE_SIGNAL_INSTRUCTION
DEF_CMD ( CmdSignalProgramMgmt , 0 , CMDT_OTHER_MANAGEMENT ) , // CMD_SIGNAL_PROGRAM_MGMT
2015-08-05 20:54:11 +00:00
2017-05-29 18:37:08 +00:00
DEF_CMD ( CmdScheduledDispatch , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH
DEF_CMD ( CmdScheduledDispatchAdd , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_ADD
DEF_CMD ( CmdScheduledDispatchRemove , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_REMOVE
DEF_CMD ( CmdScheduledDispatchSetDuration , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_SET_DURATION
DEF_CMD ( CmdScheduledDispatchSetStartDate , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_SET_START_DATE
DEF_CMD ( CmdScheduledDispatchSetDelay , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_SET_DELAY
DEF_CMD ( CmdScheduledDispatchResetLastDispatch , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_RESET_LAST_DISPATCH
2021-12-18 12:46:25 +00:00
DEF_CMD ( CmdScheduledDispatchClear , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_CLEAR
2022-01-13 19:46:43 +00:00
DEF_CMD ( CmdScheduledDispatchAddNewSchedule , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_ADD_NEW_SCHEDULE
DEF_CMD ( CmdScheduledDispatchRemoveSchedule , 0 , CMDT_ROUTE_MANAGEMENT ) , // CMD_SCHEDULED_DISPATCH_REMOVE_SCHEDULE
2017-05-29 18:37:08 +00:00
2018-08-13 07:35:23 +00:00
DEF_CMD ( CmdAddPlan , CMD_NO_TEST , CMDT_OTHER_MANAGEMENT ) , // CMD_ADD_PLAN
DEF_CMD ( CmdAddPlanLine , CMD_NO_TEST , CMDT_OTHER_MANAGEMENT ) , // CMD_ADD_PLAN_LINE
DEF_CMD ( CmdRemovePlan , CMD_NO_TEST , CMDT_OTHER_MANAGEMENT ) , // CMD_REMOVE_PLAN
DEF_CMD ( CmdRemovePlanLine , CMD_NO_TEST , CMDT_OTHER_MANAGEMENT ) , // CMD_REMOVE_PLAN_LINE
DEF_CMD ( CmdChangePlanVisibility , CMD_NO_TEST , CMDT_OTHER_MANAGEMENT ) , // CMD_CHANGE_PLAN_VISIBILITY
2020-11-06 18:23:05 +00:00
DEF_CMD ( CmdChangePlanColour , CMD_NO_TEST , CMDT_OTHER_MANAGEMENT ) , // CMD_CHANGE_PLAN_COLOUR
2018-04-10 13:29:22 +00:00
DEF_CMD ( CmdRenamePlan , CMD_NO_TEST , CMDT_OTHER_MANAGEMENT ) , // CMD_RENAME_PLAN
2015-11-23 19:47:59 +00:00
DEF_CMD ( CmdDesyncCheck , CMD_SERVER , CMDT_SERVER_SETTING ) , // CMD_DESYNC_CHECK
2004-08-09 17:04:08 +00:00
} ;
2017-02-21 21:04:28 +00:00
/**
* List of flags for a command log entry
*/
2020-09-28 17:32:23 +00:00
enum CommandLogEntryFlag : uint16 {
CLEF_NONE = 0x00 , ///< no flag is set
CLEF_CMD_FAILED = 0x01 , ///< command failed
CLEF_GENERATING_WORLD = 0x02 , ///< generating world
CLEF_TEXT = 0x04 , ///< have command text
CLEF_ESTIMATE_ONLY = 0x08 , ///< estimate only
CLEF_ONLY_SENDING = 0x10 , ///< only sending
CLEF_MY_CMD = 0x20 , ///< locally generated command
CLEF_BINARY = 0x40 , ///< binary_length is > 0
CLEF_SCRIPT = 0x80 , ///< command run by AI/game script
CLEF_TWICE = 0x100 , ///< command logged twice (only sending and execution)
2021-04-18 11:35:32 +00:00
CLEF_RANDOM = 0x200 , ///< command changed random seed
2021-12-06 18:19:49 +00:00
CLEF_ORDER_BACKUP = 0x400 , ///< command changed order backups
2017-02-21 21:04:28 +00:00
} ;
2019-07-08 15:19:07 +00:00
DECLARE_ENUM_AS_BIT_SET ( CommandLogEntryFlag )
2017-02-21 21:04:28 +00:00
struct CommandLogEntry {
2021-10-18 17:01:27 +00:00
std : : string text ;
2017-02-21 21:04:28 +00:00
TileIndex tile ;
uint32 p1 ;
uint32 p2 ;
uint32 cmd ;
2020-10-17 13:42:46 +00:00
uint64 p3 ;
2017-02-21 21:04:28 +00:00
Date date ;
DateFract date_fract ;
2017-02-21 21:50:08 +00:00
uint8 tick_skip_counter ;
2019-07-08 15:19:07 +00:00
CompanyID current_company ;
CompanyID local_company ;
2017-02-21 21:04:28 +00:00
CommandLogEntryFlag log_flags ;
CommandLogEntry ( ) { }
2021-10-18 17:01:27 +00:00
CommandLogEntry ( TileIndex tile , uint32 p1 , uint32 p2 , uint64 p3 , uint32 cmd , CommandLogEntryFlag log_flags , std : : string text )
: text ( text ) , tile ( tile ) , p1 ( p1 ) , p2 ( p2 ) , cmd ( cmd ) , p3 ( p3 ) , date ( _date ) , date_fract ( _date_fract ) , tick_skip_counter ( _tick_skip_counter ) ,
2020-09-28 17:32:23 +00:00
current_company ( _current_company ) , local_company ( _local_company ) , log_flags ( log_flags ) { }
2017-02-21 21:04:28 +00:00
} ;
2020-10-08 21:39:23 +00:00
struct CommandLog {
2021-09-30 17:42:51 +00:00
std : : array < CommandLogEntry , 256 > log ;
2020-10-08 21:39:23 +00:00
unsigned int count = 0 ;
unsigned int next = 0 ;
void Reset ( )
{
this - > count = 0 ;
this - > next = 0 ;
}
} ;
static CommandLog _command_log ;
static CommandLog _command_log_aux ;
2017-02-21 21:04:28 +00:00
void ClearCommandLog ( )
{
2020-10-08 21:39:23 +00:00
_command_log . Reset ( ) ;
_command_log_aux . Reset ( ) ;
2017-02-21 21:04:28 +00:00
}
2020-10-08 21:39:23 +00:00
static void DumpSubCommandLog ( char * & buffer , const char * last , const CommandLog & cmd_log , const unsigned int count )
2017-02-21 21:04:28 +00:00
{
2020-10-08 21:39:23 +00:00
unsigned int log_index = cmd_log . next ;
2017-02-21 21:04:28 +00:00
for ( unsigned int i = 0 ; i < count ; i + + ) {
if ( log_index > 0 ) {
log_index - - ;
} else {
2021-06-11 21:54:27 +00:00
log_index = ( uint ) cmd_log . log . size ( ) - 1 ;
2017-02-21 21:04:28 +00:00
}
2020-10-08 21:39:23 +00:00
const CommandLogEntry & entry = cmd_log . log [ log_index ] ;
2017-02-21 21:04:28 +00:00
2019-07-08 15:19:07 +00:00
auto fc = [ & ] ( CommandLogEntryFlag flag , char c ) - > char {
2017-02-21 21:04:28 +00:00
return entry . log_flags & flag ? c : ' - ' ;
} ;
YearMonthDay ymd ;
ConvertDateToYMD ( entry . date , & ymd ) ;
2017-02-21 21:50:08 +00:00
buffer + = seprintf ( buffer , last , " %3u | %4i-%02i-%02i, %2i, %3i | " , i , ymd . year , ymd . month + 1 , ymd . day , entry . date_fract , entry . tick_skip_counter ) ;
2021-12-06 18:19:49 +00:00
buffer + = seprintf ( buffer , last , " %c%c%c%c%c%c%c%c%c%c%c | " ,
fc ( CLEF_ORDER_BACKUP , ' o ' ) , fc ( CLEF_RANDOM , ' r ' ) , fc ( CLEF_TWICE , ' 2 ' ) ,
fc ( CLEF_SCRIPT , ' a ' ) , fc ( CLEF_BINARY , ' b ' ) , fc ( CLEF_MY_CMD , ' m ' ) , fc ( CLEF_ONLY_SENDING , ' s ' ) ,
2019-04-04 17:44:04 +00:00
fc ( CLEF_ESTIMATE_ONLY , ' e ' ) , fc ( CLEF_TEXT , ' t ' ) , fc ( CLEF_GENERATING_WORLD , ' g ' ) , fc ( CLEF_CMD_FAILED , ' f ' ) ) ;
2020-10-17 13:42:46 +00:00
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 ) ;
}
2021-06-15 17:52:40 +00:00
buffer + = seprintf ( buffer , last , " cc: %3u, lc: %3u, cmd: 0x%08X (%s) " ,
2020-10-17 13:42:46 +00:00
( uint ) entry . current_company , ( uint ) entry . local_company , entry . cmd , GetCommandName ( entry . cmd ) ) ;
2021-06-15 17:52:40 +00:00
switch ( entry . cmd & CMD_ID_MASK ) {
case CMD_CHANGE_SETTING :
case CMD_CHANGE_COMPANY_SETTING :
2021-10-18 17:01:27 +00:00
buffer + = seprintf ( buffer , last , " [%s] " , entry . text . c_str ( ) ) ;
2021-06-15 17:52:40 +00:00
break ;
}
buffer + = seprintf ( buffer , last , " \n " ) ;
2017-02-21 21:04:28 +00:00
}
2020-10-08 21:39:23 +00:00
}
char * DumpCommandLog ( char * buffer , const char * last )
{
2021-09-30 17:42:51 +00:00
const unsigned int count = std : : min < unsigned int > ( _command_log . count , 256 ) ;
2020-10-08 21:39:23 +00:00
buffer + = seprintf ( buffer , last , " Command Log: \n Showing most recent %u of %u commands \n " , count , _command_log . count ) ;
DumpSubCommandLog ( buffer , last , _command_log , count ) ;
if ( _command_log_aux . count > 0 ) {
2021-02-01 17:07:34 +00:00
const unsigned int aux_count = std : : min < unsigned int > ( _command_log_aux . count , 32 ) ;
2020-10-08 21:39:23 +00:00
buffer + = seprintf ( buffer , last , " \n Showing most recent %u of %u commands (aux log) \n " , aux_count , _command_log_aux . count ) ;
DumpSubCommandLog ( buffer , last , _command_log_aux , aux_count ) ;
}
2017-02-21 21:04:28 +00:00
return buffer ;
}
2007-09-10 15:21:14 +00:00
/*!
2019-04-10 21:07:06 +00:00
* This function range - checks a cmd , and checks if the cmd is not nullptr
2007-09-10 15:21:14 +00:00
*
2013-01-08 22:46:42 +00:00
* @ param cmd The integer value of a command
2007-09-10 15:21:14 +00:00
* @ return true if the command is valid ( and got a CommandProc function )
*/
2008-10-14 18:49:21 +00:00
bool IsValidCommand ( uint32 cmd )
2005-01-05 14:39:48 +00:00
{
2009-01-07 13:26:48 +00:00
cmd & = CMD_ID_MASK ;
2005-01-05 14:39:48 +00:00
2019-04-10 21:07:06 +00:00
return cmd < lengthof ( _command_proc_table ) & & _command_proc_table [ cmd ] . proc ! = nullptr ;
2005-01-05 14:39:48 +00:00
}
2007-09-10 15:21:14 +00:00
/*!
2009-01-07 13:26:48 +00:00
* This function mask the parameter with CMD_ID_MASK and returns
2007-09-10 15:21:14 +00:00
* the flags which belongs to the given command .
*
* @ param cmd The integer value of the command
* @ return The flags for this command
*/
2011-11-14 20:38:56 +00:00
CommandFlags GetCommandFlags ( uint32 cmd )
2006-06-10 08:37:41 +00:00
{
2008-10-14 18:49:21 +00:00
assert ( IsValidCommand ( cmd ) ) ;
2009-01-07 13:26:48 +00:00
return _command_proc_table [ cmd & CMD_ID_MASK ] . flags ;
2006-06-10 08:37:41 +00:00
}
2005-05-14 19:25:18 +00:00
2010-04-11 10:11:26 +00:00
/*!
* This function mask the parameter with CMD_ID_MASK and returns
* the name which belongs to the given command .
*
* @ param cmd The integer value of the command
* @ return The name for this command
*/
const char * GetCommandName ( uint32 cmd )
{
assert ( IsValidCommand ( cmd ) ) ;
return _command_proc_table [ cmd & CMD_ID_MASK ] . name ;
}
2010-12-07 21:08:35 +00:00
/**
* Returns whether the command is allowed while the game is paused .
* @ param cmd The command to check .
* @ return True if the command is allowed while paused , false otherwise .
*/
bool IsCommandAllowedWhilePaused ( uint32 cmd )
{
/* Lookup table for the command types that are allowed for a given pause level setting. */
static const int command_type_lookup [ ] = {
CMDPL_ALL_ACTIONS , ///< CMDT_LANDSCAPE_CONSTRUCTION
CMDPL_NO_LANDSCAPING , ///< CMDT_VEHICLE_CONSTRUCTION
CMDPL_NO_LANDSCAPING , ///< CMDT_MONEY_MANAGEMENT
CMDPL_NO_CONSTRUCTION , ///< CMDT_VEHICLE_MANAGEMENT
CMDPL_NO_CONSTRUCTION , ///< CMDT_ROUTE_MANAGEMENT
CMDPL_NO_CONSTRUCTION , ///< CMDT_OTHER_MANAGEMENT
CMDPL_NO_CONSTRUCTION , ///< CMDT_COMPANY_SETTING
CMDPL_NO_ACTIONS , ///< CMDT_SERVER_SETTING
2011-02-07 22:23:37 +00:00
CMDPL_NO_ACTIONS , ///< CMDT_CHEAT
2010-12-07 21:08:35 +00:00
} ;
2020-12-27 10:44:22 +00:00
static_assert ( lengthof ( command_type_lookup ) = = CMDT_END ) ;
2010-12-07 21:08:35 +00:00
assert ( IsValidCommand ( cmd ) ) ;
2010-12-07 21:13:00 +00:00
return _game_mode = = GM_EDITOR | | command_type_lookup [ _command_proc_table [ cmd & CMD_ID_MASK ] . type ] < = _settings_game . construction . command_pause_level ;
2010-12-07 21:08:35 +00:00
}
2008-01-09 17:47:05 +00:00
static int _docommand_recursive = 0 ;
2005-08-07 10:03:14 +00:00
2019-03-03 20:55:15 +00:00
struct cmd_text_info_dumper {
const char * CommandTextInfo ( const char * text , uint32 binary_length )
{
char * b = this - > buffer ;
const char * last = lastof ( this - > buffer ) ;
if ( text ) {
b + = seprintf ( b , last , " , text " ) ;
}
if ( binary_length ) {
b + = seprintf ( b , last , " , bin length: %u " , binary_length ) ;
} else if ( text ) {
b + = seprintf ( b , last , " , str length: %u " , ( uint ) strlen ( text ) ) ;
}
return this - > buffer ;
}
private :
char buffer [ 64 ] ;
} ;
2007-09-10 15:21:14 +00:00
/*!
* This function executes a given command with the parameters from the # CommandProc parameter list .
* Depending on the flags parameter it execute or test a command .
*
* @ param tile The tile to apply the command on ( for the # CommandProc )
* @ param p1 Additional data for the command ( for the # CommandProc )
* @ param p2 Additional data for the command ( for the # CommandProc )
* @ param flags Flags for the command and how to execute the command
2008-12-28 14:37:19 +00:00
* @ param cmd The command - id to execute ( a value of the CMD_ * enums )
2009-09-18 14:23:58 +00:00
* @ param text The text to pass
2019-03-03 20:53:59 +00:00
* @ param binary_length The length of binary data in text
2007-09-10 15:21:14 +00:00
* @ see CommandProc
2009-01-08 14:55:28 +00:00
* @ return the cost
2007-09-10 15:21:14 +00:00
*/
2020-10-17 13:42:46 +00:00
CommandCost DoCommandEx ( TileIndex tile , uint32 p1 , uint32 p2 , uint64 p3 , DoCommandFlag flags , uint32 cmd , const char * text , uint32 binary_length )
2004-08-09 17:04:08 +00:00
{
2020-10-17 13:42:46 +00:00
SCOPE_INFO_FMT ( [ = ] , " DoCommand: tile: %X (%d x %d), p1: 0x%X, p2: 0x%X, p3: " OTTD_PRINTFHEX64 " , flags: 0x%X, company: %s, cmd: 0x%X (%s)%s " ,
tile , TileX ( tile ) , TileY ( tile ) , p1 , p2 , p3 , flags , scope_dumper ( ) . CompanyInfo ( _current_company ) , cmd , GetCommandName ( cmd ) , cmd_text_info_dumper ( ) . CommandTextInfo ( text , binary_length ) ) ;
2016-02-17 19:45:24 +00:00
2007-06-18 10:48:15 +00:00
CommandCost res ;
2004-09-10 19:02:27 +00:00
2005-05-07 10:26:45 +00:00
/* Do not even think about executing out-of-bounds tile-commands */
2009-01-21 02:31:55 +00:00
if ( tile ! = 0 & & ( tile > = MapSize ( ) | | ( ! IsValidTile ( tile ) & & ( flags & DC_ALL_TILES ) = = 0 ) ) ) return CMD_ERROR ;
2005-05-07 10:26:45 +00:00
2009-07-22 23:39:35 +00:00
/* Chop of any CMD_MSG or other flags; we don't need those here */
2019-03-03 20:53:59 +00:00
const Command & command = _command_proc_table [ cmd & CMD_ID_MASK ] ;
2004-08-09 17:04:08 +00:00
_docommand_recursive + + ;
2007-02-23 11:50:43 +00:00
/* only execute the test call if it's toplevel, or we're not execing. */
2008-02-04 22:44:05 +00:00
if ( _docommand_recursive = = 1 | | ! ( flags & DC_EXEC ) ) {
2018-09-20 22:44:14 +00:00
if ( _docommand_recursive = = 1 ) _cleared_object_areas . clear ( ) ;
2008-01-09 17:47:05 +00:00
SetTownRatingTestMode ( true ) ;
2020-10-17 13:42:46 +00:00
res = command . Execute ( tile , flags & ~ DC_EXEC , p1 , p2 , p3 , text , binary_length ) ;
2008-01-09 17:47:05 +00:00
SetTownRatingTestMode ( false ) ;
2010-01-18 22:57:21 +00:00
if ( res . Failed ( ) ) {
2004-08-09 17:04:08 +00:00
goto error ;
}
2006-06-10 08:37:41 +00:00
if ( _docommand_recursive = = 1 & &
! ( flags & DC_QUERY_COST ) & &
2008-02-09 15:07:31 +00:00
! ( flags & DC_BANKRUPT ) & &
2010-03-14 12:58:51 +00:00
! CheckCompanyHasMoney ( res ) ) { // CheckCompanyHasMoney() modifies 'res' to an error if it fails.
2006-06-10 08:37:41 +00:00
goto error ;
2004-08-09 17:04:08 +00:00
}
if ( ! ( flags & DC_EXEC ) ) {
_docommand_recursive - - ;
return res ;
}
}
2005-01-04 17:11:03 +00:00
/* Execute the command here. All cost-relevant functions set the expenses type
2008-01-09 16:55:48 +00:00
* themselves to the cost object at some point */
2018-09-20 22:44:14 +00:00
if ( _docommand_recursive = = 1 ) _cleared_object_areas . clear ( ) ;
2020-10-17 13:42:46 +00:00
res = command . Execute ( tile , flags , p1 , p2 , p3 , text , binary_length ) ;
2010-01-18 22:57:21 +00:00
if ( res . Failed ( ) ) {
2004-08-09 17:04:08 +00:00
error :
_docommand_recursive - - ;
2010-03-14 12:58:51 +00:00
return res ;
2004-08-09 17:04:08 +00:00
}
2007-02-23 11:50:43 +00:00
/* if toplevel, subtract the money. */
2008-02-09 15:07:31 +00:00
if ( - - _docommand_recursive = = 0 & & ! ( flags & DC_BANKRUPT ) ) {
2008-09-30 20:39:50 +00:00
SubtractMoneyFromCompany ( res ) ;
2004-08-09 17:04:08 +00:00
}
return res ;
}
2007-09-10 15:21:14 +00:00
/*!
* This functions returns the money which can be used to execute a command .
2008-09-30 20:39:50 +00:00
* This is either the money of the current company or INT64_MAX if there
* is no such a company " at the moment " like the server itself .
2007-09-10 15:21:14 +00:00
*
2008-09-30 20:39:50 +00:00
* @ return The available money of a company or INT64_MAX
2007-09-10 15:21:14 +00:00
*/
2007-06-21 14:32:27 +00:00
Money GetAvailableMoneyForCommand ( )
2004-08-09 17:04:08 +00:00
{
2008-09-30 20:39:50 +00:00
CompanyID company = _current_company ;
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company ) ) return INT64_MAX ;
2009-05-16 23:34:14 +00:00
return Company : : Get ( company ) - > money ;
2004-08-09 17:04:08 +00:00
}
2021-10-18 17:01:27 +00:00
static void AppendCommandLogEntry ( const CommandCost & res , TileIndex tile , uint32 p1 , uint32 p2 , uint64 p3 , uint32 cmd , CommandLogEntryFlag log_flags , const char * text )
2020-09-28 17:32:23 +00:00
{
if ( res . Failed ( ) ) log_flags | = CLEF_CMD_FAILED ;
if ( _generating_world ) log_flags | = CLEF_GENERATING_WORLD ;
2020-10-08 21:39:23 +00:00
CommandLog & cmd_log = ( GetCommandFlags ( cmd ) & CMD_LOG_AUX ) ? _command_log_aux : _command_log ;
if ( _networking & & cmd_log . count > 0 ) {
CommandLogEntry & current = cmd_log . log [ ( cmd_log . next - 1 ) % cmd_log . log . size ( ) ] ;
2020-09-28 17:32:23 +00:00
if ( current . log_flags & CLEF_ONLY_SENDING & & ( ( current . log_flags ^ log_flags ) & ~ ( CLEF_SCRIPT | CLEF_MY_CMD ) ) = = CLEF_ONLY_SENDING & &
2020-10-17 13:42:46 +00:00
current . tile = = tile & & current . p1 = = p1 & & current . p2 = = p2 & & current . p3 = = p3 & & ( ( current . cmd ^ cmd ) & ~ CMD_NETWORK_COMMAND ) = = 0 & & current . date = = _date & &
2020-09-28 17:32:23 +00:00
current . date_fract = = _date_fract & & current . tick_skip_counter = = _tick_skip_counter & &
current . current_company = = _current_company & & current . local_company = = _local_company ) {
current . log_flags | = log_flags | CLEF_TWICE ;
current . log_flags & = ~ CLEF_ONLY_SENDING ;
return ;
}
}
2021-10-18 17:01:27 +00:00
std : : string str ;
switch ( cmd & CMD_ID_MASK ) {
case CMD_CHANGE_SETTING :
case CMD_CHANGE_COMPANY_SETTING :
if ( text ! = nullptr ) str . assign ( text ) ;
break ;
}
cmd_log . log [ cmd_log . next ] = CommandLogEntry ( tile , p1 , p2 , p3 , cmd , log_flags , std : : move ( str ) ) ;
2020-10-08 21:39:23 +00:00
cmd_log . next = ( cmd_log . next + 1 ) % cmd_log . log . size ( ) ;
cmd_log . count + + ;
2020-09-28 17:32:23 +00:00
}
2007-09-10 15:21:14 +00:00
/*!
2008-09-30 20:39:50 +00:00
* Toplevel network safe docommand function for the current company . Must not be called recursively .
2007-09-10 15:21:14 +00:00
* The callback is called when the command succeeded or failed . The parameters
2010-03-14 12:39:24 +00:00
* \ a tile , \ a p1 , and \ a p2 are from the # CommandProc function . The parameter \ a cmd is the command to execute .
* The parameter \ a my_cmd is used to indicate if the command is from a company or the server .
2007-09-10 15:21:14 +00:00
*
* @ param tile The tile to perform a command on ( see # CommandProc )
* @ param p1 Additional data for the command ( see # CommandProc )
* @ param p2 Additional data for the command ( see # CommandProc )
2020-10-17 13:42:46 +00:00
* @ param p3 Additional data for the command ( see # CommandProc )
2007-09-10 15:21:14 +00:00
* @ param cmd The command to execute ( a CMD_ * value )
2008-12-28 14:37:19 +00:00
* @ param callback A callback function to call after the command is finished
* @ param text The text to pass
2008-09-30 20:39:50 +00:00
* @ param my_cmd indicator if the command is from a company or server ( to display error messages for a user )
2019-03-03 20:53:59 +00:00
* @ param binary_length The length of binary data in text
2010-03-14 12:39:24 +00:00
* @ return \ c true if the command succeeded , else \ c false .
2007-09-10 15:21:14 +00:00
*/
2020-10-17 13:42:46 +00:00
bool DoCommandPEx ( TileIndex tile , uint32 p1 , uint32 p2 , uint64 p3 , uint32 cmd , CommandCallback * callback , const char * text , uint32 binary_length , bool my_cmd )
2004-08-09 17:04:08 +00:00
{
2020-10-17 13:42:46 +00:00
SCOPE_INFO_FMT ( [ = ] , " DoCommandP: tile: %X (%d x %d), p1: 0x%X, p2: 0x%X, p3: 0x " OTTD_PRINTFHEX64 " , company: %s, cmd: 0x%X (%s), my_cmd: %d%s " ,
tile , TileX ( tile ) , TileY ( tile ) , p1 , p2 , p3 , scope_dumper ( ) . CompanyInfo ( _current_company ) , cmd , GetCommandName ( cmd ) , my_cmd , cmd_text_info_dumper ( ) . CommandTextInfo ( text , binary_length ) ) ;
2016-02-17 19:45:24 +00:00
2010-01-11 20:39:38 +00:00
/* Cost estimation is generally only done when the
2019-09-29 20:27:32 +00:00
* local user presses shift while doing something .
2010-01-11 20:39:38 +00:00
* However , in case of incoming network commands ,
2011-08-21 12:46:46 +00:00
* map generation or the pause button we do want
2010-01-11 20:39:38 +00:00
* to execute . */
bool estimate_only = _shift_pressed & & IsLocalCompany ( ) & &
2011-08-21 12:46:46 +00:00
! _generating_world & &
2010-01-11 20:39:38 +00:00
! ( cmd & CMD_NETWORK_COMMAND ) & &
2019-02-04 17:19:21 +00:00
! ( GetCommandFlags ( cmd ) & CMD_NO_EST ) ;
2004-08-09 17:04:08 +00:00
2010-01-11 20:39:38 +00:00
/* We're only sending the command, so don't do
* fancy things for ' success ' . */
bool only_sending = _networking & & ! ( cmd & CMD_NETWORK_COMMAND ) ;
2009-01-07 13:31:09 +00:00
2010-01-11 20:39:38 +00:00
/* Where to show the message? */
2009-01-07 13:31:09 +00:00
int x = TileX ( tile ) * TILE_SIZE ;
int y = TileY ( tile ) * TILE_SIZE ;
2004-08-09 17:04:08 +00:00
2020-06-14 11:04:26 +00:00
if ( _pause_mode ! = PM_UNPAUSED & & ! IsCommandAllowedWhilePaused ( cmd ) & & ! estimate_only ) {
2010-12-07 21:09:30 +00:00
ShowErrorMessage ( GB ( cmd , 16 , 16 ) , STR_ERROR_NOT_ALLOWED_WHILE_PAUSED , WL_INFO , x , y ) ;
return false ;
}
2010-08-18 18:57:58 +00:00
/* Only set p2 when the command does not come from the network. */
2010-08-18 20:48:38 +00:00
if ( ! ( cmd & CMD_NETWORK_COMMAND ) & & GetCommandFlags ( cmd ) & CMD_CLIENT_ID & & p2 = = 0 ) p2 = CLIENT_ID_SERVER ;
2010-08-18 17:06:45 +00:00
2021-04-18 11:35:32 +00:00
GameRandomSeedChecker random_state ;
2021-12-06 18:19:49 +00:00
uint order_backup_update_counter = OrderBackup : : GetUpdateCounter ( ) ;
2021-04-18 11:35:32 +00:00
2020-10-17 13:42:46 +00:00
CommandCost res = DoCommandPInternal ( tile , p1 , p2 , p3 , cmd , callback , text , my_cmd , estimate_only , binary_length ) ;
2019-04-04 17:44:04 +00:00
CommandLogEntryFlag log_flags ;
log_flags = CLEF_NONE ;
2020-10-17 12:00:57 +00:00
if ( binary_length = = 0 & & ! StrEmpty ( text ) ) log_flags | = CLEF_TEXT ;
2019-04-04 17:44:04 +00:00
if ( estimate_only ) log_flags | = CLEF_ESTIMATE_ONLY ;
if ( only_sending ) log_flags | = CLEF_ONLY_SENDING ;
if ( my_cmd ) log_flags | = CLEF_MY_CMD ;
if ( binary_length > 0 ) log_flags | = CLEF_BINARY ;
2021-04-18 11:35:32 +00:00
if ( ! random_state . Check ( ) ) log_flags | = CLEF_RANDOM ;
2021-12-06 18:19:49 +00:00
if ( order_backup_update_counter ! = OrderBackup : : GetUpdateCounter ( ) ) log_flags | = CLEF_ORDER_BACKUP ;
2021-10-18 17:01:27 +00:00
AppendCommandLogEntry ( res , tile , p1 , p2 , p3 , cmd , log_flags , text ) ;
2019-04-04 17:44:04 +00:00
2021-10-03 21:26:25 +00:00
if ( unlikely ( HasChickenBit ( DCBF_DESYNC_CHECK_POST_COMMAND ) ) & & ! ( GetCommandFlags ( cmd ) & CMD_LOG_AUX ) ) {
2021-10-03 22:58:35 +00:00
CheckCachesFlags flags = CHECK_CACHE_ALL | CHECK_CACHE_EMIT_LOG ;
if ( HasChickenBit ( DCBF_DESYNC_CHECK_NO_GENERAL ) ) flags & = ~ CHECK_CACHE_GENERAL ;
CheckCaches ( true , nullptr , flags ) ;
2021-10-03 21:26:25 +00:00
}
2010-01-18 22:57:21 +00:00
if ( res . Failed ( ) ) {
2010-01-11 20:39:38 +00:00
/* Only show the error when it's for us. */
StringID error_part1 = GB ( cmd , 16 , 16 ) ;
if ( estimate_only | | ( IsLocalCompany ( ) & & error_part1 ! = 0 & & my_cmd ) ) {
2018-11-19 18:59:25 +00:00
ShowErrorMessage ( error_part1 , res . GetErrorMessage ( ) , WL_INFO , x , y , res . GetTextRefStackGRF ( ) , res . GetTextRefStackSize ( ) , res . GetTextRefStack ( ) , res . GetExtraErrorMessage ( ) ) ;
2010-01-11 20:39:38 +00:00
}
} else if ( estimate_only ) {
ShowEstimatedCostOrIncome ( res . GetCost ( ) , x , y ) ;
2022-05-15 12:54:13 +00:00
} else if ( ! only_sending & & tile ! = 0 & & IsLocalCompany ( ) & & _game_mode ! = GM_EDITOR & & HasBit ( _extra_display_opt , XDO_SHOW_MONEY_TEXT_EFFECTS ) ) {
2010-01-11 20:39:38 +00:00
/* Only show the cost animation when we did actually
* execute the command , i . e . we ' re not sending it to
* the server , when it has cost the local company
* something . Furthermore in the editor there is no
* concept of cost , so don ' t show it there either . */
2011-11-04 10:18:13 +00:00
ShowCostOrIncomeAnimation ( x , y , GetSlopePixelZ ( x , y ) , res . GetCost ( ) ) ;
2010-01-11 20:39:38 +00:00
}
2019-04-10 21:07:06 +00:00
if ( ! estimate_only & & ! only_sending & & callback ! = nullptr ) {
2020-10-17 13:42:46 +00:00
callback ( res , tile , p1 , p2 , p3 , cmd ) ;
2010-01-11 20:39:38 +00:00
}
2019-04-04 17:44:04 +00:00
return res . Succeeded ( ) ;
}
2020-10-17 13:42:46 +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 , uint32 binary_length )
2019-04-04 17:44:04 +00:00
{
2021-04-18 11:35:32 +00:00
GameRandomSeedChecker random_state ;
2021-12-06 18:19:49 +00:00
uint order_backup_update_counter = OrderBackup : : GetUpdateCounter ( ) ;
2021-04-18 11:35:32 +00:00
2020-10-17 13:42:46 +00:00
CommandCost res = DoCommandPInternal ( tile , p1 , p2 , p3 , cmd , callback , text , my_cmd , estimate_only , binary_length ) ;
2019-04-04 17:44:04 +00:00
2017-02-21 21:04:28 +00:00
CommandLogEntryFlag log_flags ;
2019-04-04 17:44:04 +00:00
log_flags = CLEF_SCRIPT ;
2020-10-17 12:00:57 +00:00
if ( binary_length = = 0 & & ! StrEmpty ( text ) ) log_flags | = CLEF_TEXT ;
2017-02-21 21:04:28 +00:00
if ( estimate_only ) log_flags | = CLEF_ESTIMATE_ONLY ;
2020-09-28 17:32:23 +00:00
if ( _networking & & ! ( cmd & CMD_NETWORK_COMMAND ) ) log_flags | = CLEF_ONLY_SENDING ;
2017-02-21 21:04:28 +00:00
if ( my_cmd ) log_flags | = CLEF_MY_CMD ;
2017-02-21 21:50:08 +00:00
if ( binary_length > 0 ) log_flags | = CLEF_BINARY ;
2021-04-18 11:35:32 +00:00
if ( ! random_state . Check ( ) ) log_flags | = CLEF_RANDOM ;
2021-12-06 18:19:49 +00:00
if ( order_backup_update_counter ! = OrderBackup : : GetUpdateCounter ( ) ) log_flags | = CLEF_ORDER_BACKUP ;
2021-10-18 17:01:27 +00:00
AppendCommandLogEntry ( res , tile , p1 , p2 , p3 , cmd , log_flags , text ) ;
2017-02-21 21:04:28 +00:00
2021-10-03 21:26:25 +00:00
if ( unlikely ( HasChickenBit ( DCBF_DESYNC_CHECK_POST_COMMAND ) ) & & ! ( GetCommandFlags ( cmd ) & CMD_LOG_AUX ) ) {
2021-10-03 22:58:35 +00:00
CheckCachesFlags flags = CHECK_CACHE_ALL | CHECK_CACHE_EMIT_LOG ;
if ( HasChickenBit ( DCBF_DESYNC_CHECK_NO_GENERAL ) ) flags & = ~ CHECK_CACHE_GENERAL ;
CheckCaches ( true , nullptr , flags ) ;
2021-10-03 21:26:25 +00:00
}
2019-04-04 17:44:04 +00:00
return res ;
2010-01-11 20:39:38 +00:00
}
/**
* Helper to deduplicate the code for returning .
* @ param cmd the command cost to return .
*/
2014-02-23 22:03:08 +00:00
# define return_dcpi(cmd) { _docommand_recursive = 0; return cmd; }
2010-01-11 20:39:38 +00:00
/*!
* Helper function for the toplevel network safe docommand function for the current company .
*
* @ param tile The tile to perform a command on ( see # CommandProc )
* @ param p1 Additional data for the command ( see # CommandProc )
* @ param p2 Additional data for the command ( see # CommandProc )
2020-10-17 13:42:46 +00:00
* @ param p3 Additional data for the command ( see # CommandProc )
2010-01-11 20:39:38 +00:00
* @ param cmd The command to execute ( a CMD_ * value )
* @ param callback A callback function to call after the command is finished
* @ param text The text to pass
* @ param my_cmd indicator if the command is from a company or server ( to display error messages for a user )
* @ param estimate_only whether to give only the estimate or also execute the command
* @ return the command cost of this function .
*/
2020-10-17 13:42:46 +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 , uint32 binary_length )
2010-01-11 20:39:38 +00:00
{
/* Prevent recursion; it gives a mess over the network */
assert ( _docommand_recursive = = 0 ) ;
_docommand_recursive = 1 ;
/* Reset the state. */
2004-08-09 17:04:08 +00:00
_additional_cash_required = 0 ;
2010-01-11 20:39:38 +00:00
/* Get pointer to command handler */
2009-01-07 13:26:48 +00:00
byte cmd_id = cmd & CMD_ID_MASK ;
assert ( cmd_id < lengthof ( _command_proc_table ) ) ;
2009-01-07 13:31:09 +00:00
2019-03-03 20:53:59 +00:00
const Command & command = _command_proc_table [ cmd_id ] ;
2010-01-11 20:39:38 +00:00
/* Shouldn't happen, but you never know when someone adds
* NULLs to the _command_proc_table . */
2019-04-11 17:14:13 +00:00
assert ( command . proc ! = nullptr ) ;
2004-08-09 17:04:08 +00:00
2009-01-07 13:31:09 +00:00
/* Command flags are used internally */
2011-11-14 20:38:56 +00:00
CommandFlags cmd_flags = GetCommandFlags ( cmd ) ;
2009-01-12 15:27:39 +00:00
/* Flags get send to the DoCommand */
2009-02-09 21:20:05 +00:00
DoCommandFlag flags = CommandFlagsToDCFlags ( cmd_flags ) ;
2009-01-07 13:31:09 +00:00
2010-08-18 17:06:45 +00:00
/* Make sure p2 is properly set to a ClientID. */
assert ( ! ( cmd_flags & CMD_CLIENT_ID ) | | p2 ! = 0 ) ;
2009-01-21 02:31:55 +00:00
/* Do not even think about executing out-of-bounds tile-commands */
2014-02-23 22:03:08 +00:00
if ( tile ! = 0 & & ( tile > = MapSize ( ) | | ( ! IsValidTile ( tile ) & & ( cmd_flags & CMD_ALL_TILES ) = = 0 ) ) ) return_dcpi ( CMD_ERROR ) ;
2009-01-21 02:31:55 +00:00
2009-05-26 21:24:11 +00:00
/* Always execute server and spectator commands as spectator */
2010-06-23 14:38:17 +00:00
bool exec_as_spectator = ( cmd_flags & ( CMD_SPECTATOR | CMD_SERVER ) ) ! = 0 ;
2009-05-26 21:55:49 +00:00
2009-05-26 19:23:02 +00:00
/* If the company isn't valid it may only do server command or start a new company!
* The server will ditch any server commands a client sends to it , so effectively
* this guards the server from executing functions for an invalid company . */
2011-12-19 20:50:36 +00:00
if ( _game_mode = = GM_NORMAL & & ! exec_as_spectator & & ! Company : : IsValidID ( _current_company ) & & ! ( _current_company = = OWNER_DEITY & & ( cmd_flags & CMD_DEITY ) ! = 0 ) ) {
2014-02-23 22:03:08 +00:00
return_dcpi ( CMD_ERROR ) ;
2009-05-26 19:23:02 +00:00
}
2009-02-04 16:57:40 +00:00
2019-04-22 08:10:04 +00:00
Backup < CompanyID > cur_company ( _current_company , FILE_LINE ) ;
2010-06-05 13:32:42 +00:00
if ( exec_as_spectator ) cur_company . Change ( COMPANY_SPECTATOR ) ;
2010-01-11 20:39:38 +00:00
bool test_and_exec_can_differ = ( cmd_flags & CMD_NO_TEST ) ! = 0 ;
2019-05-21 19:48:43 +00:00
GameRandomSeedChecker random_state ;
2012-01-09 22:21:45 +00:00
/* Test the command. */
2018-09-20 22:44:14 +00:00
_cleared_object_areas . clear ( ) ;
2012-01-09 22:21:45 +00:00
SetTownRatingTestMode ( true ) ;
2014-02-23 22:03:08 +00:00
BasePersistentStorageArray : : SwitchMode ( PSM_ENTER_TESTMODE ) ;
2020-10-17 13:42:46 +00:00
CommandCost res = command . Execute ( tile , flags , p1 , p2 , p3 , text , binary_length ) ;
2014-02-23 22:03:08 +00:00
BasePersistentStorageArray : : SwitchMode ( PSM_LEAVE_TESTMODE ) ;
2012-01-09 22:21:45 +00:00
SetTownRatingTestMode ( false ) ;
2019-05-21 19:48:43 +00:00
if ( ! random_state . Check ( ) ) {
2020-10-17 13:42:46 +00:00
std : : string msg = stdstr_fmt ( " Random seed changed in test command: company: %02x; tile: %06x (%u x %u); p1: %08x; p2: %08x; p3: " OTTD_PRINTFHEX64PAD " ; cmd: %08x; \" %s \" %X (%s) " ,
( int ) _current_company , tile , TileX ( tile ) , TileY ( tile ) , p1 , p2 , p3 , cmd & ~ CMD_NETWORK_COMMAND , text , binary_length , GetCommandName ( cmd ) ) ;
2019-05-22 18:57:16 +00:00
DEBUG ( desync , 0 , " msg: date{%08x; %02x; %02x}; %s " , _date , _date_fract , _tick_skip_counter , msg . c_str ( ) ) ;
LogDesyncMsg ( std : : move ( msg ) ) ;
2019-05-21 19:48:43 +00:00
}
2012-01-09 22:21:45 +00:00
/* Make sure we're not messing things up here. */
assert ( exec_as_spectator ? _current_company = = COMPANY_SPECTATOR : cur_company . Verify ( ) ) ;
/* If the command fails, we're doing an estimate
* or the player does not have enough money
* ( unless it ' s a command where the test and
* execution phase might return different costs )
* we bail out here . */
if ( res . Failed ( ) | | estimate_only | |
( ! test_and_exec_can_differ & & ! CheckCompanyHasMoney ( res ) ) ) {
2012-01-14 19:44:25 +00:00
if ( ! _networking | | _generating_world | | ( cmd & CMD_NETWORK_COMMAND ) ! = 0 ) {
/* Log the failed command as well. Just to be able to be find
* causes of desyncs due to bad command test implementations . */
2020-10-17 13:42:46 +00:00
DEBUG ( desync , 1 , " cmdf: date{%08x; %02x; %02x}; company: %02x; tile: %06x (%u x %u); p1: %08x; p2: %08x; p3: " OTTD_PRINTFHEX64PAD " ; cmd: %08x; \" %s \" %X (%s) " ,
_date , _date_fract , _tick_skip_counter , ( int ) _current_company , tile , TileX ( tile ) , TileY ( tile ) , p1 , p2 , p3 , cmd & ~ CMD_NETWORK_COMMAND , text , binary_length , GetCommandName ( cmd ) ) ;
2012-01-14 19:44:25 +00:00
}
2012-01-09 22:21:45 +00:00
cur_company . Restore ( ) ;
2014-02-23 22:03:08 +00:00
return_dcpi ( res ) ;
2004-08-09 17:04:08 +00:00
}
2009-05-26 19:23:02 +00:00
/*
* If we are in network , and the command is not from the network
2005-05-17 20:52:52 +00:00
* send it to the command - queue and abort execution
*/
2011-12-19 20:56:50 +00:00
if ( _networking & & ! _generating_world & & ! ( cmd & CMD_NETWORK_COMMAND ) ) {
2020-10-17 13:42:46 +00:00
NetworkSendCommand ( tile , p1 , p2 , p3 , cmd & ~ CMD_FLAGS_MASK , callback , text , _current_company , binary_length ) ;
2010-06-05 13:32:42 +00:00
cur_company . Restore ( ) ;
2010-01-11 20:39:38 +00:00
/* Don't return anything special here; no error, no costs.
* This way it ' s not handled by DoCommand and only the
* actual execution of the command causes messages . Also
* reset the storages as we ' ve not executed the command . */
2014-02-23 22:03:08 +00:00
return_dcpi ( CommandCost ( ) ) ;
2004-08-09 17:04:08 +00:00
}
2020-10-17 13:42:46 +00:00
DEBUG ( desync , 1 , " cmd: date{%08x; %02x; %02x}; company: %02x; tile: %06x (%u x %u); p1: %08x; p2: %08x; p3: " OTTD_PRINTFHEX64PAD " ; cmd: %08x; \" %s \" %X (%s) " ,
_date , _date_fract , _tick_skip_counter , ( int ) _current_company , tile , TileX ( tile ) , TileY ( tile ) , p1 , p2 , p3 , cmd & ~ CMD_NETWORK_COMMAND , text , binary_length , GetCommandName ( cmd ) ) ;
2004-08-09 17:04:08 +00:00
2005-01-04 17:11:03 +00:00
/* Actually try and execute the command. If no cost-type is given
* use the construction one */
2018-09-20 22:44:14 +00:00
_cleared_object_areas . clear ( ) ;
2014-02-23 22:03:08 +00:00
BasePersistentStorageArray : : SwitchMode ( PSM_ENTER_COMMAND ) ;
2020-10-17 13:42:46 +00:00
CommandCost res2 = command . Execute ( tile , flags | DC_EXEC , p1 , p2 , p3 , text , binary_length ) ;
2014-02-23 22:03:08 +00:00
BasePersistentStorageArray : : SwitchMode ( PSM_LEAVE_COMMAND ) ;
2004-09-10 19:02:27 +00:00
2010-06-05 13:32:42 +00:00
if ( cmd_id = = CMD_COMPANY_CTRL ) {
cur_company . Trash ( ) ;
/* We are a new company -> Switch to new local company.
* We were closed down - > Switch to spectator
* Some other company opened / closed down - > The outside function will switch back */
_current_company = _local_company ;
} else {
/* Make sure nothing bad happened, like changing the current company. */
assert ( exec_as_spectator ? _current_company = = COMPANY_SPECTATOR : cur_company . Verify ( ) ) ;
cur_company . Restore ( ) ;
}
2009-02-07 18:09:30 +00:00
2012-01-09 22:21:45 +00:00
/* If the test and execution can differ we have to check the
* return of the command . Otherwise we can check whether the
* test and execution have yielded the same result ,
* i . e . cost and error state are the same . */
if ( ! test_and_exec_can_differ ) {
2016-02-16 18:27:21 +00:00
assert_msg ( res . GetCost ( ) = = res2 . GetCost ( ) & & res . Failed ( ) = = res2 . Failed ( ) ,
" Command: cmd: 0x%X (%s), Test: %s, Exec: %s " , cmd , GetCommandName ( cmd ) ,
res . AllocSummaryMessage ( GB ( cmd , 16 , 16 ) ) , res2 . AllocSummaryMessage ( GB ( cmd , 16 , 16 ) ) ) ; // sanity check
2010-01-18 22:57:21 +00:00
} else if ( res2 . Failed ( ) ) {
2014-02-23 22:03:08 +00:00
return_dcpi ( res2 ) ;
2004-08-09 17:04:08 +00:00
}
2010-01-11 20:39:38 +00:00
/* If we're needing more money and we haven't done
* anything yet , ask for the money ! */
if ( _additional_cash_required ! = 0 & & res2 . GetCost ( ) = = 0 ) {
2010-04-17 20:21:33 +00:00
/* It could happen we removed rail, thus gained money, and deleted something else.
* So make sure the signal buffer is empty even in this case */
UpdateSignalsInBuffer ( ) ;
2021-08-28 11:51:06 +00:00
if ( _extra_aspects > 0 ) FlushDeferredAspectUpdates ( ) ;
2010-01-11 20:39:38 +00:00
SetDParam ( 0 , _additional_cash_required ) ;
2014-02-23 22:03:08 +00:00
return_dcpi ( CommandCost ( STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY ) ) ;
2004-08-09 17:04:08 +00:00
}
2010-01-11 20:39:38 +00:00
/* update last build coordinate of company. */
if ( tile ! = 0 ) {
Company * c = Company : : GetIfValid ( _current_company ) ;
2019-04-10 21:07:06 +00:00
if ( c ! = nullptr ) c - > last_build_coordinate = tile ;
2006-03-12 10:15:36 +00:00
}
2004-08-09 17:04:08 +00:00
2010-01-11 20:39:38 +00:00
SubtractMoneyFromCompany ( res2 ) ;
/* update signals if needed */
UpdateSignalsInBuffer ( ) ;
2021-08-28 11:51:06 +00:00
if ( _extra_aspects > 0 ) FlushDeferredAspectUpdates ( ) ;
2004-09-10 19:02:27 +00:00
2014-02-23 22:03:08 +00:00
return_dcpi ( res2 ) ;
2004-08-09 17:04:08 +00:00
}
2010-01-11 20:39:38 +00:00
# undef return_dcpi
2008-04-07 20:02:36 +00:00
2010-02-14 15:30:08 +00:00
/**
* Adds the cost of the given command return value to this cost .
* Also takes a possible error message when it is set .
* @ param ret The command to add the cost of .
*/
2010-02-14 15:44:21 +00:00
void CommandCost : : AddCost ( const CommandCost & ret )
2008-04-07 20:02:36 +00:00
{
this - > AddCost ( ret . cost ) ;
if ( this - > success & & ! ret . success ) {
this - > message = ret . message ;
this - > success = false ;
}
}
2011-07-03 14:32:15 +00:00
/**
* Values to put on the # TextRefStack for the error message .
* There is only one static instance of the array , just like there is only one
* instance of normal DParams .
*/
uint32 CommandCost : : textref_stack [ 16 ] ;
/**
* Activate usage of the NewGRF # TextRefStack for the error message .
2014-01-12 18:00:39 +00:00
* @ param grffile NewGRF that provides the # TextRefStack
* @ param num_registers number of entries to copy from the temporary NewGRF registers
2011-07-03 14:32:15 +00:00
*/
2014-01-12 18:00:39 +00:00
void CommandCost : : UseTextRefStack ( const GRFFile * grffile , uint num_registers )
2011-07-03 14:32:15 +00:00
{
extern TemporaryStorageArray < int32 , 0x110 > _temp_store ;
assert ( num_registers < lengthof ( textref_stack ) ) ;
2014-01-12 18:00:39 +00:00
this - > textref_stack_grffile = grffile ;
2011-07-03 14:32:15 +00:00
this - > textref_stack_size = num_registers ;
for ( uint i = 0 ; i < num_registers ; i + + ) {
textref_stack [ i ] = _temp_store . GetValue ( 0x100 + i ) ;
}
}
2016-02-16 18:27:21 +00:00
char * CommandCost : : AllocSummaryMessage ( StringID cmd_msg ) const
{
char buf [ DRAW_STRING_BUFFER ] ;
this - > WriteSummaryMessage ( buf , lastof ( buf ) , cmd_msg ) ;
return stredup ( buf , lastof ( buf ) ) ;
}
int CommandCost : : WriteSummaryMessage ( char * buf , char * last , StringID cmd_msg ) const
{
if ( this - > Succeeded ( ) ) {
return seprintf ( buf , last , " Success: cost: " OTTD_PRINTF64 , ( int64 ) this - > GetCost ( ) ) ;
} else {
if ( this - > textref_stack_size > 0 ) StartTextRefStackUsage ( this - > textref_stack_grffile , this - > textref_stack_size , textref_stack ) ;
char * b = buf ;
b + = seprintf ( b , last , " Failed: cost: " OTTD_PRINTF64 , ( int64 ) this - > GetCost ( ) ) ;
if ( cmd_msg ! = 0 ) {
b + = seprintf ( b , last , " " ) ;
b = GetString ( b , cmd_msg , last ) ;
}
if ( this - > message ! = INVALID_STRING_ID ) {
b + = seprintf ( b , last , " " ) ;
b = GetString ( b , this - > message , last ) ;
}
if ( this - > textref_stack_size > 0 ) StopTextRefStackUsage ( ) ;
return b - buf ;
}
}