summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_info.cpp9
-rw-r--r--src/ai/ai_info.hpp8
-rw-r--r--src/ai/ai_info_dummy.cpp1
-rw-r--r--src/ai/ai_scanner.cpp7
4 files changed, 23 insertions, 2 deletions
diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp
index b2c653826..a9bf22eae 100644
--- a/src/ai/ai_info.cpp
+++ b/src/ai/ai_info.cpp
@@ -42,6 +42,12 @@ const char *AIFileInfo::GetName()
return this->name;
}
+const char *AIFileInfo::GetShortName()
+{
+ if (this->short_name == NULL) this->short_name = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetShortName");
+ return this->short_name;
+}
+
const char *AIFileInfo::GetDescription()
{
if (this->description == NULL) this->description = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetDescription");
@@ -106,7 +112,7 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
{
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
char error[1024];
- snprintf(error, sizeof(error), "your AIFileInfo doesn't have the method '%s'", name);
+ snprintf(error, sizeof(error), "your info.nut/library.nut doesn't have the method '%s'", name);
this->engine->ThrowError(error);
*res = SQ_ERROR;
}
@@ -127,6 +133,7 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
/* Check if all needed fields are there */
info->CheckMethods(&res, "GetAuthor");
info->CheckMethods(&res, "GetName");
+ info->CheckMethods(&res, "GetShortName");
info->CheckMethods(&res, "GetDescription");
info->CheckMethods(&res, "GetVersion");
info->CheckMethods(&res, "GetDate");
diff --git a/src/ai/ai_info.hpp b/src/ai/ai_info.hpp
index 71691ae3a..223fbeaf3 100644
--- a/src/ai/ai_info.hpp
+++ b/src/ai/ai_info.hpp
@@ -35,7 +35,7 @@ public:
friend class AIInfo;
friend class AILibrary;
- AIFileInfo() : author(NULL), name(NULL), description(NULL), date(NULL), instance_name(NULL) {};
+ AIFileInfo() : author(NULL), name(NULL), short_name(NULL), description(NULL), date(NULL), instance_name(NULL) {};
~AIFileInfo();
/**
@@ -49,6 +49,11 @@ public:
const char *GetName();
/**
+ * Get the 4 character long short name of the AI.
+ */
+ const char *GetShortName();
+
+ /**
* Get the description of the AI.
*/
const char *GetDescription();
@@ -106,6 +111,7 @@ private:
class AIScanner *base;
const char *author;
const char *name;
+ const char *short_name;
const char *description;
const char *date;
const char *instance_name;
diff --git a/src/ai/ai_info_dummy.cpp b/src/ai/ai_info_dummy.cpp
index a060a0a65..7865c52b7 100644
--- a/src/ai/ai_info_dummy.cpp
+++ b/src/ai/ai_info_dummy.cpp
@@ -16,6 +16,7 @@ const SQChar dummy_script_info[] = _SC("
class DummyAI extends AIInfo { \n\
function GetAuthor() { return \"OpenTTD NoAI Developers Team\"; } \n\
function GetName() { return \"DummyAI\"; } \n\
+ function GetShortName() { return \"DUMM\"; } \n\
function GetDescription() { return \"A Dummy AI that is loaded when your ai/ dir is empty\"; }\n\
function GetVersion() { return 1; } \n\
function GetDate() { return \"2008-07-26\"; } \n\
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index 2a389fa9d..46a89511b 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -308,6 +308,13 @@ void AIScanner::RegisterAI(AIInfo *info)
{
const char *ai_name = info->GetDirName();
+ /* Check if GetShortName follows the rules */
+ if (strlen(info->GetShortName()) != 4) {
+ DEBUG(ai, 0, "The AI '%s' returned a string from GetShortName() which is not four characaters. Unable to load the AI.", info->GetDirName());
+ delete info;
+ return;
+ }
+
/* Check if we register twice; than the first always wins */
if (this->info_list.find(ai_name) != this->info_list.end()) {
/* In case they are not the same dir, give a warning */