aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEugene Sandulenko2016-05-29 14:28:56 +0200
committerEugene Sandulenko2016-05-29 14:31:40 +0200
commitf80d676f3b8d137581e7ec8f250a1c402e77a422 (patch)
tree9a62f1caa48e2494c79f8254071835b6fb6d7732 /engines
parent05ba3fdb3bfc5808c34ae19d67d66431f7dc11fd (diff)
downloadscummvm-rg350-f80d676f3b8d137581e7ec8f250a1c402e77a422.tar.gz
scummvm-rg350-f80d676f3b8d137581e7ec8f250a1c402e77a422.tar.bz2
scummvm-rg350-f80d676f3b8d137581e7ec8f250a1c402e77a422.zip
SCUMM HE: Explicit type conversion
Diffstat (limited to 'engines')
-rw-r--r--engines/scumm/he/moonbase/ai_defenseunit.cpp32
-rw-r--r--engines/scumm/he/moonbase/ai_main.cpp3
-rw-r--r--engines/scumm/he/moonbase/ai_targetacquisition.cpp13
-rw-r--r--engines/scumm/he/moonbase/ai_traveller.cpp12
-rw-r--r--engines/scumm/he/moonbase/ai_tree.cpp7
5 files changed, 36 insertions, 31 deletions
diff --git a/engines/scumm/he/moonbase/ai_defenseunit.cpp b/engines/scumm/he/moonbase/ai_defenseunit.cpp
index 37ce303bc5..ab61297603 100644
--- a/engines/scumm/he/moonbase/ai_defenseunit.cpp
+++ b/engines/scumm/he/moonbase/ai_defenseunit.cpp
@@ -80,14 +80,14 @@ Common::Point *AntiAirUnit::createTargetPos(int index, int distance, int weaponT
targetPos->y = getPosY();
} else {
ratio = MAX(0, (getRadius() / distance));
- targetPos->x = getPosX() - ratio * (getPosX() - sourceX);
- targetPos->y = getPosY() - ratio * (getPosY() - sourceY);
+ targetPos->x = (int16)(getPosX() - ratio * (getPosX() - sourceX));
+ targetPos->y = (int16)(getPosY() - ratio * (getPosY() - sourceY));
}
break;
case ITEM_EMP:
- if (getRadius() + 215 > distance) { //emp radius
+ if (getRadius() + 215 > distance) { // Emp radius
double x1 = static_cast<double>(sourceX);
double y1 = static_cast<double>(sourceY);
double x2 = static_cast<double>(getPosX());
@@ -96,17 +96,17 @@ Common::Point *AntiAirUnit::createTargetPos(int index, int distance, int weaponT
double r2 = static_cast<double>(getRadius() + 3);
double d = static_cast<double>(distance);
- //formulae for calculating one point of intersection of two circles
+ // Formulae for calculating one point of intersection of two circles
float root = sqrt((((r1 + r2) * (r1 + r2)) - (d * d)) * ((d * d) - ((r2 - r1) * (r2 - r1))));
- int x = ((x1 + x2) / 2) + ((x2 - x1) * (r1 * r1 - r2 * r2)) / (2 * d * d) + ((y2 - y1) / (2 * d * d)) * root;
- int y = ((y1 + y2) / 2) + ((y2 - y1) * (r1 * r1 - r2 * r2)) / (2 * d * d) - ((x2 - x1) / (2 * d * d)) * root;
+ int x = (int)(((x1 + x2) / 2) + ((x2 - x1) * (r1 * r1 - r2 * r2)) / (2 * d * d) + ((y2 - y1) / (2 * d * d)) * root);
+ int y = (int)(((y1 + y2) / 2) + ((y2 - y1) * (r1 * r1 - r2 * r2)) / (2 * d * d) - ((x2 - x1) / (2 * d * d)) * root);
targetPos->x = x;
targetPos->y = y;
} else {
ratio = 1 - (getRadius() / static_cast<float>(distance - 20));
- targetPos->x = sourceX + ratio * (getPosX() - sourceX);
- targetPos->y = sourceY + ratio * (getPosY() - sourceY);
+ targetPos->x = (int16)(sourceX + ratio * (getPosX() - sourceX));
+ targetPos->y = (int16)(sourceY + ratio * (getPosY() - sourceY));
}
break;
@@ -188,7 +188,7 @@ Common::Point *ShieldUnit::createTargetPos(int index, int distance, int weaponTy
break;
case ITEM_EMP:
- if (getRadius() + 215 > distance) { //emp radius
+ if (getRadius() + 215 > distance) { // Emp radius
double x1 = static_cast<double>(sourceX);
double y1 = static_cast<double>(sourceY);
double x2 = static_cast<double>(getPosX());
@@ -197,17 +197,17 @@ Common::Point *ShieldUnit::createTargetPos(int index, int distance, int weaponTy
double r2 = static_cast<double>(getRadius() + 10);
double d = static_cast<double>(distance);
- //formulae for calculating one point of intersection of two circles
+ // Formulae for calculating one point of intersection of two circles
float root = sqrt((((r1 + r2) * (r1 + r2)) - (d * d)) * ((d * d) - ((r2 - r1) * (r2 - r1))));
- int x = ((x1 + x2) / 2) + ((x2 - x1) * (r1 * r1 - r2 * r2)) / (2 * d * d) + ((y2 - y1) / (2 * d * d)) * root;
- int y = ((y1 + y2) / 2) + ((y2 - y1) * (r1 * r1 - r2 * r2)) / (2 * d * d) - ((x2 - x1) / (2 * d * d)) * root;
+ int x = (int)(((x1 + x2) / 2) + ((x2 - x1) * (r1 * r1 - r2 * r2)) / (2 * d * d) + ((y2 - y1) / (2 * d * d)) * root);
+ int y = (int)(((y1 + y2) / 2) + ((y2 - y1) * (r1 * r1 - r2 * r2)) / (2 * d * d) - ((x2 - x1) / (2 * d * d)) * root);
targetPos->x = x;
targetPos->y = y;
} else {
ratio = 1 - (getRadius() / static_cast<float>(distance - 20));
- targetPos->x = sourceX + ratio * (getPosX() - sourceX);
- targetPos->y = sourceY + ratio * (getPosY() - sourceY);
+ targetPos->x = (int16)(sourceX + ratio * (getPosX() - sourceX));
+ targetPos->y = (int16)(sourceY + ratio * (getPosY() - sourceY));
}
if (distance < getRadius()) {
@@ -282,8 +282,8 @@ Common::Point *MineUnit::createTargetPos(int index, int distance, int weaponType
case ITEM_EMP:
ratio = 1 - (getRadius() / static_cast<float>(distance - 20));
- targetPos->x = sourceX + ratio * (getPosX() - sourceX);
- targetPos->y = sourceY + ratio * (getPosY() - sourceY);
+ targetPos->x = (int16)(sourceX + ratio * (getPosX() - sourceX));
+ targetPos->y = (int16)(sourceY + ratio * (getPosY() - sourceY));
break;
default:
diff --git a/engines/scumm/he/moonbase/ai_main.cpp b/engines/scumm/he/moonbase/ai_main.cpp
index 7ca4fbd933..9c9ff8bb01 100644
--- a/engines/scumm/he/moonbase/ai_main.cpp
+++ b/engines/scumm/he/moonbase/ai_main.cpp
@@ -817,8 +817,7 @@ int AI::masterControlProgram(const int paramCount, const int32 *params) {
{
// ANGLE setting
- int angleAdjustment = 0;
- angleAdjustment = _vm->_rnd.getRandomNumber(_aiType[getCurrentPlayer()]->getAngleVariation() * AI_VAR_BASE_ANGLE) * 3.6;
+ int angleAdjustment = (int)(_vm->_rnd.getRandomNumber(_aiType[getCurrentPlayer()]->getAngleVariation() * AI_VAR_BASE_ANGLE) * 3.6);
//pos or neg choice
angleAdjustment *= ((_vm->_rnd.getRandomNumber(1) * 2) - 1);
angleAdjustment *= randomAttenuation;
diff --git a/engines/scumm/he/moonbase/ai_targetacquisition.cpp b/engines/scumm/he/moonbase/ai_targetacquisition.cpp
index 938a02dba3..02c49dc1a7 100644
--- a/engines/scumm/he/moonbase/ai_targetacquisition.cpp
+++ b/engines/scumm/he/moonbase/ai_targetacquisition.cpp
@@ -226,7 +226,7 @@ IContainedObject *Sortie::createChildObj(int index, int &completionFlag) {
if (!_ai->_vm->_rnd.getRandomNumber(4))
currentWeapon->setTypeID(ITEM_MINE);
- (*i)->setDamage(thisDamage);
+ (*i)->setDamage((int)thisDamage);
// Apply emp effect
if (currentWeapon->getTypeID() == ITEM_EMP) {
@@ -278,7 +278,8 @@ float Sortie::calcH() {
}
int Sortie::checkSuccess() {
- if (!_enemyDefenses.size()) return SUCCESS;
+ if (!_enemyDefenses.size())
+ return SUCCESS;
int targetX = getTargetPosX();
int targetY = getTargetPosY();
@@ -431,8 +432,8 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
int randAngle = directAngleToHub + _ai->_vm->_rnd.getRandomNumber(179) - 90;
int randDist = _ai->_vm->_rnd.getRandomNumber(109) + 40;
- int x = targetX + randDist * cos(_ai->degToRad(randAngle));
- int y = targetY + randDist * sin(_ai->degToRad(randAngle));
+ int x = (int)(targetX + randDist * cos(_ai->degToRad(randAngle)));
+ int y = (int)(targetY + randDist * sin(_ai->degToRad(randAngle)));
int powAngle = _ai->getPowerAngleFromPoint(hubX, hubY, x, y, 20);
@@ -496,8 +497,8 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
int xDist = xCoord - x;
int yDist = yCoord - y;
- x = xCoord + (terrainSquareSize * 1.414 * (xDist / (abs(xDist) + 1)));
- y = yCoord + (terrainSquareSize * 1.414 * (yDist / (abs(yDist) + 1)));
+ x = (int)(xCoord + (terrainSquareSize * 1.414 * (xDist / (abs(xDist) + 1))));
+ y = (int)(yCoord + (terrainSquareSize * 1.414 * (yDist / (abs(yDist) + 1))));
setTargetX(x);
setTargetY(y);
diff --git a/engines/scumm/he/moonbase/ai_traveller.cpp b/engines/scumm/he/moonbase/ai_traveller.cpp
index 8294ea32b5..b1c9985b9d 100644
--- a/engines/scumm/he/moonbase/ai_traveller.cpp
+++ b/engines/scumm/he/moonbase/ai_traveller.cpp
@@ -143,10 +143,10 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
if (directDist > _maxDist + 120)
maxPower = _ai->getMaxPower();
else
- maxPower = (static_cast<float>(directDist) / static_cast<float>(_maxDist + 120)) * _ai->getMaxPower();
+ maxPower = (int)((static_cast<float>(directDist) / static_cast<float>(_maxDist + 120)) * _ai->getMaxPower());
maxPower -= 70;
- power = maxPower * (1 - ((index % NUM_POWER_STEPS) * SIZE_POWER_STEP));
+ power = (int)(maxPower * (1 - ((index % NUM_POWER_STEPS) * SIZE_POWER_STEP)));
}
retTraveller->setAngleTo(angle);
@@ -188,8 +188,8 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
float pwr = _ai->getMinPower() * .3;
float cosine = cos((static_cast<float>(angle) / 360) * (2 * M_PI));
float sine = sin((static_cast<float>(angle) / 360) * (2 * M_PI));
- int xParam = xCoord + (pwr * cosine);
- int yParam = yCoord + (pwr * sine);
+ int xParam = (int)(xCoord + (pwr * cosine));
+ int yParam = (int)(yCoord + (pwr * sine));
if (xParam < 0)
xParam += _ai->getMaxX();
@@ -233,8 +233,8 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
int xDist = xCoord - _posX;
int yDist = yCoord - _posY;
- retTraveller->setPosX(xCoord + (terrainSquareSize * 1.414 * (xDist / (abs(xDist) + 1))));
- retTraveller->setPosY(yCoord + (terrainSquareSize * 1.414 * (yDist / (abs(yDist) + 1))));
+ retTraveller->setPosX((int)(xCoord + (terrainSquareSize * 1.414 * (xDist / (abs(xDist) + 1)))));
+ retTraveller->setPosY((int)(yCoord + (terrainSquareSize * 1.414 * (yDist / (abs(yDist) + 1)))));
int closestHub = _ai->getClosestUnit(retTraveller->getPosX(), retTraveller->getPosY(), _ai->getMaxX(), _ai->getCurrentPlayer(), 1, BUILDING_MAIN_BASE, 1, 110);
diff --git a/engines/scumm/he/moonbase/ai_tree.cpp b/engines/scumm/he/moonbase/ai_tree.cpp
index e3098a7b24..d18536812b 100644
--- a/engines/scumm/he/moonbase/ai_tree.cpp
+++ b/engines/scumm/he/moonbase/ai_tree.cpp
@@ -29,7 +29,12 @@
namespace Scumm {
static int compareTreeNodes(const void *a, const void *b) {
- return ((const TreeNode *)a)->value - ((const TreeNode *)b)->value;
+ if (((const TreeNode *)a)->value < ((const TreeNode *)b)->value)
+ return -1;
+ else if (((const TreeNode *)a)->value > ((const TreeNode *)b)->value)
+ return 1;
+ else
+ return 0;
}
Tree::Tree(AI *ai) : _ai(ai) {