ScummVM API documentation
scripts.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 XEEN_SCRIPTS_H
23 #define XEEN_SCRIPTS_H
24 
25 #include "common/scummsys.h"
26 #include "common/system.h"
27 #include "common/serializer.h"
28 #include "common/stack.h"
29 #include "common/str-array.h"
30 #include "xeen/files.h"
31 #include "xeen/party.h"
32 
33 namespace Xeen {
34 
35 enum Opcode {
36  OP_None = 0x00,
37  OP_Display0x01 = 0x01,
38  OP_DoorTextSml = 0x02,
39  OP_DoorTextLrg = 0x03,
40  OP_SignText = 0x04,
41  OP_NPC = 0x05,
42  OP_PlayFX = 0x06,
43  OP_TeleportAndExit = 0x07,
44  OP_If1 = 0x08,
45  OP_If2 = 0x09,
46  OP_If3 = 0x0A,
47  OP_MoveObj = 0x0B,
48  OP_TakeOrGive = 0x0C,
49  OP_NoAction = 0x0D,
50  OP_Remove = 0x0E,
51  OP_SetChar = 0x0F,
52  OP_Spawn = 0x10,
53  OP_DoTownEvent = 0x11,
54  OP_Exit = 0x12,
55  OP_AfterMap = 0x13,
56  OP_GiveMulti = 0x14,
57  OP_ConfirmWord = 0x15,
58  OP_Damage = 0x16,
59  OP_JumpRnd = 0x17,
60  OP_AfterEvent = 0x18,
61  OP_CallEvent = 0x19,
62  OP_Return = 0x1A,
63  OP_SetVar = 0x1B,
64  OP_TakeOrGive_2 = 0x1C,
65  OP_TakeOrGive_3 = 0x1D,
66  OP_CutsceneEndClouds = 0x1E,
67  OP_TeleportAndContinue = 0x1F,
68  OP_WhoWill = 0x20,
69  OP_RndDamage = 0x21,
70  OP_MoveWallObj = 0x22,
71  OP_AlterCellFlag = 0x23,
72  OP_AlterHed = 0x24,
73  OP_DisplayStat = 0x25,
74  OP_TakeOrGive_4 = 0x26,
75  OP_SeatTextSml = 0x27,
76  OP_PlayEventVoc = 0x28,
77  OP_DisplayBottom = 0x29,
78  OP_IfMapFlag = 0x2A,
79  OP_SelectRandomChar = 0x2B,
80  OP_GiveEnchanted = 0x2C,
81  OP_ItemType = 0x2D,
82  OP_MakeNothingHere = 0x2E,
83  OP_NoAction_2 = 0x2F,
84  OP_ChooseNumeric = 0x30,
85  OP_DisplayBottomTwoLines = 0x31,
86  OP_DisplayLarge = 0x32,
87  OP_ExchObj = 0x33,
88  OP_FallToMap = 0x34,
89  OP_DisplayMain = 0x35,
90  OP_Goto = 0x36,
91  OP_ConfirmWord_2 = 0x37,
92  OP_GotoRandom = 0x38,
93  OP_CutsceneEndDarkside = 0x39,
94  OP_CutsceneEdWorld = 0x3A,
95  OP_FlipWorld = 0x3B,
96  OP_PlayCD = 0x3C
97 };
98 
99 enum {
100  SCRIPT_ABORT = -1,
101  SCRIPT_RESET = -2
102 };
103 
104 class XeenEngine;
105 
109 class EventParameters : public Common::Array<byte> {
110 public:
111  class Iterator {
112  private:
113  uint _index;
114  const EventParameters &_data;
115  public:
116  Iterator(const EventParameters &owner) : _data(owner), _index(0) {}
117  Iterator(const Iterator &it) : _data(it._data), _index(0) {}
118 
122  byte readByte();
123 
127  int8 readShort() { return (int8)readByte(); }
128 
132  uint16 readUint16LE();
133 
137  uint32 readUint32LE();
138  };
139 public:
144  return Iterator(*this);
145  }
146 };
147 
151 class MazeEvent {
152 public:
153  Common::Point _position;
154  int _direction;
155  int _line;
156  Opcode _opcode;
157  EventParameters _parameters;
158 public:
159  MazeEvent();
160 
164  void synchronize(Common::Serializer &s);
165 };
166 
170 class MazeEvents : public Common::Array<MazeEvent> {
171 public:
172  Common::StringArray _text;
173 public:
177  void synchronize(XeenSerializer &s);
178 };
179 
183 struct StackEntry : public Common::Point {
184  int line;
185 
186  StackEntry(const Common::Point &pt, int l) : Common::Point(pt), line(l) {}
187 };
188 
192 struct MirrorEntry {
193  Common::String _name;
194  int _mapId;
195  Common::Point _position;
196  int _direction;
197 
198  MirrorEntry() : _mapId(0), _direction(DIR_ALL) {}
199 
200  bool synchronize(Common::SeekableReadStream &s);
201 };
202 
206 class Scripts {
207 private:
208  XeenEngine *_vm;
209  int _treasureItems;
210  int _lineNum;
211  int _charIndex;
212  int _mirrorId;
213  int _refreshIcons;
214  int _scriptResult;
215  bool _scriptExecuted;
216  bool _dirFlag;
217  int _windowIndex;
218  bool _redrawDone;
219  MazeEvent *_event;
220  Common::Point _currentPos;
222  Common::String _displayMessage;
223 
225 
229  bool doOpcode(MazeEvent &event);
230 
234  bool cmdDoNothing(ParamsIterator &params);
235 
239  bool cmdDisplay1(ParamsIterator &params);
240 
244  bool cmdDoorTextSml(ParamsIterator &params);
245 
249  bool cmdDoorTextLrg(ParamsIterator &params);
250 
254  bool cmdSignText(ParamsIterator &params);
255 
259  bool cmdNPC(ParamsIterator &params);
260 
264  bool cmdPlayFX(ParamsIterator &params);
265 
269  bool cmdTeleport(ParamsIterator &params);
270 
274  bool cmdIf(ParamsIterator &params);
275 
279  bool cmdMoveObj(ParamsIterator &params);
280 
284  bool cmdTakeOrGive(ParamsIterator &params);
285 
289  bool cmdRemove(ParamsIterator &params);
290 
294  bool cmdSetChar(ParamsIterator &params);
295 
299  bool cmdSpawn(ParamsIterator &params);
300 
305  bool cmdDoTownEvent(ParamsIterator &params);
306 
310  bool cmdExit(ParamsIterator &params);
311 
315  bool cmdAlterMap(ParamsIterator &params);
316 
320  bool cmdGiveMulti(ParamsIterator &params);
321 
326  bool cmdConfirmWord(ParamsIterator &params);
327 
331  bool cmdDamage(ParamsIterator &params);
332 
336  bool cmdJumpRnd(ParamsIterator &params);
337 
341  bool cmdAlterEvent(ParamsIterator &params);
342 
347  bool cmdCallEvent(ParamsIterator &params);
348 
353  bool cmdReturn(ParamsIterator &params);
354 
358  bool cmdSetVar(ParamsIterator &params);
359 
363  bool cmdCutsceneEndClouds(ParamsIterator &params);
364 
368  bool cmdWhoWill(ParamsIterator &params);
369 
373  bool cmdRndDamage(ParamsIterator &params);
374 
380  bool cmdMoveWallObj(ParamsIterator &params);
381 
385  bool cmdAlterCellFlag(ParamsIterator &params);
386 
391  bool cmdAlterHed(ParamsIterator &params);
392 
396  bool cmdDisplayStat(ParamsIterator &params);
397 
402  bool cmdSignTextSml(ParamsIterator &params);
403 
408  bool cmdPlayEventVoc(ParamsIterator &params);
409 
413  bool cmdDisplayBottom(ParamsIterator &params);
414 
419  bool cmdIfMapFlag(ParamsIterator &params);
420 
424  bool cmdSelectRandomChar(ParamsIterator &params);
425 
429  bool cmdGiveEnchanted(ParamsIterator &params);
430 
434  bool cmdItemType(ParamsIterator &params);
435 
439  bool cmdMakeNothingHere(ParamsIterator &params);
440 
444  bool cmdCheckProtection(ParamsIterator &params);
445 
450  bool cmdChooseNumeric(ParamsIterator &params);
451 
455  bool cmdDisplayBottomTwoLines(ParamsIterator &params);
456 
460  bool cmdDisplayLarge(ParamsIterator &params);
461 
465  bool cmdExchObj(ParamsIterator &params);
466 
470  bool cmdFallToMap(ParamsIterator &params);
471 
475  bool cmdDisplayMain(ParamsIterator &params);
476 
482  bool cmdGoto(ParamsIterator &params);
483 
487  bool cmdGotoRandom(ParamsIterator &params);
488 
492  bool cmdCutsceneEndDarkside(ParamsIterator &params);
493 
497  bool cmdCutsceneEndWorld(ParamsIterator &params);
498 
502  bool cmdFlipWorld(ParamsIterator &params);
503 
507  bool cmdPlayCD(ParamsIterator &params);
508 
509  int whoWill(int v1, int v2, int v3);
510 
514  void doCloudsEnding();
515 
519  void doDarkSideEnding();
520 
525  void doWorldEnding();
526 
530  void doEnding(const Common::String &endStr);
531 
535  bool ifProc(int action, uint32 val, int mode, int charIndex);
536 
540  bool copyProtectionCheck();
541 
545  void display(bool justifyFlag, int var46);
546 
550  uint convertCDTime(uint srcTime);
551 public:
552  int _animCounter;
553  bool _eventSkipped;
554  int _whoWill;
555  DamageType _nEdamageType;
557  Common::String _message;
558 public:
559  Scripts(XeenEngine *vm);
560 
565  int checkEvents();
566 
571  bool openGrate(int wallVal, int action);
572 };
573 
574 } // End of namespace Xeen
575 
576 #endif /* XEEN_SCRIPTS_H */
Definition: str.h:59
Definition: scripts.h:151
Definition: array.h:52
Iterator getIterator() const
Definition: scripts.h:143
Definition: stream.h:652
Definition: serializer.h:79
Definition: files.h:244
Definition: scripts.h:111
Definition: scripts.h:192
Definition: scripts.h:109
Definition: rect.h:45
Definition: scripts.h:183
Definition: xeen.h:100
Definition: scripts.h:206
Definition: scripts.h:170
int8 readShort()
Definition: scripts.h:127
Definition: character.h:33