From 81789162d3f76ef827eeff7e042ab79206b7b92f Mon Sep 17 00:00:00 2001 From: Miroslav Remák Date: Wed, 29 Aug 2018 18:24:06 +0200 Subject: MUTATIONOFJB: Disallow interaction with inactive doors. --- engines/mutationofjb/gamedata.cpp | 8 ++++++-- engines/mutationofjb/gamedata.h | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/mutationofjb/gamedata.cpp b/engines/mutationofjb/gamedata.cpp index 2c1ee5ab52..a669fcffbb 100644 --- a/engines/mutationofjb/gamedata.cpp +++ b/engines/mutationofjb/gamedata.cpp @@ -39,6 +39,10 @@ static bool readString(Common::ReadStream &stream, char *str) { return true; } +bool Door::isActive() { + return *_name != '\0'; +} + bool Door::loadFromStream(Common::ReadStream &stream) { readString(stream, _name); @@ -183,10 +187,10 @@ uint8 Scene::getNoStatics(bool ignoreNo) const { return (!ignoreNo ? MIN(_noStatics, static_cast(ARRAYSIZE(_statics))) : ARRAYSIZE(_statics)); } -Door *Scene::findDoor(int16 x, int16 y, int *index) { +Door *Scene::findDoor(int16 x, int16 y, bool activeOnly, 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 ((!activeOnly || door.isActive()) && (x >= door._x) && (x < door._x + door._width) && (y >= door._y) && (y < door._y + door._height)) { if (index) { *index = i + 1; } diff --git a/engines/mutationofjb/gamedata.h b/engines/mutationofjb/gamedata.h index 8a67db61e7..5d7dea1b05 100644 --- a/engines/mutationofjb/gamedata.h +++ b/engines/mutationofjb/gamedata.h @@ -83,6 +83,12 @@ struct Door { /* Unknown for now - likely not even used. */ uint8 _SP; + /** + * Check if this door can be interacted with. + * @return True if this door can be interacted with, false otherwise. + */ + bool isActive(); + bool loadFromStream(Common::ReadStream &stream); }; @@ -259,7 +265,16 @@ struct Scene { uint8 getNoObjects(bool ignoreNo = false) const; uint8 getNoStatics(bool ignoreNo = false) const; - Door *findDoor(int16 x, int16 y, int *index = nullptr); + /** + * Finds the door at the given position. By default, only active doors are considered. + * + * @param x X coordinate. + * @param y Y coordinate. + * @param activeOnly If true, consider only active doors; otherwise consider any. + * @param index Output parameter for the found door's ID. + * @return A door if found, nullptr otherwise. + */ + Door *findDoor(int16 x, int16 y, bool activeOnly = true, int *index = nullptr); /** * Finds the static at the given position. By default, only active statics are considered. * -- cgit v1.2.3