| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package NetHack::FOV; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = 0.01; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our @EXPORT_OK = qw(calculate_fov); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 74376 | ▶ | sub _clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 74376 | my ($self, $x, $y) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 74376 | return $self->{cbi}->($x + $self->{x}, $y + $self->{y}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 26899 | ▶ | sub _see { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_see: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 26899 | my ($self, $x, $y) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 26899 | return $self->{cbo}->($x + $self->{x}, $y + $self->{y}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6868 | ▶ | sub _Q_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Q_path: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6868 | my ($self, $x, $y) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 6868 | my ($px, $py) = (0,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6868 | my $flip = abs($x) > abs($y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 6868 | ▶ | my ($rmaj, $rmin) = $flip ? (\$px,\$py) : (\$py,\$px); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6868 | ▶ | my ($dmaj, $dmin) = $flip ? ( $x , $y ) : ( $y , $x ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 6868 | my $fmin = -abs($dmaj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 6868 | for (2 .. abs($dmaj)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 27625 | $fmin += 2*abs($dmin); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 27625 | ▶ | if ($fmin >= 0) { $fmin -= 2*abs($dmaj); $$rmin += ($dmin <=> 0); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 27625 | $$rmaj += ($dmaj <=> 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 27625 | ▶ | if (!$self->_clear($px, $py)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4095 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2773 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4377 | ▶ | sub _quadrant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quadrant: called CC=28 SCAR=33.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 4377 | my ($self, $hs, $row, $left, $right_mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4377 | my ($right, $right_edge); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4377 | ▶ | my $rail = ($hs == 1) ? 79 - $self->{x} : $self->{x}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # Why does this have to be irregular | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4377 | ▶ | while ($left <= $right_mark) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | #print "in quadrant, $rail $hs $row $left $right_mark\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6462 | $right_edge = $left; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 6462 | my $left_clear = $self->_clear($hs*$left, $row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 6462 | ▶ | while ($self->_clear($hs*$right_edge, $row) == $left_clear && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->_clear($hs * $right_edge, $row) == $left_clear and $left_clear || $right_edge <= $right_mark + 1
$left_clear or $right_edge <= $right_mark + 1
MC/DC100%3/3
$self->_clear($hs * $right_edge, $row) == $left_clear and $left_clear || $right_edge <= $right_mark + 1
$self->_clear($hs * $right_edge, $row) == $left_clear
$left_clear
$right_edge <= $right_mark + 1
Truth table100%4/4
A and B or C
A= $self->_clear($hs * $right_edge, $row) == $left_clearB= $left_clearC= $right_edge <= $right_mark + 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ($left_clear || $right_edge <= $right_mark + 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 27968 | { $right_edge++ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 6462 | $right_edge--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 6462 | ▶ | if ($left_clear) { $right_edge++; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6462 | ▶ | if ($right_edge >= $rail) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $right_edge = $rail; # Yuck | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | #print "in quadrant2, $hs $row $left $right_mark $right_edge\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 6462 | ▶ | if (!$left_clear) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2617 | ▶ | if ($right_edge > $right_mark) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1612 | ▶ | $right_edge = $self->_clear($hs*$right_mark, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $row - ($row <=> 0)) ? $right_mark + 1 : $right_mark; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2617 | ▶ | for (my $i = $left; $i <= $right_edge; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 9348 | $self->_see($hs*$i, $row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2617 | $left = $right_edge + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2617 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | #print "in quadrant3, $hs $row $left $right_mark\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3845 | ▶ | if ($left != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1557 | ▶ | for (; $left <= $right_edge; $left++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4235 | ▶ | last if $self->_Q_path($hs*$left, $row); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1557 | ▶ | if ($left >= $rail) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Double yuck | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($left == $rail) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->_see($left*$hs, $row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1557 | ▶ | if ($left >= $right_edge) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 800 | $left = $right_edge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 800 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | #print "in quadrant4, $hs $row $left $right_mark\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3045 | ▶ | if ($right_mark < $right_edge) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1064 | ▶ | for ($right = $right_mark; $right <= $right_edge; $right++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2633 | ▶ | last if !$self->_Q_path($hs*$right, $row); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1064 | --$right; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1981 | else { $right = $right_edge; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | #print "in quadrant5, $hs $row $left $right_mark\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3045 | ▶ | if ($left <= $right) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2969 | ▶ | if ($left == $right && $left == 0 && !$self->_clear($hs,$row) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$left == $right and $left == 0 and not $self->_clear($hs, $row) and $left != $rail
$left == $right and $left == 0 and not $self->_clear($hs, $row)
$left == $right and $left == 0
MC/DC75%3/4
$left == $right and $left == 0 and not $self->_clear($hs, $row) and $left != $rail
$left == $right
$left == 0
not $self->_clear($hs, $row)
$left != $rail
Truth table80%4/5
A and B and not(C) and D
A= $left == $rightB= $left == 0C= not $self->_clear($hs, $row)D= $left != $rail
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ($left != $rail)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 66 | $right = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($right > $rail) { $right = $rail } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2969 | ▶ | for (my $i = $left; $i <= $right; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 13259 | $self->_see($hs*$i,$row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2969 | $self->_quadrant($hs, $row + ($row <=> 0),$left,$right); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2969 | $left = $right + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | #print "in quadrant6, $hs $row $left $right_mark\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 352 | ▶ | sub _trace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trace: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 352 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 352 | my ($xl, $xr) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 352 | $self->_see(0,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | #for my $i (-2 .. 2) { print ($self->_clear($i,0) ? "1" : "0"); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | #print "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 352 | ▶ | do { $self->_see(--$xl,0) } while $self->_clear($xl,0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 352 | ▶ | do { $self->_see(++$xr,0) } while $self->_clear($xr,0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # Triple yuck | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 352 | ▶ | $xr-- if $xr + $self->{x} == 80; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 352 | ▶ | $xl++ if $xl + $self->{x} < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | #print "$xl $xr\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 352 | $self->_quadrant(-1,-1,0,-$xl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 352 | $self->_quadrant(+1,-1,0,$xr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 352 | $self->_quadrant(-1,+1,0,-$xl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 352 | $self->_quadrant(+1,+1,0,$xr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # not handled: swimming, phasing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # possibly buggy: everything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 352 | ▶ | sub calculate_fov { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
calculate_fov: called CC=2 SCAR=7.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 352 | my ($startx, $starty, $cb, $cbo) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 352 | my @visible; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 352 | my $self = bless { x => $startx, y => $starty, cbi => $cb, cbo => $cbo }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 26899 | ▶ | $self->{cbo} ||= sub { my ($x, $y) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 352 | ▶ | $visible[$x][$y] = 1 unless $x < 0 || $y < 0; }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->{"cbo"} ||= sub {
my($x, $y) = @_;
$visible[$x][$y] = 1 unless $x < 0 or $y < 0;
}
$x < 0 or $y < 0
MC/DC0%0/2
$self->{"cbo"} ||= sub {
my($x, $y) = @_;
$visible[$x][$y] = 1 unless $x < 0 or $y < 0;
}
$self->{"cbo"}
sub {
my($x, $y) = @_;
$visible[$x][$y] = 1 unless $x < 0 or $y < 0;
}
MC/DC0%0/2
$x < 0 or $y < 0
$x < 0
$y < 0
Truth table33%1/3
A ||= B
A= $self->{"cbo"}B= sub {
my($x, $y) = @_;
$visible[$x][$y] = 1 unless $x < 0 or $y < 0;
}
Truth table33%1/3
A or B
A= $x < 0B= $y < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 352 | $self->_trace(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 352 | return \@visible; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | NetHack::FOV - NetHack compatible field of view | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | use NetHack::FOV 'calculate_fov'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | my $AoA = calculate_fov($x, $y, \&transparent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | This package implements field of view (the determination, for every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | square on the map simultaneously, of whether it is visible to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | avatar), in a NetHack compatible way. It is expected to be primarily | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | useful to bot writers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | =head1 FUNCTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | NetHack::FOV defines and allows import of a single function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | =item B<calculate_fov STARTX, STARTY, INCALLBACK, [OUTCALLBACK]> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | STARTX and STARTY determine the location of the avatar on the integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | plane used by FOV::NetHack. INCALLBACK is used to determine the map's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | local structure; it is passed two arguments, X and Y coordinates, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | must return true iff the specified point is transparent. OUTCALLBACK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | is used to return the viewable map, one coordinate pair at a time as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | for INCALLBACK. OUTCALLBACK is optional; if you omit it, calculate_fov | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | will return an array of arrays such that $ret[$x][$y] will be true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | iff ($x,$y) is visible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | Obviously, calculate_fov will hang if passed a map which has lines of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | sight with infinite length. Also, if the visible part of the map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | extends beyond the doubly non-negative quadrant, and you are using | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | the array of arrays return method, only the part which lies within | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | said quadrant will be returned. Due to unusual boundary conditions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | of the NetHack FOV algorithm, this module will misbehave if passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | data outside the range of 1 to 79 inclusive in the horizontal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | dimension; no such restriction exists vertically. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | You may be wondering why the callbacks exist at all and calculate_fov | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | doesn't just use arrays of arrays both ways. The answer is asymptotic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | complexity. The algorithm used by calculate_fov takes time proportional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | to the number of I<visible> tiles. If an array of arrays had to be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | constructed for the transparency data, any user would suffer time costs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | proportional to the number of I<total> tiles. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | Stefan O'Rear <stefanor@cox.net> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | Copyright 2008 Stefan O'Rear. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||