aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/cruise/cruise_main.cpp36
-rw-r--r--engines/cruise/object.cpp84
-rw-r--r--engines/cruise/overlay.cpp29
-rw-r--r--engines/cruise/overlay.h25
-rw-r--r--engines/cruise/saveload.cpp61
-rw-r--r--engines/cruise/vars.cpp3
-rw-r--r--engines/cruise/vars.h8
7 files changed, 132 insertions, 114 deletions
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index 5d220bc818..399704f350 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -98,7 +98,7 @@ int loadScriptSub1(int scriptIdx, int param) {
counter = 0;
for (i = 0; i < overlayTable[scriptIdx].ovlData->numObj; i++) {
- if (ptr2[i].var0 == param) {
+ if (ptr2[i]._type == param) {
counter++;
}
}
@@ -764,45 +764,49 @@ void *allocAndZero(int size) {
}
const char *getObjectName(int index, const char *string) {
- int i;
const char *ptr = string;
if (!string)
return NULL;
- for (i = 0; i < index; i++) {
- while (*ptr) {
- ptr++;
- }
- ptr++;
+ int i = 0;
+ int j = 0;
+
+ while (i < index)
+ {
+ ptr += strlen(ptr)+1;
+ i++;
}
return ptr;
}
-int buildInventorySub1(int overlayIdx, int objIdx) {
+int getObjectClass(int overlayIdx, int objIdx) {
objDataStruct *pObjectData = getObjectDataFromOverlay(overlayIdx, objIdx);
if (pObjectData) {
- return pObjectData->type;
+ return pObjectData->_class;
} else {
return -11;
}
}
void buildInventory(int X, int Y) {
- int numObjectInInventory = 0;
menuStruct *pMenu;
pMenu = createMenu(X, Y, "Inventaire");
menuTable[1] = pMenu;
- if (pMenu && numOfLoadedOverlay > 1) {
- for (int i = 1; i < numOfLoadedOverlay; i++) {
- ovlDataStruct *pOvlData = overlayTable[i].ovlData;
+ if(pMenu == NULL)
+ return;
+
+ int numObjectInInventory = 0;
+ for (int i = 1; i < numOfLoadedOverlay; i++) {
+ ovlDataStruct *pOvlData = overlayTable[i].ovlData;
- if (pOvlData && pOvlData->arrayObject && pOvlData->numObj) {
+ if (overlayTable[i].alreadyLoaded) {
+ if(overlayTable[i].ovlData->arrayObject) {
for (int j = 0; j < pOvlData->numObj; j++) {
- if (buildInventorySub1(i, j) != 3) {
+ if (getObjectClass(i, j) != 3) {
int16 returnVar;
getSingleObjectParam(i, j, 5, &returnVar);
@@ -879,7 +883,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->type != 3) {
+ if ((thisOvl == objOvl) && (objIdx ==ptrHead->obj1Number) && pObject && pObject->_class != 3) {
int verbeOvl = ptrHead->verbOverlay;
int obj1Ovl = ptrHead->obj1Overlay;
int obj2Ovl = ptrHead->obj2Overlay;
diff --git a/engines/cruise/object.cpp b/engines/cruise/object.cpp
index 990fdf4c9b..79caf06986 100644
--- a/engines/cruise/object.cpp
+++ b/engines/cruise/object.cpp
@@ -58,14 +58,14 @@ objDataStruct *getObjectDataFromOverlay(int ovlIdx, int objIdx) {
}
int16 getMultipleObjectParam(int16 overlayIdx, int16 objectIdx, objectParamsQuery *returnParam) {
- int16 size;
- int16 var_A;
- int16 var_14;
objectParams *ptr2;
objDataStruct *ptr;
ovlDataStruct *ovlData;
// int16 type;
+ int state = 0;
+ int state2 = 0;
+
ptr = getObjectDataFromOverlay(overlayIdx, objectIdx);
if (!ptr)
@@ -73,32 +73,32 @@ int16 getMultipleObjectParam(int16 overlayIdx, int16 objectIdx, objectParamsQuer
ovlData = overlayTable[overlayIdx].ovlData;
- switch (ptr->type) {
- case 0:
+ switch (ptr->_class) {
+ case THEME:
+ case MULTIPLE:
{
- ptr2 = &ovlData->arrayStates[ptr->var5];
-
- var_14 = globalVars[*(int16 *) (&overlayTable[overlayIdx].state + ptr->stateTableIdx)];
-
- var_A = ptr2->state;
+ state = globalVars[overlayTable[overlayIdx].state + ptr->_stateTableIdx];
+ ptr2 = &ovlData->arrayStates[ptr->_firstStateIdx + state];
+ state2 = ptr2->state;
break;
}
- case 1:
+ case VARIABLE:
{
- ptr2 = &ovlData->arrayObjVar[ptr->var4];
-
- var_A = var_14 = ptr2->state;
- size = var_A + ptr->var5;
-
- if (ptr->var5 + var_14 <= ovlData->size8) {
- var_A = ovlData->arrayStates[ptr->var5 + var_14].state;
+ ptr2 = &ovlData->arrayObjVar[ptr->_varTableIdx];
+
+ state = ptr2->state;
+ state2 = state;
+ if(ptr->_firstStateIdx + state < ovlData->size8)
+ {
+ objectParams *ptr3 = &ovlData->arrayStates[ptr->_firstStateIdx + state];
+ state2 = ptr3->state;
}
break;
}
default:
{
- printf("unsupported case %d in getMultipleObjectParam\n", ptr->type);
+ printf("Unsupported case %d in getMultipleObjectParam\n",ptr->_class);
exit(1);
}
}
@@ -108,9 +108,9 @@ int16 getMultipleObjectParam(int16 overlayIdx, int16 objectIdx, objectParamsQuer
returnParam->baseFileIdx = ptr2->Z;
returnParam->fileIdx = ptr2->frame;
returnParam->scale = ptr2->scale;
- returnParam->var5 = var_14;
- returnParam->var6 = var_A;
- returnParam->var7 = ptr->var3;
+ returnParam->var5 = state;
+ returnParam->var6 = state2;
+ returnParam->var7 = ptr->_numStates;
return 0;
}
@@ -127,10 +127,10 @@ void setObjectPosition(int16 ovlIdx, int16 objIdx, int16 param3, int16 param4) {
}
//overlayTable[param1].ovlData
- switch (ptr->type) {
+ switch (ptr->_class) {
case 1:
{
- ptr2 = &overlayTable[ovlIdx].ovlData->arrayObjVar[ptr->var4];
+ ptr2 = &overlayTable[ovlIdx].ovlData->arrayObjVar[ptr->_varTableIdx];
switch (param3) {
case 0: // x
@@ -159,7 +159,7 @@ void setObjectPosition(int16 ovlIdx, int16 objIdx, int16 param3, int16 param4) {
ptr2->scale = param4;
break;
}
- case 5: // box colision
+ case 5: // state
{
ptr2->state = param4;
break;
@@ -191,11 +191,11 @@ int16 objInit(int ovlIdx, int objIdx, int newState) {
ovlData = overlayTable[ovlIdx].ovlData;
- switch (ptr->type) {
+ switch (ptr->_class) {
case THEME:
case MULTIPLE:
{
- globalVars[overlayTable[ovlIdx].state + ptr->stateTableIdx] = newState;
+ globalVars[overlayTable[ovlIdx].state + ptr->_stateTableIdx] = newState;
sortCells(ovlIdx, objIdx, &cellHead);
break;
}
@@ -206,12 +206,12 @@ int16 objInit(int ovlIdx, int objIdx, int newState) {
objectParams *destEntry;
objectParams *sourceEntry;
- if (ptr->var5 + newState > ovlData->size8) {
+ if (ptr->_firstStateIdx + newState > ovlData->size8) {
return 0;
}
- destEntry = &ovlData->arrayObjVar[ptr->var4];
- sourceEntry = &ovlData->arrayStates[ptr->var5 + newState];
+ destEntry = &ovlData->arrayObjVar[ptr->_varTableIdx];
+ sourceEntry = &ovlData->arrayStates[ptr->_firstStateIdx + newState];
memcpy(destEntry, sourceEntry, sizeof(objectParams));
@@ -222,7 +222,7 @@ int16 objInit(int ovlIdx, int objIdx, int newState) {
}
default:
{
- printf("Unsupported param = %d in objInit\n", ptr->type);
+ printf("Unsupported param = %d in objInit\n", ptr->_class);
// exit(1);
}
}
@@ -231,7 +231,7 @@ int16 objInit(int ovlIdx, int objIdx, int newState) {
}
int16 getSingleObjectParam(int16 overlayIdx, int16 param2, int16 param3, int16 *returnParam) {
- int var_A = 0;
+ int state = 0;
//char* ptr3 = NULL;
objDataStruct *ptr;
ovlDataStruct *ovlData;
@@ -244,25 +244,25 @@ int16 getSingleObjectParam(int16 overlayIdx, int16 param2, int16 param3, int16 *
ovlData = overlayTable[overlayIdx].ovlData;
- switch (ptr->type) {
- case 0:
- case 3:
+ switch (ptr->_class) {
+ case THEME:
+ case MULTIPLE:
{
- var_A = globalVars[ptr->stateTableIdx];
+ state = globalVars[overlayTable[overlayIdx].state + ptr->_stateTableIdx];
- ptr2 = &ovlData->arrayStates[ptr->var5];
+ ptr2 = &ovlData->arrayStates[ptr->_firstStateIdx + state];
break;
}
- case 1:
+ case VARIABLE:
{
- ptr2 = &ovlData->arrayObjVar[ptr->var4];
+ ptr2 = &ovlData->arrayObjVar[ptr->_varTableIdx];
- var_A = ptr2->state;
+ state = ptr2->state;
break;
}
default:
{
- printf("Unsupported case %d in getSingleObjectParam\n",ptr->type);
+ printf("Unsupported case %d in getSingleObjectParam\n",ptr->_class);
exit(1);
}
}
@@ -295,7 +295,7 @@ int16 getSingleObjectParam(int16 overlayIdx, int16 param2, int16 param3, int16 *
}
case 5:
{
- *returnParam = var_A;
+ *returnParam = state;
break;
}
default:
diff --git a/engines/cruise/overlay.cpp b/engines/cruise/overlay.cpp
index e0db30bab2..29079d7d9e 100644
--- a/engines/cruise/overlay.cpp
+++ b/engines/cruise/overlay.cpp
@@ -400,33 +400,34 @@ int loadOverlay(const char *scriptName) {
}
for (i = 0; i < ovlData->numObj; i++) {
- ovlData->arrayObject[i].var0 = *(int16 *) scriptPtr;
+ ovlData->arrayObject[i]._type = *(int16 *) scriptPtr;
scriptPtr += 2;
- flipShort(&ovlData->arrayObject[i].var0);
+ flipShort(&ovlData->arrayObject[i]._type);
- ovlData->arrayObject[i].type = *(int16 *) scriptPtr;
+ int16 tempClass = *(int16 *) scriptPtr;
+ flipShort(&tempClass);
+ ovlData->arrayObject[i]._class = (eClass)tempClass;
scriptPtr += 2;
- flipShort(&ovlData->arrayObject[i].type);
- ovlData->arrayObject[i].var2 = *(int16 *) scriptPtr;
+ ovlData->arrayObject[i]._nameOffset = *(int16 *) scriptPtr;
scriptPtr += 2;
- flipShort(&ovlData->arrayObject[i].var2);
+ flipShort(&ovlData->arrayObject[i]._nameOffset);
- ovlData->arrayObject[i].var3 = *(int16 *) scriptPtr;
+ ovlData->arrayObject[i]._numStates = *(int16 *) scriptPtr;
scriptPtr += 2;
- flipShort(&ovlData->arrayObject[i].var3);
+ flipShort(&ovlData->arrayObject[i]._numStates);
- ovlData->arrayObject[i].var4 = *(int16 *) scriptPtr;
+ ovlData->arrayObject[i]._varTableIdx = *(int16 *) scriptPtr;
scriptPtr += 2;
- flipShort(&ovlData->arrayObject[i].var4);
+ flipShort(&ovlData->arrayObject[i]._varTableIdx);
- ovlData->arrayObject[i].var5 = *(int16 *) scriptPtr;
+ ovlData->arrayObject[i]._firstStateIdx = *(int16 *) scriptPtr;
scriptPtr += 2;
- flipShort(&ovlData->arrayObject[i].var5);
+ flipShort(&ovlData->arrayObject[i]._firstStateIdx);
- ovlData->arrayObject[i].stateTableIdx = *(int16 *) scriptPtr;
+ ovlData->arrayObject[i]._stateTableIdx = *(int16 *) scriptPtr;
scriptPtr += 2;
- flipShort(&ovlData->arrayObject[i].stateTableIdx);
+ flipShort(&ovlData->arrayObject[i]._stateTableIdx);
}
if (scriptNotLoadedBefore) {
diff --git a/engines/cruise/overlay.h b/engines/cruise/overlay.h
index 14da8f41ef..2685e94c41 100644
--- a/engines/cruise/overlay.h
+++ b/engines/cruise/overlay.h
@@ -99,19 +99,22 @@ struct importDataStruct {
uint16 nameOffset;
};
-#define MULTIPLE 0
-#define VARIABLE 1
-#define UNIQUE 2
-#define THEME 3
+enum eClass
+{
+ MULTIPLE = 0,
+ VARIABLE = 1,
+ UNIQUE = 2,
+ THEME = 3,
+};
struct objDataStruct {
- int16 var0;
- int16 type;
- int16 var2;
- int16 var3;
- int16 var4;
- int16 var5;
- int16 stateTableIdx;
+ int16 _type;
+ eClass _class;
+ int16 _nameOffset;
+ int16 _numStates;
+ int16 _varTableIdx;
+ int16 _firstStateIdx;
+ int16 _stateTableIdx;
};
struct objectParams {
diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp
index 9d94045da6..9f33b1a3ac 100644
--- a/engines/cruise/saveload.cpp
+++ b/engines/cruise/saveload.cpp
@@ -27,30 +27,47 @@
namespace Cruise {
+struct overlayRestoreTemporary {
+ int _sBssSize;
+ uint8* _pBss;
+ int _sNumObj;
+ objectParams* _pObj;
+};
+
+overlayRestoreTemporary ovlRestoreData[90];
+
void loadSavegameDataSub1(Common::File& currentSaveFile) {
int i;
for (i = 1; i < numOfLoadedOverlay; i++) {
- filesData[i].field_4 = NULL;
- filesData[i].field_0 = NULL;
- filesData2[i].field_0 = 0;
+ ovlRestoreData[i]._sBssSize = ovlRestoreData[i]._sNumObj = 0;
+ ovlRestoreData[i]._pBss = NULL;
+ ovlRestoreData[i]._pObj = NULL;
if (overlayTable[i].alreadyLoaded) {
- filesData2[i].field_0 = currentSaveFile.readSint16LE();
+ ovlRestoreData[i]._sBssSize = currentSaveFile.readSint16LE();
- if (filesData2[i].field_0) {
- filesData[i].field_0 = (uint8 *) mallocAndZero(filesData2[i].field_0);
- if (filesData[i].field_0) {
- currentSaveFile.read(filesData[i].field_0, filesData2[i].field_0);
- }
+ if (ovlRestoreData[i]._sBssSize) {
+ ovlRestoreData[i]._pBss = (uint8 *) mallocAndZero(ovlRestoreData[i]._sBssSize);
+ ASSERT(ovlRestoreData[i]._pBss);
+
+ currentSaveFile.read(ovlRestoreData[i]._pBss, ovlRestoreData[i]._sBssSize);
}
- filesData2[i].field_2 = currentSaveFile.readSint16LE();
+ ovlRestoreData[i]._sNumObj = currentSaveFile.readSint16LE();
- if (filesData2[i].field_2) {
- filesData[i].field_4 = (uint8 *) mallocAndZero(filesData2[i].field_2 * 12);
- if (filesData[i].field_4) {
- currentSaveFile.read(filesData[i].field_4, filesData2[i].field_2 * 12);
+ if (ovlRestoreData[i]._sNumObj) {
+ ovlRestoreData[i]._pObj = (objectParams *) mallocAndZero(ovlRestoreData[i]._sNumObj * sizeof(objectParams));
+ ASSERT(ovlRestoreData[i]._pObj);
+
+ for(int j=0; j<ovlRestoreData[i]._sNumObj; j++)
+ {
+ ovlRestoreData[i]._pObj[j].X = currentSaveFile.readSint16LE();
+ ovlRestoreData[i]._pObj[j].Y = currentSaveFile.readSint16LE();
+ ovlRestoreData[i]._pObj[j].Z = currentSaveFile.readSint16LE();
+ ovlRestoreData[i]._pObj[j].frame = currentSaveFile.readSint16LE();
+ ovlRestoreData[i]._pObj[j].scale = currentSaveFile.readSint16LE();
+ ovlRestoreData[i]._pObj[j].state = currentSaveFile.readSint16LE();
}
}
}
@@ -355,22 +372,26 @@ int loadSavegameData(int saveGameIdx) {
if (overlayTable[j].alreadyLoaded) {
ovlDataStruct *ovlData = overlayTable[j].ovlData;
- if (filesData[j].field_0) {
+ // overlay BSS
+
+ if (ovlRestoreData[j]._sBssSize) {
if (ovlData->data4Ptr) {
free(ovlData->data4Ptr);
}
- ovlData->data4Ptr = (uint8 *) filesData[j].field_0;
- ovlData->sizeOfData4 = filesData2[j].field_0;
+ ovlData->data4Ptr = ovlRestoreData[j]._pBss;
+ ovlData->sizeOfData4 = ovlRestoreData[j]._sBssSize;
}
- if (filesData[j].field_4) {
+ // overlay object data
+
+ if (ovlRestoreData[j]._sNumObj) {
if (ovlData->arrayObjVar) {
free(ovlData->arrayObjVar);
}
- ovlData->arrayObjVar = (objectParams *) filesData[j].field_4; // TODO: fix !
- ovlData->size9 = filesData2[j].field_2;
+ ovlData->arrayObjVar = ovlRestoreData[j]._pObj;
+ ovlData->size9 = ovlRestoreData[j]._sNumObj;
}
}
diff --git a/engines/cruise/vars.cpp b/engines/cruise/vars.cpp
index 01b28a79d9..42fc7ad3d6 100644
--- a/engines/cruise/vars.cpp
+++ b/engines/cruise/vars.cpp
@@ -43,9 +43,6 @@ int16 currentActiveBackgroundPlane;
int16 main5;
int16 var22 = 0;
-filesDataStruct filesData[90];
-filesData2Struct filesData2[90];
-
mediumVarStruct mediumVar[64];
volumeDataStruct volumeData[20];
diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h
index 6c72d93218..0d0e507a56 100644
--- a/engines/cruise/vars.h
+++ b/engines/cruise/vars.h
@@ -78,11 +78,6 @@ struct mediumVarStruct {
int16 ovl;
};
-struct filesDataStruct {
- uint8 *field_0;
- uint8 *field_4;
-};
-
struct filesData2Struct {
int16 field_0;
int16 field_2;
@@ -142,9 +137,6 @@ struct systemStringsStruct {
char bootScriptName[8];
};
-extern filesDataStruct filesData[90];
-extern filesData2Struct filesData2[90];
-
extern mediumVarStruct mediumVar[64];
extern volumeDataStruct volumeData[20];