Merge branch 'openttd'
This commit is contained in:
@@ -42,6 +42,10 @@
|
||||
#include "game/game.hpp"
|
||||
#include "table/strings.h"
|
||||
#include "walltime_func.h"
|
||||
#include "company_cmd.h"
|
||||
#include "misc_cmd.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "citymania/cm_console_cmds.hpp"
|
||||
|
||||
@@ -253,6 +257,59 @@ DEF_CONSOLE_CMD(ConResetTile)
|
||||
}
|
||||
#endif /* _DEBUG */
|
||||
|
||||
/**
|
||||
* Zoom map to given level.
|
||||
* param level As defined by ZoomLevel and as limited by zoom_min/zoom_max from GUISettings.
|
||||
* @return True when either console help was shown or a proper amount of parameters given.
|
||||
*/
|
||||
DEF_CONSOLE_CMD(ConZoomToLevel)
|
||||
{
|
||||
switch (argc) {
|
||||
case 0:
|
||||
IConsolePrint(CC_HELP, "Set the current zoom level of the main viewport.");
|
||||
IConsolePrint(CC_HELP, "Usage: 'zoomto <level>'.");
|
||||
IConsolePrint(
|
||||
CC_HELP,
|
||||
ZOOM_LVL_MIN < _settings_client.gui.zoom_min ?
|
||||
"The lowest zoom-in level allowed by current client settings is {}." :
|
||||
"The lowest supported zoom-in level is {}.",
|
||||
std::max(ZOOM_LVL_MIN, _settings_client.gui.zoom_min)
|
||||
);
|
||||
IConsolePrint(
|
||||
CC_HELP,
|
||||
_settings_client.gui.zoom_max < ZOOM_LVL_MAX ?
|
||||
"The highest zoom-out level allowed by current client settings is {}." :
|
||||
"The highest supported zoom-out level is {}.",
|
||||
std::min(_settings_client.gui.zoom_max, ZOOM_LVL_MAX)
|
||||
);
|
||||
return true;
|
||||
|
||||
case 2: {
|
||||
uint32 level;
|
||||
if (GetArgumentInteger(&level, argv[1])) {
|
||||
if (level < ZOOM_LVL_MIN) {
|
||||
IConsolePrint(CC_ERROR, "Zoom-in levels below {} are not supported.", ZOOM_LVL_MIN);
|
||||
} else if (level < _settings_client.gui.zoom_min) {
|
||||
IConsolePrint(CC_ERROR, "Current client settings do not allow zooming in below level {}.", _settings_client.gui.zoom_min);
|
||||
} else if (level > ZOOM_LVL_MAX) {
|
||||
IConsolePrint(CC_ERROR, "Zoom-in levels above {} are not supported.", ZOOM_LVL_MAX);
|
||||
} else if (level > _settings_client.gui.zoom_max) {
|
||||
IConsolePrint(CC_ERROR, "Current client settings do not allow zooming out beyond level {}.", _settings_client.gui.zoom_max);
|
||||
} else {
|
||||
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||
Viewport *vp = w->viewport;
|
||||
while (vp->zoom > level) DoZoomInOutWindow(ZOOM_IN, w);
|
||||
while (vp->zoom < level) DoZoomInOutWindow(ZOOM_OUT, w);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scroll to a tile on the map.
|
||||
* param x tile number or tile x coordinate.
|
||||
@@ -264,34 +321,44 @@ DEF_CONSOLE_CMD(ConResetTile)
|
||||
*/
|
||||
DEF_CONSOLE_CMD(ConScrollToTile)
|
||||
{
|
||||
switch (argc) {
|
||||
case 0:
|
||||
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).");
|
||||
return true;
|
||||
if (argc == 0) {
|
||||
IConsolePrint(CC_HELP, "Center the screen on a given tile.");
|
||||
IConsolePrint(CC_HELP, "Usage: 'scrollto [instant] <tile>' or 'scrollto [instant] <x> <y>'.");
|
||||
IConsolePrint(CC_HELP, "Numbers can be either decimal (34161) or hexadecimal (0x4a5B).");
|
||||
IConsolePrint(CC_HELP, "'instant' will immediately move and redraw viewport without smooth scrolling.");
|
||||
return true;
|
||||
}
|
||||
if (argc < 2) return false;
|
||||
|
||||
case 2: {
|
||||
uint32 arg_index = 1;
|
||||
bool instant = false;
|
||||
if (strcmp(argv[arg_index], "instant") == 0) {
|
||||
++arg_index;
|
||||
instant = true;
|
||||
}
|
||||
|
||||
switch (argc - arg_index) {
|
||||
case 1: {
|
||||
uint32 result;
|
||||
if (GetArgumentInteger(&result, argv[1])) {
|
||||
if (GetArgumentInteger(&result, argv[arg_index])) {
|
||||
if (result >= MapSize()) {
|
||||
IConsolePrint(CC_ERROR, "Tile does not exist.");
|
||||
return true;
|
||||
}
|
||||
ScrollMainWindowToTile((TileIndex)result);
|
||||
ScrollMainWindowToTile((TileIndex)result, instant);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: {
|
||||
case 2: {
|
||||
uint32 x, y;
|
||||
if (GetArgumentInteger(&x, argv[1]) && GetArgumentInteger(&y, argv[2])) {
|
||||
if (GetArgumentInteger(&x, argv[arg_index]) && GetArgumentInteger(&y, argv[arg_index + 1])) {
|
||||
if (x >= MapSizeX() || y >= MapSizeY()) {
|
||||
IConsolePrint(CC_ERROR, "Tile does not exist.");
|
||||
return true;
|
||||
}
|
||||
ScrollMainWindowToTile(TileXY(x, y));
|
||||
ScrollMainWindowToTile(TileXY(x, y), instant);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -632,7 +699,7 @@ DEF_CONSOLE_CMD(ConPauseGame)
|
||||
}
|
||||
|
||||
if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
|
||||
DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
|
||||
Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
|
||||
if (!_networking) IConsolePrint(CC_DEFAULT, "Game paused.");
|
||||
} else {
|
||||
IConsolePrint(CC_DEFAULT, "Game is already paused.");
|
||||
@@ -654,7 +721,7 @@ DEF_CONSOLE_CMD(ConUnpauseGame)
|
||||
}
|
||||
|
||||
if ((_pause_mode & PM_PAUSED_NORMAL) != PM_UNPAUSED) {
|
||||
DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
|
||||
Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, false);
|
||||
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.");
|
||||
@@ -865,7 +932,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
|
||||
}
|
||||
|
||||
/* It is safe to remove this company */
|
||||
DoCommandP(0, CCA_DELETE | index << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
|
||||
Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, index, CRR_MANUAL, INVALID_CLIENT_ID);
|
||||
IConsolePrint(CC_DEFAULT, "Company deleted.");
|
||||
|
||||
return true;
|
||||
@@ -1097,58 +1164,65 @@ DEF_CONSOLE_CMD(ConReload)
|
||||
|
||||
/**
|
||||
* Print a text buffer line by line to the console. Lines are separated by '\n'.
|
||||
* @param buf The buffer to print.
|
||||
* @note All newlines are replace by '\0' characters.
|
||||
* @param full_string The multi-line string to print.
|
||||
*/
|
||||
static void PrintLineByLine(char *buf)
|
||||
static void PrintLineByLine(const std::string &full_string)
|
||||
{
|
||||
char *p = buf;
|
||||
/* Print output line by line */
|
||||
for (char *p2 = buf; *p2 != '\0'; p2++) {
|
||||
if (*p2 == '\n') {
|
||||
*p2 = '\0';
|
||||
IConsolePrint(CC_DEFAULT, p);
|
||||
p = p2 + 1;
|
||||
}
|
||||
std::istringstream in(full_string);
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
IConsolePrint(CC_DEFAULT, line.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConListAILibs)
|
||||
{
|
||||
char buf[4096];
|
||||
AI::GetConsoleLibraryList(buf, lastof(buf));
|
||||
if (argc == 0) {
|
||||
IConsolePrint(CC_HELP, "List installed AI libraries. Usage: 'list_ai_libs'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
PrintLineByLine(buf);
|
||||
const std::string output_str = AI::GetConsoleLibraryList();
|
||||
PrintLineByLine(output_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConListAI)
|
||||
{
|
||||
char buf[4096];
|
||||
AI::GetConsoleList(buf, lastof(buf));
|
||||
if (argc == 0) {
|
||||
IConsolePrint(CC_HELP, "List installed AIs. Usage: 'list_ai'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
PrintLineByLine(buf);
|
||||
const std::string output_str = AI::GetConsoleList();
|
||||
PrintLineByLine(output_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConListGameLibs)
|
||||
{
|
||||
char buf[4096];
|
||||
Game::GetConsoleLibraryList(buf, lastof(buf));
|
||||
if (argc == 0) {
|
||||
IConsolePrint(CC_HELP, "List installed Game Script libraries. Usage: 'list_game_libs'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
PrintLineByLine(buf);
|
||||
const std::string output_str = Game::GetConsoleLibraryList();
|
||||
PrintLineByLine(output_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConListGame)
|
||||
{
|
||||
char buf[4096];
|
||||
Game::GetConsoleList(buf, lastof(buf));
|
||||
if (argc == 0) {
|
||||
IConsolePrint(CC_HELP, "List installed Game Scripts. Usage: 'list_game'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
PrintLineByLine(buf);
|
||||
const std::string output_str = Game::GetConsoleList();
|
||||
PrintLineByLine(output_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1222,7 +1296,7 @@ DEF_CONSOLE_CMD(ConStartAI)
|
||||
}
|
||||
|
||||
/* Start a new AI company */
|
||||
DoCommandP(0, CCA_NEW_AI | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
|
||||
Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1258,8 +1332,8 @@ DEF_CONSOLE_CMD(ConReloadAI)
|
||||
}
|
||||
|
||||
/* First kill the company of the AI, then start a new one. This should start the current AI again */
|
||||
DoCommandP(0, CCA_DELETE | company_id << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
|
||||
DoCommandP(0, CCA_NEW_AI | company_id << 16, 0, CMD_COMPANY_CTRL);
|
||||
Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, company_id, CRR_MANUAL, INVALID_CLIENT_ID);
|
||||
Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, company_id, CRR_NONE, INVALID_CLIENT_ID);
|
||||
IConsolePrint(CC_DEFAULT, "AI reloaded.");
|
||||
|
||||
return true;
|
||||
@@ -1296,7 +1370,7 @@ DEF_CONSOLE_CMD(ConStopAI)
|
||||
}
|
||||
|
||||
/* Now kill the company of the AI. */
|
||||
DoCommandP(0, CCA_DELETE | company_id << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
|
||||
Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, company_id, CRR_MANUAL, INVALID_CLIENT_ID);
|
||||
IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
|
||||
|
||||
return true;
|
||||
@@ -1524,7 +1598,7 @@ DEF_CONSOLE_CMD(ConDebugLevel)
|
||||
if (argc == 1) {
|
||||
IConsolePrint(CC_DEFAULT, "Current debug-level: '{}'", GetDebugString());
|
||||
} else {
|
||||
SetDebugString(argv[1]);
|
||||
SetDebugString(argv[1], [](const char *err) { IConsolePrint(CC_ERROR, std::string(err)); });
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -2396,6 +2470,7 @@ void IConsoleStdLibRegister()
|
||||
IConsole::CmdRegister("return", ConReturn);
|
||||
IConsole::CmdRegister("screenshot", ConScreenShot);
|
||||
IConsole::CmdRegister("script", ConScript);
|
||||
IConsole::CmdRegister("zoomto", ConZoomToLevel);
|
||||
IConsole::CmdRegister("scrollto", ConScrollToTile);
|
||||
IConsole::CmdRegister("alias", ConAlias);
|
||||
IConsole::CmdRegister("load", ConLoad);
|
||||
|
||||
Reference in New Issue
Block a user