Esempio n. 1
0
 def cast(self, context):
     from monsters import Boulder
     spots = [ neighbour for neighbour in context.player.tile.neighbours() if not neighbour.cannotEnterBecause( Boulder ) ]
     if not spots:
         context.player.context.log( "Nothing happens." )
     else:
         context.player.context.log( "A boulder appears!" )
         spot = random.choice( spots )
         Boulder.spawn( context, spot )
Esempio n. 2
0
def mapFromGenerator( context, ancestor = None):
    from levelgen import generateLevel
    lg = generateLevel( 80, 
                        50,
                        (16,30,16,30),
                        (12,20,12,16)
    )
    rv = Map( context, lg.width, lg.height )
    if ancestor:
        rv.previousLevel = ancestor
        ancestor.nextLevel = rv
        rv.depth = ancestor.depth + 1
    else:
        rv.depth = 1
        rv.nextLevel = None
    # Ror now just the cell data is used; do recall that the lg object
    # also contains .rooms; these make up a graph that can be used to
    # classify the rooms.
    for x in range( lg.width ):
        for y in range( lg.height ):
            {
                ' ': makeImpenetrableRock,
                '+': lambda tile: makeOpenDoor(tile) if random.random() > 0.5 else makeClosedDoor(tile),
                'o': makeHallway,
                '.': makeFloor,
                '#': makeWall,
            }[ lg.data[y][x] ]( rv.tiles[x,y] )
    makeStairsUp( rv.tiles[ lg.entryRoom.internalFloorpoint() ], isPortal = not ancestor )
    makeStairsDown( rv.tiles[ lg.exitRoom.internalFloorpoint() ] )
    if rv.depth == DungeonDepth:
        tile = rv.randomTile( lambda tile : not tile.cannotEnterBecause( context.macGuffinMobile ) and lg.exitRoom.contains( tile.x, tile.y )  )
        monster = context.macGuffinMobile.spawn( context, tile )
    for room in lg.rewardRooms:
        # should be in chests: that way it's hard to
        # distinguish between danger rooms and reward rooms
        valueTarget = random.randint(40,70) # per room, people!
        for protoitem in selectThings( rv.depth, valueTarget, context.protoitems ):
            item = protoitem.spawn()
            tile = rv.tiles[ room.internalFloorpoint() ]
            tile.items.append( item )
        if rv.depth == 1:
            for protoitem in selectThings( rv.depth, 70 - valueTarget, context.protorunes ):
                item = protoitem.spawn()
                tile = rv.tiles[ room.internalFloorpoint() ]
                tile.items.append( item )

    for room in lg.dangerRooms:
        generateTrapsForRoom( rv, context, room )
    monsterValueTarget = random.randint( 6, 12 )
    potentialMonsters = [ thing for thing in context.protomonsters if thing.rarity.eligible( rv.depth ) ]
    populateLevel( rv, context, monsterValueTarget, potentialMonsters, excludeRoom = lg.entryRoom )
    from monsters import Boulder
    noBoulders = random.randint( 2, 6 )
    for i in range( noBoulders ):
        tile = rv.randomTile( lambda tile : not tile.cannotEnterBecause( Boulder ) )
        monster = Boulder.spawn( context, tile )
    context.levels.append( rv )
    return rv