aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/items/item.cpp
diff options
context:
space:
mode:
authorMatthew Hoops2011-09-04 12:33:32 -0400
committerMatthew Hoops2011-09-04 12:33:32 -0400
commitbfb0de109ab8cc27aae9ed9a46c55068ac20eecc (patch)
treea92ea296d049f1ed343c1ebc3df7ba785831b398 /engines/pegasus/items/item.cpp
parentcb7b382acfd29957c9522b08b6460526fc73983c (diff)
downloadscummvm-rg350-bfb0de109ab8cc27aae9ed9a46c55068ac20eecc.tar.gz
scummvm-rg350-bfb0de109ab8cc27aae9ed9a46c55068ac20eecc.tar.bz2
scummvm-rg350-bfb0de109ab8cc27aae9ed9a46c55068ac20eecc.zip
PEGASUS: Implement more item code
Diffstat (limited to 'engines/pegasus/items/item.cpp')
-rwxr-xr-xengines/pegasus/items/item.cpp157
1 files changed, 156 insertions, 1 deletions
diff --git a/engines/pegasus/items/item.cpp b/engines/pegasus/items/item.cpp
index 934dce6f2d..2043317f5f 100755
--- a/engines/pegasus/items/item.cpp
+++ b/engines/pegasus/items/item.cpp
@@ -27,6 +27,7 @@
#include "common/stream.h"
#include "pegasus/constants.h"
+#include "pegasus/pegasus.h"
#include "pegasus/items/item.h"
#include "pegasus/items/itemlist.h"
@@ -40,10 +41,87 @@ Item::Item(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID r
_itemOwnerID = kNoActorID;
_itemState = 0;
+ PegasusEngine *vm = (PegasusEngine *)g_engine;
+
+ Common::SeekableReadStream *info = vm->_resFork->getResource(kItemInfoResType, kItemBaseResID + id);
+ if (info) {
+ _itemInfo.infoLeftTime = info->readUint32BE();
+ _itemInfo.infoRightStart = info->readUint32BE();
+ _itemInfo.infoRightStop = info->readUint32BE();
+ _itemInfo.dragSpriteNormalID = info->readUint32BE();
+ _itemInfo.dragSpriteUsedID = info->readUint32BE();
+
+ if (vm->isDemo()) {
+ // Adjust info right times to account for the stuff that was chopped out of the
+ // info right movies.
+ // Assumes time scale of 600.
+
+ // Gap times in seconds
+ static const TimeValue kGap1 = 24;
+ static const TimeValue kGap2 = 34;
+ static const TimeValue kGap3 = 4;
+ static const TimeValue kGap4 = 4;
+
+ static const TimeValue kGapForGroup1 = kGap1;
+ static const TimeValue kGapForGroup2 = kGapForGroup1 + kGap2;
+ static const TimeValue kGapForGroup3 = kGapForGroup2 + kGap3;
+ static const TimeValue kGapForGroup4 = kGapForGroup3 + kGap4;
+
+ switch (id) {
+ case kHistoricalLog:
+ case kJourneymanKey:
+ case kKeyCard:
+ _itemInfo.infoRightStart -= 600 * kGapForGroup1;
+ _itemInfo.infoRightStop -= 600 * kGapForGroup1;
+ break;
+ case kAIBiochip:
+ _itemInfo.infoRightStart -= 600 * kGapForGroup2;
+ _itemInfo.infoRightStop -= 600 * kGapForGroup2;
+ break;
+ case kMapBiochip:
+ _itemInfo.infoRightStart -= 600 * kGapForGroup3;
+ _itemInfo.infoRightStop -= 600 * kGapForGroup3;
+ break;
+ case kPegasusBiochip:
+ _itemInfo.infoRightStart -= 600 * kGapForGroup4;
+ _itemInfo.infoRightStop -= 600 * kGapForGroup4;
+ break;
+ }
+ }
+
+ delete info;
+ } else {
+ memset(&_itemInfo, 0, sizeof(_itemInfo));
+ }
+
+ Common::SeekableReadStream *middleAreaInfo = vm->_resFork->getResource(kMiddleAreaInfoResType, kItemBaseResID + id);
+ if (!middleAreaInfo)
+ error("Middle area info not found for item %d", id);
+
+ _sharedAreaInfo = readItemState(middleAreaInfo);
+
+ delete middleAreaInfo;
+
+ Common::SeekableReadStream *extraInfo = vm->_resFork->getResource(kItemExtraInfoResType, kItemBaseResID + id);
+ if (!extraInfo)
+ error("Extra info not found for item %d", id);
+
+ _itemExtras.numEntries = extraInfo->readUint16BE();
+ for (uint16 i = 0; i < _itemExtras.numEntries; i++) {
+ _itemExtras.entries[i].extraID = extraInfo->readUint32BE();
+ _itemExtras.entries[i].extraArea = extraInfo->readUint16BE();
+ _itemExtras.entries[i].extraStart = extraInfo->readUint32BE();
+ _itemExtras.entries[i].extraStop = extraInfo->readUint32BE();
+ }
+
+ delete extraInfo;
+
g_allItems.push_back(this);
}
Item::~Item() {
+ delete[] _sharedAreaInfo.entries;
+ delete[] _itemExtras.entries;
}
Common::Error Item::writeToStream(Common::WriteStream *stream) {
@@ -78,6 +156,14 @@ tActorID Item::getItemOwner() const {
void Item::setItemOwner(const tActorID owner) {
_itemOwnerID = owner;
+
+ if (owner == kNoActorID) {
+ if (isSelected())
+ deselect();
+ removedFromInventory();
+ } else {
+ addedToInventory();
+ }
}
tWeightType Item::getItemWeight() {
@@ -89,7 +175,10 @@ tItemState Item::getItemState() const {
}
void Item::setItemState(const tItemState state) {
- _itemState = state;
+ if (state != _itemState) {
+ _itemState = state;
+ // TODO: Selection
+ }
}
void Item::getItemRoom(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) const {
@@ -102,10 +191,76 @@ void Item::setItemRoom(const tNeighborhoodID neighborhood, const tRoomID room, c
_itemNeighborhood = neighborhood;
_itemRoom = room;
_itemDirection = direction;
+
+ if (neighborhood == kNoNeighborhoodID)
+ pickedUp();
+ else
+ dropped();
}
tNeighborhoodID Item::getItemNeighborhood() const {
return _itemNeighborhood;
}
+TimeValue Item::getSharedAreaTime() const {
+ if (!_sharedAreaInfo.entries)
+ return 0xffffffff;
+
+ TimeValue time;
+ tItemState state;
+
+ findItemStateEntryByState(_sharedAreaInfo, _itemState, time);
+ if (time == 0xffffffff)
+ getItemStateEntry(_sharedAreaInfo, 0, state, time);
+
+ return time;
+}
+
+// Must affect images in shared area.
+void Item::select() {
+ _isSelected = true;
+
+ // TODO: AI
+}
+
+void Item::deselect() {
+ _isActive = false;
+ _isSelected = false;
+
+ // TODO: AI
+}
+
+void Item::getItemStateEntry(ItemStateInfo info, uint32 index, tItemState &state, TimeValue &time) {
+ if (index < info.numEntries) {
+ state = info.entries[index].itemState;
+ time = info.entries[index].itemTime;
+ } else {
+ state = kNoItemState;
+ time = 0xffffffff;
+ }
+}
+
+void Item::findItemStateEntryByState(ItemStateInfo info, tItemState state, TimeValue &time) {
+ for (uint16 i = 0; i < info.numEntries; i++) {
+ if (info.entries[i].itemState == state) {
+ time = info.entries[i].itemTime;
+ return;
+ }
+ }
+
+ time = 0xffffffff;
+}
+
+ItemStateInfo Item::readItemState(Common::SeekableReadStream *stream) {
+ ItemStateInfo info;
+
+ info.numEntries = stream->readUint16BE();
+ for (uint16 i = 0; i < info.numEntries; i++) {
+ info.entries[i].itemState = stream->readSint16BE();
+ info.entries[i].itemTime = stream->readUint32BE();
+ }
+
+ return info;
+}
+
} // End of namespace Pegasus