line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BalanceOfPower::Role::Ruler; |
2
|
|
|
|
|
|
|
$BalanceOfPower::Role::Ruler::VERSION = '0.400105'; |
3
|
13
|
|
|
13
|
|
4633
|
use strict; |
|
13
|
|
|
|
|
20
|
|
|
13
|
|
|
|
|
349
|
|
4
|
13
|
|
|
13
|
|
46
|
use Moo::Role; |
|
13
|
|
|
|
|
20
|
|
|
13
|
|
|
|
|
64
|
|
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
2699
|
use BalanceOfPower::Constants ':all'; |
|
13
|
|
|
|
|
18
|
|
|
13
|
|
|
|
|
6162
|
|
7
|
|
|
|
|
|
|
|
8
|
13
|
|
|
13
|
|
3791
|
use BalanceOfPower::Relations::Influence; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
10221
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
requires 'broadcast_event'; |
11
|
|
|
|
|
|
|
requires 'get_nation'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has influences => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
default => sub { BalanceOfPower::Relations::RelPack->new() }, |
16
|
|
|
|
|
|
|
handles => { reset_influences => 'delete_link_for_node', |
17
|
|
|
|
|
|
|
add_influence => 'add_link' } |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
sub influences_garbage_collector |
20
|
|
|
|
|
|
|
{ |
21
|
47
|
|
|
47
|
0
|
55
|
my $self = shift; |
22
|
47
|
|
|
6
|
|
294
|
$self->influences->garbage_collector(sub { my $rel = shift; return $rel->status == -1 }); |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
25
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
sub is_under_influence |
25
|
|
|
|
|
|
|
{ |
26
|
303
|
|
|
303
|
0
|
225
|
my $self = shift; |
27
|
303
|
|
|
|
|
243
|
my $nation = shift; |
28
|
|
|
|
|
|
|
my @rels = $self->influences->query( |
29
|
|
|
|
|
|
|
sub { |
30
|
14
|
|
|
14
|
|
13
|
my $rel = shift; |
31
|
14
|
100
|
|
|
|
51
|
return 0 if($rel->node2 ne $nation); |
32
|
3
|
|
|
|
|
8
|
return $rel->actual_influence() |
33
|
303
|
|
|
|
|
1179
|
}, $nation); |
34
|
303
|
100
|
|
|
|
720
|
if(@rels > 0) |
35
|
|
|
|
|
|
|
{ |
36
|
3
|
|
|
|
|
9
|
return $rels[0]->start($nation); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else |
39
|
|
|
|
|
|
|
{ |
40
|
300
|
|
|
|
|
724
|
return undef; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
sub print_nation_situation |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
46
|
0
|
|
|
|
|
0
|
my $nation = shift; |
47
|
0
|
|
|
|
|
0
|
my $domination = $self->is_under_influence($nation); |
48
|
0
|
0
|
|
|
|
0
|
return "$nation is under control of $domination" if $domination; |
49
|
0
|
|
|
|
|
0
|
my @influence = $self->has_influence($nation); |
50
|
0
|
0
|
|
|
|
0
|
if(@influence > 0) |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
|
|
0
|
my $out = ""; |
53
|
0
|
|
|
|
|
0
|
for(@influence) |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
0
|
$out .= "$nation has influence on $_\n"; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
return $out; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
0
|
return "$nation is free"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
sub has_influence |
66
|
|
|
|
|
|
|
{ |
67
|
326
|
|
|
326
|
0
|
299
|
my $self = shift; |
68
|
326
|
|
|
|
|
281
|
my $nation = shift; |
69
|
|
|
|
|
|
|
my @influences = $self->influences->query( |
70
|
|
|
|
|
|
|
sub { |
71
|
28
|
|
|
28
|
|
21
|
my $rel = shift; |
72
|
28
|
100
|
|
|
|
83
|
return 0 if($rel->node1 ne $nation); |
73
|
10
|
|
|
|
|
25
|
return $rel->actual_influence() |
74
|
326
|
|
|
|
|
1464
|
}, $nation); |
75
|
326
|
|
|
|
|
790
|
my @out = (); |
76
|
326
|
|
|
|
|
331
|
for(@influences) |
77
|
|
|
|
|
|
|
{ |
78
|
10
|
|
|
|
|
23
|
push @out, $_->destination($nation); |
79
|
|
|
|
|
|
|
} |
80
|
326
|
|
|
|
|
403
|
return @out; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
sub empire |
83
|
|
|
|
|
|
|
{ |
84
|
137
|
|
|
137
|
0
|
122
|
my $self = shift; |
85
|
137
|
|
|
|
|
125
|
my $n = shift; |
86
|
137
|
100
|
|
|
|
283
|
if(my $domination = $self->is_under_influence($n)) |
87
|
|
|
|
|
|
|
{ |
88
|
3
|
|
|
|
|
2
|
my $dominator = $domination; |
89
|
3
|
|
|
|
|
8
|
my @allies = $self->has_influence($dominator); |
90
|
3
|
|
|
|
|
3
|
push @allies, $dominator; |
91
|
3
|
|
|
|
|
6
|
return @allies; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else |
94
|
|
|
|
|
|
|
{ |
95
|
134
|
|
|
|
|
201
|
my @allies = $self->has_influence($n); |
96
|
134
|
|
|
|
|
130
|
push @allies, $n; |
97
|
134
|
|
|
|
|
268
|
return @allies; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
sub occupy |
101
|
|
|
|
|
|
|
{ |
102
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
103
|
3
|
|
|
|
|
3
|
my $nation = shift; |
104
|
3
|
|
|
|
|
5
|
my $occupiers = shift; |
105
|
3
|
|
|
|
|
3
|
my $leader = shift; |
106
|
3
|
|
100
|
|
|
8
|
my $internal_disorder = shift || 0; |
107
|
3
|
|
|
|
|
7
|
$self->get_nation($nation)->occupation($self); |
108
|
3
|
|
|
|
|
9
|
my $occupied_progress = $self->get_nation($nation)->progress; |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
5
|
my @occupiers_array = @{$occupiers}; |
|
3
|
|
|
|
|
5
|
|
111
|
3
|
|
|
|
|
13
|
my $real_leader = $self->is_under_influence($leader); |
112
|
3
|
50
|
|
|
|
7
|
if($real_leader) |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
|
|
|
|
0
|
@occupiers_array = grep { $_ ne $real_leader } @occupiers_array; |
|
0
|
|
|
|
|
0
|
|
115
|
0
|
|
|
|
|
0
|
push @occupiers_array, $real_leader; |
116
|
0
|
|
|
|
|
0
|
$leader = $real_leader; |
117
|
|
|
|
|
|
|
} |
118
|
3
|
|
|
|
|
6
|
foreach my $c (@occupiers_array) |
119
|
|
|
|
|
|
|
{ |
120
|
3
|
50
|
|
|
|
5
|
if($c eq $leader) |
121
|
|
|
|
|
|
|
{ |
122
|
3
|
100
|
|
|
|
55
|
$self->add_influence(BalanceOfPower::Relations::Influence->new( node1 => $c, |
123
|
|
|
|
|
|
|
node2 => $nation, |
124
|
|
|
|
|
|
|
status => 0, |
125
|
|
|
|
|
|
|
next => $internal_disorder ? 2 : 1, |
126
|
|
|
|
|
|
|
clock => 0 )); |
127
|
3
|
|
|
|
|
12
|
$self->set_diplomacy($nation, $c, DOMINION_DIPLOMACY); |
128
|
3
|
|
|
|
|
11
|
$self->copy_diplomacy($c, $nation); |
129
|
3
|
100
|
|
|
|
8
|
if($self->get_nation($c)->progress < $occupied_progress) |
130
|
|
|
|
|
|
|
{ |
131
|
1
|
|
|
|
|
4
|
$self->get_nation($c)->progress($occupied_progress); |
132
|
1
|
|
|
|
|
20
|
$self->broadcast_event({ code => 'acquireprogress', |
133
|
|
|
|
|
|
|
text => "$c ACQUIRES PROGRESS FROM $nation: $occupied_progress", |
134
|
|
|
|
|
|
|
involved => [$c, $nation], |
135
|
|
|
|
|
|
|
values => [$occupied_progress] }, $c, $nation); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
|
|
0
|
$self->add_influence(BalanceOfPower::Relations::Influence->new( node1 => $c, |
141
|
|
|
|
|
|
|
node2 => $nation, |
142
|
|
|
|
|
|
|
status => 0, |
143
|
|
|
|
|
|
|
clock => 0 )); |
144
|
0
|
|
|
|
|
0
|
$self->set_diplomacy($nation, $c, DIPLOMACY_AFTER_OCCUPATION); |
145
|
0
|
|
|
|
|
0
|
$self->get_nation($c)->grow(); |
146
|
|
|
|
|
|
|
} |
147
|
3
|
|
|
|
|
25
|
$self->broadcast_event({code => 'occupy', |
148
|
|
|
|
|
|
|
text => "$c OCCUPIES $nation", |
149
|
|
|
|
|
|
|
involved => [$c, $nation] }, $c, $nation ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
sub situation_clock |
153
|
|
|
|
|
|
|
{ |
154
|
47
|
|
|
47
|
0
|
60
|
my $self = shift; |
155
|
47
|
|
|
|
|
121
|
foreach my $i ($self->influences->all()) |
156
|
|
|
|
|
|
|
{ |
157
|
6
|
|
|
|
|
15
|
my $old_status = $i->status_label; |
158
|
6
|
|
|
|
|
14
|
my $new_status = $i->click(); |
159
|
6
|
50
|
33
|
|
|
24
|
if($new_status && $old_status ne $new_status) |
160
|
|
|
|
|
|
|
{ |
161
|
6
|
50
|
|
|
|
22
|
if($new_status eq 'dominate') |
|
|
100
|
|
|
|
|
|
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
|
|
0
|
$self->broadcast_event({ code => 'dominate', |
164
|
|
|
|
|
|
|
text => $i->node1 . " DOMINATES " . $i->node2, |
165
|
|
|
|
|
|
|
involved => [$i->node1, $i->node2] }, $i->node1, $i->node2); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
elsif($new_status eq 'control') |
168
|
|
|
|
|
|
|
{ |
169
|
2
|
|
|
|
|
22
|
$self->broadcast_event({ code => 'control', |
170
|
|
|
|
|
|
|
text => $i->node1 . " CONTROLS " . $i->node2, |
171
|
|
|
|
|
|
|
involved => [$i->node1, $i->node2] }, $i->node1, $i->node2); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
47
|
|
|
|
|
140
|
$self->influences_garbage_collector(); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub print_influences |
179
|
|
|
|
|
|
|
{ |
180
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
181
|
0
|
|
|
|
|
|
my $n = shift; |
182
|
0
|
|
0
|
|
|
|
my $mode = shift || 'print'; |
183
|
0
|
|
|
|
|
|
my @inf = $self->influences->links_for_node($n); |
184
|
0
|
|
|
|
|
|
@inf = sort { lc($a->node1) cmp lc($b->node1) } @inf; |
|
0
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
return BalanceOfPower::Printer::print($mode, $self, 'print_influences', |
186
|
|
|
|
|
|
|
{ influences => \@inf } ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1; |