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): missiles lead moving ground targets from launch

Olcay Seygan6a558dc111db
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 166c081d7..32f922110 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -443,7 +443,7 @@ found and fixed — EA's own, not port damage.**
- Something flagged unselectable is unselectable. The flag existed and nothing read it.
- A suicide unit pressed up against a building goes off. Touching the building's outline counted as having its view blocked, so it walked away to find a clear line of sight it never needed, came back, and did it again without ever detonating.
- A nuclear missile hurts the whole of a big building. The blast measured to the middle of everything near it, so an airfield whose centre sat just outside the outer ring took nothing while half of it stood in the fire. Distance is now taken halfway between the nearest edge and the centre.
-- Rockets curve into their target instead of snapping onto it. In the last few frames before impact a guided missile swung its nose straight at the target in one step, up to 40 degrees in a single frame, when the whole flight before that never turned more than 5. It now flies an arc from the heading it had to the spot where it meets the target, so a tank driving across its path is led rather than chased. In the same test battle no rocket turns more than 8 degrees in a frame, and all 101 land. Rockets fired at aircraft still fly straight at them: a helicopter is nearly as fast as the rocket, and on an arc the rocket flew past it and climbed away into the sky. A rocket whose target is behind it flies straight at it too. The arc to something behind the nose loops out past it, and when the target is on the ground under a helicopter the bottom of that loop is in the dirt: a Comanche hovering over a supply truck put all four missiles into the ground 23 to 47 away from it, while the same Comanche 250 away landed all four. Now the truck is down to 16 health of 300 five seconds in, where it had 136. Rockets fired at driving tanks and at aircraft land exactly where they did before.
+- Rockets curve into their target instead of snapping onto it. In the last few frames before impact a guided missile swung its nose straight at the target in one step, up to 40 degrees in a single frame, when the whole flight before that never turned more than 5. It now flies an arc from the heading it had to the spot where it meets the target, so a tank driving across its path is led rather than chased. In the same test battle no rocket turns more than 8 degrees in a frame, and all 101 land. Rockets fired at aircraft still fly straight at them: a helicopter is nearly as fast as the rocket, and on an arc the rocket flew past it and climbed away into the sky. A rocket whose target is behind it flies straight at it too. The arc to something behind the nose loops out past it, and when the target is on the ground under a helicopter the bottom of that loop is in the dirt: a Comanche hovering over a supply truck put all four missiles into the ground 23 to 47 away from it, while the same Comanche 250 away landed all four. Now the truck is down to 16 health of 300 five seconds in, where it had 136. Rockets fired at driving tanks and at aircraft land exactly where they did before. A rocket fired at a soldier on the move now goes where he will be when it gets there. Rockets at infantry fly at a spot on the ground rather than at the man, and a soldier walking across the line of fire had left that spot before the rocket came down. A Stinger Site shooting at twelve Rangers walking past it killed three in each of six matches where it used to kill one, and took 627 health off the squad where it took 447. A rocket at someone standing still lands where it always did. A replay recorded before this change, with rockets fired at moving infantry, will not play back the same.
- Scuds come down from the top of their climb in a smooth curve, level at the top and steepest at the end, instead of tipping into a straight dive 200 short of the target. Over those last 200 a Scud now stays within 14 of that curve where the dive strayed by up to 49, and every one lands on the spot it was fired at; one in the old test came down 22 away.
- Cancelling an order of Red Guard after the first soldier has walked out no longer refunds the order. One order is two soldiers for one price, and the refund came back whole, so the first one was free.
- Double-clicking to grab everything of a kind grabs what a box would, not things you can only click one at a time.
diff --git a/GeneralsMD/Code/Data/Scenarios/leadinfantry.txt b/GeneralsMD/Code/Data/Scenarios/leadinfantry.txt
new file mode 100644
index 000000000..9cf3dee07
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/leadinfantry.txt
@@ -0,0 +1,21 @@
+# A Stinger Site shooting at Rangers walking across in front of it, for issue #46.
+#
+# A rocket at infantry is a shot at a point: ScatterRadiusVsInfantry turns it into a coordinate shot,
+# and a Ranger walking across the line of fire is somewhere else by the time the rocket lands there.
+# The Rangers walk 550 units across the open grass of the small generated map, passing 150 to the side
+# of the site, and the two tallies say how much of the squad was left. Nothing is ordered to shoot:
+# the site picks its own targets as the Rangers come into range, and a building does not chase.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 1 2 small -autoskirmish 2 -takeover
+# -side 0 FactionGLA -side 1 FactionAmerica -seed 1 -maxframes 1100
+# -scenario leadinfantry -logPrefix leadinfantry_
+#
+# See mobstress.txt for the line grammar.
+
+30 spawn 0 GLAStingerSite 1 700 800
+30 spawn 1 AmericaInfantryRanger 12 850 550 15
+
+60 move 1 AmericaInfantryRanger 850 1100
+60 tally 1 AmericaInfantryRanger
+1080 tally 1 AmericaInfantryRanger
diff --git a/GeneralsMD/Code/Data/Scenarios/leadvehicle.txt b/GeneralsMD/Code/Data/Scenarios/leadvehicle.txt
new file mode 100644
index 000000000..c463b28b3
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/leadvehicle.txt
@@ -0,0 +1,20 @@
+# Missile Defenders shooting at Technicals driving across in front of them, for issue #46.
+#
+# Against a vehicle the rocket follows its target, flying at where the Technical is until it is close
+# enough to lock on. The Technicals drive 700 units across the open grass of the small generated map,
+# passing 120 to the side of the four Missile Defenders, and the two tallies say how much of the
+# column was left. Nothing is ordered to shoot: the Defenders pick their own targets.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 1 2 small -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 900
+# -scenario leadvehicle -logPrefix leadvehicle_
+#
+# See mobstress.txt for the line grammar.
+
+30 spawn 0 AmericaInfantryMissileDefender 4 700 800 18
+30 spawn 1 GLAVehicleTechnical 6 820 450 30
+
+60 move 1 GLAVehicleTechnical* 820 1150
+60 tally 1 GLAVehicleTechnical*
+880 tally 1 GLAVehicleTechnical*
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
index 58608ac9e..e357453cc 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
@@ -515,5 +515,7 @@ private:
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
extern LocomotorStore *TheLocomotorStore;
+Coord3D Locomotor_groundLead(const Coord3D& toVictim, const Coord3D& victimVelocity, Real speed);
+
#endif // __Locomotor_H_
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h
index 821861573..9246d8652 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h
@@ -94,6 +94,7 @@ public:
virtual ProjectileUpdateInterface* getProjectileUpdateInterface() { return this; }
virtual void projectileFireAtObjectOrPosition( const Object *victim, const Coord3D *victimPos, const WeaponTemplate *detWeap, const ParticleSystemTemplate* exhaustSysOverride );
virtual void projectileLaunchAtObjectOrPosition(const Object *victim, const Coord3D* victimPos, const Object *launcher, WeaponSlotType wslot, Int specificBarrelToUse, const WeaponTemplate* detWeap, const ParticleSystemTemplate* exhaustSysOverride);
+ virtual void projectileLeadVictim( const Object *victim );
virtual Bool projectileHandleCollision( Object *other );
virtual Bool projectileIsArmed() const { return m_isArmed; }
virtual ObjectID projectileGetLauncherID() const { return m_launcherID; }
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h
index d2e4433d3..81a368f5f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h
@@ -264,6 +264,7 @@ class ProjectileUpdateInterface
public:
virtual void projectileLaunchAtObjectOrPosition(const Object *victim, const Coord3D* victimPos, const Object *launcher, WeaponSlotType wslot, Int specificBarrelToUse, const WeaponTemplate* detWeap, const ParticleSystemTemplate* exhaustSysOverride) = 0; ///< launch the projectile at the given victim
virtual void projectileFireAtObjectOrPosition( const Object *victim, const Coord3D *victimPos, const WeaponTemplate *detWeap, const ParticleSystemTemplate* exhaustSysOverride ) = 0;
+ virtual void projectileLeadVictim( const Object *victim ) {} ///< a shot just launched at a point near this victim aims where it will be instead
virtual Bool projectileIsArmed() const = 0; ///< return true if the projectile is armed and ready to explode
virtual ObjectID projectileGetLauncherID() const = 0; ///< All projectiles need to keep track of their firer
virtual Bool projectileHandleCollision(Object *other) = 0;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index a101dcb53..afd01b611 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -245,6 +245,20 @@ Coord3D Locomotor_interceptOffset(const Coord3D& toVictim, const Coord3D& victim
return offset;
}
+//-------------------------------------------------------------------------------------------------
+// How far a victim on the ground moves before a projectile flying straight at `speed` a frame meets it,
+// for the aim point that far ahead of the victim. Only the victim's travel over the ground counts, as in
+// the arc after the lock: its velocity's climb over a slope is left out. Zero for a victim standing still.
+Coord3D Locomotor_groundLead(const Coord3D& toVictim, const Coord3D& victimVelocity, Real speed)
+{
+ Coord3D flatVelocity = victimVelocity;
+ flatVelocity.z = 0.0f;
+ Coord3D meeting = Locomotor_interceptOffset(toVictim, flatVelocity, speed);
+ Coord3D lead;
+ lead.set(meeting.x - toVictim.x, meeting.y - toVictim.y, 0.0f);
+ return lead;
+}
+
//-------------------------------------------------------------------------------------------------
// A locked projectile chasing something in the air keeps EA's cheat and moves straight at it every
// frame. An aircraft is nearly as fast as the rocket, and neither arc could close on one: a rocket got
@@ -2008,11 +2022,28 @@ void Locomotor::moveTowardsPositionHover(Object* obj, PhysicsBehavior *physics,
}
//-------------------------------------------------------------------------------------------------
-void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed)
+void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, const Coord3D& chasedGoalPos, Real onPathDistToGoal, Real desiredSpeed)
{
BodyDamageType bdt = obj->getBodyModule()->getDamageState();
Real maxForwardSpeed = getMaxSpeedForCondition(bdt);
+
+ // A missile that has not locked on yet flies at where a victim on the ground will be when it gets
+ // there, not at where the victim is now, so it comes up to the lock already in front of a crossing
+ // vehicle. The lock's cheat put these hits in anyway: Missile Defenders at Technicals driving past
+ // killed as many with it as without. Aircraft keep the straight chase: see
+ // Locomotor_projectileChasesStraight.
+ Coord3D goalPos = chasedGoalPos;
+ Object *victim = obj->isKindOf(KINDOF_PROJECTILE) ? obj->getAI()->getGoalObject() : NULL;
+ if (victim && victim->getPhysics() && !victim->isAboveTerrain() && !obj->getStatusBits().test(OBJECT_STATUS_BRAKING))
+ {
+ Coord3D toVictim;
+ toVictim.set(goalPos.x - obj->getPosition()->x, goalPos.y - obj->getPosition()->y, goalPos.z - obj->getPosition()->z);
+ Coord3D lead = Locomotor_groundLead(toVictim, *victim->getPhysics()->getVelocity(), maxForwardSpeed);
+ goalPos.x += lead.x;
+ goalPos.y += lead.y;
+ }
+
desiredSpeed = clamp(m_template->m_minSpeed, desiredSpeed, maxForwardSpeed);
Real actualForwardSpeed = physics->getForwardSpeed3D();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp
index 66d402aa5..1fb8d24c2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp
@@ -306,6 +306,39 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co
m_prevPos = *getObject()->getPosition();
}
+//-------------------------------------------------------------------------------------------------
+// A shot at a point flies there and goes off, and a victim moving across the line of fire has left it
+// by then: a rocket at infantry is always such a shot, its scatter makes it one. Move the point as far
+// as a victim on the ground goes in the missile's flight. A Stinger Site at twelve Rangers walking
+// past killed one and took 447 health off them before, three and 627 after, over six seeds. A missile
+// that follows its victim leads it on the way instead (Locomotor::moveTowardsPositionThrust), and a
+// victim standing still keeps the shot it had.
+//-------------------------------------------------------------------------------------------------
+void MissileAIUpdate::projectileLeadVictim( const Object *victim )
+{
+ const PhysicsBehavior *victimPhysics = victim->getPhysics();
+ if (m_isTrackingTarget || victimPhysics == NULL || victim->isAboveTerrain())
+ return;
+
+ const Coord3D *from = getObject()->getPosition();
+ Coord3D toVictim;
+ toVictim.set(victim->getPosition()->x - from->x, victim->getPosition()->y - from->y, victim->getPosition()->z - from->z);
+ Coord3D lead = Locomotor_groundLead(toVictim, *victimPhysics->getVelocity(), getCurLocomotor()->getMaxSpeedForCondition(BODY_PRISTINE));
+ if (lead.x == 0.0f && lead.y == 0.0f)
+ return;
+
+ // keep the point as high over the ground as it was: on the ground for a scattered shot
+ Real groundBefore = TheTerrainLogic->getLayerHeight(m_originalTargetPos.x, m_originalTargetPos.y, victim->getLayer());
+ m_originalTargetPos.x += lead.x;
+ m_originalTargetPos.y += lead.y;
+ m_originalTargetPos.z += TheTerrainLogic->getLayerHeight(m_originalTargetPos.x, m_originalTargetPos.y, victim->getLayer()) - groundBefore;
+
+ Coord3D initialPos = m_originalTargetPos;
+ if (getMissileAIUpdateModuleData()->m_lockDistance > 0.0f)
+ initialPos.z += APPROACH_HEIGHT;
+ aiMoveToPosition(&initialPos, CMD_FROM_AI);
+}
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
Bool MissileAIUpdate::projectileHandleCollision( Object *other )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
index dbf1593f7..034cb23e8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
@@ -1222,6 +1222,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
{
pui->projectileLaunchAtObjectOrPosition(victimObj, &projectileDestination, sourceObj, wslot, specificBarrelToUse, this, m_projectileExhausts[v]);
}
+ if( victimObj )
+ pui->projectileLeadVictim( victimObj );
}
else
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index a5995b2e9..eb556fa0b 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -7349,6 +7349,7 @@ TEST(an_enemy_plan_is_hidden_even_where_the_viewer_has_sight)
}
extern Coord3D Locomotor_interceptOffset( const Coord3D& toVictim, const Coord3D& victimVelocity, Real speed );
+extern Coord3D Locomotor_groundLead( const Coord3D& toVictim, const Coord3D& victimVelocity, Real speed );
/** A locked missile curves towards where it will meet a moving victim. Curving towards where the
victim is now left a rocket barely faster than a helicopter trailing it with its nose 40 degrees
@@ -7385,6 +7386,36 @@ TEST(a_locked_missile_aims_where_it_will_meet_a_moving_victim)
CHECK_NEAR( offset.x, 100.0f, 0.001f );
}
+/** A missile shot at infantry flies to a point, and a Rebel walking across the line of fire was gone
+ from it when the rocket landed. The point moves as far as the victim walks in the flight, over the
+ ground only, and not at all for a victim standing still. */
+TEST(a_missile_aims_ahead_of_a_victim_moving_on_the_ground)
+{
+ Coord3D toVictim;
+ toVictim.set( 100.0f, 0.0f, -20.0f );
+ Coord3D lead;
+
+ Coord3D standing;
+ standing.set( 0.0f, 0.0f, 0.0f );
+ lead = Locomotor_groundLead( toVictim, standing, 10.0f );
+ CHECK( lead.x == 0.0f && lead.y == 0.0f && lead.z == 0.0f );
+
+ // crossing at 3 a frame against 10: |(100, 3t, -20)| = 10t meets at t = 10.69, 32 to the side
+ Coord3D crossing;
+ crossing.set( 0.0f, 3.0f, 0.0f );
+ lead = Locomotor_groundLead( toVictim, crossing, 10.0f );
+ CHECK_NEAR( lead.x, 0.0f, 0.001f );
+ CHECK_NEAR( lead.y, 3.0f * 10.6904f, 0.01f );
+ CHECK_NEAR( lead.z, 0.0f, 0.001f );
+
+ // walking up a slope the climb is not led: the same crossing, the same point
+ Coord3D climbing;
+ climbing.set( 0.0f, 3.0f, 1.5f );
+ Coord3D climbLead = Locomotor_groundLead( toVictim, climbing, 10.0f );
+ CHECK_NEAR( climbLead.y, lead.y, 0.001f );
+ CHECK_NEAR( climbLead.z, 0.0f, 0.001f );
+}
+
/** There is nothing to stop about a building that is still going up, so the stop key calls it off
instead - the same cancel, refund and all, that the command bar button on that structure does.
One structure of your own only: a mixed selection or anything already finished still means