Example #1
0
def place_objects(room, Game):
    #choose random number of monsters
    #max number monsters per room

    max_monsters = from_dungeon_level([[3, 1], [4, 3], [5, 6], [7, 10]], Game)
    num_monsters = libtcod.random_get_int(0, 0, max_monsters)
    monster_chances = get_monster_chances(Game)

    max_items = from_dungeon_level([[1, 1], [2, 4]], Game)
    num_items = libtcod.random_get_int(0, 0, max_items)
    item_chances = get_item_chances(Game)



    for i in range(num_monsters):
        #choose random spot for this monster
        x =  libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y =  libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        if not entities.is_blocked(x, y, Game):
            #create a monster
            choice = random_choice(monster_chances)

            monster             = entities.Object(**entitydata.mobs[choice])
            monster.name        = choice  
            monster.blocks      = True        
            monster.ai          = entities.BasicMonster()  #how do I set different ai?
            monster.ai.owner    = monster

            monster.set_location(x, y, Game)
            #print 'Added a ' + choice
            Game.objects.append(monster)


    for i in range(num_items):
        #choose random spot for this item
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        #only place it if the tile is not blocked
        if not entities.is_blocked(x, y,Game):
            #create an item
            choice = random_choice(item_chances)

            item = entities.Object(**entitydata.items[choice])
            item.always_visible = True

            item.set_location(x, y, Game)

            Game.objects.append(item)
            item.send_to_back(Game) #items appear below other objects
Example #2
0
def place_objects(gm, zone, safe=False):
    num_satellites = utils.from_dungeon_level(dungeon_level, SATELLITES_PER_LEVEL)
    for _ in range(num_satellites):
        (x, y) = zone.random_coordinates()

        if not is_blocked(x, y, gm, objects):
            fighter_component = Fighter(player=player, hp=1, defense=9999, power=0, xp=0,
                                        death_function=projectile_death)
            monster = Object(x, y, '#', 'satellite', libtcod.white, blocks=True, fighter=fighter_component)
            non_interactive_objects.append(monster)
            # TODO: Hack!
            gm[x][y].blocked = True

    if not safe:
        encounter = tables.choose_encounter_for_level(dungeon_level)
    else:
        encounter = tables.EMPTY_ENCOUNTER
    zone.encounter = encounter
    enemies = tables.encounters_to_ship_lists[encounter]
    for choice in enemies:
        (x, y) = zone.random_unblocked_coordinates(gm, objects)

        if choice == SCOUT:
            fighter_component = Fighter(player=player, hp=10, defense=0, power=0, xp=30, base_speed=75,
                                        death_function=monster_death)
            ai_component = ScoutMonster()
            monster = Object(x, y, 'S', SCOUT, libtcod.darker_green, blocks=True, fighter=fighter_component,
                             ai=ai_component)
        elif choice == FIGHTER:
            fighter_component = Fighter(player=player, hp=30, defense=0, power=0, xp=50, base_speed=125,
                                        death_function=monster_death)
            ai_component = FighterMonster()
            monster = Object(x, y, 'F', FIGHTER, libtcod.darker_green, blocks=True, fighter=fighter_component,
                             ai=ai_component)
        elif choice == GUNSHIP:
            fighter_component = Fighter(player=player, hp=50, defense=4, power=3, xp=100, base_speed=100,
                                        death_function=monster_death)
            ai_component = GunshipMonster()
            monster = Object(x, y, 'G', GUNSHIP, libtcod.darker_green, blocks=True, fighter=fighter_component,
                             ai=ai_component)
        elif choice == FRIGATE:
            fighter_component = Fighter(player=player, hp=150, defense=10, power=3, xp=200, base_speed=250,
                                        death_function=monster_death)
            ai_component = FrigateMonster()
            monster = Object(x, y, 'R', FRIGATE, libtcod.darker_green, blocks=True, fighter=fighter_component,
                             ai=ai_component)
        elif choice == DESTROYER:
            fighter_component = Fighter(player=player, hp=200, defense=15, power=0, xp=500, base_speed=300,
                                        death_function=monster_death)
            ai_component = DestroyerMonster()
            monster = Object(x, y, 'D', DESTROYER, libtcod.darker_green, blocks=True,
                             fighter=fighter_component, ai=ai_component)
        elif choice == CRUISER:
            fighter_component = Fighter(player=player, hp=300, defense=10, power=0, xp=1000, base_speed=400,
                                        death_function=monster_death)
            ai_component = CruiserMonster()
            monster = Object(x, y, 'C', CRUISER, libtcod.darker_green, blocks=True,
                             fighter=fighter_component, ai=ai_component)
        elif choice == CARRIER:
            fighter_component = Fighter(player=player, hp=500, defense=0, power=0, xp=2000, base_speed=200,
                                        death_function=monster_death)
            ai_component = CarrierMonster()
            monster = Object(x, y, 'A', CARRIER, libtcod.darker_green, blocks=True,
                             fighter=fighter_component, ai=ai_component)
        elif choice == 'placeholder':
            print('placeholder encounter')
            fighter_component = Fighter(player=player, hp=10, defense=0, power=0, xp=30, base_speed=75,
                                        death_function=projectile_death)
            ai_component = ScoutMonster()
            monster = Object(x, y, 'P', 'placeholder', libtcod.darker_green, blocks=True, fighter=fighter_component,
                             ai=ai_component)

        objects.append(monster)

    max_items = utils.from_dungeon_level(dungeon_level, [[3, 1], [2, 4], [1, 6]])
    item_chances = {ITEM_DUCT_TAPE: 45,
                    ITEM_EXTRA_BATTERY: 25,
                    ITEM_RED_PAINT: 10,
                    ITEM_EMP: 10}

    # Place items
    num_items = libtcod.random_get_int(0, 0, max_items)
    for _ in range(num_items):
        (x, y) = zone.random_unblocked_coordinates(gm, objects)

        choice = utils.random_choice(item_chances)

        if choice == ITEM_DUCT_TAPE:
            item_component = Item(use_function=use_repair_player)
            item = Object(x, y, 't', ITEM_DUCT_TAPE, libtcod.violet, always_visible=True, item=item_component)
        elif choice == ITEM_EXTRA_BATTERY:
            item_component = Item(use_function=boost_player_power)
            item = Object(x, y, 'b', ITEM_EXTRA_BATTERY, libtcod.light_yellow, always_visible=True,
                          item=item_component)
        elif choice == ITEM_EMP:
            item_component = Item(use_function=cast_area_disable)
            item = Object(x, y, 'p', ITEM_EMP, libtcod.light_blue, always_visible=True,
                          item=item_component)
        elif choice == ITEM_RED_PAINT:
            item = Object(x, y, 'r', ITEM_RED_PAINT, libtcod.light_red, always_visible=True,
                          item=Item(use_function=boost_player_speed))

        objects.append(item)
        zone.register_item(item)
        item.send_to_back(objects)
Example #3
0
 def random_unblocked_coordinates(self, game_map, objects):
     (x, y) = self.random_coordinates()
     while is_blocked(x, y, game_map, objects):
         (x, y) = self.random_coordinates()
     return x, y
Example #4
0
def place_objects(room, Game):
    # choose random number of monsters
    # max number monsters per room
    nextid = 1
    max_monsters = from_dungeon_level([[10, 1], [40, 3], [50, 6], [70, 10]], data.maplist.index(Game.dungeon_levelname))
    num_monsters = libtcod.random_get_int(0, 0, max_monsters)
    monster_chances = get_monster_chances(Game)

    max_items = from_dungeon_level([[10, 1], [2, 4]], data.maplist.index(Game.dungeon_levelname))
    num_items = libtcod.random_get_int(0, 0, max_items)
    item_chances = get_item_chances(Game)

    for i in range(num_monsters):
        # choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        if not entities.is_blocked(x, y, Game):
            # create a monster
            choice = random_choice(monster_chances)

            monster = entities.Object(**entitydata.mobs[choice])
            monster.dungeon_level = data.maplist.index(Game.dungeon_levelname)
            monster.blocks = True
            monster.ai = entities.Ai(entities.BasicMonster())  # how do I set different ai?
            monster.ai.owner = monster
            monster.id = str(monster.dungeon_level) + "." + str(nextid)
            monster.name = choice + "(" + str(monster.id) + ")"
            if data.FREE_FOR_ALL_MODE:
                monster.fighter.clan = monster.name
            nextid += 1
            monster.fighter.fov = Game.map[Game.dungeon_levelname].fov_map

            print "MAPGEN--\t " + str(Game.tick) + "\t" + Game.dungeon_levelname + "\t" + " made a " + monster.name

            # give monster items if they have them
            if entitydata.mobitems[choice]:
                for itemname in entitydata.mobitems[choice]:
                    item = entities.Object(**entitydata.items[itemname])
                    monster.fighter.add_item(item)

            monster.set_location(x, y, Game)
            Game.objects[Game.dungeon_levelname].append(monster)

    for i in range(num_items):
        # choose random spot for this item
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        # only place it if the tile is not blocked
        if not entities.is_blocked(x, y, Game):
            # create an item
            choice = random_choice(item_chances)

            item = entities.Object(**entitydata.items[choice])
            item.always_visible = True

            item.set_location(x, y, Game)
            item.dungeon_level = data.maplist.index(Game.dungeon_levelname)

            Game.objects[Game.dungeon_levelname].append(item)
            item.send_to_back(Game)  # items appear below other objects
Example #5
0
def place_objects(room, Game):
    #choose random number of monsters
    #max number monsters per room
    nextid = 1
    max_monsters = from_dungeon_level([[10, 1], [40, 3], [50, 6], [70, 10]],
                                      data.maplist.index(
                                          Game.dungeon_levelname))
    num_monsters = libtcod.random_get_int(0, 0, max_monsters)
    monster_chances = get_monster_chances(Game)

    max_items = from_dungeon_level([[10, 1], [2, 4]],
                                   data.maplist.index(Game.dungeon_levelname))
    num_items = libtcod.random_get_int(0, 0, max_items)
    item_chances = get_item_chances(Game)

    for i in range(num_monsters):
        #choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        if not entities.is_blocked(x, y, Game):
            #create a monster
            choice = random_choice(monster_chances)

            monster = entities.Object(**entitydata.mobs[choice])
            monster.dungeon_level = data.maplist.index(Game.dungeon_levelname)
            monster.blocks = True
            monster.ai = entities.Ai(
                entities.BasicMonster())  #how do I set different ai?
            monster.ai.owner = monster
            monster.id = str(monster.dungeon_level) + '.' + str(nextid)
            monster.name = choice + '(' + str(monster.id) + ')'
            if data.FREE_FOR_ALL_MODE:
                monster.fighter.clan = monster.name
            nextid += 1
            monster.fighter.fov = Game.map[Game.dungeon_levelname].fov_map

            print 'MAPGEN--\t ' + str(
                Game.tick
            ) + '\t' + Game.dungeon_levelname + '\t' + ' made a ' + monster.name

            #give monster items if they have them
            if entitydata.mobitems[choice]:
                for itemname in entitydata.mobitems[choice]:
                    item = entities.Object(**entitydata.items[itemname])
                    monster.fighter.add_item(item)

            monster.set_location(x, y, Game)
            Game.objects[Game.dungeon_levelname].append(monster)

    for i in range(num_items):
        #choose random spot for this item
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        #only place it if the tile is not blocked
        if not entities.is_blocked(x, y, Game):
            #create an item
            choice = random_choice(item_chances)

            item = entities.Object(**entitydata.items[choice])
            item.always_visible = True

            item.set_location(x, y, Game)
            item.dungeon_level = data.maplist.index(Game.dungeon_levelname)

            Game.objects[Game.dungeon_levelname].append(item)
            item.send_to_back(Game)  #items appear below other objects