-
Notifications
You must be signed in to change notification settings - Fork 11
/
thoughts.t
140 lines (113 loc) · 4.31 KB
/
thoughts.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
#charset "us-ascii"
#include "advlite.h"
/*
* *************************************************************************
* thoughts.t
*
* This module forms part of the adv3Lite library (c) 2012-13 Eric Eve
*
*
* This file adds support for a THINK about command
*/
property thinkDesc;
/*
* The base clase for a thought manager object. To use this in a game create a
* single object of this class and locate a number of Thought objects in it
* (with the + notation) to represent responses to THINK ABOUT
*/
class ThoughtManager: PreinitObject, TopicDatabase
/* Carry out the ThoughtManager's preinitialization */
execute()
{
/* Register this object as the game's intial thoughtManager object. */
if(thinker == nil || thinker == gameMain.initialPlayerChar)
{
libGlobal.thoughtManagerObj = self;
gPlayerChar.myThoughtManager = self;
}
else if(thinker)
thinker.myThoughtManager = self;
/*
* Add every Thought object that's located in us to our topic entry
* list
*/
forEachInstance(Thought, new function(t) {
if(t.location == self)
addTopic(t);
});
}
/* Handle a THINK ABOUT command. */
handleTopic(top)
{
/* First get the best match to the topic we want to think about */
local match = getBestMatch(thoughtList, top);
/* If we didn't find a match, display a message to that effect. */
if(match == nil)
say(noThoughtMsg);
/* Otherwise have our best match display its reponse. */
else
match.handleResponse();
}
/* The list of Thoughts associated with this ThoughtManager object */
thoughtList = []
/* The message to display when we don't find a matching Thought */
noThoughtMsg = BMsg(no thoughts, '{I} {have} no thoughts on that particular
topic.')
/* Our actor is the actor who's doing the thinking. */
getActor = (gActor)
/*
* The person whose thoughts are located in this ThoughtManager. If the player character never
* changes in this game and/or you only define one ThoughtManager, this can be left at nil;
* otherwise you should override this property to point to the actor whose thoughta are being
* managed by this object.
*/
thinker = nil
;
/*
* A kind of TopicEntry that responds to a THINK ABOUT command when located in
* a ThoughtManager object. These can be defined just like any other topic
* entry objects, and work in just the same way as ConsultTopics.
*/
class Thought: TopicEntry
includeInList = [&thoughtList]
/*
* On a Thought our handleResponse() method simply calls out topicResponse() method. We
* separate the two to allow DefaultThought to do something different.
*/
handleResponse() { topicResponse(); }
;
/*
* A DefaultThought is a Thought that matches any THINK ABOUT command with a
* very low match score, so that any more specific Thought that's matched will
* take precedence. Game code can use this to provide a fall-back response
* when no more specific response is available.
*/
class DefaultThought: Thought
matchObj = [Thing, Topic ]
matchTopic(top)
{
/* Note the Topic we matched. */
topicMatched = top;
/*
* Since we can match anything, simply return the sum of our matchScore and our
* scoreBoost.
*/
return matchScore + scoreBooster();
}
matchScore = 1
handleResponse()
{
/*
* If the topic we matched defines a thinkDesc property, use that thinkDesc property to
* preovide our response. Otherwise use our topicResponse.
*/
if(!((topicMatched.propDefined(&thinkDesc) && topicMatched.propType(&hinkDesc) != TypeNil)
&& topicMatched.displayAlt(&thinkDesc, location.noThoughtMsg)))
topicResponse();
}
/*
* By default, take our topicResponse from our thoughtManager's noThoughtMsg. Game code can
* override to provide a different response here.
*/
topicResponse() { "<<location.noThoughtMsg>>"; }
;