Reconstruct lab story, interactions, patrol and jet pack practice flow
This commit is contained in:
1 parent
58424120bb
commit
c929f942e1
84 files changed
+7957
-305
No files matched your search
@@ -0,0 +1,527 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Assets;
|
||||
|
||||
namespace GamePort.Game;
|
||||
|
||||
/// <summary>Mutable source-entity state for the reconstructed trigger/camera interpreter.</summary>
|
||||
public sealed class DirectorActor
|
||||
{
|
||||
public GamEntity? SourceGam { get; }
|
||||
public string Tag { get; }
|
||||
public string Kind { get; }
|
||||
public bool ConstructorCreated => SourceGam is null;
|
||||
public Vector3 Position { get; internal set; }
|
||||
public Vector3 Rotation { get; internal set; }
|
||||
public bool Visible { get; internal set; }
|
||||
public bool Active { get; internal set; }
|
||||
public string Animation { get; internal set; } = "STOP";
|
||||
public int AIstate { get; internal set; }
|
||||
public float Speed { get; internal set; }
|
||||
public string? Patrol { get; internal set; }
|
||||
public int SpriteRevision { get; internal set; }
|
||||
public bool SpritePlaying { get; internal set; }
|
||||
|
||||
internal DirectorActor(GamEntity? source, string tag, string kind, Vector3 position)
|
||||
{
|
||||
SourceGam = source; Tag = tag; Kind = kind; Position = position;
|
||||
Rotation = source?.Rotation ?? Vector3.Zero;
|
||||
Visible = source?.Integer("InitiallyVisible", -1) != 0;
|
||||
Active = source?.Integer("InitallyActive", source?.Integer("Activated", 1) ?? 1) != 0;
|
||||
if (kind == "3PIC") Visible = Active;
|
||||
AIstate = source?.Integer("AIState", kind == "3DOG" ? 4 : 0) ?? (kind == "3DOG" ? 4 : 0);
|
||||
Speed = kind switch { "3CAR" => 200, "3DOG" => 1, _ => 0 }; // EXE413BCB /41C8FA.
|
||||
if (kind == "3DOG") Animation = "none"; // Initial pose selection is not recovered; no fabricated STOP alias.
|
||||
Patrol = source?.Text("PatrolPoint");
|
||||
SpritePlaying = (source?.Integer("Activated") ?? 0) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record DirectorIssue(string Tag, string Kind, string Detail);
|
||||
|
||||
/// <summary>
|
||||
/// Recovered synchronous AI-trigger dispatch and audio-duration-driven CAM/MCA
|
||||
/// sequence. See lab-progression.md. Actor physics/AI, sprites, inventory effects
|
||||
/// and fades remain separate consumers; unsupported execution is reported.
|
||||
/// </summary>
|
||||
public sealed class SceneDirector
|
||||
{
|
||||
private readonly GamLevel level;
|
||||
private readonly TaskStates tasks;
|
||||
private readonly Func<string, int, double> soundDuration;
|
||||
private readonly Dictionary<string, GamEntity> entities = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, DirectorActor> actors = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<int, int> activations = [];
|
||||
private readonly Queue<(string Tag, string? Caller)> pending = [];
|
||||
private readonly List<DirectorIssue> issues = [];
|
||||
private readonly HashSet<string> reported = new(StringComparer.Ordinal);
|
||||
private readonly HashSet<string> patrolConsumers = new(StringComparer.OrdinalIgnoreCase);
|
||||
private Shot? shot;
|
||||
private bool draining, skipping;
|
||||
private string? blockedNext, blockedCaller;
|
||||
|
||||
private sealed class Shot(GamEntity source, int index, DirectorActor target, double duration)
|
||||
{
|
||||
public GamEntity Source { get; } = source;
|
||||
public int Index { get; } = index; // -1 for a single CAM.
|
||||
public DirectorActor Target { get; } = target;
|
||||
public double Duration { get; } = duration;
|
||||
public double Elapsed { get; set; }
|
||||
}
|
||||
|
||||
public List<DirectorActor> Actors { get; } = [];
|
||||
public IReadOnlyList<DirectorIssue> Issues => issues;
|
||||
public bool Controlled => Equal(ControlledTag, level.Player?.Tag);
|
||||
public string? ControlledTag { get; private set; }
|
||||
public bool InventoryEnabled { get; private set; } = true;
|
||||
public bool Blocked { get; private set; }
|
||||
public bool Playing => shot is not null;
|
||||
public string? CurrentTag => shot?.Source.Tag;
|
||||
public int CurrentShot => shot?.Index ?? -1;
|
||||
public Vector3? CameraEye { get; private set; }
|
||||
public Vector3? CameraTarget { get; private set; }
|
||||
public event Action<string, int>? Speech;
|
||||
public event Action<DirectorActor>? ActorChanged;
|
||||
public event Action<string, string>? Unsupported;
|
||||
|
||||
public SceneDirector(GamLevel level, TaskStates tasks, Func<string, int, double> soundDuration)
|
||||
{
|
||||
this.level = level;
|
||||
this.tasks = tasks;
|
||||
this.soundDuration = soundDuration;
|
||||
foreach (var entity in level.Entities)
|
||||
{
|
||||
if (entity.Tag is not { Length: > 0 } tag) continue;
|
||||
// Original tag lookup scans in object-list order and returns the first.
|
||||
entities.TryAdd(tag, entity);
|
||||
var actor = new DirectorActor(entity, tag, entity.Kind, entity.Position);
|
||||
Actors.Add(actor);
|
||||
actors.TryAdd(tag, actor);
|
||||
}
|
||||
// Jimmy creates Goddard in EXE423C98->41C810, independently of GAM.
|
||||
// LV1B's explicit SITGODDARD command positions him at gstart before his
|
||||
// first shot. This initial binding is a documented placement inference.
|
||||
if (!actors.ContainsKey("C3DGODDARD") && entities.TryGetValue("gstart", out var goddardStart))
|
||||
{
|
||||
var goddard = new DirectorActor(null, "C3DGODDARD", "3DOG", goddardStart.Position);
|
||||
Actors.Add(goddard);
|
||||
actors.Add(goddard.Tag, goddard);
|
||||
}
|
||||
ControlledTag = level.Player?.Tag;
|
||||
foreach (var actor in Actors) ApplyTask(actor, tasks.Get(actor.SourceGam?.Text("TaskName")));
|
||||
tasks.Assigned += OnTaskAssigned;
|
||||
}
|
||||
|
||||
public void Begin(GamEntity start)
|
||||
{
|
||||
if (start.Kind != "STRT") throw new ArgumentException("Expected original STRT entity", nameof(start));
|
||||
shot = null; pending.Clear(); activations.Clear();
|
||||
Blocked = skipping = false; blockedNext = blockedCaller = null;
|
||||
CameraEye = CameraTarget = null;
|
||||
InventoryEnabled = true;
|
||||
foreach (var actor in Actors)
|
||||
{
|
||||
if (actor.SourceGam is not { } source) continue;
|
||||
var initial = new DirectorActor(source, actor.Tag, actor.Kind, source.Position);
|
||||
actor.Position = initial.Position; actor.Rotation = initial.Rotation;
|
||||
actor.Visible = initial.Visible; actor.Active = initial.Active;
|
||||
actor.Animation = initial.Animation; actor.AIstate = initial.AIstate;
|
||||
actor.Speed = initial.Speed; actor.Patrol = initial.Patrol;
|
||||
actor.SpritePlaying = initial.SpritePlaying; actor.SpriteRevision++;
|
||||
ApplyTask(actor, tasks.Get(source.Text("TaskName")));
|
||||
}
|
||||
var trigger = start.Text("StartTrigger");
|
||||
ControlledTag = IsNone(trigger) ? level.Player?.Tag : null; // EXE4426B7.
|
||||
if (!IsNone(trigger)) Trigger(trigger!, start.Tag);
|
||||
}
|
||||
|
||||
public void Trigger(string tag, string? callerTag = null)
|
||||
{
|
||||
if (tag.Length > 100) throw new ArgumentException("Trigger tag exceeds original field size", nameof(tag));
|
||||
pending.Enqueue((tag, callerTag));
|
||||
Drain();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Port contact query: point against the source trigger radius. Original
|
||||
/// collision callback selection/radius combination is not yet reproduced.
|
||||
/// The actual AI trigger's actor, animation and task-child checks are retained.
|
||||
/// </summary>
|
||||
public void Touch(string activatorTag, Vector3 position)
|
||||
{
|
||||
if (!Finite(position)) throw new ArgumentOutOfRangeException(nameof(position));
|
||||
foreach (var entity in level.Entities)
|
||||
{
|
||||
if (entity.Kind != "3AIT" || entity.Integer("TouchActivated") == 0) continue;
|
||||
var radius = entity.Number("Radius");
|
||||
if (radius < 0 || Vector3.DistanceSquared(position, entity.Position) > radius * radius) continue;
|
||||
if (entity.Tag is { } tag) pending.Enqueue((tag, activatorTag));
|
||||
}
|
||||
Drain();
|
||||
}
|
||||
|
||||
public DirectorActor? FindActor(string tag) => actors.GetValueOrDefault(tag);
|
||||
|
||||
public void RegisterPatrolConsumer(string tag) => patrolConsumers.Add(tag);
|
||||
|
||||
public void SyncActor(string tag, Vector3 position, Vector3 rotation)
|
||||
{
|
||||
if (!Finite(position) || !Finite(rotation)) throw new ArgumentOutOfRangeException(nameof(position));
|
||||
if (!actors.TryGetValue(tag, out var actor)) return;
|
||||
actor.Position = position; actor.Rotation = rotation;
|
||||
if (shot is not null) UpdateCamera(shot);
|
||||
}
|
||||
|
||||
public void Step(float dt)
|
||||
{
|
||||
if (!float.IsFinite(dt) || dt < 0 || dt > 1) throw new ArgumentOutOfRangeException(nameof(dt));
|
||||
foreach (var actor in Actors)
|
||||
if (actor.Kind == "3TRO") actor.Rotation = actor.Rotation with { Y = (actor.Rotation.Y + dt * 90) % 360 };
|
||||
var remaining = (double)dt;
|
||||
for (var count = 0; count < 256 && shot is not null; count++)
|
||||
{
|
||||
var current = shot;
|
||||
var untilEnd = Math.Max(0, current.Duration - current.Elapsed);
|
||||
var consumed = Math.Min(remaining, untilEnd);
|
||||
current.Elapsed += consumed;
|
||||
remaining -= consumed;
|
||||
UpdateCamera(current);
|
||||
if (current.Elapsed + 1e-8 < current.Duration) return;
|
||||
FinishShot(current);
|
||||
if (remaining <= 0 && (shot is null || shot.Duration > 0)) return;
|
||||
}
|
||||
if (shot is not null && shot.Duration <= 0)
|
||||
Block(shot.Source, "Zero-duration scene sequence exceeded bounded dispatch", shot.Source.Text("NextTrigger"));
|
||||
}
|
||||
|
||||
/// <summary>Escape/Space original chain skip: preserve AI/toggle actions and skip remaining speech/shots.</summary>
|
||||
public void Skip()
|
||||
{
|
||||
skipping = true;
|
||||
if (Blocked)
|
||||
{
|
||||
Blocked = false;
|
||||
if (blockedNext is { } next) pending.Enqueue((next, blockedCaller));
|
||||
blockedNext = blockedCaller = null;
|
||||
}
|
||||
if (shot is { } current)
|
||||
{
|
||||
shot = null;
|
||||
DeactivateAnimation(current);
|
||||
if (current.Index >= 0) FinishMulti(current.Source);
|
||||
else EnqueueNext(current.Source);
|
||||
}
|
||||
Drain();
|
||||
}
|
||||
|
||||
private void Drain()
|
||||
{
|
||||
if (draining || Blocked) return;
|
||||
draining = true;
|
||||
var visited = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
try
|
||||
{
|
||||
for (var count = 0; pending.Count > 0 && !Blocked; count++)
|
||||
{
|
||||
var (tag, caller) = pending.Dequeue();
|
||||
if (IsNone(tag)) continue;
|
||||
if (Equal(tag, "default")) { RestoreControl(); continue; }
|
||||
if (count >= 256 || !visited.Add(tag))
|
||||
{
|
||||
Report(tag, "cycle", "Synchronous trigger cycle or dispatch limit");
|
||||
pending.Clear(); Blocked = true; return;
|
||||
}
|
||||
if (!entities.TryGetValue(tag, out var entity))
|
||||
{
|
||||
Report(tag, "missing", "Trigger target absent from original GAM");
|
||||
Blocked = true; return;
|
||||
}
|
||||
switch (entity.Kind)
|
||||
{
|
||||
case "3AIT": ExecuteAi(entity, caller); break;
|
||||
case "3CAM": StartCamera(entity, -1); break;
|
||||
case "3MCA": StartMulti(entity); break;
|
||||
default: Block(entity, "Trigger class execution not recovered", entity.Text("NextTrigger")); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { draining = false; }
|
||||
}
|
||||
|
||||
private void ExecuteAi(GamEntity entity, string? caller)
|
||||
{
|
||||
var by = entity.Text("ActivateBy");
|
||||
var isA = entity.Text("IsA");
|
||||
var matchesActor = !IsNone(by) && Equal(by, caller);
|
||||
if (!IsNone(isA))
|
||||
{
|
||||
Report(entity.Tag!, entity.Kind, "IsA predicate requires original class hierarchy; trigger not executed");
|
||||
return;
|
||||
}
|
||||
if (!IsNone(by) && !matchesActor) return;
|
||||
var byAnimation = entity.Text("ActivateByAnim");
|
||||
if (!IsNone(byAnimation) && (!actors.TryGetValue(caller ?? "", out var callerActor)
|
||||
|| !Equal(byAnimation, callerActor.Animation))) return;
|
||||
var times = entity.Integer("TimesToTrigger", -1);
|
||||
var number = activations.GetValueOrDefault(entity.Offset) + 1;
|
||||
activations[entity.Offset] = number;
|
||||
if (times != -1 && number > times) return;
|
||||
SetControl(entity);
|
||||
|
||||
var targetTag = entity.Text("AITarget");
|
||||
if (!IsNone(targetTag))
|
||||
{
|
||||
if (!actors.TryGetValue(targetTag!, out var target))
|
||||
Report(entity.Tag!, entity.Kind, $"AI target {targetTag} absent");
|
||||
else
|
||||
{
|
||||
var hide = entity.Integer("AIHideObj", -1);
|
||||
if (hide != -1) target.Visible = hide == 0;
|
||||
var positionTag = entity.Text("AINewPos");
|
||||
if (!IsNone(positionTag))
|
||||
{
|
||||
if (actors.TryGetValue(positionTag!, out var marker)) target.Position = marker.Position;
|
||||
else Report(entity.Tag!, entity.Kind, $"AINewPos {positionTag} absent");
|
||||
}
|
||||
var animation = entity.Text("AIAnim");
|
||||
if (!IsNone(animation)) target.Animation = animation!;
|
||||
target.AIstate = entity.Integer("AIState", target.AIstate);
|
||||
var speed = entity.Integer("AISpeed", -1);
|
||||
if (speed != -1) target.Speed = speed;
|
||||
var patrol = entity.Text("AIPatrol");
|
||||
if (!IsNone(patrol)) target.Patrol = patrol;
|
||||
var yaw = entity.Number("AINewRotY", -1);
|
||||
if (yaw != -1) target.Rotation = target.Rotation with { Y = yaw };
|
||||
ActorChanged?.Invoke(target);
|
||||
if (target.AIstate == 3 && (target.Kind is "3DOG" or "3CAR") && !patrolConsumers.Contains(target.Tag))
|
||||
Report(target.Tag, target.Kind, "Patrol motion/arrival is not yet reconstructed; actor-state callback emitted");
|
||||
}
|
||||
}
|
||||
Toggle(entity);
|
||||
var conditional = ConditionalChild(entity);
|
||||
// EXE40CB43: the nearby teleport explanation advances the task before its camera chain.
|
||||
if (Equal(entity.Tag, "teleportexplanation") && tasks.Get("SCENE") is 30 or 31)
|
||||
tasks.SetExisting("SCENE", 35);
|
||||
pending.Enqueue((conditional ?? entity.Text("NextTrigger") ?? "none", entity.Tag));
|
||||
}
|
||||
|
||||
private string? ConditionalChild(GamEntity entity)
|
||||
{
|
||||
var state = tasks.Get(entity.Text("TaskName"));
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
var desired = entity.Integer($"ActivateState{i}", -1);
|
||||
var target = entity.Text($"ActivateObject{i}");
|
||||
if (desired != -1 && desired == state && !IsNone(target) && entities.ContainsKey(target!)) return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void StartMulti(GamEntity entity)
|
||||
{
|
||||
SetControl(entity);
|
||||
Toggle(entity);
|
||||
if (skipping) { FinishMulti(entity); return; }
|
||||
StartCamera(entity, 0, applyCommon: false);
|
||||
}
|
||||
|
||||
private void StartCamera(GamEntity entity, int index, bool applyCommon = true)
|
||||
{
|
||||
if (applyCommon) { SetControl(entity); Toggle(entity); }
|
||||
if (entity.Integer("DeactivateInv") != 0) InventoryEnabled = false;
|
||||
if (skipping)
|
||||
{
|
||||
if (index >= 0) FinishMulti(entity);
|
||||
else EnqueueNext(entity);
|
||||
return;
|
||||
}
|
||||
var suffix = index < 0 ? "" : index.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
var targetTag = entity.Text("CameraTarget" + suffix);
|
||||
var sound = entity.Integer("SoundIndex" + suffix, -1);
|
||||
if (index >= 8 || IsNone(targetTag) || sound == -1)
|
||||
{
|
||||
if (index >= 0) FinishMulti(entity);
|
||||
else Block(entity, "CAM target/sound unavailable", entity.Text("NextTrigger"));
|
||||
return;
|
||||
}
|
||||
if (!actors.TryGetValue(targetTag!, out var target))
|
||||
{
|
||||
Block(entity, $"Camera target {targetTag} absent", entity.Text("NextTrigger"));
|
||||
return;
|
||||
}
|
||||
var database = entity.Text("SoundDatabase") ?? "none";
|
||||
var duration = soundDuration(database, sound);
|
||||
if (!double.IsFinite(duration) || duration < 0)
|
||||
{
|
||||
Block(entity, $"Missing original sound duration {database}:{sound}", entity.Text("NextTrigger"));
|
||||
return;
|
||||
}
|
||||
var animation = entity.Text(index < 0 ? "TargetActAnim" : "TargetAnim" + suffix);
|
||||
if (!IsNone(animation)) { target.Animation = animation!; ActorChanged?.Invoke(target); }
|
||||
shot = new Shot(entity, index, target, duration);
|
||||
UpdateCamera(shot);
|
||||
Speech?.Invoke(database, sound);
|
||||
}
|
||||
|
||||
private void FinishShot(Shot current)
|
||||
{
|
||||
if (shot != current) return;
|
||||
shot = null;
|
||||
DeactivateAnimation(current);
|
||||
if (current.Index < 0) EnqueueNext(current.Source);
|
||||
else StartCamera(current.Source, current.Index + 1, applyCommon: false);
|
||||
Drain();
|
||||
}
|
||||
|
||||
private void DeactivateAnimation(Shot current)
|
||||
{
|
||||
var animation = current.Source.Text("TargetDeactAnim");
|
||||
if (!IsNone(animation))
|
||||
{
|
||||
current.Target.Animation = animation!;
|
||||
ActorChanged?.Invoke(current.Target);
|
||||
}
|
||||
}
|
||||
|
||||
private void FinishMulti(GamEntity entity)
|
||||
{
|
||||
// MCA finisher4311F0 preserves 'none'/NULL semantics for PlayerControlled.
|
||||
SetControl(entity);
|
||||
EnqueueNext(entity);
|
||||
}
|
||||
|
||||
private void EnqueueNext(GamEntity entity)
|
||||
{
|
||||
pending.Enqueue((entity.Text("NextTrigger") ?? "none", entity.Tag));
|
||||
}
|
||||
|
||||
private void UpdateCamera(Shot current)
|
||||
{
|
||||
var source = current.Source;
|
||||
var target = current.Target;
|
||||
var t = (float)current.Elapsed;
|
||||
if (current.Index >= 0)
|
||||
{
|
||||
var suffix = current.Index.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
var type = source.Integer("CameraType" + suffix);
|
||||
var local = type switch
|
||||
{
|
||||
1 => new Vector3(0, 140, MathF.Max(100, 300 - 15 * t)),
|
||||
2 => new Vector3(0, 240, MathF.Max(100, 500 - 35 * t)),
|
||||
3 => new Vector3(200, 240, MathF.Max(100, 700 - 55 * t)),
|
||||
4 => new Vector3(-200, 190, MathF.Max(100, 700 - 55 * t)),
|
||||
_ => new Vector3(0, 40, 200),
|
||||
};
|
||||
CameraEye = TransformLocal(target, local);
|
||||
CameraTarget = target.Position + Vector3.UnitY * (source.Number("LookatVOffset" + suffix, 100) - 60);
|
||||
return;
|
||||
}
|
||||
if (source.Integer("CameraType") == 2)
|
||||
{
|
||||
CameraEye = source.Position;
|
||||
CameraTarget = target.Position;
|
||||
return;
|
||||
}
|
||||
var minimum = source.Number("MinDist", 100);
|
||||
var maximum = source.Number("MaxDist", 1000);
|
||||
var distance = Math.Clamp(source.Number("InitialDist", 200) - source.Number("ZoomSpeed") * t,
|
||||
MathF.Min(minimum, maximum), MathF.Max(minimum, maximum));
|
||||
var offset = new Vector3(source.Number("TargOffsetX"), source.Number("TargOffsetY"), source.Number("TargOffsetZ"));
|
||||
if (source.Integer("ViewFromCamera") == 0)
|
||||
{
|
||||
CameraEye = TransformLocal(target, offset with { Z = distance });
|
||||
CameraTarget = target.Position + Vector3.UnitY * source.Number("LookVoffset");
|
||||
}
|
||||
else
|
||||
{
|
||||
var point = TransformLocal(target, offset);
|
||||
var direction = source.Position - point;
|
||||
if (direction.LengthSquared() < .000001f)
|
||||
{
|
||||
Report(source.Tag!, source.Kind, "CAM eye coincides with target offset; original normalization undefined");
|
||||
CameraEye = source.Position;
|
||||
}
|
||||
else CameraEye = point + Vector3.Normalize(direction) * distance;
|
||||
CameraTarget = point;
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3 TransformLocal(DirectorActor target, Vector3 point)
|
||||
{
|
||||
// Original OMT Euler local-to-world routine472980; quantized modern
|
||||
// sin/cos here retains the source angular grid, not x87 bit identity.
|
||||
var (sx, cx) = LabSimulation.Trig(target.Rotation.X);
|
||||
var (sy, cy) = LabSimulation.Trig(target.Rotation.Y);
|
||||
var (sz, cz) = LabSimulation.Trig(target.Rotation.Z);
|
||||
var x = point.X * cz - point.Y * sz;
|
||||
var y = point.X * sz + point.Y * cz;
|
||||
var z = point.Z;
|
||||
var pitchedY = y * cx - z * sx;
|
||||
var pitchedZ = y * sx + z * cx;
|
||||
return target.Position + new Vector3(x * cy - pitchedZ * sy, pitchedY, x * sy + pitchedZ * cy);
|
||||
}
|
||||
|
||||
private void SetControl(GamEntity entity)
|
||||
{
|
||||
var control = entity.Text("PlayerControlled");
|
||||
if (IsNone(control)) return;
|
||||
if (Equal(control, "NULL")) ControlledTag = null;
|
||||
else if (actors.ContainsKey(control!)) ControlledTag = control;
|
||||
else Report(entity.Tag!, entity.Kind, $"PlayerControlled target {control} absent");
|
||||
}
|
||||
|
||||
private void Toggle(GamEntity entity)
|
||||
{
|
||||
var tag = entity.Text("ToggleObject");
|
||||
var toggle = entity.Integer("Toggle", -1);
|
||||
if (toggle is not (0 or 1) || IsNone(tag)) return;
|
||||
if (!actors.TryGetValue(tag!, out var actor)) { Report(entity.Tag!, entity.Kind, $"ToggleObject {tag} absent"); return; }
|
||||
actor.Visible = actor.Active = toggle == 1;
|
||||
if (actor.Kind == "3ANI") { actor.SpritePlaying = toggle == 1; actor.SpriteRevision++; }
|
||||
ActorChanged?.Invoke(actor);
|
||||
}
|
||||
|
||||
private void RestoreControl()
|
||||
{
|
||||
shot = null;
|
||||
ControlledTag = level.Player?.Tag;
|
||||
InventoryEnabled = true;
|
||||
CameraEye = CameraTarget = null;
|
||||
skipping = false;
|
||||
// Original DEFAULT invokes a Jimmy help/inventory callback at SCENE30;
|
||||
// it does not assign a new task value or complete the lab.
|
||||
}
|
||||
|
||||
private void OnTaskAssigned(string name, int state)
|
||||
{
|
||||
foreach (var actor in Actors)
|
||||
if (Equal(actor.SourceGam?.Text("TaskName"), name)) ApplyTask(actor, state);
|
||||
}
|
||||
|
||||
private void ApplyTask(DirectorActor actor, int state)
|
||||
{
|
||||
if (actor.SourceGam is not { } source) return;
|
||||
// LOAD.RequiredLevel belongs to its RequiredTask contact gate, not the
|
||||
// animated actor's TaskName activation contract. Applying the latter
|
||||
// here disables the lab exit even when SCENE reaches60.
|
||||
if (source.Kind == "LOAD") return;
|
||||
var active = source.Kind == "3PIC" ? TaskActivation.Pickup(source, state) : TaskActivation.Animated(source, state);
|
||||
if (active.HasValue) { actor.Active = actor.Visible = active.Value; ActorChanged?.Invoke(actor); }
|
||||
}
|
||||
|
||||
private void Block(GamEntity source, string detail, string? next)
|
||||
{
|
||||
shot = null; Blocked = true;
|
||||
blockedNext = next; blockedCaller = source.Tag;
|
||||
Report(source.Tag ?? "?", source.Kind, detail);
|
||||
}
|
||||
|
||||
private void Report(string tag, string kind, string detail)
|
||||
{
|
||||
if (!reported.Add(tag + "\0" + kind + "\0" + detail)) return;
|
||||
issues.Add(new DirectorIssue(tag, kind, detail));
|
||||
Unsupported?.Invoke(tag, kind);
|
||||
}
|
||||
private static bool Equal(string? a, string? b) => a is not null && b is not null && string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
|
||||
private static bool IsNone(string? value) => string.IsNullOrEmpty(value) || Equal(value, "none");
|
||||
private static bool Finite(Vector3 p) => float.IsFinite(p.X) && float.IsFinite(p.Y) && float.IsFinite(p.Z);
|
||||
}
|
||||
Reference in new issue
Block a user