예제 #1
0
        private static bool add_corridor(Endpoint ep, bool follow)
        {
            if (MapBuilder.fCorridorTiles.Count == 0)
            {
                return(false);
            }
            int  num  = Session.Random.Next() % MapBuilder.fCorridorTiles.Count;
            Tile item = MapBuilder.fCorridorTiles[num];

            if (ep != null)
            {
                Pair <TileData, Direction> pair = MapBuilder.add_tile(item, ep, follow, true);
                if (pair == null)
                {
                    return(false);
                }
                MapBuilder.fEndpoints.Add(MapBuilder.get_endpoint(item, pair.First, pair.Second));
            }
            else
            {
                TileData  tileDatum         = MapBuilder.add_first_tile(item);
                Direction startingDirection = MapBuilder.get_starting_direction(MapBuilder.get_orientation(item, tileDatum));
                MapBuilder.fEndpoints.Add(MapBuilder.get_endpoint(item, tileDatum, startingDirection));
            }
            return(true);
        }
예제 #2
0
        private static bool add_doorway(Endpoint ep)
        {
            List <Tile> item = MapBuilder.fTiles[TileCategory.Doorway];

            if (item.Count == 0)
            {
                return(false);
            }
            int  num  = Session.Random.Next() % item.Count;
            Tile tile = item[num];

            if (ep != null)
            {
                Pair <TileData, Direction> pair = MapBuilder.add_tile(tile, ep, true, true);
                if (pair == null)
                {
                    return(false);
                }
                MapBuilder.fEndpoints.Add(MapBuilder.get_endpoint(tile, pair.First, pair.Second));
            }
            return(true);
        }
예제 #3
0
        private static bool add_stairway(Endpoint ep)
        {
            List <Tile> item = MapBuilder.fTiles[TileCategory.Stairway];

            if (item.Count == 0)
            {
                return(false);
            }
            int  num  = Session.Random.Next() % item.Count;
            Tile tile = item[num];

            if (ep == null)
            {
                TileData  tileDatum         = MapBuilder.add_first_tile(tile);
                Direction startingDirection = MapBuilder.get_starting_direction(MapBuilder.get_orientation(tile, tileDatum));
                MapBuilder.fEndpoints.Add(MapBuilder.get_endpoint(tile, tileDatum, startingDirection));
            }
            else if (MapBuilder.add_tile(tile, ep, true, true) == null)
            {
                return(false);
            }
            return(true);
        }
예제 #4
0
        private static bool add_area(Endpoint ep)
        {
            if (MapBuilder.fRoomTiles.Count == 0)
            {
                return(false);
            }
            List <Tile> tiles = new List <Tile>();
            int         num   = 1 + Session.Random.Next() % 5;

            while (tiles.Count != num)
            {
                int num1 = Session.Random.Next() % MapBuilder.fRoomTiles.Count;
                tiles.Add(MapBuilder.fRoomTiles[num1]);
            }
            List <Endpoint> endpoints = new List <Endpoint>()
            {
                ep
            };
            List <Pair <Tile, TileData> > pairs = new List <Pair <Tile, TileData> >();

            foreach (Tile tile in tiles)
            {
                if (endpoints.Count == 0)
                {
                    break;
                }
                int      num2 = Session.Random.Next() % endpoints.Count;
                Endpoint item = endpoints[num2];
                Pair <TileData, Direction> pair = MapBuilder.add_tile(tile, item, false, false);
                if (pair == null)
                {
                    continue;
                }
                endpoints.Remove(item);
                pairs.Add(new Pair <Tile, TileData>(tile, pair.First));
                if (pair.Second != Direction.South)
                {
                    endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.North));
                }
                if (pair.Second != Direction.West)
                {
                    endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.East));
                }
                if (pair.Second != Direction.North)
                {
                    endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.South));
                }
                if (pair.Second == Direction.East)
                {
                    continue;
                }
                endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.West));
            }
            if (pairs.Count != 0)
            {
                MapBuilder.add_map_area(pairs);
                List <Tile> item1 = MapBuilder.fTiles[TileCategory.Feature];
                if (item1.Count != 0)
                {
                    int area = 0;
                    foreach (Pair <Tile, TileData> pair1 in pairs)
                    {
                        area += pair1.First.Area;
                    }
                    int num3 = Session.Random.Next() % (area / 10);
                    int num4 = 0;
                    int num5 = 0;
                    List <Pair <Tile, TileData> > pairs1 = new List <Pair <Tile, TileData> >();
                    while (num4 != num3 && num5 != 1000)
                    {
                        int      num6      = Session.Random.Next() % item1.Count;
                        Tile     tile1     = item1[num6];
                        TileData tileDatum = new TileData()
                        {
                            TileID    = tile1.ID,
                            Rotations = Session.Random.Next() % 4
                        };
                        int num7 = (tileDatum.Rotations % 2 == 0 ? tile1.Size.Width : tile1.Size.Height);
                        int num8 = (tileDatum.Rotations % 2 == 0 ? tile1.Size.Height : tile1.Size.Width);
                        List <Pair <Tile, TileData> > pairs2 = new List <Pair <Tile, TileData> >();
                        foreach (Pair <Tile, TileData> pair2 in pairs)
                        {
                            int num9  = (pair2.Second.Rotations % 2 == 0 ? pair2.First.Size.Width : pair2.First.Size.Height);
                            int num10 = (pair2.Second.Rotations % 2 == 0 ? pair2.First.Size.Height : pair2.First.Size.Width);
                            int num11 = num9 - num7;
                            if (num11 < 0 || num10 - num8 < 0)
                            {
                                continue;
                            }
                            pairs2.Add(pair2);
                        }
                        bool flag = false;
                        if (pairs2.Count != 0)
                        {
                            int num12 = Session.Random.Next() % pairs2.Count;
                            Pair <Tile, TileData> item2 = pairs2[num12];
                            int num13 = (item2.Second.Rotations % 2 == 0 ? item2.First.Size.Width : item2.First.Size.Height);
                            int num14 = (item2.Second.Rotations % 2 == 0 ? item2.First.Size.Height : item2.First.Size.Width);
                            int num15 = num13 - num7;
                            int num16 = num14 - num8;
                            if (num15 >= 0 && num16 >= 0)
                            {
                                Point location = item2.Second.Location;
                                int   x        = location.X;
                                if (num15 != 0)
                                {
                                    x = x + Session.Random.Next() % num15;
                                }
                                location = item2.Second.Location;
                                int y = location.Y;
                                if (num16 != 0)
                                {
                                    y = y + Session.Random.Next() % num16;
                                }
                                tileDatum.Location = new Point(x, y);
                                bool      flag1 = true;
                                Rectangle _rect = MapBuilder.get_rect(tile1, tileDatum);
                                foreach (Pair <Tile, TileData> pair3 in pairs1)
                                {
                                    if (!MapBuilder.get_rect(pair3.First, pair3.Second).IntersectsWith(_rect))
                                    {
                                        continue;
                                    }
                                    flag1 = false;
                                    break;
                                }
                                if (flag1)
                                {
                                    MapBuilder.fMap.Tiles.Add(tileDatum);
                                    pairs1.Add(new Pair <Tile, TileData>(tile1, tileDatum));
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (!flag)
                        {
                            num5++;
                        }
                        else
                        {
                            num4++;
                            num5 = 0;
                        }
                    }
                }
                int num17 = 1 + Session.Random.Next() % 3;
                int num18 = 0;
                int num19 = 0;
                while (num18 != num17 && endpoints.Count != 0 && num19 != 1000)
                {
                    int      num20    = Session.Random.Next() % endpoints.Count;
                    Endpoint endpoint = endpoints[num20];
                    bool     flag2    = true;
                    switch (Session.Random.Next() % 2)
                    {
                    case 0:
                    {
                        flag2 = MapBuilder.add_doorway(endpoint);
                        break;
                    }

                    case 1:
                    {
                        flag2 = MapBuilder.add_corridor(endpoint, true);
                        break;
                    }
                    }
                    if (!flag2)
                    {
                        num19++;
                    }
                    else
                    {
                        num18++;
                        endpoints.Remove(endpoint);
                        num19 = 0;
                    }
                }
            }
            return(pairs.Count != 0);
        }