| 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
MC/DC0%0/1
$opts->{'tile_size'} || 1
$opts->{'tile_size'}
Truth table50%1/2
A
A= $opts->{'tile_size'}
| |||||||||||||||||||||||||||||
| 41 | 5 | ▶ | $max_span = 1 unless $max_span > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$n and $n->{"type"}
MC/DC100%2/2
$n and $n->{"type"}
$n
$n->{"type"}
Truth table100%3/3
A and B
A= $nB= $n->{"type"}
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5145 | ▶ | unless( $t->{_bchkt}{$dir} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 4946 | my ($ttype, $ntype) = ($t->{type}, $n->{type}); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 4946 | ▶ | if( $ttype eq "room" and $ntype eq "room" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ttype eq "room" and $ntype eq "room"
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"
| |||||||||||||||||||||||||||||
| 60 | 2975 | ▶ | if( $t->{group}{name} eq $n->{group}{name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2035 | ▶ | if( (my $r = roll(1, 10000)) <= (my $c = $chances->{door}*100) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$dir eq "n" or $dir eq "s"
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"
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 67 | my $ls = 0; | |||||||||||||||||||||||||||
| 130 | 67 | ▶ | while( $ls != int @$span ) { $ls = int @$span; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n
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
| |||||||||||||||||||||||||||||
| 133 | 148 | ▶ | if( $t->{od}{$ud} == 1 and (my $c = $t->{nb}{$ud}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t->{"od"}{$ud} == 1 and my $c = $t->{"nb"}{$ud}
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}
| |||||||||||||||||||||||||||||
| 134 | 75 | ▶ | if( $n->{od}{$ud} == 1 and (my $d = $n->{nb}{$ud}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$n->{"od"}{$ud} == 1 and my $d = $n->{"nb"}{$ud}
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}
| |||||||||||||||||||||||||||||
| 135 | 64 | ▶ | if( $c->{od}{$dir} == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$n->{"nb"}{$opp} == $t and $t->{"nb"}{$dir} == $n
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
| |||||||||||||||||||||||||||||
| 144 | 148 | ▶ | if( $t->{od}{$pd} == 1 and (my $c = $t->{nb}{$pd}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t->{"od"}{$pd} == 1 and my $c = $t->{"nb"}{$pd}
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}
| |||||||||||||||||||||||||||||
| 145 | 69 | ▶ | if( $n->{od}{$pd} == 1 and (my $d = $n->{nb}{$pd}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$n->{"od"}{$pd} == 1 and my $d = $n->{"nb"}{$pd}
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}
| |||||||||||||||||||||||||||||
| 146 | 58 | ▶ | if( $c->{od}{$dir} == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||