if ($house['data']['store'][$iitem]) {
                     output("You decide to use the materials that are already hanging around.  There's still %s of these left.`n`n", $house['data']['store'][$iitem]);
                 } else {
                     output("You decide to use the materials that are already hanging around.  That was the last one.`n`n");
                 }
             } else {
                 output("Before you can get started, you realise someone has already depleted the materials store!`n`n");
                 improbablehousing_bottomnavs($house, $rid);
                 page_footer();
                 $interrupt = true;
             }
         } else {
             //determine iitems to use, and use them - assume we're using iitems from the Main inventory
             use_item($iitem);
             if ($iitem != "toolbox_carpentry" && $iitem != "toolbox_masonry") {
                 $qleft = has_item_quantity($iitem);
                 if ($qleft == 1) {
                     $iname = get_item_setting("verbosename", $iitem);
                 } else {
                     $iname = get_item_setting("plural", $iitem);
                 }
                 if (!$qleft) {
                     $qleft = "no";
                 }
                 output("You have %s %s left.`n`n", $qleft, $iname);
             }
         }
     }
 }
 if ($interrupt) {
     break;
function meatsystem_run()
{
    global $session;
    require_once "modules/staminasystem/lib/lib.php";
    page_header("Meat!");
    addnav("Meat Skills");
    $from = httpget('from');
    switch (httpget('op')) {
        case "devour":
            //special ability for Zombies only - Zombies can eat raw meat, so we're giving them the ability to simply devour the carcass where it lies.
            $carcasses = unserialize(get_module_pref("carcasses"));
            if (!is_array($carcasses)) {
                $carcasses = array();
            }
            debug($carcasses);
            foreach ($carcasses as $carcassnum => $creatureid) {
                $sql = "SELECT creaturename FROM " . db_prefix("creatures") . " WHERE creatureid = " . $creatureid . " ";
                $result = db_query_cached($sql, "creaturename-" . $creatureid, 86400);
                $creature = db_fetch_assoc($result);
                output("Giving in to your primal urges, you lean down and begin ripping meat from the still-twitching %s with your teeth.`n`n", $creature['creaturename']);
                $meat1 = get_module_objpref("creatures", $creatureid, "meat1");
                $meat2 = get_module_objpref("creatures", $creatureid, "meat2");
                $meat3 = get_module_objpref("creatures", $creatureid, "meat3");
                for ($i = 0; $i < $meat1; $i++) {
                    increment_module_pref("nutrition", 1, "staminafood");
                    increment_module_pref("fat", 3, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(1000);
                }
                for ($i = 0; $i < $meat2; $i++) {
                    increment_module_pref("nutrition", 2, "staminafood");
                    increment_module_pref("fat", 2, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(2000);
                }
                for ($i = 0; $i < $meat3; $i++) {
                    increment_module_pref("nutrition", 3, "staminafood");
                    increment_module_pref("fat", 1, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(5000);
                }
                output("For the record, and since it's nice to know these things even if you're too busy tearing cartilage and muscle from the bone to really pay attention to them, in this meal you have eaten %s bite's-worth of Crap Meat, %s bite's-worth of Half-Decent Meat, and %s bite's-worth of Tasty Meat.`n", $meat1, $meat2, $meat3);
                $full = get_module_pref("fullness", "staminafood");
                if ($full < 0) {
                    output("You still feel as though you haven't eaten in days.`n`n");
                }
                if ($full >= 0 && $full < 50) {
                    output("You feel a little less hungry.`n`n");
                }
                if ($full >= 50 && $full < 100) {
                    output("You still feel as though you've got room for more!`n`n");
                }
                if ($full >= 100) {
                    output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
                }
                unset($carcasses[$carcassnum]);
                set_module_pref("carcasses", serialize($carcasses));
            }
            break;
        case "clean":
            $creatureid = httpget('creatureid');
            $carcass = httpget('carcass');
            $meat1 = get_module_objpref("creatures", $creatureid, "meat1");
            $meat2 = get_module_objpref("creatures", $creatureid, "meat2");
            $meat3 = get_module_objpref("creatures", $creatureid, "meat3");
            $amber = get_stamina();
            $return = process_action("Cleaning the Carcass");
            if ($return['lvlinfo']['levelledup'] == true) {
                output("`n`c`b`0You gained a level in Cleaning Carcasses!  You are now level %s!  This action will cost fewer Stamina points now, so you can butcher more creatures each day!`b`c`n", $return['lvlinfo']['newlvl']);
            }
            $failchance = e_rand(0, 100);
            if ($failchance > $amber) {
                //failure - the nice meat gets turned into Crap Meat
                $meat1 += $meat2;
                $meat1 += $meat3;
                output("`4You sit down to clean the carcass.  Your exhausted, clumsy incisions make a mockery of the choicest cuts - what is left over can only be described as Crap Meat.  %s bite's-worth, to be precise.  It looks like it was hacked into chunks by a blind woodsman.", $meat1);
                //todo
                for ($i = 0; $i < $meat1; $i++) {
                    give_item("meat_low", false, false, true);
                }
                load_inventory();
                $carcasses = unserialize(get_module_pref("carcasses"));
                unset($carcasses[$carcass]);
                $carcasses = array_values($carcasses);
                set_module_pref("carcasses", serialize($carcasses));
            } else {
                //success - all meat is sorted
                output("You spend a few minutes up to your elbows in gore, and getting rather hungry.`n");
                if ($meat1 > 0) {
                    output("You tear off enough to make %s rough bite's-worth of what the locals affectionately call Crap Meat.  It's mostly wobbling chunks of stinking yellow fat, intermingled with the occasional squirmy tendon.`n", $meat1);
                }
                if ($meat2 > 0) {
                    output("You make swift work of the fattier muscle, and before too long you have %s rough bite's-worth of Half-Decent Meat.`n", $meat2);
                }
                if ($meat3 > 0) {
                    output("The red, tender slivers of muscle slide easily from the bone, and you wind up with %s rough bite's-worth of Tasty Meat.`n", $meat3);
                }
                //todo
                for ($i = 0; $i < $meat1; $i++) {
                    give_item("meat_low", false, false, true);
                }
                for ($i = 0; $i < $meat2; $i++) {
                    give_item("meat_medium", false, false, true);
                }
                for ($i = 0; $i < $meat3; $i++) {
                    give_item("meat_high", false, false, true);
                }
                load_inventory();
                $carcasses = unserialize(get_module_pref("carcasses"));
                unset($carcasses[$carcass]);
                $carcasses = array_values($carcasses);
                set_module_pref("carcasses", serialize($carcasses));
                $pmeat1 = has_item("meat_low");
                $pmeat2 = has_item("meat_medium");
                $pmeat3 = has_item("meat_high");
                if (($pmeat1 || $pmeat2 || $pmeat3) && $session['user']['race'] != "Robot") {
                    if (get_module_pref("fullness", "staminafood") < 100) {
                        $cookcost = stamina_getdisplaycost("Cooking");
                        addnav(array("Cook up some meat (`Q%s%%`0)", $cookcost), "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                    } else {
                        addnav("You're too full to cook, let alone eat", "");
                    }
                }
            }
            break;
        case "cook":
            $pmeat1qty = has_item_quantity("meat_low");
            $pmeat2qty = has_item_quantity("meat_medium");
            $pmeat3qty = has_item_quantity("meat_high");
            output("You whip out your camping stove.  It's time to cook!`n`nWhat will you put in the pan?  You can fit up to 20 bite's-worth of meat in there.  Right now you have %s bite's-worth of Crap Meat, %s bite's-worth of Half-Decent Meat, and %s bite's-worth of Tasty Meat.`n`n", $pmeat1qty, $pmeat2qty, $pmeat3qty);
            rawoutput("<form action='runmodule.php?module=meatsystem&op=cookfinal&from=" . $from . "' method='POST'>");
            rawoutput("Put in <input name='meat1' width='2' value='0'> bite's-worth of Crap Meat.<br />");
            rawoutput("Put in <input name='meat2' width='2' value='0'> bite's-worth of Half-Decent Meat.<br />");
            rawoutput("Put in <input name='meat3' width='2' value='0'> bite's-worth of Tasty Meat.<br />");
            rawoutput("<input type='submit' class='button' value='" . translate_inline("Cook!") . "'>");
            rawoutput("</form>");
            addnav("", "runmodule.php?module=meatsystem&op=cookfinal&from=" . $from);
            break;
        case "cookfinal":
            $pmeat1qty = has_item_quantity("meat_low");
            $pmeat2qty = has_item_quantity("meat_medium");
            $pmeat3qty = has_item_quantity("meat_high");
            $meat1 = httppost("meat1");
            $meat2 = httppost("meat2");
            $meat3 = httppost("meat3");
            //check for the dumbass player cooking meat that they don't have
            if ($meat1 > $pmeat1qty || $meat2 > $pmeat2qty || $meat3 > $pmeat3qty) {
                output("You don't `ihave`i that much meat!`n`n");
                addnav("Whoops");
                addnav("Sorry, I forgot how to count for a second there.  Let's try this again.", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player inputting a negative number
            if ($meat1 < 0 || $meat2 < 0 || $meat3 < 0) {
                page_header("Either taking vegetarianism to whole new levels, or trying to grow meat from an empty pan");
                output("You want to cook `inegative`i meat?  How very Zen of you.`n`n");
                addnav("You sneaky bugger");
                addnav("Abandon your efforts to produce the opposite of meat and try again, pretending that you weren't just trying to cheat.", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player trying to put too much meat in the pan
            $totalmeat = $meat1 + $meat2 + $meat3;
            if ($totalmeat > 20) {
                output("Your pan can't hold that much meat, pal.`n`n");
                addnav("Whoops");
                addnav("Try again, without filling the pan up so much", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player trying to cook no meat at all
            $totalmeat = $meat1 + $meat2 + $meat3;
            if ($totalmeat == 0) {
                output("You start the process of cooking up your tasty meat.  After a few minutes of poking around in your pan, growing hungrier by the second, you realise that you've forgotten something.`n`n");
                addnav("Whoops");
                addnav("Try again, with meat this time", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //Stamina interaction, including consequences and level-up details.
            $amber = get_stamina();
            $return = process_action("Cooking");
            if ($return['lvlinfo']['levelledup'] == true) {
                output("`n`c`b`0You gained a level in Cooking!  You are now level %s!  This action will cost fewer Stamina points now, so you can cook more tasty meals each day!`b`c`n", $return['lvlinfo']['newlvl']);
            }
            $failchance = e_rand(0, 100);
            if ($failchance > $amber) {
                output("`4You put your meat into the pan, and sit down to stir-fry it.  The hypnotic motion and white-noise sizzling, combined with your tiredness, sends you staring into space.  While your concentration is impaired, the meat bursts into flames.  You jerk back into awareness, and look down sadly at the flaming chunks.  Bummer.");
                for ($i = 0; $i < $meat1; $i++) {
                    delete_item(has_item("meat_low"));
                }
                for ($i = 0; $i < $meat2; $i++) {
                    delete_item(has_item("meat_medium"));
                }
                for ($i = 0; $i < $meat3; $i++) {
                    delete_item(has_item("meat_high"));
                }
                break;
            }
            //we can now assume that the player is not some sort of cheating reprobate, or trying to cook while dog-tired, and do some cooking!
            for ($i = 0; $i < $meat1; $i++) {
                increment_module_pref("nutrition", 1, "staminafood");
                increment_module_pref("fat", 3, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_low"));
                addstamina(1000);
            }
            for ($i = 0; $i < $meat2; $i++) {
                increment_module_pref("nutrition", 2, "staminafood");
                increment_module_pref("fat", 2, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_medium"));
                addstamina(2000);
            }
            for ($i = 0; $i < $meat3; $i++) {
                increment_module_pref("nutrition", 3, "staminafood");
                increment_module_pref("fat", 1, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_high"));
                addstamina(5000);
            }
            output("You fry up your lovely meaty loveliness, and sit down to eat.  You gain some Stamina!`n`n");
            $full = get_module_pref("fullness", "staminafood");
            if ($full < 0) {
                output("You still feel as though you haven't eaten in days.`n`n");
            }
            if ($full >= 0 && $full < 50) {
                output("You feel a little less hungry.`n`n");
            }
            if ($full >= 50 && $full < 100) {
                output("You still feel as though you've got room for more!`n`n");
            }
            if ($full >= 100) {
                output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
            }
            break;
    }
    $carcasses = unserialize(get_module_pref("carcasses"));
    if (!is_array($carcasses)) {
        $carcasses = array();
    }
    if (count($carcasses) > 0) {
        output("You look at the spoils of your most recent battle.  They lie bloodied and broken on the ground.  What will you do with them?");
        foreach ($carcasses as $carcassnum => $creatureid) {
            $sql = "SELECT creaturename FROM " . db_prefix("creatures") . " WHERE creatureid = " . $creatureid . " ";
            $result = db_query_cached($sql, "creaturename-" . $creatureid, 86400);
            $creature = db_fetch_assoc($result);
            $cleancost = stamina_getdisplaycost("Cleaning the Carcass");
            addnav(array("Clean the carcass of %s (`Q%s%%`0)", $creature['creaturename'], $cleancost), "runmodule.php?module=meatsystem&op=clean&creatureid=" . $creatureid . "&carcass=" . $carcassnum . "&from=" . $from);
        }
    } else {
        if (httpget('op') != "cook" && httpget('op') != "cookfinal") {
            output("Now only bloody bones lie strewn around the area.`n`n");
        }
    }
    addnav("Ah, screw it.");
    if ($from == "forest") {
        addnav("Return to the Jungle", "forest.php");
    } else {
        if ($from == "world") {
            addnav("Return to the World Map", "runmodule.php?module=worldmapen&op=continue");
        }
    }
    page_footer();
    return true;
}
            $house['data']['store'][$takeitem] -= $q;
            load_inventory();
            output("Okay.  You pick up every single one, and stuff them all into your Backpack.`n`n");
        } else {
            give_item($takeitem);
            $house['data']['store'][$takeitem] -= 1;
            output("Okay.  You pick up the item and stuff it into your Backpack.`n`n");
        }
        improbablehousing_sethousedata($house);
    }
}
output("You can drop materials directly into this Dwelling, if you like.  However, once materials have been dropped in a Dwelling, they can only be used for construction within this Dwelling.  Only the Dwelling owner (or someone with an equivalent key) can remove them from the Dwelling.  This can help prevent materials from going missing unexpectedly (or, if you prefer, being pinched by Thieving Midget Bastards or Other Unsavoury Types), and it can be a nice surprise for the Dwelling owner.`n`n");
output("Currently, this Materials Store holds:`n");
addnav("Give Materials");
foreach ($house['data']['store'] as $storeitem => $number) {
    $qty = has_item_quantity($storeitem);
    if ($qty > 0) {
        $hasitems = 1;
        addnav(array("Give a %s (you have %s)", get_item_setting("verbosename", $storeitem), $qty), "runmodule.php?module=improbablehousing&op=store&giveiitem={$storeitem}&hid={$hid}&rid={$rid}");
    }
    if ($qty > 1) {
        addnav(array("Give all your %s", get_item_setting("plural", $storeitem)), "runmodule.php?module=improbablehousing&op=store&giveiitem={$storeitem}&giveall=true&hid={$hid}&rid={$rid}");
    }
    if ($keytype >= 100) {
        if ($number > 0) {
            addnav(array("Take a %s", get_item_setting("verbosename", $storeitem)), "runmodule.php?module=improbablehousing&op=store&takeiitem={$storeitem}&hid={$hid}&rid={$rid}");
        }
        if ($number > 1) {
            addnav(array("Take all %s", get_item_setting("plural", $storeitem)), "runmodule.php?module=improbablehousing&op=store&takeiitem={$storeitem}&takeall=true&hid={$hid}&rid={$rid}");
        }
    }
function staminafood_run()
{
    global $session;
    $pmeat1 = has_item_quantity("meat_low");
    $pmeat2 = has_item_quantity("meat_medium");
    $pmeat3 = has_item_quantity("meat_high");
    addnav("Eat");
    switch (httpget("op")) {
        case "sellmeat":
            switch ($session['user']['location']) {
                case "NewHome":
                    page_header("Joe's Diner");
                    if (httpget('q') == 1) {
                        delete_item(has_item("meat_medium"));
                        $session['user']['gold'] += 5;
                        output("With a surly grunt, Joe grabs your meat and slaps down five Requisition tokens.`n`n");
                    } else {
                        for ($i = 1; $i <= $pmeat2; $i++) {
                            delete_item(has_item("meat_medium"));
                            $session['user']['gold'] += 5;
                        }
                        output("With a surly grunt, Joe grabs your meat and slaps down %s Requisition tokens.`n`n", $pmeat2 * 5);
                    }
                    break;
                case "New Pittsburgh":
                    page_header("BRAAAAAINS");
                    if (httpget('q') == 1) {
                        delete_item(has_item("meat_medium"));
                        $session['user']['gold'] += 6;
                        output("With a nod, the waiter takes your meat and hands back six Requisition tokens.`n`n");
                    } else {
                        for ($i = 1; $i <= $pmeat2; $i++) {
                            delete_item(has_item("meat_medium"));
                            $session['user']['gold'] += 6;
                        }
                        output("With a nod, the waiter takes your meat and hands back %s Requisition tokens.`n`n", $pmeat2 * 6);
                    }
                    break;
                case "Kittania":
                    page_header("Cool Springs Cafe");
                    if (httpget('q') == 1) {
                        delete_item(has_item("meat_high"));
                        $session['user']['gold'] += 12;
                        output("With a warm smile, the waitress takes your meat and hands back twelve Requisition tokens.`n`n");
                    } else {
                        for ($i = 1; $i <= $pmeat3; $i++) {
                            delete_item(has_item("meat_high"));
                            $session['user']['gold'] += 12;
                        }
                        output("With a warm smile, the waitress takes your meat and hands back %s Requisition tokens.`n`n", $pmeat3 * 12);
                    }
                    break;
                case "Squat Hole":
                    page_header("Kebabs 'N' S***e");
                    if (httpget('q') == 1) {
                        delete_item(has_item("meat_low"));
                        $session['user']['gold'] += 2;
                        output("With a squeaky \"Ta mate,\" the Midget behind the counter relieves you of the stinking yellow meat and hands back two Requisition tokens.`n`n");
                    } else {
                        for ($i = 1; $i <= $pmeat1; $i++) {
                            delete_item(has_item("meat_low"));
                            $session['user']['gold'] += 2;
                        }
                        output("With a squeaky \"Ta mate,\" the Midget behind the counter relieves you of the stinking yellow meat and hands back %s Requisition tokens.`n`n", $pmeat1 * 2);
                    }
                    break;
            }
            break;
        case "start":
            switch (httpget("location")) {
                case "nh":
                    page_header("Joe's Diner");
                    output("`0You head into what presents itself as a 1950's-style diner.  Plastic red and white gingham patterns cover every available surface.  Tomato-shaped ketchup bottles are dotted on tables here and there, dried gunge crusting their nozzles.  Behind the bar can be seen Joe, the owner, who is keeping himself busy wiping down the counter tops with a rag, redistributing the half-inch-thick layer of grease into a more uniform level.  A sign above the counter reads \"`2WE BUY MEAT.  WE PAY 5 REQ PER 120 GRAM'S.`0\"`n`n");
                    if ($session['user']['race'] != "Robot") {
                        output("The smell of fried onions does its wicked work, and you glance up at the menu.`n`n");
                        if (get_module_pref("fullness") <= 100) {
                            if ($session['user']['gold'] >= 10) {
                                addnav("Crisps (10 Req)", "runmodule.php?module=staminafood&op=buy&bought=1");
                            } else {
                                output("After a careful read of the menu, you realise that you can't afford a single thing on it.  Bah.");
                            }
                            if ($session['user']['gold'] >= 40) {
                                addnav("Garden Salad (40 Req)", "runmodule.php?module=staminafood&op=buy&bought=2");
                            }
                            if ($session['user']['gold'] >= 50) {
                                addnav("Plate of Chips (50 Req)", "runmodule.php?module=staminafood&op=buy&bought=3");
                                addnav("Coffee (50 Req)", "runmodule.php?module=staminafood&op=buy&bought=4");
                            }
                            if ($session['user']['gold'] >= 150) {
                                addnav("Bangers & Mash (150 Req)", "runmodule.php?module=staminafood&op=buy&bought=5");
                            }
                            if ($session['user']['gold'] >= 300) {
                                addnav("Cheeseburger (300 Req)", "runmodule.php?module=staminafood&op=buy&bought=6");
                            }
                        } else {
                            output("You are far too full to eat any more today.`n`n");
                        }
                    }
                    if ($pmeat2) {
                        output("You remember that Maiko told you that the NewHome diner will only buy middling-quality meat.  You have %s pieces of average-quality meat to sell.  All of them, quite conveniently - perhaps a little TOO conveniently - weigh exactly a hundred and twenty grams each.`n`n", $pmeat2);
                        addnav("Sell Meat");
                        addnav("Sell one piece", "runmodule.php?module=staminafood&op=sellmeat&q=1");
                        if ($pmeat2 > 1) {
                            addnav("Sell all Meat", "runmodule.php?module=staminafood&op=sellmeat&q=all");
                        }
                    }
                    break;
                case "ki":
                    page_header("Cool Springs Cafe");
                    output("You head into what at first appears to be a little hut.  As you work down the stairs into the rock underneath Kittania, you realise that this place is so much more.`n`nStrings of fairy lights illuminate the cavern, and soft trickling sounds can be heard against the laughter and conversation of KittyMorphs around you.`n`nYou take a seat and a white-furred KittyMorph approaches, a menu in her hand.  \"Welcome to the Cool Springs Cafe,\" she says with a smile.  \"We try to tread on Mother Earth as lightly as we can, in here; all of our produce is locally-grown, you'll find a wonderful selection of vegetarian and vegan meals, and the various waters come from the three springs that run through this very cavern.  Now, what can I get you?\"`n`nYou peruse the menu, your eyes lingering on the last entry, detailing a rare, dripping, bloody steak.  The KittyMorph follows your gaze, and laughs sheepishly.  \"Like I said, we `itry`i,\" she giggles, elongated canines peeking out.  \"We `iare`i carnivores, you know.  Oh, on that note, I should mention that we also buy meat, if you've got any of the good stuff to sell.  We pay twelve Requisition per slice.\"`n`n");
                    if ($session['user']['race'] != "Robot") {
                        if (get_module_pref("fullness") <= 100) {
                            if ($session['user']['gold'] >= 50) {
                                addnav("Hot Chocolate (50 Req)", "runmodule.php?module=staminafood&op=buy&bought=7");
                                addnav("White Spring Water (50 Req)", "runmodule.php?module=staminafood&op=buy&bought=8");
                            } else {
                                output("After a careful read of the menu, you realise that you can't afford a single thing on it.  Bah.");
                            }
                            if ($session['user']['gold'] >= 100) {
                                addnav("Nut and Berry Salad (100 Req)", "runmodule.php?module=staminafood&op=buy&bought=9");
                            }
                            if ($session['user']['gold'] >= 175) {
                                addnav("Turquoise Spring Water (175 Req)", "runmodule.php?module=staminafood&op=buy&bought=10");
                            }
                            if ($session['user']['gold'] >= 250) {
                                addnav("Red Spring Water (250 Req)", "runmodule.php?module=staminafood&op=buy&bought=11");
                            }
                            if ($session['user']['gold'] >= 500) {
                                addnav("Still-Twitching Steak (500 Req)", "runmodule.php?module=staminafood&op=buy&bought=12");
                            }
                        } else {
                            output("You are far too full to eat any more today.`n`n");
                        }
                    }
                    if ($pmeat3) {
                        output("You remember that Maiko told you that the Kittania cafe will only buy the best-quality meat.  You have %s pieces of high-quality meat to sell.`n`n", $pmeat3);
                        addnav("Sell Meat");
                        addnav("Sell one piece", "runmodule.php?module=staminafood&op=sellmeat&q=1");
                        if ($pmeat3 > 1) {
                            addnav("Sell all Meat", "runmodule.php?module=staminafood&op=sellmeat&q=all");
                        }
                    }
                    break;
                case "np":
                    page_header("BRAAAAAINS");
                    output("You head into the local cafe, imaginatively titled \"BRAAAAAINS\".  A waiter comes shuffling over to you, green skin peeling from his face.  \"BRAAAAAINS?\" he asks, holding out a menu.`n`nA sign above the counter says \"We are only too happy to buy your surplus meat.  We pay 6 Requisition tokens per 120 grams.\"`n`n");
                    if ($session['user']['race'] != "Robot") {
                        if (get_module_pref("fullness") <= 100) {
                            if ($session['user']['gold'] >= 50) {
                                addnav("Egg and Brains (50 Req)", "runmodule.php?module=staminafood&op=buy&bought=13");
                            } else {
                                output("After a careful read of the menu, you realise that you can't afford a single thing on it.  Bah.");
                            }
                            if ($session['user']['gold'] >= 100) {
                                addnav("Sausage and Brains (100 Req)", "runmodule.php?module=staminafood&op=buy&bought=14");
                            }
                            if ($session['user']['gold'] >= 150) {
                                addnav("Spam and Brains (150 Req)", "runmodule.php?module=staminafood&op=buy&bought=15");
                            }
                            if ($session['user']['gold'] >= 200) {
                                addnav("Egg, Brains, Sausage and Brains (200 Req)", "runmodule.php?module=staminafood&op=buy&bought=16");
                            }
                            if ($session['user']['gold'] >= 250) {
                                addnav("Brains, Spam, Brains, Sausage and Brains (250 Req)", "runmodule.php?module=staminafood&op=buy&bought=17");
                            }
                            if ($session['user']['gold'] >= 300) {
                                addnav("Brains, Brains, Brains, Brains and Spam (300 Req)", "runmodule.php?module=staminafood&op=buy&bought=18");
                            }
                        } else {
                            output("You are far too full to eat any more today.`n`n");
                        }
                    }
                    if ($pmeat2) {
                        output("You remember that Maiko told you that the New Pittsburgh diner will only buy middling-quality meat.  You have %s pieces of average-quality meat to sell.  All of them, quite conveniently - perhaps a little TOO conveniently - weigh a hundred and twenty grams each.`n`n", $pmeat2);
                        addnav("Sell Meat");
                        addnav("Sell one piece", "runmodule.php?module=staminafood&op=sellmeat&q=1");
                        if ($pmeat2 > 1) {
                            addnav("Sell all Meat", "runmodule.php?module=staminafood&op=sellmeat&q=all");
                        }
                    }
                    break;
                case "sq":
                    page_header("Kebabs 'N' S***e");
                    output("You head into the local kebab house.  As you're studying the menu, a Midget brushes past you, dragging a six-foot blue plastic bag with the words \"INCINERATE ONLY\" stencilled on the side.  He stops, glares up at you, and mutters \"Yer din't see `inuffink.`i\"  Then he resumes his journey, dragging the bag into the back of the shop.  You're sure you saw a bit of steering wheel poking out.`n`nA sign above the counter reads \"WE BY MEET 2 REK PER BIT\"`n`n");
                    if ($session['user']['race'] != "Robot") {
                        if (get_module_pref("fullness") <= 100) {
                            if ($session['user']['gold'] >= 20) {
                                addnav("Crisps (20 Req)", "runmodule.php?module=staminafood&op=buy&bought=25");
                            } else {
                                output("After a careful read of the menu, you realise that you can't afford a single thing on it.  Bah.");
                            }
                            if ($session['user']['gold'] >= 50) {
                                addnav("Skinheads on a Raft (50 Req)", "runmodule.php?module=staminafood&op=buy&bought=26");
                            }
                            if ($session['user']['gold'] >= 75) {
                                addnav("Doner Kebab (75 Req)", "runmodule.php?module=staminafood&op=buy&bought=27");
                                addnav("Crimson Pitbull (75 Req)", "runmodule.php?module=staminafood&op=buy&bought=28");
                            }
                            if ($session['user']['gold'] >= 150) {
                                addnav("C**k Nuggets (150 Req)", "runmodule.php?module=staminafood&op=buy&bought=29");
                            }
                            if ($session['user']['gold'] >= 200) {
                                addnav("Sausage Feast Pizza (200 Req)", "runmodule.php?module=staminafood&op=buy&bought=30");
                            }
                        } else {
                            output("You are far too full to eat any more today.`n`n");
                        }
                    }
                    if ($pmeat1) {
                        output("You remember that Maiko told you that the Squat Hole kebab shop only buys the sort of meat that the dog food factory would throw away.  You have %s wobbling chunks of Crap Meat to sell.`n`n", $pmeat1);
                        addnav("Sell Meat");
                        addnav("Sell one piece", "runmodule.php?module=staminafood&op=sellmeat&q=1");
                        if ($pmeat1 > 1) {
                            addnav("Sell all Meat", "runmodule.php?module=staminafood&op=sellmeat&q=all");
                        }
                    }
                    break;
                case "pl":
                    page_header("Mutated Munchies");
                    if ($session['user']['race'] != "Robot") {
                        output("You head into the local cafe.  The stench of vomit and disinfectant hangs in the air.  Bravely, you sit down at a table and peruse the menu.`n`n");
                        if (get_module_pref("fullness") <= 100) {
                            if ($session['user']['gold'] >= 100) {
                                addnav("Wriggly Biscuits (100 Req)", "runmodule.php?module=staminafood&op=buy&bought=19");
                            } else {
                                output("After a careful read of the menu, you realise that you can't afford a single thing on it.  Bah.");
                            }
                            if ($session['user']['gold'] >= 200) {
                                addnav("Phallic Nuts (200 Req)", "runmodule.php?module=staminafood&op=buy&bought=20");
                            }
                            if ($session['user']['gold'] >= 300) {
                                addnav("Noodly Noodles (300 Req)", "runmodule.php?module=staminafood&op=buy&bought=21");
                            }
                            if ($session['user']['gold'] >= 400) {
                                addnav("Three-Eyed Fish (400 Req)", "runmodule.php?module=staminafood&op=buy&bought=22");
                            }
                            if ($session['user']['gold'] >= 500) {
                                addnav("Magical Mystery Meatloaf (500 Req)", "runmodule.php?module=staminafood&op=buy&bought=23");
                            }
                            if ($session['user']['gold'] >= 750) {
                                addnav("Mutant Steak (750 Req)", "runmodule.php?module=staminafood&op=buy&bought=24");
                            }
                        } else {
                            output("You are far too full to eat any more today.`n`n");
                        }
                    } else {
                        output("You are a robot, and this place doesn't buy meat.  You have no business here.  Out with you!`n`n");
                    }
                    break;
            }
            break;
        case "buy":
            page_header("Om nom nom");
            require_once "modules/staminasystem/lib/lib.php";
            switch (httpget("bought")) {
                case 1:
                    output("You munch happily on your crisps, reflecting that they're probably not too good for you - but hell, at least they're cheap.`n`nYou gain some Stamina!");
                    $st = 5000;
                    $nu = 5;
                    $fa = 10;
                    $fu = 5;
                    $co = 10;
                    break;
                case 2:
                    output("You pick the snails out of your Garden Salad, and tuck in.`n`nYou gain some Stamina!");
                    $st = 18000;
                    $nu = 15;
                    $fa = 0;
                    $fu = 10;
                    $co = 40;
                    break;
                case 3:
                    output("You wolf down your plate of chips.  They're like little brown paper bags filled with pus, but damn it, you paid good money for these and you're going to eat them come Hell or high water.`n`nYou gain some Stamina!");
                    $st = 25000;
                    $nu = 20;
                    $fa = 30;
                    $fu = 25;
                    $co = 50;
                    break;
                case 4:
                    output("The coffee swirls grittily down your throat.  You feel like you have more energy!");
                    apply_stamina_buff('newhomedinercoffee', array("name" => "Caffeine Rush", "action" => "Global", "costmod" => 0.8, "expmod" => 1, "rounds" => 20, "roundmsg" => "Your Caffeine Rush makes everything a little bit easier!", "wearoffmsg" => "The effects of the caffeine seem to have worn off."));
                    $co = 50;
                    break;
                case 5:
                    output("It's not so much Bangers and Mash as Mingers and Mush, but you get stuck in anyway.`n`nYou gain some Stamina!");
                    $st = 105000;
                    $nu = 40;
                    $fa = 30;
                    $fu = 40;
                    $co = 150;
                    break;
                case 6:
                    output("You can has cheeseburger!  Well, it's not so much \"cheese\" as \"unidentifiable bright orange goo\", but I'm sure you'll live.`n`nYou gain some Stamina!");
                    $st = 225000;
                    $nu = 60;
                    $fa = 40;
                    $fu = 25;
                    $co = 300;
                    break;
                case 7:
                    output("You sip your hot chocolate, listening to the babbling brooks.  Life ain't so bad.`n`nYou gain some Stamina!");
                    $st = 25000;
                    $nu = 10;
                    $fa = 10;
                    $fu = 15;
                    $co = 50;
                    break;
                case 8:
                    output("There's something very odd about the water from the White Spring.  You feel light on your feet.  It seems to make everything easier, somehow.");
                    apply_stamina_buff('whitespringwater', array("name" => "White Spring Lightness", "action" => "Global", "costmod" => 0.8, "expmod" => 1, "rounds" => 20, "roundmsg" => "The waters of the White Spring seem to be making everything a little easier.", "wearoffmsg" => "The White Spring effects seem to have worn off."));
                    $co = 50;
                    break;
                case 9:
                    output("You scarf down your salad of nuts and berries, secretly wishing for a nice juicy steak.`n`nYou gain some Stamina!");
                    $st = 65000;
                    $nu = 25;
                    $fa = 5;
                    $fu = 10;
                    $co = 100;
                    break;
                case 10:
                    output("The water from the Turquoise Spring is served at room temperature, but somehow tastes very cold.  After a few moments, your eyesight improves; you can make out individual facets of a crystal buried in the far wall of the cavern.  This should make it a bit easier to hunt down monsters!");
                    apply_stamina_buff('turquoisespringwater', array("name" => "Turquoise Sight", "class" => "Hunting", "costmod" => 0.5, "expmod" => 1, "rounds" => 3, "roundmsg" => "Thanks to your heightened senses granted by the waters of the Turquoise Spring, hunting for monsters seems a lot easier now.", "wearoffmsg" => "The effects of the Turquoise Spring water have worn off, and your senses return to their usual state."));
                    $co = 175;
                    break;
                case 11:
                    output("You down the water from the Red Spring.  There's a distinct taste of iron in there.  After a few moments, you become anxious - surely there must be something around here that you can engage in combat...");
                    apply_stamina_buff('redspringwater', array("name" => "Red Haze", "class" => "Combat", "costmod" => 0.5, "expmod" => 1, "rounds" => 20, "roundmsg" => "The waters of the Red Spring make fighting seem more natural and fluid.  You're not expending nearly as much Stamina as usual.", "wearoffmsg" => "The effects of the Red Spring water have worn off, and your senses return to their natural state."));
                    $co = 250;
                    break;
                case 12:
                    output("The menu described a still-twitching steak, and boy, it delivered.  Steam rises from the plate of raw muscle in front of you.  The meat jerks and spasms as it reacts to the sudden flood of oxygen, slapping gently against the plate.  Your mouth waters, and you can see some nearby KittyMorphs glancing jealously in your direction.  You wolf it down before they get any ideas.`n`nYou gain some Stamina!");
                    $st = 385000;
                    $nu = 100;
                    $fa = 10;
                    $fu = 80;
                    $co = 500;
                    break;
                case 13:
                    output("You scarf down your braaaaainy meal, hoping that there will be no complications from the frankly ridiculous amounts of braaaaains that you're eating.`n`nYou gain some Stamina!");
                    $st = 25000;
                    $nu = 10;
                    $fa = 10;
                    $fu = 10;
                    $co = 50;
                    break;
                case 14:
                    output("You scarf down your braaaaainy meal, hoping that there will be no complications from the frankly ridiculous amounts of braaaaains that you're eating.`n`nYou gain some Stamina!");
                    $st = 65000;
                    $nu = 20;
                    $fa = 20;
                    $fu = 20;
                    $co = 100;
                    break;
                case 15:
                    output("You scarf down your braaaaainy meal, hoping that there will be no complications from the frankly ridiculous amounts of braaaaains that you're eating.`n`nYou gain some Stamina!");
                    $st = 105000;
                    $nu = 30;
                    $fa = 30;
                    $fu = 30;
                    $co = 150;
                    break;
                case 16:
                    output("You scarf down your braaaaainy meal, hoping that there will be no complications from the frankly ridiculous amounts of braaaaains that you're eating.`n`nYou gain some Stamina!");
                    $st = 145000;
                    $nu = 40;
                    $fa = 40;
                    $fu = 40;
                    $co = 200;
                    break;
                case 17:
                    output("You scarf down your braaaaainy meal, hoping that there will be no complications from the frankly ridiculous amounts of braaaaains that you're eating.`n`nYou gain some Stamina!");
                    $st = 185000;
                    $nu = 50;
                    $fa = 50;
                    $fu = 50;
                    $co = 250;
                    break;
                case 18:
                    output("You scarf down your braaaaainy meal, hoping that there will be no complications from the frankly ridiculous amounts of braaaaains that you're eating.`n`nYou gain some Stamina!");
                    $st = 225000;
                    $nu = 60;
                    $fa = 60;
                    $fu = 60;
                    $co = 300;
                    break;
                case 19:
                    output("You chew thoughtfully on your Wriggly Biscuits.  They live up to their name quite adequately.`n`nYou gain some Stamina!");
                    $st = 65000;
                    $nu = 20;
                    $fa = 10;
                    $fu = 10;
                    $co = 100;
                    break;
                case 20:
                    output("You run your tongue lovingly up, down and around the extremely phallic nuts, savouring their delightfully salty flavour.`n`nYou gain some Stamina!");
                    $st = 145000;
                    $nu = 40;
                    $fa = 10;
                    $fu = 20;
                    $co = 200;
                    break;
                case 21:
                    output("The Noodly Noodles jerk and spasm, each bite releasing a sticky yellow goo.  Tasty!`n`nYou gain some Stamina!");
                    $st = 225000;
                    $nu = 40;
                    $fa = 10;
                    $fu = 20;
                    $co = 300;
                    break;
                case 22:
                    output("You stare down at your three-eyed fish.  It stares back up at you, in ways that you can only imagine.  After a few moments of depressed contemplation, you tuck in - and hey, it's actually not that bad.`n`nYou gain some Stamina!");
                    $st = 305000;
                    $nu = 50;
                    $fa = 25;
                    $fu = 40;
                    $co = 400;
                    break;
                case 23:
                    output("As your fork sinks into your Magical Mystery Meatloaf, a hundred pairs of eyes open on its crispy skin.  They close again almost instantly, and you try your hardest to persuade yourself that you were hallucinating from the disinfectant fumes - it beats reality, that's for damn sure.`n`nYou gain some Stamina!");
                    $st = 385000;
                    $nu = 50;
                    $fa = 25;
                    $fu = 50;
                    $co = 500;
                    break;
                case 24:
                    output("The Mutant Steak is lean, delicious, nutritious and as big as your head!  What a pleasant surprise!`n`nYou gain some Stamina!");
                    $st = 585000;
                    $nu = 150;
                    $fa = 10;
                    $fu = 80;
                    $co = 750;
                    break;
                case 25:
                    output("You grimace, and call over to the midget behind the counter.  \"These taste like someone tried to make bacon flavour crisps and failed, badly.\"`n`n\"Read the fookin' packet, dick'ead!\"`n`nYou do as he says.  Ah.  Tumour flavour.  Nice.`n`nYou gain some Stamina!");
                    $st = 10000;
                    $nu = 5;
                    $fa = 10;
                    $fu = 5;
                    $co = 20;
                    break;
                case 26:
                    output("Skinheads on a Raft turned out to be beans on toast.  You're not sure whether to be relieved.`n`nYou gain some Stamina!");
                    $st = 25000;
                    $nu = 20;
                    $fa = 20;
                    $fu = 15;
                    $co = 50;
                    break;
                case 27:
                    //Potential for expansion: have the kebab taste better if the player's drunk, have the player find a wedding ring that he can sell for Req, etc.
                    output("You scarf down your doner kebab, stopping occasionally to pick out the occasional toenail or piece of car dashboard.  It's pretty fatty, and would taste a lot better if you were drunk, but you make do.`n`nYou gain some Stamina!");
                    $st = 65000;
                    $nu = 20;
                    $fa = 40;
                    $fu = 20;
                    $co = 75;
                    break;
                case 28:
                    output("You knock back your Crimson Pitbull, which turned out to be some sort of energy drink.`n`nYou feel aggressive!");
                    apply_stamina_buff('crimsonpitbull', array("name" => "Bark of the Crimson Pitbull", "class" => "Combat", "costmod" => 0.5, "expmod" => 1, "rounds" => 20, "roundmsg" => "The harsh, chemically-sweet taste of the Crimson Pitbull lurks in the back of your throat.  You're not expending nearly as much Stamina as usual.", "wearoffmsg" => "The effects of the Crimson Pitbull have worn off, and your senses return to their natural state."));
                    $co = 75;
                    break;
                case 29:
                    output("C**k Nuggets turned out to be chicken nuggets, only with a little more fowl language.`n`n...`n`n...sorry.`n`nYou gain some Stamina!");
                    $st = 145000;
                    $nu = 30;
                    $fa = 60;
                    $fu = 25;
                    $co = 150;
                    break;
                case 30:
                    output("The Sausage Feast turned out to be less sausage, and more fat, but hey, it's cheap and it tastes halfway decent.`n`nYou gain some Stamina!");
                    $st = 185000;
                    $nu = 40;
                    $fa = 80;
                    $fu = 50;
                    $co = 200;
                    break;
            }
            addstamina($st);
            increment_module_pref("nutrition", $nu);
            increment_module_pref("fat", $fa);
            increment_module_pref("fullness", $fu);
            $full = get_module_pref("fullness");
            if ($full < 0) {
                output("`n`nYou still feel as though you haven't eaten in days.");
            }
            if ($full >= 0 && $full < 50) {
                output("`n`nYou feel a little less hungry.");
            }
            if ($full >= 50 && $full < 100) {
                output("`n`nYou still feel as though you've got room for more!");
            }
            if ($full >= 100) {
                output("`n`nYou're stuffed!  You feel as though you can't possibly eat anything more today.");
            }
            $session['user']['gold'] -= $co;
            break;
    }
    debug(get_module_pref("fat"));
    debug(get_module_pref("nutrition"));
    addnav("Exit");
    addnav("Return to the Outpost", "village.php");
    page_footer();
}
function racejoker_dohook($hookname, $args)
{
    //yeah, the $resline thing is a hack.  Sorry, not sure of a better way
    // to handle this.
    // Pass it as an arg?
    global $session, $resline;
    $city = "AceHigh";
    $race = "Joker";
    switch ($hookname) {
        case "racenames":
            $args[$race] = $race;
            break;
        case "changesetting":
            // Ignore anything other than villagename setting changes
            if ($args['setting'] == "villagename" && $args['module'] == "racejoker") {
                if ($session['user']['location'] == $args['old']) {
                    $session['user']['location'] = $args['new'];
                }
                $sql = "UPDATE " . db_prefix("accounts") . " SET location='" . addslashes($args['new']) . "' WHERE location='" . addslashes($args['old']) . "'";
                db_query($sql);
                if (is_module_active("cities")) {
                    $sql = "UPDATE " . db_prefix("module_userprefs") . " SET value='" . addslashes($args['new']) . "' WHERE modulename='cities' AND setting='homecity'" . "AND value='" . addslashes($args['old']) . "'";
                    db_query($sql);
                }
            }
            break;
        case "chooserace":
            if ($session['user']['dragonkills'] < 12) {
                break;
            }
            output("`0You grin, and pull a six-sided die from your left ear.  <a href='newday.php?setrace={$race}{$resline}'>\"Well, let's see, shall we?\"</a>`n`n", true);
            addnav("`&Joker`0", "newday.php?setrace={$race}{$resline}");
            addnav("", "newday.php?setrace={$race}{$resline}");
            break;
        case "setrace":
            if ($session['user']['race'] == $race) {
                output("The gatekeeper's smile doesn't go away.  Instead, it freezes, locks carefully into place - and the gatekeeper begins to pray that he can persuade it to stay there until you go away, or at least until your eyes stop doing that `@green glowy thing`0.  \"`6Yes,`0\" he says, carefully.  \"`6Yes, that would be fine.`0\"`n`nYou roll your die.  It skitters along, making a clattering sound like bone on wood.  The fact that it's still four feet above the ground doesn't seem to faze the gatekeeper, or if it does, he's very good at not letting it show.`n`nIt finally comes to rest, seven spots facing the sun.  You look up and grin, teeth white and gleaming and not entirely friendly.  \"`#It seems I am a Joker!`0\" you exclaim in a breathy growl.`n`nThe gatekeeper nods, and picks up his journal.  \"`6Very good.  As you say.  Jay.  Oh.  Kay.  Are.  Ee.  Joker.  All done.`0\"  He looks up, to see you preparing to roll your die again.  He opens his mouth to ask you what you're doing, and bites his tongue.  Never ask what a Joker is doing; they might tell you.`n`nYou roll your die.  It skitters along the invisible table, bounces against an invisible wall, and comes up at two.`n`n\"`#Shame,`0\" you say.  \"`#You would have been more interesting with some additional eyes.  Still, if the die says two are enough, then who am I to disagree?`0\"`n`nYou give the gatekeeper a grin and a wink, and head into the outpost.`n`nA minute later, he remembers to exhale.  He shudders and puts the kettle on, hoping that it isn't going to turn out to be one of `ithose`i days.");
                if (is_module_active("cities")) {
                    set_module_pref("homecity", $city, "cities");
                    if ($session['user']['age'] == 0) {
                        $session['user']['location'] = $city;
                    }
                }
            }
            break;
        case "startofround-prebuffs":
            if ($session['user']['race'] == $race && $session['user']['alive']) {
                $chain = unserialize(get_module_pref("chain"));
                if (!is_array($chain)) {
                    $chain = array();
                }
                $suit = httpget("suit");
                if (!$suit) {
                    $suit = e_rand(1, 4);
                }
                switch ($suit) {
                    case 1:
                        $chain[] = "heart";
                        break;
                    case 2:
                        $chain[] = "diamond";
                        break;
                    case 3:
                        $chain[] = "spade";
                        break;
                    case 4:
                        $chain[] = "club";
                        break;
                }
                $hearts = 0;
                $diamonds = 0;
                $spades = 0;
                $clubs = 0;
                $num = 0;
                output("You draw a card from your rather Improbable deck, and add it to your hand.`n");
                foreach ($chain as $card) {
                    rawoutput("<img src=\"images/" . $card . ".png\">");
                    switch ($card) {
                        case "heart":
                            $hearts++;
                            break;
                        case "diamond":
                            $diamonds++;
                            break;
                        case "spade":
                            $spades++;
                            break;
                        case "club":
                            $clubs++;
                            break;
                    }
                    $num++;
                }
                output_notl("`n");
                if ($hearts == $num || $diamonds == $num || $spades == $num || $clubs == $num) {
                    if ($num > 1) {
                        output("`0With a grin you realise that all your cards match up - Joker tradition now allows you to expand your hand by one card!`n");
                    }
                } else {
                    if ($num > 1) {
                        output("`0The bottom card from your hand vanishes.`n");
                    }
                    array_shift($chain);
                }
                set_module_pref("chain", serialize($chain));
                //calculate and award buffs
                $bhearts = round($session['user']['maxhitpoints'] / 100 * e_rand($hearts * $hearts * $hearts / 100, $hearts * $hearts * $hearts / 5));
                $bdiamonds = e_rand($diamonds, $diamonds * $diamonds);
                $bspades = $spades * $spades * $spades * 0.005 + 1;
                $bclubs = $clubs * $clubs * $clubs * 0.005 + 1;
                if ($bhearts > 1) {
                    apply_buff("Hearts", array("regen" => $bhearts, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => 1, "expireafterfight" => 1, "effectmsg" => "The mysterious power of your Hearts aura causes you to regenerate {damage} hitpoints...`0", "schema" => "module-racejoker"));
                }
                if ($bdiamonds > 0) {
                    if ($bdiamonds == 1) {
                        output("`@The reward hopper mounted to the closest camera is briefly enveloped in crackling green lightning.  You step back and deftly catch the single Requisition token that clatters out of it, before heading straight back into the fight!`0`n");
                    } else {
                        output("`@The reward hopper mounted to the closest camera is briefly enveloped in crackling green lightning.  You step back and deftly catch the `b%s`b Requisition tokens that pour out of it, before heading straight back into the fight!`0`n", $bdiamonds);
                    }
                    $session['user']['gold'] += $bdiamonds;
                }
                if ($bspades > 1) {
                    apply_buff("Spades", array("defmod" => $bspades, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => 1, "startmsg" => "You feel an aura of protection gathering around you!", "expireafterfight" => 1, "roundmsg" => "Thanks to the power of the Spades suit, {badguy} is having trouble hitting you!", "schema" => "module-racejoker"));
                }
                if ($bclubs > 1) {
                    apply_buff("Clubs", array("atkmod" => $bclubs, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => 1, "startmsg" => "You feel a burning energy in your muscles...", "expireafterfight" => 1, "roundmsg" => "Thanks to the power of the Clubs suit, your attacks are more powerful!", "schema" => "module-racejoker"));
                }
            }
            break;
            // case "alternativeresurrect":
        // case "alternativeresurrect":
        case "stamina-newday":
            if ($session['user']['race'] == $race) {
                clear_module_pref("chain");
                racejoker_checkcity();
                //new Joker grenade -> improbabombs routine
                $bandolier = 0;
                $blprefs = array("inventorylocation" => "fight");
                $bandolier += has_item_quantity("banggrenade", $blprefs);
                $bandolier += has_item_quantity("whoomphgrenade", $blprefs);
                $bandolier += has_item_quantity("zapgrenade", $blprefs);
                $count = 0;
                $count += delete_all_items_of_type("banggrenade");
                $count += delete_all_items_of_type("whoomphgrenade");
                $count += delete_all_items_of_type("zapgrenade");
                if ($count) {
                    output("`0All of your Grenades have turned into Improbability Bombs overnight.  Well, that's what happens when you store explosives around such high levels of Improbability.`n");
                    $backpack = $count - $bandolier;
                    for ($i = 0; $i < $backpack; $i++) {
                        give_item("improbabilitybomb");
                    }
                    for ($i = 0; $i < $bandolier; $i++) {
                        give_item("improbabilitybomb", $blprefs);
                    }
                }
                //Combat buffs
                $jokerattack = e_rand(1, 20) / 10;
                $jokerdefence = e_rand(1, 20) / 10;
                $jokerregen = 0;
                $jokerregenchance = e_rand(1, 100);
                if ($jokerregenchance > 80) {
                    $jokerregen = 5 - e_rand(1, 10);
                }
                apply_buff("joker", array("name" => "Joker Bonus - Improbability", "atkmod" => $jokerattack, "defmod" => $jokerdefence, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racejoker"));
                if ($jokerregen < 0) {
                    output("`n`&Today is a bad day.  Your internal organs appear to have shifted themselves into a rather unfortunate configuration.  Internal bleeding will cause you to lose some hitpoints with every round of battle.`n`0");
                    apply_buff("jokerregen", array("regen" => $jokerregen, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "effectmsg" => "`3Your internal bleeding causes you to lose {damage} hitpoints.`0", "schema" => "module-racejoker"));
                }
                if ($jokerregen > 0) {
                    output("`n`&Today is a good day.  You appear to have discovered the secret of cellular regeneration.  You will gain hitpoints in every battle.`n`0");
                    apply_buff("jokerregen", array("regen" => $jokerregen, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "effectmsg" => "`3Your accelerated cellular regeneration causes you to gain {damage} hitpoints.`0", "schema" => "module-racejoker"));
                }
                $c1 = e_rand(10, 200) / 100;
                $c2 = e_rand(10, 200) / 100;
                $c3 = e_rand(10, 200) / 100;
                $c4 = e_rand(10, 200) / 100;
                $c5 = e_rand(10, 200) / 100;
                $e1 = e_rand(10, 200) / 100;
                $e2 = e_rand(10, 200) / 100;
                $e3 = e_rand(10, 200) / 100;
                $e4 = e_rand(10, 200) / 100;
                $e5 = e_rand(10, 200) / 100;
                //Stamina Buffs
                require_once "modules/staminasystem/lib/lib.php";
                apply_stamina_buff('joker1', array("name" => "Joker Improbability Modifier: Travelling", "class" => "Travelling", "costmod" => $c1, "expmod" => $e1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('joker2', array("name" => "Joker Improbability Modifier: Cooking and Carcass Cleaning", "class" => "Meat", "costmod" => $c2, "expmod" => $e2, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('joker3', array("name" => "Joker Improbability Modifier: Hunting", "class" => "Hunting", "costmod" => $c3, "expmod" => $e3, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('joker4', array("name" => "Joker Improbability Modifier: Combat", "class" => "Combat", "costmod" => $c4, "expmod" => $e4, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('joker5', array("name" => "Joker Improbability Modifier: ScrapBots", "class" => "ScrapBots", "costmod" => $c5, "expmod" => $e5, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
            }
            break;
        case "validforestloc":
        case "validlocation":
            if (is_module_active("cities")) {
                $args[$city] = "village-{$race}";
            }
            break;
        case "moderate":
            if (is_module_active("cities")) {
                tlschema("commentary");
                $args["village-{$race}"] = sprintf_translate("City of %s", $city);
                tlschema();
            }
            break;
        case "villagetext":
            racejoker_checkcity();
            if ($session['user']['location'] == $city) {
                $args['text'] = array("`0You are standing in the heart of AceHigh.  Though relatively new, this town seems to be prospering.  The houses are built of stone and timber frames, and well-dressed gentlemen and ladies stroll about with impeccable manners.  Every now and then, one of them explodes in an astonishing flash of green light, drawing polite applause from those nearby.`n`n");
                $args['schemas']['text'] = "module-racejoker";
                $args['clock'] = "`0The great clockwork readout at the centre of the city reads `&%s`0.`n`n";
                $args['schemas']['clock'] = "module-racejoker";
                if (is_module_active("calendar")) {
                    $args['calendar'] = "`0A smaller contraption next to it reads `&%s`0, `&%s %s %s`0.`n`n";
                    $args['schemas']['calendar'] = "module-racejoker";
                }
                $args['title'] = array("%s, Home of the Jokers", $city);
                $args['schemas']['title'] = "module-racejoker";
                $args['sayline'] = "says";
                $args['schemas']['sayline'] = "module-racejoker";
                $args['talk'] = "`0Nearby some people converse politely:`n";
                $args['schemas']['talk'] = "module-racejoker";
                $new = get_module_setting("newest-{$city}", "cities");
                if ($new != 0) {
                    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid='{$new}'";
                    $result = db_query_cached($sql, "newest-{$city}");
                    $row = db_fetch_assoc($result);
                    $args['newestplayer'] = $row['name'];
                    $args['newestid'] = $new;
                } else {
                    $args['newestplayer'] = $new;
                    $args['newestid'] = "";
                }
                if ($new == $session['user']['acctid']) {
                    $args['newest'] = "`n`0As you wander your new home, you feel your jaw dropping at the wonders around you.";
                } else {
                    $args['newest'] = "`n`0Wandering the village, jaw agape, is `&%s`0.";
                }
                $args['schemas']['newest'] = "module-racejoker";
                $args['section'] = "village-{$race}";
                $args['stablename'] = "Mike's Chop Shop";
                $args['schemas']['stablename'] = "module-racejoker";
                $args['gatenav'] = "Village Gates";
                $args['schemas']['gatenav'] = "module-racejoker";
                unblocknav("stables.php");
            }
            break;
    }
    return $args;
}