void MarkDiagonal() { // * N . // W . . // . . . for (int y = 0; y < Height; ++y) { // NORTH & WEST for (int x = 0; x < Width; ++x) { Int2 p = new Int2(x, y); JPSPlusMapBakerBlock block = GetBlockOrNull(p); if (block == null) { continue; } if (x == 0 || y == 0) { block.SetDistance(EDirFlags.NORTHWEST, 0); // Diagonal-Wall Distance continue; } Int2 p1 = p.Foward(EDirFlags.NORTH); Int2 p2 = p.Foward(EDirFlags.NORTHWEST); Int2 p3 = p.Foward(EDirFlags.WEST); bool p1Walkable = IsWalkable(p1); bool p3Walkable = IsWalkable(p3); if (!p1Walkable || !IsWalkable(p2) || !p3Walkable) { block.SetDistance(EDirFlags.NORTHWEST, 0); // Diagonal-Wall Distance continue; } JPSPlusMapBakerBlock prevBlock = GetBlockOrNull(p2); if (p1Walkable && p3Walkable && (prevBlock.GetDistance(EDirFlags.NORTH) > 0 || prevBlock.GetDistance(EDirFlags.WEST) > 0)) { block.SetDistance(EDirFlags.NORTHWEST, 1); // Initial Diagonal Distance continue; } int distanceFromPrev = prevBlock.GetDistance(EDirFlags.NORTHWEST); if (distanceFromPrev > 0) { block.SetDistance(EDirFlags.NORTHWEST, distanceFromPrev + 1); // Diagonal Distance } else { block.SetDistance(EDirFlags.NORTHWEST, distanceFromPrev - 1); // Diagonal-Wall Distance } } } // NORTH & WEST // . N * // . . E // . . . for (int y = 0; y < Height; ++y) { // NORTH & EAST for (int x = Width - 1; x >= 0; --x) { Int2 p = new Int2(x, y); JPSPlusMapBakerBlock block = GetBlockOrNull(p); if (block == null) { continue; } if (x == Width - 1 || y == 0) { block.SetDistance(EDirFlags.NORTHEAST, 0); // Diagonal-Wall Distance continue; } Int2 p1 = p.Foward(EDirFlags.NORTH); Int2 p2 = p.Foward(EDirFlags.NORTHEAST); Int2 p3 = p.Foward(EDirFlags.EAST); bool p1Walkable = IsWalkable(p1); bool p3Walkable = IsWalkable(p3); if (!p1Walkable || !IsWalkable(p2) || !p3Walkable) { block.SetDistance(EDirFlags.NORTHEAST, 0); // Diagonal-Wall Distance continue; } JPSPlusMapBakerBlock prevBlock = GetBlockOrNull(p2); if (p1Walkable && p3Walkable && (prevBlock.GetDistance(EDirFlags.NORTH) > 0 || prevBlock.GetDistance(EDirFlags.EAST) > 0)) { block.SetDistance(EDirFlags.NORTHEAST, 1); // Initial Diagonal Distance continue; } int distanceFromPrev = prevBlock.GetDistance(EDirFlags.NORTHEAST); if (distanceFromPrev > 0) { block.SetDistance(EDirFlags.NORTHEAST, distanceFromPrev + 1); // Diagonal Distance } else { block.SetDistance(EDirFlags.NORTHEAST, distanceFromPrev - 1); // Diagonal-Wall Distance } } } // NORTH & EAST // . . . // W . . // * S . for (int y = Height - 1; y >= 0; --y) { // SOUTH & WEST for (int x = 0; x < Width; ++x) { Int2 p = new Int2(x, y); JPSPlusMapBakerBlock block = GetBlockOrNull(p); if (block == null) { continue; } if (x == 0 || y == Height - 1) { block.SetDistance(EDirFlags.SOUTHWEST, 0); // Diagonal-Wall Distance continue; } Int2 p1 = p.Foward(EDirFlags.SOUTH); Int2 p2 = p.Foward(EDirFlags.SOUTHWEST); Int2 p3 = p.Foward(EDirFlags.WEST); bool p1Walkable = IsWalkable(p1); bool p3Walkable = IsWalkable(p3); if (!p1Walkable || !IsWalkable(p2) || !p3Walkable) { block.SetDistance(EDirFlags.SOUTHWEST, 0); // Diagonal-Wall Distance continue; } JPSPlusMapBakerBlock prevBlock = GetBlockOrNull(p2); if (p1Walkable && p3Walkable && (prevBlock.GetDistance(EDirFlags.SOUTH) > 0 || prevBlock.GetDistance(EDirFlags.WEST) > 0)) { block.SetDistance(EDirFlags.SOUTHWEST, 1); // Initial Diagonal Distance continue; } int distanceFromPrev = prevBlock.GetDistance(EDirFlags.SOUTHWEST); if (distanceFromPrev > 0) { block.SetDistance(EDirFlags.SOUTHWEST, distanceFromPrev + 1); // Diagonal Distance } else { block.SetDistance(EDirFlags.SOUTHWEST, distanceFromPrev - 1); // Diagonal-Wall Distance } } } // SOUTH & WEST // . . . // . . E // . S * for (int y = Height - 1; y >= 0; --y) { // SOUTH & EAST for (int x = Width - 1; x >= 0; --x) { Int2 p = new Int2(x, y); JPSPlusMapBakerBlock block = GetBlockOrNull(p); if (block == null) { continue; } if (x == Width - 1 || y == Height - 1) { block.SetDistance(EDirFlags.SOUTHEAST, 0); // Diagonal-Wall Distance continue; } Int2 p1 = p.Foward(EDirFlags.SOUTH); Int2 p2 = p.Foward(EDirFlags.SOUTHEAST); Int2 p3 = p.Foward(EDirFlags.EAST); bool p1Walkable = IsWalkable(p1); bool p3Walkable = IsWalkable(p3); if (!p1Walkable || !IsWalkable(p2) || !p3Walkable) { block.SetDistance(EDirFlags.SOUTHEAST, 0); // Diagonal-Wall Distance continue; } JPSPlusMapBakerBlock prevBlock = GetBlockOrNull(p2); if (p1Walkable && p3Walkable && (prevBlock.GetDistance(EDirFlags.SOUTH) > 0 || prevBlock.GetDistance(EDirFlags.EAST) > 0)) { block.SetDistance(EDirFlags.SOUTHEAST, 1); // Initial Diagonal Distance continue; } int distanceFromPrev = prevBlock.GetDistance(EDirFlags.SOUTHEAST); if (distanceFromPrev > 0) { block.SetDistance(EDirFlags.SOUTHEAST, distanceFromPrev + 1); // Diagonal Distance } else { block.SetDistance(EDirFlags.SOUTHEAST, distanceFromPrev - 1); // Diagonal-Wall Distance } } } // SOUTH & EAST }
private void Indicate(bool mIsStraightOn, bool mIsDiagonalOn, bool mIsWallOn) { for (int i = 0b10000000; i > 0; i >>= 1) { EDirFlags dir = (EDirFlags)i; int dist = mBakedBlock.GetDistance(dir); int index = DirFlags.ToArrayIndex(dir); if (dist > 0) { if ((dir & StraightDirs) == dir) { if (mIsStraightOn) { dirImages[index].color = InvisibleColor; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } if ((dir & DiagonalDirs) == dir) { if (mIsDiagonalOn) { dirImages[index].color = InvisibleColor; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } } else if (dist == 0) { if (mIsWallOn) { dirImages[index].color = Color.red; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } else { if ((dir & StraightDirs) == dir) { if (mIsWallOn && mIsStraightOn) { dirImages[index].color = Color.yellow; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } if ((dir & DiagonalDirs) == dir) { if (mIsWallOn && mIsDiagonalOn) { dirImages[index].color = Color.yellow; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } } } }