Files
TeslaSuite/Console/TeslaConsole.BattleTech/BTMissionResults.cs
T
CydandClaude Fable 5 36166a95b0 BTGame pane + shell de-hardcode for multi-game pods (BT port phase 3)
BTGame mirrors RPGame - same GameStateData/state-machine/NetworkScan engine
driving each pod's MungaGame (take ownership, stream egg on WaitingForEgg,
Run/Abort/Stop, countdown) - with the BT differences: ApplicationID.BTL4, a
pilots grid carrying Mech/Camo/Patch/Badge/Experience, an Advanced Damage
checkbox in place of RP's Score Compression, and the Mech* in-match messages
recorded via BTMissionRecorder into BTMissionResults (.btm, gzip +
BinaryFormatter like .rpm; scores are 1000-based like RP). Free For All and
No Return share the pane; the mode selects the pilots' role. BTDefaults
persists per-mode operator defaults to BTDefaults.btd (no dialog yet).
RPGame's dead decompile members (sStopToIdleStates, IsAllPodsAppState) were
not carried over.

TeslaConsoleForm no longer assumes RP: the "AppID != 0 -> Pod Not Running RP"
check becomes a GameTag map (RPL4 -> RP, BTL4 -> BT, otherwise Unknown Pod
Application) feeding the per-game status strings, and the Games menu gains
BattleTech: Free For All / No Return.

Deferred to phase 4: mech/arena art, BT defaults dialog, BT score-sheet
print document, Apps.xml BT411 product, live-pod verification.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 22:29:20 -05:00

108 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization.Formatters.Binary;
namespace TeslaConsole.BattleTech;
/// <summary>
/// The recorded outcome of one BattleTech mission, saved as a gzip'd
/// BinaryFormatter blob (.btm) exactly like the RP .rpm mechanism. Mirrors
/// <c>RPMissionResults</c> minus the football branches; the score-sheet print
/// document (RPPrintDocument's counterpart) is deferred until a real BT match
/// has been recorded to design it against.
/// </summary>
[Serializable]
internal class BTMissionResults
{
private BTMission mMission;
internal DateTime mMissionStart;
internal TimeSpan mActuallMissionTime;
internal readonly List<BTMissionEvent> mEvents = new List<BTMissionEvent>();
internal readonly Dictionary<BTPlayer, int> mFinalScores = new Dictionary<BTPlayer, int>();
public BTMission Mission => mMission;
public DateTime MissionStart => mMissionStart;
public TimeSpan ActuallMissionTime => mActuallMissionTime;
public IEnumerable<BTMissionEvent> Events => mEvents;
internal BTMissionResults(BTMission mission)
{
mMission = mission;
}
public static string GetBTMissionsDirectory()
{
string text = Path.Combine(Program.GetCommonAppDataDirectory(), "BT Missions");
if (!Directory.Exists(text))
{
Directory.CreateDirectory(text);
}
return text;
}
public static BTMissionResults Load(string file)
{
using GZipStream gZipStream = new GZipStream(File.OpenRead(file), CompressionMode.Decompress);
BinaryFormatter binaryFormatter = new BinaryFormatter();
BTMissionResults result = (BTMissionResults)binaryFormatter.Deserialize(gZipStream);
gZipStream.Close();
return result;
}
public void Save()
{
string path = Path.Combine(GetBTMissionsDirectory(), mMissionStart.ToString("yyyy-MM-dd HH-mm-ss.ffff") + ".btm");
using GZipStream gZipStream = new GZipStream(File.OpenWrite(path), CompressionMode.Compress);
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(gZipStream, this);
gZipStream.Close();
}
public int GetScore(BTPlayer player)
{
return GetScore(player, TimeSpan.MaxValue);
}
public int GetScore(BTPlayer player, TimeSpan gameTime)
{
if (gameTime == TimeSpan.MaxValue && mFinalScores.ContainsKey(player))
{
return mFinalScores[player];
}
int result = 1000;
TimeSpan timeSpan = TimeSpan.MinValue;
foreach (BTMissionEvent mEvent in mEvents)
{
if (mEvent is BTScoreUpdateEvent && mEvent.ReportingPilot == player && mEvent.GameTime > timeSpan && mEvent.GameTime <= gameTime)
{
result = ((BTScoreUpdateEvent)mEvent).Score;
timeSpan = mEvent.GameTime;
}
}
return result;
}
public int GetFinalPlace(BTPlayer player)
{
int num = 1;
int score = GetScore(player, TimeSpan.MaxValue);
foreach (BTPlayer player2 in mMission.Players)
{
if (player2 != player && GetScore(player2, TimeSpan.MaxValue) > score)
{
num++;
}
}
return num;
}
}