server/src/vendor/navigation/Navigation/Source/navigation_tile_handle.cpp
bool NavTileHandle::MapSearchNode::GetSuccessors(AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node)
{
	int parent_x = -1; 
	int parent_y = -1; 

	if( parent_node )
	{
		parent_x = parent_node->x;
		parent_y = parent_node->y;
	}
	
	MapSearchNode NewNode;

	// push each possible move except allowing the search to go backwards

	if( (NavTileHandle::pCurrNavTileHandle->getMap( x-1, y ) < TILE_STATE_CLOSED) 
		&& !((parent_x == x-1) && (parent_y == y))
	  ) 
	{
		NewNode = MapSearchNode( x-1, y );
		astarsearch->AddSuccessor( NewNode );
	}	

	if( (NavTileHandle::pCurrNavTileHandle->getMap( x, y-1 ) < TILE_STATE_CLOSED) 
		&& !((parent_x == x) && (parent_y == y-1))
	  ) 
	{
		NewNode = MapSearchNode( x, y-1 );
		astarsearch->AddSuccessor( NewNode );
	}	

	if( (NavTileHandle::pCurrNavTileHandle->getMap( x+1, y ) < TILE_STATE_CLOSED)
		&& !((parent_x == x+1) && (parent_y == y))
	  ) 
	{
		NewNode = MapSearchNode( x+1, y );
		astarsearch->AddSuccessor( NewNode );
	}
		
	if( (NavTileHandle::pCurrNavTileHandle->getMap( x, y+1 ) < TILE_STATE_CLOSED) 
		&& !((parent_x == x) && (parent_y == y+1))
		)
	{
		NewNode = MapSearchNode( x, y+1 );
		astarsearch->AddSuccessor( NewNode );
	}	

	// 如果是8方向移动
	if(NavTileHandle::pCurrNavTileHandle->direction8())
	{
		if( (NavTileHandle::pCurrNavTileHandle->getMap( x + 1, y + 1 ) < TILE_STATE_CLOSED) 
			&& !((parent_x == x + 1) && (parent_y == y + 1))
		  ) 
		{
			NewNode = MapSearchNode( x + 1, y + 1 );
			astarsearch->AddSuccessor( NewNode );
		}	

		if( (NavTileHandle::pCurrNavTileHandle->getMap( x + 1, y-1 ) < TILE_STATE_CLOSED) 
			&& !((parent_x == x + 1) && (parent_y == y-1))
		  ) 
		{
			NewNode = MapSearchNode( x + 1, y-1 );
			astarsearch->AddSuccessor( NewNode );
		}	

		if( (NavTileHandle::pCurrNavTileHandle->getMap( x - 1, y + 1) < TILE_STATE_CLOSED)
			&& !((parent_x == x - 1) && (parent_y == y + 1))
		  ) 
		{
			NewNode = MapSearchNode( x - 1, y + 1);
			astarsearch->AddSuccessor( NewNode );
		}	

		if( (NavTileHandle::pCurrNavTileHandle->getMap( x - 1, y - 1 ) < TILE_STATE_CLOSED) 
			&& !((parent_x == x - 1) && (parent_y == y - 1))
			)
		{
			NewNode = MapSearchNode( x - 1, y - 1 );
			astarsearch->AddSuccessor( NewNode );
		}	
	}

	return true;
}
//-------------------------------------------------------------------------------------
// This generates the successors to the given Node. It uses a helper function called
// AddSuccessor to give the successors to the AStar class. The A* specific initialisation
// is done for each node internally, so here you just set the state information that
// is specific to the application
This generates the successors to the given Node. It uses a helper function called
AddSuccessor to give the successors to the AStar class. The A* specific initialisation
is done for each node internally, so here you just set the state information that
is specific to the application
This generates the successors to the given Node . It uses a helper function called AddSuccessor to give the successors to the AStar class . The A * specific initialisation is done for each node internally so here you just set the state information that is specific to the application
bool NavTileHandle::MapSearchNode::GetSuccessors(AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node)
{
	int parent_x = -1; 
	int parent_y = -1; 
	if( parent_node )
	{
		parent_x = parent_node->x;
		parent_y = parent_node->y;
	}
	MapSearchNode NewNode;
	if( (NavTileHandle::pCurrNavTileHandle->getMap( x-1, y ) < TILE_STATE_CLOSED) 
		&& !((parent_x == x-1) && (parent_y == y))
	  ) 
	{
		NewNode = MapSearchNode( x-1, y );
		astarsearch->AddSuccessor( NewNode );
	}	
	if( (NavTileHandle::pCurrNavTileHandle->getMap( x, y-1 ) < TILE_STATE_CLOSED) 
		&& !((parent_x == x) && (parent_y == y-1))
	  ) 
	{
		NewNode = MapSearchNode( x, y-1 );
		astarsearch->AddSuccessor( NewNode );
	}	
	if( (NavTileHandle::pCurrNavTileHandle->getMap( x+1, y ) < TILE_STATE_CLOSED)
		&& !((parent_x == x+1) && (parent_y == y))
	  ) 
	{
		NewNode = MapSearchNode( x+1, y );
		astarsearch->AddSuccessor( NewNode );
	}
	if( (NavTileHandle::pCurrNavTileHandle->getMap( x, y+1 ) < TILE_STATE_CLOSED) 
		&& !((parent_x == x) && (parent_y == y+1))
		)
	{
		NewNode = MapSearchNode( x, y+1 );
		astarsearch->AddSuccessor( NewNode );
	}	
	if(NavTileHandle::pCurrNavTileHandle->direction8())
	{
		if( (NavTileHandle::pCurrNavTileHandle->getMap( x + 1, y + 1 ) < TILE_STATE_CLOSED) 
			&& !((parent_x == x + 1) && (parent_y == y + 1))
		  ) 
		{
			NewNode = MapSearchNode( x + 1, y + 1 );
			astarsearch->AddSuccessor( NewNode );
		}	
		if( (NavTileHandle::pCurrNavTileHandle->getMap( x + 1, y-1 ) < TILE_STATE_CLOSED) 
			&& !((parent_x == x + 1) && (parent_y == y-1))
		  ) 
		{
			NewNode = MapSearchNode( x + 1, y-1 );
			astarsearch->AddSuccessor( NewNode );
		}	
		if( (NavTileHandle::pCurrNavTileHandle->getMap( x - 1, y + 1) < TILE_STATE_CLOSED)
			&& !((parent_x == x - 1) && (parent_y == y + 1))
		  ) 
		{
			NewNode = MapSearchNode( x - 1, y + 1);
			astarsearch->AddSuccessor( NewNode );
		}	
		if( (NavTileHandle::pCurrNavTileHandle->getMap( x - 1, y - 1 ) < TILE_STATE_CLOSED) 
			&& !((parent_x == x - 1) && (parent_y == y - 1))
			)
		{
			NewNode = MapSearchNode( x - 1, y - 1 );
			astarsearch->AddSuccessor( NewNode );
		}	
	}
	return true;
}
bool NavTileHandle :: MapSearchNode :: GetSuccessors ( AStarSearch < MapSearchNode > * astarsearch , MapSearchNode * parent_node ) { int parent_x = -1 ; int parent_y = -1 ; if ( parent_node ) { parent_x = parent_node -> x ; parent_y = parent_node -> y ; } MapSearchNode NewNode ; if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x - 1 , y ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x - 1 ) && ( parent_y == y ) ) ) { NewNode = MapSearchNode ( x - 1 , y ) ; astarsearch -> AddSuccessor ( NewNode ) ; } if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x , y - 1 ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x ) && ( parent_y == y - 1 ) ) ) { NewNode = MapSearchNode ( x , y - 1 ) ; astarsearch -> AddSuccessor ( NewNode ) ; } if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x + 1 , y ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x + 1 ) && ( parent_y == y ) ) ) { NewNode = MapSearchNode ( x + 1 , y ) ; astarsearch -> AddSuccessor ( NewNode ) ; } if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x , y + 1 ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x ) && ( parent_y == y + 1 ) ) ) { NewNode = MapSearchNode ( x , y + 1 ) ; astarsearch -> AddSuccessor ( NewNode ) ; } if ( NavTileHandle :: pCurrNavTileHandle -> direction8 ( ) ) { if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x + 1 , y + 1 ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x + 1 ) && ( parent_y == y + 1 ) ) ) { NewNode = MapSearchNode ( x + 1 , y + 1 ) ; astarsearch -> AddSuccessor ( NewNode ) ; } if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x + 1 , y - 1 ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x + 1 ) && ( parent_y == y - 1 ) ) ) { NewNode = MapSearchNode ( x + 1 , y - 1 ) ; astarsearch -> AddSuccessor ( NewNode ) ; } if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x - 1 , y + 1 ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x - 1 ) && ( parent_y == y + 1 ) ) ) { NewNode = MapSearchNode ( x - 1 , y + 1 ) ; astarsearch -> AddSuccessor ( NewNode ) ; } if ( ( NavTileHandle :: pCurrNavTileHandle -> getMap ( x - 1 , y - 1 ) < TILE_STATE_CLOSED ) && ! ( ( parent_x == x - 1 ) && ( parent_y == y - 1 ) ) ) { NewNode = MapSearchNode ( x - 1 , y - 1 ) ; astarsearch -> AddSuccessor ( NewNode ) ; } } return true ; }
This generates the successors to the given Node.
This generates the successors to the given Node .
// push each possible move except allowing the search to go backwards // 如果是8方向移动