From e9671a73eb505d7d7ad8262a65adfd372b8209f2 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 30 Jun 2021 07:31:22 +0200 Subject: [PATCH] SAGA2: Fix MSVC warnings --- engines/saga2/actor.cpp | 10 +++-- engines/saga2/intrface.cpp | 32 ++++----------- engines/saga2/motion.cpp | 6 +-- engines/saga2/objects.cpp | 19 ++++----- engines/saga2/panel.cpp | 5 ++- engines/saga2/path.cpp | 4 +- engines/saga2/sensor.cpp | 6 +-- engines/saga2/speech.cpp | 4 +- engines/saga2/spellio.cpp | 7 ++-- engines/saga2/tile.cpp | 80 ++++++-------------------------------- 10 files changed, 52 insertions(+), 121 deletions(-) diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp index e9a1b5134bc..61eff99309a 100644 --- a/engines/saga2/actor.cpp +++ b/engines/saga2/actor.cpp @@ -656,7 +656,7 @@ bool ActorProto::acceptInsertionAtAction( heldInRightHand, worn } inUseType; - int wornWhere; + int wornWhere = 0; assert(isActor(dObj)); assert(isObject(item)); @@ -1378,7 +1378,7 @@ Actor *Actor::newActor( uint8 factionNum, uint8 initFlags) { GameObject *limbo = objectAddress(ActorLimbo); - Actor *a; + Actor *a = nullptr; debugC(2, kDebugActors, "Actor::newActor(protoNum = %d, nameIndex = %d, scriptIndex = %d, appearanceNum = %d, colorSchemeIndex = %d, factionNum = %d, initFlags = %d)", protoNum, nameIndex, scriptIndex, appearanceNum, colorSchemeIndex, factionNum, initFlags); @@ -1399,12 +1399,16 @@ Actor *Actor::newActor( // REM: If things start getting really tight, we can // start recycling common objects... - if (i >= actorCount) return NULL; + if (i >= actorCount) + return nullptr; } else { actorLimboCount--; a = (Actor *)limbo->child(); } + if (!a) + return nullptr; + a->setLocation(Location(0, 0, 0, Nothing)); a->init( protoNum, diff --git a/engines/saga2/intrface.cpp b/engines/saga2/intrface.cpp index fc3b56908a0..831b7be16ec 100644 --- a/engines/saga2/intrface.cpp +++ b/engines/saga2/intrface.cpp @@ -2574,7 +2574,7 @@ APPFUNC(cmdManaInd) { int manaType = -1; int numManaRegions = ManaIndicator->getNumManaRegions(); int i; - int curMana, baseMana; + int curMana = 0, baseMana = 0; PlayerActor *player = &playerList[getCenterActorPlayerID()]; ActorAttributes *stats = player->getEffStats(); ActorAttributes baseStatsRef = player->getBaseStats(); @@ -2598,46 +2598,28 @@ APPFUNC(cmdManaInd) { } switch (manaType) { -#define RED_MANA "Red Mana:" -#define ORANGE_MANA "Orange Mana:" - - - -#define YELLOW_MANA "Yellow Mana:" - - - -#define GREEN_MANA "Green Mana:" - - - -#define BLUE_MANA "Blue Mana:" - - - -#define VIOLET_MANA "Purple Mana:" case 0: - sprintf(textBuffer, "%s %d/%d", RED_MANA, curMana, baseMana); + sprintf(textBuffer, "%s %d/%d", "Red Mana:", curMana, baseMana); break; case 1: - sprintf(textBuffer, "%s %d/%d", ORANGE_MANA, curMana, baseMana); + sprintf(textBuffer, "%s %d/%d", "Orange Mana:", curMana, baseMana); break; case 2: - sprintf(textBuffer, "%s %d/%d", YELLOW_MANA, curMana, baseMana); + sprintf(textBuffer, "%s %d/%d", "Yellow Mana:", curMana, baseMana); break; case 3: - sprintf(textBuffer, "%s %d/%d", GREEN_MANA, curMana, baseMana); + sprintf(textBuffer, "%s %d/%d", "Green Mana:", curMana, baseMana); break; case 4: - sprintf(textBuffer, "%s %d/%d", BLUE_MANA, curMana, baseMana); + sprintf(textBuffer, "%s %d/%d", "Blue Mana:", curMana, baseMana); break; case 5: - sprintf(textBuffer, "%s %d/%d", VIOLET_MANA, curMana, baseMana); + sprintf(textBuffer, "%s %d/%d", "Purple Mana:", curMana, baseMana); break; case -1: diff --git a/engines/saga2/motion.cpp b/engines/saga2/motion.cpp index ca619712036..ff62651d875 100644 --- a/engines/saga2/motion.cpp +++ b/engines/saga2/motion.cpp @@ -2491,12 +2491,12 @@ void MotionTask::walkAction(void) { TilePoint immediateTarget = getImmediateTarget(), newPos, targetVector; - int16 targetDist; + int16 targetDist = 0; int16 movementDirection, directionAngle; int16 moveBlocked, - speed, - speedScale; + speed = walkSpeed, + speedScale = 2; Actor *a; ActorAppearance *aa; StandingTileInfo sti; diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp index 5f4f93ab058..141ce15088d 100644 --- a/engines/saga2/objects.cpp +++ b/engines/saga2/objects.cpp @@ -1167,7 +1167,7 @@ ObjectID GameObject::makeAlias(const Location &l) { // return it's address GameObject *GameObject::newObject(void) { // get a newly created object GameObject *limbo = objectAddress(ObjectLimbo), - *obj; + *obj = nullptr; if (limbo->_data.childID == Nothing) { int16 i; @@ -1185,7 +1185,8 @@ GameObject *GameObject::newObject(void) { // get a newly created object // REM: If things start getting really tight, we can // start recycling common objects... - if (i >= objectCount) return nullptr; + if (i >= objectCount) + return nullptr; } else { objectLimboCount--; obj = limbo->child(); @@ -3453,19 +3454,19 @@ ObjectID RadialObjectIterator::first(GameObject **obj, int16 *dist) { // Return the next object within the specified region ObjectID RadialObjectIterator::next(GameObject **obj, int16 *dist) { - GameObject *currentObject; + GameObject *currentObject = nullptr; ObjectID currentObjectID; - int16 currentDist; + int16 currentDist = 0; do { currentObjectID = SectorRegionObjectIterator::next(¤tObject); } while (currentObjectID != Nothing - && (currentDist = - computeDist(currentObject->getLocation())) - > radius); + && (currentDist = computeDist(currentObject->getLocation())) > radius); - if (dist != nullptr) *dist = currentDist; - if (obj != nullptr) *obj = currentObject; + if (dist != nullptr) + *dist = currentDist; + if (obj != nullptr) + *obj = currentObject; return currentObjectID; } diff --git a/engines/saga2/panel.cpp b/engines/saga2/panel.cpp index 420db50071c..d949e95b8c9 100644 --- a/engines/saga2/panel.cpp +++ b/engines/saga2/panel.cpp @@ -182,9 +182,10 @@ void gPanel::invalidate(Rect16 *) { void gPanel::drawTitle(enum text_positions placement) { gPort &port = window.windowPort; Rect16 r = extent; - const gPixelMap *img; + const gPixelMap *img = nullptr; - if (title == NULL) return; + if (title == NULL) + return; if (imageLabel) { img = (const gPixelMap *)title; diff --git a/engines/saga2/path.cpp b/engines/saga2/path.cpp index 80da6a10cfc..85054c96b38 100644 --- a/engines/saga2/path.cpp +++ b/engines/saga2/path.cpp @@ -124,6 +124,8 @@ static StaticTilePoint tDirTable3[8] = { struct PathTileInfo { TileInfo *surfaceTile; int16 surfaceHeight; + + PathTileInfo() : surfaceTile(nullptr), surfaceHeight(0) {} }; typedef PathTileInfo PathTilePosInfo[maxPlatforms]; @@ -1582,7 +1584,7 @@ big_break: void PathRequest::finish(void) { Direction prevDir; - int16 prevHeight; + int16 prevHeight = 0; StaticTilePoint *resultSteps = path, coords; int16 stepCount = 0; diff --git a/engines/saga2/sensor.cpp b/engines/saga2/sensor.cpp index f18543b08af..729654888fd 100644 --- a/engines/saga2/sensor.cpp +++ b/engines/saga2/sensor.cpp @@ -90,7 +90,7 @@ void deleteSensor(Sensor *p) { void *constructSensor(int16 ctr, void *buf) { int16 type; - Sensor *sensor; + Sensor *sensor = nullptr; SensorList *sl; // Get the sensor type @@ -123,12 +123,12 @@ void *constructSensor(int16 ctr, void *buf) { break; } - assert(sensor != NULL); + assert(sensor != nullptr); // Get the sensor list sl = fetchSensorList(sensor->getObject()); - assert(sl != NULL); + assert(sl != nullptr); // Append this Sensor to the sensor list sl->_list.push_back(sensor); diff --git a/engines/saga2/speech.cpp b/engines/saga2/speech.cpp index 13cf9959132..00ef910cc71 100644 --- a/engines/saga2/speech.cpp +++ b/engines/saga2/speech.cpp @@ -622,7 +622,7 @@ int16 TextWrap( int16 i, // loop counter line_start, // start of current line last_space, // last space encountered - last_space_pixels, // pixel pos of last space + last_space_pixels = 0, // pixel pos of last space pixel_len, // pixel length of line line_count = 0; // number of lines @@ -688,7 +688,7 @@ int16 buttonWrap( int16 i, // loop counter line_start, // start of current line last_space, // last space encountered - last_space_pixels, // pixel pos of last space + last_space_pixels = 0, // pixel pos of last space charPixels, // pixel length of character linePixels, // pixels in current line buttonPixels, // pixels in current button diff --git a/engines/saga2/spellio.cpp b/engines/saga2/spellio.cpp index f1db67695ee..87d718ebe4e 100644 --- a/engines/saga2/spellio.cpp +++ b/engines/saga2/spellio.cpp @@ -98,7 +98,7 @@ void SpellStuff::setupFromResource(ResourceSpellItem *rsi) { // add spell internal effect void SpellStuff::addEffect(ResourceSpellEffect *rse) { - ProtoEffect *pe; + ProtoEffect *pe = nullptr; assert(rse && rse->spell == master); switch (rse->effectGroup) { case effectNone : @@ -197,11 +197,10 @@ void SpellStuff::addEffect(ResourceSpellEffect *rse) { break; } } - if (pe == NULL) + if (pe == nullptr) error("failed to alloc protoEffect"); - - if (effects == NULL) + if (effects == nullptr) effects = pe; else { ProtoEffect *tail; diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp index 604915a6a16..9c917fb6eaf 100644 --- a/engines/saga2/tile.cpp +++ b/engines/saga2/tile.cpp @@ -2646,7 +2646,7 @@ inline void drawMetaRow(TilePoint coords, Point16 pos) { pos.x += kMetaTileWidth ) { TilePoint clipCoords; - int16 mtile; + int16 mtile = 0; MetaTilePtr metaPtr; clipCoords.u = (uint16)coords.u % curMap->mapSize; @@ -3283,7 +3283,7 @@ void maskMetaRow( pos.x += kMetaTileWidth ) { TilePoint clipCoords; - int16 mtile; + int16 mtile = 0; MetaTilePtr metaPtr; clipCoords.u = (uint16)coords.u % curMap->mapSize; @@ -3311,9 +3311,11 @@ void maskMetaRow( mtile = mapData[clipCoords.u * curMap->mapSize + clipCoords.v] & ~metaTileVisited; break; } - } else mtile = mapData[clipCoords.u * curMap->mapSize + clipCoords.v] & ~metaTileVisited; + } else + mtile = mapData[clipCoords.u * curMap->mapSize + clipCoords.v] & ~metaTileVisited; - if (mtile >= curMap->metaCount) mtile = curMap->metaCount - 1; + if (mtile >= curMap->metaCount) + mtile = curMap->metaCount - 1; metaPtr = metaArray[mtile]; put = drawList; @@ -4071,7 +4073,7 @@ TilePoint pickTile(Point32 pos, testCoords, deltaP; MetaTile *mt; - ActiveItemPtr bestTileTAI; + ActiveItemPtr bestTileTAI = nullptr; TileInfo *ti, *bestTile = nullptr; uint8 *imageData; @@ -4190,36 +4192,21 @@ TilePoint pickTile(Point32 pos, if (sti.surfaceTAG == nullptr) { if (surface != surfaceHoriz - && pointOnHiddenSurface( - tCoords + origin, - pCoords, - surface)) { - surface = surface == surfaceVertU - ? surfaceVertV - : surfaceVertU; + && pointOnHiddenSurface(tCoords + origin, pCoords, surface)) { + surface = surface == surfaceVertU ? surfaceVertV : surfaceVertU; } // If pick point is on vertical surface // not facing protaganist, reject tile - if (surface == surfaceVertU - && pCoords.v < protagPos.v) + if (surface == surfaceVertU && pCoords.v < protagPos.v) continue; - if (surface == surfaceVertV - && pCoords.u < protagPos.u) + if (surface == surfaceVertV && pCoords.u < protagPos.u) continue; - /* // Make sure surface is exposed, else reject it - if ( surface != surfaceHoriz - && !validSurface( tCoords + origin, pCoords ) ) - continue;*/ } pickCoords = pCoords; floorCoords = fCoords; bestTile = ti; -#ifdef DAVIDR - bestTP = tCoords + origin; - bestTP.z = sti.surfaceHeight; -#endif bestTileTAI = sti.surfaceTAG; } } @@ -4263,51 +4250,6 @@ TilePoint pickTile(Point32 pos, return pickCoords; } -#ifdef DAVIDR - if (showTile) { - if (bestTile) { - bestTP.u <<= kTileUVShift; - bestTP.v <<= kTileUVShift; - showAbstractTile(bestTP, bestTile); - - TilePoint pt1, pt2; - pt1 = pt2 = pickCoords; - pt1.u += 3; - pt2.u -= 3; - TPLine(pt1, pt2); - pt1 = pt2 = pickCoords; - pt1.v += 3; - pt2.v -= 3; - TPLine(pt1, pt2); - - pt1 = pt2 = floorCoords; - pt1.u += 2; - pt1.v += 2; - pt2.u -= 2; - pt2.v -= 2; - TPLine(pt1, pt2); - pt1 = pt2 = floorCoords; - pt1.u += 2; - pt1.v -= 2; - pt2.u -= 2; - pt2.v += 2; - TPLine(pt1, pt2); - - pt1 = pt2 = pickCoords; - pt1.z = bestTP.z; - TPLine(pt1, pt2); - pt2.z = bestTP.z; - pt2.u = pt1.u & 0xFFF0; - TPLine(pt1, pt2); - pt2.u = pt1.u; - pt2.v = pt1.v & 0xFFF0; - TPLine(pt1, pt2); - - WriteStatusF(8, "%4.4x:%4.4x:%4.4x", pickCoords.u, pickCoords.v, pickCoords.z); - } - } -#endif - if (floorResult) *floorResult = floorCoords; if (pickTAI) *pickTAI = bestTileTAI; return pickCoords;