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
fix(gameengine): stop a capture when the capturer walks away
Olcay Seygan07816d8522e2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 983690335..f669ef64b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -283,6 +283,7 @@ found and fixed — EA's own, not port damage.**## Twenty-two-year-old bugs, found by testing+- A rifleman pulled off an oil derrick mid-capture left it flashing and chiming for the rest of the match, and the derrick changed hands anyway with nobody standing on it. Walking away now stops the capture, whether you or the computer gave the order.- Every countdown on screen was a second too long. Rounding up a whole number of seconds gave a whole number plus one, so a ten second build said eleven - production queues, buildings going up, superweapons, all of it.- A Chinese silo researching an upgrade while its missile charged drew both bars and both countdowns in the same row of pixels. They stack now.- Units moving diagonally ran up to 40% faster than their own stat sheet.@@ -379,6 +380,7 @@ found and fixed — EA's own, not port damage.**- The videos play: the intro, the sizzle reel, the mission briefings, the general portraits.- About 5,600 graphics calls are translated to a modern path, none of them touched.- No disc, no registry keys, no retail installer — a normal install works.+- The startup screen is this build's own, so you can see which one you launched before the menu loads.- The 1.04 patch content is reachable again.---diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SpecialAbilityUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SpecialAbilityUpdate.hindex ebc3da407..b53b14735 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SpecialAbilityUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SpecialAbilityUpdate.h@@ -46,6 +46,24 @@ enum SpecialPowerType;#define SPECIAL_ABILITY_HUGE_DISTANCE 10000000.0f+//-------------------------------------------------------------------------------------------------+/** Walking away from a special ability in progress breaks it off - a rifleman ordered off a+ * building he is halfway through capturing has stopped capturing it. The one movement that does+ * not count is the turn towards the target the ability itself asks for: that is the ability+ * working, not the unit leaving.+ *+ * Only the turn, though. Reading "the facing has been initiated" as the exemption meant the+ * exemption never ended - the flag is set once when the turn starts and cleared only when the+ * whole ability restarts - so from that frame on, nothing this unit did could break the capture.+ * Human orders still stopped it through the command-source check, but an AI's orders look+ * exactly like the ability's own, so a bot pulling its infantry off a derrick under fire left+ * the building flashing and ticking with nobody on it. */+//-------------------------------------------------------------------------------------------------+inline Bool abilityBrokenByMovement( Bool isMoving, Bool powerInUse, Bool facingInitiated, Bool facingComplete )+{+ return isMoving && powerInUse && !( facingInitiated && !facingComplete );+}+//-------------------------------------------------------------------------------------------------class SpecialAbilityUpdateModuleData : public UpdateModuleData{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 1cf269436..a8fcf84e4 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -4631,6 +4631,17 @@ void AIPlayer::doCapture( void )if( ai == NULL || !ai->isIdle() )return; // still on its way+ //+ // A capture in progress reads as idle - the ability parks the unit's AI while it works - so+ // this check used to come round every five seconds and order the same capture again on the+ // same building, restarting it before it could finish. On anything whose capture takes longer+ // than the check rate that is a loop with no way out: the derrick flashed and ticked forever+ // with a rifleman standing on it, and each restart left another copy of the ability's loop+ // sound playing.+ //+ if( capturer->testStatus( OBJECT_STATUS_IS_USING_ABILITY ) )+ return; // already taking one+if( target == NULL ){// nothing left to take: sit on what we own rather than wander home and let it be taken backdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cppindex f6fa9137d..e9237f7ef 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp@@ -230,10 +230,11 @@ UpdateSleepTime SpecialAbilityUpdate::update( void )onExit( false );return calcSleepTime();}- if( ai->isMoving() && isPowerCurrentlyInUse() && !m_facingInitiated )+ if( abilityBrokenByMovement( ai->isMoving(), isPowerCurrentlyInUse(), m_facingInitiated, m_facingComplete ) ){// Capture is broken by movement just as if we had been given a direct command (above check).// However, the time of Facing the target is considered isPowerCurrentlyInUse, but isMoving. So let that slide.+ // (Only the turn itself - see abilityBrokenByMovement for what that used to let through.)switch(data->m_specialPowerTemplate->getSpecialPowerType() ){case SPECIAL_INFANTRY_CAPTURE_BUILDING:@@ -501,6 +502,7 @@ Bool SpecialAbilityUpdate::initiateIntentToDoSpecialPower( const SpecialPowerTemm_facingInitiated = false;m_facingComplete = false;m_withinStartAbilityRange = false;+ m_captureFlashPhase = 0.0f; // a restarted capture starts its flash over, not part way up the ramp// getObject()->getControllingPlayer()->getAcademyStats()->recordSpecialPowerUsed( specialPowerTemplate );@@ -1095,6 +1097,10 @@ void SpecialAbilityUpdate::startPreparation()}getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_IS_USING_ABILITY ) );+ // the handle is the only way to stop a looping sound, so drop the last one before it is+ // overwritten - a preparation that starts twice used to leave the first loop playing forever+ TheAudio->removeAudioEvent( m_prepSoundLoop.getPlayingHandle() );+m_prepSoundLoop = data->m_prepSoundLoop;m_prepSoundLoop.setObjectID( getObject()->getID() );m_prepSoundLoop.setPlayingHandle( TheAudio->addAudioEvent( &m_prepSoundLoop ) );diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 665428f6a..422243073 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -69,6 +69,7 @@#include "GameLogic/AI.h"#include "GameLogic/Module/ProductionUpdate.h"#include "GameLogic/Module/SupplyTruckAIUpdate.h"+#include "GameLogic/Module/SpecialAbilityUpdate.h"#include "GameClient/InGameUI.h"#include "GameClient/View.h"#include "GameLogic/IncomingDamage.h"@@ -6200,3 +6201,28 @@ TEST(every_role_commits_at_its_own_moment_and_none_of_them_is_a_bonus)CHECK_NEAR( aiEnemyCost( dist, FALSE, FALSE, FALSE, 0.5f, FALSE ),aiEnemyCost( dist, FALSE, FALSE, FALSE, 0.5f, TRUE ), 0.001f );}+++/** A capture in progress is broken by the capturing unit walking away - that is the whole of the+ rule, and the only movement exempt from it is the turn towards the target that the ability+ itself orders. The exemption used to be "the facing has started", a flag that is never cleared+ once set, so after the first turn nothing the unit did could break the capture: an AI ordering+ its riflemen to run from a fight left the derrick they were on flashing and sounding its+ capture tick with nobody there, and it changed hands anyway. */+TEST(walking_away_breaks_a_capture_but_turning_towards_it_does_not)+{+ // standing on the building, working: nothing to break+ CHECK( !abilityBrokenByMovement( FALSE, TRUE, TRUE, TRUE ) );++ // the ability's own turn towards the target: moving, but not leaving+ CHECK( !abilityBrokenByMovement( TRUE, TRUE, TRUE, FALSE ) );++ // the turn is over and the unit is moving again: it has left, whoever ordered it+ CHECK( abilityBrokenByMovement( TRUE, TRUE, TRUE, TRUE ) );++ // an ability that never faces its target (NeedToFaceTarget = No) is broken by movement too+ CHECK( abilityBrokenByMovement( TRUE, TRUE, FALSE, FALSE ) );++ // and nothing is broken when no power is up: walking is just walking+ CHECK( !abilityBrokenByMovement( TRUE, FALSE, TRUE, TRUE ) );+}