aboutsummaryrefslogtreecommitdiff
path: root/engines/hugo/object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/hugo/object.cpp')
-rw-r--r--engines/hugo/object.cpp257
1 files changed, 131 insertions, 126 deletions
diff --git a/engines/hugo/object.cpp b/engines/hugo/object.cpp
index b909df45bb..f9364a8781 100644
--- a/engines/hugo/object.cpp
+++ b/engines/hugo/object.cpp
@@ -48,9 +48,10 @@
namespace Hugo {
-ObjectHandler::ObjectHandler(HugoEngine *vm) : _vm(vm), _objects(0) {
+ObjectHandler::ObjectHandler(HugoEngine *vm) : _vm(vm), _objects(0), _uses(0) {
_numObj = 0;
_objCount = 0;
+ _usesSize = 0;
memset(_objBound, '\0', sizeof(overlay_t));
memset(_boundary, '\0', sizeof(overlay_t));
memset(_overlay, '\0', sizeof(overlay_t));
@@ -108,20 +109,20 @@ void ObjectHandler::useObject(int16 objId) {
if ((obj->genericCmd & TAKE) || obj->objValue) // Get collectible item
sprintf(_vm->_line, "%s %s", _vm->_text->getVerb(_vm->_take, 0), _vm->_text->getNoun(obj->nounIndex, 0));
else if (obj->cmdIndex != 0) // Use non-collectible item if able
- sprintf(_vm->_line, "%s %s", _vm->_text->getVerb(_vm->_cmdList[obj->cmdIndex][0].verbIndex, 0), _vm->_text->getNoun(obj->nounIndex, 0));
- else if ((verb = _vm->useBG(_vm->_text->getNoun(obj->nounIndex, 0))) != 0)
+ sprintf(_vm->_line, "%s %s", _vm->_text->getVerb(_vm->_parser->getCmdDefaultVerbIdx(obj->cmdIndex), 0), _vm->_text->getNoun(obj->nounIndex, 0));
+ else if ((verb = _vm->_parser->useBG(_vm->_text->getNoun(obj->nounIndex, 0))) != 0)
sprintf(_vm->_line, "%s %s", verb, _vm->_text->getNoun(obj->nounIndex, 0));
else
return; // Can't use object directly
} else {
// Use status.objid on objid
// Default to first cmd verb
- sprintf(_vm->_line, "%s %s %s", _vm->_text->getVerb(_vm->_cmdList[_objects[inventObjId].cmdIndex][0].verbIndex, 0),
+ sprintf(_vm->_line, "%s %s %s", _vm->_text->getVerb(_vm->_parser->getCmdDefaultVerbIdx(_objects[inventObjId].cmdIndex), 0),
_vm->_text->getNoun(_objects[inventObjId].nounIndex, 0),
_vm->_text->getNoun(obj->nounIndex, 0));
// Check valid use of objects and override verb if necessary
- for (uses_t *use = _vm->_uses; use->objId != _numObj; use++) {
+ for (uses_t *use = _uses; use->objId != _numObj; use++) {
if (inventObjId == use->objId) {
// Look for secondary object, if found use matching verb
bool foundFl = false;
@@ -212,40 +213,52 @@ void ObjectHandler::lookObject(object_t *obj) {
}
/**
- * Free all object images
+ * Free all object images, uses and ObjArr (before exiting)
*/
void ObjectHandler::freeObjects() {
debugC(1, kDebugObject, "freeObjects");
- // Nothing to do if not allocated yet
- if (_vm->_hero == 0 || _vm->_hero->seqList[0].seqPtr == 0)
- return;
-
- // Free all sequence lists and image data
- for (int i = 0; i < _numObj; i++) {
- object_t *obj = &_objects[i];
- for (int j = 0; j < obj->seqNumb; j++) {
- seq_t *seq = obj->seqList[j].seqPtr;
- seq_t *next;
- if (seq == 0) // Failure during database load
- break;
- if (seq->imagePtr != 0) {
- free(seq->imagePtr);
- seq->imagePtr = 0;
- }
- seq = seq->nextSeqPtr;
- while (seq != obj->seqList[j].seqPtr) {
+ if (_vm->_hero != 0 && _vm->_hero->seqList[0].seqPtr != 0) {
+ // Free all sequence lists and image data
+ for (int16 i = 0; i < _numObj; i++) {
+ object_t *obj = &_objects[i];
+ for (int16 j = 0; j < obj->seqNumb; j++) {
+ seq_t *seq = obj->seqList[j].seqPtr;
+ seq_t *next;
+ if (seq == 0) // Failure during database load
+ break;
if (seq->imagePtr != 0) {
free(seq->imagePtr);
seq->imagePtr = 0;
}
- next = seq->nextSeqPtr;
+ seq = seq->nextSeqPtr;
+ while (seq != obj->seqList[j].seqPtr) {
+ if (seq->imagePtr != 0) {
+ free(seq->imagePtr);
+ seq->imagePtr = 0;
+ }
+ next = seq->nextSeqPtr;
+ free(seq);
+ seq = next;
+ }
free(seq);
- seq = next;
}
- free(seq);
}
}
+
+ if (_uses) {
+ for (int16 i = 0; i < _usesSize; i++)
+ free(_uses[i].targets);
+ free(_uses);
+ }
+
+ for(int16 i = 0; i < _objCount; i++) {
+ free(_objects[i].stateDataIndex);
+ _objects[i].stateDataIndex = 0;
+ }
+
+ free(_objects);
+ _objects = 0;
}
/**
@@ -355,122 +368,114 @@ bool ObjectHandler::findObjectSpace(object_t *obj, int16 *destx, int16 *desty) {
return foundFl;
}
+void ObjectHandler::readUse(Common::ReadStream &in, uses_t &curUse) {
+ curUse.objId = in.readSint16BE();
+ curUse.dataIndex = in.readUint16BE();
+ uint16 numSubElem = in.readUint16BE();
+ curUse.targets = (target_t *)malloc(sizeof(target_t) * numSubElem);
+ for (int j = 0; j < numSubElem; j++) {
+ curUse.targets[j].nounIndex = in.readUint16BE();
+ curUse.targets[j].verbIndex = in.readUint16BE();
+ }
+}
/**
- * Free ObjectArr (before exiting)
+ * Load _uses from Hugo.dat
*/
-void ObjectHandler::freeObjectArr() {
- for(int16 i = 0; i < _objCount; i++) {
- free(_objects[i].stateDataIndex);
- _objects[i].stateDataIndex = 0;
+void ObjectHandler::loadObjectUses(Common::ReadStream &in) {
+ uses_t tmpUse;
+ //Read _uses
+ for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
+ tmpUse.targets = 0;
+ uint16 numElem = in.readUint16BE();
+ if (varnt == _vm->_gameVariant) {
+ _usesSize = numElem;
+ _uses = (uses_t *)malloc(sizeof(uses_t) * numElem);
+ }
+
+ for (int i = 0; i < numElem; i++)
+ readUse(in, (varnt == _vm->_gameVariant) ? _uses[i] : tmpUse);
+
+ if (tmpUse.targets)
+ free(tmpUse.targets);
}
- free(_objects);
- _objects = 0;
}
+void ObjectHandler::readObject(Common::ReadStream &in, object_t &curObject) {
+ curObject.nounIndex = in.readUint16BE();
+ curObject.dataIndex = in.readUint16BE();
+ uint16 numSubElem = in.readUint16BE();
+
+ if (numSubElem == 0)
+ curObject.stateDataIndex = 0;
+ else
+ curObject.stateDataIndex = (uint16 *)malloc(sizeof(uint16) * numSubElem);
+ for (int j = 0; j < numSubElem; j++)
+ curObject.stateDataIndex[j] = in.readUint16BE();
+
+ curObject.pathType = (path_t) in.readSint16BE();
+ curObject.vxPath = in.readSint16BE();
+ curObject.vyPath = in.readSint16BE();
+ curObject.actIndex = in.readUint16BE();
+ curObject.seqNumb = in.readByte();
+ curObject.currImagePtr = 0;
+
+ if (curObject.seqNumb == 0) {
+ curObject.seqList[0].imageNbr = 0;
+ curObject.seqList[0].seqPtr = 0;
+ }
+
+ for (int j = 0; j < curObject.seqNumb; j++) {
+ curObject.seqList[j].imageNbr = in.readUint16BE();
+ curObject.seqList[j].seqPtr = 0;
+ }
+
+ curObject.cycling = (cycle_t)in.readByte();
+ curObject.cycleNumb = in.readByte();
+ curObject.frameInterval = in.readByte();
+ curObject.frameTimer = in.readByte();
+ curObject.radius = in.readByte();
+ curObject.screenIndex = in.readByte();
+ curObject.x = in.readSint16BE();
+ curObject.y = in.readSint16BE();
+ curObject.oldx = in.readSint16BE();
+ curObject.oldy = in.readSint16BE();
+ curObject.vx = in.readByte();
+ curObject.vy = in.readByte();
+ curObject.objValue = in.readByte();
+ curObject.genericCmd = in.readSint16BE();
+ curObject.cmdIndex = in.readUint16BE();
+ curObject.carriedFl = (in.readByte() != 0);
+ curObject.state = in.readByte();
+ curObject.verbOnlyFl = (in.readByte() != 0);
+ curObject.priority = in.readByte();
+ curObject.viewx = in.readSint16BE();
+ curObject.viewy = in.readSint16BE();
+ curObject.direction = in.readSint16BE();
+ curObject.curSeqNum = in.readByte();
+ curObject.curImageNum = in.readByte();
+ curObject.oldvx = in.readByte();
+ curObject.oldvy = in.readByte();
+}
/**
* Load ObjectArr from Hugo.dat
*/
void ObjectHandler::loadObjectArr(Common::ReadStream &in) {
debugC(6, kDebugObject, "loadObject(&in)");
+ object_t tmpObject;
for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
uint16 numElem = in.readUint16BE();
+ tmpObject.stateDataIndex = 0;
if (varnt == _vm->_gameVariant) {
_objCount = numElem;
_objects = (object_t *)malloc(sizeof(object_t) * numElem);
- for (int i = 0; i < numElem; i++) {
- _objects[i].nounIndex = in.readUint16BE();
- _objects[i].dataIndex = in.readUint16BE();
- uint16 numSubElem = in.readUint16BE();
- if (numSubElem == 0)
- _objects[i].stateDataIndex = 0;
- else
- _objects[i].stateDataIndex = (uint16 *)malloc(sizeof(uint16) * numSubElem);
- for (int j = 0; j < numSubElem; j++)
- _objects[i].stateDataIndex[j] = in.readUint16BE();
- _objects[i].pathType = (path_t) in.readSint16BE();
- _objects[i].vxPath = in.readSint16BE();
- _objects[i].vyPath = in.readSint16BE();
- _objects[i].actIndex = in.readUint16BE();
- _objects[i].seqNumb = in.readByte();
- _objects[i].currImagePtr = 0;
- if (_objects[i].seqNumb == 0) {
- _objects[i].seqList[0].imageNbr = 0;
- _objects[i].seqList[0].seqPtr = 0;
- }
- for (int j = 0; j < _objects[i].seqNumb; j++) {
- _objects[i].seqList[j].imageNbr = in.readUint16BE();
- _objects[i].seqList[j].seqPtr = 0;
- }
- _objects[i].cycling = (cycle_t)in.readByte();
- _objects[i].cycleNumb = in.readByte();
- _objects[i].frameInterval = in.readByte();
- _objects[i].frameTimer = in.readByte();
- _objects[i].radius = in.readByte();
- _objects[i].screenIndex = in.readByte();
- _objects[i].x = in.readSint16BE();
- _objects[i].y = in.readSint16BE();
- _objects[i].oldx = in.readSint16BE();
- _objects[i].oldy = in.readSint16BE();
- _objects[i].vx = in.readByte();
- _objects[i].vy = in.readByte();
- _objects[i].objValue = in.readByte();
- _objects[i].genericCmd = in.readSint16BE();
- _objects[i].cmdIndex = in.readUint16BE();
- _objects[i].carriedFl = (in.readByte() != 0);
- _objects[i].state = in.readByte();
- _objects[i].verbOnlyFl = (in.readByte() != 0);
- _objects[i].priority = in.readByte();
- _objects[i].viewx = in.readSint16BE();
- _objects[i].viewy = in.readSint16BE();
- _objects[i].direction = in.readSint16BE();
- _objects[i].curSeqNum = in.readByte();
- _objects[i].curImageNum = in.readByte();
- _objects[i].oldvx = in.readByte();
- _objects[i].oldvy = in.readByte();
- }
- } else {
- for (int i = 0; i < numElem; i++) {
- in.readUint16BE();
- in.readUint16BE();
- uint16 numSubElem = in.readUint16BE();
- for (int j = 0; j < numSubElem; j++)
- in.readUint16BE();
- in.readSint16BE();
- in.readSint16BE();
- in.readSint16BE();
- in.readUint16BE();
- numSubElem = in.readByte();
- for (int j = 0; j < numSubElem; j++)
- in.readUint16BE();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readSint16BE();
- in.readSint16BE();
- in.readSint16BE();
- in.readSint16BE();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readSint16BE();
- in.readUint16BE();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readSint16BE();
- in.readSint16BE();
- in.readUint16BE();
- in.readByte();
- in.readByte();
- in.readByte();
- in.readByte();
- }
}
+
+ for (int i = 0; i < numElem; i++)
+ readObject(in, (varnt == _vm->_gameVariant) ? _objects[i] : tmpObject);
+
+ if (tmpObject.stateDataIndex)
+ free(tmpObject.stateDataIndex);
}
}