The last eight stubs plus the two chain layers they actually need (PoweredSubsystem @004b13ac and ProjectileWeapon @004bc7cc were DECLARED in our headers all along -- only their definitions were missing). These are the notation->stream converters the 1995 authoring pipeline ran; missions read prebuilt streams and never call them, so the verification standard is compile + link + the raw decomp's key fingerprints -- and those fingerprints convicted the donors three more times: - The heat chain: Condenser, Reservoir AND PoweredSubsystem all chain ONE shared parser (@004ae150, reconstructed in full from the decomp -- the BT411 donor's body was its own TODO stub with a miscited address). It reads the five thermal scalars and the conduction-graph link (the linkedSinkIndex our wire-format work dump-verified from the runtime side, with the +2 segment-table bias), and HeatSink adds no keys of its own. - The Emitter's SeekVoltage LADDER is a notation ENTRY LIST walked in file order (curve rungs in sequence, the RecommendedIndex entry by name); the donor flattened it to one keyed read, which would author one-rung ladders against the runtime's real five-rung ones. MakeEntryList/GetFirstEntry is the engine's own idiom. - PipColor and MuzzleVelocity parse through the engine's authentic Convert_From_Ascii overloads (RGBColor / Vector3D); the donors' sscanf substitutes were port drift. Explosion and alarm models resolve as model FAMILIES (ModelListResourceType == the literal 1 in the binary; the donor comment calling it GameModelResourceType was wrong-name-right-number). Entry reads target the SUBSYSTEM notation file -- the decomp's fifth argument at every site; several donors wrote model_file. Class IDs stamp through OUR reader's enum symbols (they parse the real BTL4.RES streams today, and the 3000-base enum lands exactly on the binary's 0xBBB.. ids; 0x0BCD is the weapon-base stamp every concrete leaf overwrites). Stubs: NONE. Every function in restoration/source410 now has a body. Mission soak clean. Remaining reconstruction is depth, not holes: the mech4/mech3 archaeology (IntegrateMotion, the master-perf disasm, the stream builders that seed the 0xC/0x100 flags), HUD blocks 4-6, and the live networked/rig verifications queued for when a pod is available. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
457 lines
15 KiB
C++
457 lines
15 KiB
C++
//===========================================================================//
|
|
// File: mechsub.cpp //
|
|
// Project: BattleTech Brick: Mech subsystems //
|
|
// Contents: Implementation details for the MechSubsystem base //
|
|
//---------------------------------------------------------------------------//
|
|
// Copyright (C) 1995, Virtual World Entertainment, Inc. //
|
|
// All Rights reserved worldwide //
|
|
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
|
|
//===========================================================================//
|
|
|
|
#include <bt.hpp>
|
|
#pragma hdrstop
|
|
|
|
#if !defined(MECHSUB_HPP)
|
|
# include <mechsub.hpp>
|
|
#endif
|
|
|
|
#if !defined(MECH_HPP)
|
|
# include <mech.hpp>
|
|
#endif
|
|
|
|
#if !defined(DAMAGE_HPP)
|
|
# include <damage.hpp>
|
|
#endif
|
|
|
|
#if !defined(BTPLAYER_HPP)
|
|
# include <btplayer.hpp>
|
|
#endif
|
|
|
|
#if !defined(BTMSSN_HPP)
|
|
# include <btmssn.hpp>
|
|
#endif
|
|
|
|
//
|
|
//#############################################################################
|
|
// Shared data support -- MechSubsystem adds no message handlers or attributes
|
|
// that are boot-critical, so it reuses the base Subsystem sets (which are the
|
|
// inherited Simulation sets).
|
|
//#############################################################################
|
|
//
|
|
Derivation
|
|
MechSubsystem::ClassDerivations(
|
|
Subsystem::ClassDerivations,
|
|
"MechSubsystem"
|
|
);
|
|
|
|
const MechSubsystem::IndexEntry
|
|
MechSubsystem::AttributePointers[]=
|
|
{
|
|
ATTRIBUTE_ENTRY(MechSubsystem, ConfigureActivePress, configureActivePress)
|
|
};
|
|
|
|
MechSubsystem::AttributeIndexSet
|
|
MechSubsystem::AttributeIndex(
|
|
ELEMENTS(MechSubsystem::AttributePointers),
|
|
MechSubsystem::AttributePointers,
|
|
Subsystem::AttributeIndex
|
|
);
|
|
|
|
MechSubsystem::SharedData
|
|
MechSubsystem::DefaultData(
|
|
MechSubsystem::ClassDerivations,
|
|
Subsystem::MessageHandlers,
|
|
MechSubsystem::AttributeIndex,
|
|
Subsystem::StateCount
|
|
);
|
|
|
|
//
|
|
//#############################################################################
|
|
// Light constructor (name + classID). For a subsystem created without a
|
|
// streamed resource; builds a trivial (armour-free) damage zone named by the
|
|
// base.
|
|
//#############################################################################
|
|
//
|
|
MechSubsystem::MechSubsystem(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
const char *subsystem_name,
|
|
RegisteredClass::ClassID class_id,
|
|
SharedData &shared_data
|
|
):
|
|
Subsystem(owner, subsystem_ID, subsystem_name, class_id, shared_data)
|
|
{
|
|
this->owner = owner;
|
|
vitalSubsystem = False;
|
|
alarmModel = ResourceDescription::NullResourceID;
|
|
criticalReference = 0.0f;
|
|
collisionCriticalHitWeight = 0.0f;
|
|
printSimulationState = False;
|
|
configureActivePress = -1;
|
|
resource = NULL;
|
|
statusAlarm.SetLevel(0);
|
|
|
|
//
|
|
// The base Subsystem ctor leaves damageZone NULL; give this subsystem a
|
|
// trivial (armour-free) zone.
|
|
//
|
|
damageZone = new DamageZone(owner, 0);
|
|
Register_Object(damageZone);
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// Resource constructor. Chains the base Subsystem resource ctor and seeds the
|
|
// mech-specific fields from the subsystem resource.
|
|
//
|
|
// The 4.10 damage model is per-damage-TYPE: the damage zone owns
|
|
// defaultArmorPoints + damageScale[5] and streams them itself (a
|
|
// Mech__DamageZone built from the model's damage-zone stream). Wiring that
|
|
// stream through from the resource is deferred (see MECHSUB.NOTES.md); until
|
|
// then the subsystem gets a trivial armour-free zone so it constructs and takes
|
|
// damage with default (unscaled) behaviour.
|
|
//#############################################################################
|
|
//
|
|
MechSubsystem::MechSubsystem(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &shared_data
|
|
):
|
|
Subsystem(owner, subsystem_ID, subsystem_resource, shared_data)
|
|
{
|
|
Check_Pointer(subsystem_resource);
|
|
|
|
this->owner = owner;
|
|
resource = subsystem_resource;
|
|
vitalSubsystem = (subsystem_resource->vitalSubsystemIndex == 1);
|
|
alarmModel = subsystem_resource->alarmModel;
|
|
printSimulationState = subsystem_resource->printSimulationState;
|
|
criticalReference = subsystem_resource->criticalReference;
|
|
collisionCriticalHitWeight = subsystem_resource->collisionCriticalHitWeight;
|
|
configureActivePress = -1;
|
|
statusAlarm.SetLevel(0);
|
|
|
|
//
|
|
// The subsystem's PRIVATE damage zone (binary @4abf28: `new
|
|
// DamageZone(this, 0)` -- owned by the SUBSYSTEM, index 0, NOT an entry
|
|
// in the entity's hull-zone array). The resource authors its armor the
|
|
// same way the hull stream does -- structureReference points +
|
|
// armorByFacing[5] per-type values -- normalized with the same rule as
|
|
// Mech::DamageZone (scale = 1/(raw x points); already-normalized cells
|
|
// pass through). This is what makes critical hits MEASURABLE
|
|
// (ApplyDamageAndMeasure) and the crit-allotment push meaningful.
|
|
//
|
|
damageZone = new DamageZone(this, 0);
|
|
Register_Object(damageZone);
|
|
damageZone->damageZoneName = GetName();
|
|
if (subsystem_resource->structureReference > 0.0f)
|
|
{
|
|
damageZone->defaultArmorPoints = subsystem_resource->structureReference;
|
|
for (int tt = 0; tt < Damage::DamageTypeCount; ++tt)
|
|
{
|
|
Scalar raw = subsystem_resource->armorByFacing[tt];
|
|
Scalar even = 1.0f / subsystem_resource->structureReference;
|
|
Scalar diff = raw - even;
|
|
if (diff < 0.0f)
|
|
{
|
|
diff = -diff;
|
|
}
|
|
if (diff > 1.0e-4f && raw > 0.0f)
|
|
{
|
|
damageZone->damageScale[tt] =
|
|
1.0f / (raw * subsystem_resource->structureReference);
|
|
}
|
|
else
|
|
{
|
|
damageZone->damageScale[tt] = raw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
//#############################################################################
|
|
//
|
|
MechSubsystem::~MechSubsystem()
|
|
{
|
|
if (damageZone)
|
|
{
|
|
Unregister_Object(damageZone);
|
|
delete damageZone;
|
|
damageZone = NULL;
|
|
}
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
//#############################################################################
|
|
//
|
|
Logical
|
|
MechSubsystem::TestClass(Mech &)
|
|
{
|
|
return True;
|
|
}
|
|
|
|
Logical
|
|
MechSubsystem::TestInstance() const
|
|
{
|
|
return IsDerivedFrom(ClassDerivations);
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// Damage support -- the 4.10 damage zone tracks damageLevel in [0,1]
|
|
// (0 = intact, 1 = destroyed).
|
|
//#############################################################################
|
|
//
|
|
Scalar
|
|
MechSubsystem::GetSubsystemDamageLevel() const
|
|
{
|
|
Check(this);
|
|
return damageZone ? damageZone->damageLevel : 0.0f;
|
|
}
|
|
|
|
void
|
|
MechSubsystem::SetSubsystemDamageLevel(Scalar level)
|
|
{
|
|
Check(this);
|
|
if (damageZone)
|
|
{
|
|
damageZone->damageLevel = level;
|
|
}
|
|
}
|
|
|
|
void
|
|
MechSubsystem::ForceCriticalFailure()
|
|
{
|
|
Check(this);
|
|
//
|
|
// Binary @4ac8xx family: the status alarm's DESTROYED display level is 1
|
|
// (the TechStatusType enum's Destroyed=0 is the display CATEGORY, not
|
|
// the alarm level -- BT411 disasm: "+0x2C: 1 = Destroyed").
|
|
//
|
|
statusAlarm.SetLevel(1);
|
|
//
|
|
// DestroyedState is the hard-failure gate the weapon simulations poll
|
|
// (`GetSimulationState() == 1`): a destroyed weapon drops its charge /
|
|
// pins the unavailable alarm from the next frame on.
|
|
//
|
|
SetSimulationState(DestroyedState);
|
|
if (damageZone)
|
|
{
|
|
damageZone->SetDamageZoneState(DamageZone::BurningState);
|
|
}
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// DeathReset -- the respawn restore (the engine base virtual pair's reset
|
|
// half; Mech::Reset @0049fb74 loops every subsystem through it). The base:
|
|
// heal the private zone, clear the Destroyed display level and -- the
|
|
// load-bearing part -- clear DestroyedState so the weapon hard gates
|
|
// (GetSimulationState() == 1) release.
|
|
//#############################################################################
|
|
//
|
|
void
|
|
MechSubsystem::DeathReset(Logical /*full_reset*/)
|
|
{
|
|
Check(this);
|
|
|
|
if (damageZone != NULL)
|
|
{
|
|
damageZone->damageLevel = 0.0f;
|
|
damageZone->SetDamageZoneState(0);
|
|
}
|
|
statusAlarm.SetLevel(0);
|
|
SetSimulationState(Simulation::DefaultState);
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// ApplyDamageAndMeasure (binary @4ac07c): apply through the virtual
|
|
// TakeDamage and report the zone-level delta -- the critical accountant
|
|
// (Mech::DamageZone::CriticalHit) charges the delta against the entry's
|
|
// damagePercentage allotment.
|
|
//#############################################################################
|
|
//
|
|
Scalar
|
|
MechSubsystem::ApplyDamageAndMeasure(Damage &damage)
|
|
{
|
|
Check(this);
|
|
Scalar before = (damageZone != NULL) ? damageZone->damageLevel : 0.0f;
|
|
TakeDamage(damage);
|
|
Scalar after = (damageZone != NULL) ? damageZone->damageLevel : 0.0f;
|
|
return after - before;
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// TakeDamage Forward to the damage zone (per-type scaling happens there).
|
|
//#############################################################################
|
|
//
|
|
void
|
|
MechSubsystem::TakeDamage(Damage &damage)
|
|
{
|
|
Check(this);
|
|
Check_Pointer(&damage);
|
|
if (damageZone)
|
|
{
|
|
damageZone->TakeDamage(damage);
|
|
}
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// CreateStreamedSubsystem Model-load-time construction of the subsystem
|
|
// resource + its damage-zone stream. Not yet reconstructed (see
|
|
// MECHSUB.NOTES.md -- the 4.10 per-type damage-zone stream format).
|
|
//#############################################################################
|
|
//
|
|
|
|
//
|
|
//#############################################################################
|
|
// CreateStreamedSubsystem -- binary @004ac9ec (1469 bytes). The authoring
|
|
// converter: parse the damageable-subsystem record from the notation files
|
|
// onto the stream resource. First pass primes every field to its unset
|
|
// sentinel; on later passes a missing key is only an error if the field is
|
|
// still unset. All entry reads come from the SUBSYSTEM notation file (the
|
|
// binary's fifth argument; the BT411 donor's model_file reads were drift).
|
|
//#############################################################################
|
|
//
|
|
int
|
|
MechSubsystem::CreateStreamedSubsystem(
|
|
NotationFile *model_file,
|
|
const char *model_name,
|
|
const char *subsystem_name,
|
|
SubsystemResource *subsystem_resource,
|
|
NotationFile *subsystem_file,
|
|
const ResourceDirectories *directories,
|
|
int passes
|
|
)
|
|
{
|
|
if (
|
|
!Subsystem::CreateStreamedSubsystem(
|
|
model_file, model_name, subsystem_name,
|
|
subsystem_resource, subsystem_file, directories
|
|
)
|
|
)
|
|
{
|
|
return False;
|
|
}
|
|
|
|
subsystem_resource->subsystemModelSize = 0xE4;
|
|
subsystem_resource->classID = RegisteredClass::MechSubsystemClassID;
|
|
|
|
if (passes == 1)
|
|
{
|
|
int
|
|
facing;
|
|
subsystem_resource->criticalReference = -1.0f;
|
|
for (facing = 0; facing < 5; facing++)
|
|
{
|
|
subsystem_resource->armorByFacing[facing] = -1.0f;
|
|
}
|
|
subsystem_resource->structureReference = -1.0f;
|
|
subsystem_resource->vitalSubsystemIndex = -1;
|
|
memset(subsystem_resource->videoObjectName, 0,
|
|
sizeof(subsystem_resource->videoObjectName));
|
|
strcpy(subsystem_resource->videoObjectName, "None");
|
|
subsystem_resource->alarmModel = 0;
|
|
subsystem_resource->printSimulationState = 0;
|
|
subsystem_resource->collisionCriticalHitWeight = 0.0f;
|
|
}
|
|
|
|
subsystem_file->GetEntry(subsystem_name, "PrintSimulationState",
|
|
&subsystem_resource->printSimulationState);
|
|
subsystem_file->GetEntry(subsystem_name, "CollisionCriticalHitWeight",
|
|
&subsystem_resource->collisionCriticalHitWeight);
|
|
|
|
const char
|
|
*video_name = "Unspecified";
|
|
subsystem_file->GetEntry(subsystem_name, "VideoObjectName", &video_name);
|
|
if (strcmp(video_name, "Unspecified") != 0)
|
|
{
|
|
strcpy(subsystem_resource->videoObjectName, video_name);
|
|
}
|
|
|
|
//
|
|
// "VitalSubsystem" -- optional; a skeleton page name resolved to a
|
|
// segment index.
|
|
//
|
|
const char
|
|
*vital_name = "Unspecified";
|
|
subsystem_file->GetEntry(subsystem_name, "VitalSubsystem", &vital_name);
|
|
if (strcmp(vital_name, "Unspecified") != 0)
|
|
{
|
|
subsystem_resource->vitalSubsystemIndex =
|
|
Get_Segment_Index(model_file, model_name, directories, vital_name);
|
|
}
|
|
|
|
//
|
|
// The armour/crit economy keys (binary key strings @0x50e09d..0x50e15d):
|
|
// WeaponDamagePoints and CriticalHitScoreBonus are REQUIRED; the five
|
|
// per-damage-type points are optional. (structureReference /
|
|
// armorByFacing are this tree's names for the same stream fields the
|
|
// runtime damage economy reads.)
|
|
//
|
|
if (
|
|
!subsystem_file->GetEntry(subsystem_name, "WeaponDamagePoints",
|
|
&subsystem_resource->structureReference)
|
|
&& subsystem_resource->structureReference == -1.0f
|
|
)
|
|
{
|
|
DEBUG_STREAM << subsystem_name << " Must have a WeaponDamagePoints" << endl;
|
|
return False;
|
|
}
|
|
if (
|
|
!subsystem_file->GetEntry(subsystem_name, "CriticalHitScoreBonus",
|
|
&subsystem_resource->criticalReference)
|
|
&& subsystem_resource->criticalReference == -1.0f
|
|
)
|
|
{
|
|
DEBUG_STREAM << subsystem_name << " Must have a CriticalHitScoreBonus" << endl;
|
|
return False;
|
|
}
|
|
subsystem_file->GetEntry(subsystem_name, "CollisionDamagePoints",
|
|
&subsystem_resource->armorByFacing[0]);
|
|
subsystem_file->GetEntry(subsystem_name, "BallisticDamagePoints",
|
|
&subsystem_resource->armorByFacing[1]);
|
|
subsystem_file->GetEntry(subsystem_name, "ExplosiveDamagePoints",
|
|
&subsystem_resource->armorByFacing[2]);
|
|
subsystem_file->GetEntry(subsystem_name, "LaserDamagePoints",
|
|
&subsystem_resource->armorByFacing[3]);
|
|
subsystem_file->GetEntry(subsystem_name, "EnergyDamagePoints",
|
|
&subsystem_resource->armorByFacing[4]);
|
|
|
|
Check_Fpu();
|
|
return True;
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// NoviceLockout -- the novice-experience lockout predicate (binary @4ac9c8):
|
|
// owner mech -> Entity::playerLink -> the BTPlayer's experience level == 0.
|
|
// Locks the advanced cockpit controls (condenser valves, coolant flush,
|
|
// cooling toggles). An unlinked mech reads UNLOCKED (dev-permissive).
|
|
//#############################################################################
|
|
//
|
|
Logical
|
|
MechSubsystem::NoviceLockout()
|
|
{
|
|
Check(this);
|
|
|
|
if (owner == NULL)
|
|
{
|
|
return False;
|
|
}
|
|
BTPlayer *player = Cast_Object(BTPlayer *, owner->GetPlayerLink());
|
|
if (player == NULL)
|
|
{
|
|
return False;
|
|
}
|
|
return (player->GetExperienceLevel() == BTMission::NoviceMode)
|
|
? True : False;
|
|
}
|