diff --git a/hwe/compare/turn_state_snapshot.php b/hwe/compare/turn_state_snapshot.php index 5878fb86..1c9eee28 100644 --- a/hwe/compare/turn_state_snapshot.php +++ b/hwe/compare/turn_state_snapshot.php @@ -190,6 +190,7 @@ function comparisonTurnStateSnapshot(array $request): array $nationIds = comparisonIntegerList($observe['nationIds'] ?? [], 'nationIds'); $logAfterId = $observe['logAfterId'] ?? 0; $messageAfterId = $observe['messageAfterId'] ?? 0; + $includeNationHistoryLogs = $observe['includeNationHistoryLogs'] ?? false; $generalCooldownSelectors = comparisonGeneralCooldownSelectors( $observe['generalCooldowns'] ?? [], 'generalCooldowns', @@ -202,9 +203,17 @@ function comparisonTurnStateSnapshot(array $request): array $observe['diplomacyPairs'] ?? [], 'diplomacyPairs', ); - if (!is_int($logAfterId) || $logAfterId < 0 || !is_int($messageAfterId) || $messageAfterId < 0) { + if ( + !is_int($logAfterId) + || $logAfterId < 0 + || !is_int($messageAfterId) + || $messageAfterId < 0 + ) { throw new \InvalidArgumentException('logAfterId and messageAfterId must be non-negative integers'); } + if (!is_bool($includeNationHistoryLogs)) { + throw new \InvalidArgumentException('includeNationHistoryLogs must be a boolean'); + } $db = DB::db(); $game = KVStorage::getStorage($db, 'game_env'); @@ -486,6 +495,24 @@ function comparisonTurnStateSnapshot(array $request): array ]); } } + if ($includeNationHistoryLogs && $nationIds !== []) { + foreach ($db->query( + 'SELECT id, nation_id, year, month, text FROM world_history WHERE nation_id IN %li ORDER BY id', + $nationIds, + ) as $row) { + $logs[] = comparisonPickRow($row, [ + 'id' => 'id', + 'nationId' => 'nation_id', + 'year' => 'year', + 'month' => 'month', + 'text' => 'text', + ]) + [ + 'scope' => 'nation', + 'category' => 'history', + 'generalId' => null, + ]; + } + } $messages = array_map( static fn(array $row): array => comparisonPickRow(