diff options
Diffstat (limited to 'engines/cruise')
-rw-r--r-- | engines/cruise/cruise_main.cpp | 170 | ||||
-rw-r--r-- | engines/cruise/cruise_main.h | 2 | ||||
-rw-r--r-- | engines/cruise/function.cpp | 8 | ||||
-rw-r--r-- | engines/cruise/linker.cpp | 40 | ||||
-rw-r--r-- | engines/cruise/overlay.cpp | 47 | ||||
-rw-r--r-- | engines/cruise/overlay.h | 2 | ||||
-rw-r--r-- | engines/cruise/saveload.cpp | 4 | ||||
-rw-r--r-- | engines/cruise/script.cpp | 2 | ||||
-rw-r--r-- | engines/cruise/vars.cpp | 2 | ||||
-rw-r--r-- | engines/cruise/vars.h | 2 |
10 files changed, 124 insertions, 155 deletions
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp index 70f2bbcbd0..f076fcc0d6 100644 --- a/engines/cruise/cruise_main.cpp +++ b/engines/cruise/cruise_main.cpp @@ -79,7 +79,7 @@ void loadPakedFileToMem(int fileIdx, uint8 *buffer) { currentVolumeFile.read(buffer, volumePtrToFileDescriptor[fileIdx].size); } -int loadScriptSub1(int scriptIdx, int param) { +int getNumObjectsByClass(int scriptIdx, int param) { objDataStruct *ptr2; int counter; int i; @@ -98,7 +98,7 @@ int loadScriptSub1(int scriptIdx, int param) { counter = 0; for (i = 0; i < overlayTable[scriptIdx].ovlData->numObj; i++) { - if (ptr2[i]._type == param) { + if (ptr2[i]._class == param) { counter++; } } @@ -442,7 +442,7 @@ int initAllData(void) { setupOpcodeTable(); initOverlayTable(); - setup1 = 0; + stateID = 0; currentActiveBackgroundPlane = 0; freeDisk(); @@ -625,114 +625,113 @@ int findObject(int mouseX, int mouseY, int *outObjOvl, int *outObjIdx) { cellStruct *currentObject = cellHead.prev; while (currentObject) { - if (currentObject->overlay >= 0 && overlayTable[currentObject->overlay].alreadyLoaded && (currentObject->type == OBJ_TYPE_SPRITE || currentObject->type == OBJ_TYPE_MASK || currentObject->type == OBJ_TYPE_EXIT || currentObject->type == OBJ_TYPE_VIRTUEL)) { + if (currentObject->overlay > 0 && overlayTable[currentObject->overlay].alreadyLoaded && (currentObject->type == OBJ_TYPE_SPRITE || currentObject->type == OBJ_TYPE_MASK || currentObject->type == OBJ_TYPE_EXIT || currentObject->type == OBJ_TYPE_VIRTUEL)) { const char* pObjectName = getObjectName(currentObject->idx, overlayTable[currentObject->overlay].ovlData->arrayNameObj); - if (pObjectName) { - strcpy(objectName, pObjectName); - if (strlen(objectName) && (currentObject->freeze == 0)) { - int objIdx = currentObject->idx; - int objOvl = currentObject->overlay; - int linkedObjIdx = currentObject->followObjectIdx; - int linkedObjOvl = currentObject->followObjectOverlayIdx; + strcpy(objectName, pObjectName); - objectParamsQuery params; - getMultipleObjectParam(objOvl, objIdx, ¶ms); + if (strlen(objectName) && (currentObject->freeze == 0)) { + int objIdx = currentObject->idx; + int objOvl = currentObject->overlay; + int linkedObjIdx = currentObject->followObjectIdx; + int linkedObjOvl = currentObject->followObjectOverlayIdx; - int x2 = 0; - int y2 = 0; - int j2 = 0; + objectParamsQuery params; + getMultipleObjectParam(objOvl, objIdx, ¶ms); - if ((objOvl != linkedObjOvl) || (objIdx != linkedObjIdx)) { - getMultipleObjectParam(linkedObjOvl, linkedObjIdx, ¶ms); + int x2 = 0; + int y2 = 0; + int j2 = 0; - x2 = params.X; - y2 = params.Y; - j2 = params.fileIdx; - } + if ((objOvl != linkedObjOvl) || (objIdx != linkedObjIdx)) { + getMultipleObjectParam(linkedObjOvl, linkedObjIdx, ¶ms); - if (params.var5 >= 0 && params.fileIdx >= 0) { - if (currentObject->type == OBJ_TYPE_SPRITE || currentObject->type == OBJ_TYPE_MASK || currentObject->type == OBJ_TYPE_EXIT) { - int x = params.X + x2; - int y = params.Y + y2; - int j = params.fileIdx; + x2 = params.X; + y2 = params.Y; + j2 = params.fileIdx; + } - if (j >= 0) { - j += j2; - } + if (params.var5 >= 0 && params.fileIdx >= 0) { + if (currentObject->type == OBJ_TYPE_SPRITE || currentObject->type == OBJ_TYPE_MASK || currentObject->type == OBJ_TYPE_EXIT) { + int x = params.X + x2; + int y = params.Y + y2; + int j = params.fileIdx; - if ((filesDatabase[j].subData.resourceType == OBJ_TYPE_POLY) && (filesDatabase[j].subData.ptr)) { - int zoom = params.scale; + if (j >= 0) { + j += j2; + } - int16* dataPtr = (int16*)filesDatabase[j].subData.ptr; + if ((filesDatabase[j].subData.resourceType == OBJ_TYPE_POLY) && (filesDatabase[j].subData.ptr)) { + int zoom = params.scale; - if (*dataPtr == 0) { - int16 offset; - int16 newX; - int16 newY; + int16* dataPtr = (int16*)filesDatabase[j].subData.ptr; - dataPtr ++; + if (*dataPtr == 0) { + int16 offset; + int16 newX; + int16 newY; - offset = *(dataPtr++); - flipShort(&offset); + dataPtr ++; - newX = *(dataPtr++); - flipShort(&newX); + offset = *(dataPtr++); + flipShort(&offset); - newY = *(dataPtr++); - flipShort(&newY); + newX = *(dataPtr++); + flipShort(&newX); - offset += j; + newY = *(dataPtr++); + flipShort(&newY); - if (offset >= 0 ) { - if (filesDatabase[offset].resType == 0 && filesDatabase[offset].subData.ptr) { - dataPtr = (int16 *)filesDatabase[offset].subData.ptr; - } - } + offset += j; - zoom = -zoom; - x -= newX; - y -= newY; + if (offset >= 0 ) { + if (filesDatabase[offset].resType == 0 && filesDatabase[offset].subData.ptr) { + dataPtr = (int16 *)filesDatabase[offset].subData.ptr; + } } - if (dataPtr && findPoly((char*)dataPtr, x, y, zoom, mouseX, mouseY)) { - *outObjOvl = objOvl; - *outObjIdx = objIdx; + zoom = -zoom; + x -= newX; + y -= newY; + } - return (currentObject->type); - } - } else { - // int numBitPlanes = filesDatabase[j].resType; + if (dataPtr && findPoly((char*)dataPtr, x, y, zoom, mouseX, mouseY)) { + *outObjOvl = objOvl; + *outObjIdx = objIdx; - int nWidth; - int nHeight; + return (currentObject->type); + } + } else { + // int numBitPlanes = filesDatabase[j].resType; - nWidth = filesDatabase[j].width; - nHeight = filesDatabase[j].height; + int nWidth; + int nHeight; - int offsetX = mouseX - x; - int offsetY = mouseY - y; + nWidth = filesDatabase[j].width; + nHeight = filesDatabase[j].height; - if ((offsetX >= 0) && (offsetX < nWidth) && (offsetY >= 0) && (offsetY <= nHeight) && filesDatabase[j].subData.ptr) { - if(testMask(offsetX, offsetY, filesDatabase[j].subData.ptrMask, filesDatabase[j].width/8)) { - *outObjOvl = objOvl; - *outObjIdx = objIdx; - return currentObject->type; - } + int offsetX = mouseX - x; + int offsetY = mouseY - y; + + if ((offsetX >= 0) && (offsetX < nWidth) && (offsetY >= 0) && (offsetY <= nHeight) && filesDatabase[j].subData.ptr) { + if(testMask(offsetX, offsetY, filesDatabase[j].subData.ptrMask, filesDatabase[j].width/8)) { + *outObjOvl = objOvl; + *outObjIdx = objIdx; + return currentObject->type; } } - } else if (currentObject->type == OBJ_TYPE_VIRTUEL) { - int x = params.X + x2; - int y = params.Y + y2; - int width = params.fileIdx; - int height = params.scale; + } + } else if (currentObject->type == OBJ_TYPE_VIRTUEL) { + int x = params.X + x2; + int y = params.Y + y2; + int width = params.fileIdx; + int height = params.scale; - if ((mouseX >= x) && (mouseX <= x+width) && (mouseY >= y) && (mouseY <= y+height)) { - *outObjOvl = objOvl; - *outObjIdx = objIdx; + if ((mouseX >= x) && (mouseX <= x+width) && (mouseY >= y) && (mouseY <= y+height)) { + *outObjOvl = objOvl; + *outObjIdx = objIdx; - return (currentObject->type); - } + return (currentObject->type); } } } @@ -872,8 +871,7 @@ bool findRelation(int objOvl, int objIdx, int x, int y) { if (overlayTable[j].alreadyLoaded) { int idHeader = overlayTable[j].ovlData->numMsgRelHeader; - int i; - for (i=0; i<idHeader; i++) { + for (int i=0; i<idHeader; i++) { linkDataStruct* ptrHead = &overlayTable[j].ovlData->arrayMsgRelHeader[i]; int thisOvl = ptrHead->obj1Overlay; @@ -883,7 +881,7 @@ bool findRelation(int objOvl, int objIdx, int x, int y) { objDataStruct* pObject = getObjectDataFromOverlay(thisOvl, ptrHead->obj1Number); - if ((thisOvl == objOvl) && (objIdx ==ptrHead->obj1Number) && pObject && pObject->_class != 3) { + if ((thisOvl == objOvl) && (objIdx == ptrHead->obj1Number) && pObject && (pObject->_class != THEME)) { int verbeOvl = ptrHead->verbOverlay; int obj1Ovl = ptrHead->obj1Overlay; int obj2Ovl = ptrHead->obj2Overlay; @@ -922,7 +920,7 @@ bool findRelation(int objOvl, int objIdx, int x, int y) { if ((ovl3) && (ptrHead->obj1Number >= 0)) { testState = ptrHead->obj1OldState; - if ((first) && (ovl3->arrayNameObj) && ((testState ==-1) || (testState == objectState))) { + if ((first) && (ovl3->arrayNameObj) && ((testState == -1) || (testState == objectState))) { const char *ptrName = getObjectName(ptrHead->obj1Number, ovl3->arrayNameObj); menuTable[0] = createMenu(x, y, ptrName); diff --git a/engines/cruise/cruise_main.h b/engines/cruise/cruise_main.h index e56862fdec..7e58bda57a 100644 --- a/engines/cruise/cruise_main.h +++ b/engines/cruise/cruise_main.h @@ -93,7 +93,7 @@ void printInfoBlackBox(const char *string); void waitForPlayerInput(void); int loadCtp(const char * ctpName); void loadPakedFileToMem(int fileIdx, uint8 * buffer); -int loadScriptSub1(int scriptIdx, int param); +int getNumObjectsByClass(int scriptIdx, int param); void resetFileEntryRange(int param1, int param2); int getProcParam(int overlayIdx, int param2, const char * name); void changeScriptParamInList(int param1, int param2, scriptInstanceStruct * pScriptInstance, int newValue, int param3); diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp index 74984289a0..b05d80874d 100644 --- a/engines/cruise/function.cpp +++ b/engines/cruise/function.cpp @@ -30,6 +30,8 @@ namespace Cruise { +//#define FUNCTION_DEBUG + opcodeFunction opcodeTablePtr[256]; int16 Op_LoadOverlay(void) { @@ -521,6 +523,10 @@ int16 Op_InitializeState(void) { if (!ovlIdx) ovlIdx = currentScriptPtr->overlayNumber; +#ifdef FUNCTION_DEBUG + printf("Init %s state to %d\n", getObjectName(objIdx, overlayTable[ovlIdx].ovlData->arrayNameObj), param1); +#endif + objInit(ovlIdx, objIdx, param1); return (0); @@ -1582,7 +1588,7 @@ int32 opcodeType8(void) { return (-21); if (opcodeTablePtr[opcode]) { - printf("Function: %d\n",opcode); + // printf("Function: %d\n",opcode); pushVar(opcodeTablePtr[opcode] ()); return (0); } else { diff --git a/engines/cruise/linker.cpp b/engines/cruise/linker.cpp index c2cb16b028..748a5f6053 100644 --- a/engines/cruise/linker.cpp +++ b/engines/cruise/linker.cpp @@ -250,49 +250,31 @@ int updateScriptImport(int ovlIdx) { int linkType; int linkEntryIdx; - strcpy(buffer, - ovlData->arrayNameRelocGlob + - ovlData->arrayRelocGlob[i].nameOffset); + strcpy(buffer, ovlData->arrayNameRelocGlob + ovlData->arrayRelocGlob[i].nameOffset); - pFoundExport = - parseExport(&out1, &foundExportIdx, buffer); + pFoundExport = parseExport(&out1, &foundExportIdx, buffer); linkType = ovlData->arrayRelocGlob[i].linkType; linkEntryIdx = ovlData->arrayRelocGlob[i].linkIdx; if (pFoundExport && foundExportIdx) { switch (linkType) { - case 0: // var + case 0: // verb { - ovlData-> - arrayMsgRelHeader[linkEntryIdx]. - verbOverlay = foundExportIdx; - ovlData-> - arrayMsgRelHeader[linkEntryIdx]. - verbNumber = - pFoundExport->offsetToName; + ovlData->arrayMsgRelHeader[linkEntryIdx].verbOverlay = foundExportIdx; + ovlData->arrayMsgRelHeader[linkEntryIdx].verbNumber = pFoundExport->idx; break; } - case 1: // string + case 1: // obj1 { - ovlData-> - arrayMsgRelHeader[linkEntryIdx]. - obj1Overlay = foundExportIdx; - ovlData-> - arrayMsgRelHeader[linkEntryIdx]. - obj1Number = - pFoundExport->offsetToName; + ovlData->arrayMsgRelHeader[linkEntryIdx].obj1Overlay = foundExportIdx; + ovlData->arrayMsgRelHeader[linkEntryIdx].obj1Number = pFoundExport->idx; break; } - case 2: // proc + case 2: // obj2 { - ovlData-> - arrayMsgRelHeader[linkEntryIdx]. - obj2Overlay = foundExportIdx; - ovlData-> - arrayMsgRelHeader[linkEntryIdx]. - obj2Number = - pFoundExport->offsetToName; + ovlData->arrayMsgRelHeader[linkEntryIdx].obj2Overlay = foundExportIdx; + ovlData->arrayMsgRelHeader[linkEntryIdx].obj2Number = pFoundExport->idx; break; } } diff --git a/engines/cruise/overlay.cpp b/engines/cruise/overlay.cpp index 29079d7d9e..73ca422bd3 100644 --- a/engines/cruise/overlay.cpp +++ b/engines/cruise/overlay.cpp @@ -170,8 +170,7 @@ int loadOverlay(const char *scriptName) { if (ovlData->numSymbGlob) { // export data int i; ovlData->arraySymbGlob = - (exportEntryStruct *) mallocAndZero(ovlData->numSymbGlob * - sizeof(exportEntryStruct)); + (exportEntryStruct *) mallocAndZero(ovlData->numSymbGlob * sizeof(exportEntryStruct)); if (!ovlData->arraySymbGlob) { return (-2); @@ -179,13 +178,10 @@ int loadOverlay(const char *scriptName) { for (i = 0; i < ovlData->numSymbGlob; i++) { ovlData->arraySymbGlob[i].var0 = readB16(scriptPtr); - ovlData->arraySymbGlob[i].var2 = - readB16(scriptPtr + 2); - ovlData->arraySymbGlob[i].var4 = - readB16(scriptPtr + 4); + ovlData->arraySymbGlob[i].var2 = readB16(scriptPtr + 2); + ovlData->arraySymbGlob[i].var4 = readB16(scriptPtr + 4); ovlData->arraySymbGlob[i].idx = readB16(scriptPtr + 6); - ovlData->arraySymbGlob[i].offsetToName = - readB16(scriptPtr + 8); + ovlData->arraySymbGlob[i].offsetToName = readB16(scriptPtr + 8); scriptPtr += 10; } @@ -215,14 +211,10 @@ int loadOverlay(const char *scriptName) { for (i = 0; i < ovlData->numRelocGlob; i++) { ovlData->arrayRelocGlob[i].var0 = readB16(scriptPtr); - ovlData->arrayRelocGlob[i].var1 = - readB16(scriptPtr + 2); - ovlData->arrayRelocGlob[i].linkType = - readB16(scriptPtr + 4); - ovlData->arrayRelocGlob[i].linkIdx = - readB16(scriptPtr + 6); - ovlData->arrayRelocGlob[i].nameOffset = - readB16(scriptPtr + 8); + ovlData->arrayRelocGlob[i].var1 = readB16(scriptPtr + 2); + ovlData->arrayRelocGlob[i].linkType = readB16(scriptPtr + 4); + ovlData->arrayRelocGlob[i].linkIdx = readB16(scriptPtr + 6); + ovlData->arrayRelocGlob[i].nameOffset = readB16(scriptPtr + 8); scriptPtr += 10; } @@ -243,19 +235,15 @@ int loadOverlay(const char *scriptName) { if (ovlData->numMsgRelHeader) { // link data ASSERT(sizeof(linkDataStruct) == 0x22); - ovlData->arrayMsgRelHeader = - (linkDataStruct *) mallocAndZero(ovlData->numMsgRelHeader * - sizeof(linkDataStruct)); + ovlData->arrayMsgRelHeader = (linkDataStruct *) mallocAndZero(ovlData->numMsgRelHeader * sizeof(linkDataStruct)); if (!ovlData->arrayMsgRelHeader) { return (-2); } - memcpy(ovlData->arrayMsgRelHeader, scriptPtr, - ovlData->numMsgRelHeader * sizeof(linkDataStruct)); + memcpy(ovlData->arrayMsgRelHeader, scriptPtr, ovlData->numMsgRelHeader * sizeof(linkDataStruct)); scriptPtr += ovlData->numMsgRelHeader * sizeof(linkDataStruct); - flipGen(ovlData->arrayMsgRelHeader, - ovlData->numMsgRelHeader * sizeof(linkDataStruct)); + flipGen(ovlData->arrayMsgRelHeader, ovlData->numMsgRelHeader * sizeof(linkDataStruct)); } if (ovlData->numProc) { // script @@ -430,16 +418,11 @@ int loadOverlay(const char *scriptName) { flipShort(&ovlData->arrayObject[i]._stateTableIdx); } - if (scriptNotLoadedBefore) { - //int var1; - //int var2; - - overlayTable[scriptIdx].state = (char)setup1; + // allocte states for object with multiple states - var1 = loadScriptSub1(scriptIdx, 3); - var2 = loadScriptSub1(scriptIdx, 0); - - setup1 = var1 + var2; + if (scriptNotLoadedBefore) { + overlayTable[scriptIdx].state = stateID; + stateID += getNumObjectsByClass(scriptIdx, MULTIPLE) + getNumObjectsByClass(scriptIdx, THEME); } } diff --git a/engines/cruise/overlay.h b/engines/cruise/overlay.h index 426ef8b895..7d8b2051e1 100644 --- a/engines/cruise/overlay.h +++ b/engines/cruise/overlay.h @@ -88,7 +88,7 @@ struct linkDataStruct { int16 obj2OldState; int16 trackDirection; - int16 field_20; + int16 dialog; }; struct importDataStruct { diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp index 9f33b1a3ac..8e30909ae4 100644 --- a/engines/cruise/saveload.cpp +++ b/engines/cruise/saveload.cpp @@ -270,7 +270,7 @@ int loadSavegameData(int saveGameIdx) { var22 = currentSaveFile.readSint16LE(); main5 = currentSaveFile.readSint16LE(); numOfLoadedOverlay = currentSaveFile.readSint16LE(); - setup1 = currentSaveFile.readSint16LE(); + stateID = currentSaveFile.readSint16LE(); fontFileIndex = currentSaveFile.readSint16LE(); currentActiveMenu = currentSaveFile.readSint16LE(); userWait = currentSaveFile.readSint16LE(); @@ -304,7 +304,7 @@ int loadSavegameData(int saveGameIdx) { currentSaveFile.read(palette, 256*2); currentSaveFile.read(initVar5, 24); - currentSaveFile.read(globalVars, setup1 * 2); // ok + currentSaveFile.read(globalVars, stateID * 2); // ok for(int i=0; i<257; i++) { filesDatabase[i].widthInColumn = currentSaveFile.readUint16LE(); diff --git a/engines/cruise/script.cpp b/engines/cruise/script.cpp index 16adef5135..11be0dcc67 100644 --- a/engines/cruise/script.cpp +++ b/engines/cruise/script.cpp @@ -727,7 +727,7 @@ int executeScripts(scriptInstanceStruct *ptr) { } opcodeType = getByteFromScript(); - printf("opType: %d\n",(opcodeType&0xFB)>>3); + // printf("opType: %d\n",(opcodeType&0xFB)>>3); currentScriptOpcodeType = opcodeType & 7; diff --git a/engines/cruise/vars.cpp b/engines/cruise/vars.cpp index 42fc7ad3d6..36bf02a3a4 100644 --- a/engines/cruise/vars.cpp +++ b/engines/cruise/vars.cpp @@ -91,7 +91,7 @@ int16 positionInStack; actorStruct actorHead; -int16 setup1; +int16 stateID; uint8 *currentData3DataPtr; uint8 *scriptDataPtrTable[7]; diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h index 0d0e507a56..886fe10470 100644 --- a/engines/cruise/vars.h +++ b/engines/cruise/vars.h @@ -184,7 +184,7 @@ extern opcodeTypeFunction opcodeTypeTable[64]; extern int16 positionInStack; extern actorStruct actorHead; -extern int16 setup1; +extern int16 stateID; extern uint8 *currentData3DataPtr; extern uint8 *scriptDataPtrTable[7]; |