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(gameclient): restore rally lines, draw a plain move's route, harden the range ring

Olcay Seygan615fdfc9a080
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 67219c98e..35d5d16bb 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -757,6 +757,7 @@ protected:
void updateIncomeEstimate( Player *player ); ///< income per minute, shown beside the money
Bool m_placementRangeRingUp; ///< we put a radius cursor up for a pending structure, so we owe a clear
+ Real m_placementRingRadius; ///< the radius that ring was built at, so it is not rebuilt every frame
DisplayString * m_hudDisplayString; ///< the ShowHudOverlay line (fps / clock / income)
UnsignedInt m_hudLastSampleFrame; ///< client frame the fps sample was last refreshed on
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 419e01774..542716f25 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1021,6 +1021,7 @@ InGameUI::InGameUI()
m_messagesOn = TRUE;
m_placementRangeRingUp = FALSE;
+ m_placementRingRadius = 0.0f;
m_hudDisplayString = NULL;
m_hudLastSampleFrame = 0;
m_hudLastSampleMs = 0;
@@ -1234,16 +1235,16 @@ void InGameUI::setRadiusCursorForRadius(Real radius)
return;
}
- // re-create only when the size actually changed, otherwise the decal restarts every frame
- static Real s_lastRadius = 0.0f;
- if (m_curRcType == RADIUSCURSOR_GUARD_AREA && s_lastRadius == radius)
+ // re-create only when the size actually changed, otherwise the decal restarts every frame.
+ // (this used to hang off a function-level static, which outlived the decal it described.)
+ if (m_curRcType == RADIUSCURSOR_GUARD_AREA && !m_curRadiusCursor.isEmpty() && m_placementRingRadius == radius)
return;
m_curRadiusCursor.clear();
Coord3D pos = { 0, 0, 0 }; // handleRadiusCursor() puts it under the cursor
m_radiusCursors[RADIUSCURSOR_GUARD_AREA].createRadiusDecal(pos, radius, ThePlayerList->getLocalPlayer(), m_curRadiusCursor);
m_curRcType = RADIUSCURSOR_GUARD_AREA;
- s_lastRadius = radius;
+ m_placementRingRadius = radius;
handleRadiusCursor();
}
@@ -1478,13 +1479,18 @@ void InGameUI::handleBuildPlacements( void )
//
if( TheGlobalData->m_showPlacementRangeRing )
{
+ //
+ // Walk every weapon set the template has, not just the one an empty condition mask
+ // happens to select: a defence whose gun lives in a conditional set (an upgrade, a
+ // garrisoned variant) would otherwise report no range at all and draw no ring.
+ //
Real placeRange = 0.0f;
- const WeaponTemplateSet *wts = m_pendingPlaceType->findWeaponTemplateSet( WeaponSetFlags() );
- if( wts )
+ const WeaponTemplateSetVector& sets = m_pendingPlaceType->getWeaponTemplateSets();
+ for( WeaponTemplateSetVector::const_iterator si = sets.begin(); si != sets.end(); ++si )
{
for( Int ws = PRIMARY_WEAPON; ws < WEAPONSLOT_COUNT; ++ws )
{
- const WeaponTemplate *wt = wts->getNth( (WeaponSlotType)ws );
+ const WeaponTemplate *wt = si->getNth( (WeaponSlotType)ws );
if( wt && wt->getUnmodifiedAttackRange() > placeRange )
placeRange = wt->getUnmodifiedAttackRange();
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp
index cae10ae50..3be5a6cef 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp
@@ -59,6 +59,7 @@
#include <texture.h>
#include "Common/GlobalData.h"
+#include "GameLogic/AIPathfind.h" // Path/PathNode, to draw a plain move order's route
#include "Common/RandomValue.h"
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
@@ -188,9 +189,16 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
- // AlwaysShowWaypointLines: retail only draws the queued path while the waypoint key is held,
- // so you cannot see an order you already gave. With this on, any selected unit that still has
- // a goal path left shows it.
+ //
+ // AlwaysShowWaypointLines: retail only draws a route while the waypoint key is held, so you
+ // cannot look at an order you already gave. With this on, a selected unit shows the route it
+ // is actually following - its queued waypoints if it has any, otherwise the path it computed
+ // for a plain move order, which is what you get from a single click.
+ //
+ // Note this block and the rally-point one below are NOT alternatives: rally points used to be
+ // drawn only when we were not in waypoint mode, so making this condition always true silently
+ // took every rally line away.
+ //
if( TheInGameUI->isInWaypointMode() || TheGlobalData->m_alwaysShowWaypointLines )
{
//Create a default light environment with no lights and only full ambient.
@@ -202,9 +210,16 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
localRinfo.light_environment=&lightEnv;
Vector3 points[ MAX_DISPLAY_NODES + 1 ]; //Lines have nodes + 1 points.
+ //
+ // A whole army's worth of routes is a lot of line work for something nobody can read
+ // anyway, so only the first few selected units draw one.
+ //
+ const Int MAX_ROUTE_LINES = 8;
+ Int routeLines = 0;
+
const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
Drawable *draw;
- for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )
+ for( DrawableListCIt it = selected->begin(); it != selected->end() && routeLines < MAX_ROUTE_LINES; ++it )
{
draw = *it;
Object *obj = draw->getObject();
@@ -214,8 +229,38 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
AIUpdateInterface *ai = obj->getAI();
Int goalSize = ai ? ai->friend_getWaypointGoalPathSize() : 0;
Int gpIdx = ai ? ai->friend_getCurrentGoalPathIndex() : 0;
- if( ai && gpIdx >= 0 && gpIdx < goalSize )
+
+ if( ai && !(gpIdx >= 0 && gpIdx < goalSize) && TheGlobalData->m_alwaysShowWaypointLines )
+ {
+ //
+ // No queued waypoints - this is a plain move order, which is what a single
+ // click gives you. Draw the route it actually computed instead, or there is
+ // nothing to see until you queue a second point.
+ //
+ const Path *path = ai->getPath();
+ const PathNode *node = path ? path->getFirstNode() : NULL;
+ if( node )
+ {
+ const Coord3D *pos = obj->getPosition();
+ points[ 0 ].Set( Vector3( pos->x, pos->y, pos->z ) );
+
+ for( ; node && numPoints < MAX_DISPLAY_NODES + 1; node = node->getNextOptimized() )
+ {
+ const Coord3D *np = node->getPosition();
+ points[ numPoints ].Set( Vector3( np->x, np->y, np->z ) );
+ numPoints++;
+ }
+
+ if( numPoints > 1 )
+ {
+ queueLine( numPoints, points );
+ ++routeLines;
+ }
+ }
+ }
+ else if( ai && gpIdx >= 0 && gpIdx < goalSize )
{
+ ++routeLines;
const Coord3D *pos = obj->getPosition();
points[ 0 ].Set( Vector3( pos->x, pos->y, pos->z ) );
@@ -243,7 +288,9 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
}
renderQueuedLines( localRinfo );
}
- else // maybe we want to draw rally points, then?
+ // Rally points, drawn whenever we are not actively laying down waypoints. This used to be the
+ // else of the block above, which is why turning that block on full time hid every rally line.
+ if( !TheInGameUI->isInWaypointMode() )
{
//Create a default light environment with no lights and only full ambient.
//@todo: Fix later by copying default scene light environement from W3DScene.cpp.