X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=generate-board;h=9ce1dc23e4fd441521e71abc37fcd0e71f862f75;hb=80d5c2f420e30982360cd7398e63898e05111c9f;hp=54f2e5ebe1429cb3254d25200c70fdb6d2e828df;hpb=3692f8c549cffecb6173e62b23c201403484d763;p=pandemic-rising-tide.git
diff --git a/generate-board b/generate-board
index 54f2e5e..9ce1dc2 100755
--- a/generate-board
+++ b/generate-board
@@ -1,4 +1,50 @@
#!/usr/bin/perl -w
+#
+# generate-board - program for generating playing board images
+# for games very like Pandemic Rising Tide
+#
+# Copyright (C) 2019 Ian Jackson
+#
+# This program is dual licensed, GPv3+ or CC-BY-SA 4.0+.
+# It copies bits of itself into its output; those parts are CC-BY 4.0+.
+# Only to the Pandemic Rising Tide folks, it is permissively licensed.
+#
+# This program is free software.
+#
+# You can redistribute it and/or modify it under the terms of the
+# GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option)
+# any later version; or (at your option), under the terms of the
+# Creative Commons Attribution-ShareAlike International License,
+# version 4.0 of that License, or (at your option), any later
+# version.
+#
+# This program copies pieces itself into the output. Those pieces,
+# when copied into the output, are additionally (at your option)
+# available under a difference licence: they are made available
+# under the Creative Commons Attribution International License,
+# version 4.0 of that License, or (at your option), any later
+# version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License Creative Commons Attribution-ShareAlike
+# License or the for more details.
+#
+# You should have received a copy of these licenses along with this
+# program. If not, see and
+# .
+#
+# Pandemic and Pandemic Rising Tide are (I think) trademarks of Z-Man
+# games and I use them without permission.
+#
+# For the avoidance of doubt, I do not consider this program to be a
+# derivative work of the game Pandemic Rising Tide. However, it is
+# not very useful without a pair of game description files and the
+# only nontrivial game description files I know of are indeed such
+# derivatives.
+
use strict;
use Carp;
@@ -38,8 +84,7 @@ our $a1_h = 2384;
our $max_printeredge = 5.50 * MM2PT;
our $a1m_pasteedge = 3.5 * MM2PT; # along each edge
our $preamble_from_boundings = '';
-our $top_adjuncts_dy_from_boundings = 0;
-our $bottom_adjuncts_dy_from_boundings = 0;
+our %adjuncts_dy_from_boundings = (Top => 0, Bottom => 0);
# ----- region names from plag, incl. reverse mapping -----
@@ -246,6 +291,13 @@ sub transform_coordinates () {
$mid = ($lims[1] - $lims[0]) * 0.5;
}
+sub pos_plus_dy_adjunct ($) {
+ my ($cval) = @_;
+ my ($x,$y,$whadjunct) = @$cval;
+ my $adjunct = $adjuncts_dy_from_boundings{ $whadjunct//'' };
+ return "$x $y".( defined $adjunct and " $adjunct add translate" );
+}
+
sub adjust_sea() {
# Adjusts the top and bottom edges of the sea
my $poly = $region{$c{Sea}}{Polygon};
@@ -388,8 +440,8 @@ sub computeboundings() {
-$surroundw 0 rlineto
closepath $w_stroke clip
END
- ($top_adjuncts_dy_from_boundings,
- $bottom_adjuncts_dy_from_boundings) = @{ $c{PA}{BoundingsA1dy} };
+ $adjuncts_dy_from_boundings{Top} = $c{PA}{BoundingsA1dy}[0];
+ $adjuncts_dy_from_boundings{Bottom} = $c{PA}{BoundingsA1dy}[1];
# ^ if we are doing it all in one go we lose less printable area
} else {
confess;
@@ -684,8 +736,10 @@ END
}
if ($hs{$rr->{Name}}) {
#print STDERR "adjust hs $rr->{Name}\n";
- $pos -= mkvec(0, -$hs_sz*
- ( $rr->{Colour} eq 'green' ? 0.25 : 0.65 ));
+ my $posadj = $c{PA_HS_HS}{$rr->{Colour}};
+ $posadj //= [0,0];
+ $pos -= mkvec(0, -$hs_sz * 0.65);
+ $pos += &mkvec(@$posadj) * $hs_sz;
my $hspos = $pos - mkvec(0, $sz * @$words + $hs_sz/2 + $hs_lw
+ $hs_sz*0.15);
one_hs($rr->{Colour}, $hspos);
@@ -769,21 +823,24 @@ sub decks(){
}
o(" closepath\n");
o(" } bind def");
+
o(" /deckpairpathx {\n"); # x because it leaves matrix changed
o(" newpath deck1path\n");
o(" 200 0 translate deck1path\n");
o(" } bind def");
- o(" $lw setlinewidth ",miscpscolour('playerdeck'),"\n");
- o(" gsave 401 44 $bottom_adjuncts_dy_from_boundings add translate");
- o(" deckpairpathx stroke grestore");
- o(" $lw setlinewidth ",miscpscolour('dykefail'),"\n");
- o(" gsave 242 1363 $top_adjuncts_dy_from_boundings add translate ");
- o(" 90 rotate deckpairpathx stroke grestore");
+
+ foreach my $deck (@{ $c{Decks} }) {
+ o(" $lw setlinewidth ",miscpscolour($deck->{Colour}),"\n");
+ o(" gsave ".pos_plus_dy_adjunct($deck->{PosAdy})." ");
+ my $rotate = $deck->{Rotate};
+ if ($rotate) { o(" $rotate rotate "); }
+ o("deckpairpathx stroke grestore");
+ }
}
sub sea_track(){
o("% sea level track\n");
- o(" gsave 11 700 translate\n");
+ o(" gsave ",pos_plus_dy_adjunct($c{PA}{SeaTrack})," translate\n");
my $track = $c{SeaTrack};
my $token_sz = $hs_sz;
my $dy = $token_sz * 1.25;
@@ -922,53 +979,58 @@ sub dykes(){
}
}
-sub hs_initial_1 ($$$;$$$) {
- my ($colour, $xi,$yi, $text, $text2, $fn) = @_;
+sub hs_initial_1 ($) {
+ my ($hs1) = @_;
+ my ($colour) = $hs1->{Colour};
+ my ($text, $text2);
+ if ($hs1->{Water}) {
+ ($text,$text2) = ('up to '.$hs1->{Water}, 'fewer');
+ } elsif ($hs1->{Dykes}) {
+ ($text,$text2) = ('up to '.$hs1->{Dykes}, '');
+ }
my $interval = $hs_sz * 1.75;
my $demo_h = $hs_sz; #water_cubes_sz(3);
my $demo_x0 = $hs_sz * 0.75 + $dyke_l * 0.60;
my $demo_w = $demo_x0 + $dyke_l * 0.60;
o(" % HS I $colour\n");
o(" gsave\n");
- o(" 550 1705 $top_adjuncts_dy_from_boundings add translate\n");
- o(" ", ($xi*$interval), " ", (($yi-1)*$interval), " translate\n");
- if ($fn) {
+ o(" ".pos_plus_dy_adjunct($c{PA}{HS1_initials})."\n");
+ o(" ", ($hs1->{XIYI}[0]*$interval), " ",
+ (($hs1->{XIYI}[1]-1)*$interval), " translate\n");
+ if (defined $text) {
o(" gsave\n");
o(" $demo_h setlinewidth 0 0 moveto $demo_w 0 rlineto\n");
o(" ", facepscolour($colour), " stroke grestore\n");
}
one_hs($colour, mkvec(0,0));
- if ($fn) {
+ if (defined $text) {
o(" /words {\n");
o(" 2 copy moveto ($text) show\n");
o(" 2 copy moveto 0 -$text_sz rmoveto ($text2) show\n");
o(" } bind def\n");
o(" gsave ".($hs_sz * 0.8)." $cube_gap translate wordsshow grestore\n");
o(" $demo_x0 ",($hs_sz * -0.25)," translate\n");
- $fn->();
}
- o(" grestore\n");
-}
-
-sub hs_initial () {
- hs_initial_1('red', 0,0);
- hs_initial_1('purple', 0,1);
- hs_initial_1('green', 1,0, 'up to 6', 'fewer', sub {
+ if ($hs1->{Water}) {
o(" ",(water_cubes_sz(1))," 0 translate\n");
o(" 0 ",(-water_cubes_sz(1) * 0.3)," translate\n");
water_cubes(1, miscpscolour('edge'));
- });
- hs_initial_1('yellow', 1,1, 'up to 4', '', sub {
+ } elsif ($hs1->{Dykes}) {
o(" newpath dykepath\n");
o(" gsave ",miscpscolour('edge')," stroke grestore\n");
o(" gsave ",miscpscolour('dykehsadd')," fill grestore\n");
- });
+ }
+ o(" grestore\n");
+}
+
+sub hs_initial () {
+ hs_initial_1($_) foreach @{ $c{HS1} };
}
sub play_hint () {
my $sz = 20;
o(" gsave ",miscpscolour('hinttext'),
- " 260 1715 $top_adjuncts_dy_from_boundings add translate\n");
+ " ",pos_plus_dy_adjunct($c{PA}{PlayHint}),"\n");
o(" /Helvetica-Bold findfont $sz scalefont setfont\n");
my @t = split /\n/, $c{PlayHint};
foreach my $i (0..$#t) {