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