ScummVM API documentation
conv.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_CORE_CONV_H
23 #define MADS_CORE_CONV_H
24 
25 #include "common/array.h"
26 #include "common/stream.h"
27 
28 namespace MADS {
29 namespace MADSV2 {
30 
31 // Return of the Phantom needs 40, Dragonsphere needs 70
32 constexpr int CONV_MAX_SLOTS = 70;
33 constexpr int CONV_MAX_DATA = 5;
34 
35 enum ConvStatus {
36  CONV_STATUS_HOLDING = -1,
37  CONV_STATUS_NEXT_NODE = 0,
38  CONV_STATUS_WAIT_AUTO = 1,
39  CONV_STATUS_WAIT_ENTRY = 2,
40  CONV_STATUS_EXECUTE = 3,
41  CONV_STATUS_REPLY = 4,
42  CONV_STATUS_DONE = 10 // conversation finished; next update calls conv_abort
43 };
44 
45 // Operator codes used inside conversation script expressions.
46 // Stored as int16 on disk; 0 = identity (return param1), 255 = no expression.
47 enum ConvOp : int16 {
48  CONV_OP_VALUE = 0, // No operator — return param1 directly
49  CONV_OP_ADD = 1, // param1 + param2
50  CONV_OP_SUB = 2, // param1 - param2
51  CONV_OP_MUL = 3, // param1 * param2
52  CONV_OP_DIV = 4, // param1 / param2 (signed integer)
53  CONV_OP_MOD = 5, // param1 % param2 (signed remainder)
54  CONV_OP_GE = 6, // param1 >= param2
55  CONV_OP_LE = 7, // param1 <= param2
56  CONV_OP_GT = 8, // param1 > param2
57  CONV_OP_LT = 9, // param1 < param2
58  CONV_OP_NE = 10, // param1 != param2
59  CONV_OP_EQ = 11, // param1 == param2
60  CONV_OP_AND = 12, // param1 && param2 (logical)
61  CONV_OP_OR = 13, // param1 || param2 (logical)
62  CONV_OP_NONE = 255 // No expression — evaluates to -1
63 };
64 
65 struct ConvNode {
66  int16 index;
67  int16 dialog_count;
68  int16 active;
69  int16 field_6;
70  int16 field_8;
71 
72  static constexpr int SIZE = 2 * 5;
73  void load(Common::SeekableReadStream *src);
74 };
75 
76 struct ConvDialog {
77  int16 text_line_index;
78  int16 speech_index;
79  int16 script_offset;
80  int16 script_size;
81 
82  static constexpr int SIZE = 2 * 4;
83  void load(Common::SeekableReadStream *src);
84 };
85 
87  ConvOp operation;
88  byte param1IsVar;
89  byte param2IsVar;
90  int16 param1;
91  int16 param2;
92 
93  static constexpr int SIZE = 2 + 1 + 1 + 2 + 2;
94  void load(Common::SeekableReadStream *src);
95 };
96 
97 struct ConvVariable {
98  enum PtrType { PTRTYPE_GLOBAL = 1, PTRTYPE_CONV_CONTROL = 2 };
99 
100  bool isPtr = false;
101  int16 val = 0, type = 0;
102  int16 *ptr;
103 
104  static constexpr int SIZE = 2 * 3;
105  void load(Common::SeekableReadStream *src);
106  void save(Common::WriteStream *dest) const;
107 };
108 
109 struct Conv {
110  int16 node_count;
111  int16 dialog_count;
112  int16 message_count;
113  int16 text_line_count;
114  int16 num_variables;
115 
116  int16 max_imports;
117  int16 speaker_count;
118  char speaker_portraits[5][16];
119  int16 speaker_frame[5];
120  char speech_file[14];
121  uint32 text_length;
122  uint32 commands_length;
123 
124  struct LineSet {
125  int lineStart = 0;
126  int lineCount = 0;
127  };
128 
131  Common::Array<LineSet> messages;
132  Common::Array<char> text;
133  Common::Array<byte> scripts;
134  Common::Array<uint16> textLines;
135 
136  static constexpr int SIZE = (2 * 7 + 16 * 5 + 2 * 5 + 14 + 4 + 4) +
137  // Padding for pointers in original structure
138  4 * 6;
139  void load(Common::SeekableReadStream *src);
140 };
141 
142 struct ConvData {
143  int16 currentNode;
144  int16 entryFlagsCount;
145  int16 variablesCount;
146  int16 importsCount;
147  int16 numImports;
148  int16 optionListSize;
149  int16 messageList1Size;
150  int16 messageList2Size;
151  int16 speechList1Size;
152  int16 speechList2Size;
153  int16 optionList[10];
154  int16 messageList1[10];
155  int16 messageList2[10];
156  int16 speechList1[10];
157  int16 speechList2[10];
158 
159  uint16 importsOffset;
160  uint16 entryFlagsOffset;
161  uint16 variablesOffset;
162  Common::Array<int16> imports;
163  Common::Array<uint16> entryFlags;
164  Common::Array<ConvVariable> variables;
165 
166  static constexpr int SIZE = 2 * 10 + 2 * 10 * 5 + 2 * 3;
167  void load(Common::SeekableReadStream *src);
168  void save(Common::WriteStream *dest) const;
169 };
170 
171 struct ConvControl {
172  int16 running;
173  int16 index;
174  ConvStatus status;
175  ConvStatus hold_status;
176  int16 has_text;
177  int16 popup_is_up;
178  int16 popup_duration;
179  long popup_clock;
180  int16 speaker_active[CONV_MAX_DATA];
181  int16 speaker_series[CONV_MAX_DATA];
182  int16 speaker_frame[CONV_MAX_DATA];
183  int16 x[CONV_MAX_DATA];
184  int16 y[CONV_MAX_DATA];
185  int16 width[CONV_MAX_DATA];
186  int16 speaker_val;
187  int16 person_speaking;
188  int16 node;
189  int16 entry;
190  int16 me_trigger;
191  int16 me_trigger_mode;
192  int16 you_trigger;
193  int16 you_trigger_mode;
194  int16 commands_allowed;
195  int16 input_mode;
196 };
197 
198 extern Conv *conv[CONV_MAX_DATA];
199 extern ConvData *conv_data[CONV_MAX_DATA];
200 extern Conv *active_conv;
201 extern ConvData *active_conv_data;
202 
203 extern int16 *conv_imports;
204 extern uint16 *conv_entry_flags;
205 extern ConvVariable *conv_varsDataPtr;
206 extern int16 *conv_vars0ValPtr;
207 
208 extern int conv_restore_running;
209 extern ConvControl conv_control;
210 extern int16 *conv_my_next_start;
211 extern bool conv_show_boxes;
212 
213 extern void conv_system_init();
214 extern void conv_system_cleanup();
215 
216 extern void conv_start(ConvData *convData, Conv *convIn);
217 extern void conv_stop();
218 extern void conv_get(int convNum);
219 extern void conv_run(int convNum);
220 extern void conv_update(bool);
221 extern void conv_regenerate_last_message();
222 extern void conv_export_pointer(int16 *ptr);
223 extern void conv_abort();
224 extern void conv_me_trigger(int trigger);
225 extern void conv_you_trigger(int trigger);
226 extern int16 *conv_get_variable(int varNum);
227 extern void conv_export_value(int16 value);
228 extern void conv_hold();
229 extern void conv_release();
230 extern void conv_flush();
231 extern void conv_reset(int id);
232 extern int conv_append(Common::WriteStream *handle);
233 extern int conv_expand(Common::SeekableReadStream *handle);
234 
235 extern void init_conv();
236 
237 } // namespace MADSV2
238 } // namespace MADS
239 
240 #endif
Definition: conv.h:171
Definition: conv.h:76
Definition: stream.h:77
Definition: array.h:52
Definition: stream.h:745
Definition: conv.h:109
Definition: conv.h:65
Definition: conv.h:86
Definition: conv.h:124
Definition: mps_installer.h:31
Definition: conv.h:97
Definition: conv.h:142