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