Example #1
0
    def go_to_depot(self):
        if self.findSpecialty() == ATTACK:
            target = self.room.find_closest_by_range(FIND_HOSTILE_CREEPS, self.pos)
            if target:
                self.move_to(target)
                return

        RoleBase.go_to_depot(self)
Example #2
0
    def go_to_depot(self):
        if self.findSpecialty() == ATTACK:
            target = cast(Optional[Creep], self.room.find_closest_by_range(FIND_HOSTILE_CREEPS, self.pos))
            if target:
                self.move_to(target)
                self.creep.attack(target)
                return

        RoleBase.go_to_depot(self)
Example #3
0
 def should_pickup(self, resource_type=None):
     if 'running' in self.memory:
         if self.memory.running == role_upgrader:
             return upgrading.Upgrader.should_pickup(self, resource_type)
         elif self.memory.running == role_builder:
             return building.Builder.should_pickup(self, resource_type)
     return RoleBase.should_pickup(self, resource_type)
Example #4
0
def run_creep(hive, targets, creeps_skipped, room, creep):
    # type: (HiveMind, TargetMind, Dict[str, List[str]], RoomMind, Creep) -> None
    if Game.cpu.getUsed() > Game.cpu.limit * 0.5 and (
            Game.cpu.bucket < 3000 and
        (Game.gcl.level > 1 or Game.cpu.bucket < 1000)):
        role = creep.memory.role
        if not (role == role_spawn_fill or role == role_tower_fill
                or role == role_link_manager or role == role_hauler
                or role == role_miner or role == role_ranged_offense
                or role == role_wall_defender):
            if creeps_skipped[room.name]:
                creeps_skipped[room.name].append(creep.name)
            else:
                creeps_skipped[room.name] = [creep.name]
            return

    if creep.spawning and creep.memory.role != role_temporary_replacing \
            and creep.memory.role != role_squad_init:
        return
    if volatile_cache.setmem("creep_defense_override").has(creep.name):
        return
    records.start_record()
    instance = wrap_creep(hive, targets, room, creep)
    if not instance:
        if creep.memory.role:
            print(
                "[main] warning! couldn't find role-type wrapper for role: {} ({} of {})"
                .format(creep.memory.role, creep.name, creep.memory.home))
        else:
            print("[main] couldn't find role for creep: {} of {}".format(
                creep.name, creep.memory.home))
        role = default_roles[spawning.find_base_type(creep)]
        if role:
            creep.memory.role = role
            instance = wrap_creep(hive, targets, room, creep)
            room.register_to_role(instance)
        else:
            instance = RoleBase(hive, targets, room, creep)
            instance.go_to_depot()
    records.finish_record('hive.wrap-creep')
    creep.wrapped = instance
    records.start_record()
    bef = Game.cpu.getUsed()
    rerun = instance.run()
    if Game.cpu.bucket >= 7000 or Game.cpu.getUsed() - bef < 0.3:
        if rerun:
            rerun = instance.run()
        if rerun:
            rerun = instance.run()
        if rerun:
            print(
                "[main] creep tried to run three times: {} ({} of {})".format(
                    creep.memory.role, creep.name, instance.home.name))
    records.finish_record(creep.memory.role)
Example #5
0
 def should_pickup(self, resource_type=None):
     return RoleBase.should_pickup(
         self, resource_type) and not self.home.upgrading_paused()
Example #6
0
 def should_pickup(self, resource_type=None):
     # type: (Optional[str]) -> bool
     return RoleBase.should_pickup(
         self, resource_type) and self.any_building_targets()
Example #7
0
 def should_pickup(self, resource_type=None):
     return 'container_pos' in self.memory and RoleBase.should_pickup(
         resource_type)