Esempio n. 1
0
    def reset_body(self):
        self.parts['head'] = parts.get_part(parts.by_name['Human Head'])
        self.parts['body'] = parts.get_part(parts.by_name['Human Torso'])
        self.parts['legs'] = parts.get_part(parts.by_name['Human Legs'])
        #self.parts['back'] = None
        self.parts['tail'] = None

        self.parts['left_arm'] = [parts.get_part(parts.by_name['Human Arm'])]
        self.parts['right_arm'] = [parts.get_part(parts.by_name['Human Arm'])]
Esempio n. 2
0
    def generate_body(self, *args, **kwargs):
        self.parts['head'] = parts.get_part(parts.by_name['Owl Head'])
        self.parts['body'] = parts.get_part(parts.by_name['Feathered Torso'])
        self.parts['legs'] = parts.get_part(parts.by_name['Bear Legs'])

        self.parts['left_arm'] = [
                parts.get_part(parts.by_name['Feathered Arm'])
        ]
        self.parts['right_arm'] = [
                parts.get_part(parts.by_name['Feathered Arm'])
        ]
Esempio n. 3
0
 def random_part(self, slot):
     if slot in self.limbs:
         slot = 'limbs'
     return parts.get_part(random.choice(parts.parts[slot]))
Esempio n. 4
0
    def generate_body(self, monster_level):
        log.debug("Generating class-%i enemy", monster_level)
        #start off human-like
        base_parts = {
            'head': parts.get_part(parts.by_name['Human Head']),
            'body': parts.get_part(parts.by_name['Human Torso']),
            'legs': parts.get_part(parts.by_name['Human Legs']),
            'left_arm': parts.get_part(parts.by_name['Human Arm']),
            'right_arm': parts.get_part(parts.by_name['Human Arm']),
            'tail': None
        }
        #determine how mutated to be
        mutation_count = 0
        extra_limbs = 0

        if monster_level == 0:
            mutation_count = 1
            max_extra_limbs = 0
            monster_level = 1
        else:
            mutation_count = monster_level + 2
            extra_limbs = max(0, random.randint(monster_level - 2, monster_level + 1))


        #do some mutatin'
        for i in range(mutation_count):
            for attempt in range(20):
                slot = random.choice(base_parts.keys())
                part = self.random_part(slot)
                if part.power > monster_level or part.power < monster_level-1:
                    if attempt >= 19:
                        log.debug("forced to accept a %r, power = %r and level = %r",part.name, part.power, monster_level)
                        break
                    log.debug("skipping a %r, power = %r and level = %r",part.name, part.power, monster_level)
                    continue
                break

            log.debug("mutating the %r into a %r", slot, part.name)
            self.add_part(slot, part)

            #take it out of the base_parts set so we don't re-mutate the same component
            del base_parts[slot]
        
        #put the regular, unmutated bits in
        for slot, part in base_parts.items():
            if not part:
                continue
            self.add_part(slot, part)

        #do some farm-fresh limb growin'
        log.debug("adding %r extra limbs", extra_limbs)
        for i in range(extra_limbs):
            for attempt in range(20):
                new_limb = self.random_part('limbs')
                if new_limb.power > monster_level or new_limb.power < monster_level-1:
                    if attempt >= 19:
                        log.debug("forced to accept a %r limb, power = %r and level = %r", new_limb.name, new_limb.power, monster_level)
                        break
                    log.debug("skipping a %r limb, power = %r and level = %r", new_limb.name, new_limb.power, monster_level)
                    continue
                break
            slot = random.choice(['left_arm', 'right_arm'])
            log.debug("adding a %r to the %r", new_limb.name, slot)
            self.parts[slot].append(new_limb)
        log.debug("generation complete")