diff options
-rw-r--r-- | scumm/insane/insane.cpp | 70 | ||||
-rw-r--r-- | scumm/insane/insane.h | 16 | ||||
-rw-r--r-- | scumm/insane/insane_enemy.cpp | 6 | ||||
-rw-r--r-- | scumm/insane/insane_iact.cpp | 63 | ||||
-rw-r--r-- | scumm/insane/insane_scenes.cpp | 9 |
5 files changed, 66 insertions, 98 deletions
diff --git a/scumm/insane/insane.cpp b/scumm/insane/insane.cpp index d6c8c3d0b0..782d1f0dd1 100644 --- a/scumm/insane/insane.cpp +++ b/scumm/insane/insane.cpp @@ -122,7 +122,6 @@ void Insane::initvars(void) { _keyboardDisable = 0; _needSceneSwitch = false; _idx2Exceeded = 0; - _memoryAllocatedNotOK = 0; _lastKey = 0; _tiresRustle = false; _keybOldDx = 0; @@ -156,7 +155,7 @@ void Insane::initvars(void) { _roadBumps = false; _val211d = 0; _val213d = 0; - _val215d = 0; + _metEnemiesListTail = 0; _smlayer_room = 0; _smlayer_room2 = 0; _isBenCut = 0; @@ -166,6 +165,9 @@ void Insane::initvars(void) { _iactSceneId = 0; _iactSceneId2 = 0; + for (i = 0; i < 12; i++) + _metEnemiesList[i] = 0; + for (i = 0; i < 9; i++) for (j = 0; j < 9; j++) _enHdlVar[i][j] = 0; @@ -451,7 +453,7 @@ void Insane::init_actStruct(int actornum, int actnum, int32 actorval, byte state } void Insane::init_enemyStruct(int n, int32 handler, int32 initializer, - int16 occurences, int32 maxdamage, int32 field_10, + int16 occurences, int32 maxdamage, int32 isEmpty, int32 weapon, int32 sound, const char *filename, int32 costume4, int32 costume6, int32 costume5, int16 costumevar, int32 maxframe, int32 apprAnim) { @@ -461,7 +463,7 @@ void Insane::init_enemyStruct(int n, int32 handler, int32 initializer, _enemy[n].initializer = initializer; _enemy[n].occurences = occurences; _enemy[n].maxdamage = maxdamage; - _enemy[n].field_10 = field_10; + _enemy[n].isEmpty = isEmpty; _enemy[n].weapon = weapon; _enemy[n].sound = sound; strncpy(_enemy[n].filename, filename, 20); @@ -648,7 +650,6 @@ void Insane::readState(void) { // PATCH _actor[0].inventory[INV_DUST] = readArray(55) != 0; _actor[0].inventory[INV_HAND] = 1; _actor[0].inventory[INV_BOOT] = 1; - _enemy[EN_CAVEFISH].field_10 = readArray(56); _smlayer_room = readArray(320); _smlayer_room2 = readArray(321); _posBrokenTruck = readArray(322); @@ -667,8 +668,22 @@ void Insane::readState(void) { // PATCH _enemy[EN_VULTF2].occurences = readArray(334); _enemy[EN_VULTM2].occurences = readArray(335); _enemy[EN_CAVEFISH].occurences = readArray(336); - _enemy[EN_VULTM2].field_10 = readArray(340); - _enemy[EN_VULTF2].field_10 = readArray(339); + _enemy[EN_VULTM2].isEmpty = readArray(340); + _enemy[EN_VULTF2].isEmpty = readArray(339); + _enemy[EN_CAVEFISH].isEmpty = readArray(56); + + // Some sanity checks. There were submitted savefiles where these values were wrong + if (_enemy[EN_VULTM2].isEmpty != readArray(7)) + error("Wrong INSANE parameters for EN_VULTM2 (%d %d). Please, report this", + _enemy[EN_VULTM2].isEmpty, readArray(7)); + + if (_enemy[EN_VULTF2].isEmpty != _actor[0].inventory[INV_CHAINSAW]) + error("Wrong INSANE parameters for EN_VULTF2 (%d %d). Please, report this", + _enemy[EN_VULTF2].isEmpty, _actor[0].inventory[INV_CHAINSAW]); + + if (_enemy[EN_CAVEFISH].isEmpty != readArray(8)) + error("Wrong INSANE parameters for EN_CAVEFISH (%d %d). Please, report this", + _enemy[EN_CAVEFISH].isEmpty, readArray(8)); } } @@ -691,47 +706,6 @@ void Insane::setupValues(void) { smush_warpMouse(160, 100, -1); } -// FIXME: it seems that in ScummVM it may be unused -void Insane::mainLoop(void) { - int32 resid; - - while (!idx2Compare()) { - if(!(resid = idx2Tweak())) - continue; - - _vm->ensureResourceLoaded(rtSound, resid); - _vm->setResourceCounter(rtSound, resid, 1); - } - _vm->increaseResourceCounter(); - - while (!idx1Compare()) { - resid = idx1Tweak(); - _vm->ensureResourceLoaded(rtCostume, resid); - _vm->setResourceCounter(rtCostume, resid, 1); - // smlayer_lock (rtCostume, resid); - } - - if (loadSceneData(_currSceneId, 0, 2)) { - _sceneData1Loaded = 0; - _objArray2[0] = 0; - return; - } - _sceneData1Loaded = 1; - if (idx1Compare() || idx2Compare()) { - _objArray2[0] = 0; - return; - } - _objArray2[0]++; - if (_objArray2[0] <= 5) { - _objArray2[0] = 0; - return; - } - - smush_setToFinish(); - loadSceneData(_currSceneId, 1, 2); - _memoryAllocatedNotOK = 1; -} - bool Insane::idx1Compare(void) { return _objArray1Idx == _objArray1Idx2; } diff --git a/scumm/insane/insane.h b/scumm/insane/insane.h index a314eab8ea..ec8f3bbd2e 100644 --- a/scumm/insane/insane.h +++ b/scumm/insane/insane.h @@ -105,7 +105,6 @@ class Insane { int16 _keyboardDisable; bool _needSceneSwitch; int32 _idx2Exceeded; - bool _memoryAllocatedNotOK; int32 _lastKey; bool _beenCheated; bool _tiresRustle; @@ -175,15 +174,15 @@ class Insane { bool _val115_; int32 _val211d; int32 _val213d; - int32 _val215d; - int32 _val216d[12]; + int32 _metEnemiesListTail; + int32 _metEnemiesList[12]; struct enemy { int32 handler; int32 initializer; int16 occurences; int32 maxdamage; - int32 field_10; + int32 isEmpty; int32 weapon; int32 sound; char filename[20]; @@ -288,7 +287,6 @@ class Insane { int32 readArray(int item); void writeArray(int item, int value); - void mainLoop(void); bool idx1Compare(void); bool idx2Compare(void); int32 idx1Tweak(void); @@ -335,7 +333,7 @@ class Insane { void init_actStruct(int actornum, int actnum, int32 actorval, byte state, int32 room, int32 animtilt, int32 tilt, int32 frame); void init_enemyStruct(int n, int32 handler, int32 initializer, - int16 occurences, int32 maxdamage, int32 field_10, + int16 occurences, int32 maxdamage, int32 isEmpty, int32 field_14, int32 sound, const char *filename, int32 costume4, int32 costume6, int32 costume5, int16 field_2C, int32 field_30, int32 field_34); @@ -448,9 +446,9 @@ class Insane { bool isBitSet(int n); void setBit(int n); void clearBit(int n); - void proc62(void); - void proc63(void); - void proc64(int32); + void chooseEnemy(void); + void removeEmptyEnemies(void); + void removeEnemyFromMetList(int32); }; } // End of namespace Insane diff --git a/scumm/insane/insane_enemy.cpp b/scumm/insane/insane_enemy.cpp index ab64941a72..62c099bc03 100644 --- a/scumm/insane/insane_enemy.cpp +++ b/scumm/insane/insane_enemy.cpp @@ -2410,7 +2410,7 @@ void Insane::actor12Reaction(int32 buttons) { _actor[1].lost = true; if (_actor[1].act[2].frame >= 18) { writeArray(7, 1); - _enemy[EN_VULTM2].field_10 = 1; + _enemy[EN_VULTM2].isEmpty = 1; queueSceneSwitch(12, 0, "getnitro.san", 0, 0, 0, 0); } break; @@ -2467,7 +2467,7 @@ void Insane::actor12Reaction(int32 buttons) { if (_actor[1].act[2].frame >= 18 || ((_actor[1].x < 50 || _actor[1].x > 270) && _actor[1].act[2].frame >= 9)) { - _enemy[EN_CAVEFISH].field_10 = 1; + _enemy[EN_CAVEFISH].isEmpty = 1; queueSceneSwitch(20, 0, "wr2_cvko.san", 64, 0, 0, 0); _actor[1].act[2].state = 38; } @@ -2535,7 +2535,7 @@ void Insane::actor12Reaction(int32 buttons) { _actor[1].act[0].room = 0; _actor[1].cursorX = 0; _actor[1].act[2].state = 114; - _enemy[EN_VULTF2].field_10 = 1; + _enemy[EN_VULTF2].isEmpty = 1; smlayer_startVoice(275); break; case 114: diff --git a/scumm/insane/insane_iact.cpp b/scumm/insane/insane_iact.cpp index 9e1da22bb3..d0956c389a 100644 --- a/scumm/insane/insane_iact.cpp +++ b/scumm/insane/insane_iact.cpp @@ -86,7 +86,7 @@ void Insane::iactScene1(byte *renderBitmap, int32 codecparam, int32 setupsan12, } if (_approachAnim == -1) { - proc62(); //PATCH + chooseEnemy(); //PATCH _approachAnim = _enemy[_currEnemy].apprAnim; } @@ -183,26 +183,25 @@ void Insane::iactScene1(byte *renderBitmap, int32 codecparam, int32 setupsan12, } } -void Insane::proc62(void) { - debug(1, "Insane::proc62"); +void Insane::chooseEnemy(void) { if (readArray(58) != 0) - _enemy[EN_TORQUE].field_10 = 1; + _enemy[EN_TORQUE].isEmpty = 1; if (_enemy[EN_TORQUE].occurences == 0) { _currEnemy = EN_TORQUE; - _val215d++; - _val216d[_val215d] = EN_TORQUE; + _metEnemiesListTail++; + _metEnemiesList[_metEnemiesListTail] = EN_TORQUE; return; } - proc63(); + removeEmptyEnemies(); int32 count, i, j, en, en2; bool notfound; en = 0; for (i = 0; i < 9; i++) - if (_enemy[i].field_10 == 0) + if (_enemy[i].isEmpty == 0) ++en; en -= 4; @@ -220,16 +219,16 @@ void Insane::proc62(void) { notfound = true; - if (_enemy[en2].field_10 != 0) + if (_enemy[en2].isEmpty != 0) continue; - if (0 < _val215d) { + if (0 < _metEnemiesListTail) { i = 0; do { - if (en2 == _val216d[i + 1]) + if (en2 == _metEnemiesList[i + 1]) notfound = false; i++; - } while (i < _val215d && notfound); + } while (i < _metEnemiesListTail && notfound); } if (!notfound) { continue; @@ -239,29 +238,29 @@ void Insane::proc62(void) { do { notfound = true; en2 = j; - if (0 < _val215d) { + if (0 < _metEnemiesListTail) { i = 0; do { - if (en2 == _val216d[i + 1]) + if (en2 == _metEnemiesList[i + 1]) notfound = false; i++; - } while (i < _val215d && notfound); + } while (i < _metEnemiesListTail && notfound); } j++; } while (j < 9 && !notfound); if (!notfound) { - _val215d = 0; + _metEnemiesListTail = 0; count = 0; continue; } } - ++_val215d; - assert(_val215d < ARRAYSIZE(_val216d)); - _val216d[_val215d] = en2; + ++_metEnemiesListTail; + assert(_metEnemiesListTail < ARRAYSIZE(_metEnemiesList)); + _metEnemiesList[_metEnemiesListTail] = en2; - if (_val215d >= en) { - proc64(0); + if (_metEnemiesListTail >= en) { + removeEnemyFromMetList(0); } if (notfound) @@ -271,25 +270,25 @@ void Insane::proc62(void) { _currEnemy = en2; } -void Insane::proc63(void) { - if (_val215d > 0) { - for (int i = 0; i < _val215d; i++) - if (_enemy[i].field_10 == 1) - proc64(i); +void Insane::removeEmptyEnemies(void) { + if (_metEnemiesListTail > 0) { + for (int i = 0; i < _metEnemiesListTail; i++) + if (_enemy[i].isEmpty == 1) + removeEnemyFromMetList(i); } } -void Insane::proc64(int32 enemy1) { - if (enemy1 >= _val215d) +void Insane::removeEnemyFromMetList(int32 enemy1) { + if (enemy1 >= _metEnemiesListTail) return; int en = enemy1; do { ++en; - assert(en + 1 < ARRAYSIZE(_val216d)); - _val216d[en] = _val216d[en + 1]; - } while (en < _val215d); - _val215d--; + assert(en + 1 < ARRAYSIZE(_metEnemiesList)); + _metEnemiesList[en] = _metEnemiesList[en + 1]; + } while (en < _metEnemiesListTail); + _metEnemiesListTail--; } void Insane::iactScene3(byte *renderBitmap, int32 codecparam, int32 setupsan12, diff --git a/scumm/insane/insane_scenes.cpp b/scumm/insane/insane_scenes.cpp index ff4beab914..9cd9bf9a3a 100644 --- a/scumm/insane/insane_scenes.cpp +++ b/scumm/insane/insane_scenes.cpp @@ -148,7 +148,7 @@ void Insane::runScene(int arraynum) { writeArray(53, _actor[0].inventory[INV_2X4]); writeArray(54, _actor[0].inventory[INV_WRENCH]); writeArray(55, _actor[0].inventory[INV_DUST]); - writeArray(56, _enemy[EN_CAVEFISH].field_10); + writeArray(56, _enemy[EN_CAVEFISH].isEmpty); writeArray(337, _enemy[EN_TORQUE].occurences); writeArray(329, _enemy[EN_ROTT1].occurences); writeArray(330, _enemy[EN_ROTT2].occurences); @@ -158,14 +158,11 @@ void Insane::runScene(int arraynum) { writeArray(334, _enemy[EN_VULTF2].occurences); writeArray(335, _enemy[EN_VULTM2].occurences); writeArray(336, _enemy[EN_CAVEFISH].occurences); - writeArray(339, _enemy[EN_VULTF2].field_10); - writeArray(340, _enemy[EN_VULTM2].field_10); + writeArray(339, _enemy[EN_VULTF2].isEmpty); + writeArray(340, _enemy[EN_VULTM2].isEmpty); } // insane_unlock(); // FIXME _vm->_sound->stopAllSounds(); // IMUSE_StopAllSounds(); - if (_memoryAllocatedNotOK) { - error("Memory Alloc Error in Mineroad (Heap Size?)"); - } delete _player; } |