aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2018-01-13 16:20:49 -0500
committerPaul Gilbert2018-01-13 16:20:49 -0500
commit17d68b8bf9903ada535d4d5701815f57dde8b9a9 (patch)
treef088c2b99142e4860c2f843b9321f640c001572d /engines
parentd52bfbb75231cd66d119ff12b91b9ebce4423c84 (diff)
downloadscummvm-rg350-17d68b8bf9903ada535d4d5701815f57dde8b9a9.tar.gz
scummvm-rg350-17d68b8bf9903ada535d4d5701815f57dde8b9a9.tar.bz2
scummvm-rg350-17d68b8bf9903ada535d4d5701815f57dde8b9a9.zip
XEEN: Centralize logic for finding map in _mazeData array
Diffstat (limited to 'engines')
-rw-r--r--engines/xeen/map.cpp71
-rw-r--r--engines/xeen/map.h6
2 files changed, 35 insertions, 42 deletions
diff --git a/engines/xeen/map.cpp b/engines/xeen/map.cpp
index 2b954f5afa..20a6c841c8 100644
--- a/engines/xeen/map.cpp
+++ b/engines/xeen/map.cpp
@@ -1323,6 +1323,17 @@ void Map::load(int mapId) {
files.setGameCc(isDarkCc);
}
+void Map::findMap(int mapId) {
+ if (mapId == -1)
+ mapId = _vm->_party->_mazeId;
+
+ _mazeDataIndex = 0;
+ while (_mazeDataIndex < 9 && _mazeData[_mazeDataIndex]._mazeId != mapId)
+ ++_mazeDataIndex;
+ if (_mazeDataIndex == 9)
+ error("Could not find map %d", mapId);
+}
+
int Map::mazeLookup(const Common::Point &pt, int layerShift, int wallMask) {
Common::Point pos = pt;
int mapId = _vm->_party->_mazeId;
@@ -1333,9 +1344,7 @@ int Map::mazeLookup(const Common::Point &pt, int layerShift, int wallMask) {
}
// Find the correct maze data out of the set to use
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != _vm->_party->_mazeId)
- ++_mazeDataIndex;
+ findMap();
// Handle map changing to the north or south as necessary
if (pos.y & 16) {
@@ -1349,9 +1358,7 @@ int Map::mazeLookup(const Common::Point &pt, int layerShift, int wallMask) {
if (mapId) {
// Move to the correct map to north/south
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
} else {
// No map, so reached outside indoor area or outer space outdoors
_currentSteppedOn = true;
@@ -1369,11 +1376,9 @@ int Map::mazeLookup(const Common::Point &pt, int layerShift, int wallMask) {
mapId = _mazeData[_mazeDataIndex]._surroundingMazes._west;
}
- if (mapId) {
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
- }
+ if (mapId)
+ // Move to the correct map to east/west
+ findMap(mapId);
}
if (mapId) {
@@ -1489,10 +1494,10 @@ void Map::saveMaze() {
void Map::cellFlagLookup(const Common::Point &pt) {
Common::Point pos = pt;
+ findMap();
+
int mapId = _vm->_party->_mazeId;
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
// Handle map changing to the north or south as necessary
if (pos.y & 16) {
@@ -1504,9 +1509,7 @@ void Map::cellFlagLookup(const Common::Point &pt) {
mapId = _mazeData[_mazeDataIndex]._surroundingMazes._south;
}
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
}
// Handle map changing to the east or west as necessary
@@ -1519,9 +1522,7 @@ void Map::cellFlagLookup(const Common::Point &pt) {
mapId = _mazeData[_mazeDataIndex]._surroundingMazes._west;
}
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
}
// Get the cell flags
@@ -1575,9 +1576,7 @@ int Map::getCell(int idx) {
return INVALID_CELL;
}
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
if (pt.y & 16) {
if (pt.y >= 0) {
@@ -1610,9 +1609,7 @@ int Map::getCell(int idx) {
}
}
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
}
if (pt.x & 16) {
@@ -1646,9 +1643,7 @@ int Map::getCell(int idx) {
}
}
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
}
assert(pt.x >= 0 && pt.x < 16 && pt.y >= 0 && pt.y < 16);
@@ -1690,9 +1685,7 @@ void Map::getNewMaze() {
int mapId = party._mazeId;
// Get the correct map to use from the cached list
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
// Adjust Y and X to be in the 0-15 range, and on the correct surrounding
// map if either value is < 0 or >= 16
@@ -1705,11 +1698,8 @@ void Map::getNewMaze() {
mapId = _mazeData[_mazeDataIndex]._surroundingMazes._south;
}
- if (mapId) {
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId == mapId)
- ++_mazeDataIndex;
- }
+ if (mapId)
+ findMap(mapId);
}
if (pt.x & 16) {
@@ -1721,11 +1711,8 @@ void Map::getNewMaze() {
mapId = _mazeData[_mazeDataIndex]._surroundingMazes._west;
}
- if (mapId) {
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId == mapId)
- ++_mazeDataIndex;
- }
+ if (mapId)
+ findMap(mapId);
}
// Save the adjusted (0,0)-(15,15) position and load the given map.
diff --git a/engines/xeen/map.h b/engines/xeen/map.h
index fe626858c8..b8b77c49ff 100644
--- a/engines/xeen/map.h
+++ b/engines/xeen/map.h
@@ -425,6 +425,12 @@ private:
* Save the map data
*/
void saveMap();
+
+ /**
+ * Finds a map in the array that contains the currently active and the surrounding
+ * maps in the eight cardinal directions
+ */
+ void findMap(int mapId = -1);
public:
Common::String _mazeName;
bool _isOutdoors;