line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BalanceOfPower::Role::Mapmaker; |
2
|
|
|
|
|
|
|
$BalanceOfPower::Role::Mapmaker::VERSION = '0.400110'; |
3
|
13
|
|
|
13
|
|
4337
|
use v5.10; |
|
13
|
|
|
|
|
32
|
|
4
|
13
|
|
|
13
|
|
44
|
use strict; |
|
13
|
|
|
|
|
12
|
|
|
13
|
|
|
|
|
210
|
|
5
|
13
|
|
|
13
|
|
38
|
use Moo::Role; |
|
13
|
|
|
|
|
15
|
|
|
13
|
|
|
|
|
57
|
|
6
|
|
|
|
|
|
|
|
7
|
13
|
|
|
13
|
|
6295
|
use BalanceOfPower::Relations::Border; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
333
|
|
8
|
13
|
|
|
13
|
|
4005
|
use BalanceOfPower::Relations::RelPack; |
|
13
|
|
|
|
|
22
|
|
|
13
|
|
|
|
|
362
|
|
9
|
13
|
|
|
13
|
|
63
|
use BalanceOfPower::Utils qw( as_main_title); |
|
13
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
7404
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has borders => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
default => sub { BalanceOfPower::Relations::RelPack->new() }, |
15
|
|
|
|
|
|
|
handles => { add_border => 'add_link', |
16
|
|
|
|
|
|
|
border_exists => 'exists_link', |
17
|
|
|
|
|
|
|
get_borders => 'links_for_node', |
18
|
|
|
|
|
|
|
near_on_the_map => 'near', |
19
|
|
|
|
|
|
|
distance_on_the_map => 'distance' |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub print_borders |
24
|
|
|
|
|
|
|
{ |
25
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
my $n = shift; |
27
|
0
|
|
|
|
|
0
|
return $self->output_borders("BORDERS", $n, 'print'); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
sub html_borders |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
32
|
0
|
|
|
|
|
0
|
my $n = shift; |
33
|
0
|
|
|
|
|
0
|
return $self->output_borders("BORDERS", $n, 'html'); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub output_borders |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
40
|
0
|
|
|
|
|
0
|
my $title = shift; |
41
|
0
|
|
|
|
|
0
|
my $n = shift; |
42
|
0
|
|
|
|
|
0
|
my $mode = shift; |
43
|
0
|
|
|
|
|
0
|
my $out = ""; |
44
|
0
|
|
|
|
|
0
|
$out .= as_main_title($title, $mode); |
45
|
0
|
|
|
|
|
0
|
$out .= $self->borders->output_links($n, $mode); |
46
|
0
|
|
|
|
|
0
|
return $out; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub load_borders |
51
|
|
|
|
|
|
|
{ |
52
|
16
|
|
|
16
|
0
|
27
|
my $self = shift; |
53
|
16
|
|
|
|
|
24
|
my $bordersfile = shift; |
54
|
16
|
|
33
|
|
|
131
|
my $file = shift || $self->data_directory . "/" . $bordersfile; |
55
|
16
|
50
|
|
|
|
623
|
open(my $borders, "<", $file) || die $!;; |
56
|
16
|
|
|
|
|
345
|
for(<$borders>) |
57
|
|
|
|
|
|
|
{ |
58
|
56
|
|
|
|
|
79
|
chomp; |
59
|
56
|
|
|
|
|
58
|
my $border = $_; |
60
|
56
|
|
|
|
|
133
|
my @nodes = split(/,/, $border); |
61
|
56
|
50
|
33
|
|
|
149
|
if($self->check_nation_name($nodes[0]) && $self->check_nation_name($nodes[1])) |
62
|
|
|
|
|
|
|
{ |
63
|
56
|
50
|
33
|
|
|
265
|
if($nodes[0] && $nodes[1] && ! $self->border_exists($nodes[0], $nodes[1])) |
|
|
|
33
|
|
|
|
|
64
|
|
|
|
|
|
|
{ |
65
|
56
|
|
|
|
|
693
|
my $b = BalanceOfPower::Relations::Border->new(node1 => $nodes[0], node2 => $nodes[1]); |
66
|
56
|
|
|
|
|
8508
|
$self->add_border($b); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
0
|
say "WRONG BORDER: $border"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub near_nations |
77
|
|
|
|
|
|
|
{ |
78
|
19
|
|
|
19
|
0
|
19
|
my $self = shift; |
79
|
19
|
|
|
|
|
22
|
my $nation = shift; |
80
|
19
|
|
100
|
|
|
40
|
my $geographical = shift || 0; |
81
|
19
|
100
|
|
|
|
31
|
if($geographical) |
82
|
|
|
|
|
|
|
{ |
83
|
17
|
|
|
|
|
64
|
return $self->near_on_the_map($nation, $self->nation_names); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else |
86
|
|
|
|
|
|
|
{ |
87
|
2
|
100
|
|
|
|
2
|
return grep { $self->in_military_range($nation, $_) && $nation ne $_ } @{$self->nation_names}; |
|
10
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
5
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
sub print_near_nations |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
93
|
0
|
|
|
|
|
0
|
my $nation = shift; |
94
|
0
|
|
|
|
|
0
|
my $out = ""; |
95
|
0
|
|
|
|
|
0
|
for($self->near_nations($nation)) |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
0
|
$out .= $_ . "\n"; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
0
|
return $out; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
sub distance |
102
|
|
|
|
|
|
|
{ |
103
|
177
|
|
|
177
|
0
|
169
|
my $self = shift; |
104
|
177
|
|
|
|
|
153
|
my $nation1 = shift; |
105
|
177
|
|
|
|
|
130
|
my $nation2 = shift; |
106
|
177
|
|
|
|
|
458
|
return $self->distance_on_the_map($nation1, $nation2, $self->nation_names); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_group_borders |
111
|
|
|
|
|
|
|
{ |
112
|
14
|
|
|
14
|
0
|
13
|
my $self = shift; |
113
|
14
|
|
|
|
|
16
|
my $group1 = shift; |
114
|
14
|
|
|
|
|
13
|
my $group2 = shift; |
115
|
14
|
|
|
|
|
10
|
my @from = @{ $group1 }; |
|
14
|
|
|
|
|
22
|
|
116
|
14
|
|
|
|
|
14
|
my @to = @{ $group2 }; |
|
14
|
|
|
|
|
19
|
|
117
|
14
|
|
|
|
|
18
|
my @out = (); |
118
|
14
|
|
|
|
|
19
|
foreach my $to_n (@to) |
119
|
|
|
|
|
|
|
{ |
120
|
18
|
|
|
|
|
18
|
foreach my $from_n (@from) |
121
|
|
|
|
|
|
|
{ |
122
|
21
|
100
|
|
|
|
43
|
if($self->in_military_range($from_n, $to_n)) |
123
|
|
|
|
|
|
|
{ |
124
|
8
|
|
|
|
|
12
|
push @out, $to_n; |
125
|
8
|
|
|
|
|
21
|
last; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
14
|
|
|
|
|
32
|
return @out; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#cache management |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub print_distance |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
138
|
0
|
|
|
|
|
|
my $n1 = shift; |
139
|
0
|
|
|
|
|
|
my $n2 = shift; |
140
|
0
|
|
|
|
|
|
return "Distance between $n1 and $n2: " . $self->distance($n1, $n2); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |