src/ai/api/ai_object.cpp
branchnoai
changeset 9682 d031eb183733
parent 9680 5ed7bbfd51c7
child 9688 8ada9fe60ce0
--- a/src/ai/api/ai_object.cpp	Thu Jul 19 22:26:26 2007 +0000
+++ b/src/ai/api/ai_object.cpp	Thu Jul 19 22:39:43 2007 +0000
@@ -72,15 +72,22 @@
 	return AIObject::GetDoCommandStruct(_current_player)->new_sign_id;
 }
 
-void **AIObject::GetEventPointer()
+void *&AIObject::GetEventPointer()
 {
-	return &AIObject::GetDoCommandStruct(_current_player)->event_data;
+	return AIObject::GetDoCommandStruct(_current_player)->event_data;
 }
 
 AIObject::AIDoCommandStruct *AIObject::GetDoCommandStruct(PlayerID player)
 {
 	/* Storage for data on per-AI level */
 	static AIObject::AIDoCommandStruct command_struct[MAX_PLAYERS];
+	static bool initialized = false;
+
+	/* Make sure all memory is NULL when we start */
+	if (!initialized) {
+		initialized = true;
+		memset(&command_struct, 0, sizeof(command_struct));
+	}
 
 	return &command_struct[player];
 }
@@ -91,6 +98,8 @@
 	command_struct->mode = NULL;
 	command_struct->delay = 1;
 	command_struct->costs = CommandCost();
+	if (command_struct->event_data != NULL) AIEventController::FreeEventPointer();
+	command_struct->event_data = NULL;
 }
 
 bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint procc)