2009-01-18 17:04:24 +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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-03-04 11:53:25 +00:00
|
|
|
#ifdef ENABLE_LOL
|
2009-01-18 17:04:24 +00:00
|
|
|
|
|
|
|
#include "kyra/lol.h"
|
2009-02-21 17:24:50 +00:00
|
|
|
#include "kyra/screen_lol.h"
|
2009-01-18 17:04:24 +00:00
|
|
|
|
|
|
|
namespace Kyra {
|
|
|
|
|
|
|
|
void LoLEngine::giveCredits(int credits, int redraw) {
|
|
|
|
static const uint8 stashSetupData[] = { 4, 4, 4, 4, 2, 2, 2, 3, 3, 0, 1, 1 };
|
|
|
|
|
|
|
|
if (redraw)
|
|
|
|
snd_playSoundEffect(0x65, 0xff);
|
|
|
|
|
|
|
|
int t = credits / 30;
|
|
|
|
if (!t)
|
|
|
|
t = 1;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
while (credits) {
|
|
|
|
if (t > credits)
|
|
|
|
t = credits;
|
|
|
|
|
|
|
|
if (_credits < 60 && t >= 0) {
|
|
|
|
cnt = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (_credits < 60) {
|
|
|
|
int d = stashSetupData[_credits % 12] - _credits / 12;
|
|
|
|
if (d < 0)
|
|
|
|
d += 5;
|
|
|
|
_moneyColumnHeight[d]++;
|
|
|
|
}
|
|
|
|
_credits++;
|
2009-01-29 05:26:12 +00:00
|
|
|
} while (++cnt < t);
|
2009-01-18 17:04:24 +00:00
|
|
|
} else if (_credits >= 60) {
|
|
|
|
_credits += t;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw) {
|
|
|
|
gui_drawMoneyBox(6);
|
2009-02-01 19:27:01 +00:00
|
|
|
if (credits)
|
2009-02-21 17:24:50 +00:00
|
|
|
delay(_tickLength, 1);
|
2009-01-18 17:04:24 +00:00
|
|
|
}
|
|
|
|
credits -= t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int LoLEngine::makeItem(int itemIndex, int curFrame, int flags) {
|
|
|
|
int cnt = 0;
|
|
|
|
int r = 0;
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
for (; i < 400; i++) {
|
|
|
|
if (_itemsInPlay[i].shpCurFrame_flg & 0x8000) {
|
|
|
|
cnt = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_itemsInPlay[i].level < 1 || _itemsInPlay[i].level > 29 || _itemsInPlay[i].level == _currentLevel)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int diff = ABS(_currentLevel - _itemsInPlay[i].level);
|
2009-02-14 13:55:00 +00:00
|
|
|
|
2009-01-18 17:04:24 +00:00
|
|
|
if (diff <= cnt)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool t = false;
|
|
|
|
int ii = i;
|
|
|
|
while (ii && !t) {
|
|
|
|
t = testUnkItemFlags(ii);
|
|
|
|
if (t)
|
|
|
|
break;
|
|
|
|
else
|
2009-03-01 14:45:30 +00:00
|
|
|
ii = _itemsInPlay[ii - 1].next;
|
2009-01-18 17:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (t) {
|
|
|
|
cnt = diff;
|
|
|
|
r = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int slot = i;
|
|
|
|
if (cnt) {
|
|
|
|
slot = r;
|
|
|
|
if (testUnkItemFlags(r)) {
|
2009-03-01 14:45:30 +00:00
|
|
|
if (_itemsInPlay[r].next)
|
|
|
|
_itemsInPlay[_itemsInPlay[r].next].level = _itemsInPlay[r].level;
|
2009-02-21 17:24:50 +00:00
|
|
|
deleteItem(r);
|
2009-01-18 17:04:24 +00:00
|
|
|
slot = r;
|
|
|
|
} else {
|
2009-03-01 14:45:30 +00:00
|
|
|
int ii = _itemsInPlay[slot].next;
|
2009-02-14 13:55:00 +00:00
|
|
|
while (ii) {
|
2009-01-18 17:04:24 +00:00
|
|
|
if (testUnkItemFlags(ii)) {
|
2009-03-01 14:45:30 +00:00
|
|
|
_itemsInPlay[slot].next = _itemsInPlay[ii].next;
|
2009-02-21 17:24:50 +00:00
|
|
|
deleteItem(ii);
|
2009-01-18 17:04:24 +00:00
|
|
|
slot = ii;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
slot = ii;
|
|
|
|
}
|
2009-03-01 14:45:30 +00:00
|
|
|
ii = _itemsInPlay[slot].next;
|
2009-01-18 17:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&_itemsInPlay[slot], 0, sizeof(ItemInPlay));
|
2009-02-14 13:55:00 +00:00
|
|
|
|
2009-01-18 17:04:24 +00:00
|
|
|
_itemsInPlay[slot].itemPropertyIndex = itemIndex;
|
|
|
|
_itemsInPlay[slot].shpCurFrame_flg = (curFrame & 0x1fff) | flags;
|
|
|
|
_itemsInPlay[slot].level = -1;
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoLEngine::testUnkItemFlags(int itemIndex) {
|
|
|
|
if (!(_itemsInPlay[itemIndex].shpCurFrame_flg & 0x4000))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (_itemProperties[_itemsInPlay[itemIndex].itemPropertyIndex].flags & 4)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-02-21 17:24:50 +00:00
|
|
|
void LoLEngine::deleteItem(int itemIndex) {
|
2009-01-18 17:04:24 +00:00
|
|
|
memset(&_itemsInPlay[itemIndex], 0, sizeof(ItemInPlay));
|
|
|
|
_itemsInPlay[itemIndex].shpCurFrame_flg |= 0x8000;
|
|
|
|
}
|
|
|
|
|
2009-03-01 14:45:30 +00:00
|
|
|
ItemInPlay *LoLEngine::findItem(uint16 index) {
|
2009-01-18 17:04:24 +00:00
|
|
|
if (index & 0x8000)
|
2009-03-01 14:45:30 +00:00
|
|
|
return (ItemInPlay *)&_monsters[index & 0x7fff];
|
2009-01-18 17:04:24 +00:00
|
|
|
else
|
2009-03-01 14:45:30 +00:00
|
|
|
return &_itemsInPlay[index];
|
2009-01-18 17:04:24 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 17:24:50 +00:00
|
|
|
void LoLEngine::runItemScript(int charNum, int item, int reg0, int reg3, int reg4) {
|
2009-01-18 17:04:24 +00:00
|
|
|
EMCState scriptState;
|
|
|
|
memset(&scriptState, 0, sizeof(EMCState));
|
|
|
|
|
2009-02-01 19:27:01 +00:00
|
|
|
uint8 func = item ? _itemProperties[_itemsInPlay[item].itemPropertyIndex].itemScriptFunc : 3;
|
2009-01-18 17:04:24 +00:00
|
|
|
if (func == 0xff)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_emc->init(&scriptState, &_itemScript);
|
|
|
|
_emc->start(&scriptState, func);
|
|
|
|
|
|
|
|
scriptState.regs[0] = reg0;
|
2009-02-21 17:24:50 +00:00
|
|
|
scriptState.regs[1] = charNum;
|
2009-02-01 19:27:01 +00:00
|
|
|
scriptState.regs[2] = item;
|
2009-01-18 17:04:24 +00:00
|
|
|
scriptState.regs[3] = reg3;
|
|
|
|
scriptState.regs[4] = reg4;
|
|
|
|
|
|
|
|
while (_emc->isValid(&scriptState))
|
|
|
|
_emc->run(&scriptState);
|
|
|
|
}
|
|
|
|
|
2009-02-21 23:20:14 +00:00
|
|
|
void LoLEngine::setHandItem(uint16 itemIndex) {
|
2009-02-21 17:24:50 +00:00
|
|
|
if (itemIndex && _itemProperties[_itemsInPlay[itemIndex].itemPropertyIndex].flags & 0x80) {
|
|
|
|
runItemScript(-1, itemIndex, 0x400, 0, 0);
|
|
|
|
if (_itemsInPlay[itemIndex].shpCurFrame_flg & 0x8000)
|
|
|
|
itemIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mouseOffs = 0;
|
|
|
|
|
|
|
|
if (itemIndex && !(_screen->_drawGuiFlag & 0x200)) {
|
|
|
|
mouseOffs = 10;
|
|
|
|
if (!_hideControls || textEnabled())
|
|
|
|
_txt->printMessage(0, getLangString(0x403E), getLangString(_itemProperties[_itemsInPlay[itemIndex].itemPropertyIndex].nameStringId));
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemInHand = itemIndex;
|
|
|
|
_screen->setMouseCursor(mouseOffs, mouseOffs, getItemIconShapePtr(itemIndex));
|
|
|
|
}
|
|
|
|
|
2009-02-21 23:20:14 +00:00
|
|
|
void LoLEngine::clickSceneSub1() {
|
2009-02-23 20:17:53 +00:00
|
|
|
assignBlockCaps(_currentBlock, _currentDirection);
|
|
|
|
_screen->fillRect(112, 0, 287, 119, 0);
|
2009-02-21 23:20:14 +00:00
|
|
|
|
2009-02-23 20:17:53 +00:00
|
|
|
static const uint8 sceneItemWidth[] = { 0, 254, 1, 255, 2, 0, 1, 255 } ;
|
|
|
|
static const uint8 sceneClickTileIndex[] = { 13, 16};
|
|
|
|
|
|
|
|
int16 x1 = 0;
|
|
|
|
int16 x2 = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
uint8 tile = sceneClickTileIndex[i];
|
|
|
|
setLevelShapesDim(sceneClickTileIndex[i], x1, x2, 13);
|
|
|
|
uint16 s = _curBlockCaps[tile]->field_6;
|
|
|
|
|
|
|
|
int t = (i << 7) + 1;
|
|
|
|
while (s) {
|
|
|
|
if (s & 0x8000) {
|
|
|
|
s &= 0x7fff;
|
|
|
|
s = _monsters[i].unk2;
|
|
|
|
} else {
|
|
|
|
ItemInPlay *item = &_itemsInPlay[s];
|
|
|
|
|
|
|
|
if (item->shpCurFrame_flg & 0x4000) {
|
2009-03-01 14:45:30 +00:00
|
|
|
if (checkMonsterSpace(item->x, item->y, _partyPosX, _partyPosY) > 319)
|
2009-02-23 20:17:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
int w = sceneItemWidth[s & 7] << 1;
|
|
|
|
int h = sceneItemWidth[(s >> 1) & 7] + 5;
|
|
|
|
if (item->unk4 > 1)
|
|
|
|
h -= ((item->unk4 - 1) * 6);
|
|
|
|
|
|
|
|
uint8 shpIx = _itemProperties[item->itemPropertyIndex].shpIndex;
|
|
|
|
uint8 *shp = (_itemProperties[item->itemPropertyIndex].flags & 0x40) ? _gameShapes[shpIx] : _itemShapes[_gameShapeMap[shpIx]];
|
|
|
|
|
2009-03-01 14:45:30 +00:00
|
|
|
drawItemOrMonster(shp, 0, item->x, item->y, w, h, 0, t, 0);
|
2009-02-23 20:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s = item->unk2;
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-01 14:45:30 +00:00
|
|
|
int LoLEngine::checkMonsterSpace(int itemX, int itemY, int partyX, int partyY) {
|
|
|
|
int a = itemX - partyX;
|
|
|
|
if (a < 0)
|
|
|
|
a = -a;
|
|
|
|
|
|
|
|
int b = itemY - partyY;
|
|
|
|
if (b < 0)
|
|
|
|
b = -b;
|
|
|
|
|
|
|
|
return a + b;
|
2009-02-23 20:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int LoLEngine::checkSceneForItems(LevelBlockProperty *block, int pos) {
|
|
|
|
return -1;
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 20:17:53 +00:00
|
|
|
void LoLEngine::foundItemSub(int item, int block) {
|
2009-02-21 23:20:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-18 17:04:24 +00:00
|
|
|
} // end of namespace Kyra
|
|
|
|
|
2009-03-04 11:53:25 +00:00
|
|
|
#endif // ENABLE_LOL
|
2009-01-18 17:04:24 +00:00
|
|
|
|