File Coverage

lib/BalanceOfPower/Commands/BuildTroops.pm
Criterion Covered Total %
statement 20 23 86.9
branch 8 12 66.6
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 32 41 78.0


line stmt bran cond sub pod time code
1             package BalanceOfPower::Commands::BuildTroops;
2             $BalanceOfPower::Commands::BuildTroops::VERSION = '0.400110';
3 13     13   44 use Moo;
  13         14  
  13         51  
4              
5 13     13   2385 use BalanceOfPower::Constants ':all';
  13         16  
  13         7487  
6              
7             extends 'BalanceOfPower::Commands::NoArgs';
8              
9             sub allowed
10             {
11 20     20 0 21 my $self = shift;
12 20         72 my $nation = $self->world->get_nation($self->actor);
13 20         49 my $other_checks = $self->SUPER::allowed();
14 20 100       34 if($other_checks)
15             {
16 15         31 my $export_cost = $nation->build_troops_cost();
17 15         45 return $nation->production_for_export >= $export_cost;
18             }
19             else
20             {
21 5         9 return 0;
22             }
23             }
24              
25             sub IA
26             {
27 15     15 0 15 my $self = shift;
28 15         31 my $actor = $self->get_nation();
29 15 100       55 if($actor->army < MAX_ARMY_FOR_SIZE->[ $actor->size ])
30             {
31 14 100       32 if($actor->army < MINIMUM_ARMY_LIMIT)
    50          
32             {
33 13         23 return "BUILD TROOPS";
34             }
35             elsif($actor->army < MEDIUM_ARMY_LIMIT)
36             {
37 0 0       0 if($actor->production_for_export > MEDIUM_ARMY_BUDGET)
38             {
39 0         0 return "BUILD TROOPS";
40             }
41             }
42             else
43             {
44 1 50       4 if($actor->production_for_export > MAX_ARMY_BUDGET)
45             {
46 0         0 return "BUILD TROOPS";
47             }
48             }
49             }
50 2         4 return undef;
51             }
52              
53             1;