Newsgroups: rec.arts.int-fiction
Path: nntp.gmd.de!Dortmund.Germany.EU.net!Germany.EU.net!howland.reston.ans.net!spool.mu.edu!news.cs.indiana.edu!shulick@mango.ucs.indiana.edu
From: "Sam Hulick" <shulick@mango.ucs.indiana.edu>
Subject: Inform: Free code..in-game hints
Message-ID: <1995Oct4.015056.1538@news.cs.indiana.edu>
Organization: Vallen Software
Date: Wed, 4 Oct 1995 01:50:51 -0500
Lines: 230


As promised, here is my code (inspired by the creator of 'Theatre') for
in-game hints.  Enjoy!

---cut here---
! This game demonstrates expanding menus as hints.  The hints are
! accessible in an actual object rather than typing 'help'

Switches xv5;

Constant Story "HINTLAND";
Constant Headline "^A Hintbook Example^Freeware by Sam Hulick^";

! Must replace DoMenu..
REPLACE DoMenu;

Include "parser";
Include "verblib";

! our DoMenu replacement... sorry for the long mess. :)

[ DoMenu menu_choices EntryR ChoiceR
         lines main_title main_wid cl i j oldcl pkey;
  menu_nesting++;
  menu_item=0;
  lines=indirect(EntryR);
  main_title=item_name; main_wid=item_width;
  cl=7;
  .ReDisplay;
      oldcl=0;
      @erase_window $ffff;
      i=lines+7;
      @split_window i;
      i = 0->33;
      if (i==0) i=80;
      @set_window 1;
      @set_cursor 1 1;
      style reverse;
      spaces(i); j=i/2-main_wid;
      @set_cursor 1 j;
      print_paddr main_title;
      @set_cursor 2 1; spaces(i);
      @set_cursor 2 2; print "N = next subject";
      j=i-12; @set_cursor 2 j; print "P = previous";
      @set_cursor 3 1; spaces(i);
      @set_cursor 3 2; print "RETURN = read subject";
      j=i-17; @set_cursor 3 j;
      if (menu_nesting==1)
          print "  Q = resume game";
      else
          print "Q = previous menu";
      style roman;
      @set_cursor 5 2; font off;

!      print_paddr menu_choices;
 ! this is all I changed.. just added this switch section.
 ! also removed some pretty_flag thing above. no biggie..right?
      switch (ZRegion(menu_choices))
      {
         3: print_paddr menu_choices;
         2: indirect(menu_choices);
      }

      .KeyLoop;
      if (cl~=oldcl)
      {   if (oldcl>0) { @set_cursor oldcl 4; print " "; }
          @set_cursor cl 4; print ">";
      }
      oldcl=cl;
      @read_char 1 0 0 pkey;
      if (pkey=='N' or 'n' or 130)
          { cl++; if (cl==7+lines) cl=7; jump KeyLoop; }
      if (pkey=='P' or 'p' or 129)
          { cl--; if (cl==6)  cl=6+lines; jump KeyLoop; }
      if (pkey=='Q' or 'q' or 27) { jump QuitHelp; }
      if (pkey==10 or 13)
      {   @set_window 0; font on;
          new_line; new_line; new_line;

          menu_item=cl-6;
          indirect(EntryR);

          @erase_window $ffff;
          @split_window 1;
          i = 0->33; if (i==0) { i=80; }
          @set_window 1; @set_cursor 1 1; style reverse; spaces(i);
          j=i/2-item_width;
          @set_cursor 1 j;
          print_paddr item_name;
          style roman; @set_window 0; new_line;

          i = indirect(ChoiceR);
          if (i==2) jump ReDisplay;
          if (i==3) jump QuitHelp;

          print "^[Please press SPACE.]^";
          @read_char 1 0 0 pkey; jump ReDisplay;
      }
      jump KeyLoop;
      .QuitHelp;
      menu_nesting--; if (menu_nesting>0) rfalse;
      font on; @set_cursor 1 1;
      @erase_window $ffff; @set_window 0;
      new_line; new_line; new_line;
      if (deadflag==0) <<Look>>;
];

Global hintflags = $0;
Global hintcount = 0;
Array hint_array --> 30;

Constant HOWOPENSAFE   $1;
Constant WHYMANSCREAMS $2;
Constant HOWGETOUT     $4;

Object oneroom "One Room"
 with  description "You're in a room full of objects that need to be \
                    dealt with somehow.  Check out your magic clue \
                    book every once in awhile for new hints!",
       cant_go [;
          AddHint(HOWGETOUT);
          "You see no way out!  Hmm, but there must be a way...";
       ],
 has   light;

Nearby safe "seriously tough safe"
 with  name "tough" "safe",
       description "It's one heck of a safe.",
       before [;
        Open:
        if (self has locked)
        {
           AddHint(HOWOPENSAFE);
           "It's locked quite well.";
        }
       ],
 has   openable lockable locked static;

Nearby smallman "tiny man"
 with  name "tiny" "man",
       description "It's a small man, only a few inches high!",
       before [;
        Take: AddHint(WHYMANSCREAMS);
              "He screams and dodges your hand as you try to pick him \
                 up.";
       ],
 has   static;

Object cluebook "magic clue book"
 with  name "magic" "clue" "book" "clues",
       description [;
          if (hintflags == $0) "The clue book is blank.  Confused, you \
                                turn to the back, where it reads, \
                                ~Clues will fill in automatically as \
                                you encounter new problems.~";
          return HintRoutine();
       ],
       invent [;
          if (inventory_stage == 2)
          {
             if (hintcount == 0) { print " (devoid of any clues)";
                    rtrue; }
             else print " (hints for ", (number) hintcount, " question";
             if (hintcount ~= 1) print "s)"; else print ")";
             rtrue;
          }
       ],
       after [;
        Take: "You feel a bit less vulnerable as you pick up the clue \
               book.";
        Drop, PutOn, Insert: print "(Yes, that's it.  Just get rid of \
               it, then you will not be tempted to look up hints.)^";
       ];

[ Initialise;
   location = oneroom;
   move cluebook to player;
   "^^^^^You're glad this game is set in...^^";
];

[ HintRoutine;
   DoMenu(#r$HDetermine, #r$HintMenu, #r$HintInfo);
];

[ AddHint bit;
   if (hintflags & bit ~= 0) rfalse;
   hintflags = hintflags | bit;
   hint_array-->hintcount = bit;
   hintcount++;
];

[ HDetermine x;
   print "Pick an area you've having trouble with.^^";

   for (x = 0: x < hintcount: x++)
   {
      switch (hint_array-->x)
      {
         HOWOPENSAFE:   print "      How do I open the safe?^";
         WHYMANSCREAMS: print "      Why the heck does that man scream \
                               when I try to take him?^";
         HOWGETOUT:     print "      How do I get out of here?^";
      }
   }
];

[ HintMenu;
   item_name = "Hints";
   item_width = 2;
   if (menu_item == 0) return hintcount;
];

[ HintInfo mi;
   mi = hint_array-->(menu_item-1);

  ! And you could use the GiveHint() func here, if you wanted. Anything.
   if (mi == HOWOPENSAFE) "You don't, pal!";
   if (mi == WHYMANSCREAMS) "Wouldn't you scream, too?";
   if (mi == HOWGETOUT) "You type 'quit', of course.";
];

Include "grammar";
end;

---cut here---
-- 
--- Sam Hulick ------------- shulick@indiana.edu ---------------------
Systems Consultant        | Homepage:
Indiana College Placement |    http://copper.ucs.indiana.edu/~shulick/
  and Assessment Center   | PGP public key available on request
