summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai.hpp2
-rw-r--r--src/ai/ai_core.cpp5
-rw-r--r--src/ai/ai_scanner.cpp13
-rw-r--r--src/ai/ai_scanner.hpp5
-rw-r--r--src/console_cmds.cpp34
5 files changed, 52 insertions, 7 deletions
diff --git a/src/ai/ai.hpp b/src/ai/ai.hpp
index f84175864..67ce470cd 100644
--- a/src/ai/ai.hpp
+++ b/src/ai/ai.hpp
@@ -126,6 +126,8 @@ public:
/** Wrapper function for AIScanner::GetAIConsoleList */
static char *GetConsoleList(char *p, const char *last);
+ /** Wrapper function for AIScanner::GetAIConsoleLibraryList */
+ static char *GetConsoleLibraryList(char *p, const char *last);
/** Wrapper function for AIScanner::GetAIInfoList */
static const AIInfoList *GetInfoList();
/** Wrapper function for AIScanner::GetUniqueAIInfoList */
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp
index b03e2a5ae..f2bfc4292 100644
--- a/src/ai/ai_core.cpp
+++ b/src/ai/ai_core.cpp
@@ -294,6 +294,11 @@ void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
return AI::ai_scanner->GetAIConsoleList(p, last);
}
+/* static */ char *AI::GetConsoleLibraryList(char *p, const char *last)
+{
+ return AI::ai_scanner->GetAIConsoleLibraryList(p, last);
+}
+
/* static */ const AIInfoList *AI::GetInfoList()
{
return AI::ai_scanner->GetAIInfoList();
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index 36607c217..90bdd99c7 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -343,6 +343,19 @@ char *AIScanner::GetAIConsoleList(char *p, const char *last) const
return p;
}
+char *AIScanner::GetAIConsoleLibraryList(char *p, const char *last) const
+{
+ p += seprintf(p, last, "List of AI Libraries:\n");
+ AILibraryList::const_iterator it = this->library_list.begin();
+ for (; it != this->library_list.end(); it++) {
+ AILibrary *i = (*it).second;
+ p += seprintf(p, last, "%10s (v%d): %s\n", i->GetName(), i->GetVersion(), i->GetDescription());
+ }
+ p += seprintf(p, last, "\n");
+
+ return p;
+}
+
#if defined(ENABLE_NETWORK)
#include "../network/network_content.h"
#include "../3rdparty/md5/md5.h"
diff --git a/src/ai/ai_scanner.hpp b/src/ai/ai_scanner.hpp
index fce07f651..117f6cd3e 100644
--- a/src/ai/ai_scanner.hpp
+++ b/src/ai/ai_scanner.hpp
@@ -59,6 +59,11 @@ public:
char *GetAIConsoleList(char *p, const char *last) const;
/**
+ * Get the list of available AI Libraries for the console.
+ */
+ char *GetAIConsoleLibraryList(char *p, const char *last) const;
+
+ /**
* Get the list of all registered AIs.
*/
const AIInfoList *GetAIInfoList() { return &this->info_list; }
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 4012c1c8a..a7d855ab2 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -995,21 +995,40 @@ DEF_CONSOLE_CMD(ConRestart)
}
#ifdef ENABLE_AI
-DEF_CONSOLE_CMD(ConListAI)
+/**
+ * Print a text buffer line by line to the console. Lines are seperated by '\n'.
+ * @param buf The buffer to print.
+ * @note All newlines are replace by '\0' characters.
+ */
+static void PrintLineByLine(char *buf)
{
- char buf[4096];
- char *p = &buf[0];
- p = AI::GetConsoleList(p, lastof(buf));
-
- p = &buf[0];
+ char *p = buf;
/* Print output line by line */
- for (char *p2 = &buf[0]; *p2 != '\0'; p2++) {
+ for (char *p2 = buf; *p2 != '\0'; p2++) {
if (*p2 == '\n') {
*p2 = '\0';
IConsolePrintF(CC_DEFAULT, "%s", p);
p = p2 + 1;
}
}
+}
+
+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);
return true;
}
@@ -1780,6 +1799,7 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("developer", "setting developer %+");
#ifdef ENABLE_AI
+ IConsoleCmdRegister("list_ai_libs", ConListAILibs);
IConsoleCmdRegister("list_ai", ConListAI);
IConsoleCmdRegister("reload_ai", ConReloadAI);
IConsoleCmdRegister("rescan_ai", ConRescanAI);