diff options
author | Johannes Schickel | 2010-10-22 02:09:16 +0000 |
---|---|---|
committer | Johannes Schickel | 2010-10-22 02:09:16 +0000 |
commit | 3653613443d8def9ae7f552eb799d1f039fd8097 (patch) | |
tree | b8732b6d508e53252596c61d778ac7319f755cf0 /engines/kyra | |
parent | 38463e61619fe1e4d2b6c59313d99c40482d7411 (diff) | |
download | scummvm-rg350-3653613443d8def9ae7f552eb799d1f039fd8097.tar.gz scummvm-rg350-3653613443d8def9ae7f552eb799d1f039fd8097.tar.bz2 scummvm-rg350-3653613443d8def9ae7f552eb799d1f039fd8097.zip |
KYRA: Add a datatype for the item ids and convert Kyra1 to use it.
svn-id: r53696
Diffstat (limited to 'engines/kyra')
-rw-r--r-- | engines/kyra/gui_lok.cpp | 15 | ||||
-rw-r--r-- | engines/kyra/item.h | 45 | ||||
-rw-r--r-- | engines/kyra/items_lok.cpp | 46 | ||||
-rw-r--r-- | engines/kyra/kyra_lok.cpp | 13 | ||||
-rw-r--r-- | engines/kyra/kyra_lok.h | 15 | ||||
-rw-r--r-- | engines/kyra/saveload_lok.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/scene_lok.cpp | 5 | ||||
-rw-r--r-- | engines/kyra/script_lok.cpp | 5 |
8 files changed, 102 insertions, 46 deletions
diff --git a/engines/kyra/gui_lok.cpp b/engines/kyra/gui_lok.cpp index 9a1d750391..8a6fa9af9f 100644 --- a/engines/kyra/gui_lok.cpp +++ b/engines/kyra/gui_lok.cpp @@ -32,6 +32,7 @@ #include "kyra/gui_lok.h" #include "kyra/timer.h" #include "kyra/util.h" +#include "kyra/item.h" #include "common/config-manager.h" #include "common/savefile.h" @@ -49,9 +50,9 @@ void KyraEngine_LoK::initMainButtonList() { int KyraEngine_LoK::buttonInventoryCallback(Button *caller) { int itemOffset = caller->index - 2; - uint8 inventoryItem = _currentCharacter->inventoryItems[itemOffset]; - if (_itemInHand == -1) { - if (inventoryItem == 0xFF) { + Item inventoryItem = (int8)_currentCharacter->inventoryItems[itemOffset]; + if (_itemInHand == kItemNone) { + if (inventoryItem == kItemNone) { snd_playSoundEffect(0x36); return 0; } else { @@ -62,10 +63,10 @@ int KyraEngine_LoK::buttonInventoryCallback(Button *caller) { updateSentenceCommand(_itemList[getItemListIndex(inventoryItem)], _takenList[0], 179); _itemInHand = inventoryItem; _screen->showMouse(); - _currentCharacter->inventoryItems[itemOffset] = 0xFF; + _currentCharacter->inventoryItems[itemOffset] = kItemNone; } } else { - if (inventoryItem != 0xFF) { + if (inventoryItem != kItemNone) { snd_playSoundEffect(0x35); _screen->hideMouse(); _screen->fillRect(_itemPosX[itemOffset], _itemPosY[itemOffset], _itemPosX[itemOffset] + 15, _itemPosY[itemOffset] + 15, _flags.platform == Common::kPlatformAmiga ? 19 : 12); @@ -87,7 +88,7 @@ int KyraEngine_LoK::buttonInventoryCallback(Button *caller) { updateSentenceCommand(_itemList[getItemListIndex(_itemInHand)], _placedList[0], 179); _screen->showMouse(); _currentCharacter->inventoryItems[itemOffset] = _itemInHand; - _itemInHand = -1; + _itemInHand = kItemNone; } } _screen->updateScreen(); @@ -104,7 +105,7 @@ int KyraEngine_LoK::buttonAmuletCallback(Button *caller) { } if (!queryGameFlag(0x2D)) return 1; - if (_itemInHand != -1) { + if (_itemInHand != kItemNone) { assert(_putDownFirst); characterSays(2000, _putDownFirst[0], 0, -2); return 1; diff --git a/engines/kyra/item.h b/engines/kyra/item.h new file mode 100644 index 0000000000..2088f4bd8b --- /dev/null +++ b/engines/kyra/item.h @@ -0,0 +1,45 @@ +/* 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$ + * + */ + +#ifndef KYRA_ITEM_H +#define KYRA_ITEM_H + +#include "common/scummsys.h" + +namespace Kyra { + +typedef int16 Item; + +enum { + /** + * Constant for invalid item. + */ + kItemNone = -1 +}; + +} // End of namespace Kyra + +#endif + diff --git a/engines/kyra/items_lok.cpp b/engines/kyra/items_lok.cpp index daa8043bb2..ed6313496c 100644 --- a/engines/kyra/items_lok.cpp +++ b/engines/kyra/items_lok.cpp @@ -74,28 +74,30 @@ void KyraEngine_LoK::clearNoDropRects() { byte KyraEngine_LoK::findFreeItemInScene(int scene) { assert(scene < _roomTableSize); Room *room = &_roomTable[scene]; + for (int i = 0; i < 12; ++i) { - if (room->itemsTable[i] == 0xFF) + if (room->itemsTable[i] == kItemNone) return i; } + return 0xFF; } byte KyraEngine_LoK::findItemAtPos(int x, int y) { assert(_currentCharacter->sceneId < _roomTableSize); - const uint8 *itemsTable = _roomTable[_currentCharacter->sceneId].itemsTable; + const int8 *itemsTable = _roomTable[_currentCharacter->sceneId].itemsTable; const uint16 *xposOffset = _roomTable[_currentCharacter->sceneId].itemsXPos; const uint8 *yposOffset = _roomTable[_currentCharacter->sceneId].itemsYPos; int highestYPos = -1; - byte returnValue = 0xFF; + Item returnValue = kItemNone; for (int i = 0; i < 12; ++i) { - if (*itemsTable != 0xFF) { + if (*itemsTable != kItemNone) { int xpos = *xposOffset - 11; int xpos2 = *xposOffset + 10; if (x > xpos && x < xpos2) { - assert(*itemsTable < ARRAYSIZE(_itemTable)); + assert(*itemsTable >= 0); int itemHeight = _itemTable[*itemsTable].height; int ypos = *yposOffset + 3; int ypos2 = ypos - itemHeight - 3; @@ -108,6 +110,7 @@ byte KyraEngine_LoK::findItemAtPos(int x, int y) { } } } + ++xposOffset; ++yposOffset; ++itemsTable; @@ -173,27 +176,28 @@ void KyraEngine_LoK::placeItemInGenericMapScene(int item, int index) { void KyraEngine_LoK::setHandItem(uint16 item) { _screen->hideMouse(); setMouseItem(item); - _itemInHand = item; + _itemInHand = (Item)item; _screen->showMouse(); } void KyraEngine_LoK::removeHandItem() { _screen->hideMouse(); _screen->setMouseCursor(1, 1, _shapes[0]); - _itemInHand = -1; + _itemInHand = kItemNone; _screen->showMouse(); } -void KyraEngine_LoK::setMouseItem(uint16 item) { - if (item == 0xFFFF) +void KyraEngine_LoK::setMouseItem(Item item) { + if (item == kItemNone) _screen->setMouseCursor(1, 1, _shapes[6]); else _screen->setMouseCursor(8, 15, _shapes[216+item]); } void KyraEngine_LoK::wipeDownMouseItem(int xpos, int ypos) { - if (_itemInHand == -1) + if (_itemInHand == kItemNone) return; + xpos -= 8; ypos -= 15; _screen->hideMouse(); @@ -261,7 +265,7 @@ int KyraEngine_LoK::countItemsInScene(uint16 sceneId) { int items = 0; for (int i = 0; i < 12; ++i) { - if (currentRoom->itemsTable[i] != 0xFF) + if (currentRoom->itemsTable[i] != kItemNone) ++items; } @@ -284,7 +288,7 @@ int KyraEngine_LoK::processItemDrop(uint16 sceneId, uint8 item, int x, int y, in if (unk1 != 3) { for (int i = 0; i < 12; ++i) { - if (currentRoom->itemsTable[i] == 0xFF) { + if (currentRoom->itemsTable[i] == kItemNone) { freeItem = i; break; } @@ -647,7 +651,8 @@ void KyraEngine_LoK::magicOutMouseItem(int animIndex, int itemPos) { int videoPageBackUp = _screen->_curPage; _screen->_curPage = 0; int x = 0, y = 0; - if (itemPos == -1) { + + if (itemPos == kItemNone) { Common::Point mouse = getMousePos(); x = mouse.x - 12; y = mouse.y - 18; @@ -656,7 +661,7 @@ void KyraEngine_LoK::magicOutMouseItem(int animIndex, int itemPos) { y = _itemPosY[itemPos] - 3; } - if (_itemInHand == -1 && itemPos == -1) + if (_itemInHand == kItemNone && itemPos == -1) return; int tableIndex = 0, loopStart = 0, maxLoops = 0; @@ -713,15 +718,17 @@ void KyraEngine_LoK::magicOutMouseItem(int animIndex, int itemPos) { delayUntil(nextTime); } restoreItemRect1(x, y); + if (itemPos == -1) { _screen->setMouseCursor(1, 1, _shapes[0]); - _itemInHand = -1; + _itemInHand = kItemNone; } else { - _characterList[0].inventoryItems[itemPos] = 0xFF; + _characterList[0].inventoryItems[itemPos] = kItemNone; _screen->hideMouse(); _screen->fillRect(_itemPosX[itemPos], _itemPosY[itemPos], _itemPosX[itemPos] + 15, _itemPosY[itemPos] + 15, _flags.platform == Common::kPlatformAmiga ? 19 : 12, 0); _screen->showMouse(); } + _screen->showMouse(); _screen->_curPage = videoPageBackUp; } @@ -884,7 +891,8 @@ void KyraEngine_LoK::redrawInventory(int page) { _screen->hideMouse(); for (int i = 0; i < 10; ++i) { _screen->fillRect(_itemPosX[i], _itemPosY[i], _itemPosX[i] + 15, _itemPosY[i] + 15, _flags.platform == Common::kPlatformAmiga ? 19 : 12, page); - if (_currentCharacter->inventoryItems[i] != 0xFF) { + + if (_currentCharacter->inventoryItems[i] != kItemNone) { uint8 item = _currentCharacter->inventoryItems[i]; _screen->drawShape(page, _shapes[216+item], _itemPosX[i], _itemPosY[i], 0, 0); } @@ -914,12 +922,12 @@ void KyraEngine_LoK::restoreItemRect1(int xpos, int ypos) { _screen->copyBlockToPage(_screen->_curPage, xpos, ypos, 4<<3, 32, _itemBkgBackUp[1]); } -int KyraEngine_LoK::getItemListIndex(uint16 item) { +int KyraEngine_LoK::getItemListIndex(Item item) { if (_flags.platform != Common::kPlatformAmiga) return item; // "Unknown item" is at 81. - if (item == 0xFFFF || item == 0xFF) + if (item == kItemNone) return 81; // The first item names are mapped directly else if (item <= 28) diff --git a/engines/kyra/kyra_lok.cpp b/engines/kyra/kyra_lok.cpp index 159230e928..225f71ee4e 100644 --- a/engines/kyra/kyra_lok.cpp +++ b/engines/kyra/kyra_lok.cpp @@ -260,7 +260,7 @@ Common::Error KyraEngine_LoK::init() { _marbleVaseItem = -1; memset(_foyerItemTable, -1, sizeof(_foyerItemTable)); - _itemInHand = -1; + _itemInHand = kItemNone; _currentRoom = 0xFFFF; _scenePhasingFlag = 0; @@ -373,7 +373,7 @@ void KyraEngine_LoK::startup() { for (int i = 0; i < _roomTableSize; ++i) { for (int item = 0; item < 12; ++item) { - _roomTable[i].itemsTable[item] = 0xFF; + _roomTable[i].itemsTable[item] = kItemNone; _roomTable[i].itemsXPos[item] = 0xFFFF; _roomTable[i].itemsYPos[item] = 0xFF; _roomTable[i].needInit[item] = 0; @@ -672,12 +672,13 @@ void KyraEngine_LoK::processInput(int xpos, int ypos) { runNpcScript(script); return; } - if (_itemInHand != -1) { + if (_itemInHand != kItemNone) { if (ypos < 155) { if (hasClickedOnExit(xpos, ypos)) { handleSceneChange(xpos, ypos, 1, 1); return; } + dropItem(0, _itemInHand, xpos, ypos, 1); } } else { @@ -691,14 +692,14 @@ void KyraEngine_LoK::processInput(int xpos, int ypos) { int KyraEngine_LoK::processInputHelper(int xpos, int ypos) { uint8 item = findItemAtPos(xpos, ypos); if (item != 0xFF) { - if (_itemInHand == -1) { + if (_itemInHand == kItemNone) { _screen->hideMouse(); _animator->animRemoveGameItem(item); snd_playSoundEffect(53); assert(_currentCharacter->sceneId < _roomTableSize); Room *currentRoom = &_roomTable[_currentCharacter->sceneId]; int item2 = currentRoom->itemsTable[item]; - currentRoom->itemsTable[item] = 0xFF; + currentRoom->itemsTable[item] = kItemNone; setMouseItem(item2); assert(_itemList && _takenList); updateSentenceCommand(_itemList[getItemListIndex(item2)], _takenList[0], 179); @@ -830,7 +831,7 @@ void KyraEngine_LoK::updateMousePointer(bool forceUpdate) { if (mouse.y > 158 || (mouse.x >= 12 && mouse.x < 308 && mouse.y < 136 && mouse.y >= 12) || forceUpdate) { _mouseState = _itemInHand; _screen->hideMouse(); - if (_itemInHand == -1) + if (_itemInHand == kItemNone) _screen->setMouseCursor(1, 1, _shapes[0]); else _screen->setMouseCursor(8, 15, _shapes[216+_itemInHand]); diff --git a/engines/kyra/kyra_lok.h b/engines/kyra/kyra_lok.h index 50f36d7b71..ddf21c7cc2 100644 --- a/engines/kyra/kyra_lok.h +++ b/engines/kyra/kyra_lok.h @@ -30,6 +30,7 @@ #include "kyra/script.h" #include "kyra/screen_lok.h" #include "kyra/gui_lok.h" +#include "kyra/item.h" namespace Kyra { @@ -46,7 +47,7 @@ struct Character { uint8 height; uint8 facing; uint16 currentAnimFrame; - uint8 inventoryItems[10]; + int8 inventoryItems[10]; int16 x1, y1, x2, y2; }; @@ -62,13 +63,13 @@ struct Room { uint16 eastExit; uint16 southExit; uint16 westExit; - uint8 itemsTable[12]; + int8 itemsTable[12]; uint16 itemsXPos[12]; uint8 itemsYPos[12]; uint8 needInit[12]; }; -struct Item { +struct ItemDescription { uint8 unk1; uint8 height; uint8 unk2; @@ -290,9 +291,9 @@ protected: // -> mouse item void setHandItem(uint16 item); void removeHandItem(); - void setMouseItem(uint16 item); + void setMouseItem(Item item); - int getItemListIndex(uint16 item); + int getItemListIndex(Item item); // -> graphics effects void wipeDownMouseItem(int xpos, int ypos); @@ -402,7 +403,7 @@ protected: bool _menuDirectlyToLoad; uint8 *_itemBkgBackUp[2]; uint8 *_shapes[373]; - int8 _itemInHand; + Item _itemInHand; bool _changedScene; int _unkScreenVar1, _unkScreenVar2, _unkScreenVar3; int _beadStateVar; @@ -455,7 +456,7 @@ protected: int8 *_sceneAnimTable[50]; - Item _itemTable[145]; + ItemDescription _itemTable[145]; int _lastProcessedItem; int _lastProcessedItemHeight; diff --git a/engines/kyra/saveload_lok.cpp b/engines/kyra/saveload_lok.cpp index 1a61f9a962..29f224a5ba 100644 --- a/engines/kyra/saveload_lok.cpp +++ b/engines/kyra/saveload_lok.cpp @@ -80,7 +80,7 @@ Common::Error KyraEngine_LoK::loadGameState(int slot) { } _marbleVaseItem = in->readSint16BE(); - _itemInHand = in->readByte(); + _itemInHand = (int8)in->readByte(); for (int i = 0; i < 4; ++i) _birthstoneGemTable[i] = in->readByte(); @@ -109,7 +109,7 @@ Common::Error KyraEngine_LoK::loadGameState(int slot) { for (int i = 0; i < _roomTableSize; ++i) { for (int item = 0; item < 12; ++item) { - _roomTable[i].itemsTable[item] = 0xFF; + _roomTable[i].itemsTable[item] = kItemNone; _roomTable[i].itemsXPos[item] = 0xFFFF; _roomTable[i].itemsYPos[item] = 0xFF; _roomTable[i].needInit[item] = 0; diff --git a/engines/kyra/scene_lok.cpp b/engines/kyra/scene_lok.cpp index f71c3bd756..f7ada5d623 100644 --- a/engines/kyra/scene_lok.cpp +++ b/engines/kyra/scene_lok.cpp @@ -824,13 +824,14 @@ void KyraEngine_LoK::initSceneScreen(int brandonAlive) { _emc->run(&_scriptClick); setTextFadeTimerCountdown(-1); + if (_currentCharacter->sceneId == 210) { - if (_itemInHand != -1) + if (_itemInHand != kItemNone) magicOutMouseItem(2, -1); _screen->hideMouse(); for (int i = 0; i < 10; ++i) { - if (_currentCharacter->inventoryItems[i] != 0xFF) + if (_currentCharacter->inventoryItems[i] != kItemNone) magicOutMouseItem(2, i); } _screen->showMouse(); diff --git a/engines/kyra/script_lok.cpp b/engines/kyra/script_lok.cpp index 1b4a11f793..a2bad8035e 100644 --- a/engines/kyra/script_lok.cpp +++ b/engines/kyra/script_lok.cpp @@ -37,6 +37,7 @@ #include "kyra/sound.h" namespace Kyra { + int KyraEngine_LoK::o1_magicInMouseItem(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_magicInMouseItem(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); magicInMouseItem(stackPos(0), stackPos(1), -1); @@ -203,9 +204,7 @@ int KyraEngine_LoK::o1_getElapsedSeconds(EMCState *script) { int KyraEngine_LoK::o1_mouseIsPointer(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_mouseIsPointer(%p) ()", (const void *)script); - if (_itemInHand == -1) - return 1; - return 0; + return (_itemInHand == kItemNone); } int KyraEngine_LoK::o1_runSceneAnimUntilDone(EMCState *script) { |