Skip to content

Commit

Permalink
LILLIPUT: Fix mouse icon clipping, rework map Index formula, some ren…
Browse files Browse the repository at this point in the history
…aming
  • Loading branch information
Strangerke authored and sev- committed Mar 28, 2018
1 parent f0a4290 commit f602ca7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 53 deletions.
95 changes: 47 additions & 48 deletions engines/lilliput/lilliput.cpp
Expand Up @@ -346,9 +346,13 @@ void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point
int index2 = pos.x + (pos.y * 320);

for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
if (newBuf[j] != 0)
((byte *)_mainSurface->getPixels())[index2 + j] = newBuf[j];
// clip on y
if (pos.y + i < 200) {
for (int j = 0; j < 16; j++) {
// clip on x
if ((newBuf[j] != 0) && (pos.x + j < 320))
((byte *)_mainSurface->getPixels())[index2 + j] = newBuf[j];
}
}
index2 += 320;
newBuf += 16;
Expand Down Expand Up @@ -482,14 +486,12 @@ void LilliputEngine::displayLandscape() {

memcpy(_savedSurfaceGameArea2, _savedSurfaceGameArea3, 176 * 256); // 45056

int var1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
int var2;
int index = 0;
int index = (_scriptHandler->_viewportPos.y * 64 + _scriptHandler->_viewportPos.x) * 4;

for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8 ; j++) {
var2 = (j << 8) + i;
displayIsometricBlock(_savedSurfaceGameArea2, _bufferIsoMap[var1 + index], var2, 0);
for (int posY = 0; posY < 8; posY++) {
for (int posX = 0; posX < 8 ; posX++) {
assert (index < 16384);
displayIsometricBlock(_savedSurfaceGameArea2, _bufferIsoMap[index], posX, posY, 0);
index += 4;
}
index += 224;
Expand Down Expand Up @@ -608,11 +610,11 @@ void LilliputEngine::initGameAreaDisplay() {
free(tmpBuf);
}

void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int var2, int var3) {
debugC(1, kDebugEngine, "displayIsometricBlock(buf, %d, %d, %d)", var1, var2, var3);
void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int posX, int posY, int var3) {
debugC(1, kDebugEngine, "displayIsometricBlock(buf, %d, %d - %d, %d)", var1, posX, posY, var3);

byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7)) << 3) & 0xFF;
byte tmpByte1 = ((7 + posX - posY) << 4) & 0xFF;
byte tmpByte2 = ((4 + posX + posY - (var3 >> 7)) << 3) & 0xFF;

int index = (tmpByte2 << 8) + tmpByte1;
int index2 = var1 << 10;
Expand Down Expand Up @@ -763,25 +765,25 @@ void LilliputEngine::prepareGameArea() {

memcpy(_savedSurfaceGameArea1, _savedSurfaceGameArea2, 176 * 256); // 45056;

int index1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
int index1 = (_scriptHandler->_viewportPos.y * 64 + _scriptHandler->_viewportPos.x) * 4;
assert(index1 < 16384);
byte *map = &_bufferIsoMap[index1];

for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
int tmpVal = (j << 8) + i;
for (int posY = 0; posY < 8; posY++) {
for (int posX = 0; posX < 8; posX++) {
if (map[1] != 0xFF) {
int var1 = map[1];
if ((_rulesChunk9[var1] & 128) != 0)
var1 += _animationTick;
displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 1 << 8);
displayIsometricBlock(_savedSurfaceGameArea1, var1, posX, posY, 1 << 8);
}
renderCharacters(map, Common::Point(j, i));
renderCharacters(map, Common::Point(posX, posY));

if (map[2] != 0xFF) {
int var1 = map[2];
if ((_rulesChunk9[var1] & 128) != 0)
var1 += _animationTick;
displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 2 << 8);
displayIsometricBlock(_savedSurfaceGameArea1, var1, posX, posY, 2 << 8);
}
map += 4;
}
Expand Down Expand Up @@ -894,7 +896,9 @@ void LilliputEngine::paletteFadeIn() {
int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
debugC(2, kDebugEngineTBC, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);

byte *isoMap = _bufferIsoMap + (y1 << 8) + (x1 << 2) + 1;
int index = (y1 * 64 + x1) * 4;
assert(index < 16384);
byte *isoMap = &_bufferIsoMap[1];

int dx = x2 - x1;
int dy = y2 - y1;
Expand Down Expand Up @@ -1488,7 +1492,9 @@ void LilliputEngine::sub167EF(int index) {
}

// var4h == var4l
int mapIndex = (((_array10A11PosY[index] << 8) >> 2) + _array109E9PosX[index]) << 2;
int mapIndex = (_array10A11PosY[index] * 64 + _array109E9PosX[index]) * 4;
assert(mapIndex < 16384);

int tmpVal = _bufferIsoMap[mapIndex + 3];
if ((tmpVal & 8) != 0)
++_array109E9PosX[index];
Expand Down Expand Up @@ -1521,6 +1527,7 @@ void LilliputEngine::sub1693A(int index) {
int retVal = 0;
for (int i = 3; i >= 0; i--) {
mapIndexDiff = mapArrayMove[i];
assert(mapIndex + mapIndexDiff + 3 < 16384);
if (((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & _array16C54[i]) != 0) && ((_bufferIsoMap[mapIndex + 3] & _array16C58[i]) != 0)) {
if ((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & 0x80) != 0 && (sub16A76(i, index) != 0)) {
_array1692B[i] -= 20;
Expand Down Expand Up @@ -1820,13 +1827,12 @@ byte LilliputEngine::sub1675D(int index, Common::Point var1) {
void LilliputEngine::sub16EBC() {
debugC(2, kDebugEngine, "sub16EBC()");

int index2 = 3;

for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2);
int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
int mapIndex = (_scriptHandler->_array1614BPosY[index1] * 64 + _scriptHandler->_array16123PosX[index1]) * 4;
assert(mapIndex < 16384);
byte var1 = _bufferIsoMap[mapIndex + 3];

if (var1 == _array16E94[index1])
if ((var1 & 0x40) == _array16E94[index1])
continue;

_array16E94[index1] = var1;
Expand Down Expand Up @@ -1935,31 +1941,25 @@ void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
}

void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
debugC(2, kDebugEngineTBC, "checkInterfaceHotspots()");
debugC(2, kDebugEngine, "checkInterfaceHotspots()");

forceReturnFl = false;
for (int index = _interfaceHotspotNumb - 1; index >= 0; index--) {
if (sub13240(_mousePos, _interfaceHotspotsX[index], _interfaceHotspotsY[index]) == 0) {
if (isMouseOverHotspot(_mousePos, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]))) {
sub1305C(index, 1);
forceReturnFl = true;
return;
}
}
}

int LilliputEngine::sub13240(Common::Point mousePos, int var3, int var4) {
debugC(2, kDebugEngineTBC, "sub13240(%d, %d, %d, %d)", mousePos.x, mousePos.y, var3, var4);

if ((mousePos.x < var3) || (mousePos.y < var4))
return -1;

var3 += 16;
var4 += 16;
bool LilliputEngine::isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos) {
debugC(2, kDebugEngine, "isMouseOverHotspot(%d - %d, %d - %d)", mousePos.x, mousePos.y, hotspotPos.x, hotspotPos.y);

if ((mousePos.x > var3) || (mousePos.y > var4))
return -1;
if ((mousePos.x < hotspotPos.x) || (mousePos.y < hotspotPos.y) || (mousePos.x > hotspotPos.x + 16) || (mousePos.y > hotspotPos.y + 16))
return false;

return 0;
return true;
}

void LilliputEngine::sub1305C(byte index, byte button) {
Expand Down Expand Up @@ -2147,8 +2147,8 @@ void LilliputEngine::sub16B8F_moveCharacter(int index, Common::Point pos, int di
if ((pos.x < 0) || (pos.x >= 512) || (pos.y < 0) || (pos.y >= 512))
return;

int mapIndex = (_scriptHandler->_array1614BPosY[index] << 6) + _scriptHandler->_array16123PosX[index];
mapIndex <<= 2;
int mapIndex = (_scriptHandler->_array1614BPosY[index] * 64 + _scriptHandler->_array16123PosX[index]) * 4;
assert(mapIndex < 16384);

if ((_bufferIsoMap[mapIndex + 3] & _array16C58[direction]) == 0)
return;
Expand Down Expand Up @@ -2398,17 +2398,16 @@ byte *LilliputEngine::loadVGA(Common::String filename, int expectedSize, bool lo
return decodeBuffer;
}

byte *LilliputEngine::loadRaw(Common::String filename) {
byte *LilliputEngine::loadRaw(Common::String filename, int filesize) {
debugC(1, kDebugEngine, "loadRaw(%s)", filename.c_str());

Common::File f;

if (!f.open(filename))
error("Missing game file %s", filename.c_str());

int size = f.size();
byte *res = (byte *)malloc(sizeof(byte) * size);
for (int i = 0; i < size; ++i)
byte *res = (byte *)malloc(sizeof(byte) * filesize);
for (int i = 0; i < filesize; ++i)
res[i] = f.readByte();

f.close();
Expand Down Expand Up @@ -2742,7 +2741,7 @@ Common::Error LilliputEngine::run() {
_bufferMen = loadVGA("MEN.VGA", 61440, false);
_bufferMen2 = loadVGA("MEN2.VGA", 61440, false);
_bufferIsoChars = loadVGA("ISOCHARS.VGA", 4096, false);
_bufferIsoMap = loadRaw("ISOMAP.DTA");
_bufferIsoMap = loadRaw("ISOMAP.DTA", 16384);

loadRules();
_int8installed = true;
Expand Down
6 changes: 3 additions & 3 deletions engines/lilliput/lilliput.h
Expand Up @@ -236,7 +236,7 @@ class LilliputEngine : public Engine {
void displaySpeechBubble();
void displaySpeech(byte *buf);
void initGameAreaDisplay();
void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
void displayIsometricBlock(byte *buf, int var1, int posX, int posY, int var3);
void displayGameArea();
void prepareGameArea();
void displayRefreshScreen();
Expand Down Expand Up @@ -290,7 +290,7 @@ class LilliputEngine : public Engine {
void sub130EE();
void sub1305C(byte index, byte var2);
void checkInterfaceHotspots(bool &forceReturnFl);
int sub13240(Common::Point mousePos, int var3, int var4);
bool isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos);
void sub131B2(Common::Point pos, bool &forceReturnFl);
void sub131FC(Common::Point pos);
void sub1546F(Common::Point displayPos);
Expand All @@ -316,7 +316,7 @@ class LilliputEngine : public Engine {

void initGame(const LilliputGameDescription *gd);
byte *loadVGA(Common::String filename, int fileSize, bool loadPal);
byte *loadRaw(Common::String filename);
byte *loadRaw(Common::String filename, int filesize);
void loadRules();

void displayVGAFile(Common::String fileName);
Expand Down
6 changes: 4 additions & 2 deletions engines/lilliput/script.cpp
Expand Up @@ -2777,11 +2777,13 @@ void LilliputScript::OC_setInterfaceHotspot() {
debugC(1, kDebugScript, "OC_setInterfaceHotspot()");

int16 index = _currScript->readSint16LE();
uint16 curWord = _currScript->readUint16LE();

assert((index >= 0) && (index < 20));

uint16 curWord = _currScript->readUint16LE();
_interfaceHotspotStatus[index] = (curWord & 0xFF);
_array122FD[index] = (curWord >> 8);
if (_array122FD[index] != 0)
warning("debug - OC_setInterfaceHotspot - _array122FD[index] = %d", _array122FD[index]);

_vm->displayInterfaceHotspots();
}
Expand Down

0 comments on commit f602ca7

Please sign in to comment.