def wait_until_next_event(): for c in Map.get_creatures(): if c.alive and not c.check_health(): c.die() if Time.times == []: return Time.now = Time.times[0] Time.actions[0]() Time.times = Time.times[1:] Time.actions = Time.actions[1:] Time.ids = Time.ids[1:]
def wait_until_event(ev_id): for c in Map.get_creatures(): if c.alive and not c.check_health(): c.die() if ev_id not in Time.ids: log(Time.times, Time.ids, Time.actions) raise ValueError('No such event!') else: g = Time.ids.index(ev_id) t = Time.times[g] Time.wait(t-Time.now) return t
def wait(t=100): log(Time.times) for c in Map.get_creatures(): if c.alive and not c.check_health(): c.die() for i in range(t): Time.now += 1 count = 0 for k in range(len(Time.times)): if Time.times[k] > Time.now: break else: count += 1 Time.actions[k]() Time.times = Time.times[count:] Time.actions = Time.actions[count:] Time.ids = Time.ids[count:]
def after(time, action): for c in Map.get_creatures(): if c.alive and not c.check_health(): c.die() if Time.times == []: Time.times = [time+Time.now] Time.actions = [action] Time.__curr_id += 1 Time.ids = [Time.__curr_id] return Time.__curr_id if time + Time.now >= Time.times[-1]: Time.times.append(time+Time.now) Time.actions.append(action) Time.__curr_id += 1 Time.ids.append(Time.__curr_id) return Time.__curr_id for i in range(len(Time.times)): if Time.times[i] > time + Time.now: Time.times[i:i] = [time+Time.now] Time.actions[i:i] = [action] Time.__curr_id += 1 Time.ids[i:i] = [Time.__curr_id] return Time.__curr_id