Restore Goddard leveling and Scooter positional pitch processing

This commit is contained in:
UnixNight committed 2026-11-04 18:27:56 -05:00
1 parent 74be19eb15
commit fccc0b9d1b
24 files changed
+967 -8

No files matched your search

+19 -4
View File
@@ -96,10 +96,15 @@ public sealed class ActorPatrol
throw new InvalidOperationException("Goddard body solver produced nonfinite state");
actor.Position = body.Position;
Velocity = body.Velocity;
var yawError = (desiredYaw - actor.Rotation.Y) % 360;
if (yawError > 180) yawError -= 360;
if (yawError < -180) yawError += 360;
actor.Rotation = actor.Rotation with { Y = actor.Rotation.Y + yawError * yawFactor * dt };
if(FollowPlayer&&actor.Kind=="3DOG")
actor.Rotation=GoddardFacing(actor.Rotation,desiredYaw,dt);
else
{
var yawError = (desiredYaw - actor.Rotation.Y) % 360;
if (yawError > 180) yawError -= 360;
if (yawError < -180) yawError += 360;
actor.Rotation = actor.Rotation with { Y = actor.Rotation.Y + yawError * yawFactor * dt };
}
switch (actor.AIstate)
{
@@ -120,6 +125,16 @@ public sealed class ActorPatrol
return true;
}
/// <summary>4096E0 with41C8DB Goddard factors and the ordinary supported
/// follow target (pitch/roll0). Dismount copies tilt; this later AI phase
/// gradually levels it. Full airborne AI target selection remains separate.</summary>
public static Vector3 GoddardFacing(Vector3 rotation,float yaw,float dt)
{
static float Arc(float delta)=>delta>180?delta-360:delta< -180?delta+360:delta;
var delta=new Vector3(Arc(-rotation.X)*.3f*dt,Arc(yaw-rotation.Y)*3.2f*dt,Arc(-rotation.Z)*.3f*dt);
return RocketOrientation.Add(rotation,delta);
}
private void StepFollow()
{
var target=findActor("JIM1");if(target==null||!target.Active)return;
+39
View File
@@ -0,0 +1,39 @@
using System.Numerics;
namespace GamePort.Game;
/// <summary>412ED0 engine command followed by bounded47D9D0 positional pitch.
/// Owns source695F84 channel history; scene/global audio scheduling stays separate.</summary>
public sealed class ScooterAudio
{
private int appliedFrequency;
public float History { get; private set; }
public void Reset(){History=0;appliedFrequency=0;}
public static int EngineFrequency(int baseFrequency,float speed)
=>Math.Max(7000,(int)(baseFrequency+(double)speed*0.5263157894736842*51));
public int Frequency(int baseFrequency,float speed,Vector3 source,Vector3 listener)
{
float distance=OriginalBodySupport.QuickMagnitude(listener-source);
//A zero-distance source exits before set_frequency, retaining device Hz.
if(distance==0)return appliedFrequency==0?baseFrequency:appliedFrequency;
var history=History;
int nominal=EngineFrequency(baseFrequency,speed);
int adjusted=PositionalFrequency(nominal,distance,ref history);
History=history;
//DX accepts unsigned Hz, clamps nonzero to100..100000;0 means source rate.
uint hz=unchecked((uint)adjusted);
appliedFrequency=hz==0?baseFrequency:(int)Math.Clamp(hz,100u,100000u);
return appliedFrequency;
}
public static int PositionalFrequency(int nominal,float distance,ref float history)
{
if(distance==0)return nominal; //47DA7E returns without the channel write/history update.
int correction=(int)(((double)distance-history)*.75);
int result=distance>history?unchecked(nominal-correction):unchecked(nominal+correction);
//47DBFC/47DC11 fild the integer correction, not the current distance.
history=correction;
return result;
}
}
+5 -4
View File
@@ -33,8 +33,6 @@ internal static class Program
catch (Exception error) { Console.Error.WriteLine(error); return 1; }
}
private static int ScooterEngineFrequency(int baseFrequency,float speed)=>Math.Max(7000,(int)(baseFrequency+(double)speed*(1/1.9)*51));
private static string? Option(string[] args, string name)
{
var i = Array.IndexOf(args, name);
@@ -622,9 +620,12 @@ internal static class Program
}
if(scooter!=null)
{
scooter.EngineStarted+=()=>sceneAudio?.Effect(46,"scooter");
var scooterAudio=new ScooterAudio();
scooter.EngineStarted+=()=>{scooterAudio.Reset();sceneAudio?.Effect(46,"scooter");};
scooter.EngineStopped+=()=>sceneAudio?.StopLoop("scooter");
scooter.EngineSpeedChanged+=speed=>sceneAudio?.TuneLoop("scooter",baseFrequency=>ScooterEngineFrequency(baseFrequency,speed));
scooter.EngineSpeedChanged+=speed=>sceneAudio?.TuneLoop("scooter",baseFrequency=>
scooterAudio.Frequency(baseFrequency,speed,scooter.Root,
director?.CameraEye??(scooter.Mounted?scooter.CameraEye:simulation!.CameraEye)));
}
if(baseballs!=null)baseballs.Sound+=id=>sceneAudio?.Effect(id);
if(rocketship!=null)