Пример #1
0
  def place_monsters(state, monsters, game_map, room, objects):
    for i in range(len(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 game_map.is_blocked(objects, x, y):
        monster = state.monsters.get_data_object(monsters[i])
        objects.append(monster.create_at_location(x, y))
Пример #2
0
 def place_items(objects_to_place, object_data_type, game_map, room, objects):
   for i in range(len(objects_to_place)):
     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 game_map.is_blocked(objects, x, y):
       item_to_place = object_data_type.get_data_object(objects_to_place[i])
       item = item_to_place.create_at_location(x, y)
       objects.append(item)
       item.send_to_back(objects)  # items appear below other objects
Пример #3
0
 def take_turn(self, util):
     # Move randomly
     if self.num_turns > 0:
         self.owner.move(
             util.objects, util.game_map, libtcod.random_get_int(0, -1, 1), libtcod.random_get_int(0, -1, 1)
         )
         self.num_turns -= 1
     else:
         # reset to old AI
         self.owner.ai = self.old_ai
         util.status_panel.message("The " + self.owner.name + " is no longer confused!", libtcod.red)
Пример #4
0
 def random_chance_index(chances):
     dice = libtcod.random_get_int(0, 1, sum(chances))
     running_sum = 0
     choice = 0
     for w in chances:
         running_sum += w
         if dice <= running_sum:
             return choice
         choice += 1
Пример #5
0
  def get_items_to_place(state):
    max_items_table = [[3, 0], [5, 3]]
    max_items = Util.from_dungeon_level(state, max_items_table)
    item_chances = {
        ItemConstants.HEALTH_POTION: 35,
        ItemConstants.SCROLL_OF_LIGHTNING_BOLT: Util.from_dungeon_level(state, [[25, 1]]),
        ItemConstants.SCROLL_OF_FIREBALL: Util.from_dungeon_level(state, [[25, 1]]),
        ItemConstants.SCROLL_OF_CONFUSE: Util.from_dungeon_level(state, [[10, 1]]),
    }
    equipment_chances = {
        EquipmentConstants.SWORD: 50,  # Util.from_dungeon_level(state, [[5, 4]]),
        EquipmentConstants.SHIELD: 50  # Util.from_dungeon_level(state, [[15, 8]]),
    }
    num_total_items = libtcod.random_get_int(0, 0, max_items)
    num_items = libtcod.random_get_int(0, 0, num_total_items)
    num_equipments = num_total_items - num_items

    items = [Util.random_choice(item_chances) for i in range(num_items)]
    equipments = [Util.random_choice(equipment_chances) for i in range(num_equipments)]
    return items, equipments
Пример #6
0
  def get_monsters_to_place(state):
    max_monsters_table = [[2, 0], [3, 3], [5, 5]]
    max_monsters = Util.from_dungeon_level(state, max_monsters_table)

    # choose random number of monsters
    monster_chances = {
      MonsterConstants.ORC: 80,
      MonsterConstants.TROLL: Util.from_dungeon_level(state, [[15, 3], [30, 5], [60, 7]])
    }
    num_monsters = libtcod.random_get_int(0, 0, max_monsters)
    monsters = [Util.random_choice(monster_chances) for i in range(num_monsters)]
    return monsters
Пример #7
0
 def connect_two_rooms(game_map, old_room, new_room):
   if old_room and new_room:
     choice_points = libtcod.random_get_int(0, 0, 3)
     cx1, cy1 = old_room.center()
     cx2, cy2 = new_room.center()
     rx1, ry1 = old_room.get_random_point()
     rx2, ry2 = new_room.get_random_point()
     if choice_points == 0:
       MapCreation.create_h_tunnel(game_map, cx1, cx2, cy1)
       MapCreation.create_v_tunnel(game_map, cy1, cy2, cx2)
     elif choice_points == 1:
       MapCreation.create_v_tunnel(game_map, cy1, cy2, cx2)
       MapCreation.create_h_tunnel(game_map, cx1, cx2, cy2)
     elif choice_points == 2:
       MapCreation.create_h_tunnel(game_map, rx1, rx2, ry1)
       MapCreation.create_v_tunnel(game_map, ry1, ry2, rx2)
     elif choice_points == 3:
       MapCreation.create_v_tunnel(game_map, ry1, ry2, rx2)
       MapCreation.create_h_tunnel(game_map, rx1, rx2, ry2)
Пример #8
0
 def create_rect_for_room():
   w = libtcod.random_get_int(0, MapConstants.ROOM_MIN_SIZE, MapConstants.ROOM_MAX_SIZE)
   h = libtcod.random_get_int(0, MapConstants.ROOM_MIN_SIZE, MapConstants.ROOM_MAX_SIZE)
   x = libtcod.random_get_int(0, 0, MapConstants.MAP_WIDTH - w - 1)
   y = libtcod.random_get_int(0, 0, MapConstants.MAP_HEIGHT - h - 1)
   return Rect(x, y, w, h)