MCPcopy Create free account
hub / github.com/JACoders/OpenJK / FindPath

Method FindPath

code/game/g_navigator.cpp:2801–3062  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

2799//
2800////////////////////////////////////////////////////////////////////////////////////////
2801bool NAV::FindPath(gentity_t* actor, NAV::TNodeHandle target, float MaxDangerLevel)
2802{
2803 mUser.ClearActor();
2804
2805 // If Either Start Or End Is Invalid, We Can't Do Any Pathing
2806 //------------------------------------------------------------
2807 if (target==WAYPOINT_NONE)
2808 {
2809 return false;
2810 }
2811
2812 NAV::TNodeHandle start = GetNearestNode(actor, true, target);
2813 if (start==WAYPOINT_NONE)
2814 {
2815 return false;
2816 }
2817
2818 // Convert Edges To Points
2819 //------------------------
2820 if (start<0)
2821 {
2822 start = (Q_irand(0,1)==0)?(mGraph.get_edge(abs(start)).mNodeA):(mGraph.get_edge(abs(start)).mNodeB);
2823 }
2824 if (target<0)
2825 {
2826 target = (Q_irand(0,1)==0)?(mGraph.get_edge(abs(target)).mNodeA):(mGraph.get_edge(abs(target)).mNodeB);
2827 }
2828
2829 mUser.SetActor(actor);
2830
2831 // First Step: Find The Actor And Make Sure He Has A Path User Struct
2832 //--------------------------------------------------------------------
2833 int pathUserNum = mPathUserIndex[actor->s.number];
2834 if (pathUserNum==NULL_PATH_USER_INDEX)
2835 {
2836 if (mPathUsers.full())
2837 {
2838 assert("NAV: No more unused path users, possibly change MAX_PATH_USERS"==0);
2839 return false;
2840 }
2841
2842 pathUserNum = mPathUsers.alloc();
2843 mPathUsers[pathUserNum].mEnd = WAYPOINT_NONE;
2844 mPathUsers[pathUserNum].mSuccess = false;
2845 mPathUsers[pathUserNum].mLastAStarTime = 0;
2846 mPathUserIndex[actor->s.number] = pathUserNum;
2847 }
2848 SPathUser& puser = mPathUsers[pathUserNum];
2849 puser.mLastUseTime = level.time;
2850
2851
2852 // Now, Check To See If He Already Has Found A Path To This Target
2853 //-----------------------------------------------------------------
2854 if (puser.mEnd==target && level.time<puser.mLastAStarTime)
2855 {
2856 return puser.mSuccess;
2857 }
2858

Callers

nothing calls this directly

Calls 15

Q_irandFunction · 0.85
MoveTraceFunction · 0.85
ClearActorMethod · 0.80
SetActorMethod · 0.80
has_valid_edgeMethod · 0.80
SetDangerSpotMethod · 0.80
astarMethod · 0.80
ClearDangerSpotMethod · 0.80
successMethod · 0.80
path_beginMethod · 0.80
path_endMethod · 0.80
path_incMethod · 0.80

Tested by

no test coverage detected