(svn r12554) [NoAI] -Codechange: add more typing information.
--- a/src/ai/api/ai_error.cpp Thu Apr 03 22:18:52 2008 +0000
+++ b/src/ai/api/ai_error.cpp Thu Apr 03 22:32:28 2008 +0000
@@ -8,7 +8,7 @@
AIError::AIErrorMap AIError::error_map = AIError::AIErrorMap();
AIError::AIErrorMapString AIError::error_map_string = AIError::AIErrorMapString();
-/* static */ uint AIError::GetLastError()
+/* static */ AIErrorType AIError::GetLastError()
{
return AIObject::GetLastError();
}
@@ -18,19 +18,19 @@
return (*error_map_string.find(AIError::GetLastError())).second;
}
-/* static */ uint AIError::StringToError(uint internal_string_id)
+/* static */ AIErrorType AIError::StringToError(StringID internal_string_id)
{
AIErrorMap::iterator it = error_map.find(internal_string_id);
if (it == error_map.end()) return ERR_UNKNOWN;
return (*it).second;
}
-/* static */ void AIError::RegisterErrorMap(uint internal_string_id, uint ai_error_msg)
+/* static */ void AIError::RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg)
{
error_map[internal_string_id] = ai_error_msg;
}
-/* static */ void AIError::RegisterErrorMapString(uint ai_error_msg, const char *message)
+/* static */ void AIError::RegisterErrorMapString(AIErrorType ai_error_msg, const char *message)
{
error_map_string[ai_error_msg] = message;
}
--- a/src/ai/api/ai_error.hpp Thu Apr 03 22:18:52 2008 +0000
+++ b/src/ai/api/ai_error.hpp Thu Apr 03 22:32:28 2008 +0000
@@ -71,7 +71,7 @@
* Get the last error.
* @return An ErrorMessages enum value.
*/
- static uint GetLastError();
+ static AIErrorType GetLastError();
/**
* Get the last error in string format (for human readability).
@@ -85,7 +85,7 @@
* @param internal_string_id The string to convert.
* @return The NoAI equivalent error message.
*/
- static uint StringToError(uint internal_string_id);
+ static AIErrorType StringToError(StringID internal_string_id);
/**
* Map an internal OpenTTD error message to it's NoAI equivalent.
@@ -93,7 +93,7 @@
* @param internal_string_id The OpenTTD StringID used for an error.
* @param ai_error_msg The NoAI equivalent error message.
*/
- static void RegisterErrorMap(uint internal_string_id, uint ai_error_msg);
+ static void RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg);
/**
* Map an internal OpenTTD error message to it's NoAI equivalent.
@@ -101,11 +101,11 @@
* @param ai_error_msg The NoAI error message representation.
* @param message The string representation of this error message, used for debug purposes.
*/
- static void RegisterErrorMapString(uint ai_error_msg, const char *message);
+ static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
private:
- typedef std::map<uint, uint> AIErrorMap;
- typedef std::map<uint, const char *> AIErrorMapString;
+ typedef std::map<StringID, AIErrorType> AIErrorMap;
+ typedef std::map<AIErrorType, const char *> AIErrorMapString;
static AIErrorMap error_map;
static AIErrorMapString error_map_string;
--- a/src/ai/api/ai_object.cpp Thu Apr 03 22:18:52 2008 +0000
+++ b/src/ai/api/ai_object.cpp Thu Apr 03 22:32:28 2008 +0000
@@ -56,12 +56,12 @@
return GetDoCommandStruct(_current_player)->costs.GetCost();
}
-void AIObject::SetLastError(uint last_error)
+void AIObject::SetLastError(AIErrorType last_error)
{
GetDoCommandStruct(_current_player)->last_error = last_error;
}
-uint AIObject::GetLastError()
+AIErrorType AIObject::GetLastError()
{
return GetDoCommandStruct(_current_player)->last_error;
}
@@ -153,7 +153,7 @@
res = ::DoCommand(tile, p1, p2, flags, procc);
/* The command failed, so return */
if (::CmdFailed(res)) {
- AIObject::SetLastError(AIError::StringToError(_error_message));
+ SetLastError(AIError::StringToError(_error_message));
return false;
}
@@ -199,7 +199,7 @@
}
if (::CmdFailed(res)) {
- AIObject::SetLastError(AIError::StringToError(_error_message));
+ SetLastError(AIError::StringToError(_error_message));
return false;
}
--- a/src/ai/api/ai_object.hpp Thu Apr 03 22:18:52 2008 +0000
+++ b/src/ai/api/ai_object.hpp Thu Apr 03 22:32:28 2008 +0000
@@ -23,6 +23,11 @@
#endif
/**
+ * The type (an alias) for all errors the AI API knows.
+ */
+typedef uint AIErrorType;
+
+/**
* The callback function for Mode-classes.
*/
typedef bool (AIModeProc)(TileIndex tile, uint32 p1, uint32 p2, uint procc, CommandCost costs);
@@ -78,12 +83,12 @@
* Set the DoCommand last error.
* @note last_error is an ERR_* from a ErrorMessages enum.
*/
- static void SetLastError(uint last_error);
+ static void SetLastError(AIErrorType last_error);
/**
* Get the DoCommand last error.
*/
- static uint GetLastError();
+ static AIErrorType GetLastError();
/**
* Set the current mode of your AI to this proc.