line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
# Copyright (C) 2009-2021 Alex Schroeder |
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 . |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Traveller::Mapper::Classic; |
18
|
2
|
|
|
2
|
|
1173
|
use Mojo::Base 'Traveller::Mapper'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
19
|
2
|
|
|
2
|
|
153
|
use Traveller::Util qw(distance); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2745
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
0
|
0
|
|
sub communications { |
22
|
|
|
|
|
|
|
# do nothing |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub trade { |
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
|
|
|
0
|
0
|
|
my ($self) = @_; |
29
|
0
|
0
|
|
|
|
|
return if $self->trade_set; |
30
|
0
|
|
|
|
|
|
my @edges; |
31
|
0
|
|
|
|
|
|
my @candidates = grep { $_->starport =~ /^[A-E]$/ } @{$self->hexes}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
next if $hex == $other; |
37
|
0
|
|
|
|
|
|
my $d = distance($hex, $other) - 1; |
38
|
0
|
0
|
|
|
|
|
next if $d > 3; # 0-4! |
39
|
0
|
|
|
|
|
|
my ($from, $to) = sort $hex->starport, $other->starport; |
40
|
0
|
|
|
|
|
|
my $target; |
41
|
0
|
0
|
0
|
|
|
|
if ($from eq 'A' and $to eq 'A') { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$target = [1,2,4,5]->[$d]; |
43
|
|
|
|
|
|
|
} elsif ($from eq 'A' and $to eq 'B') { |
44
|
0
|
|
|
|
|
|
$target = [1,3,4,5]->[$d]; |
45
|
|
|
|
|
|
|
} elsif ($from eq 'A' and $to eq 'C') { |
46
|
0
|
|
|
|
|
|
$target = [1,4,6]->[$d]; |
47
|
|
|
|
|
|
|
} elsif ($from eq 'A' and $to eq 'D') { |
48
|
0
|
|
|
|
|
|
$target = [1,5]->[$d]; |
49
|
|
|
|
|
|
|
} elsif ($from eq 'A' and $to eq 'E') { |
50
|
0
|
|
|
|
|
|
$target = [2]->[$d]; |
51
|
|
|
|
|
|
|
} elsif ($from eq 'B' and $to eq 'B') { |
52
|
0
|
|
|
|
|
|
$target = [1,3,4,6]->[$d]; |
53
|
|
|
|
|
|
|
} elsif ($from eq 'B' and $to eq 'C') { |
54
|
0
|
|
|
|
|
|
$target = [2,4,6]->[$d]; |
55
|
|
|
|
|
|
|
} elsif ($from eq 'B' and $to eq 'D') { |
56
|
0
|
|
|
|
|
|
$target = [3,6]->[$d]; |
57
|
|
|
|
|
|
|
} elsif ($from eq 'B' and $to eq 'E') { |
58
|
0
|
|
|
|
|
|
$target = [4]->[$d]; |
59
|
|
|
|
|
|
|
} elsif ($from eq 'C' and $to eq 'C') { |
60
|
0
|
|
|
|
|
|
$target = [3,6]->[$d]; |
61
|
|
|
|
|
|
|
} elsif ($from eq 'C' and $to eq 'D') { |
62
|
0
|
|
|
|
|
|
$target = [4]->[$d]; |
63
|
|
|
|
|
|
|
} elsif ($from eq 'C' and $to eq 'E') { |
64
|
0
|
|
|
|
|
|
$target = [4]->[$d]; |
65
|
|
|
|
|
|
|
} elsif ($from eq 'D' and $to eq 'D') { |
66
|
0
|
|
|
|
|
|
$target = [4]->[$d]; |
67
|
|
|
|
|
|
|
} elsif ($from eq 'D' and $to eq 'E') { |
68
|
0
|
|
|
|
|
|
$target = [5]->[$d]; |
69
|
|
|
|
|
|
|
} elsif ($from eq 'E' and $to eq 'E') { |
70
|
0
|
|
|
|
|
|
$target = [6]->[$d]; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
0
|
|
|
|
if ($target and Traveller::System::roll1d6() >= $target) { |
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
|
|
|
|
|
|
|
sub trade_svg { |
83
|
0
|
|
|
0
|
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}) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $u = @{$edge}[0]; |
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $v = @{$edge}[1]; |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $d = @{$edge}[2]; |
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my ($x1, $y1) = ($u->x, $u->y); |
91
|
0
|
|
|
|
|
|
my ($x2, $y2) = ($v->x, $v->y); |
92
|
0
|
|
|
|
|
|
$data .= sprintf(qq{ \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
|
|
|
|
|
|
|
sub legend { |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
0
|
|
|
|
|
|
my $scale = 100; |
102
|
0
|
|
|
|
|
|
my $doc; |
103
|
0
|
|
|
|
|
|
$doc .= sprintf(qq{ ◉ gas giant} |
104
|
|
|
|
|
|
|
. qq{ – ▲ scout base} |
105
|
|
|
|
|
|
|
. qq{ – ★ navy base} |
106
|
|
|
|
|
|
|
. qq{ – ▮ trade}, |
107
|
|
|
|
|
|
|
-10, ($self->height + 1) * sqrt(3) * $scale); |
108
|
0
|
0
|
|
|
|
|
if ($self->source) { |
109
|
0
|
|
|
|
|
|
$doc .= ' – UWP'; |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
$doc .= qq{\n}; |
112
|
0
|
|
|
|
|
|
$doc .= sprintf(qq{ coreward\n}, |
113
|
|
|
|
|
|
|
$self->width/2 * 1.5 * $scale, -0.13 * $scale); |
114
|
0
|
|
|
|
|
|
$doc .= sprintf(qq{
|
115
|
|
|
|
|
|
|
. qq{ class="direction">trailing\n}, |
116
|
|
|
|
|
|
|
($self->width + 0.4) * 1.5 * $scale, $self->height/2 * sqrt(3) * $scale); |
117
|
0
|
|
|
|
|
|
$doc .= sprintf(qq{ rimward\n}, |
118
|
|
|
|
|
|
|
$self->width/2 * 1.5 * $scale, ($self->height + 0.7) * sqrt(3) * $scale); |
119
|
0
|
|
|
|
|
|
$doc .= sprintf(qq{
|
120
|
|
|
|
|
|
|
. qq{ class="direction">spinward\n}, |
121
|
|
|
|
|
|
|
-0.1 * $scale, $self->height/2 * sqrt(3) * $scale); |
122
|
0
|
|
|
|
|
|
return $doc; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |