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
28namespace MADS {
29
30// Return of the Phantom needs 40, Dragonsphere needs 70
31constexpr int CONV_MAX_SLOTS = 70;
32constexpr int CONV_MAX_DATA = 5;
33
34enum 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.
46enum 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
64struct ConvNode {
65 int16 index;
66 int16 dialog_count;
67 int16 active;
68 int16 field_6;
69 int16 field_8;
70
71 static constexpr size_t SIZE = 2 * 5;
72 void load(Common::SeekableReadStream *src);
73};
74
75struct ConvDialog {
76 int16 text_line_index;
77 int16 speech_index;
78 int16 script_offset;
79 int16 script_size;
80
81 static constexpr size_t 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 size_t SIZE = 2 + 1 + 1 + 2 + 2;
93 void load(Common::SeekableReadStream *src);
94};
95
97 enum PtrType { PTRTYPE_GLOBAL = 1, PTRTYPE_CONV_CONTROL = 2 };
98
99 bool isPtr = false;
100 int16 val = 0, type = 0;
101 int16 *ptr = nullptr;
102
103 static constexpr size_t SIZE = 2 * 3;
104 void load(Common::SeekableReadStream *src);
105 void save(Common::WriteStream *dest) const;
106};
107
108struct 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;
132 Common::Array<byte> scripts;
133 Common::Array<uint16> textLines;
134
135 static constexpr size_t 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
141struct 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;
164
165 static constexpr size_t SIZE = 2 * 10 + 2 * 10 * 5 + 2 * 3;
166 void load(Common::SeekableReadStream *src);
167 void save(Common::WriteStream *dest) const;
168};
169
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
197extern Conv *conv[CONV_MAX_DATA];
198extern ConvData *conv_data[CONV_MAX_DATA];
199extern Conv *active_conv;
200extern ConvData *active_conv_data;
201
202extern int16 *conv_imports;
203extern uint16 *conv_entry_flags;
204extern ConvVariable *conv_varsDataPtr;
205extern int16 *conv_vars0ValPtr;
206
207extern int conv_restore_running;
208extern ConvControl conv_control;
209extern int16 *conv_my_next_start;
210extern bool conv_show_boxes;
211
212extern void conv_system_init();
213extern void conv_system_cleanup();
214
215extern void conv_start(ConvData *convData, Conv *convIn);
216extern void conv_stop();
217extern void conv_get(int convNum);
218extern void conv_run(int convNum);
219extern void conv_update(bool);
220extern void conv_regenerate_last_message();
221extern void conv_export_pointer(int16 *ptr);
222extern void conv_abort();
223extern void conv_me_trigger(int trigger);
224extern void conv_you_trigger(int trigger);
225extern int16 *conv_get_variable(int varNum);
226extern void conv_export_value(int16 value);
227extern void conv_hold();
228extern void conv_release();
229extern void conv_flush();
230extern void conv_reset(int id);
231extern int conv_append(Common::WriteStream *handle);
232extern int conv_expand(Common::SeekableReadStream *handle);
233
234extern void init_conv();
235
236} // namespace MADS
237
238#endif
Definition: array.h:52
Definition: stream.h:745
Definition: stream.h:77
Definition: conv.h:123
Definition: conv.h:170
Definition: conv.h:141
Definition: conv.h:75
Definition: conv.h:108
Definition: conv.h:64
Definition: conv.h:85
Definition: conv.h:96