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(gameengine): add -groupdrill and draw the band with -showlanes
Olcay Seygan23f79506c2bc
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex 500d9f4c3..70d134c8e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -3823,6 +3823,74 @@ static const char *getModuleProfileReport( void )}#endif+//-------------------------------------------------------------------------------------------------+/** -groupdrill: play the part of a player giving group orders.++ The self-play harness never exercised the crowd model, and it took a SHOWLANES log to notice.+ The computer's armies do not move as groups: a skirmish AI team hands each of its units its own+ aiMoveToPosition, and a unit that was never handed a lane is one crowdSteer returns out of on+ its first line. Every steering rule under -crowd was therefore reachable by a human with a+ mouse and by nothing else, while ai-batch.ps1 reported on the flag's other half - the collision+ rules in AIUpdate::blockedBy - and called it the crowd model.++ This selects each player's ground army every n frames and gives it one order, through the same+ AIGroup::groupMoveToPosition a right-click goes through. The match it produces is nonsense:+ two armies marching corner to corner past each other, nobody defending anything, and the win+ rate means nothing at all. The blocked unit-frames underneath it are the point, and they are+ the first numbers this fork has ever had for the steering itself. */+//-------------------------------------------------------------------------------------------------+static void groupDrillTick( void )+{+ Region3D extent;+ TheTerrainLogic->getExtent( &extent );+ const Real inset = PATHFIND_CELL_SIZE_F * 8.0f;++ // which corner this tick sends them to; alternating it marches the army back and forth over the+ // same ground rather than parking it once and measuring an empty map+ const Int tick = (Int)(TheGameLogic->getFrame() / (UnsignedInt)TheGlobalData->m_groupDrill);++ for( Int p = 0; p < ThePlayerList->getPlayerCount(); p++ )+ {+ Player *player = ThePlayerList->getNthPlayer( p );+ if (player == NULL)+ continue;++ AIGroup *group = TheAI->createGroup();+ Int taken = 0;+ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )+ {+ if (obj->getControllingPlayer() != player || obj->isEffectivelyDead())+ continue;+ if (obj->getAIUpdateInterface() == NULL)+ continue;+ // the army, and only the army: a base that stops building has no traffic to measure+ if (obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_IMMOBILE )+ || obj->isKindOf( KINDOF_AIRCRAFT ) || obj->isKindOf( KINDOF_DOZER )+ || obj->isKindOf( KINDOF_HARVESTER ))+ continue;++ group->add( obj );+ if (++taken >= 40)+ break;+ }++ if (taken < 2)+ {+ TheAI->destroyGroup( group );+ continue;+ }++ Coord3D dest;+ const Bool farCorner = ((tick + p) & 1) != 0;+ dest.x = farCorner ? extent.hi.x - inset : extent.lo.x + inset;+ dest.y = farCorner ? extent.hi.y - inset : extent.lo.y + inset;+ dest.z = TheTerrainLogic->getGroundHeight( dest.x, dest.y );++ group->groupMoveToPosition( &dest, false, CMD_FROM_AI );+ TheAI->destroyGroup( group );+ }+}+void GameLogic::update( void ){USE_PERF_TIMER(GameLogic_update)@@ -3896,6 +3964,11 @@ void GameLogic::update( void )TheScriptEngine->UPDATE();}+ // the measurement harness for group movement; the first tick waits for there to be an army+ if (TheGlobalData->m_groupDrill > 0 && now > (UnsignedInt)(LOGICFRAMES_PER_SECOND * 60)+ && (now % (UnsignedInt)TheGlobalData->m_groupDrill) == 0)+ groupDrillTick();+QueryPerformanceCounter( (LARGE_INTEGER *)&tScripts );Bool freezeTime = TheTacticalView->isTimeFrozen() && !TheTacticalView->isCameraMovementFinished();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex 15c9b990f..578ccbcea 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -1650,7 +1650,24 @@ void W3DView::calcDeltaScroll(Coord2D &screenDelta)//--------------------------------------------------------------------------------------------------/** Draw member for the W3D window, this will literally draw the window+/** One world-space segment, projected and clipped to the screen. The AI path overlay above spells+ * this out by hand; the lane overlay below draws hundreds of segments a frame and wants it once. */+//-------------------------------------------------------------------------------------------------+static void drawWorldLine( View *view, IRegion2D *clipRegion, const Coord3D *a, const Coord3D *b,+ UnsignedInt color )+{+ ICoord2D start, end, clipStart, clipEnd;+ Bool onScreenA = view->worldToScreen( a, &start );+ Bool onScreenB = view->worldToScreen( b, &end );+ if( !onScreenA && !onScreenB )+ return;++ if( ClipLine2D( &start, &end, &clipStart, &clipEnd, clipRegion ) )+ TheDisplay->drawLine( clipStart.x, clipStart.y, clipEnd.x, clipEnd.y, 1.0f, color );+}++//-------------------------------------------------------------------------------------------------+/** Draw member for the W3D window, this will literally draw the window* for this view *///-------------------------------------------------------------------------------------------------void W3DView::drawView( void )@@ -1834,6 +1851,85 @@ void W3DView::draw( void )} // end if, show debug AI+ /* -showlanes: the band, drawn on the ground.++ Three things per moving unit, and the point of separating them is that two different failures+ look identical from the camera - a unit that was never handed a lane, and a unit that was+ handed one and then had it refused.++ blue its route, so twenty units sent to the same place show whether they were even given+ twenty different routes;+ yellow from the unit, sideways across its route, the lane it holds - length is how far off+ centre that lane sits, and the side is which side. No yellow means no lane;+ green from the centre line of the route to the point the unit is actually steering at,+ which is the offset that survived the passability check and the taper. Yellow+ with no green is a lane that was measured and thrown away.++ It draws every unit on the map, not the selected ones: a group's shape is the thing being+ looked at and half a group is not a shape. Client-side only, and it reads nothing the logic+ does not already have - closestPointAndDir does no query and no caching. */+ if( TheGlobalData->m_showLanes )+ {+ IRegion2D clipRegion;+ clipRegion.lo.x = 0;+ clipRegion.lo.y = 0;+ clipRegion.hi.x = getWidth();+ clipRegion.hi.y = getHeight();++ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )+ {+ AIUpdateInterface *ai = obj->getAIUpdateInterface();+ if( ai == NULL )+ continue;++ Path *path = ai->getPath();+ if( path == NULL )+ continue;++ const Coord3D *unitPos = obj->getPosition();++ // the route itself+ PathNode *prevNode = path->getFirstNode();+ for( PathNode *node = (prevNode ? prevNode->getNext() : NULL); node; node = node->getNext() )+ {+ drawWorldLine( this, &clipRegion, prevNode->getPosition(), node->getPosition(), 0xFF3060C0 );+ prevNode = node;+ }++ Coord3D centre;+ Coord2D dir;+ if( !path->closestPointAndDir( *unitPos, ¢re, &dir ) )+ continue;++ // the lane this unit holds, drawn sideways from the unit itself. 120 feet at the edge of+ // the band, which is about a tank and a half - long enough to read at normal zoom.+ if( ai->hasLaneFraction() )+ {+ Real off = (ai->getLaneFraction() - 0.5f) * 120.0f;+ Coord3D tip = *unitPos;+ tip.x += -dir.y * off;+ tip.y += dir.x * off;+ tip.z = TheTerrainLogic->getGroundHeight( tip.x, tip.y );+ drawWorldLine( this, &clipRegion, unitPos, &tip, 0xFFFFFF00 );+ }++ // and the offset it actually kept+ if( path->hasCachedPointOnPath() )+ {+ Coord3D steer;+ path->peekCachedPointOnPath( steer );+ drawWorldLine( this, &clipRegion, ¢re, &steer, 0xFF00FF00 );++ ICoord2D s;+ if( worldToScreen( &steer, &s ) )+ {+ TheDisplay->drawLine( s.x-3, s.y, s.x+3, s.y, 1.0f, 0xFF00FF00 );+ TheDisplay->drawLine( s.x, s.y-3, s.x, s.y+3, 1.0f, 0xFF00FF00 );+ }+ }+ }+ } // end if, show lanes+#if defined(_DEBUG) || defined(_INTERNAL)if( TheGlobalData->m_debugCamera ){