2009-02-21 23:20:14 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-03-04 11:53:25 +00:00
|
|
|
#ifdef ENABLE_LOL
|
|
|
|
|
2009-02-21 23:20:14 +00:00
|
|
|
#include "kyra/lol.h"
|
|
|
|
#include "kyra/timer.h"
|
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
|
2009-02-21 23:20:14 +00:00
|
|
|
namespace Kyra {
|
|
|
|
|
|
|
|
#define TimerV2(x) new Common::Functor1Mem<int, void, LoLEngine>(this, &LoLEngine::x)
|
|
|
|
|
|
|
|
void LoLEngine::setupTimers() {
|
2009-03-06 22:53:08 +00:00
|
|
|
_timer->addTimer(0, TimerV2(timerProcessDoors), 15, true);
|
2009-03-01 14:45:30 +00:00
|
|
|
_timer->addTimer(0x10, TimerV2(timerProcessMonsters), 6, true);
|
|
|
|
_timer->addTimer(0x11, TimerV2(timerProcessMonsters), 6, true);
|
2009-03-03 22:32:39 +00:00
|
|
|
_timer->setNextRun(0x11, _system->getMillis() + 3 * _tickLength);
|
2009-04-25 13:15:05 +00:00
|
|
|
_timer->addTimer(3, TimerV2(timerSpecialCharacterUpdate), 15, true);
|
2009-03-16 21:20:34 +00:00
|
|
|
_timer->addTimer(4, TimerV2(timerProcessFlyingObjects), 1, true);
|
2009-03-09 20:34:36 +00:00
|
|
|
_timer->addTimer(0x50, TimerV2(timerRunSceneAnimScript), 0, false);
|
|
|
|
_timer->addTimer(0x51, TimerV2(timerRunSceneAnimScript), 0, false);
|
|
|
|
_timer->addTimer(0x52, TimerV2(timerRunSceneAnimScript), 0, false);
|
2009-04-25 13:15:05 +00:00
|
|
|
_timer->addTimer(8, TimerV2(timerRegeneratePoints), 1200, true);
|
2009-02-23 20:17:53 +00:00
|
|
|
_timer->addTimer(9, TimerV2(timerUpdatePortraitAnimations), 10, true);
|
2009-02-21 23:20:14 +00:00
|
|
|
_timer->addTimer(10, TimerV2(timerUpdateLampState), 360, true);
|
|
|
|
_timer->addTimer(11, TimerV2(timerFadeMessageText), 360, false);
|
2011-08-17 16:46:29 +00:00
|
|
|
_timer->resetNextRun();
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-03-01 14:45:30 +00:00
|
|
|
void LoLEngine::timerProcessMonsters(int timerNum) {
|
|
|
|
for (int i = timerNum & 0x0f; i < 30; i += 2)
|
|
|
|
updateMonster(&_monsters[i]);
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
void LoLEngine::timerSpecialCharacterUpdate(int timerNum) {
|
2009-12-20 16:23:44 +00:00
|
|
|
int eventsLeft = 0;
|
2009-04-25 13:15:05 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (!(_characters[i].flags & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int ii = 0; ii < 5; ii++) {
|
|
|
|
if (!(_characters[i].characterUpdateEvents[ii]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (--_characters[i].characterUpdateDelay[ii] > 0) {
|
2009-12-20 16:23:44 +00:00
|
|
|
if (_characters[i].characterUpdateDelay[ii] > eventsLeft)
|
|
|
|
eventsLeft = _characters[i].characterUpdateDelay[ii];
|
2009-04-25 13:15:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (_characters[i].characterUpdateEvents[ii] - 1) {
|
2009-05-29 13:09:26 +00:00
|
|
|
case 0:
|
|
|
|
if (_characters[i].weaponHit) {
|
|
|
|
_characters[i].weaponHit = 0;
|
|
|
|
_characters[i].characterUpdateDelay[ii] = calcMonsterSkillLevel(i, 6);
|
2009-12-20 16:23:44 +00:00
|
|
|
if (_characters[i].characterUpdateDelay[ii] > eventsLeft)
|
|
|
|
eventsLeft = _characters[i].characterUpdateDelay[ii];
|
2009-05-29 13:09:26 +00:00
|
|
|
} else {
|
|
|
|
_characters[i].flags &= 0xfffb;
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
_characters[i].damageSuffered = 0;
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
_characters[i].flags &= 0xffbf;
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2009-12-20 16:23:44 +00:00
|
|
|
eventsLeft = rollDice(1, 2);
|
|
|
|
if (inflictDamage(i, eventsLeft, 0x8000, 0, 0x80)) {
|
2009-05-29 13:09:26 +00:00
|
|
|
_txt->printMessage(2, getLangString(0x4022), _characters[i].name);
|
|
|
|
_characters[i].characterUpdateDelay[ii] = 10;
|
2009-12-20 16:23:44 +00:00
|
|
|
if (_characters[i].characterUpdateDelay[ii] > eventsLeft)
|
|
|
|
eventsLeft = _characters[i].characterUpdateDelay[ii];
|
2009-05-29 13:09:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
_characters[i].flags &= 0xfeff;
|
|
|
|
_txt->printMessage(0, getLangString(0x4027), _characters[i].name);
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
setTemporaryFaceFrame(i, 0, 0, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
_characters[i].flags &= 0xefff;
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
restoreSwampPalette();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-04-25 13:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_characters[i].characterUpdateDelay[ii] <= 0)
|
|
|
|
_characters[i].characterUpdateEvents[ii] = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-02-21 23:20:14 +00:00
|
|
|
|
2009-12-20 16:23:44 +00:00
|
|
|
if (eventsLeft)
|
2009-04-25 13:15:05 +00:00
|
|
|
_timer->enable(3);
|
2009-12-20 16:23:44 +00:00
|
|
|
else
|
2009-04-25 13:15:05 +00:00
|
|
|
_timer->disable(3);
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-03-16 21:20:34 +00:00
|
|
|
void LoLEngine::timerProcessFlyingObjects(int timerNum) {
|
|
|
|
for (int i = 0; i < 8; i++) {
|
2009-03-24 07:18:16 +00:00
|
|
|
if (!_flyingObjects[i].enable)
|
2009-03-16 21:20:34 +00:00
|
|
|
continue;
|
2009-04-25 13:15:05 +00:00
|
|
|
updateFlyingObject(&_flyingObjects[i]);
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 20:34:36 +00:00
|
|
|
void LoLEngine::timerRunSceneAnimScript(int timerNum) {
|
2009-02-21 23:20:14 +00:00
|
|
|
runLevelScript(0x401 + (timerNum & 0x0f), -1);
|
|
|
|
}
|
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
void LoLEngine::timerRegeneratePoints(int timerNum) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (!(_characters[i].flags & 1))
|
|
|
|
continue;
|
2009-02-21 23:20:14 +00:00
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
// check for Duble ring
|
|
|
|
int hInc = (_characters[i].flags & 8) ? 0 : (itemEquipped(i, 228) ? 4 : 1);
|
|
|
|
// check for Talba ring
|
|
|
|
int mInc = _drainMagic ? ((_characters[i].magicPointsMax >> 5) * -1) :
|
2011-12-31 04:11:33 +00:00
|
|
|
((_characters[i].flags & 8) ? 0 : (itemEquipped(i, 227) ? (_characters[i].magicPointsMax / 10) : 1));
|
2009-04-25 13:15:05 +00:00
|
|
|
|
|
|
|
_characters[i].magicPointsCur = CLIP<int16>(_characters[i].magicPointsCur + mInc, 0, _characters[i].magicPointsMax);
|
|
|
|
|
|
|
|
if (!(_characters[i].flags & 0x80))
|
|
|
|
increaseCharacterHitpoints(i, hInc, false);
|
|
|
|
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
|
|
|
}
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 20:17:53 +00:00
|
|
|
void LoLEngine::timerUpdatePortraitAnimations(int skipUpdate) {
|
|
|
|
if (skipUpdate != 1)
|
|
|
|
skipUpdate = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (!(_characters[i].flags & 1) || (_characters[i].flags & 8) || (_characters[i].curFaceFrame > 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (_characters[i].curFaceFrame != 1) {
|
|
|
|
if (--_characters[i].nextAnimUpdateCountdown <= 0 && !skipUpdate) {
|
|
|
|
_characters[i].curFaceFrame = 1;
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
|
|
|
_timer->setCountdown(9, 10);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_characters[i].curFaceFrame = 0;
|
|
|
|
gui_drawCharPortraitWithStats(i);
|
2009-07-08 21:12:03 +00:00
|
|
|
_characters[i].nextAnimUpdateCountdown = rollDice(1, 12) + 6;
|
2009-02-23 20:17:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoLEngine::timerUpdateLampState(int timerNum) {
|
2009-12-26 14:12:38 +00:00
|
|
|
if ((_flagsTable[31] & 0x08) && (_flagsTable[31] & 0x04) && _brightness && _lampOilStatus)
|
2009-03-28 11:58:22 +00:00
|
|
|
_lampOilStatus--;
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoLEngine::timerFadeMessageText(int timerNum) {
|
|
|
|
_timer->disable(timerNum);
|
|
|
|
initTextFading(0, 0);
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Kyra
|
2009-03-04 11:53:25 +00:00
|
|
|
|
|
|
|
#endif // ENABLE_LOL
|