Skip to content

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.

fix(gameengine): floor the leg between two supply dockings

Olcay Seygan3f7650684150
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 12910dd84..24891a22d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -672,6 +672,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- 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.
+- A GLA worker can no longer mint money standing still. Build a stash as close to a supply pile as the game allows and a worker could end up in the gap between them, touching both. It loaded at the pile and unloaded at the stash without taking a step, a $75 box every second, and the popups stacked over its head. Every hand-over now waits until a worker could have walked the gap, so that worker earns what a worker walking the shortest trip earns: with a stash hugging a pile, two workers brought in 101 boxes in a minute before and 50 now. Workers that do walk are untouched; a stash placed so they have to earned exactly the same, box for box, before and after.
- 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. Six hundred dollars 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. A single box was too little to be worth the trip: a hundred dollars every forty seconds is less than the harvester earns going to fetch it, so a mined-out point stayed mined out as far as anybody playing was concerned. Both sides expanding onto the same patch make it richer and then have to decide which of them keeps it.
- Your workers tell you a supply point has run dry once a match. With piles refilling, they ran dry again and again, and every time the same worker said so.
- 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. The first version of that also skipped the walk to a supply pile or a GLA stash, which have no door of their own, so a worker a long way off played its loading animation where it stood and was paid anyway. In a four-player test match 72 loads were picked up or dropped off away from the dock, one of them 613 feet from it; now there are none.
diff --git a/GeneralsMD/Code/Data/Scenarios/stashbeside.txt b/GeneralsMD/Code/Data/Scenarios/stashbeside.txt
new file mode 100644
index 000000000..3a4492961
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/stashbeside.txt
@@ -0,0 +1,30 @@
+# A GLA supply stash built as close to a supply pile as SupplyBuildBorder allows (90 feet centre to
+# centre, a gap about 24 feet wide between them), one worker sent to the pile. Neither building has
+# dock bones, so a worker standing in the gap is on both approach spots at once and never walks.
+# The money column of each tally line is the seat's cash; the difference between two lines over the
+# frames between them is the income. The workers that end up on the pile are the spawned one and
+# the stash's own.
+#
+# Before the leg floor: 101 deliveries by frame 1860, money 17425. After it: 50, money 13675.
+# A stash at 830 920 (closer than a player may build) has its workers walk, and earned 11950 both ways.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover
+# -side 0 FactionGLA -side 1 FactionAmerica -seed 1 -maxframes 1900
+# -scenario stashbeside -logPrefix stashbeside_
+#
+# See mobstress.txt for the line grammar.
+
+30 spawn 0 SupplyPile 1 760 920
+30 spawn 0 GLASupplyStash 1 670 920
+30 spawn 0 GLAInfantryWorker 1 715 960
+
+60 dock 0 GLAInfantryWorker 0 SupplyPile
+
+60 tally 0 GLAInfantryWorker
+360 tally 0 GLAInfantryWorker
+660 tally 0 GLAInfantryWorker
+960 tally 0 GLAInfantryWorker
+1260 tally 0 GLAInfantryWorker
+1560 tally 0 GLAInfantryWorker
+1860 tally 0 GLAInfantryWorker
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h
index 8ef869fe3..2f5383c41 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h
@@ -59,6 +59,27 @@ inline Bool supplyDockHasNextBox( Int stockLeft, Int dockerBoxes, Int dockerMax
return stockLeft > 0 && dockerBoxes < dockerMax;
}
+//-------------------------------------------------------------------------------------------------
+/** The shortest a leg between two supply dockings may take, pile to centre or centre to pile. A
+ * supply pile and a GLA stash have no dock bones, so each one docks a worker wherever its approach
+ * spot is, and that spot is the clear ground nearest the building on the worker's side. A stash
+ * built at the legal limit leaves a gap about 24 feet wide beside the pile, and a worker standing
+ * in it is on both approach spots at once: it loaded and unloaded without taking a step, a box
+ * every 15 frames where a worker that walks the same gap needs 37 or more. 37 frames is that
+ * shortest walked leg, so the floor only ever catches a worker that did not walk. */
+//-------------------------------------------------------------------------------------------------
+enum { SUPPLY_DOCK_MIN_LEG_FRAMES = 37 };
+
+inline UnsignedInt supplyDockLegDelay( UnsignedInt dockDelay, UnsignedInt now, UnsignedInt lastActionFrame )
+{
+ // 0 is a docker that has never docked
+ const UnsignedInt earliest = lastActionFrame + SUPPLY_DOCK_MIN_LEG_FRAMES;
+ if( lastActionFrame == 0 || now >= earliest || earliest - now <= dockDelay )
+ return dockDelay;
+
+ return earliest - now;
+}
+
//-------------------------------------------------------------------------------------------------
/** 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
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index c72ba9208..b7ad9553f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -80,7 +80,8 @@ enum ScenarioActionType
SCENARIO_ACTION_SHIFTATTACK, ///< shiftattack <slot> <selector> <targetSlot> <targetSelector>; the same with an attack on one unit
SCENARIO_ACTION_SHIFTGUARD, ///< shiftguard <slot> <selector> <position>; the same with the guard key
SCENARIO_ACTION_SHIFTPOWER, ///< shiftpower <slot> <selector> <targetSlot> <targetSelector> <power>; the same with a special power armed, on one object
- SCENARIO_ACTION_SHIFTUPGRADE ///< shiftupgrade <slot> <selector> <upgrade>; shift on an object upgrade button, bought by every unit that matches
+ SCENARIO_ACTION_SHIFTUPGRADE, ///< shiftupgrade <slot> <selector> <upgrade>; shift on an object upgrade button, bought by every unit that matches
+ SCENARIO_ACTION_DOCK ///< dock <slot> <selector> <targetSlot> <targetSelector>; a right click on a supply point or a dock
};
/// ScenarioAction::atStart when the position is plain numbers
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
index 40bb4aa28..95f0f8441 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
@@ -232,13 +232,15 @@ UnsignedInt SupplyTruckAIUpdate::getActionDelayForDock( Object *dock )
SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate*) dock->findUpdateModule( key_warehouseUpdate );
if (warehouseModule) {
// 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() );
+ // Never sooner after the last docking than a walk could have been: see supplyDockLegDelay.
+ return supplyDockLegDelay( supplyWarehouseActionDelay( getSupplyTruckAIUpdateModuleData()->m_warehouseDelay,
+ warehouseModule->getBoxesStored(), m_numberBoxes, getMaxBoxes() ),
+ TheGameLogic->getFrame(), m_dockActionEndFrame );
}
static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate");
SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*) dock->findUpdateModule( key_centerUpdate );
if (centerModule) {
- return getSupplyTruckAIUpdateModuleData()->m_centerDelay;
+ return supplyDockLegDelay( getSupplyTruckAIUpdateModuleData()->m_centerDelay, TheGameLogic->getFrame(), m_dockActionEndFrame );
}
return 0;
@@ -295,11 +297,12 @@ void SupplyTruckAIUpdate::crc( Xfer *xfer )
// ------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
- * 1: Initial version */
+ * 1: Initial version
+ * 2: The dock action window, which now times the shortest leg between two supply dockings */
// ------------------------------------------------------------------------------------------------
void SupplyTruckAIUpdate::xfer( Xfer *xfer )
{
- XferVersion currentVersion = 1;
+ XferVersion currentVersion = 2;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -310,6 +313,11 @@ void SupplyTruckAIUpdate::xfer( Xfer *xfer )
xfer->xferObjectID(&m_preferredDock);
xfer->xferInt(&m_numberBoxes);
xfer->xferBool(&m_forcePending);
+ if( version >= 2 )
+ {
+ xfer->xferUnsignedInt(&m_dockActionStartFrame);
+ xfer->xferUnsignedInt(&m_dockActionEndFrame);
+ }
} // end xfer
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp
index 4e8298751..c6b5dc40b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp
@@ -229,13 +229,15 @@ UnsignedInt WorkerAIUpdate::getActionDelayForDock( Object *dock )
SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate*) dock->findUpdateModule( key_warehouseUpdate );
if (warehouseModule) {
// 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() );
+ // Never sooner after the last docking than a walk could have been: see supplyDockLegDelay.
+ return supplyDockLegDelay( supplyWarehouseActionDelay( getWorkerAIUpdateModuleData()->m_warehouseDelay,
+ warehouseModule->getBoxesStored(), getNumberBoxes(), getMaxBoxes() ),
+ TheGameLogic->getFrame(), m_dockActionEndFrame );
}
static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate");
SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*) dock->findUpdateModule( key_centerUpdate );
if (centerModule) {
- return getWorkerAIUpdateModuleData()->m_centerDelay;
+ return supplyDockLegDelay( getWorkerAIUpdateModuleData()->m_centerDelay, TheGameLogic->getFrame(), m_dockActionEndFrame );
}
return 0;
@@ -1497,11 +1499,12 @@ void WorkerAIUpdate::crc( Xfer *xfer )
// ------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
- * 1: Initial version */
+ * 1: Initial version
+ * 2: The dock action window, which now times the shortest leg between two supply dockings */
// ------------------------------------------------------------------------------------------------
void WorkerAIUpdate::xfer( Xfer *xfer )
{
- XferVersion currentVersion = 1;
+ XferVersion currentVersion = 2;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -1545,6 +1548,11 @@ void WorkerAIUpdate::xfer( Xfer *xfer )
xfer->xferObjectID(&m_preferredDock);
xfer->xferInt(&m_numberBoxes);
xfer->xferBool(&m_forcePending);
+ if( version >= 2 )
+ {
+ xfer->xferUnsignedInt(&m_dockActionStartFrame);
+ xfer->xferUnsignedInt(&m_dockActionEndFrame);
+ }
//-------------------------- xfer Worker info
xfer->xferSnapshot(m_workerMachine);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index 6ceac3532..0ff427e2c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -176,6 +176,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_ATTACK;
else if (token == "enter")
*action = SCENARIO_ACTION_ENTER;
+ else if (token == "dock")
+ *action = SCENARIO_ACTION_DOCK;
else if (token == "stop")
*action = SCENARIO_ACTION_STOP;
else if (token == "arrive")
@@ -286,6 +288,7 @@ static Int tokensNeededFor( ScenarioActionType action )
case SCENARIO_ACTION_SHIFTUPGRADE: return SCENARIO_TOKENS_SHIFTUPGRADE;
case SCENARIO_ACTION_ATTACK: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_ENTER: return SCENARIO_TOKENS_ATTACK;
+ case SCENARIO_ACTION_DOCK: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_PRODUCE: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_STOP: return SCENARIO_TOKENS_STOP;
case SCENARIO_ACTION_TALLY: return SCENARIO_TOKENS_STOP;
@@ -373,6 +376,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
case SCENARIO_ACTION_ATTACK:
case SCENARIO_ACTION_ENTER:
+ case SCENARIO_ACTION_DOCK:
case SCENARIO_ACTION_SHIFTATTACK:
case SCENARIO_ACTION_SHIFTPOWER:
{
@@ -1026,8 +1030,9 @@ static Bool executeTally( const ScenarioAction &action, Player *player )
worth += obj->getTemplate()->friend_getBuildCost();
}
- DEBUG_LOG(("HEADLESS TALLY: frame %d slot %d '%s': %d alive, health %.0f of %.0f, worth %d, %d inside\n",
- action.frame, action.slot, action.selector.str(), alive, health, maxHealth, worth, inside));
+ DEBUG_LOG(("HEADLESS TALLY: frame %d slot %d '%s': %d alive, health %.0f of %.0f, worth %d, %d inside, money %d\n",
+ action.frame, action.slot, action.selector.str(), alive, health, maxHealth, worth, inside,
+ player->getMoney()->countMoney()));
return TRUE;
}
@@ -1183,8 +1188,10 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
case SCENARIO_ACTION_ATTACK:
case SCENARIO_ACTION_ENTER:
+ case SCENARIO_ACTION_DOCK:
{
- const char *verb = (action.action == SCENARIO_ACTION_ATTACK) ? "attack" : "enter";
+ const char *verb = (action.action == SCENARIO_ACTION_ATTACK) ? "attack"
+ : (action.action == SCENARIO_ACTION_DOCK) ? "dock" : "enter";
Player *targetPlayer = findPlayerForSlot( action.targetSlot );
Object *target = (targetPlayer != NULL)
? findFirstMatching( targetPlayer, action.targetSelector )
@@ -1199,6 +1206,8 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
if (action.action == SCENARIO_ACTION_ATTACK)
group->groupAttackObject( target, SCENARIO_ATTACK_SHOTS, CMD_FROM_SCRIPT );
+ else if (action.action == SCENARIO_ACTION_DOCK)
+ group->groupDock( target, CMD_FROM_SCRIPT );
else
group->groupEnter( target, CMD_FROM_SCRIPT );
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index da2edefe1..38757731c 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -9415,6 +9415,25 @@ TEST(a_supply_visit_costs_what_the_load_costs)
CHECK_EQ( 30u, supplyWarehouseActionDelay( 30, 1, 7, 8 ) );
}
+/** A worker standing in the gap between a supply pile and a stash built beside it docked at both
+ without a step, a $75 box every 15 frames. A docking now waits out the rest of the shortest leg a
+ walking worker takes, counted from the last one; a worker that did walk never waits longer. */
+TEST(a_worker_that_does_not_walk_still_pays_for_the_walk)
+{
+ // docked at frame 1000, arrives at the other building 10 frames later with a 5-frame dock delay
+ CHECK_EQ( (UnsignedInt)SUPPLY_DOCK_MIN_LEG_FRAMES - 10, supplyDockLegDelay( 5, 1010, 1000 ) );
+
+ // walked the leg: only the dock's own delay
+ CHECK_EQ( 5u, supplyDockLegDelay( 5, 1000 + SUPPLY_DOCK_MIN_LEG_FRAMES, 1000 ) );
+ CHECK_EQ( 5u, supplyDockLegDelay( 5, 5000, 1000 ) );
+
+ // a dock delay longer than what is left of the leg is not shortened
+ CHECK_EQ( 90u, supplyDockLegDelay( 90, 1010, 1000 ) );
+
+ // never docked before
+ CHECK_EQ( 5u, supplyDockLegDelay( 5, 3, 0 ) );
+}
+
/** EA's floor and ceil nudged the value by the largest float below one and truncated. The nudge
does not survive the addition: for anything from 2 upwards, f + 0.99999994 rounds to f + 1, so