-
Notifications
You must be signed in to change notification settings - Fork 2
/
object.h
442 lines (359 loc) · 10.1 KB
/
object.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef UNITY_OBJECT_H
#define UNITY_OBJECT_H
#include "common/array.h"
#include "common/str.h"
namespace Common {
class SeekableReadStream;
}
namespace Unity {
class UnityEngine;
class UnityData;
class SpritePlayer;
class Conversation;
enum {
OBJFLAG_WALK = 0x01,
OBJFLAG_USE = 0x02,
OBJFLAG_TALK = 0x04,
OBJFLAG_GET = 0x08,
OBJFLAG_LOOK = 0x10,
OBJFLAG_ACTIVE = 0x20,
OBJFLAG_INVENTORY = 0x40,
OBJFLAG_STUNNED = 0x80
};
enum {
OBJWALKTYPE_NORMAL = 0x0,
OBJWALKTYPE_SCALED = 0x1, // scaled with walkable polygons (e.g. characters)
OBJWALKTYPE_TS = 0x2, // transition square
OBJWALKTYPE_AS = 0x3 // action square
};
enum {
RESULT_FAILOTHER = 0x2, // failed to match other object
RESULT_WALKING = 0x4, // had to start walking
RESULT_FAILSKILL = 0x8, // skill level too low
RESULT_NOTARGET = 0x10, // couldn't find target
RESULT_OTHERPOS = 0x20, // other object wasn't in position (unused?)
RESULT_FAILPOS = 0x40, // something wasn't in position
RESULT_AWAYTEAM = 0x80, // not in away team
RESULT_INVENTORY = 0x100, // something was/wasn't in inventory
RESULT_INACTIVE = 0x200, // something was inactive
RESULT_FAILSCREEN = 0x400, // something wasn't on right screen
RESULT_STOPPED = 0x800, // stop here
RESULT_FAILSTATE = 0x1000, // something didn't have right state
RESULT_MATCHOTHER = 0x2000, // successfully matched other object
RESULT_EMPTYTALK = 0x4000, // talk string was empty
RESULT_DIDSOMETHING = 0x8000, // a result was actually executed
RESULT_COUNTER_DOWHEN = 0x10000, // wasn't time for DO WHEN yet
RESULT_COUNTER_DOUNTIL = 0x20000, // all done with DO UNTIL
RESULT_STUNNED = 0x40000, // something was stunned
RESULT_FAILPHASER = 0x80000 // couldn't phaser object
};
enum {
BLOCK_OBJ_HEADER = 0x0,
BLOCK_DESCRIPTION = 0x1,
BLOCK_USE_ENTRIES = 0x2,
BLOCK_GET_ENTRIES = 0x3,
BLOCK_LOOK_ENTRIES = 0x4,
BLOCK_TIMER_ENTRIES = 0x5,
BLOCK_CONDITION = 0x6,
BLOCK_ALTER = 0x7,
BLOCK_REACTION = 0x8,
BLOCK_COMMAND = 0x9,
BLOCK_SCREEN = 0x10,
BLOCK_PATH = 0x11,
// 0x12 unused?
BLOCK_GENERAL = 0x13,
BLOCK_CONVERSATION = 0x14,
BLOCK_BEAMDOWN = 0x15,
BLOCK_TRIGGER = 0x16,
BLOCK_COMMUNICATE = 0x17,
BLOCK_CHOICE = 0x18,
// 0x19, 0x20, 0x21, 0x22 unused?
// (planet, computer, game, encounter?)
BLOCK_END_ENTRY = 0x23,
BLOCK_BEGIN_ENTRY = 0x24,
BLOCK_END_BLOCK = 0x25,
BLOCK_CHOICE1 = 0x26,
BLOCK_CHOICE2 = 0x27,
BLOCK_CONV_RESPONSE = 0x28,
BLOCK_CONV_WHOCANSAY = 0x29,
BLOCK_CONV_CHANGEACT_DISABLE = 0x30,
BLOCK_CONV_CHANGEACT_SET = 0x31,
BLOCK_CONV_CHANGEACT_ENABLE = 0x32,
BLOCK_CONV_CHANGEACT_UNKNOWN2 = 0x33,
BLOCK_CONV_TEXT = 0x34,
BLOCK_CONV_RESULT = 0x35,
BLOCK_PHASER_STUN = 0x36,
BLOCK_PHASER_GTP = 0x37,
BLOCK_PHASER_KILL = 0x38,
BLOCK_PHASER_RECORD = 0x39,
BLOCK_SPEECH_INFO = 0x40
};
enum {
RESPONSE_ENABLED = 0x2,
RESPONSE_DISABLED = 0x3,
RESPONSE_UNKNOWN1 = 0x4
};
typedef unsigned int ResultType;
struct objectID {
byte id;
byte screen;
byte world;
byte unused;
objectID(): id(255), screen(255), world(255), unused(0) { }
objectID(byte i, byte s, byte w) : id(i), screen(s), world(w), unused(0) { }
bool operator == (const objectID &o) const {
return id == o.id && screen == o.screen && world == o.world;
}
bool operator != (const objectID &o) const {
return id != o.id || screen != o.screen || world != o.world;
}
};
objectID readObjectID(Common::SeekableReadStream *stream);
objectID readObjectIDBE(Common::SeekableReadStream *stream);
enum ActionType {
ACTION_USE = 0,
ACTION_GET = 1,
ACTION_LOOK = 2,
ACTION_TIMER = 3,
ACTION_WALK = 4,
ACTION_TALK = 5
};
struct Action {
ActionType action_type;
class Object *target;
objectID who;
objectID other;
unsigned int x, y;
};
struct Description {
Common::String text;
uint32 entry_id;
uint32 voice_group, voice_subgroup, voice_id;
};
int readBlockHeader(Common::SeekableReadStream *objstream);
class Entry {
friend class EntryList; // (temporary) hack for stop_here
protected:
objectID internal_obj;
byte counter1, counter2, counter3, counter4;
uint16 state_counter, response_counter;
byte stop_here;
void readHeaderFrom(Common::SeekableReadStream *stream, byte header_type);
public:
virtual ResultType check(UnityEngine *_vm, Action *context) { return 0; }
virtual ResultType execute(UnityEngine *_vm, Action *context) = 0;
virtual ~Entry() { }
};
class EntryList {
public:
~EntryList();
Common::Array<Common::Array<Entry *>*> list;
void readEntryList(Common::SeekableReadStream *objstream);
void readEntry(int type, Common::SeekableReadStream *objstream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class ConditionBlock : public Entry {
protected:
objectID target;
objectID WhoCan;
uint16 how_close_dist, how_close_x, how_close_y;
uint16 skill_check;
uint16 counter_value;
byte counter_when;
objectID condition[4];
uint16 check_x[4];
uint16 check_y[4];
uint16 check_unknown[4];
uint16 check_univ_x[4];
uint16 check_univ_y[4];
uint16 check_univ_z[4];
byte check_screen[4];
byte check_status[4];
byte check_state[4];
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType check(UnityEngine *_vm, Action *context);
ResultType execute(UnityEngine *_vm, Action *context);
};
class AlterBlock : public Entry {
protected:
objectID target;
byte alter_flags, alter_reset, alter_state;
uint16 x_pos, y_pos;
Common::String alter_name, alter_hail;
uint16 alter_timer;
uint16 alter_anim;
byte play_description;
uint16 unknown8;
byte unknown11;
byte unknown12;
uint16 universe_x, universe_y, universe_z;
uint32 voice_id;
uint32 voice_group;
uint16 voice_subgroup;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class ReactionBlock : public Entry {
protected:
objectID target;
uint16 dest_world, dest_screen, dest_entrance;
byte target_type;
byte action_type;
byte damage_amount;
byte beam_type;
uint16 dest_x, dest_y, dest_unknown;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class CommandBlock : public Entry {
protected:
objectID target[3];
uint16 target_x, target_y;
uint32 command_id;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class ScreenBlock : public Entry {
protected:
uint16 new_world;
byte new_screen;
byte new_entrance;
byte advice_screen;
uint16 new_advice_id;
uint16 new_advice_timer;
uint16 unknown6;
uint32 unknown7;
byte unknown8;
uint32 unknown9;
uint32 unknown10;
uint16 unknown11;
uint16 unknown12;
uint16 unknown13;
byte unknown14;
byte unknown15;
byte unknown16;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class PathBlock : public Entry {
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class GeneralBlock : public Entry {
protected:
uint16 movie_id;
uint16 unknown1;
uint16 unknown2;
uint16 unknown3;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class ConversationBlock : public Entry {
protected:
uint16 world_id, conversation_id, response_id, state_id, action_id;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class BeamBlock : public Entry {
protected:
uint16 world_id;
uint16 unknown1;
uint16 unknown3;
uint16 screen_id;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class TriggerBlock : public Entry {
protected:
uint32 trigger_id;
bool enable_trigger;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class CommunicateBlock : public Entry {
protected:
objectID target;
uint16 conversation_id;
uint16 situation_id;
byte hail_type;
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
};
class ChoiceBlock : public Entry {
public:
void readFrom(Common::SeekableReadStream *stream);
ResultType execute(UnityEngine *_vm, Action *context);
uint16 _unknown1, _unknown2;
objectID _object;
Common::String _questionstring;
Common::String _choicestring[2];
EntryList _choice[2];
};
class Object {
public:
Object(UnityEngine *p);
~Object();
objectID id;
byte curr_screen;
unsigned int x, y, z;
unsigned int universe_x, universe_y, universe_z;
unsigned int width, height;
int16 y_adjust;
uint32 region_id;
byte flags;
byte state;
uint16 skills;
uint16 timer;
byte objwalktype;
objectID transition;
byte cursor_flag;
byte cursor_id;
uint16 anim_index;
uint16 sprite_id;
SpritePlayer *sprite;
Common::String name;
Common::String talk_string;
uint32 voice_id;
uint32 voice_group;
uint16 voice_subgroup;
Common::String identify();
Common::Array<Description> descriptions;
EntryList use_entries, get_entries, look_entries, timer_entries;
void loadObject(unsigned int world, unsigned int screen, unsigned int id);
void loadSprite();
void setTalkString(const Common::String &str);
void changeTalkString(const Common::String &str);
void runHail(const Common::String &hail);
protected:
UnityEngine *_vm;
void readBlock(int type, Common::SeekableReadStream *objstream);
void readDescriptions(Common::SeekableReadStream *objstream);
void readDescriptionBlock(Common::SeekableReadStream *objstream);
};
} // Unity
#endif