App-traveller
view release on metacpan or search on metacpan
lib/Traveller/Mapper/Classic.pm view on Meta::CPAN
my ($from, $to) = sort $hex->starport, $other->starport;
my $target;
if ($from eq 'A' and $to eq 'A') {
$target = [1,2,4,5]->[$d];
} elsif ($from eq 'A' and $to eq 'B') {
$target = [1,3,4,5]->[$d];
} elsif ($from eq 'A' and $to eq 'C') {
$target = [1,4,6]->[$d];
} elsif ($from eq 'A' and $to eq 'D') {
$target = [1,5]->[$d];
} elsif ($from eq 'A' and $to eq 'E') {
$target = [2]->[$d];
} elsif ($from eq 'B' and $to eq 'B') {
$target = [1,3,4,6]->[$d];
} elsif ($from eq 'B' and $to eq 'C') {
$target = [2,4,6]->[$d];
} elsif ($from eq 'B' and $to eq 'D') {
$target = [3,6]->[$d];
} elsif ($from eq 'B' and $to eq 'E') {
$target = [4]->[$d];
} elsif ($from eq 'C' and $to eq 'C') {
$target = [3,6]->[$d];
} elsif ($from eq 'C' and $to eq 'D') {
$target = [4]->[$d];
} elsif ($from eq 'C' and $to eq 'E') {
$target = [4]->[$d];
} elsif ($from eq 'D' and $to eq 'D') {
$target = [4]->[$d];
} elsif ($from eq 'D' and $to eq 'E') {
$target = [5]->[$d];
} elsif ($from eq 'E' and $to eq 'E') {
$target = [6]->[$d];
}
if ($target and Traveller::System::roll1d6() >= $target) {
push(@edges, [$hex, $other, $d + 1]);
}
}
shift(@others);
}
# $self->routes($self->minimal_spanning_tree(@edges));
$self->routes(\@edges);
}
sub trade_svg {
my $self = shift;
my $data = '';
my $scale = 100;
foreach my $edge (sort { $b->[2] cmp $a->[2] } @{$self->routes}) {
my $u = @{$edge}[0];
my $v = @{$edge}[1];
my $d = @{$edge}[2];
my ($x1, $y1) = ($u->x, $u->y);
my ($x2, $y2) = ($v->x, $v->y);
$data .= sprintf(qq{ <line class="trade d$d" x1="%.3f" y1="%.3f" x2="%.3f" y2="%.3f" />\n},
(1 + ($x1-1) * 1.5) * $scale, ($y1 - $x1%2/2) * sqrt(3) * $scale,
(1 + ($x2-1) * 1.5) * $scale, ($y2 - $x2%2/2) * sqrt(3) * $scale);
}
return $data;
}
sub legend {
my $self = shift;
my $scale = 100;
my $doc;
$doc .= sprintf(qq{ <text class="legend" x="%.3f" y="%.3f">â gas giant}
. qq{ â â² scout base}
. qq{ â â
navy base}
. qq{ â <tspan class="trade">â®</tspan> trade},
-10, ($self->height + 1) * sqrt(3) * $scale);
if ($self->source) {
$doc .= ' â <a xlink:href="' . $self->source . '">UWP</a>';
}
$doc .= qq{</text>\n};
$doc .= sprintf(qq{ <text class="direction" x="%.3f" y="%.3f">coreward</text>\n},
$self->width/2 * 1.5 * $scale, -0.13 * $scale);
$doc .= sprintf(qq{ <text transform="translate(%.3f,%.3f) rotate(90)"}
. qq{ class="direction">trailing</text>\n},
($self->width + 0.4) * 1.5 * $scale, $self->height/2 * sqrt(3) * $scale);
$doc .= sprintf(qq{ <text class="direction" x="%.3f" y="%.3f">rimward</text>\n},
$self->width/2 * 1.5 * $scale, ($self->height + 0.7) * sqrt(3) * $scale);
$doc .= sprintf(qq{ <text transform="translate(%.3f,%.3f) rotate(-90)"}
. qq{ class="direction">spinward</text>\n},
-0.1 * $scale, $self->height/2 * sqrt(3) * $scale);
return $doc;
}
1;
( run in 1.971 second using v1.01-cache-2.11-cpan-df04353d9ac )