home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tads2os2.zip / STD.T < prev    next >
Text File  |  1994-09-22  |  13KB  |  358 lines

  1. /* Copyright (c) 1989, 1991 by Michael J. Roberts.  All Rights Reserved. */
  2. /*
  3. Name
  4.   std.t   - standard default adventure definitions
  5.   Version 1.2
  6.   
  7.   This file is part of TADS:  The Text Adventure Development System.
  8.   Please see the file LICENSE.DOC (which should be part of the TADS
  9.   distribution) for information on using this file, and for information
  10.   on reaching High Energy Software, the developers of TADS.
  11.  
  12.   This file provides some simple definitions for objects and functions
  13.   that are required by TADS, but not defined in the file "adv.t".
  14.   The definitions in std.t are suitable for use while a game is
  15.   being written, but you will probably find that you will want to
  16.   customize the definitions in this file for your game when the
  17.   game is nearing completion.  This file is intended to help you
  18.   get started more quickly by providing basic definitions for these
  19.   functions and objects.
  20.  
  21.   When you decide to customize these functions and objects for
  22.   your game, be sure to remove the inclusion of std.t to avoid
  23.   duplicate definitions.
  24. */
  25.  
  26. /* parse with normal TADS operators */
  27. #pragma C-
  28.  
  29. /*
  30.  *   Pre-declare all functions, so the compiler knows they are functions.
  31.  *   (This is only really necessary when a function will be referenced
  32.  *   as a daemon or fuse before it is defined; however, it doesn't hurt
  33.  *   anything to pre-declare all of them.)
  34.  */
  35. die: function;
  36. scoreRank: function;
  37. init: function;
  38. terminate: function;
  39. pardon: function;
  40. sleepDaemon: function;
  41. eatDaemon: function;
  42. darkTravel: function;
  43.  
  44. /*
  45.  *   The die() function is called when the player dies.  It tells the
  46.  *   player how well he has done (with his score), and asks if he'd
  47.  *   like to start over (the alternative being quitting the game).
  48.  */
  49. die: function
  50. {
  51.     "\b*** You have died ***\b";
  52.     scoreRank();
  53.     "\bYou may restore a saved game, start over, quit, or undo
  54.     the current command.\n";
  55.     while ( 1 )
  56.     {
  57.         local resp;
  58.  
  59.     "\nPlease enter RESTORE, RESTART, QUIT, or UNDO: >";
  60.         resp := upper(input());
  61.         if ( resp = 'RESTORE' )
  62.     {
  63.         resp := askfile( 'File to restore' );
  64.         if ( resp = nil ) "Restore failed. ";
  65.         else if ( restore( resp )) "Restore failed. ";
  66.         else
  67.         {
  68.             Me.location.lookAround(true);
  69.             scoreStatus( global.score, global.turnsofar );
  70.         abort;
  71.         }
  72.     }
  73.         else if ( resp = 'RESTART' )
  74.     {
  75.         scoreStatus( 0, 0 );
  76.             restart();
  77.     }
  78.     else if ( resp = 'QUIT' )
  79.         {
  80.         terminate();
  81.             quit();
  82.         abort;
  83.         }
  84.     else if (resp = 'UNDO')
  85.     {
  86.         if (undo())
  87.         {
  88.         "(Undoing one command)\b";
  89.         Me.location.lookAround(true);
  90.             scoreStatus(global.score, global.turnsofar);
  91.         abort;
  92.         }
  93.         else
  94.         "Sorry, no undo information is available. ";
  95.     }
  96.     }
  97. }
  98.  
  99. /*
  100.  *   The scoreRank() function displays how well the player is doing.
  101.  *   This default definition doesn't do anything aside from displaying
  102.  *   the current and maximum scores.  Some game designers like to
  103.  *   provide a ranking that goes with various scores ("Novice Adventurer,"
  104.  *   "Expert," and so forth); this is the place to do so if desired.
  105.  *
  106.  *   Note that "global.maxscore" defines the maximum number of points
  107.  *   possible in the game; change the property in the "global" object
  108.  *   if necessary.
  109.  */
  110. scoreRank: function
  111. {
  112.     "In a total of "; say( global.turnsofar );
  113.     " turns, you have achieved a score of ";
  114.     say( global.score ); " points out of a possible ";
  115.     say( global.maxscore ); ".\n";
  116. }
  117.  
  118. /*
  119.  *   The init() function is run at the very beginning of the game.
  120.  *   It should display the introductory text for the game, start
  121.  *   any needed daemons and fuses, and move the player's actor ("Me")
  122.  *   to the initial room, which defaults here to "startroom".
  123.  */
  124. init: function
  125. {
  126.     // put introductory text here
  127.     
  128.     version.sdesc;                // display the game's name and version number
  129.  
  130.     setdaemon( turncount, nil );               // start the turn counter daemon
  131.     setdaemon( sleepDaemon, nil );                    // start the sleep daemon
  132.     setdaemon( eatDaemon, nil );                     // start the hunger daemon
  133.     Me.location := startroom;                // move player to initial location
  134.     startroom.lookAround( true );                    // show player where he is
  135.     startroom.isseen := true;                  // note that we've seen the room
  136.     scoreStatus(0, 0);                          // initialize the score display
  137. }
  138.  
  139. /*
  140.  *   preinit() is called after compiling the game, before it is written
  141.  *   to the binary game file.  It performs all the initialization that can
  142.  *   be done statically before storing the game in the file, which speeds
  143.  *   loading the game, since all this work has been done ahead of time.
  144.  *
  145.  *   This routine puts all lamp objects (those objects with islamp = true) into
  146.  *   the list global.lamplist.  This list is consulted when determining whether
  147.  *   a dark room contains any light sources.
  148.  */
  149. preinit: function
  150. {
  151.     local o;
  152.     
  153.     global.lamplist := [];
  154.     o := firstobj();
  155.     while( o <> nil )
  156.     {
  157.         if ( o.islamp ) global.lamplist := global.lamplist + o;
  158.         o := nextobj( o );
  159.     }
  160.     initSearch();
  161. }
  162.  
  163. /*
  164.  *   The terminate() function is called just before the game ends.  It
  165.  *   generally displays a good-bye message.  The default version does
  166.  *   nothing.  Note that this function is called only when the game is
  167.  *   about to exit, NOT after dying, before a restart, or anywhere else.
  168.  */
  169. terminate: function
  170. {
  171. }
  172.  
  173. /*
  174.  *   The pardon() function is called any time the player enters a blank
  175.  *   line.  The function generally just prints a message ("Speak up" or
  176.  *   some such).  This default version just says "I beg your pardon?"
  177.  */
  178. pardon: function
  179. {
  180.     "I beg your pardon? ";
  181. }
  182.  
  183. /*
  184.  *   This function is a daemon, started by init(), that monitors how long
  185.  *   it has been since the player slept.  It provides warnings for a while
  186.  *   before the player gets completely exhausted, and causes the player
  187.  *   to pass out and sleep when it has been too long.  The only penalty
  188.  *   exacted if the player passes out is that he drops all his possessions.
  189.  *   Some games might also wish to consider the effects of several hours
  190.  *   having passed; for example, the time-without-food count might be
  191.  *   increased accordingly.
  192.  */
  193. sleepDaemon: function( parm )
  194. {
  195.     local a, s;
  196.  
  197.     global.awakeTime := global.awakeTime + 1;
  198.     a := global.awakeTime;
  199.     s := global.sleepTime;
  200.  
  201.     if ( a = s or a = s+10 or a = s+20 )
  202.         "\bYou're feeling a bit drowsy; you should find a
  203.         comfortable place to sleep. ";
  204.     else if ( a = s+25 or a = s+30 )
  205.         "\bYou really should find someplace to sleep soon, or
  206.         you'll probably pass out from exhaustion. ";
  207.     else if ( a >= s+35 )
  208.     {
  209.       global.awakeTime := 0;
  210.       if ( Me.location.isbed or Me.location.ischair )
  211.       {
  212.         "\bYou find yourself unable to stay awake any longer.
  213.         Fortunately, you are << Me.location.statusPrep >> <<
  214.     Me.location.adesc >>, so you gently slip off into
  215.         unconsciousness.
  216.         \b* * * * *
  217.         \bYou awake some time later, feeling refreshed. ";
  218.       }
  219.       else
  220.       {
  221.         local itemRem, thisItem;
  222.  
  223.         "\bYou find yourself unable to stay awake any longer.
  224.         You pass out, falling to the ground.
  225.         \b* * * * *
  226.         \bYou awaken, feeling somewhat the worse for wear.
  227.         You get up and dust yourself off. ";
  228.         itemRem := Me.contents;
  229.         while (car( itemRem ))
  230.         {
  231.             thisItem := car( itemRem );
  232.             if ( not thisItem.isworn )
  233.             thisItem.moveInto( Me.location );
  234.             itemRem := cdr( itemRem );
  235.         }
  236.       }
  237.     }
  238. }
  239.  
  240. /*
  241.  *   This function is a daemon, set running by init(), which monitors how
  242.  *   long it has been since the player has had anything to eat.  It will
  243.  *   provide warnings for some time prior to the player's expiring from
  244.  *   hunger, and will kill the player if he should go too long without
  245.  *   heeding these warnings.
  246.  */
  247. eatDaemon: function( parm )
  248. {
  249.     local e, l;
  250.  
  251.     global.lastMealTime := global.lastMealTime + 1;
  252.     e := global.eatTime;
  253.     l := global.lastMealTime;
  254.  
  255.     if ( l = e or l = e+5 or l = e+10 )
  256.         "\bYou're feeling a bit peckish. Perhaps it would be a good
  257.         time to find something to eat. ";
  258.     else if ( l = e+15 or l = e+20 or l = e+25 )
  259.         "\bYou're feeling really hungry. You should find some food
  260.         soon or you'll pass out from lack of nutrition. ";
  261.     else if ( l=e+30 or l = e+35 )
  262.         "\bYou can't go much longer without food. ";
  263.     else if ( l >= e+40 )
  264.     {
  265.         "\bYou simply can't go on any longer without food. You perish from
  266.         lack of nutrition. ";
  267.         die();
  268.     }
  269. }
  270.  
  271. /*
  272.  *   The numObj object is used to convey a number to the game whenever
  273.  *   the player uses a number in his command.  For example, "turn dial
  274.  *   to 621" results in an indirect object of numObj, with its "value"
  275.  *   property set to 621.
  276.  */
  277. numObj: basicNumObj  // use default definition from adv.t
  278. ;
  279.  
  280. /*
  281.  *   strObj works like numObj, but for strings.  So, a player command of
  282.  *     type "hello" on the keyboard
  283.  *   will result in a direct object of strObj, with its "value" property
  284.  *   set to the string 'hello'.
  285.  *
  286.  *   Note that, because a string direct object is used in the save, restore,
  287.  *   and script commands, this object must handle those commands.
  288.  */
  289. strObj: basicStrObj     // use default definition from adv.t
  290. ;
  291.  
  292. /*
  293.  *   The "global" object is the dumping ground for any data items that
  294.  *   don't fit very well into any other objects.  The properties of this
  295.  *   object that are particularly important to the objects and functions
  296.  *   are defined here; if you replace this object, but keep other parts
  297.  *   of this file, be sure to include the properties defined here.
  298.  *
  299.  *   Note that awakeTime is set to zero; if you wish the player to start
  300.  *   out tired, just move it up around the sleepTime value (which specifies
  301.  *   the interval between sleeping).  The same goes for lastMealTime; move
  302.  *   it up to around eatTime if you want the player to start out hungry.
  303.  *   With both of these values, the player only starts getting warnings
  304.  *   when the elapsed time (awakeTime, lastMealTime) reaches the interval
  305.  *   (sleepTime, eatTime); the player isn't actually required to eat or
  306.  *   sleep until several warnings have been issued.  Look at the eatDaemon
  307.  *   and sleepDaemon functions for details of the timing.
  308.  */
  309. global: object
  310.     turnsofar = 0                            // no turns have transpired so far
  311.     score = 0                            // no points have been accumulated yet
  312.     maxscore = 100                                    // maximum possible score
  313.     verbose = nil                             // we are currently in TERSE mode
  314.     awakeTime = 0               // time that has elapsed since the player slept
  315.     sleepTime = 400     // interval between sleeping times (longest time awake)
  316.     lastMealTime = 0              // time that has elapsed since the player ate
  317.     eatTime = 200         // interval between meals (longest time without food)
  318.     lamplist = []              // list of all known light providers in the game
  319. ;
  320.  
  321. /*
  322.  *   The "version" object defines, via its "sdesc" property, the name and
  323.  *   version number of the game.  Change this to a suitable name for your
  324.  *   game.
  325.  */
  326. version: object
  327.     sdesc = "A TADS Adventure
  328.       \n Developed with TADS, the Text Adventure Development System.\n"
  329. ;
  330.  
  331. /*
  332.  *   "Me" is the player's actor.  Pick up the default definition, basicMe,
  333.  *   from "adv.t".
  334.  */
  335. Me: basicMe
  336. ;
  337.  
  338. /*
  339.  *   darkTravel() is called whenever the player attempts to move from a dark
  340.  *   location into another dark location.  By default, it just says "You
  341.  *   stumble around in the dark," but it could certainly cast the player into
  342.  *   the jaws of a grue, whatever that is...
  343.  */
  344. darkTravel: function
  345. {
  346.     "You stumble around in the dark, and don't get anywhere. ";
  347. }
  348.  
  349. /*
  350.  *   goToSleep - carries out the task of falling asleep.  We just display
  351.  *   a message to this effect.
  352.  */
  353. goToSleep: function
  354. {
  355.     "***\bYou wake up some time later, feeling refreshed. ";
  356.     global.awakeTime := 0;
  357. }
  358.