private static void PaintFOVTest(RootConsole console, int x, int y, TCODFov fov) { fov.CalculateFOV(x, y, 3, false, FovAlgorithm.Basic); for (int i = 0; i < 5; ++i) //width { for (int j = 0; j < 5; ++j) //height { if (room[j, i] == '.') { if (fov.CheckTileFOV(i, j)) { console.PutChar(i, j, '.'); } else { console.PutChar(i, j, '~'); } } else { console.PutChar(i, j, '#'); } } } console.PutChar(x, y, '@'); console.Flush(); }
/// <summary> /// Recalculate the players FOV. Subsequent accesses to the TCODMap of the player's level will have his FOV /// Note that the maps may get hijacked by other creatures /// </summary> internal void CalculatePlayerFOV() { //Get TCOD to calculate the player's FOV Map currentMap = levels[Player.LocationLevel]; TCODFov tcodFOV = levelTCODMaps[Player.LocationLevel]; tcodFOV.CalculateFOV(Player.LocationMap.x, Player.LocationMap.y, Player.SightRadius); //Set the FOV flags on the map //Process the whole level, which effectively resets out-of-FOV areas for (int i = 0; i < currentMap.width; i++) { for (int j = 0; j < currentMap.height; j++) { MapSquare thisSquare = currentMap.mapSquares[i, j]; thisSquare.InPlayerFOV = tcodFOV.CheckTileFOV(i, j); //Set 'has ever been seen flag' if appropriate if (thisSquare.InPlayerFOV == true) { thisSquare.SeenByPlayer = true; } } } }
/// <summary> /// Calculates the FOV for a creature /// </summary> /// <param name="creature"></param> public TCODFov CalculateCreatureFOV(Creature creature) { Map currentMap = levels[creature.LocationLevel]; TCODFov tcodFOV = levelTCODMaps[creature.LocationLevel]; //Update FOV tcodFOV.CalculateFOV(creature.LocationMap.x, creature.LocationMap.y, creature.SightRadius); return(tcodFOV); }
/// <summary> /// Displays the creature FOV on the map. Note that this clobbers the FOV map /// </summary> /// <param name="creature"></param> public void ShowCreatureFOVOnMap(Creature creature) { //Only do this if the creature is on a visible level if (creature.LocationLevel != Player.LocationLevel) { return; } Map currentMap = levels[creature.LocationLevel]; TCODFov tcodFOV = levelTCODMaps[creature.LocationLevel]; //Calculate FOV tcodFOV.CalculateFOV(creature.LocationMap.x, creature.LocationMap.y, creature.SightRadius); //Only check sightRadius around the creature int xl = creature.LocationMap.x - creature.SightRadius; int xr = creature.LocationMap.x + creature.SightRadius; int yt = creature.LocationMap.y - creature.SightRadius; int yb = creature.LocationMap.y + creature.SightRadius; //If sight is infinite, check all the map if (creature.SightRadius == 0) { xl = 0; xr = currentMap.width; yt = 0; yb = currentMap.height; } if (xl < 0) { xl = 0; } if (xr >= currentMap.width) { xr = currentMap.width - 1; } if (yt < 0) { yt = 0; } if (yb >= currentMap.height) { yb = currentMap.height - 1; } for (int i = xl; i <= xr; i++) { for (int j = yt; j <= yb; j++) { MapSquare thisSquare = currentMap.mapSquares[i, j]; bool inFOV = tcodFOV.CheckTileFOV(i, j); if (inFOV) { thisSquare.InMonsterFOV = true; } } } }