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): keep an aircraft's remaining ammo on screen

Olcay Seygan90c182d1a8fb
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h
index 62f07f518..dec9d8880 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h
@@ -234,6 +234,7 @@ public:
WeaponSlotType getCurWeaponSlot() const { return m_curWeapon; }
Weapon* findWaypointFollowingCapableWeapon();
const Weapon* findAmmoPipShowingWeapon() const;
+ const Weapon* findReturnToBaseToReloadWeapon() const; ///< for the always-on aircraft ammo display
void weaponSetOnWeaponBonusChange(const Object *source);
UnsignedInt getMostPercentReadyToFireAnyWeapon() const;
inline UnsignedInt getNthCommandSourceMask( WeaponSlotType n ) const { return m_curWeaponTemplateSet ? m_curWeaponTemplateSet->getNthCommandSourceMask( n ) : NULL; }
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 83ac7e976..3de849e38 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -2886,9 +2886,16 @@ void Drawable::drawAmmo( const IRegion2D *healthBarRegion )
{
const Object *obj = getObject();
+ //
+ // Our own aircraft show their load all the time, not just while selected or under the cursor:
+ // how many passes a flight has left decides whether you commit it or let it go home, and you
+ // cannot be selecting it while you watch it fly.
+ //
+ const Bool alwaysShow = obj->isKindOf(KINDOF_AIRCRAFT);
+
if (!(
TheGlobalData->m_showObjectHealth &&
- (isSelected() || (TheInGameUI && (TheInGameUI->getMousedOverDrawableID() == getID()))) &&
+ (alwaysShow || isSelected() || (TheInGameUI && (TheInGameUI->getMousedOverDrawableID() == getID()))) &&
obj->getControllingPlayer() == ThePlayerList->getLocalPlayer()
))
return;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index 87030f023..5f51848c4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -1429,6 +1429,15 @@ Bool Object::getAmmoPipShowingInfo(Int& numTotal, Int& numFull) const
{
/// @todo srj -- may need to cache this inside weaponset.
const Weapon* w = m_weaponSet.findAmmoPipShowingWeapon();
+
+ //
+ // An aircraft that has to fly home to reload shows its load whether or not the weapon sets
+ // ShowsAmmoPips: knowing how many passes are left before it leaves is the whole point of
+ // watching it, and most of those weapons never set the flag.
+ //
+ if (w == NULL && isKindOf(KINDOF_AIRCRAFT))
+ w = m_weaponSet.findReturnToBaseToReloadWeapon();
+
if (w)
{
numTotal = w->getClipSize();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp
index 75004a817..f3bc2f117 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp
@@ -1024,6 +1024,23 @@ const Weapon* WeaponSet::findAmmoPipShowingWeapon() const
return NULL;
}
+//-------------------------------------------------------------------------------------------------
+/** The first weapon that has to return to base to reload, so an aircraft can show its remaining
+ * passes even when the weapon never sets ShowsAmmoPips. */
+//-------------------------------------------------------------------------------------------------
+const Weapon* WeaponSet::findReturnToBaseToReloadWeapon() const
+{
+ for( Int i = 0; i < WEAPONSLOT_COUNT; i++ )
+ {
+ const Weapon *weapon = m_weapons[ i ];
+ if (weapon && weapon->getReloadType() == RETURN_TO_BASE_TO_RELOAD)
+ {
+ return weapon;
+ }
+ }
+ return NULL;
+}
+
//-------------------------------------------------------------------------------------------------
Weapon* WeaponSet::findWaypointFollowingCapableWeapon()
{