/*
 * 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.
 */
/*** FUNNY TRANSITION ROUTINES ***/

proc exitg()
{
    "Oh dear, you seem to have gotten yourself killed.\n";
    skore();
    ratng();
    ratnx();
    if (!$ME.debug) {
        Die();
    }
}


proc em3()
{
    if (!paper.signed) {
        cg();
        return;
    }
    $ME.move(irm1);
}


proc ei8()
{
    if (spices.loc == $ME) {
        "The savory blend of spices and human wakes up the sleeping ",
        "crocodiles who decide to have you for breakfast.\n";
        exitg();
    }
    else if (rupees.loc == $ME) {
        "The weight of the coins pulls you underwater and you eventually ",
        "drown.\n";
        exitg();
    }
    else {
        "You manage to get across the river, just as the crocodiles ",
        "begin to stir.\n";
        $ME.move(irm9);
    }
}


proc wi12()
{
    if (!statue.tlakst) {
        cg();
        return;
    }
    $ME.move(irm14);
}


proc ui16()
{
    if (!rope.ropstf) {
        cg();
        return;
    }
    "You scramble up the rope and get to the ledge.\n";
    $ME.move(irm17);
}


proc ui17()
{
    "Are you a rock climber? \n";
    if (!yorn()) {
        "Then you better not try it.\n";
        return;
    }
    "That climb is rated 5.11. Do you still want to try it?\n";
    if (!yorn()) {
        "Wise move.\n";
        return;
    }
    "Half way up, you fall off a 1/32 inch wide ledge and ",
    "plummet to your death.\n";
    exitg();
}


proc di19()
{
    "You magically get transported to the corner of Westwood and Broxton, ",
    "where you are forced to spend the rest of eternity surrounded by ",
    "Hari-Krishna freaks. (That'll teach you not to believe legends.)\n";
    quit();
}


proc ei20()
{
    if (!monkey.fedmky) {
        cg();
        return;
    }
    $ME.move(irm21);
}


proc wi21()
{
    if (peel.loc == irm20) {
        "As you leave the temple, you slip on a banana peel and break ",
        "your neck.\n";
        exitg();
    }
    $ME.move(irm20);
}


proc di22()
{
    if (cobra.loc == irm22) {
        "The cobra takes a bite at your unprotected leg and injects an ",
        "unhealthy dose of neurotoxin.  You start to lose your senses, your ",
        "cognitive abilities, an yer rekcogiskdfsdk.\n";
        exitg();
    }
    $ME.move(irm23);
}


proc sm5()
{
    if (!paper.signed) { 
        "You bumped into the grate.\n";
        return;
    }
    $ME.move(prm1);
}


proc dp2()
{
    if (!rope.rtied) {
        "It is too dangerous to climb down without a rope.\n";
        return;
    }
    if ((lamp.loc == $ME) && lamp.pLight) {
        "Half-way down the rope, the carbide lamp burns through the ",
        "rope above you and you plummet to your death.\n";
        exitg();
    }
    "You climb down the rope without any problems.\n";
    $ME.move(prm3);
}


proc ep5()
{
    if (spear.loc == $ME) {
        "You can't fit the spear you are carrying through that crack.\n";
        ExitPhase(PHX_ACTOR);
    }
    $ME.move(prm6);
}


proc ep8()
{
    "You fall off the cliff and plummet several hundred feet to your ",
    "death.\n";
    exitg();
}


proc dp6()
{
    if (!smilodon.stond) {
        "As soon as you reach the bottom of the pit, the sabre-tooth ",
        "tiger tears you to shreads.\n";
        exitg();
    }
    $ME.move(prm7);
}


proc ep10()
{
    "You fall into the lake, which actually turns out to be a tar-pit ",
    "covered with a thin layer of rain water.  You eventually sink and ",
    "get fossilized.\n";
    exitg();
}


proc ep11()
{
    if (!feet.wiped) {
        $ME.move(prm10);
        ExitPhase(PHX_ACTOR);
    }
    "As you walk down the slab, your feet slip and you tumble off the slab.\n";
    ep10();
}


proc sp12()
{
    "You find your feet to be quite slippery as you walk.\n";
    feet.wiped = 1;
    $ME.move(prm11);
}


proc sp14()
{
    if (!mammoth.blokd) {
        "The mammoth keeps you from going that way.\n";
        ExitPhase(PHX_ACTOR);
    }
    $ME.move(prm15);
}


proc np17()
{
    if ((spear.tooky == 1) & (spear.abrad == 0)) {
        "The rubble keeps you from going in that direction.\n";
        ExitPhase(PHX_ACTOR);
    }
    $ME.move(prm18);
}


proc np19()
{
    if (!bear.hitbr) {
        "The bear keeps you from going that direction.\n";
        ExitPhase(PHX_ACTOR);
    }
    $ME.move(prm20);
}


proc wp22()
{
    if (spear.loc == $ME) {
        "The spear that you were carrying lodges in the Tyrannosaurus's ",
        "mouth.\n";
        spear.move(prm23);
        $ME.move(prm23);
    }
    if (spear.loc == prm23) {
        $ME.move(prm23);
    }
    if ((spear.loc != $ME) & (spear.loc != prm23)) {
        "The Tyrannosaurus crushes you in his jaws then swallows you.\n";
        exitg();
    }
}


proc dp23()
{
    "You slide down the gullet of the Tyrannosaurus and get ",
    "digested alive.\n";
    exitg();
}


proc dm6()
{
    "After wandering around in the forest for a while, you eventually ",
    "find your way out.\n";
    $ME.move(mrm1);
}


proc darkq()
{
    if (!Lit($ME.loc)) {
        if (oadl::nargs()) {
            return 1;
        }
        "It is too dark to see anything in here.\n";
        ExitPhase(PHX_CURRENT);
    }
    return 0;
}


proc darkt()
{
    if (!Lit($ME.loc)) {
        if (Percent(50)) {
            "While stumbling around in the darkness, you trip and impale ",
            "yourself on a stalagmite.\n";
            exitg();
        }
    }
}  


proc onlmp()
{
    if (lamp.loc != $ME) {
        "You don't have the lamp with you.\n";
        ExitPhase(PHX_ACTOR);
    }
    if (!lamp.pLight) {
        "A blue flame now flickers out of the lantern.\n";
        lamp.pLight = 1;
        ExitPhase(PHX_ACTOR);
    }
}


/*** TRANSITIONS ***/

... mrm1 {
    action = proc() {
        Hit($ME, mrm6, mrm2, mrm6, mrm6, nil, nil, mrm2, nil);
        Miss( nil, nil, nil, nil, cg, cg, nil, dumdir);
    }
}


... mrm2 {
    action = proc() {
        Hit($ME, mrm1, mrm4, mrm3, mrm4, nil, mrm5, nil, nil);
        Miss( nil, nil, nil, nil, cg, nil, dumdir, dumdir);
    }
}


... mrm3 {
    action = proc() {
        Hit($ME, nil, nil, nil, mrm2, nil, nil, nil, nil);
        Miss( cg, cg, em3, nil, cg, cg, dumdir, dumdir);
    }
}


... mrm4 {
    action = proc() {
        Hit($ME, mrm2, nil, nil, nil, nil, nil, nil, mrm2);
        Miss( nil, cg, cg, cg, cg, cg, cg, nil);
    }
}


... mrm5 {
    action = proc() {
        Hit($ME, nil, nil, nil, nil, mrm2, nil, nil, nil);
        Miss( cg, sm5, cg, cg, nil, cg, dumdir, dumdir);
    }
}


... mrm6 {
    action = proc() {
        Hit($ME, nil, nil, nil, nil, nil, nil, nil, nil);
        Miss( dm6, dm6, dm6, dm6, cg, cg, dumdir, dm6);
    }
}


... irm1 {
    action = proc() {
        Hit($ME, nil, nil, nil, mrm3, nil, irm2, nil, nil);
        Miss( cg, cg, cg, nil, cg, nil, dumdir, dumdir);
    }
}


... irm2 {
    action = proc() {
        Hit($ME, nil, nil, irm10, irm3, irm1, nil, nil, nil);
        Miss( cg, cg, nil, nil, nil, cg, dumdir, dumdir);
    }
}


... irm3 {
    action = proc() {
        Hit($ME, irm4, nil, irm2, nil, nil, nil, nil, nil);
        Miss( nil, cg, nil, cg, cg, cg, dumdir, dumdir);
    }
}


... irm4 {
    action = proc() {
        Hit($ME, nil, irm3, nil, nil, nil, irm5, nil, irm3);
        Miss( cg, nil, cg, cg, cg, nil, dumdir, nil);
    }
}


... irm5 {
    action = proc() {
        Hit($ME, irm6, irm7, irm8, nil, nil, nil, nil, nil);
        Miss( nil, nil, nil, cg, tohigh, cg, dumdir, dumdir);
    }
}


... irm6 {
    action = proc() {
        Hit($ME, nil, irm5, nil, irm7, nil, nil, nil, nil);
        Miss( tosml, nil, cg, nil, cg, cg, dumdir, dumdir);
    }
}


... irm7 {
    action = proc() {
        Hit($ME, irm5, nil, irm6, nil, nil, nil, nil, nil);
        Miss( nil, cg, nil, cg, cg, cg, dumdir, dumdir);
    }
}


... irm8 {
    action = proc() {
        Hit($ME, nil, nil, nil, irm5, nil, nil, nil, irm5);
        Miss( cg, cg, ei8, nil, cg, cg, dumdir, nil);
    }
}


... irm9 {
    action = proc() {
        Hit($ME, nil, nil, nil, irm8, irm10, nil, nil, irm10);
        Miss( cg, cg, cg, nil, nil, cg, dumdir, nil);
    }
}


... irm10 {
    action = proc() {
        Hit($ME, nil, irm11, irm22, irm2, nil, irm9, nil, nil);
        Miss( cg, nil, nil, nil, cg, nil, dumdir, dumdir);
    }
}


... irm11 {
    action = proc() {
        Hit($ME, irm10, irm12, nil, irm13, nil, nil, nil, nil);
        Miss( nil, nil, cg, nil, cg, cg, cg, cg);
    }
}


... irm12 {
    action = proc() {
        Hit($ME, irm11, nil, irm15, nil, nil, nil, nil, nil);
        Miss( nil, cg, nil, wi12, cg, cg, dumdir, dumdir);
    }
}


... irm13 {
    action = proc() {
        Hit($ME, nil, irm15, irm11, nil, nil, nil, nil, nil);
        Miss( cg, nil, nil, cg, cg, cg, dumdir, dumdir);
    }
}


... irm14 {
    action = proc() {
        Hit($ME, nil, nil, irm12, nil, nil, nil, nil, irm12);
        Miss(cg, cg, nil, cg, cg, cg, dumdir, nil);
    }
}


... irm15 {
    action = proc() {
        Hit($ME, irm13, nil, irm16, irm12, nil, nil, nil, nil);
        Miss(nil, cg, nil, nil, cg, cg, dumdir, dumdir);
    }
}


... irm16 {
    action = proc() {
        Hit($ME, irm22, nil, irm18, irm15, nil, nil, nil, nil);
        Miss(nil, cg, nil, nil, ui16, cg, dumdir, dumdir);
    }
}


... irm17 {
    action = proc() {
        Hit($ME, nil, nil, nil, nil, nil, irm16, nil, nil);
        Miss(cg, cg, cg, cg, ui17, nil, dumdir, dumdir);
    }
}


... irm18 {
    action = proc() {
        Hit($ME, nil, irm19, irm20, irm16, nil, nil, nil, nil);
        Miss(cg, nil, nil, nil, cg, cg, dumdir, dumdir);
    }
}


... irm19 {
    action = proc() {
        Hit($ME, irm18, nil, nil, nil, nil, nil, nil, irm18);
        Miss(nil, cg, cg, tosml, cg, di19, dumdir, nil);
    }
}


... irm20 {
    action = proc() {
        Hit($ME, nil, nil, nil, irm18, nil, nil, nil, nil);
        Miss(cg, cg, ei20, nil, cg, cg, dumdir, dumdir);
    }
}


... irm21 {
    action = proc() {
        Miss(cg, cg, cg, wi21, cg, cg, dumdir, wi21);
    }
}


... irm22 {
    action = proc() {
        Hit($ME, nil, irm16, nil, irm10, nil, nil, nil, nil);
        Miss(cg, nil, cg, nil, cg, di22, di22, cg);
    }
}


... irm23 {
    action = proc() {
        Hit($ME, nil, nil, nil, nil, irm22, nil, nil, irm22);
        Miss(cg, cg, cg, cg, nil, cg, dumdir, nil);
    }
}


... prm1 {
    action = proc() {
        darkt();
        Hit($ME, mrm5, prm2, nil, nil, nil, nil, nil, nil);
        Miss(nil, nil, cg, cg, cg, cg, dumdir, dumdir);
    }
}


... prm2 {
    action = proc() {
        Hit($ME, prm1, nil, nil, nil, nil, nil, nil, nil);
        Miss(nil, cg, cg, cg, cg, dp2, dumdir, dumdir);
    }
}


... prm3 {
    action = proc() {
        Hit($ME, nil, nil, nil, prm4, prm2, nil, nil, nil);
        Miss(cg, cg, cg, nil, nil, cg, dumdir, dumdir);
    }
}


... prm4 {
    action = proc() {
        Hit($ME, nil, prm5, prm3, prm9, nil, nil, prm5, nil);
        Miss(cg, nil, nil, nil, cg, cg, nil, dumdir);
    }
}


... prm5 {
    action = proc() {
        darkt();
        Hit($ME, prm4, nil, nil, nil, nil, nil, nil, prm4);
        Miss(nil, cg, ep5, cg, cg, cg, dumdir, nil);
    }
}


... prm6 {
    action = proc() {
        darkt();
        Hit($ME, nil, nil, nil, prm5, nil, nil, nil, nil);
        Miss(cg, cg, cg, nil, cg, dp6, dumdir, dumdir);
    }
}


... prm7 {
    action = proc() {
        darkt();
        Hit($ME, nil, prm8, nil, nil, prm6, nil, nil, nil);
        Miss(cg, nil, cg, cg, nil, cg, dumdir, dumdir);
    }
}


... prm8 {
    action = proc() {
        darkt();
        Hit($ME, prm7, nil, nil, nil, nil, nil, nil, nil);
        Miss(nil, cg, ep8, cg, cg, cg, dumdir, dumdir);
    }
}


... prm9 {
    action = proc() {
        Hit($ME, prm10, nil, prm4, prm13, nil, nil, nil, nil);
        Miss(nil, cg, nil, nil, cg, cg, dumdir, dumdir);
    }
}


... prm10 {
    action = proc() {
        Hit($ME, nil, prm9, nil, prm11, prm11, nil, nil, nil);
        Miss(cg, nil, ep10, nil, nil, cg, dumdir, dumdir);
    }
}


... prm11 {
    action = proc() {
        Hit($ME, prm12, nil, nil, nil, nil, nil, nil, nil);
        Miss(nil, cg, ep11, cg, cg, ep11, dumdir, dumdir);
    }
}


... prm12 {
    action = proc() {
        Miss(cg, sp12, cg, cg, cg, cg, dumdir, dumdir);
    }
}


... prm13 {
    action = proc() {
        Hit($ME, nil, prm14, prm9, prm16, nil, nil, nil, nil);
        Miss(cg, nil, nil, nil, cg, cg, dumdir, dumdir);
    }
}


... prm14 {
    action = proc() {
        Hit($ME, prm13, nil, nil, nil, nil, nil, nil, nil);
        Miss(nil, sp14, tosml, cg, cg, cg, dumdir, dumdir);
    }
}


... prm15 {
    action = proc() {
        Hit($ME, prm14, nil, nil, nil, nil, nil, nil, nil);
        Miss(nil, cg, cg, cg, cg, cg, dumdir, dumdir);
    }
}


... prm16 {
    action = proc() {
        Hit($ME, prm17, nil, prm13, nil, nil, prm21, nil, nil);
        Miss(nil, cg, nil, cg, cg, nil, dumdir, dumdir);
    }
}


... prm17 {
    action = proc() {
        Hit($ME, nil, prm16, nil, nil, nil, nil, nil, nil);
        Miss(np17, nil, cg, cg, cg, cg, dumdir, dumdir);
    }
}


... prm18 {
    action = proc() {
        Hit($ME, prm19, prm17, nil, nil, nil, nil, nil, nil);
        Miss(nil, nil, cg, cg, cg, cg, dumdir, dumdir);
    }
}


... prm19 {
    action = proc() {
        Hit($ME, nil, prm18, nil, nil, nil, nil, nil, nil);
        Miss(np19, nil, cg, cg, cg, cg, dumdir, dumdir);
    }
}


... prm20 {
    action = proc() {
        Hit($ME, nil, prm19, nil, nil, nil, nil, nil, prm19);
        Miss(cg, nil, cg, cg, cg, cg, dumdir, nil);
    }
}


... prm21 {
    action = proc() {
        Hit($ME, nil, nil, nil, nil, prm16, prm22, nil, nil);
        Miss(cg, cg, cg, cg, nil, nil, dumdir, dumdir);
    }
}


... prm22 {
    action = proc() {
        Hit($ME, nil, nil, nil, nil, prm21, nil, nil, nil);
        Miss(cg, cg, cg, wp22, nil, cg, dumdir, dumdir);
    }
}


... prm23 {
    action = proc() {
        Hit($ME, nil, nil, prm22, nil, nil, nil, nil, prm22);
        Miss(cg, cg, nil, cg, cg, dp23, dumdir, nil);
    }
}