+ def proceed_to_next_player_turn(self, connection_id):
+ """Run game world turns until player can decide their next step.
+
+ Sends a 'TURN_FINISHED' message, then iterates through all non-player
+ things, on each step furthering them in their tasks (and letting them
+ decide new ones if they finish). The iteration order is: first all
+ things that come after the player in the world things list, then (after
+ incrementing the world turn) all that come before the player; then the
+ player's .proceed() is run, and if it does not finish his task, the
+ loop starts at the beginning. Once the player's task is finished, the
+ loop breaks, and client-relevant game data is sent.
+ """
+ self.send_all('TURN_FINISHED ' + str(self.world.turn))
+ while True:
+ for thing in self.world.things[self.world.player_i+1:]:
+ thing.proceed()
+ self.world.turn += 1
+ for thing in self.world.things[:self.world.player_i]:
+ thing.proceed()
+ self.world.player.proceed(is_AI=False)
+ if self.world.player.task is None:
+ break
+ self.send_all('NEW_TURN ' + str(self.world.turn))
+ self.send_all('MAP_SIZE ' + self.stringify_yx(self.world.map_size))
+ self.send_all('TERRAIN\n' + self.world.map_)
+ self.send_all('POSITION ' + self.stringify_yx(self.world.player.position))
+