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): let factory doors shut while the next unit is far off
Olcay Seygan51b8f0a4d729
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 08893f3b4..001e40b55 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1098,7 +1098,7 @@ found and fixed, EA's own, not port damage.**- A bounty pays what the percentage says. Rounding up a fraction that was already a whole number paid a dollar extra on every kill.- A supply upgrade pays for what arrives. The bonus was a flat sum handed over on arrival, so a truck turning up with one box collected the same as a full load - and a driver dropping off little and often earned several times what the upgrade is worth.- Taking over a defeated ally's base no longer starts his research again from scratch. A player upgrade is bought once for the whole player, and the buildings you inherit were left paying for a second copy of what you already had.-- A tank drives out the moment it is paid for. The factory doors only began opening once the vehicle was already finished, and it stood inside waiting for them, so every single unit cost its build time plus the whole door animation on top - on every tank, all game. The doors now start moving during the last seconds of the build and are open on the frame the unit is done. And they stay open while there is another vehicle behind him, however long that takes: a factory working through a queue keeps its doors up and shuts them when the queue runs out, instead of dropping and hauling them back for every unit. That was worth watching in its own right - there is no artwork for a door that changes its mind partway, so a door caught mid-close and pulled back open snapped wide in a single frame.+- A tank drives out the moment it is paid for. The factory doors only began opening once the vehicle was already finished, and it stood inside waiting for them, so every single unit cost its build time plus the whole door animation on top - on every tank, all game. The doors now start moving during the last seconds of the build and are open on the frame the unit is done. And they stay open while the next vehicle is close behind him: a factory working through a queue keeps its doors up and shuts them when the queue runs out, instead of dropping and hauling them back for every unit. One still a long way off lets them shut in between; a Command Center training a second engineer used to stand with its gate open and nobody in it for eighteen seconds. That was worth watching in its own right - there is no artwork for a door that changes its mind partway, so a door caught mid-close and pulled back open snapped wide in a single frame.- A unit lifts the fog only half as far again as its guns reach: enough to spot what it is about to fight, not enough to scout. A rifleman used to see well past the range of his rifle, so any cheap soldier was a scout. Artillery that outshoots its own eyes still needs a spotter, and units with no weapon at all, like bulldozers and supply trucks, keep the sight they had. Buildings are unchanged.- Workers and bulldozers can see again. Each one carries a mine-clearing tool a few feet long, and the rule above took it for a gun, so a builder saw no further than the end of its own blade and walked into the fog blind. They keep their full sight now, armed or not.- Hills and buildings block sight. A tank at the foot of a ridge used to see straight through it to the far side, and a squad in a city saw through every block around it. Now the fog stays on whatever a ridge, a building or a tree hides, yours, the enemy's or a civilian's, and a unit on high ground looks down over everything below it. Aircraft fly above it all and see past. Soldiers garrisoned in a building still see out of it; its own walls do not blind them.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cppindex 8a8e3449b..3d533b7d7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp@@ -589,6 +589,19 @@ Bool Production_shouldCloseDoorNow( UnsignedInt framesWaitingOpen, UnsignedInt dreturn framesWaitingOpen > doorWaitOpenTime && !holdOpen && !moreUnitsComing;}+//-------------------------------------------------------------------------------------------------+/** Whether the unit at the head of the queue is close enough behind to keep the door up for. Any+ * queued unit used to count, so an engineer with eighteen seconds still to build held the gate+ * open the whole time with nobody in it; retail shuts after its wait and opens again for him.+ * Closing pays only if the door can shut and still start its early opening for him from shut:+ * the close clears one frame after its time, and the early open is checked one frame further on+ * than this (production counts its frame after the doors are updated), hence the +2. */+//-------------------------------------------------------------------------------------------------+Bool Production_isNextUnitDue( Int framesRemaining, UnsignedInt doorClosingTime, UnsignedInt doorOpeningTime )+{+ return framesRemaining <= (Int)(doorClosingTime + doorOpeningTime) + 2;+}+//-------------------------------------------------------------------------------------------------/** Update the door behavior *///-------------------------------------------------------------------------------------------------@@ -729,10 +742,13 @@ UpdateSleepTime ProductionUpdate::update( void )UnsignedInt now = TheGameLogic->getFrame();Object *us = getObject();- // update the door behaviors. a unit still at the head of the queue is a unit still due out- // of a door, so the doors stay open for him instead of closing between the two.+ // update the door behaviors. a unit at the head of the queue that will be done before the door+ // could shut and open again is still due out of it, so the doors stay open for him instead of+ // closing between the two; one further off gets them shut and opened again on his own time.if( d->m_numDoorAnimations > 0 )- updateDoors( production != NULL && production->getProductionType() == PRODUCTION_UNIT );+ updateDoors( production != NULL && production->getProductionType() == PRODUCTION_UNIT &&+ Production_isNextUnitDue( production->m_totalProductionFrames - production->m_framesUnderConstruction,+ d->m_doorClosingTime, d->m_doorOpeningTime ) );//// if we're in the construction complete state ... we need to check framediff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 8e4dddeba..58bf432e9 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -17960,6 +17960,27 @@ TEST(a_door_stays_open_while_another_unit_is_still_coming)CHECK( !Production_shouldCloseDoorNow( 31, 30, true, true ) );}+/* ProductionUpdate.cpp: but only a unit close behind holds it. Any queued unit used to count, so a+ Command Center training an engineer with eighteen seconds still to go stood with its gate open+ and empty the whole time. A unit far enough off that the door can shut and still open early for+ him from shut lets it close, as retail's stopwatch did. */+extern Bool Production_isNextUnitDue( Int framesRemaining, UnsignedInt doorClosingTime, UnsignedInt doorOpeningTime );++TEST(a_door_closes_on_a_unit_still_far_off)+{+ /* 90 frames to close and 90 to open, retail's 1.5 s each: 182 frames out he is still due. */+ CHECK( Production_isNextUnitDue( 182, 90, 90 ) );+ CHECK( Production_isNextUnitDue( 1, 90, 90 ) );++ /* finished and waiting on the door, or a fresh entry not yet measured: due. */+ CHECK( Production_isNextUnitDue( 0, 90, 90 ) );+ CHECK( Production_isNextUnitDue( -5, 90, 90 ) );++ /* one frame further and there is time to shut first; eighteen seconds certainly is. */+ CHECK( !Production_isNextUnitDue( 183, 90, 90 ) );+ CHECK( !Production_isNextUnitDue( 1080, 90, 90 ) );+}+/* ProductionUpdate.h: production repeat. A factory keeps one unit on repeat. Turning a secondon takes the first off. Turning the same one on again is a no-op, and off takes it out. */TEST(production_repeat_is_one_unit_at_a_time)