diff options
author | Nipun Garg | 2019-07-01 08:57:17 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:17:06 +0200 |
commit | c3be6f7f2b025886489e08d74c8248f883c609bf (patch) | |
tree | df8f28e3ff3c5a3be7c285690c031c0dc56c33e4 /engines/hdb | |
parent | 6b5fd8a95ff3713a0e199f2757ddde8d1ad8a9c8 (diff) | |
download | scummvm-rg350-c3be6f7f2b025886489e08d74c8248f883c609bf.tar.gz scummvm-rg350-c3be6f7f2b025886489e08d74c8248f883c609bf.tar.bz2 scummvm-rg350-c3be6f7f2b025886489e08d74c8248f883c609bf.zip |
HDB: Add Inventory functions
Diffstat (limited to 'engines/hdb')
-rw-r--r-- | engines/hdb/ai-inventory.cpp | 166 | ||||
-rw-r--r-- | engines/hdb/ai.h | 23 |
2 files changed, 188 insertions, 1 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; diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 31a6766151..27fcddfe50 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -46,7 +46,9 @@ enum { kPushMoveSpeed = (kPlayerMoveSpeed >> 1), kPlayerTouchPWait = 16, kMaxCineGfx = 10, - kRunToggleDelay = 2 + kRunToggleDelay = 2, + kYouGotX = -1, + kYouGotY = (kScreenHeight - 16) }; enum AIType { @@ -917,6 +919,7 @@ public: // Inventory Functions bool addToInventory(AIEntity *e); + void purgeInventory(); void clearInventory(); int getInvAmount() { return _numInventory; @@ -933,8 +936,24 @@ public: void setGemAmount(int amt) { _numGems = amt; } + int getInvMax() { + return _numInventory; + } + AIType getInvItemType(int which) { + return _inventory[which].ent->type; + } + Tile *getInvItemGfx(int which) { + return _inventory[which].ent->standdownGfx[0]; + } AIEntity *getInvItem(int which); + int queryInventory(const char *string); + bool removeInvItem(const char *string, int amount); + int queryInventoryType(AIType which); + bool removeInvItemType(AIType which, int amount); + bool addItemToInventory(AIType type, int amount, char *funcInit, char *funcAction, char *funcUse); + void keepInvItem(AIType type); + void printYouGotMsg(const char *name); // Delivery Functions void newDelivery(const char *itemTextName, const char *itemGfxName, const char *destTextName, const char *destGfxName, const char *id); @@ -1124,6 +1143,8 @@ public: // Virtual Player AIEntity _dummyPlayer, _dummyLaser; + char _youGotBuffer[32]; // For printing the text of entities that are removed + // Cinematic Variables Common::Array<CineCommand *> _cine; |