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 eboy_updateprices()
{
    global $session;
    $eboy_info = get_items_with_settings("eboy");
    require_once "modules/cityprefs/lib.php";
    $cid = get_cityprefs_cityid("location", $session['user']['location']);
    $sql = "SELECT count(acctid) AS c FROM " . db_prefix("accounts") . " WHERE locked=0";
    $result = db_query($sql);
    $row = db_fetch_assoc($result);
    $totalplayers = $row['c'];
    foreach ($eboy_info as $item => $settings) {
        if ($settings['eboy_stock_' . $cid]) {
            if (!$settings['eboy_multiplier_' . $cid] || !isset($settings['eboy_multiplier_' . $cid])) {
                $settings['eboy_multiplier_' . $cid] = 1;
            }
            $newprice = round($totalplayers / $settings['eboy_stock_' . $cid] * $settings['eboy_multiplier_' . $cid]);
            set_item_setting("eboy_price_" . $cid, $newprice, $item);
            $eboy_info['eboy_price_' . $cid] = $newprice;
        } else {
            if (!$settings['eboy_multiplier_' . $cid] || !isset($settings['eboy_multiplier_' . $cid])) {
                $settings['eboy_multiplier_' . $cid] = 1;
            }
            $newprice = round($totalplayers * $settings['eboy_multiplier_' . $cid]);
            set_item_setting("eboy_price_" . $cid, $newprice, $item);
            $eboy_info['eboy_price_' . $cid] = $newprice;
        }
        if ($settings['eboy_price_' . $cid] < 10) {
            set_item_setting("eboy_price_" . $cid, 10, $item);
        }
    }
}
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 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;
}
<?php

// Already on the top of the run function...
//		checkday();
if ($cityid == "") {
    require_once "modules/cityprefs/lib.php";
    $cityid = get_cityprefs_cityid("location", $session['user']['location']);
}
$subop = httpget('subop');
$costgems = get_module_setting("gemcost", $type);
$costgold = get_module_setting("goldcost", $type);
$dwname = translate_inline(get_module_setting("dwname", $type));
$sql = "SELECT COUNT(dwid) AS count FROM " . db_prefix("dwellings") . " WHERE location='" . $session['user']['location'] . "' and type='" . $type . "'";
$result = db_query($sql);
$row = db_fetch_assoc($result);
$typesumloc = $row['count'];
//for location limit on types
$sql = "SELECT COUNT(dwid) AS count FROM " . db_prefix("dwellings") . " WHERE ownerid=" . $session['user']['acctid'] . "";
$result = db_query($sql);
$row = db_fetch_assoc($result);
$globsum = $row['count'];
//for global limit
$sql = "SELECT COUNT(dwid) AS count FROM " . db_prefix("dwellings") . " WHERE location='" . $session['user']['location'] . "' and ownerid=" . $session['user']['acctid'] . " and type='{$type}'";
$result = db_query($sql);
$row = db_fetch_assoc($result);
$usertypesumloc = $row['count'];
//for location limit on types by owner
$sql = "SELECT COUNT(dwid) AS count FROM " . db_prefix("dwellings") . " WHERE type='{$type}'";
$result = db_query($sql);
$row = db_fetch_assoc($result);
$usertypesumglobal = $row['count'];
function onslaught_checkwalls($cid = "none")
{
    global $session;
    if ($cid == "none") {
        require_once "modules/cityprefs/lib.php";
        $cid = get_cityprefs_cityid("location", $session['user']['location']);
    }
    $def = get_module_objpref("city", $cid, "defences");
    $def = round($def);
    return $def;
}