diff options
-rw-r--r-- | engines/hdb/ai-inventory.cpp | 18 | ||||
-rw-r--r-- | engines/hdb/ai.h | 16 |
2 files changed, 22 insertions, 12 deletions
diff --git a/engines/hdb/ai-inventory.cpp b/engines/hdb/ai-inventory.cpp index cc1a28162c..272d41dc89 100644 --- a/engines/hdb/ai-inventory.cpp +++ b/engines/hdb/ai-inventory.cpp @@ -92,13 +92,11 @@ void AI::clearInventory() { int keepslot = 0; for (int i = 0; i < _numInventory; i++) { if (!_inventory[i].keep) { - memset(&_inventory[i], 0, sizeof(InvEnt)); + _inventory[i].reset(); } else { if (i != keepslot) { _inventory[keepslot] = _inventory[i]; - _inventory[keepslot].ent = _inventory[i].ent; - _inventory[keepslot].keep = _inventory[i].keep; - memset(&_inventory[i], 0, sizeof(InvEnt)); + _inventory[i].reset(); } keepslot++; } @@ -154,10 +152,10 @@ bool AI::removeInvItem(const char *string, int amount) { for (int i = _numInventory - 1; i >= 0; i--) if (strstr(_inventory[i].ent.entityName, string)) { int j = i; - memset(&_inventory[j], 0, sizeof(InvEnt)); + _inventory[j].reset(); while (j < _numInventory - 1) { - memcpy(&_inventory[j], &_inventory[j + 1], sizeof(InvEnt)); - memset(&_inventory[j + 1], 0, sizeof(InvEnt)); + _inventory[j] = _inventory[j + 1]; + _inventory[j + 1].reset(); j++; } _numInventory--; @@ -228,10 +226,10 @@ bool AI::removeInvItemType(AIType which, int amount) { for (int i = 0; i < _numInventory; i++) { if (_inventory[i].ent.type == which) { int j = i; - memset(&_inventory[j], 0, sizeof(InvEnt)); + _inventory[j].reset(); while (j < _numInventory - 1) { - memcpy(&_inventory[j], &_inventory[j + 1], sizeof(InvEnt)); - memset(&_inventory[j + 1], 0, sizeof(InvEnt)); + _inventory[j] = _inventory[j + 1]; + _inventory[j + 1].reset(); j++; } _numInventory--; diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 572ab79186..86c3709aeb 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -456,7 +456,7 @@ struct AIEntity { int16 moverightFrames; Tile *moverightGfx[kMaxAnimFrames]; - AIEntity() { + void reset() { luaFuncInit[0] = 0; luaFuncAction[0] = 0; luaFuncUse[0] = 0; @@ -543,6 +543,11 @@ struct AIEntity { moverightGfx[i] = NULL; } } + + AIEntity() { + reset(); + } + ~AIEntity() { } @@ -602,7 +607,14 @@ struct InvEnt { uint16 keep; AIEntity ent; - InvEnt() : keep(0) {} + void reset() { + keep = 0; + ent.reset(); + } + + InvEnt() { + reset(); + } }; struct DlvEnt { |