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(gameengine): ai drives its particle cannon beam onto the richest ground

Olcay Seygan9119cc6a277a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 00b4c66ed..f5b7b9234 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -147,6 +147,7 @@ found and fixed — EA's own, not port damage.**
- Two silos ready on the same second fired at the same spot, because nothing that was already in the air was on the map yet. A spot that has just been aimed at is worth nothing to the next shot and climbs back over ten minutes, so the salvo spreads across your base instead of digging one crater.
- Measured over a half-hour match: a Particle Cannon that fired at the identical spot three times running now spreads six shots over five parts of the map, and comes back to the first one at the end, when what you rebuilt there is worth twice what it killed.
- The spy satellite goes through the same targeting, and it was scanning one cell of one base seventeen times a match. It sweeps now.
+- The computer drives its Particle Cannon's beam the way you do. It used to draw the same short S across the aim point and burn empty ground on either side of it; now the beam walks from one cluster to the next, leaving each the moment what stood there is dead. Fired into five groups of six Scorpions, the old sweep killed 4. Medium now kills 8 and Hard, which drives at double speed, 11. Easy keeps the old sweep. Replays recorded before this change play out differently.
## Generals powers the computer actually meant to buy
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index ddd14bb53..ee880e81f 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -126,6 +126,7 @@ Data/Scenarios/alphaaurora.txt
Data/Scenarios/ambulanceclean.txt
Data/Scenarios/aurorafog.txt
Data/Scenarios/avengerlasers.txt
+Data/Scenarios/beamsteer.txt
Data/Scenarios/blastcheck.txt
Data/Scenarios/bridgecross.txt
Data/Scenarios/bridgelong.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/beamsteer.txt b/GeneralsMD/Code/Data/Scenarios/beamsteer.txt
new file mode 100644
index 000000000..44736ef4a
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/beamsteer.txt
@@ -0,0 +1,24 @@
+# A skirmish AI's Particle Cannon on Twilight Flame, fired at the middle of a spread of GLA tanks.
+# Five clumps of six sit 150 apart across the line from the uplink to the aim point, so EA's S curve,
+# 200 along that line and 50 either side, only reaches the middle clump. A steered beam walks on to
+# the others. The cannon is fired with the power verb at frame 60; the beam lands about 75 frames
+# later and burns for 300. Compare the tally's worth at frame 50 and frame 600 between an Easy AI
+# (the retail S curve) and a Hard one (the beam is driven):
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -aidiff hard
+# -side 0 FactionGLA -side 1 FactionAmerica -seed 7 -maxframes 620 -scenario beamsteer
+# -logPrefix beamsteer_hard_
+
+10 spawn 1 AmericaParticleCannonUplink 1 start1:0:200
+10 spawn 1 AmericaPowerPlant 3 start1:-260:40 90
+
+20 spawn 0 GLATankScorpion 6 1135 3696 30
+20 spawn 0 GLATankScorpion 6 1250 3600 30
+20 spawn 0 GLATankScorpion 6 1020 3793 30
+20 spawn 0 GLATankScorpion 6 1365 3503 30
+20 spawn 0 GLATankScorpion 6 905 3890 30
+
+50 tally 0 GLATankScorpion
+60 power 1 AmericaParticleCannonUplink 1135 3696
+600 tally 0 GLATankScorpion
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
index 54e260009..8fa6a821b 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
@@ -230,6 +230,9 @@ struct AIDifficultyProfile
Real m_firstPushSeconds; ///< no attack before this, nor before the first drop zone or black market stands (AI_PURCHASE_EARLY_FRAMES at most)
Real m_minAttackPower; ///< parked teams worth less than this wait for company, up to the wave's longest wait
Real m_siegeTrail; ///< artillery out with a wave keeps this far behind its front unit; 0 = walks with it
+
+ // Superweapons
+ Real m_beamSteerSeconds; ///< how often a firing Particle Cannon's beam is driven onto the richest ground near it; 0 = the retail S curve
};
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
index ec3b6e94e..2da9e98ee 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -339,6 +339,8 @@ protected:
* that, with no clock; as many superweapons as the game's rules allow, and a few copies of the
* tech building so one of them blowing up leaves the tree standing. */
virtual void doSuperweapons(void);
+ void doParticleBeams(void); ///< drive a firing Particle Cannon's beam onto the richest ground within reach of it
+ Bool richestGroundNear(const Coord3D *spot, Real radius, Coord3D *aim); ///< that ground, FALSE when there is nothing worth moving to
/** The purchase queue (AIPurchaseQueue): every skirmish spender asks before it pays, on every rung
* with a bank target, and the thing at the top that cannot be afforded yet has the money saved for
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParticleUplinkCannonUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParticleUplinkCannonUpdate.h
index 0e84deb85..6a306fec9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParticleUplinkCannonUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParticleUplinkCannonUpdate.h
@@ -182,6 +182,7 @@ public:
void createGroundHitParticleSystem( IntensityTypes intensity );
Bool findOrbitBeamRadius( Real &radius ) const; ///< the beam template's half width, FALSE without a beam
+ Bool getBurningSpot( Coord3D *spot, Real *damageRadius ) const; ///< where a live beam that can still be driven is burning, and how wide
Real computeOrbitBeamWidthScalar( UnsignedInt frame ) const;
Bool calculateDefaultInformation();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
index bc276d76f..d4c6a32d3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
@@ -1143,9 +1143,9 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons
* scoutS maxSc decis cntr mass ttk indiv team infl focus save harv expand guard hoard econ micro gate answer massU bankS floor payoff upgr nonc share maxF fMult */
static const AIDifficultyProfile s_defaultSkillLadder[ AISKILL_COUNT ] =
{
- /* Easy */ { 75.0f, 1, 7.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE, FALSE, 120.0f, 6000, 4.0f, 720.0f, 0.05f, 0.05f, 3, 0.0f, 360.0f, 1500.0f, 80.0f },
- /* Medium */ { 45.0f, 1, 3.0f, 0.50f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 6000, FALSE, FALSE, FALSE, FALSE, FALSE, 60.0f, 5000, 2.5f, 420.0f, 0.05f, 0.10f, 3, 0.0f, 300.0f, 3000.0f, 120.0f },
- /* Hard */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, TRUE, TRUE, FALSE, 30.0f, 4000, 1.5f, 180.0f, 0.05f, 1.00f, 8, 2.0f, 240.0f, 4500.0f, 160.0f }
+ /* Easy */ { 75.0f, 1, 7.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE, FALSE, 120.0f, 6000, 4.0f, 720.0f, 0.05f, 0.05f, 3, 0.0f, 360.0f, 1500.0f, 80.0f, 0.00f },
+ /* Medium */ { 45.0f, 1, 3.0f, 0.50f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 6000, FALSE, FALSE, FALSE, FALSE, FALSE, 60.0f, 5000, 2.5f, 420.0f, 0.05f, 0.10f, 3, 0.0f, 300.0f, 3000.0f, 120.0f, 1.00f },
+ /* Hard */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, TRUE, TRUE, FALSE, 30.0f, 4000, 1.5f, 180.0f, 0.05f, 1.00f, 8, 2.0f, 240.0f, 4500.0f, 160.0f, 0.25f }
};
//-------------------------------------------------------------------------------------------------
@@ -1792,6 +1792,7 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*
{ "FirstPushSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_firstPushSeconds ) },
{ "MinAttackPower", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_minAttackPower ) },
{ "SiegeTrail", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_siegeTrail ) },
+ { "BeamSteerSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_beamSteerSeconds ) },
{ NULL, NULL, NULL, 0 }
};
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index b99c43dd2..bbdb83946 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -82,6 +82,7 @@
#include "GameLogic/Module/TransportContain.h" // ... and a template's hold, before one exists
#include "GameLogic/Module/JetAIUpdate.h" // a Comanche is a jet with no runway
#include "GameLogic/Module/CleanupHazardUpdate.h" // an Ambulance out cleaning is left to it
+#include "GameLogic/Module/ParticleUplinkCannonUpdate.h" // driving the beam
#include <map>
#include "Platform/MsvcFloatCasts.h"
@@ -2142,8 +2143,10 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad
for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance())
{
Object *pObj = iter.cur();
- if (!pObj)
+ if (!pObj)
continue;
+ if (pObj->isEffectivelyDead())
+ continue; // a tank in its death throes stays on the team for seconds and held a steered beam on its wreck
if (!observerKnowsAbout(pObj, observerNdx))
continue; // a superweapon is aimed at what has been scouted, not at the object list
@@ -4826,6 +4829,7 @@ void AIPlayer::update( void )
AI_PHASE( AIP_ECONOMY, doSpending() ); // Upgrades for the army, and whatever is over the bank target.
AI_PHASE( AIP_POWER, doPower() ); // Keep the lights on, and out of reach.
AI_PHASE( AIP_ECONOMY, doSuperweapons() ); // The big guns, as soon as they can be bought.
+ AI_PHASE( AIP_TACTICS, doParticleBeams() ); // ... and the Particle Cannon's beam driven across his base.
AI_PHASE( AIP_WAVE, rememberEnemies() ); // Write down the enemy army in sight.
AI_PHASE( AIP_WAVE, answerArmy() ); // Train the answer to the part of it nothing answers.
AI_PHASE( AIP_WAVE, doMass() ); // Build the fist, and send it when it is one.
@@ -6359,6 +6363,93 @@ void AIPlayer::doSuperweapons( void )
buildAsap( superweapon );
}
+static void findParticleCannons( Object *obj, void *userData )
+{
+ static const NameKeyType key = NAMEKEY( "ParticleUplinkCannonUpdate" );
+ if( !obj->isKindOf( KINDOF_FS_SUPERWEAPON ) )
+ return;
+ ParticleUplinkCannonUpdate *cannon = (ParticleUplinkCannonUpdate *)obj->findUpdateModule( key );
+ if( cannon )
+ ((std::vector<ParticleUplinkCannonUpdate *> *)userData)->push_back( cannon );
+}
+
+/** How far from the burning spot a steer looks, about four seconds of the beam's fast drive. */
+const Real BEAM_STEER_REACH = 150.0f;
+/** The look is a square of this many steps each side of the burning spot. */
+const Int BEAM_STEER_STEPS = 3;
+
+//----------------------------------------------------------------------------------------------------------
+/** A computer player's Particle Cannon used to draw EA's S curve: 200 feet along the line from the
+ * uplink to the aim point, 50 either side of it, whatever stood there. The aim was the richest
+ * spot in his base, and most of the ten seconds of beam burned the ground on either side of it.
+ * A player drives the beam instead, from one building to the next. So does this: every
+ * m_beamSteerSeconds it looks around the spot the beam is burning, and sends it to the ground
+ * worth most with the same score the aim used, nearer ground preferred. What the beam has killed
+ * drops out of that score, so it moves on from a dead cluster to the next one by itself.
+ * Hard steers more often than the game's double click delay, which makes the cannon drive at its
+ * fast speed; Medium drives at the walking speed; Easy keeps the S curve. */
+//----------------------------------------------------------------------------------------------------------
+void AIPlayer::doParticleBeams( void )
+{
+ const Real every = getSkillProfile()->m_beamSteerSeconds;
+ if( every <= 0.0f )
+ return;
+ const Int rate = REAL_TO_INT_CEIL( every * LOGICFRAMES_PER_SECOND );
+ if( TheGameLogic->getFrame() % rate != 0 )
+ return;
+
+ std::vector<ParticleUplinkCannonUpdate *> cannons;
+ m_player->iterateObjects( findParticleCannons, &cannons );
+ for( size_t i = 0; i < cannons.size(); ++i )
+ {
+ Coord3D spot;
+ Real radius;
+ if( !cannons[ i ]->getBurningSpot( &spot, &radius ) )
+ continue;
+ Coord3D aim;
+ if( richestGroundNear( &spot, radius, &aim ) )
+ cannons[ i ]->setSpecialPowerOverridableDestination( &aim );
+ }
+}
+
+//----------------------------------------------------------------------------------------------------------
+Bool AIPlayer::richestGroundNear( const Coord3D *spot, Real radius, Coord3D *aim )
+{
+ const Int me = m_player->getPlayerIndex();
+ const Real step = BEAM_STEER_REACH / BEAM_STEER_STEPS;
+ Real best = 0.0f;
+ for( Int x = -BEAM_STEER_STEPS; x <= BEAM_STEER_STEPS; ++x )
+ {
+ for( Int y = -BEAM_STEER_STEPS; y <= BEAM_STEER_STEPS; ++y )
+ {
+ Coord3D pos;
+ pos.x = spot->x + x * step;
+ pos.y = spot->y + y * step;
+ pos.z = 0.0f;
+ Int value = 0;
+ for( Int p = 0; p < ThePlayerList->getPlayerCount(); ++p )
+ {
+ Player *other = ThePlayerList->getNthPlayer( p );
+ if( other != m_player && m_player->getRelationship( other->getDefaultTeam() ) == ENEMIES )
+ value += getPlayerSuperweaponValue( &pos, p, radius, TRUE, me );
+ }
+ const Real distance = sqrt( (Real)(x * x + y * y) ) * step;
+ const Real worth = value * (1.0f - 0.5f * distance / BEAM_STEER_REACH);
+ if( worth > best )
+ {
+ best = worth;
+ *aim = pos;
+ }
+ }
+ }
+ if( best <= 0.0f )
+ return FALSE;
+ aim->z = TheTerrainLogic->getGroundHeight( aim->x, aim->y );
+ DEBUG_LOG(("AI BEAM frame %d player %d drives the beam from (%.0f,%.0f) to (%.0f,%.0f), worth %.0f, radius %.0f\n",
+ TheGameLogic->getFrame(), me, spot->x, spot->y, aim->x, aim->y, best, radius));
+ return TRUE;
+}
+
//----------------------------------------------------------------------------------------------------------
/** The purchase queue. Every skirmish rung with a bank target, each saving below its own target; every
* campaign AI buys exactly as it did. */
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
index 0f048196c..712ad3a90 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
@@ -1133,6 +1133,24 @@ Bool ParticleUplinkCannonUpdate::findOrbitBeamRadius( Real &radius ) const
return TRUE;
}
+//-------------------------------------------------------------------------------------------------
+/** Where the beam is burning while it can still be driven: born, not yet decaying, not following a
+ * script's waypoints, and past its first damage pulse, which is when m_currentTargetPosition is the
+ * spot on the ground rather than whatever the last shot left in it. The radius is the one the next
+ * pulse will use. */
+//-------------------------------------------------------------------------------------------------
+Bool ParticleUplinkCannonUpdate::getBurningSpot( Coord3D *spot, Real *damageRadius ) const
+{
+ if( m_laserStatus != LASERSTATUS_BORN || m_scriptedWaypointMode || m_damagePulsesMade == 0 )
+ return FALSE;
+ Real beamRadius = 0.0f;
+ if( !findOrbitBeamRadius( beamRadius ) )
+ return FALSE;
+ *spot = m_currentTargetPosition;
+ *damageRadius = beamRadius * computeOrbitBeamWidthScalar( TheGameLogic->getFrame() ) * getParticleUplinkCannonUpdateModuleData()->m_damageRadiusScalar;
+ return TRUE;
+}
+
//-------------------------------------------------------------------------------------------------
/** LaserUpdate::computeWidthScalar on the cannon's own frames: wider from birth over WidthGrowTime,
* narrower from the decay over the same time, the same arithmetic so the radius is the same float. */
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index da6017460..2630495db 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -11892,6 +11892,11 @@ TEST(the_bank_target_and_the_upgrade_the_army_pays_for)
CHECK_EQ( 0.0f, data.m_skill[ AISKILL_MEDIUM ].m_factoryBankMultiple );
CHECK_EQ( 0.0f, data.m_skill[ AISKILL_EASY ].m_factoryBankMultiple );
CHECK( data.m_skill[ AISKILL_BRUTAL ].m_surplusShare >= 5.0f * data.m_skill[ AISKILL_MEDIUM ].m_surplusShare );
+ // Easy fires the retail S curve; Medium drives the Particle Cannon's beam at walking pace, Hard
+ // steers it often enough to count as the double click that drives it fast
+ CHECK_EQ( 0.0f, data.m_skill[ AISKILL_EASY ].m_beamSteerSeconds );
+ CHECK( data.m_skill[ AISKILL_MEDIUM ].m_beamSteerSeconds > data.m_skill[ AISKILL_BRUTAL ].m_beamSteerSeconds );
+ CHECK( data.m_skill[ AISKILL_BRUTAL ].m_beamSteerSeconds > 0.0f && data.m_skill[ AISKILL_BRUTAL ].m_beamSteerSeconds < 0.5f );
}