コード例 #1
0
        /// <summary>
        /// Generates usually one random Monster chosen appropriately for the given depth. May
        /// generate more than one if the Monster chosen has escorts or appears in groups. Adds
        /// them to the current dungeon.
        /// </summary>
        /// <param name="level">Dungeon level to generate at.</param>
        /// <returns>The new Monsters that were added to the Dungeon.</returns>
        public static IList <Monster> AddRandom(Dungeon dungeon, int level, Vec startPos)
        {
            Race race = Race.Random(dungeon, level, true);

            List <Monster> monsters = new List <Monster>();

            // create the monster(s)
            Monster monster = new Monster(startPos, race);

            monsters.Add(monster);
            dungeon.Entities.Add(monster);

            // generate friends
            if (race.NumberInGroup > 1)
            {
                int numMonsters = Rng.TriangleInt(race.NumberInGroup, race.NumberInGroup / 3);
                int tries       = 0;
                while ((monsters.Count < numMonsters) && (tries < 100))
                {
                    tries++;

                    // pick a random spot next to one of the monsters in the group
                    Vec pos;
                    if (dungeon.TryFindOpenAdjacent(Rng.Item(monsters).Position, out pos))
                    {
                        // found one, so put another there
                        Monster buddy = new Monster(pos, race);
                        monsters.Add(buddy);
                        dungeon.Entities.Add(buddy);
                    }
                }
            }

            return(monsters);
        }
コード例 #2
0
        void IFeatureWriter.Populate(Vec pos, int monsterDensity, int itemDensity, int depth)
        {
            // test every open tile
            if (mDungeon.Tiles[pos].IsPassable)
            {
                // place a monster
                if ((mDungeon.Entities.GetAt(pos) == null) && (Rng.Int(1000) < monsterDensity + (depth / 4)))
                {
                    Monster.AddRandom(mDungeon, depth, pos);
                }

                // place an item
                if (Rng.Int(1000) < itemDensity + (depth / 4))
                {
                    Race race = Race.Random(mDungeon, depth, false);
                    race.PlaceDrop(mDungeon, pos);
                }
            }
        }