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(gameengine): no health bars on bridges and unowned scenery

Olcay Seygan40b80a4d45af
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10f12bc26..3eb5112c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -329,6 +329,8 @@ found and fixed — EA's own, not port damage.**
- Every garrisonable building shows how full it is, whoever holds it.
- A vehicle's load stays private.
- Lamps, barrels, rocks and bushes no longer wear health bars.
+- Bridges no longer float a health bar over the middle of the river. There was never anything under it: the span is part of the terrain, and the bar belonged to an invisible marker standing in the water.
+- The city itself stops wearing them too. A building nobody owns shows a bar only if there is something to do about it - troops can go inside, or it can be taken. A row of houses does not, and neither does the concrete apron each of them stands on, which is a separate two-thousand-point object that was drawing a second bar down at street level.
## Twenty-two-year-old bugs, found by testing
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 97cf55452..5d212bcf2 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -78,6 +78,10 @@ const Real PLACEMENT_SILHOUETTE_OPACITY = 0.45f;
///< the opacity a drawable is actually drawn at, given what it is doing
extern Real Drawable_effectiveOpacity( Real explicitOpacity, Real stealthOpacity, Bool awaitingBuilder );
+///< whether a structure's health bar is worth drawing at all
+extern Bool Drawable_structureShowsHealthBar( Bool isBridge, Bool isUnowned, Bool isGarrisonable,
+ Bool isCapturable );
+
//-----------------------------------------------------------------------------
//@TODO -- The drawable icon system needs to be implemented in a proper manner -- KM
// Fact 1: Every drawable in the world shouldn't have to have a pointer
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index aaee560af..4d4fd08fa 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -365,6 +365,36 @@ Real Drawable_effectiveOpacity( Real explicitOpacity, Real stealthOpacity, Bool
return opacity;
}
+//-------------------------------------------------------------------------------------------------
+/** Whether a structure's health bar belongs on screen.
+ *
+ * A bridge is not a thing you can see: `GenericBridge` carries an empty `W3DDefaultDraw` and one
+ * immortal hit point, the span itself being drawn by the terrain, so its bar hung in mid air over
+ * the middle of the river with no object under it - and so did the landmark bridges' and the
+ * bridge towers'.
+ *
+ * The rest of the map's masonry is nobody's: a row of houses, the concrete apron each of them
+ * stands on - a separate 2000 hit point object of its own - and the scenery of a city map. None
+ * of it is anybody's to lose, and always-on bars turned a built up map into a wall of them.
+ *
+ * Two exceptions, and both are things worth doing something about. A building troops can be put
+ * in: clearing a garrison out of it is a real decision, so its health stays readable. And one
+ * that can be taken - an oil derrick, a hospital, an artillery platform - because whether to walk
+ * in or to level it is exactly the choice its health answers. Anything a player owns keeps its
+ * bar either way. */
+//-------------------------------------------------------------------------------------------------
+Bool Drawable_structureShowsHealthBar( Bool isBridge, Bool isUnowned, Bool isGarrisonable,
+ Bool isCapturable )
+{
+ if( isBridge )
+ return FALSE;
+
+ if( isUnowned && !isGarrisonable && !isCapturable )
+ return FALSE;
+
+ return TRUE;
+}
+
//-------------------------------------------------------------------------------------------------
/** The silhouette is the finished building, not a foundation: the construction model conditions are
* left alone until the builder arrives, so what stands on the map is the shape that was under the
@@ -4089,6 +4119,27 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)
( obj->isKindOf( KINDOF_IMMOBILE ) && !obj->isKindOf( KINDOF_STRUCTURE ) ) )
return;
+ if( obj->isKindOf( KINDOF_STRUCTURE ) )
+ {
+ const ContainModuleInterface *contain = obj->getContain();
+ const Bool isBridge = obj->isKindOf( KINDOF_BRIDGE ) ||
+ obj->isKindOf( KINDOF_LANDMARK_BRIDGE ) ||
+ obj->isKindOf( KINDOF_BRIDGE_TOWER );
+ //
+ // "nobody's" is a side test, not a player-pointer test: a map hands its houses either to
+ // the neutral player or to a Civilian-faction player of its own, and both are equally not
+ // in the match. Every faction anyone plays is a playable side, so a captured tech building
+ // or a rebuilt GLA hole is owned the moment it changes hands.
+ //
+ const Player *owner = obj->getControllingPlayer();
+ const Bool isUnowned = owner == NULL || !owner->isPlayableSide();
+
+ if( !Drawable_structureShowsHealthBar( isBridge, isUnowned,
+ contain != NULL && contain->isGarrisonable(),
+ obj->isKindOf( KINDOF_CAPTURABLE ) ) )
+ return;
+ }
+
if( obj->isKindOf( KINDOF_FORCEATTACKABLE ) )
{
//Currently (Nov 2002), everything that is forceattackable are civ fences, and they all have a
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index bbaa29a09..48ed1c087 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -5537,6 +5537,39 @@ TEST(the_placement_silhouette_scales_the_opacity_it_is_given)
CHECK_NEAR( Drawable_effectiveOpacity( 0.0f, 1.0f, TRUE ), 0.0f, 0.0001f );
}
+/** A bridge has no object to hang a bar on: GenericBridge is an empty draw module with one immortal
+ hit point, and the span is drawn by the terrain, so the bar floated in mid air over the water.
+ Landmark bridges and bridge towers are the same case. */
+TEST(a_bridge_draws_no_health_bar)
+{
+ CHECK( Drawable_structureShowsHealthBar( TRUE, TRUE, FALSE, FALSE ) == FALSE );
+ CHECK( Drawable_structureShowsHealthBar( TRUE, FALSE, FALSE, FALSE ) == FALSE );
+
+ // even a bridge somebody could walk into stays bare - it is still art the terrain draws
+ CHECK( Drawable_structureShowsHealthBar( TRUE, TRUE, TRUE, TRUE ) == FALSE );
+}
+
+/** The map's civilian masonry is nobody's - the houses, and the concrete apron each one stands on,
+ which is a 2000 hit point object in its own right - so a city map no longer comes up wearing a
+ bar over every building and a second one at its feet. A building troops can be put in keeps
+ its bar, and so does one that can be taken: both are decisions its health answers. */
+TEST(only_a_garrisonable_or_capturable_civilian_building_wears_a_health_bar)
+{
+ CHECK( Drawable_structureShowsHealthBar( FALSE, TRUE, FALSE, FALSE ) == FALSE );
+ CHECK( Drawable_structureShowsHealthBar( FALSE, TRUE, TRUE, FALSE ) == TRUE );
+
+ // a hospital or an artillery platform: walk in or level it, and the bar is what decides
+ CHECK( Drawable_structureShowsHealthBar( FALSE, TRUE, FALSE, TRUE ) == TRUE );
+}
+
+/** Anything a player owns keeps its bar - a barracks is neither garrisonable nor capturable, and
+ both it and a captured tech building are things the fight turns on. */
+TEST(an_owned_structure_always_wears_a_health_bar)
+{
+ CHECK( Drawable_structureShowsHealthBar( FALSE, FALSE, FALSE, FALSE ) == TRUE );
+ CHECK( Drawable_structureShowsHealthBar( FALSE, FALSE, TRUE, FALSE ) == TRUE );
+}
+
/** Ground you have already scouted stays buildable after your units leave it, so a base can be
planned out into the fog and the builder sent to walk there. Shroud - terrain nobody of yours
has ever laid eyes on - is still off limits, which is what stops the map being read through a