static void DumpPaths( int pinx ) { pathNode_p pPath; trackep_p pTrackep; int tinx; lprintf(" Current = %d\n", pinx ); for (pinx=0; pinx<pathNode_da.cnt; pinx++) { pPath = &pathNode(pinx); lprintf( " %3d: S%c T%d:%d D%0.3f T%d:%d", pinx, pPath->state==Unknown?'U':pPath->state==Working?'W':pPath->state==Final?'F':'?', (pPath->contTrk?GetTrkIndex(pPath->contTrk):-1), pPath->contEP, pPath->dist, pPath->inxTracks, pPath->numTracks ); if (pPath->inxBack>=0) { lprintf(" B%d", pPath->inxBack ); } lprintf("\n "); for (tinx=0; tinx<pPath->numTracks; tinx++) { pTrackep = &trackep(pPath->inxTracks+tinx); lprintf( " T%d:%d-%d=%0.1f", GetTrkIndex(pTrackep->trk), pTrackep->ep1, pTrackep->ep2, pTrackep->dist ); } lprintf("\n"); } }
uint pathNode::findWalkableAdjacents(pathList& list_to_fill) const { uint items_before = list_to_fill.list.count(); iPoint new_pos; uint items_added = 0; //LOG(" Origin position : %d,%d", pos.x, pos.y); //Nodes-- > North, West, South, East new_pos.set(pos.x, pos.y - 1); //LOG(" Tile %d,%d -> Walkability = %d", new_pos.x, new_pos.y, app->path->isWalkable(new_pos)); if (app->path->isWalkable(new_pos)) { //pathNode node_N(-1, -1, new_pos, this); items_added++; list_to_fill.list.add(pathNode(-1, -1, new_pos, this)); } new_pos.set(pos.x - 1, pos.y); //LOG(" Tile %d,%d -> Walkability = %d", new_pos.x, new_pos.y, app->path->isWalkable(new_pos)); if (app->path->isWalkable(new_pos)) { //pathNode node_W(-1, -1, new_pos, this); items_added++; list_to_fill.list.add(pathNode(-1, -1, new_pos, this)); } new_pos.set(pos.x, pos.y + 1); //LOG(" Tile %d,%d -> Walkability = %d", new_pos.x, new_pos.y, app->path->isWalkable(new_pos)); if (app->path->isWalkable(new_pos)) { //pathNode node_S(-1, -1, new_pos, this); items_added++; list_to_fill.list.add(pathNode(-1, -1, new_pos, this)); } new_pos.set(pos.x + 1, pos.y); //LOG(" Tile %d,%d -> Walkability = %d", new_pos.x, new_pos.y, app->path->isWalkable(new_pos)); if (app->path->isWalkable(new_pos)) { //pathNode node_E(-1, -1, new_pos, this); items_added++; list_to_fill.list.add(pathNode(-1, -1, new_pos, this)); } //LOG(" ------------------------- "); return items_added - items_before; }
static void AddTracksToPath( int inxCurr, shortestPathFunc_p func, void * data ) { pathNode_p pPath; int tinx; trackep_p pTrackep; while (inxCurr>=0) { pPath = &pathNode(inxCurr); for (tinx=pPath->numTracks-1;tinx>=0;tinx--) { pTrackep = &trackep(pPath->inxTracks+tinx); DoShortPathFunc( func, "ADDTRK", SPTC_ADD_TRK, pTrackep->trk, pTrackep->ep1, pTrackep->ep2, pTrackep->dist, data ); } inxCurr = pPath->inxBack; } }
void GameControllerAttachment::sceneFileConfig() { QDomDocument sceneFile(m_sceneFile->sceneFileDom()); QDomElement pathNode(sceneFile.documentElement().firstChildElement("EnginePath")); // Create a wizard for the configuration of the directories QWizard wizard; PathPage* page = new PathPage(&wizard); page->setDirectories( pathNode.attribute("mediapath"), pathNode.attribute("scriptpath") ); wizard.addPage(page); if (wizard.exec() == QDialog::Accepted) { pathNode.setAttribute("mediapath", wizard.field("mediadir").toString()); pathNode.setAttribute("scriptpath", wizard.field("scriptdir").toString()); } }
int PathFinding::createPath(const iPoint& origin, const iPoint& destination) { // Origin and destination are walkable? if (!isWalkable(origin) || !isWalkable(destination)) return -1; path_found.clear(); // Open and close list pathList open_list, close_list; open_list.list.add(pathNode(0, 0, origin, NULL)); while (open_list.list.count() > 0) { doubleNode<pathNode> *pnode = open_list.getNodeLowestScore(); close_list.list.add(pnode->data); iPoint pos = pnode->data.pos; open_list.list.del(pnode); pnode = close_list.find(pos); if (pnode->data.pos == destination) { close_list.list.add(pnode->data); break; } pathList candidate_nodes; int items_added = pnode->data.findWalkableAdjacents(candidate_nodes); doubleNode<pathNode> *item = candidate_nodes.list.getLast(); for (int i = 0; i < items_added; i++) { if (close_list.find(item->data.pos)) { item = item->previous; continue; } else if (open_list.find(item->data.pos)) { doubleNode<pathNode> *to_compare = open_list.find(item->data.pos); if (item->data.calculateF(destination) < to_compare->data.score()) { to_compare->data.parent = item->data.parent; to_compare->data.calculateF(destination); } } else { item->data.calculateF(destination); open_list.list.add(item->data); } item = item->previous; } } const pathNode *item = &(close_list.list.getLast()->data); while (item != NULL) { path_found.pushBack(item->pos); item = item->parent; } path_found.flip(); return path_found.getNumElements(); }
} goto makeNode; } ep2 = 1-ep1; } makeNode: if ( trk ) { LOG( log_shortPath, 2, ( " -> FORK: [%d] T%d:%d", pathNode_da.cnt, GetTrkIndex(trk), ep1 ) ) } else { LOG( log_shortPath, 2, ( " -> MATCH%s: [%d]", msg, pathNode_da.cnt ) ) } LOG( log_shortPath, 2, ( " t%d D=%0.3f\n", startTrack, dist ) ) DYNARR_APPEND( pathNode_t, pathNode_da, 10 ); pNode = &pathNode(pathNode_da.cnt-1); pNode->state = Working; pNode->dist = dist; pNode->contTrk = trk; pNode->contEP = ep1; pNode->inxBack = inxCurr; pNode->inxTracks = startTrack; pNode->numTracks = trackep_da.cnt-startTrack; if ( trk ) SetTrkBits( trk, TB_SHRTPATH ); return TRUE; skipNode: LOG( log_shortPath, 2, ( " -> FAIL: %s @ T%d:%d.%d\n", msg, GetTrkIndex(trk), ep1, ep2 ) ) trackep_da.cnt = startTrack; return FALSE;