aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 1434fb08aa195cb81d0373f42a1f1ab7a50e8f29
parent c1e6aec8b5842fde14926c12ff30447d1b337b6b
Author: anon <anon@example.com>
Date:   Mon, 26 Oct 2026 17:27:30 +0000

Simulate frozen movement through native permission callbacks

Enter and leave the frozen helper on committed living-player restriction
edges, retain independent gravity and turning, and preserve seated/flight
callback admission. Restore persisted restrictions before world readiness.

Verify 1,345 server roots, 88 focused race roots, seven failing production
baselines and paired GPU WASM falling, turning, blocked locomotion,
late joins and walking/running expiry. Record remaining trajectory,
actor-flag, death and sneak policy gaps explicitly.

Diffstat:
MTODO.md | 33++++++++++++++++++++++++++-------
Mdocs/player-movement.md | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mserver/main.go | 3+++
Mserver/nano_buffs.go | 1+
Mserver/nano_casting.go | 1+
Mserver/nano_control.go | 1+
Mserver/nano_periodic.go | 1+
Aserver/player_frozen_test.go | 266+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/player_movement.go | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
9 files changed, 441 insertions(+), 27 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1339,13 +1339,32 @@ disconnect retention and succession policy still need period corroboration. seated turning, falling and landing. Normal stand33 restores preferred walk/run without Halt. Keep posture acknowledgements for both native consumers even when their physical helpers reject. See [posture](docs/player-movement.md#sit-and-stand). -- [ ] Complete frozen and sneak movement callbacks and lifecycles before claiming - the whole helper state machine. Features4-clear stand33 currently preserves - seated actor state but does not enter frozen helper1. Recover RestrictAction's - internal21/34 transitions, stationary state, control cleanup, and the distinction - between helper primary and raw MovementMode173/posture430. Cover overlapping - restrictions, expiry/removal, death and late observers. - Trace the complete sneak flow before admitting movement26/32; ordinary +- [x] Apply living-player frozen callbacks through effective restriction changes. + Share conditional FullStop19 with the native sit predicate, submit21/34 and + subsequent deep-water24 through helper admission, and enter1 on restricted + stand33 while retaining rest/history. Keep turning, elevation and gravity in + the common integrator. Verify failed expiry transactions, seated/swimming and + flight branches, both preferences, warm/cold entry and paired WASM late joins. + See [frozen movement](docs/player-movement.md#frozen-movement-and-permission-changes). +- [ ] Complete the remaining frozen actor lifecycle: establish initial Features4 + counter provenance and Flags0 mask0x20000 semantics, and death/posture callback + ordering before changing current death/NPC policy. Cover multiple independent + restriction sources, partial/final removal, reconnect and late observers with + runtime evidence. Native counters are signed and dispatch only effective bit + edges; the flag suppresses callbacks and latches permission clear. Actor+70 is + stationary; +94 is deletion, not HP0. Source checks do not establish an extra + stationary physics gate. Preserve helper/raw173/425/430 distinctions. +- [ ] Resolve frozen fall trajectory differences under normal and loaded frame + cadence. The fixed server and both clients settle at16.41m, but post-placement + intermediate differences reach27.59m running and51.75m walking alongside the + full suite. Compare ordinary unrooted falls, measured frame deltas, relocation + and effect-replay clocks before attributing this to restriction handling. + Keep `local/player-frozen/runtime-verification.json` as the bounded baseline. +- [ ] Complete the sneak request163/ack162 -> movement26 lifecycle and server + concealment policy before admitting movement26/32. Source-only recovery binds + primary6/preferred callbacks, Features128/presentation, weapon-holder/InFight410 + guards and retained rest/controls/gravity, but not the server decision policy. + Ordinary sit/stand86/87 uses helper28/33 instead. Crawl25 is only bound to an exported API, and no ordinary elevation15/16 producer is established. The helper's elevation callbacks use+3/-0.8, including cached-state quirks; do not invent diff --git a/docs/player-movement.md b/docs/player-movement.md @@ -140,8 +140,8 @@ native owner/observer mode difference at rounded packet coordinates; water-edge classification remains in TODO and is not claimed as exact trajectory parity. The predicate retains the source's eight-mode rules. Existing server lifecycle -support remains walking/running, swimming, flying and sitting; copying the -predicate does not implement frozen/sneak transitions. The verified source +support includes walking/running, swimming, flying, sitting and the living-player +frozen callbacks below. Sneak remains pending. The verified source tables remain under `local/player-flight-input/research/helpers/`; this milestone's tests and paired traces are under `local/player-movement-mode/`. @@ -164,11 +164,10 @@ cannot submit helper14 through primary8; its secondary4 remains until another admitted transition changes it. Normal stand restores the preferred ground mode from8, preserves motion and -performs no Halt or position lift. Features4-clear stand leaves the seated actor -flag intact. The complete frozen lifecycle remains unsupported: native33 would -enter helper1 while retaining actor stats173/425/430, whereas the server currently -keeps its existing helper. RestrictAction53068 mask4 controls that same permission. -Do not equate the physical helper with raw MovementMode173 in that branch. +performs no Halt or position lift. Features4-clear stand enters frozen helper1 +while retaining the seated actor flag and independent gravity. Its native callback +does not refresh raw173/425/430. RestrictAction53068 mask4 controls that same +permission; do not equate the physical helper with raw MovementMode173. Water transitions preserve actor posture independently of the physical helper; see [water and retained rest](#water-and-retained-rest). @@ -191,6 +190,75 @@ running stand. Both native helpers and raw stats173/425/430 agree with server posture, with no WASM page errors. These captures establish the selected state and final-contact checks; they do not claim bit-identical intermediate motion. +## Frozen movement and permission changes + +Living-player permission changes use the existing template-derived restriction +predicate. Only a change in effective permission dispatches movement callbacks. +The detached outcome first settles the old controller; its new helper state is +published only after the effect transaction commits. Failed expiry/removal leaves +the original effect and controller intact for retry. World entry initializes the +helper from persisted active effects before readiness. + +On restriction, the native actor wrapper conditionally submits FullStop19, then +freeze21. The shared sit/FullStop predicate checks forward state3, strafe state3, +turn state5 or primary7. FullStop retains primary/preferred mode, resets all input +pairs and secondary, and clears cached forward/strafe/turn. Direct restricted +stand33 skips that wrapper. Freeze21 and restricted stand33 select primary1, +conditionally Halt and clear cached forward/strafe/turn, retaining actor rest, +input-pair history, elevation and gravity. Only entry from flight7 lifts position +by0.1, clears elevation and restores effective stat197 orientation. The worn +vehicle remains equipped. + +Frozen1 rejects locomotion, jumping and sit/stand, but admits turn9..12 and +landing14. Physics therefore continues through the common integrator, including +direct elevation, falling and collision. It must not return early just because +Features4 is clear. Final permission restoration submits34, restores preferred +walk/run and clears actor rest without resetting gravity or current controls. +If already in deep water it subsequently attempts24 even when34 was rejected. +Seated8 rejects21/34; its restriction and expiry therefore retain seated mode +unless an independently admitted water transition changes it. + +Maintained-source ledgers under `local/player-frozen/research/` verify190 frozen +bodies,90 sneak bodies and39 independently checked FullStop bodies, with full +hashes and inert bindings. These overlapping counts are not unique functions. +Actor byte+70 is stationary; byte+94 is engine deletion, not stationary or HP0. +No stationary gate is established in the demonstrated player physics chain. + +The native signed permission counters explain overlapping restrictions: initial1, +two applications produce0/-1, and only the final removal restores1. Flags0 +mask0x20000 suppresses callbacks and latches permission clear; it is not a general +NPC/owner test. Its initial provenance and the full death/posture ordering remain +open. The server retains its existing death policy and separate NPC controller; +this milestone does not complete every actor's frozen lifecycle. + +Seven new regression roots cover28 results, including retained rest/history, +independent physics, both preferences, seated/deep-water expiry, flight exit, +FullStop admission, failed delete/ignored delete/deferred commit and warm/cold +entry. All seven roots fail against the previous production implementation. +The final code passes1,345 server roots (14,419 results),88 focused/race roots +(277 results each), data package tests and go vet. + +Fifteen paired GPU WASM captures compare the old server with the candidate, +then repeat the candidate with walking preference. Offline fixtures extend owned +program42110 from its authored15 seconds to60 seconds for observation. Ordinary +control-editor relocation, keyboard turns/forward, observer reload and natural +expiry verify both clients' helper, permission count and final preferred mode, +with no page errors. The old server remains112.59m above the settled clients; +the candidate reaches their16.41m floor. Intermediate trajectories remain a +material limitation: maximum sampled differences after all three actors are +above120m are27.59m in the running capture and51.75m in the walking capture, +the latter alongside the full regression suite. Relocation also creates brief +actor-absent and pre-effect-replay samples; these are retained and counted. +These checks establish callback behavior and settled contact, not trajectory +parity. Evidence and exact-source verification are in `local/player-frozen/`. + +Sneak's recovered flow is special action19 -> CharacterAction163 request, then +server acknowledgement162 -> movement26. Ordinary send suppresses26 while +seated; the receiver requires its weapon-holder state and no effective InFight410. +Helper26/32 changes primary6/preferred and presentation/Features128, preserving +rest, velocity, controls and gravity. The server request/acknowledgement policy +and concealment/visibility rules remain unresolved; incoming26/32 stay excluded. + ## Water and retained rest Water entry submits helper24 through ordinary admission, replacing seated8 with @@ -205,7 +273,7 @@ Resting actors can therefore swim and follow after water entry or exit. Attack submits normal stand33 only from helper8. An explicit stand admitted during swimming clears actor rest while retaining helper4 and velocity. Recovery still uses retained rest; transient water/movement updates keep the periodic database -checkpoint cadence. Frozen and sneak lifecycles remain separate TODOs. +checkpoint cadence. Remaining frozen and sneak lifecycle gaps stay in TODO. Observer snapshots publish raw425/430 separately after the physical state. These generic stat setters do not select a helper or stand the actor. This preserves diff --git a/server/main.go b/server/main.go @@ -366,6 +366,9 @@ func (server *server) serveWorldClient(client *worldClient) error { character.sitting = false // Native controlled actors simulate after SCFU, before CharacterReady. character.movement.prepare(character, time.Now()) + if character.movementRestricted() { + character.restrictMovement() + } client.regenerationAt = time.Now() client.regenerationSeconds = 0 client.id = character.id diff --git a/server/nano_buffs.go b/server/nano_buffs.go @@ -371,6 +371,7 @@ func (server *server) removeNano_locked(player *character, index int, now time.T if !candidate.npc { candidate.health, candidate.nano = min(candidate.health, candidate.maximumHealth()), min(candidate.nano, candidate.maximumNano()) } + candidate.updateMovementPermission(player, now) if err := server.saveActiveNanos_locked(&candidate, now); err != nil { return err } diff --git a/server/nano_casting.go b/server/nano_casting.go @@ -310,6 +310,7 @@ func (server *server) advanceNanos(now time.Time) { victim.roaming, victim.running = &roaming, false } + victim.updateMovementPermission(target, now) award, err := server.saveNanoOutcome_locked(&caster, &victim, now) if err != nil { log.Printf("Nano outcome: %v", err) diff --git a/server/nano_control.go b/server/nano_control.go @@ -150,5 +150,6 @@ func (server *server) prepareWeaponDamage_locked(attacker, target *character, da if damage != 0 { server.breakNanos_locked(&candidate, 422) } + candidate.updateMovementPermission(target, now) return candidate } diff --git a/server/nano_periodic.go b/server/nano_periodic.go @@ -49,6 +49,7 @@ func (server *server) advancePeriodicNanos_locked(now time.Time, updates map[*wo if len(packets) == 0 { continue } + candidate.updateMovementPermission(target, now) // Damage, tick progress, contribution and any death/reward commit together. award, err := server.saveDamageOutcome_locked(&candidate, now) diff --git a/server/player_frozen_test.go b/server/player_frozen_test.go @@ -0,0 +1,266 @@ +package main + +import ( + "encoding/binary" + "fmt" + "math" + "testing" + "time" +) + +func TestPlayerRestrictedStandFreezesHelperWithoutClearingRest(t *testing.T) { + for _, running := range []bool{false, true} { + t.Run(fmt.Sprint(running), func(t *testing.T) { + world, _ := newCombatWorld() + player := world.characters[1] + player.sitting, player.running = true, running + player.movement.prepare(player, time.Now().Add(time.Second)) + player.activeNanos = []activeNano{{program: 42110}} + player.movement.components = [10]byte{8, 3, 1, 3, 4, 1, 5, 5, 3, 4} + player.movement.velocity, player.movement.speed = [3]float32{3, 0, 4}, 5 + player.movement.direction = -1 + player.movement.forward, player.movement.strafe, player.movement.turn = -1, 2, -1.5 + player.movement.vertical = -.8 + player.movement.verticalVelocity, player.movement.falling = -12, true + request := make([]byte, 36) + binary.BigEndian.PutUint32(request[16:], 87) + + if err := world.handlePosture(world.clients[1], request); err != nil { + t.Fatal(err) + } + + if player.movement.components != [10]byte{1, 3, 1, 3, 4, 3, 5, 5, 3, 4} || !player.sitting || player.running != running { + t.Fatal("restricted stand lost frozen helper, retained rest or accepted component history", player.sitting, player.running, player.movement) + } + if player.movement.velocity != [3]float32{} || player.movement.speed != 0 || player.movement.direction != 1 || player.movement.forward != 0 || player.movement.strafe != 0 || player.movement.turn != 0 { + t.Fatal("frozen entry did not halt and clear ordinary controls", player.movement) + } + if player.movement.vertical != -.8 || player.movement.verticalVelocity != -12 || !player.movement.falling { + t.Fatal("frozen entry cleared independent elevation or gravity outside its flight branch", player.movement) + } + }) + } +} + +func TestPlayerFrozenPhysicsRetainsGravityElevationAndTurning(t *testing.T) { + world := newPlayerCollisionWorld(t) + player, client := world.characters[1], world.clients[1] + player.position, player.rotation = [3]float32{961.625, 80, 510.75}, [4]float32{0, 0, 0, 1} + player.movement.prepare(player, time.Now().Add(time.Second)) + player.movement.components[0] = 1 + player.activeNanos = []activeNano{{program: 42110}} + player.movement.verticalVelocity, player.movement.falling = -12, true + player.movement.vertical = -.8 + if err := world.handleMovement(client, playerMovementRequest(player, 9)); err != nil { + t.Fatal(err) + } + started := player.movement.updatedAt + + world.advancePlayerMovement(started.Add(200 * time.Millisecond)) + + if player.movement.components[0] != 1 || player.position[1] >= 77 || player.movement.verticalVelocity >= -15 || !player.movement.falling || player.movement.vertical != -.8 || math.Abs(float64(player.rotation[1])) < .1 { + t.Fatal("movement restriction bypassed ordinary frozen physics", player.position, player.rotation, player.movement) + } +} + +func TestPlayerRestrictionExpiryUsesFrozenAdmissionAndWaterState(t *testing.T) { + for _, mode := range []byte{1, 8} { + for _, swimming := range []bool{false, true} { + for _, running := range []bool{false, true} { + t.Run(fmt.Sprintf("mode%d/water%t/running%t", mode, swimming, running), func(t *testing.T) { + world, _ := newEquipmentWorld(t) + player := world.characters[1] + player.sitting, player.running = true, running + deadline := time.Now().Add(15 * time.Second) + player.movement.prepare(player, deadline.Add(time.Second)) + player.movement.components = [10]byte{mode, 3, 1, 3, 4, 1, 5, 5, 3, 4} + player.movement.deepWater = swimming + player.movement.turn, player.movement.vertical = 1.5, -.8 + player.movement.verticalVelocity, player.movement.falling = -12, true + player.activeNanos = []activeNano{{program: 42110, caster: 1, expiresAt: deadline}} + if err := world.saveActiveNanos_locked(player, time.Now()); err != nil { + t.Fatal(err) + } + + world.advanceNanos(deadline) + + preferred := byte(2) + if running { + preferred = 3 + } + expected := preferred + if mode == 8 { + expected = 8 + } + if swimming { + expected = 4 + } + if len(player.activeNanos) != 0 || player.movement.components[0] != expected || player.sitting != (mode == 8) || player.running != running { + t.Fatal("restriction expiry bypassed helper admission or retained the frozen mode", player.sitting, player.running, player.activeNanos, player.movement) + } + elevation := float32(-.8) + if swimming { + elevation = 0 + } + if player.movement.turn != 1.5 || player.movement.verticalVelocity != -12 || !player.movement.falling || player.movement.vertical != elevation { + t.Fatal("restriction expiry reset unrelated motion or lost swim entry cleanup", player.movement) + } + }) + } + } + } +} + +func TestPlayerFullStopPreservesModeAndIndependentMotion(t *testing.T) { + for _, mode := range []byte{1, 3, 7, 8} { + t.Run(fmt.Sprint(mode), func(t *testing.T) { + world, _ := newCombatWorld() + player := world.characters[1] + player.running = true + player.movement.prepare(player, time.Now()) + player.movement.components = [10]byte{mode, 3, 1, 3, 4, 3, 5, 5, 3, 4} + player.movement.velocity, player.movement.speed = [3]float32{3, 0, 4}, 5 + player.movement.direction = -1 + player.movement.forward, player.movement.strafe, player.movement.turn = -1, 2, -1.5 + player.movement.vertical, player.movement.verticalVelocity, player.movement.falling = -.8, -12, true + before := player.movement + + // FullStop is an internal actor event, excluded from incoming movement packets. + accepted := player.movement.action(player, 19) + + if mode == 1 || mode == 8 { + if accepted || player.movement != before { + t.Fatal("rejected FullStop changed a frozen or seated helper", accepted, player.movement) + } + return + } + if !accepted || player.movement.components != [10]byte{mode, 1, 0, 1, 0, 1, 0, 1, 0, 1} || !player.running || player.movement.direction != 1 { + t.Fatal("FullStop lost mode/preference or reset the wrong component words", accepted, player.movement) + } + if player.movement.velocity != [3]float32{} || player.movement.speed != 0 || player.movement.forward != 0 || player.movement.strafe != 0 || player.movement.turn != 0 || player.movement.vertical != -.8 || player.movement.verticalVelocity != -12 || !player.movement.falling { + t.Fatal("FullStop did not clear ordinary controls independently of elevation and gravity", player.movement) + } + }) + } +} + +func TestPlayerRestrictedStandLeavesFlightWithoutNormalizingRest(t *testing.T) { + world := newPlayerFormWorld(t, 117322) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + player.position = [3]float32{961.625, 90, 510.75} + player.movement.updatedAt = time.Now().Add(time.Second) + player.movement.velocity, player.movement.speed = [3]float32{3, 0, 4}, 5 + player.movement.components = [10]byte{7, 3, 1, 3, 4, 3, 5, 5, 3, 4} + player.movement.forward, player.movement.strafe, player.movement.turn, player.movement.vertical = 1, 2, 1.5, 3 + player.movement.verticalVelocity, player.movement.falling = -12, true + player.sitting = true + player.activeNanos = []activeNano{{program: 42110}} + request := make([]byte, 36) + binary.BigEndian.PutUint32(request[16:], 87) + + if err := world.handlePosture(client, request); err != nil { + t.Fatal(err) + } + + if player.movement.components != [10]byte{1, 3, 1, 3, 4, 3, 5, 5, 3, 4} || math.Abs(float64(player.position[1])-90.1) > .00001 || player.movement.orientation != 0 || player.flying() || !player.sitting || player.inventory.Items[0].Slot != 1 { + t.Fatal("frozen flight exit lost placement, input history or the worn vehicle", player.position, player.movement, player.inventory) + } + if player.movement.velocity != [3]float32{} || player.movement.forward != 0 || player.movement.strafe != 0 || player.movement.turn != 0 || player.movement.vertical != 0 || player.movement.verticalVelocity != -12 || !player.movement.falling { + t.Fatal("frozen flight exit lost selective control cleanup or independent gravity", player.movement) + } +} + +func TestPlayerFailedRestrictionExpiryPreservesFrozenStateAndRetries(t *testing.T) { + for _, failure := range []struct{ name, statement string }{ + {"delete", "CREATE TRIGGER fail_expiry BEFORE DELETE ON active_nanos BEGIN SELECT RAISE(FAIL,'test frozen expiry'); END"}, + {"ignored delete", "CREATE TRIGGER fail_expiry BEFORE DELETE ON active_nanos BEGIN SELECT RAISE(IGNORE); END"}, + {"commit", "CREATE TABLE pending_expiry (player_id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER fail_expiry AFTER DELETE ON active_nanos BEGIN INSERT INTO pending_expiry VALUES(999999); END"}, + } { + t.Run(failure.name, func(t *testing.T) { + world, output := newEquipmentWorld(t) + player := world.characters[1] + player.sitting, player.running = true, true + deadline := time.Now().Add(15 * time.Second) + player.movement.prepare(player, deadline.Add(time.Second)) + player.movement.components[0] = 1 + player.movement.turn, player.movement.vertical = 1.5, -.8 + player.movement.verticalVelocity, player.movement.falling = -12, true + player.activeNanos = []activeNano{{program: 42110, caster: 1, expiresAt: deadline}} + if err := world.saveActiveNanos_locked(player, time.Now()); err != nil { + t.Fatal(err) + } + before := player.movement + if _, err := world.db.Exec(failure.statement); err != nil { + t.Fatal(err) + } + output.packets = nil + + world.advanceNanos(deadline) + + if len(player.activeNanos) != 1 || !player.sitting || player.movement != before || len(output.packets) != 0 { + t.Fatal("failed expiry leaked staged helper/rest changes or a removal packet", player.sitting, player.movement, output.packets) + } + if _, err := world.db.Exec("DROP TRIGGER fail_expiry"); err != nil { + t.Fatal(err) + } + world.advanceNanos(deadline.Add(time.Nanosecond)) + var remaining int + if err := world.db.QueryRow("SELECT count(*) FROM active_nanos WHERE character_id=1").Scan(&remaining); err != nil { + t.Fatal(err) + } + if len(player.activeNanos) != 0 || remaining != 0 || player.sitting || player.movement.components[0] != 3 || player.movement.turn != 1.5 || player.movement.vertical != -.8 || player.movement.verticalVelocity != -12 { + t.Fatal("retried expiry failed to restore the committed helper without resetting motion", player.sitting, player.activeNanos, player.movement, remaining) + } + }) + } +} + +func TestPlayerWorldEntryRestoresPersistedMovementRestriction(t *testing.T) { + for _, restart := range []bool{false, true} { + for _, running := range []bool{false, true} { + t.Run(fmt.Sprintf("restart%t/running%t", restart, running), func(t *testing.T) { + world, _ := newEquipmentWorld(t) + player := world.characters[1] + player.sitting, player.running = true, running + player.activeNanos = []activeNano{{program: 42110, caster: 1, remaining: 15 * time.Second}} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.savePosition_locked(player); err != nil { + t.Fatal(err) + } + delete(world.clients, 1) + if restart { + world = newTestInventoryServer(t) + } + + connection := connectZoningClient(t, world, true) + t.Cleanup(func() { + connection.Close() + deadline := time.Now().Add(5 * time.Second) + for time.Now().Before(deadline) { + world.mutex.Lock() + closed := world.clients[1] == nil + world.mutex.Unlock() + if closed { + return + } + time.Sleep(time.Millisecond) + } + t.Error("test world connection did not finish closing") + }) + + world.mutex.Lock() + defer world.mutex.Unlock() + player = world.characters[1] + if player.movement.components[0] != 1 || player.sitting || player.running != running || len(player.activeNanos) != 1 || player.activeNanos[0].expiresAt.IsZero() { + t.Fatal("world entry lost persisted permission, frozen helper or ground preference", player.sitting, player.running, player.activeNanos, player.movement) + } + }) + } + } +} diff --git a/server/player_movement.go b/server/player_movement.go @@ -62,6 +62,11 @@ func (movement *playerMovement) canSteerForward() bool { return movement.components[0] != 1 && movement.components[0] != 8 && movement.components[0] != 9 } +func (movement *playerMovement) blocksSit() bool { + // KKR360497A0 is also the actor's conditional FullStop predicate. + return movement.components[1] == 3 || movement.components[3] == 3 || movement.components[7] == 5 || movement.components[0] == 7 +} + func (player *character) predictedMovement(now time.Time) character { snapshot := *player if snapshot.followTarget == 0 { @@ -77,6 +82,33 @@ func (player *character) anchorMovement_locked(now time.Time) { player.movement.updatedAt = now } +func (player *character) updateMovementPermission(previous *character, now time.Time) { + if player.npc || player.health == 0 || player.movementRestricted() == previous.movementRestricted() { + return + } + // Settle the old controller on detached outcome state before changing permission. + snapshot := previous.predictedMovement(now) + player.position, player.rotation, player.movement, player.body = snapshot.position, snapshot.rotation, snapshot.movement, snapshot.body + if player.movementRestricted() { + player.restrictMovement() + return + } + player.movement.action(player, 34) + // Native permission restoration attempts water entry even when34 was rejected. + if player.movement.deepWater { + player.movement.action(player, 24) + } +} + +func (player *character) restrictMovement() { + // Actor71460 conditionally submits FullStop19 before permission freeze21. + player.movement.prepare(player, player.movement.updatedAt) + if player.movement.blocksSit() { + player.movement.action(player, 19) + } + player.movement.action(player, 21) +} + func predictedPosition_locked(player *character, now time.Time) [3]float32 { return player.predictedMovement(now).position } @@ -173,11 +205,6 @@ func (player *character) advanceMovement(now time.Time, target [3]float32) bool return heightLimited } movement.prepare(player, now) - if player.movementRestricted() { - movement.velocity = [3]float32{} - movement.speed = 0 - return heightLimited - } physical := player.geometry != nil && player.geometry.terrain[player.playfield] != nil if physical { _, physical = player.geometry.playfields[player.playfield] @@ -200,6 +227,9 @@ func (player *character) advanceMovement(now time.Time, target [3]float32) bool steering := false if movement.canSteerForward() && player.followTarget != 0 { // KKR48430 / QQR15fe0,15e90: four-unit arrival point, damping and Halt. + if player.movementRestricted() { + target = player.position + } delta := [3]float32{target[0] - player.position[0], target[1] - player.position[1], target[2] - player.position[2]} distance := vectorLength(delta) arrival := player.position @@ -441,6 +471,13 @@ func (movement *playerMovement) action(player *character, action uint32) bool { if accepted && old[0] != 7 { movement.components[9] = 1 } + case 19: + movement.components = [10]byte{old[0], 1, 0, 1, 0, 1, 0, 1, 0, 1} + if movement.speed != 0 { + movement.velocity, movement.speed = [3]float32{}, 0 + } + movement.direction = 1 + movement.forward, movement.strafe, movement.turn = 0, 0, 0 case 22, 23: player.running = action == 23 if old[0] == 7 { @@ -460,14 +497,17 @@ func (movement *playerMovement) action(player *character, action uint32) bool { movement.strafe = 0 } movement.vertical = 0 - case 31: + case 31, 34: movement.components[0] = 2 if player.running { movement.components[0] = 3 } + if action == 34 { + player.sitting = false + } case 28: // KKR helper360497A0 checks component states, independently of cached speed. - accepted = old[1] != 3 && old[3] != 3 && old[7] != 5 + accepted = !movement.blocksSit() if accepted { player.sitting = true movement.components[0] = 8 @@ -476,10 +516,8 @@ func (movement *playerMovement) action(player *character, action uint32) bool { movement.velocity, movement.speed = [3]float32{}, 0 } } - case 33: - // Features4-clear stand retains seated actor state; its frozen helper is pending. - accepted = !player.movementRestricted() - if accepted { + case 21, 33: + if action == 33 && !player.movementRestricted() { player.sitting = false if old[0] == 8 { movement.components[0] = 2 @@ -487,11 +525,27 @@ func (movement *playerMovement) action(player *character, action uint32) bool { movement.components[0] = 3 } } + break + } + // Frozen entry shares Halt and control cleanup, retaining actor rest and gravity. + // Source: client/game/kkr.dll/lifted-0022.c, sub_36046D60. + movement.components[0] = 1 + if movement.speed != 0 { + movement.velocity, movement.speed = [3]float32{}, 0 } + if old[0] == 7 { + position := player.position + position[1] += .1 + player.placePosition(position) + movement.vertical = 0 + movement.orientation = uint32(player.inventory.equipmentBonus(197) + player.nanoBonus(197)) + } + movement.direction = 1 + movement.forward, movement.strafe, movement.turn = 0, 0, 0 case 20: return true } - if accepted { + if accepted && action != 19 { movement.components[5] = old[3] } return accepted