$|=1;
+sub chk_ascending ($$$) {
+ my ($this,$lastref,$desc) = @_;
+ printf "# WARNING - $desc $this < $$lastref\n"
+ if defined($$lastref) and $this < $$lastref;
+ $$lastref= $this;
+}
+
foreach my $bs qw(Buy Sell) {
my $alloffers_want= getint("Buy ncommods");
my $alloffers_done=0;
+ my $commodix_last;
+ my $price_last;
while ($alloffers_done < $alloffers_want) {
my $commodix= getint("Buy $alloffers_done/$alloffers_want commodix");
+ $price_last=undef unless
+ defined($commodix_last) && $commodix == $commodix_last;
my $offers= getint("Buy $commodix offers");
my $offernum;
for ($offernum=0; $offernum<$offers; $offernum++) {
$bs,
inmap('commod',@pctb_commodmap,$commodix),
inmap('stall',@stalls,$stallix)) or die $!;
- if ($bs eq 'Sell') { print "\t\t" or die $!; }
+ my $chk_asc_price_neg;
+ my $pricesort;
+ if ($bs eq 'Sell') { $pricesort=1; print "\t\t" or die $!; }
printf("\t%d\t%d", $price, $qty) or die $!;
- if ($bs eq 'Buy') { print "\t\t" or die $!; }
+ if ($bs eq 'Buy') { $pricesort=-1; print "\t\t" or die $!; }
print "\n" or die $!;
+ chk_ascending($commodix,\$commodix_last,'commodix');
+ chk_ascending($pricesort*$price,\$price_last,'price');
$alloffers_done++;
die if $alloffers_done > $alloffers_want;
}
# 0060 01 00 1e 00 OI 30
# 0070 02 00 qty 2
#
+# buy offers need to be sorted first by commodity index, then by
+# prices (prices ascending)
+# sell offers need to be sorted first by commodity index, then by
+# prices (prices descending)
+# [ however, it seems that this is wrong and the price sort order is
+# supposed to be descending for buy and ascending for sell ]