tests/tprops.nim is new: the caps (per bucket, keys, values), the key rules, the registry (empty fallback, a registered key's kind and bucket), set/unset and the clone that keeps an edit away from the original bucket. ttokens covers radius, the three buckets, the status set (round trip, sorted, replaced rather than appended, removed by the FK cascade). tmoverules covers per-token radius, shrink/grow/squeeze, the no-crossing rule, the corner relaxation and the independence of the two sources; the old `blocked` tests became `stuckWalls`. tviews covers the bucket and source filtering, one `token` frame per change and the effective radius. tdb/tdb's fixtures move to step 6, and tprobing follows the rename.
497 lines
29 KiB
Nim
497 lines
29 KiB
Nim
import std/[unittest, math]
|
|
import geometry, moverules, refold, testutil
|
|
|
|
const R = 20.0
|
|
let me = Actor(role: rolePlayer, player: 1)
|
|
let other = Actor(role: rolePlayer, player: 2)
|
|
let gm = Actor(role: roleGM)
|
|
|
|
proc scene(walls: seq[Wall], toks: seq[Token] = @[]): Scene =
|
|
Scene(w: 4096, h: 4096, visionDefault: 400, walls: walls, tokens: toks)
|
|
proc tok(x, y: float, owner = 1, vision = false, vr = 0.0, radius = R): Token =
|
|
## `radius` is the token's *effective* radius (5.6): worldmap.ruleToken resolves the scene default.
|
|
Token(pos: (x, y), owner: owner, radius: radius, hasVision: vision, visionRadius: vr)
|
|
proc clearOfWalls(sc: Scene, t: Token): bool =
|
|
for w in sc.walls:
|
|
if w.blocks and segDist(t.pos, w.a, w.b) < t.radius: return false
|
|
true
|
|
proc ok(sc: Scene, s, d: Vec, r = R): bool = pathClear(sc.walls, s, d, r)
|
|
|
|
suite "pathClear, r = 0 (ported prototype move tests)":
|
|
let wall = W(0, -50, 0, 50)
|
|
let sc = scene(@[wall])
|
|
test "crossing blocked, parallel ok":
|
|
check not sc.ok((-10.0, 0.0), (10.0, 0.0), 0)
|
|
check sc.ok((-10.0, 0.0), (-10.0, 30.0), 0)
|
|
check sc.ok((-10.0, 60.0), (10.0, 60.0), 0) # passes beyond the end
|
|
test "grazing an endpoint is blocked":
|
|
check not sc.ok((-10.0, 50.0), (10.0, 50.0), 0)
|
|
check not sc.ok((-10.0, -60.0), (10.0, -40.0), 0) # crosses
|
|
test "no leak through shared vertex":
|
|
check not scene(@[W(0, -50, 0, 0), W(0, 0, 0, 50)]).ok((-10.0, 0.0), (10.0, 0.0), 0)
|
|
test "diagonal squeeze through corner vertex of L":
|
|
check not scene(@[W(0, 0, 50, 0), W(0, 0, 0, 50)]).ok((10.0, -10.0), (-10.0, 10.0), 0)
|
|
test "moving along a collinear wall is blocked":
|
|
check not sc.ok((0.0, -100.0), (0.0, 100.0), 0)
|
|
test "doors":
|
|
var d = scene(@[W(0, -10, 0, 10, true, false)])
|
|
check not d.ok((-5.0, 0.0), (5.0, 0.0), 0)
|
|
d.walls[0].open = true
|
|
check d.ok((-5.0, 0.0), (5.0, 0.0), 0)
|
|
test "zero-length move":
|
|
check sc.ok((-5.0, 0.0), (-5.0, 0.0), 0)
|
|
|
|
suite "capsule (swept circle), r = 20":
|
|
test "near pillar: circle overlapping blocked, clear ok (ported)":
|
|
let c = scene(box(600, 600, 680, 680))
|
|
check not c.ok((500.0, 640.0), (585.0, 640.0))
|
|
check c.ok((500.0, 640.0), (570.0, 640.0)) # 30 away
|
|
test "closed door blocks near, open door passes (ported)":
|
|
let cl = scene(@[W(0, 0, 0, 64, door = true)])
|
|
check not cl.ok((-50.0, 32.0), (10.0, 32.0))
|
|
check not cl.ok((-50.0, 32.0), (-10.0, 32.0))
|
|
check cl.ok((-50.0, 32.0), (-30.0, 32.0))
|
|
let op = scene(@[W(0, 0, 0, 64, door = true, open = true)])
|
|
check op.ok((-50.0, 32.0), (50.0, 32.0))
|
|
test "64px corridor and doorway passable on the centreline (ported)":
|
|
let c = scene(@[W(0, 0, 500, 0), W(0, 64, 500, 64)])
|
|
check c.ok((10.0, 32.0), (490.0, 32.0))
|
|
check c.ok((10.0, 32.0), (11.0, 32.0))
|
|
let door = scene(@[W(0, -200, 0, -32), W(0, 32, 0, 200)])
|
|
check door.ok((-30.0, 0.0), (30.0, 0.0))
|
|
test "corner clipping: path passes the wall end closer than r though both ends are clear":
|
|
let w = scene(@[W(0, 0, 0, 100)]) # wall end at (0,0)
|
|
let (s, d): (Vec, Vec) = (( -60.0, -10.0), (60.0, -10.0)) # passes 10 px past the end
|
|
check not w.ok(s, d)
|
|
check not moveBlockedOld(w.walls, s, d, R) # the prototype said clear: that was the H10 hole
|
|
check w.ok((-60.0, -25.0), (60.0, -25.0)) # 25 past the end: clear
|
|
test "parallel pass: r clear, just under r blocked (touching at exactly r is clear)":
|
|
let w = scene(@[W(0, 0, 200, 0)])
|
|
check w.ok((20.0, 20.0), (180.0, 20.0))
|
|
check not w.ok((20.0, 19.9), (180.0, 19.9))
|
|
check not w.ok((20.0, 20.0), (180.0, 19.0)) # tilts closer at the far end
|
|
test "diagonal squeeze past an L corner with a gap narrower than 2r is blocked":
|
|
let w = scene(@[W(0, 0, 50, 0), W(0, 0, 0, 50)])
|
|
check not w.ok((30.0, -30.0), (-30.0, 30.0))
|
|
test "leg of the path inside r of a non-start wall blocks even if start and end are clear":
|
|
let w = scene(@[W(100, -5, 100, 5)]) # tiny post mid-path
|
|
check not w.ok((0.0, 0.0), (200.0, 0.0))
|
|
check not w.ok((0.0, 15.0), (200.0, 15.0)) # 15 < 20 from the post
|
|
check w.ok((0.0, 26.0), (200.0, 26.0)) # 21 from the post's end
|
|
|
|
suite "token on / near a wall: escape (replaces the KNOWN LIMITATION pin)":
|
|
let sc = scene(@[W(0, -50, 0, 50)])
|
|
test "exactly on a wall: can step off perpendicular, either side, to a clear spot":
|
|
check sc.ok((0.0, 10.0), (30.0, 10.0))
|
|
check sc.ok((0.0, 10.0), (-30.0, 10.0))
|
|
check sc.ok((0.0, 10.0), (20.0, 10.0)) # exactly r away: clear
|
|
check sc.ok((0.0, 10.0), (25.0, 40.0)) # diagonal away
|
|
test "exactly on a wall: still refused when it would stay overlapped or run along/through":
|
|
check not sc.ok((0.0, 10.0), (1.0, 10.0)) # one pixel: dest still overlaps
|
|
check not sc.ok((0.0, 10.0), (19.0, 10.0))
|
|
check not sc.ok((0.0, 10.0), (0.0, 10.0)) # zero-length: stays overlapped
|
|
check not sc.ok((0.0, 10.0), (0.0, 80.0)) # along the wall's line (collinear overlap counts as crossing)
|
|
check not sc.ok((0.0, 10.0), (0.0, -10.0)) # along the wall, staying on it
|
|
test "r = 0: standing on a wall is not an escape case (touch blocks), as the prototype":
|
|
check not sc.ok((0.0, 10.0), (30.0, 10.0), 0)
|
|
test "overlapping 10 px off: may leave away from the wall, not cross it, not stay overlapped":
|
|
check sc.ok((10.0, 0.0), (40.0, 0.0))
|
|
check not sc.ok((10.0, 0.0), (15.0, 0.0))
|
|
check not sc.ok((10.0, 0.0), (-40.0, 0.0)) # through
|
|
check not sc.ok((1.0, 0.0), (-40.0, 0.0)) # 1 px off the wall: crossing at t > eps
|
|
check not sc.ok((1e-3, 0.0), (-40.0, 0.0)) # even 1e-3 px off
|
|
test "escaping one wall does not excuse another":
|
|
let two = scene(@[W(0, -50, 0, 50), W(60, -50, 60, 50)])
|
|
check two.ok((0.0, 10.0), (30.0, 10.0)) # 30 from the far wall: fine
|
|
check not two.ok((0.0, 10.0), (45.0, 10.0)) # clear of the first, 15 from the second
|
|
check two.ok((0.0, 10.0), (-30.0, 10.0)) # control: the other side is free
|
|
test "escape from a closed door; an open door never needed an escape":
|
|
var d = scene(@[W(0, -50, 0, 50, door = true)])
|
|
check d.ok((0.0, 0.0), (30.0, 0.0))
|
|
d.walls[0].open = true
|
|
check d.ok((0.0, 0.0), (1.0, 0.0))
|
|
test "overlapping at a wall end: leave past the end without crossing":
|
|
check sc.ok((5.0, 55.0), (5.0, 100.0)) # 5 off the line, 5 past the end: dist 7.07 < r, leaves along +y
|
|
check not sc.ok((5.0, 55.0), (5.0, 60.0)) # still within r of the end
|
|
check sc.ok((5.0, 55.0), (40.0, 80.0))
|
|
|
|
suite "move rules: player vs GM, step cap, uniform nack":
|
|
test "owner check: not yours is mkError, no position":
|
|
var s = scene(@[], @[tok(100, 100, owner = 2)])
|
|
let r = s.moveToken(me, 0, (110.0, 100.0))
|
|
check r.kind == mkError
|
|
check r.pos == (0.0, 0.0)
|
|
check s.tokens[0].pos == (100.0, 100.0)
|
|
check s.moveToken(me, 7, (1.0, 1.0)).kind == mkError # unknown token
|
|
check s.moveToken(other, 0, (110.0, 100.0)).kind == mkAck # the owner can
|
|
test "GM-controlled token (no owner): players get mkError":
|
|
var s = scene(@[], @[tok(100, 100, owner = NoOwner)])
|
|
check s.moveToken(me, 0, (110.0, 100.0)).kind == mkError
|
|
check s.moveToken(gm, 0, (110.0, 100.0)).kind == mkAck
|
|
test "step cap = scene default without vision, token vision radius with it":
|
|
var s = scene(@[], @[tok(500, 500), tok(500, 500, vision = true, vr = 100), tok(500, 500, vision = true, vr = 0)])
|
|
check s.moveToken(me, 0, (500.0 + 400, 500.0)).kind == mkAck # exactly the default cap
|
|
check s.moveToken(me, 0, (500.0 + 800.5, 500.0)).kind == mkNack # from 900: 400.5 > cap
|
|
check s.moveToken(me, 1, (600.0, 500.0)).kind == mkAck # exactly 100
|
|
check s.moveToken(me, 1, (600.0 + 100.01, 500.0)).kind == mkNack
|
|
check s.moveToken(me, 2, (500.0 + 400, 500.0)).kind == mkAck # vision flag, radius unset: default
|
|
check s.moveToken(me, 2, (500.0 + 400 + 400.5, 500.0)).kind == mkNack
|
|
check stepCap(s, s.tokens[1]) == 100
|
|
test "over-cap, wall, lock-flag and out-of-bounds nacks are identical":
|
|
var s = scene(@[W(200, 0, 200, 1000)], @[tok(100, 500), tok(100, 500), tok(100, 500)])
|
|
s.tokens[2].locked = true
|
|
let cap = s.moveToken(me, 0, (100.0 + 2000, 500.0)) # over cap, nothing in the way
|
|
let wal = s.moveToken(me, 1, (300.0, 500.0)) # in cap, through the wall
|
|
let flg = s.moveToken(me, 2, (130.0, 500.0)) # in cap, clear, but locked
|
|
let oob = s.moveToken(me, 0, (-5.0, 500.0))
|
|
let nan = s.moveToken(me, 0, (NaN, 500.0))
|
|
for r in [cap, wal, flg, oob, nan]:
|
|
check r == MoveResult(kind: mkNack, pos: (100.0, 500.0))
|
|
check cap == wal and wal == flg
|
|
check s.tokens[0].pos == (100.0, 500.0) and s.tokens[1].pos == (100.0, 500.0) # nothing mutated
|
|
test "an accepted move applies and echoes the destination":
|
|
var s = scene(@[W(200, 0, 200, 100)], @[tok(100, 500)])
|
|
let r = s.moveToken(me, 0, (150.0, 520.0))
|
|
check r == MoveResult(kind: mkAck, pos: (150.0, 520.0))
|
|
check s.tokens[0].pos == (150.0, 520.0)
|
|
test "player move honours walls (capsule) via moveToken":
|
|
var s = scene(@[W(500, 0, 500, 200)], @[tok(440, 100)])
|
|
check s.moveToken(me, 0, (490.0, 100.0)).kind == mkNack # would overlap
|
|
check s.moveToken(me, 0, (470.0, 100.0)).kind == mkAck
|
|
check s.moveToken(me, 0, (530.0, 100.0)).kind == mkNack # through
|
|
test "GM: ignores walls, step cap and the lock; bounds still apply":
|
|
var s = scene(@[W(200, 0, 200, 1000)], @[tok(100, 500, vision = true, vr = 50)])
|
|
s.tokens[0].stuckWalls = true
|
|
check s.moveToken(gm, 0, (300.0, 500.0)).kind == mkAck # through a wall
|
|
check s.moveToken(gm, 0, (3000.0, 3000.0)).kind == mkAck # far beyond the cap
|
|
check s.moveToken(gm, 0, (200.0, 500.0)).kind == mkAck # onto the wall
|
|
check s.moveToken(gm, 0, (-1.0, 0.0)) == MoveResult(kind: mkNack, pos: (200.0, 500.0))
|
|
check s.moveToken(gm, 0, (5000.0, 0.0)).kind == mkNack
|
|
check s.tokens[0].stuckWalls # ended on the wall: GM move set the flag
|
|
check s.moveToken(gm, 9, (1.0, 1.0)).kind == mkError
|
|
|
|
suite "stuck/squeezed statuses (walls source)":
|
|
proc stuckSc(): Scene = scene(@[], @[tok(100, 100), tok(100, 300, owner = NoOwner), tok(900, 900)])
|
|
test "wall added within r of the circle (centre not on it) sets stuck; exactly r does not":
|
|
var s = stuckSc()
|
|
discard s.addWall(W(115, 0, 115, 200)) # 15 from token 0's centre: circle overlaps
|
|
check s.tokens[0].stuckWalls
|
|
check not s.tokens[1].stuckWalls # wall ends at y=200, token 1 is at y=300
|
|
check not s.tokens[2].stuckWalls
|
|
var t = stuckSc()
|
|
discard t.addWall(W(120, 0, 120, 200)) # exactly r: clear
|
|
check not t.tokens[0].stuckWalls
|
|
test "GM-controlled tokens get the flag too; wall bbox does not matter, distance does":
|
|
var s = stuckSc()
|
|
discard s.addWall(W(0, 310, 200, 310))
|
|
check s.tokens[1].stuckWalls and not s.tokens[0].stuckWalls
|
|
test "open door added or opened never sets; closing a door on a token pushes it, never sets":
|
|
var s = stuckSc()
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
check not s.tokens[0].stuckWalls
|
|
check s.setDoor(id, false)
|
|
check not s.tokens[0].stuckWalls
|
|
check s.tokens[0].pos != (100.0, 100.0)
|
|
test "a stuck token: player moves refused, GM move allowed":
|
|
var s = stuckSc()
|
|
discard s.addWall(W(110, 0, 110, 200))
|
|
check s.moveToken(me, 0, (40.0, 100.0)).kind == mkNack # would be a perfectly clear step
|
|
check s.tokens[0].pos == (100.0, 100.0)
|
|
check s.moveToken(gm, 0, (40.0, 100.0)).kind == mkAck # GM bypasses the lock
|
|
check not s.tokens[0].stuckWalls # and landed clear of every wall: cleared
|
|
test "cleared by removing the wall; unrelated removals keep it":
|
|
var s = stuckSc()
|
|
let a = s.addWall(W(110, 0, 110, 200))
|
|
let b = s.addWall(W(2000, 0, 2000, 200))
|
|
check s.removeWall(b)
|
|
check s.tokens[0].stuckWalls
|
|
check s.removeWall(a)
|
|
check not s.tokens[0].stuckWalls
|
|
check s.moveToken(me, 0, (40.0, 100.0)).kind == mkAck
|
|
check not s.removeWall(5)
|
|
test "cleared by opening the door; a second open is a no-op":
|
|
var s = stuckSc()
|
|
let id = s.addWall(W(110, 0, 110, 200, door = true))
|
|
check s.tokens[0].stuckWalls
|
|
check s.setDoor(id, true)
|
|
check not s.tokens[0].stuckWalls
|
|
check s.setDoor(id, true)
|
|
check not s.setDoor(77, true)
|
|
var w = stuckSc()
|
|
check not w.setDoor(w.addWall(W(110, 0, 110, 200)), true) # a plain wall is not a door
|
|
check w.tokens[0].stuckWalls
|
|
test "cleared by the GM; not re-set by itself":
|
|
var s = stuckSc()
|
|
discard s.addWall(W(110, 0, 110, 200))
|
|
s.gmClearBlocked(0)
|
|
check not s.tokens[0].stuckWalls
|
|
check s.moveToken(me, 0, (100.0, 150.0)).kind == mkNack # clear flag, but the capsule still refuses (overlap, dest overlaps)
|
|
check s.moveToken(me, 0, (40.0, 100.0)).kind == mkAck # and it can walk out (escape)
|
|
test "wall update = remove then add":
|
|
var s = stuckSc()
|
|
let id = s.addWall(W(110, 0, 110, 200))
|
|
check s.updateWall(id, W(500, 0, 500, 200)) # moved away: clears
|
|
check not s.tokens[0].stuckWalls
|
|
check s.updateWall(id, W(105, 0, 105, 200)) # moved onto the token: sets
|
|
check s.tokens[0].stuckWalls
|
|
check s.updateWall(id, W(110, 0, 110, 200, door = true, open = true)) # became an open door: clears
|
|
check not s.tokens[0].stuckWalls
|
|
check not s.updateWall(9, W(0, 0, 1, 1))
|
|
test "GM placement and GM move onto a wall: blocked; player escape works only after a GM clear":
|
|
var s = scene(@[W(500, 0, 500, 1000)])
|
|
let i = s.addToken(tok(500, 400)) # placed exactly on the wall
|
|
check s.tokens[i].stuckWalls
|
|
check s.moveToken(me, i, (530.0, 400.0)).kind == mkNack # stuck
|
|
s.gmClearBlocked(i)
|
|
check s.moveToken(me, i, (530.0, 400.0)).kind == mkAck # escape sideways
|
|
check s.moveToken(gm, i, (505.0, 400.0)).kind == mkAck # GM puts it back within r
|
|
check s.tokens[i].stuckWalls
|
|
s.gmClearBlocked(i)
|
|
check s.moveToken(me, i, (505.0, 450.0)).kind == mkNack # still overlapped: refused
|
|
check s.moveToken(me, i, (540.0, 400.0)).kind == mkAck # but it can leave
|
|
test "Q14: a door closed 10 px from a token: pushed to its side, clear by r, not blocked; GM-owned too":
|
|
var s = scene(@[], @[tok(110, 100), tok(90, 100, owner = NoOwner), tok(130, 100)])
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
var pushed: seq[Push]
|
|
check s.setDoor(id, false, pushed)
|
|
check pushed.len == 2 and pushed[0].ti == 0 and pushed[1].ti == 1 # token 2 is exactly r away: untouched
|
|
check s.tokens[0].pos == pushed[0].pos and s.tokens[1].pos == pushed[1].pos
|
|
check s.tokens[0].pos.x >= 120.0 and s.tokens[0].pos.x < 120.001 and s.tokens[0].pos.y == 100.0
|
|
check s.tokens[1].pos.x <= 80.0 and s.tokens[1].pos.x > 79.999
|
|
check s.tokens[2].pos == (130.0, 100.0)
|
|
for t in s.tokens: check not t.stuckWalls and clearOfWalls(s, t)
|
|
check s.moveToken(me, 0, (150.0, 100.0)).kind == mkAck
|
|
test "push: centre on the door line -> side of the previous position; no history -> left of a->b":
|
|
for (prev, wantLeft) in [((130.0, 100.0), false), ((60.0, 100.0), true)]: # door runs +y: left = -x
|
|
var s = scene(@[], @[tok(prev[0], prev[1])])
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
check s.moveToken(me, 0, (100.0, 100.0)).kind == mkAck # lands in the open doorway
|
|
check s.setDoor(id, false)
|
|
check (s.tokens[0].pos.x < 100.0) == wantLeft
|
|
check abs(s.tokens[0].pos.x - 100.0) >= R
|
|
var s = scene(@[], @[tok(100, 100)])
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
check s.setDoor(id, false)
|
|
check s.tokens[0].pos.x < 100.0 and not s.tokens[0].stuckWalls # default: left side
|
|
test "push: past the end of the door the offset shrinks (minimal), still >= r from the door":
|
|
var s = scene(@[], @[tok(110, 160)]) # 10 beyond the end a-b = (100,50)-(100,150): dist 14.1 < 20
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
check s.setDoor(id, false)
|
|
let d = segDist(s.tokens[0].pos, (100.0, 50.0), (100.0, 150.0))
|
|
check d >= R and d < R + 1e-4
|
|
check s.tokens[0].pos.x > 110.0 and s.tokens[0].pos.y == 160.0 # perpendicular only
|
|
test "push: one side blocked by another wall -> the other side; out of bounds -> the other side":
|
|
var s = scene(@[W(125, 0, 125, 300)], @[tok(110, 100)]) # +x side lands at 120, 5 from the wall
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
check s.setDoor(id, false)
|
|
check s.tokens[0].pos.x <= 80.0 and not s.tokens[0].stuckWalls
|
|
var b = scene(@[], @[tok(110, 100)])
|
|
let j = b.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
b.w = 110 # +x side (120) is out of bounds
|
|
check b.setDoor(j, false)
|
|
check b.tokens[0].pos.x <= 80.0 and not b.tokens[0].stuckWalls
|
|
test "push: both sides invalid -> squeezed in place; door open -> still squeezed (KEEP); GM can move it":
|
|
var s = scene(@[W(125, 0, 125, 300), W(75, 0, 75, 300)], @[tok(110, 100)])
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
var pushed: seq[Push]
|
|
check s.setDoor(id, false, pushed)
|
|
check pushed.len == 0 and s.tokens[0].squeezedWalls and not s.tokens[0].stuckWalls
|
|
check s.tokens[0].pos == (110.0, 100.0)
|
|
check s.moveToken(me, 0, (112.0, 100.0)).kind == mkNack
|
|
check s.setDoor(id, true)
|
|
check s.tokens[0].squeezedWalls # 125-wall still overlaps (KEEP)
|
|
check s.moveToken(gm, 0, (400.0, 100.0)).kind == mkAck
|
|
check not s.tokens[0].squeezedWalls # GM moved it clear
|
|
test "push: wall added on a token still sticks it (regression); closing on nobody pushes nobody":
|
|
var s = scene(@[], @[tok(110, 100)])
|
|
discard s.addWall(W(100, 50, 100, 150))
|
|
check s.tokens[0].stuckWalls and s.tokens[0].pos == (110.0, 100.0)
|
|
var t = scene(@[], @[tok(300, 300)])
|
|
let id = t.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
var pushed: seq[Push]
|
|
check t.setDoor(id, false, pushed) and pushed.len == 0
|
|
test "doorway: token in an open doorway, door closes -> pushed clear, free; door reopens/closes again -> unchanged":
|
|
var s = scene(@[], @[tok(100, 100)])
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
check s.setDoor(id, false)
|
|
check not s.tokens[0].stuckWalls
|
|
let p = s.tokens[0].pos
|
|
check s.moveToken(me, 0, (p.x - 40.0, 100.0)).kind == mkAck
|
|
check s.setDoor(id, true) and s.setDoor(id, false)
|
|
check s.tokens[0].pos.x == p.x - 40.0
|
|
test "KEEP: opening one door / removing one wall while another overlaps -> still blocked; last one frees":
|
|
var s = scene(@[], @[tok(100, 100)])
|
|
let a = s.addWall(W(110, 0, 110, 200))
|
|
let door = s.addWall(W(100, 0, 100, 200, door = true))
|
|
check s.tokens[0].stuckWalls
|
|
check s.setDoor(door, true)
|
|
check s.tokens[0].stuckWalls # plain wall still overlaps
|
|
check s.moveToken(me, 0, (40.0, 100.0)).kind == mkNack
|
|
check s.removeWall(a)
|
|
check not s.tokens[0].stuckWalls
|
|
var t = scene(@[], @[tok(100, 100)])
|
|
let x = t.addWall(W(110, 0, 110, 200))
|
|
let y = t.addWall(W(90, 0, 90, 200))
|
|
check t.removeWall(y)
|
|
check t.tokens[0].stuckWalls
|
|
check t.removeWall(x)
|
|
check not t.tokens[0].stuckWalls
|
|
test "KEEP: wall update away from one of two overlapping walls keeps blocked":
|
|
var s = scene(@[], @[tok(100, 100)])
|
|
let a = s.addWall(W(110, 0, 110, 200))
|
|
let b = s.addWall(W(90, 0, 90, 200))
|
|
check s.updateWall(b, W(500, 0, 500, 200))
|
|
check s.tokens[0].stuckWalls
|
|
check s.updateWall(a, W(500, 0, 500, 100))
|
|
check not s.tokens[0].stuckWalls
|
|
test "GM moves a stuck token clear -> free; to another wall-overlapping spot -> still blocked":
|
|
var s = scene(@[W(110, 0, 110, 200), W(500, 0, 500, 200)], @[])
|
|
let i = s.addToken(tok(100, 100))
|
|
check s.tokens[i].stuckWalls
|
|
check s.moveToken(gm, i, (505.0, 100.0)).kind == mkAck
|
|
check s.tokens[i].stuckWalls # other wall overlaps
|
|
check s.moveToken(gm, i, (300.0, 100.0)).kind == mkAck
|
|
check not s.tokens[i].stuckWalls
|
|
check s.moveToken(me, i, (330.0, 100.0)).kind == mkAck
|
|
test "GM drops a token inside a wall -> blocked; a door counts only while closed":
|
|
var s = scene(@[W(110, 0, 110, 200, door = true, open = true)], @[tok(300, 300), tok(100, 100)])
|
|
check not s.tokens[1].stuckWalls
|
|
check s.moveToken(gm, 0, (100.0, 100.0)).kind == mkAck
|
|
check not s.tokens[0].stuckWalls # open door: no wall
|
|
check s.setDoor(0, false) # both pushed clear, none stuck
|
|
check not s.tokens[0].stuckWalls and not s.tokens[1].stuckWalls
|
|
check s.moveToken(gm, 0, (112.0, 100.0)).kind == mkAck # GM drop back inside the closed door: stuck
|
|
check s.tokens[0].stuckWalls
|
|
check s.setDoor(0, true)
|
|
check not s.tokens[0].stuckWalls
|
|
var t = scene(@[W(110, 0, 110, 200)], @[tok(300, 300)])
|
|
check t.moveToken(gm, 0, (100.0, 100.0)).kind == mkAck
|
|
check t.tokens[0].stuckWalls
|
|
test "GM manual clear inside a wall: player escapes sideways, cannot cross":
|
|
var s = scene(@[W(500, 0, 500, 1000)], @[tok(500, 400)])
|
|
check s.moveToken(gm, 0, (505.0, 400.0)).kind == mkAck
|
|
check s.tokens[0].stuckWalls
|
|
s.gmClearBlocked(0)
|
|
check not s.tokens[0].stuckWalls
|
|
check s.moveToken(me, 0, (530.0, 400.0)).kind == mkAck # sideways out
|
|
var t = scene(@[W(500, 0, 500, 1000)], @[tok(505, 400)])
|
|
t.gmClearBlocked(0)
|
|
check t.moveToken(me, 0, (470.0, 400.0)).kind == mkNack # across the wall
|
|
check t.moveToken(me, 0, (510.0, 450.0)).kind == mkNack # destination still overlapping
|
|
test "an unrelated wall change elsewhere does not re-block a GM-cleared token":
|
|
var s = scene(@[W(110, 0, 110, 200)], @[tok(100, 100)])
|
|
s.tokens[0].stuckWalls = true
|
|
s.gmClearBlocked(0)
|
|
let far = s.addWall(W(2000, 0, 2000, 200))
|
|
check not s.tokens[0].stuckWalls
|
|
check s.updateWall(far, W(2100, 0, 2100, 200))
|
|
check s.removeWall(far)
|
|
check not s.tokens[0].stuckWalls
|
|
let d = s.addWall(W(3000, 0, 3000, 200, door = true))
|
|
check s.setDoor(d, true) and s.setDoor(d, false)
|
|
check not s.tokens[0].stuckWalls
|
|
|
|
suite "seed scene":
|
|
test "no escape hatch: a player cannot walk through any wall of a boxed room":
|
|
var s = scene(box(0, 0, 400, 400), @[tok(200, 200)])
|
|
var p: Vec = (200.0, 200.0)
|
|
for d in [(500.0, 200.0), (200.0, -100.0), (-100.0, 200.0), (200.0, 500.0), (390.0, 200.0), (385.0, 385.0)]:
|
|
let r = s.moveToken(me, 0, d)
|
|
check r.kind == mkNack
|
|
check r.pos == p
|
|
check s.moveToken(me, 0, (370.0, 200.0)).kind == mkAck # 30 from the wall
|
|
|
|
suite "per-token radius (5.6, #4)":
|
|
test "the overlap test, the escape and the push use the token's own radius":
|
|
# a token the scene default (20) would refuse, but whose own radius is 10, fits in the gap
|
|
var s = scene(@[W(0, -100, 0, 100)])
|
|
var small = tok(15, 0, radius = 10.0)
|
|
s.tokens = @[small]
|
|
check s.moveToken(me, 0, (15.0, 40.0)).kind == mkAck # 15 away: clear for r=10
|
|
var big = scene(@[W(0, -100, 0, 100)], @[tok(15, 0, radius = 20.0)])
|
|
check big.moveToken(me, 0, (15.0, 40.0)).kind == mkNack # still overlapping with r=20
|
|
test "a big token is refused where a small one passes, on the same geometry":
|
|
var s = scene(@[W(0, -100, 0, 100)], @[tok(30, 0, radius = 40.0)])
|
|
check not s.tokens[0].stuckWalls # set directly, not by the rules
|
|
check s.moveToken(me, 0, (30.0, 60.0)).kind == mkNack # escaping, but the destination overlaps
|
|
check s.moveToken(me, 0, (90.0, 0.0)).kind == mkAck # away from the wall: clear of r=40
|
|
test "the door push clears the token's own radius":
|
|
var s = scene(@[], @[tok(110, 100, radius = 40.0)])
|
|
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
|
|
check s.setDoor(id, false)
|
|
check segDist(s.tokens[0].pos, (100.0, 50.0), (100.0, 150.0)) >= 40.0
|
|
check s.tokens[0].pos.x >= 140.0
|
|
|
|
suite "resize: shrink never pushes, grow pushes or squeezes (5.6)":
|
|
test "a grow that already fits does not move the token":
|
|
var s = scene(@[W(0, -100, 0, 100)], @[tok(400, 0, radius = 20.0)])
|
|
let before = s.tokens[0].pos
|
|
check s.resizeToken(0, 30.0) == rkUnchanged
|
|
check s.tokens[0].pos == before and s.tokens[0].radius == 30.0
|
|
test "grow inside r of a wall pushes it out by the minimal perpendicular distance":
|
|
var s = scene(@[W(0, -100, 0, 100)], @[tok(15, 0, radius = 10.0)])
|
|
check s.tokens[0].stuckWalls == false
|
|
check s.resizeToken(0, 30.0) == rkPushed
|
|
check s.tokens[0].radius == 30.0
|
|
check abs(s.tokens[0].pos.x - 30.0) <= 1e-4 # 30 from the wall, on the side it was on
|
|
check s.tokens[0].pos.y == 0.0 # perpendicular: no along-axis drift
|
|
check s.tokens[0].prev == (15.0, 0.0) and s.tokens[0].hasPrev
|
|
test "grow with no room on either side squeezes the token and leaves it in place":
|
|
var s = scene(@[W(0, -300, 0, 300), W(60, -300, 60, 300)], @[tok(30, 0, radius = 10.0)])
|
|
check s.resizeToken(0, 40.0) == rkSqueezed
|
|
check s.tokens[0].squeezedWalls and not s.tokens[0].stuckWalls
|
|
check s.tokens[0].pos == (30.0, 0.0)
|
|
check s.moveToken(me, 0, (31.0, 0.0)).kind == mkNack # locked for its player
|
|
test "a squeeze from a failed grow clears when a later shrink ends the overlap":
|
|
var s = scene(@[W(0, -300, 0, 300), W(60, -300, 60, 300)], @[tok(30, 0, radius = 10.0)])
|
|
check s.resizeToken(0, 40.0) == rkSqueezed
|
|
check s.resizeToken(0, 10.0) == rkUnchanged
|
|
check not s.tokens[0].squeezedWalls # shrink ended the overlap: CLEAR
|
|
check s.moveToken(me, 0, (45.0, 0.0)).kind == mkAck # and the token is free again
|
|
test "a shrink that still overlaps keeps the stuck entry":
|
|
var s = scene(@[W(0, -300, 0, 300)], @[tok(15, 0, radius = 30.0)])
|
|
s.tokens[0].stuckWalls = true # as a wall add would have set it
|
|
check s.resizeToken(0, 20.0) == rkUnchanged
|
|
check s.tokens[0].stuckWalls # 15 < 20: still overlapping
|
|
check s.resizeToken(0, 10.0) == rkUnchanged
|
|
check not s.tokens[0].stuckWalls # 15 >= 10: clear
|
|
test "a grow out of a corner relaxes off both walls":
|
|
let corner = @[W(1000, 900, 1000, 1100), W(900, 1000, 1100, 1000)]
|
|
var s = scene(corner, @[tok(985, 985, radius = 10.0)])
|
|
check s.resizeToken(0, 30.0) == rkPushed
|
|
check segDist(s.tokens[0].pos, (1000.0, 900.0), (1000.0, 1100.0)) >= 30.0 - 1e-6
|
|
check segDist(s.tokens[0].pos, (900.0, 1000.0), (1100.0, 1000.0)) >= 30.0 - 1e-6
|
|
check s.tokens[0].pos.x < 1000.0 and s.tokens[0].pos.y < 1000.0 # pushed away from both
|
|
test "a grow that would have to cross a wall squeezes instead of jumping through it":
|
|
# a corridor narrower than the grown token: the relaxation may not step across x=500 or x=540
|
|
var s = scene(@[W(500, 0, 500, 900), W(540, 0, 540, 900)], @[tok(505, 400, radius = 15.0)])
|
|
check s.resizeToken(0, 40.0) == rkSqueezed
|
|
check s.tokens[0].squeezedWalls and not s.tokens[0].stuckWalls
|
|
check s.tokens[0].pos == (505.0, 400.0)
|
|
test "a grow that would leave the world squeezes instead of teleporting the token":
|
|
var s = scene(@[W(20, -400, 20, 400)], @[tok(10, 0, radius = 5.0)])
|
|
s.w = 15.0 # 25 px either side, r = 30 needs 30
|
|
check s.resizeToken(0, 30.0) == rkSqueezed
|
|
check s.tokens[0].squeezedWalls and s.tokens[0].pos == (10.0, 0.0)
|
|
test "resize ignores an out-of-range token index":
|
|
var s = scene(@[], @[])
|
|
check s.resizeToken(3, 30.0) == rkUnchanged
|
|
|
|
suite "status sources (5.5: walls and GM are independent entries)":
|
|
test "a GM-sourced lock refuses player moves without touching the walls entries":
|
|
var s = scene(@[], @[tok(100, 100)])
|
|
s.tokens[0].locked = true # what a GM-sourced entry means to the rules
|
|
check s.moveToken(me, 0, (140.0, 100.0)).kind == mkNack
|
|
check s.moveToken(gm, 0, (140.0, 100.0)).kind == mkAck # the GM always moves it
|
|
check not s.tokens[0].stuckWalls
|
|
test "a wall added over a GM-locked token only adds the walls entry":
|
|
var s = scene(@[], @[tok(100, 100)])
|
|
s.tokens[0].locked = true
|
|
discard s.addWall(W(110, 0, 110, 200))
|
|
check s.tokens[0].stuckWalls
|
|
test "the GM clear of the walls entries leaves a GM-sourced entry alone (no rule runs)":
|
|
var s = scene(@[W(110, 0, 110, 200)], @[tok(100, 100)])
|
|
s.tokens[0].stuckWalls = true
|
|
s.gmClearBlocked(0)
|
|
check not s.tokens[0].stuckWalls and not s.tokens[0].squeezedWalls
|