-#!/usr/bin/perl
+#!/usr/bin/perl -w
-use IO::Handle;
+# This specific file is hereby placed in the public domain, or nearest
+# equivalent in law, by me, Ian Jackson. 5th July 2009.
-open CM, "_commodmap.tsv" or die $!;
+use IO::File;
+use strict (qw(vars));
+
+use Commods;
+
+our ($debug)= 0;
$debug=1 if @ARGV;
-while (<CM>) {
- m/^(\S.*\S)\t(\d+)$/ or die;
- $commodmap[$2]= $1;
-}
-die $! if CM->error;
+parse_pctb_commodmap();
-%stallkinds= qw(A Apothecary
- D Distilling
- F Furnishing
- I Ironworking
- S Shipbuilding
- T Tailor
- W Weaving);
+our %stallkinds= qw(A Apothecary
+ D Distilling
+ F Furnishing
+ I Ironworking
+ S Shipbuilding
+ T Tailor
+ W Weaving);
sub getline ($) {
my ($w)= @_;
printf "# Version: \"%s\"\n", getline("version");
-$nstalls= getline("nstalls")+0;
+our $nstalls= getline("nstalls")+0;
+our @stalls;
while (@stalls < $nstalls) {
$_= getline("stall name ".(@stalls+1));
if (s/\^([A-Z])$//) {
- $kind= $1;
- $sk= $stallkinds{$kind};
+ my $kind= $1;
+ my $sk= $stallkinds{$kind};
die "kind $kind in $_ ?" unless defined $sk;
$_ .= "'s $sk Stall";
}
$|=1;
-foreach $bs qw(Buy Sell) {
- $alloffers_want= getint("Buy ncommods");
- $alloffers_done=0;
+foreach my $bs qw(Buy Sell) {
+ my $alloffers_want= getint("Buy ncommods");
+ my $alloffers_done=0;
while ($alloffers_done < $alloffers_want) {
- $commodix= getint("Buy $alloffers_done/$alloffers_want commodix");
- $offers= getint("Buy $commodnum offers");
+ my $commodix= getint("Buy $alloffers_done/$alloffers_want commodix");
+ my $offers= getint("Buy $commodix offers");
+ my $offernum;
for ($offernum=0; $offernum<$offers; $offernum++) {
- $stallix= getint("Buy $commodnum $offernum stallix");
- $price= getint("Buy $commodnum $offernum price");
- $qty= getint("Buy $commodnum $offernum qty");
+ my $stallix= getint("Buy $commodix $offernum stallix");
+ my $price= getint("Buy $commodix $offernum price");
+ my $qty= getint("Buy $commodix $offernum qty");
printf("%s\t%s\t%s",
$bs,
- inmap('commod',@commodmap,$commodix),
+ inmap('commod',@pctb_commodmap,$commodix),
inmap('stall',@stalls,$stallix)) or die $!;
if ($bs eq 'Sell') { print "\t\t" or die $!; }
printf("\t%d\t%d", $price, $qty) or die $!;
}
}
-$r= read STDIN,$b,1;
+my $r= read STDIN,$b,1;
STDIN->error and die $!;
STDIN->eof or die;
$b and die;