def __init__(self, name, spec, built=False): super(Base, self).__init__(spec) self._name = name self.started_at = g.pl.raw_min self.location = None self.raw_cpu = 0 self.cpu = 0 self.items = { "cpu": None, "reactor": None, "network": None, "security": None, } self._power_state = "offline" self.grace_over = False self.maintenance = buyable.array(self.spec.maintenance, int64) if built: self.finish(is_player=False) if self.spec.force_cpu: self.cpus = item.Item(g.items[self.spec.force_cpu], base=self, count=self.spec.size) self.cpus.finish(is_player=False)
def set_current(self, type, item_type, count): if type.id == "cpu": space_left = self.base.space_left_for(item_type) try: count = int(count) except ValueError: msg = _( "\"%(value)s\" does not seem to be a valid integer.") % { "value": count } md = dialog.MessageDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) dialog.call_dialog(md, self) md.parent = None return if count > space_left or count <= 0 or space_left == 0: if space_left > 0: msg = _("Please choose an integer between 1 and %(limit)s." ) % { "limit": space_left } else: msg = _( "The base cannot support any additional number of %(item_name)s." ) % { "item_name": item_type.name } md = dialog.MessageDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) dialog.call_dialog(md, self) md.parent = None return # If there are any existing CPUs of this type, warn that they will # be taken offline until construction finishes. cpu_added = self.base.cpus is not None \ and self.base.cpus.spec == item_type if cpu_added: space_left -= self.base.cpus.count if self.base.cpus.done: msg = _( "I will need to take the existing processors offline while I install the new ones. Continue anyway?" ) yn = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) go_ahead = dialog.call_dialog(yn, self) yn.parent = None if not go_ahead: return # If there are already existing CPUs of other type, warn that they will # be taken removed. cpu_removed = self.base.cpus is not None \ and self.base.cpus.spec != item_type if cpu_removed: msg = _( "I will need to remove the existing different processors while I install the new type. Continue anyway?" ) yn = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) go_ahead = dialog.call_dialog(yn, self) yn.parent = None if not go_ahead: return new_cpus = item.Item(item_type, base=self.base, count=count) if cpu_added: self.base.cpus += new_cpus else: self.base.cpus = new_cpus self.base.check_power() else: old_item = self.base.items[type.id] if old_item is None or old_item.spec != item_type: self.base.items[type.id] = item.Item(item_type, base=self.base) self.base.check_power() self.base.recalc_cpu()