aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/items_lol.cpp
diff options
context:
space:
mode:
authorathrxx2011-12-12 20:10:57 +0100
committerathrxx2011-12-28 00:01:32 +0100
commit6786c41f4fd56d588e61f329b6d81f580e9b040f (patch)
tree78d636269ddeea94a0425967eaf50efb3d034f44 /engines/kyra/items_lol.cpp
parentcbfdd227a173238cd7069264c2f83bdf247ca1d6 (diff)
downloadscummvm-rg350-6786c41f4fd56d588e61f329b6d81f580e9b040f.tar.gz
scummvm-rg350-6786c41f4fd56d588e61f329b6d81f580e9b040f.tar.bz2
scummvm-rg350-6786c41f4fd56d588e61f329b6d81f580e9b040f.zip
KYRA: (LOL) - refactor item/monster structs
Diffstat (limited to 'engines/kyra/items_lol.cpp')
-rw-r--r--engines/kyra/items_lol.cpp83
1 files changed, 69 insertions, 14 deletions
diff --git a/engines/kyra/items_lol.cpp b/engines/kyra/items_lol.cpp
index 0d6e99a696..e6cd9355fc 100644
--- a/engines/kyra/items_lol.cpp
+++ b/engines/kyra/items_lol.cpp
@@ -27,6 +27,68 @@
namespace Kyra {
+LoLObject *LoLEngine::findObject(uint16 index) {
+ if (index & 0x8000)
+ return &_monsters[index & 0x7fff];
+ else
+ return &_itemsInPlay[index];
+}
+
+int LoLEngine::calcObjectPosition(LoLObject *i, uint16 direction) {
+ int x = i->x;
+ int y = i->y;
+
+ calcSpriteRelPosition(_partyPosX, _partyPosY, x, y, direction);
+
+ if (y < 0)
+ y = 0;
+
+ int res = (i->flyingHeight << 12);
+ res |= (4095 - y);
+
+ return res;
+}
+
+void LoLEngine::removeAssignedObjectFromBlock(LevelBlockProperty *l, uint16 id) {
+ uint16 *blockItemIndex = &l->assignedObjects;
+ LoLObject *i = 0;
+
+ while (*blockItemIndex) {
+ if (*blockItemIndex == id) {
+ i = findObject(id);
+ *blockItemIndex = i->nextAssignedObject;
+ i->nextAssignedObject = 0;
+ return;
+ }
+
+ i = findObject(*blockItemIndex);
+ blockItemIndex = &i->nextAssignedObject;
+ }
+}
+
+void LoLEngine::removeDrawObjectFromBlock(LevelBlockProperty *l, uint16 id) {
+ uint16 *blockItemIndex = &l->drawObjects;
+ LoLObject *i = 0;
+
+ while (*blockItemIndex) {
+ if (*blockItemIndex == id) {
+ i = findObject(id);
+ *blockItemIndex = i->nextDrawObject;
+ i->nextDrawObject = 0;
+ return;
+ }
+
+ i = findObject(*blockItemIndex);
+ blockItemIndex = &i->nextDrawObject;
+ }
+}
+
+void LoLEngine::assignObjectToBlock(uint16 *assignedBlockObjects, uint16 id) {
+ LoLObject *t = findObject(id);
+ t->nextAssignedObject = *assignedBlockObjects;
+ *assignedBlockObjects = id;
+}
+
void LoLEngine::giveCredits(int credits, int redraw) {
if (redraw)
snd_playSoundEffect(101, -1);
@@ -156,7 +218,7 @@ Item LoLEngine::makeItem(int itemType, int curFrame, int flags) {
}
}
- memset(&_itemsInPlay[slot], 0, sizeof(ItemInPlay));
+ memset(&_itemsInPlay[slot], 0, sizeof(LoLItem));
_itemsInPlay[slot].itemPropertyIndex = itemType;
_itemsInPlay[slot].shpCurFrame_flg = (curFrame & 0x1fff) | flags;
@@ -221,17 +283,10 @@ bool LoLEngine::isItemMoveable(Item itemIndex) {
}
void LoLEngine::deleteItem(Item itemIndex) {
- memset(&_itemsInPlay[itemIndex], 0, sizeof(ItemInPlay));
+ memset(&_itemsInPlay[itemIndex], 0, sizeof(LoLItem));
_itemsInPlay[itemIndex].shpCurFrame_flg |= 0x8000;
}
-ItemInPlay *LoLEngine::findObject(uint16 index) {
- if (index & 0x8000)
- return (ItemInPlay *)&_monsters[index & 0x7fff];
- else
- return &_itemsInPlay[index];
-}
-
void LoLEngine::runItemScript(int charNum, Item item, int flags, int next, int reg4) {
EMCState scriptState;
memset(&scriptState, 0, sizeof(EMCState));
@@ -443,7 +498,7 @@ void LoLEngine::objectFlightProcessHits(FlyingObject *t, int x, int y, int objec
if (_itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000) {
int o = _levelBlockProperties[_itemsInPlay[t->item].block].assignedObjects;
while (o & 0x8000) {
- ItemInPlay *i = findObject(o);
+ LoLObject *i = findObject(o);
o = i->nextAssignedObject;
runItemScript(t->attackerId, t->item, 0x8000, o, 0);
}
@@ -502,13 +557,13 @@ void LoLEngine::updateFlyingObject(FlyingObject *t) {
void LoLEngine::assignItemToBlock(uint16 *assignedBlockObjects, int id) {
while (*assignedBlockObjects & 0x8000) {
- ItemInPlay *tmp = findObject(*assignedBlockObjects);
+ LoLObject *tmp = findObject(*assignedBlockObjects);
assignedBlockObjects = &tmp->nextAssignedObject;
}
- ItemInPlay *newObject = findObject(id);
+ LoLObject *newObject = findObject(id);
newObject->nextAssignedObject = *assignedBlockObjects;
- newObject->level = -1;
+ ((LoLItem*)newObject)->level = -1;
*assignedBlockObjects = id;
}
@@ -531,7 +586,7 @@ int LoLEngine::checkSceneForItems(uint16 *blockDrawObjects, int color) {
return *blockDrawObjects;
}
- ItemInPlay *i = findObject(*blockDrawObjects);
+ LoLObject *i = findObject(*blockDrawObjects);
blockDrawObjects = &i->nextDrawObject;
}