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 * Additional copyright for this file:
8 * Copyright (C) 1994-1998 Revolution Software Ltd.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24// logic management
25
26#ifndef SWORD2_LOGIC_H
27#define SWORD2_LOGIC_H
28
29#include "common/endian.h"
30#include "sword2/animation.h"
31#include "sword2/memory.h"
32
33namespace Sword2 {
34
35#define MAX_events 10
36
37#define TREE_SIZE 3
38
39// This must allow for the largest number of objects in a screen
40#define OBJECT_KILL_LIST_SIZE 50
41
42#define MAX_SEQUENCE_TEXT_LINES 15
43
44class Sword2Engine;
45class Router;
46
47struct EventUnit {
48 uint32 id;
49 uint32 interact_id;
50};
51
52class Logic {
53private:
54 Sword2Engine *_vm;
55
56 inline byte *decodePtr(int32 n) {
57 return _vm->_memory->decodePtr(n);
58 }
59
60 uint32 _objectKillList[OBJECT_KILL_LIST_SIZE];
61
62 // keeps note of no. of objects in the kill list
63 uint32 _kills;
64
65 // denotes the res id of the game-object-list in current use
66 uint32 _currentRunList;
67
68 //pc during logic loop
69 uint32 _pc;
70
71 // each object has one of these tacked onto the beginning
72 ObjectHub _curObjectHub;
73
74 EventUnit _eventList[MAX_events];
75
76 MoviePlayer *_moviePlayer;
77
78 // Resource id of the wav to use as lead-in/lead-out from smacker
79 uint32 _smackerLeadIn;
80 uint32 _smackerLeadOut;
81
82 // keeps count of number of text lines to disaply during the sequence
83 uint32 _sequenceTextLines;
84
85 MovieText _sequenceTextList[MAX_SEQUENCE_TEXT_LINES];
86
87 // when not playing a wav we calculate the speech time based upon
88 // length of ascii
89
90 uint32 _speechTime;
91
92 uint32 _animId;
93
94 // 0 lip synced and repeating - 1 normal once through
95 uint32 _speechAnimType;
96
97 uint32 _leftClickDelay; // click-delay for LEFT mouse button
98 uint32 _rightClickDelay; // click-delay for RIGHT mouse button
99
100 // calculated by locateTalker() for use in speech-panning & text-sprite
101 // positioning
102
103 int16 _textX, _textY;
104
105 void locateTalker(int32 *params);
106 void formText(int32 *params);
107 bool wantSpeechForLine(uint32 wavId);
108
109 // Set by fnPassMega()
110 byte _engineMega[56];
111
112
113 bool _cycleSkip;
114 bool _speechRunning;
115
116public:
117 Logic(Sword2Engine *vm);
118 ~Logic();
119
120 EventUnit *getEventList() { return _eventList; }
121 byte *getEngineMega() { return _engineMega; }
122
123 byte _saveLogic[8];
124 byte _saveGraphic[12];
125 byte _saveMega[56];
126
127 // Point to the global variable data
128 byte *_scriptVars;
129
130 // "TEXT" - current official text line number - will match the wav
131 // filenames
132
133 int16 _officialTextNumber;
134
135 // so speech text cleared when running a new start-script
136 uint32 _speechTextBlocNo;
137
138 uint32 readVar(int n) {
139 return READ_LE_UINT32(_scriptVars + 4 * n);
140 }
141
142 void writeVar(int n, uint32 value) {
143 WRITE_LE_UINT32(_scriptVars + 4 * n, value);
144 }
145
146 int runResScript(uint32 scriptRes, uint32 offset);
147 int runResObjScript(uint32 scriptRes, uint32 objRes, uint32 offset);
148 int runScript(byte *scriptData, byte *objectData, uint32 offset);
149 int runScript2(byte *scriptData, byte *objectData, byte *offset);
150
151 void sendEvent(uint32 id, uint32 interact_id);
152 void setPlayerActionEvent(uint32 id, uint32 interact_id);
153 void startEvent();
154 int checkEventWaiting();
155 void clearEvent(uint32 id);
156 void killAllIdsEvents(uint32 id);
157
158 uint32 countEvents();
159
160 struct SyncUnit {
161 uint32 id;
162 uint32 sync;
163 };
164
165 // There won't be many, will there? Probably 2 at most i reckon
166 SyncUnit _syncList[10];
167
168 void clearSyncs(uint32 id);
169 void sendSync(uint32 id, uint32 sync);
170 int getSync();
171
172 Router *_router;
173
174 typedef int32 (Logic::*OpcodeProc)(int32 *);
175 struct OpcodeEntry {
176 OpcodeProc proc;
177 const char *desc;
178 };
179 const OpcodeEntry *_opcodes;
180 int _numOpcodes;
181 void setupOpcodes();
182
183 int32 fnTestFunction(int32 *params);
184 int32 fnTestFlags(int32 *params);
185 int32 fnRegisterStartPoint(int32 *params);
186 int32 fnInitBackground(int32 *params);
187 int32 fnSetSession(int32 *params);
188 int32 fnBackSprite(int32 *params);
189 int32 fnSortSprite(int32 *params);
190 int32 fnForeSprite(int32 *params);
191 int32 fnRegisterMouse(int32 *params);
192 int32 fnAnim(int32 *params);
193 int32 fnRandom(int32 *params);
194 int32 fnPreLoad(int32 *params);
195 int32 fnAddSubject(int32 *params);
196 int32 fnInteract(int32 *params);
197 int32 fnChoose(int32 *params);
198 int32 fnWalk(int32 *params);
199 int32 fnWalkToAnim(int32 *params);
200 int32 fnTurn(int32 *params);
201 int32 fnStandAt(int32 *params);
202 int32 fnStand(int32 *params);
203 int32 fnStandAfterAnim(int32 *params);
204 int32 fnPause(int32 *params);
205 int32 fnMegaTableAnim(int32 *params);
206 int32 fnAddMenuObject(int32 *params);
207 int32 fnStartConversation(int32 *params);
208 int32 fnEndConversation(int32 *params);
209 int32 fnSetFrame(int32 *params);
210 int32 fnRandomPause(int32 *params);
211 int32 fnRegisterFrame(int32 *params);
212 int32 fnNoSprite(int32 *params);
213 int32 fnSendSync(int32 *params);
214 int32 fnUpdatePlayerStats(int32 *params);
215 int32 fnPassGraph(int32 *params);
216 int32 fnInitFloorMouse(int32 *params);
217 int32 fnPassMega(int32 *params);
218 int32 fnFaceXY(int32 *params);
219 int32 fnEndSession(int32 *params);
220 int32 fnNoHuman(int32 *params);
221 int32 fnAddHuman(int32 *params);
222 int32 fnWeWait(int32 *params);
223 int32 fnTheyDoWeWait(int32 *params);
224 int32 fnTheyDo(int32 *params);
225 int32 fnWalkToTalkToMega(int32 *params);
226 int32 fnFadeDown(int32 *params);
227 int32 fnISpeak(int32 *params);
228 int32 fnTotalRestart(int32 *params);
229 int32 fnSetWalkGrid(int32 *params);
230 int32 fnSpeechProcess(int32 *params);
231 int32 fnSetScaling(int32 *params);
232 int32 fnStartEvent(int32 *params);
233 int32 fnCheckEventWaiting(int32 *params);
234 int32 fnRequestSpeech(int32 *params);
235 int32 fnGosub(int32 *params);
236 int32 fnTimedWait(int32 *params);
237 int32 fnPlayFx(int32 *params);
238 int32 fnStopFx(int32 *params);
239 int32 fnPlayMusic(int32 *params);
240 int32 fnStopMusic(int32 *params);
241 int32 fnSetValue(int32 *params);
242 int32 fnNewScript(int32 *params);
243 int32 fnGetSync(int32 *params);
244 int32 fnWaitSync(int32 *params);
245 int32 fnRegisterWalkGrid(int32 *params);
246 int32 fnReverseMegaTableAnim(int32 *params);
247 int32 fnReverseAnim(int32 *params);
248 int32 fnAddToKillList(int32 *params);
249 int32 fnSetStandbyCoords(int32 *params);
250 int32 fnBackPar0Sprite(int32 *params);
251 int32 fnBackPar1Sprite(int32 *params);
252 int32 fnForePar0Sprite(int32 *params);
253 int32 fnForePar1Sprite(int32 *params);
254 int32 fnSetPlayerActionEvent(int32 *params);
255 int32 fnSetScrollCoordinate(int32 *params);
256 int32 fnStandAtAnim(int32 *params);
257 int32 fnSetScrollLeftMouse(int32 *params);
258 int32 fnSetScrollRightMouse(int32 *params);
259 int32 fnColor(int32 *params);
260 int32 fnFlash(int32 *params);
261 int32 fnPreFetch(int32 *params);
262 int32 fnGetPlayerSaveData(int32 *params);
263 int32 fnPassPlayerSaveData(int32 *params);
264 int32 fnSendEvent(int32 *params);
265 int32 fnAddWalkGrid(int32 *params);
266 int32 fnRemoveWalkGrid(int32 *params);
267 int32 fnCheckForEvent(int32 *params);
268 int32 fnPauseForEvent(int32 *params);
269 int32 fnClearEvent(int32 *params);
270 int32 fnFaceMega(int32 *params);
271 int32 fnPlaySequence(int32 *params);
272 int32 fnShadedSprite(int32 *params);
273 int32 fnUnshadedSprite(int32 *params);
274 int32 fnFadeUp(int32 *params);
275 int32 fnDisplayMsg(int32 *params);
276 int32 fnSetObjectHeld(int32 *params);
277 int32 fnAddSequenceText(int32 *params);
278 int32 fnResetGlobals(int32 *params);
279 int32 fnSetPalette(int32 *params);
280 int32 fnRegisterPointerText(int32 *params);
281 int32 fnFetchWait(int32 *params);
282 int32 fnRelease(int32 *params);
283 int32 fnPrepareMusic(int32 *params);
284 int32 fnSoundFetch(int32 *params);
285 int32 fnSmackerLeadIn(int32 *params);
286 int32 fnSmackerLeadOut(int32 *params);
287 int32 fnStopAllFx(int32 *params);
288 int32 fnCheckPlayerActivity(int32 *params);
289 int32 fnResetPlayerActivityDelay(int32 *params);
290 int32 fnCheckMusicPlaying(int32 *params);
291 int32 fnPlayCredits(int32 *params);
292 int32 fnSetScrollSpeedNormal(int32 *params);
293 int32 fnSetScrollSpeedSlow(int32 *params);
294 int32 fnRemoveChooser(int32 *params);
295 int32 fnSetFxVolAndPan(int32 *params);
296 int32 fnSetFxVol(int32 *params);
297 int32 fnRestoreGame(int32 *params);
298 int32 fnRefreshInventory(int32 *params);
299 int32 fnChangeShadows(int32 *params);
300
301 // do one cycle of the current session
302 int processSession();
303
304 // cause the logic loop to terminate and drop out
305 void expressChangeSession(uint32 sesh_id);
306
307 uint32 getRunList();
308
309 // setup script_id and script_pc in _curObjectHub - called by fnGosub()
310 void logicUp(uint32 new_script);
311
312 void logicReplace(uint32 new_script);
313 void logicOne(uint32 new_script);
314 void resetKillList();
315
316 // Read location number from script vars
317 uint32 getLocationNum();
318};
319
320} // End of namespace Sword2
321
322#endif
Definition: logic.h:52
Definition: animation.h:62
Definition: header.h:290
Definition: router.h:97
Definition: sword2.h:99
Definition: animation.h:37
Definition: logic.h:47
Definition: logic.h:175
Definition: logic.h:160
Definition: animation.h:46