aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/xeen/map.cpp')
-rw-r--r--engines/xeen/map.cpp106
1 files changed, 50 insertions, 56 deletions
diff --git a/engines/xeen/map.cpp b/engines/xeen/map.cpp
index 2b954f5afa..e16dcf5cb4 100644
--- a/engines/xeen/map.cpp
+++ b/engines/xeen/map.cpp
@@ -685,7 +685,7 @@ MazeMonster::MazeMonster() {
_isAttacking = false;
_damageType = DT_PHYSICAL;
_field9 = 0;
- _fieldA = 0;
+ _postAttackDelay = 0;
_hp = 0;
_effect1 = _effect2 = 0;
_effect3 = 0;
@@ -791,7 +791,7 @@ void MonsterObjectData::synchronize(XeenSerializer &s, MonsterData &monsterData)
} else {
// Load monster/obbject data and merge together with sprite Ids
- // Merge together object data
+ // Load objects
mobStruct.synchronize(s);
do {
MazeObject obj;
@@ -799,25 +799,35 @@ void MonsterObjectData::synchronize(XeenSerializer &s, MonsterData &monsterData)
obj._id = mobStruct._id;
obj._direction = mobStruct._direction;
obj._frame = 100;
- obj._spriteId = _objectSprites[obj._id]._spriteId;
- obj._sprites = &_objectSprites[obj._id]._sprites;
+
+ if (obj._id < (int)_objectSprites.size()) {
+ obj._spriteId = _objectSprites[obj._id]._spriteId;
+ obj._sprites = &_objectSprites[obj._id]._sprites;
+ } else {
+ assert(!obj._id);
+ }
_objects.push_back(obj);
mobStruct.synchronize(s);
} while (mobStruct._id != 255 || mobStruct._pos.x != -1);
- // Merge together monster data
+ // Load monsters
mobStruct.synchronize(s);
do {
MazeMonster mon;
mon._position = mobStruct._pos;
mon._id = mobStruct._id;
- mon._spriteId = _monsterSprites[mon._id]._spriteId;
- mon._sprites = &_monsterSprites[mon._id]._sprites;
- mon._attackSprites = &_monsterSprites[mon._id]._attackSprites;
- mon._monsterData = &monsterData[mon._spriteId];
mon._frame = _vm->getRandomNumber(7);
+ if (mon._id < (int)_monsterSprites.size()) {
+ mon._spriteId = _monsterSprites[mon._id]._spriteId;
+ mon._sprites = &_monsterSprites[mon._id]._sprites;
+ mon._attackSprites = &_monsterSprites[mon._id]._attackSprites;
+ mon._monsterData = &monsterData[mon._spriteId];
+ } else {
+ assert(!mon._id);
+ }
+
MonsterStruct &md = *mon._monsterData;
mon._hp = md._hp;
mon._effect1 = mon._effect2 = md._animationEffect;
@@ -828,7 +838,7 @@ void MonsterObjectData::synchronize(XeenSerializer &s, MonsterData &monsterData)
mobStruct.synchronize(s);
} while (mobStruct._id != 255 || mobStruct._pos.x != -1);
- // Merge together wall item data
+ // Load wall items
mobStruct.synchronize(s);
do {
if (mobStruct._id < (int)_wallItemSprites.size()) {
@@ -1093,9 +1103,6 @@ void Map::load(int mapId) {
_headData.synchronize(headFile);
headFile.close();
- if (!isDarkCc && party._mazeId)
- _mobData._monsters.clear();
-
if (!isDarkCc && mapId == 15) {
if ((_mobData._monsters[0]._position.x > 31 || _mobData._monsters[0]._position.y > 31) &&
(_mobData._monsters[1]._position.x > 31 || _mobData._monsters[1]._position.y > 31) &&
@@ -1198,7 +1205,7 @@ void Map::load(int mapId) {
if (_mazeData[0]._wallTypes[i] != 0) {
_wallSprites._surfaces[i].load(Common::String::format("%s.wal",
- Res.SURFACE_TYPE_NAMES[_mazeData[0]._wallTypes[i]]));
+ Res.OUTDOORS_WALL_TYPES[_mazeData[0]._wallTypes[i]]));
}
_surfaceSprites[i].clear();
@@ -1323,6 +1330,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 +1351,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 +1365,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 +1383,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 +1501,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 +1516,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 +1529,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 +1583,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 +1616,7 @@ int Map::getCell(int idx) {
}
}
- _mazeDataIndex = 0;
- while (_mazeData[_mazeDataIndex]._mazeId != mapId)
- ++_mazeDataIndex;
+ findMap(mapId);
}
if (pt.x & 16) {
@@ -1646,9 +1650,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 +1692,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 +1705,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 +1718,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.