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(gameclient): blue health bar for a held and disabled object
Olcay Seygan2ec29509296d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b0cc749e0..4bc6a7e64 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -373,6 +373,7 @@ found and fixed — EA's own, not port damage.**- A health bar keeps its size against the unit at any resolution. It was a fixed number of pixels wide and three tall, so the bigger the screen the thinner the thread over a tank.- Health bars are in the owner's colour instead of green to red. A building going up fills its bar in that same colour as it rises, so a glance across the map says whose expansion it is - the seconds written over it already say it is not finished. A disabled building keeps the blue.- A building's bar sits above its roof rather than inside its art.+- A unit that is inside a transport and also disabled wears the blue bar. Being carried and being knocked out were asked as one question, so the two together answered no: a squad EMP'd inside a bunker, or hacked while riding a Battle Bus, looked perfectly healthy from outside.- The progress bar stacked over the health bar is white, wherever it turns up - a factory turning out a tank, a silo charging, a supply drop counting down to its payout. It was yellow, which is a colour the game already spends on your own units and on damage, and a strip of it sitting directly above a coloured health bar read as part of the same bar.- Every garrisonable building shows how full it is, whoever holds it.- A vehicle's load stays private.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex c153eeeb8..a560fd054 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -31,6 +31,7 @@#define _DRAWABLE_H_#include "Common/AudioEventRTS.h"+#include "Common/DisabledTypes.h"#include "Common/GameType.h"#include "Common/ModelState.h"#include "Common/ModuleFactory.h"@@ -86,6 +87,9 @@ extern Bool Drawable_structureShowsHealthBar( Bool isBridge, Bool isUnowned, Booextern Bool Drawable_healthBarModeShows( Int healthBarMode, Bool isSelected, Bool isMousedOver,Bool isDamaged );+///< whether these disabled flags mean the health bar is drawn blue instead of the owner's colour+extern Bool Drawable_disabledShowsBlueHealthBar( DisabledMaskType disabledFlags );+//-----------------------------------------------------------------------------//@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 pointerdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 512e66ead..0b5c5fb1d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -422,6 +422,22 @@ Bool Drawable_healthBarModeShows( Int healthBarMode, Bool isSelected, Bool isMoureturn healthBarMode == HEALTH_BAR_SMART && isDamaged;}+//-------------------------------------------------------------------------------------------------+/** A disabled object wears a blue bar instead of its owner's colour, because that is a state+ * nothing else on screen signals. Being held - inside a transport, a bunker, a building - is not+ * a malfunction and does not count.+ *+ * The old test was `isDisabled() && !isDisabledByType(DISABLED_HELD)`, which is two different+ * questions stapled together: a unit that is both held and EMP'd answers yes to the second, so it+ * lost its blue bar and looked healthy. Clear HELD out of the mask and ask whether anything is+ * left, which is what was meant. */+//-------------------------------------------------------------------------------------------------+Bool Drawable_disabledShowsBlueHealthBar( DisabledMaskType disabledFlags )+{+ disabledFlags.clear( MAKE_DISABLED_MASK( DISABLED_HELD ) );+ return DISABLEDMASK_ANY_SET( disabledFlags );+}+//-------------------------------------------------------------------------------------------------/** 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@@ -4206,7 +4222,7 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)//Color color, outlineColor;- if( obj->isDisabled() && !obj->isDisabledByType(DISABLED_HELD) )+ if( Drawable_disabledShowsBlueHealthBar( obj->getDisabledFlags() ) ){color = GameMakeColor( 0, healthRatio * 255.0f, 255, 255 );//blue to cyanoutlineColor = GameMakeColor( 0, healthRatio * 128.0f, 128, 255 );//dark blue to dark cyandiff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 8cba60686..302457f5b 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -5854,6 +5854,24 @@ TEST(an_owned_structure_always_wears_a_health_bar)CHECK( Drawable_structureShowsHealthBar( FALSE, FALSE, TRUE, FALSE ) == TRUE );}+/** Being carried is not a malfunction, so a unit inside a transport keeps its owner's colour.+ Anything else that disables it turns the bar blue - and the pair together used to fail: the old+ test asked `isDisabled() && !isDisabledByType(DISABLED_HELD)`, so a held unit that was then EMP'd+ answered no and looked perfectly healthy inside the transport it could no longer leave. */+TEST(a_held_and_disabled_object_still_shows_a_blue_health_bar)+{+ CHECK( Drawable_disabledShowsBlueHealthBar( DISABLEDMASK_NONE ) == FALSE );+ CHECK( Drawable_disabledShowsBlueHealthBar( MAKE_DISABLED_MASK( DISABLED_HELD ) ) == FALSE );++ CHECK( Drawable_disabledShowsBlueHealthBar( MAKE_DISABLED_MASK( DISABLED_EMP ) ) == TRUE );+ CHECK( Drawable_disabledShowsBlueHealthBar( MAKE_DISABLED_MASK( DISABLED_HACKED ) ) == TRUE );+ CHECK( Drawable_disabledShowsBlueHealthBar( MAKE_DISABLED_MASK( DISABLED_UNDERPOWERED ) ) == TRUE );++ // the case the old condition got wrong+ CHECK( Drawable_disabledShowsBlueHealthBar( MAKE_DISABLED_MASK2( DISABLED_HELD, DISABLED_EMP ) ) == TRUE );+ CHECK( Drawable_disabledShowsBlueHealthBar( MAKE_DISABLED_MASK2( DISABLED_HELD, DISABLED_SUBDUED ) ) == TRUE );+}+/** Always and never are the two ends and answer without looking at the object at all. */TEST(health_bar_always_and_never_ignore_everything_else){