| 1 |
/* Copyright (c) 1989-2000 by Michael J. Roberts. All Rights Reserved. */ |
| 2 |
/* |
| 3 |
Name |
| 4 |
std.t - standard default adventure definitions |
| 5 |
Version 2.5.17 |
| 6 |
|
| 7 |
This file is part of TADS: The Text Adventure Development System. |
| 8 |
Please see the file LICENSE.TAD (which should be part of the TADS |
| 9 |
distribution) for information on using this file. |
| 10 |
|
| 11 |
You may modify and use this file in any way you want, provided that |
| 12 |
if you redistribute modified copies of this file in source form, the |
| 13 |
copies must include the original copyright notice (including this |
| 14 |
paragraph), and must be clearly marked as modified from the original |
| 15 |
version. |
| 16 |
|
| 17 |
This file provides some simple definitions for objects and functions |
| 18 |
that are required by TADS, but not defined in the file "adv.t". |
| 19 |
The definitions in std.t are suitable for use while a game is |
| 20 |
being written, but you will probably find that you will want to |
| 21 |
customize the definitions in this file for your game when the |
| 22 |
game is nearing completion. This file is intended to help you |
| 23 |
get started more quickly by providing basic definitions for these |
| 24 |
functions and objects. |
| 25 |
|
| 26 |
When you decide to customize these functions and objects for |
| 27 |
your game, be sure to remove the inclusion of std.t to avoid |
| 28 |
duplicate definitions. |
| 29 |
*/ |
| 30 |
|
| 31 |
/* parse with normal TADS operators */ |
| 32 |
#pragma C- |
| 33 |
|
| 34 |
/* |
| 35 |
* Pre-declare all functions, so the compiler knows they are functions. |
| 36 |
* (This is only really necessary when a function will be referenced |
| 37 |
* as a daemon or fuse before it is defined; however, it doesn't hurt |
| 38 |
* anything to pre-declare all of them.) |
| 39 |
*/ |
| 40 |
die: function; |
| 41 |
scoreRank: function; |
| 42 |
init: function; |
| 43 |
terminate: function; |
| 44 |
pardon: function; |
| 45 |
sleepDaemon: function; |
| 46 |
eatDaemon: function; |
| 47 |
darkTravel: function; |
| 48 |
mainRestore: function; |
| 49 |
commonInit: function; |
| 50 |
initRestore: function; |
| 51 |
|
| 52 |
/* |
| 53 |
* The die() function is called when the player dies. It tells the |
| 54 |
* player how well he has done (with his score), and asks if he'd |
| 55 |
* like to start over (the alternative being quitting the game). |
| 56 |
*/ |
| 57 |
die: function |
| 58 |
{ |
| 59 |
"\b*** You have died ***\b"; |
| 60 |
scoreRank(); |
| 61 |
"\bYou may restore a saved game, start over, quit, or undo |
| 62 |
the current command.\n"; |
| 63 |
while (true) |
| 64 |
{ |
| 65 |
local resp; |
| 66 |
|
| 67 |
"\nPlease enter RESTORE, RESTART, QUIT, or UNDO: >"; |
| 68 |
resp := upper(input()); |
| 69 |
if (resp = 'RESTORE') |
| 70 |
{ |
| 71 |
resp := askfile('File to restore', |
| 72 |
ASKFILE_PROMPT_OPEN, FILE_TYPE_SAVE); |
| 73 |
if (resp = nil) |
| 74 |
"Restore failed. "; |
| 75 |
else if (restore(resp)) |
| 76 |
"Restore failed. "; |
| 77 |
else |
| 78 |
{ |
| 79 |
parserGetMe().location.lookAround(true); |
| 80 |
scoreStatus(global.score, global.turnsofar); |
| 81 |
abort; |
| 82 |
} |
| 83 |
} |
| 84 |
else if (resp = 'RESTART') |
| 85 |
{ |
| 86 |
scoreStatus(0, 0); |
| 87 |
restart(); |
| 88 |
} |
| 89 |
else if (resp = 'QUIT') |
| 90 |
{ |
| 91 |
terminate(); |
| 92 |
quit(); |
| 93 |
abort; |
| 94 |
} |
| 95 |
else if (resp = 'UNDO') |
| 96 |
{ |
| 97 |
if (undo()) |
| 98 |
{ |
| 99 |
"(Undoing one command)\b"; |
| 100 |
parserGetMe().location.lookAround(true); |
| 101 |
scoreStatus(global.score, global.turnsofar); |
| 102 |
abort; |
| 103 |
} |
| 104 |
else |
| 105 |
"Sorry, no undo information is available. "; |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
/* |
| 111 |
* The scoreRank() function displays how well the player is doing. |
| 112 |
* This default definition doesn't do anything aside from displaying |
| 113 |
* the current and maximum scores. Some game designers like to |
| 114 |
* provide a ranking that goes with various scores ("Novice Adventurer," |
| 115 |
* "Expert," and so forth); this is the place to do so if desired. |
| 116 |
* |
| 117 |
* Note that "global.maxscore" defines the maximum number of points |
| 118 |
* possible in the game; change the property in the "global" object |
| 119 |
* if necessary. |
| 120 |
*/ |
| 121 |
scoreRank: function |
| 122 |
{ |
| 123 |
"In a total of "; say(global.turnsofar); |
| 124 |
" turns, you have achieved a score of "; |
| 125 |
say(global.score); " points out of a possible "; |
| 126 |
say(global.maxscore); ".\n"; |
| 127 |
} |
| 128 |
|
| 129 |
/* |
| 130 |
* commonInit() - this is not a system-required function; this is simply |
| 131 |
* a helper function that we define so that we can put common |
| 132 |
* initialization code in a single place. Both init() and initRestore() |
| 133 |
* call this. Since the system may call either init() or initRestore() |
| 134 |
* during game startup, but not both, it's desirable to have a single |
| 135 |
* function that both of those functions call for code that must be |
| 136 |
* performed at startup regardless of how we're starting. |
| 137 |
*/ |
| 138 |
commonInit: function |
| 139 |
{ |
| 140 |
// put common initialization code here |
| 141 |
} |
| 142 |
|
| 143 |
/* |
| 144 |
* The init() function is run at the very beginning of the game. |
| 145 |
* It should display the introductory text for the game, start |
| 146 |
* any needed daemons and fuses, and move the player's actor ("Me") |
| 147 |
* to the initial room, which defaults here to "startroom". |
| 148 |
*/ |
| 149 |
init: function |
| 150 |
{ |
| 151 |
#ifdef USE_HTML_STATUS |
| 152 |
/* |
| 153 |
* We're using the adv.t HTML-style status line - make sure the |
| 154 |
* run-time version is recent enough to support this code. (The |
| 155 |
* status line code uses systemInfo to detect whether the run-time |
| 156 |
* is HTML-enabled or not, which doesn't work properly before |
| 157 |
* version 2.2.4.) |
| 158 |
*/ |
| 159 |
if (systemInfo(__SYSINFO_SYSINFO) != true |
| 160 |
|| systemInfo(__SYSINFO_VERSION) < '2.2.4') |
| 161 |
{ |
| 162 |
"\b\b\(WARNING! This game requires the TADS run-time version |
| 163 |
2.2.4 or higher. You appear to be using an older version of the |
| 164 |
TADS run-time. You can still attempt to run this game, but the |
| 165 |
game's screen display may not work properly. If you experience |
| 166 |
any problems, you should try upgrading to the latest version of |
| 167 |
the TADS run-time.\)\b\b"; |
| 168 |
} |
| 169 |
#endif |
| 170 |
|
| 171 |
/* perform common initializations */ |
| 172 |
commonInit(); |
| 173 |
|
| 174 |
// put introductory text here |
| 175 |
|
| 176 |
version.sdesc; // display the game's name and version number |
| 177 |
|
| 178 |
setdaemon(turncount, nil); // start the turn counter daemon |
| 179 |
setdaemon(sleepDaemon, nil); // start the sleep daemon |
| 180 |
setdaemon(eatDaemon, nil); // start the hunger daemon |
| 181 |
parserGetMe().location := startroom; // move player to initial location |
| 182 |
startroom.lookAround(true); // show player where he is |
| 183 |
startroom.isseen := true; // note that we've seen the room |
| 184 |
scoreStatus(0, 0); // initialize the score display |
| 185 |
} |
| 186 |
|
| 187 |
/* |
| 188 |
* initRestore() - the system calls this function automatically at game |
| 189 |
* startup if the player specifies a saved game to restore on the |
| 190 |
* run-time command line (or through another appropriate |
| 191 |
* system-dependent mechanism). We'll simply restore the game in the |
| 192 |
* normal way. |
| 193 |
*/ |
| 194 |
initRestore: function(fname) |
| 195 |
{ |
| 196 |
/* perform common initializations */ |
| 197 |
commonInit(); |
| 198 |
|
| 199 |
/* tell the player we're restoring a game */ |
| 200 |
"\b[Restoring saved position...]\b"; |
| 201 |
|
| 202 |
/* go restore the game in the normal way */ |
| 203 |
mainRestore(fname); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
/* |
| 208 |
* preinit() is called after compiling the game, before it is written |
| 209 |
* to the binary game file. It performs all the initialization that can |
| 210 |
* be done statically before storing the game in the file, which speeds |
| 211 |
* loading the game, since all this work has been done ahead of time. |
| 212 |
* |
| 213 |
* This routine puts all lamp objects (those objects with islamp = true) into |
| 214 |
* the list global.lamplist. This list is consulted when determining whether |
| 215 |
* a dark room contains any light sources. |
| 216 |
*/ |
| 217 |
preinit: function |
| 218 |
{ |
| 219 |
local o; |
| 220 |
|
| 221 |
global.lamplist := []; |
| 222 |
o := firstobj(); |
| 223 |
while(o <> nil) |
| 224 |
{ |
| 225 |
if (o.islamp) |
| 226 |
global.lamplist := global.lamplist + o; |
| 227 |
o := nextobj(o); |
| 228 |
} |
| 229 |
initSearch(); |
| 230 |
|
| 231 |
#ifdef GAMEINFO_INCLUDED |
| 232 |
writeGameInfo(getGameInfo()); |
| 233 |
#endif |
| 234 |
} |
| 235 |
|
| 236 |
/* |
| 237 |
* The terminate() function is called just before the game ends. It |
| 238 |
* generally displays a good-bye message. The default version does |
| 239 |
* nothing. Note that this function is called only when the game is |
| 240 |
* about to exit, NOT after dying, before a restart, or anywhere else. |
| 241 |
*/ |
| 242 |
terminate: function |
| 243 |
{ |
| 244 |
} |
| 245 |
|
| 246 |
/* |
| 247 |
* The pardon() function is called any time the player enters a blank |
| 248 |
* line. The function generally just prints a message ("Speak up" or |
| 249 |
* some such). This default version just says "I beg your pardon?" |
| 250 |
*/ |
| 251 |
pardon: function |
| 252 |
{ |
| 253 |
"I beg your pardon? "; |
| 254 |
} |
| 255 |
|
| 256 |
/* |
| 257 |
* This function is a daemon, started by init(), that monitors how long |
| 258 |
* it has been since the player slept. It provides warnings for a while |
| 259 |
* before the player gets completely exhausted, and causes the player |
| 260 |
* to pass out and sleep when it has been too long. The only penalty |
| 261 |
* exacted if the player passes out is that he drops all his possessions. |
| 262 |
* Some games might also wish to consider the effects of several hours |
| 263 |
* having passed; for example, the time-without-food count might be |
| 264 |
* increased accordingly. |
| 265 |
*/ |
| 266 |
sleepDaemon: function(parm) |
| 267 |
{ |
| 268 |
local a, s; |
| 269 |
|
| 270 |
global.awakeTime := global.awakeTime + 1; |
| 271 |
a := global.awakeTime; |
| 272 |
s := global.sleepTime; |
| 273 |
|
| 274 |
if (a = s or a = s + 10 or a = s + 20) |
| 275 |
"\bYou're feeling a bit drowsy; you should find a |
| 276 |
comfortable place to sleep. "; |
| 277 |
else if (a = s + 25 or a = s + 30) |
| 278 |
"\bYou really should find someplace to sleep soon, or |
| 279 |
you'll probably pass out from exhaustion. "; |
| 280 |
else if (a >= s + 35) |
| 281 |
{ |
| 282 |
global.awakeTime := 0; |
| 283 |
if (parserGetMe().location.isbed or parserGetMe().location.ischair) |
| 284 |
{ |
| 285 |
"\bYou find yourself unable to stay awake any longer. |
| 286 |
Fortunately, you are << parserGetMe().location.statusPrep >> << |
| 287 |
parserGetMe().location.adesc >>, so you gently slip off into |
| 288 |
unconsciousness. |
| 289 |
\b* * * * * |
| 290 |
\bYou awake some time later, feeling refreshed. "; |
| 291 |
} |
| 292 |
else |
| 293 |
{ |
| 294 |
local itemRem, thisItem; |
| 295 |
|
| 296 |
"\bYou find yourself unable to stay awake any longer. |
| 297 |
You pass out, falling to the ground. |
| 298 |
\b* * * * * |
| 299 |
\bYou awaken, feeling somewhat the worse for wear. |
| 300 |
You get up and dust yourself off. "; |
| 301 |
itemRem := parserGetMe().contents; |
| 302 |
while (car(itemRem)) |
| 303 |
{ |
| 304 |
thisItem := car(itemRem); |
| 305 |
if (not thisItem.isworn) |
| 306 |
thisItem.moveInto(parserGetMe().location); |
| 307 |
itemRem := cdr(itemRem); |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
/* |
| 314 |
* This function is a daemon, set running by init(), which monitors how |
| 315 |
* long it has been since the player has had anything to eat. It will |
| 316 |
* provide warnings for some time prior to the player's expiring from |
| 317 |
* hunger, and will kill the player if he should go too long without |
| 318 |
* heeding these warnings. |
| 319 |
*/ |
| 320 |
eatDaemon: function(parm) |
| 321 |
{ |
| 322 |
local e, l; |
| 323 |
|
| 324 |
global.lastMealTime := global.lastMealTime + 1; |
| 325 |
e := global.eatTime; |
| 326 |
l := global.lastMealTime; |
| 327 |
|
| 328 |
if (l = e or l = e + 5 or l = e + 10) |
| 329 |
"\bYou're feeling a bit peckish. Perhaps it would be a good |
| 330 |
time to find something to eat. "; |
| 331 |
else if (l = e + 15 or l = e + 20 or l = e + 25) |
| 332 |
"\bYou're feeling really hungry. You should find some food |
| 333 |
soon or you'll pass out from lack of nutrition. "; |
| 334 |
else if (l = e + 30 or l = e + 35) |
| 335 |
"\bYou can't go much longer without food. "; |
| 336 |
else if (l >= e + 40) |
| 337 |
{ |
| 338 |
"\bYou simply can't go on any longer without food. You perish from |
| 339 |
lack of nutrition. "; |
| 340 |
die(); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
/* |
| 345 |
* The numObj object is used to convey a number to the game whenever |
| 346 |
* the player uses a number in his command. For example, "turn dial |
| 347 |
* to 621" results in an indirect object of numObj, with its "value" |
| 348 |
* property set to 621. |
| 349 |
*/ |
| 350 |
numObj: basicNumObj // use default definition from adv.t |
| 351 |
; |
| 352 |
|
| 353 |
/* |
| 354 |
* strObj works like numObj, but for strings. So, a player command of |
| 355 |
* type "hello" on the keyboard |
| 356 |
* will result in a direct object of strObj, with its "value" property |
| 357 |
* set to the string 'hello'. |
| 358 |
* |
| 359 |
* Note that, because a string direct object is used in the save, restore, |
| 360 |
* and script commands, this object must handle those commands. |
| 361 |
*/ |
| 362 |
strObj: basicStrObj // use default definition from adv.t |
| 363 |
; |
| 364 |
|
| 365 |
/* |
| 366 |
* The "global" object is the dumping ground for any data items that |
| 367 |
* don't fit very well into any other objects. The properties of this |
| 368 |
* object that are particularly important to the objects and functions |
| 369 |
* are defined here; if you replace this object, but keep other parts |
| 370 |
* of this file, be sure to include the properties defined here. |
| 371 |
* |
| 372 |
* Note that awakeTime is set to zero; if you wish the player to start |
| 373 |
* out tired, just move it up around the sleepTime value (which specifies |
| 374 |
* the interval between sleeping). The same goes for lastMealTime; move |
| 375 |
* it up to around eatTime if you want the player to start out hungry. |
| 376 |
* With both of these values, the player only starts getting warnings |
| 377 |
* when the elapsed time (awakeTime, lastMealTime) reaches the interval |
| 378 |
* (sleepTime, eatTime); the player isn't actually required to eat or |
| 379 |
* sleep until several warnings have been issued. Look at the eatDaemon |
| 380 |
* and sleepDaemon functions for details of the timing. |
| 381 |
*/ |
| 382 |
global: object |
| 383 |
turnsofar = 0 // no turns have transpired so far |
| 384 |
score = 0 // no points have been accumulated yet |
| 385 |
maxscore = 100 // maximum possible score |
| 386 |
verbose = nil // we are currently in TERSE mode |
| 387 |
awakeTime = 0 // time that has elapsed since the player slept |
| 388 |
sleepTime = 400 // interval between sleeping times (longest time awake) |
| 389 |
lastMealTime = 0 // time that has elapsed since the player ate |
| 390 |
eatTime = 200 // interval between meals (longest time without food) |
| 391 |
lamplist = [] // list of all known light providers in the game |
| 392 |
; |
| 393 |
|
| 394 |
/* |
| 395 |
* The "version" object defines, via its "sdesc" property, the name and |
| 396 |
* version number of the game. Change this to a suitable name for your |
| 397 |
* game. |
| 398 |
*/ |
| 399 |
version: object |
| 400 |
sdesc = "A TADS Adventure |
| 401 |
\n Developed with TADS, the Text Adventure Development System.\n" |
| 402 |
; |
| 403 |
|
| 404 |
/* |
| 405 |
* "Me" is the initial player's actor; the parser automatically uses the |
| 406 |
* object named "Me" as the player character object at the beginning of |
| 407 |
* the game. We'll provide a default definition simply by creating an |
| 408 |
* object that inherits from the basic player object, basicMe, defined |
| 409 |
* in "adv.t". |
| 410 |
* |
| 411 |
* Note that you can change the player character object at any time |
| 412 |
* during the game by calling parserSetMe(newMe). You can also create |
| 413 |
* additional player character objects, if you want to let the player |
| 414 |
* take the role of different characters in the course of the game, by |
| 415 |
* creating additional objects that inherit from basicMe. (Inheriting |
| 416 |
* from basicMe isn't required for player character objects -- you can |
| 417 |
* define your own objects from scratch -- but it makes it a lot easier, |
| 418 |
* since basicMe has a lot of code pre-defined for you.) |
| 419 |
*/ |
| 420 |
Me: basicMe |
| 421 |
; |
| 422 |
|
| 423 |
/* |
| 424 |
* darkTravel() is called whenever the player attempts to move from a dark |
| 425 |
* location into another dark location. By default, it just says "You |
| 426 |
* stumble around in the dark," but it could certainly cast the player into |
| 427 |
* the jaws of a grue, whatever that is... |
| 428 |
*/ |
| 429 |
darkTravel: function |
| 430 |
{ |
| 431 |
"You stumble around in the dark, and don't get anywhere. "; |
| 432 |
} |
| 433 |
|
| 434 |
/* |
| 435 |
* goToSleep - carries out the task of falling asleep. We just display |
| 436 |
* a message to this effect. |
| 437 |
*/ |
| 438 |
goToSleep: function |
| 439 |
{ |
| 440 |
"***\bYou wake up some time later, feeling refreshed. "; |
| 441 |
global.awakeTime := 0; |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
#ifdef USE_HTML_PROMPT |
| 446 |
/* |
| 447 |
* commandPrompt - this displays the command prompt. For HTML games, we |
| 448 |
* switch to the special TADS-Input font, which lets the player choose |
| 449 |
* the font for command input through the preferences dialog. |
| 450 |
*/ |
| 451 |
commandPrompt: function(code) |
| 452 |
{ |
| 453 |
/* display the normal prompt */ |
| 454 |
"\b>"; |
| 455 |
|
| 456 |
/* |
| 457 |
* switch the font to TADS-Input - the standard text-only |
| 458 |
* interpreter will simply ignore this, so we don't have to worry |
| 459 |
* about whether we're using an HTML-enabled interpreter or not |
| 460 |
*/ |
| 461 |
"<font face='TADS-Input'>"; |
| 462 |
} |
| 463 |
|
| 464 |
/* |
| 465 |
* commandAfterRead - this is called just after each command is entered. |
| 466 |
* For HTML games, we'll switch back to the original font that was in |
| 467 |
* effect before commandPrompt switched to TADS-Input. |
| 468 |
*/ |
| 469 |
commandAfterRead: function(code) |
| 470 |
{ |
| 471 |
"</font>"; |
| 472 |
} |
| 473 |
#endif /* USE_HTML_PROMPT */ |
| 474 |
|