Revert to original minimal Inform lexer.
[ibg.git] / chapters / 13.rst
1 ===========================
2 Captain Fate: the final cut
3 ===========================
4
5 .. epigraph::
6
7    | *Y was a youth, that did not love school;*
8    | *Z was a zany, a poor harmless fool.*
9
10 .. only:: html
11
12    .. image:: /images/picY.png
13       :align: left
14
15 .. raw:: latex
16
17    \dropcap{y}
18
19 ou'll probably be pleased to hear that Captain Fate has almost run his 
20 allotted span. There are some minor objects still to be defined -- the 
21 toilet, our hero’s clothes, the all-important costume -- but first we 
22 need to decorate the café a little more.
23
24 Additional catering garnish
25 ===========================
26
27 We must not forget a couple of tiny details in the café room:
28
29 .. code-block:: inform
30
31   Object   food "Benny's snacks" cafe
32     with   name 'food' 'pastry' 'pastries' 'sandwich' 'sandwiches' 'snack'
33            before [; "There is no time for FOOD right now."; ],
34     has    scenery proper;
35
36   Object   menu "menu" cafe
37     with   name 'informative' 'menu' 'board' 'picture' 'writing',
38            description
39                "The menu board lists Benny's food and drinks, along with their
40                 prices. Too bad you've never learnt how to read, but luckily
41                 there is a picture of a big cup of coffee among the
42                 incomprehensible writing.",
43            before [;
44              Take:
45                "The board is mounted on the wall behind Benny. Besides, it's
46                 useless WRITING.";
47            ],
48     has    scenery;
49
50 And a not-so-trivial object:
51
52 .. code-block:: inform
53
54   Object  coffee "cup of coffee" benny
55     with  name 'cup' 'of' 'coffee' 'steaming' 'cappuccino'
56                'cappucino' 'capuccino' 'capucino',
57           description [;
58               if (self in benny)
59                   "The picture on the menu board SURE looks good.";
60               else
61                   "It smells delicious.";
62           ],
63           before [;
64             Take,Drink,Taste:
65               if (self in benny) "You should ask Benny for one first.";
66               else {
67                   move self to benny;
68                   print "You pick up the cup and swallow a mouthful. Benny's
69                          WORLDWIDE REPUTATION is well deserved. Just as you
70                          finish, Benny takes away the empty cup.";
71                   if (benny.coffee_not_paid == true)
72                       " ~That will be one quidbuck, sir.~";
73                   else
74                       "";
75               }
76             Buy:
77               if (coin in player) <<Give coin benny>>;
78               else                "You have no money.";
79             Smell:
80               "If your HYPERACTIVE pituitary glands are to be trusted,
81                it's Colombian.";
82           ];
83
84 There's nothing really new in this object (other than that the ``name`` 
85 property caters for orthographically challenged players), but notice how 
86 we don't ``remove`` it after the player drinks it. In an apparently 
87 absurd whim, the coffee returns to Benny magically (although this is not 
88 information that the player needs to know). Why? After you remove an 
89 object from the game, if the player attempts, say, to EXAMINE it, the 
90 interpreter will impertinently state that "You can't see any such 
91 thing". Moreover, if the player asks Benny for a second coffee, once the 
92 first one has been removed, Benny will complain "I don’t think that’s on 
93 the menu, sir" -- a blatant lie -- which was the default in Benny’s 
94 orders property. Since the removed coffee object does not belong to 
95 Benny, it's not a noun that the player can ASK Benny FOR. By making it a 
96 child of the barman (who has the ``transparent`` attribute set), the 
97 coffee is still an object that players can refer to. We ensure that they 
98 don't get more cups thanks to Benny's ``coffee_asked_for property``, 
99 which will remain ``true`` after the first time.
100
101 We also ensure that Benny doesn't ask for money from players who have 
102 already paid, by first printing a "You pick up the cup..." message and 
103 then testing Benny's ``coffee_not_paid`` property. If its value is 
104 ``true``, we can finish the message with the "quidbuck" print-and-return 
105 statement. If its value is ``false``, the player has previously paid, 
106 and so there's nothing else to say. However, we still need to terminate 
107 the incomplete message with a newline, and to return ``true`` from the 
108 property routine; we *could* have used the statements ``{ print "^"; 
109 return true; }``, but an empty ``""`` statement does the same thing more 
110 neatly.
111
112
113 Toilet or dressing room?
114 ========================
115
116 Rather more of the latter, actually, since it's the only place away from 
117 curious eyes where our hero will be able to metamorphose from weakling 
118 into the bane of all evildoers. And we *really* don't want to become, 
119 erm, bogged down with details of the room's function or plumbing.
120
121 There's not a lot about the toilet room and its contents, though there 
122 will be some tricky side effects:
123
124 .. code-block:: inform
125
126   Room    toilet "Unisex toilet"
127     with  description
128               "A surprisingly CLEAN square room covered with glazed-ceramic
129                tiles, featuring little more than a lavatory and a light switch.
130                The only exit is south, through the door and into the cafe.",
131           s_to toilet_door,
132     has   ~light scored;
133
134   Appliance lavatory "lavatory" toilet
135     with name 'lavatory' 'wc' 'toilet' 'loo' 'bowl' 'can' 'john' 'bog',
136          before [;
137            Examine,Search,LookUnder:
138              if (coin in self) {
139                  move coin to parent(self);
140                  "The latest user CIVILLY flushed it after use, but failed to
141                   pick up the VALUABLE coin that fell from his pants.";
142              }
143            Receive:
144              "While any other MORTALS might unwittingly throw just about
145               ANYTHING into ", (the) self, ", you remember the WISE teachings
146               of your mentor, Duke ELEGANT, about elderly plumbing and rising
147               waters.";
148          ];
149
150   Object  coin "valuable coin" lavatory
151     with  name 'valuable' 'coin' 'silver' 'quidbuck',
152           description "It's a genuine SILVER QUIDBUCK.",
153           before [;
154             Drop:
155               if (self notin player) return false;
156               "Such a valuable coin? Har, har! This must be a demonstration of
157                your ULTRA-FLIPPANT jesting!";
158           ],
159           after [;
160             Take:
161               "You crouch into the SLEEPING DRAGON position and deftly, with
162                PARAMOUNT STEALTH, you pocket the lost coin.";
163           ],
164     has   scored;
165
166 We initially place the coin as a child of the lavatory (just so that we 
167 can easily make the ``if (coin in self)`` one-time test). Since the 
168 lavatory does not have the ``transparent`` attribute set, the coin will 
169 be invisible to players until they try to inspect the lavatory, an 
170 action that will move the coin into the toilet room. Once taken, the 
171 coin will remain in the inventory until the player gives it to Benny, 
172 because we trap any ``Drop`` actions to help the player to Do the Right 
173 Thing.
174
175 The lavatory object includes a load of helpful synonyms in its name 
176 property, including our favourite word ``'toilet'`` . That won't be a 
177 problem: the other objects here which may have TOILET in their names -- 
178 the key and the door -- both use the ``pname`` property to turn their 
179 use of ``'toilet'`` into a lower-priority adjective.
180
181 See that here we have the only two ``scored`` attributes of the game. 
182 The player will be awarded one point for entering the toilet room, and 
183 another for finding and picking up the coin.
184
185 You might have noticed that we are forcefully clearing the ``light`` 
186 attribute, inherited from the ``Room`` class. This will be a windowless 
187 space and, to add a touch of realism, we'll make the room a dark one, 
188 which will enable us to tell you about Inform's default behaviour when 
189 there's no light to see by. However, let's define first the light switch 
190 mentioned in the room's description to aid players in their dressing 
191 duties.
192
193 .. code-block:: inform
194
195   Appliance  light_switch "light switch" toilet
196     with     name 'light' 'switch',
197              description
198                  "A notorious ACHIEVEMENT of technological SCIENCE, elegant yet
199                   EASY to use.",
200              before [;
201                Push:
202                  if (self has on) <<SwitchOff self>>;
203                  else             <<SwitchOn  self>>;
204              ],
205              after [;
206                SwitchOn:
207                  give self light;
208                  "You turn on the light in the toilet.";
209                SwitchOff:
210                  give self ~light;
211                  "You turn off the light in the toilet.";
212              ],
213     has      switchable ~on;
214
215 Please notice the appearance of new attributes ``switchable`` and 
216 ``on``. switchable enables the object to be turned on and off, and is 
217 typical of lanterns, computers, television sets, radios, and so on. The 
218 library automatically extends the description of these objects by 
219 indicating if they are currently on or off::
220
221   > X LIGHT SWITCH
222   A notorious ACHIEVEMENT of technological SCIENCE, elegant yet EASY to use.
223   The light switch is currently switched on.
224
225 Two new actions are ready to use, ``SwitchOn`` and ``SwitchOff``. Left 
226 to themselves, they toggle the object's state between ON and OFF and 
227 display a message like::
228
229   You switch the brass lantern on.
230
231 They also take care of checking if the player fumbled and tried to turn 
232 on (or off) an object which was already on (or off). How does the 
233 library know the state of the object? This is thanks to the ``on`` 
234 attribute, which is set or cleared automatically as needed. You can, of 
235 course, set or clear it manually like any other attribute, with the 
236 ``give`` statement:
237
238 .. code-block:: inform
239
240   give self on;
241
242   give self ~on;
243
244 and check if a ``switchable`` object is on or off with the test:
245
246 .. code-block:: inform
247
248   if (light_switch has on) ...
249
250   if (light_switch hasnt on) ...
251
252 A ``switchable`` object is OFF by default. However, you’ll notice that 
253 the has line of the object definition includes ``~on`` :
254
255 .. code-block:: inform
256
257   has    switchable ~on;
258
259 Surely that’s saying "not-on"? Surely that's what would have happened 
260 anyway if the line hadn't mentioned the attribute at all?
261
262 .. code-block:: inform
263
264   has    switchable;
265
266 Absolutely true. Adding that ``~on`` attribute has no effect whatsoever 
267 on the game -- but nevertheless it's a good idea. It's an aide-mémoire, 
268 a way of reminding ourselves that we start with the attribute clear, and 
269 that at some point we'll be setting it for some purpose. Trust us: it's 
270 worthwhile taking tiny opportunities like this to help yourself.
271
272 Let’s see how our light switch works. We trap the ``SwitchOn`` and 
273 ``SwitchOff`` actions in the ``after`` property (when the switching has 
274 successfully taken place) and use them to give ``light`` to the light 
275 switch.
276
277 Uh, wait. To the light switch? Why not to the toilet room? Well, there's 
278 a reason and we'll see it in a minute. For now, just remember that, in 
279 order for players to see their surroundings, you need only one object in 
280 a room with the ``light`` attribute set. It doesn't have to be the room 
281 itself (though this is usually convenient).
282
283 After setting the ``light`` attribute, we display a customised message, 
284 to avoid the default::
285
286   You switch the light switch on.
287
288 which, given the name of the object, doesn't read very elegantly. We 
289 foresee that players might try to PUSH SWITCH, so we trap this attempt 
290 in a ``before`` property and redirect it to ``SwitchOn`` and 
291 ``SwitchOff`` actions, checking first which one is needed by testing the 
292 ``on`` attribute. Finally, we have made the switch a member of the class 
293 ``Appliance``, so that the player doesn't walk away with it.
294
295 .. note::
296
297   remember what we said about class inheritance? No matter what you 
298   define in the class, the object’s definition has priority. The class 
299   ``Appliance`` defines a response for the ``Push`` action, but we 
300   override it here with a new behaviour.
301
302
303 And there was light
304 ===================
305
306 So the player walks into the toilet and
307
308 .. code-block:: transcript
309
310   Darkness
311   It is pitch dark, and you can't see a thing.
312
313 Oops! No toilet description, no mention of the light switch, nothing. It 
314 is reasonable to think that if we have opened the toilet door to access 
315 the toilet, some light coming from the café room will illuminate our 
316 surroundings -- at least until the player decides to close the door. So 
317 perhaps it would be a good idea to append a little code to the door 
318 object to account for this. A couple of lines in the after property will 
319 suffice:
320
321 .. code-block:: inform
322
323   after [ ks;
324     Unlock:
325       if (self has locked) return false;
326       print "You unlock ", (the) self, " and open it.^";
327       ks = keep_silent; keep_silent = true;
328       <Open self>; keep_silent = ks;
329       return true;
330     Open:
331       give toilet light;
332     Close:
333       give toilet ~light;
334
335   ],
336
337 And this is the reason why the light switch didn't set the ``light`` 
338 attribute of the toilet room, but did it to itself. We avoid running 
339 into trouble if we let the open/closed states of the door control the 
340 light of the room object, and the on/off states of the switch control 
341 the light of the switch. So it is one shiny light switch. Fortunately, 
342 players are never aware of this glowing artefact.
343
344 .. note::
345
346   now, could they? Well, if players could TAKE the light switch (which
347   we have forbidden) and then did INVENTORY, the trick would be given
348   away, because all objects with the ``light`` attribute set are listed 
349   as ``(providing light)`` .
350
351 So the player walks into the toilet and
352
353 .. code-block:: transcript
354
355   Unisex toilet
356   A surprisingly CLEAN square room covered with glazed-ceramic tiles, featuring
357   little more than a lavatory and a light switch. The only exit is south, through
358   the door and into the cafe.
359
360   [Your score has just gone up by one point.]
361
362 Better. Now, suppose the player closes the door.
363
364 .. code-block:: transcript
365
366   >CLOSE DOOR
367   You close the door to the cafe.
368
369   It is now pitch dark in here!
370
371 The player might try then to LOOK:
372
373 Well, no problem. We have mentioned that there is a light switch. Surely 
374 the player will now try to:
375
376 .. code-block:: transcript
377
378   >TURN ON LIGHT SWITCH
379   You can't see any such thing.
380
381 Oops! Things are getting nasty here in the dark. It's probably time to 
382 leave this place and try another approach:
383
384 .. code-block:: transcript
385
386   >OPEN DOOR
387   You can't see any such thing.
388
389 And this illustrates one of the terrible things about darkness in a 
390 game. You can't see anything; you can do very little indeed. All objects 
391 except those in your inventory are out of scope, unreachable, as if 
392 non-existent. Worse, if you DROP one of the objects you are carrying, it 
393 will be swallowed by the dark, never to be found until there is light to 
394 see by.
395
396 The player, who is doubtless immersed in the fantasy of the game, will 
397 now be a little annoyed. "I am in a small bathroom and I can't even 
398 reach the door I have just closed?" The player's right, of 
399 course [#dark]_.  Darkened rooms are one cliché of traditional games. 
400 Usually you move in one direction while looking for treasure in some 
401 underground cave, and suddenly arrive at a pitch black place. It's good 
402 behaviour of the game to disallow exploration of unknown dark territory, 
403 and it's a convention to bar passage to players until they return with a 
404 light source. However, if the scenario of the game features, say, the 
405 player character's home, a little apartment with two rooms, and there’s 
406 no light in the kitchen, we could expect the owner of the house to know 
407 how to move around a little, perhaps groping for the light switch or 
408 even going to the refrigerator in the dark.
409
410 We are in a similar situation. The inner logic of the game demands that 
411 blind players should be able to open the door and probably operate the 
412 light switch they've just encountered. We have been telling you that an 
413 object is in scope when it’s in the same room as the player. Darkness 
414 changes that rule. All objects not directly carried by the player become 
415 out of scope.
416
417 One of the advantages of an advanced design system like Inform is the 
418 flexibility to change all default behaviours to suit your particular 
419 needs. Scope problems are no different. There is a set of routines and 
420 functions to tamper with what's in scope when. We'll see just a tiny 
421 example to fix our particular problem. In the section "``Entry point 
422 routines``" of our game -- after the ``Initialise`` routine, for 
423 instance -- include the following lines:
424
425 .. code-block:: inform
426
427   [ InScope person;
428       if (person == player && location == thedark && real_location == toilet) {
429           PlaceInScope(light_switch);
430           PlaceInScope(toilet_door);
431       }
432       return false;
433   ];
434
435 ``InScope(actor_obj_id)`` is an entry point routine that can tamper with 
436 the scope rules for the given ``actor_obj_id`` (either the player 
437 character or a NPC). We define it with one variable (which we name as we 
438 please; it's also a good idea to name variables in an intuitive way to 
439 remind us of what they represent), ``person`` , and then we make a 
440 complex test to see if the player is actually in the toilet and in the 
441 dark.
442
443 We have told you that the library variable ``location`` holds the 
444 current 
445 room that the player is in. However, when there is no light, the 
446 variable location gets assigned to the value of the special library 
447 object thedark . It doesn't matter if we have ten dark rooms in our 
448 game; location will be equal to thedark in all of them. There is yet 
449 another variable, called ``real_location``, which holds the room the 
450 player is in *even when there is no light to see by*.
451
452 So the test:
453
454 .. code-block:: inform
455
456   if (person == player && location == thedark && real_location == toilet) ...
457
458 is stating: if the specified actor is the ``player`` character *and* he 
459 finds himself in the dark *and* he actually happens to be in the 
460 toilet...
461
462 Then we make a call to one of the library routines, 
463 ``PlaceInScope(obj_id)``, which has a very descriptive name: it places 
464 in scope the given object. In our case, we want both the door and the 
465 light switch to be within reach of the player, hence both additional 
466 lines. Finally, we must ``return false``, because we want the normal 
467 scope rules for the defined actor -- the player -- to apply to the rest 
468 of the objects of the game (if we returned ``true``, players would find 
469 that they are able to interact with very little indeed). Now we get a 
470 friendlier and more logical response:
471
472 .. code-block:: transcript
473
474   Darkness
475   It is pitch dark, and you can't see a thing.
476
477   >TURN ON SWITCH
478   You turn on the light in the toilet.
479
480   Unisex toilet
481   A surprisingly CLEAN square room covered with glazed-ceramic tiles, featuring
482   little more than a lavatory and a light switch. The only exit is south, through
483   the door and into the cafe.
484
485 And the same would happen with the door. Notice how the room description 
486 gets displayed after we pass from dark to light; this is the normal 
487 library behaviour.
488
489 There is still one final problem which, admittedly, might originate from 
490 an improbable course of action; however, it could be a nuisance. Suppose 
491 that the player enters the toilet, locks the door -- which is possible 
492 in the dark now that the door is in scope -- and then drops the key. 
493 There's no way to exit the toilet -- because the door is locked and the 
494 key has disappeared, engulfed by the darkness -- unless the player 
495 thinks to turn on the light switch, thereby placing the key in scope 
496 once more.
497
498 Why don't we add a ``PlaceInScope(toilet_key)`` to the above routine? 
499 Well, for starters, the key can be moved around (as opposed to the door 
500 or the light switch, which are fixed items in the toilet room). Suppose 
501 the player opens the door of the toilet, but drops the key in the café, 
502 then enters the toilet and closes the door. The condition is met and the 
503 key is placed in scope, when it's in another room. Second, this is a 
504 simple game with just a few objects, so you can define a rule for each 
505 of them; but in any large game, you might like to be able to refer to 
506 objects in bunches, and make general rules that apply to all (or some) 
507 of them.
508
509 We need to add code to the ``InScope`` routine, telling the game to 
510 place in scope all objects that we drop in the dark, so that we might 
511 recover them (maybe going on all fours and groping a little, but it’s a 
512 possible action). We don’t want the player to have other objects in 
513 scope (like the coin, for instance), so it might be good to have a way 
514 of testing if the objects have been touched and carried by the player. 
515 The attribute ``moved`` is perfect for this. The library sets it for 
516 every object that the player has picked up at one time in the game; 
517 ``scenery`` and ``static`` objects, and those we have not yet seen don't 
518 have ``moved``. Here is the reworked ``InScope`` routine. There are a 
519 couple of new concepts to look at:
520
521 .. code-block:: inform
522
523   [ InScope person item;
524       if (person == player && location == thedark && real_location == toilet) {
525           PlaceInScope(light_switch);
526           PlaceInScope(toilet_door);
527       }
528       if (person == player && location == thedark)
529           objectloop (item in parent(player))
530               if (item has moved) PlaceInScope(item);
531       return false;
532   ];
533
534 We have added one more local variable to the routine, ``item`` -- again, 
535 this is a variable we have created and named on our own; it is not part 
536 of the library. We make now a new test: if the actor is the player and 
537 the location is any dark room, then perform a certain action. We don't 
538 need to specify the toilet, because we want this rule to apply to all 
539 dark rooms (well, the only dark room in the game *is* the toilet, but we 
540 are trying to provide a general rule).
541
542    :samp:`objectloop (variable) {statement};`
543
544 is a loop statement, one of the four defined in Inform. A loop statement is
545 a construct that allows you to run several times through a statement (or a
546 statement block). ``objectloop`` performs the :samp:`{statement}` once for
547 every object defined in the (``variable``) . If we were to code:
548
549    :samp:`objectloop (item) {statement};`
550
551 then the :samp:`{statement}` would be executed once for each object in the
552 game. However, we want to perform the statement only for those objects
553 whose parent object is the same as the player's parent object: that is, for
554 objects in the same room as the player, so we instead code:
555
556    :samp:`objectloop (item in parent(player)) {statement};`
557
558 What is the actual :samp:`{statement}` that we'll repeatedly execute?
559
560 .. code-block:: inform
561
562   if (item has moved)
563       PlaceInScope(item);
564
565 The test: ``if (item has moved)`` ensures that ``PlaceInScope(item)`` 
566 deals only with objects with the ``moved`` attribute set. So: if the 
567 player is in the dark, let’s go through the objects which are in the 
568 same room, one at a time. For each of them, check if it's an item that 
569 the player has at some time carried, in which case, place it in scope. 
570 All dropped objects within the room were carried at one time, so we let 
571 players recollect them even if they can’t see them.
572
573 As you see, darkness has its delicate side. If you plan to have dark 
574 rooms galore in your games, bear in mind that you are in for some 
575 elaborate code (unless you let the library carry on with default rules, 
576 in which case there won't be much for your players to do).
577
578
579 Amazing techicolour dreamcoats
580 ==============================
581
582 This leaves us the clothing items themselves, which will require a few 
583 tailored actions. Let's see first the ordinary garments of John Covarth:
584
585 .. code-block:: inform
586
587   Object  clothes "your clothes"
588     with  name 'ordinary' 'street' 'clothes' 'clothing',
589           description
590               "Perfectly ORDINARY-LOOKING street clothes for a NOBODY like
591                John Covarth.",
592           before [;
593             Wear:
594               if (self has worn)
595                   "You are already dressed as John Covarth.";
596               else
597                   "The town NEEDS the power of Captain FATE, not the anonymity
598                    of John Covarth.";
599             Change,Disrobe:
600               if (self hasnt worn)
601                  "Your KEEN eye detects that you're no longer wearing them.";
602               switch (location) {
603                 street:
604                   if (player in booth)
605                       "Lacking Superman's super-speed, you realise that it
606                        would be awkward to change in plain view of the passing
607                        pedestrians.";          
608                   else
609                       "In the middle of the street? That would be a PUBLIC
610                        SCANDAL, to say nothing of revealing your secret
611                        identity.";
612                 cafe:
613                       "Benny allows no monkey business in his establishment.";
614                 toilet:
615                   if (toilet_door has open)
616                       "The door to the bar stands OPEN at tens of curious eyes.
617                        You'd be forced to arrest yourself for LEWD conduct.";
618                   print "You quickly remove your street clothes and bundle them
619                          up together into an INFRA MINUSCULE pack ready for easy
620                          transportation. ";
621                   if (toilet_door has locked) {
622                       give clothes ~worn; give costume worn;
623                       "Then you unfold your INVULNERABLE-COTTON costume and
624                        turn into Captain FATE, defender of free will, adversary
625                        of tyranny!";
626                   }
627                   else {
628                       deadflag = 3;
629                       "Just as you are slipping into Captain FATE's costume,
630                        the door opens and a young woman enters. She looks at
631                        you and starts screaming, ~RAPIST! NAKED RAPIST IN THE
632                        TOILET!!!~^^
633                        Everybody in the cafe quickly comes to the rescue, only
634                        to find you ridiculously jumping on one leg while trying
635                        to get dressed. Their laughter brings a QUICK END to
636                        your crime-fighting career!";
637                   }
638                 thedark:
639                   "Last time you changed in the dark, you wore the suit inside
640                    out!";
641                 default:                  ! this _should_ never happen...
642                   "There must be better places to change your clothes!";
643               }
644           ],
645     clothing proper pluralname;
646
647 See how the object deals only with ``Wear``, ``Disrobe`` and ``Change``. 
648 ``Wear`` and ``Disrobe`` are standard library actions already defined in 
649 Inform, but we'll have to make a new verb to allow for CHANGE CLOTHES. 
650 In this game, ``Disrobe`` and ``Change`` are considered synonymous for 
651 all purposes; we'll deal with them first.
652
653 The goal of the game is for players to change their clothes, so we might 
654 expect them to try this almost anywhere; but first of all we have to 
655 check that the ``clothes`` object is actually being worn. If not, we 
656 display a message reminding the player that this action has become 
657 irrelevant. What we do with the ``switch`` statement is to offer a 
658 variety of responses according to the ``location`` variable. The street 
659 (in or out of the booth) and the café all display refusals of some kind, 
660 until the player character manages to enter the toilet, where we 
661 additionally require that he locks the door before taking off his 
662 clothes. If the door is closed but not locked, he is interrupted in his 
663 naked state by a nervous woman who starts shouting, and the game is lost 
664 (this is not as unfair as it seems, because the player may always revert 
665 to the previous state with UNDO). If the door is locked, he succeeds in 
666 his transformation (we take away the ``worn`` attribute from the 
667 ``clothes`` and give it to the ``costume`` instead). We add a special 
668 refusal to change in the dark, forcing players to turn on the light and 
669 then, we hope, to find the coin. And finally we code a ``default`` 
670 entry; you'll remember that, in a ``switch`` statement, this is supposed 
671 to cater for any value not explicitly listed for the expression under 
672 control -- in this case, for the variable ``location``. Since we have 
673 already gone through all the possible locations of the game, this entry 
674 appears only as a defensive measure, just in case something unexpected 
675 happens (for instance, we might extend the game with another room and 
676 forget about this ``switch`` statement). In normal and controlled 
677 conditions, it should never be reached, but it doesn't hurt one bit to 
678 have it there.
679
680 The ``Wear`` action just checks if these clothes are already being worn, 
681 to offer two different rejection responses: the goal of the game is to 
682 change into the hero's suit, after which we'll prevent a change back 
683 into ordinary clothes. So now we are dealing with a Captain Fate in full 
684 costume:
685
686 .. code-block:: inform
687
688   Object   costume "your costume"
689     with   name 'captain' 'captain^s' 'fate' 'fate^s' 'costume' 'suit',
690            description
691                "STATE OF THE ART manufacture, from chemically reinforced 100%
692                 COTTON-lastic(tm).",
693            before [;
694              Wear:
695                if (self has worn)
696                    "You are already dressed as Captain FATE.";
697                else
698                    "First you'd have to take off your commonplace unassuming
699                     John Covarth INCOGNITO street clothes.";
700              Change,Disrobe:
701                if (self has worn)
702                    "You need to wear your costume to FIGHT crime!";
703                else
704                    "But you're not yet wearing it!";
705              Drop:
706                "Your UNIQUE Captain FATE multi-coloured costume? The most
707                 coveted clothing ITEM in the whole city? Certainly NOT!";
708            ],
709     has    clothing proper;
710
711 Note that we intercept the action WEAR COSTUME and hint that players 
712 should try TAKE OFF CLOTHES instead. We don't let them take off the 
713 costume once it’s being worn, and we certainly don't let them misplace 
714 it anywhere, by refusing to accept a ``Drop`` action.
715
716
717 It's a wrap
718 ===========
719
720 Nearly there; just a few minor odds and ends to round things off.
721
722 .. rubric:: Initialise routine
723
724 All the objects of our game are defined. Now we must add a couple of 
725 lines to the ``Initialise`` routine to make sure that the player does 
726 not start the game naked:
727
728 .. code-block:: inform
729
730   [ Initialise;
731       #Ifdef DEBUG; pname_verify(); #Endif;       ! suggested by pname.h
732       location = street;
733       move costume to player;
734       move clothes to play; give clothes worn;
735       lookmode = 2;
736       "^^Impersonating mild mannered John Covarth, assistant help boy at an
737        insignificant drugstore, you suddenly STOP when your acute hearing
738        deciphers a stray radio call from the POLICE. There's some MADMAN
739        attacking the population in Granary Park! You must change into your
740        Captain FATE costume fast...!^^";
741   ];
742
743 Remember that we included a disambiguation package, ``pname.h``? There 
744 were some additional comments in the accompanying text file that should 
745 be taken in consideration:
746
747   pname.h provides a pname_verify routine. When DEBUG is defined, you 
748   may call pname_verify() in your Initialise() routine to verify the pname 
749   properties in your objects.
750
751 The designer of the package has made a debugging tool (a routine) to 
752 check for errors when using his library, and he tells us how to use it. 
753 So we include the suggested lines into our ``Initialise`` routine:
754
755 .. code-block:: inform
756
757   #Ifdef DEBUG; pname_verify(); #Endif;
758
759 As the text explains, what this does is: first check whether the game is 
760 being compiled in Debug mode; if this is the case, run the 
761 ``pname_verify`` routine, so that it tests all ``pname`` properties to 
762 see if they are written correctly.
763
764 .. rubric:: Demise of our hero
765
766 We have made three possible endings:
767
768 #.  The player attempts to change in the toilet with an unlocked door.
769
770 #.  The player tries to attack Benny while wearing the costume.
771
772 #.  The player manages to exit the café dressed as Captain Fate.
773
774 (1) and (2) lose the game, (3) wins it. The library defaults for these 
775 two states display, respectively,
776
777 .. code-block:: transcript
778
779   *** You have died ***
780
781   *** You have won ***
782
783 These states correspond to the values of the ``deadflag`` variable: 1 
784 for losing, 2 for winning. However, we have made up different messages, 
785 because our hero does not really die -- ours suffers a FATE worse than 
786 death -- and because we want to give him a more descriptive winning 
787 line. Therefore, we must define a ``DeathMessage`` routine as we did in 
788 "William Tell", to write our customised messages and assign them to 
789 ``deadflag`` values greater than 2.
790
791 .. code-block:: inform
792
793   [ DeathMessage;
794       if (deadflag == 3) print "Your secret identity has been revealed";
795       if (deadflag == 4) print "You have been SHAMEFULLY defeated";
796       if (deadflag == 5) print "You fly away to SAVE the DAY";
797   ];
798
799 .. rubric:: Grammar
800
801 Finally, we need to extend the existing grammar, to allow for a couple 
802 of things. We have already seen that we need a verb CHANGE. We'll make 
803 it really simple:
804
805 .. code-block:: inform
806
807   [ ChangeSub;
808       if (noun has pluralname) print "They're";
809       else                     print "That's";
810       " not something you must change to save the day.";
811   ];
812
813   Verb 'change' 'exchange' 'swap' 'swop'
814       * noun                     -> Change;
815
816 Just notice how the verb handler checks whether the noun given is plural 
817 or singular, to display a suitable pronoun.
818
819 A further detail: when players are in the café, they might ask Benny for 
820 the coffee (as we intend and heavily hint), for a sandwich or a pastry 
821 (both mentioned in the café description), for food or a snack (mentioned 
822 here and there, and we have provided for those); but what if they try a 
823 meat pie? Or scrambled eggs? There’s just so much decoration one can 
824 reasonably insert in a game, and loading the dictionary with Benny’s 
825 full menu would be overdoing it a bit.
826
827 One might reasonably imagine that the ``default`` line at the end of the 
828 ``Give`` action in the orders property handles every input not already 
829 specified:
830
831 .. code-block:: inform
832
833   orders [;
834     Give:
835       switch (noun) {
836         toilet_key:  ! code for the key...
837         coffee:      ! code for the coffee...
838         food:        ! code for the food...
839         menu:        ! code for the menu...
840         default:
841           "~I don't
842       }
843   ],
844
845 Not so. The library grammar that deals with ASK BENNY FOR... is this
846 (specifically, the last line):
847
848 .. code-block:: inform
849
850   Verb 'ask'
851       * creature 'about' topic    -> Ask
852       * creature 'for' noun       -> AskFor
853
854 You'll see the ``noun`` token, which means that whatever the player asks 
855 him for must be a real game object, visible at that moment. Assuming 
856 that the player mentions such an object, the interpreter finds it in the 
857 dictionary and places its internal ID in the ``noun`` variable, where 
858 our ``switch`` statement can handle it. So, ASK BENNY FOR KEY assigns 
859 the ``toilet_key`` object to the noun variable, and Benny responds. ASK 
860 BENNY FOR CUSTOMERS also works; the ``default`` case picks that one up. 
861 But, ASK BENNY FOR SPAGHETTI BOLOGNESE won't work: we have no object for 
862 Spaghetti Bolognese (or any other delicacy from Benny's kitchen) -- the 
863 words ``'spaghetti'`` and ``'bolognese'`` simply aren't in the 
864 dictionary. This is perhaps not a major deficiency in our game, but it 
865 takes very little to allow Benny to use his default line for *any* 
866 undefined input from the player. We need to extend the existing ASK 
867 grammar:
868
869 .. code-block:: inform
870
871   Extend 'ask'
872       * creature 'for' topic    -> AskFor;
873
874 This line will be added to the end of the existing grammar for Ask, so 
875 it doesn’t override the conventional noun-matching line. ``topic`` is a 
876 token that roughly means “any input at all”; the value of noun isn't 
877 important, because it'll be handled by the default case. Now players may 
878 ask Benny for a tuna sandwich or a good time; they'll get: "I don’t 
879 think that’s on the menu, sir", which makes Benny a barman with 
880 attitude.
881
882 And that's it; on the slightly surreal note of ASK BENNY FOR A GOOD TIME 
883 we've taken "Captain Fate" as far as we intend to. The guide is nearly 
884 done. All that's left is to recap some of the more important issues, 
885 talk a little more about compilation and debugging, and send you off 
886 into the big wide world of IF authorship.
887
888
889 .. rubric:: Footnotes
890
891 .. [#dark]
892
893   We're alluding here to the Classical concept of mimesis. In an 
894   oft-quoted essay from 1996, Roger Giner-Sorolla wrote: "I see 
895   successful fiction as an imitation or 'mimesis' of reality, be it 
896   this world's or an alternate world's. Well-written fiction leads the 
897   reader to temporarily enter and believe in the reality of that world. 
898   A crime against mimesis is any aspect of an IF game that breaks the 
899   coherence of its fictional world as a representation of reality."
900