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
feat(gameengine): earn veterancy for healing allies
Olcay Seygan5814c73bddd9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ad53fcde1..e497d22a8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -35,7 +35,7 @@ found and fixed — EA's own, not port damage.**## Veterancy goes to everyone who fought-- A kill used to promote only the unit that fired the last shot. Two Crusaders could grind an Overlord down to a sliver and a passing Humvee's rocket took every point of it. Now the killing blow earns a quarter and the rest is shared out among everything that hurt the target in the last ten seconds, by how much of its health each one took off. A unit that died before the kill leaves its share to the killer. The kill on the scoreboard and your general's promotion points still go to the last shot. Replays recorded before this change play out differently.+- A kill used to promote only the unit that fired the last shot. Two Crusaders could grind an Overlord down to a sliver and a passing Humvee's rocket took every point of it. Now the killing blow earns a quarter and the rest is shared out among everything that hurt the target in the last ten seconds, by how much of its health each one took off. A unit that died before the kill leaves its share to the killer. Healing counts too: an Emperor, or an Overlord or Helix with a Propaganda Tower, earns for every friendly unit it patches up, half of that unit's worth as a kill for a full repair and less for less. The kill on the scoreboard and your general's promotion points still go to the last shot. Replays recorded before this change play out differently.## The frame rate cap is gonediff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ExperienceTracker.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ExperienceTracker.hindex c1955d4b6..21470750c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ExperienceTracker.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ExperienceTracker.h@@ -65,6 +65,19 @@ void KillXPRecordDamage( KillXPDamager *slots, ObjectID source, Int damage, Unsiwhat is left for the killing blow, its 25% plus the rounding. No live damage returns total. */Int KillXPSplit( Int total, const KillXPDamager *slots, UnsignedInt frame, Int *shares );+/* Restoring an ally's health earns experience (Object::scoreTheHeal): HEAL_XP_PERCENT of what the+ patient is worth as a kill, scaled by the share of its maximum health put back. Heals come a+ sliver a frame, so the healer carries the fraction of a point in HEAL_XP_SCALE units. */+enum+{+ HEAL_XP_PERCENT = 50, ///< a full heal is worth this much of a kill+ HEAL_XP_SCALE = 1000000, ///< carry units per experience point+};++/** Add one heal to *carry and return the whole points it now holds, leaving the remainder in it.+ restored and maxHealth are in the same units, restored no more than maxHealth. */+Int HealXPAccrue( Int *carry, Int value, Int restored, Int maxHealth );+class ExperienceTracker : public MemoryPoolObject, public Snapshot{MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(ExperienceTracker, "ExperienceTrackerPool" )@@ -90,6 +103,8 @@ public:void recordDamage( ObjectID source, Int damage ); ///< an enemy took this much health off meconst KillXPDamager *getDamagers() const { return m_damagers; } ///< KILL_XP_DAMAGER_SLOTS of them+ ObjectID getExperienceSink() const { return m_experienceSink; }+ Int accrueHealExperience( Int value, Int restored, Int maxHealth ) { return HealXPAccrue( &m_healXPCarry, value, restored, maxHealth ); }// --------------- inherited from Snapshot interface --------------void crc( Xfer *xfer );@@ -103,6 +118,7 @@ private:ObjectID m_experienceSink; ///< ID of object I have pledged my experience point gains toReal m_experienceScalar; ///< Scales any experience gained by this multiplier.KillXPDamager m_damagers[KILL_XP_DAMAGER_SLOTS]; ///< recent attackers, for splitting the kill+ Int m_healXPCarry; ///< healing experience short of a whole point, in HEAL_XP_SCALE units};#endif\ No newline at end of filediff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex ee8d79dfb..abf89ab02 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -285,7 +285,8 @@ public:void doStatusDamage( ObjectStatusTypes status, Real duration );///< At this level, we just pass this on to our helpervoid doTempWeaponBonus( WeaponBonusConditionType status, UnsignedInt duration );///< At this level, we just pass this on to our helper- void scoreTheKill( const Object *victim ); ///< I just killed this object.+ void scoreTheKill( const Object *victim ); ///< I just killed this object.+ void scoreTheHeal( const Object *patient, Real restored, Real maxHealth ); ///< I just put restored health back on this objectvoid onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel newLevel, Bool provideFeedback = TRUE ); ///< I just achieved this level right this momentExperienceTracker* getExperienceTracker() {return m_experienceTracker;}const ExperienceTracker* getExperienceTracker() const {return m_experienceTracker;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cppindex 03b80be48..da7da409b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp@@ -915,6 +915,11 @@ void ActiveBody::attemptHealing( DamageInfo *damageInfo )damageInfo->out.m_actualDamageDealt = amount;damageInfo->out.m_actualDamageClipped = m_currentHealth - m_prevHealth;+ // whoever put the health back may earn experience for it (Object::scoreTheHeal)+ Object *healer = TheGameLogic->findObjectByID( damageInfo->in.m_sourceID );+ if( damageInfo->out.m_actualDamageClipped > 0.0f && healer && healer != obj )+ healer->scoreTheHeal( obj, damageInfo->out.m_actualDamageClipped, m_maxHealth );+//// Only the healing timestamp is stamped here. This used to overwrite m_lastDamageInfo and// m_lastDamageTimestamp with the heal record as well, which lied to everything that meansdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ExperienceTracker.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ExperienceTracker.cppindex 4f9a6ebf2..c0516a97c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ExperienceTracker.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ExperienceTracker.cpp@@ -50,7 +50,8 @@ ExperienceTracker::ExperienceTracker(Object *parent) :m_experienceSink(INVALID_ID),m_experienceScalar( 1.0f ),m_currentExperience(0), // Added By Sadullah Nader- m_damagers()+ m_damagers(),+ m_healXPCarry(0){}@@ -114,6 +115,15 @@ Int KillXPSplit( Int total, const KillXPDamager *slots, UnsignedInt frame, Int *return left;}+//-------------------------------------------------------------------------------------------------+Int HealXPAccrue( Int *carry, Int value, Int restored, Int maxHealth )+{+ *carry += (Int)( (Int64)value * HEAL_XP_PERCENT * (HEAL_XP_SCALE / 100) * restored / maxHealth );+ Int points = *carry / HEAL_XP_SCALE;+ *carry -= points * HEAL_XP_SCALE;+ return points;+}+//-------------------------------------------------------------------------------------------------void ExperienceTracker::recordDamage( ObjectID source, Int damage ){@@ -319,6 +329,9 @@ void ExperienceTracker::crc( Xfer *xfer )xfer->xferInt( &m_damagers[i].m_damage );xfer->xferUnsignedInt( &m_damagers[i].m_frame );}++ if( m_healXPCarry != 0 )+ xfer->xferInt( &m_healXPCarry );} // end crc//-----------------------------------------------------------------------------@@ -326,13 +339,14 @@ void ExperienceTracker::crc( Xfer *xfer )* Version Info:* 1: Initial version* 2: Recent damagers, for splitting kill experience+ * 3: Healing experience carry*/// ----------------------------------------------------------------------------void ExperienceTracker::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 2;+ XferVersion currentVersion = 3;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -362,6 +376,10 @@ void ExperienceTracker::xfer( Xfer *xfer )}}+ // healing experience carry+ if( version >= 3 )+ xfer->xferInt( &m_healXPCarry );+} // end xfer//-----------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 27a0cf698..806e414a6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -3097,9 +3097,9 @@ Bool Object::isMobile() const}//--------------------------------------------------------------------------------------------------/** Give kill experience to whoever takes points for source, walking up the producers (see- scoreTheKill). Returns the one who took it, or NULL when nobody could or it is the victim's ally. */-static Object *giveKillExperience( Object *source, const Object *victim, Int experience )+/** Whoever takes experience points for source: source itself, or the first of its producers that+ can (see scoreTheKill). NULL when nobody up the chain can. */+static Object *findExperienceEarner( Object *source ){const Int MAX_PRODUCER_HOPS = 4;Object *earner = source;@@ -3116,14 +3116,63 @@ static Object *giveKillExperience( Object *source, const Object *victim, Int exp}ExperienceTracker *earnerTracker = earner->getExperienceTracker();- if (earnerTracker == NULL || !earnerTracker->isAcceptingExperiencePoints()- || victim->getExperienceTracker()->getExperienceValue( earner ) == 0)+ return (earnerTracker && earnerTracker->isAcceptingExperiencePoints()) ? earner : NULL;+}++//-------------------------------------------------------------------------------------------------+/** Give kill experience to whoever takes points for source. Returns the one who took it, or NULL+ when nobody could or it is the victim's ally. */+static Object *giveKillExperience( Object *source, const Object *victim, Int experience )+{+ Object *earner = findExperienceEarner( source );+ if (earner == NULL || victim->getExperienceTracker()->getExperienceValue( earner ) == 0)return NULL;- earnerTracker->addExperiencePoints( experience );+ earner->getExperienceTracker()->addExperiencePoints( experience );return earner;}+//-------------------------------------------------------------------------------------------------+/** ActiveBody::attemptHealing put restored health back on patient, with me as the source.++ A trainable unit that heals or repairs an ally earns HEAL_XP_PERCENT of the patient's kill value+ for a full heal, pro rata. The points go where kill points from me would go: up the producers,+ so an Overlord's or a Helix's Propaganda Tower pays the vehicle carrying it (the tower is a+ rider whose experience sink is the vehicle). A building earns nothing, and neither does the+ walk from one, or every repair bay would pay the dozer that built it. Healing yourself earns+ nothing, which is also where a Battle Drone repairing its own vehicle ends up. */+void Object::scoreTheHeal( const Object *patient, Real restored, Real maxHealth )+{+ if (isKindOf( KINDOF_STRUCTURE ) || patient->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ))+ return;++ Object *earner = findExperienceEarner( this );+ if (earner == NULL)+ return;++ Object *sink = TheGameLogic->findObjectByID( earner->getExperienceTracker()->getExperienceSink() );+ if (sink)+ earner = sink;++ ExperienceTracker *tracker = earner->getExperienceTracker();+ if (earner == patient || earner->isEffectivelyDead() || !tracker->isTrainable()+ || earner->getRelationship( patient ) != ALLIES)+ return;++ // thousandths of a hit point, so a frame's sliver of health still counts+ Int value = patient->getTemplate()->getExperienceValue( patient->getVeterancyLevel() );+ Int points = tracker->accrueHealExperience( value, REAL_TO_INT_FLOOR( restored * 1000.0f ),+ REAL_TO_INT_CEIL( maxHealth * 1000.0f ) );+ if (points == 0)+ return;++ tracker->addExperiencePoints( points );++ DEBUG_LOG(("HEALXP frame=%d healer=%s earner=%s patient=%s xp=%d\n", TheGameLogic->getFrame(),+ getTemplate()->getName().str(), earner->getTemplate()->getName().str(),+ patient->getTemplate()->getName().str(), points));+}+//-------------------------------------------------------------------------------------------------void Object::scoreTheKill( const Object *victim ){diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 9246c75c2..4b8ab5a3c 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -1226,6 +1226,35 @@ TEST(kill_xp_splits_by_damage_and_the_killing_blow_keeps_the_remainder)CHECK_EQ( full[1].m_damage, 5 );}+/* ExperienceTracker.cpp: healing pays half a kill for a full heal, pro rata, and carries the fraction. */+TEST(heal_xp_is_half_a_kill_per_full_heal_and_carries_the_fraction)+{+ Int carry = 0;++ /* a full heal of something worth 200 pays 100, nothing left over */+ CHECK_EQ( HealXPAccrue( &carry, 200, 1000, 1000 ), 100 );+ CHECK_EQ( carry, 0 );++ /* a quarter heal of something worth 10 is 1.25 points: 1 now, the quarter kept */+ CHECK_EQ( HealXPAccrue( &carry, 10, 250, 1000 ), 1 );+ CHECK_EQ( carry, HEAL_XP_SCALE / 4 );++ /* a thousandth of the health a frame, on something worth 50, is 0.025 points: nothing for 39+ frames, the first point on the 40th, and the whole heal still makes 25 */+ carry = 0;+ Int total = 0;+ for( Int frame = 1; frame <= 1000; ++frame )+ {+ total += HealXPAccrue( &carry, 50, 100, 100000 );+ if( frame == 39 )+ CHECK_EQ( total, 0 );+ if( frame == 40 )+ CHECK_EQ( total, 1 );+ }+ CHECK_EQ( total, 25 );+ CHECK_EQ( carry, 0 );+}+/* CommandXlat.cpp: with the move, attack move or guard key armed, a left drag spreads the selectionalong the line drawn, but only when there is a selection to spread and no GUI command alreadywaiting for the click. The right button never draws it; a right drag pans. */