def generate(self, cache_path, version):
        '''Generate a treasure hunt'''
        # the treasure hunt name is stored in dungeon_name and is built here
        # because we don't have a ruins[] section
        _thnames = (
            ('{owners} booty',20),
            ('{owners} treasure',20),
            ('{owners} loot', 20),
            ('{owners} chest', 20),
            ('{owners} locker', 20),
            ('{owners} college fund',1)
        )
        # Pick a starting size.
        self.xsize = 1
        self.zsize = 1
        self.steps = randint(cfg.min_steps, cfg.max_steps)
        self.min_distance = cfg.min_distance
        self.max_distance = cfg.max_distance

        located = False
        result = False
        # Find a landmark, if we can.
        # Manual landmark
        if cfg.offset is not '':
            print 'Treasure hunt step: {1}'.format(self.steps)

            self.position = str2Vec(cfg.offset)
            self.position.x = self.position.x & ~15
            self.position.z = self.position.z & ~15
            # XXX bury the chest below ground
            self.bury()
            print "Location set to: ", self.position
        # Search for a location.
        else:
            print "Searching for a suitable location..."
            located = self.findlocation()
            if (located is False):
                print 'Unable to place any more treasure hunts.'
            else:
                print 'Treasure hunt steps: {0}'.format(self.steps)
                print "Location: ", self.position
        # Generate!
        if (located is True):
            # We have a final size, so let's initialize some things.

            self.heightmap = numpy.zeros(( self.room_size,
                                           self.room_size))

            # Set the seed if requested.
            if (self.args.seed is not None):
                seed(self.args.seed)
                print 'Seed:', self.args.seed

            # Now we know the biome, we can setup a name generator
            self.namegen = namegenerator.namegenerator(None, theme='pirate')
            print 'Theme:', self.namegen.theme
            self.owner = self.namegen.genroyalname()
            print 'Owner:', self.owner
            print "Location: ", self.position
            print "Generating landmarks..."
            self.genlandmarks()
            # Name this place
            if self.owner.endswith("s"):
                owners = self.owner + "'"
            else:
                owners = self.owner + "'s"
            self.dinfo['dungeon_name'] = weighted_choice( _thnames )
            self.dungeon_name = self.dinfo['dungeon_name'].format(
                owner=self.owner,
                owners=owners)
            self.dungeon_name = self.dungeon_name[:32]
            self.dinfo['full_name'] = self.dungeon_name
            print "Treasure hunt name:", self.dungeon_name
            self.renderlandmarks()

            self.placechests()
            if cfg.th_spawners is True:
                self.placespawners()
            self.processBiomes()

            # Signature
            self.setblock(Vec(0, 0, 0), materials.Chest, 0, hide=True)
            self.tile_ents[Vec(0, 0, 0)] = encodeTHuntInfo(self,version)
            # Add to the dungeon cache.
            key = '%s,%s' % (
                self.position.x,
                self.position.z,
            )
            # we need the info if making multiple hunts, to avoid
            # all previous landmarks
            #self.thunt_cache[key] = self.tile_ents[Vec(0, 0, 0)]
            self.thunt_cache[key] = True

            # copy results to the world
            self.applychanges()

            # Relight these chunks.
            if (self.args.write is True and self.args.skiprelight is False):
                # Super ugly, but does progress bars for lighting.
                for handler in logging.root.handlers[:]:
                    logging.root.removeHandler(handler)
                h = RelightHandler()
                logging.basicConfig(stream=h, level=logging.INFO)
                self.world.generateLights()
                h.done()
                logging.getLogger().level = logging.CRITICAL
                for handler in logging.root.handlers[:]:
                    logging.root.removeHandler(handler)

            # Saving here allows us to pick up where we left off if we stop.
            if (self.args.write is True):
                print "Saving..."
                self.world.saveInPlace()
                saveTHuntCache(cache_path, self.thunt_cache)
                saveChunkCache(cache_path, self.chunk_cache)
                # make sure commandBlockOutput is false.
                root_tag = nbt.load(self.world.filename)
                root_tag['Data']['GameRules'][
                    'commandBlockOutput'].value = 'false'
                root_tag.save(self.world.filename)
            else:
                print "Skipping save! (--write disabled)"

            result = True

        return result
Example #2
0
    def generate(self, cache_path, version):
        '''Generate a treasure hunt'''
        # the treasure hunt name is stored in dungeon_name and is built here
        # because we don't have a ruins[] section
        _thnames = (('{owners} lost booty', 10), ('{owners} treasure', 10),
                    ('{owners} secret loot',
                     10), ('Lost treasure of {owner}',
                           10), ('Hidden gold of {owner}',
                                 10), ('{owners} hidden gold', 10),
                    ('The secret hoard of {owner}',
                     10), ('Buried treasure of {owner} the Pirate',
                           10), ('{owners} college fund', 1))
        # Pick a starting size.
        self.xsize = 1
        self.zsize = 1
        self.steps = randint(cfg.min_steps, cfg.max_steps)
        self.min_distance = cfg.min_distance
        self.max_distance = cfg.max_distance

        located = False
        result = False
        # Find a landmark, if we can.
        # Manual landmark
        if cfg.offset is not '':
            print 'Treasure hunt step: {1}'.format(self.steps)

            self.position = str2Vec(cfg.offset)
            self.position.x = self.position.x & ~15
            self.position.z = self.position.z & ~15
            # XXX bury the chest below ground
            self.bury()
            print "Location set to: ", self.position
        # Search for a location.
        else:
            print "Searching for a suitable location..."
            located = self.findlocation()
            if (located is False):
                print 'Unable to place any more treasure hunts.'
            else:
                print 'Treasure hunt steps: {0}'.format(self.steps)
                print "Location: ", self.position
        # Generate!
        if (located is True):
            # We have a final size, so let's initialize some things.

            self.heightmap = numpy.zeros((self.room_size, self.room_size))

            # Set the seed if requested.
            if (self.args.seed is not None):
                seed(self.args.seed)
                print 'Seed:', self.args.seed

            # Now we know the biome, we can setup a name generator
            self.namegen = namegenerator.namegenerator(None, theme='pirate')
            print 'Theme:', self.namegen.theme
            self.owner = self.namegen.genroyalname()
            print 'Owner:', self.owner
            print "Location: ", self.position
            print "Generating landmarks..."
            self.genlandmarks()
            # Name this place
            if self.owner.endswith("s"):
                owners = self.owner + "'"
            else:
                owners = self.owner + "'s"
            self.dinfo['dungeon_name'] = weighted_choice(_thnames)
            self.dungeon_name = self.dinfo['dungeon_name'].format(
                owner=self.owner, owners=owners)
            self.dinfo['full_name'] = self.dungeon_name
            print "Treasure hunt name:", self.dungeon_name
            self.renderlandmarks()

            self.placechests()
            if cfg.th_spawners is True:
                self.placespawners()
            self.processBiomes()

            # Signature
            self.setblock(Vec(0, 0, 0), materials.Chest, 0, hide=True)
            self.tile_ents[Vec(0, 0, 0)] = encodeTHuntInfo(self, version)
            # Add to the dungeon cache.
            key = '%s,%s' % (
                self.position.x,
                self.position.z,
            )
            # we need the info if making multiple hunts, to avoid
            # all previous landmarks
            #self.thunt_cache[key] = self.tile_ents[Vec(0, 0, 0)]
            self.thunt_cache[key] = True

            # copy results to the world
            self.applychanges()

            # Relight these chunks.
            if (self.args.write is True and self.args.skiprelight is False):
                # Super ugly, but does progress bars for lighting.
                for handler in logging.root.handlers[:]:
                    logging.root.removeHandler(handler)
                h = RelightHandler()
                logging.basicConfig(stream=h, level=logging.INFO)
                self.world.generateLights()
                h.done()
                logging.getLogger().level = logging.CRITICAL
                for handler in logging.root.handlers[:]:
                    logging.root.removeHandler(handler)

            # Saving here allows us to pick up where we left off if we stop.
            if (self.args.write is True):
                print "Saving..."
                self.world.saveInPlace()
                saveTHuntCache(cache_path, self.thunt_cache)
                saveChunkCache(cache_path, self.chunk_cache)
                # make sure commandBlockOutput is false.
                root_tag = nbt.load(self.world.filename)
                root_tag['Data']['GameRules'][
                    'commandBlockOutput'].value = 'false'
                root_tag.save(self.world.filename)
            else:
                print "Skipping save! (--write disabled)"

            result = True

        return result
Example #3
0
#!/usr/bin/python
import random
import sys

import ruins
import namegenerator

print
for x in xrange(50):
    n = namegenerator.namegenerator(random.randint(0, 39))
    o = n.genroyalname()
    if o.endswith("s"):
        os = o+"'"
    else:
        os = o+"'s"
    print random.choice([
        ruins.Blank.nameDungeon().format(
            owner=o,
            owners=os
        ),
        ruins.RuinedFane.nameDungeon().format(
            owner=o,
            owners=os
        ),
        ruins.StepPyramid.nameDungeon().format(
            owner=o,
            owners=os
        ),
        ruins.Barrow.nameDungeon().format(
            owner=o,
            owners=os
Example #4
0
#!/usr/bin/env python
import random
import sys

import ruins
import namegenerator

print
for x in xrange(50):
    n = namegenerator.namegenerator(random.randint(0, 39))
    o = n.genroyalname()
    if o.endswith("s"):
        os = o + "'"
    else:
        os = o + "'s"
    print random.choice([
        ruins.Blank.nameDungeon().format(
            owner=o,
            owners=os
        ),
        ruins.RuinedFane.nameDungeon().format(
            owner=o,
            owners=os
        ),
        ruins.StepPyramid.nameDungeon().format(
            owner=o,
            owners=os
        ),
        ruins.Barrow.nameDungeon().format(
            owner=o,
            owners=os