aboutsummaryrefslogtreecommitdiff
path: root/engines/hdb/ai-inventory.cpp
diff options
context:
space:
mode:
authorNipun Garg2019-07-01 08:57:17 +0530
committerEugene Sandulenko2019-09-03 17:17:06 +0200
commitc3be6f7f2b025886489e08d74c8248f883c609bf (patch)
treedf8f28e3ff3c5a3be7c285690c031c0dc56c33e4 /engines/hdb/ai-inventory.cpp
parent6b5fd8a95ff3713a0e199f2757ddde8d1ad8a9c8 (diff)
downloadscummvm-rg350-c3be6f7f2b025886489e08d74c8248f883c609bf.tar.gz
scummvm-rg350-c3be6f7f2b025886489e08d74c8248f883c609bf.tar.bz2
scummvm-rg350-c3be6f7f2b025886489e08d74c8248f883c609bf.zip
HDB: Add Inventory functions
Diffstat (limited to 'engines/hdb/ai-inventory.cpp')
-rw-r--r--engines/hdb/ai-inventory.cpp166
1 files changed, 166 insertions, 0 deletions
diff --git a/engines/hdb/ai-inventory.cpp b/engines/hdb/ai-inventory.cpp
index cfa45e342f..0325d3b696 100644
--- a/engines/hdb/ai-inventory.cpp
+++ b/engines/hdb/ai-inventory.cpp
@@ -79,6 +79,11 @@ bool AI::addToInventory(AIEntity *e) {
return true;
}
+void AI::purgeInventory() {
+ memset(&_inventory, 0, sizeof(InvEnt) * kMaxInventory);
+ _numInventory = 0;
+}
+
// Clear out the Player inventory except Gems,
// Monkeystones and Goo Cups unless its marked
void AI::clearInventory() {
@@ -105,6 +110,167 @@ AIEntity *AI::getInvItem(int which) {
return _inventory[which].ent;
}
+int AI::queryInventory(const char *string) {
+ int i, count;
+
+ if (!scumm_stricmp(string, "monkeystone"))
+ return getMonkeystoneAmount();
+ if (!scumm_stricmp(string, "goo"))
+ return getGooCupAmount();
+ if (!scumm_stricmp(string, "gem"))
+ return getGemAmount();
+
+ if (!_numInventory)
+ return 0;
+
+ count = 0;
+ for (i = _numInventory - 1; i >= 0; i--)
+ if (_inventory[i].ent->entityName && strstr(_inventory[i].ent->entityName, string))
+ count++;
+
+ return count;
+}
+
+bool AI::removeInvItem(const char *string, int amount) {
+ int i, j;
+ int found;
+
+ // Check specially for Gems, Monkeystones and Goo Cups
+ if (!scumm_stricmp(string, "gem")) {
+ _numGems -= amount;
+ return true;
+ } else if (!scumm_stricmp(string, "monkeystone")) {
+ _numMonkeystones -= amount;
+ return true;
+ } else if (!scumm_stricmp(string, "goo")) {
+ _numGooCups -= amount;
+ return true;
+ }
+
+ if (!_numInventory)
+ return false;
+
+ do {
+ found = 0;
+
+ for (i = _numInventory - 1; i >= 0; i--)
+ if (_inventory[i].ent->entityName && strstr(_inventory[i].ent->entityName, string)) {
+ j = i;
+ memset(&_inventory[j], 0, sizeof(InvEnt));
+ while (j < _numInventory - 1) {
+ memcpy(&_inventory[j], &_inventory[j + 1], sizeof(InvEnt));
+ memset(&_inventory[j + 1], 0, sizeof(InvEnt));
+ j++;
+ }
+ _numInventory--;
+ amount--;
+ found = 1;
+ if (!amount)
+ break;
+ }
+ } while (found && amount);
+
+ // if we haven't removed them all, return false
+ if (amount)
+ return false;
+
+ return true;
+}
+
+int AI::queryInventoryType(AIType which) {
+ int i, count;
+
+ if (which == ITEM_MONKEYSTONE)
+ return getMonkeystoneAmount();
+ if (which == ITEM_GOO_CUP)
+ return getGooCupAmount();
+ if (which == ITEM_GEM_WHITE)
+ return getGemAmount();
+
+ if (!_numInventory)
+ return 0;
+
+ count = 0;
+ for (i = 0; i < _numInventory; i++)
+ if (_inventory[i].ent->type == which)
+ count++;
+
+ return count;
+}
+
+bool AI::removeInvItemType(AIType which, int amount) {
+ int i, j, found;
+
+ // Check specially for Gems, Monkeystones and Goo Cups
+ if (which == ITEM_GEM_WHITE) {
+ _numGems -= amount;
+ return true;
+ } else if (which == ITEM_MONKEYSTONE) {
+ _numMonkeystones -= amount;
+ return true;
+ } else if (which == ITEM_GOO_CUP) {
+ _numGooCups -= amount;
+ return true;
+ }
+
+ if (!_numInventory)
+ return false;
+
+ do {
+ found = 0;
+
+ for (i = 0; i < _numInventory; i++)
+ if (_inventory[i].ent->type == which) {
+ j = i;
+ memset(&_inventory[j], 0, sizeof(InvEnt));
+ while (j < _numInventory - 1) {
+ memcpy(&_inventory[j], &_inventory[j + 1], sizeof(InvEnt));
+ memset(&_inventory[j + 1], 0, sizeof(InvEnt));
+ j++;
+ }
+ _numInventory--;
+ amount--;
+ found = 1;
+ if (!amount)
+ break;
+ }
+ } while (found && amount);
+
+ // if we haven't removed them all, return false
+ if (amount)
+ return false;
+
+ return true;
+}
+
+bool AI::addItemToInventory(AIType type, int amount, char *funcInit, char *funcAction, char *funcUse) {
+ int i;
+ AIEntity *e;
+ for (i = 0; i < amount; i++) {
+ spawn(type, DIR_UP, 0, 0, funcInit, funcAction, funcUse, DIR_UP, 1, 0, 0, 1);
+ e = findEntity(0, 0);
+ if (!e)
+ return false;
+ if (!addToInventory(e))
+ return false;
+ }
+ return true;
+}
+
+void AI::keepInvItem(AIType type) {
+ for (int i = 0; i < _numInventory; i++)
+ if (_inventory[i].ent->type == type)
+ _inventory[i].keep = 1;
+}
+
+void AI::printYouGotMsg(const char *name) {
+ if (!name || !name[0])
+ return;
+
+ sprintf(_youGotBuffer, "Got %s", name);
+ g_hdb->_window->textOut(_youGotBuffer, kYouGotX, kYouGotY, 120);
+}
+
void AI::newDelivery(const char *itemTextName, const char *itemGfxName, const char *destTextName, const char *destGfxName, const char *id) {
int i = _numDeliveries;