Newsgroups: rec.arts.int-fiction
Subject: ALAN Floyd code right here
From: Mark 'Mark' Sachs <MBS110@psuvm.psu.edu>
Date: Thu, 12 Nov 1992 22:35:19 EST
Organization: The Leader Desslok School of Diplomacy

Good lord, it's somewhat longer than I had thought... oh well...

Anyway, here it is. Note the '(' marks scattered through the text are
from simulated quotation marks: on the Amiga, typing alt-k space
generates an umlaut by itself, which looks enough like double quotes
for government work.

Save it as floyd.alan, issue the command ALAN floyd, then ARUN floyd,
and there you are.

------------8< cut here 8<--------------------------------------------

-- ALAN etude featuring Floyd from Planetfall.
-- By Mark Sachs mbs110@psuvm.psu.edu

OBJECT ATTRIBUTES
   closed.
   NOT locked.
   NOT openable.
   NOT takable.
   NOT slidable.
   NOT a_card.
   NOT an_actor.
   weight 0.

SYNONYMS
   east = e.
   west = w.

   z = 'wait'.
   i = 'inventory'.

   get = take.
   run = slide.

   thru = through.

   floyd = robot.

SYNTAX
   'look' = 'look'.
   'quit' = 'quit'.
   'wait' = 'wait'.
   'score' = 'score'.
   take_inv = 'inventory'.

   take = take (obj) *.
   drop = drop (obj) *.

   turn_on = turn on (obj).
   turn_off = turn off (obj).
   play_with = play with (obj).
   talk_to = talk 'to' (obj).

   give = 'give' (obj) 'to' (recip).
   slide_thru = 'slide' (obj) 'through' (ind).

VERB 'look' DOES
   LOOK.
END VERB.

VERB 'quit' DOES
   IF Floyd HERE THEN
      "Floyd grins impishly. (Giving up, huh?("
   ELSE
      "Goodbye!"
   END IF.
   QUIT.
END VERB.

VERB 'wait' DOES
   "Time passes..."
END VERB.

VERB 'score' DOES
   SCORE.
END VERB.

VERB take_inv DOES
   LIST inventory.
END VERB.

VERB open
   CHECK OBJECT IS openable
      ELSE "That would be a neat trick, opening the $o..."
   AND OBJECT IS closed
      ELSE "The $o is already open."
   AND OBJECT IS NOT locked
      ELSE "It isn't opening."
   DOES
      MAKE OBJECT NOT closed.
      "The $o opens."
END VERB.

VERB close
   CHECK OBJECT IS openable
      ELSE "You can't even open the $o, much less close it."
   AND OBJECT IS NOT closed
      ELSE "It _is_ closed!"
   DOES
      MAKE OBJECT closed.
      "You close the $o."
END VERB.

VERB take
   CHECK OBJECT IS takable
      ELSE "You can't take that."
   AND OBJECT NOT IN inventory
      ELSE "You did already, remember?"
   DOES
      IF OBJECT IN Floyd THEN
         MAKE Floyd NOT carrying.
      END IF.
      LOCATE OBJECT IN inventory.
      "Taken."
END VERB.

VERB drop
   CHECK OBJECT IN inventory
      ELSE "But you're not carrying that!"
   DOES
      LOCATE OBJECT HERE.
      "Dropped."
END VERB.

VERB read DOES
   "That isn't something you can read."
END VERB.

VERB examine DOES
   "You see nothing special."
END VERB.

VERB give
   CHECK obj IN inventory
      ELSE "You don't have that."
   AND recip IS an_actor
      ELSE "You can't give a $o to a $2!"
END VERB.

VERB play_with DOES
   "You fiddle with the $o for a while. Gosh, that was fun."
END VERB.

VERB talk_to DOES
   "Talking to a $o is usually taken as a sign of impending mental
    collapse."
END VERB.

VERB turn_on DOES
   "You can't turn that on."
END VERB.

VERB turn_off DOES
   "You can't turn that off."
END VERB.

VERB slide_thru
   CHECK obj IN inventory
      ELSE "You don't have that."
   AND ind IS slidable
      ELSE "I don't think so."
   AND obj IS a_card
      ELSE "That makes no sense!"
END VERB.

-- THE WORLD and all its contents.

-- First, redefine the inventory for weight limits etc.
-- How this works is straightforward: if a LIMIT is violated, the object
-- simply does not budge. If you try to take something, it stays on the
-- ground; if something is LOCATEd into your inventory, it doesn't move.
-- This leads to problems, needless to say, when stuff is being LOCATEd
-- in from Limbo...

-- Three work-arounds: first, write your own limit system -- quite possible.
-- Second, avoid teleporting things directly into the inventory. Third,
-- put in additional code for the (usually) uncommon occasions when you
-- really want to port things in: teleport an object first to the room,
-- then to the inventory -- so if a check fails the object remains in the
-- room, at least. A few appropriate failure messages here give the impression
-- that the player tried to take the object, but failed. This last method is
-- what I use here.

-- The weight limits are disabled due to an annoying bug peculiar only
-- to ALAN 2.3; they should work right in 2.4.

CONTAINER inventory
   LIMITS
      COUNT 3 THEN
         "$nYou can't juggle any more objects; it slips from your hands."
--    weight 20 THEN
--       "$nYou can't carry that much weight. It tumbles to the ground."
   HEADER
      "You are carrying:"
   ELSE
      "You are empty-handed."
END CONTAINER.

-- Where stuff goes when we want to hide it from the player.

LOCATION limbo
END LOCATION.

LOCATION waiting_room NAME Waiting Room
   DESCRIPTION
      "You're standing in a nondescript, slightly dingy waiting room with white
       painted walls and a tile floor. A corridor leads south into the Robot
Shop."
      DESCRIBE scenic_door.
      DESCRIBE scenic_slot.
      "$n"

   EXIT e, out TO scenic_overlook
      CHECK
         scenic_door IS NOT closed
         ELSE "Thump! You bang your nose against the closed door as you attempt
               this feat."
      DOES
         "You step through the door and are stunned by the sight that unfolds."
      SCORE 5.
   END EXIT.

   EXIT s TO robot_shop.

END LOCATION.

OBJECT scenic_door NAME white door AT waiting_room
   IS closed.
   IS openable.
   IS locked.
   DESCRIPTION
      "An ordinary white door leads east."
      IF scenic_door IS closed THEN
         "It's closed."
      ELSE
         "It's wide open, admitting chill winds and brilliant sunlight."
      END IF.

   VERB open DOES
      "A gust of cold wind hits you in the face."
   END VERB.

   VERB examine DOES ONLY
      DESCRIBE scenic_door.
      DESCRIBE scenic_slot.
   END VERB.

END OBJECT.

OBJECT scenic_slot NAME narrow slot AT waiting_room
   IS slidable.
   DESCRIPTION
      "Next to the door, mounted into the wall, is a narrow slot."

   VERB examine DOES ONLY
      "The slot is about ten centimeters wide, but only about two
       centimeters deep. It is surrounded on its long sides by parallel
       ridges of metal."
   END VERB.

   VERB slide_thru DOES ONLY
      IF OBJECT = scenic_card THEN
         "There is a loud buzz and then a click from the locking mechanism.
          The door opens and cold air blows into the room."
         MAKE scenic_door NOT locked.
         MAKE scenic_door NOT closed.
      ELSE
         "A pleasant voice chimes from a hidden speaker: (Access denied.("
      END IF.
   END VERB.

END OBJECT.

OBJECT widget1 NAME light widget AT waiting_room
   IS takable.
   HAS weight 5.

   VERB examine DOES ONLY
      "This is basically just a widget. There are a couple of round flanges
       at one end and a sort of a hole for a screw at the other end. It's
       not very big or heavy."
   END VERB.

END OBJECT.

OBJECT widget2 NAME heavy widget AT waiting_room
   IS takable.
   HAS weight 20.

   VERB examine DOES ONLY
      "This widget is about the size of a toaster and very heavy, as
       if it were made out of lead."
   END VERB.

END OBJECT.

LOCATION scenic_overlook NAME Scenic Overlook
   DESCRIPTION
      "You're at a small balcony overlooking a magnificent
       view indeed! Apparently this area is located at the top of a gigantic
cliff
       in the middle of a range of high mountains extending to the horizon.
Looking
       down on the mountains you feel as if you're at the top of the world. A
chill
       wind is blowing and the sky is absolutely clear and a very deep blue. An
       ordinary-looking doorway leads back into the cliff.$n"
   EXIT w TO waiting_room.
END LOCATION.

---------
---------
-- That stuff just sets up a few rooms and objects to mess around in and
-- with. This next bit sets up Floyd the robot. In fact there are THREE
-- Floyd-objects: one for when he is awake, one when he is turned off,
-- and an actor that follows him everywhere and fakes his actions.

LOCATION robot_shop NAME Robot Shop
   DESCRIPTION
      "This room, with an exit north, is filled with robot-like devices
       of every conceivable description, all in various states of
       disassembly.$n"
   EXIT n TO waiting_room.
END LOCATION.

OBJECT scenic_card NAME Scenic Overlook Access Card AT limbo
   IS takable.
   IS a_card.
   HAS weight 1.
END OBJECT.

-- Floyd the robot.

-- His attributes:
--  woken -- Has he been activated for the first time yet?
--  working -- Is he on?
--  searched -- Have you searched him and taken the access card?
--  carrying -- Have you given him an object to carry? Careful
--              experimentation with the real _Planetfall_ showed that
--              Floyd never carries more than one object at once.
--              I didn't simply use LIMITS because Floyd accepts
--              additional objects but then drops them.

-- Quotation marks, incidentally, can be simulated with alt-k space.

OBJECT Floyd NAME multiple purpose robot AT limbo
   CONTAINER
      HEADER
         "The multiple purpose robot is holding:"
   IS takable.    --
   IS openable.   -- These two are just to get past the global CHECKs
   IS an_actor.
   IS NOT woken.
   IS NOT working.
   IS NOT searched.
   IS NOT carrying.
   DESCRIPTION
      "There is a multiple purpose robot here.$n"
      IF Floyd IS carrying THEN
         LIST Floyd.
      END IF.

   VERB examine DOES ONLY
       "From its design, the robot seems to be of the multi-purpose sort.
        It is slightly cross-eyed, and its mechanical mouth forms a
        lopsided grin."
   END VERB.

   VERB take DOES ONLY
       "You manage to lift Floyd a few inches off the ground, but he is
        too heavy and you drop him suddenly. Floyd gives a surprised
        squeal and moves a respectable distance away."
   END VERB.

-- look in also does the same thing with Floyd.

   VERB open DOES ONLY
       "Floyd giggles and pushes you away. (You're tickling Floyd!( He
        clutches at his side panels, laughing hysterically. Oil drops
        stream from his eyes."
   END VERB.

   VERB turn_on DOES ONLY
       "He's already been activated."
   END VERB.

-- The clumsy text in here is because ALAN insists on putting a space at the
-- end of half-continued paragraphs.

   VERB turn_off DOES ONLY
         MAKE Floyd NOT working.
         "Floyd, shocked by this betrayal from his new-found friend, whimpers
          and keels"
         IF Floyd IS carrying THEN
            "over, dropping what he was carrying."
            MAKE Floyd NOT carrying.
            EMPTY Floyd HERE.
         ELSE
            "over."
         END IF.
         LOCATE off_floyd HERE.
         LOCATE Floyd AT limbo.
         LOCATE real_floyd AT limbo.
         USE SCRIPT 3 FOR real_floyd.
   END VERB.

   VERB give DOES
      IF Floyd IS carrying THEN
         "Floyd examines the $o, shrugs, and drops it."
         LOCATE obj HERE.
      ELSE
         "(Neat!( exclaims Floyd. He thanks you profusely."
         LOCATE obj IN Floyd.
         MAKE Floyd carrying.
      END IF.
   END VERB.

   VERB play_with DOES ONLY
      "You play with Floyd for several centichrons until you drop to the
       floor, exhausted. Floyd pokes at you gleefully. (C'mon! Let's play
       some more!("
   END VERB.

   VERB talk_to DOES ONLY
         "(Hi!( Floyd grins and bounces up and down."
   END VERB.

END OBJECT.

-- off_floyd: This is Floyd when he is not switched on.

OBJECT off_floyd NAME multiple purpose robot AT robot_shop
   IS openable.   -- again, this is just to get past global checks
   DESCRIPTION
      IF Floyd IS NOT woken THEN
          "$nOnly one robot, about four feet high, looks even remotely close
           to being in working order.$n"
      ELSE
          "There is a multiple purpose robot here.$n"
      END IF.

   VERB examine DOES ONLY
      "The de-activated robot is leaning against the wall, its
       head lolling to the side. It is short, and seems to be equipped for
       general-purpose work. It has apparently been turned off."
   END VERB.

   VERB turn_on DOES ONLY
         IF Floyd IS woken THEN
            "Floyd jumps to his feet, hopping mad. (Why you turn Floyd off?(
             he asks accusingly."
            MAKE Floyd working.
            LOCATE Floyd HERE.
            LOCATE real_floyd HERE.
            LOCATE off_floyd AT limbo.
            USE SCRIPT 2 FOR real_floyd.
         ELSE
            "Nothing happens."
            USE SCRIPT 1 FOR real_floyd.
         END IF.
   END VERB.

   VERB turn_off DOES ONLY
      "The robot doesn't seem to be on."
   END VERB.

   VERB open DOES ONLY
      IF Floyd IS searched THEN
         "Your search discovers nothing in the robot's compartments except a
          single crayon which you leave where you found it."
      ELSE
         "In one of the robot's compartments you find and take a
          magnetic-striped card embossed (Seenik Overluuk Akses Kard.("
          MAKE Floyd searched.
          LOCATE scenic_card HERE.
          LOCATE scenic_card IN inventory.
      END IF.
   END VERB.

END OBJECT.

-- The actor Floyd, which carries out all actions you do not instigate.

-- real_floyd has these attributes:
--  random_action: a holder for random numbers for his next silly act.
--  been_alone: how long you and Floyd have been apart, which governs
--              whether the player sees "Floyd follows you" or the other
message.

-- And these scripts:
--  script 1: For when Floyd is first activated.
--  script 2: His normal wandering about.
--  script 3: Used to quietly abort whatever he's doing (ie, he's turned off.)

ACTOR real_floyd AT limbo
   HAS random_action 0.
   HAS been_alone 0.

   DESCRIPTION

   SCRIPT 1.
      STEP
         " " -- no-op
      STEP
         MAKE Floyd woken.
         MAKE Floyd working.
         LOCATE Floyd AT hero.
         LOCATE real_floyd AT hero.
         LOCATE off_floyd AT limbo.

         "$pSuddenly, the robot comes to life and its head starts swivelling
          about. It notices you and bounds over. (Hi! I'm B-19-7, but to
          everyperson I'm called Floyd. Are you a doctor-person or a
          planner-person? Isn't it nice that Mark Sachs wrote this example?
          Let's play Hider-and-Seeker you with me.("
      USE SCRIPT 2.

   SCRIPT 2.
      STEP
         IF hero NOT HERE THEN
            INCREMENT been_alone OF real_floyd BY 1.

   -- The documention states that INCREMENT attr by itself increases the
   -- attribute by 1, but that does not seem to be the case. Specify 1 anyway.

         ELSE
            SET been_alone OF real_floyd TO 0.
         END IF.

         IF RANDOM 1 TO 3 = 1 THEN
            SET random_action OF real_floyd TO RANDOM 1 TO 21.
            IF random_action OF real_floyd = 1 THEN
   "$pFloyd wanders restlessly around the room."
            END IF.
            IF random_action OF real_floyd = 2 THEN
   "$pFloyd paces impatiently."
            END IF.
            IF random_action OF real_floyd = 3 THEN
   "$pFloyd lowers his voice and tells you the latest rumors about Dr.
    Fizpick."
            END IF.
            IF random_action OF real_floyd = 4 THEN
   "$pFloyd absent-mindedly oils one of his joints."
            END IF.
            IF random_action OF real_floyd = 5 THEN
   "$pFloyd tells you about the time he helped someone sharpen a pencil."
            END IF.
            IF random_action OF real_floyd = 6 THEN
   "$pFloyd yawns and looks bored."
            END IF.
            IF random_action OF real_floyd = 7 THEN
   "$pFloyd reminisces about his friend Lazarus, a medical robot."
            END IF.
            IF random_action OF real_floyd = 8 THEN
   "$pFloyd examines himself for signs of rust."
            END IF.
            IF random_action OF real_floyd = 9 THEN
   "$pFloyd cranes his neck to see what you are doing."
            END IF.
            IF random_action OF real_floyd = 10 THEN
   "$pFloyd recalls the time he bruised his knee."
            END IF.
            IF random_action OF real_floyd = 11 THEN
   "$pFloyd whistles tunelessly."
            END IF.
            IF random_action OF real_floyd = 12 THEN
   "$pFloyd produces a crayon from one of his compartments and scrawls his
    name on the wall."
            END IF.
            IF random_action OF real_floyd = 13 THEN
   "$pFloyd says (Floyd going exploring. See you later.( He glides out of the
    room."
               LOCATE Floyd AT limbo.
               LOCATE real_floyd AT limbo.
               SET been_alone OF real_floyd TO 2.
            END IF.
            IF random_action OF real_floyd = 14 THEN
   "$pFloyd relates some fond memories about his old friend Lazarus."
            END IF.
            IF random_action OF real_floyd = 15 THEN
   "$pFloyd absent-mindedly recites the first six hundred digits of pi."
            END IF.
            IF random_action OF real_floyd = 16 THEN
   "$pFloyd asks if you want to play Hucka-Bucka-Beanstalk."
            END IF.
            IF random_action OF real_floyd = 17 THEN
   "$pFloyd chants the death scene from (Carmen(."
            END IF.
            IF random_action OF real_floyd = 18 THEN
   "$pFloyd rubs his head affectionately against your shoulder."
            END IF.
            IF random_action OF real_floyd = 19 THEN
   "$pFloyd frets about the possibility of his batteries failing."
            END IF.
            IF random_action OF real_floyd = 20 THEN
   "$pFloyd notices a mouse scurrying by and tries to hide behind you."
            END IF.
            IF random_action OF real_floyd = 21 THEN
   "$pFloyd sings an ancient ballad, totally out of key."
            END IF.
         ELSE
            IF hero NOT HERE THEN
               LOCATE Floyd AT hero.
               LOCATE real_floyd AT hero.
               IF been_alone OF real_floyd = 1 THEN
                  "$pFloyd follows you."
                  IF Floyd AT scenic_overlook THEN
                     "(Ooo. Nice view,( Floyd says appreciatively."
                  END IF.
               ELSE
                  IF RANDOM 1 TO 2 = 1 THEN
                     "$pFloyd bounds into the room. (Floyd here now!( he cries."
                  ELSE
                     "$pFloyd rushes into the room and barrels into you.
                      (Oops, sorry,( he says. (Floyd not looking at where
                      he was going to.("
                  END IF.
               END IF.
               SET been_alone OF real_floyd TO 0.
            END IF.
         END IF.
         USE SCRIPT 2.

   SCRIPT 3.
      STEP
         " "

END ACTOR.

-- START section...

START AT waiting_room.