Stefan O'Rear
and 1 contributors


NetHack::FOV - NetHack compatible field of view


  use NetHack::FOV 'calculate_fov';

  my $AoA = calculate_fov($x, $y, \&transparent);


This package implements field of view (the determination, for every square on the map simultaneously, of whether it is visible to the avatar), in a NetHack compatible way. It is expected to be primarily useful to bot writers.


NetHack::FOV defines and allows import of a single function.


STARTX and STARTY determine the location of the avatar on the integer plane used by FOV::NetHack. INCALLBACK is used to determine the map's local structure; it is passed two arguments, X and Y coordinates, and must return true iff the specified point is transparent. OUTCALLBACK is used to return the viewable map, one coordinate pair at a time as for INCALLBACK. OUTCALLBACK is optional; if you omit it, calculate_fov will return an array of arrays such that $ret[$x][$y] will be true iff ($x,$y) is visible.

Obviously, calculate_fov will hang if passed a map which has lines of sight with infinite length. Also, if the visible part of the map extends beyond the doubly non-negative quadrant, and you are using the array of arrays return method, only the part which lies within said quadrant will be returned. Due to unusual boundary conditions of the NetHack FOV algorithm, this module will misbehave if passed data outside the range of 1 to 79 inclusive in the horizontal dimension; no such restriction exists vertically.

You may be wondering why the callbacks exist at all and calculate_fov doesn't just use arrays of arrays both ways. The answer is asymptotic complexity. The algorithm used by calculate_fov takes time proportional to the number of visible tiles. If an array of arrays had to be constructed for the transparency data, any user would suffer time costs proportional to the number of total tiles.


Stefan O'Rear <>


Copyright 2008 Stefan O'Rear.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.