def grant_bar_add(self, gnt): self.grant_bar += gnt if level.has_more_levels() and self.grant_bar > self.level.publication_target: lvl = level.pop_level() self.level = level.current_level() self.grant_bar -= lvl.publication_target self.funds += lvl.grant discovery = random.choice(lvl.discoveries) discovery["granted"] = lvl.grant self.event("grant", discovery)
def process_events(self): elapsed = (time() - self.last_updated) for _ in xrange(int(elapsed)): total_quality = 0 for scientist in self.hr_manager.scientists: if self.data_centre.empty(): scientist.reset_last_published() elif scientist.can_work(): total_quality += scientist.publish(self.data_centre.retrieve()) self.grant_bar_add(total_quality*settings.GRANT_BAR_CONSTANT) if self.accelerator_running: data = self.accelerator.run(1) self.data_centre.store(data) self.last_updated += 1 if not self.has_won and not level.has_more_levels(): self.event("win") self.has_won = True # Month duration in real time elapsed_months = int((time() - self.last_month_start) / settings.MONTH_DURATION) for _ in xrange(elapsed_months): self.process_month()