« blib/lib/BalanceOfPower/Commands/RecallRebelMilitarySupport.pm
↑ Summary
lib/BalanceOfPower/Nation.pm »
| 1 | package BalanceOfPower::Role::Mapmaker; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | $BalanceOfPower::Role::Mapmaker::VERSION = '0.200000'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
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::Border; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use BalanceOfPower::Relations::RelPack; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | has borders => ( | ||||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 14 | ▶ | default => sub { BalanceOfPower::Relations::RelPack->new() }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | handles => { add_border => 'add_link', | |||||||||||||||||||||||||||||||||||||||||
| 14 | border_exists => 'exists_link', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | print_borders => 'print_links', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | get_borders => 'links_for_node', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | near_on_the_map => 'near', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | distance_on_the_map => 'distance' | ||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub load_borders | ||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_borders: called CC=9 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 14 | my $bordersfile = shift; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | ▶ | my $file = shift || $self->data_directory . "/" . $bordersfile; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || $self->data_directory . '/' . $bordersfile
MC/DC0%0/1
shift() || $self->data_directory . '/' . $bordersfile
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 14 | ▶ | open(my $borders, "<", $file) || die $!;; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | for(<$borders>) | |||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 51 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 51 | my $border = $_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 51 | my @nodes = split(/,/, $border); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 51 | ▶ | if($self->check_nation_name($nodes[0]) && $self->check_nation_name($nodes[1])) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->check_nation_name($nodes[0]) and $self->check_nation_name($nodes[1])
MC/DC0%0/2
$self->check_nation_name($nodes[0]) and $self->check_nation_name($nodes[1])
$self->check_nation_name($nodes[0])
$self->check_nation_name($nodes[1])
Truth table33%1/3
A and B
A= $self->check_nation_name($nodes[0])B= $self->check_nation_name($nodes[1])
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 51 | ▶ | if($nodes[0] && $nodes[1] && ! $self->border_exists($nodes[0], $nodes[1])) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$nodes[0] and $nodes[1] and not $self->border_exists($nodes[0], $nodes[1])
$nodes[0] and $nodes[1]
MC/DC0%0/3
$nodes[0] and $nodes[1] and not $self->border_exists($nodes[0], $nodes[1])
$nodes[0]
$nodes[1]
not $self->border_exists($nodes[0], $nodes[1])
Truth table25%1/4
A and B and not(C)
A= $nodes[0]B= $nodes[1]C= not $self->border_exists($nodes[0], $nodes[1])
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 51 | my $b = BalanceOfPower::Relations::Border->new(node1 => $nodes[0], node2 => $nodes[1]); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 51 | $self->add_border($b); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | else | ||||||||||||||||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | say "WRONG BORDER: $border"; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | sub near_nations | ||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
near_nations: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 13 | my $nation = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 13 | ▶ | my $geographical = shift || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 13 | ▶ | if($geographical) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 13 | return $self->near_on_the_map($nation, $self->nation_names); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | else | ||||||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return grep { $self->in_military_range($nation, $_) && $nation ne $_ } @{$self->nation_names}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | sub print_near_nations | ||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_near_nations: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $nation = shift; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $out = ""; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | for($self->near_nations($nation)) | |||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $out .= $_ . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | sub distance | ||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 136 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
distance: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 136 | my $nation1 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 136 | my $nation2 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 136 | return $self->distance_on_the_map($nation1, $nation2, $self->nation_names); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | sub get_group_borders | ||||||||||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_group_borders: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 14 | my $group1 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 14 | my $group2 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 14 | my @from = @{ $group1 }; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 14 | my @to = @{ $group2 }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 14 | my @out = (); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 14 | foreach my $to_n (@to) | |||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 18 | foreach my $from_n (@from) | |||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 21 | ▶ | if($self->in_military_range($from_n, $to_n)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | push @out, $to_n; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | last; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 14 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | #cache management | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | sub print_distance | ||||||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_distance: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | my $n1 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my $n2 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | return "Distance between $n1 and $n2: " . $self->distance($n1, $n2); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||