diff --git a/hwe/compare/turn_command_trace.php b/hwe/compare/turn_command_trace.php index 908439bc..be1a1b47 100644 --- a/hwe/compare/turn_command_trace.php +++ b/hwe/compare/turn_command_trace.php @@ -124,6 +124,20 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void } $game->setValue($key, $value); } + if (array_key_exists('develCost', $world)) { + $develCost = $world['develCost']; + if (!is_int($develCost) || $develCost < 0) { + throw new \InvalidArgumentException('setup.world.develCost is invalid'); + } + $game->setValue('develcost', $develCost); + } + if (array_key_exists('isUnited', $world)) { + $isUnited = $world['isUnited']; + if (!is_int($isUnited) || $isUnited < 0 || $isUnited > 3) { + throw new \InvalidArgumentException('setup.world.isUnited is invalid'); + } + $game->setValue('isunited', $isUnited); + } $game->resetCache(); if (array_key_exists('hiddenSeed', $world)) { $hiddenSeed = $world['hiddenSeed']; @@ -412,8 +426,32 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void if (!is_array($row) || !is_int($row['id'] ?? null) || $row['id'] < 1) { throw new \InvalidArgumentException('setup.generals requires positive integer ids'); } + if (array_key_exists('ownerId', $row) && (!is_int($row['ownerId']) || $row['ownerId'] < 0)) { + throw new \InvalidArgumentException('setup.generals.ownerId must be a non-negative integer'); + } + if ( + array_key_exists('inheritActiveActionPoints', $row) + && (!array_key_exists('ownerId', $row) || !is_int($row['ownerId']) || $row['ownerId'] < 1) + ) { + throw new \InvalidArgumentException( + 'setup.generals.inheritActiveActionPoints requires a positive ownerId', + ); + } + if ( + array_key_exists('inheritActiveActionPoints', $row) + && ( + (!is_int($row['inheritActiveActionPoints']) && !is_float($row['inheritActiveActionPoints'])) + || !is_finite($row['inheritActiveActionPoints']) + || $row['inheritActiveActionPoints'] < 0 + ) + ) { + throw new \InvalidArgumentException( + 'setup.generals.inheritActiveActionPoints must be a finite non-negative number', + ); + } $patch = comparisonMappedPatch($row, [ 'name' => 'name', + 'ownerId' => 'owner', 'nationId' => 'nation', 'cityId' => 'city', 'troopId' => 'troop', @@ -460,6 +498,9 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void 'itemBook' => 'book', 'itemExtra' => 'item', ]); + if (($setup['isolateWorld'] ?? false) === true && !array_key_exists('ownerId', $row)) { + $patch['owner'] = 0; + } if (isset($row['meta'])) { $patch['aux'] = Json::encode($row['meta']); } @@ -475,6 +516,12 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void if ($patch !== []) { $db->update('general', $patch, 'no = %i', $row['id']); } + if (array_key_exists('inheritActiveActionPoints', $row)) { + $ownerId = $row['ownerId']; + $inheritanceStorage = KVStorage::getStorage($db, "inheritance_{$ownerId}"); + $inheritanceStorage->setValue('active_action', [$row['inheritActiveActionPoints'], null]); + $inheritanceStorage->resetCache(); + } if (array_key_exists('nationId', $row)) { $db->update('rank_data', [ 'nation_id' => $row['nationId'],