- pr1('desired stock level', sprintf("%4d fine rum", $need{Fine}));
- $need_proof= $need{Fine} * $proof{Fine} - $have_proof;
- map {
- $buy{$_} = $need_proof / $proof{$_};
- } @rums;
- pr1("stock equivalent", sprintf "$ff fine rum", $have_proof / $proof{Fine});
- pr1("restock equivalent", sprintf "$ff fine rum", $need_proof / $proof{Fine});
- prf('would need', %buy, 'rum');
-}
-
-sub compute_restock_cheapest_rum() {
- my %bill;
- map {
- $bill{$_} = $buy{$_} * $price{$_} if defined $price{$_};
- } @rums;
- prf('nominal bill', %bill, 'poe');
- print "\n";
- if ($need_proof < 0) {
- printf "stocks are sufficient";
- } else {
- my $buy= ceil($buy{$best});
- printf "buy %d %s at %d poe each for %d poe",
- $buy, $best, $price{$best}, $buy * $price{$best};
+ if (@price) {
+ my ($rum_buy,$shot_buy) = ('','');
+ my ($rum_bill,$shot_bill) = qw(0 0);
+ my $ok=1;
+ if ($rum_need > 0) {
+ if (defined $best) {
+ 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];
+ } else {
+ $rum_buy= ' (rum unavailable)';
+ $ok= 0;
+ }
+ }
+ if ($shot_need > 0) {
+ if (valid($price[3])) {
+ $shot_buy= sprintf('%7s shot **', "** $shot_need");
+ $shot_bill= $shot_need * $price[3];
+ } else {
+ $shot_buy= ' (shot unavailable)';
+ $ok= 0;
+ }
+ }
+ if (length($rum_buy) or length($shot_buy)) {
+ pr2($ok
+ ? sprintf('for a total of %d poe', $rum_bill + $shot_bill)
+ : 'for',
+ $rum_bill ? sprintf("%12d poe ", $rum_bill) : '',
+ $shot_bill ? sprintf("%10d poe", $shot_bill) : '');
+ pr2('BUY', $rum_buy, $shot_buy);
+ } else {
+ print "stocks are sufficient.\n";
+ }
+ print "\n";