line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Settlers::Map::Intersection; |
2
|
|
|
|
|
|
|
$Settlers::Map::Intersection::VERSION = '0.07'; |
3
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
1
|
|
6
|
|
|
3
|
|
|
|
|
72
|
|
|
1
|
|
|
|
|
1057
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
4
|
3
|
|
|
3
|
|
21
|
use warnings; |
|
3
|
|
|
1
|
|
5
|
|
|
3
|
|
|
|
|
85
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
3
|
|
|
|
|
16
|
'""' => 'uuid', |
|
1
|
|
|
|
|
8
|
|
8
|
3
|
|
|
3
|
|
13
|
fallback => 1; |
|
3
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new |
11
|
|
|
|
|
|
|
{ |
12
|
1163
|
|
|
1163
|
0
|
1970
|
my ($class, $tiles) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1163
|
50
|
33
|
|
|
7661
|
die 'Intersection->new() requires an arrayref of 3 tiles' |
|
|
|
33
|
|
|
|
|
15
|
|
|
|
|
|
|
unless $tiles && ref $tiles eq 'ARRAY' && @$tiles == 3; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# check tiles are joined |
18
|
1163
|
|
|
|
|
2075
|
for my $t1 (@$tiles) |
19
|
|
|
|
|
|
|
{ |
20
|
3487
|
|
|
|
|
53251
|
for my $t2 (@$tiles) |
21
|
|
|
|
|
|
|
{ |
22
|
10461
|
100
|
100
|
|
|
118887
|
die 'Invalid intersection - all 3 tiles must be next to each other' |
23
|
|
|
|
|
|
|
unless $t1 eq $t2 || $t1->hex_distance($t2) == 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
bless { |
28
|
|
|
|
|
|
|
location => $tiles, |
29
|
1162
|
|
|
|
|
3007
|
uuid => join('|', map {$_->id} sort {$a->id cmp $b->id} @$tiles), |
|
3486
|
|
|
|
|
16704
|
|
|
3061
|
|
|
|
|
14483
|
|
30
|
|
|
|
|
|
|
}, $class; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
101836
|
|
|
101836
|
0
|
340453
|
sub uuid { $_[0]->{uuid} } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub is_colliding |
36
|
|
|
|
|
|
|
{ |
37
|
3441
|
|
|
3441
|
0
|
4610
|
my ($self, $location) = @_; |
38
|
|
|
|
|
|
|
|
39
|
3441
|
50
|
33
|
|
|
6091
|
die 'is_colliding requires an Intersection or Path object as an argument' |
|
|
|
33
|
|
|
|
|
40
|
|
|
|
|
|
|
unless $location && ($location->isa('Settlers::Map::Intersection') |
41
|
|
|
|
|
|
|
|| $location->isa('Settlers::Map::Path')); |
42
|
3441
|
50
|
|
|
|
15092
|
return $location->isa('Settlers::Map::Path') |
43
|
|
|
|
|
|
|
? $location->is_colliding($self) |
44
|
|
|
|
|
|
|
: $self eq $location; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub is_adjacent |
48
|
|
|
|
|
|
|
{ |
49
|
19246
|
|
|
19246
|
0
|
27033
|
my ($self, $location) = @_; |
50
|
|
|
|
|
|
|
|
51
|
19246
|
50
|
66
|
|
|
34503
|
die 'is_adjacent requires an Intersection or tile object as an argument' |
|
|
|
33
|
|
|
|
|
52
|
|
|
|
|
|
|
unless $location |
53
|
|
|
|
|
|
|
&& ( $location->isa('Settlers::Map::Intersection') |
54
|
|
|
|
|
|
|
|| $location->isa('Settlers::Map::Tile')); |
55
|
|
|
|
|
|
|
|
56
|
19246
|
|
|
|
|
29256
|
my ($matching_tiles, $tiles_to_match) = (0); |
57
|
19246
|
100
|
|
|
|
50950
|
if ($location->isa('Settlers::Map::Intersection')) |
58
|
|
|
|
|
|
|
{ |
59
|
18199
|
|
|
|
|
20416
|
$tiles_to_match = 2; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# intersections are adjacent if they share 2 coordinates with the intersection |
62
|
18199
|
|
|
|
|
19691
|
for my $hex (@{$self->{location}}) |
|
18199
|
|
|
|
|
34798
|
|
63
|
|
|
|
|
|
|
{ |
64
|
54597
|
|
|
|
|
63069
|
$matching_tiles += grep($hex eq $_, @{$location->{location}}); |
|
54597
|
|
|
|
|
153267
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else |
68
|
|
|
|
|
|
|
{ |
69
|
1047
|
|
|
|
|
1309
|
$tiles_to_match = 1; |
70
|
|
|
|
|
|
|
# tiles are adjacent if they share 1 coordinate with the intersection |
71
|
1047
|
|
|
|
|
1221
|
for my $tile (@{$self->{location}}) |
|
1047
|
|
|
|
|
2372
|
|
72
|
|
|
|
|
|
|
{ |
73
|
3141
|
100
|
|
|
|
7284
|
$matching_tiles += $tile eq $location ? 1 : 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
19246
|
|
|
|
|
99079
|
return $matching_tiles == $tiles_to_match; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |