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