/*
 * 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.
 */
VerbClass pry {...}
VerbClass strike {...}
VerbClass wake {...}
VerbClass V_say("say") {...}
VerbClass beam {...}
VerbClass join {...}
VerbClass opener {...}
VerbClass glow {...}
VerbClass grab {...}
VerbClass weigh {...}
VerbClass rname {...}
VerbClass score {...}
VerbClass debug {...}
VerbClass echo {...}
VerbClass wave {...}
VerbClass plug {...}
VerbClass unplug {...}

Synonym feel(touch);
Synonym shake(wake);
Synonym hit(strike);
Synonym kill(strike);
Synonym shut(close);
Synonym push(move);
Synonym pull(move);
Synonym lift(move);
Synonym destroy(V_break);
Synonym incant(V_say);
Synonym chant(V_say);
Synonym shout(V_say);
Synonym yell(V_say);
Synonym out(exit);


proc cg()
{
    "You can't go that way.\n";
    MyLoc = $ME.loc;
}

proc Die()
{
    "You are transported to a large building built of white ",
    "marble, with hundreds of columns and sculptures about. ",
    "A robed figure emerges from the building and says,\n";
    if (NumDie == 0)
        "\"Having a bit of trouble with my little playground, are we? ",
        "Well, you seem to show some promise, so I'll take pity on you ",
        "and give you a second chance.  Begone!\"\n";
    else if (NumDie == 1)
        "\"Hmm, I would have thought that the first time might have ",
        "taught you a lesson.  Oh, well, you are yet young in the ways ",
        "of philosophy.  I'll give you one last chance.  Away!\"\n";
    else if (!Wizrd) {
        "\"I'm greatly disappointed in you.  And to think that you showed ",
        "such promise at the beginning!  Ah, well, another may come to try ",
        "out my playground.  As for you, good riddance!\"\n";
        Die();
    }
    NumDie = NumDie + 1;
    "The figure raises his arms, and you are transported to...\n";
    $ME.move(road1);
    while ($ME.cont) {
        $ME.cont.move(farm5);
    }
    $ME.HAS = 0;
    GO = true;
    ExitPhase(PHX_ACTOR);
}


proc Looks()
{
    if (Dobj) {
        "Huh?\n";
        ExitPhase(PHX_ACTOR);
    }
    GOVERB = true;
    MyLoc = -1;
}


proc initPredefVerbs()
{
    north.preact = Looks;
    south.preact = Looks;
    east.preact = Looks;
    west.preact = Looks;

    northwest.preact = Looks;
    northeast.preact = Looks;
    southwest.preact = Looks;
    southeast.preact = Looks;

    up.preact = Looks;
    down.preact = Looks;

    exit.preact = Looks;
    enter.preact = Looks;
}

... V_say {
    preact = proc() {
        Expect(NO_OBJ|ONE_OBJ|STR_OBJ|PLAIN_OBJ, NO_OBJ);
        if (!Dobj) {
            "Type just what you want to say: ";
            Dobj = Getstr();
        }
        if (Dobj ?= String) {
            "You want to make ", Dobj.name,
            " a linguistic artifact??  Strange!\n";
            ExitPhase(PHX_ACTOR);
        }
    }
    action = proc() {
        if (Dobj == Shazm) {
            WzTgl();
        }
        else {
            "Very well.  '", Dobj, "'.\n";
        }
    }
}

proc adv::DWIMD(prs,obj) {return Dwimmer(prs,obj);}
proc adv::DWIMI(prs,obj) {return Dwimmer(prs,obj);}

... wake {
    preact = Preact
    action = proc() {"I don't know how to wake ", Dobj.name, ".\n";}
}

... strike {
    preact = Preact
    action = proc() {
        "Hitting the ", Dobj.name, " doesn't seem to do anything.";
    }
}

... pry {
    preact = proc() {
        Expect(ONE_OBJ|PLAIN_OBJ, ONE_OBJ|PLAIN_OBJ);
        CheckAvail();
    }
    action = proc() {"I can't seem to manage that.\n";}
}


proc Tress()
{
    "You were warned about trespassing! The fence is electrified!\n";
    Die();
}


... score {
    action = proc() {
        if (Wizrd || ($ME.loc == town5)) {
            "A mysterious glowing network of lights appears, and you can ",
            "just make out the words:\n",
            "\tYour account is now at $", SCORE, ". ",
            "\tThank you for letting Arpa-Citizen's be your host. ",
            "The network then disappears.\n";
        }
        else {
            "Hmm, you'll have to check at the local bank.\n";
        }
    }
}

proc WizP()
{
    if (!Wizrd) {
        "Only a real Wizard can do that!\n";
        ExitPhase(PHX_ACTOR);
    }
}

... rname {
    preact = proc() {
        if (Dobj) {
            WizP();
            Dobj.sdesc();
        }
        else {
            $ME.loc.sdesc();
        }
        ExitPhase(PHX_ACTOR);
    }
}

... beam { preact = WizP ... }
... grab { preact = WizP ... }
... join { preact = WizP ... }
... opener { preact = WizP ... }
... glow { preact = WizP ... }
... weigh { preact = WizP ... }
... debug { preact = WizP ... }

... beam {
    action = proc() {
        if (Dobj) {
            $ME.move(Dobj);
            MyLoc = -1;
        }
    }
}

... join {
    action = proc() {
        if (Dobj) {
            $ME.move(Dobj.loc);
            MyLoc = -1;
        }
    }
}

... opener {
    action = proc() {
        if (Dobj) {
            try {
                Dobj.pOpened = true;
                "Opened.\n";
            }
            catch( e ) {
                "It can not be opened.\n";
            }
        }
    }
}

... glow {
    action = proc() {
        $ME.pLight = !$ME.pLight;
        if ($ME.pLight)
            "Your body begins to radiate a strong but gentle white light!\n";
        else
            "The light from your body fades away.\n";
    }
}

... grab {
    action = proc() {
        if (Dobj) {
            "You have the ", Dobj.name, ", Boss!\n";
            Dobj.move($ME);
            $ME.HAS = $ME.HAS + Dobj.WEIGH;
        }
    }
}

... weigh {
    action = proc() {
        if (Dobj)
            "The ", Dobj.name, " weighs ", Dobj.WEIGH;
        else
            "You are carrying ", $ME.HAS;
        " pounds, Boss!\n";
    }
}

... debug {
    action = proc() {
        // spec(DEBUG);       // Turn on debugging
    }
}

... echo {
    action = proc() {
        echoInput = !echoInput;
        if( echoInput ) {
            "Echo on\n";
        }
        else {
            "Echo off\n";
        }
    }
}

... plug {
    preact = Preact
    action = proc() { "That doesn't seem to work.\n"; }
}

... unplug {
    preact = Preact
    action = proc() { "That doesn't seem to work.\n"; }
}

... wave {
    preact = Preact
    action = proc() { "That doesn't seem to do anything.\n"; }
}