3 # helper program for determining pixmap resolution options
5 # This is part of ypp-sc-tools, a set of third-party tools for assisting
6 # players of Yohoho Puzzle Pirates.
8 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
24 # are used without permission. This program is not endorsed or
25 # sponsored by Three Rings.
27 use strict (qw(vars));
35 @ARGV>=1 or die "You probably don't want to run this program directly.\n";
36 our ($which) = shift @ARGV;
40 our ($pctb) = $ENV{'YPPSC_YARRG_PCTB'};
41 our ($ua)= LWP::UserAgent->new;
44 sub jparsetable ($$) {
46 my $jtab= $jobj->{$wh};
47 die "$jsonresp $wh ?" unless defined $jtab;
48 my $cns= $jtab->{'colNames'}; die "$jsonresp $wh ?" unless defined $cns;
49 my $ad= $jtab->{'arrayData'}; die "$jsonresp $wh ?" unless defined $ad;
51 foreach my $ai (@$ad) {
52 @$ai == @$cns or die "$jsonresp $wh ".scalar(@o)."?";
54 for (my $i=0; $i<@$cns; $i++) {
55 $v->{$cns->[$i]} = $ai->[$i];
63 $a->{'name'} cmp $b->{'name'};
67 sub p ($) { print $_[0] or die $!; }
70 die "$_ $& ?" if m/[^-+'"# 0-9a-z]/i;
74 sub json_convert_shim ($) {
76 # In JSON.pm 2.x, jsonToObj prints a warning to stderr which
77 # our callers don't like at all.
78 if ($JSON::VERSION >= 2.0) {
79 return from_json($json);
81 return jsonToObj($json);
85 sub get_arches_islands_pctb ($) {
88 my $url= "$pctb/islands.php?oceanName=".uc $ocean;
89 my $resp= $ua->get($url);
90 die $resp->status_line unless $resp->is_success;
91 $jsonresp= $resp->content;
92 my $jobj= json_convert_shim($resp->content);
93 my $arches= [ jparsetable($jobj, 'arches') ];
94 my $islands= [ jparsetable($jobj, 'islands') ];
97 foreach my $arch (@$arches) {
98 # print Dumper($arnch);
99 my $aname= $arch->{'name'};
100 die "$jsonresp ?" unless defined $aname;
102 foreach my $island (@$islands) {
103 my $iname= $island->{'name'};
104 die "$jsonresp $aname ?" unless defined $iname;
105 next unless $arch->{'id'} == $island->{'arch'};
107 $oceans{$ocean}{$aname}{$iname} .= 'b';
112 die "$jsonresp $islands_done ?" unless $islands_done == @$islands;
116 my $ocean= $ENV{'YPPSC_OCEAN'}; die unless $ocean;
117 return ucfirst lc $ocean;
120 sub for_islands ($$$$) {
121 my ($ocean,$forarch,$forisle,$endarch) = @_;
123 my $arches= $oceans{$ocean};
124 foreach my $aname (sort keys %$arches) {
125 &$forarch($ocean,$aname);
126 my $islands= $arches->{$aname};
127 foreach my $iname (sort keys %$islands) {
128 &$forisle($ocean,$aname,$iname);
134 sub for_commods ($) {
135 my ($forcommod) = @_;
136 foreach my $commod (sort keys %commods) { &$forcommod($commod); }
139 sub compare_sources_one ($$) {
140 my ($srcs,$what) = @_;
141 return if $srcs =~ m,^sl?(?:\%sl?)*b$,;
142 print "srcs=$srcs $what\n";
145 sub main__comparesources () {
146 my $ocean= get_ocean();
148 parse_info_clientside();
149 get_arches_islands_pctb($ocean);
150 parse_pctb_commodmap() or die;
155 my ($ocean,$a,$i)= @_;
156 my $srcs= $oceans{$ocean}{$a}{$i};
157 compare_sources_one($srcs, "island $ocean / $a / $i");
162 my $srcs= $commods{$commod};
163 compare_sources_one($srcs, "commodity $commod");
167 sub main__island () {
168 my $ocean= get_ocean();
170 parse_info_clientside();
171 get_arches_islands_pctb($ocean);
175 my ($ocean,$aname)= @_;
176 ptcl($aname); p(' '); ptcl($aname); p(" {\n");
179 my ($ocean,$aname,$iname)= @_;
180 p(' '); ptcl($iname); p(' '); ptcl($iname); p("\n");
187 sub main__timestamp () {
189 $o{'requesttimestamp'}= '1';
190 my $respcontent= yarrgpostform($ua, \%o);
191 $respcontent =~ m/^OK ([1-9]\d{1,20})\./ or die "$respcontent ?";
196 sub main__sunshinewidget () {
205 Vessel {On board a ship} {
216 &{"main__$which"}(@ARGV);