lib/Traveller/Mapper/Classic.pm

filter: Statementstmt 10.1% 7 / 69 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 33.3% 2 / 6 Podpod 0.0% 0 / 4 totaltotal 4.5% 9 / 199 CC 40 SCAR 71.3
CC
40
Cov
4%
trade
1482.0
trade_svg
6.0
legend
6.0
CRAP 1252.1
« lib/Traveller/System/Classic/MPTS.pm ↑ Summary lib/Traveller/System/Classic.pm »
1 #!/usr/bin/perl
2 # Copyright (C) 2009-2021 Alex Schroeder <alex@gnu.org>
3 # Copyright (C) 2020 Christian Carey
4 #
5 # This program is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program. If not, see <http://www.gnu.org/licenses/>.
16  
17 package Traveller::Mapper::Classic;
18 2 ▶use Mojo::Base 'Traveller::Mapper';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Traveller::Util qw(distance);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub communications {
Subroutine communications: not called CC=1 SCAR=0.0
Pod undocumented
22 # do nothing
23 }
24  
25 0 ▶sub trade {
Subroutine trade: not called CC=38 SCAR=73.0
Pod undocumented
26 # connect starports to each other based on a table
27 # see https://talestoastound.wordpress.com/2015/10/30/traveller-out-of-the-box-interlude-the-1977-edition-over-the-1981-edition/
28 0 my ($self) = @_;
29 0 ▶ return if $self->trade_set;
Branch: 1 branch
BranchTrueFalseTotal
if $self->trade_set 0 0 0
30 0 my @edges;
31 0 my @candidates = grep { $_->starport =~ /^[A-E]$/ } @{$self->hexes};
32 0 my @others = @candidates;
33 # every system has a link to its partners
34 0 foreach my $hex (@candidates) {
35 0 foreach my $other (@others) {
36 0 ▶ next if $hex == $other;
Branch: 1 branch
BranchTrueFalseTotal
if $hex == $other 0 0 0
37 0 my $d = distance($hex, $other) - 1;
38 0 ▶ next if $d > 3; # 0-4!
Branch: 1 branch
BranchTrueFalseTotal
if $d > 3 0 0 0
39 0 my ($from, $to) = sort $hex->starport, $other->starport;
40 0 my $target;
41 0 ▶ if ($from eq 'A' and $to eq 'A') {
Branch: 15 branches
BranchTrueFalseTotal
if ($from eq 'A' and $to eq 'A') { } 0 0 0
elsif ($from eq 'A' and $to eq 'B') { } 0 0 0
elsif ($from eq 'A' and $to eq 'C') { } 0 0 0
elsif ($from eq 'A' and $to eq 'D') { } 0 0 0
elsif ($from eq 'A' and $to eq 'E') { } 0 0 0
elsif ($from eq 'B' and $to eq 'B') { } 0 0 0
elsif ($from eq 'B' and $to eq 'C') { } 0 0 0
elsif ($from eq 'B' and $to eq 'D') { } 0 0 0
elsif ($from eq 'B' and $to eq 'E') { } 0 0 0
elsif ($from eq 'C' and $to eq 'C') { } 0 0 0
elsif ($from eq 'C' and $to eq 'D') { } 0 0 0
elsif ($from eq 'C' and $to eq 'E') { } 0 0 0
elsif ($from eq 'D' and $to eq 'D') { } 0 0 0
elsif ($from eq 'D' and $to eq 'E') { } 0 0 0
elsif ($from eq 'E' and $to eq 'E') { } 0 0 0
Condition0%0/3
$from eq "A" and $to eq "A"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "A" and $to eq "A"
$from eq "A" $to eq "A"
Truth table0%0/3
A and B
A= $from eq "A"B= $to eq "A"
ABresult
0X0
100
111
42 0 $target = [1,2,4,5]->[$d];
43 ▶ } elsif ($from eq 'A' and $to eq 'B') {
Condition0%0/3
$from eq "A" and $to eq "B"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "A" and $to eq "B"
$from eq "A" $to eq "B"
Truth table0%0/3
A and B
A= $from eq "A"B= $to eq "B"
ABresult
0X0
100
111
44 0 $target = [1,3,4,5]->[$d];
45 ▶ } elsif ($from eq 'A' and $to eq 'C') {
Condition0%0/3
$from eq "A" and $to eq "C"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "A" and $to eq "C"
$from eq "A" $to eq "C"
Truth table0%0/3
A and B
A= $from eq "A"B= $to eq "C"
ABresult
0X0
100
111
46 0 $target = [1,4,6]->[$d];
47 ▶ } elsif ($from eq 'A' and $to eq 'D') {
Condition0%0/3
$from eq "A" and $to eq "D"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "A" and $to eq "D"
$from eq "A" $to eq "D"
Truth table0%0/3
A and B
A= $from eq "A"B= $to eq "D"
ABresult
0X0
100
111
48 0 $target = [1,5]->[$d];
49 ▶ } elsif ($from eq 'A' and $to eq 'E') {
Condition0%0/3
$from eq "A" and $to eq "E"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "A" and $to eq "E"
$from eq "A" $to eq "E"
Truth table0%0/3
A and B
A= $from eq "A"B= $to eq "E"
ABresult
0X0
100
111
50 0 $target = [2]->[$d];
51 ▶ } elsif ($from eq 'B' and $to eq 'B') {
Condition0%0/3
$from eq "B" and $to eq "B"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "B" and $to eq "B"
$from eq "B" $to eq "B"
Truth table0%0/3
A and B
A= $from eq "B"B= $to eq "B"
ABresult
0X0
100
111
52 0 $target = [1,3,4,6]->[$d];
53 ▶ } elsif ($from eq 'B' and $to eq 'C') {
Condition0%0/3
$from eq "B" and $to eq "C"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "B" and $to eq "C"
$from eq "B" $to eq "C"
Truth table0%0/3
A and B
A= $from eq "B"B= $to eq "C"
ABresult
0X0
100
111
54 0 $target = [2,4,6]->[$d];
55 ▶ } elsif ($from eq 'B' and $to eq 'D') {
Condition0%0/3
$from eq "B" and $to eq "D"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "B" and $to eq "D"
$from eq "B" $to eq "D"
Truth table0%0/3
A and B
A= $from eq "B"B= $to eq "D"
ABresult
0X0
100
111
56 0 $target = [3,6]->[$d];
57 ▶ } elsif ($from eq 'B' and $to eq 'E') {
Condition0%0/3
$from eq "B" and $to eq "E"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "B" and $to eq "E"
$from eq "B" $to eq "E"
Truth table0%0/3
A and B
A= $from eq "B"B= $to eq "E"
ABresult
0X0
100
111
58 0 $target = [4]->[$d];
59 ▶ } elsif ($from eq 'C' and $to eq 'C') {
Condition0%0/3
$from eq "C" and $to eq "C"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "C" and $to eq "C"
$from eq "C" $to eq "C"
Truth table0%0/3
A and B
A= $from eq "C"B= $to eq "C"
ABresult
0X0
100
111
60 0 $target = [3,6]->[$d];
61 ▶ } elsif ($from eq 'C' and $to eq 'D') {
Condition0%0/3
$from eq "C" and $to eq "D"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "C" and $to eq "D"
$from eq "C" $to eq "D"
Truth table0%0/3
A and B
A= $from eq "C"B= $to eq "D"
ABresult
0X0
100
111
62 0 $target = [4]->[$d];
63 ▶ } elsif ($from eq 'C' and $to eq 'E') {
Condition0%0/3
$from eq "C" and $to eq "E"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "C" and $to eq "E"
$from eq "C" $to eq "E"
Truth table0%0/3
A and B
A= $from eq "C"B= $to eq "E"
ABresult
0X0
100
111
64 0 $target = [4]->[$d];
65 ▶ } elsif ($from eq 'D' and $to eq 'D') {
Condition0%0/3
$from eq "D" and $to eq "D"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "D" and $to eq "D"
$from eq "D" $to eq "D"
Truth table0%0/3
A and B
A= $from eq "D"B= $to eq "D"
ABresult
0X0
100
111
66 0 $target = [4]->[$d];
67 ▶ } elsif ($from eq 'D' and $to eq 'E') {
Condition0%0/3
$from eq "D" and $to eq "E"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "D" and $to eq "E"
$from eq "D" $to eq "E"
Truth table0%0/3
A and B
A= $from eq "D"B= $to eq "E"
ABresult
0X0
100
111
68 0 $target = [5]->[$d];
69 ▶ } elsif ($from eq 'E' and $to eq 'E') {
Condition0%0/3
$from eq "E" and $to eq "E"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq "E" and $to eq "E"
$from eq "E" $to eq "E"
Truth table0%0/3
A and B
A= $from eq "E"B= $to eq "E"
ABresult
0X0
100
111
70 0 $target = [6]->[$d];
71 }
72 0 ▶ if ($target and Traveller::System::roll1d6() >= $target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target and Traveller::System::roll1d6() >= $target) 0 0 0
Condition0%0/3
$target and Traveller::System::roll1d6() >= $target
!ll&&!rl&&r
000
MC/DC0%0/2
$target and Traveller::System::roll1d6() >= $target
$target Traveller::System::roll1d6() >= $target
Truth table0%0/3
A and B
A= $targetB= Traveller::System::roll1d6() >= $target
ABresult
0X0
100
111
73 0 push(@edges, [$hex, $other, $d + 1]);
74 }
75 }
76 0 shift(@others);
77 }
78 # $self->routes($self->minimal_spanning_tree(@edges));
79 0 $self->routes(\@edges);
80 }
81  
82 0 ▶sub trade_svg {
Subroutine trade_svg: not called CC=2 SCAR=17.9
Pod undocumented
83 0 my $self = shift;
84 0 my $data = '';
85 0 my $scale = 100;
86 0 foreach my $edge (sort { $b->[2] cmp $a->[2] } @{$self->routes}) {
87 0 my $u = @{$edge}[0];
88 0 my $v = @{$edge}[1];
89 0 my $d = @{$edge}[2];
90 0 my ($x1, $y1) = ($u->x, $u->y);
91 0 my ($x2, $y2) = ($v->x, $v->y);
92 0 $data .= sprintf(qq{ <line class="trade d$d" x1="%.3f" y1="%.3f" x2="%.3f" y2="%.3f" />\n},
93 (1 + ($x1-1) * 1.5) * $scale, ($y1 - $x1%2/2) * sqrt(3) * $scale,
94 (1 + ($x2-1) * 1.5) * $scale, ($y2 - $x2%2/2) * sqrt(3) * $scale);
95 }
96 0 return $data;
97 }
98  
99 0 ▶sub legend {
Subroutine legend: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my $self = shift;
101 0 my $scale = 100;
102 0 my $doc;
103 0 $doc .= sprintf(qq{ <text class="legend" x="%.3f" y="%.3f">◉ gas giant}
104 . qq{ – ▲ scout base}
105 . qq{ – ★ navy base}
106 . qq{ – <tspan class="trade">▮</tspan> trade},
107 -10, ($self->height + 1) * sqrt(3) * $scale);
108 0 ▶ if ($self->source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->source) 0 0 0
109 0 $doc .= ' – <a xlink:href="' . $self->source . '">UWP</a>';
110 }
111 0 $doc .= qq{</text>\n};
112 0 $doc .= sprintf(qq{ <text class="direction" x="%.3f" y="%.3f">coreward</text>\n},
113 $self->width/2 * 1.5 * $scale, -0.13 * $scale);
114 0 $doc .= sprintf(qq{ <text transform="translate(%.3f,%.3f) rotate(90)"}
115 . qq{ class="direction">trailing</text>\n},
116 ($self->width + 0.4) * 1.5 * $scale, $self->height/2 * sqrt(3) * $scale);
117 0 $doc .= sprintf(qq{ <text class="direction" x="%.3f" y="%.3f">rimward</text>\n},
118 $self->width/2 * 1.5 * $scale, ($self->height + 0.7) * sqrt(3) * $scale);
119 0 $doc .= sprintf(qq{ <text transform="translate(%.3f,%.3f) rotate(-90)"}
120 . qq{ class="direction">spinward</text>\n},
121 -0.1 * $scale, $self->height/2 * sqrt(3) * $scale);
122 0 return $doc;
123 }
124  
125 2 1;
« lib/Traveller/System/Classic/MPTS.pm ↑ Summary lib/Traveller/System/Classic.pm »