void CalcPathJob::Execute(){

	if (myPath){

		CalcPath(*myPath, myMap, start, goal, ignoreEntities);
	
		if (myPath->m_isComplete){
			myPath->SetPathFound();
			if (myPath->m_pathFound.empty()){
				myPath->m_isImpossible = true;
			}
		}
	}

}
Example #2
0
NodeList_t& AStar::FindPath()
{
	Reset();

	FoundPath = false;

	//Msg("Reset Variables: %i, %i, %i\n", Path.Count(), Opened.Count(), Closed.Count());

	if(GetStart() == GetEnd())
	{
		//Msg("Start Is End\n");
		return Path;
	}

	// 1) Add the starting node to the open list.
	AddOpenedNode(Start);
	Start->SetStatus(NULL, 0, 0, 0);

	float CurrentScoreG;
	float ScoreF, ScoreG, ScoreH;
	NodeList_t Links;
	AStarNode *Current = NULL, *LastNode = NULL, *Link = NULL;

	//Msg("Added Node\n");

	// 2) Repeat the following:
	while(true)
	{
		// a) Look for the lowest F cost square on the open list. We refer to this as the current square.
		Current = FindLowestF();

		if(Current != NULL)
		{
			LastNode = Current;

			if(Current->GetPos() == End->GetPos())
			{
				FoundPath = true;
				break;
			}
			else
			{
				CurrentScoreG = Current->GetScoreG();

				// b) Switch it to the closed list.
				AddClosedNode(Current);

				// c) For each of the nodes linked to this node...
				Links = Current->GetLinks();

				ScoreH = HeuristicDistance(Current->GetPos(), End->GetPos());

				//Msg("Found Lowest F: %i | %f, %f, %f\n", Links.Count(), Current->GetPos().x, Current->GetPos().y, Current->GetPos().z);

				for(int i = 0; i < Links.Count(); i++)
				{
					Link = Links[i];

					if(Link != NULL)
					{

						// If it is not walkable or if it is on the closed list, ignore it.
						if(!Link->IsClosed())
						{

							// If it isn’t on the open list, add it to the open list. Make the current node the parent of this node. Record the F, G, and H costs of the node. 
							if(!Link->IsOpened())
							{
								//Msg("SetStatus\n");
								AddOpenedNode(Link);
								ScoreG = CurrentScoreG + HeuristicDistance(Current->GetPos(), Link->GetPos());
								ScoreF = ScoreG + ScoreH;
								Link->SetStatus(Current, ScoreF, ScoreG, ScoreH);
							}

							//if(Link->Opened()) Always true?
							//{
								if(CurrentScoreG > ScoreG)
								{
									Link->SetParent(Current);
									//Msg("Set Parent\n");
								}
								else
								{
									//Msg("%f | %f\n", CurrentScoreG, ScoreG);
								}
							//}
						}
					}
				}
			}
		}
		else
		{
			//Msg("Failed to find Lowest F\n");
			break;
		}
	}

	return CalcPath(LastNode);
}