From c87ad51470fb11103e620cf0b09cb36c6a08439f Mon Sep 17 00:00:00 2001 From: Vincent Hamm Date: Thu, 27 Dec 2007 17:37:38 +0000 Subject: Nearly working pathfinder svn-id: r30015 --- engines/cruise/actor.cpp | 17 ++++------ engines/cruise/ctp.cpp | 82 +++++++++++++++++++++++++-------------------- engines/cruise/ctp.h | 4 ++- engines/cruise/function.cpp | 19 ++++++----- engines/cruise/vars.cpp | 4 +-- engines/cruise/vars.h | 4 +-- 6 files changed, 67 insertions(+), 63 deletions(-) (limited to 'engines/cruise') diff --git a/engines/cruise/actor.cpp b/engines/cruise/actor.cpp index ed88c0d089..50ab7e1656 100644 --- a/engines/cruise/actor.cpp +++ b/engines/cruise/actor.cpp @@ -340,12 +340,12 @@ int point_proche(int16 table[][2]) { x = table[i][0]; y = table[i][1]; - ctpProc2(x_mouse, y_mouse, x, y); - if (ctpVar14 < d1) { + int pointDistance = computeDistance(x_mouse, y_mouse, x, y); + if (pointDistance < d1) { polydroite(x_mouse, y_mouse, x, y); if (!flag_obstacle && ctp_routes[i][0] > 0) { - d1 = ctpVar14; + d1 = pointDistance; p = i; } } @@ -394,9 +394,7 @@ void explore(int depart, int arrivee) { sol[idsol] = (char)arrivee; D = 0; for (i = 0; i < idsol; i++) { - D = D + - ctp_routeCoords[(int)sol[i]][(int) - sol[i + 1]]; + D = D + distanceTable[(int)sol[i]][(int)sol[i + 1]]; Fsol[i] = sol[i]; } prem2 = 0; @@ -478,9 +476,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2 // can we go there directly ? polydroite(x1, y1, x2, y2); - //////////////// - flag_obstacle = 0; - //////////////// + if (!flag_obstacle) { solution0[0][0] = x1; solution0[0][1] = y1; @@ -651,8 +647,7 @@ int16 computePathfinding(int16 *pSolution, int16 x, int16 y, int16 destX, int16 x_mouse = x; y_mouse = y; - if (!flag_obstacle - || (point_select = point_proche(ctp_routeCoords)) == -1) { + if (!flag_obstacle || (point_select = point_proche(ctp_routeCoords)) == -1) { pSolution[0] = -1; pSolution[1] = -1; diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp index 9020e76f72..e015828c30 100644 --- a/engines/cruise/ctp.cpp +++ b/engines/cruise/ctp.cpp @@ -45,7 +45,7 @@ int currentWalkBoxCenterYBis; int ctpVarUnk; uint8 walkboxTable[0x12]; -int ctpProc2(int varX, int varY, int paramX, int paramY) { +int computeDistance(int varX, int varY, int paramX, int paramY) { int diffX = ABS(paramX - varX); int diffY = ABS(paramY - varY); @@ -53,39 +53,23 @@ int ctpProc2(int varX, int varY, int paramX, int paramY) { diffY = diffX; } - ctpVar14 = diffY; // highest difference return (diffY); } // this function process path finding coordinates -void computeDistance(short int coordCount, short int *ptr) { -// coordCount = ctp_routeCoordCount, ptr = ctpVar8 - int i; - int offset = 0; - - short int *cur_ctp_routeCoords = (short int *)ctp_routeCoords; // coordinates table - int8 *cur_ctp_routes = (int8 *) ctp_routes; - - for (i = 0; i < coordCount; i++) { // for i < ctp_routeCoordCount - int varX = cur_ctp_routeCoords[0]; // x - int varY = cur_ctp_routeCoords[1]; // y +void computeAllDistance(int16 table[][10], short int coordCount) { + for(int i=0; i di) { // while (coordCount > counter++) - int idx = *(int16 *) (cur_ctp_routes + var4Offset); - ptr[offset + idx] = - ctpProc2(varX, varY, ctp_routeCoords[idx][0], - ctp_routeCoords[idx * 2][1]); + int x2 = ctp_routeCoords[p][0]; + int y2 = ctp_routeCoords[p][1]; - var4Offset += 2; - di++; + table[i][p] = computeDistance(x1, y1, x2, y2); } - - offset += 10; - cur_ctp_routes += 20; - cur_ctp_routeCoords += 2; } } @@ -119,13 +103,11 @@ void getWalkBoxCenter(int n, int16 table[][40]) { // ax dx bx 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(hotPointX, scale) - X; - wbSelf2 = upscaleValue(hotPointY, scale) - Y; + int startX = X - ((upscaleValue(hotPointX, scale) + 0x8000) >> 16); + int startY = Y - ((upscaleValue(hotPointY, scale) + 0x8000) >> 16); numPoints = *(walkboxData++); @@ -135,13 +117,11 @@ void renderCTPWalkBox(int16 *walkboxData, int hotPointX, int hotPointY, int X, i int pointX = *(walkboxData++); int pointY = *(walkboxData++); - int scaledX = upscaleValue(pointX, scale) - wbSelf1; - int scaledY = upscaleValue(pointY, scale) - wbSelf2; + int scaledX =((upscaleValue(pointX, scale) + 0x8000) >> 16) + startX; + int scaledY =((upscaleValue(pointY, scale) + 0x8000) >> 16) + startX; - /* *(destination++) = scaledX >> 16; - *(destination++) = scaledY >> 16; */ - *(destination++) = pointX; - *(destination++) = pointY; + *(destination++) = scaledX; + *(destination++) = scaledY; } m_color = 0; @@ -219,6 +199,34 @@ int getNode(int nodeResult[2], int nodeId){ return 0; } +int setNodeColor(int nodeIdx, int nodeColor) { + if (nodeIdx < 0 || nodeIdx >= ctp_routeCoordCount) + return -1; + + int oldColor = walkboxColor[nodeIdx]; + + if(nodeColor == -1) + return + + walkboxColor[nodeIdx] = nodeColor; + + return oldColor; +} + +int setNodeState(int nodeIdx, int nodeState) { + if (nodeIdx < 0 || nodeIdx >= ctp_routeCoordCount) + return -1; + + int oldState = walkboxState[nodeIdx]; + + if(nodeState == -1) + return + + walkboxState[nodeIdx] = nodeState; + + return oldState; +} + int initCt(const char *ctpName) { uint8 *dataPointer; // ptr2 char fileType[5]; // string2 @@ -321,7 +329,7 @@ int initCt(const char *ctpName) { numberOfWalkboxes = segementSizeTable[6] / 2; // get the number of walkboxes - computeDistance(ctp_routeCoordCount, ctpVar8); // process path-finding stuff + computeAllDistance(distanceTable, ctp_routeCoordCount); // process path-finding stuff polyStruct = polyStructNorm = adrStructPoly = workBuffer; diff --git a/engines/cruise/ctp.h b/engines/cruise/ctp.h index 71df47ac57..f2ce4c86c5 100644 --- a/engines/cruise/ctp.h +++ b/engines/cruise/ctp.h @@ -52,9 +52,11 @@ extern uint8 *ctpVar17; extern uint8 *polyStruct0; int initCt(const char * ctpName); -int ctpProc2(int varX, int varY, int paramX, int paramY); +int computeDistance(int varX, int varY, int paramX, int paramY); int getNode(int nodeResult[2], int nodeId); +int setNodeColor(int nodeIdx, int nodeColor); +int setNodeState(int nodeIdx, int nodeState); } // End of namespace Cruise diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp index 0f54f21850..7adc358bee 100644 --- a/engines/cruise/function.cpp +++ b/engines/cruise/function.cpp @@ -1468,15 +1468,18 @@ int16 Op_SongExist(void) { return 0; } -int16 Op_SetNodeColor(void) { - int16 color; - int16 node; +int16 Op_SetNodeState(void) { + int16 state = popVar(); + int16 node = popVar(); - color = popVar(); - node = popVar(); - printf("Unimplemented \"Op_SetNodeColor\"\n"); + return setNodeState(node, state); +} - return 0; +int16 Op_SetNodeColor(void) { + int16 color = popVar(); + int16 node = popVar(); + + return setNodeColor(node, color); } int16 Op_SetXDial(void) { @@ -1587,7 +1590,7 @@ opcodeFunction opcodeTablePtr[] = Op_RemoveAnimation, Op_SetZoom, Op_SetObjectAtNode, - NULL, // setNodeState, never used ? + Op_SetNodeState, Op_SetNodeColor, Op_TrackAnim, Op_GetNodeX, diff --git a/engines/cruise/vars.cpp b/engines/cruise/vars.cpp index 7d7c249f56..c22a03df80 100644 --- a/engines/cruise/vars.cpp +++ b/engines/cruise/vars.cpp @@ -169,9 +169,7 @@ int16 ctp_routes[20][10]; int16 ctp_walkboxTable[15][40]; // ctpVar5 int16 walkboxColorIndex[16]; int16 walkboxZoom[15]; // ctpVar7 -int16 ctpVar8[200]; - -int16 ctpVar14; +int16 distanceTable[20][10]; int16 flagSpeed; int16 speedGame; diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h index 2b499af10e..04568337d6 100644 --- a/engines/cruise/vars.h +++ b/engines/cruise/vars.h @@ -282,9 +282,7 @@ extern int16 ctp_routes[20][10]; // path-finding line information 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; +extern int16 distanceTable[20][10]; extern int16 flagSpeed; extern int16 speedGame; -- cgit v1.2.3