LILLIPUT: Refactor engine, replace the use of MinMax by Common::Rect

This commit is contained in:
Strangerke 2018-04-20 07:55:46 +02:00
parent 7af31d6614
commit 56db8c626e
3 changed files with 31 additions and 55 deletions

View File

@ -236,12 +236,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
_listIndex = nullptr;
_listArr = nullptr;
_rectNumb = 0;
for (int i = 0; i < 40; ++i) {
_rectXMinMax[i].min = 0;
_rectXMinMax[i].max = 0;
_rectYMinMax[i].min = 0;
_rectYMinMax[i].max = 0;
}
for (int i = 0; i < 40; ++i)
_enclosureRect[i] = Common::Rect(0, 0, 0, 0);
_interfaceHotspotNumb = 0;
for (int i = 0; i < 20; ++i)
_keyboardMapping[i] = Common::KEYCODE_DOLLAR;
@ -1396,32 +1393,28 @@ void LilliputEngine::homeInPathFinding(int index) {
return;
}
if ((enclosureDst != -1) &&
(_characterTargetPos[index].x >= _rectXMinMax[enclosureSrc].min) &&
(_characterTargetPos[index].x <= _rectXMinMax[enclosureSrc].max) &&
(_characterTargetPos[index].y >= _rectYMinMax[enclosureSrc].min) &&
(_characterTargetPos[index].y <= _rectYMinMax[enclosureSrc].max)) {
if ((enclosureDst != -1) && _enclosureRect->contains(_characterTargetPos[index])) {
_characterSubTargetPos[index] = _portalPos[enclosureDst];
return;
}
_characterSubTargetPos[index] = _portalPos[enclosureSrc];
if (_rectXMinMax[enclosureSrc].min != _rectXMinMax[enclosureSrc].max) {
if (_portalPos[enclosureSrc].x == _rectXMinMax[enclosureSrc].min) {
if (_enclosureRect[enclosureSrc].left != _enclosureRect[enclosureSrc].right) {
if (_portalPos[enclosureSrc].x == _enclosureRect[enclosureSrc].left) {
_characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x - 1, _portalPos[enclosureSrc].y);
return;
}
if (_portalPos[enclosureSrc].x == _rectXMinMax[enclosureSrc].max) {
if (_portalPos[enclosureSrc].x == _enclosureRect[enclosureSrc].right) {
_characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x + 1, _portalPos[enclosureSrc].y);
return;
}
if (_rectYMinMax[enclosureSrc].min != _rectYMinMax[enclosureSrc].max) {
if (_portalPos[enclosureSrc].y == _rectYMinMax[enclosureSrc].min)
if (_enclosureRect[enclosureSrc].bottom != _enclosureRect[enclosureSrc].top) {
if (_portalPos[enclosureSrc].y == _enclosureRect[enclosureSrc].bottom)
_characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x, _portalPos[enclosureSrc].y - 1);
else // CHECKME: Should be a check on y == max
else // CHECKME: Should be a check on y == top
_characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x, _portalPos[enclosureSrc].y + 1);
return;
@ -1499,18 +1492,14 @@ byte LilliputEngine::homeInAvoidDeadEnds(int indexb, int indexs) {
Common::Point tmpPos = Common::Point(_curCharacterTilePos.x + constDirX[indexb], _curCharacterTilePos.y + constDirY[indexb]);
int16 var2 = checkEnclosure(tmpPos);
if (var2 == -1)
int16 idx = checkEnclosure(tmpPos);
if (idx == -1)
return 1;
tmpPos = _curCharacterTilePos;
if ((tmpPos.x >= _rectXMinMax[var2].min) && (tmpPos.x <= _rectXMinMax[var2].max) && (tmpPos.y >= _rectYMinMax[var2].min) && (tmpPos.y <= _rectYMinMax[var2].max))
if (_enclosureRect[idx].contains(_curCharacterTilePos))
return 0;
tmpPos = _characterSubTargetPos[indexs];
if ((tmpPos.x >= _rectXMinMax[var2].min) && (tmpPos.x <= _rectXMinMax[var2].max) && (tmpPos.y >= _rectYMinMax[var2].min) && (tmpPos.y <= _rectYMinMax[var2].max))
if (_enclosureRect[idx].contains(_characterSubTargetPos[indexs]))
return 0;
return 1;
@ -1519,8 +1508,8 @@ byte LilliputEngine::homeInAvoidDeadEnds(int indexb, int indexs) {
int16 LilliputEngine::checkEnclosure(Common::Point pos) {
debugC(2, kDebugEngine, "checkEnclosure(%d, %d)", pos.x, pos.y);
for (int i = 0; i < _rectNumb; i++) {
if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max))
for (int i = 0; i < _rectNumb; ++i) {
if (_enclosureRect[i].contains(pos))
return i;
}
return -1;
@ -1529,8 +1518,8 @@ int16 LilliputEngine::checkEnclosure(Common::Point pos) {
int16 LilliputEngine::checkOuterEnclosure(Common::Point pos) {
debugC(2, kDebugEngine, "checkOuterEnclosure(%d, %d)", pos.x, pos.y);
for (int i = _rectNumb - 1; i >= 0 ; i--) {
if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max))
for (int i = _rectNumb - 1; i >= 0 ; --i) {
if (_enclosureRect[i].contains(pos))
return i;
}
return -1;
@ -2571,10 +2560,10 @@ void LilliputEngine::loadRules() {
assert((_rectNumb >= 0) && (_rectNumb <= 40));
for (int i = 0; i < _rectNumb; i++) {
_rectXMinMax[i].max = (int16)f.readByte();
_rectXMinMax[i].min = (int16)f.readByte();
_rectYMinMax[i].max = (int16)f.readByte();
_rectYMinMax[i].min = (int16)f.readByte();
_enclosureRect[i].right = (int16)f.readByte();
_enclosureRect[i].left = (int16)f.readByte();
_enclosureRect[i].top = (int16)f.readByte();
_enclosureRect[i].bottom = (int16)f.readByte();
int16 tmpValY = (int16)f.readByte();
int16 tmpValX = (int16)f.readByte();

View File

@ -87,11 +87,6 @@ struct SmallAnim {
int16 _frameIndex[8];
};
struct MinMax {
int16 min;
int16 max;
};
class LilliputEngine : public Engine {
public:
LilliputEngine(OSystem *syst, const LilliputGameDescription *gd);
@ -200,8 +195,7 @@ public:
int16 *_listIndex;
byte *_listArr;
int16 _rectNumb;
MinMax _rectXMinMax[40];
MinMax _rectYMinMax[40];
Common::Rect _enclosureRect[40];
Common::Point _keyPos[40];
Common::Point _portalPos[40];
int _interfaceHotspotNumb;

View File

@ -1518,36 +1518,29 @@ byte LilliputScript::OC_CompareCharacterVariables() {
return compareValues(var1, operation, var2);
}
// TODO Rename function to "Check if character pos in rectangle"
// TODO Rename function to "Check if current script character pos is in enclosure"
byte LilliputScript::OC_compareCoords_1() {
debugC(1, kDebugScript, "OC_compareCoords_1()");
int index = _currScript->readUint16LE();
assert(index < 40);
MinMax xMinMax = _vm->_rectXMinMax[index];
MinMax yMinMax = _vm->_rectYMinMax[index];
Common::Point var1 = _vm->_currentScriptCharacterPos;
if (_vm->_enclosureRect[index].contains(_vm->_currentScriptCharacterPos))
return 1;
if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max))
return 0;
return 1;
return 0;
}
// TODO Rename function to "Check if character pos in rectangle"
// TODO Rename function to "Check if given character pos is in enclosure"
byte LilliputScript::OC_compareCoords_2() {
debugC(1, kDebugScript, "OC_compareCoords_2()");
int16 index = getValue1();
Common::Point var1 = _characterTilePos[index];
index = _currScript->readUint16LE();
MinMax xMinMax = _vm->_rectXMinMax[index];
MinMax yMinMax = _vm->_rectYMinMax[index];
if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max))
return 0;
return 1;
if (_vm->_enclosureRect[index].contains(_characterTilePos[index]))
return 1;
return 0;
}
byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {