lib/BalanceOfPower/Role/Analyst.pm

filter: Statementstmt 20.8% 40 / 192 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 40.0% 8 / 20 Podpod 0.0% 0 / 12 totaltotal 16.8% 48 / 285 CC 34 SCAR 32.6
CC
34
Cov
16%
print_near_analysis
72.0
print_nation_actual_situation
42.0
print_market
30.0
CRAP 26.0
« lib/BalanceOfPower/Relations/Friendship.pm ↑ Summary blib/lib/BalanceOfPower/Commands/InMilitaryRange.pm »
1 package BalanceOfPower::Role::Analyst;
2 11 $BalanceOfPower::Role::Analyst::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 Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use BalanceOfPower::Utils qw( prev_turn as_title as_title as_subtitle compare_turns);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use BalanceOfPower::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 11 requires 'diplomacy_exists';
14 11 requires 'get_borders';
15 11 requires 'supported';
16 11 requires 'exists_military_support';
17 11 requires 'near_nations';
18 11 requires 'routes_for_node';
19 11 requires 'get_allies';
20 11 requires 'get_crises';
21 11 requires 'get_wars';
22 11 requires 'print_nation_situation';
23 11 requires 'print_nation_statistics_header';
24 11 requires 'print_nation_statistics_line';
25 11 requires 'get_player';
26 11 requires 'print_all_crises';
27 11 requires 'print_wars';
28  
29 sub print_nation_actual_situation
30 {
31 0 ▶ my $self = shift;
Subroutine print_nation_actual_situation: not called CC=6 SCAR=37.4
Pod undocumented
32 0 my $nation = shift;
33 0 my $in_the_middle = shift;
34 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
35 0 my $attributes_names = ["Size", "Prod.", "Wealth", "W/D", "Growth", "Disor.", "Army", "Prog.", "Pstg."];
36 0 my $attributes = ["production", "wealth", "w/d", "growth", "internal disorder", "army", "progress", "prestige"];
37  
38 0 my $turn;
39 0 ▶ if($in_the_middle)
Branch: 1 branch
BranchTrueFalseTotal
if ($in_the_middle) { } 0 0 0
40 {
41 0 $turn = prev_turn($self->current_year);
42 }
43 else
44 {
45 0 $turn = $self->current_year;
46 }
47 0 my $nation_obj = $self->get_nation($nation);
48 0 my $under_influence = $self->is_under_influence($nation);
49 0 my @influence = $self->has_influence($nation);
50 0 my @ndata = $self->get_nation_statistics_line($nation, $turn, $attributes);
51 0 my @routes = $self->routes_for_node($nation);
52 0 my @treaties = $self->get_treaties_for_nation($nation);
53 0 my @supports = $self->supports($nation);
54 0 my @rebel_supports = $self->rebel_supports($nation);
55 0 my $first_row_height;
56 0 ▶ if(@treaties > @supports + @rebel_supports)
Branch: 1 branch
BranchTrueFalseTotal
if (@treaties > @supports + @rebel_supports) { } 0 0 0
57 {
58 0 $first_row_height = @treaties;
59 }
60 else
61 {
62 0 $first_row_height = @supports + @rebel_supports;
63 }
64 0 my @crises = $self->get_crises($nation);
65 0 my @wars = $self->get_wars($nation);
66 0 my $second_row_height;
67 0 ▶ if(@crises > @wars)
Branch: 1 branch
BranchTrueFalseTotal
if (@crises > @wars) { } 0 0 0
68 {
69 0 $second_row_height = @crises;
70 }
71 else
72 {
73 0 $second_row_height = @wars;
74 }
75 0 ▶ my $latest_order = $self->get_statistics_value($turn, $nation, 'order') ? $self->get_statistics_value($turn, $nation, 'order') : 'NONE';
Branch: 1 branch
BranchTrueFalseTotal
$self->get_statistics_value($turn, $nation, 'order') ? : 0 0 0
76 0 return BalanceOfPower::Printer::print($mode, $self, 'print_actual_nation_situation',
77 { nation => $nation_obj,
78 under_influence => $under_influence,
79 influence => \@influence,
80 attributes => $attributes_names,
81 nationstats => \@ndata,
82 traderoutes => \@routes,
83 treaties => \@treaties,
84 supports => \@supports,
85 rebel_supports => \@rebel_supports,
86 first_row_height => $first_row_height,
87 crises => \@crises,
88 wars => \@wars,
89 second_row_height => $second_row_height,
90 latest_order => $latest_order,
91 } );
92 }
93  
94 sub print_borders_analysis
95 {
96 0 ▶ my $self = shift;
Subroutine print_borders_analysis: not called CC=4 SCAR=30.0
Pod undocumented
97 0 my $nation = shift;
98 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
99 0 my @borders = $self->near_nations($nation, 1);
100 0 my %data;
101  
102 0 foreach my $b (@borders)
103 {
104 0 my $rel = $self->diplomacy_exists($nation, $b);
105 0 $data{$b}->{'relation'} = $rel;
106  
107 0 my $supps = $self->supported($b);
108 0 ▶ if($supps)
Branch: 1 branch
BranchTrueFalseTotal
if ($supps) 0 0 0
109 {
110 0 my $supporter = $supps->start($b);
111 0 $data{$b}->{'support'}->{nation} = $supporter;
112 0 my $sup_rel = $self->diplomacy_exists($nation, $supporter);
113 0 $data{$b}->{'support'}->{relation} = $sup_rel;
114 }
115 }
116 0 return BalanceOfPower::Printer::print($mode, $self, 'print_borders_analysis',
117 { nation => $nation,
118 borders => \%data } );
119  
120 }
121 sub print_near_analysis
122 {
123 0 ▶ my $self = shift;
Subroutine print_near_analysis: not called CC=8 SCAR=42.8
Pod undocumented
124 0 my $nation = shift;
125 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
126 0 my @data = ();
127 0 my @near = $self->near_nations($nation, 0);
128 0 foreach my $b (@near)
129 {
130 0 my $rel = $self->diplomacy_exists($nation, $b);
131 0 ▶ if(! $self->border_exists($nation, $b))
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->border_exists($nation, $b)) { } 0 0 0
132 {
133 0 ▶ if($self->exists_military_support($nation, $b))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exists_military_support($nation, $b)) { } 0 0 0
134 {
135 0 push @data, { nation => $b,
136 relation => $rel,
137 how => 'supported' };
138 }
139 else
140 {
141 0 my @foreign_borders = $self->get_borders($b);
142 0 foreach my $fb (@foreign_borders)
143 {
144 0 my $other_n = $fb->destination($b);
145 0 my $sups = $self->supported($other_n);
146 0 ▶ if($sups)
Branch: 1 branch
BranchTrueFalseTotal
if ($sups) 0 0 0
147 {
148 0 ▶ if($sups->start($other_n) eq $nation)
Branch: 1 branch
BranchTrueFalseTotal
if ($sups->start($other_n) eq $nation) 0 0 0
149 {
150 0 push @data, { nation => $b,
151 relation => $rel,
152 how => $other_n };
153 }
154 }
155 }
156 }
157 }
158 else
159 {
160 0 push @data, { nation => $b,
161 relation => $rel,
162 how => "border" };
163 }
164 }
165 0 BalanceOfPower::Printer::print($mode, $self, 'print_near_analysis',
166 { nation => $nation,
167 near => \@data } );
168  
169 }
170 sub print_hotspots
171 {
172 0 ▶ my $self = shift;
Subroutine print_hotspots: not called CC=2 SCAR=17.9
Pod undocumented
173 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
174 0 my $out = "";
175 0 $out .= $self->print_all_crises(undef, 1, $mode);
176 0 $out .= $self->print_wars(undef, $mode);
177 0 return $out;
178 }
179  
180 sub print_civil_war_report
181 {
182 0 ▶ my $self = shift;
Subroutine print_civil_war_report: not called CC=4 SCAR=30.0
Pod undocumented
183 0 my $nation = shift;
184 0 ▶ if (! $self->at_civil_war($nation))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->at_civil_war($nation)) 0 0 0
185 {
186 0 return "$nation is not fightinh civil war";
187 }
188 0 my $out = "";
189 0 my $nation_obj = $self->get_nation($nation);
190 0 $out .= "Rebel provinces: " . $nation_obj->rebel_provinces . "/" . PRODUCTION_UNITS->[$nation_obj->size] . "\n";
191 0 $out .= "Army: " . $nation_obj->army . "\n";
192 0 my $sup = $self->supported($nation);
193 0 my $rebsup = $self->rebel_supported($nation);
194 0 ▶ $out .= "Support: " . $sup->print . "\n" if($sup);
Branch: 1 branch
BranchTrueFalseTotal
if $sup 0 0 0
195 0 ▶ $out .= "Rebel support: " . $rebsup->print . "\n" if ($rebsup);
Branch: 1 branch
BranchTrueFalseTotal
if $rebsup 0 0 0
196 0 return $out;
197 }
198  
199 sub print_war_history
200 {
201 0 ▶ my $self = shift;
Subroutine print_war_history: not called CC=4 SCAR=30.0
Pod undocumented
202 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
203 0 my %wars;
204 my @war_names;
205 0 foreach my $w (@{$self->memorial})
206 {
207 0 ▶ if(exists $wars{$w->war_id})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $wars{$w->war_id}) { } 0 0 0
208 {
209 0 push @{$wars{$w->war_id}}, $w;
210 }
211 else
212 {
213 0 $wars{$w->war_id} = [ $w ];
214 0 push @war_names, { name => $w->war_id,
215 start => $w->start_date };
216 }
217 }
218 sub comp
219 {
220 0 ▶ compare_turns($a->{start}, $b->{start});
Subroutine comp: not called CC=1 SCAR=6.9
Pod undocumented
221 }
222 0 @war_names = sort comp @war_names;
223 0 return BalanceOfPower::Printer::print($mode, $self, 'print_war_history',
224 { wars => \%wars,
225 war_names => \@war_names } );
226 }
227 sub print_treaties_table
228 {
229 0 ▶ my $self = shift;
Subroutine print_treaties_table: not called CC=2 SCAR=17.9
Pod undocumented
230 0 my $out = sprintf "%-20s %-6s %-5s %-5s %-5s", "Nation", "LIMIT", "ALL", "NAG", "COM";
231 0 $out .= "\n";
232 0 my @nations = @{$self->nation_names};
233 0 for(@nations)
234 {
235 0 my $n = $_;
236 0 my $limit = $self->get_nation($n)->treaty_limit;
237 0 my $alls = $self->get_treaties_for_nation_by_type($n, 'alliance');
238 0 my $coms = $self->get_treaties_for_nation_by_type($n, 'commercial');
239 0 my $nags = $self->get_treaties_for_nation_by_type($n, 'no aggression');
240 0 $out .= sprintf "%-20s %-6s %-5s %-5s %-5s", $n, $limit, $alls, $nags, $coms;
241 0 $out .= "\n";
242 }
243 0 return $out;
244 }
245 sub player_stocks_status
246 {
247 0 ▶ my $self = shift;
Subroutine player_stocks_status: not called CC=4 SCAR=30.0
Pod undocumented
248 0 my $player = shift;
249 0 my $player_obj = $self->get_player($player);
250 0 my $stock_value = 0;
251 0 my %market_data = ();
252 0 foreach my $nation(keys %{$player_obj->wallet})
253 {
254 0 ▶ if( $player_obj->stocks($nation) > 0 || $player_obj->influence($nation) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($player_obj->stocks($nation) > 0 or $player_obj->influence($nation) > 0) 0 0 0
Condition0%0/3
$player_obj->stocks($nation) > 0 or $player_obj->influence($nation) > 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$player_obj->stocks($nation) > 0 or $player_obj->influence($nation) > 0
$player_obj->stocks($nation) > 0 $player_obj->influence($nation) > 0
Truth table0%0/3
A or B
A= $player_obj->stocks($nation) > 0B= $player_obj->influence($nation) > 0
ABresult
1X1
011
000
255 {
256 $market_data{$nation} = { 'stocks' => $player_obj->wallet->{$nation}->{stocks},
257 'value' => $self->get_statistics_value(prev_turn($self->current_year), $nation, "w/d"),
258 'influence' => $player_obj->wallet->{$nation}->{influence},
259 0 'war_bonds' => $player_obj->wallet->{$nation}->{'war_bonds'},
260 };
261 0 $stock_value += $player_obj->wallet->{$nation}->{stocks} * $self->get_statistics_value(prev_turn($self->current_year), $nation, "w/d");
262 }
263 }
264 0 my $total_value = $stock_value + $player_obj->money;
265 0 return { market_data => \%market_data,
266 stock_value => $stock_value,
267 money => $player_obj->money,
268 total_value => $total_value };
269 }
270  
271  
272 sub print_stocks
273 {
274 0 ▶ my $self = shift;
Subroutine print_stocks: not called CC=2 SCAR=17.9
Pod undocumented
275 0 my $player = shift;
276 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
277 0 return BalanceOfPower::Printer::print($mode, $self, 'print_stocks', $self->player_stocks_status($player));
278 }
279 sub print_all_stocks
280 {
281 0 ▶ my $self = shift;
Subroutine print_all_stocks: not called CC=3 SCAR=24.8
Pod undocumented
282 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
283 0 my %data = ();
284 0 my @names;
285 0 for(@{$self->players})
286 {
287 0 my $p = $_;
288 0 push @names, $p->name;
289 0 $data{$p->name} = $self->player_stocks_status($p->name);
290 }
291 0 @names = sort { $data{$b}->{total_value} <=> $data{$a}->{total_value} } @names;
292  
293 0 return BalanceOfPower::Printer::print($mode, $self, 'print_ranking',
294 { players_data => \%data,
295 players => \@names });
296 }
297 sub print_market
298 {
299 0 ▶ my $self = shift;
Subroutine print_market: not called CC=5 SCAR=34.0
Pod undocumented
300 0 ▶ my $mode = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
301 0 my @ordered = $self->order_statistics(prev_turn($self->current_year), 'w/d');
302 0 my %data = ();
303 0 my @nations = ();
304 0 foreach my $stats (@ordered)
305 {
306 0 my $nation = $self->get_nation($stats->{nation});
307 0 push @nations, $stats->{nation};
308 0 my $status = "";
309 0 ▶ if($self->at_war($nation->name))
Branch: 2 branches
BranchTrueFalseTotal
if ($self->at_war($nation->name)) { } 0 0 0
elsif ($self->at_civil_war($nation->name)) { } 0 0 0
310 {
311 0 $status = "WAR";
312 }
313 elsif($self->at_civil_war($nation->name))
314 {
315 0 $status = "CIVILW";
316 }
317 $data{$nation->name} = { stocks => $nation->available_stocks,
318 wd => $stats->{value},
319 0 status => $status };
320 }
321 0 return BalanceOfPower::Printer::print($mode, $self, 'print_market',
322 { market_data => \%data,
323 nations => \@nations } );
324 }
325 11 1;
« lib/BalanceOfPower/Relations/Friendship.pm ↑ Summary blib/lib/BalanceOfPower/Commands/InMilitaryRange.pm »