diff options
author | Ľubomír Remák | 2018-02-15 22:05:56 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | 3696865e6910067e011500d09e0d0e44bab796c1 (patch) | |
tree | 10e861cac661f81f8bd40dd56b3d3baebc1e161c | |
parent | 95cd6b74426b555e58577be0c46006a60fd77979 (diff) | |
download | scummvm-rg350-3696865e6910067e011500d09e0d0e44bab796c1.tar.gz scummvm-rg350-3696865e6910067e011500d09e0d0e44bab796c1.tar.bz2 scummvm-rg350-3696865e6910067e011500d09e0d0e44bab796c1.zip |
MUTATIONOFJB: Load initial game state and allow room change
-rw-r--r-- | engines/mutationofjb/game.cpp | 152 | ||||
-rw-r--r-- | engines/mutationofjb/game.h | 134 | ||||
-rw-r--r-- | engines/mutationofjb/module.mk | 6 | ||||
-rw-r--r-- | engines/mutationofjb/mutationofjb.cpp | 64 | ||||
-rw-r--r-- | engines/mutationofjb/mutationofjb.h | 5 | ||||
-rw-r--r-- | engines/mutationofjb/room.cpp | 10 | ||||
-rw-r--r-- | engines/mutationofjb/util.cpp | 35 | ||||
-rw-r--r-- | engines/mutationofjb/util.h | 25 |
8 files changed, 420 insertions, 11 deletions
diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp new file mode 100644 index 0000000000..581077acd6 --- /dev/null +++ b/engines/mutationofjb/game.cpp @@ -0,0 +1,152 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "mutationofjb/game.h" +#include "common/stream.h" +#include "common/util.h" + +namespace MutationOfJB { + +static bool readString(Common::ReadStream &stream, char *str) +{ + char buf[MAX_STR_LENGTH]; + memset(str, 0, MAX_STR_LENGTH + 1); + + uint8 len = stream.readByte(); + stream.read(buf, MAX_STR_LENGTH); + + len = MIN(len, MAX_STR_LENGTH); + memcpy(str, buf, len); + + return true; +} + +bool Door::loadFromStream(Common::ReadStream &stream) { + readString(stream, _name); + + _destSceneId = stream.readByte(); + _destX = stream.readUint16LE(); + _destY = stream.readUint16LE(); + _x = stream.readUint16LE(); + _y = stream.readByte(); + _width = stream.readUint16LE(); + _height = stream.readByte(); + _walkToX = stream.readUint16LE(); + _walkToY = stream.readByte(); + _SP = stream.readByte(); + + return true; +} + +bool Object::loadFromStream(Common::ReadStream &stream) { + _AC = stream.readByte(); + _FA = stream.readByte(); + _FR = stream.readByte(); + _NA = stream.readByte(); + _FS = stream.readByte(); + _unknown = stream.readByte(); + _CA = stream.readByte(); + _x = stream.readUint16LE(); + _y = stream.readByte(); + _XL = stream.readUint16LE(); + _YL = stream.readByte(); + _WX = stream.readUint16LE(); + _WY = stream.readByte(); + _SP = stream.readByte(); + + return true; +} + +bool Static::loadFromStream(Common::ReadStream &stream) { + _active = stream.readByte(); + readString(stream, _name); + _x = stream.readUint16LE(); + _y = stream.readByte(); + _width = stream.readUint16LE(); + _height = stream.readByte(); + _walkToX = stream.readUint16LE(); + _walkToY = stream.readByte(); + _SP = stream.readByte(); + + return true; +} + +bool Bitmap::loadFromStream(Common::ReadStream &stream) { + _unknown = stream.readByte(); + _isVisible = stream.readByte(); + _x1 = stream.readUint16LE(); + _y1 = stream.readByte(); + _x2 = stream.readUint16LE(); + _y2 = stream.readByte(); + + return true; +} + +bool SceneInfo::loadFromStream(Common::ReadStream &stream) { + int i; + + _startup = stream.readByte(); + _unknown001 = stream.readByte(); + _unknown002 = stream.readByte(); + _unknown003 = stream.readByte(); + _DL = stream.readByte(); + + _noDoors = stream.readByte(); + for (i = 0; i < ARRAYSIZE(_doors); ++i) { + _doors[i].loadFromStream(stream); + } + + _noObjects = stream.readByte(); + for (i = 0; i < ARRAYSIZE(_objects); ++i) { + _objects[i].loadFromStream(stream); + } + + _noStatics = stream.readByte(); + for (i = 0; i < ARRAYSIZE(_statics); ++i) { + _statics[i].loadFromStream(stream); + } + + for (i = 0; i < ARRAYSIZE(_bitmaps); ++i) { + _bitmaps[i].loadFromStream(stream); + } + + _obstacleY1 = stream.readByte(); + _unknown386 = stream.readByte(); + _palRotStart = stream.readByte(); + _palRotEnd = stream.readByte(); + _palRotPeriod = stream.readByte(); + stream.read(_unknown38A, 80); + + return true; +} + +GameData::GameData() : _currentScene(0) {} + +bool GameData::loadFromStream(Common::ReadStream &stream) { + for (int i = 0; i < ARRAYSIZE(_scenes); ++i) { + _scenes[i].loadFromStream(stream); + } + + return true; +} + +} diff --git a/engines/mutationofjb/game.h b/engines/mutationofjb/game.h new file mode 100644 index 0000000000..d8f2079e3a --- /dev/null +++ b/engines/mutationofjb/game.h @@ -0,0 +1,134 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" + +namespace Common +{ + class ReadStream; +} + +namespace MutationOfJB +{ + +static const uint8 MAX_STR_LENGTH = 0x14; + +struct Door { + char _name[MAX_STR_LENGTH + 1]; + uint8 _destSceneId; + uint16 _destX; + uint16 _destY; + uint16 _x; + uint8 _y; + uint16 _width; + uint8 _height; + uint16 _walkToX; + uint8 _walkToY; + uint8 _SP; + + bool loadFromStream(Common::ReadStream &stream); +}; + +struct Object { + uint8 _AC; + uint8 _FA; + uint8 _FR; + uint8 _NA; + uint8 _FS; + uint8 _unknown; + uint8 _CA; + uint16 _x; + uint8 _y; + uint16 _XL; + uint8 _YL; + uint16 _WX; + uint8 _WY; + uint8 _SP; + + bool loadFromStream(Common::ReadStream &stream); +}; + +struct Static { + uint8 _active; + char _name[MAX_STR_LENGTH + 1]; + uint16 _x; + uint8 _y; + uint16 _width; + uint8 _height; + uint16 _walkToX; + uint8 _walkToY; + uint8 _SP; + + bool loadFromStream(Common::ReadStream &stream); +}; + +struct Bitmap { + uint8 _unknown; + uint8 _isVisible; + uint16 _x1; + uint8 _y1; + uint16 _x2; + uint8 _y2; + + bool loadFromStream(Common::ReadStream &stream); +}; + + +struct SceneInfo { + uint8 _startup; + uint8 _unknown001; + uint8 _unknown002; + uint8 _unknown003; + uint8 _DL; + + uint8 _noDoors; + Door _doors[5]; + + uint8 _noObjects; + Object _objects[9]; + + uint8 _noStatics; + Static _statics[15]; + + Bitmap _bitmaps[10]; + + uint8 _obstacleY1; + uint8 _unknown386; + uint8 _palRotStart; + uint8 _palRotEnd; + uint8 _palRotPeriod; + uint8 _unknown38A[80]; + + bool loadFromStream(Common::ReadStream &stream); +}; + +struct GameData +{ + GameData(); + + SceneInfo _scenes[45]; + uint8 _currentScene; + + bool loadFromStream(Common::ReadStream &stream); +}; + +} diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk index fcb9478bb7..7baea826c1 100644 --- a/engines/mutationofjb/module.mk +++ b/engines/mutationofjb/module.mk @@ -1,10 +1,12 @@ MODULE := engines/mutationofjb MODULE_OBJS := \ - encryptedfile.o \ detection.o \ + encryptedfile.o \ + game.o \ mutationofjb.o \ - room.o + room.o \ + util.o # This module can be built as a plugin ifeq ($(ENABLE_MUTATIONOFJB), DYNAMIC_PLUGIN) diff --git a/engines/mutationofjb/mutationofjb.cpp b/engines/mutationofjb/mutationofjb.cpp index 04068646e4..dc7f51869c 100644 --- a/engines/mutationofjb/mutationofjb.cpp +++ b/engines/mutationofjb/mutationofjb.cpp @@ -27,11 +27,15 @@ #include "common/system.h" #include "common/events.h" #include "graphics/screen.h" +#include "graphics/cursorman.h" #include "engines/util.h" #include "mutationofjb/mutationofjb.h" #include "mutationofjb/room.h" +#include "mutationofjb/game.h" +#include "mutationofjb/encryptedfile.h" +#include "mutationofjb/util.h" namespace MutationOfJB { @@ -48,19 +52,73 @@ MutationOfJBEngine::~MutationOfJBEngine() { debug("MutationOfJBEngine::~MutationOfJBEngine"); } +bool MutationOfJBEngine::loadGameData(bool partB) { + EncryptedFile file; + const char *fileName = !partB ? "startup.dat" : "startupb.dat"; + file.open(fileName); + if (!file.isOpen()) { + reportFileMissingError(fileName); + return false; + } + + _gameData->loadFromStream(file); + + file.close(); + + return true; +} + +void MutationOfJBEngine::setupCursor() +{ + const uint8 white[] = {0xFF, 0xFF, 0xFF}; + const uint8 cursor[] = {0xFF}; + + _screen->setPalette(white, 0xFF, 1); + + CursorMan.disableCursorPalette(true); + CursorMan.pushCursor(cursor, 1, 1, 0, 0, 0); + CursorMan.showMouse(true); +} + Common::Error MutationOfJBEngine::run() { debug("MutationOfJBEngine::run"); initGraphics(320, 200); + _console = new Console(this); _screen = new Graphics::Screen; + setupCursor(); + + _gameData = new GameData; + _gameData->_currentScene = 13; + loadGameData(false); + _room = new Room(_screen); - _room->load(13, false); + _room->load(_gameData->_currentScene, false); while(!shouldQuit()) { Common::Event event; - while (_eventMan->pollEvent(event)); - _system->delayMillis(100); + while (_eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_LBUTTONDOWN: + { + const SceneInfo &sceneInfo = _gameData->_scenes[_gameData->_currentScene - 1]; + for (int i = 0; i < MIN(ARRAYSIZE(sceneInfo._doors), (int) sceneInfo._noDoors); ++i) { + const Door &door = sceneInfo._doors[i]; + if ((event.mouse.x >= door._x) && (event.mouse.x < door._x + door._width) && (event.mouse.y >= door._y) && (event.mouse.y < door._y + door._height)) { + _gameData->_currentScene = door._destSceneId; + _room->load(_gameData->_currentScene, false); + } + } + break; + } + default: + break; + } + } + + _system->delayMillis(40); + _screen->update(); } return Common::kNoError; diff --git a/engines/mutationofjb/mutationofjb.h b/engines/mutationofjb/mutationofjb.h index 815baf8b5c..75bd6788d6 100644 --- a/engines/mutationofjb/mutationofjb.h +++ b/engines/mutationofjb/mutationofjb.h @@ -34,6 +34,7 @@ namespace MutationOfJB { class Console; class Room; +struct GameData; class MutationOfJBEngine : public Engine { public: @@ -42,8 +43,12 @@ public: virtual Common::Error run(); private: + bool loadGameData(bool partB); + void setupCursor(); + Console *_console; Room *_room; + GameData *_gameData; Graphics::Screen *_screen; }; diff --git a/engines/mutationofjb/room.cpp b/engines/mutationofjb/room.cpp index e927971858..298a54bbb1 100644 --- a/engines/mutationofjb/room.cpp +++ b/engines/mutationofjb/room.cpp @@ -22,9 +22,9 @@ #include "mutationofjb/room.h" #include "mutationofjb/encryptedfile.h" +#include "mutationofjb/util.h" +#include "common/str.h" #include "graphics/screen.h" -#include "engines/engine.h" -#include "common/translation.h" namespace MutationOfJB { @@ -37,9 +37,7 @@ bool Room::load(uint8 roomNumber, bool roomB) { file.open(fileName); if (!file.isOpen()) { - Common::String errorMessage = Common::String::format(_("Unable to locate the '%s' engine data file."), fileName.c_str()); - GUIErrorMessage(errorMessage); - warning("%s", errorMessage.c_str()); + reportFileMissingError(fileName.c_str()); return false; } @@ -90,7 +88,7 @@ void Room::loadPalette(EncryptedFile &file) { palette[j] <<= 2; // Uses 6-bit colors. } - _screen->setPalette(palette); + _screen->setPalette(palette, 0x00, 0xBF); // Load only 0xBF colors. } void Room::loadBackground(EncryptedFile &file, uint32 size) { diff --git a/engines/mutationofjb/util.cpp b/engines/mutationofjb/util.cpp new file mode 100644 index 0000000000..41d2a3a039 --- /dev/null +++ b/engines/mutationofjb/util.cpp @@ -0,0 +1,35 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "mutationofjb/util.h" +#include "common/str.h" +#include "common/translation.h" +#include "engines/engine.h" + +namespace MutationOfJB { + void reportFileMissingError(const char *fileName) { + Common::String errorMessage = Common::String::format(_("Unable to locate the '%s' engine data file."), fileName); + GUIErrorMessage(errorMessage); + warning("%s", errorMessage.c_str()); + } +} + diff --git a/engines/mutationofjb/util.h b/engines/mutationofjb/util.h new file mode 100644 index 0000000000..3059d51012 --- /dev/null +++ b/engines/mutationofjb/util.h @@ -0,0 +1,25 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +namespace MutationOfJB { + void reportFileMissingError(const char *fileName); +} |