lib/BalanceOfPower/Nation/Role/IA.pm

filter: Statementstmt 21.2% 20 / 94 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 7 totaltotal 13.9% 26 / 187 CC 31 SCAR 50.8
CC
31
Cov
13%
good_prey
342.0
decision
72.0
accept_military_support
30.0
CRAP 161.2
« blib/lib/BalanceOfPower/World.pm ↑ Summary blib/lib/BalanceOfPower/Commands/NagTreaty.pm »
1 package BalanceOfPower::Nation::Role::IA;
2 11 $BalanceOfPower::Nation::Role::IA::VERSION = '0.300010';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Array::Utils qw(intersect);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use BalanceOfPower::Utils qw( prev_turn );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 has executive => (
12 is => 'rw',
13 handles => { decide => 'decide' }
14
15 );
16  
17 sub decision
18 {
19 0 ▶ my $self = shift;
Subroutine decision: not called CC=8 SCAR=42.8
Pod undocumented
20 0 my $world = shift;
21 0 my @advisors;
22 0 ▶ if($world->at_war($self->name) || $world->at_civil_war($self->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->at_war($self->name) or $world->at_civil_war($self->name)) { } 0 0 0
Condition0%0/3
$world->at_war($self->name) or $world->at_civil_war($self->name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$world->at_war($self->name) or $world->at_civil_war($self->name)
$world->at_war($self->name) $world->at_civil_war($self->name)
Truth table0%0/3
A or B
A= $world->at_war($self->name)B= $world->at_civil_war($self->name)
ABresult
1X1
011
000
23 {
24 0 @advisors = ('military');
25 }
26 else
27 {
28 0 @advisors = ('domestic', 'economy', 'military');
29 }
30 0 @advisors = $world->shuffle("Choosing advisor for ".$self->name, @advisors);
31 0 foreach my $a (@advisors)
32 {
33 0 my $decision = undef;
34 0 ▶ if($a eq 'domestic')
Branch: 3 branches
BranchTrueFalseTotal
if ($a eq 'domestic') { } 0 0 0
elsif ($a eq 'economy') { } 0 0 0
elsif ($a eq 'military') { } 0 0 0
35 {
36 0 $decision = $self->domestic_advisor();
37 }
38 elsif($a eq 'economy')
39 {
40 0 $decision = $self->economy_advisor();
41 }
42 elsif($a eq 'military')
43 {
44 0 $decision = $self->military_advisor();
45 }
46 0 ▶ return $self->name . ": " . $decision if($decision);
Branch: 1 branch
BranchTrueFalseTotal
if $decision 0 0 0
47 }
48 0 return undef;
49 }
50  
51 sub advisor
52 {
53 0 ▶ my $self = shift;
Subroutine advisor: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my @orders = @_;
55 0 my $order = undef;
56 0 for(@orders)
57 {
58 0 $order = $self->decide($_);
59 0 ▶ return $order if $order;
Branch: 1 branch
BranchTrueFalseTotal
if $order 0 0 0
60 }
61 0 return undef;
62 }
63  
64 sub domestic_advisor
65 {
66 0 ▶ my $self = shift;
Subroutine domestic_advisor: not called CC=1 SCAR=6.9
Pod undocumented
67 0 return $self->advisor("LOWER DISORDER",
68 "BOOST PRODUCTION",
69 "TREATY NAG WITH",
70 "DIPLOMATIC PRESSURE ON",
71 "MILITARY AID FOR",
72 "PROGRESS");
73 }
74  
75 sub economy_advisor
76 {
77 0 ▶ my $self = shift;
Subroutine economy_advisor: not called CC=1 SCAR=6.9
Pod undocumented
78 0 return $self->advisor("TREATY COM WITH",
79 "DELETE TRADEROUTE",
80 "ADD ROUTE",
81 "ECONOMIC AID");
82 }
83  
84 sub military_advisor
85 {
86 0 ▶ my $self = shift;
Subroutine military_advisor: not called CC=1 SCAR=6.9
Pod undocumented
87 0 return $self->advisor("DECLARE WAR TO",
88 "AID INSURGENTS IN",
89 "MILITARY SUPPORT",
90 "REBEL MILITARY SUPPORT",
91 "RECALL MILITARY SUPPORT",
92 "BUILD TROOPS");
93 }
94 sub accept_military_support
95 {
96 0 ▶ my $self = shift;
Subroutine accept_military_support: not called CC=5 SCAR=34.0
Pod undocumented
97 0 my $other = shift;
98 0 my $world = shift;
99 0 ▶ if($world->already_in_military_support($self->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->already_in_military_support($self->name)) 0 0 0
100 {
101 0 my $supd = $world->supported($self->name);
102 0 ▶ if($supd && $supd->node1 eq $other)
Branch: 1 branch
BranchTrueFalseTotal
if ($supd and $supd->node1 eq $other) { } 0 0 0
Condition0%0/3
$supd and $supd->node1 eq $other
!ll&&!rl&&r
000
MC/DC0%0/2
$supd and $supd->node1 eq $other
$supd $supd->node1 eq $other
Truth table0%0/3
A and B
A= $supdB= $supd->node1 eq $other
ABresult
0X0
100
111
103 {
104 0 return 1;
105 }
106 else
107 {
108 0 return 0;
109 }
110 }
111 0 ▶ return 0 if($world->diplomacy_status($self->name, $other) eq 'HATE');
Branch: 1 branch
BranchTrueFalseTotal
if $world->diplomacy_status($self->name, $other) eq "HATE" 0 0 0
112 0 return $self->army < ARMY_TO_ACCEPT_MILITARY_SUPPORT;
113 }
114  
115 sub good_prey
116 {
117 0 ▶ my $self = shift;
Subroutine good_prey: not called CC=18 SCAR=58.3
Pod undocumented
118 0 my $enemy = shift;
119 0 my $world = shift;
120  
121 0 my $crisis = $world->crisis_exists($self->name, $enemy->name);
122 0 ▶ my $level = $crisis ? $crisis->get_crisis_level : ALLY_CONFLICT_LEVEL_FOR_INVOLVEMENT;
Branch: 1 branch
BranchTrueFalseTotal
$crisis ? : 0 0 0
123  
124 0 ▶ if($self->army < MIN_ARMY_FOR_WAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->army < 5) 0 0 0
125 {
126 0 return 0;
127 }
128 0 my $war_points = 0;
129  
130 #ARMY EVALUATION
131 0 my $army_ratio;
132 0 ▶ if($enemy->army > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($enemy->army > 0) { } 0 0 0
133 {
134 0 $army_ratio = int($self->army / $enemy->army);
135 }
136 else
137 {
138 0 $army_ratio = 3;
139 }
140 0 ▶ if($army_ratio < 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($army_ratio < 1) 0 0 0
141 {
142 0 my $reverse_army_ratio = $enemy->army / $self->army;
143 0 ▶ if($reverse_army_ratio > MIN_INFERIOR_ARMY_RATIO_FOR_WAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse_army_ratio > 1.2) { } 0 0 0
144 {
145 0 return 0;
146 }
147 else
148 {
149 0 $army_ratio = -1;
150 }
151 }
152 0 $war_points += $army_ratio;
153  
154 #INTERNAL EVALUATION
155 0 ▶ if($self->internal_disorder_status eq 'Peace')
Branch: 3 branches
BranchTrueFalseTotal
if ($self->internal_disorder_status eq 'Peace') { } 0 0 0
elsif ($self->internal_disorder_status eq 'Terrorism') { } 0 0 0
elsif ($self->internal_disorder_status eq 'Insurgence') { } 0 0 0
156 {
157 0 $war_points += 1;
158 }
159 elsif($self->internal_disorder_status eq 'Terrorism')
160 {
161 0 $war_points += 0;
162 }
163 elsif($self->internal_disorder_status eq 'Insurgence')
164 {
165 0 $war_points += -1;
166 }
167  
168 #WEALTH EVALUATION/PROGRES EVALUATION
169 0 my $wealth = $world->get_statistics_value(prev_turn($self->current_year), $self->name, 'wealth');
170 0 my $enemy_wealth = $world->get_statistics_value(prev_turn($self->current_year), $enemy->name, 'wealth');
171 0 my $progress_delta = $enemy->progress - $self->progress;
172 0 ▶ if($wealth && $enemy_wealth)
Branch: 1 branch
BranchTrueFalseTotal
if ($wealth and $enemy_wealth) { } 0 0 0
Condition0%0/3
$wealth and $enemy_wealth
!ll&&!rl&&r
000
MC/DC0%0/2
$wealth and $enemy_wealth
$wealth $enemy_wealth
Truth table0%0/3
A and B
A= $wealthB= $enemy_wealth
ABresult
0X0
100
111
173 {
174 0 ▶ if($enemy_wealth > $wealth)
Branch: 1 branch
BranchTrueFalseTotal
if ($enemy_wealth > $wealth) { } 0 0 0
175 {
176 0 $war_points += 1
177 }
178 else
179 {
180 0 ▶ if($progress_delta > 0 && $progress_delta < MAX_AFFORDABLE_PROGRESS)
Branch: 1 branch
BranchTrueFalseTotal
if ($progress_delta > 0 and $progress_delta < "0.8") 0 0 0
Condition0%0/3
$progress_delta > 0 and $progress_delta < "0.8"
!ll&&!rl&&r
000
MC/DC0%0/2
$progress_delta > 0 and $progress_delta < "0.8"
$progress_delta > 0 $progress_delta < "0.8"
Truth table0%0/3
A and B
A= $progress_delta > 0B= $progress_delta < "0.8"
ABresult
0X0
100
111
181 {
182 0 $war_points += 1
183 }
184
185 }
186 }
187 else
188 {
189 0 $war_points += 1;
190 }
191  
192
193 #COALITION EVALUATION
194 0 ▶ if($world->empire($self->name) && $world->empire($enemy->name) && $world->empire($self->name) > $world->empire($enemy->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($world->empire($self->name) and $world->empire($enemy->name) and $world->empire($self->name) > $world->empire($enemy->name)) 0 0 0
Condition0%0/6
$world->empire($self->name) and $world->empire($enemy->name) and $world->empire($self->name) > $world->empire($enemy->name)
!ll&&!rl&&r
000
$world->empire($self->name) and $world->empire($enemy->name)
!ll&&!rl&&r
000
MC/DC0%0/3
$world->empire($self->name) and $world->empire($enemy->name) and $world->empire($self->name) > $world->empire($enemy->name)
$world->empire($self->name) $world->empire($enemy->name) $world->empire($self->name) > $world->empire($enemy->name)
Truth table0%0/4
A and B and C
A= $world->empire($self->name)B= $world->empire($enemy->name)C= $world->empire($self->name) > $world->empire($enemy->name)
ABCresult
0XX0
10X0
1100
1111
195 {
196 0 $war_points += 1;
197 }
198 0 ▶ if($war_points + $level >= 4)
Branch: 1 branch
BranchTrueFalseTotal
if ($war_points + $level >= 4) { } 0 0 0
199 {
200 0 return 1;
201 }
202 else
203 {
204 0 return 0;
205 }
206 }
207  
208 11 1;
209  
« blib/lib/BalanceOfPower/World.pm ↑ Summary blib/lib/BalanceOfPower/Commands/NagTreaty.pm »