ScummVM API documentation
conversations.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 MADS_CONVERSATIONS_H
23 #define MADS_CONVERSATIONS_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "common/str-array.h"
28 #include "mads/screen.h"
29 #include "mads/dialogs.h"
30 
31 namespace MADS {
32 
33 #define MAX_CONVERSATIONS 5
34 #define MAX_SPEAKERS 5
35 
36 enum ConversationMode {
37  CONVMODE_NONE = -1,
38  CONVMODE_NEXT = 0,
39  CONVMODE_WAIT_AUTO = 1,
40  CONVMODE_WAIT_ENTRY = 2,
41  CONVMODE_EXECUTE = 3,
42  CONVMODE_REPLY = 4,
43  CONVMODE_5 = 5,
44  CONVMODE_6 = 6,
45  CONVMODE_7 = 7,
46  CONVMODE_8 = 8,
47  CONVMODE_9 = 9,
48  CONVMODE_STOP = 10
49 };
50 
51 enum DialogCommand {
52  CMD_END = 0,
53  CMD_1 = 1,
54  CMD_HIDE = 2,
55  CMD_UNHIDE = 3,
56  CMD_MESSAGE1 = 4,
57  CMD_MESSAGE2 = 5,
58  CMD_ERROR = 6,
59  CMD_NODE = 7,
60  CMD_GOTO = 8,
61  CMD_ASSIGN = 9,
62  CMD_DIALOG_END = 255
63 };
64 
65 enum ConvEntryFlag {
66  ENTRYFLAG_2 = 2,
67  ENTRYFLAG_4000 = 0x4000,
68  ENTRYFLAG_8000 = 0x8000
69 };
70 
71 enum ConditionalOperation {
72  CONDOP_NONE = 0xff,
73  CONDOP_VALUE = 0,
74  CONDOP_ADD = 1,
75  CONDOP_SUBTRACT = 2,
76  CONDOP_MULTIPLY = 3,
77  CONDOP_DIVIDE = 4,
78  CONDOP_MODULUS = 5,
79  CONDOP_LTEQ = 6,
80  CONDOP_GTEQ = 7,
81  CONDOP_LT = 8,
82  CONDOP_GT = 9,
83  CONDOP_NEQ = 10,
84  CONDOP_EQ = 11,
85  CONDOP_AND = 12,
86  CONDOP_OR = 13,
87  CONDOP_ABORT = 0xff
88 };
89 
90 
92  bool _isPtr;
93  int _val;
94  int *_valPtr;
95 
99  ConversationVar() : _isPtr(false), _val(0), _valPtr(nullptr) {}
100 
104  void setValue(int val);
105 
109  void setValue(int *val);
110 
114  int *getValue() { return _isPtr ? _valPtr : &_val; }
115 
119  bool isPtr() const { return _isPtr; }
120 
124  bool isNumeric() const { return !_isPtr; }
125 };
126 
127 struct ScriptEntry {
128  struct Conditional {
130  bool _isVariable;
131  int _val;
132 
136  CondtionalParamEntry() : _isVariable(false), _val(0) {}
137  };
138 
139  static Common::Array<ConversationVar> *_vars;
140  ConditionalOperation _operation;
141  CondtionalParamEntry _param1;
142  CondtionalParamEntry _param2;
143 
147  Conditional() : _operation(CONDOP_NONE) {}
148 
152  void load(Common::SeekableReadStream &s);
153 
157  int get(int paramNum) const;
158 
162  int evaluate() const;
163  };
164 
165  struct MessageEntry {
166  int _size;
167  int _v2;
168 
169  MessageEntry() : _size(0), _v2(0) {}
170  };
171 
172  DialogCommand _command;
173  Conditional _conditionals[3];
174 
175  // Extra parameters for different opcodes
176  int _index;
177  Common::Array<int> _entries;
178  Common::Array<MessageEntry> _entries2;
179 
183  ScriptEntry() : _command(CMD_END), _index(0) {}
184 
188  void load(Common::SeekableReadStream &s);
189 };
190 
194 class DialogScript : public Common::Array<ScriptEntry> {
195 public:
199  void load(Common::SeekableReadStream &s, uint startingOffset);
200 };
201 
205 struct ConvDialog {
206  struct ScriptEntry {
207  DialogCommand _command;
208  };
209 
210  int16 _textLineIndex; // 0-based
211  int16 _speechIndex; // 1-based
212  uint16 _scriptOffset; // offset of script entry
213  uint16 _scriptSize; // size of script entry
214 
215  DialogScript _script;
216 };
217 
221 struct ConvNode {
222  uint16 _index;
223  uint16 _dialogCount;
224  int16 _unk1;
225  bool _active;
226  int16 _unk3;
227 
228  Common::Array<ConvDialog> _dialogs;
229 };
230 
234 struct ConvMessage {
235  uint _stringIndex;
236  uint _count;
237 
238  ConvMessage() : _stringIndex(0), _count(0) {}
239 };
240 
245  uint16 _nodeCount; // conversation nodes, each one containing several dialog options and messages
246  uint16 _dialogCount; // messages (non-selectable) + texts (selectable)
247  uint16 _messageCount; // messages (non-selectable)
248  uint16 _textLineCount;
249  uint16 _unk2;
250  uint16 _maxImports;
251  uint16 _speakerCount;
252  int _textSize;
253  int _commandsSize;
254 
255  Common::Path _portraits[MAX_SPEAKERS];
256  int _speakerFrame[MAX_SPEAKERS];
257  Common::Path _speechFile;
258  Common::Array<ConvMessage> _messages;
259  Common::StringArray _textLines;
261  Common::Array<ConvDialog> _dialogs;
262 
266  void load(const Common::Path &filename);
267 };
268 
273  Common::Array<uint> _importVariables;
274  Common::Array<uint> _entryFlags;
276  int _numImports;
277 
278  int _currentNode;
279  Common::Array<int> _playerMessageList;
280  Common::Array<int> _actorMessageList;
281  Common::Array<int> _playerSpeechList;
282  Common::Array<int> _actorSpeechList;
283 
288 
292  void load(const Common::Path &filename);
293 };
294 
299  int _convId;
300  ConversationData _data;
302 };
303 
304 class MADSEngine;
305 
310 private:
311  MADSEngine *_vm;
312  ConversationEntry _conversations[MAX_CONVERSATIONS];
313  bool _speakerActive[MAX_SPEAKERS];
314  int _speakerSeries[MAX_SPEAKERS];
315  int _speakerFrame[MAX_SPEAKERS];
316  int _popupX[MAX_SPEAKERS];
317  int _popupY[MAX_SPEAKERS];
318  int _popupMaxLen[MAX_SPEAKERS];
319  InputMode _inputMode;
320  bool _popupVisible;
321  ConversationMode _currentMode;
322  ConversationMode _priorMode;
323  int _verbId;
324  int _speakerVal;
325  int _heroTrigger;
326  TriggerMode _heroTriggerMode;
327  int _interlocutorTrigger;
328  TriggerMode _interlocutorTriggerMode;
329  ConversationEntry *_runningConv;
330  int _restoreRunning;
331  bool _playerEnabled;
332  uint32 _startFrameNumber;
333  ConversationVar *_vars;
334  ConversationVar *_nextStartNode;
335  int _currentNode;
336  int _dialogNodeOffset, _dialogNodeSize;
337  int _personSpeaking;
338  TextDialog *_dialog;
339  bool _dialogAltFlag;
340 
344  ConversationEntry *getConv(int convId);
345 
349  void start();
350 
354  void removeActiveWindow();
355 
359  void flagEntry(DialogCommand mode, int entryIndex);
360 
364  ConversationMode generateMenu();
365 
369  void generateText(int textLineIndex, Common::Array<int> &messages);
370 
374  void generateMessage(Common::Array<int> &messageList, Common::Array<int> &voiecList);
375 
379  bool nextNode();
380 
384  int executeEntry(int index);
385 
389  void scriptMessage(ScriptEntry &scrEntry);
390 
394  bool scriptNode(ScriptEntry &scrEntry);
395 public:
400 
404  virtual ~GameConversations();
405 
410  void load(int id);
411 
416  void run(int id);
417 
421  void setVariable(uint idx, int val);
422 
426  void setVariable(uint idx, int *val);
427 
431  void setStartNode(uint nodeIndex);
432 
436  void setHeroTrigger(int val);
437 
441  void setInterlocutorTrigger(int val);
442 
447  int *getVariable(int idx);
448 
452  void hold();
453 
457  void release();
458 
462  void stop();
463 
467  void exportPointer(int *ptr);
468 
472  void exportValue(int val);
473 
474  void reset(int id);
475 
479  void update(bool flag);
480 
484  bool active() const { return _runningConv != nullptr; }
485 
489  int activeConvId() const { return !active() ? -1 : _runningConv->_convId; }
490 
494  int restoreRunning() const { return _restoreRunning; }
495 
499  ConversationMode currentMode() const { return _currentMode; }
500 };
501 
502 } // End of namespace MADS
503 
504 #endif /* MADS_CONVERSATIONS_H */
Conditional()
Definition: conversations.h:147
bool isPtr() const
Definition: conversations.h:119
Definition: conversations.h:298
Definition: conversations.h:234
Definition: dialogs.h:101
Definition: conversations.h:272
int * getValue()
Definition: conversations.h:114
Definition: array.h:52
void setValue(int val)
int restoreRunning() const
Definition: conversations.h:494
Definition: conversations.h:244
Definition: path.h:52
Definition: stream.h:745
Definition: conversations.h:205
ScriptEntry()
Definition: conversations.h:183
Definition: conversations.h:221
Definition: conversations.h:206
bool isNumeric() const
Definition: conversations.h:124
Definition: conversations.h:127
ConversationMode currentMode() const
Definition: conversations.h:499
Definition: mads.h:87
ConversationVar()
Definition: conversations.h:99
CondtionalParamEntry()
Definition: conversations.h:136
bool active() const
Definition: conversations.h:484
Definition: action.h:28
Definition: conversations.h:194
Definition: conversations.h:128
int activeConvId() const
Definition: conversations.h:489
Definition: conversations.h:309
Definition: conversations.h:129
Definition: conversations.h:91
Definition: conversations.h:165