| | 1 | #charset "us-ascii" |
| | 2 | |
| | 3 | #include <adv3.h> |
| | 4 | #include <en_us.h> |
| | 5 | |
| | 6 | /* |
| | 7 | * CustomStatus - by Mark Engelberg (mark.engelberg@gmail.com) |
| | 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 | * openableContentsLister. We really don't want the status to be |
| | 104 | * displayed unless we specify, so we have to set the descContentsLister |
| | 105 | * back to the basic thingDescContentsLister in the case that this is an |
| | 106 | * openable object. The flaw with this approach is that if you have a |
| | 107 | * class between CustomStatus and Openable in your class list which |
| | 108 | * defines a different descContentsLister, this will break it. |
| | 109 | * Unfortunately, I can't think of a better strategy right now. |
| | 110 | */ |
| | 111 | |
| | 112 | descContentsLister { |
| | 113 | if (ofKind(Openable)) |
| | 114 | return(thingDescContentsLister); |
| | 115 | else |
| | 116 | return inherited; |
| | 117 | } |
| | 118 | |
| | 119 | // Often, in containers, it is useful to report a container's open status and |
| | 120 | // its contents in the same sentence. |
| | 121 | reportOpenStatusAndContents { |
| | 122 | examineListContentsWith(openableContentsLister); |
| | 123 | } |
| | 124 | |
| | 125 | // Reporters for actors |
| | 126 | |
| | 127 | // If you have a specific lister you'd like to use, you can just |
| | 128 | // use examineListContentsWith, but we give it a reportContentsWith name |
| | 129 | // for consistency with the other reporters. |
| | 130 | |
| | 131 | // Now let's turn our attention to actors that use this mix-in |
| | 132 | // The default examineStatus provides a posture description, and a state |
| | 133 | // description. Let's provide some default reporters. |
| | 134 | |
| | 135 | reportPosture { |
| | 136 | postureDesc; |
| | 137 | } |
| | 138 | |
| | 139 | reportState { |
| | 140 | curState.stateDesc; |
| | 141 | } |
| | 142 | |
| | 143 | // Combine all the actor status pieces into one default report, if desired. |
| | 144 | reportActorStatus { |
| | 145 | reportPosture; |
| | 146 | reportState; |
| | 147 | reportContents; |
| | 148 | } |
| | 149 | |
| | 150 | // Reporters for attachable objects |
| | 151 | |
| | 152 | reportAttachments { |
| | 153 | local tab; |
| | 154 | |
| | 155 | /* get the actor's visual sense table */ |
| | 156 | tab = gActor.visibleInfoTable(); |
| | 157 | |
| | 158 | /* add our list of attachments */ |
| | 159 | attachmentLister.showList(gActor, self, attachedObjects, |
| | 160 | 0, 0, tab, nil); |
| | 161 | |
| | 162 | /* add our list of major attachments */ |
| | 163 | majorAttachmentLister.showList(gActor, self, attachedObjects, |
| | 164 | 0, 0, tab, nil); |
| | 165 | } |
| | 166 | |
| | 167 | |
| | 168 | ; |
| | 169 | |