def place_pack(monster): (min, max) = packs[monster.name] cur_x = monster.x cur_y = monster.y failures = 0 monsters_to_place = settings.RNG.get_int(min, max) - 1 while monsters_to_place > 0: x = cur_x + settings.RNG.get_int(-1, 1) y = cur_y + settings.RNG.get_int(-1, 1) if not Object.is_blocked(x, y): packmonster = copy.deepcopy(monster) packmonster.x = x packmonster.y = y settings.objects.append(packmonster) cur_x = x cur_y = y monsters_to_place -= 1 failures = 0 else: failures += 1 if failures > 10: cur_x = monster.x cur_y = monster.y if failures > 30: monsters_to_place -= 1
def place_objects(room): # make sure we don't accidentally change these from monster_list import bestiary from item_list import all_items #choose random number of monsters num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS) 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) #only place it if the tile is not blocked if not Object.is_blocked(x, y): # 80% chance of getting an orc if libtcod.random_get_int(0, 0, 100) < 80: #create an orc monster = bestiary["Orc"](x=x, y=y) else: #create a troll monster = bestiary["Troll"](x=x, y=y) g.actors.append(monster) #choose random number of items num_items = libtcod.random_get_int(0, 0, MAX_ROOM_ITEMS) 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 Object.is_blocked(x, y): dice = libtcod.random_get_int(0, 0, 100) if dice < 50: #create a healing potion (50% chance) item = all_items["HealingPotion"](x, y) else: # create a mana potion (50% chance) item = all_items["ManaPotion"](x, y) g.items.append(item) item.send_to_back() # items appear below other objects
def place_objects(rect): max_monster = from_dungeon_level([[2, 1], [3, 4], [5, 6]]) monster_chances = {} for key in monsters: monster_chances[key] = \ from_dungeon_level(monsters[key].placement_range) max_items = from_dungeon_level([[1, 1], [2, 4]]) item_chances = {} for key in items: item_chances[key] = from_dungeon_level(items[key].placement_range) num_monsters = settings.RNG.get_int(0, max_monster) for i in range(num_monsters): x = settings.RNG.get_int(rect.x1 + 1, rect.x2 - 1) y = settings.RNG.get_int(rect.y1 + 1, rect.y2 - 1) if not Object.is_blocked(x, y): choice = random_choice(monster_chances) monster = copy.deepcopy(monsters[choice]) monster.x = x monster.y = y if choice in packs: place_pack(monster) settings.objects.append(monster) num_items = settings.RNG.get_int(0, max_items) for i in range(num_items): x = settings.RNG.get_int(rect.x1 + 1, rect.x2 - 1) y = settings.RNG.get_int(rect.y1 + 1, rect.y2 - 1) if not Object.is_blocked(x, y): choice = random_choice(item_chances) item = copy.deepcopy(items[choice]) item.x = x item.y = y settings.objects.append(item) item.send_to_back() item.always_visible = True