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/core/screen.h"
29 #include "mads/core/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 class RexNebularEngine;
91 
93  bool _isPtr;
94  int _val;
95  int *_valPtr;
96 
100  ConversationVar() : _isPtr(false), _val(0), _valPtr(nullptr) {}
101 
105  void setValue(int val);
106 
110  void setValue(int *val);
111 
115  int *getValue() { return _isPtr ? _valPtr : &_val; }
116 
120  bool isPtr() const { return _isPtr; }
121 
125  bool isNumeric() const { return !_isPtr; }
126 };
127 
128 struct ScriptEntry {
129  struct Conditional {
131  bool _isVariable;
132  int _val;
133 
137  CondtionalParamEntry() : _isVariable(false), _val(0) {}
138  };
139 
140  static Common::Array<ConversationVar> *_vars;
141  ConditionalOperation _operation;
142  CondtionalParamEntry _param1;
143  CondtionalParamEntry _param2;
144 
148  Conditional() : _operation(CONDOP_NONE) {}
149 
153  void load(Common::SeekableReadStream &s);
154 
158  int get(int paramNum) const;
159 
163  int evaluate() const;
164  };
165 
166  struct MessageEntry {
167  int _size;
168  int _v2;
169 
170  MessageEntry() : _size(0), _v2(0) {}
171  };
172 
173  DialogCommand _command;
174  Conditional _conditionals[3];
175 
176  // Extra parameters for different opcodes
177  int _index;
178  Common::Array<int> _entries;
179  Common::Array<MessageEntry> _entries2;
180 
184  ScriptEntry() : _command(CMD_END), _index(0) {}
185 
189  void load(Common::SeekableReadStream &s);
190 };
191 
195 class DialogScript : public Common::Array<ScriptEntry> {
196 public:
200  void load(Common::SeekableReadStream &s, uint startingOffset);
201 };
202 
206 struct ConvDialog {
207  struct ScriptEntry {
208  DialogCommand _command;
209  };
210 
211  int16 _textLineIndex; // 0-based
212  int16 _speechIndex; // 1-based
213  uint16 _scriptOffset; // offset of script entry
214  uint16 _scriptSize; // size of script entry
215 
216  DialogScript _script;
217 };
218 
222 struct ConvNode {
223  uint16 _index;
224  uint16 _dialogCount;
225  int16 _unk1;
226  bool _active;
227  int16 _unk3;
228 
229  Common::Array<ConvDialog> _dialogs;
230 };
231 
235 struct ConvMessage {
236  uint _stringIndex;
237  uint _count;
238 
239  ConvMessage() : _stringIndex(0), _count(0) {}
240 };
241 
246  uint16 _nodeCount; // conversation nodes, each one containing several dialog options and messages
247  uint16 _dialogCount; // messages (non-selectable) + texts (selectable)
248  uint16 _messageCount; // messages (non-selectable)
249  uint16 _textLineCount;
250  uint16 _unk2;
251  uint16 _maxImports;
252  uint16 _speakerCount;
253  int _textSize;
254  int _commandsSize;
255 
256  Common::Path _portraits[MAX_SPEAKERS];
257  int _speakerFrame[MAX_SPEAKERS];
258  Common::Path _speechFile;
259  Common::Array<ConvMessage> _messages;
260  Common::StringArray _textLines;
262  Common::Array<ConvDialog> _dialogs;
263 
267  void load(const Common::Path &filename);
268 };
269 
274  Common::Array<uint> _importVariables;
275  Common::Array<uint> _entryFlags;
277  int _numImports;
278 
279  int _currentNode;
280  Common::Array<int> _playerMessageList;
281  Common::Array<int> _actorMessageList;
282  Common::Array<int> _playerSpeechList;
283  Common::Array<int> _actorSpeechList;
284 
289 
293  void load(const Common::Path &filename);
294 };
295 
300  int _convId;
301  ConversationData _data;
303 };
304 
305 class MADSEngine;
306 
311 private:
312  RexNebularEngine *_vm;
313  ConversationEntry _conversations[MAX_CONVERSATIONS];
314  bool _speakerActive[MAX_SPEAKERS];
315  int _speakerSeries[MAX_SPEAKERS];
316  int _speakerFrame[MAX_SPEAKERS];
317  int _popupX[MAX_SPEAKERS];
318  int _popupY[MAX_SPEAKERS];
319  int _popupMaxLen[MAX_SPEAKERS];
320  InputMode _inputMode;
321  bool _popupVisible;
322  ConversationMode _currentMode;
323  ConversationMode _priorMode;
324  int _verbId;
325  int _speakerVal;
326  int _heroTrigger;
327  TriggerMode _heroTriggerMode;
328  int _interlocutorTrigger;
329  TriggerMode _interlocutorTriggerMode;
330  ConversationEntry *_runningConv;
331  int _restoreRunning;
332  bool _playerEnabled;
333  uint32 _startFrameNumber;
334  ConversationVar *_vars;
335  ConversationVar *_nextStartNode;
336  int _currentNode;
337  int _dialogNodeOffset, _dialogNodeSize;
338  int _personSpeaking;
339  TextDialog *_dialog;
340  bool _dialogAltFlag;
341 
345  ConversationEntry *getConv(int convId);
346 
350  void start();
351 
355  void removeActiveWindow();
356 
360  void flagEntry(DialogCommand mode, int entryIndex);
361 
365  ConversationMode generateMenu();
366 
370  void generateText(int textLineIndex, Common::Array<int> &messages);
371 
375  void generateMessage(Common::Array<int> &messageList, Common::Array<int> &voiecList);
376 
380  bool nextNode();
381 
385  int executeEntry(int index);
386 
390  void scriptMessage(ScriptEntry &scrEntry);
391 
395  bool scriptNode(ScriptEntry &scrEntry);
396 public:
401 
405  virtual ~GameConversations();
406 
411  void load(int id);
412 
417  void run(int id);
418 
422  void setVariable(uint idx, int val);
423 
427  void setVariable(uint idx, int *val);
428 
432  void setStartNode(uint nodeIndex);
433 
437  void setHeroTrigger(int val);
438 
442  void setInterlocutorTrigger(int val);
443 
448  int *getVariable(int idx);
449 
453  void hold();
454 
458  void release();
459 
463  void stop();
464 
468  void exportPointer(int *ptr);
469 
473  void exportValue(int val);
474 
475  void reset(int id);
476 
480  void update(bool flag);
481 
485  bool active() const { return _runningConv != nullptr; }
486 
490  int activeConvId() const { return !active() ? -1 : _runningConv->_convId; }
491 
495  int restoreRunning() const { return _restoreRunning; }
496 
500  ConversationMode currentMode() const { return _currentMode; }
501 };
502 
503 } // namespace MADS
504 
505 #endif /* MADS_CONVERSATIONS_H */
Conditional()
Definition: conversations.h:148
bool isPtr() const
Definition: conversations.h:120
Definition: conversations.h:299
Definition: conversations.h:235
Definition: dialogs.h:103
Definition: conversations.h:273
int * getValue()
Definition: conversations.h:115
Definition: array.h:52
void setValue(int val)
int restoreRunning() const
Definition: conversations.h:495
Definition: conversations.h:245
Definition: path.h:52
Definition: stream.h:745
Definition: conversations.h:206
ScriptEntry()
Definition: conversations.h:184
Definition: nebular.h:50
Definition: conversations.h:222
Definition: conversations.h:207
bool isNumeric() const
Definition: conversations.h:125
Definition: conversations.h:128
ConversationMode currentMode() const
Definition: conversations.h:500
Definition: mads.h:68
ConversationVar()
Definition: conversations.h:100
CondtionalParamEntry()
Definition: conversations.h:137
bool active() const
Definition: conversations.h:485
Definition: action.h:28
Definition: conversations.h:195
Definition: conversations.h:129
int activeConvId() const
Definition: conversations.h:490
Definition: conversations.h:310
Definition: conversations.h:130
Definition: conversations.h:92
Definition: conversations.h:166