lib/BalanceOfPower/Role/Supporter.pm

filter: Statementstmt 19.4% 21 / 108 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 27.7% 5 / 18 Podpod 0.0% 0 / 9 totaltotal 15.2% 26 / 171 CC 17 SCAR 26.2
CC
17
Cov
15%
start_military_support
30.0
start_rebel_military_support
30.0
print_supports
20.0
CRAP 13.8
« lib/BalanceOfPower/Commands/RebelMilitarySupport.pm ↑ Summary blib/lib/BalanceOfPower/Role/Ruler.pm »
1 package BalanceOfPower::Role::Supporter;
2 11 $BalanceOfPower::Role::Supporter::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  
7 11 ▶use BalanceOfPower::Relations::MilitarySupport;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 requires 'get_nation';
11 11 requires 'at_civil_war';
12 11 requires 'war_report';
13  
14 has military_supports => (
15 is => 'ro',
16 0 ▶ default => sub { BalanceOfPower::Relations::RelPack->new() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 11 handles => { add_military_support => 'add_link',
18 delete_military_support => 'delete_link',
19 exists_military_support => 'exists_link',
20 already_in_military_support => 'first_link_for_node',
21 supports => 'links_for_node',
22 supporter => 'links_for_node1',
23 supported => 'first_link_for_node2',
24 reset_supports => 'delete_link_for_node'
25 }
26 );
27 has rebel_military_supports => (
28 is => 'ro',
29 0 ▶ default => sub { BalanceOfPower::Relations::RelPack->new() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 11 handles => { add_rebel_military_support => 'add_link',
31 delete_rebel_military_support => 'delete_link',
32 exists_rebel_military_support => 'exists_link',
33 rebel_supports => 'links_for_node',
34 rebel_supporter => 'links_for_node1',
35 rebel_supported => 'first_link_for_node2',
36 reset_rebel_supports => 'delete_link_for_node'
37 }
38 );
39  
40 sub start_military_support
41 {
42 0 ▶ my $self = shift;
Subroutine start_military_support: not called CC=5 SCAR=34.0
Pod undocumented
43 0 my $nation1 = shift;
44 0 my $nation2 = shift;
45 0 ▶ return 0 if($nation1->army < ARMY_FOR_SUPPORT);
Branch: 1 branch
BranchTrueFalseTotal
if $nation1->army < 4 0 0 0
46 0 my $precedent_sup = $self->exists_military_support($nation1->name, $nation2->name);
47 0 ▶ if($precedent_sup)
Branch: 1 branch
BranchTrueFalseTotal
if ($precedent_sup) 0 0 0
48 {
49 0 $precedent_sup->casualities(-1 * ARMY_FOR_SUPPORT);
50 0 $self->broadcast_event("MILITARY SUPPORT TO " . $nation2->name . " INCREASED BY " . $nation1->name, $nation1->name, $nation2->name);
51 0 $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_INCREASING_SUPPORT);
52 0 return 1;
53 }
54 0 ▶ if($self->supported($nation2->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->supported($nation2->name)) 0 0 0
55 {
56 0 $self->broadcast_event($nation2->name . " ALREADY SUPPORTED. MILITARY SUPPORT IMPOSSIBILE FOR " . $nation1->name, $nation1->name, $nation2->name);
57 0 return 0;
58 }
59 0 my $supported = $self->supported($nation1->name);
60 0 ▶ if($supported)
Branch: 1 branch
BranchTrueFalseTotal
if ($supported) 0 0 0
61 {
62 0 $self->stop_military_support($self->get_nation($supported->node1), $self->get_nation($supported->node2));
63 }
64 0 $nation1->add_army(-1 * ARMY_FOR_SUPPORT);
65 0 $self->add_military_support(
66 BalanceOfPower::Relations::MilitarySupport->new(
67 node1 => $nation1->name,
68 node2 => $nation2->name,
69 army => ARMY_FOR_SUPPORT));
70 0 $self->broadcast_event("MILITARY SUPPORT TO " . $nation2->name . " STARTED BY " . $nation1->name, $nation1->name, $nation2->name);
71 0 $self->war_report($nation1->name . " started military support for " . $nation2->name, $nation2->name);
72 0 $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_STARTING_SUPPORT);
73 }
74 sub start_rebel_military_support
75 {
76 0 ▶ my $self = shift;
Subroutine start_rebel_military_support: not called CC=5 SCAR=34.0
Pod undocumented
77 0 my $nation1 = shift;
78 0 my $nation2 = shift;
79 0 ▶ return 0 if($nation1->army < REBEL_ARMY_FOR_SUPPORT);
Branch: 1 branch
BranchTrueFalseTotal
if $nation1->army < 4 0 0 0
80 0 ▶ return 0 if(! $self->at_civil_war($nation2->name));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->at_civil_war($nation2->name) 0 0 0
81 0 my $precedent_sup = $self->exists_rebel_military_support($nation1->name, $nation2->name);
82 0 ▶ if($precedent_sup)
Branch: 1 branch
BranchTrueFalseTotal
if ($precedent_sup) 0 0 0
83 {
84 0 $precedent_sup->casualities(-1 * ARMY_FOR_SUPPORT);
85 0 $self->broadcast_event("REBEL MILITARY SUPPORT AGAINST " . $nation2->name . " INCREASED BY " . $nation1->name, $nation1->name, $nation2->name);
86 0 $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_INCREASING_REBEL_SUPPORT);
87 0 return 1;
88 }
89 0 ▶ if($self->rebel_supported($nation2->name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rebel_supported($nation2->name)) 0 0 0
90 {
91 0 $self->broadcast_event("REBELS IN " . $nation2->name . " ALREADY SUPPORTED. REBEL MILITARY SUPPORT IMPOSSIBILE FOR " . $nation1->name, $nation1->name, $nation2->name);
92 0 return 0;
93 }
94 0 $nation1->add_army(-1 * ARMY_FOR_SUPPORT);
95 0 $self->add_rebel_military_support(
96 BalanceOfPower::Relations::MilitarySupport->new(
97 node1 => $nation1->name,
98 node2 => $nation2->name,
99 army => ARMY_FOR_SUPPORT));
100 0 $self->broadcast_event("REBEL MILITARY SUPPORT AGAINST " . $nation2->name . " STARTED BY " . $nation1->name, $nation1->name, $nation2->name);
101 0 $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_STARTING_REBEL_SUPPORT);
102 }
103 sub stop_military_support
104 {
105 0 ▶ my $self = shift;
Subroutine stop_military_support: not called CC=3 SCAR=24.8
Pod undocumented
106 0 my $node1 = shift;
107 0 my $node2 = shift;
108 0 my $avoid_diplomacy = shift;
109 0 my $milsup = $self->exists_military_support($node1->name, $node2->name);
110 0 ▶ return if (! $milsup);
Branch: 1 branch
BranchTrueFalseTotal
unless $milsup 0 0 0
111 0 $self->delete_military_support($node1->name, $node2->name);
112 0 $node1->add_army($milsup->army);
113 0 $self->broadcast_event("MILITARY SUPPORT FOR " . $node2->name . " STOPPED BY " . $node1->name, $node1->name, $node2->name);
114 0 $self->war_report($node1->name . " stopped military support for " . $node2->name, $node2->name);
115 0 ▶ if(! $avoid_diplomacy)
Branch: 1 branch
BranchTrueFalseTotal
if (not $avoid_diplomacy) 0 0 0
116 {
117 0 $self->change_diplomacy($node1->name, $node2->name, -1 * DIPLOMACY_FACTOR_BREAKING_SUPPORT);
118 }
119 }
120 sub stop_rebel_military_support
121 {
122 0 ▶ my $self = shift;
Subroutine stop_rebel_military_support: not called CC=2 SCAR=17.9
Pod undocumented
123 0 my $node1 = shift;
124 0 my $node2 = shift;
125 0 my $milsup = $self->exists_rebel_military_support($node1->name, $node2->name);
126 0 ▶ return if (! $milsup);
Branch: 1 branch
BranchTrueFalseTotal
unless $milsup 0 0 0
127 0 $self->delete_rebel_military_support($node1->name, $node2->name);
128 0 $node1->add_army($milsup->army);
129 0 $self->broadcast_event("REBEL MILITARY SUPPORT AGAINST " . $node2->name . " STOPPED BY " . $node1->name, $node1->name, $node2->name);
130 }
131 sub military_support_garbage_collector
132 {
133 0 ▶ my $self = shift;
Subroutine military_support_garbage_collector: not called CC=1 SCAR=6.9
Pod undocumented
134 0 ▶ $self->military_supports->garbage_collector(sub { my $rel = shift; return $rel->army <= 0 });
Subroutine __ANON__: not called CC=1 SCAR=6.9
135 }
136 sub rebel_military_support_garbage_collector
137 {
138 0 ▶ my $self = shift;
Subroutine rebel_military_support_garbage_collector: not called CC=1 SCAR=6.9
Pod undocumented
139 0 ▶ $self->rebel_military_supports->garbage_collector(sub { my $rel = shift; return $rel->army <= 0 });
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 }
141  
142 sub print_military_supports
143 {
144 0 ▶ my $self = shift;
Subroutine print_military_supports: not called CC=2 SCAR=17.9
Pod undocumented
145 0 my $n = shift;
146 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
147 0 return $self->print_supports($n, "MILITARY SUPPORTS", 0, $mode);
148 }
149 sub print_rebel_military_supports
150 {
151 0 ▶ my $self = shift;
Subroutine print_rebel_military_supports: not called CC=2 SCAR=17.9
Pod undocumented
152 0 my $n = shift;
153 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
154 0 return $self->print_supports($n, "REBEL MILITARY SUPPORTS", 1, $mode);
155 }
156  
157  
158 sub print_supports
159 {
160 0 ▶ my $self = shift;
Subroutine print_supports: not called CC=4 SCAR=30.0
Pod undocumented
161 0 my $n = shift;
162 0 ▶ my $title = shift || "MILITARY SUPPORTS";
Condition0%0/2
shift() || 'MILITARY SUPPORTS'
l!l
00
MC/DC0%0/1
shift() || 'MILITARY SUPPORTS'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
163 0 my $rebel = shift;
164 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
165 0 my @sups;
166 0 ▶ if($rebel)
Branch: 1 branch
BranchTrueFalseTotal
if ($rebel) { } 0 0 0
167 {
168 0 @sups = $self->rebel_military_supports->links_for_node($n);
169 }
170 else
171 {
172 0 @sups = $self->military_supports->links_for_node($n);
173 }
174 0 return BalanceOfPower::Printer::print($mode, $self, 'print_supports',
175 { title => $title,
176 supports => \@sups,
177 } );
178  
179 }
180 11 1;
« lib/BalanceOfPower/Commands/RebelMilitarySupport.pm ↑ Summary blib/lib/BalanceOfPower/Role/Ruler.pm »