| 1 | package BalanceOfPower::Commands::NagTreaty; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | $BalanceOfPower::Commands::NagTreaty::VERSION = '0.300010'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Array::Utils qw(intersect); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | extends 'BalanceOfPower::Commands::TargetNation'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | with 'BalanceOfPower::Commands::Role::TreatiesUnderLimit'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | sub get_available_targets | ||||||||||||||||||||||||||||||||||||||||||
| 10 | { | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_available_targets: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | my @targets = $self->SUPER::get_available_targets(); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my $nation = $self->actor; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | @targets = grep {! $self->world->exists_treaty($nation, $_) } @targets; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | @targets = grep { $self->world->diplomacy_status($nation, $_) ne 'HATE' } @targets; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | return $self->nations_under_treaty_limit(@targets); | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub IA | ||||||||||||||||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
IA: not called CC=21 SCAR=61.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $actor = $self->get_nation(); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my @available_targets = $self->get_available_targets(); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return undef if @available_targets == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my @near = $self->world->near_nations($actor->name, 1); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my @friendly_neighbors = $self->world->shuffle("Mixing neighbors to choose about NAG treaty", intersect(@near, @available_targets)); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my @ordered_friendly_neighbors = (); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $dangerous_neighbor = 0; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | for(@friendly_neighbors) | |||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $n = $_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if(! $self->world->exists_treaty($self->name, $n)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $supporter = $self->world->supported($n); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if($supporter) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $supporter_nation = $supporter->node1; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if($supporter_nation eq $actor->name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | #I'm the supporter of this nation! | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | push @ordered_friendly_neighbors, { nation => $n, | |||||||||||||||||||||||||||||||||||||||||
| 43 | interest => 0 }; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | else | ||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if($self->world->crisis_exists($actor->name, $supporter_nation)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | push @ordered_friendly_neighbors, { nation => $n, | |||||||||||||||||||||||||||||||||||||||||
| 50 | interest => 100 }; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $dangerous_neighbor = 1; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | elsif($self->world->diplomacy_status($actor->name, $supporter_nation) eq 'HATE') | ||||||||||||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | push @ordered_friendly_neighbors, { nation => $n, | |||||||||||||||||||||||||||||||||||||||||
| 56 | interest => 10 }; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | else | ||||||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | push @ordered_friendly_neighbors, { nation => $n, | |||||||||||||||||||||||||||||||||||||||||
| 61 | interest => 2 }; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | else | ||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | push @ordered_friendly_neighbors, { nation => $n, | |||||||||||||||||||||||||||||||||||||||||
| 68 | interest => 1 }; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if(@ordered_friendly_neighbors > 0 && $dangerous_neighbor) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@ordered_friendly_neighbors > 0 and $dangerous_neighbor
MC/DC0%0/2
@ordered_friendly_neighbors > 0 and $dangerous_neighbor
@ordered_friendly_neighbors > 0
$dangerous_neighbor
Truth table0%0/3
A and B
A= @ordered_friendly_neighbors > 0B= $dangerous_neighbor
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | @ordered_friendly_neighbors = sort { $b->{interest} <=> $a->{interest} } @ordered_friendly_neighbors; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return "TREATY NAG WITH " . $ordered_friendly_neighbors[0]->{nation}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | else | ||||||||||||||||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | #Scanning crises | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my @crises = $self->world->get_crises($actor->name); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if(@crises > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | foreach my $c ($self->world->shuffle("Mixing crisis for war for " . $actor->name, @crises)) | |||||||||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | #NAG with enemy supporter | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $enemy = $c->destination($actor->name); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $supporter = $self->world->supported($enemy); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if($supporter) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $supporter_nation = $supporter->node1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if($supporter_nation ne $actor->name && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$supporter_nation ne $actor->name and $self->world->diplomacy_status($actor->name, $supporter_nation) ne "HATE" and not $self->world->exists_treaty($actor->name, $supporter_nation)
$supporter_nation ne $actor->name and $self->world->diplomacy_status($actor->name, $supporter_nation) ne "HATE"
MC/DC0%0/3
$supporter_nation ne $actor->name and $self->world->diplomacy_status($actor->name, $supporter_nation) ne "HATE" and not $self->world->exists_treaty($actor->name, $supporter_nation)
$supporter_nation ne $actor->name
$self->world->diplomacy_status($actor->name, $supporter_nation) ne "HATE"
not $self->world->exists_treaty($actor->name, $supporter_nation)
Truth table0%0/4
A and B and not(C)
A= $supporter_nation ne $actor->nameB= $self->world->diplomacy_status($actor->name, $supporter_nation) ne "HATE"C= not $self->world->exists_treaty($actor->name, $supporter_nation)
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | $self->world->diplomacy_status($actor->name, $supporter_nation) ne 'HATE' && | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ! $self->world->exists_treaty($actor->name, $supporter_nation)) | ||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return "TREATY NAG WITH " . $supporter_nation; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | #NAG with enemy ally | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my @allies = $self->world->get_allies($enemy); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | for($self->world->shuffle("Mixing allies of enemy for a NAG", @allies)) | |||||||||||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $all = $_->destination($enemy); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if($all ne $actor->name && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$all ne $actor->name and $self->world->diplomacy_status($actor->name, $all) ne "HATE" and not $self->world->exists_treaty($actor->name, $all)
$all ne $actor->name and $self->world->diplomacy_status($actor->name, $all) ne "HATE"
MC/DC0%0/3
$all ne $actor->name and $self->world->diplomacy_status($actor->name, $all) ne "HATE" and not $self->world->exists_treaty($actor->name, $all)
$all ne $actor->name
$self->world->diplomacy_status($actor->name, $all) ne "HATE"
not $self->world->exists_treaty($actor->name, $all)
Truth table0%0/4
A and B and not(C)
A= $all ne $actor->nameB= $self->world->diplomacy_status($actor->name, $all) ne "HATE"C= not $self->world->exists_treaty($actor->name, $all)
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | $self->world->diplomacy_status($actor->name, $all) ne 'HATE' && | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ! $self->world->exists_treaty($actor->name, $all)) | ||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return "TREATY NAG WITH " . $all; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if(@ordered_friendly_neighbors > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | @ordered_friendly_neighbors = sort { $b->{interest} <=> $a->{interest} } @ordered_friendly_neighbors; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return "TREATY NAG WITH " . $ordered_friendly_neighbors[0]->{nation}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||