The subsystem-family cockpit buttons now work through the authentic Receiver dispatch -> per-class handler-table path. The id space decodes cleanly: Receiver::NextMessageID == 3, so ToggleCooling = 3 on the HeatSink chain and the per-class id 4 is MoveValve on a Condenser / InjectCoolant on the Reservoir -- same number, different class, the binary's per-receiver-class convention. - HeatSink::ToggleCoolingMessageHandler (@004ad6f8, id 3): novice-locked, press-only; toggles coolantAvailable + coolantFlowScale together. - Condenser::MoveValveMessageHandler (@4ae464, id 4): novice-locked; cycles the valve 1->5->50->0->1 and calls Condenser::RecomputeValves (@0049f788): every condenser's coolantFlowScale = valve / sum-of-valves. The ctor now streams the AUTHENTIC flowScale=0; the Mech ctor seeds equal shares once at spawn -- the flowScale=1 interim is retired. - Reservoir::InjectCoolantMessageHandler (@4aee70, id 4): novice-locked; press arms the flush when the tank holds charge, release drops it. - MechSubsystem::NoviceLockout() (@4ac9c8): owner -> playerLink -> experience == novice; unlinked mechs read unlocked. - DEV harness BT_PRESS_VALVE / BT_PRESS_FLUSH: dispatch the REAL messages ~6s into the mission from Mech::Simulate. VERIFIED: spawn shares 6 x 0.166667; one MoveValve press -> Condenser1 valve=5 flow=0.5, others 0.1 (valve/sum exact); flush arms via the real button message; NOVICE locks both presses (valve lines stay spawn-only, zero flush). Zero Fail throughout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
253 lines
7.2 KiB
C++
253 lines
7.2 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"
|
|
);
|
|
|
|
MechSubsystem::SharedData
|
|
MechSubsystem::DefaultData(
|
|
MechSubsystem::ClassDerivations,
|
|
Subsystem::MessageHandlers,
|
|
Subsystem::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);
|
|
|
|
damageZone = new DamageZone(owner, GetSegmentIndex());
|
|
Register_Object(damageZone);
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
//#############################################################################
|
|
//
|
|
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);
|
|
statusAlarm.SetLevel(MechSubsystem::Destroyed);
|
|
if (damageZone)
|
|
{
|
|
damageZone->SetDamageZoneState(DamageZone::BurningState);
|
|
}
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// 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).
|
|
//#############################################################################
|
|
//
|
|
int
|
|
MechSubsystem::CreateStreamedSubsystem(
|
|
NotationFile *,
|
|
const char *,
|
|
const char *,
|
|
SubsystemResource *,
|
|
NotationFile *,
|
|
const ResourceDirectories *,
|
|
int
|
|
)
|
|
{
|
|
Fail("MechSubsystem::CreateStreamedSubsystem -- mechsub.cpp not yet reconstructed");
|
|
return 0;
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// 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;
|
|
}
|