Implement original gadget panel and playable shrink ray

This commit is contained in:
UnixNight committed 2026-10-27 12:18:45 -04:00
1 parent 0272f7bef7
commit 7b5230ceb8
57 files changed
+3545 -48

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
using System.Numerics;
namespace GamePort.Game;
public readonly record struct GadgetCanvas(int Id, Vector2 Position);
/// <summary>Bounded group0 gadget panel; source425870/425EF0/425B20/427370.</summary>
public sealed class GadgetScreen(SceneInventory inventory)
{
public static IReadOnlyList<Vector2> Positions { get; } = Array.AsReadOnly<Vector2>([new(12,182), new(158,182), new(12,327), new(157,327),
new(342,182), new(487,182), new(342,327), new(487,327)]);
private static readonly int[] idle = [52,46,47,48,49,50,51,45];
private Vector2 pointerOffset;
public bool Open { get; private set; }
public bool PracticeArmed { get; private set; }
public int Hovered { get; private set; } = -1;
public event Action<int>? PracticeRequested;
public event Action? Changed;
//UI display3 is the default shrink-ray/jetpack; source equipped word is-1.
public static int EquippedMode(int displaySelection) => displaySelection == 3 ? -1 : displaySelection;
public bool Toggle(bool permitted)
{
if (Open) { Close(); return true; }
if (!permitted) return false;
if (EquippedMode(inventory.SelectedGadget) != -1)
{
inventory.SelectGadget(-1); Changed?.Invoke(); return true;
}
Open = true; Hovered = -1; PracticeArmed = false; pointerOffset = Vector2.Zero; Changed?.Invoke(); return true;
}
public void Close()
{
if (!Open) return;
Open = false; Hovered = -1; PracticeArmed = false; pointerOffset = Vector2.Zero; Changed?.Invoke();
}
public Vector2 MovePointer(Vector2 point, Vector2 axis, float seconds)
{
if (!float.IsFinite(seconds) || seconds < 0 || seconds >= 1) throw new ArgumentOutOfRangeException(nameof(seconds));
if (!Open) return point;
//404080: accumulated source80*dt offsets; neutral clears each axis.
pointerOffset.X = axis.X > .5f ? pointerOffset.X + 80 * seconds
: axis.X < -.5f ? pointerOffset.X - 80 * seconds : 0;
pointerOffset.Y = axis.Y > .5f ? pointerOffset.Y + 80 * seconds
: axis.Y < -.5f ? pointerOffset.Y - 80 * seconds : 0;
return point + pointerOffset;
}
public bool PracticeAvailable(string level, int task) => task < 500
&& !(level.Length == 4 && level.StartsWith("VR0", StringComparison.Ordinal) && level[3] is >= '1' and <= '8');
public void Point(Vector2 point, string level, int task)
{
Hovered = -1;
if (!Open) return;
for (var i = 0; i < Positions.Count; i++)
if (inventory.State(0,i) is not (0 or 4) && Inside(point,Positions[i],141,141)) Hovered = i;
if (PracticeAvailable(level,task) && Inside(point,new(487,95),141,78)) Hovered = 9;
if (Inside(point,new(12,95),141,78)) Hovered = 10;
}
public bool Activate(string level, int task)
{
if (!Open) return false;
if (Hovered == 10) { Close(); return true; }
if (Hovered == 9 && PracticeAvailable(level,task))
{ PracticeArmed = !PracticeArmed; Changed?.Invoke(); return true; }
if (Hovered is < 0 or > 7 || inventory.State(0,Hovered) is 0 or 4) return false;
var item = Hovered;
var practice = PracticeArmed;
Close();
inventory.SelectGadget(item);
if (practice) PracticeRequested?.Invoke(item);
return true;
}
public GadgetCanvas[] Canvases(string level, int task)
{
if (!Open) return [];
List<GadgetCanvas> result = [new(20,Vector2.Zero)];
for (var i = 0; i < Positions.Count; i++)
{
//Known route states0/1/4. Other nonzero states retain an owned tile;
//their complete inherited visibility is not claimed recovered here.
if (inventory.State(0,i) is 0 or 4) continue;
result.Add(new(Hovered == i && inventory.State(0,i) != 3 ? 11+i : idle[i],Positions[i]));
}
result.Add(new(Hovered == 10 ? 181 : 182,new(12,95)));
if (PracticeAvailable(level,task))
result.Add(new(Hovered == 9 || PracticeArmed ? 179 : 180,new(487,95)));
return result.ToArray();
}
private static bool Inside(Vector2 point, Vector2 start, float width, float height) =>
point.X > start.X && point.X < start.X + width && point.Y > start.Y && point.Y < start.Y + height;
}
+12 -4
View File
@@ -4,8 +4,8 @@ using GamePort.Assets;
namespace GamePort.Game;
public readonly record struct PlayerInput(bool Forward, bool Backward, bool Left, bool Right, bool Jump,
bool Rise = false, bool Descend = false, bool StrafeLeft = false, bool StrafeRight = false, bool Fast = false);
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly }
bool Rise = false, bool Descend = false, bool StrafeLeft = false, bool StrafeRight = false, bool Fast = false, bool Fire = false);
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly, Shoot }
/// <summary>
/// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in
@@ -39,6 +39,8 @@ public sealed class LabSimulation
//predates source-body integration; burst100 is not an interaction-only size.
public float InteractionRadius { get; private set; } = 60;
public bool JetpackEffectVisible { get; private set; }
public Action<PlayerInput>? InputActions { get; set; }
public bool Shooting { get; private set; }
public float JetpackRemaining => jumpState.EffectRemaining;
public int JumpState => jumpState.JumpState;
public float JumpHoldSeconds => jumpState.HoldSeconds;
@@ -59,7 +61,7 @@ public sealed class LabSimulation
public bool Grounded { get; private set; }
public PlayerPose Pose => Noclip ? Velocity.LengthSquared() > 0 ? PlayerPose.Fly : PlayerPose.Idle
: pendingImpulse.Y > 0 ? PlayerPose.Jump
: Grounded ? Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
: Grounded ? Shooting ? PlayerPose.Shoot : Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
: !forceFall && Velocity.Y > 0 ? PlayerPose.Jump : PlayerPose.Fall;
public int Steps { get; private set; }
@@ -113,6 +115,7 @@ public sealed class LabSimulation
lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0;
jumpState = default;
forceFall = JetpackEffectVisible = false;
Shooting = false;
InteractionRadius = 60; Bursts = 0;
Grounded = true;
Noclip = HasNoclipEntry = false;
@@ -168,7 +171,7 @@ public sealed class LabSimulation
StepPhysics();
if (controlled && !InputAfterPlayerUpdate) StepInput(input);
//42469F..4246DC reasserts ordinary grounded radius before ownership
//checks. The scooter's separate radius160 policy remains unimplemented.
//checks. Bubble mode0's separate radius160 policy remains unimplemented.
if (Grounded) InteractionRadius = 60;
//424BE0..424C34 runs this wrapper before437940's ownership gate.
StepCeiling();
@@ -187,6 +190,9 @@ public sealed class LabSimulation
Speed = 0; Velocity = Vector3.Zero;
}
public void StopForPrimaryFire() => Speed = 0;
public void SetShooting(bool shooting) => Shooting = shooting;
private void StepCeiling()
{
if (Velocity.Y <= 0 || ceilingRay == null
@@ -228,6 +234,7 @@ public sealed class LabSimulation
public void StopDebugMotion()
{
Shooting = false;
Velocity = pendingImpulse = Vector3.Zero;
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = lateralContribution = 0;
jumpState = default; movementMode = 0; forceFall = JetpackEffectVisible = false;
@@ -285,6 +292,7 @@ public sealed class LabSimulation
targetYaw = Yaw;
}
StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state.
InputActions?.Invoke(input);
}
private void StepPlayer(PlayerInput input)
+39
View File
@@ -0,0 +1,39 @@
using System.Numerics;
namespace GamePort.Game;
/// <summary>OMT2 vector::angles second output used by the original shrink ray.</summary>
public static class OriginalHeading
{
private static readonly ushort[] halfAcos = BuildHalfAcos();
public static float Degrees(Vector3 vector)
{
if (!float.IsFinite(vector.X) || !float.IsFinite(vector.Y) || !float.IsFinite(vector.Z))
throw new ArgumentOutOfRangeException(nameof(vector), "A finite direction is required.");
double x = vector.X, z = vector.Z;
if (x == 0 && z == 0) return 0;
// DLL1001FDCB..1001FE3D: truncate the squared ratio, table lookup,
// quadrant correction, negate and mask to the original 14-bit circle.
// Double intermediates approximate x87 extended precision; see findings.
int index = (int)(16384.0 * z * z / (x * x + z * z));
int angle = halfAcos[index];
if (z < 0)
angle = x < 0 ? 8192 + angle : 8192 - angle;
else if (x < 0)
angle = 16384 - angle;
return ((-angle) & 0x3fff) * 0.02197265625f;
}
private static ushort[] BuildHalfAcos()
{
var table = new ushort[16385];
// Stored DLL constants; final endpoint is explicitly zero at100EDD0D.
for (int i = 0; i < 16384; i++)
table[i] = (ushort)(Math.Acos(i * 0.0001220703125 - 1)
* 2607.5945876921437 * 0.5);
return table;
}
}
+5
View File
@@ -17,6 +17,8 @@ public sealed class PlayerSceneBinding : IDisposable
this.director = director; this.player = player; this.inventory = inventory; this.tag = tag;
director.ActorPreparing += Prepare;
director.AuthoredTransformChanged += Transform;
inventory.GadgetSelected += Selected;
Selected(inventory.SelectedGadget);
}
public bool Step(PlayerInput input)
@@ -42,6 +44,8 @@ public sealed class PlayerSceneBinding : IDisposable
}
}
private void Selected(int item) => player.GadgetMode = GadgetScreen.EquippedMode(item);
private void Transform(DirectorActor actor)
{
if (string.Equals(actor.Tag, tag, StringComparison.OrdinalIgnoreCase))
@@ -52,5 +56,6 @@ public sealed class PlayerSceneBinding : IDisposable
{
director.ActorPreparing -= Prepare;
director.AuthoredTransformChanged -= Transform;
inventory.GadgetSelected -= Selected;
}
}
+88
View File
@@ -0,0 +1,88 @@
using System.Numerics;
using GamePort.Assets;
namespace GamePort.Game;
/// <summary>First usable default shrink/jetpack device; special gadgets stay separate.</summary>
public sealed class SceneGadgets : IDisposable
{
private readonly LabSimulation player;
private readonly SceneInventory inventory;
private readonly OriginalScenePhysics physics;
private readonly OriginalCameraRay geometry;
private bool loop, busy;
public ShrinkRay Ray { get; } = new();
public IReadOnlyList<ShrinkSoldier> Soldiers { get; }
public int ShrinkHits { get; private set; }
public event Action<int, bool>? Sound;
public event Action? StopSound;
public event Action<int>? ScoreAwarded;
public SceneGadgets(SceneDirector director, SceneInventory inventory, LabSimulation player, Mesh world)
{
this.inventory = inventory; this.player = player;
//Static source registration game-filter is only recovered for the route.
geometry = OriginalCameraRay.FromRouteScene(world, player.LevelCode);
physics = new OriginalScenePhysics(world);
Soldiers = director.Actors.Where(a => a.Kind == "3SOL").Select(a => new ShrinkSoldier(a)).ToArray();
foreach (var soldier in Soldiers) soldier.Actor.Animation = "WALK";
player.InputActions += Input;
}
public void StepBodies(float seconds)
{
Ray.StepTexture(seconds);
foreach (var soldier in Soldiers) soldier.StepBody(physics, seconds);
}
public void StepTimers(float seconds)
{
foreach (var soldier in Soldiers) soldier.StepTimer(seconds);
}
private void Input(PlayerInput input)
{
if (!input.Fire) { busy = false; Stop(); return; }
if (busy || player.GadgetMode != -1) { Stop(); return; }
player.StopForPrimaryFire();
if (inventory.State(0,3) != 1)
{ Sound?.Invoke(117,false); busy = true; Stop(); return; }
//426937..426989: ordinary airborne FALL stops/hides the owned beam.
if (!player.Grounded && player.Pose == PlayerPose.Fall) { Stop(); return; }
player.SetShooting(player.Grounded);
if (!loop) { Sound?.Invoke(0,true); loop = true; }
const float dt = FixedStepClock.Step;
if (!(player.LevelCode.Length == 4 && player.LevelCode.StartsWith("VR0",StringComparison.Ordinal)
&& player.LevelCode[3] is >= '1' and <= '8')) player.Energy = Math.Clamp(player.Energy - dt,0,100);
//Bridge modern signed float yaw to the source's nonnegative Euler domain.
var yaw = (player.Yaw % 360 + 360) % 360;
var hits = Ray.Fire(player.ActorRoot,yaw,dt,
Soldiers.Select(s => new ShrinkCandidate(s.Actor.Tag,s.Actor.Position,Shrunk:s.Shrunk)),
(start,end) => geometry.TraceGeometry(start,end));
foreach (var tag in hits)
{
var soldier = Soldiers.First(s => s.Actor.Tag == tag);
soldier.Shrink(); ShrinkHits++;
//Ordinary3SOL callback42AD81 awards10, then publishes marker94C.
//Other enemy classes/special LIBBYPLANT/C3DDINO callbacks are separate.
if (!tag.Equals("LIBBYPLANT",StringComparison.OrdinalIgnoreCase)
&& !tag.Equals("C3DDINO",StringComparison.OrdinalIgnoreCase))
{ ScoreAwarded?.Invoke(10); soldier.MarkScoredHit(); }
}
}
public void Stop()
{
Ray.Hide(); player.SetShooting(false);
if (loop) StopSound?.Invoke();
loop = false;
}
public void Reset()
{
Stop(); busy = false; Ray.Reset(); ShrinkHits = 0;
foreach (var soldier in Soldiers) soldier.Reset();
}
public void Dispose() { player.InputActions -= Input; Stop(); }
}
+3 -2
View File
@@ -32,6 +32,7 @@ public sealed class SceneInteractions
public event Action<Vector3>? CheckpointCaptured;
public event Action<DirectorActor, string>? ConversationStarted;
public event Action<int>? ObjectiveChanged;
public void ChangeScore(int delta) => Score = Math.Max(0,unchecked(Score + delta));
public SceneInteractions(SceneDirector director, TaskStates tasks, OriginalSave save)
{
@@ -134,8 +135,8 @@ public sealed class SceneInteractions
private void CollectPickup(DirectorActor actor, GamEntity source, Vector3 playerRoot)
{
var id = source.Integer("PickupIndex", -1);
// The source tag is SHRINKRAY; original objective art120 calls this
// pickup the jet pack, matching group0/item3 and powered-jump ownership.
//Group0/item3 is the combined shrink ray/jetpack. Objective120 names its
//jetpack action; original gadget tile14 and controls113 also name SHRINK.
var jetpack = Equal(source.Tag, "SHRINKRAY");
var ordinaryStar = id is >= 3000 and < 4000 && source.Integer("PointValue") == 5;
if (id is <= 0 or >= OriginalSave.ItemCount || !(ordinaryStar || jetpack && source.Integer("PointValue") == 50)
+106
View File
@@ -0,0 +1,106 @@
using System.Numerics;
namespace GamePort.Game;
public readonly record struct ShrinkCandidate(string Tag, Vector3 Position, bool BodyEnabled = true,
bool ShrinkEnabled = true, bool Shrunk = false);
/// <summary>Ordinary owned-item3/mode-1 continuous426E40 scan, not a projectile.</summary>
public sealed class ShrinkRay
{
private float textureTime;
public int TexturePhase { get; private set; }
public bool Visible { get; private set; }
public Vector3 Position { get; private set; }
public float Yaw { get; private set; }
public void StepTexture(float seconds)
{
Seconds(seconds);
textureTime += seconds;
//Float accumulation compared with the source stored double0.1.
if ((double)textureTime <= .1) return;
TexturePhase = (TexturePhase + 1) % 3;
textureTime = 0;
}
public void Hide() => Visible = false;
public void Reset() { Visible = false; TexturePhase = 0; textureTime = 0; }
public IReadOnlyList<string> Fire(Vector3 root, float yaw, float seconds,
IEnumerable<ShrinkCandidate> candidates, Func<Vector3, Vector3, SupportHit?> wallQuery)
{
Seconds(seconds);
if (!float.IsFinite(yaw)) throw new ArgumentOutOfRangeException(nameof(yaw));
Visible = true; Position = root; Yaw = yaw;
List<string> hits = [];
foreach (var target in candidates)
{
if (!target.BodyEnabled || !target.ShrinkEnabled || target.Shrunk
|| target.Position.Y <= root.Y - 150 || target.Position.Y >= root.Y + 60) continue;
var difference = target.Position - root;
var distance = difference.Length();
if (distance >= 1500) continue;
var heading = OriginalHeading.Degrees(difference);
//No added angle-seam wrapping in the recovered comparison.
if (heading <= yaw - 5 || heading >= yaw + 5) continue;
var (sin, cos) = LabSimulation.Trig(yaw);
var start = root + Vector3.UnitY * 150;
var end = start + new Vector3(-sin * distance, 0, cos * distance);
if (wallQuery(start, end) != null) continue;
hits.Add(target.Tag);
}
return hits;
}
private static void Seconds(float seconds)
{
if (!float.IsFinite(seconds) || seconds < 0 || seconds >= 1)
throw new ArgumentOutOfRangeException(nameof(seconds));
}
}
/// <summary>Bounded original3SOL body settling and shrink state; combat/path AI remain open.</summary>
public sealed class ShrinkSoldier(DirectorActor actor)
{
public DirectorActor Actor { get; } = actor;
public Vector3 Velocity { get; private set; }
public bool Grounded { get; private set; }
public bool Shrunk { get; private set; }
public float Remaining { get; private set; }
public int AuthoredMode { get; } = actor.SourceGam?.Integer("AIState",2) ?? 2;
public int PreviousMode { get; private set; }
public int ShrinkRevision { get; private set; }
public float HitMarker { get; private set; }
public void MarkScoredHit() => HitMarker = 1;
public void Reset()
{
Velocity = Vector3.Zero; Grounded = Shrunk = false; Remaining = 0;
ShrinkRevision = 0; HitMarker = 0; Actor.Animation = "WALK";
}
public void StepBody(OriginalScenePhysics physics, float seconds)
{
var result = physics.Step(Actor.Position, Velocity, 90, 1, Grounded, seconds);
Actor.Position = result.Body.Position; Velocity = result.Body.Velocity; Grounded = result.Supported;
}
public void Shrink()
{
if (Shrunk) return;
PreviousMode = Actor.AIstate; Actor.AIstate = 5;
Actor.Animation = "SHRINK"; Remaining = 30; Shrunk = true; ShrinkRevision++;
}
public void StepTimer(float seconds)
{
if (!float.IsFinite(seconds) || seconds < 0 || seconds >= 1) throw new ArgumentOutOfRangeException(nameof(seconds));
if (!Shrunk || Remaining <= 0) return;
Remaining -= seconds;
//Source44AE85: exact zero does not expire and is skipped next tick.
if (Remaining >= 0) return;
Remaining = 0; Shrunk = false; HitMarker = 0;
PreviousMode = Actor.AIstate;
Actor.AIstate = AuthoredMode; Actor.Animation = "WALK"; Actor.Speed = 200;
}
}