diff options
author | Eugene Sandulenko | 2006-01-03 23:14:39 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2006-01-03 23:14:39 +0000 |
commit | fd8ac69fc45fb346a931f61701e8aec04278159b (patch) | |
tree | fc4ca73bf00b17f7c42569a789baf0f4e64a91c3 /gob/map.cpp | |
parent | f046a14bb22f1d6c138ed82efa03d5ff89ae85e0 (diff) | |
download | scummvm-rg350-fd8ac69fc45fb346a931f61701e8aec04278159b.tar.gz scummvm-rg350-fd8ac69fc45fb346a931f61701e8aec04278159b.tar.bz2 scummvm-rg350-fd8ac69fc45fb346a931f61701e8aec04278159b.zip |
Patch #1395615 "GobEngine code wrapped in classes". With some cosmetic changes.
svn-id: r19899
Diffstat (limited to 'gob/map.cpp')
-rw-r--r-- | gob/map.cpp | 522 |
1 files changed, 266 insertions, 256 deletions
diff --git a/gob/map.cpp b/gob/map.cpp index 955742503a..85983a72de 100644 --- a/gob/map.cpp +++ b/gob/map.cpp @@ -31,28 +31,38 @@ namespace Gob { -int8 map_passMap[kMapHeight][kMapWidth]; // [y][x] -int16 map_itemsMap[kMapHeight][kMapWidth]; // [y][x] - -Map_Point map_wayPoints[40]; -int16 map_nearestWayPoint = 0; -int16 map_nearestDest = 0; - -int16 map_curGoblinX; -int16 map_curGoblinY; -int16 map_destX; -int16 map_destY; - -Map_ItemPos map_itemPoses[40]; -int8 map_loadFromAvo; -char map_sourceFile[15]; -static char *map_avoDataPtr; - -void map_placeItem(int16 x, int16 y, int16 id) { - if ((map_itemsMap[y][x] & 0xff00) != 0) - map_itemsMap[y][x] = (map_itemsMap[y][x] & 0xff00) | id; +Map::Map(GobEngine *vm) : _vm(vm) { + for (int i = 0; i < kMapHeight; i++) + for (int j = 0; j < kMapWidth; j++) { + passMap[i][j] = 0; + itemsMap[i][j] = 0; + } + for (int i = 0; i < 40; i++) { + wayPoints[i].x = 0; + wayPoints[i].y = 0; + } + for (int i = 0; i < 40; i++) { + itemPoses[i].x = 0; + itemPoses[i].y = 0; + itemPoses[i].orient = 0; + } + + nearestWayPoint = 0; + nearestDest = 0; + curGoblinX = 0; + curGoblinY = 0; + destX = 0; + destY = 0; + loadFromAvo = 0; + sourceFile[0] = 0; + avoDataPtr = 0; +} + +void Map::placeItem(int16 x, int16 y, int16 id) { + if ((itemsMap[y][x] & 0xff00) != 0) + itemsMap[y][x] = (itemsMap[y][x] & 0xff00) | id; else - map_itemsMap[y][x] = (map_itemsMap[y][x] & 0x00ff) | (id << 8); + itemsMap[y][x] = (itemsMap[y][x] & 0x00ff) | (id << 8); } enum { @@ -62,7 +72,7 @@ enum { kDown = (1 << 3) }; -int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { +int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { int16 dir = 0; if (x0 == x1 && y0 == y1) @@ -81,63 +91,63 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { else if (x1 < x0) dir |= kLeft; - if (map_passMap[y0][x0] == 3 && (dir & kUp)) { - if (map_passMap[y0 - 1][x0] != 0) + if (passMap[y0][x0] == 3 && (dir & kUp)) { + if (passMap[y0 - 1][x0] != 0) return kDirN; } - if (map_passMap[y0][x0] == 3 && (dir & kDown)) { - if (map_passMap[y0 + 1][x0] != 0) + if (passMap[y0][x0] == 3 && (dir & kDown)) { + if (passMap[y0 + 1][x0] != 0) return kDirS; } - if (map_passMap[y0][x0] == 6 && (dir & kUp)) { - if (map_passMap[y0 - 1][x0] != 0) + if (passMap[y0][x0] == 6 && (dir & kUp)) { + if (passMap[y0 - 1][x0] != 0) return kDirN; } - if (map_passMap[y0][x0] == 6 && (dir & kDown)) { - if (map_passMap[y0 + 1][x0] != 0) + if (passMap[y0][x0] == 6 && (dir & kDown)) { + if (passMap[y0 + 1][x0] != 0) return kDirS; } if (dir == kLeft) { - if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0) + if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0) return kDirW; return 0; } if (dir == kRight) { - if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0) + if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0) return kDirE; return 0; } if (dir == kUp) { - if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0) + if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0) return kDirN; if (y0 - 1 >= 0 && x0 - 1 >= 0 - && map_passMap[y0 - 1][x0 - 1] != 0) + && passMap[y0 - 1][x0 - 1] != 0) return kDirNW; if (y0 - 1 >= 0 && x0 + 1 < kMapWidth - && map_passMap[y0 - 1][x0 + 1] != 0) + && passMap[y0 - 1][x0 + 1] != 0) return kDirNE; return 0; } if (dir == kDown) { - if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0) + if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0) return kDirS; if (y0 + 1 < kMapHeight && x0 - 1 >= 0 - && map_passMap[y0 + 1][x0 - 1] != 0) + && passMap[y0 + 1][x0 - 1] != 0) return kDirSW; if (y0 + 1 < kMapHeight && x0 + 1 < kMapWidth - && map_passMap[y0 + 1][x0 + 1] != 0) + && passMap[y0 + 1][x0 + 1] != 0) return kDirSE; return 0; @@ -145,13 +155,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kRight | kUp)) { if (y0 - 1 >= 0 && x0 + 1 < kMapWidth - && map_passMap[y0 - 1][x0 + 1] != 0) + && passMap[y0 - 1][x0 + 1] != 0) return kDirNE; - if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0) + if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0) return kDirN; - if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0) + if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0) return kDirE; return 0; @@ -159,13 +169,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kRight | kDown)) { if (x0 + 1 < kMapWidth && y0 + 1 < kMapHeight - && map_passMap[y0 + 1][x0 + 1] != 0) + && passMap[y0 + 1][x0 + 1] != 0) return kDirSE; - if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0) + if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0) return kDirS; - if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0) + if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0) return kDirE; return 0; @@ -173,13 +183,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kLeft | kUp)) { if (x0 - 1 >= 0 && y0 - 1 >= 0 - && map_passMap[y0 - 1][x0 - 1] != 0) + && passMap[y0 - 1][x0 - 1] != 0) return kDirNW; - if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0) + if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0) return kDirN; - if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0) + if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0) return kDirW; return 0; @@ -187,13 +197,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kLeft | kDown)) { if (x0 - 1 >= 0 && y0 + 1 < kMapHeight - && map_passMap[y0 + 1][x0 - 1] != 0) + && passMap[y0 + 1][x0 - 1] != 0) return kDirSW; - if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0) + if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0) return kDirS; - if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0) + if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0) return kDirW; return 0; @@ -201,8 +211,8 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return -1; } -int16 map_findNearestWayPoint(int16 x, int16 y) { - int16 nearestWayPoint = -1; +int16 Map::findNearestWayPoint(int16 x, int16 y) { + int16 lnearestWayPoint = -1; int16 length; int16 i; int16 tmp; @@ -210,41 +220,41 @@ int16 map_findNearestWayPoint(int16 x, int16 y) { length = 30000; for (i = 0; i < 40; i++) { - if (map_wayPoints[i].x < 0 || - map_wayPoints[i].x >= kMapWidth || - map_wayPoints[i].y < 0 || map_wayPoints[i].y >= kMapHeight) + if (wayPoints[i].x < 0 || + wayPoints[i].x >= kMapWidth || + wayPoints[i].y < 0 || wayPoints[i].y >= kMapHeight) return -1; - tmp = ABS(x - map_wayPoints[i].x) + ABS(y - map_wayPoints[i].y); + tmp = ABS(x - wayPoints[i].x) + ABS(y - wayPoints[i].y); if (tmp <= length) { - nearestWayPoint = i; + lnearestWayPoint = i; length = tmp; } } - return nearestWayPoint; + return lnearestWayPoint; } -void map_findNearestToGob(void) { - int16 wayPoint = map_findNearestWayPoint(map_curGoblinX, map_curGoblinY); +void Map::findNearestToGob(void) { + int16 wayPoint = findNearestWayPoint(curGoblinX, curGoblinY); if (wayPoint != -1) - map_nearestWayPoint = wayPoint; + nearestWayPoint = wayPoint; } -void map_findNearestToDest(void) { - int16 wayPoint = map_findNearestWayPoint(map_destX, map_destY); +void Map::findNearestToDest(void) { + int16 wayPoint = findNearestWayPoint(destX, destY); if (wayPoint != -1) - map_nearestDest = wayPoint; + nearestDest = wayPoint; } -int16 map_checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) { +int16 Map::checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) { uint16 dir; while (1) { - dir = map_getDirection(x0, y0, x1, y1); + dir = getDirection(x0, y0, x1, y1); if (x0 == x1 && y0 == y1) return 1; @@ -292,7 +302,7 @@ int16 map_checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) { } } -int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) { +int16 Map::checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) { uint16 dir; int16 curX; int16 curY; @@ -309,30 +319,30 @@ int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 nextLink = 1; if (nextLink != 0) { - if (map_checkDirectPath(x0, y0, x1, y1) == 1) + if (checkDirectPath(x0, y0, x1, y1) == 1) return 1; nextLink = 0; if (i0 > i1) { - curX = map_wayPoints[i0].x; - curY = map_wayPoints[i0].y; + curX = wayPoints[i0].x; + curY = wayPoints[i0].y; i0--; } else if (i0 < i1) { - curX = map_wayPoints[i0].x; - curY = map_wayPoints[i0].y; + curX = wayPoints[i0].x; + curY = wayPoints[i0].y; i0++; } else if (i0 == i1) { - curX = map_wayPoints[i0].x; - curY = map_wayPoints[i0].y; + curX = wayPoints[i0].x; + curY = wayPoints[i0].y; } } - if (i0 == i1 && map_wayPoints[i0].x == x0 - && map_wayPoints[i0].y == y0) { - if (map_checkDirectPath(x0, y0, x1, y1) == 1) + if (i0 == i1 && wayPoints[i0].x == x0 + && wayPoints[i0].y == y0) { + if (checkDirectPath(x0, y0, x1, y1) == 1) return 1; return 0; } - dir = map_getDirection(x0, y0, curX, curY); + dir = getDirection(x0, y0, curX, curY); switch (dir) { case 0: return 0; @@ -376,54 +386,54 @@ int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 } } -void map_optimizePoints(void) { +void Map::optimizePoints(void) { int16 i; - if (map_nearestWayPoint < map_nearestDest) { - for (i = map_nearestWayPoint; i <= map_nearestDest; i++) { - if (map_checkDirectPath(map_curGoblinX, map_curGoblinY, - map_wayPoints[i].x, map_wayPoints[i].y) == 1) - map_nearestWayPoint = i; + if (nearestWayPoint < nearestDest) { + for (i = nearestWayPoint; i <= nearestDest; i++) { + if (checkDirectPath(curGoblinX, curGoblinY, + wayPoints[i].x, wayPoints[i].y) == 1) + nearestWayPoint = i; } - } else if (map_nearestWayPoint > map_nearestDest) { - for (i = map_nearestWayPoint; i >= map_nearestDest; i--) { - if (map_checkDirectPath(map_curGoblinX, map_curGoblinY, - map_wayPoints[i].x, map_wayPoints[i].y) == 1) - map_nearestWayPoint = i; + } else if (nearestWayPoint > nearestDest) { + for (i = nearestWayPoint; i >= nearestDest; i--) { + if (checkDirectPath(curGoblinX, curGoblinY, + wayPoints[i].x, wayPoints[i].y) == 1) + nearestWayPoint = i; } } } -void map_loadDataFromAvo(char *dest, int16 size) { - memcpy(dest, map_avoDataPtr, size); - map_avoDataPtr += size; +void Map::loadDataFromAvo(char *dest, int16 size) { + memcpy(dest, avoDataPtr, size); + avoDataPtr += size; } -uint16 map_loadFromAvo_LE_UINT16() { - uint16 tmp = READ_LE_UINT16(map_avoDataPtr); - map_avoDataPtr += 2; +uint16 Map::loadFromAvo_LE_UINT16() { + uint16 tmp = READ_LE_UINT16(avoDataPtr); + avoDataPtr += 2; return tmp; } -void map_loadItemToObject(void) { +void Map::loadItemToObject(void) { int16 flag; int16 count; int16 i; - flag = map_loadFromAvo_LE_UINT16(); + flag = loadFromAvo_LE_UINT16(); if (flag == 0) return; - map_avoDataPtr += 1456; - count = map_loadFromAvo_LE_UINT16(); + avoDataPtr += 1456; + count = loadFromAvo_LE_UINT16(); for (i = 0; i < count; i++) { - map_avoDataPtr += 20; - gob_itemToObject[i] = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += 5; + avoDataPtr += 20; + _vm->_goblin->itemToObject[i] = loadFromAvo_LE_UINT16(); + avoDataPtr += 5; } } -void map_loadMapObjects(char *avjFile) { +void Map::loadMapObjects(char *avjFile) { int16 i; char avoName[128]; int16 handle; @@ -436,7 +446,7 @@ void map_loadMapObjects(char *avjFile) { int16 state; int16 col; int32 flag; - Gob_State *pState; + Goblin::Gob_State *pState; char buf[128]; char sndNames[20][14]; char *dataBuf; @@ -445,154 +455,154 @@ void map_loadMapObjects(char *avjFile) { int16 count2; int16 count3; - strcpy(avoName, map_sourceFile); + strcpy(avoName, sourceFile); strcat(avoName, ".avo"); - handle = data_openData(avoName); + handle = _vm->_dataio->openData(avoName); if (handle >= 0) { - map_loadFromAvo = 1; - data_closeData(handle); - map_avoDataPtr = data_getData(avoName); - dataBuf = map_avoDataPtr; - map_loadDataFromAvo((char *)map_passMap, kMapHeight * kMapWidth); + loadFromAvo = 1; + _vm->_dataio->closeData(handle); + avoDataPtr = _vm->_dataio->getData(avoName); + dataBuf = avoDataPtr; + loadDataFromAvo((char *)passMap, kMapHeight * kMapWidth); for (y = 0; y < kMapHeight; y++) { for (x = 0; x < kMapWidth; x++) { - map_loadDataFromAvo(&item, 1); - map_itemsMap[y][x] = item; + loadDataFromAvo(&item, 1); + itemsMap[y][x] = item; } } for (i = 0; i < 40; i++) { - map_wayPoints[i].x = map_loadFromAvo_LE_UINT16(); - map_wayPoints[i].y = map_loadFromAvo_LE_UINT16(); + wayPoints[i].x = loadFromAvo_LE_UINT16(); + wayPoints[i].y = loadFromAvo_LE_UINT16(); } - map_loadDataFromAvo((char *)map_itemPoses, szMap_ItemPos * 20); + loadDataFromAvo((char *)itemPoses, szMap_ItemPos * 20); } else { - map_loadFromAvo = 0; - map_avoDataPtr = data_getData(avjFile); - dataBuf = map_avoDataPtr; + loadFromAvo = 0; + avoDataPtr = _vm->_dataio->getData(avjFile); + dataBuf = avoDataPtr; } - map_avoDataPtr += 32; - map_avoDataPtr += 76; - map_avoDataPtr += 4; - map_avoDataPtr += 20; + avoDataPtr += 32; + avoDataPtr += 76; + avoDataPtr += 4; + avoDataPtr += 20; for (i = 0; i < 3; i++) { - tmp = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += tmp * 14; + tmp = loadFromAvo_LE_UINT16(); + avoDataPtr += tmp * 14; } - soundCount = map_loadFromAvo_LE_UINT16(); - savedPtr = map_avoDataPtr; + soundCount = loadFromAvo_LE_UINT16(); + savedPtr = avoDataPtr; - map_avoDataPtr += 14 * soundCount; - map_avoDataPtr += 4; - map_avoDataPtr += 24; + avoDataPtr += 14 * soundCount; + avoDataPtr += 4; + avoDataPtr += 24; - count2 = map_loadFromAvo_LE_UINT16(); - count3 = map_loadFromAvo_LE_UINT16(); + count2 = loadFromAvo_LE_UINT16(); + count3 = loadFromAvo_LE_UINT16(); - savedPtr2 = map_avoDataPtr; - map_avoDataPtr += count2 * 8; + savedPtr2 = avoDataPtr; + avoDataPtr += count2 * 8; - savedPtr3 = map_avoDataPtr; - map_avoDataPtr += count3 * 8; + savedPtr3 = avoDataPtr; + avoDataPtr += count3 * 8; - gob_gobsCount = map_loadFromAvo_LE_UINT16(); - for (i = 0; i < gob_gobsCount; i++) { - gob_goblins[i] = (Gob_Object *)malloc(sizeof(Gob_Object)); + _vm->_goblin->gobsCount = loadFromAvo_LE_UINT16(); + for (i = 0; i < _vm->_goblin->gobsCount; i++) { + _vm->_goblin->goblins[i] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object)); - gob_goblins[i]->xPos = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->xPos = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; - gob_goblins[i]->yPos = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->yPos = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; - gob_goblins[i]->order = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->order = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; - gob_goblins[i]->state = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->state = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; if (i == 3) - gob_goblins[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 70); + _vm->_goblin->goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 70); else - gob_goblins[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40); + _vm->_goblin->goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40); - // FIXME: All is wrong further. We should unwind calls to map_loadDataFromAvo() - map_loadDataFromAvo((char *)gob_goblins[i]->stateMach, 40 * szGob_StateLine); - map_avoDataPtr += 160; - gob_goblins[i]->multObjIndex = *map_avoDataPtr; - map_avoDataPtr += 2; + // FIXME: All is wrong further. We should unwind calls to loadDataFromAvo() + loadDataFromAvo((char *)_vm->_goblin->goblins[i]->stateMach, 40 * szGob_StateLine); + avoDataPtr += 160; + _vm->_goblin->goblins[i]->multObjIndex = *avoDataPtr; + avoDataPtr += 2; - gob_goblins[i]->realStateMach = gob_goblins[i]->stateMach; + _vm->_goblin->goblins[i]->realStateMach = _vm->_goblin->goblins[i]->stateMach; for (state = 0; state < 40; state++) { for (col = 0; col < 6; col++) { - if (gob_goblins[i]->stateMach[state][col] == 0) + if (_vm->_goblin->goblins[i]->stateMach[state][col] == 0) continue; - Gob_State *tmpState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_goblins[i]->stateMach[state][col] = tmpState; + Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[i]->stateMach[state][col] = tmpState; - tmpState->animation = map_loadFromAvo_LE_UINT16(); - tmpState->layer = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += 8; - tmpState->unk0 = map_loadFromAvo_LE_UINT16(); - tmpState->unk1 = map_loadFromAvo_LE_UINT16(); + tmpState->animation = loadFromAvo_LE_UINT16(); + tmpState->layer = loadFromAvo_LE_UINT16(); + avoDataPtr += 8; + tmpState->unk0 = loadFromAvo_LE_UINT16(); + tmpState->unk1 = loadFromAvo_LE_UINT16(); - map_avoDataPtr += 2; - if (READ_LE_UINT32(map_avoDataPtr) != 0) { - map_avoDataPtr += 4; - tmpState->sndItem = map_loadFromAvo_LE_UINT16(); + avoDataPtr += 2; + if (READ_LE_UINT32(avoDataPtr) != 0) { + avoDataPtr += 4; + tmpState->sndItem = loadFromAvo_LE_UINT16(); } else { - map_avoDataPtr += 6; + avoDataPtr += 6; tmpState->sndItem = -1; } - tmpState->freq = map_loadFromAvo_LE_UINT16(); - tmpState->repCount = map_loadFromAvo_LE_UINT16(); - tmpState->sndFrame = map_loadFromAvo_LE_UINT16(); + tmpState->freq = loadFromAvo_LE_UINT16(); + tmpState->repCount = loadFromAvo_LE_UINT16(); + tmpState->sndFrame = loadFromAvo_LE_UINT16(); } } } - pState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_goblins[0]->stateMach[39][0] = pState; + pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[0]->stateMach[39][0] = pState; pState->animation = 0; pState->layer = 98; pState->unk0 = 0; pState->unk1 = 0; pState->sndItem = -1; - pState = (Gob_State *) malloc(sizeof(Gob_State)); - gob_goblins[1]->stateMach[39][0] = pState; + pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[1]->stateMach[39][0] = pState; pState->animation = 0; pState->layer = 99; pState->unk0 = 0; pState->unk1 = 0; pState->sndItem = -1; - pState = (Gob_State *) malloc(sizeof(Gob_State)); - gob_goblins[2]->stateMach[39][0] = pState; + pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[2]->stateMach[39][0] = pState; pState->animation = 0; pState->layer = 100; pState->unk0 = 0; pState->unk1 = 0; pState->sndItem = -1; - gob_goblins[2]->stateMach[10][0]->sndFrame = 13; - gob_goblins[2]->stateMach[11][0]->sndFrame = 13; - gob_goblins[2]->stateMach[28][0]->sndFrame = 13; - gob_goblins[2]->stateMach[29][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[10][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[11][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[28][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[29][0]->sndFrame = 13; - gob_goblins[1]->stateMach[10][0]->sndFrame = 13; - gob_goblins[1]->stateMach[11][0]->sndFrame = 13; + _vm->_goblin->goblins[1]->stateMach[10][0]->sndFrame = 13; + _vm->_goblin->goblins[1]->stateMach[11][0]->sndFrame = 13; for (state = 40; state < 70; state++) { - pState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_goblins[3]->stateMach[state][0] = pState; - gob_goblins[3]->stateMach[state][1] = 0; + pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[3]->stateMach[state][0] = pState; + _vm->_goblin->goblins[3]->stateMach[state][1] = 0; pState->animation = 9; pState->layer = state - 40; @@ -600,70 +610,70 @@ void map_loadMapObjects(char *avjFile) { pState->sndFrame = 0; } - gob_objCount = map_loadFromAvo_LE_UINT16(); - for (i = 0; i < gob_objCount; i++) { - gob_objects[i] = - (Gob_Object *) malloc(sizeof(Gob_Object)); + _vm->_goblin->objCount = loadFromAvo_LE_UINT16(); + for (i = 0; i < _vm->_goblin->objCount; i++) { + _vm->_goblin->objects[i] = + (Goblin::Gob_Object *) malloc(sizeof(Goblin::Gob_Object)); - gob_objects[i]->xPos = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->xPos = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->yPos = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->yPos = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->order = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->order = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->state = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->state = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40); + _vm->_goblin->objects[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40); - map_loadDataFromAvo((char *)gob_objects[i]->stateMach, 40 * szGob_StateLine); - map_avoDataPtr += 160; - gob_objects[i]->multObjIndex = *map_avoDataPtr; - map_avoDataPtr += 2; + loadDataFromAvo((char *)_vm->_goblin->objects[i]->stateMach, 40 * szGob_StateLine); + avoDataPtr += 160; + _vm->_goblin->objects[i]->multObjIndex = *avoDataPtr; + avoDataPtr += 2; - gob_objects[i]->realStateMach = gob_objects[i]->stateMach; + _vm->_goblin->objects[i]->realStateMach = _vm->_goblin->objects[i]->stateMach; for (state = 0; state < 40; state++) { for (col = 0; col < 6; col++) { - if (gob_objects[i]->stateMach[state][col] == 0) + if (_vm->_goblin->objects[i]->stateMach[state][col] == 0) continue; - Gob_State *tmpState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_objects[i]->stateMach[state][col] = tmpState; + Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->objects[i]->stateMach[state][col] = tmpState; - tmpState->animation = map_loadFromAvo_LE_UINT16(); - tmpState->layer = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += 8; - tmpState->unk0 = map_loadFromAvo_LE_UINT16(); - tmpState->unk1 = map_loadFromAvo_LE_UINT16(); + tmpState->animation = loadFromAvo_LE_UINT16(); + tmpState->layer = loadFromAvo_LE_UINT16(); + avoDataPtr += 8; + tmpState->unk0 = loadFromAvo_LE_UINT16(); + tmpState->unk1 = loadFromAvo_LE_UINT16(); - map_avoDataPtr += 2; - if (READ_LE_UINT32(map_avoDataPtr) != 0) { - map_avoDataPtr += 4; - tmpState->sndItem = map_loadFromAvo_LE_UINT16(); + avoDataPtr += 2; + if (READ_LE_UINT32(avoDataPtr) != 0) { + avoDataPtr += 4; + tmpState->sndItem = loadFromAvo_LE_UINT16(); } else { - map_avoDataPtr += 6; + avoDataPtr += 6; tmpState->sndItem = -1; } - tmpState->freq = map_loadFromAvo_LE_UINT16(); - tmpState->repCount = map_loadFromAvo_LE_UINT16(); - tmpState->sndFrame = map_loadFromAvo_LE_UINT16(); + tmpState->freq = loadFromAvo_LE_UINT16(); + tmpState->repCount = loadFromAvo_LE_UINT16(); + tmpState->sndFrame = loadFromAvo_LE_UINT16(); } } } - gob_objects[10] = (Gob_Object *)malloc(sizeof(Gob_Object)); - memset(gob_objects[10], 0, sizeof(Gob_Object)); + _vm->_goblin->objects[10] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object)); + memset(_vm->_goblin->objects[10], 0, sizeof(Goblin::Gob_Object)); - gob_objects[10]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40); - memset(gob_objects[10]->stateMach, 0, szGob_StateLine * 40); + _vm->_goblin->objects[10]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40); + memset(_vm->_goblin->objects[10]->stateMach, 0, szGob_StateLine * 40); - pState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_objects[10]->stateMach[0][0] = pState; + pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->objects[10]->stateMach[0][0] = pState; - memset(pState, 0, sizeof(Gob_State)); + memset(pState, 0, sizeof(Goblin::Gob_State)); pState->animation = 9; pState->layer = 27; pState->unk0 = 0; @@ -671,84 +681,84 @@ void map_loadMapObjects(char *avjFile) { pState->sndItem = -1; pState->sndFrame = 0; - gob_placeObject(gob_objects[10], 1); + _vm->_goblin->placeObject(_vm->_goblin->objects[10], 1); - gob_objects[10]->realStateMach = gob_objects[10]->stateMach; - gob_objects[10]->type = 1; - gob_objects[10]->unk14 = 1; + _vm->_goblin->objects[10]->realStateMach = _vm->_goblin->objects[10]->stateMach; + _vm->_goblin->objects[10]->type = 1; + _vm->_goblin->objects[10]->unk14 = 1; - state = map_loadFromAvo_LE_UINT16(); + state = loadFromAvo_LE_UINT16(); for (i = 0; i < state; i++) { - map_avoDataPtr += 30; + avoDataPtr += 30; - map_loadDataFromAvo((char *)&flag, 4); - map_avoDataPtr += 56; + loadDataFromAvo((char *)&flag, 4); + avoDataPtr += 56; if (flag != 0) - map_avoDataPtr += 30; + avoDataPtr += 30; } - map_loadDataFromAvo((char *)&tmp, 2); - map_avoDataPtr += 48; - map_loadItemToObject(); - map_avoDataPtr = savedPtr; + loadDataFromAvo((char *)&tmp, 2); + avoDataPtr += 48; + loadItemToObject(); + avoDataPtr = savedPtr; for (i = 0; i < soundCount; i++) { - map_loadDataFromAvo(buf, 14); + loadDataFromAvo(buf, 14); strcat(buf, ".SND"); strcpy(sndNames[i], buf); } free(dataBuf); - gob_soundData[14] = snd_loadSoundData("diamant1.snd"); + _vm->_goblin->soundData[14] = _vm->_snd->loadSoundData("diamant1.snd"); for (i = 0; i < soundCount; i++) { - handle = data_openData(sndNames[i]); + handle = _vm->_dataio->openData(sndNames[i]); if (handle < 0) continue; - data_closeData(handle); - gob_soundData[i] = snd_loadSoundData(sndNames[i]); + _vm->_dataio->closeData(handle); + _vm->_goblin->soundData[i] = _vm->_snd->loadSoundData(sndNames[i]); } } -void map_loadMapsInitGobs(void) { +void Map::loadMapsInitGobs(void) { int16 layer; int16 i; - if (map_loadFromAvo == 0) - error("map_load: Loading .pas/.pos files is not supported!"); + if (loadFromAvo == 0) + error("load: Loading .pas/.pos files is not supported!"); for (i = 0; i < 3; i++) { - gob_nextLayer(gob_goblins[i]); + _vm->_goblin->nextLayer(_vm->_goblin->goblins[i]); } for (i = 0; i < 3; i++) { layer = - gob_goblins[i]->stateMach[gob_goblins[i]->state][0]->layer; + _vm->_goblin->goblins[i]->stateMach[_vm->_goblin->goblins[i]->state][0]->layer; - scen_updateAnim(layer, 0, gob_goblins[i]->animation, 0, - gob_goblins[i]->xPos, gob_goblins[i]->yPos, 0); + _vm->_scenery->updateAnim(layer, 0, _vm->_goblin->goblins[i]->animation, 0, + _vm->_goblin->goblins[i]->xPos, _vm->_goblin->goblins[i]->yPos, 0); - gob_goblins[i]->yPos = (gob_gobPositions[i].y + 1) * 6 - - (scen_toRedrawBottom - scen_animTop); + _vm->_goblin->goblins[i]->yPos = (_vm->_goblin->gobPositions[i].y + 1) * 6 - + (_vm->_scenery->toRedrawBottom - _vm->_scenery->animTop); - gob_goblins[i]->xPos = gob_gobPositions[i].x * 12 - - (scen_toRedrawLeft - scen_animLeft); + _vm->_goblin->goblins[i]->xPos = _vm->_goblin->gobPositions[i].x * 12 - + (_vm->_scenery->toRedrawLeft - _vm->_scenery->animLeft); - gob_goblins[i]->order = scen_toRedrawBottom / 24 + 3; + _vm->_goblin->goblins[i]->order = _vm->_scenery->toRedrawBottom / 24 + 3; } - gob_currentGoblin = 0; - gob_pressedMapX = gob_gobPositions[0].x; - gob_pressedMapY = gob_gobPositions[0].y; - gob_pathExistence = 0; + _vm->_goblin->currentGoblin = 0; + _vm->_goblin->pressedMapX = _vm->_goblin->gobPositions[0].x; + _vm->_goblin->pressedMapY = _vm->_goblin->gobPositions[0].y; + _vm->_goblin->pathExistence = 0; - gob_goblins[0]->doAnim = 0; - gob_goblins[1]->doAnim = 1; - gob_goblins[2]->doAnim = 1; + _vm->_goblin->goblins[0]->doAnim = 0; + _vm->_goblin->goblins[1]->doAnim = 1; + _vm->_goblin->goblins[2]->doAnim = 1; } } // End of namespace Gob |