aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Hamm2007-12-27 12:05:43 +0000
committerVincent Hamm2007-12-27 12:05:43 +0000
commitf953ed4dde2600da2a4075e29614379a1fb05ea9 (patch)
tree045eb5f8c682d16b28e78de2b71c05d98d852db9
parent410a4a974ef78324ba6d8bd5535b2b46b231b0f7 (diff)
downloadscummvm-rg350-f953ed4dde2600da2a4075e29614379a1fb05ea9.tar.gz
scummvm-rg350-f953ed4dde2600da2a4075e29614379a1fb05ea9.tar.bz2
scummvm-rg350-f953ed4dde2600da2a4075e29614379a1fb05ea9.zip
Early pathfinding
svn-id: r30012
-rw-r--r--engines/cruise/actor.cpp74
-rw-r--r--engines/cruise/cruise.cpp3
-rw-r--r--engines/cruise/cruise_main.cpp7
-rw-r--r--engines/cruise/cruise_main.h2
-rw-r--r--engines/cruise/ctp.cpp351
-rw-r--r--engines/cruise/ctp.h14
-rw-r--r--engines/cruise/font.cpp2
-rw-r--r--engines/cruise/function.cpp44
-rw-r--r--engines/cruise/gfxModule.cpp2
-rw-r--r--engines/cruise/mainDraw.cpp6
-rw-r--r--engines/cruise/saveload.cpp14
-rw-r--r--engines/cruise/vars.cpp13
-rw-r--r--engines/cruise/vars.h15
13 files changed, 216 insertions, 331 deletions
diff --git a/engines/cruise/actor.cpp b/engines/cruise/actor.cpp
index f3245dcf31..ed88c0d089 100644
--- a/engines/cruise/actor.cpp
+++ b/engines/cruise/actor.cpp
@@ -68,40 +68,35 @@ int flag_aff_chemin;
void getPixel(int x, int y) {
int x_min, x_max, y_min, y_max;
- ctpVar19Struct *polygone;
- ctpVar19SubStruct *tableau;
+ int16* polygone = (int16*)polyStruct0;
+ int16* next;
- polygone = ctpVar19; /* adr structure polygone */
+ while ((next = *(int16**)polygone) != (int16 *) -1) {
+ polygone+=sizeof(uint16*);
- while (polygone->field_0 != (ctpVar19Struct *) - 1) {
- tableau = &polygone->subStruct;
+ int16* tableau = polygone+2;
- x_min = tableau->minX;
- x_max = tableau->maxX;
- y_min = tableau->minY;
- y_max = tableau->maxY;
+ x_min = *tableau++;
+ x_max = *tableau++;
+ y_min = *tableau++;
+ y_max = *tableau++;
- computedVar14 = tableau->boxIdx; /* numero polygone */
+ computedVar14 = *polygone++;
- if (walkboxChange[computedVar14] == 0 && ((x >= x_min
- && x <= x_max) && (y >= y_min && y <= y_max))) {
+ if (walkboxState[computedVar14] == 0 && ((x >= x_min && x <= x_max) && (y >= y_min && y <= y_max))) {
// click was in given box
- /* u = y-y_min;
- *
- * //tableau+=u;
- * tableau = &polygone[u].subStruct;
- *
- * x_min = tableau->minX;
- * x_max = tableau->maxX;
- *
- * if ( (x>=x_min && x<=x_max) ) */
- {
- flag_obstacle = walkboxType[computedVar14]; /* sa couleur */
+ int u = y-y_min;
+ tableau+=u*2;
+ x_min = *tableau++;
+ x_max = *tableau++;
+
+ if ( (x>=x_min && x<=x_max) ) {
+ flag_obstacle = walkboxColor[computedVar14];
return;
}
}
- polygone = polygone->field_0;
+ polygone = next;
}
flag_obstacle = 0;
@@ -306,7 +301,7 @@ int point_proche(int16 table[][2]) {
int x1, y1, i, x, y, p;
int d1 = 1000;
- ctpVar19 = ctpVar11;
+ polyStruct0 = polyStructNorm;
if (nclick_noeud == 1) {
x = x_mouse;
@@ -314,19 +309,19 @@ int point_proche(int16 table[][2]) {
x1 = table_ptselect[0][0];
y1 = table_ptselect[0][1];
- ctpVar19 = ctpVar15;
+ polyStruct0 = polyStructExp;
getPixel(x, y);
if (!flag_obstacle) {
- ctpVar19 = ctpVar11;
+ polyStruct0 = polyStructNorm;
getPixel(x, y);
if (flag_obstacle) {
polydroite(x1, y1, x, y);
}
- ctpVar19 = ctpVar15;
+ polyStruct0 = polyStructExp;
}
if (!flag_obstacle) { /* dans flag_obstacle --> couleur du point */
x1 = table_ptselect[0][0];
@@ -338,7 +333,7 @@ int point_proche(int16 table[][2]) {
y_mouse = Y;
}
}
- ctpVar19 = ctpVar11;
+ polyStruct0 = polyStructNorm;
p = -1;
for (i = 0; i < ctp_routeCoordCount; i++) {
@@ -468,7 +463,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
table_ptselect[*nclick][0] = x_mouse;
table_ptselect[*nclick][1] = y_mouse;
(*nclick)++;
- ctpVar19 = ctpVar11;
+ polyStruct0 = polyStructNorm;
if (*nclick == 2) { // second point
x1 = table_ptselect[0][0];
@@ -479,7 +474,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
return;
}
flag_aff_chemin = 1;
- ctpVar19 = ctpVar15;
+ polyStruct0 = polyStructExp;
// can we go there directly ?
polydroite(x1, y1, x2, y2);
@@ -489,7 +484,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
if (!flag_obstacle) {
solution0[0][0] = x1;
solution0[0][1] = y1;
- ctpVar19 = ctpVar15;
+ polyStruct0 = polyStructExp;
poly2(x2, y2, ctp_routeCoords[select_noeud[1]][0],
ctp_routeCoords[select_noeud[1]][1]);
@@ -533,7 +528,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
solution0[++i][1] =
ctp_routeCoords[p1][1];
}
- ctpVar19 = ctpVar15;
+ polyStruct0 = polyStructExp;
poly2(x2, y2,
ctp_routeCoords[select_noeud[1]][0],
ctp_routeCoords[select_noeud[1]][1]);
@@ -558,7 +553,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
while (flag_obstacle && i != d) {
x2 = solution0[i][0];
y2 = solution0[i][1];
- ctpVar19 = ctpVar15;
+ polyStruct0 = polyStructExp;
polydroite(x1, y1, x2, y2);
i--;
}
@@ -597,7 +592,7 @@ int16 computePathfinding(int16 *pSolution, int16 x, int16 y, int16 destX, int16
}
}
- //if (!flagCt)
+ if (!flagCt)
{
int i;
int16 *ptr;
@@ -637,7 +632,7 @@ int16 computePathfinding(int16 *pSolution, int16 x, int16 y, int16 destX, int16
}
nclick_noeud = 0;
- ctpVar19 = ctpVar11;
+ polyStruct0 = polyStructNorm;
flag_aff_chemin = 0;
if (x == destX && y == destY) {
@@ -689,12 +684,9 @@ int16 computePathfinding(int16 *pSolution, int16 x, int16 y, int16 destX, int16
y_mouse = destY;
if ((point_select = point_proche(ctp_routeCoords)) != -1)
- valide_noeud(select_noeud, point_select, &nclick_noeud,
- perso->solution);
+ valide_noeud(select_noeud, point_select, &nclick_noeud, perso->solution);
- if ((!flag_aff_chemin)
- || ((table_ptselect[0][0] == table_ptselect[1][0])
- && (table_ptselect[0][1] == table_ptselect[1][1]))) {
+ if ((!flag_aff_chemin) || ((table_ptselect[0][0] == table_ptselect[1][0]) && (table_ptselect[0][1] == table_ptselect[1][1]))) {
pSolution[0] = -1;
pSolution[1] = -1;
freePerso(num);
diff --git a/engines/cruise/cruise.cpp b/engines/cruise/cruise.cpp
index 0e840c8ca3..43e74a4300 100644
--- a/engines/cruise/cruise.cpp
+++ b/engines/cruise/cruise.cpp
@@ -98,8 +98,7 @@ int CruiseEngine::go() {
void CruiseEngine::initialize() {
PCFadeFlag = 0;
- ptr_something =
- (ctpVar19Struct *) mallocAndZero(sizeof(ctpVar19Struct) * 0x200);
+ workBuffer = (uint8 *) mallocAndZero(8192);
/*volVar1 = 0;
* fileData1 = 0; */
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index 0907dc67ec..1c0f1fd8ab 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -1924,16 +1924,13 @@ int oldmain(int argc, char *argv[]) {
printf("Initializing engine...\n");
-// initBuffer(scaledScreen,640,400);
-
PCFadeFlag = 0;
//lowLevelInit();
// arg parser stuff
- ptr_something =
- (ctpVar19Struct *) mallocAndZero(sizeof(ctpVar19Struct) * 0x200);
+ workBuffer = (uint8 *) mallocAndZero(8192);
/*volVar1 = 0;
* fileData1 = 0; */
@@ -1956,7 +1953,7 @@ int oldmain(int argc, char *argv[]) {
//freeStuff();
- //freePtr(ptr_something);
+ //freePtr(workBuffer);
return (0);
}
diff --git a/engines/cruise/cruise_main.h b/engines/cruise/cruise_main.h
index 269bc2516f..c7d597dbd6 100644
--- a/engines/cruise/cruise_main.h
+++ b/engines/cruise/cruise_main.h
@@ -96,7 +96,7 @@ void *mallocAndZero(int32 size);
uint8 *mainProc14(uint16 overlay, uint16 idx);
void printInfoBlackBox(const char *string);
void waitForPlayerInput(void);
-int loadCtp(const char * ctpName);
+int initCt(const char * ctpName);
void loadPakedFileToMem(int fileIdx, uint8 * buffer);
int getNumObjectsByClass(int scriptIdx, int param);
void resetFileEntryRange(int param1, int param2);
diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp
index 45eeb9f8e4..9020e76f72 100644
--- a/engines/cruise/ctp.cpp
+++ b/engines/cruise/ctp.cpp
@@ -28,14 +28,14 @@
namespace Cruise {
-ctpVar19Struct *ptr_something;
-ctpVar19Struct *polyStruct;
-ctpVar19Struct *ctpVar11;
-ctpVar19Struct *ctpVar13;
-ctpVar19Struct *ctpVar15;
+uint8 *workBuffer;
+uint8 *polyStruct;
+uint8 *adrStructPoly;
+uint8 *polyStructNorm;
+uint8 *polyStructExp;
uint8 *ctpVar17;
-ctpVar19Struct *ctpVar19;
+uint8 *polyStruct0;
int currentWalkBoxCenterX;
int currentWalkBoxCenterY;
@@ -58,7 +58,7 @@ int ctpProc2(int varX, int varY, int paramX, int paramY) {
}
// this function process path finding coordinates
-void loadCtpSub2(short int coordCount, short int *ptr) {
+void computeDistance(short int coordCount, short int *ptr) {
// coordCount = ctp_routeCoordCount, ptr = ctpVar8
int i;
int offset = 0;
@@ -89,37 +89,27 @@ void loadCtpSub2(short int coordCount, short int *ptr) {
}
}
-void getWalkBoxCenter(int boxIdx, uint16 *_walkboxTable) {
+void getWalkBoxCenter(int n, int16 table[][40]) {
int minX = 1000;
int minY = 1000;
int maxX = -1;
int maxY = -1;
- ASSERT(boxIdx <= 15); // max number of walkboxes is 16
- ASSERT(_walkboxTable[boxIdx * 40]); // we should never have an empty walk box
+ for(int i=0; i< table[n][0]; i++) {
+ int x = table[n][i*2+1];
+ int y = table[n][i*2+2];
- if (_walkboxTable[boxIdx * 40] > 0) {
- int numPoints = _walkboxTable[boxIdx * 40];
- uint16 *pCurrentPtr = _walkboxTable + (boxIdx * 40) + 1;
+ if (x < minX)
+ minX = x;
- int i;
+ if (x > maxX)
+ maxX = x;
- for (i = 0; i < numPoints; i++) {
- int X = *(pCurrentPtr++);
- int Y = *(pCurrentPtr++);;
+ if (y < minY)
+ minY = y;
- if (X < minX)
- minX = X;
-
- if (X > maxX)
- maxX = X;
-
- if (Y < minY)
- minY = Y;
-
- if (Y > maxY)
- maxY = Y;
- }
+ if (y > maxY)
+ maxY = y;
}
currentWalkBoxCenterX = ((maxX - minX) / 2) + minX;
@@ -127,16 +117,15 @@ void getWalkBoxCenter(int boxIdx, uint16 *_walkboxTable) {
}
// ax dx bx
-void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2,
- uint16 *walkboxData) {
+void renderCTPWalkBox(int16 *walkboxData, int hotPointX, int hotPointY, int X, int Y, int scale ) {
int numPoints;
int wbSelf1;
int wbSelf2;
int i;
int16 *destination;
- wbSelf1 = upscaleValue(X1, scale) - X2;
- wbSelf2 = upscaleValue(Y1, scale) - Y2;
+ wbSelf1 = upscaleValue(hotPointX, scale) - X;
+ wbSelf2 = upscaleValue(hotPointY, scale) - Y;
numPoints = *(walkboxData++);
@@ -149,8 +138,10 @@ void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2,
int scaledX = upscaleValue(pointX, scale) - wbSelf1;
int scaledY = upscaleValue(pointY, scale) - wbSelf2;
- *(destination++) = scaledX >> 16;
- *(destination++) = scaledY >> 16;
+ /* *(destination++) = scaledX >> 16;
+ *(destination++) = scaledY >> 16; */
+ *(destination++) = pointX;
+ *(destination++) = pointY;
}
m_color = 0;
@@ -164,119 +155,58 @@ void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2,
}
// this process the walkboxes
-void loadCtpSub1(int boxIdx, int scale, uint16 *_walkboxTable,
- ctpVar19Struct *param4) {
+void makeCtStruct(uint8* str, int16 table[][40], int num, int z) {
int minX = 1000;
- int minY = 1000;
int maxX = -1;
- int maxY = -1;
- ctpVar19Struct *var_1C;
- ctpVar19Struct *var_12;
-// int16 *var_18;
-// int16 *si;
- // int16* di;
- // uint8* cx;
- // int bx;
- // int ax;
- // int var_2;
-// int var_E;
- //int var_C = 1000;
- //int var_A = 0;
- ctpVar19SubStruct *subStruct;
-
- ASSERT(boxIdx <= 15);
-
- if (_walkboxTable[boxIdx * 40] > 0) { // is walkbox used ?
- getWalkBoxCenter(boxIdx, _walkboxTable);
-
- currentWalkBoxCenterYBis = currentWalkBoxCenterY;
- currentWalkBoxCenterXBis = currentWalkBoxCenterX;
- // + 512
- renderCTPWalkBox(currentWalkBoxCenterX, currentWalkBoxCenterY,
- currentWalkBoxCenterX, scale + 0x200,
- currentWalkBoxCenterY, _walkboxTable + boxIdx * 40);
-
- var_1C = param4;
- var_12 = var_1C + 1; // next
-/*
- var_18 = XMIN_XMAX;
- var_E = 0;
-
- si = &XMIN_XMAX[1];
- if (*si>=0)
- * {
- * di = si;
- * cx = var_12;
- *
- * do
- * {
- * di++;
- * bx = di[-1];
- * ax = di[0];
- * di++;
- *
- * var_2 = ax;
- * if (var_C < bx)
- * {
- * var_C = bx;
- * }
- *
- * if (var_2 < var_A)
- * {
- * var_A = var_2;
- * }
- *
- * *cx = bx;
- * cx++;
- * *cx = var_2;
- * cx++;
- * var_E ++;
- * } while (di);
- *
- * var_12 = cx;
- * } */
-
- /*************/
- {
- int i;
- int numPoints;
- uint16 *pCurrentPtr = _walkboxTable + boxIdx * 40;
-
- numPoints = *(pCurrentPtr++);
-
- for (i = 0; i < numPoints; i++) {
- int X = *(pCurrentPtr++);
- int Y = *(pCurrentPtr++);
-
- if (X < minX)
- minX = X;
-
- if (X > maxX)
- maxX = X;
-
- if (Y < minY)
- minY = Y;
-
- if (Y > maxY)
- maxY = Y;
- }
- }
- /************/
+ if(table[num][0] < 1)
+ return;
+
+ getWalkBoxCenter(num, table);
+
+ currentWalkBoxCenterXBis = currentWalkBoxCenterX;
+ currentWalkBoxCenterYBis = currentWalkBoxCenterY;
+
+ renderCTPWalkBox(&table[num][0], currentWalkBoxCenterX, currentWalkBoxCenterY, currentWalkBoxCenterX, currentWalkBoxCenterY, z + 0x200 );
- var_1C->field_0 = var_12;
- ctpVar13 = var_12;
- var_12->field_0 = (ctpVar19Struct *) (-1);
+ int16* a1;
+ int16* a2;
- subStruct = &var_1C->subStruct;
+ a1 = a2 = (int16*)str;
+ a2 += 4+sizeof(int16*); // skip header
- subStruct->boxIdx = boxIdx;
- subStruct->type = walkboxType[boxIdx];
- subStruct->minX = minX;
- subStruct->maxX = maxX;
- subStruct->minY = minY;
- subStruct->maxY = maxY;
+ int16* XArray = XMIN_XMAX;
+ int minY = *XArray++;
+
+ int i=0;
+
+ while( *XArray >= 0 ) {
+ int x1 = *XArray++;
+ int x2 = *XArray++;
+
+ if(x1<minX)
+ minX = x1;
+
+ if(x2>maxX)
+ maxX = x2;
+
+ *a2++ = x1;
+ *a2++ = x2;
+ i++;
}
+ *(int16**)a1 = a2;
+
+ adrStructPoly = (uint8*)a2;
+
+ *(uint16**)a2 = (uint16*)-1;
+
+ a1+=sizeof(int16*);
+ *a1++=num;
+ *a1++=walkboxColor[num];
+ *a1++=minX;
+ *a1++=maxX;
+ *a1++=minY;
+ *a1++=minY+i+2;
}
int getNode(int nodeResult[2], int nodeId){
@@ -289,21 +219,17 @@ int getNode(int nodeResult[2], int nodeId){
return 0;
}
-int loadCtp(const char *ctpName) {
- int walkboxCounter; // si
- uint8 *ptr;
+int initCt(const char *ctpName) {
uint8 *dataPointer; // ptr2
char fileType[5]; // string2
short int segementSizeTable[7]; // tempTable
- if (ctpVar1 == 0) {
- int i;
-
- for (i = 0; i < 10; i++) {
+ if ( !loadCtFromSave) {
+ for (int i = 0; i < 10; i++) {
persoTable[i] = NULL;
}
}
-
+ uint8* ptr = NULL;
if (!loadFileSub1(&ptr, ctpName, 0)) {
free(ptr);
return (-18);
@@ -320,96 +246,111 @@ int loadCtp(const char *ctpName) {
return (0);
}
- memcpy(&ctp_routeCoordCount, dataPointer, 2); // get the number of path-finding coordinates
+ ctp_routeCoordCount = readB16(dataPointer); // get the number of nods
dataPointer += 2;
- flipShort(&ctp_routeCoordCount);
- memcpy(segementSizeTable, dataPointer, 0xE);
- dataPointer += 0xE; // + 14
- flipGen(segementSizeTable, 0xE);
+ for(int i=0; i<7; i++) {
+ segementSizeTable[i] = readB16(dataPointer);
+ dataPointer += 2;
+ }
- memcpy(ctp_routeCoords, dataPointer, segementSizeTable[0]); // get the path-finding coordinates
- dataPointer += segementSizeTable[0];
- flipGen(ctp_routeCoords, segementSizeTable[0]);
+ // get the path-finding coordinates
+ ASSERT((segementSizeTable[0]%4) == 0);
+ for(int i=0; i<segementSizeTable[0]/4; i++) {
+ ctp_routeCoords[i][0] = readB16(dataPointer);
+ dataPointer += 2;
+ ctp_routeCoords[i][1] = readB16(dataPointer);
+ dataPointer += 2;
+ }
- memcpy(ctp_routes, dataPointer, segementSizeTable[1]); // get the path-finding line informations (indexing the routeCoords array)
- dataPointer += segementSizeTable[1];
- flipGen(ctp_routes, segementSizeTable[1]);
+ // get the path-finding line informations (indexing the routeCoords array)
+ ASSERT((segementSizeTable[1]%20) == 0);
+ for(int i=0; i<segementSizeTable[1]/20; i++) {
+ for(int j=0; j<10; j++) {
+ ctp_routes[i][j] = readB16(dataPointer);
+ dataPointer += 2;
+ }
+ }
- memcpy(ctp_walkboxTable, dataPointer, segementSizeTable[2]); // get the walkbox coordinates and lines
- dataPointer += segementSizeTable[2];
- flipGen(ctp_walkboxTable, segementSizeTable[2]);
+ // read polygons
+ ASSERT((segementSizeTable[2]%80) == 0);
+ for(int i=0; i<segementSizeTable[2]/80; i++) {
+ for(int j=0; j<40; j++) {
+ ctp_walkboxTable[i][j] = readB16(dataPointer);
+ dataPointer += 2;
+ }
+ }
- if (ctpVar1) {
+ if (loadCtFromSave) {
+ // loading from save, ignore the initial values
dataPointer += segementSizeTable[3];
dataPointer += segementSizeTable[4];
} else {
- memcpy(walkboxType, dataPointer, segementSizeTable[3]); // get the walkbox type
- dataPointer += segementSizeTable[3];
- flipGen(walkboxType, segementSizeTable[3]); // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone
+ // get the walkbox type
+ // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone
+ ASSERT((segementSizeTable[3] % 2) == 0);
+ for(int i=0; i<segementSizeTable[3]/2; i++) {
+ walkboxColor[i] = readB16(dataPointer);
+ dataPointer += 2;
+ }
- memcpy(walkboxChange, dataPointer, segementSizeTable[4]); // change indicator, walkbox type can change, i.e. blocked by object (values are either 0x00 or 0x01)
- dataPointer += segementSizeTable[4];
- flipGen(walkboxChange, segementSizeTable[4]);
+ // change indicator, walkbox type can change, i.e. blocked by object (values are either 0x00 or 0x01)
+ ASSERT((segementSizeTable[4] % 2) == 0);
+ for(int i=0; i<segementSizeTable[4]/2; i++) {
+ walkboxState[i] = readB16(dataPointer);
+ dataPointer += 2;
+ }
}
- memcpy(ctpVar6, dataPointer, segementSizeTable[5]); // unknown? always 2*16 bytes (used by S24.CTP, S33.CTP, S33_2.CTP, S34.CTP, S35.CTP, S36.CTP; values can be 0x00, 0x01, 0x03, 0x05)
- dataPointer += segementSizeTable[5];
- flipGen(ctpVar6, segementSizeTable[5]);
-
- memcpy(ctp_scale, dataPointer, segementSizeTable[6]); // scale values for the walkbox coordinates (don't know why there is a need for scaling walkboxes)
- dataPointer += segementSizeTable[6];
- flipGen(ctp_scale, segementSizeTable[6]); // ok
+ //
+ ASSERT((segementSizeTable[5] % 2) == 0);
+ for(int i=0; i<segementSizeTable[5]/2; i++) {
+ walkboxColorIndex[i] = readB16(dataPointer);
+ dataPointer += 2;
+ }
+ //
+ ASSERT((segementSizeTable[6] % 2) == 0);
+ for(int i=0; i<segementSizeTable[6]/2; i++) {
+ walkboxZoom[i] = readB16(dataPointer);
+ dataPointer += 2;
+ }
free(ptr);
strcpy(currentCtpName, ctpName);
numberOfWalkboxes = segementSizeTable[6] / 2; // get the number of walkboxes
- loadCtpSub2(ctp_routeCoordCount, ctpVar8); // process path-finding stuff
+ computeDistance(ctp_routeCoordCount, ctpVar8); // process path-finding stuff
- polyStruct = ctpVar11 = ctpVar13 = ptr_something;
+ polyStruct = polyStructNorm = adrStructPoly = workBuffer;
ptr = (uint8 *) polyStruct;
- walkboxCounter = numberOfWalkboxes;
-
- while ((--walkboxCounter) >= 0) {
- loadCtpSub1(walkboxCounter, 0, ctp_walkboxTable, ctpVar13);
+ for(int i= numberOfWalkboxes-1; i >=0; i--) {
+ makeCtStruct(adrStructPoly, ctp_walkboxTable, i, 0 );
}
- ctpVar15 = ctpVar13 + 1; // was after the -1 thing
-
- walkboxCounter = numberOfWalkboxes;
+ polyStructExp = adrStructPoly += 4;
- while (--walkboxCounter) {
- loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20,
- ctp_walkboxTable, ctpVar13);
+ for(int i= numberOfWalkboxes-1; i >=0; i--) {
+ makeCtStruct(adrStructPoly, ctp_walkboxTable, i, walkboxZoom[i] * 20 );
}
- //ctpVar17 = ctpVar13 - ptr + 4;
-
- {
- int numOfUsedEntries = ctpVar13 - (ctpVar19Struct *) ptr;
- numOfUsedEntries++; // there is a -1 entry at the end... Original was only mallocing numOfUsedEntries*sizeof(ctpVar19Struct)+4, but this is a bit ugly...
- ctpVar13 = ctpVar11 = polyStruct = (ctpVar19Struct *) malloc(numOfUsedEntries * sizeof(ctpVar19Struct));
- }
+ int ctSize = (adrStructPoly - ptr) + 4; // for now, the +4 is a safe zone
+ adrStructPoly = polyStructNorm = polyStruct = (uint8 *) malloc(ctSize);
- walkboxCounter = numberOfWalkboxes;
- while ((--walkboxCounter) >= 0) {
- loadCtpSub1(walkboxCounter, 0, ctp_walkboxTable, ctpVar13);
+ for(int i= numberOfWalkboxes-1; i >=0; i--) {
+ makeCtStruct(adrStructPoly, ctp_walkboxTable, i, 0);
}
- ctpVar15 = ctpVar13 + 1;
+ polyStructExp = adrStructPoly += 4;
- walkboxCounter = numberOfWalkboxes;
- while (--walkboxCounter) {
- loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20,
- ctp_walkboxTable, ctpVar13);
+ for(int i= numberOfWalkboxes-1; i >=0; i--) {
+ makeCtStruct(adrStructPoly, ctp_walkboxTable, i, walkboxZoom[i] * 20);
}
- ctpVar19 = ctpVar11;
+ polyStruct0 = polyStructNorm;
return (1);
}
diff --git a/engines/cruise/ctp.h b/engines/cruise/ctp.h
index 4e98b60feb..71df47ac57 100644
--- a/engines/cruise/ctp.h
+++ b/engines/cruise/ctp.h
@@ -42,16 +42,16 @@ struct ctpVar19Struct {
ctpVar19SubStruct subStruct;
};
-extern ctpVar19Struct *ptr_something;
-extern ctpVar19Struct *polyStruct;
-extern ctpVar19Struct *ctpVar11;
-extern ctpVar19Struct *ctpVar13;
-extern ctpVar19Struct *ctpVar15;
+extern uint8 *workBuffer;
+extern uint8 *polyStruct;
+extern uint8 *adrStructPoly;
+extern uint8 *polyStructNorm;
+extern uint8 *polyStructExp;
extern uint8 *ctpVar17;
-extern ctpVar19Struct *ctpVar19;
+extern uint8 *polyStruct0;
-int loadCtp(const char * ctpName);
+int initCt(const char * ctpName);
int ctpProc2(int varX, int varY, int paramX, int paramY);
int getNode(int nodeResult[2], int nodeId);
diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp
index 8be6543eb1..6963aaef83 100644
--- a/engines/cruise/font.cpp
+++ b/engines/cruise/font.cpp
@@ -400,7 +400,7 @@ void drawString(int32 x, int32 y, uint8 *string, uint8 *buffer, uint8 color,
}
useDynamicBuffer = 1;
} else {
- currentStrRenderBuffer = (uint8 *) ptr_something;
+ currentStrRenderBuffer = (uint8 *) workBuffer;
useDynamicBuffer = 0;
}
diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp
index 963dce6996..0f54f21850 100644
--- a/engines/cruise/function.cpp
+++ b/engines/cruise/function.cpp
@@ -728,7 +728,7 @@ int16 Op_Preload(void) {
}
int16 Op_LoadCt(void) {
- return loadCtp((char*)popPtr());
+ return initCt((char*)popPtr());
}
int16 Op_LoadSong(void) {
@@ -1095,46 +1095,6 @@ int removeAnimation(actorStruct * pHead, int overlay, int objIdx, int objType) {
int flag_obstacle; // computedVar14Bis
-void checkCollisionWithWalkBoxesBoundingBoxes(int x, int y) {
- ctpVar19Struct *di = ctpVar19;
-
- do {
- int minX;
- int maxX;
- int minY;
- int maxY;
-
- ctpVar19SubStruct *subStruct;
-
- if ((ctpVar19Struct *)-1 == di->field_0) { // ok, ugly, but it's in the original
- flag_obstacle = 0;
- return;
- }
-
- subStruct = &di->subStruct;
-
- minX = subStruct->minX;
- maxX = subStruct->maxX;
- minY = subStruct->minY;
- maxY = subStruct->maxY;
-
- computedVar14 = subStruct->boxIdx; // Box index
-
- if (!(walkboxChange[subStruct->boxIdx]) && (minY >= x)
- && (maxY <= x) && (minX >= y) && (maxX <= y)) {
- /**************/
-
- flag_obstacle = walkboxType[computedVar14];
-
- /**************/
- }
-
- di = di->field_0;
- } while (1);
-
- flag_obstacle = 0;
-}
-
// add animation
int16 Op_AddAnimation(void) {
int stepY = popVar();
@@ -1176,7 +1136,7 @@ int16 Op_AddAnimation(void) {
zoom = -zoom;
}
- checkCollisionWithWalkBoxesBoundingBoxes(params.X, params.Y);
+ getPixel(params.X, params.Y);
setObjectPosition(overlay, obj, 3, newFrame + start);
setObjectPosition(overlay, obj, 4, zoom);
diff --git a/engines/cruise/gfxModule.cpp b/engines/cruise/gfxModule.cpp
index ffc2462fd1..8ba65680fa 100644
--- a/engines/cruise/gfxModule.cpp
+++ b/engines/cruise/gfxModule.cpp
@@ -228,8 +228,6 @@ static uint32 lastTick;
void flip() {
int i;
byte paletteRGBA[256 * 4];
- //uint8* outPtr = scaledScreen;
- //uint8* inPtr = globalScreen;
if (palDirtyMax != -1) {
for (i = palDirtyMin; i <= palDirtyMax; i++) {
diff --git a/engines/cruise/mainDraw.cpp b/engines/cruise/mainDraw.cpp
index 9a6ed700f6..9040838a01 100644
--- a/engines/cruise/mainDraw.cpp
+++ b/engines/cruise/mainDraw.cpp
@@ -1254,12 +1254,12 @@ void drawSprite(int objX1, int var_6, cellStruct *currentObjPtr, char *data1, in
#ifdef _DEBUG
void drawCtp(void) {
- int i;
+/* int i;
if (ctp_walkboxTable) {
for (i = 0; i < 15; i++) {
uint16 *dataPtr = &ctp_walkboxTable[i * 40];
- int type = walkboxType[i]; // show different types in different colors
+ int type = walkboxColor[i]; // show different types in different colors
if (*dataPtr) {
int j;
@@ -1277,7 +1277,7 @@ void drawCtp(void) {
dataPtr[2], 0);
}
}
- }
+ }*/
}
#endif
diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp
index 88567fdee7..77cd904973 100644
--- a/engines/cruise/saveload.cpp
+++ b/engines/cruise/saveload.cpp
@@ -441,8 +441,8 @@ void saveCT(Common::OutSaveFile& currentSaveFile) {
if(numberOfWalkboxes)
{
- currentSaveFile.write(walkboxType, numberOfWalkboxes * 2);
- currentSaveFile.write(walkboxChange, numberOfWalkboxes * 2);
+ currentSaveFile.write(walkboxColor, numberOfWalkboxes * 2);
+ currentSaveFile.write(walkboxState, numberOfWalkboxes * 2);
}
for (unsigned long int i = 0; i < 10; i++) {
@@ -474,8 +474,8 @@ void loadSavegameDataSub6(Common::InSaveFile& currentSaveFile) {
numberOfWalkboxes = currentSaveFile.readUint16LE();
if (numberOfWalkboxes) {
- currentSaveFile.read(walkboxType, numberOfWalkboxes * 2);
- currentSaveFile.read(walkboxChange, numberOfWalkboxes * 2);
+ currentSaveFile.read(walkboxColor, numberOfWalkboxes * 2);
+ currentSaveFile.read(walkboxState, numberOfWalkboxes * 2);
}
for (i = 0; i < 10; i++) {
@@ -907,9 +907,9 @@ int loadSavegameData(int saveGameIdx) {
//TODO: here, restart music
if (strlen(currentCtpName)) {
- ctpVar1 = 1;
- loadCtp(currentCtpName);
- ctpVar1 = 0;
+ loadCtFromSave = 1;
+ initCt(currentCtpName);
+ loadCtFromSave = 0;
}
//prepareFadeOut();
//gfxModuleData.gfxFunction8();
diff --git a/engines/cruise/vars.cpp b/engines/cruise/vars.cpp
index e584faa97a..7d7c249f56 100644
--- a/engines/cruise/vars.cpp
+++ b/engines/cruise/vars.cpp
@@ -155,20 +155,20 @@ int16 saveVar1;
uint8 saveVar2[97]; // recheck size
int16 numberOfWalkboxes; // saveVar3
-int16 walkboxType[15]; // saveVar4
-int16 walkboxChange[15]; // saveVar5
+int16 walkboxColor[15]; // saveVar4
+int16 walkboxState[15]; // saveVar5
uint8 lastAni[16];
int32 loadFileVar1;
-int16 ctpVar1 = 0;
+int16 loadCtFromSave = 0;
int16 ctp_routeCoordCount; // ctpVar2
int16 ctp_routeCoords[20][2]; // ctpVar3
int16 ctp_routes[20][10];
-uint16 ctp_walkboxTable[15 * 40]; // ctpVar5
-int8 ctpVar6[32];
-int16 ctp_scale[15]; // ctpVar7
+int16 ctp_walkboxTable[15][40]; // ctpVar5
+int16 walkboxColorIndex[16];
+int16 walkboxZoom[15]; // ctpVar7
int16 ctpVar8[200];
int16 ctpVar14;
@@ -178,7 +178,6 @@ int16 speedGame;
int16 oldSpeedGame;
uint8 globalScreen[320 * 200];
-uint8 scaledScreen[640 * 400];
//OSystem *osystem;
diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h
index cdf3de072c..2b499af10e 100644
--- a/engines/cruise/vars.h
+++ b/engines/cruise/vars.h
@@ -250,14 +250,14 @@ extern int16 saveVar1;
extern uint8 saveVar2[97]; // recheck size
extern int16 numberOfWalkboxes; // saveVar3
-extern int16 walkboxType[15]; // saveVar4 // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone
-extern int16 walkboxChange[15]; // saveVar5 // walkbox can change its type: 0x00 - not changeable, 0x01 - changeable
- // Assumption: To change the type: walkboxType[i] -= walkboxChane[i] and vice versa
+extern int16 walkboxColor[15]; // saveVar4 // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone
+extern int16 walkboxState[15]; // saveVar5 // walkbox can change its type: 0x00 - not changeable, 0x01 - changeable
+ // Assumption: To change the type: walkboxColor[i] -= walkboxChane[i] and vice versa
extern uint8 lastAni[16];
extern int32 loadFileVar1;
-extern int16 ctpVar1;
+extern int16 loadCtFromSave;
extern int16 ctp_routeCoordCount; // ctpVar2 // number of path-finding coordinates
extern int16 ctp_routeCoords[20][2]; // ctpVar3 // path-finding coordinates array
@@ -279,9 +279,9 @@ extern int16 ctp_routes[20][10]; // path-finding line information
for the 20 * i slice the root x,y is routeCoords[i], routeCoords[i+2]
the unused rest of the slice if filled up with 0xFF
*/
-extern uint16 ctp_walkboxTable[15 * 40]; // ctpVar5 // walkboxes coordinates and lines
-extern int8 ctpVar6[32];
-extern int16 ctp_scale[15]; // ctpVar7 // scaling information for walkboxes
+extern int16 ctp_walkboxTable[15][40]; // ctpVar5 // walkboxes coordinates and lines
+extern int16 walkboxColorIndex[16];
+extern int16 walkboxZoom[15]; // ctpVar7 // scaling information for walkboxes
extern int16 ctpVar8[200];
extern int16 ctpVar14;
@@ -291,7 +291,6 @@ extern int16 speedGame;
extern int16 oldSpeedGame;
extern uint8 globalScreen[320 * 200];
-extern uint8 scaledScreen[640 * 400];
//extern OSystem *osystem;