function cakeordeath_run()
{
    global $session;
    page_header("Cake Or Death");
    switch (httpget("op")) {
        case "examine":
            // Tell the player what the deal with Cake Or Death is
            $counter = number_format(get_module_setting("counter"));
            output("`0A shiny wooden table sits back from the main street.  Behind it, a man sits idly reading the Improbable Island Enquirer.  Before him, sat on the table, is a large sponge cake.  Above him is a banner, displaying the name of his game:`b'`5Cake`0 or `4Death!`0'`b`n`nHe sees you pondering the sign, and calls over to you.  `b'`5Cake`0 or `4Death!`0  `b`5Cake`0 or `4Death!`0' he cries.  'Ninety-nine per cent chance of `b`5Cake`0`b!'`n`nIt's not often that an immaculately-dressed gentleman with glowing green eyes offers you a 99% chance of cake.  What would you like to do?");
            //add navs
            addnav("CAKE!", "runmodule.php?module=cakeordeath&op=play");
            addnav("Back away slowly", "village.php");
            break;
        case "play":
            $counter = get_module_setting("counter");
            addnav("Back to the Outpost", "village.php");
            if ($counter > 0) {
                output("The green-eyed gentleman hands you a slice of cake, on a paper plate.  You thank him, and walk away merrily wolfing down your prize.`n`nYou feel `5Full Of Cake!`0");
                set_module_setting("counter", get_module_setting("counter") - 1);
                apply_buff('tastycake', array("name" => "`5Full Of Cake`0", "rounds" => 10, "atkmod" => 1.1, "defmod" => 1.1, "roundmsg" => "`5The cake you ate earlier has boosted your energy!`n", "schema" => "module-cakeordeath"));
            }
            if ($counter <= 0) {
                output("The green-eyed gentleman hands you a slice of cake, on a paper plate.  You thank him, and walk away merrily wolfing down your prize.`n`nYou feel `5Full Of Cake!`0`n`nMoments later, the slow-acting poison starts to take effect.  The world begins to melt in front of you.  Grey spots dance on the edges of your vision.  Behind you, a green-eyed monster offers you another slice of cake, laughing and pointing.`n`nYou curse your luck as the hallucinations begin to kick in.");
                set_module_setting("counter", 100);
                apply_buff('failcake', array("name" => "`5Full Of FailCake`0", "rounds" => -1, "regen" => -10, "startmsg" => "`5You are walking on pink icing.  The sky is made of jam.  Your eyes are two cherries.  That cake was awesome.`0`n", "roundmsg" => "`5The poisoned cake saps your strength, and you lose ten hitpoints!`0`n", "schema" => "module-cakeordeath"));
                if (is_module_active("medals")) {
                    require_once "modules/medals.php";
                    medals_award_medal("failcake", "Failcake Fancier", "This player was unfortunate at the Cake or Death stand...", "medal_failcake.png");
                }
            }
            break;
    }
    page_footer();
}
function emilybundle_run()
{
    global $session;
    $op = httpget("op");
    page_header("The Emily Bundle");
    $cost = get_module_setting("cost");
    $stock = get_module_setting("stock");
    $playerpoints = $session['user']['donation'] - $session['user']['donationspent'];
    switch ($op) {
        case "start":
            output("So, Improbable Island has been going for a couple of years now and it's turning into something that can keep me alive and with a roof over my head without me having to do website design.  It's turned from a hobby into a full-time job.`n`nSince then, I've gotten married, and my wife, Emily(*), has gotten increasingly frustrated with her job.  She does database work for a hospital; the pay's good, but the hours and the work itself is pretty depressing.`n`nI've noticed lately that my original goal - \"Hey, I'll write a text adventure game!\" - hasn't quite worked out the way I wanted it to, because I thought it'd be about writing.  I figured I'd have a plot, decent characters, a beginning, middle and end - you know, a story.  But lately I've been doing a lot more building of games and systems than I have building of worlds, and I'm beginning to realise that that's what I'm good at.`n`nThe Island needs a writer.`n`nA dedicated writer, so that I can be a dedicated coder.  Recently I've done all sorts of stuff with Titans, Onslaught, new Commentary, Dwellings, and all that jazz - but the last actual piece of world-building writing that I did was in Common Ground, with its time-sensitive description text.  I believe that was before Christmas.`n`nOh, and there were some lions, too.`n`nTo give you an idea of where I am right now, let's say this: the system is in place to extend that level of time-and-context-sensitive detail to every Outpost.  I just don't have any writing to go in the system.`n`nIt's not that I don't like writing, and forgive me for parping my own horn but I don't think it's that I'm not good at it (although that sentence may have been evidence to the contrary).  It's just that I have so much else to do.`n`nI need help.`n`nHey, you know... my wife is an excellent writer.`n`nHonestly I'd be doing this before too long even if I didn't need Emily to help me with the Island.  She hates her job, I love mine, and that's unfair; it's imperative that the Island support both of us if we ever want to have our own house, or raise a family.`n`nWe've done our maths and figured out how much we need per month on which to survive without Emily's workplace sorting out our health insurance (that's the biggest expense, right there), and from that, based on historical data, we've figured out how much of an advertisement boost we'd need to get the Island up to that sort of level, and from that, how much money we'd need to get together by 'x' if we want Emily to be able to quit her job by 'y', with 'y' being \"Before September.\"`n`nIn a nutshell we need to get some bread together so that we can expand our player base enough that casual everyday donations cover us both without me having to tell you all about it every time my laptop breaks, my car breaks down, or my lion gets into an argument he just can't win.`n`nSo, you can give me money so that the Island can have more juicy plot points and a better sense of place, or you can give me money so that Emily and I can be happier and spend more time together.  Both are excellent reasons.  I've got another reason for you:`n`nIntroducing the `5Emily Bundle`0!`n`nThe `5Emily Bundle`0 costs 2,500 Donator Points, and it's worth well over three times as much.  In the Emily Bundle for 2,500 Donator Points (that's twenty-five bucks, for those of you keeping track), you get:`n`n* Permanent, unlimited free Avatar picture changes (never pay to change your Avatar picture again!)`n* Permanent, unlimited free Custom Weapon changes (custom weaponry now sticks around properly!)`n* Permanent, unlimited free Custom Armour changes (likewise!)`n* Permanent, unlimited free Custom Name Colour changes`n* Permanent, inlimited free Title changes`n* Permanent, unlimited free Mount Name changes`n* Permanent, unlimited free Commentary Race Name changes`n* Ten cigarettes`n* Ten thousand Requisition tokens`n* Two extra Chronospheres`n* All your current Chronospheres refilled`n* Ten Special Comments`n* A special, strictly-limited-and-not-to-be-repeated Medal`n`nAnd if you've not already donated, you'll also get room for a ten-thousand character Extended Bio (players who've already donated already have this).`n`nNow, the Emily Bundle is limited to two hundred players.  That should give Emily and I enough of a financial boost to get this plan underway.  If something stupidly awesome happens like the whole stock running out in a day, then I might add another fifty or a hundred or so, but no more than that (I'm not going to say it's strictly limited just to stimulate demand and then make it as common as muck - I want this to be a bit special).`n`nSo, help us recruit a writer and make the Island more awesome, more quickly - grab the Emily Bundle while it's still around to grab!`n(*) Yes, I named the pickle-wench barmaid after my wife.  Looking back, I could have made a better choice for an homage.");
            addnav("Buy the Emily Bundle!");
            if ($playerpoints >= $cost) {
                addnav("Yes! (2,500 points)", "runmodule.php?module=emilybundle&op=buy");
            } else {
                addnav(array("Just %s more points!", $cost - $playerpoints), "");
            }
            break;
        case "buy":
            set_module_pref("permanent", true, "commentaryicons_customrace");
            set_module_pref("permanent", true, "titlechange");
            set_module_pref("permanent", true, "namedmount");
            set_module_pref("permanent", true, "namecolor");
            set_module_pref("permanent", true, "avatar");
            set_module_pref("permanentarmor", true, "customeq");
            set_module_pref("permanentweapon", true, "customeq");
            $session['user']['gems'] += 10;
            $session['user']['goldinbank'] += 10000;
            $curspheres = get_module_pref("slots", "daysave");
            set_module_pref("slots", $curspheres + 2, "daysave");
            set_module_pref("days", $curspheres + 2, "daysave");
            increment_module_pref("commentsleft", 10, "specialcomments");
            require_once "modules/medals.php";
            medals_award_medal("emilybundle", "Emily Bundle Supporter", "This player bought the Emily Bundle, supporting Improbable Island and its admin!", "medal_emilybundle.png");
            $session['user']['donationspent'] += $cost;
            increment_module_setting("stock", -1);
            set_module_pref("bought", 1);
            output("You've got the Emily Bundle!  Thank you so much for supporting the Island.  Have fun!`n`n");
            //todo: medal, take points, diminish stock, output thankyou
            break;
    }
    addnav("Return");
    addnav("L?Return to the Lodge", "lodge.php");
    page_footer();
}
function strategyhut_run()
{
    global $session;
    $cost = get_module_setting("cost");
    $op = httpget("op");
    page_header("The Strategy Hut");
    output("`5`c`bThe Strategy Hut`b`c");
    if ($op == "") {
        addnav(array("Ask for Advice (`^%s gold`0)", $cost), "runmodule.php?module=strategyhut&op=ask");
        output("`&You enter the hut, to find `6Atrus `&busy at his desk.");
        output("\"`^Well, a young warrior in search of help!");
        output("For a small fee, I will offer advice to you.`3\"`n`n");
        output("`&Hesitantly, you approach the burly warrior.`n`n");
        output("`&You blink a few times before you realize he was actually talking to you.");
        output("`6Atrus `&doesn't seem very patient, so you'd better decide quickly if you want to hear his advice!`n");
    } elseif ($session['user']['gold'] < $cost) {
        output("`&You go through your pockets, searching for money, but you don't have enough.");
        output("After a moment of intense searching, `6Atrus `&starts to scowl, and you decide to leave before he gets annoyed.`n`n");
    } else {
        $session['user']['gold'] -= $cost;
        debuglog("spent {$cost} gold at the strategy hut");
        output("`&You give `6Atrus `^%s gold`7.", $cost);
        output("`&He nods, and thinks for a moment.`n`n");
        $phrases = array("\"`^Heal often, bank often.`3\"", "\"`^Think balance: weapons and armor must be close in level, not enough defense and your first attack will be your last.`3\"", "\"`^Don't be afraid to slum, in the lower DK levels, speed is NOT a priority. Later is different.`3\"", "\"`^That stat bar is your life, when it gets into the yellow zone, heal. When it goes red, pray.`3\"", "\"`^In PvP, pick your targets with care. If not sure, DON'T... or you'll be explaining to {deathoverlord}`^ what happened.`3\"", "\"`^You don't always need to resurrect. There will be times to save favor for emergencies.`3\"", "\"`^If it's a game bug, petition it. If it's a gameplay issue, petition it.`3\"", "\"`^A good offense is not always a good defense, even the strongest players die in the forest.`3\"", "\"`^Confidence is one thing: attacking a God is suicide. Check the bio first.`3\"", "\"`^Keep an open mind and think it through. Only a fool fights blindly.`3\"", "\"`^There is a dragon, and when you are ready, it will be too. Patience.`3\"", "\"`^Travelling between towns can be dangerous. Heal first.`3\"", "\"`^Talk to everyone in all the villages, visit the shops and stalls. Explore. Learn.`3\"", "\"`^Lower DK players die often in the beginning. It happens to all of us.`3\"", "\"`^When you face the dragon, be ready and fully healed... or it will eat you for lunch.`3\"", "\"`^Your mount or familiar is an asset... learn what it can do, and know its limits. *And* yours, as well.`3\"", "\"`^There is no shame in knowing when to run. Better a bruised ego than a visit to {deathoverlord}`^.`3\"", "\"`^Log in ONCE per game day only, or you will be killed repeatedly... and lose experience as a result. There is no safe place.`3\"", "\"`^If you can't resurrect, log off and wait for New Day. You are already dead.`3\"", "\"`^A good player treats his fellows with courtesy and respect. A wise player knows that new friends can help him succeed.`3\"", "\"`^Don't forget to feed your mount or familiar.`3\"");
        $question = e_rand(0, count($phrases) - 1);
        $phrases = translate_inline($phrases);
        $myphrase = $phrases[$question];
        $myphrase = str_replace('{deathoverlord}', getsetting('deathoverlord', '`$Ramius'), $myphrase);
        output_notl("%s`n`n", $myphrase);
        output("`&You ponder his advice for a moment, before thanking him and making your exit.`n`n");
        if (is_module_active("medals")) {
            require_once "modules/medals.php";
            medals_award_medal("strategyhut", "Strategy Seeker", "This player asked for help in the Strategy Hut.", "medal_strategy.png");
        }
    }
    villagenav();
    page_footer();
}
function supplycrate_use($args)
{
    increment_module_pref("cratesopened", 1, "supplycrates");
    $found = get_module_pref("cratesopened", "supplycrates");
    if (is_module_active("medals")) {
        if ($found > 250) {
            require_once "modules/medals.php";
            medals_award_medal("crate1000", "Supreme Crate Finder", "This player has opened more than 250 Supply Crates!", "medal_crategold.png");
        }
        if ($found > 50) {
            require_once "modules/medals.php";
            medals_award_medal("crate500", "Expert Crate Finder", "This player has opened more than 50 Supply Crates!", "medal_cratesilver.png");
        }
        if ($found > 10) {
            require_once "modules/medals.php";
            medals_award_medal("crate100", "Supreme Crate Finder", "This player has opened more than 10 Supply Crates!", "medal_cratebronze.png");
        }
    }
    $crateables = get_items_with_settings("cratefind");
    $randompool = array();
    foreach ($crateables as $item => $prefs) {
        for ($i = 0; $i < $prefs['cratefind']; $i++) {
            $randompool[] = $item;
        }
    }
    output("You spend a few minutes prying open your Supply Crate.`n");
    $giveitems = array();
    $numitems = e_rand(get_module_setting("minitems", "supplycrates"), get_module_setting("maxitems", "supplycrates"));
    $chosenitems = array_rand($randompool, $numitems);
    foreach ($chosenitems as $key => $poolkey) {
        $item = $randompool[$poolkey];
        $name = $crateables[$item]['verbosename'];
        output("You find a %s!`n", $name);
        give_item($item);
    }
    return $args;
}
function timedcombat_teach_dohook($hookname, $args)
{
    global $session, $last_timestamp;
    switch ($hookname) {
        case "newday":
            set_module_pref("taughttoday", 0);
            break;
        case "biostat":
            if (httpget('op') == "teachtimedcombat") {
                set_module_pref("able", true, "timedcombat", $args['acctid']);
                debug(get_module_pref("able", "timedcombat", $args['acctid']));
                set_module_pref("taughttoday", 1);
                increment_module_pref("taught");
                output("`bYou have successfully taught this character how to do Timed Combat!`b`n");
                if (is_module_active("medals")) {
                    require_once "modules/medals.php";
                    medals_award_medal("timedcombat_teach", "Time Tutor", "This player taught another player how to do Timed Combat!", "medal_timeteacher.png");
                }
                require_once "lib/systemmail.php";
                $subj = $session['user']['name'] . " taught you a new skill!";
                $body = "You can now perform Timed Combat in fights!  If you time your fight commands correctly, you'll get a double-attack and double-defence bonus!  The bonus applies to everything you do in combat.  Try timing your five-round auto-fights - one correct hit wins you five rounds of extra power, and the same goes for ten-round auto-fighting too!  If you don't want to muck about with counting under your breath, you can ignore the new skill and carry on fighting as you've always done.  Get four perfect hits in a row and you can teach other players!  Have fun!";
                systemmail($args['acctid'], $subj, $body);
            }
            $ret = httpget('ret');
            if ($args['acctid'] != $session['user']['acctid'] && !get_module_pref("taughttoday") && get_module_pref("maxchain", "timedcombat") >= 4) {
                //get the players' chat locations from commentaryinfo.php - it's handy!
                $tloc = get_module_pref("loc", "commentaryinfo");
                $sloc = get_module_pref("loc", "commentaryinfo", $args['acctid']);
                if ($tloc == $sloc && !get_module_pref("able", "timedcombat", $args['acctid'])) {
                    output("This player doesn't know how to do Timed Combat.  You can teach one student per game day.`n`n");
                    addnav("Teach this player the Timed Combat skill", "bio.php?op=teachtimedcombat&char=" . $args['acctid'] . "&ret=" . urlencode($ret));
                }
            }
            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 kissingbooth_run()
{
    global $session;
    require_once "lib/villagenav.php";
    $gardens = get_module_setting("gardens");
    $smackloss = get_module_setting("smackloss");
    $cost = get_module_setting("cost");
    $totalcost = $cost * $session['user']['level'];
    page_header("The Kissing Booth");
    $op = httpget('op');
    $kissedtoday = get_module_pref("kissedtoday");
    $kissee = get_module_pref("kissee");
    output("`c`b`QThe `\$Kissing`Q Booth`0`b`c`n");
    if ($op == "") {
        while ($kissee == "") {
            $guys = array(getsetting("barkeep", '`tCedrik'), "`!Lonestrider", "`@JR`3Min`!ga", "`6Smiythe", getsetting("bard", "`^Seth"), "`&Oliver", "`#MightyE", "`%Kendaer");
            $girls = array("`)Heidi", "`7Petra", "`QSaucy`\$Wench", "`@Foil`&wench", getsetting('barmaid', "`%Violet"), "`^Ella");
            if ($session['user']['sex'] != SEX_MALE) {
                $kissee = $guys[e_rand(0, count($guys) - 1)];
            } else {
                $kissee = $girls[e_rand(0, count($girls) - 1)];
            }
            set_module_pref("kissee", $kissee);
        }
        // will change this if it's in a town (which town? romar? glorfy?
        // d'burg? rather than a special area (carnival, esoterron (ew!))
        output("`QYou walk towards the booth marked \"`@LOGD Kissing Booth`Q\".`n");
        output("`QThere seems to be a decent line, possibly because %s`Q is behind the booth today!`n", $kissee);
        if (!$kissedtoday) {
            output("`QYou find yourself shuffled into the line, which seems to suddenly be moving fairly quickly.`n");
            output("`QFinally, you reach the front!");
            output("`QYour eyes dart to the jar marked \"`@Donations`Q\", and then meet the gaze of %s`Q, who looks up at you expectantly.`n", $kissee);
            if ($totalcost > $session['user']['gold']) {
                output("`!You can't afford the donation at the moment.");
                output("%s`! smiles at you sadly as you slink off, dejected.", $kissee);
                if ($gardens) {
                    addnav("G?Return to the Gardens", "gardens.php");
                } else {
                    villagenav();
                }
            } else {
                output("`QWhat will you do?");
                addnav(array("Make donation (%s gold)", $totalcost), "runmodule.php?module=kissingbooth&op=stay");
                addnav("Chicken out", "runmodule.php?module=kissingbooth&op=flee");
            }
        } else {
            output("`Q`nYou know, that line seems really long, and you've already taken your turn today.`n");
            output("`QMaybe you should wait until later, and let somebody else have their fun.");
            if ($gardens) {
                addnav("G?Return to the Gardens", "gardens.php");
            } else {
                villagenav();
            }
        }
    } elseif ($op == "flee") {
        output("`#You freeze with embarrasment at the thought of kissing %s`#.`n", $kissee);
        output("`#After about a minute has passed and you're still standing there stammering, %s`# sighs and beckons the person behind you to come forward and take your place.`n", $kissee);
        output("`#A helper gently takes you aside and seats you under a nearby tree to recover.");
        if ($gardens) {
            addnav("Leave", "gardens.php");
        } else {
            addnav("Leave", "village.php");
        }
    } elseif ($op == "stay") {
        set_module_pref("kissedtoday", 1);
        $session['user']['gold'] -= $totalcost;
        if ($session['user']['sex'] != SEX_MALE) {
            $heshe = "he";
            $Cheshe = "He";
            // "capital he/she." capital idea, wot?
            $hisher = "his";
        } else {
            $heshe = "she";
            $Cheshe = "She";
            $hisher = "her";
        }
        $rnd = e_rand(1, 16);
        switch ($rnd) {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                //charm++ (1-5)
                output("`6You drop the coins in the jar.`n");
                output("%s`6 leans forward and kisses you gently on the lips.", $kissee);
                output("{$Cheshe} holds it slightly longer than you expected and pulls back with an impressed look on {$hisher} face.`n");
                output("\"`#Not bad`6\", {$heshe} says, \"come back anytime!\"`n");
                output("You blush slightly, but find a new confidence in your step as you walk away.`n");
                output("You feel `\$charming`6!");
                $session['user']['charm']++;
                break;
            case 6:
            case 7:
            case 8:
            case 9:
                //hp++ (6-9) (tee hee)
                output("`6Stepping forward, you deposit your coins in the jar.`n");
                output("%s`6 leans forward and kisses you softly but warmly.`n", $kissee);
                output("`6The warmth floods your body, and eases your pain.`n");
                output("%s`6 smiles and waves as you wander off.", $kissee);
                if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                    $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
                } else {
                    $session['user']['hitpoints'] = $session['user']['hitpoints'] * 1.1;
                }
                break;
            case 10:
            case 11:
            case 12:
                //ff++ (10-12)
                output("`6You place your donation in the jar.`n");
                output("%s`6's eyes light up as you approach, and {$heshe} kisses you with enthusiasm.`n", $kissee);
                output("`6You feel an energy spread throughout your entire body, making you `^tingle!`n`n");
                output("`6As you walk away, you feel a light tap on your bottom!`n");
                output("`6You turn around to see %s`6 winking at you! \"`#Go get 'em, tiger!`6\", {$heshe} says.`n", $kissee);
                output("`6The tingling fills you, and you feel enthusiastic about life in general!  You gain some Stamina`n");
                $session['user']['turns']++;
                if (is_module_active("medals")) {
                    require_once "modules/medals.php";
                    medals_award_medal("goodkiss", "Really Awesome Kiss", "This player received a totally awesome kiss at the Kissing Booth!", "medal_kissingbooth.png");
                }
                break;
            case 13:
            case 14:
                //charm-- (13-14)
                output("`6You eagerly place your donation in the jar and rush forward to kiss %s.`n", $kissee);
                output("`6However, in your enthusiasm, you fumble the kiss and end up bumping noses!`n");
                output("`6You look up and see nearby people trying to stifle giggles!`n");
                output("`6You wander off, feeling somewhat embarrassed.`n`n");
                output("`6However, looking down as you walk off, you spot something `#shiny`6 in the dust!`n");
                output("`QYou lose charm, but you gain a gem!`n");
                if ($session['user']['charm'] > 0) {
                    $session['user']['charm']--;
                }
                $session['user']['gems']++;
                debuglog("gained a gem at the kissing booth");
                break;
            case 15:
                //hp-- (15)
                output("`6You drop your coins in the jar and reach forward to kiss %s.`n", $kissee);
                output("`6\"`#Hey! Not so hard!`6\", {$heshe} yells, and smacks you across the face!`n");
                $loss = round($session['user']['maxhitpoints'] * ($smackloss / 100), 0);
                if ($loss >= $session['user']['hitpoints']) {
                    $loss = $session['user']['hitpoints'] - 1;
                }
                output("`QYou `\$lose %s `Q hitpoints!`n", $loss);
                $session['user']['hitpoints'] -= $loss;
                if ($session['user']['hitpoints'] <= 0) {
                    $session['user']['hitpoints'] = 1;
                }
                break;
            case 16:
                //ff-- (16)
                output("`6As you walk forward and place your donation in the jar, your foot finds a banana peel thrown by an errant reveller.`n");
                output("`6You attempt to maintain your balance, but pitch forward and hit your head on one of the posts holding up the booth!`n");
                output("`6When you come to, %s`6 is cradling your head in {$hisher} lap.`n", $kissee);
                output("{$Cheshe} `6bends down and kisses you on the forehead, and sets you on your feet.`n");
                if ($session['user']['turns'] > 0) {
                    output("`QYou `\$lost`Q some Stamina!`n");
                    $session['user']['turns']--;
                }
                break;
        }
        if ($gardens) {
            addnav("G?Return to the Gardens", "gardens.php");
        } else {
            villagenav();
        }
    }
    page_footer();
}
function crazyaudrey_baskets($type)
{
    global $session;
    $from = "runmodule.php?module=crazyaudrey&";
    if ($type == "forest") {
        $from = "forest.php?";
    }
    if ($type == "forest") {
        $session['user']['specialinc'] = "module:crazyaudrey";
    }
    $animal = get_module_setting("animal");
    $lcanimal = get_module_setting("lanimal");
    $lcplural = get_module_setting("lanimals");
    $sound = get_module_setting("sound");
    $op = httpget('op');
    if ($op == "" || $op == "search" || $op == "baskets") {
        if ($op == "baskets") {
            output("`5You reach for the lid of one of Crazy Audrey's baskets when you think she is distracted, when out of nowhere, Crazy Audrey appears, ranting feverishly about colored %s, and pulls the baskets to her.`n`n", $lcplural);
        } elseif ($type == "forest") {
            output("`5You stumble across a clearing that is oddly quiet.");
            output("To one side are three baskets, tightly lidded.");
            output("Finding this curious, you cautiously approach them when you hear the faint %s`5 of a %s`5.", $sound, $lcanimal);
            output("You reach for the lid of the first basket when out of nowhere, Crazy Audrey appears, ranting feverishly about colored %s`5, and pulls the baskets to her.`n`n", $lcplural);
        }
        output("Taken somewhat aback, you decide you had best question her about these %s.`n`n", $lcplural);
        output("\"`#Tell me, good woman,`5\" you begin...`n`n");
        output("\"`%GOOD GOOD good good goodgoodgoodgoodgood...`5\" Audrey begins to repeat.");
        output("Unflustered, you persist.`n`n");
        output("\"`#What are these %s`# you speak of?`5\"`n`n", $lcplural);
        output("Amazingly, Crazy Audrey suddenly grows quiet and begins to speak in a regal accent both melodious and soft.`n`n");
        output("\"`%Of these baskets, have I three,`n");
        output("Four %s`% inside each there do be.`n`n", $lcplural);
        output("Minds of their own, do they have,`n");
        output("Should two alike emerge, you'll get this salve.`n`n");
        output("Energy it gives, to fight your foes,`n");
        output("Merely rub it 'tween your toes.`n`n");
        output("Should no two alike show their head,`n");
        output("Earlier today, you'll see your bed.`n`n");
        output("That then is my proposition,`n");
        output("Shall thou take it, or from me run?`5\"`n`n");
        output("Will you play her game?");
        addnav("Play", $from . "op=play");
        addnav("Run away from Crazy Audrey", $from . "op=run");
    } else {
        if ($op == "run") {
            output("`5You run, very quickly, away from this mad woman.");
        } else {
            if ($op == "play") {
                if ($type == "module-internal") {
                    set_module_pref("played", 1);
                }
                $colors = array("`^C`&a`Ql`6i`7c`qo", "`7T`&i`7g`&e`7r", "`QGinger", "`&White", "`^`bHedgehog!`b");
                $colors = translate_inline($colors);
                $c1 = e_rand(0, 3);
                $c2 = e_rand(0, 3);
                $c3 = e_rand(0, 3);
                if (e_rand(1, 20) == 1) {
                    $c1 = 4;
                    $c2 = 4;
                    $c3 = 4;
                }
                output("`5You agree to Crazy Audrey's preposterous game and she thumps the first basket on the lid.");
                if ($c1 == 4) {
                    output("A %s`5 peeks its head out.`n`n", $colors[$c1]);
                } else {
                    output("A %s`5 %s`5 peeks its head out.`n`n", $colors[$c1], $lcanimal);
                }
                if ($c2 == 4) {
                    output("Crazy Audrey then thumps the second basket on the lid, and a %s`5 peeks its head out.`n`n", $colors[$c2]);
                } else {
                    output("Crazy Audrey then thumps the second basket on the lid, and a %s`5 %s`5 peeks its head out.`n`n", $colors[$c2], $lcanimal);
                }
                if ($c3 == 4) {
                    output("She thumps the third basket on the lid, and a %s`5 hops out and bounds up to Crazy Audrey's shoulder.`n`n", $colors[$c3]);
                } else {
                    output("She thumps the third basket on the lid, and a %s`5 %s`5 hops out and bounds up to Crazy Audrey's shoulder.`n`n", $colors[$c3], $lcanimal);
                }
                if ($c1 == $c2 && $c2 == $c3) {
                    if ($c1 == 4) {
                        $where = translate_inline($type == "forest" ? "forest" : "crowd");
                        output("\"`%Hedgehogs?  HEDGEHOGS??  Hahahahaha, HEDGEHOGS!!!!`5\" shouts Crazy Audrey as she snatches them up in glee and runs cheering into the %s.", $where);
                        output("You notice that she has dropped a full BAG of those wonderful salves.`n`n");
                        output("`^You gain a whole LOAD of Stamina!");
                        $session['user']['turns'] += 5;
                        if (is_module_active("medals")) {
                            require_once "modules/medals.php";
                            medals_award_medal("audrey-hedgehogs", "Friend of the Hedgehogs", "This player was fortunate enough to find hedgehogs in Crazy Audrey's baskets!", "medal_audreyhedgie.png");
                        }
                    } else {
                        output("\"`%Argh, you are ALL very bad %s`%!`5\" shouts Crazy Audrey before hugging her shoulder %s`5 and putting it back in the basket.", $lcplural, $lcanimal);
                        output("\"`%Because my %s`% all were alike, I grant you TWO salves.`5\"`n`n", $lcplural);
                        output("You rub the salves on your toes.`n`n");
                        output("`^You gain LOTS of Stamina!");
                        $session['user']['turns'] += 2;
                        if (is_module_active("medals")) {
                            require_once "modules/medals.php";
                            medals_award_medal("audrey-kittens", "Pervy Kitten Fancier", "This player was fortunate enough to find five kittens of the same colour!", "medal_audreykitty.png");
                        }
                    }
                } elseif ($c1 == $c2 || $c2 == $c3 || $c1 == $c3) {
                    output("\"`%Garr, you crazy %s`%, what do you know?  Why I ought to paint you all different colors!`5\"", $lcplural);
                    output("Despite her threatening words, Crazy Audrey pets the %s`5 on her shoulder and places it back in the basket, before giving you your salve, which you rub all over your toes.`n`n", $lcanimal);
                    output("`^You gain some Stamina!");
                    $session['user']['turns']++;
                } else {
                    output("\"`%Well done my pretties!`5\" shouts Crazy Audrey.");
                    output("Just then her shoulder-mounted %s`5 leaps at you.", $lcanimal);
                    if ($session['user']['turns'] > 0) {
                        output("In fending it off, you lose some energy.");
                        $msg = "`^You lose some Stamina!";
                        $session['user']['turns']--;
                    } else {
                        output("In fending it off, you get a nasty scratch along one side of your face.");
                        $msg = "`^You lose a charm point!";
                        if ($session['user']['charm'] > 0) {
                            $session['user']['charm']--;
                        }
                    }
                    output("Finally it hops back in its basket and all is quiet.");
                    output("Crazy Audrey cackles quietly and looks at you.`n`n");
                    output($msg);
                }
            }
        }
    }
    if ($op == "run" || $op == "play") {
        if ($type == "forest") {
            $session['user']['specialinc'] = "";
        }
    }
}
function pinata_hit()
{
    global $session;
    $rand = e_rand(1, 9);
    switch ($rand) {
        case 1:
            output("`#You stumble as you take the swing and `&MISS!`n`n");
            output("`#You fall to the ground with a twisted ankle and lay looking up at the `@pinata `#as it continues to sway in the gentle breeze.`n`n");
            $curhp = $session['user']['hitpoints'];
            $newhp = round($session['user']['hitpoints'] * 0.1, 0);
            if ($newhp < 1) {
                $newhp = 1;
            }
            if ($session['user']['turns'] > 0 && $curhp > $newhp) {
                output("`&The pain in your twisted, swollen ankle causes you to lose some Stamina, and most of your hitpoints.");
            } elseif ($session['user']['turns'] > 0) {
                output("`&The pain in your twisted, swollen ankle causes you to lose some Stamina.");
            } elseif ($curhp > $newhp) {
                output("`&The pain in your twisted, swollen ankle causes you to lose most of your hitpoints.");
            } else {
                output("`&The pain in your twisted, swollen ankle quickly subsides, to your immense relief.");
            }
            if ($session['user']['turns'] > 0) {
                $session['user']['turns']--;
            }
            if ($curhp > $newhp) {
                $session['user']['hitpoints'] = $newhp;
            }
            break;
        case 2:
        case 3:
            output("`#The branch hits the `@pinata `#with a resounding thud.");
            output("There is an explosion of `@green `#paper as the `@pinata  `#disintegrates causing sweet candies to fall to the ground.");
            output("You quickly pick them up and pop some in your mouth.`n`n");
            output("You feel `&INVIGORATED!`0`n`n");
            output("`^Your hitpoints have been restored to full, and you gain some Stamina.");
            if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
            }
            $session['user']['turns']++;
            break;
        case 4:
            output("`#The branch hits the `@pinata `#with a resounding thud.");
            output("There is an explosion of `@green `#paper as the `@pinata  `#disintegrates causing sweet candies to fall to the ground.`n`n");
            output("You feel `&PERCEPTIVE!`0`n`n");
            output("You notice something glittering under some of the paper as you pick up the candy.`n`n");
            output("`^You find a `%GEM`^!");
            $session['user']['gems']++;
            debuglog("found 1 gem under the pinata");
            if (is_module_active("medals")) {
                require_once "modules/medals.php";
                medals_award_medal("pinatacigarette", "Pinata Punisher", "This player was fortunate enough to receive a cigarette from the Pinata!", "medal_pinata.png");
            }
            break;
        case 5:
            output("You stumble as you take the swing and MISS!`n`n");
            output("`#You fall to the ground and lay looking up at the `@pinata `#as it continues to sway in the gentle breeze.`n`n");
            output("`7In your tumble your gem pouch opens.`n`n");
            if ($session['user']['gems'] > 0) {
                $session['user']['gems']--;
                output("`^You lost a `%gem`^!");
                debuglog("lost 1 gem under the pinata");
            } else {
                output("`^Fortunately, you don't seem to have lost anything!");
            }
            break;
        case 6:
            output("You stumble as you take the swing and MISS!`n`n");
            output("`#You fall to the ground and lay looking up at the `@pinata `#as it continues to sway in the gentle breeze.`n`n");
            output("`^In your tumble your gold pouch opens.`n`n");
            $goldlost = round($session['user']['gold'] * 0.1, 0);
            if ($goldlost) {
                output("`^You lost %s `6gold`^.", $goldlost);
                $session['user']['gold'] -= $goldlost;
                debuglog("lost {$goldlost} gold under the pinata");
            } else {
                output("`^Fortunately, you don't seem to have lost anything!");
            }
            break;
        case 7:
            // If (is_module_active("cities")){
            // output("`#The branch hits the `@pinata `#with a resounding thud.");
            // output("There is an explosion of `@green `#paper as the `@pinata  `#disintegrates causing sweet candies to fall to the ground.`n`n");
            // output("You pick up a very large piece of candy and put it in your mouth.`n`n");
            // output("`#You feel `&BOLD!`0`n`n");
            // output("`^You receive an extra `&Travel `^today!`0`n`n");
            // set_module_pref("traveltoday",
            // get_module_pref("traveltoday","cities")-1,"cities");
            // break;
            // }
        // If (is_module_active("cities")){
        // output("`#The branch hits the `@pinata `#with a resounding thud.");
        // output("There is an explosion of `@green `#paper as the `@pinata  `#disintegrates causing sweet candies to fall to the ground.`n`n");
        // output("You pick up a very large piece of candy and put it in your mouth.`n`n");
        // output("`#You feel `&BOLD!`0`n`n");
        // output("`^You receive an extra `&Travel `^today!`0`n`n");
        // set_module_pref("traveltoday",
        // get_module_pref("traveltoday","cities")-1,"cities");
        // break;
        // }
        case 8:
        case 9:
            output("`#The branch hits the `@pinata `#with a resounding thud.");
            output("There is an explosion of `@green `#paper as the `@pinata  `#disintegrates causing sweet candies to fall to the ground.`n`n");
            output("You pick up a small piece of candy and put it in your mouth.`n`n");
            output("You feel `&ENERGETIC!`0`n`n");
            output("`^You gain some Stamina!");
            $session['user']['turns']++;
            break;
    }
    output("`0");
}
function riddles_runevent($type)
{
    require_once "lib/increment_specialty.php";
    global $session;
    // We assume this event only shows up in the forest currently.
    $from = "forest.php?";
    $session['user']['specialinc'] = "module:riddles";
    require_once "lib/partner.php";
    $partner = get_partner();
    $op = httpget('op');
    if ($op == "" || $op == "search") {
        output("You come across a tall man wearing an immaculate white Victorian suit, a top hat, and the sort of smile that you only ever see on tigers who want you to believe that they're kittens.  He leans on a handsome walking stick as he eyes you up and down.`n`n\"Good afternoon,\" says the gentleman.  \"Would you care to play a game with me?\"`n`nYou're pretty sure this guy is a Joker.  They like stuff like this.  And the glowing green eyes were a dead giveaway.`n`n\"What sort of game?\" you ask warily.`n`n\"Well,\" says the gentleman, smartly rapping his staff upon the floor and sauntering towards you, \"I've always been fond of riddles, you see.  Cryptic questions, as it were.  How about if I ask you a riddle, and if you get it right, I'll give you something rather nice?\"`n`nYou smirk.  \"And I presume that if I get it wrong, you'll do something horrible to me.\"`n`n\"Oh,\" says the Joker, smiling even wider, \"`iquite`i horrible, I assure you.  All a part of the service, you know!\"`n`nWhat will you do?");
        addnav("Cryptic Joker");
        addnav("Play his game", $from . "op=yes");
        addnav("Run like hell", $from . "op=no");
        $session['user']['specialmisc'] = "";
    } elseif ($op == "yes") {
        $subop = httpget('subop');
        if ($subop != "answer") {
            $rid = $session['user']['specialmisc'];
            if (!strpos($rid, "Riddle")) {
                $sq1 = "SELECT * FROM " . db_prefix("riddles") . " ORDER BY rand(" . e_rand() . ")";
            } else {
                // 6 letters in "Riddle"
                $rid = substr($rid, -1 * (strlen($rid) - 6));
                $sq1 = "SELECT * FROM " . db_prefix("riddles") . " WHERE id={$rid}";
            }
            $result = db_query($sq1);
            $riddle = db_fetch_assoc($result);
            $session['user']['specialmisc'] = "Riddle" . $riddle['id'];
            output("The Joker smiles, leans in close, and whispers to you:`n`n");
            output("`6\"`@%s`6\"`n`n", $riddle['riddle']);
            output("What is your guess?");
            rawoutput("<form action='" . $from . "op=yes&subop=answer' method='POST'>");
            rawoutput("<input name='guess'>");
            $guess = translate_inline("Guess");
            rawoutput("<input type='submit' class='button' value='{$guess}'>");
            rawoutput("</form>");
            addnav("", $from . "op=yes&subop=answer");
        } else {
            $rid = substr($session['user']['specialmisc'], 6);
            $sq1 = "SELECT * FROM " . db_prefix("riddles") . " WHERE id={$rid}";
            $result = db_query($sq1);
            $riddle = db_fetch_assoc($result);
            //*** Get and filter correct answer
            // there can be more than one answer in the database,
            // separated by semicolons (;)
            $answer = explode(";", $riddle['answer']);
            foreach ($answer as $key => $answer1) {
                // changed "" to " " below, I believe this is the correct
                // implementation.
                $answer[$key] = preg_replace("/[^[:alnum:]]/", " ", $answer1);
                $answer[$key] = riddles_filterwords($answer1);
            }
            //*** Get and filter players guess
            $guess = httppost('guess');
            $guess = preg_replace("/[^[:alnum:]]/", " ", $guess);
            $guess = riddles_filterwords($guess);
            $correct = 0;
            //changed to 2 on the levenshtein just for compassion's
            // sake :-)  --MightyE
            foreach ($answer as $answer1) {
                // Only allow spelling mistakes if te word is long enough
                if (strlen($answer1) > 2) {
                    if (levenshtein($guess, $answer1) <= 2) {
                        // Allow two letter to be off to compensate for silly
                        // spelling mistakes
                        $correct = 1;
                    }
                } else {
                    // Otherwise, they have to be exact
                    if ($guess == $answer1) {
                        $correct = 1;
                    }
                }
            }
            // make sure an empty response from the player is never correct.
            if (!$guess) {
                $correct = 0;
            }
            if ($correct) {
                if (is_module_active("medals")) {
                    require_once "modules/medals.php";
                    medals_award_medal("crypticjoker", "Cryptic Answers", "This player correctly answered a question from the Cryptic Questions Joker!", "medal_crypticjoker.png");
                }
                output("`nThe Joker's face splits into a wide grin.  \"I see you're no stranger to cryptic questions!  Very well, here is your prize.\"`n`nHe produces a long, thin hypodermic needle from his sleeve and, moving with the speed of a cat, slides it into your arm...`n`n`6");
                // It would be nice to have some more consequences
                $rand = e_rand(1, 7);
                switch ($rand) {
                    case 1:
                    case 2:
                        output("You feel the chemical beginning to toughen your skin!  Within moments, your defensive powers are dramatically increased!");
                        apply_buff("riddlejoker1", array("name" => "`7Cryptic Questions Joker Needle`0", "defmod" => "1.2", "rounds" => 20, "wearoff" => "`4The effects of the Riddling Joker's hypodermic have faded...`0", "schema" => "module-riddles"));
                        break;
                    case 3:
                    case 4:
                        output("You feel the chemical beginning to heighten your perception!  Within moments, you feel a lot more dangerous!");
                        apply_buff("riddlejoker2", array("name" => "`7Cryptic Questions Joker Needle`0", "atkmod" => "1.2", "rounds" => 20, "wearoff" => "`4The effects of the Riddling Joker's hypodermic have faded...`0", "schema" => "module-riddles"));
                        break;
                    case 5:
                    case 6:
                        output("You feel the chemical beginning to quicken your heartbeat!  Within moments, you feel you have the energy to take on a couple more jungle fights!  You gain some Stamina!");
                        $session['user']['turns']++;
                        $session['user']['turns']++;
                        break;
                    case 7:
                        output("You feel a burning in your extremities as your muscles begin to knit back together...");
                        apply_buff("riddlejoker3", array("name" => "`7Cryptic Questions Joker Needle`0", "regen" => e_rand(1, 12), "rounds" => 20, "effectmsg" => "`4The chemical contained in the Riddle Joker's hypodermic surprise heals you for {damage} points.", "wearoff" => "`4The effects of the Riddling Joker's hypodermic have faded...`0", "schema" => "module-riddles"));
                        break;
                }
            } else {
                output("`nThe Joker smiles.  \"I see.  Well, then, let's see what we have for you...\"`n`nHe produces a slender, wickedly sharp hypodermic needle from an inner pocket and jabs it into your neck before you even have time to react.`n`n`4");
                // It would be nice to have some more consequences
                $rand = e_rand(1, 7);
                switch ($rand) {
                    case 1:
                    case 2:
                        output("You feel the chemical beginning to slow you down!  Within moments, your defensive powers are dramatically reduced!");
                        apply_buff("riddlejoker4", array("name" => "`7Cryptic Questions Joker Needle`0", "defmod" => "0.8", "rounds" => 10, "wearoff" => "`4The effects of the Riddling Joker's hypodermic have faded...`0", "schema" => "module-riddles"));
                        break;
                    case 3:
                    case 4:
                        output("You feel the chemical beginning to weaken your muscles!  Within moments, you feel a lot less dangerous!");
                        apply_buff("riddlejoker5", array("name" => "`7Cryptic Questions Joker Needle`0", "atkmod" => "0.8", "rounds" => 10, "wearoff" => "`4The effects of the Riddling Joker's hypodermic have faded...`0", "schema" => "module-riddles"));
                        break;
                    case 5:
                    case 6:
                        output("You suddenly feel drowsy!  You lose some Stamina!");
                        $session['user']['turns']--;
                        $session['user']['turns']--;
                        break;
                    case 7:
                        output("Your muscles begin to decay inside your skin as you live and breathe!");
                        apply_buff("riddlejoker6", array("name" => "`7Cryptic Questions Joker Needle`0", "regen" => e_rand(-1, -12), "rounds" => 10, "effectmsg" => "`4The chemical contained in the Riddle Joker's hypodermic surprise damages you for {damage} points.", "effectfailmsg" => "`4The chemical contained in the Riddle Joker's hypodermic surprise damages you for {damage} points.", "wearoff" => "`4The effects of the Riddling Joker's hypodermic have faded...`0", "schema" => "module-riddles"));
                        break;
                }
            }
            $session['user']['specialinc'] = "";
            $session['user']['specialmisc'] = "";
        }
    } elseif ($op == "no") {
        output("`n`6Afraid to look the fool, you decline his challenge.");
        output("He was a little bit creepy anyway.`n");
        output("`6The strange man waves goodbye as you stroll, a little quickly but hating to show it, into the depths of the jungle.");
        $session['user']['specialinc'] = "";
        $session['user']['specialmisc'] = "";
    }
    output("`0");
}
function basictraining_run()
{
    global $session;
    $op = httpget("op");
    page_header("Basic Training");
    switch ($op) {
        case "start":
            if (get_module_pref("visited") == 0) {
                set_module_pref("visited", 1);
                output("`0A uniformed, medallion-festooned, barrel-chested brute of a man greets you at the Basic Training compound just inside the Outpost gates.  His moustache is broad enough to have its own postcode.`n`n\"`2RAAAAAIIIIGHT THEN!`0\" he bellows, his cheeks red and his eyes bulging with barely-suppressed bloodlust.  \"`2My name is Corporal `iPUNISHMENT!`i  You may refer to me as \"Corporal,\" \"Sir,\" or \"Your 'ighness.\"  My job is to educate freshly-baked recruits like you, and prepare them for their moments of `iGLORY!`i\"`n`n`0You take note of the Corporal's bulging forehead veins, and seriously consider fleeing into the Jungle.`n`n\"`2NAOHW!  The `ifirst`i exercise we're going to perform today is a `irole-playing exercise`i!  I want you to imagine that you're not really here, but instead, you're sat in a comfy chair somewhere about seventy years ago with a computer or a mobile phone, playin' some sort of \"browser-based text adventure game\" and just `ireadin'`i about your experiences 'ere today!  And `ithen`i I want you to reach out towards your keyboard, and press the 'F' key!  That's 'F' for Foxtrot!  An' if you have JavaScript disabled, it's likely that nothing will happen, and you can simply click on the link and ignore anything I say about the keyboard!`0\"`n`nYou gawp at the man, now convinced that he's living in some sort of fantasy world.");
                addnav("Oh dear.");
                addnav("F?Fear for your life", "runmodule.php?module=basictraining&op=continue");
            } else {
                output("`0\"`2NOW!  What ELSE can I 'elp you with today, young recruit?`0\"");
                addnav("Questions");
                addnav("Tell me how I go about destroying this Improbability Drive.", "runmodule.php?module=basictraining&op=improbabilitydrive-destroy");
                addnav("Tell me about this Head-Up Display you mentioned.", "runmodule.php?module=basictraining&op=hud");
                addnav("Tell me about fighting monsters.", "runmodule.php?module=basictraining&op=combat");
                addnav("Tell me about backpacks and bandoliers.", "runmodule.php?module=basictraining&op=backpackbandolier");
                addnav("Tell me about travelling to different Outposts.", "runmodule.php?module=basictraining&op=travel");
                addnav("Tell me why you shout so much.", "runmodule.php?module=basictraining&op=shout");
                addnav("Leave Basic Training");
                addnav("Exit to NewHome", "village.php");
            }
            break;
        case "continue":
            output("The Corporal beams at you.  \"`2`iEXCELLENT!`i  We might just make a soldier of you yet!`0\"`n`nYou shake your head, still not sure what's going on.  It's not like you said or did anything other than worry about your safety.  He just kind of paused for a second, then carried on.`n`n\"`2AS you can see, it is possible to use the KEYBOARD to move around instead of the MOUSE, should you so prefer it!  Simply press the key that is a-`iAHAIGHLIGHTED!`i  HERE is a BACKPACK and BANDOLIER in which to keep your EQUIPMENT.`0\"  He hands you a shoddy-looking backpack, and an even shoddier-looking bandolier.  You shrug, and put them both on.  \"`2Now, let's talk about your head-up Statistics display.  This can be found to the RIGHT of your SCREEN!`0\"`n`nYou look around.  You don't see anything of the sort.  Nor do you see any type of screen.  But you decide to go along with it, and nod and smile at the appropriate points.`n`n\"`2The two most IMPORTANT pieces of BASIC INFORMATION that you NEED to KNOW in order to `iSURVIVE`i,\"`0 bellows the Corporal, spittle flying from his lips, \"`2are your HITPOINTS and your STAMINA!  When your HITPOINTS are gone, you'll be taking a trip to see...`0\" He looks left and right, then leans forward conspiratorially.  \"`2You know.  `\$Her.`0\"`n`nYou wonder whether he's scared of `\$The Watcher`0, and also how the hell he did that `\$thing`0 with his voice.`n`n\"`2MOST of the things that you can do on the Island will require some amount of STAMINA!  When your Stamina is low, you run the risk of making MISTAKES or even LOSING CONSCIOUSNESS because you are becoming EXHAUSTED!  STAMINA is restored to MAXIMUM once every new GAME DAY.  NOW, do you have any QUESTIONS, or shall I move on?`0\"`n`nYou think for a moment, unsure of whether to ask.  Eventually you decide to go for it.  \"`#Yes.  Why do you measure everything you see in terms of numbers and statistics in some sort of computer game?`0\"`n`nThe Corporal smiles.  \"`2For the SAME reason you have your FISTS strapped to your BACK, sunshine.`0\"`n`nWell, that cleared that up.`n`n\"`2If you take NOTHING else from my INSTRUCTION, just remember these FOUR SIMPLE THINGS.`n`n\"ONE: Keep an eye on your STAMINA, and try not to let it go too far into the ORANGE.  You can REPLENISH it by waiting for the next new GAME DAY, or by EATING, DRINKING or SMOKING.`n`n\"TWO: Keep an eye on your HITPOINTS, and go to the HOSPITAL TENT to recover them.  All healing is FREE at Level One.`n`n\"THREE: Don't walk around with lots of REQUISITION in your pockets, because if you get KNOCKED OUT, all your MONEY will be STOLEN by MIDGETS.  Put it in the BANK, where it will be MARGINALLY SAFER.`n`n\"FOUR: BEFORE you go GALLAVANTING into the JUNGLE like a LAMB to the `iSLAUGHTER`i, for GOD'S SAKE `iBUY SOMETHING WITH WHICH TO DEFEND YOURSELF!`i  SHEILA'S SHACK has a very NICE range of WEAPONRY and ARMOUR available for purchase, and that should be your FIRST stop when you head into the Outpost, followed by the COUNCIL OFFICES where you can obtain free GRENADES, RATION PACKS, or MEDKITS.`0\"  The Corporal wipes his now-sodden moustache on his sleeve.  \"`2I now pronounce you JUST ABOUT fit to SURVIVE for LONG enough to get CONFUSED, and you may LEAVE this compound if you wish.  UNLESS you have FURTHER questions, which I will answer `iNOW!`i`0\"  He shrugs.  \"`2Or, hell, I'll be here when you come back.  I don't get out much.`0\"");
            addnav("Questions");
            addnav("Tell me about this Island, and the Improbability Drive.", "runmodule.php?module=basictraining&op=island");
            addnav("What is my objective here?", "runmodule.php?module=basictraining&op=objective");
            addnav("Tell me more about this Head-Up Display of yours.", "runmodule.php?module=basictraining&op=hud");
            addnav("What's this backpack and bandolier for?", "runmodule.php?module=basictraining&op=backpackbandolier");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "island":
            output("\"`2MANY years ago, a man called Professor HAWTON tried to create an OVERUNITY DEVICE!  That is to say, a type of GENERATOR that OUTPUTS more power than it CONSUMES, in blatant disregard for the second law of THERMODYNAMICS and the law of CONSERVATION of `iENERGY!`i  He was SENT here obstensibly to work on his machine in an environment without ELECTROMAGNETIC INTEFERENCE, but the TRUTH of the matter is that he was sent HERE because NOBODY at his university could STOMACH the man!`0\"  You wonder if that might be because Hawton shouted as much as Corporal Punishment.  \"`2LONG story SHORT, he must have been at least PARTIALLY successful - because with the help of a similarly banished assistant, he created a machine that generates a type of energy that the human race has NEVER before EXPERIENCED!  THAT energy is what created this place, along with the unusual FLORA and FAUNA that INHABIT it!  For a more DETAILED account, and information about the various POPULACES and HISTORY of the Island, you'd do well to visit the MUSEUM just down the road.`0\"");
            addnav("Questions");
            addnav("Is \"unusual fauna\" a euphemism for \"horrible, drooling monster\", and if so, what do I do about those?", "runmodule.php?module=basictraining&op=combat");
            addnav("Remind me what I'm even doing in this awful place?", "runmodule.php?module=basictraining&op=objective");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "objective":
            output("\"`2Your OBJECTIVE is, of course, to DESTROY or DISABLE the Improbability Drive!  HOWEVER, a LOT of people seem to be more interested in such NAMBY-BLOODY-PAMBY activities as travelling between Outposts to trade commodities, building ROBOTS out of BITS of SCRAP, perfecting their COOKING skills or just CHATTING amongst themselves!  It `iMAKES MY BLOOD BOIL!`i`0\"  He's not kidding.  You can see flecks of foam clinging to his moustache.  \"`2GOD, WHAT I'D DO FOR A DECENT WAR!  Trying to get that lot out there ORGANIZED is like trying to herd CATS!`0\"  He hyperventilates for a moment, then calms himself.  \"`2Well, I might as well give you the full run-down.  Where should I start?`0\"");
            addnav("Questions");
            addnav("Remind me why this Island is here to begin with, and just what this Improbability Drive actually is?", "runmodule.php?module=basictraining&op=island");
            addnav("Tell me how I go about destroying this Improbability Drive.", "runmodule.php?module=basictraining&op=improbabilitydrive-destroy");
            addnav("Tell me about this Head-Up Display you mentioned.", "runmodule.php?module=basictraining&op=hud");
            addnav("What's this backpack and bandolier for?", "runmodule.php?module=basictraining&op=backpackbandolier");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Bloody hell mate, you don't half shout a lot.", "runmodule.php?module=basictraining&op=shout");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "improbabilitydrive-destroy":
            output("\"`2As far as we KNOW, destroying the Improbability Drive is like DESTROYING any other MONSTER.  The HARD part is FINDING the damned thing!  RUMOUR has it that it can ONLY be found by people who are a HIGH enough COMBAT LEVEL.`0\"");
            addnav("Questions");
            addnav("Combat Level?  Is that something from the Head-Up Display?", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Tell me about combat.", "runmodule.php?module=basictraining&op=combat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "shout":
            $npcact = e_rand(1, 8);
            $npcspk = e_rand(1, 8);
            $pla = e_rand(1, 8);
            switch ($npcact) {
                case 1:
                    output("The Corporal's eyes open wide at the accusation, and appear to bulge out of his head.  \"`2");
                    break;
                case 2:
                    output("The Corporal's face flushes to an even deeper red, reminding you of an overcooked lobster.  \"`2");
                    break;
                case 3:
                    output("The pulsating vein in the Corporal's forehead throbs ominously.  \"`2");
                    break;
                case 4:
                    output("The Corporal sputters, wipes the spittle from his moustache, and shouts.  \"`2");
                    break;
                case 5:
                    output("The Corporal's right eye bores into your soul, while his left begins to swivel slowly towards the sky, exposing some rather worrying ruptured blood vessels.  \"`2");
                    break;
                case 6:
                    output("The Corporal stands in silence for a moment.  His left eye twitches, twice.  Then, he lunges forward.  \"`2");
                    break;
                case 7:
                    output("The Corporal's eyebrows descend, narrowing his eyes to bloodshot slits.  He advances upon you, with a hiss of \"`2");
                    break;
                case 8:
                    output("The Corporal takes a deep breath, buttons popping comically off his uniform, and says \"`2");
                    break;
            }
            switch ($npcspk) {
                case 1:
                    output("`iDO I BOLLOCKS!`i");
                    break;
                case 2:
                    output("`iTHAT`i is a load of `iUTTER DRIVEL!`i  I've never SHOUTED before in my LIFE!");
                    break;
                case 3:
                    output("`iI'VE NEVER HEARD SUCH NONSENSE IN ALL MY LIFE!`i");
                    break;
                case 4:
                    output("`iNO I BLOODY WELL DO `bNOT`b YOU ARROGANT TWERP!`i");
                    break;
                case 5:
                    output("`iTHAT`i is an `iUNFOUNDED`i and `iSLANDEROUS `bACCUSATION!`b`i");
                    break;
                case 6:
                    output("`iBULLSHIT!`i  UTTER, TOTAL `iBLOODY WANKING `bBULLSHIT`b!`i`0\"  He takes a deep breath, and twitches a couple of times.  \"`2ARSE!");
                    break;
                case 7:
                    output("I'm not shouting now, am I?  No.`0\" The Corporal stands quietly, breathing deeply.  \"`2No.  Now, I'm relaxed.  Everything is fine.  So long as nobody `i`bBLOODY ACCUSES ME OF SHOUTING WITHIN MY BLOODY EARSHOT!`b`i");
                    break;
                case 8:
                    output("`iI DON'T SHOUT!  `bTHIS`b ISN'T `bSHOUTING`b!  DO YOU WANT TO SEE `bSHOUTING`b?  `bDO`b YOU?  THEN JUST KEEP ON COMPLAINING ABOUT MY SHOUTING!`i");
                    break;
            }
            output("`0\"");
            addnav("Oh really?");
            switch ($pla) {
                case 1:
                    addnav("You bloody do, though, don't you?", "runmodule.php?module=basictraining&op=shout");
                    break;
                case 2:
                    addnav("Oh, you totally do.", "runmodule.php?module=basictraining&op=shout");
                    break;
                case 3:
                    addnav("You're shouting `iright now,`i dude.", "runmodule.php?module=basictraining&op=shout");
                    break;
                case 4:
                    addnav("Yes you do.", "runmodule.php?module=basictraining&op=shout");
                    break;
                case 5:
                    addnav("Yes, yes I'm afraid you do.", "runmodule.php?module=basictraining&op=shout");
                    break;
                case 6:
                    addnav("I have it on good authority that you shout at least three words out of every sentence.", "runmodule.php?module=basictraining&op=shout");
                    break;
                case 7:
                    addnav("It is a matter of public record that you, sir, shout at every available opportunity.", "runmodule.php?module=basictraining&op=shout");
                    break;
                case 8:
                    addnav("You're a bad liar, and you shout too.", "runmodule.php?module=basictraining&op=shout");
                    break;
            }
            addnav("Stop this childish nonsense.");
            addnav("Ask him a question, quick.", "runmodule.php?module=basictraining&op=start");
            increment_module_pref("shoutingmatch");
            if (is_module_active("medals" && get_module_pref("shoutingmatch") >= 10)) {
                require_once "modules/medals.php";
                medals_award_medal("punishment_shoutingmatch", "Sore Throat", "This player engaged in a very long shouting match with Corporal Punishment!", "medal_shoutingmatch.png");
            }
            break;
        case "backpackbandolier":
            output("The Corporal nods, and takes a deep breath.  \"`2Your BACKPACK and BANDOLIER are there for you to put THINGS in.  As a HUMAN contestant, you will receive a set of GRENADES once per day.`0\"`n`nYou frown, and look down.  \"`#Wouldn't it be better if I got, say... some pants?`0\"`n`n\"`2`iYOU'LL GET WHAT'S GIVEN AND BLEEDIN' WELL LIKE IT!`i  You can always sell the Grenades at eBoy's place, I suppose, if LUXURIES like PANTS are really THAT `iIMPORTANT`i to you, YOUR BLEEDIN' HIGHNESS.  `iAS I WAS SAYING`i.  You `iCAN'T`i go rummaging around in your Backpack in the MIDDLE of a FIGHT!  THAT'S what your BANDOLIER is for!  If you want to use a GRENADE or another item in a FIGHT, you had better open up your INVENTORY and TRANSFER the item to your BANDOLIER, so that it's EASILY GRABBABLE!`0\"`n`nThat seems kind of arbitrary and oversimplified, but it makes sense - at least to the sort of madman who sees head-up displays and keyboards wherever he looks.`n`n\"`2Your BACKPACK and BANDOLIER each have a WEIGHT limit.  You can EXCEED this limit, but if you do, EVERY ACTION that you take will cost you more STAMINA than usual.  You can INCREASE your limits by obtaining HIGHER-QUALITY equipment, and the Luggage Hut in Improbable Central can help you with THAT.`0\"");
            addnav("Questions");
            addnav("Ask about Travelling.", "runmodule.php?module=basictraining&op=travel");
            addnav("Remind me why this Island is here to begin with, and just what this Improbability Drive actually is?", "runmodule.php?module=basictraining&op=island");
            addnav("Tell me how I go about destroying this Improbability Drive.", "runmodule.php?module=basictraining&op=improbabilitydrive-destroy");
            addnav("Tell me about this Head-Up Display you mentioned.", "runmodule.php?module=basictraining&op=hud");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "hud":
            output("\"`2The HEAD-UP DISPLAY on the right-hand side of your SCREEN contains various STATISTICS about your good self!  What would you like to know about?`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "hud-level":
            output("\"`2The LEVEL shown in your HEAD-UP DISPLAY is a simple measure of your COMBAT SKILL!`0\" barks the Corporal.  \"`2Every time you defeat a VILE CREATURE in COMBAT, you will earn some EXPERIENCE points!  Once you have ENOUGH Experience points, you'll be able to challenge your MASTER at the DOJO in your home town, and ascend one LEVEL!  This will earn you TEN extra HITPOINTS and one extra point of both ATTACK and DEFENCE!  When you reach a HIGH enough COMBAT LEVEL, you will be able to take on the `iIMPROBABILITY DRIVE`i and make me a very PROUD Corporal `iindeed!`i`0\"");
            addnav("Ask about Statistics");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Tangents");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Ask about destroying the Improbability Drive", "runmodule.php?module=basictraining&op=improbabilitydrive-destroy");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "hud-hitpoints":
            output("\"`2The HITPOINTS shown to the right of your screen are a simple measure of how healthy, or how `iHORRIBLY MAIMED`i, you happen to be at any given time.  You will lose HITPOINTS whenever you are `iINJURED,`i either in COMBAT or DOING SOMETHING SILLY!  The easiest way to recouperate Hitpoints is to go to the HOSPITAL Tent in the Jungle.  At Level One, all services provided by the Hospital Tent are FREE of CHARGE.  From Level Two onwards, it's always cheaper to heal, say, ten hitpoints' worth of DAMAGE than it is to heal FIVE hitpoints of damage TWICE.  So it's best to let yourself get a bit BEATEN UP before asking for the services of your local mmm-mmmm...`0\"  Tendons stand out on the Corporal's neck, and the vein in his scarlet forehead throbs disconcertingly.  \"`2MMM`iMEDIC!`i`0\"`n`nHe takes a breath and carries on.  \"`2If your hitpoints drop to ZERO, you will lose CONSCIOUSNESS and find yourself stuck on the FAILBOAT until such time as you can ESCAPE!`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Tangents");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Ask about the FailBoat", "runmodule.php?module=basictraining&op=failboat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "hud-attack":
            output("The Corporal grimaces.  \"`2I would have thought that would have been BLEEDIN' OBVIOUS, don't you?  Your ATTACK rating is a simple measure of how EFFECTIVE you are in COMBAT!  A high LEVEL and good WEAPONS will `iINCREASE`i this number.  The HIGHER the number, the HIGHER your chance of landing a successful blow, and doing a lot of damage!  BUFFS can also affect your Attack rating.\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Tangents");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "hud-defence":
            output("\"`2Your DEFENCE rating establishes how RESILIENT you are to ATTACKS from VARIOUS AGGRESSORS!  A high DEFENCE rating will allow you to take HEAVIER blows without losing as many HITPOINTS.  It will ALSO allow you to deal more frequent COUNTER-ATTACKS!  You can RAISE your DEFENCE rating with ARMOUR, by going UP a LEVEL, or with BUFFS!\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Tangents");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "stamina":
            output("\"`2Your STAMINA is a measure of how TIRED you are!  Whenever you are about to do something that will consume STAMINA, the amount of Stamina the action will cost will be displayed to the RIGHT of the relevant LINK!  If you are a SIGHTED player, you will see that the STAMINA amount is highlighted in ORANGE!  If you are a BLIND or VISUALLY IMPAIRED player using a SCREEN READER like NVDA or... I suppose... JAWS - `0\" he takes a moment to spit on the ground at the very mention of whatever the hell JAWS is - \"`2you can assume that ANYTHING in BRACKETS expressed as a PERCENTAGE is a STAMINA cost reading!`0\"`n`n\"`2Players used to playing LEGEND of the GREEN DRAGON will be NEW to STAMINA, so I'll try to EXPLAIN it as BEST I can HERE.  When you are TIRED, your chances of SUCCEEDING in any given ACTION or in COMBAT are `iDIMINISHED!`i  When your Stamina is in the RED, you are in SEVERE peril of simply LOSING CONSCIOUSNESS!  Over time you will LEVEL UP in certain particular SKILLS - in a NUTSHELL, the MORE you perform a particular ACTION and the HIGHER your LEVEL for that ACTION, the FEWER Stamina points that ACTION will COST to PERFORM.  `iSO!`i  If you enjoy TRAVELLING more than COMBAT, and do it more REGULARLY, then you will find that your character will EVENTUALLY become very PROFICIENT in TRAVEL, and you will be able to travel FURTHER in a SINGLE DAY.  Think of it like a CHARACTER CLASS, except that rather than CHOOSING or CREATING a class at the start of the GAME, your class is `iAUTOMATICALLY`i created by the game, ACCORDING to the way in which you play, `iJUST FOR YOU!`i`0\"`n`nAgain with the computer game analogies.  And it sounds like a bloody complex game he's describing.  You're very, very glad that you don't live in this man's world.`n`nYou nod and smile as the madman continues his gibbering.`n`n\"`2AS you explore the ISLAND, you will very likely come across PEOPLE who can teach you new SKILLS.  To get an OVERVIEW of your SKILLS, along with any BONUSES or PENALTIES to STAMINA COST or ACTION EXPERIENCE GAIN, just click the STAMINA link in your HEAD-UP DISPLAY.  BONUSES and PENALTIES to the cost and experience gain of individual ACTIONS can be applied by different MOUNTS, various items of FOOD and DRINK, certain PILLS, and various OTHER items and events.`0\"`n`n\"`#You know,`0\" you mumble, \"`#this all sounds `ihorrendously`i complicated.`0\"`n`n\"`2YES, it DOES!  `iHOWEVER`i, in MY experience of teaching NEWBIES like YOU, nearly ALL of them have found the system very EASY to use after a minute or two of USING it.  This is probably just one of those things that's a `ilot`i easier to learn by doing it, rather than by having me explain how it works.`0\"`n`nYou shrug.  I guess we'll see about that.");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Tangents");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Ask about Travel", "runmodule.php?module=basictraining&op=travel");
            addnav("Ask about Backpacks and Bandoliers", "runmodule.php?module=basictraining&op=backpackbandolier");
            addnav("Ask about Mounts", "runmodule.php?module=basictraining&op=mounts");
            addnav("Ask about food and drink", "runmodule.php?module=basictraining&op=foodanddrink");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "requisition":
            output("\"`2REQUISITION tokens are little silver COINS that are dispensed from HOPPERS mounted underneath the CAMERAS that you see EVERYWHERE on the Island.  When you defeat a MONSTER, some TOKENS will be EJECTED from the HOPPER.  These tokens can be used to procure GOODS and SERVICES.  They are an official currency, but SOME merchants will refuse to accept them, opting for CIGARETTES instead.`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "cigarettes":
            output("\"`2CIGARETTES can be either SMOKED or used in TRADE.  They can be obtained VERY occasionally in COMBAT.  SMOKING a cigarette will result in GREATER COMBAT EFFICACY, but can also lead to CRAVINGS.  Some merchants INSIST on being paid in CIGARETTES rather than in REQUISITION tokens.  Also, AMERICAN players should remember that SOME people on the ISLAND are BRITISH, myself included, and may refer to cigarettes as `iFAGS`i, which I understand is also a rather INSULTING American term for a GAY gentleman.  This is a distinction that both AMERICAN and BRITISH players should be `iAWARE`i of, because sometimes `iMISUNDERSTANDINGS`i can occur!  In general, if someone says that, for example, they need more fags in order to get a good Mount, you should give them the BENEFIT of the DOUBT and assume that they're BRITISH and are, in fact, talking about DELICIOUS CIGARETTES.`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "experience":
            output("\"`2EXPERIENCE is awarded with every VILE CREATURE you dispatch in the JUNGLE!  With enough EXPERIENCE, you will be able to CHALLENGE your MASTER and ascend one LEVEL.`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Tangents");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "newday":
            output("\"`2In Improbable Island, there are several new GAME DAYS per REAL DAY.  At a new GAME DAY, your HITPOINTS are restored to their MAXIMUM, as is your STAMINA, and most BUFFS are removed or reset.  All players who spent the night on the FAILBOAT due to their own INEXPERIENCE, poor JUDGEMENT or simply BAD LUCK, will be RESTORED to the Island at the beginning of each new DAY.`0\"`n`n\"`2Since few people have the spare TIME to play every GAME DAY, a certain number of GAME DAYS can be stored up for later use, simply by not logging in.`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Tangents");
            addnav("Ask about the FailBoat", "runmodule.php?module=basictraining&op=failboat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "weaponsandarmour":
            output("\"`2WEAPONS and ARMOUR can be purchased from SHEILA'S SHACK, and will improve your ATTACK and DEFENCE ratings.`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "buffs":
            output("\"`2BUFFS are temporary, semi-permanent or permanent MODIFIERS to your ATTACK and/or DEFENCE ratings, or the ATTACK and DEFENCE ratings of the MONSTER you happen to be FIGHTING.  You will come across these as you EXPLORE.`0\"");
            addnav("Ask about Statistics");
            addnav("Level", "runmodule.php?module=basictraining&op=hud-level");
            addnav("Hitpoints", "runmodule.php?module=basictraining&op=hud-hitpoints");
            addnav("Attack", "runmodule.php?module=basictraining&op=hud-attack");
            addnav("Defence", "runmodule.php?module=basictraining&op=hud-defence");
            addnav("Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Next Day", "runmodule.php?module=basictraining&op=newday");
            addnav("Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "mounts":
            output("\"`2MOUNTS are creatures or machines that you can RIDE AROUND.  Some of these Mounts will FIGHT with you in COMBAT!`0\" spits the Corporal.  \"`2OTHERS will allow you to travel FUTHER in a single DAY!  You can buy a Mount at Mike's Chop Shop.  Most Chop Shops will only accept CIGARETTES as PAYMENT!`0\"");
            addnav("Questions");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Ask about Travel", "runmodule.php?module=basictraining&op=travel");
            addnav("Ask about Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Ask about Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Ask about Cigarettes", "runmodule.php?module=basictraining&op=cigarettes");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "foodanddrink":
            output("\"`2EATING and DRINKING are ESSENTIAL for your continued SURVIVAL!`0\" barks the Corporal. \"`2If you do not keep yourself WELL-FED, you run the risk of waking up with less STAMINA than you would normally have!  Likewise, if you only eat foods high in fat or low in nutritional content, you will ALSO suffer ill-effects!  HOWEVER, if you eat only good-quality, nutritious food, you will find yourself with MORE Stamina each DAY!`0\"");
            addnav("Questions");
            addnav("Ask about Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Ask about Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Ask about Game Days", "runmodule.php?module=basictraining&op=newday");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "failboat":
            output("\"`2The FAILBOAT is where you will be sent if you are found UNCONSCIOUS!`0\" barks the Corporal. \"`2If you are DEFEATED in COMBAT, or if you LOSE CONSCIOUSNESS due to EXHAUSTION, this is where you'll end up!  To get off the FailBoat and back onto the Island, you'll have to impress `\$THE WATCHER.`2  She will let you back on to the Island when you either undergo retraining to her satisfaction, or when the next Game Day arrives.`0\"");
            addnav("Questions");
            addnav("Ask about Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Ask about Game Days", "runmodule.php?module=basictraining&op=newday");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "combat":
            output("\"`2The EASIEST way to get your feet wet in COMBAT is to march PROUDLY into the JUNGLE and start LOOKING for TROUBLE!`0\" yells the Corporal, his moustache jiggling as he grins. \"`2Better WEAPONS and ARMOUR will IMPROVE your chances of success, as will certain BUFFS.  When you are INJURED, be sure to HEAL yourself using MEDKITS, or at the HOSPITAL TENT.  Every MONSTER you DEFEAT will grant both EXPERIENCE and REQUISITION!  Sometimes you will come across a MONSTER that is BIGGER than you, and it would be a good idea to `iRUN LIKE HELL!`i  Sometimes the monster will CHASE you as you flee, in which case you may wish to either ABANDON the chase and go back to FIGHTING, or CONTINUE trying to run, GIBBERING and SCREAMING and `iFLAILING YOUR ARMS`i as you do so.  If you are DEFEATED in COMBAT, you will be knocked UNCONSCIOUS.  You will `iLOSE`i a certain amount of EXPERIENCE.  You will LOSE `iALL`i of the REQUISITION tokens that you have on your person.  And you `iWILL`i be `iSENT`i to the `iFAILBOAT!`i  THIS is why it is IMPORTANT to know when to RUN, when to FIGHT, when to use GRENADES and other OFFENSIVE items, and to `iFREQUENTLY BANK YOUR REQUISTION`i.  And REMEMBER, you can ONLY use items in COMBAT that you have placed in your `iBANDOLIER`i.  You DON'T want to be rummaging around in your BACKPACK during a FIGHT, sunshine!`0\"");
            addnav("Questions");
            addnav("Ask about Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Ask about Requisition", "runmodule.php?module=basictraining&op=requisition");
            addnav("Ask about Weapons and Armour", "runmodule.php?module=basictraining&op=weaponsandarmour");
            addnav("Ask about Experience", "runmodule.php?module=basictraining&op=experience");
            addnav("Ask about Buffs", "runmodule.php?module=basictraining&op=buffs");
            addnav("Ask about the FailBoat", "runmodule.php?module=basictraining&op=failboat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
        case "travel":
            output("\"`2TRAVEL between different OUTPOSTS can be a DANGEROUS and LONELY affair!`0\" yells the Corporal. \"`2You will be accosted by more MONSTERS in some terrain types than in others!  Likewise, navigating different types of TERRAIN will cost MORE or LESS Stamina!  Certain MOUNTS will make TRAVEL easier, and reduce the chances of being ACCOSTED by a `iMONSTER`i on the way!  Bear in mind that the more TIRED you are, the SLOWER you will move, and the more VULNERABLE you will be to MONSTER attack!  The two EASIEST Outposts to get to from here are KITTANIA, the home of the KITTYMORPHS, and IMPROBABLE CENTRAL, the `iCAPITAL`i CITY.  To get to EITHER of these places, head NORTH EAST from here.  When you get to a FORK in the PATH, head `iNORTH`i for Improbable CENTRAL, or `iEAST`i for KITTANIA!  Remember to make sure you are fully HEALED, and STOCK UP on MEDKITS if possible before you go, because there are NO HEALERS out there in the wilderness.`0\"");
            addnav("Questions");
            addnav("Ask about Stamina", "runmodule.php?module=basictraining&op=stamina");
            addnav("Ask about Mounts", "runmodule.php?module=basictraining&op=mounts");
            addnav("Ask about Combat", "runmodule.php?module=basictraining&op=combat");
            addnav("Change the subject");
            addnav("Ask about something else", "runmodule.php?module=basictraining&op=start");
            addnav("Leave Basic Training");
            addnav("Exit to NewHome", "village.php");
            break;
    }
    page_footer();
}
function misterstern_run()
{
    global $session;
    switch (httpget("op")) {
        case "start":
            page_header("Mister Stern");
            $name = $session['user']['name'];
            output("\"`6Hello!`0\"`n`nYour heart puts on its running shoes and tears off around the track.  After roughly half a second of panic, you realise that the voice sounded quite friendly.  Jolly, even.  Male, British - a little upper class, perhaps, but not snooty with it.  Rather warm and sophisticated, in fact.`n`nYou look in the direction of the voice, and in the dim light you make out the outline of a figure standing behind the desk in the lobby.  You step forward.  \"`#Um, hello?`0\" you say.  \"`#I'm sorry, I thought I was alone.`0\"`n`nAs you step closer, the figure walks around from behind his desk.  \"`6I can't blame you, in this gloom,`0\" he says, walking across the room to a window and opening it.  Warm sunlight floods the lobby, little specks of dust dancing and reflecting in the air.  \"`6There,`0\" says the man.  \"`6That's better.`0\"`n`nThe tall, rather slender man wears a grey waistcoat, white shirt, and smart grey trousers.  A little pair of round-framed glasses sits on his nose, its arms connected via a chain around his neck.  When he turns to face you, you can see the outline of a pocket watch resting in his waistcoat pocket, silver chain sparkling.  His age is hard to tell.  Clearly he's been around a few years; he's old enough to make you think of the librarian or dusty old academic who can't quite bring himself to retire, despite it being more than time to do so.`n`nYou can't help but grin.  This guy is the ultimate stereotype of dusty British museum curators.`n`nHe grins back and steps towards you, hand outstretched.  \"`6Mister Havelock Stern, Stern by name but not by nature, pleased to make your acquiaintance.`0\"  You get the impression that he says this every time he meets someone - and that when he said he was pleased to meet you, he actually meant it.  You take the hand, give it a shake, and say \"`#%s`#.  Nice to meet you.`0\"`n`n\"`6Sorry to give you a fright,`0\" says Mister Stern.  \"`6Only I'd just nipped into the cupboard to put the kettle on.  I don't get many visitors here, you see.`0\"`n`n\"`#That's okay,`0\" you say, a little sheepishly.  \"`#Honestly I think I was just full of adrenaline anyway.`0\"`n`nMister Stern shows you another grin.  \"`6Aha.  Did `\$The Watcher`6 send you here, by any chance?  Blonde lady, glasses, looks somewhere in her thirties?  Always wears a red turtleneck?`0\"`n`n\"`#Utterly insane and rather frightening?`0\"`n`nMister Stern chuckles.  \"`6Yes, that's the one.  I see.  Well, you must be a new recruit, then.  Well, I remember my first day.  It's rough, isn't it?  Well, the kettle should be boiled by now, if you'd like a break from it all...?`0\"`n`nYou've been kidnapped and thrust into a war against a reality-altering machine, and now a kindly gentleman is offering you a cup of tea.  Well, what happens next?", $name);
            addnav("Mister Stern");
            addnav("I have to admit, it's all a bit confusing.  A cup of tea sounds nice.", "runmodule.php?module=misterstern&op=tea");
            addnav("No, I think I'm doing okay.  Thanks for the offer, but I'd best be on my way.", "runmodule.php?module=misterstern&op=notea");
            break;
        case "tea":
            page_header("Mister Stern");
            set_module_pref("hadtea", 1);
            output("\"`6Jolly good,`0\" says Mister Stern, and again, you get the impression that he means it.`n`n\"`6So,`0\" he says a few minutes later, while pouring and adulterating the tea, \"`6tell me honestly.  What do you think of the exhibits?`0\"`n`n\"`#To be completely honest,`0\" you say, \"`#I wouldn't have thought there would `ibe`i a museum here.  I mean, this is Improbable Island, after all...`0\" you trail off.  \"`#I still can't believe I'm actually here.  I mean, I watched the show and everything, but you never think your number's gonna come up, do you?  Anyway.  Yes, the exhibits were very nice, but they made me miss the old days a bit.`0\"`n`nMister Stern sits down and hands you your cup.  \"`6Yes,`0\" he says, taking a sip.  \"`6I know exactly what you mean.  It's quite a culture shock, isn't it?  On both sides, I mean - coming to the Island, and getting thrown back into the Renaissance practically overnight.  They're both a big blow to the system, really.`0\"`n`n\"`#Tell me about it,`0\" you mutter into your cup.`n`nMister Stern takes you literally.  \"`6I remember the day the mines went off.  I think we all do, really.  I remember waking up and wondering why my alarm clock wasn't playing.  I assumed we'd had a power cut when I saw the display was blank.`0\"  He blows on his tea.  \"`6So, of course, I checked my phone, and that was dead, too.  Although to be fair, the battery was on its way out, and I always charge it overnight.`0\"  He takes a sip.  \"`6So, I assumed that the battery had run out in the night.  I practically jumped out of bed and ran all around the house trying to find a working clock, worried that I was going to be late.`0\"  He grins.  \"`6I ran a museum in my past life too, you see.  It's become something of a habit.`0\"  You nod and grin back.  \"`6Anyway,`0\" continues Mister Stern, \"`6I picked up the landline to try to call the speaking clock, and couldn't get a dial tone.  That was when I started to think that maybe something very bad had happened.`0\"`n`nMister Stern's eyes seem to focus somewhere in the middle distance, left of your head.  \"`6I remembered I had a little travel alarm clock, powered by a nine volt battery.  I dashed upstairs and rummaged around until I found it.`0\"  He blows on his tea.  \"`6It was dead as a doornail.  I took the battery out, and tested it on my tongue.  It gave a little tingle, so I knew the battery was fine.`0\"  He sips his tea, staring off into nowhere.  \"`6In fact, it gave quite a big tingle - almost as if it had been overcharged.  And that's when I noticed the smell, coming from the alarm clock...`0\"`n`n\"`#I remember that smell,`0\" you mutter.  \"`#Burning solder.`0\"`n`nMister Stern gives you a sad little nod.  You sit in silence for a moment.`n`n\"`6When did you catch on?`0\" asks Mister Stern after some seconds.`n`nYou shrug.  \"`#What, that the world had ended?  I honestly can't remember.  It was a very busy day.  I know my neighbour didn't realise until his car didn't start.  And even then, he didn't understand what was going on.`0\"`n`n\"`6I see,`0\" sighs Mister Stern.  \"`6You know, I think I understand why I don't get many visitors here.  The memories are too much for most people.`0\"`n`nYou nod.  \"`#The other exhibits, though - the dummies, they're not bad.`0\"`n`n\"`6Yes.  Yes, we certainly do need some more exhibits, don't we?  Maybe some cheerful ones.`0\"  Mister Stern looks out of the window.  \"`6You know, there's a world of interesting things out there.  If I could get around a little more, I'd head out and find some things to show off myself.`0\"`n`n\"`#What sort of things?`0\" you ask.`n`n\"`6Oh, just anything interesting, really.  Some herbs from the KittyMorph village, maybe some artefacts from Cyber City, that sort of thing.  I'd like to get a good range of things to show to people, you know?  But since the accident, I just haven't been able to get around too much.`0\"`n`n\"`#Accident?`0\"`n`nMister Stern points to his left knee.  \"`6Shrapnel.  Shrapnel from a piece of the equipment surrounding the Improbability Drive, no less.  It's impossible to walk terribly far, and I daren't use any of these new-fangled teleporter devices - who knows how such a machine would interact with a piece of Improbability-infused metal?`0\"`n`nYou shrug.  \"`#Hell, I'm going to be heading out into the Big Bad Jungle just as soon as I've finished this tea; if I come across anything interesting, I'll be sure to let you know.`0\"`n`nMister Stern smiles.  \"`6I'm sure you'll come across a great `imany`i interesting things.  It's a jungle out there.`0\"`n`nYou grin back.`n`nA few minutes of idle chitchat later, you finish your tea, bid your farewells and leave the Museum.");
            addnav("Continue");
            addnav("Head back into the Outpost", "village.php");
            break;
        case "notea":
            page_header("Mister Stern");
            output("\"`6Right enough,`0\" says Mister Stern.  \"`6I expect you've got all sorts of monsters and creatures and things to be getting on with.  The offer remains open, though - I'm here rain or shine.`0\"`n`nYou bid your farewell and head out of the Museum.");
            addnav("Continue");
            addnav("Continue back into the Outpost", "village.php");
            break;
        case "getrelic":
            page_header("Got any Relics?");
            output("You ask if there are any interesting things handy that could help illustrate the local culture.`n`n");
            switch ($session['user']['location']) {
                case "NewHome":
                    output("`0The man behind the desk furrows his brow.  \"`1`iMuseum`i exhibits?  This'll be for that Mister Stern, won't it?`0\"  He rummages in a desk drawer.  \"`1Yup, he's been after some new stuff for his museum for a while now, or so I gather.  Now, let's see...  Ah, maybe this'll do.`0\"  He pulls out what looks like an old service revolver, rusted with age.  \"`1I've been meaning to give this to him for a while.  It's not much good as an actual weapon, but I reckon that's probably the oldest firearm on the whole Island.  Well pre-EMP.  He should like that.`0\"`n`nYou thank the man and make your farewells.");
                    give_item("stern_revolver");
                    set_module_pref("gotnh", 1);
                    break;
                case "Kittania":
                    output("`0The KittyMorph smiles.  \"`1Oh, Mister Stern must have sent you!  Here, you can have this.`0\"  She reaches into her desk drawer and hands you a dead mouse.`n`nYou stare at it for a moment.`n`n\"`1Oh!  Whoops, sorry...`0\" she takes the mouse back from your hand, giggling as she puts it back in the drawer.  \"`1That's not what I meant to give you at all!  Deary me, what on Earth would a human want with one of `ithose`i?  Here.`0\"`n`nShe hands you a dead rat.`n`nWell, it's better than nothing.  Maybe this is how KittyMorphs pay respect to one another.`n`nMaybe.");
                    give_item("stern_rat");
                    set_module_pref("gotki", 1);
                    break;
                case "New Pittsburgh":
                    output("The Zombie behind the desk nods, slowly.  She reaches under her desk, and brings up a brain in a jar.  \"`1He's a lovely man.  He can have this BRAAAAAAAAAAIIINS,`0\" she slurs.  \"`1I was saving it for my lunch, but I'm sure it'd be a good conversation piece.  I know our eating habits differ quite a bit.`0\"`n`nYou nod.  \"`#I'm sure it'll prove very useful, thanks.`0\"`n`nYou leave hastily, in case she changes her mind and decides on a fresh brain instead.");
                    give_item("stern_brain");
                    set_module_pref("gotnp", 1);
                    break;
                case "Squat Hole":
                    output("\"`1Is this for tha' fookin' old geezer in der 'umin town, yeah?`0\"`n`nYou nod.`n`n\"`1Tell 'im 'e can 'ave dis,`0\" says the Midget.  With a loud snort and a cringe-inducing squishing sound, he shifts some phlegm into his mouth and spits into his hand.  He holds it out to you.`n`n\"`1Whassa' fookin' matter, eh?`0\" he asks, seeing that you're less than enthusiastic about his gift.  \"`1I tell yer, you lot've got no fookin' `iclue`i about 'ow we live, do ya?  Thass' a `ivaluable commodity,`i is tha'!  We use it fer all sorts!  This Stern feller, 'e should consider 'imself 'ighly respected fer a gift like dis!`0\"  He looks down at his hand.  \"`1Oh, right.  Never mind, I get yer now.  Sorry mate, I completely forgot me fookin' manners.  I'll get yer a little bag, shall I?`0\"`n`nYou cringe as the Midget pours the contents of his hand into a little sandwich bag, and tosses it to you.  It splats into your hand, mercifully dry but still soft and squishy, and... `iwarm.`i`n`nYou mutter a hasty \"`#Thanks,`0\" and leave quickly before the Midget can give you anything else.");
                    give_item("stern_phlegm");
                    set_module_pref("gotsq", 1);
                    break;
                case "Pleasantville":
                    output("\"`1This would be for Mister Stern, I assume.  Fine fellow.  Very understanding, easy to talk to.  It's a terrible shame about his accident.`0\"  The Mutant behind the desk hesitates.  \"`1Although to be honest, I've no idea what I can give you.`0\"`n`nYou shrug.  \"`#Anything, really.  Anything that makes it easier to understand Mutants.`0\"`n`nThe Mutant's eyes seem to light up.  \"`1I have some poetry.  Would you like to hear it?`0\"`n`nYou shuffle your feet.  \"`#Ah, well, see, thing is, I've really got to -`0\"`n`n\"`1Black is the pit where my heart once lurked,`0\" says the Mutant, reading from a piece of paper pulled from his pocket.  \"`1`iBlack`i is the pupil of my one working eye.`0\"`n`n\"`#Oh, God...`0\"`n`n\"`1`iBlack`i is the stubbed toenail that sprouts from my left ear.  `iBlack`i is the gunge that seeps from the festering hole in my torso.  `iBLACK`i are the teeth within that festering hole, how I long for a toothbrush that will reach!`0\"`n`nYou begin to feel a little faint.`n`n\"`1`iBlack`i is the colour of my `isoul`i, the colour of my `imind`i, the colour of my heavily-altered `iT-shirt`i, the colour of my `iPAIN!`i  `iBlack`i are the sightless, staring eyes that cover my knees and my penis.`0\"`n`nGrey fuzz seems to be seeping in around the edges of your vision.  You can hear a high-pitched whine, but it doesn't drown out the sounds of the Mutant's poetry.`n`n\"`1`iMy penis!`i  Oh, cruel and sadistic fate!  My instrument of `ilove`i, my rod of passion, studded with the `iblack gems`i that drive women `iscreaming`i and `iurinating`i into the night!  The eyes, the `ieyes!`i  They do not see, they can not look in love and wonder upon a newborn babe or a majestic waterfall!  But if you cut me, do I not bleed?  If you poke my penis-eyes, do they not blink as one in soundless anguish?`0\"`n`n\"`#I'M SURE HE'LL LOVE IT!`0\" you scream.  \"`#THANK YOU VERY VERY MUCH!`0\"  You snatch the paper from his hand, and run gibbering out of the hut.");
                    give_item("stern_poetry");
                    set_module_pref("gotpl", 1);
                    break;
                case "Cyber City 404":
                    output("\"`1Affirmative.  The fleshling Stern wishes to create a permament record of your primitive, chemical-based knowledge, yes?  An excellent aspiration, given that your memories are flawed and untrustworthy.`0\"  The Robot behind the desk nods his appreciation.  \"`1I will give you this.`0\"`n`nHe hands over a tiny memory card.  \"`#Oh, thank you very much,`0\" you say.  \"`#He seems to be really into his pre-EMP technology.  What is it, exactly?`0\"`n`n\"`1Oddly enough, the collected thoughts and memories of your home town.  A complete record of every personality, ready to be transplanted into Robot bodies should the need arise.  I believe you are in there somewhere.`0\"`n`nYou stare at the card.  Your entire life, and the lives of those around you, on a memory card smaller than a suppository.  You stuff it moodily into your pocket, mutter something like \"`#Thanks,`0\" and head out of the door, leaving the Robot wondering why the display of his superior technology and mental capacity seemed to lose him a potential friend, rather than make one.`n`nHe shrugs.  It seems appropriate to do so.  He's good at shrugging.  He's practiced in front of a mirror.");
                    give_item("stern_memorycard");
                    set_module_pref("gotcc", 1);
                    break;
                case "AceHigh":
                    output("\"`1You needn't say another word,`0\" says the lady behind the desk, dressed in an immaculate Victorian suit.  \"`1I know what you're here for, and I know who sent you.  Give him this.`0\"`n`nThe green glow around her eyes seems to intensify as she pulls a coin out of her pocket.  She hands it to you, and the light dies away a little.`n`nYou turn it over.  It's an old British penny, one of the really huge ones from the 1940's.  But there's something wrong.  \"`#This is a double-headed one,`0\" you say.`n`n\"`1Flip it,`0\" says the woman, smiling.`n`nYou do as commanded.  When you catch it, both sides show tails.  \"`#Wow, that's really neat!`0\" you say, and flip it again.  It comes up heads on both sides.  \"`#You know, this is probably the best thing I've gotten on this little adventure.`0\"`n`nThe lady nods, watching you flip the coin a third time, clearly enjoying your interest in her artefact.  \"`1It's certainly a fascinating piece.  Full of rather complex equations and Improbabilities.  Each time the faces are reversed, there's a one in seven chance of folding a localised area of time and space, generating a potentially universe-shattering paradox.  Isn't that exciting?`0\"`n`nYou catch the coin and slip it into your pocket.  \"`#I'll just keep this safe in here for now.`0\"");
                    give_item("stern_penny");
                    set_module_pref("gotah", 1);
                    break;
            }
            addnav("Return");
            addnav("Back to the Outpost", "village.php");
            break;
        case "show":
            page_header("Mister Stern");
            set_module_pref("subplotcomplete", 1);
            output("\"`6My goodness!`0\" says Mister Stern, pushing his glasses further up on his nose and examining the array of objects you've just placed on his desk.  \"`6What an excellent find!  Let's see, here...  A dead rat, some phlegm, a rusty pistol, a brain, some sort of memory card, some... goodness, some Mutant poetry from the look of things...`0\"`n`n\"`#Do you think they'll be useful?`0\" you ask, somewhat dubious.`n`n\"`6Oh, yes!  These are superb!`0\" says Mister Stern.  \"`6Oh, and this must be one of those Joker coins!`0\"  He flips it into the air.`n`n\"`6My goodness!`0\" says Mister Stern, pushing his glasses further up on his nose and examining the array of objects you've just placed on his desk.  \"`6What an excellent find!  Let's see, here...  A dead rat, some phlegm, a rusty pistol, a brain, some sort of memory card, some... my goodness, some Mutant poetry from the look of things...`0\"`n`n\"`#Do you think they'll be useful?`0\" you ask, somewhat dubious.`n`n\"`6Oh, yes!  These are superb!`0\" says Mister Stern.  \"`6Oh, and this must be one of those Joker coins!`0\"  He flips it into the air.`n`nYou pull out a cigarette and light it, knowing that there are questions to be asked and answered - like what you're going to do with the rest of your life - but for the moment, at least, you're content to just lie here for a little while.`n`nA metallic creaking sound jars you out of your contemplation. You sit up, staring at the jagged edges of the Improbability Drive's remains, the jagged edges that are now trying to bend themselves back into shape...`n`n\"`6Oh, and this must be one of those Joker coins!`0\"  He flips it into the air.`n`nYou snatch the coin out of the air mid-flip.  \"`#Might want to go easy on that.`0\"`n`n\"`6Oh,`0\" says Mister Stern.  \"`6Yes, I see what you mean.  Gives one a belter of a headache, doesn't it?  Well, listen, I can't thank you enough for all this, but I want to give you your time's worth.`0\"`n`nHe hands you a pack of ten cigarettes.  Result!`n`n\"`#Well, thanks very much,`0\" you say, \"`#and I really should get going.  I've monsters to kill, and I expect you'll be wanting to arrange your exhibits and write up cards for them, and that sort of thing.`0\"`n`n\"`6Indeed, indeed.  Come back any time!  And thank you once again!`0\"");
            delete_item(has_item("stern_revolver"));
            delete_item(has_item("stern_rat"));
            delete_item(has_item("stern_brain"));
            delete_item(has_item("stern_phlegm"));
            delete_item(has_item("stern_poetry"));
            delete_item(has_item("stern_memorycard"));
            delete_item(has_item("stern_penny"));
            $session['user']['gems'] += 10;
            addnav("Continue");
            addnav("Back to the Outpost", "village.php");
            if (is_module_active("medals")) {
                require_once "modules/medals.php";
                medals_award_medal("mister_stern", "Museum Marketeer", "This player helped Mister Stern restore his museum to popularity!", "medal_museumquest.png");
            }
            break;
    }
    page_footer();
}
function skronkypot_run()
{
    global $session;
    page_header("The Skronky Pot");
    switch (httpget("op")) {
        case "examine":
            // have they been introduced to the pleasures of the Skronky Pot?
            if (get_module_pref("skronkyvirgin") == 0) {
                output("`0Two midgets sit smoking around the Skronky Pot.  They give you a wave and a one-fingered salute as they recognise you, and beckon you towards the fetid bucket.`n`n");
            }
            if (get_module_pref("skronkyvirgin") == 1) {
                output("`0`0Two midgets sit smoking around a bucket filled with what appears to be thick yellow custard.`n`nOne of them looks up as you lean in to get a closer look.`n`n\"`^What, mate, you wanna contribute?`0\" he asks in an annoying squeaky voice.  \"`^Give ya twenny-five Req per hack.`0\"`n`n\"`#Contribute?`0\" you ask, bemused.  \"`#I'm not sure I follow you.`0\"`n`n\"`^You thick or summat, dick'ead?  Jus' cough yer lung butter inter the bucket, yer get free money, innit?  It's a valuable commodity, is that.`0\"`n`nWith a horrible realisation dawning upon you, you look into the bucket.  Several cigarette butts are floating inside.  The contents smell like bacon and nicotine.`n`n\"`#Why?  What the hell do you use it for?`0\" you ask, incredulous.`n`n\"`^Makin' fings fer der yoomans.  Soap an' dat.  Cangles.  Cheap ciggies, once we've boiled an' strained der nikkitine out an' mixed it wi' some nettles.  Fookin' posh toss an' s***e, innit.`0\"`n`nYou resist the urge to be violently ill as you ponder what to do.`n`n");
                set_module_pref("skronkyvirgin", 1);
            }
            // evalutate the fullness of the Skronky Pot and warn the player if it's dangerous
            $capacity = get_module_pref("capacity");
            $contents = get_module_pref("contents");
            if ($capacity > $contents + 10) {
                output("Looks like the Skronky Pot's getting pretty full.`n`n");
            }
            //add navs
            addnav("Make a contribution?");
            addnav("Hack your phlegm into the gloriously ghastly Skronky Pot!", "runmodule.php?module=skronkypot&op=ohgodno");
            addnav("My soul's worth more than that.", "village.php");
            break;
        case "ohgodno":
            // have they already coughed up everything they've got?
            // yup
            if (get_module_pref("dailyhacks") > get_module_setting("maxdailyhacks")) {
                output("You cough, and strain, but nothing comes out.  You're done for today.`n`n");
                addnav("I do feel about two pounds lighter...");
                addnav("O?Back to the Outpost", "village.php");
            }
            // nope
            if (get_module_pref("dailyhacks") <= get_module_setting("maxdailyhacks")) {
                output("Getting down on your knees in front of the bucket, you grimly grip its edges and cough and hack until a sizeable chunk of greenish awfulness drops in with a sad, wet \"plop\".`n`n");
                // increment the foulness index
                set_module_setting("contents", get_module_setting("contents") + 1);
                // did they - oh horror of horrors - KNOCK OVER THE SKRONKY POT?
                if (get_module_setting("contents") > get_module_setting("capacity")) {
                    // punish the player
                    output("`0You realise something's wrong.  Time appears to slow down as you sit, frozen in horror, as the Skronky Pot first wobbles, then tips, then, in awful slow-motion, falls over.`n`nIts contents, fouler than anything you'd ever encountered in even your sweatiest, most urine-soaked nightmares, splash liberally over your crotch and thighs.`n`nAs the smell of the fermented bottom portion of the bucket hits you, you pass out and fall onto your back, and into the Skronky Pot's now-liberated contents.`n`nWhen you come to, you remain unaware of your surroundings for a blissful half-second.  When faced with the full horror of what has happened, you immediately and violently lose control of your stomach, bowels and bladder.  Onlookers will talk for years about the explosive humanoid fountain of grief and mourning that came into their lives that day.`n`nAfter a full five minutes of uninterrupted full-body, every-orifice retching, you lie stinking in the baking sun, not daring to contemplate whether this is truly the lowest point in your life, or whether things could possibly get worse.  Then you hear the sound of laughter, and realise that you're surrounded on all sides by pointing, laughing midgets.`n`nYou knocked over the Skronky Pot, and lost all of your Charm points as a result.  Don't worry, Chuck - things can only get better from here.`n`n");
                    $session['user']['charm'] = 0;
                    // reset the contents and capacity
                    $newcapacity = e_rand(0, 100);
                    set_module_setting("capacity", $newcapacity);
                    set_module_setting("contents", 0);
                    if (is_module_active("medals")) {
                        require_once "modules/medals.php";
                        medals_award_medal("tippedskronky", "Skronky Disaster", "This player unfortunately tipped over the Skronky Pot...", "medal_tippedskronky.png");
                    }
                }
                // give them their reward
                $session['user']['gold'] += get_module_setting("reward");
                set_module_pref("dailyhacks", get_module_pref("dailyhacks") + 1);
                output("Eyes streaming, you sit up, and the midget to your left pats you on your back and hands over your reward.`n`n");
                // add their navs so they can get the hell out of here
                addnav("Is that everything?");
                addnav("Wait, I'm not done yet.", "runmodule.php?module=skronkypot&op=ohgodno");
                addnav("Thank God that's over.", "village.php");
            }
            break;
    }
    page_footer();
}
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;
}
function stocks_dohook($hookname, $args)
{
    global $REQUEST_URI;
    global $session;
    $stocks = get_module_setting("victim");
    $capital = getsetting("villagename", LOCATION_FIELDS);
    switch ($hookname) {
        case "village-desc":
            if ($session['user']['location'] != $capital) {
                break;
            }
            $op = httpget("op");
            if ($op == "stocks") {
                // Get rid of the op=stocks bit from the URI
                $REQUEST_URI = preg_replace("/[&?]?op=stocks/", "", $REQUEST_URI);
                $_SERVER['REQUEST_URI'] = preg_replace("/[&?]?op=stocks/", "", $_SERVER['REQUEST_URI']);
                if ($stocks == 0) {
                    output("`n`0You head over to examine the stocks, and wondering how they work, you place your head and hands in the notches for them when SNAP, they clap shut, trapping you inside!`0`n");
                    modulehook("stocksenter");
                } elseif ($stocks != $session['user']['acctid']) {
                    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid='{$stocks}'";
                    $result = db_query_cached($sql, "stocks");
                    $row = db_fetch_assoc($result);
                    output("`n`0You head over to examine the stocks, and out of compassion, you help %s`0 out of the stocks.  ", $row['name']);
                    output("Wondering how they got in there in the first place, you place your own head and hands in them when SNAP, they clap shut, trapping you inside! `0`n");
                    modulehook("stocksenter");
                }
                set_module_setting("victim", $session['user']['acctid']);
                invalidatedatacache("stocks");
            } else {
                $examine = translate_inline("Examine Stocks");
                if ($stocks == 0) {
                    output("`n`0Next to the stables is an empty set of stocks.");
                    rawoutput(" [<a href='village.php?op=stocks'>{$examine}</a>]");
                    output_notl("`0`n");
                    addnav("", "village.php?op=stocks");
                } elseif ($stocks == $session['user']['acctid']) {
                    output("`n`@You are now stuck in the stocks!  All around you, people gape and stare. Small children climb on your back, waving wooden swords, and declaring you to be the slain dragon, with them the victor.  This really grates you because you know you could totally take any one of these kids!  Nearby, artists are drawing caricatures of paying patrons pretending to throw various vegetables at you.`0`n");
                    if (is_module_active("medals")) {
                        require_once "modules/medals.php";
                        medals_award_medal("stocks", "Stock Hog", "This player got stuck in the stocks!", "medal_stockades.png");
                    }
                } else {
                    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid='{$stocks}'";
                    $result = db_query_cached($sql, "stocks");
                    $row = db_fetch_assoc($result);
                    output("`n`0Next to the statue is a set of stocks in which `&%s`0 seems to have become stuck!", $row['name']);
                    output_notl(" [");
                    rawoutput("<a href='village.php?op=stocks'>{$examine}</a>");
                    output_notl("]`0`n");
                    addnav("", "village.php?op=stocks");
                }
            }
            break;
        case "dragonkill":
        case "namechange":
            if ($stocks == $session['user']['acctid']) {
                invalidatedatacache("stocks");
            }
            break;
    }
    return $args;
}
function iitemcrates_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "donation":
            $amt = $args['amt'];
            $donationbonus = floor($args['amt'] / get_module_setting("donationaddition"));
            require_once "modules/iitems/lib/lib.php";
            $allitems = iitems_get_all_item_details();
            $items = array();
            $cratefind = array();
            foreach ($allitems as $localid => $data) {
                if ($data['cratefind']) {
                    $items[$localid] = $data;
                    for ($i = 0; $i < $data['cratefind']; $i++) {
                        $cratefind[] = $localid;
                    }
                }
            }
            $crates = unserialize(get_module_setting("crates"));
            for ($i = 0; $i < $donationbonus; $i++) {
                $crate = array();
                //set a random location
                $x = e_rand(1, get_module_setting("worldmapsizeX", "worldmapen"));
                $y = e_rand(1, get_module_setting("worldmapsizeY", "worldmapen"));
                $loc = array();
                $loc['x'] = $x;
                $loc['y'] = $y;
                $crate['loc'] = $loc;
                //set crate contents
                $numitems = e_rand(get_module_setting("minitems"), get_module_setting("maxitems"));
                for ($a = 0; $a < $numitems; $a++) {
                    $add = e_rand(1, count($cratefind));
                    $crate['contents'][] = $cratefind[$add - 1];
                }
                $crates[] = $crate;
            }
            set_module_setting("crates", serialize($crates));
            break;
        case "worldnav":
            $crates = unserialize(get_module_setting("crates"));
            //debug($crates);
            $ploc = get_module_pref("worldXYZ", "worldmapen");
            if (!is_array($crates)) {
                $crates = array();
            }
            foreach ($crates as $key => $vals) {
                if ($ploc == $vals['loc']['x'] . "," . $vals['loc']['y'] . ",1") {
                    require_once "modules/iitems/lib/lib.php";
                    output("`bYou found something!`b`nYou come across a wooden crate, with a small parachute attached.  You spend a few minutes prying it open.`n`n");
                    foreach ($vals['contents'] as $ckey => $content) {
                        $itemdetails = iitems_get_item_details($content);
                        output("You found a %s!`n", $itemdetails['verbosename']);
                        iitems_give_item($content);
                    }
                    increment_module_pref("cratesfound");
                    $found = get_module_pref("cratesfound");
                    if (is_module_active("medals")) {
                        if ($found > 250) {
                            require_once "modules/medals.php";
                            medals_award_medal("crate1000", "Supreme Crate Finder", "This player has found more than 1000 Supply Crates!", "medal_crategold.png");
                        }
                        if ($found > 50) {
                            require_once "modules/medals.php";
                            medals_award_medal("crate500", "Expert Crate Finder", "This player has found more than 500 Supply Crates!", "medal_cratesilver.png");
                        }
                        if ($found > 10) {
                            require_once "modules/medals.php";
                            medals_award_medal("crate100", "Supreme Crate Finder", "This player has found more than 100 Supply Crates!", "medal_cratebronze.png");
                        }
                    }
                    unset($crates[$key]);
                    set_module_setting("crates", serialize($crates));
                    modulehook("iitems_findcrate");
                    //Break operation - players cannot find more than one item crate in a single move.
                    break;
                }
            }
            break;
        case "newday-runonce":
            require_once "modules/iitems/lib/lib.php";
            $allitems = iitems_get_all_item_details();
            $items = array();
            $cratefind = array();
            foreach ($allitems as $localid => $data) {
                if ($data['cratefind']) {
                    $items[$localid] = $data;
                    for ($i = 0; $i < $data['cratefind']; $i++) {
                        $cratefind[] = $localid;
                    }
                }
            }
            $crates = unserialize(get_module_setting("crates"));
            for ($i = 0; $i < get_module_setting("dailyadditions"); $i++) {
                $crate = array();
                //set a random location
                $x = e_rand(1, get_module_setting("worldmapsizeX", "worldmapen"));
                $y = e_rand(1, get_module_setting("worldmapsizeY", "worldmapen"));
                $loc = array();
                $loc['x'] = $x;
                $loc['y'] = $y;
                $crate['loc'] = $loc;
                //set crate contents
                $numitems = e_rand(get_module_setting("minitems"), get_module_setting("maxitems"));
                for ($a = 0; $a < $numitems; $a++) {
                    $add = e_rand(1, count($cratefind));
                    $crate['contents'][] = $cratefind[$add - 1];
                }
                $crates[] = $crate;
            }
            set_module_setting("crates", serialize($crates));
            break;
    }
    return $args;
}
function worldmapen_run_real()
{
    global $session, $badguy, $pvptimeout, $options, $outdoors, $shady;
    $outdoors = true;
    $op = httpget("op");
    $battle = false;
    if ($op == 'move' && rawurldecode(httpget('oloc')) != get_module_pref('worldXYZ')) {
        debug(get_module_pref('worldXYZ'));
        $op = 'continue';
        httpset('op', $op);
    }
    //	debug("Worldmap running op={$op} ...");
    // handle the admin editor first
    if ($op == "edit") {
        if (!get_module_pref("canedit")) {
            check_su_access(SU_EDIT_USERS);
        }
        if (get_module_setting("worldmapenInstalled") != 1) {
            set_module_setting('worldmapenInstalled', "1");
            worldmapen_defaultcityloc();
        }
        worldmapen_editor();
    }
    if ($op == "destination") {
        $cname = httpget("cname");
        $session['user']['location'] = $cname;
        addnav(array("Enter %s", $cname), "village.php");
        output("`c`4`bYou've Arrived in %s.`b`0`c`n", $cname);
        output("`cYou have reached the outer gates of the city.`c");
    }
    if (!get_module_setting("worldmapenInstalled")) {
        page_header("A rip in the fabric of space and time");
        require_once "lib/villagenav.php";
        villagenav();
        output("`^The admins of this game haven't yet finished installing the worldmapen module.");
        output("You should send them a petition and tell them that they forgot to generate the initial locations of the cities.");
        output("Until then, you are kind of stuck here, so I hope you like where you are.`n`n");
        output("After all, remember:`nWherever you go, there you are.`0");
        page_footer();
    }
    $subop = httpget("subop");
    $act = httpget("act");
    $type = httpget("type");
    $name = httpget("name");
    $direction = httpget("dir");
    $su = httpget("su");
    $buymap = httpget("buymap");
    $worldmapCostGold = get_module_setting("worldmapCostGold");
    $pvp = httpget('pvp');
    require_once "lib/events.php";
    if ($session['user']['specialinc'] != "" || httpget("eventhandler")) {
        $in_event = handle_event(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue&", "Travel");
        if ($in_event) {
            addnav("Continue", "runmodule.php?module=worldmapen&op=continue");
            module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
            page_footer();
        }
    }
    page_header("Journey");
    //is the player looking at chat?
    if (httpget('comscroll') || httpget('comscroll') === 0 || httpget('comment') || httpget('refresh')) {
        $chatoverride = 1;
        require_once "lib/commentary.php";
        addcommentary();
        $loc = get_module_pref("worldXYZ", "worldmapen");
        viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
    }
    if ($op == "beginjourney") {
        $loc = $session['user']['location'];
        $x = get_module_setting($loc . "X");
        $y = get_module_setting($loc . "Y");
        $z = get_module_setting($loc . "Z");
        $xyz = $x . "," . $y . "," . $z;
        set_module_pref("worldXYZ", $xyz);
        output("`b`&The gates of %s`& stand closed behind you.`0`b`n`n", $session['user']['location']);
        $num = e_rand(1, 5);
        $msg = get_module_setting("leaveGates{$num}");
        output("`c`n`^%s`0`n`c`n", $msg);
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "continue") {
        checkday();
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
        //Turns Trading bit, added by CavemanJoe
    } elseif ($op == "tradeturn") {
        checkday();
        $pointstrade = get_module_setting("turntravel");
        output("You can trade one Turn for %s Travel Points.  Do you want to do this now?", $pointstrade);
        addnav("Yes, use a turn", "runmodule.php?module=worldmapen&op=tradeturnconfirm");
        addnav("No, cancel and return to the map", "runmodule.php?module=worldmapen&op=continue");
    } elseif ($op == "tradeturnconfirm") {
        $pointstrade = get_module_setting("turntravel");
        output("By conserving energy that you would have otherwise used for fighting creatures, you have gained %s Travel Points.", $pointstrade);
        $session['user']['turns']--;
        $ttoday = get_module_pref("traveltoday", "cities");
        set_module_pref("traveltoday", $ttoday - $pointstrade, "cities");
        addnav("Continue", "runmodule.php?module=worldmapen&op=continue");
    } elseif ($op == "move" && !$chatoverride) {
        checkday();
        if ($session['user']['location'] != 'World') {
            set_module_pref("lastCity", $session['user']['location']);
            $session['user']['location'] = "World";
        }
        $session['user']['restorepage'] = "runmodule.php?module=worldmapen&op=continue";
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        if ($direction == "north") {
            $y += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "northeast") {
            $y += 1;
            $x += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "northwest") {
            $y += 1;
            $x -= 1;
        }
        if ($direction == "east") {
            $x += 1;
        }
        if ($direction == "south") {
            $y -= 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "southeast") {
            $y -= 1;
            $x += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "southwest") {
            $y -= 1;
            $x -= 1;
        }
        if ($direction == "west") {
            $x -= 1;
        }
        $terraincost = worldmapen_terrain_cost($x, $y, $z);
        $encounterbase = worldmapen_encounter($x, $y, $z);
        $encounterchance = get_module_pref("encounterchance");
        $encounter = $encounterbase * $encounterchance / 100;
        debug($encounterbase . " * " . $encounterchance . " / 100 = " . $encounter);
        $ttoday = get_module_pref("traveltoday", "cities");
        set_module_pref("traveltoday", $ttoday + $terraincost, "cities");
        worldmapen_terrain_takestamina($x, $y, $z);
        $xyz = $x . "," . $y . "," . $z;
        set_module_pref("worldXYZ", $xyz);
        // $randchance = get_module_setting("randchance");
        // if (e_rand(0,100) < $randchance){
        // $eventravel = "travel";
        // set_module_setting("randevent", $eventravel);
        // }else{
        // $eventravel = "forest";
        // set_module_setting("randevent", $eventravel);
        // }
        //Extra Gubbins pertaining to trading Turns for Travel, added by Caveman Joe
        $useturns = get_module_setting("useturns");
        $allowzeroturns = get_module_setting("allowzeroturns");
        $playerturns = $session['user']['turns'];
        $proceed = 1;
        //the Proceed value is used when the player has hit a monster, to make sure it's okay to actually run the event/monster.
        if ($playerturns == 0 && $allowzeroturns == 0) {
            $proceed = 0;
        }
        if (e_rand(0, 100) < $encounter && $su != '1' && $proceed == 1 && !$chatoverride) {
            // They've hit a monster!
            if (module_events(get_module_setting("randevent"), get_module_setting("wmspecialchance"), "runmodule.php?module=worldmapen&op=continue&") != 0) {
                page_header("Something Special!");
                if (checknavs()) {
                    page_footer();
                } else {
                    // Reset the special for good.
                    $session['user']['specialinc'] = "";
                    $session['user']['specialmisc'] = "";
                    $skipvillagedesc = true;
                    $op = "";
                    httpset("op", "");
                    addnav("Continue", "runmodule.php?module=worldmapen&op=continue&");
                    module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
                    page_footer();
                }
            }
            //Check if we're removing a turn when the player encounters a monster, and if so, do it
            if ($useturns == 1) {
                $session['user']['turns']--;
            }
            //Fix to only search for Forest type creatures, added by CavemanJoe
            $sql = "SELECT * FROM " . db_prefix("creatures") . " WHERE creaturelevel = '{$session['user']['level']}' AND forest = 1 ORDER BY rand(" . e_rand() . ") LIMIT 1";
            $result = db_query($sql);
            restore_buff_fields();
            if (db_num_rows($result) == 0) {
                // There is nothing in the database to challenge you,
                // let's give you a doppleganger.
                $badguy = array();
                $badguy['creaturename'] = "An evil doppleganger of " . $session['user']['name'];
                $badguy['creatureweapon'] = $session['user']['weapon'];
                $badguy['creaturelevel'] = $session['user']['level'];
                $badguy['creaturegold'] = rand($session['user']['level'] * 15, $session['user']['level'] * 30);
                $badguy['creatureexp'] = round($session['user']['experience'] / 10, 0);
                $badguy['creaturehealth'] = $session['user']['maxhitpoints'];
                $badguy['creatureattack'] = $session['user']['attack'];
                $badguy['creaturedefense'] = $session['user']['defense'];
            } else {
                $badguy = db_fetch_assoc($result);
                require_once "lib/forestoutcomes.php";
                $badguy = buffbadguy($badguy);
            }
            calculate_buff_fields();
            $badguy['playerstarthp'] = $session['user']['hitpoints'];
            $badguy['diddamage'] = 0;
            $badguy['type'] = 'world';
            //debug("Worldmap run.php is debugging badguy");
            //debug($badguy);
            $session['user']['badguy'] = createstring($badguy);
            $battle = true;
        } else {
            // $args = modulehook("count-travels", array('available'=>0, 'used'=>0));
            // $free = max(0, $args['available'] - $args['used']);
            // if (get_module_setting("usestamina")==1){
            // output("`c`nYou think to yourself what a nice day it is.`c`n");
            // } else {
            // output("`c`nYou think to yourself what a nice day it is.`nYou have %s Travel Points remaining.%s`c`n",$free);
            // }
            $free = 100;
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            if (!$chatoverride) {
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
            }
            worldmapen_viewmapkey(true, false);
            module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
        }
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "gypsy") {
        $outdoors = false;
        if ($buymap == '') {
            output("`5\"`!Ah, yes.  An adventurer.  I could tell by looking into your eyes,`5\" the gypsy says.`n");
            output("\"`!Many people have lost their way while journeying without a guide such as this.");
            output("It will let you see all the world.`5\"`n");
            output("\"`!Yes, yes.  Let's see...  What sort of price should we put on this?");
            output("Hmm.  How about `^%s`! gold?`5\"", $worldmapCostGold);
            addnav(array("Buy World Map `0(`^%s gold`0)", $worldmapCostGold), "runmodule.php?module=worldmapen&op=gypsy&buymap=yes");
            addnav("Forget it", "village.php");
        } elseif ($buymap == 'yes') {
            if ($session['user']['gold'] < $worldmapCostGold) {
                output("`5\"`!What do you take me for?  A blind hag?  Come back when you have the money`5\"");
                addnav("Leave quickly", "village.php");
            } else {
                output("`5\"`!Enjoy your newfound sight,`5\"  the gypsy says as she walks away to greet some patrons that have just strolled in.");
                $session['user']['gold'] -= $worldmapCostGold;
                set_module_pref("worldmapbuy", 1);
                require_once "lib/villagenav.php";
                villagenav();
            }
        }
    } elseif ($op == "viewmap") {
        worldmapen_determinenav();
        worldmapen_viewmap(true);
        if (is_module_active("medals")) {
            require_once "modules/medals.php";
            medals_award_medal("boughtmap", "Bearer of the Map", "This player purchased the World Map from the Comms Tent!", "medal_islandmap.png");
        }
    } elseif ($op == "camp") {
        if ($session['user']['loggedin']) {
            $session['user']['loggedin'] = 0;
            $session['user']['restorepage'] = "runmodule.php?module=worldmapen&op=wake";
            saveuser();
            invalidatedatacache("charlisthomepage");
            invalidatedatacache("list.php-warsonline");
        }
        $session = array();
        redirect("index.php", "Redirected to Index from World Map");
    } elseif ($op == "wake") {
        if ($session['user']['hitpoints'] > 0) {
            // runmodule.php calls do_forced_nav,
            $session['user']['alive'] = true;
            // and that resets ['alive'], so
        } else {
            // this is from common.php to make sure
            $session['user']['alive'] = false;
            // the player is not half-dead after log-in.
        }
        output("You yawn and stretch and look around your campsite.`n`n");
        output("Ah, how wonderful it is to sleep in the open air!`n");
        output("The world seems full of possibilities today.`n`n");
        checkday();
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "combat") {
        // Okay, we've picked a person to fight.
        require_once "lib/pvpsupport.php";
        $name = httpget("name");
        $badguy = setup_target($name);
        $failedattack = false;
        if ($badguy === false) {
            output("`0`n`nYou survey the area again.`n");
            worldmapen_determinenav();
        } else {
            $battle = true;
            $badguy['type'] = 'pvp';
            //$options['type'] = 'pvp';
            $session['user']['badguy'] = createstring($badguy);
            $session['user']['playerfights']--;
        }
    } elseif ($op == "fight" || $op == "run") {
        if (!$chatoverride && !httpget("frombio")) {
            $battle = true;
        } else {
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            worldmapen_viewmapkey(true, false);
        }
        // $args = modulehook("count-travels", array('available'=>0,'used'=>0));
        // $free = max(0, $args['available'] - $args['used']);
        // if (get_module_setting("usestamina")==1){
        $free = 100;
        // }
        if ($op == "run" && !$pvp) {
            if (!$chatoverride) {
                if (e_rand(1, 5) < 3 && $free) {
                    // They managed to get away.
                    output("You set off running at a breakneck pace!`n`n");
                    output("A short time later, you have managed to avoid your opponent, so you stop to catch your breath.");
                    $ttoday = get_module_pref("traveltoday", "cities");
                    set_module_pref("traveltoday", $ttoday + 1, "cities");
                    output("As you look around, you realize that all you really managed was to run in circles.");
                    $battle = false;
                    worldmapen_determinenav();
                    if (get_module_setting("smallmap")) {
                        worldmapen_viewsmallmap();
                    }
                    require_once "lib/commentary.php";
                    addcommentary();
                    $loc = get_module_pref("worldXYZ", "worldmapen");
                    viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
                    worldmapen_viewmapkey(true, false);
                } else {
                    output("You try to run, but you don't manage to get away!`n");
                    $op = "fight";
                    httpset('op', $op);
                }
            } else {
                if (get_module_setting("smallmap")) {
                    worldmapen_viewsmallmap();
                }
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
                worldmapen_determinenav();
                worldmapen_viewmapkey(true, false);
            }
        } elseif ($op == "run" && $pvp) {
            output("Your pride prevents you from running");
            $op = "fight";
            httpset('op', $op);
        }
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    }
    if ($battle) {
        include_once "battle.php";
        if (isset($enemies) && !$pvp) {
            $badguy =& $enemies;
        }
        if ($victory) {
            if ($pvp) {
                require_once "lib/pvpsupport.php";
                $aliveloc = $badguy['location'];
                pvpvictory($badguy, $aliveloc, $options);
                addnews("`4%s`3 defeated `4%s`3 while they were camped in the wilderness.`0", $session['user']['name'], $badguy['creaturename']);
                $badguy = array();
            } else {
                if (!$chatoverride && !httpget('frombio')) {
                    //is talking
                    require_once "lib/forestoutcomes.php";
                    forestvictory($badguy, false);
                }
            }
            //has just beaten a badguy
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            if (!$chatoverride) {
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
            }
            worldmapen_viewmapkey(true, false);
        } elseif ($defeat) {
            // Reset the players body to the last city they were in
            $session['user']['location'] = get_module_pref('lastCity');
            if ($pvp) {
                require_once "lib/pvpsupport.php";
                require_once "lib/taunt.php";
                $killedloc = $badguy['location'];
                $taunt = select_taunt();
                pvpdefeat($badguy, $killedloc, $taunt, $options);
                addnews("`4%s`3 was defeated while attacking `4%s`3 as they were camped in the wilderness.`0`n%s", $session['user']['name'], $badguy['creaturename'], $taunt);
            } else {
                require_once "lib/forestoutcomes.php";
                forestdefeat($badguy, "in the wild");
            }
            output("`n`n`&You are sure that someone, sooner or later, will stumble over your corpse and return it to %s`& for you.`0", $session['user']['location']);
        } else {
            require_once "lib/fightnav.php";
            $allow = true;
            $extra = "";
            if ($pvp) {
                $allow = false;
                $extra = "pvp=1&";
            }
            fightnav($allow, $allow, "runmodule.php?module=worldmapen&{$extra}");
        }
    }
    page_footer();
}
function timedcombat_dohook($hookname, $args)
{
    global $session, $last_timestamp;
    switch ($hookname) {
        case "creatureencounter":
        case "gravefight-start":
            set_module_pref("willing", 0);
            if (!get_module_pref("able")) {
                if ($session['user']['donation'] >= 2000) {
                    set_module_pref("able", true);
                }
            }
            break;
        case "battle":
            if (get_module_pref("able")) {
                if (!get_module_pref("willing")) {
                    $target = e_rand(4, 7);
                    rawoutput("<table cellpadding=0 cellspacing=0><tr><td width=\"220px\"><div style=\"width:200; height:25; background:url(/images/timedcombat-background.png); border:1px solid #000000;\"></div></td><td>");
                    set_module_pref("target", $target);
                    output("Next target: `b%s seconds`b", $target);
                    rawoutput("</td></tr></table>");
                    set_module_pref("willing", true);
                    $now = microtime(true);
                    set_module_pref("lasttime", $now);
                } else {
                    $now = microtime(true);
                    $last = get_module_pref("lasttime");
                    $target = get_module_pref("target");
                    $offset = round($now - $last, 1);
                    $offset -= $target;
                    if ($offset < 60) {
                        $pass = 0;
                        while ($offset > $target / 2) {
                            $offset -= $target;
                            $pass++;
                        }
                        $pixeloffset = 91 + $offset * 20;
                        if ($pixeloffset < 4) {
                            $pixeloffset = 4;
                        }
                        if ($pixeloffset > 180) {
                            $pixeloffset = 180;
                        }
                        rawoutput("<table cellpadding=0 cellspacing=0><tr><td width=\"220px\"><div style=\"width:200; height:25; background:url(/images/timedcombat-background.png); border:1px solid #000000;\"><div style=\"width: 196; height: 21; padding-left:10px; background: url(/images/timedcombat-pointer.png); background-repeat: no-repeat; line-height: 25px; background-position: " . $pixeloffset . "px\"></div></div></td><td>");
                        if ($offset == 1 || $offset == -1) {
                            $sdisp = "Second";
                        } else {
                            $sdisp = "Seconds";
                        }
                        if ($pass > 1) {
                            output("Repeater: ");
                        }
                        if ($offset > 0.1) {
                            output("`b%s %s late`b / ", $offset, $sdisp);
                            clear_module_pref("chain");
                        } else {
                            if ($offset < -0.1) {
                                output("`b%s %s early`b / ", $offset * -1, $sdisp);
                                clear_module_pref("chain");
                            } else {
                                output("`b`@Perfect!`0`b / ");
                                increment_module_pref("hits");
                                increment_module_pref("chain");
                                $chain = get_module_pref("chain");
                                if ($chain > 1) {
                                    output("`b`@%s-chain!`b`0 / ", $chain);
                                    if ($chain > get_module_pref("maxchain")) {
                                        set_module_pref("maxchain", $chain);
                                        output("`b`@New Personal Chain Record!`0`b / ");
                                        if (get_module_pref("maxchain") == 4) {
                                            $subj = "Congratulations!";
                                            $body = "You've just got your first four-chain, and now you can teach Timed Combat to other players!  You can teach a maximum of one player per Game Day.  To teach a player, ensure that you're both logged in and in the same chatspace, then click on their Bio and you should see the option to teach them the new skill.  Have fun!";
                                            require_once "lib/systemmail.php";
                                            systemmail($session['user']['acctid'], $subj, $body);
                                        }
                                    }
                                    if (is_module_active("medals")) {
                                        if ($chain >= 25) {
                                            require_once "modules/medals.php";
                                            medals_award_medal("timedcombat_chain_25", "Master of the Metronome", "This player got a 25-Chain in Timed Combat!", "medal_timedchaingold.png");
                                        } else {
                                            if ($chain >= 10) {
                                                require_once "modules/medals.php";
                                                medals_award_medal("timedcombat_chain_10", "Split-Second Savant", "This player got a 10-Chain in Timed Combat!", "medal_timedchainsilver.png");
                                            } else {
                                                if ($chain >= 5) {
                                                    require_once "modules/medals.php";
                                                    medals_award_medal("timedcombat_chain_5", "Perfect Timing", "This player got a 5-Chain in Timed Combat!", "medal_timedchainbronze.png");
                                                }
                                            }
                                        }
                                    }
                                }
                                switch (httpget('auto')) {
                                    case "five":
                                        $rounds = 5;
                                        break;
                                    case "ten":
                                        $rounds = 10;
                                        break;
                                    case "full":
                                        $rounds = -1;
                                        break;
                                    default:
                                        $rounds = 1;
                                        break;
                                }
                                apply_buff('timedcombat', array("roundmsg" => "`0Your perfect timing really makes a difference!", "rounds" => $rounds, "atkmod" => 2, "defmod" => 2, "expireafterfight" => 1, "schema" => "module-timedcombat"));
                            }
                        }
                        $newtarget = e_rand(4, 7);
                        set_module_pref("target", $newtarget);
                        output("Next target: `b%s seconds`b", $newtarget);
                        rawoutput("</td></tr></table>");
                    }
                    set_module_pref("lasttime", $now);
                }
            }
            break;
    }
    return $args;
}