Permalink
Browse files

MUTATIONOFJB: Load initial game state and allow room change

  • Loading branch information...
LubomirR authored and sev- committed Feb 15, 2018
1 parent 95cd6b7 commit 3696865e6910067e011500d09e0d0e44bab796c1
@@ -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;
}

}
@@ -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);
};

}
@@ -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)
@@ -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;
Oops, something went wrong.

0 comments on commit 3696865

Please sign in to comment.