136 lines
6 KiB
Text
136 lines
6 KiB
Text
# compass_test.ludic - a viewer at (vx, vz) facing yaw with a compass of `tier`, and two providers:
|
|
# the places (a camp ahead, a sign west, a far legend) and the objective. The tier gate, the order
|
|
# and the cap, bearings and distances, the tracked mark, a capture, the radar's tiers, the points.
|
|
import "ludic.compass"
|
|
import "ludic.base"
|
|
program CompassTest {
|
|
numbers float
|
|
|
|
state CompasstestState {
|
|
vx: float = 0.0
|
|
vz: float = 0.0
|
|
yaw: float = 0.0
|
|
tier: int = 4
|
|
objective: bool = true
|
|
}
|
|
|
|
function fk_x(compasstest_st: CompasstestState) -> float { return compasstest_st.vx }
|
|
function fk_z(compasstest_st: CompasstestState) -> float { return compasstest_st.vz }
|
|
function fk_yaw(compasstest_st: CompasstestState) -> float { return compasstest_st.yaw }
|
|
function fk_tier(compasstest_st: CompasstestState) -> int { return compasstest_st.tier }
|
|
bind CompassWorld { x: fn fk_x, z: fn fk_z, yaw: fn fk_yaw, tier: fn fk_tier }
|
|
|
|
function places(compass_st: mut CompassState) -> void {
|
|
compass_mark(compass_st, 0.0, -100.0, 1, 10, 1, COMPASS_PLAIN, "camp")
|
|
compass_mark(compass_st, -50.0, 0.0, 2, 11, 2, COMPASS_PLAIN, "sign")
|
|
compass_mark(compass_st, 0.0, 300.0, 3, 12, 4, COMPASS_PLAIN, "legend")
|
|
compass_mark(compass_st, 10.0, 10.0, 4, 13, 1, COMPASS_NOTE, "my mark")
|
|
}
|
|
function goal(compass_st: mut CompassState, compasstest_st: CompasstestState) -> void { if compasstest_st.objective { compass_mark(compass_st, 80.0, 0.0, 5, 14, 2, COMPASS_TRACKED, "the dock") } }
|
|
def CompassProviders places { gather: fn places }
|
|
def CompassProviders goal { gather: fn goal }
|
|
|
|
function fresh(compass_st: mut CompassState, compasstest_st: mut CompasstestState) -> void {
|
|
compass_config(compass_st, 64)
|
|
compass_config_radar(compass_st, [0.0, 0.0, 0.0, 120.0, 260.0], 2)
|
|
compasstest_st.vx = 0.0
|
|
compasstest_st.vz = 0.0
|
|
compasstest_st.yaw = 0.0
|
|
compasstest_st.tier = 4
|
|
compasstest_st.objective = true
|
|
}
|
|
function labels(compass_st: CompassState) -> string {
|
|
var s = ""
|
|
for i in 0 .. compass_count(compass_st) { s = s + compass_at(compass_st, i).label + ";" }
|
|
return s
|
|
}
|
|
|
|
test "every provider is asked, the tracked mark first, then the player's, then the rest in order" (compass_st: mut CompassState, compasstest_st: mut CompasstestState) {
|
|
fresh(compass_st, compasstest_st)
|
|
compass_gather(compass_st)
|
|
expect_eq(compass_count(compass_st), 5)
|
|
expect(labels(compass_st) == "the dock;my mark;camp;sign;legend;")
|
|
expect_eq(compass_tracked(compass_st), 0)
|
|
}
|
|
|
|
test "a mark shows from its tier up, and without a compass nothing is gathered" (compass_st: mut CompassState, compasstest_st: mut CompasstestState) {
|
|
fresh(compass_st, compasstest_st)
|
|
compasstest_st.tier = 1
|
|
compass_gather(compass_st)
|
|
expect(labels(compass_st) == "my mark;camp;")
|
|
expect_eq(compass_tracked(compass_st), -1)
|
|
compasstest_st.tier = 0
|
|
compass_gather(compass_st)
|
|
expect_eq(compass_count(compass_st), 0)
|
|
}
|
|
|
|
test "past the cap the lowest priorities go" (compass_st: mut CompassState, compasstest_st: mut CompasstestState) {
|
|
fresh(compass_st, compasstest_st)
|
|
compass_config(compass_st, 2)
|
|
compass_gather(compass_st)
|
|
expect(labels(compass_st) == "the dock;my mark;")
|
|
}
|
|
|
|
test "a bearing is from the viewer's facing, a distance from where it stands" (compass_st: mut CompassState, compasstest_st: mut CompasstestState) {
|
|
fresh(compass_st, compasstest_st)
|
|
compass_gather(compass_st)
|
|
expect_near(compass_bearing(compass_st, 2), 0.0, 0.001)
|
|
expect_near(compass_dist(compass_st, 2), 100.0, 0.01)
|
|
expect_near(compass_bearing(compass_st, 3), 1.5708, 0.001)
|
|
expect_near(compass_bearing(compass_st, 0), -1.5708, 0.001)
|
|
compasstest_st.yaw = 1.5708
|
|
expect_near(compass_bearing(compass_st, 3), 0.0, 0.001)
|
|
expect_near(compass_bearing(compass_st, 2), -1.5708, 0.001)
|
|
compasstest_st.vx = -50.0
|
|
compasstest_st.vz = 100.0
|
|
expect_near(compass_dist(compass_st, 3), 100.0, 0.01)
|
|
expect_near(compass_wrap(7.0), 7.0 - 6.2832, 0.001)
|
|
expect_near(compass_strip_t(0.5, 1.0), 0.5, 0.001)
|
|
}
|
|
|
|
test "a capture hears every mark whatever the tier and leaves the frame's list alone" (compass_st: mut CompassState, compasstest_st: mut CompasstestState) {
|
|
fresh(compass_st, compasstest_st)
|
|
compass_gather(compass_st)
|
|
compasstest_st.tier = 1
|
|
compass_capture_begin(compass_st)
|
|
expect(compass_capturing(compass_st))
|
|
goal(compass_st, compasstest_st)
|
|
places(compass_st)
|
|
let got = compass_capture_end(compass_st)
|
|
expect(not compass_capturing(compass_st))
|
|
expect_eq(len(got), 5)
|
|
expect(got[0].label == "the dock")
|
|
expect_eq(compass_count(compass_st), 5)
|
|
}
|
|
|
|
test "the radar: its range by tier, the blips in it, and where each falls on the disc" (compass_st: mut CompassState, compasstest_st: mut CompasstestState) {
|
|
fresh(compass_st, compasstest_st)
|
|
compasstest_st.tier = 2
|
|
compass_gather(compass_st)
|
|
expect(not compass_radar_on(compass_st))
|
|
expect(not compass_radar_has(compass_st, 0))
|
|
compasstest_st.tier = 3
|
|
compass_gather(compass_st)
|
|
expect(compass_radar_on(compass_st))
|
|
expect_near(compass_radar_range(compass_st), 120.0, 0.01)
|
|
expect(compass_radar_has(compass_st, 0))
|
|
expect(not compass_radar_has(compass_st, 1))
|
|
expect(not compass_radar_has(compass_st, 2))
|
|
expect(compass_radar_has(compass_st, 3))
|
|
expect_near(compass_radar_x(compass_st, 3), -50.0 / 120.0, 0.001)
|
|
expect_near(compass_radar_y(compass_st, 3), 0.0, 0.001)
|
|
expect_near(compass_radar_x(compass_st, 0), 80.0 / 120.0, 0.001)
|
|
compasstest_st.tier = 9
|
|
expect_near(compass_radar_range(compass_st), 260.0, 0.01)
|
|
}
|
|
|
|
test "the eight points go round from the heading 0 toward -x" {
|
|
expect_eq(compass_octant(0.0, -10.0), 0)
|
|
expect_eq(compass_octant(-10.0, -10.0), 1)
|
|
expect_eq(compass_octant(-10.0, 0.0), 2)
|
|
expect_eq(compass_octant(0.0, 10.0), 4)
|
|
expect_eq(compass_octant(10.0, 0.0), 6)
|
|
expect_eq(compass_octant(10.0, -10.0), 7)
|
|
expect_eq(compass_octant(1.0, -10.0), 0)
|
|
}
|
|
}
|