3 # helper program for processing commodity output
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.
28 use strict (qw(vars));
31 # $commod{'Hemp'}{Buy|Sell}{'stall'}{Stall}
32 # $commod{'Hemp'}{Buy|Sell}{'stall'}{Price}
33 # $commod{'Hemp'}{Buy|Sell}{'stall'}{Qty}
34 # $commod{'Hemp'}{Hold}
37 our ($commod,$stall,%commod);
39 @ARGV==1 or die "You probably don't want to run this program directly.\n";
40 our ($mode) = shift @ARGV;
42 # ./yppsc-commod-processor tsv <t |less -x40,80,90,100,110
47 my ($price,$qty) = @v[$c..$c+1];
48 return if !length($price) && !length($qty);
49 die "$_ ?" unless length($price) && length($qty);
50 $commod{$commod}{$bs}{$stall}= {
60 #print STDERR "[".join("|",@v)."]\n";
61 ($commod,$stall) = @v;
64 $commod{$commod}{Hold}= $v[6]+0 if @v>6;
70 my ($commod,$bs,$sortmul) = @_;
71 my $ary= $current->{$bs};
74 foreach my $stall (sort {
75 $sortmul * ($ary->{$a}{Price} <=> $ary->{$b}{Price});
77 push @$r, $ary->{$stall};
82 sub bs_p_bestprice ($) {
85 printf("| %-25.25s %4d", $l->[0]{Stall}, $l->[0]{Price}) or die $!;
87 printf("| %25s %4s","","") or die $!;
91 our $arbitrage_only= 0;
93 sub main__arbitrage () {
98 sub main__bestprices () {
99 foreach $commod (sort keys %commod) {
100 $current= $commod{$commod};
101 my $buys= bs_p($commod,Buy, -1);
102 my $sells= bs_p($commod,Sell,+1);
103 if ($arbitrage_only) {
104 next unless @$buys and @$sells;
105 next unless $buys->[0]{Price} > $sells->[0]{Price};
107 printf("%-15.15s", $commod) or die $!;
108 bs_p_bestprice($buys);
109 bs_p_bestprice($sells);
110 print("\n") or die $!;
116 if (exists $current->{$bs}{$stall}) {
117 my $si= $current->{$bs}{$stall};
118 printf("\t%d\t%s", $si->{Price}, $si->{Qty}) or die $!;
120 printf("\t\t") or die $!;
125 foreach $commod (sort keys %commod) {
126 $current= $commod{$commod};
128 map { $stalls{$_}=1; } keys %{ $current->{Buy} };
129 map { $stalls{$_}=1; } keys %{ $current->{Sell} };
130 foreach $stall (sort keys %stalls) {
131 printf("%s\t%s", $commod, $stall) or die $!;
134 print("\n") or die $!;
139 sub main__upload () {
140 die "\nUploading not yet implemented, sorry.\n";
145 close(STDOUT) or die $!;