extends TestCase ## Seeds for the placement checks, and the fewer, slower traversal walks. const PLACEMENT_SEEDS: int = 30 const TRAVERSAL_SEEDS: Array[int] = [1, 2, 3, 4] ## A route segment must be walked within this many seconds. const SEGMENT_SECONDS: float = 12.0 const ARRIVE_METRES: float = 0.45 func test_every_island_gets_every_kind_well_spaced() -> void: var kinds: int = Tuning.POI_KINDS.size() assert_true(kinds >= 6, "issue W4 asks for at least 6 kinds") for seed_value: int in range(1, PLACEMENT_SEEDS + 1): var island: Island = Island.generate(seed_value) var placed: PoiSet = PoiSet.generate(island) var label: String = "seed %d" % seed_value var total: int = placed.pois.size() assert_true(total >= Tuning.POI_MIN_TOTAL and total <= Tuning.POI_MAX_TOTAL, "%s placed %d" % [label, total]) for kind: String in Tuning.POI_KINDS: var count: int = placed.count_of(kind) assert_true(count >= Tuning.POI_KINDS[kind]["min"] and count <= Tuning.POI_KINDS[kind]["max"], "%s: %d %s" % [label, count, kind]) for a: int in total: var here: Vector3 = placed.pois[a].origin assert_true(here.y > 0.0, "%s: %s sited in the sea" % [label, placed.pois[a].kind]) for b: int in range(a + 1, total): var gap: float = Vector2(here.x, here.z).distance_to(Vector2(placed.pois[b].origin.x, placed.pois[b].origin.z)) assert_true(gap >= Tuning.POI_SPACING_METRES - 0.001, "%s: two sites %.0f m apart" % [label, gap]) _check_sites(placed, label) func test_same_seed_places_the_same_points_of_interest() -> void: var first: PoiSet = PoiSet.generate(Island.generate(9)) var second: PoiSet = PoiSet.generate(Island.generate(9)) assert_eq(first.pois.size(), second.pois.size()) for index: int in first.pois.size(): assert_eq(first.pois[index].origin, second.pois[index].origin) assert_eq(first.pois[index].solids, second.pois[index].solids) func test_loot_markers_are_exposed_and_stand_on_floors() -> void: var sim: Simulation = Simulation.new(6) var markers: Array[Dictionary] = sim.pois.loot_markers() assert_true(markers.size() >= sim.pois.pois.size(), "every POI should offer loot, got %d markers" % markers.size()) var kinds: Dictionary = {} for marker: Dictionary in markers: var at: Vector3 = marker["position"] kinds[marker["kind"]] = true var support: float = sim.ground.support_height(at.x, at.z, at.y + 0.5) assert_near(support, at.y, 0.6, "%s marker at %s floats or is buried" % [marker["kind"], at]) assert_false(sim.ground.body_blocked(at + Vector3.UP * 0.05, 0.3, 1.0, 0.0), "%s marker at %s is inside a solid" % [marker["kind"], at]) assert_eq(kinds.size(), Tuning.POI_KINDS.size(), "every kind has loot") func test_interiors_are_walkable() -> void: # The automated traversal: a player walks every route of every POI, from open ground # outside, through the door and up any stairs, to the loot inside, using the real # Movement code against the real solids. var walked: int = 0 for seed_value: int in TRAVERSAL_SEEDS: var sim: Simulation = Simulation.new(seed_value) for poi: Poi in sim.pois.pois: for route: Array in poi.routes: var failure: String = _walk(sim.ground, route) assert_eq(failure, "", "seed %d %s at %s" % [seed_value, poi.kind, poi.origin]) walked += 1 assert_true(walked >= 40, "walked only %d routes" % walked) func test_players_do_not_spawn_inside_buildings() -> void: var sim: Simulation = Simulation.new(3) for _index: int in Tuning.SOLO_PLAYERS: var player: SimEntity = sim.entities.find(sim.add_player()) assert_false(sim.ground.body_blocked(player.position, Tuning.PLAYER_RADIUS, Tuning.PLAYER_HEIGHT, 0.0), "spawned inside a solid at %s" % player.position) func _check_sites(placed: PoiSet, label: String) -> void: for poi: Poi in placed.pois: var height: float = poi.origin.y match poi.kind: "shrine": assert_true(height >= Tuning.ISLAND_FOREST_TOP * 0.8, "%s: shrine at %.1f m" % [label, height]) "dock": assert_true(height < 6.0, "%s: dock at %.1f m" % [label, height]) "salt_works": assert_true(height < Tuning.ISLAND_MARSH_TOP * 3.2, "%s: salt works at %.1f m" % [label, height]) "quarry": assert_true(height >= Tuning.ISLAND_FOREST_TOP - 6.0, "%s: quarry at %.1f m" % [label, height]) ## Walks a player along `route`. Returns "" on success or what went wrong. func _walk(ground: SimGround, route: Array) -> String: var player: SimEntity = SimEntity.new(1, SimEntity.ARCHETYPE_PLAYER) var start: Vector3 = route[0] player.position = Vector3(start.x, ground.support_height(start.x, start.z, start.y + 1.0), start.z) player.health = Tuning.PLAYER_MAX_HEALTH player.on_ground = true if ground.body_blocked(player.position, Tuning.PLAYER_RADIUS, Tuning.PLAYER_HEIGHT, Tuning.STEP_HEIGHT): return "route starts inside a solid at %s" % player.position var tick: int = 0 for index: int in range(1, route.size()): var target: Vector3 = route[index] var limit: int = tick + roundi(SEGMENT_SECONDS * Tuning.TICK_RATE_HZ) while true: var towards: Vector2 = Vector2(target.x - player.position.x, target.z - player.position.z) if towards.length() < ARRIVE_METRES: break if tick >= limit: return "stuck at %s heading for waypoint %d %s" % [player.position, index, target] var speed: float = clampf(towards.length() / (Tuning.WALK_SPEED / Tuning.TICK_RATE_HZ), 0.2, 1.0) var command: PlayerCommand = PlayerCommand.from_input(tick, Vector2(0.0, speed), atan2(towards.x, towards.y), 0.0) Movement.step(player, command, ground) tick += 1 if absf(player.position.y - target.y) > 1.0: return "reached waypoint %d at height %.2f, expected %.2f" % [index, player.position.y, target.y] if player.health < Tuning.PLAYER_MAX_HEALTH: return "took damage on the way" return ""