aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorStrangerke2012-07-01 18:16:56 +0200
committerEugene Sandulenko2018-03-28 17:36:57 +0200
commited9daf2ed649878a8a3eafcbbae4e60989e039ca (patch)
tree98737f0188b59ff3cdd48412b99f9e5a7cb08488 /engines
parent4efebbbeee94e24ecc9a95588a3c21b15d9b14d6 (diff)
downloadscummvm-rg350-ed9daf2ed649878a8a3eafcbbae4e60989e039ca.tar.gz
scummvm-rg350-ed9daf2ed649878a8a3eafcbbae4e60989e039ca.tar.bz2
scummvm-rg350-ed9daf2ed649878a8a3eafcbbae4e60989e039ca.zip
LILLIPUT: Rework _rectXMinMax and _rectYMinMax
Diffstat (limited to 'engines')
-rw-r--r--engines/lilliput/lilliput.cpp36
-rw-r--r--engines/lilliput/lilliput.h9
-rw-r--r--engines/lilliput/script.cpp29
-rw-r--r--engines/lilliput/script.h2
4 files changed, 42 insertions, 34 deletions
diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 773f09bfa8..b377d6c95c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1476,10 +1476,10 @@ void LilliputEngine::sub167EF(int index) {
}
if ((word167ED != -1) &&
- (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
- (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
- (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
- (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF))) {
+ (_array10999PosX[index] >= _rectXMinMax[word167EB].min) &&
+ (_array10999PosX[index] <= _rectXMinMax[word167EB].max) &&
+ (_array109C1PosY[index] >= _rectYMinMax[word167EB].min) &&
+ (_array109C1PosY[index] <= _rectYMinMax[word167EB].max)) {
_array109E9PosX[index] = _rulesBuffer12Pos4[word167ED].x;
_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
return;
@@ -1487,8 +1487,8 @@ void LilliputEngine::sub167EF(int index) {
_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
- int var4h = (_rectXMinMax[word167EB] >> 8);
- int var4l = (_rectXMinMax[word167EB] & 0xFF);
+ int var4h = _rectXMinMax[word167EB].min;
+ int var4l = _rectXMinMax[word167EB].max;
if (var4h != var4l) {
if (_rulesBuffer12Pos4[word167EB].x == var4h) {
@@ -1503,8 +1503,8 @@ void LilliputEngine::sub167EF(int index) {
return;
}
- var4h = (_rectYMinMax[word167EB] >> 8);
- var4l = (_rectYMinMax[word167EB] & 0xFF);
+ var4h = (_rectYMinMax[word167EB].min);
+ var4l = (_rectYMinMax[word167EB].max);
if (var4h != var4l) {
if (_rulesBuffer12Pos4[word167EB].y == var4h) {
@@ -1606,13 +1606,13 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
var1h = _word16937Pos.x;
var1l = _word16937Pos.y;
- if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
+ if ((var1h >= _rectXMinMax[var2].min) && (var1h <= _rectXMinMax[var2].max) && (var1l >= _rectYMinMax[var2].min) && (var1l <= _rectYMinMax[var2].max))
return 0;
var1h = _array109E9PosX[indexs];
var1l = _array10A11PosY[indexs];
- if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
+ if ((var1h >= _rectXMinMax[var2].min) && (var1h <= _rectXMinMax[var2].max) && (var1l >= _rectYMinMax[var2].min) && (var1l <= _rectYMinMax[var2].max))
return 0;
return 1;
@@ -1622,7 +1622,7 @@ int16 LilliputEngine::findHotspot(Common::Point pos) {
debugC(2, kDebugEngine, "findHotspot(%d, %d)", pos.x, pos.y);
for (int i = 0; i < _rectNumb; i++) {
- if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
+ if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max))
return i;
}
return -1;
@@ -1632,7 +1632,7 @@ int16 LilliputEngine::reverseFindHotspot(Common::Point pos) {
debugC(2, kDebugEngine, "reverseFindHotspot(%d, %d)", pos.x, pos.y);
for (int i = _rectNumb - 1; i >= 0 ; i--) {
- if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
+ if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max))
return i;
}
return -1;
@@ -1658,10 +1658,10 @@ void LilliputEngine::sub16A08(int index) {
int8 tmpIndex = 0;
for (int i = 3; i > 0; i--) {
- int16 tmpVal = 0x7FFF;
+ int16 smallestDistance = 0x7FFF;
for (int j = 0; j < 4; j++) {
- if (tmpVal > arrayDistance[j]) {
- tmpVal = arrayDistance[j];
+ if (smallestDistance > arrayDistance[j]) {
+ smallestDistance = arrayDistance[j];
tmpIndex = j;
}
}
@@ -2697,8 +2697,10 @@ void LilliputEngine::loadRules() {
uint16 tmpVal;
for (int i = 0; i < _rectNumb; i++) {
- _rectXMinMax[i] = f.readUint16LE();
- _rectYMinMax[i] = f.readUint16LE();
+ _rectXMinMax[i].min = (int16)f.readByte();
+ _rectXMinMax[i].max = (int16)f.readByte();
+ _rectYMinMax[i].min = (int16)f.readByte();
+ _rectYMinMax[i].max = (int16)f.readByte();
tmpVal = f.readUint16LE();
_rulesBuffer12Pos3[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
tmpVal = f.readUint16LE();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8d15400b06..7f26b05456 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -82,6 +82,11 @@ struct SmallAnim {
int16 _frameIndex[8];
};
+struct MinMax {
+ int16 min;
+ int16 max;
+};
+
class LilliputEngine : public Engine {
public:
LilliputEngine(OSystem *syst, const LilliputGameDescription *gd);
@@ -190,8 +195,8 @@ public:
int16 *_rulesChunk10;
byte *_rulesChunk11;
int16 _rectNumb;
- int16 _rectXMinMax[40];
- int16 _rectYMinMax[40];
+ MinMax _rectXMinMax[40];
+ MinMax _rectYMinMax[40];
Common::Point _rulesBuffer12Pos3[40];
Common::Point _rulesBuffer12Pos4[40];
int _interfaceHotspotNumb;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index af0879fc3d..89b414af57 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -25,6 +25,7 @@
#include "common/debug.h"
#include "common/system.h"
+#include <climits>
namespace Lilliput {
@@ -466,7 +467,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
OC_enableCharacterScript();
break;
case 0x4A:
- OC_sub18387();
+ OC_setRulesBuffer2Element();
break;
case 0x4B:
OC_setDebugFlag();
@@ -684,7 +685,7 @@ static const OpCode opCodes2[] = {
/* 0x47 */ { "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
/* 0x48 */ { "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone },
/* 0x49 */ { "OC_enableCharacterScript", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-/* 0x4a */ { "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+/* 0x4a */ { "OC_setRulesBuffer2Element", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
/* 0x4b */ { "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone },
/* 0x4c */ { "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone },
/* 0x4d */ { "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone },
@@ -1537,11 +1538,11 @@ byte LilliputScript::OC_compareCoords_1() {
int index = _currScript->readUint16LE();
assert(index < 40);
- int16 var3 = _vm->_rectXMinMax[index];
- int16 var4 = _vm->_rectYMinMax[index];
+ MinMax xMinMax = _vm->_rectXMinMax[index];
+ MinMax yMinMax = _vm->_rectYMinMax[index];
Common::Point var1 = _vm->_currentScriptCharacterPos;
- if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
+ if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max))
return 0;
return 1;
@@ -1554,10 +1555,10 @@ byte LilliputScript::OC_compareCoords_2() {
int16 index = getValue1();
Common::Point var1 = Common::Point(_characterTilePosX[index], _characterTilePosY[index]);
index = _currScript->readUint16LE();
- uint16 var3 = _vm->_rectXMinMax[index];
- uint16 var4 = _vm->_rectYMinMax[index];
+ MinMax xMinMax = _vm->_rectXMinMax[index];
+ MinMax yMinMax = _vm->_rectYMinMax[index];
- if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
+ if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max))
return 0;
return 1;
}
@@ -2947,7 +2948,7 @@ void LilliputScript::OC_sub18260() {
byte *isoMapBuf = getMapPtr(pt);
if (isoMapBuf[1] != 0xFF) {
- int byte1825D = 255;
+ int minVal = INT_MAX;
for (int var2 = 7; var2 >= 0; var2--) {
for (int var3 = 7; var3 >= 0; var3--) {
Common::Point(_viewportPos.x + var2, _viewportPos.y + var3);
@@ -2956,8 +2957,8 @@ void LilliputScript::OC_sub18260() {
if (isoMapBuf[1] == 0xFF) {
int x = abs(var2 - var4.x);
int y = abs(var3 - var4.y);
- if (x + y < byte1825D) {
- byte1825D = x + y;
+ if (x + y < minVal) {
+ minVal = x + y;
_word1825E = Common::Point(var2, var3);
}
}
@@ -3048,13 +3049,13 @@ void LilliputScript::OC_enableCharacterScript() {
enableCharacterScript(index, var2, _vm->getCharacterVariablesPtr(index * 32));
}
-void LilliputScript::OC_sub18387() {
- debugC(1, kDebugScriptTBC, "OC_sub18387()");
+void LilliputScript::OC_setRulesBuffer2Element() {
+ debugC(1, kDebugScript, "OC_setRulesBuffer2Element()");
int index = getValue1();
byte var1 = _currScript->readUint16LE() & 0xFF;
- assert(index < 40);
+ assert((index >= 0) && (index < 40));
_vm->_rulesBuffer2_10[index] = var1;
}
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 51b06ec7ef..bb01f80555 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -276,7 +276,7 @@ private:
void OC_setArray122C1();
void OC_sub18367();
void OC_enableCharacterScript();
- void OC_sub18387();
+ void OC_setRulesBuffer2Element();
void OC_setDebugFlag();
void OC_setByte14837();
void OC_waitForEvent();