File Coverage

lib/BalanceOfPower/Commands/DeclareWar.pm
Criterion Covered Total %
statement 30 30 100.0
branch 3 4 75.0
condition 2 6 33.3
subroutine 7 7 100.0
pod 0 2 0.0
total 42 49 85.7


line stmt bran cond sub pod time code
1             package BalanceOfPower::Commands::DeclareWar;
2             $BalanceOfPower::Commands::DeclareWar::VERSION = '0.400110';
3 13     13   94 use v5.10;
  13         28  
4 13     13   37 use Moo;
  13         15  
  13         1296  
5              
6 13     13   2311 use Array::Utils qw(intersect);
  13         19  
  13         494  
7              
8 13     13   44 use BalanceOfPower::Constants ":all";
  13         13  
  13         5435  
9 13     13   56 use BalanceOfPower::Utils qw( prev_turn );
  13         14  
  13         2506  
10              
11             extends 'BalanceOfPower::Commands::InMilitaryRange';
12              
13             sub get_available_targets
14             {
15 24     24 0 17 my $self = shift;
16 24         62 my @targets = $self->SUPER::get_available_targets();
17 24         29 my @out = ();
18 24         30 for(@targets)
19             {
20 7         6 my $t = $_;
21 7 50 33     22 if((! $self->world->is_under_influence($t) || $self->world->is_under_influence($t) ne $self->actor) &&
      33        
22             ! $self->world->war_busy($t))
23             {
24 7         25 push @out, $t;
25             }
26             }
27 24         361 return @out;
28             }
29              
30              
31             sub IA
32             {
33 24     24 0 26 my $self = shift;
34 24         43 my $actor = $self->get_nation();
35 24         83 my @choose = $self->world->shuffle("Choosing someone to declare war to for ". $actor->name , $self->get_available_targets());
36 24         50 for(@choose)
37             {
38 7         29 my $enemy = $self->world->get_nation($_);
39 7 100       31 if($actor->good_prey($enemy, $self->world))
40             {
41 1         6 return "DECLARE WAR TO " . $enemy->name;
42             }
43             }
44 23         48 return undef;
45             }
46              
47             1;