extends TestCase ## The scripted player from issue M8: a stand-in for a person, which also harvests and ## builds, things bots don't do yet. func test_a_scripted_seat_sends_commands_like_anyone_else() -> void: var loop: ServerLoop = ServerLoop.new(99, 1, 1) loop.play_humans_by_script() assert_eq(loop.scripted.size(), 1) assert_eq(loop.scripted[0].player_id, 1) assert_eq(loop.bots.size(), 1) for _index: int in Tuning.TICK_RATE_HZ * 24: loop.run_tick() assert_ne(loop.sim.entities.find(1).drop_state, Drop.ABOARD, "the scripted player leapt from the barge") func test_harvests_driftwood_and_builds_with_it() -> void: # Seed 2 is the match `make match` plays: the player lands, finds a weapon, cuts # driftwood and puts up a breakwater and a wall about a minute in. var loop: ServerLoop = ServerLoop.new(2, 1, 23) loop.play_humans_by_script() var player: ScriptedPlayer = loop.scripted[0] var placed: int = 0 var harvests: int = 0 while loop.ticks < 2400 and player.step != ScriptedPlayer.DONE: loop.run_tick() for event: Dictionary in loop.sim.events: if event["type"] == "piece_placed" and event["player"] == player.player_id: placed += 1 elif event["type"] == "harvest" and event["player"] == player.player_id: harvests += 1 assert_eq(player.step, ScriptedPlayer.DONE) assert_true(harvests >= 3, "swung at props %d times" % harvests) assert_true(player.harvested >= ScriptedPlayer.WANTED_DRIFTWOOD, "harvested %d" % player.harvested) assert_eq(player.built, 2) assert_eq(placed, 2) var kinds: Array[int] = [] for piece: StructureSet.Piece in loop.sim.structures.pieces.values(): if piece.owner == player.player_id: kinds.append(piece.kind) kinds.sort() assert_eq(kinds, [StructureSet.WALL, StructureSet.BREAKWATER] as Array[int]) assert_false(loop.sim.entities.find(player.player_id).eliminated)