Ejemplo n.º 1
0
 def tick(self):
     tick_start = datetime.now()
     if self.location_received is False:
         self.last_tick_time = tick_start
         return config.TIME_STEP
     if not self.ready:
         self.ready = self.in_complete_chunks(self.bot_object) and self.spawn_point_received
         if not self.ready:
             self.last_tick_time = tick_start
             return config.TIME_STEP
     self.move(self.bot_object)
     self.bot_object.direction = [0, 0]
     self.send_location(self.bot_object)
     tools.do_later(0, self.on_standing_ready, self.bot_object)
     tools.do_later(0, self.behaviour_manager.run)
     tick_end = datetime.now()
     d_run = (tick_end - tick_start).total_seconds()  # time this step took
     t = config.TIME_STEP - d_run  # decreased by computation in tick
     d_iter = (tick_start - self.last_tick_time).total_seconds()  # real tick period
     r_over = d_iter - self.period_time_estimation  # diff from scheduled by
     t -= r_over
     t = max(0, t)  # cannot delay into past
     self.period_time_estimation = t + d_run
     self.last_tick_time = tick_start
     return t
Ejemplo n.º 2
0
 def __init__(self, host=None, port=None, commander_name=None, bot_name=None):
     self.server_host = host
     self.server_port = port
     self.commander = Commander(commander_name)
     self.status_diff = StatusDiff(self)
     self.bot = BotEntity(self, bot_name)
     self.chat = Chat(self)
     self.stats = Statistics()
     self.game_state = GameState()
     self.game_ticks = 0
     self.connected = False
     self.logged_in = False
     self.protocol = None
     self.entities = None
     self.grid = None
     self.navgrid = None
     self.spawn_position = None
     self.dim_entities = [None, None, None]
     self.dim_grid = [None, None, None]
     self.dim_navgrid = [None, None, None]
     self.players = defaultdict(int)
     tools.do_later(config.TIME_STEP, self.tick)
Ejemplo n.º 3
0
 def on_death(self):
     self.location_received = False
     self.spawn_point_received = False
     tools.do_later(1.0, self.do_respawn)
Ejemplo n.º 4
0
 def tick(self):
     t = config.TIME_STEP
     if self.logged_in:
         t = self.bot.tick()
         self.every_n_ticks()
     tools.do_later(t, self.tick)