Nearly working pathfinder
svn-id: r30015
This commit is contained in:
parent
1312d4b3fd
commit
c87ad51470
6 changed files with 67 additions and 63 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
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 @@ 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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1468,15 +1468,18 @@ int16 Op_SongExist(void) {
|
|||
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 @@ opcodeFunction opcodeTablePtr[] =
|
|||
Op_RemoveAnimation,
|
||||
Op_SetZoom,
|
||||
Op_SetObjectAtNode,
|
||||
NULL, // setNodeState, never used ?
|
||||
Op_SetNodeState,
|
||||
Op_SetNodeColor,
|
||||
Op_TrackAnim,
|
||||
Op_GetNodeX,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue