lib/BalanceOfPower/Nation.pm

filter: Statementstmt 12.1% 37 / 304 Branchbran 0.0% 0 / 96 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 14.2% 5 / 35 Podpod 0.0% 0 / 30 totaltotal 8.6% 42 / 485 CC 57 SCAR 37.8
CC
57
Cov
9%
fight_civil_war
182.0
win_civil_war
56.0
production
42.0
CRAP 43.7
« lib/BalanceOfPower/Commands/MilitarySupport.pm ↑ Summary lib/BalanceOfPower/Commands/NoArgs.pm »
1 package BalanceOfPower::Nation;
2 11 $BalanceOfPower::Nation::VERSION = '0.300010';
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  
8 11 ▶use BalanceOfPower::Utils qw( prev_turn );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 with 'BalanceOfPower::Role::Reporter';
12 11 with 'BalanceOfPower::Nation::Role::IA';
13 11 with 'BalanceOfPower::Nation::Role::Shareholder';
14  
15 11 has name => (
16 is => 'ro',
17 default => 'Dummyland'
18 );
19 11 has code => (
20 is => 'ro',
21 default => 'DUM'
22 );
23 11 has area => (
24 is => 'ro',
25 default => 'Neverwhere'
26 );
27  
28  
29 11 has export_quote => (
30 is => 'ro',
31 default => 50
32 );
33 11 has government => (
34 is => 'ro',
35 default => 'democracy'
36 );
37 11 has government_strength => (
38 is => 'rw',
39 default => 70
40 );
41 11 has size => (
42 is => 'ro',
43 default => 1
44 );
45  
46 11 has internal_disorder => (
47 is => 'rw',
48 default => 0
49 );
50 11 has production_for_domestic => (
51 is => 'rw',
52 default => 0
53 );
54 11 has production_for_export => (
55 is => 'rw',
56 default => 0
57 );
58 11 has prestige => (
59 is => 'rw',
60 default => 0
61 );
62 11 has wealth => (
63 is => 'rw',
64 default => 0
65 );
66 11 has debt => (
67 is => 'rw',
68 default => 0
69 );
70 11 has rebel_provinces => (
71 is => 'rw',
72 default => 0
73 );
74 11 has current_year => (
75 is => 'rw'
76 );
77  
78 11 has army => (
79 default => 0,
80 is => 'rw'
81 );
82  
83 11 has progress => (
84 default => 0,
85 is => 'rw'
86 );
87  
88 11 has frozen_disorder => (
89 default => 0,
90 is => 'rw'
91 );
92  
93 sub production
94 {
95 0 ▶ my $self = shift;
Subroutine production: not called CC=6 SCAR=37.4
Pod undocumented
96 0 my $prod = shift;
97 0 ▶ if($prod)
Branch: 1 branch
BranchTrueFalseTotal
if ($prod) 0 0 0
98 {
99 0 ▶ if($prod <= DEBT_TO_RAISE_LIMIT && $self->debt < MAX_DEBT && DEBT_ALLOWED)
Branch: 1 branch
BranchTrueFalseTotal
if ($prod <= 50 and $self->debt < 3 and 0) 0 0 0
Condition0%0/5
$prod <= 50 and $self->debt < 3 and 0
!ll
00
$prod <= 50 and $self->debt < 3
!ll&&!rl&&r
000
MC/DC0%0/2
$prod <= 50 and $self->debt < 3 and 0
$prod <= 50 $self->debt < 3
Truth table0%0/3
A and B
A= $prod <= 50B= $self->debt < 3
ABresult
0X0
100
111
100 {
101 0 $prod += PRODUCTION_THROUGH_DEBT;
102 0 $self->debt($self->debt + 1);
103 0 $self->register_event("DEBT RISE");
104 }
105 0 ▶ if($self->government eq 'dictatorship')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->government eq "dictatorship") 0 0 0
106 {
107 0 $prod -= DICTATORSHIP_PRODUCTION_MALUS;
108 }
109 0 my $internal = $prod - (($self->export_quote * $prod) / 100);
110 0 my $export = $prod - $internal;
111 0 $self->production_for_domestic($internal);
112 0 $self->production_for_export($export);
113 0 $self->register_event("PRODUCTION INT: $internal EXP: $export");
114 }
115 0 return $self->production_for_domestic + $self->production_for_export;
116 }
117  
118 sub calculate_internal_wealth
119 {
120 0 ▶ my $self = shift;
Subroutine calculate_internal_wealth: not called CC=1 SCAR=6.9
Pod undocumented
121 0 my $internal_production = $self->production_for_domestic();
122 0 $self->add_wealth($internal_production * INTERNAL_PRODUCTION_GAIN);
123 0 $self->production_for_domestic(0);
124 0 $self->register_event("INTERNAL " . $internal_production);
125 }
126  
127 sub calculate_trading
128 {
129 0 ▶ my $self = shift;
Subroutine calculate_trading: not called CC=6 SCAR=37.4
Pod undocumented
130 0 my $world = shift;
131 0 my @routes = $world->routes_for_node($self->name);
132 0 my %diplomacy = $world->diplomacy_for_node($self->name);
133 0 @routes = sort { $b->factor_for_node($self->name) * 1000 + $diplomacy{$b->destination($self->name)}
134 <=>
135 0 $a->factor_for_node($self->name) * 1000 + $diplomacy{$a->destination($self->name)}
136 } @routes;
137 0 ▶ if(@routes > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@routes > 0) 0 0 0
138 {
139 0 foreach my $r (@routes)
140 {
141 0 ▶ if($self->production_for_export >= TRADING_QUOTE)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->production_for_export >= 15) { } 0 0 0
142 {
143 0 my $treaty_bonus = 0;
144 0 ▶ if($world->exists_treaty_by_type($self->name, $r->destination($self->name), 'commercial'))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->exists_treaty_by_type($self->name, $r->destination($self->name), "commercial")) 0 0 0
145 {
146 0 $treaty_bonus = TREATY_TRADE_FACTOR;
147 }
148 0 $self->trade(TRADING_QUOTE, $r->factor_for_node($self->name) + $treaty_bonus);
149 0 my $event = "TRADE OK " . $r->destination($self->name) . " [x" . $r->factor_for_node($self->name);
150 0 ▶ if($treaty_bonus > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($treaty_bonus > 0) 0 0 0
151 {
152 0 $event .= " +$treaty_bonus";
153 }
154 0 $event .= "]";
155 0 $self->register_event($event);
156 }
157 else
158 {
159 0 $self->trade(0, $r->factor_for_node($self->name));
160 0 $self->register_event("TRADE KO " . $r->destination($self->name));
161 }
162 }
163 }
164 }
165  
166 sub convert_remains
167 {
168 0 ▶ my $self = shift;
Subroutine convert_remains: not called CC=1 SCAR=6.9
Pod undocumented
169 0 $self->add_wealth($self->production);
170 0 $self->register_event("REMAIN " . $self->production);
171 0 $self->production_for_domestic(0);
172 0 $self->production_for_export(0);
173 }
174  
175 sub war_cost
176 {
177 0 ▶ my $self = shift;
Subroutine war_cost: not called CC=1 SCAR=6.9
Pod undocumented
178 0 $self->add_wealth(-1 * WAR_WEALTH_MALUS);
179 0 $self->register_event("WAR COST PAYED: " . WAR_WEALTH_MALUS);
180 }
181 sub civil_war_cost
182 {
183 0 ▶ my $self = shift;
Subroutine civil_war_cost: not called CC=1 SCAR=6.9
Pod undocumented
184 0 $self->add_wealth(-1 * CIVIL_WAR_WEALTH_MALUS);
185 0 $self->register_event("CIVIL WAR COST PAYED: " . CIVIL_WAR_WEALTH_MALUS);
186 }
187  
188 sub boost_production
189 {
190 0 ▶ my $self = shift;
Subroutine boost_production: not called CC=1 SCAR=6.9
Pod undocumented
191 0 my $boost = BOOST_PRODUCTION_QUOTE * PRODUCTION_UNITS->[$self->size];
192 0 $self->subtract_production('export', -1 * $boost);
193 0 $self->subtract_production('domestic', -1 * $boost);
194 0 $self->register_event("BOOST OF PRODUCTION");
195 }
196 sub receive_aid
197 {
198 0 ▶ my $self = shift;
Subroutine receive_aid: not called CC=1 SCAR=6.9
Pod undocumented
199 0 my $from = shift;
200 0 my $boost = ECONOMIC_AID_QUOTE * PRODUCTION_UNITS->[$self->size];
201 0 $self->subtract_production('export', -1 * $boost);
202 0 $self->subtract_production('domestic', -1 * $boost);
203 }
204  
205 sub trade
206 {
207 0 ▶ my $self = shift;
Subroutine trade: not called CC=1 SCAR=6.9
Pod undocumented
208 0 my $production = shift;
209 0 my $gain = shift;
210 0 $self->subtract_production('export', $production);
211 0 $self->add_wealth($production * $gain);
212 0 $self->add_wealth(-1 * TRADEROUTE_COST);
213 }
214  
215 sub calculate_disorder
216 {
217 0 ▶ my $self = shift;
Subroutine calculate_disorder: not called CC=4 SCAR=30.0
Pod undocumented
218 0 my $world = shift;
219 0 ▶ return if($self->internal_disorder_status eq 'Civil war');
Branch: 1 branch
BranchTrueFalseTotal
if $self->internal_disorder_status eq "Civil war" 0 0 0
220 0 ▶ return if($self->frozen_disorder);
Branch: 1 branch
BranchTrueFalseTotal
if $self->frozen_disorder 0 0 0
221  
222 0 my @ordered_best = $world->order_statistics(prev_turn($self->current_year), 'progress');
223
224 #Variables
225 0 my $wd = $self->wealth / PRODUCTION_UNITS->[$self->size];
226 0 my $d = $self->internal_disorder;
227 0 my $g = $self->government_strength;
228 0 ▶ my $prg = $ordered_best[0] ? $ordered_best[0]->{'value'} - $self->progress : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ordered_best[0] ? : 0 0 0
229  
230 #Constants
231 0 my $wd_middle = 30;
232 0 my $wd_divider = 10;
233 0 my $disorder_divider = 70;
234 0 my $government_strength_minimum = 60;
235 0 my $government_strength_divider = 40;
236 0 my $random_factor_max = 15;
237
238 0 my $disorder = ( ($wd_middle - $wd) / $wd_divider ) +
239 ( $d / $disorder_divider ) +
240 ( ($government_strength_minimum - $g) / $government_strength_divider ) +
241 $world->random_around_zero($random_factor_max, 100, "Internal disorder random factor for " . $self->name) +
242 $prg;
243  
244 0 $disorder = int ($disorder * 100) / 100;
245 0 $self->register_event("DISORDER CHANGE: " . $disorder);
246 0 $self->add_internal_disorder($disorder, $world);
247 }
248  
249 sub subtract_production
250 {
251 0 ▶ my $self = shift;
Subroutine subtract_production: not called CC=3 SCAR=24.8
Pod undocumented
252 0 my $which = shift;
253 0 my $production = shift;
254 0 ▶ if($which eq 'export')
Branch: 2 branches
BranchTrueFalseTotal
if ($which eq 'export') { } 0 0 0
elsif ($which eq 'domestic') { } 0 0 0
255 {
256 0 $self->production_for_export($self->production_for_export - $production);
257 }
258 elsif($which eq 'domestic')
259 {
260 0 $self->production_for_domestic($self->production_for_domestic - $production);
261 }
262
263 }
264  
265 sub add_wealth
266 {
267 0 ▶ my $self = shift;
Subroutine add_wealth: not called CC=2 SCAR=17.9
Pod undocumented
268 0 my $wealth = shift;
269 0 $self->wealth($self->wealth + $wealth);
270 0 ▶ $self->wealth(0) if($self->wealth < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->wealth < 0 0 0 0
271 }
272  
273 sub lower_disorder
274 {
275 0 ▶ my $self = shift;
Subroutine lower_disorder: not called CC=3 SCAR=24.8
Pod undocumented
276 0 my $world = shift;
277 0 ▶ if($world->at_civil_war($self->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->at_civil_war($self->name)) 0 0 0
278 {
279 0 return;
280 }
281 0 ▶ if($self->production_for_domestic > RESOURCES_FOR_DISORDER)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->production_for_domestic > 20) 0 0 0
282 {
283 0 $self->subtract_production('domestic', RESOURCES_FOR_DISORDER);
284 0 $self->add_internal_disorder(-1 * DISORDER_REDUCTION, $world);
285 0 $self->register_event("DISORDER LOWERED TO " . $self->internal_disorder);
286 }
287 }
288  
289 sub add_internal_disorder
290 {
291 0 ▶ my $self = shift;
Subroutine add_internal_disorder: not called CC=5 SCAR=34.0
Pod undocumented
292 0 my $disorder = shift;
293 0 my $world = shift;
294 0 my $actual_disorder = $self->internal_disorder_status;
295 0 my $new_disorder_data = $self->internal_disorder + $disorder;
296 0 $new_disorder_data = int($new_disorder_data * 100) / 100;
297 0 $self->internal_disorder($new_disorder_data);
298 0 ▶ if($self->internal_disorder > 100)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->internal_disorder > 100) 0 0 0
299 {
300 0 $self->internal_disorder(100);
301 }
302 0 ▶ if($self->internal_disorder < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->internal_disorder < 0) 0 0 0
303 {
304 0 $self->internal_disorder(0);
305 }
306 0 my $new_disorder = $self->internal_disorder_status;
307 0 ▶ if($actual_disorder ne $new_disorder)
Branch: 1 branch
BranchTrueFalseTotal
if ($actual_disorder ne $new_disorder) 0 0 0
308 {
309 0 $self->register_event("INTERNAL DISORDER LEVEL FROM $actual_disorder TO $new_disorder");
310 0 ▶ if($new_disorder eq "Civil war")
Branch: 1 branch
BranchTrueFalseTotal
if ($new_disorder eq "Civil war") 0 0 0
311 {
312 0 $world->start_civil_war($self);
313 }
314 }
315 }
316  
317 sub internal_disorder_status
318 {
319 0 ▶ my $self = shift;
Subroutine internal_disorder_status: not called CC=4 SCAR=30.0
Pod undocumented
320 0 my $disorder = $self->internal_disorder;
321 0 ▶ if($disorder < INTERNAL_DISORDER_TERRORISM_LIMIT)
Branch: 3 branches
BranchTrueFalseTotal
if ($disorder < 10) { } 0 0 0
elsif ($disorder < 40) { } 0 0 0
elsif ($disorder < 80) { } 0 0 0
322 {
323 0 return "Peace";
324 }
325 elsif($disorder < INTERNAL_DISORDER_INSURGENCE_LIMIT)
326 {
327 0 return "Terrorism";
328 }
329 elsif($disorder < INTERNAL_DISORDER_CIVIL_WAR_LIMIT)
330 {
331 0 return "Insurgence";
332 }
333 else
334 {
335 0 return "Civil war";
336 }
337 }
338  
339 sub fight_civil_war
340 {
341 0 ▶ my $self = shift;
Subroutine fight_civil_war: not called CC=13 SCAR=52.0
Pod undocumented
342 0 my $world = shift;
343 0 ▶ return undef if($self->internal_disorder_status ne 'Civil war');
Branch: 1 branch
BranchTrueFalseTotal
if $self->internal_disorder_status ne "Civil war" 0 0 0
344 0 my $government = $world->random(0, 100, "Civil war " . $self->name . ": government fight result");
345 0 my $rebels = $world->random(0, 100, "Civil war " . $self->name . ": rebels fight result");
346 0 $self->register_event("FIGHTING CIVIL WAR");
347 0 ▶ if($self->army >= ARMY_UNIT_FOR_CIVIL_WAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->army >= 2) 0 0 0
348 {
349 0 $self->add_army(-1 * ARMY_UNIT_FOR_CIVIL_WAR);
350 0 $government += ARMY_HELP_FOR_CIVIL_WAR;
351 }
352 0 ▶ if($self->government eq 'dictatorship')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->government eq "dictatorship") 0 0 0
353 {
354 0 $government += DICTATORSHIP_BONUS_FOR_CIVIL_WAR;
355 }
356 0 my $reb_sup;
357 my $sup;
358 0 ▶ if($reb_sup = $world->rebel_supported($self->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($reb_sup = $world->rebel_supported($self->name)) 0 0 0
359 {
360 0 $rebels += REBEL_SUPPORT_HELP_FOR_CIVIL_WAR;
361 }
362 0 ▶ if($sup = $world->supported($self->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($sup = $world->supported($self->name)) 0 0 0
363 {
364 0 $government += SUPPORT_HELP_FOR_CIVIL_WAR;
365 }
366 0 ▶ if($reb_sup)
Branch: 1 branch
BranchTrueFalseTotal
if ($reb_sup) 0 0 0
367 {
368 0 $world->broadcast_event("RELATIONS BETWEEN " . $self->name . " AND " . $reb_sup->node1 . " CHANGED FOR CIVIL WAR IN " . $self->name, $self->name, $reb_sup->node1);
369 0 $world->change_diplomacy($self->name, $reb_sup->node1, -1 * DIPLOMACY_MALUS_FOR_REBEL_CIVIL_WAR_SUPPORT);
370 }
371 0 ▶ if($sup && $reb_sup)
Branch: 1 branch
BranchTrueFalseTotal
if ($sup and $reb_sup) 0 0 0
Condition0%0/3
$sup and $reb_sup
!ll&&!rl&&r
000
MC/DC0%0/2
$sup and $reb_sup
$sup $reb_sup
Truth table0%0/3
A and B
A= $supB= $reb_sup
ABresult
0X0
100
111
372 {
373 0 $world->broadcast_event("RELATIONS BETWEEN " . $sup->node1 . " AND " . $reb_sup->node1 . " CHANGED FOR CIVIL WAR IN " . $self->name, $self->name, $sup->node1, $reb_sup->node1);
374 0 $world->change_diplomacy($sup->node1, $reb_sup->node1, -1 * DIPLOMACY_MALUS_FOR_CROSSED_CIVIL_WAR_SUPPORT);
375 }
376 0 ▶ if($government > $rebels)
Branch: 2 branches
BranchTrueFalseTotal
if ($government > $rebels) { } 0 0 0
elsif ($rebels > $government) { } 0 0 0
377 {
378 0 ▶ $reb_sup->casualities(1) if $reb_sup;
Branch: 1 branch
BranchTrueFalseTotal
if $reb_sup 0 0 0
379 0 $world->rebel_military_support_garbage_collector();
380 0 return $self->civil_war_battle('government');
381 }
382 elsif($rebels > $government)
383 {
384 0 ▶ $sup->casualities(1) if $sup;
Branch: 1 branch
BranchTrueFalseTotal
if $sup 0 0 0
385 0 $world->military_support_garbage_collector();
386 0 return $self->civil_war_battle('rebels');
387 }
388 else
389 {
390 0 return undef;
391 }
392 }
393  
394 sub civil_war_battle
395 {
396 0 ▶ my $self = shift;
Subroutine civil_war_battle: not called CC=5 SCAR=34.0
Pod undocumented
397 0 my $battle_winner = shift;
398 0 ▶ if($battle_winner eq 'government')
Branch: 2 branches
BranchTrueFalseTotal
if ($battle_winner eq 'government') { } 0 0 0
elsif ($battle_winner eq 'rebels') { } 0 0 0
399 {
400 0 $self->rebel_provinces($self->rebel_provinces() - .5);
401 }
402 elsif($battle_winner eq 'rebels')
403 {
404 0 $self->rebel_provinces($self->rebel_provinces() + .5);
405 }
406 0 ▶ if($self->rebel_provinces == 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->rebel_provinces == 0) { } 0 0 0
elsif ($self->rebel_provinces == [2..4]->[$self->size]) { } 0 0 0
407 {
408 0 $self->internal_disorder(AFTER_CIVIL_WAR_INTERNAL_DISORDER);
409 0 $self->register_event("THE GOVERNMENT WON THE CIVIL WAR");
410 0 return 'government';
411 }
412 elsif($self->rebel_provinces == PRODUCTION_UNITS->[$self->size])
413 {
414 0 $self->internal_disorder(AFTER_CIVIL_WAR_INTERNAL_DISORDER);
415 0 $self->register_event("THE REBELS WON THE CIVIL WAR");
416 0 $self->rebel_provinces(0);
417 0 return 'rebels';
418 }
419 0 return undef;
420 }
421  
422 sub win_civil_war
423 {
424 0 ▶ my $self = shift;
Subroutine win_civil_war: not called CC=7 SCAR=40.3
Pod undocumented
425 0 my $winner = shift;
426 0 my $world = shift;
427 0 ▶ if($winner eq 'rebels')
Branch: 2 branches
BranchTrueFalseTotal
if ($winner eq 'rebels') { } 0 0 0
elsif ($winner eq 'government') { } 0 0 0
428 {
429 0 $self->new_government($world);
430 0 my $rebsup = $world->rebel_supported($self->name);
431 0 ▶ if($rebsup)
Branch: 1 branch
BranchTrueFalseTotal
if ($rebsup) 0 0 0
432 {
433 0 my $rebel_supporter = $world->get_nation($rebsup->node1);
434 0 ▶ $world->stop_rebel_military_support($rebel_supporter, $self) if $rebel_supporter;
Branch: 1 branch
BranchTrueFalseTotal
if $rebel_supporter 0 0 0
435 0 $world->diplomacy_exists($self->name, $rebel_supporter->name)->factor(REBEL_SUPPORTER_WINNER_FRIENDSHIP);
436 0 $world->create_treaty($self->name, $rebel_supporter->name, 'alliance');
437 0 $world->broadcast_event($self->name . " AND " . $rebel_supporter->name . " ARE NOW ALLIES. " . $rebel_supporter->name . " HELPED " . $self->name . " REVOLUTION", $self->name, $rebel_supporter->name);
438 }
439 0 $world->empty_stocks($self->name);
440 0 $self->available_stocks(START_STOCKS->[$self->size]);
441 }
442 elsif($winner eq 'government')
443 {
444 0 my $rebsup = $world->rebel_supported($self->name);
445 0 ▶ if($rebsup)
Branch: 1 branch
BranchTrueFalseTotal
if ($rebsup) 0 0 0
446 {
447 0 my $rebel_supporter = $world->get_nation($rebsup->node1);
448 0 ▶ $world->stop_rebel_military_support($rebel_supporter, $self) if $rebel_supporter;
Branch: 1 branch
BranchTrueFalseTotal
if $rebel_supporter 0 0 0
449 }
450 }
451 }
452  
453 sub new_government
454 {
455 0 ▶ my $self = shift;
Subroutine new_government: not called CC=1 SCAR=6.9
Pod undocumented
456 0 my $world = shift;
457 0 $self->government_strength($world->random10(MIN_GOVERNMENT_STRENGTH, MAX_GOVERNMENT_STRENGTH, "Reroll government strength for " . $self->name));
458 0 $world->reroll_diplomacy($self->name);
459 0 $world->reset_treaties($self->name);
460 0 $world->reset_influences($self->name);
461 0 $world->reset_supports($self->name);
462 0 $world->reset_crises($self->name);
463 0 $self->register_event("NEW GOVERNMENT CREATED");
464 }
465  
466 sub occupation
467 {
468 0 ▶ my $self = shift;
Subroutine occupation: not called CC=1 SCAR=6.9
Pod undocumented
469 0 my $world = shift;
470 0 $world->reset_treaties($self->name);
471 0 $world->reset_influences($self->name);
472 0 $world->reset_supports($self->name);
473 0 $world->reset_crises($self->name);
474 }
475  
476 sub build_troops
477 {
478 0 ▶ my $self = shift;
Subroutine build_troops: not called CC=3 SCAR=24.8
Pod undocumented
479 0 my $army_cost = $self->build_troops_cost();
480
481 0 ▶ if($self->production_for_domestic > $army_cost && $self->army < MAX_ARMY_FOR_SIZE->[ $self->size ])
Branch: 1 branch
BranchTrueFalseTotal
if ($self->production_for_domestic > $army_cost and $self->army < [9,12,15]->[$self->size]) 0 0 0
Condition0%0/3
$self->production_for_domestic > $army_cost and $self->army < [9,12,15]->[$self->size]
!ll&&!rl&&r
000
MC/DC0%0/2
$self->production_for_domestic > $army_cost and $self->army < [9,12,15]->[$self->size]
$self->production_for_domestic > $army_cost $self->army < [9,12,15]->[$self->size]
Truth table0%0/3
A and B
A= $self->production_for_domestic > $army_costB= $self->army < [9,12,15]->[$self->size]
ABresult
0X0
100
111
482 {
483 0 $self->subtract_production('domestic', $army_cost);
484 0 $self->add_army(ARMY_UNIT);
485 0 $self->register_event("NEW TROOPS FOR THE ARMY");
486 }
487 }
488  
489 sub build_troops_cost
490 {
491 0 ▶ my $self = shift;
Subroutine build_troops_cost: not called CC=2 SCAR=17.9
Pod undocumented
492 0 my $army_cost = ARMY_COST;
493 0 ▶ if($self->government eq 'dictatorship')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->government eq "dictatorship") 0 0 0
494 {
495 0 $army_cost -= DICTATORSHIP_BONUS_FOR_ARMY_CONSTRUCTION;
496 }
497 0 return $army_cost;
498 }
499  
500 sub add_army
501 {
502 0 ▶ my $self = shift;
Subroutine add_army: not called CC=3 SCAR=24.8
Pod undocumented
503 0 my $army = shift;
504 0 $self->army($self->army + $army);
505 0 ▶ if($self->army > MAX_ARMY_FOR_SIZE->[ $self->size ])
Branch: 1 branch
BranchTrueFalseTotal
if ($self->army > [9,12,15]->[$self->size]) 0 0 0
506 {
507 0 $self->army(MAX_ARMY_FOR_SIZE->[ $self->size ]);
508 }
509 0 ▶ if($self->army < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->army < 0) 0 0 0
510 {
511 0 $self->army(0);
512 }
513  
514 }
515  
516 sub grow
517 {
518 0 ▶ my $self = shift;
Subroutine grow: not called CC=2 SCAR=17.9
Pod undocumented
519 0 ▶ return if($self->production_for_domestic < PROGRESS_COST);
Branch: 1 branch
BranchTrueFalseTotal
if $self->production_for_domestic < 30 0 0 0
520 0 my $new_progress = $self->progress + PROGRESS_INCREMENT;
521 0 $self->progress($new_progress);
522 0 $self->subtract_production('domestic', PROGRESS_COST);
523 0 $self->register_event("GROW. NEW PROGRESS: $new_progress");
524 }
525  
526 sub treaty_limit
527 {
528 0 ▶ my $self = shift;
Subroutine treaty_limit: not called CC=1 SCAR=6.9
Pod undocumented
529 0 my $progress_step = int($self->progress / TREATY_LIMIT_PROGRESS_STEP) + 1;
530 0 return $progress_step * TREATIES_FOR_PROGRESS_STEP;
531 }
532  
533 sub print_attributes
534 {
535 0 ▶ my $self = shift;
Subroutine print_attributes: not called CC=1 SCAR=6.9
Pod undocumented
536 0 my $out = "";
537 0 $out .= "Area: " . $self->area . "\n";
538 0 $out .= "Export quote: " . $self->export_quote . "\n";
539 0 $out .= "Government strength: " . $self->government_strength . "\n";
540 0 $out .= "Internal situation: " . $self->internal_disorder_status . "\n";
541 0 return $out;
542 }
543  
544 sub print
545 {
546 0 ▶ my $self = shift;
Subroutine print: not called CC=3 SCAR=24.8
Pod undocumented
547 0 my $out = "";
548 0 $out .= "Name: " . $self->name . "\n";
549 0 $out .= $self->print_attributes();
550 0 $out .= "Events:\n";
551 0 foreach my $year (sort keys %{$self->events})
552 {
553 0 $out .= " $year:\n";
554 0 foreach my $e (@{$self->events->{$year}})
555 {
556 0 $out .= " " . $e ."\n";
557 }
558 }
559 0 return $out;
560 }
561  
562 sub dump
563 {
564 0 ▶ my $self = shift;
Subroutine dump: not called CC=2 SCAR=17.9
Pod undocumented
565 0 my $io = shift;
566 0 ▶ my $indent = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
567 0 print {$io} $indent .
568 join(";", $self->name, $self->code, $self->area, $self->export_quote, $self->government, $self->government_strength, $self->size, $self->internal_disorder, $self->production_for_domestic, $self->production_for_export, $self->prestige, $self->wealth, $self->debt, $self->rebel_provinces, $self->current_year, $self->army, $self->progress, $self->available_stocks) . "\n";
569 0 $self->dump_events($io, " " . $indent);
570 }
571 #TODO finish this
572 sub dump_resources
573 {
574 0 ▶ my $self = shift;
Subroutine dump_resources: not called CC=1 SCAR=6.9
Pod undocumented
575 0 my %data = shift;
576 }
577  
578 sub load
579 {
580 0 ▶ my $self = shift;
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
581 0 my $data = shift;
582 0 my $nation_line = ( split /\n/, $data )[0];
583 0 $nation_line =~ s/^\s+//;
584 0 chomp $nation_line;
585 0 my ($name, $code, $area, $export_quote, $government, $government_strength, $size, $internal_disorder, $production_for_domestic, $production_for_export, $prestige, $wealth, $debt, $rebel_provinces, $current_year, $army, $progress, $available_stocks) = split ";", $nation_line;
586 0 $data =~ s/^.*?\n//;
587 0 my $events = $self->load_events($data);
588 0 return $self->new(name => $name, code => $code, area => $area, size => $size,
589 export_quote => $export_quote, government => $government, government_strength => $government_strength,
590 internal_disorder => $internal_disorder,
591 production_for_domestic => $production_for_domestic, production_for_export => $production_for_export,
592 prestige => $prestige, wealth => $wealth, debt => $debt,
593 rebel_provinces => $rebel_provinces, army => $army,
594 current_year => $current_year,
595 progress => $progress,
596 events => $events,
597 available_stocks => $available_stocks);
598 }
599  
600 11 1;
« lib/BalanceOfPower/Commands/MilitarySupport.pm ↑ Summary lib/BalanceOfPower/Commands/NoArgs.pm »