Files
BT411/engine/MUNGA/PLUG.cpp
arcattackandClaude Opus 4.8 7b7d465e5e Initial commit: bt411 -- standalone Windows BattleTech (Tesla 4.10 port)
Clean, self-contained extraction of the BattleTech-specific work from the
reverse-engineering workspace -- engine + game + content + build, with nothing
from Red Planet or the raw archive dumps. Builds green (Win32) and runs the
single-player drive->animate->target->fire->damage->destroy loop out of the box.

Layout:
  engine/   MUNGA + MUNGA_L4 shared 2007 engine, carrying our BT render/loader
            work (bgfload/L4D3D/L4VIDEO: BSL bit-slice decode, LOD/ground/shadow
            models) + image codec; the minimal rp/ headers the audio HAL needs
  game/     reconstructed BT logic + surviving-original BT source + fwd shims
            + WinMain launcher
  content/  full runtime tree (BTL4.RES, VIDEO/, GAUGE/, AUDIO/, eggs, BTDPL.INI)
  docs/     format specs + reconstruction ledgers
  reference/ raw Ghidra pseudocode (recon source-of-truth) + decomp exporter
  tools/    MP console emulator + map/resource scanners

One top-level CMake builds munga_engine lib + bt410_l4 game lib + btl4.exe.
All paths relativized (186 fwd shims + ~437 CMake abs paths -> repo-relative);
DXSDK is the one external, overridable via -DDXSDK. Verified: builds to a
byte-identical 2.27MB exe and runs combat (TARGET DESTROYED, 0 crashes) against
the bundled content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-05 21:03:40 -05:00

491 lines
9.3 KiB
C++

#include "munga.h"
#pragma hdrstop
#include "plug.h"
#include "objstrm.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Plug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//#############################################################################
// Plug
//#############################################################################
//
Plug::Plug(ClassID class_id):
RegisteredClass(class_id)
{
linkHead = NULL;
}
//
//#############################################################################
// Plug
//#############################################################################
//
Plug::Plug(PlugStream *stream):
RegisteredClass(stream)
{
linkHead = NULL;
}
//
//###########################################################################
// ~Plug
//###########################################################################
//
Plug::~Plug()
{
while (linkHead != NULL)
{
Unregister_Object(linkHead);
delete(linkHead);
}
}
//
//###########################################################################
// TestInstance
//###########################################################################
//
Logical
Plug::TestInstance() const
{
if (linkHead != NULL)
{
Check(linkHead);
}
return True;
}
//
//#############################################################################
// ReceivePlugCommand
//#############################################################################
//
// Considering removal
#if 0
int
Plug::ReceivePlugCommand(
Plug::CommandID,
void*
)
{
return 0;
}
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugIterator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//#############################################################################
// PlugIterator
//#############################################################################
//
PlugIterator::PlugIterator(
const Plug *plug,
RegisteredClass::ClassID class_to_iterate
)
{
Check(plug);
this->plug = plug;
classToIterate = class_to_iterate;
currentLink = plug->linkHead;
}
PlugIterator::PlugIterator(const PlugIterator &iterator)
{
Check(&iterator);
plug = iterator.plug;
classToIterate = iterator.classToIterate;
currentLink = iterator.currentLink;
}
//
//#############################################################################
// PlugIterator
//#############################################################################
//
PlugIterator::~PlugIterator()
{
}
//
//###########################################################################
// TestInstance
//###########################################################################
//
Logical
PlugIterator::TestInstance() const
{
if (currentLink != NULL)
{
Check(currentLink);
}
return True;
}
//
//###########################################################################
// First
//###########################################################################
//
void
PlugIterator::First()
{
Check(plug);
currentLink = plug->linkHead;
NextNode();
}
//
//###########################################################################
// Last
//###########################################################################
//
void
PlugIterator::Last()
{
if (currentLink == NULL)
{
Check(plug);
if ((currentLink = plug->linkHead) == NULL)
return;
}
Check(currentLink);
while(currentLink->nextLink != NULL)
{
currentLink = currentLink->nextLink;
Check(currentLink);
}
PreviousNode();
}
//
//###########################################################################
// Next
//###########################################################################
//
void
PlugIterator::Next()
{
Check(currentLink);
currentLink = currentLink->nextLink;
NextNode();
}
//
//###########################################################################
// Previous
//###########################################################################
//
void
PlugIterator::Previous()
{
Check(currentLink);
currentLink = currentLink->prevLink;
PreviousNode();
}
//
//###########################################################################
// ReadAndNextImplementation
//###########################################################################
//
void*
PlugIterator::ReadAndNextImplementation()
{
if (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
node = currentLink->socket->GetReleaseNode();
currentLink = currentLink->nextLink;
NextNode();
return node;
}
return NULL;
}
//
//###########################################################################
// ReadAndPreviousImplementation
//###########################################################################
//
void*
PlugIterator::ReadAndPreviousImplementation()
{
if (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
node = currentLink->socket->GetReleaseNode();
currentLink = currentLink->prevLink;
PreviousNode();
return node;
}
return NULL;
}
//
//###########################################################################
// GetCurrentImplementation
//###########################################################################
//
void*
PlugIterator::GetCurrentImplementation()
{
if (currentLink != NULL)
{
Check(currentLink);
Check(currentLink->socket);
return currentLink->socket->GetReleaseNode();
}
return NULL;
}
//
//###########################################################################
// GetSize
//###########################################################################
//
#if 0
CollectionSize
PlugIterator::GetSize()
{
Link *link;
CollectionSize count;
Check(plug);
count = 0;
for
(
link = plug->linkHead;
link != NULL;
link = link->nextLink
)
{
Check(link);
Check(link->socket);
if (link->socket->GetReleaseNode() != NULL)
count++;
}
return count;
}
#else
CollectionSize
PlugIterator::GetSize()
{
CollectionSize i = 0;
First();
while (GetCurrentImplementation() != NULL)
{
i++;
Next();
}
return i;
}
#endif
//
//###########################################################################
// GetNthImplementation
//###########################################################################
//
#if 0
void*
PlugIterator::GetNthImplementation(
CollectionSize index
)
{
Link *link;
CollectionSize count;
Check(plug);
count = 0;
for
(
link = plug->linkHead;
link != NULL;
link = link->nextLink
)
{
Check(link);
if (count == index) {
currentLink = link;
Check(currentLink);
Check(currentLink->socket);
return currentLink->socket->GetReleaseNode();
}
count++;
}
return NULL;
}
#else
void*
PlugIterator::GetNthImplementation(
CollectionSize index
)
{
CollectionSize i = 0;
void *item;
First();
while ((item = GetCurrentImplementation()) != NULL)
{
if (i == index)
return item;
Next();
i++;
}
return NULL;
}
#endif
//
//###########################################################################
// NextNode
//###########################################################################
//
void
PlugIterator::NextNode()
{
while (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
if ((node = currentLink->socket->GetReleaseNode()) != NULL)
{
Check(node);
if (
node->GetClassID() == classToIterate ||
classToIterate == RegisteredClass::NullClassID
)
{
return;
}
}
currentLink = currentLink->nextLink;
}
return;
}
//
//###########################################################################
// PreviousNode
//###########################################################################
//
void
PlugIterator::PreviousNode()
{
while (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
if ((node = currentLink->socket->GetReleaseNode()) != NULL)
{
Check(node);
if (
node->GetClassID() == classToIterate ||
classToIterate == RegisteredClass::NullClassID
)
{
return;
}
}
currentLink = currentLink->prevLink;
}
return;
}
//
//###########################################################################
// Remove
//###########################################################################
//
void
PlugIterator::Remove()
{
Link *old_link;
Check(currentLink);
old_link = currentLink;
currentLink = currentLink->nextLink;
Unregister_Object(old_link);
delete old_link;
}
//
//#############################################################################
// SendNodeCommand
//#############################################################################
//
int
PlugIterator::SendNodeCommand(
NodeCommandID node_command,
void *info
)
{
int ret;
Node *node;
First();
while ((node = (Node *)GetCurrentImplementation()) != NULL)
{
Check(node);
if ((ret = node->ReceiveNodeCommand(node_command, info)) != 0)
return ret;
Next();
}
return 0;
}
//
//###########################################################################
// RemoveSocket
//###########################################################################
//
void
PlugIterator::RemoveSocket(Socket *socket)
{
Link *link;
Check(socket);
Check(plug);
for
(
link = plug->linkHead;
link != NULL;
link = link->nextLink
)
{
Check(link);
if (link->GetSocket() == socket)
{
currentLink = link->nextLink;
Unregister_Object(link);
delete link;
return;
}
}
}