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 console_cmds.cpp Implementation of the console hooks. */
2007-02-23 11:50:43 +00:00
2004-09-12 21:49:38 +00:00
# include "stdafx.h"
2008-05-24 10:15:06 +00:00
# include "console_internal.h"
2012-01-03 21:47:01 +00:00
# include "debug.h"
2008-03-31 00:17:39 +00:00
# include "engine_func.h"
2007-04-12 13:07:15 +00:00
# include "landscape.h"
2009-01-04 15:32:25 +00:00
# include "saveload/saveload.h"
2021-04-26 13:18:10 +00:00
# include "network/core/game_info.h"
2012-01-03 21:47:01 +00:00
# include "network/network.h"
# include "network/network_func.h"
2008-12-23 11:06:52 +00:00
# include "network/network_base.h"
2010-10-17 17:41:52 +00:00
# include "network/network_admin.h"
2011-02-11 22:10:10 +00:00
# include "network/network_client.h"
2007-12-21 21:50:46 +00:00
# include "command_func.h"
2008-01-07 00:19:09 +00:00
# include "settings_func.h"
2006-08-05 00:59:45 +00:00
# include "fios.h"
2008-08-31 10:50:05 +00:00
# include "fileio_func.h"
2006-07-28 21:51:00 +00:00
# include "screenshot.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"
2008-01-09 09:57:48 +00:00
# include "viewport_func.h"
2007-12-25 11:26:07 +00:00
# include "window_func.h"
2007-12-26 13:50:40 +00:00
# include "date_func.h"
2008-09-30 20:51:04 +00:00
# include "company_func.h"
2008-06-03 18:35:58 +00:00
# include "gamelog.h"
2009-01-12 17:11:45 +00:00
# include "ai/ai.hpp"
# include "ai/ai_config.hpp"
2010-03-24 20:47:03 +00:00
# include "newgrf.h"
2020-01-26 12:45:51 +00:00
# include "newgrf_profiling.h"
2010-01-15 16:41:15 +00:00
# include "console_func.h"
2011-02-05 16:07:23 +00:00
# include "engine_base.h"
2021-01-13 20:16:47 +00:00
# include "road.h"
# include "rail.h"
2011-12-19 20:55:56 +00:00
# include "game/game.hpp"
2012-12-09 16:53:41 +00:00
# include "table/strings.h"
2021-05-13 08:00:41 +00:00
# include "walltime_func.h"
2008-01-13 01:21:35 +00:00
2014-04-23 20:13:33 +00:00
# include "safeguards.h"
2009-03-15 00:32:18 +00:00
/* scriptfile handling */
2021-03-12 08:23:03 +00:00
static uint _script_current_depth ; ///< Depth of scripts running (used to abort execution when #ConReturn is encountered).
2004-09-14 16:10:20 +00:00
2016-09-04 12:55:21 +00:00
/** File list storage for the console, for caching the last 'ls' command. */
class ConsoleFileList : public FileList {
public :
ConsoleFileList ( ) : FileList ( )
{
this - > file_list_valid = false ;
}
/** Declare the file storage cache as being invalid, also clears all stored files. */
void InvalidateFileList ( )
{
2021-04-29 21:46:42 +00:00
this - > clear ( ) ;
2016-09-04 12:55:21 +00:00
this - > file_list_valid = false ;
}
/**
* ( Re - ) validate the file storage cache . Only makes a change if the storage was invalid , or if \ a force_reload .
2018-10-28 02:17:36 +00:00
* @ param force_reload Always reload the file storage cache .
2016-09-04 12:55:21 +00:00
*/
void ValidateFileList ( bool force_reload = false )
{
if ( force_reload | | ! this - > file_list_valid ) {
2016-09-04 16:06:50 +00:00
this - > BuildFileList ( FT_SAVEGAME , SLO_LOAD ) ;
2016-09-04 12:55:21 +00:00
this - > file_list_valid = true ;
}
}
bool file_list_valid ; ///< If set, the file list is valid.
} ;
static ConsoleFileList _console_file_list ; ///< File storage cache for the console.
2010-02-10 17:32:39 +00:00
/* console command defines */
2005-05-02 15:52:19 +00:00
# define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
2010-03-24 20:43:31 +00:00
# define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
2004-09-12 21:49:38 +00:00
2004-09-14 16:10:20 +00:00
2010-02-10 17:32:39 +00:00
/****************
* command hooks
* * * * * * * * * * * * * * * */
2004-09-12 21:49:38 +00:00
2011-02-14 19:52:26 +00:00
/**
* Check network availability and inform in console about failure of detection .
* @ return Network availability .
*/
2010-03-24 20:43:31 +00:00
static inline bool NetworkAvailable ( bool echo )
2004-09-12 21:49:38 +00:00
{
2005-05-02 15:52:19 +00:00
if ( ! _network_available ) {
2021-06-12 19:07:04 +00:00
if ( echo ) IConsolePrint ( CC_ERROR , " You cannot use this command because there is no network available. " ) ;
2004-09-12 21:49:38 +00:00
return false ;
2004-09-19 15:24:45 +00:00
}
2004-09-12 21:49:38 +00:00
return true ;
}
2011-02-14 19:52:26 +00:00
/**
* Check whether we are a server .
* @ return Are we a server ? True when yes , false otherwise .
*/
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookServerOnly )
2004-09-12 21:49:38 +00:00
{
2010-03-24 20:43:31 +00:00
if ( ! NetworkAvailable ( echo ) ) return CHR_DISALLOW ;
2005-05-02 15:52:19 +00:00
2004-12-04 17:54:56 +00:00
if ( ! _network_server ) {
2021-06-12 19:07:04 +00:00
if ( echo ) IConsolePrint ( CC_ERROR , " This command is only available to a network server. " ) ;
2010-03-24 20:43:31 +00:00
return CHR_DISALLOW ;
2004-09-19 15:24:45 +00:00
}
2010-03-24 20:43:31 +00:00
return CHR_ALLOW ;
2004-09-12 21:49:38 +00:00
}
2011-02-14 19:52:26 +00:00
/**
* Check whether we are a client in a network game .
* @ return Are we a client in a network game ? True when yes , false otherwise .
*/
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookClientOnly )
2004-09-12 21:49:38 +00:00
{
2010-03-24 20:43:31 +00:00
if ( ! NetworkAvailable ( echo ) ) return CHR_DISALLOW ;
2005-05-02 15:52:19 +00:00
if ( _network_server ) {
2021-06-12 19:07:04 +00:00
if ( echo ) IConsolePrint ( CC_ERROR , " This command is not available to a network server. " ) ;
2010-03-24 20:43:31 +00:00
return CHR_DISALLOW ;
2004-12-04 17:54:56 +00:00
}
2010-03-24 20:43:31 +00:00
return CHR_ALLOW ;
2004-12-04 17:54:56 +00:00
}
2011-02-14 19:52:26 +00:00
/**
* Check whether we are in a multiplayer game .
* @ return True when we are client or server in a network game .
*/
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookNeedNetwork )
2004-12-04 17:54:56 +00:00
{
2010-03-24 20:43:31 +00:00
if ( ! NetworkAvailable ( echo ) ) return CHR_DISALLOW ;
2005-05-02 15:52:19 +00:00
2011-02-11 22:10:10 +00:00
if ( ! _networking | | ( ! _network_server & & ! MyClient : : IsConnected ( ) ) ) {
2021-06-12 19:07:04 +00:00
if ( echo ) IConsolePrint ( CC_ERROR , " Not connected. This command is only available in multiplayer. " ) ;
2010-03-24 20:43:31 +00:00
return CHR_DISALLOW ;
2004-09-19 15:24:45 +00:00
}
2010-03-24 20:43:31 +00:00
return CHR_ALLOW ;
2004-09-12 21:49:38 +00:00
}
2011-02-14 19:52:26 +00:00
/**
2021-01-22 15:24:29 +00:00
* Check whether we are in singleplayer mode .
2011-02-14 19:52:26 +00:00
* @ return True when no network is active .
*/
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookNoNetwork )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( _networking ) {
2021-06-12 19:07:04 +00:00
if ( echo ) IConsolePrint ( CC_ERROR , " This command is forbidden in multiplayer. " ) ;
2010-03-24 20:43:31 +00:00
return CHR_DISALLOW ;
2004-12-04 17:54:56 +00:00
}
2010-03-24 20:43:31 +00:00
return CHR_ALLOW ;
2004-12-04 17:54:56 +00:00
}
2021-06-10 18:11:50 +00:00
/**
* Check if are either in singleplayer or a server .
* @ return True iff we are either in singleplayer or a server .
*/
DEF_CONSOLE_HOOK ( ConHookServerOrNoNetwork )
{
if ( _networking & & ! _network_server ) {
2021-06-12 19:07:04 +00:00
if ( echo ) IConsolePrint ( CC_ERROR , " This command is only available to a network server. " ) ;
2021-06-10 18:11:50 +00:00
return CHR_DISALLOW ;
}
return CHR_ALLOW ;
}
2010-03-24 20:47:03 +00:00
DEF_CONSOLE_HOOK ( ConHookNewGRFDeveloperTool )
{
if ( _settings_client . gui . newgrf_developer_tools ) {
if ( _game_mode = = GM_MENU ) {
2021-06-12 19:07:04 +00:00
if ( echo ) IConsolePrint ( CC_ERROR , " This command is only available in-game and in the editor. " ) ;
2010-03-24 20:47:03 +00:00
return CHR_DISALLOW ;
}
return ConHookNoNetwork ( echo ) ;
}
return CHR_HIDE ;
}
2011-02-14 19:52:26 +00:00
/**
* Reset status of all engines .
* @ return Will always succeed .
*/
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConResetEngines )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-09-12 21:49:38 +00:00
StartupEngines ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2011-02-14 19:52:26 +00:00
/**
* Reset status of the engine pool .
* @ return Will always return true .
* @ note Resetting the pool only succeeds when there are no vehicles ingame .
*/
2011-02-05 16:07:23 +00:00
DEF_CONSOLE_CMD ( ConResetEnginePool )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again. " ) ;
2011-02-05 16:07:23 +00:00
return true ;
}
if ( _game_mode = = GM_MENU ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " This command is only available in-game and in the editor. " ) ;
2011-02-05 16:07:23 +00:00
return true ;
}
if ( ! EngineOverrideManager : : ResetToCurrentNewGRFConfig ( ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " This can only be done when there are no vehicles in the game. " ) ;
2011-02-05 16:07:23 +00:00
return true ;
}
return true ;
}
2004-09-19 15:24:45 +00:00
# ifdef _DEBUG
2011-02-14 19:52:26 +00:00
/**
* Reset a tile to bare land in debug mode .
* param tile number .
* @ return True when the tile is reset or the help on usage was printed ( 0 or two parameters ) .
*/
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConResetTile )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Reset a tile to bare land. Usage: 'resettile <tile>'. " ) ;
IConsolePrint ( CC_HELP , " Tile can be either decimal (34161) or hexadecimal (0x4a5B). " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-09-12 21:49:38 +00:00
if ( argc = = 2 ) {
2005-05-02 15:52:19 +00:00
uint32 result ;
if ( GetArgumentInteger ( & result , argv [ 1 ] ) ) {
DoClearSquare ( ( TileIndex ) result ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
}
2005-05-02 15:52:19 +00:00
return false ;
2004-09-12 21:49:38 +00:00
}
2005-05-02 16:00:49 +00:00
# endif /* _DEBUG */
2004-09-12 21:49:38 +00:00
2011-02-14 19:52:26 +00:00
/**
* Scroll to a tile on the map .
2018-10-28 02:17:36 +00:00
* param x tile number or tile x coordinate .
* param y optional y coordinate .
2019-09-29 20:27:32 +00:00
* @ note When only one argument is given it is interpreted as the tile number .
2011-02-14 19:52:26 +00:00
* When two arguments are given , they are interpreted as the tile ' s x
* and y coordinates .
* @ return True when either console help was shown or a proper amount of parameters given .
*/
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConScrollToTile )
{
2009-05-26 13:16:58 +00:00
switch ( argc ) {
case 0 :
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Center the screen on a given tile. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'scrollto <tile>' or 'scrollto <x> <y>'. " ) ;
IConsolePrint ( CC_HELP , " Numbers can be either decimal (34161) or hexadecimal (0x4a5B). " ) ;
2009-05-26 13:16:58 +00:00
return true ;
2005-05-02 15:52:19 +00:00
2009-05-26 13:16:58 +00:00
case 2 : {
uint32 result ;
if ( GetArgumentInteger ( & result , argv [ 1 ] ) ) {
if ( result > = MapSize ( ) ) {
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_ERROR , " Tile does not exist. " ) ;
2009-05-26 13:16:58 +00:00
return true ;
}
ScrollMainWindowToTile ( ( TileIndex ) result ) ;
2006-09-09 22:15:19 +00:00
return true ;
}
2009-05-26 13:16:58 +00:00
break ;
}
case 3 : {
uint32 x , y ;
if ( GetArgumentInteger ( & x , argv [ 1 ] ) & & GetArgumentInteger ( & y , argv [ 2 ] ) ) {
if ( x > = MapSizeX ( ) | | y > = MapSizeY ( ) ) {
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_ERROR , " Tile does not exist. " ) ;
2009-05-26 13:16:58 +00:00
return true ;
}
ScrollMainWindowToTile ( TileXY ( x , y ) ) ;
return true ;
}
break ;
2005-05-02 15:52:19 +00:00
}
2004-09-12 21:49:38 +00:00
}
2005-05-02 15:52:19 +00:00
return false ;
2004-09-12 21:49:38 +00:00
}
2011-02-14 19:52:26 +00:00
/**
* Save the map to a file .
2018-10-28 02:17:36 +00:00
* param filename the filename to save the map to .
2011-02-14 19:52:26 +00:00
* @ return True when help was displayed or the file attempted to be saved .
*/
2005-03-25 18:26:49 +00:00
DEF_CONSOLE_CMD ( ConSave )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Save the current game. Usage: 'save <filename>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2005-03-25 18:26:49 +00:00
if ( argc = = 2 ) {
2007-06-17 15:48:57 +00:00
char * filename = str_fmt ( " %s.sav " , argv [ 1 ] ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Saving map... " ) ;
2005-05-02 15:52:19 +00:00
2016-09-04 16:06:50 +00:00
if ( SaveOrLoad ( filename , SLO_SAVE , DFT_GAME_FILE , SAVE_DIR ) ! = SL_OK ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_ERROR , " Saving map failed. " ) ;
2006-06-27 21:25:53 +00:00
} else {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_INFO , " Map successfully saved to '{}'. " , filename ) ;
2006-06-27 21:25:53 +00:00
}
2007-06-17 15:48:57 +00:00
free ( filename ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-03-25 18:26:49 +00:00
}
2005-05-02 15:52:19 +00:00
return false ;
2005-03-25 18:26:49 +00:00
}
2011-02-14 19:52:26 +00:00
/**
* Explicitly save the configuration .
* @ return True .
*/
2007-01-03 18:06:50 +00:00
DEF_CONSOLE_CMD ( ConSaveConfig )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Saves the configuration for new games to the configuration file, typically 'openttd.cfg'. " ) ;
IConsolePrint ( CC_HELP , " It does not save the configuration of the current game to the configuration file. " ) ;
2007-01-03 18:06:50 +00:00
return true ;
}
SaveToConfig ( ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Saved config. " ) ;
2007-01-03 18:06:50 +00:00
return true ;
}
2005-01-04 15:06:08 +00:00
DEF_CONSOLE_CMD ( ConLoad )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Load a game by name or index. Usage: 'load <file | number>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2008-06-02 14:19:27 +00:00
const char * file = argv [ 1 ] ;
2016-09-04 12:55:21 +00:00
_console_file_list . ValidateFileList ( ) ;
const FiosItem * item = _console_file_list . FindItem ( file ) ;
2019-04-10 21:07:06 +00:00
if ( item ! = nullptr ) {
2016-09-04 12:57:20 +00:00
if ( GetAbstractFileType ( item - > type ) = = FT_SAVEGAME ) {
_switch_mode = SM_LOAD_GAME ;
_file_to_saveload . SetMode ( item - > type ) ;
2016-09-04 12:58:04 +00:00
_file_to_saveload . SetName ( FiosBrowseTo ( item ) ) ;
_file_to_saveload . SetTitle ( item - > title ) ;
2016-09-04 12:57:20 +00:00
} else {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " '{}' is not a savegame. " , file ) ;
2005-03-27 12:48:25 +00:00
}
2006-06-27 21:25:53 +00:00
} else {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " '{}' cannot be found. " , file ) ;
2006-06-27 21:25:53 +00:00
}
2005-01-04 15:06:08 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-09-11 14:57:56 +00:00
DEF_CONSOLE_CMD ( ConRemove )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Remove a savegame by name or index. Usage: 'rm <file | number>'. " ) ;
2005-09-11 14:57:56 +00:00
return true ;
}
if ( argc ! = 2 ) return false ;
2008-06-02 14:19:27 +00:00
const char * file = argv [ 1 ] ;
2016-09-04 12:55:21 +00:00
_console_file_list . ValidateFileList ( ) ;
const FiosItem * item = _console_file_list . FindItem ( file ) ;
2019-04-10 21:07:06 +00:00
if ( item ! = nullptr ) {
2010-07-24 10:14:39 +00:00
if ( ! FiosDelete ( item - > name ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Failed to delete '{}'. " , file ) ;
2010-07-24 10:14:39 +00:00
}
2006-06-27 21:25:53 +00:00
} else {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " '{}' could not be found. " , file ) ;
2006-06-27 21:25:53 +00:00
}
2005-09-11 14:57:56 +00:00
2016-09-04 12:55:21 +00:00
_console_file_list . InvalidateFileList ( ) ;
2005-09-11 14:57:56 +00:00
return true ;
}
2005-03-27 12:48:25 +00:00
/* List all the files in the current dir via console */
DEF_CONSOLE_CMD ( ConListFiles )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2016-09-04 12:55:21 +00:00
_console_file_list . ValidateFileList ( true ) ;
2021-04-29 21:46:42 +00:00
for ( uint i = 0 ; i < _console_file_list . size ( ) ; i + + ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " {}) {} " , i , _console_file_list [ i ] . title ) ;
2005-01-08 00:48:10 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2005-01-08 00:48:10 +00:00
}
2005-01-04 15:06:08 +00:00
/* Change the dir via console */
2005-03-27 12:48:25 +00:00
DEF_CONSOLE_CMD ( ConChangeDirectory )
2005-01-04 15:06:08 +00:00
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Change the dir via console. Usage: 'cd <directory | number>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2008-06-02 14:19:27 +00:00
const char * file = argv [ 1 ] ;
2016-09-04 12:55:21 +00:00
_console_file_list . ValidateFileList ( true ) ;
const FiosItem * item = _console_file_list . FindItem ( file ) ;
2019-04-10 21:07:06 +00:00
if ( item ! = nullptr ) {
2005-03-27 12:48:25 +00:00
switch ( item - > type ) {
2005-05-02 15:52:19 +00:00
case FIOS_TYPE_DIR : case FIOS_TYPE_DRIVE : case FIOS_TYPE_PARENT :
2005-03-27 12:48:25 +00:00
FiosBrowseTo ( item ) ;
break ;
2021-06-12 19:07:04 +00:00
default : IConsolePrint ( CC_ERROR , " {}: Not a directory. " , file ) ;
2005-01-04 15:06:08 +00:00
}
2006-06-27 21:25:53 +00:00
} else {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " {}: No such file or directory. " , file ) ;
2006-06-27 21:25:53 +00:00
}
2005-01-04 15:06:08 +00:00
2016-09-04 12:55:21 +00:00
_console_file_list . InvalidateFileList ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-03-27 12:48:25 +00:00
}
DEF_CONSOLE_CMD ( ConPrintWorkingDirectory )
{
2005-05-02 15:52:19 +00:00
const char * path ;
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Print out the current working directory. Usage: 'pwd'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2005-03-27 12:48:25 +00:00
2009-03-15 00:32:18 +00:00
/* XXX - Workaround for broken file handling */
2016-09-04 12:55:21 +00:00
_console_file_list . ValidateFileList ( true ) ;
_console_file_list . InvalidateFileList ( ) ;
2005-01-04 15:06:08 +00:00
2019-04-10 21:07:06 +00:00
FiosGetDescText ( & path , nullptr ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , path ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-05-16 13:46:26 +00:00
DEF_CONSOLE_CMD ( ConClearBuffer )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Clear the console buffer. Usage: 'clear'. " ) ;
2005-05-16 13:46:26 +00:00
return true ;
}
IConsoleClearBuffer ( ) ;
2009-09-13 19:15:59 +00:00
SetWindowDirty ( WC_CONSOLE , 0 ) ;
2005-05-16 13:46:26 +00:00
return true ;
}
2004-12-04 17:54:56 +00:00
2009-03-15 00:32:18 +00:00
/**********************************
* Network Core Console Commands
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-09-12 21:49:38 +00:00
2021-05-29 17:47:58 +00:00
static bool ConKickOrBan ( const char * argv , bool ban , const std : : string & reason )
2005-01-02 12:03:43 +00:00
{
2011-04-22 15:59:32 +00:00
uint n ;
2005-01-02 12:03:43 +00:00
2019-04-10 21:07:06 +00:00
if ( strchr ( argv , ' . ' ) = = nullptr & & strchr ( argv , ' : ' ) = = nullptr ) { // banning with ID
2010-05-13 16:00:50 +00:00
ClientID client_id = ( ClientID ) atoi ( argv ) ;
2005-01-02 12:03:43 +00:00
2011-05-03 15:05:15 +00:00
/* Don't kill the server, or the client doing the rcon. The latter can't be kicked because
* kicking frees closes and subsequently free the connection related instances , which we
* would be reading from and writing to after returning . So we would read or write data
* from freed memory up till the segfault triggers . */
if ( client_id = = CLIENT_ID_SERVER | | client_id = = _redirect_console_to_client ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " You can not {} yourself! " , ban ? " ban " : " kick " ) ;
2010-05-13 16:00:50 +00:00
return true ;
}
2005-01-02 12:03:43 +00:00
2011-04-22 15:54:16 +00:00
NetworkClientInfo * ci = NetworkClientInfo : : GetByClientID ( client_id ) ;
2019-04-10 21:07:06 +00:00
if ( ci = = nullptr ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Invalid client ID. " ) ;
2010-05-13 16:00:50 +00:00
return true ;
2006-01-29 18:04:52 +00:00
}
2010-05-13 16:00:50 +00:00
if ( ! ban ) {
/* Kick only this client, not all clients with that IP */
2020-01-21 15:39:10 +00:00
NetworkServerKickClient ( client_id , reason ) ;
2010-05-13 16:00:50 +00:00
return true ;
}
/* When banning, kick+ban all clients with that IP */
2020-01-21 15:39:10 +00:00
n = NetworkServerKickOrBanIP ( client_id , ban , reason ) ;
2011-04-22 15:59:32 +00:00
} else {
2020-01-21 15:39:10 +00:00
n = NetworkServerKickOrBanIP ( argv , ban , reason ) ;
2006-01-19 15:58:57 +00:00
}
2005-01-02 12:03:43 +00:00
2010-05-13 16:00:50 +00:00
if ( n = = 0 ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_DEFAULT , ban ? " Client not online, address added to banlist. " : " Client not found. " ) ;
2010-05-13 16:00:50 +00:00
} else {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " {}ed {} client(s). " , ban ? " Bann " : " Kick " , n ) ;
2005-05-02 15:52:19 +00:00
}
2006-01-19 15:58:57 +00:00
2010-05-13 16:00:50 +00:00
return true ;
}
DEF_CONSOLE_CMD ( ConKick )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'. " ) ;
IConsolePrint ( CC_HELP , " For client-id's, see the command 'clients'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
2020-01-21 15:39:10 +00:00
if ( argc ! = 2 & & argc ! = 3 ) return false ;
/* No reason supplied for kicking */
2021-05-29 17:47:58 +00:00
if ( argc = = 2 ) return ConKickOrBan ( argv [ 1 ] , false , { } ) ;
2010-05-13 16:00:50 +00:00
2020-01-21 15:39:10 +00:00
/* Reason for kicking supplied */
2020-02-06 15:44:54 +00:00
size_t kick_message_length = strlen ( argv [ 2 ] ) ;
2020-01-21 15:39:10 +00:00
if ( kick_message_length > = 255 ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Maximum kick message length is 254 characters. You entered {} characters. " , kick_message_length ) ;
2020-01-21 15:39:10 +00:00
return false ;
} else {
return ConKickOrBan ( argv [ 1 ] , false , argv [ 2 ] ) ;
}
2010-05-13 16:00:50 +00:00
}
DEF_CONSOLE_CMD ( ConBan )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'. " ) ;
IConsolePrint ( CC_HELP , " For client-id's, see the command 'clients'. " ) ;
IConsolePrint ( CC_HELP , " If the client is no longer online, you can still ban their IP. " ) ;
2010-05-13 16:00:50 +00:00
return true ;
2006-06-27 21:25:53 +00:00
}
2006-01-29 18:04:52 +00:00
2020-01-21 15:39:10 +00:00
if ( argc ! = 2 & & argc ! = 3 ) return false ;
/* No reason supplied for kicking */
2021-05-29 17:47:58 +00:00
if ( argc = = 2 ) return ConKickOrBan ( argv [ 1 ] , true , { } ) ;
2005-01-02 12:03:43 +00:00
2020-01-21 15:39:10 +00:00
/* Reason for kicking supplied */
2020-02-06 15:44:54 +00:00
size_t kick_message_length = strlen ( argv [ 2 ] ) ;
2020-01-21 15:39:10 +00:00
if ( kick_message_length > = 255 ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Maximum kick message length is 254 characters. You entered {} characters. " , kick_message_length ) ;
2020-01-21 15:39:10 +00:00
return false ;
} else {
return ConKickOrBan ( argv [ 1 ] , true , argv [ 2 ] ) ;
}
2005-05-02 15:52:19 +00:00
}
DEF_CONSOLE_CMD ( ConUnBan )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Unban a client from a network game. Usage: 'unban <ip | banlist-index>'. " ) ;
IConsolePrint ( CC_HELP , " For a list of banned IP's, see the command 'banlist'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2017-09-10 14:02:13 +00:00
/* Try by IP. */
uint index ;
2018-09-23 11:23:54 +00:00
for ( index = 0 ; index < _network_ban_list . size ( ) ; index + + ) {
2019-04-02 19:31:33 +00:00
if ( _network_ban_list [ index ] = = argv [ 1 ] ) break ;
2017-09-10 14:02:13 +00:00
}
/* Try by index. */
2018-09-23 11:23:54 +00:00
if ( index > = _network_ban_list . size ( ) ) {
2017-09-10 14:02:13 +00:00
index = atoi ( argv [ 1 ] ) - 1U ; // let it wrap
}
2018-09-23 11:23:54 +00:00
if ( index < _network_ban_list . size ( ) ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Unbanned {}. " , _network_ban_list [ index ] ) ;
2018-09-25 20:01:56 +00:00
_network_ban_list . erase ( _network_ban_list . begin ( ) + index ) ;
2017-09-10 14:02:13 +00:00
} else {
2017-09-10 14:03:29 +00:00
IConsolePrint ( CC_DEFAULT , " Invalid list index or IP not in ban-list. " ) ;
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_DEFAULT , " For a list of banned IP's, see the command 'banlist'. " ) ;
2005-05-02 15:52:19 +00:00
}
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
DEF_CONSOLE_CMD ( ConBanList )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List the IP's of banned clients: Usage 'banlist'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_DEFAULT , " Banlist: " ) ;
2005-01-02 12:03:43 +00:00
2009-04-03 12:49:58 +00:00
uint i = 1 ;
2019-04-02 19:31:33 +00:00
for ( const auto & entry : _network_ban_list ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " {}) {} " , i , entry ) ;
2020-06-08 20:22:49 +00:00
i + + ;
2005-01-02 12:03:43 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
2005-01-24 21:33:44 +00:00
DEF_CONSOLE_CMD ( ConPauseGame )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Pause a network game. Usage: 'pause'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2021-06-10 18:11:50 +00:00
if ( _game_mode = = GM_MENU ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " This command is only available in-game and in the editor. " ) ;
2021-06-10 18:11:50 +00:00
return true ;
}
2009-11-12 20:38:52 +00:00
if ( ( _pause_mode & PM_PAUSED_NORMAL ) = = PM_UNPAUSED ) {
2009-05-06 15:06:57 +00:00
DoCommandP ( 0 , PM_PAUSED_NORMAL , 1 , CMD_PAUSE ) ;
2009-11-12 20:38:52 +00:00
if ( ! _networking ) IConsolePrint ( CC_DEFAULT , " Game paused. " ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Game is already paused. " ) ;
2006-06-27 21:25:53 +00:00
}
2005-01-24 21:33:44 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2005-01-24 21:33:44 +00:00
}
2011-11-15 19:40:42 +00:00
DEF_CONSOLE_CMD ( ConUnpauseGame )
2005-01-24 21:33:44 +00:00
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Unpause a network game. Usage: 'unpause'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2021-06-10 18:11:50 +00:00
if ( _game_mode = = GM_MENU ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " This command is only available in-game and in the editor. " ) ;
2021-06-10 18:11:50 +00:00
return true ;
}
2009-11-12 20:38:52 +00:00
if ( ( _pause_mode & PM_PAUSED_NORMAL ) ! = PM_UNPAUSED ) {
2009-05-06 15:06:57 +00:00
DoCommandP ( 0 , PM_PAUSED_NORMAL , 0 , CMD_PAUSE ) ;
2009-11-12 20:38:52 +00:00
if ( ! _networking ) IConsolePrint ( CC_DEFAULT , " Game unpaused. " ) ;
} else if ( ( _pause_mode & PM_PAUSED_ERROR ) ! = PM_UNPAUSED ) {
IConsolePrint ( CC_DEFAULT , " Game is in error state and cannot be unpaused via console. " ) ;
} else if ( _pause_mode ! = PM_UNPAUSED ) {
IConsolePrint ( CC_DEFAULT , " Game cannot be unpaused manually; disable pause_on_join/min_active_clients. " ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Game is already unpaused. " ) ;
2006-06-27 21:25:53 +00:00
}
2005-01-24 21:33:44 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2005-01-24 21:33:44 +00:00
}
2005-01-15 20:09:16 +00:00
DEF_CONSOLE_CMD ( ConRcon )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Remote control the server from another client. Usage: 'rcon <password> <command>'. " ) ;
IConsolePrint ( CC_HELP , " Remember to enclose the command in quotes, otherwise only the first parameter is sent. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-15 20:09:16 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc < 3 ) return false ;
2005-01-15 20:09:16 +00:00
2008-05-17 11:46:35 +00:00
if ( _network_server ) {
IConsoleCmdExec ( argv [ 2 ] ) ;
} else {
2008-05-30 18:20:26 +00:00
NetworkClientSendRcon ( argv [ 1 ] , argv [ 2 ] ) ;
2008-05-17 11:46:35 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2005-01-15 20:09:16 +00:00
}
2004-12-04 17:54:56 +00:00
DEF_CONSOLE_CMD ( ConStatus )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List the status of all clients connected to the server. Usage 'status'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2008-05-30 18:20:26 +00:00
NetworkServerShowStatusToConsole ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2006-01-25 18:11:06 +00:00
DEF_CONSOLE_CMD ( ConServerInfo )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List current and maximum client/company limits. Usage 'server_info'. " ) ;
2021-08-10 18:03:13 +00:00
IConsolePrint ( CC_HELP , " You can change these values by modifying settings 'network.max_clients' and 'network.max_companies'. " ) ;
2006-01-25 18:11:06 +00:00
return true ;
}
2021-04-29 13:37:02 +00:00
IConsolePrint ( CC_DEFAULT , " Invite code: {} " , _network_server_invite_code ) ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Current/maximum clients: {:3d}/{:3d} " , _network_game_info . clients_on , _settings_client . network . max_clients ) ;
IConsolePrint ( CC_DEFAULT , " Current/maximum companies: {:3d}/{:3d} " , Company : : GetNumItems ( ) , _settings_client . network . max_companies ) ;
2021-08-10 18:03:13 +00:00
IConsolePrint ( CC_DEFAULT , " Current spectators: {:3d} " , NetworkSpectatorCount ( ) ) ;
2006-01-25 18:11:06 +00:00
return true ;
}
2009-01-21 23:07:11 +00:00
DEF_CONSOLE_CMD ( ConClientNickChange )
{
if ( argc ! = 3 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'. " ) ;
IConsolePrint ( CC_HELP , " For client-id's, see the command 'clients'. " ) ;
2009-01-21 23:07:11 +00:00
return true ;
}
ClientID client_id = ( ClientID ) atoi ( argv [ 1 ] ) ;
if ( client_id = = CLIENT_ID_SERVER ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Please use the command 'name' to change your own name! " ) ;
2009-01-21 23:07:11 +00:00
return true ;
}
2019-04-10 21:07:06 +00:00
if ( NetworkClientInfo : : GetByClientID ( client_id ) = = nullptr ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Invalid client ID. " ) ;
2009-01-21 23:07:11 +00:00
return true ;
}
2021-04-27 20:02:40 +00:00
std : : string client_name ( argv [ 2 ] ) ;
2021-04-22 06:09:36 +00:00
StrTrimInPlace ( client_name ) ;
if ( ! NetworkIsValidClientName ( client_name ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Cannot give a client an empty name. " ) ;
2021-04-22 06:09:36 +00:00
return true ;
}
2021-05-29 17:29:14 +00:00
if ( ! NetworkServerChangeClientName ( client_id , client_name ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Cannot give a client a duplicate name. " ) ;
2009-01-21 23:07:11 +00:00
}
return true ;
}
2009-01-23 22:18:06 +00:00
DEF_CONSOLE_CMD ( ConJoinCompany )
{
if ( argc < 2 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Request joining another company. Usage: 'join <company-id> [<password>]'. " ) ;
IConsolePrint ( CC_HELP , " For valid company-id see company list, use 255 for spectator. " ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
CompanyID company_id = ( CompanyID ) ( atoi ( argv [ 1 ] ) < = MAX_COMPANIES ? atoi ( argv [ 1 ] ) - 1 : atoi ( argv [ 1 ] ) ) ;
/* Check we have a valid company id! */
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company_id ) & & company_id ! = COMPANY_SPECTATOR ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Company does not exist. Company-id must be between 1 and {}. " , MAX_COMPANIES ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
2011-04-22 15:54:16 +00:00
if ( NetworkClientInfo : : GetByClientID ( _network_own_client_id ) - > client_playas = = company_id ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " You are already there! " ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
2009-06-23 12:11:35 +00:00
if ( company_id ! = COMPANY_SPECTATOR & & ! Company : : IsHumanID ( company_id ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Cannot join AI company. " ) ;
2009-04-26 20:01:14 +00:00
return true ;
}
2009-01-23 22:18:06 +00:00
/* Check if the company requires a password */
if ( NetworkCompanyIsPassworded ( company_id ) & & argc < 3 ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Company {} requires a password to join. " , company_id + 1 ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
/* non-dedicated server may just do the move! */
if ( _network_server ) {
NetworkServerDoMove ( CLIENT_ID_SERVER , company_id ) ;
} else {
NetworkClientRequestMove ( company_id , NetworkCompanyIsPassworded ( company_id ) ? argv [ 2 ] : " " ) ;
}
return true ;
}
DEF_CONSOLE_CMD ( ConMoveClient )
{
if ( argc < 3 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Move a client to another company. Usage: 'move <client-id> <company-id>'. " ) ;
IConsolePrint ( CC_HELP , " For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators. " ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
2011-04-22 15:54:16 +00:00
const NetworkClientInfo * ci = NetworkClientInfo : : GetByClientID ( ( ClientID ) atoi ( argv [ 1 ] ) ) ;
2009-01-23 22:18:06 +00:00
CompanyID company_id = ( CompanyID ) ( atoi ( argv [ 2 ] ) < = MAX_COMPANIES ? atoi ( argv [ 2 ] ) - 1 : atoi ( argv [ 2 ] ) ) ;
/* check the client exists */
2019-04-10 21:07:06 +00:00
if ( ci = = nullptr ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Invalid client-id, check the command 'clients' for valid client-id's. " ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company_id ) & & company_id ! = COMPANY_SPECTATOR ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Company does not exist. Company-id must be between 1 and {}. " , MAX_COMPANIES ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
2009-06-23 12:11:35 +00:00
if ( company_id ! = COMPANY_SPECTATOR & & ! Company : : IsHumanID ( company_id ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " You cannot move clients to AI companies. " ) ;
2009-04-26 20:01:14 +00:00
return true ;
}
2009-01-23 22:18:06 +00:00
if ( ci - > client_id = = CLIENT_ID_SERVER & & _network_dedicated ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " You cannot move the server! " ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
if ( ci - > client_playas = = company_id ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " You cannot move someone to where they already are! " ) ;
2009-01-23 22:18:06 +00:00
return true ;
}
/* we are the server, so force the update */
NetworkServerDoMove ( ci - > client_id , company_id ) ;
return true ;
}
2004-12-16 11:36:57 +00:00
DEF_CONSOLE_CMD ( ConResetCompany )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Remove an idle company from the game. Usage: 'reset_company <company-id>'. " ) ;
IConsolePrint ( CC_HELP , " For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2004-12-16 11:36:57 +00:00
2009-05-18 16:21:28 +00:00
CompanyID index = ( CompanyID ) ( atoi ( argv [ 1 ] ) - 1 ) ;
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
/* Check valid range */
2009-06-23 12:11:35 +00:00
if ( ! Company : : IsValidID ( index ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Company does not exist. Company-id must be between 1 and {}. " , MAX_COMPANIES ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-16 11:36:57 +00:00
2009-06-23 12:11:35 +00:00
if ( ! Company : : IsHumanID ( index ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Company is owned by an AI. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2008-09-30 20:39:50 +00:00
if ( NetworkCompanyHasClients ( index ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Cannot remove company: a client is connected to that company. " ) ;
2008-05-30 18:20:26 +00:00
return false ;
2005-05-02 15:52:19 +00:00
}
2011-04-22 15:54:16 +00:00
const NetworkClientInfo * ci = NetworkClientInfo : : GetByClientID ( CLIENT_ID_SERVER ) ;
2006-10-17 22:16:46 +00:00
if ( ci - > client_playas = = index ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Cannot remove company: the server is connected to that company. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-16 11:36:57 +00:00
}
2005-05-02 15:52:19 +00:00
/* It is safe to remove this company */
2019-04-05 13:11:52 +00:00
DoCommandP ( 0 , CCA_DELETE | index < < 16 | CRR_MANUAL < < 24 , 0 , CMD_COMPANY_CTRL ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Company deleted. " ) ;
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-12-16 11:36:57 +00:00
}
2004-12-04 17:54:56 +00:00
DEF_CONSOLE_CMD ( ConNetworkClients )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2008-12-22 21:26:26 +00:00
NetworkPrintClients ( ) ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2009-09-07 21:03:41 +00:00
DEF_CONSOLE_CMD ( ConNetworkReconnect )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'. " ) ;
IConsolePrint ( CC_HELP , " Company 255 is spectator (default, if not specified), 0 means creating new company. " ) ;
IConsolePrint ( CC_HELP , " All others are a certain company with Company 1 being #1. " ) ;
2009-09-07 21:03:41 +00:00
return true ;
}
CompanyID playas = ( argc > = 2 ) ? ( CompanyID ) atoi ( argv [ 1 ] ) : COMPANY_SPECTATOR ;
switch ( playas ) {
case 0 : playas = COMPANY_NEW_COMPANY ; break ;
case COMPANY_SPECTATOR : /* nothing to do */ break ;
default :
/* From a user pov 0 is a new company, internally it's different and all
* companies are offset by one to ease up on users ( eg companies 1 - 8 not 0 - 7 ) */
2019-04-22 08:10:04 +00:00
if ( playas < COMPANY_FIRST + 1 | | playas > MAX_COMPANIES + 1 ) return false ;
2009-09-07 21:03:41 +00:00
break ;
}
2021-04-27 19:10:11 +00:00
if ( _settings_client . network . last_joined . empty ( ) ) {
2009-09-07 21:03:41 +00:00
IConsolePrint ( CC_DEFAULT , " No server for reconnecting. " ) ;
return true ;
}
/* Don't resolve the address first, just print it directly as it comes from the config file. */
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Reconnecting to {} ... " , _settings_client . network . last_joined ) ;
2009-09-07 21:03:41 +00:00
2021-05-01 11:54:30 +00:00
return NetworkClientConnectGame ( _settings_client . network . last_joined , playas ) ;
2010-03-23 22:37:18 +00:00
}
2009-09-07 21:03:41 +00:00
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConNetworkConnect )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'. " ) ;
IConsolePrint ( CC_HELP , " IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'. " ) ;
IConsolePrint ( CC_HELP , " Company #255 is spectator all others are a certain company with Company 1 being #1. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
if ( argc < 2 ) return false ;
2004-12-04 17:54:56 +00:00
2021-05-01 11:54:30 +00:00
return NetworkClientConnectGame ( argv [ 1 ] , COMPANY_NEW_COMPANY ) ;
2004-09-12 21:49:38 +00:00
}
2009-03-15 00:32:18 +00:00
/*********************************
* script file console commands
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-09-14 16:10:20 +00:00
DEF_CONSOLE_CMD ( ConExec )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Execute a local script file. Usage: 'exec <script> <?>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc < 2 ) return false ;
2004-09-14 16:10:20 +00:00
2010-06-26 15:04:57 +00:00
FILE * script_file = FioFOpenFile ( argv [ 1 ] , " r " , BASE_DIR ) ;
2004-09-14 16:10:20 +00:00
2019-04-10 21:07:06 +00:00
if ( script_file = = nullptr ) {
2021-06-12 19:07:04 +00:00
if ( argc = = 2 | | atoi ( argv [ 2 ] ) ! = 0 ) IConsolePrint ( CC_ERROR , " Script file '{}' not found. " , argv [ 1 ] ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-02-18 08:49:04 +00:00
}
2004-09-14 16:10:20 +00:00
2021-03-12 08:26:03 +00:00
if ( _script_current_depth = = 11 ) {
2021-05-09 21:00:36 +00:00
FioFCloseFile ( script_file ) ;
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times. " ) ;
2021-03-12 08:26:03 +00:00
return true ;
}
2021-03-12 08:23:03 +00:00
_script_current_depth + + ;
uint script_depth = _script_current_depth ;
2004-09-14 16:10:20 +00:00
2010-06-26 15:12:51 +00:00
char cmdline [ ICON_CMDLN_SIZE ] ;
2021-03-12 08:23:03 +00:00
while ( fgets ( cmdline , sizeof ( cmdline ) , script_file ) ! = nullptr ) {
2005-05-02 17:05:59 +00:00
/* Remove newline characters from the executing script */
2010-06-26 15:12:51 +00:00
for ( char * cmdptr = cmdline ; * cmdptr ! = ' \0 ' ; cmdptr + + ) {
2005-05-02 17:05:59 +00:00
if ( * cmdptr = = ' \n ' | | * cmdptr = = ' \r ' ) {
* cmdptr = ' \0 ' ;
break ;
}
}
2005-05-02 15:52:19 +00:00
IConsoleCmdExec ( cmdline ) ;
2021-03-12 08:23:03 +00:00
/* Ensure that we are still on the same depth or that we returned via 'return'. */
assert ( _script_current_depth = = script_depth | | _script_current_depth = = script_depth - 1 ) ;
/* The 'return' command was executed. */
if ( _script_current_depth = = script_depth - 1 ) break ;
2005-05-02 17:05:59 +00:00
}
2005-02-18 08:36:11 +00:00
2010-07-24 10:14:39 +00:00
if ( ferror ( script_file ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " Encountered error while trying to read from script file '{}'. " , argv [ 1 ] ) ;
2010-07-24 10:14:39 +00:00
}
2004-09-14 16:10:20 +00:00
2021-03-12 08:23:03 +00:00
if ( _script_current_depth = = script_depth ) _script_current_depth - - ;
2010-06-26 15:04:57 +00:00
FioFCloseFile ( script_file ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-14 16:10:20 +00:00
}
DEF_CONSOLE_CMD ( ConReturn )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Stop executing a running script. Usage: 'return'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2021-03-12 08:23:03 +00:00
_script_current_depth - - ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-14 16:10:20 +00:00
}
2009-03-15 00:32:18 +00:00
/*****************************
* default console commands
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-03-07 11:47:46 +00:00
extern bool CloseConsoleLogIfActive ( ) ;
2005-01-15 16:38:10 +00:00
DEF_CONSOLE_CMD ( ConScript )
{
2009-01-10 00:31:47 +00:00
extern FILE * _iconsole_output_file ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Start or stop logging console output to a file. Usage: 'script <filename>'. " ) ;
IConsolePrint ( CC_HELP , " If filename is omitted, a running log is stopped if it is active. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2005-01-15 16:38:10 +00:00
if ( ! CloseConsoleLogIfActive ( ) ) {
2005-05-02 15:52:19 +00:00
if ( argc < 2 ) return false ;
2004-09-19 15:24:45 +00:00
_iconsole_output_file = fopen ( argv [ 1 ] , " ab " ) ;
2021-06-12 19:33:01 +00:00
if ( _iconsole_output_file = = nullptr ) {
IConsolePrint ( CC_ERROR , " Could not open console log file '{}'. " , argv [ 1 ] ) ;
} else {
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_INFO , " Console log output started to '{}'. " , argv [ 1 ] ) ;
2021-06-12 19:33:01 +00:00
}
2004-09-14 16:10:20 +00:00
}
2005-01-15 16:38:10 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-14 16:10:20 +00:00
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConEcho )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Print back the first argument to the console. Usage: 'echo <arg>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc < 2 ) return false ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , argv [ 1 ] ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConEchoC )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc < 3 ) return false ;
2011-01-03 12:04:53 +00:00
IConsolePrint ( ( TextColour ) Clamp ( atoi ( argv [ 1 ] ) , TC_BEGIN , TC_END - 1 ) , argv [ 2 ] ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
(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
DEF_CONSOLE_CMD ( ConNewGame )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Start a new game. Usage: 'newgame [seed]'. " ) ;
IConsolePrint ( CC_HELP , " The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game. " ) ;
(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
return true ;
}
2019-04-10 21:07:06 +00:00
StartNewGameWithoutGUI ( ( argc = = 2 ) ? strtoul ( argv [ 1 ] , nullptr , 10 ) : GENERATE_NEW_SEED ) ;
(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
return true ;
}
DEF_CONSOLE_CMD ( ConRestart )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Restart game. Usage: 'restart'. " ) ;
IConsolePrint ( CC_HELP , " Restarts a game. It tries to reproduce the exact same map as the game started with. " ) ;
IConsolePrint ( CC_HELP , " However: " ) ;
IConsolePrint ( CC_HELP , " * restarting games started in another version might create another map due to difference in map generation. " ) ;
IConsolePrint ( CC_HELP , " * restarting games based on scenarios, loaded games or heightmaps will start a new game based on the settings stored in the scenario/savegame. " ) ;
(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
return true ;
}
2009-02-25 00:45:52 +00:00
/* Don't copy the _newgame pointers to the real pointers, so call SwitchToMode directly */
2008-05-29 15:13:28 +00:00
_settings_game . game_creation . map_x = MapLogX ( ) ;
_settings_game . game_creation . map_y = FindFirstBit ( MapSizeY ( ) ) ;
2010-04-25 16:12:03 +00:00
_switch_mode = SM_RESTARTGAME ;
(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
return true ;
}
2021-01-08 15:23:07 +00:00
DEF_CONSOLE_CMD ( ConReload )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Reload game. Usage: 'reload'. " ) ;
IConsolePrint ( CC_HELP , " Reloads a game. " ) ;
IConsolePrint ( CC_HELP , " * if you started from a savegame / scenario / heightmap, that exact same savegame / scenario / heightmap will be loaded. " ) ;
IConsolePrint ( CC_HELP , " * if you started from a new game, this acts the same as 'restart'. " ) ;
2021-01-08 15:23:07 +00:00
return true ;
}
/* Don't copy the _newgame pointers to the real pointers, so call SwitchToMode directly */
_settings_game . game_creation . map_x = MapLogX ( ) ;
_settings_game . game_creation . map_y = FindFirstBit ( MapSizeY ( ) ) ;
_switch_mode = SM_RELOADGAME ;
return true ;
}
2011-01-03 14:52:30 +00:00
/**
2013-01-08 22:46:42 +00:00
* Print a text buffer line by line to the console . Lines are separated by ' \n ' .
2011-01-03 14:52:30 +00:00
* @ param buf The buffer to print .
* @ note All newlines are replace by ' \0 ' characters .
*/
static void PrintLineByLine ( char * buf )
2009-01-12 17:11:45 +00:00
{
2011-01-03 14:52:30 +00:00
char * p = buf ;
2009-01-12 17:11:45 +00:00
/* Print output line by line */
2011-01-03 14:52:30 +00:00
for ( char * p2 = buf ; * p2 ! = ' \0 ' ; p2 + + ) {
2009-01-12 17:11:45 +00:00
if ( * p2 = = ' \n ' ) {
* p2 = ' \0 ' ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , p ) ;
2009-01-12 17:11:45 +00:00
p = p2 + 1 ;
}
}
2011-01-03 14:52:30 +00:00
}
DEF_CONSOLE_CMD ( ConListAILibs )
{
char buf [ 4096 ] ;
AI : : GetConsoleLibraryList ( buf , lastof ( buf ) ) ;
PrintLineByLine ( buf ) ;
return true ;
}
DEF_CONSOLE_CMD ( ConListAI )
{
char buf [ 4096 ] ;
AI : : GetConsoleList ( buf , lastof ( buf ) ) ;
PrintLineByLine ( buf ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
2011-12-19 20:56:59 +00:00
DEF_CONSOLE_CMD ( ConListGameLibs )
{
char buf [ 4096 ] ;
Game : : GetConsoleLibraryList ( buf , lastof ( buf ) ) ;
PrintLineByLine ( buf ) ;
return true ;
}
2011-12-19 20:55:56 +00:00
DEF_CONSOLE_CMD ( ConListGame )
{
char buf [ 4096 ] ;
Game : : GetConsoleList ( buf , lastof ( buf ) ) ;
PrintLineByLine ( buf ) ;
return true ;
}
2009-01-12 17:11:45 +00:00
DEF_CONSOLE_CMD ( ConStartAI )
{
if ( argc = = 0 | | argc > 3 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Start a new AI. Usage: 'start_ai [<AI>] [<settings>]'. " ) ;
IConsolePrint ( CC_HELP , " Start a new AI. If <AI> is given, it starts that specific AI (if found). " ) ;
IConsolePrint ( CC_HELP , " If <settings> is given, it is parsed and the AI settings are set to that. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
2009-01-13 11:06:21 +00:00
if ( _game_mode ! = GM_NORMAL ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " AIs can only be managed in a game. " ) ;
2009-01-13 11:06:21 +00:00
return true ;
}
2009-05-22 15:23:47 +00:00
if ( Company : : GetNumItems ( ) = = CompanyPool : : MAX_SIZE ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Can't start a new AI (no more free slots). " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
if ( _networking & & ! _network_server ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Only the server can start a new AI. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
if ( _networking & & ! _settings_game . ai . ai_in_multiplayer ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " AIs are not allowed in multiplayer by configuration. " ) ;
IConsolePrint ( CC_ERROR , " Switch AI -> AI in multiplayer to True. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
if ( ! AI : : CanStartNew ( ) ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Can't start a new AI. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
int n = 0 ;
/* Find the next free slot */
2019-12-14 16:22:38 +00:00
for ( const Company * c : Company : : Iterate ( ) ) {
2009-01-12 17:11:45 +00:00
if ( c - > index ! = n ) break ;
n + + ;
}
AIConfig * config = AIConfig : : GetConfig ( ( CompanyID ) n ) ;
if ( argc > = 2 ) {
2020-12-25 14:22:40 +00:00
config - > Change ( argv [ 1 ] , - 1 , false ) ;
/* If the name is not found, and there is a dot in the name,
* try again with the assumption everything right of the dot is
* the version the user wants to load . */
if ( ! config - > HasScript ( ) ) {
char * name = stredup ( argv [ 1 ] ) ;
char * e = strrchr ( name , ' . ' ) ;
if ( e ! = nullptr ) {
* e = ' \0 ' ;
e + + ;
int version = atoi ( e ) ;
config - > Change ( name , version , true ) ;
}
free ( name ) ;
}
2011-11-29 23:26:35 +00:00
if ( ! config - > HasScript ( ) ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Failed to load the specified AI. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
if ( argc = = 3 ) {
config - > StringToSettings ( argv [ 2 ] ) ;
}
}
/* Start a new AI company */
2019-02-04 17:06:19 +00:00
DoCommandP ( 0 , CCA_NEW_AI | INVALID_COMPANY < < 16 , 0 , CMD_COMPANY_CTRL ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
2009-01-14 15:39:05 +00:00
DEF_CONSOLE_CMD ( ConReloadAI )
{
if ( argc ! = 2 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Reload an AI. Usage: 'reload_ai <company-id>'. " ) ;
IConsolePrint ( CC_HELP , " Reload the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc. " ) ;
2009-01-14 15:39:05 +00:00
return true ;
}
if ( _game_mode ! = GM_NORMAL ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " AIs can only be managed in a game. " ) ;
2009-01-14 15:39:05 +00:00
return true ;
}
if ( _networking & & ! _network_server ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Only the server can reload an AI. " ) ;
2009-01-14 15:39:05 +00:00
return true ;
}
CompanyID company_id = ( CompanyID ) ( atoi ( argv [ 1 ] ) - 1 ) ;
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company_id ) ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_ERROR , " Unknown company. Company range is between 1 and {}. " , MAX_COMPANIES ) ;
2009-01-14 15:39:05 +00:00
return true ;
}
2021-01-22 15:24:29 +00:00
/* In singleplayer mode the player can be in an AI company, after cheating or loading network save with an AI in first slot. */
2021-01-18 14:33:39 +00:00
if ( Company : : IsHumanID ( company_id ) | | company_id = = _local_company ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Company is not controlled by an AI. " ) ;
2009-01-14 15:39:05 +00:00
return true ;
}
/* First kill the company of the AI, then start a new one. This should start the current AI again */
2021-02-05 10:00:36 +00:00
DoCommandP ( 0 , CCA_DELETE | company_id < < 16 | CRR_MANUAL < < 24 , 0 , CMD_COMPANY_CTRL ) ;
2019-02-04 17:06:19 +00:00
DoCommandP ( 0 , CCA_NEW_AI | company_id < < 16 , 0 , CMD_COMPANY_CTRL ) ;
2009-01-14 15:39:05 +00:00
IConsolePrint ( CC_DEFAULT , " AI reloaded. " ) ;
return true ;
}
2009-01-12 17:11:45 +00:00
DEF_CONSOLE_CMD ( ConStopAI )
{
if ( argc ! = 2 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Stop an AI. Usage: 'stop_ai <company-id>'. " ) ;
IConsolePrint ( CC_HELP , " Stop the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
2009-01-13 11:06:21 +00:00
if ( _game_mode ! = GM_NORMAL ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " AIs can only be managed in a game. " ) ;
2009-01-13 11:06:21 +00:00
return true ;
}
2009-01-12 17:11:45 +00:00
if ( _networking & & ! _network_server ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Only the server can stop an AI. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
CompanyID company_id = ( CompanyID ) ( atoi ( argv [ 1 ] ) - 1 ) ;
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company_id ) ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_ERROR , " Unknown company. Company range is between 1 and {}. " , MAX_COMPANIES ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
2021-01-22 15:24:29 +00:00
/* In singleplayer mode the player can be in an AI company, after cheating or loading network save with an AI in first slot. */
2011-12-28 17:33:12 +00:00
if ( Company : : IsHumanID ( company_id ) | | company_id = = _local_company ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Company is not controlled by an AI. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
/* Now kill the company of the AI. */
2019-04-05 13:11:52 +00:00
DoCommandP ( 0 , CCA_DELETE | company_id < < 16 | CRR_MANUAL < < 24 , 0 , CMD_COMPANY_CTRL ) ;
2009-01-12 17:11:45 +00:00
IConsolePrint ( CC_DEFAULT , " AI stopped, company deleted. " ) ;
return true ;
}
DEF_CONSOLE_CMD ( ConRescanAI )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Rescan the AI dir for scripts. Usage: 'rescan_ai'. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
if ( _networking & & ! _network_server ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Only the server can rescan the AI dir for scripts. " ) ;
2009-01-12 17:11:45 +00:00
return true ;
}
AI : : Rescan ( ) ;
return true ;
}
2011-12-21 12:25:17 +00:00
DEF_CONSOLE_CMD ( ConRescanGame )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Rescan the Game Script dir for scripts. Usage: 'rescan_game'. " ) ;
2011-12-21 12:25:17 +00:00
return true ;
}
if ( _networking & & ! _network_server ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Only the server can rescan the Game Script dir for scripts. " ) ;
2011-12-21 12:25:17 +00:00
return true ;
}
Game : : Rescan ( ) ;
return true ;
}
2010-08-03 12:54:19 +00:00
DEF_CONSOLE_CMD ( ConRescanNewGRF )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Rescan the data dir for NewGRFs. Usage: 'rescan_newgrf'. " ) ;
2010-08-03 12:54:19 +00:00
return true ;
}
2021-04-12 18:53:04 +00:00
if ( ! RequestNewGRFScan ( ) ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " NewGRF scanning is already running. Please wait until completed to run again. " ) ;
2021-04-12 18:53:04 +00:00
}
2010-08-03 12:54:19 +00:00
return true ;
}
(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
DEF_CONSOLE_CMD ( ConGetSeed )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Returns the seed used to create this game. Usage: 'getseed'. " ) ;
IConsolePrint ( CC_HELP , " The seed can be used to reproduce the exact same map as the game started with. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Generation Seed: {} " , _settings_game . game_creation . generation_seed ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2007-06-13 14:52:41 +00:00
DEF_CONSOLE_CMD ( ConGetDate )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Returns the current date (year-month-day) of the game. Usage: 'getdate'. " ) ;
2007-06-13 14:52:41 +00:00
return true ;
}
YearMonthDay ymd ;
ConvertDateToYMD ( _date , & ymd ) ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Date: {:04d}-{:02d}-{:02d} " , ymd . year , ymd . month + 1 , ymd . day ) ;
2019-08-04 18:35:56 +00:00
return true ;
}
DEF_CONSOLE_CMD ( ConGetSysDate )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Returns the current date (year-month-day) of your system. Usage: 'getsysdate'. " ) ;
2019-08-04 18:35:56 +00:00
return true ;
}
2021-05-13 08:00:41 +00:00
char buffer [ lengthof ( " 2000-01-02 03:04:05 " ) ] ;
LocalTime : : Format ( buffer , lastof ( buffer ) , " %Y-%m-%d %H:%M:%S " ) ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " System Date: {} " , buffer ) ;
2007-06-13 14:52:41 +00:00
return true ;
}
2004-12-13 18:51:08 +00:00
DEF_CONSOLE_CMD ( ConAlias )
{
2005-05-02 15:52:19 +00:00
IConsoleAlias * alias ;
2004-12-13 22:13:02 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc < 3 ) return false ;
2004-12-13 22:13:02 +00:00
2021-04-24 13:19:57 +00:00
alias = IConsole : : AliasGet ( argv [ 1 ] ) ;
2019-04-10 21:07:06 +00:00
if ( alias = = nullptr ) {
2021-04-24 13:19:57 +00:00
IConsole : : AliasRegister ( argv [ 1 ] , argv [ 2 ] ) ;
2004-12-13 22:13:02 +00:00
} else {
2021-04-24 13:19:57 +00:00
alias - > cmdline = argv [ 2 ] ;
2004-12-13 22:13:02 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-13 18:51:08 +00:00
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConScreenShot )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | heightmap | minimap] [no_con] [size <width> <height>] [<filename>]'. " ) ;
IConsolePrint ( CC_HELP , " 'viewport' (default) makes a screenshot of the current viewport (including menus, windows). " ) ;
IConsolePrint ( CC_HELP , " 'normal' makes a screenshot of the visible area. " ) ;
IConsolePrint ( CC_HELP , " 'big' makes a zoomed-in screenshot of the visible area. " ) ;
IConsolePrint ( CC_HELP , " 'giant' makes a screenshot of the whole map. " ) ;
IConsolePrint ( CC_HELP , " 'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap. " ) ;
IConsolePrint ( CC_HELP , " 'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel. " ) ;
IConsolePrint ( CC_HELP , " 'no_con' hides the console to create the screenshot (only useful in combination with 'viewport'). " ) ;
IConsolePrint ( CC_HELP , " 'size' sets the width and height of the viewport to make a screenshot of (only useful in combination with 'normal' or 'big'). " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2021-01-22 15:16:33 +00:00
if ( argc > 7 ) return false ;
2005-10-19 19:41:38 +00:00
2009-11-01 18:15:35 +00:00
ScreenshotType type = SC_VIEWPORT ;
2021-01-22 15:16:33 +00:00
uint32 width = 0 ;
uint32 height = 0 ;
2021-05-01 17:55:46 +00:00
std : : string name { } ;
2021-01-22 15:16:33 +00:00
uint32 arg_index = 1 ;
if ( argc > arg_index ) {
if ( strcmp ( argv [ arg_index ] , " viewport " ) = = 0 ) {
type = SC_VIEWPORT ;
arg_index + = 1 ;
} else if ( strcmp ( argv [ arg_index ] , " normal " ) = = 0 ) {
type = SC_DEFAULTZOOM ;
arg_index + = 1 ;
} else if ( strcmp ( argv [ arg_index ] , " big " ) = = 0 ) {
2010-08-15 23:32:36 +00:00
type = SC_ZOOMEDIN ;
2021-01-22 15:16:33 +00:00
arg_index + = 1 ;
} else if ( strcmp ( argv [ arg_index ] , " giant " ) = = 0 ) {
2009-11-01 18:15:35 +00:00
type = SC_WORLD ;
2021-01-22 15:16:33 +00:00
arg_index + = 1 ;
2021-03-04 09:38:25 +00:00
} else if ( strcmp ( argv [ arg_index ] , " heightmap " ) = = 0 ) {
type = SC_HEIGHTMAP ;
arg_index + = 1 ;
2021-01-22 15:16:33 +00:00
} else if ( strcmp ( argv [ arg_index ] , " minimap " ) = = 0 ) {
2020-01-04 16:47:37 +00:00
type = SC_MINIMAP ;
2021-01-22 15:16:33 +00:00
arg_index + = 1 ;
}
}
if ( argc > arg_index & & strcmp ( argv [ arg_index ] , " no_con " ) = = 0 ) {
if ( type ! = SC_VIEWPORT ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " 'no_con' can only be used in combination with 'viewport'. " ) ;
2021-01-22 15:16:33 +00:00
return true ;
2009-11-01 18:15:35 +00:00
}
2021-01-22 15:16:33 +00:00
IConsoleClose ( ) ;
arg_index + = 1 ;
}
if ( argc > arg_index + 2 & & strcmp ( argv [ arg_index ] , " size " ) = = 0 ) {
/* size <width> <height> */
if ( type ! = SC_DEFAULTZOOM & & type ! = SC_ZOOMEDIN ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " 'size' can only be used in combination with 'normal' or 'big'. " ) ;
2021-01-22 15:16:33 +00:00
return true ;
}
GetArgumentInteger ( & width , argv [ arg_index + 1 ] ) ;
GetArgumentInteger ( & height , argv [ arg_index + 2 ] ) ;
arg_index + = 3 ;
}
if ( argc > arg_index ) {
/* Last parameter that was not one of the keywords must be the filename. */
name = argv [ arg_index ] ;
arg_index + = 1 ;
}
if ( argc > arg_index ) {
/* We have parameters we did not process; means we misunderstood any of the above. */
return false ;
2004-09-19 15:24:45 +00:00
}
2005-10-19 19:41:38 +00:00
2021-01-22 15:16:33 +00:00
MakeScreenshot ( type , name , width , height ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-09-14 16:10:20 +00:00
DEF_CONSOLE_CMD ( ConInfoCmd )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Print out debugging information about a command. Usage: 'info_cmd <cmd>'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc < 2 ) return false ;
2021-04-24 13:19:57 +00:00
const IConsoleCmd * cmd = IConsole : : CmdGet ( argv [ 1 ] ) ;
2019-04-10 21:07:06 +00:00
if ( cmd = = nullptr ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " The given command was not found. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-19 15:24:45 +00:00
}
2005-05-02 15:52:19 +00:00
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_DEFAULT , " Command name: '{}' " , cmd - > name ) ;
2005-05-02 15:52:19 +00:00
2021-06-12 18:55:56 +00:00
if ( cmd - > hook ! = nullptr ) IConsolePrint ( CC_DEFAULT , " Command is hooked. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConDebugLevel )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'. " ) ;
IConsolePrint ( CC_HELP , " Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \" ' \" s. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2005-05-20 17:59:24 +00:00
if ( argc > 2 ) return false ;
if ( argc = = 1 ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Current debug-level: '{}' " , GetDebugString ( ) ) ;
2006-06-27 21:25:53 +00:00
} else {
SetDebugString ( argv [ 1 ] ) ;
}
2005-05-20 17:59:24 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConExit )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Exit the game. Usage: 'exit'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2008-05-29 15:13:28 +00:00
if ( _game_mode = = GM_NORMAL & & _settings_client . gui . autosave_on_exit ) DoExitSave ( ) ;
2007-07-23 15:28:02 +00:00
2004-09-12 21:49:38 +00:00
_exit_game = true ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2005-05-15 10:40:53 +00:00
DEF_CONSOLE_CMD ( ConPart )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Leave the currently joined/running game (only ingame). Usage: 'part'. " ) ;
2005-05-15 10:40:53 +00:00
return true ;
}
if ( _game_mode ! = GM_NORMAL ) return false ;
_switch_mode = SM_MENU ;
return true ;
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConHelp )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 2 ) {
2005-05-02 17:05:59 +00:00
const IConsoleCmd * cmd ;
const IConsoleAlias * alias ;
2005-05-02 15:52:19 +00:00
2021-04-24 13:19:57 +00:00
cmd = IConsole : : CmdGet ( argv [ 1 ] ) ;
2019-04-10 21:07:06 +00:00
if ( cmd ! = nullptr ) {
cmd - > proc ( 0 , nullptr ) ;
2005-07-08 22:25:24 +00:00
return true ;
}
2021-04-24 13:19:57 +00:00
alias = IConsole : : AliasGet ( argv [ 1 ] ) ;
2019-04-10 21:07:06 +00:00
if ( alias ! = nullptr ) {
2021-04-24 13:19:57 +00:00
cmd = IConsole : : CmdGet ( alias - > cmdline ) ;
2019-04-10 21:07:06 +00:00
if ( cmd ! = nullptr ) {
cmd - > proc ( 0 , nullptr ) ;
2005-07-08 22:25:24 +00:00
return true ;
}
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_ERROR , " Alias is of special type, please see its execution-line: '{}'. " , alias - > cmdline ) ;
2005-07-08 22:25:24 +00:00
return true ;
}
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_ERROR , " Command not found. " ) ;
2005-07-08 22:25:24 +00:00
return true ;
}
2005-05-02 15:52:19 +00:00
2021-06-12 18:55:56 +00:00
IConsolePrint ( TC_LIGHT_BLUE , " ---- OpenTTD Console Help ---- " ) ;
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_DEFAULT , " - commands: the command to list all commands is 'list_cmds'. " ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " call commands with '<command> <arg2> <arg3>...' " ) ;
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_DEFAULT , " - to assign strings, or use them as arguments, enclose it within quotes. " ) ;
IConsolePrint ( CC_DEFAULT , " like this: '<command> \" string argument with spaces \" '. " ) ;
IConsolePrint ( CC_DEFAULT , " - use 'help <command>' to get specific information. " ) ;
IConsolePrint ( CC_DEFAULT , " - scroll console output with shift + (up | down | pageup | pagedown). " ) ;
IConsolePrint ( CC_DEFAULT , " - scroll console input history with the up or down arrows. " ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConListCommands )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List all registered commands. Usage: 'list_cmds [<pre-filter>]'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2021-04-24 13:19:57 +00:00
for ( auto & it : IConsole : : Commands ( ) ) {
const IConsoleCmd * cmd = & it . second ;
if ( argv [ 1 ] = = nullptr | | cmd - > name . find ( argv [ 1 ] ) ! = std : : string : : npos ) {
2021-06-12 19:33:01 +00:00
if ( cmd - > hook = = nullptr | | cmd - > hook ( false ) ! = CHR_HIDE ) IConsolePrint ( CC_DEFAULT , cmd - > name ) ;
2005-05-02 15:52:19 +00:00
}
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-12-13 18:51:08 +00:00
DEF_CONSOLE_CMD ( ConListAliases )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List all registered aliases. Usage: 'list_aliases [<pre-filter>]'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-09-12 21:49:38 +00:00
2021-04-24 13:19:57 +00:00
for ( auto & it : IConsole : : Aliases ( ) ) {
const IConsoleAlias * alias = & it . second ;
if ( argv [ 1 ] = = nullptr | | alias - > name . find ( argv [ 1 ] ) ! = std : : string : : npos ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " {} => {} " , alias - > name , alias - > cmdline ) ;
2010-02-10 13:52:10 +00:00
}
2005-05-02 15:52:19 +00:00
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2012-12-09 16:53:41 +00:00
DEF_CONSOLE_CMD ( ConCompanies )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List the details of all companies in the game. Usage 'companies'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2019-12-14 16:22:38 +00:00
for ( const Company * c : Company : : Iterate ( ) ) {
2012-12-09 16:53:41 +00:00
/* Grab the company name */
char company_name [ 512 ] ;
SetDParam ( 0 , c - > index ) ;
GetString ( company_name , STR_COMPANY_NAME , lastof ( company_name ) ) ;
2005-05-02 15:52:19 +00:00
2012-12-09 16:53:41 +00:00
const char * password_state = " " ;
if ( c - > is_ai ) {
password_state = " AI " ;
Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.
Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.
A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.
With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.
All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 16:01:13 +00:00
} else if ( _network_server ) {
2021-05-02 06:27:06 +00:00
password_state = _network_company_states [ c - > index ] . password . empty ( ) ? " unprotected " : " protected " ;
2012-12-09 16:53:41 +00:00
}
char colour [ 512 ] ;
GetString ( colour , STR_COLOUR_DARK_BLUE + _company_colours [ c - > index ] , lastof ( colour ) ) ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_INFO , " #:{}({}) Company Name: '{}' Year Founded: {} Money: {} Loan: {} Value: {} (T:{}, R:{}, P:{}, S:{}) {} " ,
2012-12-09 16:53:41 +00:00
c - > index + 1 , colour , company_name ,
c - > inaugurated_year , ( int64 ) c - > money , ( int64 ) c - > current_loan , ( int64 ) CalculateCompanyValue ( c ) ,
c - > group_all [ VEH_TRAIN ] . num_vehicle ,
c - > group_all [ VEH_ROAD ] . num_vehicle ,
c - > group_all [ VEH_AIRCRAFT ] . num_vehicle ,
c - > group_all [ VEH_SHIP ] . num_vehicle ,
password_state ) ;
2006-06-27 21:25:53 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2012-12-09 16:53:41 +00:00
DEF_CONSOLE_CMD ( ConSay )
2006-05-11 14:08:03 +00:00
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Chat to your fellow players in a multiplayer game. Usage: 'say \" <msg> \" '. " ) ;
2006-05-11 14:08:03 +00:00
return true ;
}
2006-05-14 23:01:11 +00:00
2012-12-09 16:53:41 +00:00
if ( argc ! = 2 ) return false ;
2007-05-02 19:00:59 +00:00
2012-12-09 16:53:41 +00:00
if ( ! _network_server ) {
NetworkClientSendChat ( NETWORK_ACTION_CHAT , DESTTYPE_BROADCAST , 0 /* param does not matter */ , argv [ 1 ] ) ;
} else {
bool from_admin = ( _redirect_console_to_admin < INVALID_ADMIN_ID ) ;
NetworkServerSendChat ( NETWORK_ACTION_CHAT , DESTTYPE_BROADCAST , 0 , argv [ 1 ] , CLIENT_ID_SERVER , from_admin ) ;
2006-05-11 14:08:03 +00:00
}
return true ;
}
2008-09-30 20:39:50 +00:00
DEF_CONSOLE_CMD ( ConSayCompany )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \" <msg> \" '. " ) ;
IConsolePrint ( CC_HELP , " CompanyNo is the company that plays as company <companyno>, 1 through max_companies. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc ! = 3 ) return false ;
2004-12-04 17:54:56 +00:00
2008-09-30 20:39:50 +00:00
CompanyID company_id = ( CompanyID ) ( atoi ( argv [ 1 ] ) - 1 ) ;
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company_id ) ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Unknown company. Company range is between 1 and {}. " , MAX_COMPANIES ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( ! _network_server ) {
2008-09-30 20:39:50 +00:00
NetworkClientSendChat ( NETWORK_ACTION_CHAT_COMPANY , DESTTYPE_TEAM , company_id , argv [ 2 ] ) ;
2006-06-27 21:25:53 +00:00
} else {
2010-10-17 17:41:52 +00:00
bool from_admin = ( _redirect_console_to_admin < INVALID_ADMIN_ID ) ;
NetworkServerSendChat ( NETWORK_ACTION_CHAT_COMPANY , DESTTYPE_TEAM , company_id , argv [ 2 ] , CLIENT_ID_SERVER , from_admin ) ;
2006-06-27 21:25:53 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
DEF_CONSOLE_CMD ( ConSayClient )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \" <msg> \" '. " ) ;
IConsolePrint ( CC_HELP , " For client-id's, see the command 'clients'. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc ! = 3 ) return false ;
if ( ! _network_server ) {
2008-05-30 18:20:26 +00:00
NetworkClientSendChat ( NETWORK_ACTION_CHAT_CLIENT , DESTTYPE_CLIENT , atoi ( argv [ 1 ] ) , argv [ 2 ] ) ;
2006-06-27 21:25:53 +00:00
} else {
2010-10-17 17:41:52 +00:00
bool from_admin = ( _redirect_console_to_admin < INVALID_ADMIN_ID ) ;
NetworkServerSendChat ( NETWORK_ACTION_CHAT_CLIENT , DESTTYPE_CLIENT , atoi ( argv [ 1 ] ) , argv [ 2 ] , CLIENT_ID_SERVER , from_admin ) ;
2006-06-27 21:25:53 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2010-02-10 15:17:27 +00:00
DEF_CONSOLE_CMD ( ConCompanyPassword )
2005-05-02 15:52:19 +00:00
{
if ( argc = = 0 ) {
2011-01-19 16:52:57 +00:00
if ( _network_dedicated ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_HELP , " Change the password of a company. Usage: 'company_pw <company-no> \" <password> \" . " ) ;
2011-01-19 16:52:57 +00:00
} else if ( _network_server ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_HELP , " Change the password of your or any other company. Usage: 'company_pw [<company-no>] \" <password> \" '. " ) ;
2011-01-19 16:52:57 +00:00
} else {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_HELP , " Change the password of your company. Usage: 'company_pw \" <password> \" '. " ) ;
2011-01-19 16:52:57 +00:00
}
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_HELP , " Use \" * \" to disable the password. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2011-01-19 16:52:57 +00:00
CompanyID company_id ;
2021-05-02 07:18:56 +00:00
std : : string password ;
2011-01-19 16:52:57 +00:00
const char * errormsg ;
if ( argc = = 2 ) {
company_id = _local_company ;
password = argv [ 1 ] ;
errormsg = " You have to own a company to make use of this command. " ;
} else if ( argc = = 3 & & _network_server ) {
company_id = ( CompanyID ) ( atoi ( argv [ 1 ] ) - 1 ) ;
password = argv [ 2 ] ;
errormsg = " You have to specify the ID of a valid human controlled company. " ;
} else {
return false ;
}
2010-02-10 15:17:27 +00:00
2011-01-19 16:52:57 +00:00
if ( ! Company : : IsValidHumanID ( company_id ) ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , errormsg ) ;
2005-05-02 15:52:19 +00:00
return false ;
2005-01-15 20:09:16 +00:00
}
2011-08-13 08:32:55 +00:00
password = NetworkChangeCompanyPassword ( company_id , password ) ;
2004-12-13 15:07:33 +00:00
2021-05-02 07:18:56 +00:00
if ( password . empty ( ) ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_INFO , " Company password cleared. " ) ;
2007-12-02 15:12:19 +00:00
} else {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_INFO , " Company password changed to '{}'. " , password ) ;
2007-12-02 15:12:19 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-04 17:54:56 +00:00
2009-05-24 17:49:08 +00:00
/* Content downloading only is available with ZLIB */
# if defined(WITH_ZLIB)
2009-01-21 09:22:49 +00:00
# include "network/network_content.h"
/** Resolve a string to a content type. */
static ContentType StringToContentType ( const char * str )
{
2009-09-20 23:11:01 +00:00
static const char * const inv_lookup [ ] = { " " , " base " , " newgrf " , " ai " , " ailib " , " scenario " , " heightmap " } ;
2009-01-21 09:22:49 +00:00
for ( uint i = 1 /* there is no type 0 */ ; i < lengthof ( inv_lookup ) ; i + + ) {
if ( strcasecmp ( str , inv_lookup [ i ] ) = = 0 ) return ( ContentType ) i ;
}
return CONTENT_TYPE_END ;
}
/** Asynchronous callback */
struct ConsoleContentCallback : public ContentCallback {
void OnConnect ( bool success )
{
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Content server connection {}. " , success ? " established " : " failed " ) ;
2009-01-21 09:22:49 +00:00
}
void OnDisconnect ( )
{
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Content server connection closed. " ) ;
2009-01-21 09:22:49 +00:00
}
void OnDownloadComplete ( ContentID cid )
{
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Completed download of {}. " , cid ) ;
2009-01-21 09:22:49 +00:00
}
} ;
2013-11-14 22:48:03 +00:00
/**
* Outputs content state information to console
* @ param ci the content info
*/
static void OutputContentState ( const ContentInfo * const ci )
{
static const char * const types [ ] = { " Base graphics " , " NewGRF " , " AI " , " AI library " , " Scenario " , " Heightmap " , " Base sound " , " Base music " , " Game script " , " GS library " } ;
2020-12-27 10:44:22 +00:00
static_assert ( lengthof ( types ) = = CONTENT_TYPE_END - CONTENT_TYPE_BEGIN ) ;
2013-11-14 22:48:03 +00:00
static const char * const states [ ] = { " Not selected " , " Selected " , " Dep Selected " , " Installed " , " Unknown " } ;
static const TextColour state_to_colour [ ] = { CC_COMMAND , CC_INFO , CC_INFO , CC_WHITE , CC_ERROR } ;
char buf [ sizeof ( ci - > md5sum ) * 2 + 1 ] ;
md5sumToString ( buf , lastof ( buf ) , ci - > md5sum ) ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( state_to_colour [ ci - > state ] , " {}, {}, {}, {}, {:08X}, {} " , ci - > id , types [ ci - > type - 1 ] , states [ ci - > state ] , ci - > name , ci - > unique_id , buf ) ;
2013-11-14 22:48:03 +00:00
}
2009-01-21 09:22:49 +00:00
DEF_CONSOLE_CMD ( ConContent )
{
2019-04-10 21:07:06 +00:00
static ContentCallback * cb = nullptr ;
if ( cb = = nullptr ) {
2009-01-21 09:22:49 +00:00
cb = new ConsoleContentCallback ( ) ;
_network_content_client . AddCallback ( cb ) ;
}
if ( argc < = 1 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'. " ) ;
IConsolePrint ( CC_HELP , " update: get a new list of downloadable content; must be run first. " ) ;
IConsolePrint ( CC_HELP , " upgrade: select all items that are upgrades. " ) ;
IConsolePrint ( CC_HELP , " select: select a specific item given by its id. If no parameter is given, all selected content will be listed. " ) ;
IConsolePrint ( CC_HELP , " unselect: unselect a specific item given by its id or 'all' to unselect all. " ) ;
IConsolePrint ( CC_HELP , " state: show the download/select state of all downloadable content. Optionally give a filter string. " ) ;
IConsolePrint ( CC_HELP , " download: download all content you've selected. " ) ;
2009-01-21 09:22:49 +00:00
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " update " ) = = 0 ) {
_network_content_client . RequestContentList ( ( argc > 2 ) ? StringToContentType ( argv [ 2 ] ) : CONTENT_TYPE_END ) ;
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " upgrade " ) = = 0 ) {
_network_content_client . SelectUpgrade ( ) ;
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " select " ) = = 0 ) {
if ( argc < = 2 ) {
2013-11-14 22:48:03 +00:00
/* List selected content */
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_WHITE , " id, type, state, name " ) ;
2013-11-14 22:48:03 +00:00
for ( ConstContentIterator iter = _network_content_client . Begin ( ) ; iter ! = _network_content_client . End ( ) ; iter + + ) {
if ( ( * iter ) - > state ! = ContentInfo : : SELECTED & & ( * iter ) - > state ! = ContentInfo : : AUTOSELECTED ) continue ;
OutputContentState ( * iter ) ;
}
} else if ( strcasecmp ( argv [ 2 ] , " all " ) = = 0 ) {
2020-12-07 13:48:13 +00:00
/* The intention of this function was that you could download
* everything after a filter was applied ; but this never really
* took off . Instead , a select few people used this functionality
* to download every available package on BaNaNaS . This is not in
* the spirit of this service . Additionally , these few people were
* good for 70 % of the consumed bandwidth of BaNaNaS . */
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " 'select all' is no longer supported since 1.11. " ) ;
2009-01-21 09:22:49 +00:00
} else {
_network_content_client . Select ( ( ContentID ) atoi ( argv [ 2 ] ) ) ;
}
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " unselect " ) = = 0 ) {
if ( argc < = 2 ) {
2021-06-12 19:07:04 +00:00
IConsolePrint ( CC_ERROR , " You must enter the id. " ) ;
2009-01-21 09:22:49 +00:00
return false ;
}
if ( strcasecmp ( argv [ 2 ] , " all " ) = = 0 ) {
_network_content_client . UnselectAll ( ) ;
} else {
_network_content_client . Unselect ( ( ContentID ) atoi ( argv [ 2 ] ) ) ;
}
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " state " ) = = 0 ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_WHITE , " id, type, state, name " ) ;
2009-01-21 09:22:49 +00:00
for ( ConstContentIterator iter = _network_content_client . Begin ( ) ; iter ! = _network_content_client . End ( ) ; iter + + ) {
2021-05-30 11:02:44 +00:00
if ( argc > 2 & & strcasestr ( ( * iter ) - > name . c_str ( ) , argv [ 2 ] ) = = nullptr ) continue ;
2013-11-14 22:48:03 +00:00
OutputContentState ( * iter ) ;
2009-01-21 09:22:49 +00:00
}
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " download " ) = = 0 ) {
uint files ;
uint bytes ;
_network_content_client . DownloadSelectedContent ( files , bytes ) ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Downloading {} file(s) ({} bytes). " , files , bytes ) ;
2009-01-21 09:22:49 +00:00
return true ;
}
return false ;
}
2009-05-24 17:49:08 +00:00
# endif /* defined(WITH_ZLIB) */
2004-12-16 13:59:23 +00:00
2009-02-08 12:25:13 +00:00
DEF_CONSOLE_CMD ( ConSetting )
2005-05-02 15:52:19 +00:00
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Change setting for all clients. Usage: 'setting <name> [<value>]'. " ) ;
IConsolePrint ( CC_HELP , " Omitting <value> will print out the current value of the setting. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-16 13:59:23 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc = = 1 | | argc > 3 ) return false ;
2004-12-16 13:59:23 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 2 ) {
2009-02-08 12:25:13 +00:00
IConsoleGetSetting ( argv [ 1 ] ) ;
2006-06-27 21:25:53 +00:00
} else {
2009-02-08 12:25:13 +00:00
IConsoleSetSetting ( argv [ 1 ] , argv [ 2 ] ) ;
2006-06-27 21:25:53 +00:00
}
2004-12-23 17:37:26 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-13 15:07:33 +00:00
2010-01-28 23:17:28 +00:00
DEF_CONSOLE_CMD ( ConSettingNewgame )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'. " ) ;
IConsolePrint ( CC_HELP , " Omitting <value> will print out the current value of the setting. " ) ;
2010-01-28 23:17:28 +00:00
return true ;
}
if ( argc = = 1 | | argc > 3 ) return false ;
if ( argc = = 2 ) {
IConsoleGetSetting ( argv [ 1 ] , true ) ;
} else {
IConsoleSetSetting ( argv [ 1 ] , argv [ 2 ] , true ) ;
}
return true ;
}
2009-02-08 12:25:13 +00:00
DEF_CONSOLE_CMD ( ConListSettings )
2007-04-05 12:59:57 +00:00
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " List settings. Usage: 'list_settings [<pre-filter>]'. " ) ;
2007-04-05 12:59:57 +00:00
return true ;
}
2008-08-11 17:15:31 +00:00
if ( argc > 2 ) return false ;
2007-04-05 12:59:57 +00:00
2019-04-10 21:07:06 +00:00
IConsoleListSettings ( ( argc = = 2 ) ? argv [ 1 ] : nullptr ) ;
2007-04-05 12:59:57 +00:00
return true ;
}
2008-06-03 18:35:58 +00:00
DEF_CONSOLE_CMD ( ConGamelogPrint )
{
GamelogPrintConsole ( ) ;
return true ;
}
2004-12-04 17:54:56 +00:00
2010-03-24 20:47:03 +00:00
DEF_CONSOLE_CMD ( ConNewGRFReload )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Reloads all active NewGRFs from disk. Equivalent to reapplying NewGRFs via the settings, but without asking for confirmation. This might crash OpenTTD! " ) ;
2010-03-24 20:47:03 +00:00
return true ;
}
ReloadNewGRFData ( ) ;
return true ;
}
2021-09-26 21:11:22 +00:00
DEF_CONSOLE_CMD ( ConListDirs )
{
struct SubdirNameMap {
Subdirectory subdir ; ///< Index of subdirectory type
const char * name ; ///< UI name for the directory
bool default_only ; ///< Whether only the default (first existing) directory for this is interesting
} ;
static const SubdirNameMap subdir_name_map [ ] = {
/* Game data directories */
{ BASESET_DIR , " baseset " , false } ,
{ NEWGRF_DIR , " newgrf " , false } ,
{ AI_DIR , " ai " , false } ,
{ AI_LIBRARY_DIR , " ailib " , false } ,
{ GAME_DIR , " gs " , false } ,
{ GAME_LIBRARY_DIR , " gslib " , false } ,
{ SCENARIO_DIR , " scenario " , false } ,
{ HEIGHTMAP_DIR , " heightmap " , false } ,
/* Default save locations for user data */
{ SAVE_DIR , " save " , true } ,
{ AUTOSAVE_DIR , " autosave " , true } ,
{ SCREENSHOT_DIR , " screenshot " , true } ,
} ;
if ( argc ! = 2 ) {
IConsolePrint ( CC_HELP , " List all search paths or default directories for various categories. " ) ;
IConsolePrint ( CC_HELP , " Usage: list_dirs <category> " ) ;
std : : string cats = subdir_name_map [ 0 ] . name ;
bool first = true ;
for ( const SubdirNameMap & sdn : subdir_name_map ) {
if ( ! first ) cats = cats + " , " + sdn . name ;
first = false ;
}
IConsolePrint ( CC_HELP , " Valid categories: {} " , cats ) ;
return true ;
}
std : : set < std : : string > seen_dirs ;
for ( const SubdirNameMap & sdn : subdir_name_map ) {
if ( strcasecmp ( argv [ 1 ] , sdn . name ) ! = 0 ) continue ;
bool found = false ;
for ( Searchpath sp : _valid_searchpaths ) {
/* Get the directory */
std : : string path = FioGetDirectory ( sp , sdn . subdir ) ;
/* Check it hasn't already been listed */
if ( seen_dirs . find ( path ) ! = seen_dirs . end ( ) ) continue ;
seen_dirs . insert ( path ) ;
/* Check if exists and mark found */
bool exists = FileExists ( path ) ;
found | = exists ;
/* Print */
if ( ! sdn . default_only | | exists ) {
IConsolePrint ( exists ? CC_DEFAULT : CC_INFO , " {} {} " , path , exists ? " [ok] " : " [not found] " ) ;
if ( sdn . default_only ) break ;
}
}
if ( ! found ) {
IConsolePrint ( CC_ERROR , " No directories exist for category {} " , argv [ 1 ] ) ;
}
return true ;
}
IConsolePrint ( CC_ERROR , " Invalid category name: {} " , argv [ 1 ] ) ;
return false ;
}
2020-01-26 12:45:51 +00:00
DEF_CONSOLE_CMD ( ConNewGRFProfile )
{
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'newgrf_profile [list]': " ) ;
IConsolePrint ( CC_HELP , " List all NewGRFs that can be profiled, and their status. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'newgrf_profile select <grf-num>...': " ) ;
IConsolePrint ( CC_HELP , " Select one or more GRFs for profiling. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'newgrf_profile unselect <grf-num>...': " ) ;
IConsolePrint ( CC_HELP , " Unselect one or more GRFs from profiling. Use the keyword \" all \" instead of a GRF number to unselect all. Removing an active profiler aborts data collection. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'newgrf_profile start [<num-days>]': " ) ;
IConsolePrint ( CC_HELP , " Begin profiling all selected GRFs. If a number of days is provided, profiling stops after that many in-game days. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'newgrf_profile stop': " ) ;
IConsolePrint ( CC_HELP , " End profiling and write the collected data to CSV files. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'newgrf_profile abort': " ) ;
IConsolePrint ( CC_HELP , " End profiling and discard all collected data. " ) ;
2020-01-26 12:45:51 +00:00
return true ;
}
extern const std : : vector < GRFFile * > & GetAllGRFFiles ( ) ;
const std : : vector < GRFFile * > & files = GetAllGRFFiles ( ) ;
/* "list" sub-command */
if ( argc = = 1 | | strncasecmp ( argv [ 1 ] , " lis " , 3 ) = = 0 ) {
IConsolePrint ( CC_INFO , " Loaded GRF files: " ) ;
int i = 1 ;
for ( GRFFile * grf : files ) {
auto profiler = std : : find_if ( _newgrf_profilers . begin ( ) , _newgrf_profilers . end ( ) , [ & ] ( NewGRFProfiler & pr ) { return pr . grffile = = grf ; } ) ;
bool selected = profiler ! = _newgrf_profilers . end ( ) ;
bool active = selected & & profiler - > active ;
TextColour tc = active ? TC_LIGHT_BLUE : selected ? TC_GREEN : CC_INFO ;
const char * statustext = active ? " (active) " : selected ? " (selected) " : " " ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( tc , " {}: [{:08X}] {}{} " , i , BSWAP32 ( grf - > grfid ) , grf - > filename , statustext ) ;
2020-01-26 12:45:51 +00:00
i + + ;
}
return true ;
}
/* "select" sub-command */
if ( strncasecmp ( argv [ 1 ] , " sel " , 3 ) = = 0 & & argc > = 3 ) {
for ( size_t argnum = 2 ; argnum < argc ; + + argnum ) {
int grfnum = atoi ( argv [ argnum ] ) ;
if ( grfnum < 1 | | grfnum > ( int ) files . size ( ) ) { // safe cast, files.size() should not be larger than a few hundred in the most extreme cases
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_WARNING , " GRF number {} out of range, not added. " , grfnum ) ;
2020-01-26 12:45:51 +00:00
continue ;
}
GRFFile * grf = files [ grfnum - 1 ] ;
if ( std : : any_of ( _newgrf_profilers . begin ( ) , _newgrf_profilers . end ( ) , [ & ] ( NewGRFProfiler & pr ) { return pr . grffile = = grf ; } ) ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_WARNING , " GRF number {} [{:08X}] is already selected for profiling. " , grfnum , BSWAP32 ( grf - > grfid ) ) ;
2020-01-26 12:45:51 +00:00
continue ;
}
_newgrf_profilers . emplace_back ( grf ) ;
}
return true ;
}
/* "unselect" sub-command */
if ( strncasecmp ( argv [ 1 ] , " uns " , 3 ) = = 0 & & argc > = 3 ) {
for ( size_t argnum = 2 ; argnum < argc ; + + argnum ) {
if ( strcasecmp ( argv [ argnum ] , " all " ) = = 0 ) {
_newgrf_profilers . clear ( ) ;
break ;
}
int grfnum = atoi ( argv [ argnum ] ) ;
if ( grfnum < 1 | | grfnum > ( int ) files . size ( ) ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_WARNING , " GRF number {} out of range, not removing. " , grfnum ) ;
2020-01-26 12:45:51 +00:00
continue ;
}
GRFFile * grf = files [ grfnum - 1 ] ;
auto pos = std : : find_if ( _newgrf_profilers . begin ( ) , _newgrf_profilers . end ( ) , [ & ] ( NewGRFProfiler & pr ) { return pr . grffile = = grf ; } ) ;
if ( pos ! = _newgrf_profilers . end ( ) ) _newgrf_profilers . erase ( pos ) ;
}
return true ;
}
/* "start" sub-command */
if ( strncasecmp ( argv [ 1 ] , " sta " , 3 ) = = 0 ) {
std : : string grfids ;
size_t started = 0 ;
for ( NewGRFProfiler & pr : _newgrf_profilers ) {
if ( ! pr . active ) {
pr . Start ( ) ;
started + + ;
if ( ! grfids . empty ( ) ) grfids + = " , " ;
char grfidstr [ 12 ] { 0 } ;
seprintf ( grfidstr , lastof ( grfidstr ) , " [%08X] " , BSWAP32 ( pr . grffile - > grfid ) ) ;
grfids + = grfidstr ;
}
}
if ( started > 0 ) {
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_DEBUG , " Started profiling for GRFID{} {}. " , ( started > 1 ) ? " s " : " " , grfids ) ;
2020-01-26 12:45:51 +00:00
if ( argc > = 3 ) {
2021-01-08 10:16:18 +00:00
int days = std : : max ( atoi ( argv [ 2 ] ) , 1 ) ;
2020-01-26 12:45:51 +00:00
_newgrf_profile_end_date = _date + days ;
char datestrbuf [ 32 ] { 0 } ;
SetDParam ( 0 , _newgrf_profile_end_date ) ;
GetString ( datestrbuf , STR_JUST_DATE_ISO , lastof ( datestrbuf ) ) ;
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEBUG , " Profiling will automatically stop on game date {}. " , datestrbuf ) ;
2020-01-26 12:45:51 +00:00
} else {
_newgrf_profile_end_date = MAX_DAY ;
}
} else if ( _newgrf_profilers . empty ( ) ) {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " No GRFs selected for profiling, did not start. " ) ;
2020-01-26 12:45:51 +00:00
} else {
2021-06-12 18:55:56 +00:00
IConsolePrint ( CC_ERROR , " Did not start profiling for any GRFs, all selected GRFs are already profiling. " ) ;
2020-01-26 12:45:51 +00:00
}
return true ;
}
/* "stop" sub-command */
if ( strncasecmp ( argv [ 1 ] , " sto " , 3 ) = = 0 ) {
NewGRFProfiler : : FinishAll ( ) ;
return true ;
}
/* "abort" sub-command */
if ( strncasecmp ( argv [ 1 ] , " abo " , 3 ) = = 0 ) {
for ( NewGRFProfiler & pr : _newgrf_profilers ) {
pr . Abort ( ) ;
}
_newgrf_profile_end_date = MAX_DAY ;
return true ;
}
return false ;
}
2004-09-12 21:49:38 +00:00
# ifdef _DEBUG
2010-02-10 17:32:39 +00:00
/******************
* debug commands
* * * * * * * * * * * * * * * * * */
2004-09-12 21:49:38 +00:00
2007-03-07 11:47:46 +00:00
static void IConsoleDebugLibRegister ( )
2004-09-12 21:49:38 +00:00
{
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " resettile " , ConResetTile ) ;
IConsole : : AliasRegister ( " dbg_echo " , " echo %A; echo %B " ) ;
IConsole : : AliasRegister ( " dbg_echo2 " , " echo %! " ) ;
2004-09-12 21:49:38 +00:00
}
# endif
2018-07-19 19:17:07 +00:00
DEF_CONSOLE_CMD ( ConFramerate )
{
extern void ConPrintFramerate ( ) ; // framerate_gui.cpp
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Show frame rate and game speed information. " ) ;
2018-07-19 19:17:07 +00:00
return true ;
}
ConPrintFramerate ( ) ;
return true ;
}
DEF_CONSOLE_CMD ( ConFramerateWindow )
{
extern void ShowFramerateWindow ( ) ;
if ( argc = = 0 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Open the frame rate window. " ) ;
2018-07-19 19:17:07 +00:00
return true ;
}
if ( _network_dedicated ) {
2021-06-13 12:55:11 +00:00
IConsolePrint ( CC_ERROR , " Can not open frame rate window on a dedicated server. " ) ;
2018-07-19 19:17:07 +00:00
return false ;
}
ShowFramerateWindow ( ) ;
return true ;
}
2021-01-13 20:16:47 +00:00
static void ConDumpRoadTypes ( )
{
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Flags: " ) ;
IConsolePrint ( CC_DEFAULT , " c = catenary " ) ;
IConsolePrint ( CC_DEFAULT , " l = no level crossings " ) ;
IConsolePrint ( CC_DEFAULT , " X = no houses " ) ;
IConsolePrint ( CC_DEFAULT , " h = hidden " ) ;
IConsolePrint ( CC_DEFAULT , " T = buildable by towns " ) ;
2021-01-13 20:16:47 +00:00
std : : map < uint32 , const GRFFile * > grfs ;
for ( RoadType rt = ROADTYPE_BEGIN ; rt < ROADTYPE_END ; rt + + ) {
const RoadTypeInfo * rti = GetRoadTypeInfo ( rt ) ;
if ( rti - > label = = 0 ) continue ;
uint32 grfid = 0 ;
const GRFFile * grf = rti - > grffile [ ROTSG_GROUND ] ;
if ( grf ! = nullptr ) {
grfid = grf - > grfid ;
grfs . emplace ( grfid , grf ) ;
}
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " {:02d} {} {:c}{:c}{:c}{:c}, Flags: {}{}{}{}{}, GRF: {:08X}, {} " ,
2021-02-05 10:00:36 +00:00
( uint ) rt ,
2021-01-13 20:16:47 +00:00
RoadTypeIsTram ( rt ) ? " Tram " : " Road " ,
rti - > label > > 24 , rti - > label > > 16 , rti - > label > > 8 , rti - > label ,
HasBit ( rti - > flags , ROTF_CATENARY ) ? ' c ' : ' - ' ,
HasBit ( rti - > flags , ROTF_NO_LEVEL_CROSSING ) ? ' l ' : ' - ' ,
HasBit ( rti - > flags , ROTF_NO_HOUSES ) ? ' X ' : ' - ' ,
HasBit ( rti - > flags , ROTF_HIDDEN ) ? ' h ' : ' - ' ,
HasBit ( rti - > flags , ROTF_TOWN_BUILD ) ? ' T ' : ' - ' ,
BSWAP32 ( grfid ) ,
GetStringPtr ( rti - > strings . name )
) ;
}
for ( const auto & grf : grfs ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " GRF: {:08X} = {} " , BSWAP32 ( grf . first ) , grf . second - > filename ) ;
2021-01-13 20:16:47 +00:00
}
}
static void ConDumpRailTypes ( )
{
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Flags: " ) ;
IConsolePrint ( CC_DEFAULT , " c = catenary " ) ;
IConsolePrint ( CC_DEFAULT , " l = no level crossings " ) ;
IConsolePrint ( CC_DEFAULT , " h = hidden " ) ;
IConsolePrint ( CC_DEFAULT , " s = no sprite combine " ) ;
IConsolePrint ( CC_DEFAULT , " a = always allow 90 degree turns " ) ;
IConsolePrint ( CC_DEFAULT , " d = always disallow 90 degree turns " ) ;
2021-01-13 20:16:47 +00:00
std : : map < uint32 , const GRFFile * > grfs ;
for ( RailType rt = RAILTYPE_BEGIN ; rt < RAILTYPE_END ; rt + + ) {
const RailtypeInfo * rti = GetRailTypeInfo ( rt ) ;
if ( rti - > label = = 0 ) continue ;
uint32 grfid = 0 ;
const GRFFile * grf = rti - > grffile [ RTSG_GROUND ] ;
if ( grf ! = nullptr ) {
grfid = grf - > grfid ;
grfs . emplace ( grfid , grf ) ;
}
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " {:02d} {:c}{:c}{:c}{:c}, Flags: {}{}{}{}{}{}, GRF: {:08X}, {} " ,
2021-02-05 10:00:36 +00:00
( uint ) rt ,
2021-01-13 20:16:47 +00:00
rti - > label > > 24 , rti - > label > > 16 , rti - > label > > 8 , rti - > label ,
HasBit ( rti - > flags , RTF_CATENARY ) ? ' c ' : ' - ' ,
HasBit ( rti - > flags , RTF_NO_LEVEL_CROSSING ) ? ' l ' : ' - ' ,
HasBit ( rti - > flags , RTF_HIDDEN ) ? ' h ' : ' - ' ,
HasBit ( rti - > flags , RTF_NO_SPRITE_COMBINE ) ? ' s ' : ' - ' ,
HasBit ( rti - > flags , RTF_ALLOW_90DEG ) ? ' a ' : ' - ' ,
HasBit ( rti - > flags , RTF_DISALLOW_90DEG ) ? ' d ' : ' - ' ,
BSWAP32 ( grfid ) ,
GetStringPtr ( rti - > strings . name )
) ;
}
for ( const auto & grf : grfs ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " GRF: {:08X} = {} " , BSWAP32 ( grf . first ) , grf . second - > filename ) ;
2021-01-13 20:16:47 +00:00
}
}
static void ConDumpCargoTypes ( )
{
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " Cargo classes: " ) ;
IConsolePrint ( CC_DEFAULT , " p = passenger " ) ;
IConsolePrint ( CC_DEFAULT , " m = mail " ) ;
IConsolePrint ( CC_DEFAULT , " x = express " ) ;
IConsolePrint ( CC_DEFAULT , " a = armoured " ) ;
IConsolePrint ( CC_DEFAULT , " b = bulk " ) ;
IConsolePrint ( CC_DEFAULT , " g = piece goods " ) ;
IConsolePrint ( CC_DEFAULT , " l = liquid " ) ;
IConsolePrint ( CC_DEFAULT , " r = refrigerated " ) ;
IConsolePrint ( CC_DEFAULT , " h = hazardous " ) ;
IConsolePrint ( CC_DEFAULT , " c = covered/sheltered " ) ;
IConsolePrint ( CC_DEFAULT , " S = special " ) ;
2021-01-13 20:16:47 +00:00
std : : map < uint32 , const GRFFile * > grfs ;
for ( CargoID i = 0 ; i < NUM_CARGO ; i + + ) {
const CargoSpec * spec = CargoSpec : : Get ( i ) ;
if ( ! spec - > IsValid ( ) ) continue ;
uint32 grfid = 0 ;
const GRFFile * grf = spec - > grffile ;
if ( grf ! = nullptr ) {
grfid = grf - > grfid ;
grfs . emplace ( grfid , grf ) ;
}
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " {:02d} Bit: {:2d}, Label: {:c}{:c}{:c}{:c}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {} " ,
2021-02-05 10:00:36 +00:00
( uint ) i ,
2021-01-13 20:16:47 +00:00
spec - > bitnum ,
spec - > label > > 24 , spec - > label > > 16 , spec - > label > > 8 , spec - > label ,
spec - > callback_mask ,
( spec - > classes & CC_PASSENGERS ) ! = 0 ? ' p ' : ' - ' ,
( spec - > classes & CC_MAIL ) ! = 0 ? ' m ' : ' - ' ,
( spec - > classes & CC_EXPRESS ) ! = 0 ? ' x ' : ' - ' ,
( spec - > classes & CC_ARMOURED ) ! = 0 ? ' a ' : ' - ' ,
( spec - > classes & CC_BULK ) ! = 0 ? ' b ' : ' - ' ,
( spec - > classes & CC_PIECE_GOODS ) ! = 0 ? ' g ' : ' - ' ,
( spec - > classes & CC_LIQUID ) ! = 0 ? ' l ' : ' - ' ,
( spec - > classes & CC_REFRIGERATED ) ! = 0 ? ' r ' : ' - ' ,
( spec - > classes & CC_HAZARDOUS ) ! = 0 ? ' h ' : ' - ' ,
( spec - > classes & CC_COVERED ) ! = 0 ? ' c ' : ' - ' ,
( spec - > classes & CC_SPECIAL ) ! = 0 ? ' S ' : ' - ' ,
BSWAP32 ( grfid ) ,
GetStringPtr ( spec - > name )
) ;
}
for ( const auto & grf : grfs ) {
2021-06-12 19:33:01 +00:00
IConsolePrint ( CC_DEFAULT , " GRF: {:08X} = {} " , BSWAP32 ( grf . first ) , grf . second - > filename ) ;
2021-01-13 20:16:47 +00:00
}
}
DEF_CONSOLE_CMD ( ConDumpInfo )
{
if ( argc ! = 2 ) {
2021-06-12 19:37:19 +00:00
IConsolePrint ( CC_HELP , " Dump debugging information. " ) ;
IConsolePrint ( CC_HELP , " Usage: 'dump_info roadtypes|railtypes|cargotypes'. " ) ;
IConsolePrint ( CC_HELP , " Show information about road/tram types, rail types or cargo types. " ) ;
2021-01-13 20:16:47 +00:00
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " roadtypes " ) = = 0 ) {
ConDumpRoadTypes ( ) ;
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " railtypes " ) = = 0 ) {
ConDumpRailTypes ( ) ;
return true ;
}
if ( strcasecmp ( argv [ 1 ] , " cargotypes " ) = = 0 ) {
ConDumpCargoTypes ( ) ;
return true ;
}
return false ;
}
2010-02-10 17:32:39 +00:00
/*******************************
* console command registration
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-09-12 21:49:38 +00:00
2007-03-07 11:47:46 +00:00
void IConsoleStdLibRegister ( )
2004-09-12 21:49:38 +00:00
{
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " debug_level " , ConDebugLevel ) ;
IConsole : : CmdRegister ( " echo " , ConEcho ) ;
IConsole : : CmdRegister ( " echoc " , ConEchoC ) ;
IConsole : : CmdRegister ( " exec " , ConExec ) ;
IConsole : : CmdRegister ( " exit " , ConExit ) ;
IConsole : : CmdRegister ( " part " , ConPart ) ;
IConsole : : CmdRegister ( " help " , ConHelp ) ;
IConsole : : CmdRegister ( " info_cmd " , ConInfoCmd ) ;
IConsole : : CmdRegister ( " list_cmds " , ConListCommands ) ;
IConsole : : CmdRegister ( " list_aliases " , ConListAliases ) ;
IConsole : : CmdRegister ( " newgame " , ConNewGame ) ;
IConsole : : CmdRegister ( " restart " , ConRestart ) ;
IConsole : : CmdRegister ( " reload " , ConReload ) ;
IConsole : : CmdRegister ( " getseed " , ConGetSeed ) ;
IConsole : : CmdRegister ( " getdate " , ConGetDate ) ;
IConsole : : CmdRegister ( " getsysdate " , ConGetSysDate ) ;
IConsole : : CmdRegister ( " quit " , ConExit ) ;
IConsole : : CmdRegister ( " resetengines " , ConResetEngines , ConHookNoNetwork ) ;
IConsole : : CmdRegister ( " reset_enginepool " , ConResetEnginePool , ConHookNoNetwork ) ;
IConsole : : CmdRegister ( " return " , ConReturn ) ;
IConsole : : CmdRegister ( " screenshot " , ConScreenShot ) ;
IConsole : : CmdRegister ( " script " , ConScript ) ;
IConsole : : CmdRegister ( " scrollto " , ConScrollToTile ) ;
IConsole : : CmdRegister ( " alias " , ConAlias ) ;
IConsole : : CmdRegister ( " load " , ConLoad ) ;
IConsole : : CmdRegister ( " rm " , ConRemove ) ;
IConsole : : CmdRegister ( " save " , ConSave ) ;
IConsole : : CmdRegister ( " saveconfig " , ConSaveConfig ) ;
IConsole : : CmdRegister ( " ls " , ConListFiles ) ;
IConsole : : CmdRegister ( " cd " , ConChangeDirectory ) ;
IConsole : : CmdRegister ( " pwd " , ConPrintWorkingDirectory ) ;
IConsole : : CmdRegister ( " clear " , ConClearBuffer ) ;
IConsole : : CmdRegister ( " setting " , ConSetting ) ;
IConsole : : CmdRegister ( " setting_newgame " , ConSettingNewgame ) ;
IConsole : : CmdRegister ( " list_settings " , ConListSettings ) ;
IConsole : : CmdRegister ( " gamelog " , ConGamelogPrint ) ;
IConsole : : CmdRegister ( " rescan_newgrf " , ConRescanNewGRF ) ;
2021-09-26 21:11:22 +00:00
IConsole : : CmdRegister ( " list_dirs " , ConListDirs ) ;
2021-04-24 13:19:57 +00:00
IConsole : : AliasRegister ( " dir " , " ls " ) ;
IConsole : : AliasRegister ( " del " , " rm %+ " ) ;
IConsole : : AliasRegister ( " newmap " , " newgame " ) ;
IConsole : : AliasRegister ( " patch " , " setting %+ " ) ;
IConsole : : AliasRegister ( " set " , " setting %+ " ) ;
IConsole : : AliasRegister ( " set_newgame " , " setting_newgame %+ " ) ;
IConsole : : AliasRegister ( " list_patches " , " list_settings %+ " ) ;
IConsole : : AliasRegister ( " developer " , " setting developer %+ " ) ;
IConsole : : CmdRegister ( " list_ai_libs " , ConListAILibs ) ;
IConsole : : CmdRegister ( " list_ai " , ConListAI ) ;
IConsole : : CmdRegister ( " reload_ai " , ConReloadAI ) ;
IConsole : : CmdRegister ( " rescan_ai " , ConRescanAI ) ;
IConsole : : CmdRegister ( " start_ai " , ConStartAI ) ;
IConsole : : CmdRegister ( " stop_ai " , ConStopAI ) ;
IConsole : : CmdRegister ( " list_game " , ConListGame ) ;
IConsole : : CmdRegister ( " list_game_libs " , ConListGameLibs ) ;
IConsole : : CmdRegister ( " rescan_game " , ConRescanGame ) ;
IConsole : : CmdRegister ( " companies " , ConCompanies ) ;
IConsole : : AliasRegister ( " players " , " companies " ) ;
2012-12-09 16:53:41 +00:00
2010-02-10 17:32:39 +00:00
/* networking functions */
Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.
Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.
A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.
With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.
All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 16:01:13 +00:00
2009-05-24 17:49:08 +00:00
/* Content downloading is only available with ZLIB */
# if defined(WITH_ZLIB)
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " content " , ConContent ) ;
2009-05-24 17:49:08 +00:00
# endif /* defined(WITH_ZLIB) */
2006-01-25 18:40:12 +00:00
2005-05-02 15:52:19 +00:00
/*** Networking commands ***/
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " say " , ConSay , ConHookNeedNetwork ) ;
IConsole : : CmdRegister ( " say_company " , ConSayCompany , ConHookNeedNetwork ) ;
IConsole : : AliasRegister ( " say_player " , " say_company %+ " ) ;
IConsole : : CmdRegister ( " say_client " , ConSayClient , ConHookNeedNetwork ) ;
IConsole : : CmdRegister ( " connect " , ConNetworkConnect , ConHookClientOnly ) ;
IConsole : : CmdRegister ( " clients " , ConNetworkClients , ConHookNeedNetwork ) ;
IConsole : : CmdRegister ( " status " , ConStatus , ConHookServerOnly ) ;
IConsole : : CmdRegister ( " server_info " , ConServerInfo , ConHookServerOnly ) ;
IConsole : : AliasRegister ( " info " , " server_info " ) ;
IConsole : : CmdRegister ( " reconnect " , ConNetworkReconnect , ConHookClientOnly ) ;
IConsole : : CmdRegister ( " rcon " , ConRcon , ConHookNeedNetwork ) ;
IConsole : : CmdRegister ( " join " , ConJoinCompany , ConHookNeedNetwork ) ;
IConsole : : AliasRegister ( " spectate " , " join 255 " ) ;
IConsole : : CmdRegister ( " move " , ConMoveClient , ConHookServerOnly ) ;
IConsole : : CmdRegister ( " reset_company " , ConResetCompany , ConHookServerOnly ) ;
IConsole : : AliasRegister ( " clean_company " , " reset_company %A " ) ;
IConsole : : CmdRegister ( " client_name " , ConClientNickChange , ConHookServerOnly ) ;
IConsole : : CmdRegister ( " kick " , ConKick , ConHookServerOnly ) ;
IConsole : : CmdRegister ( " ban " , ConBan , ConHookServerOnly ) ;
IConsole : : CmdRegister ( " unban " , ConUnBan , ConHookServerOnly ) ;
IConsole : : CmdRegister ( " banlist " , ConBanList , ConHookServerOnly ) ;
2021-06-10 18:11:50 +00:00
IConsole : : CmdRegister ( " pause " , ConPauseGame , ConHookServerOrNoNetwork ) ;
IConsole : : CmdRegister ( " unpause " , ConUnpauseGame , ConHookServerOrNoNetwork ) ;
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " company_pw " , ConCompanyPassword , ConHookNeedNetwork ) ;
IConsole : : AliasRegister ( " company_password " , " company_pw %+ " ) ;
IConsole : : AliasRegister ( " net_frame_freq " , " setting frame_freq %+ " ) ;
IConsole : : AliasRegister ( " net_sync_freq " , " setting sync_freq %+ " ) ;
IConsole : : AliasRegister ( " server_pw " , " setting server_password %+ " ) ;
IConsole : : AliasRegister ( " server_password " , " setting server_password %+ " ) ;
IConsole : : AliasRegister ( " rcon_pw " , " setting rcon_password %+ " ) ;
IConsole : : AliasRegister ( " rcon_password " , " setting rcon_password %+ " ) ;
IConsole : : AliasRegister ( " name " , " setting client_name %+ " ) ;
IConsole : : AliasRegister ( " server_name " , " setting server_name %+ " ) ;
IConsole : : AliasRegister ( " server_port " , " setting server_port %+ " ) ;
IConsole : : AliasRegister ( " max_clients " , " setting max_clients %+ " ) ;
IConsole : : AliasRegister ( " max_companies " , " setting max_companies %+ " ) ;
IConsole : : AliasRegister ( " max_join_time " , " setting max_join_time %+ " ) ;
IConsole : : AliasRegister ( " pause_on_join " , " setting pause_on_join %+ " ) ;
IConsole : : AliasRegister ( " autoclean_companies " , " setting autoclean_companies %+ " ) ;
IConsole : : AliasRegister ( " autoclean_protected " , " setting autoclean_protected %+ " ) ;
IConsole : : AliasRegister ( " autoclean_unprotected " , " setting autoclean_unprotected %+ " ) ;
IConsole : : AliasRegister ( " restart_game_year " , " setting restart_game_year %+ " ) ;
IConsole : : AliasRegister ( " min_players " , " setting min_active_clients %+ " ) ;
IConsole : : AliasRegister ( " reload_cfg " , " setting reload_cfg %+ " ) ;
2004-09-12 21:49:38 +00:00
2009-03-15 00:32:18 +00:00
/* debugging stuff */
2004-12-05 12:25:25 +00:00
# ifdef _DEBUG
IConsoleDebugLibRegister ( ) ;
# endif
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " fps " , ConFramerate ) ;
IConsole : : CmdRegister ( " fps_wnd " , ConFramerateWindow ) ;
2010-03-24 20:47:03 +00:00
/* NewGRF development stuff */
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " reload_newgrfs " , ConNewGRFReload , ConHookNewGRFDeveloperTool ) ;
IConsole : : CmdRegister ( " newgrf_profile " , ConNewGRFProfile , ConHookNewGRFDeveloperTool ) ;
2021-01-13 20:16:47 +00:00
2021-04-24 13:19:57 +00:00
IConsole : : CmdRegister ( " dump_info " , ConDumpInfo ) ;
2004-09-12 21:49:38 +00:00
}