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.400115';
3 13     13   51 use Moo;
  13         17  
  13         81  
4              
5 13     13   2901 use BalanceOfPower::Constants ':all';
  13         46  
  13         8979  
6              
7             extends 'BalanceOfPower::Commands::NoArgs';
8              
9             sub allowed
10             {
11 22     22 0 38 my $self = shift;
12 22         109 my $nation = $self->world->get_nation($self->actor);
13 22         87 my $other_checks = $self->SUPER::allowed();
14 22 100       88 if($other_checks)
15             {
16 20         66 my $export_cost = $nation->build_troops_cost();
17 20         80 return $nation->production_for_export >= $export_cost;
18             }
19             else
20             {
21 2         7 return 0;
22             }
23             }
24              
25             sub IA
26             {
27 20     20 0 29 my $self = shift;
28 20         45 my $actor = $self->get_nation();
29 20 100       119 if($actor->army < MAX_ARMY_FOR_SIZE->[ $actor->size ])
30             {
31 19 100       56 if($actor->army < MINIMUM_ARMY_LIMIT)
    50          
32             {
33 18         38 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       6 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;