From b9539c6cb168ecabda994353a453e050b380487f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 27 Feb 2015 20:52:59 -0500 Subject: XEEN: Fixes for marking grates as unlocked --- engines/xeen/interface.cpp | 2 ++ engines/xeen/map.cpp | 11 ++++--- engines/xeen/map.h | 2 +- engines/xeen/scripts.cpp | 79 ++++++++++++++++++++++++---------------------- engines/xeen/scripts.h | 2 +- 5 files changed, 52 insertions(+), 44 deletions(-) diff --git a/engines/xeen/interface.cpp b/engines/xeen/interface.cpp index ded3d9ca00..0354732b2b 100644 --- a/engines/xeen/interface.cpp +++ b/engines/xeen/interface.cpp @@ -299,12 +299,14 @@ void Interface::perform() { } case 6: + // Open grate being closed if (!map._isOutdoors) { scripts.openGrate(9, 0); eventsFlag = _buttonValue != 0; } break; case 9: + // Closed grate being opened if (!map._isOutdoors) { scripts.openGrate(6, 0); eventsFlag = _buttonValue != 0; diff --git a/engines/xeen/map.cpp b/engines/xeen/map.cpp index 2017978398..e5a5531cbf 100644 --- a/engines/xeen/map.cpp +++ b/engines/xeen/map.cpp @@ -891,7 +891,7 @@ Map::Map(XeenEngine *vm) : _vm(vm), _mobData(vm) { _currentSurfaceId = 0; _currentWall = 0; _currentTile = 0; - _currentIsGrate = false; + _currentGrateUnlocked = false; _currentCantRest = false; _currentIsDrain = false; _currentIsEvent = false; @@ -1383,7 +1383,7 @@ void Map::cellFlagLookup(const Common::Point &pt) { // Get the cell flags const MazeCell &cell = _mazeData[_mazeDataIndex]._cells[pos.y][pos.x]; - _currentIsGrate = cell._flags & OUTFLAG_GRATE; + _currentGrateUnlocked = cell._flags & OUTFLAG_GRATE; _currentCantRest = cell._flags & RESTRICTION_REST; _currentIsDrain = cell._flags & OUTFLAG_DRAIN; _currentIsEvent = cell._flags & FLAG_AUTOEXECUTE_EVENT; @@ -1393,14 +1393,17 @@ void Map::cellFlagLookup(const Common::Point &pt) { void Map::setCellSurfaceFlags(const Common::Point &pt, int bits) { mazeLookup(pt, 0); - _mazeData[0]._cells[pt.y][pt.x]._surfaceId |= bits; + + Common::Point mapPos(pt.x & 15, pt.y & 15); + _mazeData[_mazeDataIndex]._cells[mapPos.y][mapPos.x]._surfaceId |= bits; } void Map::setWall(const Common::Point &pt, Direction dir, int v) { const int XOR_MASKS[4] = { 0xFFF, 0xF0FF, 0xFF0F, 0xFFF0 }; mazeLookup(pt, 0, 0); - MazeWallLayers &wallLayer = _mazeData[0]._wallData[pt.y][pt.x]; + Common::Point mapPos(pt.x & 15, pt.y & 15); + MazeWallLayers &wallLayer = _mazeData[_mazeDataIndex]._wallData[mapPos.y][mapPos.x]; wallLayer._data &= XOR_MASKS[dir]; wallLayer._data |= v << WALL_SHIFTS[dir][2]; } diff --git a/engines/xeen/map.h b/engines/xeen/map.h index bd74837788..bfc09ec053 100644 --- a/engines/xeen/map.h +++ b/engines/xeen/map.h @@ -376,7 +376,7 @@ public: SpriteResource _tileSprites; SpriteResource _surfaceSprites[TOTAL_SURFACES]; WallSprites _wallSprites; - bool _currentIsGrate; + bool _currentGrateUnlocked; bool _currentCantRest; bool _currentIsDrain; bool _currentIsEvent; diff --git a/engines/xeen/scripts.cpp b/engines/xeen/scripts.cpp index f1bce0438c..4af7af1d6a 100644 --- a/engines/xeen/scripts.cpp +++ b/engines/xeen/scripts.cpp @@ -215,53 +215,56 @@ void Scripts::openGrate(int wallVal, int action) { SoundManager &sound = *_vm->_sound; bool isDarkCc = _vm->_files->_isDarkCc; - if ((wallVal != 13 || map._currentIsGrate) && (!isDarkCc || wallVal != 9 || + if ((wallVal != 13 || map._currentGrateUnlocked) && (!isDarkCc || wallVal != 9 || map.mazeData()._wallKind != 2)) { - if (wallVal != 9 && !map._currentIsGrate) { + if (wallVal != 9 && !map._currentGrateUnlocked) { int charIndex = WhoWill::show(_vm, 13, action, false) - 1; - if (charIndex >= 0) { - // There is a 1 in 4 chance the character will receive damage - if (_vm->getRandomNumber(1, 4) == 1) { - combat.giveCharDamage(map.mazeData()._trapDamage, - (DamageType)_vm->getRandomNumber(0, 6), charIndex); - } - - // Check whether character can unlock the door - Character &c = party._activeParty[charIndex]; - if ((c.getThievery() + _vm->getRandomNumber(1, 20)) < - map.mazeData()._difficulties._unlockDoor) - return; + if (charIndex < 0) { + intf.draw3d(true); + return; + } - c._experience += map.mazeData()._difficulties._unlockDoor * c.getCurrentLevel(); + // There is a 1 in 4 chance the character will receive damage + if (_vm->getRandomNumber(1, 4) == 1) { + combat.giveCharDamage(map.mazeData()._trapDamage, + (DamageType)_vm->getRandomNumber(0, 6), charIndex); } - // Set the wall state for the wall party is facing - map.setCellSurfaceFlags(party._mazePosition, 0x80); - map.setWall(party._mazePosition, party._mazeDirection, wallVal); + // Check whether character can unlock the door + Character &c = party._activeParty[charIndex]; + if ((c.getThievery() + _vm->getRandomNumber(1, 20)) < + map.mazeData()._difficulties._unlockDoor) + return; - // Set the wall state for the reverse wall in the next cell over - Common::Point pt = party._mazePosition; - Direction dir = (Direction)((int)party._mazeDirection ^ 2); - switch (party._mazeDirection) { - case DIR_NORTH: - pt.y++; - break; - case DIR_EAST: - pt.x++; - break; - case DIR_SOUTH: - pt.y--; - break; - case DIR_WEST: - pt.x--; - break; - } + c._experience += map.mazeData()._difficulties._unlockDoor * c.getCurrentLevel(); + } + + // Flag the grate as unlocked, and the wall the grate is on + map.setCellSurfaceFlags(party._mazePosition, 0x80); + map.setWall(party._mazePosition, party._mazeDirection, wallVal); - map.setCellSurfaceFlags(pt, 0x80); - map.setWall(pt, dir, wallVal); - sound.playFX(10); + // Set the grate as opened and the wall on the other side of the grate + Common::Point pt = party._mazePosition; + Direction dir = (Direction)((int)party._mazeDirection ^ 2); + switch (party._mazeDirection) { + case DIR_NORTH: + pt.y++; + break; + case DIR_EAST: + pt.x++; + break; + case DIR_SOUTH: + pt.y--; + break; + case DIR_WEST: + pt.x--; + break; } + map.setCellSurfaceFlags(pt, 0x80); + map.setWall(pt, dir, wallVal); + + sound.playFX(10); intf.draw3d(true); } } diff --git a/engines/xeen/scripts.h b/engines/xeen/scripts.h index d347ec07bf..3a835d88b5 100644 --- a/engines/xeen/scripts.h +++ b/engines/xeen/scripts.h @@ -233,7 +233,7 @@ public: int checkEvents(); - void openGrate(int v1, int action); + void openGrate(int wallVal, int action); }; } // End of namespace Xeen -- cgit v1.2.3