UW1 PORT -- PLAYER PHYSICS / COLLISION FUNCTIONS
(branch player-movement; source uw.c. "// PHYSICS" comments mark the key lines.)

CALL TREE (per movement tick)
  movement_tick
   -> apply_movement_tick
       -> apply_heading_turn            heading / turn rate
       -> movement_collision_sweep      (was FUN_0005878c) per-tick driver
           -> movement_sweep_setup      (was FUN_00058e08) velocity, sub-step count,
                                        target heights; gates gravity on DAT_0020488a
               -> sweep_init_position   (was FUN_00058878) movement block -> working set
               -> collision_build_height_field  (was FUN_00050d78) 5x5 corner height field
                   -> collision_corner_flags    (was FUN_00050c18) slope/blocked flag word
                   -> collision_sample_floor_height (was FUN_00050984) per-corner floor Z
               -> collision_height_envelope (was FUN_000518c0) -> DAT_002049d4/d6/d8/d9/dc..de
               -> reticle_object_pick   (was FUN_0005898c) picks target floor _DAT_0008699b
           -> loop DAT_00086990+1 times:
               sweep_step               (was FUN_0005a550) advance one sub-step
                 -> sweep_integrate_substep (was FUN_000595d4) HORIZONTAL X/Y integrate
                 -> sweep_step_vertical   (was FUN_0005a348) VERTICAL integrate
                                           (gravity/climb) -- only when
                                           *(DAT_00204874+10) (DAT_0020488a) != 0
                     -> sweep_land_on_surface (was FUN_00059d20) floor+ceiling snap
                     -> sweep_integrate_substep
               sweep_apply_collision    (was FUN_0005ad18) act on flags: stop / slide / step
                 -> sweep_collision_flags (was FUN_0005a6bc) build block/step/fall flag word
                 -> sweep_slide_along_wall  (was FUN_00059b7c) slide along a solid face
                     -> sweep_deflect_heading (was FUN_0005989c) deflect heading vs normal
                 -> sweep_restart_remaining (was FUN_0005932c) re-seed the leftover move
                 -> sweep_kill_velocity     (was FUN_000593c0) zero all velocity (hard hit)
                 -> sweep_apply_knockback   (was FUN_00059c38) recoil / stagger set-up
           -> sweep_writeback_position   (was FUN_00059488) working set -> movement block
   -> FUN_0006907c                       animation: knockback / stagger / shove effects
                                         (NOT floor gravity)

KEY STATE
  DAT_0008697c[0..2]   swept X, Y, foot Z (1/8-tile units)   [foot Z also read as
                        *(short*)((char*)DAT_0008697c + 4) -- byte offset, == [2]]
  DAT_00086980/82/84   X / Y / Z sub-unit accumulators
  DAT_0008698a         signed vertical velocity for the sweep (+/-0x800 seed)
  DAT_0020488a         "vertical motion active" flag (= *(DAT_00204874+10)); gates gravity
  _DAT_000869a1        vertical rate (gravity accel / climb speed), per sweep,
                        derived from DAT_0020488a in movement_sweep_setup
  _DAT_0008699b        target surface height (floor when falling, ceiling when rising)
  DAT_00086990         sub-step count for the tick (= horizontal distance / 0x2000)
  DAT_00086992         horizontal step magnitude remainder
  DAT_002049d8/d9      destination tile floor height (envelope)
  DAT_002049d4 & 4     "walkable / auto-stick floor" -> step resolver snaps instantly
  byte DAT_00204874+0x26  player height (head clearance)
  byte DAT_00204874+0x27  step up/down limit
  byte DAT_00204874+0x25  wall-vs-step threshold
  DAT_0008699f/869a0   ceiling clearance (CONCAT11) for the head-fits test

FALL PHYSICS  (fixed -- repo memory.md UPDATE 30, commits 95670c7 + fd862cf)
  How a gravity fall runs:
   - sweep_apply_collision arms it: a sub-step that returns fully blocked
     (flag 0x1000) sets movement block +0x10 (DAT_00204890) = -4.
   - movement_sweep_setup integrates it every tick:
        DAT_00086978[2] += remaining(+0x12) * (+0x10)
     and DAT_00086978[2] IS +0xa (DAT_0020488a) -- DAT_00086978 = (short*)(block+6),
     so [2] = *(short*)(block+0xa). So +0xa accumulates downward velocity.
   - It then derives the 16-bit accel rate _DAT_000869a1 from +0xa and the
     horizontal distance (u16, NOT a byte -- do not sign-extend the low byte).
   - sweep_step dispatches to sweep_step_vertical while +0xa != 0.
   - sweep_step_vertical moves the foot by ~(_DAT_000869a1*0x20 + rem) >> 11
     per sub-step; when the step would cross _DAT_0008699b it calls
     sweep_land_on_surface, which snaps the foot and (our fix) clears +0xa,
     +0x10 and the airborne state byte +0x28 (0x10 -> 8).

  The ledge walk never reached this because sweep_collision_flags' auto-stick
  clause (DAT_002049d4 & 4) snapped the foot onto ANY lower floor in one tick.
  FIX: restrict that clause to `footZ - floorZ <= step-down limit (byte +0x27)`
  so a bigger drop falls through to the blocked path and the existing hook
  arms the fall. See set_locomotion_state (was FUN_0003c524): it re-arms
  +0x10 = -4 every tick while +0x28 says airborne, hence the state reset on
  landing.

  Also fixed earlier this pass: sweep_step called sweep_step_vertical() and
  sweep_step_vertical called sweep_integrate_substep() with Ghidra-dropped
  args -- the vertical integrator ran with a garbage direction/scale.
  Now both forward param_1.

RELATED FIXES ALREADY ON THIS BRANCH (repo memory.md UPDATEs 21-28)
  DAT_00086987 alias (reversed forward), sine-table stride (turning), the
  0x86998 reticle record, the 0x202bf8 corner field + DAT_00202c78, the
  DAT_0008697c+4 double-scale, and the "no-feature fallback -> DAT_002049d9"
  (float -> fall to floor).
