aboutsummaryrefslogtreecommitdiff
path: root/sword1/logic.h
blob: 37fbc823193a0992bd3ac9a9d42487350c7ebde3 (plain)
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
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003-2005 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program 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 General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#ifndef BSLOGIC_H
#define BSLOGIC_H
// combination of logic.c and scr_int.c

#include "sword1/sworddefs.h"
#include "sword1/objectman.h"
#include "common/util.h"
#include "sound/mixer.h"

namespace Sword1 {

#define NON_ZERO_SCRIPT_VARS 95
#define NUM_SCRIPT_VARS		 1179

class Text;
class Sound;
class EventManager;
class Menu;
class Router;
class Screen;
class Mouse;
class Music;

class Logic;
typedef int (Logic::*BSMcodeTable)(Object *, int32, int32, int32, int32, int32, int32, int32);

class Logic {
public:
	Logic(ObjectMan *pObjMan, ResMan *resMan, Screen *pScreen, Mouse *pMouse, Sound *pSound, Music *pMusic, Menu *pMenu, OSystem *system, SoundMixer *mixer);
	~Logic(void);
	void initialize(void);
	void newScreen(uint32 screen);
	void engine(void);
	void updateScreenParams(void);
	void runMouseScript(Object *cpt, int32 scriptId);
	void startPositions(uint32 pos);

	static uint32 _scriptVars[NUM_SCRIPT_VARS];
// public for mouse (menu looking)
	int cfnPresetScript	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
private:
	ObjectMan *_objMan;
	OSystem *_system;
	SoundMixer *_mixer;
	ResMan *_resMan;
	Screen *_screen;
	Sound *_sound;
	Mouse *_mouse;
	Router *_router;
	Text *_textMan;
	EventManager *_eventMan;
	Menu *_menu;
	Music *_music;
	uint32 _newScript; // <= ugly, but I can't avoid it.
	bool _speechRunning, _speechFinished, _textRunning;
	uint8 _speechClickDelay;
	Common::RandomSource _rnd;

	int scriptManager(Object *compact, uint32 id);
	void processLogic(Object *compact, uint32 id);
	int interpretScript(Object *compact, int id, Header *scriptModule, int scriptBase, int scriptNum);

	int logicWaitTalk(Object *compact);
	int logicStartTalk(Object *compact);
	int logicArAnimate(Object *compact, uint32 id);
	int speechDriver(Object *compact);
	int fullAnimDriver(Object *compact);
	int animDriver(Object *compact);

	static BSMcodeTable _mcodeTable[100];

	uint16 inRange(uint16 a, uint16 b, uint16 c);

//- mcodeTable:
	int fnBackground	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnForeground	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSort			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnNoSprite		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnMegaSet		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnAnim			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetFrame		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnFullAnim		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnFullSetFrame	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnFadeDown		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnFadeUp		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnCheckFade		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetSpritePalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetWholePalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetFadeTargetPalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetPaletteToFade(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetPaletteToCut(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnPlaySequence	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);

	int fnIdle			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnPause			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnPauseSeconds	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnQuit			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnKillId		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSuicide		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnNewScript		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSubScript		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnRestartScript	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetBookmark	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnGotoBookmark	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSendSync		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnWaitSync		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	
	int cfnClickInteract(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int cfnSetScript	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);

	int fnInteract		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnIssueEvent	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnCheckForEvent	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnWipeHands		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnISpeak		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnTheyDo		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnTheyDoWeWait	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnWeWait		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnChangeSpeechText(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnTalkError		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnStartTalk		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnCheckForTextLine(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnAddTalkWaitStatusBit(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnRemoveTalkWaitStatusBit(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);

	int fnNoHuman		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnAddHuman		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnBlankMouse	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnNormalMouse	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnLockMouse		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnUnlockMouse	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetMousePointer(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetMouseLuggage(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnMouseOn		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnMouseOff		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnChooser		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnEndChooser	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnStartMenu		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnEndMenu		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	
	int cfnReleaseMenu	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	
	int fnAddSubject	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnAddObject		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnRemoveObject	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnEnterSection	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnLeaveSection	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnChangeFloor	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnWalk			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnTurn			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnStand			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnStandAt		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnFace			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnFaceXy		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnIsFacing		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnGetTo			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnGetToError	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnGetPos		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnGetGamepadXy	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnPlayFx		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnStopFx		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnPlayMusic		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnStopMusic		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnInnerSpace	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnRandom		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetScreen		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnPreload		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnCheckCD		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnRestartGame	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnQuitGame		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnDeathScreen	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnSetParallax	(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnTdebug		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);

	int fnRedFlash		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnBlueFlash		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnYellow		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnGreen			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnPurple		(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	int fnBlack			(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
	static const uint32 _scriptVarInit[NON_ZERO_SCRIPT_VARS][2];
	static const uint8 *_startData[];
	static const uint8 *_helperData[];
	void startPosCallFn(uint8 fnId, uint32 param1, uint32 param2, uint32 param3);
	void runStartScript(const uint8 *data);
};

enum StartPosOpcodes {
	opcSeqEnd = 0,
	opcCallFn,
	opcCallFnLong,
	opcSetVar8,
	opcSetVar16,
	opcSetVar32,
	opcGeorge,
	opcRunStart,
	opcRunHelper,
	opcPlaySequence,
	opcAddObject,
	opcRemoveObject,
	opcMegaSet,
	opcNoSprite
};

enum HelperScripts {
	HELP_IRELAND = 0,
	HELP_SYRIA,
	HELP_SPAIN,
	HELP_NIGHTTRAIN,
	HELP_SCOTLAND,
	HELP_WHITECOAT,
	HELP_SPAIN2
};

} // End of namespace Sword1 

#endif //BSLOGIC_H