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): missiles holding height to the lock fly ea's flight
Olcay Seygan9be4c84474c6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f657937c0..5da1f821d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -82,6 +82,7 @@ found and fixed — EA's own, not port damage.**- Contra's cyborgs no longer stand on black squares. Their little ground shadow is drawn the way Zero Hour draws it again, darkening the ground by the shape painted in the picture, so it comes out as a soft patch under the feet. We had been reading the shape from the picture's transparency instead, and Contra's shadow picture has none: it filled its whole square. Zero Hour's own shadows look as they did.- A computer opponent on ShockWave's Armor, Special Weapons or Salvage general plays on every map now. Those are the three generals ShockWave adds to Zero Hour's nine, and Shockwave Chaos renames two of them the Scumbag Artillery and Bandana generals. A map made before they existed, every one Zero Hour ships among them, has no computer player for them, so the seat started with no AI at all: its base sat idle, and clicking it with nothing selected handed it to you, which is how a player found himself running the enemy's base. The seat now takes the mod's skirmish AI for that general and builds like any other; on Tournament Desert it had three buildings up in forty seconds where it used to have none.- ShockWave's EMP Patriot fires its missiles again. ShockWave switched on a short-range field around the battery that EA had left commented out, and every time the field pulsed, every 0.75 seconds, the battery's missiles had to wait their turn again from the start. The turret kept tracking its target and nothing left the rails: a lone EMP Patriot fired 0 missiles in 6 seconds at rocket soldiers 200 away, where Zero Hour's fires 12. The field now keeps its own clock, so the battery fires 12 like Zero Hour's and the field still pulses. ShockWave's Superweapon Humvee, its Reaper tank and its Salvage SA-2 site carried the same pairing.+- ShockWave's Armor General's cluster missiles land where you aim them. The missile is built to cruise high and drop straight onto the target, splitting into warheads on the way down, but it was flying Reforged's smooth Scud curve instead and split a long way off: aimed at a Scud Launcher, the warheads came down 180 to 270 short of it. A missile like this one now flies the way Zero Hour flew it, and the same two shots landed 4 and 5 from the aim and killed both launchers. Scuds and Tomahawks keep their curve.- Shockwave Chaos beside a second full mod starts now. With Contra, ShockWave and Shockwave Chaos switched on together the game stopped while loading, on one line of Chaos's Black Market tank that lists 43 of the mod's own tanks it can turn into. Keeping each mod's armies apart puts a short mark in front of every name the mod defines, and that line grew past the room the game gave a line of text. A line has three times the room now, more than any mod can fill.- A `-mod` path with `.` or `..` in it is refused. An archive counts as your mod's only when it was loaded for that mod. Two mods under `-modfactions` that define a command set with the same name both load now, and the later one wins.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.hindex 11c8b0db5..065bbde2d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h@@ -383,6 +383,14 @@ public:*/inline void setUsePreciseZPos(Bool u) { setFlag(PRECISE_Z_POS, u); }+ /**+ a missile's DistanceToTargetBeforeDiving, set only when that is inside its lock distance, so that+ it never dives before the lock. Such a missile flies EA's flight instead of the cruise curve: it+ holds its preferred height, dives inside this distance and is pulled straight onto the goal after+ the lock.+ */+ inline void setDiveDistance(Real dist) { m_diveDistance = dist; }+/**when off (the default), units slow down as they approach their target.@@ -459,6 +467,7 @@ protected:Real calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real curZ, Real surfaceAtPt, Real preferredHeight);Bool fixInvalidPosition(Object* obj, PhysicsBehavior *physics);+ Bool holdsHeightToLock() const; ///< see setDiveDistanceprotected:// snapshot methods@@ -516,7 +525,7 @@ private:UnsignedInt m_flags;Real m_preferredHeight;Real m_preferredHeightDamping;- Real m_sineDescentDistance; ///< no longer read; kept so saves keep their layout+ Real m_diveDistance; ///< see setDiveDistanceReal m_angleOffset;Real m_offsetIncrement;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.hindex 3a5fcbcb0..e7196ae20 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h@@ -53,7 +53,7 @@ public:UnsignedInt m_ignitionDelay; ///< delay in frames from when missile is 'fired', to when it starts moving 15Real m_initialVel;Real m_initialDist;- Real m_diveDistance; ///< parsed and unused: a cruise missile flies one curve to its goal (Locomotor::moveTowardsPositionThrust)+ Real m_diveDistance; ///< inside the lock distance, the missile keeps EA's flight over the cruise curve (Locomotor::setDiveDistance)const FXList* m_ignitionFX; ///< FXList to do when missile 'ignites'Bool m_useWeaponSpeed; ///< if true, limit speed of projectile to the Weapon's infoBool m_detonateOnNoFuel; ///< If true, don't just stop thrusting, blow up when out of gasdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cppindex 18e915bb4..0002093a8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp@@ -315,6 +315,18 @@ static Bool Locomotor_projectileChasesStraight(Object* obj, const Vector3& toGoareturn Vector3::Dot_Product(obj->getTransformMatrix()->Get_X_Vector(), toGoal) <= 0.0f;}+//-------------------------------------------------------------------------------------------------+// A missile that holds its cruise height until it has locked keeps EA's whole flight: level at the+// preferred height, then the cheat straight down onto the goal. Its data can count on that.+// ShockWave's cluster missile holds 500 until 0.01 from its goal and splits into warheads where it+// passes 420 over the ground coming down. The cruise curve split it 180 to 270 short of the aim;+// held level, the arc after the lock looped it 230 past, the goal lying almost straight under a+// level nose. A Scud or a Tomahawk dives before its lock and keeps the curve.+Bool Locomotor::holdsHeightToLock() const+{+ return m_diveDistance > 0.0f && m_preferredHeight != 0.0f;+}+//-------------------------------------------------------------------------------------------------inline Real tryToOrientInThisDirection3D(Object* obj, Real maxTurnRate, const Coord3D* dir){@@ -810,7 +822,7 @@ Locomotor::Locomotor(const LocomotorTemplate* tmpl)#endifm_preferredHeight = m_template->m_preferredHeight;m_preferredHeightDamping = m_template->m_preferredHeightDamping;- m_sineDescentDistance = 0.0f;+ m_diveDistance = 0.0f;m_angleOffset = GameLogicRandomValueReal(-PI/6, PI/6);m_offsetIncrement = (PI/40) * (GameLogicRandomValueReal(0.8f, 1.2f)/m_template->m_wanderLengthFactor);@@ -847,7 +859,7 @@ Locomotor::Locomotor(const Locomotor& that)#endifm_preferredHeight = that.m_preferredHeight;m_preferredHeightDamping = that.m_preferredHeightDamping;- m_sineDescentDistance = that.m_sineDescentDistance;+ m_diveDistance = that.m_diveDistance;m_angleOffset = that.m_angleOffset;m_offsetIncrement = that.m_offsetIncrement;m_yawRate = that.m_yawRate;@@ -876,7 +888,7 @@ Locomotor& Locomotor::operator=(const Locomotor& that)#endifm_preferredHeight = that.m_preferredHeight;m_preferredHeightDamping = that.m_preferredHeightDamping;- m_sineDescentDistance = that.m_sineDescentDistance;+ m_diveDistance = that.m_diveDistance;m_yawRate = that.m_yawRate;m_driveAccelX = that.m_driveAccelX;m_driveAccelY = that.m_driveAccelY;@@ -903,7 +915,7 @@ void Locomotor::crc( Xfer *xfer )/** Xfer method* Version Info:* 1: Initial version- * 3: m_sineDescentDistance+ * 3: m_diveDistance* 4: m_yawRate, m_driveAccelX, m_driveAccelY* 5: m_driveSpeed, m_driveFrame */// ------------------------------------------------------------------------------------------------@@ -936,7 +948,7 @@ void Locomotor::xfer( Xfer *xfer )xfer->xferReal(&m_offsetIncrement);if (version >= 3)- xfer->xferReal(&m_sineDescentDistance);+ xfer->xferReal(&m_diveDistance);if (version >= 4){@@ -1388,7 +1400,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalPvel = MIN_VEL;if (vel > dist)vel = dist; // do not overcompensate!- if (dist > 0.001f && Locomotor_projectileChasesStraight(obj, Vector3(dx, dy, dz)))+ if (dist > 0.001f && (holdsHeightToLock() || Locomotor_projectileChasesStraight(obj, Vector3(dx, dy, dz)))){pos.x += dx / dist * vel;pos.y += dy / dist * vel;@@ -2975,7 +2987,8 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics,//out of the handleBehaviorZ() functionCoord3D pos = *obj->getPosition();Real distToGoal2D = sqrt(sqr(goalPos.x - pos.x) + sqr(goalPos.y - pos.y));- if( m_preferredHeight != 0.0f && !getFlag(PRECISE_Z_POS) && obj->isKindOf(KINDOF_PROJECTILE) )+ const Bool heldToLock = holdsHeightToLock();+ if( m_preferredHeight != 0.0f && !getFlag(PRECISE_Z_POS) && obj->isKindOf(KINDOF_PROJECTILE) && !heldToLock ){// A cruise missile flies one smooth curve from where it is, leaving along the way it is going and// arriving in a sixty degree dive, aiming a few frames ahead on it. The curve is drawn again every@@ -3001,7 +3014,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics,localGoalPos.z = b0 * pos.z + b1 * (pos.z + leave.z * hLeave) + b2 * (goalPos.z - arrive.z * hArrive) + b3 * goalPos.z;}}- else if( m_preferredHeight != 0.0f && !getFlag(PRECISE_Z_POS) )+ else if( m_preferredHeight != 0.0f && !getFlag(PRECISE_Z_POS) && !(heldToLock && distToGoal2D < m_diveDistance) ){// If we have a preferred flight height, and we haven't been told explicitly to ignore it...Real surfaceHt = getSurfaceHtAtPt(pos.x, pos.y);@@ -3054,7 +3067,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics,// we are at target.adjust = false;}- else if (obj->isKindOf(KINDOF_PROJECTILE) && !Locomotor_projectileChasesStraight(obj, vel))+ else if (obj->isKindOf(KINDOF_PROJECTILE) && !holdsHeightToLock() && !Locomotor_projectileChasesStraight(obj, vel)){// 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 thediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cppindex 38a01cb0c..e531aa861 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp@@ -577,6 +577,12 @@ void MissileAIUpdate::doAttackState(Bool turnOK)}}+ // a missile that would not dive before its lock flies EA's flight, not the cruise curve; the lock+ // distance is halved for a ground position, as below+ Real effectiveLockDistance = m_isTrackingTarget ? d->m_lockDistance : d->m_lockDistance * 0.5f;+ if (curLoco)+ curLoco->setDiveDistance(d->m_diveDistance < effectiveLockDistance ? d->m_diveDistance : 0.0f);+if (d->m_lockDistance > 0){Real lockDistanceSquared = d->m_lockDistance;