From 6786c41f4fd56d588e61f329b6d81f580e9b040f Mon Sep 17 00:00:00 2001 From: athrxx Date: Mon, 12 Dec 2011 20:10:57 +0100 Subject: KYRA: (LOL) - refactor item/monster structs --- engines/kyra/items_lol.cpp | 83 +++++++++++++++++++++++++----- engines/kyra/lol.cpp | 28 +++++----- engines/kyra/lol.h | 71 +++++++++++++------------- engines/kyra/saveload_lol.cpp | 24 ++++----- engines/kyra/scene_lol.cpp | 16 +++--- engines/kyra/script_lol.cpp | 18 +++---- engines/kyra/sprites_lol.cpp | 115 +++++++++++------------------------------- 7 files changed, 177 insertions(+), 178 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; } diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp index a57fe4fdb8..62143e5f72 100644 --- a/engines/kyra/lol.cpp +++ b/engines/kyra/lol.cpp @@ -390,8 +390,8 @@ Common::Error LoLEngine::init() { _pageBuffer2 = new uint8[0xfa00]; memset(_pageBuffer2, 0, 0xfa00); - _itemsInPlay = new ItemInPlay[400]; - memset(_itemsInPlay, 0, sizeof(ItemInPlay) * 400); + _itemsInPlay = new LoLItem[400]; + memset(_itemsInPlay, 0, sizeof(LoLItem) * 400); _characters = new LoLCharacter[4]; memset(_characters, 0, sizeof(LoLCharacter) * 4); @@ -404,8 +404,8 @@ Common::Error LoLEngine::init() { _wllAutomapData = new uint8[80]; memset(_wllAutomapData, 0, 80); - _monsters = new LoLMonsterInPlay[30]; - memset(_monsters, 0, 30 * sizeof(LoLMonsterInPlay)); + _monsters = new LoLMonster[30]; + memset(_monsters, 0, 30 * sizeof(LoLMonster)); _monsterProperties = new LoLMonsterProperty[5]; memset(_monsterProperties, 0, 5 * sizeof(LoLMonsterProperty)); @@ -821,7 +821,7 @@ void LoLEngine::startup() { for (int i = 0; i < _numHealiShapes; i++) _healiShapes[i] = _screen->makeShapeCopy(shp, i); - memset(_itemsInPlay, 0, 400 * sizeof(ItemInPlay)); + memset(_itemsInPlay, 0, 400 * sizeof(LoLItem)); for (int i = 0; i < 400; i++) _itemsInPlay[i].shpCurFrame_flg |= 0x8000; @@ -1946,7 +1946,7 @@ void LoLEngine::setupDialogueButtons(int numStr, const char *s1, const char *s2, removeInputTop(); } -void LoLEngine::giveItemToMonster(LoLMonsterInPlay *monster, Item item) { +void LoLEngine::giveItemToMonster(LoLMonster *monster, Item item) { uint16 *c = &monster->assignedItems; while (*c) c = &_itemsInPlay[*c].nextAssignedObject; @@ -2397,7 +2397,7 @@ int LoLEngine::processMagicIce(int charNum, int spellLevel) { int might = rollDice(iceDamageMin[spellLevel], iceDamageMax[spellLevel]) + iceDamageAdd[spellLevel]; int dmg = calcInflictableDamagePerItem(charNum, 0, might, 3, 2); - LoLMonsterInPlay *m = &_monsters[o & 0x7fff]; + LoLMonster *m = &_monsters[o & 0x7fff]; if (m->hitPoints <= dmg) { increaseExperience(charNum, 2, m->hitPoints); o = m->nextAssignedObject; @@ -2476,7 +2476,7 @@ int LoLEngine::processMagicFireball(int charNum, int spellLevel) { while (o & 0x8000) { static const uint8 fireballDamage[] = { 20, 40, 80, 100 }; int dmg = calcInflictableDamagePerItem(charNum, o, fireballDamage[spellLevel], 4, 1); - LoLMonsterInPlay *m = &_monsters[o & 0x7fff]; + LoLMonster *m = &_monsters[o & 0x7fff]; o = m->nextAssignedObject; _envSfxUseQueue = true; inflictDamage(m->id | 0x8000, dmg, charNum, 2, 4); @@ -2641,7 +2641,7 @@ int LoLEngine::processMagicHandOfFate(int spellLevel) { uint16 o = _levelBlockProperties[b1].assignedObjects; while (o & 0x8000) { uint16 o2 = o; - LoLMonsterInPlay *m = &_monsters[o & 0x7fff]; + LoLMonster *m = &_monsters[o & 0x7fff]; o = findObject(o)->nextAssignedObject; int nX = 0; int nY = 0; @@ -2910,7 +2910,7 @@ int LoLEngine::processMagicVaelansCube() { uint16 o = _levelBlockProperties[bl].assignedObjects; while (o & 0x8000) { - LoLMonsterInPlay *m = &_monsters[o & 0x7fff]; + LoLMonster *m = &_monsters[o & 0x7fff]; if (m->properties->flags & 0x1000) { inflictDamage(o, 100, 0xffff, 0, 0x80); v = 1; @@ -3390,7 +3390,7 @@ int LoLEngine::calcInflictableDamage(int16 attacker, int16 target, int hitType) } int LoLEngine::inflictDamage(uint16 target, int damage, uint16 attacker, int skill, int flags) { - LoLMonsterInPlay *m = 0; + LoLMonster *m = 0; LoLCharacter *c = 0; if (target & 0x8000) { @@ -3607,7 +3607,7 @@ void LoLEngine::checkForPartyDeath() { } } -void LoLEngine::applyMonsterAttackSkill(LoLMonsterInPlay *monster, int16 target, int16 damage) { +void LoLEngine::applyMonsterAttackSkill(LoLMonster *monster, int16 target, int16 damage) { if (rollDice(1, 100) > monster->properties->attackSkillChance) return; @@ -3677,7 +3677,7 @@ void LoLEngine::applyMonsterAttackSkill(LoLMonsterInPlay *monster, int16 target, } } -void LoLEngine::applyMonsterDefenseSkill(LoLMonsterInPlay *monster, int16 attacker, int flags, int skill, int damage) { +void LoLEngine::applyMonsterDefenseSkill(LoLMonster *monster, int16 attacker, int flags, int skill, int damage) { if (rollDice(1, 100) > monster->properties->defenseSkillChance) return; @@ -3936,7 +3936,7 @@ uint16 LoLEngine::getNearestMonsterFromCharacterForBlock(uint16 block, int charN int o = _levelBlockProperties[block].assignedObjects; while (o & 0x8000) { - LoLMonsterInPlay *m = &_monsters[o & 0x7fff]; + LoLMonster *m = &_monsters[o & 0x7fff]; if (m->mode >= 13) { o = m->nextAssignedObject; continue; diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h index e44857ec2b..bb8f24eb66 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -108,18 +108,21 @@ struct LoLMonsterProperty { uint8 sounds[3]; }; -struct LoLMonsterInPlay { +struct LoLObject { uint16 nextAssignedObject; uint16 nextDrawObject; uint8 flyingHeight; uint16 block; uint16 x; uint16 y; +}; + +struct LoLMonster : public LoLObject { + uint8 destDirection; int8 shiftStep; uint16 destX; uint16 destY; - uint8 destDirection; int8 hitOffsX; int8 hitOffsY; uint8 currentSubFrame; @@ -141,13 +144,7 @@ struct LoLMonsterInPlay { uint8 equipmentShapes[4]; }; -struct ItemInPlay { - uint16 nextAssignedObject; - uint16 nextDrawObject; - uint8 flyingHeight; - uint16 block; - uint16 x; - uint16 y; +struct LoLItem : public LoLObject { int8 level; uint16 itemPropertyIndex; uint16 shpCurFrame_flg; @@ -906,7 +903,7 @@ private: void loadLevel(int index); void addLevelItems(); void loadLevelWallData(int fileIndex, bool mapShapes); - void assignBlockObject(LevelBlockProperty *l, uint16 item); + void assignBlockItem(LevelBlockProperty *l, uint16 item); int assignLevelDecorationShapes(int index); uint8 *getLevelDecorationShapes(int index); void releaseDecorations(int first = 0, int num = 400); @@ -1028,6 +1025,13 @@ private: const int16 *_dscDoorMonsterX; const int16 *_dscDoorMonsterY; + // objects (item/monster common) + LoLObject *findObject(uint16 index); + int calcObjectPosition(LoLObject *obj, uint16 direction); + void removeAssignedObjectFromBlock(LevelBlockProperty *l, uint16 id); + void removeDrawObjectFromBlock(LevelBlockProperty *l, uint16 id); + void assignObjectToBlock(uint16 *assignedBlockObjects, uint16 id); + // items void giveCredits(int credits, int redraw); void takeCredits(int credits, int redraw); @@ -1036,7 +1040,6 @@ private: bool addItemToInventory(Item itemIndex); bool isItemMoveable(Item itemIndex); void deleteItem(Item itemIndex); - ItemInPlay *findObject(uint16 index); void runItemScript(int charNum, Item item, int flags, int next, int reg4); void setHandItem(Item itemIndex); bool itemEquipped(int charNum, uint16 itemType); @@ -1057,7 +1060,7 @@ private: uint8 _moneyColumnHeight[5]; uint16 _credits; - ItemInPlay *_itemsInPlay; + LoLItem *_itemsInPlay; ItemProperty *_itemProperties; Item _itemInHand; @@ -1084,16 +1087,13 @@ private: void loadMonsterShapes(const char *file, int monsterIndex, int b); void releaseMonsterShapes(int monsterIndex); int deleteMonstersFromBlock(int block); - void setMonsterMode(LoLMonsterInPlay *monster, int mode); - bool updateMonsterAdjustBlocks(LoLMonsterInPlay *monster); - void placeMonster(LoLMonsterInPlay *monster, uint16 x, uint16 y); + void setMonsterMode(LoLMonster *monster, int mode); + bool updateMonsterAdjustBlocks(LoLMonster *monster); + void placeMonster(LoLMonster *monster, uint16 x, uint16 y); int calcMonsterDirection(uint16 x1, uint16 y1, uint16 x2, uint16 y2); - void setMonsterDirection(LoLMonsterInPlay *monster, int dir); - void monsterDropItems(LoLMonsterInPlay *monster); - void removeAssignedObjectFromBlock(LevelBlockProperty *l, uint16 id); - void removeDrawObjectFromBlock(LevelBlockProperty *l, uint16 id); - void assignMonsterToBlock(uint16 *assignedBlockObjects, uint16 id); - void giveItemToMonster(LoLMonsterInPlay *monster, Item item); + void setMonsterDirection(LoLMonster *monster, int dir); + void monsterDropItems(LoLMonster *monster); + void giveItemToMonster(LoLMonster *monster, Item item); int checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 objectWidth, uint16 testFlag, uint16 wallFlag); int checkBlockForWallsAndSufficientSpace(int block, int x, int y, int objectWidth, int testFlag, int wallFlag); int calcMonsterSkillLevel(int id, int a); @@ -1104,30 +1104,29 @@ private: void drawBlockObjects(int blockArrayIndex); void drawMonster(uint16 id); - int getMonsterCurFrame(LoLMonsterInPlay *m, uint16 dirFlags); + int getMonsterCurFrame(LoLMonster *m, uint16 dirFlags); void reassignDrawObjects(uint16 direction, uint16 itemIndex, LevelBlockProperty *l, bool flag); void redrawSceneItem(); - int calcItemMonsterPosition(ItemInPlay *i, uint16 direction); void calcSpriteRelPosition(uint16 x1, uint16 y1, int &x2, int &y2, uint16 direction); void drawDoor(uint8 *shape, uint8 *doorPalette, int index, int unk2, int w, int h, int flags); void drawDoorOrMonsterEquipment(uint8 *shape, uint8 *objectPalette, int x, int y, int flags, const uint8 *brightnessOverlay); uint8 *drawItemOrMonster(uint8 *shape, uint8 *monsterPalette, int x, int y, int fineX, int fineY, int flags, int tblValue, bool vflip); int calcDrawingLayerParameters(int srcX, int srcY, int &x2, int &y2, uint16 &w, uint16 &h, uint8 *shape, int vflip); - void updateMonster(LoLMonsterInPlay *monster); - void moveMonster(LoLMonsterInPlay *monster); - void walkMonster(LoLMonsterInPlay *monster); - bool chasePartyWithDistanceAttacks(LoLMonsterInPlay *monster); - void chasePartyWithCloseAttacks(LoLMonsterInPlay *monster); - int walkMonsterCalcNextStep(LoLMonsterInPlay *monster); + void updateMonster(LoLMonster *monster); + void moveMonster(LoLMonster *monster); + void walkMonster(LoLMonster *monster); + bool chasePartyWithDistanceAttacks(LoLMonster *monster); + void chasePartyWithCloseAttacks(LoLMonster *monster); + int walkMonsterCalcNextStep(LoLMonster *monster); int checkForPossibleDistanceAttack(uint16 monsterBlock, int direction, int distance, uint16 curBlock); - int walkMonsterCheckDest(int x, int y, LoLMonsterInPlay *monster, int unk); + int walkMonsterCheckDest(int x, int y, LoLMonster *monster, int unk); void getNextStepCoords(int16 monsterX, int16 monsterY, int &newX, int &newY, uint16 direction); - void rearrangeAttackingMonster(LoLMonsterInPlay *monster); - void moveStrayingMonster(LoLMonsterInPlay *monster); - void killMonster(LoLMonsterInPlay *monster); + void rearrangeAttackingMonster(LoLMonster *monster); + void moveStrayingMonster(LoLMonster *monster); + void killMonster(LoLMonster *monster); - LoLMonsterInPlay *_monsters; + LoLMonster *_monsters; LoLMonsterProperty *_monsterProperties; uint8 **_monsterDecorationShapes; uint8 _monsterAnimType[3]; @@ -1241,8 +1240,8 @@ private: int calcInflictableDamagePerItem(int16 attacker, int16 target, uint16 itemMight, int index, int hitType); void checkForPartyDeath(); - void applyMonsterAttackSkill(LoLMonsterInPlay *monster, int16 target, int16 damage); - void applyMonsterDefenseSkill(LoLMonsterInPlay *monster, int16 attacker, int flags, int skill, int damage); + void applyMonsterAttackSkill(LoLMonster *monster, int16 target, int16 damage); + void applyMonsterDefenseSkill(LoLMonster *monster, int16 attacker, int flags, int skill, int damage); int removeCharacterItem(int charNum, int itemFlags); int paralyzePoisonCharacter(int charNum, int typeFlag, int immunityFlags, int hitChance, int redraw); void paralyzePoisonAllCharacters(int typeFlag, int immunityFlags, int hitChance); diff --git a/engines/kyra/saveload_lol.cpp b/engines/kyra/saveload_lol.cpp index 3edc4759ca..7736d45540 100644 --- a/engines/kyra/saveload_lol.cpp +++ b/engines/kyra/saveload_lol.cpp @@ -188,7 +188,7 @@ Common::Error LoLEngine::loadGameState(int slot) { } for (int i = 0; i < 400; i++) { - ItemInPlay *t = &_itemsInPlay[i]; + LoLItem *t = &_itemsInPlay[i]; t->nextAssignedObject = in.readUint16(); t->nextDrawObject = in.readUint16(); t->flyingHeight = in.readByte(); @@ -229,12 +229,12 @@ Common::Error LoLEngine::loadGameState(int slot) { _lvlTempData[i] = new LevelTempData; _lvlTempData[i]->wallsXorData = new uint8[4096]; _lvlTempData[i]->flags = new uint16[1024]; - LoLMonsterInPlay *lm = new LoLMonsterInPlay[30]; + LoLMonster *lm = new LoLMonster[30]; _lvlTempData[i]->monsters = lm; FlyingObject *lf = new FlyingObject[_numFlyingObjects]; _lvlTempData[i]->flyingObjects = lf; LevelTempData *l = _lvlTempData[i]; - + uint32 next = in.pos() + 2500; if (header.originalSave) { @@ -254,7 +254,7 @@ Common::Error LoLEngine::loadGameState(int slot) { l->monsterDifficulty = in.readUint16(); for (int ii = 0; ii < 30; ii++) { - LoLMonsterInPlay *m = &lm[ii]; + LoLMonster *m = &lm[ii]; m->nextAssignedObject = in.readUint16(); m->nextDrawObject = in.readUint16(); m->flyingHeight = in.readByte(); @@ -381,7 +381,7 @@ Common::Error LoLEngine::saveGameStateIntern(int slot, const char *saveName, con for (int ii = 0; ii < 5; ii++) out->writeByte(c->characterUpdateDelay[ii]); } - + out->writeUint16BE(_currentBlock); out->writeUint16BE(_partyPosX); out->writeUint16BE(_partyPosY); @@ -416,7 +416,7 @@ Common::Error LoLEngine::saveGameStateIntern(int slot, const char *saveName, con resetItems(0); for (int i = 0; i < 400; i++) { - ItemInPlay *t = &_itemsInPlay[i]; + LoLItem *t = &_itemsInPlay[i]; out->writeUint16BE(t->nextAssignedObject); out->writeUint16BE(t->nextDrawObject); out->writeByte(t->flyingHeight); @@ -439,11 +439,11 @@ Common::Error LoLEngine::saveGameStateIntern(int slot, const char *saveName, con for (int ii = 0; ii < 1024; ii++) out->writeByte(l->flags[ii] & 0xff); - LoLMonsterInPlay *lm = (LoLMonsterInPlay*)_lvlTempData[i]->monsters; + LoLMonster *lm = (LoLMonster*)_lvlTempData[i]->monsters; FlyingObject *lf = (FlyingObject*)_lvlTempData[i]->flyingObjects; for (int ii = 0; ii < 30; ii++) { - LoLMonsterInPlay *m = &lm[ii]; + LoLMonster *m = &lm[ii]; out->writeUint16BE(m->nextAssignedObject); out->writeUint16BE(m->nextDrawObject); out->writeByte(m->flyingHeight); @@ -537,8 +537,8 @@ void LoLEngine::restoreBlockTempData(int levelIndex) { } void *LoLEngine::generateMonsterTempData(LevelTempData *tmp) { - LoLMonsterInPlay *m = new LoLMonsterInPlay[30]; - memcpy(m, _monsters, sizeof(LoLMonsterInPlay) * 30); + LoLMonster *m = new LoLMonster[30]; + memcpy(m, _monsters, sizeof(LoLMonster) * 30); tmp->monsterDifficulty = _monsterDifficulty; return m; } @@ -562,7 +562,7 @@ void LoLEngine::restoreTempDataAdjustMonsterStrength(int index) { } void LoLEngine::restoreMonsterTempData(LevelTempData *tmp) { - memcpy(_monsters, tmp->monsters, sizeof(LoLMonsterInPlay) * 30); + memcpy(_monsters, tmp->monsters, sizeof(LoLMonster) * 30); for (int i = 0; i < 30; i++) { if (_monsters[i].block) { @@ -574,7 +574,7 @@ void LoLEngine::restoreMonsterTempData(LevelTempData *tmp) { } void LoLEngine::releaseMonsterTempData(LevelTempData *tmp) { - LoLMonsterInPlay *p = (LoLMonsterInPlay*)tmp->monsters; + LoLMonster *p = (LoLMonster*)tmp->monsters; delete[] p; } diff --git a/engines/kyra/scene_lol.cpp b/engines/kyra/scene_lol.cpp index 8610d20d02..fea9b27bd1 100644 --- a/engines/kyra/scene_lol.cpp +++ b/engines/kyra/scene_lol.cpp @@ -105,16 +105,16 @@ void LoLEngine::addLevelItems() { if (_itemsInPlay[i].level != _currentLevel) continue; - assignBlockObject(&_levelBlockProperties[_itemsInPlay[i].block], i); + assignBlockItem(&_levelBlockProperties[_itemsInPlay[i].block], i); _levelBlockProperties[_itemsInPlay[i].block].direction = 5; _itemsInPlay[i].nextDrawObject = 0; } } -void LoLEngine::assignBlockObject(LevelBlockProperty *l, uint16 item) { +void LoLEngine::assignBlockItem(LevelBlockProperty *l, uint16 item) { uint16 *index = &l->assignedObjects; - ItemInPlay *tmp = 0; + LoLObject *tmp = 0; while (*index & 0x8000) { tmp = findObject(*index); @@ -122,7 +122,7 @@ void LoLEngine::assignBlockObject(LevelBlockProperty *l, uint16 item) { } tmp = findObject(item); - tmp->level = -1; + ((LoLItem*)tmp)->level = -1; uint16 ix = *index; @@ -474,17 +474,17 @@ void LoLEngine::resetItems(int flag) { for (int i = 0; i < 1024; i++) { _levelBlockProperties[i].direction = 5; uint16 id = _levelBlockProperties[i].assignedObjects; - LoLMonsterInPlay *r = 0; + LoLObject *r = 0; while (id & 0x8000) { - r = (LoLMonsterInPlay *)findObject(id); + r = findObject(id); id = r->nextAssignedObject; } if (!id) continue; - ItemInPlay *it = &_itemsInPlay[id]; + LoLItem *it = &_itemsInPlay[id]; it->level = _currentLevel; it->block = i; if (r) @@ -496,7 +496,7 @@ void LoLEngine::resetItems(int flag) { } void LoLEngine::disableMonsters() { - memset(_monsters, 0, 30 * sizeof(LoLMonsterInPlay)); + memset(_monsters, 0, 30 * sizeof(LoLMonster)); for (int i = 0; i < 30; i++) _monsters[i].mode = 0x10; } diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp index 342014bfed..f81961a08b 100644 --- a/engines/kyra/script_lol.cpp +++ b/engines/kyra/script_lol.cpp @@ -286,7 +286,7 @@ int LoLEngine::olol_getItemPara(EMCState *script) { if (!stackPos(0)) return 0; - ItemInPlay *i = &_itemsInPlay[stackPos(0)]; + LoLItem *i = &_itemsInPlay[stackPos(0)]; ItemProperty *p = &_itemProperties[i->itemPropertyIndex]; switch (stackPos(1)) { @@ -811,11 +811,11 @@ int LoLEngine::olol_initMonster(EMCState *script) { return -1; for (uint8 i = 0; i < 30; i++) { - LoLMonsterInPlay *l = &_monsters[i]; + LoLMonster *l = &_monsters[i]; if (l->hitPoints || l->mode == 13) continue; - memset(l, 0, sizeof(LoLMonsterInPlay)); + memset(l, 0, sizeof(LoLMonster)); l->id = i; l->x = x; l->y = y; @@ -998,7 +998,7 @@ int LoLEngine::olol_inflictDamage(EMCState *script) { int LoLEngine::olol_moveMonster(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_moveMonster(%p) (%d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4)); - LoLMonsterInPlay *m = &_monsters[stackPos(0)]; + LoLMonster *m = &_monsters[stackPos(0)]; if (m->mode == 1 || m->mode == 2) { calcCoordinates(m->destX, m->destY, stackPos(1), stackPos(2), stackPos(3)); @@ -1193,7 +1193,7 @@ int LoLEngine::olol_changeMonsterStat(EMCState *script) { if (stackPos(0) == -1) return 1; - LoLMonsterInPlay *m = &_monsters[stackPos(0) & 0x7fff]; + LoLMonster *m = &_monsters[stackPos(0) & 0x7fff]; int16 d = stackPos(2); uint16 x = 0; @@ -1234,7 +1234,7 @@ int LoLEngine::olol_getMonsterStat(EMCState *script) { if (stackPos(0) == -1) return 0; - LoLMonsterInPlay *m = &_monsters[stackPos(0) & 0x7fff]; + LoLMonster *m = &_monsters[stackPos(0) & 0x7fff]; int d = stackPos(1); switch (d) { @@ -1547,7 +1547,7 @@ int LoLEngine::olol_moveBlockObjects(EMCState *script) { l &= 0x7fff; - LoLMonsterInPlay *m = &_monsters[l]; + LoLMonster *m = &_monsters[l]; setMonsterMode(m, 14); checkSceneUpdateNeed(m->block); @@ -1618,7 +1618,7 @@ int LoLEngine::olol_dummy1(EMCState *script) { int LoLEngine::olol_suspendMonster(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_suspendMonster(%p) (%d)", (const void *)script, stackPos(0)); - LoLMonsterInPlay *m = &_monsters[stackPos(0) & 0x7fff]; + LoLMonster *m = &_monsters[stackPos(0) & 0x7fff]; setMonsterMode(m, 14); checkSceneUpdateNeed(m->block); placeMonster(m, 0, 0); @@ -2035,7 +2035,7 @@ int LoLEngine::olol_changeItemTypeOrFlag(EMCState *script) { if (stackPos(0) < 1) return 0; - ItemInPlay *i = &_itemsInPlay[stackPos(0)]; + LoLItem *i = &_itemsInPlay[stackPos(0)]; int16 val = stackPos(2); if (stackPos(1) == 4) diff --git a/engines/kyra/sprites_lol.cpp b/engines/kyra/sprites_lol.cpp index 06d781328e..2fe896b085 100644 --- a/engines/kyra/sprites_lol.cpp +++ b/engines/kyra/sprites_lol.cpp @@ -159,7 +159,7 @@ int LoLEngine::deleteMonstersFromBlock(int block) { continue; } - LoLMonsterInPlay *m = &_monsters[i & 0x7fff]; + LoLMonster *m = &_monsters[i & 0x7fff]; cnt++; setMonsterMode(m, 14); @@ -173,7 +173,7 @@ int LoLEngine::deleteMonstersFromBlock(int block) { return cnt; } -void LoLEngine::setMonsterMode(LoLMonsterInPlay *monster, int mode) { +void LoLEngine::setMonsterMode(LoLMonster *monster, int mode) { if (monster->mode == 13 && mode != 14) return; @@ -210,7 +210,7 @@ void LoLEngine::setMonsterMode(LoLMonsterInPlay *monster, int mode) { } } -bool LoLEngine::updateMonsterAdjustBlocks(LoLMonsterInPlay *monster) { +bool LoLEngine::updateMonsterAdjustBlocks(LoLMonster *monster) { static const uint8 dims[] = { 0, 13, 9, 3 }; if (monster->properties->flags & 8) return true; @@ -251,7 +251,7 @@ bool LoLEngine::updateMonsterAdjustBlocks(LoLMonsterInPlay *monster) { return (fx1 >= fx2) ? false : true; } -void LoLEngine::placeMonster(LoLMonsterInPlay *monster, uint16 x, uint16 y) { +void LoLEngine::placeMonster(LoLMonster *monster, uint16 x, uint16 y) { bool cont = true; int t = monster->block; if (monster->block) { @@ -273,7 +273,7 @@ void LoLEngine::placeMonster(LoLMonsterInPlay *monster, uint16 x, uint16 y) { if (monster->block == 0) return; - assignMonsterToBlock(&_levelBlockProperties[monster->block].assignedObjects, ((uint16)monster->id) | 0x8000); + assignObjectToBlock(&_levelBlockProperties[monster->block].assignedObjects, ((uint16)monster->id) | 0x8000); _levelBlockProperties[monster->block].direction = 5; checkSceneUpdateNeed(monster->block); @@ -329,7 +329,7 @@ int LoLEngine::calcMonsterDirection(uint16 x1, uint16 y1, uint16 x2, uint16 y2) return retVal[r]; } -void LoLEngine::setMonsterDirection(LoLMonsterInPlay *monster, int dir) { +void LoLEngine::setMonsterDirection(LoLMonster *monster, int dir) { monster->direction = dir; if (!(dir & 1) || ((monster->direction - (monster->facing << 1)) >= 2)) @@ -338,7 +338,7 @@ void LoLEngine::setMonsterDirection(LoLMonsterInPlay *monster, int dir) { checkSceneUpdateNeed(monster->block); } -void LoLEngine::monsterDropItems(LoLMonsterInPlay *monster) { +void LoLEngine::monsterDropItems(LoLMonster *monster) { uint16 a = monster->assignedItems; while (a) { uint16 b = a; @@ -347,46 +347,6 @@ void LoLEngine::monsterDropItems(LoLMonsterInPlay *monster) { } } -void LoLEngine::removeAssignedObjectFromBlock(LevelBlockProperty *l, uint16 id) { - uint16 *blockItemIndex = &l->assignedObjects; - ItemInPlay *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; - ItemInPlay *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::assignMonsterToBlock(uint16 *assignedBlockObjects, uint16 id) { - ItemInPlay *t = findObject(id); - t->nextAssignedObject = *assignedBlockObjects; - *assignedBlockObjects = id; -} - int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 objectWidth, uint16 testFlag, uint16 wallFlag) { _objectLastDirection = 0; uint16 x2 = 0; @@ -503,7 +463,7 @@ int LoLEngine::checkBlockForWallsAndSufficientSpace(int block, int x, int y, int uint16 b = _levelBlockProperties[block].assignedObjects; while (b & 0x8000) { - LoLMonsterInPlay *monster = &_monsters[b & 0x7fff]; + LoLMonster *monster = &_monsters[b & 0x7fff]; if (monster->mode < 13) { int r = checkDrawObjectSpace(x, y, monster->x, monster->y); @@ -554,7 +514,7 @@ int LoLEngine::checkBlockOccupiedByParty(int x, int y, int testFlag) { void LoLEngine::drawBlockObjects(int blockArrayIndex) { LevelBlockProperty *l = _visibleBlocks[blockArrayIndex]; uint16 s = l->assignedObjects; - ItemInPlay *i = findObject(s); + LoLObject *obj = findObject(s); if (l->direction != _currentDirection) { l->drawObjects = 0; @@ -562,8 +522,8 @@ void LoLEngine::drawBlockObjects(int blockArrayIndex) { while (s) { reassignDrawObjects(_currentDirection, s, l, true); - i = findObject(s); - s = i->nextAssignedObject; + obj = findObject(s); + s = obj->nextAssignedObject; } } @@ -575,7 +535,7 @@ void LoLEngine::drawBlockObjects(int blockArrayIndex) { drawMonster(s); s = _monsters[s].nextDrawObject; } else { - i = &_itemsInPlay[s]; + LoLItem *i = &_itemsInPlay[s]; int fx = _sceneItemOffs[s & 7] << 1; int fy = _sceneItemOffs[(s >> 1) & 7] + 5; @@ -645,7 +605,7 @@ void LoLEngine::drawBlockObjects(int blockArrayIndex) { } void LoLEngine::drawMonster(uint16 id) { - LoLMonsterInPlay *m = &_monsters[id]; + LoLMonster *m = &_monsters[id]; int16 flg = _monsterDirFlags[(_currentDirection << 2) + m->facing]; int curFrm = getMonsterCurFrame(m, flg & 0xffef); uint8 *shp = 0; @@ -721,7 +681,7 @@ void LoLEngine::drawMonster(uint16 id) { delete[] tbl; } -int LoLEngine::getMonsterCurFrame(LoLMonsterInPlay *m, uint16 dirFlags) { +int LoLEngine::getMonsterCurFrame(LoLMonster *m, uint16 dirFlags) { int tmp = 0; switch (_monsterAnimType[m->properties->shapeIndex]) { case 0: @@ -796,19 +756,19 @@ void LoLEngine::reassignDrawObjects(uint16 direction, uint16 itemIndex, LevelBlo return; } - ItemInPlay *newObject = findObject(itemIndex); - int r = calcItemMonsterPosition(newObject, direction); + LoLObject *newObject = findObject(itemIndex); + int r = calcObjectPosition(newObject, direction); uint16 *b = &l->drawObjects; - ItemInPlay *lastObject = 0; + LoLObject *lastObject = 0; while (*b) { lastObject = findObject(*b); if (flag) { - if (calcItemMonsterPosition(lastObject, direction) >= r) + if (calcObjectPosition(lastObject, direction) >= r) break; } else { - if (calcItemMonsterPosition(lastObject, direction) > r) + if (calcObjectPosition(lastObject, direction) > r) break; } @@ -838,7 +798,7 @@ void LoLEngine::redrawSceneItem() { if (s & 0x8000) { s = _monsters[s & 0x7fff].nextDrawObject; } else { - ItemInPlay *item = &_itemsInPlay[s]; + LoLItem *item = &_itemsInPlay[s]; if (item->shpCurFrame_flg & 0x4000) { if (checkDrawObjectSpace(item->x, item->y, _partyPosX, _partyPosY) < 320) { @@ -862,21 +822,6 @@ void LoLEngine::redrawSceneItem() { } } -int LoLEngine::calcItemMonsterPosition(ItemInPlay *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::calcSpriteRelPosition(uint16 x1, uint16 y1, int &x2, int &y2, uint16 direction) { int a = x2 - x1; int b = y1 - y2; @@ -1080,7 +1025,7 @@ int LoLEngine::calcDrawingLayerParameters(int x1, int y1, int &x2, int &y2, uint return l; } -void LoLEngine::updateMonster(LoLMonsterInPlay *monster) { +void LoLEngine::updateMonster(LoLMonster *monster) { static const uint8 flags[] = { 1, 0, 1, 3, 3, 0, 0, 3, 4, 1, 0, 0, 4, 0, 0 }; if (monster->mode > 14) return; @@ -1228,7 +1173,7 @@ void LoLEngine::updateMonster(LoLMonsterInPlay *monster) { monster->flags &= 0xffef; } -void LoLEngine::moveMonster(LoLMonsterInPlay *monster) { +void LoLEngine::moveMonster(LoLMonster *monster) { static const int8 turnPos[] = { 0, 2, 6, 6, 0, 2, 4, 4, 2, 2, 4, 6, 0, 0, 4, 6, 0 }; if (monster->x != monster->destX || monster->y != monster->destY) { walkMonster(monster); @@ -1238,7 +1183,7 @@ void LoLEngine::moveMonster(LoLMonsterInPlay *monster) { } } -void LoLEngine::walkMonster(LoLMonsterInPlay *monster) { +void LoLEngine::walkMonster(LoLMonster *monster) { if (monster->properties->flags & 0x400) return; @@ -1269,7 +1214,7 @@ void LoLEngine::walkMonster(LoLMonsterInPlay *monster) { placeMonster(monster, fx, fy); } -bool LoLEngine::chasePartyWithDistanceAttacks(LoLMonsterInPlay *monster) { +bool LoLEngine::chasePartyWithDistanceAttacks(LoLMonster *monster) { if (!monster->numDistAttacks) return false; @@ -1347,7 +1292,7 @@ bool LoLEngine::chasePartyWithDistanceAttacks(LoLMonsterInPlay *monster) { return true; } -void LoLEngine::chasePartyWithCloseAttacks(LoLMonsterInPlay *monster) { +void LoLEngine::chasePartyWithCloseAttacks(LoLMonster *monster) { if (!(monster->flags & 8)) { int dir = calcMonsterDirection(monster->x & 0xff00, monster->y & 0xff00, _partyPosX & 0xff00, _partyPosY & 0xff00); int x1 = _partyPosX; @@ -1389,7 +1334,7 @@ void LoLEngine::chasePartyWithCloseAttacks(LoLMonsterInPlay *monster) { } } -int LoLEngine::walkMonsterCalcNextStep(LoLMonsterInPlay *monster) { +int LoLEngine::walkMonsterCalcNextStep(LoLMonster *monster) { static const int8 walkMonsterTable1[] = { 7, -6, 5, -4, 3, -2, 1, 0 }; static const int8 walkMonsterTable2[] = { -7, 6, -5, 4, -3, 2, -1, 0 }; @@ -1479,7 +1424,7 @@ int LoLEngine::checkForPossibleDistanceAttack(uint16 monsterBlock, int direction return 5; } -int LoLEngine::walkMonsterCheckDest(int x, int y, LoLMonsterInPlay *monster, int unk) { +int LoLEngine::walkMonsterCheckDest(int x, int y, LoLMonster *monster, int unk) { uint8 m = monster->mode; monster->mode = 15; @@ -1497,7 +1442,7 @@ void LoLEngine::getNextStepCoords(int16 srcX, int16 srcY, int &newX, int &newY, newY = (srcY + shiftTableY[direction]) & 0x1fff; } -void LoLEngine::rearrangeAttackingMonster(LoLMonsterInPlay *monster) { +void LoLEngine::rearrangeAttackingMonster(LoLMonster *monster) { int t = (monster->direction >> 1); uint16 mx = monster->x; uint16 my = monster->y; @@ -1564,7 +1509,7 @@ void LoLEngine::rearrangeAttackingMonster(LoLMonsterInPlay *monster) { placeMonster(monster, mx, my); } -void LoLEngine::moveStrayingMonster(LoLMonsterInPlay *monster) { +void LoLEngine::moveStrayingMonster(LoLMonster *monster) { int x = 0; int y = 0; @@ -1601,7 +1546,7 @@ void LoLEngine::moveStrayingMonster(LoLMonsterInPlay *monster) { } } -void LoLEngine::killMonster(LoLMonsterInPlay *monster) { +void LoLEngine::killMonster(LoLMonster *monster) { setMonsterMode(monster, 14); monsterDropItems(monster); checkSceneUpdateNeed(monster->block); -- cgit v1.2.3