{$temp['name']}";
}
}
function printresults ($self, $opp1, $opp2, $opp3, $opp4, $opp5) {
global $maxweight, $combat;
echo "You are using: {$self['name']}
";
for($i = 1; $i <= $maxweight; $i++)
$weights[$i] = '';
for($i = 1; $i <= 5; $i++) {
for($j = 0; $j < 4; $j++) {
if(${"opp" . $i}[$j] == 0) {
$x = 1;
$power = 5;
if(${"opp" . $i}['weight'] == 1000)
$power = 1000;
} else {
$x = 0;
$power = ${"opp" . $i}['weight'] + ${"opp" . $i}[$j]*3;
}
if($self[$j] != 0) {
if($x == 1 && $weights[($power + 3) - 3*$self[$j]] == '')
$weights[($power + 3) - 3*$self[$j]] = "{$combat[$j]} versus {${'opp' . $i}['name']} ({${'opp' . $i}['weight']} pound)";
else if($x == 0)
$weights[($power + 3) - 3*$self[$j]] = "{$combat[$j]} versus {${'opp' . $i}['name']} ({${'opp' . $i}['weight']} pound)";
}
}
}
for($i = 1; $i < $maxweight; $i++) {
if($weights[$i] != '')
echo "At weight $i, do $weights[$i]
";
}
echo '
';
echo '';
}
class Familiar {
public $name; // string
public $cagematch; // strength, 0..3
public $scavenger; // ...
public $obstacle; // ...
public $hidenseek; // ...
public function __construct($n, $c, $s, $o, $h) {
$this->name = $n;
$this->cagematch = $c;
$this->scavenger = $s;
$this->obstacle = $o;
$this->hidenseek = $h;
}
}
function read_fams() {
global $familiar, $datafile;
$lines = file($datafile);
foreach ($lines as $i => $line) {
list($c, $s, $o, $h, $name) = preg_split('/ +/', $line, 5);
$familiar[$i] = new Familiar($name, $c, $s, $o, $h);
}
}
function get_familiar ($var, $weight) {
global $familiar;
return array($familiar[$var]->cagematch, $familiar[$var]->scavenger,
$familiar[$var]->obstacle, $familiar[$var]->hidenseek,
'name' => $familiar[$var]->name, 'weight' => $weight);
}
function get_famcount() {
global $familiar;
return count($familiar);
}
function get_opponent($var) {
$index = 1;
for($i = 0; $i < get_famcount(); $i++) {
$temp = $_POST["w$i"];
if($temp != '') {
if($index == $var)
return get_familiar($i, $temp);
else
$index = $index + 1;
}
}
return array(0,0,0,0, 'name' => 'Unknown', 'weight' => 1000);
}
function intro() {
echo "Kingdom of Loathing Familiar Tool
\n";
echo 'Original version by Xylpher (#540421)
'."\n";
echo 'Modifications by greycat (#692002)
'."\n";
echo 'Thanks to The Rye for their already excellent familiar tool';
echo ' which is the source for most of the information used herein.
'."\n";
echo 'Neither Xylpher nor greycat can be held responsible for any loss or personal injury incurred by use or misuse of this tool.
'."\n";
echo 'Source code. Remember, folks, greycat did not write this; he only modified it. Xylpher is the original author and deserves the credit.
'."\n";
echo 'Note that this tool will not yield 100% perfect results. I [Xylpher] thought every battle would have a weight at which you would get 5 XP when I started building this, but it seems they don\'t. So there might be occurences of losing or getting 4 or even 3 XP. They should be sporadic though.
'."\n";
}
function outro() {
global $datafile;
echo "Noteworthy Changes:
\n";
echo '2009-03-04: Sixteen new familiars to add, none of which are on the rye\'s site. Six of these aren\'t even fully spaded yet (at least not on the wiki), so don\'t rely on this tool to work for those familiars. They\'re the ones with XX in front of their names.
'."\n";
echo "2009-11-10: Major rewrite of the familiar data-reading code by greycat. Data are now stored in a separate file and read at run-time, instead of being hard-coded in this script. Also attempted to fix any other bugs that made themselves known during this rewrite.
\n";
echo "2009-11-10: Many of the arena strength values for familiars as listed on The Rye's site and the wiki disagree. I'm going with the wiki values. The data file needs to be re-checked for accuracy.
\n";
}
function metadata() {
global $datafile;
echo "Data: " . get_famcount() . " familiars, last modified ";
$stat = stat($datafile);
echo gmstrftime("%Y-%m-%d %H:%M", $stat['mtime']) . " UTC
\n";
}
$var='';
if(isset($_POST['class'])) { $var = $_POST['class']; }
read_fams();
if($var == 'layout2') {
intro();
echo '';
// Old layout needs instructions.
echo 'Enter weights of Cake-Shaped Arena opponents in the boxes, and select your own familiar with the radio buttons.
'."\n";
echo '';
metadata();
outro();
} else if($var == '') {
intro();
echo '';
echo '';
metadata();
outro();
} else {
if($_POST['layout'] == 1) {
$array0 = get_familiar($var, 0);
for($i = 1; $i <= 5; $i++) {
if($_POST["w{$i}"] != '')
${"array" . $i} = get_familiar($_POST["opp{$i}"], $_POST["w{$i}"]);
else
${"array" . $i} = array(0,0,0,0, 'name' => 'Unknown', 'weight' => 1000);
}
printresults($array0, $array1, $array2, $array3, $array4, $array5);
}
if($_POST['layout'] == 2) {
$array0 = get_familiar($var, 0);
$array1 = get_opponent(1);
$array2 = get_opponent(2);
$array3 = get_opponent(3);
$array4 = get_opponent(4);
$array5 = get_opponent(5);
printresults($array0, $array1, $array2, $array3, $array4, $array5);
}
}
?>