blib/lib/Games/RolePlay/MapGen/Generator/SubMap.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 115 CC 12 SCAR 47.7
CC
12
Cov
0%
genmap
156.0
BEGIN
2.0
BEGIN
2.0
CRAP 117.5
1 # vi:tw=0 syntax=perl:
2  
3 package Games::RolePlay::MapGen::Generator::SubMap;
4  
5 use common::sense;
6 use Carp;
7 use parent q(Games::RolePlay::MapGen::Generator);
8 use Games::RolePlay::MapGen::Tools qw( _group _tile _door );
9  
10 1;
11  
12 sub genmap {
13 my $this = shift;
14 my $opts = shift;
15  
16 my $map = [];
17 my $groups = [];
18  
19 my @X = ( sort {$a<=>$b} ($opts->{upper_left}[0], $opts->{lower_right}[0]) );
20 my @Y = ( sort {$a<=>$b} ($opts->{upper_left}[1], $opts->{lower_right}[1]) );
21  
22 my $smap = $opts->{map_input}{_the_map};
23  
24 $opts->{$_} = $opts->{map_input}{$_} for qw(tile_size cell_size);
25 $opts->{x_size} = my $xs = 2+($X[1]-$X[0])+1;
26 $opts->{y_size} = my $ys = 2+($Y[1]-$Y[0])+1;
27 $opts->{bounding_box} = $xs . "x" . $ys;
28  
29 for my $x ( 0 .. $xs-1 ) { my $y = 0; $map->[ $y ][ $x ] = &_tile( x=>$x, y=>$y, type=>'fog' );
30 $y = $ys-1; $map->[ $y ][ $x ] = &_tile( x=>$x, y=>$y, type=>'fog' ); }
31  
32 for my $y ( 1 .. $ys-2 ) { my $x = 0; $map->[ $y ][ $x ] = &_tile( x=>$x, y=>$y, type=>'fog' );
33 $x = $xs-1; $map->[ $y ][ $x ] = &_tile( x=>$x, y=>$y, type=>'fog' ); }
34  
35 ## DEBUG ## # disable mistakes:
36 ## DEBUG ## tie @$_, "Games::RolePlay::MapGen::_disallow_autoviv", $_ for $map, @$map;
37  
38 for my $x1 ( $X[0] .. $X[1] ) { my $x2 = 1 + ($x1-$X[0]);
39 for my $y1 ( $Y[0] .. $Y[1] ) { my $y2 = 1 + ($y1-$Y[0]);
40 my $otile = $smap->[ $y1 ][ $x1 ];
41  
42 my $ntile = $map->[ $y2 ][ $x2 ] = &_tile( x=>$x2, y=>$y2, (exists $otile->{type} ? (type=>$otile->{type}) :()) );
43 for my $d (qw(n e s w)) {
44 my $ood = $otile->{od}{$d};
45  
46 my @ops = ($x2,$y2);
47 $ops[0] ++ if $d eq "e";
48 $ops[0] -- if $d eq "w";
49 $ops[1] ++ if $d eq "s";
50 $ops[1] -- if $d eq "n";
51  
52 ## DEBUG ## do { local $" = ","; warn "($x2,$y2):$d -> (@ops)" };
53  
54 my $opp = $Games::RolePlay::MapGen::opp{$d};
55 if( my $nt = $map->[ $ops[1] ][ $ops[0] ] ) {
56 if( ref $ood ) {
57 $nt->{od}{$opp} = $ntile->{od}{$d} = &_door(
58 map {($_ => $ood->{$_})} qw(locked stuck secret open),
59 open_dir => { map {($ood->{open_dir}{$_})} qw(major minor) },
60 );
61  
62 } elsif($ood) {
63 $nt->{od}{$opp} = $ntile->{od}{$d} = 1;
64 }
65 }
66 }
67 }}
68  
69 $map = new Games::RolePlay::MapGen::_interconnected_map( $map );
70
71 for my $row (@$map) {
72 for my $tile (@$row) {
73 next unless $tile and exists $tile->{type} and $tile->{type} eq "fog";
74 for my $d (qw(n w)) {
75 if( my $n = $tile->{nb}{$d} ) {
76 next unless $n and exists $n->{type} and $n->{type} eq "fog";
77 my $o = $Games::RolePlay::MapGen::opp{$d};
78 $n->{od}{$o} = $tile->{od}{$d} = 1;
79 }
80 }
81 }
82 }
83  
84 return ($map, $groups);
85 }
86  
87 __END__