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 #ifndef SWORD2_SWORD2_H 26 #define SWORD2_SWORD2_H 27 28 #define FRAMES_PER_SECOND 12 29 30 // Enable this to make it possible to clear the mouse cursor luggage by 31 // right-clicking. The original didn't do this, but it feels natural to me. 32 // However, I'm afraid that it'll interfer badly with parts of the game, so 33 // for now I'll keep it disabled. 34 35 #define RIGHT_CLICK_CLEARS_LUGGAGE 0 36 37 #include "engines/engine.h" 38 39 #include "common/events.h" 40 #include "common/util.h" 41 #include "common/random.h" 42 43 #define MAX_starts 100 44 #define MAX_description 100 45 46 class OSystem; 47 48 /** 49 * This is the namespace of the Sword2 engine. 50 * 51 * Status of this engine: ??? 52 * 53 * Games using this engine: 54 * - Broken Sword II: The Smoking Mirror 55 */ 56 namespace Sword2 { 57 58 enum { 59 GF_DEMO = 1 << 0 60 }; 61 62 class MemoryManager; 63 class ResourceManager; 64 class Sound; 65 class Screen; 66 class Mouse; 67 class Logic; 68 class FontRenderer; 69 class Gui; 70 class Debugger; 71 72 enum { 73 RD_LEFTBUTTONDOWN = 0x01, 74 RD_LEFTBUTTONUP = 0x02, 75 RD_RIGHTBUTTONDOWN = 0x04, 76 RD_RIGHTBUTTONUP = 0x08, 77 RD_WHEELUP = 0x10, 78 RD_WHEELDOWN = 0x20, 79 RD_KEYDOWN = 0x40 80 }; 81 82 struct MouseEvent { 83 bool pending; 84 uint16 buttons; 85 }; 86 87 struct KeyboardEvent { 88 bool pending; 89 Common::KeyState kbd; 90 }; 91 92 struct StartUp { 93 char description[MAX_description]; 94 95 // id of screen manager object 96 uint32 start_res_id; 97 98 // Tell the manager which startup you want (if there are more than 1) 99 // (i.e more than 1 entrance to a screen and/or separate game boots) 100 uint32 key; 101 }; 102 103 class Sword2Engine : public Engine { 104 private: 105 uint32 _inputEventFilter; 106 107 // The event "buffers" 108 MouseEvent _mouseEvent; 109 KeyboardEvent _keyboardEvent; 110 111 uint32 _bootParam; 112 int32 _saveSlot; 113 114 void getPlayerStructures(); 115 void putPlayerStructures(); 116 117 uint32 saveData(uint16 slotNo, byte *buffer, uint32 bufferSize); 118 uint32 restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize); 119 120 uint32 calcChecksum(byte *buffer, uint32 size); 121 122 uint32 _totalStartups; 123 uint32 _totalScreenManagers; 124 uint32 _startRes; 125 126 bool _useSubtitles; 127 int _gameSpeed; 128 129 // Used to trigger GMM Loading 130 int _gmmLoadSlot; 131 132 StartUp _startList[MAX_starts]; 133 134 // We need these to fetch data from SCREENS.CLU, which is 135 // a resource file with custom format keeping background and 136 // parallax data (which is removed from multiscreen files). 137 byte *fetchPsxBackground(uint32 location); 138 byte *fetchPsxParallax(uint32 location, uint8 level); // level: 0 -> bg, 1 -> fg 139 140 // Original game platform (PC/PSX) 141 static Common::Platform _platform; 142 143 protected: 144 // Engine APIs 145 virtual Common::Error run(); 146 virtual GUI::Debugger *getDebugger(); 147 virtual bool hasFeature(EngineFeature f) const; 148 virtual void syncSoundSettings(); 149 virtual void pauseEngineIntern(bool pause); 150 151 public: 152 Sword2Engine(OSystem *syst); 153 ~Sword2Engine(); 154 155 int getFramesPerSecond(); 156 157 void registerDefaultSettings(); 158 void readSettings(); 159 void writeSettings(); 160 161 void setupPersistentResources(); 162 getSubtitles()163 bool getSubtitles() { return _useSubtitles; } setSubtitles(bool b)164 void setSubtitles(bool b) { _useSubtitles = b; } 165 166 // GMM Loading/Saving 167 Common::Error saveGameState(int slot, const Common::String &desc); 168 bool canSaveGameStateCurrently(); 169 Common::Error loadGameState(int slot); 170 bool canLoadGameStateCurrently(); 171 172 uint32 _features; 173 174 MemoryManager *_memory; 175 ResourceManager *_resman; 176 Sound *_sound; 177 Screen *_screen; 178 Mouse *_mouse; 179 Logic *_logic; 180 FontRenderer *_fontRenderer; 181 182 Debugger *_debugger; 183 184 Common::RandomSource _rnd; 185 186 uint32 _speechFontId; 187 uint32 _controlsFontId; 188 uint32 _redFontId; 189 190 uint32 setInputEventFilter(uint32 filter); 191 192 void parseInputEvents(); 193 194 bool checkForMouseEvents(); 195 MouseEvent *mouseEvent(); 196 KeyboardEvent *keyboardEvent(); 197 198 bool _wantSfxDebug; 199 200 int32 _gameCycle; 201 202 #if RIGHT_CLICK_CLEARS_LUGGAGE 203 bool heldIsInInventory(); 204 #endif 205 206 void fetchPalette(byte *screenFile, byte *palBuffer); 207 byte *fetchScreenHeader(byte *screenFile); 208 byte *fetchLayerHeader(byte *screenFile, uint16 layerNo); 209 byte *fetchShadingMask(byte *screenFile); 210 211 byte *fetchAnimHeader(byte *animFile); 212 byte *fetchCdtEntry(byte *animFile, uint16 frameNo); 213 byte *fetchFrameHeader(byte *animFile, uint16 frameNo); 214 byte *fetchBackgroundParallaxLayer(byte *screenFile, int layer); 215 byte *fetchBackgroundLayer(byte *screenFile); 216 byte *fetchForegroundParallaxLayer(byte *screenFile, int layer); 217 byte *fetchTextLine(byte *file, uint32 text_line); 218 bool checkTextLine(byte *file, uint32 text_line); 219 byte *fetchPaletteMatchTable(byte *screenFile); 220 221 uint32 saveGame(uint16 slotNo, const byte *description); 222 uint32 restoreGame(uint16 slotNo); 223 uint32 getSaveDescription(uint16 slotNo, byte *description); 224 bool saveExists(); 225 bool saveExists(uint16 slotNo); 226 uint32 restoreFromBuffer(byte *buffer, uint32 size); 227 Common::String getSaveFileName(uint16 slotNo); 228 uint32 findBufferSize(); 229 230 void startGame(); 231 void gameCycle(); 232 void restartGame(); 233 234 void sleepUntil(uint32 time); 235 236 void initializeFontResourceFlags(); 237 void initializeFontResourceFlags(uint8 language); 238 239 bool initStartMenu(); 240 void registerStartPoint(int32 key, char *name); 241 getNumStarts()242 uint32 getNumStarts() { return _totalStartups; } getNumScreenManagers()243 uint32 getNumScreenManagers() { return _totalScreenManagers; } getStartList()244 StartUp *getStartList() { return _startList; } 245 246 void runStart(int start); 247 248 // Convenience alias for OSystem::getMillis(). 249 // This is a bit hackish, of course :-). 250 uint32 getMillis(); 251 252 //Used to check wether we are running PSX version isPsx()253 static bool isPsx() { return _platform == Common::kPlatformPSX; } 254 }; 255 256 } // End of namespace Sword2 257 258 #endif 259