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.

feat(gameclient): draw a thin line from flying aircraft to the ground

Olcay Seyganf0c51999964e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1b639a3ff..58af43050 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -809,6 +809,7 @@ found and fixed, EA's own, not port damage.**
## Aircraft, guards, and orders that used to be ignored
+- From the game's angle a Comanche over a ridge and a Comanche over your base can sit on the same spot of the screen. Aircraft in the air now hang a thin line straight down to the ground or water under them, so the foot tells you where the plane really is and the length how high. A parked one has none, and cutscenes draw none. A high plane at the very bottom edge of the screen can lose its line there, and so can one whose line would be taller than the screen.
- Two jets on one airfield could deadlock waiting for each other; now they go.
- Losing the airfield no longer leaves its aircraft circling rubble forever.
- A jet looking for a new airfield no longer locks parking spaces it never uses. The search booked a space at every airfield it looked at on the way to the nearest, and each of those stayed booked for that jet until it died: an empty spot on the tarmac no other plane could land on and the airfield could not build into.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index ea779e756..b0365900d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -964,6 +964,7 @@ private:
void drawEmoticon( const IRegion2D* healthBarRegion );
void drawHealthBar( const IRegion2D* healthBarRegion ); ///< draw heath bar
void drawCaptureProgress( void ); ///< the clock under the health bar of the building this one is taking
+ void drawAltitudeLine( void ); ///< the line from an aircraft in the air down to the ground under it
void drawHealing( const IRegion2D* healthBarRegion ); ///< draw icons
void drawEnthusiastic( const IRegion2D* healthBarRegin ); ///< draw icons
#ifdef ALLOW_DEMORALIZE
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 0d525a3ea..a31d2929e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -3584,6 +3584,75 @@ Bool Drawable::drawsAnyUIText( void )
}
+// ------------------------------------------------------------------------------------------------
+/** A thin line from an aircraft in the air straight down to the ground under it, because a plane
+ * over a ridge and a plane over your base can sit on the same pixel. drawablePostDraw has already
+ * turned away what the local player may not see. */
+// ------------------------------------------------------------------------------------------------
+void Drawable::drawAltitudeLine( void )
+{
+ const Object *obj = getObject();
+ if( obj == NULL || obj->isEffectivelyDead() )
+ return;
+
+ // The shell map and a mission's cutscene have no interface up. Asked of the script and not of
+ // getInputEnabled, which setGamePaused also turns off: a paused match keeps its lines.
+ if( TheGameLogic->isInShellGame() || TheScriptEngine->isInputHeldByScript() )
+ return;
+
+ // The height over terrain says nothing on a carrier's deck, which stands far above the sea bed. The
+ // airborne flag does: a taxi locomotor has no AirborneTargetingHeight, so nothing parked ever sets
+ // it. KINDOF_AIRCRAFT stays, because boats over deep water, drones, flares and missiles set it too.
+ if( !obj->isKindOf( KINDOF_AIRCRAFT ) || !obj->isAirborneTarget() )
+ return;
+
+ // China's artillery barrage flies a plane with no draw module at all
+ if( *getDrawModulesNonDirty() == NULL )
+ return;
+
+ const Color LINE_COLOR = GameMakeColor( 255, 255, 255, 120 );
+
+ Coord3D top = *obj->getPosition();
+ Coord3D bottom = top;
+ bottom.z = TheTerrainLogic->getLayerHeight( top.x, top.y, obj->getLayer() );
+ Real waterZ;
+ if( TheTerrainLogic->isUnderwater( top.x, top.y, &waterZ ) )
+ bottom.z = MAX( bottom.z, waterZ ); // the surface and not the sea bed; a bridge deck over it stays
+
+ ICoord2D topScreen, bottomScreen;
+ const Bool topOn = TheTacticalView->worldToScreen( &top, &topScreen );
+ const Bool bottomOn = TheTacticalView->worldToScreen( &bottom, &bottomScreen );
+ // ponytail: both ends off draws nothing, so a line taller than the screen goes at full zoom; sample along it if that shows
+ if( !topOn && !bottomOn )
+ return;
+
+ // An end off the screen has no position worth clipping: past the clip planes it projects to (0,0),
+ // and just in front of the near plane far enough to overflow ClipLine2D's Int products. The frustum
+ // is convex and the line crosses its edge once, so halve the way there.
+ if( topOn != bottomOn )
+ {
+ Real insideZ = topOn ? top.z : bottom.z;
+ Real outsideZ = topOn ? bottom.z : top.z;
+ ICoord2D &edge = topOn ? bottomScreen : topScreen;
+ edge = topOn ? topScreen : bottomScreen;
+ for( Int i = 0; i < 10; ++i )
+ {
+ Coord3D middle = top;
+ middle.z = ( insideZ + outsideZ ) * 0.5f;
+ ICoord2D middleScreen;
+ if( TheTacticalView->worldToScreen( &middle, &middleScreen ) )
+ {
+ insideZ = middle.z;
+ edge = middleScreen;
+ }
+ else
+ outsideZ = middle.z;
+ }
+ }
+
+ TheDisplay->drawLine( topScreen.x, topScreen.y, bottomScreen.x, bottomScreen.y, 1.0f, LINE_COLOR );
+}
+
// ------------------------------------------------------------------------------------------------
/** This is called as part of the "post draw" phase when drawable a drawable. It is there
* that we should overlay on the screen any 2D elements for purposes of user interface
@@ -3623,6 +3692,8 @@ void Drawable::drawIconUI( void )
drawConstructPercent( healthBarRegion );
drawSupplyCash( healthBarRegion );
+ drawAltitudeLine(); // ahead of the bail: the planes a general's power sends over are IGNORED_IN_GUI
+
//All Icons Below only draw on ALIVE things, so bail here -------------------------
if( obj->isEffectivelyDead() || obj->isKindOf( KINDOF_IGNORED_IN_GUI )) // object explicitly wants nothing to do with these icons, so...
return;