| 1 |
#charset "us-ascii" |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (c) 2000, 2006 Michael J. Roberts. All Rights Reserved. |
| 5 |
* |
| 6 |
* TADS 3 Library: Actions. |
| 7 |
* |
| 8 |
* This module defines the set of built-in library actions. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "adv3.h" |
| 12 |
#include "tok.h" |
| 13 |
|
| 14 |
/* ------------------------------------------------------------------------ */ |
| 15 |
/* |
| 16 |
* Special "debug" action - this simply breaks into the debugger, if the |
| 17 |
* debugger is present. |
| 18 |
*/ |
| 19 |
DefineIAction(Debug) |
| 20 |
execAction() |
| 21 |
{ |
| 22 |
/* if the debugger is present, break into it */ |
| 23 |
if (t3DebugTrace(T3DebugCheck)) |
| 24 |
t3DebugTrace(T3DebugBreak); |
| 25 |
else |
| 26 |
"Debugger not present. "; |
| 27 |
} |
| 28 |
; |
| 29 |
|
| 30 |
/* ------------------------------------------------------------------------ */ |
| 31 |
/* |
| 32 |
* Special internal action to note a change to the darkness level. This |
| 33 |
* command is invoked internally when a change to the darkness level |
| 34 |
* occurs. |
| 35 |
*/ |
| 36 |
DefineIAction(NoteDarkness) |
| 37 |
execAction() |
| 38 |
{ |
| 39 |
/* |
| 40 |
* if we're in the dark, note that darkness has fallen; |
| 41 |
* otherwise, show the player character's room description as |
| 42 |
* though the player had typed "look" |
| 43 |
*/ |
| 44 |
if (gActor.isLocationLit()) |
| 45 |
{ |
| 46 |
/* look around */ |
| 47 |
gActor.lookAround(true); |
| 48 |
} |
| 49 |
else |
| 50 |
{ |
| 51 |
/* it is now dark */ |
| 52 |
mainReport(&newlyDarkMsg); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/* this is an internal command that takes no time */ |
| 57 |
actionTime = 0 |
| 58 |
|
| 59 |
/* this isn't a real action, so it's not repeatable */ |
| 60 |
isRepeatable = nil |
| 61 |
|
| 62 |
/* this action doesn't do anything; don't include it in undo */ |
| 63 |
includeInUndo = nil |
| 64 |
; |
| 65 |
|
| 66 |
/* ------------------------------------------------------------------------ */ |
| 67 |
/* |
| 68 |
* Special "again" action. This command repeats the previous command. |
| 69 |
*/ |
| 70 |
DefineIAction(Again) |
| 71 |
/* for obvious reasons, 'again' is not itself repeatable with 'again' */ |
| 72 |
isRepeatable = nil |
| 73 |
|
| 74 |
/* |
| 75 |
* the undo command itself is not undoable (but the underlying |
| 76 |
* command that we repeat might be) |
| 77 |
*/ |
| 78 |
includeInUndo = nil |
| 79 |
|
| 80 |
/* information on the most recent command */ |
| 81 |
lastIssuingActor = nil |
| 82 |
lastTargetActor = nil |
| 83 |
lastTargetActorPhrase = nil |
| 84 |
lastAction = nil |
| 85 |
|
| 86 |
/* save the most recent command so that it can be repeated if desired */ |
| 87 |
saveForAgain(issuingActor, targetActor, targetActorPhrase, action) |
| 88 |
{ |
| 89 |
/* save the information */ |
| 90 |
lastIssuingActor = issuingActor; |
| 91 |
lastTargetActor = targetActor; |
| 92 |
lastTargetActorPhrase = targetActorPhrase; |
| 93 |
lastAction = action.createClone(); |
| 94 |
} |
| 95 |
|
| 96 |
/* forget the last command, so that AGAIN cannot be used */ |
| 97 |
clearForAgain() { lastAction = nil; } |
| 98 |
|
| 99 |
/* |
| 100 |
* Execute the 'again' command. This action is special enough that |
| 101 |
* we override its entire action processing sequence - this is |
| 102 |
* necessary in case we're repeating another special command, such |
| 103 |
* as 'again', and in any case is desirable because we don't want |
| 104 |
* 'again' to count as a command in its own right; it's essentially |
| 105 |
* just a macro that we replace with the original command. |
| 106 |
*/ |
| 107 |
doAction(issuingActor, targetActor, targetActorPhrase, |
| 108 |
countsAsIssuerTurn) |
| 109 |
{ |
| 110 |
/* if there's nothing to repeat, show an error and give up */ |
| 111 |
if (lastAction == nil) |
| 112 |
{ |
| 113 |
gLibMessages.noCommandForAgain(); |
| 114 |
return; |
| 115 |
} |
| 116 |
|
| 117 |
/* |
| 118 |
* 'again' cannot be executed with a target actor - the target |
| 119 |
* actor must be the player character |
| 120 |
*/ |
| 121 |
if (!targetActor.isPlayerChar) |
| 122 |
{ |
| 123 |
gLibMessages.againCannotChangeActor(); |
| 124 |
return; |
| 125 |
} |
| 126 |
|
| 127 |
/* |
| 128 |
* if the issuing actor isn't the same as the target actor, make |
| 129 |
* sure the issuer can still talk to the target |
| 130 |
*/ |
| 131 |
if (lastIssuingActor != lastTargetActor |
| 132 |
&& !lastIssuingActor.canTalkTo(lastTargetActor)) |
| 133 |
{ |
| 134 |
/* complain that we can no longer talk to the target */ |
| 135 |
gLibMessages.againCannotTalkToTarget( |
| 136 |
lastIssuingActor, lastTargetActor); |
| 137 |
return; |
| 138 |
} |
| 139 |
|
| 140 |
/* |
| 141 |
* If the last issuing actor is different from the last target |
| 142 |
* actor, then the command counts as an issuer turn, because |
| 143 |
* we're effectively repeating the entire last command, including |
| 144 |
* the target actor specification. That is, after a command like |
| 145 |
* "bob, go east", saying "again" is just like saying "bob, go |
| 146 |
* east" again, which counts as an issuer turn. |
| 147 |
*/ |
| 148 |
if (lastTargetActor != lastIssuingActor) |
| 149 |
countsAsIssuerTurn = true; |
| 150 |
|
| 151 |
/* reset any cached information for the new command context */ |
| 152 |
lastAction.resetAction(); |
| 153 |
|
| 154 |
/* repeat the action */ |
| 155 |
lastAction.repeatAction(lastTargetActor, lastTargetActorPhrase, |
| 156 |
lastIssuingActor, countsAsIssuerTurn); |
| 157 |
|
| 158 |
/* |
| 159 |
* If the command was directed from the issuer to a different |
| 160 |
* target actor, and the issuer wants to wait for the full set of |
| 161 |
* issued commands to complete before getting another turn, tell |
| 162 |
* the issuer to begin waiting. |
| 163 |
*/ |
| 164 |
if (lastTargetActor != lastIssuingActor) |
| 165 |
lastIssuingActor.waitForIssuedCommand(lastTargetActor); |
| 166 |
} |
| 167 |
|
| 168 |
/* |
| 169 |
* this command itself consumes no time on the game clock (although |
| 170 |
* the action we perform might) |
| 171 |
*/ |
| 172 |
actionTime = 0 |
| 173 |
; |
| 174 |
|
| 175 |
/* ------------------------------------------------------------------------ */ |
| 176 |
/* |
| 177 |
* PreSaveObject - every instance of this class is notified, via its |
| 178 |
* execute() method, just before we save the game. This uses the |
| 179 |
* ModuleExecObject framework, so the sequencing lists (execBeforeMe, |
| 180 |
* execAfterMe) can be used to control relative ordering of execution |
| 181 |
* among instances. |
| 182 |
*/ |
| 183 |
class PreSaveObject: ModuleExecObject |
| 184 |
/* |
| 185 |
* Each instance must override execute() with its specific pre-save |
| 186 |
* code. |
| 187 |
*/ |
| 188 |
; |
| 189 |
|
| 190 |
/* |
| 191 |
* PostRestoreObject - every instance of this class is notified, via its |
| 192 |
* execute() method, immediately after we restore the game. |
| 193 |
*/ |
| 194 |
class PostRestoreObject: ModuleExecObject |
| 195 |
/* |
| 196 |
* note: each instance must override execute() with its post-restore |
| 197 |
* code |
| 198 |
*/ |
| 199 |
|
| 200 |
/* |
| 201 |
* The "restore code," which is the (normally integer) value passed |
| 202 |
* as the second argument to restoreGame(). The restore code gives |
| 203 |
* us some idea of what triggered the restoration. By default, we |
| 204 |
* define the following restore codes: |
| 205 |
* |
| 206 |
* 1 - the system is restoring a game as part of interpreter |
| 207 |
* startup, usually because the user explicitly specified a game to |
| 208 |
* restore on the interpreter command line or via a GUI shell |
| 209 |
* mechanism, such as double-clicking on a saved game file from the |
| 210 |
* desktop. |
| 211 |
* |
| 212 |
* 2 - the user is explicitly restoring a game via a RESTORE command. |
| 213 |
* |
| 214 |
* Games and library extensions can use their own additional restore |
| 215 |
* codes in their calls to restoreGame(). |
| 216 |
*/ |
| 217 |
restoreCode = nil |
| 218 |
; |
| 219 |
|
| 220 |
/* |
| 221 |
* PreRestartObject - every instance of this class is notified, via its |
| 222 |
* execute() method, just before we restart the game (with a RESTART |
| 223 |
* command, for example). |
| 224 |
*/ |
| 225 |
class PreRestartObject: ModuleExecObject |
| 226 |
/* |
| 227 |
* Each instance must override execute() with its specific |
| 228 |
* pre-restart code. |
| 229 |
*/ |
| 230 |
; |
| 231 |
|
| 232 |
/* |
| 233 |
* PostUndoObject - every instance of this class is notified, via its |
| 234 |
* execute() method, immediately after we perform an 'undo' command. |
| 235 |
*/ |
| 236 |
class PostUndoObject: ModuleExecObject |
| 237 |
/* |
| 238 |
* Each instance must override execute() with its specific post-undo |
| 239 |
* code. |
| 240 |
*/ |
| 241 |
; |
| 242 |
|
| 243 |
/* ------------------------------------------------------------------------ */ |
| 244 |
/* |
| 245 |
* Special "save" action. This command saves the current game state to |
| 246 |
* an external file for later restoration. |
| 247 |
*/ |
| 248 |
DefineAction(Save, FileOpAction) |
| 249 |
/* the file dialog prompt */ |
| 250 |
filePromptMsg = (gLibMessages.getSavePrompt()) |
| 251 |
|
| 252 |
/* we're asking for a file to save, or type t3-save */ |
| 253 |
fileDisposition = InFileSave |
| 254 |
fileTypeID = FileTypeT3Save |
| 255 |
|
| 256 |
/* cancel message */ |
| 257 |
showCancelMsg() { gLibMessages.saveCanceled(); } |
| 258 |
|
| 259 |
/* perform a save */ |
| 260 |
performFileOp(fname, ack, desc:?) |
| 261 |
{ |
| 262 |
/* before saving the game, notify all PreSaveObject instances */ |
| 263 |
PreSaveObject.classExec(); |
| 264 |
|
| 265 |
/* |
| 266 |
* Save the game to the given file. If an error occurs, the |
| 267 |
* save routine will throw a runtime error. |
| 268 |
*/ |
| 269 |
try |
| 270 |
{ |
| 271 |
/* try saving the game */ |
| 272 |
saveGame(fname, gameMain.getSaveDesc(desc)); |
| 273 |
} |
| 274 |
catch (StorageServerError sse) |
| 275 |
{ |
| 276 |
/* the save failed due to a storage server problem - explain */ |
| 277 |
gLibMessages.saveFailedOnServer(sse); |
| 278 |
|
| 279 |
/* done */ |
| 280 |
return; |
| 281 |
} |
| 282 |
catch (RuntimeError err) |
| 283 |
{ |
| 284 |
/* the save failed - mention the problem */ |
| 285 |
gLibMessages.saveFailed(err); |
| 286 |
|
| 287 |
/* done */ |
| 288 |
return; |
| 289 |
} |
| 290 |
|
| 291 |
/* note the successful save */ |
| 292 |
gLibMessages.saveOkay(); |
| 293 |
} |
| 294 |
|
| 295 |
/* |
| 296 |
* Saving has no effect on game state, so it's irrelevant whether or |
| 297 |
* not it's undoable; but it might be confusing to say we undid a |
| 298 |
* "save" command, because the player might think we deleted the |
| 299 |
* saved file. To avoid such confusion, do not include "save" |
| 300 |
* commands in the undo log. |
| 301 |
*/ |
| 302 |
includeInUndo = nil |
| 303 |
|
| 304 |
/* |
| 305 |
* Don't allow this to be repeated with AGAIN. There's no point in |
| 306 |
* repeating a SAVE immediately, as nothing will have changed in the |
| 307 |
* game state to warrant saving again. |
| 308 |
*/ |
| 309 |
isRepeatable = nil |
| 310 |
; |
| 311 |
|
| 312 |
/* |
| 313 |
* Subclass of Save action that takes a literal string as part of the |
| 314 |
* command. The filename must be a literal enclosed in quotes, and the |
| 315 |
* string (with the quotes) must be stored in our fname_ property by |
| 316 |
* assignment of a quotedStringPhrase production in the grammar rule. |
| 317 |
*/ |
| 318 |
DefineAction(SaveString, SaveAction) |
| 319 |
execSystemAction() |
| 320 |
{ |
| 321 |
/* |
| 322 |
* Perform the save, using the filename given in our fname_ |
| 323 |
* parameter, trimmed of quotes. |
| 324 |
*/ |
| 325 |
performFileOp(fname_.getStringText(), true); |
| 326 |
} |
| 327 |
; |
| 328 |
|
| 329 |
|
| 330 |
/* ------------------------------------------------------------------------ */ |
| 331 |
/* |
| 332 |
* Special "restore" action. This action restores game state previously |
| 333 |
* saved with the "save" action. |
| 334 |
*/ |
| 335 |
DefineSystemAction(Restore) |
| 336 |
execSystemAction() |
| 337 |
{ |
| 338 |
/* ask for a file and restore it */ |
| 339 |
askAndRestore(); |
| 340 |
|
| 341 |
/* |
| 342 |
* regardless of what happened, abandon any additional commands |
| 343 |
* on the same command line |
| 344 |
*/ |
| 345 |
throw new TerminateCommandException(); |
| 346 |
} |
| 347 |
|
| 348 |
/* |
| 349 |
* Ask for a file and try to restore it. Returns true on success, |
| 350 |
* nil on failure. (Failure could indicate that the user chose to |
| 351 |
* cancel out of the file selector, that we couldn't find the file to |
| 352 |
* restore, or that the file isn't a valid saved state file. In any |
| 353 |
* case, we show an appropriate message on failure.) |
| 354 |
*/ |
| 355 |
askAndRestore() |
| 356 |
{ |
| 357 |
local succ; |
| 358 |
local result; |
| 359 |
local origElapsedTime; |
| 360 |
|
| 361 |
/* presume failure */ |
| 362 |
succ = nil; |
| 363 |
|
| 364 |
/* note the current elapsed game time */ |
| 365 |
origElapsedTime = realTimeManager.getElapsedTime(); |
| 366 |
|
| 367 |
/* ask for a file */ |
| 368 |
result = getInputFile(gLibMessages.getRestorePrompt(), InFileOpen, |
| 369 |
FileTypeT3Save, 0); |
| 370 |
|
| 371 |
/* |
| 372 |
* restore the real-time clock, so that the time spent in the |
| 373 |
* file selector dialog doesn't count against the game time |
| 374 |
*/ |
| 375 |
realTimeManager.setElapsedTime(origElapsedTime); |
| 376 |
|
| 377 |
/* check the inputFile response */ |
| 378 |
switch(result[1]) |
| 379 |
{ |
| 380 |
case InFileSuccess: |
| 381 |
/* |
| 382 |
* try restoring the file; use code 2 to indicate that the |
| 383 |
* restoration was performed by an explicit RESTORE command |
| 384 |
*/ |
| 385 |
if (performRestore(result[2], 2)) |
| 386 |
{ |
| 387 |
/* note that we succeeded */ |
| 388 |
succ = true; |
| 389 |
} |
| 390 |
else |
| 391 |
{ |
| 392 |
/* |
| 393 |
* failed - in case the failed restore took some time, |
| 394 |
* restore the real-time clock, so that the file-reading |
| 395 |
* time doesn't count against the game time |
| 396 |
*/ |
| 397 |
realTimeManager.setElapsedTime(origElapsedTime); |
| 398 |
} |
| 399 |
|
| 400 |
/* done */ |
| 401 |
break; |
| 402 |
|
| 403 |
case InFileFailure: |
| 404 |
/* advise of the failure of the prompt */ |
| 405 |
if (result.length() > 1) |
| 406 |
gLibMessages.filePromptFailedMsg(result[2]); |
| 407 |
else |
| 408 |
gLibMessages.filePromptFailed(); |
| 409 |
break; |
| 410 |
|
| 411 |
case InFileCancel: |
| 412 |
/* acknowledge the cancellation */ |
| 413 |
gLibMessages.restoreCanceled(); |
| 414 |
break; |
| 415 |
} |
| 416 |
|
| 417 |
/* |
| 418 |
* If we were successful, clear out the AGAIN memory. This |
| 419 |
* avoids any confusion about whether we're repeating the RESTORE |
| 420 |
* command itself, the command just before RESTORE from the |
| 421 |
* current session, or the last command before SAVE from the |
| 422 |
* restored game. |
| 423 |
*/ |
| 424 |
if (succ) |
| 425 |
AgainAction.clearForAgain(); |
| 426 |
|
| 427 |
/* return the success/failure indication */ |
| 428 |
return succ; |
| 429 |
} |
| 430 |
|
| 431 |
/* |
| 432 |
* Restore a game on startup. This can be called from mainRestore() |
| 433 |
* to restore a saved game directly as part of loading the game. |
| 434 |
* (Most interpreters provide a way of starting the interpreter |
| 435 |
* directly with a saved game to be restored, skipping the |
| 436 |
* intermediate step of running the game and using a RESTORE |
| 437 |
* command.) |
| 438 |
* |
| 439 |
* Returns true on success, nil on failure. On failure, the caller |
| 440 |
* should simply exit the program. On success, the caller should |
| 441 |
* start the game running, usually using runGame(), after showing any |
| 442 |
* desired introductory messages. |
| 443 |
*/ |
| 444 |
startupRestore(fname) |
| 445 |
{ |
| 446 |
/* |
| 447 |
* try restoring the game, using code 1 to indicate that this is |
| 448 |
* a direct startup restore |
| 449 |
*/ |
| 450 |
if (performRestore(fname, 1)) |
| 451 |
{ |
| 452 |
/* success - tell the caller to proceed with the restored game */ |
| 453 |
return true; |
| 454 |
} |
| 455 |
else |
| 456 |
{ |
| 457 |
/* |
| 458 |
* Failure. We've described the problem, so ask the user |
| 459 |
* what they want to do about it. |
| 460 |
*/ |
| 461 |
try |
| 462 |
{ |
| 463 |
/* show options and read the response */ |
| 464 |
failedRestoreOptions(); |
| 465 |
|
| 466 |
/* if we get here, proceed with the game */ |
| 467 |
return true; |
| 468 |
} |
| 469 |
catch (QuittingException qe) |
| 470 |
{ |
| 471 |
/* quitting - tell the caller to terminate */ |
| 472 |
return nil; |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
/* |
| 479 |
* Restore a file. 'code' is the restoreCode value for the |
| 480 |
* PostRestoreObject notifications. Returns true on success, nil on |
| 481 |
* failure. |
| 482 |
*/ |
| 483 |
performRestore(fname, code) |
| 484 |
{ |
| 485 |
try |
| 486 |
{ |
| 487 |
/* restore the file */ |
| 488 |
restoreGame(fname); |
| 489 |
} |
| 490 |
catch (StorageServerError sse) |
| 491 |
{ |
| 492 |
/* failed due to a storage server error - explain the problem */ |
| 493 |
gLibMessages.restoreFailedOnServer(sse); |
| 494 |
|
| 495 |
/* indicate failure */ |
| 496 |
return nil; |
| 497 |
} |
| 498 |
catch (RuntimeError err) |
| 499 |
{ |
| 500 |
/* failed - check the error to see what went wrong */ |
| 501 |
switch(err.errno_) |
| 502 |
{ |
| 503 |
case 1201: |
| 504 |
/* not a saved state file */ |
| 505 |
gLibMessages.restoreInvalidFile(); |
| 506 |
break; |
| 507 |
|
| 508 |
case 1202: |
| 509 |
/* saved by different game or different version */ |
| 510 |
gLibMessages.restoreInvalidMatch(); |
| 511 |
break; |
| 512 |
|
| 513 |
case 1207: |
| 514 |
/* corrupted saved state file */ |
| 515 |
gLibMessages.restoreCorruptedFile(); |
| 516 |
break; |
| 517 |
|
| 518 |
default: |
| 519 |
/* some other failure */ |
| 520 |
gLibMessages.restoreFailed(err); |
| 521 |
break; |
| 522 |
} |
| 523 |
|
| 524 |
/* indicate failure */ |
| 525 |
return nil; |
| 526 |
} |
| 527 |
|
| 528 |
/* note that we've successfully restored the game */ |
| 529 |
gLibMessages.restoreOkay(); |
| 530 |
|
| 531 |
/* set the appropriate restore-action code */ |
| 532 |
PostRestoreObject.restoreCode = code; |
| 533 |
|
| 534 |
/* notify all PostRestoreObject instances */ |
| 535 |
PostRestoreObject.classExec(); |
| 536 |
|
| 537 |
/* |
| 538 |
* look around, to refresh the player's memory of the state the |
| 539 |
* game was in when saved |
| 540 |
*/ |
| 541 |
"\b"; |
| 542 |
libGlobal.playerChar.lookAround(true); |
| 543 |
|
| 544 |
/* indicate success */ |
| 545 |
return true; |
| 546 |
} |
| 547 |
|
| 548 |
/* |
| 549 |
* There's no point in including this in undo. If the command |
| 550 |
* succeeds, it's not undoable itself, and there won't be any undo |
| 551 |
* information in the newly restored state. If the command fails, it |
| 552 |
* won't make any changes to the game state, so there won't be |
| 553 |
* anything to undo. |
| 554 |
*/ |
| 555 |
includeInUndo = nil |
| 556 |
; |
| 557 |
|
| 558 |
/* |
| 559 |
* Subclass of Restore action that takes a literal string as part of the |
| 560 |
* command. The filename must be a literal enclosed in quotes, and the |
| 561 |
* string (with the quotes) must be stored in our fname_ property by |
| 562 |
* assignment of a quotedStringPhrase production in the grammar rule. |
| 563 |
*/ |
| 564 |
DefineAction(RestoreString, RestoreAction) |
| 565 |
execSystemAction() |
| 566 |
{ |
| 567 |
/* |
| 568 |
* Perform the restore, using the filename given in our fname_ |
| 569 |
* parameter, trimmed of quotes. Use code 2, the same as any |
| 570 |
* other explicit RESTORE command. |
| 571 |
*/ |
| 572 |
performRestore(fname_.getStringText(), 2); |
| 573 |
|
| 574 |
/* abandon any additional commands on the same command line */ |
| 575 |
throw new TerminateCommandException(); |
| 576 |
} |
| 577 |
; |
| 578 |
|
| 579 |
/* ------------------------------------------------------------------------ */ |
| 580 |
/* |
| 581 |
* Restart the game from the beginning. |
| 582 |
*/ |
| 583 |
DefineSystemAction(Restart) |
| 584 |
execSystemAction() |
| 585 |
{ |
| 586 |
/* confirm that they really want to restart */ |
| 587 |
gLibMessages.confirmRestart(); |
| 588 |
if (yesOrNo()) |
| 589 |
{ |
| 590 |
/* |
| 591 |
* The confirmation input will have put us into |
| 592 |
* start-of-command mode for sequencing purposes; force the |
| 593 |
* sequencer back to mid-command mode, so we can show |
| 594 |
* inter-command separation before the restart. |
| 595 |
*/ |
| 596 |
|
| 597 |
/* restart the game */ |
| 598 |
doRestartGame(); |
| 599 |
} |
| 600 |
else |
| 601 |
{ |
| 602 |
/* confirm that we're not really restarting */ |
| 603 |
gLibMessages.notRestarting(); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
/* carry out the restart action */ |
| 608 |
doRestartGame() |
| 609 |
{ |
| 610 |
/* |
| 611 |
* Show a command separator, to provide separation from any |
| 612 |
* introductory text that we'll show on restarting. Note that |
| 613 |
* we probably just asked for confirmation, which means that the |
| 614 |
* command sequencer will be in start-of-command mode; force it |
| 615 |
* back to mid-command mode so we show inter-command separation. |
| 616 |
*/ |
| 617 |
commandSequencer.setCommandMode(); |
| 618 |
"<.commandsep>"; |
| 619 |
|
| 620 |
/* before restarting, notify anyone interested of our intentions */ |
| 621 |
PreRestartObject.classExec(); |
| 622 |
|
| 623 |
/* |
| 624 |
* Throw a 'restart' signal; the main entrypoint loop will catch |
| 625 |
* this and actually perform the restart. |
| 626 |
* |
| 627 |
* Note that we *could* do the VM reset (via restartGame()) here, |
| 628 |
* but there's an advantage to doing it in the main loop: we |
| 629 |
* won't be in the stack context of whatever command we're |
| 630 |
* performing. If we did the restart here, it's possible that |
| 631 |
* some useless objects would survive the VM reset just because |
| 632 |
* they're referenced from within a caller's stack frame. Those |
| 633 |
* objects would immediately go out of scope when we get back to |
| 634 |
* the main loop, but they might survive long enough to create |
| 635 |
* apparent inconsistencies. In particular, if we did a |
| 636 |
* firstObj/nextObj loop, we could discover those objects and |
| 637 |
* re-establish more lasting references to them, which we |
| 638 |
* certainly don't want to do. By deferring the VM reset until |
| 639 |
* we get back to the main loop, we'll ensure that objects won't |
| 640 |
* survive the reset just because they're on the stack |
| 641 |
* momentarily here. |
| 642 |
*/ |
| 643 |
throw new RestartSignal(); |
| 644 |
} |
| 645 |
|
| 646 |
/* there's no point in including this in undo */ |
| 647 |
includeInUndo = nil |
| 648 |
; |
| 649 |
|
| 650 |
/* ------------------------------------------------------------------------ */ |
| 651 |
/* |
| 652 |
* Undo one turn. |
| 653 |
*/ |
| 654 |
DefineSystemAction(Undo) |
| 655 |
/* |
| 656 |
* "Undo" is so special that we must override the entire action |
| 657 |
* processing sequence. We do this because undoing will restore the |
| 658 |
* game state as of the previous savepoint, which would leave all |
| 659 |
* sorts of things unsynchronized in the normal action sequence. To |
| 660 |
* avoid problems, we simply leave out any other action processing |
| 661 |
* and perform the 'undo' directly. |
| 662 |
*/ |
| 663 |
doAction(issuingActor, targetActor, targetActorPhrase, |
| 664 |
countsAsIssuerTurn) |
| 665 |
{ |
| 666 |
/* |
| 667 |
* the player obviously knows about UNDO, so there's no need for |
| 668 |
* a tip about it |
| 669 |
*/ |
| 670 |
undoTip.makeShown(); |
| 671 |
|
| 672 |
/* |
| 673 |
* don't allow this unless the player character is performing |
| 674 |
* the command directly |
| 675 |
*/ |
| 676 |
if (!targetActor.isPlayerChar) |
| 677 |
{ |
| 678 |
/* |
| 679 |
* tell them this command cannot be directed to another |
| 680 |
* actor, and give up |
| 681 |
*/ |
| 682 |
gLibMessages.systemActionToNPC(); |
| 683 |
return; |
| 684 |
} |
| 685 |
|
| 686 |
/* perform the undo */ |
| 687 |
performUndo(true); |
| 688 |
} |
| 689 |
|
| 690 |
/* |
| 691 |
* Perform undo. Returns true if we were successful, nil if not. |
| 692 |
* |
| 693 |
* 'asCommand' indicates whether or not the undo is being performed |
| 694 |
* as an explicit command: if so, we'll save the UNDO command for use |
| 695 |
* in AGAIN. |
| 696 |
*/ |
| 697 |
performUndo(asCommand) |
| 698 |
{ |
| 699 |
/* try undoing to the previous savepoint */ |
| 700 |
if (undo()) |
| 701 |
{ |
| 702 |
local oldActor; |
| 703 |
local oldIssuer; |
| 704 |
local oldAction; |
| 705 |
|
| 706 |
/* notify all PostUndoObject instances */ |
| 707 |
PostUndoObject.classExec(); |
| 708 |
|
| 709 |
/* set up the globals for the command */ |
| 710 |
oldActor = gActor; |
| 711 |
oldIssuer = gIssuingActor; |
| 712 |
oldAction = gAction; |
| 713 |
|
| 714 |
/* set the new globals */ |
| 715 |
gActor = gPlayerChar; |
| 716 |
gIssuingActor = gPlayerChar; |
| 717 |
gAction = self; |
| 718 |
|
| 719 |
/* make sure we reset globals on the way out */ |
| 720 |
try |
| 721 |
{ |
| 722 |
/* success - mention what we did */ |
| 723 |
gLibMessages.undoOkay(libGlobal.lastActorForUndo, |
| 724 |
libGlobal.lastCommandForUndo); |
| 725 |
|
| 726 |
/* look around, to refresh the player's memory */ |
| 727 |
libGlobal.playerChar.lookAround(true); |
| 728 |
} |
| 729 |
finally |
| 730 |
{ |
| 731 |
/* restore the parser globals to how we found them */ |
| 732 |
gActor = oldActor; |
| 733 |
gIssuingActor = oldIssuer; |
| 734 |
gAction = oldAction; |
| 735 |
} |
| 736 |
|
| 737 |
/* |
| 738 |
* if this was an explicit 'undo' command, save the command |
| 739 |
* to allow repeating it with 'again' |
| 740 |
*/ |
| 741 |
if (asCommand) |
| 742 |
AgainAction.saveForAgain(gPlayerChar, gPlayerChar, nil, self); |
| 743 |
|
| 744 |
/* indicate success */ |
| 745 |
return true; |
| 746 |
} |
| 747 |
else |
| 748 |
{ |
| 749 |
/* no more undo information available */ |
| 750 |
gLibMessages.undoFailed(); |
| 751 |
|
| 752 |
/* indicate failure */ |
| 753 |
return nil; |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
/* |
| 758 |
* "undo" is not undoable - if we undo again after an undo, we undo |
| 759 |
* the next most recent command |
| 760 |
*/ |
| 761 |
includeInUndo = nil |
| 762 |
; |
| 763 |
|
| 764 |
/* ------------------------------------------------------------------------ */ |
| 765 |
/* |
| 766 |
* Save the defaults |
| 767 |
*/ |
| 768 |
DefineSystemAction(SaveDefaults) |
| 769 |
execSystemAction() |
| 770 |
{ |
| 771 |
/* tell SettingsItem to save all settings */ |
| 772 |
settingsUI.saveSettingsMsg(); |
| 773 |
} |
| 774 |
|
| 775 |
/* there's no point in including this in undo */ |
| 776 |
includeInUndo = nil |
| 777 |
; |
| 778 |
|
| 779 |
/* |
| 780 |
* Restore defaults |
| 781 |
*/ |
| 782 |
DefineSystemAction(RestoreDefaults) |
| 783 |
execSystemAction() |
| 784 |
{ |
| 785 |
/* |
| 786 |
* Tell SettingsItem to restore all settings. This is an |
| 787 |
* explicit request, so we want SettingsItem to describe what |
| 788 |
* happened. |
| 789 |
*/ |
| 790 |
settingsUI.restoreSettingsMsg(); |
| 791 |
} |
| 792 |
|
| 793 |
/* there's no point in including this in undo */ |
| 794 |
includeInUndo = nil |
| 795 |
; |
| 796 |
|
| 797 |
|
| 798 |
/* ------------------------------------------------------------------------ */ |
| 799 |
/* |
| 800 |
* Quit the game. |
| 801 |
*/ |
| 802 |
DefineSystemAction(Quit) |
| 803 |
execSystemAction() |
| 804 |
{ |
| 805 |
/* confirm that they really want to quit */ |
| 806 |
gLibMessages.confirmQuit(); |
| 807 |
if (yesOrNo()) |
| 808 |
{ |
| 809 |
/* carry out the termination */ |
| 810 |
terminateGame(); |
| 811 |
} |
| 812 |
else |
| 813 |
{ |
| 814 |
/* show the confirmation that we're not quitting */ |
| 815 |
gLibMessages.notTerminating(); |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
/* |
| 820 |
* Carry out game termination. This can be called when we wish to |
| 821 |
* end the game without asking for any additional player |
| 822 |
* confirmation. |
| 823 |
*/ |
| 824 |
terminateGame() |
| 825 |
{ |
| 826 |
/* acknowledge that we're quitting */ |
| 827 |
gLibMessages.okayQuitting(); |
| 828 |
|
| 829 |
/* throw a 'quitting' signal to end the game */ |
| 830 |
throw new QuittingException; |
| 831 |
} |
| 832 |
|
| 833 |
/* there's no point in including this in undo */ |
| 834 |
includeInUndo = nil |
| 835 |
; |
| 836 |
|
| 837 |
/* |
| 838 |
* Pause the game. This stops the real-time clock until the user |
| 839 |
* presses a key. Games that don't use the real-time clock will have no |
| 840 |
* use for this. |
| 841 |
*/ |
| 842 |
DefineSystemAction(Pause) |
| 843 |
execSystemAction() |
| 844 |
{ |
| 845 |
local elapsed; |
| 846 |
|
| 847 |
/* |
| 848 |
* remember the current elapsed game real time - when we are |
| 849 |
* released from the pause, we'll restore this time |
| 850 |
*/ |
| 851 |
elapsed = realTimeManager.getElapsedTime(); |
| 852 |
|
| 853 |
/* show our prompt */ |
| 854 |
gLibMessages.pausePrompt(); |
| 855 |
|
| 856 |
/* keep going until we're released */ |
| 857 |
waitLoop: |
| 858 |
for (;;) |
| 859 |
{ |
| 860 |
/* |
| 861 |
* Wait for a key, and see what we have. Note that we |
| 862 |
* explicitly do not want to allow any real-time events to |
| 863 |
* occur, so we simply wait forever without timeout. |
| 864 |
*/ |
| 865 |
switch(inputKey()) |
| 866 |
{ |
| 867 |
case ' ': |
| 868 |
/* space key - end the wait */ |
| 869 |
break waitLoop; |
| 870 |
|
| 871 |
case 's': |
| 872 |
case 'S': |
| 873 |
/* mention that we're saving */ |
| 874 |
gLibMessages.pauseSaving(); |
| 875 |
|
| 876 |
/* |
| 877 |
* set the elapsed time to the time when we started, so |
| 878 |
* that the saved position reflects the time at the |
| 879 |
* start of the pause |
| 880 |
*/ |
| 881 |
realTimeManager.setElapsedTime(elapsed); |
| 882 |
|
| 883 |
/* save the game - go run the normal SAVE command */ |
| 884 |
SaveAction.execSystemAction(); |
| 885 |
|
| 886 |
/* show our prompt again */ |
| 887 |
"<.p>"; |
| 888 |
gLibMessages.pausePrompt(); |
| 889 |
|
| 890 |
/* go back to wait for another key */ |
| 891 |
break; |
| 892 |
|
| 893 |
case '[eof]': |
| 894 |
/* end-of-file on keyboard input - throw an error */ |
| 895 |
"\b"; |
| 896 |
throw new EndOfFileException(); |
| 897 |
|
| 898 |
default: |
| 899 |
/* ignore other keys; just go back to wait again */ |
| 900 |
break; |
| 901 |
} |
| 902 |
} |
| 903 |
|
| 904 |
/* show the released-from-pause message */ |
| 905 |
gLibMessages.pauseEnded(); |
| 906 |
|
| 907 |
/* |
| 908 |
* set the real-time clock to the same elapsed game time |
| 909 |
* that we had when we started the pause, so that the |
| 910 |
* elapsed real time of the pause itself doesn't count |
| 911 |
* against the game elapsed time |
| 912 |
*/ |
| 913 |
realTimeManager.setElapsedTime(elapsed); |
| 914 |
} |
| 915 |
; |
| 916 |
|
| 917 |
/* |
| 918 |
* Change to VERBOSE mode. |
| 919 |
*/ |
| 920 |
DefineSystemAction(Verbose) |
| 921 |
execSystemAction() |
| 922 |
{ |
| 923 |
/* set the global 'verbose' mode */ |
| 924 |
gameMain.verboseMode.isOn = true; |
| 925 |
|
| 926 |
/* acknowledge it */ |
| 927 |
gLibMessages.acknowledgeVerboseMode(true); |
| 928 |
} |
| 929 |
; |
| 930 |
|
| 931 |
/* |
| 932 |
* Change to TERSE mode. |
| 933 |
*/ |
| 934 |
DefineSystemAction(Terse) |
| 935 |
execSystemAction() |
| 936 |
{ |
| 937 |
/* set the global 'verbose' mode */ |
| 938 |
gameMain.verboseMode.isOn = nil; |
| 939 |
|
| 940 |
/* acknowledge it */ |
| 941 |
gLibMessages.acknowledgeVerboseMode(nil); |
| 942 |
} |
| 943 |
; |
| 944 |
|
| 945 |
/* in case the score module isn't present */ |
| 946 |
property showScore; |
| 947 |
property showFullScore; |
| 948 |
property scoreNotify; |
| 949 |
|
| 950 |
/* |
| 951 |
* Show the current score. |
| 952 |
*/ |
| 953 |
DefineSystemAction(Score) |
| 954 |
execSystemAction() |
| 955 |
{ |
| 956 |
/* show the simple score */ |
| 957 |
if (libGlobal.scoreObj != nil) |
| 958 |
{ |
| 959 |
/* show the score */ |
| 960 |
libGlobal.scoreObj.showScore(); |
| 961 |
|
| 962 |
/* |
| 963 |
* Mention the FULL SCORE command to the player if we haven't |
| 964 |
* already. Note that we only want to mention |
| 965 |
*/ |
| 966 |
if (!mentionedFullScore) |
| 967 |
{ |
| 968 |
/* explain about it */ |
| 969 |
gLibMessages.mentionFullScore; |
| 970 |
|
| 971 |
/* don't mention it again */ |
| 972 |
ScoreAction.mentionedFullScore = true; |
| 973 |
} |
| 974 |
} |
| 975 |
else |
| 976 |
gLibMessages.scoreNotPresent; |
| 977 |
} |
| 978 |
|
| 979 |
/* there's no point in including this in undo */ |
| 980 |
includeInUndo = nil |
| 981 |
|
| 982 |
/* have we mentioned the FULL SCORE command yet? */ |
| 983 |
mentionedFullScore = nil |
| 984 |
; |
| 985 |
|
| 986 |
/* |
| 987 |
* Show the full score. |
| 988 |
*/ |
| 989 |
DefineSystemAction(FullScore) |
| 990 |
execSystemAction() |
| 991 |
{ |
| 992 |
/* show the full score in response to an explicit player request */ |
| 993 |
showFullScore(); |
| 994 |
|
| 995 |
/* this counts as a mention of the FULL SCORE command */ |
| 996 |
ScoreAction.mentionedFullScore = true; |
| 997 |
} |
| 998 |
|
| 999 |
/* show the full score */ |
| 1000 |
showFullScore() |
| 1001 |
{ |
| 1002 |
/* show the full score */ |
| 1003 |
if (libGlobal.scoreObj != nil) |
| 1004 |
libGlobal.scoreObj.showFullScore(); |
| 1005 |
else |
| 1006 |
gLibMessages.scoreNotPresent; |
| 1007 |
} |
| 1008 |
|
| 1009 |
/* there's no point in including this in undo */ |
| 1010 |
includeInUndo = nil |
| 1011 |
; |
| 1012 |
|
| 1013 |
/* |
| 1014 |
* Show the NOTIFY status. |
| 1015 |
*/ |
| 1016 |
DefineSystemAction(Notify) |
| 1017 |
execSystemAction() |
| 1018 |
{ |
| 1019 |
/* show the current notification status */ |
| 1020 |
if (libGlobal.scoreObj != nil) |
| 1021 |
gLibMessages.showNotifyStatus( |
| 1022 |
libGlobal.scoreObj.scoreNotify.isOn); |
| 1023 |
else |
| 1024 |
gLibMessages.commandNotPresent; |
| 1025 |
} |
| 1026 |
; |
| 1027 |
|
| 1028 |
/* |
| 1029 |
* Turn score change notifications on. |
| 1030 |
*/ |
| 1031 |
DefineSystemAction(NotifyOn) |
| 1032 |
execSystemAction() |
| 1033 |
{ |
| 1034 |
/* turn notifications on, and acknowledge the status */ |
| 1035 |
if (libGlobal.scoreObj != nil) |
| 1036 |
{ |
| 1037 |
libGlobal.scoreObj.scoreNotify.isOn = true; |
| 1038 |
gLibMessages.acknowledgeNotifyStatus(true); |
| 1039 |
} |
| 1040 |
else |
| 1041 |
gLibMessages.commandNotPresent; |
| 1042 |
} |
| 1043 |
; |
| 1044 |
|
| 1045 |
/* |
| 1046 |
* Turn score change notifications off. |
| 1047 |
*/ |
| 1048 |
DefineSystemAction(NotifyOff) |
| 1049 |
execSystemAction() |
| 1050 |
{ |
| 1051 |
/* turn notifications off, and acknowledge the status */ |
| 1052 |
if (libGlobal.scoreObj != nil) |
| 1053 |
{ |
| 1054 |
libGlobal.scoreObj.scoreNotify.isOn = nil; |
| 1055 |
gLibMessages.acknowledgeNotifyStatus(nil); |
| 1056 |
} |
| 1057 |
else |
| 1058 |
gLibMessages.commandNotPresent; |
| 1059 |
} |
| 1060 |
; |
| 1061 |
|
| 1062 |
/* |
| 1063 |
* Show version information for the game and the library modules the |
| 1064 |
* game is using. |
| 1065 |
*/ |
| 1066 |
DefineSystemAction(Version) |
| 1067 |
execSystemAction() |
| 1068 |
{ |
| 1069 |
/* show the version information for each library */ |
| 1070 |
foreach (local cur in ModuleID.getModuleList()) |
| 1071 |
cur.showVersion(); |
| 1072 |
} |
| 1073 |
|
| 1074 |
/* there's no point in including this in undo */ |
| 1075 |
includeInUndo = nil |
| 1076 |
; |
| 1077 |
|
| 1078 |
/* |
| 1079 |
* Show the credits for the game and the library modules the game |
| 1080 |
* includes. |
| 1081 |
*/ |
| 1082 |
DefineSystemAction(Credits) |
| 1083 |
execSystemAction() |
| 1084 |
{ |
| 1085 |
/* show the credits for each library */ |
| 1086 |
foreach (local cur in ModuleID.getModuleList()) |
| 1087 |
cur.showCredit(); |
| 1088 |
} |
| 1089 |
|
| 1090 |
/* there's no point in including this in undo */ |
| 1091 |
includeInUndo = nil |
| 1092 |
; |
| 1093 |
|
| 1094 |
/* |
| 1095 |
* Show the "about" information for the game and library modules. |
| 1096 |
*/ |
| 1097 |
DefineSystemAction(About) |
| 1098 |
execSystemAction() |
| 1099 |
{ |
| 1100 |
local anyOutput; |
| 1101 |
|
| 1102 |
/* watch for any output while showing module information */ |
| 1103 |
anyOutput = outputManager.curOutputStream |
| 1104 |
.watchForOutput(function() |
| 1105 |
{ |
| 1106 |
/* show information for each module */ |
| 1107 |
foreach (local cur in ModuleID.getModuleList()) |
| 1108 |
cur.showAbout(); |
| 1109 |
}); |
| 1110 |
|
| 1111 |
/* |
| 1112 |
* if we didn't have any ABOUT information to show, display a |
| 1113 |
* message to this effect |
| 1114 |
*/ |
| 1115 |
if (!anyOutput) |
| 1116 |
gLibMessages.noAboutInfo; |
| 1117 |
} |
| 1118 |
|
| 1119 |
/* there's no point in including this in undo */ |
| 1120 |
includeInUndo = nil |
| 1121 |
; |
| 1122 |
|
| 1123 |
/* |
| 1124 |
* A state object that keeps track of our logging (scripting) status. |
| 1125 |
* This is transient, because logging is controlled through the output |
| 1126 |
* layer in the interpreter, which does not participate in any of the |
| 1127 |
* persistence mechanisms. |
| 1128 |
*/ |
| 1129 |
transient scriptStatus: object |
| 1130 |
/* |
| 1131 |
* Script file name. This is nil when logging is not in effect, and |
| 1132 |
* is set to the name of the scripting file when a log file is |
| 1133 |
* active. |
| 1134 |
*/ |
| 1135 |
scriptFile = nil |
| 1136 |
|
| 1137 |
/* RECORD file name */ |
| 1138 |
recordFile = nil |
| 1139 |
|
| 1140 |
/* have we warned about using NOTE without logging in effect? */ |
| 1141 |
noteWithoutScriptWarning = nil |
| 1142 |
; |
| 1143 |
|
| 1144 |
/* |
| 1145 |
* Property: object is a web temp file. The Web UI uses this to flag |
| 1146 |
* that a file we're saving to is actually a temp file that will be |
| 1147 |
* offered as a downloadable file to the client after the file is written |
| 1148 |
* and closed. |
| 1149 |
*/ |
| 1150 |
property isWebTempFile; |
| 1151 |
|
| 1152 |
/* |
| 1153 |
* A base class for file-oriented actions, such as SCRIPT, RECORD, and |
| 1154 |
* REPLAY. We provide common handling that prompts interactively for a |
| 1155 |
* filename; subclasses must override a few methods and properties to |
| 1156 |
* carry out the specific subclassed operation on the file. |
| 1157 |
*/ |
| 1158 |
DefineSystemAction(FileOp) |
| 1159 |
/* our file dialog prompt message */ |
| 1160 |
filePromptMsg = '' |
| 1161 |
|
| 1162 |
/* the file dialog open/save type */ |
| 1163 |
fileDisposition = InFileSave |
| 1164 |
|
| 1165 |
/* the file dialog type ID */ |
| 1166 |
fileTypeID = FileTypeLog |
| 1167 |
|
| 1168 |
/* show our cancellation mesage */ |
| 1169 |
showCancelMsg = "" |
| 1170 |
|
| 1171 |
/* |
| 1172 |
* Carry out our file operation. |
| 1173 |
* |
| 1174 |
* 'desc' is an optional named argument giving a description string |
| 1175 |
* entered by the user via the Save Game dialog. Some versions of |
| 1176 |
* the Save Game dialog let the user enter this additional |
| 1177 |
* information, which can be stored as part of the saved game |
| 1178 |
* metadata. |
| 1179 |
*/ |
| 1180 |
performFileOp(fname, ack, desc:?) |
| 1181 |
{ |
| 1182 |
/* |
| 1183 |
* Each concrete action subclass must override this to carry out |
| 1184 |
* our operation. This is called when the user has successfully |
| 1185 |
* selected a filename for the operation. |
| 1186 |
*/ |
| 1187 |
} |
| 1188 |
|
| 1189 |
execSystemAction() |
| 1190 |
{ |
| 1191 |
/* |
| 1192 |
* ask for a file and carry out our action; since the command is |
| 1193 |
* being performed directly from the command line, we want an |
| 1194 |
* acknowledgment message on success |
| 1195 |
*/ |
| 1196 |
setUpFileOp(true); |
| 1197 |
} |
| 1198 |
|
| 1199 |
/* ask for a file, and carry out our operation is we get one */ |
| 1200 |
setUpFileOp(ack) |
| 1201 |
{ |
| 1202 |
local result; |
| 1203 |
local origElapsedTime; |
| 1204 |
|
| 1205 |
/* note the current game time */ |
| 1206 |
origElapsedTime = realTimeManager.getElapsedTime(); |
| 1207 |
|
| 1208 |
/* ask for a file */ |
| 1209 |
result = getInputFile(filePromptMsg, fileDisposition, fileTypeID, 0); |
| 1210 |
|
| 1211 |
/* check the inputFile result */ |
| 1212 |
switch(result[1]) |
| 1213 |
{ |
| 1214 |
case InFileSuccess: |
| 1215 |
/* carry out our file operation */ |
| 1216 |
if (result.length >= 3) |
| 1217 |
performFileOp(result[2], ack, desc:result[3]); |
| 1218 |
else |
| 1219 |
performFileOp(result[2], ack); |
| 1220 |
break; |
| 1221 |
|
| 1222 |
case InFileFailure: |
| 1223 |
/* advise of the failure of the prompt */ |
| 1224 |
if (result.length() > 1) |
| 1225 |
gLibMessages.filePromptFailedMsg(result[2]); |
| 1226 |
else |
| 1227 |
gLibMessages.filePromptFailed(); |
| 1228 |
break; |
| 1229 |
|
| 1230 |
case InFileCancel: |
| 1231 |
/* acknowledge the cancellation */ |
| 1232 |
showCancelMsg(); |
| 1233 |
break; |
| 1234 |
} |
| 1235 |
|
| 1236 |
/* |
| 1237 |
* restore the original elapsed game time, so that the time spent |
| 1238 |
* in the file selector dialog doesn't count against the game |
| 1239 |
* time |
| 1240 |
*/ |
| 1241 |
realTimeManager.setElapsedTime(origElapsedTime); |
| 1242 |
} |
| 1243 |
|
| 1244 |
/* we can't include this in undo, as it affects external files */ |
| 1245 |
includeInUndo = nil |
| 1246 |
|
| 1247 |
/* don't allow repeating with AGAIN */ |
| 1248 |
isRepeatable = nil |
| 1249 |
; |
| 1250 |
|
| 1251 |
/* |
| 1252 |
* Turn scripting on. This creates a text file that contains a |
| 1253 |
* transcript of all commands and responses from this point forward. |
| 1254 |
*/ |
| 1255 |
DefineAction(Script, FileOpAction) |
| 1256 |
/* our file dialog parameters - ask for a log file to save */ |
| 1257 |
filePromptMsg = (gLibMessages.getScriptingPrompt()) |
| 1258 |
fileTypeID = FileTypeLog |
| 1259 |
fileDisposition = InFileSave |
| 1260 |
|
| 1261 |
/* show our cancellation mesasge */ |
| 1262 |
showCancelMsg() { gLibMessages.scriptingCanceled(); } |
| 1263 |
|
| 1264 |
/* |
| 1265 |
* set up scripting - this can be used to set up scripting |
| 1266 |
* programmatically, in the course of carrying out another action |
| 1267 |
*/ |
| 1268 |
setUpScripting(ack) { setUpFileOp(ack); } |
| 1269 |
|
| 1270 |
/* turn on scripting to the given file */ |
| 1271 |
performFileOp(fname, ack) |
| 1272 |
{ |
| 1273 |
/* turn on logging */ |
| 1274 |
local ok = nil, exc = nil; |
| 1275 |
try |
| 1276 |
{ |
| 1277 |
ok = aioSetLogFile(fname, LogTypeTranscript); |
| 1278 |
} |
| 1279 |
catch (Exception e) |
| 1280 |
{ |
| 1281 |
exc = e; |
| 1282 |
} |
| 1283 |
if (ok) |
| 1284 |
{ |
| 1285 |
/* remember that scripting is in effect */ |
| 1286 |
scriptStatus.scriptFile = fname; |
| 1287 |
|
| 1288 |
/* |
| 1289 |
* forget any past warning that we've issued about NOTE |
| 1290 |
* without a script in effect; the next time scripting isn't |
| 1291 |
* active, we'll want to issue a new warning, since they |
| 1292 |
* might not be aware at that point that the scripting we're |
| 1293 |
* starting now has ended |
| 1294 |
*/ |
| 1295 |
scriptStatus.noteWithoutScriptWarning = nil; |
| 1296 |
|
| 1297 |
/* note that logging is active, if acknowledgment is desired */ |
| 1298 |
if (ack) |
| 1299 |
{ |
| 1300 |
if (fname.isWebTempFile) |
| 1301 |
gLibMessages.scriptingOkayWebTemp(); |
| 1302 |
else |
| 1303 |
gLibMessages.scriptingOkay(); |
| 1304 |
} |
| 1305 |
} |
| 1306 |
else |
| 1307 |
{ |
| 1308 |
/* scripting is no longer in effect */ |
| 1309 |
scriptStatus.scriptFile = nil; |
| 1310 |
|
| 1311 |
/* show an error, if acknowledgment is desired */ |
| 1312 |
if (ack) |
| 1313 |
{ |
| 1314 |
if (exc != nil) |
| 1315 |
gLibMessages.scriptingFailedException(exc); |
| 1316 |
else |
| 1317 |
gLibMessages.scriptingFailed; |
| 1318 |
} |
| 1319 |
} |
| 1320 |
} |
| 1321 |
; |
| 1322 |
|
| 1323 |
/* |
| 1324 |
* Subclass of Script action taking a quoted string as part of the |
| 1325 |
* command syntax. The grammar rule must set our fname_ property to a |
| 1326 |
* quotedStringPhrase subproduction. |
| 1327 |
*/ |
| 1328 |
DefineAction(ScriptString, ScriptAction) |
| 1329 |
execSystemAction() |
| 1330 |
{ |
| 1331 |
/* if there's a filename, we don't need to prompt */ |
| 1332 |
if (fname_ != nil) |
| 1333 |
{ |
| 1334 |
/* set up scripting to the filename specified in the command */ |
| 1335 |
performFileOp(fname_.getStringText(), true); |
| 1336 |
} |
| 1337 |
else |
| 1338 |
{ |
| 1339 |
/* there's no filename, so prompt as usual */ |
| 1340 |
inherited(); |
| 1341 |
} |
| 1342 |
} |
| 1343 |
; |
| 1344 |
|
| 1345 |
/* |
| 1346 |
* Turn scripting off. This stops recording the game transcript started |
| 1347 |
* with the most recent SCRIPT command. |
| 1348 |
*/ |
| 1349 |
DefineSystemAction(ScriptOff) |
| 1350 |
execSystemAction() |
| 1351 |
{ |
| 1352 |
/* turn off scripting */ |
| 1353 |
turnOffScripting(true); |
| 1354 |
} |
| 1355 |
|
| 1356 |
/* turn off scripting */ |
| 1357 |
turnOffScripting(ack) |
| 1358 |
{ |
| 1359 |
/* if we're not in a script file, ignore it */ |
| 1360 |
if (scriptStatus.scriptFile == nil) |
| 1361 |
{ |
| 1362 |
gLibMessages.scriptOffIgnored(); |
| 1363 |
return; |
| 1364 |
} |
| 1365 |
|
| 1366 |
/* cancel scripting in the interpreter's output layer */ |
| 1367 |
aioSetLogFile(nil, LogTypeTranscript); |
| 1368 |
|
| 1369 |
/* remember that scripting is no longer in effect */ |
| 1370 |
scriptStatus.scriptFile = nil; |
| 1371 |
|
| 1372 |
/* acknowledge the change, if desired */ |
| 1373 |
if (ack) |
| 1374 |
gLibMessages.scriptOffOkay(); |
| 1375 |
} |
| 1376 |
|
| 1377 |
/* we can't include this in undo, as it affects external files */ |
| 1378 |
includeInUndo = nil |
| 1379 |
; |
| 1380 |
|
| 1381 |
/* |
| 1382 |
* RECORD - this is similar to SCRIPT, but stores a file containing only |
| 1383 |
* the command input, not the output. |
| 1384 |
*/ |
| 1385 |
DefineAction(Record, FileOpAction) |
| 1386 |
/* our file dialog parameters - ask for a log file to save */ |
| 1387 |
filePromptMsg = (gLibMessages.getRecordingPrompt()) |
| 1388 |
fileTypeID = FileTypeCmd |
| 1389 |
fileDisposition = InFileSave |
| 1390 |
|
| 1391 |
/* show our cancellation mesasge */ |
| 1392 |
showCancelMsg() { gLibMessages.recordingCanceled(); } |
| 1393 |
|
| 1394 |
/* |
| 1395 |
* set up recording - this can be used to set up scripting |
| 1396 |
* programmatically, in the course of carrying out another action |
| 1397 |
*/ |
| 1398 |
setUpRecording(ack) { setUpFileOp(ack); } |
| 1399 |
|
| 1400 |
/* turn on recording to the given file */ |
| 1401 |
performFileOp(fname, ack) |
| 1402 |
{ |
| 1403 |
/* turn on command logging */ |
| 1404 |
local ok = nil, exc = nil; |
| 1405 |
try |
| 1406 |
{ |
| 1407 |
ok = aioSetLogFile(fname, logFileType); |
| 1408 |
} |
| 1409 |
catch (Exception e) |
| 1410 |
{ |
| 1411 |
exc = e; |
| 1412 |
} |
| 1413 |
if (ok) |
| 1414 |
{ |
| 1415 |
/* remember that recording is in effect */ |
| 1416 |
scriptStatus.recordFile = fname; |
| 1417 |
|
| 1418 |
/* note that logging is active, if acknowledgment is desired */ |
| 1419 |
if (ack) |
| 1420 |
gLibMessages.recordingOkay(); |
| 1421 |
} |
| 1422 |
else |
| 1423 |
{ |
| 1424 |
/* recording failed */ |
| 1425 |
scriptStatus.recordFile = nil; |
| 1426 |
|
| 1427 |
/* show an error if acknowledgment is desired */ |
| 1428 |
if (ack) |
| 1429 |
{ |
| 1430 |
if (exc != nil) |
| 1431 |
gLibMessages.recordingFailedException(exc); |
| 1432 |
else |
| 1433 |
gLibMessages.recordingFailed(); |
| 1434 |
} |
| 1435 |
} |
| 1436 |
} |
| 1437 |
|
| 1438 |
/* the log file type - by default, we open a regular command log */ |
| 1439 |
logFileType = LogTypeCommand |
| 1440 |
; |
| 1441 |
|
| 1442 |
/* subclass of Record action that sets up an event script recording */ |
| 1443 |
DefineAction(RecordEvents, RecordAction) |
| 1444 |
logFileType = LogTypeScript |
| 1445 |
; |
| 1446 |
|
| 1447 |
/* subclass of Record action taking a quoted string for the filename */ |
| 1448 |
DefineAction(RecordString, RecordAction) |
| 1449 |
execSystemAction() |
| 1450 |
{ |
| 1451 |
/* set up scripting to the filename specified in the command */ |
| 1452 |
performFileOp(fname_.getStringText(), true); |
| 1453 |
} |
| 1454 |
; |
| 1455 |
|
| 1456 |
/* subclass of RecordString action that sets up an event script recording */ |
| 1457 |
DefineAction(RecordEventsString, RecordStringAction) |
| 1458 |
logFileType = LogTypeScript |
| 1459 |
; |
| 1460 |
|
| 1461 |
/* |
| 1462 |
* Turn command recording off. This stops recording the command log |
| 1463 |
* started with the most recent RECORD command. |
| 1464 |
*/ |
| 1465 |
DefineSystemAction(RecordOff) |
| 1466 |
execSystemAction() |
| 1467 |
{ |
| 1468 |
/* turn off recording */ |
| 1469 |
turnOffRecording(true); |
| 1470 |
} |
| 1471 |
|
| 1472 |
/* turn off recording */ |
| 1473 |
turnOffRecording(ack) |
| 1474 |
{ |
| 1475 |
/* if we're not recording anything, ignore it */ |
| 1476 |
if (scriptStatus.recordFile == nil) |
| 1477 |
{ |
| 1478 |
gLibMessages.recordOffIgnored(); |
| 1479 |
return; |
| 1480 |
} |
| 1481 |
|
| 1482 |
/* cancel recording in the interpreter's output layer */ |
| 1483 |
aioSetLogFile(nil, LogTypeCommand); |
| 1484 |
|
| 1485 |
/* remember that recording is no longer in effect */ |
| 1486 |
scriptStatus.recordFile = nil; |
| 1487 |
|
| 1488 |
/* acknowledge the change, if desired */ |
| 1489 |
if (ack) |
| 1490 |
gLibMessages.recordOffOkay(); |
| 1491 |
} |
| 1492 |
|
| 1493 |
/* we can't include this in undo, as it affects external files */ |
| 1494 |
includeInUndo = nil |
| 1495 |
; |
| 1496 |
|
| 1497 |
/* |
| 1498 |
* REPLAY - play back a command log previously recorded. |
| 1499 |
*/ |
| 1500 |
DefineAction(Replay, FileOpAction) |
| 1501 |
/* our file dialog parameters - ask for a log file to save */ |
| 1502 |
filePromptMsg = (gLibMessages.getReplayPrompt()) |
| 1503 |
fileTypeID = FileTypeCmd |
| 1504 |
fileDisposition = InFileOpen |
| 1505 |
|
| 1506 |
/* show our cancellation mesasge */ |
| 1507 |
showCancelMsg() { gLibMessages.replayCanceled(); } |
| 1508 |
|
| 1509 |
/* script flags passed to setScriptFile */ |
| 1510 |
scriptOptionFlags = 0 |
| 1511 |
|
| 1512 |
/* replay the given file */ |
| 1513 |
performFileOp(fname, ack) |
| 1514 |
{ |
| 1515 |
/* |
| 1516 |
* Note that we're reading from the script file if desired. Do |
| 1517 |
* this before opening the script, so that we display the |
| 1518 |
* acknowledgment even if we're in 'quiet' mode. |
| 1519 |
*/ |
| 1520 |
if (ack) |
| 1521 |
gLibMessages.inputScriptOkay( |
| 1522 |
fname.ofKind(TemporaryFile) ? fname.getFilename() : fname); |
| 1523 |
|
| 1524 |
/* activate the script file */ |
| 1525 |
local ok = nil, exc = nil; |
| 1526 |
try |
| 1527 |
{ |
| 1528 |
ok = setScriptFile(fname, scriptOptionFlags); |
| 1529 |
} |
| 1530 |
catch (Exception e) |
| 1531 |
{ |
| 1532 |
exc = e; |
| 1533 |
} |
| 1534 |
if (!ok) |
| 1535 |
{ |
| 1536 |
if (exc != nil) |
| 1537 |
gLibMessages.inputScriptFailed(exc); |
| 1538 |
else |
| 1539 |
gLibMessages.inputScriptFailed(); |
| 1540 |
} |
| 1541 |
} |
| 1542 |
; |
| 1543 |
|
| 1544 |
/* subclass of Replay action taking a quoted string for the filename */ |
| 1545 |
DefineAction(ReplayString, ReplayAction) |
| 1546 |
execSystemAction() |
| 1547 |
{ |
| 1548 |
/* |
| 1549 |
* if there's a string, use the string as the filename; |
| 1550 |
* otherwise, inherit the default handling to ask for a filename |
| 1551 |
*/ |
| 1552 |
if (fname_ != nil) |
| 1553 |
{ |
| 1554 |
/* set up scripting to the filename specified in the command */ |
| 1555 |
performFileOp(fname_.getStringText(), true); |
| 1556 |
} |
| 1557 |
else |
| 1558 |
{ |
| 1559 |
/* inherit the default handling to ask for a filename */ |
| 1560 |
inherited(); |
| 1561 |
} |
| 1562 |
} |
| 1563 |
; |
| 1564 |
|
| 1565 |
|
| 1566 |
/* in case the footnote module is not present */ |
| 1567 |
property showFootnote; |
| 1568 |
|
| 1569 |
/* |
| 1570 |
* Footnote - this requires a numeric argument parsed via the |
| 1571 |
* numberPhrase production and assigned to the numMatch property. |
| 1572 |
*/ |
| 1573 |
DefineSystemAction(Footnote) |
| 1574 |
execSystemAction() |
| 1575 |
{ |
| 1576 |
/* ask the Footnote class to do the work */ |
| 1577 |
if (libGlobal.footnoteClass != nil) |
| 1578 |
libGlobal.footnoteClass.showFootnote(numMatch.getval()); |
| 1579 |
else |
| 1580 |
gLibMessages.commandNotPresent; |
| 1581 |
} |
| 1582 |
|
| 1583 |
/* there's no point in including this in undo */ |
| 1584 |
includeInUndo = nil |
| 1585 |
; |
| 1586 |
|
| 1587 |
property footnoteSettings; |
| 1588 |
|
| 1589 |
/* base class for FOOTNOTES xxx commands */ |
| 1590 |
DefineSystemAction(Footnotes) |
| 1591 |
execSystemAction() |
| 1592 |
{ |
| 1593 |
if (libGlobal.footnoteClass != nil) |
| 1594 |
{ |
| 1595 |
/* set my footnote status in the global setting */ |
| 1596 |
libGlobal.footnoteClass.footnoteSettings.showFootnotes = |
| 1597 |
showFootnotes; |
| 1598 |
|
| 1599 |
/* acknowledge it */ |
| 1600 |
gLibMessages.acknowledgeFootnoteStatus(showFootnotes); |
| 1601 |
} |
| 1602 |
else |
| 1603 |
gLibMessages.commandNotPresent; |
| 1604 |
} |
| 1605 |
|
| 1606 |
/* |
| 1607 |
* the footnote status I set when this command is activated - this |
| 1608 |
* must be overridden by each subclass |
| 1609 |
*/ |
| 1610 |
showFootnotes = nil |
| 1611 |
; |
| 1612 |
|
| 1613 |
DefineAction(FootnotesFull, FootnotesAction) |
| 1614 |
showFootnotes = FootnotesFull |
| 1615 |
; |
| 1616 |
|
| 1617 |
DefineAction(FootnotesMedium, FootnotesAction) |
| 1618 |
showFootnotes = FootnotesMedium |
| 1619 |
; |
| 1620 |
|
| 1621 |
DefineAction(FootnotesOff, FootnotesAction) |
| 1622 |
showFootnotes = FootnotesOff |
| 1623 |
; |
| 1624 |
|
| 1625 |
DefineSystemAction(FootnotesStatus) |
| 1626 |
execSystemAction() |
| 1627 |
{ |
| 1628 |
/* show the current status */ |
| 1629 |
if (libGlobal.footnoteClass != nil) |
| 1630 |
gLibMessages.showFootnoteStatus(libGlobal.footnoteClass. |
| 1631 |
footnoteSettings.showFootnotes); |
| 1632 |
else |
| 1633 |
gLibMessages.commandNotPresent; |
| 1634 |
} |
| 1635 |
|
| 1636 |
/* there's no point in including this in undo */ |
| 1637 |
includeInUndo = nil |
| 1638 |
; |
| 1639 |
|
| 1640 |
DefineIAction(Inventory) |
| 1641 |
execAction() |
| 1642 |
{ |
| 1643 |
/* show the actor's inventory in the current mode */ |
| 1644 |
gActor.showInventory(inventoryMode == InventoryTall); |
| 1645 |
} |
| 1646 |
|
| 1647 |
/* current inventory mode - start in 'wide' mode by default */ |
| 1648 |
inventoryMode = InventoryWide; |
| 1649 |
; |
| 1650 |
|
| 1651 |
DefineIAction(InventoryTall) |
| 1652 |
execAction() |
| 1653 |
{ |
| 1654 |
/* set inventory mode to 'tall' */ |
| 1655 |
InventoryAction.inventoryMode = InventoryTall; |
| 1656 |
|
| 1657 |
/* run the inventory action */ |
| 1658 |
InventoryAction.checkAction(); |
| 1659 |
InventoryAction.execAction(); |
| 1660 |
} |
| 1661 |
; |
| 1662 |
|
| 1663 |
DefineIAction(InventoryWide) |
| 1664 |
execAction() |
| 1665 |
{ |
| 1666 |
/* set inventory mode to 'wide' */ |
| 1667 |
InventoryAction.inventoryMode = InventoryWide; |
| 1668 |
|
| 1669 |
/* run the inventory action */ |
| 1670 |
InventoryAction.checkAction(); |
| 1671 |
InventoryAction.execAction(); |
| 1672 |
} |
| 1673 |
; |
| 1674 |
|
| 1675 |
DefineIAction(Wait) |
| 1676 |
execAction() |
| 1677 |
{ |
| 1678 |
/* just show the "time passes" message */ |
| 1679 |
defaultReport(&timePassesMsg); |
| 1680 |
} |
| 1681 |
; |
| 1682 |
|
| 1683 |
DefineIAction(Look) |
| 1684 |
execAction() |
| 1685 |
{ |
| 1686 |
/* show the actor's current location in verbose mode */ |
| 1687 |
gActor.lookAround(true); |
| 1688 |
} |
| 1689 |
; |
| 1690 |
|
| 1691 |
DefineIAction(Sleep) |
| 1692 |
execAction() |
| 1693 |
{ |
| 1694 |
/* let the actor handle it */ |
| 1695 |
gActor.goToSleep(); |
| 1696 |
} |
| 1697 |
; |
| 1698 |
|
| 1699 |
DefineTAction(Take) |
| 1700 |
/* this is a basic inventory-management verb, so allow ALL with it */ |
| 1701 |
actionAllowsAll = true |
| 1702 |
|
| 1703 |
/* get the ALL list for the direct object */ |
| 1704 |
getAllDobj(actor, scopeList) |
| 1705 |
{ |
| 1706 |
local locList; |
| 1707 |
local dropLoc; |
| 1708 |
local actorLoc; |
| 1709 |
|
| 1710 |
/* |
| 1711 |
* Include all of the objects that are directly in the actor's |
| 1712 |
* immediate container, the container's container, and so on out |
| 1713 |
* to the "drop destination" location (which is where things go |
| 1714 |
* when we DROP them, and is meant to represent the nearest |
| 1715 |
* platform-like or floor-like container). Also include anything |
| 1716 |
* that's directly in anything fixed in place within one of these |
| 1717 |
* containers. Don't include anything that actually contains the |
| 1718 |
* actor, since we normally can't pick up something we're inside. |
| 1719 |
* |
| 1720 |
* Start by getting the actor's immediate location and drop |
| 1721 |
* destination location. |
| 1722 |
*/ |
| 1723 |
actorLoc = actor.location; |
| 1724 |
dropLoc = actor.getDropDestination(nil, nil); |
| 1725 |
|
| 1726 |
/* |
| 1727 |
* create a vector to hold the location list, and start it off |
| 1728 |
* with the drop location |
| 1729 |
*/ |
| 1730 |
locList = new Vector(10); |
| 1731 |
locList.append(dropLoc); |
| 1732 |
|
| 1733 |
/* now work up the location list until we hit the drop location */ |
| 1734 |
for (local cur = actorLoc ; cur != nil && cur != dropLoc ; |
| 1735 |
cur = cur.location) |
| 1736 |
{ |
| 1737 |
/* add this container to the list */ |
| 1738 |
locList.append(cur); |
| 1739 |
} |
| 1740 |
|
| 1741 |
/* |
| 1742 |
* now generate the subset of in-scope objects that are directly |
| 1743 |
* in any of these locations (or directly in items fixed in place |
| 1744 |
* within any of these locations), and return the result |
| 1745 |
*/ |
| 1746 |
return scopeList.subset( |
| 1747 |
{x: (locList.indexWhich( |
| 1748 |
{loc: x.isDirectlyIn(loc) || x.isInFixedIn(loc)}) != nil |
| 1749 |
&& !actor.isIn(x)) }); |
| 1750 |
} |
| 1751 |
; |
| 1752 |
|
| 1753 |
DefineTIAction(TakeFrom) |
| 1754 |
/* this is a basic inventory-management verb, so allow ALL with it */ |
| 1755 |
actionAllowsAll = true |
| 1756 |
|
| 1757 |
/* get the ALL list for the direct object */ |
| 1758 |
getAllDobj(actor, scopeList) |
| 1759 |
{ |
| 1760 |
/* ask the indirect object for the list */ |
| 1761 |
return getIobj() == nil |
| 1762 |
? [] |
| 1763 |
: getIobj().getAllForTakeFrom(scopeList); |
| 1764 |
} |
| 1765 |
; |
| 1766 |
|
| 1767 |
DefineTAction(Remove) |
| 1768 |
; |
| 1769 |
|
| 1770 |
DefineTAction(Drop) |
| 1771 |
/* this is a basic inventory-management verb, so allow ALL with it */ |
| 1772 |
actionAllowsAll = true |
| 1773 |
|
| 1774 |
/* get the ALL list for the direct object */ |
| 1775 |
getAllDobj(actor, scopeList) |
| 1776 |
{ |
| 1777 |
/* include only objects directly held by the actor */ |
| 1778 |
return scopeList.subset({x: x.isDirectlyIn(actor)}); |
| 1779 |
} |
| 1780 |
; |
| 1781 |
|
| 1782 |
DefineTAction(Examine) |
| 1783 |
; |
| 1784 |
|
| 1785 |
DefineTAction(Read) |
| 1786 |
; |
| 1787 |
|
| 1788 |
DefineTAction(LookIn) |
| 1789 |
; |
| 1790 |
|
| 1791 |
DefineTAction(Search) |
| 1792 |
; |
| 1793 |
|
| 1794 |
DefineTAction(LookUnder) |
| 1795 |
; |
| 1796 |
|
| 1797 |
DefineTAction(LookBehind) |
| 1798 |
; |
| 1799 |
|
| 1800 |
DefineTAction(LookThrough) |
| 1801 |
; |
| 1802 |
|
| 1803 |
DefineTAction(Feel) |
| 1804 |
; |
| 1805 |
|
| 1806 |
DefineTAction(Taste) |
| 1807 |
; |
| 1808 |
|
| 1809 |
DefineTAction(Smell) |
| 1810 |
; |
| 1811 |
|
| 1812 |
DefineTAction(ListenTo) |
| 1813 |
; |
| 1814 |
|
| 1815 |
/* |
| 1816 |
* Base class for undirected sensing, such as "listen" or "smell" with no |
| 1817 |
* object. We'll scan for things that have a presence in the |
| 1818 |
* corresponding sense and describe each one. |
| 1819 |
*/ |
| 1820 |
DefineIAction(SenseImplicit) |
| 1821 |
/* the sense in which I operate */ |
| 1822 |
mySense = nil |
| 1823 |
|
| 1824 |
/* the object property to display this sense's description */ |
| 1825 |
descProp = nil |
| 1826 |
|
| 1827 |
/* the default message to display if we find nothing specific to sense */ |
| 1828 |
defaultMsgProp = nil |
| 1829 |
|
| 1830 |
/* the Lister we use to show the items */ |
| 1831 |
resultLister = nil |
| 1832 |
|
| 1833 |
/* execute the action */ |
| 1834 |
execAction() |
| 1835 |
{ |
| 1836 |
local senseTab; |
| 1837 |
local presenceList; |
| 1838 |
|
| 1839 |
/* get a list of everything in range of this sense for the actor */ |
| 1840 |
senseTab = gActor.senseInfoTable(mySense); |
| 1841 |
|
| 1842 |
/* get a list of everything with a presence in this sense */ |
| 1843 |
presenceList = senseInfoTableSubset(senseTab, |
| 1844 |
{obj, info: obj.(mySense.presenceProp)}); |
| 1845 |
|
| 1846 |
/* |
| 1847 |
* if there's anything in the list, show it; otherwise, show a |
| 1848 |
* default report |
| 1849 |
*/ |
| 1850 |
if (presenceList.length() != 0) |
| 1851 |
{ |
| 1852 |
/* show the list using our lister */ |
| 1853 |
resultLister.showList(gActor, nil, presenceList, 0, 0, |
| 1854 |
senseTab, nil); |
| 1855 |
} |
| 1856 |
else |
| 1857 |
{ |
| 1858 |
/* there's nothing to show - say so */ |
| 1859 |
defaultReport(defaultMsgProp); |
| 1860 |
} |
| 1861 |
} |
| 1862 |
; |
| 1863 |
|
| 1864 |
DefineAction(SmellImplicit, SenseImplicitAction) |
| 1865 |
mySense = smell |
| 1866 |
descProp = &smellDesc |
| 1867 |
defaultMsgProp = ¬hingToSmellMsg |
| 1868 |
resultLister = smellActionLister |
| 1869 |
; |
| 1870 |
|
| 1871 |
DefineAction(ListenImplicit, SenseImplicitAction) |
| 1872 |
mySense = sound |
| 1873 |
descProp = &soundDesc |
| 1874 |
defaultMsgProp = ¬hingToHearMsg |
| 1875 |
resultLister = listenActionLister |
| 1876 |
; |
| 1877 |
|
| 1878 |
DefineTIAction(PutIn) |
| 1879 |
/* this is a basic inventory-management verb, so allow ALL with it */ |
| 1880 |
actionAllowsAll = true |
| 1881 |
|
| 1882 |
/* get the ALL list for the direct object */ |
| 1883 |
getAllDobj(actor, scopeList) |
| 1884 |
{ |
| 1885 |
local loc; |
| 1886 |
local iobj = nil; |
| 1887 |
local iobjIdent = nil; |
| 1888 |
|
| 1889 |
/* get the actor's location */ |
| 1890 |
loc = actor.location; |
| 1891 |
|
| 1892 |
/* if we have an iobj list, retrieve its first element */ |
| 1893 |
if (iobjList_ != nil && iobjList_.length() > 0) |
| 1894 |
{ |
| 1895 |
iobj = iobjList_[1].obj_; |
| 1896 |
iobjIdent = iobj.getIdentityObject(); |
| 1897 |
} |
| 1898 |
|
| 1899 |
/* |
| 1900 |
* Include objects that are directly in the actor's location, or |
| 1901 |
* within fixed items in the actor's location, or directly in the |
| 1902 |
* actor's inventory. |
| 1903 |
* |
| 1904 |
* Exclude the indirect object and its "identity" object (since |
| 1905 |
* we obviously can't put the indirect object in itself), and |
| 1906 |
* exclude everything already directly in the indirect object. |
| 1907 |
*/ |
| 1908 |
return scopeList.subset({x: |
| 1909 |
(x.isDirectlyIn(loc) |
| 1910 |
|| x.isInFixedIn(loc) |
| 1911 |
|| x.isDirectlyIn(actor)) |
| 1912 |
&& x != iobj |
| 1913 |
&& x != iobjIdent |
| 1914 |
&& !x.isDirectlyIn(iobj)}); |
| 1915 |
} |
| 1916 |
; |
| 1917 |
|
| 1918 |
DefineTIAction(PutOn) |
| 1919 |
/* this is a basic inventory-management verb, so allow ALL with it */ |
| 1920 |
actionAllowsAll = true |
| 1921 |
|
| 1922 |
/* get the ALL list for the direct object */ |
| 1923 |
getAllDobj(actor, scopeList) |
| 1924 |
{ |
| 1925 |
/* use the same strategy that we do in PutIn */ |
| 1926 |
local loc = actor.location; |
| 1927 |
return scopeList.subset({x: |
| 1928 |
(x.isDirectlyIn(loc) |
| 1929 |
|| x.isInFixedIn(loc) |
| 1930 |
|| x.isDirectlyIn(actor)) |
| 1931 |
&& x != getIobj() |
| 1932 |
&& !x.isDirectlyIn(getIobj())}); |
| 1933 |
} |
| 1934 |
; |
| 1935 |
|
| 1936 |
DefineTIAction(PutUnder) |
| 1937 |
; |
| 1938 |
|
| 1939 |
DefineTIAction(PutBehind) |
| 1940 |
; |
| 1941 |
|
| 1942 |
DefineTAction(Wear) |
| 1943 |
; |
| 1944 |
|
| 1945 |
DefineTAction(Doff) |
| 1946 |
; |
| 1947 |
|
| 1948 |
DefineConvTopicTAction(AskFor, IndirectObject) |
| 1949 |
; |
| 1950 |
|
| 1951 |
DefineConvTopicTAction(AskAbout, IndirectObject) |
| 1952 |
; |
| 1953 |
|
| 1954 |
DefineConvTopicTAction(TellAbout, IndirectObject) |
| 1955 |
/* |
| 1956 |
* TELL ABOUT is a conversational address, as opposed to an order, |
| 1957 |
* if the direct object of the action is the same as the issuer: in |
| 1958 |
* this case, the command has the form <actor>, TELL ME ABOUT |
| 1959 |
* <topic>, which has exactly the same meaning as ASK <actor> ABOUT |
| 1960 |
* <topic>. |
| 1961 |
*/ |
| 1962 |
isConversational(issuer) |
| 1963 |
{ |
| 1964 |
local dobj; |
| 1965 |
|
| 1966 |
/* |
| 1967 |
* if the resolved direct object matches the issuer, it's |
| 1968 |
* conversational |
| 1969 |
*/ |
| 1970 |
dobj = getResolvedDobjList(); |
| 1971 |
return (dobj.length() == 1 && dobj[1] == issuer); |
| 1972 |
} |
| 1973 |
; |
| 1974 |
|
| 1975 |
/* |
| 1976 |
* AskVague and TellVague are for syntactically incorrect phrasings that |
| 1977 |
* a player might accidentally type, especially in conjunction with a |
| 1978 |
* past SpecialTopic prompt; in English, for example, we define these as |
| 1979 |
* ASK <actor> <topic> and TELL <actor> <topic>. These are used only to |
| 1980 |
* provide more helpful error messages. |
| 1981 |
*/ |
| 1982 |
DefineTopicTAction(AskVague, IndirectObject) |
| 1983 |
; |
| 1984 |
DefineTopicTAction(TellVague, IndirectObject) |
| 1985 |
; |
| 1986 |
|
| 1987 |
DefineConvIAction(Hello) |
| 1988 |
execAction() |
| 1989 |
{ |
| 1990 |
/* the issuing actor is saying hello to the target actor */ |
| 1991 |
gIssuingActor.sayHello(gActor); |
| 1992 |
} |
| 1993 |
; |
| 1994 |
|
| 1995 |
DefineConvIAction(Goodbye) |
| 1996 |
execAction() |
| 1997 |
{ |
| 1998 |
/* the issuing actor is saying goodbye to the target actor */ |
| 1999 |
gIssuingActor.sayGoodbye(gActor); |
| 2000 |
} |
| 2001 |
; |
| 2002 |
|
| 2003 |
DefineConvIAction(Yes) |
| 2004 |
execAction() |
| 2005 |
{ |
| 2006 |
/* the issuing actor is saying yes to the target actor */ |
| 2007 |
gIssuingActor.sayYes(gActor); |
| 2008 |
} |
| 2009 |
; |
| 2010 |
|
| 2011 |
DefineConvIAction(No) |
| 2012 |
execAction() |
| 2013 |
{ |
| 2014 |
/* the issuing actor is saying no to the target actor */ |
| 2015 |
gIssuingActor.sayNo(gActor); |
| 2016 |
} |
| 2017 |
; |
| 2018 |
|
| 2019 |
/* |
| 2020 |
* Invoke the active SpecialTopic. This isn't a real command - the |
| 2021 |
* player will never actually type this; rather, it's a pseudo-command |
| 2022 |
* that we send to ourselves from a string pre-parser when we recognize |
| 2023 |
* input that matches a SpecialTopic's custom command syntax. |
| 2024 |
* |
| 2025 |
* Note that we actually define the syntax for this command right here |
| 2026 |
* in the language-independent library, because this isn't a real |
| 2027 |
* command. The user never needs to type this command, since it's |
| 2028 |
* something we generate internally. The only important language issue |
| 2029 |
* is that we use a command keyword that no language will ever want to |
| 2030 |
* use for a real command, so we intentionally use some near-English |
| 2031 |
* gibberish. |
| 2032 |
*/ |
| 2033 |
DefineLiteralAction(SpecialTopic) |
| 2034 |
execAction() |
| 2035 |
{ |
| 2036 |
/* |
| 2037 |
* the issuing actor is saying the current special topic to the |
| 2038 |
* actor's current interlocutor |
| 2039 |
*/ |
| 2040 |
gIssuingActor.saySpecialTopic(); |
| 2041 |
} |
| 2042 |
|
| 2043 |
/* |
| 2044 |
* Repeat the action, for an AGAIN command. We need to make sure |
| 2045 |
* the special text interpretation we gave to the command still |
| 2046 |
* holds; if not, reparse the original text and try that. |
| 2047 |
*/ |
| 2048 |
repeatAction(lastTargetActor, lastTargetActorPhrase, |
| 2049 |
lastIssuingActor, countsAsIssuerTurn) |
| 2050 |
{ |
| 2051 |
local cmd; |
| 2052 |
|
| 2053 |
/* get the original text the player entered */ |
| 2054 |
cmd = getEnteredText(); |
| 2055 |
|
| 2056 |
/* |
| 2057 |
* try running this through the special topic pre-parser again, |
| 2058 |
* to see if it still has the special meaning |
| 2059 |
*/ |
| 2060 |
if (specialTopicPreParser.doParsing(cmd, rmcCommand) |
| 2061 |
.startsWith('xspcltopic ')) |
| 2062 |
{ |
| 2063 |
/* |
| 2064 |
* it still has the special meaning, so simply execute as we |
| 2065 |
* normally would, by inheriting the standard Action |
| 2066 |
* handling |
| 2067 |
*/ |
| 2068 |
inherited(lastTargetActor, lastTargetActorPhrase, |
| 2069 |
lastIssuingActor, countsAsIssuerTurn); |
| 2070 |
} |
| 2071 |
else |
| 2072 |
{ |
| 2073 |
/* |
| 2074 |
* The command no longer has the special meaning it did on |
| 2075 |
* the last command, so we can't repeat this command. |
| 2076 |
*/ |
| 2077 |
gLibMessages.againNotPossible(lastIssuingActor); |
| 2078 |
} |
| 2079 |
} |
| 2080 |
|
| 2081 |
/* |
| 2082 |
* Get the original player-entered text. This is our literal |
| 2083 |
* phrase, with the embedded-quote encoding decoded. |
| 2084 |
*/ |
| 2085 |
getEnteredText() { return decodeOrig(getLiteral()); } |
| 2086 |
|
| 2087 |
/* |
| 2088 |
* encode the original text for our literal phrase: turn double |
| 2089 |
* quotes into '%q' sequences, and turn percent signs into '%%' |
| 2090 |
* sequences |
| 2091 |
*/ |
| 2092 |
encodeOrig(txt) |
| 2093 |
{ |
| 2094 |
/* replace '%' with '%%', and double quotes with '%q' */ |
| 2095 |
return txt.findReplace(['%', '"'], ['%%', '%q']); |
| 2096 |
} |
| 2097 |
|
| 2098 |
/* decode our encoding */ |
| 2099 |
decodeOrig(txt) |
| 2100 |
{ |
| 2101 |
/* replace '%%' with '%', and '%q' with '"' */ |
| 2102 |
return txt.findReplace(['%%', '%q'], ['%', '"']); |
| 2103 |
} |
| 2104 |
; |
| 2105 |
|
| 2106 |
grammar predicate(SpecialTopic): |
| 2107 |
'xspcltopic' literalPhrase->literalMatch |
| 2108 |
: SpecialTopicAction |
| 2109 |
|
| 2110 |
/* |
| 2111 |
* Use the text of the command as originally typed by the player as |
| 2112 |
* our apparent original text. |
| 2113 |
*/ |
| 2114 |
getOrigText() { return getEnteredText(); } |
| 2115 |
; |
| 2116 |
|
| 2117 |
/* in case they try typing just 'xspcltopic' */ |
| 2118 |
grammar predicate(EmptySpecialTopic): |
| 2119 |
'xspcltopic' : IAction |
| 2120 |
|
| 2121 |
/* just act like we don't understand this command */ |
| 2122 |
execAction() { gLibMessages.commandNotPresent; } |
| 2123 |
; |
| 2124 |
|
| 2125 |
DefineTAction(Kiss) |
| 2126 |
; |
| 2127 |
|
| 2128 |
DefineIAction(Yell) |
| 2129 |
execAction() |
| 2130 |
{ |
| 2131 |
/* yelling generally has no effect; issue a default response */ |
| 2132 |
mainReport(&okayYellMsg); |
| 2133 |
} |
| 2134 |
; |
| 2135 |
|
| 2136 |
DefineTAction(TalkTo) |
| 2137 |
; |
| 2138 |
|
| 2139 |
DefineSystemAction(Topics) |
| 2140 |
execSystemAction() |
| 2141 |
{ |
| 2142 |
/* check to see if any suggestions are defined in the entire game */ |
| 2143 |
if (firstObj(SuggestedTopic, ObjInstances) != nil) |
| 2144 |
{ |
| 2145 |
/* we have topics - let the actor handle it */ |
| 2146 |
gActor.suggestTopics(true); |
| 2147 |
} |
| 2148 |
else |
| 2149 |
{ |
| 2150 |
/* there are no topics at all, so this command isn't used */ |
| 2151 |
gLibMessages.commandNotPresent; |
| 2152 |
} |
| 2153 |
} |
| 2154 |
|
| 2155 |
/* don't include this in undo */ |
| 2156 |
includeInUndo = nil |
| 2157 |
; |
| 2158 |
|
| 2159 |
DefineTIAction(GiveTo) |
| 2160 |
getDefaultIobj(np, resolver) |
| 2161 |
{ |
| 2162 |
/* check the actor for a current interlocutor */ |
| 2163 |
local obj = resolver.getTargetActor().getCurrentInterlocutor(); |
| 2164 |
if (obj != nil) |
| 2165 |
return [new ResolveInfo(obj, 0, np)]; |
| 2166 |
else |
| 2167 |
return inherited(np, resolver); |
| 2168 |
} |
| 2169 |
; |
| 2170 |
|
| 2171 |
/* |
| 2172 |
* Define a global remapping to transform commands of the form "X, GIVE |
| 2173 |
* ME Y" to the format "ME, ASK X FOR Y". This makes it easier to write |
| 2174 |
* the code to handle these sorts of exchanges, since it means you only |
| 2175 |
* have to write it in the ASK FOR handler. |
| 2176 |
*/ |
| 2177 |
giveMeToAskFor: GlobalRemapping |
| 2178 |
/* |
| 2179 |
* Remap a command, if applicable. We look for commands of the form |
| 2180 |
* "X, GIVE ME Y": we look for a GiveTo action whose indirect object |
| 2181 |
* is the same as the issuing actor. When we find this form of |
| 2182 |
* command, we rewrite it to "ME, ASK X FOR Y". |
| 2183 |
*/ |
| 2184 |
getRemapping(issuingActor, targetActor, action) |
| 2185 |
{ |
| 2186 |
/* |
| 2187 |
* if it's of the form "X, GIVE Y TO Z", where Z is the issuing |
| 2188 |
* actor (generally ME, but it could conceivably be someone |
| 2189 |
* else), transform it into "Z, ASK X FOR Y". |
| 2190 |
*/ |
| 2191 |
if (action.ofKind(GiveToAction) |
| 2192 |
&& action.canIobjResolveTo(issuingActor)) |
| 2193 |
{ |
| 2194 |
/* create the ASK FOR action */ |
| 2195 |
local newAction = AskForAction.createActionInstance(); |
| 2196 |
|
| 2197 |
/* remember the original version of the action */ |
| 2198 |
newAction.setOriginalAction(action); |
| 2199 |
|
| 2200 |
/* |
| 2201 |
* Changing the phrasing from "X, GIVE Y TO Z" to "Z, ASK X |
| 2202 |
* FOR Y" will change the target actor from X in the old |
| 2203 |
* version to Z in the new version. In the original format, |
| 2204 |
* the pronouns "you", "your", and "yours" implicitly refers |
| 2205 |
* to Z ("Bob, give me your book" implies "bob's book"). The |
| 2206 |
* rewrite will change that, though - assuming that Z is a |
| 2207 |
* second-person actor, "you" will by default refer to Z in |
| 2208 |
* the rewrite. In order to preserve the original meaning, |
| 2209 |
* we have to override "you" in the rewrite so that it |
| 2210 |
* continues to refer to "X", which we can do using a pronoun |
| 2211 |
* override in the new action. |
| 2212 |
*/ |
| 2213 |
newAction.setPronounOverride(PronounYou, targetActor); |
| 2214 |
|
| 2215 |
/* |
| 2216 |
* The direct object - the person we're asking - is the |
| 2217 |
* original target actor ("bob" in "bob, give me x"). Since |
| 2218 |
* this is a specific object, we need to wrap it in a |
| 2219 |
* PreResolvedProd. |
| 2220 |
*/ |
| 2221 |
local dobj = new PreResolvedProd(targetActor); |
| 2222 |
|
| 2223 |
/* |
| 2224 |
* The thing we're asking for is the original direct object. |
| 2225 |
* ASK FOR takes a topic phrase for its indirect object, |
| 2226 |
* whereas GIVE TO takes a regular noun phrase. The two |
| 2227 |
* aren't quite identical syntactically, so we'll do better |
| 2228 |
* if we re-parse the original dobj noun phrase as a topic |
| 2229 |
* phrase. Fortunately, this is easy... |
| 2230 |
*/ |
| 2231 |
local iobj = newAction.reparseMatchAsTopic( |
| 2232 |
action.dobjMatch, issuingActor, issuingActor); |
| 2233 |
|
| 2234 |
/* set the object match trees */ |
| 2235 |
newAction.setObjectMatches(dobj, iobj); |
| 2236 |
|
| 2237 |
/* |
| 2238 |
* Return the new command, addressing the *issuing* actor |
| 2239 |
* this time around. |
| 2240 |
*/ |
| 2241 |
return [issuingActor, newAction]; |
| 2242 |
} |
| 2243 |
|
| 2244 |
/* it's not ours */ |
| 2245 |
return nil; |
| 2246 |
} |
| 2247 |
; |
| 2248 |
|
| 2249 |
|
| 2250 |
DefineTIAction(ShowTo) |
| 2251 |
getDefaultIobj(np, resolver) |
| 2252 |
{ |
| 2253 |
/* check the actor for a current interlocutor */ |
| 2254 |
local obj = resolver.getTargetActor().getCurrentInterlocutor(); |
| 2255 |
if (obj != nil) |
| 2256 |
return [new ResolveInfo(obj, 0, np)]; |
| 2257 |
else |
| 2258 |
return inherited(np, resolver); |
| 2259 |
} |
| 2260 |
; |
| 2261 |
|
| 2262 |
DefineTAction(Follow) |
| 2263 |
/* |
| 2264 |
* For resolving our direct object, we want to include in the scope |
| 2265 |
* any item that isn't present but which the actor saw departing the |
| 2266 |
* present location. |
| 2267 |
*/ |
| 2268 |
initResolver(issuingActor, targetActor) |
| 2269 |
{ |
| 2270 |
/* inherit the base resolver initialization */ |
| 2271 |
inherited(issuingActor, targetActor); |
| 2272 |
|
| 2273 |
/* |
| 2274 |
* add to the scope all of the actor's followable objects - |
| 2275 |
* these are the objects which the actor has witnessed leaving |
| 2276 |
* the actor's present location |
| 2277 |
*/ |
| 2278 |
scope_ = scope_.appendUnique(targetActor.getFollowables()); |
| 2279 |
} |
| 2280 |
; |
| 2281 |
|
| 2282 |
DefineTAction(Attack) |
| 2283 |
; |
| 2284 |
|
| 2285 |
DefineTIAction(AttackWith) |
| 2286 |
/* |
| 2287 |
* for the indirect object, limit 'all' and defaults to the items in |
| 2288 |
* inventory |
| 2289 |
*/ |
| 2290 |
getAllIobj(actor, scopeList) |
| 2291 |
{ |
| 2292 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2293 |
} |
| 2294 |
; |
| 2295 |
|
| 2296 |
DefineTAction(Throw) |
| 2297 |
; |
| 2298 |
|
| 2299 |
DefineTAction(ThrowDir) |
| 2300 |
/* get the direction of the throwing (as a Direction object) */ |
| 2301 |
getDirection() { return dirMatch.dir; } |
| 2302 |
; |
| 2303 |
|
| 2304 |
DefineTIAction(ThrowAt) |
| 2305 |
; |
| 2306 |
|
| 2307 |
DefineTIAction(ThrowTo) |
| 2308 |
; |
| 2309 |
|
| 2310 |
DefineTAction(Dig) |
| 2311 |
; |
| 2312 |
|
| 2313 |
DefineTIAction(DigWith) |
| 2314 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2315 |
getAllIobj(actor, scopeList) |
| 2316 |
{ |
| 2317 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2318 |
} |
| 2319 |
; |
| 2320 |
|
| 2321 |
DefineIAction(Jump) |
| 2322 |
preCond = [actorStanding] |
| 2323 |
execAction() |
| 2324 |
{ |
| 2325 |
/* show the default report for jumping in place */ |
| 2326 |
mainReport(&okayJumpMsg); |
| 2327 |
} |
| 2328 |
; |
| 2329 |
|
| 2330 |
DefineTAction(JumpOver) |
| 2331 |
; |
| 2332 |
|
| 2333 |
DefineTAction(JumpOff) |
| 2334 |
; |
| 2335 |
|
| 2336 |
DefineIAction(JumpOffI) |
| 2337 |
execAction() |
| 2338 |
{ |
| 2339 |
mainReport(&cannotJumpOffHereMsg); |
| 2340 |
} |
| 2341 |
; |
| 2342 |
|
| 2343 |
DefineTAction(Push) |
| 2344 |
; |
| 2345 |
|
| 2346 |
DefineTAction(Pull) |
| 2347 |
; |
| 2348 |
|
| 2349 |
DefineTAction(Move) |
| 2350 |
; |
| 2351 |
|
| 2352 |
DefineTIAction(MoveWith) |
| 2353 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2354 |
getAllIobj(actor, scopeList) |
| 2355 |
{ |
| 2356 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2357 |
} |
| 2358 |
; |
| 2359 |
|
| 2360 |
DefineTIAction(MoveTo) |
| 2361 |
; |
| 2362 |
|
| 2363 |
DefineTAction(Turn) |
| 2364 |
; |
| 2365 |
|
| 2366 |
DefineTIAction(TurnWith) |
| 2367 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2368 |
getAllIobj(actor, scopeList) |
| 2369 |
{ |
| 2370 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2371 |
} |
| 2372 |
; |
| 2373 |
|
| 2374 |
DefineLiteralTAction(TurnTo, IndirectObject) |
| 2375 |
; |
| 2376 |
|
| 2377 |
DefineTAction(Set) |
| 2378 |
; |
| 2379 |
|
| 2380 |
DefineLiteralTAction(SetTo, IndirectObject) |
| 2381 |
; |
| 2382 |
|
| 2383 |
DefineTAction(TypeOn) |
| 2384 |
; |
| 2385 |
|
| 2386 |
DefineLiteralTAction(TypeLiteralOn, DirectObject) |
| 2387 |
; |
| 2388 |
|
| 2389 |
DefineLiteralTAction(EnterOn, DirectObject) |
| 2390 |
; |
| 2391 |
|
| 2392 |
DefineTAction(Consult) |
| 2393 |
; |
| 2394 |
|
| 2395 |
DefineTopicTAction(ConsultAbout, IndirectObject) |
| 2396 |
getDefaultDobj(np, resolver) |
| 2397 |
{ |
| 2398 |
/* |
| 2399 |
* if the actor has consulted something before, and that object |
| 2400 |
* is still visible, use it as the default for this consultation |
| 2401 |
*/ |
| 2402 |
local actor = resolver.getTargetActor(); |
| 2403 |
local obj = actor.lastConsulted; |
| 2404 |
if (obj != nil && actor.canSee(obj)) |
| 2405 |
return [new ResolveInfo(obj, DefaultObject, np)]; |
| 2406 |
else |
| 2407 |
return inherited(np, resolver); |
| 2408 |
} |
| 2409 |
|
| 2410 |
/* |
| 2411 |
* Filter the topic phrase resolution. If we know our direct object, |
| 2412 |
* and it's a Consultable, refer the resolution to the Consultable. |
| 2413 |
*/ |
| 2414 |
filterTopic(lst, np, resolver) |
| 2415 |
{ |
| 2416 |
local dobj; |
| 2417 |
|
| 2418 |
/* check the direct object */ |
| 2419 |
if (dobjList_ != nil |
| 2420 |
&& dobjList_.length() == 1 |
| 2421 |
&& (dobj = dobjList_[1].obj_).ofKind(Consultable)) |
| 2422 |
{ |
| 2423 |
/* |
| 2424 |
* we have a Consultable direct object - let it handle the |
| 2425 |
* topic phrase resolution |
| 2426 |
*/ |
| 2427 |
return dobj.resolveConsultTopic(lst, topicMatch, resolver); |
| 2428 |
} |
| 2429 |
else |
| 2430 |
{ |
| 2431 |
/* otherwise, use the default handling */ |
| 2432 |
return inherited(lst, np, resolver); |
| 2433 |
} |
| 2434 |
} |
| 2435 |
; |
| 2436 |
|
| 2437 |
DefineTAction(Switch) |
| 2438 |
; |
| 2439 |
|
| 2440 |
DefineTAction(Flip) |
| 2441 |
; |
| 2442 |
|
| 2443 |
DefineTAction(TurnOn) |
| 2444 |
; |
| 2445 |
|
| 2446 |
DefineTAction(TurnOff) |
| 2447 |
; |
| 2448 |
|
| 2449 |
DefineTAction(Light) |
| 2450 |
; |
| 2451 |
|
| 2452 |
DefineTAction(Burn) |
| 2453 |
; |
| 2454 |
|
| 2455 |
DefineTIAction(BurnWith) |
| 2456 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2457 |
getAllIobj(actor, scopeList) |
| 2458 |
{ |
| 2459 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2460 |
} |
| 2461 |
|
| 2462 |
/* resolve the direct object first */ |
| 2463 |
resolveFirst = DirectObject |
| 2464 |
; |
| 2465 |
|
| 2466 |
DefineTAction(Extinguish) |
| 2467 |
; |
| 2468 |
|
| 2469 |
DefineTIAction(AttachTo) |
| 2470 |
; |
| 2471 |
|
| 2472 |
DefineTIAction(DetachFrom) |
| 2473 |
; |
| 2474 |
|
| 2475 |
DefineTAction(Detach) |
| 2476 |
; |
| 2477 |
|
| 2478 |
DefineTAction(Break) |
| 2479 |
; |
| 2480 |
|
| 2481 |
DefineTAction(Cut) |
| 2482 |
; |
| 2483 |
|
| 2484 |
DefineTIAction(CutWith) |
| 2485 |
; |
| 2486 |
|
| 2487 |
DefineTAction(Climb) |
| 2488 |
; |
| 2489 |
|
| 2490 |
DefineTAction(ClimbUp) |
| 2491 |
; |
| 2492 |
|
| 2493 |
DefineTAction(ClimbDown) |
| 2494 |
; |
| 2495 |
|
| 2496 |
DefineTAction(Open) |
| 2497 |
; |
| 2498 |
|
| 2499 |
DefineTAction(Close) |
| 2500 |
; |
| 2501 |
|
| 2502 |
DefineTAction(Lock) |
| 2503 |
; |
| 2504 |
|
| 2505 |
DefineTAction(Unlock) |
| 2506 |
; |
| 2507 |
|
| 2508 |
DefineTIAction(LockWith) |
| 2509 |
/* |
| 2510 |
* Resolve the direct object (the lock) first, so that we know what |
| 2511 |
* we're trying to unlock when we're verifying the key. This allows |
| 2512 |
* us to (optionally) boost the likelihood of a known good key for |
| 2513 |
* disambiguation. |
| 2514 |
*/ |
| 2515 |
resolveFirst = DirectObject |
| 2516 |
|
| 2517 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2518 |
getAllIobj(actor, scopeList) |
| 2519 |
{ |
| 2520 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2521 |
} |
| 2522 |
; |
| 2523 |
|
| 2524 |
DefineTIAction(UnlockWith) |
| 2525 |
/* resolve the direct object first, for the same reason as in LockWith */ |
| 2526 |
resolveFirst = DirectObject |
| 2527 |
|
| 2528 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2529 |
getAllIobj(actor, scopeList) |
| 2530 |
{ |
| 2531 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2532 |
} |
| 2533 |
; |
| 2534 |
|
| 2535 |
DefineTAction(Eat) |
| 2536 |
; |
| 2537 |
|
| 2538 |
DefineTAction(Drink) |
| 2539 |
; |
| 2540 |
|
| 2541 |
DefineTAction(Pour) |
| 2542 |
; |
| 2543 |
|
| 2544 |
DefineTIAction(PourInto) |
| 2545 |
; |
| 2546 |
|
| 2547 |
DefineTIAction(PourOnto) |
| 2548 |
; |
| 2549 |
|
| 2550 |
DefineTAction(Clean) |
| 2551 |
; |
| 2552 |
|
| 2553 |
DefineTIAction(CleanWith) |
| 2554 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2555 |
getAllIobj(actor, scopeList) |
| 2556 |
{ |
| 2557 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2558 |
} |
| 2559 |
; |
| 2560 |
|
| 2561 |
DefineIAction(Sit) |
| 2562 |
execAction() |
| 2563 |
{ |
| 2564 |
/* |
| 2565 |
* if the actor is already sitting, just say so; otherwise, ask |
| 2566 |
* what they want to sit on |
| 2567 |
*/ |
| 2568 |
if (gActor.posture == sitting) |
| 2569 |
reportFailure(&alreadySittingMsg); |
| 2570 |
else |
| 2571 |
askForDobj(SitOn); |
| 2572 |
} |
| 2573 |
; |
| 2574 |
|
| 2575 |
DefineTAction(SitOn) |
| 2576 |
; |
| 2577 |
|
| 2578 |
DefineIAction(Lie) |
| 2579 |
execAction() |
| 2580 |
{ |
| 2581 |
/* |
| 2582 |
* if the actor is already lying down, just say so; otherwise, |
| 2583 |
* ask what they want to lie on |
| 2584 |
*/ |
| 2585 |
if (gActor.posture == lying) |
| 2586 |
reportFailure(&alreadyLyingMsg); |
| 2587 |
else |
| 2588 |
askForDobj(LieOn); |
| 2589 |
} |
| 2590 |
; |
| 2591 |
|
| 2592 |
DefineTAction(LieOn) |
| 2593 |
; |
| 2594 |
|
| 2595 |
DefineTAction(StandOn) |
| 2596 |
; |
| 2597 |
|
| 2598 |
DefineIAction(Stand) |
| 2599 |
execAction() |
| 2600 |
{ |
| 2601 |
/* let the actor handle it */ |
| 2602 |
gActor.standUp(); |
| 2603 |
} |
| 2604 |
; |
| 2605 |
|
| 2606 |
DefineTAction(Board) |
| 2607 |
; |
| 2608 |
|
| 2609 |
DefineTAction(GetOutOf) |
| 2610 |
getAllDobj(actor, scopeList) |
| 2611 |
{ |
| 2612 |
/* 'all' for 'get out of' is the actor's immediate container */ |
| 2613 |
return scopeList.subset({x: actor.isDirectlyIn(x)}); |
| 2614 |
} |
| 2615 |
; |
| 2616 |
|
| 2617 |
DefineTAction(GetOffOf) |
| 2618 |
getAllDobj(actor, scopeList) |
| 2619 |
{ |
| 2620 |
/* 'all' for 'get off of' is the actor's immediate container */ |
| 2621 |
return scopeList.subset({x: actor.isDirectlyIn(x)}); |
| 2622 |
} |
| 2623 |
; |
| 2624 |
|
| 2625 |
DefineIAction(GetOut) |
| 2626 |
execAction() |
| 2627 |
{ |
| 2628 |
/* let the actor handle it */ |
| 2629 |
gActor.disembark(); |
| 2630 |
} |
| 2631 |
; |
| 2632 |
|
| 2633 |
DefineTAction(Fasten) |
| 2634 |
; |
| 2635 |
|
| 2636 |
DefineTIAction(FastenTo) |
| 2637 |
; |
| 2638 |
|
| 2639 |
DefineTAction(Unfasten) |
| 2640 |
; |
| 2641 |
|
| 2642 |
DefineTIAction(UnfastenFrom) |
| 2643 |
; |
| 2644 |
|
| 2645 |
DefineTAction(PlugIn) |
| 2646 |
; |
| 2647 |
|
| 2648 |
DefineTIAction(PlugInto) |
| 2649 |
; |
| 2650 |
|
| 2651 |
DefineTAction(Unplug) |
| 2652 |
; |
| 2653 |
|
| 2654 |
DefineTIAction(UnplugFrom) |
| 2655 |
; |
| 2656 |
|
| 2657 |
DefineTAction(Screw) |
| 2658 |
; |
| 2659 |
|
| 2660 |
DefineTIAction(ScrewWith) |
| 2661 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2662 |
getAllIobj(actor, scopeList) |
| 2663 |
{ |
| 2664 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2665 |
} |
| 2666 |
; |
| 2667 |
|
| 2668 |
DefineTAction(Unscrew) |
| 2669 |
; |
| 2670 |
|
| 2671 |
DefineTIAction(UnscrewWith) |
| 2672 |
/* limit 'all' for the indirect object to items in inventory */ |
| 2673 |
getAllIobj(actor, scopeList) |
| 2674 |
{ |
| 2675 |
return scopeList.subset({x: x.isIn(actor)}); |
| 2676 |
} |
| 2677 |
; |
| 2678 |
|
| 2679 |
/* ------------------------------------------------------------------------ */ |
| 2680 |
/* |
| 2681 |
* Travel Action - this is the base class for verbs that attempt to move |
| 2682 |
* an actor to a new location via one of the directional connections |
| 2683 |
* from the current location. |
| 2684 |
* |
| 2685 |
* Each grammar rule for this action must set the 'dirMatch' property to |
| 2686 |
* a DirectionProd match object that gives the direction. |
| 2687 |
*/ |
| 2688 |
DefineIAction(Travel) |
| 2689 |
execAction() |
| 2690 |
{ |
| 2691 |
local conn; |
| 2692 |
|
| 2693 |
/* |
| 2694 |
* Perform the travel via the connector, if we have one. If |
| 2695 |
* there's no connector defined for this direction, show a |
| 2696 |
* default "you can't go that way" message. |
| 2697 |
*/ |
| 2698 |
if ((conn = getConnector()) != nil) |
| 2699 |
{ |
| 2700 |
/* |
| 2701 |
* we have a connector - use the pseudo-action TravelVia with |
| 2702 |
* the connector to carry out the travel |
| 2703 |
*/ |
| 2704 |
replaceAction(TravelVia, conn); |
| 2705 |
} |
| 2706 |
else |
| 2707 |
{ |
| 2708 |
/* no connector - show a default "can't go that way" error */ |
| 2709 |
mainReport(&cannotGoThatWayMsg); |
| 2710 |
} |
| 2711 |
} |
| 2712 |
|
| 2713 |
/* get the direction object for the travel */ |
| 2714 |
getDirection() { return dirMatch != nil ? dirMatch.dir : nil; } |
| 2715 |
|
| 2716 |
/* |
| 2717 |
* Get my travel connector. My connector is given by the travel |
| 2718 |
* link property for this action as defined in the actor's current |
| 2719 |
* location. |
| 2720 |
*/ |
| 2721 |
getConnector() |
| 2722 |
{ |
| 2723 |
/* ask the location for the connector in my direction */ |
| 2724 |
return gActor.location == nil |
| 2725 |
? nil |
| 2726 |
: gActor.location.getTravelConnector(getDirection(), gActor); |
| 2727 |
} |
| 2728 |
|
| 2729 |
/* |
| 2730 |
* The grammar rules for the individual directions will usually just |
| 2731 |
* create a base TravelAction object, rather than one of the |
| 2732 |
* direction-specific subclasses (NorthAction, etc). For |
| 2733 |
* convenience in testing the action, though, treat ourself as |
| 2734 |
* matching the subclass with the same direction. |
| 2735 |
*/ |
| 2736 |
actionOfKind(cls) |
| 2737 |
{ |
| 2738 |
/* |
| 2739 |
* If they're asking about a specific-direction TravelAction |
| 2740 |
* subclass, then we match it if our own direction matches that |
| 2741 |
* of the given subclass, and we fail to match if our direction |
| 2742 |
* doesn't match the given direction. |
| 2743 |
*/ |
| 2744 |
if (cls.ofKind(TravelAction) && cls.getDirection() != nil) |
| 2745 |
{ |
| 2746 |
/* we match if and only if the direction matches */ |
| 2747 |
return (getDirection() == cls.getDirection()); |
| 2748 |
} |
| 2749 |
|
| 2750 |
/* otherwise, inherit the default handling */ |
| 2751 |
return inherited(cls); |
| 2752 |
} |
| 2753 |
; |
| 2754 |
|
| 2755 |
/* for a vague command such as GO, which doesn't say where to go */ |
| 2756 |
DefineIAction(VagueTravel) |
| 2757 |
execAction() |
| 2758 |
{ |
| 2759 |
/* simply ask for a direction */ |
| 2760 |
reportFailure(&whereToGoMsg); |
| 2761 |
} |
| 2762 |
; |
| 2763 |
|
| 2764 |
/* |
| 2765 |
* This class makes it convenient to synthesize a TravelAction given a |
| 2766 |
* Direction object. To create a travel action for a direction, use |
| 2767 |
* |
| 2768 |
*. new TravelDirAction(direction) |
| 2769 |
* |
| 2770 |
* where 'direction' is the direction object (northDirection, etc) for |
| 2771 |
* the desired direction of travel. Note that if you want to use the |
| 2772 |
* resulting object in replaceAction() or one of the similar macros, |
| 2773 |
* you'll need to go directly to the underlying function rather than |
| 2774 |
* using the standard macro, since the macros expect a literal action |
| 2775 |
* name rather than an object. For example: |
| 2776 |
* |
| 2777 |
*. _replaceAction(gActor, new TravelDirAction(getDirection)); |
| 2778 |
*/ |
| 2779 |
DefineAction(TravelDir, TravelAction) |
| 2780 |
construct(dir) |
| 2781 |
{ |
| 2782 |
/* remember my direction */ |
| 2783 |
dir_ = dir; |
| 2784 |
} |
| 2785 |
|
| 2786 |
/* get my direction */ |
| 2787 |
getDirection() { return dir_; } |
| 2788 |
|
| 2789 |
/* my direction, normally specified during construction */ |
| 2790 |
dir_ = nil |
| 2791 |
; |
| 2792 |
|
| 2793 |
/* |
| 2794 |
* To make it more convenient to use directional travel actions as |
| 2795 |
* synthesized commands, define a set of action classes for the specific |
| 2796 |
* directions. |
| 2797 |
*/ |
| 2798 |
DefineAction(North, TravelAction) |
| 2799 |
getDirection = northDirection |
| 2800 |
; |
| 2801 |
DefineAction(South, TravelAction) |
| 2802 |
getDirection = southDirection |
| 2803 |
; |
| 2804 |
DefineAction(East, TravelAction) |
| 2805 |
getDirection = eastDirection |
| 2806 |
; |
| 2807 |
DefineAction(West, TravelAction) |
| 2808 |
getDirection = westDirection |
| 2809 |
; |
| 2810 |
DefineAction(Northeast, TravelAction) |
| 2811 |
getDirection = northeastDirection |
| 2812 |
; |
| 2813 |
DefineAction(Northwest, TravelAction) |
| 2814 |
getDirection = northwestDirection |
| 2815 |
; |
| 2816 |
DefineAction(Southeast, TravelAction) |
| 2817 |
getDirection = southeastDirection |
| 2818 |
; |
| 2819 |
DefineAction(Southwest, TravelAction) |
| 2820 |
getDirection = southwestDirection |
| 2821 |
; |
| 2822 |
DefineAction(In, TravelAction) |
| 2823 |
getDirection = inDirection |
| 2824 |
; |
| 2825 |
DefineAction(Out, TravelAction) |
| 2826 |
getDirection = outDirection |
| 2827 |
; |
| 2828 |
DefineAction(Up, TravelAction) |
| 2829 |
getDirection = upDirection |
| 2830 |
; |
| 2831 |
DefineAction(Down, TravelAction) |
| 2832 |
getDirection = downDirection |
| 2833 |
; |
| 2834 |
DefineAction(Fore, TravelAction) |
| 2835 |
getDirection = foreDirection |
| 2836 |
; |
| 2837 |
DefineAction(Aft, TravelAction) |
| 2838 |
getDirection = aftDirection |
| 2839 |
; |
| 2840 |
DefineAction(Port, TravelAction) |
| 2841 |
getDirection = portDirection |
| 2842 |
; |
| 2843 |
DefineAction(Starboard, TravelAction) |
| 2844 |
getDirection = starboardDirection |
| 2845 |
; |
| 2846 |
|
| 2847 |
/* |
| 2848 |
* Non-directional travel actions |
| 2849 |
*/ |
| 2850 |
|
| 2851 |
DefineTAction(GoThrough) |
| 2852 |
; |
| 2853 |
|
| 2854 |
DefineTAction(Enter) |
| 2855 |
; |
| 2856 |
|
| 2857 |
/* |
| 2858 |
* An internal action for traveling via a connector. This isn't a real |
| 2859 |
* action, and shouldn't have a grammar defined for it. The purpose of |
| 2860 |
* this action is to allow real actions that cause travel via a |
| 2861 |
* connector to be implemented by mapping to this internal action, which |
| 2862 |
* we implement on the base travel connector class. |
| 2863 |
*/ |
| 2864 |
DefineTAction(TravelVia) |
| 2865 |
/* |
| 2866 |
* The direct object of this synthetic action isn't necessarily an |
| 2867 |
* ordinary simulation object: it could be a TravelConnector instead. |
| 2868 |
* Since callers asking for a direct object almost always expect a |
| 2869 |
* simulation object, returning a non-simulation object here can be |
| 2870 |
* problematic. To avoid this, we return an empty object list by |
| 2871 |
* default - this ensures that no one who asks for the direct object |
| 2872 |
* of the verb will get back a non-simulation travel connector. |
| 2873 |
*/ |
| 2874 |
getCurrentObjects = [] |
| 2875 |
; |
| 2876 |
|
| 2877 |
/* "go back" */ |
| 2878 |
DefineIAction(GoBack) |
| 2879 |
execAction() |
| 2880 |
{ |
| 2881 |
/* ask the actor to handle it */ |
| 2882 |
gActor.reverseLastTravel(); |
| 2883 |
} |
| 2884 |
; |
| 2885 |
|
| 2886 |
/* ------------------------------------------------------------------------ */ |
| 2887 |
/* |
| 2888 |
* Combined pushing-and-traveling action ("push crate north", "drag sled |
| 2889 |
* into cave"). All of these are based on a base action class, which |
| 2890 |
* defines the methods invoked on the object being pushed; the |
| 2891 |
* subclasses provide a definition of the connector that determines |
| 2892 |
* where the travel takes us. |
| 2893 |
*/ |
| 2894 |
DefineTAction(PushTravel) |
| 2895 |
/* |
| 2896 |
* Carry out the nested travel action for the special combination |
| 2897 |
* push-traveler. This should carry out the same action we would |
| 2898 |
* have performed for the underlying basic travel. |
| 2899 |
* |
| 2900 |
* This method is invoked by the TravelPushable to carry out a |
| 2901 |
* push-travel action. The TravelPushable object will first set up |
| 2902 |
* a PushTraveler as the actor's global traveler, and it will then |
| 2903 |
* invoke this method to carry out the actual travel with that |
| 2904 |
* special traveler in effect. Our job is to provide the mapping to |
| 2905 |
* the correct underlying simple travel action; since we'll be |
| 2906 |
* moving the PushTraveler object, we can move it using the ordinary |
| 2907 |
* non-push travel action as though it were any other traveler. |
| 2908 |
* |
| 2909 |
* This method is abstract - each subclass must define it |
| 2910 |
* appropriately. |
| 2911 |
*/ |
| 2912 |
// performTravel() { } |
| 2913 |
; |
| 2914 |
|
| 2915 |
/* |
| 2916 |
* For directional push-and-travel commands, we define a common base |
| 2917 |
* class that does the work to find the connector based on the room's |
| 2918 |
* directional connector. |
| 2919 |
* |
| 2920 |
* Subclasses for grammar rules must define the 'dirMatch' property to |
| 2921 |
* be a DirectionProd object for the associated direction. |
| 2922 |
*/ |
| 2923 |
DefineAction(PushTravelDir, PushTravelAction) |
| 2924 |
/* |
| 2925 |
* Get the direction we're going. By default, we return the |
| 2926 |
* direction associated with the dirMatch match object from our |
| 2927 |
* grammar match. |
| 2928 |
*/ |
| 2929 |
getDirection() { return dirMatch.dir; } |
| 2930 |
|
| 2931 |
/* carry out the nested travel action for a PushTravel */ |
| 2932 |
performTravel() |
| 2933 |
{ |
| 2934 |
local conn; |
| 2935 |
|
| 2936 |
/* ask the actor's location for the connector in our direction */ |
| 2937 |
conn = gActor.location.getTravelConnector(getDirection(), gActor); |
| 2938 |
|
| 2939 |
/* perform a nested TravelVia on the connector */ |
| 2940 |
nestedAction(TravelVia, conn); |
| 2941 |
} |
| 2942 |
; |
| 2943 |
|
| 2944 |
/* |
| 2945 |
* To make it easy to synthesize actions for pushing objects, define |
| 2946 |
* individual subclasses for the various directions. |
| 2947 |
*/ |
| 2948 |
DefineAction(PushNorth, PushTravelDirAction) |
| 2949 |
getDirection = northDirection |
| 2950 |
; |
| 2951 |
|
| 2952 |
DefineAction(PushSouth, PushTravelDirAction) |
| 2953 |
getDirection = southDirection |
| 2954 |
; |
| 2955 |
|
| 2956 |
DefineAction(PushEast, PushTravelDirAction) |
| 2957 |
getDirection = eastDirection |
| 2958 |
; |
| 2959 |
|
| 2960 |
DefineAction(PushWest, PushTravelDirAction) |
| 2961 |
getDirection = westDirection |
| 2962 |
; |
| 2963 |
|
| 2964 |
DefineAction(PushNorthwest, PushTravelDirAction) |
| 2965 |
getDirection = northwestDirection |
| 2966 |
; |
| 2967 |
|
| 2968 |
DefineAction(PushNortheast, PushTravelDirAction) |
| 2969 |
getDirection = northeastDirection |
| 2970 |
; |
| 2971 |
|
| 2972 |
DefineAction(PushSouthwest, PushTravelDirAction) |
| 2973 |
getDirection = southwestDirection |
| 2974 |
; |
| 2975 |
|
| 2976 |
DefineAction(PushSoutheast, PushTravelDirAction) |
| 2977 |
getDirection = southeastDirection |
| 2978 |
; |
| 2979 |
|
| 2980 |
DefineAction(PushUp, PushTravelDirAction) |
| 2981 |
getDirection = upDirection |
| 2982 |
; |
| 2983 |
|
| 2984 |
DefineAction(PushDown, PushTravelDirAction) |
| 2985 |
getDirection = downDirection |
| 2986 |
; |
| 2987 |
|
| 2988 |
DefineAction(PushIn, PushTravelDirAction) |
| 2989 |
getDirection = inDirection |
| 2990 |
; |
| 2991 |
|
| 2992 |
DefineAction(PushOut, PushTravelDirAction) |
| 2993 |
getDirection = outDirection |
| 2994 |
; |
| 2995 |
|
| 2996 |
DefineAction(PushFore, PushTravelDirAction) |
| 2997 |
getDirection = foreDirection |
| 2998 |
; |
| 2999 |
|
| 3000 |
DefineAction(PushAft, PushTravelDirAction) |
| 3001 |
getDirection = aftDirection |
| 3002 |
; |
| 3003 |
|
| 3004 |
DefineAction(PushPort, PushTravelDirAction) |
| 3005 |
getDirection = portDirection |
| 3006 |
; |
| 3007 |
|
| 3008 |
DefineAction(PushStarboard, PushTravelDirAction) |
| 3009 |
getDirection = starboardDirection |
| 3010 |
; |
| 3011 |
|
| 3012 |
/* |
| 3013 |
* Base class for two-object push-travel commands, such as "push boulder |
| 3014 |
* out of cave" or "drag sled up hill". For all of these, the connector |
| 3015 |
* is given by the indirect object. |
| 3016 |
*/ |
| 3017 |
DefineAction(PushTravelViaIobj, TIAction, PushTravelAction) |
| 3018 |
/* |
| 3019 |
* Verify the indirect object of the push-travel action. We'll |
| 3020 |
* remap this to given corresponding simple travel action, and call |
| 3021 |
* that action's verifier. |
| 3022 |
*/ |
| 3023 |
verifyPushTravelIobj(obj, action) |
| 3024 |
{ |
| 3025 |
/* handle this by remapping it to the underlying simple action */ |
| 3026 |
remapVerify(IndirectObject, gVerifyResults, [action, obj]); |
| 3027 |
} |
| 3028 |
; |
| 3029 |
|
| 3030 |
DefineTIActionSub(PushTravelThrough, PushTravelViaIobjAction) |
| 3031 |
/* |
| 3032 |
* Carry out the underlying simple travel action. This simply |
| 3033 |
* performs a GoThrough on my indirect object, as though we had |
| 3034 |
* typed simply GO THROUGH iobj. The PushTraveler will already be |
| 3035 |
* set up as the actor's special traveler, so the ordinary GO |
| 3036 |
* THROUGH command will move the special PushTraveler object as |
| 3037 |
* though it were the original actor. |
| 3038 |
*/ |
| 3039 |
performTravel() { nestedAction(GoThrough, getIobj()); } |
| 3040 |
; |
| 3041 |
|
| 3042 |
DefineTIActionSub(PushTravelEnter, PushTravelViaIobjAction) |
| 3043 |
/* carry out the underlying simple travel as an ENTER action */ |
| 3044 |
performTravel() { nestedAction(Enter, getIobj()); } |
| 3045 |
; |
| 3046 |
|
| 3047 |
DefineTIActionSub(PushTravelGetOutOf, PushTravelViaIobjAction) |
| 3048 |
/* carry out the underlying simple travel as a GET OUT OF action */ |
| 3049 |
performTravel() { nestedAction(GetOutOf, getIobj()); } |
| 3050 |
; |
| 3051 |
|
| 3052 |
DefineTIActionSub(PushTravelClimbUp, PushTravelViaIobjAction) |
| 3053 |
/* carry out the underlying simple travel as a CLIMB UP action */ |
| 3054 |
performTravel() { nestedAction(ClimbUp, getIobj()); } |
| 3055 |
; |
| 3056 |
|
| 3057 |
DefineTIActionSub(PushTravelClimbDown, PushTravelViaIobjAction) |
| 3058 |
/* carry out the underlying simple travel as an CLIMB DOWN action */ |
| 3059 |
performTravel() { nestedAction(ClimbDown, getIobj()); } |
| 3060 |
; |
| 3061 |
|
| 3062 |
/* |
| 3063 |
* The "exits" verb. This verb explicitly shows all of the exits from |
| 3064 |
* the current location. |
| 3065 |
*/ |
| 3066 |
DefineIAction(Exits) |
| 3067 |
execAction() |
| 3068 |
{ |
| 3069 |
/* |
| 3070 |
* if we have an exit lister object, invoke it; otherwise, |
| 3071 |
* explain that this command isn't supported in this game |
| 3072 |
*/ |
| 3073 |
if (gExitLister != nil) |
| 3074 |
gExitLister.showExitsCommand(); |
| 3075 |
else |
| 3076 |
gLibMessages.commandNotPresent; |
| 3077 |
} |
| 3078 |
; |
| 3079 |
|
| 3080 |
/* in case the exits module isn't included */ |
| 3081 |
property showExitsCommand, exitsOnOffCommand; |
| 3082 |
|
| 3083 |
/* |
| 3084 |
* Change the exit display mode. The grammar must set one of the mode |
| 3085 |
* token properties to a non-nil value, according to which mode the |
| 3086 |
* player selected: on_ for turning on statusline and description lists; |
| 3087 |
* stat_ for turning on only the statusline list; look_ for turning on |
| 3088 |
* only the room description list; and off_ for turning off everything. |
| 3089 |
*/ |
| 3090 |
DefineSystemAction(ExitsMode) |
| 3091 |
execSystemAction() |
| 3092 |
{ |
| 3093 |
local stat, look; |
| 3094 |
|
| 3095 |
/* |
| 3096 |
* If it's EXITS ON, turn on both statusline and room description |
| 3097 |
* lists. If it's EXITS LOOK or EXITS STATUS, just turn on one |
| 3098 |
* or the other. Otherwise, turn both off. |
| 3099 |
*/ |
| 3100 |
stat = (stat_ != nil || on_ != nil); |
| 3101 |
look = (look_ != nil || on_ != nil); |
| 3102 |
|
| 3103 |
/* update the exit display */ |
| 3104 |
if (gExitLister != nil) |
| 3105 |
gExitLister.exitsOnOffCommand(stat, look); |
| 3106 |
else |
| 3107 |
gLibMessages.commandNotPresent; |
| 3108 |
} |
| 3109 |
; |
| 3110 |
|
| 3111 |
/* |
| 3112 |
* Dummy OOPS action for times when OOPS isn't in context. We'll simply |
| 3113 |
* explain how OOPS works, and that you can't use it right now. |
| 3114 |
*/ |
| 3115 |
DefineLiteralAction(Oops) |
| 3116 |
execAction() |
| 3117 |
{ |
| 3118 |
/* simply explain how this command works */ |
| 3119 |
gLibMessages.oopsOutOfContext; |
| 3120 |
} |
| 3121 |
|
| 3122 |
/* this is a meta-command, so don't consume any time */ |
| 3123 |
actionTime = 0 |
| 3124 |
; |
| 3125 |
|
| 3126 |
/* intransitive form of "oops" */ |
| 3127 |
DefineIAction(OopsI) |
| 3128 |
doActionMain() |
| 3129 |
{ |
| 3130 |
/* as with OOPS with a literal, simply explain the problem */ |
| 3131 |
gLibMessages.oopsOutOfContext; |
| 3132 |
} |
| 3133 |
|
| 3134 |
/* this is a meta-command, so don't consume any time */ |
| 3135 |
actionTime = 0 |
| 3136 |
; |
| 3137 |
|
| 3138 |
property disableHints, showHints; |
| 3139 |
|
| 3140 |
/* hint system - disable hints for this session */ |
| 3141 |
DefineSystemAction(HintsOff) |
| 3142 |
execSystemAction() |
| 3143 |
{ |
| 3144 |
if (gHintManager != nil) |
| 3145 |
gHintManager.disableHints(); |
| 3146 |
else |
| 3147 |
mainReport(gLibMessages.hintsNotPresent); |
| 3148 |
} |
| 3149 |
; |
| 3150 |
|
| 3151 |
/* invoke hint system */ |
| 3152 |
DefineSystemAction(Hint) |
| 3153 |
execSystemAction() |
| 3154 |
{ |
| 3155 |
if (gHintManager != nil) |
| 3156 |
gHintManager.showHints(); |
| 3157 |
else |
| 3158 |
mainReport(gLibMessages.hintsNotPresent); |
| 3159 |
} |
| 3160 |
; |
| 3161 |
|
| 3162 |
/* ------------------------------------------------------------------------ */ |
| 3163 |
/* |
| 3164 |
* Parser debugging verbs |
| 3165 |
*/ |
| 3166 |
|
| 3167 |
#ifdef PARSER_DEBUG |
| 3168 |
|
| 3169 |
DefineIAction(ParseDebug) |
| 3170 |
execAction() |
| 3171 |
{ |
| 3172 |
local newMode; |
| 3173 |
|
| 3174 |
/* |
| 3175 |
* get the mode - if the mode is explicitly stated in the |
| 3176 |
* command, use the stated new mode, otherwise invert the current |
| 3177 |
* mode |
| 3178 |
*/ |
| 3179 |
newMode = (onOrOff_ == 'on' |
| 3180 |
? true |
| 3181 |
: onOrOff_ == 'off' |
| 3182 |
? nil |
| 3183 |
: !libGlobal.parserDebugMode); |
| 3184 |
|
| 3185 |
/* set the new mode */ |
| 3186 |
libGlobal.parserDebugMode = newMode; |
| 3187 |
|
| 3188 |
/* mention the change */ |
| 3189 |
"Parser debugging is now |
| 3190 |
<<libGlobal.parserDebugMode ? 'on' : 'off'>>.\n"; |
| 3191 |
} |
| 3192 |
; |
| 3193 |
|
| 3194 |
grammar predicate(ParseDebug): |
| 3195 |
'parse-debug' 'on'->onOrOff_ |
| 3196 |
| 'parse-debug' 'off'->onOrOff_ |
| 3197 |
| 'parse-debug' |
| 3198 |
: ParseDebugAction |
| 3199 |
; |
| 3200 |
|
| 3201 |
#endif |
| 3202 |
|