diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cge/cge.cpp | 27 | ||||
-rw-r--r-- | engines/cge/cge.h | 19 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 29 | ||||
-rw-r--r-- | engines/cge/walk.cpp | 4 |
4 files changed, 30 insertions, 49 deletions
diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index dafb8a3782..66262e5e4a 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -38,6 +38,8 @@ namespace CGE { +const int CGEEngine::_maxCaveArr[5] = {1, 8, 16, 23, 24}; + CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription), _randomSource("cge") { @@ -54,36 +56,17 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } void CGEEngine::initCaveValues() { - _caveDx = 9; - _caveDy = 10; - _caveNx = 8; - _caveNy = 3; - _caveMax = _caveNx * _caveNy; - - _maxCaveArr[0] = 1; - _maxCaveArr[1] = 8; - _maxCaveArr[2] = 16; - _maxCaveArr[3] = 23; - _maxCaveArr[4] = 24; - - _heroXY = (Hxy *)malloc(sizeof(Hxy) * _caveMax); - for (int i = 0; i < _caveMax; i++) { + for (int i = 0; i < kCaveMax; i++) { _heroXY[i]._x = 0; _heroXY[i]._y = 0; } - _barriers = (Bar *)malloc(sizeof(Bar) * (1 + _caveMax)); - for (int i = 0; i < _caveMax + 1; i++) { + for (int i = 0; i < kCaveMax + 1; i++) { _barriers[i]._horz = 0xFF; _barriers[i]._vert = 0xFF; } } -void CGEEngine::freeCaveValues() { - free(_heroXY); - free(_barriers); -} - void CGEEngine::init() { debugC(1, kCGEDebugEngine, "CGEEngine::setup()"); @@ -195,8 +178,6 @@ void CGEEngine::deinit() { delete _miniShpList[i]; delete[] _miniShpList; } - - freeCaveValues(); } CGEEngine::~CGEEngine() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 40ea682ebc..95985103f4 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -51,6 +51,12 @@ class Sprite; #define kPocketNY 1 #define kPocketSX 8 #define kPocketSY 3 +#define kCaveDx 9 +#define kCaveDy 10 +#define kCaveNx 8 +#define kCaveNy 3 +#define kCaveMax kCaveNx * kCaveNy + // our engine debug channels enum { @@ -106,6 +112,8 @@ public: virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); + static const int _maxCaveArr[5]; + const ADGameDescription *_gameDescription; int _startupMode; int _demoText; @@ -114,7 +122,6 @@ public: bool _music; int _pocref[kPocketNX]; uint8 _volume[2]; - int _maxCaveArr[5]; int _maxCave; bool _flag[4]; bool _dark; @@ -132,13 +139,8 @@ public: Sprite *_sprK2; Sprite *_sprK3; - uint8 _caveDx; - uint8 _caveDy; - uint8 _caveNx; - uint8 _caveNy; - uint16 _caveMax; - Hxy *_heroXY; - Bar *_barriers; + Hxy _heroXY[kCaveMax]; + Bar _barriers[kCaveMax]; Common::RandomSource _randomSource; MusicPlayer _midiPlayer; @@ -212,7 +214,6 @@ public: void postMiniStep(int stp); void showBak(int ref); void initCaveValues(); - void freeCaveValues(); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a6fd08d396..b168c039e6 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -162,16 +162,15 @@ void CGEEngine::syncHeader(Common::Serializer &s) { s.syncAsUint16LE(_flag[i]); if (s.isLoading()) { - // Reinitialise cave values - freeCaveValues(); + // Reset cave values initCaveValues(); } - for (i = 0; i < _caveMax; i++) { + for (i = 0; i < kCaveMax; i++) { s.syncAsSint16LE(_heroXY[i]._x); s.syncAsUint16LE(_heroXY[i]._y); } - for (i = 0; i < 1 + _caveMax; i++) { + for (i = 0; i < 1 + kCaveMax; i++) { s.syncAsByte(_barriers[i]._horz); s.syncAsByte(_barriers[i]._vert); } @@ -281,8 +280,8 @@ Common::Error CGEEngine::loadGameState(int slot) { // Load the game loadGame(slot, NULL); _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % kCaveNx) * kCaveDx + kCaveSX, + kCaveY + ((_now - 1) / kCaveNx) * kCaveDy + kCaveSY); caveUp(); return Common::kNoError; @@ -480,7 +479,7 @@ void CGEEngine::loadHeroXY() { memset(_heroXY, 0, sizeof(_heroXY)); if (!cf._error) { - for (int i = 0; i < _caveMax; ++i) { + for (int i = 0; i < kCaveMax; ++i) { cf.read((byte *)&x, 2); cf.read((byte *)&y, 2); @@ -493,7 +492,7 @@ void CGEEngine::loadHeroXY() { void CGEEngine::loadMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()"); - if (_now <= _caveMax) { + if (_now <= kCaveMax) { VFile cf(progName(".TAB")); if (!cf._error) { // Move to the data for the given room @@ -730,8 +729,8 @@ void CGEEngine::switchCave(int cav) { _hero->step(0); _vga->_spareQ->_show = 0; } - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % kCaveNx) * kCaveDx + kCaveSX, + kCaveY + ((_now - 1) / kCaveNx) * kCaveDy + kCaveSY); killText(); if (!_startupMode) keyClick(); @@ -794,9 +793,9 @@ void System::touch(uint16 mask, int x, int y) { _infoLine->update(NULL); if (y >= kWorldHeight ) { if (x < kButtonX) { // select cave? - if (y >= kCaveY && y < kCaveY + _vm->_caveNy * _vm->_caveDy && - x >= kCaveX && x < kCaveX + _vm->_caveNx * _vm->_caveDx && !_vm->_game) { - cav = ((y - kCaveY) / _vm->_caveDy) * _vm->_caveNx + (x - kCaveX) / _vm->_caveDx + 1; + if (y >= kCaveY && y < kCaveY + kCaveNy * kCaveDy && + x >= kCaveX && x < kCaveX + kCaveNx * kCaveDx && !_vm->_game) { + cav = ((y - kCaveY) / kCaveDy) * kCaveNx + (x - kCaveX) / kCaveDx + 1; if (cav > _vm->_maxCave) cav = 0; } else { @@ -1397,8 +1396,8 @@ void CGEEngine::runGame() { _startupMode = 0; _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % kCaveNx) * kCaveDx + kCaveSX, + kCaveY + ((_now - 1) / kCaveNx) * kCaveDy + kCaveSY); caveUp(); _keyboard->setClient(_sys); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index bcd15768f1..e2b9a8961f 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -200,7 +200,7 @@ void Walk::reach(Sprite *spr, int mode) { _snail->insCom(kSnPause, -1, 64, NULL); _snail->insCom(kSnSeq, -1, kTSeq + mode, this); if (spr) { - _snail->insCom(kSnWait, -1, -1, _hero); /////--------$$$$$$$ + _snail->insCom(kSnWait, -1, -1, _hero); //SNINSERT(SNWALK, -1, -1, spr); } // sequence is not finished, @@ -212,7 +212,7 @@ void Walk::noWay() { } bool Cluster::chkBar() const { - assert(_vm->_now <= _vm->_caveMax); + assert(_vm->_now <= kCaveMax); return (_pt.x == _vm->_barriers[_vm->_now]._horz) || (_pt.y == _vm->_barriers[_vm->_now]._vert); } |