/*
 * 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.
 */
#include "stdadv.oah"

using namespace adv;
using namespace stdadv;

/****** Locations ******/
LitRoom startroom;
LitRoom brightroom;

proc cg() {"You can't go that way.\n";}
proc header(str, acnt) { if (!acnt) "", str, ".\n"; return str; }

LitRoom startroom($ALL) {
    ldesc = proc() {
        "You are in a small but comfortable room.  You hardly want ";
        "to leave, but there is a door leading east, if you insist.\n";
    }
    sdesc = proc() {return header("Comfortable room", oadl::nargs());}
    action = proc() {
        adv::Miss(          cg,  cg,        nil,  cg );
        adv::Hit(adv::$ME, nil, nil, brightroom, nil );
    }
}

LitRoom brightroom($ALL) {
    ldesc = proc() {
        "You are in a brightly lit room.  The walls sparkle with ";
        "scintillating lights.  There is a darker room to the west.\n";
    }
    sdesc = proc() {return header("Bright room", oadl::nargs());}
    action = proc() {
        adv::Miss(     cg,  cg,  cg,       nil );
        adv::Hit($ME, nil, nil, nil, startroom );
    }
}

/****** Vocabulary ******/
AdjecClass red();
AdjecClass blue();
AdjecClass platinum();
NounClass pillow();
NounClass bar();

/****** Objects ******/
Thing redPillow(startroom) {
    noun = pillow
    adjec = red
    ldesc = proc() {"There is a red pillow here.\n";}
    sdesc = proc() {"A red pillow";}
}

Thing bluePillow(startroom) {
    noun = pillow
    adjec = blue
    ldesc = proc() {"There is a blue pillow here.\n";}
    sdesc = proc() {"A blue pillow";}
}

Thing platBar(brightroom) {
    noun = bar
    adjec = platinum
    ldesc = proc() {"There is a bar of platinum here!\n";}
    sdesc = proc() {"A platinum bar";}
    action =  proc() {
        if ((Verb == drop) && ($ME.loc == redPillow.loc)) {
            "The bar falls onto the red pillow, breaking it!  The symbolism ";
            "impresses itself upon you, and you go back to work instead of ";
            "playing these silly games!\n";
            Quit();
        }
    }
}

StdActor SELF(startroom);

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

proc adv::START()
{
    StdInit(SELF);
    Prompt = prompter;
}

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

Thing adv::STRING();
VerbClass adv::TELLER();

// For testing
VerbClass echo {
    action = proc() {
        echoInput = !echoInput;
        "", echoInput ? "Echo on\n" : "Echo off\n";
    }
}