SAGA2: Change abs to ABS

This commit is contained in:
Paul Gilbert 2021-07-04 11:18:23 -07:00
parent 9c1c4d3788
commit fd55e0f71a
18 changed files with 79 additions and 79 deletions

View File

@ -395,7 +395,7 @@ bool ActorProto::acceptDamageAction(
damage = absDamage;
if (dice)
for (int d = 0; d < abs(dice); d++)
for (int d = 0; d < ABS(dice); d++)
damage += ((rand() % sides) + pdm + 1) * (dice > 0 ? 1 : -1);
}
@ -3318,7 +3318,7 @@ int16 GetRandomBetween(int start, int end) {
// Here's a more efficient way to express this.
if (start == end) return start;
else return (rand() % abs(end - start)) + start;
else return (rand() % ABS(end - start)) + start;
}

View File

@ -97,9 +97,9 @@ static ATTENUATOR(volumeFromDist) {
TilePoint tp(loc.x, loc.y, 0);
uint32 dist = tp.quickHDistance();
if (dist < fullVolumeDist) {
return abs(maxVol);
return ABS(maxVol);
} else if (dist < offVolumeDist) {
return abs((int)(maxVol * ((int)((offVolumeDist - fullVolumeDist) - (dist - fullVolumeDist))) / (offVolumeDist - fullVolumeDist)));
return ABS((int)(maxVol * ((int)((offVolumeDist - fullVolumeDist) - (dist - fullVolumeDist))) / (offVolumeDist - fullVolumeDist)));
}
return 0;
}

View File

@ -862,9 +862,9 @@ int16 gSlider::getSliderLenVal(void) {
if (slValMin < 0 && slValMax < 0) {
val = slValMax - slValMin;
} else if (slValMin < 0 && slValMax >= 0) {
val = abs(slValMin) + slValMax;
val = ABS(slValMin) + slValMax;
} else if (slValMin >= 0 && slValMax < 0) {
val = abs(slValMax) - slValMin;
val = ABS(slValMax) - slValMin;
} else if (slValMin >= 0 && slValMax >= 0) {
val = slValMax - slValMin;
}

View File

@ -109,13 +109,13 @@ int CalenderTime::lightLevel(int maxLevel) {
// grows to 'framesAtNoon' at noon, then shrinks
// back to 0 at midnight again.
solarAngle = framesAtNoon
- abs(frameInDay() - framesAtNoon);
- ABS(frameInDay() - framesAtNoon);
// Just for fun, we'll make the days longer in the summer,
// and shorter the winter. The calculation produces a number
// which equals daysPerYear/4 in summer, and -daysperYear/4
// in winter.
season = daysPerYear / 4 - abs(dayInYear - daysPerYear / 2);
season = daysPerYear / 4 - ABS(dayInYear - daysPerYear / 2);
// Convert season to an extra hour of daylight in summer,
// and an extra hour of night in winter. (That's an extra

View File

@ -30,13 +30,13 @@
namespace Saga2 {
inline int32 RANDOM(int32 minV, int32 maxV) {
return (maxV - minV + 1) ? g_vm->_rnd->getRandomNumber(abs(maxV - minV)) + minV : 0;
return (maxV - minV + 1) ? g_vm->_rnd->getRandomNumber(ABS(maxV - minV)) + minV : 0;
}
inline int32 diceRoll(int dice, int sides, int perDieMod, int base) {
int32 rv = base;
if (dice)
for (int i = 0; i < abs(dice); i++)
for (int i = 0; i < ABS(dice); i++)
rv += (RANDOM(1, sides) + perDieMod * (dice > 0 ? 1 : -1));
return rv;
}

View File

@ -206,8 +206,8 @@ void DisplayNodeList::buildObjects(bool fromScratch) {
int16 dist;
// Compute distance from object to screen center.
dist = abs(viewCenter.u - objLoc.u)
+ abs(viewCenter.v - objLoc.v);
dist = ABS(viewCenter.u - objLoc.u)
+ ABS(viewCenter.v - objLoc.v);
// Determine if the object is beyond the screen threshold
if ((dist >= loadDist

View File

@ -131,8 +131,8 @@ class frameSmoother: public frameCounter {
// get variance totals
for (uint i = 0; i < historySize; i++) {
dif1Sec[i / int(desiredFPS)] += abs(ksHistory(i) - avg1Sec[i / int(desiredFPS)]);
dif5Sec += abs(ksHistory(i) - avg5Sec);
dif1Sec[i / int(desiredFPS)] += ABS(ksHistory(i) - avg1Sec[i / int(desiredFPS)]);
dif5Sec += ABS(ksHistory(i) - avg5Sec);
}
// get average variances

View File

@ -265,7 +265,7 @@ gTextBox::~gTextBox() {
*/
bool gTextBox::insertText(char *newText, int length) {
int16 selStart = MIN(cursorPos, anchorPos),
selWidth = abs(cursorPos - anchorPos),
selWidth = ABS(cursorPos - anchorPos),
selEnd = selStart + selWidth;
if (length == -1) length = strlen(newText);
@ -429,7 +429,7 @@ void gTextBox::scroll(int8 req) {
indexReq = clamp(0, indexReq, numEditLines);
visIndex = (indexReq - (visBase - linesPerPage));
if (abs(oldIndex - indexReq) < 2) {
if (ABS(oldIndex - indexReq) < 2) {
if (visIndex < 0) {
visBase--;
visIndex++;
@ -640,7 +640,7 @@ void gTextBox::pointerRelease(gPanelMessage &msg) {
bool gTextBox::keyStroke(gPanelMessage &msg) {
gPort &port = window.windowPort;
int16 selStart = MIN(cursorPos, anchorPos),
selWidth = abs(cursorPos - anchorPos);
selWidth = ABS(cursorPos - anchorPos);
uint8 key = msg.key;
// Process the various keystrokes...
@ -839,7 +839,7 @@ char *gTextBox::getLine(int8 stringIndex) {
//-----------------------------------------------------------------------
char *gTextBox::selectedText(int &length) {
length = abs(cursorPos - anchorPos);
length = ABS(cursorPos - anchorPos);
return fieldStrings[index] + MIN(cursorPos, anchorPos);
}

View File

@ -274,7 +274,7 @@ bool unstickObject(GameObject *obj) {
// Set new radius to maximum of abs of the 3 coords, minus 1
// (Because we want solution to converge faster)
newRadius = MAX(MAX(abs(dx), abs(dy)), abs(dz)) - 1;
newRadius = MAX(MAX(ABS(dx), ABS(dy)), ABS(dz)) - 1;
if (newRadius < radius) {
radius = newRadius;
@ -2178,7 +2178,7 @@ void MotionTask::ballisticAction(void) {
// Make Up For Rounding Errors In ThrowTo
if (uFrac) {
uErrorTerm += abs(uFrac);
uErrorTerm += ABS(uFrac);
if (uErrorTerm >= steps) {
uErrorTerm -= steps;
@ -2190,7 +2190,7 @@ void MotionTask::ballisticAction(void) {
}
if (vFrac) {
vErrorTerm += abs(vFrac);
vErrorTerm += ABS(vFrac);
if (vErrorTerm >= steps) {
vErrorTerm -= steps;
@ -2434,7 +2434,7 @@ bool MotionTask::nextWayPoint(void) {
// use dumb pathfinding until the pathfinder finishes it's task.
if ((finalTarget - object->_data.location).quickHDistance() > 0
|| abs(finalTarget.z - object->_data.location.z) > kMaxStepHeight) {
|| ABS(finalTarget.z - object->_data.location.z) > kMaxStepHeight) {
// If no pathfind in progress
if ((flags & pathFind)
&& !(flags & finalPath)
@ -2585,7 +2585,7 @@ void MotionTask::walkAction(void) {
// If we're not already there, then proceed towards
// the target.
if (targetDist > 0 || abs(targetVector.z) > kMaxStepHeight)
if (targetDist > 0 || ABS(targetVector.z) > kMaxStepHeight)
break;
}
@ -2645,7 +2645,7 @@ void MotionTask::walkAction(void) {
if (moveTaskDone || moveTaskWaiting) {
movementDirection = a->currentFacing;
} else if (targetDist == 0 && abs(targetVector.z) > kMaxStepHeight) {
} else if (targetDist == 0 && ABS(targetVector.z) > kMaxStepHeight) {
if (pathFindTask) {
movementDirection = a->currentFacing;
moveTaskWaiting = true;

View File

@ -1710,7 +1710,7 @@ bool GameObject::inRange(const TilePoint &tp, uint16 range) {
TilePoint vector = tp - loc;
return vector.quickHDistance() <= range
&& abs(vector.z) <= range;
&& ABS(vector.z) <= range;
}
//-----------------------------------------------------------------------
@ -3527,8 +3527,8 @@ ObjectID RingObjectIterator::next(GameObject **obj) {
int16 DispRegionObjectIterator::computeDist(const TilePoint &tp) {
// Compute distance from object to screen center.
// REM: remember to add in Z there somewhere.
return abs(getCenter().u - tp.u)
+ abs(getCenter().v - tp.v);
return ABS(getCenter().u - tp.u)
+ ABS(getCenter().v - tp.v);
}
/* ======================================================================= *

View File

@ -619,7 +619,7 @@ bool ProtoObj::acceptHealing(
assert(dObj != Nothing);
damage = absDamage;
if (dice)
for (int d = 0; d < abs(dice); d++)
for (int d = 0; d < ABS(dice); d++)
damage += (g_vm->_rnd->getRandomNumber(sides - 1) + pdm + 1) * (dice > 0 ? 1 : -1);
return acceptHealingAction(dObj, enactor, damage);

View File

@ -930,7 +930,7 @@ void gToolBase::handleMouse(Common::Event &event, uint32 time) {
|| _curMouseState.right > 1) {
Point16 diff = lastClickPos - _curMouseState.pos;
if (abs(diff.x) + abs(diff.y) < 6)
if (ABS(diff.x) + ABS(diff.y) < 6)
msg.doubleClick = 1;
}

View File

@ -1571,14 +1571,14 @@ big_break:
// If the height difference is too great skip this tile
// position
if (abs(quantizedCoords.z - startingCoords.z) > kMaxStepHeight)
if (ABS(quantizedCoords.z - startingCoords.z) > kMaxStepHeight)
continue;
// Compute initial cost based upon the distance from the
// starting location
offsetVector = quantizedCoords - startingCoords;
dist = offsetVector.quickHDistance();
zDist = abs(offsetVector.z);
zDist = ABS(offsetVector.z);
cost = dist + zDist;
// Push this point
@ -1625,7 +1625,7 @@ void PathRequest::finish(void) {
if (cell->direction != dirInvalid) {
if (cell->direction != prevDir
|| abs(cell->height - prevHeight) > kMaxStepHeight) {
|| ABS(cell->height - prevHeight) > kMaxStepHeight) {
if (res <= tempResult) break;
coords.u =
@ -1854,7 +1854,7 @@ PathResult PathRequest::findPath(void) {
&testPlatform);
// Determine if elevation change is too great
if (abs(testPt.z - prevZ) <= kMaxStepHeight)
if (ABS(testPt.z - prevZ) <= kMaxStepHeight)
prevZ = testPt.z;
else
goto big_continue;
@ -2105,8 +2105,8 @@ bool DestinationPathRequest::setCenter(
// Determine the target vector in order to calculate distance.
targetDelta = (targetCoords - centerPt);
dist = targetDelta.quickHDistance();
zDist = abs(targetDelta.z);
platDiff = abs(centerPlatform - targetPlatform);
zDist = ABS(targetDelta.z);
platDiff = ABS(centerPlatform - targetPlatform);
centerCost = dist + zDist * (platDiff + 1);
// Determine if this location is closer than any location we have
@ -2179,8 +2179,8 @@ int16 DestinationPathRequest::evaluateMove(
// order to calculate the distance.
targetDelta = targetCoords - testPt;
dist = targetDelta.quickHDistance();
zDist = abs(targetDelta.z);
platDiff = abs(testPlatform - targetPlatform);
zDist = ABS(targetDelta.z);
platDiff = ABS(testPlatform - targetPlatform);
return (dist + zDist * (platDiff + 1) - centerCost) >> 2;
}
@ -2229,7 +2229,7 @@ bool WanderPathRequest::setCenter(
// Determine the movement vector in order to calculate distance.
movementDelta = (startingCoords - centerPt);
dist = movementDelta.quickHDistance();
zDist = abs(movementDelta.z);
zDist = ABS(movementDelta.z);
centerCost = dist + zDist;
// Determine if this location is farther than any location we have
@ -2276,7 +2276,7 @@ int16 WanderPathRequest::evaluateMove(const TilePoint &testPt, uint8) {
// order to calculate the distance.
movementDelta = startingCoords - testPt;
dist = movementDelta.quickHDistance();
zDist = abs(movementDelta.z) >> 1;
zDist = ABS(movementDelta.z) >> 1;
return (centerCost - (dist + zDist)) >> 1;
}
@ -2540,7 +2540,7 @@ TilePoint selectNearbySite(
distFromCenter =
quickDistance(
Point32(qi.u - searchCenter, qi.v - searchCenter));
// max( abs( qi.u - searchCenter ), abs( qi.v - searchCenter ) );
// max( ABS( qi.u - searchCenter ), ABS( qi.v - searchCenter ) );
// Calculate the "goodness" of this cell -- is it in the
// middle of the band between min and max?
@ -2781,14 +2781,14 @@ bool checkPath(
// If the height difference is too great skip this tile
// position
if (abs(quantizedCoords.z - startingCoords.z) > kMaxStepHeight)
if (ABS(quantizedCoords.z - startingCoords.z) > kMaxStepHeight)
continue;
// Compute initial cost based upon the distance from the
// starting location
offsetVector = quantizedCoords - startingCoords;
dist = offsetVector.quickHDistance();
zDist = abs(offsetVector.z);
zDist = ABS(offsetVector.z);
cost = dist + zDist;
// Push this point
@ -2908,7 +2908,7 @@ bool checkPath(
// If the resulting height is significantly different
// from the destination height, assume we're on a
// different level and return false.
return abs(testPt.z - destCoords.z) <= kMaxStepHeight;
return ABS(testPt.z - destCoords.z) <= kMaxStepHeight;
}

View File

@ -3619,15 +3619,15 @@ int16 scriptSwapRegions(int16 *args) {
region1.min.u = args[1];
region1.min.v = args[2];
region1.min.z = -128;
region1.max.u = args[1] + abs(args[6]);
region1.max.v = args[2] + abs(args[7]);
region1.max.u = args[1] + ABS(args[6]);
region1.max.v = args[2] + ABS(args[7]);
region1.max.z = 127;
region2.min.u = args[4];
region2.min.v = args[5];
region2.min.z = -128;
region2.max.u = args[4] + abs(args[6]);
region2.max.v = args[5] + abs(args[7]);
region2.max.u = args[4] + ABS(args[6]);
region2.max.v = args[5] + ABS(args[7]);
region2.max.z = 127;
// Count how many objects are in each region

View File

@ -897,8 +897,8 @@ bool isVisible(GameObject *obj) {
TileToScreenCoords(viewCenter, vp);
distanceX = abs(vp.x - p.x);
distanceY = abs(vp.y - p.y);
distanceX = ABS(vp.x - p.x);
distanceY = ABS(vp.y - p.y);
if ((distanceY >= loadDistY) ||
(distanceX >= loadDistX))

View File

@ -81,7 +81,7 @@ TilePoint computeRepulsionVector(
repulsorDist;
repulsorDist = repulsorVectorArray[i].quickHDistance()
+ abs(repulsorVectorArray[i].z);
+ ABS(repulsorVectorArray[i].z);
repulsorWeight =
repulsorDist != 0
? 64 * 64 / (repulsorDist * repulsorDist)
@ -1347,7 +1347,7 @@ TaskResult GotoTask::update(void) {
!= (immediateDest.u >> kTileUVShift)
|| (motionTarget.v >> kTileUVShift)
!= (immediateDest.v >> kTileUVShift)
|| abs(motionTarget.z - immediateDest.z) > 16
|| ABS(motionTarget.z - immediateDest.z) > 16
|| runState != prevRunState)
actorMotion->changeTarget(
immediateDest,
@ -1478,7 +1478,7 @@ bool GotoLocationTask::run(void) {
return runThreshold != maxuint8
? (targetLoc - actorLoc).quickHDistance() > runThreshold
|| abs(targetLoc.z - actorLoc.z) > runThreshold
|| ABS(targetLoc.z - actorLoc.z) > runThreshold
: false;
}
@ -1677,7 +1677,7 @@ bool GotoObjectTargetTask::lineOfSight(void) {
// sight if the target has moved beyond a certain range from
// the last location it was tested at.
if ((targetLoc - lastTestedLoc).quickHDistance() > 25
|| abs(targetLoc.z - lastTestedLoc.z) > 25) {
|| ABS(targetLoc.z - lastTestedLoc.z) > 25) {
if (a->canSenseSpecificObject(
info,
maxSenseRange,
@ -4014,11 +4014,11 @@ bool BandTask::targetHasChanged(GotoTask *gotoTarget) {
int16 slop;
slop = ((currentTarget - actorLoc).quickHDistance()
+ abs(currentTarget.z - actorLoc.z))
+ ABS(currentTarget.z - actorLoc.z))
/ 2;
if ((currentTarget - oldTarget).quickHDistance()
+ abs(currentTarget.z - oldTarget.z)
+ ABS(currentTarget.z - oldTarget.z)
> slop)
gotoLocation->changeTarget(currentTarget);
@ -4043,7 +4043,7 @@ bool BandTask::atTarget(void) {
TilePoint actorLoc = stack->getActor()->getLocation();
if ((actorLoc - currentTarget).quickHDistance() > 6
|| abs(actorLoc.z - currentTarget.z) > kMaxStepHeight) {
|| ABS(actorLoc.z - currentTarget.z) > kMaxStepHeight) {
if (attend != NULL) {
attend->abortTask();
delete attend;
@ -4380,7 +4380,7 @@ TaskResult FollowPatrolRouteTask::handleFollowPatrolRoute(void) {
== (currentWayPoint.u >> kTileUVShift)
&& (actorLoc.v >> kTileUVShift)
== (currentWayPoint.v >> kTileUVShift)
&& abs(actorLoc.z - currentWayPoint.z) <= kMaxStepHeight) {
&& ABS(actorLoc.z - currentWayPoint.z) <= kMaxStepHeight) {
// Delete the gotoWayPoint task
if (gotoWayPoint != NULL) {
gotoWayPoint->abortTask();

View File

@ -174,8 +174,8 @@ struct TilePoint {
void operator-= (TilePoint a) { u -= a.u; v -= a.v; z -= a.z; }
int16 quickHDistance(void) {
int16 au = (int16)abs(u),
av = (int16)abs(v);
int16 au = (int16)ABS(u),
av = (int16)ABS(v);
if (au > av)
return (int16)(au + (av >> 1));
@ -264,8 +264,8 @@ public:
void operator-= (TilePoint32 a) { u -= a.u; v -= a.v; z -= a.z; }
int32 quickHDistance( void ) {
int32 au = abs( u ),
av = abs( v );
int32 au = ABS( u ),
av = ABS( v );
if (au > av) return au + (av >> 1);
else return av + (au >> 1);

View File

@ -3667,7 +3667,7 @@ SurfaceType pointOnTile(TileInfo *ti,
// Compute the mask which represents the subtile
sMask = calcSubTileMask(subTile.u, subTile.v);
yBound = abs(subTileRel.x >> 1);
yBound = ABS(subTileRel.x >> 1);
while (subTileRel.y >= 0
&& subTile.u < 4
@ -3812,7 +3812,7 @@ SurfaceType pointOnTile(TileInfo *ti,
sMask <<= kSubTileMaskUShift + kSubTileMaskVShift;
subTileRel.y -= kSubTileDY * 2;
}
yBound = abs(subTileRel.x >> 1);
yBound = ABS(subTileRel.x >> 1);
if (subTile.u >= 4 || subTile.v >= 4) {
// No subtile was found, so lets move the pointer.
@ -3826,10 +3826,10 @@ SurfaceType pointOnTile(TileInfo *ti,
subTileRel.x = relPos.x -
((subTile.u - subTile.v) << kSubTileDXShift);
subTileRel.y = ti->attrs.terrainHeight + kSubTileDY * 2 -
abs(subTileRel.x >> 1) - 1;
ABS(subTileRel.x >> 1) - 1;
sMask = calcSubTileMask(subTile.u, subTile.v);
yBound = abs(subTileRel.x >> 1);
yBound = ABS(subTileRel.x >> 1);
} else {
// If there were no raised subtiles checked, move the
// pointer laterally to the nearest raised subtile.
@ -3899,7 +3899,7 @@ testLeft:
if (raisedCol == -4) break;
// compute the number of subtiles in column
int8 subsInCol = 4 - abs(raisedCol);
int8 subsInCol = 4 - ABS(raisedCol);
relPos.x = (raisedCol << kSubTileDXShift) + subTileRel.x;
if (raisedCol > 0) {
@ -3925,7 +3925,7 @@ testLeft:
// column
subTileRel.y = relPos.y - ((subTile.u + subTile.v) * kSubTileDY) - h;
sMask = calcSubTileMask(subTile.u, subTile.v);
yBound = abs(subTileRel.x >> 1);
yBound = ABS(subTileRel.x >> 1);
}
}
}
@ -4122,7 +4122,7 @@ StaticTilePoint pickTile(Point32 pos,
mt = curMap->lookupMeta(mCoords);
// While we are less than the pick altitude
while (relPos.y < zMax + kTileDX + kMaxStepHeight - abs(relPos.x >> 1)) {
while (relPos.y < zMax + kTileDX + kMaxStepHeight - ABS(relPos.x >> 1)) {
// If there is a metatile on this spot
if (mt != nullptr) {
// Iterate through all platforms
@ -4155,7 +4155,7 @@ StaticTilePoint pickTile(Point32 pos,
// Reject the tile if mouse position is below lower tile
// boundary
if ((relPos.y - sti.surfaceHeight) < abs(relPos.x >> 1))
if ((relPos.y - sti.surfaceHeight) < ABS(relPos.x >> 1))
continue;
if (ti->attrs.height > 0) {
@ -4525,8 +4525,8 @@ void updateMainDisplay(void) {
viewDiff = trackPos - lastViewLoc;
lastViewLoc = trackPos;
if (abs(viewDiff.u) > 8 * kPlatformWidth * kTileUVSize
|| abs(viewDiff.v) > 8 * kPlatformWidth * kTileUVSize)
if (ABS(viewDiff.u) > 8 * kPlatformWidth * kTileUVSize
|| ABS(viewDiff.v) > 8 * kPlatformWidth * kTileUVSize)
freeAllTileBanks();
// Add current coordinates to map if they have mapping
@ -4693,25 +4693,25 @@ void markMetaAsVisited(const TilePoint &pt) {
* ===================================================================== */
int16 quickDistance(const Point16 &p) {
int16 ax = abs(p.x),
ay = abs(p.y);
int16 ax = ABS(p.x),
ay = ABS(p.y);
if (ax > ay) return ax + (ay >> 1);
else return ay + (ax >> 1);
}
int32 quickDistance(const Point32 &p) {
int32 ax = abs(p.x),
ay = abs(p.y);
int32 ax = ABS(p.x),
ay = ABS(p.y);
if (ax > ay) return ax + (ay >> 1);
else return ay + (ax >> 1);
}
int16 TilePoint::magnitude(void) {
int16 au = abs(u),
av = abs(v),
az = abs(z);
int16 au = ABS(u),
av = ABS(v),
az = ABS(z);
if (az > au && az > av) return az + ((au + av) >> 1);
if (au > av) return au + ((az + av) >> 1);
@ -4763,7 +4763,7 @@ uint16 lineDist(
else
dist = lineFar;
return abs(dist);
return ABS(dist);
}
} // end of namespace Saga2