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