Esempio n. 1
0
        public void updateFovMap(int level, FovMap fovMap)
        {
            TCODFov tcodLevel = new TCODFov(fovMap.Width, fovMap.Height);

            for (int j = 0; j < fovMap.Width; j++)
            {
                for (int k = 0; k < fovMap.Height; k++)
                {
                    if (fovMap.getCell(j, k) != FOVTerrain.Blocking)
                        tcodLevel.SetCell(j, k, true, false);
                    else
                        tcodLevel.SetCell(j, k, false, false);
                }
            }

            levelTCODMaps[level] = tcodLevel;
            levelTCODMapSizes[level] = new WidthHeight(fovMap.Width, fovMap.Height);
        }
Esempio n. 2
0
        public void updateFovMap(int level, FovMap fovMap)
        {
            TCODFov tcodLevel = new TCODFov(fovMap.Width, fovMap.Height);

            for (int j = 0; j < fovMap.Width; j++)
            {
                for (int k = 0; k < fovMap.Height; k++)
                {
                    if (fovMap.getCell(j, k) != FOVTerrain.Blocking)
                    {
                        tcodLevel.SetCell(j, k, true, false);
                    }
                    else
                    {
                        tcodLevel.SetCell(j, k, false, false);
                    }
                }
            }

            levelTCODMaps[level]     = tcodLevel;
            levelTCODMapSizes[level] = new WidthHeight(fovMap.Width, fovMap.Height);
        }
Esempio n. 3
0
        /// <summary>
        /// Calculate FoV
        /// </summary>
        /// <param name="coords"></param>
        /// <param name="isExploring"></param>
        /// <returns></returns>
        private HashSet <Coord> CalculateFoV(Coord coords, bool isExploring = false)
        {
            const int fovrange = 5;

            // calculate fov
            FovMap.Calculate(coords.X, coords.Y, fovrange, Radius.CIRCLE);

            if (isExploring)
            {
                // Visited tile = 2
                ExplorationMap[coords] = 2;

                // Observed reachable tiles = 1
                // Observed impassable tiles = -1
                foreach (Coord fovCoord in FovMap.CurrentFOV)
                {
                    if (ExplorationMap[fovCoord] != 0)
                    {
                        continue;
                    }

                    ExplorationMap[fovCoord] = WalkabilityMap[fovCoord] ? 1 : -1;
                }

                // Temporary cropped resistance map.
                // Use exploration map instead of actual walkability map
                // to prevent cheating.

                // Only use local part of the map to reduce memory allocation
                var xMin = coords.X - fovrange - 1;
                if (xMin < 0)
                {
                    xMin = 0;
                }
                var xMax = coords.X + fovrange + 1;
                if (xMax >= Width)
                {
                    xMax = Width - 1;
                }
                var yMin = coords.Y - fovrange - 1;
                if (yMin < 0)
                {
                    yMin = 0;
                }
                var yMax = coords.Y + fovrange + 1;
                if (yMax >= Height)
                {
                    yMax = Height - 1;
                }
                var tempResMap = new ArrayMap <bool>(xMax - xMin + 1, yMax - yMin + 1);

                for (var x = xMin; x <= xMax; x++)
                {
                    for (var y = yMin; y <= yMax; y++)
                    {
                        tempResMap[x - xMin, y - yMin] = ExplorationMap[x, y] >= 0;
                    }
                }

                var tempFOV = new FOV(tempResMap);

                // Calculate expected fov gain for each current fov tiles
                foreach (Coord fovCoord in FovMap.CurrentFOV)
                {
                    // Use translated coordinate instead because tempFOV is viewport.
                    Coord translated = fovCoord.Translate(-xMin, -yMin);

                    tempFOV.Calculate(translated, 5, Radius.CIRCLE);

                    var c = 0;
                    foreach (Coord tempFovCoord in tempFOV.CurrentFOV)
                    {
                        // Don't need to consider already observed tiles
                        if (ExplorationMap[tempFovCoord.Translate(xMin, yMin)] != 0)
                        {
                            continue;
                        }
                        c++;
                    }

                    // Store expected Number of fov gain
                    ExpectedFovNum[fovCoord.X, fovCoord.Y] = c;

                    // Tiles that don't need to visit = 2
                    if (c == 0)
                    {
                        ExplorationMap[fovCoord] = 2;
                    }
                }
            }

            return(new HashSet <Coord>(FovMap.CurrentFOV));
        }