def execute(self): if self.preexecuteCall is not None: self.preexecuteCall() resultingEvent = None if get_type(self.object) == buildings.BUILDINGS: log.debug('Bulding task : {}'.format(self.__str__())) resultingEvent = buildings.upgrade_building( self.planet.name, self.object) elif get_type(self.object) == research.RESEARCH: log.debug('Researching task : {}'.format(self.__str__())) resultingEvent = research.researchTech(self.planet.name, self.object) elif get_type(self.object) == shipyard.SHIPYARD: log.debug('Shipyard task : {} {} on {}'.format( self.count, self.object, self.planet.name)) resultingEvent = shipyard.build_device(self.planet.name, self.object, self.count) else: log.warn('This type of task ({}) is not yet implemented'.format( get_type(self.object))) #TODO:other cases (fleet ...) resultingEvent.callback = self.postexecuteCall return resultingEvent
def can_execute_task(self, task): # log.debug('checking for execution of {}:\n{}'.format(task, task.__dict__)) if get_type(task.object) == BUILDINGS: # Check special building nanite factory if task.object == NANITE_FACTORY: return self._shipyard_queue_empty and self._building_slot_available else: return self._building_slot_available if get_type(task.object) == SHIPYARD: # TODO: make sure the shipyard queue cannot be full return not self._shipyard_locked # because of nanite log.error('Not implemented for this task : {}'.format(task))
def price(self): log.debug('Pricing {}'.format(self.__str__())) if get_type(self.object) == buildings.BUILDINGS: self.cost = buildings.getBuildingCost(self.planet.name, self.object) elif get_type(self.object) == research.RESEARCH: self.cost = research.getTechCost(self.planet.name, self.object) elif get_type(self.object) == shipyard.SHIPYARD: self.cost = shipyard.getDeviceCost(self.object, self.count) else: log.warn( 'This type of task pricing ({}) is not yet implemented'.format( get_type(self.object)))
def can_execute_task(self, task): if get_type(task.object) == RESEARCH: return not self._lab_lock if get_type(task.object) == BUILDINGS: # log.debug('checking for execution of building task {}:\n{}'.format(task, task.__dict__)) # Check special building research lab if task.object == RESEARCH_LAB: return (not self._lab_lock) and self.planets[ task.planet.name].can_execute_task(task) else: return self.planets[task.planet.name].can_execute_task(task) if get_type(task.object) == SHIPYARD: return self.planets[task.planet.name].can_execute_task(task)
def processTask(self, task): resultingEvent = task.execute() self.newEvent(resultingEvent) if resultingEvent.type != Event.ERROR: resultingEvent.callback = lambda: self.remove_achieved_task(task.id ) self.remove_launched_task(task.id) if get_type(task.object) == buildings.BUILDINGS: self.empire.planets[task.planet.name].take_building_slot() if task.object == buildings.RESEARCH_LAB: self.empire.lock_research_lab() if task.object == buildings.NANITE_FACTORY or task.object == buildings.SHIPYARD: self.empire.planets[task.planet.name].lock_shipyard() if get_type(task.object) == research.RESEARCH: self.empire.lock_research_lab() if get_type(task.object) == shipyard.SHIPYARD: # Extend the shipyard is done event #TODO pass
def level_to_build(self, already_planned_tasks): already_planned = 0 for planned_task in already_planned_tasks: if planned_task.object == self.object: already_planned += 1 if self.is_building(): return (self.level - self.planet.get_building_level(self.object) - already_planned) if self.is_research(): return (self.level - self.planet.empire.get_research_level(self.object) - already_planned) log.warn( 'Unhandled type for this goal ({} : {}), default to one level'. format(get_type(self.object), self.object)) return 1
def count_to_build(self): if get_type(self.object) == shipyard.SHIPYARD: #TODO deal with ships return self.count - self.planet.get_defense_count(self.object) return self.count
def is_shipyard(self): return get_type(self.object) == shipyard.SHIPYARD
def is_research(self): return get_type(self.object) == research.RESEARCH
def is_building(self): return get_type(self.object) == buildings.BUILDINGS