/* REXX */ /* Mines Copyright (c) 1979, 2005, 2006, 2007 James L. Dean Version 1.1 released February 24, 2007 This Rexx application may be distributed or used without payment to its author. Derivative works must credit its author. "mines.rexx" lets you explore mines. The mine you explore is determined by a mine number specified at the beginning of a game. The object of a game is to visit all of the rooms and return all of the treasures to the entrance without making too many moves. In a mine, the passages are straight. So, for example, if you go North to leave a room, you can go South to reenter it. The rooms are not evenly spaced. However, the distance between adjacent rooms is always a multiple of the minimum distance between adjacent rooms. */ m_bQuitting=0 m_cDirection.0='N' m_cDirection.1='S' m_cDirection.2='E' m_cDirection.3='W' m_cDirection.4='U' m_cDirection.5='D' m_nDirectionOpposite.0=1 m_nDirectionOpposite.1=0 m_nDirectionOpposite.2=3 m_nDirectionOpposite.3=2 m_nDirectionOpposite.4=5 m_nDirectionOpposite.5=4 m_strDirection.0='north' m_strDirection.1='south' m_strDirection.2='east' m_strDirection.3='west' m_strDirection.4='up' m_strDirection.5='down' m_nTreasures=15 /* sames as number of guardians and weapons */ m_strGuardian.0='gorgon' m_strGuardian.1='grizzly bear' m_strGuardian.2='vampire' m_strGuardian.3='crocodile' m_strGuardian.4='giant crayfish' m_strGuardian.5='troll' m_strGuardian.6='werewolf' m_strGuardian.7='harpy' m_strGuardian.8='cobra' m_strGuardian.9='ferocious snail' m_strGuardian.10='vicious Doberman pinscher' m_strGuardian.11='colossal cockroach' m_strGuardian.12='giant' m_strGuardian.13='Trekkie' m_strGuardian.14='titanic ant' m_nRooms=99 m_strRoom.0='a spherical room.' m_strRoom.1='the hall of bones. Dinosaur bones are everywhere.' m_strRoom.2='a subway tunnel. Don''t touch that third rail!' m_strRoom.3='a railroad tunnel. A whistle wails in the distance.' m_strRoom.4='an elfin quiche factory. The elves are out mowing ', ||'spinach.' m_strRoom.5='an abandoned Plymouth plant. Beware of Road Runners ', ||'and Barracudas.' m_strRoom.6='an abandoned Dodge plant. There is a Dart embedded in ', ||'the North wall.' m_strRoom.7='a mouse''s nest. You''d best exhale; this is a small ', ||'room.' m_strRoom.8='a giant crayfish hole. An immense chicken neck is ', ||'hanging from a rope.' m_strRoom.9='an abandoned coal mine. Beware of methane.' m_strRoom.10='the hall of winds. Presently, the wind is from ', ||'the south.' m_strRoom.11='a stove pipe!' m_strRoom.12='a totally darkened room. Although you can see ', ||'nothing, the sound of dripping water echoes from the walls.' m_strRoom.13='an industrial waste site. Hold your breath and ', ||'don''t touch anything.' m_strRoom.14='the warehouse for an extremely popular brand of ', ||'home computer. Tacky plastic enclosures abound.' m_strRoom.15='a hobbit''s bedroom. The hobbit does not look pleased!' m_strRoom.16='a troll sewerage processing plant. The air quality ', ||'is not good.' m_strRoom.17='a rabbit hole. There is a jar of marmalade on a ', ||'shelf in the wall.' m_strRoom.18='the giant''s oven. Fortunately, it hasn''t been ', ||'used for years.' m_strRoom.19='a hobbit''s drying room. Tobacco leaves abound.' m_strRoom.20='a large circular room. It is dark in here.' m_strRoom.21='the Crystal Palace. Quartz crystals cover the walls.' m_strRoom.22='the Emerald Room. Green crystals cover the ceiling.' m_strRoom.23='a curtained room.' m_strRoom.24='an air conditioning duct!' m_strRoom.25='a giant kiln. Smoke stains the walls.' m_strRoom.26='the Hall of Mists. Wisps of white vapor rise from ', ||'the floor.' m_strRoom.27='an Aztec pyramid. A mummy lies in the northwest ', ||'corner.' m_strRoom.28='the Room of the Eternal Flame. A large natural gas ', ||'flame burns in the center of the room. Coming from the west ', ||'wall you can barely hear the words, ''Fee Fye Foe Fum''.' m_strRoom.29='the Giant''s store room. You are surrounded by old ', ||'rugs, books, chairs, etc.' m_strRoom.30='the Leprechaun''s Treasure Room. Unfortunately, ', ||'the leprechaun''s treasure was stolen years ago.' m_strRoom.31='a large tiled room. A girl is inquiring after a ', ||'rabbit. Feel free to ignore her.' m_strRoom.32='a former nuclear test site. There is a large pile ', ||'of rubble in the center of the floor. The walls are ', ||'streaked with a multitude of colors.' m_strRoom.33='a drainage system holding tank. Either it is no ', ||'longer used, or it hasn''t rained in a long time; the room ', ||'is dry.' m_strRoom.34='Mayor Schiro''s bomb shelter.' m_strRoom.35='a room with a waterfall. It is not very ', ||'impressive; it looks like someone left a water faucet running.' m_strRoom.36='an abandoned Neanderthal home.' m_strRoom.37='a volcanic chimney. The air is getting warmer.' m_strRoom.38='a pit full of snakes. Let''s get out of here!!!!' m_strRoom.39='a salt dome.' m_strRoom.40='Eleanor Roosevelt''s privy. Wendell Wilkie buttons ', ||'cover the wall.' m_strRoom.41='Napoleon''s wine cellar. German wines line the shelves.' m_strRoom.42='the space behind the giant''s bathroom wall. ', ||'Large razor blades litter the floor. Step lightly.' m_strRoom.43='the room where all old toe nail clipping come to ', ||'rest. Used corn pads litter the floor.' m_strRoom.44='the Den of the Horta. The walls are covered with ', ||'a sticky fluid. Don''t touch it; it is extremely corrosive.' m_strRoom.45='a damp room. A small creek runs into a crack in ', ||'the West wall.' m_strRoom.46='what appears to be a NOPSI manhole.' m_strRoom.47='the cafeteria of Mammoth Cave. The aroma of ', ||'rancid corned beef assails your nostrils.' m_strRoom.48='a small room with a large table. On the table is ', ||'a bottle that says, ''Drink me.''' m_strRoom.49='a Confederate States of America bank vault. Once ', ||'worthless currency papers the walls.' m_strRoom.50='an abandoned subway station.' m_strRoom.51='a mine shaft. In the distance you can hear seven ', ||'high pitched voices singing, ''Hi Ho, Hi Ho, ...''' m_strRoom.52='a Minuteman missile silo.' m_strRoom.53='the giant''s mouse trap. Fortunately, you are ', ||'small enough to escape.' m_strRoom.54='Adolph Hitler''s summer bunker.' m_strRoom.55='a dwarf work site. A sign says, "Under ', ||'construction. Enter at your own risk."' m_strRoom.56='the giant''s refrigerator. Dwarf bodies hang from ', ||'hooks.' m_strRoom.57='the Dragon''s Lair. Slightly melted suits of armor ', ||'litter the floor.' m_strRoom.58='a nuclear waste depository. The walls glow faintly.' m_strRoom.59='Millard Fillmore''s tomb. It is dull.' m_strRoom.60='an abandoned corridor of the Strategic Air Command ', ||'Headquarters. A graffito reads, "Beware of Bat Guano."' m_strRoom.61='a gnome''s workshop. Half-completed whoopee ', ||'cushions line the tables.' m_strRoom.62='the Mummy''s Tomb. You''ve triggered some ', ||'mechanism and the ceiling is slowly descending.' m_strRoom.63='the Underground Gourmet''s retreat. Twinkie and ', ||'King Don wrappers are piled knee deep.' m_strRoom.64='a Hoola Hoop warehouse. The words "Shoop Shoop" ', ||'echo from the walls.' m_strRoom.65='the first circle of hell. The living are not ', ||'allowed here.' m_strRoom.66='the hall of the pixies. The furniture appears to ', ||'have been made from cradles.' m_strRoom.67='a sulfur mine. Molten sulfur churns in a nearby ', ||'pit. It is becoming difficult to breath.' m_strRoom.68='a fairy mushroom farm. Brilliantly colored ', ||'mushrooms cover the floor.' m_strRoom.69='an ice cave. Along the western wall, a ', ||'brontosaurus is defrosting.' m_strRoom.70='the giant''s stove. Fortunately, the giant now ', ||'owns a microwave oven.' m_strRoom.71='the rib cage of a long deceased whale.' m_strRoom.72='a room with six walls. The walls appear to be ', ||'made of wax. A loud buzzing noise can be heard.' m_strRoom.73='the tomb of a Pharaoh. It has obviously been ', ||'visited by others; the tomb is in a state of total disarray.' m_strRoom.74='a coal bin. There is a fossilized fern stump here.' m_strRoom.75='a diamond mine. It is uncomfortably hot here.' m_strRoom.76='the bottom of an oil well. The walls are slick.' m_strRoom.77='the lowest level of Project Mohole. The funding ', ||'bubble burst before the earth did.' m_strRoom.78='the giant''s cesspool. Fortunately, the giant was ', ||'connected to the city sewerage system years ago.' m_strRoom.79='an eighteenth century sewer. The walls are ', ||'crumbling brick. Small alligators snap at your feet.' m_strRoom.80='the lair of a giant trapdoor spider.' m_strRoom.81='a giant gopher tunnel.' m_strRoom.82='a shell -- the sole remains of a prehistoric turtle.' m_strRoom.83='a small chamber. The walls are made of earth. The ', ||'air smells of formic acid. A strange squeaking noise can ', ||'be heard in the distance.' m_strRoom.84='a chamber of columns. The stalagmites and ', ||'stalactites join here.' m_strRoom.85='a service tunnel. Ducts, pipes, and cables are ', ||'everywhere.' m_strRoom.86='a gas tank below an abandoned service station. ', ||'No smoking!' m_strRoom.87='a huge dark chamber. To one side, a dark, muddy ', ||'river moves sluggishly. A sign written in ancient Greek ', ||'says, "Ferry out of order."' m_strRoom.88='a small chamber. It is brightly lit by a ', ||'peculiar lichen growing on the walls and ceiling. The floor ', ||'is rocky and steeply sloping. Nearby, a cold, clear creek ', ||'boils into the floor and out of sight.' m_strRoom.89='the nest of a very large pack rat. There are ', ||'discarded aluminum Christmas trees, broken steel utility ', ||'poles, and other shiny, worthless items here.' m_strRoom.90='a dungeon. An iron maiden, a rack, a piano, and ', ||'other machines of torture can be seen.' m_strRoom.91='the hall of bats. Thousands of bats hang from the ', ||'ceiling. Watch your step; the droppings are quite deep in places.' m_strRoom.92='a hobgoblin''s hideaway.' m_strRoom.93='an electrical substation. A transformer is ', ||'humming loudly. Nearby, cables crackle with high voltage.' m_strRoom.94='the "gold" room. The walls are covered with iron ', ||'pyrite.' m_strRoom.95='a room with one of Dracula''s emergency coffins. ', ||'The Count is out.' m_strRoom.96='a saltpeter mine. To one side there is a huge ', ||'wooden evaporation vat. Small crystals of saltpeter cause the ', ||'walls to sparkle.' m_strRoom.97='the basement cafeteria of a local hospital. Some ', ||'say that there has been nothing edible here for years.' m_strRoom.98='a troll arsenal. Kegs of gun powder surround you.' m_strTreasure.0='bag full of gold coins' m_strTreasure.1='large blue-white diamond' m_strTreasure.2='sixty carat emerald' m_strTreasure.3='platinum crucifix' m_strTreasure.4='string of pearls' m_strTreasure.5='Ming vase' m_strTreasure.6='list of the next ten winners of the Kentucky Derby' m_strTreasure.7='pile of rubies' m_strTreasure.8='previously undiscovered Rembrandt painting' m_strTreasure.9='ounce of antimatter in magnetic containment' m_strTreasure.10='stack of silver bars' m_strTreasure.11='set of ivory tusks' m_strTreasure.12='Holland and Holland double rifle chambered for ', ||'.600 Nitro Express' m_strTreasure.13='ancient Greek statue' m_strTreasure.14='five kilograms of plutonium in a lead container' m_strWeapon.0='mirror' m_strWeapon.1='pepper spray dispenser' m_strWeapon.2='wooden stake' m_strWeapon.3='roll of duct tape' m_strWeapon.4='jar of Zatarain''s Crab Boil' m_strWeapon.5='elfin sword' m_strWeapon.6='silver bullet' m_strWeapon.7='crossbow' m_strWeapon.8='flute fashioned from a dried-out pumpkin' m_strWeapon.9='bag of salt' m_strWeapon.10='soporific-laced dog biscuit' m_strWeapon.11='block of boric acid' m_strWeapon.12='slingshot' m_strWeapon.13='recording of Leonard Nimoy singing "Proud Mary"' m_strWeapon.14='Fresnel lens' m_nRNPartialSum=0 m_nReplaceIndex=0 m_nAddIndex=0 m_nRN.0=0 m_nRN.1=0 m_nRN.2=0 m_nRN.3=0 m_nRN.4=0 m_nRN.5=0 m_nRN.6=0 m_nRN.7=0 m_nRoomsAllocated=0 m_nPassagesAllocated=0 SAY 'Mine number?' PULL strMineNum QUEUE strMineNum CALL SetUpGame m_nMoves=0 m_room=m_roomEntrance CALL DescribeLocation QUEUE ' Press H for Help.' CALL DisplayText strCommand=' ' DO UNTIL (strCommand = 'Q') QUEUE ' Command?' CALL DisplayText PULL strLine IF LENGTH(strLine) > 0 THEN DO strCommand=SUBSTR(strLine,1,1) IF strCommand = 'Q' THEN DO QUEUE 1 CALL ReportScore END ELSE DO QUEUE strCommand CALL ProcessCommand CALL DescribeLocation END END END RETURN RandomNumber: PROCEDURE EXPOSE m_nRN.0 m_nRN.1 m_nRN.2 m_nRN.3 m_nRN.4 m_nRN.5, m_nRN.6 m_nRN.7 m_nRNPartialSum m_nReplaceIndex m_nAddIndex /* Each pseudo-random number is the modulo sum of the previous eight pseudo-random numbers. A prime modulus makes it likely that the pseudo-random numbers will be uniformly distributed. To speed computation, a partial sum of 7 of the 8 previous pseudo-random numbers is maintained. For a given set of initial values m_nRN[i], i=0,1,2,...,7, this random number generator should produce the same sequence of random numbers, no matter what 32-bit compiler it is compiled under. */ DO UNTIL (nResult <= 32767) nResult=m_nRNPartialSum+m_nRN.m_nAddIndex IF nResult >= 32771 THEN nResult=nResult-32771 m_nRNPartialSum=nResult-m_nRN.m_nReplaceIndex IF m_nRNPartialSum < 0 THEN m_nRNPartialSum=m_nRNPartialSum+32771 m_nRN.m_nReplaceIndex=nResult m_nAddIndex=m_nReplaceIndex m_nReplaceIndex=m_nReplaceIndex+1 IF m_nReplaceIndex >= 8 THEN m_nReplaceIndex=0 END RETURN nResult SeedRandomNumberGenerator: PROCEDURE EXPOSE m_nRN.0 m_nRN.1 m_nRN.2 m_nRN.3 m_nRN.4 m_nRN.5, m_nRN.6 m_nRN.7 m_nRNPartialSum m_nReplaceIndex m_nAddIndex PARSE PULL strMine nKeyLength=LENGTH(strMine) nKeyIndex=0 nKeyStart=nKeyLength DO WHILE (nKeyStart < 8) m_nRN.nKeyIndex=49 /* 1+(int) '0' */ nKeyIndex=nKeyIndex+1 nKeyStart=nKeyStart+1 END nKeyStart=1 DO WHILE ((nKeyStart <= 8) & (nKeyStart <= nKeyLength)) c=SUBSTR(strMine,nKeyStart,1) SELECT WHEN c = '0' THEN m_nRN.nKeyIndex=49 WHEN c = '1' THEN m_nRN.nKeyIndex=50 WHEN c = '2' THEN m_nRN.nKeyIndex=51 WHEN c = '3' THEN m_nRN.nKeyIndex=52 WHEN c = '4' THEN m_nRN.nKeyIndex=53 WHEN c = '5' THEN m_nRN.nKeyIndex=54 WHEN c = '6' THEN m_nRN.nKeyIndex=55 WHEN c = '7' THEN m_nRN.nKeyIndex=56 WHEN c = '8' THEN m_nRN.nKeyIndex=57 WHEN c = '9' THEN m_nRN.nKeyIndex=58 OTHERWISE m_nRN.nKeyIndex=49 END nKeyIndex=nKeyIndex+1 nKeyStart=nKeyStart+1 END m_nRNPartialSum=0 nKeyIndex=7 DO WHILE(nKeyIndex > 0) m_nRNPartialSum=m_nRNPartialSum+m_nRN.nKeyIndex IF m_nRNPartialSum >= 32771 THEN m_nRNPartialSum=m_nRNPartialSum-32771 nKeyIndex=nKeyIndex-1 END m_nReplaceIndex=1 m_nAddIndex=0 nKeyIndex=256 DO WHILE (nKeyIndex > 0) nKeyIndex=nKeyIndex-1 tem_int=RandomNumber() END RETURN ShuffleRoomDescriptions: nRoom1=m_nRooms-1 DO WHILE (nRoom1 > 0) nRoom2=RandomNumber()//nRoom1 str=m_strRoom.nRoom1 m_strRoom.nRoom1=m_strRoom.nRoom2 m_strRoom.nRoom2=str nRoom1=nRoom1-1 END RETURN ExcavateMine: nMax=0 DO WHILE (nMax*nMax*nMax < m_nRooms) nMax=nMax+1 END IF nMax*nMax*nMax = m_nRooms THEN nMax=nMax+10 ELSE nMax=nMax+9 DO UNTIL ((nLen*nWidth*nHeight >= 2*(m_nRooms-1)), & (nLen*nWidth*nHeight <= 3*(m_nRooms-1))) nLen=RandomNumber()//(nMax-3)+3 nWidth=RandomNumber()//(nMax-3)+3 nHeight=RandomNumber()//(nMax-3)+3 END nXFirstRoom=0 nYFirstRoom=RandomNumber()//nLen nZFirstRoom=RandomNumber()//nHeight roomWestBase=-1 roomWestBaseBase=-1 nX=0 DO WHILE (nX < nWidth) roomSouthBase=-1 nY=0 DO WHILE (nY < nLen) roomWest=roomWestBase roomSouth=roomSouthBase roomDown=-1 nZ=0 DO WHILE (nZ < nHeight) roomIndex=m_nRoomsAllocated m_nRoomsAllocated=m_nRoomsAllocated+1 room.roomIndex.strDescription=-1 room.roomIndex.nChokepoint=-1 room.roomIndex.bMined=0 room.roomIndex.bVisited=0 room.roomIndex.passageIndex.0=-1 room.roomIndex.passageIndex.1=-1 room.roomIndex.passageIndex.2=-1 room.roomIndex.passageIndex.3=-1 room.roomIndex.passageIndex.4=-1 room.roomIndex.passageIndex.5=-1 /* (X,Y,Z) gets linked to (X-1,Y,Z); (X,Y-1,Z); and (X,Y,Z-1) roomWest roomSouth roomDown */ IF nZ = 0 THEN DO roomSouthBase=roomIndex IF nY = 0 THEN roomWestBaseBase=roomIndex END IF roomDown \= -1 THEN DO /* link room to one below it */ passagePtr=m_nPassagesAllocated m_nPassagesAllocated=m_nPassagesAllocated+1 passage.passagePtr.bBlocked=1 passage.passagePtr.treasureGuardian=-1 passage.passagePtr.room1=roomIndex passage.passagePtr.room2=roomDown room.roomIndex.passageIndex.5=passagePtr room.roomDown.passageIndex.4=passagePtr END IF roomSouth \= -1 THEN DO /* link to room to the south */ passagePtr=m_nPassagesAllocated m_nPassagesAllocated=m_nPassagesAllocated+1 passage.passagePtr.bBlocked=1 passage.passagePtr.treasureGuardian=-1 passage.passagePtr.room1=roomIndex passage.passagePtr.room2=roomSouth room.roomIndex.passageIndex.1=passagePtr room.roomSouth.passageIndex.0=passagePtr IF room.roomSouth.passageIndex.4 \= -1 THEN DO passagePtr=room.roomSouth.passageIndex.4 IF passage.passagePtr.room1 = roomSouth THEN roomSouth=passage.passagePtr.room2 ELSE roomSouth=passage.passagePtr.room1 END ELSE roomSouth=-1 END IF roomWest \= -1 THEN DO /* link to the room to the west */ passagePtr=m_nPassagesAllocated m_nPassagesAllocated=m_nPassagesAllocated+1 passage.passagePtr.bBlocked=1 passage.passagePtr.treasureGuardian=-1 passage.passagePtr.room1=roomIndex passage.passagePtr.room2=roomWest room.roomIndex.passageIndex.3=passagePtr room.roomWest.passageIndex.2=passagePtr IF room.roomWest.passageIndex.4 \= -1 THEN DO passagePtr=room.roomWest.passageIndex.4 IF passage.passagePtr.room1 = roomWest THEN roomWest=passage.passagePtr.room2 ELSE roomWest=passage.passagePtr.room1 END ELSE roomWest=-1 END /* If this is the first room, connect it to the entrance. */ IF ((nX = nXFirstRoom), & (nY = nYFirstRoom), & (nZ = nZFirstRoom)) THEN DO passagePtr=m_nPassagesAllocated m_nPassagesAllocated=m_nPassagesAllocated+1 passage.passagePtr.bBlocked=0 passage.passagePtr.treasureGuardian=-1 passage.passagePtr.room1=roomIndex passage.passagePtr.room2=m_roomEntrance room.roomIndex.passageIndex.3=passagePtr room.m_roomEntrance.passageIndex.2=passagePtr END roomDown=roomIndex nZ=nZ+1 END IF roomWestBase \= -1 THEN DO IF room.roomWestBase.passageIndex.0 \= -1 THEN DO passagePtr=room.roomWestBase.passageIndex.0 IF passage.passagePtr.room1 = roomWestBase THEN roomWestBase=passage.passagePtr.room2 ELSE roomWestBase=passage.passagePtr.room1 END END nY=nY+1 END roomWestBase=roomWestBaseBase nX=nX+1 END nChokepointAssigned=-1 nTreasure=0 roomIndex=m_roomEntrance nRoom=0 DO WHILE (nRoom < m_nRooms) nDirection1=RandomNumber()//6 nDirectionOpposite=m_nDirectionOpposite.nDirection1 nDistance=RandomNumber()//3+1 nStep=0 DO WHILE ((room.roomIndex.passageIndex.nDirection1 \= -1), & (nStep < nDistance)) passagePtr=room.roomIndex.passageIndex.nDirection1 IF passage.passagePtr.room1 = roomIndex THEN roomNext=passage.passagePtr.room2 ELSE roomNext=passage.passagePtr.room1 IF passage.passagePtr.bBlocked THEN IF ((room.roomNext.nChokepoint = nChokepointAssigned), | (\ (room.roomNext.bMined))) THEN DO roomIndex=roomNext room.roomIndex.bMined=1 room.roomIndex.nChokepoint=nChokepointAssigned passage.passagePtr.bBlocked=0 IF room.roomIndex.strDescription \= -1 THEN nStep=nStep+1 ELSE DO nUnblocked=0 nDirection2=6 DO WHILE ((nUnblocked < 2) & (nDirection2 > 0)) nDirection2=nDirection2-1 IF nDirection2 \= nDirectionOpposite THEN DO passagePtr=, room.roomIndex.passageIndex.nDirection2 IF passagePtr \= -1 THEN IF (\ passage.passagePtr.bBlocked) THEN nUnblocked=nUnblocked+1 END END IF nUnblocked < 2 THEN nStep=nStep+1 ELSE nStep=nDistance END END ELSE nStep=nDistance ELSE DO nStep=nStep+1 roomIndex=roomNext nChokepointAssigned=room.roomIndex.nChokepoint END END IF nStep \= 0 THEN DO IF room.roomIndex.strDescription = -1 THEN DO room.roomIndex.strDescription=m_strRoom.nRoom nDirection1=0 nUnblocked=0 nDirection2=6 DO WHILE ((nUnblocked < 2) & (nDirection2 > 0)) nDirection2=nDirection2-1 passagePtr=room.roomIndex.passageIndex.nDirection2 IF passagePtr \= -1 THEN IF (\ passage.passagePtr.bBlocked) THEN DO nDirection1=nDirection2 nUnblocked=nUnblocked+1 END END IF nUnblocked = 1 THEN DO IF ((m_nRooms-nRoom)*RandomNumber(), < 32768*(m_nTreasures-nTreasure)) THEN DO nChokepointAssigned=nTreasure passagePtr=room.roomIndex.passageIndex.nDirection1 passage.passagePtr.treasureGuardian=nTreasure nTreasure=nTreasure+1 END END room.roomIndex.nChokepoint=nChokepointAssigned m_roomWithName.nRoom=roomIndex nRoom=nRoom+1 END END END m_roomWithName.nRoom=m_roomEntrance m_nChokepoints=nTreasure RETURN HideTreasuresAndWeapons: nTreasure=0 DO WHILE (nTreasure < m_nTreasures) bChokepointFound=0 nRoom=0 DO WHILE ((\ bChokepointFound) & (nRoom < m_nRooms)) nRoomWithName=m_roomWithName.nRoom IF room.nRoomWithName.nChokepoint = nTreasure THEN bChokepointFound=1 ELSE nRoom=nRoom+1 END IF bChokepointFound THEN DO bFound=0 DO UNTIL (bFound) nRoom=RandomNumber()//m_nRooms nRoomWithName=m_roomWithName.nRoom IF room.nRoomWithName.nChokepoint = nTreasure THEN bFound=1 END m_treasure.nTreasure.roomTreasure=nRoomWithName bFound=0 DO UNTIL (bFound) nRoom=RandomNumber()//(m_nRooms+1) nRoomWithName=m_roomWithName.nRoom IF room.nRoomWithName.nChokepoint < nTreasure THEN bFound=1 END m_treasure.nTreasure.roomWeapon=nRoomWithName END ELSE DO nRoom=RandomNumber()%m_nRooms m_treasure.nTreasure.roomTreasure=m_roomWithName.nRoom m_treasure.nTreasure.roomWeapon=m_roomWithName.m_nRooms END nTreasure=nTreasure+1 END RETURN ListPassages: nPassages=0 nDirection=6 DO WHILE (nDirection > 0) nDirection=nDirection-1 passagePtr=room.m_room.passageIndex.nDirection IF passagePtr \= -1 THEN IF (\ passage.passagePtr.bBlocked) THEN nPassages=nPassages+1 END IF nPassages > 1 THEN m_sbLocation=m_sbLocation||' There are passages' else m_sbLocation=m_sbLocation||' There is a passage' nPassage=0 nDirection=0 DO WHILE (nDirection < 6) passagePtr=room.m_room.passageIndex.nDirection IF passagePtr \= -1 THEN IF (\ passage.passagePtr.bBlocked) THEN DO nPassage=nPassage+1 IF nPassage > 1 THEN IF nPassages \= 2 THEN m_sbLocation=m_sbLocation||',' m_sbLocation=m_sbLocation||' ' IF nPassage = nPassages THEN IF nPassages > 1 THEN m_sbLocation=m_sbLocation||'and ' m_sbLocation=m_sbLocation||m_strDirection.nDirection END nDirection=nDirection+1 END m_sbLocation=m_sbLocation||'.' nDirection=0 DO WHILE (nDirection < 6) strDescriptionCurrent=-1 roomAlongPassage=m_room passagePtr=room.roomAlongPassage.passageIndex.nDirection bPassageBlocked=0 IF passagePtr \= -1 THEN bPassageBlocked=passage.passagePtr.bBlocked DO WHILE ((passagePtr \= -1), & (\ bPassageBlocked), & (strDescriptionCurrent = -1)) treasure=passage.passagePtr.treasureGuardian IF treasure \= -1 THEN DO m_sbLocation=m_sbLocation||' The passage ' m_sbLocation=m_sbLocation||m_strDirection.nDirection m_sbLocation=m_sbLocation||' is guarded by a' cFirstChar=SUBSTR(m_treasure.treasure.strGuardian,1,1) IF ((cFirstChar = 'A'), | (cFirstChar = 'a'), | (cFirstChar = 'E'), | (cFirstChar = 'e'), | (cFirstChar = 'I'), | (cFirstChar = 'i'), | (cFirstChar = 'O'), | (cFirstChar = 'o'), | (cFirstChar = 'U'), | (cFirstChar = 'u')) THEN m_sbLocation=m_sbLocation||'n' m_sbLocation=m_sbLocation||' ' m_sbLocation=m_sbLocation||m_treasure.treasure.strGuardian m_sbLocation=m_sbLocation||'.' END IF passage.passagePtr.room1 = roomAlongPassage THEN roomAlongPassage=passage.passagePtr.room2 else roomAlongPassage=passage.passagePtr.room1 strDescriptionCurrent=room.roomAlongPassage.strDescription passagePtr=room.roomAlongPassage.passageIndex.nDirection IF passagePtr \= -1 THEN bPassageBlocked=passage.passagePtr.bBlocked END nDirection=nDirection+1 END RETURN ListTreasures: nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomTreasure = m_room THEN DO m_sbLocation=m_sbLocation||' There is a' cFirstChar=SUBSTR(m_treasure.nTreasure.strTreasure,1,1) IF ((cFirstChar = 'A'), | (cFirstChar = 'a'), | (cFirstChar = 'E'), | (cFirstChar = 'e'), | (cFirstChar = 'I'), | (cFirstChar = 'i'), | (cFirstChar = 'O'), | (cFirstChar = 'o'), | (cFirstChar = 'U'), | (cFirstChar = 'u')) THEN m_sbLocation=m_sbLocation||'n' m_sbLocation=m_sbLocation||' ' m_sbLocation=m_sbLocation||m_treasure.nTreasure.strTreasure m_sbLocation=m_sbLocation||' here.' END END RETURN ListWeapons: nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomWeapon = m_room THEN DO m_sbLocation=m_sbLocation||' There is a' cFirstChar=SUBSTR(m_treasure.nTreasure.strWeapon,1,1) IF ((cFirstChar = 'A'), | (cFirstChar = 'a'), | (cFirstChar = 'E'), | (cFirstChar = 'e'), | (cFirstChar = 'I'), | (cFirstChar = 'i'), | (cFirstChar = 'O'), | (cFirstChar = 'o'), | (cFirstChar = 'U'), | (cFirstChar = 'u')) THEN m_sbLocation=m_sbLocation||'n' m_sbLocation=m_sbLocation||' ' m_sbLocation=m_sbLocation||m_treasure.nTreasure.strWeapon m_sbLocation=m_sbLocation||' here.' END END RETURN DisplayText: PARSE PULL strText nMaxLineLen=79 nColumn=1 nPendingSpaces=0 nTokenStart=0 nTokenStart=1 strLine='' nTextLen=LENGTH(strText) bBlank=1 DO WHILE (bBlank & (nTokenStart <= nTextLen)) IF SUBSTR(strText,nTokenStart,1) = ' ' THEN DO strLine=strLine||' ' nColumn=nColumn+1 IF nColumn > nMaxLineLen THEN DO SAY strLine strLine='' nColumn=1 END nTokenStart=nTokenStart+1 END ELSE bBlank=0 END DO WHILE (nTokenStart <= nTextLen) bBlank=1 DO WHILE (bBlank & (nTokenStart <= nTextLen)) IF SUBSTR(strText,nTokenStart,1) = ' ' THEN nTokenStart=nTokenStart+1 ELSE bBlank=0 END IF (nColumn+nPendingSpaces) > nMaxLineLen THEN DO SAY strLine strLine='' nPendingSpaces=0 nColumn=1 END ELSE DO WHILE (nPendingSpaces > 0) strLine=strLine||' ' nColumn=nColumn+1 nPendingSpaces=nPendingSpaces-1 END IF nTokenStart <= nTextLen THEN DO nTokenStop=nTokenStart bBlank=0 DO WHILE ((\ bBlank) & (nTokenStop <= nTextLen)) IF SUBSTR(strText,nTokenStop,1) = ' ' THEN bBlank=1 ELSE nTokenStop=nTokenStop+1 END nTokenLen=nTokenStop-nTokenStart IF (nColumn+nTokenLen) > nMaxLineLen THEN IF nTokenLen > nMaxLineLen THEN DO DO WHILE (nColumn < nMaxLineLen) strLine=strLine||SUBSTR(strText,nTokenStart,1) nColumn=nColumn+1 nTokenStart=nTokenStart+1 END SAY strLine strLine='' nColumn=1 DO WHILE (nTokenStart < nTokenStop) strLine=strLine||SUBSTR(strText,nTokenStart,1) nColumn=nColumn+1 IF nColumn > nMaxLineLen THEN DO SAY strLine strLine='' nColumn=1 END nTokenStart=nTokenStart+1 END END ELSE DO SAY strLine strLine='' nColumn=1 DO WHILE (nTokenStart < nTokenStop) strLine=strLine||SUBSTR(strText,nTokenStart,1) nColumn=nColumn+1 nTokenStart=nTokenStart+1 END END ELSE DO WHILE (nTokenStart < nTokenStop) strLine=strLine||SUBSTR(strText,nTokenStart,1) nColumn=nColumn+1 nTokenStart=nTokenStart+1 END c=SUBSTR(strText,nTokenStop-1,1) SELECT WHEN c = '.' THEN nPendingSpaces=2 WHEN c = '?' THEN nPendingSpaces=2 WHEN c = '!' THEN nPendingSpaces=2 OTHERWISE nPendingSpaces=1 END END END IF nColumn > 1 THEN SAY strLine RETURN DescribeLocation: m_sbLocation=' You''re in ' m_sbLocation=m_sbLocation||room.m_room.strDescription CALL ListPassages CALL ListTreasures CALL ListWeapons QUEUE m_sbLocation CALL DisplayText RETURN ListCommands: QUEUE ' Commands in the game are "N", "E", "S", "W", "U", and ', ||'"D" to move North, East, South, West, Up, or Down, ', ||'respectively. Other commands are "C" to carry things, "I" to ', ||'inventory what you are carrying, ', ||'"L" to leave treasures, "P" to ', ||'get the points you"ve scored, "O" for help getting out of the ', ||'mine, "H" for help, and "Q" to quit.' CALL DisplayText RETURN DisplayHelp: QUEUE ' The object of the game is to ', ||'visit all of the rooms and return all the treasures to the ', ||'entrance without making too many moves.' CALL DisplayText CALL ListCommands QUEUE ' In a mine, the passages are straight. ', ||'So, for example, if ', ||'you go North to leave a room, ', ||'you can go South to reenter it. ', ||'The rooms are not evenly spaced. ', ||'However, the distance between ', ||'adjacent rooms is always a multiple of the minimum distance ', ||'between adjacent rooms.' CALL DisplayText RETURN ProcessCarry: bSomethingToCarry=0 nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomWeapon = m_room THEN DO bSomethingToCarry=1 m_treasure.nTreasure.roomWeapon=-1 END IF m_treasure.nTreasure.roomTreasure = m_room THEN DO bSomethingToCarry=1 m_treasure.nTreasure.roomTreasure=-1 END END IF (\ bSomethingToCarry) THEN DO QUEUE ' There is nothing to carry.' CALL DisplayText END RETURN ListInventory: bFirstLine=1 nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomTreasure = -1 THEN DO IF bFirstLine THEN DO bFirstLine=0 QUEUE ' You are carrying the following:' CALL DisplayText END QUEUE ' '||m_treasure.nTreasure.strTreasure CALL DisplayText END END nTreasure=m_nChokepoints DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomWeapon = -1 THEN IF (\ m_treasure.nTreasure.bSlain) THEN DO IF bFirstLine THEN DO bFirstLine=0 QUEUE ' You are carrying the following:' CALL DisplayText END QUEUE ' '||m_treasure.nTreasure.strWeapon CALL DisplayText END END IF bFirstLine THEN DO QUEUE ' You aren''t carrying anything.' CALL DisplayText END RETURN Move: PARSE PULL nDirection sb='' passagePtr=room.m_room.passageIndex.nDirection IF passagePtr \= -1 THEN DO IF (\ passage.passagePtr.bBlocked) THEN DO bGuarded=0 strDescriptionCurrent=-1 roomAlongPassage=m_room DO WHILE ((passagePtr \= -1) & (strDescriptionCurrent = -1)) treasure=passage.passagePtr.treasureGuardian IF treasure \= -1 THEN DO IF m_treasure.treasure.roomWeapon \= -1 THEN DO bGuarded=1 sb=sb||' You carry nothing to overcome the ' sb=sb||m_treasure.treasure.strGuardian||'.' END ELSE DO sb=sb||' Your '||m_treasure.treasure.strWeapon sb=sb||' overcomes the ' sb=sb||m_treasure.treasure.strGuardian||'.' m_treasure.treasure.bSlain=1 passage.passagePtr.treasureGuardian=-1 END END IF passage.passagePtr.room1 = roomAlongPassage THEN roomAlongPassage=passage.passagePtr.room2 ELSE roomAlongPassage=passage.passagePtr.room1 passagePtr=room.roomAlongPassage.passageIndex.nDirection strDescriptionCurrent=room.roomAlongPassage.strDescription END IF (\ bGuarded) THEN DO m_nMoves=m_nMoves+1 room.roomAlongPassage.bVisited=1 m_room=roomAlongPassage END END ELSE sb=sb||' You can''t go that way.' END ELSE sb=sb||' You can''t go that way.' IF LENGTH(sb) > 0 THEN DO QUEUE sb CALL DisplayText END RETURN DropItems: nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomTreasure = -1 THEN m_treasure.nTreasure.roomTreasure=m_room END RETURN ReportScore: PARSE PULL bRank sb=' You have moved ' integerRooms=m_nRooms+1 nScore=0 nTreasuresRecovered=0 nTreasuresCarried=0 nRoomsVisited=0 nRoom=0 DO WHILE (nRoom <= m_nRooms) nNamedRoom=m_roomWithName.nRoom IF room.nNamedRoom.bVisited THEN nRoomsVisited=nRoomsVisited+1 nRoom=nRoom+1 END sb=sb||m_nMoves||' times to visit '||nRoomsVisited||' of ' sb=sb||integerRooms||' locations.' QUEUE sb CALL DisplayText nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomTreasure = -1 THEN nTreasuresCarried=nTreasuresCarried+1 END sb=' You hold '||nTreasuresCarried||' of ' sb=sb||m_nTreasures||' treasures.' QUEUE sb CALL DisplayText nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomTreasure = m_roomEntrance THEN nTreasuresRecovered=nTreasuresRecovered+1 END sb=' You have returned '||nTreasuresRecovered sb=sb||' of '||m_nTreasures sb=sb||' treasures to the entrance of the mine.' QUEUE sb CALL DisplayText nScore=25*nRoomsVisited/(m_nRooms+1), +75*nTreasuresRecovered/m_nTreasures, +45*nTreasuresCarried/m_nTreasures IF m_nMoves > 5*m_nRooms THEN DO nScore=nScore-m_nMoves/(5*m_nRooms) IF nScore < 0 THEN nScore=0 END integerScore=TRUNC(nScore) sb=' You have scored '||integerScore||' of 100 points.' QUEUE sb CALL DisplayText IF bRank THEN DO IF nScore < 25 THEN sb=' Your score ranks you as a beginner.' ELSE IF nScore < 50 THEN sb=' Your score ranks you as a novice adventurer.' ELSE IF nScore < 75 THEN sb=' Your score ranks you as a seasoned explorer.' ELSE IF nScore < 100 THEN sb=' Your score ranks you as a grissly old prospector.' ELSE sb=' Your score ranks you as an expert treasure ', ||'hunter; there is no higher rating.' QUEUE sb CALL DisplayText END RETURN FindPathToEntrance: nPathParms=0 nPathLocals=0 nPaths=0 pathLocalsStk=-1 pathLocalsStkHead=-1 pathParmsStk=-1 pathParmsStkHead=-1 pathParmsStk=nPathParms nPathParms=nPathParms+1 PathParms.pathParmsStk.pathParmsStkNext, =pathParmsStkHead PathParms.pathParmsStk.roomIndex=m_room PathParms.pathParmsStk.nDirUsedToEnter=0 PathParms.pathParmsStk.nReturnAddress=0 pathParmsStkHead=pathParmsStk pathStkHead=-1 bResume=0 nIterations=0 DO UNTIL ((nReturnAddress = 0) | (nIterations >= 1000)) nIterations=nIterations+1 bReenter=0 IF bResume THEN DO DO WHILE ((\ bReenter) & (m_sbWayOut = -1), & (PathLocals.pathLocalsStkHead.nDirection1 > 0)) PathLocals.pathLocalsStkHead.nDirection1, =PathLocals.pathLocalsStkHead.nDirection1-1 i=PathLocals.pathLocalsStkHead.nDirection1 PathLocals.pathLocalsStkHead.nDirection2, =PathLocals.pathLocalsStkHead.nDirectionRandom.i i=PathLocals.pathLocalsStkHead.nDirection2 roomPtr=PathParms.pathParmsStkHead.roomIndex passagePtr=room.roomPtr.passageIndex.i IF passagePtr \= -1 THEN DO IF (\ passage.passagePtr.bBlocked) THEN DO IF passage.passagePtr.room1 = roomPtr THEN DO pathParmsStk=nPathParms nPathParms=nPathParms+1 PathParms.pathParmsStk.pathParmsStkNext, =pathParmsStkHead PathParms.pathParmsStk.roomIndex, =passage.passagePtr.room2 PathParms.pathParmsStk.nDirUsedToEnter, =PathLocals.pathLocalsStkHead.nDirection2 PathParms.pathParmsStk.nReturnAddress=1 pathParmsStkHead=pathParmsStk bReenter=1 END ELSE DO pathParmsStk=nPathParms nPathParms=nPathParms+1 PathParms.pathParmsStk.pathParmsStkNext, =pathParmsStkHead PathParms.pathParmsStk.roomIndex, =passage.passagePtr.room1 PathParms.pathParmsStk.nDirUsedToEnter, =PathLocals.pathLocalsStkHead.nDirection2 PathParms.pathParmsStk.nReturnAddress=1 pathParmsStkHead=pathParmsStk bReenter=1 END END END END IF (\ bReenter) THEN DO pathPtr=PathLocals.pathLocalsStkHead.pathStk pathStkHead=Path.pathPtr.pathStkNext PathLocals.pathLocalsStkHead.pathStk=-1 pathLocalsStk=pathLocalsStkHead pathLocalsStkHead, =PathLocals.pathLocalsStk.pathLocalsStkNext pathLocalsStk=-1 END END ELSE bReenter=1 IF bReenter THEN DO UNTIL (\ bReenter) bReenter=0 pathLocalsStk=nPathLocals nPathLocals=nPathLocals+1 PathLocals.pathLocalsStk.bRoomAlreadyInStk=0 PathLocals.pathLocalsStk.nDirection1=0 PathLocals.pathLocalsStk.nDirection2=0 nDirection=0 DO WHILE (nDirection < 6) PathLocals.pathLocalsStk.nDirectionRandom.nDirection=0 nDirection=nDirection+1 END PathLocals.pathLocalsStk.nDirection3=0 PathLocals.pathLocalsStk.nPathLen=0 PathLocals.pathLocalsStk.pathStk=-1 PathLocals.pathLocalsStk.pathLocalsStkNext, =pathLocalsStkHead pathLocalsStkHead=pathLocalsStk IF PathParms.pathParmsStkHead.roomIndex, = m_roomEntrance THEN DO PathLocals.pathLocalsStkHead.nPathLen=0 PathLocals.pathLocalsStkHead.pathStk=pathStkHead DO WHILE, (PathLocals.pathLocalsStkHead.pathStk \= -1) pathPtr=PathLocals.pathLocalsStkHead.pathStk roomPtr=Path.pathPtr.roomIndex IF room.roomPtr.strDescription \= -1 THEN PathLocals.pathLocalsStkHead.nPathLen, =PathLocals.pathLocalsStkHead.nPathLen+1 PathLocals.pathLocalsStkHead.pathStk, =Path.pathPtr.pathStkNext END j=PathParms.pathParmsStkHead.nDirUsedToEnter m_sbWayOut=m_cDirection.j PathLocals.pathLocalsStkHead.nPathLen, =PathLocals.pathLocalsStkHead.nPathLen-1 PathLocals.pathLocalsStkHead.pathStk=pathStkHead DO WHILE, (PathLocals.pathLocalsStkHead.pathStk \= -1) pathPtr=PathLocals.pathLocalsStkHead.pathStk IF Path.pathPtr.pathStkNext \= -1 THEN DO roomPtr=Path.pathPtr.roomIndex IF room.roomPtr.strDescription \= -1 THEN DO PathLocals.pathLocalsStkHead.nPathLen, =PathLocals.pathLocalsStkHead.nPathLen-1 j=Path.pathPtr.nDirUsedToEnter m_sbWayOut=m_cDirection.j||m_sbWayOut END END PathLocals.pathLocalsStkHead.pathStk, =Path.pathPtr.pathStkNext END END ELSE DO PathLocals.pathLocalsStkHead.bRoomAlreadyInStk=0 PathLocals.pathLocalsStkHead.pathStk=pathStkHead bAlreadyInStk=0 DO WHILE, ((PathLocals.pathLocalsStkHead.pathStk \= -1), & (\ bAlreadyInStk)) IF PathLocals.pathLocalsStkHead.bRoomAlreadyInStk, THEN bAlreadyInStk=1 ELSE DO pathPtr=PathLocals.pathLocalsStkHead.pathStk IF Path.pathPtr.roomIndex, = PathParms.pathParmsStkHead.roomIndex THEN PathLocals.pathLocalsStkHead.bRoomAlreadyInStk, =1 ELSE PathLocals.pathLocalsStkHead.bRoomAlreadyInStk, =0 PathLocals.pathLocalsStkHead.pathStk, =Path.pathPtr.pathStkNext END END IF (\, (PathLocals.pathLocalsStkHead.bRoomAlreadyInStk)), THEN DO PathLocals.pathLocalsStkHead.pathStk=nPaths Path.nPaths.roomIndex, =PathParms.pathParmsStkHead.roomIndex Path.nPaths.nDirUsedToEnter, =PathParms.pathParmsStkHead.nDirUsedToEnter Path.nPaths.pathStkNext=pathStkHead nPaths=nPaths+1 pathStkHead, =PathLocals.pathLocalsStkHead.pathStk PathLocals.pathLocalsStkHead.nDirection1=6 DO WHILE, (PathLocals.pathLocalsStkHead.nDirection1 > 0) PathLocals.pathLocalsStkHead.nDirection1, =PathLocals.pathLocalsStkHead.nDirection1-1 k=PathLocals.pathLocalsStkHead.nDirection1 PathLocals.pathLocalsStkHead.nDirectionRandom.k, =PathLocals.pathLocalsStkHead.nDirection1 END PathLocals.pathLocalsStkHead.nDirection1=5 DO WHILE, (PathLocals.pathLocalsStkHead.nDirection1 > 0) PathLocals.pathLocalsStkHead.nDirection2, =RandomNumber(), //(PathLocals.pathLocalsStkHead.nDirection1+1) i1=PathLocals.pathLocalsStkHead.nDirection1 i2=PathLocals.pathLocalsStkHead.nDirection2 PathLocals.pathLocalsStkHead.nDirection3, =PathLocals.pathLocalsStkHead.nDirectionRandom.i1 PathLocals.pathLocalsStkHead.nDirectionRandom.i1, =PathLocals.pathLocalsStkHead.nDirectionRandom.i2 PathLocals.pathLocalsStkHead.nDirectionRandom.i2, =PathLocals.pathLocalsStkHead.nDirection3 PathLocals.pathLocalsStkHead.nDirection1, =PathLocals.pathLocalsStkHead.nDirection1-1 END PathLocals.pathLocalsStkHead.nDirection1=6 DO WHILE ((\ bReenter), & (m_sbWayOut = -1), & (PathLocals.pathLocalsStkHead.nDirection1 > 0)) PathLocals.pathLocalsStkHead.nDirection1, =PathLocals.pathLocalsStkHead.nDirection1-1 i=PathLocals.pathLocalsStkHead.nDirection1 PathLocals.pathLocalsStkHead.nDirection2, =PathLocals.pathLocalsStkHead.nDirectionRandom.i i=PathLocals.pathLocalsStkHead.nDirection2 roomPtr, =PathParms.pathParmsStkHead.roomIndex passagePtr=room.roomPtr.passageIndex.i IF passagePtr \= -1 THEN DO IF (\ passage.passagePtr.bBlocked) THEN DO IF (passage.passagePtr.room1 = roomPtr) THEN DO pathParmsStk=nPathParms nPathParms=nPathParms+1 PathParms.pathParmsStk.pathParmsStkNext, =pathParmsStkHead PathParms.pathParmsStk.roomIndex, =passage.passagePtr.room2 PathParms.pathParmsStk.nDirUsedToEnter=, PathLocals.pathLocalsStkHead.nDirection2 PathParms.pathParmsStk.nReturnAddress, =1 pathParmsStkHead=pathParmsStk bReenter=1 END ELSE DO pathParmsStk=nPathParms nPathParms=nPathParms+1 PathParms.pathParmsStk.pathParmsStkNext, =pathParmsStkHead PathParms.pathParmsStk.roomIndex, =passage.passagePtr.room1 PathParms.pathParmsStk.nDirUsedToEnter=, PathLocals.pathLocalsStkHead.nDirection2 PathParms.pathParmsStk.nReturnAddress=1 pathParmsStkHead=pathParmsStk bReenter=1 END END END END IF (\ bReenter) THEN DO pathPtr, =PathLocals.pathLocalsStkHead.pathStk pathStkHead=Path.pathPtr.pathStkNext PathLocals.pathLocalsStkHead.pathStk=-1 END END END IF (\ bReenter) THEN DO pathLocalsStk=pathLocalsStkHead pathLocalsStkHead, =PathLocals.pathLocalsStk.pathLocalsStkNext pathLocalsStk=-1 END END nReturnAddress, =PathParms.pathParmsStkHead.nReturnAddress pathParmsStk=pathParmsStkHead pathParmsStkHead, =PathParms.pathParmsStk.pathParmsStkNext pathParmsStk=-1 bResume=1 END RETURN ReportWayOut: sb='' IF m_room = m_roomEntrance THEN sb=sb||' You"re already at the entrance.' ELSE DO bCarryingTreasure=0 nTreasure=m_nTreasures DO WHILE ((\ bCarryingTreasure) & (nTreasure > 0)) nTreasure=nTreasure-1 IF m_treasure.nTreasure.roomTreasure = -1 THEN bCarryingTreasure=1 END IF bCarryingTreasure THEN DO m_sbWayOut=-1 CALL FindPathToEntrance IF m_sbWayOut = -1 THEN sb=sb||' Nothing happens.' ELSE DO DO UNTIL (m_roomWithName.nRoom \= m_room) nRoom=RandomNumber()//m_nRooms END m_treasure.nTreasure.roomTreasure=m_roomWithName.nRoom sb=sb||' The pirate takes one of your treasures. ' IF LENGTH(m_sbWayOut) = 1 THEN sb=sb||'As he leaves, he shouts the letter "' ELSE sb=sb||'As he leaves, he shouts the letters "' sb=sb||m_sbWayOut||'".' m_sbWayOut=-1 END END ELSE sb=sb||' Nothing happens.' END QUEUE sb CALL DisplayText RETURN ProcessCommand: PARSE PULL strCommand SELECT WHEN strCommand = 'H' THEN CALL DisplayHelp WHEN strCommand = 'h' THEN CALL DisplayHelp WHEN strCommand = 'O' THEN CALL ReportWayOut WHEN strCommand = 'o' THEN CALL ReportWayOut WHEN strCommand = 'L' THEN CALL DropItems WHEN strCommand = 'l' THEN CALL DropItem WHEN strCommand = 'C' THEN CALL ProcessCarry WHEN strCommand = 'c' THEN CALL ProcessCarry WHEN strCommand = 'D' THEN DO QUEUE 5 CALL Move END WHEN strCommand = 'd' THEN DO QUEUE 5 CALL Move END WHEN strCommand = 'S' THEN DO QUEUE 1 CALL Move END WHEN strCommand = 's' THEN DO QUEUE 1 CALL Move END WHEN strCommand = 'E' THEN DO QUEUE 2 CALL Move END WHEN strCommand = 'e' THEN DO QUEUE 2 CALL Move END WHEN strCommand = 'W' THEN DO QUEUE 3 CALL Move END WHEN strCommand = 'w' THEN DO QUEUE 3 CALL Move END WHEN strCommand = 'N' THEN DO QUEUE 0 CALL Move END WHEN strCommand = 'n' THEN DO QUEUE 0 CALL Move END WHEN strCommand = 'U' THEN DO QUEUE 4 CALL Move END WHEN strCommand = 'u' THEN DO QUEUE 4 CALL Move END WHEN strCommand = 'I' THEN CALL ListInventory WHEN strCommand = 'i' THEN CALL ListInventory WHEN strCommand = 'P' THEN DO QUEUE 0 CALL ReportScore END WHEN strCommand = 'p' THEN DO QUEUE 0 CALL ReportScore END OTHERWISE DO QUEUE ' I don''t recognize that command.' CALL DisplayText CALL ListCommands END END RETURN SetUpGame: PARSE PULL strMineNum m_roomEntrance=m_nRoomsAllocated m_nRoomsAllocated=m_nRoomsAllocated+1 room.m_roomEntrance.strDescription='the entrance to the mine.' room.m_roomEntrance.bMined=1 room.m_roomEntrance.bVisited=1 room.m_roomEntrance.nChokepoint=-1 room.m_roomEntrance.passageIndex.0=-1 room.m_roomEntrance.passageIndex.1=-1 room.m_roomEntrance.passageIndex.2=-1 room.m_roomEntrance.passageIndex.3=-1 room.m_roomEntrance.passageIndex.4=-1 room.m_roomEntrance.passageIndex.5=-1 QUEUE strMineNum CALL SeedRandomNumberGenerator CALL ShuffleRoomDescriptions nTreasure=m_nTreasures DO WHILE (nTreasure > 0) nTreasure=nTreasure-1 m_treasure.nTreasure.strTreasure=m_strTreasure.nTreasure m_treasure.nTreasure.strGuardian=m_strGuardian.nTreasure m_treasure.nTreasure.strWeapon=m_strWeapon.nTreasure m_treasure.nTreasure.roomTreasure=-1 m_treasure.nTreasure.bSlain=0 m_treasure.nTreasure.roomWeapon=-1 END m_nChokepoints=0 CALL ExcavateMine CALL HideTreasuresAndWeapons RETURN