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 
27 namespace Ultima {
28 namespace Ultima4 {
29 
30 class Debug;
31 class Person;
32 class Script;
33 
38 class ResponsePart {
39 public:
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 
46 private:
47  Common::String _value, _arg;
48  bool _command;
49 };
50 
55 public:
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 
69  ResponseParts();
70  ~ResponseParts();
71 };
72 
73 extern ResponseParts *g_responseParts;
74 
79 class Response {
80 public:
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 
93 private:
94  int _references;
96 };
97 
103 class DynamicResponse : public Response {
104 public:
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 
114 private:
115  Response *(*_generator)(const DynamicResponse *);
116  Response *_currentResponse;
117  Common::String _param;
118 };
119 
126 class Dialogue {
127 public:
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 
244 private:
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 
265 public:
267  enum State {
270  ASK,
286  DONE
287  };
288 
290  enum InputType {
291  INPUT_STRING,
292  INPUT_CHARACTER,
293  INPUT_NONE
294  };
295 
296  /* Constructor/Destructors */
297  Conversation();
298  ~Conversation();
299 
300  /* Member functions */
301  InputType getInputRequired(int *bufferLen);
302 
303  /* Static variables */
304  static const uint BUFFERLEN;
306 public:
310  class Script *_script;
312  int _quant;
313  int _player;
314  int _price;
315 };
316 
317 } // End of namespace Ultima4
318 } // End of namespace Ultima
319 
320 #endif
int _quant
Definition: conversation.h:312
Definition: conversation.h:268
Definition: str.h:59
Definition: script.h:46
Definition: conversation.h:276
Definition: conversation.h:285
Definition: conversation.h:283
Definition: array.h:52
Definition: conversation.h:274
class Script * _script
Definition: conversation.h:310
Definition: conversation.h:272
Definition: conversation.h:54
int _player
Definition: conversation.h:313
Definition: conversation.h:269
Definition: conversation.h:275
Common::List< Common::String > _reply
Definition: conversation.h:309
static const uint BUFFERLEN
Definition: conversation.h:304
Common::HashMap< Common::String, Keyword * > KeywordMap
Definition: conversation.h:174
InputType
Definition: conversation.h:290
int _price
Definition: conversation.h:314
Definition: detection.h:27
Dialogue::Question * _question
Definition: conversation.h:311
Definition: conversation.h:281
Common::String _playerInput
Definition: conversation.h:308
State _state
Definition: conversation.h:307
State
Definition: conversation.h:267
Definition: conversation.h:282
Definition: conversation.h:38
Definition: conversation.h:148
Definition: conversation.h:131
Definition: conversation.h:271
Definition: conversation.h:103
Definition: conversation.h:277
Definition: conversation.h:270
Definition: conversation.h:79
Definition: conversation.h:273
Definition: conversation.h:264
Definition: conversation.h:284
Definition: conversation.h:280
Definition: conversation.h:126
Definition: conversation.h:278