aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStrangerke2016-09-11 11:10:22 +0200
committerStrangerke2016-09-11 11:10:22 +0200
commit2f311a800fe66ad183c49e917acd212cc9316e3b (patch)
treec5d1ca059c8b2c70aa4b7f5a22bbd8348a6b4423
parentb0bfa2e4f535cdaafb389950381fc3fff340e634 (diff)
downloadscummvm-rg350-2f311a800fe66ad183c49e917acd212cc9316e3b.tar.gz
scummvm-rg350-2f311a800fe66ad183c49e917acd212cc9316e3b.tar.bz2
scummvm-rg350-2f311a800fe66ad183c49e917acd212cc9316e3b.zip
DM: Get rid of getBoundedValue, replace it by CLIP
-rw-r--r--engines/dm/champion.cpp16
-rw-r--r--engines/dm/dm.h8
-rw-r--r--engines/dm/gfx.cpp38
-rw-r--r--engines/dm/group.cpp2
-rw-r--r--engines/dm/menus.cpp2
5 files changed, 31 insertions, 35 deletions
diff --git a/engines/dm/champion.cpp b/engines/dm/champion.cpp
index 2d5ea5e15f..d138b4c719 100644
--- a/engines/dm/champion.cpp
+++ b/engines/dm/champion.cpp
@@ -234,7 +234,7 @@ bool ChampionMan::isObjectThrown(uint16 champIndex, int16 slotIndex, int16 side)
kineticEnergy += weaponKineticEnergy;
int16 skillLevel = getSkillLevel((ChampionIndex)champIndex, kDMSkillThrow);
kineticEnergy += _vm->getRandomNumber(16) + (kineticEnergy >> 1) + skillLevel;
- int16 attack = getBoundedValue((uint16)40, (uint16)((skillLevel << 3) + _vm->getRandomNumber(32)), (uint16)200);
+ int16 attack = CLIP<int16>(40, ((skillLevel << 3) + _vm->getRandomNumber(32)), 200);
int16 stepEnergy = MAX(5, 11 - skillLevel);
_vm->_projexpl->createProjectile(curThing, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY,
_vm->normalizeModulo4(_vm->_dungeonMan->_partyDir + side),
@@ -657,7 +657,7 @@ uint16 ChampionMan::getStrength(int16 champIndex, int16 slotIndex) {
if (getFlag(curChampion->_wounds, (slotIndex == kDMSlotReadyHand) ? kDMWoundReadHand : kDMWoundActionHand)) {
strength >>= 1;
}
- return getBoundedValue(0, strength >> 1, 100);
+ return CLIP(0, strength >> 1, 100);
}
Thing ChampionMan::getObjectRemovedFromSlot(uint16 champIndex, uint16 slotIndex) {
@@ -877,7 +877,7 @@ int16 ChampionMan::getWoundDefense(int16 champIndex, uint16 woundIndex) {
if (_partyIsSleeping)
woundDefense >>= 1;
- return getBoundedValue(0, woundDefense >> 1, 100);
+ return CLIP(0, woundDefense >> 1, 100);
}
uint16 ChampionMan::getStatisticAdjustedAttack(Champion *champ, uint16 statIndex, uint16 attack) {
@@ -912,7 +912,7 @@ void ChampionMan::wakeUp() {
int16 ChampionMan::getThrowingStaminaCost(Thing thing) {
int16 weight = _vm->_dungeonMan->getObjectWeight(thing) >> 1;
- int16 staminaCost = getBoundedValue<int16>(1, weight, 10);
+ int16 staminaCost = CLIP<int16>(1, weight, 10);
while ((weight -= 10) > 0)
staminaCost += weight >> 1;
@@ -969,7 +969,7 @@ void ChampionMan::addSkillExperience(uint16 champIndex, uint16 skillIndex, uint1
Skill *curSkill = &curChampion->_skills[skillIndex];
curSkill->_experience += exp;
if (curSkill->_temporaryExperience < 32000)
- curSkill->_temporaryExperience += getBoundedValue(1, exp >> 3, 100);
+ curSkill->_temporaryExperience += CLIP(1, exp >> 3, 100);
curSkill = &curChampion->_skills[baseSkillIndex];
if (skillIndex >= kDMSkillSwing)
@@ -1088,7 +1088,7 @@ int16 ChampionMan::getDexterity(Champion *champ) {
if (_partyIsSleeping)
dexterity >>= 1;
- return getBoundedValue(1 + _vm->getRandomNumber(8), dexterity >> 1, 100 - _vm->getRandomNumber(8));
+ return CLIP(1 + _vm->getRandomNumber(8), dexterity >> 1, 100 - _vm->getRandomNumber(8));
}
bool ChampionMan::isLucky(Champion *champ, uint16 percentage) {
@@ -1097,7 +1097,7 @@ bool ChampionMan::isLucky(Champion *champ, uint16 percentage) {
unsigned char *curStat = champ->_statistics[kDMStatLuck];
bool isLucky = (_vm->getRandomNumber(curStat[kDMStatCurrent]) > percentage);
- curStat[kDMStatCurrent] = getBoundedValue<char>(curStat[kDMStatMinimum], curStat[kDMStatCurrent] + (isLucky ? -2 : 2), curStat[kDMStatMaximum]);
+ curStat[kDMStatCurrent] = CLIP<unsigned char>(curStat[kDMStatMinimum], curStat[kDMStatCurrent] + (isLucky ? -2 : 2), curStat[kDMStatMaximum]);
return isLucky;
}
@@ -1616,7 +1616,7 @@ void ChampionMan::applyTimeEffects() {
staminaGainCycleCount += 2;
int16 staminaLoss = 0;
- int16 staminaAmount = getBoundedValue(1, (championPtr->_maxStamina >> 8) - 1, 6);
+ int16 staminaAmount = CLIP(1, (championPtr->_maxStamina >> 8) - 1, 6);
if (_partyIsSleeping)
staminaAmount <<= 1;
diff --git a/engines/dm/dm.h b/engines/dm/dm.h
index 3f4b6f0f5c..6dfc2d4f97 100644
--- a/engines/dm/dm.h
+++ b/engines/dm/dm.h
@@ -202,11 +202,7 @@ public:
#define getFlag(val, mask) ((val) & (mask))
#define clearFlag(val, mask) ((val) &= (~(mask))) // @ M09_CLEAR
-//TODO: Directly use CLIP
-template<typename T>
-inline T getBoundedValue(T min, T val, T max) {
- return CLIP<T>(min, val, max);
-} // @ F0026_MAIN_GetBoundedValue
+// Note: F0026_MAIN_GetBoundedValue<T> has been replaced by CLIP<T>
#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
@@ -260,7 +256,7 @@ public:
Direction turnDirLeft(int16 dir); // @ M19_PREVIOUS
Direction returnOppositeDir(int16 dir); // @ M18_OPPOSITE
bool isOrientedWestEast(int16 dir); // @ M16_IS_ORIENTED_WEST_EAST
- uint16 normalizeModulo4(int16 val); // @ M21_NORMALIZE
+ uint16 normalizeModulo4(int16 dir); // @ M21_NORMALIZE
int32 filterTime(int32 map_time); // @ M30_TIME
int32 setMapAndTime(int32 &map_time, uint32 map, uint32 time); // @ M33_SET_MAP_AND_TIME
diff --git a/engines/dm/gfx.cpp b/engines/dm/gfx.cpp
index 8d68cbd6f3..13dd79d7a0 100644
--- a/engines/dm/gfx.cpp
+++ b/engines/dm/gfx.cpp
@@ -2809,7 +2809,6 @@ int16 DisplayMan::getScaledDimension(int16 dimension, int16 scale) {
void DisplayMan::drawObjectsCreaturesProjectilesExplosions(Thing thingParam, Direction directionParam, int16 mapXpos,
int16 mapYpos, int16 viewSquareIndex, uint16 orderedViewCellOrdinals) {
- int16 AL_0_creatureGraphicInfoRed;
int16 AL_0_creatureIndexRed;
#define AL_1_viewSquareExplosionIndex viewSquareIndex
int16 L0126_i_Multiple;
@@ -2854,6 +2853,7 @@ void DisplayMan::drawObjectsCreaturesProjectilesExplosions(Thing thingParam, Dir
int16 creatureSize;
int16 creatureDirectionDelta;
int16 creatureGraphicInfoGreen;
+ int16 creatureGraphicInfoRed;
int16 creatureAspectInt;
int16 creatureIndexGreen;
int16 transparentColor;
@@ -3299,12 +3299,12 @@ T0115077_DrawSecondHalfSquareCreature:
coordinateSet = creatureCoordinateSets[((CreatureAspect *)objectAspect)->getCoordSet()][viewSquareIndex][AL_2_viewCell];
if (!coordinateSet[1])
goto T0115126_CreatureNotVisible;
- AL_0_creatureGraphicInfoRed = creatureGraphicInfoGreen;
+ creatureGraphicInfoRed = creatureGraphicInfoGreen;
AL_4_nativeBitmapIndex = k446_FirstCreatureGraphicIndice + ((CreatureAspect *)objectAspect)->_firstNativeBitmapRelativeIndex; /* By default, assume using the front image */
derivedBitmapIndex = ((CreatureAspect *)objectAspect)->_firstDerivedBitmapIndex;
int16 sourceByteWidth;
int16 sourceHeight;
- useCreatureSideBitmap = getFlag(AL_0_creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide) && (creatureDirectionDelta & 0x0001);
+ useCreatureSideBitmap = getFlag(creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide) && (creatureDirectionDelta & 0x0001);
if (useCreatureSideBitmap) {
useCreatureAttackBitmap = useFlippedHorizontallyCreatureFrontImage = useCreatureBackBitmap = false;
AL_4_nativeBitmapIndex++; /* Skip the front image. Side image is right after the front image */
@@ -3312,20 +3312,20 @@ T0115077_DrawSecondHalfSquareCreature:
sourceByteWidth = byteWidth = ((CreatureAspect *)objectAspect)->_byteWidthSide;
sourceHeight = heightRedEagle = ((CreatureAspect *)objectAspect)->_heightSide;
} else {
- useCreatureBackBitmap = getFlag(AL_0_creatureGraphicInfoRed, k0x0010_CreatureInfoGraphicMaskBack) && (creatureDirectionDelta == 0);
+ useCreatureBackBitmap = getFlag(creatureGraphicInfoRed, k0x0010_CreatureInfoGraphicMaskBack) && (creatureDirectionDelta == 0);
useCreatureAttackBitmap = !useCreatureBackBitmap;
- if (useCreatureAttackBitmap && getFlag(creatureAspectInt, k0x0080_MaskActiveGroupIsAttacking) && getFlag(AL_0_creatureGraphicInfoRed, k0x0020_CreatureInfoGraphicMaskAttack)) {
+ if (useCreatureAttackBitmap && getFlag(creatureAspectInt, k0x0080_MaskActiveGroupIsAttacking) && getFlag(creatureGraphicInfoRed, k0x0020_CreatureInfoGraphicMaskAttack)) {
useFlippedHorizontallyCreatureFrontImage = false;
sourceByteWidth = byteWidth = ((CreatureAspect *)objectAspect)->_byteWidthAttack;
sourceHeight = heightRedEagle = ((CreatureAspect *)objectAspect)->_heightAttack;
AL_4_nativeBitmapIndex++; /* Skip the front image */
derivedBitmapIndex += 2;
- if (getFlag(AL_0_creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide)) {
+ if (getFlag(creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide)) {
AL_4_nativeBitmapIndex++; /* If the creature has a side image, it preceeds the attack image */
derivedBitmapIndex += 2;
}
- if (getFlag(AL_0_creatureGraphicInfoRed, k0x0010_CreatureInfoGraphicMaskBack)) {
+ if (getFlag(creatureGraphicInfoRed, k0x0010_CreatureInfoGraphicMaskBack)) {
AL_4_nativeBitmapIndex++; /* If the creature has a back image, it preceeds the attack image */
derivedBitmapIndex += 2;
}
@@ -3334,7 +3334,7 @@ T0115077_DrawSecondHalfSquareCreature:
sourceHeight = heightRedEagle = ((CreatureAspect *)objectAspect)->_heightFront;
if (useCreatureBackBitmap) {
useFlippedHorizontallyCreatureFrontImage = false;
- if (getFlag(AL_0_creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide)) {
+ if (getFlag(creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide)) {
AL_4_nativeBitmapIndex += 2; /* If the creature has a side image, it preceeds the back image */
derivedBitmapIndex += 4;
} else {
@@ -3342,16 +3342,16 @@ T0115077_DrawSecondHalfSquareCreature:
derivedBitmapIndex += 2;
}
} else {
- useFlippedHorizontallyCreatureFrontImage = getFlag(AL_0_creatureGraphicInfoRed, k0x0004_CreatureInfoGraphicMaskFlipNonAttack) && getFlag(creatureAspectInt, k0x0040_MaskActiveGroupFlipBitmap);
+ useFlippedHorizontallyCreatureFrontImage = getFlag(creatureGraphicInfoRed, k0x0004_CreatureInfoGraphicMaskFlipNonAttack) && getFlag(creatureAspectInt, k0x0040_MaskActiveGroupFlipBitmap);
if (useFlippedHorizontallyCreatureFrontImage) {
derivedBitmapIndex += 2;
- if (getFlag(AL_0_creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide))
+ if (getFlag(creatureGraphicInfoRed, k0x0008_CreatureInfoGraphicMaskSide))
derivedBitmapIndex += 2;
- if (getFlag(AL_0_creatureGraphicInfoRed, k0x0010_CreatureInfoGraphicMaskBack))
+ if (getFlag(creatureGraphicInfoRed, k0x0010_CreatureInfoGraphicMaskBack))
derivedBitmapIndex += 2;
- if (getFlag(AL_0_creatureGraphicInfoRed, k0x0020_CreatureInfoGraphicMaskAttack))
+ if (getFlag(creatureGraphicInfoRed, k0x0020_CreatureInfoGraphicMaskAttack))
derivedBitmapIndex += 2;
}
}
@@ -3379,7 +3379,7 @@ T0115077_DrawSecondHalfSquareCreature:
bitmapRedBanana = getDerivedBitmap(derivedBitmapIndex);
else {
bitmapGreenAnt = getNativeBitmapOrGraphic(AL_4_nativeBitmapIndex);
- if (getFlag(AL_0_creatureGraphicInfoRed, k0x0004_CreatureInfoGraphicMaskFlipNonAttack))
+ if (getFlag(creatureGraphicInfoRed, k0x0004_CreatureInfoGraphicMaskFlipNonAttack))
copyBitmapAndFlipHorizontal(bitmapGreenAnt, bitmapRedBanana = getDerivedBitmap(derivedBitmapIndex), byteWidth, heightRedEagle);
addDerivedBitmap(derivedBitmapIndex);
@@ -3392,7 +3392,7 @@ T0115077_DrawSecondHalfSquareCreature:
if (viewSquareIndex >= k3_ViewSquare_D2C) { /* Creature is on D2 */
derivedBitmapIndex++; /* Skip front D3 image in additional graphics */
AL_8_shiftSetIndex = k1_ShiftSet_D1BackD2Front;
- useCreatureSpecialD2FrontBitmap = getFlag(AL_0_creatureGraphicInfoRed, k0x0080_CreatureInfoGraphicMaskSpecialD2Front) && !useCreatureSideBitmap && !useCreatureBackBitmap && !useCreatureAttackBitmap;
+ useCreatureSpecialD2FrontBitmap = getFlag(creatureGraphicInfoRed, k0x0080_CreatureInfoGraphicMaskSpecialD2Front) && !useCreatureSideBitmap && !useCreatureBackBitmap && !useCreatureAttackBitmap;
paletteChanges = _palChangesCreatureD2;
scale = k20_Scale_D2;
} else { /* Creature is on D3 */
@@ -3416,8 +3416,8 @@ T0115077_DrawSecondHalfSquareCreature:
}
if ((useCreatureSideBitmap && (creatureDirectionDelta == 1)) || /* If creature is viewed from the right, the side view must be flipped */
(useCreatureAttackBitmap && getFlag(creatureAspectInt, k0x0040_MaskActiveGroupFlipBitmap)) ||
- (useCreatureSpecialD2FrontBitmap && getFlag(AL_0_creatureGraphicInfoRed, k0x0100_CreatureInfoGraphicMaskSpecialD2FrontIsFlipped)) ||
- (useFlippedHorizontallyCreatureFrontImage && getFlag(AL_0_creatureGraphicInfoRed, k0x0004_CreatureInfoGraphicMaskFlipNonAttack))) { /* If the graphic should be flipped */
+ (useCreatureSpecialD2FrontBitmap && getFlag(creatureGraphicInfoRed, k0x0100_CreatureInfoGraphicMaskSpecialD2FrontIsFlipped)) ||
+ (useFlippedHorizontallyCreatureFrontImage && getFlag(creatureGraphicInfoRed, k0x0004_CreatureInfoGraphicMaskFlipNonAttack))) { /* If the graphic should be flipped */
if (!useFlippedHorizontallyCreatureFrontImage || !derivedBitmapInCache) {
AL_4_normalizdByteWidth = getNormalizedByteWidth(byteWidth);
if (!useFlippedHorizontallyCreatureFrontImage) {
@@ -3442,12 +3442,12 @@ T0115077_DrawSecondHalfSquareCreature:
else if (viewLane) /* Lane right */
AL_4_xPos += 100;
- boxByteGreen._x2 = getBoundedValue(0, AL_4_xPos + byteWidth, 223);
+ boxByteGreen._x2 = CLIP(0, AL_4_xPos + byteWidth, 223);
if (!boxByteGreen._x2)
goto T0115126_CreatureNotVisible;
int16 AL_0_creaturePosX;
- boxByteGreen._x1 = getBoundedValue(0, AL_4_xPos - byteWidth + 1, 223);
+ boxByteGreen._x1 = CLIP(0, AL_4_xPos - byteWidth + 1, 223);
if (boxByteGreen._x1) {
if (boxByteGreen._x1 == 223)
goto T0115126_CreatureNotVisible;
@@ -3706,7 +3706,7 @@ T0115200_DrawExplosion:
continue;
boxByteGreen._x2 = AL_4_xPos;
AL_4_xPos = explosionCoordinates[0];
- boxByteGreen._x1 = getBoundedValue(0, AL_4_xPos - byteWidth + 1, 223);
+ boxByteGreen._x1 = CLIP(0, AL_4_xPos - byteWidth + 1, 223);
if (boxByteGreen._x1)
AL_4_xPos = paddingPixelCount;
diff --git a/engines/dm/group.cpp b/engines/dm/group.cpp
index f0a3cd211a..6679599e8e 100644
--- a/engines/dm/group.cpp
+++ b/engines/dm/group.cpp
@@ -1473,7 +1473,7 @@ bool GroupMan::isCreatureAttacking(Group *group, int16 mapX, int16 mapY, uint16
kineticEnergy += _vm->getRandomNumber(kineticEnergy);
kineticEnergy += _vm->getRandomNumber(kineticEnergy);
_vm->_sound->requestPlay(k13_soundSPELL, mapX, mapY, k0_soundModePlayImmediately);
- _vm->_projexpl->createProjectile(projectileThing, mapX, mapY, targetCell, (Direction)_currGroupPrimaryDirToParty, getBoundedValue((int16)20, kineticEnergy, (int16)255), creatureInfo->_dexterity, 8);
+ _vm->_projexpl->createProjectile(projectileThing, mapX, mapY, targetCell, (Direction)_currGroupPrimaryDirToParty, CLIP<byte>(20, kineticEnergy, 255), creatureInfo->_dexterity, 8);
} else {
int16 championIndex;
if (getFlag(creatureInfo->_attributes, k0x0010_MaskCreatureInfo_attackAnyChamp)) {
diff --git a/engines/dm/menus.cpp b/engines/dm/menus.cpp
index 34cbd7e14b..5edbeb3db7 100644
--- a/engines/dm/menus.cpp
+++ b/engines/dm/menus.cpp
@@ -575,7 +575,7 @@ int16 MenuMan::getChampionSpellCastResult(uint16 champIndex) {
if (curSpell->getType() == kDMSpellTypeProjectileOpenDoor)
skillLevel <<= 1;
- _vm->_championMan->isProjectileSpellCast(champIndex, Thing(curSpell->getType() + Thing::_firstExplosion.toUint16()), getBoundedValue(21, (powerSymbolOrdinal + 2) * (4 + (skillLevel << 1)), 255), 0);
+ _vm->_championMan->isProjectileSpellCast(champIndex, Thing(curSpell->getType() + Thing::_firstExplosion.toUint16()), CLIP(21, (powerSymbolOrdinal + 2) * (4 + (skillLevel << 1)), 255), 0);
break;
case kDMSpellKindOther: {
TimelineEvent newEvent;