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): jets bank in wide turns, fly a circuit, taxi on wheels

Olcay Seygan7ef05c695b9d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c291e0bda..c7a91a1aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,16 @@ found and fixed — EA's own, not port damage.**
---
+## Jets fly like jets
+
+- The Raptor, King Raptor, MiG, Aurora and Stealth Fighter turn the way a plane turns. The faster a jet flies, the slower it comes round, so at cruise it sweeps a wide arc and only a slow jet turns tight. It no longer slides sideways through a turn. A Raptor's half circle at cruise takes about 3.2 seconds, where it took about 1.7.
+- A jet banks into every turn and rolls through level when it swings from one turn into the opposite one, so you can read where it is going from its wings.
+- Attack runs take longer, and against a target that moves that is a real nerf. A jet cannot snap round onto a tank that drives out from under it, so it flies a wider loop to come back for another pass. In a test a Raptor's pass on a moving Overlord took about 14 seconds where it took about 4. That is the price of a plane that turns like one.
+- Takeoff has a runway in it. The jet rolls at full throttle, rotates its nose up, lifts its wheels off the tarmac and climbs out at a steady angle, where it used to hop off the end of the runway.
+- Landing has a circuit in it. The jet turns down in a descending curve onto a straight final, glides in, flares and touches down on the centreline, then rolls out and slows. It used to corkscrew down and stop dead.
+- On the ground a jet taxis on its wheels. It rounds the taxiway corners, rolls straight out of the landing into the taxi and turns into its parking spot in one smooth sweep.
+- Helicopters are untouched and fly as they did.
+
## A tank shell kills the man it hits
- A cannon shell did 6 damage to a soldier. A Ranger has 180 health, so thirty shells that actually hit him left him standing, a full minute of fire from a Crusader, while the same shell does 60 to another tank. It now does that 60 to him as well. Three hits kill a Ranger. Two kill a Red Guard or a Rebel.
diff --git a/GeneralsMD/Code/Data/INI/BalanceReforged.ini b/GeneralsMD/Code/Data/INI/BalanceReforged.ini
index c185f7ea0..0bd300c44 100644
--- a/GeneralsMD/Code/Data/INI/BalanceReforged.ini
+++ b/GeneralsMD/Code/Data/INI/BalanceReforged.ini
@@ -871,6 +871,23 @@ Locomotor CombatBikeTerroristCliffLocomotor
TurnRateDamaged = 150 ; EA: 120
End
+; ---- jets taxi on a nose wheel ---------------------------------------------------------------------
+;
+; EA taxied every jet on treads with a Braking of 999999: it stopped dead off its landing roll and at
+; every corner of the taxiway, spun on the spot to the next leg at 180 degrees a second, and spun again
+; on its parking spot. On four wheels it drives the ground vehicles' drive (Locomotor::isGroundVehicle):
+; it brakes for a corner and rounds it, crawls round one too tight for its turning circle instead of
+; spinning, and slows to a stop at the end of the taxi. Turning on its spot to its parking heading or
+; onto the runway eases in and out (Locomotor::locoUpdate_moveTowardsAngle). Speed is EA's.
+; Scenarios/jetrunway.txt has the numbers.
+
+Locomotor BasicJetTaxiLocomotor
+ Appearance = FOUR_WHEELS ; EA: TREADS
+ Braking = 50 ; EA: 999999
+ TurnRate = 120 ; EA: 180
+ TurnRateDamaged = 120 ; EA: 180
+End
+
; ---- missile defence: point defense lasers in clips, and a burst where they hit ------------------
;
; EA gave the Air Force General's King Raptor, Aurora, Stealth Fighter, B-3 and both Chinooks, the
diff --git a/GeneralsMD/Code/Data/Scenarios/jetpass.txt b/GeneralsMD/Code/Data/Scenarios/jetpass.txt
index f9570466d..02b52bc64 100644
--- a/GeneralsMD/Code/Data/Scenarios/jetpass.txt
+++ b/GeneralsMD/Code/Data/Scenarios/jetpass.txt
@@ -12,8 +12,14 @@
# out, turns and fires all four, and the Overlord has 700 at frame 400. The other three targets end
# on the same health in both builds. The 42-pass sweep behind the changelog numbers (attack frame
# 240 to 300, wing offset 0 to 180, parked and driving) is in the commit message of the fix.
+#
+# 2026-10-16: the spawn check now refuses 2200,3300 (a cliff cell), so the Overlord starts at 2250.
+# Banked flight against EA's, health at frame 650 and the frame of the first hit: Overlord 700 at 400
+# against 800 at 490 (the Raptor turns too wide to get all four off in one pass and is still on its
+# second at 650), Battle Master 222 at 290 against 234 at 500, Crusader 80 at 300 against 80 at 330,
+# Scorpion 170 at 330 against 170 at 430. Every jet still hits; the wide turns cost time.
-30 spawn 1 ChinaTankOverlord 1 2200 3300
+30 spawn 1 ChinaTankOverlord 1 2250 3300
30 spawn 0 AmericaJetRaptor 1 1000 3420
31 move 0 AmericaJetRaptor 4400 3420
30 spawn 1 ChinaTankBattleMaster 1 2200 3650
@@ -26,7 +32,7 @@
30 spawn 0 AmericaJetStealthFighter 1 1000 4470
31 move 0 AmericaJetStealthFighter 4400 4470
250 attack 0 AmericaJetRaptor 1 ChinaTankOverlord
-250 move 1 ChinaTankOverlord 2200 3000
+250 move 1 ChinaTankOverlord 2250 3000
250 attack 0 ChinaJetMIG 1 ChinaTankBattleMaster
250 move 1 ChinaTankBattleMaster 2200 3350
250 attack 0 AmericaJetAurora 1 AmericaTankCrusader
diff --git a/GeneralsMD/Code/Data/Scenarios/jetrunway.txt b/GeneralsMD/Code/Data/Scenarios/jetrunway.txt
new file mode 100644
index 000000000..1679d59e2
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/jetrunway.txt
@@ -0,0 +1,33 @@
+# A Raptor built at an airfield, sent out, and left idle until it comes home: one takeoff and one
+# landing on the same runway. The airfield (isobase2's ground) builds it in 20 seconds; the move at
+# 700 sends it about 1500 away, and ten seconds after it gets there (ReturnToBaseIdleTime) it flies
+# back and lands.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Golden Oasis\Golden Oasis.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -maxframes 6000
+# -scenario jetrunway -logPrefix jetrunway_
+#
+# Measured 2026-10-16 with a temporary per-frame trace (runway 140 long, threshold at x 2690).
+# Takeoff, EA: held at about 105 u/s by the slow-down for the end of its path, the wheels left 67
+# down the runway and it went from level to 51 u/s up in a fifth of a second, a 25 degree hop.
+# Now: full throttle to 175, wheels off 43 down, the climb rounds into 12 degrees (5 to 35 u/s up),
+# 14 up at the far end of the runway and 30 at 224.
+# Landing, EA: it reached the threshold at 100 up and corkscrewed 270 degrees down to the runway in
+# 2.4 s, sinking at up to 73 u/s, touched down 103 past the threshold 13 degrees off the centre line,
+# and stopped dead from 60 u/s into the taxi. Now: a circuit out to 183 past the threshold, a
+# descending turn onto a 150 final, an 11 degree glide (sink no more than 22 u/s), a flare to a
+# touchdown 52 past the threshold on the centre line, and a rollout from 61 to 17 u/s. Threshold to
+# touchdown takes 6.6 s instead of 2.4.
+# Taxi, EA: treads, so it stopped dead at each taxiway corner and spun on the spot at 180 degrees a
+# second, and swung onto its parking spot the same way. Now: on its nose wheel, the corners rounded
+# and taken at 14 to 30 u/s, the rollout running into the taxi without a stop, a slow stop on the
+# spot and an eased half turn there in 1.8 s. Runway to parked takes 4.7 s instead of 3.2.
+#
+# For a film, swap -headless for -win -fps 120.
+
+30 spawn 0 AmericaAirfield 1 2520 3370
+30 spawn 0 AmericaPowerPlant 1 1950 3380
+40 produce 0 AmericaAirfield AmericaJetRaptor 1
+700 move 0 AmericaJetRaptor 2520 1900
+2900 tally 0 AmericaJetRaptor
diff --git a/GeneralsMD/Code/Data/Scenarios/jetturn.txt b/GeneralsMD/Code/Data/Scenarios/jetturn.txt
new file mode 100644
index 000000000..977c78728
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/jetturn.txt
@@ -0,0 +1,33 @@
+# Four jets at cruise turned round: each flies east, and at frame 150 is sent back to the x it started
+# from on its own line, a 180 degree reversal at full speed. The width of the U is twice the turn
+# radius the jet flies at cruise, and the time from the order to the heading settling on west is the
+# time the reversal takes.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -maxframes 700
+# -scenario jetturn -logPrefix jetturn_
+#
+# Measured 2026-10-16 with a temporary per-frame trace, EA's flight against the banked one
+# (Locomotor::getJetMaxYawRate): reversal time, width of the U, and the tightest radius flown.
+# Raptor 1.68 s 168 83 -> 3.22 s 217 103
+# MiG 1.67 s 157 76 -> 3.22 s 198 94
+# Aurora 1.08 s 102 57 -> 2.25 s 152 73
+# Stealth 0.93 s 91 56 -> 2.03 s 160 71
+# EA's yaw rate jumped to full in a frame or two (4 to 6 degrees a frame squared); the banked one
+# winds up over half a second (0.2).
+#
+# For a film, swap -headless for -win -fps 120 and follow one jet; the Raptor is on 3000.
+
+30 spawn 0 AmericaJetRaptor 1 1000 3000
+30 spawn 0 ChinaJetMIG 1 1000 3600
+30 spawn 0 AmericaJetAurora 1 1000 4200
+30 spawn 0 AmericaJetStealthFighter 1 1000 4800
+31 move 0 AmericaJetRaptor 4400 3000
+31 move 0 ChinaJetMIG 4400 3600
+31 move 0 AmericaJetAurora 4400 4200
+31 move 0 AmericaJetStealthFighter 4400 4800
+150 move 0 AmericaJetRaptor 1000 3000
+150 move 0 ChinaJetMIG 1000 3600
+150 move 0 AmericaJetAurora 1000 4200
+150 move 0 AmericaJetStealthFighter 1000 4800
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 1c9419eaf..3dccf2265 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -194,6 +194,9 @@ public:
Real m_airPitch; ///< hover or wings pitch, roll and yaw from that frame, drawn until the next one
Real m_airRoll;
Real m_airYaw;
+ Real m_jetHeading; ///< a jet's heading on the retail frame wings last stepped on, for its turn rate
+ Real m_jetBank; ///< a jet's bank into its turn and its nose-up pitch, eased
+ Real m_jetPitch;
Real m_groundLeanStages[2][3]; ///< a ground vehicle's pitch and roll lean, smoothed through three stages once a retail frame
UnsignedInt m_groundFrame; ///< the retail frame (logic frame / LOGICFRAMES_PER_RETAIL_FRAME) those were last stepped on
Real m_prevForwardSpeed; ///< a ground vehicle's forward speed on that frame
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
index 43c5ff2cd..f797f5de1 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
@@ -250,8 +250,14 @@ public:
False if the path is empty or has a single node, in which case there is no direction. */
Bool closestPointAndDir( const Coord3D& pos, Coord3D *ptOut, Coord2D *dirOut ) const;
- /// Given a flight path, compute the distance to goal (0 if we are past it) & return the goal pos.
- Real computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos );
+ /** Given a flight path, compute the distance to goal (0 if we are past it) & return the goal pos.
+ A node counts as passed once pos is less than nodeReachedDist short of it along its leg. */
+ Real computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos, Real nodeReachedDist = 0.0f );
+ /** After computeFlightDistToGoal, the distance still to drive along the route, where that one sums
+ the reach to every node and so overstates it; and in bendDist and bendCos how far off the
+ node it steers for is and the cosine of the sharpest turn off the present heading in the few
+ cells after it, or 0 and 1 when that node is the last. */
+ Real computeFlightRouteLeft( const Coord3D *pos, Real *bendDist, Real *bendCos ) const;
/// Given a location, return closest location on path, and along-path dist to end as function result
void markOptimized(void) {m_isOptimized = true;}
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
index 9c243a74b..11c8b0db5 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
@@ -310,6 +310,26 @@ public:
Real calcMinTurnRadius(BodyDamageType condition, Real* timeToTravelThatDist) const;
+ /**
+ A live fixed-wing aircraft flown by JetAIUpdate on a WINGS locomotor: Raptor, MiG, Aurora,
+ Stealth Fighter and every general's copy. It banks into its turns: the turn rate falls off
+ above its corner speed, so a fast jet turns wide, and the velocity follows the nose. The B-52,
+ the Spectre and the other scripted aircraft keep EA's flight.
+ */
+ Bool isJet(const Object* obj) const;
+ /// the speed a jet turns tightest at, for the time a turn takes: half its top speed
+ Real getJetCornerSpeed(BodyDamageType condition) const;
+ /// a jet's turn rate at this speed, in radians a frame: TurnRate up to the corner speed, falling off as 1/speed above it
+ Real getJetMaxYawRate(BodyDamageType condition, Real speed) const;
+ /// the lateral acceleration a jet's wings pull at full rate above its corner speed
+ Real getJetPull(BodyDamageType condition) const;
+ /**
+ The circle a hard turn begun now would fly, for an aircraft on wings, and in entryDist how far
+ it goes straight before it is on that circle (a jet's roll into the bank). Other aircraft get
+ EA's estimate, a speed halfway down to MinSpeed at TurnRate, and no entry.
+ */
+ Real calcTurnCircle(const Object* obj, Real* entryDist) const;
+
/**
A live aircraft on a hovering air locomotor: Comanche, Chinook, Helix and every general's copy.
Its locomotor steers the whole 2D velocity, so it flies sideways and backwards and the nose
@@ -318,12 +338,15 @@ public:
Bool isHelicopter(const Object* obj) const;
/**
- A tank, car or bike driving under its own power: treads, four wheels or a motorcycle, on an
- object that is no aircraft taxiing, and not in an ULTRA_ACCURATE manoeuvre. Its speed eases
- up and down, it brakes into bends and stops it can see coming, treads back up to a goal
- close behind and wheels turn no tighter than their wheelbase allows.
+ A tank, car or bike driving under its own power: treads, four wheels or a motorcycle, not in
+ an ULTRA_ACCURATE manoeuvre; or a jet taxiing on four wheels, which is. A helicopter taxiing
+ on treads is not. Its speed eases up and down, it brakes into bends and stops it can see
+ coming, treads back up to a goal close behind and wheels turn no tighter than their wheelbase
+ allows.
*/
Bool isGroundVehicle(const Object* obj) const;
+ /// the tightest circle a ground vehicle on wheels drives at speed, from its length
+ Real calcWheelTurnRadius(const Object* obj) const;
/// this is handy for doing things like forcing helicopters to crash realistically: cut their lift.
inline void setMaxLift(Real lift) { m_maxLift = lift; }
@@ -408,6 +431,9 @@ protected:
Real getVehicleStopDecel(BodyDamageType condition) const;
void moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
void moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
+ void moveTowardsPositionJet(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
+ void flyJet(Object* obj, PhysicsBehavior *physics, Real headingError, Real goalSpeed);
+ Real getJetBraking(BodyDamageType condition) const;
void maintainCurrentPositionThrust(Object* obj, PhysicsBehavior *physics);
void maintainCurrentPositionOther(Object* obj, PhysicsBehavior *physics);
@@ -495,7 +521,7 @@ private:
Real m_angleOffset;
Real m_offsetIncrement;
UnsignedInt m_donutTimer; ///< Frame time to keep units from doing the donut. jba.
- Real m_yawRate; ///< radians a frame a helicopter's or ground vehicle's nose is swinging, eased up and down
+ Real m_yawRate; ///< radians a frame a helicopter's, jet's or ground vehicle's nose is swinging, eased up and down
Real m_driveAccelX; ///< the 2D acceleration a helicopter is pulling, eased towards what it wants;
Real m_driveAccelY; ///< a ground vehicle uses X alone, for its pull along the nose
Real m_driveSpeed; ///< the speed along the nose a ground vehicle's last drive left it at
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index ab9a3986d..55ad4314e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -227,6 +227,9 @@ DrawableLocoInfo::DrawableLocoInfo()
m_airPitch = 0.0f;
m_airRoll = 0.0f;
m_airYaw = 0.0f;
+ m_jetHeading = 0.0f;
+ m_jetBank = 0.0f;
+ m_jetPitch = 0.0f;
for (Int i = 0; i < 3; ++i)
m_groundLeanStages[0][i] = m_groundLeanStages[1][i] = 0.0f;
m_groundFrame = 0;
@@ -1828,8 +1831,89 @@ void Drawable::calcPhysicsXformHoverOrWings( const Locomotor *locomotor, Physics
info.m_totalZ = 0.0f;
return;
}
+ UnsignedInt elapsed = now - m_locoInfo->m_airFrame;
m_locoInfo->m_airFrame = now;
+ /* A jet banks into its turn and pitches with its climb. The bank is the lateral acceleration of
+ the turn, speed times turn rate, against the full pull of its wings (Locomotor::getJetPull):
+ JET_MAX_BANK at the full pull and level flying straight. The logic eases the turn in and out,
+ so the bank rolls with it, and through level when a turn reverses. The pitch is the climb
+ angle, clamped, plus a few degrees of nose-up while it flies slow, the attitude it comes in to
+ land with, fading out over the last few feet so the nose comes down after the wheels touch.
+ Both are eased again here against single-frame jumps. The springs below are left holding
+ the same attitude, so a jet that dies falls from where it was. */
+ if (locomotor->isJet(obj))
+ {
+ const Real JET_MAX_BANK = 1.1f; // radians, about 63 degrees, at the full pull of the wings
+ const Real JET_MAX_CLIMB = 0.35f; // radians, about 20 degrees, nose up or down
+ const Real JET_SLOW_NOSE_UP = 0.12f; // radians, about 7 degrees, at MinSpeed and below, none from twice that
+ const Real JET_NOSE_UP_HEIGHT = 5.0f; // the nose-up fades out below this height
+ const Real JET_EASE_FRAMES = 3.0f; // retail frames
+ const UnsignedInt MAX_GAP = 4; // retail frames; after a longer gap (taxiing, hidden) the turn rate is not known
+
+ BodyDamageType bdt = obj->getBodyModule()->getDamageState();
+ Real speed = sqrt(sqr(vel->x) + sqr(vel->y)); // per logic frame
+ Real heading = obj->getOrientation();
+ Real bank = 0.0f;
+ Real pull = locomotor->getJetPull(bdt);
+ if (elapsed <= MAX_GAP && pull > 0.0f)
+ {
+ Real turnRate = stdAngleDiff(heading, m_locoInfo->m_jetHeading) / (Real)(elapsed * LOGICFRAMES_PER_RETAIL_FRAME);
+ bank = JET_MAX_BANK * speed * turnRate / pull;
+ if (bank > JET_MAX_BANK)
+ bank = JET_MAX_BANK;
+ else if (bank < -JET_MAX_BANK)
+ bank = -JET_MAX_BANK;
+ }
+ m_locoInfo->m_jetHeading = heading;
+
+ Real pitch = 0.0f; // nose up
+ if (speed > 0.01f || fabs(vel->z) > 0.01f)
+ pitch = atan2(vel->z, speed);
+ if (pitch > JET_MAX_CLIMB)
+ pitch = JET_MAX_CLIMB;
+ else if (pitch < -JET_MAX_CLIMB)
+ pitch = -JET_MAX_CLIMB;
+ Real height = obj->getHeightAboveTerrain();
+ if (obj->getStatusBits().test( OBJECT_STATUS_DECK_HEIGHT_OFFSET ))
+ height -= obj->getCarrierDeckHeight();
+ Real minSpeed = locomotor->getMinSpeed();
+ if (height > 0.0f && minSpeed > 0.0f)
+ {
+ Real slow = (2.0f * minSpeed - speed) / minSpeed;
+ if (slow > 1.0f)
+ slow = 1.0f;
+ if (slow > 0.0f)
+ {
+ Real fade = height / JET_NOSE_UP_HEIGHT;
+ if (fade > 1.0f)
+ fade = 1.0f;
+ pitch += JET_SLOW_NOSE_UP * slow * fade;
+ }
+ }
+
+ m_locoInfo->m_jetBank += (bank - m_locoInfo->m_jetBank) / JET_EASE_FRAMES;
+ m_locoInfo->m_jetPitch += (pitch - m_locoInfo->m_jetPitch) / JET_EASE_FRAMES;
+
+ info.m_totalRoll = m_locoInfo->m_jetBank; // positive rolls the left wing down, into a turn to the left
+ info.m_totalPitch = -m_locoInfo->m_jetPitch; // negative lifts the nose
+ info.m_totalYaw = 0.0f;
+ info.m_totalZ = 0.0f;
+
+ m_locoInfo->m_pitch = info.m_totalPitch;
+ m_locoInfo->m_roll = info.m_totalRoll;
+ m_locoInfo->m_pitchRate = 0.0f;
+ m_locoInfo->m_rollRate = 0.0f;
+ m_locoInfo->m_accelerationPitch = 0.0f;
+ m_locoInfo->m_accelerationPitchRate = 0.0f;
+ m_locoInfo->m_accelerationRoll = 0.0f;
+ m_locoInfo->m_accelerationRollRate = 0.0f;
+ m_locoInfo->m_airPitch = info.m_totalPitch;
+ m_locoInfo->m_airRoll = info.m_totalRoll;
+ m_locoInfo->m_airYaw = info.m_totalYaw;
+ return;
+ }
+
m_locoInfo->m_pitchRate += ((-PITCH_STIFFNESS * m_locoInfo->m_pitch) + (-PITCH_DAMPING * m_locoInfo->m_pitchRate)); // spring/damper
m_locoInfo->m_rollRate += ((-ROLL_STIFFNESS * m_locoInfo->m_roll) + (-ROLL_DAMPING * m_locoInfo->m_rollRate)); // spring/damper
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index 661990f0f..0c6b25897 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@ -1458,7 +1458,7 @@ void Path::computePointOnPath(
Returns the goal position in goalPos. This is intended for use with flying paths, that go
directly to the goal and don't consider obstacles. jba.
*/
-Real Path::computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos )
+Real Path::computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos, Real nodeReachedDist )
{
if (m_path == NULL)
{
@@ -1501,7 +1501,7 @@ Real Path::computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos )
// Dot product is the posToGoal vector projected onto the path vector.
Real dotProduct = posToGoalVector.x*pathVector.x + posToGoalVector.y*pathVector.y;
- if (dotProduct>=0) {
+ if (dotProduct>=nodeReachedDist) {
distance += dotProduct;
useNext = false;
} else if (useNext) {
@@ -1513,6 +1513,46 @@ Real Path::computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos )
return distance;
}
+
+//-----------------------------------------------------------------------------------
+Real Path::computeFlightRouteLeft( const Coord3D *pos, Real *bendDist, Real *bendCos ) const
+{
+ *bendDist = 0.0f;
+ *bendCos = 1.0f;
+ const PathNode *curNode = m_cpopRecentStart ? m_cpopRecentStart : m_path;
+ if (curNode == NULL)
+ return 0.0f;
+ Coord2D dir;
+ Real length;
+ const PathNode *nextNode = curNode->getNextOptimized(&dir, &length);
+ if (nextNode == NULL)
+ return 0.0f;
+
+ Real left = (nextNode->getPosition()->x - pos->x) * dir.x + (nextNode->getPosition()->y - pos->y) * dir.y;
+ if (left < 0.0f)
+ left = 0.0f;
+ Real toNext = left;
+
+ /* A corner rounded into an arc is many small bends; the one braked for is the whole turn off this
+ segment's heading within BEND_LOOK past the node steered for, so the speed comes down before the
+ arc and stays down round it. */
+ const Real BEND_LOOK = 4.0f * PATHFIND_CELL_SIZE_F;
+ Coord2D outDir;
+ for (const PathNode *node = nextNode->getNextOptimized(&outDir, &length); node; node = node->getNextOptimized(&outDir, &length))
+ {
+ if (left - toNext < BEND_LOOK)
+ {
+ Real turnCos = dir.x * outDir.x + dir.y * outDir.y;
+ if (turnCos < *bendCos)
+ {
+ *bendCos = turnCos;
+ *bendDist = toNext;
+ }
+ }
+ left += length;
+ }
+ return left;
+}
//-----------------------------------------------------------------------------------
/* How many cells the queued searches may look at in one logic frame. EA's 5000 is about 3.5ms of
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 9d37c1d14..0544f7b5d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -5630,20 +5630,20 @@ Coord3D AIAttackAimAtTargetState::computeAttackRunGoal( Object *source, const We
const Real dx = targetPos.x - pos->x;
const Real dy = targetPos.y - pos->y;
- // a hard turn bleeds speed toward the locomotor's minimum, so the circle tightens as it goes
- const Real speed = 0.5f*(max(source->getPhysics()->getForwardSpeed2D(), loco->getMinSpeed()) + loco->getMinSpeed());
- const Real turnRadius = speed / loco->getMaxTurnRate(source->getBodyModule()->getDamageState());
+ // the circle the turn would fly, and the straight run before it while a jet rolls into the bank
+ Real entryDist = 0.0f;
+ const Real turnRadius = loco->calcTurnCircle(source, &entryDist);
// range is measured between the bounding spheres, so the minimum range seen from the centres is longer
Real minRange = weapon->getTemplate()->getMinimumAttackRange() + source->getGeometryInfo().getBoundingSphereRadius();
if (victim)
minRange += victim->getGeometryInfo().getBoundingSphereRadius();
- const Real runOutDist = minRange + 2.0f*turnRadius;
+ const Real runOutDist = minRange + 2.0f*turnRadius + entryDist;
if (m_isRunningOut)
m_isRunningOut = dx*dx + dy*dy < sqr(runOutDist);
else if (fabs(relAngle) >= aimDelta)
- m_isRunningOut = AIAttackAim_needsRunOut(dx*dir->x + dy*dir->y, dir->x*dy - dir->y*dx, turnRadius,
+ m_isRunningOut = AIAttackAim_needsRunOut(dx*dir->x + dy*dir->y - entryDist, dir->x*dy - dir->y*dx, turnRadius,
Cos(aimDelta), minRange);
if (!m_isRunningOut)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index 609abac68..18e915bb4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -80,6 +80,7 @@ static const Real TREAD_PIVOT_SHARE = 0.5f; // share of TurnRate a tank piv
static const Real TREAD_PIVOT_COS = -0.17f; // cos 100 degrees: further round than this a tank stops and pivots
static const Real VEHICLE_CORNER_GRIP = 0.5f; // share of its braking a car can pull sideways on its tightest arc
static const Real WHEEL_MIN_RADIUS_BODY_LENGTHS = 1.5f; // a car turns no tighter than this, unless that arc cannot reach the goal
+static const Real JET_TAXI_MIN_RADIUS_BODY_LENGTHS = 0.75f; // a taxiing jet steers its nose wheel this tight: an airfield's taxiway corners are a jet's length apart
static const Real WHEEL_TIGHT_RADIUS_BODY_LENGTHS = 0.3f; // and then crawls round this, at its turn speed
// Infantry on two legs (moveTowardsPositionLegs, maintainCurrentPositionLegs).
@@ -1075,9 +1076,12 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle)
if (minSpeed > 0)
{
// can't stay in one place; move in the desired direction at min speed.
+ // a jet is sent far down that bearing: a point this close beside it is inside its turn and it
+ // would fly straight on (moveTowardsPositionJet)
+ Real probe = isJet(obj) ? 1000.0f : minSpeed * 2;
Coord3D desiredPos = *obj->getPosition();
- desiredPos.x += Cos(goalAngle) * minSpeed * 2;
- desiredPos.y += Sin(goalAngle) * minSpeed * 2;
+ desiredPos.x += Cos(goalAngle) * probe;
+ desiredPos.y += Sin(goalAngle) * probe;
// pass a huge num for "dist to goal", so that we don't think we're nearing
// our destination and thus slow down...
const Real onPathDistToGoal = 99999.0f;
@@ -1093,7 +1097,10 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle)
Coord3D desiredPos = *obj->getPosition();
desiredPos.x += Cos(goalAngle) * 1000.0f;
desiredPos.y += Sin(goalAngle) * 1000.0f;
- PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos);
+ // a jet on its wheels swings round its parking spot or onto the runway with the turn eased in
+ // and out, as a helicopter's nose does, where rotateTowardsPosition starts and stops dead
+ Bool taxiingJet = obj->isKindOf(KINDOF_AIRCRAFT) && isGroundVehicle(obj);
+ PhysicsTurningType rotating = taxiingJet ? turnHelicopter(obj, &desiredPos, 1.0f) : rotateTowardsPosition(obj, desiredPos);
physics->setTurning(rotating);
// a helicopter turning in place has no sideways friction to stop a slide it came in with
if (isHelicopter(obj))
@@ -1136,8 +1143,10 @@ void Locomotor::setPhysicsOptions(Object* obj)
physics->setAllowAirborneFriction(getApply2DFrictionWhenAirborne()); // you'd think we wouldn't want friction in the air, but it's needed for realistic behavior.
physics->setStickToGround(getStickToGround()); // walking guys aren't allowed to catch huge (or even small) air.
Bool helicopter = isHelicopter(obj);
- physics->setMotiveSteersSideways(helicopter);
- if (!helicopter && !isGroundVehicle(obj) && m_template->m_appearance != LOCO_LEGS_TWO)
+ Bool jet = isJet(obj);
+ // a jet's locomotor carries its velocity round with the nose itself, so there is no slip for friction to take
+ physics->setMotiveSteersSideways(helicopter || jet);
+ if (!helicopter && !jet && !isGroundVehicle(obj) && m_template->m_appearance != LOCO_LEGS_TWO)
{
// landed, taxiing or dying: whatever it was pulling or swinging when it last flew or drove is over
m_yawRate = 0.0f;
@@ -1155,13 +1164,32 @@ Bool Locomotor::isHelicopter(const Object* obj) const
&& !obj->isEffectivelyDead(); // a dying one spirals on HelicopterSlowDeathBehavior's forces and the old friction
}
+//-------------------------------------------------------------------------------------------------
+Bool Locomotor::isJet(const Object* obj) const
+{
+ if (m_template->m_appearance != LOCO_WINGS || !obj->isKindOf(KINDOF_AIRCRAFT) || obj->isEffectivelyDead())
+ return FALSE; // a dying one falls on JetSlowDeathBehavior's forces and the old friction
+ const AIUpdateInterface *ai = obj->getAI();
+ return ai != NULL && ai->getJetAIUpdate() != NULL;
+}
+
//-------------------------------------------------------------------------------------------------
Bool Locomotor::isGroundVehicle(const Object* obj) const
{
LocomotorAppearance appearance = m_template->m_appearance;
+ // a jet taxis on its nose wheel (BasicJetTaxiLocomotor in BalanceReforged.ini), with the precision
+ // its taxi asks for; a landed helicopter keeps EA's drive
+ if (obj->isKindOf(KINDOF_AIRCRAFT))
+ return appearance == LOCO_WHEELS_FOUR;
return (appearance == LOCO_TREADS || appearance == LOCO_WHEELS_FOUR || appearance == LOCO_MOTORCYCLE)
- && !obj->isKindOf(KINDOF_AIRCRAFT) // a jet or a landed helicopter taxiing keeps EA's drive
- && !getFlag(ULTRA_ACCURATE); // and so does a dozer or a POW truck lining up on its spot
+ && !getFlag(ULTRA_ACCURATE); // a dozer or a POW truck lining up on its spot keeps EA's drive
+}
+
+//-------------------------------------------------------------------------------------------------
+Real Locomotor::calcWheelTurnRadius(const Object* obj) const
+{
+ Real bodyLength = 2.0f * obj->getGeometryInfo().getMajorRadius();
+ return (obj->isKindOf(KINDOF_AIRCRAFT) ? JET_TAXI_MIN_RADIUS_BODY_LENGTHS : WHEEL_MIN_RADIUS_BODY_LENGTHS) * bodyLength;
}
//-------------------------------------------------------------------------------------------------
@@ -1942,7 +1970,7 @@ void Locomotor::moveTowardsPositionVehicle(Object* obj, PhysicsBehavior *physics
Real arcRadius = BIGNUM;
if (fabs(leadSin) > 0.01f)
arcRadius = dist / (2.0f * fabs(leadSin));
- Real minRadius = WHEEL_MIN_RADIUS_BODY_LENGTHS * bodyLength;
+ Real minRadius = calcWheelTurnRadius(obj);
Bool tight = FALSE;
if (!treads && !backing)
@@ -2184,6 +2212,90 @@ Real Locomotor::calcMinTurnRadius(BodyDamageType condition, Real* timeToTravelTh
return minTurnRadius;
}
+//-------------------------------------------------------------------------------------------------
+/*
+ A jet banks into a turn instead of swinging its nose round a point. Its wings pull no harder than
+ they do with the full TurnRate at JET_CORNER_SHARE of its top speed, so above that speed the turn
+ rate falls off as 1/speed and the circle grows with the square of the speed: at top speed it is
+ twice EA's radius, at the corner speed and below it is EA's. The rate winds up and down over
+ JET_BANK_EASE_FRAMES, which is the roll into and out of the bank, so a reversal rolls through
+ level. A turn bleeds speed, up to JET_TURN_SPEED_LOSS of it at the full rate, which tightens a long
+ turn as it goes; the throttle brings it back after. The velocity follows the nose, with no slip.
+
+ Measured with Scenarios/jetturn.txt (a 180 degree reversal at cruise), width of the U before and
+ after: see that file.
+*/
+static const Real JET_CORNER_SHARE = 0.5f;
+static const Real JET_BANK_EASE_FRAMES = LOGICFRAMES_PER_SECOND * 0.5f; // from wings level to the full bank
+static const Real JET_TURN_SPEED_LOSS = 0.2f;
+static const Real JET_AIRBRAKE_SHARE = 0.25f; // a jet slows at this share of its Acceleration, or at Braking if that is more
+static const Real JET_ORBIT_CORRECTION = PI / 3.0f; // circling, a radius off the circle heads this far in from the tangent
+
+//-------------------------------------------------------------------------------------------------
+Real Locomotor::getJetCornerSpeed(BodyDamageType condition) const
+{
+ Bool healthy = IS_CONDITION_BETTER( condition, TheGlobalData->m_movementPenaltyDamageState );
+ return JET_CORNER_SHARE * (healthy ? m_template->m_maxSpeed : m_template->m_maxSpeedDamaged);
+}
+
+//-------------------------------------------------------------------------------------------------
+Real Locomotor::getJetMaxYawRate(BodyDamageType condition, Real speed) const
+{
+ // not getMaxTurnRate: its ULTRA_ACCURATE doubling would whip a jet round its landing pattern
+ Bool healthy = IS_CONDITION_BETTER( condition, TheGlobalData->m_movementPenaltyDamageState );
+ Real turnRate = healthy ? m_template->m_maxTurnRate : m_template->m_maxTurnRateDamaged;
+ if (turnRate > m_maxTurnRate)
+ turnRate = m_maxTurnRate;
+ Real cornerSpeed = getJetCornerSpeed(condition);
+ if (speed > cornerSpeed)
+ turnRate *= cornerSpeed / speed;
+ return turnRate;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real Locomotor::getJetPull(BodyDamageType condition) const
+{
+ Real cornerSpeed = getJetCornerSpeed(condition);
+ return getJetMaxYawRate(condition, cornerSpeed) * cornerSpeed;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real Locomotor::getJetBraking(BodyDamageType condition) const
+{
+ Real braking = getMaxAcceleration(condition) * JET_AIRBRAKE_SHARE;
+ if (braking < getBraking())
+ braking = getBraking();
+ return braking;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real Locomotor::calcTurnCircle(const Object* obj, Real* entryDist) const
+{
+ BodyDamageType bdt = obj->getBodyModule()->getDamageState();
+ Real minSpeed = getMinSpeed();
+ Real speed = obj->getPhysics()->getForwardSpeed2D();
+ if (speed < minSpeed)
+ speed = minSpeed;
+
+ if (!isJet(obj))
+ {
+ // a hard turn bleeds speed toward the locomotor's minimum, so the circle tightens as it goes
+ if (entryDist)
+ *entryDist = 0.0f;
+ Real turnRate = getMaxTurnRate(bdt);
+ return (turnRate > 0.0f) ? 0.5f * (speed + minSpeed) / turnRate : BIGNUM;
+ }
+
+ // the turn bleeds up to JET_TURN_SPEED_LOSS of the speed: take the circle at half of that
+ if (entryDist)
+ *entryDist = speed * JET_BANK_EASE_FRAMES * 0.5f;
+ Real turnSpeed = speed * (1.0f - 0.5f * JET_TURN_SPEED_LOSS);
+ if (turnSpeed < minSpeed)
+ turnSpeed = minSpeed;
+ Real turnRate = getJetMaxYawRate(bdt, turnSpeed);
+ return (turnRate > 0.0f) ? turnSpeed / turnRate : BIGNUM;
+}
+
//-------------------------------------------------------------------------------------------------
void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed)
@@ -2421,6 +2533,12 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics,
//-------------------------------------------------------------------------------------------------
void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed)
{
+ if (isJet(obj))
+ {
+ moveTowardsPositionJet(obj, physics, goalPos, onPathDistToGoal, desiredSpeed);
+ return;
+ }
+
#ifdef CIRCLE_FOR_LANDING
if (m_circleThresh > 0.0f)
{
@@ -2460,6 +2578,117 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics,
moveTowardsPositionOther(obj, physics, goalPos, onPathDistToGoal, desiredSpeed);
}
+//-------------------------------------------------------------------------------------------------
+/*
+ Turn towards the goal and keep the speed asked for, the way moveTowardsPositionOther does, but on a
+ jet's terms (flyJet). A goal inside the circle the jet would turn on cannot be reached by turning
+ towards it, and chasing it is the orbit round a point a jet used to fly; the jet holds its wings
+ level instead until the goal is outside the circle, and then comes round onto it.
+*/
+void Locomotor::moveTowardsPositionJet(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed)
+{
+ BodyDamageType bdt = obj->getBodyModule()->getDamageState();
+ Real maxSpeed = getMaxSpeedForCondition(bdt);
+ if (desiredSpeed > maxSpeed)
+ desiredSpeed = maxSpeed;
+
+ const Coord3D *pos = obj->getPosition();
+ Real dx = goalPos.x - pos->x;
+ Real dy = goalPos.y - pos->y;
+ Real error = 0.0f;
+ if (fabs(dx) > 0.1f || fabs(dy) > 0.1f)
+ error = stdAngleDiff(ATan2(dy, dx), obj->getOrientation());
+
+ const Coord3D *vel = physics->getVelocity();
+ Real speed = sqrt(sqr(vel->x) + sqr(vel->y));
+ Real maxRate = getJetMaxYawRate(bdt, speed);
+ if (error != 0.0f && maxRate > 0.0f)
+ {
+ Real radius = speed / maxRate;
+ Real side = (error > 0.0f) ? 1.0f : -1.0f;
+ const Coord3D *dir = obj->getUnitDirectionVector2D();
+ Real centreX = pos->x - dir->y * radius * side;
+ Real centreY = pos->y + dir->x * radius * side;
+ if (sqr(goalPos.x - centreX) + sqr(goalPos.y - centreY) < sqr(radius))
+ error = 0.0f;
+ }
+
+ Real goalSpeed = desiredSpeed;
+ if (!getFlag(NO_SLOW_DOWN_AS_APPROACHING_DEST))
+ {
+ Real slowDownDist = calcSlowDownDist(speed, m_template->m_minSpeed, getJetBraking(bdt));
+ if (onPathDistToGoal < slowDownDist && goalSpeed > m_template->m_minSpeed)
+ goalSpeed = m_template->m_minSpeed;
+ }
+
+ flyJet(obj, physics, error, goalSpeed);
+}
+
+//-------------------------------------------------------------------------------------------------
+/**
+ Fly a jet for one frame: turn its nose towards a heading headingError radians away, the turn
+ eased in and out and no faster than its speed allows (getJetMaxYawRate), and carry its whole 2D
+ velocity round with the nose at a speed eased towards goalSpeed. Acceleration takes it up,
+ getJetBraking or the pull of the turn takes it down.
+*/
+void Locomotor::flyJet(Object* obj, PhysicsBehavior *physics, Real headingError, Real goalSpeed)
+{
+ BodyDamageType bdt = obj->getBodyModule()->getDamageState();
+ const Coord3D *vel = physics->getVelocity();
+ Real speed = sqrt(sqr(vel->x) + sqr(vel->y));
+ Real maxRate = getJetMaxYawRate(bdt, speed);
+
+ Real rate = easeYaw(headingError, maxRate, maxRate / JET_BANK_EASE_FRAMES);
+ if (rate != 0.0f)
+ {
+ obj->setOrientation(normalizeAngle(obj->getOrientation() + rate));
+ physics->setTurning(rate > 0.0f ? TURN_POSITIVE : TURN_NEGATIVE);
+ }
+ else
+ {
+ physics->setTurning(TURN_NONE);
+ }
+
+ Real minSpeed = m_template->m_minSpeed;
+ Real decel = getJetBraking(bdt);
+ if (rate != 0.0f && maxRate > 0.0f)
+ {
+ Real share = fabs(rate) / maxRate;
+ if (share > 1.0f)
+ share = 1.0f;
+ Real turnSpeed = goalSpeed * (1.0f - JET_TURN_SPEED_LOSS * share);
+ if (turnSpeed < minSpeed)
+ turnSpeed = minSpeed;
+ if (turnSpeed < goalSpeed)
+ goalSpeed = turnSpeed;
+ Real pull = speed * fabs(rate);
+ if (decel < pull)
+ decel = pull;
+ }
+
+ Real newSpeed = speed;
+ if (goalSpeed > speed)
+ {
+ newSpeed += getMaxAcceleration(bdt);
+ if (newSpeed > goalSpeed)
+ newSpeed = goalSpeed;
+ }
+ else
+ {
+ newSpeed -= decel;
+ if (newSpeed < goalSpeed)
+ newSpeed = goalSpeed;
+ }
+
+ const Coord3D *dir = obj->getUnitDirectionVector2D();
+ Real mass = physics->getMass();
+ Coord3D force;
+ force.x = mass * (dir->x * newSpeed - vel->x);
+ force.y = mass * (dir->y * newSpeed - vel->y);
+ force.z = 0.0f;
+ physics->applyMotiveForce(&force);
+}
+
//-------------------------------------------------------------------------------------------------
void Locomotor::moveTowardsPositionHover(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed, const Coord3D *faceTarget, Bool fighting)
{
@@ -3416,7 +3645,35 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi
{
DEBUG_ASSERTCRASH(getFlag(MAINTAIN_POS_IS_VALID), ("invalid maintain pos"));
physics->setTurning(TURN_NONE);
- if (physics->isMotive() && obj->isAboveTerrain()) // no need to stop something that isn't moving (or is just sitting on the ground)
+ if (physics->isMotive() && obj->isAboveTerrain() && isJet(obj))
+ {
+ /* A jet flies a true circle round the spot at CirclingRadius, steering for the tangent and
+ a share of JET_ORBIT_CORRECTION in towards the circle or out from it, so it banks once and
+ holds the bank; chasing a point across the circle swung it in and out of the turn. */
+ Real radius = m_template->m_circlingRadius;
+ if (radius == 0.0f)
+ radius = calcMinTurnRadius(obj->getBodyModule()->getDamageState(), NULL);
+ Real side = (radius > 0.0f) ? -1.0f : 1.0f; // a positive radius circles clockwise
+ radius = fabs(radius);
+
+ const Coord3D* pos = obj->getPosition();
+ Real dx = pos->x - m_maintainPos.x;
+ Real dy = pos->y - m_maintainPos.y;
+ Real dist = sqrt(dx*dx + dy*dy);
+ Real error = 0.0f;
+ if (dist > 1.0f && radius > 0.0f)
+ {
+ Real off = (dist - radius) / radius;
+ if (off > 1.0f)
+ off = 1.0f;
+ else if (off < -1.0f)
+ off = -1.0f;
+ Real heading = ATan2(dy, dx) + side * (PI / 2.0f + JET_ORBIT_CORRECTION * off);
+ error = stdAngleDiff(heading, obj->getOrientation());
+ }
+ flyJet(obj, physics, error, m_template->m_minSpeed);
+ }
+ else if (physics->isMotive() && obj->isAboveTerrain()) // no need to stop something that isn't moving (or is just sitting on the ground)
{
// aim for the spot on the opposite side of the circle.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 6df395b77..252a45b16 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -3952,6 +3952,8 @@ Bool AIUpdateInterface::isValidLocomotorPosition(const Coord3D* pos) const
return TheAI->pathfinder()->validMovementPosition( getObject()->getCrusherLevel()>0, getObject()->getLayer(), m_locomotorSet, pos );
}
+static const Real JET_TAXI_NODE_REACHED_DIST = 0.01f; ///< a taxiing jet this close short of a route node has passed it
+
//-------------------------------------------------------------------------------------------------
DECLARE_PERF_TIMER(doLocomotor)
/**
@@ -4138,7 +4140,14 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
if (!isDoingGroundMovement())
{
// airborne locomotor. Get the goal and distance direct to the goal, don't consider obstacles.
- onPathDistToGoal = getPath()->computeFlightDistToGoal(getObject()->getPosition(), goalPos);
+ // A jet taxiing on its wheels passes a node it stands on, since its last-cell slide
+ // (Locomotor::moveTowardsPositionVehicle) puts it exactly there and it would sit there for
+ // good, and it plans its stop and its corners from what is left of the route. A tank
+ // falling off a bridge or out of a plane keeps EA's flight path.
+ Bool taxiingJet = getObject()->isKindOf(KINDOF_AIRCRAFT) && m_curLocomotor->isGroundVehicle(getObject());
+ onPathDistToGoal = getPath()->computeFlightDistToGoal(getObject()->getPosition(), goalPos, taxiingJet ? JET_TAXI_NODE_REACHED_DIST : 0.0f);
+ if (taxiingJet)
+ onPathDistToGoal = getPath()->computeFlightRouteLeft(getObject()->getPosition(), &bendDist, &bendCos);
}
else
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
index 05956460b..e2445f2d2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
@@ -50,6 +50,119 @@
const Real BIGNUM = 99999.0f;
+/*
+ A runway is flown, not followed point to point. Taking off, the jet rolls down the centre line at
+ full throttle, the wheels leave at JET_LIFTOFF_SHARE of the runway and the climb builds up over
+ JET_ROTATE_SHARE more of it to a steady JET_CLIMB_SLOPE; the takeoff is done at the airfield's
+ approach height. Landing, it steers for a point on the extended centre line ahead of it, down a
+ JET_GLIDE_SLOPE glide that rounds out over JET_FLARE_DIST to a level touchdown on the runway's
+ threshold, and rolls out slowing to JET_ROLLOUT_END_SHARE of MinSpeed at its far end. A jet that
+ cannot line up from where it is (beside the runway, past it, across it, or too high) flies a
+ circuit first, at its corner speed: out along the side of the runway two turn radii off the centre
+ line, round onto a JET_FINAL_DIST final, and in, slowing to MinSpeed over the threshold. Its
+ height follows the same glide measured along the circuit, so it comes down through the turns, and
+ a jet above the glide comes down to it no steeper than JET_STEEPEST_DESCENT.
+*/
+static const Real JET_LIFTOFF_SHARE = 0.55f;
+static const Real JET_ROTATE_SHARE = 0.25f;
+static const Real JET_CLIMB_SLOPE = 0.21f; // tan 12 degrees
+static const Real JET_GLIDE_SLOPE = 0.176f; // tan 10 degrees
+static const Real JET_FLARE_DIST = 50.0f;
+static const Real JET_ROLLOUT_END_SHARE = 0.2f;
+static const Real JET_MIN_LOOKAHEAD = 60.0f; // the steering point runs at least this far ahead on the centre line
+static const Real JET_GO_AROUND_HEIGHT = 10.0f; // past the threshold higher than this, it goes round
+static const Real JET_LINE_UP_SLACK = 8.0f; // this far off the centre line it lands anyway
+static const Real JET_LINE_UP_ROOM = 3.0f; // otherwise it needs this many times its distance off it to line up in
+static const Real JET_HIGH_ON_FINAL = 20.0f; // more than this above the glide, it flies the circuit instead of diving
+static const Real JET_STEEPEST_DESCENT = 0.27f; // tan 15 degrees: a jet above its glide comes down to it no steeper
+static const Real JET_FINAL_DIST = 150.0f; // the straight final after the circuit's turn in
+// the jet's height servo settles this many frames of travel short of a height target moving away
+// under it, so a target this far ahead holds the jet on a slope (measured: 10 u/s down at 60 u/s)
+static const Real JET_HEIGHT_LAG_FRAMES = LOGICFRAMES_PER_SECOND * 0.1f;
+
+/**
+ Height above the runway, dist before the point where it meets it, of a straight slope that rounds
+ out over roundDist into the level, capped at maxHeight: the glide down to a touchdown, or read the
+ other way, the climb from a liftoff. No Object involved, so test_gameengine can link to it.
+*/
+Real JetRunway_slopeHeight( Real dist, Real maxHeight, Real slope, Real roundDist )
+{
+ if (dist <= 0.0f)
+ return 0.0f;
+ Real height = (dist < roundDist) ? slope * dist * dist / (2.0f * roundDist) : slope * (dist - 0.5f * roundDist);
+ return (height < maxHeight) ? height : maxHeight;
+}
+
+static const Real JET_TAXI_ARC_STEP = PI / 8.0f; // a rounded taxi corner gets a route point every this much of its turn
+static const Real JET_TAXI_LEG_SHARE = 0.45f; // and takes no more than this share of either leg beside it
+static const Real JET_TAXI_HAIRPIN = 0.01f; // one plus the cosine of a turn this near to straight back is left a corner
+
+/**
+ Round every corner of a taxi route (the first point where the jet stands) into an arc of radius,
+ or of as much of one as fits in JET_TAXI_LEG_SHARE of the shorter leg beside it, laid down as
+ route points JET_TAXI_ARC_STEP apart round the turn. A jet follows its route point to point, so
+ it turns along the arc instead of reaching the corner and swinging round it. The ends stay put,
+ and so does a corner that turns straight back. No Object involved, so test_gameengine can link
+ to it.
+*/
+void JetTaxi_roundCorners( std::vector<Coord3D>& route, Real radius )
+{
+ if (route.size() < 3)
+ return;
+
+ std::vector<Coord3D> rounded;
+ rounded.push_back(route.front());
+ for (size_t i = 1; i + 1 < route.size(); ++i)
+ {
+ const Coord3D& from = route[i - 1];
+ const Coord3D& corner = route[i];
+ const Coord3D& to = route[i + 1];
+ Real inX = corner.x - from.x;
+ Real inY = corner.y - from.y;
+ Real outX = to.x - corner.x;
+ Real outY = to.y - corner.y;
+ Real inLength = sqrt(inX*inX + inY*inY);
+ Real outLength = sqrt(outX*outX + outY*outY);
+ Real cross = (inX*outY - inY*outX) / (inLength * outLength); // positive turning left
+ Real dot = (inX*outX + inY*outY) / (inLength * outLength);
+ Real turn = ATan2(fabs(cross), dot);
+ if (turn < 0.5f * JET_TAXI_ARC_STEP || 1.0f + dot < JET_TAXI_HAIRPIN)
+ {
+ rounded.push_back(corner);
+ continue;
+ }
+ inX /= inLength;
+ inY /= inLength;
+
+ Real halfTurnTan = fabs(cross) / (1.0f + dot);
+ Real shorterLeg = (inLength < outLength) ? inLength : outLength;
+ Real tangent = radius * halfTurnTan;
+ if (tangent > JET_TAXI_LEG_SHARE * shorterLeg)
+ tangent = JET_TAXI_LEG_SHARE * shorterLeg;
+ Real arcRadius = tangent / halfTurnTan;
+ Real side = (cross > 0.0f) ? 1.0f : -1.0f;
+
+ // the arc leaves the leg in where it is tangent to it, round a centre a radius to the side
+ Real startX = corner.x - inX * tangent;
+ Real startY = corner.y - inY * tangent;
+ Real centreX = startX - inY * arcRadius * side;
+ Real centreY = startY + inX * arcRadius * side;
+ Real startAngle = ATan2(startY - centreY, startX - centreX);
+ Int steps = (Int)ceil(turn / JET_TAXI_ARC_STEP);
+ for (Int step = 0; step <= steps; ++step)
+ {
+ Real angle = startAngle + side * turn * step / steps;
+ Coord3D point;
+ point.x = centreX + arcRadius * Cos(angle);
+ point.y = centreY + arcRadius * Sin(angle);
+ point.z = corner.z;
+ rounded.push_back(point);
+ }
+ }
+ rounded.push_back(route.back());
+ route.swap(rounded);
+}
+
#ifdef _INTERNAL
// for occasional debugging...
//#pragma optimize("", off)
@@ -632,7 +745,23 @@ public:
}
}
- m_waitingForPath = FALSE;
+ // a jet on its wheels turns along each corner instead of reaching it and swinging round
+ Locomotor* taxiLoco = jetAI->getCurLocomotor();
+ if (taxiLoco->isGroundVehicle(jet))
+ {
+ std::vector<Coord3D> route;
+ for (const PathNode* node = movePath->getFirstNode(); node; node = node->getNext())
+ route.push_back(*node->getPosition());
+ JetTaxi_roundCorners(route, taxiLoco->calcWheelTurnRadius(jet));
+ movePath->deleteInstance();
+ movePath = newInstance(Path);
+ movePath->prependNode( &route[0], LAYER_GROUND );
+ movePath->markOptimized();
+ for (size_t i = 1; i < route.size(); ++i)
+ movePath->appendNode( &route[i], LAYER_GROUND );
+ }
+
+ m_waitingForPath = FALSE;
TheAI->pathfinder()->setDebugPath(movePath);
setAdjustsDestination(false); // precision is necessary
@@ -709,7 +838,6 @@ class JetTakeoffOrLandingState : public AIFollowPathState
{
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(JetTakeoffOrLandingState, "JetTakeoffOrLandingState")
private:
- Real m_maxLift;
Real m_maxSpeed;
#ifdef CIRCLE_FOR_LANDING
Coord3D m_circleForLandingPos;
@@ -738,7 +866,6 @@ public:
DEBUG_ASSERTCRASH(loco, ("no loco"));
loco->setMaxLift(BIGNUM);
BodyDamageType bdt = jet->getBodyModule()->getDamageState();
- m_maxLift = loco->getMaxLift(bdt);
m_maxSpeed = loco->getMaxSpeedForCondition(bdt);
m_landingSoundPlayed = FALSE;
if (m_landing)
@@ -747,7 +874,8 @@ public:
}
else
{
- loco->setMaxLift(0);
+ // full throttle down the runway; the height it is sent to keeps it on the wheels until liftoff
+ loco->setNoSlowDownAsApproachingDest(true);
}
loco->setUsePreciseZPos(true);
loco->setUltraAccurate(true);
@@ -857,48 +985,188 @@ public:
if( zPos - zSlop <= groundZ )
{
m_landingSoundPlayed = TRUE;
- AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_aircraftWheelScreech;
+ AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_aircraftWheelScreech;
soundToPlay.setPosition( jet->getPosition() );
TheAudio->addAudioEvent( &soundToPlay );
}
}
+
+ ParkingPlaceBehaviorInterface* pp = getPP(jet->getProducerID());
+ if (pp)
+ return flyLanding(jet, jetAI, pp);
}
else
{
ParkingPlaceBehaviorInterface* pp = getPP(jet->getProducerID());
if (pp)
+ {
pp->transferRunwayReservationToNextInLineForTakeoff(jet->getID());
+ return flyTakeoff(jet, jetAI, pp);
+ }
- //Calculate the distance of the jet from the end of the runway as a ratio from the start.
- //As it approaches the end of the runway, the plane will gain more lift, even if it's already
- //going quickly. Using speed for lift is bad in the case of the aircraft carrier, because
- //we don't want it to take off quickly.
// the airfield can be sold or destroyed under a jet on its takeoff roll: no runway left
// to measure against, so give it full lift and let it go
- if (pp)
+ jetAI->getCurLocomotor()->setMaxLift(BIGNUM);
+ }
+
+ StateReturnType ret = AIFollowPathState::update();
+ return ret;
+ }
+
+private:
+
+ /// steer down the runway's centre line and climb off it (see JET_LIFTOFF_SHARE)
+ StateReturnType flyTakeoff(Object* jet, JetAIUpdate* jetAI, ParkingPlaceBehaviorInterface* pp)
+ {
+ ParkingPlaceBehaviorInterface::PPInfo ppinfo;
+ pp->calcPPInfo( jet->getID(), &ppinfo );
+ const Coord3D& start = ppinfo.runwayStart;
+ const Coord3D& end = ppinfo.runwayEnd;
+ Real ux = end.x - start.x;
+ Real uy = end.y - start.y;
+ Real length = sqrt(ux*ux + uy*uy);
+ if (length < 1.0f)
+ return STATE_SUCCESS;
+ ux /= length;
+ uy /= length;
+
+ // runwayStart may be the prep spot of a jet that was in line; the runway itself is runwayTakeoffDist long
+ Real runway = ppinfo.runwayTakeoffDist;
+ const Coord3D* pos = jet->getPosition();
+ Real along = runway + (pos->x - end.x) * ux + (pos->y - end.y) * uy;
+ Real runwayZ = end.z;
+ if (along < runway && runway > 0.0f)
+ runwayZ = start.z + (end.z - start.z) * ((along > 0.0f) ? along / runway : 0.0f);
+ // off a deck, the climb starts from the deck the jet is drawn on
+ Real deckOffset = pp->getLandingDeckHeightOffset();
+ Real climbHeight = ppinfo.runwayExit.z - end.z - deckOffset;
+ if (climbHeight < JET_GO_AROUND_HEIGHT)
+ climbHeight = JET_GO_AROUND_HEIGHT;
+
+ // a few frames of travel ahead, for the height to lead the lift that has to reach it
+ Real speed = jet->getPhysics()->getForwardSpeed2D();
+ Real lead = speed * JET_HEIGHT_LAG_FRAMES;
+ Real height = JetRunway_slopeHeight(along + lead - JET_LIFTOFF_SHARE * runway, climbHeight, JET_CLIMB_SLOPE,
+ JET_ROTATE_SHARE * runway);
+ if (height >= climbHeight)
+ return STATE_SUCCESS;
+
+ Coord3D goal;
+ Real ahead = along - runway + calcLookAhead(jet, jetAI->getCurLocomotor());
+ goal.x = end.x + ux * ahead;
+ goal.y = end.y + uy * ahead;
+ goal.z = (height > 0.0f) ? runwayZ + deckOffset + height : runwayZ;
+ jetAI->setLocomotorGoalPositionExplicit(goal);
+ return STATE_CONTINUE;
+ }
+
+ /// fly the circuit onto the final, down the glide slope, and roll out (see JET_GLIDE_SLOPE)
+ StateReturnType flyLanding(Object* jet, JetAIUpdate* jetAI, ParkingPlaceBehaviorInterface* pp)
+ {
+ ParkingPlaceBehaviorInterface::PPInfo ppinfo;
+ pp->calcPPInfo( jet->getID(), &ppinfo );
+ // a carrier lands on its own strip; an airfield the way it took off, the other way round
+ Bool deck = jet->testStatus( OBJECT_STATUS_DECK_HEIGHT_OFFSET );
+ const Coord3D& touch = deck ? ppinfo.runwayLandingStart : ppinfo.runwayEnd;
+ const Coord3D& stop = deck ? ppinfo.runwayLandingEnd : ppinfo.runwayStart;
+ Real ux = stop.x - touch.x;
+ Real uy = stop.y - touch.y;
+ Real runway = sqrt(ux*ux + uy*uy);
+ if (runway < 1.0f)
+ return STATE_SUCCESS;
+ ux /= runway;
+ uy /= runway;
+
+ Locomotor* loco = jetAI->getCurLocomotor();
+ BodyDamageType bdt = jet->getBodyModule()->getDamageState();
+ Real minSpeed = loco->getMinSpeed();
+ Real circuitSpeed = loco->getJetCornerSpeed(bdt);
+ if (circuitSpeed < minSpeed)
+ circuitSpeed = minSpeed;
+ Real rate = loco->getJetMaxYawRate(bdt, circuitSpeed);
+ Real radius = (rate > 0.0f) ? circuitSpeed / rate : 0.0f;
+ Real deckOffset = pp->getLandingDeckHeightOffset();
+ // the turn onto the final starts a radius further out than the final itself
+ Real turnIn = JET_FINAL_DIST + radius;
+
+ const Coord3D* pos = jet->getPosition();
+ Real along = (pos->x - touch.x) * ux + (pos->y - touch.y) * uy; // negative short of the threshold
+ Real across = (pos->y - touch.y) * ux - (pos->x - touch.x) * uy; // positive to the left
+ Real runwayZ = stop.z;
+ if (along < runway)
+ runwayZ = touch.z + (stop.z - touch.z) * ((along > 0.0f) ? along / runway : 0.0f);
+ Real height = pos->z - runwayZ - deckOffset;
+ Real offLine = stdAngleDiff(jet->getOrientation(), ATan2(uy, ux));
+ Real speed = jet->getPhysics()->getForwardSpeed2D();
+ Real lead = speed * JET_HEIGHT_LAG_FRAMES;
+
+ // the distance flown to the threshold, round what is left of the turn onto the centre line
+ Real toThreshold = -along + radius * fabs(offLine);
+ Real glide = JetRunway_slopeHeight(toThreshold - lead, BIGNUM, JET_GLIDE_SLOPE, JET_FLARE_DIST);
+ Bool linedUp = along < 0.0f && fabs(offLine) < PI / 2.0f && height <= glide + JET_HIGH_ON_FINAL &&
+ (fabs(across) <= JET_LINE_UP_SLACK || -along >= JET_LINE_UP_ROOM * fabs(across));
+ Bool rollingOut = along >= 0.0f && height <= JET_GO_AROUND_HEIGHT;
+
+ Coord3D goal;
+ Real wantSpeed = circuitSpeed;
+ if (linedUp || rollingOut || along <= -turnIn)
+ {
+ // on the final, or far enough out to come round onto it: steer for a point ahead on the centre line
+ Real ahead = along + calcLookAhead(jet, loco);
+ goal.x = touch.x + ux * ahead;
+ goal.y = touch.y + uy * ahead;
+
+ if (along >= 0.0f)
{
- ParkingPlaceBehaviorInterface::PPInfo ppinfo;
- pp->calcPPInfo( jet->getID(), &ppinfo );
- Coord3D vector = ppinfo.runwayEnd;
- vector.sub( jet->getPosition() );
- Real dist = vector.length();
-
- Real ratio = 1.0f - (dist / ppinfo.runwayTakeoffDist);
- ratio *= ratio; //dampen it....
- if (ratio < 0.0f) ratio = 0.0f;
- if (ratio > 1.0f) ratio = 1.0f;
- jetAI->getCurLocomotor()->setMaxLift(m_maxLift * ratio);
+ if (along >= runway - JET_LINE_UP_SLACK)
+ return STATE_SUCCESS;
+ // slow down the length of the runway, to a crawl at its end
+ Real endSpeed = JET_ROLLOUT_END_SHARE * minSpeed;
+ wantSpeed = endSpeed + (minSpeed - endSpeed) * (runway - along) / runway;
}
- else
+ else if (-along < turnIn)
{
- jetAI->getCurLocomotor()->setMaxLift(m_maxLift);
+ // down the final from the circuit speed to MinSpeed over the threshold
+ wantSpeed = minSpeed + (circuitSpeed - minSpeed) * (-along / turnIn);
}
}
+ else
+ {
+ // the circuit: out along the side of the runway the jet is heading for, two radii off the
+ // centre line, to where the turn in starts
+ Real sideways = across + 2.0f * radius * Sin(offLine);
+ Real side = (sideways >= 0.0f) ? 2.0f * radius : -2.0f * radius;
+ goal.x = touch.x - ux * turnIn - uy * side;
+ goal.y = touch.y - uy * turnIn + ux * side;
+ Real toTurn = sqrt(sqr(goal.x - pos->x) + sqr(goal.y - pos->y));
+ glide = JetRunway_slopeHeight(toTurn + PI * radius + turnIn - lead, BIGNUM, JET_GLIDE_SLOPE, JET_FLARE_DIST);
+ }
+
+ // never climb back up to the glide, and come down to it no steeper than JET_STEEPEST_DESCENT
+ Real wantHeight = (glide < height) ? glide : height;
+ Real steepest = height - JET_HEIGHT_LAG_FRAMES * JET_STEEPEST_DESCENT * speed;
+ if (wantHeight < steepest && !rollingOut)
+ wantHeight = steepest;
+ goal.z = (wantHeight > 0.0f) ? runwayZ + deckOffset + wantHeight : runwayZ;
+
+ loco->setMaxSpeed(wantSpeed);
+ jetAI->setLocomotorGoalPositionExplicit(goal);
+ return STATE_CONTINUE;
+ }
- StateReturnType ret = AIFollowPathState::update();
- return ret;
+ /// how far ahead on the centre line to steer for: twice the jet's turn radius at its speed, at least JET_MIN_LOOKAHEAD
+ static Real calcLookAhead(Object* jet, Locomotor* loco)
+ {
+ Real speed = jet->getPhysics()->getForwardSpeed2D();
+ if (speed < loco->getMinSpeed())
+ speed = loco->getMinSpeed();
+ Real rate = loco->getJetMaxYawRate(jet->getBodyModule()->getDamageState(), speed);
+ Real look = (rate > 0.0f) ? 2.0f * speed / rate : JET_MIN_LOOKAHEAD;
+ return (look > JET_MIN_LOOKAHEAD) ? look : JET_MIN_LOOKAHEAD;
}
+public:
+
virtual void onExit( StateExitType status )
{
AIFollowPathState::onExit(status);
@@ -921,6 +1189,7 @@ public:
{
loco->setUsePreciseZPos(false);
loco->setUltraAccurate(false);
+ loco->setNoSlowDownAsApproachingDest(false);
// don't restore lift if dead -- this may fight with JetSlowDeathBehavior!
if (!jet->isEffectivelyDead())
loco->setMaxLift(BIGNUM);
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 4beb3b41e..4a04a20b7 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -2509,6 +2509,72 @@ TEST(jet_runs_out_from_a_target_it_cannot_turn_onto)
CHECK( !AIAttackAim_needsRunOut( 60.0f, 60.0f, R, 0.7071068f, 0.0f ) );
}
+/* JetAIUpdate.cpp: the glide down to a touchdown and the climb from a liftoff are one shape, a
+ straight slope that rounds out to level at the runway and stops at the approach height. */
+extern Real JetRunway_slopeHeight( Real dist, Real maxHeight, Real slope, Real roundDist );
+
+TEST(jet_glide_rounds_out_to_a_level_touchdown)
+{
+ const Real SLOPE = 0.176f;
+ const Real ROUND = 50.0f;
+
+ /* on and past the threshold it is on the runway */
+ CHECK_NEAR( JetRunway_slopeHeight( 0.0f, 50.0f, SLOPE, ROUND ), 0.0f, 1e-6f );
+ CHECK_NEAR( JetRunway_slopeHeight( -30.0f, 50.0f, SLOPE, ROUND ), 0.0f, 1e-6f );
+
+ /* the round-out meets the slope with the same height and the same steepness, so the sink rate
+ eases off instead of stepping */
+ const Real atJoin = JetRunway_slopeHeight( ROUND, 50.0f, SLOPE, ROUND );
+ CHECK_NEAR( atJoin, SLOPE * ROUND * 0.5f, 1e-4f );
+ CHECK_NEAR( JetRunway_slopeHeight( ROUND + 10.0f, 50.0f, SLOPE, ROUND ) - atJoin, SLOPE * 10.0f, 1e-4f );
+ CHECK( JetRunway_slopeHeight( 5.0f, 50.0f, SLOPE, ROUND ) < SLOPE * 5.0f * 0.1f );
+
+ /* far out it holds the approach height */
+ CHECK_NEAR( JetRunway_slopeHeight( 2000.0f, 50.0f, SLOPE, ROUND ), 50.0f, 1e-6f );
+}
+
+/* JetAIUpdate.cpp: a taxi route's corners become arcs a jet on its wheels can drive round. */
+extern void JetTaxi_roundCorners( std::vector<Coord3D>& route, Real radius );
+
+TEST(jet_taxi_corner_becomes_an_arc)
+{
+ std::vector<Coord3D> route(3);
+ route[0].set( 0.0f, 0.0f, 0.0f );
+ route[1].set( 100.0f, 0.0f, 0.0f );
+ route[2].set( 100.0f, 100.0f, 0.0f );
+ JetTaxi_roundCorners( route, 20.0f );
+
+ /* the ends stay put, and everything between lies on the circle round (80, 20), from where it
+ leaves the leg in to where it joins the leg out */
+ CHECK( route.size() > 3 );
+ CHECK_NEAR( route.front().x, 0.0f, 1e-4f );
+ CHECK_NEAR( route.back().y, 100.0f, 1e-4f );
+ for (size_t i = 1; i + 1 < route.size(); ++i)
+ {
+ Real dx = route[i].x - 80.0f;
+ Real dy = route[i].y - 20.0f;
+ CHECK_NEAR( sqrt(dx*dx + dy*dy), 20.0f, 0.01f );
+ }
+ CHECK_NEAR( route[1].x, 80.0f, 0.01f );
+ CHECK_NEAR( route[route.size() - 2].y, 20.0f, 0.01f );
+
+ /* a leg too short for the radius shrinks the arc to fit in under half of it */
+ std::vector<Coord3D> tight(3);
+ tight[0].set( 0.0f, 0.0f, 0.0f );
+ tight[1].set( 10.0f, 0.0f, 0.0f );
+ tight[2].set( 10.0f, 100.0f, 0.0f );
+ JetTaxi_roundCorners( tight, 20.0f );
+ CHECK_NEAR( tight[1].x, 5.5f, 0.01f );
+
+ /* a straight route is left alone */
+ std::vector<Coord3D> straight(3);
+ straight[0].set( 0.0f, 0.0f, 0.0f );
+ straight[1].set( 50.0f, 0.0f, 0.0f );
+ straight[2].set( 100.0f, 0.0f, 0.0f );
+ JetTaxi_roundCorners( straight, 20.0f );
+ CHECK_EQ( straight.size(), (size_t)3 );
+}
+
/* AIStates.cpp: telling a firing pass from a failed approach when the attack move
disengages. A fight the unit spent rounds on was real however short; only one it
never fired in is charged the re-acquire delay. The ammunition count is the state