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(gamelogic): end a supply docking on the box that finishes it
Olcay Seyganb9ac40bd86d0
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.hindex ea8790849..afcf05af4 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h@@ -48,6 +48,17 @@ inline Real dockActionProgress( UnsignedInt now, UnsignedInt start, UnsignedIntreturn INT_TO_REAL( now - start ) / INT_TO_REAL( end - start );}+//-------------------------------------------------------------------------------------------------+/** Is there another box in this for the docker after the one just handed over? Asked the moment a+ * box changes hands, so that a docking that is finished ends there and then: a docker that stays+ * docked spends another whole action delay before finding out there was nothing left to take,+ * and the bar over its head fills again for a box that never arrives. */+//-------------------------------------------------------------------------------------------------+inline Bool supplyDockHasNextBox( Int stockLeft, Int dockerBoxes, Int dockerMax )+{+ return stockLeft > 0 && dockerBoxes < dockerMax;+}+//-------------------------------------------------------------------------------------------------class SupplyTruckStateMachine : public StateMachine{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cppindex 3f1a37b10..fa5a6fa8e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp@@ -628,7 +628,6 @@ StateReturnType AIDockProcessDockState::update( void )// Some dockers can have a delay built inif( TheGameLogic->getFrame() < m_nextDockActionFrame )return STATE_CONTINUE;- setNextDockActionFrame();Object *drone = findMyDrone();@@ -636,6 +635,14 @@ StateReturnType AIDockProcessDockState::update( void )if( dock->isDockOpen() == false || dock->action( getMachineOwner(), drone ) == false )return STATE_SUCCESS;+ //+ // Only now, with one more transfer actually going to happen, does the next window open. It+ // used to be opened before the action, so the very transfer that ended the docking restarted+ // the bar over the worker's head and then walked off: the worker left the moment its own+ // progress bar reset to nothing, which is what "it leaves before it has finished" looks like.+ //+ setNextDockActionFrame();+return STATE_CONTINUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cppindex ccfcd5b8c..b7765a322 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp@@ -132,6 +132,15 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone )}}+ //+ // A docker that is full, or a warehouse with nothing left in it, has no next box - so say+ // so now, on the frame the last one is handed over. Answering TRUE bought the worker one+ // more whole action delay standing at the warehouse taking nothing, with the bar over its+ // head filling a second time for a box that was never coming.+ //+ if( !supplyDockHasNextBox( m_boxesStored, ai->getNumberBoxes(), ai->getMaxBoxes() ) )+ return FALSE;+return TRUE;}elsediff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 86cf89f3d..02d489ed4 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -6163,6 +6163,28 @@ TEST(a_dock_action_bar_fills_across_its_window_and_shows_nothing_outside_it)CHECK( dockActionProgress( 100, 100, 100 ) < 0.0f );}+/** A docking ends on the frame the last box changes hands, not one action delay later. Both ends+ can finish it: the docker filling up, or the pile running out. Staying docked past that point+ cost a worker a whole extra delay per trip standing at a pile it could take nothing from. */+TEST(a_supply_docking_ends_on_the_box_that_finishes_it)+{+ // mid-load: pile has plenty, worker has room+ CHECK( supplyDockHasNextBox( 40, 3, 8 ) );++ // the box that fills the worker is the last one+ CHECK( !supplyDockHasNextBox( 40, 8, 8 ) );+ CHECK( !supplyDockHasNextBox( 40, 9, 8 ) ); // over-full is still full++ // so is the box that empties the pile, even for a worker with room left+ CHECK( !supplyDockHasNextBox( 0, 3, 8 ) );++ // and both at once+ CHECK( !supplyDockHasNextBox( 0, 8, 8 ) );++ // one box left and room for it: worth staying for+ CHECK( supplyDockHasNextBox( 1, 7, 8 ) );+}+/** EA's floor and ceil nudged the value by the largest float below one and truncated. The nudgedoes not survive the addition: for anything from 2 upwards, f + 0.99999994 rounds to f + 1, so