Permalink
Browse files

MUTATIONOFJB: Disallow interaction with inactive doors.

  • Loading branch information...
MiroslavR committed Aug 29, 2018
1 parent 008bfeb commit 727f9add3abb555fe415cf08688ccc75d6e39700
Showing with 22 additions and 3 deletions.
  1. +6 −2 engines/mutationofjb/gamedata.cpp
  2. +16 −1 engines/mutationofjb/gamedata.h
@@ -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<uint8>(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;
}
@@ -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.
*

0 comments on commit 727f9ad

Please sign in to comment.