コード例 #1
0
 public static CheckRegion Instance(TileRegion region)
 {
     CheckRegion ret;
     if (!instances.TryGetValue(region, out ret))
         ret = instances[region] = new CheckRegion(region);
     return ret;
 }
コード例 #2
0
ファイル: Market.cs プロジェクト: po-omena/NR-CORE
        private ItemType GetItemType(TileRegion region)
        {
            switch (region)
            {
            case TileRegion.Store_9:
                return(ItemType.Weapon);

            case TileRegion.Store_10:
                return(ItemType.Ability);

            case TileRegion.Store_11:
                return(ItemType.Armor);

            case TileRegion.Store_12:
                return(ItemType.Ring);

            case TileRegion.Store_13:
                return(ItemType.StatPot);

            case TileRegion.Store_14:
                return(ItemType.Other);

            default:
                return(ItemType.None);
            }
        }
コード例 #3
0
        /* The following method has some subtleties to it that need to be explained. The purpose of it is to trace out the
         * floor tiles in the room that are adjacent to a wall tile. The tricky part is ensuring that this is done
         * in an orderly fashion, i.e. that it traces out a more or less continuous path (some error is fine, but a random
         * ordering is not, as the ordering of the edge tiles is needed for an enormous optimization in the connectivity
         * algorithm used elsewhere).
         *
         * The basic idea is to start on an edge tile, and then perform a depth-first search along edge tiles. The difficulty
         * comes from two situations. First, consider this example:
         *
         * x x o
         * x x o
         * 1 2 o
         * o o o
         *
         * x represents wall, o represents floor, numbers represent the path travelled (and the order). If we only
         * look at horizontal neighbors, the search will terminate at 2, because no adjacent floor is adjacent to a wall.
         * So we need to look at diagonal neighbors. That leads to the following problem:
         *
         * x x x x
         * x x o x
         * x 3 x x
         * 1 2 x x
         *
         * The remaining o is not connected to the path so far, but it's diagonally adjacent to the 3. This is handled
         * by explicitly checking for this situation: in order to take a diagonal jump, one of the
         * two adjacent tiles must be a floor. i.e. one of these situations:
         *
         * x x x x     x x x x      x x x x
         * x x o x     x o o x      x o o x
         * x 3 o x     x 3 x x      x 3 o x
         * 1 2 x x     1 2 x x      1 2 x x
         *
         * The final complexity is the possibility of the path jumping, leading to irregularities in the edges.
         * Example:
         *
         * x x o o o 8 x
         * x x 4 5 6 7 x
         * 1 2 3 x x o x
         * o o o x x o x
         *
         * Ultimately this level of error is accepted as is. */

        public TileRegion Extract(TileRegion region)
        {
            UnityEngine.Assertions.Assert.AreNotEqual(region.Count, 0, "Room is empty!");
            List <Coord>  edgeTiles = new List <Coord>(region.Count);
            Stack <Coord> stack     = new Stack <Coord>();
            Coord         firstTile = GetStartingEdgeTile(map, region);

            stack.Push(firstTile);
            edgeTiles.Add(firstTile);
            visited[firstTile.x, firstTile.y] = true;

            while (stack.Count > 0)
            {
                Coord tile = stack.Pop();
                foreach (Coord adj in GetAdjacentCoords(tile, adjacentTiles))
                {
                    if (!visited[adj.x, adj.y] && FoundEdgeTile(tile, adj, map))
                    {
                        visited[adj.x, adj.y] = true;
                        stack.Push(adj);
                        edgeTiles.Add(adj);
                    }
                }
            }
            return(new TileRegion(edgeTiles));
        }
コード例 #4
0
        public static ConnectionInfo FindConnection(TileRegion regionA, TileRegion regionB, int roomIndexA, int roomIndexB)
        {
            Coord bestTileA    = new Coord();
            Coord bestTileB    = new Coord();
            float bestDistance = float.MaxValue;

            int indexA = 0;

            while (indexA < regionA.Count)
            {
                int   indexB               = 0;
                Coord tileA                = regionA[indexA];
                Coord bestTileBThisLoop    = new Coord();
                float bestDistanceThisLoop = float.MaxValue;
                while (indexB < regionB.Count)
                {
                    Coord tileB    = regionB[indexB];
                    float distance = tileA.Distance(tileB);
                    if (distance < bestDistanceThisLoop)
                    {
                        bestDistanceThisLoop = distance;
                        bestTileBThisLoop    = tileB;
                    }
                    indexB += (int)distance;
                }
                if (bestDistanceThisLoop < bestDistance)
                {
                    bestTileA    = tileA;
                    bestTileB    = bestTileBThisLoop;
                    bestDistance = bestDistanceThisLoop;
                }
                indexA += (int)bestDistanceThisLoop;
            }
            return(new ConnectionInfo(bestTileA, bestTileB, roomIndexA, roomIndexB, bestDistance));
        }
コード例 #5
0
        /// <summary>
        /// Build the tile buffer at the specified region index with target coordinates' tiles
        /// </summary>
        /// <param name="region_index">Index in the local region array</param>
        /// <param name="region_i">X coordinate of the region in the grid</param>
        /// <param name="region_j">Y coordinate of the region in the grid</param>
        void BuildBuffer(int region_index, int region_i, int region_j)
        {
            int tile_count = RegionWidth * RegionHeight;
            var grid       = ((Objects.TileMap)GameObject).Grid;

            // TODO: account for the resolution change
            if (regions[region_index] == null)
            {
                regions[region_index] = new TileRegion(tile_count);
            }

            var region = regions[region_index];

            region.ResetBuffers();

            for (int i = region_i * RegionWidth; i < (region_i + 1) * RegionWidth; i++)
            {
                for (int j = region_j * RegionHeight; j < (region_j + 1) * RegionHeight; j++)
                {
                    var type = grid[i, j];
                    if (type == 0)
                    {
                        continue;
                    }
                    region.AddBackgroundTile(i, j, type);
                }
            }
            region.SetData();
        }
コード例 #6
0
ファイル: PlanetGenerator.cs プロジェクト: Lagostra/PlanetHex
 private Layer GenerateEmptyLayer(TileRegion tileRegion, int layerNumber)
 {
     return(new Layer
     {
         Blocks = new int[tileRegion.Tiles.Count],
         LayerNumber = layerNumber
     });
 }
コード例 #7
0
        public static CheckRegion Instance(TileRegion region)
        {
            CheckRegion ret;

            if (!instances.TryGetValue(region, out ret))
            {
                ret = instances[region] = new CheckRegion(region);
            }
            return(ret);
        }
コード例 #8
0
ファイル: PlanetGenerator.cs プロジェクト: Lagostra/PlanetHex
 private Chunk GenerateEmptyChunk(TileRegion tileRegion, int chunkNumber)
 {
     return(new Chunk
     {
         Layers = Enumerable.Range(0, _settings.ChunkHeight)
                  .Select(layerNumber => GenerateEmptyLayer(tileRegion, layerNumber))
                  .ToArray(),
         ChunkNumber = chunkNumber
     });
 }
コード例 #9
0
        public IntPoint GetRandomTile(TileRegion region)
        {
            if (!Map.Regions.ContainsKey(region))
            {
                return(new IntPoint(0, 0));
            }
            var             rand  = new Random();
            List <IntPoint> tiles = Map.Regions[region];

            return(tiles[rand.Next(0, tiles.Count)]);
        }
コード例 #10
0
        static TileRegion[] ExtractEdges(Map map, List <TileRegion> regions)
        {
            EdgeExtractor extractor = new EdgeExtractor(map);

            TileRegion[] rooms = new TileRegion[regions.Count];
            for (int i = 0; i < rooms.Length; i++)
            {
                rooms[i] = extractor.Extract(regions[i]);
            }
            return(rooms);
        }
コード例 #11
0
 private void AddRegion(TileRegion region, int x, int y)
 {
     if (Regions.ContainsKey(region))
     {
         Regions[region].Add(new IntPoint(x, y));
     }
     else
     {
         Regions.Add(region, new List <IntPoint> {
             new IntPoint(x, y)
         });
     }
 }
コード例 #12
0
ファイル: PlanetGenerator.cs プロジェクト: Lagostra/PlanetHex
        private Region GenerateEmptyRegion(TileRegion tileRegion, int regionNumber)
        {
            var numChunks = (int)Mathf.Ceil((float)_settings.HeightLimit / _settings.ChunkHeight);

            return(new Region
            {
                Chunks = Enumerable.Range(0, numChunks)
                         .Select(chunkNumber => GenerateEmptyChunk(tileRegion, chunkNumber))
                         .ToArray(),
                RegionNumber = regionNumber,
                Center = tileRegion.Center,
            });
        }
コード例 #13
0
ファイル: Reproduce.cs プロジェクト: smillyz/Valor-Server
 public Reproduce(string children      = null,
                  double densityRadius = 10,
                  int densityMax       = 5,
                  Cooldown coolDown    = new Cooldown(),
                  TileRegion region    = TileRegion.None,
                  double regionRange   = 10)
 {
     _children      = children == null ? null : (ushort?)GetObjType(children);
     _densityRadius = densityRadius;
     _densityMax    = densityMax;
     _coolDown      = coolDown.Normalize(60000);
     _region        = region;
     _regionRange   = regionRange;
 }
コード例 #14
0
        public Position?GetRegionPosition(TileRegion region)
        {
            if (Map.Regions.All(t => t.Value != region))
            {
                return(null);
            }

            var reg = Map.Regions.Single(t => t.Value == region);

            return(new Position()
            {
                X = reg.Key.X, Y = reg.Key.Y
            });
        }
コード例 #15
0
 void CreateArea()
 {
     arrRegion = new TileRegion[numberRegionVerAndHor, numberRegionVerAndHor];
     for (int x = 0; x < numberRegionVerAndHor; x++)
     {
         for (int y = 0; y < numberRegionVerAndHor; y++)
         {
             Vector3    regionPosition = new Vector3(-numberRegionVerAndHor / 2 + x * regionSize, 0, -numberRegionVerAndHor / 2 + y * regionSize);
             TileRegion regionCreated  = Instantiate(regionPref, regionPosition, regionPref.transform.rotation) as TileRegion;
             regionCreated.x = x;
             regionCreated.y = y;
             arrRegion[x, y] = regionCreated;
             regionCreated.transform.parent        = this.transform;
             regionCreated.transform.localScale    = new Vector3(regionSize, regionSize, 0f);
             regionCreated.renderer.material.color = Color.white;
         }
     }
 }
コード例 #16
0
        public ReproduceGroup(
            string group         = null,
            double densityRadius = 10,
            int densityMax       = 5,
            Cooldown coolDown    = new Cooldown(),
            TileRegion region    = TileRegion.None,
            double regionRange   = 10)
        {
            _children = BehaviorDb.InitGameData.ObjectDescs.Values
                        .Where(x => x.Group == group)
                        .Select(x => x.ObjectType).ToArray();

            _group         = group;
            _densityRadius = densityRadius;
            _densityMax    = densityMax;
            _coolDown      = coolDown.Normalize(60000);
            _region        = region;
            _regionRange   = regionRange;
        }
コード例 #17
0
ファイル: PlanetGenerator.cs プロジェクト: Lagostra/PlanetHex
        private Region GenerateRegion(TileRegion tileRegion, int regionNumber)
        {
            var region = GenerateEmptyRegion(tileRegion, regionNumber);

            foreach (var(tile, tileIndex) in tileRegion.Tiles.WithIndex())
            {
                var tileStack = GenerateTileStack(tile);

                foreach (var(chunk, chunkIndex) in region.Chunks.WithIndex())
                {
                    foreach (var(layer, layerIndex) in chunk.Layers.WithIndex())
                    {
                        layer.Blocks[tileIndex] = tileStack[chunkIndex * _settings.ChunkHeight + layerIndex];
                    }
                }
            }

            return(region);
        }
コード例 #18
0
        public void Reset(Wmap map = null, int x = 0, int y = 0)
        {
            TileId   = _originalDesc.TileId;
            TileDesc = _originalDesc.TileDesc;

            ObjType = _originalDesc.ObjType;
            ObjDesc = _originalDesc.ObjDesc;
            ObjCfg  = _originalDesc.ObjCfg;

            Terrain   = _originalDesc.Terrain;
            Region    = _originalDesc.Region;
            Elevation = _originalDesc.Elevation;

            if (map != null)
            {
                InitConnection(map, x, y);
            }

            UpdateCount++;
        }
コード例 #19
0
        public TossObject(string child, double range = 5, double?angle                    = null,
                          Cooldown coolDown          = new Cooldown(), int coolDownOffset = 0,
                          bool tossInvis             = false, double probability          = 1, string group = null,
                          double?minAngle            = null, double?maxAngle = null,
                          double?minRange            = null, double?maxRange = null,
                          double?densityRange        = null, int?maxDensity  = null,
                          TileRegion region          = TileRegion.None, double regionRange = 10
                          )
        {
            if (group == null)
            {
                _children = new ushort[] { GetObjType(child) }
            }
            ;
            else
            {
                _children = BehaviorDb.InitGameData.ObjectDescs.Values
                            .Where(x => x.Group == group)
                            .Select(x => x.ObjectType).ToArray();
            }

            _range          = range;
            _angle          = angle * Math.PI / 180;
            _coolDown       = coolDown.Normalize();
            _coolDownOffset = coolDownOffset;
            _tossInvis      = tossInvis;
            _probability    = probability;
            _minRange       = minRange;
            _maxRange       = maxRange;
            _minAngle       = minAngle * Math.PI / 180;
            _maxAngle       = maxAngle * Math.PI / 180;
            _densityRange   = densityRange;
            _maxDensity     = maxDensity;
            _group          = group;
            _region         = region;
            _regionRange    = regionRange;
        }
コード例 #20
0
ファイル: Wmap.cs プロジェクト: Club559/Travs-Domain-Server
 private void AddRegion(TileRegion region, int x, int y)
 {
     if (Regions.ContainsKey(region))
         Regions[region].Add(new IntPoint(x, y));
     else
         Regions.Add(region, new List<IntPoint> {new IntPoint(x, y)});
 }
コード例 #21
0
 static Coord GetStartingEdgeTile(Map map, TileRegion region)
 {
     // Note that in practice, this should return the very first item in alltiles, but that may change in the future.
     return(region.First(tile => map.IsAdjacentToWallFast(tile.x, tile.y)));
 }
コード例 #22
0
 private CheckRegion(TileRegion region)
 {
     this.region = region;
 }
コード例 #23
0
ファイル: World.cs プロジェクト: Club559/Travs-Domain-Server
 public IntPoint GetRandomTile(TileRegion region)
 {
     if (!Map.Regions.ContainsKey(region))
         return new IntPoint(0, 0);
     var rand = new Random();
     List<IntPoint> tiles = Map.Regions[region];
     return tiles[rand.Next(0, tiles.Count)];
 }
コード例 #24
0
 private CheckRegion(TileRegion region)
 {
     this.region = region;
 }