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
feat(gamelogic): take the whole load in one visit to a supply point
Olcay Seygan2d2db0aa9de7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 37d4a78e7..bfdec52d9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -361,6 +361,7 @@ found and fixed — EA's own, not port damage.**- A structure's button says what it does to the power grid, in the fourth corner: what it draws, or what a plant puts back. Money and time were already on the button and power is the third thing a base spends; it was the one figure you had to hover for, which is the wrong way round for the building you are putting up because the lights went out.- A worker fetching or handing over a box shows a bar while it works.- That bar is now the work itself. A worker used to reset it to empty at the very moment it finished and then walk away, so every trip looked like it left mid-handover; and after taking its last box it stood at the pile for one more full loading cycle, taking nothing. It leaves the instant the load is done - which is a little more money per trip, on every worker you own.+- A worker loads in one go instead of a box at a time. It used to take one, wait a loading cycle, take the next, wait again, and the bar over its head restarted for each of them; now the whole load changes hands once and the wait is that load's worth of time - four boxes cost what four boxes always cost, in one stretch rather than four. Money in the bank is unchanged, which is the point: three headless matches on the same seeds came back within a few percent of what they earned before.- Supply points refill themselves, slowly, and faster the more of a base has grown around them. A warehouse used to be a fixed lump of money that ran out and left the map with nothing to fight over: whoever mined out the middle first had the game, and the second half of every match was played on income neither side could earn any more. A box comes back every forty seconds standing on its own, every twenty with one supply centre built near it, every thirteen with two - up to what the point started with, never past it. Both sides expanding onto the same patch make it richer and then have to decide which of them keeps it.- Workers stop hesitating on their way in and out. A dock has a queue outside it and a worker treated its place in that queue as a destination: it drove to the spot, stopped dead, waited a frame, drove to the door, stopped again, and only then went in - twice a load, and nearly every load with nothing else queued. With the dock empty it drives straight in.- Hackers show how far off the next payout is. So do the black market and the oil derricks.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.hindex afcf05af4..c2ec4892a 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h@@ -59,6 +59,25 @@ inline Bool supplyDockHasNextBox( Int stockLeft, Int dockerBoxes, Int dockerMaxreturn stockLeft > 0 && dockerBoxes < dockerMax;}+//-------------------------------------------------------------------------------------------------+/** How long one visit to a supply point takes. The whole load changes hands in a single action+ * now, so the visit is priced by what that load is: SupplyWarehouseActionDelay buys one box, and+ * a docker leaving with four of them waits for four. Same total as taking them one at a time,+ * one bar instead of four.+ *+ * The price is fixed when the docking opens, so a box another worker takes out of the pile while+ * this one is loading is not refunded, and one the pile grows back is carried for free. */+//-------------------------------------------------------------------------------------------------+inline UnsignedInt supplyWarehouseActionDelay( UnsignedInt perBoxDelay, Int stockLeft, Int dockerBoxes, Int dockerMax )+{+ const Int room = dockerMax - dockerBoxes;+ Int boxes = ( stockLeft < room ) ? stockLeft : room;+ if( boxes < 1 )+ boxes = 1; // nothing to take, but the docker still walks up and finds that out++ return perBoxDelay * (UnsignedInt)boxes;+}+//-------------------------------------------------------------------------------------------------class SupplyTruckStateMachine : public StateMachine{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cppindex f8fe4ed0c..4958eb85b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp@@ -230,7 +230,9 @@ UnsignedInt SupplyTruckAIUpdate::getActionDelayForDock( Object *dock )static const NameKeyType key_warehouseUpdate = NAMEKEY("SupplyWarehouseDockUpdate");SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate*) dock->findUpdateModule( key_warehouseUpdate );if (warehouseModule) {- return getSupplyTruckAIUpdateModuleData()->m_warehouseDelay;+ // One action moves the whole load, so the wait is the whole load's worth of action delay.+ return supplyWarehouseActionDelay( getSupplyTruckAIUpdateModuleData()->m_warehouseDelay,+ warehouseModule->getBoxesStored(), m_numberBoxes, getMaxBoxes() );}static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate");SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*) dock->findUpdateModule( key_centerUpdate );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cppindex 52d9b01ba..212388c15 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp@@ -228,7 +228,9 @@ UnsignedInt WorkerAIUpdate::getActionDelayForDock( Object *dock )static const NameKeyType key_warehouseUpdate = NAMEKEY("SupplyWarehouseDockUpdate");SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate*) dock->findUpdateModule( key_warehouseUpdate );if (warehouseModule) {- return getWorkerAIUpdateModuleData()->m_warehouseDelay;+ // One action moves the whole load, so the wait is the whole load's worth of action delay.+ return supplyWarehouseActionDelay( getWorkerAIUpdateModuleData()->m_warehouseDelay,+ warehouseModule->getBoxesStored(), getNumberBoxes(), getMaxBoxes() );}static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate");SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*) dock->findUpdateModule( key_centerUpdate );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cppindex ce116b22d..637573de9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp@@ -209,44 +209,49 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone )return FALSE; //not close enough.}- --m_boxesStored;// so the docker sees that I am shy by one box (or empty) from within his gainOneBox()-// getAIUpdateInterface() can be NULL here and was dereferenced blind (the sibling- // SupplyCenterDockUpdate does check). The ai==NULL path below already puts the box back.+ // SupplyCenterDockUpdate does check). The no-room path below puts the box back.AIUpdateInterface *dockerAI = docker->getAIUpdateInterface();SupplyTruckAIInterface *ai = dockerAI ? dockerAI->getSupplyTruckAIInterface() : NULL;- if( ai && ai->gainOneBox( m_boxesStored ) )++ //+ // The whole load in one visit. A box per action delay left a worker parked here for MaxBoxes+ // times SupplyWarehouseActionDelay to collect what one trip pays, and the walk was already the+ // expensive half. The supply centre end has always emptied a truck in one go+ // (SupplyCenterDockUpdate's `while( loseOneBox() )`); this is the same on the pick-up end.+ //+ Int taken = 0;+ while( ai && m_boxesStored > 0 ){- if( m_boxesStored == 0 && getSupplyWarehouseDockUpdateModuleData()->m_deleteWhenEmpty )+ --m_boxesStored;// so the docker sees that I am shy by one box (or empty) from within his gainOneBox()+ if( !ai->gainOneBox( m_boxesStored ) ){- TheGameLogic->destroyObject( getObject() );- return FALSE; //Yer done. And so am I.- }- else- {- Drawable *draw = getObject()->getDrawable();- if( draw )- {- draw->updateDrawableSupplyStatus( getSupplyWarehouseDockUpdateModuleData()->m_startingBoxesData, m_boxesStored );- }+ ++m_boxesStored; //take it back, since he had no room for it+ //this is important so that I have one less boxes as perceived by the docker when he gains one+ break;}+ ++taken;- //- // 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;+ break;+ }++ if( taken == 0 )+ return FALSE; //nobody to gain the boxes, or nowhere to put them- return TRUE;+ if( m_boxesStored == 0 && getSupplyWarehouseDockUpdateModuleData()->m_deleteWhenEmpty )+ {+ TheGameLogic->destroyObject( getObject() );+ return FALSE; //Yer done. And so am I.}- else- ++m_boxesStored; //take it back, since there was noone to gain the box- //this is important so that I have one less boxes as perceived by the docker when he gains one+ Drawable *draw = getObject()->getDrawable();+ if( draw )+ {+ draw->updateDrawableSupplyStatus( getSupplyWarehouseDockUpdateModuleData()->m_startingBoxesData, m_boxesStored );+ }+ // A full docker, or an empty warehouse: either way there is no second action to wait for.return FALSE;}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex b58b82b25..4c7129200 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -6735,6 +6735,29 @@ TEST(a_supply_docking_ends_on_the_box_that_finishes_it)CHECK( supplyDockHasNextBox( 1, 7, 8 ) );}+/** The whole load changes hands in one action, and that action is priced by the load: the INI's+ SupplyWarehouseActionDelay buys one box, so a full load of eight waits for eight of them. Same+ total time as taking them one at a time, one trip instead of one per box. */+TEST(a_supply_visit_costs_what_the_load_costs)+{+ // empty worker, full pile: the whole load+ CHECK_EQ( 8u * 30u, supplyWarehouseActionDelay( 30, 40, 0, 8 ) );++ // half loaded already: only the room left is paid for+ CHECK_EQ( 5u * 30u, supplyWarehouseActionDelay( 30, 40, 3, 8 ) );++ // a pile with less in it than the worker can carry prices what is actually there+ CHECK_EQ( 2u * 30u, supplyWarehouseActionDelay( 30, 2, 0, 8 ) );++ // nothing to take: one delay, and the worker finds that out when it gets there+ CHECK_EQ( 30u, supplyWarehouseActionDelay( 30, 0, 0, 8 ) );+ CHECK_EQ( 30u, supplyWarehouseActionDelay( 30, 40, 8, 8 ) );+ CHECK_EQ( 30u, supplyWarehouseActionDelay( 30, 40, 9, 8 ) ); // over-full does not go negative++ // one box, one delay - which is what every trip used to cost per box+ CHECK_EQ( 30u, supplyWarehouseActionDelay( 30, 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