-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhintsys.t
986 lines (867 loc) · 36.2 KB
/
hintsys.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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
#charset "us-ascii"
/*
* Copyright (c) 2000, 2006 by Michael J. Roberts. All Rights Reserved.
* Adapted for adv3lite library by Eric Eve
*
* TADS 3 Library - Hint System
*
* This module provides a hint system framework. Games can use this
* framework to define context-sensitive hints for players.
*
* This module depends on the menus module to display the user interface.
*/
/* include the library header */
#include "advlite.h"
/* ------------------------------------------------------------------------ */
/*
* We refer to some properties defined primarily in score.t - that's an
* optional module, though, so make sure the compiler has heard of these.
* We do the same for some properties in eventList.t
*/
property scoreCount;
property achieved;
property eventList;
/* HintOpener provides some properties common to Goal and ExtraHint, in particuar
* those relating to opening and closing Goals and ExtraHints.
*/
class HintOpener: object
/*
* An optional object that, when seen by the player character, opens
* this goal. It's often convenient to declare a goal open as soon
* as the player enters a particular area or has encountered a
* particular object. For such cases, simply set this property to
* the room or object that opens the goal, and we'll automatically
* mark the goal as Open the next time the player asks for a hint
* after seeing the referenced object.
*/
openWhenSeen = nil
/*
* An option object that, when seen by the player character, closes
* this goal. Many goals will be things like "how do I find the
* X?", in which case it's nice to close the goal when the X is
* found.
*/
closeWhenSeen = nil
/*
* this is like openWhenSeen, but opens the topic when the given
* object is described (with EXAMINE)
*/
openWhenExamined = nil
/* close the goal when the given object is described */
closeWhenExamined = nil
/*
* An optional object that, when moved, opens this goal. It's often
* convenient to declare a goal open as soon as the player enters a
* particular area or has encountered a particular object. For such
* cases, simply set this property to the object that opens the goal, and
* we'll automatically mark the goal as Open the next time the player asks
* for a hint after seeing the referenced object.
*/
openWhenMoved = nil
/*
* An optional object that, when moved, closes this goal. Many goals will
* be things like "how do I find the X?", in which case it's nice to close
* the goal when the X is found.
*/
closeWhenMoved = nil
/*
* An optional Achievement object that opens this goal. This goal
* will be opened automatically once the goal is achieved, if the
* goal was previously undiscovered. This makes it easy to set up a
* hint topic that becomes available after a particular puzzle is
* solved, which is useful when a new puzzle only becomes known to
* the player after a gating puzzle has been solved.
*/
openWhenAchieved = nil
/*
* An optional Achievement object that closes this goal. Once the
* achievement is completed, this goal's state will automatically be
* set to Closed. This makes it easy to associate the goal with a
* puzzle: once the puzzle is solved, there's no need to show hints
* for the goal any more.
*/
closeWhenAchieved = nil
/*
* An optional Topic or Thing that opens this goal when the object
* becomes "known" to the player character. This will open the goal
* as soon as gPlayerChar.knowsAbout(openWhenKnown) returns true.
* This makes it easy to open a goal as soon as the player comes
* across some information in the game.
*/
openWhenKnown = nil
/* an optional Topic or Thing that closes this goal when known */
closeWhenKnown = nil
/*
* An optional <.reveal> tag name that opens this goal. If this is
* set to a non-nil string, we'll automatically open this goal when
* the tag has been revealed via <.reveal> (or gReveal()).
*/
openWhenRevealed = nil
/* an optional <.reveal> tag that closes this goal when revealed */
closeWhenRevealed = nil
/*
* An optional arbitrary check that opens the goal. If this returns
* true, we'll open the goal. This check is made in addition to the
* other checks (openWhenSeen, openWhenDescribed, etc). This can be
* used for any custom check that doesn't fit into one of the
* standard openWhenXxx properties.
*/
openWhenTrue = nil
/* an optional general-purpose check that closes the goal */
closeWhenTrue = nil
/*
* Determine if there's any condition that should open this goal.
* This checks openWhenSeen, openWhenDescribed, and all of the other
* openWhenXxx conditions; if any of these return true, then we'll
* return true.
*
* Note that this should generally NOT be overridden in individual
* instances; normally, instances would define openWhenTrue instead.
* However, some games might find that they use the same special
* condition over and over in many goals, often enough to warrant
* adding a new openWhenXxx property to Goal. In these cases, you
* can use 'modify Goal' to override openWhen to add the new
* condition: simply define openWhen as (inherited || newCondition),
* where 'newCondition' is the new special condition you want to
* add.
*/
openWhen = (
(openWhenSeen != nil && gPlayerChar.hasSeen(openWhenSeen))
|| (openWhenExamined != nil && openWhenExamined.examined)
|| (openWhenMoved != nil && openWhenMoved.moved)
|| (openWhenAchieved != nil && openWhenAchieved.scoreCount != 0)
|| (openWhenKnown != nil && gPlayerChar.knowsAbout(openWhenKnown))
|| (openWhenRevealed != nil && gRevealed(openWhenRevealed))
|| openWhenTrue)
/*
* Determine if there's any condition that should close this goal.
* We'll check closeWhenSeen, closeWhenDescribed, and all of the
* other closeWhenXxx conditions; if any of these return true, then
* we'll return true.
*/
closeWhen = (
(closeWhenSeen != nil && gPlayerChar.hasSeen(closeWhenSeen))
|| (closeWhenExamined != nil && closeWhenExamined.examined)
|| (closeWhenMoved != nil && closeWhenMoved.moved)
|| (closeWhenAchieved != nil && closeWhenAchieved.scoreCount != 0)
|| (closeWhenKnown != nil && gPlayerChar.knowsAbout(closeWhenKnown))
|| (closeWhenRevealed != nil && gRevealed(closeWhenRevealed))
|| closeWhenTrue)
;
/* ------------------------------------------------------------------------ */
/*
* A basic hint menu object. This is an abstract base class that
* encapsulates some behavior common to different hint menu classes.
*/
class HintMenuObject: object
/*
* The topic order. When we're about to show a list of open topics,
* we'll sort the list in ascending order of this property, then in
* ascending order of title. By default, we set this order value to
* 1000; if individual goals don't override this, then they'll
* simply be sorted lexically by topic name. This can be used if
* there's some basis other than alphabetical order for sorting the
* list.
*/
topicOrder = 1000
/*
* Compare this goal to another, for the purposes of sorting a list
* of topics. Returns a positive number if this goal sorts after
* the other one, a negative number if this goal sorts before the
* other one, 0 if the relative order is arbitrary.
*
* By default, we'll sort by topicOrder if the topicOrder values are
* different, otherwise alphabetically by title.
*/
compareForTopicSort(other)
{
/* if the topicOrder values are different, sort by topicOrder */
if (topicOrder != other.topicOrder)
return topicOrder - other.topicOrder;
/* the topicOrder values are the same, so sort by title */
if (title > other.title)
return 1;
else if (title < other.title)
return -1;
else
return 0;
}
;
/*
* A Goal represents an open task: something that the player is trying
* to achieve. A Goal is an abstract object, not part of the simulated
* world of the game.
*
* Each goal is associated with a hint topic (usually shown as a
* question, such as "How do I get past the guard?") and an ordered list
* of hints. The hints are usually ordered from most general to most
* specific. The idea is to let the player control how big a hint they
* get; we start with a small nudge and work towards giving away the
* puzzle completely, so the player can stop as soon as they see
* something that helps.
*
* At any given time, a goal can be in one of three states:
*
* - Open: this means that the player is (or ought to be) aware of the
* goal, but the goal hasn't yet been achieved. Determining this
* awareness is up to the goal. In some cases, a goal is opened as soon
* as the player has seen a particular object or entered a particular
* area; in other cases, a goal might be opened by a scripted event,
* such as a speech by an NPC telling the player they have to accomplish
* something. A goal could even be opened by viewing a hint for another
* goal, because that hint could explain a gating goal that the player
* might not otherwise been able to know about.
*
* - Undiscovered: this means that the player doesn't yet have any
* reason to know about the goal.
*
* - Closed: this means that the player has accomplished the goal, or in
* some cases that the goal has become irrelevant.
*
* The hint system only shows goals that are Open. We don't show Closed
* goals because the player presumably has no need of them any longer;
* we don't show Undiscovered goals to avoid giving away developments
* later in the game before they become relevant.
*/
class Goal: MenuTopicItem, HintMenuObject, HintOpener
/*
* The topic question associated with the goal. The hint system
* shows a list of the topics for the goals that are currently open,
* so that the player can decide what area they want help on.
*/
title = ''
/*
* Our parent menu - this is usually a HintMenu object. In very
* simple hint systems, this could simply be a top-level hint menu
* container; more typically, the hint system will be structured
* into a menu tree that organizes the hint topics into several
* different submenus, for easier navigatino.
*/
location = nil
/*
* The list of hints for this topic. This should be ordered from
* most general to most specific; we offer the hints in the order
* they appear in this list, so the earlier hints should give away
* as little as possible, while the later hints should get
* progressively closer to just outright giving away the answer.
*
* Each entry in the list can be a simple (single-quoted) string, or
* it can be a Hint object. In most cases, a string will do. A
* Hint object is only needed when displaying the hint has some side
* effect, such as opening a new Goal.
*/
menuContents = []
/*
* Has this goal been fully displayed? The hint system automatically
* sets this to true when the last item in our hint list is
* displayed.
*
* You can use this, for example, to automatically remove the hint
* from the hint menu after it's been fully displayed. (You might
* want to do this with a hint for a red herring, for example. After
* the player has learned that the red herring is a red herring, they
* probably won't need to see that particular line of hints again, so
* you can remove the clutter in the menu by closing the hint after
* it's been fully displayed.) To do this, simply add this to the
* Goal object:
*
*. closeWhenTrue = (goalFullyDisplayed)
*/
goalFullyDisplayed = nil
/*
* Check our menu state and update it if necessary. Each time our
* parent menu is about to display, it'll call this on its sub-items
* to let them update their current states. This method can promote
* the state to Open or Closed if the necessary conditions for the
* goal have been met.
*
* Sometimes it's more convenient to set a goal's state explicitly
* from a scripted event; for example, if the goal is associated
* with a scored achievement, awarding the goal's achievement will
* set the goal's state to Closed. In these cases, there's no need
* to use this method, since you're managing the goal's state
* explicitly. The purpose of this method is to make it easy to
* catch goal state changes that can be reached by several different
* routes; in these cases, you can just write a single test for
* those conditions in this method rather than trying to catch every
* possible route to the new conditions and writing code in all of
* those.
*
* The default implementation looks at our openWhenSeen property.
* If this property is not nil, then we'll check the object
* referenced in this property; if our current state is
* Undiscovered, and the object referenced by openWhenSeen has been
* seen by the player character, then we'll change our state to
* Open. We'll make the corresponding check for openWhenDescribed.
*/
updateContents()
{
/*
* If we're currently Undiscovered, and our openWhenSeen object
* has been seen by the player charater, change our state to
* Open. Likewise, if our gating achievement has been scored,
* open the goal.
*/
if (goalState == UndiscoveredGoal && openWhen)
{
/*
* the player has encountered our gating object, so open
* this goal
*/
goalState = OpenGoal;
}
/*
* if we're currently Undiscovered or Open, and our Achievement
* has been scored, then change our state to Closed - once the
* goal has been achieved, there's no need to offer hints on the
* topic any longer
*/
if (goalState is in (UndiscoveredGoal, OpenGoal) && closeWhen)
{
/* the goal has been achieved, so close it */
goalState = ClosedGoal;
}
}
/* display a sub-item, keeping track of when we've shown them all */
displaySubItem(idx, lastBeforeInput, eol)
{
/* do the inherited work */
inherited(idx, lastBeforeInput, eol);
/* if we just displayed the last item, note it */
if (idx == menuContents.length())
goalFullyDisplayed = true;
}
/* we're active in our parent menu if our goal state is Open */
isActiveInMenu = (goalState == OpenGoal)
/*
* This goal's current state. We'll start off undiscovered. When a
* goal should be open from the very start of the game, this should
* be overridden and set to OpenGoal.
*/
goalState = UndiscoveredGoal
;
/*
* A Hint encapsulates one hint from a topic. In many cases, hints can
* be listed in a topic simply as strings, rather than using Hint
* objects. Hint objects provide a little more control, though; in
* particular, a Hint object can specify some additional code to run
* when the hint is shown, so that it can apply any side effects of
* showing the hint (for example, when a hint is shown, it could mark
* another Goal object as Open, which might be desirable if the hint
* refers to another topic that the player might not yet have
* encountered).
*/
class Hint: MenuTopicSubItem
/* the hint text */
hintText = ''
/*
* A list of other Goal objects that this hint references. By
* default, when we show this hint for the first time, we'll promote
* each goal in this list from Undiscovered to Open.
*
* Sometimes, it's necessary to solve one puzzle before another can
* be solved. In these cases, some hints for the first puzzle
* (which depends on the second), especially the later, more
* specific hints, might need to refer to the other puzzle. This
* would make the player aware of the other puzzle even if they
* weren't already. In such cases, it's a good idea to make sure
* that we make hints for the other puzzle available immediately,
* since otherwise the player might be confused by the absence of
* hints about it.
*/
referencedGoals = []
/*
* Get my hint text. By default, we mark as Open any goals listed
* in our referencedGoals list, then return our hintText string.
* Individual Hint objects can override this as desired to apply any
* additional side effects.
*/
getItemText()
{
/* scan the referenced goals list */
foreach (local cur in referencedGoals)
{
/* if this goal is not yet discovered, open it */
if (cur.goalState == UndiscoveredGoal)
cur.goalState = OpenGoal;
}
/* return our hint text */
return hintText;
}
;
/*
* A hint menu. This same class can be used for the top-level hints
* menu and for sub-menus within the hints menu.
*
* The typical hint menu system will be structured into a top-level hint
* menu that contains a set of sub-menus for the main areas of the game;
* each sub-menu will have a series of Goal items, each Goal providing a
* set of answers to a particular question. Something like this:
*
* topHintMenu: TopHintMenu 'Hints';
*. + HintMenu 'General Questions';
*. ++ Goal 'What am I supposed to be doing?' [answer, answer, answer];
*. ++ Goal 'Amusing things to try' [thing, thing, thing];
*. + HintMenu 'First Area';
*. ++ Goal 'How do I get past the shark?' [answer, answer, answer];
*. ++ Goal 'How do I open the fish tank?' [answer, answer, answer];
*. + HintMenu 'Second Area';
*. ++ Goal 'Where is the gold key?' [answer, answer, answer];
*. ++ Goal 'How do I unlock the gold door?' [answer, answer, answer];
*
* Note that there's no requirement that the hint menu tree takes
* exactly this shape. A very small game could dispense with the
* submenus and simply put all of the goals directly in the top hint
* menu. A very large game with lots of goals could add more levels of
* sub-menus to make it easier to navigate the large number of topics.
*/
class HintMenu: MenuItem, HintMenuObject
/* the menu's title */
title = ''
/* update our contents */
updateContents()
{
local vec = new Vector(16);
/*
* First, run through all of our sub-items, and update their
* contents. We only want to show our active contents, so we
* need to check with each item to find out which is active.
*/
foreach (local cur in allContents)
cur.updateContents();
/* create a vector containing all of our active items */
foreach (local cur in allContents)
{
/* if this item is active, add it to the active vector */
if (cur.isActiveInMenu)
vec.append(cur);
}
/* set our contents list to the list of active items */
contents = vec;
}
/* we're active in a menu if we have any active contents */
isActiveInMenu = (contents.length() != 0)
/* add a sub-item to our contents */
addToContents(obj)
{
/*
* add the sub-item to our allContents list rather than our
* active contents
*/
allContents += obj;
}
/* initialize our contents list */
initializeContents()
{
/* sort our allContents list in the object-defined sorting order */
allContents = allContents.sort(
SortAsc, {a, b: a.compareForTopicSort(b)});
}
/*
* our list of all of our sub-items (some of which may not be
* active, in which case they'll appear in this list but not in our
* 'contents' list, which contains only active contents)
*/
allContents = []
;
/*
* A hint menu version of the long topic menu.
*/
class HintLongTopicItem: MenuLongTopicItem, HintMenuObject
/*
* presume these are always active - they're usually used for things
* like hint system instructions that should always be available
*/
isActiveInMenu = true
;
/*
* Top-level hint menu. As a convenience, an object defined of this
* class will automatically register itself as the top-level hint menu
* during pre-initialization.
*/
class TopHintMenu: HintMenu, PreinitObject
/* register as the top-level hint menu during pre-initialization */
execute() { hintManager.topHintMenuObj = self; }
;
/* ------------------------------------------------------------------------ */
/*
* The default hint system user interface implementation. All of the
* hint-related verbs operate by calling methods in the object stored in
* the global variable gHintSystem, which we'll by default initialize
* with a reference to this object. Games can replace this with their
* own implementations if desired.
*/
hintManager: PreinitObject
/* during pre-initialization, register as the global hint manager */
execute() { gHintManager = self; }
/*
* Disable hints - this is invoked by the HINTS OFF action.
*
* Some users don't like on-line hint systems because they find them
* to be too much of a temptation. To address this concern, we
* provide this HINTS OFF command. Players who want to ensure that
* their will-power won't crumble later on in the face of a
* difficult puzzle can type HINTS OFF early on, before the going
* gets rough; this will disable hints for the rest of the session.
* It's kind of like giving your credit card to a friend before
* going to the mall, making the friend promise that they won't let
* you spend more than such and such an amount, no matter how much
* you beg and plead.
*/
disableHints()
{
/*
* Remember that hints have been disabled. Keep this
* information in the transient session object, since we want
* the disabled status to last for the rest of this session,
* even if we restore or restart later.
*/
sessionHintStatus.hintsDisabled = true;
/* acknowledge it */
DMsg(hints disabled, '<.notification>Hints are now disabled.<./notification> ');
}
/*
* The top-level hint menu. This must be provided by the game, and
* should be set during initialization. If this is nil, hints won't
* be available.
*
* We don't provide a default top-level hint menu because we want to
* give the game maximum flexibility in defining this object exactly
* as it wants. For convenience, an object of class TopHintMenu
* will automatically register itself during pre-initialization -
* but note that there should be only one such object in the entire
* game, since if there are more than one, only one will be
* arbitrarily chosen as the registered object.
*/
topHintMenuObj = nil
/*
* Show hints - invoke the hint system.
*/
showHints()
{
/* if there is no top-level hint menu, no hints are available */
if (topHintMenuObj == nil)
{
Hints.sayHintsNotPresent();
return;
}
/* if hints are disabled, reject the request */
if (sessionHintStatus.hintsDisabled)
{
DMsg(sorry hints disabled, '<.parser>Sorry, but hints have been
disabled for this session, as you requested. If you’ve
changed your mind, you’ll have to save your current
position, exit the TADS interpreter, and start a new interpreter
session.<./parser> ');
return;
}
/* bring the hint menu tree up to date */
topHintMenuObj.updateContents();
/* if there are no hints available, say so and give up */
if (topHintMenuObj.contents.length() == 0)
{
DMsg(currently no hints, '<.parser>Sorry, no hints are currently
available. Please check back later.<./parser> ');
return;
}
/* if we haven't warned about hints, do so now */
if (!showHintWarning())
return;
/* display the hint menu */
topHintMenuObj.display();
/* all done */
DMsg(hints done, '<.parser>Done.<./parser> ');
}
/*
* Show a warning before showing any hints. By default, we'll show
* this at most once per session or once per saved game. Returns
* true if we are to proceed to the hints, nil if not.
*/
showHintWarning()
{
/*
* If we have previously warned in this session, or if we've
* warned in a previous session and the same game was later
* saved and restored, don't warn again. The transient session
* object tells us if we've asked in this session; the normal
* persistent object tells us if we've asked in a previous
* session that we've since saved and restored.
*/
if (!sessionHintStatus.hintWarning && !gameHintStatus.hintWarning)
{
/*
* we haven't asked yet in either the session or the game,
* so show the warning now
*/
cquoteOutputFilter.deactivate();
DMsg(showHintWarning, '<.notification>Warning: Some people
don’t like built-in hints, since the temptation to ask
for help prematurely can become overwhelming when hints are so
close at hand. If you’re worried that your willpower
won’t hold up, you can disable hints for the rest of this
session by typing <<aHref('hints off', 'HINTS OFF')
>>. If you still want to see the hints now, type
<<aHref('hint', 'HINT')>>.<./notification> ');
cquoteOutputFilter.activate();
/* note that we've shown the warning */
sessionHintStatus.hintWarning = true;
gameHintStatus.hintWarning = true;
/* don't proceed to hints now; let them ask again */
return nil;
}
/*
* They've already seen the warning before. It's possible that
* they've seen it in a past session with the game and not
* otherwise during this session, but now that we're accessing
* the hint system once, don't bother with another warning for
* the rest of this session.
*/
sessionHintStatus.hintWarning = true;
/* proceed to the hints */
return true;
}
;
/*
* We keep several pieces of information about the status of the hint
* system. Some of it pertains to the current session, independently of
* any saving/restoring/restarting, so we keep this information in a
* transient object. Some pertains to the present game, so we keep it
* in an ordinary persistent object, so that it's saved and restored
* along with the game.
*/
transient sessionHintStatus: object
/* flag: we've warned about the hint system in this session */
hintWarning = nil
/* flag: we've disabled hints for this session */
hintsDisabled = nil
;
gameHintStatus: object
/* flag: we've warned about the hint system in this session */
hintWarning = nil
;
property achieved;
//==============================================================================
/*
* FRAMEWORK FOR THE EXTRA HINTS MECHANISM
*
* The ExtraHint class provides a framework for providing players (especially
* novice players) with extra hints, nudges, and tips during the course of
* play. When it is activated (either at player request, or because the player
* appears to be having trouble), a hint or tip can be displayed at the end of
* the turn in response to what the player has just typed, or some condition
* that has just become true, or which became true a certain number of turns
* ago.
*
* It is also possible to define conditions (typically the achievement of some
* goal) that render a particular ExtraHint otiose, so that it is not
* displayed if it is no longer needed.
*
* We simply need to define objects of the ExtraHint class to encapsulate the
* extra hints we want displayed.
*
* A series of ExtraHints can be defined using a template if desired.
*
* The first (optional) element in the template (e.g. ->doorAchievement) is
* the achievement we check to see if this ExtraHint has become redundant. For
* example, if the player has already taken the flyer, flyer.achievement has
* been achieved, and so we don't need this first ExtraHint.
*
* The second (optional) element in the template (e.g. +1) is the hintDelay;
* this is number of turns that should elapse between the openWhen condition
* (see below) becoming true and the hint being offered. This optionally
* allows the player a few turns to work on the solution before being offered
* a gratuitous hint.
*
* The third element in the template is simply the text of the extra hint to
* display.
*
* The openWhen property holds the condition that must be true before this
* ExtraHint is displayed. In the case of the first ExtraHint, the condition
* is that the player char has visited the location that contains the
* telephone pole.
*/
class ExtraHint: HintOpener
location = extraHintManager
/*
* The condition under which we close this ExtraHint. By default we close
* it if either hintDone becomes true or our closeWhen condition is true.
*/
checkClose()
{
return hintDone || closeWhen;
}
/*
* The number of turns between openWhen becoming true and this hint
* being displayed.
*/
hintDelay = 0
/*
* If the closeWhen condition is true we remove this ExtraHint from the
* list of potentially active ExtraHints and return nil to tell the
* caller that this ExtraHint was not displayed. Otherwise we check if
* this ExtraHint (a) meets its openWhen conditions to be displayed
* and (b) is due to be displayed because hintDelay turns have passed
* since it was open. If both conditions are met we show our text and
* return true to tell our caller that an ExtraHint has been displayed
* (important since we display at most one ExtraHint per turn).
* Otherwise we return nil.
*/
doHint()
{
if(checkClose())
{
extraHintManager.removeFromContents(self);
return nil;
}
if(openWhen)
{
if(openedWhen == nil)
openedWhen = libGlobal.totalTurns;
if(libGlobal.totalTurns < (openedWhen + hintDelay))
return nil;
showHint();
return true;
}
return nil;
}
/* The text to display in relation to this ExtraHint */
hintText = ""
/* Show the text related to this ExtraHint */
showHint()
{
"<.extrahint>";
if(ofKind(Script))
{
doScript();
/*
* Reset openedWhen so that we don't display this hint again until
* after another hintDelay turns.
*/
openedWhen = libGlobal.totalTurns;
}
else
hintText();
"<./extrahint>";
/*
* Mark this hint as done now we've shown it, unless we're an
* EventList with more items to show.
*/
if(eventList == nil || getScriptState() > eventList.length)
hintDone = true;
}
/* Set the number of turns that must elapse before we display this hint */
setDelay(val)
{
hintDone = nil;
hintDelay = val;
}
/*
* For internal use only: Flag; have we done with this hint (because we've
* displayed it)?
*/
hintDone = nil
/* The turn on which this ExtraHint was first opened */
openedWhen = nil
/*
* Our priority. When two ExtraHints become available on the same term,
* the one with the higher priority will be displayed.
*/
priority = 100
;
extraHintStyleTag: StyleTag 'extrahint' '<.p><i>' '</i><.p>';
/*
* The extraHintManager carries out the work of starting and stopping the
* display of ExtraHints, and determing which, if any, ExtraHint is ready
* to be displayed.
*/
extraHintManager: PreinitObject
/* Start the Daemon that checks whether to display any ExtraHints. */
activate()
{
/*
* First check that our daemonID is nil so we don't start another
* Daemon if one is already running.
*/
if(daemonID == nil)
daemonID = new Daemon(self, &hintDaemon, 1);
}
/*
* Even if this module is included, there may be no ExtraHints defined in
* the game, in which case we might want to check whether any ExtraHints
* exist before offering them to the player.
*/
extraHintsExist()
{
return firstObj(ExtraHint) != nil;
}
/* Stop the Daemon that checks whether to display any ExtraHints. */
deactivate()
{
if(daemonID)
{
daemonID.removeEvent();
daemonID = nil;
}
}
daemonID = nil
/* The extraHintManager is activated if it has a running daemon */
activated = (daemonID != nil)
/*
* When we're active we run through every ExtraHint object in our
* contents and run its doHint() method till either we run out of
* ExtraHint objects or we find one that displays an extra hint, and
* so returns true.
*/
hintDaemon()
{
foreach(local obj in contents)
{
if(obj.doHint())
break;
}
}
contents = []
addToContents(obj) { contents += obj; }
removeFromContents(obj) { contents -= obj; }
/* Build a list of all ExtraHints in our contents property at PreInit */
execute()
{
/* First register our existence */
gExtraHintManager = self;
/* Then add every ExtraHint to our contents */
forEachInstance(ExtraHint, {x: addToContents(x) });
/* Finally sort the ExtraHints in descending order of priority */
contents = contents.sort(SortDesc, {a, b: a.priority - b.priority });
}
explainExtraHints()
{
DMsg(explain extra hints, 'If you\'re new to Interactive Fiction and
would like to read a few extra hints and tips that will pop up here
and there as you explore the story, type <<cmdStr('ON')>>. If you
decide you don\'t want any more of these bonus tips, simply type
<<cmdStr('OFF')>>. ' );
}
cmdStr(stat)
{
return BMsg(extra hint cmd str,
'<<aHref('EXTRA ' + stat, 'EXTRA ' + stat, 'Turning extra hints ' +
stat.toLower)>>');
}
;
class Tip: ExtraHint
showTip()
{
showHint();
shownCount ++;
}
shownCount = 0
closeWhen = (shownCount >= maxTimesToShow)
maxTimesToShow = 1
;
undoTip: Tip
hintText
{
DMsg(undo tip, 'If this didn\'t turn out quite as intended, note that you can
always take back one or more commands by typing UNDO' );
}
;