HDB: Fix some CppCheck warnings in ai-inventory and ai-lists

This commit is contained in:
Strangerke 2019-07-21 19:57:05 +02:00 committed by Eugene Sandulenko
parent 8a44ed4a97
commit cfe228d7bb
2 changed files with 29 additions and 42 deletions

View File

@ -110,8 +110,6 @@ AIEntity *AI::getInvItem(int which) {
}
int AI::queryInventory(const char *string) {
int i, count;
if (!scumm_stricmp(string, "monkeystone"))
return getMonkeystoneAmount();
if (!scumm_stricmp(string, "goo"))
@ -122,8 +120,8 @@ int AI::queryInventory(const char *string) {
if (!_numInventory)
return 0;
count = 0;
for (i = _numInventory - 1; i >= 0; i--)
int count = 0;
for (int i = _numInventory - 1; i >= 0; i--)
if (_inventory[i].ent.entityName && strstr(_inventory[i].ent.entityName, string))
count++;
@ -131,9 +129,6 @@ int AI::queryInventory(const char *string) {
}
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;
@ -149,12 +144,13 @@ bool AI::removeInvItem(const char *string, int amount) {
if (!_numInventory)
return false;
bool found;
do {
found = 0;
found = false;
for (i = _numInventory - 1; i >= 0; i--)
for (int i = _numInventory - 1; i >= 0; i--)
if (_inventory[i].ent.entityName && strstr(_inventory[i].ent.entityName, string)) {
j = i;
int j = i;
memset(&_inventory[j], 0, sizeof(InvEnt));
while (j < _numInventory - 1) {
memcpy(&_inventory[j], &_inventory[j + 1], sizeof(InvEnt));
@ -163,7 +159,7 @@ bool AI::removeInvItem(const char *string, int amount) {
}
_numInventory--;
amount--;
found = 1;
found = true;
if (!amount)
break;
}
@ -177,8 +173,6 @@ bool AI::removeInvItem(const char *string, int amount) {
}
int AI::queryInventoryType(AIType which) {
int i, count;
if (which == ITEM_MONKEYSTONE)
return getMonkeystoneAmount();
if (which == ITEM_GOO_CUP)
@ -189,8 +183,8 @@ int AI::queryInventoryType(AIType which) {
if (!_numInventory)
return 0;
count = 0;
for (i = 0; i < _numInventory; i++)
int count = 0;
for (int i = 0; i < _numInventory; i++)
if (_inventory[i].ent.type == which)
count++;
@ -198,20 +192,16 @@ int AI::queryInventoryType(AIType which) {
}
int AI::queryInventoryTypeSlot(AIType which) {
int i;
if (!_numInventory)
return 0;
for (i = 0; i < _numInventory; i++)
for (int i = 0; i < _numInventory; i++)
if (_inventory[i].ent.type == which)
return i;
return -1;
}
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;
@ -227,12 +217,13 @@ bool AI::removeInvItemType(AIType which, int amount) {
if (!_numInventory)
return false;
bool found;
do {
found = 0;
found = false;
for (i = 0; i < _numInventory; i++)
for (int i = 0; i < _numInventory; i++)
if (_inventory[i].ent.type == which) {
j = i;
int j = i;
memset(&_inventory[j], 0, sizeof(InvEnt));
while (j < _numInventory - 1) {
memcpy(&_inventory[j], &_inventory[j + 1], sizeof(InvEnt));
@ -241,7 +232,7 @@ bool AI::removeInvItemType(AIType which, int amount) {
}
_numInventory--;
amount--;
found = 1;
found = true;
if (!amount)
break;
}
@ -255,11 +246,9 @@ bool AI::removeInvItemType(AIType which, int amount) {
}
bool AI::addItemToInventory(AIType type, int amount, const char *funcInit, const char *funcAction, const char *funcUse) {
int i;
AIEntity *e;
for (i = 0; i < amount; i++) {
for (int i = 0; i < amount; i++) {
spawn(type, DIR_UP, 0, 0, funcInit, funcAction, funcUse, DIR_UP, 1, 0, 0, 1);
e = findEntity(0, 0);
AIEntity *e = findEntity(0, 0);
if (!e)
return false;
if (!addToInventory(e))
@ -269,9 +258,10 @@ bool AI::addItemToInventory(AIType type, int amount, const char *funcInit, const
}
void AI::keepInvItem(AIType type) {
for (int i = 0; i < _numInventory; i++)
for (int i = 0; i < _numInventory; i++) {
if (_inventory[i].ent.type == type)
_inventory[i].keep = 1;
}
}
void AI::printYouGotMsg(const char *name) {

View File

@ -162,7 +162,7 @@ void AI::addBridgeExtend(int x, int y, int bridgeType) {
}
void AI::animateBridges() {
int i, j, tileIndex, xv, yv;
int tileIndex, xv, yv;
uint32 flags;
bool done;
@ -170,7 +170,7 @@ void AI::animateBridges() {
if (!_numBridges)
return;
for (i = 0; i < _numBridges; i++) {
for (int i = 0; i < _numBridges; i++) {
if (_bridges[i].delay-- > 0)
continue;
@ -231,7 +231,7 @@ void AI::animateBridges() {
if (!flags || (flags & kFlagMetal) || tileIndex >= 0 || (flags & kFlagSolid)) {
if (g_hdb->_map->onScreen(_bridges[i].x, _bridges[i].y))
g_hdb->_sound->playSound(SND_BRIDGE_END);
for (j = 0; j < _numBridges - 1; j++)
for (int j = 0; j < _numBridges - 1; j++)
memcpy(&_bridges[i], &_bridges[i + 1], sizeof(Bridge));
_numBridges--;
}
@ -250,17 +250,16 @@ void AI::addToFairystones(int index, int tileX, int tileY, int sourceOrDest) {
}
int AI::checkFairystones(int tileX, int tileY) {
int i;
for (i = 0; i < kMaxFairystones; i++)
for (int i = 0; i < kMaxFairystones; i++) {
if (_fairystones[i].destX == tileX && _fairystones[i].destY == tileY)
return i;
}
return -1;
}
// Add an action location to the list of possible actions
// Each action must be paired with another of the same number
void AI::addToActionList(int actionIndex, int x, int y, char *luaFuncInit, char *luaFuncUse) {
if (!_actions[actionIndex].x1) {
_actions[actionIndex].x1 = x;
_actions[actionIndex].y1 = y;
@ -356,7 +355,7 @@ void AI::addToHereList(const char *entName, int x, int y) {
}
HereT *AI::findHere(int x, int y) {
for (Common::Array<HereT *>::iterator it = _hereList->begin(); it != _hereList->end(); it++) {
for (Common::Array<HereT *>::iterator it = _hereList->begin(); it != _hereList->end(); ++it) {
if ((*it)->x == x && (*it)->y == y)
return *it;
}
@ -770,7 +769,7 @@ bool AI::checkTeleportList(AIEntity *e, int x, int y) {
g_hdb->_window->stopPanicZone();
// Is there an attack gem still floating around?
for (Common::Array<AIEntity *>::iterator it = _ents->begin(); it != _ents->end(); it++) {
for (Common::Array<AIEntity *>::iterator it = _ents->begin(); it != _ents->end(); ++it) {
if ((*it)->type == AI_GEM_ATTACK) {
int amt = getGemAmount();
setGemAmount(amt + 1);
@ -799,7 +798,7 @@ void AI::addToPathList(int x, int y, int type, AIDir dir) {
}
ArrowPath *AI::findArrowPath(int x, int y) {
for (Common::Array<ArrowPath *>::iterator it = _arrowPaths->begin(); it != _arrowPaths->end(); it++) {
for (Common::Array<ArrowPath *>::iterator it = _arrowPaths->begin(); it != _arrowPaths->end(); ++it) {
if ((*it)->tileX == x && (*it)->tileY == y)
return *it;
}
@ -835,10 +834,8 @@ void AI::addToTriggerList(char *luaFuncInit, char *luaFuncUse, int x, int y, int
}
bool AI::checkTriggerList(char *entName, int x, int y) {
Trigger *t;
for (Common::Array<Trigger *>::iterator it = _triggerList->begin(); it != _triggerList->end(); it++) {
t = *it;
for (Common::Array<Trigger *>::iterator it = _triggerList->begin(); it != _triggerList->end(); ++it) {
Trigger *t = *it;
if (t->x == x && t->y == y) {
if (!t->luaFuncUse[0])
return false;