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) {
|
|
|
|
if (redraw)
|
2009-03-14 13:48:12 +00:00
|
|
|
snd_playSoundEffect(101, -1);
|
2009-01-18 17:04:24 +00:00
|
|
|
|
|
|
|
int t = credits / 30;
|
|
|
|
if (!t)
|
|
|
|
t = 1;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
while (credits) {
|
|
|
|
if (t > credits)
|
|
|
|
t = credits;
|
|
|
|
|
2009-05-10 13:40:28 +00:00
|
|
|
if (_credits < 60 && t > 0) {
|
2009-01-18 17:04:24 +00:00
|
|
|
cnt = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (_credits < 60) {
|
2009-03-14 13:48:12 +00:00
|
|
|
int d = _stashSetupData[_credits % 12] - _credits / 12;
|
2009-01-18 17:04:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-14 13:48:12 +00:00
|
|
|
void LoLEngine::takeCredits(int credits, int redraw) {
|
|
|
|
if (redraw)
|
|
|
|
snd_playSoundEffect(101, -1);
|
|
|
|
|
|
|
|
if (credits > _credits)
|
|
|
|
credits = _credits;
|
|
|
|
|
|
|
|
int t = credits / 30;
|
|
|
|
if (!t)
|
|
|
|
t = 1;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
while (credits && _credits > 0) {
|
|
|
|
if (t > credits)
|
|
|
|
t = credits;
|
|
|
|
|
2009-05-10 13:40:28 +00:00
|
|
|
if (_credits - t < 60 && t > 0) {
|
2009-03-14 13:48:12 +00:00
|
|
|
cnt = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (--_credits < 60) {
|
|
|
|
int d = _stashSetupData[_credits % 12] - _credits / 12;
|
|
|
|
if (d < 0)
|
|
|
|
d += 5;
|
|
|
|
_moneyColumnHeight[d]--;
|
|
|
|
}
|
|
|
|
} while (++cnt < t);
|
2009-05-10 13:40:28 +00:00
|
|
|
} else if (_credits - t >= 60) {
|
2009-03-14 13:48:12 +00:00
|
|
|
_credits -= t;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw) {
|
|
|
|
gui_drawMoneyBox(6);
|
|
|
|
if (credits)
|
|
|
|
delay(_tickLength, 1);
|
|
|
|
}
|
|
|
|
credits -= t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-24 07:18:16 +00:00
|
|
|
int LoLEngine::makeItem(int itemType, int curFrame, int flags) {
|
2009-01-18 17:04:24 +00:00
|
|
|
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-15 16:48:20 +00:00
|
|
|
ii = _itemsInPlay[ii - 1].nextAssignedObject;
|
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-15 16:48:20 +00:00
|
|
|
if (_itemsInPlay[r].nextAssignedObject)
|
|
|
|
_itemsInPlay[_itemsInPlay[r].nextAssignedObject].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-15 16:48:20 +00:00
|
|
|
int ii = _itemsInPlay[slot].nextAssignedObject;
|
2009-02-14 13:55:00 +00:00
|
|
|
while (ii) {
|
2009-01-18 17:04:24 +00:00
|
|
|
if (testUnkItemFlags(ii)) {
|
2009-03-15 16:48:20 +00:00
|
|
|
_itemsInPlay[slot].nextAssignedObject = _itemsInPlay[ii].nextAssignedObject;
|
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-15 16:48:20 +00:00
|
|
|
ii = _itemsInPlay[slot].nextAssignedObject;
|
2009-01-18 17:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&_itemsInPlay[slot], 0, sizeof(ItemInPlay));
|
2009-02-14 13:55:00 +00:00
|
|
|
|
2009-03-24 07:18:16 +00:00
|
|
|
_itemsInPlay[slot].itemPropertyIndex = itemType;
|
2009-01-18 17:04:24 +00:00
|
|
|
_itemsInPlay[slot].shpCurFrame_flg = (curFrame & 0x1fff) | flags;
|
|
|
|
_itemsInPlay[slot].level = -1;
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
2009-03-24 07:18:16 +00:00
|
|
|
void LoLEngine::placeMoveLevelItem(int itemIndex, int level, int block, int xOffs, int yOffs, int flyingHeight) {
|
|
|
|
calcCoordinates(_itemsInPlay[itemIndex].x, _itemsInPlay[itemIndex].y, block, xOffs, yOffs);
|
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
if (_itemsInPlay[itemIndex].block)
|
|
|
|
removeLevelItem(itemIndex, _itemsInPlay[itemIndex].block);
|
2009-03-24 07:18:16 +00:00
|
|
|
|
|
|
|
if (_currentLevel == level) {
|
|
|
|
setItemPosition(itemIndex, _itemsInPlay[itemIndex].x, _itemsInPlay[itemIndex].y, flyingHeight, 1);
|
|
|
|
} else {
|
|
|
|
_itemsInPlay[itemIndex].level = level;
|
2009-04-25 13:15:05 +00:00
|
|
|
_itemsInPlay[itemIndex].block = block;
|
2009-03-24 07:18:16 +00:00
|
|
|
_itemsInPlay[itemIndex].flyingHeight = flyingHeight;
|
|
|
|
_itemsInPlay[itemIndex].shpCurFrame_flg |= 0x4000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-06 23:59:12 +00:00
|
|
|
bool LoLEngine::addItemToInventory(int itemIndex) {
|
|
|
|
int pos = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (; i < 48; i++) {
|
|
|
|
pos = _inventoryCurItem + i;
|
|
|
|
if (pos > 47)
|
|
|
|
pos -= 48;
|
|
|
|
|
|
|
|
if (!_inventory[pos])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 48)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while ((_inventoryCurItem > pos) || ((_inventoryCurItem + 9) <= pos)) {
|
|
|
|
if (++_inventoryCurItem > 47)
|
|
|
|
_inventoryCurItem -= 48;
|
|
|
|
gui_drawInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
_inventory[pos] = itemIndex;
|
|
|
|
gui_drawInventory();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-18 17:04:24 +00:00
|
|
|
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-15 16:48:20 +00:00
|
|
|
ItemInPlay *LoLEngine::findObject(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-03-16 21:20:34 +00:00
|
|
|
void LoLEngine::runItemScript(int charNum, int item, int sub, int next, 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);
|
|
|
|
|
2009-03-16 21:20:34 +00:00
|
|
|
scriptState.regs[0] = sub;
|
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-03-16 21:20:34 +00:00
|
|
|
scriptState.regs[3] = next;
|
2009-01-18 17:04:24 +00:00
|
|
|
scriptState.regs[4] = reg4;
|
|
|
|
|
2009-03-16 21:20:34 +00:00
|
|
|
if (_emc->isValid(&scriptState)) {
|
|
|
|
if (*(scriptState.ip - 1) & sub) {
|
|
|
|
while (_emc->isValid(&scriptState))
|
|
|
|
_emc->run(&scriptState);
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 17:04:24 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2009-06-07 20:43:43 +00:00
|
|
|
if (itemIndex && !(_flagsTable[31] & 0x02)) {
|
2009-02-21 17:24:50 +00:00
|
|
|
mouseOffs = 10;
|
2009-03-24 07:18:16 +00:00
|
|
|
if (!_currentControlMode || textEnabled())
|
2009-02-21 17:24:50 +00:00
|
|
|
_txt->printMessage(0, getLangString(0x403E), getLangString(_itemProperties[_itemsInPlay[itemIndex].itemPropertyIndex].nameStringId));
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemInHand = itemIndex;
|
|
|
|
_screen->setMouseCursor(mouseOffs, mouseOffs, getItemIconShapePtr(itemIndex));
|
|
|
|
}
|
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
bool LoLEngine::itemEquipped(int charNum, uint16 itemType) {
|
|
|
|
if (charNum < 0 || charNum > 3)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!(_characters[charNum].flags & 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (int i = 0; i < 11; i++) {
|
|
|
|
if (!_characters[charNum].items[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (_itemsInPlay[_characters[charNum].items[i]].itemPropertyIndex == itemType)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-16 21:20:34 +00:00
|
|
|
void LoLEngine::setItemPosition(int item, uint16 x, uint16 y, int flyingHeight, int b) {
|
|
|
|
if (!flyingHeight) {
|
2009-03-15 16:48:20 +00:00
|
|
|
x = (x & 0xffc0) | 0x40;
|
|
|
|
y = (y & 0xffc0) | 0x40;
|
|
|
|
}
|
2009-02-23 20:17:53 +00:00
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
uint16 block = calcBlockIndex(x, y);
|
|
|
|
_itemsInPlay[item].x = x;
|
|
|
|
_itemsInPlay[item].y = y;
|
2009-04-25 13:15:05 +00:00
|
|
|
_itemsInPlay[item].block = block;
|
2009-03-16 21:20:34 +00:00
|
|
|
_itemsInPlay[item].flyingHeight = flyingHeight;
|
2009-02-23 20:17:53 +00:00
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
if (b)
|
|
|
|
_itemsInPlay[item].shpCurFrame_flg |= 0x4000;
|
|
|
|
else
|
|
|
|
_itemsInPlay[item].shpCurFrame_flg &= 0xbfff;
|
2009-02-23 20:17:53 +00:00
|
|
|
|
2009-05-21 13:13:09 +00:00
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
assignItemToBlock(&_levelBlockProperties[block].assignedObjects, item);
|
|
|
|
reassignDrawObjects(_currentDirection, item, &_levelBlockProperties[block], false);
|
2009-05-21 13:13:09 +00:00
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
if (b)
|
|
|
|
runLevelScriptCustom(block, 0x80, -1, item, 0, 0);
|
2009-02-23 20:17:53 +00:00
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
checkSceneUpdateNeed(block);
|
|
|
|
}
|
2009-02-23 20:17:53 +00:00
|
|
|
|
2009-03-24 07:18:16 +00:00
|
|
|
void LoLEngine::removeLevelItem(int item, int block) {
|
2009-03-16 21:20:34 +00:00
|
|
|
removeAssignedObjectFromBlock(&_levelBlockProperties[block], item);
|
|
|
|
removeDrawObjectFromBlock(&_levelBlockProperties[block], item);
|
2009-03-15 16:48:20 +00:00
|
|
|
runLevelScriptCustom(block, 0x100, -1, item, 0, 0);
|
2009-04-25 13:15:05 +00:00
|
|
|
_itemsInPlay[item].block = 0;
|
2009-03-15 16:48:20 +00:00
|
|
|
_itemsInPlay[item].level = 0;
|
|
|
|
}
|
2009-02-23 20:17:53 +00:00
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
bool LoLEngine::launchObject(int objectType, int item, int startX, int startY, int flyingHeight, int direction, int, int attackerId, int c) {
|
2009-05-10 13:40:28 +00:00
|
|
|
int sp = checkDrawObjectSpace(_partyPosX, _partyPosY, startX, startY);
|
2009-03-24 07:18:16 +00:00
|
|
|
FlyingObject *t = _flyingObjects;
|
2009-03-16 21:20:34 +00:00
|
|
|
int slot = -1;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (; i < 8; i++) {
|
|
|
|
if (!t->enable) {
|
|
|
|
sp = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-10 13:40:28 +00:00
|
|
|
int csp = checkDrawObjectSpace(_partyPosX, _partyPosY, t->x, t->y);
|
2009-03-16 21:20:34 +00:00
|
|
|
if (csp > sp){
|
|
|
|
sp = csp;
|
|
|
|
slot = i;
|
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sp != -1 && slot != -1) {
|
|
|
|
i = slot;
|
|
|
|
|
2009-03-24 07:18:16 +00:00
|
|
|
t = &_flyingObjects[i];
|
2009-04-25 13:15:05 +00:00
|
|
|
endObjectFlight(t, startX, startY, 8);
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 8)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
t->enable = 1;
|
2009-04-25 13:15:05 +00:00
|
|
|
t->objectType = objectType;
|
2009-03-16 21:20:34 +00:00
|
|
|
t->item = item;
|
2009-04-25 13:15:05 +00:00
|
|
|
t->x = startX;
|
|
|
|
t->y = startY;
|
2009-03-16 21:20:34 +00:00
|
|
|
t->flyingHeight = flyingHeight;
|
|
|
|
t->direction = direction;
|
|
|
|
t->distance = 255;
|
2009-04-25 13:15:05 +00:00
|
|
|
t->attackerId = attackerId;
|
2009-03-16 21:20:34 +00:00
|
|
|
t->flags = 7;
|
|
|
|
t->wallFlags = 2;
|
2009-05-21 13:13:09 +00:00
|
|
|
t->c = c;
|
2009-03-16 21:20:34 +00:00
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
if (attackerId != -1) {
|
|
|
|
if (attackerId & 0x8000) {
|
2009-03-16 21:20:34 +00:00
|
|
|
t->flags &= 0xfd;
|
|
|
|
} else {
|
|
|
|
t->flags &= 0xfb;
|
2009-04-25 13:15:05 +00:00
|
|
|
increaseExperience(attackerId, 1, 2);
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateObjectFlightPosition(t);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoLEngine::endObjectFlight(FlyingObject *t, int x, int y, int objectOnNextBlock) {
|
|
|
|
int cx = x;
|
|
|
|
int cy = y;
|
|
|
|
uint16 block = calcBlockIndex(t->x, t->y);
|
|
|
|
removeAssignedObjectFromBlock(&_levelBlockProperties[block], t->item);
|
|
|
|
removeDrawObjectFromBlock(&_levelBlockProperties[block], t->item);
|
|
|
|
|
|
|
|
if (objectOnNextBlock == 1) {
|
|
|
|
cx = t->x;
|
|
|
|
cy = t->y;
|
|
|
|
}
|
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
if (t->objectType == 0 || t->objectType == 1) {
|
2009-03-16 21:20:34 +00:00
|
|
|
objectFlightProcessHits(t, cx, cy, objectOnNextBlock);
|
|
|
|
t->x = (cx & 0xffc0) | 0x40;
|
|
|
|
t->y = (cy & 0xffc0) | 0x40;
|
|
|
|
t->flyingHeight = 0;
|
|
|
|
updateObjectFlightPosition(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
t->enable = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoLEngine::processObjectFlight(FlyingObject *t, int x, int y) {
|
|
|
|
int bl = calcBlockIndex(t->x, t->y);
|
|
|
|
LevelBlockProperty *l = &_levelBlockProperties[bl];
|
|
|
|
removeAssignedObjectFromBlock(l, t->item);
|
|
|
|
removeDrawObjectFromBlock(l, t->item);
|
|
|
|
t->x = x;
|
|
|
|
t->y = y;
|
|
|
|
updateObjectFlightPosition(t);
|
|
|
|
checkSceneUpdateNeed(bl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoLEngine::updateObjectFlightPosition(FlyingObject *t) {
|
2009-04-25 13:15:05 +00:00
|
|
|
if (t->objectType == 0) {
|
2009-03-16 21:20:34 +00:00
|
|
|
setItemPosition(t->item, t->x, t->y, t->flyingHeight, (t->flyingHeight == 0) ? 1 : 0);
|
2009-04-25 13:15:05 +00:00
|
|
|
} else if (t->objectType == 1) {
|
2009-03-16 21:20:34 +00:00
|
|
|
if (t->flyingHeight == 0) {
|
|
|
|
deleteItem(t->item);
|
|
|
|
checkSceneUpdateNeed(calcBlockIndex(t->x, t->y));
|
|
|
|
} else {
|
|
|
|
setItemPosition(t->item, t->x, t->y, t->flyingHeight, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoLEngine::objectFlightProcessHits(FlyingObject *t, int x, int y, int objectOnNextBlock) {
|
2009-03-21 14:30:25 +00:00
|
|
|
uint16 r = 0;
|
2009-03-16 21:20:34 +00:00
|
|
|
|
|
|
|
if (objectOnNextBlock == 1) {
|
2009-04-25 13:15:05 +00:00
|
|
|
runLevelScriptCustom(calcNewBlockPosition(_itemsInPlay[t->item].block, t->direction >> 1), 0x8000, -1, t->item, 0, 0);
|
2009-03-16 21:20:34 +00:00
|
|
|
|
|
|
|
} else if (objectOnNextBlock == 2) {
|
|
|
|
if (_itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000) {
|
2009-04-25 13:15:05 +00:00
|
|
|
int o = _levelBlockProperties[_itemsInPlay[t->item].block].assignedObjects;
|
2009-03-16 21:20:34 +00:00
|
|
|
while (o & 0x8000) {
|
|
|
|
ItemInPlay *i = findObject(o);
|
|
|
|
o = i->nextAssignedObject;
|
2009-04-25 13:15:05 +00:00
|
|
|
runItemScript(t->attackerId, t->item, 0x8000, o, 0);
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
2009-05-21 13:13:09 +00:00
|
|
|
|
2009-03-16 21:20:34 +00:00
|
|
|
} else {
|
2009-04-25 13:15:05 +00:00
|
|
|
r = getNearestMonsterFromPos(x, y);
|
2009-06-06 18:46:07 +00:00
|
|
|
runItemScript(t->attackerId, t->item, 0x8000, r, 0);
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (objectOnNextBlock == 4) {
|
2009-05-10 23:08:32 +00:00
|
|
|
_partyAwake = true;
|
2009-03-16 21:20:34 +00:00
|
|
|
if (_itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (_characters[i].flags & 1)
|
2009-04-25 13:15:05 +00:00
|
|
|
runItemScript(t->attackerId, t->item, 0x8000, i, 0);
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-04-25 13:15:05 +00:00
|
|
|
r = getNearestPartyMemberFromPos(x, y);
|
2009-06-06 18:46:07 +00:00
|
|
|
runItemScript(t->attackerId, t->item, 0x8000, r, 0);
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
2009-06-25 01:30:12 +00:00
|
|
|
}
|
2009-03-16 21:20:34 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
void LoLEngine::updateFlyingObject(FlyingObject *t) {
|
2009-03-16 21:20:34 +00:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
getNextStepCoords(t->x, t->y, x, y, t->direction);
|
2009-05-10 13:40:28 +00:00
|
|
|
// WORKAROUND: The next line seems to be bugged in the original code. I have fixed it in a way that at least seems to work fine.
|
|
|
|
int objectOnNextBlock = checkBlockBeforeObjectPlacement(x, y, _itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000 ? 127 : 63, t->flags, t->wallFlags);
|
2009-03-16 21:20:34 +00:00
|
|
|
if (objectOnNextBlock) {
|
|
|
|
endObjectFlight(t, x, y, objectOnNextBlock);
|
|
|
|
} else {
|
|
|
|
if (--t->distance) {
|
|
|
|
processObjectFlight(t, x, y);
|
|
|
|
} else {
|
|
|
|
endObjectFlight(t, x, y, 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
void LoLEngine::assignItemToBlock(uint16 *assignedBlockObjects, int id) {
|
|
|
|
while (*assignedBlockObjects & 0x8000) {
|
|
|
|
ItemInPlay *tmp = findObject(*assignedBlockObjects);
|
|
|
|
assignedBlockObjects = &tmp->nextAssignedObject;
|
2009-02-23 20:17:53 +00:00
|
|
|
}
|
2009-03-15 16:48:20 +00:00
|
|
|
|
|
|
|
ItemInPlay *newObject = findObject(id);
|
|
|
|
newObject->nextAssignedObject = *assignedBlockObjects;
|
|
|
|
newObject->level = -1;
|
|
|
|
*assignedBlockObjects = id;
|
2009-02-23 20:17:53 +00:00
|
|
|
}
|
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
int LoLEngine::checkDrawObjectSpace(int itemX, int itemY, int partyX, int partyY) {
|
2009-03-01 14:45:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
int LoLEngine::checkSceneForItems(uint16 *blockDrawObjects, int colour) {
|
|
|
|
while (*blockDrawObjects) {
|
|
|
|
if (!(*blockDrawObjects & 0x8000)) {
|
|
|
|
if (!--colour)
|
|
|
|
return *blockDrawObjects;
|
|
|
|
}
|
2009-02-21 23:20:14 +00:00
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
ItemInPlay *i = findObject(*blockDrawObjects);
|
|
|
|
blockDrawObjects = &i->nextDrawObject;
|
|
|
|
}
|
2009-02-21 23:20:14 +00:00
|
|
|
|
2009-03-15 16:48:20 +00:00
|
|
|
return -1;
|
2009-02-21 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Kyra
|
2009-01-18 17:04:24 +00:00
|
|
|
|
2009-03-04 11:53:25 +00:00
|
|
|
#endif // ENABLE_LOL
|
2009-01-18 17:04:24 +00:00
|
|
|
|