blib/lib/BalanceOfPower/Commands/DeclareWar.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 53 CC 3 SCAR 13.3
CC
3
Cov
0%
get_available_targets
6.0
IA
6.0
BEGIN
2.0
CRAP 3.8
1 package BalanceOfPower::Commands::DeclareWar;
2 $BalanceOfPower::Commands::DeclareWar::VERSION = '0.300010';
3 use v5.10;
4 use Moo;
5  
6 use Array::Utils qw(intersect);
7  
8 use BalanceOfPower::Constants ":all";
9 use BalanceOfPower::Utils qw( prev_turn );
10  
11 extends 'BalanceOfPower::Commands::InMilitaryRange';
12  
13 sub get_available_targets
14 {
15 my $self = shift;
16 my @targets = $self->SUPER::get_available_targets();
17 my @out = ();
18 for(@targets)
19 {
20 my $t = $_;
21 if((! $self->world->is_under_influence($t) || $self->world->is_under_influence($t) ne $self->actor) &&
22 ! $self->world->war_busy($t))
23 {
24 push @out, $t;
25 }
26 }
27 return @out;
28 }
29  
30  
31 sub IA
32 {
33 my $self = shift;
34 my $actor = $self->get_nation();
35 my @choose = $self->world->shuffle("Choosing someone to declare war to for ". $actor->name , $self->get_available_targets());
36 for(@choose)
37 {
38 my $enemy = $self->world->get_nation($_);
39 if($actor->good_prey($enemy, $self->world))
40 {
41 return "DECLARE WAR TO " . $enemy->name;
42 }
43 }
44 return undef;
45 }
46  
47 1;