lib/BalanceOfPower/Commands/MilitarySupport.pm

filter: Statementstmt 88.2% 30 / 34 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 78.4% 40 / 51 CC 8 SCAR 19.6
CC
8
Cov
80%
IA
10.1
BEGIN
1.0
BEGIN
1.0
CRAP 7.1
« lib/BalanceOfPower/Commands/RecallRebelMilitarySupport.pm ↑ Summary blib/lib/BalanceOfPower/Commands/AddRoute.pm »
1 package BalanceOfPower::Commands::MilitarySupport;
2 11 $BalanceOfPower::Commands::MilitarySupport::VERSION = '0.200000';
3 11 ▶use BalanceOfPower::Constants ":all";
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Array::Utils qw(intersect);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 extends 'BalanceOfPower::Commands::TargetNation';
8  
9 sub get_available_targets
10 {
11 1 ▶ my $self = shift;
Subroutine get_available_targets: called CC=1 SCAR=0.0
Pod undocumented
12 1 my $player = $self->actor;
13 1 return grep { $self->world->get_nation($_)->accept_military_support($player, $self->world) } $self->world->get_friends($player);
14 }
15  
16 sub IA
17 {
18 2 ▶ my $self = shift;
Subroutine IA: called CC=8 SCAR=23.2
Pod undocumented
19 2 my $actor = $self->get_nation();
20 2 ▶ return undef if($actor->army < ARMY_TO_GIVE_MILITARY_SUPPORT);
Branch: 1 branch
BranchTrueFalseTotal
if $actor->army < 6 1 1 2
21  
22 1 my @crises = $self->world->get_crises($actor->name);
23 1 my @friends = $self->world->shuffle("Choosing friend to support for " . $actor->name, $self->world->get_friends($actor->name));
24 1 my @targets = $self->get_available_targets();
25 1 @friends = $self->world->shuffle("Mixing friends for military support for " . $actor->name, intersect(@friends, @targets));
26 1 ▶ if(@crises > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@crises > 0) 1 0 1
27 {
28 1 foreach my $c ($self->world->shuffle("Mixing crisis for war for " . $actor->name, @crises))
29 {
30 1 my $enemy = $self->world->get_nation($c->destination($actor->name));
31 1 ▶ next if $self->world->war_busy($enemy->name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->world->war_busy($enemy->name) 0 1 1
32 1 for(@friends)
33 {
34 1 ▶ if($self->world->border_exists($_, $enemy->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->world->border_exists($_, $enemy->name)) 1 0 1
35 {
36 1 return "MILITARY SUPPORT " . $_;
37 }
38 }
39 }
40 }
41 0 ▶ if(@friends)
Branch: 1 branch
BranchTrueFalseTotal
if (@friends) 0 0 0
42 {
43 0 my $f = $friends[0];
44 0 return "MILITARY SUPPORT " . $f;
45 }
46 0 return undef;
47 }
48  
49 11 1;
« lib/BalanceOfPower/Commands/RecallRebelMilitarySupport.pm ↑ Summary blib/lib/BalanceOfPower/Commands/AddRoute.pm »