function dwshacks_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "dwellings-list-type":
            addnav("Show Only Types");
            addnav(array("%s", translate_inline(ucfirst(get_module_setting("dwnameplural", "dwshacks")))), "runmodule.php?module=dwellings&op=list&showonly=dwshacks&ref={$args['ref']}&sortby={$args['sortby']}&order={$args['order']}");
            break;
        case "dwellings-list-interact":
            if ($args['type'] == "dwshacks" && $args['status'] == 1 && get_module_setting("maxkeys") == 123456789) {
                addnav("", "runmodule.php?module=dwellings&op=enter&dwid={$args['dwid']}");
                $tress = translate_inline("Tresspass");
                rawoutput("<a href='runmodule.php?module=dwellings&op=enter&dwid={$args['dwid']}'>{$tress}</a>");
            }
            break;
        case "dwellings-manage":
            $dwid = $args['dwid'];
            if (get_module_setting("maxkeys") == 123456789 && $args['type'] == "dwshacks") {
                blocknav("runmodule.php?module=dwellings&op=keys&dwid={$dwid}");
            }
            break;
        case "dwellings":
            if (get_module_objpref("city", $args['cityid'], "showdwshacks")) {
                output("  Along the narrow pathway, precariously placed wood planks are nailed and leaning on each other in a fashion that only leaves you to assume they are supposed to be %s.`0", translate_inline(get_module_setting("dwnameplural")));
                if ($args['allowbuy'] == 1 && $session['user']['dragonkills'] >= get_module_setting("dkreq")) {
                    $cityid = $args['cityid'];
                    addnav("Options");
                    addnav(array("Establish a %s", translate_inline(ucfirst(get_module_setting("dwname", "dwshacks")))), "runmodule.php?module=dwellings&op=buy&type=dwshacks&subop=presetup&cityid={$cityid}");
                }
            }
            break;
    }
    return $args;
}
function creatureaddon_run()
{
    global $session, $args;
    $op = httpget('op');
    $header = $args['creaturename'] . " Description";
    popup_header($header);
    $description = get_module_objpref("creatures", $args['creatureid'], "description");
    output($description);
    popup_footer();
}
function iitems_eboy_gypsy_run()
{
    global $session;
    page_header("eBoy's Price Chart");
    require_once "modules/iitems/lib/lib.php";
    $cost = get_module_setting("cost", "iitems_eboy_gypsy");
    if ($cost == 1) {
        $p = "Cigarette";
    } else {
        $p = "Cigarettes";
    }
    if ($session['user']['gems'] >= $cost) {
        $session['user']['gems'] -= $cost;
        output("`5You hand over the %s and the old man chuckles.  \"`!Aaah, thank ye kindly.  Now, here we are!  I'd recommend you write these down.  Now mark my words - these prices fluctuate by the `iminute`i!  That eBoy, he's a crafty bastard, y'see.  He sells things for whatever people are willing to buy them for, and not one penny less!  Even if that means putting his prices up the `isecond`i someone buys something!`5\"`n`nHe reaches under his desk and brings up a clattering rectangular machine made out of wood and brass, about the size of a fat telephone directory.  A radio antenna protrudes from one corner.`n`nTrue to his word, the spinning reels show the prices of every commodity in every outpost.  You spend a few minutes studying the readout.`n`n", $p);
        $sql = "select * from " . db_prefix("cityprefs");
        $result = db_query($sql);
        for ($i = 0; $i < db_num_rows($result); $i++) {
            $row = db_fetch_assoc($result);
            $cid = $row['cityid'];
            $name = $row['cityname'];
            $eboy = unserialize(get_module_objpref("city", $cid, "eboytrades-intelligent", "iitems_eboy_intelligent"));
            output("`b`0%s`b`n", $name);
            rawoutput("<table border=0 cellpadding=3 cellspacing=2><tr class=\"trdark\"><td>Item</td><td>Buying at</td><td>Selling at</td><td>Stock</td></tr>");
            $classcount = 1;
            foreach ($eboy as $key => $details) {
                $itemdetails = iitems_get_item_details($key);
                if ($details['price'] < 10) {
                    $details['price'] = 10;
                }
                $eboy[$key]['price'] = $details['price'];
                if ($details['stock'] < 3) {
                    $buy = round($details['price'] * 0.5);
                } else {
                    $buy = round($details['price'] * 0.7);
                }
                $classcount++;
                $class = $classcount % 2 ? "trdark" : "trlight";
                $dname = $itemdetails['verbosename'];
                $dsell = number_format($details['price']);
                $dbuy = number_format($buy);
                $dstock = number_format($details['stock']);
                rawoutput("<tr class='{$class}'><td>{$dname}</td><td align=\"center\">{$dbuy}</td><td align=\"center\">{$dsell}</td><td align=\"center\">{$dstock}</td></tr>");
            }
            rawoutput("</table>");
            output("`n`n");
        }
    } else {
        output("`5You enthusiastically agree to the price, before realising that you don't actually have that many cigarettes.  Whoops.");
    }
    addnav("Leave");
    addnav("Return to the Outpost", "village.php");
    page_footer();
    return true;
}
function dwellingscostsp_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "dwellings-buy-valuecheck":
            $typeid = get_module_setting("typeid", $args['type']);
            $paidsp = abs((int) httppost('paidsp'));
            if ($paidsp < 0) {
                $paidsp = 0;
            }
            $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
            if ($pointsavailable < $paidsp) {
                $args['allowpay'] = 0;
                blocknav("runmodule.php?module=dwellings&op=build&type=" . $args['type'] . "&dwid=" . $args['dwid'] . "");
                output("`nYou do not have that many site points.");
            } elseif ($paidsp > get_module_objpref("dwellingtypes", $typeid, "spcost") - get_module_objpref("dwellings", $args['dwid'], "spspent")) {
                $args['allowpay'] = 0;
                blocknav("runmodule.php?module=dwellings&op=build&type=" . $args['type'] . "&dwid=" . $args['dwid'] . "");
                output("`nYou have tried to spend more site points than you need to.");
            }
            break;
        case "dwellings-buy-setup":
            $typeid = get_module_setting("typeid", $args['type']);
            $paidsp = abs((int) httppost('paidsp'));
            if ($paidsp < 0) {
                $paidsp = 0;
            }
            $spent = get_module_objpref("dwellings", $args['dwid'], "spspent") + $paidsp;
            set_module_objpref("dwellings", $args['dwid'], "spspent", $spent);
            $session['user']['donationspent'] += $paidsp;
            if ($spent != get_module_objpref("dwellingtypes", $typeid, "spcost")) {
                $args['finished'] = 0;
            }
            break;
        case "dwellings-pay-costs":
            $typeid = get_module_setting("typeid", $args['type']);
            $costsp = get_module_objpref("dwellingtypes", $typeid, "spcost") - get_module_objpref("dwellings", $args['dwid'], "spspent");
            if ($costsp) {
                output("`#%s Site Points`0`n", $costsp);
            }
            break;
        case "dwellings-pay-input":
            $typeid = get_module_setting("typeid", $args['type']);
            $costsp = get_module_objpref("dwellingtypes", $typeid, "spcost") - get_module_objpref("dwellings", $args['dwid'], "spspent");
            $sp = translate_inline("Site Points");
            if ($costsp) {
                rawoutput("{$sp}: <input id='input' name='paidsp' width=5><br>");
            }
            break;
    }
    return $args;
}
function uniqueforests_dohook($hookname, $args)
{
    global $session;
    require_once "modules/cityprefs/lib.php";
    $cityid = get_cityprefs_cityid("location", $session['user']['location']);
    switch ($hookname) {
        case "collect-events":
            if (get_module_objpref("city", $cityid, "use")) {
                foreach ($args as $index => $event) {
                    $event['rawchance'] = 0;
                    $events[$index] = $event;
                }
                $args = $events;
            }
            break;
        case "village":
            if (get_module_objpref("city", $cityid, "use")) {
                addnav($args['gatenav']);
                $name = get_module_objpref("city", $cityid, "name");
                blocknav("forest.php");
                addnav(array("%s", $name), "forest.php?location=uniqueforests");
            }
            break;
        case "header-forest":
            if (httpget('location') == "uniqueforests" || get_module_objpref("city", $cityid, "use")) {
                if (httpget('op') == "") {
                    global $block_new_output;
                    $block_new_output = true;
                }
                blocknav("runmodule.php", true);
                blocknav("healer.php", true);
                tlschema("module-uniqueforests");
            }
            break;
        case "footer-forest":
            if (httpget('location') == "uniqueforests" || get_module_objpref("city", $cityid, "use")) {
                $name = get_module_objpref("city", $cityid, "name");
                page_header(color_sanitize($name));
            }
            break;
        case "forest-desc":
            if (httpget('location') == "uniqueforests" || get_module_objpref("city", $cityid, "use")) {
                page_header(color_sanitize($name));
                global $block_new_output;
                $block_new_output = false;
                output(get_module_objpref("city", $cityid, "desc"));
                $block_new_output = true;
            }
            break;
    }
    return $args;
}
function buildinghitpoints_get_data($cid)
{
    //Grab all the data from a particular Outpost
    if (!is_numeric($cid)) {
        require_once "modules/cityprefs/lib.php";
        $cid = get_cityprefs_cityid($cid);
    }
    $data = get_module_objpref("city", $cid, "buildinghitpoints");
    $ret = array();
    $ret['data'] = @unserialize($data);
    $ret['cid'] = $cid;
    return $data;
}
function mountrarity_dohook($hookname, $args)
{
    switch ($hookname) {
        case "newday-runonce":
            $sql = "SELECT mountid FROM " . db_prefix("mounts") . " WHERE mountactive=1";
            $result = db_query($sql);
            while ($row = db_fetch_assoc($result)) {
                $id = $row['mountid'];
                $rarity = get_module_objpref("mounts", $id, "rarity");
                if (e_rand(1, 100) > $rarity) {
                    set_module_objpref("mounts", $id, "unavailable", 1);
                } else {
                    // You need to reset the availability if it's not unavailable
                    // otherwise, it never becomes available again!
                    set_module_objpref("mounts", $id, "unavailable", 0);
                }
            }
            break;
        case "mountfeatures":
            $rarity = get_module_objpref("mounts", $args['id'], "rarity");
            $args['features']['Rarity'] = $rarity;
            break;
        case "stables-desc":
            if (get_module_setting("showout")) {
                $sql = "SELECT mountid, mountname FROM " . db_prefix("mounts") . " WHERE mountactive=1";
                $result = db_query($sql);
                output("`nA sign by the door proclaims that the following mounts are out of stock for today:");
                while ($row = db_fetch_assoc($result)) {
                    $out = get_module_objpref("mounts", $row['mountid'], "unavailable");
                    if ($out) {
                        output("`n%s", $row['mountname']);
                    }
                }
            } else {
                output("`nIf you don't see something you like today, perhaps you should check again tomorrow.");
            }
            break;
        case "stables-nav":
            $sql = "SELECT mountid FROM " . db_prefix("mounts") . " WHERE mountactive=1";
            $result = db_query($sql);
            while ($row = db_fetch_assoc($result)) {
                $id = $row['mountid'];
                $out = get_module_objpref("mounts", $id, "unavailable");
                if ($out) {
                    blocknav("stables.php?op=examine&id={$id}");
                }
            }
            break;
    }
    return $args;
}
function clanbuffs_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "footer-hof":
            if (get_module_setting("hof")) {
                addnav("Warrior Rankings");
                addnav("Clan Buffs", "runmodule.php?module=clanbuffs&op=hof");
            }
            break;
        case "footer-clan":
            if ($session['user']['clanid'] != 0 and httpget("op") == "") {
                if ($session['user']['clanrank'] > 0) {
                    addnav("Clan Buffs", "runmodule.php?module=clanbuffs&op=enter");
                }
            }
            break;
        case "village":
        case "forest":
        case "clanhall":
            if (get_module_pref("refreshbuff")) {
                set_module_pref("refreshbuff", 0);
                include_once "modules/clanbuffs/clanbuffs_func.php";
                apply_clan_buff_for_one();
                output("`n`n`c`b`!Your clan's aura has been upgraded and refreshed!`0`b`c`n`n");
            }
            break;
        case "newday":
            if ($session['user']['clanid'] != 0 && $session['user']['clanrank'] > 0) {
                if (get_module_objpref("clans", $session['user']['clanid'], "buffactive") == 1) {
                    include_once "modules/clanbuffs/clanbuffs_func.php";
                    apply_clan_buff_for_one();
                    output("`n`^Your clan's aura protects you!`n");
                }
            }
            break;
        case "changesetting":
            if ($args['setting'] == "remakecost" && $args['module'] == "clanbuffs") {
                include_once "modules/clanbuffs/clanbuffs_func.php";
                remake_costs();
            }
            break;
    }
    return $args;
}
function staminamounts_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "boughtmount":
        case "soldmount":
        case "stamina-newday":
            require_once "modules/staminasystem/lib/lib.php";
            $currentmount = $session['user']['hashorse'];
            for ($i = 1; $i <= 10; $i++) {
                if (get_module_objpref("mounts", $currentmount, "buff" . $i . "name", "staminamounts") || get_module_objpref("mounts", $currentmount, "buff" . $i . "costmod", "staminamounts") || get_module_objpref("mounts", $currentmount, "buff" . $i . "expmod", "staminamounts")) {
                    apply_stamina_buff("mountbuff" . $i, array("name" => get_module_objpref("mounts", $currentmount, "buff" . $i . "name", "staminamounts"), "action" => get_module_objpref("mounts", $currentmount, "buff" . $i . "action", "staminamounts"), "class" => get_module_objpref("mounts", $currentmount, "buff" . $i . "class", "staminamounts"), "costmod" => get_module_objpref("mounts", $currentmount, "buff" . $i . "costmod", "staminamounts"), "expmod" => get_module_objpref("mounts", $currentmount, "buff" . $i . "expmod", "staminamounts"), "rounds" => get_module_objpref("mounts", $currentmount, "buff" . $i . "rounds", "staminamounts"), "roundmsg" => get_module_objpref("mounts", $currentmount, "buff" . $i . "roundmsg", "staminamounts"), "wearoffmsg" => get_module_objpref("mounts", $currentmount, "buff" . $i . "wearoffmsg", "staminamounts")));
                }
            }
            break;
    }
    return $args;
}
function descriptioncheck_run()
{
    global $session;
    page_header("Creature Descriptions Checker Thing");
    output("This handy page shows all creature descriptions, win messages, lose messages, and failboat/jungle status, complete with colour codes.`n`nPlease use this page sparingly, as it's kinda resource-intensive.  Ta!`n`n");
    $sql = "SELECT * FROM " . db_prefix("creatures") . " ORDER BY creaturelevel,creaturename";
    $result = db_query($sql);
    $n = db_num_rows($result);
    for ($i = 0; $i < $n; $i++) {
        $row = db_fetch_assoc($result);
        $desc = stripslashes(get_module_objpref("creatures", $row['creatureid'], "description", "creatureaddon"));
        if ($desc == "") {
            $desc = "No Description!";
        }
        output("`0`bCreature: %s | Weapon: %s | Level: %s | Jungle: %s | FailBoat: %s`nDescription:`b`n-----`n%s`n-----`n`n", $row['creaturename'], $row['creatureweapon'], $row['creaturelevel'], $row['forest'], $row['graveyard'], $desc);
    }
    addnav("Back to the Grotto", "superuser.php");
    page_footer();
}
function additionalkeys_run()
{
    global $session;
    $dwid = httpget('dwid');
    $type = httpget('type');
    $typeid = get_module_setting("typeid", $type);
    $op = httpget('op');
    $points = get_module_objpref("dwellingtypes", $typeid, "keydonationcost", "additionalkeys");
    $gem = get_module_objpref("dwellingtypes", $typeid, "keygemcost", "additionalkeys");
    $gold = get_module_objpref("dwellingtypes", $typeid, "keygoldcost", "additionalkeys");
    $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
    addnav("Navigation");
    addnav("Return to Management", "runmodule.php?module=dwellings&op=manage&dwid={$dwid}");
    page_header("Keymaker");
    switch ($op) {
        case "buykeys":
            $type = httpget('type');
            $typeid = get_module_setting("typeid", $type);
            output("`n`0You enter the smithy and wait at the desk until a dwarf appears. \"`2Soso, you would like to buy more keys?`0\" he asks you and you nod. ");
            output("Then he tells you that this will cost you `^%s gold, %s gems `0and `^%s donationpoints`0. \"`2Still interested?`0\"", $gold, $gem, $points);
            addnav("Keymaker");
            addnav("Yes", "runmodule.php?module=additionalkeys&op=yes&dwid={$dwid}&type={$type}");
            break;
        case "yes":
            $type = httpget('type');
            $typeid = get_module_setting("typeid", $type);
            if ($session['user']['gold'] < $gold || $session['user']['gems'] < $gem || $pointsavailable < $points) {
                output("`n`n\"`2Did I not just tell you what it costs to get an extra key? So why do you waste my precious time?!`0\" the keymaker yells at you. ");
                output("Embarassed you just nod, what is apparently you can do best und leave the keymakers office.");
            } else {
                $add = get_module_objpref("dwellings", $dwid, "addkeys", "additionalkeys");
                $add++;
                set_module_objpref("dwellings", $dwid, "addkeys", $add, "additionalkeys");
                $session['user']['donationspent'] += $points;
                $session['user']['gems'] -= $gem;
                $session['user']['gold'] -= $gold;
                output("`n`n`0It takes a moment as the dwarf finally wipes away the sweat and returns to the desk, where you are still waiting for your key. He hands it over to you and says, \"`2Think about it carefully, whom you like to give it.`0\"");
            }
            break;
    }
    page_footer();
}
function farmhouses_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "dwellings-list-type":
            addnav("Show Only Types");
            addnav(array("%s", ucfirst(get_module_setting("dwnameplural", "farmhouses"))), "runmodule.php?module=dwellings&op=list&showonly=farmhouses&ref={$args['ref']}&sortby={$args['sortby']}&order={$args['order']}");
            break;
        case "dwellings":
            if (get_module_objpref("city", $args['cityid'], "showfarmhouses")) {
                output("  Off in the distance, you can see smoke rising from chimneys of a few %s.`0", get_module_setting("dwnameplural"));
                if ($args['allowbuy'] == 1 && $session['user']['dragonkills'] >= get_module_setting("dkreq")) {
                    $cityid = $args['cityid'];
                    addnav("Options");
                    addnav(array("Establish a %s", ucfirst(get_module_setting("dwname", "farmhouses"))), "runmodule.php?module=dwellings&op=buy&type=farmhouses&subop=presetup&cityid={$cityid}");
                }
            }
            break;
    }
    return $args;
}
function dwcastles_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "dwellings-list-type":
            addnav("Show Only Types");
            addnav(array("%s", ucfirst(translate_inline(get_module_setting("dwnameplural", "dwcastles")))), "runmodule.php?module=dwellings&op=list&showonly=dwcastles&ref={$args['ref']}&sortby={$args['sortby']}&order={$args['order']}");
            break;
        case "dwellings":
            if (get_module_objpref("city", $args['cityid'], "showdwcastles")) {
                output("  High on the far hills, you see waving flags of the glorious %s`0 of the rich and fabulous.", translate_inline(get_module_setting("dwnameplural")));
                if ($args['allowbuy'] == 1 && $session['user']['dragonkills'] >= get_module_setting("dkreq")) {
                    $cityid = $args['cityid'];
                    addnav("Options");
                    addnav(array("Establish a %s", ucfirst(translate_inline(get_module_setting("dwname", "dwcastles")))), "runmodule.php?module=dwellings&op=buy&type=dwcastles&subop=presetup&cityid={$cityid}");
                }
            }
            break;
    }
    return $args;
}
function darkhorse_dohook($hookname, $args)
{
    switch ($hookname) {
        case "moderate":
            $args['darkhorse'] = get_module_setting("tavernname");
            break;
        case "mountfeatures":
            $tavern = get_module_objpref("mounts", $args['id'], "findtavern");
            $args['features']['Darkhorse'] = $tavern;
            break;
        case "forest":
            if (darkhorse_tavernmount()) {
                // add the nav
                addnav("Other");
                $iname = get_module_setting("tavernname");
                require_once "lib/mountname.php";
                list($name, $lcname) = getmountname();
                addnav(array("D?Take %s`0 to %s", $lcname, $iname), "runmodule.php?module=darkhorse&op=enter");
            }
            break;
    }
    return $args;
}
             $goldvalue = round($paidgold * get_module_setting("valueper") / 100);
             $gemvalue = round($paidgems * get_module_setting("valueper") / 100);
             $sql = "INSERT INTO " . db_prefix("dwellings") . " (gold,gems,goldvalue,gemvalue,ownerid,type,location,status) VALUES ({$paidgold},{$paidgems},{$goldvalue},{$gemvalue}," . $session['user']['acctid'] . ",'{$type}','" . $session['user']['location'] . "',2)";
             $result = db_query($sql);
             // Now, here comes the trick... really nice one... No additional queries needed...
             //						$sql = "SELECT dwid FROM ".db_prefix("dwellings")." WHERE location='".$session['user']['location']."' AND ownerid=".$session['user']['acctid']." ORDER BY dwid DESC LIMIT 1";
             //						db_query($sql);
             //						$result = db_query($sql);
             //						$row = db_fetch_assoc($result);
             $dwid = db_insert_id($result);
             $finished = 1;
             $buyargs = modulehook("dwellings-buy-setup", array('type' => $type, 'dwid' => $dwid, 'finished' => $finished));
             $finished = $buyargs['finished'];
             if ($paidgold == $costgold && $paidgems == $costgems && $finished == 1) {
                 output("You have paid for your dwelling in full!");
                 if (get_module_objpref("dwelling", $dwid, "buildturns") <= get_module_setting("turncost", $type)) {
                     output("Now it's time to build it!");
                     $status = 3;
                     addnav(array("Build your %s", $dwname), "runmodule.php?module=dwellings&op=build&type={$type}&dwid={$dwid}");
                 } else {
                     $status = 1;
                     addnav(array("Enter your %s", $dwname), "runmodule.php?module=dwellings&op=enter&type={$type}&dwid={$dwid}");
                 }
                 $sql = "UPDATE " . db_prefix("dwellings") . " SET status={$status} WHERE dwid={$dwid}";
                 db_query($sql);
             } else {
                 output("`@You are now one step closer to finishing the payments on your %s`@.", $dwname);
             }
         }
     }
 }
    $loggedin = date("U") - strtotime($row['laston']) < getsetting("LOGINTIMEOUT", 900) && $row['loggedin'];
    output_notl("`&%s`0", $row['location']);
    if ($loggedin) {
        output_notl("%s", $online);
    }
    rawoutput("</td><td>");
    output_notl("%s", translate_inline($row['race'], "race"));
    rawoutput("</td><td>");
    $sex = translate_inline($row['sex'] ? "`%Female`0" : "`!Male`0");
    output_notl("%s", $sex);
    rawoutput("</td><td>");
    //$sql = "SELECT name FROM ".db_prefix("accounts")." WHERE acctid='".$row['marriedto']."' AND locked=0";
    //$res = db_fetch_assoc(db_query($sql));
    //output_notl("%s",$res['name']);
    output_notl("%s", $row['partnername']);
    rawoutput("</td><td>");
    $reg = get_module_objpref("marriage", $row['acctid'], "marriagedate");
    if ($reg == "0000-00-00 00:00:00" || $reg == 0) {
        $reg = $unlogged;
    }
    output_notl("%s", $reg);
    rawoutput("</td></tr>");
}
rawoutput("</table>");
output_notl("`n");
$search = translate_inline("Search by name: ");
$search2 = translate_inline("Search");
rawoutput("<form action='runmodule.php?module=marriage&op=newlyweds&action=search' method='POST'>{$search}<input name='name'><input type='submit' class='button' value='{$search2}'></form>");
addnav("", "runmodule.php?module=marriage&op=newlyweds&action=search");
output_notl("`c");
page_footer();
function improbablestufftrading_run()
{
    global $session;
    $op = httpget("op");
    //city prefs
    //God this is gonna be a mess, would be much better with a serialized item system, perhaps for S3...
    require_once "modules/cityprefs/lib.php";
    $cityid = get_cityprefs_cityid("location", $session['user']['location']);
    $smallmedkitcurrent = get_module_objpref("city", $cityid, "smallmedkit-current");
    $smallmedkitmax = get_module_objpref("city", $cityid, "smallmedkit-max");
    $smallmedkitmin = get_module_objpref("city", $cityid, "smallmedkit-min");
    $smallmedkitbuypct = get_module_objpref("city", $cityid, "smallmedkit-buypct");
    $smallmedkitbuy = round($smallmedkitcurrent / 100 * $smallmedkitbuypct);
    $smallmedkitavail = get_module_objpref("city", $cityid, "smallmedkit-avail");
    $largemedkitcurrent = get_module_objpref("city", $cityid, "largemedkit-current");
    $largemedkitmax = get_module_objpref("city", $cityid, "largemedkit-max");
    $largemedkitmin = get_module_objpref("city", $cityid, "largemedkit-min");
    $largemedkitbuypct = get_module_objpref("city", $cityid, "largemedkit-buypct");
    $largemedkitbuy = round($largemedkitcurrent / 100 * $largemedkitbuypct);
    $largemedkitavail = get_module_objpref("city", $cityid, "largemedkit-avail");
    $energydrinkcurrent = get_module_objpref("city", $cityid, "energydrink-current");
    $energydrinkmax = get_module_objpref("city", $cityid, "energydrink-max");
    $energydrinkmin = get_module_objpref("city", $cityid, "energydrink-min");
    $energydrinkbuypct = get_module_objpref("city", $cityid, "energydrink-buypct");
    $energydrinkbuy = round($energydrinkcurrent / 100 * $energydrinkbuypct);
    $energydrinkavail = get_module_objpref("city", $cityid, "energydrink-avail");
    $nicotinegumcurrent = get_module_objpref("city", $cityid, "nicotinegum-current");
    $nicotinegummax = get_module_objpref("city", $cityid, "nicotinegum-max");
    $nicotinegummin = get_module_objpref("city", $cityid, "nicotinegum-min");
    $nicotinegumbuypct = get_module_objpref("city", $cityid, "nicotinegum-buypct");
    $nicotinegumbuy = round($nicotinegumcurrent / 100 * $nicotinegumbuypct);
    $nicotinegumavail = get_module_objpref("city", $cityid, "nicotinegum-avail");
    $powerpillcurrent = get_module_objpref("city", $cityid, "powerpill-current");
    $powerpillmax = get_module_objpref("city", $cityid, "powerpill-max");
    $powerpillmin = get_module_objpref("city", $cityid, "powerpill-min");
    $powerpillbuypct = get_module_objpref("city", $cityid, "powerpill-buypct");
    $powerpillbuy = round($powerpillcurrent / 100 * $powerpillbuypct);
    $powerpillavail = get_module_objpref("city", $cityid, "powerpill-avail");
    $teleportercurrent = get_module_objpref("city", $cityid, "teleporter-current");
    $teleportermax = get_module_objpref("city", $cityid, "teleporter-max");
    $teleportermin = get_module_objpref("city", $cityid, "teleporter-min");
    $teleporterbuypct = get_module_objpref("city", $cityid, "teleporter-buypct");
    $teleporterbuy = round($teleportercurrent / 100 * $teleporterbuypct);
    $teleporteravail = get_module_objpref("city", $cityid, "teleporter-avail");
    $banggrenadecurrent = get_module_objpref("city", $cityid, "banggrenade-current");
    $banggrenademax = get_module_objpref("city", $cityid, "banggrenade-max");
    $banggrenademin = get_module_objpref("city", $cityid, "banggrenade-min");
    $banggrenadebuypct = get_module_objpref("city", $cityid, "banggrenade-buypct");
    $banggrenadebuy = round($banggrenadecurrent / 100 * $banggrenadebuypct);
    $banggrenadeavail = get_module_objpref("city", $cityid, "banggrenade-avail");
    $whoomphgrenadecurrent = get_module_objpref("city", $cityid, "whoomphgrenade-current");
    $whoomphgrenademax = get_module_objpref("city", $cityid, "whoomphgrenade-max");
    $whoomphgrenademin = get_module_objpref("city", $cityid, "whoomphgrenade-min");
    $whoomphgrenadebuypct = get_module_objpref("city", $cityid, "whoomphgrenade-buypct");
    $whoomphgrenadebuy = round($whoomphgrenadecurrent / 100 * $whoomphgrenadebuypct);
    $whoomphgrenadeavail = get_module_objpref("city", $cityid, "whoomphgrenade-avail");
    $zapgrenadecurrent = get_module_objpref("city", $cityid, "zapgrenade-current");
    $zapgrenademax = get_module_objpref("city", $cityid, "zapgrenade-max");
    $zapgrenademin = get_module_objpref("city", $cityid, "zapgrenade-min");
    $zapgrenadebuypct = get_module_objpref("city", $cityid, "zapgrenade-buypct");
    $zapgrenadebuy = round($zapgrenadecurrent / 100 * $zapgrenadebuypct);
    $zapgrenadeavail = get_module_objpref("city", $cityid, "zapgrenade-avail");
    $repellentspraycurrent = get_module_objpref("city", $cityid, "repellentspray-current");
    $repellentspraymax = get_module_objpref("city", $cityid, "repellentspray-max");
    $repellentspraymin = get_module_objpref("city", $cityid, "repellentspray-min");
    $repellentspraybuypct = get_module_objpref("city", $cityid, "repellentspray-buypct");
    $repellentspraybuy = round($repellentspraycurrent / 100 * $repellentspraybuypct);
    $repellentsprayavail = get_module_objpref("city", $cityid, "repellentspray-avail");
    $rationpackcurrent = get_module_objpref("city", $cityid, "rationpack-current");
    $rationpackmax = get_module_objpref("city", $cityid, "rationpack-max");
    $rationpackmin = get_module_objpref("city", $cityid, "rationpack-min");
    $rationpackbuypct = get_module_objpref("city", $cityid, "rationpack-buypct");
    $rationpackbuy = round($rationpackcurrent / 100 * $rationpackbuypct);
    $rationpackavail = get_module_objpref("city", $cityid, "rationpack-avail");
    $improbabilitybombcurrent = get_module_objpref("city", $cityid, "improbabilitybomb-current");
    $improbabilitybombmax = get_module_objpref("city", $cityid, "improbabilitybomb-max");
    $improbabilitybombmin = get_module_objpref("city", $cityid, "improbabilitybomb-min");
    $improbabilitybombbuypct = get_module_objpref("city", $cityid, "improbabilitybomb-buypct");
    $improbabilitybombbuy = round($improbabilitybombcurrent / 100 * $improbabilitybombbuypct);
    $improbabilitybombavail = get_module_objpref("city", $cityid, "improbabilitybomb-avail");
    $kittencardcurrent = get_module_objpref("city", $cityid, "kittencard-current");
    $kittencardmax = get_module_objpref("city", $cityid, "kittencard-max");
    $kittencardmin = get_module_objpref("city", $cityid, "kittencard-min");
    $kittencardbuypct = get_module_objpref("city", $cityid, "kittencard-buypct");
    $kittencardbuy = round($kittencardcurrent / 100 * $kittencardbuypct);
    $kittencardavail = get_module_objpref("city", $cityid, "kittencard-avail");
    $bribe = get_module_objpref("city", $cityid, "bribe");
    $acceptingbribes = get_module_objpref("city", $cityid, "acceptingbribes");
    page_header("eBoy's Trading Station");
    switch (httpget("op")) {
        case "start":
            output("Already fearing the worst, you head into eBoy's Trading Station.`n`nYour fears are well-founded.  The place is packed with the heaving, sweaty bodies of the hardcore capitalist, shouting \"`iBuy, buy!`i\" and \"`iSell, sell!`i\" and \"`iPut down the chainsaw and let's talk about this!`i\"`n`neBoy himself - although you suspect that this place, like Mike's Chop Shop, is a franchise of which you'll find one in every outpost, so is his name really eBoy?  Whoever he is, he stands on an elevated section of floor behind a tall mahogany counter, grabbing money with one hand and tossing grenades and ration packs over his shoulder with the other.  His arms are a blur.  His speech is the unintelligible, rapid-fire gabble of a professional auctioneer.  His eyes bulge and swivel.  You know he's loving this.`n`n");
            break;
        case "buy":
            $item = httpget("item");
            if (get_module_objpref("city", $cityid, "" . $item . "-avail") <= 0) {
                output("eBoy turns to you and gibbers.`n`n\"Sorrymatejustsoldthelastoneyougottabefasteritsthequickandthedeadaroundherepal.\"  He turns to the next customer in line, leaving you trying to piece together whatever it is that he just said.`n`n");
                break;
            }
            switch ($item) {
                case "smallmedkit":
                    increment_module_pref("item1number", 1, "improbablestuff");
                    $session['user']['gold'] -= $smallmedkitcurrent;
                    increment_module_objpref("city", $cityid, "smallmedkit-avail", -1);
                    break;
                case "largemedkit":
                    increment_module_pref("item2number", 1, "improbablestuff");
                    $session['user']['gold'] -= $largemedkitcurrent;
                    increment_module_objpref("city", $cityid, "largemedkit-avail", -1);
                    break;
                case "energydrink":
                    increment_module_pref("item3number", 1, "improbablestuff");
                    $session['user']['gold'] -= $energydrinkcurrent;
                    increment_module_objpref("city", $cityid, "energydrink-avail", -1);
                    break;
                case "nicotinegum":
                    increment_module_pref("item4number", 1, "improbablestuff");
                    $session['user']['gold'] -= $nicotinegumcurrent;
                    increment_module_objpref("city", $cityid, "nicotinegum-avail", -1);
                    break;
                case "powerpill":
                    increment_module_pref("item5number", 1, "improbablestuff");
                    $session['user']['gold'] -= $powerpillcurrent;
                    increment_module_objpref("city", $cityid, "powerpill-avail", -1);
                    break;
                case "teleporter":
                    increment_module_pref("item6number", 1, "improbablestuff");
                    $session['user']['gold'] -= $teleportercurrent;
                    increment_module_objpref("city", $cityid, "teleporter-avail", -1);
                    break;
                case "banggrenade":
                    increment_module_pref("item7number", 1, "improbablestuff");
                    $session['user']['gold'] -= $banggrenadecurrent;
                    increment_module_objpref("city", $cityid, "banggrenade-avail", -1);
                    break;
                case "whoomphgrenade":
                    increment_module_pref("item8number", 1, "improbablestuff");
                    $session['user']['gold'] -= $whoomphgrenadecurrent;
                    increment_module_objpref("city", $cityid, "whoomphgrenade-avail", -1);
                    break;
                case "zapgrenade":
                    increment_module_pref("item9number", 1, "improbablestuff");
                    $session['user']['gold'] -= $zapgrenadecurrent;
                    increment_module_objpref("city", $cityid, "zapgrenade-avail", -1);
                    break;
                case "repellentspray":
                    increment_module_pref("item10number", 1, "improbablestuff");
                    $session['user']['gold'] -= $repellentspraycurrent;
                    increment_module_objpref("city", $cityid, "repellentspray-avail", -1);
                    break;
                case "rationpack":
                    increment_module_pref("item11number", 1, "improbablestuff");
                    $session['user']['gold'] -= $rationpackcurrent;
                    increment_module_objpref("city", $cityid, "rationpack-avail", -1);
                    break;
                case "improbabilitybomb":
                    increment_module_pref("item12number", 1, "improbablestuff");
                    $session['user']['gold'] -= $improbabilitybombcurrent;
                    increment_module_objpref("city", $cityid, "improbabilitybomb-avail", -1);
                    break;
                case "kittencard":
                    increment_module_pref("item13number", 1, "improbablestuff");
                    $session['user']['gold'] -= $kittencardcurrent;
                    increment_module_objpref("city", $cityid, "kittencard-avail", -1);
                    break;
            }
            output("You fight your way to the front of the crowd and shout your order up to eBoy, slapping your Requisition tokens down on the counter.  Before you can blink, your money is gone and the item you desired sits in its place.  You grab it hastily and stuff it into your backpack as eBoy turns to deal with the next customer.`n`n");
            break;
        case "sell":
            $item = httpget("item");
            switch ($item) {
                case "smallmedkit":
                    increment_module_pref("item1number", -1, "improbablestuff");
                    $session['user']['gold'] += $smallmedkitbuy;
                    increment_module_objpref("city", $cityid, "smallmedkit-avail", 1);
                    break;
                case "largemedkit":
                    increment_module_pref("item2number", -1, "improbablestuff");
                    $session['user']['gold'] += $largemedkitbuy;
                    increment_module_objpref("city", $cityid, "largemedkit-avail", 1);
                    break;
                case "energydrink":
                    increment_module_pref("item3number", -1, "improbablestuff");
                    $session['user']['gold'] += $energydrinkbuy;
                    increment_module_objpref("city", $cityid, "energydrink-avail", 1);
                    break;
                case "nicotinegum":
                    increment_module_pref("item4number", -1, "improbablestuff");
                    $session['user']['gold'] += $nicotinegumbuy;
                    increment_module_objpref("city", $cityid, "nicotinegum-avail", 1);
                    break;
                case "powerpill":
                    increment_module_pref("item5number", -1, "improbablestuff");
                    $session['user']['gold'] += $powerpillbuy;
                    increment_module_objpref("city", $cityid, "powerpill-avail", 1);
                    break;
                case "teleporter":
                    increment_module_pref("item6number", -1, "improbablestuff");
                    $session['user']['gold'] += $teleporterbuy;
                    increment_module_objpref("city", $cityid, "teleporter-avail", 1);
                    break;
                case "banggrenade":
                    increment_module_pref("item7number", -1, "improbablestuff");
                    $session['user']['gold'] += $banggrenadebuy;
                    increment_module_objpref("city", $cityid, "banggrenade-avail", 1);
                    break;
                case "whoomphgrenade":
                    increment_module_pref("item8number", -1, "improbablestuff");
                    $session['user']['gold'] += $whoomphgrenadebuy;
                    increment_module_objpref("city", $cityid, "whoomphgrenade-avail", 1);
                    break;
                case "zapgrenade":
                    increment_module_pref("item9number", -1, "improbablestuff");
                    $session['user']['gold'] += $zapgrenadebuy;
                    increment_module_objpref("city", $cityid, "zapgrenade-avail", 1);
                    break;
                case "repellentspray":
                    increment_module_pref("item10number", -1, "improbablestuff");
                    $session['user']['gold'] += $repellentspraybuy;
                    increment_module_objpref("city", $cityid, "repellentspray-avail", 1);
                    break;
                case "rationpack":
                    increment_module_pref("item11number", -1, "improbablestuff");
                    $session['user']['gold'] += $rationpackbuy;
                    increment_module_objpref("city", $cityid, "rationpack-avail", 1);
                    break;
                case "improbabilitybomb":
                    increment_module_pref("item12number", -1, "improbablestuff");
                    $session['user']['gold'] += $improbabilitybombbuy;
                    increment_module_objpref("city", $cityid, "improbabilitybomb-avail", 1);
                    break;
                case "kittencard":
                    increment_module_pref("item13number", -1, "improbablestuff");
                    $session['user']['gold'] += $kittencardbuy;
                    increment_module_objpref("city", $cityid, "kittencard-avail", 1);
                    break;
            }
            increment_module_pref("soldtoday", 1);
            output("You barge your way through the crowd like a battleship through an ice flow, and toss your item up to eBoy.  eBoy snatches the item out of the air with his left hand while tossing your Requisition tokens back at you with his right, and goes on to serve the next customer.`n`n");
            break;
    }
    //get the latest availability data
    $smallmedkitavail = get_module_objpref("city", $cityid, "smallmedkit-avail");
    $largemedkitavail = get_module_objpref("city", $cityid, "largemedkit-avail");
    $energydrinkavail = get_module_objpref("city", $cityid, "energydrink-avail");
    $nicotinegumavail = get_module_objpref("city", $cityid, "nicotinegum-avail");
    $powerpillavail = get_module_objpref("city", $cityid, "powerpill-avail");
    $teleporteravail = get_module_objpref("city", $cityid, "teleporter-avail");
    $banggrenadeavail = get_module_objpref("city", $cityid, "banggrenade-avail");
    $whoomphgrenadeavail = get_module_objpref("city", $cityid, "whoomphgrenade-avail");
    $zapgrenadeavail = get_module_objpref("city", $cityid, "zapgrenade-avail");
    $repellentsprayavail = get_module_objpref("city", $cityid, "repellentspray-avail");
    $rationpackavail = get_module_objpref("city", $cityid, "rationpack-avail");
    $improbabilitybombavail = get_module_objpref("city", $cityid, "improbabilitybomb-avail");
    $kittencardavail = get_module_objpref("city", $cityid, "kittencard-avail");
    //show info board
    output("You look up above eBoy's head at the trading board, the values of each commodity hastily scrawled in chalk early this morning:`n`n");
    output("`0Small Medkits:`n");
    output("Stock available: %s`n", $smallmedkitavail);
    output("`2Selling at: %s Requisition`n", $smallmedkitcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $smallmedkitbuy);
    output("`0Large Medkits:`n");
    output("Stock available: %s`n", $largemedkitavail);
    output("`2Selling at: %s Requisition`n", $largemedkitcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $largemedkitbuy);
    output("`0Energy Drinks:`n");
    output("Stock available: %s`n", $energydrinkavail);
    output("`2Selling at: %s Requisition`n", $energydrinkcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $energydrinkbuy);
    output("`0Nicotine Gum:`n");
    output("Stock available: %s`n", $nicotinegumavail);
    output("`2Selling at: %s Requisition`n", $nicotinegumcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $nicotinegumbuy);
    output("`0Power Pills:`n");
    output("Stock available: %s`n", $powerpillavail);
    output("`2Selling at: %s Requisition`n", $powerpillcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $powerpillbuy);
    output("`0One-Shot Teleporters:`n");
    output("Stock available: %s`n", $teleporteravail);
    output("`2Selling at: %s Requisition`n", $teleportercurrent);
    output("`7Buying at: %s Requisition`0`n`n", $teleporterbuy);
    output("`0BANG Grenades:`n");
    output("Stock available: %s`n", $banggrenadeavail);
    output("`2Selling at: %s Requisition`n", $banggrenadecurrent);
    output("`7Buying at: %s Requisition`0`n`n", $banggrenadebuy);
    output("`0WHOOMPH Grenades:`n");
    output("Stock available: %s`n", $whoomphgrenadeavail);
    output("`2Selling at: %s Requisition`n", $whoomphgrenadecurrent);
    output("`7Buying at: %s Requisition`0`n`n", $whoomphgrenadebuy);
    output("`0ZAP Grenades:`n");
    output("Stock available: %s`n", $zapgrenadeavail);
    output("`2Selling at: %s Requisition`n", $zapgrenadecurrent);
    output("`7Buying at: %s Requisition`0`n`n", $zapgrenadebuy);
    output("`0Monster Repellent Spray:`n");
    output("Stock available: %s`n", $repellentsprayavail);
    output("`2Selling at: %s Requisition`n", $repellentspraycurrent);
    output("`7Buying at: %s Requisition`0`n`n", $repellentspraybuy);
    output("`0Ration Packs:`n");
    output("Stock available: %s`n", $rationpackavail);
    output("`2Selling at: %s Requisition`n", $rationpackcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $rationpackbuy);
    output("`0Improbability Bombs:`n");
    output("Stock available: %s`n", $improbabilitybombavail);
    output("`2Selling at: %s Requisition`n", $improbabilitybombcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $improbabilitybombbuy);
    output("`0Kitten Greetings Cards:`n");
    output("Stock available: %s`n", $kittencardavail);
    output("`2Selling at: %s Requisition`n", $kittencardcurrent);
    output("`7Buying at: %s Requisition`0`n`n", $kittencardbuy);
    //buying navs
    addnav("Buying");
    if ($session['user']['gold'] >= $smallmedkitcurrent && $smallmedkitavail > 0) {
        addnav(array("Buy a Small Medkit (%s Requisition)", $smallmedkitcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=smallmedkit");
    }
    if ($session['user']['gold'] >= $largemedkitcurrent && $largemedkitavail > 0) {
        addnav(array("Buy a Large Medkit (%s Requisition)", $largemedkitcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=largemedkit");
    }
    if ($session['user']['gold'] >= $energydrinkcurrent && $energydrinkavail > 0) {
        addnav(array("Buy an Energy Drink (%s Requisition)", $energydrinkcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=energydrink");
    }
    if ($session['user']['gold'] >= $nicotinegumcurrent && $nicotinegumavail > 0) {
        addnav(array("Buy a piece of Nicotine Gum (%s Requisition)", $nicotinegumcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=nicotinegum");
    }
    if ($session['user']['gold'] >= $powerpillcurrent && $powerpillavail > 0) {
        addnav(array("Buy a Power Pill (%s Requisition)", $powerpillcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=powerpill");
    }
    if ($session['user']['gold'] >= $teleportercurrent && $teleporteravail > 0) {
        addnav(array("Buy a One-Shot Teleporter (%s Requisition)", $teleportercurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=teleporter");
    }
    if ($session['user']['gold'] >= $banggrenadecurrent && $banggrenadeavail > 0) {
        addnav(array("Buy a Bang Grenade (%s Requisition)", $banggrenadecurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=banggrenade");
    }
    if ($session['user']['gold'] >= $whoomphgrenadecurrent && $whoomphgrenadeavail > 0) {
        addnav(array("Buy a WHOOMPH Grenade (%s Requisition)", $whoomphgrenadecurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=whoomphgrenade");
    }
    if ($session['user']['gold'] >= $zapgrenadecurrent && $zapgrenadeavail > 0) {
        addnav(array("Buy a ZAP Grenade (%s Requisition)", $zapgrenadecurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=zapgrenade");
    }
    if ($session['user']['gold'] >= $repellentspraycurrent && $repellentsprayavail > 0) {
        addnav(array("Buy a can of Monster Repellent Spray (%s Requisition)", $repellentspraycurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=repellentspray");
    }
    if ($session['user']['gold'] >= $rationpackcurrent && $rationpackavail > 0) {
        addnav(array("Buy a Ration Pack (%s Requisition)", $rationpackcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=rationpack");
    }
    if ($session['user']['gold'] >= $improbabilitybombcurrent && $improbabilitybombavail > 0) {
        addnav(array("Buy an Improbability Bomb (%s Requisition)", $improbabilitybombcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=improbabilitybomb");
    }
    if ($session['user']['gold'] >= $kittencardcurrent && $kittencardavail > 0) {
        addnav(array("Buy a Kitten Card (%s Requisition)", $kittencardcurrent), "runmodule.php?module=improbablestufftrading&op=buy&item=kittencard");
    }
    //player prefs
    $playersmallmedkit = get_module_pref("item1number", "improbablestuff");
    $playerlargemedkit = get_module_pref("item2number", "improbablestuff");
    $playerenergydrink = get_module_pref("item3number", "improbablestuff");
    $playernicotinegum = get_module_pref("item4number", "improbablestuff");
    $playerpowerpill = get_module_pref("item5number", "improbablestuff");
    $playerteleporter = get_module_pref("item6number", "improbablestuff");
    $playerbanggrenade = get_module_pref("item7number", "improbablestuff");
    $playerwhoomphgrenade = get_module_pref("item8number", "improbablestuff");
    $playerzapgrenade = get_module_pref("item9number", "improbablestuff");
    $playerrepellentspray = get_module_pref("item10number", "improbablestuff");
    $playerrationpack = get_module_pref("item11number", "improbablestuff");
    $playerimprobabilitybomb = get_module_pref("item12number", "improbablestuff");
    $playerkittencard = get_module_pref("item13number", "improbablestuff");
    //selling navs
    addnav("Selling");
    if ($playersmallmedkit > 0) {
        addnav(array("Sell a Small Medkit (%s remaining)", $playersmallmedkit), "runmodule.php?module=improbablestufftrading&op=sell&item=smallmedkit");
    }
    if ($playerlargemedkit > 0) {
        addnav(array("Sell a Large Medkit (%s remaining)", $playerlargemedkit), "runmodule.php?module=improbablestufftrading&op=sell&item=largemedkit");
    }
    if ($playerenergydrink > 0) {
        addnav(array("Sell an Energy Drink (%s remaining)", $playerenergydrink), "runmodule.php?module=improbablestufftrading&op=sell&item=energydrink");
    }
    if ($playernicotinegum > 0) {
        addnav(array("Sell a piece of Nicotine Gum (%s remaining)", $playernicotinegum), "runmodule.php?module=improbablestufftrading&op=sell&item=nicotinegum");
    }
    if ($playerpowerpill > 0) {
        addnav(array("Sell a Power Pill (%s remaining)", $playerpowerpill), "runmodule.php?module=improbablestufftrading&op=sell&item=powerpill");
    }
    if ($playerteleporter > 0) {
        addnav(array("Sell a One-Shot Teleporter (%s remaining)", $playerteleporter), "runmodule.php?module=improbablestufftrading&op=sell&item=teleporter");
    }
    if ($playerbanggrenade > 0) {
        addnav(array("Sell a Bang Grenade (%s remaining)", $playerbanggrenade), "runmodule.php?module=improbablestufftrading&op=sell&item=banggrenade");
    }
    if ($playerwhoomphgrenade > 0) {
        addnav(array("Sell a WHOOMPH Grenade (%s remaining)", $playerwhoomphgrenade), "runmodule.php?module=improbablestufftrading&op=sell&item=whoomphgrenade");
    }
    if ($playerzapgrenade > 0) {
        addnav(array("Sell a ZAP Grenade (%s remaining)", $playerzapgrenade), "runmodule.php?module=improbablestufftrading&op=sell&item=zapgrenade");
    }
    if ($playerrepellentspray > 0) {
        addnav(array("Sell a can of Monster Repellent Spray (%s remaining)", $playerrepellentspray), "runmodule.php?module=improbablestufftrading&op=sell&item=repellentspray");
    }
    if ($playerrationpack > 0) {
        addnav(array("Sell a Ration Pack (%s remaining)", $playerrationpack), "runmodule.php?module=improbablestufftrading&op=sell&item=rationpack");
    }
    if ($playerimprobabilitybomb > 0) {
        addnav(array("Sell an Improbability Bomb (%s remaining)", $playerimprobabilitybomb), "runmodule.php?module=improbablestufftrading&op=sell&item=improbabilitybomb");
    }
    if ($playerkittencard > 0) {
        addnav(array("Sell a Kitten Card (%s remaining)", $playerkittencard), "runmodule.php?module=improbablestufftrading&op=sell&item=kittencard");
    }
    addnav("Other");
    // todo: add eBoy bribery
    // addnav("Ask eBoy if he's got any insider tips...","runmodule.pnp?module=improbablestufftrading&op=bribe");
    addnav("Return to the Outpost", "village.php");
    page_footer();
    return $args;
}
    $gold_cost = get_module_objpref("dwellingtypes", $typeid, "cost-gold", "dwellings_pvp");
    $gems_cost = get_module_objpref("dwellingtypes", $typeid, "cost-gems", "dwellings_pvp");
    $daysleft = get_module_objpref("dwellings", $dwid, "run-out", "dwellings_pvp");
    $isauto = get_module_objpref("dwellings", $dwid, "isauto", "dwellings_pvp");
    set_module_objpref("dwellings", $dwid, "run-out", $daysleft - 1, "dwellings_pvp");
    $subj = translate_inline("Concerning Dwellings Guard");
    if ($daysleft == 1) {
        if ($gold_coffer >= $gold_cost && $gems_coffer >= $gems_cost && (get_module_setting("whatif") && $isauto)) {
            $extra = translate_inline("However, you have enough gold and gems inside of your coffers to purchase another Guard. So, we will go ahead and place a guard order when they expire.");
        } else {
            $extra = "";
        }
        $body = sprintf("`@We are sorry to inform you, but your establishment, %s`@, in `^%s`@ will lose the usage of it's personal guard in `\$1 day`@. This is due to the rental time running out. %s`n`nDwellings Commission.", $row['name'], $row['location'], $extra);
        require_once "lib/systemmail.php";
        systemmail($row['ownerid'], $subj, $body);
    } elseif ($daysleft <= 0) {
        if ($gold_coffer >= $gold_cost && $gems_coffer >= $gems_cost && (get_module_setting("whatif") && $isauto)) {
            require_once "modules/dwellings/lib.php";
            dwellings_modify_coffers($dwid, "gold", "-" . $gold_cost);
            dwellings_modify_coffers($dwid, "gems", "-" . $gems_cost);
            $days = get_module_objpref("dwellingtypes", $typeid, "guard-length", "dwellings_pvp");
            invalidatedatacache("objpref-dwellings-{$dwid}-run-out-dwellings_pvp");
            invalidatedatacache("objpref-dwellings-{$dwid}-bought-dwellings_pvp");
            set_module_objpref("dwellings", $dwid, "run-out", $days, "dwellings_pvp");
            set_module_objpref("dwellings", $dwid, "bought", 1, "dwellings_pvp");
        } else {
            invalidatedatacache("objpref-dwellings-{$dwid}-bought-dwellings_pvp");
            set_module_objpref("dwellings", $dwid, "bought", 0, "dwellings_pvp");
        }
    }
}
<?php

$fail = 0;
$last = date("Y-m-d H:i:s", strtotime("-" . getsetting("LOGINTIMEOUT", 900) . " sec"));
if (is_module_active("pvpimmunity") && !get_module_pref("check_willing", "pvpimmunity")) {
    $fail = 1;
}
if (!$fail) {
    $typeid = get_module_setting("typeid", $args['type']);
    if ($session['user']['location'] == $args['location'] && get_module_objpref("dwellingtypes", $typeid, "pvp", "dwellings_pvp") && !get_module_objpref("dwellings", $args['dwid'], "bought", "dwellings_pvp") && $session['user']['playerfights'] > 0 && $args['status'] == 1) {
        $top = $session['user']['level'] + get_module_objpref("dwellingtypes", $typeid, "top-band", "dwellings_pvp");
        $bottom = $session['user']['level'] - get_module_objpref("dwellingtypes", $typeid, "bottom-band", "dwellings_pvp");
        $sql = "SELECT count(acctid) AS count FROM " . db_prefix("accounts") . " \r\n\t\t\t\t\tINNER JOIN " . db_prefix("module_userprefs") . " \r\n\t\t\t\t\tON acctid=userid \r\n\t\t\t\t\tWHERE (level>={$bottom} && level<={$top})\r\n\t\t\t\t\tAND (laston < '{$last}' OR loggedin=0)\r\n\t\t\t\t\tAND (pvpflag < '{$pvptimeout}')\r\n\t\t\t\t\tAND (alive=1) AND (locked=0) AND (slaydragon=0)\r\n\t\t\t\t\tAND modulename='dwellings'\r\n\t\t\t\t\tAND setting='dwelling_saver' \r\n\t\t\t\t\tAND value='{$args['dwid']}'";
        $res = db_query($sql);
        $row = db_fetch_assoc($res);
        $dwid = $args['dwid'];
        if ($row['count'] > 0) {
            $p = httpget('page');
            $s = httpget('sortby');
            $sh = httpget('showonly');
            $o = httpget('order');
            $temp = sprintf_translate("Slay (%s)", $row['count']);
            rawoutput("<a href='runmodule.php?module=dwellings_pvp&op=attack_list&dwid={$dwid}&typeid={$typeid}&p={$p}&s={$s}&sh={$sh}&o={$o}'>{$temp}</a><br>");
            addnav("", "runmodule.php?module=dwellings_pvp&op=attack_list&dwid={$dwid}&typeid={$typeid}&p={$p}&s={$s}&sh={$sh}&o={$o}");
        } else {
            // output_notl("`c`i");
            // output("None");
            // output_notl("`i`c`0");
        }
    }
}
        }
        output_notl("%s%s%s", $pre, $row1['name'], $suf);
        $i++;
    }
}
/* 
Removed for aesthetic purposes.
$city_link = urlencode(get_module_pref("location_saver","dwellings"));
if (is_module_active("cities")) 
	$link = "runmodule.php?module=cities&op=travel&city=$city_link&su=1";
}else {
	$link = "village.php";
}
addnav("Leave");
addnav(array("Return to %s",get_module_pref("location_saver","dwellings")),$link); 
*/
$session['user']['location'] = get_module_setting("logoutlocation");
addnav("Dwellings Extras");
modulehook("dwellings-inside", array("type" => $type, "dwid" => $dwid, "owner" => $row['ownerid']));
if (get_module_setting("enablecof") && get_module_setting("enablecof", $type) == 1) {
    addnav("The Coffers", "runmodule.php?module=dwellings&op=coffers&dwid={$dwid}");
}
if ($session['user']['acctid'] != $row['ownerid']) {
    addnav("Turn in Key", "runmodule.php?module=dwellings&op=keys&subop=giveback&dwid={$dwid}");
} else {
    addnav("Dwelling Management", "runmodule.php?module=dwellings&op=manage&dwid={$dwid}");
}
require_once "lib/commentary.php";
addcommentary();
$tl = get_module_objpref("dwellings", $dwid, "dwidtalkline");
viewcommentary("dwellings-" . $dwid, "The walls echo past comments", 20, $tl);
function cities_dohook($hookname, $args)
{
    global $session;
    $city = getsetting("villagename", LOCATION_FIELDS);
    $home = $session['user']['location'] == get_module_pref("homecity");
    $capital = $session['user']['location'] == $city;
    switch ($hookname) {
        case "validatesettings":
            if ($args['dangerchance'] < $args['safechance']) {
                $args['validation_error'] = "Danger chance must be equal to or greater than the safe chance.";
            }
            break;
        case "drinks-check":
            if ($session['user']['location'] == $city) {
                $val = get_module_objpref("drinks", $args['drinkid'], "servedcapital");
                $args['allowdrink'] = $val;
            }
            break;
        case "master-autochallenge":
            global $session;
            if (get_module_pref("homecity") != $session['user']['location']) {
                $info = modulehook("cities-usetravel", array("foresttext" => array("`n`n`^Startled to find your master in %s`^, your heart skips a beat, costing a forest fight from shock.", $session['user']['location']), "traveltext" => array("`n`n`%Surprised at finding your master in %s`%, you feel a little less inclined to be gallivanting around the countryside today.", $session['user']['location'])));
                if ($info['success']) {
                    if ($info['type'] == "travel") {
                        debuglog("Lost a travel because of being truant from master.");
                    } elseif ($info['type'] == "forest") {
                        debuglog("Lost a forest fight because of being truant from master.");
                    } else {
                        debuglog("Lost something, not sure just what, because of being truant from master.");
                    }
                }
            }
            break;
        case "villagetext":
            if ($session['user']['location'] == $city) {
                // The city needs a name still, but at least now it's a bit
                // more descriptive
                // Let's do this a different way so that things which this
                // module (or any other) resets don't get resurrected.
                $args['text'] = array("All around you, the people of Improbable Central move about their business.  No one seems to pay much attention to you as they all seem absorbed in their own lives and problems.  Along various streets you see many different types of shops, each with a sign out front proclaiming the business done therein.  Off to one side, you see a very curious looking rock which attracts your eye with its strange shape and color.  People are constantly entering and leaving via the city gates to a variety of destinations.`n`n");
                $args['schemas']['text'] = "module-cities";
                $args['clock'] = "`n`0The clock on the inn reads `^%s.`0`n";
                $args['schemas']['clock'] = "module-cities";
                // if (is_module_active("calendar")) {
                // $args['calendar']="`n`0You hear a townsperson say that today is `^%1\$s`0, `^%3\$s %2\$s`0, `^%4\$s`0.`n";
                // $args['schemas']['calendar'] = "module-cities";
                // }
                $args['title'] = array("%s, the Capital City", $city);
                $args['schemas']['title'] = "module-cities";
                $args['fightnav'] = "Combat Avenue";
                $args['schemas']['fightnav'] = "module-cities";
                $args['marketnav'] = "Store Street";
                $args['schemas']['marketnav'] = "module-cities";
                $args['tavernnav'] = "Ale Alley";
                $args['schemas']['tavernnav'] = "module-cities";
                $args['newestplayer'] = "";
                $args['schemas']['newestplayer'] = "module-cities";
            }
            if ($home) {
                //in home city.
                blocknav("inn.php");
                blocknav("stables.php");
                blocknav("rock.php");
                // blocknav("hof.php");
                blocknav("mercenarycamp.php");
            } elseif ($capital) {
                //in capital city.
                //blocknav("forest.php");
                blocknav("train.php");
                blocknav("weapons.php");
                blocknav("armor.php");
            } else {
                //in another city.
                blocknav("train.php");
                blocknav("inn.php");
                blocknav("stables.php");
                blocknav("rock.php");
                blocknav("clans.php");
                // blocknav("hof.php");
                blocknav("mercenarycamp.php");
            }
            break;
        case "stablelocs":
            $args[$city] = sprintf_translate("The City of %s", $city);
            break;
        case "camplocs":
            $args[$city] = sprintf_translate("The City of %s", $city);
            break;
    }
    return $args;
}
function onslaught_checkbreach()
{
    global $session;
    $cid = get_cityprefs_cityid("location", $session['user']['location']);
    $breachpoint = get_module_objpref("city", $cid, "breachpoint");
    $creatures = get_module_objpref("city", $cid, "creatures");
    return $creatures / $breachpoint * 100;
}
function mountprereq_run()
{
    global $session;
    $op = httpget('op');
    $id = httpget("id");
    if ($op == "bestiary") {
        page_header("Bestiary");
        if (get_module_setting('viewactiveonly') == 1) {
            $sql = "SELECT mountname,mountid,mountdkcost FROM " . db_prefix("mounts") . " WHERE mountactive=1 ORDER BY mountdkcost,mountcostgems,mountcostgold";
        } else {
            $sql = "SELECT mountname,mountid,mountdkcost FROM " . db_prefix("mounts") . " ORDER BY mountdkcost,mountcostgems,mountcostgold";
        }
        $result = db_query($sql);
        $end = "";
        if (get_module_pref('viewed') == 0) {
            $wonder = "You briefly wonder why you never noticed this here before.";
            set_module_pref('viewed', 1);
            set_module_pref('vieweddk', 1);
        } elseif (get_module_pref('vieweddk') == 0) {
            $wonder = "It seems to have changed somewhat since you last saw it.";
            $end = "Feeling a little more confident since the last time you were here, you also decide to look up on some of the entries that you previously ignored.";
            set_module_pref('vieweddk', 1);
        } else {
            $wonder = "It does not seem to have changed since you last saw it.";
            $end = "`nAs the list descends down the page, more and more fantasic creatures make their appearance. Feeling a little overwhelmed, you decide to ignore the entries of the beasts that seem out of your league.";
        }
        output("You discover a dusty tome left on a stool. %s `nGingerly, you prise open the heavy cover, and discover a Table of Contents page. How helpful!`n%s", $wonder, $end);
        addnav("View the entry on...");
        for ($i = 0; $i < db_num_rows($result); $i++) {
            $row = db_fetch_assoc($result);
            if ($row['mountdkcost'] <= $session['user']['dragonkills'] && get_module_objpref("mounts", $row['mountid'], "boolshow") != 0) {
                addnav(array("View %s`0", $row['mountname']), "runmodule.php?module=mountprereq&op=browse&id={$row['mountid']}");
            }
        }
        addnav("Close the book");
        addnav("Return from whence you came", "stables.php");
    }
    if ($op == "browse") {
        page_header("Bestiary");
        $sql = "SELECT * FROM " . db_prefix("mounts") . " WHERE mountid='{$id}'";
        $result = db_query_cached($sql, "mountdata-{$id}", 3600);
        if (db_num_rows($result) <= 0) {
            output("You find that the book is actually full of empty pages!");
        } else {
            $mount = db_fetch_assoc($result);
            $buff = unserialize($mount['mountbuff']);
            if (get_module_setting('boolshowcost') == 1) {
                output("`c`&-=%s`&=-`7`c`n`n", $mount['mountname']);
                output("`b`c`#Costs`b`c`7");
                $goldcost = "";
                $gemcost = "";
                $donationcost = "";
                $favorcost = "";
                $upgrade = "";
                if (get_module_objpref("mounts", $id, "favorcost") != 0) {
                    $favorcost = '`n' . get_module_objpref("mounts", $id, "favorcost") . ' `$Favor`7';
                }
                if (get_module_objpref("mounts", $id, "donationcost") != 0) {
                    $donationcost = '`n' . get_module_objpref("mounts", $id, "donationcost") . ' Donation Point(s)';
                }
                if ($mount['mountcostgold'] != "" && $mount['mountcostgold'] != 0) {
                    $goldcost = '`n' . $mount['mountcostgold'] . ' `^Gold`7';
                }
                if ($mount['mountcostgems'] != "" && $mount['mountcostgems'] != 0) {
                    $gemcost = '`n' . $mount['mountcostgems'] . ' `%Gem(s)`7';
                }
                if ($mount['mountfeedcost'] != "" && $mount['mountfeedcost'] != 0 && $buff['rounds'] > 0) {
                    $cost = $mount['mountfeedcost'] * $session['user']['level'];
                    $feedcost = '`nFeeding costs ' . $cost . ' `6Gold`7';
                }
                output("`c{$goldcost} {$gemcost} {$favorcost} {$donationcost} {$feedcost}`c`n");
            }
            if (get_module_objpref("mounts", $id, "buffatkmod") == "") {
                if ($buff['atkmod'] != "" && get_module_setting('toggleatkmod') == 1) {
                    $var = mountprereq_calc($buff['atkmod']);
                    $atkmod = round($var * 100 - 100, 2);
                    if ($atkmod != 0) {
                        if ($atkmod > 0) {
                            $sign1 = '+';
                        }
                        $atk = '`n' . $sign1 . $atkmod . '% attack';
                    }
                }
            } else {
                $atk = "`nAttack Modifier: " . get_module_objpref("mounts", $id, "buffatkmod");
            }
            if (get_module_objpref("mounts", $id, "buffdefmod") == "") {
                if ($buff['defmod'] != "" && get_module_setting('toggledefmod') == 1) {
                    $var0 = mountprereq_calc($buff['defmod']);
                    $defmod = round($var0 * 100 - 100, 2);
                    if ($defmod != 0) {
                        if ($defmod > 0) {
                            $sign2 = '+';
                        }
                        $def = '`n' . $sign2 . $defmod . '% defense';
                    }
                }
            } else {
                $def = "`nDefense Modifier: " . get_module_objpref("mounts", $id, "buffdefmod");
            }
            if (get_module_objpref("mounts", $id, "buffregen") == "") {
                if ($buff['regen'] != "" && get_module_setting('toggleregen') == 1) {
                    $var1 = round(mountprereq_calc($buff['regen']), 0);
                    if ($var1 != 0) {
                        if ($var1 > 0) {
                            $sign3 = '+';
                        }
                        $regen = '`n' . $sign3 . $var1 . 'HP regeneration per round';
                    }
                }
            } else {
                $regen = "`nRegen: " . get_module_objpref("mounts", $id, "buffregen");
            }
            if (get_module_objpref("mounts", $id, "buffdamageshield") == "") {
                if ($buff['damageshield'] != "" && get_module_setting('toggledamageshield') == 1) {
                    $var2 = mountprereq_calc($buff['damageshield']);
                    $damageshieldmod = round($var2 * 100, 2);
                    if ($damageshieldmod != 0) {
                        if ($damageshieldmod >= 0) {
                            $sign4 = '+';
                        }
                        $damageshield = '`n' . $sign4 . $damageshieldmod . '% damage shield';
                    }
                }
            } else {
                $damageshield = "`nDamageshield: " . get_module_objpref("mounts", $id, "buffdamageshield");
            }
            if (get_module_objpref("mounts", $id, "bufflifetap") == "") {
                if ($buff['lifetap'] != "" && get_module_setting('togglelifetap') == 1) {
                    $var3 = mountprereq_calc($buff['lifetap']);
                    $lifetapmod = round($var3 * 100, 2);
                    if ($lifetapmod != 0) {
                        if ($lifetapmod >= 0) {
                            $sign5 = '+';
                        }
                        $lifetap = '`n' . $sign5 . $lifetapmod . '% HP leech';
                    }
                }
            } else {
                $lifetap = "`nLifetap: " . get_module_objpref("mounts", $id, "bufflifetap");
            }
            if (get_module_objpref("mounts", $id, "buffminioncount") == "") {
                if ($buff['minioncount'] != "" && get_module_setting('toggleminioncount') == 1) {
                    $var4 = round(mountprereq_calc($buff['minioncount']), 0);
                    if ($var4 != 0) {
                        $minioncount = '`n' . $var4 . ' attack(s) maximum per round';
                    }
                }
            } else {
                $minioncount = "`nMaximum number of Attacks per round: " . get_module_objpref("mounts", $id, "buffminioncount");
            }
            if (get_module_objpref("mounts", $id, "buffmaxbadguydamage") == "") {
                if ($buff['maxbadguydamage'] != "" && get_module_setting('togglemaxbadguydamage') == 1) {
                    $var5 = round(mountprereq_calc($buff['maxbadguydamage']), 0);
                    if ($var5 != 0) {
                        $maxbadguydamage = '`n' . $var5 . ' maximum damage per attack';
                    }
                }
            } else {
                $maxbadguydamage = "`nMaximum damage per Attack per round: " . get_module_objpref("mounts", $id, "buffmaxbadguydamage");
            }
            if (get_module_objpref("mounts", $id, "buffbadguyatkmod") == "") {
                if ($buff['badguyatkmod'] != "" && get_module_setting('togglebadguyatkmod') == 1) {
                    $var6 = mountprereq_calc($buff['badguyatkmod']);
                    $badguyatk = round($var6 * 100 - 100, 2);
                    if ($badguyatk != 0) {
                        if ($badguyatk >= 0) {
                            $sign6 = '+';
                        }
                        $badguyatkmod = '`n' . $sign6 . $badguyatk . '% enemy attack';
                    }
                }
            } else {
                $badguyatkmod = "`nEnemy Attack Modifier: " . get_module_objpref("mounts", $id, "buffbadguyatkmod");
            }
            if (get_module_objpref("mounts", $id, "buffbadguydefmod") == "") {
                if ($buff['badguydefmod'] != "" && get_module_setting('togglebadguydefmod') == 1) {
                    $var7 = mountprereq_calc($buff['badguydefmod']);
                    $badguydef = round($var7 * 100 - 100, 2);
                    if ($badguydef != 0) {
                        if ($badguydef >= 0) {
                            $sign7 = '+';
                        }
                        $badguydefmod = '`n' . $sign7 . $badguydef . '% enemy defense';
                    }
                }
            } else {
                $badguydefmod = "`nEnemy Defense Modifier: " . get_module_objpref("mounts", $id, "buffbadguydefmod");
            }
            if (get_module_objpref("mounts", $id, "buffbadguydmgmod") == "") {
                if ($buff['badguydmgmod'] != "" && get_module_setting('togglebadguydmgmod') == 1) {
                    $var8 = mountprereq_calc($buff['badguydmgmod']);
                    $badguydmg = round($var8 * 100 - 100, 2);
                    if ($badguydmg != 0) {
                        if ($badguydmg >= 0) {
                            $sign8 = '+';
                        }
                        $badguydmgmod = '`n' . $sign8 . $badguydmg . '% enemy damage modifier';
                    }
                }
            } else {
                $badguydmgmod = "`nEnemy Damage Modifier: " . get_module_objpref("mounts", $id, "badguydmgmod");
            }
            if (get_module_objpref("mounts", $id, "buffinv") == "") {
                if ($buff['invulnerable'] != "" && get_module_setting('toggleinv') == 1) {
                    $var9 = round(mountprereq_calc($buff['invulnerable']), 0);
                    if ($var9 == 1) {
                        $var9 = "INVULNERABLE!!";
                        $inv = '`n' . $var9;
                    }
                }
            } else {
                $inv = "`nInvulnerability: " . get_module_objpref("mounts", $id, "buffinv");
            }
            if (get_module_objpref("mounts", $id, "ffs") == "") {
                if ($mount['mountforestfights'] != "" && $mount['mountforestfights'] != 0 && get_module_setting('toggleffs') == 1) {
                    $ffs = '`n' . $mount[mountforestfights] . ' extra turn(s) per day';
                }
            } else {
                $ffs = "`nExtra Forest Fights each day: " . get_module_objpref("mounts", $id, "ffs");
            }
            if (get_module_objpref("mounts", $id, "mountspd", "speed") < 0) {
                $spd = '`n' . abs(get_module_objpref("mounts", $id, "mountspd", "speed")) . ' Agility penalty';
            } elseif (get_module_objpref("mounts", $id, "mountspd", "speed") > 0) {
                $spd = '`n' . get_module_objpref("mounts", $id, "mountspd", "speed") . ' Agility bonus';
            } else {
                $spd = '';
            }
            if (get_module_objpref("mounts", $id, "buffrounds") == "") {
                if ($buff['rounds'] != "" && $buff['rounds'] != 0 && get_module_setting('toggleround') == 1) {
                    $round = $buff['rounds'];
                    if ($round < 0) {
                        $round = 'Permanent';
                    }
                    $rounds = '`n' . $round . ' Rounds';
                }
            } else {
                $rounds = "`nRounds: " . get_module_objpref("mounts", $id, "buffrounds");
            }
            if (get_module_objpref("mounts", $id, "buffname") == "") {
                if ($buff['name'] != "" && get_module_setting('togglename') == 1) {
                    $name = $buff['name'];
                }
            } else {
                $name = get_module_objpref("mounts", $id, "buffname");
            }
            if (is_module_active('mountupgrade') && get_module_setting('boolmountupgrade') == 1 && get_module_objpref("mounts", $id, "upgradeto", "mountupgrade") > 0) {
                $upgradeto = get_module_objpref("mounts", $id, "upgradeto", "mountupgrade");
                $sql = "SELECT mountname FROM " . db_prefix("mounts") . " WHERE mountid='{$upgradeto}'";
                $result = db_query($sql);
                $upgrademount = db_fetch_assoc($result);
                $upgrade = '`n`nupgrades to ' . $upgrademount['mountname'] . '`7';
                if (get_module_objpref("mounts", $id, "upgradedks") == "") {
                    if (get_module_objpref("mounts", $id, "reqdks", "mountupgrade") != "" && get_module_objpref("mounts", $id, "reqdks", "mountupgrade") != 0 && get_module_setting('toggleupgradedks') == 1) {
                        $upgradedks = '`n' . get_module_objpref("mounts", $id, "reqdks", "mountupgrade") . ' DKs required to upgrade';
                    }
                } else {
                    $upgradedks = "`nDKs required for upgrade: " . get_module_objpref("mounts", $id, "upgradedks");
                }
                if (get_module_objpref("mounts", $id, "upgradelevels") == "") {
                    if (get_module_objpref("mounts", $id, "reqlevels", "mountupgrade") != "" && get_module_objpref("mounts", $id, "reqlevels", "mountupgrade") != 0 && get_module_setting('toggleupgradelevels') == 1) {
                        $upgradelevels = '`n' . get_module_objpref("mounts", $id, "reqdks", "mountupgrade") . ' levelss required to upgrade';
                    }
                } else {
                    $upgradelevels = "`nLevels required for upgrade: " . get_module_objpref("mounts", $id, "upgradelevels");
                }
                if (get_module_objpref("mounts", $id, "upgradedays") == "") {
                    if (get_module_objpref("mounts", $id, "reqdays", "mountupgrade") != "" && get_module_objpref("mounts", $id, "reqdays", "mountupgrade") != 0 && get_module_setting('toggleupgradedays') == 1) {
                        $upgradedays = '`n' . get_module_objpref("mounts", $id, "reqdays", "mountupgrade") . ' Days required to upgrade';
                    }
                } else {
                    $upgradedays = "`nDays required for upgrade: " . get_module_objpref("mounts", $id, "upgradedays");
                }
                if (get_module_objpref("mounts", $id, "upgradeffs") == "") {
                    if (get_module_objpref("mounts", $id, "reqffs", "mountupgrade") != "" && get_module_objpref("mounts", $id, "reqffs", "mountupgrade") != 0 && get_module_setting('toggleupgradeffs') == 1) {
                        $upgradeffs = '`n' . get_module_objpref("mounts", $id, "reqffs", "mountupgrade") . ' forest fights required to upgrade';
                    }
                } else {
                    $upgradeffs = "`nForest fights required for upgrade: " . get_module_objpref("mounts", $id, "upgradeffs");
                }
                if (getmodulesetting('toggleupgradeview') && get_module_objpref("mounts", $id, "boolshowupgrade") == 1) {
                    addnav("View Upgrade");
                    addnav(array("View %s`0", $upgrademount['mountname']), "runmodule.php?module=mountprereq&op=browse&id={$upgradeto}");
                }
            }
            output("`n`b`c`@Special Abilities`7`b`c");
            output("`c`7{$name}`7 {$rounds} {$atk} {$def} {$regen} {$damageshield} {$lifetap} {$minioncount} {$maxbadguydamage} {$badguyatkmod} {$badguydefmod} {$badguydmgmod} {$ffs} {$spd} {$upgrade} {$upgradedks} {$upgradelevels} {$upgradedays} {$upgradeffs}`c`n");
            output("`n`c`b`^Ownership Requirements`7`b`c");
            $dkreq = "";
            $charmreq = "";
            $recareq = "";
            $sexreq = "";
            $donationreq = "";
            $favorreq = "";
            $alignreq = "";
            if ($mount['mountdkcost'] != 0 && $mount['mountdkcost'] != "") {
                $dkreq = "`nDragonkills: " . $mount['mountdkcost'];
            }
            if (get_module_objpref("mounts", $id, "charmreq") != 0) {
                $charmreq = "`nCharm: " . get_module_objpref("mounts", $id, "charmreq");
            }
            if (get_module_objpref("mounts", $id, "racereq") != "") {
                $racereq = "`n" . get_module_objpref("mounts", $id, "racereq") . " `0Race";
            }
            if (get_module_objpref("mounts", $id, "sexreq") != 2) {
                if (get_module_objpref("mounts", $id, "sexreq") == 0) {
                    $sex = "`!Male`7";
                } else {
                    $sex = "`rFemale`7";
                }
                $sexreq = "`n{$sex} owners";
            }
            if (get_module_objpref("mounts", $id, "favorreq") != 0) {
                $favorreq = "`nFavor: " . get_module_objpref("mounts", $id, "favorreq");
            }
            if (get_module_objpref("mounts", $id, "donationreq") != 0) {
                $donationreq = "`nDonation Points: " . get_module_objpref("mounts", $id, "donationreq");
            }
            if (is_module_active('alignment') && get_module_objpref("mounts", $id, "boolalign") != 0) {
                if (get_module_objpref("mounts", $id, "boolalign") == 1) {
                    $align = "`nBelow `4" . get_module_objpref("mounts", $id, "alignlo") . "`7 alignment.`n";
                } elseif (get_module_objpref("mounts", $id, "boolalign") == 3) {
                    $align = "`nAbove `@" . get_module_objpref("mounts", $id, "alignhi") . "`7 alignment.`n";
                } else {
                    $align = "`nBetween `4" . get_module_objpref("mounts", $id, "alignlo") . "`7 and `@" . get_module_objpref("mounts", $id, "alignhi") . "`7 alignment.";
                }
            }
            output("`c{$dkreq} {$charmreq} {$favorreq} {$alignreq} {$donationreq} {$racereq} {$sexreq}`7 {$align}`0`c`n");
            if (is_module_active('mountrarity') && get_module_setting('boolmountrarity') == 1 && get_module_objpref("mounts", $id, "rarity", "mountrarity") != 100) {
                $rare = get_module_objpref("mounts", $id, "rarity", "mountrarity");
                if ($rare <= 20) {
                    $raretext = '`b`$extremely rare`b`7!!';
                } elseif ($rare <= 40) {
                    $raretext = '`@rare`7!';
                } elseif ($rare <= 60) {
                    $raretext = 'uncommon.';
                } elseif ($rare <= 80) {
                    $raretext = 'common.';
                } else {
                    $raretext = 'very common.';
                }
                output("`n`c`b`&Miscellaneous Infomation`c`b");
                output("`c`7The`& %s`7 is %s`c`n", $mount['mountname'], $raretext);
            }
            if (get_module_objpref("mounts", $id, "outputtext") != "") {
                output("`n`c`Q`i%s`7`i`c`n", stripslashes(get_module_objpref("mounts", $id, "outputtext")));
            }
            addnav("Go Back");
            addnav("Flip back to the Contents page", "runmodule.php?module=mountprereq&op=bestiary");
        }
    }
    page_footer();
}
function creaturetargets_dohook($hookname, $args)
{
    global $session, $enemies;
    switch ($hookname) {
        case "buffbadguy":
            if (get_module_objpref("creatures", $args['creatureid'], "usetargets") == 1) {
                for ($i = 1; $i <= 6; $i++) {
                    $args['target' . $i . '']['name'] = get_module_objpref("creatures", $args['creatureid'], "target" . $i . "");
                    $args['target' . $i . '']['hitpoints'] = round($args['creaturehealth'] / 100 * get_module_objpref("creatures", $args['creatureid'], "hitpoints" . $i . ""));
                    $args['target' . $i . '']['killatk'] = get_module_objpref("creatures", $args['creatureid'], "killatk" . $i . "");
                    $args['target' . $i . '']['killdef'] = get_module_objpref("creatures", $args['creatureid'], "killdef" . $i . "");
                    $args['target' . $i . '']['killhp'] = get_module_objpref("creatures", $args['creatureid'], "killhp" . $i . "");
                    $args['target' . $i . '']['killmsg'] = get_module_objpref("creatures", $args['creatureid'], "killmsg" . $i . "");
                    $args['target' . $i . '']['hitatk'] = get_module_objpref("creatures", $args['creatureid'], "hitatk" . $i . "");
                    $args['target' . $i . '']['hitdef'] = get_module_objpref("creatures", $args['creatureid'], "hitdef" . $i . "");
                    $args['target' . $i . '']['hitmsg'] = get_module_objpref("creatures", $args['creatureid'], "hitmsg" . $i . "");
                    $args['target' . $i . '']['currenttarget'] = 0;
                }
            }
            //Check to see if there's an AI Script involved with this creature, and if not, tell battle.php (via our modifications) to execute our AI Script at the start of the round, not the end - as long as we're actually using multiple hit targets with this creature, of course
            if ($args['target1']['hitpoints'] != 0) {
                if ($args['creatureaiscript'] == '') {
                    $args['creatureaiscript'] = "require(\"ai/creaturetargetai.php\");";
                }
            }
            //Give the creature a set of starting hitpoints, because it's SO DAMNED USEFUL
            $args['creaturestartinghealth'] = $args['creaturehealth'];
            debug($args['creaturestartinghealth']);
            //Set the phase for the AI Script and move on
            $args['phase'] = 1;
            // debug("Debugging args after creatureencounter");
            // debug ($args);
            return $args;
            break;
        case "battle":
            foreach ($enemies as $index => $badguy) {
                $badguy['oldhitpoints'] = $badguy['creaturehealth'];
                $enemies[$index] = $badguy;
            }
            //		debug("Debugging enemies at battle");
            //		debug($enemies);
            break;
        case "apply-specialties":
            foreach ($enemies as $index => $badguy) {
                $skill = httpget('skill');
                $target = httpget('target');
                if ($badguy['istarget'] == 1) {
                    if ($skill == "target") {
                        require_once "modules/staminasystem/lib/lib.php";
                        $return = process_action("Fighting - Targeted");
                        if ($return['lvlinfo']['levelledup'] == true) {
                            output("`n`c`b`0You gained a level in Targeted Fighting!  You are now level %s!  This action will cost fewer Stamina points now.`b`c`n", $return['lvlinfo']['newlvl']);
                        }
                        //					debug("Altering creature stats");
                        //First grab and save the current attack and defence stats, so we can revert back in the next round
                        $badguy['oldcreatureattack'] = $badguy['creatureattack'];
                        $badguy['oldcreaturedefense'] = $badguy['creaturedefense'];
                        //Now change the values for hitting the relevant target
                        $badguy['creatureattack'] = $badguy['creatureattack'] * $badguy['target' . $target . '']['hitatk'];
                        $badguy['creaturedefense'] = $badguy['creaturedefense'] * $badguy['target' . $target . '']['hitdef'];
                        // Set this target as the target being... targeted, I guess.
                        $badguy['target' . $target . '']['currenttarget'] = 1;
                        //Tell the AI Script to put the stats back the way they were
                        $badguy['revert'] = 1;
                        //Output the hit message.  We're using a buff so that it goes in the right place in the text.  The atkmod is only there to force the buff to output the start message.
                        apply_buff("creaturetargets", array("rounds" => 1, "startmsg" => array("%s", stripslashes($badguy['target' . $target . '']['hitmsg'])), "atkmod" => 1, "schema" => "module-creaturetargets"));
                    }
                }
                $enemies[$index] = $badguy;
            }
            //		debug("Debugging enemies after apply-specialties");
            //		debug($enemies);
            break;
        case "fightnav-specialties":
            $script = $args['script'];
            require_once "modules/staminasystem/lib/lib.php";
            $cost = stamina_getdisplaycost("Fighting - Targeted");
            foreach ($enemies as $index => $badguy) {
                for ($i = 1; $i <= 6; $i++) {
                    if ($badguy['istarget'] == 1 && $badguy['target' . $i . '']['hitpoints'] > 0) {
                        addnav(array("Targeting (`Q+%s%%`0)", $cost));
                        addnav(array("Aim for the %s", $badguy['target' . $i . '']['name']), $script . "op=fight&skill=target&target=" . $i . "", true);
                    }
                }
            }
            break;
    }
    return $args;
}
function meatsystem_run()
{
    global $session;
    require_once "modules/staminasystem/lib/lib.php";
    page_header("Meat!");
    addnav("Meat Skills");
    $from = httpget('from');
    switch (httpget('op')) {
        case "devour":
            //special ability for Zombies only - Zombies can eat raw meat, so we're giving them the ability to simply devour the carcass where it lies.
            $carcasses = unserialize(get_module_pref("carcasses"));
            if (!is_array($carcasses)) {
                $carcasses = array();
            }
            debug($carcasses);
            foreach ($carcasses as $carcassnum => $creatureid) {
                $sql = "SELECT creaturename FROM " . db_prefix("creatures") . " WHERE creatureid = " . $creatureid . " ";
                $result = db_query_cached($sql, "creaturename-" . $creatureid, 86400);
                $creature = db_fetch_assoc($result);
                output("Giving in to your primal urges, you lean down and begin ripping meat from the still-twitching %s with your teeth.`n`n", $creature['creaturename']);
                $meat1 = get_module_objpref("creatures", $creatureid, "meat1");
                $meat2 = get_module_objpref("creatures", $creatureid, "meat2");
                $meat3 = get_module_objpref("creatures", $creatureid, "meat3");
                for ($i = 0; $i < $meat1; $i++) {
                    increment_module_pref("nutrition", 1, "staminafood");
                    increment_module_pref("fat", 3, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(1000);
                }
                for ($i = 0; $i < $meat2; $i++) {
                    increment_module_pref("nutrition", 2, "staminafood");
                    increment_module_pref("fat", 2, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(2000);
                }
                for ($i = 0; $i < $meat3; $i++) {
                    increment_module_pref("nutrition", 3, "staminafood");
                    increment_module_pref("fat", 1, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(5000);
                }
                output("For the record, and since it's nice to know these things even if you're too busy tearing cartilage and muscle from the bone to really pay attention to them, in this meal you have eaten %s bite's-worth of Crap Meat, %s bite's-worth of Half-Decent Meat, and %s bite's-worth of Tasty Meat.`n", $meat1, $meat2, $meat3);
                $full = get_module_pref("fullness", "staminafood");
                if ($full < 0) {
                    output("You still feel as though you haven't eaten in days.`n`n");
                }
                if ($full >= 0 && $full < 50) {
                    output("You feel a little less hungry.`n`n");
                }
                if ($full >= 50 && $full < 100) {
                    output("You still feel as though you've got room for more!`n`n");
                }
                if ($full >= 100) {
                    output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
                }
                unset($carcasses[$carcassnum]);
                set_module_pref("carcasses", serialize($carcasses));
            }
            break;
        case "clean":
            $creatureid = httpget('creatureid');
            $carcass = httpget('carcass');
            $meat1 = get_module_objpref("creatures", $creatureid, "meat1");
            $meat2 = get_module_objpref("creatures", $creatureid, "meat2");
            $meat3 = get_module_objpref("creatures", $creatureid, "meat3");
            $amber = get_stamina();
            $return = process_action("Cleaning the Carcass");
            if ($return['lvlinfo']['levelledup'] == true) {
                output("`n`c`b`0You gained a level in Cleaning Carcasses!  You are now level %s!  This action will cost fewer Stamina points now, so you can butcher more creatures each day!`b`c`n", $return['lvlinfo']['newlvl']);
            }
            $failchance = e_rand(0, 100);
            if ($failchance > $amber) {
                //failure - the nice meat gets turned into Crap Meat
                $meat1 += $meat2;
                $meat1 += $meat3;
                output("`4You sit down to clean the carcass.  Your exhausted, clumsy incisions make a mockery of the choicest cuts - what is left over can only be described as Crap Meat.  %s bite's-worth, to be precise.  It looks like it was hacked into chunks by a blind woodsman.", $meat1);
                //todo
                for ($i = 0; $i < $meat1; $i++) {
                    give_item("meat_low", false, false, true);
                }
                load_inventory();
                $carcasses = unserialize(get_module_pref("carcasses"));
                unset($carcasses[$carcass]);
                $carcasses = array_values($carcasses);
                set_module_pref("carcasses", serialize($carcasses));
            } else {
                //success - all meat is sorted
                output("You spend a few minutes up to your elbows in gore, and getting rather hungry.`n");
                if ($meat1 > 0) {
                    output("You tear off enough to make %s rough bite's-worth of what the locals affectionately call Crap Meat.  It's mostly wobbling chunks of stinking yellow fat, intermingled with the occasional squirmy tendon.`n", $meat1);
                }
                if ($meat2 > 0) {
                    output("You make swift work of the fattier muscle, and before too long you have %s rough bite's-worth of Half-Decent Meat.`n", $meat2);
                }
                if ($meat3 > 0) {
                    output("The red, tender slivers of muscle slide easily from the bone, and you wind up with %s rough bite's-worth of Tasty Meat.`n", $meat3);
                }
                //todo
                for ($i = 0; $i < $meat1; $i++) {
                    give_item("meat_low", false, false, true);
                }
                for ($i = 0; $i < $meat2; $i++) {
                    give_item("meat_medium", false, false, true);
                }
                for ($i = 0; $i < $meat3; $i++) {
                    give_item("meat_high", false, false, true);
                }
                load_inventory();
                $carcasses = unserialize(get_module_pref("carcasses"));
                unset($carcasses[$carcass]);
                $carcasses = array_values($carcasses);
                set_module_pref("carcasses", serialize($carcasses));
                $pmeat1 = has_item("meat_low");
                $pmeat2 = has_item("meat_medium");
                $pmeat3 = has_item("meat_high");
                if (($pmeat1 || $pmeat2 || $pmeat3) && $session['user']['race'] != "Robot") {
                    if (get_module_pref("fullness", "staminafood") < 100) {
                        $cookcost = stamina_getdisplaycost("Cooking");
                        addnav(array("Cook up some meat (`Q%s%%`0)", $cookcost), "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                    } else {
                        addnav("You're too full to cook, let alone eat", "");
                    }
                }
            }
            break;
        case "cook":
            $pmeat1qty = has_item_quantity("meat_low");
            $pmeat2qty = has_item_quantity("meat_medium");
            $pmeat3qty = has_item_quantity("meat_high");
            output("You whip out your camping stove.  It's time to cook!`n`nWhat will you put in the pan?  You can fit up to 20 bite's-worth of meat in there.  Right now you have %s bite's-worth of Crap Meat, %s bite's-worth of Half-Decent Meat, and %s bite's-worth of Tasty Meat.`n`n", $pmeat1qty, $pmeat2qty, $pmeat3qty);
            rawoutput("<form action='runmodule.php?module=meatsystem&op=cookfinal&from=" . $from . "' method='POST'>");
            rawoutput("Put in <input name='meat1' width='2' value='0'> bite's-worth of Crap Meat.<br />");
            rawoutput("Put in <input name='meat2' width='2' value='0'> bite's-worth of Half-Decent Meat.<br />");
            rawoutput("Put in <input name='meat3' width='2' value='0'> bite's-worth of Tasty Meat.<br />");
            rawoutput("<input type='submit' class='button' value='" . translate_inline("Cook!") . "'>");
            rawoutput("</form>");
            addnav("", "runmodule.php?module=meatsystem&op=cookfinal&from=" . $from);
            break;
        case "cookfinal":
            $pmeat1qty = has_item_quantity("meat_low");
            $pmeat2qty = has_item_quantity("meat_medium");
            $pmeat3qty = has_item_quantity("meat_high");
            $meat1 = httppost("meat1");
            $meat2 = httppost("meat2");
            $meat3 = httppost("meat3");
            //check for the dumbass player cooking meat that they don't have
            if ($meat1 > $pmeat1qty || $meat2 > $pmeat2qty || $meat3 > $pmeat3qty) {
                output("You don't `ihave`i that much meat!`n`n");
                addnav("Whoops");
                addnav("Sorry, I forgot how to count for a second there.  Let's try this again.", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player inputting a negative number
            if ($meat1 < 0 || $meat2 < 0 || $meat3 < 0) {
                page_header("Either taking vegetarianism to whole new levels, or trying to grow meat from an empty pan");
                output("You want to cook `inegative`i meat?  How very Zen of you.`n`n");
                addnav("You sneaky bugger");
                addnav("Abandon your efforts to produce the opposite of meat and try again, pretending that you weren't just trying to cheat.", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player trying to put too much meat in the pan
            $totalmeat = $meat1 + $meat2 + $meat3;
            if ($totalmeat > 20) {
                output("Your pan can't hold that much meat, pal.`n`n");
                addnav("Whoops");
                addnav("Try again, without filling the pan up so much", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player trying to cook no meat at all
            $totalmeat = $meat1 + $meat2 + $meat3;
            if ($totalmeat == 0) {
                output("You start the process of cooking up your tasty meat.  After a few minutes of poking around in your pan, growing hungrier by the second, you realise that you've forgotten something.`n`n");
                addnav("Whoops");
                addnav("Try again, with meat this time", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //Stamina interaction, including consequences and level-up details.
            $amber = get_stamina();
            $return = process_action("Cooking");
            if ($return['lvlinfo']['levelledup'] == true) {
                output("`n`c`b`0You gained a level in Cooking!  You are now level %s!  This action will cost fewer Stamina points now, so you can cook more tasty meals each day!`b`c`n", $return['lvlinfo']['newlvl']);
            }
            $failchance = e_rand(0, 100);
            if ($failchance > $amber) {
                output("`4You put your meat into the pan, and sit down to stir-fry it.  The hypnotic motion and white-noise sizzling, combined with your tiredness, sends you staring into space.  While your concentration is impaired, the meat bursts into flames.  You jerk back into awareness, and look down sadly at the flaming chunks.  Bummer.");
                for ($i = 0; $i < $meat1; $i++) {
                    delete_item(has_item("meat_low"));
                }
                for ($i = 0; $i < $meat2; $i++) {
                    delete_item(has_item("meat_medium"));
                }
                for ($i = 0; $i < $meat3; $i++) {
                    delete_item(has_item("meat_high"));
                }
                break;
            }
            //we can now assume that the player is not some sort of cheating reprobate, or trying to cook while dog-tired, and do some cooking!
            for ($i = 0; $i < $meat1; $i++) {
                increment_module_pref("nutrition", 1, "staminafood");
                increment_module_pref("fat", 3, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_low"));
                addstamina(1000);
            }
            for ($i = 0; $i < $meat2; $i++) {
                increment_module_pref("nutrition", 2, "staminafood");
                increment_module_pref("fat", 2, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_medium"));
                addstamina(2000);
            }
            for ($i = 0; $i < $meat3; $i++) {
                increment_module_pref("nutrition", 3, "staminafood");
                increment_module_pref("fat", 1, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_high"));
                addstamina(5000);
            }
            output("You fry up your lovely meaty loveliness, and sit down to eat.  You gain some Stamina!`n`n");
            $full = get_module_pref("fullness", "staminafood");
            if ($full < 0) {
                output("You still feel as though you haven't eaten in days.`n`n");
            }
            if ($full >= 0 && $full < 50) {
                output("You feel a little less hungry.`n`n");
            }
            if ($full >= 50 && $full < 100) {
                output("You still feel as though you've got room for more!`n`n");
            }
            if ($full >= 100) {
                output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
            }
            break;
    }
    $carcasses = unserialize(get_module_pref("carcasses"));
    if (!is_array($carcasses)) {
        $carcasses = array();
    }
    if (count($carcasses) > 0) {
        output("You look at the spoils of your most recent battle.  They lie bloodied and broken on the ground.  What will you do with them?");
        foreach ($carcasses as $carcassnum => $creatureid) {
            $sql = "SELECT creaturename FROM " . db_prefix("creatures") . " WHERE creatureid = " . $creatureid . " ";
            $result = db_query_cached($sql, "creaturename-" . $creatureid, 86400);
            $creature = db_fetch_assoc($result);
            $cleancost = stamina_getdisplaycost("Cleaning the Carcass");
            addnav(array("Clean the carcass of %s (`Q%s%%`0)", $creature['creaturename'], $cleancost), "runmodule.php?module=meatsystem&op=clean&creatureid=" . $creatureid . "&carcass=" . $carcassnum . "&from=" . $from);
        }
    } else {
        if (httpget('op') != "cook" && httpget('op') != "cookfinal") {
            output("Now only bloody bones lie strewn around the area.`n`n");
        }
    }
    addnav("Ah, screw it.");
    if ($from == "forest") {
        addnav("Return to the Jungle", "forest.php");
    } else {
        if ($from == "world") {
            addnav("Return to the World Map", "runmodule.php?module=worldmapen&op=continue");
        }
    }
    page_footer();
    return true;
}
function calculate_level()
{
    global $session;
    $cost = unserialize(get_module_setting("costarray"));
    $total = 0;
    if (get_module_setting("allowatk") && get_module_objpref("clans", $session['user']['clanid'], "atkactive")) {
        $total += $cost['atk']['active'];
        $total += $cost['atk'][get_module_objpref("clans", $session['user']['clanid'], "atklevel")];
    }
    if (get_module_setting("allowdef") && get_module_objpref("clans", $session['user']['clanid'], "defactive")) {
        $total += $cost['def']['active'];
        $total += $cost['def'][get_module_objpref("clans", $session['user']['clanid'], "deflevel")];
    }
    if (get_module_setting("allowdrain") && get_module_objpref("clans", $session['user']['clanid'], "drainactive")) {
        $total += $cost['drain']['active'];
        $total += $cost['drain'][get_module_objpref("clans", $session['user']['clanid'], "drainlevel")];
    }
    if (get_module_setting("allowthorn") && get_module_objpref("clans", $session['user']['clanid'], "thornactive")) {
        $total += $cost['thorn']['active'];
        $total += $cost['thorn'][get_module_objpref("clans", $session['user']['clanid'], "thornlevel")];
    }
    if (get_module_setting("allowregen") && get_module_objpref("clans", $session['user']['clanid'], "regenactive")) {
        $total += $cost['regen']['active'];
        $total += $cost['regen'][get_module_objpref("clans", $session['user']['clanid'], "regenlevel")];
    }
    $total += $cost['round'][get_module_objpref("clans", $session['user']['clanid'], "roundlevel")];
    if (get_module_setting("allowult") && get_module_objpref("clans", $session['user']['clanid'], "ultactive")) {
        $total += $cost['ult']['active'];
    }
    if ($total == $cost['ult']['allow']) {
        set_module_objpref("clans", $session['user']['clanid'], "ultready", 1);
    }
    $total = round($total / $cost['total'] * 100, 1);
    set_module_objpref("clans", $session['user']['clanid'], "totallevel", $total);
}
function worldmapen_encounter($x, $y, $z = 1)
{
    global $session;
    $terrain = worldmapen_getTerrain($x, $y, $z);
    $id = $session['user']['hashorse'];
    // debug("Worldmap lib.php is debugging base terrain encounter rate");
    // debug($terrain['encounter']);
    if ($id != 0) {
        switch ($terrain['type']) {
            case "Plains":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterPlains");
                break;
            case "Forest":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterForest");
                break;
            case "River":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterRiver");
                break;
            case "Ocean":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterOcean");
                break;
            case "Desert":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterDesert");
                break;
            case "Swamp":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterSwamp");
                break;
            case "Mount":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterMount");
                break;
            case "Snow":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterSnow");
                break;
            case "Earth":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterEarth");
                break;
            case "Air":
                $terrain['encounter'] = $terrain['encounter'] * get_module_objpref("mounts", $id, "encounterAir");
                break;
        }
    }
    //Interaction with Stamina system - increases encounter rate by 1% for every percentage point of player's Amber stamina used
    if (get_module_setting("usestamina") == 1) {
        require_once 'modules/staminasystem/lib/lib.php';
        $amber = get_stamina();
        if ($amber < 100) {
            output("`4You are getting tired`0.  Monsters have a tendency to swarm towards contestants who look like they're half-asleep.  You might want to consider setting up camp, or doing something to raise your Stamina.`n");
        }
        $add = 100 - $amber;
        $terrain['encounter'] += $add;
    }
    return $terrain['encounter'];
}
         $args['toomany'] = get_module_setting("bartendername") . " `3apologizes, \"`&You've cleaned the place out.`3\"";
         $array = array("title", "barkeep", "return", "demand", "toodrunk", "toomany", "drinksubs");
         $schemas = array();
         foreach ($array as $val) {
             $schemas[$val] = "module-marriage";
         }
         $args['schemas'] = $schemas;
         $args['drinksubs'] = array("/^he/" => "^" . (get_module_setting('genderbartender') ? translate_inline("she") : translate_inline("he")), "/ he/" => " " . (get_module_setting('genderbartender') ? translate_inline("she") : translate_inline("he")), "/^his/" => "^" . (get_module_setting('genderbartender') ? translate_inline("her") : translate_inline("his")), "/ his/" => " " . (get_module_setting('genderbartender') ? translate_inline("her") : translate_inline("his")), "/^him/" => "^" . (get_module_setting('genderbartender') ? translate_inline("her") : translate_inline("him")), "/ him/" => " " . (get_module_setting('genderbartender') ? translate_inline("her") : translate_inline("him")), "/{barkeep}/" => get_module_setting("bartendername"), "/Violet/" => translate_inline("a stranger"), "/Seth/" => translate_inline("a stranger"));
     }
     break;
 case "drinks-check":
     $allprefs = unserialize(get_module_pref('allprefs'));
     if ($allprefs['inShack'] == 1) {
         $args['allowdrink'] = get_module_objpref('drinks', $args['drinkid'], 'drinkLove');
     } else {
         $args['allowdrink'] = get_module_objpref('drinks', $args['drinkid'], 'loveOnly');
     }
     break;
 case "moderate":
     if (get_module_setting('oc') == 0) {
         $args['marriage'] = 'The Chapel';
     } else {
         $args['marriage'] = 'The Old Church';
     }
     if (get_module_setting('flirttype') == 1) {
         $args['loveshack'] = 'The Loveshack';
     }
     break;
 case "newday":
     require_once "modules/marriage/marriage_func.php";
     $allprefs = unserialize(get_module_pref('allprefs'));
	
	if($reset==1){
		output("`4You throw every scrap of paper that you can find into the open fire. You should remember what profit was made today, but to be sure you start a new page in your register and only add information starting now.`n`n`n");
		
		$sql = "UPDATE " . db_prefix(dwinns) . " SET statroomsprofit=0, statmealsprofit=0, statdrinksprofit=0, statrooms=0, statdrinks=0, statmeals=0, statmealsbought=0, statticks=0	WHERE dwid='$dwid'";
	 	db_query($sql);
				
	}

	$sql = "SELECT * FROM " . db_prefix("dwinns") . " WHERE dwid='$dwid'";
	$result = db_query($sql);
	$row = db_fetch_assoc($result);
	
	$guards = get_module_objpref("dwellings", $dwid, "bought", "dwellings_pvp");
	if($guards==0) $guard=translate_inline("No");
	else $guard=translate_inline("Yes, for %s more days",get_module_objpref("dwellings", $dwid, "run-out", "dwellings_pvp"));
	
	output("`2From bills and receipts on little scraps of paper (and oddly enough, a sock) from dozens of clerks and maids you try to figure out exactly if you're actually making money out of this place.`n`n");
	output("`2The following statistics are only accurate up to the time you last burned your bills and receipts.`n`n");
	output("`2%s `2name: `&%s`n",$dwname,$row2['name']);	
	
	rawoutput("<br><hr><br>");
	
	output("`QNumber of rooms: `&%s`n",$row['rooms']);	
	output("`QNumber of stars: `&%s`n",$row['stars']);	
	output("`QNumber of guests during the last %s days: `&%s`n",$row['statticks'],$row['statrooms']);	
	output("`QProfit made from rooms during the last %s days: `&%s gold`n",$row['statticks'],$row['statroomsprofit']*0.9);	
	output("`QProfit made from rooms today: `&%s gold`n",$row['logrooms']*0.9);	
	if($row['statroomsprofit']+$row['statmealsprofit']+$row['statdrinksprofit']>0){
		$total=($row['statroomsprofit']+$row['statmealsprofit']+$row['statdrinksprofit']);
		$percentrooms = round($row['statroomsprofit']/$total*100);
<?
	$dwname = get_module_setting("dwname","dwinns");
	if(get_module_objpref("city",$args['cityid'],"showdwinns")){
		output("  `2The newest addition to the dwellings area seems to be player owned %s`2, which seem to be under some remodeling still.`0",translate_inline(get_module_setting("dwnameplural")));
		if($args['allowbuy']==1 && $session['user']['dragonkills']>=get_module_setting("dkreq")){
			$cityid=$args['cityid'];
			addnav("Options");
			addnav(array("Establish a %s",translate_inline(ucfirst($dwname))),"runmodule.php?module=dwellings&op=buy&type=dwinns&subop=presetup&cityid=$cityid");
		}
	}
	$tname = translate_inline("Name");
	$tstars = translate_inline("Stars");
	$tdesc = translate_inline("Description");
	$enter = translate_inline("Enter");
	$location = $session['user']['location'];
	$sql = "SELECT name, dwid, windowpeer FROM " . db_prefix("dwellings") . " WHERE type='dwinns' AND status=1 AND location='$location'";
	$result = db_query($sql);
	if (db_num_rows($result)>0){
	 output("`n`n`n`n`cYou can find music, screaming and ale flowing out of the following establishments:`c`n");
	 rawoutput("<table border='0' cellpadding='3' cellspacing='0' align='center'><tr class='trhead'><td style=\"width:150px\">$tname</td><td style='width:350px' align=center>$tdesc</td><td align=center>$tstars</td><td align=center style='width:75px'>&nbsp;</td></tr>"); 
	
	 for($i = 0; $i < db_num_rows($result); $i++){
	 	$row = db_fetch_assoc($result);
	 	if($row['name']==""){
	 		$name = translate_inline("Unnamed");
	 	}else{
	 		$name = $row['name'];
	 	}
	 	$rdwid = $row['dwid'];
	 	$name = appoencode($name);
		$sql2 = "SELECT stars, closed FROM " . db_prefix("dwinns") . " WHERE dwid=$rdwid";