ScummVM API documentation
logic.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 SWORD1_LOGIC_H
23 #define SWORD1_LOGIC_H
24 // combination of logic.c and scr_int.c
25 
26 #include "sword1/sworddefs.h"
27 #include "sword1/objectman.h"
28 #include "common/util.h"
29 #include "common/random.h"
30 
31 class OSystem;
32 
33 namespace Audio {
34 class Mixer;
35 }
36 
37 namespace Sword1 {
38 
39 #define NON_ZERO_SCRIPT_VARS 95
40 #define NUM_SCRIPT_VARS 1179
41 
42 class SwordEngine;
43 class Text;
44 class Sound;
45 class EventManager;
46 class Menu;
47 class Router;
48 class Screen;
49 class Mouse;
50 class Control;
51 
52 class Logic;
53 typedef int (Logic::*BSMcodeTable)(Object *, int32, int32, int32, int32, int32, int32, int32);
54 
55 class Logic {
56  friend class Control;
57 public:
58  Logic(SwordEngine *vm, ObjectMan *pObjMan, ResMan *resMan, Screen *pScreen, Mouse *pMouse, Sound *pSound, Menu *pMenu, OSystem *system, Audio::Mixer *mixer);
59  ~Logic();
60  void initialize();
61  void setControlPanelObject(Control *control);
62  void newScreen(uint32 screen);
63  void engine();
64  void updateScreenParams();
65  void runMouseScript(Object *cpt, int32 scriptId);
66  void startPositions(uint32 pos);
67  bool canShowDebugTextNumber();
68  void plotRouteGrid(Object *megaObject);
69 
70  static uint32 _scriptVars[NUM_SCRIPT_VARS];
71 // public for mouse (menu looking)
72  int cfnPresetScript(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
73 private:
74  SwordEngine *_vm;
75  ObjectMan *_objMan;
76  OSystem *_system;
77  Audio::Mixer *_mixer;
78  ResMan *_resMan;
79  Screen *_screen;
80  Sound *_sound;
81  Mouse *_mouse;
82  Router *_router;
83  Text *_textMan;
84  EventManager *_eventMan;
85  Menu *_menu;
86  Control *_control;
87  uint32 _newScript; // <= ugly, but I can't avoid it.
88  uint8 _speechClickDelay = 0;
90  bool _psxFudgeRandom = false; // Used within fnIdle() and fnRandom() for the PSX version
91 
92  int scriptManager(Object *compact, uint32 id);
93  void processLogic(Object *compact, uint32 id);
94  int interpretScript(Object *compact, int id, Header *scriptModule, int scriptBase, int scriptNum);
95 
96  int logicWaitTalk(Object *compact);
97  int logicStartTalk(Object *compact);
98  int logicArAnimate(Object *compact, uint32 id);
99  int speechDriver(Object *compact);
100  int fullAnimDriver(Object *compact);
101  int animDriver(Object *compact);
102 
103  void setupMcodeTable();
104  const BSMcodeTable *_mcodeTable;
105 
106 //- mcodeTable:
107  int fnBackground(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
108  int fnForeground(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
109  int fnSort(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
110  int fnNoSprite(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
111  int fnMegaSet(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
112  int fnAnim(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
113  int fnSetFrame(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
114  int fnFullAnim(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
115  int fnFullSetFrame(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
116  int fnFadeDown(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
117  int fnFadeUp(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
118  int fnCheckFade(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
119  int fnSetSpritePalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
120  int fnSetWholePalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
121  int fnSetFadeTargetPalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
122  int fnSetPaletteToFade(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
123  int fnSetPaletteToCut(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
124  int fnPlaySequence(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
125 
126  int fnIdle(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
127  int fnPause(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
128  int fnPauseSeconds(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
129  int fnQuit(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
130  int fnKillId(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
131  int fnSuicide(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
132  int fnNewScript(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
133  int fnSubScript(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
134  int fnRestartScript(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
135  int fnSetBookmark(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
136  int fnGotoBookmark(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
137  int fnSendSync(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
138  int fnWaitSync(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
139 
140  int cfnClickInteract(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
141  int cfnSetScript(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
142 
143  int fnInteract(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
144  int fnIssueEvent(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
145  int fnCheckForEvent(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
146  int fnWipeHands(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
147  int fnISpeak(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
148  int fnTheyDo(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
149  int fnTheyDoWeWait(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
150  int fnWeWait(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
151  int fnChangeSpeechText(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
152  int fnTalkError(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
153  int fnStartTalk(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
154  int fnCheckForTextLine(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
155  int fnAddTalkWaitStatusBit(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
156  int fnRemoveTalkWaitStatusBit(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
157 
158  int fnNoHuman(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
159  int fnAddHuman(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
160  int fnBlankMouse(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
161  int fnNormalMouse(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
162  int fnLockMouse(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
163  int fnUnlockMouse(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
164  int fnSetMousePointer(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
165  int fnSetMouseLuggage(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
166  int fnMouseOn(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
167  int fnMouseOff(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
168  int fnChooser(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
169  int fnEndChooser(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
170  int fnStartMenu(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
171  int fnEndMenu(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
172 
173  int cfnReleaseMenu(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
174 
175  int fnAddSubject(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
176  int fnAddObject(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
177  int fnRemoveObject(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
178  int fnEnterSection(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
179  int fnLeaveSection(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
180  int fnChangeFloor(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
181  int fnWalk(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
182  int fnTurn(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
183  int fnStand(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
184  int fnStandAt(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
185  int fnFace(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
186  int fnFaceXy(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
187  int fnIsFacing(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
188  int fnGetTo(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
189  int fnGetToError(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
190  int fnGetPos(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
191  int fnGetGamepadXy(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
192  int fnPlayFx(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
193  int fnStopFx(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
194  int fnPlayMusic(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
195  int fnStopMusic(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
196  int fnInnerSpace(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
197  int fnRandom(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
198  int fnSetScreen(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
199  int fnPreload(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
200  int fnCheckCD(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
201  int fnRestartGame(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
202  int fnQuitGame(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
203  int fnDeathScreen(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
204  int fnSetParallax(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
205  int fnTdebug(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
206 
207  int fnRedFlash(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
208  int fnBlueFlash(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
209  int fnYellow(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
210  int fnGreen(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
211  int fnPurple(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
212  int fnBlack(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
213  static const uint32 _scriptVarInit[NON_ZERO_SCRIPT_VARS][2];
214  static const uint8 *const _startData[];
215  static const uint8 *const _helperData[];
216  void startPosCallFn(uint8 fnId, uint32 param1, uint32 param2, uint32 param3);
217  void runStartScript(const uint8 *data);
218 };
219 
220 enum StartPosOpcodes {
221  opcSeqEnd = 0,
222  opcCallFn,
223  opcCallFnLong,
224  opcSetVar8,
225  opcSetVar16,
226  opcSetVar32,
227  opcGeorge,
228  opcRunStart,
229  opcRunHelper,
230  opcPlaySequence,
231  opcAddObject,
232  opcRemoveObject,
233  opcMegaSet,
234  opcNoSprite
235 };
236 
237 enum HelperScripts {
238  HELP_IRELAND = 0,
239  HELP_SYRIA,
240  HELP_SPAIN,
241  HELP_NIGHTTRAIN,
242  HELP_SCOTLAND,
243  HELP_WHITECOAT,
244  HELP_SPAIN2
245 };
246 
247 } // End of namespace Sword1
248 
249 #endif //BSLOGIC_H
Definition: sword1.h:104
Definition: sound.h:109
Definition: text.h:48
Definition: menu.h:65
Definition: random.h:44
Definition: resman.h:65
Definition: screen.h:75
Definition: atari-screen.h:60
Definition: animation.h:38
Definition: eventman.h:36
Definition: mixer.h:59
Definition: router.h:90
Definition: logic.h:55
Definition: sworddefs.h:100
Definition: objectman.h:33
Definition: mouse.h:70
Definition: control.h:120
Definition: system.h:161
Definition: system.h:38