lib/BalanceOfPower/World.pm

filter: Statementstmt 94.7% 484 / 511 Branchbran 80.4% 156 / 194 Conditioncond 42.3% 11 / 26 MC/DCmcdc 17.6% 3 / 17 Subroutinesub 100% 50 / 50 Podpod 0.0% 0 / 34 totaltotal 84.6% 704 / 832 CC 127 SCAR 25.0
CC
127
Cov
89%
stipulate_treaty
38.9
execute_decisions
28.9
init_random
18.1
CRAP 12.2
« blib/lib/BalanceOfPower/Relations/Role/Relation.pm ↑ Summary blib/lib/BalanceOfPower/Relations/Influence.pm »
1 package BalanceOfPower::World;
2 11 $BalanceOfPower::World::VERSION = '0.200000';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use BalanceOfPower::Utils qw(prev_turn next_turn);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use BalanceOfPower::Nation;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use BalanceOfPower::Dice;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use BalanceOfPower::Commands;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 has name => (
17 is => 'ro',
18 default => 'WORLD'
19 );
20 11 has silent => (
21 is => 'rw',
22 default => 0
23 );
24 11 has first_year => (
25 is => 'ro'
26 );
27 11 has current_year => (
28 is => 'rw'
29 );
30 has nations => (
31 is => 'rw',
32 14 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
33 11 );
34 has nation_names => (
35 is => 'rw',
36 14 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
37 11 );
38 has nation_codes => (
39 is => 'rw',
40 14 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
41 11 );
42 11 has order => (
43 is => 'rw',
44 default => ""
45 );
46 has ia_orders => (
47 is => 'rw',
48 14 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
49 11 );
50 11 has autoplay => (
51 is => 'rw',
52 default => 0
53 );
54 has data_directory => (
55 is => 'rw',
56 default => sub {
57 14 ▶ my $module_file_path = __FILE__;
Subroutine __ANON__: called CC=1 SCAR=0.0
58 14 my $root_path = abs_path($module_file_path);
59 14 $root_path =~ s/World\.pm//;
60 14 my $data_directory = $root_path . "data";
61  
62 }
63 11 );
64 has dice => (
65 is => 'ro',
66 14 ▶ default => sub { BalanceOfPower::Dice->new( log_name => "bop-dice.log" ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
67 11 handles => { random => 'random',
68 random10 => 'random10',
69 random_around_zero => 'random_around_zero',
70 shuffle => 'shuffle_array',
71 tricks => 'tricks',
72 forced_advisor => 'forced_advisor',
73 only_one_nation_acting => 'only_one_nation_acting',
74 dice_log => 'log_active'
75 }
76 );
77 11 has savefile => (
78 is => 'rw',
79 default => ""
80 );
81  
82  
83  
84 11 with 'BalanceOfPower::Role::GameMaster';
85 11 with 'BalanceOfPower::Role::Historian';
86 11 with 'BalanceOfPower::Role::Herald';
87 11 with 'BalanceOfPower::Role::Ruler';
88 11 with 'BalanceOfPower::Role::Mapmaker';
89 11 with 'BalanceOfPower::Role::Supporter';
90 11 with 'BalanceOfPower::Role::Diplomat';
91 11 with 'BalanceOfPower::Role::Merchant';
92 11 with 'BalanceOfPower::Role::Broker';
93 11 with 'BalanceOfPower::Role::Warlord';
94 11 with 'BalanceOfPower::Role::CrisisManager';
95 11 with 'BalanceOfPower::Role::Analyst';
96 11 with 'BalanceOfPower::Role::Recorder';
97  
98 sub get_nation
99 {
100 1711 ▶ my $self = shift;
Subroutine get_nation: called CC=3 SCAR=12.5
Pod undocumented
101 1711 my $nation = shift;
102 1711 ▶ if(! $nation)
Branch: 1 branch
BranchTrueFalseTotal
unless ($nation) 0 1711 1711
103 {
104 0 say "Nation is undef";
105 0 return undef;
106 }
107 1711 my @nations = grep { $_->name eq $nation } @{$self->nations};
108 1711 ▶ if(@nations > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@nations > 0) { } 1711 0 1711
109 {
110 1711 return $nations[0];
111 }
112 else
113 {
114 0 say "Cannot found $nation";
115 0 return undef;
116 }
117 }
118 sub correct_nation_name
119 {
120 25 ▶ my $self = shift;
Subroutine correct_nation_name: called CC=5 SCAR=16.1
Pod undocumented
121 25 my $nation = shift;
122 25 ▶ return undef if(! $nation);
Branch: 1 branch
BranchTrueFalseTotal
unless $nation 6 19 25
123 19 ▶ $nation = $self->nation_codes->{uc $nation} if(exists $self->nation_codes->{uc $nation});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->nation_codes->{uc $nation} 0 19 19
124 19 for(@{$self->nation_names})
125 {
126 73 ▶ return $_ if(uc $_ eq uc $nation);
Branch: 1 branch
BranchTrueFalseTotal
if uc $_ eq uc $nation 13 60 73
127 }
128 6 return undef;
129 }
130 sub check_nation_name
131 {
132 102 ▶ my $self = shift;
Subroutine check_nation_name: called CC=1 SCAR=0.0
Pod undocumented
133 102 my $name = shift;
134 102 return grep {$_ eq $name} @{$self->nation_names};
135 }
136 sub get_prev_year
137 {
138 1 ▶ my $self = shift;
Subroutine get_prev_year: called CC=1 SCAR=0.0
Pod undocumented
139 1 return prev_turn($self->current_year);
140 }
141  
142 sub load_nations_data
143 {
144 14 ▶ my $self = shift;
Subroutine load_nations_data: called CC=6 SCAR=17.9
Pod undocumented
145 14 my $datafile = shift;
146 14 my $file = $self->data_directory . "/" . $datafile;
147 14 ▶ open(my $nations_file, "<", $file) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $nations_file, "<", $file or die $! 0 14 14
148 14 my $area;
149 my %nations_data;
150 14 for(<$nations_file>)
151 {
152 79 my $n = $_;
153 79 chomp $n;
154 79 ▶ if(! ($n =~ /^#/))
Branch: 1 branch
BranchTrueFalseTotal
if (not $n =~ /^#/) { } 65 14 79
155 {
156 65 my ($name, $code, $size, $government) = split(',', $n);
157 65 ▶ if($government eq 'd')
Branch: 2 branches
BranchTrueFalseTotal
if ($government eq 'd') { } 52 13 65
elsif ($government eq 'D') { } 13 0 13
158 {
159 52 $government = 'democracy';
160 }
161 elsif($government eq 'D')
162 {
163 13 $government = 'dictatorship';
164 }
165 65 $nations_data{$name} = { code => $code,
166 area => $area,
167 size => $size,
168 government => $government ,
169 }
170  
171 }
172 else
173 {
174 14 $n =~ /^# (.*)$/;
175 14 $area = $1;
176 }
177 }
178 14 return %nations_data;
179 }
180  
181 #Initial values, randomly generated
182 sub init_random
183 {
184 14 ▶ my $self = shift;
Subroutine init_random: called CC=18 SCAR=28.9
Pod undocumented
185 14 my $datafile = shift;
186 14 my $bordersfile = shift;
187 14 my %nations_data = $self->load_nations_data($datafile);
188 14 my $flags = shift;
189  
190 14 my $trades = 1;
191 14 my $diplomacy = 1;
192 14 my $alliances = 1;
193 14 ▶ if($flags)
Branch: 1 branch
BranchTrueFalseTotal
if ($flags) 13 1 14
194 {
195 $trades = $flags->{'trades'}
196 13 ▶ if(exists $flags->{'trades'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $flags->{"trades"} 12 1 13
197 $diplomacy = $flags->{'diplomacy'}
198 13 ▶ if(exists $flags->{'diplomacy'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $flags->{"diplomacy"} 1 12 13
199 $alliances = $flags->{'alliances'}
200 13 ▶ if(exists $flags->{'alliances'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $flags->{"alliances"} 13 0 13
201  
202 }
203  
204 14 $self->delete_log();
205 14 $self->dice->delete_log();
206 14 my @nation_names = ();
207 14 foreach my $n (keys %nations_data)
208 {
209 65 push @nation_names, $n;
210 65 ▶ say "Working on $n" if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 21 44 65
211 65 my $export_quote = $self->random10(MIN_EXPORT_QUOTE, MAX_EXPORT_QUOTE, "Export quote $n");
212 65 ▶ say " export quote: $export_quote" if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 21 44 65
213 65 my $government_strength = $self->random10(MIN_GOVERNMENT_STRENGTH, MAX_GOVERNMENT_STRENGTH, "Government strenght $n");
214 65 ▶ say " government strength: $government_strength" if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 21 44 65
215  
216 65 my $executive = BalanceOfPower::Executive->new( actor => $n );
217 65 $executive->init($self);
218 65 push @{$self->nations}, BalanceOfPower::Nation->new(
219 name => $n,
220 code => $nations_data{$n}->{code},
221 executive => $executive,
222 area => $nations_data{$n}->{area},
223 size => $nations_data{$n}->{size},
224 government => $nations_data{$n}->{government},
225 export_quote => $export_quote,
226 government_strength => $government_strength,
227 65 available_stocks => START_STOCKS->[$nations_data{$n}->{size}],
228 log_name => $self->log_name,
229 log_on_stdout => $self->log_on_stdout);
230 65 $self->nation_codes->{$nations_data{$n}->{code}} = $n;
231 }
232 14 $self->nation_names(\@nation_names);
233 14 $self->load_borders($bordersfile);
234 14 ▶ if($trades)
Branch: 1 branch
BranchTrueFalseTotal
if ($trades) { } 2 12 14
235 {
236 2 ▶ say "Trades generation..." if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 2 0 2
237 2 $self->init_trades();
238 }
239 else
240 {
241 12 ▶ say "Trades generation skipped" if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 3 9 12
242 }
243 14 ▶ if($diplomacy)
Branch: 1 branch
BranchTrueFalseTotal
if ($diplomacy) { } 13 1 14
244 {
245 13 ▶ say "Diplomacy generation..." if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 4 9 13
246 13 $self->init_diplomacy();
247 }
248 else
249 {
250 1 ▶ say "Diplomacy generation skipped" if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 1 0 1
251 }
252 14 ▶ if($alliances)
Branch: 1 branch
BranchTrueFalseTotal
if ($alliances) { } 1 13 14
253 {
254 1 ▶ say "Alliances generation..." if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->silent 1 0 1
255 1 $self->init_random_alliances();
256 }
257 else
258 {
259 13 ▶ say "Alliances generation skipped" if ! $self->silent;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->silent 4 9 13
260 }
261 }
262  
263 #Group function for all the steps involved in a turn
264 sub pre_decisions_elaborations
265 {
266 40 ▶ my $self = shift;
Subroutine pre_decisions_elaborations: called CC=1 SCAR=0.0
Pod undocumented
267 40 my $t = shift;
268 40 $self->init_year($t);
269 40 $self->war_current_year();
270 40 $self->player_current_year();
271 40 $self->war_debts();
272 40 $self->crisis_generator();
273 }
274 sub post_decisions_elaborations
275 {
276 40 ▶ my $self = shift;
Subroutine post_decisions_elaborations: called CC=1 SCAR=0.0
Pod undocumented
277 40 $self->execute_stock_orders();
278 40 $self->execute_decisions();
279 40 $self->economy();
280 40 $self->warfare();
281 40 $self->internal_conflict();
282 40 $self->register_global_data();
283 40 $self->collect_events();
284 }
285  
286  
287  
288 sub elaborate_turn
289 {
290 14 ▶ my $self = shift;
Subroutine elaborate_turn: called CC=1 SCAR=0.0
Pod undocumented
291 14 my $t = shift;
292 14 $self->pre_decisions_elaborations($t);
293 14 $self->decisions();
294 14 $self->post_decisions_elaborations();
295 }
296  
297 #To automatically generate turns
298 sub autopilot
299 {
300 1 ▶ my $self = shift;
Subroutine autopilot: called CC=3 SCAR=11.0
Pod undocumented
301 1 my $start = shift;
302 1 my $stop = shift;
303 1 $self->autoplay(1);
304 1 for($start..$stop)
305 {
306 1 my $y = $_;
307 1 foreach my $t (get_year_turns($y))
308 {
309 4 $self->elaborate_turn($t);
310 }
311 }
312 1 $self->autoplay(0);
313 }
314  
315  
316 # Configure current year
317 # Give production to countries. Countries split it between export and domestic and, if allowed, raise the debt in case of necessity
318 # Wealth reset
319 # Production and debt recorded
320 sub init_year
321 {
322 41 ▶ my $self = shift;
Subroutine init_year: called CC=4 SCAR=13.9
Pod undocumented
323 41 my $turn = shift;
324 41 ▶ if(! $turn)
Branch: 1 branch
BranchTrueFalseTotal
unless ($turn) 5 36 41
325 {
326 5 $turn = next_turn($self->current_year);
327 }
328 41 $self->log("--- $turn ---");
329 41 ▶ say $turn if $self->autoplay();
Branch: 1 branch
BranchTrueFalseTotal
if $self->autoplay 8 33 41
330 41 $self->current_year($turn);
331 41 foreach my $n (@{$self->nations})
332 {
333 179 $n->current_year($turn);
334 179 $n->wealth(0);
335 179 my $prod = $self->calculate_production($n);
336 179 $n->production($prod);
337 179 my $prestige = $self->calculate_prestige($n);
338 179 $n->prestige($prestige);
339 179 $self->set_statistics_value($n, 'production', $prod);
340 179 $self->set_statistics_value($n, 'debt', $n->debt);
341 179 $self->set_statistics_value($n, 'prestige', $prestige);
342 }
343 }
344  
345  
346  
347 # PRODUCTION MANAGEMENT ###############################
348  
349 #Say the value of starting production used to calculate production for a turn.
350 #Usually is just the value of production the turn before, but if rebels won a civil war it has to be undef to allow a totally random generation of production.
351 sub get_base_production
352 {
353 179 ▶ my $self = shift;
Subroutine get_base_production: called CC=4 SCAR=13.9
Pod undocumented
354 179 my $nation = shift;
355  
356 179 my @newgov = $nation->get_events("NEW GOVERNMENT CREATED", prev_turn($nation->current_year));
357 179 my $previous_production = $self->get_statistics_value(prev_turn($nation->current_year), $nation->name, 'production');
358
359 179 ▶ return () if(@newgov > 0);
Branch: 1 branch
BranchTrueFalseTotal
if @newgov > 0 0 179 179
360 179 ▶ return () if(! $previous_production);
Branch: 1 branch
BranchTrueFalseTotal
unless $previous_production 45 134 179
361
362 134 my @prods = ();
363 134 ▶ for(my $i = 0; $i < PRODUCTION_UNITS->[$nation->size]; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < [2,3,4]->[$nation->size]) 536 134 670
364 {
365 536 push @prods, $self->get_statistics_value(prev_turn($nation->current_year), $nation->name, 'production' . $i);
366 }
367 134 return @prods;
368 }
369 sub calculate_production
370 {
371 179 ▶ my $self = shift;
Subroutine calculate_production: called CC=7 SCAR=19.9
Pod undocumented
372 179 my $n = shift;
373 179 my @prev_prods = $self->get_base_production($n);
374 179 my @next_prods = ();
375 179 my $cost_for_retreat = 0;
376 179 my @retreats = $n->get_events("RETREAT FROM", prev_turn($n->current_year));
377 179 my $global_production = 0;
378 179 ▶ for(my $i = 0; $i < PRODUCTION_UNITS->[$n->size]; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < [2,3,4]->[$n->size]) 716 179 895
379 {
380 716 ▶ if(@prev_prods > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@prev_prods > 0) { } 536 180 716
381 {
382 536 $next_prods[$i] = $prev_prods[$i] + $self->random10(MIN_DELTA_PRODUCTION, MAX_DELTA_PRODUCTION, "Delta production" . $i . " " . $n->name);
383 }
384 else
385 {
386 180 $next_prods[$i] = $self->random10(MIN_STARTING_PRODUCTION, MAX_STARTING_PRODUCTION, "Starting production" . $i . " " . $n->name);
387 }
388  
389 #DEFEAT COST MANAGEMENT
390 716 ▶ if(@retreats)
Branch: 1 branch
BranchTrueFalseTotal
if (@retreats) 0 716 716
391 {
392 0 $next_prods[$i] -= ATTACK_FAILED_PRODUCTION_MALUS;
393 0 $cost_for_retreat += ATTACK_FAILED_PRODUCTION_MALUS;
394 }
395 716 ▶ $next_prods[$i] = 0 if($next_prods[$i] < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $next_prods[$i] < 0 0 716 716
396 716 ▶ $next_prods[$i] = MAX_PRODUCTION if($next_prods[$i] > MAX_PRODUCTION);
Branch: 1 branch
BranchTrueFalseTotal
if $next_prods[$i] > 50 20 696 716
397  
398 716 $self->set_statistics_value($n, 'production' . $i, $next_prods[$i]);
399 716 $global_production += $next_prods[$i];
400 }
401 179 ▶ if($cost_for_retreat)
Branch: 1 branch
BranchTrueFalseTotal
if ($cost_for_retreat) 0 179 179
402 {
403 0 $self->send_event("COST FOR DEFEAT ON PRODUCTION: " . $cost_for_retreat);
404 }
405 179 return $global_production;
406 }
407  
408  
409 #Conquered nations give to the conqueror a quote of their production at start of the turn
410 sub war_debts
411 {
412 40 ▶ my $self = shift;
Subroutine war_debts: called CC=2 SCAR=6.9
Pod undocumented
413 40 for($self->influences->all())
414 {
415 5 $self->loot($_);
416 }
417 40 $self->situation_clock();
418 }
419  
420 sub loot
421 {
422 5 ▶ my $self = shift;
Subroutine loot: called CC=5 SCAR=16.2
Pod undocumented
423 5 my $influence = shift;
424 5 my $n2 = $influence->node2;
425 5 my $n1 = $influence->node1;
426 5 my $quote = $influence->get_loot_quote();
427 5 ▶ return if(! $quote || $quote == 0);
Branch: 1 branch
BranchTrueFalseTotal
if not $quote or $quote == 0 4 1 5
Condition66%2/3
not $quote or $quote == 0
l!l&&r!l&&!r
401
MC/DC50%1/2
not $quote or $quote == 0
not $quote $quote == 0
Truth table66%2/3
not(A) or B
A= not $quoteB= $quote == 0
ABresult
1X1
011
000
428 1 my $nation = $self->get_nation($n2);
429 1 my $receiver = $self->get_nation($n1);
430 1 ▶ my $amount_domestic = $nation->production_for_domestic >= $quote ? $quote : $nation->production_for_domestic;
Branch: 1 branch
BranchTrueFalseTotal
$nation->production_for_domestic >= $quote ? : 1 0 1
431 1 ▶ my $amount_export = $nation->production_for_export >= $quote ? $quote : $nation->production_for_export;
Branch: 1 branch
BranchTrueFalseTotal
$nation->production_for_export >= $quote ? : 1 0 1
432 1 $nation->subtract_production('domestic', $amount_domestic);
433 1 $nation->subtract_production('export', $amount_export);
434 1 $nation->register_event("PAY LOOT TO " . $receiver->name . ": $amount_domestic + $amount_export");
435 1 $receiver->subtract_production('domestic', -1 * $amount_domestic);
436 1 $receiver->subtract_production('export', -1 * $amount_export);
437 1 $receiver->register_event("ACQUIRE LOOT FROM " . $nation->name . ": $amount_domestic + $amount_export");
438 }
439  
440  
441  
442 # PRODUCTION MANAGEMENT END ###############################################
443  
444 # PRESTIGE MANAGEMENT #####################################################
445  
446 sub calculate_prestige
447 {
448 179 ▶ my $self = shift;
Subroutine calculate_prestige: called CC=8 SCAR=20.8
Pod undocumented
449 179 my $nation = shift;
450 179 my $nation_name = $nation->name;
451 179 my $prestige = 0;
452 179 my @routes = $self->routes_for_node($nation_name);
453 179 $prestige += @routes;
454 179 my @supported = $self->supporter($nation_name);
455 179 $prestige += @supported;
456 179 my @influenced = $self->has_influence($nation_name);
457 179 $prestige += @influenced * INFLUENCE_PRESTIGE_BONUS;
458 179 my $bonus = 0;
459 179 my @ordered_best_w = $self->order_statistics(prev_turn($nation->current_year), 'w/d');
460 179 ▶ if(@ordered_best_w >= BEST_WEALTH_FOR_PRESTIGE)
Branch: 1 branch
BranchTrueFalseTotal
if (@ordered_best_w >= 5) 125 54 179
461 {
462 125 ▶ for(my $i = 0; $i < BEST_WEALTH_FOR_PRESTIGE; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 5) 625 125 750
463 {
464 625 ▶ if($ordered_best_w[$i]->{nation} eq $nation_name)
Branch: 1 branch
BranchTrueFalseTotal
if ($ordered_best_w[$i]{"nation"} eq $nation_name) 125 500 625
465 {
466 125 $bonus += BEST_WEALTH_FOR_PRESTIGE_BONUS;
467 125 $self->broadcast_event("ONE OF THE FIRST " . BEST_WEALTH_FOR_PRESTIGE . " NATIONS FOR WEALTH WAS " . $nation_name, $nation_name);
468 }
469 }
470 }
471 179 my @ordered_best_p = $self->order_statistics(prev_turn($nation->current_year), 'progress');
472 179 ▶ if(@ordered_best_p >= BEST_PROGRESS_FOR_PRESTIGE)
Branch: 1 branch
BranchTrueFalseTotal
if (@ordered_best_p >= 5) 125 54 179
473 {
474 125 ▶ for(my $i = 0; $i < BEST_PROGRESS_FOR_PRESTIGE; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 5) 625 125 750
475 {
476 625 ▶ if($ordered_best_p[$i]->{nation} eq $nation_name)
Branch: 1 branch
BranchTrueFalseTotal
if ($ordered_best_p[$i]{"nation"} eq $nation_name) 125 500 625
477 {
478 125 $bonus += BEST_PROGRESS_FOR_PRESTIGE_BONUS;
479 125 $self->broadcast_event("ONE OF THE FIRST " . BEST_PROGRESS_FOR_PRESTIGE . " NATIONS FOR PROGRESS WAS " . $nation_name, $nation_name);
480 }
481 }
482 }
483
484 179 $prestige += $bonus;
485 179 my @wins = $nation->get_events("WAR BETWEEN .* AND .* WON BY ". $nation_name, prev_turn($nation->current_year));
486 179 ▶ if(@wins > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@wins > 0) 1 178 179
487 {
488 1 $prestige += WAR_PRESTIGE_BONUS;
489 }
490 179 return $prestige;
491 }
492  
493 # PRESTIGE MANAGEMENT END #####################################################
494  
495 # DECISIONS ###############################################################
496  
497 # Decisions are collected and executed
498 sub execute_decisions
499 {
500 40 ▶ my $self = shift;
Subroutine execute_decisions: called CC=28 SCAR=33.6
Pod undocumented
501 40 my @decisions = @{$self->ia_orders};
502 40 my @route_adders = ();
503 #foreach my $d (@decisions)
504 40 foreach my $n (@{$self->nation_names})
505 {
506 174 my $command = $self->control($n);
507 174 ▶ if(! $command)
Branch: 1 branch
BranchTrueFalseTotal
unless ($command) 173 1 174
508 {
509 173 ▶ my @nation_orders = grep { $_ =~ /^$n: / } @decisions; if(@nation_orders > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@nation_orders > 0) { } 69 104 173
510 {
511 69 $nation_orders[0] =~ /^(.*): (.*)$/;
512 69 $command = $2;
513 }
514 else
515 {
516 104 next;
517 }
518 }
519 70 my $nation = $self->get_nation($n);
520 70 ▶ if($command =~ /^DELETE TRADEROUTE (.*)->(.*)$/)
Branch: 16 branches
BranchTrueFalseTotal
if ($command =~ /^DELETE TRADEROUTE (.*)->(.*)$/) { } 1 69 70
elsif ($command =~ /^ADD ROUTE$/) { } 8 61 69
elsif ($command =~ /^LOWER DISORDER$/) { } 4 57 61
elsif ($command =~ /^BUILD TROOPS$/) { } 11 46 57
elsif ($command =~ /^BOOST PRODUCTION$/) { } 6 40 46
elsif ($command =~ /DECLARE WAR TO (.*)$/) { } 6 34 40
elsif ($command =~ /^MILITARY SUPPORT (.*)$/) { } 3 31 34
elsif ($command =~ /^RECALL MILITARY SUPPORT (.*)$/) { } 1 30 31
elsif ($command =~ /^AID INSURGENTS IN (.*)$/) { } 8 22 30
elsif ($command =~ /^TREATY (.*) WITH (.*)$/) { } 2 20 22
elsif ($command =~ /^ECONOMIC AID FOR (.*)$/) { } 1 19 20
elsif ($command =~ /^REBEL MILITARY SUPPORT (.*)$/) { } 1 18 19
elsif ($command =~ /^DIPLOMATIC PRESSURE ON (.*)$/) { } 9 9 18
elsif ($command =~ /^RECALL REBEL MILITARY SUPPORT (.*)$/) { } 1 8 9
elsif ($command =~ /^MILITARY AID FOR (.*)$/) { } 3 5 8
elsif ($command =~ /^PROGRESS$/) { } 5 0 5
521 {
522 1 $self->delete_route($1, $2);
523 }
524 elsif($command =~ /^ADD ROUTE$/)
525 {
526 8 push @route_adders, $nation->name;
527 }
528 elsif($command =~ /^LOWER DISORDER$/)
529 {
530 4 $nation->lower_disorder($self);
531 }
532 elsif($command =~ /^BUILD TROOPS$/)
533 {
534 11 $nation->build_troops();
535 }
536 elsif($command =~ /^BOOST PRODUCTION$/)
537 {
538 6 $nation->boost_production();
539 }
540 elsif($command =~ /DECLARE WAR TO (.*)$/)
541 {
542 6 my $attacker = $nation;
543 6 my $defender = $self->get_nation($1);
544 6 ▶ if(! $self->at_war($attacker->name) && ! $self->at_war($defender->name))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->at_war($attacker->name) or $self->at_war($defender->name)) 4 2 6
Condition66%2/3
$self->at_war($attacker->name) or $self->at_war($defender->name)
l!l&&r!l&&!r
204
MC/DC50%1/2
$self->at_war($attacker->name) or $self->at_war($defender->name)
$self->at_war($attacker->name) $self->at_war($defender->name)
Truth table66%2/3
A or B
A= $self->at_war($attacker->name)B= $self->at_war($defender->name)
ABresult
1X1
011
000
545 {
546 4 $self->create_war($attacker, $defender);
547 }
548 }
549 elsif($command =~ /^MILITARY SUPPORT (.*)$/)
550 {
551 3 my $supporter = $nation;
552 3 my $supported = $self->get_nation($1);
553 3 ▶ if($supported->accept_military_support($supporter->name, $self))
Branch: 1 branch
BranchTrueFalseTotal
if ($supported->accept_military_support($supporter->name, $self)) { } 3 0 3
554 {
555 3 $self->start_military_support($supporter, $supported);
556 }
557 else
558 {
559 0 $self->broadcast_event($supported->name . " REFUSED MILITARY SUPPORT FROM " . $supporter->name);
560 }
561 }
562 elsif($command =~ /^RECALL MILITARY SUPPORT (.*)$/)
563 {
564 1 my $supporter = $nation;
565 1 my $supported = $self->get_nation($1);
566 1 $self->stop_military_support($supporter, $supported);
567 }
568 elsif($command =~ /^AID INSURGENTS IN (.*)$/)
569 {
570 8 my $victim = $self->get_nation($1);
571 8 $self->aid_insurgents($nation, $victim);
572 }
573 elsif($command =~ /^TREATY (.*) WITH (.*)$/)
574 {
575 2 my $nation2 = $self->get_nation($2);
576 2 $self->stipulate_treaty($nation, $nation2, $1);
577 }
578 elsif($command =~ /^ECONOMIC AID FOR (.*)$/)
579 {
580 1 my $nation2 = $self->get_nation($1);
581 1 $self->economic_aid($nation, $nation2);
582 }
583 elsif($command =~ /^REBEL MILITARY SUPPORT (.*)$/)
584 {
585 1 my $nation2 = $self->get_nation($1);
586 1 my $rebsup = $self->rebel_supported($nation2->name);
587 1 ▶ if($rebsup && $rebsup->node1 ne $nation->name)
Branch: 1 branch
BranchTrueFalseTotal
if ($rebsup and $rebsup->node1 ne $nation->name) { } 0 1 1
Condition33%1/3
$rebsup and $rebsup->node1 ne $nation->name
!ll&&!rl&&r
100
MC/DC0%0/2
$rebsup and $rebsup->node1 ne $nation->name
$rebsup $rebsup->node1 ne $nation->name
Truth table33%1/3
A and B
A= $rebsupB= $rebsup->node1 ne $nation->name
ABresult
0X0
100
111
588 {
589 0 $self->broadcast_event("REBEL SUPPORT IN " . $nation2->name . " IMPOSSIBLE FOR " . $nation->name, $nation->name, $nation2->name);
590 }
591 else
592 {
593 1 $self->start_rebel_military_support($nation, $nation2);
594 }
595 }
596 elsif($command =~ /^DIPLOMATIC PRESSURE ON (.*)$/)
597 {
598 9 my $n2 = $1;
599 9 ▶ if($nation->prestige >= DIPLOMATIC_PRESSURE_PRESTIGE_COST)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation->prestige >= 6) 9 0 9
600 {
601 9 my $under_infl = $self->is_under_influence($n2);
602 9 ▶ $under_infl ||= "";
Condition50%1/2
$under_infl ||= ""
l!l
09
MC/DC0%0/1
$under_infl ||= ""
$under_infl
Truth table50%1/2
A
A= $under_infl
Aresult
11
00
603 9 ▶ if($under_infl ne $nation->name)
Branch: 1 branch
BranchTrueFalseTotal
if ($under_infl ne $nation->name) { } 9 0 9
604 {
605 9 $self->diplomatic_pressure($nation->name, $n2);
606 }
607 else
608 {
609 0 $self->broadcast_event("DIPLOMATIC PRESSURE ON $n2 BY " . $nation->name . " IMPOSSIBLE! $n2 IS UNDER INFLUENCE OF " . $nation->name, $nation->name, $n2);
610 }
611 }
612 }
613 elsif($command =~ /^RECALL REBEL MILITARY SUPPORT (.*)$/)
614 {
615 1 my $supported = $self->get_nation($1);
616 1 $self->stop_rebel_military_support($nation, $supported);
617 }
618 elsif($command =~ /^MILITARY AID FOR (.*)$/)
619 {
620 3 my $nation2 = $self->get_nation($1);
621 3 $self->military_aid($nation, $nation2);
622 }
623 elsif($command =~ /^PROGRESS$/)
624 {
625 5 $nation->grow();
626 5 $self->broadcast_event("INVESTMENT IN PROGRESS FOR " . $nation->name, $nation->name);
627 }
628 70 $self->set_statistics_value($nation, 'order', $command);
629 }
630 40 $self->empty_control_orders();
631 40 $self->manage_route_adding(@route_adders);
632 }
633 sub empty_control_orders
634 {
635 40 ▶ my $self = shift;
Subroutine empty_control_orders: called CC=2 SCAR=6.9
Pod undocumented
636 40 foreach my $p (@{$self->players})
637 {
638 5 $p->empty_control_orders();
639 }
640 }
641  
642 sub manage_route_adding
643 {
644 40 ▶ my $self = shift;
Subroutine manage_route_adding: called CC=10 SCAR=23.0
Pod undocumented
645 40 my @route_adders = @_;
646 40 ▶ if(@route_adders > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@route_adders > 1) 3 37 40
647 {
648 3 @route_adders = $self->shuffle("Route adders", @route_adders);
649 3 my $done = 0;
650 3 ▶ while(! $done)
Branch: 1 branch
BranchTrueFalseTotal
if (not $done) 5 3 8
651 {
652 5 my $node1 = shift @route_adders;
653 5 ▶ if($self->suitable_route_creator($node1))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->suitable_route_creator($node1)) { } 5 0 5
654 {
655 5 ▶ if(@route_adders == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@route_adders == 0) { } 2 3 5
656 {
657 2 $self->send_event("TRADEROUTE CREATION FAILED FOR LACK OF PARTNERS", $node1);
658 2 $done = 1;
659 }
660 else
661 {
662 3 my $complete = 0;
663 3 foreach my $second (@route_adders)
664 {
665 4 ▶ if($self->suitable_new_route($node1, $second))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->suitable_new_route($node1, $second)) 2 2 4
666 {
667 2 @route_adders = grep { $_ ne $second } @route_adders;
668 2 $self->generate_traderoute($node1, $second, 1);
669 2 $complete = 1;
670 }
671 4 ▶ last if $complete;
Branch: 1 branch
BranchTrueFalseTotal
if $complete 2 2 4
672 }
673 3 ▶ if($complete == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($complete == 0) 1 2 3
674 {
675 1 $self->send_event("TRADEROUTE CREATION FAILED FOR LACK OF PARTNERS", $node1);
676 }
677 }
678 }
679 else
680 {
681 0 $self->broadcast_event("TRADEROUTE CREATION NOT POSSIBLE FOR $node1", $node1);
682 }
683 5 ▶ $done = 1 if(@route_adders == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @route_adders == 0 3 2 5
684 }
685 }
686 }
687 sub decisions
688 {
689 16 ▶ my $self = shift;
Subroutine decisions: called CC=3 SCAR=11.0
Pod undocumented
690 16 my @decisions = ();
691 16 foreach my $nation (@{$self->nations})
692 {
693 60 my $decision;
694 60 $decision = $nation->decision($self);
695 60 ▶ if($decision)
Branch: 1 branch
BranchTrueFalseTotal
if ($decision) 44 16 60
696 {
697 44 push @decisions, $decision;
698 }
699 }
700 16 $self->ia_orders(\@decisions);
701 }
702 sub control
703 {
704 174 ▶ my $self = shift;
Subroutine control: called CC=7 SCAR=19.7
Pod undocumented
705 174 my $nation = shift;
706 174 my $quote = -1;
707 174 my $winner = undef;
708 174 my @losers = ();
709 174 my $winner_command;
710 174 foreach my $player (@{$self->players})
711 {
712 25 my $player_command = $player->get_control_order($nation);
713 25 ▶ if($player_command)
Branch: 1 branch
BranchTrueFalseTotal
if ($player_command) 1 24 25
714 {
715 1 $player->add_influence(-1 * INFLUENCE_COST, $nation);
716 1 ▶ if($player->stocks($nation) > $quote)
Branch: 1 branch
BranchTrueFalseTotal
if ($player->stocks($nation) > $quote) { } 1 0 1
717 {
718 1 ▶ if($winner)
Branch: 1 branch
BranchTrueFalseTotal
if ($winner) 0 1 1
719 {
720 0 push @losers, $winner;
721 }
722 1 $winner = $player;
723 1 $quote = $player->stocks($nation);
724 1 $winner_command = $player_command;
725 }
726 else
727 {
728 0 push @losers, $player;
729 }
730 }
731 }
732 174 ▶ if($winner)
Branch: 1 branch
BranchTrueFalseTotal
if ($winner) { } 1 173 174
733 {
734 1 $winner->register_event("ORDER FOR $nation IS EXECUTED: $winner_command");
735 1 for(@losers)
736 {
737 0 $_->register_event("ORDER FOR $nation NOT EXECUTED! " . $winner->name . " MORE POWERFUL");
738 }
739 1 return $winner_command;
740 }
741 else
742 {
743 173 return undef;
744 }
745 }
746  
747 # DECISIONS END ###########################################################
748  
749 # ECONOMY #################################################################
750  
751 # Calculate internal wealth converting domestic production to wealth
752 # Active trade routes one by one trying to generate wealth from each of them
753 # Convert remain as generating internal wealth
754 sub economy
755 {
756 40 ▶ my $self = shift;
Subroutine economy: called CC=5 SCAR=16.1
Pod undocumented
757 40 foreach my $n (@{$self->nations})
758 {
759 174 $n->calculate_internal_wealth();
760 174 $n->calculate_trading($self);
761 174 $n->convert_remains();
762 174 ▶ if($self->at_war($n->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->at_war($n->name)) 20 154 174
763 {
764 20 $n->war_cost();
765 }
766 174 ▶ if($self->at_civil_war($n->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->at_civil_war($n->name)) 13 161 174
767 {
768 13 $n->civil_war_cost();
769 }
770  
771 174 my $wealth = $n->wealth;
772 174 my $pu = PRODUCTION_UNITS->[$n->size];
773 174 my $prod = $self->get_statistics_value($self->current_year, $n->name, 'production');
774  
775 174 $self->set_statistics_value($n, 'wealth', $n->wealth);
776 174 $self->set_statistics_value($n, 'w/d', int(($wealth / $pu) * 100) / 100);
777 174 ▶ if($prod != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($prod != 0) { } 174 0 174
778 {
779 174 $self->set_statistics_value($n, 'growth', int(($wealth / $prod) * 100) / 100 );
780 }
781 else
782 {
783 0 $self->set_statistics_value($n, 'growth', 'X' );
784 }
785 }
786 }
787 sub economic_aid
788 {
789 1 ▶ my $self = shift;
Subroutine economic_aid: called CC=1 SCAR=0.0
Pod undocumented
790 1 my $nation1 = shift;
791 1 my $nation2 = shift;
792 1 $nation1->subtract_production('export', ECONOMIC_AID_COST);
793 1 $nation2->receive_aid($nation1->name);
794 1 $self->broadcast_event("ECONOMIC AID FROM " . $nation1->name . " TO " . $nation2->name, $nation1->name, $nation2->name);
795 1 $self->change_diplomacy($nation1->name, $nation2->name, ECONOMIC_AID_DIPLOMACY_FACTOR);
796  
797 }
798  
799 # ECONOMY END #############################################################
800  
801 # INTERNAL DISORDER #######################################################
802  
803 sub internal_conflict
804 {
805 40 ▶ my $self = shift;
Subroutine internal_conflict: called CC=6 SCAR=18.7
Pod undocumented
806 40 foreach my $n (@{$self->nations})
807 {
808 174 my $present_status = $n->internal_disorder_status;
809  
810 174 $n->calculate_disorder($self);
811
812 174 my $winner = $n->fight_civil_war($self);
813 174 ▶ if($winner && $winner eq 'rebels')
Branch: 2 branches
BranchTrueFalseTotal
if ($winner and $winner eq 'rebels') { } 1 173 174
elsif ($winner and $winner eq 'government') { } 0 346 346
Condition66%2/3
$winner and $winner eq "rebels"
!ll&&!rl&&r
17301
MC/DC50%1/2
$winner and $winner eq "rebels"
$winner $winner eq "rebels"
Truth table66%2/3
A and B
A= $winnerB= $winner eq "rebels"
ABresult
0X0
100
111
814 {
815 1 $n->win_civil_war('rebels', $self);
816 1 $n->new_government($self);
817 }
818 ▶ elsif($winner && $winner eq 'government')
Condition33%1/3
$winner and $winner eq "government"
!ll&&!rl&&r
17300
MC/DC0%0/2
$winner and $winner eq "government"
$winner $winner eq "government"
Truth table33%1/3
A and B
A= $winnerB= $winner eq "government"
ABresult
0X0
100
111
819 {
820 0 $n->win_civil_war('government', $self);
821 }
822
823 174 $self->set_statistics_value($n, 'internal disorder', $n->internal_disorder);
824 }
825 }
826  
827 sub aid_insurgents
828 {
829 8 ▶ my $self = shift;
Subroutine aid_insurgents: called CC=3 SCAR=11.4
Pod undocumented
830 8 my $nation1 = shift;
831 8 my $nation2 = shift;
832 8 ▶ if($nation1->production_for_export >= AID_INSURGENTS_COST && $nation2->internal_disorder_status ne 'Civil war')
Branch: 1 branch
BranchTrueFalseTotal
if ($nation1->production_for_export >= 25 and $nation2->internal_disorder_status ne "Civil war") 8 0 8
Condition33%1/3
$nation1->production_for_export >= 25 and $nation2->internal_disorder_status ne "Civil war"
!ll&&!rl&&r
008
MC/DC0%0/2
$nation1->production_for_export >= 25 and $nation2->internal_disorder_status ne "Civil war"
$nation1->production_for_export >= 25 $nation2->internal_disorder_status ne "Civil war"
Truth table33%1/3
A and B
A= $nation1->production_for_export >= 25B= $nation2->internal_disorder_status ne "Civil war"
ABresult
0X0
100
111
833 {
834 8 $self->broadcast_event("AIDS FOR INSURGENTS OF " . $nation2->name . " FROM " . $nation1->name, $nation1->name, $nation2->name);
835 8 $nation1->subtract_production('export', AID_INSURGENTS_COST);
836 8 $nation2->add_internal_disorder(INSURGENTS_AID, $self);
837 }
838 }
839  
840 sub at_civil_war
841 {
842 426 ▶ my $self = shift;
Subroutine at_civil_war: called CC=1 SCAR=0.0
Pod undocumented
843 426 my $n = shift;
844 426 my $nation = $self->get_nation($n);
845 426 return $nation->internal_disorder_status eq 'Civil war';
846 }
847  
848 sub start_civil_war
849 {
850 2 ▶ my $self = shift;
Subroutine start_civil_war: called CC=1 SCAR=0.0
Pod undocumented
851 2 my $nation = shift;
852 2 $self->broadcast_event("CIVIL WAR OUTBREAK IN " . $nation->name, $nation->name);
853 2 $nation->rebel_provinces(STARTING_REBEL_PROVINCES->[$nation->size]);
854 2 $self->war_report("Civil war in " . $nation->name . "!", $nation->name);
855 2 $self->lose_war($nation->name, 1);
856 }
857  
858 # INTERNAL DISORDER END ######################################################
859  
860 # WAR ######################################################################
861  
862 sub warfare
863 {
864 40 ▶ my $self = shift;
Subroutine warfare: called CC=2 SCAR=6.9
Pod undocumented
865 40 $self->fight_wars();
866 40 foreach my $n (@{$self->nations})
867 {
868 174 $self->set_statistics_value($n, 'army', $n->army);
869 }
870 }
871  
872 sub military_aid
873 {
874 3 ▶ my $self = shift;
Subroutine military_aid: called CC=1 SCAR=0.0
Pod undocumented
875 3 my $nation1 = shift;
876 3 my $nation2 = shift;
877 3 $nation1->subtract_production('export', MILITARY_AID_COST);
878 3 $nation2->add_army(ARMY_UNIT);
879 3 $self->broadcast_event("MILITARY AID FROM " . $nation1->name . " TO " . $nation2->name, $nation1->name, $nation2->name);
880 3 $self->change_diplomacy($nation1->name, $nation2->name, MILITARY_AID_DIPLOMACY_FACTOR);
881 }
882  
883 sub war_report
884 {
885 9 ▶ my $self = shift;
Subroutine war_report: called CC=2 SCAR=6.9
Pod undocumented
886 9 my $message = shift;
887 9 my $nation = shift;
888 9 my @wars = $self->get_wars($nation);
889 9 for(@wars)
890 {
891 1 $_->register_event($message);
892 }
893 }
894  
895  
896 # WAR END ##################################################################
897  
898 # TREATIES #################################################################
899  
900 sub stipulate_treaty
901 {
902 2 ▶ my $self = shift;
Subroutine stipulate_treaty: called CC=12 SCAR=36.6
Pod undocumented
903 2 my $nation1 = shift;
904 2 my $nation2 = shift;
905 2 my $type = shift;
906 2 my $present_treaty = $self->exists_treaty($nation1->name, $nation2->name);
907 2 my $diplomatic_status = $self->diplomacy_status($nation1->name, $nation2->name);
908 2 ▶ if($diplomatic_status eq 'HATE')
Branch: 1 branch
BranchTrueFalseTotal
if ($diplomatic_status eq "HATE") 0 2 2
909 {
910 0 $self->broadcast_event("TREATY BETWEEN " . $nation1->name . " AND " . $nation2->name . " NOT POSSIBLE BECAUSE OF HATE", $nation1->name, $nation2->name);
911 0 return;
912 }
913 2 ▶ if($self->get_treaties_for_nation($nation1->name) >= $nation1->treaty_limit ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_treaties_for_nation($nation1->name) >= $nation1->treaty_limit or $self->get_treaties_for_nation($nation2->name) >= $nation2->treaty_limit) 0 2 2
Condition33%1/3
$self->get_treaties_for_nation($nation1->name) >= $nation1->treaty_limit or $self->get_treaties_for_nation($nation2->name) >= $nation2->treaty_limit
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->get_treaties_for_nation($nation1->name) >= $nation1->treaty_limit or $self->get_treaties_for_nation($nation2->name) >= $nation2->treaty_limit
$self->get_treaties_for_nation($nation1->name) >= $nation1->treaty_limit $self->get_treaties_for_nation($nation2->name) >= $nation2->treaty_limit
Truth table33%1/3
A or B
A= $self->get_treaties_for_nation($nation1->name) >= $nation1->treaty_limitB= $self->get_treaties_for_nation($nation2->name) >= $nation2->treaty_limit
ABresult
1X1
011
000
914 $self->get_treaties_for_nation($nation2->name) >= $nation2->treaty_limit)
915 {
916 0 $self->broadcast_event("TREATY BETWEEN " . $nation1->name . " AND " . $nation2->name . " NOT POSSIBLE BECAUSE ONE NATION HAS ALREADY REACHED MAXIMUM ALLOWED TREATIES", $nation1->name, $nation2->name);
917 0 return;
918 }
919 2 ▶ if($nation1->prestige >= TREATY_PRESTIGE_COST)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation1->prestige >= 7) 2 0 2
920 {
921 2 ▶ if($type eq 'COM')
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'COM') { } 2 0 2
elsif ($type eq 'NAG') { } 0 0 0
922 {
923 2 ▶ if(! $present_treaty)
Branch: 1 branch
BranchTrueFalseTotal
if (not $present_treaty) 2 0 2
924 {
925 2 ▶ if($self->route_exists($nation1->name, $nation2->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->route_exists($nation1->name, $nation2->name)) { } 2 0 2
926 {
927 2 $self->create_treaty($nation1->name, $nation2->name, 'commercial');
928 2 $self->broadcast_event("COMMERCIAL TREATY BETWEEN " . $nation1->name . " AND " . $nation2->name, $nation1->name, $nation2->name);
929 }
930 else
931 {
932 0 $self->broadcast_event("COMMERCIAL TREATY BETWEEN " . $nation1->name . " AND " . $nation2->name . " MADE USELESS BY ROUTE CANCELATION", $nation1->name, $nation2->name);
933 }
934 }
935 }
936 elsif($type eq 'NAG')
937 {
938 0 ▶ if(! $present_treaty)
Branch: 1 branch
BranchTrueFalseTotal
if (not $present_treaty) 0 0 0
939 {
940 0 $self->create_treaty($nation1->name, $nation2->name, 'no aggression');
941 0 $self->broadcast_event("NO AGGRESSION TREATY BETWEEN " . $nation1->name . " AND " . $nation2->name, $nation1->name, $nation2->name);
942 }
943 }
944 else
945 {
946 0 ▶ if($present_treaty && $present_treaty->type ne 'alliance')
Branch: 1 branch
BranchTrueFalseTotal
if ($present_treaty and $present_treaty->type ne "alliance") 0 0 0
Condition0%0/3
$present_treaty and $present_treaty->type ne "alliance"
!ll&&!rl&&r
000
MC/DC0%0/2
$present_treaty and $present_treaty->type ne "alliance"
$present_treaty $present_treaty->type ne "alliance"
Truth table0%0/3
A and B
A= $present_treatyB= $present_treaty->type ne "alliance"
ABresult
0X0
100
111
947 {
948 0 $self->create_treaty($nation1->name, $nation2->name, 'alliance');
949 0 $self->broadcast_event("ALLIANCE BETWEEN " . $nation1->name . " AND " . $nation2->name, $nation1->name, $nation2->name);
950 }
951 }
952 }
953  
954  
955 }
956  
957  
958  
959 # TRATIES END ##############################################################
960  
961 sub register_global_data
962 {
963 40 ▶ my $self = shift;
Subroutine register_global_data: called CC=1 SCAR=0.0
Pod undocumented
964 40 my $crises = $self->get_all_crises();
965 40 my $wars = $self->wars->all();
966 40 $self->set_statistics_value(undef, 'crises', $crises);
967 40 $self->set_statistics_value(undef, 'wars', $wars);
968 }
969  
970 sub collect_events
971 {
972 40 ▶ my $self = shift;
Subroutine collect_events: called CC=4 SCAR=13.9
Pod undocumented
973 40 my @events_to_collect = ("DISORDER LOWERED TO",
974 "INTERNAL DISORDER LEVEL FROM",
975 "THE GOVERNMENT WON THE CIVIL WAR",
976 "THE REBELS WON THE CIVIL WAR",
977 "NEW GOVERNMENT CREATED",
978 "TRADEROUTE CREATION FAILED FOR LACK OF PARTNERS");
979 40 foreach my $n (@{$self->nations})
980 {
981 174 my @collected = ();
982 174 foreach my $e (@events_to_collect)
983 {
984 1044 push @collected, $n->get_events($e, $self->current_year);
985 }
986 174 foreach my $c (@collected)
987 {
988 20 $self->register_event($n->name . ": ". $c);
989 }
990 174 $self->set_statistics_value($n, 'progress', $n->progress);
991 }
992 }
993  
994 ### Commands
995  
996 sub build_commands
997 {
998 2 ▶ my $self = shift;
Subroutine build_commands: called CC=1 SCAR=0.0
Pod undocumented
999 2 my $commands = BalanceOfPower::Commands->new( world => $self, log_name => 'bop-commands.log', log_active => $self->log_active );
1000 2 return $commands;
1001 }
1002  
1003 11 1;
« blib/lib/BalanceOfPower/Relations/Role/Relation.pm ↑ Summary blib/lib/BalanceOfPower/Relations/Influence.pm »