diff options
author | Strangerke | 2019-07-22 17:38:57 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:17:26 +0200 |
commit | bcf910470c0dfef858045cc224ec686e539937b8 (patch) | |
tree | 3954c14b3aaf49809e7b5433e571b6a31792d5e2 | |
parent | 04901e7ac9d38ef17191832b370ef25ea5557bef (diff) | |
download | scummvm-rg350-bcf910470c0dfef858045cc224ec686e539937b8.tar.gz scummvm-rg350-bcf910470c0dfef858045cc224ec686e539937b8.tar.bz2 scummvm-rg350-bcf910470c0dfef858045cc224ec686e539937b8.zip |
HDB: Fix some CppCheck warnings in ai-player, ai-use, ai-waypoint and gfx
-rw-r--r-- | engines/hdb/ai-player.cpp | 41 | ||||
-rw-r--r-- | engines/hdb/ai-use.cpp | 24 | ||||
-rw-r--r-- | engines/hdb/ai-waypoint.cpp | 42 | ||||
-rw-r--r-- | engines/hdb/gfx.cpp | 65 |
4 files changed, 74 insertions, 98 deletions
diff --git a/engines/hdb/ai-player.cpp b/engines/hdb/ai-player.cpp index 25f371202c..86d22b20b1 100644 --- a/engines/hdb/ai-player.cpp +++ b/engines/hdb/ai-player.cpp @@ -107,8 +107,10 @@ void aiPlayerInit2(AIEntity *e) { } void aiPlayerAction(AIEntity *e) { - AIState stand[5] = {STATE_NONE, STATE_STANDUP, STATE_STANDDOWN, STATE_STANDLEFT, STATE_STANDRIGHT}; - int xvAhead[5] = {9, 0, 0, -1, 1}, yvAhead[5] = {9, -1, 1, 0, 0}; + static const AIState stand[5] = {STATE_NONE, STATE_STANDUP, STATE_STANDDOWN, STATE_STANDLEFT, STATE_STANDRIGHT}; + static const int xvAhead[5] = {9, 0, 0, -1, 1}; + static const int yvAhead[5] = {9, -1, 1, 0, 0}; + AIEntity *hit = NULL; // Draw the STUN lightning if it exists @@ -473,9 +475,8 @@ void aiGemAttackInit(AIEntity *e) { } void aiGemAttackAction(AIEntity *e) { - int xv[5] = {9, 0, 0, -1, 1}, yv[5] = {9, -1, 1, 0, 0}; - AIEntity *hit; - int result; + static const int xv[5] = {9, 0, 0, -1, 1}; + static const int yv[5] = {9, -1, 1, 0, 0}; switch (e->sequence) { // flying out at something @@ -486,10 +487,10 @@ void aiGemAttackAction(AIEntity *e) { g_hdb->_ai->checkActionList(e, e->tileX, e->tileY, false); g_hdb->_ai->checkAutoList(e, e->tileX, e->tileY); - hit = g_hdb->_ai->findEntityIgnore(e->tileX, e->tileY, e); + AIEntity *hit = g_hdb->_ai->findEntityIgnore(e->tileX, e->tileY, e); uint32 bgFlags = g_hdb->_map->getMapBGTileFlags(e->tileX, e->tileY); uint32 fgFlags = g_hdb->_map->getMapFGTileFlags(e->tileX, e->tileY); - result = (e->level == 1 ? (bgFlags & (kFlagSolid)) : !(fgFlags & kFlagGrating) && (bgFlags & (kFlagSolid))); + int result = (e->level == 1 ? (bgFlags & (kFlagSolid)) : !(fgFlags & kFlagGrating) && (bgFlags & (kFlagSolid))); if (hit) { switch (hit->type) { case AI_CHICKEN: @@ -791,30 +792,29 @@ void aiBarrelExplodeAction(AIEntity *e) { } void aiBarrelExplodeSpread(AIEntity *e) { - AIEntity *e2; + static const int xv1[4] = {-1, 1, -1, 0}; + static const int yv1[4] = {-1, -1, 0, -1}; + static const int xv2[4] = {1, 0, 1, -1}; + static const int yv2[4] = {0, 1, 1, 1}; + int x = e->tileX; int y = e->tileY; - int xv, yv; int index = e->animFrame; - int xv1[4] = {-1, 1, -1, 0}; - int yv1[4] = {-1, -1, 0, -1}; - int xv2[4] = {1, 0, 1, -1}; - int yv2[4] = {0, 1, 1, 1}; // are we just starting an explosion ring? if (e->animDelay != e->animCycle) return; // the animation frame is the index into which set of 2 explosions to spawn - xv = xv1[index]; - yv = yv1[index]; + int xv = xv1[index]; + int yv = yv1[index]; // explosion 1: check to see if we can explode (non-solid tile) // if so, spawn it and mark it in the explosion matrix if (!(g_hdb->_map->getMapBGTileFlags(x + xv, y + yv) & kFlagSolid) && !g_hdb->_map->explosionExist(x + xv, y + yv)) { aiBarrelBlowup(e, x + xv, y + yv); // are we blowing up on another BOOMBARREL? if so, start it exploding. - e2 = g_hdb->_ai->findEntity(x + xv, y + yv); + AIEntity *e2 = g_hdb->_ai->findEntity(x + xv, y + yv); if (e2 && e2->state != STATE_EXPLODING) { switch (e2->type) { case AI_GUY: @@ -858,7 +858,7 @@ void aiBarrelExplodeSpread(AIEntity *e) { if (!(g_hdb->_map->getMapBGTileFlags(x + xv, y + yv) & kFlagSolid) && !g_hdb->_map->explosionExist(x + xv, y + yv)) { aiBarrelBlowup(e, x + xv, y + yv); // are we blowing up on another BOOMBARREL? if so, start it exploding. - e2 = g_hdb->_ai->findEntity(x + xv, y + yv); + AIEntity *e2 = g_hdb->_ai->findEntity(x + xv, y + yv); if (e2 && e2->state != STATE_EXPLODING) { switch (e2->type) { case AI_GUY: @@ -1590,17 +1590,14 @@ void aiMonkeystoneUse(AIEntity *e) { } void aiGemAction(AIEntity *e) { - AIEntity *p; - int tolerance; - e->animFrame++; if (e->animFrame >= e->standdownFrames) { e->animFrame = 0; // every 4th frame, check for player collision & // add to inventory if it happens - p = g_hdb->_ai->getPlayer(); - tolerance = 16; + AIEntity *p = g_hdb->_ai->getPlayer(); + int tolerance = 16; if (g_hdb->_ai->playerRunning()) tolerance = 24; diff --git a/engines/hdb/ai-use.cpp b/engines/hdb/ai-use.cpp index 806491fe7b..21c331bb2a 100644 --- a/engines/hdb/ai-use.cpp +++ b/engines/hdb/ai-use.cpp @@ -89,11 +89,9 @@ bool AI::isOpenDoor(int x, int y) { } bool AI::useTarget(int x, int y, int targetX, int targetY, int newTile, int *worked) { - int tileIndex; - // open a locked door? if (isClosedDoor(targetX, targetY)) { - tileIndex = g_hdb->_map->getMapBGTileIndex(targetX, targetY); + int tileIndex = g_hdb->_map->getMapBGTileIndex(targetX, targetY); addAnimateTarget(targetX, targetY, tileIndex, tileIndex - 3, ANIM_SLOW, false, true, NULL); g_hdb->_map->setMapBGTileIndex(x, y, newTile); @@ -105,7 +103,7 @@ bool AI::useTarget(int x, int y, int targetX, int targetY, int newTile, int *wor // close an open door? if (isOpenDoor(targetX, targetY)) { - tileIndex = g_hdb->_map->getMapBGTileIndex(targetX, targetY); + int tileIndex = g_hdb->_map->getMapBGTileIndex(targetX, targetY); addAnimateTarget(targetX, targetY, tileIndex, tileIndex + 3, ANIM_SLOW, false, true, NULL); g_hdb->_map->setMapBGTileIndex(x, y, newTile); @@ -116,7 +114,7 @@ bool AI::useTarget(int x, int y, int targetX, int targetY, int newTile, int *wor } // open up a bridge? - tileIndex = g_hdb->_map->getMapFGTileIndex(targetX, targetY); + int tileIndex = g_hdb->_map->getMapFGTileIndex(targetX, targetY); if (tileIndex == _targetBridgeU || tileIndex == _targetBridgeD || tileIndex == _targetBridgeL || @@ -158,11 +156,9 @@ bool AI::useLockedSwitch(AIEntity *e, int x, int y, int targetX, int targetY, in return false; int amount = queryInventoryType(item); - int worked; - bool rtn; - if (amount) { - rtn = useTarget(x, y, targetX, targetY, onTile, &worked); + int worked; + bool rtn = useTarget(x, y, targetX, targetY, onTile, &worked); if (worked) { removeInvItemType(item, 1); if (g_hdb->_map->onScreen(x, y)) @@ -182,12 +178,11 @@ bool AI::useLockedSwitchOn(AIEntity *e, int x, int y, int targetX, int targetY, if (abs(x - _player->tileX) > 1 || abs(y - _player->tileY) > 1) return false; - int worked; - bool rtn; if (getInvAmount() == 10) return false; - rtn = useTarget(x, y, targetX, targetY, offTile, &worked); + int worked; + bool rtn = useTarget(x, y, targetX, targetY, offTile, &worked); if (worked) { addItemToInventory(item, 1, NULL, NULL, NULL); if (g_hdb->_map->onScreen(x, y)) @@ -203,11 +198,10 @@ bool AI::useCellHolder(AIEntity *e, int x, int y, int targetX, int targetY) { return false; int amount = queryInventoryType(ITEM_CELL); - int worked; - bool rtn; if (amount) { - rtn = useTarget(x, y, targetX, targetY, _useHolderFull, &worked); + int worked; + bool rtn = useTarget(x, y, targetX, targetY, _useHolderFull, &worked); if (worked) { removeInvItemType(ITEM_CELL, 1); if (g_hdb->_map->onScreen(x, y)) diff --git a/engines/hdb/ai-waypoint.cpp b/engines/hdb/ai-waypoint.cpp index cbc9e9efc2..34704d2e08 100644 --- a/engines/hdb/ai-waypoint.cpp +++ b/engines/hdb/ai-waypoint.cpp @@ -363,29 +363,29 @@ void AI::clearWaypoints() { } bool AI::traceStraightPath(int x1, int y1, int *x2, int *y2, int *level) { - int xVel, yVel, ok, entOK; - AIEntity *e; - // this checks to make sure we're only going vert or horz if (x1 != *x2 && y1 != *y2) return false; // this sets a -1, 0, or 1 step value - xVel = *x2 - x1; + int xVel = *x2 - x1; if (xVel < 0) xVel = -1; if (xVel > 0) xVel = 1; - yVel = *y2 - y1; + int yVel = *y2 - y1; if (yVel < 0) yVel = -1; if (yVel > 0) yVel = 1; + AIEntity *e; while (1) { // clear tile ahead? - entOK = ok = 0; + bool entOK = false; + bool ok = false; + uint32 flags = g_hdb->_map->getMapBGTileFlags(x1, y1); if (flags & kFlagStairTop) *level = 2; @@ -401,23 +401,23 @@ bool AI::traceStraightPath(int x1, int y1, int *x2, int *y2, int *level) { ((flags & kFlagRadFloor) == kFlagRadFloor); e = findEntity(x1, y1); if (e && g_hdb->_ai->walkThroughEnt(e->type)) - entOK = 1; + entOK = true; else if (ok && e && (e->state == STATE_FLOATING || e->state == STATE_MELTED || e == _player)) - entOK = ok = 1; + entOK = ok = true; else - ok = 0; + ok = false; } else if (ok && ((flags & kFlagWater) == kFlagWater || (flags & kFlagSlime) == kFlagSlime)) { // if it's non-blocking, is there water or slime? e = findEntity(x1, y1); if (e && g_hdb->_ai->walkThroughEnt(e->type)) - entOK = 1; + entOK = true; else if (e && (e->state == STATE_FLOATING || e->state == STATE_MELTED || e == _player)) - entOK = ok = 1; + entOK = ok = true; else - ok = 0; + ok = false; } } else { // Floor level 2 @@ -432,23 +432,23 @@ bool AI::traceStraightPath(int x1, int y1, int *x2, int *y2, int *level) { ((flags & kFlagRadFloor) == kFlagRadFloor); e = findEntity(x1, y1); if (e && g_hdb->_ai->walkThroughEnt(e->type)) - entOK = 1; + entOK = true; else if (ok && e && (e->state == STATE_FLOATING || e->state == STATE_MELTED || e == _player)) - entOK = ok = 1; + entOK = ok = true; else - ok = 0; + ok = false; } else if (ok && ((flags & kFlagWater) == kFlagWater || (flags & kFlagSlime) == kFlagSlime)) { // if it's non-blocking, is there water or slime? e = findEntity(x1, y1); if (e && g_hdb->_ai->walkThroughEnt(e->type)) - entOK = 1; + entOK = true; else if (e && (e->state == STATE_FLOATING || e->state == STATE_MELTED || e == _player)) - entOK = ok = 1; + entOK = ok = true; else - ok = 0; + ok = false; } } } @@ -529,16 +529,15 @@ Tile *AI::getStandFrameDir(AIEntity *e) { } void AI::drawWayPoints() { - int i; - int mapX, mapY; static int anim = 0; static uint32 delay = g_hdb->getTimeSlice(); static int alpha = 255; static int aVel = -4; + int mapX, mapY; g_hdb->_map->getMapXY(&mapX, &mapY); - for (i = 0; i < _numWaypoints; i++) { + for (int i = 0; i < _numWaypoints; i++) { int x = _waypoints[i].x * kTileWidth; int y = _waypoints[i].y * kTileHeight; @@ -562,6 +561,7 @@ void AI::drawWayPoints() { // don't animate every single game frame... if (delay > g_hdb->getTimeSlice()) return; + delay = g_hdb->getTimeSlice() + 100; // cycle the waypoint gfx animation diff --git a/engines/hdb/gfx.cpp b/engines/hdb/gfx.cpp index aba874213e..9dc3d3b76c 100644 --- a/engines/hdb/gfx.cpp +++ b/engines/hdb/gfx.cpp @@ -171,8 +171,6 @@ bool Gfx::init() { } void Gfx::save(Common::OutSaveFile *out) { - int i; - out->writeSint32LE(_currentSky); out->writeByte(_fadeInfo.active); @@ -183,19 +181,17 @@ void Gfx::save(Common::OutSaveFile *out) { out->writeSint32LE(_fadeInfo.curStep); out->writeByte(_snowInfo.active); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) out->writeDoubleLE(_snowInfo.x[i]); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) out->writeDoubleLE(_snowInfo.y[i]); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) out->writeDoubleLE(_snowInfo.yv[i]); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) out->writeSint32LE(_snowInfo.xvindex[i]); } void Gfx::loadSaveFile(Common::InSaveFile *in) { - int i; - _currentSky = in->readSint32LE(); _fadeInfo.active = in->readByte(); @@ -207,13 +203,13 @@ void Gfx::loadSaveFile(Common::InSaveFile *in) { _snowInfo.active = in->readByte(); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) _snowInfo.x[i] = in->readDoubleLE(); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) _snowInfo.y[i] = in->readDoubleLE(); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) _snowInfo.yv[i] = in->readDoubleLE(); - for (i = 0; i < MAX_SNOW; i++) + for (int i = 0; i < MAX_SNOW; i++) _snowInfo.xvindex[i] = in->readSint32LE(); setSky(_currentSky); @@ -387,9 +383,8 @@ void Gfx::updateFade() { } void Gfx::turnOnSnow() { - int i; _snowInfo.active = true; - for (i = 0; i < MAX_SNOW; i++) { + for (int i = 0; i < MAX_SNOW; i++) { _snowInfo.x[i] = g_hdb->_rnd->getRandomNumber(kScreenWidth - 1); _snowInfo.y[i] = g_hdb->_rnd->getRandomNumber(kScreenHeight - 1); _snowInfo.yv[i] = g_hdb->_rnd->getRandomNumber(2) + 1; @@ -434,7 +429,6 @@ Tile *Gfx::loadIcon(const char *tileName) { } Tile *Gfx::getTile(int index) { - if (index < 0 || index > _numTiles) { if (index != 0xFFFF) debug(6, "getTile(%d): wrong index > %d", index, _numTiles); @@ -535,7 +529,7 @@ bool Gfx::selectGfxType(const char *name) { Tile *Gfx::getTileGfx(const char *name, int32 size) { // Try to find graphic - for (Common::Array<GfxCache *>::iterator it = _gfxCache->begin(); it != _gfxCache->end(); it++) { + for (Common::Array<GfxCache *>::iterator it = _gfxCache->begin(); it != _gfxCache->end(); ++it) { if (Common::matchString((*it)->name, name)) { if ((*it)->loaded == -1) { // Marked for Deletetion? (*it)->loaded = 1; // Reactivate it @@ -559,7 +553,7 @@ Tile *Gfx::getTileGfx(const char *name, int32 size) { } void Gfx::markGfxCacheFreeable() { - for (Common::Array<GfxCache *>::iterator it = _gfxCache->begin(); it != _gfxCache->end(); it++) + for (Common::Array<GfxCache *>::iterator it = _gfxCache->begin(); it != _gfxCache->end(); ++it) (*it)->loaded = -1; } @@ -569,7 +563,7 @@ void Gfx::markTileCacheFreeable() { Picture *Gfx::getPicGfx(const char *name, int32 size) { // Try to find graphic - for (Common::Array<GfxCache *>::iterator it = _gfxCache->begin(); it != _gfxCache->end(); it++) { + for (Common::Array<GfxCache *>::iterator it = _gfxCache->begin(); it != _gfxCache->end(); ++it) { if (Common::matchString((*it)->name, name)) { if ((*it)->loaded == -1) { // Marked for Deletetion? (*it)->loaded = 1; // Reactivate it @@ -740,12 +734,11 @@ bool Gfx::loadFont(const char *string) { debug(3, "leading: %d", _fontHeader.leading); // Loading _charInfoBlocks & creating character surfaces - CharInfo *cInfo; int startPos = stream->pos(); // Position after _fontHeader int curPos; // Position after reading cInfo uint16 *ptr; for (int i = 0; i < _fontHeader.numChars; i++) { - cInfo = new CharInfo; + CharInfo *cInfo = new CharInfo; cInfo->width = (int16)stream->readUint32LE(); cInfo->offset = (int32)stream->readUint32LE(); @@ -856,13 +849,12 @@ void Gfx::getDimensions(const char *string, int *pixelsWide, int *lines) { } int width, maxWidth, height; - unsigned char c; maxWidth = 0; width = _eLeft; height = 1; for (int i = 0; i < (int)strlen(string); i++) { - c = string[i]; + unsigned char c = string[i]; width += _charInfoBlocks[c]->width + _fontHeader.kerning + kFontIncrement; if (c == ' ') width += kFontSpace; @@ -909,9 +901,9 @@ int Gfx::stringLength(const char *string) { } void Gfx::centerPrint(const char *string) { - int totalWidth = 0, i; + int totalWidth = 0; - for (i = 0; i < (int)strlen(string); i++) { + for (int i = 0; i < (int)strlen(string); i++) { if (string[i] == ' ') totalWidth += kFontSpace; else if (string[i] != '\n') @@ -957,9 +949,8 @@ void Gfx::getCursor(int *x, int *y) { } void Gfx::turnOnBonusStars(int which) { - int i; _starsInfo.active = true; - for (i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) _starsInfo.starAngle[i] = (36 * (i + 1)) - 10; if (!_starsInfo.gfx[0]) { switch (which) { @@ -987,8 +978,6 @@ void Gfx::turnOnBonusStars(int which) { } void Gfx::drawBonusStars() { - int i, w, h; - if (!_starsInfo.active) return; @@ -997,10 +986,10 @@ void Gfx::drawBonusStars() { _starsInfo.anim = 1 - _starsInfo.anim; } - w = _starsInfo.gfx[0]->_width / 2; - h = _starsInfo.gfx[0]->_height / 2; + int w = _starsInfo.gfx[0]->_width / 2; + int h = _starsInfo.gfx[0]->_height / 2; - for (i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { _starsInfo.gfx[_starsInfo.anim]->drawMasked( (int)(480 / 2 + ((float)_starsInfo.radius / 2)) + (int)((double)_starsInfo.radius * _cosines->at(_starsInfo.starAngle[i]) - w), (480 / 2) + (int)((double)_starsInfo.radius * _sines->at(_starsInfo.starAngle[i]) - h) @@ -1027,8 +1016,6 @@ void Gfx::drawBonusStars() { } void Gfx::drawDebugInfo(Tile *_debugLogo, int fps) { - int x, y; - AIEntity *p; char buff[64]; _debugLogo->drawMasked(kScreenWidth - 32, 0); @@ -1040,12 +1027,14 @@ void Gfx::drawDebugInfo(Tile *_debugLogo, int fps) { // Draw Player Info setCursor(0, 16); + + int x, y; g_hdb->_ai->getPlayerXY(&x, &y); sprintf(buff, "Player X: %d, Y: %d", x / kTileWidth, y / kTileHeight); drawText(buff); setCursor(0, 32); - p = g_hdb->_ai->getPlayer(); + AIEntity *p = g_hdb->_ai->getPlayer(); if (p) { sprintf(buff, "Player height level: %d", p->level); drawText(buff); @@ -1071,10 +1060,8 @@ Graphics::Surface Picture::load(Common::SeekableReadStream *stream) { _surface.create(_width, _height, g_hdb->_format); stream->readUint32LE(); // Skip Win32 Surface - uint16 *ptr; - for (int y = 0; y < _height; y++) { - ptr = (uint16 *)_surface.getBasePtr(0, y); + uint16 *ptr = (uint16 *)_surface.getBasePtr(0, y); for (int x = 0; x < _width; x++) { *ptr = TO_LE_16(stream->readUint16LE()); ptr++; @@ -1125,10 +1112,8 @@ Graphics::Surface Tile::load(Common::SeekableReadStream *stream) { _surface.create(32, 32, g_hdb->_format); stream->readUint32LE(); // Skip Win32 Surface - uint16 *ptr; - for (uint y = 0; y < 32; y++) { - ptr = (uint16 *)_surface.getBasePtr(0, y); + uint16 *ptr = (uint16 *)_surface.getBasePtr(0, y); for (uint x = 0; x < 32; x++) { *ptr = TO_LE_16(stream->readUint16LE()); ptr++; |