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.cpp52
1 files changed, 47 insertions, 5 deletions
diff --git a/engines/hugo/object.cpp b/engines/hugo/object.cpp
index b909df45bb..c2bcffb833 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;
@@ -249,6 +250,16 @@ void ObjectHandler::freeObjects() {
}
/**
+ * Free all object uses
+ */
+void ObjectHandler::freeObjectUses() {
+ if (_uses) {
+ for (int i = 0; i < _usesSize; i++)
+ free(_uses[i].targets);
+ free(_uses);
+ }
+}
+/**
* Compare function for the quicksort. The sort is to order the objects in
* increasing vertical position, using y+y2 as the baseline
* Returns -1 if ay2 < by2 else 1 if ay2 > by2 else 0
@@ -368,6 +379,37 @@ void ObjectHandler::freeObjectArr() {
}
/**
+ * Load _uses from Hugo.dat
+ */
+void ObjectHandler::loadObjectUses(Common::ReadStream &in) {
+ //Read _uses
+ for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
+ uint16 numElem = in.readUint16BE();
+ uses_t *wrkUses = (uses_t *)malloc(sizeof(uses_t) * numElem);
+
+ for (int i = 0; i < numElem; i++) {
+ wrkUses[i].objId = in.readSint16BE();
+ wrkUses[i].dataIndex = in.readUint16BE();
+ uint16 numSubElem = in.readUint16BE();
+ wrkUses[i].targets = (target_t *)malloc(sizeof(target_t) * numSubElem);
+ for (int j = 0; j < numSubElem; j++) {
+ wrkUses[i].targets[j].nounIndex = in.readUint16BE();
+ wrkUses[i].targets[j].verbIndex = in.readUint16BE();
+ }
+ }
+
+ if (varnt == _vm->_gameVariant) {
+ _usesSize = numElem;
+ _uses = wrkUses;
+ } else {
+ for (int i = 0; i < numElem; i++)
+ free(wrkUses[i].targets);
+ free(wrkUses);
+ }
+ }
+}
+
+/**
* Load ObjectArr from Hugo.dat
*/
void ObjectHandler::loadObjectArr(Common::ReadStream &in) {