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