| 1 | package BalanceOfPower::Relations::Friendship; | ||||||||||||||||||||||||||||
| 2 | 11 | $BalanceOfPower::Relations::Friendship::VERSION = '0.200000'; | |||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
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 Term::ANSIColor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 11 | has factor => ( | |||||||||||||||||||||||||||
| 11 | is => 'rw' | ||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||
| 13 | 11 | has crisis_level => ( | |||||||||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||||||||||
| 15 | default => 0 | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | 11 | with 'BalanceOfPower::Relations::Role::Relation'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub get_crisis_level | ||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||
| 21 | 405 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_crisis_level: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 405 | ▶ | if($self->factor > PERMANENT_CRISIS_HATE_LIMIT) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 259 | return $self->crisis_level; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | else | ||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | 146 | ▶ | if($self->crisis_level < CRISIS_MAX_FACTOR) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 146 | return $self->crisis_level + 1; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | else | ||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 0 | return $self->crisis_level; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | sub status | ||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 894 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
status: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 894 | ▶ | if($self->factor == ALLIANCE_FRIENDSHIP_FACTOR) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 28 | return 'ALLIANCE'; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | elsif($self->factor == DOMINION_DIPLOMACY) | ||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||
| 47 | 4 | return 'INFLUENCE PRESENT'; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 862 | ▶ | if($self->factor <= HATE_LIMIT) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 318 | return 'HATE'; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | elsif($self->factor >= LOVE_LIMIT) | ||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | 241 | return 'FRIENDSHIP'; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | else | ||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 303 | return 'NEUTRAL'; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub status_color | ||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | 25 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
status_color: called CC=5 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 25 | ▶ | if($self->status eq 'ALLIANCE' || $self->status eq 'INFLUENCE PRESENT') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->status eq "ALLIANCE" or $self->status eq "INFLUENCE PRESENT"
MC/DC50%1/2
$self->status eq "ALLIANCE" or $self->status eq "INFLUENCE PRESENT"
$self->status eq "ALLIANCE"
$self->status eq "INFLUENCE PRESENT"
Truth table66%2/3
A or B
A= $self->status eq "ALLIANCE"B= $self->status eq "INFLUENCE PRESENT"
| |||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | 11 | return color("cyan bold"); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 14 | ▶ | if($self->status eq 'HATE') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | 14 | return color("red bold"); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | elsif($self->status eq 'FRIENDSHIP') | ||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 0 | return color("green bold"); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else | ||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 0 | return ""; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub print | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 8 | my $from = shift; | |||||||||||||||||||||||||||
| 88 | 8 | my $second_node; | |||||||||||||||||||||||||||
| 89 | my $out; | ||||||||||||||||||||||||||||
| 90 | 8 | ▶ | if($from) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | 8 | ▶ | if($from eq $self->node1) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||
| 94 | 4 | $second_node = $self->node2; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | elsif($from eq $self->node2) | ||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | 4 | $second_node = $self->node1; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | else | ||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | 0 | $from = $self->node1; | |||||||||||||||||||||||||||
| 104 | 0 | $second_node = $self->node2; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 8 | $out = $self->status_color . $from . " <--> " . $second_node . " [" . $self->factor . " " . $self->status . "]"; | |||||||||||||||||||||||||||
| 107 | 8 | ▶ | if($self->get_crisis_level > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 4 | $out .= " " . $self->print_crisis_bar(); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 8 | $out .= color("reset"); | |||||||||||||||||||||||||||
| 112 | 8 | return $out; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | sub print_status | ||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_status: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 117 | 6 | return $self->status_color . $self->status . color("reset"); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | sub print_crisis | ||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_crisis: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 5 | my $color = shift; | |||||||||||||||||||||||||||
| 123 | 5 | ▶ | $color = 1 if(! defined $color); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 5 | ▶ | if($self->get_crisis_level > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 5 | my $out = $self->node1 . " <-> " . $self->node2; | |||||||||||||||||||||||||||
| 127 | 5 | ▶ | if($color) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||
| 129 | 1 | return $out . " " . $self->print_crisis_bar(); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | else | ||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||
| 133 | 4 | return $out . " " . $self->print_grey_crisis_bar(); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | else | ||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | 0 | return ""; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | sub print_grey_crisis_bar | ||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | 15 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_grey_crisis_bar: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 15 | my $out = ""; | |||||||||||||||||||||||||||
| 145 | 15 | ▶ | if($self->get_crisis_level > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||
| 147 | 13 | $out .= "["; | |||||||||||||||||||||||||||
| 148 | 13 | ▶ | for(my $i = 0; $i < CRISIS_MAX_FACTOR; $i++) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | 39 | ▶ | if($i < $self->get_crisis_level) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||
| 152 | 13 | $out .= "*"; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | else | ||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||
| 156 | 26 | $out .= " "; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | 13 | $out .= "]"; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | 15 | return $out; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | sub print_crisis_bar | ||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_crisis_bar: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 11 | return $self->status_color . $self->print_grey_crisis_bar . color("reset"); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | sub change_factor | ||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||
| 171 | 52 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
change_factor: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 172 | 52 | my $delta = shift; | |||||||||||||||||||||||||||
| 173 | 52 | my $new_factor = $self->factor + $delta; | |||||||||||||||||||||||||||
| 174 | 52 | ▶ | $new_factor = $new_factor < 0 ? 0 : $new_factor > 100 ? 100 : $new_factor; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 175 | 52 | $self->factor($new_factor); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | sub escalate_crisis | ||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||
| 180 | 24 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
escalate_crisis: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 181 | 24 | ▶ | if($self->crisis_level < CRISIS_MAX_FACTOR) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||
| 183 | 24 | $self->crisis_level($self->crisis_level() + 1); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | sub cooldown_crisis | ||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||
| 188 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
cooldown_crisis: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 189 | 5 | ▶ | if($self->crisis_level > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||
| 191 | 5 | $self->crisis_level($self->crisis_level() - 1); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | sub is_crisis | ||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||
| 196 | 679 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_crisis: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 197 | 679 | return $self->crisis_level > 0; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | sub is_max_crisis | ||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||
| 201 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_max_crisis: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 202 | 9 | return $self->get_crisis_level() == CRISIS_MAX_FACTOR; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | sub dump | ||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 207 | 0 | my $io = shift; | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | my $indent = shift || ""; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 209 | 0 | print {$io} $indent . join(";", $self->node1, $self->node2, $self->factor, $self->crisis_level) . "\n"; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | sub load | ||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 214 | 0 | my $data = shift; | |||||||||||||||||||||||||||
| 215 | 0 | $data =~ s/^\s+//; | |||||||||||||||||||||||||||
| 216 | 0 | chomp $data; | |||||||||||||||||||||||||||
| 217 | 0 | my ($node1, $node2, $factor, $crisis_level) = split ";", $data; | |||||||||||||||||||||||||||
| 218 | 0 | return $self->new(node1 => $node1, node2 => $node2, factor => $factor, crisis_level => $crisis_level); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 11 | 1; | |||||||||||||||||||||||||||