#!/usr/bin/perl -w
use strict;

# Defaults.  Override with command-line arguments.
my $plusmeat = 200;
my $plusitem = 100;
my $combatrate = 85;

my $verbose = 0;
if ($ARGV[0] eq "-v") { $verbose = 1; shift; }

$plusmeat = $ARGV[0] if $#ARGV >= 0;
$plusitem = $ARGV[1] if $#ARGV >= 1;
$combatrate = $ARGV[2] if $#ARGV >= 2;

$combatrate /= 100 if $combatrate > 1;

# Reject wheel.  This is 1/3 of noncombats.
# R = natural combat rate
# 1-R = NC rate
# (1-R)/3 = wheel rate
# Effective combat rate = R / (1 - (1-R)/3)
$combatrate = $combatrate /  (1 - (1 - $combatrate) / 3);

# Assume we olfact goths.  Assume olfaction is *always* on, and there is
# no refractory period for re-sniffing.  This is, of course, a silly
# assumption.  But hey.  We're also ignoring pick-pocketing.
my $gothrate = 0.5470;
my $otherrate = (1 - $gothrate) / 5;


# These item lists include prices.  For the smashables, I went with mall
# prices harvested on 2010-03-28.  For warm subjects, the value is the
# average meat output of using them.  For everything else, autosell value.

my @gothitems = (
  [ "APJ", 0.30, 136 ],
  [ "candle", 0.30, 144 ],
  [ "warm", 0.30, 450 ],
);

my @otheritems = (
  [ "D", 0.40, 135 ],
  [ "G", 0.40, 143 ],
  [ "fanfic", 0.30, 132 ],
  [ "fur", 0.40, 129 ],
  [ "mask", 0.10, 550 ],
  [ "chaos", 0.20, 124 ],
  [ "plot", 0.20, 128 ],
  [ "prob pot", 0.30, 128 ],
  [ "procrast", 0.30, 138 ],
  [ "candy", 0.30, 137 ],
  [ "needle", 0.30, 550 ],
  [ "rub", 0.30, 141 ],
  [ "whistle", 0.05, 350 ],
);

my $ncmeat = 423;	# Average meat for one of the non-wheel noncombats

my $meatmult = 1 + $plusmeat / 100;
my $itemmult = 1 + $plusitem / 100;

my $meat = $ncmeat * (1 - $combatrate);
print "Noncombats: $meat\n" if $verbose;

my $tmp = 150 * $combatrate * $meatmult;
print "Giants: $tmp\n" if $verbose;
$meat += $tmp;

my ($item, $m, $r);
$tmp = 0;
for $item ( @gothitems ) {
    $r = $item->[1] * $itemmult;
    $r = 1 if $r > 1;
    $m = $item->[2] * $r * $combatrate * $gothrate;
    print "$item->[0] rate=$r meat=$m\n" if $verbose;
    $meat += $m;
}

for $item ( @otheritems ) {
    $r = $item->[1] * $itemmult;
    $r = 1 if $r > 1;
    $m = $item->[2] * $r * $combatrate * $otherrate;
    print "$item->[0] rate=$r meat=$m\n" if $verbose;
    $meat += $m;
}

print "+meat: $plusmeat%; +item: $plusitem%; eff. combat rate: $combatrate\n";
print "Total meat per adventure: $meat\n";
