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): make the first percent, not placement, raise the building
Olcay Seyganfa23541c01ec
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b0b4d3cb2..451bc8042 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -118,6 +118,8 @@ found and fixed — EA's own, not port damage.**- Cancelling a plan is silent — nothing was built, so nothing explodes.- Ground your units have walked stays buildable after they leave it.- A plan opens no fog of its own, and your opponent never sees it.+- Your units walk straight over a plan — nothing solid is there until the builder starts work.+- The plan turns solid the instant the first work goes in, so no building goes up inside its own ghost.- The stop button prints its key on it, like the build buttons do.## Bonuses that come and go when they shoulddiff --git a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.hindex 74f4e68f3..0a7d7e777 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h@@ -198,20 +198,23 @@ public:void xferTheSellList(Xfer *xfer );+ /// will move objects that can move out of the way.+ /// will return false if there are objects that cannot be moved out of the way.+ /// 'ignore' is left where it stands - the builder is standing against the footprint on purpose,+ /// and shoving it away would cancel the very job it just started.+ Bool moveObjectsForConstruction( const ThingTemplate *whatToBuild,+ const Coord3D *pos, Real angle, Player *playerToBuild,+ const Object *ignore = NULL );+protected:/// some objects will be "cleared" automatically when constructingBool isRemovableForConstruction( Object *obj );-+/// clear the area of removable objects for construction- void clearRemovableForConstruction( const ThingTemplate *whatToBuild,+ void clearRemovableForConstruction( const ThingTemplate *whatToBuild,const Coord3D *pos, Real angle );- /// will move objects that can move out of the way.- /// will return false if there are objects that cannot be moved out of the way.- Bool moveObjectsForConstruction( const ThingTemplate *whatToBuild,- const Coord3D *pos, Real angle, Player *playerToBuild );-Coord3D *m_buildPositions; ///< array used to create a line of build locations (think walls)Int m_buildPositionSize; ///< number of elements in the build position arrayObjectSellList m_sellList; ///< list of objects currently going through the "sell process"diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex 01107c308..8829375d2 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -166,6 +166,10 @@ enum CrushSquishTestType//-------------------------------------------------------------------------------------------------extern Bool Object_isAwaitingBuilder( Bool underConstruction, Real constructionPercent );+///< has the builder just arrived, so the plan's footprint becomes solid to pathfinding now?+extern Bool Object_constructionFootprintGoesDown( Bool underConstruction, Real wasPercent,+ Real nowPercent );+///< how far a structure clears shroud, given where it is in its constructionextern Real Object_shroudClearingRange( Real ownRange, Bool underConstruction, Real constructionPercent,Real boundingCircleRadius );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cppindex 16c51f055..24d33961b 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp@@ -1445,9 +1445,10 @@ void BuildAssistant::clearRemovableForConstruction( const ThingTemplate *whatToBBool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuild,const Coord3D *pos,Real angle,- Player *playerToBuild )-{- GeometryInfo gi (GEOMETRY_BOX, false, 10, whatToBuild->getTemplateGeometryInfo().getMajorRadius(),+ Player *playerToBuild,+ const Object *ignore )+{+ GeometryInfo gi (GEOMETRY_BOX, false, 10, whatToBuild->getTemplateGeometryInfo().getMajorRadius(),whatToBuild->getTemplateGeometryInfo().getMajorRadius());if (whatToBuild->getTemplateGeometryInfo().getGeomType()==GEOMETRY_BOX) {gi = whatToBuild->getTemplateGeometryInfo();@@ -1464,6 +1465,10 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuilfor( Object *them = iter->first(); them; them = iter->next() ){+ // the builder itself docks against the footprint, so it collides with it by design+ if (them == ignore)+ continue;+//ignore land mines, cluster mines and demo traps, since you can build on them// doing so will damage them during construction, by the wayif (them->isKindOf( KINDOF_MINE ))diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex cb049fdff..e40378fe1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -3073,7 +3073,40 @@ void Object::setConstructionPercent( Real percent )Real delta = percent - m_constructionPercent;if( delta > 0.0f )m_constructionRateAccum += delta;++ //+ // A structure that has only been planned is not on the ground yet, so it is not in the pathfind+ // map either (see DozerAIUpdate/WorkerAIUpdate::construct) - a plan waiting for a free builder+ // stood there as a solid wall units had to walk around, which is a wall around a building that+ // does not exist. The footprint goes in here, on the first percent, which is every builder's+ // path into the ground: the dozer and the worker both come through this one call.+ //+ const Bool underConstruction = getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION );+ const Real wasPercent = m_constructionPercent;m_constructionPercent = percent;++ if( Object_constructionFootprintGoesDown( underConstruction, wasPercent, percent ) )+ {+ // whoever wandered into the site while it was only a plan gets out of the way now, exactly+ // as they would have when it was first placed - all but the builder, which is standing there+ // because it is the one building it+ TheBuildAssistant->moveObjectsForConstruction( getTemplate(), getPosition(), getOrientation(),+ getControllingPlayer(),+ TheGameLogic->findObjectByID( m_builderID ) );++ TheAI->pathfinder()->addObjectToPathfindMap( this );++ //+ // and the building starts putting itself up. This is the same frame the silhouette goes+ // solid (Drawable::getEffectiveOpacity asks Object_isAwaitingBuilder, which asks this very+ // percent), so the scaffold and the ghost never overlap - the builder arriving is not the+ // start of work, the first percent is.+ //+ clearAndSetModelConditionFlags(+ MAKE_MODELCONDITION_MASK( MODELCONDITION_AWAITING_CONSTRUCTION ),+ MAKE_MODELCONDITION_MASK2( MODELCONDITION_PARTIALLY_CONSTRUCTED,+ MODELCONDITION_ACTIVELY_BEING_CONSTRUCTED ) );+ }}//-------------------------------------------------------------------------------------------------@@ -5250,6 +5283,19 @@ Bool Object_isAwaitingBuilder( Bool underConstruction, Real constructionPercentreturn underConstruction && constructionPercent <= 0.0f;}+//-------------------------------------------------------------------------------------------------+/** The moment a plan stops being a plan: the builder has arrived and put the first percent in, so+ * the structure is now really standing there and its footprint becomes solid to pathfinding. Up+ * to here it was walk-through ground - a plan waiting for a free builder must not wall a base in+ * around a building nobody has started. Selling runs the percent back down and must not count:+ * the structure is already in the map and stays in it until it is gone. */+//-------------------------------------------------------------------------------------------------+Bool Object_constructionFootprintGoesDown( Bool underConstruction, Real wasPercent, Real nowPercent )+{+ return Object_isAwaitingBuilder( underConstruction, wasPercent ) &&+ !Object_isAwaitingBuilder( underConstruction, nowPercent );+}+//-------------------------------------------------------------------------------------------------Real Object_shroudClearingRange( Real ownRange, Bool underConstruction, Real constructionPercent,Real boundingCircleRadius )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cppindex 662a4dd9e..bcb68529f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp@@ -67,6 +67,26 @@ class DozerActionStateMachine;static const Real MIN_ACTION_TOLERANCE = 70.0f;+//-------------------------------------------------------------------------------------------------+/** Is the builder near enough to a dock point to work from where it stands? One place, because the+ * move-to state and the build state have to agree: the move ends when this says yes, so if the+ * build state asked a stricter question it would send the builder walking to a spot the move+ * already decided it had reached. */+//-------------------------------------------------------------------------------------------------+static Bool dozerHasArrivedAt( const Object *dozer, const Coord3D *goalPos )+{+ if( dozer == NULL || goalPos == NULL )+ return FALSE;++ const Real SLOP = 15.0f;+ Real distSqr = ThePartitionManager->getDistanceSquared( dozer, goalPos, FROM_BOUNDINGSPHERE_2D );+ Real allowableDistanceSqr = sqr(max( MIN_ACTION_TOLERANCE,+ dozer->getGeometryInfo().getBoundingSphereRadius() + SLOP ));++ return distSqr <= allowableDistanceSqr;++} // end dozerHasArrivedAt+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////@@ -340,32 +360,15 @@ StateReturnType DozerActionMoveToActionPosState::update( void )}// if distance between us and our goal position is close enough- const Coord3D *goalPos = getMachine()->getGoalPosition();- Real distSqr = ThePartitionManager->getDistanceSquared( dozer, goalPos, FROM_BOUNDINGSPHERE_2D );- const Real SLOP = 15.0f;- Real allowableDistanceSqr = sqr(max( MIN_ACTION_TOLERANCE, dozer->getGeometryInfo().getBoundingSphereRadius() + SLOP ));--- if( distSqr <= allowableDistanceSqr )- {- if( m_task == DOZER_TASK_BUILD )- {-- //- // the object is now no longer awaiting construction, it is being constructed ... note- // that we might possibly be here multiple times for a single object being built- // but the setting of the same model condition doesn't have any adverse effects- //- goalObject->clearAndSetModelConditionFlags(- MAKE_MODELCONDITION_MASK(MODELCONDITION_AWAITING_CONSTRUCTION),- MAKE_MODELCONDITION_MASK2(MODELCONDITION_PARTIALLY_CONSTRUCTED, MODELCONDITION_ACTIVELY_BEING_CONSTRUCTED));-- } // end if-+ //+ // The scaffold used to go up here, on arrival. Arrival is not the start of work: the first+ // percent is, and until it goes in the structure is still a plan drawn as a translucent+ // silhouette - so the building was seen putting itself up inside its own ghost. Both now+ // happen in the same call, Object::setConstructionPercent.+ //+ if( dozerHasArrivedAt( dozer, getMachine()->getGoalPosition() ) )return STATE_SUCCESS;- } // end if-// if we're in the idle state fail our move// Failure transition is back to DOZER_ACTION_PICK_ACTION_POS, so@@ -1794,8 +1797,14 @@ Object *DozerAIUpdate::construct( const ThingTemplate *what,adjustedPos.z = TheTerrainLogic->getGroundHeight(pos->x, pos->y);obj->setPosition(&adjustedPos);+ //+ // The footprint is not an obstacle yet: this is a plan standing at zero percent, and until the+ // builder arrives units walk over the site as if it were empty ground. Object::setConstructionPercent+ // puts it in the map on the first percent - after the terrain is flattened, which is what EA's+ // note below was guarding.+ //// Note - very important that we add to map AFTER we flatten terrain. jba.- TheAI->pathfinder()->addObjectToPathfindMap( obj );+// "callback" event for structure created (note that it's not yet "complete")owningPlayer->onStructureCreated( getObject(), obj );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cppindex 549c43f83..3601512aa 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp@@ -434,8 +434,13 @@ Object *WorkerAIUpdate::construct( const ThingTemplate *what,adjustedPos.z = TheTerrainLogic->getGroundHeight(pos->x, pos->y);obj->setPosition(&adjustedPos);+ //+ // The footprint is not an obstacle yet: this is a plan standing at zero percent, and until the+ // worker arrives units walk over the site as if it were empty ground. Object::setConstructionPercent+ // puts it in the map on the first percent - after the terrain is flattened, which is what EA's+ // note below was guarding.+ //// Note - very important that we add to map AFTER we flatten terrain. jba.- TheAI->pathfinder()->addObjectToPathfindMap( obj );// "callback" event for structure created (note that it's not yet "complete")owningPlayer->onStructureCreated( getObject(), obj );diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 7d6d64a3a..077335e6a 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -4933,6 +4933,29 @@ TEST(a_structure_the_builder_has_reached_is_drawn_solid)CHECK_NEAR( Drawable_effectiveOpacity( 1.0f, 1.0f, FALSE ), 1.0f, 0.0001f );}+/** A plan is not a wall. Its footprint stays out of the pathfind map until the builder puts the+ first percent in, so units walk over a site that is only planned - a structure queued behind a+ busy builder used to stand there as a solid obstacle for as long as it waited. Selling runs the+ percent back down through the same call and must not re-lay a footprint that is already down. */+TEST(a_planned_structure_becomes_an_obstacle_when_its_builder_arrives)+{+ // the builder arrives: this is the one transition that lays the footprint+ CHECK( Object_constructionFootprintGoesDown( TRUE, 0.0f, 0.1f ) == TRUE );++ // still waiting - construct() sets zero on a plan that is already at zero+ CHECK( Object_constructionFootprintGoesDown( TRUE, 0.0f, 0.0f ) == FALSE );++ // already building: the footprint went down on the first percent, not on every one after it+ CHECK( Object_constructionFootprintGoesDown( TRUE, 50.0f, 51.0f ) == FALSE );++ // selling a finished building winds it down from 100 to 0 - it is in the map and stays there+ CHECK( Object_constructionFootprintGoesDown( FALSE, 100.0f, 99.9f ) == FALSE );+ CHECK( Object_constructionFootprintGoesDown( FALSE, 0.1f, 0.0f ) == FALSE );++ // completion clears the status first and only then sets CONSTRUCTION_COMPLETE (-1)+ CHECK( Object_constructionFootprintGoesDown( FALSE, 99.9f, CONSTRUCTION_COMPLETE ) == FALSE );+}+/** The silhouette scales whatever opacity the drawable already asked for instead of replacing it,so a stealthed or half-faded drawable is not dragged back up to 45% by being a plan, and onethat has been faded all the way out stays out. */