The gyro's sway slew (@004b275c) was already reconstructed and already read the cell the master perf writes -- swayBias -- which nothing had ever written. So the mechInstability member I added to the gyro in 5.3.127 was a duplicate of that same cell, the second such mistake this arc after realMaxSpeed/runSpeedMax. The lesson repeats: grep our own tree for an existing carve before adding a member for a binary offset. Merged, and the loop closes: the instability model now publishes into swayBias, so an unstable mech shakes its pilot harder through code that was already correct and waiting for a writer. Also corrected: the binary's impaired gate has three terms where ours had two -- a gyro destroyed outright swings to the impaired sway base, not only an unpowered or heat-failed one. Verified on the rig (BT_SWAY_LOG): bias arrives, the angle slews toward base+bias and stays inside the authored band, zero faults. AND THE LOG IMMEDIATELY EARNED ITS KEEP. It showed impaired=1 for an entire clean run. Instrumenting the three terms: state=0, heat=0 -- so the new term is inert and correct -- but watchdog=0 where Ready is 4. PowerWatcher::UpdateWatch falls back to 0 when its watched link resolves NULL, and watchedLink is default-constructed and bound NOWHERE in the tree, for PowerWatcher and HeatWatcher alike. So the whole watcher family is inert: every watcher resolves NULL, every PowerWatcher reports its target unpowered, and the gyro has been sitting on its destruction-grade sway base since the sway model landed -- invisibly, until this log existed. The fix needs the streamed watch index and a real ctor bind; guessing a binding is precisely what this project forbids, so it is recorded with its evidence for the next sitting rather than improvised now. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
223 lines
7.3 KiB
C++
223 lines
7.3 KiB
C++
//===========================================================================//
|
|
// File: gyro.hpp //
|
|
// Project: BattleTech Brick: Mech subsystems //
|
|
// Contents: Gyroscope -- the eye/body stabilisation subsystem //
|
|
//---------------------------------------------------------------------------//
|
|
// Copyright (C) 1995, Virtual World Entertainment, Inc. //
|
|
// All Rights reserved worldwide //
|
|
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
|
|
//===========================================================================//
|
|
|
|
#if !defined(GYRO_HPP)
|
|
# define GYRO_HPP
|
|
|
|
# if !defined(POWERSUB_HPP)
|
|
# include <powersub.hpp>
|
|
# endif
|
|
|
|
//##################### Forward Class Declarations #######################
|
|
class Mech;
|
|
|
|
//###########################################################################
|
|
//################### Gyroscope Model Resource #########################
|
|
//###########################################################################
|
|
|
|
//
|
|
// One per-damage-type response row: how hard a hit of that type kicks
|
|
// the four gyro channels.
|
|
//
|
|
struct Gyroscope__DamageResponse
|
|
{
|
|
Scalar trans;
|
|
Scalar pitchRoll;
|
|
Scalar yaw;
|
|
Scalar vibration;
|
|
};
|
|
|
|
struct Gyroscope__SubsystemResource:
|
|
public PowerWatcher::SubsystemResource
|
|
{
|
|
Scalar reservedF4;
|
|
Scalar exageration;
|
|
Scalar maxAnimationNoise;
|
|
Scalar minAnimationNoise;
|
|
Scalar rotationPerSecond;
|
|
Scalar percentageOnNormal;
|
|
Scalar percentageOnDestruction;
|
|
Scalar percentageOnDegradation;
|
|
Scalar percentageOnFailure;
|
|
Vector3D springConstant;
|
|
Vector3D dampingConstant;
|
|
Vector3D posSpring;
|
|
Vector3D negSpring;
|
|
Vector3D rotationSpringConstant;
|
|
Vector3D rotationDampingConstant;
|
|
Vector3D rotationPosSpring;
|
|
Vector3D rotationNegSpring;
|
|
char eyeJoint[32];
|
|
char mechJoint[32];
|
|
Scalar collisionDamageMultiplier;
|
|
Scalar ballisticDamageMultiplier;
|
|
Scalar explosiveDamageMultiplier;
|
|
Scalar laserDamageMultiplier;
|
|
Scalar energyDamageMultiplier;
|
|
|
|
//
|
|
// The five response quads follow the multipliers in the stream
|
|
// (record size 0x21C -- binary-verified layout).
|
|
//
|
|
Gyroscope__DamageResponse collisionDamageResponse;
|
|
Gyroscope__DamageResponse ballisticDamageResponse;
|
|
Gyroscope__DamageResponse explosiveDamageResponse;
|
|
Gyroscope__DamageResponse laserDamageResponse;
|
|
Gyroscope__DamageResponse energyDamageResponse;
|
|
};
|
|
|
|
//###########################################################################
|
|
//############################## Gyroscope #############################
|
|
//###########################################################################
|
|
//
|
|
// The gyro drives the cockpit eye joint (view stabilisation) and the body
|
|
// lean. The tuning constants are read from the resource; the eye/body
|
|
// dynamics state (springs, forces, velocities, work matrices) is advanced by
|
|
// the per-frame GyroscopeSimulation and held in dynamicsState until that
|
|
// (staged) method is reconstructed with the named fields.
|
|
//
|
|
class Gyroscope:
|
|
public PowerWatcher
|
|
{
|
|
public:
|
|
static Derivation ClassDerivations;
|
|
static SharedData DefaultData;
|
|
|
|
typedef void
|
|
(Gyroscope::*Performance)(Scalar time_slice);
|
|
void
|
|
SetPerformance(Performance performance)
|
|
{
|
|
Check(this);
|
|
activePerformance = (Simulation::Performance)performance;
|
|
}
|
|
|
|
static Logical
|
|
TestClass(Mech &);
|
|
Logical
|
|
TestInstance() const;
|
|
void
|
|
ResetToInitialState();
|
|
void
|
|
GyroscopeSimulation(Scalar time_slice);
|
|
|
|
//
|
|
// The two integrators (called by the sim) and the two joint writes
|
|
// (called by the MECH master performance tail, after the gait --
|
|
// NOT by the sim; binary @0x4aaf74/83).
|
|
//
|
|
void
|
|
IntegrateEyeJoint(Scalar time_slice);
|
|
void
|
|
IntegrateBody(Scalar time_slice);
|
|
void
|
|
WriteEyeJoint();
|
|
void
|
|
WriteMechJoint();
|
|
|
|
//
|
|
// The hit-bounce feeds. ApplyDamageResponse is the damage hub's
|
|
// fan-out (every non-collision hit shakes the cockpit); the three
|
|
// primitive kicks are also fed directly by the collision CRUNCH.
|
|
//
|
|
void
|
|
ApplyDamageResponse(const Damage &damage);
|
|
void
|
|
ApplyDamageImpulse(Scalar x, Scalar y, Scalar z, Scalar magnitude);
|
|
void
|
|
ApplyDamageTorque(Scalar x, Scalar y, Scalar z, Scalar magnitude);
|
|
void
|
|
ApplyVerticalImpulse(Scalar pitch, Scalar magnitude);
|
|
|
|
public:
|
|
typedef Gyroscope__SubsystemResource SubsystemResource;
|
|
|
|
Gyroscope(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &shared_data = DefaultData
|
|
);
|
|
~Gyroscope();
|
|
|
|
protected:
|
|
Scalar exageration;
|
|
Scalar maxAnimationNoise;
|
|
Scalar minAnimationNoise;
|
|
Scalar rotationPerSecond;
|
|
Scalar percentageOnNormal;
|
|
Scalar percentageOnDestruction;
|
|
Scalar percentageOnDegradation;
|
|
Scalar percentageOnFailure;
|
|
Vector3D springConstant;
|
|
Vector3D dampingConstant;
|
|
Vector3D posSpring;
|
|
Vector3D negSpring;
|
|
Vector3D rotationSpringConstant;
|
|
Vector3D rotationDampingConstant;
|
|
Vector3D rotationPosSpring;
|
|
Vector3D rotationNegSpring;
|
|
Scalar damageMultiplier[5];
|
|
Gyroscope__DamageResponse
|
|
damageResponse[5];
|
|
|
|
//
|
|
// The eye TRANSLATION spring state (the steady eye offset + hit
|
|
// bounce) and the body ROTATION spring state (the hull tip). The
|
|
// clamps are COPIES of the spring pairs, taken at ctor time (the
|
|
// body pair scaled by 2).
|
|
//
|
|
Vector3D eyePosition, eyeVelocity, eyeForce, eyeWork;
|
|
Vector3D eyeClampUpper, eyeClampLower;
|
|
Vector3D bodyOrientation, bodyVelocity, bodyForce, bodyWork;
|
|
Vector3D bodyClampUpper, bodyClampLower;
|
|
|
|
//
|
|
// Sway (the animation-noise wander the sim slews between the
|
|
// powered/impaired percentages) and the placement scratch the
|
|
// damage fan-out rotates hit directions through.
|
|
//
|
|
public:
|
|
//
|
|
// The mech's instability, republished here by the master perf every
|
|
// frame (binary gyro+0x3a8) straight into the sway bias below.
|
|
//
|
|
void
|
|
SetSwayBias(Scalar instability)
|
|
{ Check(this); swayBias = instability; }
|
|
|
|
protected:
|
|
//
|
|
// swayAngle the live cockpit noise amplitude (binary gyro+0x3bc),
|
|
// slewed toward its target at rotationPerSecond and clamped into
|
|
// the authored [minAnimationNoise, maxAnimationNoise] band.
|
|
// swayBias THE MECH'S INSTABILITY (binary gyro+0x3a8), added to
|
|
// the sway target: the closer the mech is to going over, the
|
|
// harder the cockpit shakes. 5.3.131 -- this member always
|
|
// existed and the slew always read it, but nothing wrote it; the
|
|
// separate 'mechInstability' member added in 5.3.127 was a
|
|
// duplicate of the same cell and is retired.
|
|
//
|
|
Scalar swayAngle, swayBias, swayVelocity;
|
|
int swayActive;
|
|
Vector3D placeRot, placePos;
|
|
Scalar placeQuat[4];
|
|
Scalar workMatrix[12];
|
|
Scalar spare0;
|
|
Scalar *externalPitchPtr; // -> the torso twist (yaw-only hit
|
|
// frame); self-points at spare0
|
|
// until a torso binds it
|
|
Vector3D vibrationDirection; // the fixed up axis
|
|
Joint *eyeJointNode;
|
|
Joint *mechJointNode;
|
|
};
|
|
|
|
#endif
|