diff options
-rw-r--r-- | engines/access/access.cpp | 18 | ||||
-rw-r--r-- | engines/access/access.h | 11 | ||||
-rw-r--r-- | engines/access/amazon/amazon_game.cpp | 389 | ||||
-rw-r--r-- | engines/access/amazon/amazon_game.h | 78 | ||||
-rw-r--r-- | engines/access/amazon/amazon_logic.cpp | 1832 | ||||
-rw-r--r-- | engines/access/amazon/amazon_logic.h | 228 | ||||
-rw-r--r-- | engines/access/amazon/amazon_player.cpp | 2 | ||||
-rw-r--r-- | engines/access/amazon/amazon_resources.cpp | 62 | ||||
-rw-r--r-- | engines/access/amazon/amazon_resources.h | 6 | ||||
-rw-r--r-- | engines/access/amazon/amazon_room.cpp | 3 | ||||
-rw-r--r-- | engines/access/amazon/amazon_scripts.cpp | 1514 | ||||
-rw-r--r-- | engines/access/amazon/amazon_scripts.h | 59 | ||||
-rw-r--r-- | engines/access/martian/martian_game.h | 2 | ||||
-rw-r--r-- | engines/access/module.mk | 1 | ||||
-rw-r--r-- | engines/access/player.cpp | 2 | ||||
-rw-r--r-- | engines/access/scripts.cpp | 69 | ||||
-rw-r--r-- | engines/access/scripts.h | 11 |
17 files changed, 2236 insertions, 2051 deletions
diff --git a/engines/access/access.cpp b/engines/access/access.cpp index 885b2f998c..1ab40a2de7 100644 --- a/engines/access/access.cpp +++ b/engines/access/access.cpp @@ -92,15 +92,6 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc) _helpTbl[2] = _help3; _travel = 0; _ask = 0; - _rScrollRow = 0; - _rScrollCol = 0; - _rScrollX = 0; - _rScrollY = 0; - _rOldRectCount = 0; - _rNewRectCount = 0; - _rKeyFlag = 0; - _mapOffset = 0; - _screenVirtX = 0; _lastTime = g_system->getMillis(); _curTime = 0; _narateFile = 0; @@ -524,15 +515,6 @@ void AccessEngine::synchronize(Common::Serializer &s) { s.syncAsUint16LE(_travel); s.syncAsUint16LE(_ask); - s.syncAsUint16LE(_rScrollRow); - s.syncAsUint16LE(_rScrollCol); - s.syncAsSint16LE(_rScrollX); - s.syncAsSint16LE(_rScrollY); - s.syncAsUint16LE(_rOldRectCount); - s.syncAsUint16LE(_rNewRectCount); - s.syncAsUint16LE(_rKeyFlag); - s.syncAsUint16LE(_mapOffset); - s.syncAsUint16LE(_screenVirtX); for (int i = 0; i < 100; ++i) s.syncAsByte(_establishTable[i]); diff --git a/engines/access/access.h b/engines/access/access.h index c0bc467f08..0942c9eb8e 100644 --- a/engines/access/access.h +++ b/engines/access/access.h @@ -213,15 +213,6 @@ public: byte *_helpTbl[3]; int _travel; int _ask; - int _rScrollRow; - int _rScrollCol; - int _rScrollX; - int _rScrollY; - int _rOldRectCount; - int _rNewRectCount; - int _rKeyFlag; - int _mapOffset; - int _screenVirtX; bool _clearSummaryFlag; @@ -234,6 +225,8 @@ public: AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc); virtual ~AccessEngine(); + virtual void dead(int deathId) = 0; + uint32 getFeatures() const; bool isCD() const; Common::Language getLanguage() const; diff --git a/engines/access/amazon/amazon_game.cpp b/engines/access/amazon/amazon_game.cpp index 4237982b4d..55876b5692 100644 --- a/engines/access/amazon/amazon_game.cpp +++ b/engines/access/amazon/amazon_game.cpp @@ -36,38 +36,22 @@ AccessEngine(syst, gameDesc), _jasMayaFlag(_flags[168]), _moreHelp(_flags[169]), _flashbackFlag(_flags[171]), _riverFlag(_flags[185]), _aniOutFlag(_flags[195]), _badEnd(_flags[218]), _noHints(_flags[219]), _aniFlag(_flags[229]), _allenFlag(_flags[237]), - _noSound(_flags[239]) { + _noSound(_flags[239]), + _ant(this), _cast(this), _guard(this), _jungle(this), _opening(this), + _plane(this), _river(this) { _skipStart = false; _charSegSwitch = false; - _canoeLane = 0; - _canoeYPos = 0; - _hitCount = 0; _saveRiver = false; - _hitSafe = 0; _oldTitleChapter = _chapter = 0; _updateChapter = -1; - _topList = nullptr; - _botList = nullptr; - _riverIndex = 0; _rawInactiveX = 0; _rawInactiveY = 0; _inactiveYOff = 0; _tilePos = Common::Point(0, 0); _hintLevel = 0; - _antDirection = NONE; - _pitDirection = NONE; - _antCel = 0; - _torchCel = 0; - _pitCel = 0; - _stabCel = 0; - _antPos = Common::Point(0, 0); - _antDieFl = _antEatFl = false; - _stabFl = false; - _pitPos = Common::Point(0, 0); - Common::fill(&_esTabTable[0], &_esTabTable[100], 0); memset(_tileData, 0, sizeof(_tileData)); @@ -96,7 +80,6 @@ void AmazonEngine::playGame() { // Initialize Amazon game-specific objects _room = new AmazonRoom(this); _scripts = new AmazonScripts(this); - _guard.setVm(this); // Setup the game setupGame(); @@ -140,7 +123,7 @@ void AmazonEngine::doIntroduction() { return; _screen->setPanel(3); - ((AmazonScripts *)_scripts)->mWhileDoOpen(); + _opening.mWhileDoOpen(); if (shouldQuit() || _skipStart) return; @@ -916,315 +899,89 @@ void AmazonEngine::startChapter(int chapter) { } } -void AmazonEngine::synchronize(Common::Serializer &s) { - AccessEngine::synchronize(s); - - int dummy = 0; - - s.syncAsSint16LE(_canoeLane); - s.syncAsSint16LE(_canoeYPos); - s.syncAsSint16LE(_hitCount); - s.syncAsSint16LE(_saveRiver); - s.syncAsSint16LE(_hitSafe); - s.syncAsSint16LE(_chapter); - s.syncAsSint16LE(dummy); - s.syncAsSint16LE(dummy); - s.syncAsSint16LE(_riverIndex); - s.syncAsSint16LE(_rawInactiveX); - s.syncAsSint16LE(_rawInactiveY); - s.syncAsSint16LE(_inactiveYOff); - for (int i = 0; i < 100; ++i) - s.syncAsSint16LE(_esTabTable[i]); - - if (_player->_roomNumber == 45) { - - - warning("TODO: s.syncAsSint16LE(_topList);"); - warning("TODO: s.syncAsSint16LE(_botList);"); - } -} - -/*------------------------------------------------------------------------*/ - -Plane::Plane() { - _pCount = 0; - _planeCount = 0; - _propCount = 0; - _xCount = 0; -} - -/*------------------------------------------------------------------------*/ - -Guard::Guard() { - _vm = nullptr; - _guardCel = 0; - _gCode1 = _gCode2 = 0; - _xMid = _yMid = 0; -} -void Guard::setVerticalCode() { - _gCode1 = 0; - _gCode2 = 0; - if (_topLeft.x < _vm->_screen->_orgX1) - _gCode1 |= 8; - else if (_topLeft.x == _vm->_screen->_orgX1) { - _gCode1 |= 8; - _gCode1 |= 2; - } - else - _gCode1 |= 2; - - if (_bottomRight.x < _vm->_screen->_orgX1) - _gCode2 |= 8; - else if (_bottomRight.x == _vm->_screen->_orgX1) { - _gCode2 |= 8; - _gCode2 |= 2; - } - else - _gCode2 |= 2; - - if (_topLeft.y < _vm->_screen->_orgY1) - _gCode1 |= 4; - else if (_topLeft.y > _vm->_screen->_orgY2) - _gCode1 |= 1; - - if (_bottomRight.y < _vm->_screen->_orgY1) - _gCode2 |= 4; - else if (_bottomRight.y > _vm->_screen->_orgY2) - _gCode2 |= 1; -} - -void Guard::setHorizontalCode() { - _gCode1 = 0; - _gCode2 = 0; - - if (_topLeft.y < _vm->_screen->_orgY1) - _gCode1 |= 4; - else if (_topLeft.x == _vm->_screen->_orgX1) { - _gCode1 |= 4; - _gCode1 |= 1; - } - else - _gCode1 |= 1; - - if (_bottomRight.y < _vm->_screen->_orgY1) - _gCode2 |= 4; - else if (_bottomRight.x == _vm->_screen->_orgX1) { - _gCode2 |= 4; - _gCode2 |= 1; - } - else - _gCode2 |= 1; - - if (_topLeft.x < _vm->_screen->_orgX1) - _gCode1 |= 8; - else if (_topLeft.x > _vm->_screen->_orgX2) - _gCode1 |= 2; - - if (_bottomRight.x < _vm->_screen->_orgX1) - _gCode2 |= 8; - else if (_bottomRight.y > _vm->_screen->_orgX2) - _gCode2 |= 2; -} +void AmazonEngine::dead(int deathId) { + _events->hideCursor(); + _screen->forceFadeOut(); + _scripts->cmdFreeSound(); -void Guard::chkVLine() { - if (_position.x > _vm->_player->_rawPlayer.x) { - _topLeft = _vm->_player->_rawPlayer; - _bottomRight = _position; - } else { - _topLeft = _position; - _bottomRight = _vm->_player->_rawPlayer; - } + _sound->_soundTable.push_back(SoundEntry(_files->loadFile(98, 44), 1)); - if (_vm->_screen->_orgY1 > _vm->_screen->_orgY2) - SWAP(_vm->_screen->_orgY1, _vm->_screen->_orgY2); + _screen->clearScreen(); + _screen->setPanel(3); - for (;;) { - setVerticalCode(); - int code = _gCode1 | _gCode2; - if (code == 10) { - _vm->_guardFind = 0; - return; + if (deathId != 10) { + _sound->newMusic(62, 0); + _files->_setPaletteFlag = false; + _files->loadScreen(94, 0); + _files->_setPaletteFlag = true; + _buffer2.copyFrom(*_screen); + + for (int i = 0; i < 3; ++i) { + _sound->playSound(0); + _screen->forceFadeIn(); + _sound->playSound(0); + _screen->forceFadeOut(); } + freeCells(); + + // Load the cell list for the death screen + DeathEntry &de = _deaths[deathId]; + Common::Array<CellIdent> cells; + cells.push_back(_deaths._cells[de._screenId]); + loadCells(cells); + + _screen->setDisplayScan(); + _files->_setPaletteFlag = false; + _files->loadScreen(&_buffer2, 94, 1); + _screen->setIconPalette(); + + _buffer2.plotImage(_objectsTable[0], 0, Common::Point(105, 25)); + _buffer2.copyTo(_screen); + _screen->forceFadeIn(); + + _fonts._charSet._hi = 10; + _fonts._charSet._lo = 1; + _fonts._charFor._lo = 55; + _fonts._charFor._hi = 255; + _screen->_maxChars = 46; + _screen->_printOrg = Common::Point(20, 155); + _screen->_printStart = Common::Point(20, 155); + + Common::String &msg = de._msg; + _printEnd = 180; + printText(_screen, msg); + _screen->forceFadeOut(); - int code2 = _gCode1 & _gCode2; - code2 &= 5; - if (((code & 10) == 8) || ((code & 10) == 2) || (code2 != 0)) - return; - - int midX = (_topLeft.x + _bottomRight.x) / 2; - int midY = (_topLeft.y + _bottomRight.y) / 2; - - if (midX < _vm->_screen->_orgX1) { - if ((midX == _topLeft.x) && (midY == _topLeft.y)) - return; - - _topLeft.x = midX; - _topLeft.y = midY; - } else { - if ((midX == _bottomRight.x) && (midY == _bottomRight.y)) - return; - - _bottomRight.x = midX; - _bottomRight.y = midY; - } - } -} + _sound->newMusic(0, 1); + _events->showCursor(); + _room->clearRoom(); + freeChar(); -void Guard::chkHLine() { - if (_position.y > _vm->_player->_rawPlayer.y) { - _topLeft = _vm->_player->_rawPlayer; - _bottomRight = _position; + warning("TODO: restart game"); + quitGame(); + _events->pollEvents(); } else { - _topLeft = _position; - _bottomRight = _vm->_player->_rawPlayer; - } - - if (_vm->_screen->_orgX1 > _vm->_screen->_orgX2) - SWAP(_vm->_screen->_orgX1, _vm->_screen->_orgX2); - - while (true) { - setHorizontalCode(); - int code = _gCode1 | _gCode2; - if (code == 5) { - _vm->_guardFind = 0; - return; - } - - int code2 = _gCode1 & _gCode2; - code2 &= 10; - if (((code & 5) == 4) || ((code & 5) == 1) || (code2 != 0)) - return; - - int midX = (_topLeft.x + _bottomRight.x) / 2; - int midY = (_topLeft.y + _bottomRight.y) / 2; - - if (midY < _vm->_screen->_orgY1) { - if ((midX == _topLeft.x) && (midY == _topLeft.y)) - return; - - _topLeft.x = midX; - _topLeft.y = midY; - } else { - if ((midX == _bottomRight.x) && (midY == _bottomRight.y)) - return; - - _bottomRight.x = midX; - _bottomRight.y = midY; - } - } -} - -void Guard::guardSee() { - int tmpY = (_vm->_screen->_scrollRow << 4) + _vm->_screen->_scrollY; - _vm->_flags[140] = 0; - if (tmpY > _position.y) - return; - - tmpY += _vm->_screen->_vWindowLinesTall; - tmpY -= 11; - - if (tmpY < _position.y) - return; - - _vm->_guardFind = 1; - _vm->_flags[140] = 1; - - for (uint16 idx = 0; idx < _vm->_room->_plotter._walls.size(); idx++) { - _vm->_screen->_orgX1 = _vm->_room->_plotter._walls[idx].left; - _vm->_screen->_orgY1 = _vm->_room->_plotter._walls[idx].top; - _vm->_screen->_orgX2 = _vm->_room->_plotter._walls[idx].right; - _vm->_screen->_orgY2 = _vm->_room->_plotter._walls[idx].bottom; - if (_vm->_screen->_orgX1 == _vm->_screen->_orgX2) { - chkVLine(); - if (_vm->_guardFind == 0) - return; - } - else if (_vm->_screen->_orgY1 == _vm->_screen->_orgY2) { - chkHLine(); - if (_vm->_guardFind == 0) - return; - } + quitGame(); + _events->pollEvents(); } } -void Guard::setGuardFrame() { - ImageEntry ie; - ie._flags = IMGFLAG_UNSCALED; - - if (_vm->_guardLocation == 4) - ie._flags |= IMGFLAG_BACKWARDS; - ie._spritesPtr = _vm->_objectsTable[37]; - ie._frameNumber = _guardCel; - ie._position = _position; - ie._offsetY = 10; - _vm->_images.addToList(ie); -} +void AmazonEngine::synchronize(Common::Serializer &s) { + AccessEngine::synchronize(s); -void Guard::guard() { - if (_vm->_timers[8]._flag) { - setGuardFrame(); - return; - } + int dummy = 0; - ++_vm->_timers[8]._flag; - ++_guardCel; - int curCel = _guardCel; - - switch (_vm->_guardLocation) { - case 1: - // Guard walking down - if (curCel <= 8 || curCel > 13) - _guardCel = curCel = 8; - - _position.y += _vm->_player->_walkOffDown[curCel - 8]; - guardSee(); - if (_position.y >= 272) { - _position.y = 272; - _vm->_guardLocation = 2; - } - break; - case 2: - // Guard walking left - if (curCel <= 43 || curCel > 48) - _guardCel = curCel = 43; - - _position.x -= _vm->_player->_walkOffLeft[curCel - 43]; - guardSee(); - if (_position.x <= 56) { - _position.x = 56; - _vm->_guardLocation = 3; - } - break; - case 3: - // Guard walking up - if (curCel <= 0 || curCel > 5) - _guardCel = curCel = 0; - - _position.y -= _vm->_player->_walkOffUp[curCel]; - guardSee(); - if (_position.y <= 89) { - _position.y = 89; - _vm->_guardLocation = 4; - if (_vm->_flags[121] == 1) - _vm->_guardLocation = 5; - } - break; - default: - // Guard walking right - if (curCel <= 43 || curCel > 48) - _guardCel = curCel = 43; - - _position.x += _vm->_player->_walkOffRight[curCel - 43]; - guardSee(); - if (_position.x >= 127) { - _position.x = 127; - _vm->_guardLocation = 1; - } - break; - } + s.syncAsSint16LE(_chapter); + s.syncAsSint16LE(dummy); + s.syncAsSint16LE(dummy); + s.syncAsSint16LE(_rawInactiveX); + s.syncAsSint16LE(_rawInactiveY); + s.syncAsSint16LE(_inactiveYOff); + for (int i = 0; i < 100; ++i) + s.syncAsSint16LE(_esTabTable[i]); - setGuardFrame(); + _river.synchronize(s); } } // End of namespace Amazon diff --git a/engines/access/amazon/amazon_game.h b/engines/access/amazon/amazon_game.h index 4c4b304514..b09c96d263 100644 --- a/engines/access/amazon/amazon_game.h +++ b/engines/access/amazon/amazon_game.h @@ -24,53 +24,13 @@ #define ACCESS_AMAZON_GAME_H #include "access/access.h" +#include "access/amazon/amazon_logic.h" namespace Access { namespace Amazon { - class AmazonEngine; - -class Plane { -public: - int _pCount; - Common::Point _position; - int _planeCount; - int _propCount; - int _xCount; -public: - Plane(); -}; - -class Guard { -private: - AmazonEngine *_vm; - - void chkVLine(); - void chkHLine(); - void setVerticalCode(); - void setHorizontalCode(); - void guardSee(); - void setGuardFrame(); -public: - int _guardCel; - Common::Point _position; - int _gCode1; - int _gCode2; - Common::Point _topLeft; - Common::Point _bottomRight; - int _xMid, _yMid; -public: - Guard(); - void setVm(AmazonEngine *vm) { _vm = vm; } - - void guard(); -}; - -class InactivePlayer : public ImageEntry { -public: - SpriteResource *_altSpritesPtr; -}; +class AmazonEngine; class AmazonEngine : public AccessEngine { private: @@ -126,10 +86,7 @@ public: InactivePlayer _inactive; bool _charSegSwitch; bool _skipStart; - - RiverStruct *_topList; - RiverStruct *_botList; - int _canoeDir; + bool _saveRiver; // Fields that are mapped to flags int &_guardLocation; @@ -147,21 +104,20 @@ public: int &_noSound; // Saved fields - int _canoeLane; - int _canoeYPos; - int _hitCount; - bool _saveRiver; - int _hitSafe; int _chapter; - int _riverIndex; int _rawInactiveX; int _rawInactiveY; int _inactiveYOff; int _esTabTable[100]; // Other game specific fields + Ant _ant; + Cast _cast; Guard _guard; + Jungle _jungle; + Opening _opening; Plane _plane; + River _river; int _hintLevel; int _updateChapter; int _oldTitleChapter; @@ -170,28 +126,14 @@ public: bool _deathFlag; int _deathCount; int _deathType; - const byte *_mapPtr; - int _canoeVXPos; - int _canoeMoveCount; - int _canoeFrame; - - Direction _antDirection; - Direction _pitDirection; - int _antCel; - int _torchCel; - int _pitCel; - int _stabCel; - Common::Point _antPos; - bool _antDieFl; - bool _antEatFl; - bool _stabFl; - Common::Point _pitPos; int _iqValue; public: AmazonEngine(OSystem *syst, const AccessGameDescription *gameDesc); virtual ~AmazonEngine(); + virtual void dead(int deathId); + /** * Free the inactive player data */ diff --git a/engines/access/amazon/amazon_logic.cpp b/engines/access/amazon/amazon_logic.cpp new file mode 100644 index 0000000000..cae3373ea8 --- /dev/null +++ b/engines/access/amazon/amazon_logic.cpp @@ -0,0 +1,1832 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" +#include "access/access.h" +#include "access/resources.h" +#include "access/screen.h" +#include "access/amazon/amazon_game.h" +#include "access/amazon/amazon_logic.h" + +namespace Access { + +namespace Amazon { + +PannedScene::PannedScene(AmazonEngine *vm): AmazonManager(vm) { + for (int i = 0; i < PAN_SIZE; ++i) { + _pan[i]._pObject = nullptr; + _pan[i]._pImgNum = 0; + _pan[i]._pObjX = _pan[i]._pObjY = _pan[i]._pObjZ = 0; + _pan[i]._pObjXl = _pan[i]._pObjYl = 0; + } + + _xCount = 0; + _xTrack = _yTrack = _zTrack = 0; + _xCam = _yCam = _zCam = 0; + _pNumObj = 0; + _screenVertX = 0; +} + +void PannedScene::pan() { + _zCam += _zTrack; + _xCam += _xTrack; + int tx = (_xTrack << 8) / _zCam; + _yCam += _yTrack; + int ty = (_yTrack << 8) / _zCam; + + if (_vm->_timers[24]._flag != 1) { + ++_vm->_timers[24]._flag; + for (int i = 0; i < _pNumObj; i++) { + _pan[i]._pObjZ += _zTrack; + _pan[i]._pObjXl += (_pan[i]._pObjZ * tx) & 0xff; + _pan[i]._pObjX += ((_pan[i]._pObjZ * tx) >> 8) + (_pan[i]._pObjXl >> 8); + _pan[i]._pObjXl &= 0xff; + + _pan[i]._pObjYl += (_pan[i]._pObjZ * ty) & 0xff; + _pan[i]._pObjY += ((_pan[i]._pObjZ * ty) >> 8) + (_pan[i]._pObjYl >> 8); + _pan[i]._pObjYl &= 0xff; + } + } + + for (int i = 0; i < _pNumObj; i++) { + ImageEntry ie; + ie._flags = IMGFLAG_UNSCALED; + ie._position = Common::Point(_pan[i]._pObjX, _pan[i]._pObjY); + ie._offsetY = 255; + ie._spritesPtr = _pan[i]._pObject; + ie._frameNumber = _pan[i]._pImgNum; + + _vm->_images.addToList(ie); + } +} + +/*------------------------------------------------------------------------*/ + +Opening::Opening(AmazonEngine *vm) : PannedScene(vm) { +} + +void Opening::mWhileDoOpen() { + Screen &screen = *_vm->_screen; + EventsManager &events = *_vm->_events; + + screen.setBufferScan(); + events.hideCursor(); + screen.forceFadeOut(); + _vm->_skipStart = false; + if (_vm->_conversation != 2) { + // Cutscene at start of chapter 1 + screen.setPanel(3); + _vm->startChapter(1); + _vm->establishCenter(0, 1); + } + + Resource *data = _vm->_files->loadFile(1, 0); + _vm->_objectsTable[1] = new SpriteResource(_vm, data); + delete data; + + _vm->_files->_setPaletteFlag = false; + _vm->_files->loadScreen(1, 2); + _vm->_buffer2.copyFrom(*_vm->_screen); + _vm->_buffer1.copyFrom(*_vm->_screen); + + // Load animation data + _vm->_animation->freeAnimationData(); + Resource *animResource = _vm->_files->loadFile(1, 1); + _vm->_animation->loadAnimations(animResource); + delete animResource; + + _xTrack = 8; + _yTrack = -3; + _zTrack = 0; + _xCam = _yCam = 0; + _zCam = 270; + _vm->_timers[24]._timer = _vm->_timers[24]._initTm = 1; + ++_vm->_timers[24]._flag; + _vm->_timers.updateTimers(); + + _pNumObj = 10; + for (int i = 0; i < _pNumObj; i++) { + _pan[i]._pObject = _vm->_objectsTable[1]; + _pan[i]._pImgNum = OPENING_OBJS[i][0]; + _pan[i]._pObjX = OPENING_OBJS[i][1]; + _pan[i]._pObjY = OPENING_OBJS[i][2]; + _pan[i]._pObjZ = OPENING_OBJS[i][3]; + _pan[i]._pObjXl = _pan[i]._pObjYl = 0; + } + + _vm->_oldRects.clear(); + _vm->_newRects.clear(); + Animation *anim = _vm->_animation->setAnimation(0); + _vm->_animation->setAnimTimer(anim); + anim = _vm->_animation->setAnimation(1); + _vm->_animation->setAnimTimer(anim); + _vm->_sound->newMusic(10, 0); + + bool startFl = false; + while (!_vm->shouldQuit()) { + _vm->_images.clear(); + _vm->_animation->animate(0); + _vm->_animation->animate(1); + pan(); + _vm->_buffer2.copyFrom(_vm->_buffer1); + _vm->_newRects.clear(); + _vm->plotList(); + _vm->copyBlocks(); + if (!startFl) { + startFl = true; + screen.forceFadeIn(); + } + + events.pollEventsAndWait(); + + if (events._leftButton || events._rightButton || events._keypresses.size() > 0) { + _vm->_skipStart = true; + _vm->_sound->newMusic(10, 1); + + events.debounceLeft(); + events.zeroKeys(); + break; + } + + if (_xCam > 680) { + events._vbCount = 125; + + while (!_vm->shouldQuit() && !events.isKeyMousePressed() && events._vbCount > 0) { + events.pollEventsAndWait(); + } + break; + } + } + + events.showCursor(); + _vm->_buffer2.copyFrom(*_vm->_screen); + _vm->_buffer1.copyFrom(*_vm->_screen); + + _vm->freeCells(); + _vm->_oldRects.clear(); + _vm->_newRects.clear(); + _vm->_numAnimTimers = 0; + _vm->_images.clear(); + + if (_vm->_conversation == 2) { + // Cutscene at end of Chapter 6 + Resource *spriteData = _vm->_files->loadFile(28, 37); + _vm->_objectsTable[28] = new SpriteResource(_vm, spriteData); + delete spriteData; + + _vm->_animation->freeAnimationData(); + animResource = _vm->_files->loadFile(28, 38); + _vm->_animation->loadAnimations(animResource); + delete animResource; + } +} + +/*------------------------------------------------------------------------*/ + +Plane::Plane(AmazonEngine *vm): PannedScene(vm) { + _pCount = 0; + _planeCount = 0; + _propCount = 0; +} + + +void Plane::doFlyCell() { + SpriteResource *sprites = _vm->_objectsTable[15]; + + if (_pCount <= 40) { + _vm->_buffer2.plotImage(sprites, 3, Common::Point(70, 74)); + } else if (_pCount <= 80) { + _vm->_buffer2.plotImage(sprites, 6, Common::Point(70, 74)); + } else if (_pCount <= 120) { + _vm->_buffer2.plotImage(sprites, 2, Common::Point(50, 76)); + } else if (_pCount <= 160) { + _vm->_buffer2.plotImage(sprites, 14, Common::Point(63, 78)); + } else if (_pCount <= 200) { + _vm->_buffer2.plotImage(sprites, 5, Common::Point(86, 74)); + } else if (_pCount <= 240) { + _vm->_buffer2.plotImage(sprites, 0, Common::Point(103, 76)); + } else if (_pCount <= 280) { + _vm->_buffer2.plotImage(sprites, 4, Common::Point(119, 77)); + } else { + _vm->_buffer2.plotImage(sprites, 1, Common::Point(111, 77)); + } + + if (_planeCount == 11 || _planeCount == 12) + ++_position.y; + else if (_planeCount >= 28) + --_position.y; + + _vm->_buffer2.plotImage(sprites, 7, _position); + _vm->_buffer2.plotImage(sprites, 8 + _propCount, Common::Point( + _position.x + 99, _position.y + 10)); + _vm->_buffer2.plotImage(sprites, 11 + _propCount, Common::Point( + _position.x + 104, _position.y + 18)); + + if (++_planeCount >= 30) + _planeCount = 0; + if (++_propCount >= 3) + _propCount = 0; + + ++_xCount; + if (_xCount == 1) + ++_position.x; + else + _xCount = 0; +} + +void Plane::doFallCell() { + if (_vm->_scaleI <= 20) + return; + + SpriteFrame *frame = _vm->_objectsTable[20]->getFrame(_planeCount / 6); + Common::Rect r(115, 11, 115 + _vm->_screen->_scaleTable1[frame->w], + 11 + _vm->_screen->_scaleTable1[frame->h]); + _vm->_buffer2.sPlotF(frame, r); + + _vm->_scaleI -= 3; + _vm->_scale = _vm->_scaleI; + _vm->_screen->setScaleTable(_vm->_scale); + ++_xCount; + if (_xCount == 5) + return; + _xCount = 0; + if (_planeCount == 18) + _planeCount = 0; + else + _planeCount += 6; +} + +void Plane::scrollFly() { + _vm->copyBF1BF2(); + _vm->_newRects.clear(); + doFlyCell(); + _vm->copyRects(); + _vm->copyBF2Vid(); +} + +void Plane::scrollFall() { + _vm->copyBF1BF2(); + _vm->_newRects.clear(); + doFallCell(); + _vm->copyRects(); + _vm->copyBF2Vid(); +} + +void Plane::mWhileFly() { + Screen &screen = *_vm->_screen; + Player &player = *_vm->_player; + EventsManager &events = *_vm->_events; + + events.hideCursor(); + screen.clearScreen(); + screen.setBufferScan(); + screen.fadeOut(); + screen._scrollX = 0; + + _vm->_room->buildScreen(); + _vm->copyBF2Vid(); + screen.fadeIn(); + _vm->_oldRects.clear(); + _vm->_newRects.clear(); + + // KEYFLG = 0; + + screen._scrollRow = screen._scrollCol = 0; + screen._scrollX = screen._scrollY = 0; + player._rawPlayer = Common::Point(0, 0); + player._scrollAmount = 1; + + _pCount = 0; + _planeCount = 0; + _propCount = 0; + _xCount = 0; + _position = Common::Point(20, 29); + + while (!_vm->shouldQuit() && !events.isKeyMousePressed() && + ((screen._scrollCol + screen._vWindowWidth) != _vm->_room->_playFieldWidth)) { + events._vbCount = 4; + screen._scrollX += player._scrollAmount; + + while (screen._scrollX >= TILE_WIDTH) { + screen._scrollX -= TILE_WIDTH; + ++screen._scrollCol; + + _vm->_buffer1.moveBufferLeft(); + _vm->_room->buildColumn(screen._scrollCol + screen._vWindowWidth, screen._vWindowBytesWide); + } + + scrollFly(); + ++_pCount; + + while (!_vm->shouldQuit() && events._vbCount > 0) { + // To be rewritten when NEWTIMER is done + events.checkForNextFrameCounter(); + _vm->_sound->playSound(0); + + events.pollEventsAndWait(); + } + } + + events.showCursor(); +} + +void Plane::mWhileFall() { + Screen &screen = *_vm->_screen; + EventsManager &events = *_vm->_events; + + events.hideCursor(); + screen.clearScreen(); + screen.setBufferScan(); + screen.fadeOut(); + screen._scrollX = 0; + + _vm->_room->buildScreen(); + _vm->copyBF2Vid(); + screen.fadeIn(); + _vm->_oldRects.clear(); + _vm->_newRects.clear(); + + // KEYFLG = 0; + + screen._scrollRow = screen._scrollCol = 0; + screen._scrollX = screen._scrollY = 0; + _vm->_player->_scrollAmount = 3; + _vm->_scaleI = 255; + + _xCount = 0; + _planeCount = 0; + + while (!_vm->shouldQuit() && !events.isKeyMousePressed() && + (screen._scrollCol + screen._vWindowWidth != _vm->_room->_playFieldWidth)) { + events._vbCount = 4; + screen._scrollX += _vm->_player->_scrollAmount; + + while (screen._scrollX >= TILE_WIDTH) { + screen._scrollX -= TILE_WIDTH; + ++screen._scrollCol; + + _vm->_buffer1.moveBufferLeft(); + _vm->_room->buildColumn(screen._scrollCol + screen._vWindowWidth, screen._vWindowBytesWide); + } + + scrollFall(); + + while (!_vm->shouldQuit() && events._vbCount > 0) { + events.pollEventsAndWait(); + } + } + + events.showCursor(); +} + +/*------------------------------------------------------------------------*/ + +Jungle::Jungle(AmazonEngine *vm) : PannedScene(vm) { + for (int i = 0; i < JUNGLE_SIZE; ++i) { + _jCnt[i] = _jungleX[i] = -1; + } +} + +void Jungle::jungleMove() { + const static int jungleY[3] = { 27, 30, 29 }; + int count = 1; + int frameOffset = 0; + + if (!_vm->_timers[0]._flag) { + ++_vm->_timers[0]._flag; + _vm->_screen->_scrollX += _vm->_player->_scrollAmount; + + for (int i = 0; i < 3; ++i) { + int newJCnt = (_jCnt[i] + 1) % 8; + _jCnt[i] = newJCnt; + _jungleX[i] += 5; + } + + frameOffset = 4; + count = (_vm->_allenFlag != 1) ? 2 : 3; + } + + for (int i = 0; i < count; ++i) { + ImageEntry ie; + ie._flags = IMGFLAG_UNSCALED; + ie._spritesPtr = _vm->_objectsTable[24]; + ie._frameNumber = _jCnt[i] + frameOffset; + ie._position = Common::Point(_jungleX[i], jungleY[i]); + ie._offsetY = jungleY[i]; + + _vm->_images.addToList(ie); + frameOffset += 8; + } +} + +void Jungle::initJWalk2() { + const int JUNGLE1OBJ[7][4] = { + { 2, 470, 0, 20 }, + { 0, 290, 0, 50 }, + { 1, 210, 0, 40 }, + { 0, 500, 0, 30 }, + { 1, 550, 0, 20 }, + { 0, 580, 0, 60 }, + { 1, 650, 0, 30 } + }; + _vm->_screen->fadeOut(); + _vm->_events->hideCursor(); + _vm->_screen->clearScreen(); + _vm->_buffer2.clearBuffer(); + _vm->_screen->setBufferScan(); + + _vm->_screen->_scrollX = _vm->_screen->_scrollY; + _vm->_screen->_scrollCol = _vm->_screen->_scrollRow; + _vm->_room->buildScreen(); + _vm->copyBF2Vid(); + _vm->_screen->fadeIn(); + // KEYFL = 0; + + _xCount = 2; + _vm->_player->_scrollAmount = 5; + _xTrack = -10; + _yTrack = _zTrack = 0; + _xCam = 480; + _yCam = 0; + _zCam = 80; + + _vm->_timers[24]._timer = 1; + _vm->_timers[24]._initTm = 1; + ++_vm->_timers[24]._flag; + + _pNumObj = 7; + for (int i = 0; i < _pNumObj; i++) { + _pan[i]._pObject = _vm->_objectsTable[24]; + _pan[i]._pImgNum = JUNGLE1OBJ[i][0]; + _pan[i]._pObjX = JUNGLE1OBJ[i][1]; + _pan[i]._pObjY = JUNGLE1OBJ[i][2]; + _pan[i]._pObjZ = JUNGLE1OBJ[i][3]; + _pan[i]._pObjXl = _pan[i]._pObjYl = 0; + } + + _jCnt[0] = 0; + _jCnt[1] = 3; + _jCnt[2] = 5; + + _jungleX[0] = 50; + _jungleX[1] = 16; + _jungleX[2] = 93; +} + +void Jungle::mWhileJWalk() { + Screen &screen = *_vm->_screen; + EventsManager &events = *_vm->_events; + Player &player = *_vm->_player; + + static const int JUNGLE_OBJ[7][4] = { + { 2, 77, 0, 40 }, + { 0, 290, 0, 50 }, + { 1, 210, 0, 70 }, + { 0, 50, 0, 30 }, + { 1, 70, 0, 20 }, + { 0, -280, 0, 60 }, + { 1, -150, 0, 30 }, + }; + + screen.fadeOut(); + events.hideCursor(); + screen.clearScreen(); + _vm->_buffer2.clearBuffer(); + screen.setBufferScan(); + screen._scrollX = 0; + + // Build the initial jungle scene and fade it in + _vm->_room->buildScreen(); + _vm->copyBF2Vid(); + screen.fadeIn(); + + // Set up the player to walk horizontally + player._xFlag = 1; + player._yFlag = 0; + player._moveTo.x = 160; + player._playerMove = true; + + _xCount = 2; + _xTrack = 10; + _yTrack = _zTrack = 0; + _xCam = 480; + _yCam = 0; + _zCam = 80; + + TimerEntry *te = &_vm->_timers[24]; + te->_initTm = te->_timer = 1; + te->_flag++; + + _pNumObj = 7; + for (int i = 0; i < _pNumObj; i++) { + _pan[i]._pObject = _vm->_objectsTable[24]; + _pan[i]._pImgNum = JUNGLE_OBJ[i][0]; + _pan[i]._pObjX = JUNGLE_OBJ[i][1]; + _pan[i]._pObjY = JUNGLE_OBJ[i][2]; + _pan[i]._pObjZ = JUNGLE_OBJ[i][3]; + _pan[i]._pObjXl = _pan[i]._pObjYl = 0; + } + + while (!_vm->shouldQuit() && !events.isKeyMousePressed() && (player._xFlag != 2)) { + _vm->_images.clear(); + events._vbCount = 6; + + _pan[0]._pImgNum = _xCount; + if (_xCount == 2) + ++_xCount; + else + --_xCount; + + player.checkMove(); + player.checkScroll(); + pan(); + scrollJWalk(); + + while (!_vm->shouldQuit() && events._vbCount > 0) { + events.pollEventsAndWait(); + } + } + + _vm->_images.clear(); + events.showCursor(); +} + +void Jungle::mWhileJWalk2() { + Screen &screen = *_vm->_screen; + + initJWalk2(); + + while (!_vm->shouldQuit() && !_vm->_events->isKeyMousePressed() && + (screen._scrollCol + screen._vWindowWidth) != _vm->_room->_playFieldWidth) { + _vm->_images.clear(); + _vm->_events->_vbCount = 6; + _pan[0]._pImgNum = _xCount; + + jungleMove(); + while (screen._scrollX >= TILE_WIDTH) { + screen._scrollX -= TILE_WIDTH; + ++screen._scrollCol; + _vm->_buffer1.moveBufferLeft(); + _vm->_room->buildColumn(screen._scrollCol + screen._vWindowWidth, screen._vWindowBytesWide); + } + + if (_xCount == 2) + ++_xCount; + else + --_xCount; + + pan(); + scrollJWalk(); + + while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0) { + _vm->_events->pollEventsAndWait(); + } + } + + _vm->_events->showCursor(); +} + +void Jungle::scrollJWalk() { + _vm->copyBF1BF2(); + _vm->_newRects.clear(); + _vm->plotList(); + _vm->copyRects(); + _vm->copyBF2Vid(); +} + +/*------------------------------------------------------------------------*/ + +Guard::Guard(AmazonEngine *vm): PannedScene(vm) { + _vm = nullptr; + _guardCel = 0; + _gCode1 = _gCode2 = 0; + _xMid = _yMid = 0; +} + +void Guard::setVerticalCode() { + _gCode1 = 0; + _gCode2 = 0; + if (_topLeft.x < _vm->_screen->_orgX1) + _gCode1 |= 8; + else if (_topLeft.x == _vm->_screen->_orgX1) { + _gCode1 |= 8; + _gCode1 |= 2; + } + else + _gCode1 |= 2; + + if (_bottomRight.x < _vm->_screen->_orgX1) + _gCode2 |= 8; + else if (_bottomRight.x == _vm->_screen->_orgX1) { + _gCode2 |= 8; + _gCode2 |= 2; + } + else + _gCode2 |= 2; + + if (_topLeft.y < _vm->_screen->_orgY1) + _gCode1 |= 4; + else if (_topLeft.y > _vm->_screen->_orgY2) + _gCode1 |= 1; + + if (_bottomRight.y < _vm->_screen->_orgY1) + _gCode2 |= 4; + else if (_bottomRight.y > _vm->_screen->_orgY2) + _gCode2 |= 1; +} + +void Guard::setHorizontalCode() { + _gCode1 = 0; + _gCode2 = 0; + + if (_topLeft.y < _vm->_screen->_orgY1) + _gCode1 |= 4; + else if (_topLeft.x == _vm->_screen->_orgX1) { + _gCode1 |= 4; + _gCode1 |= 1; + } + else + _gCode1 |= 1; + + if (_bottomRight.y < _vm->_screen->_orgY1) + _gCode2 |= 4; + else if (_bottomRight.x == _vm->_screen->_orgX1) { + _gCode2 |= 4; + _gCode2 |= 1; + } + else + _gCode2 |= 1; + + if (_topLeft.x < _vm->_screen->_orgX1) + _gCode1 |= 8; + else if (_topLeft.x > _vm->_screen->_orgX2) + _gCode1 |= 2; + + if (_bottomRight.x < _vm->_screen->_orgX1) + _gCode2 |= 8; + else if (_bottomRight.y > _vm->_screen->_orgX2) + _gCode2 |= 2; +} + +void Guard::chkVLine() { + if (_position.x > _vm->_player->_rawPlayer.x) { + _topLeft = _vm->_player->_rawPlayer; + _bottomRight = _position; + } + else { + _topLeft = _position; + _bottomRight = _vm->_player->_rawPlayer; + } + + if (_vm->_screen->_orgY1 > _vm->_screen->_orgY2) + SWAP(_vm->_screen->_orgY1, _vm->_screen->_orgY2); + + for (;;) { + setVerticalCode(); + int code = _gCode1 | _gCode2; + if (code == 10) { + _vm->_guardFind = 0; + return; + } + + int code2 = _gCode1 & _gCode2; + code2 &= 5; + if (((code & 10) == 8) || ((code & 10) == 2) || (code2 != 0)) + return; + + int midX = (_topLeft.x + _bottomRight.x) / 2; + int midY = (_topLeft.y + _bottomRight.y) / 2; + + if (midX < _vm->_screen->_orgX1) { + if ((midX == _topLeft.x) && (midY == _topLeft.y)) + return; + + _topLeft.x = midX; + _topLeft.y = midY; + } + else { + if ((midX == _bottomRight.x) && (midY == _bottomRight.y)) + return; + + _bottomRight.x = midX; + _bottomRight.y = midY; + } + } +} + +void Guard::chkHLine() { + if (_position.y > _vm->_player->_rawPlayer.y) { + _topLeft = _vm->_player->_rawPlayer; + _bottomRight = _position; + } + else { + _topLeft = _position; + _bottomRight = _vm->_player->_rawPlayer; + } + + if (_vm->_screen->_orgX1 > _vm->_screen->_orgX2) + SWAP(_vm->_screen->_orgX1, _vm->_screen->_orgX2); + + while (true) { + setHorizontalCode(); + int code = _gCode1 | _gCode2; + if (code == 5) { + _vm->_guardFind = 0; + return; + } + + int code2 = _gCode1 & _gCode2; + code2 &= 10; + if (((code & 5) == 4) || ((code & 5) == 1) || (code2 != 0)) + return; + + int midX = (_topLeft.x + _bottomRight.x) / 2; + int midY = (_topLeft.y + _bottomRight.y) / 2; + + if (midY < _vm->_screen->_orgY1) { + if ((midX == _topLeft.x) && (midY == _topLeft.y)) + return; + + _topLeft.x = midX; + _topLeft.y = midY; + } + else { + if ((midX == _bottomRight.x) && (midY == _bottomRight.y)) + return; + + _bottomRight.x = midX; + _bottomRight.y = midY; + } + } +} + +void Guard::guardSee() { + int tmpY = (_vm->_screen->_scrollRow << 4) + _vm->_screen->_scrollY; + _vm->_flags[140] = 0; + if (tmpY > _position.y) + return; + + tmpY += _vm->_screen->_vWindowLinesTall; + tmpY -= 11; + + if (tmpY < _position.y) + return; + + _vm->_guardFind = 1; + _vm->_flags[140] = 1; + + for (uint16 idx = 0; idx < _vm->_room->_plotter._walls.size(); idx++) { + _vm->_screen->_orgX1 = _vm->_room->_plotter._walls[idx].left; + _vm->_screen->_orgY1 = _vm->_room->_plotter._walls[idx].top; + _vm->_screen->_orgX2 = _vm->_room->_plotter._walls[idx].right; + _vm->_screen->_orgY2 = _vm->_room->_plotter._walls[idx].bottom; + if (_vm->_screen->_orgX1 == _vm->_screen->_orgX2) { + chkVLine(); + if (_vm->_guardFind == 0) + return; + } + else if (_vm->_screen->_orgY1 == _vm->_screen->_orgY2) { + chkHLine(); + if (_vm->_guardFind == 0) + return; + } + } +} + +void Guard::setGuardFrame() { + ImageEntry ie; + ie._flags = IMGFLAG_UNSCALED; + + if (_vm->_guardLocation == 4) + ie._flags |= IMGFLAG_BACKWARDS; + ie._spritesPtr = _vm->_objectsTable[37]; + ie._frameNumber = _guardCel; + ie._position = _position; + ie._offsetY = 10; + _vm->_images.addToList(ie); +} + +void Guard::doGuard() { + if (_vm->_timers[8]._flag) { + setGuardFrame(); + return; + } + + ++_vm->_timers[8]._flag; + ++_guardCel; + int curCel = _guardCel; + + switch (_vm->_guardLocation) { + case 1: + // Guard walking down + if (curCel <= 8 || curCel > 13) + _guardCel = curCel = 8; + + _position.y += _vm->_player->_walkOffDown[curCel - 8]; + guardSee(); + if (_position.y >= 272) { + _position.y = 272; + _vm->_guardLocation = 2; + } + break; + case 2: + // Guard walking left + if (curCel <= 43 || curCel > 48) + _guardCel = curCel = 43; + + _position.x -= _vm->_player->_walkOffLeft[curCel - 43]; + guardSee(); + if (_position.x <= 56) { + _position.x = 56; + _vm->_guardLocation = 3; + } + break; + case 3: + // Guard walking up + if (curCel <= 0 || curCel > 5) + _guardCel = curCel = 0; + + _position.y -= _vm->_player->_walkOffUp[curCel]; + guardSee(); + if (_position.y <= 89) { + _position.y = 89; + _vm->_guardLocation = 4; + if (_vm->_flags[121] == 1) + _vm->_guardLocation = 5; + } + break; + default: + // Guard walking right + if (curCel <= 43 || curCel > 48) + _guardCel = curCel = 43; + + _position.x += _vm->_player->_walkOffRight[curCel - 43]; + guardSee(); + if (_position.x >= 127) { + _position.x = 127; + _vm->_guardLocation = 1; + } + break; + } + + setGuardFrame(); +} + +void Guard::setPosition(const Common::Point &pt) { + _position = pt; +} + +/*------------------------------------------------------------------------*/ + +Cast::Cast(AmazonEngine *vm) : PannedScene(vm) { +} + +void Cast::doCast(int param1) { + _vm->_screen->setDisplayScan(); + _vm->_events->hideCursor(); + _vm->_screen->forceFadeOut(); + _vm->_screen->_clipHeight = 173; + _vm->_screen->clearScreen(); + _vm->_chapter = 16; + _vm->tileScreen(); + _vm->updateSummary(param1); + _vm->_screen->setPanel(3); + _vm->_chapter = 14; + + Resource *spriteData = _vm->_files->loadFile(91, 0); + _vm->_objectsTable[0] = new SpriteResource(_vm, spriteData); + delete spriteData; + spriteData = _vm->_files->loadFile(91, 1); + _vm->_objectsTable[1] = new SpriteResource(_vm, spriteData); + delete spriteData; + + _vm->_files->_setPaletteFlag = false; + _vm->_files->loadScreen(58, 1); + _vm->_buffer2.copyFrom(*_vm->_screen); + _vm->_buffer1.copyFrom(*_vm->_screen); + + _xTrack = 0; + _yTrack = -6; + _zTrack = 0; + _xCam = _yCam = 0; + _zCam = 60; + + _vm->_timers[24]._timer = 1; + _vm->_timers[24]._initTm = 1; + ++_vm->_timers[24]._flag; + + _pNumObj = 26; + for (int i = 0; i < _pNumObj; i++) { + _pan[i]._pObject = _vm->_objectsTable[0]; + _pan[i]._pImgNum = CAST_END_OBJ[i][0]; + _pan[i]._pObjX = CAST_END_OBJ[i][1]; + _pan[i]._pObjY = CAST_END_OBJ[i][2]; + _pan[i]._pObjZ = CAST_END_OBJ[i][3]; + _pan[i]._pObjXl = _pan[i]._pObjYl = 0; + } + + _pNumObj = 4; + for (int i = 0; i < _pNumObj; i++) { + _pan[26 + i]._pObject = _vm->_objectsTable[1]; + _pan[26 + i]._pImgNum = CAST_END_OBJ1[i][0]; + _pan[26 + i]._pObjX = CAST_END_OBJ1[i][1]; + _pan[26 + i]._pObjY = CAST_END_OBJ1[i][2]; + _pan[26 + i]._pObjZ = CAST_END_OBJ1[i][3]; + _pan[26 + i]._pObjXl = _pan[26 + i]._pObjYl = 0; + } + + _vm->_oldRects.clear(); + _vm->_newRects.clear(); + _vm->_numAnimTimers = 0; + + _vm->_sound->newMusic(58, 0); + _vm->_screen->forceFadeIn(); + + while (!_vm->shouldQuit()) { + _vm->_images.clear(); + pan(); + _vm->_buffer2.copyFrom(_vm->_buffer1); + _vm->_newRects.clear(); + _vm->plotList(); + _vm->copyBlocks(); + + _vm->_events->pollEvents(); + if (_vm->_events->isKeyMousePressed()) + break; + + if (_yCam < -7550) { + _vm->_events->_vbCount = 50; + + while (!_vm->shouldQuit() && !_vm->_events->isKeyMousePressed() && _vm->_events->_vbCount > 0) { + _vm->_events->pollEventsAndWait(); + } + + while (!_vm->shouldQuit() && !_vm->_sound->checkMidiDone()) + _vm->_events->pollEventsAndWait(); + + break; + } + } + + _vm->_sound->newMusic(58, 1); + _vm->_events->showCursor(); + + _vm->freeCells(); + _vm->_oldRects.clear(); + _vm->_newRects.clear(); + _vm->_numAnimTimers = 0; + _vm->_images.clear(); + _vm->_screen->forceFadeOut(); + + _vm->quitGame(); + _vm->_events->pollEvents(); +} + +/*------------------------------------------------------------------------*/ + +River::River(AmazonEngine *vm): PannedScene(vm) { + _vm = nullptr; + _CHICKENOUTFLG = false; + _rScrollRow = 0; + _rScrollCol = 0; + _rScrollX = 0; + _rScrollY = 0; + _rOldRectCount = 0; + _rNewRectCount = 0; + _rKeyFlag = 0; + _mapOffset = 0; + _screenVirtX = 0; +} + +void River::setRiverPan() { + int delta = (_vm->_screen->_scrollCol * 16) + _vm->_screen->_scrollX; + + _xTrack = 9; + _yTrack = _zTrack = 0; + _xCam = 160; + _yCam = 0; + _zCam = 80; + + _vm->_timers[24]._timer = 1; + _vm->_timers[24]._initTm = 1; + ++_vm->_timers[24]._flag; + + _pNumObj = 23; + for (int i = 0; i < _pNumObj; i++) { + _pan[i]._pObject = _vm->_objectsTable[45]; + _pan[i]._pImgNum = RIVER1OBJ[i][0]; + _pan[i]._pObjX = RIVER1OBJ[i][1] + delta; + _pan[i]._pObjY = RIVER1OBJ[i][2]; + _pan[i]._pObjZ = RIVER1OBJ[i][3]; + _pan[i]._pObjXl = _pan[i]._pObjYl = 0; + } +} + +void River::initRiver() { + static const int RIVERVXTBL[3] = { 6719, 7039, 8319 }; + + _vm->_events->centerMousePos(); + _vm->_events->restrictMouse(); + _vm->_screen->setDisplayScan(); + _vm->_screen->clearScreen(); + _vm->_screen->savePalette(); + _vm->_screen->forceFadeOut(); + + _vm->_files->_setPaletteFlag = false; + _vm->_files->loadScreen(95, 4); + _vm->_buffer2.copyFrom(*_vm->_screen); + + _vm->_screen->restorePalette(); + _vm->_screen->setBufferScan(); + _vm->_destIn = &_vm->_buffer2; + _vm->_room->roomMenu(); + + if (_vm->_saveRiver) { + // Restoring a savegame, so set properties from saved fields + _vm->_screen->_scrollRow = _rScrollRow; + _vm->_screen->_scrollCol = _rScrollCol; + _vm->_screen->_scrollX = _rScrollX; + _vm->_screen->_scrollY = _rScrollY; + } else { + // Set initial scene state + _vm->_screen->_scrollRow = 0; + _vm->_screen->_scrollCol = 140; + _vm->_screen->_scrollX = 0; + _vm->_screen->_scrollY = 0; + } + + _vm->_room->buildScreen(); + _vm->copyBF2Vid(); + _vm->_screen->forceFadeIn(); + + if (_vm->_saveRiver) { + // Restore draw rects from savegame + _vm->_oldRects.resize(_rOldRectCount); + _vm->_newRects.resize(_rNewRectCount); + // KEYFLG = _vm->_rKeyFlag + } else { + // Reset draw rects + _vm->_oldRects.clear(); + _vm->_newRects.clear(); + // KEYFLG = 0 + } + + _vm->_player->_scrollAmount = 2; + setRiverPan(); + _vm->_timers[3]._timer = 1; + _vm->_timers[3]._initTm = 1; + ++_vm->_timers[3]._flag; + + _canoeFrame = 0; + _mapPtr = (const byte *)MAPTBL[_vm->_riverFlag] + 1; + if (_vm->_saveRiver) { + _mapPtr--; + _mapPtr += _mapOffset; + } else { + _screenVertX = RIVERVXTBL[_vm->_riverFlag] - 320; + _canoeLane = 3; + _hitCount = 0; + _hitSafe = 0; + _canoeYPos = 71; + } + + _riverIndex = _vm->_riverFlag; + _topList = RIVEROBJECTTBL[_riverIndex]; + updateObstacles(); + riverSetPhysX(); + _canoeDir = 0; + _vm->_deathFlag = 0; + _vm->_deathCount = 0; + + _vm->_timers[11]._timer = 1200; + _vm->_timers[11]._initTm = 1200; + ++_vm->_timers[11]._flag; + _vm->_timers[12]._timer = 1500; + _vm->_timers[12]._initTm = 1500; + ++_vm->_timers[12]._flag; + + _vm->_maxHits = 2 - _vm->_riverFlag; + _vm->_saveRiver = false; +} + +void River::resetPositions() { + riverSetPhysX(); + int val = (_vm->_screen->_scrollCol + 1 - _vm->_oldScrollCol) * 16; + if (val > 256) { + val &= 0x7F; + val |= 0x80; + } + + for (int i = 0; i < _pNumObj; i++) + _pan[i]._pObjX += val; +} + +void River::checkRiverPan() { + int val = (_vm->_screen->_scrollCol + 20) * 16; + + for (int i = 0; i < _pNumObj; i++) { + if (_pan[i]._pObjX < val) + return; + } + + setRiverPan(); +} + +bool River::riverJumpTest() { + if (_vm->_screen->_scrollCol == 120 || _vm->_screen->_scrollCol == 60 || _vm->_screen->_scrollCol == 0) { + int val = _mapPtr[0]; + ++_mapPtr; + if (val == 0xFF) + return true; + _vm->_oldScrollCol = _vm->_screen->_scrollCol; + + if (val == 0) { + _vm->_screen->_scrollCol = 139; + _vm->_screen->_scrollX = 14; + _vm->_room->buildScreen(); + resetPositions(); + return false; + } + } else if (_vm->_screen->_scrollCol == 105) { + int val1 = _mapPtr[1]; + int val2 = _mapPtr[2]; + _mapPtr += 3; + if (_canoeLane < 3) { + if (val1 != 0) { + _vm->_deathFlag = true; + _vm->_deathCount = 300; + _vm->_deathType = val2; + } + } else { + if (val1 != 1) { + _vm->_deathFlag = true; + _vm->_deathCount = 300; + _vm->_deathType = val2; + } + _vm->_oldScrollCol = _vm->_screen->_scrollCol; + _vm->_screen->_scrollCol = 44; + _vm->_screen->_scrollX = 14; + _vm->_room->buildScreen(); + resetPositions(); + return false; + } + } + + _vm->_screen->_scrollX = 14; + --_vm->_screen->_scrollCol; + _vm->_buffer1.moveBufferRight(); + _vm->_room->buildColumn(_vm->_screen->_scrollCol, 0); + checkRiverPan(); + return false; +} + +void River::riverSound() { + if (_vm->_timers[11]._flag == 0) { + ++_vm->_timers[11]._flag; + _vm->_sound->playSound(2); + } + + if (_vm->_timers[12]._flag == 0) { + ++_vm->_timers[12]._flag; + _vm->_sound->playSound(3); + } + + if ((_xCam >= 1300) && (_xCam <= 1320)) + _vm->_sound->playSound(1); +} + +void River::moveCanoe() { + Screen &screen = *_vm->_screen; + EventsManager &events = *_vm->_events; + Common::Point pt = events.calcRawMouse(); + + // Do an event polling + _vm->_canSaveLoad = true; + events.pollEvents(); + _vm->_canSaveLoad = false; + if (_vm->_room->_function == FN_CLEAR1) + return; + + if (_canoeDir) { + // Canoe movement in progress + moveCanoe2(); + } else { + if (events._leftButton && pt.y >= 140) { + if (pt.x < RMOUSE[8][0]) { + // Disk icon wasn't clicked + _vm->_scripts->printString(BAR_MESSAGE); + } else { + // Clicked on the Disc icon + _vm->_saveRiver = true; + _rScrollRow = screen._scrollRow; + _rScrollCol = screen._scrollCol; + _rScrollX = screen._scrollX; + _rScrollY = screen._scrollY; + _mapOffset = _mapPtr - MAPTBL[_vm->_riverFlag]; + + // Show the ScummVM menu + _vm->_room->handleCommand(9); + + if (_vm->_room->_function != FN_CLEAR1) { + _vm->_saveRiver = false; + _vm->_room->buildScreen(); + _vm->copyBF2Vid(); + } + } + } + else if ((events._leftButton && pt.y <= _canoeYPos) || + (!events._leftButton && _vm->_player->_move == UP)) { + // Move canoe up + if (_canoeLane > 0) { + _canoeDir = -1; + _canoeMoveCount = 0; + + moveCanoe2(); + } + } + else if (events._leftButton || _vm->_player->_move == DOWN) { + // Move canoe down + if (_canoeLane < 7) { + _canoeDir = 1; + _canoeMoveCount = 0; + + moveCanoe2(); + } + } + } +} + +void River::moveCanoe2() { + _canoeYPos += _canoeDir; + + if (++_canoeMoveCount == 5) { + _canoeLane += _canoeDir; + _canoeDir = 0; + } +} + +void River::updateObstacles() { + RiverStruct *cur; + for (cur = _topList; cur < RIVEROBJECTTBL[_riverIndex + 1]; ++cur) { + int val = cur->_field1 + cur->_field3 - 1; + if (val < _screenVertX) + break; + + if (cur->_field3 < (_screenVirtX + 319)) { + _topList = cur; + _botList = cur; + + while (cur < RIVEROBJECTTBL[_riverIndex + 1]) { + ++cur; + val = cur->_field1 + cur->_field3 - 1; + if (val < _screenVertX || (cur->_field3 >= (_screenVirtX + 319))) + break; + + _botList = cur; + } + + return; + } + } + + cur = _topList; + cur--; + _botList = cur; +} + +void River::riverSetPhysX() { + int val = (_vm->_screen->_scrollCol * 16) + _vm->_screen->_scrollX; + RiverStruct *cur = _topList; + while (cur <= _botList) { + cur[0]._field5 = val - (_screenVertX - cur[0]._field3); + ++cur; + } +} + +bool River::checkRiverCollide() { + if (_hitSafe) + return false; + + _canoeVXPos = _screenVertX + 170; + + for (RiverStruct *si = _topList; si <= _botList; ++si) { + if (si[0]._lane < _canoeLane) + continue; + + if ((si[0]._lane == _canoeLane) || (si[0]._lane == _canoeLane + 1)) { + if (si[0]._field1 + si[0]._field3 - 1 >= _canoeVXPos) { + if (_canoeVXPos + 124 >= si[0]._field3) { + _vm->_sound->playSound(4); + return true; + } + } + } + } + return false; +} + +void River::plotRiver() { + if (_vm->_timers[3]._flag == 0) { + ++_vm->_timers[3]._flag; + if (_canoeFrame == 12) + _canoeFrame = 0; + else + ++_canoeFrame; + } + + ImageEntry ie; + ie._flags = IMGFLAG_UNSCALED; + ie._spritesPtr = _vm->_objectsTable[45]; + ie._frameNumber = _canoeFrame; + ie._position.x = (_vm->_screen->_scrollCol * 16) + _vm->_screen->_scrollX + 160; + ie._position.y = _canoeYPos - 41; + ie._offsetY = 41; + _vm->_images.addToList(ie); + + RiverStruct *cur = _topList; + while (cur <= _botList) { + if (cur[0]._id != -1) { + ie._flags = IMGFLAG_UNSCALED; + ie._spritesPtr = _vm->_objectsTable[45]; + ie._frameNumber = 0; + ie._position.x = cur[0]._field5; + int val = (cur[0]._lane * 5) + 56; + ie._position.y = val - cur[0]._field8; + ie._offsetY = cur[0]._field8; + _vm->_images.addToList(ie); + } + ++cur; + } +} + +void River::mWhileDownRiver() { + _vm->_events->hideCursor(); + _vm->_screen->setDisplayScan(); + _vm->_screen->clearScreen(); + _vm->_screen->savePalette(); + + _vm->_files->loadScreen(95, 4); + _vm->_buffer2.copyFrom(*_vm->_screen); + _vm->_screen->restorePalette(); + _vm->_screen->setPalette(); + _vm->_screen->setBufferScan(); + _vm->_screen->_scrollX = 0; + _vm->_room->buildScreen(); + _vm->copyBF2Vid(); + + _vm->_player->_scrollAmount = 2; + _vm->_destIn = &_vm->_buffer2; + _xTrack = -7; + _yTrack = _zTrack = 0; + _xCam = _yCam = 0; + _zCam = 80; + + _vm->_timers[24]._timer = 1; + _vm->_timers[24]._initTm = 1; + ++_vm->_timers[24]._flag; + + _pNumObj = 14; + for (int i = 0; i <_pNumObj; i++) { + _pan[i]._pObject = _vm->_objectsTable[33]; + _pan[i]._pImgNum = DOWNRIVEROBJ[i][0]; + _pan[i]._pObjX = DOWNRIVEROBJ[i][1]; + _pan[i]._pObjY = DOWNRIVEROBJ[i][2]; + _pan[i]._pObjZ = DOWNRIVEROBJ[i][3]; + _pan[i]._pObjXl = _pan[i]._pObjYl = 0; + } + + _vm->_timers[3]._timer = 200; + _vm->_timers[3]._initTm = 200; + ++_vm->_timers[3]._flag; + _vm->_timers[4]._timer = 350; + _vm->_timers[4]._initTm = 350; + ++_vm->_timers[4]._flag; + + while (!_vm->shouldQuit() && !_vm->_events->isKeyMousePressed() && + (_vm->_screen->_scrollCol + _vm->_screen->_vWindowWidth != _vm->_room->_playFieldWidth)) { + _vm->_images.clear(); + _vm->_events->_vbCount = 6; + + _vm->_screen->_scrollX += _vm->_player->_scrollAmount; + while (_vm->_screen->_scrollX >= TILE_WIDTH) { + _vm->_screen->_scrollX -= TILE_WIDTH; + ++_vm->_screen->_scrollCol; + _vm->_buffer1.moveBufferLeft(); + _vm->_room->buildColumn(_vm->_screen->_scrollCol + _vm->_screen->_vWindowWidth, _vm->_screen->_vWindowBytesWide); + } + + pan(); + scrollRiver(); + + if (!_vm->_timers[3]._flag) { + ++_vm->_timers[3]._flag; + _vm->_sound->playSound(1); + } + else if (!_vm->_timers[4]._flag) { + ++_vm->_timers[4]._flag; + _vm->_sound->playSound(0); + } + + while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0) { + _vm->_events->pollEventsAndWait(); + } + } + + _vm->_events->showCursor(); +} + +void River::scrollRiver() { + _vm->copyBF1BF2(); + _vm->_newRects.clear(); + _vm->_buffer2.plotImage(_vm->_objectsTable[33], 0, Common::Point(66, 30)); + _vm->plotList(); + _vm->copyRects(); + _vm->copyBF2Vid(); +} + +void River::scrollRiver1() { + _vm->copyBF1BF2(); + _vm->_newRects.clear(); + plotRiver(); + _vm->plotList(); + _vm->copyRects(); + _vm->copyBF2Vid(); +} + +void River::river() { + static const int RIVERDEATH[5] = { 22, 23, 24, 25, 26 }; + + initRiver(); + _vm->_events->showCursor(); + + while (!_vm->shouldQuit()) { + _vm->_events->_vbCount = 4; + + // int bx = _vm->_player->_scrollAmount - _screenVertX; + if (_vm->_screen->_scrollX == 0) { + _vm->_sound->midiRepeat(); + if (riverJumpTest()) { + _CHICKENOUTFLG = false; + return; + } + } + else { + _vm->_screen->_scrollX -= _vm->_player->_scrollAmount; + } + + if (_CHICKENOUTFLG) { + _CHICKENOUTFLG = false; + return; + } + + _vm->_images.clear(); + _vm->_animation->animate(0); + + riverSound(); + pan(); + moveCanoe(); + + if (_vm->_room->_function != FN_CLEAR1) { + updateObstacles(); + riverSetPhysX(); + bool checkCollide = checkRiverCollide(); + if (_hitSafe != 0) + _hitSafe -= 2; + + if (checkCollide) { + _vm->dead(RIVERDEATH[0]); + return; + } + + if (_vm->_deathFlag) { + _vm->_deathCount--; + if (_vm->_deathCount == 0) { + _vm->dead(RIVERDEATH[_vm->_deathType]); + return; + } + } + + // Scroll the river + scrollRiver1(); + + // Allow time for new scrolled river position to be shown + _vm->_canSaveLoad = true; + while (!_vm->shouldQuit() && _vm->_room->_function == FN_NONE && + _vm->_events->_vbCount > 0) { + _vm->_events->pollEventsAndWait(); + } + _vm->_canSaveLoad = false; + } + + if (_vm->_room->_function == FN_CLEAR1) { + _vm->_scripts->_endFlag = true; + _vm->_scripts->_returnCode = 0; + _CHICKENOUTFLG = false; + break; + } + } +} +void River::synchronize(Common::Serializer &s) { + s.syncAsSint16LE(_canoeLane); + s.syncAsSint16LE(_canoeYPos); + s.syncAsSint16LE(_hitCount); + s.syncAsSint16LE(_riverIndex); + s.syncAsSint16LE(_hitSafe); + s.syncAsUint16LE(_rScrollRow); + s.syncAsUint16LE(_rScrollCol); + s.syncAsSint16LE(_rScrollX); + s.syncAsSint16LE(_rScrollY); + s.syncAsUint16LE(_rOldRectCount); + s.syncAsUint16LE(_rNewRectCount); + s.syncAsUint16LE(_rKeyFlag); + s.syncAsUint16LE(_mapOffset); + s.syncAsUint16LE(_screenVirtX); + warning("TODO: s.syncAsSint16LE(_topList);"); + warning("TODO: s.syncAsSint16LE(_botList);"); +} + +/*------------------------------------------------------------------------*/ + +Ant::Ant(AmazonEngine *vm) : AmazonManager(vm) { + _antDirection = NONE; + _pitDirection = NONE; + _antCel = 0; + _torchCel = 0; + _pitCel = 0; + _stabCel = 0; + _antPos = Common::Point(0, 0); + _antDieFl = _antEatFl = false; + _stabFl = false; + _pitPos = Common::Point(0, 0); +} + +void Ant::plotTorchSpear(int indx, const int *&buf) { + int idx = indx; + + ImageEntry ie; + ie._flags = IMGFLAG_UNSCALED; + ie._spritesPtr = _vm->_objectsTable[62]; + ie._frameNumber = buf[(idx / 2)]; + ie._position = Common::Point(_pitPos.x + buf[(idx / 2) + 1], _pitPos.y + buf[(idx / 2) + 2]); + ie._offsetY = 255; + _vm->_images.addToList(ie); +} + +void Ant::plotPit(int indx, const int *&buf) { + int idx = indx; + ImageEntry ie; + ie._flags = IMGFLAG_UNSCALED; + ie._spritesPtr = _vm->_objectsTable[62]; + ie._frameNumber = buf[(idx / 2)]; + ie._position = Common::Point(_pitPos.x, _pitPos.y); + ie._offsetY = _pitPos.y; + _vm->_images.addToList(ie); + + _vm->_player->_rawPlayer = _pitPos; + if (_vm->_inventory->_inv[76]._value == 1) { + idx = _torchCel; + buf = Amazon::TORCH; + _vm->_timers[14]._flag = 1; + idx += 6; + if (buf[idx / 2] == -1) + idx = 0; + _torchCel = idx; + plotTorchSpear(idx, buf); + } + else if (!_stabFl && (_vm->_inventory->_inv[78]._value == 1)) { + idx = 0; + buf = Amazon::SPEAR; + plotTorchSpear(idx, buf); + } +} + +int Ant::antHandleRight(int indx, const int *&buf) { + int retval = indx; + if (_pitDirection == NONE) { + _pitDirection = UP; + _pitPos.y = 127; + } + retval = _pitCel; + buf = Amazon::PITWALK; + if (_pitPos.x < 230) { + if (retval == 0) { + retval = 48; + _pitPos.y = 127; + } + retval -= 6; + _pitPos.x -= buf[(retval / 2) + 1]; + _pitPos.y -= buf[(retval / 2) + 2]; + _pitCel = retval; + } + return retval; +} + +int Ant::antHandleLeft(int indx, const int *&buf) { + int retval = indx; + if (_pitDirection == UP) { + _pitDirection = NONE; + _pitPos.y = 127; + } + retval = _pitCel; + buf = Amazon::PITWALK; + retval += 6; + if (buf[retval / 2] == -1) { + retval = 0; + _pitPos.y = 127; + } + _pitPos.x += buf[(retval / 2) + 1]; + _pitPos.y += buf[(retval / 2) + 2]; + _pitCel = retval; + + return retval; +} + +int Ant::antHandleStab(int indx, const int *&buf) { + int retval = indx; + if (_vm->_inventory->_inv[78]._value != 1) { + if (_stabFl) { + buf = Amazon::PITSTAB; + retval = _stabCel; + if (_vm->_timers[13]._flag == 0) { + _vm->_timers[13]._flag = 1; + retval += 6; + if (Amazon::PITSTAB[retval] == -1) { + _stabFl = false; + _pitCel = 0; + _pitPos.y = 127; + retval = 0; + buf = Amazon::PITWALK; + } + else { + _pitPos.x += buf[(retval / 2) + 1]; + _pitPos.y += buf[(retval / 2) + 2]; + _pitCel = retval; + } + } + } + else { + _stabFl = true; + _pitCel = 0; + retval = 0; + _stabCel = 0; + int dist = _pitPos.x - _antPos.x; + if (_antEatFl && !_antDieFl && (dist <= 80)) { + _antDieFl = true; + _antCel = 0; + _antPos.y = 123; + _vm->_sound->playSound(1); + } + } + } + return retval; +} + +void Ant::doAnt() { + _antDirection = NONE; + if (_vm->_aniFlag != 1) { + _vm->_aniFlag = 1; + _antCel = 0; + _torchCel = 0; + _pitCel = 0; + + _vm->_timers[15]._timer = 16; + _vm->_timers[15]._initTm = 16; + _vm->_timers[15]._flag = 1; + + _vm->_timers[13]._timer = 5; + _vm->_timers[13]._initTm = 5; + _vm->_timers[13]._flag = 1; + + _vm->_timers[14]._timer = 10; + _vm->_timers[14]._initTm = 10; + _vm->_timers[14]._flag = 1; + + _antPos = Common::Point(-40, 123); + _antDieFl = _antEatFl = false; + _stabFl = false; + _pitPos = Common::Point(_vm->_player->_rawPlayer.x, 127); + } + + const int *buf = nullptr; + if (_antDieFl) { + buf = Amazon::ANTDIE; + } + else if (_antEatFl) { + buf = Amazon::ANTEAT; + } + else if (_antPos.x > 120 && _vm->_flags[198] == 1) { + _antEatFl = true; + _vm->_flags[235] = 1; + _antCel = 0; + buf = Amazon::ANTEAT; + } + else { + buf = Amazon::ANTWALK; + if (_vm->_inventory->_inv[76]._value == 1) + _antDirection = UP; + } + + int idx = _antCel; + if (_vm->_timers[15]._flag == 0) { + _vm->_timers[15]._flag = 1; + if (_antDirection == UP) { + if (_antPos.x > 10) { + if (idx == 0) + idx = 36; + else + idx -= 6; + + _antPos = Common::Point(buf[(idx / 2) + 1], buf[(idx / 2) + 2]); + _antCel = idx; + } + } + else { + idx += 6; + if (buf[(idx / 2)] != -1) { + _antPos = Common::Point(buf[(idx / 2) + 1], buf[(idx / 2) + 2]); + _antCel = idx; + } + else if (!_antDieFl) { + idx = 0; + _antPos = Common::Point(buf[(idx / 2) + 1], buf[(idx / 2) + 2]); + _antCel = idx; + } + else { + idx -= 6; + if (_vm->_flags[200] == 0) + _vm->_flags[200] = 1; + } + } + } + + ImageEntry ie; + ie._flags = IMGFLAG_UNSCALED; + ie._spritesPtr = _vm->_objectsTable[61]; + ie._frameNumber = buf[(idx / 2)]; + ie._position = Common::Point(_antPos.x, _antPos.y); + ie._offsetY = _antPos.y - 70; + _vm->_images.addToList(ie); + _antCel = idx; + + if (_vm->_flags[196] != 1) { + idx = _pitCel; + if (_stabFl == 1) { + idx = antHandleStab(idx, buf); + } + else { + buf = Amazon::PITWALK; + if (_vm->_timers[13]._flag == 0) { + _vm->_timers[13]._flag = 1; + _vm->_events->pollEvents(); + if (_vm->_events->_leftButton) { + Common::Point pt = _vm->_events->calcRawMouse(); + if (pt.x < _pitPos.x) + idx = antHandleLeft(idx, buf); + else if (pt.x > _pitPos.x) + idx = antHandleRight(idx, buf); + } + else { + buf = Amazon::PITWALK; + if (_vm->_player->_playerDirection == UP) + idx = antHandleStab(idx, buf); + else if (_vm->_player->_playerDirection == LEFT) + idx = antHandleLeft(idx, buf); + else if (_vm->_player->_playerDirection == RIGHT) + idx = antHandleRight(idx, buf); + } + } + } + plotPit(idx, buf); + } + + if (!_antDieFl) { + int dist = _pitPos.x - _antPos.x; + if ((_antEatFl && (dist <= 45)) || (!_antEatFl && (dist <= 80))) { + _vm->_flags[199] = 1; + _vm->_aniFlag = 0; + } + } +} + +} // End of namespace Amazon + +} // End of namespace Access diff --git a/engines/access/amazon/amazon_logic.h b/engines/access/amazon/amazon_logic.h new file mode 100644 index 0000000000..4d5e274388 --- /dev/null +++ b/engines/access/amazon/amazon_logic.h @@ -0,0 +1,228 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ACCESS_AMAZON_LOGIC_H +#define ACCESS_AMAZON_LOGIC_H + +#include "common/scummsys.h" +#include "access/scripts.h" +#include "access/asurface.h" + +namespace Access { + +namespace Amazon { + +class AmazonEngine; + +#define PAN_SIZE 32 + +class AmazonManager { +protected: + AmazonEngine *_vm; +public: + AmazonManager(AmazonEngine *vm) : _vm(vm) {} +}; + +class PannedScene: public AmazonManager { + struct PanEntry { + SpriteResource *_pObject; + int _pImgNum; + int _pObjX; + int _pObjY; + int _pObjZ; + int _pObjXl; + int _pObjYl; + }; +protected: + int _xCount; + int _xTrack; + int _yTrack; + int _zTrack; + int _xCam; + int _yCam; + int _zCam; + int _pNumObj; + int _screenVertX; + + PanEntry _pan[PAN_SIZE]; +public: + PannedScene(AmazonEngine *vm); + + void pan(); +}; + +class Opening: public PannedScene { +public: + Opening(AmazonEngine *vm); + + void mWhileDoOpen(); +}; + +class Plane: public PannedScene { +public: + int _pCount; + Common::Point _position; + int _planeCount; + int _propCount; + + void doFlyCell(); + void doFallCell(); + void scrollFly(); + void scrollFall(); + void mWhileFly(); + void mWhileFall(); +public: + Plane(AmazonEngine *vm); +}; + +#define JUNGLE_SIZE 3 +class Jungle: public PannedScene { +private: + void initJWalk2(); + void jungleMove(); + void scrollJWalk(); + + int _jCnt[JUNGLE_SIZE]; + int _jungleX[JUNGLE_SIZE]; +public: + Jungle(AmazonEngine *vm); + + void mWhileJWalk(); + void mWhileJWalk2(); +}; + +class Guard : public PannedScene { +private: + int _guardCel; + Common::Point _position; + int _gCode1; + int _gCode2; + Common::Point _topLeft; + Common::Point _bottomRight; + int _xMid, _yMid; + + void chkVLine(); + void chkHLine(); + void setVerticalCode(); + void setHorizontalCode(); + void guardSee(); + void setGuardFrame(); +public: + Guard(AmazonEngine *vm); + + void doGuard(); + + void setPosition(const Common::Point &pt); +}; + +class Cast : public PannedScene { +public: + Cast(AmazonEngine *vm); + + void doCast(int param1); +}; + +class River: public PannedScene { +private: + bool _CHICKENOUTFLG; + const byte *_mapPtr; + int _canoeVXPos; + int _canoeMoveCount; + int _canoeFrame; + RiverStruct *_topList; + RiverStruct *_botList; + int _canoeDir; + + // Saved fields + int _canoeLane; + int _canoeYPos; + int _hitCount; + int _riverIndex; + int _hitSafe; + int _rScrollRow; + int _rScrollCol; + int _rScrollX; + int _rScrollY; + int _rOldRectCount; + int _rNewRectCount; + int _rKeyFlag; + int _mapOffset; + int _screenVirtX; + + void initRiver(); + void resetPositions(); + void checkRiverPan(); + bool riverJumpTest(); + void riverSound(); + void moveCanoe(); + void moveCanoe2(); + void updateObstacles(); + void riverSetPhysX(); + bool checkRiverCollide(); + void plotRiver(); + void scrollRiver(); + void scrollRiver1(); + void setRiverPan(); +public: + River(AmazonEngine *vm); + + void river(); + void mWhileDownRiver(); + + void synchronize(Common::Serializer &s); +}; + +class Ant: public AmazonManager { +private: + Direction _antDirection; + Direction _pitDirection; + int _antCel; + int _torchCel; + int _pitCel; + int _stabCel; + Common::Point _antPos; + bool _antDieFl; + bool _antEatFl; + bool _stabFl; + Common::Point _pitPos; + + void plotTorchSpear(int indx, const int *&buf); + void plotPit(int indx, const int *&buf); + int antHandleRight(int indx, const int *&buf); + int antHandleLeft(int indx, const int *&buf); + int antHandleStab(int indx, const int *&buf); +public: + Ant(AmazonEngine *vm); + + void doAnt(); +}; + +class InactivePlayer : public ImageEntry { +public: + SpriteResource *_altSpritesPtr; +}; + +} // End of namespace Amazon + +} // End of namespace Access + +#endif /* ACCESS_AMAZON_LOGIC_H */ diff --git a/engines/access/amazon/amazon_player.cpp b/engines/access/amazon/amazon_player.cpp index ede7ab58e2..c9b63a9108 100644 --- a/engines/access/amazon/amazon_player.cpp +++ b/engines/access/amazon/amazon_player.cpp @@ -77,7 +77,7 @@ void AmazonPlayer::load() { _diagUpWalkMax = 5; _diagDownWalkMin = 0; _diagDownWalkMax = 5; - _game->_guard._position = Common::Point(56, 190); + _game->_guard.setPosition(Common::Point(56, 190)); } } diff --git a/engines/access/amazon/amazon_resources.cpp b/engines/access/amazon/amazon_resources.cpp index 05e234aefc..0ae7ef0718 100644 --- a/engines/access/amazon/amazon_resources.cpp +++ b/engines/access/amazon/amazon_resources.cpp @@ -1776,6 +1776,68 @@ const int HELP1COORDS[2][4] = { { 76, 129, 168, 183 }, { 187, 240, 168, 183 } }; +const int RIVER1OBJ[23][4] = { + { 18, -77, 0, 30 }, + { 18, -325, 0, 20 }, + { 18, -450, 0, 15 }, + { 18, -1250, 0, 25 }, + { 19, -130, 0, 20 }, + { 19, -410, 0, 15 }, + { 19, -710, 0, 25 }, + { 19, -1510, 0, 20 }, + { 20, -350, 0, 30 }, + { 20, -695, 0, 25 }, + { 20, -990, 0, 20 }, + { 20, -1300, 0, 25 }, + { 20, -1600, 0, 30 }, + { 21, -370, 0, 20 }, + { 21, -650, 0, 30 }, + { 21, -1215, 0, 40 }, + { 21, -1815, 0, 35 }, + { 22, -380, 0, 25 }, + { 22, -720, 0, 35 }, + { 22, -1020, 0, 30 }, + { 22, -1170, 0, 25 }, + { 22, -1770, 0, 35 }, + { 23, -500, 63, 20 } +}; + +const int CAST_END_OBJ[26][4] = { + { 0, 118, 210, 10 }, + { 1, 38, 250, 10 }, + { 2, 38, 280, 10 }, + { 3, 38, 310, 10 }, + { 4, 38, 340, 10 }, + { 5, 38, 370, 10 }, + { 6, 38, 400, 10 }, + { 7, 38, 430, 10 }, + { 8, 38, 460, 10 }, + { 9, 38, 490, 10 }, + { 10, 38, 520, 10 }, + { 11, 38, 550, 10 }, + { 12, 38, 580, 10 }, + { 13, 38, 610, 10 }, + { 14, 38, 640, 10 }, + { 15, 38, 670, 10 }, + { 16, 38, 700, 10 }, + { 17, 38, 730, 10 }, + { 18, 38, 760, 10 }, + { 19, 38, 790, 10 }, + { 20, 95, 820, 10 }, + { 21, 94, 850, 10 }, + { 22, 96, 880, 10 }, + { 23, 114, 910, 10 }, + { 24, 114, 940, 10 }, + { 25, 110, 970, 10 } +}; + +const int CAST_END_OBJ1[4][4] = { + { 0, 40, 1100, 10 }, + { 2, 11, 1180, 10 }, + { 1, 154, 1180, 10 }, + { 3, 103, 1300, 10 } +}; + } // End of namespace Amazon } // End of namespace Access diff --git a/engines/access/amazon/amazon_resources.h b/engines/access/amazon/amazon_resources.h index 6d94e6a359..61659d30d4 100644 --- a/engines/access/amazon/amazon_resources.h +++ b/engines/access/amazon/amazon_resources.h @@ -128,6 +128,12 @@ extern RiverStruct ENDRIVER2[1]; extern RiverStruct *RIVEROBJECTTBL[6]; extern const int HELP1COORDS[2][4]; +extern const int RIVER1OBJ[23][4]; + +extern const int CAST_END_OBJ[26][4]; + +extern const int CAST_END_OBJ1[4][4]; + } // End of namespace Amazon } // End of namespace Access diff --git a/engines/access/amazon/amazon_room.cpp b/engines/access/amazon/amazon_room.cpp index ca0d7bf341..14514c2c7c 100644 --- a/engines/access/amazon/amazon_room.cpp +++ b/engines/access/amazon/amazon_room.cpp @@ -205,7 +205,8 @@ void AmazonRoom::walkCursor() { // the Exit icon wgeb the cursor is already a walk cursor EventsManager &events = *_vm->_events; - if (_vm->_player->_roomNumber == 29 && events._normalMouse != CURSOR_CROSSHAIRS) { + if (_vm->_events->_middleButton || (_vm->_player->_roomNumber == 29 && + events._normalMouse != CURSOR_CROSSHAIRS)) { events._normalMouse = CURSOR_CROSSHAIRS; events.setCursor(CURSOR_CROSSHAIRS); _selectCommand = -1; diff --git a/engines/access/amazon/amazon_scripts.cpp b/engines/access/amazon/amazon_scripts.cpp index 58491250ad..d6a57d7919 100644 --- a/engines/access/amazon/amazon_scripts.cpp +++ b/engines/access/amazon/amazon_scripts.cpp @@ -33,28 +33,6 @@ namespace Amazon { AmazonScripts::AmazonScripts(AccessEngine *vm) : Scripts(vm) { _game = (AmazonEngine *)_vm; - - _xTrack = 0; - _yTrack = 0; - _zTrack = 0; - _xCam = 0; - _yCam = 0; - _zCam = 0; - _CHICKENOUTFLG = false; - - _pNumObj = 0; - for (int i = 0; i < 32; i++) { - _pImgNum[i] = 0; - _pObject[i] = nullptr; - _pObjX[i] = 0; - _pObjY[i] = 0; - _pObjZ[i] = 0; - } - - for (int i = 0; i < 16; i++) { - _pObjXl[i] = 0; - _pObjYl[i] = 0; - } } void AmazonScripts::cLoop() { @@ -227,662 +205,31 @@ void AmazonScripts::mWhile2() { } while (_vm->_flags[52] == 4); } -void AmazonScripts::initJWalk2() { - const int JUNGLE1OBJ[7][4] = { - {2, 470, 0, 20}, - {0, 290, 0, 50}, - {1, 210, 0, 40}, - {0, 500, 0, 30}, - {1, 550, 0, 20}, - {0, 580, 0, 60}, - {1, 650, 0, 30} - }; - _vm->_screen->fadeOut(); - _vm->_events->hideCursor(); - _vm->_screen->clearScreen(); - _vm->_buffer2.clearBuffer(); - _vm->_screen->setBufferScan(); - - _vm->_screen->_scrollX = _vm->_screen->_scrollY; - _vm->_screen->_scrollCol = _vm->_screen->_scrollRow; - _vm->_room->buildScreen(); - _vm->copyBF2Vid(); - _vm->_screen->fadeIn(); - // KEYFL = 0; - - _game->_plane._xCount = 2; - _vm->_player->_scrollAmount = 5; - _xTrack = -10; - _yTrack = _zTrack = 0; - _xCam = 480; - _yCam = 0; - _zCam = 80; - - _game->_timers[24]._timer = 1; - _game->_timers[24]._initTm = 1; - ++_game->_timers[24]._flag; - - _pNumObj = 7; - for (int i = 0; i < _pNumObj; i++) { - _pObject[i] = _vm->_objectsTable[24]; - _pImgNum[i] = JUNGLE1OBJ[i][0]; - _pObjX[i] = JUNGLE1OBJ[i][1]; - _pObjY[i] = JUNGLE1OBJ[i][2]; - _pObjZ[i] = JUNGLE1OBJ[i][3]; - _pObjXl[i] = _pObjYl[i] = 0; - } - - _jCnt[0] = 0; - _jCnt[1] = 3; - _jCnt[2] = 5; - - _jungleX[0] = 50; - _jungleX[1] = 16; - _jungleX[2] = 93; -} - -void AmazonScripts::jungleMove() { - const static int jungleY[3] = {27, 30, 29}; - int count = 1; - int frameOffset = 0; - - if (!_vm->_timers[0]._flag) { - ++_vm->_timers[0]._flag; - _vm->_screen->_scrollX += _vm->_player->_scrollAmount; - - for (int i = 0; i < 3; ++i) { - int newJCnt = (_jCnt[i] + 1) % 8; - _jCnt[i] = newJCnt; - _jungleX[i] += 5; - } - - frameOffset = 4; - count = (_game->_allenFlag != 1) ? 2 : 3; - } - - for (int i = 0; i < count; ++i) { - ImageEntry ie; - ie._flags = IMGFLAG_UNSCALED; - ie._spritesPtr = _vm->_objectsTable[24]; - ie._frameNumber = _jCnt[i] + frameOffset; - ie._position = Common::Point(_jungleX[i], jungleY[i]); - ie._offsetY = jungleY[i]; - - _vm->_images.addToList(ie); - frameOffset += 8; - } -} - -void AmazonScripts::mWhileJWalk2() { - Screen &screen = *_vm->_screen; - - initJWalk2(); - - while (!_vm->shouldQuit() && !_vm->_events->isKeyMousePressed() && - (screen._scrollCol + screen._vWindowWidth) != _vm->_room->_playFieldWidth) { - _vm->_images.clear(); - _vm->_events->_vbCount = 6; - _pImgNum[0] = _game->_plane._xCount; - - jungleMove(); - while (screen._scrollX >= TILE_WIDTH) { - screen._scrollX -= TILE_WIDTH; - ++screen._scrollCol; - _vm->_buffer1.moveBufferLeft(); - _vm->_room->buildColumn(screen._scrollCol + screen._vWindowWidth, screen._vWindowBytesWide); - } - - if (_game->_plane._xCount == 2) - ++_game->_plane._xCount; - else - --_game->_plane._xCount; - - pan(); - scrollJWalk(); - - while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0) { - _vm->_events->pollEventsAndWait(); - } - } - - _vm->_events->showCursor(); -} - -void AmazonScripts::doFlyCell() { - Plane &plane = _game->_plane; - SpriteResource *sprites = _vm->_objectsTable[15]; - - if (plane._pCount <= 40) { - _vm->_buffer2.plotImage(sprites, 3, Common::Point(70, 74)); - } else if (plane._pCount <= 80) { - _vm->_buffer2.plotImage(sprites, 6, Common::Point(70, 74)); - } else if (plane._pCount <= 120) { - _vm->_buffer2.plotImage(sprites, 2, Common::Point(50, 76)); - } else if (plane._pCount <= 160) { - _vm->_buffer2.plotImage(sprites, 14, Common::Point(63, 78)); - } else if (plane._pCount <= 200) { - _vm->_buffer2.plotImage(sprites, 5, Common::Point(86, 74)); - } else if (plane._pCount <= 240) { - _vm->_buffer2.plotImage(sprites, 0, Common::Point(103, 76)); - } else if (plane._pCount <= 280) { - _vm->_buffer2.plotImage(sprites, 4, Common::Point(119, 77)); - } else { - _vm->_buffer2.plotImage(sprites, 1, Common::Point(111, 77)); - } - - if (plane._planeCount == 11 || plane._planeCount == 12) - ++plane._position.y; - else if (plane._planeCount >= 28) - --plane._position.y; - - _vm->_buffer2.plotImage(sprites, 7, plane._position); - _vm->_buffer2.plotImage(sprites, 8 + plane._propCount, Common::Point( - plane._position.x + 99, plane._position.y + 10)); - _vm->_buffer2.plotImage(sprites, 11 + plane._propCount, Common::Point( - plane._position.x + 104, plane._position.y + 18)); - - if (++plane._planeCount >= 30) - plane._planeCount = 0; - if (++plane._propCount >= 3) - plane._propCount = 0; - - ++plane._xCount; - if (plane._xCount == 1) - ++plane._position.x; - else - plane._xCount = 0; -} - -void AmazonScripts::doFallCell() { - if (_vm->_scaleI <= 20) - return; - - SpriteFrame *frame = _vm->_objectsTable[20]->getFrame(_game->_plane._planeCount / 6); - Common::Rect r(115, 11, 115 + _vm->_screen->_scaleTable1[frame->w], - 11 + _vm->_screen->_scaleTable1[frame->h]); - _vm->_buffer2.sPlotF(frame, r); - - _vm->_scaleI -= 3; - _vm->_scale = _vm->_scaleI; - _vm->_screen->setScaleTable(_vm->_scale); - ++_game->_plane._xCount; - if (_game->_plane._xCount == 5) - return; - _game->_plane._xCount = 0; - if (_game->_plane._planeCount == 18) - _game->_plane._planeCount = 0; - else - _game->_plane._planeCount += 6; -} - -void AmazonScripts::pan() { - _zCam += _zTrack; - _xCam += _xTrack; - int tx = (_xTrack << 8) / _zCam; - _yCam += _yTrack; - int ty = (_yTrack << 8) / _zCam; - - if (_vm->_timers[24]._flag != 1) { - ++_vm->_timers[24]._flag; - for (int i = 0; i < _pNumObj; i++) { - _pObjZ[i] += _zTrack; - _pObjXl[i] += (_pObjZ[i] * tx) & 0xff; - _pObjX[i] += ((_pObjZ[i] * tx) >> 8) + (_pObjXl[i] >> 8); - _pObjXl[i] &= 0xff; - - _pObjYl[i] += (_pObjZ[i] * ty) & 0xff; - _pObjY[i] += ((_pObjZ[i] * ty) >> 8) + (_pObjYl[i] >> 8); - _pObjYl[i] &= 0xff; - } - } - - for (int i = 0; i < _pNumObj; i++) { - ImageEntry ie; - ie._flags = IMGFLAG_UNSCALED; - ie._position = Common::Point(_pObjX[i], _pObjY[i]); - ie._offsetY = 255; - ie._spritesPtr = _pObject[i]; - ie._frameNumber = _pImgNum[i]; - - _vm->_images.addToList(ie); - } -} - -void AmazonScripts::scrollFly() { - _vm->copyBF1BF2(); - _vm->_newRects.clear(); - doFlyCell(); - _vm->copyRects(); - _vm->copyBF2Vid(); -} - -void AmazonScripts::scrollFall() { - _vm->copyBF1BF2(); - _vm->_newRects.clear(); - doFallCell(); - _vm->copyRects(); - _vm->copyBF2Vid(); -} - -void AmazonScripts::scrollJWalk() { - _vm->copyBF1BF2(); - _vm->_newRects.clear(); - _game->plotList(); - _vm->copyRects(); - _vm->copyBF2Vid(); -} - -void AmazonScripts::mWhileFly() { - Screen &screen = *_vm->_screen; - Player &player = *_vm->_player; - EventsManager &events = *_vm->_events; - Plane &plane = _game->_plane; - - events.hideCursor(); - screen.clearScreen(); - screen.setBufferScan(); - screen.fadeOut(); - screen._scrollX = 0; - - _vm->_room->buildScreen(); - _vm->copyBF2Vid(); - screen.fadeIn(); - _vm->_oldRects.clear(); - _vm->_newRects.clear(); - - // KEYFLG = 0; - - screen._scrollRow = screen._scrollCol = 0; - screen._scrollX = screen._scrollY = 0; - player._rawPlayer = Common::Point(0, 0); - player._scrollAmount = 1; - - plane._pCount = 0; - plane._planeCount = 0; - plane._propCount = 0; - plane._xCount = 0; - plane._position = Common::Point(20, 29); - - while (!_vm->shouldQuit() && !events.isKeyMousePressed() && - ((screen._scrollCol + screen._vWindowWidth) != _vm->_room->_playFieldWidth)) { - events._vbCount = 4; - screen._scrollX += player._scrollAmount; - - while (screen._scrollX >= TILE_WIDTH) { - screen._scrollX -= TILE_WIDTH; - ++screen._scrollCol; - - _vm->_buffer1.moveBufferLeft(); - _vm->_room->buildColumn(screen._scrollCol + screen._vWindowWidth, screen._vWindowBytesWide); - } - - scrollFly(); - ++plane._pCount; - - while (!_vm->shouldQuit() && events._vbCount > 0) { - // To be rewritten when NEWTIMER is done - events.checkForNextFrameCounter(); - _vm->_sound->playSound(0); - - events.pollEventsAndWait(); - } - } - - events.showCursor(); -} - -void AmazonScripts::mWhileFall() { - Screen &screen = *_vm->_screen; - EventsManager &events = *_vm->_events; - - events.hideCursor(); - screen.clearScreen(); - screen.setBufferScan(); - screen.fadeOut(); - screen._scrollX = 0; - - _vm->_room->buildScreen(); - _vm->copyBF2Vid(); - screen.fadeIn(); - _vm->_oldRects.clear(); - _vm->_newRects.clear(); - - // KEYFLG = 0; - - screen._scrollRow = screen._scrollCol = 0; - screen._scrollX = screen._scrollY = 0; - _vm->_player->_scrollAmount = 3; - _vm->_scaleI = 255; - - _game->_plane._xCount = 0; - _game->_plane._planeCount = 0; - - while (!_vm->shouldQuit() && !events.isKeyMousePressed() && - (screen._scrollCol + screen._vWindowWidth != _vm->_room->_playFieldWidth)) { - events._vbCount = 4; - screen._scrollX += _vm->_player->_scrollAmount; - - while (screen._scrollX >= TILE_WIDTH) { - screen._scrollX -= TILE_WIDTH; - ++screen._scrollCol; - - _vm->_buffer1.moveBufferLeft(); - _vm->_room->buildColumn(screen._scrollCol + screen._vWindowWidth, screen._vWindowBytesWide); - } - - scrollFall(); - - while (!_vm->shouldQuit() && events._vbCount > 0) { - events.pollEventsAndWait(); - } - } - - events.showCursor(); -} - -void AmazonScripts::mWhileJWalk() { - Screen &screen = *_vm->_screen; - EventsManager &events = *_vm->_events; - Player &player = *_vm->_player; - - static const int JUNGLE_OBJ[7][4] = { - {2, 77, 0, 40}, - {0, 290, 0, 50}, - {1, 210, 0, 70}, - {0, 50, 0, 30}, - {1, 70, 0, 20}, - {0, -280, 0, 60}, - {1, -150, 0, 30}, - }; - - screen.fadeOut(); - events.hideCursor(); - screen.clearScreen(); - _vm->_buffer2.clearBuffer(); - screen.setBufferScan(); - screen._scrollX = 0; - - // Build the initial jungle scene and fade it in - _vm->_room->buildScreen(); - _vm->copyBF2Vid(); - screen.fadeIn(); - - // Set up the player to walk horizontally - player._xFlag = 1; - player._yFlag = 0; - player._moveTo.x = 160; - player._playerMove = true; - - _game->_plane._xCount = 2; - _xTrack = 10; - _yTrack = _zTrack = 0; - _xCam = 480; - _yCam = 0; - _zCam = 80; - - TimerEntry *te = &_vm->_timers[24]; - te->_initTm = te->_timer = 1; - te->_flag++; - - _pNumObj = 7; - for (int i = 0; i < _pNumObj; i++) { - _pObject[i] = _vm->_objectsTable[24]; - _pImgNum[i] = JUNGLE_OBJ[i][0]; - _pObjX[i] = JUNGLE_OBJ[i][1]; - _pObjY[i] = JUNGLE_OBJ[i][2]; - _pObjZ[i] = JUNGLE_OBJ[i][3]; - _pObjXl[i] = _pObjYl[i] = 0; - } - - while (!_vm->shouldQuit() && !events.isKeyMousePressed() && (player._xFlag != 2)) { - _vm->_images.clear(); - events._vbCount = 6; - - _pImgNum[0] = _game->_plane._xCount; - if (_game->_plane._xCount == 2) - ++_game->_plane._xCount; - else - --_game->_plane._xCount; - - player.checkMove(); - player.checkScroll(); - pan(); - scrollJWalk(); - - while (!_vm->shouldQuit() && events._vbCount > 0) { - events.pollEventsAndWait(); - } - } - - _vm->_images.clear(); - events.showCursor(); -} - -void AmazonScripts::mWhileDoOpen() { - Screen &screen = *_vm->_screen; - EventsManager &events = *_vm->_events; - - screen.setBufferScan(); - events.hideCursor(); - screen.forceFadeOut(); - _game->_skipStart = false; - if (_vm->_conversation != 2) { - // Cutscene at start of chapter 1 - screen.setPanel(3); - _game->startChapter(1); - _game->establishCenter(0, 1); - } - - Resource *data = _vm->_files->loadFile(1, 0); - _vm->_objectsTable[1] = new SpriteResource(_vm, data); - delete data; - - _vm->_files->_setPaletteFlag = false; - _vm->_files->loadScreen(1, 2); - _vm->_buffer2.copyFrom(*_vm->_screen); - _vm->_buffer1.copyFrom(*_vm->_screen); - - // Load animation data - _vm->_animation->freeAnimationData(); - Resource *animResource = _vm->_files->loadFile(1, 1); - _vm->_animation->loadAnimations(animResource); - delete animResource; - - _xTrack = 8; - _yTrack = -3; - _zTrack = 0; - _xCam = _yCam = 0; - _zCam = 270; - _vm->_timers[24]._timer = _vm->_timers[24]._initTm = 1; - ++_vm->_timers[24]._flag; - _vm->_timers.updateTimers(); - - _pNumObj = 10; - for (int i = 0; i < _pNumObj; i++) { - _pObject[i] = _vm->_objectsTable[1]; - _pImgNum[i] = OPENING_OBJS[i][0]; - _pObjX[i] = OPENING_OBJS[i][1]; - _pObjY[i] = OPENING_OBJS[i][2]; - _pObjZ[i] = OPENING_OBJS[i][3]; - _pObjXl[i] = _pObjYl[i] = 0; - } - - _vm->_oldRects.clear(); - _vm->_newRects.clear(); - Animation *anim = _vm->_animation->setAnimation(0); - _vm->_animation->setAnimTimer(anim); - anim = _vm->_animation->setAnimation(1); - _vm->_animation->setAnimTimer(anim); - _vm->_sound->newMusic(10, 0); - - bool startFl = false; - while (!_vm->shouldQuit()) { - _vm->_images.clear(); - _vm->_animation->animate(0); - _vm->_animation->animate(1); - pan(); - _vm->_buffer2.copyFrom(_vm->_buffer1); - _vm->_newRects.clear(); - _game->plotList(); - _vm->copyBlocks(); - if (!startFl) { - startFl = true; - screen.forceFadeIn(); - } - - events.pollEventsAndWait(); - - if (events._leftButton || events._rightButton || events._keypresses.size() > 0) { - _game->_skipStart = true; - _vm->_sound->newMusic(10, 1); - - events.debounceLeft(); - events.zeroKeys(); - break; - } - - if (_xCam > 680) { - events._vbCount = 125; - - while(!_vm->shouldQuit() && !events.isKeyMousePressed() && events._vbCount > 0) { - events.pollEventsAndWait(); - } - break; - } - } - - events.showCursor(); - _vm->_buffer2.copyFrom(*_vm->_screen); - _vm->_buffer1.copyFrom(*_vm->_screen); - - _vm->freeCells(); - _vm->_oldRects.clear(); - _vm->_newRects.clear(); - _vm->_numAnimTimers = 0; - _vm->_images.clear(); - - if (_vm->_conversation == 2) { - // Cutscene at end of Chapter 6 - Resource *spriteData = _vm->_files->loadFile(28, 37); - _vm->_objectsTable[28] = new SpriteResource(_vm, spriteData); - delete spriteData; - - _vm->_animation->freeAnimationData(); - animResource = _vm->_files->loadFile(28, 38); - _vm->_animation->loadAnimations(animResource); - delete animResource; - } -} - -void AmazonScripts::scrollRiver() { - _vm->copyBF1BF2(); - _vm->_newRects.clear(); - _vm->_buffer2.plotImage(_vm->_objectsTable[33], 0, Common::Point(66, 30)); - _vm->plotList(); - _vm->copyRects(); - _vm->copyBF2Vid(); -} - -void AmazonScripts::mWhileDownRiver() { - _vm->_events->hideCursor(); - _vm->_screen->setDisplayScan(); - _vm->_screen->clearScreen(); - _vm->_screen->savePalette(); - - _vm->_files->loadScreen(95, 4); - _vm->_buffer2.copyFrom(*_vm->_screen); - _vm->_screen->restorePalette(); - _vm->_screen->setPalette(); - _vm->_screen->setBufferScan(); - _vm->_screen->_scrollX = 0; - _vm->_room->buildScreen(); - _vm->copyBF2Vid(); - - _vm->_player->_scrollAmount = 2; - _vm->_destIn = &_vm->_buffer2; - _xTrack = -7; - _yTrack = _zTrack = 0; - _xCam = _yCam = 0; - _zCam = 80; - - _game->_timers[24]._timer = 1; - _game->_timers[24]._initTm = 1; - ++_game->_timers[24]._flag; - - _pNumObj = 14; - for (int i = 0; i <_pNumObj; i++) { - _pObject[i] = _vm->_objectsTable[33]; - _pImgNum[i] = DOWNRIVEROBJ[i][0]; - _pObjX[i] = DOWNRIVEROBJ[i][1]; - _pObjY[i] = DOWNRIVEROBJ[i][2]; - _pObjZ[i] = DOWNRIVEROBJ[i][3]; - _pObjXl[i] = _pObjYl[i] = 0; - } - - _game->_timers[3]._timer = 200; - _game->_timers[3]._initTm = 200; - ++_game->_timers[3]._flag; - _game->_timers[4]._timer = 350; - _game->_timers[4]._initTm = 350; - ++_game->_timers[4]._flag; - - while (!_vm->shouldQuit() && !_vm->_events->isKeyMousePressed() && - (_vm->_screen->_scrollCol + _vm->_screen->_vWindowWidth != _vm->_room->_playFieldWidth)) { - _vm->_images.clear(); - _vm->_events->_vbCount = 6; - - _vm->_screen->_scrollX += _vm->_player->_scrollAmount; - while (_vm->_screen->_scrollX >= TILE_WIDTH) { - _vm->_screen->_scrollX -= TILE_WIDTH; - ++_vm->_screen->_scrollCol; - _vm->_buffer1.moveBufferLeft(); - _vm->_room->buildColumn(_vm->_screen->_scrollCol + _vm->_screen->_vWindowWidth, _vm->_screen->_vWindowBytesWide); - } - - pan(); - scrollRiver(); - - if (!_game->_timers[3]._flag) { - ++_game->_timers[3]._flag; - _vm->_sound->playSound(1); - } else if (!_game->_timers[4]._flag) { - ++_game->_timers[4]._flag; - _vm->_sound->playSound(0); - } - - while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0) { - _vm->_events->pollEventsAndWait(); - } - } - - _vm->_events->showCursor(); -} - void AmazonScripts::mWhile(int param1) { switch(param1) { case 1: mWhile1(); break; case 2: - mWhileFly(); + _game->_plane.mWhileFly(); break; case 3: - mWhileFall(); + _game->_plane.mWhileFall(); break; case 4: - mWhileJWalk(); + _game->_jungle.mWhileJWalk(); break; case 5: - mWhileDoOpen(); + _game->_opening.mWhileDoOpen(); break; case 6: - mWhileDownRiver(); + _game->_river.mWhileDownRiver(); break; case 7: mWhile2(); break; case 8: - mWhileJWalk2(); + _game->_jungle.mWhileJWalk2(); break; default: break; @@ -899,143 +246,6 @@ void AmazonScripts::loadBackground(int param1, int param2) { _vm->_screen->forceFadeIn(); } -void AmazonScripts::doCast(int param1) { - static const int END_OBJ[26][4] = { - { 0, 118, 210, 10}, - { 1, 38, 250, 10}, - { 2, 38, 280, 10}, - { 3, 38, 310, 10}, - { 4, 38, 340, 10}, - { 5, 38, 370, 10}, - { 6, 38, 400, 10}, - { 7, 38, 430, 10}, - { 8, 38, 460, 10}, - { 9, 38, 490, 10}, - {10, 38, 520, 10}, - {11, 38, 550, 10}, - {12, 38, 580, 10}, - {13, 38, 610, 10}, - {14, 38, 640, 10}, - {15, 38, 670, 10}, - {16, 38, 700, 10}, - {17, 38, 730, 10}, - {18, 38, 760, 10}, - {19, 38, 790, 10}, - {20, 95, 820, 10}, - {21, 94, 850, 10}, - {22, 96, 880, 10}, - {23, 114, 910, 10}, - {24, 114, 940, 10}, - {25, 110, 970, 10} - }; - - static const int END_OBJ1[4][4] = { - {0, 40, 1100, 10}, - {2, 11, 1180, 10}, - {1, 154, 1180, 10}, - {3, 103, 1300, 10} - }; - - _vm->_screen->setDisplayScan(); - _vm->_events->hideCursor(); - _vm->_screen->forceFadeOut(); - _vm->_screen->_clipHeight = 173; - _vm->_screen->clearScreen(); - _game->_chapter = 16; - _game->tileScreen(); - _game->updateSummary(param1); - _vm->_screen->setPanel(3); - _game->_chapter = 14; - - Resource *spriteData = _vm->_files->loadFile(91, 0); - _vm->_objectsTable[0] = new SpriteResource(_vm, spriteData); - delete spriteData; - spriteData = _vm->_files->loadFile(91, 1); - _vm->_objectsTable[1] = new SpriteResource(_vm, spriteData); - delete spriteData; - - _vm->_files->_setPaletteFlag = false; - _vm->_files->loadScreen(58, 1); - _vm->_buffer2.copyFrom(*_vm->_screen); - _vm->_buffer1.copyFrom(*_vm->_screen); - - _xTrack = 0; - _yTrack = -6; - _zTrack = 0; - _xCam = _yCam = 0; - _zCam = 60; - - _game->_timers[24]._timer = 1; - _game->_timers[24]._initTm = 1; - ++_game->_timers[24]._flag; - - _pNumObj = 26; - for (int i = 0; i < _pNumObj; i++) { - _pObject[i] = _vm->_objectsTable[0]; - _pImgNum[i] = END_OBJ[i][0]; - _pObjX[i] = END_OBJ[i][1]; - _pObjY[i] = END_OBJ[i][2]; - _pObjZ[i] = END_OBJ[i][3]; - _pObjXl[i] = _pObjYl[i] = 0; - } - - _pNumObj = 4; - for (int i = 0; i < _pNumObj; i++) { - _pObject[26 + i] = _vm->_objectsTable[1]; - _pImgNum[26 + i] = END_OBJ1[i][0]; - _pObjX[26 + i] = END_OBJ1[i][1]; - _pObjY[26 + i] = END_OBJ1[i][2]; - _pObjZ[26 + i] = END_OBJ1[i][3]; - _pObjXl[26 + i] = _pObjYl[26 + i] = 0; - } - - _vm->_oldRects.clear(); - _vm->_newRects.clear(); - _vm->_numAnimTimers = 0; - - _vm->_sound->newMusic(58, 0); - _vm->_screen->forceFadeIn(); - - while (!_vm->shouldQuit()) { - _vm->_images.clear(); - pan(); - _vm->_buffer2.copyFrom(_vm->_buffer1); - _vm->_newRects.clear(); - _game->plotList(); - _vm->copyBlocks(); - - _vm->_events->pollEvents(); - if (_vm->_events->isKeyMousePressed()) - break; - - if (_yCam < -7550) { - _vm->_events->_vbCount = 50; - - while(!_vm->shouldQuit() && !_vm->_events->isKeyMousePressed() && _vm->_events->_vbCount > 0) { - _vm->_events->pollEventsAndWait(); - } - - while (!_vm->shouldQuit() && !_vm->_sound->checkMidiDone()) - _vm->_events->pollEventsAndWait(); - - break; - } - } - - _vm->_sound->newMusic(58, 1); - _vm->_events->showCursor(); - - _vm->freeCells(); - _vm->_oldRects.clear(); - _vm->_newRects.clear(); - _vm->_numAnimTimers = 0; - _vm->_images.clear(); - _vm->_screen->forceFadeOut(); - - _vm->quitGame(); - _vm->_events->pollEvents(); -} - void AmazonScripts::setInactive() { _game->_rawInactiveX = _vm->_player->_rawPlayer.x; _game->_rawInactiveY = _vm->_player->_rawPlayer.y; @@ -1044,243 +254,6 @@ void AmazonScripts::setInactive() { mWhile(_game->_rawInactiveY); } -void AmazonScripts::plotTorchSpear(int indx, const int *&buf) { - int idx = indx; - - ImageEntry ie; - ie._flags = IMGFLAG_UNSCALED; - ie._spritesPtr = _vm->_objectsTable[62]; - ie._frameNumber = buf[(idx / 2)]; - ie._position = Common::Point(_game->_pitPos.x + buf[(idx / 2) + 1], _game->_pitPos.y + buf[(idx / 2) + 2]); - ie._offsetY = 255; - _vm->_images.addToList(ie); -} - -void AmazonScripts::plotPit(int indx, const int *&buf) { - int idx = indx; - ImageEntry ie; - ie._flags = IMGFLAG_UNSCALED; - ie._spritesPtr = _vm->_objectsTable[62]; - ie._frameNumber = buf[(idx / 2)]; - ie._position = Common::Point(_game->_pitPos.x, _game->_pitPos.y); - ie._offsetY = _game->_pitPos.y; - _vm->_images.addToList(ie); - - _vm->_player->_rawPlayer = _game->_pitPos; - if (_vm->_inventory->_inv[76]._value == 1) { - idx = _game->_torchCel; - buf = Amazon::TORCH; - _vm->_timers[14]._flag = 1; - idx += 6; - if (buf[idx / 2] == -1) - idx = 0; - _game->_torchCel = idx; - plotTorchSpear(idx, buf); - } else if (!_game->_stabFl && (_vm->_inventory->_inv[78]._value == 1)) { - idx = 0; - buf = Amazon::SPEAR; - plotTorchSpear(idx, buf); - } -} - -int AmazonScripts::antHandleRight(int indx, const int *&buf) { - int retval = indx; - if (_game->_pitDirection == NONE) { - _game->_pitDirection = UP; - _game->_pitPos.y = 127; - } - retval = _game->_pitCel; - buf = Amazon::PITWALK; - if (_game->_pitPos.x < 230) { - if (retval == 0) { - retval = 48; - _game->_pitPos.y = 127; - } - retval -= 6; - _game->_pitPos.x -= buf[(retval / 2) + 1]; - _game->_pitPos.y -= buf[(retval / 2) + 2]; - _game->_pitCel = retval; - } - return retval; -} - -int AmazonScripts::antHandleLeft(int indx, const int *&buf) { - int retval = indx; - if (_game->_pitDirection == UP) { - _game->_pitDirection = NONE; - _game->_pitPos.y = 127; - } - retval = _game->_pitCel; - buf = Amazon::PITWALK; - retval += 6; - if (buf[retval / 2] == -1) { - retval = 0; - _game->_pitPos.y = 127; - } - _game->_pitPos.x += buf[(retval / 2) + 1]; - _game->_pitPos.y += buf[(retval / 2) + 2]; - _game->_pitCel = retval; - - return retval; -} - -int AmazonScripts::antHandleStab(int indx, const int *&buf) { - int retval = indx; - if (_vm->_inventory->_inv[78]._value != 1) { - if (_game->_stabFl) { - buf = Amazon::PITSTAB; - retval = _game->_stabCel; - if (_game->_timers[13]._flag == 0) { - _game->_timers[13]._flag = 1; - retval += 6; - if (Amazon::PITSTAB[retval] == -1) { - _game->_stabFl = false; - _game->_pitCel = 0; - _game->_pitPos.y = 127; - retval = 0; - buf = Amazon::PITWALK; - } else { - _game->_pitPos.x += buf[(retval / 2) + 1]; - _game->_pitPos.y += buf[(retval / 2) + 2]; - _game->_pitCel = retval; - } - } - } else { - _game->_stabFl = true; - _game->_pitCel = 0; - retval = 0; - _game->_stabCel = 0; - int dist = _game->_pitPos.x - _game->_antPos.x; - if (_game->_antEatFl && !_game->_antDieFl && (dist <= 80)) { - _game->_antDieFl = true; - _game->_antCel = 0; - _game->_antPos.y = 123; - _vm->_sound->playSound(1); - } - } - } - return retval; -} - -void AmazonScripts::ANT() { - _game->_antDirection = NONE; - if (_game->_aniFlag != 1) { - _game->_aniFlag = 1; - _game->_antCel = 0; - _game->_torchCel = 0; - _game->_pitCel = 0; - - _game->_timers[15]._timer = 16; - _game->_timers[15]._initTm = 16; - _game->_timers[15]._flag = 1; - - _game->_timers[13]._timer = 5; - _game->_timers[13]._initTm = 5; - _game->_timers[13]._flag = 1; - - _game->_timers[14]._timer = 10; - _game->_timers[14]._initTm = 10; - _game->_timers[14]._flag = 1; - - _game->_antPos = Common::Point(-40, 123); - _game->_antDieFl = _game->_antEatFl = false; - _game->_stabFl = false; - _game->_pitPos = Common::Point(_vm->_player->_rawPlayer.x, 127); - } - - const int *buf = nullptr; - if (_game->_antDieFl) { - buf = Amazon::ANTDIE; - } else if (_game->_antEatFl) { - buf = Amazon::ANTEAT; - } else if (_game->_antPos.x > 120 && _vm->_flags[198] == 1) { - _game->_antEatFl = true; - _vm->_flags[235] = 1; - _game->_antCel = 0; - buf = Amazon::ANTEAT; - } else { - buf = Amazon::ANTWALK; - if (_vm->_inventory->_inv[76]._value == 1) - _game->_antDirection = UP; - } - - int idx = _game->_antCel; - if (_game->_timers[15]._flag == 0) { - _game->_timers[15]._flag = 1; - if (_game->_antDirection == UP) { - if (_game->_antPos.x > 10) { - if (idx == 0) - idx = 36; - else - idx -= 6; - - _game->_antPos = Common::Point(buf[(idx / 2) + 1], buf[(idx / 2) + 2]); - _game->_antCel = idx; - } - } else { - idx += 6; - if (buf[(idx / 2)] != -1) { - _game->_antPos = Common::Point(buf[(idx / 2) + 1], buf[(idx / 2) + 2]); - _game->_antCel = idx; - } else if (!_game->_antDieFl) { - idx = 0; - _game->_antPos = Common::Point(buf[(idx / 2) + 1], buf[(idx / 2) + 2]); - _game->_antCel = idx; - } else { - idx -= 6; - if (_game->_flags[200] == 0) - _game->_flags[200] = 1; - } - } - } - - ImageEntry ie; - ie._flags = IMGFLAG_UNSCALED; - ie._spritesPtr = _vm->_objectsTable[61]; - ie._frameNumber = buf[(idx / 2)]; - ie._position = Common::Point(_game->_antPos.x, _game->_antPos.y); - ie._offsetY = _game->_antPos.y - 70; - _vm->_images.addToList(ie); - _game->_antCel = idx; - - if (_game->_flags[196] != 1) { - idx = _game->_pitCel; - if (_game->_stabFl == 1) { - idx = antHandleStab(idx, buf); - } else { - buf = Amazon::PITWALK; - if (_game->_timers[13]._flag == 0) { - _game->_timers[13]._flag = 1; - _vm->_events->pollEvents(); - if (_vm->_events->_leftButton) { - Common::Point pt = _vm->_events->calcRawMouse(); - if (pt.x < _game->_pitPos.x) - idx = antHandleLeft(idx, buf); - else if (pt.x > _game->_pitPos.x) - idx = antHandleRight(idx, buf); - } else { - buf = Amazon::PITWALK; - if (_vm->_player->_playerDirection == UP) - idx = antHandleStab(idx, buf); - else if (_vm->_player->_playerDirection == LEFT) - idx = antHandleLeft(idx, buf); - else if (_vm->_player->_playerDirection == RIGHT) - idx = antHandleRight(idx, buf); - } - } - } - plotPit(idx, buf); - } - - if (!_game->_antDieFl) { - int dist = _game->_pitPos.x - _game->_antPos.x; - if ((_game->_antEatFl && (dist <= 45)) || (!_game->_antEatFl && (dist <= 80))) { - _game->_flags[199] = 1; - _game->_aniFlag = 0; - } - } -} - void AmazonScripts::boatWalls(int param1, int param2) { if (param1 == 1) _vm->_room->_plotter._walls[42] = Common::Rect(96, 27, 96 + 87, 27 + 42); @@ -1339,473 +312,6 @@ void AmazonScripts::plotInactive() { _vm->_images.addToList(_game->_inactive); } -void AmazonScripts::setRiverPan() { - static const int RIVER1OBJ[23][4] = { - {18, -77, 0, 30}, - {18, -325, 0, 20}, - {18, -450, 0, 15}, - {18, -1250, 0, 25}, - {19, -130, 0, 20}, - {19, -410, 0, 15}, - {19, -710, 0, 25}, - {19, -1510, 0, 20}, - {20, -350, 0, 30}, - {20, -695, 0, 25}, - {20, -990, 0, 20}, - {20, -1300, 0, 25}, - {20, -1600, 0, 30}, - {21, -370, 0, 20}, - {21, -650, 0, 30}, - {21, -1215, 0, 40}, - {21, -1815, 0, 35}, - {22, -380, 0, 25}, - {22, -720, 0, 35}, - {22, -1020, 0, 30}, - {22, -1170, 0, 25}, - {22, -1770, 0, 35}, - {23, -500, 63, 20} - }; - - int delta = (_vm->_screen->_scrollCol * 16) + _vm->_screen->_scrollX; - - _xTrack = 9; - _yTrack = _zTrack = 0; - _xCam = 160; - _yCam = 0; - _zCam = 80; - - _game->_timers[24]._timer = 1; - _game->_timers[24]._initTm = 1; - ++_game->_timers[24]._flag; - - _pNumObj = 23; - for (int i = 0; i < _pNumObj; i++) { - _pObject[i] = _vm->_objectsTable[45]; - _pImgNum[i] = RIVER1OBJ[i][0]; - _pObjX[i] = RIVER1OBJ[i][1] + delta; - _pObjY[i] = RIVER1OBJ[i][2]; - _pObjZ[i] = RIVER1OBJ[i][3]; - _pObjXl[i] = _pObjYl[i] = 0; - } -} - -void AmazonScripts::initRiver() { - static const int RIVERVXTBL[3] = {6719, 7039, 8319}; - - _vm->_events->centerMousePos(); - _vm->_events->restrictMouse(); - _vm->_screen->setDisplayScan(); - _vm->_screen->clearScreen(); - _vm->_screen->savePalette(); - _vm->_screen->forceFadeOut(); - - _vm->_files->_setPaletteFlag = false; - _vm->_files->loadScreen(95, 4); - _vm->_buffer2.copyFrom(*_vm->_screen); - - _vm->_screen->restorePalette(); - _vm->_screen->setBufferScan(); - _vm->_destIn = &_vm->_buffer2; - _vm->_room->roomMenu(); - - if (_game->_saveRiver) { - // Restoring a savegame, so set properties from saved fields - _vm->_screen->_scrollRow = _vm->_rScrollRow; - _vm->_screen->_scrollCol = _vm->_rScrollCol; - _vm->_screen->_scrollX = _vm->_rScrollX; - _vm->_screen->_scrollY = _vm->_rScrollY; - } else { - // Set initial scene state - _vm->_screen->_scrollRow = 0; - _vm->_screen->_scrollCol = 140; - _vm->_screen->_scrollX = 0; - _vm->_screen->_scrollY = 0; - } - - _vm->_room->buildScreen(); - _vm->copyBF2Vid(); - _vm->_screen->forceFadeIn(); - - if (_game->_saveRiver) { - // Restore draw rects from savegame - _vm->_oldRects.resize(_vm->_rOldRectCount); - _vm->_newRects.resize(_vm->_rNewRectCount); - // KEYFLG = _vm->_rKeyFlag - } else { - // Reset draw rects - _vm->_oldRects.clear(); - _vm->_newRects.clear(); - // KEYFLG = 0 - } - - _vm->_player->_scrollAmount = 2; - setRiverPan(); - _game->_timers[3]._timer = 1; - _game->_timers[3]._initTm = 1; - ++_game->_timers[3]._flag; - - _game->_canoeFrame = 0; - _game->_mapPtr = (const byte *)MAPTBL[_game->_riverFlag] + 1; - if (_game->_saveRiver) { - _game->_mapPtr--; - _game->_mapPtr += _game->_mapOffset; - } else { - _screenVertX = RIVERVXTBL[_game->_riverFlag] - 320; - _game->_canoeLane = 3; - _game->_hitCount = 0; - _game->_hitSafe = 0; - _game->_canoeYPos = 71; - } - - _game->_riverIndex = _game->_riverFlag; - _game->_topList = RIVEROBJECTTBL[_game->_riverIndex]; - updateObstacles(); - riverSetPhysX(); - _game->_canoeDir = 0; - _game->_deathFlag = 0; - _game->_deathCount = 0; - - _game->_timers[11]._timer = 1200; - _game->_timers[11]._initTm = 1200; - ++_game->_timers[11]._flag; - _game->_timers[12]._timer = 1500; - _game->_timers[12]._initTm = 1500; - ++_game->_timers[12]._flag; - - _game->_maxHits = 2 - _game->_riverFlag; - _game->_saveRiver = false; -} - -void AmazonScripts::resetPositions() { - riverSetPhysX(); - int val = (_vm->_screen->_scrollCol + 1 - _game->_oldScrollCol) * 16; - if (val > 256) { - val &= 0x7F; - val |= 0x80; - } - - for (int i = 0; i < _pNumObj; i++) - _pObjX[i] += val; -} - -void AmazonScripts::checkRiverPan() { - int val = (_vm->_screen->_scrollCol + 20) * 16; - - for (int i = 0; i < _pNumObj; i++) { - if (_pObjX[i] < val) - return; - } - - setRiverPan(); -} - -bool AmazonScripts::riverJumpTest() { - if (_vm->_screen->_scrollCol == 120 || _vm->_screen->_scrollCol == 60 || _vm->_screen->_scrollCol == 0) { - int val = _game->_mapPtr[0]; - ++_game->_mapPtr; - if (val == 0xFF) - return true; - _game->_oldScrollCol = _vm->_screen->_scrollCol; - - if (val == 0) { - _vm->_screen->_scrollCol = 139; - _vm->_screen->_scrollX = 14; - _vm->_room->buildScreen(); - resetPositions(); - return false; - } - } else if (_vm->_screen->_scrollCol == 105) { - int val1 = _game->_mapPtr[1]; - int val2 = _game->_mapPtr[2]; - _game->_mapPtr += 3; - if (_game->_canoeLane < 3) { - if (val1 != 0) { - _game->_deathFlag = true; - _game->_deathCount = 300; - _game->_deathType = val2; - } - } else { - if (val1 != 1) { - _game->_deathFlag = true; - _game->_deathCount = 300; - _game->_deathType = val2; - } - _game->_oldScrollCol = _vm->_screen->_scrollCol; - _vm->_screen->_scrollCol = 44; - _vm->_screen->_scrollX = 14; - _vm->_room->buildScreen(); - resetPositions(); - return false; - } - } - - _vm->_screen->_scrollX = 14; - --_vm->_screen->_scrollCol; - _vm->_buffer1.moveBufferRight(); - _vm->_room->buildColumn(_vm->_screen->_scrollCol, 0); - checkRiverPan(); - return false; -} - -void AmazonScripts::riverSound() { - if (_game->_timers[11]._flag == 0) { - ++_game->_timers[11]._flag; - _vm->_sound->playSound(2); - } - - if (_game->_timers[12]._flag == 0) { - ++_game->_timers[12]._flag; - _vm->_sound->playSound(3); - } - - if ((_xCam >= 1300) && (_xCam <= 1320)) - _vm->_sound->playSound(1); -} - -void AmazonScripts::moveCanoe() { - Screen &screen = *_vm->_screen; - EventsManager &events = *_vm->_events; - Common::Point pt = events.calcRawMouse(); - - // Do an event polling - _vm->_canSaveLoad = true; - events.pollEvents(); - _vm->_canSaveLoad = false; - if (_vm->_room->_function == FN_CLEAR1) - return; - - if (_game->_canoeDir) { - // Canoe movement in progress - moveCanoe2(); - } else { - if (events._leftButton && pt.y >= 140) { - if (pt.x < RMOUSE[8][0]) { - // Disk icon wasn't clicked - printString(BAR_MESSAGE); - } else { - // Clicked on the Disc icon - _game->_saveRiver = true; - _game->_rScrollRow = screen._scrollRow; - _game->_rScrollCol = screen._scrollCol; - _game->_rScrollX = screen._scrollX; - _game->_rScrollY = screen._scrollY; - _game->_mapOffset = _game->_mapPtr - MAPTBL[_game->_riverFlag]; - - // Show the ScummVM menu - _vm->_room->handleCommand(9); - - if (_vm->_room->_function != FN_CLEAR1) { - _game->_saveRiver = false; - _vm->_room->buildScreen(); - _vm->copyBF2Vid(); - } - } - } else if ((events._leftButton && pt.y <= _game->_canoeYPos) || - (!events._leftButton && _vm->_player->_move == UP)) { - // Move canoe up - if (_game->_canoeLane > 0) { - _game->_canoeDir = -1; - _game->_canoeMoveCount = 0; - - moveCanoe2(); - } - } else if (events._leftButton || _vm->_player->_move == DOWN) { - // Move canoe down - if (_game->_canoeLane < 7) { - _game->_canoeDir = 1; - _game->_canoeMoveCount = 0; - - moveCanoe2(); - } - } - } -} - -void AmazonScripts::moveCanoe2() { - _game->_canoeYPos += _game->_canoeDir; - - if (++_game->_canoeMoveCount == 5) { - _game->_canoeLane += _game->_canoeDir; - _game->_canoeDir = 0; - } -} - -void AmazonScripts::updateObstacles() { - RiverStruct *cur; - for (cur = _game->_topList; cur < RIVEROBJECTTBL[_game->_riverIndex + 1]; ++cur) { - int val = cur->_field1 + cur->_field3 - 1; - if (val < _screenVertX) - break; - - if (cur->_field3 < (_game->_screenVirtX + 319)) { - _game->_topList = cur; - _game->_botList = cur; - - while (cur < RIVEROBJECTTBL[_game->_riverIndex + 1]) { - ++cur; - val = cur->_field1 + cur->_field3 - 1; - if (val < _screenVertX || (cur->_field3 >= (_game->_screenVirtX + 319))) - break; - - _game->_botList = cur; - } - - return; - } - } - - cur = _game->_topList; - cur--; - _game->_botList = cur; -} - -void AmazonScripts::riverSetPhysX() { - int val = (_vm->_screen->_scrollCol * 16) + _vm->_screen->_scrollX; - RiverStruct *cur = _game->_topList; - while (cur <= _game->_botList) { - cur[0]._field5 = val - (_screenVertX - cur[0]._field3); - ++cur; - } -} - -bool AmazonScripts::checkRiverCollide() { - if (_game->_hitSafe) - return false; - - _game->_canoeVXPos = _screenVertX + 170; - - for (RiverStruct *si = _game->_topList; si <= _game->_botList; ++si) { - if (si[0]._lane < _game->_canoeLane) - continue; - - if ((si[0]._lane == _game->_canoeLane) || (si[0]._lane == _game->_canoeLane + 1)) { - if (si[0]._field1 + si[0]._field3 - 1 >= _game->_canoeVXPos) { - if (_game->_canoeVXPos + 124 >= si[0]._field3) { - _vm->_sound->playSound(4); - return true; - } - } - } - } - return false; -} - -void AmazonScripts::plotRiver() { - if (_vm->_timers[3]._flag == 0) { - ++_vm->_timers[3]._flag; - if (_game->_canoeFrame == 12) - _game->_canoeFrame = 0; - else - ++_game->_canoeFrame; - } - - ImageEntry ie; - ie._flags = IMGFLAG_UNSCALED; - ie._spritesPtr = _vm->_objectsTable[45]; - ie._frameNumber = _game->_canoeFrame; - ie._position.x = (_vm->_screen->_scrollCol * 16) + _vm->_screen->_scrollX + 160; - ie._position.y = _game->_canoeYPos - 41; - ie._offsetY = 41; - _vm->_images.addToList(ie); - - RiverStruct *cur = _game->_topList; - while (cur <= _game->_botList) { - if (cur[0]._id != -1) { - ie._flags = IMGFLAG_UNSCALED; - ie._spritesPtr = _vm->_objectsTable[45]; - ie._frameNumber = 0; - ie._position.x = cur[0]._field5; - int val = (cur[0]._lane * 5) + 56; - ie._position.y = val - cur[0]._field8; - ie._offsetY = cur[0]._field8; - _vm->_images.addToList(ie); - } - ++cur; - } -} - -void AmazonScripts::scrollRiver1() { - _vm->copyBF1BF2(); - _vm->_newRects.clear(); - plotRiver(); - _vm->plotList(); - _vm->copyRects(); - _vm->copyBF2Vid(); -} - -void AmazonScripts::RIVER() { - static const int RIVERDEATH[5] = {22, 23, 24, 25, 26}; - - initRiver(); - _vm->_events->showCursor(); - - while (!_vm->shouldQuit()) { - _vm->_events->_vbCount = 4; - -// int bx = _vm->_player->_scrollAmount - _screenVertX; - if (_vm->_screen->_scrollX == 0) { - _vm->_sound->midiRepeat(); - if (riverJumpTest()) { - _CHICKENOUTFLG = false; - return; - } - } else { - _vm->_screen->_scrollX -= _vm->_player->_scrollAmount; - } - - if (_CHICKENOUTFLG) { - _CHICKENOUTFLG = false; - return; - } - - _vm->_images.clear(); - _vm->_animation->animate(0); - - riverSound(); - pan(); - moveCanoe(); - - if (_vm->_room->_function != FN_CLEAR1) { - updateObstacles(); - riverSetPhysX(); - bool checkCollide = checkRiverCollide(); - if (_game->_hitSafe != 0) - _game->_hitSafe -= 2; - - if (checkCollide) { - cmdDead(RIVERDEATH[0]); - return; - } - - if (_game->_deathFlag) { - _game->_deathCount--; - if (_game->_deathCount == 0) { - cmdDead(RIVERDEATH[_game->_deathType]); - return; - } - } - - // Scroll the river - scrollRiver1(); - - // Allow time for new scrolled river position to be shown - _vm->_canSaveLoad = true; - while (!_vm->shouldQuit() && _vm->_room->_function == FN_NONE && - _vm->_events->_vbCount > 0) { - _vm->_events->pollEventsAndWait(); - } - _vm->_canSaveLoad = false; - } - - if (_vm->_room->_function == FN_CLEAR1) { - _endFlag = true; - _returnCode = 0; - _CHICKENOUTFLG = false; - break; - } - } -} - void AmazonScripts::executeSpecial(int commandIndex, int param1, int param2) { switch (commandIndex) { case 1: @@ -1815,7 +321,7 @@ void AmazonScripts::executeSpecial(int commandIndex, int param1, int param2) { loadBackground(param1, param2); break; case 3: - doCast(param1); + _game->_cast.doCast(param1); break; case 4: setInactive(); @@ -1824,7 +330,7 @@ void AmazonScripts::executeSpecial(int commandIndex, int param1, int param2) { mWhile(param1); break; case 9: - _game->_guard.guard(); + _game->_guard.doGuard(); break; case 10: _vm->_sound->newMusic(param1, param2); @@ -1833,10 +339,10 @@ void AmazonScripts::executeSpecial(int commandIndex, int param1, int param2) { plotInactive(); break; case 13: - RIVER(); + _game->_river.river(); break; case 14: - ANT(); + _game->_ant.doAnt(); break; case 15: boatWalls(param1, param2); diff --git a/engines/access/amazon/amazon_scripts.h b/engines/access/amazon/amazon_scripts.h index bd47e9ce5b..968d51e2c4 100644 --- a/engines/access/amazon/amazon_scripts.h +++ b/engines/access/amazon/amazon_scripts.h @@ -35,72 +35,15 @@ class AmazonEngine; class AmazonScripts: public Scripts { private: AmazonEngine *_game; - int _xTrack; - int _yTrack; - int _zTrack; - int _xCam; - int _yCam; - int _zCam; - int _pNumObj; - int _screenVertX; - bool _CHICKENOUTFLG; - - SpriteResource *_pObject[32]; - int _pImgNum[32]; - int _pObjX[32]; - int _pObjY[32]; - int _pObjZ[32]; - int _pObjXl[32]; - int _pObjYl[32]; - - int _jCnt[3]; - int _jungleX[3]; - - void pan(); - protected: virtual void executeSpecial(int commandIndex, int param1, int param2); virtual void executeCommand(int commandIndex); - void doFlyCell(); - void doFallCell(); - void scrollFly(); - void scrollFall(); - void scrollJWalk(); void cLoop(); void mWhile1(); void mWhile2(); - void mWhileFly(); - void mWhileFall(); - void mWhileJWalk(); - void initJWalk2(); - void jungleMove(); - void mWhileJWalk2(); - void scrollRiver(); - void mWhileDownRiver(); void mWhile(int param1); - void plotTorchSpear(int indx, const int *&buf); - void plotPit(int indx, const int *&buf); - int antHandleRight(int indx, const int *&buf); - int antHandleLeft(int indx, const int *&buf); - int antHandleStab(int indx, const int *&buf); - void ANT(); - void doCast(int param1); void loadBackground(int param1, int param2); - void initRiver(); - void resetPositions(); - void checkRiverPan(); - bool riverJumpTest(); - void riverSound(); - void moveCanoe(); - void moveCanoe2(); - void updateObstacles(); - void riverSetPhysX(); - bool checkRiverCollide(); - void plotRiver(); - void scrollRiver1(); - void setRiverPan(); - void RIVER(); void plotInactive(); void setInactive(); void boatWalls(int param1, int param2); @@ -114,8 +57,6 @@ protected: void CMDRETFLASH(); public: AmazonScripts(AccessEngine *vm); - - void mWhileDoOpen(); }; } // End of namespace Amazon diff --git a/engines/access/martian/martian_game.h b/engines/access/martian/martian_game.h index a99ece67cf..e46b2bb0fd 100644 --- a/engines/access/martian/martian_game.h +++ b/engines/access/martian/martian_game.h @@ -63,6 +63,8 @@ protected: * Play the game */ virtual void playGame(); + + virtual void dead(int deathId) {} public: MartianEngine(OSystem *syst, const AccessGameDescription *gameDesc); diff --git a/engines/access/module.mk b/engines/access/module.mk index 98464014ba..b6961aeca9 100644 --- a/engines/access/module.mk +++ b/engines/access/module.mk @@ -22,6 +22,7 @@ MODULE_OBJS := \ sound.o \ video.o \ amazon/amazon_game.o \ + amazon/amazon_logic.o \ amazon/amazon_player.o \ amazon/amazon_resources.o \ amazon/amazon_room.o \ diff --git a/engines/access/player.cpp b/engines/access/player.cpp index b945b76600..2313ed266e 100644 --- a/engines/access/player.cpp +++ b/engines/access/player.cpp @@ -751,7 +751,7 @@ bool Player::scrollDown() { bool Player::scrollLeft() { Screen &screen = *_vm->_screen; _scrollAmount = -(screen._clipWidth - _playerX - _scrollThreshold); - if ((_vm->_rScrollCol + screen._vWindowWidth) == _vm->_room->_playFieldWidth) { + if ((screen._scrollCol + screen._vWindowWidth) == _vm->_room->_playFieldWidth) { _scrollEnd = 2; screen._scrollX = 0; _scrollFlag = true; diff --git a/engines/access/scripts.cpp b/engines/access/scripts.cpp index 72650f472c..add461eb81 100644 --- a/engines/access/scripts.cpp +++ b/engines/access/scripts.cpp @@ -784,76 +784,9 @@ void Scripts::cmdPlayerOn() { _vm->_player->_playerOff = false; } -void Scripts::cmdDead(int deathId) { - _vm->_events->hideCursor(); - _vm->_screen->forceFadeOut(); - cmdFreeSound(); - - _vm->_sound->_soundTable.push_back(SoundEntry(_vm->_files->loadFile(98, 44), 1)); - - _vm->_screen->clearScreen(); - _vm->_screen->setPanel(3); - - if (deathId != 10) { - _vm->_sound->newMusic(62, 0); - _vm->_files->_setPaletteFlag = false; - _vm->_files->loadScreen(94, 0); - _vm->_files->_setPaletteFlag = true; - _vm->_buffer2.copyFrom(*_vm->_screen); - - for (int i = 0; i < 3; ++i) { - _vm->_sound->playSound(0); - _vm->_screen->forceFadeIn(); - _vm->_sound->playSound(0); - _vm->_screen->forceFadeOut(); - } - _vm->freeCells(); - - // Load the cell list for the death screen - DeathEntry &de = _vm->_deaths[deathId]; - Common::Array<CellIdent> cells; - cells.push_back(_vm->_deaths._cells[de._screenId]); - _vm->loadCells(cells); - - _vm->_screen->setDisplayScan(); - _vm->_files->_setPaletteFlag = false; - _vm->_files->loadScreen(&_vm->_buffer2, 94, 1); - _vm->_screen->setIconPalette(); - - _vm->_buffer2.plotImage(_vm->_objectsTable[0], 0, Common::Point(105, 25)); - _vm->_buffer2.copyTo(_vm->_screen); - _vm->_screen->forceFadeIn(); - - _vm->_fonts._charSet._hi = 10; - _vm->_fonts._charSet._lo = 1; - _vm->_fonts._charFor._lo = 55; - _vm->_fonts._charFor._hi = 255; - _vm->_screen->_maxChars = 46; - _vm->_screen->_printOrg = Common::Point(20, 155); - _vm->_screen->_printStart = Common::Point(20, 155); - - Common::String &msg = de._msg; - _vm->_printEnd = 180; - _vm->printText(_vm->_screen, msg); - _vm->_screen->forceFadeOut(); - - _vm->_sound->newMusic(0, 1); - _vm->_events->showCursor(); - _vm->_room->clearRoom(); - _vm->freeChar(); - - warning("TODO: restart game"); - _vm->quitGame(); - _vm->_events->pollEvents(); - } else { - _vm->quitGame(); - _vm->_events->pollEvents(); - } -} - void Scripts::cmdDead() { int deathId = _data->readByte(); - cmdDead(deathId); + _vm->dead(deathId); } void Scripts::cmdFadeOut() { diff --git a/engines/access/scripts.h b/engines/access/scripts.h index b6a3dc4dd9..098fd4f322 100644 --- a/engines/access/scripts.h +++ b/engines/access/scripts.h @@ -48,11 +48,6 @@ protected: virtual void executeCommand(int commandIndex); /** - * Print a given message to the screen in a bubble box - */ - void printString(const Common::String &msg); - - /** * Read a null terminated string from the script */ Common::String readString(); @@ -120,7 +115,6 @@ protected: void cmdPlayerOff(); void cmdPlayerOn(); void cmdDead(); - void cmdDead(int deathId); void cmdFadeOut(); void cmdEndVideo(); public: @@ -146,6 +140,11 @@ public: void findNull(); + /** + * Print a given message to the screen in a bubble box + */ + void printString(const Common::String &msg); + // Script commands that need to be public void cmdFreeSound(); void cmdRetPos(); |