/*** FUNNY OBJECT ROUTINES ***/

paper(ACTION) = Proc()
{
    If (Verb == sign) {
	If (paper.signed) {
	    "You already signed it.\n";
	    $exit(1);
	}
	If ($loc(pen) != $ME) {
	    "You don't have anything to write with.\n";
	    $exit(1);
	}
	If ($loc(paper) != $ME) {
	    "You don't have the release with you.\n";
	    $exit(1);
	}
	paper.signed = 1;
	$move(grate, $ALL);
	If ($loc($ME) == mrm3) {
            "In a blinding flash of light, a stone archway appears in the "
            "east wall!\n";
        }
	Else If ($loc($ME) == mrm5) {
	    "The grate magically disappears into thin air.\n";
	    $exit(1);
        }
	Else {
	    "You hear strange noises in the nearby rooms.\n";
	}
	$exit(1);
    }
    Else If (Verb == read) {
	If ($loc(paper) != $ME) {
	    "You don't have the paper with you.\n";
        }
	Else {
            "\t\tTHIS CONTRACT LIMITS OUR LIABILITY\n"
            "\t\t\tREAD IT\n"
            "\n"
            "I, the undersigned, will not hold the AARDVARK, the UCLA "
            "Computer Sciences Department, the UCLA Computer Club, Bell "
            "Labs, or the Digital Equipment Corporation responsible for "
            "any injuries or deaths due to my executing this program.\n";
	    paper.readl = 1;
	}
	$exit(1);
    }
}


spices(ACTION) = Proc()
{
    If ((Verb == throw) & ($loc($ME) == irm8)) {
	"The bag of spices lands on the other side of the river.\n";
	$move(spices, irm9);
	$exit(1);
    }
    Else If (Verb == eat) {
	"Munch, Munch Munch.  It needed a little more salt.\n";
	$move(spices, $ALL);
	$exit(1);
    }
    Else If ((Verb == throw) & ($loc($ME) == irm9)) {
        "The bag of spices gets intercepted by one of the crocodiles, "
        "who promptly swallows it.\n";
	$move(spices, $ALL);
	$exit(1);
    }
}


rupees(ACTION) = Proc()
{
    If ((Verb == throw) & (($loc($ME) == irm8) | ($loc($ME) == irm9))) {
        "The bag is too heavy to throw across the river.  It lands in the "
        "middle of the river and sinks to the bottom.\n"
	$move(rupees, $ALL);
	$exit(1);
    }
}


coconut(ACTION) = Proc()
{
    If (($loc($ME) == irm19) & (Verb == drop)) {
	If (!rupees.wellbt) {
	    "The water in the well rises.\n";
        }
	Else {
            "The water level in the well slowly rises. "
            "Magically floating on the water is a bag of rupees.\n";
	    rupees.wellbt = 0;
	    $move(rupees, irm19);
	}
    }
    Else If ((Verb == eat) & ($loc(coconut) == $ME)) {
	"The coconut is too large for you to consume.\n";
	$exit(1);
    }
}


clarinet(ACTION) = Proc()
{
    If ((Verb == play) & ($loc(clarinet) == $ME)) {
	If (($loc($ME) == irm22) & ($loc(cobra) == irm22)) {
            "Your clarinet playing sounds so poor that the cobra "
            "slithers off in terror.\n";
	    $move(cobra, $ALL);
	    $exit(1);
        }
	Else If (($loc($ME) == irm16) & ($loc(rope) == irm16)) {
	    If (rope.ropstf == 0) {
		"The rope magically extends itself up into the air.\n";
		rope.ropstf = 1;
		$exit(1);
	    }
	}
	"Benny Goodman you ain't.\n";
	$exit(1);
    }
}


rope(ACTION) = Proc()
{
    If (rope.ropstf & (Verb == take)) {
	rope.ropstf = 0;
	Return 0;
    }
    Else If (($loc($ME) == prm2) | ($loc($ME) == prm3)) {
	If (rope.rtied) {
	    If (Verb == take) {
		"You have to untie the rope first.\n";
		Skip = TRUE;
            }
	    Else If (Verb == tie) {
		"It's already tied, turkey.\n";
		$exit(1);
            }
	    Else If (Verb == untie) {
		If ($loc($ME) == prm2) {
		    $move(rope, $ME);
		    rope.rtied = 0;
		    rope.LDESC = rldesc;
		    rope.SDESC = rsdesc;
		    "You untie the rope and coil it up.\n";
                }
		Else If ($loc($ME) == prm3) {
		    "It's tied down at the other end.\n";
		}
		$exit(1);
	    }
        }
	Else {
	    If (Verb == tie) {
		If ($loc($ME) == prm2) {
                    "You tie one end of the rope around the pole; the other "
                    "end dangles down into the canyon.\n";
		    $move(rope, prm2);
		    rope.rtied = 1;
		    rope.LDESC = 0;
		    rope.SDESC = 0;
		    $exit(1);
		}
		"I see nothing to which to tie it.\n";
		$exit(1);
            }
	    Else If (Verb == untie) {
		"It's already untied.\n";
	    }
	}
    }
}


river(ACTION) = Proc()
{
    If (($loc($ME) != irm8) & ($loc($ME) != irm9)) {
	"You see no river here.\n";
	$exit(1);
    }
    Else If (Verb == take) {
	"You can't do that to the river!\n";
	Skip = TRUE;
    }
}


cobra(ACTION) = Proc()
{
    If ((Verb == take) & ($loc($ME) == $loc(cobra))) {
	"Taking the cobra would be a poor idea.\n";
	Skip = TRUE;
    }
}


crocodiles(ACTION) = Proc()
{
    If (Verb == take) {
	"I can't get to any crocodiles from here.\n";
	Skip = TRUE;
    }
}


cmara = Proc()
{
    If (Verb == take) {
	"The statue is too heavy for you to carry.\n";
	Skip = TRUE;
	Return TRUE;
    }
    Return FALSE;
}


claks = Proc()
{
    If (((Verb == take) | (Verb == touch)) & (statue.tlakst == 0)) {
        "The statue slides away very easily, revealing a secret passage.\n";
	statue.tlakst = 1;
	Skip = TRUE;
	Return TRUE;
    }
    Return FALSE;
}


mara(ACTION) = Proc()
{
    If ($loc($ME) == irm10) {
	cmara();
    }
}


vishnu(ACTION) = Proc()
{
    If ($loc($ME) == irm11) {
	cmara();
    }
}


lakshmi(ACTION) = Proc()
{
    If ($loc($ME) == irm12) {
	claks();
    }
}


statue(ACTION) = Proc()
{
    If (($loc($ME) == irm10) | ($loc($ME) == irm11)) {
	If (!cmara()) {
	    "That won't accomplish anything.\n";
	    $exit(1);
	}
    }
    Else If ($loc($ME) == irm12) {
	If (!claks()) {
	    "I don't see how you can do that to a statue.\n";
	    $exit(1);
	}
    }
}


banana(ACTION) = Proc()
{
    If ($loc(banana) == $ME) {
	If (Verb == eat) {
	    "You eat the banana, peel and all.\n";
	    $move(banana, $ALL);
	    $exit(1);
	}
    }
    If ($loc($ME) == irm20) {
	If (Verb == drop) {
            "The monkey picks up the banana, eats it, and discards "
            "the banana-peel.  As soon as the monkey finishes eating "
            "the banana, a bolt of lighting hits the stone slab and  "
            "cracks it open.\n";
	    monkey.fedmky = 1;
	    $move(banana, $ALL);
	    $move(peel, irm20);
	    Skip = TRUE;
	}
    }
}


horn(ACTION) = Proc()
{
    If (rhino.cutflg) {
	Return 0;
    }
    Else If ($loc($ME) == irm13) {
	If (Verb == take) {
	    "The horn is still attached to the rhino!\n";
	    Skip = TRUE;
        }
	Else If (Verb == cut) {
	    If ($loc(saw) != $ME) {
		"You don't have something to cut the horn with.\n";
		$exit(1);
            }
	    Else If (rhino.earplg) {
		"You cut the horn off without waking up the rhino.\n";
		rhino.cutflg = 1;
		horn.NOTAKE = FALSE;
		$exit(1);
            }
	    Else {
                "The noise of the sawing wakes up the rhinoceros who tramples "
                "you to death because you disturbed his beauty sleep.\n";
		exitg();
	    }
	}
    }
}


lattice(ACTION) = Proc()
{
    If ($loc($ME) == irm13) {
	If (Verb == take) {
	    If (rhino.earplg) {
                "You successfully take the lattice without waking the rhino. "
                "Unfortunately, the lattice was the structure which supported "
                "the roof of the room, and the ceiling comes crashing down "
                "upon you and breaks every bone in your body.\n";
            }
	    Else {
                "As you take the lattice, a large part of the bamboo falls "
                "down.  The noise caused by the falling bamboo scares the "
                "sleeping rhinoceros who tramples you in his panicked exit "
                "from the room.\n";
	    }
	}
	exitg();
    }
}


monkey(ACTION) = Proc()
{
    If ($loc($ME) == irm20) {
	If (Verb == feed) {
	    If ($loc(banana) == $ME) {
                "The monkey takes your banana, peels it, eats it, and throws "
                "away the banana peel.  As soon as he finishes eating the "
                "banana, there is a rumble from the depths of the earth and  "
                "a crack appears in the stone slab.\n";
		monkey.fedmky = 1;
		$move(banana, $ALL);
		$move(peel, irm20);
		$exit(1);
	    }
	}
    }
}


cotton(ACTION) = Proc()
{
    If ($loc($ME) == irm13) {
	If ((Verb == drop) & (Iobj == ears)) {
	    "You stick the wads of cotton into the rhino's ears.\n";
	    $move(cotton, $ALL);
	    rhino.earplg = 1;
	    Skip = TRUE;
	    Return 0;
	}
	If ($loc(cotton) == $ALL) {
	    If ($loc($ME) == irm13) {
		If (Verb == take) {
		    rhino.earplg = 0;
		}
	    }
	}
    }
}


pole(ACTION) = Proc()
{
    If (($loc($ME) == prm2) & (Verb == take)) {
	"The pole is firmly cemented into the ground.\n";
	Skip = TRUE;
    }
}


lamp(ACTION) = Proc()
{
    If (Verb == light) {
	onlmp();
	$exit(1);
    }
    Else If (Verb == douse) {
	If (!lamp.LIGHT) {
	    "The lamp is already off!\n";
        }
	Else {
	    lamp.LIGHT = 0;
	    "The lamp is now off.\n";
	}
	$exit(1);
    }
}


oven(ACTION) = Proc()
{
    If (($loc($ME) == irm4) & (Verb == open)) {
	"The door of the oven doesn't budge.\n";
	$exit(1);
    }
}


grate(ACTION) = Proc()
{
    If ((paper.signed == 0) & ($loc($ME) == mrm5)) {
	If ((Verb == open) | (Verb == take)) {
	    "The grate appears to be firmly cemented into the wall.\n";
	    If (Verb == open) {
		$exit(1);
            }
	    Else {
		Skip = TRUE;
	    }
        }
	Else If (Verb == shut) {
	    "The grate is already shut.\n";
	    $exit(1);
	}
    }
}


weapo = Proc()
{
    If (Verb == throw) {
	If ((!bear.hitbr) & ($loc($ME) == prm19)) {
	    "The axe bounces harmlessly off of the bear.\n";
	    $move(axe, prm19);
	    $exit(1);
        }
	 Else If ($loc($ME) == prm14) {
            "The weapon that you just threw imbeds itself deep into the  "
            "skull of the mammoth and is covered by the mammoth's long fur "
            "so that it can't be seen.  The mammoth just stares back at you "
            "blankly.\n"
	    $move(Dobj, $ALL);
	    $exit(1);
        }
	Else If (($loc($ME) == irm8) | ($loc($ME) == irm9)) {
            "You miss the crocodile and your weapon sinks into the river.\n"
	    $move(Dobj, $ALL);
	    $exit(1);
        }
	Else If ($loc($ME) == irm13) {
	    "Your weapon bounces harmlessly off of the rhino.\n";
	    $move(Dobj, irm13);
	    $exit(1);
        }
	Else If (($loc($ME) == prm6) & !smilo.stond) {
            "The sabre-tooth catches your weapon in its mouth and promptly "
            "swallows it.\n"
	    $move(Dobj, $ALL);
	    $exit(1);
        }
	Else If (($loc($ME) == prm8) & !trogl.killd) {
            "You hit the troglodyte, who, screaming in pain, drops the "
            "gold nugget and falls over the cliff.\n";
	    trogl.killd = 1;
	    $move(Dobj, $ALL);
	    $move(nugget, prm8);
	    $exit(1);
	}
    }
}


spear(ACTION) = Proc()
{
    If ($loc(spear) == $ME) {
	If ($loc($ME) != prm19) {
	    weapo();
	}
	If (Verb == throw) {
            "You repeatedly throw your spear at the bear.  Eventually, he "
            "gets bored and wanders off.\n";
	    $move(bear, $ALL);
	    $move(spear, prm19);
	    bear.hitbr = 1;
	    $exit(1);
	}
    }
    Else If ($loc($ME) == prm17) {
	If (Verb == take) {
	    If (!spear.tooky) {
                "You hear a loud roar as an avalanche blocks the path to "
                "your north.\n";
		spear.tooky = 1;
	    }
	}
    }
    Else If (Verb == shake) {
	"I don't see any playwrights here.\n";
    }
    Else If (($loc($ME) == prm23) & (Verb == take)) {
        "As soon as you take the spear, the Tyrannosaurus Rex closes his "
        "mouth and swallows you.\n";
	exitg();
    }
}


axe(ACTION) = Proc()
{
    If ($loc(axe) == $ME) {
	weapo();
    }
}


smilo(ACTION) = Proc()
{
    If (($loc($ME) == prm6) & (Verb == take)) {
	"You must be dumber than you look.\n";
	Skip = TRUE;
    }
}


troglodyte(ACTION) = Proc()
{
    If (($loc($ME) == prm8) & (Verb == take)) {
        "The troglodyte does not look like he wants to be carried.\n";
	Skip = TRUE;
    }
}


plant(ACTION) = Proc()
{
    If ($loc($ME) == prm6) {
	If ((Verb == throw) | (Verb == drop)) {
	    If (!smilo.stond) {
                "The plant you were holding turns out to be primo grade "
                "catnip.  The sabre-tooth cat grabs the plant and runs off "
                "purring loudly.\n";
		$move(plant, $ALL);
		smilo.stond = 1;
		If (Verb == throw) {
		    $exit(1);
                }
		Else {
		    Skip = TRUE;
		}
	    }
	}
    }
    If (Verb == eat) {
	"You completely eat the plant and now feel quite nauseous.\n";
	$move(plant, $ALL);
	$exit(1);
    }
}


nugget(ACTION) = Proc()
{
    If ((Verb == take) & !trogl.killd) {
	"He ain't gonna let you take it.\n";
	Skip = TRUE;
    }
}


cheese(ACTION) = Proc()
{
    If (Verb == eat) {
	"You eat the cheese, but nothing peculiar happens.\n";
	$move(cheese, $ALL);
	$exit(1);
    }
    Else If ((Verb == drop) & ($loc($ME) == prm14)) {
        "As soon as you drop the cheese, a mouse runs out of the hole in "
        "the east wall and takes it.  This scares the mammoth who runs off "
        "in terror.\n";
	mammoth.blokd = 1;
	$move(mammoth, $ALL);
	$move(cheese, $ALL);
	Skip = TRUE;
    }
}


mammoth(ACTION) = Proc()
{
    If ($loc(mammoth) == $loc($ME)) {
	If (Verb == feed) {
	    "He doesn't look hungry.\n";
	    $exit(1);
        }
	Else If (Verb == take) {
	    "He doesn't look too easy to carry.\n";
	    Skip = TRUE;
	}
    }
}


feet(ACTION) = Proc()
{
    If (Verb == wipe) {
	If ($loc(towel) != $ME) {
	    "You don't have something to wipe them with.\n";
	    $exit(1);
        }
	Else {
	    "You just cleaned off your feet.\n";
	    feet.wiped = 0;
	    $exit(1);
	}
    }
    Else If (Verb == touch) {
	"You can't without bending your knees.\n";
    }
}


cairn(ACTION) = Proc()
{
    If ($loc($ME) == prm18) {
        "How dare you do such a thing.  Any idiot with just the slightest "
        "knowledge of prehistoric etiquette knows that you aren't supposed "
        "to do anything to a cairn.\n";
	$exit(1);
    }
}


bear(ACTION) = Proc()
{
    If ($loc($ME) == prm19) {
	If (Verb == take) {
	    If (!bear.hitbr) {
		"The bear is a little too bulky to carry.\n";
		Skip = TRUE;
	    }
	}
    }
}


tyrannosaurus(ACTION) = Proc()
{
    If (($loc($ME) != prm22) & ($loc($ME) != prm23)) {
        "What?  One of those things hasn't existed in several "
        "million years.\n";
    }
}


hole(ACTION) = Proc()
{
    If ($loc($ME) == prm14) {
	"That hole is too small to do anything with.\n";
	$exit(1);
    }
    Else If ($loc($ME) == irm19) {
	If ((Verb == drop) & (Iobj == hole)) {
	    "It falls back out of the hole.\n";
	    Skip = TRUE;
	}
    }
    Else If ($loc($ME) == irm6) {
	If ((Verb == drop) & (Iobj == hole)) {
	    If (Dobj == spices) {
                "The bag of spices rips against the jagged sides of the "
                "shaft and almost all of the spices get blown away in "
                "the wind.\n";
		$move(spices, $ALL);
            }
	    Else If (Dobj == rupees) {
                "The rupees fall down the shaft into the darkness below. "
                "You eventually hear a barely audible splash.\n";
		rupees.wellbt = 1;
		$move(rupees, $ALL);
            }
	    Else {
		"That doesn't fit in the hole.\n";
	    }
	    Skip = TRUE;
	    Return 0;
	}
    }
    Else {
	"I do not see any holes here.\n";
	$exit(1);
    }
}


newspaper(ACTION) = Proc()
{
    If (Verb == read) {
        "\t\t\tDAILY GNUS\n"
        "Vol 2.\t\t\t25 AUGUST\n"
        "\n"
        "Spies in the far reaches of the Museum have reported that new "
        "construction is now taking place.\n"
        "\n"
        "Dungeon consultant Mr. Mctesq has recently waved his magic wand "
        "over the aardvark museum.  The following things should be brought "
        "to light:\n"
        "\tThe commands SAVE, RESTORE, and SHELL exist and work.\n"
        "\tENTER is a verb, but IN is a preposition.\n"
        "\n"
        "Again, Adventurers are reminded that restocking of the museum "
        "sections will be greatly rewarded.\n"
        "\n";
	$exit(1);
    }
}


crack(ACTION) = Proc()
{
    If (Verb == jamb) {
	"The only climbable cracks in this place are A4.\n";
	$exit(1);
    }
    "I can't figure that out. I'm not as smart as I am cracked up to be.\n";
    $exit(1);
}


shaft(ACTION) = Proc()
{
    If (Verb == jamb) {
	"Try jamb crack (How do you jamb a shaft?)\n";
	$exit(1);
    }
    Else If ((Verb == drop) & (Iobj == shaft)) {
	Iobj = hole;
	hole.ACTION();
    }
}