159 lines
10 KiB
C#
159 lines
10 KiB
C#
using System.Numerics;
|
|
using GamePort.Assets;
|
|
using GamePort.Game;
|
|
using GamePort.Application;
|
|
|
|
var tests=new(string,Action)[]{
|
|
("owned actor handoff and actual passenger/body phases",Ownership),
|
|
("fresh versus retained input registration order",InputOrder),
|
|
("release/remount preserves ship motion and stops engine",Remount),
|
|
("vehicle Tab access uses rider menu callback",Menu),
|
|
("noclip releases vehicle and scene reset clears its state",ResetAndNoclip),
|
|
("debug force-control preserves mounted input and authored ownership",ForcedControl),
|
|
("named Jimmy cutscene cleanup releases the controlled vehicle",Cutscene),
|
|
("six copied-original50/.6 support references",Support),
|
|
("Rocket ceiling370 preserves acceleration and forces minus120",Ceiling),
|
|
("Rocket wall374 does not inherit horizontal reflection",Wall),
|
|
("actual passenger can activate RETURN while ship owns control",Return),
|
|
("exact four resource families and additive fire visibility",Visuals),
|
|
};
|
|
foreach(var(name,check)in tests){check();Console.WriteLine("PASS "+name);}
|
|
Console.WriteLine($"Rocketship integration: {tests.Length} groups passed; bounded static VR02, not original whole-game verification.");
|
|
|
|
static void Ownership()
|
|
{
|
|
using var f=new Fixture();var root=f.Player.ActorRoot;f.Mount();
|
|
Check(f.Director.ControlledTag==f.Ship.Actor.Tag&&!f.Director.Controlled&&f.Binding.InventoryControlled,"ship ownership/menu");
|
|
Near(f.Ship.Root,root,"owned ship uses Jimmy root, not authored ship placement");
|
|
int body=f.Player.PhysicsSteps,controller=f.Player.ControllerSteps;
|
|
for(int i=0;i<20;i++)f.Binding.Step(new(true,false,false,false,false));
|
|
Check(f.Player.PhysicsSteps==body+20&&f.Player.ControllerSteps==controller,"passenger static physics remains live without controller");
|
|
Near(f.Player.ActorRoot,f.Ship.Root,"passenger copied after its own physics");
|
|
Check(f.Ship.InputSteps==20&&f.Ship.Steering.Speed==1400&&f.Player.Energy==20,"flight input/tutorial energy");
|
|
}
|
|
static void InputOrder()
|
|
{
|
|
using var fresh=new Fixture();using var retained=new Fixture();retained.Player.InputAfterPlayerUpdate=true;
|
|
fresh.Mount();retained.Mount();var input=new PlayerInput(true,false,false,false,false);
|
|
fresh.Binding.Step(input);retained.Binding.Step(input);
|
|
Check(fresh.Ship.Velocity.Z>300&&retained.Ship.Velocity.Z==0,"fresh input precedes apply, retained follows");
|
|
Check(fresh.Ship.Steering.Speed==400&&retained.Ship.Steering.Speed==400,"same stored scalar, different publication phase");
|
|
}
|
|
static void Remount()
|
|
{
|
|
using var f=new Fixture();var sounds=new List<int>();int stopped=0;
|
|
f.Ship.EngineSound+=sounds.Add;f.Ship.EngineStopped+=()=>stopped++;
|
|
f.Mount();for(int i=0;i<12;i++)f.Binding.Step(new(true,false,false,false,false));
|
|
var velocity=f.Ship.Velocity;var scalar=f.Ship.Steering.Speed;var root=f.Player.ActorRoot;
|
|
f.Interactions.Inventory.SelectGadget(-1);
|
|
Check(!f.Ship.Mounted&&f.Director.Controlled&&f.Player.GadgetMode==-1&&f.Ship.EngineMode==0,"cleanup owners/engine");
|
|
Near(f.Player.ActorRoot,root,"cleanup retains copied root");Near(f.Player.Velocity,Vector3.Zero,"cleanup clears Jimmy velocity");
|
|
f.Interactions.Inventory.SelectGadget(1);
|
|
Near(f.Ship.Velocity,velocity,"remount retains ship velocity");Check(f.Ship.Steering.Speed==scalar,"remount retains scalar");
|
|
Check(sounds.SequenceEqual(new[]{196})&&stopped==1,"unchanged engine mode does not restart; cleanup stops once");
|
|
}
|
|
static void Menu()
|
|
{
|
|
using var f=new Fixture();f.Mount();var screen=new GadgetScreen(f.Interactions.Inventory,()=>f.Player.GadgetMode);
|
|
Check(screen.Toggle(f.Binding.InventoryControlled)&&!screen.Open&&!f.Ship.Mounted,"firstTab unequips ship");
|
|
Check(screen.Toggle(f.Binding.InventoryControlled)&&screen.Open,"secondTab opens panel");
|
|
}
|
|
static void ResetAndNoclip()
|
|
{
|
|
using var f=new Fixture();f.Mount();f.Player.SetNoclip(true);f.Binding.Step(default);
|
|
Check(!f.Ship.Mounted&&f.Player.Noclip&&f.Director.Controlled&&f.Ship.EngineMode==0,"noclip cleanup");
|
|
f.Binding.ResetVehicle();Check(f.Ship.FrameSteps==0&&!f.Ship.Actor.Visible,"scene reset clears owned state");
|
|
}
|
|
static void ForcedControl()
|
|
{
|
|
using var f=new Fixture();f.Mount();f.Binding.Step(new(true,false,false,false,false));
|
|
int input=f.Ship.InputSteps;f.Director.DebugForceControl=true;
|
|
f.Binding.Step(new(false,true,false,false,false));
|
|
Check(f.Ship.InputSteps==input+1&&f.Ship.Steering.Down,"mounted pilot still receives forced input");
|
|
Check(f.Ship.Mounted&&f.Director.AuthoredControlledTag==f.Ship.Actor.Tag,"force override preserves authored ship owner");
|
|
f.Director.DebugForceControl=false;Check(f.Director.ControlledTag==f.Ship.Actor.Tag,"disabling override restores effective ship owner");
|
|
}
|
|
static void Cutscene()
|
|
{
|
|
using var f=new Fixture();f.Mount();f.Binding.Step(new(true,false,false,false,false));
|
|
f.Director.Trigger("rs");
|
|
Check(!f.Ship.Mounted&&f.Player.GadgetMode==-1&&f.Ship.EngineMode==0&&!f.Ship.FireVisible,"MCA named-Jimmy cleanup releases ship/engine/fire");
|
|
}
|
|
static void Support()
|
|
{
|
|
var floor=new CameraRayPolygon(new(new(-1000,0,-1000),new(1000,0,-1000),new(0,0,1000)),Vector3.UnitY);
|
|
var physics=new OriginalBodyPhysics(new([floor]));
|
|
var cases=new(float Y,Vector3 Velocity,bool Supported,float Published,Vector3 Root,Vector3 Out,bool Grounded)[]{
|
|
(30,Vector3.Zero,false,0,new(0,30.0000019f,0),Vector3.Zero,true),
|
|
(26,Vector3.Zero,false,0,new(0,30.0000019f,0),Vector3.Zero,true),
|
|
(75.9f,Vector3.Zero,false,0,new(0,75.6777802f,0),new(0,-13.333334f,0),false),
|
|
(30,new(0,300,0),false,0,new(0,34.7777786f,0),new(0,286.666656f,0),false),
|
|
(30,new(120,0,-60),true,0,new(2,30.0000019f,-1),new(118.400002f,0,-59.2000008f),true),
|
|
(30,new(120,0,-60),true,100,new(2,30.0000019f,-1),new(120,0,-60),true),
|
|
};
|
|
foreach(var c in cases)
|
|
{
|
|
var r=physics.Step(new(new(0,c.Y,0),c.Velocity,Vector3.Zero,Vector3.Zero,c.Supported,c.Published),1f/60,50,.6f,profile:BodyResponseProfile.Rocketship);
|
|
Near(r.Body.Position,c.Root,"original root");Near(r.Body.Velocity,c.Out,"original velocity");Check(r.Body.Supported==c.Grounded,"original support");
|
|
}
|
|
}
|
|
static void Ceiling()
|
|
{
|
|
var ceiling=new CameraRayPolygon(new(new(-1000,300,-1000),new(1000,300,1000),new(1000,300,-1000)),-Vector3.UnitY);
|
|
var p=new OriginalBodyPhysics(new([ceiling]));var acceleration=new Vector3(3,1800,5);
|
|
var result=p.Step(new(new(100,249,0),new(0,200,0),acceleration,Vector3.Zero),1f/60,50,.6f,profile:BodyResponseProfile.Rocketship);
|
|
Check(result.Contact.HasValue&&result.Body.Velocity.Y==-120,$"source370 unconditional downward velocity: contact={result.Contact?.StoredNormal} body={result.Body}");
|
|
Near(result.Body.Acceleration,acceleration,"source370 retains acceleration");
|
|
}
|
|
static void Wall()
|
|
{
|
|
var wall=new CameraRayPolygon(new(new(0,-1000,-1000),new(0,1000,-1000),new(0,1000,1000)),-Vector3.UnitX,MaterialId:0);
|
|
var p=new OriginalBodyPhysics(new([wall]));
|
|
var result=p.Step(new(new(-51,300,0),new(300,0,20),Vector3.Zero,Vector3.Zero),1f/60,50,.6f,profile:BodyResponseProfile.Rocketship);
|
|
Check(result.Contact.HasValue&&MathF.Abs(result.Body.Velocity.X-300)<.001f&&MathF.Abs(result.Body.Velocity.Z-20)<.001f,$"no invented generic reflection: contact={result.Contact?.StoredNormal}, body={result.Body}");
|
|
}
|
|
static void Return()
|
|
{
|
|
using var f=new Fixture();LevelTransition? transition=null;f.Interactions.Transition+=t=>transition=t;
|
|
f.Interactions.SetReturnContext("level1b.gam","STARTEXP");f.Mount();
|
|
var exit=f.Director.Actors.Single(a=>a.Kind=="LOAD");
|
|
f.Ship.Mount(exit.Position,Vector3.Zero,f.Player.CameraEye);f.Binding.Step(default);
|
|
f.Interactions.Update(f.Player.ActorRoot,f.Player.InteractionRadius,f.Ship.Actor);
|
|
Check(transition is{Returning:true,LevelFile:"level1b.gam",StartPoint:"STARTEXP"},"passenger LOAD gate resolves stored RETURN");
|
|
}
|
|
static void Visuals()
|
|
{
|
|
using var f=new Fixture();var visuals=new RocketshipVisuals(f.World,Path.GetFullPath("artifacts/extracted"));
|
|
visuals.Update(visuals.Mesh,f.Ship,0,f.Player.Appearance);Check(visuals.Mesh.Draws.TakeLast(4).All(d=>!d.Visible),"unmounted owned visuals hidden");
|
|
f.Mount();f.Binding.Step(new(true,false,false,false,false));visuals.Update(visuals.Mesh,f.Ship,.1,f.Player.Appearance);
|
|
Check(visuals.Mesh.Draws.TakeLast(4).All(d=>d.Visible)&&visuals.Mesh.Draws[^1].Blend==MeshBlend.Additive,"body/driver/dog/fire source layers");
|
|
f.Interactions.Inventory.SelectGadget(-1);visuals.Update(visuals.Mesh,f.Ship,.2,f.Player.Appearance);
|
|
Check(visuals.Mesh.Draws.TakeLast(4).All(d=>!d.Visible),"cleanup hides every owned layer");
|
|
}
|
|
static void Check(bool ok,string message){if(!ok)throw new Exception(message);}
|
|
static void Near(Vector3 actual,Vector3 expected,string message)=>Check(float.IsFinite(actual.X+actual.Y+actual.Z)&&Vector3.Distance(actual,expected)<.002f,$"{message}: {actual} != {expected}");
|
|
|
|
sealed class Fixture:IDisposable
|
|
{
|
|
public Mesh World {get;}=Mesh.LoadSceneJson("artifacts/extracted/VR02/scene.json");
|
|
public SceneDirector Director {get;}
|
|
public SceneInteractions Interactions {get;}
|
|
public LabSimulation Player {get;}
|
|
public Rocketship Ship {get;}
|
|
public PlayerSceneBinding Binding {get;}
|
|
public Fixture()
|
|
{
|
|
var level=GamLevel.Load("../Original/gam/VR02.gam");var save=OriginalSave.Load("../Original/NewGame.tsk");var tasks=new TaskStates(save.Tasks);
|
|
Director=new(level,tasks,(_,_)=>0);Interactions=new(Director,tasks,save);
|
|
var start=level.FindStart()!;Director.Begin(start,activateStartTrigger:false);
|
|
var ray=OriginalCameraRay.FromRouteScene(World,"VR02");
|
|
Player=new(new(World),new MorphAnimation("artifacts/extracted/animations/jimstop/animation.json").Base,start.Position,start.Rotation.Y,
|
|
(a,b)=>ray.Trace(a,b),(a,b)=>ray.TraceGeometry(a,b),OriginalStaticCollision.FromRouteScene(World,"VR02")){LevelCode="VR02"};
|
|
Director.SyncActor(level.Player!.Tag!,Player.ActorRoot,new(0,Player.Yaw,0));
|
|
Ship=new(Director.Actors.Single(a=>a.Kind=="3ROC"),World,"VR02");
|
|
Binding=new(Director,Player,Interactions.Inventory,level.Player.Tag!,Ship);
|
|
}
|
|
public void Mount(){Interactions.Inventory.SetState(0,1,1);Interactions.Inventory.SelectGadget(1);}
|
|
public void Dispose()=>Binding.Dispose();
|
|
}
|