bool PathMap::jump(Point &jumppoint, int cx, int cy, int px, int py, int goalx, int goaly){
Point jx(0, 0), jy(0, 0);
bool bjx=false, bjy=false;
if(!IsTypeWalkable(Map[cy][cx])){
return false;
}
if(cx==goalx&&cy==goaly){
jumppoint.X=goalx; jumppoint.Y=goaly; return true;
}
int dx=cx-px; int dy=cy-py;
if(cx+dx<0||cx+dx>SizeX-1||cy+dy<0||cy+dy>SizeY-1||
cx-dx<0||cx-dx>SizeX-1||cy-dy<0||cy-dy>SizeY-1){
return false;
}
if(dx!=0&&dy!=0){
if(IsTypeWalkable(Map[cy+dy][cx+dx])&&IsTypeWalkable(Map[cy][cx+dx])&&!IsTypeWalkable(Map[cy+dy][cx])||
IsTypeWalkable(Map[cy+dy][cx+dx])&&IsTypeWalkable(Map[cy+dy][cx])&&!IsTypeWalkable(Map[cy][cx+dx])){
jumppoint.X=cx; jumppoint.Y=cy; return true;
}
}else{
if(dx!=0){
if(IsTypeWalkable(Map[cy-1][cx])&&!IsTypeWalkable(Map[cy-1][cx-dx])){
jumppoint.X=cx; jumppoint.Y=cy; return true;
}
if(IsTypeWalkable(Map[cy+1][cx])&&!IsTypeWalkable(Map[cy+1][cx-dx])){
jumppoint.X=cx; jumppoint.Y=cy; return true;
}
}else{
if(IsTypeWalkable(Map[cy][cx-1])&&!IsTypeWalkable(Map[cy-dy][cx-1])){
jumppoint.X=cx; jumppoint.Y=cy; return true;
}
if(IsTypeWalkable(Map[cy][cx+1])&&!IsTypeWalkable(Map[cy-dy][cx+1])){
jumppoint.X=cx; jumppoint.Y=cy; return true;
}
}
if(dx!=0&&dy!=0){
bjx=jump(jx, cx+dx, cy, cx, cy, goalx, goaly);
bjy=jump(jy, cx, cy+dy, cx, cy, goalx, goaly);
if(bjx || bjy){
jumppoint.X=cx; jumppoint.Y=cy; return true;
}
}
if(IsTypeWalkable(Map[cy+dy][cx])&&IsTypeWalkable(Map[cy][cx+dx])){
return jump(jumppoint, cx+dx, cy+dy, cx, cy, goalx, goaly);
}else{
return false;
}
}
}
void PathMap::seekPoints(PointParented* parent, int goalx, int goaly){
int k=-1; int q=-1;
bool goodJump=false;
double cg=0;
vector<Point> neighbors;
Point jumpPoint(0, 0);
neighbors=getNeighbors(parent, goalx, goaly);
if(!neighbors.empty()){
for(int i=0; i<neighbors.size(); i++){
goodJump=jump(jumpPoint, neighbors[i].X, neighbors[i].Y, parent->X, parent->Y, goalx, goaly);
if(goodJump){
k=IsPointInList(CloseList, jumpPoint.X, jumpPoint.Y);
if(k==-1){
q=IsPointInList(OpenList, jumpPoint.X, jumpPoint.Y);
cg=parent->CostG+GetDistance(parent->X, parent->Y, jumpPoint.X, jumpPoint.Y);
if(q==-1){
OpenList.push_back(new PointParented(parent, SizeX, jumpPoint.X, jumpPoint.Y, cg, GetDistance(jumpPoint.X, jumpPoint.Y, goalx, goaly)));
}else{
if(cg<OpenList[q]->CostG){
OpenList[q]->CostG=cg;
OpenList[q]->CostT=OpenList[q]->CostG+OpenList[q]->CostH;
OpenList[q]->Parent=parent;
}
}
}
}
goodJump=false;
}
}
}
Проблема с передачей значения
Код:
Сразу поправлюсь - пишу на плюсах, а не C.