void NPC::TaskBase(void) { if (m_goalWaypointAPI != -1) { if (m_goalWaypointAPI != m_goalWaypoint) { DeleteSearchNodes(); m_goalWaypoint = m_goalWaypointAPI; } } if (DoWaypointNav()) { m_goalWaypoint = -1; if (m_goalWaypointAPI != -1 && m_goalWaypointAPI == m_currentWaypointIndex) m_goalWaypointAPI = -1; } if (!GoalIsValid()) { if (m_goalWaypoint == -1) m_goalWaypoint = RANDOM_LONG(0, g_numWaypoints - 1); FindWaypoint(); DeleteSearchNodes(); FindShortestPath(m_currentWaypointIndex, m_goalWaypoint); } }
static int FindProfileShortestPath( track_p trkN, EPINX_T epN ) { LOG( log_profile, 4, ( "Searching from T%d:%d to T%d:%d or T%d:%d\n", GetTrkIndex(trkN), epN, pathStartTrk?GetTrkIndex(pathStartTrk):-1, pathStartTrk?pathStartEp:-1, pathEndTrk?GetTrkIndex(pathEndTrk):-1, pathEndTrk?pathEndEp:-1 ) ) profileShortestPathMatch = -1; return FindShortestPath( trkN, epN, TRUE, ProfileShortestPathFunc, NULL ); }
void NPC::TaskMoveTarget(void) { if (FNullEnt(m_moveTargetEntity)) return; if (DoWaypointNav()) DeleteSearchNodes(); int destIndex = g_waypoint->GetEntityWpIndex(m_moveTargetEntity); if (destIndex >= 0 && destIndex < g_numWaypoints) { bool moveToTarget = false; if (&m_navNode[0] != null) { PathNode *node = m_navNode; while (node->next != null) node = node->next; if (node->index == destIndex) moveToTarget = true; } if (!GoalIsValid() || (m_goalWaypoint != destIndex && !moveToTarget)) { int srcIndex = m_currentWaypointIndex; if (m_currentWaypointIndex != g_waypoint->GetEntityWpIndex(GetEntity())) { if (*(g_waypoint->m_distMatrix + (m_currentWaypointIndex * g_numWaypoints) + destIndex) <= *(g_waypoint->m_distMatrix + (g_waypoint->GetEntityWpIndex(GetEntity()) * g_numWaypoints) + destIndex)) srcIndex = m_currentWaypointIndex; else srcIndex = g_waypoint->GetEntityWpIndex(GetEntity()); } DeleteSearchNodes(); m_currentWaypointIndex = srcIndex; m_navTime = gpGlobals->time + 5.0f; SetWaypointOrigin(); m_goalWaypoint = destIndex; FindShortestPath(m_currentWaypointIndex, m_goalWaypoint); } if (m_currentWaypointIndex == m_goalWaypoint) SetEnemy(m_moveTargetEntity); } }
void CriticalPoint::TraceLine() { /* TraceLine : from each saddle point, find its corresponding four max-min points */ for(set<size_t>::iterator it=p_SadPointID->begin(); it!=p_SadPointID->end(); ++it) { M_Point& sadPoint = *(m_vtx[*it]); TraceLineFromSaddle(dynamic_cast<SadPoint&>(sadPoint)); TraceLine4MaxMin(dynamic_cast<SadPoint&>(sadPoint)); } for(map<MaxMinPair,IndexArray>::iterator im = p_DualConn->begin(); im!=p_DualConn->end(); ++im) { //Global::mesh->m_BasicOp.GetShortestPath( // (VertexID)(im->first).first, (VertexID)(im->first).second, im->second); FindShortestPath(m_vtx,(im->first).first, (im->first).second, im->second); } }
bool LeeRoutePlannerImpl::GetShortestPath( const GraphTypes::PointF& start, const GraphTypes::PointF& end, GraphTypes::PointFVector& path ) { bool bSuccess=m_bgrid; if ( bSuccess ) // make sure EndAddPoints was called { grid_vertex_descriptor from, to; from=PointF2Descriptor(start); to=PointF2Descriptor(end); if ( from!=to ) { grid_vertex_descriptor_vector vpath; grid_vertex_descriptor_vector::reverse_iterator ri, rend; FindShortestPath( from, to, vpath ); SetPathWeight( vpath ); if (vpath.size() >= 3) { grid_vertex_descriptor first; GraphTypes::PointF pt; Direction dir = dirNotSet, lastDir=dirNotSet; path.clear(); ri=vpath.rbegin(); rend=vpath.rend(); // don't store first and last points - they belong to vertices ++ri; --rend; first=from; for ( ; ri!=rend; ++ri) { Descriptor2PointF(*ri, pt); dir=GetDirection(first, *ri); if (dir==lastDir) // don't store colinear points path.pop_back(); path.push_back(pt); lastDir=dir; first=*ri; } dir=GetDirection(first, to); if (dir==lastDir) // don't store colinear points path.pop_back(); } else { bSuccess=false; } } } return bSuccess; }
void DoNonCombatAI(void) { static boolean waitpwall; word nowon, nexton, mypos, nx, ny; fixed nxd, nyd; byte tile; int tangle, dangle; boolean tryuse; objtype* check; static int inc; inc++; if(!destination) destination = FindShortestPath(); if(!destination) return; if(pwallstate) waitpwall = true; mypos = TILE_ENCODE(player->tilex, player->tiley); nowon = nexton = WORD_MAX; for(nowon = destination; nowon != WORD_MAX; nexton = nowon, nowon = path_prev[nowon]) { if(nowon == mypos) break; } if(nowon == WORD_MAX || (!pwallstate && waitpwall)) { waitpwall = false; destination = 0; return; } if(nexton == WORD_MAX) { // prevon = path_prev[nowon]; destination = 0; nx = pushtargetx; ny = pushtargety; } else { nx = TILE_DECODE_X(nexton); ny = TILE_DECODE_Y(nexton); tile = tilemap[nx][ny]; if(tile & 0x80) { tile &= ~0x80; if(!CanGoThruLockedDoor(tile)) { destination = 0; return; } tryuse = (doorobjlist[tile].action == dr_closed || doorobjlist[tile].action == dr_closing); } } tangle = DirAngle(player->x, player->y, ((fixed)nx << TILESHIFT) + TILEGLOBAL/2, ((fixed)ny << TILESHIFT) + TILEGLOBAL / 2); dangle = CentreAngle(tangle, player->angle); if(dangle > -ANGLE_FOV && dangle < ANGLE_FOV) { controly = -RUNMOVE * tics; if(tryuse) { check = actorat[nx][ny]; if(check && check < objlist && inc % 2) buttonstate[bt_use] = true; } } TurnToAngle(dangle); }