ScummVM API documentation
objects.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 PARALLACTION_ZONE_H
23 #define PARALLACTION_ZONE_H
24 
25 #include "common/list.h"
26 #include "common/ptr.h"
27 
28 #include "parallaction/graphics.h"
29 
30 
31 namespace Parallaction {
32 
33 struct Zone;
34 struct Animation;
35 struct Command;
36 struct Question;
37 struct Answer;
38 struct Instruction;
39 struct Program;
40 
41 typedef Common::SharedPtr<Zone> ZonePtr;
42 typedef Common::List<ZonePtr> ZoneList;
43 
44 typedef Common::SharedPtr<Animation> AnimationPtr;
45 typedef Common::List<AnimationPtr> AnimationList;
46 
47 typedef Common::SharedPtr<Instruction> InstructionPtr;
48 typedef Common::Array<InstructionPtr> InstructionList;
49 
50 typedef Common::List<Common::Point> PointList;
51 
52 enum ZoneTypes {
53  kZoneExamine = 1, // zone displays comment if activated
54  kZoneDoor = 2, // zone activated on click (after some walk if needed)
55  kZoneGet = 3, // for pickable items
56  kZoneMerge = 4, // tags items which can be merged in inventory
57  kZoneTaste = 5, // NEVER USED
58  kZoneHear = 6, // NEVER USED: they ran out of time before integrating sfx
59  kZoneFeel = 7, // NEVER USED
60  kZoneSpeak = 8, // tags NPCs the character can talk with
61  kZoneNone = 9, // used to prevent parsing on peculiar Animations
62  kZoneTrap = 10, // zone activated when character enters
63  kZoneYou = 11, // marks the character
64  kZoneCommand = 12,
65 
66  // BRA specific
67  kZonePath = 13, // defines nodes for assisting walk calculation routines
68  kZoneBox = 14
69 };
70 
71 
72 enum ZoneFlags {
73  kFlagsClosed = 1, // Zone: door is closed / switch is off
74  kFlagsActive = 2, // Zone/Animation: object is visible
75  kFlagsRemove = 4, // Zone/Animation: object is soon to be removed
76  kFlagsActing = 8, // Animation: script execution is active
77  kFlagsLocked = 0x10, // Zone: door or switch cannot be toggled
78  kFlagsFixed = 0x20, // Zone: Zone item cannot be picked up
79  kFlagsNoName = 0x40, // Zone with no name (used to prevent some kEvEnterZone events)
80  kFlagsNoMasked = 0x80, // Animation is to be drawn ignoring z buffer
81  kFlagsLooping = 0x100, // Animation: script is to be executed repeatedly
82  kFlagsAdded = 0x200, // NEVER USED in Nippon Safes
83  kFlagsCharacter = 0x400, //
84  kFlagsNoWalk = 0x800, // Zone: character doesn't need to walk towards object to interact
85 
86  // BRA specific
87  kFlagsYourself = 0x1000, // BRA: marks zones used by the character on him/herself
88  kFlagsScaled = 0x2000,
89  kFlagsSelfuse = 0x4000, // BRA: marks zones to be preserved across location changes (see Parallaction::freeZones)
90  kFlagsIsAnimation = 0x1000000, // BRA: used in walk code (trap check), to tell is a Zone is an Animation
91  kFlagsAnimLinked = 0x2000000
92 };
93 
94 
95 enum CommandFlags : uint {
96  kFlagsAll = 0xFFFFFFFFU,
97 
98  kFlagsVisited = 1,
99  kFlagsExit = 0x10000000,
100  kFlagsEnter = 0x20000000,
101  kFlagsGlobal = 0x40000000,
102 
103  // BRA specific
104  kFlagsTestTrue = 2
105 };
106 
107 struct Command {
108  uint16 _id;
109  uint32 _flagsOn;
110  uint32 _flagsOff;
111  bool _valid;
112 
113  Command();
114 
115  // Common fields
116  uint32 _flags;
117  ZonePtr _zone;
118  Common::String _zoneName;
119  Common::String _string;
120  uint16 _callable;
121  uint16 _object;
122  Common::Point _move;
123 
124  // BRA specific
125  Common::Point _startPos;
126  Common::Point _startPos2;
127  Common::String _counterName;
128  int _counterValue;
129  int _zeta0;
130  int _zeta1;
131  int _zeta2;
132  Common::String _characterName;
133  Common::String _string2;
134  int _musicCommand;
135  int _musicParm;
136 };
137 
140 
141 
142 #define NUM_QUESTIONS 40
143 #define NUM_ANSWERS 20
144 
145 struct Answer {
146  Common::String _text;
147  uint16 _mood;
148  Common::String _followingName;
149 
150  CommandList _commands;
151  uint32 _noFlags;
152  uint32 _yesFlags;
153 
154  // BRA specific
155  bool _hasCounterCondition;
156  Common::String _counterName;
157  int _counterValue;
158  int _counterOp;
159 
160  Answer();
161  bool textIsNull();
162  int speakerMood();
163 };
164 
165 struct Question {
166  Common::String _name;
167  Common::String _text;
168  uint16 _mood;
169  Answer* _answers[NUM_ANSWERS];
170 
171  Question(const Common::String &name);
172  ~Question();
173  bool textIsNull();
174  int speakerMood();
175  int balloonWinding();
176 };
177 
178 struct Dialogue {
179  Question *_questions[NUM_QUESTIONS];
180  uint _numQuestions;
181 
182  Question *findQuestion(const Common::String &name) const;
183  void addQuestion(Question *q);
184 
185  Dialogue();
186  ~Dialogue();
187 };
188 
189 #define MAX_WALKPOINT_LISTS 20
190 #define FREE_HEAR_CHANNEL -1
191 #define MUSIC_HEAR_CHANNEL -2
192 
193 struct TypeData {
194  // common
195  GfxObj *_gfxobj; // get, examine, door
196  Common::String _filename; // speak, examine, hear
197 
198  // get
199  uint32 _getIcon;
200 
201  // speak
202  Dialogue *_speakDialogue;
203 
204  // examine
205  Common::String _examineText;
206 
207  // door
208  Common::String _doorLocation;
209  Common::Point _doorStartPos;
210  uint16 _doorStartFrame;
211  Common::Point _doorStartPos2_br;
212  uint16 _doorStartFrame2_br;
213 
214  // hear
215  int _hearChannel;
216  int _hearFreq;
217 
218  // merge
219  uint32 _mergeObj1;
220  uint32 _mergeObj2;
221  uint32 _mergeObj3;
222 
223  // path
224  int _pathNumLists;
225  PointList _pathLists[MAX_WALKPOINT_LISTS];
226 
227  TypeData() {
228  _gfxobj = 0;
229  _getIcon = 0;
230  _speakDialogue = 0;
231  _doorStartFrame = 0;
232  _doorStartPos.x = -1000;
233  _doorStartPos.y = -1000;
234  _doorStartFrame2_br = 0;
235  _doorStartPos2_br.x = -1000;
236  _doorStartPos2_br.y = -1000;
237  _hearChannel = FREE_HEAR_CHANNEL;
238  _hearFreq = -1;
239  _mergeObj1 = 0;
240  _mergeObj2 = 0;
241  _mergeObj3 = 0;
242  _pathNumLists = 0;
243  }
244 
245  ~TypeData() {
246  if (_gfxobj) {
247  _gfxobj->release();
248  }
249  delete _speakDialogue;
250  }
251 };
252 
253 #define ACTIONTYPE(z) ((z)->_type & 0xFFFF)
254 #define ITEMTYPE(z) ((z)->_type & 0xFFFF0000)
255 
256 #define PACK_ZONETYPE(zt,it) (((zt) & 0xFFFF) | (((it) & 0xFFFF) << 16))
257 
258 #define ZONENAME_LENGTH 32
259 
260 #define INVALID_LOCATION_INDEX ((uint32)-1)
261 #define INVALID_ZONE_INDEX ((uint32)-1)
262 
263 struct Zone {
264 private:
265  int16 _right;
266  int16 _bottom;
267 
268 protected:
269  int16 _left;
270  int16 _top;
271 
272 public:
273  char _name[ZONENAME_LENGTH];
274 
275  uint32 _type;
276  uint32 _flags;
277  GfxObj *_label;
278 
279  TypeData u;
280  CommandList _commands;
281  Common::Point _moveTo;
282 
283  // BRA specific
284  uint _index;
285  uint _locationIndex;
286  Common::String _linkedName;
287  AnimationPtr _linkedAnim;
288 
289  Zone();
290  virtual ~Zone();
291 
292  void translate(int16 x, int16 y);
293 
294  bool hitRect(int x, int y) const;
295 
296  void setRect(int16 left, int16 top, int16 right, int16 bottom) {
297  setX(left);
298  setY(top);
299  _right = right;
300  _bottom = bottom;
301  }
302 
303  void getRect(Common::Rect& r) {
304  r.left = _left; r.right = _right;
305  r.top = _top; r.bottom = _bottom;
306  }
307 
308 
309  // getters/setters
310  virtual int16 getX() { return _left; }
311  virtual void setX(int16 value) { _left = value; }
312 
313  virtual int16 getY() { return _top; }
314  virtual void setY(int16 value) { _top = value; }
315 };
316 
317 
319 protected:
320  int16 _value;
321  int16 _min;
322  int16 _max;
323 
324 public:
325 
326  LocalVariable() {
327  _value = 0;
328  _min = -10000;
329  _max = 10000;
330  }
331 
332  void setRange(int16 min, int16 max);
333 
334  int16 getValue() const;
335  void setValue(int16 value);
336 };
337 
338 
339 enum ParaFlags {
340  kParaImmediate = 1, // instruction is using an immediate parameter
341  kParaLocal = 2, // instruction is using a local variable
342  kParaField = 0x10, // instruction is using an animation's field
343  kParaRandom = 0x100,
344 
345  kParaLValue = 0x20
346 };
347 
348 
352 
353  typedef Accessor::FuncType AccessorFunc;
354  typedef Mutator::FuncType MutatorFunc;
355 
356 protected:
357  Accessor *_accessor;
358  Mutator *_mutator;
359 
360 public:
361  AnimationField(Animation* instance, AccessorFunc accessor, MutatorFunc mutator) {
362  _accessor = new Accessor(instance, accessor);
363  _mutator = new Mutator(instance, mutator);
364  }
365 
366  AnimationField(Animation* instance, AccessorFunc accessor) {
367  _accessor = new Accessor(instance, accessor);
368  _mutator = 0;
369  }
370 
371  ~AnimationField() {
372  delete _accessor;
373  delete _mutator;
374  }
375 
376  int16 getValue() const {
377  assert(_accessor);
378  return (*_accessor)();
379  }
380 
381  void setValue(int16 value) {
382  assert(_mutator);
383  (*_mutator)(value);
384  }
385 };
386 
387 
388 struct ScriptVar {
389  uint32 _flags;
390 
391  int16 _value;
392  LocalVariable* _local;
393  AnimationField* _field;
394 
395  ScriptVar();
396  ~ScriptVar();
397 
398  int16 getValue();
399  void setValue(int16 value);
400 
401  void setLocal(LocalVariable *local);
402  void setField(Animation *anim, AnimationField::AccessorFunc accessor, AnimationField::MutatorFunc mutator);
403  void setField(Animation *anim, AnimationField::AccessorFunc accessor);
404  void setImmediate(int16 value);
405  void setRandom(int16 seed);
406 };
407 
408 enum InstructionFlags {
409  kInstMod = 4,
410  kInstMaskedPut = 8,
411  kInstUnk20 = 0x20
412 };
413 
414 
415 struct Instruction {
416  uint32 _index;
417  uint32 _flags;
418 
419  // common
420  AnimationPtr _a;
421  ZonePtr _z;
422  int16 _immediate;
423  ScriptVar _opA;
424  ScriptVar _opB;
425 
426  // BRA specific
427  byte _colors[3];
428  ScriptVar _opC;
429  Common::String _text;
430  Common::String _text2;
431  int _y;
432  uint32 _endif;
433 
434  Instruction();
435 };
436 
437 enum {
438  kProgramIdle, // awaiting execution
439  kProgramRunning, // running
440  kProgramDone // execution completed
441 };
442 
443 struct Program {
444  AnimationPtr _anim;
445  LocalVariable *_locals;
446 
447  uint16 _loopCounter;
448  uint16 _numLocals;
449 
450  uint32 _ip;
451  uint32 _loopStart;
452  InstructionList _instructions;
453 
454  uint32 _status;
455 
456  Program();
457  ~Program();
458 
459  int16 findLocal(const char* name);
460  int16 addLocal(const char *name, int16 value = 0, int16 min = -10000, int16 max = 10000);
461 };
462 
465 
466 struct Animation : public Zone {
467 protected:
468  int16 _frame;
469  int16 _z;
470 public:
471 
472  GfxObj *gfxobj;
473  Common::String _scriptName;
474 
475  Animation();
476  ~Animation() override;
477  uint16 getFrameNum() const;
478  byte* getFrameData() const;
479 
480  void resetZ();
481  bool hitFrameRect(int x, int y) const;
482  void getFrameRect(Common::Rect &r) const;
483  int16 getBottom() const;
484 
485  // HACK: this routine is only used to download initialisation
486  // parameter to a script used when moving sarcophagi around in
487  // the museum. It bypasses all the consistency checks that
488  // can be performed by the individual setters. See the comment
489  // in startMovingSarcophagus() in callables_ns.cpp
490  void forceXYZF(int16 x, int16 y, int16 z, int16 f);
491 
492  // getters/setters used by scripts
493  int16 getX() override { return _left; }
494  void setX(int16 value) override { _left = value; }
495 
496  int16 getY() override { return _top; }
497  void setY(int16 value) override { _top = value; }
498 
499  int16 getZ() { return _z; }
500  void setZ(int16 value) { _z = value; }
501 
502  int16 getF() { return _frame; }
503  void setF(int16 value);
504 
505  void getFoot(Common::Point &foot);
506  void setFoot(const Common::Point &foot);
507 };
508 
509 class Table {
510 
511 protected:
512  char **_data;
513  uint16 _size;
514  uint16 _used;
515  bool _disposeMemory;
516 
517 public:
518  Table(uint32 size);
519  Table(uint32 size, const char** data);
520 
521  virtual ~Table();
522 
523  enum {
524  notFound = 0
525  };
526 
527  uint count() const { return _used; }
528  const char *item(uint index) const;
529 
530  virtual void addData(const char* s);
531  virtual void clear();
532  virtual uint16 lookup(const char* s);
533 };
534 
535 class FixedTable : public Table {
536 
537  uint16 _numFixed;
538 
539 public:
540  FixedTable(uint32 size, uint32 fixed);
541  void clear() override;
542 };
543 
544 Table* createTableFromStream(uint32 size, Common::SeekableReadStream *stream);
545 
546 } // namespace Parallaction
547 
548 #endif
Definition: str.h:59
Definition: objects.h:388
Definition: objects.h:349
Definition: objects.h:145
Definition: objects.h:193
int16 right
Definition: rect.h:146
Definition: objects.h:107
Definition: objects.h:318
Definition: objects.h:466
Definition: rect.h:144
Definition: stream.h:745
Definition: objects.h:443
Definition: func.h:389
Definition: debug.h:8
Definition: func.h:452
Definition: rect.h:45
Definition: objects.h:535
int16 left
Definition: rect.h:145
Definition: objects.h:165
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
Definition: objects.h:178
Definition: objects.h:263
Definition: objects.h:415
Definition: graphics.h:300
Definition: objects.h:509