zones_set / zones_clear / zones_merge, zones_contains / zones_nearest and the clusters' bounding circles, over fixed arrays of ZONES_MAX (16). WildlifeWorld.active freezes an animal outside (no state change, no dice), NpcWorld.active a walker (and no birth outside), VehicleWorld.active a moored boat, and ThingsWorld.restocks keeps a morning's restock inside; every default is "everywhere", so an unbound game is unchanged. Tests: the merge (near players one cluster, far two, a player leaving splits a chain), contains, nearest, the radius; wildlife, npc, vehicles and things pass as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.2 KiB
Text
52 lines
2.2 KiB
Text
# zones_test.ludic - discs merged into clusters (near players one, far ones two, a player leaving
|
|
# splits the chain), inside or not, how far to the nearest edge, and the radius a fog gives
|
|
import "ludic.zones"
|
|
import "ludic.base"
|
|
program ZonesTest {
|
|
numbers float
|
|
|
|
test "two near players are one cluster, two far apart are two" (zones_st: mut ZonesState) {
|
|
zones_reset(zones_st)
|
|
zones_set(zones_st, 0, 0.0, 0.0, 200.0)
|
|
zones_set(zones_st, 1, 300.0, 0.0, 150.0)
|
|
zones_merge(zones_st)
|
|
expect_eq(zones_clusters(zones_st), 1)
|
|
expect_eq(zones_cluster_of(zones_st, 0), zones_cluster_of(zones_st, 1))
|
|
expect_eq(zones_cluster_n(zones_st, 0), 2)
|
|
expect(zones_cluster_r(zones_st, 0) >= 325.0)
|
|
zones_set(zones_st, 1, 1000.0, 0.0, 150.0)
|
|
zones_merge(zones_st)
|
|
expect_eq(zones_clusters(zones_st), 2)
|
|
expect(zones_cluster_of(zones_st, 0) != zones_cluster_of(zones_st, 1))
|
|
}
|
|
|
|
test "a player leaving the middle of a chain splits it" (zones_st: mut ZonesState) {
|
|
zones_reset(zones_st)
|
|
zones_set(zones_st, 0, 0.0, 0.0, 200.0)
|
|
zones_set(zones_st, 3, 350.0, 0.0, 200.0)
|
|
zones_set(zones_st, 5, 700.0, 0.0, 200.0)
|
|
zones_merge(zones_st)
|
|
expect_eq(zones_clusters(zones_st), 1)
|
|
zones_clear(zones_st, 3)
|
|
zones_merge(zones_st)
|
|
expect_eq(zones_clusters(zones_st), 2)
|
|
expect(zones_cluster_of(zones_st, 0) != zones_cluster_of(zones_st, 5))
|
|
}
|
|
|
|
test "inside, the distance to the nearest edge, and nothing set is everywhere" (zones_st: mut ZonesState) {
|
|
zones_reset(zones_st)
|
|
expect(zones_contains(zones_st, 5000.0, 5000.0))
|
|
expect(zones_nearest(zones_st, 5000.0, 5000.0) == 0.0)
|
|
zones_set(zones_st, 2, 100.0, 100.0, 150.0)
|
|
expect(zones_contains(zones_st, 200.0, 100.0))
|
|
expect(not zones_contains(zones_st, 300.0, 100.0))
|
|
expect(zones_nearest(zones_st, 200.0, 100.0) == 0.0)
|
|
expect(Math.abs(zones_nearest(zones_st, 350.0, 100.0) - 100.0) < 0.001)
|
|
}
|
|
|
|
test "a player's radius: past the fog, never under the least, the horizon with none" (zones_st: mut ZonesState) {
|
|
expect(zones_radius(0.0) == ZONES_NO_FOG)
|
|
expect(zones_radius(30.0) == ZONES_LEAST)
|
|
expect(zones_radius(500.0) == 540.0)
|
|
}
|
|
}
|