extends TestCase ## A11: the chart, its place names and its tide forecast, during the drop and in play. func test_place_names_follow_the_seed_and_the_kind() -> void: var kinds: Array[String] = ["hamlet", "dock", "lighthouse", "quarry", "hamlet"] var names: Array[String] = PlaceNames.names_for(7, kinds) assert_eq(names, PlaceNames.names_for(7, kinds), "the same seed, the same names") assert_ne(names, PlaceNames.names_for(8, kinds), "another seed, other names") assert_eq(names.size(), kinds.size()) var firsts: Dictionary = {} for index: int in names.size(): var words: Array = PlaceNames.KIND_WORDS[kinds[index]] var ends_right: bool = false for word: String in words: ends_right = ends_right or names[index].ends_with(" " + word) assert_true(ends_right, "%s is named as a %s" % [names[index], kinds[index]]) firsts[names[index].trim_suffix(names[index].get_slice(" ", names[index].get_slice_count(" ") - 1))] = true assert_eq(firsts.size(), names.size(), "no first word twice") func test_the_chart_draws_sea_land_and_coast() -> void: var sim: Simulation = Simulation.new(5) var began: int = Time.get_ticks_msec() var image: Image = ChartMap.base_image(sim.ground) var took: int = Time.get_ticks_msec() - began print("chart base image: %d ms" % took) assert_eq(image.get_size(), Vector2i(ChartMap.PIXELS, ChartMap.PIXELS)) # The corner is open sea; the island's highest summit is paper or ink, not sea. var corner: Color = image.get_pixel(2, 2) assert_true(corner.b > corner.r, "the corner is sea") var top: Vector3 = sim.island.summits[0] var pixel: Vector2i = Vector2i(top.x / Tuning.WORLD_SIZE_METRES * ChartMap.PIXELS, top.z / Tuning.WORLD_SIZE_METRES * ChartMap.PIXELS) var land: Color = image.get_pixel(pixel.x, pixel.y) assert_true(land.r >= land.b, "a summit is land") var ink: int = 0 for py: int in ChartMap.PIXELS: for px: int in ChartMap.PIXELS: var colour: Color = image.get_pixel(px, py) if absf(colour.r - Palette.INK.r) < 0.01 and absf(colour.g - Palette.INK.g) < 0.01 and absf(colour.b - Palette.INK.b) < 0.01: ink += 1 assert_true(ink > 50, "there is a coastline (%d ink pixels)" % ink) func test_the_forecast_overlay_marks_what_the_next_tide_takes() -> void: var sim: Simulation = Simulation.new(5) assert_eq(ChartMap.coming_flood(sim).size(), 0, "no tide yet, no forecast") sim.start_tide() var coming: PackedByteArray = ChartMap.coming_flood(sim) var expected: PackedByteArray = sim.flood.forecast(sim.tide.forecast_at(sim.tick), sim.structures) var count: int = 0 for index: int in coming.size(): if coming[index] != 0: count += 1 assert_eq(expected[index], 1) assert_eq(sim.flood.flooded[index], 0, "only land not yet taken") assert_true(count > 100, "the first tide takes a good piece of shore (%d cells)" % count) var chart: ChartMap = ChartMap.new() chart.setup(sim, 5) chart.refresh(Vector3(500.0, 10.0, 500.0), 0.0, true, 1.0) assert_eq(chart.forecast_cells, count, "the chart drew them all") assert_near(chart.forecast_level, sim.tide.forecast_at(sim.tick), 0.001) assert_eq(chart.places.size(), sim.pois.pois.size(), "every place is named") var mini: ChartMap = ChartMap.new(ChartMap.Mode.MINI) mini.setup(sim, 5, null, chart) assert_eq(mini._base, chart._base, "the minimap shares the chart's paper") chart.free() mini.free() func test_the_session_shows_the_minimap_in_play_and_the_chart_on_the_map_key() -> void: var tree: SceneTree = Engine.get_main_loop() as SceneTree var rules: MatchRules = MatchRules.new() rules.max_players = 2 rules.min_players = 1 rules.lobby_ticks = 2 rules.countdown_ticks = 2 var session: ClientSession = ClientSession.new() session.input.autoplay = true session.play_offline(6, 1, rules) tree.root.add_child(session) var frames: int = 0 while not session.game.playing() and frames < 600: session._process(1.0 / 30.0) frames += 1 assert_true(session.game.playing()) session._process(1.0 / 30.0) assert_true(session.minimap.visible, "the minimap during the drop") assert_false(session.chart.visible) assert_eq(session.chart.route.size(), 2, "the drop route is on the chart") assert_true(session.game.prediction.player.drop_state != Drop.NONE, "still on the drop") session.input.press(KEY_M) session._process(1.0 / 30.0) assert_true(session.chart.visible, "M opens the chart") assert_false(session.minimap.visible, "and the minimap gives way") assert_true(session.chart.show_me) assert_near(session.chart.me.x, session.game.prediction.player.position.x, 0.01, "the player is marked where they are") session.input.press(KEY_M) session._process(1.0 / 30.0) assert_false(session.chart.visible) session.free()