(svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
--- a/src/ai/ai.cpp Sun Mar 18 18:06:45 2007 +0000
+++ b/src/ai/ai.cpp Sun Mar 18 18:37:45 2007 +0000
@@ -72,6 +72,7 @@
return;
}
_current_player = player;
+ AIObject::ResetInternalPlayerData();
AI_StartPlayer(player, _ai_player[player]);
}
--- a/src/ai/api/ai_object.cpp Sun Mar 18 18:06:45 2007 +0000
+++ b/src/ai/api/ai_object.cpp Sun Mar 18 18:37:45 2007 +0000
@@ -46,21 +46,18 @@
AIObject::AIDoCommandStruct *AIObject::GetDoCommandStruct(PlayerID player)
{
- static bool initialized = false;
/* Storage for data on per-AI level */
static AIObject::AIDoCommandStruct command_struct[MAX_PLAYERS];
- if (!initialized) {
- initialized = true;
- /* Set default values */
- for (int i = 0; i < MAX_PLAYERS; i++) {
- command_struct[i].mode = NULL;
- command_struct[i].delay = 1;
- command_struct[i].costs = 0;
- }
- }
+ return &command_struct[player];
+}
- return &command_struct[player];
+void AIObject::ResetInternalPlayerData()
+{
+ AIObject::AIDoCommandStruct *command_struct = GetDoCommandStruct(_current_player);
+ command_struct->mode = NULL;
+ command_struct->delay = 1;
+ command_struct->costs = 0;
}
bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
--- a/src/ai/api/ai_object.hpp Sun Mar 18 18:06:45 2007 +0000
+++ b/src/ai/api/ai_object.hpp Sun Mar 18 18:37:45 2007 +0000
@@ -69,6 +69,13 @@
* Get the delay of the DoCommand.
*/
uint GetDoCommandDelay();
+
+public:
+ /**
+ * If an AI starts, some internals needs to be resetted. This function
+ * takes care of that.
+ */
+ static void ResetInternalPlayerData();
};
#endif /* AI_OBJECT_HPP */