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.400105';
3 13     13   41 use Moo;
  13         14  
  13         53  
4              
5 13     13   2344 use BalanceOfPower::Constants ':all';
  13         15  
  13         7244  
6              
7             extends 'BalanceOfPower::Commands::NoArgs';
8              
9             sub allowed
10             {
11 15     15 0 16 my $self = shift;
12 15         63 my $nation = $self->world->get_nation($self->actor);
13 15         48 my $other_checks = $self->SUPER::allowed();
14 15 100       32 if($other_checks)
15             {
16 12         31 my $export_cost = $nation->build_troops_cost();
17 12         33 return $nation->production_for_export >= $export_cost;
18             }
19             else
20             {
21 3         5 return 0;
22             }
23             }
24              
25             sub IA
26             {
27 12     12 0 11 my $self = shift;
28 12         26 my $actor = $self->get_nation();
29 12 100       48 if($actor->army < MAX_ARMY_FOR_SIZE->[ $actor->size ])
30             {
31 11 100       32 if($actor->army < MINIMUM_ARMY_LIMIT)
    50          
32             {
33 10         15 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         5 return undef;
51             }
52              
53             1;