function items_world_map_gathering_showgather($loc = false)
{
    if (!$loc) {
        $loc = get_module_pref("worldXYZ", "worldmapen");
    }
    list($worldmapX, $worldmapY, $worldmapZ) = explode(",", $loc);
    require_once "modules/worldmapen/lib.php";
    $terrain = worldmapen_getTerrain($worldmapX, $worldmapY, $worldmapZ);
    if ($terrain['type'] == "Forest") {
        $equipment = get_items_with_prefs("treechopping");
        if (is_array($equipment)) {
            require_once "modules/staminasystem/lib/lib.php";
            if (mass_suspend_stamina_buffs("wlimit")) {
                $restorebuffs = true;
            }
            addnav("Material Gathering");
            foreach ($equipment as $key => $vals) {
                //debug($vals);
                $displaycost = stamina_getdisplaycost("Logging");
                addnav(array("Cut wood using %s (`Q%s%%`0)", $vals['verbosename'], $displaycost), "runmodule.php?module=items_world_map_gathering&mat=wood&item=" . $vals['item']);
            }
        }
    } else {
        if ($terrain['type'] == "Mount") {
            $equipment = get_items_with_prefs("rockbreaking");
            if (is_array($equipment)) {
                require_once "modules/staminasystem/lib/lib.php";
                if (mass_suspend_stamina_buffs("wlimit")) {
                    $restorebuffs = true;
                }
                addnav("Material Gathering");
                foreach ($equipment as $key => $vals) {
                    //				debug($vals);
                    $displaycost = stamina_getdisplaycost("Stonecutting");
                    addnav(array("Break stone using %s (`Q%s%%`0)", $vals['verbosename'], $displaycost), "runmodule.php?module=items_world_map_gathering&mat=stone&item=" . $vals['item']);
                }
            }
        }
    }
    if ($restorebuffs) {
        restore_all_stamina_buffs();
    }
}
function improbablehousing_show_build_jobs($house)
{
    //run through the build jobs and show percentage to completion, along with navs to use the relevant item and its associated Stamina cost.
    //For easyness, don't allow the player to build if they're in Amber stamina
    $jobs = $house['data']['buildjobs'];
    require_once "modules/staminasystem/lib/lib.php";
    if (mass_suspend_stamina_buffs("wlimit")) {
        $restorebuffs = true;
    }
    $storestock = $house['data']['store'];
    $displayjobs = array();
    if (count($jobs)) {
        foreach ($jobs as $key => $vals) {
            if (!isset($displayjobs[$vals['name']])) {
                addnav(array("%s", $vals['name']));
                foreach ($vals['jobs'] as $skey => $svals) {
                    $cando = 1;
                    $displayjobs[$vals['name']][$svals['name']]['req'] = $svals['req'];
                    $displayjobs[$vals['name']][$svals['name']]['done'] = $svals['done'];
                    //check completion
                    if ($svals['completed']) {
                        $cando = 0;
                    }
                    //Check Stamina
                    if (get_stamina() < 100) {
                        $cando = 0;
                        $nostam = 1;
                        $displayjobs[$vals['name']][$svals['name']]['nostamina'] = true;
                    }
                    $store = array();
                    $player = array();
                    foreach ($svals['iitems'] as $ikey => $iitem) {
                        $store[$ikey] = $house['data']['store'][$ikey];
                        if (has_item($ikey)) {
                            $player[$ikey] = 1;
                        }
                    }
                    //check that each item required is present in either the store or the player's inventory... this could be neater...
                    $svals['useplayer'] = true;
                    foreach ($svals['iitems'] as $ikey => $iitem) {
                        if (!$store[$ikey] && !$player[$ikey]) {
                            $cando = 0;
                            $displayjobs[$vals['name']][$svals['name']]['noitem'] = true;
                        }
                        if ($store[$ikey] > 0) {
                            $svals['usestore'] = true;
                        }
                        if (!$player[$ikey]) {
                            $svals['useplayer'] = false;
                        }
                    }
                    // debug($store);
                    // debug($player);
                    if ($cando) {
                        $scost = 0;
                        foreach ($svals['actions'] as $akey => $action) {
                            $scost += stamina_getdisplaycost($akey);
                        }
                        if ($svals['useplayer']) {
                            addnav(array("%s (`Q%s%%`0)", $svals['name'], $scost), "runmodule.php?module=improbablehousing&op=build&hid=" . $house['id'] . "&job=" . $key . "&subjob=" . $skey);
                        }
                        if ($svals['usestore']) {
                            addnav(array("%s (using store) (`Q%s%%`0)", $svals['name'], $scost), "runmodule.php?module=improbablehousing&op=build&hid=" . $house['id'] . "&job=" . $key . "&subjob=" . $skey . "&store=true");
                        }
                    }
                }
            }
        }
    }
    if (count($displayjobs)) {
        output("`b`0Current Construction Jobs`b`n");
        foreach ($displayjobs as $job => $sub) {
            output_notl("`0->%s`n", $job);
            foreach ($sub as $sjob => $vals) {
                $jobout = "<table><tr><td>";
                require_once "lib/bars.php";
                $bar = fadebar($vals['done'], $vals['req']);
                if ($vals['completed']) {
                    $jobout .= "-->" . $sjob . " </td><td>" . $bar . "</td> ";
                } else {
                    $jobout .= "-->" . $sjob . " </td><td>" . $bar . "</td><td> " . $vals['done'] . "/" . $vals['req'] . " ";
                    if ($vals['nostamina']) {
                        $jobout .= "(you don't have enough Stamina to do this job) ";
                    }
                    if ($vals['noitem']) {
                        $jobout .= "(you don't have all the items you need to do this job) ";
                    }
                }
                $jobout .= "</td></tr></table>";
                rawoutput($jobout);
            }
            output_notl("`n");
        }
        output_notl("`n");
    }
    if ($nostam) {
        output("You have the brains to know that doing construction work when you're anything but wide awake is an idea so bad you're not even willing to entertain it.`n`n");
    }
    if ($restorebuffs) {
        restore_all_stamina_buffs();
    }
}
<?php

$hid = httpget('hid');
$rid = httpget('rid');
require_once "modules/improbablehousing/lib/lib.php";
require_once "modules/staminasystem/lib/lib.php";
$house = improbablehousing_gethousedata($hid);
$room = $house['data']['rooms'][$rid];
page_header("Painting and Decorating");
if (mass_suspend_stamina_buffs("wlimit")) {
    $restorebuffs = true;
}
switch (httpget('subop')) {
    case "extdesc":
        $extdesc = $house['data']['desc_exterior'];
        output("`0On Improbable Island, a dab of paint here and there can make the difference between a shack and a mansion.`n`nRedecorating the outside of your dwelling will allow you to change the name and external description.  The longer the description, the more Stamina you'll have to use - but changing the name is free.`n`nThe current description for your dwelling's exterior is:`n`n%s`n`nYou can change this via the box below.  Sorry, no bold, italics or new lines in external descriptions.  Also please keep it clean, or at least cleanish.  Remember to use the format \"You see (your description),\" or \"To the north, (your description) can be observed towering into the sky,\" or similar language that demonstrates what's around the player.`n`n", $extdesc);
        rawoutput("<form action='runmodule.php?module=improbablehousing&op=decorate&subop=extdesc_change&hid={$hid}' method='POST'>Dwelling name: <input name='name' id='name' value=\"" . $house['data']['name'] . "\"><br />Dwelling description:<br /><textarea name='newdesc' id='newdesc' rows='6' cols='60'>" . $extdesc . "</textarea><input type=submit>");
        addnav("", "runmodule.php?module=improbablehousing&op=decorate&subop=extdesc_change&hid={$hid}");
        break;
    case "extdesc_change":
        $newdesc = stripslashes(httppost('newdesc'));
        $newname = stripslashes(httppost('name'));
        if (strlen($newname) < 55 && strlen($newdesc) > 1 && !strpos($newname, "`") && !strpos($newdesc, "`n") && !strpos($newdesc, "`c") && !strpos($newdesc, "`b") && !strpos($newdesc, "`i") && !strpos($newdesc, "`h")) {
            output("`0`bThe name of this dwelling has been changed`b to %s`0.  Here is the new description, which `bhasn't been changed`b yet.  Check it carefully!  This will be displayed to other players looking around on the Island Map.`n`n---Begin---`n%s`n`0---End---`n`n", $newname, $newdesc);
            $iterations = ceil(strlen($newdesc) / 5);
            output("To make this your new exterior description, you'll have to perform the Decorating action `b%s`b times (your friends can help too).  Any currently-active decorating jobs on the exterior description will be cancelled.`n`n", $iterations);
            addnav("Change the external description?");
            addnav("No, I just wanted to change the name", "runmodule.php?module=improbablehousing&op=decorate&subop=extdesc&hid={$hid}");
            addnav("Yes, set up a new Decorating job", "runmodule.php?module=improbablehousing&op=decorate&subop=extdesc_confirm&hid={$hid}");
            $house['data']['name'] = $newname;
            $house['data']['proposed_extdesc']['desc'] = $newdesc;