From 008fbcab5b3683e03437fe136b1e72be95bcec9f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 4 Nov 2019 08:01:26 +0100 Subject: GRIFFON: Introduce ObjectInfoStruct, some refactoring --- engines/griffon/combat.cpp | 30 +++++++++++++++--------------- engines/griffon/cutscenes.cpp | 5 ++--- engines/griffon/draw.cpp | 23 +++++++++-------------- engines/griffon/griffon.cpp | 10 ++++++++-- engines/griffon/griffon.h | 17 +++++++++++++---- engines/griffon/input.cpp | 10 +++++----- engines/griffon/logic.cpp | 15 +++++++-------- engines/griffon/resources.cpp | 15 +++++++++------ 8 files changed, 68 insertions(+), 57 deletions(-) diff --git a/engines/griffon/combat.cpp b/engines/griffon/combat.cpp index 3ee185f31f..f140674186 100644 --- a/engines/griffon/combat.cpp +++ b/engines/griffon/combat.cpp @@ -55,11 +55,11 @@ void GriffonEngine::attack() { o2 = _objectMap[lx][ly - 2]; // cst - if ((_objectInfo[o][4] == 1 && (o == 0 || o > 4)) || (_objectInfo[o2][4] == 0 && o2 == 10)) { + if ((_objectInfo[o].type == 1 && (o == 0 || o > 4)) || (_objectInfo[o2].type == 0 && o2 == 10)) { if (o2 == 10) o = 10; - int oscript = _objectInfo[o][5]; + int oscript = _objectInfo[o].script; switch (oscript) { case kScriptFlask: if (_player.inventory[kInvFlask] < 9) { @@ -73,7 +73,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found Flask!"); @@ -107,7 +107,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Temple Key!"); return; @@ -122,7 +122,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Infinite Crystal!"); @@ -141,7 +141,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Obsidian Shield!"); @@ -162,7 +162,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Fidelis Sword!"); return; @@ -185,7 +185,7 @@ void GriffonEngine::attack() { _objectMapFull[_curMap][lx][ly - 1] = 1; - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found Key"); @@ -211,7 +211,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found Mega Flask!"); @@ -239,7 +239,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found Mega Flask!"); @@ -266,7 +266,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found Lightning Bomb!"); @@ -292,7 +292,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Fidelis Mail!"); @@ -344,7 +344,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Blood Sword!"); _objectMapFull[4][1][2] = 1; @@ -362,7 +362,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Entropy Shield!"); _objectMapFull[4][1][2] = 1; @@ -380,7 +380,7 @@ void GriffonEngine::attack() { setChannelVolume(snd, config.effectsVol); } - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _objectMap[lx][ly - 1] = 3; eventText("Found the Rubyscale Armour!"); _objectMapFull[4][1][2] = 1; diff --git a/engines/griffon/cutscenes.cpp b/engines/griffon/cutscenes.cpp index 4936460264..8e67eb6e63 100644 --- a/engines/griffon/cutscenes.cpp +++ b/engines/griffon/cutscenes.cpp @@ -290,7 +290,7 @@ void GriffonEngine::endOfGame() { bool ldstop = false; // CHECKME: Check if actually used do { - ld = ld + 4 * _fpsr; + ld += 4 * _fpsr; if (ld > config.musicVol) ld = config.musicVol; if (!ldstop) { @@ -413,8 +413,7 @@ void GriffonEngine::endOfGame() { if (_ticks < ticks1 + 1500) { y1 = 255 * (_ticks - ticks1) / 1500; y1 = CLIP(y1, 0, 255); - } - else + } else break; _videoBuffer->fillRect(Common::Rect(0, 0, _videoBuffer->w, _videoBuffer->h), 0); diff --git a/engines/griffon/draw.cpp b/engines/griffon/draw.cpp index 73785dfea7..3fd968f920 100644 --- a/engines/griffon/draw.cpp +++ b/engines/griffon/draw.cpp @@ -96,8 +96,8 @@ void GriffonEngine::drawAnims(int Layer) { int o = _objectMap[sx][sy]; if (o > -1) { - int xtiles = _objectInfo[o][1]; - int ytiles = _objectInfo[o][2]; + int xtiles = _objectInfo[o].xTiles; + int ytiles = _objectInfo[o].yTiles; int cframe = _objectFrame[o][1]; for (int x = 0; x <= xtiles - 1; x++) { @@ -174,7 +174,6 @@ void GriffonEngine::drawAnims(int Layer) { int hud_recalc(int a, int b, int c) { int result = a * b / c; - return MIN(result, b); } @@ -371,13 +370,13 @@ void GriffonEngine::drawHud() { rcSrc.top = sy; if (i == 0) _itemImg[6]->blit(*_videoBuffer, rcSrc.left, rcSrc.top); - if (i == 1) + else if (i == 1) _itemImg[12]->blit(*_videoBuffer, rcSrc.left, rcSrc.top); - if (i == 2) + else if (i == 2) _itemImg[17]->blit(*_videoBuffer, rcSrc.left, rcSrc.top); - if (i == 3) + else if (i == 3) _itemImg[16]->blit(*_videoBuffer, rcSrc.left, rcSrc.top); - if (i == 4) + else if (i == 4) _itemImg[14]->blit(*_videoBuffer, rcSrc.left, rcSrc.top); sprintf(line, "x%i", _player.inventory[i]); @@ -408,9 +407,7 @@ void GriffonEngine::drawHud() { rcDest.left = (float)(243 - 12 + 3 * sin(3.141592 * 2 * _itemyloc / 16)); rcDest.top = 67 + 24 * i; _itemImg[15]->blit(*_videoBuffer, rcDest.left, rcDest.top); - } - - if (_curItem == i) { + } else if (_curItem == i) { rcDest.left = (float)(189 - 12 + 3 * sin(3.141592 * 2 * _itemyloc / 16)); rcDest.top = 70 + 24 * i; _itemImg[15]->blit(*_videoBuffer, rcDest.left, rcDest.top); @@ -1193,7 +1190,7 @@ void GriffonEngine::swash() { y = 0; do { - y = y + 1 * _fpsr; + y += _fpsr; _videoBuffer->setAlpha((int)(y * 25)); _mapBg->blit(*_videoBuffer); @@ -1230,9 +1227,7 @@ void GriffonEngine::swash() { while (_cloudAngle >= 360) _cloudAngle -= 360; - if (y > 10) - break; - } while (1); + } while (y <= 10); _videoBuffer->setAlpha(255); diff --git a/engines/griffon/griffon.cpp b/engines/griffon/griffon.cpp index 5eb5643248..b921e74c80 100644 --- a/engines/griffon/griffon.cpp +++ b/engines/griffon/griffon.cpp @@ -53,8 +53,14 @@ GriffonEngine::GriffonEngine(OSystem *syst) : Engine(syst) { _cloudAngle = 0.0f; for (int i = 0; i < 33; ++i) { - for (int j = 0; j < 6; ++j) - _objectInfo[i][j] = 0; + for (int j = 0; j < 6; ++j) { + _objectInfo[i].nFrames = 0; + _objectInfo[i].xTiles = 0; + _objectInfo[i].yTiles = 0; + _objectInfo[i].speed = 0; + _objectInfo[i].type = 0; + _objectInfo[i].script = 0; + } } for (int i = 0; i < 256; ++i) { diff --git a/engines/griffon/griffon.h b/engines/griffon/griffon.h index cfdbd62a24..e7b9c82a43 100644 --- a/engines/griffon/griffon.h +++ b/engines/griffon/griffon.h @@ -302,13 +302,22 @@ struct AttackOffsetStruct { bool completed; }; -struct CONFIG { +struct Config { bool music; int musicVol; bool effects; int effectsVol; }; +struct ObjectInfoStruct { + int nFrames; + int xTiles; + int yTiles; + int speed; + int type; + int script; +}; + class GriffonEngine : public Engine { public: GriffonEngine(OSystem *syst); @@ -491,8 +500,8 @@ private: float _objectFrame[256][2]; int _lastObj; // frame!, curframe - int _objectInfo[33][6]; - // nframes,xtiles,ytiles,speed,type,script, update? + ObjectInfoStruct _objectInfo[33]; + int _objectTile[33][9][3][3][2]; // [objnum] [frame] [x] [y] [tile/layer] int _objectMap[21][15]; @@ -532,7 +541,7 @@ private: bool _pmenu; - CONFIG config; + Config config; void saveConfig(); }; diff --git a/engines/griffon/input.cpp b/engines/griffon/input.cpp index d2ac4a6e0f..4b2ea5cff4 100644 --- a/engines/griffon/input.cpp +++ b/engines/griffon/input.cpp @@ -56,7 +56,7 @@ void GriffonEngine::checkInputs() { for (int x = 0; x <= 19; x++) { for (int y = 0; y <= 14; y++) { int o = _objectMap[x][y]; - if (_objectInfo[o][4] == 3) { + if (_objectInfo[o].type == 3) { _postInfo[_postInfoNbr][0] = x * 16; _postInfo[_postInfoNbr][1] = y * 16; _postInfoNbr = _postInfoNbr + 1; @@ -545,7 +545,7 @@ void GriffonEngine::handleWalking() { if (o > -1) { // fsk - if (_objectInfo[o][4] == 2 && _player.inventory[kInvFlask] < 9) { + if (_objectInfo[o].type == 2 && _player.inventory[kInvFlask] < 9) { _objectMap[lx][ly] = -1; _player.inventory[kInvFlask]++; @@ -559,7 +559,7 @@ void GriffonEngine::handleWalking() { } } - if (_objectInfo[o][5] == 7 && _player.inventory[kInvDoubleFlask] < 9) { + if (_objectInfo[o].script == 7 && _player.inventory[kInvDoubleFlask] < 9) { _objectMap[lx][ly] = -1; _player.inventory[kInvDoubleFlask]++; @@ -573,7 +573,7 @@ void GriffonEngine::handleWalking() { } } - if (_objectInfo[o][5] == 9 && _player.inventory[kInvShock] < 9 && (_curMap == 41 && _scriptFlag[kScriptLightningBomb][1] == 0)) { + if (_objectInfo[o].script == 9 && _player.inventory[kInvShock] < 9 && (_curMap == 41 && _scriptFlag[kScriptLightningBomb][1] == 0)) { _objectMap[lx][ly] = -1; _player.inventory[kInvShock]++; @@ -590,7 +590,7 @@ void GriffonEngine::handleWalking() { } - if (_objectInfo[o][5] == 9 && _player.inventory[kInvShock] < 9) { + if (_objectInfo[o].script == 9 && _player.inventory[kInvShock] < 9) { _objectMap[lx][ly] = -1; _player.inventory[kInvShock]++; diff --git a/engines/griffon/logic.cpp b/engines/griffon/logic.cpp index 07fcd306ba..d41b352f11 100644 --- a/engines/griffon/logic.cpp +++ b/engines/griffon/logic.cpp @@ -76,15 +76,14 @@ const int elementmap[15][20] = { void GriffonEngine::updateAnims() { for (int i = 0; i <= _lastObj; i++) { - int nframes = _objectInfo[i][0]; - int o_animspd = _objectInfo[i][3]; + int nFrames = _objectInfo[i].nFrames; + int objAnimSpeed = _objectInfo[i].speed; float frame = _objectFrame[i][0]; - // _objectinfo[i][6] = 0; // ?? out of bounds - if (nframes > 1) { - frame += o_animspd / 50 * _fpsr; - while (frame >= nframes) - frame -= nframes; + if (nFrames > 1) { + frame += objAnimSpeed / 50 * _fpsr; + while (frame >= nFrames) + frame -= nFrames; int cframe = (int)frame; // truncate fractional part if (cframe < 0) @@ -1628,7 +1627,7 @@ void GriffonEngine::updateSpells() { int o = _objectMap[sx][sy]; if (o > -1) { - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) foundel[2] = true; if (o == 1 || o == 2) { foundel[2] = true; diff --git a/engines/griffon/resources.cpp b/engines/griffon/resources.cpp index a67b29235a..e0da5c1d67 100644 --- a/engines/griffon/resources.cpp +++ b/engines/griffon/resources.cpp @@ -415,7 +415,7 @@ void GriffonEngine::loadMap(int mapnum) { if (_objectMapFull[_curMap][x][y] == 0) { _objectMap[x][y] = o; - if (_objectInfo[o][0] > 1) { + if (_objectInfo[o].nFrames > 1) { if (o > _lastObj) _lastObj = o; } @@ -428,9 +428,9 @@ void GriffonEngine::loadMap(int mapnum) { rcDest.setWidth(8); rcDest.setHeight(8); - if (_objectInfo[o][4] == 1) + if (_objectInfo[o].type == 1) _clipBg->fillRect(rcDest, ccc); - if (_objectInfo[o][4] == 3) + if (_objectInfo[o].type == 3) _clipBg->fillRect(rcDest, ccc); } } @@ -1144,9 +1144,12 @@ void GriffonEngine::loadObjectDB() { error("Cannot open file objectdb.dat"); for (int a = 0; a <= 32; a++) { - for (int b = 0; b <= 5; b++) { - INPUT("%i", &_objectInfo[a][b]); - } + INPUT("%i", &_objectInfo[a].nFrames); + INPUT("%i", &_objectInfo[a].xTiles); + INPUT("%i", &_objectInfo[a].yTiles); + INPUT("%i", &_objectInfo[a].speed); + INPUT("%i", &_objectInfo[a].type); + INPUT("%i", &_objectInfo[a].script); for (int b = 0; b <= 8; b++) { for (int c = 0; c <= 2; c++) { -- cgit v1.2.3