Browse Source

Fix AI player time tracking in final statistics

- Modified VictoryService to mark game end for all players (human and AI)
- Now iterates through all owners and marks game end for Player and AI types
- AI players will now show accurate play time instead of 0:00

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 4 months ago
parent
commit
f71aed51e3
1 changed files with 14 additions and 2 deletions
  1. 14 2
      game/systems/victory_service.cpp

+ 14 - 2
game/systems/victory_service.cpp

@@ -109,7 +109,13 @@ void VictoryService::checkVictoryConditions(Engine::Core::World &world) {
     m_victoryState = "victory";
     qInfo() << "VICTORY! Conditions met.";
 
-    m_statsRegistry.markGameEnd(m_localOwnerId);
+    const auto &allOwners = m_ownerRegistry.getAllOwners();
+    for (const auto &owner : allOwners) {
+      if (owner.type == Game::Systems::OwnerType::Player ||
+          owner.type == Game::Systems::OwnerType::AI) {
+        m_statsRegistry.markGameEnd(owner.ownerId);
+      }
+    }
 
     const auto *stats = m_statsRegistry.getStats(m_localOwnerId);
     if (stats) {
@@ -145,7 +151,13 @@ void VictoryService::checkDefeatConditions(Engine::Core::World &world) {
       m_victoryState = "defeat";
       qInfo() << "DEFEAT! Condition met.";
 
-      m_statsRegistry.markGameEnd(m_localOwnerId);
+      const auto &allOwners = m_ownerRegistry.getAllOwners();
+      for (const auto &owner : allOwners) {
+        if (owner.type == Game::Systems::OwnerType::Player ||
+            owner.type == Game::Systems::OwnerType::AI) {
+          m_statsRegistry.markGameEnd(owner.ownerId);
+        }
+      }
 
       const auto *stats = m_statsRegistry.getStats(m_localOwnerId);
       if (stats) {