Permalink
Browse files

MUTATIONOFJB: Load object frames and implement special handling for m…

…ap scenes.
  • Loading branch information...
LubomirR authored and sev- committed Apr 2, 2018
1 parent 2b94873 commit 99d9055e201b0518baad741f4f46cb86c2f7e172
@@ -159,7 +159,7 @@ void AnimationDecoder::loadDiffFrame(EncryptedFile &file, uint32) {
const uint16 numLines = file.readUint16LE();

for (uint16 line = firstLine; line < firstLine + numLines; ++line) {
uint8 *imageData = reinterpret_cast<uint8 *>(_surface.getBasePtr(0, firstLine));
uint8 *imageData = reinterpret_cast<uint8 *>(_surface.getBasePtr(0, line));

uint8 runs = file.readByte();
while (runs--) {
@@ -65,6 +65,7 @@ Console::Console(MutationOfJBEngine *vm) : _vm(vm) {
registerCmd("showstartup", WRAP_METHOD(Console, cmd_showstartup));
registerCmd("changescene", WRAP_METHOD(Console, cmd_changescene));
registerCmd("dumpsceneinfo", WRAP_METHOD(Console, cmd_dumpsceneinfo));
registerCmd("dumpdoorinfo", WRAP_METHOD(Console, cmd_dumpdoorinfo));
registerCmd("dumpobjectinfo", WRAP_METHOD(Console, cmd_dumpobjectinfo));
registerCmd("dumpstaticinfo", WRAP_METHOD(Console, cmd_dumpstaticinfo));
}
@@ -324,6 +325,38 @@ bool Console::cmd_dumpsceneinfo(int argc, const char **argv) {
return true;
}

bool Console::cmd_dumpdoorinfo(int argc, const char **argv) {
if (argc == 3) {
const uint8 sceneId = atoi(argv[1]);
const uint8 doorId = atoi(argv[2]);

Scene *const scene = _vm->getGame().getGameData().getScene(sceneId);
if (scene) {
Door *const door = scene->getDoor(doorId);
if (door) {
debugPrintf("Name: '%s'\n", convertToASCII(door->_name).c_str());
debugPrintf("DestSceneId: %u\n", (unsigned int) door->_destSceneId);
debugPrintf("DestX: %u\n", (unsigned int) door->_destX);
debugPrintf("DestY: %u\n", (unsigned int) door->_destY);
debugPrintf("X: %u\n", (unsigned int) door->_x);
debugPrintf("Y: %u\n", (unsigned int) door->_y);
debugPrintf("Width: %u\n", (unsigned int) door->_width);
debugPrintf("Height: %u\n", (unsigned int) door->_height);
debugPrintf("WalkToX: %u\n", (unsigned int) door->_walkToX);
debugPrintf("WalkToY: %u\n", (unsigned int) door->_walkToY);
debugPrintf("SP: %u\n", (unsigned int) door->_SP);
} else {
debugPrintf(_("Door %u not found.\n"), (unsigned int) doorId);
}
} else {
debugPrintf(_("Scene %u not found.\n"), (unsigned int) sceneId);
}
} else {
debugPrintf(_("dumpdoorinfo <sceneid> <doorid>\n"));
}

return true;
}
bool Console::cmd_dumpobjectinfo(int argc, const char **argv) {
if (argc == 3) {
const uint8 sceneId = atoi(argv[1]);
@@ -45,6 +45,7 @@ class Console : public GUI::Debugger {
bool cmd_showstartup(int argc, const char **argv);
bool cmd_changescene(int argc, const char **argv);
bool cmd_dumpsceneinfo(int argc, const char **argv);
bool cmd_dumpdoorinfo(int argc, const char **argv);
bool cmd_dumpobjectinfo(int argc, const char **argv);
bool cmd_dumpstaticinfo(int argc, const char **argv);

@@ -46,7 +46,7 @@ Game::Game(MutationOfJBEngine *vm)
globalScriptFile.close();

_localScript = nullptr;
_room = new Room(_vm->getScreen());
_room = new Room(this, _vm->getScreen());

changeScene(13, false); // Initial scene.
}
@@ -55,6 +55,10 @@ GameData &Game::getGameData() {
return *_gameData;
}

Room &Game::getRoom() {
return *_room;
}

Script *Game::getGlobalScript() const {
return _globalScript;
}
@@ -122,36 +126,6 @@ Script *Game::changeSceneDelayScript(uint8 sceneId, bool partB) {
return _delayedLocalScript;
}

Door *Game::findDoor(int16 x, int16 y) {
Scene *scene = _gameData->getCurrentScene();
if (!scene)
return nullptr;

for (int i = 0; i < MIN(ARRAYSIZE(scene->_doors), (int) scene->_noDoors); ++i) {
Door &door = scene->_doors[i];
if ((x >= door._x) && (x < door._x + door._width) && (y >= door._y) && (y < door._y + door._height)) {
return &door;
}
}

return nullptr;
}

Static *Game::findStatic(int16 x, int16 y) {
Scene *scene = _gameData->getCurrentScene();
if (!scene)
return nullptr;

for (int i = 0; i < MIN(ARRAYSIZE(scene->_statics), (int) scene->_noStatics); ++i) {
Static &stat = scene->_statics[i];
if ((x >= stat._x) && (x < stat._x + stat._width) && (y >= stat._y) && (y < stat._y + stat._height)) {
return &stat;
}
}

return nullptr;
}

static Command *findActionInfoCommand(const ActionInfos &infos, const Common::String &entity1Name, const Common::String &entity2Name = Common::String()) {
for (ActionInfos::const_iterator it = infos.begin(); it != infos.end(); ++it) {
if (it->_entity1Name == entity1Name && it->_entity2Name == entity2Name) {
@@ -180,6 +154,10 @@ bool Game::startActionSection(ActionInfo::Action action, const Common::String &e
return false;
}

bool Game::isCurrentSceneMap() const {
return _gameData->_currentScene == 12;
}

void Game::update() {
Command::ExecuteResult res = _scriptExecCtx.runActiveCommand();
if (res == Command::Finished && _delayedLocalScript) {
@@ -39,22 +39,23 @@ class Script;
class Room;
class Door;
class Static;
class Bitmap;

class Game {
public:
Game(MutationOfJBEngine *vm);
GameData &getGameData();

Room &getRoom();
Script *getGlobalScript() const;
Script *getLocalScript() const;

void changeScene(uint8 sceneId, bool partB);
Script *changeSceneDelayScript(uint8 sceneId, bool partB);

Door *findDoor(int16 x, int16 y);
Static *findStatic(int16 x, int16 y);
bool startActionSection(ActionInfo::Action action, const Common::String &entity1Name, const Common::String &entity2Name = Common::String());

bool isCurrentSceneMap() const;

void update();

private:
@@ -151,7 +151,7 @@ Door *Scene::getDoor(uint8 doorId) {
}

Object *Scene::getObject(uint8 objectId, bool ignoreNo) {
if (objectId == 0 || objectId > (!ignoreNo ? MIN(_noObjects, (uint8) ARRAYSIZE(_objects)) : ARRAYSIZE(_objects))) {
if (objectId == 0 || objectId > getNoObjects(ignoreNo)) {
warning(_("Object %d does not exist"), objectId);
return nullptr;
}
@@ -168,6 +168,60 @@ Static *Scene::getStatic(uint8 staticId, bool ignoreNo) {
return &_statics[staticId - 1];
}

uint8 Scene::getNoDoors(bool ignoreNo) const {
return (!ignoreNo ? MIN(_noDoors, (uint8) ARRAYSIZE(_doors)) : ARRAYSIZE(_doors));
}

uint8 Scene::getNoObjects(bool ignoreNo) const {
return (!ignoreNo ? MIN(_noObjects, (uint8) ARRAYSIZE(_objects)) : ARRAYSIZE(_objects));
}

uint8 Scene::getNoStatics(bool ignoreNo) const {
return (!ignoreNo ? MIN(_noStatics, (uint8) ARRAYSIZE(_statics)) : ARRAYSIZE(_statics));
}

Door *Scene::findDoor(int16 x, int16 y, int *index) {
for (int i = 0; i < getNoDoors(); ++i) {
Door &door = _doors[i];
if ((x >= door._x) && (x < door._x + door._width) && (y >= door._y) && (y < door._y + door._height)) {
if (index) {
*index = i + 1;
}
return &door;
}
}

return nullptr;
}

Static *Scene::findStatic(int16 x, int16 y, int *index) {
for (int i = 0; i < getNoStatics(); ++i) {
Static &stat = _statics[i];
if ((x >= stat._x) && (x < stat._x + stat._width) && (y >= stat._y) && (y < stat._y + stat._height)) {
if (index) {
*index = i + 1;
}
return &stat;
}
}

return nullptr;
}

Bitmap *Scene::findBitmap(int16 x, int16 y, int *index) {
for (int i = 0; i < ARRAYSIZE(_bitmaps); ++i) {
Bitmap &bitmap = _bitmaps[i];
if ((x >= bitmap._x1) && (x <= bitmap._x2) && (y >= bitmap._y1) && (y <= bitmap._y2)) {
if (index) {
*index = i + 1;
}
return &bitmap;
}
}

return nullptr;
}


GameData::GameData()
: _currentScene(0),
@@ -121,11 +121,18 @@ struct Bitmap {


struct Scene {

Door *getDoor(uint8 objectId);
Object *getObject(uint8 objectId, bool ignoreNo = false);
Static *getStatic(uint8 staticId, bool ignoreNo = false);

uint8 getNoDoors(bool ignoreNo = false) const;
uint8 getNoObjects(bool ignoreNo = false) const;
uint8 getNoStatics(bool ignoreNo = false) const;

Door *findDoor(int16 x, int16 y, int *index = nullptr);
Static *findStatic(int16 x, int16 y, int *index = nullptr);
Bitmap *findBitmap(int16 x, int16 y, int *index = nullptr);

uint8 _startup;
uint8 _unknown001;
uint8 _unknown002;
Oops, something went wrong.

0 comments on commit 99d9055

Please sign in to comment.