addnav("Navigation");
     addnav("Return to the camp", "mercenarycamp.php?skip=1");
 } else {
     if ($op == "buy") {
         $id = httpget('id');
         $sql = "SELECT * FROM " . db_prefix("companions") . " WHERE companionid = {$id}";
         $result = db_query($sql);
         if ($row = db_fetch_assoc($result)) {
             $row['attack'] = $row['attack'] + $row['attackperlevel'] * $session['user']['level'];
             $row['defense'] = $row['defense'] + $row['defenseperlevel'] * $session['user']['level'];
             $row['maxhitpoints'] = $row['maxhitpoints'] + $row['maxhitpointsperlevel'] * $session['user']['level'];
             $row['hitpoints'] = $row['maxhitpoints'];
             $row = modulehook("alter-companion", $row);
             $row['abilities'] = @unserialize($row['abilities']);
             require_once "lib/buffs.php";
             if (apply_companion($row['name'], $row)) {
                 output("`QYou hand over `^%s gold`Q and `%%s %s`Q.`n`n", (int) $row['companioncostgold'], (int) $row['companioncostgems'], translate_inline($row['companioncostgems'] == 1 ? "gem" : "gems"));
                 if (isset($row['jointext']) && $row['jointext'] > "") {
                     output($row['jointext']);
                 }
                 $session['user']['gold'] -= $row['companioncostgold'];
                 $session['user']['gems'] -= $row['companioncostgems'];
                 debuglog("has spent {$row['companioncostgold']} gold and {$row['companioncostgems']} gems on hiring a mercenary ({$row['name']}).");
             } else {
                 // applying the companion failed. Most likely they already have more than enough companions...
                 tlschema($schemas['toomanycompanions']);
                 if (is_array($texts['toomanycompanions'])) {
                     foreach ($texts['toomanycompanions'] as $toomanycompanions) {
                         output_notl(sprintf_translate($toomanycompanions));
                     }
                 } else {
function onslaught_getcompanion()
{
    global $session;
    $chance = e_rand(0, 100);
    //$chance = 100; //debug
    switch ($session['user']['location']) {
        case "NewHome":
            $nhchance = e_rand(0, 100);
            if ($chance > 80 && $nhchance > 50 && !onslaught_hascompanion() && !onslaught_hadcompanion("stern")) {
                // Mister Stern
                apply_companion('stern', array("name" => "Mister Stern", "hitpoints" => round($session['user']['hitpoints'] * 0.4), "maxhitpoints" => round($session['user']['maxhitpoints'] * 0.4), "attack" => round($session['user']['attack'] * 0.6), "defense" => round($session['user']['defence'] * 0.6), "dyingtext" => "`0Mister Stern catches a hard blow to his stomach and doubles over, fighting for breath.`n`n\"`#Are you okay?`0\" you call to him, knowing the answer before you even ask.  Before Mister Stern can reply, however, Corporal Punishment has appeared from seemingly out of nowhere and picked up the slender man in a fireman's lift.`n`n\"`@DON'T YOU WORRY!`0\" he shouts.  \"`@YOU keep on with the MONSTERS, let ME worry about HAVELOCK here!`0\"  With that, he disappears into the fray with Stern draped across his shoulder, his pistols clearing a nice path for him towards the hospital tent.`n", "abilities" => array("fight" => true), "ignorelimit" => true), true);
                $info = @unserialize(get_module_pref("info"));
                $info['companion_escapetext'] = "`0Mister Stern pats his left pocket.  \"`6Oh, damn and blast!`0\"`n`n\"`#What is it?`0\" you shout over the roar of battle.`n`nMister Stern frowns.  \"`6I think I'm out of bullets.`0\"`n`n\"`#No problem,`0\" you shout back.  \"`#Pull back for now - if you find any more, you know where to find me!`0\"`n`n\"`6Right-ho,`0\" says Mister Stern, and turns to limp back into the Museum.`n";
                $info['companions_this_onslaught']['stern'] = 1;
                set_module_pref("info", serialize($info));
                return "You turn from the body of the beast to which you just laid waste, only to see Mister Stern drawing a familiar-looking rusty service revolver!  He levels it at a point between your knees and fires, putting a bullet right between the eyes of the creature reaching up to swipe at your back - the creature that up to a second ago you were quite sure was dead.  It convulsces once and lies still, crosseyed.  You look back towards Mister Stern.`n`n\"`#I thought that thing was too old and rusty to even `iwork`i!`0\"`n`n\"`6So did I,`0\" says Mister Stern, looking down in amazement at the revolver.  He looks up towards you again, and his eyes focus on something just behind and to your right.`n`n\"`6Look out!`0\"`n`n";
            } else {
                if ($chance > 80 && $nhchance < 50 && !onslaught_hascompanion() && !onslaught_hadcompanion("punishment")) {
                    //Corporal Punishment
                    apply_companion('punishment', array("name" => "Corporal Punishment", "hitpoints" => round($session['user']['hitpoints'] * 2), "maxhitpoints" => round($session['user']['maxhitpoints'] * 2), "attack" => round($session['user']['attack'] * 2), "defense" => round($session['user']['defence'] * 2), "dyingtext" => "`0Corporal Punishment falls to his knees, blood staining his uniform.  \"`2DAMN IT!  I'm out of HITPOINTS!`0\"  He drags himself to his feet.  \"`2LUCKILY, if I were to DIE then that would DISRUPT the GAME CONTINUITY!  `iAND WE CAN'T HAVE THAT NOW CAN WE!`i`0\"  He turns and flees, leaving you alone with the creature.  You shrug at each other before resuming your respective combat stances.`n", "abilities" => array("fight" => true), "ignorelimit" => true), true);
                    $info = @unserialize(get_module_pref("info"));
                    $info['companion_escapetext'] = "`0Corporal Punishment laughs a braying, screaming laugh as he empties his revolvers into the carcass, blasting away chunks of monster so large that after a few seconds little more than a lumpy puddle remains.  Then he spins around and runs off.`n`n\"`#Where the bloody hell are you going?!\"`n`n\"`2FUNCTION ONSLAUGHT_COMPANION_ESCAPE WAS CALLED!`0\" he shouts back.  \"`2GAME BALANCE, SORRY!`0\"`n`n\"`#`iWEIRDO!`i`0\" you shout to his retreating form as he disappears into the melee.`n";
                    $info['companions_this_onslaught']['punishment'] = 1;
                    set_module_pref("info", serialize($info));
                    return "\"`2MARVELLOUS!`0\"`n`nYou spin around.  Corporal Punishment stands before you.  \"`2EXCELLENT job, young RECRUIT!  I believe I will ASSIST you for a short PERIOD, in order to help ALLEVIATE the problems with GAME BALANCE involved in making you fight multiple MONSTERS in `iSEQUENCE`i without the benefit of HEALING between FIGHTS!`0\"  His moustache jiggles obscenely.`n`n\"`#What in the everloving `ihell`i are you talking about?`0\"`n`n\"`i`2THIS!`i`0\" laughs Corporal Punishment, pulling a pair of hilariously oversized revolvers from somewhere inside his jacket.`n`n";
                }
            }
            break;
        case "Kittania":
            break;
        case "New Pittsburgh":
            break;
        case "Squat Hole":
            break;
        case "Pleasantville":
            break;
        case "Cyber City 404":
            break;
        case "AceHigh":
            break;
        case "Improbable Central":
            break;
    }
}