+sub pr2 ($$$) {
+ my ($k,$v1,$v2) = @_;
+ printf "%-20s %-23s %s\n", "$k:", $v1, $v2;
+}
+
+sub pr3 ($$$$) {
+ my ($k,$v1,$v2,$v3) = @_;
+ printf "%-20s %-23s %-20s %s\n", "$k:", $v1, $v2, $v3;
+}
+
+sub pr2rs ($$$) {
+ my ($k,$rum,$shot) = @_;
+ pr2($k,
+ valid($rum) ? sprintf("%12.1f fine equiv", $rum) : '',
+ valid($shot) ? sprintf("%10d shot", $shot) : '');
+}
+
+sub compute_restock_requirements () {
+ return unless @want;
+
+ my $rum_want= rum_total(@want);
+
+ my $stocks= @have ? $have[-1] : [qw(0 0 0 0)];
+ my $rum_have= rum_total(@$stocks);
+
+ pr2rs('desired stock level', $rum_want, $want[3]);
+
+ my $rum_need = $rum_want - $rum_have;
+ my $shot_need = $want[3] - $stocks->[3];
+
+ if (@have) {
+ pr2rs('current stock', $rum_have, $stocks->[3]);
+ pr2rs('restock requirement', $rum_need, $shot_need);
+ print "\n";
+ }
+
+ if (@price) {
+ my ($rum_buy,$shot_buy) = ('','');
+ my ($rum_bill,$shot_bill) = qw(0 0);
+ if (defined $best and $rum_need > 0) {
+ my $rum_qty= $rum_need * 100 / $proofs[$best];
+ $rum_qty= ceil($rum_qty);
+ $rum_buy= sprintf('%12s %-11s ',"** $rum_qty","$kinds[$best] **");
+ $rum_bill= $rum_qty * $price[$best];
+ }
+ if ($shot_need > 0 and valid($price[3])) {
+ $shot_buy= sprintf('%7s shot **', "** $shot_need");
+ $shot_bill= $shot_need * $price[3];
+ }
+ if (length($rum_buy) or length($shot_buy)) {
+ pr3('for',
+ $rum_bill ? sprintf("%12d poe ", $rum_bill) : '',
+ $shot_bill ? sprintf("%10d poe", $shot_bill) : '',
+ sprintf("%7d total", $rum_bill + $shot_bill));
+ pr2('BUY', $rum_buy, $shot_buy);
+ } else {
+ print "stocks are sufficient.\n";
+ }
+ print "\n";
+ }
+}
+