예제 #1
0
        public void Paint(HexXY p, int brushSize, bool shouldPaintOnEmpty, TerrainCellType brushCellType)
        {
            var changedBlocks = new HashSet <WorldBlock>();

            for (int x = -(brushSize - 1); x <= brushSize - 1; x++)
            {
                for (int y = -(brushSize - 1); y <= brushSize - 1; y++)
                {
                    HexXY d = new HexXY(x, y);
                    if (HexXY.Dist(d) > brushSize - 1)
                    {
                        continue;
                    }
                    HexXY pd = p + d;

                    var cellType = Level.S.GetCellType(pd);

                    if (cellType != brushCellType &&
                        (shouldPaintOnEmpty || cellType != TerrainCellType.Empty || brushCellType == TerrainCellType.Empty))
                    {
                        PaintOneCell(pd, brushCellType, changedBlocks, cellType, true);
                    }
                }
            }

            RecreateTerrain(changedBlocks);
        }
예제 #2
0
파일: Cell.cs 프로젝트: CSJedi/PathFinder
 public Cell(int x, int y, TerrainCellType terrainCellType = TerrainCellType.None, ObjectCellType objectCellType = null, int resourcesValue = 0)
 {
     X = x;
     Y = y;
     TerrainCellType = terrainCellType;
     CellType        = objectCellType;
     _resourcesValue = resourcesValue;
 }
예제 #3
0
파일: Level.cs 프로젝트: Dzugaru/hexes
        public WorldBlock SetCellType(HexXY p, TerrainCellType type)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, true, out localPos);

            block.SetCellType(localPos, type);
            return(block);
        }
예제 #4
0
        public void SetCellType(HexXY pos, TerrainCellType type)
        {
            //Can't destroy tile under object
            if (entityMap[pos.x, pos.y].Count > 0 && type == TerrainCellType.Empty)
            {
                return;
            }

            var oldCellType = cellTypes[pos.x, pos.y];

            --cellTypeCounts[(int)oldCellType];
            cellTypes[pos.x, pos.y] = type;
            ++cellTypeCounts[(int)type];
        }
예제 #5
0
        public static string ToDataForPrint(this TerrainCellType cellType)
        {
            switch (cellType)
            {
            case TerrainCellType.Road:
                return("1");

            case TerrainCellType.Block:
                return("#");

            case TerrainCellType.Grass:
                return("2");

            case TerrainCellType.Marsh:
                return("3");

            case TerrainCellType.Snow:
                return("4");
            }
            return(string.Empty);
        }
예제 #6
0
        //1.729922279792746 SNOW
        //1.3316062176165804 GRASS
        //1.7292746113989637 MARSH
        //1 - ROAD
        public static double GetTerrainCellTypeWeight(this TerrainCellType terrainCellType)
        {
            switch (terrainCellType)
            {
            case TerrainCellType.Road:
                return(1f);

            case TerrainCellType.Grass:
                return(1.3316062176165804f);

            case TerrainCellType.Snow:
                return(1.729922279792746f);

            case TerrainCellType.Marsh:
                return(1.7292746113989637f);

            case TerrainCellType.Block:
                return(Single.MaxValue);
            }
            return(-1);
        }
예제 #7
0
        void PaintOneCell(HexXY p, TerrainCellType type, HashSet <WorldBlock> changedBlocks, TerrainCellType oldCellType, bool writeChanges)
        {
            var changedWb = Level.S.SetCellType(p, type);

            if (Level.S.GetCellType(p) != type)
            {
                return;                                 //Set failure
            }
            if (writeChanges)
            {
                changes.Push(new CellChange()
                {
                    oldCellType = oldCellType, newCellType = type, p = p
                });
            }

            //Changed blocks
            if (!changedBlocks.Contains(changedWb))
            {
                changedBlocks.Add(changedWb);
            }

            HexXY locp = Level.GetLocalCoords(p);

            //Other blocks possible walls fix
            if (locp.x == 0)
            {
                var nbl = Level.S.GetBlock(changedWb.position - new HexXY(1, 0));
                if (nbl != null && !changedBlocks.Contains(nbl))
                {
                    changedBlocks.Add(nbl);
                }
            }

            if (locp.y == 0)
            {
                var nbl = Level.S.GetBlock(changedWb.position - new HexXY(0, 1));
                if (nbl != null && !changedBlocks.Contains(nbl))
                {
                    changedBlocks.Add(nbl);
                }
            }

            if (locp.x == WorldBlock.sz - 1)
            {
                var nbl = Level.S.GetBlock(changedWb.position + new HexXY(1, 0));
                if (nbl != null && !changedBlocks.Contains(nbl))
                {
                    changedBlocks.Add(nbl);
                }
            }

            if (locp.y == WorldBlock.sz - 1)
            {
                var nbl = Level.S.GetBlock(changedWb.position + new HexXY(0, 1));
                if (nbl != null && !changedBlocks.Contains(nbl))
                {
                    changedBlocks.Add(nbl);
                }
            }
        }