function staminatest_run()
{
    global $session;
    page_header("Stamina Testing");
    switch (httpget("op")) {
        case "start":
            output("Testing Testing!");
            break;
        case "add":
            output("Attempting to install an action called Sexins, with these parameters:`n`nStarting and Maximum costs: 500`nMinimum cost: 200`nReps for a Reduction: 20`nReduction: 10`n");
            install_action("Sexins", array("maxcost" => 25000, "mincost" => 10000, "expperrep" => 100, "expforlvl" => 1000, "costreduction" => 10, "dkpct" => 2.5));
            break;
        case "process":
            output("Processing the Sexins action");
            process_action("Sexins");
            break;
        case "newday":
            output("Processing a New Day");
            stamina_process_newday();
            break;
        case "buff":
            output("Applying a stamina buff to Sexins for the current user, for 20 rounds, reducing action cost to half.");
            apply_stamina_buff('ultra-sexy-buff-for-sexins', array("name" => "Ultra Sexy Buff for Sexins", "action" => "Sexins", "costmod" => 0.5, "expmod" => 0.8, "rounds" => 5, "roundmsg" => "Round Message!", "wearoffmsg" => "Wearoff Message!"));
            output("Also applying a Stamina Class buff to all Hunting actions, reducing their cost to half for twenty rounds.");
            apply_stamina_buff('huntclasstest', array("name" => "Hunting Class test buff", "class" => "Hunting", "costmod" => 0.5, "expmod" => 0.8, "rounds" => 20, "roundmsg" => "Round Message!", "wearoffmsg" => "Wearoff Message!"));
            break;
        case "get":
            $thingtodebug = get_player_action("Sexins");
            debug($thingtodebug);
            break;
        case "uninstall":
            output("Uninstalling the Sexins action, deleting all actions entries and associated buffs");
            uninstall_action("Sexins");
            break;
        case "dragonkill":
            output("Processing a Dragon Kill");
            stamina_process_dragonkill();
            break;
        case "calcbuffs":
            output("Calculating Buffs");
            stamina_calculate_buffed_cost("Sexins");
            break;
        case "calcexp":
            output("Calculating Buffed EXP");
            stamina_calculate_buffed_exp("Sexins");
            break;
    }
    addnav("Install an action called Sexins", "runmodule.php?module=staminatest&op=add");
    addnav("Uninstall", "runmodule.php?module=staminatest&op=uninstall");
    addnav("Process the Sexins Action for the current user", "runmodule.php?module=staminatest&op=process");
    addnav("Process newday", "runmodule.php?module=staminatest&op=newday");
    addnav("Add a buff", "runmodule.php?module=staminatest&op=buff");
    addnav("Get Stamina", "runmodule.php?module=staminatest&op=get");
    addnav("Process a Dragon Kill", "runmodule.php?module=staminatest&op=dragonkill");
    addnav("Calculate Buffed Cost", "runmodule.php?module=staminatest&op=calcbuffs");
    addnav("Calculate Buffed exp", "runmodule.php?module=staminatest&op=calcexp");
    addnav("Back to the Grotto", "superuser.php");
    page_footer();
    return true;
}
function buildersbrew_use($args)
{
    global $session;
    require_once "modules/staminasystem/lib/lib.php";
    apply_stamina_buff('buildersbrew_1', array("name" => "Builder's Brew", "action" => "Logging", "costmod" => 0.1, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "The warmth from your Builder's Brew makes logging a breeze!"));
    apply_stamina_buff('buildersbrew_2', array("name" => "Builder's Brew", "action" => "Stonecutting", "costmod" => 0.1, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "The warmth from your Builder's Brew makes the stone seem as soft as butter!"));
    apply_stamina_buff('buildersbrew_3', array("name" => "Builder's Brew", "action" => "Carpentry", "costmod" => 0.1, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "The warmth from your Builder's Brew makes this carpentry job seem a hell of a lot easier!"));
    apply_stamina_buff('buildersbrew_3a', array("name" => "Builder's Brew", "action" => "Reinforcement", "costmod" => 0.1, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "The warmth from your Builder's Brew makes this reinforcement job seem a hell of a lot easier!"));
    apply_stamina_buff('buildersbrew_4', array("name" => "Builder's Brew", "action" => "Masonry", "costmod" => 0.1, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "The warmth from your Builder's Brew makes the stone feel light as a feather!"));
    apply_stamina_buff('buildersbrew_5', array("name" => "Builder's Brew", "action" => "Decorating", "costmod" => 0.1, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "The warmth from your Builder's Brew makes this decorating job a trivial matter indeed!"));
    return $args;
}
function staminamounts_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "boughtmount":
        case "soldmount":
        case "stamina-newday":
            require_once "modules/staminasystem/lib/lib.php";
            $currentmount = $session['user']['hashorse'];
            for ($i = 1; $i <= 10; $i++) {
                if (get_module_objpref("mounts", $currentmount, "buff" . $i . "name", "staminamounts") || get_module_objpref("mounts", $currentmount, "buff" . $i . "costmod", "staminamounts") || get_module_objpref("mounts", $currentmount, "buff" . $i . "expmod", "staminamounts")) {
                    apply_stamina_buff("mountbuff" . $i, array("name" => get_module_objpref("mounts", $currentmount, "buff" . $i . "name", "staminamounts"), "action" => get_module_objpref("mounts", $currentmount, "buff" . $i . "action", "staminamounts"), "class" => get_module_objpref("mounts", $currentmount, "buff" . $i . "class", "staminamounts"), "costmod" => get_module_objpref("mounts", $currentmount, "buff" . $i . "costmod", "staminamounts"), "expmod" => get_module_objpref("mounts", $currentmount, "buff" . $i . "expmod", "staminamounts"), "rounds" => get_module_objpref("mounts", $currentmount, "buff" . $i . "rounds", "staminamounts"), "roundmsg" => get_module_objpref("mounts", $currentmount, "buff" . $i . "roundmsg", "staminamounts"), "wearoffmsg" => get_module_objpref("mounts", $currentmount, "buff" . $i . "wearoffmsg", "staminamounts")));
                }
            }
            break;
    }
    return $args;
}
function mountaccessoriesstamina_dohook($hookname, $args)
{
    global $session, $acc;
    switch ($hookname) {
        case "mountaccessories_apply_accessory":
            require_once "modules/staminasystem/lib/lib.php";
            $numberofbuffs = $acc['numberofstaminabuffs'];
            for ($i = 0; $i <= $numberofbuffs; $i++) {
                apply_stamina_buff($acc['staminabuffref' . $i], array("name" => $acc['staminabuffname' . $i], "action" => $acc['staminabuffaction' . $i], "class" => $acc['staminabuffclass' . $i], "costmod" => $acc['staminabuffcostmod' . $i], "expmod" => $acc['staminabuffexpmod' . $i], "rounds" => $acc['staminabuffrounds' . $i], "roundmsg" => $acc['staminabuffroundmsg' . $i], "wearoffmsg" => $acc['staminabuffwearoffmsg' . $i]));
            }
            break;
        case "mountaccessories_strip_accessory":
            require_once "modules/staminasystem/lib/lib.php";
            $numberofbuffs = $acc['numberofstaminabuffs'];
            for ($i = 0; $i <= $numberofbuffs; $i++) {
                strip_stamina_buff($acc['staminabuffref' . $i]);
            }
            break;
    }
    return $args;
}
function items_weightpenalty_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "items_weights":
            require_once "modules/staminasystem/lib/lib.php";
            foreach ($args as $carrier => $prefs) {
                if ($prefs['weight_current'] && $prefs['weight_max'] && $prefs['wlimit_use_sbuff']) {
                    $mult = $prefs['weight_current'] / $prefs['weight_max'];
                    $sbuffid = "wlimit_" . $carrier;
                    if ($mult > 1) {
                        apply_stamina_buff($sbuffid, array("name" => $prefs['wlimit_sbuff_name'], "action" => "Global", "costmod" => $mult, "expmod" => 1, "rounds" => -1, "roundmsg" => $prefs['wlimit_sbuff_roundmsg'], "wearoffmsg" => ""));
                    } else {
                        //debug("stripping buff ".$sbuffid);
                        strip_stamina_buff($sbuffid);
                    }
                }
            }
            break;
    }
    return $args;
}
function racekittymorph_dohook($hookname, $args)
{
    global $session, $resline;
    $city = "Kittania";
    $race = "Kittymorph";
    switch ($hookname) {
        case "racenames":
            $args[$race] = $race;
            break;
        case "changesetting":
            // Ignore anything other than villagename setting changes
            if ($args['setting'] == "villagename" && $args['module'] == "racekittymorph") {
                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'] == 0) {
                break;
            }
            output("`0You smile, and turn around to show the gatekeeper your tail.  <a href='newday.php?setrace={$race}{$resline}'>\"Um... notice anything unusual?\"</a>`n`n", true);
            addnav("`&Kittymorph`0", "newday.php?setrace={$race}{$resline}");
            addnav("", "newday.php?setrace={$race}{$resline}");
            break;
        case "setrace":
            if ($session['user']['race'] == $race) {
                output("\"`6Oh, I see, right,`0\" says the gatekeeper, looking down at his ledger.  \"`6A kittymorph, then, okay, let's see, here...  Kay, eye, tee, ee, em, oh, are, eff.  Kittymorph.`0\"  He looks up again.  \"`6Um.  You can turn around again, now.`0\"`n`nYou oblige.  \"`#Sorry.`0\"`n`n\"`6Don't worry about it.  Have you always been like this?`0\"`n`n\"`#Since I was a kitten,`0\" you reply.  \"`#I don't know what that crazy woman back there was talking about; she says I fell out of a plane and hit my head.  Rubbish.`0\"`n`n\"`6Of course,`0\" says the gatekeeper, smiling.  \"`6You would have landed on your feet, wouldn't you?`0\"`n`n\"`#That's right.  Although...`0\"  You look down, puzzled.  \"`#Some things just don't add up...`0\" you mutter.`n`n\"`6Well, don't worry,`0\" says the gatekeeper.  \"`6Just head into town and get some nice clothes, and you'll sort everything out, I'm sure.  If you wear clothes, that is.`0\"`n`nYou grin.  \"`#When it suits me.`0\"  You saunter off through the gates.  You don't really know how to walk any other way.");
                if (is_module_active("cities")) {
                    set_module_pref("homecity", $city, "cities");
                    if ($session['user']['age'] == 0) {
                        $session['user']['location'] = $city;
                    }
                }
            }
            break;
        case "alternativeresurrect":
        case "stamina-newday":
            if ($session['user']['race'] == $race) {
                racekittymorph_checkcity();
                //Stamina buffs
                require_once "modules/staminasystem/lib/lib.php";
                apply_stamina_buff('kittymorph3', array("name" => "KittyMorph Bonus: Travelling Speed", "class" => "Travelling", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('kittymorph4', array("name" => "KittyMorph Bonus: Cooking and Carcass Cleaning Expertise", "class" => "Meat", "costmod" => 0.7, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('kittymorph1', array("name" => "KittyMorph Penalty: Hunting Indifference", "class" => "Hunting", "costmod" => 1.1, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('kittymorph2', array("name" => "KittyMorph Penalty: Combat Indifference", "class" => "Combat", "costmod" => 1.1, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('kittymorph5', array("name" => "KittyMorph Penalty: Technical Ineptitude", "class" => "ScrapBots", "costmod" => 1.1, "expmod" => 0.8, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('raceclassy', array("name" => "KittyMorph Bonus: Classy Insults Proficiency", "action" => "Insults - Classy", "costmod" => 0.9, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('raceconfusing', array("name" => "KittyMorph Bonus: Confusing Insults Proficiency", "action" => "Insults - Confusing", "costmod" => 0.5, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                //combat buffs
                apply_buff("racialbenefit1", array("name" => "`7KittyMorph Penalty: Slender`0", "defmod" => "0.8", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racekittymorph"));
                apply_buff("racialbenefit2", array("name" => "`7KittyMorph Bonus: Claws`0", "atkmod" => "1.2", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racekittymorph"));
            }
            break;
        case "creatureencounter":
            if ($session['user']['race'] == $race) {
                //get those folks who haven't manually chosen a race
                racekittymorph_checkcity();
                if ($session['user']['armordef'] == 0) {
                    apply_buff("nudekitty", array("name" => "`7KittyMorph Bonus: Nude Fighting`0", "badguyatkmod" => 0.7, "badguydefmod" => 0.7, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "roundmsg" => "Because you are fighting completely starkers, {badguy} is hilariously distracted and cannot attack or defend as effectively!", "expireafterfight" => 1, "schema" => "module-racekittymorph"));
                }
            }
            break;
        case "battle-victory":
            if ($session['user']['race'] == $race) {
                if (!$session['user']['alive']) {
                    debug($args['creatureexp']);
                    $args['creatureexp'] = round($args['creatureexp'] * 1.3);
                    debug($args['creatureexp']);
                }
            }
            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":
            racekittymorph_checkcity();
            if ($session['user']['location'] == $city) {
                $args['text'] = array("`0You are standing in the heart of Kittania.  Though officially registered as a city, it only earned that title because there were so many sentient creatures living there.`n`nIn reality, the city is a very basic affair, little more than a pack living together in common conditions.  Kittymorphs are a little too lazy to build much.`n");
                $args['schemas']['text'] = "module-racekittymorph";
                $args['clock'] = "`n`0From the position of the sun in the sky, you reckon it's about `&%s`0.`n";
                $args['schemas']['clock'] = "module-racekittymorph";
                if (is_module_active("calendar")) {
                    $args['calendar'] = "`n`0Scrawled in dust on the floor is the current date, `&%s`0, `&%s %s %s`0.`n";
                    $args['schemas']['calendar'] = "module-racekittymorph";
                }
                $args['title'] = array("%s, Home of the Kittymorphs", $city);
                $args['schemas']['title'] = "module-racekittymorph";
                $args['sayline'] = "says";
                $args['schemas']['sayline'] = "module-racekittymorph";
                $args['talk'] = "`n`&Nearby some kittymorphs talk:`n";
                $args['schemas']['talk'] = "module-racekittymorph";
                $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 wonderful smells around you.";
                } else {
                    $args['newest'] = "`n`0Wandering the village, jaw agape and buck naked, is `&%s`0.";
                }
                $args['schemas']['newest'] = "module-racekittymorph";
                $args['section'] = "village-{$race}";
                $args['stablename'] = "Mike's Chop Shop";
                $args['schemas']['stablename'] = "module-racekittymorph";
                $args['gatenav'] = "Outpost Gates";
                $args['fightnav'] = "Toothclaw Close";
                $args['marketnav'] = "The Cul-De-Sac of Sparkly Things";
                $args['tavernnav'] = "Distraction Avenue";
                $args['schemas']['gatenav'] = "module-racekittymorph";
                unblocknav("stables.php");
            }
            break;
        case "stablelocs":
            tlschema("mounts");
            $args[$city] = sprintf_translate("The Village of %s", $city);
            tlschema();
            break;
        case "stabletext":
            if ($session['user']['location'] != $city) {
                break;
            }
            $args['title'] = "Mike's Chop Shop";
            $args['schemas']['title'] = "module-racekittymorph";
            $args['desc'] = array("`6Just next door to the Clan Halls, a rather basic-looking set of stables has been erected.`n`n", array("As you head inside, you notice an obvious lack of the typical stable smell.  Apparently KittyMorphs, for all their laziness, like to keep things clean.`n`n\"`^Well hello there!  What can I do for you, my good %s?`6\" asks a grey-furred KittyMorph male whose name you're absolutely `icertain`i is not \"Mike.\"", translate_inline($session['user']['sex'] ? 'lady' : 'man', 'stables')));
            $args['schemas']['desc'] = "module-racekittymorph";
            $args['lad'] = "friend";
            $args['schemas']['lad'] = "module-racekittymorph";
            $args['lass'] = "friend";
            $args['schemas']['lass'] = "module-racekittymorph";
            $args['nosuchbeast'] = "`6\"`^Hmm.  Not heard of that one,`6\" Mike says apologetically.";
            $args['schemas']['nosuchbeast'] = "module-racekittymorph";
            $args['toolittle'] = "`6Mike looks over the handful of currency you offered.  \"`^Aha.  Well, the price for this %s, you see, was actually `&%s `^Requisition  and `%%s`^ cigarettes.  Maybe you miscounted?`6\"";
            $args['schemas']['toolittle'] = "module-racekittymorph";
            $args['replacemount'] = "`6You sadly watch Mike lead your %s`6 away, along with your cigarettes.  However, when he returns, he brings with him a nice new `&%s`6 which makes you feel a little better.";
            $args['schemas']['replacemount'] = "module-racekittymorph";
            $args['newmount'] = "`6You hand over your currency.  Within moments, you become the proud recipient of a lovely new `&%s`6!";
            $args['schemas']['newmount'] = "module-racekittymorph";
            $args['confirmsale'] = "`n`n`6Mike eyes your mount up and down, checking it over carefully.  \"`^Yes, yes, that's a really nice example, right there - are you quite sure you want to part with it?`6\"";
            $args['schemas']['confirmsale'] = "module-racekittymorph";
            $args['mountsold'] = "`6With but a single tear, you hand your %s`6 over to Mike.  The tear dries quickly, and the %s in hand helps you quickly overcome your sorrow.";
            $args['schemas']['mountsold'] = "module-racekittymorph";
            $args['offer'] = "`n`n`6Mike offers you `&%s`6 Requisition and `%%s`6 Cigarettes for %s`6.";
            $args['schemas']['offer'] = "module-racekittymorph";
            break;
    }
    return $args;
}
function meatschool_run()
{
    global $session;
    page_header("Maiko's Cookery Academy");
    switch (httpget('op')) {
        case "start":
            if (get_module_pref("meatsmith", "meatsystem") == 0) {
                //this is the player's first trip to the Meat School
                output("\"`%Don't worry, it won't feel a thing!`0\"`n`nThe voice comes through confidently - one that's clearly used to carrying across a room full of students.  A teacher's voice.  You step into the hall.`n`nTwenty or so students sit on slightly rickety-looking chairs inside, facing a raised platform.  You barely have time to register the petite, smiling KittyMorph woman before a loud `iBOOM-ch-KA`i draws your attention to the captive bolt pistol in her hand, and the cow-sized, green-furred beast that is at this very moment falling to the floor with a bass-heavy `ithump`i.  Several students squirm in their seats.`n`nThe teacher looks in your direction, and gives you a smile as she puts down the bolt pistol and picks up a pair of razor-sharp knives.  \"`%A new recruit!  I'll bring you up to speed real quick - I'm Maiko, and today we're learning how to cook Bewilderbeest steaks.  From scratch!  Come in, sit down, the first lesson's free!`0\"`n`nYou nervously make your way to a chair and take a seat.  \"`%James, tell me why it's important to begin the bleeding process right away.`0\"`n`nA sick-looking youth stutters a reply.  \"S-s-so it doesn't wake up?\"`n`n\"`%No.  No, if you've kept your gun looked after and done the stunning properly, it won't wake up from that.  The stunning pretty well destroys the forebrain - the animal's alive only in a very clinical sense of the term.  In every sense that matters, to you or to it, it's dead.  No, we start the bleeding process straight away because the blood pressure increases the longer we leave it, and that can rupture blood vessels, and cause muscular haemorrhages - which just makes the meat spoil faster.  Also, when you're out killing monsters in the jungle, if you don't get the meat from them straight away, something's apt to take the carcass the moment you turn your back, be it Midgets or other monsters.  So we butcher the monsters the moment they're unconscious, right?  Now, watch as I make the cuts.  First one, down here - and now we pull that out, and if you want to, you can tie a knot in it.  Second one, this way, and then again, and now we reach in and...  One more...  Aah!  There we go.  Hold these for me, James.  And now - see?  Just like that.  Can you see, there, at the back?  Good.  Look here - the meat can sometimes jump around a little bit.  Don't be freaked out, it's not still alive.  That's just the muscle reacting to the air - it's not used to this much oxygen.  See?  This bit in my hand is still twitching around, even though it's not attached to anything.  I'd like to point out as I'm doing this that it won't always be possible to do it so neatly while you're cleaning the animals that tried to kill you - but just do the best you can.  We're only interested in the best cuts, these ones here - the Zombies and Humans will take the other meat, and the Midgets will only take the... well, James, you could probably sell `ithose`i to them.  Now, we'll do a couple more over here, and...  Um... you there, the new recruit, are you okay?  You look a bit, um...`0\"`n`nVarious students turn around to look at you.  \"Fine,\" you squeak.`n`n\"`%Jolly good then - come on, up you come, let's see if you can do this bit.  You'll soon learn to swim if we chuck you in the deep end, eh?`0\"  You gulp, and head up to the platform.  Right into the deep end.`n`nAn hour later, Maiko shakes your hand.  \"`%That was a very successful first lesson!  If you want to gain some experience in field-dressing, cleaning and cooking, I can offer private tuition at ten Requisition per lesson.  But to be honest - you're a natural!`0\"`n`nYou're not entirely sure how to take that.`n`n`c`bYou have gained two new skills!`b`nYou are now at level one in Carcass Cleaning and Cooking!`c");
                require_once "modules/staminasystem/lib/lib.php";
                get_player_action("Cleaning the Carcass");
                get_player_action("Cooking");
                set_module_pref("meatsmith", 1, "meatsystem");
            } else {
                //lessons
                require_once "modules/staminasystem/lib/lib.php";
                $amber = get_stamina();
                if ($amber == 100) {
                    output("Maiko greets you at the door with a wide grin.  \"`%Back for some more training, eh?  Ten Req per lesson, and I keep the meat.  How's that sound?`0\"`n`n`JMaiko, like other teachers in Improbable Island, can help you level up some of your skills.  When you pay to train with Maiko, you'll use as much Stamina in performing your chosen actions as normal, but you'll receive two and a half times the experience.  Higher levels in Cooking and Carcass Cleaning will make these actions cost fewer Stamina points.`n`n`0Will you train with Maiko?`n`n");
                    addnav("Train with Maiko");
                    if ($session['user']['gold'] >= 10) {
                        $cleancost = stamina_getdisplaycost("Cleaning the Carcass");
                        addnav(array("Pay 10 Req for a Carcass Cleaning lesson (`Q%s%%`0)", $cleancost), "runmodule.php?module=meatschool&op=train&train=clean");
                        $cookcost = stamina_getdisplaycost("Cooking");
                        addnav(array("Pay 10 Req for a Cookery lesson (`Q%s%%`0)", $cookcost), "runmodule.php?module=meatschool&op=train&train=cook");
                    } else {
                        addnav("You don't have enough money.  No lessons for you.", "");
                    }
                } else {
                    output("Maiko greets you at the door with a wide grin.  \"`%Back for some more training, eh?  Well, you look half-asleep to me.  Training won't do you any good at all if you're too tired to take it in.  Go and get some rest, or a coffee or something, then we'll talk.`0\"  She shoos you out of the door.");
                }
            }
            addnav("Leave this place");
            addnav("Return to Kittania", "village.php");
            break;
        case "train":
            if (is_module_active("medals")) {
                require_once "modules/medals.php";
                medals_award_medal("maiko_train", "Maiko's Meat School", "This player took lessons at Maiko's Meat School!", "medal_maiko.png");
            }
            $session['user']['gold'] -= 10;
            require_once "modules/staminasystem/lib/lib.php";
            switch (httpget('train')) {
                case "clean":
                    apply_stamina_buff('maikoclean', array("name" => "Maiko\\'s Training", "action" => "Cleaning the Carcass", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    output("Maiko shows you a big smile.  \"`%Another butchery lesson!  Great stuff.  Let's get started!`0\"`n`nMaiko grabs her knives and captive bolt pistol, you don your gloves, and the two of you spend the next little while up to your elbows in warm, still-twitching muscle.  Under Maiko's careful watch, her gentle hands occasionally guiding yours to make a difficult cut, you learn one or two things that you didn't know before.");
                    $return = process_action("Cleaning the Carcass");
                    output("You receive %s experience in Cleaning the Carcass.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`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']);
                    }
                    break;
                case "cook":
                    apply_stamina_buff('maikocook', array("name" => "Maiko\\'s Training", "action" => "Cooking", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    output("Maiko shows you a big smile.  \"`%Another cookery lesson!  Great stuff.  Let's get started!`0\"`n`nMaiko grabs her pans and some ingredients, and you don the 'hilarious' apron Maiko has so thoughtfully provided.  Under Maiko's helpful guidance, you learn one or two things that you didn't know before.");
                    $return = process_action("Cooking");
                    output("You receive %s experience in Cooking.`n`n", $return['exp_earned']);
                    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']);
                    }
                    break;
            }
            $amber = get_stamina();
            if ($amber == 100) {
                addnav("More Training");
                if ($session['user']['gold'] >= 10) {
                    $cleancost = stamina_getdisplaycost("Cleaning the Carcass");
                    addnav(array("Pay 10 Req for a Carcass Cleaning lesson (`Q%s%%`0)", $cleancost), "runmodule.php?module=meatschool&op=train&train=clean");
                    $cookcost = stamina_getdisplaycost("Cooking");
                    addnav(array("Pay 10 Req for a Cookery lesson (`Q%s%%`0)", $cookcost), "runmodule.php?module=meatschool&op=train&train=cook");
                } else {
                    addnav("You don't have enough money.  No more lessons for you.", "");
                }
            } else {
                output("Maiko shows you a grin.  \"`%Well, that was a lot of fun.  But I can see you're getting tired - no point in training any more today, I'm afraid.`0\"  She shoos you out of the door.");
            }
            addnav("Leave this place");
            addnav("Return to Kittania", "village.php");
            break;
    }
    page_footer();
    return true;
}
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 racezombie_dohook($hookname, $args)
{
    global $session, $resline;
    $city = "New Pittsburgh";
    $race = "Zombie";
    switch ($hookname) {
        case "racenames":
            $args[$race] = $race;
            break;
        case "changesetting":
            // Ignore anything other than villagename setting changes
            if ($args['setting'] == "villagename" && $args['module'] == "racezombie") {
                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'] == 0) {
                break;
            }
            output("`0<a href='newday.php?setrace={$race}{$resline}'>\"BRAAAAAAAAAAAAINS.\"</a>`n`n", true);
            addnav("`0Zombie`0", "newday.php?setrace={$race}{$resline}");
            addnav("", "newday.php?setrace={$race}{$resline}");
            break;
        case "setrace":
            if ($session['user']['race'] == $race) {
                output("`0The hairy man nods.  \"`6All right, all right, a simple \"I'm a zombie\" would have done.`0\"  He looks down and writes in his ledger.  \"`6Zed, oh, em, bee, why.  Zombie.  There.`0\"`n`nYou give the man a sheepish look.  \"`#I didn't actually mean to say that.  It just slipped out.`0\"`n`nHe smiles.  \"`6That's okay, I know how it is.  So, how did you get here?`0\"`n`n\"`#As far as I know, it was on a jet PLAAAAAAAAINS oh God!`0\"  You clap your hands over your mouth.`n`nThe gatekeeper chuckles.  \"`6Works every time.`0\"`n`nYou scowl at him.  \"`#Get on with the form.`0\"`n`n\"`6So, have you been a zombie all your life?`0\"`n`nYou pause.  \"`#I think so.  I mean...  Growing up, I think I played with the other zombie kids in zombie school, but...  Hmm.  It's amazing that there would have `ibeen`i a zombie school in the first place.`0\"  You give the man a very serious look.  \"`#This really doesn't make much sense at all, does it?`0\"`n`n\"`6Few things do around here, sunshine.  Do yourself a favour and don't think about it too much.  Unless you want your head to explode.`0\"`n`nThe word rushes up your throat like vomit.  \"`#BRAAAAAAAAAINS!`0\"`n`n\"`6Yes, that's right, brains.  Lovely juicy brains, splattering around all over the shop.  Yum!`0\"`n`nYou scowl at the gatekeeper while convulsing again, your mouth operating of its own accord.  \"`#BRAAAAAAAAAINS you know, that's really not funny.`0\"`n`n\"`6I know.  I shouldn't make fun.  It's a tough life for zombies.  You have it very hard, don't you?  Bits falling off all the time?  Uncontrollable larynx and primeval, base reactions if something sets you off?`0\"`n`n\"`#That's not true.`0\"  You shoot the gatekeeper a withering glare.  \"`#You've just been perpetuating the tired old Zombie stereotype.  And I, for one, am sick of the constant prejudice that comes from people like you.`0\"`n`n\"`6All right, all right, I meant no offense.  I was just having a little joke.`0\"`n`nGrudgingly, you remember your manners.  \"`#Apology accepted.  I didn't mean to get angry.  It's just hard, you know?`0\"`n`n\"`6I know,`0\" says the gatekeeper with a twinkle in his eye.  \"`6You don't need to explain.`0\"`n`n\"`#EXPLAAAAAAAAAAAAAAAAAAINS!  Oh, `ifuck you`i.`0\"  You storm off towards the gate.`n`nBehind you, the gatekeeper cries \"`6You know what, I think it might rain!`0\"`n`n\"`#RAAAAAAAAAINS!`0\" says your mouth.  \"`3`iFuck you, old man,`i`0\" says your internal monologue.  \"`3`iFuck you and your tasty, tasty brains.`i`0\"");
                if (is_module_active("cities")) {
                    set_module_pref("homecity", $city, "cities");
                    if ($session['user']['age'] == 0) {
                        $session['user']['location'] = $city;
                    }
                }
            }
            break;
        case "alternativeresurrect":
        case "stamina-newday":
            if ($session['user']['race'] == $race) {
                racezombie_checkcity();
                //Stamina buffs
                require_once "modules/staminasystem/lib/lib.php";
                apply_stamina_buff('Zombie2', array("name" => "Zombie Bonus: Combat Endurance", "class" => "Combat", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie1', array("name" => "Zombie Bonus: Hunting Endurance", "class" => "Hunting", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie8', array("name" => "Zombie Bonus: Carcass Cleaning Skills", "action" => "Cleaning the Carcass", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie0', array("name" => "Zombie Penalty: Slow of Mind", "class" => "Global", "costmod" => 1, "expmod" => 0.8, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie3', array("name" => "Zombie Penalty: Slow-Moving", "class" => "Travelling", "costmod" => 1.2, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie4', array("name" => "Zombie Penalty: Scavenging Slowness", "action" => "Scavenging for Scrap", "costmod" => 1.2, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie5', array("name" => "Zombie Penalty: Metalwork Ineptitude", "action" => "Metalworking", "costmod" => 1.4, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie6', array("name" => "Zombie Penalty: Soldering Ineptitude", "action" => "Soldering", "costmod" => 1.4, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie7', array("name" => "Zombie Penalty: Programming Ineptitude", "action" => "Programming", "costmod" => 1.4, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('Zombie9', array("name" => "Zombie Penalty: Cooking Ineptitude", "action" => "Cooking", "costmod" => 1.2, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('raceclassy', array("name" => "Zombie Bonus: Insults Proficiency", "class" => "Insults", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                //Combat Buffs
                apply_buff("racialbenefit1", array("name" => "`0Zombie Bonus: No Pain`0", "defmod" => "1.2", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racezombie"));
                apply_buff("racialbenefit2", array("name" => "`0Zombie Bonus: Leathery Fists`0", "atkmod" => "1.1", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racezombie"));
            }
            break;
        case "creatureencounter":
            if ($session['user']['race'] == $race) {
                //get those folks who haven't manually chosen a race
                racezombie_checkcity();
                $args['creaturegold'] = round($args['creaturegold'] * 1.2, 0);
            }
            break;
        case "battle-victory":
            if ($session['user']['race'] == $race && $session['user']['alive'] == false) {
                if (!$session['user']['alive']) {
                    $args['creatureexp'] = round($args['creatureexp'] * 0.8);
                }
            }
            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":
            racezombie_checkcity();
            if ($session['user']['location'] == $city) {
                $args['text'] = array("`0You are standing in the heart of New Pittsburgh.  This place used to be populated almost entirely by humans, but... well, you know zombies.`n`nThe stench of rotten flesh hangs in the air, and cries of \"BRAAAAAINS\" can be heard every now and then.`n`nYou notice a group of zombies conversing in grunts and moans around an old horse trough, idly picking at the flappy bits of skin on their necks.`n");
                $args['schemas']['text'] = "module-racezombie";
                $args['clock'] = "`n`0From the strength of the overpowering odour, you reason that it is approximately `0%s`0.`n";
                $args['schemas']['clock'] = "module-racezombie";
                if (is_module_active("calendar")) {
                    $args['calendar'] = "`n`0Written in blood on a nearby wall is `0%s`0, `0%s %s %s`0.`n";
                    $args['schemas']['calendar'] = "module-racezombie";
                }
                $args['title'] = array("%s, Home of the Zombies", $city);
                $args['schemas']['title'] = "module-racezombie";
                $args['sayline'] = "says";
                $args['schemas']['sayline'] = "module-racezombie";
                $args['talk'] = "`n`0Nearby some zombies talk:`n";
                $args['schemas']['talk'] = "module-racezombie";
                $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 wonderful smells around you.  The smells of BRAAAAAAINS.";
                } else {
                    $args['newest'] = "`n`0Wandering the village, jaw agape and eyeballs swivelling in their sockets, is `0%s`0.";
                }
                $args['schemas']['newest'] = "module-racezombie";
                $args['section'] = "village-{$race}";
                $args['stablename'] = "Mike's Chop Shop";
                $args['schemas']['stablename'] = "module-racezombie";
                $args['gatenav'] = "Outpost Gates";
                $args['fightnav'] = "Brains Avenue";
                $args['marketnav'] = "Shiny Street";
                $args['tavernnav'] = "Hugs Boulevard";
                $args['schemas']['gatenav'] = "module-racezombie";
                unblocknav("stables.php");
            }
            break;
        case "stablelocs":
            tlschema("mounts");
            $args[$city] = sprintf_translate("The Village of %s", $city);
            tlschema();
            break;
        case "stabletext":
            if ($session['user']['location'] != $city) {
                break;
            }
            $args['title'] = "Mike's Chop Shop";
            $args['schemas']['title'] = "module-racezombie";
            $args['desc'] = array("`0Just next door to the Clan Halls, a scruffy-looking warehouse has been erected.  It looks pretty similar to the other buildings - blood splattered along every wall, groups of undead monsters shambling around, cries of \"BRAAAAAAAAINS!\" emanating from within - you know, the usual.  You head inside.`n`n", array("As you venture inside the building, a young Zombie woman shuffles towards you on her one good leg.  \"`^Good day to you, %s - my name is Mike, and what may I do for you today?`0\" You reason that \"Mike\" must be short for \"Michelle\" or something - or perhaps this whole franchise thing is going a bit too far.", translate_inline($session['user']['sex'] ? 'madam' : 'sir', 'stables')));
            $args['schemas']['desc'] = "module-racezombie";
            $args['lad'] = "friend";
            $args['schemas']['lad'] = "module-racezombie";
            $args['lass'] = "friend";
            $args['schemas']['lass'] = "module-racezombie";
            $args['nosuchbeast'] = "`0\"`^I'm sorry, I've never heard of such a thing,`0\" Mike says apologetically.";
            $args['schemas']['nosuchbeast'] = "module-racezombie";
            $args['toolittle'] = "`0Mike looks over the handful of currency you offered.  \"`^Hmm.  Well, you see, the price for this %s was actually `0%s `^Requisition tokens and `%%s`^ cigarettes.  My apologies for any misunderstandings.`0\"";
            $args['schemas']['toolittle'] = "module-racezombie";
            $args['replacemount'] = "`0You sadly watch Mike lead your %s`0 away, along with your cigarettes.  However, when she returns, she brings with her a nice new `0%s`0 which makes you feel a little better.";
            $args['schemas']['replacemount'] = "module-racezombie";
            $args['newmount'] = "`0You hand over your currency.  Within moments, you become the proud recipient of a lovely new `0%s`0!";
            $args['schemas']['newmount'] = "module-racezombie";
            $args['confirmsale'] = "`n`n`0Mike eyes your mount up and down, checking it over carefully.  \"`^My, this is indeed a fine specimen.  Are you quite sure you wish to part with it?`0\"";
            $args['schemas']['confirmsale'] = "module-racezombie";
            $args['mountsold'] = "`0With but a single tear, you hand your %s`0 over to Mike.  The tear dries quickly, and the %s in hand helps you quickly overcome your sorrow.";
            $args['schemas']['mountsold'] = "module-racezombie";
            $args['offer'] = "`n`n`0Mike offers you `0%s`0 Requisition and `%%s`0 Cigarettes for %s`0.";
            $args['schemas']['offer'] = "module-racezombie";
            break;
    }
    return $args;
}
function iitems_weightandmass_process_weights($applybuffs = false, $showbars = false, $returnlocation = false)
{
    global $session, $weightinfo;
    require_once "modules/iitems/lib/lib.php";
    $inventory = iitems_get_player_inventory();
    $weightinfo = array();
    foreach ($inventory as $key => $values) {
        if ($values['wlimit_capacity']) {
            $weightinfo[$values['inventorylocation']]['max'] += $values['wlimit_capacity'];
            if ($values['wlimit_display_name']) {
                $weightinfo[$values['inventorylocation']]['wlimit_display_name'] = $values['wlimit_display_name'];
            }
            if ($values['wlimit_sbuff_name']) {
                $weightinfo[$values['inventorylocation']]['wlimit_sbuff_name'] = $values['wlimit_sbuff_name'];
            }
            if ($values['wlimit_sbuff_roundmsg']) {
                $weightinfo[$values['inventorylocation']]['wlimit_sbuff_roundmsg'] = $values['wlimit_sbuff_roundmsg'];
            }
            if ($values['wlimit_sbuff_action']) {
                $weightinfo[$values['inventorylocation']]['wlimit_sbuff_action'] = $values['wlimit_sbuff_action'];
            }
            if ($values['wlimit_use_sbuff']) {
                $weightinfo[$values['inventorylocation']]['wlimit_use_sbuff'] = $values['wlimit_use_sbuff'];
            }
            if ($values['wlimit_hardlimit']) {
                $weightinfo[$values['inventorylocation']]['wlimit_hardlimit'] = $values['wlimit_hardlimit'];
            }
        }
        if ($values['quantity']) {
            $weightinfo[$values['inventorylocation']]['current'] += $values['weight'] * $values['quantity'];
        } else {
            $weightinfo[$values['inventorylocation']]['current'] += $values['weight'];
        }
    }
    require_once "modules/staminasystem/lib/lib.php";
    if ($applybuffs) {
        foreach ($weightinfo as $invloc => $details) {
            $sbuffid = "wlimit_" . $invloc;
            if ($details['current'] > $details['max']) {
                if ($details['wlimit_use_sbuff']) {
                    $penalty = $details['current'] / $details['max'];
                    apply_stamina_buff($sbuffid, array("name" => $details['wlimit_sbuff_name'], "action" => $details['wlimit_sbuff_action'], "costmod" => $penalty, "expmod" => 1, "rounds" => -1, "roundmsg" => $details['wlimit_sbuff_roundmsg'], "wearoffmsg" => ""));
                }
            } else {
                strip_stamina_buff($sbuffid);
            }
        }
    }
    if ($showbars) {
        foreach ($weightinfo as $invloc => $details) {
            $cur = $details['current'] * 5;
            $max = $details['max'] * 5;
            $left = $max - $cur;
            if ($left >= 0) {
                rawoutput("<table><tr><td>" . $details['wlimit_display_name'] . "</td><td><table style='border: solid 1px #000000' width='{$max}' height='7' bgcolor='#333333' cellpadding=0 cellspacing=0><tr><td width='{$cur}' bgcolor='#00ff00'></td><td width='{$left}'></td></tr></table></td><td>" . $details['current'] . "kg / " . $details['max'] . "kg</td></tr></table>");
            } else {
                $over = $cur - $max;
                $totalwidth = $max + $over;
                rawoutput("<table><tr><td>" . $details['wlimit_display_name'] . "</td><td><table style='border: solid 1px #000000' height='7' width='{$totalwidth}' cellpadding=0 cellspacing=0><tr><td width='{$max}' bgcolor='#990000'></td><td width='{$over}' bgcolor='#ff0000'></td></tr></table></td><td>" . $details['current'] . "kg / " . $details['max'] . "kg</td></tr></table>");
            }
        }
    }
    if ($returnlocation) {
        return $weightinfo[$returnlocation];
    } else {
        return true;
    }
}
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;
}
function racemutant_dohook($hookname, $args)
{
    global $session, $resline;
    $city = "Pleasantville";
    $race = "Mutant";
    switch ($hookname) {
        case "racenames":
            $args[$race] = $race;
            break;
        case "changesetting":
            // Ignore anything other than villagename setting changes
            if ($args['setting'] == "villagename" && $args['module'] == "racemutant") {
                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'] < 5) {
                break;
            }
            output("`0You show the gatekeeper a sad smile.  <a href='newday.php?setrace={$race}{$resline}'>\"That's a very insensitive question.\"</a>`n`n", true);
            addnav("`&Mutant`0", "newday.php?setrace={$race}{$resline}");
            addnav("", "newday.php?setrace={$race}{$resline}");
            break;
        case "setrace":
            if ($session['user']['race'] == $race) {
                output("`0The gatekeeper puts on his glasses.  \"`6Oh,`0\" he says, quietly.`n`n\"`#Yes,`0\" you reply.  \"`#Oh.`0\"`n`nYou stare at each other for a moment.  The colour slowly drains from the gatekeeper's face.`n`n\"`6Well,`0\" says the gatekeeper, to break the silence.  \"`6Let's get you signed in, shall we?`0\"  He swallows uncomfortably, and takes out his ledger.  \"`6Em, you, tee, you, enn, tee.  Mu-hluck!`0\"  He swallows again, wiping his mouth on the back of his sleeve.  \"`6Mutant.  Sorry.  Have you been like this all your li... blugh.`0\"  A little blob of vomit plops onto his ledger.  He takes a deep breath.  \"`6Have you been like this all your life?`0\"`n`n\"`#Yes,`0\" you reply.  \"`#Since my dear mother first excreted me from her poor, wretched womb, looked down, screamed \"Dear God what IS that `iTHING`i\" and died immediately from a combination of horror, shame and embarrassment, I have been the hideous abomination that you see before you now.  And you needn't apologise, I'm used to it.`0\"  You shake your head sadly.  \"`#So, so very used to it.`0\"`n`n\"`6Well, that's... hruuuu`iuuuuuuuuu`iuuuurgh!  Oh, sweet Jesus Mary and Joseph!`0\"`n`n\"`#That's okay, let it all out.  Isn't it strange how there's always carrots in there?`0\" you ask.  \"`#You don't have to look up if you don't want to.  I know that the sight of your own expulsions are preferable to my horrendous visage.`0\"`n`n\"`6Blarghle,`0\" says the gatekeeper.`n`n\"`#Like I say, I'm used to it.`0\"  You turn and head toward the gate, leaving a trail of slime behind you.");
                if (is_module_active("cities")) {
                    set_module_pref("homecity", $city, "cities");
                    if ($session['user']['age'] == 0) {
                        $session['user']['location'] = $city;
                    }
                }
            }
            break;
        case "stamina-newday":
        case "alternativeresurrect":
            if ($session['user']['race'] == $race) {
                racemutant_checkcity();
                //Stamina Buffs
                require_once "modules/staminasystem/lib/lib.php";
                apply_stamina_buff('mutant2', array("name" => "Mutant Bonus: Combat Skills", "class" => "Combat", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('mutant4', array("name" => "Mutant Bonus: Scavenging Proficiency", "action" => "Scavenging for Scrap", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('mutant5', array("name" => "Mutant Bonus: Metalwork Skills", "action" => "Metalworking", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('mutant6', array("name" => "Mutant Bonus: Soldering Skills", "action" => "Soldering", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('mutant8', array("name" => "Mutant Bonus: Carcass Cleaning Skills", "action" => "Cleaning the Carcass", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('mutant0', array("name" => "Mutant Penalty: Learning Difficulties", "class" => "Global", "costmod" => 1, "expmod" => 0.5, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('mutant1', array("name" => "Mutant Penalty: Hunting Inexperience", "class" => "Hunting", "costmod" => 1.1, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('raceclassy', array("name" => "Mutant Bonus: Insults Proficiency", "class" => "Insults", "costmod" => 0.5, "expmod" => 1.1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                //Combat Buffs
                apply_buff("racialbenefit1", array("name" => "`7Mutant Bonus: Leathery Hide`0", "defmod" => "1.1", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racemutant"));
                apply_buff("racialbenefit2", array("name" => "`7Mutant Bonus: Combat Appendages`0", "atkmod" => "1.1", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racemutant"));
            }
            break;
        case "creatureencounter":
            if ($session['user']['race'] == $race) {
                //get those folks who haven't manually chosen a race
                racemutant_checkcity();
                $args['creaturegold'] = round($args['creaturegold'] * 0.8, 0);
                $args['creatureexp'] = round($args['creatureexp'] * 0.8, 0);
            }
            break;
        case "battle-victory":
            if ($session['user']['race'] == $race && $session['user']['alive'] == false) {
                $args['creatureexp'] = round($args['creatureexp'] * 0.8);
            }
            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":
            racemutant_checkcity();
            if ($session['user']['location'] == $city) {
                $args['text'] = array("`0You are standing in the heart of Pleasantville.  It's all very clean, but there are no reflective surfaces - every window has either been boarded up or slavered with a thick coating of slime to prevent reflections.`n`nLooking around at the state of some of your fellow contestants, you think you can see why.`n`n");
                $args['schemas']['text'] = "module-racemutant";
                $args['clock'] = "`0A clock in the village square reads `&%s`0.`n`n";
                $args['schemas']['clock'] = "module-racemutant";
                if (is_module_active("calendar")) {
                    $args['calendar'] = "`0A smaller dial beneath reads `&%s`0, `&%s %s %s`0.`n`n";
                    $args['schemas']['calendar'] = "module-racemutant";
                }
                $args['title'] = array("%s, Home of the Mutants", $city);
                $args['schemas']['title'] = "module-racemutant";
                $args['sayline'] = "says";
                $args['schemas']['sayline'] = "module-racemutant";
                $args['talk'] = "`&Nearby some mutants drone endlessly about their problems:`n";
                $args['schemas']['talk'] = "module-racemutant";
                $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`0You wander around the village, sliding your noodly appendages over every surface, examining it all in great detail.";
                } else {
                    $args['newest'] = "`n`0Wandering the village, touching everything with hideously freaky noodles, is `&%s`0.";
                }
                $args['schemas']['newest'] = "module-racemutant";
                $args['section'] = "village-{$race}";
                $args['stablename'] = "Mike's Chop Shop";
                $args['schemas']['stablename'] = "module-racemutant";
                $args['gatenav'] = "Outpost Gates";
                $args['fightnav'] = "Oppression Street";
                $args['marketnav'] = "Capitalism Avenue";
                $args['tavernnav'] = "Despair Lane";
                $args['schemas']['gatenav'] = "module-racemutant";
                unblocknav("stables.php");
            }
            break;
        case "stabletext":
            if ($session['user']['location'] != $city) {
                break;
            }
            $args['title'] = "Mike's Chop Shop";
            $args['schemas']['title'] = "module-racemutant";
            $args['desc'] = array("`6Just next door to the Clan Halls, a scruffy-looking warehouse has been erected.  You head inside.`n`n", array("As you venture inside the building, you notice a young man tending to a nearby... something.  Something bloody indescribable.  \"`#Hello?`6\" you call.  The young man turns around.  \"`#Agh,`6\" you say, quietly.  Then, you smile sheepishly.  \"`#I mean... hi!`6\"`n`n\"`^Don't worry, I'm used to it.  The name's Mike, and what can I do for you today, my good %s?`6\" You try your hardest not to stare, because you know that if you stare, you'll end up counting under your breath to see how many eyes he has, and that would be rude.", translate_inline($session['user']['sex'] ? 'madam' : 'sir', 'stables')));
            $args['schemas']['desc'] = "module-racemutant";
            $args['lad'] = "friend";
            $args['schemas']['lad'] = "module-racemutant";
            $args['lass'] = "friend";
            $args['schemas']['lass'] = "module-racemutant";
            $args['nosuchbeast'] = "`6\"`^I'm sorry, I've never heard of such a thing,`6\" Mike says apologetically.";
            $args['schemas']['nosuchbeast'] = "module-racemutant";
            $args['toolittle'] = "`6Mike looks over the handful of currency you offered.  \"`^Hmm.  Well, you see, the price for this %s was actually `&%s `^Requisition tokens and `%%s`^ cigarettes.  My apologies for any misunderstandings.`6\"";
            $args['schemas']['toolittle'] = "module-racemutant";
            $args['replacemount'] = "`6You sadly watch Mike lead your %s`6 away, along with your cigarettes.  However, when he returns, he brings with him a nice new `&%s`6 which makes you feel a little better.";
            $args['schemas']['replacemount'] = "module-racemutant";
            $args['newmount'] = "`6You hand over your currency.  Within moments, you become the proud recipient of a lovely new `&%s`6!";
            $args['schemas']['newmount'] = "module-racemutant";
            $args['confirmsale'] = "`n`n`6Mike eyes your mount up and down, checking it over carefully.  Probably seeing it in ways that you can only imagine.  \"`^My, this is indeed a fine specimen.  Are you quite sure you wish to part with it?`6\"";
            $args['schemas']['confirmsale'] = "module-racemutant";
            $args['mountsold'] = "`6With but a single tear, you hand your %s`6 over to Mike.  The tear dries quickly, and the %s in hand helps you quickly overcome your sorrow.";
            $args['schemas']['mountsold'] = "module-racemutant";
            $args['offer'] = "`n`n`6Mike offers you `&%s`6 Requisition and `%%s`6 Cigarettes for %s`6.";
            $args['schemas']['offer'] = "module-racemutant";
            break;
        case "stablelocs":
            tlschema("mounts");
            $args[$city] = sprintf_translate("The Village of %s", $city);
            tlschema();
            break;
    }
    return $args;
}
function racerobot_dohook($hookname, $args)
{
    global $session, $resline;
    $city = "Cyber City 404";
    $race = "Robot";
    switch ($hookname) {
        case "load_inventory":
            if ($session['user']['race'] == $race) {
                foreach ($args as $itemid => $prefs) {
                    if ($prefs['blockrobot']) {
                        $args[$itemid]['blockuse'] = true;
                    }
                }
            }
            break;
        case "racenames":
            $args[$race] = $race;
            break;
        case "changesetting":
            // Ignore anything other than villagename setting changes
            if ($args['setting'] == "villagename" && $args['module'] == "racerobot") {
                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'] < 7) {
                break;
            }
            clear_module_pref("heat");
            clear_module_pref("atk");
            clear_module_pref("def");
            clear_module_pref("heal");
            output("`0<a href='newday.php?setrace={$race}{$resline}'>You grin at the gatekeeper</a>, exposing your sharp, bitey metal teeth.`n`n", true);
            addnav("`&Robot`0", "newday.php?setrace={$race}{$resline}");
            addnav("", "newday.php?setrace={$race}{$resline}");
            break;
        case "setrace":
            if ($session['user']['race'] == $race) {
                output("\"`6Oh, I see, right,`0\" says the gatekeeper, and takes out his ledger.  \"`6Are, oh, double-you, bee, oh, tee, tee.  Robot.  I must say, it's nice to see some straightforward logic in this place.`0\"`n`nYou nod.  \"`#Yes,`0\" you reply, \"`#it is.`0\"`n`nThe gatekeeper looks up and says, with a mischievous grin, \"`6So - would you like to play a game of chess?`0\"`n`nYou scowl.  \"`#Do not play games with me, human.  Just because you know how to press my buttons does not mean I will allow you to press them.`0\"`n`n\"`6Sorry,`0\" says the gatekeeper with an even wider smile, \"`6I meant - SUDO play a game of chess.`0\"`n`n\"`#I'd love to,`0\" you reply.`n`nAfter you checkmate the gatekeeper in three moves, he sits back, obviously miffed.`n`n\"`#As I won,`0\" you say, \"`#you must answer my question: what is this \"love\" of which you humans speak?`0\"`n`nThe gatekeeper looks up at you, pouting, arms folded.  \"`6This statement is false.`0\"`n`nYou twitch a little, let out a quiet, sad \"`#beep,`0\" and fall over onto your back.`n`nWhen you regain consciousness, you draw yourself up to your full height and stare the grinning gatekeeper in the face.  \"`#I have processed all the relevant data,`0\" you say, in a low, mechanical growl, \"`#and have come to the conclusion that you, fleshbag, are a bastard.`0\"`n`nThe gatekeeper winks and smiles.  \"`6Don't tell the others.`0\"`n`nYou turn and head towards the gate, muttering under your breath.`n`n\"`6Pi is exactly three, by the way!`0\" he calls after you.  But you're too wily for him, oh yes indeed.  Just two minutes later, you reboot successfully and place him on your \"ignore\" list.");
                if (is_module_active("cities")) {
                    set_module_pref("homecity", $city, "cities");
                    if ($session['user']['age'] == 0) {
                        $session['user']['location'] = $city;
                    }
                }
            }
            break;
        case "alternativeresurrect":
            if ($session['user']['race'] == $race) {
                racerobot_checkcity();
                set_module_pref("heat", 0);
                //Stamina buffs
                require_once "modules/staminasystem/lib/lib.php";
                apply_stamina_buff('robot3', array("name" => "Robot Bonus: Fast-Moving and Fast-Learning", "action" => "Global", "costmod" => 0.7, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                //combat buffs
                apply_buff("robotatk", array("name" => "`7Robot Bonus: Stabbity Claws`0", "atkmod" => "1.3", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                apply_buff("robotdef", array("name" => "`7Robot Penalty: Glass Skin`0", "defmod" => "0.4", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                if (get_module_pref("atk") > 0) {
                    $atk = get_module_pref("atk") / 10 + 1;
                    apply_buff("robotatkoc", array("name" => "`7Overclock: Increased Upper Body Servo Power`0", "atkmod" => $atk, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                }
                if (get_module_pref("def") > 0) {
                    $def = get_module_pref("def") / 10 + 1;
                    apply_buff("robotdefoc", array("name" => "`7Overclock: Increased Lower Body Servo Power`0", "defmod" => $def, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                }
                if (get_module_pref("heal") > 0) {
                    $heal = get_module_pref("heal");
                    apply_buff("robothealoc", array("name" => "`7Overclock: In-Combat Self-Repair Subsystem`0", "regen" => $heal, "effectmsg" => "`#SYSTEM MESSAGE: {damage} POINTS OF DAMAGE AUTO-REPAIRED`0", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                } else {
                    strip_buff("robothealoc");
                }
            }
            break;
        case "stamina-newday":
            if ($session['user']['race'] == $race) {
                racerobot_checkcity();
                set_module_pref("heat", 0);
                increment_module_pref("amber", -200000, "staminasystem");
                //Stamina buffs
                require_once "modules/staminasystem/lib/lib.php";
                apply_stamina_buff('robot3', array("name" => "Robot Bonus: Fast-Moving and Fast-Learning", "action" => "Global", "costmod" => 0.7, "expmod" => 1.2, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('raceclassy', array("name" => "Robot Penalty: Insults Incompetence", "class" => "Insults", "costmod" => 2, "expmod" => 0.5, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                //combat buffs
                apply_buff("robotatk", array("name" => "`7Robot Bonus: Stabbity Claws`0", "atkmod" => "1.3", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                apply_buff("robotdef", array("name" => "`7Robot Penalty: Glass Skin`0", "defmod" => "0.4", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                if (get_module_pref("atk") > 0) {
                    $atk = get_module_pref("atk") / 10 + 1;
                    apply_buff("robotatkoc", array("name" => "`7Overclock: Increased Upper Body Servo Power`0", "atkmod" => $atk, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                }
                if (get_module_pref("def") > 0) {
                    $def = get_module_pref("def") / 10 + 1;
                    apply_buff("robotdefoc", array("name" => "`7Overclock: Increased Lower Body Servo Power`0", "defmod" => $def, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                }
                if (get_module_pref("heal") > 0) {
                    $heal = get_module_pref("heal");
                    apply_buff("robothealoc", array("name" => "`7Overclock: In-Combat Self-Repair Subsystem`0", "regen" => $heal, "effectmsg" => "`#SYSTEM MESSAGE: {damage} POINTS OF DAMAGE AUTO-REPAIRED`0", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racerobot"));
                } else {
                    strip_buff("robothealoc");
                }
            }
            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":
            racerobot_checkcity();
            if ($session['user']['location'] == $city) {
                $args['text'] = array("`0You are standing in the heart of %s.  Though called a city by outsiders, this stronghold of robots is little more than a glorified scrapyard.  Puddles of rusted, oily water cover the bare, muddy earth, and piles of scrap metal lie here and there.  Some residents are engaged in stilted, mechanical conversation around the well in the village square.`n", $city, $city);
                $args['schemas']['text'] = "module-racerobot";
                $args['clock'] = "`n`0The great clockwork readout at the centre of the city reads `&%s`0.`n";
                $args['schemas']['clock'] = "module-racerobot";
                if (is_module_active("calendar")) {
                    $args['calendar'] = "`n`0A smaller contraption next to it reads `&%s`0, `&%s %s %s`0.`n";
                    $args['schemas']['calendar'] = "module-racerobot";
                }
                $args['title'] = array("%s, Home of the Robots", $city);
                $args['schemas']['title'] = "module-racerobot";
                $args['sayline'] = "says";
                $args['schemas']['sayline'] = "module-racerobot";
                $args['talk'] = "`n`&Nearby some robots talk:`n";
                $args['schemas']['talk'] = "module-racerobot";
                $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-racerobot";
                $args['section'] = "village-{$race}";
                $args['stablename'] = "Mike's Chop Shop";
                $args['schemas']['stablename'] = "module-racerobot";
                $args['gatenav'] = "Village Gates";
                $args['schemas']['gatenav'] = "module-racerobot";
                unblocknav("stables.php");
            }
            break;
        case "stabletext":
            if ($session['user']['location'] != $city) {
                break;
            }
            $args['title'] = "Mike's Chop Shop";
            $args['schemas']['title'] = "module-racerobot";
            $args['desc'] = array("`0Just outside the outskirts of the mighty scrapyard, a training area and riding range has been set up.", "You can see a tall, spindly Robot whose name you assume to be Mike.  He's busily tending to his flock of abominations, using his many custom-built appendages to care for the creatures and machines in his care.  Vehicles, animals, and Genetically-Engineered Beasts of Burden are arrayed in front of you.", array("As you approach, \"Mike\" spins around to meet you, brandishing a screwdriver.  \"`^HOW MAY I HELP YOU MY FINE YOUNG %s?`0\" he asks in a buzzing, 8-bit monotone.", translate_inline($session['user']['sex'] ? 'LASS' : 'LAD', 'stables')));
            $args['schemas']['desc'] = "module-racerobot";
            $args['lad'] = "friend";
            $args['schemas']['lad'] = "module-racerobot";
            $args['lass'] = "friend";
            $args['schemas']['lass'] = "module-racerobot";
            $args['nosuchbeast'] = "`0\"`^I DO NOT STOCK ANY SUCH BEAST OR MACHINE.  PERHAPS IT WAS A DREAM OF YOURS`0\", Mike says apologetically.";
            $args['schemas']['nosuchbeast'] = "module-racerobot";
            $args['finebeast'] = array("`0\"`^THIS ONE WILL ASSIST WITH YOUR OBJECTIVE OF CRUSHING YOUR FOES TO A FINE PASTE BENEATH YOUR MIGHTY METAL FEET,`0\" says Mike.`n`n", "`0\"`^TO THIS ONE, THERE ARE NO SUPERIOR EXAMPLES`0\" Mike boasts.`n`n", "`0\"`^DOES THIS ONE NOT HAVE A FINE SHINE`0\" he asks.`n`n", "`0\"`^THIS ONE I FIND AESTHETICALLY PLEASING, BEING AS ITS ANGLES AND SIZES ARE ALMOST A PERFECT 1:1.6180339887 RATIO`0\" exclaims Mike.`n`n", "`0\"`^THIS ONE WOULD BE A VERY ADVISABLE PURCHASE AT 2.1516 TIMES THE PRICE I AM ASKING,`0\" booms Mike.`n`n");
            $args['schemas']['finebeast'] = "module-racerobot";
            $args['toolittle'] = "`0Mike looks over the gold and gems you offer and turns up his mechanical nose, \"`^THIS IS NOT THE CORRECT AMOUNT.  THE %s WILL COST YOU `&%s `^REQUISITION TOKENS  AND `%%s`^ CIGARETTES.  THE PRICE IS NOT NEGOTIABLE.`0\"";
            $args['schemas']['toolittle'] = "module-racerobot";
            $args['replacemount'] = "`0Patting %s`0 on the rump, you hand the reins as well as the money for your new mount, and Mike hands you the reins of a `&%s`0.";
            $args['schemas']['replacemount'] = "module-racerobot";
            $args['newmount'] = "`0You hand over the money for your new mount, and Mike hands you the reins of a new `&%s`0.";
            $args['schemas']['newmount'] = "module-racerobot";
            $args['nofeed'] = "`0\"`^I AM SORRY %s, BUT I DO NOT STOCK FUEL OR FEED HERE.  YOU MUST LOOK ELSEWHERE.`0\"";
            $args['schemas']['nofeed'] = "module-racerobot";
            $args['nothungry'] = "`&%s`0 picks briefly at the food and then ignores it.  Mike, lacking the imagination to be dishonest, shakes his head and hands you back your money.";
            $args['schemas']['nothungry'] = "module-racerobot";
            $args['halfhungry'] = "`&%s`0 dives into the provided food and gets through about half of it before stopping.  \"`^WELL, %s WAS NOT AS HUNGRY AS YOU THOUGHT.`0\" says Mike as he hands you back all but %s Requisition tokens.";
            $args['schemas']['halfhungry'] = "module-racerobot";
            $args['hungry'] = "`0%s`0 seems to inhale the food provided.  %s`0, the greedy creature that it is, then goes snuffling at Mike's pockets for more food.`nMike shakes his head in amusement and collects `&%s`0 Requisition tokens from you.";
            $args['schemas']['hungry'] = "module-racerobot";
            $args['mountfull'] = "`n`0\"`^IT APPEARS, %s, THAT YOUR %s`^ IS NOW FULL.  YOU WILL RETURN WHEN IT IS EMPTY ONCE MORE.`0\" says Mike with a genial smile.";
            $args['schemas']['mountfull'] = "module-racerobot";
            $args['nofeedgold'] = "`0\"`^THAT IS NOT ENOUGH MONEY TO PAY FOR FOOD HERE`0\"  Mike turns his back on you, and you lead %s away to find other places for feeding.";
            $args['schemas']['nofeedgold'] = "module-racerobot";
            $args['confirmsale'] = "`n`n`0UMike eyes your mount up and down, checking it over carefully.  \"`^ARE YOU QUITE SURE YOU WISH TO RELINQUISH THIS CONVEYANCE?`0\"";
            $args['schemas']['confirmsale'] = "module-racerobot";
            $args['mountsold'] = "`0With but a single tear, you hand over the reins to your %s`0 to Mike's stableboy.  The tear dries quickly, and the %s in hand helps you quickly overcome your sorrow.";
            $args['schemas']['mountsold'] = "module-racerobot";
            $args['offer'] = "`n`n`0Mike strokes your creature's flank and offers you `&%s`0 Requisition tokens and `%%s`0 cigarettes for %s`0.";
            $args['schemas']['offer'] = "module-racerobot";
            break;
        case "potion":
            if ($session['user']['race'] == $race) {
                blocknav("healer.php?op=buy&pct=100&return=village.php");
                blocknav("healer.php?op=buy&pct=90&return=village.php");
                blocknav("healer.php?op=buy&pct=80&return=village.php");
                blocknav("healer.php?op=buy&pct=70&return=village.php");
                blocknav("healer.php?op=buy&pct=60&return=village.php");
                blocknav("healer.php?op=buy&pct=50&return=village.php");
                blocknav("healer.php?op=buy&pct=40&return=village.php");
                blocknav("healer.php?op=buy&pct=30&return=village.php");
                blocknav("healer.php?op=buy&pct=20&return=village.php");
                blocknav("healer.php?op=buy&pct=10&return=village.php");
                blocknav("healer.php?op=buy&pct=100");
                blocknav("healer.php?op=buy&pct=90");
                blocknav("healer.php?op=buy&pct=80");
                blocknav("healer.php?op=buy&pct=70");
                blocknav("healer.php?op=buy&pct=60");
                blocknav("healer.php?op=buy&pct=50");
                blocknav("healer.php?op=buy&pct=40");
                blocknav("healer.php?op=buy&pct=30");
                blocknav("healer.php?op=buy&pct=20");
                blocknav("healer.php?op=buy&pct=10");
                output("`n`nThe man stops suddenly and looks you up and down, examining your cracked glass skin and visible wiring harnesses.  \"`6'ere,`3\" he says, \"`6Are you `isure`i you're not a Robot?`3\"`n`nYou're really not sure what to say.");
            }
            break;
        case "village":
            if ($session['user']['race'] == $race) {
                blocknav("runmodule.php?module=bloodbank");
                blocknav("healer.php?op=buy");
                addnav("Robot Talents");
                addnav("Configure Overclocking", "runmodule.php?module=racerobot&op=config&from=village");
                if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                    $scost = 400 * ($session['user']['maxhitpoints'] - $session['user']['hitpoints']);
                    $spct = $scost * 100 / 1000000;
                    addnav(array("Standby until Repaired (`Q%s%%`0)", $spct), "runmodule.php?module=racerobot&op=standby&til=repaired&from=village", true);
                }
                $heat = get_module_pref("heat");
                if ($heat > 0) {
                    $scost = 40 * $heat;
                    $spct = $scost * 100 / 1000000;
                    addnav(array("Standby until Cooled (`Q%s%%`0)", $spct), "runmodule.php?module=racerobot&op=standby&til=cooled&from=village", true);
                }
            }
            break;
        case "forest":
            if ($session['user']['race'] == $race) {
                addnav("Robot Talents");
                addnav("Configure Overclocking", "runmodule.php?module=racerobot&op=config&from=forest");
                if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                    $scost = 400 * ($session['user']['maxhitpoints'] - $session['user']['hitpoints']);
                    $spct = $scost * 100 / 1000000;
                    addnav(array("Standby until Repaired (`Q%s%%`0)", $spct), "runmodule.php?module=racerobot&op=standby&til=repaired&from=forest", true);
                }
                $heat = get_module_pref("heat");
                if ($heat > 0) {
                    $scost = 40 * $heat;
                    $spct = $scost * 100 / 1000000;
                    addnav(array("Standby until Cooled (`Q%s%%`0)", $spct), "runmodule.php?module=racerobot&op=standby&til=cooled&from=forest", true);
                }
            }
            break;
        case "worldnav":
            if ($session['user']['race'] == $race) {
                addnav("Robot Talents");
                addnav("Configure Overclocking", "runmodule.php?module=racerobot&op=config&from=worldnav");
                if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                    $scost = 400 * ($session['user']['maxhitpoints'] - $session['user']['hitpoints']);
                    $spct = $scost * 100 / 1000000;
                    addnav(array("Standby until Repaired (`Q%s%%`0)", $spct), "runmodule.php?module=racerobot&op=standby&til=repaired&from=worldnav", true);
                }
                $heat = get_module_pref("heat");
                if ($heat > 0) {
                    $scost = 40 * $heat;
                    $spct = $scost * 100 / 1000000;
                    addnav(array("Standby until Cooled (`Q%s%%`0)", $spct), "runmodule.php?module=racerobot&op=standby&til=cooled&from=worldnav", true);
                }
            }
            break;
        case "stablelocs":
            tlschema("mounts");
            $args[$city] = sprintf_translate("%s", $city);
            tlschema();
            break;
        case "startofround":
            if ($session['user']['race'] == $race && $session['user']['alive'] == 1) {
                $heat = get_module_pref("heat");
                debug("Heat level: " . $heat);
                $fail = e_rand(100, 1500);
                debug("Fail Threshold: " . $fail);
                if ($heat >= $fail) {
                    $penalty = $session['user']['maxhitpoints'] / 100 * ($heat / 10);
                    debug($penalty);
                    $damage = 0 - $penalty;
                    debug("Robot is Overheating!");
                    apply_buff("robotoverheat", array("regen" => $damage, "effectmsg" => "`4`bYou feel a horrible burning, popping sensation deep within your chest!  Something has gone badly wrong, and one of your internal components is overheating!  You lose {damage} hitpoints!`b", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => 1, "schema" => "module-racerobot"));
                }
                //increase player heat level
                $heat += get_module_pref("atk") * 10;
                $heat += get_module_pref("def") * 10;
                $heat += get_module_pref("heal") * 10;
                set_module_pref("heat", $heat);
                debug("Heat level: " . $heat);
            }
            break;
        case "charstats":
            if ($session['user']['race'] == $race) {
                $heat = get_module_pref("heat");
                $col = "#00FF00";
                if ($heat > 200) {
                    $col = "#FDFF00";
                }
                if ($heat > 400) {
                    $col = "#FFA200";
                }
                if ($heat > 600) {
                    $col = "#FF5A00";
                }
                if ($heat > 800) {
                    $col = "#FF0000";
                }
                $width = $heat / 10;
                if ($width > 100) {
                    $width = 100;
                }
                $nwidth = 100 - $width;
                $bar = "<table style='border: solid 1px #000000' bgcolor='#333333' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$width}%' bgcolor='{$col}'></td><td width='{$nwidth}%' bgcolor='\$#333333'></td></tr></table>";
                setcharstat("Vital Info", "Heat Level", $bar);
            }
            break;
    }
    return $args;
}
function racemidget_dohook($hookname, $args)
{
    global $session, $resline;
    $city = "Squat Hole";
    $race = "Midget";
    static $damagestart = 0;
    switch ($hookname) {
        case "racenames":
            $args[$race] = $race;
            break;
        case "changesetting":
            // Ignore anything other than villagename setting changes
            if ($args['setting'] == "villagename" && $args['module'] == "racemidget") {
                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'] < 3) {
                break;
            }
            output("`0You stand on tiptoes, thrust a tiny upraised middle finger at the gatekeeper's face, and say <a href='newday.php?setrace={$race}{$resline}'>\"Does it fookin' LOOK like I'm a yooman, dick'ead?\"</a>`n`n", true);
            addnav("`&Midget`0", "newday.php?setrace={$race}{$resline}");
            addnav("", "newday.php?setrace={$race}{$resline}");
            break;
        case "setrace":
            if ($session['user']['race'] == $race) {
                set_module_pref("midgetrage", 0);
                output("`0\"`6All right, all right, you don't have to shout,`0\" says the gatekeeper.  He pulls out his ledger.  \"`6Right, then.  Em, eye, jay, eye, tee.  Midget.`0\"`n`n\"`#That's right,`0\" you say, hoping that he doesn't cotton on to the fact that you can't read or write.  \"`#And don't forget it, innit?`0\"`n`n\"`6Have you been like this all your life?`0\"`n`n\"`#What's it to you, pal?!`0\"`n`nThe gatekeeper sighs.  \"`6Nothing, just making conversation.  Off you go, then.`0\"`n`nIncensed, you scream up at the gatekeeper.  \"`#Don't tell ME to f**k off!  I'll go where I fookin' well like!`0\"`n`n\"`6If I remember rightly,`0\" says the gatekeeper, \"`6you came here so that you could enter the outpost, right?  Well, there's nothing stopping you now.`0\"`n`n\"`#Don'tchu fookin' get clever with me, mate!  I'll fookin' deck yer!  Come on then, right here, right now!  I'll fookin' FLOOR yer, dick'ead!`0\"`n`nThe gatekeeper sighs again, steps out through a door in the back of his hut, walks around to the front and kicks you, very hard, in the crotch.  You sail over the wall like a football.`n`n\"`6Have a pleasant stay,`0\" calls the gatekeeper.");
                if (is_module_active("cities")) {
                    set_module_pref("homecity", $city, "cities");
                    if ($session['user']['age'] == 0) {
                        $session['user']['location'] = $city;
                    }
                }
            }
            break;
        case "stamina-newday":
        case "alternativeresurrect":
            if ($session['user']['race'] == $race) {
                racemidget_checkcity();
                set_module_pref("midgetrage", 0);
                //Stamina buffs
                require_once "modules/staminasystem/lib/lib.php";
                apply_stamina_buff('midget2', array("name" => "Midget Bonus: Combat Skills", "class" => "Combat", "costmod" => 0.5, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget1', array("name" => "Midget Bonus: Hunting Skills", "class" => "Hunting", "costmod" => 0.5, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget4', array("name" => "Midget Bonus: Scavenging Proficiency", "action" => "Scavenging for Scrap", "costmod" => 0.5, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget8', array("name" => "Midget Bonus: Carcass Cleaning Skills", "action" => "Cleaning the Carcass", "costmod" => 0.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget0', array("name" => "Midget Penalty: Stupidity", "class" => "Global", "costmod" => 1, "expmod" => 0.25, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget3', array("name" => "Midget Penalty: Stubby Little Legs", "class" => "Travelling", "costmod" => 2, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget5', array("name" => "Midget Penalty: Metalwork Incompetence", "action" => "Metalworking", "costmod" => 1.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget6', array("name" => "Midget Penalty: Soldering Incompetence", "action" => "Soldering", "costmod" => 1.8, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget7', array("name" => "Midget Penalty: Programming Ultra-Incompetence", "action" => "Programming", "costmod" => 2, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('midget9', array("name" => "Midget Penalty: Cooking Ineptitude", "action" => "Cooking", "costmod" => 1.2, "expmod" => 1, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('raceclassy', array("name" => "Midget Penalty: Classy Insults Super-Duper Incompetence", "action" => "Insults - Classy", "costmod" => 5, "expmod" => 0.25, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('raceconfusing', array("name" => "Midget Penalty: Confusing Insults Confusion", "action" => "Insults - Confusing", "costmod" => 2, "expmod" => 0.25, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                apply_stamina_buff('racecoarse', array("name" => "Midget Bonus: Coarse Insults Proficiency", "action" => "Insults - Coarse", "costmod" => 0.5, "expmod" => 0.25, "rounds" => -1, "roundmsg" => "", "wearoffmsg" => ""));
                //Combat Buffs
                apply_buff("racialbenefit1", array("name" => "`7Midget Bonus: Freakish Strength`0", "atkmod" => "1.2", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racemidget"));
                apply_buff("racialbenefit2", array("name" => "`7Midget Bonus: Easily Missed`0", "defmod" => "1.2", "allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-racemidget"));
            }
            break;
        case "creatureencounter":
            if ($session['user']['race'] == $race) {
                //get those folks who haven't manually chosen a race
                racemidget_checkcity();
                $args['creaturegold'] = round($args['creaturegold'] * 1.2, 0);
            }
            break;
        case "battle-victory":
            if ($session['user']['race'] == $race) {
                //get those folks who haven't manually chosen a race
                racemidget_checkcity();
                if (!$session['user']['alive']) {
                    debug($args['creatureexp']);
                    $args['creatureexp'] = round($args['creatureexp'] / 2);
                    debug($args['creatureexp']);
                }
            }
            break;
        case "startofround":
            if ($session['user']['race'] == $race) {
                $damagestart = $session['user']['hitpoints'] / $session['user']['maxhitpoints'] * 100;
            }
            break;
        case "endofround":
            if ($session['user']['race'] == $race) {
                $damage = $damagestart - $session['user']['hitpoints'] / $session['user']['maxhitpoints'] * 100;
                if ($damage > 0) {
                    debug("Midget Rage increment: " . $damage);
                    increment_module_pref("midgetrage", $damage);
                }
            }
            break;
        case "fightnav-specialties":
            if ($session['user']['race'] == $race) {
                addnav("Midget Rage");
                $rage = round(get_module_pref("midgetrage"), 2);
                if ($rage > 100) {
                    $script = $args['script'];
                    addnav("Invoke Midget Rage!", $script . "op=fight&skill=midgetrage");
                } else {
                    $notrage = 100 - $rage;
                    addnav("{$rage}%<br /><table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$rage}' bgcolor='#ffff00'></td><td width='{$notrage}'></td></tr></table>", "", true);
                }
            }
            break;
        case "apply-specialties":
            if ($session['user']['race'] == $race) {
                $skill = httpget('skill');
                if ($skill == "midgetrage") {
                    apply_buff("midgetrage", array("startmsg" => "`4Bug-eyed, screaming and foaming at the mouth like a Daily Mail columnist talking about Political Correctness Gone Mad, you fly into a terrifying Midget Rage!", "name" => "`^Midget Rage`0", "rounds" => 5, "atkmod" => 2, "wearoff" => "`4You feel yourself coming down from your Midget Rage.`0", "schema" => "module-racemidget"));
                    set_module_pref("midgetrage", 0);
                }
            }
            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":
            racemidget_checkcity();
            if ($session['user']['location'] == $city) {
                $args['text'] = array("`0You are standing in the heart of Squat Hole.  Man, this place has gone downhill.`n`nRusted-out cars compete for space with empty cider cans, and there's a general atmosphere of meanness about.  Piles of dead skunks and excrement lie steaming and glistening by the side of the road.  All the windows are broken, and the whole place could do with a good scrubbing, but there's no chance for investment around here - there is truth in the rumour that copper wire was invented by two Midgets fighting over a penny.`n`n");
                $args['schemas']['text'] = "module-racemidget";
                $args['clock'] = "`0From the strength of the overpowering odour, you reason that it is approximately `&%s`0.`n`n";
                $args['schemas']['clock'] = "module-racemidget";
                if (is_module_active("calendar")) {
                    $args['calendar'] = "`0Written in blood on a nearby wall is `&%s`0, `&%s %s %s`0.`n`n";
                    $args['schemas']['calendar'] = "module-racemidget";
                }
                $args['title'] = array("%s, Home of the Midgets", $city);
                $args['schemas']['title'] = "module-racemidget";
                $args['sayline'] = "says";
                $args['schemas']['sayline'] = "module-racemidget";
                $args['talk'] = "`0Nearby some midgets stand around smoking hand-rolled cigarettes, using a decomposing chicken carcass as an ashtray.  Occasionally they shout at each other in irritating, squeaky voices:`n`n";
                $args['schemas']['talk'] = "module-racemidget";
                $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 just how ghastly everything is.";
                } else {
                    $args['newest'] = "`n`0Wandering the village, gawping at the state of disarray and looking as though someone had just dumped a boxfull of dead rats on their kitchen table is `&%s`0.";
                }
                $args['schemas']['newest'] = "module-racemidget";
                $args['section'] = "village-{$race}";
                $args['stablename'] = "Mike's Chop Shop";
                $args['schemas']['stablename'] = "module-racemidget";
                $args['gatenav'] = "Manky, Rusted Gates";
                $args['fightnav'] = "Brawlin' Street, like";
                $args['marketnav'] = "Shopliftin' Avenue, innit";
                $args['tavernnav'] = "All That Other S***e Road, ya dick'head";
                $args['schemas']['gatenav'] = "module-racemidget";
                unblocknav("stables.php");
            }
            break;
        case "stabletext":
            if ($session['user']['location'] != $city) {
                break;
            }
            $args['title'] = "Mike's Chop Shop";
            $args['schemas']['title'] = "module-racemidget";
            $args['desc'] = array("`6Just next door to the Clan Halls, a scruffy-looking warehouse has been erected.  The stench from the general area is indescribable - even worse than the pervasive funk that hangs over Squat Hole in general.  You hold your nose, and head inside.`n`n", array("As you venture further into the building, Mike scowls at you.  \"`^Wha' the f**k do `iyou`i want, %s?`6\" he asks in an irritating, squeaky voice.", translate_inline($session['user']['sex'] ? 'bitch' : 'dick\'ead', 'stables')));
            $args['schemas']['desc'] = "module-racemidget";
            $args['lad'] = "friend";
            $args['schemas']['lad'] = "module-racemidget";
            $args['lass'] = "friend";
            $args['schemas']['lass'] = "module-racemidget";
            $args['nosuchbeast'] = "`6\"`^Y'wot?  Wha' tha f**k's tha'?`6\" Mike says apologetically.";
            $args['schemas']['nosuchbeast'] = "module-racemidget";
            $args['toolittle'] = "`6Mike looks over the handful of currency you offered.  \"`^Yer fookin' numpty.  I said, fer this 'ere %s, yer lookin' at `&%s `^Req  and `%%s`^ fags.  Nah f**k off an' come back when ye've got it.`6\"";
            $args['schemas']['toolittle'] = "module-racemidget";
            $args['replacemount'] = "`6You sadly watch Mike lead your %s`6 away, along with your cigarettes.  However, when he returns, he brings with him a nice new `&%s`6 which makes you feel a little better.";
            $args['schemas']['replacemount'] = "module-racemidget";
            $args['newmount'] = "`6You hand over your currency, being careful not to touch the midget.  Within moments, you become the proud recipient of a lovely new `&%s`6!";
            $args['schemas']['newmount'] = "module-racemidget";
            $args['confirmsale'] = "`n`n`6Mike eyes your mount up and down, checking it over carefully.  \"`^Yeah, it's no' bad.  I guess.  Yer sure ye wanna flog it?`6\"";
            $args['schemas']['confirmsale'] = "module-racemidget";
            $args['mountsold'] = "`6With but a single tear, you hand your %s`6 over to Mike.  The tear dries quickly, and the %s in hand helps you quickly overcome your sorrow.";
            $args['schemas']['mountsold'] = "module-racemidget";
            $args['offer'] = "`n`n`6Mike offers you `&%s`6 Requisition and `%%s`6 Cigarettes for %s`6.";
            $args['schemas']['offer'] = "module-racemidget";
            break;
        case "stablelocs":
            tlschema("mounts");
            $args[$city] = sprintf_translate("The Village of %s", $city);
            tlschema();
            break;
    }
    return $args;
}
function insultschool_run()
{
    global $session;
    page_header("Cuthbert's Academy of Lingual Defence");
    switch (httpget('op')) {
        case "start":
            if (!get_module_pref("able", "insults")) {
                //this is the player's first trip to the Insults Academy
                //ronsengi
                output("\"`qAh.  Not seen you here before.`0\"`n`nA three-eyed, broad-mouthed Mutant sits behind a desk, wearing a loose-fitting black garment reminiscent of a kimono.  \"`qMy name's Cuthbert, and this is my Academy of Lingual Defence.`0\"`n`n\"`#Lingual Defence?`0\" you ask.`n`n\"`qLingual Defence,`0\" replies Cuthbert proudly.  \"`qA perfect supplement to your preferred martial art, perfected over twenty years by my good self.`0\"`n`n\"`#I see.`0\"  You look around the room.  \"`#I don't see any weaponry?`0\"`n`n\"`qNot `iphysical`i weaponry, no.  The art of Lingual Defence, or Ronsen-Kiai, doesn't require any equipment except for every now and then in training.`0\"  He grins.  \"`qThat's not a `iprecise`i translation, by the way, but I find throwing a bit of Japanese in there helps with the marketing.`0\"`n`nYou nod, looking around at the empty room and the rather sparse student list hanging on one wall.  You decide to indulge the guy - it seems he could use the business.  \"`#Can you show me a bit of this Ronsen-Kiai?`0\"`n`nCuthbert shows you an excited grin.  \"`qAbsolutely!  Here, take this.`0\"  He reaches below his desk and hands you a heavy wooden axe handle, before moving to the center of the room.  \"`qNow come and attack me with that.`0\"  He grins.  \"`qDon't be shy, now.  I'll tell you when to stop.`0\"`n`nYou shrug, heft the axe handle, and rush towards him, bringing your weapon down in a crushing arc onto his head, which isn't there.  The Mutant has stepped to the inside, and now stands close enough for you to feel his breath.`n`n\"`qFUCKWIT!`0\" roars the Mutant as you swing the axe handle towards his sides.  \"`qI've seen `iMOLD`i-`0\" the tip of the axe handle sails harmlessly past his stomach - \"`q...swing an axe handle better than that!  Holy shit you're slow!`0\"  The Mutant takes a step back and another breath, and you flick the axe handle around so that you can charge him with the tip.  \"`qAnd FAT!  Jesus Christ, your arse looks like two Volkswagens parked side-by-side!`0\" the Mutant steps back and away from your axe handle, then takes a very rapid step first towards and then past you, your axe handle chasing but not quite catching his thighs.  You switch into opposite stance, to see the Mutant giving you the finger.  \"`qAnd stupid!  Damn, you're denser than that axe handle!`0\"  Man, that's distracting.  You piston your leading leg upwards, hoping to catch the Mutant in the chest.  The Mutant catches your foot and sniffs.  \"`qAnd the stench of your feet could kill a concrete elephant at twenty paces!`0\"  Enraged, you slam your leading leg downwards while pouncing from your back leg, using the Mutant's arms like a set of stairs so that you can kick his stupid mean face like a football.`n`nYou land poorly.`n`nThe Mutant stands over you.  \"`qYou imbecilic, mewling, malodorous pervert.  You feeble-minded, cloth-eared, illigitimate buffoon.  You twisted, disgusting, Thatcher-licking dullard.  Your father f***s sheep and your mother says \"Baaa.\"  You're a disgrace.  An obscenity.  An embarrassment.\"`n`n\"`#Stop!`0\" you cry.  \"`#Why're you saying these things?`0\"`n`nThe Mutant leans down and helps you to your feet.  \"`qBecause they distract you,`0\" he says kindly.  \"`qThey get you so riled up that you try silly maneouvers like the one that just ended with you winded on the floor.  And even though I can tell that you're a better fighter than me, and would have stoved my head in under different circumstances, I was still able to get away with not being hit because a part of you was paying attention to what I was saying.`0\"`n`nYou blink.  \"`#`iThat's`i Ronsen-Kai?  Spouting a load of insults while fighting?`0\"`n`nThe Mutant nods, smiling.  \"`qTwenty cigarettes for your first lesson.  You'll learn the two starter techniques, Coarse and Confusing.  Then when you can prove to me that you're ready, I'll teach you the third technique - Classy, or as some call it, \"Shakespearean.\"  So.  Are you interested in learning how to fight with your tongue as well as your fists and feet?`0\"`n`nWell?  `iAre`i you?");
                addnav("Learn a new combat technique for 20 cigarettes?");
                if ($session['user']['gems'] >= 20) {
                    addnav("Hell yes!", "runmodule.php?module=insultschool&op=learnbasic");
                } else {
                    addnav("No, because you don't have 20 cigarettes.", "village.php");
                }
            } else {
                //lessons
                require_once "modules/staminasystem/lib/lib.php";
                $amber = get_stamina();
                if ($amber == 100) {
                    output("Cuthbert greets you with a firm handshake.  \"`qHello again!  Back for some more training, eh?  Well, you've completed the basic course, so I can give you refresher lessons at 25 Requisition each.`0\"`n`n");
                    $coarse = get_player_action("Insults - Coarse");
                    $confusing = get_player_action("Insults - Confusing");
                    $level = $coarse['lvl'] + $confusing['lvl'];
                    if ($level > 20) {
                        if (!get_module_pref("ableclassy", "insults")) {
                            output("Cuthbert pauses for a moment and looks you up and down.  \"`qYou know,`0\" he says, \"`qI think you might be ready to learn some Classy insults.  It'll be another 20 cigarettes for the basic Classy course, if you're interested.`0\"`n`n");
                            addnav("Train with Cuthbert");
                            if ($session['user']['gems'] >= 20) {
                                addnav("Pay 20 Cigarettes to learn the Classy Insults action", "runmodule.php?module=insultschool&op=learnclassy");
                            }
                        }
                    }
                    output("`JCuthbert, like other teachers in Improbable Island, can help you level up some of your skills.  When you pay to train with Cuthbert, you'll use as much Stamina in performing your chosen actions as normal, but you'll receive two and a half times the experience.  Higher levels in any given Stamina action will make that action cost fewer Stamina points.  Higher levels in Insults skills will also improve your chances of casting successful Insults, and reduce the chances of fumbling.`n`n`0Will you train with Cuthbert?`n`n");
                    addnav("Train with Cuthbert");
                    if ($session['user']['gold'] >= 25) {
                        $coarsecost = stamina_getdisplaycost("Insults - Coarse");
                        addnav(array("Pay 25 Req for a lesson in Coarse Insults (`Q%s%%`0)", $coarsecost), "runmodule.php?module=insultschool&op=train&train=coarse");
                        $confusingcost = stamina_getdisplaycost("Insults - Confusing");
                        addnav(array("Pay 25 Req for a lesson in Confusing Insults (`Q%s%%`0)", $confusingcost), "runmodule.php?module=insultschool&op=train&train=confusing");
                        if (get_module_pref("ableclassy", "insults")) {
                            $classycost = stamina_getdisplaycost("Insults - Classy");
                            addnav(array("Pay 25 Req for a lesson in Classy Insults (`Q%s%%`0)", $classycost), "runmodule.php?module=insultschool&op=train&train=classy");
                        }
                    } else {
                        addnav("You don't have enough Requisition to improve your existing Insults skills.", "");
                    }
                } else {
                    output("Cuthbert greets you with a firm handshake.  He grins.  \"`qI know what you're thinking - you want more lessons, huh?  Well, you look half-asleep to me.  This isn't something you should try without a good night's rest.  Come see me tomorrow.`0\"");
                }
            }
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
        case "train":
            $session['user']['gold'] -= 25;
            if (is_module_active("medals")) {
                require_once "modules/medals.php";
                medals_award_medal("cuthbert_train", "Cuthbert's Academy of Lingual Defence", "This player took lessons at Cuthbert's Academy of Lingual Defence!", "medal_cuthbert.png");
            }
            require_once "modules/staminasystem/lib/lib.php";
            switch (httpget('train')) {
                case "coarse":
                    apply_stamina_buff('traincoarse', array("name" => "Cuthbert's Training", "action" => "Insults - Coarse", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    require_once "modules/insults.php";
                    $i1 = insults_coarse();
                    $i2 = insults_coarse();
                    $i3 = insults_coarse();
                    $i4 = insults_coarse();
                    $i5 = insults_coarse();
                    output("Cuthbert shows you a big smile.  \"`qIt's good to train with you again.  Coarse insults it is.  Let's get started!`0\"`n`nOutside the hut, for the next half an hour or so, people stop to listen to the bizzarre and filthy profanities spouted from within.`n`n");
                    output("`i\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`qVery good!`0\"", $i1, $i2, $i3, $i4, $i5);
                    $return = process_action("Insults - Coarse");
                    output("You receive %s experience in Coarse Insults.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Coarse Insults!  You are now level %s!  This action will cost fewer Stamina points now, and you have a higher chance of casting a successful Insult!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
                case "confusing":
                    apply_stamina_buff('trainconfusing', array("name" => "Cuthbert's Training", "action" => "Insults - Confusing", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    require_once "modules/insults.php";
                    $i1 = insults_confusing();
                    $i2 = insults_confusing();
                    $i3 = insults_confusing();
                    $i4 = insults_confusing();
                    $i5 = insults_confusing();
                    output("Cuthbert shows you a big smile.  \"`qIt's good to train with you again.  Confusing insults it is.  Let's get started!`0\"`n`nOutside the hut, for the next half an hour or so, people stop to listen to the bizzarre and surreal propositions spouted from within.`n`n");
                    output("`i\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`qVery good!`0\"", $i1, $i2, $i3, $i4, $i5);
                    $return = process_action("Insults - Confusing");
                    output("You receive %s experience in Confusing Insults.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Confusing Insults!  You are now level %s!  This action will cost fewer Stamina points now, and you have a higher chance of casting a successful Insult!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
                case "classy":
                    apply_stamina_buff('trainclassy', array("name" => "Cuthbert's Training", "action" => "Insults - Classy", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    require_once "modules/insults.php";
                    $i1 = insults_classy();
                    $i2 = insults_classy();
                    $i3 = insults_classy();
                    $i4 = insults_classy();
                    $i5 = insults_classy();
                    output("Cuthbert shows you a big smile.  \"`qIt's good to train with you again.  Classy insults it is.  Let's get started!`0\"`n`nOutside the hut, for the next half an hour or so, people stop to listen to the witty and scathing insults spouted from within.`n`n");
                    output("`i\"`#You %s!`0\"`n`n\"`qI retort that you are a %s!`0\"`n`n\"`#I've never seen such a %s!`0\"`n`n\"`qIt is a matter of public record that you are a %s!`0\"`n`n\"`#And proud of it!  You sir, on the other hand, are a %s!`0\"`n`n\"`qVery good!`0\"`n`n`i", $i1, $i2, $i3, $i4, $i5);
                    $return = process_action("Insults - Classy");
                    output("You receive %s experience in Classy Insults.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Classy Insults!  You are now level %s!  This action will cost fewer Stamina points now, and you have a higher chance of casting a successful Insult!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
            }
            $amber = get_stamina();
            if ($amber == 100) {
                addnav("More Training");
                if ($session['user']['gold'] >= 25) {
                    $coarsecost = stamina_getdisplaycost("Insults - Coarse");
                    addnav(array("Pay 25 Req for a lesson in Coarse Insults (`Q%s%%`0)", $coarsecost), "runmodule.php?module=insultschool&op=train&train=coarse");
                    $confusingcost = stamina_getdisplaycost("Insults - Confusing");
                    addnav(array("Pay 25 Req for a lesson in Confusing Insults (`Q%s%%`0)", $confusingcost), "runmodule.php?module=insultschool&op=train&train=confusing");
                    if (get_module_pref("ableclassy", "insults")) {
                        $classycost = stamina_getdisplaycost("Insults - Classy");
                        addnav(array("Pay 25 Req for a lesson in Classy Insults (`Q%s%%`0)", $classycost), "runmodule.php?module=insultschool&op=train&train=classy");
                    }
                } else {
                    addnav("You don't have enough Requisition to improve your existing Insults skills.", "");
                }
            } else {
                output("Cuthbert shows you a grin.  \"`qWell, that was a lot of fun.  But I can see you're getting tired - no point in training any more today, I'm afraid.`0\"");
            }
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
        case "learnbasic":
            $session['user']['gems'] -= 20;
            output("\"`qExcellent!  Let's get started.  There are three classes of Insults - Coarse, Confusing, and Classy.  Coarse insults are the most vulgar sort, Confusing tend to be surreal and off-putting, and Classy insults are more formal and refined.  Each type has different effects upon the foe, and different difficulties.  Obviously, you'll get better at each one with time - I'm only going to teach you the Coarse and Confusing types today, and you can come back to learn the Classy insults when I think you're ready.`0\"`n`n\"`qCoarse insults are quite predictable.  They usually have only minor effects upon the enemy, but if they backfire the damage won't be too great either.  Obviously, once in a while you'll either land a critical insult or suffer a catastrophic fumble, but for the most part you'll find this happens more rarely with Coarse insults.`0\"`n`n\"`qConfusing insults are a little more erratic - your chances of fumbling or scoring a critical emotional hit are increased when compared with Coarse insults.  Similarly, the effects are slightly more potent.`0\"`n`n\"`qClassy insults go even further than Confusing insults, with potentially devastating effects - but, of course, those effects can backfire and just as easily throw `iyou`i off-kilter.`0\"`n`n\"`qRemember, a poorly-cast insult can backfire against you, so use these techniques carefully.`0\"`n`n\"`qWhen you first start using Ronsen-Kiai, you'll probably end up doing yourself about as much harm as good.  But don't be discouraged - as you gain more experience in each Insult type, you'll get the hang of it.  Now let's get started.`0\"`n`nFor the next few hours, passers-by are shocked by the profanities, obscene suggestions, bizarre propositions and scathing retorts emanating from the Academy.  By the time Cuthbert shakes your hand and sends you out into the world, you're sweating, red-faced and sore-throated - but you feel a sense of true accomplishment.`n`n`c`bYou have gained two new skills!`b`nYou are now qualified to cast Coarse and Confusing Insults against your foes!`c");
            set_module_pref("able", 1, "insults");
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
        case "learnclassy":
            $session['user']['gems'] -= 20;
            output("\"`qExcellent!  Let's get started.  Remember, Classy insults are more unpredictable than others, but their effects are greater, so use them carefully.`0\"For the next few hours, passers-by are shocked by the bizarre, Shakespearean language emanating from the Academy.  By the time Cuthbert shakes your hand and sends you out into the world, you're sweating, red-faced and sore-throated - but you feel a sense of true accomplishment.`n`n`c`bYou have gained a new skill!`b`nYou are now qualified to cast Classy Insults against your foes!`c");
            set_module_pref("ableclassy", 1, "insults");
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
    }
    page_footer();
    return true;
}