[Scummvm-cvs-logs] SF.net SVN: scummvm: [30015] scummvm/trunk/engines/cruise

yazoo at users.sourceforge.net yazoo at users.sourceforge.net
Thu Dec 27 18:37:38 CET 2007


Revision: 30015
          http://scummvm.svn.sourceforge.net/scummvm/?rev=30015&view=rev
Author:   yazoo
Date:     2007-12-27 09:37:38 -0800 (Thu, 27 Dec 2007)

Log Message:
-----------
Nearly working pathfinder

Modified Paths:
--------------
    scummvm/trunk/engines/cruise/actor.cpp
    scummvm/trunk/engines/cruise/ctp.cpp
    scummvm/trunk/engines/cruise/ctp.h
    scummvm/trunk/engines/cruise/function.cpp
    scummvm/trunk/engines/cruise/vars.cpp
    scummvm/trunk/engines/cruise/vars.h

Modified: scummvm/trunk/engines/cruise/actor.cpp
===================================================================
--- scummvm/trunk/engines/cruise/actor.cpp	2007-12-27 16:40:58 UTC (rev 30014)
+++ scummvm/trunk/engines/cruise/actor.cpp	2007-12-27 17:37:38 UTC (rev 30015)
@@ -340,12 +340,12 @@
 		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 @@
 				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 @@
 
 		// 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 @@
 	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;
 

Modified: scummvm/trunk/engines/cruise/ctp.cpp
===================================================================
--- scummvm/trunk/engines/cruise/ctp.cpp	2007-12-27 16:40:58 UTC (rev 30014)
+++ scummvm/trunk/engines/cruise/ctp.cpp	2007-12-27 17:37:38 UTC (rev 30015)
@@ -45,7 +45,7 @@
 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 @@
 		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;
+void computeAllDistance(int16 table[][10], short int coordCount) {
+	for(int i=0; i<coordCount; i++) {
+		int x1 = ctp_routeCoords[i][0];
+		int y1 = ctp_routeCoords[i][1];
 
-	short int *cur_ctp_routeCoords = (short int *)ctp_routeCoords;	// coordinates table
-	int8 *cur_ctp_routes = (int8 *) ctp_routes;
+		for(int j=0; j<ctp_routes[i][0]; j++) {
+			int p = ctp_routes[i][j+1];
 
-	for (i = 0; i < coordCount; i++) {	// for i < ctp_routeCoordCount
-		int varX = cur_ctp_routeCoords[0];	// x
-		int varY = cur_ctp_routeCoords[1];	// y 
+			int x2 = ctp_routeCoords[p][0];
+			int y2 = ctp_routeCoords[p][1];
 
-		int di = 0;
-		int var4Offset = 2;
-
-		while (*(int16 *) cur_ctp_routes > 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]);
-
-			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 @@
 // 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 @@
 		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 @@
 	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 @@
 
 	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;
 

Modified: scummvm/trunk/engines/cruise/ctp.h
===================================================================
--- scummvm/trunk/engines/cruise/ctp.h	2007-12-27 16:40:58 UTC (rev 30014)
+++ scummvm/trunk/engines/cruise/ctp.h	2007-12-27 17:37:38 UTC (rev 30015)
@@ -52,9 +52,11 @@
 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
 

Modified: scummvm/trunk/engines/cruise/function.cpp
===================================================================
--- scummvm/trunk/engines/cruise/function.cpp	2007-12-27 16:40:58 UTC (rev 30014)
+++ scummvm/trunk/engines/cruise/function.cpp	2007-12-27 17:37:38 UTC (rev 30015)
@@ -1468,15 +1468,18 @@
 	return 0;
 }
 
+int16 Op_SetNodeState(void) {
+	int16 state = popVar();
+	int16 node = popVar();
+
+	return setNodeState(node, state);
+}
+
 int16 Op_SetNodeColor(void) {
-	int16 color;
-	int16 node;
+	int16 color = popVar();
+	int16 node = popVar();
 
-	color = popVar();
-	node = popVar();
-	printf("Unimplemented \"Op_SetNodeColor\"\n");
-
-	return 0;
+	return setNodeColor(node, color);
 }
 
 int16 Op_SetXDial(void) {
@@ -1587,7 +1590,7 @@
 	Op_RemoveAnimation,
 	Op_SetZoom,
 	Op_SetObjectAtNode,
-	NULL, // setNodeState, never used ?
+	Op_SetNodeState,
 	Op_SetNodeColor,
 	Op_TrackAnim,
 	Op_GetNodeX,

Modified: scummvm/trunk/engines/cruise/vars.cpp
===================================================================
--- scummvm/trunk/engines/cruise/vars.cpp	2007-12-27 16:40:58 UTC (rev 30014)
+++ scummvm/trunk/engines/cruise/vars.cpp	2007-12-27 17:37:38 UTC (rev 30015)
@@ -169,10 +169,8 @@
 int16 ctp_walkboxTable[15][40];	// ctpVar5
 int16 walkboxColorIndex[16];
 int16 walkboxZoom[15];		//  ctpVar7
-int16 ctpVar8[200];
+int16 distanceTable[20][10];
 
-int16 ctpVar14;
-
 int16 flagSpeed;
 int16 speedGame;
 int16 oldSpeedGame;

Modified: scummvm/trunk/engines/cruise/vars.h
===================================================================
--- scummvm/trunk/engines/cruise/vars.h	2007-12-27 16:40:58 UTC (rev 30014)
+++ scummvm/trunk/engines/cruise/vars.h	2007-12-27 17:37:38 UTC (rev 30015)
@@ -282,10 +282,8 @@
 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 distanceTable[20][10];
 
-extern int16 ctpVar14;
-
 extern int16 flagSpeed;
 extern int16 speedGame;
 extern int16 oldSpeedGame;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list