From 0722f6ab5e711e99e0c79ecde8dfa4d3c36e7c4c Mon Sep 17 00:00:00 2001 From: hided62 Date: Sun, 26 Jul 2026 03:10:50 +0000 Subject: [PATCH] Add instant diplomacy response traces --- hwe/compare/turn_command_trace.php | 48 +++++++++++++++++++++++++++-- hwe/compare/turn_state_snapshot.php | 4 +++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/hwe/compare/turn_command_trace.php b/hwe/compare/turn_command_trace.php index c5b03fa4..3186270d 100644 --- a/hwe/compare/turn_command_trace.php +++ b/hwe/compare/turn_command_trace.php @@ -211,6 +211,19 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void $nationStor = KVStorage::getStorage($db, $row['id'], 'nation_env'); if (($setup['isolateWorld'] ?? false) === true) { $nationStor->deleteValue('recv_assist'); + $nationStor->deleteValue('resp_assist'); + } + if (array_key_exists('nationEnv', $row)) { + if (!is_array($row['nationEnv'])) { + throw new \InvalidArgumentException('setup.nations.nationEnv must be an object'); + } + foreach ($row['nationEnv'] as $key => $value) { + if (!is_string($key) || $key === '') { + throw new \InvalidArgumentException('setup.nations.nationEnv keys must be non-empty strings'); + } + $nationStor->setValue($key, $value); + } + $nationStor->resetCache(); } if (array_key_exists('turnLastByOfficerLevel', $row)) { $turnLastByOfficerLevel = $row['turnLastByOfficerLevel']; @@ -278,6 +291,7 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void throw new \InvalidArgumentException('setup.generals requires positive integer ids'); } $patch = comparisonMappedPatch($row, [ + 'name' => 'name', 'nationId' => 'nation', 'cityId' => 'city', 'troopId' => 'troop', @@ -382,8 +396,8 @@ function comparisonRunTurnCommand(array $request): array throw new \RuntimeException('TURN_DIFFERENTIAL_ENABLED=1 is required'); } $kind = $request['kind'] ?? null; - if ($kind !== 'general' && $kind !== 'nation') { - throw new \InvalidArgumentException('kind must be general or nation'); + if (!in_array($kind, ['general', 'nation', 'instantNation'], true)) { + throw new \InvalidArgumentException('kind must be general, nation, or instantNation'); } $actorGeneralId = $request['actorGeneralId'] ?? null; $action = $request['action'] ?? null; @@ -403,6 +417,36 @@ function comparisonRunTurnCommand(array $request): array $gameStorage->resetCache(); $environment = $gameStorage->getAll(); $general = General::createObjFromDB($actorGeneralId); + if ($kind === 'instantNation') { + $command = buildNationCommandClass($action, $general, $environment, new LastTurn(), $args); + if (!$command->hasFullConditionMet()) { + throw new \RuntimeException($command->getFailString()); + } + $completed = $command->run(NoRNG::rngInstance()); + $command->setNextAvailable(); + $general->getLogger()->flush(); + $after = comparisonTurnStateSnapshot($snapshotRequest); + + return [ + 'schemaVersion' => 1, + 'engine' => 'ref', + 'execution' => [ + 'kind' => $kind, + 'actorGeneralId' => $actorGeneralId, + 'action' => $action, + 'args' => $args, + 'seedDomain' => 'none', + 'outcome' => [ + 'lastTurn' => (object)[], + 'commandName' => $command->getName(), + 'completed' => $completed, + ], + ], + 'before' => $before, + 'after' => $after, + 'rng' => [], + ]; + } $turn = new TurnExecutionHelper($general); $general->increaseInheritancePoint(Enums\InheritanceKey::lived_month, 1); $preprocessRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( diff --git a/hwe/compare/turn_state_snapshot.php b/hwe/compare/turn_state_snapshot.php index 7cecd5f3..5e974d46 100644 --- a/hwe/compare/turn_state_snapshot.php +++ b/hwe/compare/turn_state_snapshot.php @@ -243,6 +243,10 @@ function comparisonTurnStateSnapshot(array $request): array if (is_array($receivedAssist) && $receivedAssist !== []) { $projected['meta']['recv_assist'] = $receivedAssist; } + $respondedAssist = $nationStor->getValue('resp_assist'); + if (is_array($respondedAssist) && $respondedAssist !== []) { + $projected['meta']['resp_assist'] = $respondedAssist; + } return $projected; }, comparisonRowsById('nation', 'nation', $nationIds),