blib/lib/Games/RolePlay/MapGen/GeneratorPlugin/BasicDoors.pm

filter: Statementstmt 100% 94 / 94 Branchbran 86.9% 40 / 46 Conditioncond 68.9% 20 / 29 MC/DCmcdc 52.6% 10 / 19 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 86.7% 170 / 196 CC 42 SCAR 30.2
CC
42
Cov
91%
doorgen
23.0
_find_span
21.5
BEGIN
1.0
CRAP 20.5
« blib/lib/Games/RolePlay/MapGen/Exporter/Text.pm ↑ Summary blib/lib/Games/RolePlay/MapGen.pm »
1 # vi:tw=0 syntax=perl:
2  
3 package Games::RolePlay::MapGen::GeneratorPlugin::BasicDoors;
4  
5 5 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Games::RolePlay::MapGen::Tools qw( roll _door choice );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 $Games::RolePlay::MapGen::known_opts{ "open_room_corridor_door_percent" } = { door => 95, secret => 2, stuck => 25, locked => 50 };
10 5 $Games::RolePlay::MapGen::known_opts{ "closed_room_corridor_door_percent" } = { door => 5, secret => 95, stuck => 10, locked => 30 };
11 5 $Games::RolePlay::MapGen::known_opts{ "open_corridor_corridor_door_percent" } = { door => 1, secret => 10, stuck => 25, locked => 50 };
12 5 $Games::RolePlay::MapGen::known_opts{ "closed_corridor_corridor_door_percent" } = { door => 1, secret => 95, stuck => 10, locked => 30 };
13 5 $Games::RolePlay::MapGen::known_opts{ "max_span" } = 50;
14  
15 5 1;
16  
17 # new {{{
18 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
19 5 my $class = shift;
20 5 my $this = [qw(door)]; # you have to be the types of things you hook
21  
22 5 return bless $this, $class;
23 }
24 # }}}
25 # doorgen {{{
26 5 ▶sub doorgen {
Subroutine doorgen: called CC=23 SCAR=31.4
Pod undocumented
27 5 my $this = shift;
28 5 my $opts = shift;
29 5 my $map = shift;
30 5 my $groups = shift;
31  
32 5 my $minor_dirs = {
33 n => [qw(e w)],
34 s => [qw(e w)],
35  
36 e => [qw(n s)],
37 w => [qw(n s)],
38 };
39  
40 5 ▶ my $max_span = $opts->{max_span} / ($opts->{tile_size} || 1);
Condition50%1/2
$opts->{'tile_size'} || 1
l!l
50
MC/DC0%0/1
$opts->{'tile_size'} || 1
$opts->{'tile_size'}
Truth table50%1/2
A
A= $opts->{'tile_size'}
Aresult
11
00
41 5 ▶ $max_span = 1 unless $max_span > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $max_span > 0 0 5 5
42  
43 # warn "max_span=$max_span";
44  
45 5 for my $i ( 0 .. $#$map ) {
46 125 my $jend = $#{ $map->[$i] };
47  
48 125 for my $j ( 0 .. $jend ) {
49 3275 my $t = $map->[$i][$j];
50  
51 3275 ▶ if( $t->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"type"}) 1595 1680 3275
52 1595 for my $dir (qw(n e s w)) { my $opp = $Games::RolePlay::MapGen::opp{$dir};
53 6380 my $n = $t->{nb}{$dir};
54 6380 ▶ next unless $n and $n->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $n and $n->{"type"} 1235 5145 6380
Condition100%3/3
$n and $n->{"type"}
!ll&&!rl&&r
12811075145
MC/DC100%2/2
$n and $n->{"type"}
$n $n->{"type"}
Truth table100%3/3
A and B
A= $nB= $n->{"type"}
ABresult
0X0
100
111
55  
56 5145 ▶ unless( $t->{_bchkt}{$dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t->{"_bchkt"}{$dir}) 4946 199 5145
57 4946 my ($ttype, $ntype) = ($t->{type}, $n->{type});
58  
59 4946 ▶ if( $ttype eq "room" and $ntype eq "room" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ttype eq "room" and $ntype eq "room") 2975 1971 4946
Condition100%3/3
$ttype eq "room" and $ntype eq "room"
!ll&&!rl&&r
1886852975
MC/DC100%2/2
$ttype eq "room" and $ntype eq "room"
$ttype eq "room" $ntype eq "room"
Truth table100%3/3
A and B
A= $ttype eq "room"B= $ntype eq "room"
ABresult
0X0
100
111
60 2975 ▶ if( $t->{group}{name} eq $n->{group}{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{'group'}{'name'} eq $n->{'group'}{'name'}) { } 2911 64 2975
61 2911 next;
62  
63 } else {
64 64 $ntype = "corridor";
65 }
66 }
67  
68 2035 ▶ my $tkey = ( $t->{od}{$dir} ? "open" : "closed" );
Branch: 1 branch
BranchTrueFalseTotal
$t->{'od'}{$dir} ? : 1688 347 2035
69 2035 $tkey .= "_" . join("_", reverse sort( $ttype, $ntype ));
70 2035 $tkey .= "_door_percent";
71  
72 2035 my $chances = $opts->{$tkey};
73 2035 ▶ die "chances error for $tkey" unless defined $chances;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chances 0 2035 2035
74  
75 2035 ▶ if( (my $r = roll(1, 10000)) <= (my $c = $chances->{door}*100) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $r = roll(1, 10000)) <= (my $c = $chances->{"door"} * 100)) 67 1968 2035
76 67 my ($span, $nspn) = $this->_find_span($dir=>$opp, $t=>$n);
77  
78 67 $_->{_bchkt}{$dir} = 1 for @$span;
79 67 $_->{_bchkt}{$opp} = 1 for @$nspn;
80  
81 67 ▶ next unless @$span <= $max_span;
Branch: 1 branch
BranchTrueFalseTotal
unless @$span <= $max_span 4 63 67
82  
83 63 $_->{od}{$dir} = 0 for @$span;
84 63 $_->{od}{$opp} = 0 for @$nspn;
85  
86 63 $t = choice(@$span);
87 63 $n = $t->{nb}{$dir};
88  
89 63 my $d1 = sprintf("%40s: (%5d, %5d)", $tkey, $r, $c);
90 63 my $d2 = sprintf("(%2d, %2d, $dir)", $j, $i);
91  
92 $t->{od}{$dir} = $n->{od}{$opp} = &_door(
93  
94 189 ▶ (map {$_ => ((roll(1, 10000) <= $chances->{$_}*100) ? 1:0) } qw(locked stuck secret)),
Branch: 1 branch
BranchTrueFalseTotal
roll(1, 10000) <= $chances->{$_} * 100 ? : 55 134 189
95  
96 open_dir => {
97 major => &choice( $dir, $opp ),
98 63 minor => &choice( @{$minor_dirs->{$dir}} ),
99 },
100 );
101 }
102  
103 # $t->{_bchkt}{$dir} = 1; # handled above in the span now
104 }
105 }
106 }
107 }
108 }
109  
110 5 delete $_->{_bchkt} for map(@$_, @$map); # btw, bchkt stands for: basic doors checked tile [direction]
111 }
112 # }}}
113 # _find_span {{{
114 67 ▶sub _find_span {
Subroutine _find_span: called CC=20 SCAR=30.7
115 67 my $this = shift;
116 67 my $dir = shift;
117 67 my $opp = shift;
118 67 my $t = shift;
119 67 my $n = shift;
120 67 my $span = [$t];
121 67 my $nspn = [$n];
122  
123 67 ▶ warn "WARNING: something is fishy $t->{x},$t->{y}:$dir nb!> $n->{x},$n->{y}:$opp" unless $t->{nb}{$dir} == $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $t->{"nb"}{$dir} == $n 0 67 67
124 67 ▶ warn "WARNING: something is fishy $t->{x},$t->{y}:$dir <!nb $n->{x},$n->{y}:$opp" unless $n->{nb}{$opp} == $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $n->{"nb"}{$opp} == $t 0 67 67
125  
126 67 my ($ud, $pd) = (qw(n s));
127 67 ▶ ($ud, $pd) = (qw(e w)) if $dir eq "n" or $dir eq "s";
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "n" or $dir eq "s" 31 36 67
Condition100%3/3
$dir eq "n" or $dir eq "s"
l!l&&r!l&&!r
92236
MC/DC100%2/2
$dir eq "n" or $dir eq "s"
$dir eq "n" $dir eq "s"
Truth table100%3/3
A or B
A= $dir eq "n"B= $dir eq "s"
ABresult
1X1
011
000
128  
129 67 my $ls = 0;
130 67 ▶ while( $ls != int @$span ) { $ls = int @$span;
Branch: 1 branch
BranchTrueFalseTotal
if ($ls != int @$span) 148 67 215
131 148 $t = $span->[0];
132 148 ▶ $n = $nspn->[0]; warn "WARNING: something is fishy" unless $n->{nb}{$opp} == $t and $t->{nb}{$dir} == $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n 0 148 148
Condition33%1/3
$n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n
!ll&&!rl&&r
00148
MC/DC0%0/2
$n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n
$n->{"nb"}{$opp} == $t $t->{"nb"}{$dir} == $n
Truth table33%1/3
A and B
A= $n->{"nb"}{$opp} == $tB= $t->{"nb"}{$dir} == $n
ABresult
0X0
100
111
133 148 ▶ if( $t->{od}{$ud} == 1 and (my $c = $t->{nb}{$ud}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"od"}{$ud} == 1 and my $c = $t->{"nb"}{$ud}) 75 73 148
Condition66%2/3
$t->{"od"}{$ud} == 1 and my $c = $t->{"nb"}{$ud}
!ll&&!rl&&r
73075
MC/DC50%1/2
$t->{"od"}{$ud} == 1 and my $c = $t->{"nb"}{$ud}
$t->{"od"}{$ud} == 1 my $c = $t->{"nb"}{$ud}
Truth table66%2/3
A and B
A= $t->{"od"}{$ud} == 1B= my $c = $t->{"nb"}{$ud}
ABresult
0X0
100
111
134 75 ▶ if( $n->{od}{$ud} == 1 and (my $d = $n->{nb}{$ud}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"od"}{$ud} == 1 and my $d = $n->{"nb"}{$ud}) 64 11 75
Condition66%2/3
$n->{"od"}{$ud} == 1 and my $d = $n->{"nb"}{$ud}
!ll&&!rl&&r
11064
MC/DC50%1/2
$n->{"od"}{$ud} == 1 and my $d = $n->{"nb"}{$ud}
$n->{"od"}{$ud} == 1 my $d = $n->{"nb"}{$ud}
Truth table66%2/3
A and B
A= $n->{"od"}{$ud} == 1B= my $d = $n->{"nb"}{$ud}
ABresult
0X0
100
111
135 64 ▶ if( $c->{od}{$dir} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"od"}{$dir} == 1) 51 13 64
136 51 unshift @$span, $c;
137 51 unshift @$nspn, $d;
138 }
139 }
140 }
141  
142 148 $t = $span->[$#{ $span }];
143 148 ▶ $n = $nspn->[$#{ $nspn }]; warn "WARNING: something is fishy" unless $n->{nb}{$opp} == $t and $t->{nb}{$dir} == $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n 0 148 148
Condition33%1/3
$n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n
!ll&&!rl&&r
00148
MC/DC0%0/2
$n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n
$n->{"nb"}{$opp} == $t $t->{"nb"}{$dir} == $n
Truth table33%1/3
A and B
A= $n->{"nb"}{$opp} == $tB= $t->{"nb"}{$dir} == $n
ABresult
0X0
100
111
144 148 ▶ if( $t->{od}{$pd} == 1 and (my $c = $t->{nb}{$pd}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"od"}{$pd} == 1 and my $c = $t->{"nb"}{$pd}) 69 79 148
Condition66%2/3
$t->{"od"}{$pd} == 1 and my $c = $t->{"nb"}{$pd}
!ll&&!rl&&r
79069
MC/DC50%1/2
$t->{"od"}{$pd} == 1 and my $c = $t->{"nb"}{$pd}
$t->{"od"}{$pd} == 1 my $c = $t->{"nb"}{$pd}
Truth table66%2/3
A and B
A= $t->{"od"}{$pd} == 1B= my $c = $t->{"nb"}{$pd}
ABresult
0X0
100
111
145 69 ▶ if( $n->{od}{$pd} == 1 and (my $d = $n->{nb}{$pd}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"od"}{$pd} == 1 and my $d = $n->{"nb"}{$pd}) 58 11 69
Condition66%2/3
$n->{"od"}{$pd} == 1 and my $d = $n->{"nb"}{$pd}
!ll&&!rl&&r
11058
MC/DC50%1/2
$n->{"od"}{$pd} == 1 and my $d = $n->{"nb"}{$pd}
$n->{"od"}{$pd} == 1 my $d = $n->{"nb"}{$pd}
Truth table66%2/3
A and B
A= $n->{"od"}{$pd} == 1B= my $d = $n->{"nb"}{$pd}
ABresult
0X0
100
111
146 58 ▶ if( $c->{od}{$dir} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"od"}{$dir} == 1) 40 18 58
147 40 push @$span, $c;
148 40 push @$nspn, $d;
149 }
150 }
151 }
152 }
153  
154 67 return ($span, $nspn);
155 }
156 # }}}
157  
158 __END__
« blib/lib/Games/RolePlay/MapGen/Exporter/Text.pm ↑ Summary blib/lib/Games/RolePlay/MapGen.pm »