/*
 * Copyright (c) 2021 Ross Cunniff
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
proc LOOK()
{
    if (GOVERB && !GO) {
        cg();
    }
    GOVERB = false;
    GO = false;
    if (IncFlag) {
        Incturn();
    }
    IncFlag = true;
}


proc PROMPT()
{
    Status($ME.loc.sdesc(1), SCORE, Turns);
    "> ";
}


proc GrowX(lst)
{
    forall (lst[i]) {
        var obj = lst[i];
        if (obj.SHRNK) {
            obj.SHRNK = false;
            GrowX(obj.cont);
        }
    }
}


proc Grow()
{
    if ($ME.SHRNK) {
        $ME.SHRNK = false;
        if ($ME.cont) {
            GrowX($ME.cont);
        }
    }
}


proc ShrnX(lst)
{
    forall (lst[i]) {
        var obj = lst[i];
        if (!obj.SHRNK) {
            obj.SHRNK = true;
            ShrnX(obj.cont);
        }
        else {
            "You hear a tiny POP as the ", obj.name, " vanishes completely!\n";
            obj.move($ALL);
        }
    }
}


proc Shrink()
{
    if (!$ME.SHRNK) {
        $ME.SHRNK = true;
        if ($ME.cont) {
            ShrnX($ME.cont);
        }
    }
}

proc WzTgl() // Toggle the Wizard flag
{
    Wizrd = !Wizrd;
    if (Wizrd) {
        "You hear a low rumble of thunder, shaking the very ground on ",
        "which you stand.  Suddenly, there is a blazing flash of light!! ",
        "You are unharmed, but feal great power flowing in your body.\n";
    }
    else {
        "Your wizardly powers unceremoniously fade away.\n";
    }
}


proc stdadv::TakeAct()
{
    if (Dobj.WEIGH == CAPAC) {
        "You can't move ";
        Dobj.sdesc();
        ".\n";
        ExitPhase(PHX_ACTOR);
    }
    else if ($ME.SHRNK && !Dobj.SHRNK) {
        "Right now, the ", Dobj.name, " is too big for you to deal with.\n";
        ExitPhase(PHX_ACTOR);
    }
    else if (($ME.HAS + Dobj.WEIGH) > $ME.HOLDS) {
        "You can't carry that much more!\n";
        ExitPhase(PHX_ACTOR);
    }
    else {
        $ME.HAS = $ME.HAS + Dobj.WEIGH;
    }
}


proc stdadv::DropAct()
{
    $ME.HAS = $ME.HAS - Dobj.WEIGH;
    if ($ME.loc == cel13) {
        if (!cel13.HOLED) {
            if (Dobj.WEIGH > 75) {
                "The ", Dobj.name, " breaks through the ice and sinks!\n";
                cel13.HOLED = true;
                hole.move(cel13);
                Dobj.move($ALL);
                Skip = true;
            }
            else {
                "The ice chips a bit, but does not break.\n";
            }
        }
    }
    else if ($ME.loc == cel19) {
        if (!goblet.FREED) {
            if (Dobj.WEIGH > 75) {
                "The ", Dobj.name,
                        " cracks the ice, and the goblet is freed!\n";
                goblet.FREED = true;
            }
            else {
                "The ice chips a bit, but does not break.\n";
            }
        }
    }
}

proc ShowScore()
 {
    "   \"Your account is now at $", SCORE, ".";
    if (SCORE < GMAX)
        "  You need $", GMAX-SCORE, " more to qualify ",
        "for your free gift.  Thank you for letting Arpa-Citizen's ",
        "be your host.\"\n";
    else if (!Given)
        "  Congratulations, preferred customer! ",
        "You have qualified for a free gift, compliments of Arpa-",
        "Citizen's Savings!\"\n";
    else
        "\"\n";
}