Skip to content

reimplement OpenSHC::AI::AICState - #165

Draft
gynt wants to merge 104 commits into
mainfrom
reimpl/AICState
Draft

gynt wants to merge 104 commits into
mainfrom
reimpl/AICState

Conversation

@gynt

@gynt gynt commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Currently did only a first pass using Claude. Not all methods yet, I ran out of tokens. I used TRD's skill documents, ghidra-mcp, and the tools/mcp/decomphelper.py script succesfully.

I guess it is better if I use
git restore --source otherbranch path/to/myfile.txt
to pick the 100% files and push them separately, deleting those files from this PR

@gynt
gynt marked this pull request as draft July 19, 2026 16:13
@gynt gynt self-assigned this Jul 19, 2026
@gynt
gynt force-pushed the reimpl/AICState branch from 83934e7 to 560411d Compare July 19, 2026 23:10
@gynt

gynt commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

See 2d8606c

@Krarilotus

Copy link
Copy Markdown
Contributor

I am implementing an opt-in AIC behavior extension (recruitment/sorties, one next-wave reserve, opponent/retaliation policy, bounded split raids) under the UCP owner, with the native path retained for non-opted-in personalities. I found this existing reconstruction PR and will preserve its ownership rather than open a competing AICState reconstruction.

Reference inspected: your 970160c and SHC 1.41 SHA256 3bb0a8c1e72331b3a30a5aa93ed94beca0081b476b04c1960e26d5b45387ac5a. Read-only disassembly confirms the attack-role gate at 0x4D3C15–0x4D3C20 returns when the per-player state at playerStride+0x115E99C is nonzero. aiGiveRaidInstructions also actually iterates six existing tribe entries (0x4D2DE8), so eight AIC composition slots do not establish spare group capacity. Neither observation proves safe reserves or a new raid partition.

Please let me know the preferred way to contribute any bounded, assembly-verified prerequisites to your existing work. I am keeping policy changes out of OpenSHC and have not enabled or advertised the unverified reconstruction as a runtime replacement. Shared loader prerequisites are tracked in UnofficialCrusaderPatch/extension-aicloader#17; there is no claim of native, MP, save/replay, or performance acceptance yet.

@Krarilotus

Copy link
Copy Markdown
Contributor

A bounded discrepancy from the same SHC 1.41 audit: src/OpenSHC/AI/AICState/createTribeForUnitType.cpp annotates 0x004CC960, while the member resolver points to 0x004CC910 at head 970160c. Please reconcile this before enabling/comparing that source; I have left your branch unchanged.

For the acquisition prerequisite, the existing UnitsState euroRecruit / nonEuroRecruit fourth argument already implements check-only behavior. It still writes diagnostics; knights also call GameStateStructures::recountStablesAndHorses and update all eight cached horse counts. I am reusing those original owners in the UCP policy adapter, with isolated query side effects, rather than adding a competing eligibility reconstruction.

@gynt

gynt commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Currently remaining:

  OpenSHC::AI::AICState::setAICParameters_15 (0x4ca4d0) is 74.92% similar to the original
  OpenSHC::AI::AICState::generateSiegeCreationInformation (0x4cc420) is 37.96% similar to the original
  OpenSHC::AI::AICState::smallestTribeOfUnitType (0x4cc990) is 40.93% similar to the original
  OpenSHC::AI::AICState::getSmallestPatrolTribe (0x4ccaf0) is 68.12% similar to the original
  OpenSHC::AI::AICState::addUnitToSmallestBehaviourTypeTribe (0x4ccd20) is 63.91% similar to the original
  OpenSHC::AI::AICState::recruitHarrassingSiegeEngines (0x4cd2a0) is 59.57% similar to the original
  OpenSHC::AI::AICState::instructTribe166ToMove (0x4cd7b0) is 76.14% similar to the original
  OpenSHC::AI::AICState::giveMoveCommandToSortieUnits (0x4cd8f0) is 74.19% similar to the original
  OpenSHC::AI::AICState::chooseRandomBuildingIDFromPlayersArrayOfBuildings (0x4cdb20) is 23.30% similar to the original
  OpenSHC::AI::AICState::getTargetableBuildingForPlayerID (0x4cdbc0) is 65.04% similar to the original
  OpenSHC::AI::AICState::aiShouldAttackOrWaitForTeamCoordination (0x4cdcf0) is 41.75% similar to the original
  OpenSHC::AI::AICState::setCurrentAttackStrength (0x4cde60) is 76.09% similar to the original
  OpenSHC::AI::AICState::setCurrentAttackRaidParameter (0x4cdf10) is 72.00% similar to the original
  OpenSHC::AI::AICState::computeEnemyKeepApproachTile (0x4ce200) is 55.26% similar to the original
  OpenSHC::AI::AICState::aiCommandTribe13DefensiveWave (0x4cf270) is 62.22% similar to the original
  OpenSHC::AI::AICState::aiCommandTribe12AggressiveApproach (0x4cf2e0) is 46.81% similar to the original
  OpenSHC::AI::AICState::setTribe0xCtoAggressiveAndAttack (0x4cf400) is 62.22% similar to the original
  OpenSHC::AI::AICState::aiCommandTribe11StandGroundToGate (0x4cf470) is 56.00% similar to the original
  OpenSHC::AI::AICState::sendAITribe_0xf_toAttackPatrol (0x4cf4f0) is 57.14% similar to the original
  OpenSHC::AI::AICState::setTribe0x11ToAggressiveAndAttackIfConditionMet (0x4cf560) is 37.74% similar to the original
  OpenSHC::AI::AICState::setTribe0xbToAggressiveAndAttack (0x4cf6e0) is 62.22% similar to the original
  OpenSHC::AI::AICState::sendTribeToAttack (0x4cf750) is 62.22% similar to the original
  OpenSHC::AI::AICState::aiCommandSiegeEngineTribes (0x4cfcd0) is 55.97% similar to the original
  OpenSHC::AI::AICState::playNervous2BikFromPlayer (0x4d0b10) is 68.00% similar to the original
  OpenSHC::AI::AICState::renderDebugDataAiInfo (0x4d1320) is 69.55% similar to the original
  OpenSHC::AI::AICState::setInitialAIC (0x4d18b0) is 67.92% similar to the original
  OpenSHC::AI::AICState::decideOnTribeAttackLocation (0x4d1a00) is 58.00% similar to the original
  OpenSHC::AI::AICState::sellExcessGoods (0x4d1d60) is 52.55% similar to the original
  OpenSHC::AI::AICState::aiCreateSiegeUnits (0x4d2000) is 29.44% similar to the original
  OpenSHC::AI::AICState::assignUnitToATribe (0x4d2660) is 59.57% similar to the original
  OpenSHC::AI::AICState::addUnitToSmallestPatrolTribe (0x4d2730) is 79.17% similar to the original
  OpenSHC::AI::AICState::aiGiveOuterPatrolCommand (0x4d28b0) is 73.04% similar to the original
  OpenSHC::AI::AICState::aiGiveRaidInstructions (0x4d2a70) is 30.02% similar to the original
  OpenSHC::AI::AICState::computeAttackPossibilities (0x4d2ec0) is 74.14% similar to the original
  OpenSHC::AI::AICState::computeNervousness (0x4d3780) is 74.02% similar to the original
  OpenSHC::AI::AICState::aiRecruitUnits (0x4d3ae0) is 35.82% similar to the original
  OpenSHC::AI::AICState::sendWallPatrolUnitTribesToAIVLocations (0x4d4340) is 57.89% similar to the original
  OpenSHC::AI::AICState::selectAttackTarget (0x4d4680) is 64.77% similar to the original
  OpenSHC::AI::AICState::updateAIPlayerState (0x4d49e0) is 54.70% similar to the original

Full progress:

  OpenSHC::AI::AICState::wipeAICMemory (0x4c6d30) is 93.75% similar to the original
  OpenSHC::AI::AICState::setAICParameters_01 (0x4c6d60) is 92.16% similar to the original
  OpenSHC::AI::AICState::setAICParameters_02 (0x4c7120) is 83.72% similar to the original
  OpenSHC::AI::AICState::setAICParameters_03 (0x4c7520) is 94.08% similar to the original
  OpenSHC::AI::AICState::setAICParameters_04 (0x4c7910) is 81.94% similar to the original
  OpenSHC::AI::AICState::setAICParameters_05 (0x4c7d20) is 81.53% similar to the original
  OpenSHC::AI::AICState::setAICParameters_06 (0x4c8110) is 84.28% similar to the original
  OpenSHC::AI::AICState::setAICParameters_07 (0x4c8530) is 94.70% similar to the original
  OpenSHC::AI::AICState::setAICParameters_08 (0x4c8920) is 87.50% similar to the original
  OpenSHC::AI::AICState::setAICParameters_09 (0x4c8d20) is 90.38% similar to the original
  OpenSHC::AI::AICState::setAICParameters_10 (0x4c9120) is 80.00% similar to the original
  OpenSHC::AI::AICState::setAICParameters_11 (0x4c94f0) is 89.54% similar to the original
  OpenSHC::AI::AICState::setAICParameters_12 (0x4c9900) is 84.21% similar to the original
  OpenSHC::AI::AICState::setAICParameters_13 (0x4c9cf0) is 83.33% similar to the original
  OpenSHC::AI::AICState::setAICParameters_14 (0x4ca0c0) is 82.35% similar to the original
  OpenSHC::AI::AICState::setAICParameters_15 (0x4ca4d0) is 74.92% similar to the original
  OpenSHC::AI::AICState::setAICParameters_16 (0x4ca8a0) is 84.75% similar to the original
  OpenSHC::AI::AICState::clearPlayerDataInformationChunk (0x4cac70) is 95.24% similar to the original
  OpenSHC::AI::AICState::setTargetForTribeBasedOnTargetChoiceLogic (0x4cacb0) is 97.16% similar to the original
  OpenSHC::AI::AICState::aiUpdateTaxesAndRations (0x4caea0) is 100.00% similar to the original
  OpenSHC::AI::AICState::setFoodBuyPlan (0x4cb060) is 100.00% similar to the original
  OpenSHC::AI::AICState::getAIBuildInterval (0x4cb120) is 100.00% similar to the original
  OpenSHC::AI::AICState::getResourceRebuildDelay (0x4cb150) is 100.00% similar to the original
  OpenSHC::AI::AICState::aiFarmChoice (0x4cb180) is 100.00% similar to the original
  OpenSHC::AI::AICState::setNextFarmTypeToBuild (0x4cb1b0) is 100.00% similar to the original
  OpenSHC::AI::AICState::aiShouldBuildFarm (0x4cb220) is 97.83% similar to the original
  OpenSHC::AI::AICState::aiShouldBuildWoodcutter (0x4cb290) is 98.11% similar to the original
  OpenSHC::AI::AICState::aiShouldBuildQuarry (0x4cb330) is 97.50% similar to the original
  OpenSHC::AI::AICState::aiRequiresExtraOxtethers (0x4cb3a0) is 85.29% similar to the original
  OpenSHC::AI::AICState::aiShouldBuildIronMine (0x4cb4d0) is 97.50% similar to the original
  OpenSHC::AI::AICState::aiShouldBuildPitchrig (0x4cb540) is 97.50% similar to the original
  OpenSHC::AI::AICState::shouldNotBeBuildingHovel (0x4cb5b0) is 91.30% similar to the original
  OpenSHC::AI::AICState::shouldWaitWithBuildingNegativeFearFactor (0x4cb610) is 100.00% similar to the original
  OpenSHC::AI::AICState::shouldWaitWithBuildingAPositiveFearFactor (0x4cb700) is 100.00% similar to the original
  OpenSHC::AI::AICState::destroyHouse (0x4cb810) is 92.31% similar to the original
  OpenSHC::AI::AICState::shouldDestroyWoodCutterUnk (0x4cb890) is 92.16% similar to the original
  OpenSHC::AI::AICState::destroyBuildingIfNoWorker (0x4cb940) is 88.89% similar to the original
  OpenSHC::AI::AICState::shouldNotBuildMarketArmoryGranaryBarracksMercenarypost (0x4cb9f0) is 100.00%* similar to the original
  OpenSHC::AI::AICState::planToBuyWhenLowOnResourceAndSnoozeBuildings (0x4cba50) is 85.08% similar to the original
  OpenSHC::AI::AICState::setupWorkshopProductionType (0x4cbe30) is 96.39% similar to the original
  OpenSHC::AI::AICState::sellGoods (0x4cbfa0) is 90.91% similar to the original
  OpenSHC::AI::AICState::buyGoods (0x4cc000) is 92.86% similar to the original
  OpenSHC::AI::AICState::randomlySelectAttackUnitTypeToRecruit (0x4cc070) is 99.28% similar to the original
  OpenSHC::AI::AICState::getUnitTypeForUnitBehaviourType (0x4cc250) is 94.25% similar to the original
  OpenSHC::AI::AICState::generateSiegeCreationInformation (0x4cc420) is 37.96% similar to the original
  OpenSHC::AI::AICState::aiRecruitEngineers (0x4cc520) is 93.75% similar to the original
  OpenSHC::AI::AICState::assignRequiredIdleEngineersToNewTribe (0x4cc5a0) is 85.71% similar to the original
  OpenSHC::AI::AICState::addEngineersToSelection (0x4cc680) is 83.33% similar to the original
  OpenSHC::AI::AICState::addUnitsToTribe166 (0x4cc720) is 95.24% similar to the original
  OpenSHC::AI::AICState::syncBehaviourType7UnitTribes (0x4cc7b0) is 95.24% similar to the original
  OpenSHC::AI::AICState::aiAddUnitToMoatDiggerTribe (0x4cc840) is 94.29% similar to the original
  OpenSHC::AI::AICState::unitIDIsRangedOrArmored (0x4cc8d0) is 100.00% similar to the original
  OpenSHC::AI::AICState::createTribeForUnitType (0x4cc910) is 97.06% similar to the original
  OpenSHC::AI::AICState::smallestTribeOfUnitType (0x4cc990) is 40.93% similar to the original
  OpenSHC::AI::AICState::getSmallestPatrolTribe (0x4ccaf0) is 68.12% similar to the original
  OpenSHC::AI::AICState::getDefensiveTribeForUnit (0x4ccbe0) is 99.01% similar to the original
  OpenSHC::AI::AICState::addUnitToSmallestBehaviourTypeTribe (0x4ccd20) is 63.91% similar to the original
  OpenSHC::AI::AICState::sendUnitsToKeep (0x4cd0c0) is 94.44% similar to the original
  OpenSHC::AI::AICState::sendUnitsToCampfire (0x4cd110) is 94.44% similar to the original
  OpenSHC::AI::AICState::digNearestMoat (0x4cd160) is 91.67% similar to the original
  OpenSHC::AI::AICState::canNavigateUnitsFromTileToTargetTile (0x4cd250) is 94.74% similar to the original
  OpenSHC::AI::AICState::recruitHarrassingSiegeEngines (0x4cd2a0) is 59.57% similar to the original
  OpenSHC::AI::AICState::aiRecruitSortieRangedUnits (0x4cd560) is 95.24% similar to the original
  OpenSHC::AI::AICState::aiRecruitSortieMeleeUnits (0x4cd690) is 94.94% similar to the original
  OpenSHC::AI::AICState::instructTribe166ToMove (0x4cd7b0) is 76.14% similar to the original
  OpenSHC::AI::AICState::giveMoveCommandToSortieUnits (0x4cd8f0) is 74.19% similar to the original
  OpenSHC::AI::AICState::addBuildingToTargetableBuildings (0x4cda50) is 100.00% similar to the original
  OpenSHC::AI::AICState::selectBuildingFromAListOfBuildingTypes (0x4cdab0) is 100.00% similar to the original
  OpenSHC::AI::AICState::chooseRandomBuildingIDFromPlayersArrayOfBuildings (0x4cdb20) is 23.30% similar to the original
  OpenSHC::AI::AICState::getTargetableBuildingForPlayerID (0x4cdbc0) is 65.04% similar to the original
  OpenSHC::AI::AICState::selectRandomBuildingIDFromListOfBuildingTypes (0x4cdca0) is 95.65% similar to the original
  OpenSHC::AI::AICState::aiShouldAttackOrWaitForTeamCoordination (0x4cdcf0) is 41.75% similar to the original
  OpenSHC::AI::AICState::setCurrentAttackStrength (0x4cde60) is 76.09% similar to the original
  OpenSHC::AI::AICState::setCurrentAttackRaidParameter (0x4cdf10) is 72.00% similar to the original
  OpenSHC::AI::AICState::setAttackPrimeInfo (0x4cdfd0) is 100.00% similar to the original
  OpenSHC::AI::AICState::recomputeAIPathCostToAttackedKeep (0x4ce040) is 93.55% similar to the original
  OpenSHC::AI::AICState::recomputeAttackAIZone (0x4ce110) is 92.86% similar to the original
  OpenSHC::AI::AICState::recomputeAIZonerLayer (0x4ce1a0) is 85.71% similar to the original
  OpenSHC::AI::AICState::computeEnemyKeepApproachTile (0x4ce200) is 55.26% similar to the original
  OpenSHC::AI::AICState::setNextMoveLocationForUnits (0x4ce3b0) is 91.18% similar to the original
  OpenSHC::AI::AICState::removeOrganismsAndSetMoveDestinationPairs (0x4ce430) is 91.49% similar to the original
  OpenSHC::AI::AICState::aiRetreatUnits (0x4ce4d0) is 93.83% similar to the original
  OpenSHC::AI::AICState::sendUnitsToPlayerIDsKeepIfPossible (0x4ce5f0) is 93.50% similar to the original
  OpenSHC::AI::AICState::clearRallyFlagOnAllAIAttackTribes (0x4ce790) is 98.00% similar to the original
  OpenSHC::AI::AICState::moveAttackTribesToLocations (0x4ce830) is 98.67% similar to the original
  OpenSHC::AI::AICState::findAttackTribePositionAndPathToDefenses (0x4ce930) is 86.96% similar to the original
  OpenSHC::AI::AICState::makeUnitsGoDefensiveAndBackToSomeLocation (0x4cea50) is 92.75% similar to the original
  OpenSHC::AI::AICState::giveMoveCommandToAttackTribes (0x4ceb50) is 98.80% similar to the original
  OpenSHC::AI::AICState::aiChoiceAttForceRallyPercentage (0x4cec80) is 100.00% similar to the original
  OpenSHC::AI::AICState::percentageNonMovingTribesGTEAICSpecified (0x4ced90) is 100.00% similar to the original
  OpenSHC::AI::AICState::processAttForceRallyPercentage (0x4ceea0) is 100.00% similar to the original
  OpenSHC::AI::AICState::useAITribe_0x12_toPlaceSiegeTentsAndAssignEngineers (0x4cefd0) is 97.50% similar to the original
  OpenSHC::AI::AICState::useAITribe_0xe_toPlaceTunnels (0x4cf180) is 93.44% similar to the original
  OpenSHC::AI::AICState::aiCommandTribe13DefensiveWave (0x4cf270) is 62.22% similar to the original
  OpenSHC::AI::AICState::aiCommandTribe12AggressiveApproach (0x4cf2e0) is 46.81% similar to the original
  OpenSHC::AI::AICState::setTribe0xCtoAggressiveAndAttack (0x4cf400) is 62.22% similar to the original
  OpenSHC::AI::AICState::aiCommandTribe11StandGroundToGate (0x4cf470) is 56.00% similar to the original
  OpenSHC::AI::AICState::sendAITribe_0xf_toAttackPatrol (0x4cf4f0) is 57.14% similar to the original
  OpenSHC::AI::AICState::setTribe0x11ToAggressiveAndAttackIfConditionMet (0x4cf560) is 37.74% similar to the original
  OpenSHC::AI::AICState::setEightTribe0xc0TribesToAggressiveAndAttack (0x4cf5e0) is 97.22% similar to the original
  OpenSHC::AI::AICState::aiCommandWallAssaultTribes (0x4cf660) is 97.22% similar to the original
  OpenSHC::AI::AICState::setTribe0xbToAggressiveAndAttack (0x4cf6e0) is 62.22% similar to the original
  OpenSHC::AI::AICState::sendTribeToAttack (0x4cf750) is 62.22% similar to the original
  OpenSHC::AI::AICState::commandFourTribesToMove (0x4cf7c0) is 98.15% similar to the original
  OpenSHC::AI::AICState::clearOutdatedAITribes (0x4cf870) is 100.00% similar to the original
  OpenSHC::AI::AICState::giveSomeRaidCommand (0x4cf920) is 96.88% similar to the original
  OpenSHC::AI::AICState::addRallyPointForTribe (0x4cfa10) is 96.88% similar to the original
  OpenSHC::AI::AICState::disbandAIPlayerSiegeUnits (0x4cfb20) is 97.83% similar to the original
  OpenSHC::AI::AICState::countSiegeEngineUnits (0x4cfbc0) is 100.00%* similar to the original
  OpenSHC::AI::AICState::aiCommandSiegeEngineTribes (0x4cfcd0) is 55.97% similar to the original
  OpenSHC::AI::AICState::yieldCowThrow (0x4cff60) is 100.00% similar to the original
  OpenSHC::AI::AICState::hasNoTroopsOrAllAreDiggers (0x4cffd0) is 100.00% similar to the original
  OpenSHC::AI::AICState::hasNotEnoughSupplies (0x4d00a0) is 100.00% similar to the original
  OpenSHC::AI::AICState::setAttackCoordinationLevel (0x4d0110) is 97.56% similar to the original
  OpenSHC::AI::AICState::teamIsWeakRelativeToEnemy (0x4d0190) is 87.32% similar to the original
  OpenSHC::AI::AICState::destroyAnyBuildingInCategory (0x4d0280) is 98.19% similar to the original
  OpenSHC::AI::AICState::isResourceLargerOrEqualThanMinimumGoodsRequiredAfterTrade (0x4d0520) is 100.00% similar to the original
  OpenSHC::AI::AICState::aiOfTypeInCurrentGame (0x4d0580) is 100.00%* similar to the original
  OpenSHC::AI::AICState::shareGoldAmongTeamMembers (0x4d05d0) is 96.35% similar to the original
  OpenSHC::AI::AICState::playTauntToAttackedPlayerBikFromPlayer (0x4d07c0) is 94.29% similar to the original
  OpenSHC::AI::AICState::playAnger1BikFromPlayer (0x4d0830) is 94.29% similar to the original
  OpenSHC::AI::AICState::playPlayerKilledBiksFromKilledAndKillerPlayer (0x4d08b0) is 91.74% similar to the original
  OpenSHC::AI::AICState::playGoodsRequestBikFromPlayerToPlayer (0x4d0a20) is 91.67% similar to the original
  OpenSHC::AI::AICState::playThanksBikFromPlayerToPlayer (0x4d0a80) is 95.24% similar to the original
  OpenSHC::AI::AICState::playNervous2BikFromPlayer (0x4d0b10) is 68.00% similar to the original
  OpenSHC::AI::AICState::playGoodsNotSentBikFromPlayer (0x4d0b70) is 88.89% similar to the original
  OpenSHC::AI::AICState::playGoodsSentBikFromPlayerToPlayer (0x4d0bb0) is 90.48% similar to the original
  OpenSHC::AI::AICState::playAnger2BikFromPlayerToPlayer (0x4d0c00) is 92.86% similar to the original
  OpenSHC::AI::AICState::playVictory2BikFromPlayerToPlayer (0x4d0c70) is 91.89% similar to the original
  OpenSHC::AI::AICState::playNervous1BikFromPlayer (0x4d0cf0) is 90.48% similar to the original
  OpenSHC::AI::AICState::playRequestHelpBikFromPlayer (0x4d0d40) is 92.86% similar to the original
  OpenSHC::AI::AICState::playJokeBikFromAIToHuman (0x4d0f90) is 86.67% similar to the original
  OpenSHC::AI::AICState::playFriendlyVictoryBikFromPlayer (0x4d0fc0) is 88.89% similar to the original
  OpenSHC::AI::AICState::playTeamWinningBikFromPlayer (0x4d1000) is 90.91% similar to the original
  OpenSHC::AI::AICState::playNoHelpBikFromPlayer (0x4d1050) is 88.89% similar to the original
  OpenSHC::AI::AICState::setTriggerForAITauntResponse (0x4d1090) is 90.00% similar to the original
  OpenSHC::AI::AICState::someChatMessageSelection (0x4d10b0) is 96.69% similar to the original
  OpenSHC::AI::AICState::getCurrentDesiredAttackRaidUnitCount (0x4d12a0) is 100.00% similar to the original
  OpenSHC::AI::AICState::renderDebugDataAiInfo (0x4d1320) is 69.55% similar to the original
  OpenSHC::AI::AICState::setInitialAIC (0x4d18b0) is 67.92% similar to the original
  OpenSHC::AI::AICState::aiRegisterTribeAndAssignTarget (0x4d1950) is 98.00% similar to the original
  OpenSHC::AI::AICState::decideOnTribeAttackLocation (0x4d1a00) is 58.00% similar to the original
  OpenSHC::AI::AICState::sellExcessGoods (0x4d1d60) is 52.55% similar to the original
  OpenSHC::AI::AICState::requestGoods (0x4d1f00) is 97.33% similar to the original
  OpenSHC::AI::AICState::aiCreateSiegeUnits (0x4d2000) is 29.44% similar to the original
  OpenSHC::AI::AICState::aiRecruitEngineerForOilDuty (0x4d2500) is 94.57% similar to the original
  OpenSHC::AI::AICState::assignUnitToATribe (0x4d2660) is 59.57% similar to the original
  OpenSHC::AI::AICState::addUnitToSmallestPatrolTribe (0x4d2730) is 79.17% similar to the original
  OpenSHC::AI::AICState::aiAssignUnitToDefensiveTribe (0x4d2790) is 91.30% similar to the original
  OpenSHC::AI::AICState::addUnitToItsTribe (0x4d27e0) is 92.00% similar to the original
  OpenSHC::AI::AICState::ifHasTribe0SendUnitsToKeep (0x4d2830) is 94.74% similar to the original
  OpenSHC::AI::AICState::sendTribeAtOffset1ToCampfire (0x4d2870) is 94.74% similar to the original
  OpenSHC::AI::AICState::aiGiveOuterPatrolCommand (0x4d28b0) is 73.04% similar to the original
  OpenSHC::AI::AICState::aiGiveRaidInstructions (0x4d2a70) is 30.02% similar to the original
  OpenSHC::AI::AICState::sendTribeToAIVLocationSlot (0x4d2e00) is 95.45% similar to the original
  OpenSHC::AI::AICState::computeAttackPossibilities (0x4d2ec0) is 74.14% similar to the original
  OpenSHC::AI::AICState::moveAttackingUnitsToNextRallyPoint (0x4d2f80) is 95.56% similar to the original
  OpenSHC::AI::AICState::sendUnitsToAttackBreachedCastle (0x4d30e0) is 95.45% similar to the original
  OpenSHC::AI::AICState::updateAIStrengthState (0x4d3320) is 87.69% similar to the original
  OpenSHC::AI::AICState::computeNervousness (0x4d3780) is 74.02% similar to the original
  OpenSHC::AI::AICState::determineAIPlayerHelp (0x4d3850) is 82.35% similar to the original
  OpenSHC::AI::AICState::determineAIPlayerAttackRequestResponse (0x4d38c0) is 83.78% similar to the original
  OpenSHC::AI::AICState::Constructor_AICState (0x4d3940) is 85.71% similar to the original
  OpenSHC::AI::AICState::makeOutpostTribesAttack (0x4d3960) is 96.43% similar to the original
  OpenSHC::AI::AICState::buyRequiredGoods (0x4d39b0) is 96.63% similar to the original
  OpenSHC::AI::AICState::aiRecruitUnits (0x4d3ae0) is 35.82% similar to the original
  OpenSHC::AI::AICState::aiAssignMoatDiggers (0x4d3f20) is 97.40% similar to the original
  OpenSHC::AI::AICState::addEngineersToTribe (0x4d4040) is 96.97% similar to the original
  OpenSHC::AI::AICState::aiReassignTunnelersToTribe (0x4d40b0) is 94.87% similar to the original
  OpenSHC::AI::AICState::sendRangedUnitTribesToAIVSlotsOrKeepIfNervous (0x4d4130) is 97.06% similar to the original
  OpenSHC::AI::AICState::sendCertainUnitTribesToAIVSlotsOrKeepIfNervousAndNotEnclosed (0x4d4220) is 96.30% similar to the original
  OpenSHC::AI::AICState::sendWallPatrolUnitTribesToAIVLocations (0x4d4340) is 57.89% similar to the original
  OpenSHC::AI::AICState::sendOilMenForOilPickupOrToAIVLocations (0x4d44e0) is 95.77% similar to the original
  OpenSHC::AI::AICState::abortAttackAndGoIdle (0x4d45e0) is 84.62% similar to the original
  OpenSHC::AI::AICState::recreateEngineersTribe (0x4d4630) is 94.44% similar to the original
  OpenSHC::AI::AICState::selectAttackTarget (0x4d4680) is 64.77% similar to the original
  OpenSHC::AI::AICState::aiBuyAndSellGoods (0x4d48f0) is 86.67% similar to the original
  OpenSHC::AI::AICState::updateTribeLocations (0x4d4940) is 82.22% similar to the original
  OpenSHC::AI::AICState::updateAIPlayerState (0x4d49e0) is 54.70% similar to the original
  OpenSHC::AI::AICState::updateAIBehaviour (0x4d53e0) is 85.21% similar to the original
  OpenSHC::AI::AICState::shouldNotBeBuildingGranary (0x4eca30) is 100.00% similar to the original
  OpenSHC::AI::AICState::shouldNotBeBuildingArmoury (0x4eca60) is 100.00% similar to the original
  OpenSHC::AI::AICState::shouldNotBuildKillingPits (0x4eca90) is 100.00% similar to the original
  OpenSHC::AI::AICState::mapperIsWoodCuttersHutWhileNoWoodAvailable (0x4ecab0) is 100.00% similar to the original

@gynt
gynt requested a review from TheRedDaemon September 22, 2026 18:00
@gynt

gynt commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@TheRedDaemon I have requested your review. I assume it will take a while because there are so many functions to review. In my PR view on GitHub they do look very neatly organized, so perhaps you can browse through it.

There is one function that has functional differences, this is: generateSiegeCreationInformation
All the other ones should be functionally the same.

Many non-100% are due to frequent MACRO usage, offset calculations that are cached in the original and added in our version or vice versa. The rest is register scheduling/allocation issues.

Also let's squash and merge this PR.

@gynt
gynt marked this pull request as ready for review September 22, 2026 18:03
@gynt
gynt force-pushed the reimpl/AICState branch 3 times, most recently from 32189f9 to 8a55196 Compare September 26, 2026 23:51
@gynt
gynt force-pushed the reimpl/AICState branch from e119f11 to 2b22cbc Compare October 1, 2026 19:06
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v22.1.8) reports: 1 file(s) not formatted
  • src/OpenSHC/AI/AICState/generateSiegeCreationInformation.cpp

Have any feedback or feature suggestions? Share it here.

@gynt
gynt force-pushed the reimpl/AICState branch from 9820b79 to 39e9130 Compare October 3, 2026 20:07
gynt and others added 29 commits October 11, 2026 23:35
Copying the original's loop and block structure back into the source made four
AI::AICState functions worse; the literals, where a value is computed, and arms
with identical bodies are the parts that transfer.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ccmp

The same change (one physical copy of a block the original shares) was worth
+1.3 points on aiCreateSiegeUnits and -10 on renderDebugDataAiInfo, and
quick_diff's ratio called the first one wrong. Also record the call count from
push_pattern.py as the signal that found it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants