From 76a5ea273a4bdca74558e725d74f1d4f40eea8b7 Mon Sep 17 00:00:00 2001 From: hided62 Date: Sun, 26 Jul 2026 12:04:55 +0000 Subject: [PATCH] compare: observe nation history in turn snapshots --- hwe/compare/turn_state_snapshot.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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(