ScummVM API documentation
conversation.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef ULTIMA4_CONVERSATION_CONVERSATION_H
23#define ULTIMA4_CONVERSATION_CONVERSATION_H
24
25#include "ultima/ultima4/core/utils.h"
26
27namespace Ultima {
28namespace Ultima4 {
29
30class Debug;
31class Person;
32class Script;
33
39public:
40 ResponsePart(const Common::String &value, const Common::String &arg = "", bool command = false);
41
42 operator Common::String() const;
43 bool operator==(const ResponsePart &rhs) const;
44 bool isCommand() const;
45
46private:
47 Common::String _value, _arg;
48 bool _command;
49};
50
55public:
56 const ResponsePart NONE;
57 const ResponsePart ASK;
58 const ResponsePart END;
59 const ResponsePart ATTACK;
60 const ResponsePart BRAGGED;
61 const ResponsePart HUMBLE;
62 const ResponsePart ADVANCELEVELS;
63 const ResponsePart HEALCONFIRM;
64 const ResponsePart STARTMUSIC_LB;
65 const ResponsePart STARTMUSIC_HW;
66 const ResponsePart STOPMUSIC;
67 const ResponsePart HAWKWIND;
68
71};
72
73extern ResponseParts *g_responseParts;
74
79class Response {
80public:
81 Response(const Common::String &response);
82 virtual ~Response() {}
83
84 void add(const ResponsePart &part);
85
86 virtual const Common::Array<ResponsePart> &getParts() const;
87
88 operator Common::String() const;
89
90 Response *addref();
91 void release();
92
93private:
94 int _references;
96};
97
103class DynamicResponse : public Response {
104public:
105 DynamicResponse(Response * (*generator)(const DynamicResponse *), const Common::String &param = "");
106 virtual ~DynamicResponse();
107
108 const Common::Array<ResponsePart> &getParts() const override;
109
110 const Common::String &getParam() const {
111 return _param;
112 }
113
114private:
115 Response *(*_generator)(const DynamicResponse *);
116 Response *_currentResponse;
117 Common::String _param;
118};
119
126class Dialogue {
127public:
131 class Question {
132 public:
133 Question(const Common::String &txt, Response *yes, Response *no);
134
135 Common::String getText();
136 Response *getResponse(bool yes);
137
138 private:
139 Common::String _text;
140 Response *_yesResp, *_noResp;
141 };
142
148 class Keyword {
149 public:
150 Keyword(const Common::String &kw, Response *resp);
151 Keyword(const Common::String &kw, const Common::String &resp);
152 ~Keyword();
153
154 bool operator==(const Common::String &kw) const;
155
156 /*
157 * Accessor methods
158 */
159 const Common::String &getKeyword() {
160 return _keyword;
161 }
162 Response *getResponse() {
163 return _response;
164 }
165
166 private:
167 Common::String _keyword;
168 Response *_response;
169 };
170
175
176 /*
177 * Constructors/Destructors
178 */
179 Dialogue();
180 virtual ~Dialogue();
181
182 /*
183 * Accessor methods
184 */
185 const Common::String &getName() const {
186 return _name;
187 }
188 const Common::String &getPronoun() const {
189 return _pronoun;
190 }
191 const Common::String &getPrompt() const {
192 return _prompt;
193 }
194 Response *getIntro(bool familiar = false) {
195 return _intro;
196 }
197 Response *getLongIntro(bool familiar = false) {
198 return _longIntro;
199 }
200 Response *getDefaultAnswer() {
201 return _defaultAnswer;
202 }
203 Dialogue::Question *getQuestion() {
204 return _question;
205 }
206
207 /*
208 * Getters
209 */
210 void setName(const Common::String &n) {
211 _name = n;
212 }
213 void setPronoun(const Common::String &pn) {
214 _pronoun = pn;
215 }
216 void setPrompt(const Common::String &prompt) {
217 this->_prompt = prompt;
218 }
219 void setIntro(Response *i) {
220 _intro = i;
221 }
222 void setLongIntro(Response *i) {
223 _longIntro = i;
224 }
225 void setDefaultAnswer(Response *a) {
226 _defaultAnswer = a;
227 }
228 void setTurnAwayProb(int prob) {
229 _turnAwayProb = prob;
230 }
231 void setQuestion(Question *q) {
232 _question = q;
233 }
234 void addKeyword(const Common::String &kw, Response *response);
235
236 const ResponsePart &getAction() const;
237 Common::String dump(const Common::String &arg);
238
239 /*
240 * Operators
241 */
242 Keyword *operator[](const Common::String &kw);
243
244private:
245 Common::String _name;
246 Common::String _pronoun;
247 Common::String _prompt;
248 Response *_intro;
249 Response *_longIntro;
250 Response *_defaultAnswer;
251 KeywordMap _keywords;
252 union {
253 int _turnAwayProb;
254 int _attackProb;
255 };
256 Question *_question;
257};
258
265public:
267 enum State {
286 DONE
287 };
288
291 INPUT_STRING,
292 INPUT_CHARACTER,
293 INPUT_NONE
294 };
295
296 /* Constructor/Destructors */
297 Conversation();
299
300 /* Member functions */
301 InputType getInputRequired(int *bufferLen);
302
303 /* Static variables */
304 static const uint BUFFERLEN;
306public:
312 int _quant;
314 int _price;
315};
316
317} // End of namespace Ultima4
318} // End of namespace Ultima
319
320#endif
Definition: array.h:52
Definition: str.h:59
Definition: conversation.h:264
int _price
Definition: conversation.h:314
State _state
Definition: conversation.h:307
State
Definition: conversation.h:267
@ TALK
Definition: conversation.h:269
@ SELL_ITEM
Definition: conversation.h:274
@ ASKYESNO
Definition: conversation.h:271
@ CONTINUEQUESTION
Definition: conversation.h:279
@ FULLHEAL
Definition: conversation.h:282
@ SELL_QUANTITY
Definition: conversation.h:276
@ PLAYER
Definition: conversation.h:281
@ ADVANCELEVELS
Definition: conversation.h:283
@ INTRO
Definition: conversation.h:268
@ GIVEBEGGAR
Definition: conversation.h:284
@ BUY_ITEM
Definition: conversation.h:273
@ VENDORQUESTION
Definition: conversation.h:272
@ CONFIRMATION
Definition: conversation.h:278
@ ATTACK
Definition: conversation.h:285
@ BUY_PRICE
Definition: conversation.h:277
@ ASK
Definition: conversation.h:270
@ TOPIC
Definition: conversation.h:280
@ DONE
Definition: conversation.h:286
@ BUY_QUANTITY
Definition: conversation.h:275
Common::String _playerInput
Definition: conversation.h:308
static const uint BUFFERLEN
Definition: conversation.h:304
InputType
Definition: conversation.h:290
int _quant
Definition: conversation.h:312
Common::List< Common::String > _reply
Definition: conversation.h:309
int _player
Definition: conversation.h:313
Dialogue::Question * _question
Definition: conversation.h:311
class Script * _script
Definition: conversation.h:310
Definition: conversation.h:148
Definition: conversation.h:131
Definition: conversation.h:126
Common::HashMap< Common::String, Keyword * > KeywordMap
Definition: conversation.h:174
Definition: conversation.h:103
Definition: conversation.h:79
Definition: conversation.h:38
Definition: conversation.h:54
Definition: script.h:46