| 1 |
#charset "us-ascii" |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (c) 2000, 2006 by Michael J. Roberts. All Rights Reserved. |
| 5 |
* |
| 6 |
* TADS 3 Library - Thing |
| 7 |
* |
| 8 |
* This module defines Thing, the base class for physical objects in the |
| 9 |
* simulation. We also define some utility classes that Thing uses |
| 10 |
* internally. |
| 11 |
*/ |
| 12 |
|
| 13 |
/* include the library header */ |
| 14 |
#include "adv3.h" |
| 15 |
|
| 16 |
|
| 17 |
/* ------------------------------------------------------------------------ */ |
| 18 |
/* |
| 19 |
* this property is defined in the 'exits' module, but declare it here |
| 20 |
* in case we're not including the 'exits' module |
| 21 |
*/ |
| 22 |
property lookAroundShowExits; |
| 23 |
|
| 24 |
|
| 25 |
/* ------------------------------------------------------------------------ */ |
| 26 |
/* |
| 27 |
* Sense Information entry. Thing.senseInfoTable() returns a list of |
| 28 |
* these objects to provide full sensory detail on the objects within |
| 29 |
* range of a sense. |
| 30 |
*/ |
| 31 |
class SenseInfo: object |
| 32 |
construct(obj, trans, obstructor, ambient) |
| 33 |
{ |
| 34 |
/* set the object being described */ |
| 35 |
self.obj = obj; |
| 36 |
|
| 37 |
/* remember the transparency and obstructor */ |
| 38 |
self.trans = trans; |
| 39 |
self.obstructor = obstructor; |
| 40 |
|
| 41 |
/* |
| 42 |
* set the energy level, as seen from the point of view - adjust |
| 43 |
* the level by the transparency |
| 44 |
*/ |
| 45 |
self.ambient = (ambient != nil |
| 46 |
? adjustBrightness(ambient, trans) |
| 47 |
: nil); |
| 48 |
} |
| 49 |
|
| 50 |
/* the object being sensed */ |
| 51 |
obj = nil |
| 52 |
|
| 53 |
/* the transparency from the point of view to this object */ |
| 54 |
trans = nil |
| 55 |
|
| 56 |
/* the obstructor that introduces a non-transparent value of trans */ |
| 57 |
obstructor = nil |
| 58 |
|
| 59 |
/* the ambient sense energy level at this object */ |
| 60 |
ambient = nil |
| 61 |
|
| 62 |
/* |
| 63 |
* compare this SenseInfo object's transparency to the other one; |
| 64 |
* returns a number greater than zero if 'self' is more transparent, |
| 65 |
* zero if they're equally transparent, or a negative number if |
| 66 |
* 'self' is less transparent |
| 67 |
*/ |
| 68 |
compareTransTo(other) { return transparencyCompare(trans, other.trans); } |
| 69 |
|
| 70 |
/* |
| 71 |
* Return the more transparent of two SenseInfo objects. Either |
| 72 |
* argument can be nil, in which case we'll return the non-nil one; |
| 73 |
* if both are nil, we'll return nil. If they're equal, we'll return |
| 74 |
* the first one. |
| 75 |
*/ |
| 76 |
selectMoreTrans(a, b) |
| 77 |
{ |
| 78 |
/* if one or the other is nil, return the non-nil one */ |
| 79 |
if (a == nil) |
| 80 |
return b; |
| 81 |
else if (b == nil) |
| 82 |
return a; |
| 83 |
else if (a.compareTransTo(b) >= 0) |
| 84 |
return a; |
| 85 |
else |
| 86 |
return b; |
| 87 |
} |
| 88 |
; |
| 89 |
|
| 90 |
/* |
| 91 |
* Can-Touch information. This object keeps track of whether or not a |
| 92 |
* given object is able to reach out and touch another object. |
| 93 |
*/ |
| 94 |
class CanTouchInfo: object |
| 95 |
/* construct, given the touch path */ |
| 96 |
construct(path) { touchPath = path; } |
| 97 |
|
| 98 |
/* the full reach-and-touch path from the source to the target */ |
| 99 |
touchPath = nil |
| 100 |
|
| 101 |
/* |
| 102 |
* if we have calculated whether or not the source can touch the |
| 103 |
* target, we'll set the property canTouch to nil or true |
| 104 |
* accordingly; if this property is left undefined, this information |
| 105 |
* has never been calculated |
| 106 |
*/ |
| 107 |
// canTouch = nil |
| 108 |
; |
| 109 |
|
| 110 |
/* |
| 111 |
* Given a sense information table (a LookupTable returned from |
| 112 |
* Thing.senseInfoTable()), return a vector of only those objects in the |
| 113 |
* table that match the given criteria. |
| 114 |
* |
| 115 |
* 'func' is a function that takes two arguments, func(obj, info), where |
| 116 |
* 'obj' is a simulation object and 'info' is the corresponding |
| 117 |
* SenseInfo object. This function is invoked for each object in the |
| 118 |
* sense info table; if 'func' returns true, then 'obj' is part of the |
| 119 |
* list that we return. |
| 120 |
* |
| 121 |
* The return value is a simple vector of game objects. (Note that |
| 122 |
* SenseInfo objects are not returned - just the simulation objects.) |
| 123 |
*/ |
| 124 |
senseInfoTableSubset(senseTab, func) |
| 125 |
{ |
| 126 |
local vec; |
| 127 |
|
| 128 |
/* set up a vector for the return list */ |
| 129 |
vec = new Vector(32); |
| 130 |
|
| 131 |
/* scan the table for objects matching criteria given by 'func' */ |
| 132 |
senseTab.forEachAssoc(function(obj, info) |
| 133 |
{ |
| 134 |
/* if the function accepts this object, include it in the vector */ |
| 135 |
if ((func)(obj, info)) |
| 136 |
vec.append(obj); |
| 137 |
}); |
| 138 |
|
| 139 |
/* return the result vector */ |
| 140 |
return vec; |
| 141 |
} |
| 142 |
|
| 143 |
/* |
| 144 |
* Sense calculation scratch-pad globals. Many of the sense |
| 145 |
* calculations involve recursive descents of portions of the |
| 146 |
* containment tree. In the course of these calculations, it's |
| 147 |
* sometimes useful to have information about the entire operation in |
| 148 |
* one of the recursive calls. We could pass the information around as |
| 149 |
* extra parameters, but that adds overhead, and performance is critical |
| 150 |
* in the sense routines (because they tend to get invoked a *lot*). To |
| 151 |
* reduce the overhead, particularly for information that's not needed |
| 152 |
* very often, we stuff some information into this global object rather |
| 153 |
* than passing it around through parameters. |
| 154 |
* |
| 155 |
* Note that this object is transient because this information is useful |
| 156 |
* only during the course of a single tree traversal, and so doesn't |
| 157 |
* need to be saved or undone. |
| 158 |
*/ |
| 159 |
transient senseTmp: object |
| 160 |
/* |
| 161 |
* The point of view of the sense calculation. This is the starting |
| 162 |
* point of a sense traversal; it's the object that's viewing the |
| 163 |
* other objects. |
| 164 |
*/ |
| 165 |
pointOfView = nil |
| 166 |
|
| 167 |
/* post-calculation notification list */ |
| 168 |
notifyList = static new Vector(16) |
| 169 |
; |
| 170 |
|
| 171 |
|
| 172 |
/* ------------------------------------------------------------------------ */ |
| 173 |
/* |
| 174 |
* Command check status object. This is an abstract object that we use |
| 175 |
* in to report results from a check of various kinds. |
| 176 |
* |
| 177 |
* The purpose of this object is to consolidate the code for certain |
| 178 |
* kinds of command checks into a single routine that can be used for |
| 179 |
* different purposes - verification, selection from multiple |
| 180 |
* possibilities (such as multiple paths), and command action |
| 181 |
* processing. This object encapsulates a status - success or failure - |
| 182 |
* and, when the status is failure, a message giving the reason for the |
| 183 |
* failure. |
| 184 |
*/ |
| 185 |
class CheckStatus: object |
| 186 |
/* did the check succeed or fail? */ |
| 187 |
isSuccess = nil |
| 188 |
|
| 189 |
/* |
| 190 |
* the message property or string, and parameters, for failure - |
| 191 |
* this is for use with reportFailure or the like |
| 192 |
*/ |
| 193 |
msgProp = nil |
| 194 |
msgParams = [] |
| 195 |
; |
| 196 |
|
| 197 |
/* |
| 198 |
* Success status object. Note that this is a single object, not a |
| 199 |
* class - there's no distinct information per success indicator, so we |
| 200 |
* only need this single success indicator for all uses. |
| 201 |
*/ |
| 202 |
checkStatusSuccess: CheckStatus |
| 203 |
isSuccess = true |
| 204 |
; |
| 205 |
|
| 206 |
/* |
| 207 |
* Failure status object. Unlike the success indicator, this is a |
| 208 |
* class, because we need to keep track of the separate failure message |
| 209 |
* for each kind of failure. |
| 210 |
*/ |
| 211 |
class CheckStatusFailure: CheckStatus |
| 212 |
construct(prop, [params]) |
| 213 |
{ |
| 214 |
isSuccess = nil; |
| 215 |
msgProp = prop; |
| 216 |
msgParams = params; |
| 217 |
} |
| 218 |
; |
| 219 |
|
| 220 |
|
| 221 |
/* ------------------------------------------------------------------------ */ |
| 222 |
/* |
| 223 |
* Equivalent group state information. This keeps track of a state and |
| 224 |
* the number of items in that state when we're listing a group of |
| 225 |
* equivalent items in different states. |
| 226 |
*/ |
| 227 |
class EquivalentStateInfo: object |
| 228 |
construct(st, obj, nameProp) |
| 229 |
{ |
| 230 |
/* remember the state object and the name property to display */ |
| 231 |
stateObj = st; |
| 232 |
stateNameProp = nameProp; |
| 233 |
|
| 234 |
/* this is the first one in this state */ |
| 235 |
stateVec = new Vector(8); |
| 236 |
stateVec.append(obj); |
| 237 |
} |
| 238 |
|
| 239 |
/* add an object to the list of equivalent objects in this state */ |
| 240 |
addEquivObj(obj) { stateVec.append(obj); } |
| 241 |
|
| 242 |
/* get the number of equivalent items in the same state */ |
| 243 |
getEquivCount() { return stateVec.length(); } |
| 244 |
|
| 245 |
/* get the list of equivalent items in the same state */ |
| 246 |
getEquivList() { return stateVec; } |
| 247 |
|
| 248 |
/* get the name to use for listing purposes */ |
| 249 |
getName() { return stateObj.(stateNameProp)(stateVec); } |
| 250 |
|
| 251 |
/* the ThingState object describing the state */ |
| 252 |
stateObj = nil |
| 253 |
|
| 254 |
/* the property to evaluate to get the name for listing purposes */ |
| 255 |
stateNameProp = nil |
| 256 |
|
| 257 |
/* list of items in this same state */ |
| 258 |
stateVec = nil |
| 259 |
; |
| 260 |
|
| 261 |
|
| 262 |
/* ------------------------------------------------------------------------ */ |
| 263 |
/* |
| 264 |
* Drop Descriptor. This is passed to the receiveDrop() method of a |
| 265 |
* "drop destination" when an object is discarded via commands such as |
| 266 |
* DROP or THROW. The purpose of the descriptor is to identify the type |
| 267 |
* of command being performed, so that the receiveDrop() method can |
| 268 |
* generate an appropriate report message. |
| 269 |
*/ |
| 270 |
class DropType: object |
| 271 |
/* |
| 272 |
* Generate the standard report message for the action. The drop |
| 273 |
* destination's receiveDrop() method can call this if the standard |
| 274 |
* message is adequate to describe the result of the action. |
| 275 |
* |
| 276 |
* 'obj' is the object being dropped, and 'dest' is the drop |
| 277 |
* destination. |
| 278 |
*/ |
| 279 |
// standardReport(obj, dest) { /* subclasses must override */ } |
| 280 |
|
| 281 |
/* |
| 282 |
* Get a short report describing the action without saying where the |
| 283 |
* object ended up. This is roughly the same as the standard report, |
| 284 |
* but omits any information on where the object lands, so that the |
| 285 |
* caller can show a separate message explaining that part. |
| 286 |
* |
| 287 |
* The report must be worded such that the object being dropped is |
| 288 |
* the logical antecedent for any subsequent text. This means that |
| 289 |
* callers can use a pronoun to refer back to the object dropped, |
| 290 |
* allowing for more natural sequences to be constructed. (It |
| 291 |
* usually sounds stilted to repeat the full name: "You drop the box. |
| 292 |
* The box falls into the chasm." It's better if we can use a |
| 293 |
* pronoun in the second sentence: "You drop the box. It falls into |
| 294 |
* the chasm.") |
| 295 |
* |
| 296 |
* 'obj' is the object being dropped, and 'dest' is the drop |
| 297 |
* destination. |
| 298 |
*/ |
| 299 |
// getReportPrefix(obj, dest) { return ''; } |
| 300 |
; |
| 301 |
|
| 302 |
/* |
| 303 |
* A drop-type descriptor for the DROP command. Since we have no need to |
| 304 |
* include any varying parameters in this object, we simply provide this |
| 305 |
* singleton instance. |
| 306 |
*/ |
| 307 |
dropTypeDrop: DropType |
| 308 |
standardReport(obj, dest) |
| 309 |
{ |
| 310 |
/* show the default "Dropped" response */ |
| 311 |
defaultReport(&okayDropMsg); |
| 312 |
} |
| 313 |
|
| 314 |
getReportPrefix(obj, dest) |
| 315 |
{ |
| 316 |
/* return the standard "You drop the <obj>" message */ |
| 317 |
return gActor.getActionMessageObj().droppingObjMsg(obj); |
| 318 |
} |
| 319 |
; |
| 320 |
|
| 321 |
/* |
| 322 |
* A drop-type descriptor for the THROW command. This object keeps track |
| 323 |
* of the target (the object that was hit by the projectile) and the |
| 324 |
* projectile's path to the target. The projectile is simply the direct |
| 325 |
* object. |
| 326 |
*/ |
| 327 |
class DropTypeThrow: DropType |
| 328 |
construct(target, path) |
| 329 |
{ |
| 330 |
/* remember the target and path */ |
| 331 |
target_ = target; |
| 332 |
path_ = path; |
| 333 |
} |
| 334 |
|
| 335 |
standardReport(obj, dest) |
| 336 |
{ |
| 337 |
local nominalDest; |
| 338 |
|
| 339 |
/* get the nominal drop destination */ |
| 340 |
nominalDest = dest.getNominalDropDestination(); |
| 341 |
|
| 342 |
/* |
| 343 |
* if the actual target and the nominal destination are the same, |
| 344 |
* just say that it lands on the destination; otherwise, say that |
| 345 |
* it bounces off the target and falls to the nominal destination |
| 346 |
*/ |
| 347 |
if (target_ == nominalDest) |
| 348 |
mainReport(&throwFallMsg, obj, target_); |
| 349 |
else |
| 350 |
mainReport(&throwHitFallMsg, obj, target_, nominalDest); |
| 351 |
} |
| 352 |
|
| 353 |
getReportPrefix(obj, dest) |
| 354 |
{ |
| 355 |
/* return the standard "The <projectile> hits the <target>" message */ |
| 356 |
return gActor.getActionMessageObj().throwHitMsg(obj, target_); |
| 357 |
} |
| 358 |
|
| 359 |
/* the object that was hit by the projectile */ |
| 360 |
target_ = nil |
| 361 |
|
| 362 |
/* the path the projectile took to reach the target */ |
| 363 |
path_ = nil |
| 364 |
; |
| 365 |
|
| 366 |
|
| 367 |
/* ------------------------------------------------------------------------ */ |
| 368 |
/* |
| 369 |
* Bag Affinity Info - this class keeps track of the affinity of a bag |
| 370 |
* of holding for an object it might contain. We use this class in |
| 371 |
* building bag affinity lists. |
| 372 |
*/ |
| 373 |
class BagAffinityInfo: object |
| 374 |
construct(obj, bulk, aff, bag) |
| 375 |
{ |
| 376 |
/* save our parameters */ |
| 377 |
obj_ = obj; |
| 378 |
bulk_ = bulk; |
| 379 |
aff_ = aff; |
| 380 |
bag_ = bag; |
| 381 |
} |
| 382 |
|
| 383 |
/* |
| 384 |
* Compare this item to another item, for affinity ranking purposes. |
| 385 |
* Returns positive if I should rank higher than the other item, |
| 386 |
* zero if we have equal ranking, negative if I rank lower than the |
| 387 |
* other item. |
| 388 |
*/ |
| 389 |
compareAffinityTo(other) |
| 390 |
{ |
| 391 |
/* |
| 392 |
* if this object is the indirect object of 'take from', treat |
| 393 |
* it as having the lowest ranking |
| 394 |
*/ |
| 395 |
if (gActionIs(TakeFrom) && gIobj == obj_) |
| 396 |
return -1; |
| 397 |
|
| 398 |
/* if we have different affinities, sort according to affinity */ |
| 399 |
if (aff_ != other.aff_) |
| 400 |
return aff_ - other.aff_; |
| 401 |
|
| 402 |
/* we have the same affinity, so put the higher bulk item first */ |
| 403 |
if (bulk_ != other.bulk_) |
| 404 |
return bulk_ - other.bulk_; |
| 405 |
|
| 406 |
/* |
| 407 |
* We have the same affinity and same bulk; rank according to |
| 408 |
* how recently the items were picked up. Put away the oldest |
| 409 |
* items first, so the lower holding (older) index has the |
| 410 |
* higher ranking. (Note that because lower holding index is |
| 411 |
* the higher ranking, we return the negative of the holding |
| 412 |
* index comparison.) |
| 413 |
*/ |
| 414 |
return other.obj_.holdingIndex - obj_.holdingIndex; |
| 415 |
} |
| 416 |
|
| 417 |
/* |
| 418 |
* given a vector of affinities, remove the most recent item (as |
| 419 |
* indicated by holdingIndex) and return the BagAffinityInfo object |
| 420 |
*/ |
| 421 |
removeMostRecent(vec) |
| 422 |
{ |
| 423 |
local best = vec[1]; |
| 424 |
|
| 425 |
/* find the most recent item */ |
| 426 |
foreach (local cur in vec) |
| 427 |
{ |
| 428 |
/* if this is better than the best so far, remember it */ |
| 429 |
if (cur.obj_.holdingIndex > best.obj_.holdingIndex) |
| 430 |
best = cur; |
| 431 |
} |
| 432 |
|
| 433 |
/* remove the best item from the vector */ |
| 434 |
vec.removeElement(best); |
| 435 |
|
| 436 |
/* return the best item */ |
| 437 |
return best; |
| 438 |
} |
| 439 |
|
| 440 |
/* the object the bag wants to contain */ |
| 441 |
obj_ = nil |
| 442 |
|
| 443 |
/* the object's bulk */ |
| 444 |
bulk_ = nil |
| 445 |
|
| 446 |
/* the bag that wants to contain the object */ |
| 447 |
bag_ = nil |
| 448 |
|
| 449 |
/* affinity of the bag for the object */ |
| 450 |
aff_ = nil |
| 451 |
; |
| 452 |
|
| 453 |
|
| 454 |
/* ------------------------------------------------------------------------ */ |
| 455 |
/* |
| 456 |
* "State" of a Thing. This is an object abstractly describing the |
| 457 |
* state of an object that can assume different states. |
| 458 |
* |
| 459 |
* The 'listName', 'inventoryName', and 'wornName' give the names of |
| 460 |
* state as displayed in room/contents listings, inventory listings, and |
| 461 |
* listings of items being worn by an actor. This state name is |
| 462 |
* displayed along with the item name (usually parenthetically after the |
| 463 |
* item name, but the exact nature of the display is controlled by the |
| 464 |
* language-specific part of the library). |
| 465 |
* |
| 466 |
* The 'listingOrder' is an integer giving the listing order of this |
| 467 |
* state relative to other states of the same kind of object. When we |
| 468 |
* show a list of equivalent items in different states, we'll order the |
| 469 |
* state names in ascending order of listingOrder. |
| 470 |
*/ |
| 471 |
class ThingState: object |
| 472 |
/* |
| 473 |
* The name of the state to use in ordinary room/object contents |
| 474 |
* listings. If the name is nil, no extra state information is shown |
| 475 |
* in a listing for an object in this state. (It's often desirable |
| 476 |
* to leave the most ordinary state an object can be in unnamed, to |
| 477 |
* avoid belaboring the obvious. For example, a match that isn't |
| 478 |
* burning would probably not want to mention "(not lit)" every time |
| 479 |
* it's listed.) |
| 480 |
* |
| 481 |
* 'lst' is a list of the objects being listed in this state. If |
| 482 |
* we're only listing a single object, this will be a list with one |
| 483 |
* element giving the object being listed. If we're listing a |
| 484 |
* counted set of equivalent items all in this same state, this will |
| 485 |
* be the list of items. Everything in 'lst' will be equivalent (in |
| 486 |
* the isEquivalent sense). |
| 487 |
*/ |
| 488 |
listName(lst) { return nil; } |
| 489 |
|
| 490 |
/* |
| 491 |
* The state name to use in inventory lists. By default, we just use |
| 492 |
* the base name. 'lst' has the same meaning as in listName(). |
| 493 |
*/ |
| 494 |
inventoryName(lst) { return listName(lst); } |
| 495 |
|
| 496 |
/* |
| 497 |
* The state name to use in listings of items being worn. By |
| 498 |
* default, we just use the base name. 'lst' has the same meaning as |
| 499 |
* in listName(). |
| 500 |
*/ |
| 501 |
wornName(lst) { return listName(lst); } |
| 502 |
|
| 503 |
/* the relative listing order */ |
| 504 |
listingOrder = 0 |
| 505 |
|
| 506 |
/* |
| 507 |
* Match the name of an object in this state. 'obj' is the object |
| 508 |
* to be matched; 'origTokens' and 'adjustedTokens' have the same |
| 509 |
* meanings they do for Thing.matchName; and 'states' is a list of |
| 510 |
* all of the possible states the object can assume. |
| 511 |
* |
| 512 |
* Implementation of this is always language-specific. In most |
| 513 |
* cases, this should do something along the lines of checking for |
| 514 |
* the presence (in the token list) of words that only apply to |
| 515 |
* other states, rejecting the match if any such words are found. |
| 516 |
* For example, the ThingState object representing the unlit state |
| 517 |
* of a light source might check for the presence of 'lit' as an |
| 518 |
* adjective, and reject the object if it's found. |
| 519 |
*/ |
| 520 |
matchName(obj, origTokens, adjustedTokens, states) |
| 521 |
{ |
| 522 |
/* by default, simply match the object */ |
| 523 |
return obj; |
| 524 |
} |
| 525 |
; |
| 526 |
|
| 527 |
/* ------------------------------------------------------------------------ */ |
| 528 |
/* |
| 529 |
* Object with vocabulary. This is the base class for any object that |
| 530 |
* can define vocabulary words. |
| 531 |
*/ |
| 532 |
class VocabObject: object |
| 533 |
/* |
| 534 |
* Match a name as used in a noun phrase in a player's command to |
| 535 |
* this object. The parser calls this routine to test this object |
| 536 |
* for a match to a noun phrase when all of the following conditions |
| 537 |
* are true: |
| 538 |
* |
| 539 |
* - this object is in scope; |
| 540 |
* |
| 541 |
* - our vocabulary matches the noun phrase, which means that ALL of |
| 542 |
* the words in the player's noun phrase are associated with this |
| 543 |
* object with the corresponding parts of speech. Note the special |
| 544 |
* wildcard vocabulary words: '#' as an adjective matches any number |
| 545 |
* used as an adjective; '*' as a noun matches any word used as any |
| 546 |
* part of speech. |
| 547 |
* |
| 548 |
* 'origTokens' is the list of the original input words making up |
| 549 |
* the noun phrase, in canonical tokenizer format. Each element of |
| 550 |
* this list is a sublist representing one token. |
| 551 |
* |
| 552 |
* 'adjustedTokens' is the "adjusted" token list, which provides |
| 553 |
* more information on how the parser is analyzing the phrase but |
| 554 |
* may not contain the exact original tokens of the command. In the |
| 555 |
* adjusted list, the tokens are represented by pairs of values in |
| 556 |
* the list: the first value of each pair is a string giving the |
| 557 |
* adjusted token text, and the second value of the pair is a |
| 558 |
* property ID giving the part of speech of the parser's |
| 559 |
* interpretation of the phrase. For example, if the noun phrase is |
| 560 |
* "red book", the list might look like ['red', &adjective, 'book', |
| 561 |
* &noun]. |
| 562 |
* |
| 563 |
* The adjusted token list in some cases contains different tokens |
| 564 |
* than the original input. For example, when the command contains |
| 565 |
* a spelled-out number, the parser will translate the spelled-out |
| 566 |
* number to a numeral format and provide the numeral string in the |
| 567 |
* adjusted token list: 'a hundred and thirty-four' will become |
| 568 |
* '134' in the adjusted token list. |
| 569 |
* |
| 570 |
* If this object does not match the noun phrase, this routine |
| 571 |
* returns nil. If the object is a match, the routine returns |
| 572 |
* 'self'. The routine can also return a different object, or even |
| 573 |
* a list of objects - in this case, the parser will consider the |
| 574 |
* noun phrase to have matched the returned object or objects rather |
| 575 |
* than this original match. |
| 576 |
* |
| 577 |
* Note that it isn't necessary to check that the input tokens match |
| 578 |
* our defined vocabulary words, because the parser will already |
| 579 |
* have done that for us. This routine is only called after the |
| 580 |
* parser has already determined that all of the noun phrase's words |
| 581 |
* match ours. |
| 582 |
* |
| 583 |
* By default, we do two things. First, we check to see if ALL of |
| 584 |
* our tokens are "weak" tokens, and if they are, we indicate that |
| 585 |
* we do NOT match the phrase. Second, if we pass the "weak token" |
| 586 |
* test, we'll invoke the common handling in matchNameCommon(), and |
| 587 |
* return the result. |
| 588 |
* |
| 589 |
* In most cases, games will want to override matchNameCommon() |
| 590 |
* instead of this routine. matchNameCommon() is the common handler |
| 591 |
* for both normal and disambiguation-reply matching, so overriding |
| 592 |
* that one routine will take care of both kinds of matching. Games |
| 593 |
* will only need to override matchName() separately in cases where |
| 594 |
* they need to differentiate normal matching and disambiguation |
| 595 |
* matching. |
| 596 |
*/ |
| 597 |
matchName(origTokens, adjustedTokens) |
| 598 |
{ |
| 599 |
/* if we have a weak-token list, check the tokens */ |
| 600 |
weakTest: |
| 601 |
if (weakTokens != nil) |
| 602 |
{ |
| 603 |
local sc = languageGlobals.dictComparator; |
| 604 |
|
| 605 |
/* check to see if all of our tokens are "weak" */ |
| 606 |
for (local i = 1, local len = adjustedTokens.length() ; |
| 607 |
i <= len ; i += 2) |
| 608 |
{ |
| 609 |
/* get the current token and its type */ |
| 610 |
local tok = adjustedTokens[i]; |
| 611 |
local typ = adjustedTokens[i+1]; |
| 612 |
|
| 613 |
/* |
| 614 |
* if this is a miscWord token, skip it - these aren't |
| 615 |
* vocabulary matches, so we won't find them in either |
| 616 |
* our weak or strong vocabulary lists |
| 617 |
*/ |
| 618 |
if (typ == &miscWord) |
| 619 |
continue; |
| 620 |
|
| 621 |
/* if this token isn't in our weak list, it's not weak */ |
| 622 |
if (weakTokens.indexWhich({x: sc.matchValues(tok, x) != 0}) |
| 623 |
== nil) |
| 624 |
{ |
| 625 |
/* |
| 626 |
* It's not in the weak list, so this isn't a weak |
| 627 |
* token; therefore the phrase isn't weak, so we do |
| 628 |
* not wish to veto the match. There's no need to |
| 629 |
* keep looking; simply break out of the weak test |
| 630 |
* entirely, since we've now passed. |
| 631 |
*/ |
| 632 |
break weakTest; |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
/* |
| 637 |
* If we get here, it means we got through the loop without |
| 638 |
* finding any non-weak tokens. This means the entire |
| 639 |
* phrase is weak, which means that we don't match it. |
| 640 |
* Return nil to indicate that this is not a match. |
| 641 |
*/ |
| 642 |
return nil; |
| 643 |
} |
| 644 |
|
| 645 |
/* invoke the common handling */ |
| 646 |
return matchNameCommon(origTokens, adjustedTokens); |
| 647 |
} |
| 648 |
|
| 649 |
/* |
| 650 |
* Match a name in a disambiguation response. This is similar to |
| 651 |
* matchName(), but is called for each object in an ambiguous object |
| 652 |
* list for which a disambiguation response was provided. As with |
| 653 |
* matchName(), we only call this routine for objects that match the |
| 654 |
* dictionary vocabulary. |
| 655 |
* |
| 656 |
* This routine is separate from matchName() because a |
| 657 |
* disambiguation response usually only contains a partial name. |
| 658 |
* For example, the exchange might go something like this: |
| 659 |
* |
| 660 |
* >take box |
| 661 |
*. Which box do you mean, the cardboard box, or the wood box? |
| 662 |
* >cardboard |
| 663 |
* |
| 664 |
* Note that it is not safe to assume that the disambiguation |
| 665 |
* response can be prepended to the original noun phrase to make a |
| 666 |
* complete noun phrase; if this were safe, we'd simply concatenate |
| 667 |
* the two strings and call matchName(). This would work for the |
| 668 |
* example above, since we'd get "cardboard box" as the new noun |
| 669 |
* phrase, but it wouldn't work in general. Consider these examples: |
| 670 |
* |
| 671 |
* >open post office box |
| 672 |
*. Which post office box do you mean, box 100, box 101, or box 102? |
| 673 |
* |
| 674 |
* >take jewel |
| 675 |
*. Which jewel do you mean, the emerald, or the diamond? |
| 676 |
* |
| 677 |
* There's no general way of assembling the disambiguation response |
| 678 |
* and the original noun phrase together into a new noun phrase, so |
| 679 |
* rather than trying to use matchName() for both purposes, we |
| 680 |
* simply use a separate routine to match the disambiguation name. |
| 681 |
* |
| 682 |
* Note that, when this routine is called, this object will have |
| 683 |
* been previously matched with matchName(), so there is no question |
| 684 |
* that this object matches the original noun phrase. The only |
| 685 |
* question is whether or not this object matches the response to |
| 686 |
* the "which one do you mean" question. |
| 687 |
* |
| 688 |
* The return value has the same meaning as for matchName(). |
| 689 |
* |
| 690 |
* By default, we simply invoke the common handler. Note that games |
| 691 |
* will usually want to override matchNameCommon() instead of this |
| 692 |
* routine, since matchNameCommon() provides common handling for the |
| 693 |
* main match and disambiguation match cases. Games should only |
| 694 |
* override this routine when they need to do something different |
| 695 |
* for normal vs disambiguation matching. |
| 696 |
*/ |
| 697 |
matchNameDisambig(origTokens, adjustedTokens) |
| 698 |
{ |
| 699 |
/* by default, use the same common processing */ |
| 700 |
return matchNameCommon(origTokens, adjustedTokens); |
| 701 |
} |
| 702 |
|
| 703 |
/* |
| 704 |
* Common handling for the main matchName() and the disambiguation |
| 705 |
* handler matchNameDisambig(). By default, we'll check with our |
| 706 |
* state object if we have a state object; if not, we'll simply |
| 707 |
* return 'self' to indicate that we do indeed match the given |
| 708 |
* tokens. |
| 709 |
* |
| 710 |
* In most cases, when a game wishes to customize name matching for |
| 711 |
* an object, it can simply override this routine. This routine |
| 712 |
* provides common handling for matchName() and matchNameDisambig(), |
| 713 |
* so overriding this routine will take care of both the normal and |
| 714 |
* disambiguation matching cases. In cases where a game needs to |
| 715 |
* customize only normal matching or only disambiguation matching, |
| 716 |
* it can override one of those other routines instead. |
| 717 |
*/ |
| 718 |
matchNameCommon(origTokens, adjustedTokens) |
| 719 |
{ |
| 720 |
local st; |
| 721 |
|
| 722 |
/* |
| 723 |
* if we have a state, ask our state object to check for words |
| 724 |
* applying only to other states |
| 725 |
*/ |
| 726 |
if ((st = getState()) != nil) |
| 727 |
return st.matchName(self, origTokens, adjustedTokens, allStates); |
| 728 |
|
| 729 |
/* by default, accept the parser's determination that we match */ |
| 730 |
return self; |
| 731 |
} |
| 732 |
|
| 733 |
/* |
| 734 |
* Plural resolution order. When a command contains a plural noun |
| 735 |
* phrase, we'll sort the items that match the plural phrase in |
| 736 |
* ascending order of this property value. |
| 737 |
* |
| 738 |
* In most cases, the plural resolution order doesn't matter. Once |
| 739 |
* in a while, though, a set of objects will be named as "first," |
| 740 |
* "second," "third," and so on; in these cases, it's nice to have |
| 741 |
* the order of resolution match the nominal ordering. |
| 742 |
* |
| 743 |
* Note that the sorting order only applies within the matches for a |
| 744 |
* particular plural phrase, not globally throughout the entire list |
| 745 |
* of objects in a command. For example, if the player types TAKE |
| 746 |
* BOXES AND BOOKS, we'll sort the boxes in one group, and then we'll |
| 747 |
* sort the books as a separate group - but all of the boxes will |
| 748 |
* come before any of the books, regardless of the plural orders. |
| 749 |
* |
| 750 |
* >take books and boxes |
| 751 |
*. first book: Taken. |
| 752 |
*. second book: Taken. |
| 753 |
*. third book: Taken. |
| 754 |
*. left box: Taken. |
| 755 |
*. middle box: Taken. |
| 756 |
*. right box: Taken. |
| 757 |
*/ |
| 758 |
pluralOrder = 100 |
| 759 |
|
| 760 |
/* |
| 761 |
* Disambiguation prompt order. When we interactively prompt for |
| 762 |
* help resolving an ambiguous noun phrase, we'll put the list of |
| 763 |
* ambiguous matches in ascending order of this property value. |
| 764 |
* |
| 765 |
* In most cases, the prompt order doesn't matter, so most objects |
| 766 |
* won't have to override the default setting. Sometimes, though, a |
| 767 |
* set of objects will be identified in the game as "first", |
| 768 |
* "second", "third", etc., and in these cases it's desirable to have |
| 769 |
* the objects presented in the same order as the names indicate: |
| 770 |
* |
| 771 |
* Which door do you mean, the first door, the second door, or the |
| 772 |
* third door? |
| 773 |
* |
| 774 |
* By default, we use the same value as our pluralOrder, since the |
| 775 |
* plural order has essentially the same purpose. |
| 776 |
*/ |
| 777 |
disambigPromptOrder = (pluralOrder) |
| 778 |
|
| 779 |
/* |
| 780 |
* Intrinsic parsing likelihood. During disambiguation, if the |
| 781 |
* parser finds two objects with equivalent logicalness (as |
| 782 |
* determined by the 'verify' process for the particular Action being |
| 783 |
* performed), it will pick the one with the higher intrinsic |
| 784 |
* likelihood value. The default value is zero, which makes all |
| 785 |
* objects equivalent by default. Set a higher value to make the |
| 786 |
* parser prefer this object in cases of ambiguity. |
| 787 |
*/ |
| 788 |
vocabLikelihood = 0 |
| 789 |
|
| 790 |
/* |
| 791 |
* Filter an ambiguous noun phrase resolution list. The parser calls |
| 792 |
* this method for each object that matches an ambiguous noun phrase |
| 793 |
* or an ALL phrase, to allow the object to modify the resolution |
| 794 |
* list. This method allows the object to act globally on the entire |
| 795 |
* list, so that the filtering can be sensitive to the presence or |
| 796 |
* absence in the list of other objects, and can affect the presence |
| 797 |
* of other objects. |
| 798 |
* |
| 799 |
* 'lst' is a list of ResolveInfo objects describing the tentative |
| 800 |
* resolution of the noun phrase. 'action' is the Action object |
| 801 |
* representing the command. 'whichObj' is the object role |
| 802 |
* identifier of the object being resolved (DirectObject, |
| 803 |
* IndirectObject, etc). 'np' is the noun phrase production that |
| 804 |
* we're resolving; this is usually a subclass of NounPhraseProd. |
| 805 |
* 'requiredNum' is the number of objects required, when an exact |
| 806 |
* quantity is specified; this is nil in cases where the quantity is |
| 807 |
* unspecified, as in 'all' or an unquantified plural ("take coins"). |
| 808 |
* |
| 809 |
* The result is a new list of ResolveInfo objects, which need not |
| 810 |
* contain any of the objects of the original list, and can add new |
| 811 |
* objects not in the original list, as desired. |
| 812 |
* |
| 813 |
* By default, we simply return the original list. |
| 814 |
*/ |
| 815 |
filterResolveList(lst, action, whichObj, np, requiredNum) |
| 816 |
{ |
| 817 |
/* return the original list unchanged */ |
| 818 |
return lst; |
| 819 |
} |
| 820 |
|
| 821 |
/* |
| 822 |
* Expand a pronoun list. This is essentially complementary to |
| 823 |
* filterResolveList: the function is to "unfilter" a pronoun binding |
| 824 |
* that contains this object so that it restores any objects that |
| 825 |
* would have been filtered out by filterResolveList from the |
| 826 |
* original noun phrase binding. |
| 827 |
* |
| 828 |
* This routine is called whenever the parser is called upon to |
| 829 |
* resolve a pronoun ("TAKE THEM"). This routine is called for each |
| 830 |
* object in the "raw" pronoun binding, which is simply the list of |
| 831 |
* objects that was stored by the previous command as the antecedent |
| 832 |
* for the pronoun. After this routine has been called for each |
| 833 |
* object in the raw pronoun binding, the final list will be passed |
| 834 |
* through filterResolveList(). |
| 835 |
* |
| 836 |
* 'lst' is the raw pronoun binding so far, which might reflect |
| 837 |
* changes made by this method called on previous objects in the |
| 838 |
* list. 'typ' is the pronoun type (PronounIt, PronounThem, etc) |
| 839 |
* describing the pronoun phrase being resolved. The return value is |
| 840 |
* the new pronoun binding list; if this routine doesn't need to make |
| 841 |
* any changes, it should simply return 'lst'. |
| 842 |
* |
| 843 |
* In some cases, filterResolveList chooses which of two or more |
| 844 |
* possible ways to bind a noun phrase, with the binding dependent |
| 845 |
* upon other conditions, such as the current action. In these |
| 846 |
* cases, it's often desirable for a subsequent pronoun reference to |
| 847 |
* make the same decision again, choosing from the full set of |
| 848 |
* possible bindings. This routine facilitates that by letting the |
| 849 |
* object put back objects that were filtered out, so that the |
| 850 |
* filtering can once again run on the full set of possible bindings |
| 851 |
* for the pronoun reference. |
| 852 |
* |
| 853 |
* This base implementation just returns the original list unchanged. |
| 854 |
* See CollectiveGroup for an override that uses this. |
| 855 |
*/ |
| 856 |
expandPronounList(typ, lst) { return lst; } |
| 857 |
|
| 858 |
/* |
| 859 |
* Our list of "weak" tokens. This is a token that is acceptable in |
| 860 |
* our vocabulary, but which we can only use in combination with one |
| 861 |
* or more "strong" tokens. (A token is strong if it's not weak, so |
| 862 |
* we need only keep track of one or the other kind. Weak tokens |
| 863 |
* are much less common than strong tokens, so it takes a lot less |
| 864 |
* space if we store the weak ones instead of the strong ones.) |
| 865 |
* |
| 866 |
* The purpose of weak tokens is to allow players to use more words |
| 867 |
* to refer to some objects without creating ambiguity. For |
| 868 |
* example, if we have a house, and a front door of the house, we |
| 869 |
* might want to allow the player to call the front door "front door |
| 870 |
* of house." If we just defined the door's vocabulary thus, |
| 871 |
* though, we'd create ambiguity if the player tried to refer to |
| 872 |
* "house," even though this obviously doesn't create any ambiguity |
| 873 |
* to a human reader. Weak tokens fix the problem: we define |
| 874 |
* "house" as a weak token for the front door, which allows the |
| 875 |
* player to refer to the front door as "front door of house", but |
| 876 |
* prevents the front door from matching just "house". |
| 877 |
* |
| 878 |
* By default, this is nil to indicate that we don't have any weak |
| 879 |
* tokens to check. If the object has weak tokens, this should be |
| 880 |
* set to a list of strings giving the weak tokens. |
| 881 |
*/ |
| 882 |
weakTokens = nil |
| 883 |
|
| 884 |
/* |
| 885 |
* By default, every object can be used as the resolution of a |
| 886 |
* possessive qualifier phrase (e.g., "bob" in "bob's book"). If |
| 887 |
* this property is set to nil for an object, that object can never |
| 888 |
* be used as a possessive. Note that has nothing to do with |
| 889 |
* establishing ownership relationships between objects; it controls |
| 890 |
* only the resolution of possessive phrases during parsing to |
| 891 |
* concrete game objects. |
| 892 |
*/ |
| 893 |
canResolvePossessive = true |
| 894 |
|
| 895 |
/* |
| 896 |
* Throw an appropriate parser error when this object is used in a |
| 897 |
* player command as a possessive qualifier (such as when 'self' is |
| 898 |
* the "bob" in "take bob's key"), and we don't own anything matching |
| 899 |
* the object name that we qualify. This is only called when 'self' |
| 900 |
* is in scope. By default, we throw the standard parser error ("Bob |
| 901 |
* doesn't appear to have any such thing"). 'txt' is the |
| 902 |
* lower-cased, HTMLified text that of the qualified object name |
| 903 |
* ("key" in "bob's key"). |
| 904 |
*/ |
| 905 |
throwNoMatchForPossessive(txt) |
| 906 |
{ throw new ParseFailureException(&noMatchForPossessive, self, txt); } |
| 907 |
|
| 908 |
/* |
| 909 |
* Throw an appropriate parser error when this object is used in a |
| 910 |
* player command to locationally qualify another object (such as |
| 911 |
* when we're the box in "examine the key in the box"), and there's |
| 912 |
* no object among our contents with the given name. By default, we |
| 913 |
* throw the standard parser error ("You see no key in the box"). |
| 914 |
*/ |
| 915 |
throwNoMatchForLocation(txt) |
| 916 |
{ throw new ParseFailureException(&noMatchForLocation, self, txt); } |
| 917 |
|
| 918 |
/* |
| 919 |
* Throw an appropriate parser error when this object is used in a |
| 920 |
* player command to locationally qualify "all" (such as when we're |
| 921 |
* the box in "examine everything in the box"), and we have no |
| 922 |
* contents. By default, we throw the standard parser error ("You |
| 923 |
* see nothing unusual in the box"). |
| 924 |
*/ |
| 925 |
throwNothingInLocation() |
| 926 |
{ throw new ParseFailureException(¬hingInLocation, self); } |
| 927 |
|
| 928 |
/* |
| 929 |
* Get a list of the other "facets" of this object. A facet is |
| 930 |
* another program object that to the player looks like the same or |
| 931 |
* part of the same physical object. For example, it's often |
| 932 |
* convenient to represent a door using two game objects - one for |
| 933 |
* each side - but the two really represent the same door from the |
| 934 |
* player's perspective. |
| 935 |
* |
| 936 |
* The parser uses an object's facets to resolve a pronoun when the |
| 937 |
* original antecedent goes out of scope. In our door example, if |
| 938 |
* we refer to the door, then walk through it to the other side, |
| 939 |
* then refer to 'it', the parser will realize from the facet |
| 940 |
* relationship that 'it' now refers to the other side of the door. |
| 941 |
*/ |
| 942 |
getFacets() { return []; } |
| 943 |
|
| 944 |
/* |
| 945 |
* Ownership: a vocab-object can be marked as owned by a given Thing. |
| 946 |
* This allows command input to refer to the owned object using |
| 947 |
* possessive syntax (such as, in English, "x's y"). |
| 948 |
* |
| 949 |
* This method returns true if 'self' is owned by 'obj'. The parser |
| 950 |
* generally tests for ownership in this direction, as opposed to |
| 951 |
* asking for obj's owner, because a given object might have multiple |
| 952 |
* owners, and might not be able to enumerate them all (or, at least, |
| 953 |
* might not be able to enumerate them efficiently). It's usually |
| 954 |
* efficient to determine whether a given object qualifies as an |
| 955 |
* owner, and from the parser's persepctive that's the question |
| 956 |
* anyway, since it wants to determine if the "x" in "x's y" |
| 957 |
* qualifies as my owner. |
| 958 |
* |
| 959 |
* By default, we simply return true if 'obj' matches our 'owner' |
| 960 |
* property (and is not nil). |
| 961 |
*/ |
| 962 |
isOwnedBy(obj) { return owner != nil && owner == obj; } |
| 963 |
|
| 964 |
/* |
| 965 |
* Get our nominal owner. This is the owner that we report for this |
| 966 |
* object if we're asked to distinguish this object from another |
| 967 |
* object in a disambiguation prompt. The nominal owner isn't |
| 968 |
* necessarily the only owner. Note that if getNominalOwner() |
| 969 |
* returns a non-nil value, isOwnedBy(getNominalOwner()) should |
| 970 |
* always return true. |
| 971 |
* |
| 972 |
* By default, we'll simply return our 'owner' property. |
| 973 |
*/ |
| 974 |
getNominalOwner() { return owner; } |
| 975 |
|
| 976 |
/* our explicit owner, if any */ |
| 977 |
owner = nil |
| 978 |
; |
| 979 |
|
| 980 |
/* ------------------------------------------------------------------------ */ |
| 981 |
/* |
| 982 |
* Find the best facet from the given list of facets, from the |
| 983 |
* perspective of the given actor. We'll find the facet that has the |
| 984 |
* best visibility, or, visibilities being equal, the best touchability. |
| 985 |
*/ |
| 986 |
findBestFacet(actor, lst) |
| 987 |
{ |
| 988 |
local infoList; |
| 989 |
local best; |
| 990 |
|
| 991 |
/* |
| 992 |
* if the list has no elements, there's no result; if it has only one |
| 993 |
* element, it's obviously the best one |
| 994 |
*/ |
| 995 |
if (lst.length() == 0) |
| 996 |
return nil; |
| 997 |
if (lst.length() == 1) |
| 998 |
return lst[1]; |
| 999 |
|
| 1000 |
/* make a list of the visibilities of the given facets */ |
| 1001 |
infoList = lst.mapAll({x: new SightTouchInfo(actor, x)}); |
| 1002 |
|
| 1003 |
/* scan the list and find the entry with the best results */ |
| 1004 |
best = nil; |
| 1005 |
foreach (local cur in infoList) |
| 1006 |
best = SightTouchInfo.selectBetter(best, cur); |
| 1007 |
|
| 1008 |
/* return the best result */ |
| 1009 |
return best.obj_; |
| 1010 |
} |
| 1011 |
|
| 1012 |
/* |
| 1013 |
* A small data structure class recording SenseInfo objects for sight and |
| 1014 |
* touch. We use this to pick the best facet from a list of facets. |
| 1015 |
*/ |
| 1016 |
class SightTouchInfo: object |
| 1017 |
construct(actor, obj) |
| 1018 |
{ |
| 1019 |
/* remember our object */ |
| 1020 |
obj_ = obj; |
| 1021 |
|
| 1022 |
/* get the visual SenseInfo in the actor's best sight-like sense */ |
| 1023 |
visInfo = actor.bestVisualInfo(obj); |
| 1024 |
|
| 1025 |
/* get the 'touch' SenseInfo for the object */ |
| 1026 |
touchInfo = actor.senseObj(touch, obj); |
| 1027 |
} |
| 1028 |
|
| 1029 |
/* the object we're associated with */ |
| 1030 |
obj_ = nil |
| 1031 |
|
| 1032 |
/* our SenseInfo objects for sight and touch */ |
| 1033 |
visInfo = nil |
| 1034 |
touchInfo = nil |
| 1035 |
|
| 1036 |
/* |
| 1037 |
* Class method: select the "better" of two SightTouchInfo's. |
| 1038 |
* Returns the one with the more transparent visual status, or, |
| 1039 |
* visual transparencies being equal, the one with the more |
| 1040 |
* transparent touch status. |
| 1041 |
*/ |
| 1042 |
selectBetter(a, b) |
| 1043 |
{ |
| 1044 |
local d; |
| 1045 |
|
| 1046 |
/* if one or the other is nil, return the non-nil one */ |
| 1047 |
if (a == nil) |
| 1048 |
return b; |
| 1049 |
if (b == nil) |
| 1050 |
return a; |
| 1051 |
|
| 1052 |
/* if the visual transparencies differ, compare visually */ |
| 1053 |
d = a.visInfo.compareTransTo(b.visInfo); |
| 1054 |
if (d > 0) |
| 1055 |
return a; |
| 1056 |
else if (d < 0) |
| 1057 |
return b; |
| 1058 |
else |
| 1059 |
{ |
| 1060 |
/* the visual status it the same, so compare by touch */ |
| 1061 |
d = a.touchInfo.compareTransTo(b.touchInfo); |
| 1062 |
if (d >= 0) |
| 1063 |
return a; |
| 1064 |
else |
| 1065 |
return b; |
| 1066 |
} |
| 1067 |
} |
| 1068 |
; |
| 1069 |
|
| 1070 |
/* ------------------------------------------------------------------------ */ |
| 1071 |
/* |
| 1072 |
* Thing: the basic class for game objects. An object of this class |
| 1073 |
* represents a physical object in the simulation. |
| 1074 |
*/ |
| 1075 |
class Thing: VocabObject |
| 1076 |
/* |
| 1077 |
* on constructing a new Thing, initialize it as we would a |
| 1078 |
* statically instantiated Thing |
| 1079 |
*/ |
| 1080 |
construct() |
| 1081 |
{ |
| 1082 |
/* |
| 1083 |
* If we haven't already been through here for this object, do |
| 1084 |
* the static initialization. (Because many library classes and |
| 1085 |
* game objects inherit from multiple Thing subclasses, we'll |
| 1086 |
* sometimes inherit this constructor multiple times in the |
| 1087 |
* course of creating a single new object. The set-up work we do |
| 1088 |
* isn't meant to be repeated and can create internal |
| 1089 |
* inconsistencies if it is.) |
| 1090 |
*/ |
| 1091 |
if (!isThingConstructed) |
| 1092 |
{ |
| 1093 |
/* inherit base class construction */ |
| 1094 |
inherited(); |
| 1095 |
|
| 1096 |
/* initialize the Thing properties */ |
| 1097 |
initializeThing(); |
| 1098 |
|
| 1099 |
/* note that we've been through this constructor now */ |
| 1100 |
isThingConstructed = true; |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
/* |
| 1105 |
* Have we been through Thing.construct() yet for this object? Note |
| 1106 |
* that this will only be set for dynamically created instances |
| 1107 |
* (i.e., objects created with 'new'). |
| 1108 |
*/ |
| 1109 |
isThingConstructed = nil |
| 1110 |
|
| 1111 |
/* |
| 1112 |
* My global parameter name. This is a name that can be used in |
| 1113 |
* {xxx} parameters in messages to refer directly to this object. |
| 1114 |
* This is nil by default, which means we have no global parameter |
| 1115 |
* name. Define this to a single-quoted string to set a global |
| 1116 |
* parameter name. |
| 1117 |
* |
| 1118 |
* Global parameter names can be especially useful for objects whose |
| 1119 |
* names change in the course of the game, such as actors who are |
| 1120 |
* known by one name until introduced, after which they're known by |
| 1121 |
* another name. It's a little nicer to write "{He/the bob}" than |
| 1122 |
* "<<bob.theName>>". We can do this with a global parameter name, |
| 1123 |
* because it allows us to use {bob} as a message parameter, even |
| 1124 |
* when the actor isn't involved directly in any command. |
| 1125 |
* |
| 1126 |
* Note that these parameter names are global, so no two objects are |
| 1127 |
* allowed to have the same name. These names are also subordinate |
| 1128 |
* to the parameter names in the current Action, so names that the |
| 1129 |
* actions define, such as 'dobj' and 'actor', should usually be |
| 1130 |
* avoided. |
| 1131 |
*/ |
| 1132 |
globalParamName = nil |
| 1133 |
|
| 1134 |
/* |
| 1135 |
* Set the global parameter name dynamically. If you need to add a |
| 1136 |
* new global parameter name at run-time, call this rather than |
| 1137 |
* setting the property directly, to ensure that the name is added to |
| 1138 |
* the message builder's name table. You can also use this to delete |
| 1139 |
* an object's global parameter name, by passing nil for the new |
| 1140 |
* name. |
| 1141 |
* |
| 1142 |
* (You only need to use this method if you want to add or change a |
| 1143 |
* name dynamically at run-time, because the library automatically |
| 1144 |
* initializes the table for objects with globalParamName settings |
| 1145 |
* defined at compile-time.) |
| 1146 |
*/ |
| 1147 |
setGlobalParamName(name) |
| 1148 |
{ |
| 1149 |
/* if we already had a name in the table, remove our old name */ |
| 1150 |
if (globalParamName != nil |
| 1151 |
&& langMessageBuilder.nameTable_[globalParamName] == self) |
| 1152 |
langMessageBuilder.nameTable_.removeElement(globalParamName); |
| 1153 |
|
| 1154 |
/* remember our name locally */ |
| 1155 |
globalParamName = name; |
| 1156 |
|
| 1157 |
/* add the name to the message builder's table */ |
| 1158 |
if (name != nil) |
| 1159 |
langMessageBuilder.nameTable_[name] = self; |
| 1160 |
} |
| 1161 |
|
| 1162 |
/* |
| 1163 |
* "Special" description. This is the generic place to put a |
| 1164 |
* description of the object that should appear in the containing |
| 1165 |
* room's full description. If the object defines a special |
| 1166 |
* description, the object is NOT listed in the basic contents list |
| 1167 |
* of the room, because listing it with the contents would be |
| 1168 |
* redundant with the special description. |
| 1169 |
* |
| 1170 |
* By default, we have no special description. If a special |
| 1171 |
* description is desired, define this to a double-quoted string |
| 1172 |
* containing the special description, or to a method that displays |
| 1173 |
* the special description. |
| 1174 |
*/ |
| 1175 |
specialDesc = nil |
| 1176 |
|
| 1177 |
/* |
| 1178 |
* The special descriptions to use under obscured and distant |
| 1179 |
* viewing conditions. By default, these simply display the normal |
| 1180 |
* special description, but these can be overridden if desired to |
| 1181 |
* show different messages under these viewing conditions. |
| 1182 |
* |
| 1183 |
* Note that if you override these alternative special descriptions, |
| 1184 |
* you MUST also provide a base specialDesc. The library figures |
| 1185 |
* out whether or not to show any sort of specialDesc first, based |
| 1186 |
* on the presence of a non-nil specialDesc; only then does the |
| 1187 |
* library figure out which particular variation to use. |
| 1188 |
* |
| 1189 |
* Note that remoteSpecialDesc takes precedence over these methods. |
| 1190 |
* That is, when 'self' is in a separate top-level room from the |
| 1191 |
* point-of-view actor, we'll use remoteSpecialDesc to generate our |
| 1192 |
* description, even if the sense path to 'self' is distant or |
| 1193 |
* obscured. |
| 1194 |
*/ |
| 1195 |
distantSpecialDesc = (specialDesc) |
| 1196 |
obscuredSpecialDesc = (specialDesc) |
| 1197 |
|
| 1198 |
/* |
| 1199 |
* The "remote" special description. This is the special |
| 1200 |
* description that will be used when this object is not in the |
| 1201 |
* point-of-view actor's current top-level room, but is visible in a |
| 1202 |
* connected room. For example, if two top-level rooms are |
| 1203 |
* connected by a window, so that an actor in one room can see the |
| 1204 |
* objects in the other room, this method will be used to generate |
| 1205 |
* the description of the object when the actor is in the other |
| 1206 |
* room, viewing this object through the window. |
| 1207 |
* |
| 1208 |
* By default, we just use the special description. It's usually |
| 1209 |
* better to customize this to describe the object from the given |
| 1210 |
* point of view. 'actor' is the point-of-view actor. |
| 1211 |
*/ |
| 1212 |
remoteSpecialDesc(actor) { distantSpecialDesc; } |
| 1213 |
|
| 1214 |
/* |
| 1215 |
* List order for the special description. Whenever there's more |
| 1216 |
* than one object showing a specialDesc at the same time (in a |
| 1217 |
* single room description, for example), we'll use this to order the |
| 1218 |
* specialDesc displays. We'll display in ascending order of this |
| 1219 |
* value. By default, we use the same value for everything, so |
| 1220 |
* listing order is arbitrary; when one specialDesc should appear |
| 1221 |
* before or after another, this property can be used to control the |
| 1222 |
* relative ordering. |
| 1223 |
*/ |
| 1224 |
specialDescOrder = 100 |
| 1225 |
|
| 1226 |
/* |
| 1227 |
* Special description phase. We list special descriptions for a |
| 1228 |
* room's full description in two phases: one phase before we show |
| 1229 |
* the room's portable contents list, and another phase after we show |
| 1230 |
* the contents list. This property controls the phase in which we |
| 1231 |
* show this item's special description. This only affects special |
| 1232 |
* descriptions that are shown with room descriptions; in other |
| 1233 |
* cases, such as "examine" descriptions of objects, all of the |
| 1234 |
* special descriptions are usually shown together. |
| 1235 |
* |
| 1236 |
* By default, we show our special description (if any) before the |
| 1237 |
* room's contents listing, because most special descriptions act |
| 1238 |
* like extensions of the room's main description and thus should be |
| 1239 |
* grouped directly with the room's descriptive text. Objects with |
| 1240 |
* special descriptions that are meant to indicate more ephemeral |
| 1241 |
* properties of the location can override this to be listed after |
| 1242 |
* the room's portable contents. |
| 1243 |
* |
| 1244 |
* One situation where you usually will want to list a special |
| 1245 |
* description after contents is when the special description applies |
| 1246 |
* to an item that's contained in a portable item. Since the |
| 1247 |
* container will be listed with the room contents, as it's portable, |
| 1248 |
* we'll usually want the special description of this child item to |
| 1249 |
* show up after the contents listing, so that it shows up after its |
| 1250 |
* container is mentioned. |
| 1251 |
* |
| 1252 |
* Note that the specialDescOrder is secondary to this phase |
| 1253 |
* grouping, because we essentially list special items in two |
| 1254 |
* separate groups. |
| 1255 |
*/ |
| 1256 |
specialDescBeforeContents = true |
| 1257 |
|
| 1258 |
/* |
| 1259 |
* Show my special description, given a SenseInfo object for the |
| 1260 |
* visual sense path from the point of view of the description. |
| 1261 |
*/ |
| 1262 |
showSpecialDescWithInfo(info, pov) |
| 1263 |
{ |
| 1264 |
local povActor = getPOVActorDefault(gActor); |
| 1265 |
|
| 1266 |
/* |
| 1267 |
* Determine what to show, based on the point-of-view location |
| 1268 |
* and the sense path. If the point of view isn't in the same |
| 1269 |
* top-level location as 'self', OR the actor isn't the same as |
| 1270 |
* the POV, use the remote special description; otherwise, select |
| 1271 |
* the obscured, distant, or basic special description according |
| 1272 |
* to the transparency of the sense path. |
| 1273 |
*/ |
| 1274 |
if (getOutermostRoom() != povActor.getOutermostRoom() |
| 1275 |
|| pov != povActor) |
| 1276 |
{ |
| 1277 |
/* |
| 1278 |
* different top-level rooms, or different actor and POV - |
| 1279 |
* use the remote description |
| 1280 |
*/ |
| 1281 |
showRemoteSpecialDesc(povActor); |
| 1282 |
} |
| 1283 |
else if (info.trans == obscured) |
| 1284 |
{ |
| 1285 |
/* we're obscured, so show our obscured special description */ |
| 1286 |
showObscuredSpecialDesc(); |
| 1287 |
} |
| 1288 |
else if (info.trans == distant) |
| 1289 |
{ |
| 1290 |
/* we're at a distance, so use our distant special description */ |
| 1291 |
showDistantSpecialDesc(); |
| 1292 |
} |
| 1293 |
else if (canDetailsBeSensed(sight, info, pov)) |
| 1294 |
{ |
| 1295 |
/* |
| 1296 |
* we're not obscured or distant, and our details can be |
| 1297 |
* sensed, so show our fully-visible special description |
| 1298 |
*/ |
| 1299 |
showSpecialDesc(); |
| 1300 |
} |
| 1301 |
} |
| 1302 |
|
| 1303 |
/* |
| 1304 |
* Show the special description, if we have one. If we are using |
| 1305 |
* our initial description, we'll show that; otherwise, if we have a |
| 1306 |
* specialDesc property, we'll show that. |
| 1307 |
* |
| 1308 |
* Note that the initial description overrides the specialDesc |
| 1309 |
* property whenever useInitSpecialDesc() returns true. This allows |
| 1310 |
* an object to have both an initial description that is used until |
| 1311 |
* the object is moved, and a separate special description used |
| 1312 |
* thereafter. |
| 1313 |
*/ |
| 1314 |
showSpecialDesc() |
| 1315 |
{ |
| 1316 |
/* |
| 1317 |
* if we are to use our initial description, show that; |
| 1318 |
* otherwise, show our special description |
| 1319 |
*/ |
| 1320 |
if (useInitSpecialDesc()) |
| 1321 |
initSpecialDesc; |
| 1322 |
else |
| 1323 |
specialDesc; |
| 1324 |
} |
| 1325 |
|
| 1326 |
/* show the special description under obscured viewing conditions */ |
| 1327 |
showObscuredSpecialDesc() |
| 1328 |
{ |
| 1329 |
if (useInitSpecialDesc()) |
| 1330 |
obscuredInitSpecialDesc; |
| 1331 |
else |
| 1332 |
obscuredSpecialDesc; |
| 1333 |
} |
| 1334 |
|
| 1335 |
/* show the special description under distant viewing conditions */ |
| 1336 |
showDistantSpecialDesc() |
| 1337 |
{ |
| 1338 |
if (useInitSpecialDesc()) |
| 1339 |
distantInitSpecialDesc; |
| 1340 |
else |
| 1341 |
distantSpecialDesc; |
| 1342 |
} |
| 1343 |
|
| 1344 |
/* show the remote special description */ |
| 1345 |
showRemoteSpecialDesc(actor) |
| 1346 |
{ |
| 1347 |
if (useInitSpecialDesc()) |
| 1348 |
remoteInitSpecialDesc(actor); |
| 1349 |
else |
| 1350 |
remoteSpecialDesc(actor); |
| 1351 |
} |
| 1352 |
|
| 1353 |
/* |
| 1354 |
* Determine if we should use a special description. By default, we |
| 1355 |
* have a special description if we have either a non-nil |
| 1356 |
* specialDesc property, or we have an initial description. |
| 1357 |
*/ |
| 1358 |
useSpecialDesc() |
| 1359 |
{ |
| 1360 |
/* |
| 1361 |
* if we have a non-nil specialDesc, or we are to use an initial |
| 1362 |
* description, we have a special description |
| 1363 |
*/ |
| 1364 |
return propType(&specialDesc) != TypeNil || useInitSpecialDesc(); |
| 1365 |
} |
| 1366 |
|
| 1367 |
/* |
| 1368 |
* Determine if we should use our special description in the given |
| 1369 |
* room's LOOK AROUND description. By default, this simply returns |
| 1370 |
* useSpecialDesc(). |
| 1371 |
*/ |
| 1372 |
useSpecialDescInRoom(room) { return useSpecialDesc(); } |
| 1373 |
|
| 1374 |
/* |
| 1375 |
* Determine if we should use our special description in the given |
| 1376 |
* object's contents listings, for the purposes of "examine <cont>" |
| 1377 |
* or "look in <cont>". By default, we'll use our special |
| 1378 |
* description for a given container if we'd use our special |
| 1379 |
* description in general, AND we're actually inside the container |
| 1380 |
* being examined. |
| 1381 |
*/ |
| 1382 |
useSpecialDescInContents(cont) |
| 1383 |
{ |
| 1384 |
/* |
| 1385 |
* if we would otherwise use a special description, and we are |
| 1386 |
* contained within the given object, use our special description |
| 1387 |
* in the container |
| 1388 |
*/ |
| 1389 |
return useSpecialDesc() && self.isIn(cont); |
| 1390 |
} |
| 1391 |
|
| 1392 |
/* |
| 1393 |
* Show our special description as part of a parent's full |
| 1394 |
* description. |
| 1395 |
*/ |
| 1396 |
showSpecialDescInContentsWithInfo(info, pov, cont) |
| 1397 |
{ |
| 1398 |
local povActor = getPOVActorDefault(gActor); |
| 1399 |
|
| 1400 |
/* determine what to show, based on the location and sense path */ |
| 1401 |
if (getOutermostRoom() != povActor.getOutermostRoom() |
| 1402 |
|| pov != povActor) |
| 1403 |
showRemoteSpecialDescInContents(povActor, cont); |
| 1404 |
else if (info.trans == obscured) |
| 1405 |
showObscuredSpecialDescInContents(povActor, cont); |
| 1406 |
else if (info.trans == distant) |
| 1407 |
showDistantSpecialDescInContents(povActor, cont); |
| 1408 |
else if (canDetailsBeSensed(sight, info, pov)) |
| 1409 |
showSpecialDescInContents(povActor, cont); |
| 1410 |
} |
| 1411 |
|
| 1412 |
/* |
| 1413 |
* Show the special description in contents listings under various |
| 1414 |
* sense conditions. By default, we'll use the corresponding special |
| 1415 |
* descriptions for full room descriptions. These can be overridden |
| 1416 |
* to show special versions of the description when we're examining |
| 1417 |
* particular containers, if desired. 'actor' is the actor doing the |
| 1418 |
* looking. |
| 1419 |
*/ |
| 1420 |
showSpecialDescInContents(actor, cont) |
| 1421 |
{ showSpecialDesc(); } |
| 1422 |
showObscuredSpecialDescInContents(actor, cont) |
| 1423 |
{ showObscuredSpecialDesc(); } |
| 1424 |
showDistantSpecialDescInContents(actor, cont) |
| 1425 |
{ showDistantSpecialDesc(); } |
| 1426 |
showRemoteSpecialDescInContents(actor, cont) |
| 1427 |
{ showRemoteSpecialDesc(actor); } |
| 1428 |
|
| 1429 |
/* |
| 1430 |
* If we define a non-nil initSpecialDesc, this property will be |
| 1431 |
* called to describe the object in room listings as long as the |
| 1432 |
* object is in its "initial" state (as determined by isInInitState: |
| 1433 |
* this is usually true until the object is first moved to a new |
| 1434 |
* location). By default, objects don't have initial descriptions. |
| 1435 |
* |
| 1436 |
* If this is non-nil, and the object is portable, this will be used |
| 1437 |
* (as long as the object is in its initial state) instead of |
| 1438 |
* showing the object in an ordinary room-contents listing. This |
| 1439 |
* can be used to give the object a special mention in its initial |
| 1440 |
* location in the game, rather than letting the ordinary |
| 1441 |
* room-contents lister lump it in with all of the other portable |
| 1442 |
* object lying around. |
| 1443 |
*/ |
| 1444 |
initSpecialDesc = nil |
| 1445 |
|
| 1446 |
/* |
| 1447 |
* The initial descriptions to use under obscured and distant |
| 1448 |
* viewing conditions. By default, these simply show the plain |
| 1449 |
* initSpecialDesc; these can be overridden, if desired, to show |
| 1450 |
* alternative messages when viewing conditions are less than ideal. |
| 1451 |
* |
| 1452 |
* Note that in order for one of these alternative initial |
| 1453 |
* descriptions to be shown, the regular initSpecialDesc MUST be |
| 1454 |
* defined, even if it's never actually used. We make the decision |
| 1455 |
* to display these other descriptions based on the existence of a |
| 1456 |
* non-nil initSpecialDesc, so always define initSpecialDesc |
| 1457 |
* whenever these are defined. |
| 1458 |
*/ |
| 1459 |
obscuredInitSpecialDesc = (initSpecialDesc) |
| 1460 |
distantInitSpecialDesc = (initSpecialDesc) |
| 1461 |
|
| 1462 |
/* the initial remote special description */ |
| 1463 |
remoteInitSpecialDesc(actor) { distantInitSpecialDesc; } |
| 1464 |
|
| 1465 |
/* |
| 1466 |
* If we define a non-nil initDesc, and the object is in its initial |
| 1467 |
* description state (as indicated by isInInitState), then we'll use |
| 1468 |
* this property instead of "desc" to describe the object when |
| 1469 |
* examined. This can be used to customize the description the |
| 1470 |
* player sees in parallel to initSpecialDesc. |
| 1471 |
*/ |
| 1472 |
initDesc = nil |
| 1473 |
|
| 1474 |
/* |
| 1475 |
* Am I in my "initial state"? This is used to determine if we |
| 1476 |
* should show the initial special description (initSpecialDesc) and |
| 1477 |
* initial examine description (initDesc) when describing the |
| 1478 |
* object. By default, we consider the object to be in its initial |
| 1479 |
* state until the first time it's moved. |
| 1480 |
* |
| 1481 |
* You can override this to achieve other effects. For example, if |
| 1482 |
* you want to use the initial description only the first time the |
| 1483 |
* object is examined, and then revert to the ordinary description, |
| 1484 |
* you could override this to return (!described). |
| 1485 |
*/ |
| 1486 |
isInInitState = (!moved) |
| 1487 |
|
| 1488 |
/* |
| 1489 |
* Determine whether or not I should be mentioned in my containing |
| 1490 |
* room's description (on LOOK AROUND) using my initial special |
| 1491 |
* description (initSpecialDesc). This returns true if I have an |
| 1492 |
* initial description that isn't nil, and I'm in my initial state. |
| 1493 |
* If this returns nil, the object should be described in room |
| 1494 |
* descriptions using the ordinary generated message (either the |
| 1495 |
* specialDesc, if we have one, or the ordinary mention in the list |
| 1496 |
* of portable room contents). |
| 1497 |
*/ |
| 1498 |
useInitSpecialDesc() |
| 1499 |
{ return isInInitState && propType(&initSpecialDesc) != TypeNil; } |
| 1500 |
|
| 1501 |
/* |
| 1502 |
* Determine if I should be described on EXAMINE using my initial |
| 1503 |
* examine description (initDesc). This returns true if I have an |
| 1504 |
* initial examine desription that isn't nil, and I'm in my initial |
| 1505 |
* state. If this returns nil, we'll show our ordinary description |
| 1506 |
* (given by the 'desc' property). |
| 1507 |
*/ |
| 1508 |
useInitDesc() |
| 1509 |
{ return isInInitState && propType(&initDesc) != TypeNil; } |
| 1510 |
|
| 1511 |
|
| 1512 |
/* |
| 1513 |
* Flag: I've been moved out of my initial location. Whenever we |
| 1514 |
* move the object to a new location, we'll set this to true. |
| 1515 |
*/ |
| 1516 |
moved = nil |
| 1517 |
|
| 1518 |
/* |
| 1519 |
* Flag: I've been seen by the player character. This is nil by |
| 1520 |
* default; we set this to true whenever we show a room description |
| 1521 |
* from the player character's perspective, and the object is |
| 1522 |
* visible. The object doesn't actually have to be mentioned in the |
| 1523 |
* room description to be marked as seen - it merely has to be |
| 1524 |
* visible to the player character. |
| 1525 |
* |
| 1526 |
* Note that this is only the DEFAULT 'seen' property, which all |
| 1527 |
* Actor objects use by default. The ACTUAL property that a given |
| 1528 |
* Actor uses depends on the actor's seenProp, which allows a game to |
| 1529 |
* keep track separately of what each actor has seen by using |
| 1530 |
* different 'seen' properties for different actors. |
| 1531 |
*/ |
| 1532 |
seen = nil |
| 1533 |
|
| 1534 |
/* |
| 1535 |
* Flag: suppress the automatic setting of the "seen" status for this |
| 1536 |
* object in room and object descriptions. Normally, we'll |
| 1537 |
* automatically mark every visible object as seen (by calling |
| 1538 |
* gActor.setHasSeen()) whenever we do a LOOK AROUND. We'll also |
| 1539 |
* automatically mark as seen every visible object within an object |
| 1540 |
* examined explicitly (such as with EXAMINE, LOOK IN, LOOK ON, or |
| 1541 |
* OPEN). This property can override this automatic status change: |
| 1542 |
* when this property is true, we will NOT mark this object as seen |
| 1543 |
* in any of these cases. When this property is true, the game must |
| 1544 |
* explicitly mark the object as seen, if and when desired, by |
| 1545 |
* calling actor.setHasSeen(). |
| 1546 |
* |
| 1547 |
* Sometimes, an object is not meant to be immediately obvious. For |
| 1548 |
* example, a puzzle box might have a hidden button that can't be |
| 1549 |
* seen on casual examination. In these cases, you can use |
| 1550 |
* suppressAutoSeen to ensure that the object won't be marked as seen |
| 1551 |
* merely by virtue of its being visible at the time of a LOOK AROUND |
| 1552 |
* or EXAMINE command. |
| 1553 |
* |
| 1554 |
* Note that this property does NOT affect the object's actual |
| 1555 |
* visibility or other sensory attributes. This property merely |
| 1556 |
* controls the automatic setting of the "seen" status of the object. |
| 1557 |
*/ |
| 1558 |
suppressAutoSeen = nil |
| 1559 |
|
| 1560 |
/* |
| 1561 |
* Flag: I've been desribed. This is nil by default; we set this to |
| 1562 |
* true whenever the player explicitly examines the object. |
| 1563 |
*/ |
| 1564 |
described = nil |
| 1565 |
|
| 1566 |
/* |
| 1567 |
* Mark all visible contents of 'self' as having been seen. |
| 1568 |
* 'infoTab' is a LookupTable of sight information, as returned by |
| 1569 |
* visibleInfoTable(). This should be called any time an object is |
| 1570 |
* examined in such a way that its contents should be considered to |
| 1571 |
* have been seen. |
| 1572 |
* |
| 1573 |
* We will NOT mark as seen any objects that have suppressAutoSeen |
| 1574 |
* set to true. |
| 1575 |
*/ |
| 1576 |
setContentsSeenBy(infoTab, actor) |
| 1577 |
{ |
| 1578 |
/* |
| 1579 |
* run through the table of visible objects, and mark each one |
| 1580 |
* that's contained within 'self' as having been seen |
| 1581 |
*/ |
| 1582 |
infoTab.forEachAssoc(function(obj, info) |
| 1583 |
{ |
| 1584 |
if (obj.isIn(self) && !obj.suppressAutoSeen) |
| 1585 |
actor.setHasSeen(obj); |
| 1586 |
}); |
| 1587 |
} |
| 1588 |
|
| 1589 |
/* |
| 1590 |
* Mark everything visible as having been seen. 'infoTab' is a |
| 1591 |
* LookupTable of sight information, as returned by |
| 1592 |
* visibleInfoTable(). We'll mark everything visible in the table |
| 1593 |
* as having been seen by the actor, EXCEPT objects that have |
| 1594 |
* suppressAutoSeen set to true. |
| 1595 |
*/ |
| 1596 |
setAllSeenBy(infoTab, actor) |
| 1597 |
{ |
| 1598 |
/* mark everything as seen, except suppressAutoSeen items */ |
| 1599 |
infoTab.forEachAssoc(function(obj, info) |
| 1600 |
{ |
| 1601 |
if (!obj.suppressAutoSeen) |
| 1602 |
actor.setHasSeen(obj); |
| 1603 |
}); |
| 1604 |
} |
| 1605 |
|
| 1606 |
/* |
| 1607 |
* Note that I've been seen by the given actor, setting the given |
| 1608 |
* "seen" property. This routine notifies the object that it's just |
| 1609 |
* been observed by the given actor, allowing it to take any special |
| 1610 |
* action it wants to take in such cases. |
| 1611 |
*/ |
| 1612 |
noteSeenBy(actor, prop) |
| 1613 |
{ |
| 1614 |
/* by default, simply set the given "seen" property to true */ |
| 1615 |
self.(prop) = true; |
| 1616 |
} |
| 1617 |
|
| 1618 |
/* |
| 1619 |
* Flag: this object is explicitly "known" to actors in the game, |
| 1620 |
* even if it's never been seen. This allows the object to be |
| 1621 |
* resolved as a topic in ASK ABOUT commands and the like. |
| 1622 |
* Sometimes, actors know about an object even before it's been seen |
| 1623 |
* - they might simply know about it from background knowledge, or |
| 1624 |
* they might hear about it from another character, for example. |
| 1625 |
* |
| 1626 |
* Like the 'seen' property, this is merely the DEFAULT 'known' |
| 1627 |
* property that we use for actors. Each actor can individually use |
| 1628 |
* a separate property to track its own knowledge if it prefers; it |
| 1629 |
* can do this simply by overriding its isKnownProp property. |
| 1630 |
*/ |
| 1631 |
isKnown = nil |
| 1632 |
|
| 1633 |
/* |
| 1634 |
* Hide from 'all' for a given action. If this returns true, this |
| 1635 |
* object will never be included in 'all' lists for the given action |
| 1636 |
* class. This should generally be set only for objects that serve |
| 1637 |
* some sort of internal purpose and don't represent physical |
| 1638 |
* objects in the model world. By default, objects are not hidden |
| 1639 |
* from 'all' lists. |
| 1640 |
* |
| 1641 |
* Note that returning nil doesn't put the object into an 'all' |
| 1642 |
* list. Rather, it simply *leaves* it in any 'all' list it should |
| 1643 |
* happen to be in. Each action controls its own selection criteria |
| 1644 |
* for 'all', and different verbs use different criteria. No matter |
| 1645 |
* how an action chooses its 'all' list, though, an item will always |
| 1646 |
* be excluded if hideFromAll() returns true for the item. |
| 1647 |
*/ |
| 1648 |
hideFromAll(action) { return nil; } |
| 1649 |
|
| 1650 |
/* |
| 1651 |
* Hide from defaulting for a given action. By default, we're |
| 1652 |
* hidden from being used as a default object for a given action if |
| 1653 |
* we're hidden from the action for 'all'. |
| 1654 |
*/ |
| 1655 |
hideFromDefault(action) { return hideFromAll(action); } |
| 1656 |
|
| 1657 |
/* |
| 1658 |
* Determine if I'm to be listed at all in my room's description, |
| 1659 |
* and in descriptions of objects containing my container. |
| 1660 |
* |
| 1661 |
* Most objects should be listed normally, but some types of objects |
| 1662 |
* should be suppressed from the normal room listing. For example, |
| 1663 |
* fixed-in-place scenery objects are generally described in the |
| 1664 |
* custom message for the containing room, so these are normally |
| 1665 |
* omitted from the listing of the room's contents. |
| 1666 |
* |
| 1667 |
* By default, we'll return the same thing as isListedInContents - |
| 1668 |
* that is, if this object is to be listed when its *direct* |
| 1669 |
* container is examined, it'll also be listed by default when any |
| 1670 |
* further enclosing container (including the enclosing room) is |
| 1671 |
* described. Individual objects can override this to use different |
| 1672 |
* rules. |
| 1673 |
* |
| 1674 |
* Why would we want to be able to list an object when examining in |
| 1675 |
* its direct container, but not when examining an enclosing |
| 1676 |
* container, or the enclosing room? The most common reason is to |
| 1677 |
* control the level of detail, to avoid overloading the broad |
| 1678 |
* description of the room and the main things in it with every |
| 1679 |
* detail of every deeply-nested container. |
| 1680 |
*/ |
| 1681 |
isListed { return isListedInContents; } |
| 1682 |
|
| 1683 |
/* |
| 1684 |
* Determine if I'm listed in explicit "examine" and "look in" |
| 1685 |
* descriptions of my direct container. |
| 1686 |
* |
| 1687 |
* By default, we return true as long as we're not using our special |
| 1688 |
* description in this particular context. Examining or looking in a |
| 1689 |
* container will normally show special message for any contents of |
| 1690 |
* the container, so we don't want to list the items with special |
| 1691 |
* descriptions in the ordinary list as well. |
| 1692 |
*/ |
| 1693 |
isListedInContents { return !useSpecialDescInContents(location); } |
| 1694 |
|
| 1695 |
/* |
| 1696 |
* Determine if I'm listed in inventory listings. By default, we |
| 1697 |
* include every item in an inventory list. |
| 1698 |
*/ |
| 1699 |
isListedInInventory { return true; } |
| 1700 |
|
| 1701 |
/* |
| 1702 |
* by default, regular objects are not listed when they arrive |
| 1703 |
* aboard vehicles (only actors are normally listed in this fashion) |
| 1704 |
*/ |
| 1705 |
isListedAboardVehicle = nil |
| 1706 |
|
| 1707 |
/* |
| 1708 |
* Determine if I'm listed as being located in the given room part. |
| 1709 |
* We'll first check to make sure the object is nominally contained |
| 1710 |
* in the room part; if not, it's not listed in the room part. We'll |
| 1711 |
* then ask the room part itself to make the final determination. |
| 1712 |
*/ |
| 1713 |
isListedInRoomPart(part) |
| 1714 |
{ |
| 1715 |
/* |
| 1716 |
* list me if I'm nominally contained in the room part AND the |
| 1717 |
* room part wants me listed |
| 1718 |
*/ |
| 1719 |
return (isNominallyInRoomPart(part) |
| 1720 |
&& part.isObjListedInRoomPart(self)); |
| 1721 |
} |
| 1722 |
|
| 1723 |
/* |
| 1724 |
* Determine if we're nominally in the given room part (floor, |
| 1725 |
* ceiling, wall, etc). This returns true if we *appear* to be |
| 1726 |
* located directly in/on the given room part object. |
| 1727 |
* |
| 1728 |
* In most cases, a portable object might start out with a special |
| 1729 |
* initial room part location, but once moved and then dropped |
| 1730 |
* somewhere, ends up nominally in the nominal drop destination of |
| 1731 |
* the location where it was dropped. For example, a poster might |
| 1732 |
* start out being nominally attached to a wall, or a light bulb |
| 1733 |
* might be nominally hanging from the ceiling; if these objects are |
| 1734 |
* taken and then dropped somewhere, they'll simply end up on the |
| 1735 |
* floor. |
| 1736 |
* |
| 1737 |
* Our default behavior models this. If we've never been moved, |
| 1738 |
* we'll indicate that we're in our initial room part location, |
| 1739 |
* given by initNominalRoomPartLocation. Once we've been moved (or |
| 1740 |
* if our initNominalRoomPartLocation is nil), we'll figure out what |
| 1741 |
* the nominal drop destination is for our current container, and |
| 1742 |
* then see if we appear to be in that nominal drop destination. |
| 1743 |
*/ |
| 1744 |
isNominallyInRoomPart(part) |
| 1745 |
{ |
| 1746 |
/* |
| 1747 |
* If we're not directly in the apparent container of the given |
| 1748 |
* room part, then we certainly are not even nominally in the |
| 1749 |
* room part. We only appear to be in a room part when we're |
| 1750 |
* actually in the room directly containing the room part. |
| 1751 |
*/ |
| 1752 |
if (location == nil |
| 1753 |
|| location.getRoomPartLocation(part) != location) |
| 1754 |
return nil; |
| 1755 |
|
| 1756 |
/* if we've never been moved, use our initial room part location */ |
| 1757 |
if (!moved && initNominalRoomPartLocation != nil) |
| 1758 |
return (part == initNominalRoomPartLocation); |
| 1759 |
|
| 1760 |
/* if we have an explicit special room part location, use that */ |
| 1761 |
if (specialNominalRoomPartLocation != nil) |
| 1762 |
return (part == specialNominalRoomPartLocation); |
| 1763 |
|
| 1764 |
/* |
| 1765 |
* We don't seem to have an initial or special room part |
| 1766 |
* location, but there's still one more possibility: if the room |
| 1767 |
* part is the nominal drop destination, then we are by default |
| 1768 |
* nominally in that room part, because that's where we |
| 1769 |
* otherwise end up in the absence of any special room part |
| 1770 |
* location setting. |
| 1771 |
*/ |
| 1772 |
if (location.getNominalDropDestination() == part) |
| 1773 |
return true; |
| 1774 |
|
| 1775 |
/* we aren't nominally in the given room part */ |
| 1776 |
return nil; |
| 1777 |
} |
| 1778 |
|
| 1779 |
/* |
| 1780 |
* Determine if I should show my special description with the |
| 1781 |
* description of the given room part (floor, ceiling, wall, etc). |
| 1782 |
* |
| 1783 |
* By default, we'll include our special description with a room |
| 1784 |
* part's description if either (1) we are using our initial |
| 1785 |
* description, and our initNominalRoomPartLocation is the given |
| 1786 |
* part; or (2) we are using our special description, and our |
| 1787 |
* specialNominalRoomPartLocation is the given part. |
| 1788 |
* |
| 1789 |
* Note that, by default, we do NOT use our special description for |
| 1790 |
* the "default" room part location - that is, for the nominal drop |
| 1791 |
* destination for our containing room, which is where we end up by |
| 1792 |
* default, in the absence of an initial or special room part |
| 1793 |
* location setting. We don't use our special description in this |
| 1794 |
* default location because special descriptions are most frequently |
| 1795 |
* used to describe an object that is specially situated, and hence |
| 1796 |
* we don't want to assume a default situation. |
| 1797 |
*/ |
| 1798 |
useSpecialDescInRoomPart(part) |
| 1799 |
{ |
| 1800 |
/* if we're not nominally in the part, rule it out */ |
| 1801 |
if (!isNominallyInRoomPart(part)) |
| 1802 |
return nil; |
| 1803 |
|
| 1804 |
/* |
| 1805 |
* if we're using our initial description, and we are explicitly |
| 1806 |
* in the given room part initially, use the special description |
| 1807 |
* for the room part |
| 1808 |
*/ |
| 1809 |
if (useInitSpecialDesc() && initNominalRoomPartLocation == part) |
| 1810 |
return true; |
| 1811 |
|
| 1812 |
/* |
| 1813 |
* if we're using our special description, and we are explicitly |
| 1814 |
* in the given room part as our special location, use the |
| 1815 |
* special description |
| 1816 |
*/ |
| 1817 |
if (useSpecialDesc() && specialNominalRoomPartLocation == part) |
| 1818 |
return true; |
| 1819 |
|
| 1820 |
/* do not use the special description in the room part */ |
| 1821 |
return nil; |
| 1822 |
} |
| 1823 |
|
| 1824 |
/* |
| 1825 |
* Our initial room part location. By default, we set this to nil, |
| 1826 |
* which means that we'll use the nominal drop destination of our |
| 1827 |
* actual initial location when asked. If desired, this can be set |
| 1828 |
* to another part; for example, if a poster is initially described |
| 1829 |
* as being "on the north wall," this should set to the default north |
| 1830 |
* wall object. |
| 1831 |
*/ |
| 1832 |
initNominalRoomPartLocation = nil |
| 1833 |
|
| 1834 |
/* |
| 1835 |
* Our "special" room part location. By default, we set this to |
| 1836 |
* nil, which means that we'll use the nominal drop destination of |
| 1837 |
* our actual current location when asked. |
| 1838 |
* |
| 1839 |
* This property has a function similar to |
| 1840 |
* initNominalRoomPartLocation, but is used to describe the nominal |
| 1841 |
* room part container of the object has been moved (and even before |
| 1842 |
* it's been moved, if initNominalRoomPartLocation is nil). |
| 1843 |
* |
| 1844 |
* It's rare for an object to have a special room part location |
| 1845 |
* after it's been moved, because most games simply don't provide |
| 1846 |
* commands for things like re-attaching a poster to a wall or |
| 1847 |
* re-hanging a fan from the ceiling. When it is possible to move |
| 1848 |
* an object to a new special location, though, this property can be |
| 1849 |
* used to flag its new special location. |
| 1850 |
*/ |
| 1851 |
specialNominalRoomPartLocation = nil |
| 1852 |
|
| 1853 |
/* |
| 1854 |
* Determine if my contents are to be listed when I'm shown in a |
| 1855 |
* listing (in a room description, inventory list, or a description |
| 1856 |
* of my container). |
| 1857 |
* |
| 1858 |
* Note that this doesn't affect listing my contents when I'm |
| 1859 |
* *directly* examined - use contentsListedInExamine to control that. |
| 1860 |
* |
| 1861 |
* By default, we'll list our contents in these situations if (1) we |
| 1862 |
* have some kind of presence in the description of whatever it is |
| 1863 |
* the player is looking at, either by being listed in the ordinary |
| 1864 |
* way (that is, isListed is true) or in a custom way (via a |
| 1865 |
* specialDesc), and (2) contentsListedInExamine is true. The |
| 1866 |
* reasoning behind this default is that if the object itself shows |
| 1867 |
* up in the description, then we usually want its contents to be |
| 1868 |
* mentioned as well, but if the object itself isn't mentioned, then |
| 1869 |
* its contents probably shouldn't be, either. And in any case, if |
| 1870 |
* the contents aren't listed even when we *directly* examine the |
| 1871 |
* object, then we almost certainly don't want its contents mentioned |
| 1872 |
* when we only indirectly mention the object in the course of |
| 1873 |
* describing something enclosing it. |
| 1874 |
*/ |
| 1875 |
contentsListed = (contentsListedInExamine |
| 1876 |
&& (isListed || useSpecialDesc())) |
| 1877 |
|
| 1878 |
/* |
| 1879 |
* Determine if my contents are to be listed when I'm directly |
| 1880 |
* examined (with an EXAMINE/LOOK AT command). By default, we |
| 1881 |
* *always* list our contents when we're directly examined. |
| 1882 |
*/ |
| 1883 |
contentsListedInExamine = true |
| 1884 |
|
| 1885 |
/* |
| 1886 |
* Determine if my contents are listed separately from my own list |
| 1887 |
* entry. If this is true, then my contents will be listed in a |
| 1888 |
* separate sentence from my own listing; for example, if 'self' is a |
| 1889 |
* box, we'll be listed like so: |
| 1890 |
* |
| 1891 |
*. You are carrying a box. The box contains a key and a book. |
| 1892 |
* |
| 1893 |
* By default, this is nil, which means that we list our contents |
| 1894 |
* parenthetically after our name: |
| 1895 |
* |
| 1896 |
*. You are carrying a box (which contains a key and a book). |
| 1897 |
* |
| 1898 |
* Using a separate listing is sometimes desirable for an object that |
| 1899 |
* will routinely contain listable objects that in turn have listable |
| 1900 |
* contents of their own, because it can help break up a long listing |
| 1901 |
* that would otherwise use too many nested parentheticals. |
| 1902 |
* |
| 1903 |
* Note that this only applies to "wide" listings; "tall" listings |
| 1904 |
* will show contents in the indented tree format regardless of this |
| 1905 |
* setting. |
| 1906 |
*/ |
| 1907 |
contentsListedSeparately = nil |
| 1908 |
|
| 1909 |
/* |
| 1910 |
* The language-dependent part of the library must provide a couple |
| 1911 |
* of basic descriptor methods that we depend upon. We provide |
| 1912 |
* several descriptor methods that we base on the basic methods. |
| 1913 |
* The basic methods that must be provided by the language extension |
| 1914 |
* are: |
| 1915 |
* |
| 1916 |
* listName - return a string giving the "list name" of the object; |
| 1917 |
* that is, the name that should appear in inventory and room |
| 1918 |
* contents lists. This is called with the visual sense info set |
| 1919 |
* according to the point of view. |
| 1920 |
* |
| 1921 |
* countName(count) - return a string giving the "counted name" of |
| 1922 |
* the object; that is, the name as it should appear with the given |
| 1923 |
* quantifier. In English, this might return something like 'one |
| 1924 |
* box' or 'three books'. This is called with the visual sense info |
| 1925 |
* set according to the point of view. |
| 1926 |
*/ |
| 1927 |
|
| 1928 |
/* |
| 1929 |
* Show this item as part of a list. 'options' is a combination of |
| 1930 |
* ListXxx flags indicating the type of listing. 'infoTab' is a |
| 1931 |
* lookup table of SenseInfo objects giving the sense information |
| 1932 |
* for the point of view. |
| 1933 |
*/ |
| 1934 |
showListItem(options, pov, infoTab) |
| 1935 |
{ |
| 1936 |
/* show the list, using the 'listName' of the state */ |
| 1937 |
showListItemGen(options, pov, infoTab, &listName); |
| 1938 |
} |
| 1939 |
|
| 1940 |
/* |
| 1941 |
* General routine to show the item as part of a list. |
| 1942 |
* 'stateNameProp' is the property to use in any listing state |
| 1943 |
* object to obtain the state name. |
| 1944 |
*/ |
| 1945 |
showListItemGen(options, pov, infoTab, stateNameProp) |
| 1946 |
{ |
| 1947 |
local info; |
| 1948 |
local st; |
| 1949 |
local stName; |
| 1950 |
|
| 1951 |
/* get my visual information from the point of view */ |
| 1952 |
info = infoTab[self]; |
| 1953 |
|
| 1954 |
/* show the item's list name */ |
| 1955 |
say(withVisualSenseInfo(pov, info, &listName)); |
| 1956 |
|
| 1957 |
/* |
| 1958 |
* If we have a list state with a name, show it. Note that to |
| 1959 |
* obtain the state name, we have to pass a list of the objects |
| 1960 |
* being listed to the stateNameProp method of the state object; |
| 1961 |
* we're the only object we're showing for this particular |
| 1962 |
* display list element, so we simply pass a single-element list |
| 1963 |
* containing 'self'. |
| 1964 |
*/ |
| 1965 |
if ((st = getStateWithInfo(info, pov)) != nil |
| 1966 |
&& (stName = st.(stateNameProp)([self])) != nil) |
| 1967 |
{ |
| 1968 |
/* we have a state with a name - show it */ |
| 1969 |
gLibMessages.showListState(stName); |
| 1970 |
} |
| 1971 |
} |
| 1972 |
|
| 1973 |
/* |
| 1974 |
* Show this item as part of a list, grouped with a count of |
| 1975 |
* list-equivalent items. |
| 1976 |
*/ |
| 1977 |
showListItemCounted(lst, options, pov, infoTab) |
| 1978 |
{ |
| 1979 |
/* show the item using the 'listName' property of the state */ |
| 1980 |
showListItemCountedGen(lst, options, pov, infoTab, &listName); |
| 1981 |
} |
| 1982 |
|
| 1983 |
/* |
| 1984 |
* General routine to show this item as part of a list, grouped with |
| 1985 |
* a count of list-equivalent items. 'stateNameProp' is the |
| 1986 |
* property of any list state object that we should use to obtain |
| 1987 |
* the name of the listing state. |
| 1988 |
*/ |
| 1989 |
showListItemCountedGen(lst, options, pov, infoTab, stateNameProp) |
| 1990 |
{ |
| 1991 |
local info; |
| 1992 |
local stateList; |
| 1993 |
|
| 1994 |
/* get the visual information from the point of view */ |
| 1995 |
info = infoTab[self]; |
| 1996 |
|
| 1997 |
/* show our counted name */ |
| 1998 |
say(countListName(lst.length(), pov, info)); |
| 1999 |
|
| 2000 |
/* check for list states */ |
| 2001 |
stateList = new Vector(10); |
| 2002 |
foreach (local cur in lst) |
| 2003 |
{ |
| 2004 |
local st; |
| 2005 |
|
| 2006 |
/* get this item's sense information from the list */ |
| 2007 |
info = infoTab[cur]; |
| 2008 |
|
| 2009 |
/* |
| 2010 |
* if this item has a list state with a name, include it in |
| 2011 |
* our list of states to show |
| 2012 |
*/ |
| 2013 |
if ((st = cur.getStateWithInfo(info, pov)) != nil |
| 2014 |
&& st.(stateNameProp)(lst) != nil) |
| 2015 |
{ |
| 2016 |
local stInfo; |
| 2017 |
|
| 2018 |
/* |
| 2019 |
* if this state is already in our list, simply |
| 2020 |
* increment the count of items in this state; |
| 2021 |
* otherwise, add the new state to the list |
| 2022 |
*/ |
| 2023 |
stInfo = stateList.valWhich({x: x.stateObj == st}); |
| 2024 |
if (stInfo != nil) |
| 2025 |
{ |
| 2026 |
/* it's already in the list - count the new item */ |
| 2027 |
stInfo.addEquivObj(cur); |
| 2028 |
} |
| 2029 |
else |
| 2030 |
{ |
| 2031 |
/* it's not in the list - add it */ |
| 2032 |
stateList.append( |
| 2033 |
new EquivalentStateInfo(st, cur, stateNameProp)); |
| 2034 |
} |
| 2035 |
} |
| 2036 |
} |
| 2037 |
|
| 2038 |
/* if the state list is non-empty, show it */ |
| 2039 |
if (stateList.length() != 0) |
| 2040 |
{ |
| 2041 |
/* put the state list in its desired order */ |
| 2042 |
stateList.sort(SortAsc, {a, b: (a.stateObj.listingOrder |
| 2043 |
- b.stateObj.listingOrder)}); |
| 2044 |
|
| 2045 |
/* |
| 2046 |
* If there's only one item in the state list, and all of |
| 2047 |
* the objects are in that state, then show the "all in |
| 2048 |
* state" message. Otherwise, show the list of states with |
| 2049 |
* counts. |
| 2050 |
* |
| 2051 |
* (Note that it's possible to have just one state in the |
| 2052 |
* list without having all of the objects in this state, |
| 2053 |
* because we could have some of the objects in an unnamed |
| 2054 |
* state, in which case they wouldn't contribute to the list |
| 2055 |
* at all.) |
| 2056 |
*/ |
| 2057 |
if (stateList.length() == 1 |
| 2058 |
&& stateList[1].getEquivCount() == lst.length()) |
| 2059 |
{ |
| 2060 |
/* everything is in the same state */ |
| 2061 |
gLibMessages.allInSameListState(stateList[1].getEquivList(), |
| 2062 |
stateList[1].getName()); |
| 2063 |
} |
| 2064 |
else |
| 2065 |
{ |
| 2066 |
/* list the state items */ |
| 2067 |
equivalentStateLister.showListAll(stateList.toList(), 0, 0); |
| 2068 |
} |
| 2069 |
} |
| 2070 |
} |
| 2071 |
|
| 2072 |
/* |
| 2073 |
* Single-item counted listing description. This is used to display |
| 2074 |
* an item with a count of equivalent items ("four gold coins"). |
| 2075 |
* 'info' is the sense information from the current point of view |
| 2076 |
* for 'self', which we take to be representative of the sense |
| 2077 |
* information for all of the equivalent items. |
| 2078 |
*/ |
| 2079 |
countListName(equivCount, pov, info) |
| 2080 |
{ |
| 2081 |
return withVisualSenseInfo(pov, info, &countName, equivCount); |
| 2082 |
} |
| 2083 |
|
| 2084 |
/* |
| 2085 |
* Show this item as part of an inventory list. By default, we'll |
| 2086 |
* show the regular list item name. |
| 2087 |
*/ |
| 2088 |
showInventoryItem(options, pov, infoTab) |
| 2089 |
{ |
| 2090 |
/* show the item, using the inventory state name */ |
| 2091 |
showListItemGen(options, pov, infoTab, &inventoryName); |
| 2092 |
} |
| 2093 |
showInventoryItemCounted(lst, options, pov, infoTab) |
| 2094 |
{ |
| 2095 |
/* show the item, using the inventory state name */ |
| 2096 |
showListItemCountedGen(lst, options, pov, infoTab, &inventoryName); |
| 2097 |
} |
| 2098 |
|
| 2099 |
/* |
| 2100 |
* Show this item as part of a list of items being worn. |
| 2101 |
*/ |
| 2102 |
showWornItem(options, pov, infoTab) |
| 2103 |
{ |
| 2104 |
/* show the item, using the worn-listing state name */ |
| 2105 |
showListItemGen(options, pov, infoTab, &wornName); |
| 2106 |
} |
| 2107 |
showWornItemCounted(lst, options, pov, infoTab) |
| 2108 |
{ |
| 2109 |
/* show the item, using the worn-listing state name */ |
| 2110 |
showListItemCountedGen(lst, options, pov, infoTab, &wornName); |
| 2111 |
} |
| 2112 |
|
| 2113 |
/* |
| 2114 |
* Get the "listing state" of the object, given the visual sense |
| 2115 |
* information for the object from the point of view for which we're |
| 2116 |
* generating the listing. This returns a ThingState object |
| 2117 |
* describing the object's state for the purposes of listings. This |
| 2118 |
* should return nil if the object doesn't have varying states for |
| 2119 |
* listings. |
| 2120 |
* |
| 2121 |
* By default, we return a list state if the visual sense path is |
| 2122 |
* transparent or attenuated, or we have large visual scale. In |
| 2123 |
* other cases, we assume that the details of the object are not |
| 2124 |
* visible under the current sense conditions; since the list state |
| 2125 |
* is normally a detail of the object, we don't return a list state |
| 2126 |
* when the details of the object are not visible. |
| 2127 |
*/ |
| 2128 |
getStateWithInfo(info, pov) |
| 2129 |
{ |
| 2130 |
/* |
| 2131 |
* if our details can be sensed, return the list state; |
| 2132 |
* otherwise, return nil, since the list state is a detail |
| 2133 |
*/ |
| 2134 |
if (canDetailsBeSensed(sight, info, pov)) |
| 2135 |
return getState(); |
| 2136 |
else |
| 2137 |
return nil; |
| 2138 |
} |
| 2139 |
|
| 2140 |
/* |
| 2141 |
* Get our state - returns a ThingState object describing the state. |
| 2142 |
* By default, we don't have varying states, so we simply return |
| 2143 |
* nil. |
| 2144 |
*/ |
| 2145 |
getState = nil |
| 2146 |
|
| 2147 |
/* |
| 2148 |
* Get a list of all of our possible states. For an object that can |
| 2149 |
* assume varying states as represented by getState, this should |
| 2150 |
* return the list of all possible states that the object can |
| 2151 |
* assume. |
| 2152 |
*/ |
| 2153 |
allStates = [] |
| 2154 |
|
| 2155 |
/* |
| 2156 |
* The default long description, which is displayed in response to |
| 2157 |
* an explicit player request to examine the object. We'll use a |
| 2158 |
* generic library message; most objects should override this to |
| 2159 |
* customize the object's desription. |
| 2160 |
* |
| 2161 |
* Note that we show this as a "default descriptive report," because |
| 2162 |
* this default message indicates merely that there's nothing |
| 2163 |
* special to say about the object. If we generate any additional |
| 2164 |
* description messages, such as status reports ("it's open" or "it |
| 2165 |
* contains a gold key") or special descriptions for things inside, |
| 2166 |
* we clearly *do* have something special to say about the object, |
| 2167 |
* so we'll want to suppress the nothing-special message. To |
| 2168 |
* accomplish this suppression, all we have to do is report our |
| 2169 |
* generic description as a default descriptive report, and the |
| 2170 |
* transcript will automatically filter it out if there are any |
| 2171 |
* other reports for this same action. |
| 2172 |
* |
| 2173 |
* Note that any time this is overridden by an object with any sort |
| 2174 |
* of actual description, the override should NOT use |
| 2175 |
* defaultDescReport. Instead, simply set this to display the |
| 2176 |
* descriptive message directly: |
| 2177 |
* |
| 2178 |
* desc = "It's a big green box. " |
| 2179 |
*/ |
| 2180 |
desc { defaultDescReport(&thingDescMsg, self); } |
| 2181 |
|
| 2182 |
/* |
| 2183 |
* Our LOOK IN description. This is shown when we explicitly LOOK IN |
| 2184 |
* the object. By default, we just report that there's nothing |
| 2185 |
* unusual inside. |
| 2186 |
*/ |
| 2187 |
lookInDesc { mainReport(¬hingInsideMsg); } |
| 2188 |
|
| 2189 |
/* |
| 2190 |
* The default "distant" description. If this is defined for an |
| 2191 |
* object, then we evaluate it to display the description when an |
| 2192 |
* actor explicitly examines this object from a point of view where |
| 2193 |
* we have a "distant" sight path to the object. |
| 2194 |
* |
| 2195 |
* If this property is left undefined for an object, then we'll |
| 2196 |
* describe this object when it's distant in one of two ways. If |
| 2197 |
* the object has its 'sightSize' property set to 'large', we'll |
| 2198 |
* display the ordinary 'desc', because its large visual size makes |
| 2199 |
* its details visible at a distance. If the 'sightSize' is |
| 2200 |
* anything else, we'll instead display the default library message |
| 2201 |
* indicating that the object is too far away to see any details. |
| 2202 |
* |
| 2203 |
* To display a specific description when the object is distant, set |
| 2204 |
* this to a double-quoted string, or to a method that displays a |
| 2205 |
* message. |
| 2206 |
*/ |
| 2207 |
// distantDesc = "the distant description" |
| 2208 |
|
| 2209 |
/* the default distant description */ |
| 2210 |
defaultDistantDesc { gLibMessages.distantThingDesc(self); } |
| 2211 |
|
| 2212 |
/* |
| 2213 |
* The "obscured" description. If this is defined for an object, |
| 2214 |
* then we call it to display the description when an actor |
| 2215 |
* explicitly examines this object from a point of view where we |
| 2216 |
* have an "obscured" sight path to the object. |
| 2217 |
* |
| 2218 |
* If this property is left undefined for an object, then we'll |
| 2219 |
* describe this object when it's obscured in one of two ways. If |
| 2220 |
* the object has its 'sightSize' property set to 'large', we'll |
| 2221 |
* display the ordinary 'desc', because its large visual size makes |
| 2222 |
* its details visible even when the object is obscured. If the |
| 2223 |
* 'sightSize' is anything else, we'll instead display the default |
| 2224 |
* library message indicating that the object is too obscured to see |
| 2225 |
* any details. |
| 2226 |
* |
| 2227 |
* To display a specific description when the object is visually |
| 2228 |
* obscured, override this to a method that displays your message. |
| 2229 |
* 'obs' is the object that's obstructing the view - this will be |
| 2230 |
* something on our sense path, such as a dirty window, that the |
| 2231 |
* actor has to look through to see 'self'. |
| 2232 |
*/ |
| 2233 |
// obscuredDesc(obs) { "the obscured description"; } |
| 2234 |
|
| 2235 |
/* |
| 2236 |
* The "remote" description. If this is defined for an object, then |
| 2237 |
* we call it to display the description when an actor explicitly |
| 2238 |
* examines this object from a separate top-level location. That |
| 2239 |
* is, when the actor's outermost enclosing room is different from |
| 2240 |
* our own outermost enclosing room, we'll use this description. |
| 2241 |
* |
| 2242 |
* If this property is left undefined, then we'll describe this |
| 2243 |
* object when it's distant as though it were in the same room. So, |
| 2244 |
* we'll select the obscured, distant, or ordinary description, |
| 2245 |
* according to the sense path. |
| 2246 |
*/ |
| 2247 |
// remoteDesc(pov) { "the remote description" } |
| 2248 |
|
| 2249 |
/* the default obscured description */ |
| 2250 |
defaultObscuredDesc(obs) { gLibMessages.obscuredThingDesc(self, obs); } |
| 2251 |
|
| 2252 |
/* |
| 2253 |
* The "sound description," which is the description displayed when |
| 2254 |
* an actor explicitly listens to the object. This is used when we |
| 2255 |
* have a transparent sense path and no associated "emanation" |
| 2256 |
* object; when we have an associated emanation object, we use its |
| 2257 |
* description instead of this one. |
| 2258 |
*/ |
| 2259 |
soundDesc { defaultDescReport(&thingSoundDescMsg, self); } |
| 2260 |
|
| 2261 |
/* distant sound description */ |
| 2262 |
distantSoundDesc { gLibMessages.distantThingSoundDesc(self); } |
| 2263 |
|
| 2264 |
/* obscured sound description */ |
| 2265 |
obscuredSoundDesc(obs) { gLibMessages.obscuredThingSoundDesc(self, obs); } |
| 2266 |
|
| 2267 |
/* |
| 2268 |
* The "smell description," which is the description displayed when |
| 2269 |
* an actor explicitly smells the object. This is used when we have |
| 2270 |
* a transparent sense path to the object, and we have no |
| 2271 |
* "emanation" object; when we have an associated emanation object, |
| 2272 |
* we use its description instead of this one. |
| 2273 |
*/ |
| 2274 |
smellDesc { defaultDescReport(&thingSmellDescMsg, self); } |
| 2275 |
|
| 2276 |
/* distant smell description */ |
| 2277 |
distantSmellDesc { gLibMessages.distantThingSmellDesc(self); } |
| 2278 |
|
| 2279 |
/* obscured smell description */ |
| 2280 |
obscuredSmellDesc(obs) { gLibMessages.obscuredThingSmellDesc(self, obs); } |
| 2281 |
|
| 2282 |
/* |
| 2283 |
* The "taste description," which is the description displayed when |
| 2284 |
* an actor explicitly tastes the object. Note that, unlike sound |
| 2285 |
* and smell, we don't distinguish levels of transparency or |
| 2286 |
* distance with taste, because tasting an object requires direct |
| 2287 |
* physical contact with it. |
| 2288 |
*/ |
| 2289 |
tasteDesc { gLibMessages.thingTasteDesc(self); } |
| 2290 |
|
| 2291 |
/* |
| 2292 |
* The "feel description," which is the description displayed when |
| 2293 |
* an actor explicitly feels the object. As with taste, we don't |
| 2294 |
* distinguish transparency or distance. |
| 2295 |
*/ |
| 2296 |
feelDesc { gLibMessages.thingFeelDesc(self); } |
| 2297 |
|
| 2298 |
/* |
| 2299 |
* Show the smell/sound description for the object as part of a room |
| 2300 |
* description. These are displayed when the object is in the room |
| 2301 |
* and it has a presence in the corresponding sense. By default, |
| 2302 |
* these show nothing. |
| 2303 |
* |
| 2304 |
* In most cases, regular objects don't override these, because most |
| 2305 |
* regular objects have no direct sensory presence of their own. |
| 2306 |
* Instead, a Noise or Odor is created and added to the object's |
| 2307 |
* direct contents, and the Noise or Odor provides the object's |
| 2308 |
* sense presence. |
| 2309 |
*/ |
| 2310 |
smellHereDesc() { } |
| 2311 |
soundHereDesc() { } |
| 2312 |
|
| 2313 |
/* |
| 2314 |
* "Equivalence" flag. If this flag is set, then all objects with |
| 2315 |
* the same immediate superclass will be considered interchangeable; |
| 2316 |
* such objects will be listed collectively in messages (so we would |
| 2317 |
* display "five coins" rather than "a coin, a coin, a coin, a coin, |
| 2318 |
* and a coin"), and will be treated as equivalent in resolving noun |
| 2319 |
* phrases to objects in user input. |
| 2320 |
* |
| 2321 |
* By default, this property is nil, since we want most objects to |
| 2322 |
* be treated as unique. |
| 2323 |
*/ |
| 2324 |
isEquivalent = nil |
| 2325 |
|
| 2326 |
/* |
| 2327 |
* My Distinguisher list. This is a list of Distinguisher objects |
| 2328 |
* that can be used to distinguish this object from other objects. |
| 2329 |
* |
| 2330 |
* Distinguishers are listed in order of priority. The |
| 2331 |
* disambiguation process looks for distinguishers capable of telling |
| 2332 |
* objects apart, starting with the first in the list. The |
| 2333 |
* BasicDistinguisher is generally first in every object's list, |
| 2334 |
* because any two objects can be told apart if they come from |
| 2335 |
* different classes. |
| 2336 |
* |
| 2337 |
* By default, each object has the "basic" distinguisher, which tells |
| 2338 |
* objects apart on the basis of the "isEquivalent" property and |
| 2339 |
* their superclasses; the ownership distinguisher, which tells |
| 2340 |
* objects apart based on ownership; and the location distinguisher, |
| 2341 |
* which identifies objects by their immediate containers. |
| 2342 |
*/ |
| 2343 |
distinguishers = [basicDistinguisher, |
| 2344 |
ownershipDistinguisher, |
| 2345 |
locationDistinguisher] |
| 2346 |
|
| 2347 |
/* |
| 2348 |
* Get the distinguisher to use for printing this object's name in an |
| 2349 |
* action announcement (such as a multi-object, default object, or |
| 2350 |
* vague-match announcement). We check the global option setting to |
| 2351 |
* see if we should actually use distinguishers for this; if so, we |
| 2352 |
* call getInScopeDistinguisher() to find the correct distinguisher, |
| 2353 |
* otherwise we use the "null" distinguisher, which simply lists |
| 2354 |
* objects by their base names. |
| 2355 |
* |
| 2356 |
* 'lst' is the list of other objects from which we're trying to |
| 2357 |
* differentiate 'self'. The reason 'lst' is given is that it lets |
| 2358 |
* us choose the simplest name for each object that usefully |
| 2359 |
* distinguishes it; to do this, we need to know exactly what we're |
| 2360 |
* distinguishing it from. |
| 2361 |
*/ |
| 2362 |
getAnnouncementDistinguisher(lst) |
| 2363 |
{ |
| 2364 |
return (gameMain.useDistinguishersInAnnouncements |
| 2365 |
? getBestDistinguisher(lst) |
| 2366 |
: nullDistinguisher); |
| 2367 |
} |
| 2368 |
|
| 2369 |
/* |
| 2370 |
* Get a distinguisher that differentiates me from all of the other |
| 2371 |
* objects in scope, if possible, or at least from some of the other |
| 2372 |
* objects in scope. |
| 2373 |
*/ |
| 2374 |
getInScopeDistinguisher() |
| 2375 |
{ |
| 2376 |
/* return the best distinguisher for the objects in scope */ |
| 2377 |
return getBestDistinguisher(gActor.scopeList()); |
| 2378 |
} |
| 2379 |
|
| 2380 |
/* |
| 2381 |
* Get a distinguisher that differentiates me from all of the other |
| 2382 |
* objects in the given list, if possible, or from as many of the |
| 2383 |
* other objects as possible. |
| 2384 |
*/ |
| 2385 |
getBestDistinguisher(lst) |
| 2386 |
{ |
| 2387 |
local bestDist, bestCnt; |
| 2388 |
|
| 2389 |
/* remove 'self' from the list */ |
| 2390 |
lst -= self; |
| 2391 |
|
| 2392 |
/* |
| 2393 |
* Try the "null" distinguisher, which distinguishes objects |
| 2394 |
* simply by their base names - if that can tell us apart from |
| 2395 |
* the other objects, there's no need for anything more |
| 2396 |
* elaborate. So, calculate the list of indistinguishable |
| 2397 |
* objects using the null distinguisher, and if it's empty, we |
| 2398 |
* can just use the null distinguisher as our result. |
| 2399 |
*/ |
| 2400 |
if (lst.subset({obj: !nullDistinguisher.canDistinguish(self, obj)}) |
| 2401 |
.length() == 0) |
| 2402 |
return nullDistinguisher; |
| 2403 |
|
| 2404 |
/* |
| 2405 |
* Reduce the list to the set of objects that are basic |
| 2406 |
* equivalents of mine - these are the only ones we care about |
| 2407 |
* telling apart from us, since all of the other objects can be |
| 2408 |
* distinguished by their disambig name. |
| 2409 |
*/ |
| 2410 |
lst = lst.subset( |
| 2411 |
{obj: !basicDistinguisher.canDistinguish(self, obj)}); |
| 2412 |
|
| 2413 |
/* if the basic distinguisher can tell us apart, just use it */ |
| 2414 |
if (lst.length() == 0) |
| 2415 |
return basicDistinguisher; |
| 2416 |
|
| 2417 |
/* as a last resort, fall back on the basic distinguisher */ |
| 2418 |
bestDist = basicDistinguisher; |
| 2419 |
bestCnt = lst.countWhich({obj: bestDist.canDistinguish(self, obj)}); |
| 2420 |
|
| 2421 |
/* |
| 2422 |
* run through my distinguisher list looking for the |
| 2423 |
* distinguisher that can tell me apart from the largest number |
| 2424 |
* of my vocab equivalents |
| 2425 |
*/ |
| 2426 |
foreach (local dist in distinguishers) |
| 2427 |
{ |
| 2428 |
/* if this is the default, skip it */ |
| 2429 |
if (dist == bestDist) |
| 2430 |
continue; |
| 2431 |
|
| 2432 |
/* check to see how many objects 'dist' can distinguish me from */ |
| 2433 |
local cnt = lst.countWhich({obj: dist.canDistinguish(self, obj)}); |
| 2434 |
|
| 2435 |
/* |
| 2436 |
* if it can distinguish me from every other object, use this |
| 2437 |
* one - it uniquely identifies me |
| 2438 |
*/ |
| 2439 |
if (cnt == lst.length()) |
| 2440 |
return dist; |
| 2441 |
|
| 2442 |
/* |
| 2443 |
* that can't distinguish us from everything else here, but |
| 2444 |
* if it's the best so far, remember it; we'll fall back on |
| 2445 |
* the best that we find if we fail to find a perfect |
| 2446 |
* distinguisher |
| 2447 |
*/ |
| 2448 |
if (cnt > bestCnt) |
| 2449 |
{ |
| 2450 |
bestDist = dist; |
| 2451 |
bestCnt = cnt; |
| 2452 |
} |
| 2453 |
} |
| 2454 |
|
| 2455 |
/* |
| 2456 |
* We didn't find any distinguishers that can tell me apart from |
| 2457 |
* every other object, so choose the one that can tell me apart |
| 2458 |
* from the most other objects. |
| 2459 |
*/ |
| 2460 |
return bestDist; |
| 2461 |
} |
| 2462 |
|
| 2463 |
/* |
| 2464 |
* Determine if I'm equivalent, for the purposes of command |
| 2465 |
* vocabulary, to given object. |
| 2466 |
* |
| 2467 |
* We'll run through our list of distinguishers and check with each |
| 2468 |
* one to see if it can tell us apart from the other object. If we |
| 2469 |
* can find at least one distinguisher that can tell us apart, we're |
| 2470 |
* not equivalent. If we have no distinguisher that can tell us |
| 2471 |
* apart from the other object, we're equivalent. |
| 2472 |
*/ |
| 2473 |
isVocabEquivalent(obj) |
| 2474 |
{ |
| 2475 |
/* |
| 2476 |
* Check each distinguisher - if we can find one that can tell |
| 2477 |
* us apart from the other object, we're not equivalent. If |
| 2478 |
* there are no distinguishers that can tell us apart, we're |
| 2479 |
* equivalent. |
| 2480 |
*/ |
| 2481 |
return (distinguishers.indexWhich( |
| 2482 |
{cur: cur.canDistinguish(self, obj)}) == nil); |
| 2483 |
} |
| 2484 |
|
| 2485 |
/* |
| 2486 |
* My associated "collective group" objects. A collective group is |
| 2487 |
* an abstract object, not part of the simulation (i.e, not directly |
| 2488 |
* manipulable by characters as a separate object) that can stand in |
| 2489 |
* for an entire group of related objects in some actions. For |
| 2490 |
* example, we might have a collective "money" object that stands in |
| 2491 |
* for any group of coins and paper bills for "examine" commands, so |
| 2492 |
* that when the player says something like "look at money" or "count |
| 2493 |
* money," we use the single collective money object to handle the |
| 2494 |
* command rather than running the command iteratively on each of the |
| 2495 |
* individual coins and bills present. |
| 2496 |
* |
| 2497 |
* The value is a list because this object can be associated with |
| 2498 |
* more than one collective group. For example, a diamond could be |
| 2499 |
* in a "treasure" group as well as a "jewelry" group. |
| 2500 |
* |
| 2501 |
* The associated collective objects are normally of class |
| 2502 |
* CollectiveGroup. By default, if our 'collectiveGroup' property is |
| 2503 |
* not nil, our list consists of that one item; otherwise we just use |
| 2504 |
* an empty list. |
| 2505 |
*/ |
| 2506 |
collectiveGroups = (collectiveGroup != nil ? [collectiveGroup] : []) |
| 2507 |
|
| 2508 |
/* |
| 2509 |
* Our collective group. Note - this property is obsolescent; it's |
| 2510 |
* supported only for compatibility with old code. New games should |
| 2511 |
* use 'collectiveGroups' instead. |
| 2512 |
*/ |
| 2513 |
collectiveGroup = nil |
| 2514 |
|
| 2515 |
/* |
| 2516 |
* Are we associated with the given collective group? We do if it's |
| 2517 |
* in our collectiveGroups list. |
| 2518 |
*/ |
| 2519 |
hasCollectiveGroup(g) { return collectiveGroups.indexOf(g) != nil; } |
| 2520 |
|
| 2521 |
/* |
| 2522 |
* "List Group" objects. This specifies a list of ListGroup objects |
| 2523 |
* that we use to list this object in object listings, such as |
| 2524 |
* inventory lists and room contents lists. |
| 2525 |
* |
| 2526 |
* An object can be grouped in more than one way. When multiple |
| 2527 |
* groups are specified here, the order is significant: |
| 2528 |
* |
| 2529 |
* - To the extent two groups entirely overlap, which is to say that |
| 2530 |
* one of the pair entirely contains the other (for example, if |
| 2531 |
* every coin is a kind of money, then the "money" listing group |
| 2532 |
* would contain every object in the "coin" group, plus other |
| 2533 |
* objects as well: the coin group is a subset of the money group), |
| 2534 |
* the groups must be listed from most general to most specific (for |
| 2535 |
* our money/coin example, then, money would come before coin in the |
| 2536 |
* group list). |
| 2537 |
* |
| 2538 |
* - When two groups do not overlap, then the earlier one in our |
| 2539 |
* list is given higher priority. |
| 2540 |
* |
| 2541 |
* By default, we return an empty list. |
| 2542 |
*/ |
| 2543 |
listWith = [] |
| 2544 |
|
| 2545 |
/* |
| 2546 |
* Get the list group for my special description. This works like |
| 2547 |
* the ordinary listWith, but is used to group me with other objects |
| 2548 |
* showing special descriptions, rather than in ordinary listings. |
| 2549 |
*/ |
| 2550 |
specialDescListWith = [] |
| 2551 |
|
| 2552 |
/* |
| 2553 |
* Our interior room name. This is the status line name we display |
| 2554 |
* when an actor is within this object and can't see out to the |
| 2555 |
* enclosing room. Since we can't rely on the enclosing room's |
| 2556 |
* status line name if we can't see the enclosing room, we must |
| 2557 |
* provide one of our own. |
| 2558 |
* |
| 2559 |
* By default, we'll use our regular name. |
| 2560 |
*/ |
| 2561 |
roomName = (name) |
| 2562 |
|
| 2563 |
/* |
| 2564 |
* Show our interior description. We use this to generate the long |
| 2565 |
* "look" description for the room when an actor is within this |
| 2566 |
* object and cannot see the enclosing room. |
| 2567 |
* |
| 2568 |
* Note that this is used ONLY when the actor cannot see the |
| 2569 |
* enclosing room - when the enclosing room is visible (because the |
| 2570 |
* nested room is something like a chair that doesn't enclose the |
| 2571 |
* actor, or can enclose the actor but is open or transparent), then |
| 2572 |
* we'll simply use the description of the enclosing room instead, |
| 2573 |
* adding a note to the short name shown at the start of the room |
| 2574 |
* description indicating that the actor is in the nested room. |
| 2575 |
* |
| 2576 |
* By default, we'll show the appropriate "actor here" description |
| 2577 |
* for the posture, so we'll say something like "You are sitting on |
| 2578 |
* the red chair" or "You are in the phone booth." Instances can |
| 2579 |
* override this to customize the description with something more |
| 2580 |
* detailed, if desired. |
| 2581 |
*/ |
| 2582 |
roomDesc { gActor.listActorPosture(getPOVActorDefault(gActor)); } |
| 2583 |
|
| 2584 |
/* |
| 2585 |
* Show our first-time room description. This is the description we |
| 2586 |
* show when the actor is seeing our interior description for the |
| 2587 |
* first time. By default, we just show the ordinary room |
| 2588 |
* description, but this can be overridden to provide a special |
| 2589 |
* description the first time the actor sees the room. |
| 2590 |
*/ |
| 2591 |
roomFirstDesc { roomDesc; } |
| 2592 |
|
| 2593 |
/* |
| 2594 |
* Show our remote viewing description. This is used when we show a |
| 2595 |
* description of a room, via lookAroundWithin, and the actor who's |
| 2596 |
* viewing the room is remote. Note that the library never does this |
| 2597 |
* itself, since there's no command in the basic library that lets a |
| 2598 |
* player view a remote room. However, a game might want to generate |
| 2599 |
* such a description to handle a command like LOOK THROUGH KEYHOLE, |
| 2600 |
* so we provide this extra description method for the game's use. |
| 2601 |
* |
| 2602 |
* By default, we simply show the normal room description. You'll |
| 2603 |
* probably want to override this any time you actually use it, |
| 2604 |
* though, to describe what the actor sees from the remote point of |
| 2605 |
* view. |
| 2606 |
*/ |
| 2607 |
roomRemoteDesc(actor) { roomDesc; } |
| 2608 |
|
| 2609 |
/* our interior room name when we're in the dark */ |
| 2610 |
roomDarkName = (gLibMessages.roomDarkName) |
| 2611 |
|
| 2612 |
/* show our interior description in the dark */ |
| 2613 |
roomDarkDesc { gLibMessages.roomDarkDesc; } |
| 2614 |
|
| 2615 |
/* |
| 2616 |
* Describe an actor in this location either from the point of view |
| 2617 |
* of a separate top-level room, or at a distance. This is called |
| 2618 |
* when we're showing a room description (for LOOK AROUND), and the |
| 2619 |
* given actor is in a remote room or at a distance visually from |
| 2620 |
* the actor doing the looking, and the given actor is contained |
| 2621 |
* within this room. |
| 2622 |
* |
| 2623 |
* By default, if we have a location, and the actor doing the |
| 2624 |
* looking can see out into the enclosing room, we'll defer to the |
| 2625 |
* location. Otherwise, we'll show a default library message ("The |
| 2626 |
* actor is nearby"). |
| 2627 |
*/ |
| 2628 |
roomActorThereDesc(actor) |
| 2629 |
{ |
| 2630 |
local pov = getPOV(); |
| 2631 |
|
| 2632 |
/* |
| 2633 |
* if we have an enclosing location, and the POV actor can see |
| 2634 |
* out to our location, defer to our location; otherwise, show |
| 2635 |
* the default library message |
| 2636 |
*/ |
| 2637 |
if (location != nil && pov != nil && pov.canSee(location)) |
| 2638 |
location.roomActorThereDesc(actor); |
| 2639 |
else |
| 2640 |
gLibMessages.actorInRemoteRoom(actor, self, pov); |
| 2641 |
} |
| 2642 |
|
| 2643 |
/* |
| 2644 |
* Look around from the point of view of this object and on behalf of |
| 2645 |
* the given actor. This can be used to generate a description as |
| 2646 |
* seen from this object by the given actor, and is suitable for |
| 2647 |
* cases where the actor can use this object as a sensing device. We |
| 2648 |
* simply pass this through to lookAroundPov(), passing 'self' as the |
| 2649 |
* point-of-view object. |
| 2650 |
* |
| 2651 |
* 'verbose' is a combination of LookXxx flags (defined in adv3.h) |
| 2652 |
* indicating what style of description we want. This can also be |
| 2653 |
* 'true', in which case we'll show the standard verbose listing |
| 2654 |
* (LookRoomName | LookRoomDesc | LookListSpecials | |
| 2655 |
* LookListPortables); or 'nil', in which case we'll use the standard |
| 2656 |
* terse listing (LookRoomName | LookListSpecials | |
| 2657 |
* LookListPortables). |
| 2658 |
*/ |
| 2659 |
lookAround(actor, verbose) |
| 2660 |
{ |
| 2661 |
/* look around from my point of view */ |
| 2662 |
lookAroundPov(actor, self, verbose); |
| 2663 |
} |
| 2664 |
|
| 2665 |
/* |
| 2666 |
* Look around from within this object, looking from the given point |
| 2667 |
* of view and on behalf of the given actor. |
| 2668 |
* |
| 2669 |
* 'actor' is the actor doing the looking, and 'pov' is the point of |
| 2670 |
* view of the description. These are usually the same, but need not |
| 2671 |
* be. For example, an actor could be looking at a room through a |
| 2672 |
* hole in the wall, in which case the POV would be the object |
| 2673 |
* representing the "side" of the hole in the room being described. |
| 2674 |
* Or, the actor could be observing a remote room via a |
| 2675 |
* closed-circuit television system, in which case the POV would be |
| 2676 |
* the camera in the remote room. (The POV is the physical object |
| 2677 |
* receiving the photons in the location being described, so it's the |
| 2678 |
* camera, not the TV monitor that the actor's looking at.) |
| 2679 |
* |
| 2680 |
* 'verbose' has the same meaning as it does in lookAround(). |
| 2681 |
* |
| 2682 |
* This routine checks to see if 'self' is the "look-around ceiling," |
| 2683 |
* which is for most purposes the outermost visible container of this |
| 2684 |
* object; see isLookAroundCeiling() for more. If this object is the |
| 2685 |
* look-around ceiling, then we'll call lookAroundWithin() to |
| 2686 |
* generate the description of the interior of 'self'; otherwise, |
| 2687 |
* we'll recursively defer to our immediate container so that it can |
| 2688 |
* make the same test. In most cases, the outermost visible |
| 2689 |
* container that actually generates the description will be a Room |
| 2690 |
* or a NestedRoom. |
| 2691 |
*/ |
| 2692 |
lookAroundPov(actor, pov, verbose) |
| 2693 |
{ |
| 2694 |
/* |
| 2695 |
* If we're the "look around ceiling," generate the description |
| 2696 |
* within this room. Otherwise, we have an enclosing location |
| 2697 |
* that provides the interior description. |
| 2698 |
*/ |
| 2699 |
if (isLookAroundCeiling(actor, pov)) |
| 2700 |
{ |
| 2701 |
/* we're the "ceiling," so describe our interior */ |
| 2702 |
fromPOV(actor, pov, &lookAroundWithin, actor, pov, verbose); |
| 2703 |
} |
| 2704 |
else |
| 2705 |
{ |
| 2706 |
/* our location provides the interior description */ |
| 2707 |
location.lookAroundPov(actor, pov, verbose); |
| 2708 |
} |
| 2709 |
} |
| 2710 |
|
| 2711 |
/* |
| 2712 |
* Are we the "look around ceiling"? If so, it means that a LOOK |
| 2713 |
* AROUND for an actor within this location (or from a point of view |
| 2714 |
* within this location) will use our own interior description, via |
| 2715 |
* lookAroundWithin(). If we're not the ceiling, then we defer to |
| 2716 |
* our location, letting it describe its interior. |
| 2717 |
* |
| 2718 |
* By default, we're the ceiling if we're a top-level room (that is, |
| 2719 |
* we have no enclosing location), OR it's not possible to see out to |
| 2720 |
* our location. In either of these cases, we can't see anything |
| 2721 |
* outside of this room, so we have to generate our own interior |
| 2722 |
* description. However, if we do have a location that we can see, |
| 2723 |
* then we'll assume that this object just represents a facet of its |
| 2724 |
* enclosing location, so the enclosing location provides the room |
| 2725 |
* interior description. |
| 2726 |
* |
| 2727 |
* In some cases, a room might want to provide its own LOOK AROUND |
| 2728 |
* interior description directly even if its location is visible. |
| 2729 |
* For example, if the player's inside a wooden booth with a small |
| 2730 |
* window that can see out to the enclosing location, LOOK AROUND |
| 2731 |
* should probably describe the interior of the booth rather than the |
| 2732 |
* enclosing location: even though the exterior is technically |
| 2733 |
* visible, the booth clearly dominates the view, from the player's |
| 2734 |
* perspective. In this case, we'd want to override this routine to |
| 2735 |
* indicate that we're the LOOK AROUND ceiling, despite our |
| 2736 |
* location's visibility. |
| 2737 |
*/ |
| 2738 |
isLookAroundCeiling(actor, pov) |
| 2739 |
{ |
| 2740 |
/* |
| 2741 |
* if we don't have a location, or we can't see our location, |
| 2742 |
* then we have to provide our own description, so we're the LOOK |
| 2743 |
* AROUND "ceiling" |
| 2744 |
*/ |
| 2745 |
return (location == nil || !actor.canSee(location)); |
| 2746 |
} |
| 2747 |
|
| 2748 |
/* |
| 2749 |
* Provide a "room description" of the interior of this object. This |
| 2750 |
* routine is primarily intended as a subroutine of lookAround() and |
| 2751 |
* lookAroundPov() - most game code shouldn't need to call this |
| 2752 |
* routine directly. Note that if you *do* call this routine |
| 2753 |
* directly, you *must* set the global point-of-view variables, which |
| 2754 |
* you can do most easily by calling this routine indirectly through |
| 2755 |
* the fromPOV() method. |
| 2756 |
* |
| 2757 |
* The library calls this method when an actor performs a "look |
| 2758 |
* around" command, and the actor is within this object, and the |
| 2759 |
* actor can't see anything outside of this object; this can happen |
| 2760 |
* simply because we're a top-level room, but it can also happen when |
| 2761 |
* we're a closed opaque container or there's not enough light to see |
| 2762 |
* the enclosing location. |
| 2763 |
* |
| 2764 |
* The parameters have the same meaning as they do in |
| 2765 |
* lookAroundPov(). |
| 2766 |
* |
| 2767 |
* Note that this method must be overridden if a room overrides the |
| 2768 |
* standard mechanism for representing its contents list (i.e., it |
| 2769 |
* doesn't store its complete set of direct contents in its |
| 2770 |
* 'contents' list property). |
| 2771 |
* |
| 2772 |
* In most cases, this routine will only be called in Room and |
| 2773 |
* NestedRoom objects, because actors can normally only enter those |
| 2774 |
* types of objects. However, it is possible to try to describe the |
| 2775 |
* interior of other types of objects if (1) the game allows actors |
| 2776 |
* to enter other types of objects, or (2) the game provides a |
| 2777 |
* non-actor point-of-view object, such as a video camera, that can |
| 2778 |
* be placed in ordinary containers and which transmit what they see |
| 2779 |
* for remote viewing. |
| 2780 |
*/ |
| 2781 |
lookAroundWithin(actor, pov, verbose) |
| 2782 |
{ |
| 2783 |
local illum; |
| 2784 |
local infoTab; |
| 2785 |
local info; |
| 2786 |
local specialList; |
| 2787 |
local specialBefore, specialAfter; |
| 2788 |
|
| 2789 |
/* check for the special 'true' and 'nil' settings for 'verbose' */ |
| 2790 |
if (verbose == true) |
| 2791 |
{ |
| 2792 |
/* true -> show the standard verbose description */ |
| 2793 |
verbose = (LookRoomName | LookRoomDesc |
| 2794 |
| LookListSpecials | LookListPortables); |
| 2795 |
} |
| 2796 |
else if (verbose == nil) |
| 2797 |
{ |
| 2798 |
/* nil -> show the standard terse description */ |
| 2799 |
verbose = (LookRoomName | LookListSpecials | LookListPortables); |
| 2800 |
} |
| 2801 |
|
| 2802 |
/* |
| 2803 |
* if we've never seen the room before, include the room |
| 2804 |
* description, even if it wasn't specifically requested |
| 2805 |
*/ |
| 2806 |
if (!actor.hasSeen(self)) |
| 2807 |
verbose |= LookRoomDesc; |
| 2808 |
|
| 2809 |
/* |
| 2810 |
* get a table of all of the objects that the viewer can sense |
| 2811 |
* in the location using sight-like senses |
| 2812 |
*/ |
| 2813 |
infoTab = actor.visibleInfoTableFromPov(pov); |
| 2814 |
|
| 2815 |
/* get the ambient illumination at the point of view */ |
| 2816 |
info = infoTab[pov]; |
| 2817 |
if (info != nil) |
| 2818 |
{ |
| 2819 |
/* get the ambient illumination from the info list item */ |
| 2820 |
illum = info.ambient; |
| 2821 |
} |
| 2822 |
else |
| 2823 |
{ |
| 2824 |
/* the actor's not in the list, so it must be completely dark */ |
| 2825 |
illum = 0; |
| 2826 |
} |
| 2827 |
|
| 2828 |
/* |
| 2829 |
* adjust the list of described items (usually, this removes the |
| 2830 |
* point-of-view object from the list, to ensure that we don't |
| 2831 |
* list it among the room's contents) |
| 2832 |
*/ |
| 2833 |
adjustLookAroundTable(infoTab, pov, actor); |
| 2834 |
|
| 2835 |
/* if desired, display the room name */ |
| 2836 |
if ((verbose & LookRoomName) != 0) |
| 2837 |
{ |
| 2838 |
"<.roomname>"; |
| 2839 |
lookAroundWithinName(actor, illum); |
| 2840 |
"<./roomname>"; |
| 2841 |
} |
| 2842 |
|
| 2843 |
/* if we're in verbose mode, display the full description */ |
| 2844 |
if ((verbose & LookRoomDesc) != 0) |
| 2845 |
{ |
| 2846 |
/* display the full room description */ |
| 2847 |
"<.roomdesc>"; |
| 2848 |
lookAroundWithinDesc(actor, illum); |
| 2849 |
"<./roomdesc>"; |
| 2850 |
} |
| 2851 |
|
| 2852 |
/* show the initial special descriptions, if desired */ |
| 2853 |
if ((verbose & LookListSpecials) != 0) |
| 2854 |
{ |
| 2855 |
local plst; |
| 2856 |
|
| 2857 |
/* |
| 2858 |
* Display any special description messages for visible |
| 2859 |
* objects, other than those carried by the actor. These |
| 2860 |
* messages are part of the verbose description rather than |
| 2861 |
* the portable item listing, because these messages are |
| 2862 |
* meant to look like part of the room's full description |
| 2863 |
* and thus should not be included in a non-verbose listing. |
| 2864 |
* |
| 2865 |
* Note that we only want to show objects that are currently |
| 2866 |
* using special descriptions AND which aren't contained in |
| 2867 |
* the actor doing the looking, so subset the list |
| 2868 |
* accordingly. |
| 2869 |
*/ |
| 2870 |
specialList = specialDescList( |
| 2871 |
infoTab, |
| 2872 |
{obj: obj.useSpecialDescInRoom(self) && !obj.isIn(actor)}); |
| 2873 |
|
| 2874 |
/* |
| 2875 |
* partition the special list into the parts to be shown |
| 2876 |
* before and after the portable contents list |
| 2877 |
*/ |
| 2878 |
plst = partitionList(specialList, |
| 2879 |
{obj: obj.specialDescBeforeContents}); |
| 2880 |
specialBefore = plst[1]; |
| 2881 |
specialAfter = plst[2]; |
| 2882 |
|
| 2883 |
/* |
| 2884 |
* at this point, describe only the items that are to be |
| 2885 |
* listed specially before the room's portable contents list |
| 2886 |
*/ |
| 2887 |
specialContentsLister.showList(pov, nil, specialBefore, |
| 2888 |
0, 0, infoTab, nil); |
| 2889 |
} |
| 2890 |
|
| 2891 |
/* show the portable items, if desired */ |
| 2892 |
if ((verbose & LookListPortables) != 0) |
| 2893 |
{ |
| 2894 |
/* |
| 2895 |
* Describe each visible object directly contained in the |
| 2896 |
* room that wants to be listed - generally, we list any |
| 2897 |
* mobile objects that don't have special descriptions. We |
| 2898 |
* list items in all room descriptions, verbose or not, |
| 2899 |
* because the portable item list is more of a status display |
| 2900 |
* than it is a part of the full description. |
| 2901 |
* |
| 2902 |
* Note that the infoTab has sense data that will ensure that |
| 2903 |
* we don't show anything we shouldn't if the room is dark. |
| 2904 |
*/ |
| 2905 |
lookAroundWithinContents(actor, illum, infoTab); |
| 2906 |
} |
| 2907 |
|
| 2908 |
/* |
| 2909 |
* If we're showing special descriptions, show the special descs |
| 2910 |
* for any items that want to be listed after the room's portable |
| 2911 |
* contents. |
| 2912 |
*/ |
| 2913 |
if ((verbose & LookListSpecials) != 0) |
| 2914 |
{ |
| 2915 |
/* show the subset that's listed after the room contents */ |
| 2916 |
specialContentsLister.showList(pov, nil, specialAfter, |
| 2917 |
0, 0, infoTab, nil); |
| 2918 |
} |
| 2919 |
|
| 2920 |
/* show all of the sounds we can hear */ |
| 2921 |
lookAroundWithinSense(actor, pov, sound, roomListenLister); |
| 2922 |
|
| 2923 |
/* show all of the odors we can smell */ |
| 2924 |
lookAroundWithinSense(actor, pov, smell, roomSmellLister); |
| 2925 |
|
| 2926 |
/* show the exits, if desired */ |
| 2927 |
lookAroundWithinShowExits(actor, illum); |
| 2928 |
|
| 2929 |
/* |
| 2930 |
* If we're not in the dark, note that we've been seen. Don't |
| 2931 |
* count this as having seen the location if we're in the dark, |
| 2932 |
* since we won't normally describe any detail in the dark. |
| 2933 |
*/ |
| 2934 |
if (illum > 1) |
| 2935 |
actor.setHasSeen(self); |
| 2936 |
} |
| 2937 |
|
| 2938 |
/* |
| 2939 |
* Display the "status line" name of the room. This is normally a |
| 2940 |
* brief, single-line description. |
| 2941 |
* |
| 2942 |
* By long-standing convention, each location in a game usually has a |
| 2943 |
* distinctive name that's displayed here. Players usually find |
| 2944 |
* these names helpful in forming a mental map of the game. |
| 2945 |
* |
| 2946 |
* By default, if we have an enclosing location, and the actor can |
| 2947 |
* see the enclosing location, we'll defer to the location. |
| 2948 |
* Otherwise, we'll display our roo interior name. |
| 2949 |
*/ |
| 2950 |
statusName(actor) |
| 2951 |
{ |
| 2952 |
/* |
| 2953 |
* use the enclosing location's status name if there is an |
| 2954 |
* enclosing location and its visible; otherwise, show our |
| 2955 |
* interior room name |
| 2956 |
*/ |
| 2957 |
if (location != nil && actor.canSee(location)) |
| 2958 |
location.statusName(actor); |
| 2959 |
else |
| 2960 |
lookAroundWithinName(actor, actor.getVisualAmbient()); |
| 2961 |
} |
| 2962 |
|
| 2963 |
/* |
| 2964 |
* Adjust the sense table a "look around" command. This is called |
| 2965 |
* after we calculate the sense info table, but before we start |
| 2966 |
* describing any of the room's contents, to give us a chance to |
| 2967 |
* remove any items we don't want described (or, conceivably, to add |
| 2968 |
* any items we do want described but which won't show up with the |
| 2969 |
* normal sense calculations). |
| 2970 |
* |
| 2971 |
* By default, we simply remove the point-of-view object from the |
| 2972 |
* list, to ensure that it's not included among the objects mentioned |
| 2973 |
* as being in the room. We don't want to mention the point of view |
| 2974 |
* because the POV object because a POV isn't normally in its own |
| 2975 |
* field of view. |
| 2976 |
*/ |
| 2977 |
adjustLookAroundTable(tab, pov, actor) |
| 2978 |
{ |
| 2979 |
/* remove the POV object from the table */ |
| 2980 |
tab.removeElement(pov); |
| 2981 |
|
| 2982 |
/* give the actor a chance to adjust the table as well */ |
| 2983 |
if (self not in (actor, pov)) |
| 2984 |
{ |
| 2985 |
/* let the POV object adjust the table */ |
| 2986 |
pov.adjustLookAroundTable(tab, pov, actor); |
| 2987 |
|
| 2988 |
/* if the actor differs from the POV, let it adjust the table */ |
| 2989 |
if (actor != pov) |
| 2990 |
actor.adjustLookAroundTable(tab, pov, actor); |
| 2991 |
} |
| 2992 |
} |
| 2993 |
|
| 2994 |
/* |
| 2995 |
* Show my name for a "look around" command. This is used to display |
| 2996 |
* the location name when we're providing the room description. |
| 2997 |
* 'illum' is the ambient visual sense level at the point of view. |
| 2998 |
* |
| 2999 |
* By default, we show our interior room name or interior dark room |
| 3000 |
* name, as appropriate to the ambient light level at the point of |
| 3001 |
* view. |
| 3002 |
*/ |
| 3003 |
lookAroundWithinName(actor, illum) |
| 3004 |
{ |
| 3005 |
/* |
| 3006 |
* if there's light, show our name; otherwise, show our |
| 3007 |
* in-the-dark name |
| 3008 |
*/ |
| 3009 |
if (illum > 1) |
| 3010 |
{ |
| 3011 |
/* we can see, so show our interior description */ |
| 3012 |
"\^<<roomName>>"; |
| 3013 |
} |
| 3014 |
else |
| 3015 |
{ |
| 3016 |
/* we're in the dark, so show our default dark name */ |
| 3017 |
say(roomDarkName); |
| 3018 |
} |
| 3019 |
|
| 3020 |
/* show the actor's posture as part of the description */ |
| 3021 |
actor.actorRoomNameStatus(self); |
| 3022 |
} |
| 3023 |
|
| 3024 |
/* |
| 3025 |
* Show our "look around" long description. This is used to display |
| 3026 |
* the location's full description when we're providing the room |
| 3027 |
* description - that is, when the actor doing the looking is inside |
| 3028 |
* me. This displays only the room-specific portion of the room's |
| 3029 |
* description; it does not display the status line or anything |
| 3030 |
* about the room's dynamic contents. |
| 3031 |
*/ |
| 3032 |
lookAroundWithinDesc(actor, illum) |
| 3033 |
{ |
| 3034 |
/* |
| 3035 |
* check for illumination - we must have at least dim ambient |
| 3036 |
* lighting (level 2) to see the room's long description |
| 3037 |
*/ |
| 3038 |
if (illum > 1) |
| 3039 |
{ |
| 3040 |
local pov = getPOVDefault(actor); |
| 3041 |
|
| 3042 |
/* |
| 3043 |
* Display the normal description of the room - use the |
| 3044 |
* roomRemoteDesc if the actor isn't in the same room OR the |
| 3045 |
* point of view isn't the same as the actor; use the |
| 3046 |
* firstDesc if this is the first time in the room; and |
| 3047 |
* otherwise the basic roomDesc. |
| 3048 |
*/ |
| 3049 |
if (!actor.isIn(self) || actor != pov) |
| 3050 |
{ |
| 3051 |
/* we're viewing the room remotely */ |
| 3052 |
roomRemoteDesc(actor); |
| 3053 |
} |
| 3054 |
else if (actor.hasSeen(self)) |
| 3055 |
{ |
| 3056 |
/* we've seen it already - show the basic room description */ |
| 3057 |
roomDesc; |
| 3058 |
} |
| 3059 |
else |
| 3060 |
{ |
| 3061 |
/* |
| 3062 |
* we've never seen this location before - show the |
| 3063 |
* first-time description |
| 3064 |
*/ |
| 3065 |
roomFirstDesc; |
| 3066 |
} |
| 3067 |
} |
| 3068 |
else |
| 3069 |
{ |
| 3070 |
/* display the in-the-dark description of the room */ |
| 3071 |
roomDarkDesc; |
| 3072 |
} |
| 3073 |
} |
| 3074 |
|
| 3075 |
/* |
| 3076 |
* Show my room contents for a "look around" description within this |
| 3077 |
* object. |
| 3078 |
*/ |
| 3079 |
lookAroundWithinContents(actor, illum, infoTab) |
| 3080 |
{ |
| 3081 |
local lst; |
| 3082 |
local lister; |
| 3083 |
local remoteLst; |
| 3084 |
local recurse; |
| 3085 |
|
| 3086 |
/* get our outermost enclosing room */ |
| 3087 |
local outer = getOutermostRoom(); |
| 3088 |
|
| 3089 |
/* mark everything visible from the room as having been seen */ |
| 3090 |
setAllSeenBy(infoTab, actor); |
| 3091 |
|
| 3092 |
/* |
| 3093 |
* if the illumination is less than 'dim' (level 2), display |
| 3094 |
* only self-illuminating items |
| 3095 |
*/ |
| 3096 |
if (illum != nil && illum < 2) |
| 3097 |
{ |
| 3098 |
/* |
| 3099 |
* We're in the dark - list only those objects that the actor |
| 3100 |
* can sense via the sight-like senses, which will be the |
| 3101 |
* list of self-illuminating objects. Don't include items |
| 3102 |
* being carried by the actor, though, since those don't |
| 3103 |
* count as part of the actor's surroundings. (To produce |
| 3104 |
* this list, simply make a list consisting of all of the |
| 3105 |
* objects in the sense info table that aren't contained in |
| 3106 |
* the actor; since the table naturally includes only objects |
| 3107 |
* that are illuminated, the entire contents of the table |
| 3108 |
* will give us the visible objects.) |
| 3109 |
*/ |
| 3110 |
lst = senseInfoTableSubset( |
| 3111 |
infoTab, {obj, info: !obj.isIn(actor)}); |
| 3112 |
|
| 3113 |
/* use my dark contents lister */ |
| 3114 |
lister = darkRoomContentsLister; |
| 3115 |
|
| 3116 |
/* there are no remote-room lists to generate */ |
| 3117 |
remoteLst = nil; |
| 3118 |
|
| 3119 |
/* |
| 3120 |
* Since we can't see what we're looking at, we can't see the |
| 3121 |
* positional relationships among the things we're looking |
| 3122 |
* at, so we can't show the contents tree recursively. We |
| 3123 |
* just want to show our flat list of what's visible on |
| 3124 |
* account of self-illumination. |
| 3125 |
*/ |
| 3126 |
recurse = nil; |
| 3127 |
} |
| 3128 |
else |
| 3129 |
{ |
| 3130 |
/* start with my contents list */ |
| 3131 |
lst = contents; |
| 3132 |
|
| 3133 |
/* always remove the actor from the list */ |
| 3134 |
lst -= actor; |
| 3135 |
|
| 3136 |
/* |
| 3137 |
* Use the normal (lighted) lister. Note that if the actor |
| 3138 |
* isn't in the same room, or the point of view isn't the |
| 3139 |
* same as the actor, we want to generate remote |
| 3140 |
* descriptions, so use the remote contents lister in these |
| 3141 |
* cases. |
| 3142 |
*/ |
| 3143 |
lister = (actor.isIn(self) && actor == getPOVDefault(actor) |
| 3144 |
? roomContentsLister |
| 3145 |
: remoteRoomContentsLister(self)); |
| 3146 |
|
| 3147 |
/* |
| 3148 |
* Generate a list of all of the *other* top-level rooms |
| 3149 |
* with contents visible from here. To do this, build a |
| 3150 |
* list of all of the unique top-level rooms, other than our |
| 3151 |
* own top-level room, that contain items in the visible |
| 3152 |
* information table. |
| 3153 |
*/ |
| 3154 |
remoteLst = new Vector(5); |
| 3155 |
infoTab.forEachAssoc(function(obj, info) |
| 3156 |
{ |
| 3157 |
/* if this object isn't in our top-level room, note it */ |
| 3158 |
if (obj != outer && !obj.isIn(outer)) |
| 3159 |
{ |
| 3160 |
local objOuter; |
| 3161 |
|
| 3162 |
/* |
| 3163 |
* it's not in our top-level room, so find its |
| 3164 |
* top-level room |
| 3165 |
*/ |
| 3166 |
objOuter = obj.getOutermostRoom(); |
| 3167 |
|
| 3168 |
/* if this one isn't in our list yet, add it */ |
| 3169 |
if (remoteLst.indexOf(objOuter) == nil) |
| 3170 |
remoteLst.append(objOuter); |
| 3171 |
} |
| 3172 |
}); |
| 3173 |
|
| 3174 |
/* |
| 3175 |
* since we can see what we're looking at, show the |
| 3176 |
* relationships among the contents by listing recursively |
| 3177 |
*/ |
| 3178 |
recurse = true; |
| 3179 |
} |
| 3180 |
|
| 3181 |
/* add a paragraph before the room's contents */ |
| 3182 |
"<.p>"; |
| 3183 |
|
| 3184 |
/* show the contents */ |
| 3185 |
lister.showList(actor, self, lst, (recurse ? ListRecurse : 0), |
| 3186 |
0, infoTab, nil, examinee: self); |
| 3187 |
|
| 3188 |
/* |
| 3189 |
* if we can see anything in remote top-level rooms, show the |
| 3190 |
* contents of each other room with visible contents |
| 3191 |
*/ |
| 3192 |
if (remoteLst != nil) |
| 3193 |
{ |
| 3194 |
/* show each remote room's contents */ |
| 3195 |
for (local i = 1, local len = remoteLst.length() ; i <= len ; ++i) |
| 3196 |
{ |
| 3197 |
local cur; |
| 3198 |
local cont; |
| 3199 |
|
| 3200 |
/* get this item */ |
| 3201 |
cur = remoteLst[i]; |
| 3202 |
|
| 3203 |
/* start with the direct contents of this remote room */ |
| 3204 |
cont = cur.contents; |
| 3205 |
|
| 3206 |
/* |
| 3207 |
* Remove any objects that are also contents of the |
| 3208 |
* local room or of any other room we've already listed. |
| 3209 |
* It's possible that we have a MultiLoc that's in one |
| 3210 |
* or more of the visible top-level locations, so we |
| 3211 |
* need to make sure we only list each one once. |
| 3212 |
*/ |
| 3213 |
cont = cont.subset({x: !x.isIn(outer)}); |
| 3214 |
for (local j = 1 ; j < i ; ++j) |
| 3215 |
cont = cont.subset({x: !x.isIn(remoteLst[j])}); |
| 3216 |
|
| 3217 |
/* |
| 3218 |
* list this remote room's contents using our remote |
| 3219 |
* lister for this remote room |
| 3220 |
*/ |
| 3221 |
outer.remoteRoomContentsLister(cur).showList( |
| 3222 |
actor, cur, cont, ListRecurse, 0, infoTab, nil, |
| 3223 |
examinee: self); |
| 3224 |
} |
| 3225 |
} |
| 3226 |
} |
| 3227 |
|
| 3228 |
/* |
| 3229 |
* Add to the room description a list of things we notice through a |
| 3230 |
* specific sense. This is used to add things we can hear and smell |
| 3231 |
* to a room description. |
| 3232 |
*/ |
| 3233 |
lookAroundWithinSense(actor, pov, sense, lister) |
| 3234 |
{ |
| 3235 |
local infoTab; |
| 3236 |
local presenceList; |
| 3237 |
|
| 3238 |
/* |
| 3239 |
* get the information table for the desired sense from the |
| 3240 |
* given point of view |
| 3241 |
*/ |
| 3242 |
infoTab = pov.senseInfoTable(sense); |
| 3243 |
|
| 3244 |
/* |
| 3245 |
* Get the list of everything with a presence in this sense. |
| 3246 |
* Include only items that aren't part of the actor's inventory, |
| 3247 |
* since inventory items aren't part of the room and thus |
| 3248 |
* shouldn't be described as part of the room. |
| 3249 |
*/ |
| 3250 |
presenceList = senseInfoTableSubset(infoTab, |
| 3251 |
{obj, info: obj.(sense.presenceProp) && !obj.isIn(actor)}); |
| 3252 |
|
| 3253 |
/* mark each item in the presence list as known */ |
| 3254 |
foreach (local cur in presenceList) |
| 3255 |
actor.setKnowsAbout(cur); |
| 3256 |
|
| 3257 |
/* list the items */ |
| 3258 |
lister.showList(pov, nil, presenceList, 0, 0, infoTab, nil, |
| 3259 |
examinee: self); |
| 3260 |
} |
| 3261 |
|
| 3262 |
/* |
| 3263 |
* Show the exits from this room as part of a description of the |
| 3264 |
* room, if applicable. By default, if we have an exit lister |
| 3265 |
* object, we'll invoke it to show the exits. |
| 3266 |
*/ |
| 3267 |
lookAroundWithinShowExits(actor, illum) |
| 3268 |
{ |
| 3269 |
/* if we have an exit lister, have it show a list of exits */ |
| 3270 |
if (gExitLister != nil) |
| 3271 |
gExitLister.lookAroundShowExits(actor, self, illum); |
| 3272 |
} |
| 3273 |
|
| 3274 |
/* |
| 3275 |
* Get my lighted room contents lister - this is the Lister object |
| 3276 |
* that we use to display the room's contents when the room is lit. |
| 3277 |
* We'll return the default library room lister. |
| 3278 |
*/ |
| 3279 |
roomContentsLister { return roomLister; } |
| 3280 |
|
| 3281 |
/* |
| 3282 |
* Get my lister for the contents of the given remote room. A |
| 3283 |
* remote room is a separate top-level room that an actor can see |
| 3284 |
* from its current location; for example, if two top-level rooms |
| 3285 |
* are connected by a window, so that an actor standing in one room |
| 3286 |
* can see into the other room, then the other room is the remote |
| 3287 |
* room, from the actor's perspective. |
| 3288 |
* |
| 3289 |
* This is called on the actor's outermost room to get the lister |
| 3290 |
* for objects visible in the given remote room. This lets each |
| 3291 |
* room customize the way it describes the objects in adjoining |
| 3292 |
* rooms as seen from its point of view. |
| 3293 |
* |
| 3294 |
* We provide a simple default lister that yields decent results in |
| 3295 |
* most cases. However, it's often desirable to customize this, to |
| 3296 |
* be more specific about how we see the items: "Through the window, |
| 3297 |
* you see..." or "Further down the hall, you see...". An easy way |
| 3298 |
* to provide such custom listings is to return a new |
| 3299 |
* CustomRoomLister, supplying the prefix and suffix strings as |
| 3300 |
* parameters: |
| 3301 |
* |
| 3302 |
*. return new CustomRoomLister( |
| 3303 |
*. 'Further down the hall, {you/he} see{s}', '.'); |
| 3304 |
*/ |
| 3305 |
remoteRoomContentsLister(other) { return new RemoteRoomLister(other); } |
| 3306 |
|
| 3307 |
/* |
| 3308 |
* Get my dark room contents lister - this is the Lister object we'll |
| 3309 |
* use to display the room's self-illuminating contents when the room |
| 3310 |
* is dark. |
| 3311 |
*/ |
| 3312 |
darkRoomContentsLister { return darkRoomLister; } |
| 3313 |
|
| 3314 |
/* |
| 3315 |
* Get the outermost containing room. We return our container, if |
| 3316 |
* we have one, or self if not. |
| 3317 |
*/ |
| 3318 |
getOutermostRoom() |
| 3319 |
{ |
| 3320 |
/* return our container's outermost room, if we have one */ |
| 3321 |
return (location != nil ? location.getOutermostRoom() : self); |
| 3322 |
} |
| 3323 |
|
| 3324 |
/* get the outermost room that's visible from the given point of view */ |
| 3325 |
getOutermostVisibleRoom(pov) |
| 3326 |
{ |
| 3327 |
local enc; |
| 3328 |
|
| 3329 |
/* |
| 3330 |
* Get our outermost enclosing visible room - this is the |
| 3331 |
* outermost enclosing room that the POV can see. If we manage |
| 3332 |
* to find an enclosing visible room, return that, since it's |
| 3333 |
* "more outer" than we are. |
| 3334 |
*/ |
| 3335 |
if (location != nil |
| 3336 |
&& (enc = location.getOutermostVisibleRoom(pov)) != nil) |
| 3337 |
return enc; |
| 3338 |
|
| 3339 |
/* |
| 3340 |
* We either don't have any enclosing rooms, or none of them are |
| 3341 |
* visible. So, our outermost enclosing room is one of two |
| 3342 |
* things: if we're visible, it's us; if we're not even visible |
| 3343 |
* ourselves, there's no visible room at all, so return nil. |
| 3344 |
*/ |
| 3345 |
return (pov.canSee(self) ? self : nil); |
| 3346 |
} |
| 3347 |
|
| 3348 |
/* |
| 3349 |
* Get the location traveler - this is the object that's actually |
| 3350 |
* going to change location when a traveler within this location |
| 3351 |
* performs a travel command to travel via the given connector. By |
| 3352 |
* default, we'll indicate what our containing room indicates. (The |
| 3353 |
* enclosing room might be a vehicle or an ordinary room; in any |
| 3354 |
* case, it'll know what to do, so we merely have to ask it.) |
| 3355 |
* |
| 3356 |
* We defer to our enclosing room by default because this allows for |
| 3357 |
* things like a seat in a car: the actor is sitting in the seat and |
| 3358 |
* starts traveling in the car, so the seat calls the enclosing room, |
| 3359 |
* which is the car, and the car returns itself, since it's the car |
| 3360 |
* that will be traveling. |
| 3361 |
*/ |
| 3362 |
getLocTraveler(trav, conn) |
| 3363 |
{ |
| 3364 |
/* |
| 3365 |
* if we have a location, defer to it; otherwise, just return the |
| 3366 |
* proposed traveler |
| 3367 |
*/ |
| 3368 |
return (location != nil ? location.getLocTraveler(trav, conn) : trav); |
| 3369 |
} |
| 3370 |
|
| 3371 |
/* |
| 3372 |
* Get the "location push traveler" - this is the object that's going |
| 3373 |
* to travel for a push-travel action performed by a traveler within |
| 3374 |
* this location. This is called by a traveler within this location |
| 3375 |
* to find out if the location wants to be involved in the travel, as |
| 3376 |
* a vehicle might be. By default, we let our location handle it, if |
| 3377 |
* we have one. |
| 3378 |
*/ |
| 3379 |
getLocPushTraveler(trav, obj) |
| 3380 |
{ |
| 3381 |
/* |
| 3382 |
* defer to our location if we have one, otherwise just use the |
| 3383 |
* proposed traveler |
| 3384 |
*/ |
| 3385 |
return (location != nil |
| 3386 |
? location.getLocPushTraveler(trav, obj) |
| 3387 |
: trav); |
| 3388 |
} |
| 3389 |
|
| 3390 |
/* |
| 3391 |
* Get the travel preconditions for an actor in this location. For |
| 3392 |
* ordinary objects, we'll just defer to our container, if we have |
| 3393 |
* one. |
| 3394 |
*/ |
| 3395 |
roomTravelPreCond() |
| 3396 |
{ |
| 3397 |
/* if we have a location, defer to it */ |
| 3398 |
if (location != nil) |
| 3399 |
return location.roomTravelPreCond(); |
| 3400 |
|
| 3401 |
/* |
| 3402 |
* we have no location, and we impose no conditions of our by |
| 3403 |
* default, so simply return an empty list |
| 3404 |
*/ |
| 3405 |
return []; |
| 3406 |
} |
| 3407 |
|
| 3408 |
/* |
| 3409 |
* Determine if the current gActor, who is directly in this location, |
| 3410 |
* is "travel ready." This means that the actor is ready, as far as |
| 3411 |
* this location is concerned, to traverse the given connector. By |
| 3412 |
* default, we'll defer to our location. |
| 3413 |
* |
| 3414 |
* Note that if you override this to return nil, you should also |
| 3415 |
* provide a custom 'notTravelReadyMsg' property that explains the |
| 3416 |
* objection. |
| 3417 |
*/ |
| 3418 |
isActorTravelReady(conn) |
| 3419 |
{ |
| 3420 |
/* if we have a location, defer to it */ |
| 3421 |
if (location != nil) |
| 3422 |
return location.isActorTravelReady(conn); |
| 3423 |
|
| 3424 |
/* |
| 3425 |
* we have no location, and we impose no conditions of our own by |
| 3426 |
* default, so we have no objection |
| 3427 |
*/ |
| 3428 |
return true; |
| 3429 |
} |
| 3430 |
|
| 3431 |
/* explain the reason isActorTravelReady() returned nil */ |
| 3432 |
notTravelReadyMsg = (location != nil ? location.notTravelReadyMsg : nil) |
| 3433 |
|
| 3434 |
/* show a list of exits as part of failed travel - defer to location */ |
| 3435 |
cannotGoShowExits(actor) |
| 3436 |
{ |
| 3437 |
if (location != nil) |
| 3438 |
location.cannotGoShowExits(actor); |
| 3439 |
} |
| 3440 |
|
| 3441 |
/* show exits in the statusline - defer to our location */ |
| 3442 |
showStatuslineExits() |
| 3443 |
{ |
| 3444 |
if (location != nil) |
| 3445 |
location.showStatuslineExits(); |
| 3446 |
} |
| 3447 |
|
| 3448 |
/* get the status line exit lister height - defer to our location */ |
| 3449 |
getStatuslineExitsHeight() |
| 3450 |
{ return location != nil ? location.getStatuslineExitsHeight() : 0; } |
| 3451 |
|
| 3452 |
/* |
| 3453 |
* Get the travel connector from this location in the given |
| 3454 |
* direction. |
| 3455 |
* |
| 3456 |
* Map all of the directional connections to their values in the |
| 3457 |
* enclosing location, except for any explicitly defined in this |
| 3458 |
* object. (In most cases, ordinary objects won't define any |
| 3459 |
* directional connectors directly, since those connections usually |
| 3460 |
* apply only to top-level rooms.) |
| 3461 |
* |
| 3462 |
* If 'actor' is non-nil, we'll limit our search to enclosing |
| 3463 |
* locations that the actor can currently see. If 'actor' is nil, |
| 3464 |
* we'll consider any connector in any enclosing location, whether |
| 3465 |
* the actor can see the enclosing location or not. It's useful to |
| 3466 |
* pass in a nil actor in cases where we're interested in the |
| 3467 |
* structure of the map and not actual travel, such as when |
| 3468 |
* constructing an automatic map or computing possible courses |
| 3469 |
* between locations. |
| 3470 |
*/ |
| 3471 |
getTravelConnector(dir, actor) |
| 3472 |
{ |
| 3473 |
local conn; |
| 3474 |
|
| 3475 |
/* |
| 3476 |
* if we explicitly define the link property, and the result is a |
| 3477 |
* non-nil value, use that definition |
| 3478 |
*/ |
| 3479 |
if (propDefined(dir.dirProp) && (conn = self.(dir.dirProp)) != nil) |
| 3480 |
return conn; |
| 3481 |
|
| 3482 |
/* |
| 3483 |
* We don't define the direction link explicitly. If the actor |
| 3484 |
* can see our container, or there's no actor involved, retrieve |
| 3485 |
* the link from our container; otherwise, stop here, and simply |
| 3486 |
* return the default link for the direction. |
| 3487 |
*/ |
| 3488 |
if (location != nil && (actor == nil || actor.canSee(location))) |
| 3489 |
{ |
| 3490 |
/* |
| 3491 |
* the actor can see out to our location (or there's no actor |
| 3492 |
* involved at all), so get the connector for the location |
| 3493 |
*/ |
| 3494 |
return location.getTravelConnector(dir, actor); |
| 3495 |
} |
| 3496 |
else |
| 3497 |
{ |
| 3498 |
/* |
| 3499 |
* the actor can't see our location, so there's no way to |
| 3500 |
* travel this way - return the default connector for the |
| 3501 |
* direction |
| 3502 |
*/ |
| 3503 |
return dir.defaultConnector(self); |
| 3504 |
} |
| 3505 |
} |
| 3506 |
|
| 3507 |
/* |
| 3508 |
* Search our direction list for a connector that will lead the |
| 3509 |
* given actor to the given destination. |
| 3510 |
*/ |
| 3511 |
getConnectorTo(actor, dest) |
| 3512 |
{ |
| 3513 |
local conn; |
| 3514 |
|
| 3515 |
/* search all of our directions */ |
| 3516 |
foreach (local dir in Direction.allDirections) |
| 3517 |
{ |
| 3518 |
/* get the connector for this direction */ |
| 3519 |
conn = getTravelConnector(dir, actor); |
| 3520 |
|
| 3521 |
/* ask the connector for a connector to the given destination */ |
| 3522 |
if (conn != nil) |
| 3523 |
conn = conn.connectorGetConnectorTo(self, actor, dest); |
| 3524 |
|
| 3525 |
/* if we found a valid connector, return it */ |
| 3526 |
if (conn != nil) |
| 3527 |
return conn; |
| 3528 |
} |
| 3529 |
|
| 3530 |
/* didn't find a match */ |
| 3531 |
return nil; |
| 3532 |
} |
| 3533 |
|
| 3534 |
/* |
| 3535 |
* Find a direction linked to a given connector, for travel by the |
| 3536 |
* given actor. Returns the first direction (as a Direction object) |
| 3537 |
* we find linked to the connector, or nil if we don't find any |
| 3538 |
* direction linked to it. |
| 3539 |
*/ |
| 3540 |
directionForConnector(conn, actor) |
| 3541 |
{ |
| 3542 |
/* search all known directions */ |
| 3543 |
foreach (local dir in Direction.allDirections) |
| 3544 |
{ |
| 3545 |
/* if this direction is linked to the connector, return it */ |
| 3546 |
if (self.getTravelConnector(dir, actor) == conn) |
| 3547 |
return dir; |
| 3548 |
} |
| 3549 |
|
| 3550 |
/* we didn't find any directions linked to the connector */ |
| 3551 |
return nil; |
| 3552 |
} |
| 3553 |
|
| 3554 |
/* |
| 3555 |
* Find the "local" direction link from this object to the given |
| 3556 |
* travel connector. We'll only consider our own local direction |
| 3557 |
* links; we won't consider enclosing objects. |
| 3558 |
*/ |
| 3559 |
localDirectionLinkForConnector(conn) |
| 3560 |
{ |
| 3561 |
/* scan all direction links */ |
| 3562 |
foreach (local dir in Direction.allDirections) |
| 3563 |
{ |
| 3564 |
/* |
| 3565 |
* if we define this direction property to point to this |
| 3566 |
* connector, we've found our required location |
| 3567 |
*/ |
| 3568 |
if (self.(dir.dirProp) == conn) |
| 3569 |
return dir; |
| 3570 |
} |
| 3571 |
|
| 3572 |
/* we didn't find a direction linked to the given connector */ |
| 3573 |
return nil; |
| 3574 |
} |
| 3575 |
|
| 3576 |
/* |
| 3577 |
* Check that a traveler is directly in this room. By default, a |
| 3578 |
* Thing is not a room, so a connector within a Thing actually |
| 3579 |
* requires the traveler to be in the Thing's container, not in the |
| 3580 |
* Thing itself. So, defer to our container. |
| 3581 |
*/ |
| 3582 |
checkTravelerDirectlyInRoom(traveler, allowImplicit) |
| 3583 |
{ |
| 3584 |
/* defer to our location */ |
| 3585 |
return location.checkTravelerDirectlyInRoom(traveler, allowImplicit); |
| 3586 |
} |
| 3587 |
|
| 3588 |
/* |
| 3589 |
* Check, using pre-condition rules, that the actor is removed from |
| 3590 |
* this nested location and moved to its exit destination. |
| 3591 |
* |
| 3592 |
* This is called when the actor is attempting to move to an object |
| 3593 |
* outside of this object while the actor is within this object (for |
| 3594 |
* example, if we have a platform containing a box containing a |
| 3595 |
* chair, 'self' is the box, and the actor is in the chair, an |
| 3596 |
* attempt to move to the platform will trigger a call to |
| 3597 |
* box.checkActorOutOfNested). |
| 3598 |
* |
| 3599 |
* By default, we're not a nested location, but we could *contain* |
| 3600 |
* nested locations. So what we need to do is defer to the child |
| 3601 |
* object that actually contains the actor, to let it figure out what |
| 3602 |
* it means to move the actor out of itself. |
| 3603 |
*/ |
| 3604 |
checkActorOutOfNested(allowImplicit) |
| 3605 |
{ |
| 3606 |
/* find the child containing the actor, and ask it to do the work */ |
| 3607 |
foreach (local cur in contents) |
| 3608 |
{ |
| 3609 |
if (gActor.isIn(cur)) |
| 3610 |
return cur.checkActorOutOfNested(allowImplicit); |
| 3611 |
} |
| 3612 |
|
| 3613 |
/* didn't find a child containing the actor; just fail */ |
| 3614 |
reportFailure(&cannotDoFromHereMsg); |
| 3615 |
exit; |
| 3616 |
} |
| 3617 |
|
| 3618 |
/* |
| 3619 |
* Get my "room location." If 'self' is capable of holding actors, |
| 3620 |
* this should return 'self'; otherwise, it should return the |
| 3621 |
* nearest enclosing container that's a room location. By default, |
| 3622 |
* we simply return our location's room location. |
| 3623 |
*/ |
| 3624 |
roomLocation = (location != nil ? location.roomLocation : nil) |
| 3625 |
|
| 3626 |
/* |
| 3627 |
* Get the apparent location of one of our room parts (the floor, |
| 3628 |
* the ceiling, etc). By default, we'll simply ask our container |
| 3629 |
* about it, since a nested room by default doesn't have any of the |
| 3630 |
* standard room parts. |
| 3631 |
*/ |
| 3632 |
getRoomPartLocation(part) |
| 3633 |
{ |
| 3634 |
if (location != nil) |
| 3635 |
return location.getRoomPartLocation(part); |
| 3636 |
else |
| 3637 |
return nil; |
| 3638 |
} |
| 3639 |
|
| 3640 |
/* |
| 3641 |
* By default, an object containing the player character will forward |
| 3642 |
* the roomDaemon() call up to the container. |
| 3643 |
*/ |
| 3644 |
roomDaemon() |
| 3645 |
{ |
| 3646 |
if (location != nil) |
| 3647 |
location.roomDaemon(); |
| 3648 |
} |
| 3649 |
|
| 3650 |
/* |
| 3651 |
* Our room atmospheric message list. This can be set to an |
| 3652 |
* EventList that provides messages to be displayed while the player |
| 3653 |
* character is within this object. |
| 3654 |
* |
| 3655 |
* By default, if our container is visible to us, we'll use our |
| 3656 |
* container's atmospheric messages. This can be overridden to |
| 3657 |
* provide our own atmosphere list when the player character is in |
| 3658 |
* this object. |
| 3659 |
*/ |
| 3660 |
atmosphereList() |
| 3661 |
{ |
| 3662 |
if (location != nil && gPlayerChar.canSee(location)) |
| 3663 |
return location.atmosphereList; |
| 3664 |
else |
| 3665 |
return nil; |
| 3666 |
} |
| 3667 |
|
| 3668 |
/* |
| 3669 |
* Get the notification list actions performed by actors within this |
| 3670 |
* object. Ordinary objects don't have room notification lists, but |
| 3671 |
* we might be part of a nested set of objects that includes rooms, |
| 3672 |
* so simply look to our container for the notification list. |
| 3673 |
*/ |
| 3674 |
getRoomNotifyList() |
| 3675 |
{ |
| 3676 |
local lst = []; |
| 3677 |
|
| 3678 |
/* get the notification lists for our immediate containers */ |
| 3679 |
forEachContainer( |
| 3680 |
{cont: lst = lst.appendUnique(cont.getRoomNotifyList())}); |
| 3681 |
|
| 3682 |
/* return the result */ |
| 3683 |
return lst; |
| 3684 |
} |
| 3685 |
|
| 3686 |
/* |
| 3687 |
* Are we aboard a ship? By default, we'll return our location's |
| 3688 |
* setting for this property; if we have no location, we'll return |
| 3689 |
* nil. In general, this should be overridden in shipboard rooms to |
| 3690 |
* return true. |
| 3691 |
* |
| 3692 |
* The purpose of this property is to indicate to the travel system |
| 3693 |
* that shipboard directions (fore, aft, port, starboard) make sense |
| 3694 |
* here. When this returns true, and an actor attempts travel in a |
| 3695 |
* shipboard direction that doesn't allow travel here, we'll use the |
| 3696 |
* standard noTravel message. When this returns nil, attempting to |
| 3697 |
* move in a shipboard direction will show a different response that |
| 3698 |
* indicates that such directions are not meaningful when not aboard |
| 3699 |
* a ship of some kind. |
| 3700 |
* |
| 3701 |
* Note that we look to our location unconditionally - we don't |
| 3702 |
* bother to check to see if we're open, transparent, or anything |
| 3703 |
* like that, so we'll check with our location even if the actor |
| 3704 |
* can't see the location. The idea is that, no matter how nested |
| 3705 |
* within opaque containers we are, we should still know that we're |
| 3706 |
* aboard a ship. This might not always be appropriate; if the |
| 3707 |
* actor is magically transported into an opaque container that |
| 3708 |
* happens to be aboard a ship somewhere, the actor probably |
| 3709 |
* shouldn't think of the location as shipboard until escaping the |
| 3710 |
* container, unless they'd know because of the rocking of the ship |
| 3711 |
* or some other sensory factor that would come through the opaque |
| 3712 |
* container. When the shipboard nature of an interior location |
| 3713 |
* should not be known to the actor, this should simply be |
| 3714 |
* overridden to return nil. |
| 3715 |
*/ |
| 3716 |
isShipboard() |
| 3717 |
{ |
| 3718 |
/* if we have a location, use its setting; otherwise return nil */ |
| 3719 |
return (location != nil ? location.isShipboard() : nil); |
| 3720 |
} |
| 3721 |
|
| 3722 |
/* |
| 3723 |
* When an actor takes me, the actor will assign me a holding index |
| 3724 |
* value, which is simply a serial number indicating the order in |
| 3725 |
* which I was picked up. This lets the actor determine which items |
| 3726 |
* have been held longest: the item with the lowest holding index |
| 3727 |
* has been held the longest. |
| 3728 |
*/ |
| 3729 |
holdingIndex = 0 |
| 3730 |
|
| 3731 |
/* |
| 3732 |
* An object has "weight" and "bulk" specifying how heavy and how |
| 3733 |
* large the object is. These are in arbitrary units, and by |
| 3734 |
* default everything has a weight of 1 and a bulk of 1. |
| 3735 |
*/ |
| 3736 |
weight = 1 |
| 3737 |
bulk = 1 |
| 3738 |
|
| 3739 |
/* |
| 3740 |
* Calculate the bulk contained within this object. By default, |
| 3741 |
* we'll simply add up the bulks of all of our contents. |
| 3742 |
*/ |
| 3743 |
getBulkWithin() |
| 3744 |
{ |
| 3745 |
local total; |
| 3746 |
|
| 3747 |
/* add up the bulks of our contents */ |
| 3748 |
total = 0; |
| 3749 |
foreach (local cur in contents) |
| 3750 |
total += cur.getBulk(); |
| 3751 |
|
| 3752 |
/* return the total */ |
| 3753 |
return total; |
| 3754 |
} |
| 3755 |
|
| 3756 |
/* |
| 3757 |
* get my "destination name," for travel purposes; by default, we |
| 3758 |
* simply defer to our location, if we have one |
| 3759 |
*/ |
| 3760 |
getDestName(actor, origin) |
| 3761 |
{ |
| 3762 |
if (location != nil) |
| 3763 |
return location.getDestName(actor, origin); |
| 3764 |
else |
| 3765 |
return ''; |
| 3766 |
} |
| 3767 |
|
| 3768 |
/* |
| 3769 |
* Get the effective location of an actor directly within me, for the |
| 3770 |
* purposes of a "follow" command. To follow someone, we must have |
| 3771 |
* the same effective follow location that the target had when we |
| 3772 |
* last observed the target leaving. |
| 3773 |
* |
| 3774 |
* For most objects, we simply defer to the location. |
| 3775 |
*/ |
| 3776 |
effectiveFollowLocation = (location != nil |
| 3777 |
? location.effectiveFollowLocation |
| 3778 |
: self) |
| 3779 |
|
| 3780 |
/* |
| 3781 |
* Get the destination for an object dropped within me. Ordinary |
| 3782 |
* objects can't contain actors, so an actor can't directly drop |
| 3783 |
* something within a regular Thing, but the same effect could occur |
| 3784 |
* if an actor throws a projectile, since the projectile might reach |
| 3785 |
* either the target or an intermediate obstruction, then bounce off |
| 3786 |
* and land in whatever contains the object hit. |
| 3787 |
* |
| 3788 |
* By default, objects dropped within us won't stay within us, but |
| 3789 |
* will land in our container's drop destination. |
| 3790 |
* |
| 3791 |
* 'obj' is the object being dropped. In some cases, the drop |
| 3792 |
* destination might differ according to the object; for example, if |
| 3793 |
* the floor is a metal grating, a large object might land on the |
| 3794 |
* grating when dropped, but a small object such as a coin might drop |
| 3795 |
* through the grating to the room below. Note that 'obj' can be |
| 3796 |
* nil, if the caller simply wants to determine the generic |
| 3797 |
* destination where a *typical* object would land if dropped - this |
| 3798 |
* routine must therefore not assume that 'obj' is non-nil. |
| 3799 |
* |
| 3800 |
* 'path' is the sense path (as returned by selectPathTo and the |
| 3801 |
* like) traversed by the operation that's seeking the drop |
| 3802 |
* destination. For ordinary single-location objects, the path is |
| 3803 |
* irrelevant, but this information is sometimes useful for |
| 3804 |
* multi-location objects to let them know which "side" we approached |
| 3805 |
* them from. Note that the path can be nil, so this routine must |
| 3806 |
* not depend upon a path being supplied; if the path is nil, the |
| 3807 |
* routine should assume that the ordinary "touch" sense path from |
| 3808 |
* the current actor to 'self' is to be used, because the actor is |
| 3809 |
* effectively reaching out and placing an object on self. This |
| 3810 |
* means that when calling this routine, you can supply a nil path |
| 3811 |
* any time the actor is simply dropping an object. |
| 3812 |
*/ |
| 3813 |
getDropDestination(obj, path) |
| 3814 |
{ |
| 3815 |
/* |
| 3816 |
* by default, the object lands in our container's drop |
| 3817 |
* destination; if we don't have a container, drop it here |
| 3818 |
*/ |
| 3819 |
return location != nil |
| 3820 |
? location.getDropDestination(obj, path) |
| 3821 |
: self; |
| 3822 |
} |
| 3823 |
|
| 3824 |
/* |
| 3825 |
* Adjust a drop destination chosen in a THROW. This is called on |
| 3826 |
* the object that was chosen as the preliminary landing location for |
| 3827 |
* the thrown object, as calculated by getHitFallDestination(), to |
| 3828 |
* give the preliminary destination a chance to redirect the landing |
| 3829 |
* to another object. For example, if the preliminary destination |
| 3830 |
* simply isn't a suitable surface or container where a projectile |
| 3831 |
* could land, or it's not big enough to hold the projectile, the |
| 3832 |
* preliminary destination could override this method to redirect the |
| 3833 |
* landing to a more suitable object. |
| 3834 |
* |
| 3835 |
* By default, we don't need to make any adjustment, so we simply |
| 3836 |
* return 'self' to indicate that this can be used as the actual |
| 3837 |
* destination. |
| 3838 |
*/ |
| 3839 |
adjustThrowDestination(thrownObj, path) |
| 3840 |
{ |
| 3841 |
return self; |
| 3842 |
} |
| 3843 |
|
| 3844 |
/* |
| 3845 |
* Receive a dropped object. This is called when we are the actual |
| 3846 |
* (not nominal) drop destination for an object being dropped, |
| 3847 |
* thrown, or otherwise discarded. This routine is responsible for |
| 3848 |
* carrying out the drop operation, and reporting the result of the |
| 3849 |
* command. |
| 3850 |
* |
| 3851 |
* 'desc' is a "drop descriptor": an object of class DropType, which |
| 3852 |
* describes how the object is being discarded. This can be a |
| 3853 |
* DropTypeDrop for a DROP command, a DropTypeThrow for a THROW |
| 3854 |
* command, or custom types defined by the game or by library |
| 3855 |
* extensions. |
| 3856 |
* |
| 3857 |
* In most cases, the actual *result* of dropping the object will |
| 3858 |
* always be the same for a given location, regardless of which |
| 3859 |
* command initiated the drop, so this routine won't usually have to |
| 3860 |
* look at 'desc' at all to figure out what happens. |
| 3861 |
* |
| 3862 |
* However, the *message* we generate does usually vary according to |
| 3863 |
* the drop type, because this is the report for the entire command. |
| 3864 |
* There are three main ways of handling this variation. |
| 3865 |
* |
| 3866 |
* - First, you can check what kind of descriptor it is (using |
| 3867 |
* ofKind, for example), and generate a custom message for each kind |
| 3868 |
* of descriptor. Be aware that any library extensions you're using |
| 3869 |
* might have added new DropType subclasses. |
| 3870 |
* |
| 3871 |
* - Second, experienced programmers might prefer the arguably |
| 3872 |
* cleaner OO "visitor" pattern: treat 'desc' as a visitor, calling a |
| 3873 |
* single method that you define for your custom message. You'll |
| 3874 |
* have to define that custom method in each DropType subclass, of |
| 3875 |
* course. |
| 3876 |
* |
| 3877 |
* - Third, you can build a custom message by combining the standard |
| 3878 |
* "message fragment" prefix provided by the drop descriptor with |
| 3879 |
* your own suffix. The prefix will always be the start of a |
| 3880 |
* sentence describing what the player did: "You drop the box", "The |
| 3881 |
* ball hits the wall and bounces off", and so on. Since the |
| 3882 |
* fragment always has the form of the start of a sentence, you can |
| 3883 |
* always add your own suffix: ", and falls to the floor", for |
| 3884 |
* example, or ", and falls into the chasm". Note that if you're |
| 3885 |
* using one of the other approaches above, you'll probably want to |
| 3886 |
* combine that approach with this one to handle cases where you |
| 3887 |
* don't recognize the drop descriptor type. |
| 3888 |
* |
| 3889 |
* By default, we simply move the object into self and display the |
| 3890 |
* standard message using the descriptor (we use the "visitor" |
| 3891 |
* pattern to display that standard message). This can be overridden |
| 3892 |
* in cases where it's necessary to move the object to a different |
| 3893 |
* location, or to invoke a side effect. |
| 3894 |
*/ |
| 3895 |
receiveDrop(obj, desc) |
| 3896 |
{ |
| 3897 |
/* simply move the object into self */ |
| 3898 |
obj.moveInto(self); |
| 3899 |
|
| 3900 |
/* generate the standard message */ |
| 3901 |
desc.standardReport(obj, self); |
| 3902 |
} |
| 3903 |
|
| 3904 |
/* |
| 3905 |
* Get the nominal destination for an object dropped into this |
| 3906 |
* object. This is used to report where an object ends up when the |
| 3907 |
* object is moved into me by some indirect route, such as throwing |
| 3908 |
* the object. |
| 3909 |
* |
| 3910 |
* By default, most objects simply return themselves, so we'll |
| 3911 |
* report something like "obj lands {in/on} self". Some objects |
| 3912 |
* might want to report a different object as the destination; for |
| 3913 |
* example, an indoor room might want to report objects as falling |
| 3914 |
* onto the floor. |
| 3915 |
*/ |
| 3916 |
getNominalDropDestination() { return self; } |
| 3917 |
|
| 3918 |
/* |
| 3919 |
* Announce myself as a default object for an action. By default, |
| 3920 |
* we'll show the standard library message announcing a default. |
| 3921 |
*/ |
| 3922 |
announceDefaultObject(whichObj, action, resolvedAllObjects) |
| 3923 |
{ |
| 3924 |
/* use the standard library message for the announcement */ |
| 3925 |
return gLibMessages.announceDefaultObject( |
| 3926 |
self, whichObj, action, resolvedAllObjects); |
| 3927 |
} |
| 3928 |
|
| 3929 |
/* |
| 3930 |
* Calculate my total weight. Weight is generally inclusive of the |
| 3931 |
* weights of contents or components, because anything inside an |
| 3932 |
* object normally contributes to the object's total weight. |
| 3933 |
*/ |
| 3934 |
getWeight() |
| 3935 |
{ |
| 3936 |
local total; |
| 3937 |
|
| 3938 |
/* start with my own intrinsic weight */ |
| 3939 |
total = weight; |
| 3940 |
|
| 3941 |
/* |
| 3942 |
* add the weights of my direct contents, recursively |
| 3943 |
* calculating their total weights |
| 3944 |
*/ |
| 3945 |
foreach (local cur in contents) |
| 3946 |
total += cur.getWeight(); |
| 3947 |
|
| 3948 |
/* return the total */ |
| 3949 |
return total; |
| 3950 |
} |
| 3951 |
|
| 3952 |
/* |
| 3953 |
* Calculate my total bulk. Most objects have a fixed external |
| 3954 |
* shape (and thus bulk) that doesn't vary as contents are added or |
| 3955 |
* removed, so our default implementation simply returns our |
| 3956 |
* intrinsic bulk without considering any contents. |
| 3957 |
* |
| 3958 |
* Some objects do change shape as contents are added. Such objects |
| 3959 |
* can override this routine to provide the appropriate behavior. |
| 3960 |
* (We don't try to provide a parameterized total bulk calculator |
| 3961 |
* here because there are too many possible ways a container's bulk |
| 3962 |
* could be affected by its contents or by other factors.) |
| 3963 |
* |
| 3964 |
* If an object's bulk depends on its contents, the object should |
| 3965 |
* override notifyInsert() so that it calls checkBulkChange() - this |
| 3966 |
* will ensure that an object won't suddenly become too large for |
| 3967 |
* its container (or holding actor). |
| 3968 |
*/ |
| 3969 |
getBulk() |
| 3970 |
{ |
| 3971 |
/* by default, simply return my intrinsic bulk */ |
| 3972 |
return bulk; |
| 3973 |
} |
| 3974 |
|
| 3975 |
/* |
| 3976 |
* Calculate the amount of bulk that this object contributes towards |
| 3977 |
* encumbering an actor directly holding the item. By default, this |
| 3978 |
* simply returns my total bulk. |
| 3979 |
* |
| 3980 |
* Some types of objects will override this to cause the object to |
| 3981 |
* contribute more or less bulk to an actor holding the object. For |
| 3982 |
* example, an article of clothing being worn by an actor typically |
| 3983 |
* contributes no bulk at all to the actor's encumbrance, because an |
| 3984 |
* actor wearing an item typically doesn't also have to hold on to |
| 3985 |
* the item. Or, a small animal might encumber an actor more than |
| 3986 |
* its normal bulk because it's squirming around trying to get free. |
| 3987 |
*/ |
| 3988 |
getEncumberingBulk(actor) |
| 3989 |
{ |
| 3990 |
/* by default, return our normal total bulk */ |
| 3991 |
return getBulk(); |
| 3992 |
} |
| 3993 |
|
| 3994 |
/* |
| 3995 |
* Calculate the amount of weight that this object contributes |
| 3996 |
* towards encumbering an actor directly holding the item. By |
| 3997 |
* default, this simply returns my total weight. |
| 3998 |
* |
| 3999 |
* Note that we don't recursively sum the encumbering weights of our |
| 4000 |
* contents - we simply sum the actual weights. We do it this way |
| 4001 |
* because items within a container aren't being directly held by |
| 4002 |
* the actor, so any difference between the encumbering and actual |
| 4003 |
* weights should not apply, even though the actor is indirectly |
| 4004 |
* holding the items. If a subclass does want the sum of the |
| 4005 |
* encumbering weights, it should override this to make that |
| 4006 |
* calculation. |
| 4007 |
*/ |
| 4008 |
getEncumberingWeight(actor) |
| 4009 |
{ |
| 4010 |
/* by default, return our normal total weight */ |
| 4011 |
return getWeight(); |
| 4012 |
} |
| 4013 |
|
| 4014 |
/* |
| 4015 |
* "What if" test. Make the given changes temporarily, bypassing |
| 4016 |
* any side effects that would normally be associated with the |
| 4017 |
* changes; invokes the given callback; then remove the changes. |
| 4018 |
* Returns the result of calling the callback function. |
| 4019 |
* |
| 4020 |
* The changes are expressed as pairs of argument values. The first |
| 4021 |
* value in a pair is a property, and the second is a new value for |
| 4022 |
* the property. For each pair, we'll set the given property to the |
| 4023 |
* given value. The setting is direct - we don't invoke any method, |
| 4024 |
* because we don't want to cause any side effects at this point; |
| 4025 |
* we're interested only in what the world would look like if the |
| 4026 |
* given changes were to go into effect. |
| 4027 |
* |
| 4028 |
* A special property value of 'moveInto' can be used to indicate |
| 4029 |
* that the object should be moved into another object for the test. |
| 4030 |
* In this case, the second element of the pair is not a value to be |
| 4031 |
* stored into the moveInto property, but instead the value is a new |
| 4032 |
* location for the object. We'll call the baseMoveInto method to |
| 4033 |
* move the object to the given new location. |
| 4034 |
* |
| 4035 |
* In any case, after making the changes, we'll invoke the given |
| 4036 |
* callback function, which we'll call with no arguments. |
| 4037 |
* |
| 4038 |
* Finally, on our way out, we'll restore the properties we changed |
| 4039 |
* to their original values. We once again do this without any side |
| 4040 |
* effects. Note that we restore the old values even if we exit |
| 4041 |
* with an exception. |
| 4042 |
*/ |
| 4043 |
whatIf(func, [changes]) |
| 4044 |
{ |
| 4045 |
local oldList; |
| 4046 |
local cnt; |
| 4047 |
local i; |
| 4048 |
|
| 4049 |
/* |
| 4050 |
* Allocate a vector with one slot per change, so that we have a |
| 4051 |
* place to store the old values of the properties we're |
| 4052 |
* changing. Note that the argument list has two entries (prop, |
| 4053 |
* value) for each change. |
| 4054 |
*/ |
| 4055 |
cnt = changes.length(); |
| 4056 |
oldList = new Vector(cnt / 2); |
| 4057 |
|
| 4058 |
/* run through the change list and make each change */ |
| 4059 |
for (i = 1 ; i <= cnt ; i += 2) |
| 4060 |
{ |
| 4061 |
local curProp; |
| 4062 |
local newVal; |
| 4063 |
|
| 4064 |
/* get the current property and new value */ |
| 4065 |
curProp = changes[i]; |
| 4066 |
newVal = changes[i+1]; |
| 4067 |
|
| 4068 |
/* see what we have */ |
| 4069 |
switch(curProp) |
| 4070 |
{ |
| 4071 |
case &moveInto: |
| 4072 |
/* |
| 4073 |
* It's the special moveInto property. This indicates |
| 4074 |
* that we are to move self into the given new |
| 4075 |
* location. First save the current location, then |
| 4076 |
* use baseMoveInto to make the change without |
| 4077 |
* triggering any side effects. Note that if this |
| 4078 |
* would create circular containment, we won't make |
| 4079 |
* the move. |
| 4080 |
*/ |
| 4081 |
oldList.append(saveLocation()); |
| 4082 |
if (newVal != self && !newVal.isIn(self)) |
| 4083 |
baseMoveInto(newVal); |
| 4084 |
break; |
| 4085 |
|
| 4086 |
default: |
| 4087 |
/* |
| 4088 |
* Anything else is a property to which we want to |
| 4089 |
* assign the given new value. Remember the old value |
| 4090 |
* in our original values vector, then set the new value |
| 4091 |
* from the argument. |
| 4092 |
*/ |
| 4093 |
oldList.append(self.(curProp)); |
| 4094 |
self.(curProp) = newVal; |
| 4095 |
break; |
| 4096 |
} |
| 4097 |
} |
| 4098 |
|
| 4099 |
/* |
| 4100 |
* the changes are now in effect - invoke the given callback |
| 4101 |
* function to check things out under the new conditions, but |
| 4102 |
* protect the code so that we are sure to restore things on the |
| 4103 |
* way out |
| 4104 |
*/ |
| 4105 |
try |
| 4106 |
{ |
| 4107 |
/* invoke the given callback, returning the result */ |
| 4108 |
return (func)(); |
| 4109 |
} |
| 4110 |
finally |
| 4111 |
{ |
| 4112 |
/* run through the change list and undo each change */ |
| 4113 |
for (i = 1, local j = 1 ; i <= cnt ; i += 2, ++j) |
| 4114 |
{ |
| 4115 |
local curProp; |
| 4116 |
local oldVal; |
| 4117 |
|
| 4118 |
/* get the current property and old value */ |
| 4119 |
curProp = changes[i]; |
| 4120 |
oldVal = oldList[j]; |
| 4121 |
|
| 4122 |
/* see what we have */ |
| 4123 |
switch(curProp) |
| 4124 |
{ |
| 4125 |
case &moveInto: |
| 4126 |
/* restore the location that we saved */ |
| 4127 |
restoreLocation(oldVal); |
| 4128 |
break; |
| 4129 |
|
| 4130 |
default: |
| 4131 |
/* restore the property value */ |
| 4132 |
self.(curProp) = oldVal; |
| 4133 |
break; |
| 4134 |
} |
| 4135 |
} |
| 4136 |
} |
| 4137 |
} |
| 4138 |
|
| 4139 |
/* |
| 4140 |
* Run a what-if test to see what would happen if this object were |
| 4141 |
* being held directly by the given actor. |
| 4142 |
*/ |
| 4143 |
whatIfHeldBy(func, actor) |
| 4144 |
{ |
| 4145 |
/* |
| 4146 |
* by default, simply run the what-if test with this object |
| 4147 |
* moved into the actor's inventory |
| 4148 |
*/ |
| 4149 |
return whatIf(func, &moveInto, actor); |
| 4150 |
} |
| 4151 |
|
| 4152 |
/* |
| 4153 |
* Check a proposed change in my bulk. When this is called, the new |
| 4154 |
* bulk should already be in effect (the best way to do this when |
| 4155 |
* just making a check is via whatIf). |
| 4156 |
* |
| 4157 |
* This routine can be called during the 'check' or 'action' stages |
| 4158 |
* of processing a command to determine if a change in my bulk would |
| 4159 |
* cause a problem. If so, we'll add a failure report and exit the |
| 4160 |
* command. |
| 4161 |
* |
| 4162 |
* By default, notify our immediate container of the change to see |
| 4163 |
* if there's any objection. A change in an object's bulk typically |
| 4164 |
* only aaffects its container or containers. |
| 4165 |
* |
| 4166 |
* The usual way to invoke this routine in a 'check' or 'action' |
| 4167 |
* routine is with something like this: |
| 4168 |
* |
| 4169 |
* whatIf({: checkBulkChange()}, &inflated, true); |
| 4170 |
* |
| 4171 |
* This checks to see if the change in my bulk implied by changing |
| 4172 |
* self.inflated to true would present a problem for my container, |
| 4173 |
* terminating with a reportFailure+exit if so. |
| 4174 |
*/ |
| 4175 |
checkBulkChange() |
| 4176 |
{ |
| 4177 |
/* |
| 4178 |
* Notify each of our containers of a change in our bulk; if |
| 4179 |
* any container has a problem with our new bulk, it can |
| 4180 |
* report a failure and exit. |
| 4181 |
*/ |
| 4182 |
forEachContainer( |
| 4183 |
{loc: loc.checkBulkChangeWithin(self)}); |
| 4184 |
} |
| 4185 |
|
| 4186 |
/* |
| 4187 |
* Check a bulk change of one of my direct contents, given by obj. |
| 4188 |
* When this is called, 'obj' will be (tentatively) set to reflect |
| 4189 |
* its proposed new bulk; if this routine doesn't like the new bulk, |
| 4190 |
* it should issue a failure report and exit the command, which will |
| 4191 |
* cancel the command that would have caused the change and will |
| 4192 |
* prevent the proposed change from taking effect. |
| 4193 |
* |
| 4194 |
* By default, we'll do nothing; subclasses that are sensitive to |
| 4195 |
* the bulks of their contents should override this. |
| 4196 |
*/ |
| 4197 |
checkBulkChangeWithin(changingObj) |
| 4198 |
{ |
| 4199 |
} |
| 4200 |
|
| 4201 |
/* |
| 4202 |
* Get "bag of holding" affinities for the given list of objects. |
| 4203 |
* For each item in the list, we'll get the item's bulk, and get |
| 4204 |
* each bag's affinity for containing the item. We'll note the bag |
| 4205 |
* with the highest affinity. Once we have the list, we'll put it |
| 4206 |
* in descending order of affinity, and return the result as a |
| 4207 |
* vector. |
| 4208 |
*/ |
| 4209 |
getBagAffinities(lst) |
| 4210 |
{ |
| 4211 |
local infoVec; |
| 4212 |
local bagVec; |
| 4213 |
|
| 4214 |
/* |
| 4215 |
* First, build a list of all of the bags of holding within me. |
| 4216 |
* We start with the list of bags because we want to check each |
| 4217 |
* object to see which bag we might want to put it in. |
| 4218 |
*/ |
| 4219 |
bagVec = new Vector(10); |
| 4220 |
getBagsOfHolding(bagVec); |
| 4221 |
|
| 4222 |
/* if there are no bags of holding, there will be no affinities */ |
| 4223 |
if (bagVec.length() == 0) |
| 4224 |
return []; |
| 4225 |
|
| 4226 |
/* create a vector to hold information on each child item */ |
| 4227 |
infoVec = new Vector(lst.length()); |
| 4228 |
|
| 4229 |
/* look at each child item */ |
| 4230 |
foreach (local cur in lst) |
| 4231 |
{ |
| 4232 |
local maxAff; |
| 4233 |
local bestBag; |
| 4234 |
|
| 4235 |
/* find the bag with the highest affinity for this item */ |
| 4236 |
maxAff = 0; |
| 4237 |
bestBag = nil; |
| 4238 |
foreach (local bag in bagVec) |
| 4239 |
{ |
| 4240 |
local aff; |
| 4241 |
|
| 4242 |
/* get this bag's affinity for this item */ |
| 4243 |
aff = bag.affinityFor(cur); |
| 4244 |
|
| 4245 |
/* |
| 4246 |
* If this is the best so far, note it. If this bag has |
| 4247 |
* an affinity of zero for this item, it means it |
| 4248 |
* doesn't want it at all, so don't even consider it in |
| 4249 |
* this case. |
| 4250 |
*/ |
| 4251 |
if (aff != 0 && (bestBag == nil || aff > maxAff)) |
| 4252 |
{ |
| 4253 |
/* this is the best so far - note it */ |
| 4254 |
maxAff = aff; |
| 4255 |
bestBag = bag; |
| 4256 |
} |
| 4257 |
} |
| 4258 |
|
| 4259 |
/* |
| 4260 |
* if we found a bag that wants this item, add it to our |
| 4261 |
* list of results |
| 4262 |
*/ |
| 4263 |
if (bestBag != nil) |
| 4264 |
infoVec.append(new BagAffinityInfo( |
| 4265 |
cur, cur.getEncumberingBulk(self), |
| 4266 |
maxAff, bestBag)); |
| 4267 |
} |
| 4268 |
|
| 4269 |
/* sort the list in descending order of affinity */ |
| 4270 |
infoVec = infoVec.sort(SortDesc, {a, b: a.compareAffinityTo(b)}); |
| 4271 |
|
| 4272 |
/* |
| 4273 |
* Go through the list and ensure that any item in the list |
| 4274 |
* that's destined to go inside another item that's also in the |
| 4275 |
* list gets put in the other item before the second item gets |
| 4276 |
* put in its bag. For example, if we have a credit card that |
| 4277 |
* goes in a wallet, and a wallet that goes in a pocket, we want |
| 4278 |
* to ensure that we put the credit card in the wallet before we |
| 4279 |
* put the wallet in the pocket. |
| 4280 |
* |
| 4281 |
* The point of this reordering is that, in some cases, we might |
| 4282 |
* not be able to move the first item once the second item has |
| 4283 |
* been moved. In our credit-card/wallet/pocket example, the |
| 4284 |
* wallet might have to be closed to go in the pocket, at which |
| 4285 |
* point we'd have to take it out again to put the credit card |
| 4286 |
* into it, defeating the purpose of having put it away in the |
| 4287 |
* first place. We avoid these kinds of circular traps by |
| 4288 |
* making sure the list is ordered such that we dispose of the |
| 4289 |
* credit card first, then the wallet. |
| 4290 |
* |
| 4291 |
* To avoid looping forever in cases of circular containment, |
| 4292 |
* don't allow any more moves than there are items in the list. |
| 4293 |
*/ |
| 4294 |
for (local i = 1, local len = infoVec.length(), local moves = 0 ; |
| 4295 |
i <= len && moves <= len ; ++i) |
| 4296 |
{ |
| 4297 |
/* get this item and its destination */ |
| 4298 |
local cur = infoVec[i]; |
| 4299 |
local dest = cur.bag_; |
| 4300 |
|
| 4301 |
/* |
| 4302 |
* check to see if the destination itself appears in the |
| 4303 |
* list as an item to be bagged |
| 4304 |
*/ |
| 4305 |
local idx = infoVec.indexWhich({x: x.obj_ == dest}); |
| 4306 |
|
| 4307 |
/* |
| 4308 |
* if the destination item appears in the list before the |
| 4309 |
* current item, move the current item before its |
| 4310 |
* destination |
| 4311 |
*/ |
| 4312 |
if (idx != nil && idx < i) |
| 4313 |
{ |
| 4314 |
/* remove the current item from the list */ |
| 4315 |
infoVec.removeElementAt(i); |
| 4316 |
|
| 4317 |
/* re-insert it just before its destination item */ |
| 4318 |
infoVec.insertAt(idx, cur); |
| 4319 |
|
| 4320 |
/* count the move */ |
| 4321 |
++moves; |
| 4322 |
|
| 4323 |
/* |
| 4324 |
* Now, back up and resume the scan from the item just |
| 4325 |
* after the item that moves our destination bag. This |
| 4326 |
* will ensure that any items destined to go in the bag |
| 4327 |
* we just moved are caught. (Although note that we |
| 4328 |
* start just after the destination item, rather than at |
| 4329 |
* the destination item, because the destination item |
| 4330 |
* can't be legitimately moved at this point: if it is, |
| 4331 |
* it's because we have a circular containment plan. We |
| 4332 |
* obviously can't resolve circular containment into a |
| 4333 |
* linear ordering, so there's no point in even looking |
| 4334 |
* at the destination item again at this point. If we |
| 4335 |
* have a circular chain that's several elements long, |
| 4336 |
* this won't avoid getting stuck; for that, we have to |
| 4337 |
* count on our 'moves' limit.) |
| 4338 |
*/ |
| 4339 |
i = idx + 1; |
| 4340 |
} |
| 4341 |
} |
| 4342 |
|
| 4343 |
/* return the result */ |
| 4344 |
return infoVec; |
| 4345 |
} |
| 4346 |
|
| 4347 |
/* |
| 4348 |
* Find all of the bags of holding contained within this object and |
| 4349 |
* add them to the given vector. By default, we'll simply recurse |
| 4350 |
* into our children so they can add their bags of holding. |
| 4351 |
*/ |
| 4352 |
getBagsOfHolding(vec) |
| 4353 |
{ |
| 4354 |
/* |
| 4355 |
* if my contents can't be touched from outside, there's no |
| 4356 |
* point in traversing our children |
| 4357 |
*/ |
| 4358 |
if (transSensingIn(touch) != transparent) |
| 4359 |
return; |
| 4360 |
|
| 4361 |
/* add each of my children's bags to the list */ |
| 4362 |
foreach (local cur in contents) |
| 4363 |
cur.getBagsOfHolding(vec); |
| 4364 |
} |
| 4365 |
|
| 4366 |
/* |
| 4367 |
* The strength of the light the object is giving off, if indeed it |
| 4368 |
* is giving off light. This value should be one of the following: |
| 4369 |
* |
| 4370 |
* 0: The object is giving off no light at all. |
| 4371 |
* |
| 4372 |
* 1: The object is self-illuminating, but doesn't give off enough |
| 4373 |
* light to illuminate any other objects. This is suitable for |
| 4374 |
* something like an LED digital clock. |
| 4375 |
* |
| 4376 |
* 2: The object gives off dim light. This level is bright enough to |
| 4377 |
* illuminate nearby objects, but not enough to go through obscuring |
| 4378 |
* media, and not enough for certain activities requiring strong |
| 4379 |
* lighting, such as reading. |
| 4380 |
* |
| 4381 |
* 3: The object gives off medium light. This level is bright enough |
| 4382 |
* to illuminate nearby objects, and is enough for most activities, |
| 4383 |
* including reading and the like. Traveling through an obscuring |
| 4384 |
* medium reduces this level to dim (2). |
| 4385 |
* |
| 4386 |
* 4: The object gives off strong light. This level is bright enough |
| 4387 |
* to illuminate nearby objects, and travel through an obscuring |
| 4388 |
* medium reduces it to medium light (3). |
| 4389 |
* |
| 4390 |
* Note that the special value -1 is reserved as an invalid level, |
| 4391 |
* used to flag certain events (such as the need to recalculate the |
| 4392 |
* ambient light level from a new point of view). |
| 4393 |
* |
| 4394 |
* Most objects do not give off light at all. |
| 4395 |
*/ |
| 4396 |
brightness = 0 |
| 4397 |
|
| 4398 |
/* |
| 4399 |
* Sense sizes of the object. Each object has an individual size for |
| 4400 |
* each sense. By default, objects are medium for all senses; this |
| 4401 |
* allows them to be sensed from a distance or through an obscuring |
| 4402 |
* medium, but doesn't allow their details to be sensed. |
| 4403 |
*/ |
| 4404 |
sightSize = medium |
| 4405 |
soundSize = medium |
| 4406 |
smellSize = medium |
| 4407 |
touchSize = medium |
| 4408 |
|
| 4409 |
/* |
| 4410 |
* Determine whether or not the object has a "presence" in each |
| 4411 |
* sense. An object has a presence in a sense if an actor |
| 4412 |
* immediately adjacent to the object could detect the object by the |
| 4413 |
* sense alone. For example, an object has a "hearing presence" if |
| 4414 |
* it is making some kind of noise, and does not if it is silent. |
| 4415 |
* |
| 4416 |
* Presence in a given sense is an intrinsic (which does not imply |
| 4417 |
* unchanging) property of the object, in that presence is |
| 4418 |
* independent of the relationship to any given actor. If an alarm |
| 4419 |
* clock is ringing, it has a hearing presence, unconditionally; it |
| 4420 |
* doesn't matter if the alarm clock is sealed inside a sound-proof |
| 4421 |
* box, because whether or not a given actor has a sense path to the |
| 4422 |
* object is a matter for a different computation. |
| 4423 |
* |
| 4424 |
* Note that presence doesn't control access: an actor might have |
| 4425 |
* access to an object for a sense even if the object has no |
| 4426 |
* presence in the sense. Presence indicates whether or not the |
| 4427 |
* object is actively emitting sensory data that would make an actor |
| 4428 |
* aware of the object without specifically trying to apply the |
| 4429 |
* sense to the object. |
| 4430 |
* |
| 4431 |
* By default, an object is visible and touchable, but does not emit |
| 4432 |
* any sound or odor. |
| 4433 |
*/ |
| 4434 |
sightPresence = true |
| 4435 |
soundPresence = nil |
| 4436 |
smellPresence = nil |
| 4437 |
touchPresence = true |
| 4438 |
|
| 4439 |
/* |
| 4440 |
* My "contents lister." This is a Lister object that we use to |
| 4441 |
* display the contents of this object for room descriptions, |
| 4442 |
* inventories, and the like. |
| 4443 |
*/ |
| 4444 |
contentsLister = thingContentsLister |
| 4445 |
|
| 4446 |
/* |
| 4447 |
* the Lister to use when showing my contents as part of my own |
| 4448 |
* description (i.e., for Examine commands) |
| 4449 |
*/ |
| 4450 |
descContentsLister = thingDescContentsLister |
| 4451 |
|
| 4452 |
/* |
| 4453 |
* the Lister to use when showing my contents in response to a |
| 4454 |
* LookIn command |
| 4455 |
*/ |
| 4456 |
lookInLister = thingLookInLister |
| 4457 |
|
| 4458 |
/* |
| 4459 |
* my "in-line" contents lister - this is the Lister object that |
| 4460 |
* we'll use to display my contents parenthetically as part of my |
| 4461 |
* list entry in a second-level contents listing |
| 4462 |
*/ |
| 4463 |
inlineContentsLister = inlineListingContentsLister |
| 4464 |
|
| 4465 |
/* |
| 4466 |
* My "special" contents lister. This is the Lister to use to |
| 4467 |
* display the special descriptions for objects that have special |
| 4468 |
* descriptions when we're showing a room description for this |
| 4469 |
* object. |
| 4470 |
*/ |
| 4471 |
specialContentsLister = specialDescLister |
| 4472 |
|
| 4473 |
|
| 4474 |
/* |
| 4475 |
* Determine if I can be sensed under the given conditions. Returns |
| 4476 |
* true if the object can be sensed, nil if not. If this method |
| 4477 |
* returns nil, this object will not be considered in scope for the |
| 4478 |
* current conditions. |
| 4479 |
* |
| 4480 |
* By default, we return nil if the ambient energy level for the |
| 4481 |
* object is zero. If the ambient level is non-zero, we'll return |
| 4482 |
* true in 'transparent' conditions, nil for 'opaque', and we'll let |
| 4483 |
* the sense decide via its canObjBeSensed() method for any other |
| 4484 |
* transparency conditions. Note that 'ambient' as given here is the |
| 4485 |
* ambient level *at the object*, not as seen along my sense path - |
| 4486 |
* so this should NOT be given as the ambient value from a SenseInfo, |
| 4487 |
* which has already been adjusted for the sense path. |
| 4488 |
*/ |
| 4489 |
canBeSensed(sense, trans, ambient) |
| 4490 |
{ |
| 4491 |
/* |
| 4492 |
* adjust the ambient level for the transparency path, if the |
| 4493 |
* sense uses ambience at all |
| 4494 |
*/ |
| 4495 |
if (sense.ambienceProp != nil) |
| 4496 |
{ |
| 4497 |
/* |
| 4498 |
* adjust the ambient level for the transparency - if that |
| 4499 |
* leaves a level of zero, the object can't be sensed |
| 4500 |
*/ |
| 4501 |
if (adjustBrightness(ambient, trans) == 0) |
| 4502 |
return nil; |
| 4503 |
} |
| 4504 |
|
| 4505 |
/* check the viewing conditions */ |
| 4506 |
switch(trans) |
| 4507 |
{ |
| 4508 |
case transparent: |
| 4509 |
case attenuated: |
| 4510 |
/* |
| 4511 |
* under transparent or attenuated conditions, I appear as |
| 4512 |
* myself |
| 4513 |
*/ |
| 4514 |
return true; |
| 4515 |
|
| 4516 |
case obscured: |
| 4517 |
case distant: |
| 4518 |
/* |
| 4519 |
* ask the sense to determine if I can be sensed under these |
| 4520 |
* conditions |
| 4521 |
*/ |
| 4522 |
return sense.canObjBeSensed(self, trans, ambient); |
| 4523 |
|
| 4524 |
default: |
| 4525 |
/* for any other conditions, I can't be sensed at all */ |
| 4526 |
return nil; |
| 4527 |
} |
| 4528 |
} |
| 4529 |
|
| 4530 |
/* |
| 4531 |
* Determine if I can be sensed IN DETAIL in the given sense, with |
| 4532 |
* the given SenseInfo description. By default, an object's details |
| 4533 |
* can be sensed if the sense path is 'transparent' or 'attenuated', |
| 4534 |
* OR the object's scale in the sense is 'large'. |
| 4535 |
*/ |
| 4536 |
canDetailsBeSensed(sense, info, pov) |
| 4537 |
{ |
| 4538 |
/* if the sense path is opaque, we can be sensed */ |
| 4539 |
if (info == nil || info.trans == opaque) |
| 4540 |
return nil; |
| 4541 |
|
| 4542 |
/* |
| 4543 |
* if we have 'large' scale in the sense, our details can be |
| 4544 |
* sensed under any conditions |
| 4545 |
*/ |
| 4546 |
if (self.(sense.sizeProp) == large) |
| 4547 |
return true; |
| 4548 |
|
| 4549 |
/* |
| 4550 |
* we don't have 'large' scale in the sense, so we can be sensed |
| 4551 |
* in detail only if the sense path is 'transparent' or |
| 4552 |
* 'attenuated' |
| 4553 |
*/ |
| 4554 |
return (info.trans is in (transparent, attenuated)); |
| 4555 |
} |
| 4556 |
|
| 4557 |
/* |
| 4558 |
* Call a method on this object from the given point of view. We'll |
| 4559 |
* push the current point of view, call the method, then restore the |
| 4560 |
* enclosing point of view. |
| 4561 |
*/ |
| 4562 |
fromPOV(actor, pov, propToCall, [args]) |
| 4563 |
{ |
| 4564 |
/* push the new point of view */ |
| 4565 |
pushPOV(actor, pov); |
| 4566 |
|
| 4567 |
/* make sure we pop the point of view no matter how we leave */ |
| 4568 |
try |
| 4569 |
{ |
| 4570 |
/* call the method */ |
| 4571 |
self.(propToCall)(args...); |
| 4572 |
} |
| 4573 |
finally |
| 4574 |
{ |
| 4575 |
/* restore the enclosing point of view on the way out */ |
| 4576 |
popPOV(); |
| 4577 |
} |
| 4578 |
} |
| 4579 |
|
| 4580 |
/* |
| 4581 |
* Every Thing has a location, which is the Thing that contains this |
| 4582 |
* object. A Thing's location can only be a simple object |
| 4583 |
* reference, or nil; it cannot be a list, and it cannot be a method. |
| 4584 |
* |
| 4585 |
* If the location is nil, the object does not exist anywhere in the |
| 4586 |
* simulation's physical model. A nil location can be used to |
| 4587 |
* remove an object from the game world, temporarily or permanently. |
| 4588 |
* |
| 4589 |
* In general, the 'location' property should be declared for each |
| 4590 |
* statically defined object (explicitly or implicitly via the '+' |
| 4591 |
* syntax). 'location' is a private property - it should never be |
| 4592 |
* evaluated or changed by any subclass or by any other object. |
| 4593 |
* Only Thing methods may evaluate or change the 'location' |
| 4594 |
* property. So, you can declare a 'location' property when |
| 4595 |
* defining an object, but you should essentially never refer to |
| 4596 |
* 'location' directly in any other context; instead, use the |
| 4597 |
* location and containment methods (isIn, etc) when you want to |
| 4598 |
* know an object's containment relationship to another object. |
| 4599 |
*/ |
| 4600 |
location = nil |
| 4601 |
|
| 4602 |
/* |
| 4603 |
* Get the direct container we have in common with the given object, |
| 4604 |
* if any. Returns at most one common container. Returns nil if |
| 4605 |
* there is no common location. |
| 4606 |
*/ |
| 4607 |
getCommonDirectContainer(obj) |
| 4608 |
{ |
| 4609 |
/* we haven't found one yet */ |
| 4610 |
local found = nil; |
| 4611 |
|
| 4612 |
/* scan each of our containers for one in common with 'loc' */ |
| 4613 |
forEachContainer(function(loc) { |
| 4614 |
/* |
| 4615 |
* If this location of ours is a direct container of the |
| 4616 |
* other object, it is a common location, so note it. |
| 4617 |
*/ |
| 4618 |
if (obj.isDirectlyIn(loc)) |
| 4619 |
found = loc; |
| 4620 |
}); |
| 4621 |
|
| 4622 |
/* return what we found */ |
| 4623 |
return found; |
| 4624 |
} |
| 4625 |
|
| 4626 |
/* |
| 4627 |
* Get the container (direct or indirect) we have in common with the |
| 4628 |
* object, if any. |
| 4629 |
*/ |
| 4630 |
getCommonContainer(obj) |
| 4631 |
{ |
| 4632 |
/* we haven't found one yet */ |
| 4633 |
local found = nil; |
| 4634 |
|
| 4635 |
/* scan each of our containers for one in common with 'loc' */ |
| 4636 |
forEachContainer(function(loc) { |
| 4637 |
/* |
| 4638 |
* If this location of ours is a direct container of the |
| 4639 |
* other object, it is a common location, so note it. |
| 4640 |
*/ |
| 4641 |
if (obj.isIn(loc)) |
| 4642 |
found = loc; |
| 4643 |
}); |
| 4644 |
|
| 4645 |
/* if we found a common container, return it */ |
| 4646 |
if (found != nil) |
| 4647 |
return found; |
| 4648 |
|
| 4649 |
/* |
| 4650 |
* we didn't find obj's container among our direct containers, |
| 4651 |
* so try our direct container's containers |
| 4652 |
*/ |
| 4653 |
forEachContainer(function(loc) { |
| 4654 |
local cur; |
| 4655 |
|
| 4656 |
/* try finding for a common container of this container */ |
| 4657 |
cur = loc.getCommonContainer(obj); |
| 4658 |
|
| 4659 |
/* if we found it, note it */ |
| 4660 |
if (cur != nil) |
| 4661 |
found = cur; |
| 4662 |
}); |
| 4663 |
|
| 4664 |
/* return what we found */ |
| 4665 |
return found; |
| 4666 |
} |
| 4667 |
|
| 4668 |
/* |
| 4669 |
* Get our "identity" object. This is the object that we appear to |
| 4670 |
* be an inseparable part of. |
| 4671 |
* |
| 4672 |
* In most cases, an object is its own identity object. However, |
| 4673 |
* there are times when the object that a player sees isn't the same |
| 4674 |
* as the object that the parser resolves, because we're modeling a |
| 4675 |
* single physical object with several programming objects. For |
| 4676 |
* example, a complex container has one or more secret internal |
| 4677 |
* program objects representing the different sub-containers; as far |
| 4678 |
* as the player is concerned, all of the sub-containers are just |
| 4679 |
* aspects of the parent complex container, not separate object, so |
| 4680 |
* the sub-containers all have the identity of the parent complex |
| 4681 |
* container. |
| 4682 |
* |
| 4683 |
* By default, this is simply 'self'. Objects that take their |
| 4684 |
* effective identities from other objects must override this |
| 4685 |
* accordingly. |
| 4686 |
*/ |
| 4687 |
getIdentityObject() { return self; } |
| 4688 |
|
| 4689 |
/* |
| 4690 |
* Am I a component of the given object? The base Thing is not a |
| 4691 |
* component of anything, so we'll simply return nil. |
| 4692 |
*/ |
| 4693 |
isComponentOf(obj) { return nil; } |
| 4694 |
|
| 4695 |
/* |
| 4696 |
* General initialization - this will be called during preinit so |
| 4697 |
* that we can set up the initial values of any derived internal |
| 4698 |
* properties. |
| 4699 |
*/ |
| 4700 |
initializeThing() |
| 4701 |
{ |
| 4702 |
/* initialize our location settings */ |
| 4703 |
initializeLocation(); |
| 4704 |
|
| 4705 |
/* |
| 4706 |
* if we're marked 'equivalent', it means we're interchangeable |
| 4707 |
* in parser input with other objects with the same name; set up |
| 4708 |
* our equivalence group listing if so |
| 4709 |
*/ |
| 4710 |
if (isEquivalent) |
| 4711 |
initializeEquivalent(); |
| 4712 |
|
| 4713 |
/* if we have a global parameter name, add it to the global table */ |
| 4714 |
if (globalParamName != nil) |
| 4715 |
langMessageBuilder.nameTable_[globalParamName] = self; |
| 4716 |
} |
| 4717 |
|
| 4718 |
/* |
| 4719 |
* Initialize my location's contents list - add myself to my |
| 4720 |
* container during initialization |
| 4721 |
*/ |
| 4722 |
initializeLocation() |
| 4723 |
{ |
| 4724 |
if (location != nil) |
| 4725 |
location.addToContents(self); |
| 4726 |
} |
| 4727 |
|
| 4728 |
/* |
| 4729 |
* Initialize this class object for listing its instances that are |
| 4730 |
* marked with isEquivalent. We'll initialize a list group that |
| 4731 |
* lists our equivalent instances as a group. |
| 4732 |
* |
| 4733 |
* Objects are grouped by their equivalence key - each set of objects |
| 4734 |
* with the same key is part of the same group. The key is |
| 4735 |
* determined by the language module, but is usually just the basic |
| 4736 |
* disambiguation name (the 'disambigName' property in English, for |
| 4737 |
* example). |
| 4738 |
*/ |
| 4739 |
initializeEquivalent() |
| 4740 |
{ |
| 4741 |
/* |
| 4742 |
* If we're already in an equivalence group (because our key has |
| 4743 |
* changed, for example, or due to inheritance), remove the |
| 4744 |
* existing group from the group list. If the group isn't |
| 4745 |
* changing after all, we'll just add it back, so removing it |
| 4746 |
* should be harmless. |
| 4747 |
*/ |
| 4748 |
if (equivalentGrouper != nil) |
| 4749 |
listWith -= equivalentGrouper; |
| 4750 |
|
| 4751 |
/* look up our equivalence key in the global table of groupers */ |
| 4752 |
equivalentGrouper = equivalentGrouperTable[equivalenceKey]; |
| 4753 |
|
| 4754 |
/* if there's no grouper for our key, create one */ |
| 4755 |
if (equivalentGrouper == nil) |
| 4756 |
{ |
| 4757 |
/* create a new grouper */ |
| 4758 |
equivalentGrouper = equivalentGrouperClass.createInstance(); |
| 4759 |
|
| 4760 |
/* add it to the table */ |
| 4761 |
equivalentGrouperTable[equivalenceKey] = equivalentGrouper; |
| 4762 |
} |
| 4763 |
|
| 4764 |
/* |
| 4765 |
* Add it to our list, as long as our listWith isn't already |
| 4766 |
* defined as a method. Note that we intentionally add it as the |
| 4767 |
* last element, because an equivalent group is the most specific |
| 4768 |
* kind of group possible. |
| 4769 |
*/ |
| 4770 |
if (propType(&listWith) != TypeCode) |
| 4771 |
listWith += equivalentGrouper; |
| 4772 |
} |
| 4773 |
|
| 4774 |
/* |
| 4775 |
* A static game-wide table of equivalence groups. This has a table |
| 4776 |
* of ListGroupEquivalent-derived objects, keyed by equivalence name. |
| 4777 |
* Each group of objects with the same equivalence name is listed in |
| 4778 |
* the same group and so has the same grouper object. |
| 4779 |
*/ |
| 4780 |
equivalentGrouperTable = static (new LookupTable(32, 64)) |
| 4781 |
|
| 4782 |
/* |
| 4783 |
* my equivalence grouper class - when we initialize, we'll create a |
| 4784 |
* grouper of this class and store it in equivalentGrouper |
| 4785 |
*/ |
| 4786 |
equivalentGrouperClass = ListGroupEquivalent |
| 4787 |
|
| 4788 |
/* |
| 4789 |
* Our equivalent item grouper. During initialization, we will |
| 4790 |
* create an equivalent grouper and store it in this property for |
| 4791 |
* each class object that has instances marked with isEquivalent. |
| 4792 |
* Note that this is stored with the class, because we want each of |
| 4793 |
* our equivalent instances to share the same grouper object so that |
| 4794 |
* they are listed together as a group. |
| 4795 |
*/ |
| 4796 |
equivalentGrouper = nil |
| 4797 |
|
| 4798 |
/* |
| 4799 |
* My contents. This is a list of the objects that this object |
| 4800 |
* directly contains. |
| 4801 |
*/ |
| 4802 |
contents = [] |
| 4803 |
|
| 4804 |
/* |
| 4805 |
* Get my associated noise object. By default, this looks for an |
| 4806 |
* item of class Noise directly within me. |
| 4807 |
*/ |
| 4808 |
getNoise() |
| 4809 |
{ |
| 4810 |
/* |
| 4811 |
* Look for a Noise object among my direct contents. Only look |
| 4812 |
* for a noise with an active sound presence. |
| 4813 |
*/ |
| 4814 |
return contents.valWhich( |
| 4815 |
{obj: obj.ofKind(Noise) && obj.soundPresence}); |
| 4816 |
} |
| 4817 |
|
| 4818 |
/* |
| 4819 |
* Get my associated odor object. By default, this looks for an |
| 4820 |
* item of class Odor directly within me. |
| 4821 |
*/ |
| 4822 |
getOdor() |
| 4823 |
{ |
| 4824 |
/* |
| 4825 |
* Look for an Odor object among my direct contents. Only look |
| 4826 |
* for an odor with an active smell presence. |
| 4827 |
*/ |
| 4828 |
return contents.valWhich( |
| 4829 |
{obj: obj.ofKind(Odor) && obj.smellPresence}); |
| 4830 |
} |
| 4831 |
|
| 4832 |
/* |
| 4833 |
* Get a vector of all of my contents, recursively including |
| 4834 |
* contents of contents. |
| 4835 |
*/ |
| 4836 |
allContents() |
| 4837 |
{ |
| 4838 |
local vec; |
| 4839 |
|
| 4840 |
/* start with an empty vector */ |
| 4841 |
vec = new Vector(32); |
| 4842 |
|
| 4843 |
/* add all of my contents to the vector */ |
| 4844 |
addAllContents(vec); |
| 4845 |
|
| 4846 |
/* return the result */ |
| 4847 |
return vec; |
| 4848 |
} |
| 4849 |
|
| 4850 |
/* |
| 4851 |
* Get a list of objects suitable for matching ALL in TAKE ALL FROM |
| 4852 |
* <self>. By default, this simply returns the list of everything in |
| 4853 |
* scope that's directly inside 'self'. |
| 4854 |
*/ |
| 4855 |
getAllForTakeFrom(scopeList) |
| 4856 |
{ |
| 4857 |
/* |
| 4858 |
* include only objects contained within 'self' that aren't |
| 4859 |
* components of 'self' |
| 4860 |
*/ |
| 4861 |
return scopeList.subset( |
| 4862 |
{x: x != self && x.isDirectlyIn(self) && !x.isComponentOf(self)}); |
| 4863 |
} |
| 4864 |
|
| 4865 |
/* |
| 4866 |
* add myself and all of my contents, recursively including contents |
| 4867 |
* of contents, to a vector |
| 4868 |
*/ |
| 4869 |
addAllContents(vec) |
| 4870 |
{ |
| 4871 |
/* visit everything in my contents */ |
| 4872 |
foreach (local cur in contents) |
| 4873 |
{ |
| 4874 |
/* |
| 4875 |
* if this item is already in the vector, skip it - we've |
| 4876 |
* already visited it and its contents |
| 4877 |
*/ |
| 4878 |
if (vec.indexOf(cur) != nil) |
| 4879 |
continue; |
| 4880 |
|
| 4881 |
/* add this item */ |
| 4882 |
vec.append(cur); |
| 4883 |
|
| 4884 |
/* add this item's contents recursively */ |
| 4885 |
cur.addAllContents(vec); |
| 4886 |
} |
| 4887 |
} |
| 4888 |
|
| 4889 |
/* |
| 4890 |
* Show the contents of this object, as part of a recursive listing |
| 4891 |
* generated as part of the description of our container, our |
| 4892 |
* container's container, or any further enclosing container. |
| 4893 |
* |
| 4894 |
* If the object has any contents, we'll display a listing of the |
| 4895 |
* contents. This is used to display the object's contents as part |
| 4896 |
* of the description of a room ("look around"), of an object |
| 4897 |
* ("examine box"), or of an object's contents ("look in box"). |
| 4898 |
* |
| 4899 |
* 'options' is the set of flags that we'll pass to showList(), and |
| 4900 |
* has the same meaning as for that function. |
| 4901 |
* |
| 4902 |
* 'infoTab' is a lookup table of SenseInfo objects for the objects |
| 4903 |
* that the actor to whom we're showing the contents listing can see |
| 4904 |
* via the sight-like senses. |
| 4905 |
* |
| 4906 |
* This method should be overridden by any object that doesn't store |
| 4907 |
* its contents using a simple 'contents' list property. |
| 4908 |
*/ |
| 4909 |
showObjectContents(pov, lister, options, indent, infoTab) |
| 4910 |
{ |
| 4911 |
/* get my listable contents */ |
| 4912 |
local cont = lister.getListedContents(self, infoTab); |
| 4913 |
|
| 4914 |
/* if the surviving list isn't empty, show it */ |
| 4915 |
if (cont != []) |
| 4916 |
lister.showList(pov, self, cont, options, indent, infoTab, nil); |
| 4917 |
} |
| 4918 |
|
| 4919 |
/* |
| 4920 |
* Show the contents of this object as part of an inventory listing. |
| 4921 |
* By default, we simply use the same listing we do for the normal |
| 4922 |
* contents listing. |
| 4923 |
*/ |
| 4924 |
showInventoryContents(pov, lister, options, indent, infoTab) |
| 4925 |
{ |
| 4926 |
/* by default, use the normal room/object contents listing */ |
| 4927 |
showObjectContents(pov, lister, options, indent, infoTab); |
| 4928 |
} |
| 4929 |
|
| 4930 |
/* |
| 4931 |
* Get my listed contents for recursive object descriptions. This |
| 4932 |
* returns the list of the direct contents that we'll mention when |
| 4933 |
* we're examining our container's container, a further enclosing |
| 4934 |
* container, or the enclosing room. |
| 4935 |
* |
| 4936 |
* By default, we'll return the same list we'll display on direct |
| 4937 |
* examination of this object. |
| 4938 |
*/ |
| 4939 |
getListedContents(lister, infoTab) |
| 4940 |
{ |
| 4941 |
/* |
| 4942 |
* return the contents we'd list when directly examining self, |
| 4943 |
* limited to the listable contents |
| 4944 |
*/ |
| 4945 |
return getContentsForExamine(lister, infoTab) |
| 4946 |
.subset({x: lister.isListed(x)}); |
| 4947 |
} |
| 4948 |
|
| 4949 |
/* |
| 4950 |
* Get the listed contents in a direct examination of this object. |
| 4951 |
* By default, this simply returns a list of all of our direct |
| 4952 |
* contents that are included in the info table. |
| 4953 |
*/ |
| 4954 |
getContentsForExamine(lister, infoTab) |
| 4955 |
{ |
| 4956 |
/* |
| 4957 |
* return only my direct contents that are found in the infoTab, |
| 4958 |
* since these are the objects that can be sensed from the |
| 4959 |
* actor's point of view |
| 4960 |
*/ |
| 4961 |
return contents.subset({x: infoTab[x] != nil}); |
| 4962 |
} |
| 4963 |
|
| 4964 |
/* |
| 4965 |
* Is this a "top-level" location? A top-level location is an |
| 4966 |
* object which doesn't have another container, so its 'location' |
| 4967 |
* property is nil, but which is part of the game universe anyway. |
| 4968 |
* In most cases, a top-level location is simply a Room, since the |
| 4969 |
* network of rooms makes up the game's map. |
| 4970 |
* |
| 4971 |
* If an object has no location and is not itself a top-level |
| 4972 |
* location, then the object is not part of the game world. It's |
| 4973 |
* sometimes useful to remove objects from the game world, such as |
| 4974 |
* when they're destroyed within the context of the game. |
| 4975 |
*/ |
| 4976 |
isTopLevel = nil |
| 4977 |
|
| 4978 |
/* |
| 4979 |
* Determine if I'm is inside another Thing. Returns true if this |
| 4980 |
* object is contained within 'obj', directly or indirectly (that |
| 4981 |
* is, this returns true if my immediate container is 'obj', OR my |
| 4982 |
* immediate container is in 'obj', recursively defined). |
| 4983 |
* |
| 4984 |
* isIn(nil) returns true if this object is "outside" the game |
| 4985 |
* world, which means that the object is not reachable from anywhere |
| 4986 |
* in the game map and is thus not part of the simulation. This is |
| 4987 |
* the case if our outermost container is NOT a top-level object, as |
| 4988 |
* indicated by its isTopLevel property. If we're inside an object |
| 4989 |
* marked as a top-level object, or we're inside an object that's |
| 4990 |
* inside a top-level object (and so on), then we're part of the |
| 4991 |
* game world, so isIn(nil) will return nil. If our outermost |
| 4992 |
* container is has a nil isTopLevel property, isIn(nil) will return |
| 4993 |
* true. |
| 4994 |
* |
| 4995 |
* Note that our notion of "in" is not limited to enclosing |
| 4996 |
* containment, because the same containment hierarchy is used to |
| 4997 |
* represent all types of containment relationships, including |
| 4998 |
* things being "on" other things and part of other things. |
| 4999 |
*/ |
| 5000 |
isIn(obj) |
| 5001 |
{ |
| 5002 |
local loc = location; |
| 5003 |
|
| 5004 |
/* if we have no location, we're not inside any object */ |
| 5005 |
if (loc == nil) |
| 5006 |
{ |
| 5007 |
/* |
| 5008 |
* We have no container, so there are two possibilities: |
| 5009 |
* either we're not part of the game world at all, or we're |
| 5010 |
* a top-level object, which is an object that's explicitly |
| 5011 |
* part of the game world and at the top of the containment |
| 5012 |
* tree. Our 'isTopLevel' property determines which it is. |
| 5013 |
* |
| 5014 |
* If they're asking us if we're inside 'nil', then what |
| 5015 |
* they want to know is if we're outside the game world. If |
| 5016 |
* we're not a top-level object, we are outside the game |
| 5017 |
* world, so isIn(nil) is true; if we are a top-level |
| 5018 |
* object, then we're explicitly part of the game world, so |
| 5019 |
* isIn(nil) is false. |
| 5020 |
* |
| 5021 |
* If they're asking us if we're inside any non-nil object, |
| 5022 |
* then they simply want to know if we're inside that |
| 5023 |
* object. So, if 'obj' is not nil, we must return nil: |
| 5024 |
* we're not in any object, so we can't be in 'obj'. |
| 5025 |
*/ |
| 5026 |
if (obj == nil) |
| 5027 |
{ |
| 5028 |
/* |
| 5029 |
* they want to know if we're outside the simulation |
| 5030 |
* entirely: return true if we're NOT a top-level |
| 5031 |
* object, nil otherwise |
| 5032 |
*/ |
| 5033 |
return !isTopLevel; |
| 5034 |
} |
| 5035 |
else |
| 5036 |
{ |
| 5037 |
/* |
| 5038 |
* they want to know if we're inside some specific |
| 5039 |
* object; we can't be, because we're not in any object |
| 5040 |
*/ |
| 5041 |
return nil; |
| 5042 |
} |
| 5043 |
} |
| 5044 |
|
| 5045 |
/* if obj is my immediate container, I'm obviously in it */ |
| 5046 |
if (loc == obj) |
| 5047 |
return true; |
| 5048 |
|
| 5049 |
/* I'm in obj if my container is in obj */ |
| 5050 |
return loc.isIn(obj); |
| 5051 |
} |
| 5052 |
|
| 5053 |
/* |
| 5054 |
* Determine if I'm directly inside another Thing. Returns true if |
| 5055 |
* this object is contained directly within obj. Returns nil if |
| 5056 |
* this object isn't directly within obj, even if it is indirectly |
| 5057 |
* in obj (i.e., its container is directly or indirectly in obj). |
| 5058 |
*/ |
| 5059 |
isDirectlyIn(obj) |
| 5060 |
{ |
| 5061 |
/* I'm directly in obj only if it's my immediate container */ |
| 5062 |
return location == obj; |
| 5063 |
} |
| 5064 |
|
| 5065 |
/* |
| 5066 |
* Determine if I'm "nominally" inside the given Thing. Returns true |
| 5067 |
* if the object is actually within the given object, OR the object |
| 5068 |
* is a room part and I'm nominally in the room part. |
| 5069 |
*/ |
| 5070 |
isNominallyIn(obj) |
| 5071 |
{ |
| 5072 |
/* if I'm actually in the given object, I'm nominally in it as well */ |
| 5073 |
if (isIn(obj)) |
| 5074 |
return true; |
| 5075 |
|
| 5076 |
/* |
| 5077 |
* if the object is a room part, and we're nominally in the room |
| 5078 |
* part, then we're nominally in the object |
| 5079 |
*/ |
| 5080 |
if (obj.ofKind(RoomPart) && isNominallyInRoomPart(obj)) |
| 5081 |
return true; |
| 5082 |
|
| 5083 |
/* we're not nominally in the object */ |
| 5084 |
return nil; |
| 5085 |
} |
| 5086 |
|
| 5087 |
/* |
| 5088 |
* Determine if this object is contained within an item fixed in |
| 5089 |
* place within the given location. We'll check our container to |
| 5090 |
* see if its contents are within an object fixed in place in the |
| 5091 |
* given location. |
| 5092 |
* |
| 5093 |
* This is a rather specific check that might seem a bit odd, but |
| 5094 |
* for some purposes it's useful to treat objects within fixed |
| 5095 |
* containers in a location as though they were in the location |
| 5096 |
* itself, because fixtures of a location are to some extent parts |
| 5097 |
* of the location. |
| 5098 |
*/ |
| 5099 |
isInFixedIn(loc) |
| 5100 |
{ |
| 5101 |
/* return true if my location's contents are in fixed things */ |
| 5102 |
return location != nil && location.contentsInFixedIn(loc); |
| 5103 |
} |
| 5104 |
|
| 5105 |
/* Am I either inside 'obj', or equal to 'obj'? */ |
| 5106 |
isOrIsIn(obj) { return self == obj || isIn(obj); } |
| 5107 |
|
| 5108 |
/* |
| 5109 |
* Are my contents within a fixed item that is within the given |
| 5110 |
* location? By default, we return nil because we are not ourselves |
| 5111 |
* fixed. |
| 5112 |
*/ |
| 5113 |
contentsInFixedIn(loc) { return nil; } |
| 5114 |
|
| 5115 |
/* |
| 5116 |
* Determine if I'm "held" by an actor, for the purposes of being |
| 5117 |
* manipulated in an action. In most cases, an object is considered |
| 5118 |
* held by an actor if it's directly within the actor's inventory, |
| 5119 |
* because the actor's direct inventory represents the contents of |
| 5120 |
* the actors hands (or equivalent). |
| 5121 |
* |
| 5122 |
* Some classes might override this to change the definition of |
| 5123 |
* "held" to include things not directly in the actor's inventory or |
| 5124 |
* exclude things directly in the inventory. For example, an item |
| 5125 |
* being worn is generally not considered held even though it might |
| 5126 |
* be in the direct inventory, and a key on a keyring is considered |
| 5127 |
* held if the keyring is being held. |
| 5128 |
*/ |
| 5129 |
isHeldBy(actor) |
| 5130 |
{ |
| 5131 |
/* |
| 5132 |
* by default, an object is held if and only if it's in the |
| 5133 |
* direct inventory of the actor |
| 5134 |
*/ |
| 5135 |
return isDirectlyIn(actor); |
| 5136 |
} |
| 5137 |
|
| 5138 |
/* |
| 5139 |
* Are we being held by the given actor for the purposes of the |
| 5140 |
* objHeld precondition? By default, and in almost all cases, this |
| 5141 |
* simply returns isHeldBy(). In some rare cases, it might make |
| 5142 |
* sense to consider an object to meet the objHeld condition even if |
| 5143 |
* isHeldBy returns nil; for example, an actor's hands and other |
| 5144 |
* body parts can't be considered to be held, but they also don't |
| 5145 |
* need to be for any command operating on them. |
| 5146 |
*/ |
| 5147 |
meetsObjHeld(actor) { return isHeldBy(actor); } |
| 5148 |
|
| 5149 |
/* |
| 5150 |
* Add to a vector all of my contents that are directly held when |
| 5151 |
* I'm being directly held. This is used to add the direct contents |
| 5152 |
* of an item to scope when the item itself is being directly held. |
| 5153 |
* |
| 5154 |
* In most cases, we do nothing. Certain types of objects override |
| 5155 |
* this because they consider their contents to be held if they're |
| 5156 |
* held. For example, a keyring considers all of its keys to be |
| 5157 |
* held if the keyring itself is held, because the keys are attached |
| 5158 |
* to the keyring rather than contained within it. |
| 5159 |
*/ |
| 5160 |
appendHeldContents(vec) |
| 5161 |
{ |
| 5162 |
/* by default, do nothing */ |
| 5163 |
} |
| 5164 |
|
| 5165 |
/* |
| 5166 |
* Determine if I'm "owned" by another object. By default, if we |
| 5167 |
* have an explicit owner, then we are owned by 'obj' if and only if |
| 5168 |
* 'obj' is our explicit owner; otherwise, if 'obj' is our immediate |
| 5169 |
* location, and our immediate location can own us (as reported by |
| 5170 |
* obj.canOwn(self)), then 'obj' owns us; otherwise, 'obj' owns us |
| 5171 |
* if our immediate location CANNOT own us AND our immediate |
| 5172 |
* location is owned by 'obj'. This last case is tricky: it means |
| 5173 |
* that if we're inside something other than 'obj' that can own us, |
| 5174 |
* such as another actor, then 'obj' doesn't own us because our |
| 5175 |
* immediate location does; it also means that if we're inside an |
| 5176 |
* object that has an explicit owner rather than an owner based on |
| 5177 |
* location, we have the same explicit owner, so a dollar bill |
| 5178 |
* inside Bob's wallet which is in turn being carried by Charlie is |
| 5179 |
* owned by Bob, not Charlie. |
| 5180 |
* |
| 5181 |
* This is used to determine ownership for the purpose of |
| 5182 |
* possessives in commands. Ownership is not always exclusive: it |
| 5183 |
* is possible for a given object to have multiple owners in some |
| 5184 |
* cases. For example, if Bob and Bill are both sitting on a couch, |
| 5185 |
* the couch could be referred to as "bob's couch" or "bill's |
| 5186 |
* couch", so the couch is owned by both Bob and Bill. It is also |
| 5187 |
* possible for an object to be unowned. |
| 5188 |
* |
| 5189 |
* In most cases, ownership is a function of location (possession is |
| 5190 |
* nine-tenths of the law, as they say), but not always; in some |
| 5191 |
* cases, an object has a particular owner regardless of its |
| 5192 |
* location, such as "bob's wallet". This default implementation |
| 5193 |
* allows for ownership by location, as well as explicit ownership, |
| 5194 |
* with explicit ownership (as indicated by the self.owner property) |
| 5195 |
* taking precedence. |
| 5196 |
*/ |
| 5197 |
isOwnedBy(obj) |
| 5198 |
{ |
| 5199 |
local cont; |
| 5200 |
|
| 5201 |
/* |
| 5202 |
* if I have an explicit owner, then obj is my owner if it |
| 5203 |
* matches my explicit owner |
| 5204 |
*/ |
| 5205 |
if (owner != nil) |
| 5206 |
return owner == obj; |
| 5207 |
|
| 5208 |
/* |
| 5209 |
* Check my immediate container to see if it's the owner in |
| 5210 |
* question. |
| 5211 |
*/ |
| 5212 |
if (isDirectlyIn(obj)) |
| 5213 |
{ |
| 5214 |
/* |
| 5215 |
* My immediate container is the owner of interest. If this |
| 5216 |
* container can own me, then I'm owned by it because we |
| 5217 |
* didn't find any other owners first. Otherwise, I'm not |
| 5218 |
* owned by it because it can't own me in the first place. |
| 5219 |
*/ |
| 5220 |
return obj.canOwn(self); |
| 5221 |
} |
| 5222 |
|
| 5223 |
/* presume we have a single-location container */ |
| 5224 |
cont = location; |
| 5225 |
|
| 5226 |
/* check to see if we have no single location */ |
| 5227 |
if (cont == nil) |
| 5228 |
{ |
| 5229 |
/* |
| 5230 |
* I have no location, so either I'm not inside anything at |
| 5231 |
* all, or I have multiple locations. If we're indirectly |
| 5232 |
* in 'obj', then proceed up the containment tree branch by |
| 5233 |
* which 'obj' contains us. If we're not even indirectly in |
| 5234 |
* 'obj', then there's no containment relationship that |
| 5235 |
* establishes ownership. |
| 5236 |
*/ |
| 5237 |
if (isIn(obj)) |
| 5238 |
{ |
| 5239 |
/* |
| 5240 |
* we're indirectly in 'obj', so get the containment |
| 5241 |
* branch on which we're contained by 'obj' |
| 5242 |
*/ |
| 5243 |
forEachContainer(function(x) |
| 5244 |
{ |
| 5245 |
if (x == obj || x.isIn(obj)) |
| 5246 |
cont = x; |
| 5247 |
}); |
| 5248 |
} |
| 5249 |
else |
| 5250 |
{ |
| 5251 |
/* |
| 5252 |
* we're not in 'obj', so there's no containment |
| 5253 |
* relationship that establishes ownership |
| 5254 |
*/ |
| 5255 |
return nil; |
| 5256 |
} |
| 5257 |
} |
| 5258 |
|
| 5259 |
/* |
| 5260 |
* My immediate container is not the object of interest. If |
| 5261 |
* this container can own me, then I'm owned by this container |
| 5262 |
* and NOT by obj. |
| 5263 |
*/ |
| 5264 |
if (cont.canOwn(self)) |
| 5265 |
return nil; |
| 5266 |
|
| 5267 |
/* |
| 5268 |
* My container can't own me, so it's not my owner, so our owner |
| 5269 |
* is my container's owner - thus, I'm owned by obj if my |
| 5270 |
* location is owned by obj. |
| 5271 |
*/ |
| 5272 |
return cont.isOwnedBy(obj); |
| 5273 |
} |
| 5274 |
|
| 5275 |
/* |
| 5276 |
* My explicit owner. By default, objects do not have explicit |
| 5277 |
* owners, which means that the owner at any given time is |
| 5278 |
* determined by the object's location - my innermost container that |
| 5279 |
* can own me is my owner. |
| 5280 |
* |
| 5281 |
* However, in some cases, an object is inherently owned by a |
| 5282 |
* particular other object (usually an actor), and this is invariant |
| 5283 |
* even when the object moves to a new location not within the |
| 5284 |
* owner. For such cases, this property can be set to the explicit |
| 5285 |
* owner object, which will cause self.isOwnedBy(obj) to return true |
| 5286 |
* if and only if obj == self.owner. |
| 5287 |
*/ |
| 5288 |
owner = nil |
| 5289 |
|
| 5290 |
/* |
| 5291 |
* Get the "nominal owner" of this object. This is the owner that |
| 5292 |
* we report for the object if asked to distinguish this object from |
| 5293 |
* another via the OwnershipDistinguisher. Note that the nominal |
| 5294 |
* owner is not necessarily the only owner, because an object can |
| 5295 |
* have multiple owners in some cases; however, the nominal owner |
| 5296 |
* must always be an owner, in that isOwnedBy(getNominalOwner()) |
| 5297 |
* should always return true. |
| 5298 |
* |
| 5299 |
* By default, if we have an explicit owner, we'll return that. |
| 5300 |
* Otherwise, if our immediate container can own us, we'll return |
| 5301 |
* our immediate container. Otherwise, we'll return our immediate |
| 5302 |
* container's nominal owner. Note that this last case means that a |
| 5303 |
* dollar bill inside Bob's wallet will be Bob's dollar bill, even |
| 5304 |
* if Bob's wallet is currently being carried by another actor. |
| 5305 |
*/ |
| 5306 |
getNominalOwner() |
| 5307 |
{ |
| 5308 |
/* if we have an explicit owner, return that */ |
| 5309 |
if (owner != nil) |
| 5310 |
return owner; |
| 5311 |
|
| 5312 |
/* if we have no location, we have no owner */ |
| 5313 |
if (location == nil) |
| 5314 |
return nil; |
| 5315 |
|
| 5316 |
/* if our immediate location can own us, return it */ |
| 5317 |
if (location.canOwn(self)) |
| 5318 |
return location; |
| 5319 |
|
| 5320 |
/* return our immediate location's owner */ |
| 5321 |
return location.getNominalOwner(); |
| 5322 |
} |
| 5323 |
|
| 5324 |
/* |
| 5325 |
* Can I own the given object? By default, objects cannot own other |
| 5326 |
* objects. This can be overridden when ownership is desired. |
| 5327 |
* |
| 5328 |
* This doesn't determine that we *do* own the given object, but |
| 5329 |
* only that we *can* own the given object. |
| 5330 |
*/ |
| 5331 |
canOwn(obj) { return nil; } |
| 5332 |
|
| 5333 |
/* |
| 5334 |
* Get the carrying actor. This is the nearest enclosing location |
| 5335 |
* that's an actor. |
| 5336 |
*/ |
| 5337 |
getCarryingActor() |
| 5338 |
{ |
| 5339 |
/* if I don't have a location, there's no carrier */ |
| 5340 |
if (location == nil) |
| 5341 |
return nil; |
| 5342 |
|
| 5343 |
/* if my location is an actor, it's the carrying actor */ |
| 5344 |
if (location.isActor) |
| 5345 |
return location; |
| 5346 |
|
| 5347 |
/* return my location's carrying actor */ |
| 5348 |
return location.getCarryingActor(); |
| 5349 |
} |
| 5350 |
|
| 5351 |
/* |
| 5352 |
* Try making the current command's actor hold me. By default, |
| 5353 |
* we'll simply try a "take" command on the object. |
| 5354 |
*/ |
| 5355 |
tryHolding() |
| 5356 |
{ |
| 5357 |
/* |
| 5358 |
* Try an implicit 'take' command. If the actor is carrying the |
| 5359 |
* object indirectly, make the command "take from" instead, |
| 5360 |
* since what we really want to do is take the object out of its |
| 5361 |
* container. |
| 5362 |
*/ |
| 5363 |
if (isIn(gActor)) |
| 5364 |
return tryImplicitAction(TakeFrom, self, location); |
| 5365 |
else |
| 5366 |
return tryImplicitAction(Take, self); |
| 5367 |
} |
| 5368 |
|
| 5369 |
/* |
| 5370 |
* Try moving the given object into this object, with an implied |
| 5371 |
* command. By default, since an ordinary Thing doesn't have a way |
| 5372 |
* of adding new contents by a player command, this does nothing. |
| 5373 |
* Containers and other objects that can hold new contents can |
| 5374 |
* override this as appropriate. |
| 5375 |
*/ |
| 5376 |
tryMovingObjInto(obj) { return nil; } |
| 5377 |
|
| 5378 |
/* |
| 5379 |
* Report a failure of the condition that tryMovingObjInto tries to |
| 5380 |
* bring into effect. By default, this simply says that the object |
| 5381 |
* must be in 'self'. Some objects might want to override this when |
| 5382 |
* they describe containment specially; for example, an actor might |
| 5383 |
* want to say that the actor "must be carrying" the object. |
| 5384 |
*/ |
| 5385 |
mustMoveObjInto(obj) { reportFailure(&mustBeInMsg, obj, self); } |
| 5386 |
|
| 5387 |
/* |
| 5388 |
* Add an object to my contents. |
| 5389 |
* |
| 5390 |
* Note that this should NOT be overridden to cause side effects - |
| 5391 |
* if side effects are desired when inserting a new object into my |
| 5392 |
* contents, use notifyInsert(). This routine is not allowed to |
| 5393 |
* cause side effects because it is sometimes necessary to bypass |
| 5394 |
* side effects when moving an item. |
| 5395 |
*/ |
| 5396 |
addToContents(obj) |
| 5397 |
{ |
| 5398 |
/* add the object to my contents list */ |
| 5399 |
if (contents.indexOf(obj) == nil) |
| 5400 |
contents += obj; |
| 5401 |
} |
| 5402 |
|
| 5403 |
/* |
| 5404 |
* Remove an object from my contents. |
| 5405 |
* |
| 5406 |
* Do NOT override this routine to cause side effects. If side |
| 5407 |
* effects are desired when removing an object, use notifyRemove(). |
| 5408 |
*/ |
| 5409 |
removeFromContents(obj) |
| 5410 |
{ |
| 5411 |
/* remove the object from my contents list */ |
| 5412 |
contents -= obj; |
| 5413 |
} |
| 5414 |
|
| 5415 |
/* |
| 5416 |
* Save my location for later restoration. Returns a value suitable |
| 5417 |
* for passing to restoreLocation. |
| 5418 |
*/ |
| 5419 |
saveLocation() |
| 5420 |
{ |
| 5421 |
/* |
| 5422 |
* I'm an ordinary object with only one location, so simply |
| 5423 |
* return the location |
| 5424 |
*/ |
| 5425 |
return location; |
| 5426 |
} |
| 5427 |
|
| 5428 |
/* |
| 5429 |
* Restore a previously saved location. Does not trigger any side |
| 5430 |
* effects. |
| 5431 |
*/ |
| 5432 |
restoreLocation(oldLoc) |
| 5433 |
{ |
| 5434 |
/* move myself without side effects into my old container */ |
| 5435 |
baseMoveInto(oldLoc); |
| 5436 |
} |
| 5437 |
|
| 5438 |
/* |
| 5439 |
* Move this object to a new container. Before the move is actually |
| 5440 |
* performed, we notify the items in the movement path of the |
| 5441 |
* change, then we send notifyRemove and notifyInsert messages to |
| 5442 |
* the old and new containment trees, respectively. |
| 5443 |
* |
| 5444 |
* All notifications are sent before the object is actually moved. |
| 5445 |
* This means that the current game state at the time of the |
| 5446 |
* notifications reflects the state before the move. |
| 5447 |
*/ |
| 5448 |
moveInto(newContainer) |
| 5449 |
{ |
| 5450 |
/* notify the path */ |
| 5451 |
moveIntoNotifyPath(newContainer); |
| 5452 |
|
| 5453 |
/* perform the main moveInto operations */ |
| 5454 |
mainMoveInto(newContainer); |
| 5455 |
} |
| 5456 |
|
| 5457 |
/* |
| 5458 |
* Move this object to a new container as part of travel. This is |
| 5459 |
* almost the same as the regular moveInto(), but does not attempt |
| 5460 |
* to calculate and notify the sense path to the new location. We |
| 5461 |
* omit the path notification because travel is done via travel |
| 5462 |
* connections, which are not necessarily the same as sense |
| 5463 |
* connections. |
| 5464 |
*/ |
| 5465 |
moveIntoForTravel(newContainer) |
| 5466 |
{ |
| 5467 |
/* |
| 5468 |
* perform the main moveInto operations, omitting the path |
| 5469 |
* notification |
| 5470 |
*/ |
| 5471 |
mainMoveInto(newContainer); |
| 5472 |
} |
| 5473 |
|
| 5474 |
/* |
| 5475 |
* Main moveInto - this is the mid-level containment changer; this |
| 5476 |
* routine sends notifications to the old and new container, but |
| 5477 |
* doesn't notify anything along the connecting sense path. |
| 5478 |
*/ |
| 5479 |
mainMoveInto(newContainer) |
| 5480 |
{ |
| 5481 |
/* notify my container that I'm being removed */ |
| 5482 |
sendNotifyRemove(self, newContainer, ¬ifyRemove); |
| 5483 |
|
| 5484 |
/* notify my new container that I'm about to be added */ |
| 5485 |
if (newContainer != nil) |
| 5486 |
newContainer.sendNotifyInsert(self, newContainer, ¬ifyInsert); |
| 5487 |
|
| 5488 |
/* notify myself that I'm about to be moved */ |
| 5489 |
notifyMoveInto(newContainer); |
| 5490 |
|
| 5491 |
/* perform the basic containment change */ |
| 5492 |
baseMoveInto(newContainer); |
| 5493 |
|
| 5494 |
/* note that I've been moved */ |
| 5495 |
moved = true; |
| 5496 |
} |
| 5497 |
|
| 5498 |
/* |
| 5499 |
* Base moveInto - this is the low-level containment changer; this |
| 5500 |
* routine does not send any notifications to any containers, and |
| 5501 |
* does not mark the object as moved. This form should be used only |
| 5502 |
* for internal library-initiated state changes, since it bypasses |
| 5503 |
* all of the normal side effects of moving an object to a new |
| 5504 |
* container. |
| 5505 |
*/ |
| 5506 |
baseMoveInto(newContainer) |
| 5507 |
{ |
| 5508 |
/* if I have a container, remove myself from its contents list */ |
| 5509 |
if (location != nil) |
| 5510 |
location.removeFromContents(self); |
| 5511 |
|
| 5512 |
/* remember my new location */ |
| 5513 |
location = newContainer; |
| 5514 |
|
| 5515 |
/* |
| 5516 |
* if I'm not being moved into nil, add myself to the |
| 5517 |
* container's contents |
| 5518 |
*/ |
| 5519 |
if (location != nil) |
| 5520 |
location.addToContents(self); |
| 5521 |
} |
| 5522 |
|
| 5523 |
/* |
| 5524 |
* Notify each element of the move path of a moveInto operation. |
| 5525 |
*/ |
| 5526 |
moveIntoNotifyPath(newContainer) |
| 5527 |
{ |
| 5528 |
local path; |
| 5529 |
|
| 5530 |
/* calculate the path; if there isn't one, there's nothing to do */ |
| 5531 |
if ((path = getMovePathTo(newContainer)) == nil) |
| 5532 |
return; |
| 5533 |
|
| 5534 |
/* |
| 5535 |
* We must fix up the path's final element, depending on whether |
| 5536 |
* we're moving into the new container from the outside or from |
| 5537 |
* the inside. |
| 5538 |
*/ |
| 5539 |
if (isIn(newContainer)) |
| 5540 |
{ |
| 5541 |
/* |
| 5542 |
* We're already in the new container, so we're moving into |
| 5543 |
* the new container from the inside. The final element of |
| 5544 |
* the path is the new container, but since we're stopping |
| 5545 |
* within the new container, we don't need to traverse out |
| 5546 |
* of it. Simply remove the final two elements of the path, |
| 5547 |
* since we're not going to make this traversal when moving |
| 5548 |
* the object. |
| 5549 |
*/ |
| 5550 |
path = path.sublist(1, path.length() - 2); |
| 5551 |
} |
| 5552 |
else |
| 5553 |
{ |
| 5554 |
/* |
| 5555 |
* We're moving into the new container from the outside. |
| 5556 |
* Since we calculated the path to the container, we must |
| 5557 |
* now add a final element to traverse into the container; |
| 5558 |
* the final object in the path doesn't matter, since it's |
| 5559 |
* just a placeholder for the new item inside the container |
| 5560 |
*/ |
| 5561 |
path += [PathIn, nil]; |
| 5562 |
} |
| 5563 |
|
| 5564 |
/* traverse the path, sending a notification to each element */ |
| 5565 |
traversePath(path, function(target, op) { |
| 5566 |
/* notify this path element */ |
| 5567 |
target.notifyMoveViaPath(self, newContainer, op); |
| 5568 |
|
| 5569 |
/* continue the traversal */ |
| 5570 |
return true; |
| 5571 |
}); |
| 5572 |
} |
| 5573 |
|
| 5574 |
/* |
| 5575 |
* Call a function on each container. If we have no location, we |
| 5576 |
* won't invoke the function at all. We'll invoke the function as |
| 5577 |
* follows: |
| 5578 |
* |
| 5579 |
* (func)(location, args...) |
| 5580 |
*/ |
| 5581 |
forEachContainer(func, [args]) |
| 5582 |
{ |
| 5583 |
/* call the function on our location, if we have one */ |
| 5584 |
if (location != nil) |
| 5585 |
(func)(location, args...); |
| 5586 |
} |
| 5587 |
|
| 5588 |
/* |
| 5589 |
* Call a function on each *connected* container. For most objects, |
| 5590 |
* this is the same as forEachContainer, but objects that don't |
| 5591 |
* connect their containers for sense purposes would do nothing |
| 5592 |
* here. |
| 5593 |
*/ |
| 5594 |
forEachConnectedContainer(func, [args]) |
| 5595 |
{ |
| 5596 |
/* by default, use the standard forEachContainer handling */ |
| 5597 |
forEachContainer(func, args...); |
| 5598 |
} |
| 5599 |
|
| 5600 |
/* |
| 5601 |
* Get a list of all of my connected containers. This simply returns |
| 5602 |
* the list that forEachConnectedContainer() iterates over. |
| 5603 |
*/ |
| 5604 |
getConnectedContainers() |
| 5605 |
{ |
| 5606 |
local loc; |
| 5607 |
|
| 5608 |
/* |
| 5609 |
* if I have a non-nil location, return a list containing it; |
| 5610 |
* otherwise, simply return an empty list |
| 5611 |
*/ |
| 5612 |
return ((loc = location) == nil ? [] : [loc]); |
| 5613 |
} |
| 5614 |
|
| 5615 |
/* |
| 5616 |
* Clone this object for inclusion in a MultiInstance's contents |
| 5617 |
* tree. When we clone an instance object for a MultiInstance, we'll |
| 5618 |
* also clone its contents, and their contents, and so on. This |
| 5619 |
* routine creates a private copy of all of our contents. |
| 5620 |
*/ |
| 5621 |
cloneMultiInstanceContents() |
| 5622 |
{ |
| 5623 |
local origContents; |
| 5624 |
|
| 5625 |
/* |
| 5626 |
* Remember my current contents list, then clear it out. We want |
| 5627 |
* a private copy of everything in our contents list, so we want |
| 5628 |
* to forget our references to the template contents and start |
| 5629 |
* from scratch. |
| 5630 |
*/ |
| 5631 |
origContents = contents; |
| 5632 |
contents = []; |
| 5633 |
|
| 5634 |
/* clone each entry in our contents list */ |
| 5635 |
foreach (local cur in origContents) |
| 5636 |
cur.cloneForMultiInstanceContents(self); |
| 5637 |
} |
| 5638 |
|
| 5639 |
/* |
| 5640 |
* Create a clone for inclusion in MultiInstance contents. We'll |
| 5641 |
* recursively clone our own contents. |
| 5642 |
*/ |
| 5643 |
cloneForMultiInstanceContents(loc) |
| 5644 |
{ |
| 5645 |
/* create a new instance of myself */ |
| 5646 |
local cl = createInstance(); |
| 5647 |
|
| 5648 |
/* move it into the new location */ |
| 5649 |
cl.baseMoveInto(loc); |
| 5650 |
|
| 5651 |
/* clone its contents */ |
| 5652 |
cl.cloneMultiInstanceContents(); |
| 5653 |
} |
| 5654 |
|
| 5655 |
/* |
| 5656 |
* Determine if I'm a valid staging location for the given nested |
| 5657 |
* room destination 'dest'. This is called when the actor is |
| 5658 |
* attempting to enter the nested room 'dest', and the travel |
| 5659 |
* handlers find that we're the staging location for the room. (A |
| 5660 |
* "staging location" is the location the actor is required to |
| 5661 |
* occupy immediately before moving into the destination.) |
| 5662 |
* |
| 5663 |
* If this object is a valid staging location, the routine should |
| 5664 |
* simply do nothing. If this object isn't valid as a staging |
| 5665 |
* location, this routine should display an appropriate message and |
| 5666 |
* terminate the command with 'exit'. |
| 5667 |
* |
| 5668 |
* An arbitrary object can't be a staging location, simply because |
| 5669 |
* an actor can't enter an arbitrary object. So, by default, we'll |
| 5670 |
* explain that we can't enter this object. If the destination is |
| 5671 |
* contained within us, we'll provide a more specific explanation |
| 5672 |
* indicating that the problem is that the destination is within us. |
| 5673 |
*/ |
| 5674 |
checkStagingLocation(dest) |
| 5675 |
{ |
| 5676 |
/* |
| 5677 |
* if the destination is within us, explain specifically that |
| 5678 |
* this is the problem |
| 5679 |
*/ |
| 5680 |
if (dest.isIn(self)) |
| 5681 |
reportFailure(&invalidStagingContainerMsg, self, dest); |
| 5682 |
else |
| 5683 |
reportFailure(&invalidStagingLocationMsg, self); |
| 5684 |
|
| 5685 |
/* terminate the command */ |
| 5686 |
exit; |
| 5687 |
} |
| 5688 |
|
| 5689 |
/* |
| 5690 |
* by default, objects don't accept commands |
| 5691 |
*/ |
| 5692 |
acceptCommand(issuingActor) |
| 5693 |
{ |
| 5694 |
/* report that we don't accept commands */ |
| 5695 |
gLibMessages.cannotTalkTo(self, issuingActor); |
| 5696 |
|
| 5697 |
/* tell the caller we don't accept commands */ |
| 5698 |
return nil; |
| 5699 |
} |
| 5700 |
|
| 5701 |
/* |
| 5702 |
* by default, most objects are not logical targets for commands |
| 5703 |
*/ |
| 5704 |
isLikelyCommandTarget = nil |
| 5705 |
|
| 5706 |
/* |
| 5707 |
* Get my extra scope items. This is a list of any items that we |
| 5708 |
* want to add to command scope (i.e., the set of all items to which |
| 5709 |
* an actor is allowed to refer with noun phrases) when we are |
| 5710 |
* ourselves in the command scope. Returns a list of the items to |
| 5711 |
* add (or just [] if there are no items to add). |
| 5712 |
* |
| 5713 |
* By default, we add nothing. |
| 5714 |
*/ |
| 5715 |
getExtraScopeItems(actor) { return []; } |
| 5716 |
|
| 5717 |
/* |
| 5718 |
* Generate a lookup table of all of the objects connected by |
| 5719 |
* containment to this object. This table includes all containment |
| 5720 |
* connections, even through closed containers and the like. |
| 5721 |
* |
| 5722 |
* The table is keyed by object; the associated values are |
| 5723 |
* meaningless, as all that matters is whether or not an object is |
| 5724 |
* in the table. |
| 5725 |
*/ |
| 5726 |
connectionTable() |
| 5727 |
{ |
| 5728 |
local tab; |
| 5729 |
local cache; |
| 5730 |
|
| 5731 |
/* if we already have a cached connection list, return it */ |
| 5732 |
if ((cache = libGlobal.connectionCache) != nil |
| 5733 |
&& (tab = cache[self]) != nil) |
| 5734 |
return tab; |
| 5735 |
|
| 5736 |
/* remember the point of view globally, in case anyone needs it */ |
| 5737 |
senseTmp.pointOfView = self; |
| 5738 |
|
| 5739 |
/* create a lookup table for the results */ |
| 5740 |
tab = new LookupTable(32, 64); |
| 5741 |
|
| 5742 |
/* add everything connected to me */ |
| 5743 |
addDirectConnections(tab); |
| 5744 |
|
| 5745 |
/* cache the list, if we caching is active */ |
| 5746 |
if (cache != nil) |
| 5747 |
cache[self] = tab; |
| 5748 |
|
| 5749 |
/* return the table */ |
| 5750 |
return tab; |
| 5751 |
} |
| 5752 |
|
| 5753 |
/* |
| 5754 |
* Add this item and its direct containment connections to the lookup |
| 5755 |
* table. This must recursively add all connected objects that |
| 5756 |
* aren't already in the table. |
| 5757 |
*/ |
| 5758 |
addDirectConnections(tab) |
| 5759 |
{ |
| 5760 |
local cur; |
| 5761 |
|
| 5762 |
/* add myself */ |
| 5763 |
tab[self] = true; |
| 5764 |
|
| 5765 |
/* |
| 5766 |
* Add my CollectiveGroup objects, if any. We don't have to |
| 5767 |
* traverse into the CollectiveGroup objects, since they don't |
| 5768 |
* connect us or itself to anything else; our connection to a |
| 5769 |
* collective group is one-way. |
| 5770 |
*/ |
| 5771 |
foreach (cur in collectiveGroups) |
| 5772 |
tab[cur] = true; |
| 5773 |
|
| 5774 |
/* |
| 5775 |
* Add my contents to the table. Loop over our contents list, |
| 5776 |
* and add each item that's not already in the table, then |
| 5777 |
* recursively everything connected to that item. |
| 5778 |
* |
| 5779 |
* Note that we use a C-style 'for' loop to iterate over the list |
| 5780 |
* by index, rather than a more modern tads-style 'foreach' loop, |
| 5781 |
* purely for performance reasons: this code is called an awful |
| 5782 |
* lot, and the iteration by loop index is very slightly faster. |
| 5783 |
* A 'foreach' requires calling a couple of methods of an |
| 5784 |
* iterator object each time through the loop, whereas we can do |
| 5785 |
* the index-based 'for' loop entirely with cached local |
| 5786 |
* variables. The performance difference is negligible for one |
| 5787 |
* time through any given loop; it only matters to us here |
| 5788 |
* because this routine tends to be invoked *extremely* |
| 5789 |
* frequently (an average of roughly 500 times per turn in the |
| 5790 |
* library sample game, for example). Game authors are strongly |
| 5791 |
* advised to consider 'foreach' and 'for' equivalent in |
| 5792 |
* performance for most purposes - just choose the clearest |
| 5793 |
* construct for your situation. |
| 5794 |
*/ |
| 5795 |
for (local clst = contents, local i = 1, |
| 5796 |
local len = clst.length() ; i <= len ; ++i) |
| 5797 |
{ |
| 5798 |
/* get the current item */ |
| 5799 |
cur = clst[i]; |
| 5800 |
|
| 5801 |
/* if it's not already in the table, add it (recursively) */ |
| 5802 |
if (tab[cur] == nil) |
| 5803 |
cur.addDirectConnections(tab); |
| 5804 |
} |
| 5805 |
|
| 5806 |
/* add my container if it's not already in the table */ |
| 5807 |
if ((cur = location) != nil && tab[cur] == nil) |
| 5808 |
cur.addDirectConnections(tab); |
| 5809 |
} |
| 5810 |
|
| 5811 |
/* |
| 5812 |
* Try an implicit action that would remove this object as an |
| 5813 |
* obstructor to 'obj' from the perspective of the current actor in |
| 5814 |
* the given sense. This is invoked when this object is acting as |
| 5815 |
* an obstructor between the current actor and 'obj' for the given |
| 5816 |
* sense, and the caller wants to perform a command that requires a |
| 5817 |
* clear sense path to the given object in the given sense. |
| 5818 |
* |
| 5819 |
* If it is possible to perform an implicit command that would clear |
| 5820 |
* the obstruction, try performing the command, and return true. |
| 5821 |
* Otherwise, simply return nil. The usual implied command rules |
| 5822 |
* should be followed (which can be accomplished simply by using |
| 5823 |
* tryImplictAction() to execute any implied command). |
| 5824 |
* |
| 5825 |
* The particular type of command that would remove this obstructor |
| 5826 |
* can vary by obstructor class. For a container, for example, an |
| 5827 |
* "open" command is the usual remedy. |
| 5828 |
*/ |
| 5829 |
tryImplicitRemoveObstructor(sense, obj) |
| 5830 |
{ |
| 5831 |
/* by default, we have no way of clearing our obstruction */ |
| 5832 |
return nil; |
| 5833 |
} |
| 5834 |
|
| 5835 |
/* |
| 5836 |
* Display a message explaining why we are obstructing a sense path |
| 5837 |
* to the given object. |
| 5838 |
*/ |
| 5839 |
cannotReachObject(obj) |
| 5840 |
{ |
| 5841 |
/* |
| 5842 |
* Default objects have no particular obstructive capabilities, |
| 5843 |
* so we can't do anything but show the default message. This |
| 5844 |
* is a last resort that should rarely be used; normally, we |
| 5845 |
* will be able to identify a specific obstructor that overrides |
| 5846 |
* this to explain precisely what kind of obstruction is |
| 5847 |
* involved. |
| 5848 |
*/ |
| 5849 |
gLibMessages.cannotReachObject(obj); |
| 5850 |
} |
| 5851 |
|
| 5852 |
/* |
| 5853 |
* Display a message explaining that the source of a sound cannot be |
| 5854 |
* seen because I am visually obstructing it. By default, we show |
| 5855 |
* nothing at all; subclasses can override this to provide a better |
| 5856 |
* explanation when possible. |
| 5857 |
*/ |
| 5858 |
cannotSeeSoundSource(obj) { } |
| 5859 |
|
| 5860 |
/* explain why we cannot see the source of an odor */ |
| 5861 |
cannotSeeSmellSource(obj) { } |
| 5862 |
|
| 5863 |
/* |
| 5864 |
* Get the path for this object reaching out and touching the given |
| 5865 |
* object. This can be used to determine whether or not an actor |
| 5866 |
* can touch the given object. |
| 5867 |
*/ |
| 5868 |
getTouchPathTo(obj) |
| 5869 |
{ |
| 5870 |
local path; |
| 5871 |
local key = [self, obj]; |
| 5872 |
local cache; |
| 5873 |
local info; |
| 5874 |
|
| 5875 |
/* if we have a cache, try finding the data in the cache */ |
| 5876 |
if ((cache = libGlobal.canTouchCache) != nil |
| 5877 |
&& (info = cache[key]) != nil) |
| 5878 |
{ |
| 5879 |
/* we have a cache entry - return the path from the cache */ |
| 5880 |
return info.touchPath; |
| 5881 |
} |
| 5882 |
|
| 5883 |
/* select the path from here to the target object */ |
| 5884 |
path = selectPathTo(obj, &canTouchViaPath); |
| 5885 |
|
| 5886 |
/* if caching is enabled, add a cache entry for the path */ |
| 5887 |
if (cache != nil) |
| 5888 |
cache[key] = new CanTouchInfo(path); |
| 5889 |
|
| 5890 |
/* return the path */ |
| 5891 |
return path; |
| 5892 |
} |
| 5893 |
|
| 5894 |
/* |
| 5895 |
* Determine if I can touch the given object. By default, we can |
| 5896 |
* always touch our immediate container; otherwise, we can touch |
| 5897 |
* anything with a touch path that we can traverse. |
| 5898 |
*/ |
| 5899 |
canTouch(obj) |
| 5900 |
{ |
| 5901 |
local path; |
| 5902 |
local result; |
| 5903 |
local key = [self, obj]; |
| 5904 |
local cache; |
| 5905 |
local info; |
| 5906 |
|
| 5907 |
/* if we have a cache, check the cache for the desired data */ |
| 5908 |
if ((cache = libGlobal.canTouchCache) != nil |
| 5909 |
&& (info = cache[key]) != nil) |
| 5910 |
{ |
| 5911 |
/* if we cached the canTouch result, return it */ |
| 5912 |
if (info.propDefined(&canTouch)) |
| 5913 |
return info.canTouch; |
| 5914 |
|
| 5915 |
/* |
| 5916 |
* we didn't calculate the canTouch result, but we at least |
| 5917 |
* have a cached path that we can avoid recalculating |
| 5918 |
*/ |
| 5919 |
path = info.touchPath; |
| 5920 |
} |
| 5921 |
else |
| 5922 |
{ |
| 5923 |
/* we don't have a cached path, so calculate it anew */ |
| 5924 |
path = getTouchPathTo(obj); |
| 5925 |
} |
| 5926 |
|
| 5927 |
/* if there's no 'touch' path, we can't touch the object */ |
| 5928 |
if (path == nil) |
| 5929 |
{ |
| 5930 |
/* there's no path */ |
| 5931 |
result = nil; |
| 5932 |
} |
| 5933 |
else |
| 5934 |
{ |
| 5935 |
/* we have a path - check to see if we can reach along it */ |
| 5936 |
result = traversePath(path, |
| 5937 |
{ele, op: ele.canTouchViaPath(self, obj, op)}); |
| 5938 |
} |
| 5939 |
|
| 5940 |
/* if caching is active, cache our result */ |
| 5941 |
if (cache != nil) |
| 5942 |
{ |
| 5943 |
/* if we don't already have a cache entry, create one */ |
| 5944 |
if (info == nil) |
| 5945 |
cache[key] = info = new CanTouchInfo(path); |
| 5946 |
|
| 5947 |
/* save our canTouch result in the cache entry */ |
| 5948 |
info.canTouch = result; |
| 5949 |
} |
| 5950 |
|
| 5951 |
/* return the result */ |
| 5952 |
return result; |
| 5953 |
} |
| 5954 |
|
| 5955 |
/* |
| 5956 |
* Find the object that prevents us from touching the given object. |
| 5957 |
*/ |
| 5958 |
findTouchObstructor(obj) |
| 5959 |
{ |
| 5960 |
/* cache 'touch' sense path information */ |
| 5961 |
cacheSenseInfo(connectionTable(), touch); |
| 5962 |
|
| 5963 |
/* return the opaque obstructor for the sense of touch */ |
| 5964 |
return findOpaqueObstructor(touch, obj); |
| 5965 |
} |
| 5966 |
|
| 5967 |
/* |
| 5968 |
* Get the path for moving this object from its present location to |
| 5969 |
* the given new container. |
| 5970 |
*/ |
| 5971 |
getMovePathTo(newLoc) |
| 5972 |
{ |
| 5973 |
/* |
| 5974 |
* select the path from here to the new location, using the |
| 5975 |
* canMoveViaPath method to discriminate among different path |
| 5976 |
* possibilities. |
| 5977 |
*/ |
| 5978 |
return selectPathTo(newLoc, &canMoveViaPath); |
| 5979 |
} |
| 5980 |
|
| 5981 |
/* |
| 5982 |
* Get the path for throwing this object from its present location |
| 5983 |
* to the given target object. |
| 5984 |
*/ |
| 5985 |
getThrowPathTo(newLoc) |
| 5986 |
{ |
| 5987 |
/* |
| 5988 |
* select the path from here to the target, using the |
| 5989 |
* canThrowViaPath method to discriminate among different paths |
| 5990 |
*/ |
| 5991 |
return selectPathTo(newLoc, &canThrowViaPath); |
| 5992 |
} |
| 5993 |
|
| 5994 |
/* |
| 5995 |
* Determine if we can traverse self for moving the given object in |
| 5996 |
* the given manner. This is used to determine if a containment |
| 5997 |
* connection path can be used to move an object to a new location. |
| 5998 |
* Returns a CheckStatus object indicating success if we can |
| 5999 |
* traverse self, failure if not. |
| 6000 |
* |
| 6001 |
* By default, we'll simply return a success indicator. Subclasses |
| 6002 |
* might want to override this for particular conditions. For |
| 6003 |
* example, containers would normally override this to return nil |
| 6004 |
* when attempting to move an object in or out of a closed |
| 6005 |
* container. Some special containers might also want to override |
| 6006 |
* this to allow moving an object in or out only if the object is |
| 6007 |
* below a certain size threshold, for example. |
| 6008 |
* |
| 6009 |
* 'obj' is the object being moved, and 'dest' is the destination of |
| 6010 |
* the move. |
| 6011 |
* |
| 6012 |
* 'op' is one of the pathXxx operations - PathIn, PathOut, PathPeer |
| 6013 |
* - specifying what kind of movement is being attempted. PathIn |
| 6014 |
* indicates that we're moving 'obj' from outside self to inside |
| 6015 |
* self; PathOut indicates the opposite. PathPeer indicates that |
| 6016 |
* we're moving 'obj' entirely within self - this normally means |
| 6017 |
* that we've moved the object out of one of our contents and will |
| 6018 |
* move it into another of our contents. |
| 6019 |
*/ |
| 6020 |
checkMoveViaPath(obj, dest, op) { return checkStatusSuccess; } |
| 6021 |
|
| 6022 |
/* |
| 6023 |
* Determine if we can traverse this object for throwing the given |
| 6024 |
* object in the given manner. By default, this returns the same |
| 6025 |
* thing as canMoveViaPath, since throwing is in most cases the same |
| 6026 |
* as ordinary movement. Objects can override this when throwing an |
| 6027 |
* object through this path element should be treated differently |
| 6028 |
* from ordinary movement. |
| 6029 |
*/ |
| 6030 |
checkThrowViaPath(obj, dest, op) |
| 6031 |
{ return checkMoveViaPath(obj, dest, op); } |
| 6032 |
|
| 6033 |
/* |
| 6034 |
* Determine if we can traverse self in the given manner for the |
| 6035 |
* purposes of 'obj' touching another object. 'obj' is usually an |
| 6036 |
* actor; this determines if 'obj' is allowed to reach through this |
| 6037 |
* path element on the way to touching another object. |
| 6038 |
* |
| 6039 |
* By default, this returns the same thing as canMoveViaPath, since |
| 6040 |
* touching is in most cases the same as ordinary movement of an |
| 6041 |
* object from one location to another. Objects can overridet his |
| 6042 |
* when touching an object through this path element should be |
| 6043 |
* treated differently from moving an object. |
| 6044 |
*/ |
| 6045 |
checkTouchViaPath(obj, dest, op) |
| 6046 |
{ return checkMoveViaPath(obj, dest, op); } |
| 6047 |
|
| 6048 |
/* |
| 6049 |
* Determine if we can traverse this object for moving the given |
| 6050 |
* object via a path. Calls checkMoveViaPath(), and returns true if |
| 6051 |
* checkMoveViaPath() indicates success, nil if it indicates failure. |
| 6052 |
* |
| 6053 |
* Note that this method should generally not be overridden; only |
| 6054 |
* checkMoveViaPath() should usually need to be overridden. |
| 6055 |
*/ |
| 6056 |
canMoveViaPath(obj, dest, op) |
| 6057 |
{ return checkMoveViaPath(obj, dest, op).isSuccess; } |
| 6058 |
|
| 6059 |
/* determine if we can throw an object via this path */ |
| 6060 |
canThrowViaPath(obj, dest, op) |
| 6061 |
{ return checkThrowViaPath(obj, dest, op).isSuccess; } |
| 6062 |
|
| 6063 |
/* determine if we can reach out and touch an object via this path */ |
| 6064 |
canTouchViaPath(obj, dest, op) |
| 6065 |
{ return checkTouchViaPath(obj, dest, op).isSuccess; } |
| 6066 |
|
| 6067 |
/* |
| 6068 |
* Check moving an object through this container via a path. This |
| 6069 |
* method is called during moveInto to notify each element along a |
| 6070 |
* move path that the movement is about to occur. We call |
| 6071 |
* checkMoveViaPath(); if it indicates failure, we'll report the |
| 6072 |
* failure encoded in the status object and terminate the command |
| 6073 |
* with 'exit'. |
| 6074 |
* |
| 6075 |
* Note that this method should generally not be overridden; only |
| 6076 |
* checkMoveViaPath() should usually need to be overridden. |
| 6077 |
*/ |
| 6078 |
notifyMoveViaPath(obj, dest, op) |
| 6079 |
{ |
| 6080 |
local stat; |
| 6081 |
|
| 6082 |
/* check the move */ |
| 6083 |
stat = checkMoveViaPath(obj, dest, op); |
| 6084 |
|
| 6085 |
/* if it's a failure, report the failure message and terminate */ |
| 6086 |
if (!stat.isSuccess) |
| 6087 |
{ |
| 6088 |
/* report the failure */ |
| 6089 |
reportFailure(stat.msgProp, stat.msgParams...); |
| 6090 |
|
| 6091 |
/* terminate the command */ |
| 6092 |
exit; |
| 6093 |
} |
| 6094 |
} |
| 6095 |
|
| 6096 |
/* |
| 6097 |
* Choose a path from this object to a given object. If no paths |
| 6098 |
* are available, returns nil. If any paths exist, we'll find the |
| 6099 |
* shortest usable one, calling the given property on each object in |
| 6100 |
* the path to determine if the traversals are allowed. |
| 6101 |
* |
| 6102 |
* If we can find a path, but there are no good paths, we'll return |
| 6103 |
* the shortest unusable path. This can be useful for explaining |
| 6104 |
* why the traversal is impossible. |
| 6105 |
*/ |
| 6106 |
selectPathTo(obj, traverseProp) |
| 6107 |
{ |
| 6108 |
local allPaths; |
| 6109 |
local goodPaths; |
| 6110 |
local minPath; |
| 6111 |
|
| 6112 |
/* get the paths from here to the given object */ |
| 6113 |
allPaths = getAllPathsTo(obj); |
| 6114 |
|
| 6115 |
/* if we found no paths, the answer is obvious */ |
| 6116 |
if (allPaths.length() == 0) |
| 6117 |
return nil; |
| 6118 |
|
| 6119 |
/* start off with an empty vector for the good paths */ |
| 6120 |
goodPaths = new Vector(allPaths.length()); |
| 6121 |
|
| 6122 |
/* go through the paths and find the good ones */ |
| 6123 |
for (local i = 1, local len = allPaths.length() ; i <= len ; ++i) |
| 6124 |
{ |
| 6125 |
local path = allPaths[i]; |
| 6126 |
local ok; |
| 6127 |
|
| 6128 |
/* |
| 6129 |
* traverse the path, calling the traversal check property |
| 6130 |
* on each point in the path; if any check property returns |
| 6131 |
* nil, it means that the traversal isn't allowed at that |
| 6132 |
* point, so we can't use the path |
| 6133 |
*/ |
| 6134 |
ok = true; |
| 6135 |
traversePath(path, function(target, op) { |
| 6136 |
/* |
| 6137 |
* Invoke the check property on this target. If it |
| 6138 |
* doesn't allow the traversal, the path is unusable. |
| 6139 |
*/ |
| 6140 |
if (target.(traverseProp)(self, obj, op)) |
| 6141 |
{ |
| 6142 |
/* we're still okay - continue the path traversal */ |
| 6143 |
return true; |
| 6144 |
} |
| 6145 |
else |
| 6146 |
{ |
| 6147 |
/* failed - note that the path is no good */ |
| 6148 |
ok = nil; |
| 6149 |
|
| 6150 |
/* there's no need to continue the path traversal */ |
| 6151 |
return nil; |
| 6152 |
} |
| 6153 |
}); |
| 6154 |
|
| 6155 |
/* |
| 6156 |
* if we didn't find any objections to the path, add this to |
| 6157 |
* the list of good paths |
| 6158 |
*/ |
| 6159 |
if (ok) |
| 6160 |
goodPaths.append(path); |
| 6161 |
} |
| 6162 |
|
| 6163 |
/* if there are no good paths, take the shortest bad path */ |
| 6164 |
if (goodPaths.length() == 0) |
| 6165 |
goodPaths = allPaths; |
| 6166 |
|
| 6167 |
/* find the shortest of the paths we're still considering */ |
| 6168 |
minPath = nil; |
| 6169 |
for (local i = 1, local len = goodPaths.length() ; i <= len ; ++i) |
| 6170 |
{ |
| 6171 |
/* get the current path */ |
| 6172 |
local path = goodPaths[i]; |
| 6173 |
|
| 6174 |
/* if this is the best so far, note it */ |
| 6175 |
if (minPath == nil || path.length() < minPath.length()) |
| 6176 |
minPath = path; |
| 6177 |
} |
| 6178 |
|
| 6179 |
/* return the shortest good path */ |
| 6180 |
return minPath; |
| 6181 |
} |
| 6182 |
|
| 6183 |
/* |
| 6184 |
* Traverse a containment connection path, calling the given |
| 6185 |
* function for each element. In each call to the callback, 'obj' |
| 6186 |
* is the container object being traversed, and 'op' is the |
| 6187 |
* operation being used to traverse it. |
| 6188 |
* |
| 6189 |
* At each stage, the callback returns true to continue the |
| 6190 |
* traversal, nil if we are to stop the traversal. |
| 6191 |
* |
| 6192 |
* Returns nil if any callback returns nil, true if all callbacks |
| 6193 |
* return true. |
| 6194 |
*/ |
| 6195 |
traversePath(path, func) |
| 6196 |
{ |
| 6197 |
local len; |
| 6198 |
local target; |
| 6199 |
|
| 6200 |
/* |
| 6201 |
* if there's no path at all, there's nothing to do - simply |
| 6202 |
* return true in this case, because no traversal callback can |
| 6203 |
* fail when there are no traversal callbacks to begin with |
| 6204 |
*/ |
| 6205 |
if (path == nil || (len = path.length()) == 0) |
| 6206 |
return true; |
| 6207 |
|
| 6208 |
/* traverse from the path's starting point */ |
| 6209 |
if (path[1] != nil && !(func)(path[1], PathFrom)) |
| 6210 |
return nil; |
| 6211 |
|
| 6212 |
/* run through this path and see if the traversals are allowed */ |
| 6213 |
for (target = nil, local i = 2 ; i <= len ; i += 2) |
| 6214 |
{ |
| 6215 |
local op; |
| 6216 |
|
| 6217 |
/* get the next traversal operation */ |
| 6218 |
op = path[i]; |
| 6219 |
|
| 6220 |
/* check the next traversal to see if it's allowed */ |
| 6221 |
switch(op) |
| 6222 |
{ |
| 6223 |
case PathIn: |
| 6224 |
/* |
| 6225 |
* traverse in - notify the previous object, since it's |
| 6226 |
* the container we're entering |
| 6227 |
*/ |
| 6228 |
target = path[i-1]; |
| 6229 |
break; |
| 6230 |
|
| 6231 |
case PathOut: |
| 6232 |
/* |
| 6233 |
* traversing out of the current container - tell the |
| 6234 |
* next object, since it's the object we're leaving |
| 6235 |
*/ |
| 6236 |
target = path[i+1]; |
| 6237 |
break; |
| 6238 |
|
| 6239 |
case PathPeer: |
| 6240 |
/* |
| 6241 |
* traversing from one object to a containment peer - |
| 6242 |
* notify the container in common to both peers |
| 6243 |
*/ |
| 6244 |
target = path[i-1].getCommonDirectContainer(path[i+1]); |
| 6245 |
break; |
| 6246 |
|
| 6247 |
case PathThrough: |
| 6248 |
/* |
| 6249 |
* traversing through a multi-location connector (the |
| 6250 |
* previous and next object will always be the same in |
| 6251 |
* this case, so it doesn't really matter which we |
| 6252 |
* choose) |
| 6253 |
*/ |
| 6254 |
target = path[i-1]; |
| 6255 |
break; |
| 6256 |
} |
| 6257 |
|
| 6258 |
/* call the traversal callback */ |
| 6259 |
if (target != nil && !(func)(target, op)) |
| 6260 |
{ |
| 6261 |
/* the callback told us not to continue */ |
| 6262 |
return nil; |
| 6263 |
} |
| 6264 |
} |
| 6265 |
|
| 6266 |
/* |
| 6267 |
* Traverse to the path's ending point, if we haven't already. |
| 6268 |
* Some operations do traverse to the right-hand element |
| 6269 |
* (PathOut in particular), in which case we'll already have |
| 6270 |
* reached the target. Most operations traverse the left-hand |
| 6271 |
* element, though, so in these cases we need to visit the last |
| 6272 |
* element explicitly. |
| 6273 |
*/ |
| 6274 |
if (path[len] != nil |
| 6275 |
&& path[len] != target |
| 6276 |
&& !(func)(path[len], PathTo)) |
| 6277 |
return nil; |
| 6278 |
|
| 6279 |
/* all callbacks told us to continue */ |
| 6280 |
return true; |
| 6281 |
} |
| 6282 |
|
| 6283 |
/* |
| 6284 |
* Build a vector containing all of the possible paths we can |
| 6285 |
* traverse to get from me to the given object. The return value is |
| 6286 |
* a vector of paths; each path is a list of containment operations |
| 6287 |
* needed to get from here to there. |
| 6288 |
* |
| 6289 |
* Each path item in the vector is a list arranged like so: |
| 6290 |
* |
| 6291 |
* [obj, op, obj, op, obj] |
| 6292 |
* |
| 6293 |
* Each 'obj' is an object, and each 'op' is an operation enum |
| 6294 |
* (PathIn, PathOut, PathPeer) that specifies how to get from the |
| 6295 |
* preceding object to the next object. The first object in the |
| 6296 |
* list is always the starting object (i.e., self), and the last is |
| 6297 |
* always the target object ('obj'). |
| 6298 |
*/ |
| 6299 |
getAllPathsTo(obj) |
| 6300 |
{ |
| 6301 |
local vec; |
| 6302 |
|
| 6303 |
/* create an empty vector to hold the return set */ |
| 6304 |
vec = new Vector(10); |
| 6305 |
|
| 6306 |
/* look along each connection from me */ |
| 6307 |
buildContainmentPaths(vec, [self], obj); |
| 6308 |
|
| 6309 |
/* if there's no path, check the object for a special path */ |
| 6310 |
if (obj != nil && vec.length() == 0) |
| 6311 |
obj.specialPathFrom(self, vec); |
| 6312 |
|
| 6313 |
/* return the vector */ |
| 6314 |
return vec; |
| 6315 |
} |
| 6316 |
|
| 6317 |
/* |
| 6318 |
* Get a "special" path from the given starting object to me. |
| 6319 |
* src.getAllPathsTo(obj) calls this on 'obj' when it can't find any |
| 6320 |
* actual containment path from 'src' to 'obj'. If desired, this |
| 6321 |
* method should add the path or paths to the vector 'vec'. |
| 6322 |
* |
| 6323 |
* By default, we do nothing at all. The purpose of this routine is |
| 6324 |
* to allow special objects that exist outside the normal containment |
| 6325 |
* model to insinuate themselves into the sense model under special |
| 6326 |
* conditions of their choosing. |
| 6327 |
*/ |
| 6328 |
specialPathFrom(src, vec) { } |
| 6329 |
|
| 6330 |
/* |
| 6331 |
* Service routine for getAllPathsTo: build a vector of the |
| 6332 |
* containment paths starting with this object. |
| 6333 |
*/ |
| 6334 |
buildContainmentPaths(vec, pathHere, obj) |
| 6335 |
{ |
| 6336 |
local i, len; |
| 6337 |
local cur; |
| 6338 |
|
| 6339 |
/* scan each of our contents */ |
| 6340 |
for (i = 1, len = contents.length() ; i <= len ; ++i) |
| 6341 |
{ |
| 6342 |
/* get the current item */ |
| 6343 |
cur = contents[i]; |
| 6344 |
|
| 6345 |
/* |
| 6346 |
* If this item is the target, we've found what we're |
| 6347 |
* looking for - simply add the path to here to the return |
| 6348 |
* vector. |
| 6349 |
* |
| 6350 |
* Otherwise, if this item isn't already in the path, |
| 6351 |
* traverse into it; if it's already in the path, there's no |
| 6352 |
* need to look at it because we've already looked at it to |
| 6353 |
* get here |
| 6354 |
*/ |
| 6355 |
if (cur == obj) |
| 6356 |
{ |
| 6357 |
/* |
| 6358 |
* The path to here is the path to the target. Append |
| 6359 |
* the target object itself with an 'in' operation. |
| 6360 |
* Before adding the path to the result set, normalize |
| 6361 |
* it. |
| 6362 |
*/ |
| 6363 |
vec.append(normalizePath(pathHere + [PathIn, obj])); |
| 6364 |
} |
| 6365 |
else if (pathHere.indexOf(cur) == nil) |
| 6366 |
{ |
| 6367 |
/* |
| 6368 |
* look at this item, adding it to the path with an |
| 6369 |
* 'enter child' traversal |
| 6370 |
*/ |
| 6371 |
cur.buildContainmentPaths(vec, pathHere + [PathIn, cur], obj); |
| 6372 |
} |
| 6373 |
} |
| 6374 |
|
| 6375 |
/* scan each of our locations */ |
| 6376 |
for (local clst = getConnectedContainers, i = 1, len = clst.length() ; |
| 6377 |
i <= len ; ++i) |
| 6378 |
{ |
| 6379 |
/* get the current item */ |
| 6380 |
cur = clst[i]; |
| 6381 |
|
| 6382 |
/* |
| 6383 |
* If this item is the target, we've found what we're |
| 6384 |
* looking for. Otherwise, if this item isn't already in |
| 6385 |
* the path, traverse into it |
| 6386 |
*/ |
| 6387 |
if (cur == obj) |
| 6388 |
{ |
| 6389 |
/* |
| 6390 |
* We have the path to the target. Add the traversal to |
| 6391 |
* the container to the path, normalize the path, and |
| 6392 |
* add the path to the result set. |
| 6393 |
*/ |
| 6394 |
vec.append(normalizePath(pathHere + [PathOut, cur])); |
| 6395 |
} |
| 6396 |
else if (pathHere.indexOf(cur) == nil) |
| 6397 |
{ |
| 6398 |
/* |
| 6399 |
* Look at this container, adding it to the path with an |
| 6400 |
* 'exit to container' traversal. |
| 6401 |
*/ |
| 6402 |
cur.buildContainmentPaths(vec, |
| 6403 |
pathHere + [PathOut, cur], obj); |
| 6404 |
} |
| 6405 |
} |
| 6406 |
} |
| 6407 |
|
| 6408 |
/* |
| 6409 |
* "Normalize" a containment path to remove redundant containment |
| 6410 |
* traversals. |
| 6411 |
* |
| 6412 |
* First, we expand any sequence of in+out operations that take us |
| 6413 |
* out of one root-level containment tree and into another to |
| 6414 |
* include a "through" operation for the multi-location object being |
| 6415 |
* traversed. For example, if 'a' and 'c' do not share a common |
| 6416 |
* container, then we will turn this: |
| 6417 |
* |
| 6418 |
* [a PathIn b PathOut c] |
| 6419 |
* |
| 6420 |
* into this: |
| 6421 |
* |
| 6422 |
* [a PathIn b PathThrough b PathOut c] |
| 6423 |
* |
| 6424 |
* This will ensure that when we traverse the path, we will |
| 6425 |
* explicitly traverse through the connector material of 'b'. |
| 6426 |
* |
| 6427 |
* Second, we replace any sequence of out+in operations through a |
| 6428 |
* common container with "peer" operations across the container's |
| 6429 |
* contents directly. For example, a path that looks like this |
| 6430 |
* |
| 6431 |
* [a PathOut b PathIn c] |
| 6432 |
* |
| 6433 |
* will be normalized to this: |
| 6434 |
* |
| 6435 |
* [a PathPeer c] |
| 6436 |
* |
| 6437 |
* This means that we go directly from a to c, traversing through |
| 6438 |
* the fill medium of their common container 'b' but not actually |
| 6439 |
* traversing out of 'b' and back into it. |
| 6440 |
*/ |
| 6441 |
normalizePath(path) |
| 6442 |
{ |
| 6443 |
/* |
| 6444 |
* Traverse the path looking for items to normalize with the |
| 6445 |
* (in-out)->(through) transformation. Start at the second |
| 6446 |
* element, which is the first path operation code. |
| 6447 |
*/ |
| 6448 |
for (local i = 2 ; i <= path.length() ; i += 2) |
| 6449 |
{ |
| 6450 |
/* |
| 6451 |
* If we're on an 'in' operation, and an 'out' operation |
| 6452 |
* immediately follows, and the object before the 'in' and |
| 6453 |
* the object after the 'out' do not share a common |
| 6454 |
* container, we must add an explicit 'through' step for the |
| 6455 |
* multi-location connector being traversed. |
| 6456 |
*/ |
| 6457 |
if (path[i] == PathIn |
| 6458 |
&& i + 2 <= path.length() |
| 6459 |
&& path[i+2] == PathOut |
| 6460 |
&& path[i-1].getCommonDirectContainer(path[i+3]) == nil) |
| 6461 |
{ |
| 6462 |
/* we need to add a 'through' operation */ |
| 6463 |
path = path.sublist(1, i + 1) |
| 6464 |
+ PathThrough |
| 6465 |
+ path.sublist(i + 1); |
| 6466 |
} |
| 6467 |
} |
| 6468 |
|
| 6469 |
/* |
| 6470 |
* make another pass, this time applying the (out-in)->peer |
| 6471 |
* transformation |
| 6472 |
*/ |
| 6473 |
for (local i = 2 ; i <= path.length() ; i += 2) |
| 6474 |
{ |
| 6475 |
/* |
| 6476 |
* If we're on an 'out' operation, and an 'in' operation |
| 6477 |
* immediately follows, we can collapse the out+in sequence |
| 6478 |
* to a single 'peer' operation. |
| 6479 |
*/ |
| 6480 |
if (path[i] == PathOut |
| 6481 |
&& i + 2 <= path.length() |
| 6482 |
&& path[i+2] == PathIn) |
| 6483 |
{ |
| 6484 |
/* |
| 6485 |
* this sequence can be collapsed to a single 'peer' |
| 6486 |
* operation - rewrite the path accordingly |
| 6487 |
*/ |
| 6488 |
path = path.sublist(1, i - 1) |
| 6489 |
+ PathPeer |
| 6490 |
+ path.sublist(i + 3); |
| 6491 |
} |
| 6492 |
} |
| 6493 |
|
| 6494 |
/* return the normalized path */ |
| 6495 |
return path; |
| 6496 |
} |
| 6497 |
|
| 6498 |
/* |
| 6499 |
* Get the visual sense information for this object from the current |
| 6500 |
* global point of view. If we have explicit sense information set |
| 6501 |
* with setSenseInfo, we'll return that; otherwise, we'll calculate |
| 6502 |
* the current sense information for the given point of view. |
| 6503 |
* Returns a SenseInfo object giving the information. |
| 6504 |
*/ |
| 6505 |
getVisualSenseInfo() |
| 6506 |
{ |
| 6507 |
local infoTab; |
| 6508 |
|
| 6509 |
/* if we have explicit sense information already set, use it */ |
| 6510 |
if (explicitVisualSenseInfo != nil) |
| 6511 |
return explicitVisualSenseInfo; |
| 6512 |
|
| 6513 |
/* calculate the sense information for the point of view */ |
| 6514 |
infoTab = getPOVDefault(gActor).visibleInfoTable(); |
| 6515 |
|
| 6516 |
/* return the information on myself from the table */ |
| 6517 |
return infoTab[self]; |
| 6518 |
} |
| 6519 |
|
| 6520 |
/* |
| 6521 |
* Call a description method with explicit point-of-view and the |
| 6522 |
* related point-of-view sense information. 'pov' is the point of |
| 6523 |
* view object, which is usually an actor; 'senseInfo' is a |
| 6524 |
* SenseInfo object giving the sense information for this object, |
| 6525 |
* which we'll use instead of dynamically calculating the sense |
| 6526 |
* information for the duration of the routine called. |
| 6527 |
*/ |
| 6528 |
withVisualSenseInfo(pov, senseInfo, methodToCall, [args]) |
| 6529 |
{ |
| 6530 |
local oldSenseInfo; |
| 6531 |
|
| 6532 |
/* push the sense information */ |
| 6533 |
oldSenseInfo = setVisualSenseInfo(senseInfo); |
| 6534 |
|
| 6535 |
/* push the point of view */ |
| 6536 |
pushPOV(pov, pov); |
| 6537 |
|
| 6538 |
/* make sure we restore the old value no matter how we leave */ |
| 6539 |
try |
| 6540 |
{ |
| 6541 |
/* |
| 6542 |
* call the method with the given arguments, and return the |
| 6543 |
* result |
| 6544 |
*/ |
| 6545 |
return self.(methodToCall)(args...); |
| 6546 |
} |
| 6547 |
finally |
| 6548 |
{ |
| 6549 |
/* restore the old point of view */ |
| 6550 |
popPOV(); |
| 6551 |
|
| 6552 |
/* restore the old sense information */ |
| 6553 |
setVisualSenseInfo(oldSenseInfo); |
| 6554 |
} |
| 6555 |
} |
| 6556 |
|
| 6557 |
/* |
| 6558 |
* Set the explicit visual sense information; if this is not nil, |
| 6559 |
* getVisualSenseInfo() will return this rather than calculating the |
| 6560 |
* live value. Returns the old value, which is a SenseInfo or nil. |
| 6561 |
*/ |
| 6562 |
setVisualSenseInfo(info) |
| 6563 |
{ |
| 6564 |
local oldInfo; |
| 6565 |
|
| 6566 |
/* remember the old value */ |
| 6567 |
oldInfo = explicitVisualSenseInfo; |
| 6568 |
|
| 6569 |
/* remember the new value */ |
| 6570 |
explicitVisualSenseInfo = info; |
| 6571 |
|
| 6572 |
/* return the original value */ |
| 6573 |
return oldInfo; |
| 6574 |
} |
| 6575 |
|
| 6576 |
/* current explicit visual sense information overriding live value */ |
| 6577 |
explicitVisualSenseInfo = nil |
| 6578 |
|
| 6579 |
/* |
| 6580 |
* Determine how accessible my contents are to a sense. Any items |
| 6581 |
* contained within a Thing are considered external features of the |
| 6582 |
* Thing, hence they are transparently accessible to all senses. |
| 6583 |
*/ |
| 6584 |
transSensingIn(sense) { return transparent; } |
| 6585 |
|
| 6586 |
/* |
| 6587 |
* Determine how accessible peers of this object are to the contents |
| 6588 |
* of this object, via a given sense. This has the same meaning as |
| 6589 |
* transSensingIn(), but in the opposite direction: whereas |
| 6590 |
* transSensingIn() determines how accessible my contents are from |
| 6591 |
* the outside, this determines how accessible the outside is from |
| 6592 |
* the contents. |
| 6593 |
* |
| 6594 |
* By default, we simply return the same thing as transSensingIn(), |
| 6595 |
* since most containers are symmetrical for sense passing from |
| 6596 |
* inside to outside or outside to inside. However, we distinguish |
| 6597 |
* this as a separate method so that asymmetrical containers can |
| 6598 |
* have different effects in the different directions; for example, |
| 6599 |
* a box made of one-way mirrors might be transparent when looking |
| 6600 |
* from the inside to the outside, but opaque in the other |
| 6601 |
* direction. |
| 6602 |
*/ |
| 6603 |
transSensingOut(sense) { return transSensingIn(sense); } |
| 6604 |
|
| 6605 |
/* |
| 6606 |
* Get my "fill medium." This is an object of class FillMedium that |
| 6607 |
* permeates our interior, such as fog or smoke. This object |
| 6608 |
* affects the transmission of senses from one of our children to |
| 6609 |
* another, or between our interior and exterior. |
| 6610 |
* |
| 6611 |
* Note that the FillMedium object is usually a regular object in |
| 6612 |
* scope, so that the player can refer to the fill medium. For |
| 6613 |
* example, if a room is filled with fog, the player might want to |
| 6614 |
* be able to refer to the fog in a command. |
| 6615 |
* |
| 6616 |
* By default, our medium is the same as our parent's medium, on the |
| 6617 |
* assumption that fill media diffuse throughout the location's |
| 6618 |
* interior. Note, though, that Container overrides this so that a |
| 6619 |
* closed Container is isolated from its parent's fill medium - |
| 6620 |
* think of a closed bottle within a room filled with smoke. |
| 6621 |
* However, a fill medium doesn't expand from a child into its |
| 6622 |
* containers - it only diffuses into nested containers, never out. |
| 6623 |
* |
| 6624 |
* An object at the outermost containment level has no fill medium |
| 6625 |
* by default, so we return nil if our location is nil. |
| 6626 |
* |
| 6627 |
* Note that, unlike the "surface" material, the fill medium is |
| 6628 |
* assumed to be isotropic - that is, it has the same sense-passing |
| 6629 |
* characteristics regardless of the direction in which the energy |
| 6630 |
* is traversing the medium. Since we don't have any information in |
| 6631 |
* our containment model about the positions of our objects relative |
| 6632 |
* to one another, we have no way to express anisotropy in the fill |
| 6633 |
* medium among our children anyway. |
| 6634 |
* |
| 6635 |
* Note further that energy going in or out of this object must |
| 6636 |
* traverse both the fill medium and the surface of the object |
| 6637 |
* itself. Since we have no other information on the relative |
| 6638 |
* positions of our contents, we can only assume that they're |
| 6639 |
* uniformly distributed through our interior, so it is necessary to |
| 6640 |
* traverse the same amount of fill material to go from one child to |
| 6641 |
* any other or from a child to our inner surface. |
| 6642 |
* |
| 6643 |
* As a sense is transmitted, several consecutive traversals of a |
| 6644 |
* single fill material (i.e., a single object reference) will be |
| 6645 |
* treated as a single traversal of the material. Since we don't |
| 6646 |
* have a notion of distance in our containment model, we can't |
| 6647 |
* assume that we cover a certain amount of distance just because we |
| 6648 |
* traverse a certain number of containment levels. So, if we have |
| 6649 |
* three nested containment levels all inheriting a single fill |
| 6650 |
* material from their outermost parent, traversing from the inner |
| 6651 |
* container to the outer container will count as a single traversal |
| 6652 |
* of the material. |
| 6653 |
*/ |
| 6654 |
fillMedium() |
| 6655 |
{ |
| 6656 |
local loc; |
| 6657 |
|
| 6658 |
return ((loc = location) != nil ? loc.fillMedium() : nil); |
| 6659 |
} |
| 6660 |
|
| 6661 |
/* |
| 6662 |
* Can I see/hear/smell the given object? By default, an object can |
| 6663 |
* "see" (or "hear", etc) another if there's a clear path in the |
| 6664 |
* corresponding basic sense to the other object. Note that actors |
| 6665 |
* override this, because they have a subjective view of the senses: |
| 6666 |
* an actor might see in a special infrared vision sense rather than |
| 6667 |
* (or in addition to) the normal 'sight' sense, for example. |
| 6668 |
*/ |
| 6669 |
canSee(obj) { return senseObj(sight, obj).trans != opaque; } |
| 6670 |
canHear(obj) { return senseObj(sound, obj).trans != opaque; } |
| 6671 |
canSmell(obj) { return senseObj(smell, obj).trans != opaque; } |
| 6672 |
|
| 6673 |
/* can the given actor see/hear/smell/touch me? */ |
| 6674 |
canBeSeenBy(actor) { return actor.canSee(self); } |
| 6675 |
canBeHeardBy(actor) { return actor.canHear(self); } |
| 6676 |
canBeSmelledBy(actor) { return actor.canSmell(self); } |
| 6677 |
canBeTouchedBy(actor) { return actor.canTouch(self); } |
| 6678 |
|
| 6679 |
/* can the player character see/hear/smell/touch me? */ |
| 6680 |
canBeSeen = (canBeSeenBy(gPlayerChar)) |
| 6681 |
canBeHeard = (canBeHeardBy(gPlayerChar)) |
| 6682 |
canBeSmelled = (canBeSmelledBy(gPlayerChar)) |
| 6683 |
canBeTouched = (canBeTouchedBy(gPlayerChar)) |
| 6684 |
|
| 6685 |
/* |
| 6686 |
* Am I occluded by the given Occluder when viewed in the given sense |
| 6687 |
* from the given point of view? The default Occluder implementation |
| 6688 |
* calls this on each object involved in the sense path to determine |
| 6689 |
* if it should occlude the object. Returns true if we're occluded |
| 6690 |
* by the given Occluder, nil if not. By default, we simply return |
| 6691 |
* nil to indicate that we're not occluded. |
| 6692 |
*/ |
| 6693 |
isOccludedBy(occluder, sense, pov) { return nil; } |
| 6694 |
|
| 6695 |
/* |
| 6696 |
* Determine how well I can sense the given object. Returns a |
| 6697 |
* SenseInfo object describing the sense path from my point of view |
| 6698 |
* to the object. |
| 6699 |
* |
| 6700 |
* Note that, because 'distant', 'attenuated', and 'obscured' |
| 6701 |
* transparency levels always compound (with one another and with |
| 6702 |
* themselves) to opaque, there will never be more than a single |
| 6703 |
* obstructor in a path, because any path with two or more |
| 6704 |
* obstructors would be an opaque path, and hence not a path at all. |
| 6705 |
*/ |
| 6706 |
senseObj(sense, obj) |
| 6707 |
{ |
| 6708 |
local info; |
| 6709 |
|
| 6710 |
/* get the sense information from the table */ |
| 6711 |
info = senseInfoTable(sense)[obj]; |
| 6712 |
|
| 6713 |
/* if we couldn't find the object, return an 'opaque' indication */ |
| 6714 |
if (info == nil) |
| 6715 |
info = new SenseInfo(obj, opaque, nil, 0); |
| 6716 |
|
| 6717 |
/* return the sense data descriptor */ |
| 6718 |
return info; |
| 6719 |
} |
| 6720 |
|
| 6721 |
/* |
| 6722 |
* Find an opaque obstructor. This can be called immediately after |
| 6723 |
* calling senseObj() when senseObj() indicates that the object is |
| 6724 |
* opaquely obscured. We will find the nearest (by containment) |
| 6725 |
* object where the sense status is non-opaque, and we'll return |
| 6726 |
* that object. |
| 6727 |
* |
| 6728 |
* senseObj() by itself does not determine the obstructor when the |
| 6729 |
* sense path is opaque, because doing so requires extra work. The |
| 6730 |
* sense path calculator that senseObj() uses cuts off its search |
| 6731 |
* whenever it reaches an opaque point, because beyond that point |
| 6732 |
* nothing can be sensed. |
| 6733 |
* |
| 6734 |
* This can only be called immediately after calling senseObj() |
| 6735 |
* because we re-use the same cached sense path information that |
| 6736 |
* senseObj() uses. |
| 6737 |
*/ |
| 6738 |
findOpaqueObstructor(sense, obj) |
| 6739 |
{ |
| 6740 |
local path; |
| 6741 |
|
| 6742 |
/* get all of the paths from here to there */ |
| 6743 |
path = getAllPathsTo(obj); |
| 6744 |
|
| 6745 |
/* |
| 6746 |
* if there are no paths, we won't be able to find a specific |
| 6747 |
* obstructor - the object simply isn't connected to us at all |
| 6748 |
*/ |
| 6749 |
if (path == nil) |
| 6750 |
return nil; |
| 6751 |
|
| 6752 |
/* |
| 6753 |
* Arbitrarily take the first path - there must be an opaque |
| 6754 |
* obstructor on every path or we never would have been called |
| 6755 |
* in the first place. One opaque obstructor is as good as any |
| 6756 |
* other for our purposes. |
| 6757 |
*/ |
| 6758 |
path = path[1]; |
| 6759 |
|
| 6760 |
/* |
| 6761 |
* The last thing in the list that can be sensed is the opaque |
| 6762 |
* obstructor. Note that the path entries alternate between |
| 6763 |
* objects and traversal operations. |
| 6764 |
*/ |
| 6765 |
for (local i = 3, local len = path.length() ; i <= len ; i += 2) |
| 6766 |
{ |
| 6767 |
local obj; |
| 6768 |
local trans; |
| 6769 |
local ambient; |
| 6770 |
|
| 6771 |
/* get this object */ |
| 6772 |
obj = path[i]; |
| 6773 |
|
| 6774 |
/* |
| 6775 |
* get the appropriate sense direction - if the path takes |
| 6776 |
* us out, look at the interior sense data for the object; |
| 6777 |
* otherwise look at its exterior sense data |
| 6778 |
*/ |
| 6779 |
if (path[i-1] == PathOut) |
| 6780 |
{ |
| 6781 |
/* we're looking outward, so use the interior data */ |
| 6782 |
trans = obj.tmpTransWithin_; |
| 6783 |
ambient = obj.tmpAmbientWithin_; |
| 6784 |
} |
| 6785 |
else |
| 6786 |
{ |
| 6787 |
/* we're looking inward, so use the exterior data */ |
| 6788 |
trans = obj.tmpTrans_; |
| 6789 |
ambient = obj.tmpAmbient_; |
| 6790 |
} |
| 6791 |
|
| 6792 |
/* |
| 6793 |
* if this item cannot be sensed, the previous item is the |
| 6794 |
* opaque obstructor |
| 6795 |
*/ |
| 6796 |
if (!obj.canBeSensed(sense, trans, ambient)) |
| 6797 |
{ |
| 6798 |
/* can't sense it - the previous item is the obstructor */ |
| 6799 |
return path[i-2]; |
| 6800 |
} |
| 6801 |
} |
| 6802 |
|
| 6803 |
/* we didn't find any obstructor */ |
| 6804 |
return nil; |
| 6805 |
} |
| 6806 |
|
| 6807 |
/* |
| 6808 |
* Build a list of full information on all of the objects reachable |
| 6809 |
* from me through the given sense, along with full information for |
| 6810 |
* each object's sense characteristics. |
| 6811 |
* |
| 6812 |
* We return a lookup table of each object that can be sensed (in |
| 6813 |
* the given sense) from the point of view of 'self'. The key for |
| 6814 |
* each entry in the table is an object, and the corresponding value |
| 6815 |
* is a SenseInfo object describing the sense conditions for the |
| 6816 |
* object. |
| 6817 |
*/ |
| 6818 |
senseInfoTable(sense) |
| 6819 |
{ |
| 6820 |
local objs; |
| 6821 |
local tab; |
| 6822 |
local siz; |
| 6823 |
local cache; |
| 6824 |
local key = [self, sense]; |
| 6825 |
|
| 6826 |
/* if we have cached sense information, simply return it */ |
| 6827 |
if ((cache = libGlobal.senseCache) != nil |
| 6828 |
&& (tab = cache[key]) != nil) |
| 6829 |
return tab; |
| 6830 |
|
| 6831 |
/* |
| 6832 |
* get the list of objects connected to us by containment - |
| 6833 |
* since the only way senses can travel between objects is via |
| 6834 |
* containment relationships, this is the complete set of |
| 6835 |
* objects that could be connected to us by any senses |
| 6836 |
*/ |
| 6837 |
objs = connectionTable(); |
| 6838 |
|
| 6839 |
/* we're the point of view for this path calculation */ |
| 6840 |
senseTmp.pointOfView = self; |
| 6841 |
|
| 6842 |
/* cache the sensory information for all of these objects */ |
| 6843 |
cacheSenseInfo(objs, sense); |
| 6844 |
|
| 6845 |
/* build a table of all of the objects we can reach */ |
| 6846 |
siz = objs.getEntryCount(); |
| 6847 |
tab = new LookupTable(32, siz == 0 ? 32 : siz); |
| 6848 |
objs.forEachAssoc(function(cur, val) |
| 6849 |
{ |
| 6850 |
/* add this object's sense information to the table */ |
| 6851 |
cur.addToSenseInfoTable(sense, tab); |
| 6852 |
}); |
| 6853 |
|
| 6854 |
/* add the information vector to the sense cache */ |
| 6855 |
if (cache != nil) |
| 6856 |
cache[key] = tab; |
| 6857 |
|
| 6858 |
/* return the result table */ |
| 6859 |
return tab; |
| 6860 |
} |
| 6861 |
|
| 6862 |
/* |
| 6863 |
* Add myself to a sense info table. This is called by |
| 6864 |
* senseInfoTable() for each object connected by containment to the |
| 6865 |
* source object 'src', after we've fully traversed the containment |
| 6866 |
* tree to initialize our current-sense properties (tmpAmbient_, |
| 6867 |
* tmpTrans_, etc). |
| 6868 |
* |
| 6869 |
* Our job is to figure out if 'src' can sense us, and add a |
| 6870 |
* SenseInfo entry to the LookupTable 'tab' (which is keyed by |
| 6871 |
* object, hence our key is simply 'self') if 'src' can indeed sense |
| 6872 |
* us. |
| 6873 |
* |
| 6874 |
* Note that an object that wants to set up its own special sensory |
| 6875 |
* data can do so by overriding this. This routine will only be |
| 6876 |
* called on objects connected to 'src' by containment, though, so if |
| 6877 |
* an object overrides this in order to implement a special sensory |
| 6878 |
* system that's outside of the normal containment model, it must |
| 6879 |
* somehow ensure that it gets included in the containment connection |
| 6880 |
* table in the first place. |
| 6881 |
*/ |
| 6882 |
addToSenseInfoTable(sense, tab) |
| 6883 |
{ |
| 6884 |
local trans; |
| 6885 |
local ambient; |
| 6886 |
local obs; |
| 6887 |
|
| 6888 |
/* |
| 6889 |
* consider the appropriate set of data, depending on whether the |
| 6890 |
* source is looking out from within me, or in from outside of me |
| 6891 |
*/ |
| 6892 |
if (tmpPathIsIn_) |
| 6893 |
{ |
| 6894 |
/* we're looking in from without, so use our exterior data */ |
| 6895 |
trans = tmpTrans_; |
| 6896 |
ambient = tmpAmbient_; |
| 6897 |
obs = tmpObstructor_; |
| 6898 |
} |
| 6899 |
else |
| 6900 |
{ |
| 6901 |
/* we're looking out from within, so use our interior data */ |
| 6902 |
trans = tmpTransWithin_; |
| 6903 |
ambient = tmpAmbientWithin_; |
| 6904 |
obs = tmpObstructorWithin_; |
| 6905 |
} |
| 6906 |
|
| 6907 |
/* if the source can sense us, add ourself to the data */ |
| 6908 |
if (canBeSensed(sense, trans, ambient)) |
| 6909 |
tab[self] = new SenseInfo(self, trans, obs, ambient); |
| 6910 |
} |
| 6911 |
|
| 6912 |
/* |
| 6913 |
* Build a list of the objects reachable from me through the given |
| 6914 |
* sense and with a presence in the sense. |
| 6915 |
*/ |
| 6916 |
sensePresenceList(sense) |
| 6917 |
{ |
| 6918 |
local infoTab; |
| 6919 |
|
| 6920 |
/* get the full sense list */ |
| 6921 |
infoTab = senseInfoTable(sense); |
| 6922 |
|
| 6923 |
/* |
| 6924 |
* return only the subset of items that have a presence in this |
| 6925 |
* sense, and return only the items themselves, not the |
| 6926 |
* SenseInfo objects |
| 6927 |
*/ |
| 6928 |
return senseInfoTableSubset(infoTab, |
| 6929 |
{obj, info: obj.(sense.presenceProp)}); |
| 6930 |
} |
| 6931 |
|
| 6932 |
/* |
| 6933 |
* Determine the highest ambient sense level at this object for any |
| 6934 |
* of the given senses. |
| 6935 |
* |
| 6936 |
* Note that this method changes certain global variables used during |
| 6937 |
* sense and scope calculations. Because of this, be careful not to |
| 6938 |
* call this method *during* sense or scope calculations. In |
| 6939 |
* particular, don't call this from an object's canBeSensed() method |
| 6940 |
* or anything it calls. For example, don't call this from a |
| 6941 |
* Hidden.discovered method. |
| 6942 |
*/ |
| 6943 |
senseAmbientMax(senses) |
| 6944 |
{ |
| 6945 |
local objs; |
| 6946 |
local maxSoFar; |
| 6947 |
|
| 6948 |
/* we don't have any level so far */ |
| 6949 |
maxSoFar = 0; |
| 6950 |
|
| 6951 |
/* get the table of connected objects */ |
| 6952 |
objs = connectionTable(); |
| 6953 |
|
| 6954 |
/* go through each sense */ |
| 6955 |
for (local i = 1, local lst = senses, local len = lst.length() ; |
| 6956 |
i <= len ; ++i) |
| 6957 |
{ |
| 6958 |
/* |
| 6959 |
* cache the ambient level for this sense for everything |
| 6960 |
* connected by containment |
| 6961 |
*/ |
| 6962 |
cacheAmbientInfo(objs, lst[i]); |
| 6963 |
|
| 6964 |
/* |
| 6965 |
* if our cached level for this sense is the highest so far, |
| 6966 |
* remember it |
| 6967 |
*/ |
| 6968 |
if (tmpAmbient_ > maxSoFar) |
| 6969 |
maxSoFar = tmpAmbient_; |
| 6970 |
} |
| 6971 |
|
| 6972 |
/* return the highest level we found */ |
| 6973 |
return maxSoFar; |
| 6974 |
} |
| 6975 |
|
| 6976 |
/* |
| 6977 |
* Cache sensory information for all objects in the given list from |
| 6978 |
* the point of view of self. This caches the ambient energy level |
| 6979 |
* at each object, if the sense uses ambient energy, and the |
| 6980 |
* transparency and obstructor on the best path in the sense to the |
| 6981 |
* object. 'objs' is the connection table, as generated by |
| 6982 |
* connectionTable(). |
| 6983 |
*/ |
| 6984 |
cacheSenseInfo(objs, sense) |
| 6985 |
{ |
| 6986 |
/* clear out the end-of-calculation notification list */ |
| 6987 |
local nlst = senseTmp.notifyList; |
| 6988 |
if (nlst.length() != 0) |
| 6989 |
nlst.removeRange(1, nlst.length()); |
| 6990 |
|
| 6991 |
/* first, calculate the ambient energy level at each object */ |
| 6992 |
cacheAmbientInfo(objs, sense); |
| 6993 |
|
| 6994 |
/* next, cache the sense path from here to each object */ |
| 6995 |
cacheSensePath(sense); |
| 6996 |
|
| 6997 |
/* notify each object in the notification list */ |
| 6998 |
for (local i = 1, local len = nlst.length() ; i <= len ; ++i) |
| 6999 |
nlst[i].finishSensePath(objs, sense); |
| 7000 |
} |
| 7001 |
|
| 7002 |
/* |
| 7003 |
* Cache the ambient energy level at each object in the table. The |
| 7004 |
* list must include everything connected by containment. |
| 7005 |
*/ |
| 7006 |
cacheAmbientInfo(objs, sense) |
| 7007 |
{ |
| 7008 |
local aprop; |
| 7009 |
|
| 7010 |
/* |
| 7011 |
* if this sense has ambience, transmit energy from sources to |
| 7012 |
* all reachable objects; otherwise, just clear out the sense |
| 7013 |
* data |
| 7014 |
*/ |
| 7015 |
if ((aprop = sense.ambienceProp) != nil) |
| 7016 |
{ |
| 7017 |
local sources; |
| 7018 |
|
| 7019 |
/* create a vector to hold the set of ambient energy sources */ |
| 7020 |
sources = new Vector(16); |
| 7021 |
|
| 7022 |
/* |
| 7023 |
* Clear out any cached sensory information from past |
| 7024 |
* calculations, and note objects that have ambient energy to |
| 7025 |
* propagate. |
| 7026 |
*/ |
| 7027 |
objs.forEachAssoc(function(cur, val) |
| 7028 |
{ |
| 7029 |
/* clear old sensory information for this object */ |
| 7030 |
cur.clearSenseInfo(); |
| 7031 |
|
| 7032 |
/* if it's an energy source, note it */ |
| 7033 |
if (cur.(aprop) != 0) |
| 7034 |
sources.append(cur); |
| 7035 |
}); |
| 7036 |
|
| 7037 |
/* |
| 7038 |
* Calculate the ambient energy level at each object. To do |
| 7039 |
* this, start at each energy source and transmit its energy |
| 7040 |
* to all objects within reach of the sense. |
| 7041 |
*/ |
| 7042 |
for (local i = 1, local len = sources.length() ; i <= len ; ++i) |
| 7043 |
{ |
| 7044 |
/* get this item */ |
| 7045 |
local cur = sources[i]; |
| 7046 |
|
| 7047 |
/* if this item transmits energy, process it */ |
| 7048 |
if (cur.(aprop) != 0) |
| 7049 |
cur.transmitAmbient(sense); |
| 7050 |
} |
| 7051 |
} |
| 7052 |
else |
| 7053 |
{ |
| 7054 |
/* |
| 7055 |
* this sense doesn't use ambience - all we need to do is |
| 7056 |
* clear out any old sense data for this object |
| 7057 |
*/ |
| 7058 |
objs.forEachAssoc({cur, val: cur.clearSenseInfo()}); |
| 7059 |
} |
| 7060 |
} |
| 7061 |
|
| 7062 |
/* |
| 7063 |
* Transmit my radiating energy to everything within reach of the |
| 7064 |
* sense. |
| 7065 |
*/ |
| 7066 |
transmitAmbient(sense) |
| 7067 |
{ |
| 7068 |
local ambient; |
| 7069 |
|
| 7070 |
/* get the energy level I'm transmitting */ |
| 7071 |
ambient = self.(sense.ambienceProp); |
| 7072 |
|
| 7073 |
/* if this is greater than my ambient level so far, take it */ |
| 7074 |
if (ambient > tmpAmbient_) |
| 7075 |
{ |
| 7076 |
/* |
| 7077 |
* remember the new settings: start me with my own ambience, |
| 7078 |
* and with no fill medium in the way (there's nothing |
| 7079 |
* between me and myself, so I shine on myself with full |
| 7080 |
* force and with no intervening fill medium) |
| 7081 |
*/ |
| 7082 |
tmpAmbient_ = ambient; |
| 7083 |
tmpAmbientFill_ = nil; |
| 7084 |
|
| 7085 |
/* |
| 7086 |
* if the level is at least 2, transmit to adjacent objects |
| 7087 |
* (level 1 is self-illumination only, so we don't transmit |
| 7088 |
* to anything else) |
| 7089 |
*/ |
| 7090 |
if (ambient >= 2) |
| 7091 |
{ |
| 7092 |
/* transmit to my containers */ |
| 7093 |
shineOnLoc(sense, ambient, nil); |
| 7094 |
|
| 7095 |
/* shine on my contents */ |
| 7096 |
shineOnContents(sense, ambient, nil); |
| 7097 |
} |
| 7098 |
} |
| 7099 |
|
| 7100 |
/* |
| 7101 |
* Apply our interior self-illumination if necessary. If we're |
| 7102 |
* self-illuminating, and our interior surface doesn't already |
| 7103 |
* have higher ambient energy from another source, then the |
| 7104 |
* ambient energy at our inner surface is simply 1, since we |
| 7105 |
* self-illuminate inside as well as outside. |
| 7106 |
*/ |
| 7107 |
if (ambient == 1 && ambient > tmpAmbientWithin_) |
| 7108 |
tmpAmbientWithin_ = ambient; |
| 7109 |
} |
| 7110 |
|
| 7111 |
/* |
| 7112 |
* Transmit ambient energy to my location or locations. |
| 7113 |
*/ |
| 7114 |
shineOnLoc(sense, ambient, fill) |
| 7115 |
{ |
| 7116 |
/* |
| 7117 |
* shine on my container, if I have one, and its immediate |
| 7118 |
* children |
| 7119 |
*/ |
| 7120 |
if (location != nil) |
| 7121 |
location.shineFromWithin(self, sense, ambient, fill); |
| 7122 |
} |
| 7123 |
|
| 7124 |
/* |
| 7125 |
* Shine ambient energy at my surface onto my contents. |
| 7126 |
*/ |
| 7127 |
shineOnContents(sense, ambient, fill) |
| 7128 |
{ |
| 7129 |
local levelWithin; |
| 7130 |
|
| 7131 |
/* |
| 7132 |
* Figure the level of energy to transmit to my contents. To |
| 7133 |
* reach my contents, the ambient energy here must traverse our |
| 7134 |
* surface. Since we want to know what the ambient light at our |
| 7135 |
* surface looks like when viewed from our interior, we must use |
| 7136 |
* the sensing-out transparency. |
| 7137 |
*/ |
| 7138 |
levelWithin = adjustBrightness(ambient, transSensingOut(sense)); |
| 7139 |
|
| 7140 |
/* |
| 7141 |
* Remember our ambient level at our inner surface, if the |
| 7142 |
* adjusted transmission is higher than our tentative ambient |
| 7143 |
* level already set from another source or path. Note that the |
| 7144 |
* tmpAmbientWithin_ caches the ambient level at our inner |
| 7145 |
* surface, which comes before we adjust for our fill medium |
| 7146 |
* (because our fill medium is enclosed by our inner surface). |
| 7147 |
*/ |
| 7148 |
if (levelWithin >= 2 && levelWithin > tmpAmbientWithin_) |
| 7149 |
{ |
| 7150 |
local fillWithin; |
| 7151 |
|
| 7152 |
/* note my new interior ambience */ |
| 7153 |
tmpAmbientWithin_ = levelWithin; |
| 7154 |
|
| 7155 |
/* |
| 7156 |
* If there's a new fill material in my interior that the |
| 7157 |
* ambient energy here hasn't already just traversed, we must |
| 7158 |
* further adjust the ambient level in my interior by the |
| 7159 |
* fill transparency. |
| 7160 |
*/ |
| 7161 |
fillWithin = tmpFillMedium_; |
| 7162 |
if (fillWithin != fill && fillWithin != nil) |
| 7163 |
{ |
| 7164 |
/* |
| 7165 |
* we're traversing a new fill material - adjust the |
| 7166 |
* brightness further for the fill material |
| 7167 |
*/ |
| 7168 |
levelWithin = adjustBrightness(levelWithin, |
| 7169 |
fillWithin.senseThru(sense)); |
| 7170 |
} |
| 7171 |
|
| 7172 |
/* if that leaves any ambience in my interior, transmit it */ |
| 7173 |
if (levelWithin >= 2) |
| 7174 |
{ |
| 7175 |
/* shine on each object directly within me */ |
| 7176 |
for (local clst = contents, local i = 1, |
| 7177 |
local len = clst.length() ; i <= len ; ++i) |
| 7178 |
{ |
| 7179 |
/* transmit the ambient energy to this child item */ |
| 7180 |
clst[i].shineFromWithout(self, sense, |
| 7181 |
levelWithin, fillWithin); |
| 7182 |
} |
| 7183 |
} |
| 7184 |
} |
| 7185 |
} |
| 7186 |
|
| 7187 |
/* |
| 7188 |
* Transmit ambient energy from an object within me. This transmits |
| 7189 |
* to my outer surface, and also to my own immediate children - in |
| 7190 |
* other words, to the peers of the child shining on us. We need to |
| 7191 |
* transmit to the source's peers right now, because it might |
| 7192 |
* degrade the ambient energy to go out through our surface. |
| 7193 |
*/ |
| 7194 |
shineFromWithin(fromChild, sense, ambient, fill) |
| 7195 |
{ |
| 7196 |
local levelWithout; |
| 7197 |
local levelWithin; |
| 7198 |
local fillWithin; |
| 7199 |
|
| 7200 |
/* |
| 7201 |
* Calculate the change in energy as the sense makes its way to |
| 7202 |
* our "inner surface," and to peers of the sender - in both |
| 7203 |
* cases, the energy must traverse our fill medium to get to the |
| 7204 |
* next object. |
| 7205 |
* |
| 7206 |
* As always, energy must never traverse a single fill medium |
| 7207 |
* more than once consecutively, so if the last fill material is |
| 7208 |
* the same as the fill material here, no further adjustment is |
| 7209 |
* necessary for another traversal of the same material. |
| 7210 |
*/ |
| 7211 |
levelWithin = ambient; |
| 7212 |
fillWithin = tmpFillMedium_; |
| 7213 |
if (fillWithin != fill && fillWithin != nil) |
| 7214 |
{ |
| 7215 |
/* adjust the brightness for the fill traversal */ |
| 7216 |
levelWithin = adjustBrightness(levelWithin, |
| 7217 |
fillWithin.senseThru(sense)); |
| 7218 |
} |
| 7219 |
|
| 7220 |
/* if there's no energy left to transmit, we're done */ |
| 7221 |
if (levelWithin < 2) |
| 7222 |
return; |
| 7223 |
|
| 7224 |
/* |
| 7225 |
* Since we're transmitting the energy from within us, calculate |
| 7226 |
* any attenuation as the energy goes from our inner surface to |
| 7227 |
* our outer surface - this is the energy that makes it through |
| 7228 |
* to our exterior and thus is the new ambient level at our |
| 7229 |
* surface. We must calculate the attenuation that a viewer |
| 7230 |
* from outside sees looking at an energy source within us, so |
| 7231 |
* we must use the sensing-in transparency. |
| 7232 |
* |
| 7233 |
* Note that we start here with the level within that we've |
| 7234 |
* already calculated: we assume that the energy from our child |
| 7235 |
* must first traverse our interior medium before reaching our |
| 7236 |
* "inner surface," at which point it must then further traverse |
| 7237 |
* our surface material to reach our "outer surface," at which |
| 7238 |
* point it's the ambient level at our exterior. |
| 7239 |
*/ |
| 7240 |
levelWithout = adjustBrightness(levelWithin, transSensingIn(sense)); |
| 7241 |
|
| 7242 |
/* |
| 7243 |
* The level at our outer surface is the new ambient level for |
| 7244 |
* this object. The last fill material traversed is the fill |
| 7245 |
* material within me. If it's the best yet, take it. |
| 7246 |
*/ |
| 7247 |
if (levelWithout > tmpAmbient_) |
| 7248 |
{ |
| 7249 |
/* it's the best so far - cache it */ |
| 7250 |
tmpAmbient_ = levelWithout; |
| 7251 |
tmpAmbientFill_ = fillWithin; |
| 7252 |
|
| 7253 |
/* transmit to our containers */ |
| 7254 |
shineOnLoc(sense, levelWithout, fillWithin); |
| 7255 |
} |
| 7256 |
|
| 7257 |
/* transmit the level within to each peer of the sender */ |
| 7258 |
if (levelWithin > tmpAmbientWithin_) |
| 7259 |
{ |
| 7260 |
/* note our level within */ |
| 7261 |
tmpAmbientWithin_ = levelWithin; |
| 7262 |
|
| 7263 |
/* transmit to each of our children */ |
| 7264 |
for (local i = 1, local clst = contents, |
| 7265 |
local len = clst.length() ; i <= len ; ++i) |
| 7266 |
{ |
| 7267 |
/* get the current item */ |
| 7268 |
local cur = clst[i]; |
| 7269 |
|
| 7270 |
/* if it's not the source, shine on it */ |
| 7271 |
if (cur != fromChild) |
| 7272 |
cur.shineFromWithout(self, sense, |
| 7273 |
levelWithin, fillWithin); |
| 7274 |
} |
| 7275 |
} |
| 7276 |
} |
| 7277 |
|
| 7278 |
/* |
| 7279 |
* Transmit ambient energy from an object immediately containing me. |
| 7280 |
*/ |
| 7281 |
shineFromWithout(fromParent, sense, level, fill) |
| 7282 |
{ |
| 7283 |
/* if this is the best level yet, take it and transmit it */ |
| 7284 |
if (level > tmpAmbient_) |
| 7285 |
{ |
| 7286 |
/* cache this new best level */ |
| 7287 |
tmpAmbient_ = level; |
| 7288 |
tmpAmbientFill_ = fill; |
| 7289 |
|
| 7290 |
/* transmit it down to my children */ |
| 7291 |
shineOnContents(sense, level, fill); |
| 7292 |
} |
| 7293 |
} |
| 7294 |
|
| 7295 |
/* |
| 7296 |
* Cache the sense path for each object reachable from this point of |
| 7297 |
* view. Fills in tmpTrans_ and tmpObstructor_ for each object with |
| 7298 |
* the best transparency path from the object to me. |
| 7299 |
*/ |
| 7300 |
cacheSensePath(sense) |
| 7301 |
{ |
| 7302 |
/* the view from me to myself is unobstructed */ |
| 7303 |
tmpPathIsIn_ = true; |
| 7304 |
tmpTrans_ = transparent; |
| 7305 |
tmpTransWithin_ = transparent; |
| 7306 |
tmpObstructor_ = nil; |
| 7307 |
tmpObstructorWithin_ = nil; |
| 7308 |
|
| 7309 |
/* build a path to my containers */ |
| 7310 |
sensePathToLoc(sense, transparent, nil, nil); |
| 7311 |
|
| 7312 |
/* build a path to my contents */ |
| 7313 |
sensePathToContents(sense, transparent, nil, nil); |
| 7314 |
} |
| 7315 |
|
| 7316 |
/* |
| 7317 |
* Build a path to my location or locations |
| 7318 |
*/ |
| 7319 |
sensePathToLoc(sense, trans, obs, fill) |
| 7320 |
{ |
| 7321 |
/* |
| 7322 |
* proceed to my container, if I have one, and its immediate |
| 7323 |
* children |
| 7324 |
*/ |
| 7325 |
if (location != nil) |
| 7326 |
location.sensePathFromWithin(self, sense, trans, obs, fill); |
| 7327 |
} |
| 7328 |
|
| 7329 |
/* |
| 7330 |
* Build a sense path to my contents |
| 7331 |
*/ |
| 7332 |
sensePathToContents(sense, trans, obs, fill) |
| 7333 |
{ |
| 7334 |
local transWithin; |
| 7335 |
local obsWithin; |
| 7336 |
local fillWithin; |
| 7337 |
|
| 7338 |
/* |
| 7339 |
* Figure the transparency to my contents. To reach my |
| 7340 |
* contents, we must look in through our surface. If we change |
| 7341 |
* the transparency, we're the new obstructor. |
| 7342 |
*/ |
| 7343 |
transWithin = transparencyAdd(trans, transSensingIn(sense)); |
| 7344 |
obsWithin = (trans == transWithin ? obs : self); |
| 7345 |
|
| 7346 |
/* |
| 7347 |
* If there's a new fill material in my interior that we haven't |
| 7348 |
* already just traversed, we must further adjust the |
| 7349 |
* transparency by the fill transparency. |
| 7350 |
*/ |
| 7351 |
fillWithin = tmpFillMedium_; |
| 7352 |
if (fillWithin != fill && fillWithin != nil) |
| 7353 |
{ |
| 7354 |
local oldTransWithin = transWithin; |
| 7355 |
|
| 7356 |
/* we're traversing a new fill material */ |
| 7357 |
transWithin = transparencyAdd(transWithin, |
| 7358 |
fillWithin.senseThru(sense)); |
| 7359 |
if (transWithin != oldTransWithin) |
| 7360 |
obsWithin = fill; |
| 7361 |
} |
| 7362 |
|
| 7363 |
/* if the path isn't opaque, proceed to my contents */ |
| 7364 |
if (transWithin != opaque) |
| 7365 |
{ |
| 7366 |
/* build a path to each child */ |
| 7367 |
for (local clst = contents, |
| 7368 |
local i = 1, local len = clst.length() ; i <= len ; ++i) |
| 7369 |
{ |
| 7370 |
/* build a path to this child */ |
| 7371 |
clst[i].sensePathFromWithout(self, sense, transWithin, |
| 7372 |
obsWithin, fillWithin); |
| 7373 |
} |
| 7374 |
} |
| 7375 |
} |
| 7376 |
|
| 7377 |
/* |
| 7378 |
* Build a path from an object within me. |
| 7379 |
*/ |
| 7380 |
sensePathFromWithin(fromChild, sense, trans, obs, fill) |
| 7381 |
{ |
| 7382 |
local transWithin; |
| 7383 |
local fillWithin; |
| 7384 |
local transWithout; |
| 7385 |
local obsWithout; |
| 7386 |
|
| 7387 |
/* |
| 7388 |
* Calculate the transparency change along the path from the |
| 7389 |
* child to our "inner surface" and to peers of the sender - in |
| 7390 |
* both cases, we must traverse the fill material. |
| 7391 |
* |
| 7392 |
* As always, energy must never traverse a single fill medium |
| 7393 |
* more than once consecutively, so if the last fill material is |
| 7394 |
* the same as the fill material here, no further adjustment is |
| 7395 |
* necessary for another traversal of the same material. |
| 7396 |
*/ |
| 7397 |
transWithin = trans; |
| 7398 |
fillWithin = tmpFillMedium_; |
| 7399 |
if (fillWithin != fill && fillWithin != nil) |
| 7400 |
{ |
| 7401 |
/* adjust for traversing a new fill material */ |
| 7402 |
transWithin = transparencyAdd(transWithin, |
| 7403 |
fillWithin.senseThru(sense)); |
| 7404 |
if (transWithin != trans) |
| 7405 |
obs = fillWithin; |
| 7406 |
} |
| 7407 |
|
| 7408 |
/* if we're opaque at this point, we're done */ |
| 7409 |
if (transWithin == opaque) |
| 7410 |
return; |
| 7411 |
|
| 7412 |
/* |
| 7413 |
* Calculate the transparency going from our inner surface to |
| 7414 |
* our outer surface - we must traverse our own material to |
| 7415 |
* travel this segment. |
| 7416 |
*/ |
| 7417 |
transWithout = transparencyAdd(transWithin, transSensingOut(sense)); |
| 7418 |
obsWithout = (transWithout != transWithin ? self : obs); |
| 7419 |
|
| 7420 |
/* |
| 7421 |
* We now have the path to our outer surface. The last fill |
| 7422 |
* material traversed is the fill material within me. If this |
| 7423 |
* is the best yet, remember it. |
| 7424 |
*/ |
| 7425 |
if (transparencyCompare(transWithout, tmpTrans_) > 0) |
| 7426 |
{ |
| 7427 |
/* it's the best so far - cache it */ |
| 7428 |
tmpTrans_ = transWithout; |
| 7429 |
tmpObstructor_ = obsWithout; |
| 7430 |
|
| 7431 |
/* we're coming to this object from within */ |
| 7432 |
tmpPathIsIn_ = nil; |
| 7433 |
|
| 7434 |
/* transmit to our containers */ |
| 7435 |
sensePathToLoc(sense, transWithout, obsWithout, fillWithin); |
| 7436 |
} |
| 7437 |
|
| 7438 |
/* |
| 7439 |
* if this is the best interior transparency yet, build a path |
| 7440 |
* to each peer of the sender |
| 7441 |
*/ |
| 7442 |
if (transparencyCompare(transWithin, tmpTransWithin_) > 0) |
| 7443 |
{ |
| 7444 |
/* it's the best so far - cache it */ |
| 7445 |
tmpTransWithin_ = transWithin; |
| 7446 |
tmpObstructorWithin_ = obs; |
| 7447 |
|
| 7448 |
/* we're coming to this object from within */ |
| 7449 |
tmpPathIsIn_ = nil; |
| 7450 |
|
| 7451 |
/* build a path to each peer of the sender */ |
| 7452 |
for (local i = 1, local clst = contents, |
| 7453 |
local len = clst.length() ; i <= len ; ++i) |
| 7454 |
{ |
| 7455 |
/* get this item */ |
| 7456 |
local cur = clst[i]; |
| 7457 |
|
| 7458 |
/* if it's not the source, build a path to it */ |
| 7459 |
if (cur != fromChild) |
| 7460 |
cur.sensePathFromWithout(self, sense, transWithin, |
| 7461 |
obs, fillWithin); |
| 7462 |
} |
| 7463 |
} |
| 7464 |
} |
| 7465 |
|
| 7466 |
/* |
| 7467 |
* Build a path from an object immediately containing me. |
| 7468 |
*/ |
| 7469 |
sensePathFromWithout(fromParent, sense, trans, obs, fill) |
| 7470 |
{ |
| 7471 |
/* if this is the best level yet, take it and keep going */ |
| 7472 |
if (transparencyCompare(trans, tmpTrans_) > 0) |
| 7473 |
{ |
| 7474 |
/* remember this new best level */ |
| 7475 |
tmpTrans_ = trans; |
| 7476 |
tmpObstructor_ = obs; |
| 7477 |
|
| 7478 |
/* we're coming to this object from outside */ |
| 7479 |
tmpPathIsIn_ = true; |
| 7480 |
|
| 7481 |
/* build a path down into my children */ |
| 7482 |
sensePathToContents(sense, trans, obs, fill); |
| 7483 |
} |
| 7484 |
} |
| 7485 |
|
| 7486 |
|
| 7487 |
/* |
| 7488 |
* Clear the sensory scratch-pad properties, in preparation for a |
| 7489 |
* sensory calculation pass. |
| 7490 |
*/ |
| 7491 |
clearSenseInfo() |
| 7492 |
{ |
| 7493 |
tmpPathIsIn_ = true; |
| 7494 |
tmpAmbient_ = 0; |
| 7495 |
tmpAmbientWithin_ = 0; |
| 7496 |
tmpAmbientFill_ = nil; |
| 7497 |
tmpTrans_ = opaque; |
| 7498 |
tmpTransWithin_ = opaque; |
| 7499 |
tmpObstructor_ = nil; |
| 7500 |
tmpObstructorWithin_ = nil; |
| 7501 |
|
| 7502 |
/* pre-calculate my fill medium */ |
| 7503 |
tmpFillMedium_ = fillMedium(); |
| 7504 |
} |
| 7505 |
|
| 7506 |
/* |
| 7507 |
* Scratch-pad for calculating ambient energy level - valid only |
| 7508 |
* after calcAmbience and until the game state changes in any way. |
| 7509 |
* This is for internal use within the sense propagation methods |
| 7510 |
* only. |
| 7511 |
*/ |
| 7512 |
tmpAmbient_ = 0 |
| 7513 |
|
| 7514 |
/* |
| 7515 |
* Last fill material traversed by the ambient sense energy in |
| 7516 |
* tmpAmbient_. We must keep track of this so that we can treat |
| 7517 |
* consecutive traversals of the same fill material as equivalent to |
| 7518 |
* a single traversal. |
| 7519 |
*/ |
| 7520 |
tmpAmbientFill_ = nil |
| 7521 |
|
| 7522 |
/* |
| 7523 |
* Scrach-pad for the best transparency level to this object from |
| 7524 |
* the current point of view. This is used during cacheSenseInfo to |
| 7525 |
* keep track of the sense path to this object. |
| 7526 |
*/ |
| 7527 |
tmpTrans_ = opaque |
| 7528 |
|
| 7529 |
/* |
| 7530 |
* Scratch-pad for the obstructor that contributed to a |
| 7531 |
* non-transparent path to this object in tmpTrans_. |
| 7532 |
*/ |
| 7533 |
tmpObstructor_ = nil |
| 7534 |
|
| 7535 |
/* |
| 7536 |
* Scratch-pads for the ambient level, best transparency, and |
| 7537 |
* obstructor to our *interior* surface. We keep track of these |
| 7538 |
* separately from the exterior data so that we can tell what we |
| 7539 |
* look like from the persepctive of an object within us. |
| 7540 |
*/ |
| 7541 |
tmpAmbientWithin_ = 0 |
| 7542 |
tmpTransWithin_ = opaque |
| 7543 |
tmpObstructorWithin_ = nil |
| 7544 |
|
| 7545 |
/* |
| 7546 |
* Scratch-pad for the sense path direction at this object. If this |
| 7547 |
* is true, the sense path is pointing inward - that is, the path |
| 7548 |
* from the source object to here is entering from outside me. |
| 7549 |
* Otherwise, the sense path is pointing outward. |
| 7550 |
*/ |
| 7551 |
tmpPathIsIn_ = true |
| 7552 |
|
| 7553 |
/* |
| 7554 |
* My fill medium. We cache this during each sense path |
| 7555 |
* calculation, since the fill medium calculation often requires |
| 7556 |
* traversing several containment levels. |
| 7557 |
*/ |
| 7558 |
tmpFillMedium_ = nil |
| 7559 |
|
| 7560 |
/* |
| 7561 |
* Merge two senseInfoTable tables. Merges the second table into |
| 7562 |
* the first. If an object appears only in the first table, the |
| 7563 |
* entry is left unchanged; if an object appears only in the second |
| 7564 |
* table, the entry is added to the first table. If an object |
| 7565 |
* appears in both tables, we'll keep the one with better detail or |
| 7566 |
* brightness, adding it to the first table if it's the one in the |
| 7567 |
* second table. |
| 7568 |
*/ |
| 7569 |
mergeSenseInfoTable(a, b) |
| 7570 |
{ |
| 7571 |
/* if either table is nil, return the other table */ |
| 7572 |
if (a == nil) |
| 7573 |
return b; |
| 7574 |
else if (b == nil) |
| 7575 |
return a; |
| 7576 |
|
| 7577 |
/* |
| 7578 |
* iterate over the second table, merging each item from the |
| 7579 |
* second table into the corresponding item in the first table |
| 7580 |
*/ |
| 7581 |
b.forEachAssoc({obj, info: a[obj] = mergeSenseInfo(a[obj], info)}); |
| 7582 |
|
| 7583 |
/* return the merged first table */ |
| 7584 |
return a; |
| 7585 |
} |
| 7586 |
|
| 7587 |
/* |
| 7588 |
* Merge two SenseInfo items. Chooses the "better" of the two items |
| 7589 |
* and returns it, where "better" is defined as more transparent, |
| 7590 |
* or, transparencies being equal, brighter in ambient energy. |
| 7591 |
*/ |
| 7592 |
mergeSenseInfo(a, b) |
| 7593 |
{ |
| 7594 |
/* if one or the other is nil, return the non-nil one */ |
| 7595 |
if (a == nil) |
| 7596 |
return b; |
| 7597 |
if (b == nil) |
| 7598 |
return a; |
| 7599 |
|
| 7600 |
/* |
| 7601 |
* Both items are non-nil, so keep the better of the two. If |
| 7602 |
* the transparencies aren't equal, keep the one that's more |
| 7603 |
* transparent. Otherwise, keep the one with higher ambient |
| 7604 |
* energy. |
| 7605 |
*/ |
| 7606 |
if (a.trans == b.trans) |
| 7607 |
{ |
| 7608 |
/* |
| 7609 |
* The transparencies are equal, so choose the one with |
| 7610 |
* higher ambient energy. If those are the same, |
| 7611 |
* arbitrarily keep the first one. |
| 7612 |
*/ |
| 7613 |
if (a.ambient >= b.ambient) |
| 7614 |
return a; |
| 7615 |
else |
| 7616 |
return b; |
| 7617 |
} |
| 7618 |
else |
| 7619 |
{ |
| 7620 |
/* |
| 7621 |
* The transparencies are unequal, so pick the one with |
| 7622 |
* better transparency. |
| 7623 |
*/ |
| 7624 |
if (transparencyCompare(a.trans, b.trans) < 0) |
| 7625 |
return b; |
| 7626 |
else |
| 7627 |
return a; |
| 7628 |
} |
| 7629 |
} |
| 7630 |
|
| 7631 |
/* |
| 7632 |
* Receive notification that a command is about to be performed. |
| 7633 |
* This is called on each object connected by containment with the |
| 7634 |
* actor performing the command, and on any objects explicitly |
| 7635 |
* registered with the actor, the actor's location and its locations |
| 7636 |
* up to the outermost container, or the directly involved objects. |
| 7637 |
*/ |
| 7638 |
beforeAction() |
| 7639 |
{ |
| 7640 |
/* by default, do nothing */ |
| 7641 |
} |
| 7642 |
|
| 7643 |
/* |
| 7644 |
* Receive notification that a command has just been performed. |
| 7645 |
* This is called by the same rules as beforeAction(), but under the |
| 7646 |
* conditions prevailing after the command has been completed. |
| 7647 |
*/ |
| 7648 |
afterAction() |
| 7649 |
{ |
| 7650 |
/* by default, do nothing */ |
| 7651 |
} |
| 7652 |
|
| 7653 |
/* |
| 7654 |
* Receive notification that a traveler (an actor or a vehicle, for |
| 7655 |
* example) is about to depart via travelerTravelTo(), OR that an |
| 7656 |
* actor is about to move among nested locations via travelWithin(). |
| 7657 |
* This notification is sent to each object connected to the traveler |
| 7658 |
* by containment, just before the traveler departs. |
| 7659 |
* |
| 7660 |
* If the traveler is traveling between top-level locations, |
| 7661 |
* 'connector' is the TravelConnector object being traversed. If an |
| 7662 |
* actor is merely moving between nested locations, 'connector' will |
| 7663 |
* be nil. |
| 7664 |
*/ |
| 7665 |
beforeTravel(traveler, connector) { /* do nothing by default */ } |
| 7666 |
|
| 7667 |
/* |
| 7668 |
* Receive notification that a traveler has just arrived via |
| 7669 |
* travelerTravelTo(). This notification is sent to each object |
| 7670 |
* connected to the traveler by containment, in its new location, |
| 7671 |
* just after the travel completes. |
| 7672 |
*/ |
| 7673 |
afterTravel(traveler, connector) { /* do nothing by default */ } |
| 7674 |
|
| 7675 |
/* |
| 7676 |
* Get my notification list - this is a list of objects on which we |
| 7677 |
* must call beforeAction and afterAction when this object is |
| 7678 |
* involved in a command as the direct object, indirect object, or |
| 7679 |
* any addition object (other than as the actor performing the |
| 7680 |
* command). |
| 7681 |
* |
| 7682 |
* The general notification mechanism always includes in the |
| 7683 |
* notification list all of the objects connected by containment to |
| 7684 |
* the actor; this method allows for explicit registration of |
| 7685 |
* additional objects that must be notified when commands are |
| 7686 |
* performed on this object even when the other objects are nowhere |
| 7687 |
* nearby. |
| 7688 |
*/ |
| 7689 |
getObjectNotifyList() |
| 7690 |
{ |
| 7691 |
/* return our registration list */ |
| 7692 |
return objectNotifyList; |
| 7693 |
} |
| 7694 |
|
| 7695 |
/* |
| 7696 |
* Add an item to our registered notification list for actions |
| 7697 |
* involving this object as the direct object, indirect object, and |
| 7698 |
* so on. |
| 7699 |
* |
| 7700 |
* Items can be added here if they must be notified of actions |
| 7701 |
* involving this object regardless of the physical proximity of |
| 7702 |
* this item and the notification item. |
| 7703 |
*/ |
| 7704 |
addObjectNotifyItem(obj) |
| 7705 |
{ |
| 7706 |
objectNotifyList += obj; |
| 7707 |
} |
| 7708 |
|
| 7709 |
/* remove an item from the registered notification list */ |
| 7710 |
removeObjectNotifyItem(obj) |
| 7711 |
{ |
| 7712 |
objectNotifyList -= obj; |
| 7713 |
} |
| 7714 |
|
| 7715 |
/* our list of registered notification items */ |
| 7716 |
objectNotifyList = [] |
| 7717 |
|
| 7718 |
/* -------------------------------------------------------------------- */ |
| 7719 |
/* |
| 7720 |
* Verify a proposed change of location of this object from its |
| 7721 |
* current container hierarchy to the given new container. We'll |
| 7722 |
* verify removal from each container up to but not including a |
| 7723 |
* parent that's in common with the new container - we stop upon |
| 7724 |
* reaching the common parent because the object isn't leaving the |
| 7725 |
* common parent, but merely repositioned around within it. We'll |
| 7726 |
* also verify insertion into each new parent from the first |
| 7727 |
* non-common parent on down to the immediate new container. |
| 7728 |
* |
| 7729 |
* This routine is called any time an actor action would cause this |
| 7730 |
* object to be moved to a new container, so it is the common point |
| 7731 |
* at which to intercept any action that would attempt to move the |
| 7732 |
* object. |
| 7733 |
*/ |
| 7734 |
verifyMoveTo(newLoc) |
| 7735 |
{ |
| 7736 |
/* check removal up to the common parent */ |
| 7737 |
sendNotifyRemove(self, newLoc, &verifyRemove); |
| 7738 |
|
| 7739 |
/* check insertion into parents up to the common parent */ |
| 7740 |
if (newLoc != nil) |
| 7741 |
newLoc.sendNotifyInsert(self, newLoc, &verifyInsert); |
| 7742 |
} |
| 7743 |
|
| 7744 |
/* |
| 7745 |
* Send the given notification to each direct parent, each of their |
| 7746 |
* direct parents, and so forth, stopping when we reach parents that |
| 7747 |
* we have in common with our new location. We don't notify parents |
| 7748 |
* in common with new location (or their parents) because we're not |
| 7749 |
* actually removing the object from the common parents. |
| 7750 |
*/ |
| 7751 |
sendNotifyRemove(obj, newLoc, msg) |
| 7752 |
{ |
| 7753 |
/* send notification to each container, as appropriate */ |
| 7754 |
forEachContainer(function(loc) { |
| 7755 |
/* |
| 7756 |
* If this container contains the new location, don't send it |
| 7757 |
* (or its parents) notification, since we're not leaving it. |
| 7758 |
* Otherwise, send the notification and proceed to its |
| 7759 |
* parents. |
| 7760 |
*/ |
| 7761 |
if (newLoc == nil |
| 7762 |
|| (loc != newLoc && !newLoc.isIn(loc))) |
| 7763 |
{ |
| 7764 |
/* notify this container of the removal */ |
| 7765 |
loc.(msg)(obj); |
| 7766 |
|
| 7767 |
/* recursively notify this container's containers */ |
| 7768 |
loc.sendNotifyRemove(obj, newLoc, msg); |
| 7769 |
} |
| 7770 |
}); |
| 7771 |
} |
| 7772 |
|
| 7773 |
/* |
| 7774 |
* Send the given notification to each direct parent, each of their |
| 7775 |
* direct parents, and so forth, stopping when we reach parents that |
| 7776 |
* we have in common with our new location. We don't notify parents |
| 7777 |
* in common with new location (or their parents). |
| 7778 |
* |
| 7779 |
* This should always be called *before* a change of location is |
| 7780 |
* actually put into effect, so that we will still be in our old |
| 7781 |
* container when this is called. 'obj' is the object being |
| 7782 |
* inserted, and 'newCont' is the new direct container. |
| 7783 |
*/ |
| 7784 |
sendNotifyInsert(obj, newCont, msg) |
| 7785 |
{ |
| 7786 |
/* |
| 7787 |
* If the object is already in me, there's no need to notify |
| 7788 |
* myself of the insertion; otherwise, send the notification. |
| 7789 |
* |
| 7790 |
* If the object is already inside me indirectly, and we're |
| 7791 |
* moving it directly in me, still notify myself, since we're |
| 7792 |
* still picking up a new direct child. |
| 7793 |
*/ |
| 7794 |
if (!obj.isIn(self)) |
| 7795 |
{ |
| 7796 |
/* |
| 7797 |
* before we notify ourselves, notify my own parents - this |
| 7798 |
* sends the notifications from the outside in |
| 7799 |
*/ |
| 7800 |
forEachContainer({loc: loc.sendNotifyInsert(obj, newCont, msg)}); |
| 7801 |
|
| 7802 |
/* notify this potential container of the insertion */ |
| 7803 |
self.(msg)(obj, newCont); |
| 7804 |
} |
| 7805 |
else if (newCont == self && !obj.isDirectlyIn(self)) |
| 7806 |
{ |
| 7807 |
/* notify myself of the new direct insertion */ |
| 7808 |
self.(msg)(obj, self); |
| 7809 |
} |
| 7810 |
} |
| 7811 |
|
| 7812 |
/* |
| 7813 |
* Verify removal of an object from my contents or a child object's |
| 7814 |
* contents. By default we allow the removal. This is to be called |
| 7815 |
* during verification only, so gVerifyResult is valid when this is |
| 7816 |
* called. |
| 7817 |
*/ |
| 7818 |
verifyRemove(obj) |
| 7819 |
{ |
| 7820 |
} |
| 7821 |
|
| 7822 |
/* |
| 7823 |
* Verify insertion of an object into my contents. By default we |
| 7824 |
* allow it, unless I'm already inside the other object. This is to |
| 7825 |
* be called only during verification. |
| 7826 |
*/ |
| 7827 |
verifyInsert(obj, newCont) |
| 7828 |
{ |
| 7829 |
/* |
| 7830 |
* If I'm inside the other object, don't allow it, since this |
| 7831 |
* would create circular containment. |
| 7832 |
*/ |
| 7833 |
if (isIn(obj)) |
| 7834 |
illogicalNow(obj.circularlyInMessage, newCont, obj); |
| 7835 |
} |
| 7836 |
|
| 7837 |
/* |
| 7838 |
* my message indicating that another object x cannot be put into me |
| 7839 |
* because I'm already in x |
| 7840 |
*/ |
| 7841 |
circularlyInMessage = &circularlyInMsg |
| 7842 |
|
| 7843 |
/* |
| 7844 |
* Receive notification that we are about to remove an object from |
| 7845 |
* this container. This is normally called during the action() |
| 7846 |
* phase. |
| 7847 |
* |
| 7848 |
* When an object is about to be moved via moveInto(), the library |
| 7849 |
* calls notifyRemove on the old container tree, then notifyInsert on |
| 7850 |
* the new container tree, then notifyMoveInto on the object being |
| 7851 |
* moved. Any of these routines can cancel the operation by |
| 7852 |
* displaying an explanatory message and calling 'exit'. |
| 7853 |
*/ |
| 7854 |
notifyRemove(obj) |
| 7855 |
{ |
| 7856 |
} |
| 7857 |
|
| 7858 |
/* |
| 7859 |
* Receive notification that we are about to insert a new object into |
| 7860 |
* this container. 'obj' is the object being moved, and 'newCont' is |
| 7861 |
* the new direct container (which might be a child of ours). This |
| 7862 |
* is normally called during the action() phase. |
| 7863 |
* |
| 7864 |
* During moveInto(), this is called on the new container tree after |
| 7865 |
* notifyRemove has been called on the old container tree. This |
| 7866 |
* routine can cancel the move by displaying an explanatory message |
| 7867 |
* and calling 'exit'. |
| 7868 |
*/ |
| 7869 |
notifyInsert(obj, newCont) |
| 7870 |
{ |
| 7871 |
} |
| 7872 |
|
| 7873 |
/* |
| 7874 |
* Receive notification that I'm about to be moved to a new |
| 7875 |
* container. By default, we do nothing; subclasses can override |
| 7876 |
* this to do any special processing when this object is moved. This |
| 7877 |
* is normally called during the action() phase. |
| 7878 |
* |
| 7879 |
* During moveInto(), this routine is called after notifyRemove() and |
| 7880 |
* notifyInsert() have been called on the old and new container trees |
| 7881 |
* (respectively). This routine can cancel the move by displaying an |
| 7882 |
* explanatory message and calling 'exit'. |
| 7883 |
* |
| 7884 |
* This routine is the last in the notification sequence, so if this |
| 7885 |
* routine doesn't cancel the move, then the move will definitely |
| 7886 |
* happen (at least to the extent that we'll definitely call |
| 7887 |
* baseMoveInto() to carry out the move). |
| 7888 |
*/ |
| 7889 |
notifyMoveInto(newCont) |
| 7890 |
{ |
| 7891 |
} |
| 7892 |
|
| 7893 |
/* -------------------------------------------------------------------- */ |
| 7894 |
/* |
| 7895 |
* Determine if one property on this object effectively "hides" |
| 7896 |
* another. This is a sort of override check for two distinct |
| 7897 |
* properties. |
| 7898 |
* |
| 7899 |
* We look at the object to determine where prop1 and prop2 are |
| 7900 |
* defined in the class hierarchy. If prop1 isn't defined, it |
| 7901 |
* definitely doesn't hide prop2. If prop2 isn't defined, prop1 |
| 7902 |
* definitely hides it. If both are defined, then prop1 hides prop2 |
| 7903 |
* if and only if it is defined at a point in the class hierarchy |
| 7904 |
* that is "more specialized" than prop2. That is, for prop1 to |
| 7905 |
* hide prop2, the class that defines prop1 must either be the same |
| 7906 |
* as the class that defines prop2, or the class where prop1 is |
| 7907 |
* defined must inherit from the class that defines prop2, or the |
| 7908 |
* class where prop1 is defined must be earlier in a multiple |
| 7909 |
* inheritance list than the class defining prop2. |
| 7910 |
*/ |
| 7911 |
propHidesProp(prop1, prop2) |
| 7912 |
{ |
| 7913 |
local definer1; |
| 7914 |
local definer2; |
| 7915 |
|
| 7916 |
/* |
| 7917 |
* get the classes in our hierarchy where the two properties are |
| 7918 |
* defined |
| 7919 |
*/ |
| 7920 |
definer1 = propDefined(prop1, PropDefGetClass); |
| 7921 |
definer2 = propDefined(prop2, PropDefGetClass); |
| 7922 |
|
| 7923 |
/* if prop1 isn't defined, it definitely doesn't hide prop2 */ |
| 7924 |
if (definer1 == nil) |
| 7925 |
return nil; |
| 7926 |
|
| 7927 |
/* if prop1 isn't defined, prop1 definitely hides it */ |
| 7928 |
if (definer2 == nil) |
| 7929 |
return true; |
| 7930 |
|
| 7931 |
/* |
| 7932 |
* They're both defined. If definer1 inherits from definer2, |
| 7933 |
* then prop1 definitely hides prop2. |
| 7934 |
*/ |
| 7935 |
if (definer1.ofKind(definer2)) |
| 7936 |
return true; |
| 7937 |
|
| 7938 |
/* |
| 7939 |
* if definer2 inherits from definer1, then prop2 hides prop1, |
| 7940 |
* so prop1 doesn't hide prop2 |
| 7941 |
*/ |
| 7942 |
if (definer2.ofKind(definer1)) |
| 7943 |
return nil; |
| 7944 |
|
| 7945 |
/* |
| 7946 |
* The two classes don't have an inheritance relation among |
| 7947 |
* themselves, but they might still be related in our own |
| 7948 |
* hierarchy by multiple inheritance. In particular, if there |
| 7949 |
* is some point in the hierarchy where we have multiple base |
| 7950 |
* classes, and one class among the multiple bases inherits from |
| 7951 |
* definer1 and the other from definer2, then the one that's |
| 7952 |
* earlier in the multiple inheritance list is the hider. |
| 7953 |
*/ |
| 7954 |
return superHidesSuper(definer1, definer2); |
| 7955 |
} |
| 7956 |
|
| 7957 |
/* |
| 7958 |
* Determine if a given superclass of ours hides another superclass |
| 7959 |
* of ours, by being inherited (directly or indirectly) in our class |
| 7960 |
* list ahead of the other. |
| 7961 |
*/ |
| 7962 |
superHidesSuper(s1, s2) |
| 7963 |
{ |
| 7964 |
local lst; |
| 7965 |
local idx1, idx2; |
| 7966 |
|
| 7967 |
/* get our superclass list */ |
| 7968 |
lst = getSuperclassList(); |
| 7969 |
|
| 7970 |
/* if we have no superclass, there is no hiding */ |
| 7971 |
if (lst.length() == 0) |
| 7972 |
return nil; |
| 7973 |
|
| 7974 |
/* |
| 7975 |
* if we have only one element, there's obviously no hiding |
| 7976 |
* going on at this level, so simply traverse into the |
| 7977 |
* superclass to see if the hiding happens there |
| 7978 |
*/ |
| 7979 |
if (lst.length() == 1) |
| 7980 |
return lst[1].superHidesSuper(s1, s2); |
| 7981 |
|
| 7982 |
/* |
| 7983 |
* Scan the superclass list to determine the first superclass to |
| 7984 |
* which each of the two superclasses is related. Stop looking |
| 7985 |
* when we find both superclasses or exhaust our list. |
| 7986 |
*/ |
| 7987 |
for (local i = 1, idx1 = idx2 = nil ; |
| 7988 |
i <= lst.length() && (idx1 == nil || idx2 == nil) ; ++i) |
| 7989 |
{ |
| 7990 |
/* |
| 7991 |
* if we haven't found s1 yet, and this superclass of ours |
| 7992 |
* inherits from s1, this is the earliest at which we've |
| 7993 |
* found s1 |
| 7994 |
*/ |
| 7995 |
if (idx1 == nil && lst[i].ofKind(s1)) |
| 7996 |
idx1 = i; |
| 7997 |
|
| 7998 |
/* likewise for the other superclass */ |
| 7999 |
if (idx2 == nil && lst[i].ofKind(s2)) |
| 8000 |
idx2 = i; |
| 8001 |
} |
| 8002 |
|
| 8003 |
/* |
| 8004 |
* if we found the two superclasses at different points in our |
| 8005 |
* hierarchy, the one that comes earlier hides the other; so, if |
| 8006 |
* idx1 is less than idx2, s1 hides s2, and if idx1 is greater |
| 8007 |
* than idx2, s2 hides s1 (equivalently, s1 doesn't hide s2) |
| 8008 |
*/ |
| 8009 |
if (idx1 != idx2) |
| 8010 |
return idx1 < idx2; |
| 8011 |
|
| 8012 |
/* |
| 8013 |
* We found both superclasses at the same point in our |
| 8014 |
* hierarchy, so they must be multiply inherited by this base |
| 8015 |
* class or one of its classes. Keep looking up the hierarchy |
| 8016 |
* for our answer. |
| 8017 |
*/ |
| 8018 |
return lst[idx1].superHidesSuper(s1, s2); |
| 8019 |
} |
| 8020 |
|
| 8021 |
/* |
| 8022 |
* Generic "check" failure routine. This displays the given failure |
| 8023 |
* message, then performs an 'exit' to cancel the current command. |
| 8024 |
* 'msg' is the message to display - it can be a single-quoted string |
| 8025 |
* with the message text, or a property pointer. If 'msg' is a |
| 8026 |
* property pointer, any necessary message parameters can be supplied |
| 8027 |
* as additional 'params' arguments. |
| 8028 |
*/ |
| 8029 |
failCheck(msg, [params]) |
| 8030 |
{ |
| 8031 |
reportFailure(msg, params...); |
| 8032 |
exit; |
| 8033 |
} |
| 8034 |
|
| 8035 |
/* -------------------------------------------------------------------- */ |
| 8036 |
/* |
| 8037 |
* "Examine" action |
| 8038 |
*/ |
| 8039 |
dobjFor(Examine) |
| 8040 |
{ |
| 8041 |
preCond = [objVisible] |
| 8042 |
verify() |
| 8043 |
{ |
| 8044 |
/* give slight preference to an object being held */ |
| 8045 |
if (!isIn(gActor)) |
| 8046 |
logicalRank(80, 'not held'); |
| 8047 |
} |
| 8048 |
action() |
| 8049 |
{ |
| 8050 |
/* |
| 8051 |
* call our mainExamine method from the current actor's point |
| 8052 |
* of view |
| 8053 |
*/ |
| 8054 |
fromPOV(gActor, gActor, &mainExamine); |
| 8055 |
} |
| 8056 |
} |
| 8057 |
|
| 8058 |
/* |
| 8059 |
* Main examination processing. This is called with the current |
| 8060 |
* global POV set to the actor performing the 'examine' command. |
| 8061 |
*/ |
| 8062 |
mainExamine() |
| 8063 |
{ |
| 8064 |
/* perform the basic 'examine' action */ |
| 8065 |
basicExamine(); |
| 8066 |
|
| 8067 |
/* |
| 8068 |
* listen to and smell the object, but only show a message if we |
| 8069 |
* have an explicitly associated Noise/Odor object |
| 8070 |
*/ |
| 8071 |
basicExamineListen(nil); |
| 8072 |
basicExamineSmell(nil); |
| 8073 |
|
| 8074 |
/* show special descriptions for any contents */ |
| 8075 |
examineSpecialContents(); |
| 8076 |
} |
| 8077 |
|
| 8078 |
/* |
| 8079 |
* Perform the basic 'examine' action. This shows either the normal |
| 8080 |
* or initial long description (the latter only if the object hasn't |
| 8081 |
* been moved yet, and it has a special initial examine |
| 8082 |
* description), and marks the object as having been described at |
| 8083 |
* least once. |
| 8084 |
*/ |
| 8085 |
basicExamine() |
| 8086 |
{ |
| 8087 |
/* check the transparency to viewing this object */ |
| 8088 |
local info = getVisualSenseInfo(); |
| 8089 |
local t = info.trans; |
| 8090 |
|
| 8091 |
/* |
| 8092 |
* If the viewing conditions are 'obscured' or 'distant', use |
| 8093 |
* the special, custom messages for those conditions. |
| 8094 |
* Otherwise, if the details are visible (which will be the case |
| 8095 |
* even for a distant or obscured object if its sightSize is set |
| 8096 |
* to 'large'), use the ordinary 'desc' description. Otherwise, |
| 8097 |
* use an appropriate default description indicating that the |
| 8098 |
* object's details aren't visible. |
| 8099 |
*/ |
| 8100 |
if (getOutermostRoom() != getPOVDefault(gActor).getOutermostRoom() |
| 8101 |
&& propDefined(&remoteDesc)) |
| 8102 |
{ |
| 8103 |
/* we're remote, so show our remote description */ |
| 8104 |
remoteDesc(getPOVDefault(gActor)); |
| 8105 |
} |
| 8106 |
else if (t == obscured && propDefined(&obscuredDesc)) |
| 8107 |
{ |
| 8108 |
/* we're obscured, so show our special obscured description */ |
| 8109 |
obscuredDesc(info.obstructor); |
| 8110 |
} |
| 8111 |
else if (t == distant && propDefined(&distantDesc)) |
| 8112 |
{ |
| 8113 |
/* we're distant, so show our special distant description */ |
| 8114 |
distantDesc; |
| 8115 |
} |
| 8116 |
else if (canDetailsBeSensed(sight, info, getPOVDefault(gActor))) |
| 8117 |
{ |
| 8118 |
/* |
| 8119 |
* Viewing conditions and/or scale are suitable for showing |
| 8120 |
* full details, so show my normal long description. Use |
| 8121 |
* the initDesc if desired, otherwise show the normal "desc" |
| 8122 |
* description. |
| 8123 |
*/ |
| 8124 |
if (useInitDesc()) |
| 8125 |
initDesc; |
| 8126 |
else |
| 8127 |
desc; |
| 8128 |
|
| 8129 |
/* note that we've examined it */ |
| 8130 |
described = true; |
| 8131 |
|
| 8132 |
/* show any subclass-specific status */ |
| 8133 |
examineStatus(); |
| 8134 |
} |
| 8135 |
else if (t == obscured) |
| 8136 |
{ |
| 8137 |
/* |
| 8138 |
* we're obscured, and we're not large enough to see the |
| 8139 |
* details anyway, and we don't have a special description |
| 8140 |
* for when we're obscured; show the default description of |
| 8141 |
* an obscured object |
| 8142 |
*/ |
| 8143 |
defaultObscuredDesc(info.obstructor); |
| 8144 |
} |
| 8145 |
else if (t == distant) |
| 8146 |
{ |
| 8147 |
/* |
| 8148 |
* we're distant, and we're not large enough to see the |
| 8149 |
* details anyway, and we don't have a special distant |
| 8150 |
* description; show the default distant description |
| 8151 |
*/ |
| 8152 |
defaultDistantDesc; |
| 8153 |
} |
| 8154 |
} |
| 8155 |
|
| 8156 |
/* |
| 8157 |
* Show any status associated with the object as part of the full |
| 8158 |
* description. This is shown after the basicExamine() message, and |
| 8159 |
* is only displayed if we can see full details of the object |
| 8160 |
* according to the viewing conditions. |
| 8161 |
* |
| 8162 |
* By default, we simply show our contents. Even though this base |
| 8163 |
* class isn't set up as a container from the player's perspective, |
| 8164 |
* we could contain components which are themselves containers. So, |
| 8165 |
* to ensure that we properly describe any contents of our contents, |
| 8166 |
* we need to list our children. |
| 8167 |
*/ |
| 8168 |
examineStatus() |
| 8169 |
{ |
| 8170 |
/* list my contents */ |
| 8171 |
examineListContents(); |
| 8172 |
} |
| 8173 |
|
| 8174 |
/* |
| 8175 |
* List my contents as part of Examine processing. We'll recursively |
| 8176 |
* list contents of contents; this will ensure that even if we have |
| 8177 |
* no listable contents, we'll list any listable contents of our |
| 8178 |
* contents. |
| 8179 |
*/ |
| 8180 |
examineListContents() |
| 8181 |
{ |
| 8182 |
/* show our contents with our normal contents lister */ |
| 8183 |
examineListContentsWith(descContentsLister); |
| 8184 |
} |
| 8185 |
|
| 8186 |
/* list my contents for an "examine", using the given lister */ |
| 8187 |
examineListContentsWith(lister) |
| 8188 |
{ |
| 8189 |
/* get the actor's visual sense information */ |
| 8190 |
local tab = gActor.visibleInfoTable(); |
| 8191 |
|
| 8192 |
/* mark my contents as having been seen */ |
| 8193 |
setContentsSeenBy(tab, gActor); |
| 8194 |
|
| 8195 |
/* if we don't list our contents on Examine, do nothing */ |
| 8196 |
if (!contentsListedInExamine) |
| 8197 |
return; |
| 8198 |
|
| 8199 |
/* get my listed contents for 'examine' */ |
| 8200 |
local lst = getContentsForExamine(lister, tab); |
| 8201 |
|
| 8202 |
/* show my listable contents, if I have any */ |
| 8203 |
lister.showList(gActor, self, lst, ListRecurse, 0, tab, nil, |
| 8204 |
examinee: self); |
| 8205 |
} |
| 8206 |
|
| 8207 |
/* |
| 8208 |
* Basic examination of the object for sound. If the object has an |
| 8209 |
* associated noise object, we'll describe it. |
| 8210 |
* |
| 8211 |
* If 'explicit' is true, we'll show our soundDesc if we have no |
| 8212 |
* associated Noise object; otherwise, we'll show nothing at all |
| 8213 |
* unless we have a Noise object. |
| 8214 |
*/ |
| 8215 |
basicExamineListen(explicit) |
| 8216 |
{ |
| 8217 |
/* get my associated Noise object, if we have one */ |
| 8218 |
local obj = getNoise(); |
| 8219 |
|
| 8220 |
/* |
| 8221 |
* If this is not an explicit LISTEN command, only add the sound |
| 8222 |
* description if we have a Noise object that is not marked as |
| 8223 |
* "ambient." |
| 8224 |
*/ |
| 8225 |
if (!explicit && (obj == nil || obj.isAmbient)) |
| 8226 |
return; |
| 8227 |
|
| 8228 |
/* get our sensory information from the actor's point of view */ |
| 8229 |
local info = getPOVDefault(gActor).senseObj(sound, self); |
| 8230 |
local t = info.trans; |
| 8231 |
|
| 8232 |
/* |
| 8233 |
* If we have a transparent path to the object, or we have |
| 8234 |
* 'large' sound scale, show full details. Otherwise, show the |
| 8235 |
* appropriate non-detailed message for the listening conditions. |
| 8236 |
*/ |
| 8237 |
if (canDetailsBeSensed(sound, info, getPOVDefault(gActor))) |
| 8238 |
{ |
| 8239 |
/* |
| 8240 |
* We can hear full details. If we have a Noise object, show |
| 8241 |
* its "listen to source" description; otherwise, show our |
| 8242 |
* own default sound description. |
| 8243 |
*/ |
| 8244 |
if (obj != nil) |
| 8245 |
{ |
| 8246 |
/* note the explicit display of the Noise description */ |
| 8247 |
obj.noteDisplay(); |
| 8248 |
|
| 8249 |
/* show the examine-source description of the Noise */ |
| 8250 |
obj.sourceDesc; |
| 8251 |
} |
| 8252 |
else |
| 8253 |
{ |
| 8254 |
/* we have no Noise, so use our own description */ |
| 8255 |
soundDesc; |
| 8256 |
} |
| 8257 |
} |
| 8258 |
else if (t == obscured) |
| 8259 |
{ |
| 8260 |
/* show our 'obscured' description */ |
| 8261 |
obscuredSoundDesc(info.obstructor); |
| 8262 |
} |
| 8263 |
else if (t == distant) |
| 8264 |
{ |
| 8265 |
/* show our 'distant' description */ |
| 8266 |
distantSoundDesc; |
| 8267 |
} |
| 8268 |
|
| 8269 |
/* |
| 8270 |
* If this is an explicit LISTEN TO directed at this object, also |
| 8271 |
* mention any sounds we can hear from objects inside me, other |
| 8272 |
* than the Noise object we've explicitly mentioned, that have a |
| 8273 |
* sound presence. |
| 8274 |
*/ |
| 8275 |
if (explicit) |
| 8276 |
{ |
| 8277 |
local senseTab; |
| 8278 |
local presenceList; |
| 8279 |
|
| 8280 |
/* get the set of objects we can hear */ |
| 8281 |
senseTab = getPOVDefault(gActor).senseInfoTable(sound); |
| 8282 |
|
| 8283 |
/* get the subset with a sound presence that are inside me */ |
| 8284 |
presenceList = senseInfoTableSubset( |
| 8285 |
senseTab, |
| 8286 |
{x, info: x.soundPresence && x.isIn(self) && x != obj}); |
| 8287 |
|
| 8288 |
/* show the soundHereDesc for each of these */ |
| 8289 |
foreach (local cur in presenceList) |
| 8290 |
cur.soundHereDesc(); |
| 8291 |
} |
| 8292 |
} |
| 8293 |
|
| 8294 |
/* |
| 8295 |
* Basic examination of the object for odor. If the object has an |
| 8296 |
* associated odor object, we'll describe it. |
| 8297 |
*/ |
| 8298 |
basicExamineSmell(explicit) |
| 8299 |
{ |
| 8300 |
local obj; |
| 8301 |
local info; |
| 8302 |
local t; |
| 8303 |
|
| 8304 |
/* get our associated Odor object, if any */ |
| 8305 |
obj = getOdor(); |
| 8306 |
|
| 8307 |
/* |
| 8308 |
* If this is not an explicit SMELL command, only add the odor |
| 8309 |
* description if we have an Odor object that is not marked as |
| 8310 |
* "ambient." |
| 8311 |
*/ |
| 8312 |
if (!explicit && (obj == nil || obj.isAmbient)) |
| 8313 |
return; |
| 8314 |
|
| 8315 |
/* get our sensory information from the actor's point of view */ |
| 8316 |
info = getPOVDefault(gActor).senseObj(smell, self); |
| 8317 |
t = info.trans; |
| 8318 |
|
| 8319 |
/* |
| 8320 |
* If we have a transparent path to the object, or we have |
| 8321 |
* 'large' sound scale, show full details. Otherwise, show the |
| 8322 |
* appropriate non-detailed message for the listening conditions. |
| 8323 |
*/ |
| 8324 |
if (canDetailsBeSensed(smell, info, getPOVDefault(gActor))) |
| 8325 |
{ |
| 8326 |
/* if we have a Noise object, show its "listen to source" */ |
| 8327 |
if (obj != nil) |
| 8328 |
{ |
| 8329 |
/* note the explicit display of the Odor description */ |
| 8330 |
obj.noteDisplay(); |
| 8331 |
|
| 8332 |
/* show the examine-source description of the Odor */ |
| 8333 |
obj.sourceDesc; |
| 8334 |
} |
| 8335 |
else |
| 8336 |
{ |
| 8337 |
/* we have no associated Odor; show our default description */ |
| 8338 |
smellDesc; |
| 8339 |
} |
| 8340 |
} |
| 8341 |
else if (t == obscured) |
| 8342 |
{ |
| 8343 |
/* show our 'obscured' description */ |
| 8344 |
obscuredSmellDesc(info.obstructor); |
| 8345 |
} |
| 8346 |
else if (t == distant) |
| 8347 |
{ |
| 8348 |
/* show our 'distant' description */ |
| 8349 |
distantSmellDesc; |
| 8350 |
} |
| 8351 |
|
| 8352 |
/* |
| 8353 |
* If this is an explicit SMELL command directed at this object, |
| 8354 |
* also mention any odors we can detect from objects inside me, |
| 8355 |
* other than the Odor object we've explicitly mentioned, that |
| 8356 |
* have an odor presence. |
| 8357 |
*/ |
| 8358 |
if (explicit) |
| 8359 |
{ |
| 8360 |
local senseTab; |
| 8361 |
local presenceList; |
| 8362 |
|
| 8363 |
/* get the set of objects we can smell */ |
| 8364 |
senseTab = getPOVDefault(gActor).senseInfoTable(smell); |
| 8365 |
|
| 8366 |
/* get the subset with a smell presence that are inside me */ |
| 8367 |
presenceList = senseInfoTableSubset( |
| 8368 |
senseTab, |
| 8369 |
{x, info: x.smellPresence && x.isIn(self) && x != obj}); |
| 8370 |
|
| 8371 |
/* show the smellHereDesc for each of these */ |
| 8372 |
foreach (local cur in presenceList) |
| 8373 |
cur.smellHereDesc(); |
| 8374 |
} |
| 8375 |
} |
| 8376 |
|
| 8377 |
/* |
| 8378 |
* Basic examination of an object for taste. Unlike the |
| 8379 |
* smell/listen examination routines, we don't bother using a |
| 8380 |
* separate sensory emanation object for tasting, as tasting is |
| 8381 |
* always an explicit action, never passive. Furthermore, since |
| 8382 |
* tasting requires direct physical contact with the object, we |
| 8383 |
* don't differentiate levels of transparency or distance. |
| 8384 |
*/ |
| 8385 |
basicExamineTaste() |
| 8386 |
{ |
| 8387 |
/* simply show our taste description */ |
| 8388 |
tasteDesc; |
| 8389 |
} |
| 8390 |
|
| 8391 |
/* |
| 8392 |
* Basic examination of an object for touch. As with the basic |
| 8393 |
* taste examination, we don't use an emanation object or |
| 8394 |
* distinguish transparency levels, because feeling an object |
| 8395 |
* requires direct physical contact. |
| 8396 |
*/ |
| 8397 |
basicExamineFeel() |
| 8398 |
{ |
| 8399 |
/* simply show our touch description */ |
| 8400 |
feelDesc; |
| 8401 |
} |
| 8402 |
|
| 8403 |
/* |
| 8404 |
* Show the special descriptions of any contents. We'll run through |
| 8405 |
* the visible information list for the location; for any visible |
| 8406 |
* item inside me that is using its special description, we'll |
| 8407 |
* display the special description as a separate paragraph. |
| 8408 |
*/ |
| 8409 |
examineSpecialContents() |
| 8410 |
{ |
| 8411 |
/* get the actor's table of visible items */ |
| 8412 |
local infoTab = gActor.visibleInfoTable(); |
| 8413 |
|
| 8414 |
/* |
| 8415 |
* get the objects using special descriptions and contained |
| 8416 |
* within this object |
| 8417 |
*/ |
| 8418 |
local lst = specialDescList( |
| 8419 |
infoTab, {obj: obj.useSpecialDescInContents(self)}); |
| 8420 |
|
| 8421 |
/* show the special descriptions */ |
| 8422 |
(new SpecialDescContentsLister(self)).showList( |
| 8423 |
gActor, nil, lst, 0, 0, infoTab, nil); |
| 8424 |
} |
| 8425 |
|
| 8426 |
/* |
| 8427 |
* Given a visible object info table (from Actor.visibleInfoTable()), |
| 8428 |
* get the list of objects, filtered by the given condition and |
| 8429 |
* sorted by specialDescOrder. |
| 8430 |
*/ |
| 8431 |
specialDescList(infoTab, cond) |
| 8432 |
{ |
| 8433 |
local lst; |
| 8434 |
|
| 8435 |
/* |
| 8436 |
* get a list of all of the objects in the table - the objects |
| 8437 |
* are the keys, so we just want a list of the keys |
| 8438 |
*/ |
| 8439 |
lst = infoTab.keysToList(); |
| 8440 |
|
| 8441 |
/* subset the list for the given condition */ |
| 8442 |
lst = lst.subset(cond); |
| 8443 |
|
| 8444 |
/* |
| 8445 |
* Sort the list in ascending order of specialDescOrder, and |
| 8446 |
* return the result. Where the specialDescOrder is the same, |
| 8447 |
* and one object is inside another, put the outer object earlier |
| 8448 |
* in the list; this will ensure that we'll generally list |
| 8449 |
* objects before their contents, except when the special desc |
| 8450 |
* list order specifically says otherwise. |
| 8451 |
*/ |
| 8452 |
return lst.sort(SortAsc, function(a, b) { |
| 8453 |
/* if the list orders are different, go by list order */ |
| 8454 |
if (a.specialDescOrder != b.specialDescOrder) |
| 8455 |
return a.specialDescOrder - b.specialDescOrder; |
| 8456 |
|
| 8457 |
/* |
| 8458 |
* the list order is the same; if one is inside the other, |
| 8459 |
* list the outer one first |
| 8460 |
*/ |
| 8461 |
if (a.isIn(b)) |
| 8462 |
return 1; |
| 8463 |
else if (b.isIn(a)) |
| 8464 |
return -1; |
| 8465 |
else |
| 8466 |
return 0; |
| 8467 |
}); |
| 8468 |
} |
| 8469 |
|
| 8470 |
|
| 8471 |
/* -------------------------------------------------------------------- */ |
| 8472 |
/* |
| 8473 |
* "Read" |
| 8474 |
*/ |
| 8475 |
dobjFor(Read) |
| 8476 |
{ |
| 8477 |
preCond = [objVisible] |
| 8478 |
verify() |
| 8479 |
{ |
| 8480 |
/* |
| 8481 |
* reduce the likelihood that they want to read an ordinary |
| 8482 |
* item, but allow it |
| 8483 |
*/ |
| 8484 |
logicalRank(50, 'not readable'); |
| 8485 |
|
| 8486 |
/* give slight preference to an object being held */ |
| 8487 |
if (!isIn(gActor)) |
| 8488 |
logicalRank(80, 'not held'); |
| 8489 |
} |
| 8490 |
action() |
| 8491 |
{ |
| 8492 |
/* simply show the ordinary description */ |
| 8493 |
actionDobjExamine(); |
| 8494 |
} |
| 8495 |
} |
| 8496 |
|
| 8497 |
/* -------------------------------------------------------------------- */ |
| 8498 |
/* |
| 8499 |
* "Look in" |
| 8500 |
*/ |
| 8501 |
dobjFor(LookIn) |
| 8502 |
{ |
| 8503 |
preCond = [objVisible] |
| 8504 |
verify() |
| 8505 |
{ |
| 8506 |
/* give slight preference to an object being held */ |
| 8507 |
if (!isIn(gActor)) |
| 8508 |
logicalRank(80, 'not held'); |
| 8509 |
} |
| 8510 |
action() |
| 8511 |
{ |
| 8512 |
/* show our LOOK IN description */ |
| 8513 |
lookInDesc; |
| 8514 |
} |
| 8515 |
} |
| 8516 |
|
| 8517 |
/* -------------------------------------------------------------------- */ |
| 8518 |
/* |
| 8519 |
* "Search". By default, we make "search obj" do the same thing as |
| 8520 |
* "look in obj". |
| 8521 |
*/ |
| 8522 |
dobjFor(Search) asDobjFor(LookIn) |
| 8523 |
|
| 8524 |
/* -------------------------------------------------------------------- */ |
| 8525 |
/* |
| 8526 |
* "Look under" |
| 8527 |
*/ |
| 8528 |
dobjFor(LookUnder) |
| 8529 |
{ |
| 8530 |
preCond = [objVisible] |
| 8531 |
verify() { } |
| 8532 |
action() { mainReport(¬hingUnderMsg); } |
| 8533 |
} |
| 8534 |
|
| 8535 |
/* -------------------------------------------------------------------- */ |
| 8536 |
/* |
| 8537 |
* "Look behind" |
| 8538 |
*/ |
| 8539 |
dobjFor(LookBehind) |
| 8540 |
{ |
| 8541 |
preCond = [objVisible] |
| 8542 |
verify() { } |
| 8543 |
action() { mainReport(¬hingBehindMsg); } |
| 8544 |
} |
| 8545 |
|
| 8546 |
/* -------------------------------------------------------------------- */ |
| 8547 |
/* |
| 8548 |
* "Look through" |
| 8549 |
*/ |
| 8550 |
dobjFor(LookThrough) |
| 8551 |
{ |
| 8552 |
verify() { } |
| 8553 |
action() { mainReport(¬hingThroughMsg); } |
| 8554 |
} |
| 8555 |
|
| 8556 |
/* -------------------------------------------------------------------- */ |
| 8557 |
/* |
| 8558 |
* "Listen to" |
| 8559 |
*/ |
| 8560 |
dobjFor(ListenTo) |
| 8561 |
{ |
| 8562 |
preCond = [objAudible] |
| 8563 |
verify() { } |
| 8564 |
action() |
| 8565 |
{ |
| 8566 |
/* show our "listen" description explicitly */ |
| 8567 |
fromPOV(gActor, gActor, &basicExamineListen, true); |
| 8568 |
} |
| 8569 |
} |
| 8570 |
|
| 8571 |
/* -------------------------------------------------------------------- */ |
| 8572 |
/* |
| 8573 |
* "Smell" |
| 8574 |
*/ |
| 8575 |
dobjFor(Smell) |
| 8576 |
{ |
| 8577 |
preCond = [objSmellable] |
| 8578 |
verify() { } |
| 8579 |
action() |
| 8580 |
{ |
| 8581 |
/* |
| 8582 |
* show our 'smell' description, explicitly showing our |
| 8583 |
* default description if we don't have an Odor association |
| 8584 |
*/ |
| 8585 |
fromPOV(gActor, gActor, &basicExamineSmell, true); |
| 8586 |
} |
| 8587 |
} |
| 8588 |
|
| 8589 |
/* -------------------------------------------------------------------- */ |
| 8590 |
/* |
| 8591 |
* "Taste" |
| 8592 |
*/ |
| 8593 |
dobjFor(Taste) |
| 8594 |
{ |
| 8595 |
/* to taste an object, we have to be able to touch it */ |
| 8596 |
preCond = [touchObj] |
| 8597 |
verify() |
| 8598 |
{ |
| 8599 |
/* you *can* taste anything, but for most things it's unlikely */ |
| 8600 |
logicalRank(50, 'not edible'); |
| 8601 |
} |
| 8602 |
action() |
| 8603 |
{ |
| 8604 |
/* show our "taste" description */ |
| 8605 |
fromPOV(gActor, gActor, &basicExamineTaste); |
| 8606 |
} |
| 8607 |
} |
| 8608 |
|
| 8609 |
/* -------------------------------------------------------------------- */ |
| 8610 |
/* |
| 8611 |
* "Feel" |
| 8612 |
*/ |
| 8613 |
dobjFor(Feel) |
| 8614 |
{ |
| 8615 |
/* to feel an object, we have to be able to touch it */ |
| 8616 |
preCond = [touchObj] |
| 8617 |
verify() { } |
| 8618 |
action() |
| 8619 |
{ |
| 8620 |
/* show our "feel" description */ |
| 8621 |
fromPOV(gActor, gActor, &basicExamineFeel); |
| 8622 |
} |
| 8623 |
} |
| 8624 |
|
| 8625 |
|
| 8626 |
/* -------------------------------------------------------------------- */ |
| 8627 |
/* |
| 8628 |
* "Take" action |
| 8629 |
*/ |
| 8630 |
|
| 8631 |
dobjFor(Take) |
| 8632 |
{ |
| 8633 |
preCond = [touchObj, objNotWorn, roomToHoldObj] |
| 8634 |
verify() |
| 8635 |
{ |
| 8636 |
/* |
| 8637 |
* if the object is already being held by the actor, it |
| 8638 |
* makes no sense at the moment to take it |
| 8639 |
*/ |
| 8640 |
if (isDirectlyIn(gActor)) |
| 8641 |
{ |
| 8642 |
/* I'm already holding it, so this is not logical */ |
| 8643 |
illogicalAlready(&alreadyHoldingMsg); |
| 8644 |
} |
| 8645 |
else |
| 8646 |
{ |
| 8647 |
local carrier; |
| 8648 |
|
| 8649 |
/* |
| 8650 |
* If the object isn't being held, it's logical to take |
| 8651 |
* it. However, rank objects being carried as less |
| 8652 |
* likely than objects not being carried, because in an |
| 8653 |
* ambiguous situation, it's more likely that an actor |
| 8654 |
* would want to take something not being carried at all |
| 8655 |
* than something already being carried inside another |
| 8656 |
* object. |
| 8657 |
*/ |
| 8658 |
if (isIn(gActor)) |
| 8659 |
logicalRank(70, 'already in'); |
| 8660 |
|
| 8661 |
/* |
| 8662 |
* If the object is being carried by another actor, |
| 8663 |
* reduce the likelihood, since taking something from |
| 8664 |
* another actor is usually less likely than taking |
| 8665 |
* something out of one's own possessions or from the |
| 8666 |
* location. |
| 8667 |
*/ |
| 8668 |
carrier = getCarryingActor(); |
| 8669 |
if (carrier != nil && carrier != gActor) |
| 8670 |
logicalRank(60, 'other owner'); |
| 8671 |
} |
| 8672 |
|
| 8673 |
/* |
| 8674 |
* verify transfer from the current container hierarchy to |
| 8675 |
* the new container hierarchy |
| 8676 |
*/ |
| 8677 |
verifyMoveTo(gActor); |
| 8678 |
} |
| 8679 |
|
| 8680 |
action() |
| 8681 |
{ |
| 8682 |
/* move me into the actor's direct contents */ |
| 8683 |
moveInto(gActor); |
| 8684 |
|
| 8685 |
/* issue our default acknowledgment of the command */ |
| 8686 |
defaultReport(&okayTakeMsg); |
| 8687 |
} |
| 8688 |
} |
| 8689 |
|
| 8690 |
/* -------------------------------------------------------------------- */ |
| 8691 |
/* |
| 8692 |
* "Remove" processing. We'll treat "remove dobj" as meaning "take |
| 8693 |
* dobj from <something>", where <something> is elided and must be |
| 8694 |
* determined. |
| 8695 |
* |
| 8696 |
* This should be overridden in certain cases. For clothing, |
| 8697 |
* "remove dobj" should be the same as "doff dobj". For removable |
| 8698 |
* components, this should imply removing the component from its |
| 8699 |
* container. |
| 8700 |
*/ |
| 8701 |
dobjFor(Remove) |
| 8702 |
{ |
| 8703 |
preCond = [touchObj, objNotWorn, roomToHoldObj] |
| 8704 |
verify() |
| 8705 |
{ |
| 8706 |
/* if we're already held, there's nothing to remove me from */ |
| 8707 |
if (isHeldBy(gActor)) |
| 8708 |
illogicalNow(&cannotRemoveHeldMsg); |
| 8709 |
} |
| 8710 |
action() { askForIobj(TakeFrom); } |
| 8711 |
} |
| 8712 |
|
| 8713 |
/* -------------------------------------------------------------------- */ |
| 8714 |
/* |
| 8715 |
* "Take from" processing |
| 8716 |
*/ |
| 8717 |
dobjFor(TakeFrom) |
| 8718 |
{ |
| 8719 |
preCond = [touchObj, objNotWorn, roomToHoldObj] |
| 8720 |
verify() |
| 8721 |
{ |
| 8722 |
/* |
| 8723 |
* we can only take something from something else if the thing |
| 8724 |
* is inside the other thing |
| 8725 |
*/ |
| 8726 |
if (gIobj != nil && !self.isIn(gIobj)) |
| 8727 |
illogicalAlready(gIobj.takeFromNotInMessage); |
| 8728 |
|
| 8729 |
/* treat this otherwise like a regular "take" */ |
| 8730 |
verifyDobjTake(); |
| 8731 |
} |
| 8732 |
check() |
| 8733 |
{ |
| 8734 |
/* apply the same checks as for a regular "take" */ |
| 8735 |
checkDobjTake(); |
| 8736 |
} |
| 8737 |
action() |
| 8738 |
{ |
| 8739 |
/* we've passed our checks, so process it as a regular "take" */ |
| 8740 |
replaceAction(Take, self); |
| 8741 |
} |
| 8742 |
} |
| 8743 |
iobjFor(TakeFrom) |
| 8744 |
{ |
| 8745 |
verify() |
| 8746 |
{ |
| 8747 |
/* check what we know about the dobj */ |
| 8748 |
if (gDobj == nil) |
| 8749 |
{ |
| 8750 |
/* |
| 8751 |
* We haven't yet resolved the direct object; check the |
| 8752 |
* tentative direct object list, and count us as |
| 8753 |
* illogical if none of the possible direct objects are |
| 8754 |
* in me. |
| 8755 |
*/ |
| 8756 |
if (gTentativeDobj.indexWhich({x: x.obj_.isIn(self)}) == nil) |
| 8757 |
illogicalAlready(takeFromNotInMessage); |
| 8758 |
else if (gTentativeDobj.indexWhich( |
| 8759 |
{x: x.obj_.isDirectlyIn(self)}) != nil) |
| 8760 |
logicalRank(150, 'directly in'); |
| 8761 |
} |
| 8762 |
else if (!gDobj.isIn(self)) |
| 8763 |
{ |
| 8764 |
/* |
| 8765 |
* the dobj isn't in me, so it's obviously not logical |
| 8766 |
* to take the dobj out of me |
| 8767 |
*/ |
| 8768 |
illogicalAlready(takeFromNotInMessage); |
| 8769 |
} |
| 8770 |
else if (gDobj.isDirectlyIn(self)) |
| 8771 |
{ |
| 8772 |
/* |
| 8773 |
* it's slightly more likely that they want to remove |
| 8774 |
* the object from its direct container |
| 8775 |
*/ |
| 8776 |
logicalRank(150, 'directly in'); |
| 8777 |
} |
| 8778 |
} |
| 8779 |
} |
| 8780 |
|
| 8781 |
/* general message for "take from" when an object isn't in me */ |
| 8782 |
takeFromNotInMessage = &takeFromNotInMsg |
| 8783 |
|
| 8784 |
/* -------------------------------------------------------------------- */ |
| 8785 |
/* |
| 8786 |
* "Drop" verb processing |
| 8787 |
*/ |
| 8788 |
dobjFor(Drop) |
| 8789 |
{ |
| 8790 |
preCond = [objHeld] |
| 8791 |
verify() |
| 8792 |
{ |
| 8793 |
/* the object must be held by the actor, at least indirectly */ |
| 8794 |
if (isIn(gActor)) |
| 8795 |
{ |
| 8796 |
/* |
| 8797 |
* it's being held, so dropping it makes sense; verify |
| 8798 |
* transfer from the current container hierarchy to the |
| 8799 |
* new one |
| 8800 |
*/ |
| 8801 |
verifyMoveTo(gActor.getDropDestination(self, nil)); |
| 8802 |
} |
| 8803 |
else |
| 8804 |
{ |
| 8805 |
/* it's not being held, so this is simply not logical */ |
| 8806 |
illogicalAlready(¬CarryingMsg); |
| 8807 |
} |
| 8808 |
} |
| 8809 |
|
| 8810 |
action() |
| 8811 |
{ |
| 8812 |
/* send the object to the actor's drop destination */ |
| 8813 |
gActor.getDropDestination(self, nil) |
| 8814 |
.receiveDrop(self, dropTypeDrop); |
| 8815 |
} |
| 8816 |
} |
| 8817 |
|
| 8818 |
/* -------------------------------------------------------------------- */ |
| 8819 |
/* |
| 8820 |
* "Put In" verb processing. Default objects cannot contain other |
| 8821 |
* objects, but they can be put in arbitrary containers. |
| 8822 |
*/ |
| 8823 |
dobjFor(PutIn) |
| 8824 |
{ |
| 8825 |
preCond = [objHeld] |
| 8826 |
verify() |
| 8827 |
{ |
| 8828 |
/* |
| 8829 |
* It makes no sense to put us in a container we're already |
| 8830 |
* directly in. (It's fine to put it in something it's |
| 8831 |
* indirectly in, though - doing so takes it out of the |
| 8832 |
* intermediate container and moves it directly into the |
| 8833 |
* indirect object.) |
| 8834 |
*/ |
| 8835 |
if (gIobj != nil && isDirectlyIn(gIobj)) |
| 8836 |
illogicalAlready(&alreadyPutInMsg); |
| 8837 |
|
| 8838 |
/* can't put in self, obviously */ |
| 8839 |
if (gIobj == self) |
| 8840 |
illogicalSelf(&cannotPutInSelfMsg); |
| 8841 |
|
| 8842 |
/* verify the transfer */ |
| 8843 |
verifyMoveTo(gIobj); |
| 8844 |
} |
| 8845 |
} |
| 8846 |
iobjFor(PutIn) |
| 8847 |
{ |
| 8848 |
preCond = [touchObj] |
| 8849 |
verify() |
| 8850 |
{ |
| 8851 |
/* by default, objects cannot be put in this object */ |
| 8852 |
illogical(¬AContainerMsg); |
| 8853 |
} |
| 8854 |
} |
| 8855 |
|
| 8856 |
/* -------------------------------------------------------------------- */ |
| 8857 |
/* |
| 8858 |
* "Put On" processing. Default objects cannot have other objects |
| 8859 |
* put on them, but they can be put on surfaces. |
| 8860 |
*/ |
| 8861 |
dobjFor(PutOn) |
| 8862 |
{ |
| 8863 |
preCond = [objHeld] |
| 8864 |
verify() |
| 8865 |
{ |
| 8866 |
/* it makes no sense to put us on a surface we're already on */ |
| 8867 |
if (gIobj != nil && isDirectlyIn(gIobj)) |
| 8868 |
illogicalAlready(&alreadyPutOnMsg); |
| 8869 |
|
| 8870 |
/* can't put on self, obviously */ |
| 8871 |
if (gIobj == self) |
| 8872 |
illogicalSelf(&cannotPutOnSelfMsg); |
| 8873 |
|
| 8874 |
/* verify the transfer */ |
| 8875 |
verifyMoveTo(gIobj); |
| 8876 |
} |
| 8877 |
} |
| 8878 |
|
| 8879 |
iobjFor(PutOn) |
| 8880 |
{ |
| 8881 |
preCond = [touchObj] |
| 8882 |
verify() |
| 8883 |
{ |
| 8884 |
/* by default, objects cannot be put on this object */ |
| 8885 |
illogical(¬ASurfaceMsg); |
| 8886 |
} |
| 8887 |
} |
| 8888 |
|
| 8889 |
/* -------------------------------------------------------------------- */ |
| 8890 |
/* |
| 8891 |
* "PutUnder" action |
| 8892 |
*/ |
| 8893 |
dobjFor(PutUnder) |
| 8894 |
{ |
| 8895 |
preCond = [objHeld] |
| 8896 |
verify() { } |
| 8897 |
} |
| 8898 |
|
| 8899 |
iobjFor(PutUnder) |
| 8900 |
{ |
| 8901 |
preCond = [touchObj] |
| 8902 |
verify() { illogical(&cannotPutUnderMsg); } |
| 8903 |
} |
| 8904 |
|
| 8905 |
/* -------------------------------------------------------------------- */ |
| 8906 |
/* |
| 8907 |
* "PutBehind" action |
| 8908 |
*/ |
| 8909 |
dobjFor(PutBehind) |
| 8910 |
{ |
| 8911 |
preCond = [objHeld] |
| 8912 |
verify() { } |
| 8913 |
} |
| 8914 |
|
| 8915 |
iobjFor(PutBehind) |
| 8916 |
{ |
| 8917 |
preCond = [touchObj] |
| 8918 |
verify() { illogical(&cannotPutBehindMsg); } |
| 8919 |
} |
| 8920 |
|
| 8921 |
/* -------------------------------------------------------------------- */ |
| 8922 |
/* |
| 8923 |
* "Wear" action |
| 8924 |
*/ |
| 8925 |
dobjFor(Wear) |
| 8926 |
{ |
| 8927 |
verify() { illogical(¬WearableMsg); } |
| 8928 |
} |
| 8929 |
|
| 8930 |
/* -------------------------------------------------------------------- */ |
| 8931 |
/* |
| 8932 |
* "Doff" action |
| 8933 |
*/ |
| 8934 |
dobjFor(Doff) |
| 8935 |
{ |
| 8936 |
verify() { illogical(¬DoffableMsg); } |
| 8937 |
} |
| 8938 |
|
| 8939 |
/* -------------------------------------------------------------------- */ |
| 8940 |
/* |
| 8941 |
* "Kiss" |
| 8942 |
*/ |
| 8943 |
dobjFor(Kiss) |
| 8944 |
{ |
| 8945 |
preCond = [touchObj] |
| 8946 |
verify() { logicalRank(50, 'not kissable'); } |
| 8947 |
action() { mainReport(&cannotKissMsg); } |
| 8948 |
} |
| 8949 |
|
| 8950 |
/* -------------------------------------------------------------------- */ |
| 8951 |
/* |
| 8952 |
* "Ask for" action |
| 8953 |
*/ |
| 8954 |
dobjFor(AskFor) |
| 8955 |
{ |
| 8956 |
verify() { illogical(¬AddressableMsg, self); } |
| 8957 |
} |
| 8958 |
|
| 8959 |
/* -------------------------------------------------------------------- */ |
| 8960 |
/* |
| 8961 |
* "Talk to" |
| 8962 |
*/ |
| 8963 |
dobjFor(TalkTo) |
| 8964 |
{ |
| 8965 |
verify() { illogical(¬AddressableMsg, self); } |
| 8966 |
} |
| 8967 |
|
| 8968 |
/* -------------------------------------------------------------------- */ |
| 8969 |
/* |
| 8970 |
* "Give to" action |
| 8971 |
*/ |
| 8972 |
dobjFor(GiveTo) |
| 8973 |
{ |
| 8974 |
preCond = [objHeld] |
| 8975 |
verify() |
| 8976 |
{ |
| 8977 |
/* |
| 8978 |
* if the intended recipient already has the object, there's |
| 8979 |
* no point in trying this |
| 8980 |
*/ |
| 8981 |
if (gIobj != nil && isHeldBy(gIobj)) |
| 8982 |
illogicalAlready(&giveAlreadyHasMsg); |
| 8983 |
|
| 8984 |
/* inherit any further processing */ |
| 8985 |
inherited(); |
| 8986 |
} |
| 8987 |
} |
| 8988 |
iobjFor(GiveTo) |
| 8989 |
{ |
| 8990 |
preCond = [touchObj] |
| 8991 |
verify() { illogical(&cannotGiveToMsg); } |
| 8992 |
} |
| 8993 |
|
| 8994 |
/* -------------------------------------------------------------------- */ |
| 8995 |
/* |
| 8996 |
* "Show to" action |
| 8997 |
*/ |
| 8998 |
dobjFor(ShowTo) |
| 8999 |
{ |
| 9000 |
preCond = [objHeld] |
| 9001 |
verify() |
| 9002 |
{ |
| 9003 |
/* it's more likely that we want to show something held */ |
| 9004 |
if (isHeldBy(gActor)) |
| 9005 |
{ |
| 9006 |
/* I'm being held - use the default logical ranking */ |
| 9007 |
} |
| 9008 |
else if (isIn(gActor)) |
| 9009 |
{ |
| 9010 |
/* |
| 9011 |
* the actor isn't hold me, but I am in the actor's |
| 9012 |
* inventory, so reduce the likelihood only slightly |
| 9013 |
*/ |
| 9014 |
logicalRank(80, 'not held'); |
| 9015 |
} |
| 9016 |
else |
| 9017 |
{ |
| 9018 |
/* |
| 9019 |
* the actor isn't even carrying me, so reduce our |
| 9020 |
* likelihood even more |
| 9021 |
*/ |
| 9022 |
logicalRank(70, 'not carried'); |
| 9023 |
} |
| 9024 |
} |
| 9025 |
check() |
| 9026 |
{ |
| 9027 |
/* |
| 9028 |
* The direct object must be visible to the indirect object |
| 9029 |
* in order for the indirect object to be shown the direct |
| 9030 |
* object. |
| 9031 |
*/ |
| 9032 |
if (!gIobj.canSee(self)) |
| 9033 |
{ |
| 9034 |
reportFailure(&actorCannotSeeMsg, gIobj, self); |
| 9035 |
exit; |
| 9036 |
} |
| 9037 |
|
| 9038 |
/* |
| 9039 |
* The actor performing the showing must also be visible to |
| 9040 |
* the indirect object, otherwise the actor wouldn't be able |
| 9041 |
* to attract the indirect object's attention to do the |
| 9042 |
* showing. |
| 9043 |
*/ |
| 9044 |
if (!gIobj.canSee(gActor)) |
| 9045 |
{ |
| 9046 |
reportFailure(&actorCannotSeeMsg, gIobj, gActor); |
| 9047 |
exit; |
| 9048 |
} |
| 9049 |
} |
| 9050 |
} |
| 9051 |
iobjFor(ShowTo) |
| 9052 |
{ |
| 9053 |
verify() { illogical(&cannotShowToMsg); } |
| 9054 |
} |
| 9055 |
|
| 9056 |
/* -------------------------------------------------------------------- */ |
| 9057 |
/* |
| 9058 |
* "Ask about" action |
| 9059 |
*/ |
| 9060 |
dobjFor(AskAbout) |
| 9061 |
{ |
| 9062 |
verify() { illogical(¬AddressableMsg, self); } |
| 9063 |
} |
| 9064 |
|
| 9065 |
/* -------------------------------------------------------------------- */ |
| 9066 |
/* |
| 9067 |
* "Tell about" action |
| 9068 |
*/ |
| 9069 |
dobjFor(TellAbout) |
| 9070 |
{ |
| 9071 |
verify() { illogical(¬AddressableMsg, self); } |
| 9072 |
} |
| 9073 |
|
| 9074 |
/* -------------------------------------------------------------------- */ |
| 9075 |
/* |
| 9076 |
* Vague "ask" and "tell" - these are for syntactically incorrect ASK |
| 9077 |
* and TELL phrasings, so that we can provide better error feedback. |
| 9078 |
*/ |
| 9079 |
dobjFor(AskVague) |
| 9080 |
{ |
| 9081 |
verify() { illogical(&askVagueMsg); } |
| 9082 |
} |
| 9083 |
dobjFor(TellVague) |
| 9084 |
{ |
| 9085 |
verify() { illogical(&tellVagueMsg); } |
| 9086 |
} |
| 9087 |
|
| 9088 |
/* -------------------------------------------------------------------- */ |
| 9089 |
/* |
| 9090 |
* "Follow" action |
| 9091 |
*/ |
| 9092 |
dobjFor(Follow) |
| 9093 |
{ |
| 9094 |
verify() |
| 9095 |
{ |
| 9096 |
/* make sure I'm followable to start with */ |
| 9097 |
if (!verifyFollowable()) |
| 9098 |
return; |
| 9099 |
|
| 9100 |
/* it makes no sense to follow myself */ |
| 9101 |
if (gActor == gDobj) |
| 9102 |
illogical(&cannotFollowSelfMsg); |
| 9103 |
|
| 9104 |
/* ask the actor to verify following the object */ |
| 9105 |
gActor.actorVerifyFollow(self); |
| 9106 |
} |
| 9107 |
action() |
| 9108 |
{ |
| 9109 |
/* ask the actor to carry out the follow */ |
| 9110 |
gActor.actorActionFollow(self); |
| 9111 |
} |
| 9112 |
} |
| 9113 |
|
| 9114 |
/* |
| 9115 |
* Verify that I'm a followable object. By default, it's not |
| 9116 |
* logical to follow an arbitrary object. If I'm not followable, |
| 9117 |
* this routine will generate an appropriate illogical() explanation |
| 9118 |
* and return nil. If I'm followable, we'll return true. |
| 9119 |
*/ |
| 9120 |
verifyFollowable() |
| 9121 |
{ |
| 9122 |
illogical(¬FollowableMsg); |
| 9123 |
return nil; |
| 9124 |
} |
| 9125 |
|
| 9126 |
/* -------------------------------------------------------------------- */ |
| 9127 |
/* |
| 9128 |
* "Attack" action. |
| 9129 |
*/ |
| 9130 |
dobjFor(Attack) |
| 9131 |
{ |
| 9132 |
preCond = [touchObj] |
| 9133 |
verify() { } |
| 9134 |
action() { mainReport(&uselessToAttackMsg); } |
| 9135 |
} |
| 9136 |
|
| 9137 |
/* -------------------------------------------------------------------- */ |
| 9138 |
/* |
| 9139 |
* "Attack with" action - attack with (presumably) a weapon. |
| 9140 |
*/ |
| 9141 |
dobjFor(AttackWith) |
| 9142 |
{ |
| 9143 |
preCond = [touchObj] |
| 9144 |
|
| 9145 |
/* |
| 9146 |
* it makes as much sense to attack any object as any other, but |
| 9147 |
* by default attacking an object has no effect |
| 9148 |
*/ |
| 9149 |
verify() { } |
| 9150 |
action() { mainReport(&uselessToAttackMsg); } |
| 9151 |
} |
| 9152 |
iobjFor(AttackWith) |
| 9153 |
{ |
| 9154 |
preCond = [objHeld] |
| 9155 |
verify() { illogical(¬AWeaponMsg); } |
| 9156 |
} |
| 9157 |
|
| 9158 |
/* -------------------------------------------------------------------- */ |
| 9159 |
/* |
| 9160 |
* "Throw" action. By default, we'll simply re-route this to a |
| 9161 |
* "throw at" action. Objects that can meaningfully be thrown |
| 9162 |
* without any specific target can override this. |
| 9163 |
* |
| 9164 |
* Note that we don't apply an preconditions or verification, since |
| 9165 |
* we don't really do anything with the action ourselves. If an |
| 9166 |
* object overrides this, it should add any preconditions and |
| 9167 |
* verifications that are appropriate. |
| 9168 |
*/ |
| 9169 |
dobjFor(Throw) |
| 9170 |
{ |
| 9171 |
verify() { } |
| 9172 |
action() { askForIobj(ThrowAt); } |
| 9173 |
} |
| 9174 |
|
| 9175 |
/* -------------------------------------------------------------------- */ |
| 9176 |
/* |
| 9177 |
* "Throw <direction>". By default, we simply reject this and |
| 9178 |
* explain that the command to use is THROW AT. With one exception: |
| 9179 |
* we treat THROW <down> as equivalent to THROW AT FLOOR, and use the |
| 9180 |
* default library message for that command instead. |
| 9181 |
*/ |
| 9182 |
dobjFor(ThrowDir) |
| 9183 |
{ |
| 9184 |
verify() |
| 9185 |
{ |
| 9186 |
if (gAction.getDirection() == downDirection) |
| 9187 |
illogicalAlready(&shouldNotThrowAtFloorMsg); |
| 9188 |
} |
| 9189 |
action() |
| 9190 |
{ |
| 9191 |
/* |
| 9192 |
* explain that we should use THROW AT (or DROP, in the case |
| 9193 |
* of THROW DOWN) |
| 9194 |
*/ |
| 9195 |
reportFailure(gAction.getDirection() == downDirection |
| 9196 |
? &shouldNotThrowAtFloorMsg |
| 9197 |
: &dontThrowDirMsg); |
| 9198 |
} |
| 9199 |
} |
| 9200 |
|
| 9201 |
|
| 9202 |
/* -------------------------------------------------------------------- */ |
| 9203 |
/* |
| 9204 |
* "Throw at" action |
| 9205 |
*/ |
| 9206 |
dobjFor(ThrowAt) |
| 9207 |
{ |
| 9208 |
preCond = [objHeld] |
| 9209 |
verify() |
| 9210 |
{ |
| 9211 |
/* by default, we can throw something if we can drop it */ |
| 9212 |
verifyMoveTo(gActor.getDropDestination(self, nil)); |
| 9213 |
|
| 9214 |
/* can't throw something at itself */ |
| 9215 |
if (gIobj == self) |
| 9216 |
illogicalSelf(&cannotThrowAtSelfMsg); |
| 9217 |
|
| 9218 |
/* can't throw dobj at iobj if iobj is in dobj */ |
| 9219 |
if (gIobj != nil && gIobj.isIn(self)) |
| 9220 |
illogicalNow(&cannotThrowAtContentsMsg); |
| 9221 |
} |
| 9222 |
action() |
| 9223 |
{ |
| 9224 |
/* |
| 9225 |
* process a 'throw' operation, finishing with hitting the |
| 9226 |
* target if we get that far |
| 9227 |
*/ |
| 9228 |
processThrow(gIobj, &throwTargetHitWith); |
| 9229 |
} |
| 9230 |
} |
| 9231 |
iobjFor(ThrowAt) |
| 9232 |
{ |
| 9233 |
/* by default, anything can be a target */ |
| 9234 |
verify() { } |
| 9235 |
} |
| 9236 |
|
| 9237 |
/* |
| 9238 |
* Process a 'throw' command. This is common handling that can be |
| 9239 |
* used for any sort of throwing (throw at, throw to, throw in, |
| 9240 |
* etc). The projectile is self, and 'target' is the thing we're |
| 9241 |
* throwing at or to. 'hitProp' is the property to call on 'target' |
| 9242 |
* if we reach the target. |
| 9243 |
*/ |
| 9244 |
processThrow(target, hitProp) |
| 9245 |
{ |
| 9246 |
local path; |
| 9247 |
local stat; |
| 9248 |
|
| 9249 |
/* get the throw path */ |
| 9250 |
path = getThrowPathTo(target); |
| 9251 |
|
| 9252 |
/* traverse the path with throwViaPath */ |
| 9253 |
stat = traversePath( |
| 9254 |
path, {obj, op: throwViaPath(obj, op, target, path)}); |
| 9255 |
|
| 9256 |
/* |
| 9257 |
* If we made it all the way through the path without complaint, |
| 9258 |
* process hitting the target. If something along the path |
| 9259 |
* finished the traversal (by returning nil), we'll consider the |
| 9260 |
* action complete - the object along that path that canceled |
| 9261 |
* the traversal is responsible for having displayed an |
| 9262 |
* appropriate message. |
| 9263 |
*/ |
| 9264 |
if (stat) |
| 9265 |
target.(hitProp)(self, path); |
| 9266 |
} |
| 9267 |
|
| 9268 |
/* |
| 9269 |
* Carry out a 'throw' operation along a path. 'self' is the |
| 9270 |
* projectile; 'obj' is the path element being traversed, and 'op' is |
| 9271 |
* the operation being used to traverse the element. 'target' is the |
| 9272 |
* object we're throwing 'self' at. 'path' is the projectile's full |
| 9273 |
* path (in getThrowPathTo format). |
| 9274 |
* |
| 9275 |
* By default, we'll use the standard canThrowViaPath handling (which |
| 9276 |
* invokes the even more basic checkThrowViaPath) to determine if we |
| 9277 |
* can make this traversal. If so, we'll proceed with the throw; |
| 9278 |
* otherwise, we'll stop the throw by calling stopThrowViaPath() and |
| 9279 |
* returning the result. |
| 9280 |
*/ |
| 9281 |
throwViaPath(obj, op, target, path) |
| 9282 |
{ |
| 9283 |
/* |
| 9284 |
* By default, if we can throw the object through self, return |
| 9285 |
* true to allow the caller to proceed; otherwise, describe the |
| 9286 |
* object as hitting this element and falling to the appropriate |
| 9287 |
* point. |
| 9288 |
*/ |
| 9289 |
if (obj.canThrowViaPath(self, target, op)) |
| 9290 |
{ |
| 9291 |
/* no objection - allow the traversal to proceed */ |
| 9292 |
return true; |
| 9293 |
} |
| 9294 |
else |
| 9295 |
{ |
| 9296 |
/* can't do it - stop the throw and return the result */ |
| 9297 |
return obj.stopThrowViaPath(self, path); |
| 9298 |
} |
| 9299 |
} |
| 9300 |
|
| 9301 |
/* |
| 9302 |
* Process the effect of throwing the object 'projectile' at the |
| 9303 |
* target 'self'. By default, we'll move the projectile to the |
| 9304 |
* target's drop location, and display a message saying that there |
| 9305 |
* was no effect other than the projectile dropping to the floor (or |
| 9306 |
* whatever it drops to). 'path' is the path we took to reach the |
| 9307 |
* target, as returned from getThrowPathTo(); this lets us determine |
| 9308 |
* how we approached the target. |
| 9309 |
*/ |
| 9310 |
throwTargetHitWith(projectile, path) |
| 9311 |
{ |
| 9312 |
/* |
| 9313 |
* figure out where we fall to when we hit this object, then send |
| 9314 |
* the object being thrown to that location |
| 9315 |
*/ |
| 9316 |
getHitFallDestination(projectile, path) |
| 9317 |
.receiveDrop(projectile, new DropTypeThrow(self, path)); |
| 9318 |
} |
| 9319 |
|
| 9320 |
/* |
| 9321 |
* Stop a 'throw' operation along a path. 'self' is the object in |
| 9322 |
* the path that is impassable by 'projectile' according to |
| 9323 |
* canThrowViaPath(), and 'path' is the getThrowPathTo-style path of |
| 9324 |
* objects traversed in the projectile's trajectory. |
| 9325 |
* |
| 9326 |
* The return value is taken as a path traversal continuation |
| 9327 |
* indicator: nil means to stop the traversal, which is to say that |
| 9328 |
* the 'throw' command finishes here. If we don't really want to |
| 9329 |
* stop the traversal, we can return 'true' to let the traversal |
| 9330 |
* continue. |
| 9331 |
* |
| 9332 |
* By default, we'll stop the throw by doing the same thing we would |
| 9333 |
* have done if we had successfully thrown the object at 'self' - the |
| 9334 |
* whole reason we're stopping the throw is that we're in the way, so |
| 9335 |
* the effect is the same as though we were the intended target to |
| 9336 |
* begin with. This is the normal handling when we can't throw |
| 9337 |
* through 'obj' because 'obj' is a closed container or is otherwise |
| 9338 |
* impassable by self when thrown. This can be overridden to provide |
| 9339 |
* different handling if needed. |
| 9340 |
*/ |
| 9341 |
stopThrowViaPath(projectile, path) |
| 9342 |
{ |
| 9343 |
/* we've been hit */ |
| 9344 |
throwTargetHitWith(projectile, path); |
| 9345 |
|
| 9346 |
/* tell the caller to stop the traversal */ |
| 9347 |
return nil; |
| 9348 |
} |
| 9349 |
|
| 9350 |
/* |
| 9351 |
* Get the "hit-and-fall" destination for a thrown object. This is |
| 9352 |
* called when we interrupt a thrown object's trajectory because |
| 9353 |
* we're in the way of its trajectory. |
| 9354 |
* |
| 9355 |
* For example, if the actor is inside a cage, and tries to throw a |
| 9356 |
* projectile at an object outside the cage, and the cage blocks the |
| 9357 |
* projectile's passage, then this routine is called on the cage to |
| 9358 |
* determine where the projectile ends up. The projectile's ultimate |
| 9359 |
* destination is the hit-and-fall destination for the cage: it's |
| 9360 |
* where the project ends up when it hits me and then falls to the |
| 9361 |
* ground, its trajectory cut short. |
| 9362 |
* |
| 9363 |
* 'thrownObj' is the projectile thrown, 'self' is the target object, |
| 9364 |
* and 'path' is the path the projectile took to reach us. The path |
| 9365 |
* is of the form returned by getThrowPathTo(). Note that the path |
| 9366 |
* could extend beyond 'self', because the original target might have |
| 9367 |
* been a different object - we could simply have interrupted the |
| 9368 |
* projectile's course. |
| 9369 |
*/ |
| 9370 |
getHitFallDestination(thrownObj, path) |
| 9371 |
{ |
| 9372 |
local prvCont; |
| 9373 |
local prvOp; |
| 9374 |
local idx; |
| 9375 |
local dest; |
| 9376 |
local common; |
| 9377 |
|
| 9378 |
/* find myself in the path */ |
| 9379 |
idx = path.indexOf(self); |
| 9380 |
|
| 9381 |
/* |
| 9382 |
* get the container traversed just before us in the path (it's |
| 9383 |
* two positions before us in the path list, because the path |
| 9384 |
* consists of alternating objects and operators) |
| 9385 |
*/ |
| 9386 |
prvCont = path[idx - 2]; |
| 9387 |
|
| 9388 |
/* get the operation that got from the last container to us */ |
| 9389 |
prvOp = path[idx - 1]; |
| 9390 |
|
| 9391 |
/* |
| 9392 |
* If the previous container is within us, we're throwing from |
| 9393 |
* inside to the outside, so the object falls within me; |
| 9394 |
* otherwise, the object bounces off the outside and falls |
| 9395 |
* outside me. |
| 9396 |
* |
| 9397 |
* If the projectile traversed *inward* from the previous item in |
| 9398 |
* the path, then we should simply land in the drop destination |
| 9399 |
* of the previous item itself, since we're coming in through |
| 9400 |
* that item. If the previous item is a peer of ours, though, we |
| 9401 |
* traversed *across* the item, so land in our common direct |
| 9402 |
* container. |
| 9403 |
* |
| 9404 |
* Note that in certain cases, the previous "container" will be |
| 9405 |
* the projectile itself; this happens when the thrower is |
| 9406 |
* throwing the object at itself (as in "throw it at me"). In |
| 9407 |
* these cases, we'll assume that the the thrower is *holding* |
| 9408 |
* rather than containing the object, in which case the object |
| 9409 |
* isn't actually inside the thrower, in which case we want to |
| 9410 |
* use the location's drop destination. |
| 9411 |
*/ |
| 9412 |
if (prvCont == thrownObj) |
| 9413 |
{ |
| 9414 |
/* throwing object at self - land in my location's drop dest */ |
| 9415 |
dest = (location != nil |
| 9416 |
? location.getDropDestination(thrownObj, path) |
| 9417 |
: self); |
| 9418 |
} |
| 9419 |
else if (prvCont.isIn(self)) |
| 9420 |
{ |
| 9421 |
/* throwing from within - land in my own drop destination */ |
| 9422 |
dest = getDropDestination(thrownObj, path); |
| 9423 |
} |
| 9424 |
else if (prvOp == PathPeer |
| 9425 |
&& (common = getCommonDirectContainer(prvCont)) != nil) |
| 9426 |
{ |
| 9427 |
/* |
| 9428 |
* We're coming over from a peer, and we found a container in |
| 9429 |
* common with the peer. Land in the common container's drop |
| 9430 |
* destination. |
| 9431 |
*/ |
| 9432 |
dest = common.getDropDestination(thrownObj, path); |
| 9433 |
} |
| 9434 |
else |
| 9435 |
{ |
| 9436 |
/* |
| 9437 |
* Either we're coming in from a container, or we weren't |
| 9438 |
* able to find a container in common with the peer. In |
| 9439 |
* either case, the projectile lands in the 'drop' |
| 9440 |
* destination of the previous object in the path. |
| 9441 |
*/ |
| 9442 |
dest = prvCont.getDropDestination(thrownObj, path); |
| 9443 |
} |
| 9444 |
|
| 9445 |
/* |
| 9446 |
* Whatever we found, give the destination itself a chance to |
| 9447 |
* make any necessary adjustments. |
| 9448 |
*/ |
| 9449 |
return dest.adjustThrowDestination(thrownObj, path); |
| 9450 |
} |
| 9451 |
|
| 9452 |
/* -------------------------------------------------------------------- */ |
| 9453 |
/* |
| 9454 |
* "Throw to" action |
| 9455 |
*/ |
| 9456 |
dobjFor(ThrowTo) |
| 9457 |
{ |
| 9458 |
preCond = [objHeld] |
| 9459 |
verify() |
| 9460 |
{ |
| 9461 |
/* |
| 9462 |
* by default, we can throw an object to someone if we can |
| 9463 |
* throw it at them |
| 9464 |
*/ |
| 9465 |
verifyDobjThrowAt(); |
| 9466 |
} |
| 9467 |
action() |
| 9468 |
{ |
| 9469 |
/* |
| 9470 |
* process a 'throw' operation, finishing with the target |
| 9471 |
* trying to catch the object if we get that far |
| 9472 |
*/ |
| 9473 |
processThrow(gIobj, &throwTargetCatch); |
| 9474 |
} |
| 9475 |
} |
| 9476 |
|
| 9477 |
iobjFor(ThrowTo) |
| 9478 |
{ |
| 9479 |
verify() |
| 9480 |
{ |
| 9481 |
/* by default, we don't want to catch anything */ |
| 9482 |
illogical(&cannotThrowToMsg); |
| 9483 |
} |
| 9484 |
} |
| 9485 |
|
| 9486 |
/* |
| 9487 |
* Process the effect of throwing the object 'obj' to the catcher |
| 9488 |
* 'self'. By default, we'll simply move the projectile into self. |
| 9489 |
*/ |
| 9490 |
throwTargetCatch(obj, path) |
| 9491 |
{ |
| 9492 |
/* take the object */ |
| 9493 |
obj.moveInto(self); |
| 9494 |
|
| 9495 |
/* generate the default message if we successfully took the object */ |
| 9496 |
if (obj.isDirectlyIn(self)) |
| 9497 |
mainReport(&throwCatchMsg, obj, self); |
| 9498 |
} |
| 9499 |
|
| 9500 |
/* -------------------------------------------------------------------- */ |
| 9501 |
/* |
| 9502 |
* "Dig" action - by default, simply re-reoute to dig-with, since we |
| 9503 |
* generally need a digging implement to dig in anything. Some |
| 9504 |
* objects might want to override this to allow digging without any |
| 9505 |
* implement; a sandy beach, for example, might allow digging in the |
| 9506 |
* sand without a shovel. |
| 9507 |
*/ |
| 9508 |
dobjFor(Dig) |
| 9509 |
{ |
| 9510 |
preCond = [touchObj] |
| 9511 |
verify() { } |
| 9512 |
action() { askForIobj(DigWith); } |
| 9513 |
} |
| 9514 |
|
| 9515 |
/* -------------------------------------------------------------------- */ |
| 9516 |
/* |
| 9517 |
* "DigWith" action |
| 9518 |
*/ |
| 9519 |
dobjFor(DigWith) |
| 9520 |
{ |
| 9521 |
preCond = [touchObj] |
| 9522 |
verify() { illogical(&cannotDigMsg); } |
| 9523 |
} |
| 9524 |
iobjFor(DigWith) |
| 9525 |
{ |
| 9526 |
preCond = [objHeld] |
| 9527 |
verify() { illogical(&cannotDigWithMsg); } |
| 9528 |
} |
| 9529 |
|
| 9530 |
/* -------------------------------------------------------------------- */ |
| 9531 |
/* |
| 9532 |
* "jump over" |
| 9533 |
*/ |
| 9534 |
dobjFor(JumpOver) |
| 9535 |
{ |
| 9536 |
verify() { illogical(&cannotJumpOverMsg); } |
| 9537 |
} |
| 9538 |
|
| 9539 |
/* -------------------------------------------------------------------- */ |
| 9540 |
/* |
| 9541 |
* "jump off" |
| 9542 |
*/ |
| 9543 |
dobjFor(JumpOff) |
| 9544 |
{ |
| 9545 |
verify() { illogical(&cannotJumpOffMsg); } |
| 9546 |
} |
| 9547 |
|
| 9548 |
/* -------------------------------------------------------------------- */ |
| 9549 |
/* |
| 9550 |
* "Push" action |
| 9551 |
*/ |
| 9552 |
dobjFor(Push) |
| 9553 |
{ |
| 9554 |
preCond = [touchObj] |
| 9555 |
verify() { logicalRank(50, 'not pushable'); } |
| 9556 |
action() { reportFailure(&pushNoEffectMsg); } |
| 9557 |
} |
| 9558 |
|
| 9559 |
/* -------------------------------------------------------------------- */ |
| 9560 |
/* |
| 9561 |
* "Pull" action |
| 9562 |
*/ |
| 9563 |
dobjFor(Pull) |
| 9564 |
{ |
| 9565 |
preCond = [touchObj] |
| 9566 |
verify() { logicalRank(50, 'not pullable'); } |
| 9567 |
action() { reportFailure(&pullNoEffectMsg); } |
| 9568 |
} |
| 9569 |
|
| 9570 |
/* -------------------------------------------------------------------- */ |
| 9571 |
/* |
| 9572 |
* "Move" action |
| 9573 |
*/ |
| 9574 |
dobjFor(Move) |
| 9575 |
{ |
| 9576 |
preCond = [touchObj] |
| 9577 |
verify() { logicalRank(50, 'not movable'); } |
| 9578 |
action() { reportFailure(&moveNoEffectMsg); } |
| 9579 |
} |
| 9580 |
|
| 9581 |
/* -------------------------------------------------------------------- */ |
| 9582 |
/* |
| 9583 |
* "MoveWith" action |
| 9584 |
*/ |
| 9585 |
dobjFor(MoveWith) |
| 9586 |
{ |
| 9587 |
preCond = [iobjTouchObj] |
| 9588 |
verify() { logicalRank(50, 'not movable'); } |
| 9589 |
action() { reportFailure(&moveNoEffectMsg); } |
| 9590 |
} |
| 9591 |
iobjFor(MoveWith) |
| 9592 |
{ |
| 9593 |
preCond = [objHeld] |
| 9594 |
verify() { illogical(&cannotMoveWithMsg); } |
| 9595 |
} |
| 9596 |
|
| 9597 |
/* -------------------------------------------------------------------- */ |
| 9598 |
/* |
| 9599 |
* "MoveTo" action |
| 9600 |
*/ |
| 9601 |
dobjFor(MoveTo) |
| 9602 |
{ |
| 9603 |
preCond = [touchObj] |
| 9604 |
verify() { logicalRank(50, 'not movable'); } |
| 9605 |
action() { reportFailure(&moveToNoEffectMsg); } |
| 9606 |
} |
| 9607 |
|
| 9608 |
/* -------------------------------------------------------------------- */ |
| 9609 |
/* |
| 9610 |
* "Turn" action |
| 9611 |
*/ |
| 9612 |
dobjFor(Turn) |
| 9613 |
{ |
| 9614 |
preCond = [touchObj] |
| 9615 |
verify() { illogical(&cannotTurnMsg); } |
| 9616 |
} |
| 9617 |
|
| 9618 |
/* -------------------------------------------------------------------- */ |
| 9619 |
/* |
| 9620 |
* "Turn to" action |
| 9621 |
*/ |
| 9622 |
dobjFor(TurnTo) |
| 9623 |
{ |
| 9624 |
preCond = [touchObj] |
| 9625 |
verify() { illogical(&cannotTurnMsg); } |
| 9626 |
} |
| 9627 |
|
| 9628 |
/* -------------------------------------------------------------------- */ |
| 9629 |
/* |
| 9630 |
* "TurnWith" action |
| 9631 |
*/ |
| 9632 |
dobjFor(TurnWith) |
| 9633 |
{ |
| 9634 |
preCond = [iobjTouchObj] |
| 9635 |
verify() { illogical(&cannotTurnMsg); } |
| 9636 |
} |
| 9637 |
iobjFor(TurnWith) |
| 9638 |
{ |
| 9639 |
preCond = [objHeld] |
| 9640 |
verify() { illogical(&cannotTurnWithMsg); } |
| 9641 |
} |
| 9642 |
|
| 9643 |
/* -------------------------------------------------------------------- */ |
| 9644 |
/* |
| 9645 |
* "Set" action |
| 9646 |
*/ |
| 9647 |
dobjFor(Set) |
| 9648 |
{ |
| 9649 |
verify() { } |
| 9650 |
action() { askForIobj(PutOn); } |
| 9651 |
} |
| 9652 |
|
| 9653 |
/* -------------------------------------------------------------------- */ |
| 9654 |
/* |
| 9655 |
* "SetTo" action |
| 9656 |
*/ |
| 9657 |
dobjFor(SetTo) |
| 9658 |
{ |
| 9659 |
preCond = [touchObj] |
| 9660 |
verify() { illogical(&cannotSetToMsg); } |
| 9661 |
} |
| 9662 |
|
| 9663 |
/* -------------------------------------------------------------------- */ |
| 9664 |
/* |
| 9665 |
* "Consult" action |
| 9666 |
*/ |
| 9667 |
dobjFor(Consult) |
| 9668 |
{ |
| 9669 |
preCond = [touchObj] |
| 9670 |
verify() { illogical(&cannotConsultMsg); } |
| 9671 |
} |
| 9672 |
|
| 9673 |
dobjFor(ConsultAbout) |
| 9674 |
{ |
| 9675 |
preCond = [touchObj] |
| 9676 |
verify() { illogical(&cannotConsultMsg); } |
| 9677 |
} |
| 9678 |
|
| 9679 |
/* -------------------------------------------------------------------- */ |
| 9680 |
/* |
| 9681 |
* "Type on" action |
| 9682 |
*/ |
| 9683 |
dobjFor(TypeOn) |
| 9684 |
{ |
| 9685 |
preCond = [touchObj] |
| 9686 |
verify() { illogical(&cannotTypeOnMsg); } |
| 9687 |
|
| 9688 |
/* |
| 9689 |
* if the verifier is overridden to allow typing on this object, |
| 9690 |
* by default just ask for a missing literal phrase, since we |
| 9691 |
* need something to type on this object |
| 9692 |
*/ |
| 9693 |
action() { askForLiteral(TypeLiteralOn); } |
| 9694 |
} |
| 9695 |
|
| 9696 |
/* |
| 9697 |
* "Type <literal> on" action |
| 9698 |
*/ |
| 9699 |
dobjFor(TypeLiteralOn) |
| 9700 |
{ |
| 9701 |
preCond = [touchObj] |
| 9702 |
verify() { illogical(&cannotTypeOnMsg); } |
| 9703 |
} |
| 9704 |
|
| 9705 |
/* -------------------------------------------------------------------- */ |
| 9706 |
/* |
| 9707 |
* "Enter on" action |
| 9708 |
*/ |
| 9709 |
dobjFor(EnterOn) |
| 9710 |
{ |
| 9711 |
preCond = [touchObj] |
| 9712 |
verify() { illogical(&cannotEnterOnMsg); } |
| 9713 |
} |
| 9714 |
|
| 9715 |
/* -------------------------------------------------------------------- */ |
| 9716 |
/* |
| 9717 |
* "Switch" action |
| 9718 |
*/ |
| 9719 |
dobjFor(Switch) |
| 9720 |
{ |
| 9721 |
preCond = [touchObj] |
| 9722 |
verify() { illogical(&cannotSwitchMsg); } |
| 9723 |
} |
| 9724 |
|
| 9725 |
/* -------------------------------------------------------------------- */ |
| 9726 |
/* |
| 9727 |
* "Flip" action |
| 9728 |
*/ |
| 9729 |
dobjFor(Flip) |
| 9730 |
{ |
| 9731 |
preCond = [touchObj] |
| 9732 |
verify() { illogical(&cannotFlipMsg); } |
| 9733 |
} |
| 9734 |
|
| 9735 |
/* -------------------------------------------------------------------- */ |
| 9736 |
/* |
| 9737 |
* "TurnOn" action |
| 9738 |
*/ |
| 9739 |
dobjFor(TurnOn) |
| 9740 |
{ |
| 9741 |
preCond = [touchObj] |
| 9742 |
verify() { illogical(&cannotTurnOnMsg); } |
| 9743 |
} |
| 9744 |
|
| 9745 |
/* -------------------------------------------------------------------- */ |
| 9746 |
/* |
| 9747 |
* "TurnOff" action |
| 9748 |
*/ |
| 9749 |
dobjFor(TurnOff) |
| 9750 |
{ |
| 9751 |
preCond = [touchObj] |
| 9752 |
verify() { illogical(&cannotTurnOffMsg); } |
| 9753 |
} |
| 9754 |
|
| 9755 |
/* -------------------------------------------------------------------- */ |
| 9756 |
/* |
| 9757 |
* "Light" action. By default, we treat this as equivalent to |
| 9758 |
* "burn". |
| 9759 |
*/ |
| 9760 |
dobjFor(Light) asDobjFor(Burn) |
| 9761 |
|
| 9762 |
/* -------------------------------------------------------------------- */ |
| 9763 |
/* |
| 9764 |
* "Burn". By default, we ask for something to use to burn the |
| 9765 |
* object, since most objects are not self-igniting. |
| 9766 |
*/ |
| 9767 |
dobjFor(Burn) |
| 9768 |
{ |
| 9769 |
preCond = [touchObj] |
| 9770 |
verify() |
| 9771 |
{ |
| 9772 |
/* |
| 9773 |
* although we can in principle burn anything, most things |
| 9774 |
* are unlikely choices for burning |
| 9775 |
*/ |
| 9776 |
logicalRank(50, 'not flammable'); |
| 9777 |
} |
| 9778 |
action() |
| 9779 |
{ |
| 9780 |
/* rephrase this as a "burn with" command */ |
| 9781 |
askForIobj(BurnWith); |
| 9782 |
} |
| 9783 |
} |
| 9784 |
|
| 9785 |
/* -------------------------------------------------------------------- */ |
| 9786 |
/* |
| 9787 |
* "Burn with" |
| 9788 |
*/ |
| 9789 |
dobjFor(BurnWith) |
| 9790 |
{ |
| 9791 |
preCond = [touchObj] |
| 9792 |
verify() { illogical(&cannotBurnMsg); } |
| 9793 |
} |
| 9794 |
iobjFor(BurnWith) |
| 9795 |
{ |
| 9796 |
preCond = [objHeld] |
| 9797 |
verify() { illogical(&cannotBurnWithMsg); } |
| 9798 |
} |
| 9799 |
|
| 9800 |
/* -------------------------------------------------------------------- */ |
| 9801 |
/* |
| 9802 |
* "Extinguish" |
| 9803 |
*/ |
| 9804 |
dobjFor(Extinguish) |
| 9805 |
{ |
| 9806 |
preCond = [touchObj] |
| 9807 |
verify() { illogical(&cannotExtinguishMsg); } |
| 9808 |
} |
| 9809 |
|
| 9810 |
/* -------------------------------------------------------------------- */ |
| 9811 |
/* |
| 9812 |
* "AttachTo" action |
| 9813 |
*/ |
| 9814 |
dobjFor(AttachTo) |
| 9815 |
{ |
| 9816 |
preCond = [touchObj] |
| 9817 |
verify() { illogical(&cannotAttachMsg); } |
| 9818 |
} |
| 9819 |
iobjFor(AttachTo) |
| 9820 |
{ |
| 9821 |
preCond = [touchObj] |
| 9822 |
verify() { illogical(&cannotAttachToMsg); } |
| 9823 |
} |
| 9824 |
|
| 9825 |
/* -------------------------------------------------------------------- */ |
| 9826 |
/* |
| 9827 |
* "DetachFrom" action |
| 9828 |
*/ |
| 9829 |
dobjFor(DetachFrom) |
| 9830 |
{ |
| 9831 |
preCond = [touchObj] |
| 9832 |
verify() { illogical(&cannotDetachMsg); } |
| 9833 |
} |
| 9834 |
iobjFor(DetachFrom) |
| 9835 |
{ |
| 9836 |
preCond = [touchObj] |
| 9837 |
verify() { illogical(&cannotDetachFromMsg); } |
| 9838 |
} |
| 9839 |
|
| 9840 |
/* -------------------------------------------------------------------- */ |
| 9841 |
/* |
| 9842 |
* "Detach" action |
| 9843 |
*/ |
| 9844 |
dobjFor(Detach) |
| 9845 |
{ |
| 9846 |
preCond = [touchObj] |
| 9847 |
verify() { illogical(&cannotDetachMsg); } |
| 9848 |
} |
| 9849 |
|
| 9850 |
/* -------------------------------------------------------------------- */ |
| 9851 |
/* |
| 9852 |
* "Break" action |
| 9853 |
*/ |
| 9854 |
dobjFor(Break) |
| 9855 |
{ |
| 9856 |
preCond = [touchObj] |
| 9857 |
verify() { illogical(&shouldNotBreakMsg); } |
| 9858 |
} |
| 9859 |
|
| 9860 |
/* -------------------------------------------------------------------- */ |
| 9861 |
/* |
| 9862 |
* "Cut with" action |
| 9863 |
*/ |
| 9864 |
dobjFor(CutWith) |
| 9865 |
{ |
| 9866 |
preCond = [touchObj] |
| 9867 |
verify() { logicalRank(50, 'not cuttable'); } |
| 9868 |
action() { reportFailure(&cutNoEffectMsg); } |
| 9869 |
} |
| 9870 |
|
| 9871 |
iobjFor(CutWith) |
| 9872 |
{ |
| 9873 |
preCond = [touchObj] |
| 9874 |
verify() { illogical(&cannotCutWithMsg); } |
| 9875 |
} |
| 9876 |
|
| 9877 |
/* -------------------------------------------------------------------- */ |
| 9878 |
/* |
| 9879 |
* "Climb", "climb up", and "climb down" actions |
| 9880 |
*/ |
| 9881 |
dobjFor(Climb) |
| 9882 |
{ |
| 9883 |
preCond = [touchObj] |
| 9884 |
verify() { illogical(&cannotClimbMsg); } |
| 9885 |
} |
| 9886 |
|
| 9887 |
dobjFor(ClimbUp) |
| 9888 |
{ |
| 9889 |
preCond = [touchObj] |
| 9890 |
verify() { illogical(&cannotClimbMsg); } |
| 9891 |
} |
| 9892 |
|
| 9893 |
dobjFor(ClimbDown) |
| 9894 |
{ |
| 9895 |
preCond = [touchObj] |
| 9896 |
verify() { illogical(&cannotClimbMsg); } |
| 9897 |
} |
| 9898 |
|
| 9899 |
/* -------------------------------------------------------------------- */ |
| 9900 |
/* |
| 9901 |
* "Open" action |
| 9902 |
*/ |
| 9903 |
dobjFor(Open) |
| 9904 |
{ |
| 9905 |
preCond = [touchObj] |
| 9906 |
verify() { illogical(&cannotOpenMsg); } |
| 9907 |
} |
| 9908 |
|
| 9909 |
/* -------------------------------------------------------------------- */ |
| 9910 |
/* |
| 9911 |
* "Close" action |
| 9912 |
*/ |
| 9913 |
dobjFor(Close) |
| 9914 |
{ |
| 9915 |
preCond = [touchObj] |
| 9916 |
verify() { illogical(&cannotCloseMsg); } |
| 9917 |
} |
| 9918 |
|
| 9919 |
/* -------------------------------------------------------------------- */ |
| 9920 |
/* |
| 9921 |
* "Lock" action |
| 9922 |
*/ |
| 9923 |
dobjFor(Lock) |
| 9924 |
{ |
| 9925 |
preCond = [touchObj] |
| 9926 |
verify() { illogical(&cannotLockMsg); } |
| 9927 |
} |
| 9928 |
|
| 9929 |
/* -------------------------------------------------------------------- */ |
| 9930 |
/* |
| 9931 |
* "Unlock" action |
| 9932 |
*/ |
| 9933 |
dobjFor(Unlock) |
| 9934 |
{ |
| 9935 |
preCond = [touchObj] |
| 9936 |
verify() { illogical(&cannotUnlockMsg); } |
| 9937 |
} |
| 9938 |
|
| 9939 |
/* -------------------------------------------------------------------- */ |
| 9940 |
/* |
| 9941 |
* "LockWith" action |
| 9942 |
*/ |
| 9943 |
dobjFor(LockWith) |
| 9944 |
{ |
| 9945 |
preCond = [touchObj] |
| 9946 |
verify() { illogical(&cannotLockMsg); } |
| 9947 |
} |
| 9948 |
iobjFor(LockWith) |
| 9949 |
{ |
| 9950 |
preCond = [objHeld] |
| 9951 |
verify() { illogical(&cannotLockWithMsg); } |
| 9952 |
} |
| 9953 |
|
| 9954 |
/* -------------------------------------------------------------------- */ |
| 9955 |
/* |
| 9956 |
* "UnlockWith" action |
| 9957 |
*/ |
| 9958 |
dobjFor(UnlockWith) |
| 9959 |
{ |
| 9960 |
preCond = [touchObj] |
| 9961 |
verify() { illogical(&cannotUnlockMsg); } |
| 9962 |
} |
| 9963 |
iobjFor(UnlockWith) |
| 9964 |
{ |
| 9965 |
preCond = [objHeld] |
| 9966 |
verify() { illogical(&cannotUnlockWithMsg); } |
| 9967 |
} |
| 9968 |
|
| 9969 |
/* -------------------------------------------------------------------- */ |
| 9970 |
/* |
| 9971 |
* "Eat" action |
| 9972 |
*/ |
| 9973 |
dobjFor(Eat) |
| 9974 |
{ |
| 9975 |
/* |
| 9976 |
* generally, an object must be held to be eaten; this can be |
| 9977 |
* overridden on an object-by-object basis as desired |
| 9978 |
*/ |
| 9979 |
preCond = [objHeld] |
| 9980 |
verify() { illogical(&cannotEatMsg); } |
| 9981 |
} |
| 9982 |
|
| 9983 |
/* -------------------------------------------------------------------- */ |
| 9984 |
/* |
| 9985 |
* "Drink" action |
| 9986 |
*/ |
| 9987 |
dobjFor(Drink) |
| 9988 |
{ |
| 9989 |
preCond = [objHeld] |
| 9990 |
verify() { illogical(&cannotDrinkMsg); } |
| 9991 |
} |
| 9992 |
|
| 9993 |
/* -------------------------------------------------------------------- */ |
| 9994 |
/* |
| 9995 |
* "Pour" |
| 9996 |
*/ |
| 9997 |
dobjFor(Pour) |
| 9998 |
{ |
| 9999 |
preCond = [touchObj] |
| 10000 |
verify() { illogical(&cannotPourMsg); } |
| 10001 |
} |
| 10002 |
|
| 10003 |
/* -------------------------------------------------------------------- */ |
| 10004 |
/* |
| 10005 |
* "Pour into" |
| 10006 |
*/ |
| 10007 |
dobjFor(PourInto) |
| 10008 |
{ |
| 10009 |
preCond = [touchObj] |
| 10010 |
verify() { illogical(&cannotPourMsg); } |
| 10011 |
} |
| 10012 |
iobjFor(PourInto) |
| 10013 |
{ |
| 10014 |
preCond = [touchObj] |
| 10015 |
verify() { illogical(&cannotPourIntoMsg); } |
| 10016 |
} |
| 10017 |
|
| 10018 |
/* -------------------------------------------------------------------- */ |
| 10019 |
/* |
| 10020 |
* "Pour onto" |
| 10021 |
*/ |
| 10022 |
dobjFor(PourOnto) |
| 10023 |
{ |
| 10024 |
preCond = [touchObj] |
| 10025 |
verify() { illogical(&cannotPourMsg); } |
| 10026 |
} |
| 10027 |
iobjFor(PourOnto) |
| 10028 |
{ |
| 10029 |
preCond = [touchObj] |
| 10030 |
verify() { illogical(&cannotPourOntoMsg); } |
| 10031 |
} |
| 10032 |
|
| 10033 |
/* -------------------------------------------------------------------- */ |
| 10034 |
/* |
| 10035 |
* "Clean" action |
| 10036 |
*/ |
| 10037 |
dobjFor(Clean) |
| 10038 |
{ |
| 10039 |
preCond = [touchObj] |
| 10040 |
verify() { illogical(&cannotCleanMsg); } |
| 10041 |
} |
| 10042 |
|
| 10043 |
/* -------------------------------------------------------------------- */ |
| 10044 |
/* |
| 10045 |
* "CleanWith" action |
| 10046 |
*/ |
| 10047 |
dobjFor(CleanWith) |
| 10048 |
{ |
| 10049 |
preCond = [touchObj] |
| 10050 |
verify() { illogical(&cannotCleanMsg); } |
| 10051 |
} |
| 10052 |
iobjFor(CleanWith) |
| 10053 |
{ |
| 10054 |
preCond = [objHeld] |
| 10055 |
verify() { illogical(&cannotCleanWithMsg); } |
| 10056 |
} |
| 10057 |
|
| 10058 |
/* -------------------------------------------------------------------- */ |
| 10059 |
/* |
| 10060 |
* "SitOn" action |
| 10061 |
*/ |
| 10062 |
dobjFor(SitOn) |
| 10063 |
{ |
| 10064 |
preCond = [touchObj] |
| 10065 |
verify() { illogical(&cannotSitOnMsg); } |
| 10066 |
} |
| 10067 |
|
| 10068 |
/* -------------------------------------------------------------------- */ |
| 10069 |
/* |
| 10070 |
* "LieOn" action |
| 10071 |
*/ |
| 10072 |
dobjFor(LieOn) |
| 10073 |
{ |
| 10074 |
preCond = [touchObj] |
| 10075 |
verify() { illogical(&cannotLieOnMsg); } |
| 10076 |
} |
| 10077 |
|
| 10078 |
/* -------------------------------------------------------------------- */ |
| 10079 |
/* |
| 10080 |
* "StandOn" action |
| 10081 |
*/ |
| 10082 |
dobjFor(StandOn) |
| 10083 |
{ |
| 10084 |
preCond = [touchObj] |
| 10085 |
verify() { illogical(&cannotStandOnMsg); } |
| 10086 |
} |
| 10087 |
|
| 10088 |
/* -------------------------------------------------------------------- */ |
| 10089 |
/* |
| 10090 |
* "Board" action |
| 10091 |
*/ |
| 10092 |
dobjFor(Board) |
| 10093 |
{ |
| 10094 |
preCond = [touchObj] |
| 10095 |
verify() { illogical(&cannotBoardMsg); } |
| 10096 |
} |
| 10097 |
|
| 10098 |
/* -------------------------------------------------------------------- */ |
| 10099 |
/* |
| 10100 |
* "Get out of" (unboard) action |
| 10101 |
*/ |
| 10102 |
dobjFor(GetOutOf) |
| 10103 |
{ |
| 10104 |
verify() { illogical(&cannotUnboardMsg); } |
| 10105 |
} |
| 10106 |
|
| 10107 |
/* |
| 10108 |
* "Get off of" action |
| 10109 |
*/ |
| 10110 |
dobjFor(GetOffOf) |
| 10111 |
{ |
| 10112 |
verify() { illogical(&cannotGetOffOfMsg); } |
| 10113 |
} |
| 10114 |
|
| 10115 |
/* -------------------------------------------------------------------- */ |
| 10116 |
/* |
| 10117 |
* "Fasten" action |
| 10118 |
*/ |
| 10119 |
dobjFor(Fasten) |
| 10120 |
{ |
| 10121 |
preCond = [touchObj] |
| 10122 |
verify() { illogical(&cannotFastenMsg); } |
| 10123 |
} |
| 10124 |
|
| 10125 |
/* -------------------------------------------------------------------- */ |
| 10126 |
/* |
| 10127 |
* "Fasten to" action |
| 10128 |
*/ |
| 10129 |
dobjFor(FastenTo) |
| 10130 |
{ |
| 10131 |
preCond = [touchObj] |
| 10132 |
verify() { illogical(&cannotFastenMsg); } |
| 10133 |
} |
| 10134 |
iobjFor(FastenTo) |
| 10135 |
{ |
| 10136 |
preCond = [touchObj] |
| 10137 |
verify() { illogical(&cannotFastenToMsg); } |
| 10138 |
} |
| 10139 |
|
| 10140 |
/* -------------------------------------------------------------------- */ |
| 10141 |
/* |
| 10142 |
* "Unfasten" action |
| 10143 |
*/ |
| 10144 |
dobjFor(Unfasten) |
| 10145 |
{ |
| 10146 |
preCond = [touchObj] |
| 10147 |
verify() { illogical(&cannotUnfastenMsg); } |
| 10148 |
} |
| 10149 |
|
| 10150 |
/* -------------------------------------------------------------------- */ |
| 10151 |
/* |
| 10152 |
* "Unfasten from" action |
| 10153 |
*/ |
| 10154 |
dobjFor(UnfastenFrom) |
| 10155 |
{ |
| 10156 |
preCond = [touchObj] |
| 10157 |
verify() { illogical(&cannotUnfastenMsg); } |
| 10158 |
} |
| 10159 |
iobjFor(UnfastenFrom) |
| 10160 |
{ |
| 10161 |
preCond = [touchObj] |
| 10162 |
verify() { illogical(&cannotUnfastenFromMsg); } |
| 10163 |
} |
| 10164 |
|
| 10165 |
/* -------------------------------------------------------------------- */ |
| 10166 |
/* |
| 10167 |
* "PlugIn" action |
| 10168 |
*/ |
| 10169 |
dobjFor(PlugIn) |
| 10170 |
{ |
| 10171 |
preCond = [touchObj] |
| 10172 |
verify() { illogical(&cannotPlugInMsg); } |
| 10173 |
} |
| 10174 |
|
| 10175 |
/* -------------------------------------------------------------------- */ |
| 10176 |
/* |
| 10177 |
* "PlugInto" action |
| 10178 |
*/ |
| 10179 |
dobjFor(PlugInto) |
| 10180 |
{ |
| 10181 |
preCond = [touchObj] |
| 10182 |
verify() { illogical(&cannotPlugInMsg); } |
| 10183 |
} |
| 10184 |
iobjFor(PlugInto) |
| 10185 |
{ |
| 10186 |
preCond = [touchObj] |
| 10187 |
verify() { illogical(&cannotPlugInToMsg); } |
| 10188 |
} |
| 10189 |
|
| 10190 |
/* -------------------------------------------------------------------- */ |
| 10191 |
/* |
| 10192 |
* "Unplug" action |
| 10193 |
*/ |
| 10194 |
dobjFor(Unplug) |
| 10195 |
{ |
| 10196 |
preCond = [touchObj] |
| 10197 |
verify() { illogical(&cannotUnplugMsg); } |
| 10198 |
} |
| 10199 |
|
| 10200 |
/* -------------------------------------------------------------------- */ |
| 10201 |
/* |
| 10202 |
* "UnplugFrom" action |
| 10203 |
*/ |
| 10204 |
dobjFor(UnplugFrom) |
| 10205 |
{ |
| 10206 |
preCond = [touchObj] |
| 10207 |
verify() { illogical(&cannotUnplugMsg); } |
| 10208 |
} |
| 10209 |
iobjFor(UnplugFrom) |
| 10210 |
{ |
| 10211 |
preCond = [touchObj] |
| 10212 |
verify() { illogical(&cannotUnplugFromMsg); } |
| 10213 |
} |
| 10214 |
|
| 10215 |
/* -------------------------------------------------------------------- */ |
| 10216 |
/* |
| 10217 |
* "Screw" action |
| 10218 |
*/ |
| 10219 |
dobjFor(Screw) |
| 10220 |
{ |
| 10221 |
preCond = [touchObj] |
| 10222 |
verify() { illogical(&cannotScrewMsg); } |
| 10223 |
} |
| 10224 |
|
| 10225 |
/* -------------------------------------------------------------------- */ |
| 10226 |
/* |
| 10227 |
* "ScrewWith" action |
| 10228 |
*/ |
| 10229 |
dobjFor(ScrewWith) |
| 10230 |
{ |
| 10231 |
preCond = [iobjTouchObj] |
| 10232 |
verify() { illogical(&cannotScrewMsg); } |
| 10233 |
} |
| 10234 |
iobjFor(ScrewWith) |
| 10235 |
{ |
| 10236 |
preCond = [objHeld] |
| 10237 |
verify() { illogical(&cannotScrewWithMsg); } |
| 10238 |
} |
| 10239 |
|
| 10240 |
/* -------------------------------------------------------------------- */ |
| 10241 |
/* |
| 10242 |
* "Unscrew" action |
| 10243 |
*/ |
| 10244 |
dobjFor(Unscrew) |
| 10245 |
{ |
| 10246 |
preCond = [touchObj] |
| 10247 |
verify() { illogical(&cannotUnscrewMsg); } |
| 10248 |
} |
| 10249 |
|
| 10250 |
/* -------------------------------------------------------------------- */ |
| 10251 |
/* |
| 10252 |
* "UnscrewWith" action |
| 10253 |
*/ |
| 10254 |
dobjFor(UnscrewWith) |
| 10255 |
{ |
| 10256 |
preCond = [iobjTouchObj] |
| 10257 |
verify() { illogical(&cannotUnscrewMsg); } |
| 10258 |
} |
| 10259 |
iobjFor(UnscrewWith) |
| 10260 |
{ |
| 10261 |
preCond = [objHeld] |
| 10262 |
verify() { illogical(&cannotUnscrewWithMsg); } |
| 10263 |
} |
| 10264 |
|
| 10265 |
/* -------------------------------------------------------------------- */ |
| 10266 |
/* |
| 10267 |
* "Enter" |
| 10268 |
*/ |
| 10269 |
dobjFor(Enter) |
| 10270 |
{ |
| 10271 |
preCond = [touchObj] |
| 10272 |
verify() { illogical(&cannotEnterMsg); } |
| 10273 |
} |
| 10274 |
|
| 10275 |
/* |
| 10276 |
* "Go through" |
| 10277 |
*/ |
| 10278 |
dobjFor(GoThrough) |
| 10279 |
{ |
| 10280 |
preCond = [touchObj] |
| 10281 |
verify() { illogical(&cannotGoThroughMsg); } |
| 10282 |
} |
| 10283 |
|
| 10284 |
/* -------------------------------------------------------------------- */ |
| 10285 |
/* |
| 10286 |
* Push in Direction action - this is for commands like "push |
| 10287 |
* boulder north" or "drag sled into cave". |
| 10288 |
*/ |
| 10289 |
dobjFor(PushTravel) |
| 10290 |
{ |
| 10291 |
preCond = [touchObj] |
| 10292 |
verify() { illogical(&cannotPushTravelMsg); } |
| 10293 |
} |
| 10294 |
|
| 10295 |
/* |
| 10296 |
* For all of the two-object forms, map these using our general |
| 10297 |
* push-travel mapping. We do all of this mapping here, rather than |
| 10298 |
* in the action definition, so that individual objects can change |
| 10299 |
* the meanings of these verbs for special cases as appropriate. |
| 10300 |
*/ |
| 10301 |
mapPushTravelHandlers(PushTravelThrough, GoThrough) |
| 10302 |
mapPushTravelHandlers(PushTravelEnter, Enter) |
| 10303 |
mapPushTravelHandlers(PushTravelGetOutOf, GetOutOf) |
| 10304 |
mapPushTravelHandlers(PushTravelClimbUp, ClimbUp) |
| 10305 |
mapPushTravelHandlers(PushTravelClimbDown, ClimbDown) |
| 10306 |
; |
| 10307 |
|