« blib/lib/Games/RolePlay/MapGen/Generator/OneBigRoom.pm
↑ Summary
blib/lib/Games/RolePlay/MapGen/Exporter/Text.pm »
| 1 | # vi:tw=0 syntax=perl: | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | package Games::RolePlay::MapGen::Generator::Basic; | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use common::sense; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use parent q(Games::RolePlay::MapGen::Generator::SparseAndLoops); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Games::RolePlay::MapGen::Tools qw( choice roll _group irange str_eval ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | 8 | 1; | |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | # gen_room_size {{{ | ||||||||||||||||||||||||||||||||||||
| 13 | 30 | ▶ | sub gen_room_size { | ||||||||||||||||||||||||||||||||||
|
Subroutine
gen_room_size: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 14 | 30 | my $this = shift; | |||||||||||||||||||||||||||||||||||
| 15 | 30 | my $opts = shift; | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 30 | my ($xm, $ym) = split /x/, $opts->{min_room_size}; | |||||||||||||||||||||||||||||||||||
| 18 | 30 | my ($xM, $yM) = split /x/, $opts->{max_room_size}; | |||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | 30 | my $x = irange($xm, $xM); | |||||||||||||||||||||||||||||||||||
| 21 | 30 | my $y = irange($ym, $yM); | |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | 30 | ▶ | die "ERROR: problem generating room size from '$opts->{min_room_size} - $opts->{max_room_size}'" unless $x>0 and $y>0; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$x > 0 and $y > 0
MC/DC0%0/2
$x > 0 and $y > 0
$x > 0
$y > 0
Truth table33%1/3
A and B
A= $x > 0B= $y > 0
| |||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | 30 | return ($x, $y); | |||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||
| 27 | # }}} | ||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | # mark_things_as_pseudo_rooms {{{ | ||||||||||||||||||||||||||||||||||||
| 30 | 8 | ▶ | sub mark_things_as_pseudo_rooms { | ||||||||||||||||||||||||||||||||||
|
Subroutine
mark_things_as_pseudo_rooms: called CC=19 SCAR=29.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 31 | 8 | my $this = shift; | |||||||||||||||||||||||||||||||||||
| 32 | 8 | my $map = shift; | |||||||||||||||||||||||||||||||||||
| 33 | 8 | my $groups = shift; | |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | # This function assumes all defined {type}s are corridoors and that all {od} are un-broken. | ||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||
| 37 | 8 | for my $tile ( map(@$_, @$map) ) { | |||||||||||||||||||||||||||||||||||
| 38 | 3800 | ▶ | if( $tile->{type} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||
| 40 | # Look for those 2x2 corridor-loops starting with familiar upper left corner tiles. | ||||||||||||||||||||||||||||||||||||
| 41 | 1159 | ▶ | if( $tile->{od}{e} and $tile->{od}{s} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tile->{"od"}{"e"} and $tile->{"od"}{"s"}
MC/DC100%2/2
$tile->{"od"}{"e"} and $tile->{"od"}{"s"}
$tile->{"od"}{"e"}
$tile->{"od"}{"s"}
Truth table100%3/3
A and B
A= $tile->{"od"}{"e"}B= $tile->{"od"}{"s"}
| |||||||||||||||||||||||||||||||||||||
| 42 | 129 | my $ul = $tile; | |||||||||||||||||||||||||||||||||||
| 43 | 129 | my $ur = $tile->{nb}{e}; | |||||||||||||||||||||||||||||||||||
| 44 | 129 | my $ll = $tile->{nb}{s}; | |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | 129 | ▶ | if( $ur->{od}{s} and $ll->{od}{e} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$ur->{"od"}{"s"} and $ll->{"od"}{"e"}
MC/DC100%2/2
$ur->{"od"}{"s"} and $ll->{"od"}{"e"}
$ur->{"od"}{"s"}
$ll->{"od"}{"e"}
Truth table100%3/3
A and B
A= $ur->{"od"}{"s"}B= $ll->{"od"}{"e"}
| |||||||||||||||||||||||||||||||||||||
| 47 | 17 | my $lr = $ur->{nb}{s}; | |||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | 17 | my $group = &_group; | |||||||||||||||||||||||||||||||||||
| 50 | 17 | $group->type("pseudo"); | |||||||||||||||||||||||||||||||||||
| 51 | 17 | $group->add_rectangle([$ul->{x}, $ul->{y}], [2,2]); | |||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | 17 | for( $ul, $ur, $ll, $lr) { | |||||||||||||||||||||||||||||||||||
| 54 | # $_->{DEBUG_red_mark} = 1; | ||||||||||||||||||||||||||||||||||||
| 55 | 68 | $_->{group} = $group; | |||||||||||||||||||||||||||||||||||
| 56 | 68 | $_->{type} = $group->{type}; | |||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||
| 59 | ▶ | } elsif( (my $um = $ur)->{od}{e} and $ll->{od}{e} ) { | |||||||||||||||||||||||||||||||||||
|
Condition100%3/3
+(my $um = $ur)->{"od"}{"e"} and $ll->{"od"}{"e"}
MC/DC100%2/2
+(my $um = $ur)->{"od"}{"e"} and $ll->{"od"}{"e"}
+(my $um = $ur)->{"od"}{"e"}
$ll->{"od"}{"e"}
Truth table100%3/3
A and B
A= +(my $um = $ur)->{"od"}{"e"}B= $ll->{"od"}{"e"}
| |||||||||||||||||||||||||||||||||||||
| 60 | 8 | $ur = $um->{nb}{e}; | |||||||||||||||||||||||||||||||||||
| 61 | 8 | my $lm = $ll->{nb}{e}; | |||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||
| 63 | 8 | ▶ | if( $lm->{od}{e} and $ur->{od}{s} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$lm->{"od"}{"e"} and $ur->{"od"}{"s"}
MC/DC50%1/2
$lm->{"od"}{"e"} and $ur->{"od"}{"s"}
$lm->{"od"}{"e"}
$ur->{"od"}{"s"}
Truth table66%2/3
A and B
A= $lm->{"od"}{"e"}B= $ur->{"od"}{"s"}
| |||||||||||||||||||||||||||||||||||||
| 64 | 2 | my $lr = $lm->{nb}{e}; | |||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $group = &_group; | |||||||||||||||||||||||||||||||||||
| 67 | 2 | $group->type("pseudo"); | |||||||||||||||||||||||||||||||||||
| 68 | 2 | $group->add_rectangle([$ul->{x}, $ul->{y}], [3,2]); | |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | 2 | for( $ul, $um, $ur, | |||||||||||||||||||||||||||||||||||
| 71 | $ll, $lm, $lr ) { | ||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||
| 73 | # $_->{DEBUG_blue_mark} = 1; | ||||||||||||||||||||||||||||||||||||
| 74 | 12 | $_->{group} = $group; | |||||||||||||||||||||||||||||||||||
| 75 | 12 | $_->{type} = $group->{type}; | |||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||
| 80 | ▶ | } elsif( (my $ml = $ll)->{od}{s} and $ur->{od}{s} ) { | |||||||||||||||||||||||||||||||||||
|
Condition100%3/3
+(my $ml = $ll)->{"od"}{"s"} and $ur->{"od"}{"s"}
MC/DC100%2/2
+(my $ml = $ll)->{"od"}{"s"} and $ur->{"od"}{"s"}
+(my $ml = $ll)->{"od"}{"s"}
$ur->{"od"}{"s"}
Truth table100%3/3
A and B
A= +(my $ml = $ll)->{"od"}{"s"}B= $ur->{"od"}{"s"}
| |||||||||||||||||||||||||||||||||||||
| 81 | 12 | $ll = $ml->{nb}{s}; | |||||||||||||||||||||||||||||||||||
| 82 | 12 | my $mr = $ur->{nb}{s}; | |||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||
| 84 | 12 | ▶ | if( $ll->{od}{e} and $mr->{od}{s} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ll->{"od"}{"e"} and $mr->{"od"}{"s"}
MC/DC100%2/2
$ll->{"od"}{"e"} and $mr->{"od"}{"s"}
$ll->{"od"}{"e"}
$mr->{"od"}{"s"}
Truth table100%3/3
A and B
A= $ll->{"od"}{"e"}B= $mr->{"od"}{"s"}
| |||||||||||||||||||||||||||||||||||||
| 85 | 2 | my $lr = $ll->{nb}{e}; | |||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||
| 87 | 2 | my $group = &_group; | |||||||||||||||||||||||||||||||||||
| 88 | 2 | $group->type("pseudo"); | |||||||||||||||||||||||||||||||||||
| 89 | 2 | $group->add_rectangle([$ul->{x}, $ul->{y}], [2,3]); | |||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||
| 91 | 2 | for( $ul, $ur, | |||||||||||||||||||||||||||||||||||
| 92 | $ml, $mr, | ||||||||||||||||||||||||||||||||||||
| 93 | $ll, $lr ) { | ||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||
| 95 | # $_->{DEBUG_blue_mark} = 1; | ||||||||||||||||||||||||||||||||||||
| 96 | 12 | $_->{group} = $group; | |||||||||||||||||||||||||||||||||||
| 97 | 12 | $_->{type} = $group->{type}; | |||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | 8 | push @$groups, map($_->{group}, grep {$_->{group}} map(@$_, @$map)); | |||||||||||||||||||||||||||||||||||
| 107 | 8 | for my $g (@$groups) { | |||||||||||||||||||||||||||||||||||
| 108 | 92 | $g->{lsize} = $g->enumerate_tiles; | |||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||
| 111 | # }}} | ||||||||||||||||||||||||||||||||||||
| 112 | # drop_rooms {{{ | ||||||||||||||||||||||||||||||||||||
| 113 | 8 | ▶ | sub drop_rooms { | ||||||||||||||||||||||||||||||||||
|
Subroutine
drop_rooms: called CC=46 SCAR=38.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 114 | 8 | my $this = shift; | |||||||||||||||||||||||||||||||||||
| 115 | 8 | my $opts = shift; | |||||||||||||||||||||||||||||||||||
| 116 | 8 | my $map = shift; | |||||||||||||||||||||||||||||||||||
| 117 | 8 | my $groups = shift; | |||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||
| 119 | 8 | $opts->{y_size} = $#$map; | |||||||||||||||||||||||||||||||||||
| 120 | 8 | $opts->{x_size} = $#{ $map->[0] }; | |||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | 8 | for my $rn (1 .. str_eval( $opts->{num_rooms} )) { | |||||||||||||||||||||||||||||||||||
| 123 | 30 | my @size = $this->gen_room_size( $opts ); | |||||||||||||||||||||||||||||||||||
| 124 | 30 | ▶ | $size[0] = $opts->{x_size} if $size[0] > $opts->{x_size}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 125 | 30 | ▶ | $size[1] = $opts->{y_size} if $size[1] > $opts->{y_size}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | 30 | my @possible_locs = (); # [ $j, $i, $score ] | |||||||||||||||||||||||||||||||||||
| 128 | 30 | my $lowest_score = undef; | |||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | 30 | ▶ | $opts->{t_cb}->() if exists $opts->{t_cb}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | 30 | for my $i (0 .. $#$map - $size[1]) { | |||||||||||||||||||||||||||||||||||
| 133 | 504 | my $jend = $#{ $map->[$i] }; | |||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||
| 135 | 504 | for my $j (0 .. $jend - $size[0]) { | |||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||
| 137 | 9110 | my $score = 0; | |||||||||||||||||||||||||||||||||||
| 138 | 9110 | my $pseudo = 0; | |||||||||||||||||||||||||||||||||||
| 139 | 9110 | for my $x (0 .. $size[0]-1) { | |||||||||||||||||||||||||||||||||||
| 140 | 35076 | for my $y (0 .. $size[1]-1) { | |||||||||||||||||||||||||||||||||||
| 141 | 155151 | my $tile = $map->[$i+$y][$j+$x]; | |||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||
| 143 | 155151 | ▶ | if( exists $tile->{type} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 144 | 55239 | ▶ | goto LONGJUMP_PAST_SCORING if $tile->{type} eq "room"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||
| 146 | 53481 | ▶ | if( $tile->{type} eq "corridor" ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 147 | 51275 | $score += 1.07; | |||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||
| 149 | } elsif( $tile->{type} eq "pseudo" ) { | ||||||||||||||||||||||||||||||||||||
| 150 | 2206 | $tile->{group}{_rd_all} ++; | |||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||
| 152 | 2206 | $pseudo = 1; | |||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||
| 158 | 7352 | ▶ | if( $pseudo ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 159 | 800 | for my $g (grep { $_->{type} eq "pseudo" } @$groups) { | |||||||||||||||||||||||||||||||||||
| 160 | 14658 | ▶ | if( exists $g->{_rd_all} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | 822 | ▶ | if( $g->{_rd_all} == $g->{lsize} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 163 | 268 | ▶ | $score += ( $g->{lsize} == 6 ? 1.01 : 1.03 ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||
| 165 | ▶ | } elsif( $g->{lsize} == 6 and $g->{_rd_all} == 4 ) { | |||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$g->{"lsize"} == 6 and $g->{"_rd_all"} == 4
MC/DC100%2/2
$g->{"lsize"} == 6 and $g->{"_rd_all"} == 4
$g->{"lsize"} == 6
$g->{"_rd_all"} == 4
Truth table100%3/3
A and B
A= $g->{"lsize"} == 6B= $g->{"_rd_all"} == 4
| |||||||||||||||||||||||||||||||||||||
| 166 | 33 | $score += 1.05; | |||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||
| 168 | } else { | ||||||||||||||||||||||||||||||||||||
| 169 | 521 | $score += 1.07 * 4; | |||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||
| 173 | 822 | delete $g->{_rd_all}; | |||||||||||||||||||||||||||||||||||
| 174 | 822 | $pseudo = 0; | |||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||
| 179 | 7352 | ▶ | if( $score > 0 ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 180 | 6507 | ▶ | if( not defined $lowest_score or $score < $lowest_score ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $lowest_score or $score < $lowest_score
MC/DC100%2/2
not defined $lowest_score or $score < $lowest_score
not defined $lowest_score
$score < $lowest_score
Truth table100%3/3
not(A) or B
A= not defined $lowest_scoreB= $score < $lowest_score
| |||||||||||||||||||||||||||||||||||||
| 181 | 137 | $lowest_score = $score; | |||||||||||||||||||||||||||||||||||
| 182 | 137 | @possible_locs = grep { $_->[2] <= $lowest_score } @possible_locs; | |||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||
| 185 | 6507 | ▶ | push @possible_locs, [ $j, $i, $score ] if $score <= $lowest_score; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||
| 188 | LONGJUMP_PAST_SCORING: | ||||||||||||||||||||||||||||||||||||
| 189 | # This is a way of short-cutting much looping when we're not | ||||||||||||||||||||||||||||||||||||
| 190 | # going to be putting the room there anyway. | ||||||||||||||||||||||||||||||||||||
| 191 | 9110 | } | |||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||
| 194 | 30 | ▶ | if( my $loc = choice( @possible_locs ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 195 | 30 | my @corridors = (); | |||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | 30 | pop @$loc; # ditch the score. | |||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||
| 199 | 30 | my $group = &_group; | |||||||||||||||||||||||||||||||||||
| 200 | 30 | $group->name( "Room #$rn" ); | |||||||||||||||||||||||||||||||||||
| 201 | 30 | $group->type( "room" ); | |||||||||||||||||||||||||||||||||||
| 202 | 30 | $group->add_rectangle( [@$loc], [@size] ); | |||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||
| 204 | 30 | my @tiles = $group->enumerate_tiles; | |||||||||||||||||||||||||||||||||||
| 205 | 30 | my ($xmin, $ymin, $xmax, $ymax) = $group->enumerate_extents; | |||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||
| 207 | 30 | for my $tl ( @tiles ) { | |||||||||||||||||||||||||||||||||||
| 208 | 630 | my ($x,$y) = @$tl; | |||||||||||||||||||||||||||||||||||
| 209 | 630 | my $tile = $map->[ $y ][ $x ]; | |||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||
| 211 | 630 | ▶ | if( exists $tile->{type} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 212 | 106 | ▶ | if( $tile->{type} eq "corridor" or $tile->{type} eq "pseudo" ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tile->{"type"} eq "corridor" or $tile->{"type"} eq "pseudo"
MC/DC0%0/2
$tile->{"type"} eq "corridor" or $tile->{"type"} eq "pseudo"
$tile->{"type"} eq "corridor"
$tile->{"type"} eq "pseudo"
Truth table66%2/3
A or B
A= $tile->{"type"} eq "corridor"B= $tile->{"type"} eq "pseudo"
| |||||||||||||||||||||||||||||||||||||
| 213 | 106 | ▶ | push @corridors, [ w => $tile ] if $x == $xmin and $tile->{od}{w}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$x == $xmin and $tile->{"od"}{"w"}
MC/DC100%2/2
$x == $xmin and $tile->{"od"}{"w"}
$x == $xmin
$tile->{"od"}{"w"}
Truth table100%3/3
A and B
A= $x == $xminB= $tile->{"od"}{"w"}
| |||||||||||||||||||||||||||||||||||||
| 214 | 106 | ▶ | push @corridors, [ n => $tile ] if $y == $ymin and $tile->{od}{n}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$y == $ymin and $tile->{"od"}{"n"}
MC/DC100%2/2
$y == $ymin and $tile->{"od"}{"n"}
$y == $ymin
$tile->{"od"}{"n"}
Truth table100%3/3
A and B
A= $y == $yminB= $tile->{"od"}{"n"}
| |||||||||||||||||||||||||||||||||||||
| 215 | 106 | ▶ | push @corridors, [ e => $tile ] if $x == $xmax and $tile->{od}{e}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$x == $xmax and $tile->{"od"}{"e"}
MC/DC100%2/2
$x == $xmax and $tile->{"od"}{"e"}
$x == $xmax
$tile->{"od"}{"e"}
Truth table100%3/3
A and B
A= $x == $xmaxB= $tile->{"od"}{"e"}
| |||||||||||||||||||||||||||||||||||||
| 216 | 106 | ▶ | push @corridors, [ s => $tile ] if $y == $ymax and $tile->{od}{s}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$y == $ymax and $tile->{"od"}{"s"}
MC/DC100%2/2
$y == $ymax and $tile->{"od"}{"s"}
$y == $ymax
$tile->{"od"}{"s"}
Truth table100%3/3
A and B
A= $y == $ymaxB= $tile->{"od"}{"s"}
| |||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||
| 220 | 630 | $tile->{type} = "room"; | |||||||||||||||||||||||||||||||||||
| 221 | 630 | $tile->{group} = $group; | |||||||||||||||||||||||||||||||||||
| 222 | 630 | for my $dir (qw(n e s w)) { | |||||||||||||||||||||||||||||||||||
| 223 | 2520 | $tile->{od}{$dir} = 1; # open every direction... close edges below | |||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||
| 225 | 2520 | ▶ | if( my $n = $tile->{nb}{$dir} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 226 | 2474 | $n->{od}{$Games::RolePlay::MapGen::opp{$dir}} = 1; | |||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||
| 229 | # $tile->{DEBUG_green_mark} = 1; | ||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||
| 232 | 30 | for my $y ($ymin .. $ymax) { | |||||||||||||||||||||||||||||||||||
| 233 | 136 | (my $west = $map->[$y][ $xmin ])->{od}{w} = 0; | |||||||||||||||||||||||||||||||||||
| 234 | 136 | (my $east = $map->[$y][ $xmax ])->{od}{e} = 0; | |||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||
| 236 | 136 | ▶ | if( my $west_n = $west->{nb}{w} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 237 | 103 | $west_n->{od}{e} = 0; | |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||
| 240 | 136 | ▶ | if( my $east_n = $east->{nb}{e} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 241 | 136 | $east_n->{od}{w} = 0; | |||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||
| 245 | 30 | for my $x ($xmin .. $xmax) { | |||||||||||||||||||||||||||||||||||
| 246 | 136 | (my $north = $map->[ $ymin ][$x])->{od}{n} = 0; | |||||||||||||||||||||||||||||||||||
| 247 | 136 | (my $south = $map->[ $ymax ][$x])->{od}{s} = 0; | |||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||
| 249 | 136 | ▶ | if( my $north_n = $north->{nb}{n} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 250 | 123 | $north_n->{od}{s} = 0; | |||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||
| 253 | 136 | ▶ | if( my $south_n = $south->{nb}{s} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 254 | 136 | $south_n->{od}{n} = 0; | |||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||
| 258 | # By default, tiles will be open between the new rooms and the corridors they stomped | ||||||||||||||||||||||||||||||||||||
| 259 | 30 | for my $a (@corridors) { | |||||||||||||||||||||||||||||||||||
| 260 | 50 | my $t = $a->[1]; | |||||||||||||||||||||||||||||||||||
| 261 | 50 | my $n = $t->{nb}{$a->[0]}; | |||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||
| 263 | 50 | $t->{od}{$a->[0]} = $n->{od}{$Games::RolePlay::MapGen::opp{$a->[0]}} = 1; | |||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||
| 266 | 30 | push @$groups, $group; | |||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||
| 271 | # }}} | ||||||||||||||||||||||||||||||||||||
| 272 | # cleanup_pseudo_rooms {{{ | ||||||||||||||||||||||||||||||||||||
| 273 | 8 | ▶ | sub cleanup_pseudo_rooms { | ||||||||||||||||||||||||||||||||||
|
Subroutine
cleanup_pseudo_rooms: called CC=13 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 274 | 8 | my $this = shift; | |||||||||||||||||||||||||||||||||||
| 275 | 8 | my $map = shift; | |||||||||||||||||||||||||||||||||||
| 276 | 8 | my $groups = shift; | |||||||||||||||||||||||||||||||||||
| 277 | 8 | my @pseudo = (); | |||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||
| 279 | 8 | ▶ | @$groups = grep { my $r = 1; if( $_->{type} eq "pseudo" ) { push @pseudo, $_; $r = 0 } $r } @$groups; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||
| 281 | 8 | for my $group (@pseudo) { | |||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||
| 283 | 92 | my $intact = 1; | |||||||||||||||||||||||||||||||||||
| 284 | 92 | my @tofix = (); | |||||||||||||||||||||||||||||||||||
| 285 | 92 | for my $tl ($group->enumerate_tiles) { | |||||||||||||||||||||||||||||||||||
| 286 | 416 | my $tile = $map->[$tl->[1]][$tl->[0]]; | |||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||
| 288 | # $tile->{DEBUG_red_mark} = 1; | ||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||
| 290 | 416 | ▶ | if( $tile->{type} eq "pseudo" ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 291 | 40 | $tile->{type} = "corridor"; | |||||||||||||||||||||||||||||||||||
| 292 | 40 | push @tofix, $tile; | |||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||
| 294 | } else { | ||||||||||||||||||||||||||||||||||||
| 295 | 376 | $intact = 0; | |||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||
| 299 | 92 | my ($xmin, $ymin, $xmax, $ymax) = $group->enumerate_extents; | |||||||||||||||||||||||||||||||||||
| 300 | 92 | ▶ | if( $intact ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 301 | 10 | for my $tile (@tofix) { | |||||||||||||||||||||||||||||||||||
| 302 | 40 | ▶ | $tile->{od}{n} = 1 if $tile->{y} > $ymin; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 303 | 40 | ▶ | $tile->{od}{s} = 1 if $tile->{y} < $ymax; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 304 | 40 | ▶ | $tile->{od}{e} = 1 if $tile->{x} < $xmax; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 305 | 40 | ▶ | $tile->{od}{w} = 1 if $tile->{x} > $xmin; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||
| 310 | 8 | for my $tile (grep {$_->{group}} map {@$_} @$map) { | |||||||||||||||||||||||||||||||||||
| 311 | delete $tile->{group} | ||||||||||||||||||||||||||||||||||||
| 312 | 670 | ▶ | if $tile->{group}{type} eq "pseudo"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||
| 315 | # }}} | ||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||
| 317 | # genmap {{{ | ||||||||||||||||||||||||||||||||||||
| 318 | 8 | ▶ | sub genmap { | ||||||||||||||||||||||||||||||||||
|
Subroutine
genmap: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 319 | 8 | my $this = shift; | |||||||||||||||||||||||||||||||||||
| 320 | 8 | my $opts = $this->gen_opts(%{ $_[0] }); | |||||||||||||||||||||||||||||||||||
| 321 | 8 | my ($map, $groups) = $this->SUPER::genmap(@_); | |||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||
| 323 | # There are a few types of random corridors that look enough like rooms | ||||||||||||||||||||||||||||||||||||
| 324 | # That I didn't think they should count against the room drop score below. | ||||||||||||||||||||||||||||||||||||
| 325 | # In fact, we'd really rather cover them up if possible. | ||||||||||||||||||||||||||||||||||||
| 326 | 8 | $this->mark_things_as_pseudo_rooms( $map, $groups ); | |||||||||||||||||||||||||||||||||||
| 327 | 8 | $this->drop_rooms( $opts, $map, $groups ); | |||||||||||||||||||||||||||||||||||
| 328 | 8 | $this->cleanup_pseudo_rooms( $map, $groups ); | |||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||
| 330 | 8 | return ($map, $groups); | |||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||
| 332 | # }}} | ||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||
| 334 | __END__ | ||||||||||||||||||||||||||||||||||||