// <script>
//  Adventure - main program
//
function MAIN () {
MAIN_VarInit ();



//
//  Statement functions
//
//  TOTING(OBJ)	= true if the OBJ is being carried
//  HERE(OBJ)	= true if the OBJ is at "LOC" (or is being carried)
//  AT(OBJ)	= true if on either side of two-placed OBJ
//  LIQ(DUMMY)	= object number of liquid in bottle
//  LIQLOC(LOC)	= object number of liquid (if any) at LOC
//  BITSET(L,N)	= true if COND(L) has bit N set (bit 0 is units bit)
//  FORCED(LOC)	= true if LOC moves without asking for input (COND=2)
//  DARK(DUMMY)	= true if location "LOC" is dark
//  PCT(N)       = true N% of the time (N integer from 0 to 100)
//
//  WZDARK says whether the LOC he's leaving was dark
//  LMWARN says whether he's been warned about lamp going dim
//  CLOSNG says whether its closing time yet
//  PANIC says whether he's found out he's trapped in the cave
//  CLOSED says whether we're all the way closed
//  GAVEUP says whether he exited via "QUIT"
//  SCORNG indicates to the SCORE routine whether we're doing a "SCORE" command
//  DEMO is true if this is a prime-time demonstration game
//  YEA is random YES/NO reply
//











JAL=Truncate(34*56/5)+1+Truncate(Truncate(2/5)/6);

//  Start-up, dwarf stuff
//

return MAIN1;
}
function MAIN1 () {
I=RND(1);

return MAIN_1;
}
function MAIN_1 () {
if (YesNo(65,1,0)) return MAIN_1;
HINTED[3]=YES;
NEWLOC=1;
LOC=NEWLOC;
LIMIT=330;
if (HINTED[3]) LIMIT=1000;
//
//  Can't leave cave once it's closing (except by main office).
//

return MAIN2;
}
function MAIN2 () {
if (NEWLOC>=9|NEWLOC==0|!CLOSNG) return MAIN71;
RSPEAK(130);
NEWLOC=LOC;
if (!PANIC) CLOCK2=15;
PANIC=true;
//
//  See if a dwarf has seen him and has come from where he wants to go.  If so,
//  the dwarf's blocking his way.  If coming from place forbidden to pirate
//  (dwarves rooted in place) let him get out (and attacked).
//

return MAIN71;
}
function MAIN71 () {
if (NEWLOC==LOC|FORCED(LOC)|BITSET(LOC,3)) return MAIN74;
I=(1);

return MAIN_2;
}
function MAIN_2 () {

if (ODLOC[I]!=NEWLOC|!DSEEN[I]) return MAIN73;
NEWLOC=LOC;
RSPEAK(2);
return MAIN74;

}
function MAIN73 () {
if (++I<=5)return MAIN_2;


return MAIN74;
}
function MAIN74 () {
LOC=NEWLOC;
//
//  Dwarf stuff.  See earlier comments for description of variables.  Remember
//  sixth dwarf is pirate and is thus very different except for motion rules.
//
//  First off, don't let the dwarves follow him into a pit or a wall.  Activate
//  the whole mess the first time he gets as far as the Hall of Mists (LOC 15).
//  If NEWLOC is forbidden to pirate (in particular, if it's beyond the Troll
//  Bridge), bypass dwarf stuff.  That way pirate can't steal return toll, and 
//  dwarves can't meet the bear.  Also means dwarves won't follow him into Dead
//  End in Maze, but c'est la vie.  They'll wait for him outside the Dead End.
//
if (LOC==0|FORCED(LOC)|BITSET(NEWLOC,3)) return MAIN2000;
if (DFLAG!=0) return MAIN6000;
if (LOC>=15) DFLAG=1;
return MAIN2000;
//
//  When we encounter the first dwarf, we kill 0, 1, or 2 of the 5 dwarves.  If
//  any of the survivors is at LOC, replace him with the alternate.
//

}
function MAIN6000 () {
if (DFLAG!=1) return MAIN6010;
if (LOC<15|PCT(95)) return MAIN2000;
DFLAG=2;
I=(1);

return MAIN_3;
}
function MAIN_3 () {

J=1+RND(DWFMAX-1);

return MAIN6001;
}
function MAIN6001 () {
if (PCT(50)) DLOC[J]=0;if (++I<=2)return MAIN_3;

I=(1);

return MAIN_4;
}
function MAIN_4 () {

if (DLOC[I]==LOC) DLOC[I]=DALTLC;

return MAIN6002;
}
function MAIN6002 () {
ODLOC[I]=DLOC[I];if (++I<=5)return MAIN_4;

RSPEAK(3);
DROP(AXE,LOC);
return MAIN2000;
//
//  Things are in full swing.  Move each dwarf at random, except if he's seen us
//  he sticks with us.  Dwarves never go to LOCS <15.  If wandering at random,
//  they don't back up unless there's no alternative.  If they don't have to
//  move, they attack.  And, of course, dead dwarves don't do much of anything.
//

}
function MAIN6010 () {
DTOTAL=0;
ATTACK=0;
STICK=0;
I=(1);

return MAIN_5;
}
function MAIN_5 () {

if (DLOC[I]==0) return MAIN6030;
J=1;
KK=DLOC[I];
KK=KEY[KK];
if (KK==0) return MAIN6016;

return MAIN6012;
}
function MAIN6012 () {
NEWLOC=TRVLOC[KK];
if (NEWLOC>300|NEWLOC<15|NEWLOC==ODLOC[I]|(J>1&NEWLOC==TK[J-1])|J>=HNTSIZ|
	NEWLOC==DLOC[I]|FORCED(NEWLOC)|(I==DWFMAX&BITSET(NEWLOC,3))|TRVCON[KK]==100) return MAIN6014;
TK[J]=NEWLOC;
J++;

return MAIN6014;
}
function MAIN6014 () {
KK++;
if (TRAVEL[KK-1]>=0) return MAIN6012;

return MAIN6016;
}
function MAIN6016 () {
TK[J]=ODLOC[I];
if (J>=2) J--;
J=1+RND(J);
ODLOC[I]=DLOC[I];
DLOC[I]=TK[J];
DSEEN[I]=(DSEEN[I]&LOC>=15)|(DLOC[I]==LOC|ODLOC[I]==LOC);
if (!DSEEN[I]) return MAIN6030;
DLOC[I]=LOC;
if (I!=DWFMAX) return MAIN6027;
//
//  The pirate's spotted him.  He leaves him alone once we've found chest.
//  K counts if a treasure is here.  If not, and TALLY=TALLY2 plus one for
//  an unseen chest, let the pirate be spotted.
//
if (LOC==CHLOC|PROP[CHEST]>=0) return MAIN6030;
K=0;
J=(50);

return MAIN_6;
}
function MAIN_6 () {

//
//  Pirate won't take pyramid from Plover Room or Dark Room (too easy!).
//
if (J==PYRAM&(LOC==PLAC[PYRAM]|LOC==PLAC[EMRALD])) return MAIN6020;
if (TOTING(J)) return MAIN6022;

return MAIN6020;
}
function MAIN6020 () {
if (HERE(J)) K=1;if (++J<=MAXTRS)return MAIN_6;

if (TALLY==TALLY2+1&K==0&PLACE[CHEST]==0&HERE(LAMP)&PROP[LAMP]==1) return MAIN6025;
if (ODLOC[DWFMAX]!=DLOC[DWFMAX]&PCT(20)) RSPEAK(127);
return MAIN6030;
//

}
function MAIN6022 () {
RSPEAK(128);
//
//  Don't steal chest back from troll!
//
if (PLACE[MESSAG]==0) MOVE(CHEST,CHLOC);
MOVE(MESSAG,CHLOC2);
J=(50);

return MAIN_7;
}
function MAIN_7 () {

if (J==PYRAM&(LOC==PLAC[PYRAM]|LOC==PLAC[EMRALD])) return MAIN6023;
if (AT(J)&FIXED[J]==0) CARRY(J,LOC);
if (TOTING(J)) DROP(J,CHLOC);

return MAIN6023;
}
function MAIN6023 () {
if (++J<=MAXTRS)return MAIN_7;


return MAIN6024;
}
function MAIN6024 () {
DLOC[DWFMAX]=CHLOC;
ODLOC[DWFMAX]=CHLOC;
DSEEN[DWFMAX]=false;
return MAIN6030;
//

}
function MAIN6025 () {
RSPEAK(186);
MOVE(CHEST,CHLOC);
MOVE(MESSAG,CHLOC2);
return MAIN6024;
//
//  This threatening little dwarf is in the room with him!
//

}
function MAIN6027 () {
DTOTAL++;
if (ODLOC[I]!=DLOC[I]) return MAIN6030;
ATTACK++;
if (KNFLOC>=0) KNFLOC=LOC;
if (RND(1000)<95*(DFLAG-2)) STICK++;

return MAIN6030;
}
function MAIN6030 () {
if (++I<=DWFMAX)return MAIN_5;

//
//  Now we know what's happening.  Let's tell the poor sucker about it.
//
if (DTOTAL==0) return MAIN2000;
if (DTOTAL==1) return MAIN75;
 MAIN67 (DTOTAL);

return MAIN77;

}
function MAIN75 () {
RSPEAK(4);

return MAIN77;
}
function MAIN77 () {
if (ATTACK==0) return MAIN2000;
if (DFLAG==2) DFLAG=3;
if (ATTACK==1) return MAIN79;
 MAIN78 (ATTACK);

K=6;

return MAIN82;
}
function MAIN82 () {
if (STICK>1) return MAIN83;
RSPEAK(K+STICK);
if (STICK==0) return MAIN2000;
return MAIN84;

}
function MAIN83 () {
 MAIN68 (STICK);


return MAIN84;
}
function MAIN84 () {
OLDLC2=LOC;
return MAIN99;
//

}
function MAIN79 () {
RSPEAK(5);
K=52;
return MAIN82;

//  Describe the current location and (maybe) get next command.
//
//  Print text for current LOC.
//

}
function MAIN2000 () {
if (LOC==0) return MAIN99;
KK=STEXT[LOC];
KENT=0;
if (ABBNUM!=0) KENT=MOD(ABB[LOC],ABBNUM);
if (KENT==0|KK==0) KK=LTEXT[LOC];
if (FORCED(LOC)|!DARK(0)) return MAIN2001;
if (WZDARK&PCT(35)) return MAIN90;
KK=RTEXT[16];

return MAIN2001;
}
function MAIN2001 () {
if (TOTING(BEAR)) RSPEAK(141);
SPEAK(KK);
K=1;
if (FORCED(LOC)) return MAIN8;
if (LOC==33&PCT(25)&!CLOSNG) RSPEAK(8);
//
//  Print out descriptions of objects at this location.  If not closing and
//  property value is negative, tally off another treasure.  Rug is special
//  case; once seen, its PROP is 1 (dragon on it) till dragon is killed.
//  Similarly for chain; PROP is initially 1 (locked to bear).  These hacks
//  are because PROP=0 is needed to get full score.
//
if (DARK(0)) return MAIN2012;
ABB[LOC]=ABB[LOC]+1;
I=ATLOC[LOC];

return MAIN2004;
}
function MAIN2004 () {
if (I==0) return MAIN2012;
OBJ=I;
if (OBJ>OBJMAX) OBJ=OBJ-OBJMAX;
if (OBJ==STEPS&TOTING(NUGGET)) return MAIN2008;
if (PROP[OBJ]>=0) return MAIN2006;
if (CLOSED) return MAIN2008;
PROP[OBJ]=0;
if (OBJ==RUG|OBJ==CHAIN) PROP[OBJ]=1;
TALLY--;
//  IF REMAINING TREASURES TOO ELUSIVE, ZAP HIS LAMP.
if (TALLY==TALLY2&TALLY!=0) LIMIT=MIN0(35,LIMIT);

return MAIN2006;
}
function MAIN2006 () {
KK=PROP[OBJ];
if (OBJ==STEPS&LOC==FIXED[STEPS]) KK=1;
PSPEAK(OBJ,KK);

return MAIN2008;
}
function MAIN2008 () {
I=LINK[I];
return MAIN2004;
//

}
function MAIN2009 () {
K=54;

return MAIN2010;
}
function MAIN2010 () {
SPK=K;

return MAIN2011;
}
function MAIN2011 () {
RSPEAK(SPK);
//

return MAIN2012;
}
function MAIN2012 () {
VERB=0;
OBJ=0;
//
//  Check if this LOC is eligible for any hints.  If been here long enough,
//  branch to help section (on later page).  Hints all come back here eventually
//  to finish the loop.  Ignore "HINTS" < 4 (special stuff, see database notes).
//

return MAIN2600;
}
function MAIN2600 () {
HINT=(4);

return MAIN_8;
}
function MAIN_8 () {

if (HINTED[HINT]) return MAIN2602;
if (!BITSET(LOC,HINT)) HINTLC[HINT]=-1;
HINTLC[HINT]=HINTLC[HINT]+1;
if (HINTLC[HINT]>=HINTS(HINT,1)) return MAIN40000;

return MAIN2602;
}
function MAIN2602 () {
if (++HINT<=HNTMAX)return MAIN_8;

//
//  Kick the random number generator just to add variety to the chase.  Also,
//  if closing time, check for any objects being toted with PROP < 0 and set
//  the PROP to -1-PROP.  This way objects won't be described until they've
//  been picked up and put down separate from their respective piles.  Don't
//  tick CLOCK1 unless well into cave (and not at Y2).
//
if (!CLOSED) return MAIN2605;
if (PROP[OYSTER]<0&TOTING(OYSTER)) PSPEAK(OYSTER,1);
I=(1);

return MAIN_9;
}
function MAIN_9 () {


return MAIN2604;
}
function MAIN2604 () {
if (TOTING(I)&PROP[I]<0) PROP[I]=-1-PROP[I];if (++I<=OBJMAX)return MAIN_9;


return MAIN2605;
}
function MAIN2605 () {
WZDARK=DARK(0);
if (KNFLOC>0&KNFLOC!=LOC) KNFLOC=0;
I=RND(1);

return MAIN_10;
}
function MAIN_10 () {
if (GETIN())return MAIN_10;WORD1=w1;WORD2=w2;
//
//  Every input, check "FOOBAR" flag.  If zero, nothing's going on.  If pos,
//  make neg.  If neg, he skipped a word, so make it zero.
//

return MAIN2608;
}
function MAIN2608 () {
FOOBAR=MIN0(0,-FOOBAR);
TURNS++;
//	IF(VERB.EQ.SAY .AND. WORD2.NE.' ')VERB=0
//	IF(VERB.EQ.SAY)GOTO 4090
if (TALLY==0&LOC>=15&LOC!=33) CLOCK1--;
if (CLOCK1==0) return MAIN10000;
if (CLOCK1<0) CLOCK2--;
if (CLOCK2==0) return MAIN11000;
if (PROP[LAMP]==1) LIMIT--;
if (LIMIT<=30&HERE(BATTER)&PROP[BATTER]==0&HERE(LAMP)) return MAIN12000;
if (LIMIT==0) return MAIN12400;
if (LIMIT<0&LOC<=8) return MAIN12600;
if (LIMIT<=30) return MAIN12200;

return MAIN19999;
}
function MAIN19999 () {
K=43;
if (LIQLOC(LOC)==WATER) K=70;
//
//  Do preliminary analysis of sentence to find certain special
//  cases, viz,
//
//  ENTER <WATER,STREAM>
//  ENTER <LOCATION>
//  <WATER,OIL> <PLANT,DOOR>
//
I=VOCAB(WORD1,-1);
J=VOCAB(WORD2,-1);
if (WORD1!='ENTER') return MAIN2609;
if (J==(WATER+1000)|J==STREAM) return MAIN2010;
if (WORD2!='') return MAIN2800;

return MAIN2609;
}
function MAIN2609 () {
if ((I!=(WATER+1000)&I!=(OIL+1000))|(J!=(PLANT+1000)&J!=(DOOR+1000))) return MAIN2610;
WORD2='POUR';

return MAIN2610;
}
function MAIN2610 () {
if (WORD1=='WEST'&PCT(10)) RSPEAK(17);

return MAIN2630;
}
function MAIN2630 () {
I=VOCAB(WORD1,-1);
if (I==-1) return MAIN3000;
K=MOD(I,1000);
KQ=Truncate(I/1000)+1;
if ((GOTOg = CompGOTO (KQ, MAIN8, MAIN5000, MAIN4000, MAIN2010)) != null) return GOTOg;
return BUG(22);
//
//  Get second word for analysis.
//

}
function MAIN2800 () {
WORD1=WORD2;
WORD2='';
return MAIN2610;
//
//  Gee, I don't understand.
//

}
function MAIN3000 () {
SPK=60;
if (PCT(20)) SPK=61;
if (PCT(20)) SPK=13;
RSPEAK(SPK);
return MAIN2600;
//
//  Analyse a verb.  Remember what it was, go back for object if second word
//  unless verb is "SAY", which snarfs arbitrary second word.
//

}
function MAIN4000 () {
VERB=K;
SPK=ACTSPK[VERB];
if (WORD2=='') return MAIN4080;	 //  any object?
if (VERB==SAY) return MAIN4090;	 //  say?
return MAIN2800;	 //  go analyze object
//
//  Analyse an intransitive verb (ie, no object given yet).
//

}
function MAIN4080 () {
if ((GOTOg = CompGOTO (VERB, MAIN8010, MAIN8000, MAIN8000, MAIN8040, MAIN2009, MAIN8040, MAIN9070,
		 MAIN9080, MAIN8000, MAIN8000, MAIN2011, MAIN9120, MAIN9130, MAIN8140, MAIN9150,
		 MAIN8000, MAIN8000, MAIN8180, MAIN8000, MAIN8200, MAIN8000, MAIN9220, MAIN9230,
		 MAIN8240, MAIN8250, MAIN8260, MAIN8270, MAIN8000, MAIN8000, MAIN8300, MAIN8310,
		 MAIN8320)) != null) return GOTOg;
//	     TAKE DROP  SAY OPEN NOTH LOCK   ON  OFF WAVE CALM
//	     WALK KILL POUR  EAT DRNK  RUB TOSS QUIT FIND INVN
//	     FEED FILL BLST SCOR  FOO  BRF READ BREK WAKE SUSP
//	     HOUR RESU
return BUG(23);
//
//  Analyse a transitive verb.
//

}
function MAIN4090 () {
if ((GOTOg = CompGOTO (VERB, MAIN9010, MAIN9020, MAIN9030, MAIN9040, MAIN2009, MAIN9040, MAIN9070,
		 MAIN9080, MAIN9090, MAIN2011, MAIN2011, MAIN9120, MAIN9130, MAIN9140, MAIN9150,
		 MAIN9160, MAIN9170, MAIN2011, MAIN9190, MAIN9190, MAIN9210, MAIN9220, MAIN9230,
		 MAIN2011, MAIN2011, MAIN2011, MAIN9270, MAIN9280, MAIN9290, MAIN2011, MAIN2011,
		 MAIN2011)) != null) return GOTOg;
//	     TAKE DROP  SAY OPEN NOTH LOCK   ON  OFF WAVE CALM
//	     WALK KILL POUR  EAT DRNK  RUB TOSS QUIT FIND INVN
//	     FEED FILL BLST SCOR  FOO  BRF READ BREK WAKE SUSP
//	     HOUR RESU
return BUG(24);
//
//  Analyse an object word.  See if the thing is here, whether we've got a verb
//  yet, and so on.  Object must be here unless verb is "FIND" or "INVENT(ORY)"
//  (and no new verb yet to be analysed).  Water and oil are also funny, since
//  they are never actually dropped at any location, but might be here inside
//  the bottle or as a feature of the location.
//

}
function MAIN5000 () {
OBJ=K;
if (FIXED[K]!=LOC&!HERE(K)) return MAIN5100;

return MAIN5010;
}
function MAIN5010 () {
if (WORD2!='') return MAIN2800;
if (VERB!=0) return MAIN4090;
 MAIN5015 (WORD1.substr(-1+(1),(NBLEN(WORD1))));

return MAIN2600;
//

}
function MAIN5100 () {
if (K!=GRATE) return MAIN5110;
if (LOC==1|LOC==4|LOC==7) K=DPRSSN;
if (LOC>9&LOC<15) K=ENTRNC;
if (K!=GRATE) return MAIN8;

return MAIN5110;
}
function MAIN5110 () {
if (K!=DWARF) return MAIN5120;
I=(1);

return MAIN_11;
}
function MAIN_11 () {

if (DLOC[I]==LOC&DFLAG>=2) return MAIN5010;

return MAIN5112;
}
function MAIN5112 () {
if (++I<=5)return MAIN_11;


return MAIN5120;
}
function MAIN5120 () {
if ((LIQ(0)==K&HERE(BOTTLE))|K==LIQLOC(LOC)) return MAIN5010;
if (OBJ!=PLANT|!AT(PLANT2)|PROP[PLANT2]==0) return MAIN5130;
OBJ=PLANT2;
return MAIN5010;

}
function MAIN5130 () {
if (OBJ!=KNIFE|KNFLOC!=LOC) return MAIN5140;
KNFLOC=-1;
SPK=116;
return MAIN2011;

}
function MAIN5140 () {
if (OBJ!=ROD|!HERE(ROD2)) return MAIN5190;
OBJ=ROD2;
return MAIN5010;

}
function MAIN5190 () {
if ((VERB==FIND|VERB==INVENT)&WORD2=='') return MAIN5010;
 MAIN5199 (WORD1.substr(-1+(1),(NBLEN(WORD1))));

return MAIN2012;

//  Figure out the new location
//
//  Given the current location in "LOC", and a motion verb number in "K", put
//  the new location in "NEWLOC".  The current LOC is saved in "OLDLOC" in case
//  he wants to retreat.  The current OLDLOC is saved in OLDLC2, in case he
//  dies.  (If he does, NEWLOC will be limbo, and OLDLOC will be what killed
//  him, so we need OLDLC2, which is the last place he was safe.)
//

}
function MAIN8 () {
KK=KEY[LOC];
NEWLOC=LOC;
if (KK==0) return BUG(26);
if (K==NULL) return MAIN2;
if (K==BACK) return MAIN20;
if (K==LOOK) return MAIN30;
if (K==CAVE) return MAIN40;
OLDLC2=OLDLOC;
OLDLOC=LOC;
//

return MAIN9;
}
function MAIN9 () {
LL=IABS(TRAVEL[KK]);
if (LL==1|LL==K) return MAIN10;
if (TRAVEL[KK]<0) return MAIN50;
KK++;
return MAIN9;
//

}
function MAIN10 () {
NEWLOC=TRVCON[KK];
K=MOD(NEWLOC,OBJMAX);
if (NEWLOC<=300) return MAIN13;
if (PROP[K]!=Truncate(NEWLOC/OBJMAX)-3) return MAIN16;
//
//  Try next entry in travel table
//

return MAIN12;
}
function MAIN12 () {
if (TRAVEL[KK]<0) return BUG(25);
KK++;
//
//  Make sure he doesn't go through same test again
//
if (TRVCON[KK-1]==TRVCON[KK]&TRVLOC[KK-1]==TRVLOC[KK]) return MAIN12;
return MAIN10;
//

}
function MAIN13 () {
if (NEWLOC<=OBJMAX) return MAIN14;
if (TOTING(K)|(NEWLOC>200&AT(K))) return MAIN16;
return MAIN12;
//

}
function MAIN14 () {
if (NEWLOC!=0&!PCT(NEWLOC)) return MAIN12;

return MAIN16;
}
function MAIN16 () {
NEWLOC=TRVLOC[KK];
if (NEWLOC<=300) return MAIN2;
if (NEWLOC<=500) return MAIN30000;
RSPEAK(NEWLOC-500);
NEWLOC=LOC;
return MAIN2;
//
//  Special motions come here.  Labelling convention: statement numbers NNNXX
//  (XX=00-99) ARE used for special case number NNN (NNN=301-500).
//

}
function MAIN30000 () {
NEWLOC=NEWLOC-300;
if ((GOTOg = CompGOTO (NEWLOC, MAIN30100, MAIN30200, MAIN30300)) != null) return GOTOg;
return BUG(20);
//
//  Travel 301.  Plover-Alcove passage.  Can carry only emerald.  Note: travel
//  table must include "useless" entries going through passage, which can never
//  be used for actual motion, but can be spotted by "go back".
//

}
function MAIN30100 () {
NEWLOC=99+100-LOC;
if (HOLDNG==0|(HOLDNG==1&TOTING(EMRALD))) return MAIN2;
NEWLOC=LOC;
RSPEAK(117);
return MAIN2;
//
//  Travel 302.  Plover transport.  Drop the emerald (only use special travel if
//  toting it), so he's forced to use the Plover-passage to get it out.  Having
//  dropped it, go back and pretend he wasn't carrying it after all.
//

}
function MAIN30200 () {
DROP(EMRALD,LOC);
return MAIN12;
//
//  Travel 303.  Troll Bridge.  Must be done only as special motion so that
//  dwarves won't wander across and encounter the bear.  (They won't follow the
//  player there because that region is forbidden to the pirate.)  If
//  PROP(TROLL)=1, he's crossed since paying, so step out and block him.
//  (Standard travel entries check for PROP(TROLL)=0.)  Special stuff for bear.
//

}
function MAIN30300 () {
if (PROP[TROLL]!=1) return MAIN30310;
PSPEAK(TROLL,1);
PROP[TROLL]=0;
MOVE(TROLL2,0);
MOVE(TROLL2+OBJMAX,0);
MOVE(TROLL,PLAC[TROLL]);
MOVE(TROLL+OBJMAX,FIXD[TROLL]);
JUGGLE(CHASM);
NEWLOC=LOC;
return MAIN2;
//

}
function MAIN30310 () {
NEWLOC=PLAC[TROLL]+FIXD[TROLL]-LOC;
if (PROP[TROLL]==0) PROP[TROLL]=1;
if (!TOTING(BEAR)) return MAIN2;
RSPEAK(162);
PROP[CHASM]=1;
PROP[TROLL]=2;
DROP(BEAR,NEWLOC);
FIXED[BEAR]=-1;
PROP[BEAR]=3;
if (PROP[SPICES]<0) TALLY2++;
OLDLC2=NEWLOC;
return MAIN99;
//
//  End of specials.
//
//  Handle "GO BACK".  Look for verb which goes from LOC to OLDLOC, or to OLDLC2
//  if OLDLOC HAS FORCED-MOTION.  K2 saves entry -> forced LOC -> previous LOC.
//

}
function MAIN20 () {
K=OLDLOC;
if (FORCED(K)) K=OLDLC2;
OLDLC2=OLDLOC;
OLDLOC=LOC;
K2=0;
if (K!=LOC) return MAIN21;
RSPEAK(91);
return MAIN2;
//

}
function MAIN21 () {
LL=TRVLOC[KK];
if (LL==K) return MAIN25;
if (LL>300) return MAIN22;
J=KEY[LL];
if (FORCED(LL)&TRVLOC[KK]==K) K2=KK;

return MAIN22;
}
function MAIN22 () {
if (TRAVEL[KK]<0) return MAIN23;
KK++;
return MAIN21;
//

}
function MAIN23 () {
KK=K2;
if (KK!=0) return MAIN25;
RSPEAK(140);
return MAIN2;
//

}
function MAIN25 () {
K=IABS(TRAVEL[KK]);
KK=KEY[LOC];
return MAIN9;
//
//  Look.  Can't give more detail.  Pretend it wasn't dark (though it may "now"
//  be dark) so he won't fall into a pit while staring into the gloom.
//

}
function MAIN30 () {
if (DETAIL<3) RSPEAK(15);
DETAIL++;
WZDARK=false;
ABB[LOC]=0;
return MAIN2;
//
//  Cave.  Different messages depending on whether above ground.
//

}
function MAIN40 () {
if (LOC<8) RSPEAK(57);
if (LOC>=8) RSPEAK(58);
return MAIN2;
//
//  Non-applicable motion.  Various messages depending on word given.
//

}
function MAIN50 () {
SPK=12;
if (K>=43&K<=50) SPK=9;
if (K==29|K==30) SPK=9;
if (K==7|K==36|K==37) SPK=10;
if (K==11|K==19) SPK=11;
if (VERB==FIND|VERB==INVENT) SPK=59;
if (K==62|K==65) SPK=42;
if (K==17) SPK=80;
RSPEAK(SPK);
return MAIN2;

//  "You're dead, Jim."
//
//  If the current LOC is zero, it means the clown got himself killed.  We'll
//  allow this MAXDIE times.  MAXDIE is automatically set based on the number of
//  snide messages available.  Each death results in a message (81, 83, etc.)
//  which offers reincarnation; if accepted, this results in message 82, 84,
//  etc.  The last time, if he wants another chance, he gets a snide remark as
//  we exit.  When reincarnated, all objects being carried get dropped at OLDLC2
//  (presumably the last place prior to being killed) without change of PROPS.
//  The loop runs backwards to assure that the bird is dropped before the cage.
//  (This kluge could be changed once we're sure all references to bird and cage
//  are done by keywords.)  The lamp is a special case (it wouldn't do to leave
//  it in the cave).  It is turned off and left outside the building (only if he
//  was carrying it, of course).  He himself is left inside the building (and
//  heaven help him if he tries to XYZZY back into the cave without the lamp!).
//  OLDLOC is zapped so he can't just "RETREAT".
//
//  The easiest way to get killed is to fall into a pit in pitch darkness.
//

}
function MAIN90 () {
RSPEAK(23);
OLDLC2=LOC;
//
//  Okay, he's dead.  Let's get on with it.
//

return MAIN99;
}
function MAIN99 () {
if (CLOSNG) return MAIN95;

return MAIN_12;
}
function MAIN_12 () {
if (YesNo(81+NUMDIE*2,82+NUMDIE*2,54)) return MAIN_12;
YEA=YES;
NUMDIE++;
if (NUMDIE==MAXDIE|!YEA) return MAIN20000;
PLACE[WATER]=0;
PLACE[OIL]=0;
if (TOTING(LAMP)) PROP[LAMP]=0;
J=(1);

return MAIN_13;
}
function MAIN_13 () {

I=OBJMAX+1-J;
if (!TOTING(I)) return MAIN98;
K=OLDLC2;
if (I==LAMP) K=1;
DROP(I,K);

return MAIN98;
}
function MAIN98 () {
if (++J<=OBJMAX)return MAIN_13;

LOC=3;
OLDLOC=LOC;
return MAIN2000;
//
//  He died during closing time.  No resurrection.  Tally up a death and exit.
//

}
function MAIN95 () {
RSPEAK(131);
NUMDIE++;
return MAIN20000;

//  Routines for performing the various action verbs
//
//  Statement numbers in this section are 8000 for intransitive verbs, 9000 for
//  transitive, plus ten times the verb number.  Many intransitive verbs use the
//  transitive code, and some verbs use code for other verbs, as noted below.
//
//  Random intransitive verbs come here.  Clear OBJ just in case (see "ATTACK").
//

}
function MAIN8000 () {
 MAIN8002 (WORD1.substr(-1+(1),(NBLEN(WORD1))));

OBJ=0;
return MAIN2600;
//
//  Carry, no object given yet.  Ok if only one object present.
//

}
function MAIN8010 () {
if (ATLOC[LOC]==0|LINK[ATLOC[LOC]]!=0) return MAIN8000;
I=(1);

return MAIN_14;
}
function MAIN_14 () {

if (DLOC[I]==LOC&DFLAG>=2) return MAIN8000;

return MAIN8012;
}
function MAIN8012 () {
if (++I<=5)return MAIN_14;

OBJ=ATLOC[LOC];
//
//  Carry an object.  Special cases for bird and cage (if bird in cage, can't
//  take one without the other.  Liquids also special, since they depend on
//  status of bottle.  Also various side effects, etc.
//

return MAIN9010;
}
function MAIN9010 () {
if (TOTING(OBJ)) return MAIN2011;
SPK=25;
if (OBJ==PLANT&PROP[PLANT]<=0) SPK=115;
if (OBJ==BEAR&PROP[BEAR]==1) SPK=169;
if (OBJ==CHAIN&PROP[BEAR]!=0) SPK=170;
if (FIXED[OBJ]!=0) return MAIN2011;
if (OBJ!=WATER&OBJ!=OIL) return MAIN9017;
if (HERE(BOTTLE)&LIQ(0)==OBJ) return MAIN9018;
OBJ=BOTTLE;
if (TOTING(BOTTLE)&PROP[BOTTLE]==1) return MAIN9220;
if (PROP[BOTTLE]!=1) SPK=105;
if (!TOTING(BOTTLE)) SPK=104;
return MAIN2011;

}
function MAIN9018 () {
OBJ=BOTTLE;

return MAIN9017;
}
function MAIN9017 () {
if (HOLDNG<7) return MAIN9016;
RSPEAK(92);
return MAIN2012;

}
function MAIN9016 () {
if (OBJ!=BIRD) return MAIN9014;
if (PROP[BIRD]!=0) return MAIN9014;
if (!TOTING(ROD)) return MAIN9013;
RSPEAK(26);
return MAIN2012;

}
function MAIN9013 () {
if (TOTING(CAGE)) return MAIN9015;
RSPEAK(27);
return MAIN2012;

}
function MAIN9015 () {
PROP[BIRD]=1;

return MAIN9014;
}
function MAIN9014 () {
if ((OBJ==BIRD|OBJ==CAGE)&PROP[BIRD]!=0) CARRY(BIRD+CAGE-OBJ,LOC);
CARRY(OBJ,LOC);
K=LIQ(0);
if (OBJ==BOTTLE&K!=0) PLACE[K]=-1;
return MAIN2009;
//
//  Discard object.  "THROW" also comes here for most objects.  Special cases for
//  bird (might attack snake or dragon) and cage (might contain bird) and vase.
//  Drop coins at vending machine for extra batteries.
//

}
function MAIN9020 () {
if (TOTING(ROD2)&OBJ==ROD&!TOTING(ROD)) OBJ=ROD2;
if (!TOTING(OBJ)) return MAIN2011;
if (OBJ!=BIRD|!HERE(SNAKE)) return MAIN9024;
RSPEAK(30);
if (CLOSED) return MAIN19000;
DSTROY(SNAKE);
//
//  Set prop for use by travel options
//
PROP[SNAKE]=1;

return MAIN9021;
}
function MAIN9021 () {
K=LIQ(0);
if (K==OBJ) OBJ=BOTTLE;
if (OBJ==BOTTLE&K!=0) PLACE[K]=0;
if (OBJ==CAGE&PROP[BIRD]!=0) DROP(BIRD,LOC);
if (OBJ==BIRD) PROP[BIRD]=0;
DROP(OBJ,LOC);
return MAIN2012;
//

}
function MAIN9024 () {
if (OBJ!=COINS|!HERE(VEND)) return MAIN9025;
DSTROY(COINS);
DROP(BATTER,LOC);
PSPEAK(BATTER,0);
return MAIN2012;
//

}
function MAIN9025 () {
if (OBJ!=BIRD|!AT(DRAGON)|PROP[DRAGON]!=0) return MAIN9026;
RSPEAK(154);
DSTROY(BIRD);
PROP[BIRD]=0;
if (PLACE[SNAKE]==PLAC[SNAKE]) TALLY2++;
return MAIN2012;
//

}
function MAIN9026 () {
if (OBJ!=BEAR|!AT(TROLL)) return MAIN9027;
RSPEAK(163);
MOVE(TROLL,0);
MOVE(TROLL+OBJMAX,0);
MOVE(TROLL2,PLAC[TROLL]);
MOVE(TROLL2+OBJMAX,FIXD[TROLL]);
JUGGLE(CHASM);
PROP[TROLL]=2;
return MAIN9021;
//

}
function MAIN9027 () {
if (OBJ==VASE&LOC!=PLAC[PILLOW]) return MAIN9028;
RSPEAK(54);
return MAIN9021;
//

}
function MAIN9028 () {
PROP[VASE]=2;
if (AT(PILLOW)) PROP[VASE]=0;
PSPEAK(VASE,PROP[VASE]+1);
if (PROP[VASE]!=0) FIXED[VASE]=-1;
return MAIN9021;
//
//  SAY.  Echo WORD2 (or WORD1 if no WORD2 (SAY what?, etc.).)
//  Magic words override.
//

}
function MAIN9030 () {
if (WORD2=='') return MAIN9031;
WORD1=WORD2;

return MAIN9031;
}
function MAIN9031 () {
I=VOCAB(WORD1,-1);
if (I==62|I==65|I==71|I==2025) return MAIN9035;
 MAIN9032 (WORD1.substr(-1+(1),(NBLEN(WORD1))));

return MAIN2012;
//

}
function MAIN9035 () {
WORD2='';
OBJ=0;
return MAIN2630;
//
//  LOCK, UNLOCK, no object given.  Assume various things if present.
//

}
function MAIN8040 () {
SPK=28;
if (HERE(CLAM)) OBJ=CLAM;
if (HERE(OYSTER)) OBJ=OYSTER;
if (AT(DOOR)) OBJ=DOOR;
if (AT(GRATE)) OBJ=GRATE;
if (OBJ!=0&HERE(CHAIN)) return MAIN8000;
if (HERE(CHAIN)) OBJ=CHAIN;
if (OBJ==0) return MAIN2011;
//
//  LOCK, UNLOCK object.  Special stuff for opening clam/oyster and for chain.
//

return MAIN9040;
}
function MAIN9040 () {
if (OBJ==CLAM|OBJ==OYSTER) return MAIN9046;
if (OBJ==DOOR) SPK=111;
if (OBJ==DOOR&PROP[DOOR]==1) SPK=54;
if (OBJ==CAGE) SPK=32;
if (OBJ==KEYS) SPK=55;
if (OBJ==GRATE|OBJ==CHAIN) SPK=31;
if (SPK!=31|!HERE(KEYS)) return MAIN2011;
if (OBJ==CHAIN) return MAIN9048;
if (!CLOSNG) return MAIN9043;
K=130;
if (!PANIC) CLOCK2=15;
PANIC=true;
return MAIN2010;
//

}
function MAIN9043 () {
K=34+PROP[GRATE];
PROP[GRATE]=1;
if (VERB==LOCK) PROP[GRATE]=0;
K=K+2*PROP[GRATE];
return MAIN2010;
//
//  Clam/oyster.
//

}
function MAIN9046 () {
K=0;
if (OBJ==OYSTER) K=1;
SPK=124+K;
if (TOTING(OBJ)) SPK=120+K;
if (!TOTING(TRIDNT)) SPK=122+K;
if (VERB==LOCK) SPK=61;
if (SPK!=124) return MAIN2011;
DSTROY(CLAM);
DROP(OYSTER,LOC);
DROP(PEARL,105);
return MAIN2011;
//
//  Chain.
//

}
function MAIN9048 () {
if (VERB==LOCK) return MAIN9049;
SPK=171;
if (PROP[BEAR]==0) SPK=41;
if (PROP[CHAIN]==0) SPK=37;
if (SPK!=171) return MAIN2011;
PROP[CHAIN]=0;
FIXED[CHAIN]=0;
if (PROP[BEAR]!=3) PROP[BEAR]=2;
FIXED[BEAR]=2-PROP[BEAR];
return MAIN2011;
//

}
function MAIN9049 () {
SPK=172;
if (PROP[CHAIN]!=0) SPK=34;
if (LOC!=PLAC[CHAIN]) SPK=173;
if (SPK!=172) return MAIN2011;
PROP[CHAIN]=2;
if (TOTING(CHAIN)) DROP(CHAIN,LOC);
FIXED[CHAIN]=-1;
return MAIN2011;
//
//  Light lamp
//

}
function MAIN9070 () {
if (!HERE(LAMP)) return MAIN2011;
SPK=184;
if (LIMIT<0) return MAIN2011;
PROP[LAMP]=1;
RSPEAK(39);
if (WZDARK) return MAIN2000;
return MAIN2012;
//
//  Lamp off
//

}
function MAIN9080 () {
if (!HERE(LAMP)) return MAIN2011;
PROP[LAMP]=0;
RSPEAK(40);
if (DARK(0)) RSPEAK(16);
return MAIN2012;
//
//  Wave.  No effect unless waving rod at fissure.
//

}
function MAIN9090 () {
if ((!TOTING(OBJ))&(OBJ!=ROD|!TOTING(ROD2))) SPK=29;
if (OBJ!=ROD|!AT(FISSUR)|!TOTING(OBJ)|CLOSNG) return MAIN2011;
PROP[FISSUR]=1-PROP[FISSUR];
PSPEAK(FISSUR,2-PROP[FISSUR]);
return MAIN2012;
//
//  Attack.  Assume target if unambiguous.  "THROW" also links here.  Attackable
//  objects fall into two categories: enemies (snake, dwarf, etc.)  and others
//  (bird, clam).  Ambiguous if two enemies, or if no enemies but two others.
//

}
function MAIN9120 () {
I=(1);

return MAIN_15;
}
function MAIN_15 () {

if (DLOC[I]==LOC&DFLAG>=2) return MAIN9122;

return MAIN9121;
}
function MAIN9121 () {
if (++I<=5)return MAIN_15;

I=0;

return MAIN9122;
}
function MAIN9122 () {
if (OBJ!=0) return MAIN9124;
if (I!=0) OBJ=DWARF;
if (HERE(SNAKE)) OBJ=OBJ*100+SNAKE;
if (AT(DRAGON)&PROP[DRAGON]==0) OBJ=OBJ*100+DRAGON;
if (AT(TROLL)) OBJ=OBJ*100+TROLL;
if (HERE(BEAR)&PROP[BEAR]==0) OBJ=OBJ*100+BEAR;
if (OBJ>100) return MAIN8000;
if (OBJ!=0) return MAIN9124;
//
//  Can't attack bird by throwing axe.
//
if (HERE(BIRD)&VERB!=THROW) OBJ=BIRD;
//
//  Clam and oyster both treated as clam for intransitive case; no harm done.
//
if (HERE(CLAM)|HERE(OYSTER)) OBJ=100*OBJ+CLAM;
if (OBJ>100) return MAIN8000;

return MAIN9124;
}
function MAIN9124 () {
if (OBJ!=BIRD) return MAIN9125;
SPK=137;
if (CLOSED) return MAIN2011;
DSTROY(BIRD);
PROP[BIRD]=0;
if (PLACE[SNAKE]==PLAC[SNAKE]) TALLY2++;
SPK=45;

return MAIN9125;
}
function MAIN9125 () {
if (OBJ==0) SPK=44;
if (OBJ==CLAM|OBJ==OYSTER) SPK=150;
if (OBJ==SNAKE) SPK=46;
if (OBJ==DWARF) SPK=49;
if (OBJ==DWARF&CLOSED) return MAIN19000;
if (OBJ==DRAGON) SPK=167;
if (OBJ==TROLL) SPK=157;
if (OBJ==BEAR) SPK=165+Truncate((PROP[BEAR]+1)/2);
if (OBJ!=DRAGON|PROP[DRAGON]!=0) return MAIN2011;
//
//  Fun stuff for dragon.  If he insists on attacking it, win!  Set prop to dead,
//  move dragon to central LOC (still fixed), move rug there (not fixed), and
//  move him there, too.  Then do a null motion to get new description.
//
RSPEAK(49);
VERB=0;
OBJ=0;

return MAIN_16;
}
function MAIN_16 () {
if (GETIN())return MAIN_16;WORD1=w1;WORD2=w2;
if (WORD1!='Y'&WORD1!='YE'&WORD1!='YES') return MAIN2608;
PSPEAK(DRAGON,1);
PROP[DRAGON]=2;
PROP[RUG]=0;
K=Truncate((PLAC[DRAGON]+FIXD[DRAGON])/2);
MOVE(DRAGON+OBJMAX,-1);
MOVE(RUG+OBJMAX,0);
MOVE(DRAGON,K);
MOVE(RUG,K);
OBJ=(1);

return MAIN_17;
}
function MAIN_17 () {

if (PLACE[OBJ]==PLAC[DRAGON]|PLACE[OBJ]==FIXD[DRAGON]) MOVE(OBJ,K);

return MAIN9126;
}
function MAIN9126 () {
if (++OBJ<=OBJMAX)return MAIN_17;

LOC=K;
K=NULL;
return MAIN8;
//
//  POUR.  If no object, or object is bottle, assume contents of bottle.
//  Special tests for pouring water or oil on plant or rusty door.
//

}
function MAIN9130 () {
if (OBJ==BOTTLE|OBJ==0) OBJ=LIQ(0);
if (OBJ==0) return MAIN8000;
if (!TOTING(OBJ)) return MAIN2011;
SPK=78;
if (OBJ!=OIL&OBJ!=WATER) return MAIN2011;
PROP[BOTTLE]=1;
PLACE[OBJ]=0;
SPK=77;
if (!(AT(PLANT)|AT(DOOR))) return MAIN2011;
//
if (AT(DOOR)) return MAIN9132;
SPK=112;
if (OBJ!=WATER) return MAIN2011;
PSPEAK(PLANT,PROP[PLANT]+1);
PROP[PLANT]=MOD(PROP[PLANT]+2,6);
PROP[PLANT2]=Truncate(PROP[PLANT]/2);
K=NULL;
return MAIN8;
//

}
function MAIN9132 () {
PROP[DOOR]=0;
if (OBJ==OIL) PROP[DOOR]=1;
SPK=113+PROP[DOOR];
return MAIN2011;
//
//  EAT.  Intransitive: assume food if present, else ask what.  Transitive: food
//  ok, some things lose appetite, rest are ridiculous.
//

}
function MAIN8140 () {
if (!HERE(FOOD)) return MAIN8000;

return MAIN8142;
}
function MAIN8142 () {
DSTROY(FOOD);
SPK=72;
return MAIN2011;
//

}
function MAIN9140 () {
if (OBJ==FOOD) return MAIN8142;
if (OBJ==BIRD|OBJ==SNAKE|OBJ==CLAM|OBJ==OYSTER|OBJ==DWARF|OBJ==DRAGON|
	OBJ==TROLL|OBJ==BEAR) SPK=71;
return MAIN2011;
//
//  DRINK.  If no object, assume water and look for it here.  If water is in
//  the bottle, drink that, else must be at a water LOC, so drink stream.
//

}
function MAIN9150 () {
if (OBJ==0&LIQLOC(LOC)!=WATER&(LIQ(0)!=WATER|!HERE(BOTTLE))) return MAIN8000;
if (OBJ!=0&OBJ!=WATER) SPK=110;
if (SPK==110|LIQ(0)!=WATER|!HERE(BOTTLE)) return MAIN2011;
PROP[BOTTLE]=1;
PLACE[WATER]=0;
SPK=74;
return MAIN2011;
//
//  RUB.  Yields various snide remarks.
//

}
function MAIN9160 () {
if (OBJ!=LAMP) SPK=76;
return MAIN2011;
//
//  THROW.  Same as discard unless axe.  Then same as attack except ignore bird,
//  and if dwarf is present then one might be killed.  (Only way to do so!)
//  Axe also special for dragon, bear, and troll.  Treasures special for troll.
//

}
function MAIN9170 () {
if (TOTING(ROD2)&OBJ==ROD&!TOTING(ROD)) OBJ=ROD2;
if (!TOTING(OBJ)) return MAIN2011;
if (OBJ>=50&OBJ<=MAXTRS&AT(TROLL)) return MAIN9178;
if (OBJ==FOOD&HERE(BEAR)) return MAIN9177;
if (OBJ!=AXE) return MAIN9020;
I=(1);

return MAIN_18;
}
function MAIN_18 () {

//
//  Needn't check dflag if axe is here.
//
if (DLOC[I]==LOC) return MAIN9172;

return MAIN9171;
}
function MAIN9171 () {
if (++I<=5)return MAIN_18;

SPK=152;
if (AT(DRAGON)&PROP[DRAGON]==0) return MAIN9175;
SPK=158;
if (AT(TROLL)) return MAIN9175;
if (HERE(BEAR)&PROP[BEAR]==0) return MAIN9176;
OBJ=0;
return MAIN9120;
//

}
function MAIN9172 () {
SPK=48;
if (RND(3)==0) return MAIN9175;
DSEEN[I]=false;
DLOC[I]=0;
SPK=47;
DKILL++;
if (DKILL==1) SPK=149;

return MAIN9175;
}
function MAIN9175 () {
RSPEAK(SPK);
DROP(AXE,LOC);
K=NULL;
return MAIN8;
//
//  This'll teach him to throw the axe at the bear!
//

}
function MAIN9176 () {
SPK=164;
DROP(AXE,LOC);
FIXED[AXE]=-1;
PROP[AXE]=1;
JUGGLE(BEAR);
return MAIN2011;
//
//  But throwing food is another story.
//

}
function MAIN9177 () {
OBJ=BEAR;
return MAIN9210;
//
//  Snarf a treasure for the troll.
//

}
function MAIN9178 () {
SPK=159;
DROP(OBJ,0);
MOVE(TROLL,0);
MOVE(TROLL+OBJMAX,0);
DROP(TROLL2,PLAC[TROLL]);
DROP(TROLL2+OBJMAX,FIXD[TROLL]);
JUGGLE(CHASM);
return MAIN2011;
//
//  QUIT.  Intransitive only.  Verify intent and exit if that's what he wants.
//

}
function MAIN8180 () {

return MAIN_19;
}
function MAIN_19 () {
if (YesNo(22,54,54)) return MAIN_19;
GAVEUP=YES;

return MAIN8185;
}
function MAIN8185 () {
if (GAVEUP) return MAIN20000;
return MAIN2012;
//
//  FIND.  Might be carrying it, or it might be here.  Else give caveat.
//

}
function MAIN9190 () {
if (AT(OBJ)|(LIQ(0)==OBJ&AT(BOTTLE))|K==LIQLOC(LOC)) SPK=94;
I=(1);

return MAIN_20;
}
function MAIN_20 () {


return MAIN9192;
}
function MAIN9192 () {
if (DLOC[I]==LOC&DFLAG>=2&OBJ==DWARF) SPK=94;if (++I<=5)return MAIN_20;

if (CLOSED) SPK=138;
if (TOTING(OBJ)) SPK=24;
return MAIN2011;
//
//  INVENTORY.  If object, treat same as FIND.  Else report on current burden.
//

}
function MAIN8200 () {
SPK=98;
I=(1);

return MAIN_21;
}
function MAIN_21 () {

if (I==BEAR|!TOTING(I)) return MAIN8201;
if (SPK==98) RSPEAK(99);
PSPEAK(I,-1);
SPK=0;

return MAIN8201;
}
function MAIN8201 () {
if (++I<=OBJMAX)return MAIN_21;

if (TOTING(BEAR)) SPK=141;
return MAIN2011;
//
//  FEED.  If bird, no seed.  Snake, dragon, troll: quip.  If dwarf, make him
//  mad.  Bear, special.
//

}
function MAIN9210 () {
if (OBJ!=BIRD) return MAIN9212;
SPK=100;
return MAIN2011;
//

}
function MAIN9212 () {
if (OBJ!=SNAKE&OBJ!=DRAGON&OBJ!=TROLL) return MAIN9213;
SPK=102;
if (OBJ==DRAGON&PROP[DRAGON]!=0) SPK=110;
if (OBJ==TROLL) SPK=182;
if (OBJ!=SNAKE|CLOSED|!HERE(BIRD)) return MAIN2011;
SPK=101;
DSTROY(BIRD);
PROP[BIRD]=0;
TALLY2++;
return MAIN2011;
//

}
function MAIN9213 () {
if (OBJ!=DWARF) return MAIN9214;
if (!HERE(FOOD)) return MAIN2011;
SPK=103;
DFLAG++;
return MAIN2011;
//

}
function MAIN9214 () {
if (OBJ!=BEAR) return MAIN9215;
if (PROP[BEAR]==0) SPK=102;
if (PROP[BEAR]==3) SPK=110;
if (!HERE(FOOD)) return MAIN2011;
DSTROY(FOOD);
PROP[BEAR]=1;
FIXED[AXE]=0;
PROP[AXE]=0;
SPK=168;
return MAIN2011;
//

}
function MAIN9215 () {
SPK=14;
return MAIN2011;
//
//  FILL.  Bottle must be empty, and some liquid available.  (Vase is nasty.)
//

}
function MAIN9220 () {
if (OBJ==VASE) return MAIN9222;
if (OBJ!=0&OBJ!=BOTTLE) return MAIN2011;
if (OBJ==0&!HERE(BOTTLE)) return MAIN8000;
SPK=107;
if (LIQLOC(LOC)==0) SPK=106;
if (LIQ(0)!=0) SPK=105;
if (SPK!=107) return MAIN2011;
PROP[BOTTLE]=Truncate(MOD(COND[LOC],4)/2)*2;
K=LIQ(0);
if (TOTING(BOTTLE)) PLACE[K]=-1;
if (K==OIL) SPK=108;
return MAIN2011;
//

}
function MAIN9222 () {
SPK=29;
if (LIQLOC(LOC)==0) SPK=144;
if (LIQLOC(LOC)==0|!TOTING(VASE)) return MAIN2011;
RSPEAK(145);
PROP[VASE]=2;
FIXED[VASE]=-1;
return MAIN9024;
//
//  BLAST.  No effect unless you've got dynamite, which is a neat trick!
//

}
function MAIN9230 () {
if (PROP[ROD2]<0|!CLOSED) return MAIN2011;
BONUS=133;
if (LOC==115) BONUS=134;
if (HERE(ROD2)) BONUS=135;
RSPEAK(BONUS);
return MAIN20000;
//
//  SCORE.  Go to scoring section, which will return to 8241 if SCORNG is true.
//

}
function MAIN8240 () {
SCORNG=true;
return MAIN20000;
//

}
function MAIN8241 () {
SCORNG=false;
 MAIN8243 (SCORE,MXSCOR);


return MAIN_22;
}
function MAIN_22 () {
if (YesNo(143,54,54)) return MAIN_22;
GAVEUP=YES;
return MAIN8185;
//
//  FEE FIE FOE FOO (and FUM).  Advance to next state if given in proper order.
//  Look up WORD1 in section 3 of VOCAB to determine which word we've got.  Last
//  word zips the eggs back to the Giant Room (unless already there).
//

}
function MAIN8250 () {
K=VOCAB(WORD1,3);
SPK=42;
if (FOOBAR==1-K) return MAIN8252;
if (FOOBAR!=0) SPK=151;
return MAIN2011;
//

}
function MAIN8252 () {
FOOBAR=K;
if (K!=4) return MAIN2009;
FOOBAR=0;
if (PLACE[EGGS]==PLAC[EGGS]|(TOTING(EGGS)&LOC==PLAC[EGGS])) return MAIN2011;
//
//  Bring back troll if we steal the eggs back from him before crossing.
//
if (PLACE[EGGS]==0&PLACE[TROLL]==0&PROP[TROLL]==0) PROP[TROLL]=1;
K=2;
if (HERE(EGGS)) K=1;
if (LOC==PLAC[EGGS]) K=0;
MOVE(EGGS,PLAC[EGGS]);
PSPEAK(EGGS,K);
return MAIN2012;
//
//  BRIEF.  Intransitive only.  Suppress long descriptions after first time.
//

}
function MAIN8260 () {
SPK=156;
ABBNUM=10000;
DETAIL=3;
return MAIN2011;
//
//  READ.  Magazines in dwarvish, message we've seen, and . . . oyster?
//

}
function MAIN8270 () {
if (HERE(MAGZIN)) OBJ=MAGZIN;
if (HERE(TABLET)) OBJ=OBJ*100+TABLET;
if (HERE(MESSAG)) OBJ=OBJ*100+MESSAG;
if (CLOSED&TOTING(OYSTER)) OBJ=OYSTER;
if (OBJ>100|OBJ==0|DARK(0)) return MAIN8000;
//

return MAIN9270;
}
function MAIN9270 () {
if (DARK(0)) return MAIN5190;
if (OBJ==MAGZIN) SPK=190;
if (OBJ==TABLET) SPK=196;
if (OBJ==MESSAG) SPK=191;
if (OBJ==OYSTER&HINTED[2]&TOTING(OYSTER)) SPK=194;
if (OBJ!=OYSTER|HINTED[2]|!TOTING(OYSTER)|!CLOSED) return MAIN2011;

return MAIN_23;
}
function MAIN_23 () {
if (YesNo(192,193,54)) return MAIN_23;
HINTED[2]=YES;
return MAIN2012;
//
//  BREAK.  Only works for mirror in Repository and, of course, the vase.
//

}
function MAIN9280 () {
if (OBJ==MIRROR) SPK=148;
if (OBJ==VASE&PROP[VASE]==0) return MAIN9282;
if (OBJ!=MIRROR|!CLOSED) return MAIN2011;
RSPEAK(197);
return MAIN19000;
//

}
function MAIN9282 () {
SPK=198;
if (TOTING(VASE)) DROP(VASE,LOC);
PROP[VASE]=2;
FIXED[VASE]=-1;
return MAIN2011;
//
//  WAKE.  Only use is to disturb the dwarves.
//

}
function MAIN9290 () {
if (OBJ!=DWARF|!CLOSED) return MAIN2011;
RSPEAK(199);
return MAIN19000;
//
//  SUSPEND.  Save the world.
//

}
function MAIN8300 () {
I=SAVEGM();
return MAIN2012;
//
//  HOURS.  Just a joke.
//

}
function MAIN8310 () {
RSPEAK(201);
return MAIN2012;
//
//  RESUME.  Restore the world.
//

}
function MAIN8320 () {
I=RSTRGM();
return MAIN2012;

//  HINTS
//
//  Come here if he's been long enough at required LOC(S) for some unused hint.
//  Hint number is in variable "HINT".  Branch to quick test for additional
//  conditions, then come back to do neat stuff.  GOTO 40010 if conditions are
//  met and we want to offer the hint.  GOTO 40020 to clear HINTLC back to zero,
//  40030 to take no action yet.
//

}
function MAIN40000 () {
if ((GOTOg = CompGOTO ((HINT-3), MAIN40400, MAIN40500, MAIN40600, MAIN40700, MAIN40800, MAIN40900)) != null) return GOTOg;
//	      CAVE  BIRD  SNAKE MAZE  DARK  WITT
return BUG(27);
//

}
function MAIN40010 () {
HINTLC[HINT]=0;

return MAIN_24;
}
function MAIN_24 () {
if (YesNo(HINTS(HINT,3),0,54)) return MAIN_24;
if (!YES) return MAIN2602;
 MAIN40012 (HINTS(HINT,2));


return MAIN_25;
}
function MAIN_25 () {
if (YesNo(175,HINTS(HINT,4),54)) return MAIN_25;
HINTED[HINT]=YES;
if (HINTED[HINT]&LIMIT>30) LIMIT=LIMIT+30*HINTS(HINT,2);

return MAIN40020;
}
function MAIN40020 () {
HINTLC[HINT]=0;

return MAIN40030;
}
function MAIN40030 () {
return MAIN2602;
//
//  Now for the quick tests.  See database description for one-line notes.
//

}
function MAIN40400 () {
if (PROP[GRATE]==0&!HERE(KEYS)) return MAIN40010;
return MAIN40020;
//

}
function MAIN40500 () {
if (HERE(BIRD)&TOTING(ROD)&OBJ==BIRD) return MAIN40010;
return MAIN40030;
//

}
function MAIN40600 () {
if (HERE(SNAKE)&!HERE(BIRD)) return MAIN40010;
return MAIN40020;
//

}
function MAIN40700 () {
if (ATLOC[LOC]==0&ATLOC[OLDLOC]==0&ATLOC[OLDLC2]==0&HOLDNG>1) return MAIN40010;
return MAIN40020;
//

}
function MAIN40800 () {
if (PROP[EMRALD]!=-1&PROP[PYRAM]==-1) return MAIN40010;
return MAIN40020;
//

}
function MAIN40900 () {
return MAIN40010;

//  Cave closing and scoring
//
//  These sections handle the closing of the cave.  The cave closes "CLOCK1"
//  turns after the last treasure has been located (including the pirate's
//  chest, which may of course never show up).  Note that the treasures need not
//  have been taken yet, just located.  Hence CLOCK1 must be large enough to get
//  out of the cave (it only ticks while inside the cave).  When it hits zero,
//  we branch to 10000 to start closing the cave, and then sit back and wait for
//  him to try to get out.  If he doesn't within CLOCK2 turns, we close the
//  cave; if he does try, we assume he panics, and give him a few additional
//  turns to get frantic before we close.  When CLOCK2 hits zero, we branch to
//  11000 to transport him into the final puzzle.  Note that the puzzle depends
//  upon all sorts of random things.  For instance, there must be no water or
//  oil, since there are beanstalks which we don't want to be able to water,
//  since the code can't handle it.  Also, we can have no keys, since there is a
//  grate (having moved the fixed object!) there separating him from all the
//  treasures.  Most of these problems arise from the use of negative prop
//  numbers to suppress the object descriptions until he's actually moved the
//  objects.
//
//  When the first warning comes, we lock the grate, destroy the bridge, kill
//  all the dwarves (and the pirate), remove the troll and bear (unless dead),
//  and set "CLOSNG" to true.  Leave the dragon; too much trouble to move it.
//  from now until CLOCK2 runs out, he cannot unlock the grate, move to any
//  location outside the cave (LOC<9), or create the bridge.  Nor can he be
//  resurrected if he dies.  Note that the snake is already gone, since he got
//  to the treasure accessible only via the Hall of the Mt. King.  Also, he's
//  been in Giant Room (to get eggs), so we can refer to it.  Also also, he's
//  gotten the pearl, so we know the bivalve is an oyster.  *And*, the dwarves
//  must have been activated, since we've found chest.
//

}
function MAIN10000 () {
PROP[GRATE]=0;
PROP[FISSUR]=0;
I=(1);

return MAIN_26;
}
function MAIN_26 () {

DSEEN[I]=false;

return MAIN10010;
}
function MAIN10010 () {
DLOC[I]=0;if (++I<=6)return MAIN_26;

MOVE(TROLL,0);
MOVE(TROLL+OBJMAX,0);
MOVE(TROLL2,PLAC[TROLL]);
MOVE(TROLL2+OBJMAX,FIXD[TROLL]);
JUGGLE(CHASM);
if (PROP[BEAR]!=3) DSTROY(BEAR);
PROP[CHAIN]=0;
FIXED[CHAIN]=0;
PROP[AXE]=0;
FIXED[AXE]=0;
RSPEAK(129);
CLOCK1=-1;
CLOSNG=true;
return MAIN19999;
//
//  Once he's panicked, and CLOCK2 has run out, we come here to set up the
//  Storage Room.  The room has two locs, hardwired as 115 (NE) and 116 (SW).
//  At the NE end, we place empty bottles, a nursery of plants, a bed of
//  oysters, a pile of lamps, rods with stars, sleeping dwarves, and him.  At
//  the SW end we place grate over treasures, snake pit, covey of caged birds,
//  more rods, and pillows.  A mirror stretches across one wall.  Many of the
//  objects come from known locations and/or states (e.g. the snake is known to
//  have been destroyed and needn't be carried away from its old "PLACE"),
//  making the various objects be handled differently.  We also drop all other
//  objects he might be carrying (lest he have some which could cause trouble,
//  such as the keys).  We describe the flash of light and trundle back.
//

}
function MAIN11000 () {
PROP[BOTTLE]=PUT(BOTTLE,115,1);
PROP[PLANT]=PUT(PLANT,115,0);
PROP[OYSTER]=PUT(OYSTER,115,0);
PROP[LAMP]=PUT(LAMP,115,0);
PROP[ROD]=PUT(ROD,115,0);
PROP[DWARF]=PUT(DWARF,115,0);
LOC=115;
OLDLOC=115;
NEWLOC=115;
//
//  Leave the grate with normal (non-negative property).
//
I=PUT(GRATE,116,0);
PROP[SNAKE]=PUT(SNAKE,116,1);
PROP[BIRD]=PUT(BIRD,116,1);
PROP[CAGE]=PUT(CAGE,116,0);
PROP[ROD2]=PUT(ROD2,116,0);
PROP[PILLOW]=PUT(PILLOW,116,0);
//
PROP[MIRROR]=PUT(MIRROR,115,0);
FIXED[MIRROR]=116;
//
I=(1);

return MAIN_27;
}
function MAIN_27 () {


return MAIN11010;
}
function MAIN11010 () {
if (TOTING(I)) DSTROY(I);if (++I<=OBJMAX)return MAIN_27;

//
RSPEAK(132);
CLOSED=true;
return MAIN2;
//
//  Another way we can force an end to things is by having the lamp give out.
//  When it gets close, we come here to warn him.  We go to 12000 if the lamp
//  and fresh batteries are here, in which case we replace the batteries and
//  continue.  12200 is for other cases of lamp dying.  12400 is when it goes
//  out, and 12600 is if he's wandered outside and the lamp is used up, in which
//  case we force him to give up.
//

}
function MAIN12000 () {
RSPEAK(188);
PROP[BATTER]=1;
if (TOTING(BATTER)) DROP(BATTER,LOC);
LIMIT=LIMIT+2500;
LMWARN=false;
return MAIN19999;
//

}
function MAIN12200 () {
if (LMWARN|!HERE(LAMP)) return MAIN19999;
LMWARN=true;
SPK=187;
if (PLACE[BATTER]==0) SPK=183;
if (PROP[BATTER]==1) SPK=189;
RSPEAK(SPK);
return MAIN19999;
//

}
function MAIN12400 () {
LIMIT=-1;
PROP[LAMP]=0;
if (HERE(LAMP)) RSPEAK(184);
return MAIN19999;
//

}
function MAIN12600 () {
RSPEAK(185);
GAVEUP=true;
return MAIN20000;
//
//
//  Oh dear, he's disturbed the dwarves.
//

}
function MAIN19000 () {
RSPEAK(136);
//
//  Exit code.  will eventually include scoring.  for now, however, ...
//
//  The present scoring algorithm is as follows:
//     objective:          points:        present total possible:
//  getting well into cave   25                    25
//  each treasure < chest    12                    60
//  treasure chest itself    14                    14
//  each treasure > chest    16                   144
//  surviving             (MAX-NUM)*10             30
//  not quitting              4                     4
//  reaching "closng"        25                    25
//  "closed": quit/killed    10
//            klutzed        25
//            wrong way      30
//            success        45                    45
//  came to Witt's End        1                     1
//  Round out the total       2                     2
//                                       total:   350
//  (Points can also be deducted for using hints.)
//

return MAIN20000;
}
function MAIN20000 () {
SCORE=0;
MXSCOR=0;
//
//  First tally up the treasures.  Must be in building and not broken.
//  Give the poor guy 2 points just for finding each treasure.
//
I=(50);

return MAIN_28;
}
function MAIN_28 () {

if (PTEXT[I]==0) return MAIN20010;
K=12;
if (I==CHEST) K=14;
if (I>CHEST) K=16;
if (PROP[I]>=0) SCORE=SCORE+2;
if (PLACE[I]==3&PROP[I]==0) SCORE=SCORE+K-2;
MXSCOR=MXSCOR+K;

return MAIN20010;
}
function MAIN20010 () {
if (++I<=MAXTRS)return MAIN_28;

//
//  Now look at how he finished and how far he got.  MAXDIE and NUMDIE tell us
//  how well he survived.  GAVEUP says whether he exited via QUIT.  DFLAG will
//  tell us if he ever got suitably deep into the cave.  CLOSNG still indicates
//  whether he reached the endgame.  And if he got as far as "cave closed"
//  (indicated by "CLOSED"), then bonus is zero for mundane exits or 133, 134,
//  135 if he blew it (so to speak).
//
SCORE=SCORE+(MAXDIE-NUMDIE)*10;
MXSCOR=MXSCOR+MAXDIE*10;
if (!(SCORNG|GAVEUP)) SCORE=SCORE+4;
MXSCOR=MXSCOR+4;
if (DFLAG!=0) SCORE=SCORE+25;
MXSCOR=MXSCOR+25;
if (CLOSNG) SCORE=SCORE+25;
MXSCOR=MXSCOR+25;
if (!CLOSED) return MAIN20020;
if (BONUS==0) SCORE=SCORE+10;
if (BONUS==135) SCORE=SCORE+25;
if (BONUS==134) SCORE=SCORE+30;
if (BONUS==133) SCORE=SCORE+45;

return MAIN20020;
}
function MAIN20020 () {
MXSCOR=MXSCOR+45;
//
//  Did he come to Witt's End as he should?
//
if (PLACE[MAGZIN]==108) SCORE++;
MXSCOR++;
//
//  Round it off.
//
SCORE=SCORE+2;
MXSCOR=MXSCOR+2;
//
//  Deduct points for hints.  HINTS < 4 are special; see database description.
//
I=(1);

return MAIN_29;
}
function MAIN_29 () {


return MAIN20030;
}
function MAIN20030 () {
if (HINTED[I]) SCORE=SCORE-HINTS(I,2);if (++I<=HNTMAX)return MAIN_29;

//
//  Return to SCORE command if that's where we came from.
//
if (SCORNG) return MAIN8241;
//
//  That should be good enough.  Let's tell him all about it.
//
 MAIN20100 (SCORE,MXSCOR,TURNS);

//
I=(1);

return MAIN_30;
}
function MAIN_30 () {

if (CVAL[I]>=SCORE) return MAIN20210;

return MAIN20200;
}
function MAIN20200 () {
if (++I<=CLSSES)return MAIN_30;

 MAIN20202 ();

return MAIN25000;
//

}
function MAIN20210 () {
SPEAK(CTEXT[I]);
if (I==CLSSES-1) return MAIN20220;
K=CVAL[I]+1-SCORE;
 MAIN20212 (K);

if (K==1)  MAIN20213 ();
if (K!=1)  MAIN20214 ();


return MAIN25000;
//

}
function MAIN20220 () {
 MAIN20222 ();

//

return MAIN25000;
}
function MAIN25000 () {
return null
//
}

function RDWRST () {
RDWRST_VarInit ();
F2=-1;
I1=VMAJ;
I2=VMIN;
I3=VEDIT;
I1=RDWR(I1,"I1");
I2=RDWR(I2,"I2");
I3=RDWR(I3,"I3");

if (VMAJ!=I1|VMIN!=I2) return null
F2=0;

ATLOC=RDWR(ATLOC,"ATLOC");
LINK=RDWR(LINK,"LINK");
PLACE=RDWR(PLACE,"PLACE");
FIXED=RDWR(FIXED,"FIXED");
HOLDNG=RDWR(HOLDNG,"HOLDNG");

ABB=RDWR(ABB,"ABB");

OLDLOC=RDWR(OLDLOC,"OLDLOC");
LOC=RDWR(LOC,"LOC");
NEWLOC=RDWR(NEWLOC,"NEWLOC");


PROP=RDWR(PROP,"PROP");
TALLY=RDWR(TALLY,"TALLY");
TALLY2=RDWR(TALLY2,"TALLY2");
HINTLC=RDWR(HINTLC,"HINTLC");

DSEEN=RDWR(DSEEN,"DSEEN");
DFLAG=RDWR(DFLAG,"DFLAG");
DLOC=RDWR(DLOC,"DLOC");

TURNS=RDWR(TURNS,"TURNS");
LMWARN=RDWR(LMWARN,"LMWARN");
KNFLOC=RDWR(KNFLOC,"KNFLOC");
DETAIL=RDWR(DETAIL,"DETAIL");
ABBNUM=RDWR(ABBNUM,"ABBNUM");

NUMDIE=RDWR(NUMDIE,"NUMDIE");
DKILL=RDWR(DKILL,"DKILL");
FOOBAR=RDWR(FOOBAR,"FOOBAR");
BONUS=RDWR(BONUS,"BONUS");

CLOCK1=RDWR(CLOCK1,"CLOCK1");
CLOCK2=RDWR(CLOCK2,"CLOCK2");
CLOSNG=RDWR(CLOSNG,"CLOSNG");
PANIC=RDWR(PANIC,"PANIC");
CLOSED=RDWR(CLOSED,"CLOSED");

GAVEUP=RDWR(GAVEUP,"GAVEUP");
SCORNG=RDWR(SCORNG,"SCORNG");
ODLOC=RDWR(ODLOC,"ODLOC");

HINTED=RDWR(HINTED,"HINTED");

return null
}

// FORMAT Statements

function MAIN67() {
	var Pcnt = 0;
	do {
	Ty(' There are '+Rj(arguments[Pcnt++],1)+' threatening little dwarves in the'
	+' room with you.');
	} while (Pcnt < arguments.length);
}

function MAIN78() {
	var Pcnt = 0;
	do {
	Ty(' '+Rj(arguments[Pcnt++],1)+' of them throw knives at you!');
	} while (Pcnt < arguments.length);
}

function MAIN68() {
	var Pcnt = 0;
	do {
	Ty(' '+Rj(arguments[Pcnt++],1)+' of them get you!');
	} while (Pcnt < arguments.length);
}

function MAIN5015() {
	var Pcnt = 0;
	do {
	Ty(' What do you want to do with the '+Lj(arguments[Pcnt++],0)+'?');
	} while (Pcnt < arguments.length);
}

function MAIN5199() {
	var Pcnt = 0;
	do {
	Ty(' I don\'t see any '+Lj(arguments[Pcnt++],0)+'.');
	} while (Pcnt < arguments.length);
}

function MAIN8002() {
	var Pcnt = 0;
	do {
	Ty(' I don\'t understand "'+Lj(arguments[Pcnt++],0)+'".');
	} while (Pcnt < arguments.length);
}

function MAIN9032() {
	var Pcnt = 0;
	do {
	Ty(' Okay, "'+Lj(arguments[Pcnt++],0)+'".');
	} while (Pcnt < arguments.length);
}

function MAIN8243() {
	var Pcnt = 0;
	do {
	Ty(' If you were to quit now, you would score'+Rj(arguments[Pcnt++],4)
	+' out of a possible'+Rj(arguments[Pcnt++],4)+'.');
	} while (Pcnt < arguments.length);
}

function MAIN40012() {
	var Pcnt = 0;
	do {
	Ty(' I am prepared to give you a hint, but it will cost you'+Rj(arguments[Pcnt++],2)
	+' points.');
	} while (Pcnt < arguments.length);
}

function MAIN20100() {
	var Pcnt = 0;
	do {
	Ty();
	Ty(' You scored'+Rj(arguments[Pcnt++],4)+' out of a possible'
	+Rj(arguments[Pcnt++],4)+', using'+Rj(arguments[Pcnt++],5)+' turns.');
	} while (Pcnt < arguments.length);
}

function MAIN20202() {
	Ty(' You just went off my scale!!');
}

function MAIN20212() {
	var Pcnt = 0;
	do {
	Ty(' To achieve the next higher rating, you need'+Rj(arguments[Pcnt++],3)
	+' more point');
	} while (Pcnt < arguments.length);
}

function MAIN20213() {
	Ty('+.');
}

function MAIN20214() {
	Ty('+s.');
}

function MAIN20222() {
	Ty(' To achieve the next higher rating '+'would be a neat trick!'
	);
	Ty(' Congratulations!!');
}
// Var Declariations
var	YES, TOTING, HERE, AT, BITSET, DARK, WZDARK, YEA;
var	WORD1, WORD2;

// MAIN vars 
var LMWARN,CLOSNG,PANIC,CLOSED,GAVEUP,SCORNG,WZDARK,YEA,WORD1,WORD2,OBJ,PBOTL,DUMMY,
	L,N,JAL,I,LIMIT,J,DTOTAL,ATTACK,STICK,KK,K,OLDLC2,KENT,SPK,VERB,HINT,KQ,LL,K2,
	SCORE,MXSCOR;

function MAIN_VarInit () {
LMWARN = false,CLOSNG = false,PANIC = false,CLOSED = false,GAVEUP = false,SCORNG = false,
	WZDARK = false,YEA = false,WORD1 = "",WORD2 = "",OBJ = 0,PBOTL = 0,DUMMY = 0,
	L = 0,N = 0,JAL = 0,I = 0,LIMIT = 0,J = 0,DTOTAL = 0,ATTACK = 0,STICK = 0,KK = 0,
	K = 0,OLDLC2 = 0,KENT = 0,SPK = 0,VERB = 0,HINT = 0,KQ = 0,LL = 0,K2 = 0,SCORE = 0,
	MXSCOR = 0;
}

// RDWRST vars 
var F2,I1,I2,I3;

function RDWRST_VarInit () {
F2 = 0,I1 = 0,I2 = 0,I3 = 0;
}
// User Functions

function TOTING (OBJ) {
	return PLACE[OBJ]==-1;}

function HERE (OBJ) {
	return PLACE[OBJ]==LOC|TOTING(OBJ);}

function AT (OBJ) {
	return PLACE[OBJ]==LOC|FIXED[OBJ]==LOC;}

function LIQ2 (PBOTL) {
	return (1-PBOTL)*WATER+(Truncate(PBOTL/2))*(WATER+OIL);}

function LIQ (DUMMY) {
	return LIQ2(MAX0(PROP[BOTTLE],-1-PROP[BOTTLE]));}

function LIQLOC (LOC) {
	return LIQ2((MOD(Truncate(COND[LOC]/2)*2,8)-5)*MOD(Truncate(COND[LOC]/4),2)+1);}

function BITSET (L,N) {
	return (COND[L]&ISHFT(1,N))!=0;}

function FORCED (LOC) {
	return COND[LOC]==2;}

function DARK (DUMMY) {
	return MOD(COND[LOC],2)==0&(PROP[LAMP]==0|!HERE(LAMP));}

function PCT (N) {
	return RND(100)<N;}
// Variable names Assigned to
// FIXED     PLACE     ATLOC     LINK      HOLDNG    LMWARN    CLOSNG    PANIC     HINTED    
// CLOSED    GAVEUP    SCORNG    DSEEN     ABB       OLDLOC    LOC       TK        NEWLOC    
// PROP      TALLY     TALLY2    HINTLC    DFLAG     DLOC      TURNS     KNFLOC    DETAIL    
// ABBNUM    NUMDIE    DKILL     FOOBAR    BONUS     CLOCK1    CLOCK2    ODLOC     TOTING    
// HERE      AT        BITSET    DARK      WZDARK    YEA       WORD1     WORD2     OBJ       
// LIQ2      LIQ       LIQLOC    FORCED    PCT       JAL       I         LIMIT     J         
// DTOTAL    ATTACK    STICK     KK        K         OLDLC2    KENT      SPK       VERB      
// KQ        LL        K2        SCORE     MXSCOR    F2        I1        I2        I3        
// </script>
