From d649c3058bc6d9afc1c677923fca8c5bfcc65724 Mon Sep 17 00:00:00 2001 From: johns <> Date: Mon, 26 Feb 2001 21:48:06 +0000 Subject: [PATCH] NEW_ORDERS prepared. --- src/pathfinder/astar.cpp | 57 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/src/pathfinder/astar.cpp b/src/pathfinder/astar.cpp index 6753f3c32..61b549ae3 100644 --- a/src/pathfinder/astar.cpp +++ b/src/pathfinder/astar.cpp @@ -324,11 +324,17 @@ local int AStarFindPath(Unit* unit,int* pxd,int* pyd) /* AStarPrepare();*/ x=unit->X; y=unit->Y; - r=unit->Command.Data.Move.Range; goal_reachable=0; +#ifdef NEW_ORDERS + r=unit->Orders[0].RangeX; + goal=unit->Orders[0].Goal; +#else + r=unit->Command.Data.Move.Range; + goal=unit->Command.Data.Move.Goal; +#endif + // Let's first mark goal - if(unit->Command.Data.Move.Goal) { - goal=unit->Command.Data.Move.Goal; + if(goal) { j=goal->Type->Type; cx=goal->X; cy=goal->Y; @@ -338,8 +344,13 @@ local int AStarFindPath(Unit* unit,int* pxd,int* pyd) gx=goal->X+UnitTypes[j].TileHeight/2; gy=goal->Y+UnitTypes[j].TileWidth/2; } else { +#ifdef NEW_ORDERS + cx=gx=unit->Orders[0].X; + cy=gy=unit->Orders[0].Y; +#else cx=gx=unit->Command.Data.Move.DX; cy=gy=unit->Command.Data.Move.DY; +#endif ey=r; sx=r; r=0; @@ -500,10 +511,17 @@ local int AStarFindPath(Unit* unit,int* pxd,int* pyd) // if the goal was not reachable, we replace it by the best point // this will speed up next path finding if(!goal_reachable) { +#ifdef NEW_ORDERS + unit->Orders[0].Goal=0; + unit->Orders[0].X=ex; + unit->Orders[0].Y=ey; + ResetPath(unit->Orders[0]); +#else unit->Command.Data.Move.Goal=0; unit->Command.Data.Move.DX=ex; unit->Command.Data.Move.DY=ey; ResetPath(unit->Command); +#endif } // now we need to backtrack path_length=0; @@ -560,10 +578,19 @@ global int AStarNextPathElement(Unit* unit,int* pxd,int *pyd) // needed? int x; int y; - int r=unit->Command.Data.Move.Range; - Unit* goal=unit->Command.Data.Move.Goal; + int r; + Unit* goal; UnitType* type; +#ifdef NEW_ORDERS + DebugCheck( unit->Orders[0].RangeX!=unit->Orders[0].RangeY ); + + r=unit->Orders[0].RangeX; + goal=unit->Orders[0].Goal; +#else + r=unit->Command.Data.Move.Range; + goal=unit->Command.Data.Move.Goal; +#endif x=unit->X; y=unit->Y; if( goal ) { // goal unit @@ -580,6 +607,25 @@ global int AStarNextPathElement(Unit* unit,int* pxd,int *pyd) return -1; } } else { // goal map field +#ifdef NEW_ORDERS + if( x>=unit->Orders[0].X && x<=unit->Orders[0].X+r + && y>=unit->Orders[0].Y && y<=unit->Orders[0].Y+r ) { + DebugLevel3Fn("Field reached\n"); + *pxd=*pyd=0; + return -1; + } + // This reduces the processor use, + // If target isn't reachable and were beside it + if( r==0 && x>=unit->Orders[0].X-1 && x<=unit->Orders[0].X+1 + && y>=unit->Orders[0].Y-1 && y<=unit->Orders[0].Y+1 ) { + if( !CheckedCanMoveToMask(unit->Orders[0].X,unit->Orders[0].Y + ,UnitMovementMask(unit)) ) { // blocked + DebugLevel3Fn("Field unreached\n"); + *pxd=*pyd=0; + return -2; + } + } +#else if( x>=unit->Command.Data.Move.DX && x<=unit->Command.Data.Move.DX+r && y>=unit->Command.Data.Move.DY @@ -602,6 +648,7 @@ global int AStarNextPathElement(Unit* unit,int* pxd,int *pyd) return -2; } } +#endif } return AStarFindPath(unit,pxd,pyd);