using System.Numerics;
using GamePort.Assets;
namespace GamePort.Game;
/// Mutable source-entity state for the reconstructed trigger/camera interpreter.
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; }
//Source body integration and movement-enable flags are separate from AI
//activation. Only the bounded companion gadget consumer writes them here.
public bool BodyEnabled { get; internal set; } = true;
public bool MovementEnabled { get; internal set; } = true;
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);
public enum ScriptPreparation { StopMotion, ReleaseGadget, FlattenOrientation }
///
/// 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.
///
public sealed class SceneDirector
{
private readonly GamLevel level;
private readonly TaskStates tasks;
private readonly Func soundDuration;
private readonly Dictionary entities = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary actors = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary activations = [];
private readonly Queue<(string Tag, string? Caller)> pending = [];
private readonly List issues = [];
private readonly HashSet reported = new(StringComparer.Ordinal);
private readonly HashSet 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 Actors { get; } = [];
public IReadOnlyList Issues => issues;
private string? controlledTag;
public string? AuthoredControlledTag => controlledTag;
/// Modern debug override; leaves authored control/camera transitions intact.
public bool DebugForceControl { get; set; }
public bool Controlled => Equal(ControlledTag, level.Player?.Tag);
public string? ControlledTag
{
get => DebugForceControl ? level.Player?.Tag : controlledTag;
private set => controlledTag = value;
}
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? Speech;
public event Action? MusicStopped;
public event Action? MusicRestarted;
public event Action? ActorChanged;
public event Action? ActorPreparing;
public event Action? GadgetReleaseRequested;
public event Action? AuthoredTransformChanged;
public event Action? Unsupported;
public SceneDirector(GamLevel level, TaskStates tasks, Func 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, bool activateStartTrigger = true)
{
if (start.Kind != "STRT") throw new ArgumentException("Expected original STRT entity", nameof(start));
DebugForceControl = false;
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.BodyEnabled = initial.BodyEnabled; actor.MovementEnabled = initial.MovementEnabled;
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")));
}
// RETURN sets Jimmy+954; STRT4427F2..44282A consumes that flag and
// suppresses its trigger once. Do not fast-forward the trigger's actions.
var trigger = activateStartTrigger ? start.Text("StartTrigger") : null;
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();
}
///
/// 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.
///
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);
internal DirectorActor AddOwnedActor(string tag,string kind,Vector3 root)
{
if(actors.TryGetValue(tag,out var existing))return existing;
var actor=new DirectorActor(null,tag,kind,root);Actors.Add(actor);actors.Add(tag,actor);return actor;
}
public DirectorActor EnsureCompanion(Vector3 root,Vector3 rotation)
{
var actor=AddOwnedActor("C3DGODDARD","3DOG",root);
actor.Position=root;actor.Rotation=rotation;actor.AIstate=4;actor.Speed=450;return actor;
}
internal void TransferControl(DirectorActor actor)
{
if(!Actors.Contains(actor))throw new ArgumentException("Control requires a registered actor",nameof(actor));
ControlledTag=actor.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"));
}
/// Escape/Space original chain skip: preserve AI/toggle actions and skip remaining speech/shots.
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(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, prepareOwner: true);
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 transformed = false;
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; transformed = true; }
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 }; transformed = true; }
if (transformed) AuthoredTransformChanged?.Invoke(target);
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)
{
DeactivateInvention(entity); //43129A: explicit Jimmy lookup, before first target check.
// MCA's PlayerControlled is its completion target (4311F0), not an
// activation grant. Only initial activation clears control; later shots
//use431750 without repeating431502..4315A7 preparation.
Toggle(entity);
if (IsNone(entity.Text("CameraTarget0"))) return; //431300→431668 returns, not completion.
if (skipping) { FinishMulti(entity); return; }
//431502 initial activation only. Subsequent431750 shots do not repeat
//preparation or clear control. The raw owner guard ignores debug force.
PrepareOwner(ScriptPreparation.StopMotion, ScriptPreparation.FlattenOrientation, ScriptPreparation.ReleaseGadget);
ControlledTag = null;
StartCamera(entity, 0, applyCommon: false);
}
private void StartCamera(GamEntity entity, int index, bool applyCommon = true)
{
if (applyCommon)
{
DeactivateInvention(entity); //4165B7, distinct from raw-owner preparation.
if (Equal(entity.Text("PlayerControlled"), "NULL"))
PrepareOwner(ScriptPreparation.ReleaseGadget, ScriptPreparation.StopMotion, ScriptPreparation.FlattenOrientation);
SetControl(entity); Toggle(entity);
}
if (entity.Integer("DeactivateInv", 1) != 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);
// CAM416776..4167E1 stops the selected music handle and unloads its
// database before speech. Do not infer this from every speech stream:
// standalone MCA activation has a separate source path.
if (index < 0) MusicStopped?.Invoke();
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 PrepareOwner(params ScriptPreparation[] actions)
{
if (controlledTag == null || !actors.TryGetValue(controlledTag, out var owner)) return;
foreach (var action in actions)
{
// Only Jimmy's derived preparation is modeled here; other classes
//receive the boundary without inventing their virtual side effects.
if (action == ScriptPreparation.StopMotion && owner.Kind == "3JIM")
owner.Speed = 0;
else if (action == ScriptPreparation.FlattenOrientation)
owner.Rotation = new Vector3(0, owner.Rotation.Y, 0);
ActorPreparing?.Invoke(owner, action);
//42AFC0 invokes43A750 before the derived STOP animation request.
if (action == ScriptPreparation.StopMotion && owner.Kind == "3JIM")
{ owner.Animation = "STOP"; ActorChanged?.Invoke(owner); }
}
}
public void ReleasePlayerGadget()
{
if(actors.TryGetValue("JIM1",out var jimmy))GadgetReleaseRequested?.Invoke(jimmy);
}
private void DeactivateInvention(GamEntity source)
{
//Both CAM/MCA constructors default this property to true. The source
//explicitly looks up Jimmy even when a different actor owns control.
if (source.Integer("DeactivateInv", 1) != 0 && actors.TryGetValue("JIM1", out var jimmy))
GadgetReleaseRequested?.Invoke(jimmy);
}
private void SetControl(GamEntity entity, bool prepareOwner = false)
{
var control = entity.Text("PlayerControlled");
if (IsNone(control)) return;
if (Equal(control, "NULL"))
{
if (prepareOwner) PrepareOwner(ScriptPreparation.StopMotion); //40C4AD; no438/flatten.
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()
{
// Authored music handoff must use authored ownership even if debug input
// is forced during the cutscene. The override does not grant source control.
var wasControlled = Equal(controlledTag, level.Player?.Tag);
shot = null;
ControlledTag = level.Player?.Tag;
InventoryEnabled = true;
CameraEye = CameraTarget = null;
skipping = false;
// DEFAULT447D5C skips the restart if Jimmy already owns control;
//447F12..447F45 reloads his selected music and starts wave0 again.
if (!wasControlled) MusicRestarted?.Invoke();
// 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;
// Carl413F30 captures SCENE before generic40E340, then executes his
// derived policy in the same callback, before the next registry actor.
var carlScene = source.Kind == "3CAR" ? tasks.Get("SCENE") : 0;
var active = source.Kind == "3PIC" ? TaskActivation.Pickup(source, state) : TaskActivation.Animated(source, state);
if (active.HasValue) actor.Active = actor.Visible = active.Value;
var carlOverride = source.Kind == "3CAR" && level.Code == "LV1B";
if (carlOverride)
{
//414068..414118. Other levels' derived policies remain unported.
if (carlScene is < 0 or > 60) actor.Active = actor.Visible = false;
else
{
if (carlScene > 30 && FindActor("CARLESC3") is { } marker)
{
actor.AIstate = 6;
actor.Position = marker.Position;
}
// At60 retain the generic activation result.
if (carlScene < 60) actor.Active = actor.Visible = true;
}
}
if (active.HasValue || carlOverride) 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);
}