Exemplo n.º 1
0
        protected static ListPathTraversalNode?ChooseConnection(IRandom rand, FloorPlan floorPlan, List <RoomHallIndex> candList)
        {
            SpawnList <ListPathTraversalNode> expansions = GetPossibleExpansions(floorPlan, candList);

            if (expansions.Count > 0)
            {
                return(expansions.Pick(rand));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public T Pick(IRandom rand)
        {
            SpawnDict <string, SpawnList <T> > tempSpawn = new SpawnDict <string, SpawnList <T> >();

            foreach (string key in Spawns.GetKeys())
            {
                SpawnList <T> otherList = Spawns.GetSpawn(key);
                if (!otherList.CanPick)
                {
                    continue;
                }
                tempSpawn.Add(key, otherList, Spawns.GetSpawnRate(key));
            }
            SpawnList <T> choice = tempSpawn.Pick(rand);

            return(choice.Pick(rand));
        }
Exemplo n.º 3
0
        public Loc FindPlacement(IRandom rand, Dictionary <Dir4, List <IRoomGen> > adjacentsByDir, IRoomGen newGen, IRoomGen oldGen)
        {
            SpawnList <Loc> possiblePlacements = this.GetPossiblePlacements(adjacentsByDir, newGen, oldGen);

            return(possiblePlacements.SpawnTotal == 0 ? new Loc(-1) : possiblePlacements.Pick(rand));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Chooses a node to expand the path from based on the specified branch setting.
        /// </summary>
        /// <param name="availableExpansions">todo: describe availableExpansions parameter on ChooseRoomExpansion</param>
        /// <param name="prepareRoom">todo: describe prepareRoom parameter on ChooseRoomExpansion</param>
        /// <param name="hallPercent">todo: describe hallPercent parameter on ChooseRoomExpansion</param>
        /// <param name="rand"></param>
        /// <param name="floorPlan"></param>
        /// <returns>A set of instructions on how to expand the path.</returns>
        public static ListPathBranchExpansion?ChooseRoomExpansion(RoomPrep prepareRoom, int hallPercent, IRandom rand, FloorPlan floorPlan, List <RoomHallIndex> availableExpansions)
        {
            if (availableExpansions.Count == 0)
            {
                return(null);
            }

            for (int ii = 0; ii < 30; ii++)
            {
                // choose the next room to add to
                RoomHallIndex firstExpandFrom = availableExpansions[rand.Next(availableExpansions.Count)];
                RoomHallIndex expandFrom      = firstExpandFrom;
                IRoomGen      roomFrom        = floorPlan.GetRoomHall(firstExpandFrom).RoomGen;

                // choose the next room to add
                // choose room size/fulfillables
                // note: by allowing halls to be picked as extensions, we run the risk of adding dead-end halls
                // halls should always terminate at rooms?
                // this means... doubling up with hall+room?
                bool     addHall = rand.Next(100) < hallPercent;
                IRoomGen hall    = null;
                if (addHall)
                {
                    hall = prepareRoom(rand, floorPlan, true);

                    // randomly choose a perimeter to assign this to
                    SpawnList <Loc> possibleHallPlacements = new SpawnList <Loc>();
                    foreach (Dir4 dir in DirExt.VALID_DIR4)
                    {
                        AddLegalPlacements(possibleHallPlacements, floorPlan, expandFrom, roomFrom, hall, dir);
                    }

                    // at this point, all possible factors for whether a placement is legal or not is accounted for
                    // therefor just pick one
                    if (possibleHallPlacements.Count == 0)
                    {
                        continue;
                    }

                    // randomly choose one
                    Loc hallCandLoc = possibleHallPlacements.Pick(rand);

                    // set location
                    hall.SetLoc(hallCandLoc);

                    // change the roomfrom for the upcoming room
                    expandFrom = new RoomHallIndex(-1, false);
                    roomFrom   = hall;
                }

                IRoomGen room = prepareRoom(rand, floorPlan, false);

                // randomly choose a perimeter to assign this to
                SpawnList <Loc> possiblePlacements = new SpawnList <Loc>();
                foreach (Dir4 dir in DirExt.VALID_DIR4)
                {
                    AddLegalPlacements(possiblePlacements, floorPlan, expandFrom, roomFrom, room, dir);
                }

                // at this point, all possible factors for whether a placement is legal or not is accounted for
                // therefore just pick one
                if (possiblePlacements.Count > 0)
                {
                    // randomly choose one
                    Loc candLoc = possiblePlacements.Pick(rand);

                    // set location
                    room.SetLoc(candLoc);
                    return(new ListPathBranchExpansion(firstExpandFrom, room, (IPermissiveRoomGen)hall));
                }
            }

            return(null);
        }