OpenRA.TileSet.GetTerrainIndex C# (CSharp) Method

GetTerrainIndex() public method

public GetTerrainIndex ( TerrainTile r ) : byte
r TerrainTile
return byte
        public byte GetTerrainIndex(TerrainTile r)
        {
            TerrainTemplateInfo tpl;
            if (!Templates.TryGetValue(r.Type, out tpl))
                return defaultWalkableTerrainIndex;

            if (tpl.Contains(r.Index))
            {
                var tile = tpl[r.Index];
                if (tile != null && tile.TerrainType != byte.MaxValue)
                    return tile.TerrainType;
            }

            return defaultWalkableTerrainIndex;
        }

Same methods

TileSet::GetTerrainIndex ( string type ) : byte

Usage Example

Example #1
0
        int[] LoadTiles(TileSet tileSet, MiniYaml y)
        {
            var nodes = y.ToDictionary()["Tiles"].Nodes;

            if (!PickAny)
            {
                var tiles = new int[Size.X * Size.Y];

                for (var i = 0; i < tiles.Length; i++)
                {
                    tiles[i] = -1;
                }

                foreach (var node in nodes)
                {
                    int key;
                    if (!int.TryParse(node.Key, out key) || key < 0 || key >= tiles.Length)
                    {
                        throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
                    }

                    tiles[key] = tileSet.GetTerrainIndex(node.Value.Value);
                }

                return(tiles);
            }
            else
            {
                var tiles = new int[nodes.Count];
                var i     = 0;

                foreach (var node in nodes)
                {
                    int key;
                    if (!int.TryParse(node.Key, out key) || key != i++)
                    {
                        throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
                    }

                    tiles[key] = tileSet.GetTerrainIndex(node.Value.Value);
                }

                return(tiles);
            }
        }
All Usage Examples Of OpenRA.TileSet::GetTerrainIndex