lib/Traveller/System/Classic.pm

filter: Statementstmt 7.6% 7 / 92 Branchbran 0.0% 0 / 88 Conditioncond 0.0% 0 / 69 MC/DCmcdc 0.0% 0 / 36 Subroutinesub 15.3% 2 / 13 Podpod 0.0% 0 / 11 totaltotal 2.9% 9 / 309 CC 68 SCAR 59.9
CC
68
Cov
3%
compute_tradecodes
812.0
compute_tech
380.0
str
132.0
CRAP 398.0
« lib/Traveller/Mapper/Classic.pm ↑ Summary lib/Traveller/Mapper.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::System::Classic;
18 2 ▶use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Mojo::Base 'Traveller::System';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub compute_starport {
Subroutine compute_starport: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my $self = shift;
23 0 my %map = ( 2=>'A', 3=>'A', 4=>'A', 5=>'B', 6=>'B', 7=>'C',
24 8=>'C', 9=>'D', 10=>'E', 11=>'E', 12=>'X' );
25 0 return $map{$self->roll2d6()};
26 }
27  
28 0 ▶sub compute_bases {
Subroutine compute_bases: not called CC=6 SCAR=37.4
Pod undocumented
29 0 my $self = shift;
30 0 ▶ if ($self->starport =~ /^[AB]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->starport =~ /^[AB]$/u) 0 0 0
31 0 $self->naval($self->roll2d6() >= 8);
32 }
33 0 ▶ if ($self->starport eq 'A') {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->starport eq 'A') { } 0 0 0
elsif ($self->starport eq 'B') { } 0 0 0
elsif ($self->starport eq 'C') { } 0 0 0
elsif ($self->starport eq 'D') { } 0 0 0
34 0 $self->scout($self->roll2d6() >= 10);
35 } elsif ($self->starport eq 'B') {
36 0 $self->scout($self->roll2d6() >= 9);
37 } elsif ($self->starport eq 'C') {
38 0 $self->scout($self->roll2d6() >= 8);
39 } elsif ($self->starport eq 'D') {
40 0 $self->scout($self->roll2d6() >= 7);
41 }
42 0 $self->gasgiant($self->roll2d6() < 10);
43 }
44  
45 0 ▶sub compute_atmosphere {
Subroutine compute_atmosphere: not called CC=2 SCAR=17.9
Pod undocumented
46 0 my $self = shift;
47 0 ▶ my $atmosphere = $self->size == 0 ? 0 : ($self->roll2d6() - 7 + $self->size);
Branch: 1 branch
BranchTrueFalseTotal
$self->size == 0 ? : 0 0 0
48 0 $atmosphere = min(max($atmosphere, 0), 15);
49 0 return $atmosphere;
50 }
51  
52 0 ▶sub compute_temperature {
Subroutine compute_temperature: not called CC=1 SCAR=0.0
Pod undocumented
53 # do nothing
54 }
55  
56 0 ▶sub compute_hydro {
Subroutine compute_hydro: not called CC=4 SCAR=30.0
Pod undocumented
57 0 my $self = shift;
58 0 my $hydro = $self->roll2d6() - 7 + $self->atmosphere; # erratum
59 0 ▶ $hydro -= 4
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere <= 1 or $self->atmosphere >= 10 0 0 0
Condition0%0/3
$self->atmosphere <= 1 or $self->atmosphere >= 10
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->atmosphere <= 1 or $self->atmosphere >= 10
$self->atmosphere <= 1 $self->atmosphere >= 10
Truth table0%0/3
A or B
A= $self->atmosphere <= 1B= $self->atmosphere >= 10
ABresult
1X1
011
000
60 if $self->atmosphere <= 1
61 or $self->atmosphere >= 10;
62 0 ▶ $hydro = 0 if $self->size <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->size <= 1 0 0 0
63 0 $hydro = min(max($hydro, 0), 10);
64 0 return $hydro;
65 }
66  
67 0 ▶sub compute_tech {
Subroutine compute_tech: not called CC=19 SCAR=59.4
Pod undocumented
68 0 my $self = shift;
69 0 my $tech = $self->roll1d6();
70 0 ▶ $tech += 6 if $self->starport eq 'A';
Branch: 1 branch
BranchTrueFalseTotal
if $self->starport eq "A" 0 0 0
71 0 ▶ $tech += 4 if $self->starport eq 'B';
Branch: 1 branch
BranchTrueFalseTotal
if $self->starport eq "B" 0 0 0
72 0 ▶ $tech += 2 if $self->starport eq 'C';
Branch: 1 branch
BranchTrueFalseTotal
if $self->starport eq "C" 0 0 0
73 0 ▶ $tech -= 4 if $self->starport eq 'X';
Branch: 1 branch
BranchTrueFalseTotal
if $self->starport eq "X" 0 0 0
74 0 ▶ $tech += 2 if $self->size <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->size <= 1 0 0 0
75 0 ▶ $tech += 1 if $self->size >= 2 and $self->size <= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $self->size >= 2 and $self->size <= 4 0 0 0
Condition0%0/3
$self->size >= 2 and $self->size <= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$self->size >= 2 and $self->size <= 4
$self->size >= 2 $self->size <= 4
Truth table0%0/3
A and B
A= $self->size >= 2B= $self->size <= 4
ABresult
0X0
100
111
76 0 ▶ $tech += 1 if $self->atmosphere <= 3 or $self->atmosphere >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere <= 3 or $self->atmosphere >= 10 0 0 0
Condition0%0/3
$self->atmosphere <= 3 or $self->atmosphere >= 10
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->atmosphere <= 3 or $self->atmosphere >= 10
$self->atmosphere <= 3 $self->atmosphere >= 10
Truth table0%0/3
A or B
A= $self->atmosphere <= 3B= $self->atmosphere >= 10
ABresult
1X1
011
000
77 0 ▶ $tech += 1 if $self->hydro == 9;
Branch: 1 branch
BranchTrueFalseTotal
if $self->hydro == 9 0 0 0
78 0 ▶ $tech += 2 if $self->hydro == 10;
Branch: 1 branch
BranchTrueFalseTotal
if $self->hydro == 10 0 0 0
79 0 ▶ $tech += 1 if $self->population >= 1 and $self->population <= 5;
Branch: 1 branch
BranchTrueFalseTotal
if $self->population >= 1 and $self->population <= 5 0 0 0
Condition0%0/3
$self->population >= 1 and $self->population <= 5
!ll&&!rl&&r
000
MC/DC0%0/2
$self->population >= 1 and $self->population <= 5
$self->population >= 1 $self->population <= 5
Truth table0%0/3
A and B
A= $self->population >= 1B= $self->population <= 5
ABresult
0X0
100
111
80 0 ▶ $tech += 2 if $self->population == 9;
Branch: 1 branch
BranchTrueFalseTotal
if $self->population == 9 0 0 0
81 0 ▶ $tech += 4 if $self->population == 10;
Branch: 1 branch
BranchTrueFalseTotal
if $self->population == 10 0 0 0
82 0 ▶ $tech += 1 if $self->government == 0 or $self->government == 5;
Branch: 1 branch
BranchTrueFalseTotal
if $self->government == 0 or $self->government == 5 0 0 0
Condition0%0/3
$self->government == 0 or $self->government == 5
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->government == 0 or $self->government == 5
$self->government == 0 $self->government == 5
Truth table0%0/3
A or B
A= $self->government == 0B= $self->government == 5
ABresult
1X1
011
000
83 0 ▶ $tech -= 2 if $self->government == 13;
Branch: 1 branch
BranchTrueFalseTotal
if $self->government == 13 0 0 0
84 0 return $tech;
85 }
86  
87 0 ▶sub check_doom {
Subroutine check_doom: not called CC=1 SCAR=0.0
Pod undocumented
88 # do nothing
89 }
90  
91 0 ▶sub compute_travelzone {
Subroutine compute_travelzone: not called CC=1 SCAR=0.0
Pod undocumented
92 # do nothing
93 }
94  
95 0 ▶sub compute_tradecodes {
Subroutine compute_tradecodes: not called CC=28 SCAR=67.0
Pod undocumented
96 0 my $self = shift;
97 0 my $tradecodes = '';
98 0 ▶ $tradecodes .= ' Ri' if $self->atmosphere =~ /^[68]$/
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere =~ /^[68]$/u and $self->population >= 6 and $self->population <= 8 and $self->government >= 4 and $self->government <= 9 0 0 0
Condition0%0/12
$self->atmosphere =~ /^[68]$/u and $self->population >= 6 and $self->population <= 8 and $self->government >= 4 and $self->government <= 9
!ll&&!rl&&r
000
$self->atmosphere =~ /^[68]$/u and $self->population >= 6 and $self->population <= 8 and $self->government >= 4
!ll&&!rl&&r
000
$self->atmosphere =~ /^[68]$/u and $self->population >= 6 and $self->population <= 8
!ll&&!rl&&r
000
$self->atmosphere =~ /^[68]$/u and $self->population >= 6
!ll&&!rl&&r
000
MC/DC0%0/5
$self->atmosphere =~ /^[68]$/u and $self->population >= 6 and $self->population <= 8 and $self->government >= 4 and $self->government <= 9
$self->atmosphere =~ /^[68]$/u $self->population >= 6 $self->population <= 8 $self->government >= 4 $self->government <= 9
Truth table0%0/6
A and B and C and D and E
A= $self->atmosphere =~ /^[68]$/uB= $self->population >= 6C= $self->population <= 8D= $self->government >= 4E= $self->government <= 9
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
99 and $self->population >= 6 and $self->population <= 8
100 and $self->government >= 4 and $self->government <= 9;
101 0 ▶ $tradecodes .= ' Po' if $self->atmosphere >= 2 and $self->atmosphere <= 5
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere >= 2 and $self->atmosphere <= 5 and $self->hydro <= 3 0 0 0
Condition0%0/6
$self->atmosphere >= 2 and $self->atmosphere <= 5 and $self->hydro <= 3
!ll&&!rl&&r
000
$self->atmosphere >= 2 and $self->atmosphere <= 5
!ll&&!rl&&r
000
MC/DC0%0/3
$self->atmosphere >= 2 and $self->atmosphere <= 5 and $self->hydro <= 3
$self->atmosphere >= 2 $self->atmosphere <= 5 $self->hydro <= 3
Truth table0%0/4
A and B and C
A= $self->atmosphere >= 2B= $self->atmosphere <= 5C= $self->hydro <= 3
ABCresult
0XX0
10X0
1100
1111
102 and $self->hydro <= 3;
103 0 ▶ $tradecodes .= ' Ag' if $self->atmosphere >= 4 and $self->atmosphere <= 9
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere >= 4 and $self->atmosphere <= 9 and $self->hydro >= 4 and $self->hydro <= 8 and $self->population >= 5 and $self->population <= 7 0 0 0
Condition0%0/15
$self->atmosphere >= 4 and $self->atmosphere <= 9 and $self->hydro >= 4 and $self->hydro <= 8 and $self->population >= 5 and $self->population <= 7
!ll&&!rl&&r
000
$self->atmosphere >= 4 and $self->atmosphere <= 9 and $self->hydro >= 4 and $self->hydro <= 8 and $self->population >= 5
!ll&&!rl&&r
000
$self->atmosphere >= 4 and $self->atmosphere <= 9 and $self->hydro >= 4 and $self->hydro <= 8
!ll&&!rl&&r
000
$self->atmosphere >= 4 and $self->atmosphere <= 9 and $self->hydro >= 4
!ll&&!rl&&r
000
$self->atmosphere >= 4 and $self->atmosphere <= 9
!ll&&!rl&&r
000
MC/DC0%0/6
$self->atmosphere >= 4 and $self->atmosphere <= 9 and $self->hydro >= 4 and $self->hydro <= 8 and $self->population >= 5 and $self->population <= 7
$self->atmosphere >= 4 $self->atmosphere <= 9 $self->hydro >= 4 $self->hydro <= 8 $self->population >= 5 $self->population <= 7
Truth table0%0/7
A and B and C and D and E and F
A= $self->atmosphere >= 4B= $self->atmosphere <= 9C= $self->hydro >= 4D= $self->hydro <= 8E= $self->population >= 5F= $self->population <= 7
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
104 and $self->hydro >= 4 and $self->hydro <= 8
105 and $self->population >= 5 and $self->population <= 7;
106 0 ▶ $tradecodes .= ' Na' if $self->atmosphere <= 3 and $self->hydro <= 3
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere <= 3 and $self->hydro <= 3 and $self->population >= 6 0 0 0
Condition0%0/6
$self->atmosphere <= 3 and $self->hydro <= 3 and $self->population >= 6
!ll&&!rl&&r
000
$self->atmosphere <= 3 and $self->hydro <= 3
!ll&&!rl&&r
000
MC/DC0%0/3
$self->atmosphere <= 3 and $self->hydro <= 3 and $self->population >= 6
$self->atmosphere <= 3 $self->hydro <= 3 $self->population >= 6
Truth table0%0/4
A and B and C
A= $self->atmosphere <= 3B= $self->hydro <= 3C= $self->population >= 6
ABCresult
0XX0
10X0
1100
1111
107 and $self->population >= 6;
108 0 ▶ $tradecodes .= ' In' if $self->atmosphere =~ /^[012479]$/ and $self->population >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere =~ /^[012479]$/u and $self->population >= 9 0 0 0
Condition0%0/3
$self->atmosphere =~ /^[012479]$/u and $self->population >= 9
!ll&&!rl&&r
000
MC/DC0%0/2
$self->atmosphere =~ /^[012479]$/u and $self->population >= 9
$self->atmosphere =~ /^[012479]$/u $self->population >= 9
Truth table0%0/3
A and B
A= $self->atmosphere =~ /^[012479]$/uB= $self->population >= 9
ABresult
0X0
100
111
109 0 ▶ $tradecodes .= ' Ni' if $self->population <= 6;
Branch: 1 branch
BranchTrueFalseTotal
if $self->population <= 6 0 0 0
110 0 ▶ $tradecodes .= ' Wa' if $self->hydro == 10;
Branch: 1 branch
BranchTrueFalseTotal
if $self->hydro == 10 0 0 0
111 0 ▶ $tradecodes .= ' De' if $self->atmosphere >= 2 and $self->hydro == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere >= 2 and $self->hydro == 0 0 0 0
Condition0%0/3
$self->atmosphere >= 2 and $self->hydro == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->atmosphere >= 2 and $self->hydro == 0
$self->atmosphere >= 2 $self->hydro == 0
Truth table0%0/3
A and B
A= $self->atmosphere >= 2B= $self->hydro == 0
ABresult
0X0
100
111
112 0 ▶ $tradecodes .= ' Va' if $self->atmosphere == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere == 0 0 0 0
113 0 ▶ $tradecodes .= ' As' if $self->size == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->size == 0 0 0 0
114 0 ▶ $tradecodes .= ' Ic' if $self->atmosphere <= 1 and $self->hydro >= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->atmosphere <= 1 and $self->hydro >= 1 0 0 0
Condition0%0/3
$self->atmosphere <= 1 and $self->hydro >= 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->atmosphere <= 1 and $self->hydro >= 1
$self->atmosphere <= 1 $self->hydro >= 1
Truth table0%0/3
A and B
A= $self->atmosphere <= 1B= $self->hydro >= 1
ABresult
0X0
100
111
115 0 return $tradecodes;
116 }
117  
118 0 ▶sub code {
Subroutine code: not called CC=4 SCAR=30.0
Pod undocumented
119 0 my $num = shift;
120 0 my $code = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ'; # 'I' and 'O' are omitted
121 0 ▶ return '?' if !defined $num or $num !~ /^\d{1,2}$/ or $num >= length($code);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $num && $num =~ /^\d{1,2}$/u or $num >= length $code 0 0 0
Condition0%0/6
not defined $num && $num =~ /^\d{1,2}$/u or $num >= length $code
l!l&&r!l&&!r
000
defined $num && $num =~ /^\d{1,2}$/u
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $num && $num =~ /^\d{1,2}$/u or $num >= length $code
defined $num $num =~ /^\d{1,2}$/u $num >= length $code
Truth table0%0/4
not(A && B) or C
A= defined $numB= $num =~ /^\d{1,2}$/uC= $num >= length $code
ABCresult
0XX1
10X1
1111
1100
122 0 return substr($code, $num, 1);
123 }
124  
125 0 ▶sub str {
Subroutine str: not called CC=11 SCAR=48.8
Pod undocumented
126 0 my $self = shift;
127 0 my $uwp = sprintf('%-16s %02u%02u ', $self->name, $self->x, $self->y);
128 0 $uwp .= $self->starport;
129 0 $uwp .= code($self->size);
130 0 $uwp .= code($self->atmosphere);
131 0 $uwp .= code($self->hydro);
132 0 $uwp .= code($self->population);
133 0 $uwp .= code($self->government);
134 0 $uwp .= code($self->law);
135 0 $uwp .= '-';
136 0 $uwp .= code($self->tech);
137 0 my $bases = '';
138 0 ▶ $bases .= 'N' if $self->naval;
Branch: 1 branch
BranchTrueFalseTotal
if $self->naval 0 0 0
139 0 ▶ $bases .= 'S' if $self->scout;
Branch: 1 branch
BranchTrueFalseTotal
if $self->scout 0 0 0
140 0 ▶ $bases .= 'R' if $self->research;
Branch: 1 branch
BranchTrueFalseTotal
if $self->research 0 0 0
141 0 ▶ $bases .= 'T' if $self->TAS;
Branch: 1 branch
BranchTrueFalseTotal
if $self->TAS 0 0 0
142 0 ▶ $bases .= 'C' if $self->consulate;
Branch: 1 branch
BranchTrueFalseTotal
if $self->consulate 0 0 0
143 0 ▶ $bases .= 'P' if $self->pirate;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pirate 0 0 0
144 0 ▶ $bases .= 'G' if $self->gasgiant;
Branch: 1 branch
BranchTrueFalseTotal
if $self->gasgiant 0 0 0
145 0 $uwp .= sprintf('%7s', $bases);
146 0 $uwp .= ' ' . $self->tradecodes;
147 0 ▶ $uwp .= ' ' . $self->travelzone if $self->travelzone;
Branch: 1 branch
BranchTrueFalseTotal
if $self->travelzone 0 0 0
148 0 ▶ if ($self->culture) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->culture) 0 0 0
149 0 my $spaces = 20 - length($self->tradecodes);
150 0 ▶ $spaces -= 1 + length($self->travelzone) if $self->travelzone;
Branch: 1 branch
BranchTrueFalseTotal
if $self->travelzone 0 0 0
151 0 $uwp .= ' ' x $spaces;
152 0 $uwp .= '[' . $self->culture . ']';
153 }
154 0 return $uwp;
155 }
156  
157 2 1;
« lib/Traveller/Mapper/Classic.pm ↑ Summary lib/Traveller/Mapper.pm »