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 #include "ultima/shared/std/containers.h"
27 
28 namespace Ultima {
29 namespace Ultima4 {
30 
31 class Debug;
32 class Person;
33 class Script;
34 
39 class ResponsePart {
40 public:
41  ResponsePart(const Common::String &value, const Common::String &arg = "", bool command = false);
42 
43  operator Common::String() const;
44  bool operator==(const ResponsePart &rhs) const;
45  bool isCommand() const;
46 
47 private:
48  Common::String _value, _arg;
49  bool _command;
50 };
51 
56 public:
57  const ResponsePart NONE;
58  const ResponsePart ASK;
59  const ResponsePart END;
60  const ResponsePart ATTACK;
61  const ResponsePart BRAGGED;
62  const ResponsePart HUMBLE;
63  const ResponsePart ADVANCELEVELS;
64  const ResponsePart HEALCONFIRM;
65  const ResponsePart STARTMUSIC_LB;
66  const ResponsePart STARTMUSIC_HW;
67  const ResponsePart STOPMUSIC;
68  const ResponsePart HAWKWIND;
69 
70  ResponseParts();
71  ~ResponseParts();
72 };
73 
74 extern ResponseParts *g_responseParts;
75 
80 class Response {
81 public:
82  Response(const Common::String &response);
83  virtual ~Response() {}
84 
85  void add(const ResponsePart &part);
86 
87  virtual const Std::vector<ResponsePart> &getParts() const;
88 
89  operator Common::String() const;
90 
91  Response *addref();
92  void release();
93 
94 private:
95  int _references;
97 };
98 
104 class DynamicResponse : public Response {
105 public:
106  DynamicResponse(Response * (*generator)(const DynamicResponse *), const Common::String &param = "");
107  virtual ~DynamicResponse();
108 
109  const Std::vector<ResponsePart> &getParts() const override;
110 
111  const Common::String &getParam() const {
112  return _param;
113  }
114 
115 private:
116  Response *(*_generator)(const DynamicResponse *);
117  Response *_currentResponse;
118  Common::String _param;
119 };
120 
127 class Dialogue {
128 public:
132  class Question {
133  public:
134  Question(const Common::String &txt, Response *yes, Response *no);
135 
136  Common::String getText();
137  Response *getResponse(bool yes);
138 
139  private:
140  Common::String _text;
141  Response *_yesResp, *_noResp;
142  };
143 
149  class Keyword {
150  public:
151  Keyword(const Common::String &kw, Response *resp);
152  Keyword(const Common::String &kw, const Common::String &resp);
153  ~Keyword();
154 
155  bool operator==(const Common::String &kw) const;
156 
157  /*
158  * Accessor methods
159  */
160  const Common::String &getKeyword() {
161  return _keyword;
162  }
163  Response *getResponse() {
164  return _response;
165  }
166 
167  private:
168  Common::String _keyword;
169  Response *_response;
170  };
171 
176 
177  /*
178  * Constructors/Destructors
179  */
180  Dialogue();
181  virtual ~Dialogue();
182 
183  /*
184  * Accessor methods
185  */
186  const Common::String &getName() const {
187  return _name;
188  }
189  const Common::String &getPronoun() const {
190  return _pronoun;
191  }
192  const Common::String &getPrompt() const {
193  return _prompt;
194  }
195  Response *getIntro(bool familiar = false) {
196  return _intro;
197  }
198  Response *getLongIntro(bool familiar = false) {
199  return _longIntro;
200  }
201  Response *getDefaultAnswer() {
202  return _defaultAnswer;
203  }
204  Dialogue::Question *getQuestion() {
205  return _question;
206  }
207 
208  /*
209  * Getters
210  */
211  void setName(const Common::String &n) {
212  _name = n;
213  }
214  void setPronoun(const Common::String &pn) {
215  _pronoun = pn;
216  }
217  void setPrompt(const Common::String &prompt) {
218  this->_prompt = prompt;
219  }
220  void setIntro(Response *i) {
221  _intro = i;
222  }
223  void setLongIntro(Response *i) {
224  _longIntro = i;
225  }
226  void setDefaultAnswer(Response *a) {
227  _defaultAnswer = a;
228  }
229  void setTurnAwayProb(int prob) {
230  _turnAwayProb = prob;
231  }
232  void setQuestion(Question *q) {
233  _question = q;
234  }
235  void addKeyword(const Common::String &kw, Response *response);
236 
237  const ResponsePart &getAction() const;
238  Common::String dump(const Common::String &arg);
239 
240  /*
241  * Operators
242  */
243  Keyword *operator[](const Common::String &kw);
244 
245 private:
246  Common::String _name;
247  Common::String _pronoun;
248  Common::String _prompt;
249  Response *_intro;
250  Response *_longIntro;
251  Response *_defaultAnswer;
252  KeywordMap _keywords;
253  union {
254  int _turnAwayProb;
255  int _attackProb;
256  };
257  Question *_question;
258 };
259 
266 public:
268  enum State {
271  ASK,
287  DONE
288  };
289 
291  enum InputType {
292  INPUT_STRING,
293  INPUT_CHARACTER,
294  INPUT_NONE
295  };
296 
297  /* Constructor/Destructors */
298  Conversation();
299  ~Conversation();
300 
301  /* Member functions */
302  InputType getInputRequired(int *bufferLen);
303 
304  /* Static variables */
305  static const uint BUFFERLEN;
307 public:
311  class Script *_script;
313  int _quant;
314  int _player;
315  int _price;
316 };
317 
318 } // End of namespace Ultima4
319 } // End of namespace Ultima
320 
321 #endif
int _quant
Definition: conversation.h:313
Definition: conversation.h:269
Definition: str.h:59
Definition: script.h:46
Definition: conversation.h:277
Definition: conversation.h:286
Definition: conversation.h:284
Definition: conversation.h:275
class Script * _script
Definition: conversation.h:311
Definition: conversation.h:273
Definition: conversation.h:55
int _player
Definition: conversation.h:314
Definition: conversation.h:270
Definition: conversation.h:276
Common::List< Common::String > _reply
Definition: conversation.h:310
static const uint BUFFERLEN
Definition: conversation.h:305
Common::HashMap< Common::String, Keyword * > KeywordMap
Definition: conversation.h:175
InputType
Definition: conversation.h:291
int _price
Definition: conversation.h:315
Definition: detection.h:27
Dialogue::Question * _question
Definition: conversation.h:312
Definition: conversation.h:282
Common::String _playerInput
Definition: conversation.h:309
State _state
Definition: conversation.h:308
State
Definition: conversation.h:268
Definition: conversation.h:283
Definition: conversation.h:39
Definition: conversation.h:149
Definition: conversation.h:132
Definition: conversation.h:272
Definition: conversation.h:104
Definition: conversation.h:278
Definition: conversation.h:271
Definition: conversation.h:80
Definition: conversation.h:274
Definition: conversation.h:265
Definition: conversation.h:285
Definition: conversation.h:281
Definition: containers.h:38
Definition: conversation.h:127
Definition: conversation.h:279