Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
test(gameengine): add temporary JETRELOAD probes for jet attack move
Olcay Seygan79697dc80cdc
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex b2384d4cf..d24dc7ea4 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -3592,6 +3592,33 @@ void AIAttackMoveToState::onExit( StateExitType status )AIMoveToState::onExit(status);}++// ---------------------------------------------------------------------------+// TEMPORARY DIAGNOSTIC (jet reload/resume). Remove with the matching probes+// in JetAIUpdate.cpp; every line is prefixed JETRELOAD:.+// ---------------------------------------------------------------------------+static void jetStateTrace(const Object *obj, const char *what, const char *detail)+{+ AIUpdateInterface *ai = ((Object *)obj)->getAI();+ if (ai == NULL || ai->getJetAIUpdate() == NULL)+ return; // only trace jets++ AsciiString ammo;+ for (Int i = 0; i < WEAPONSLOT_COUNT; ++i)+ {+ const Weapon *w = obj->getWeaponInWeaponSlot((WeaponSlotType)i);+ if (w == NULL)+ continue;+ AsciiString one;+ one.format(" w%d[ammo=%d/%d status=%d max=%d]", i,+ w->getRemainingAmmo(), w->getClipSize(), (Int)w->getStatus(), w->getMaxShotCount());+ ammo.concat(one);+ }+ DEBUG_LOG(("JETRELOAD: obj %d %s %s frame=%d outOfAmmo=%d%s\n",+ (Int)obj->getID(), what, detail, (Int)TheGameLogic->getFrame(),+ (Int)((Object *)obj)->isOutOfAmmo(), ammo.str()));+}+//----------------------------------------------------------------------------------------------------------StateReturnType AIAttackMoveToState::update(){@@ -3605,6 +3632,8 @@ StateReturnType AIAttackMoveToState::update()JetAIUpdate *jetAI = ai->getJetAIUpdate();if( jetAI && jetAI->isOutOfSpecialReloadAmmo() ){+ if ((TheGameLogic->getFrame() % 30) == 0)+ jetStateTrace(owner, "ATTACKMOVE-OUT-OF-RELOAD-AMMO", "(returning STATE_SUCCESS)");//We need to return to base to reload!return STATE_SUCCESS;}@@ -3639,6 +3668,15 @@ StateReturnType AIAttackMoveToState::update()Object* nextObjectToAttack;nextObjectToAttack = ai->getNextMoodTarget( !forceRetargetThisFrame, false );+ if ((TheGameLogic->getFrame() % 30) == 0 || nextObjectToAttack != NULL)+ {+ AsciiString dbg;+ dbg.format("(target=%d, forceRetarget=%d, mood=%d)",+ nextObjectToAttack ? (Int)nextObjectToAttack->getID() : 0,+ (Int)forceRetargetThisFrame,+ (Int)(ai->getMoodMatrixActionAdjustment(MM_Action_Attack) & MAA_Action_Ok));+ jetStateTrace(owner, "ATTACKMOVE-PICK-TARGET", dbg.str());+ }if (nextObjectToAttack != NULL){ai->friend_endingMove();@@ -5510,13 +5548,17 @@ StateReturnType AIAttackState::onEnter()//from ever happening, but failed in two cases which I fixed. This is an extra check to mitigate cheats.if( source->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) ){+ jetStateTrace(source, "ATTACK-ENTER-FAIL", "(under construction)");return STATE_FAILURE;}// if all of our weapons are out of ammo, can't attack.// (this can happen for units which never auto-reload, like the Raptor)if (source->isOutOfAmmo() && !source->isKindOf(KINDOF_PROJECTILE))+ {+ jetStateTrace(source, "ATTACK-ENTER-FAIL", "(isOutOfAmmo)");return STATE_FAILURE;+ }// create new state machine for attack behavior//CRCDEBUG_LOG(("AIAttackState::onEnter() - constructing state machine for object %d\n", getMachineOwner()->getID()));@@ -5548,7 +5590,10 @@ StateReturnType AIAttackState::onEnter()// our Primary (default pick) regardless of legality.Bool weaponPicked = chooseWeapon();if( !weaponPicked )+ {+ jetStateTrace(source, "ATTACK-ENTER-FAIL", "(chooseWeapon failed)");return STATE_FAILURE;+ }Weapon* curWeapon = source->getCurrentWeapon();if (curWeapon)@@ -5562,6 +5607,12 @@ StateReturnType AIAttackState::onEnter()m_lockedWeaponOnEnter = source->isCurWeaponLocked() ? curWeapon : NULL;StateReturnType retType = m_attackMachine->initDefaultState();+ {+ AsciiString dbg;+ dbg.format("(initDefaultState=%d, weapon=%s)", (Int)retType,+ source->getCurrentWeapon() ? source->getCurrentWeapon()->getName().str() : "<none>");+ jetStateTrace(source, "ATTACK-ENTER", dbg.str());+ }if( retType == STATE_CONTINUE ){source->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_IS_ATTACKING ) );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cppindex 3185844b6..02cf3feac 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp@@ -102,6 +102,30 @@ void JetAIUpdate::setFlag( FlagType f, Bool v)m_flags &= ~(1<<f);}++// ---------------------------------------------------------------------------+// TEMPORARY DIAGNOSTIC (jet reload/resume). Remove once the attack-move+// reload cycle is understood; every line is prefixed JETRELOAD: so the whole+// trace can be pulled out of Run/DebugLogFile.txt with a single grep.+// ---------------------------------------------------------------------------+static void jetReloadTrace(const Object *jet, const char *what, const char *detail)+{+ AsciiString ammo;+ for (Int i = 0; i < WEAPONSLOT_COUNT; ++i)+ {+ const Weapon *w = jet->getWeaponInWeaponSlot((WeaponSlotType)i);+ if (w == NULL)+ continue;+ AsciiString one;+ one.format(" w%d[%s ammo=%d/%d status=%d rt=%d]", i, w->getName().str(),+ w->getRemainingAmmo(), w->getClipSize(), (Int)w->getStatus(), (Int)w->getReloadType());+ ammo.concat(one);+ }+ DEBUG_LOG(("JETRELOAD: obj %d (%s) %s %s frame=%d%s\n",+ (Int)jet->getID(), jet->getTemplate()->getName().str(), what, detail,+ (Int)TheGameLogic->getFrame(), ammo.str()));+}+//-------------------------------------------------------------------------------------------------Bool JetAIUpdate::isOutOfSpecialReloadAmmo() const{@@ -1478,6 +1502,11 @@ public:if (m_reloadTime < 1)m_reloadTime = 1;m_reloadDoneFrame = m_reloadTime + TheGameLogic->getFrame();+ {+ AsciiString d;+ d.format("(reloadTime=%d)", (Int)m_reloadTime);+ jetReloadTrace(jet, "RELOAD-ENTER", d.str());+ }return STATE_CONTINUE;}@@ -1502,7 +1531,10 @@ public:}if (allDone)+ {+ jetReloadTrace(jet, "RELOAD-DONE", "");return STATE_SUCCESS;+ }return STATE_CONTINUE;}@@ -1899,6 +1931,11 @@ UpdateSleepTime JetAIUpdate::update()m_mostRecentCommand.reconstitute(parms);setFlag(HAS_PENDING_COMMAND, false);+ {+ AsciiString d;+ d.format("(cmd=%d, airLoco=%d)", (Int)parms.m_cmd, (Int)getFlag(ALLOW_AIR_LOCO));+ jetReloadTrace(jet, "RESUME-PENDING", d.str());+ }aiDoCommand(&parms);}else if (m_returnToBaseFrame != 0 && now >= m_returnToBaseFrame && getFlag(ALLOW_AIR_LOCO))@@ -1924,6 +1961,12 @@ UpdateSleepTime JetAIUpdate::update()if (getFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD) &&isOutOfSpecialReloadAmmo() && getFlag(ALLOW_AIR_LOCO)){+ {+ AsciiString d;+ d.format("(saved cmd=%d, state=%d)", (Int)m_mostRecentCommand.getCommandType(),+ (Int)getStateMachine()->getCurrentStateID());+ jetReloadTrace(jet, "INTERRUPT-FOR-RELOAD", d.str());+ }setFlag(USE_SPECIAL_RETURN_LOCO, true);setFlag(HAS_PENDING_COMMAND, true);setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, false);@@ -2409,6 +2452,15 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)if (!isAllowedToRespondToAiCommands(parms))return;+ {+ AsciiString d;+ d.format("(cmd=%d, src=%d, airLoco=%d, takeoff=%d, landing=%d, state=%d)",+ (Int)parms->m_cmd, (Int)parms->m_cmdSource, (Int)getFlag(ALLOW_AIR_LOCO),+ (Int)getFlag(TAKEOFF_IN_PROGRESS), (Int)getFlag(LANDING_IN_PROGRESS),+ (Int)getStateMachine()->getCurrentStateID());+ jetReloadTrace(getObject(), "DO-COMMAND", d.str());+ }+// note that we always store this, even if nothing will be "pending".m_mostRecentCommand.store(*parms);