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(gameengine): chase aircraft straight, lead ground targets on the arc
Olcay Seyganfaec085277de
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7a0da2630..2146fea32 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -297,7 +297,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 into the target. In the same test battle the sharpest turn is 16 degrees, and the rockets still land.+- 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.- 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/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cppindex 96e075dc6..9e1913c7b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp@@ -64,6 +64,7 @@ LocomotorStore *TheLocomotorStore = NULL; ///< the Locomotor store definitioconst Real BIGNUM = 99999.0f;const Real SINE_DESCENT_LOOKAHEAD_FRAMES = 4.0f;+const Real INTERCEPT_EPSILON = 0.0001f;static const char *TheLocomotorPriorityNames[] ={@@ -207,6 +208,54 @@ static Real calcArcTurnToGoal(const Vector3& nose, const Vector3& toGoal, Real sreturn 2.0f * step * sine / dist;}+//-------------------------------------------------------------------------------------------------+// Where a projectile flying straight at `speed` a frame meets a victim that keeps its velocity, as an+// offset from the projectile: the smallest t > 0 with |toVictim + victimVelocity*t| = speed*t. A victim+// standing still is its own meeting point, and one this speed never catches is aimed at directly.+Coord3D Locomotor_interceptOffset(const Coord3D& toVictim, const Coord3D& victimVelocity, Real speed)+{+ Real a = sqr(victimVelocity.x) + sqr(victimVelocity.y) + sqr(victimVelocity.z) - sqr(speed);+ Real b = 2.0f * (toVictim.x * victimVelocity.x + toVictim.y * victimVelocity.y + toVictim.z * victimVelocity.z);+ Real c = sqr(toVictim.x) + sqr(toVictim.y) + sqr(toVictim.z);++ Real meetingFrames = -1.0f;+ if (fabs(a) < INTERCEPT_EPSILON)+ {+ if (b < 0.0f)+ meetingFrames = -c / b;+ }+ else if (b * b - 4.0f * a * c >= 0.0f)+ {+ Real root = sqrt(b * b - 4.0f * a * c);+ Real firstFrames = (-b - root) / (2.0f * a);+ Real secondFrames = (-b + root) / (2.0f * a);+ if (firstFrames > secondFrames)+ std::swap(firstFrames, secondFrames);+ meetingFrames = (firstFrames > 0.0f) ? firstFrames : secondFrames;+ }++ if (meetingFrames <= 0.0f)+ return toVictim;++ Coord3D offset;+ offset.set(toVictim.x + victimVelocity.x * meetingFrames,+ toVictim.y + victimVelocity.y * meetingFrames,+ toVictim.z + victimVelocity.z * meetingFrames);+ return offset;+}++//-------------------------------------------------------------------------------------------------+// 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+// within 11 of a helicopter, flew past it and climbed away with its nose 110 degrees off. Rockets at+// helicopters and jets over 1800 frames stayed locked p95 20 frames on the straight chase and never drew+// away; the arc took 26 and drew away 5 times, the arc onto the meeting point 35 and 17.+static Bool Locomotor_projectileChasesStraight(Object* obj)+{+ Object *victim = obj->getAI()->getGoalObject();+ return victim && victim->isAboveTerrain();+}+//-------------------------------------------------------------------------------------------------inline Real tryToOrientInThisDirection3D(Object* obj, Real maxTurnRate, const Coord3D* dir){@@ -1147,15 +1196,22 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP{// Projectiles never stop braking once they start. jba.obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) );- // Projectiles cheat in 3 dimensions, along the nose rather than straight at the goal, so a- // missile flies the arc moveTowardsPositionThrust turns it onto instead of kinking at the lock.+ // Projectiles cheat in 3 dimensions. Chasing an aircraft that is straight at it; otherwise along+ // the nose, so a missile flies the arc moveTowardsPositionThrust turns it onto instead of+ // kinking at the lock.dist = sqrt(dx*dx+dy*dy+dz*dz);Real vel = physics->getVelocityMagnitude();if (vel < MIN_VEL)vel = MIN_VEL;if (vel > dist)vel = dist; // do not overcompensate!- if (dist > 0.001f)+ if (dist > 0.001f && Locomotor_projectileChasesStraight(obj))+ {+ pos.x += dx / dist * vel;+ pos.y += dy / dist * vel;+ pos.z += dz / dist * vel;+ }+ else if (dist > 0.001f){Vector3 nose = obj->getTransformMatrix()->Get_X_Vector();nose.Normalize();@@ -2036,12 +2092,26 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics,// we are at target.adjust = false;}- else if (obj->isKindOf(KINDOF_PROJECTILE))+ else if (obj->isKindOf(KINDOF_PROJECTILE) && !Locomotor_projectileChasesStraight(obj)){- // the projectile cheat moves along the nose, so this turn is the path it flies+ // the projectile cheat moves along the nose, so this turn is the path it flies. It bends+ // towards where a moving victim will be when the missile gets there rather than where the+ // victim is now: rockets at driving tanks turned p95 4.1 and at most 7.5 degrees a frame.Real step = physics->getVelocityMagnitude();if (step < MIN_VEL)step = MIN_VEL;+ Object *victim = obj->getAI()->getGoalObject();+ if (victim && victim->getPhysics() && step < vel.Length())+ {+ Coord3D toVictim;+ toVictim.set(vel.X, vel.Y, vel.Z);+ // flat: an aircraft held at its cruise height still carries the climb in its velocity, and+ // leading on that sent rockets straight up past the helicopter they were chasing+ Coord3D victimVelocity = *victim->getPhysics()->getVelocity();+ victimVelocity.z = 0.0f;+ Coord3D lead = Locomotor_interceptOffset(toVictim, victimVelocity, step);+ vel.Set(lead.x, lead.y, lead.z);+ }maxTurnRate = calcArcTurnToGoal(forwardDir, vel, step);}elsediff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex e5d446a3a..e11d1e0f4 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -6509,6 +6509,43 @@ TEST(an_enemy_plan_is_hidden_even_where_the_viewer_has_sight)CHECK( Object_isPlanHiddenFrom( FALSE, CONSTRUCTION_COMPLETE, ENEMIES ) == FALSE );}+extern Coord3D Locomotor_interceptOffset( 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+ off, never closing. */+TEST(a_locked_missile_aims_where_it_will_meet_a_moving_victim)+{+ Coord3D toVictim;+ toVictim.set( 100.0f, 0.0f, 0.0f );+ Coord3D offset;++ Coord3D standing;+ standing.set( 0.0f, 0.0f, 0.0f );+ offset = Locomotor_interceptOffset( toVictim, standing, 10.0f );+ CHECK_NEAR( offset.x, 100.0f, 0.001f );+ CHECK_NEAR( offset.y, 0.0f, 0.001f );++ // crossing at 6 a frame against 10: |(100, 6t)| = 10t meets at t = 12.5, 75 to the side+ Coord3D crossing;+ crossing.set( 0.0f, 6.0f, 0.0f );+ offset = Locomotor_interceptOffset( toVictim, crossing, 10.0f );+ CHECK_NEAR( offset.x, 100.0f, 0.001f );+ CHECK_NEAR( offset.y, 75.0f, 0.01f );++ // head on at the missile's own speed the two meet halfway+ Coord3D closing;+ closing.set( -10.0f, 0.0f, 0.0f );+ offset = Locomotor_interceptOffset( toVictim, closing, 10.0f );+ CHECK_NEAR( offset.x, 50.0f, 0.001f );++ // running away faster than the missile flies there is no meeting point to lead, so aim at it+ Coord3D fleeing;+ fleeing.set( 12.0f, 0.0f, 0.0f );+ offset = Locomotor_interceptOffset( toVictim, fleeing, 10.0f );+ CHECK_NEAR( offset.x, 100.0f, 0.001f );+}+/** There is nothing to stop about a building that is still going up, so the stop key calls it offinstead - 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