forked from EricEve/adv3lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exits.t
564 lines (481 loc) · 17.3 KB
/
exits.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
#charset "us-ascii"
/*
* Based on Copyright (c) 2002, 2006 by Michael J. Roberts
*
* Based on exitslister.t, copyright 2002 by Steve Breslin and
* incorporated by permission.
*
* TADS 3 Library - Exits Lister
*
* This module provides an automatic exit lister that shows the apparent
* exits from the player character's location. The automatic exit lister
* can optionally provide these main features:
*
* - An "exits" verb lets the player explicitly show the list of apparent
* exits, along with the name of the room to which each exit connects.
*
* - Exits can be shown automatically as part of the room description.
* This extra information can be controlled by the player through the
* "exits on" and "exits off" command.
*
* - Exits can be shown automatically when an actor tries to go in a
* direction where no exit exists, as a helpful reminder of which
* directions are valid.
*/
/* include the library header */
#include "advlite.h"
/* ------------------------------------------------------------------------ */
/*
* The main exits lister.
*/
exitLister: PreinitObject
/* preinitialization */
execute()
{
/* install myself as the global exit lister object */
gExitLister = self;
}
/*
* Flag: use "verbose" listing style for exit lists in room
* descriptions. When this is set to true, we'll show a
* sentence-style list of exits ("Obvious exits lead east to the
* living room, south, and up."). When this is set to nil, we'll use
* a terse style, enclosing the message in the default system
* message's brackets ("[Obvious exits: East, West]").
*
* Verbose-style room descriptions tend to fit well with a room
* description's prose, but at the expense of looking redundant with
* the exit list that's usually built into each room's custom
* descriptive text to begin with. Some authors prefer the terse
* style precisely because it doesn't look like more prose
* description, but looks like a separate bit of information being
* offered.
*
* This is an author-configured setting; the library does not provide
* a command to let the player control this setting.
*/
roomDescVerbose = nil
/*
* Flag: show automatic exit listings on attempts to move in
* directions that don't allow travel. Enable this by default,
* since most players appreciate having the exit list called out
* separately from the room description (where any mention of exits
* might be buried in lots of other text) in place of an unspecific
* "you can't go that way".
*
* This is an author-configured setting; the library does not provide
* a command to let the player control this setting.
*/
enableReminder = true
/*
* Flag: enable the automatic exit reminder even when the room
* description exit listing is enabled. When this is nil, we will
* NOT show a reminder with "can't go that way" messages when the
* room description exit list is enabled - this is the default,
* because it can be a little much to have the list of exits shown so
* frequently. Some authors might prefer to show the reminder
* unconditionally, though, so this option is offered.
*
* This is an author-configured setting; the library does not provide
* a command to let the player control this setting.
*/
enableReminderAlways = nil
/*
* Flag: use hyperlinks in the directions mentioned in room
* description exit lists, so that players can click on the direction
* name in the listing to enter the direction command.
*/
enableHyperlinks = true
/* flag: we've explained how the exits on/off command works */
exitsOnOffExplained = nil
/*
* Determine if the "reminder" is enabled. The reminder is the list
* of exits we show along with a "can't go that way" message, to
* reminder the player of the valid exits when an invalid one is
* attempted.
*/
isReminderEnabled()
{
/*
* The reminder is enabled if enableReminderAlways is true, OR if
* enableReminder is true AND exitsMode.inRoomDesc is nil.
*/
return (enableReminderAlways
|| (enableReminder && !exitsMode.inRoomDesc));
}
/*
* Get the exit lister we use for room descriptions.
*/
getRoomDescLister()
{
/* use the verbose or terse lister, according to the configuration */
return roomDescVerbose
? lookAroundExitLister
: lookAroundTerseExitLister;
}
/* perform the "exits" command to show exits on explicit request */
showExitsCommand()
{
/* show exits for the current actor */
showExits(gActor);
/*
* if we haven't explained how to turn exit listing on and off,
* do so now
*/
if (!exitsOnOffExplained)
{
DMsg(explain exits on off,
'<.p>Exit Listing can be adjusted with the following
commands:\n
EXITS ON -- show exits in both the status line and in room
descriptions.\n
EXITS OFF -- show exits neither in the status line nor in room
descriptions.\n
EXITS STATUS -- show exits in the status line only.\n
EXITS LOOK -- show exits in room descriptions only.\n
EXITS COLOR ON -- show unvisited exits in a different colour.\n
EXITS COLOR OFF -- don\'t show unvisited exits in a different colour.\n
EXITS COLOR RED / BLUE / GREEN / YELLOW -- show unvisted exits in the
specified colour.
<.p>');
exitsOnOffExplained = true;
}
}
/*
* Perform an EXITS ON/OFF/STATUS/LOOK command. 'stat' indicates
* whether we're turning on (true) or off (nil) the statusline exit
* listing; 'look' indicates whether we're turning the room
* description listing on or off.
*/
exitsOnOffCommand(stat, look)
{
/* set the new status */
exitsMode.inStatusLine = stat;
exitsMode.inRoomDesc = look;
/* confirm the new status */
DMsg(exits on off okay, 'Okay. Exit listing in the status line is now
<<stat ? 'ON' : 'OFF'>>, while exit listing in room descriptions is
now <<look ? 'ON' : 'OFF'>>. ');
/*
* If we haven't already explained how the EXITS ON/OFF command
* works, don't bother explaining it now, since they obviously
* know how it works if they've actually used it.
*/
exitsOnOffExplained = true;
}
/* show the list of exits from an actor's current location */
showExits(actor)
{
/* show exits from the actor's location */
showExitsFrom(actor, actor.getOutermostRoom);
}
/* show an exit list display in the status line, if desired */
showStatuslineExits()
{
/* if statusline exit displays are enabled, show the exit list */
if (exitsMode.inStatusLine)
showExitsWithLister(gPlayerChar, gPlayerChar.getOutermostRoom,
statuslineExitLister,
gPlayerChar.location
.wouldBeLitFor(gPlayerChar));
}
/*
* Calculate the contribution of the exits list to the height of the
* status line, in lines of text. If we're not configured to display
* the exits list in the status line, then the contribution is zero;
* otherwise, we'll estimate how much space we need to display the
* exit list.
*/
getStatuslineExitsHeight()
{
/*
* if we're enabled, our standard display takes up one line; if
* we're disabled, we don't contribute anything to the status
* line's vertical extent
*/
if (exitsMode.inStatusLine)
return 1;
else
return 0;
}
/* show exits as part of a room description */
lookAroundShowExits(actor, loc, illum)
{
/* if room exit displays are enabled, show the exits */
if (exitsMode.inRoomDesc)
showExitsWithLister(actor, loc, getRoomDescLister, illum);
}
/* show exits as part of a "cannot go that way" error */
cannotGoShowExits(actor, loc)
{
/* if we want to show the reminder, show it */
if (isReminderEnabled())
showExitsWithLister(actor, loc, explicitExitLister,
loc.wouldBeLitFor(actor));
}
/* show the list of exits from a given location for a given actor */
showExitsFrom(actor, loc)
{
/* show exits with our standard lister */
showExitsWithLister(actor, loc, explicitExitLister,
loc.wouldBeLitFor(actor));
}
/*
* Show the list of exits using a specific lister.
*
* 'actor' is the actor for whom the display is being generated.
* 'loc' is the location whose exit list is to be shown; this need
* not be the same as the actor's current location. 'lister' is the
* Lister object that will show the list of DestInfo objects that we
* create to represent the exit list.
*
* 'locIsLit' indicates whether or not the ambient illumination, for
* the actor's visual senses, is sufficient that the actor would be
* able to see if the actor were in the new location. We take this
* as a parameter so that we don't have to re-compute the
* information if the caller has already computed it for other
* reasons (such as showing a room description). If the caller
* hasn't otherwise computed the value, it can be easily computed as
* loc.wouldBeLitFor(actor).
*/
showExitsWithLister(actor, loc, lister, locIsLit)
{
local destList;
local options;
/* we have no option flags for the lister yet */
options = 0;
/* run through all of the directions used in the game */
destList = new Vector(Direction.allDirections.length());
foreach(local dir in Direction.allDirections)
{
local conn = nil;
switch(loc.propType(dir.dirProp))
{
case TypeNil:
case TypeSString:
case TypeDString:
break;
case TypeObject:
conn = loc.(dir.dirProp);
if(conn.isConnectorVisible && conn.isConnectorListed)
destList.append(new DestInfo(dir, conn.destination));
break;
/*
* If the property points to code then presumably something
* happens if the player goes this way, so we'll list the
* exit, unless the extraDestInfo table explicitly lists the
* destination as nil.
*/
case TypeCode:
if(locIsLit)
{
local dest = libGlobal.extraDestInfo[[loc, dir]];
if(dest != nil)
destList.append(new DestInfo(dir, dest));
}
break;
}
}
/* show the list */
lister.showListAll(destList.toList(), options, 0);
}
;
ExitLister: Lister
showListAll(lst, options, indent)
{
local cnt = lst.length;
if(cnt == 0)
{
showListEmpty(nil, nil);
return;
}
showListPrefixWide(1, nil, nil);
for(local obj in lst, local i = 1 ; ; ++i)
{
showListItem(obj, nil, nil, nil);
showListSeparator(nil, i, cnt);
}
showListSuffixWide(cnt, nil, nil);
}
listerShowsDest = nil
exitsPrefix = BMsg(exits, 'Exits:');
;
statuslineExitLister: ExitLister
showListEmpty(pov, parent)
{
"<<statusHTML(3)>><b><<exitsPrefix>></b> <i>None</i><<statusHTML(4)>>";
}
showListPrefixWide(cnt, pov, parent)
{
"<<statusHTML(3)>><b><<exitsPrefix>></b> ";
}
showListSuffixWide(cnt, pov, parent)
{
"<<statusHTML(4)>>";
}
showListItem(obj, options, pov, infoTab)
{
if(highlightUnvisitedExits && (obj.dest_ == nil || !obj.dest_.seen))
htmlSay('<FONT COLOR="<<unvisitedExitColour>>">');
"<<aHref(obj.dir_.name, obj.dir_.name, 'Go ' + obj.dir_.name,
AHREF_Plain)>>";
if(highlightUnvisitedExits && (obj.dest_ == nil || !obj.dest_.seen))
htmlSay('</FONT>');
}
showListSeparator(options, curItemNum, totalItems)
{
/* just show a space between items */
if (curItemNum != totalItems)
" ";
}
/* this lister does not show destination names */
listerShowsDest = nil
highlightUnvisitedExits = true
unvisitedExitColour = 'green'
;
lookAroundExitLister: ExitLister
showListEmpty(pov, parent)
{
DMsg(no exits from here, 'There {plural} {are} no exits from {here}. ');
}
showListPrefixWide(cnt, pov, parent)
{
"<<exitsPrefix>> ";
}
showListSuffixWide(cnt, pov, parent)
{
".";
}
showListItem(obj, options, pov, infoTab)
{
"<<obj.dir_.name>>";
}
showListSeparator(options, curItemNum, totalItems)
{
if(curItemNum == totalItems - 1)
" and ";
if(curItemNum < totalItems - 1)
", ";
}
;
lookAroundTerseExitLister: ExitLister
showListEmpty(pov, parent)
{
DMsg(no exits, 'Exits: none. ');
}
showListPrefixWide(cnt, pov, parent)
{
"<<exitsPrefix>> ";
}
showListSuffixWide(cnt, pov, parent)
{
".";
}
showListItem(obj, options, pov, infoTab)
{
htmlSay('<<aHref(obj.dir_.name, obj.dir_.name, 'Go ' + obj.dir_.name,
0)>>');
}
showListSeparator(options, curItemNum, totalItems)
{
if(curItemNum == totalItems - 1)
" and ";
if(curItemNum < totalItems - 1)
", ";
}
;
explicitExitLister: ExitLister
showListEmpty(pov, parent)
{
DMsg(no clear exits, 'It{dummy}{\'s} not clear where {i} {can} go from
{here}. ');
}
showListPrefixWide(cnt, pov, parent)
{
DMsg(exits from here, 'From {here} {i} could go ');
}
showListSuffixWide(cnt, pov, parent)
{
".";
}
showListItem(obj, options, pov, infoTab)
{
htmlSay('<<aHref(obj.dir_.name, obj.dir_.name, 'Go ' + obj.dir_.name,
0)>>');
}
showListSeparator(options, curItemNum, totalItems)
{
if(curItemNum == totalItems - 1)
" or ";
if(curItemNum < totalItems - 1)
", ";
}
;
/*
* A destination tracker. This keeps track of a direction and the
* apparent destination in that direction.
*/
class DestInfo: object
construct(dir, dest, destName?, destIsBack?)
{
/* remember the direction, destination, and destination name */
dir_ = dir;
dest_ = dest;
}
/* the direction of travel */
dir_ = nil
/* the destination room object */
dest_ = nil
/* the name of the destination */
destName_ = nil
/* flag: this is the "back to" destination */
destIsBack_ = nil
/* list of other directions that go to our same destination */
others_ = []
;
/*
* Settings item - show defaults in status line [SettingsItem)
*/
exitsMode: object
/* our ID */
settingID = 'adv3.exits'
/* show our description */
settingDesc()
{
DMsg(current exit settings, 'Exits are listed
<<if(inStatusLine && inRoomDesc)>>
both in the status line and in room descriptions.
<<else if(inStatusLine && !inRoomDesc)>>
in the status line only.
<<else if(!inStatusLine && inRoomDesc)>>
in room descriptions only.
<<else if(!inStatusLine && !inRoomDesc)>>
"neither in the status line nor in room descriptions. <<end>>');
}
/* convert to text */
settingToText()
{
/* just return the two binary variables */
return (inStatusLine ? 'on' : 'off')
+ ','
+ (inRoomDesc ? 'on' : 'off');
}
settingFromText(str)
{
/* parse out our format */
if (rexMatch('<space>*(<alpha>+)<space>*,<space>*(<alpha>+)',
str.toLower()) != nil)
{
/* pull out the two variables from the regexp groups */
inStatusLine = (rexGroup(1)[3] == 'on');
inRoomDesc = (rexGroup(2)[3] == 'on');
}
}
/*
* Our value is in two parts. inStatusLine controls whether or not
* we show the exit list in the status line; inRoomDesc controls the
* exit listing in room descriptions.
*/
inStatusLine = true
inRoomDesc = nil
;