line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BalanceOfPower::Role::CrisisManager; |
2
|
|
|
|
|
|
|
$BalanceOfPower::Role::CrisisManager::VERSION = '0.400115'; |
3
|
13
|
|
|
13
|
|
6528
|
use strict; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
381
|
|
4
|
13
|
|
|
13
|
|
141
|
use v5.10; |
|
13
|
|
|
|
|
39
|
|
5
|
13
|
|
|
13
|
|
56
|
use Moo::Role; |
|
13
|
|
|
|
|
21
|
|
|
13
|
|
|
|
|
100
|
|
6
|
13
|
|
|
13
|
|
3752
|
use Template; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
342
|
|
7
|
13
|
|
|
13
|
|
59
|
use Term::ANSIColor; |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
861
|
|
8
|
|
|
|
|
|
|
|
9
|
13
|
|
|
13
|
|
63
|
use BalanceOfPower::Constants ':all'; |
|
13
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
7721
|
|
10
|
13
|
|
|
13
|
|
100
|
use BalanceOfPower::Printer; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
11262
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
requires 'get_all_crises'; |
13
|
|
|
|
|
|
|
requires 'get_hates'; |
14
|
|
|
|
|
|
|
requires 'crisis_exists'; |
15
|
|
|
|
|
|
|
requires 'war_exists'; |
16
|
|
|
|
|
|
|
requires 'broadcast_event'; |
17
|
|
|
|
|
|
|
requires 'add_crisis'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub crisis_generator |
20
|
|
|
|
|
|
|
{ |
21
|
46
|
|
|
46
|
0
|
86
|
my $self = shift; |
22
|
46
|
|
|
|
|
240
|
my @crises = $self->get_all_crises(); |
23
|
46
|
|
|
|
|
84
|
my @hates = (); |
24
|
46
|
|
|
|
|
184
|
foreach my $h ($self->get_hates()) |
25
|
|
|
|
|
|
|
{ |
26
|
107
|
100
|
|
|
|
378
|
push @hates, $h |
27
|
|
|
|
|
|
|
if(! $self->crisis_exists($h->node1, $h->node2)) |
28
|
|
|
|
|
|
|
} |
29
|
46
|
|
|
|
|
79
|
my $crises_to_use = \@crises; |
30
|
46
|
|
|
|
|
76
|
my $hates_to_use = \@hates; |
31
|
46
|
|
|
|
|
186
|
for(my $i = 0; $i < CRISIS_GENERATION_TRIES; $i++) |
32
|
|
|
|
|
|
|
{ |
33
|
230
|
|
|
|
|
579
|
($hates_to_use, $crises_to_use) = $self->crisis_generator_round($hates_to_use, $crises_to_use); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub crisis_generator_round |
39
|
|
|
|
|
|
|
{ |
40
|
230
|
|
|
230
|
0
|
253
|
my $self = shift; |
41
|
230
|
|
50
|
|
|
479
|
my $hates_to_use = shift || [] ; |
42
|
230
|
|
50
|
|
|
451
|
my $crises_to_use = shift || []; |
43
|
230
|
|
|
|
|
255
|
my @hates = $self->shuffle("Crisis generation: choosing hate", @{ $hates_to_use }); |
|
230
|
|
|
|
|
5150
|
|
44
|
230
|
|
|
|
|
323
|
my @crises = $self->shuffle("Crisis generation: choosing crisis", @{ $crises_to_use}); |
|
230
|
|
|
|
|
5361
|
|
45
|
230
|
|
|
|
|
401
|
my @original_hates = @hates; |
46
|
230
|
|
|
|
|
311
|
my @original_crises = @crises; |
47
|
|
|
|
|
|
|
|
48
|
230
|
|
|
|
|
246
|
my $picked_hate = undef; |
49
|
230
|
|
|
|
|
214
|
my $picked_crisis = undef; |
50
|
230
|
100
|
|
|
|
522
|
if(@hates) |
51
|
|
|
|
|
|
|
{ |
52
|
147
|
|
|
|
|
208
|
$picked_hate = shift @hates; |
53
|
|
|
|
|
|
|
} |
54
|
230
|
100
|
|
|
|
451
|
if(@crises) |
55
|
|
|
|
|
|
|
{ |
56
|
115
|
|
|
|
|
150
|
$picked_crisis = shift @crises; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
230
|
|
|
|
|
5450
|
my $action = $self->random(0, CRISIS_GENERATOR_NOACTION_TOKENS + 3, "Crisis action choose"); |
61
|
230
|
100
|
|
|
|
1028
|
if($action == 0) #NEW CRISIS |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
62
|
|
|
|
|
|
|
{ |
63
|
17
|
100
|
|
|
|
97
|
return (\@original_hates, \@original_crises) if ! $picked_hate; |
64
|
11
|
50
|
|
|
|
102
|
if(! $self->war_exists($picked_hate->node1, $picked_hate->node2)) |
65
|
|
|
|
|
|
|
{ |
66
|
11
|
|
|
|
|
79
|
$self->create_or_escalate_crisis($picked_hate->node1, $picked_hate->node2); |
67
|
11
|
|
|
|
|
95
|
return (\@hates, \@original_crises); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif($action == 1) #ESCALATE |
71
|
|
|
|
|
|
|
{ |
72
|
25
|
100
|
|
|
|
156
|
return (\@original_hates, \@original_crises) if ! $picked_crisis; |
73
|
10
|
50
|
|
|
|
92
|
if(! $self->war_exists($picked_crisis->node1, $picked_crisis->node2)) |
74
|
|
|
|
|
|
|
{ |
75
|
10
|
|
|
|
|
77
|
$self->create_or_escalate_crisis($picked_crisis->node1, $picked_crisis->node2); |
76
|
|
|
|
|
|
|
} |
77
|
10
|
|
|
|
|
95
|
return (\@original_hates, \@crises); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif($action == 2) #COOL DOWN |
80
|
|
|
|
|
|
|
{ |
81
|
21
|
100
|
|
|
|
140
|
return (\@original_hates, \@original_crises) if ! $picked_crisis; |
82
|
5
|
50
|
|
|
|
45
|
if(! $self->war_exists($picked_crisis->node1, $picked_crisis->node2)) |
83
|
|
|
|
|
|
|
{ |
84
|
5
|
|
|
|
|
37
|
$self->cool_down($picked_crisis->node1, $picked_crisis->node2); |
85
|
|
|
|
|
|
|
} |
86
|
5
|
|
|
|
|
49
|
return (\@original_hates, \@crises); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif($action == 3) #ELIMINATE |
89
|
|
|
|
|
|
|
{ |
90
|
21
|
100
|
|
|
|
118
|
return (\@original_hates, \@original_crises) if ! $picked_crisis; |
91
|
11
|
100
|
|
|
|
105
|
if(! $self->war_exists($picked_crisis->node1, $picked_crisis->node2)) |
92
|
|
|
|
|
|
|
{ |
93
|
9
|
|
|
|
|
62
|
$self->delete_crisis($picked_crisis->node1, $picked_crisis->node2); |
94
|
|
|
|
|
|
|
} |
95
|
11
|
|
|
|
|
93
|
return (\@original_hates, \@crises); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else |
98
|
|
|
|
|
|
|
{ |
99
|
146
|
|
|
|
|
970
|
return (\@original_hates, \@original_crises); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
sub create_or_escalate_crisis |
103
|
|
|
|
|
|
|
{ |
104
|
21
|
|
|
21
|
0
|
35
|
my $self = shift; |
105
|
21
|
|
50
|
|
|
60
|
my $node1 = shift || ""; |
106
|
21
|
|
50
|
|
|
57
|
my $node2 = shift || ""; |
107
|
21
|
100
|
|
|
|
79
|
if(my $crisis = $self->crisis_exists($node1, $node2)) |
108
|
|
|
|
|
|
|
{ |
109
|
10
|
50
|
|
|
|
46
|
if(! $crisis->is_max_crisis) |
110
|
|
|
|
|
|
|
{ |
111
|
10
|
|
|
|
|
42
|
$crisis->escalate_crisis(); |
112
|
10
|
|
|
|
|
74
|
my $event = { code => 'crisisup', |
113
|
|
|
|
|
|
|
text => "CRISIS BETWEEN $node1 AND $node2 ESCALATES", |
114
|
|
|
|
|
|
|
involved => [$node1, $node2], |
115
|
|
|
|
|
|
|
values => [ $crisis->get_crisis_level() ] |
116
|
|
|
|
|
|
|
}; |
117
|
10
|
|
|
|
|
56
|
$self->broadcast_event($event, $node1, $node2); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else |
121
|
|
|
|
|
|
|
{ |
122
|
11
|
|
|
|
|
51
|
$self->add_crisis($node1, $node2); |
123
|
11
|
|
|
|
|
123
|
$self->broadcast_event( { code => 'crisisstart', |
124
|
|
|
|
|
|
|
text => "CRISIS BETWEEN $node1 AND $node2 STARTED", |
125
|
|
|
|
|
|
|
involved => [$node1, $node2] }, $node1, $node2); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
sub cool_down |
129
|
|
|
|
|
|
|
{ |
130
|
5
|
|
|
5
|
0
|
10
|
my $self = shift; |
131
|
5
|
|
|
|
|
9
|
my $node1 = shift; |
132
|
5
|
|
|
|
|
9
|
my $node2 = shift; |
133
|
5
|
50
|
|
|
|
19
|
if(my $crisis = $self->crisis_exists($node1, $node2)) |
134
|
|
|
|
|
|
|
{ |
135
|
5
|
|
|
|
|
26
|
$crisis->cooldown_crisis(); |
136
|
5
|
100
|
|
|
|
13
|
if(! $crisis->is_crisis()) |
137
|
|
|
|
|
|
|
{ |
138
|
2
|
|
|
|
|
16
|
my $event = { code => 'crisisend', |
139
|
|
|
|
|
|
|
text => "CRISIS BETWEEN $node1 AND $node2 ENDED", |
140
|
|
|
|
|
|
|
involved => [$node1, $node2] }; |
141
|
2
|
|
|
|
|
11
|
$self->broadcast_event($event, $node1, $node2); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else |
144
|
|
|
|
|
|
|
{ |
145
|
3
|
|
|
|
|
25
|
$self->broadcast_event({ code => 'crisisdown', |
146
|
|
|
|
|
|
|
text => "CRISIS BETWEEN $node1 AND $node2 COOLED DOWN", |
147
|
|
|
|
|
|
|
involved => [$node1, $node2], |
148
|
|
|
|
|
|
|
values => [ $crisis->get_crisis_level() ] |
149
|
|
|
|
|
|
|
}, $node1, $node2); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub print_all_crises |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
157
|
0
|
|
|
|
|
|
my $n = shift; |
158
|
0
|
|
0
|
|
|
|
my $level = shift || 0; |
159
|
0
|
|
0
|
|
|
|
my $mode = shift || 'print'; |
160
|
0
|
|
|
|
|
|
my @crises; |
161
|
|
|
|
|
|
|
my @war_signal; |
162
|
0
|
|
|
|
|
|
foreach my $b ($self->get_all_crises()) |
163
|
|
|
|
|
|
|
{ |
164
|
0
|
0
|
0
|
|
|
|
if(( ($n && $b->involve($n) || ! $n)) && |
|
|
|
0
|
|
|
|
|
165
|
|
|
|
|
|
|
( $b->get_crisis_level > $level)) |
166
|
|
|
|
|
|
|
{ |
167
|
0
|
|
|
|
|
|
push @crises, $b; |
168
|
0
|
0
|
|
|
|
|
if($self->war_exists($b->node1, $b->node2)) |
169
|
|
|
|
|
|
|
{ |
170
|
0
|
|
|
|
|
|
push @war_signal, 1; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
else |
173
|
|
|
|
|
|
|
{ |
174
|
0
|
|
|
|
|
|
push @war_signal, 0; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
0
|
|
|
|
|
|
my %nation_codes = reverse %{$self->nation_codes}; |
|
0
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
return BalanceOfPower::Printer::print($mode, $self, 'print_all_crises', |
180
|
|
|
|
|
|
|
{ crises => \@crises, |
181
|
|
|
|
|
|
|
wars => \@war_signal, |
182
|
|
|
|
|
|
|
nation_codes => \%nation_codes, |
183
|
|
|
|
|
|
|
}); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|