« blib/lib/Games/RolePlay/MapGen/Generator/SparseAndLoops.pm
↑ Summary
blib/lib/Games/RolePlay/MapGen/Generator.pm »
| 1 | # vi:tw=0 syntax=perl: | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Games::RolePlay::MapGen::GeneratorPlugin::FiveSplit; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use common::sense; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Games::RolePlay::MapGen::Tools qw( roll choice _group ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | 1; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # new {{{ | ||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 2 | my $this = [qw(pre)]; # general finishing filter that happens BEFORE doors, treasures, and the like | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | return bless $this, $class; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | # }}} | ||||||||||||||||||||||||||||
| 19 | # pre {{{ | ||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub pre { | ||||||||||||||||||||||||||
|
Subroutine
pre: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 2 | my ($this, $opts, $map, $groups) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | my $mults = 0; | |||||||||||||||||||||||||||
| 24 | 2 | my $ft = int $opts->{tile_size}; | |||||||||||||||||||||||||||
| 25 | 2 | $mults = $ft / 5; | |||||||||||||||||||||||||||
| 26 | 2 | ▶ | die "$opts->{tile_size} <-- tile size must be evenly divisible by 5 in order to FiveSplit" if $mults =~ m/\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | $opts->{tile_size} = 5; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | $opts->{bounding_box} = join("x", map { $_*$mults } split /x/, $opts->{bounding_box}); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | $this->split_map($mults => $map) if $mults > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | for my $g (@$groups) { | |||||||||||||||||||||||||||
| 35 | 7 | for my $i (0 .. $#{ $g->{loc} }) { | |||||||||||||||||||||||||||
| 36 | 7 | my $l = $g->{loc}[ $i ]; | |||||||||||||||||||||||||||
| 37 | 7 | my $s = $g->{size}[ $i ]; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 7 | $l->[0] *= $mults; $l->[1] *= $mults; | |||||||||||||||||||||||||||
| 40 | 7 | $s->[0] *= $mults; $s->[1] *= $mults; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 7 | $g->add_rectangle; # recalculates {loc_size} for us | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | # }}} | ||||||||||||||||||||||||||||
| 47 | # split_map {{{ | ||||||||||||||||||||||||||||
| 48 | 2 | ▶ | sub split_map { | ||||||||||||||||||||||||||
|
Subroutine
split_map: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 2 | my $this = shift; | |||||||||||||||||||||||||||
| 50 | 2 | my $mults = shift; $mults --; # we use this as a counter of the number of _extra_ tiles to generate (that's one less) | |||||||||||||||||||||||||||
| 51 | 2 | my $map = shift; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | @$map = map { $this->_generate_samemaprow( $_, $mults ) } @$map; | |||||||||||||||||||||||||||
| 54 | 2 | @$map = map {( $this->_generate_nextmaprow( $_, $mults ) )} @$map; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | for my $y ( 0 .. $#$map ) { | |||||||||||||||||||||||||||
| 57 | 60 | for my $x ( 0 .. $#{ $map->[$y] }) { | |||||||||||||||||||||||||||
| 58 | 1800 | my $tile = $map->[$y][$x]; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1800 | $tile->{x} = $x; | |||||||||||||||||||||||||||
| 61 | 1800 | $tile->{y} = $y; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | $map->interconnect_map; # rebuild the neighbor tables | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | # }}} | ||||||||||||||||||||||||||||
| 68 | # _generate_nextmaprow {{{ | ||||||||||||||||||||||||||||
| 69 | 30 | ▶ | sub _generate_nextmaprow { | ||||||||||||||||||||||||||
|
Subroutine
_generate_nextmaprow: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 70 | 30 | my $this = shift; | |||||||||||||||||||||||||||
| 71 | 30 | my $oldrow = shift; | |||||||||||||||||||||||||||
| 72 | 30 | my $mults = shift; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 30 | my @retrows = ($oldrow); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 30 | for( 1 .. $mults ) { | |||||||||||||||||||||||||||
| 77 | 30 | my $another_row = []; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 30 | for my $oldtile (@{ $retrows[$#retrows] }) { | |||||||||||||||||||||||||||
| 80 | 900 | my $nt = $oldtile->dup; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 900 | ▶ | if( $oldtile->{type} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 434 | ▶ | die "unknown type, assuming open" unless $oldtile->{type} eq "room" or $oldtile->{type} eq "corridor"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$oldtile->{"type"} eq "room" or $oldtile->{"type"} eq "corridor"
MC/DC0%0/2
$oldtile->{"type"} eq "room" or $oldtile->{"type"} eq "corridor"
$oldtile->{"type"} eq "room"
$oldtile->{"type"} eq "corridor"
Truth table66%2/3
A or B
A= $oldtile->{"type"} eq "room"B= $oldtile->{"type"} eq "corridor"
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 434 | $oldtile->{od}{s} = 1; | |||||||||||||||||||||||||||
| 86 | 434 | $nt->{od}{n} = 1; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 900 | push @$another_row, $nt; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 30 | push @retrows, $another_row; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 30 | my $newrow = $oldrow; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 30 | return @retrows; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | # }}} | ||||||||||||||||||||||||||||
| 100 | # _generate_samemaprow {{{ | ||||||||||||||||||||||||||||
| 101 | 30 | ▶ | sub _generate_samemaprow { | ||||||||||||||||||||||||||
|
Subroutine
_generate_samemaprow: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 102 | 30 | my $this = shift; | |||||||||||||||||||||||||||
| 103 | 30 | my $oldrow = shift; | |||||||||||||||||||||||||||
| 104 | 30 | my $mults = shift; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 30 | my $newrow = []; | |||||||||||||||||||||||||||
| 107 | 30 | for my $oldtile (@$oldrow) { | |||||||||||||||||||||||||||
| 108 | 450 | push @$newrow, $oldtile; | |||||||||||||||||||||||||||
| 109 | 450 | for ( 1 .. $mults ) { | |||||||||||||||||||||||||||
| 110 | 450 | my $nt = $oldtile->dup; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 450 | ▶ | if( $oldtile->{type} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 217 | ▶ | die "unknown type, assuming open" unless $oldtile->{type} eq "room" or $oldtile->{type} eq "corridor"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$oldtile->{"type"} eq "room" or $oldtile->{"type"} eq "corridor"
MC/DC0%0/2
$oldtile->{"type"} eq "room" or $oldtile->{"type"} eq "corridor"
$oldtile->{"type"} eq "room"
$oldtile->{"type"} eq "corridor"
Truth table66%2/3
A or B
A= $oldtile->{"type"} eq "room"B= $oldtile->{"type"} eq "corridor"
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 217 | $oldtile->{od}{e} = 1; | |||||||||||||||||||||||||||
| 116 | 217 | $nt->{od}{w} = 1; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 450 | push @$newrow, $nt; | |||||||||||||||||||||||||||
| 120 | 450 | $oldtile = $nt; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 30 | return $newrow; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | # }}} | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||