| 1 |
#charset "us-ascii" |
| 2 |
|
| 3 |
#include <adv3.h> |
| 4 |
#include <en_us.h> |
| 5 |
|
| 6 |
/* |
| 7 |
* CustomStatus - by Mark Engelberg ([email protected]) |
| 8 |
* |
| 9 |
* CustomStatus is a mix-in class for situations where you want to have |
| 10 |
* more control over the various status messages that are printed by |
| 11 |
* default when an object is examined. |
| 12 |
* |
| 13 |
* By mixing in this class, default reporting of status is disabled, and |
| 14 |
* it becomes an "opt-in" system. This leaves you free to describe the |
| 15 |
* status of the object as part of its prose description. |
| 16 |
* |
| 17 |
* For convenience, the class contains several status reporting functions |
| 18 |
* that you can use in your description if a default message will do. |
| 19 |
* Even if you find yourself using default messages, you may prefer doing |
| 20 |
* it this way, because you then have full control over where in your |
| 21 |
* description the status message occurs, and you have the ability to |
| 22 |
* choose between a few variations (see below). |
| 23 |
*/ |
| 24 |
|
| 25 |
|
| 26 |
CustomStatus : Thing |
| 27 |
// Most status reports occur in examineStatus. So the first step is to |
| 28 |
// override examineStatus. This gets rid of open and locked status statements |
| 29 |
// and automatic listing of contents when you examine an object. |
| 30 |
// It doesn't do anything about the way contents are described when they are |
| 31 |
// inside of other objects, or in an inventory. |
| 32 |
|
| 33 |
examineStatus{} |
| 34 |
|
| 35 |
// Next, we provide various messages you can mix in to your descriptions to |
| 36 |
// report simple status messages. It's up to you to make sure you're |
| 37 |
// reporting something meaningful for that kind of object. |
| 38 |
// For example, reportLockedStatus only makes sense on something lockable. |
| 39 |
|
| 40 |
// Reporters for openable objects. |
| 41 |
|
| 42 |
// "It's open. " |
| 43 |
reportOpenStatus { |
| 44 |
say ('\^'+openStatus+'. '); |
| 45 |
} |
| 46 |
|
| 47 |
// "It's currently open. " |
| 48 |
reportCurrentlyOpenStatus { |
| 49 |
say(isOpen ? gLibMessages.currentlyOpen : gLibMessages.currentlyClosed); |
| 50 |
} |
| 51 |
|
| 52 |
// "The object is open. " |
| 53 |
reportDobjOpenStatus { |
| 54 |
"{The dobj/he} is <<openDesc>>. "; |
| 55 |
} |
| 56 |
|
| 57 |
// Reporters for lockable objects. |
| 58 |
|
| 59 |
// Default reporting of lock status respects the lockStatusObvious and |
| 60 |
// lockStatusReportable flags. |
| 61 |
reportLockedStatus { |
| 62 |
if (lockStatusObvious && lockStatusReportable) |
| 63 |
say ( '\^' + itIsContraction + ' ' + lockedDesc + '. '); |
| 64 |
} |
| 65 |
reportCurrentlyLockedStatus { |
| 66 |
if (lockStatusObvious && lockStatusReportable) |
| 67 |
say(isLocked ? gLibMessages.currentlyLocked |
| 68 |
: gLibMessages.currentlyUnlocked); |
| 69 |
} |
| 70 |
reportDobjLockedStatus { |
| 71 |
if (lockStatusObvious && lockStatusReportable) |
| 72 |
"{The dobj/he} is <<lockedDesc>>. "; |
| 73 |
} |
| 74 |
|
| 75 |
// Reporters for containers |
| 76 |
|
| 77 |
/* |
| 78 |
* If you want to report the contents of something (a container, an |
| 79 |
* actor, etc.), you can use this reportContents, which is usually |
| 80 |
* just a synonym for examineListContents. |
| 81 |
*/ |
| 82 |
reportContents { |
| 83 |
if (ofKind(RoomPart)) // Listing the contents of a room part is handled a |
| 84 |
// bit differently |
| 85 |
examinePartContents(&descContentsLister); |
| 86 |
else |
| 87 |
examineListContents; |
| 88 |
} |
| 89 |
|
| 90 |
/* |
| 91 |
* If you want specialized lister behavior when reporting the contents, you |
| 92 |
* can call this reporter with a specific lister as an argument. |
| 93 |
*/ |
| 94 |
reportContentsWith(lister) { |
| 95 |
examineListContentsWith(lister); |
| 96 |
} |
| 97 |
|
| 98 |
/* |
| 99 |
* The openable class is a major thorn in my side for the purposes of |
| 100 |
* this opt-in strategy. The problem is that the openable class |
| 101 |
* incorporates the open status as part of its container lister. It |
| 102 |
* does this by setting the descContentsLister to |
| 103 |
* openableDescContentsLister. We really don't want the status to be |
| 104 |
* displayed unless we specify, so we have to set the |
| 105 |
* descContentsLister back to the basic thingDescContentsLister in |
| 106 |
* the case that this is an openable object. The flaw with this |
| 107 |
* approach is that if you have a class between CustomStatus and |
| 108 |
* Openable in your class list which defines a different |
| 109 |
* descContentsLister, this will break it. Unfortunately, I can't |
| 110 |
* think of a better strategy right now. |
| 111 |
*/ |
| 112 |
|
| 113 |
descContentsLister { |
| 114 |
if (ofKind(Openable)) |
| 115 |
return(thingDescContentsLister); |
| 116 |
else |
| 117 |
return inherited; |
| 118 |
} |
| 119 |
|
| 120 |
// Often, in containers, it is useful to report a container's open status and |
| 121 |
// its contents in the same sentence. |
| 122 |
reportOpenStatusAndContents { |
| 123 |
examineListContentsWith(openableDescContentsLister); |
| 124 |
} |
| 125 |
|
| 126 |
// Reporters for actors |
| 127 |
|
| 128 |
// If you have a specific lister you'd like to use, you can just |
| 129 |
// use examineListContentsWith, but we give it a reportContentsWith name |
| 130 |
// for consistency with the other reporters. |
| 131 |
|
| 132 |
// Now let's turn our attention to actors that use this mix-in |
| 133 |
// The default examineStatus provides a posture description, and a state |
| 134 |
// description. Let's provide some default reporters. |
| 135 |
|
| 136 |
reportPosture { |
| 137 |
postureDesc; |
| 138 |
} |
| 139 |
|
| 140 |
reportState { |
| 141 |
curState.stateDesc; |
| 142 |
} |
| 143 |
|
| 144 |
// Combine all the actor status pieces into one default report, if desired. |
| 145 |
reportActorStatus { |
| 146 |
reportPosture; |
| 147 |
reportState; |
| 148 |
reportContents; |
| 149 |
} |
| 150 |
|
| 151 |
// Reporters for attachable objects |
| 152 |
|
| 153 |
reportAttachments { |
| 154 |
local tab; |
| 155 |
|
| 156 |
/* get the actor's visual sense table */ |
| 157 |
tab = gActor.visibleInfoTable(); |
| 158 |
|
| 159 |
/* add our list of attachments */ |
| 160 |
attachmentLister.showList(gActor, self, attachedObjects, |
| 161 |
0, 0, tab, nil); |
| 162 |
|
| 163 |
/* add our list of major attachments */ |
| 164 |
majorAttachmentLister.showList(gActor, self, attachedObjects, |
| 165 |
0, 0, tab, nil); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
; |
| 170 |
|