(svn r12603) [NoAI] -Add: 'support' for telling AIs that the last error message was a NewGRF generated message, so we can't say anything sensible about the real error message.
--- a/src/ai/api/ai_error.cpp Mon Apr 07 12:30:28 2008 +0000
+++ b/src/ai/api/ai_error.cpp Mon Apr 07 12:31:50 2008 +0000
@@ -4,6 +4,7 @@
#include "ai_error.hpp"
#include "table/strings.h"
+#include "../../core/bitmath_func.hpp"
AIError::AIErrorMap AIError::error_map = AIError::AIErrorMap();
AIError::AIErrorMapString AIError::error_map_string = AIError::AIErrorMapString();
@@ -20,6 +21,25 @@
/* static */ AIErrorType AIError::StringToError(StringID internal_string_id)
{
+ uint index = GB(internal_string_id, 11, 5);
+ switch (GB(internal_string_id, 11, 5)) {
+ case 26: case 28: case 29: case 30: // NewGRF strings.
+ return ERR_NEWGRF_SUPPLIED_ERROR;
+
+ /* DO NOT SWAP case 14 and 4 because that will break StringToError due
+ * to the index dependency that relies on FALL THROUGHs. */
+ case 14: if (index < 0xE4) break; // Player name
+ case 4: if (index < 0xC0) break; // Town name
+ case 15: // Custom name
+ case 31: // Dynamic strings
+ /* These strings are 'random' and have no meaning.
+ * They actually shouldn't even be returned as error messages. */
+ return ERR_UNKNOWN;
+
+ default:
+ break;
+ }
+
AIErrorMap::iterator it = error_map.find(internal_string_id);
if (it == error_map.end()) return ERR_UNKNOWN;
return (*it).second;
--- a/src/ai/api/ai_error.hpp Mon Apr 07 12:30:28 2008 +0000
+++ b/src/ai/api/ai_error.hpp Mon Apr 07 12:31:50 2008 +0000
@@ -53,6 +53,8 @@
ERR_UNKNOWN, // []
/** If a precondition is not met */
ERR_PRECONDITION_FAILED, // []
+ /** An error returned by a NewGRF. No possibility to get the exact error in an AI readable format */
+ ERR_NEWGRF_SUPPLIED_ERROR, // []
/** Base for general errors */
ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE,
--- a/src/ai/api/ai_error.hpp.sq Mon Apr 07 12:30:28 2008 +0000
+++ b/src/ai/api/ai_error.hpp.sq Mon Apr 07 12:31:50 2008 +0000
@@ -29,6 +29,7 @@
SQAIError.DefSQConst(engine, AIError::ERR_NONE, "ERR_NONE");
SQAIError.DefSQConst(engine, AIError::ERR_UNKNOWN, "ERR_UNKNOWN");
SQAIError.DefSQConst(engine, AIError::ERR_PRECONDITION_FAILED, "ERR_PRECONDITION_FAILED");
+ SQAIError.DefSQConst(engine, AIError::ERR_NEWGRF_SUPPLIED_ERROR, "ERR_NEWGRF_SUPPLIED_ERROR");
SQAIError.DefSQConst(engine, AIError::ERR_GENERAL_BASE, "ERR_GENERAL_BASE");
SQAIError.DefSQConst(engine, AIError::ERR_NOT_ENOUGH_CASH, "ERR_NOT_ENOUGH_CASH");
SQAIError.DefSQConst(engine, AIError::ERR_LOCAL_AUTHORITY_REFUSES, "ERR_LOCAL_AUTHORITY_REFUSES");
@@ -66,6 +67,7 @@
AIError::RegisterErrorMapString(AIError::ERR_NONE, "ERR_NONE");
AIError::RegisterErrorMapString(AIError::ERR_UNKNOWN, "ERR_UNKNOWN");
AIError::RegisterErrorMapString(AIError::ERR_PRECONDITION_FAILED, "ERR_PRECONDITION_FAILED");
+ AIError::RegisterErrorMapString(AIError::ERR_NEWGRF_SUPPLIED_ERROR, "ERR_NEWGRF_SUPPLIED_ERROR");
AIError::RegisterErrorMapString(AIError::ERR_NOT_ENOUGH_CASH, "ERR_NOT_ENOUGH_CASH");
AIError::RegisterErrorMapString(AIError::ERR_LOCAL_AUTHORITY_REFUSES, "ERR_LOCAL_AUTHORITY_REFUSES");
AIError::RegisterErrorMapString(AIError::ERR_ALREADY_BUILT, "ERR_ALREADY_BUILT");