Xonotic
pathlib.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEBUGPATHING   0
 
#define inwater(point)   (pointcontents(point) == CONTENT_WATER)
 

Functions

var bool buildpath_nodefilter (vector n, vector c, vector p)
 
var float pathlib_cost (entity parent, vector to, float static_cost)
 
var float pathlib_expandnode (entity node, vector start, vector goal)
 
float pathlib_expandnode_box (entity node, vector start, vector goal)
 
float pathlib_expandnode_star (entity node, vector start, vector goal)
 
vector pathlib_flynode (entity this, vector start, vector end, float doedge)
 
float pathlib_g_euclidean (entity parent, vector to, float static_cost)
 
float pathlib_g_euclidean_water (entity parent, vector to, float static_cost)
 
float pathlib_g_static (entity parent, vector to, float static_cost)
 
float pathlib_g_static_water (entity parent, vector to, float static_cost)
 
float pathlib_h_diagonal (vector a, vector b)
 This heuristic consider both straight and diagonal moves to have the same cost. More...
 
float pathlib_h_diagonal2 (vector a, vector b)
 This heuristic consider both straight and diagonal moves, but has a separate cost for diagonal moves. More...
 
float pathlib_h_diagonal2sdp (vector preprev, vector prev, vector point, vector end)
 This heuristic consider both straight and diagonal moves, But has a separate cost for diagonal moves. More...
 
float pathlib_h_diagonal3 (vector a, vector b)
 
float pathlib_h_euclidean (vector a, vector b)
 This heuristic only considers the straight line distance. More...
 
float pathlib_h_manhattan (vector a, vector b)
 Manhattan heuristic means we expect to move up, down left or right No diagonal moves expected. More...
 
float pathlib_h_none (vector preprev, vector prev)
 
var float pathlib_heuristic (vector from, vector to)
 
var bool pathlib_makenode (entity parent, vector start, vector to, vector goal, float cost)
 
var vector pathlib_movenode (entity this, vector start, vector end, float doedge)
 
vector pathlib_swimnode (entity this, vector start, vector end, float doedge)
 
vector pathlib_walknode (entity this, vector start, vector end, float doedge)
 
vector pathlib_wateroutnode (entity this, vector start, vector end, float doedge)
 
var float pathlib_wpp_waypointcallback (entity wp, entity wp_prev)
 
 STATIC_INIT (g_pathlib_nodes)
 
var bool tile_check (entity this, vector where)
 
bool tile_check_cross (entity this, vector where)
 
bool tile_check_plus (entity this, vector where)
 
bool tile_check_star (entity this, vector where)
 

Variables

entity best_open_node
 
entity closedlist
 
IntrusiveList g_pathlib_nodes
 
entity goal_node
 
bool is_path_node
 
vector movenode_boxmax
 
vector movenode_boxmin
 
vector movenode_boxup
 
vector movenode_maxdrop
 
float movenode_stepsize
 
vector movenode_stepup
 
entity openlist
 
entity path_next
 
entity path_prev
 
float pathlib_bestcash_hits
 
float pathlib_bestcash_saved
 
float pathlib_bestopen_searched
 
float pathlib_closed_cnt
 
float pathlib_foundgoal
 
float pathlib_gridsize
 
entity pathlib_list
 
float pathlib_made_cnt
 
const float pathlib_maxtime = 60
 
float pathlib_merge_cnt
 
float pathlib_movecost
 
float pathlib_movecost_diag
 
float pathlib_movecost_waterfactor
 
bool pathlib_movenode_goodnode
 
float pathlib_node_c
 
const float pathlib_node_edgeflag_back = BIT(4)
 
const float pathlib_node_edgeflag_backleft = BIT(5)
 
const float pathlib_node_edgeflag_backright = BIT(6)
 
const float pathlib_node_edgeflag_forward = BIT(3)
 
const float pathlib_node_edgeflag_forwardleft = BIT(7)
 
const float pathlib_node_edgeflag_forwardright = BIT(8)
 
const float pathlib_node_edgeflag_left = BIT(1)
 
const float pathlib_node_edgeflag_none = BIT(9)
 
const float pathlib_node_edgeflag_right = BIT(2)
 
const float pathlib_node_edgeflag_unknown = 0
 
float pathlib_node_edgeflags
 
float pathlib_node_f
 
float pathlib_node_g
 
float pathlib_node_h
 
float pathlib_open_cnt
 
float pathlib_searched_cnt
 
float pathlib_starttime
 
const vector PLIB_FORWARD = '0 1 0'
 
const vector PLIB_RIGHT = '1 0 0'
 
entity start_node
 
vector tile_check_down
 
float tile_check_size
 
vector tile_check_up
 

Macro Definition Documentation

◆ DEBUGPATHING

#define DEBUGPATHING   0

Definition at line 4 of file pathlib.qh.

◆ inwater

#define inwater (   point)    (pointcontents(point) == CONTENT_WATER)

Function Documentation

◆ buildpath_nodefilter()

var bool buildpath_nodefilter ( vector  n,
vector  c,
vector  p 
)

Referenced by path_build(), pathlib_astar(), pathlib_h_none(), and pathlib_waypointpath_step().

+ Here is the caller graph for this function:

◆ pathlib_cost()

var float pathlib_cost ( entity  parent,
vector  to,
float  static_cost 
)

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

+ Here is the caller graph for this function:

◆ pathlib_expandnode()

var float pathlib_expandnode ( entity  node,
vector  start,
vector  goal 
)

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

+ Here is the caller graph for this function:

◆ pathlib_expandnode_box()

float pathlib_expandnode_box ( entity  node,
vector  start,
vector  goal 
)

Definition at line 224 of file expandnode.qc.

References pathlib_gridsize, pathlib_makenode(), pathlib_movecost, pathlib_open_cnt, v, and vector().

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

225 {
226  vector v;
227 
228  for(v.z = node.origin.z - pathlib_gridsize; v.z <= node.origin.z + pathlib_gridsize; v.z += pathlib_gridsize)
229  for(v.y = node.origin.y - pathlib_gridsize; v.y <= node.origin.y + pathlib_gridsize; v.y += pathlib_gridsize)
230  for(v.x = node.origin.x - pathlib_gridsize; v.x <= node.origin.x + pathlib_gridsize; v.x += pathlib_gridsize)
231  {
232  //if(vlen(v - node.origin))
233  pathlib_makenode(node,start,v,goal,pathlib_movecost);
234  }
235 
236  return pathlib_open_cnt;
237 }
float pathlib_movecost
Definition: pathlib.qh:51
float pathlib_gridsize
Definition: pathlib.qh:50
float pathlib_open_cnt
Definition: pathlib.qh:42
var bool pathlib_makenode(entity parent, vector start, vector to, vector goal, float cost)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_expandnode_star()

float pathlib_expandnode_star ( entity  node,
vector  start,
vector  goal 
)

Definition at line 96 of file expandnode.qc.

References LOG_TRACE, pathlib_gridsize, pathlib_makenode(), pathlib_movecost, pathlib_movecost_diag, pathlib_node_edgeflag_back, pathlib_node_edgeflag_backleft, pathlib_node_edgeflag_backright, pathlib_node_edgeflag_forward, pathlib_node_edgeflag_forwardleft, pathlib_node_edgeflag_forwardright, pathlib_node_edgeflag_left, pathlib_node_edgeflag_none, pathlib_node_edgeflag_right, pathlib_node_edgeflag_unknown, pathlib_open_cnt, PLIB_FORWARD, PLIB_RIGHT, tile_check_plus2(), vector(), and vtos().

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

97 {
98  vector point;
99 
100  vector where = node.origin;
101 
104 
105  if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_unknown)
106  node.pathlib_node_edgeflags = tile_check_plus2(node, node.origin);
107 
108  if(node.pathlib_node_edgeflags == pathlib_node_edgeflag_none)
109  {
110  LOG_TRACE("Node at ", vtos(node.origin), " not expanable");
111  return pathlib_open_cnt;
112  }
113 
114  // Forward
115  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forward)
116  {
117  point = where + f;
118  pathlib_makenode(node, start, point, goal, pathlib_movecost);
119  }
120 
121  // Back
122  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_back)
123  {
124  point = where - f;
125  pathlib_makenode(node, start, point, goal, pathlib_movecost);
126  }
127 
128  // Right
129  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_right)
130  {
131  point = where + r;
132  pathlib_makenode(node, start, point, goal, pathlib_movecost);
133  }
134 
135  // Left
136  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_left)
137  {
138  point = where - r;
139  pathlib_makenode(node, start, point, goal, pathlib_movecost);
140 
141  }
142 
143  // Forward-right
144  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardright)
145  {
146  point = where + f + r;
147  pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
148  }
149 
150  // Forward-left
151  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardleft)
152  {
153  point = where + f - r;
154  pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
155 
156  }
157 
158  // Back-right
159  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backright)
160  {
161  point = where - f + r;
162  pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
163  }
164 
165  // Back-left
166  if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backleft)
167  {
168  point = where - f - r;
169  pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
170  }
171 
172  return pathlib_open_cnt;
173 }
float tile_check_plus2(entity this, vector where)
Definition: utility.qc:112
const float pathlib_node_edgeflag_backright
Definition: pathlib.qh:36
const float pathlib_node_edgeflag_forwardleft
Definition: pathlib.qh:37
const vector PLIB_FORWARD
Definition: pathlib.qh:13
const float pathlib_node_edgeflag_left
Definition: pathlib.qh:31
float pathlib_movecost
Definition: pathlib.qh:51
float pathlib_gridsize
Definition: pathlib.qh:50
float pathlib_open_cnt
Definition: pathlib.qh:42
var bool pathlib_makenode(entity parent, vector start, vector to, vector goal, float cost)
const float pathlib_node_edgeflag_back
Definition: pathlib.qh:34
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define LOG_TRACE(...)
Definition: log.qh:81
const float pathlib_node_edgeflag_backleft
Definition: pathlib.qh:35
const float pathlib_node_edgeflag_none
Definition: pathlib.qh:39
const vector PLIB_RIGHT
Definition: pathlib.qh:15
float pathlib_movecost_diag
Definition: pathlib.qh:52
const float pathlib_node_edgeflag_forward
Definition: pathlib.qh:33
const float pathlib_node_edgeflag_right
Definition: pathlib.qh:32
const float pathlib_node_edgeflag_forwardright
Definition: pathlib.qh:38
const float pathlib_node_edgeflag_unknown
Definition: pathlib.qh:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_flynode()

vector pathlib_flynode ( entity  this,
vector  start,
vector  end,
float  doedge 
)

Definition at line 65 of file movenode.qc.

References fsnap(), MOVE_WORLDONLY, movenode_boxmax, movenode_boxmin, pathlib_gridsize, pathlib_movenode_goodnode, and trace_fraction.

66 {
68 
69  end.x = fsnap(end.x, pathlib_gridsize);
70  end.y = fsnap(end.y, pathlib_gridsize);
71 
72  tracebox(start, movenode_boxmin,movenode_boxmax, end, MOVE_WORLDONLY, this);
73  if(trace_fraction == 1)
75 
76  return end;
77 }
float pathlib_gridsize
Definition: pathlib.qh:50
vector movenode_boxmin
Definition: pathlib.qh:74
bool pathlib_movenode_goodnode
Definition: pathlib.qh:75
vector movenode_boxmax
Definition: pathlib.qh:73
float MOVE_WORLDONLY
float trace_fraction
Definition: csprogsdefs.qc:36
ERASEABLE float fsnap(float val, float fsize)
Definition: math.qh:57
+ Here is the call graph for this function:

◆ pathlib_g_euclidean()

float pathlib_g_euclidean ( entity  parent,
vector  to,
float  static_cost 
)

Definition at line 16 of file costs.qc.

References vlen().

17 {
18  return parent.pathlib_node_g + vlen(parent.origin - to);
19 }
entity parent
Definition: animhost.qc:7
entity to
Definition: self.qh:96
+ Here is the call graph for this function:

◆ pathlib_g_euclidean_water()

float pathlib_g_euclidean_water ( entity  parent,
vector  to,
float  static_cost 
)

Definition at line 21 of file costs.qc.

References inwater, pathlib_movecost_waterfactor, and vlen().

Referenced by pathlib_astar().

22 {
23  if(inwater(to))
24  return parent.pathlib_node_g + vlen(parent.origin - to) * pathlib_movecost_waterfactor;
25  else
26  return parent.pathlib_node_g + vlen(parent.origin - to);
27 }
entity parent
Definition: animhost.qc:7
entity to
Definition: self.qh:96
#define inwater(point)
Definition: pathlib.qh:11
float pathlib_movecost_waterfactor
Definition: pathlib.qh:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_g_static()

float pathlib_g_static ( entity  parent,
vector  to,
float  static_cost 
)

Definition at line 3 of file costs.qc.

4 {
5  return parent.pathlib_node_g + static_cost;
6 }
entity parent
Definition: animhost.qc:7

◆ pathlib_g_static_water()

float pathlib_g_static_water ( entity  parent,
vector  to,
float  static_cost 
)

Definition at line 8 of file costs.qc.

References inwater, and pathlib_movecost_waterfactor.

9 {
10  if(inwater(to))
11  return parent.pathlib_node_g + static_cost * pathlib_movecost_waterfactor;
12  else
13  return parent.pathlib_node_g + static_cost;
14 }
entity parent
Definition: animhost.qc:7
entity to
Definition: self.qh:96
#define inwater(point)
Definition: pathlib.qh:11
float pathlib_movecost_waterfactor
Definition: pathlib.qh:53

◆ pathlib_h_diagonal()

float pathlib_h_diagonal ( vector  a,
vector  b 
)

This heuristic consider both straight and diagonal moves to have the same cost.

Definition at line 49 of file costs.qc.

References fabs(), max(), and pathlib_movecost.

Referenced by pathlib_astar().

50 {
51  //h(n) = D * max(abs(n.x-goal.x), abs(n.y-goal.y))
52 
53  float hx = fabs(a.x - b.x);
54  float hy = fabs(a.y - b.y);
55  float h = pathlib_movecost * max(hx, hy);
56 
57  return h;
58 }
float pathlib_movecost
Definition: pathlib.qh:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_h_diagonal2()

float pathlib_h_diagonal2 ( vector  a,
vector  b 
)

This heuristic consider both straight and diagonal moves, but has a separate cost for diagonal moves.

Definition at line 74 of file costs.qc.

References fabs(), min(), pathlib_movecost, and pathlib_movecost_diag.

75 {
76  /*
77  h_diagonal(n) = min(abs(n.x-goal.x), abs(n.y-goal.y))
78  h_straight(n) = (abs(n.x-goal.x) + abs(n.y-goal.y))
79  h(n) = D2 * h_diagonal(n) + D * (h_straight(n) - 2*h_diagonal(n)))
80  */
81 
82  float hx = fabs(a.x - b.x);
83  float hy = fabs(a.y - b.y);
84 
85  float h_diag = min(hx,hy);
86  float h_str = hx + hy;
87 
88  float h = pathlib_movecost_diag * h_diag;
89  h += pathlib_movecost * (h_str - 2 * h_diag);
90 
91  return h;
92 }
float pathlib_movecost
Definition: pathlib.qh:51
float pathlib_movecost_diag
Definition: pathlib.qh:52
+ Here is the call graph for this function:

◆ pathlib_h_diagonal2sdp()

float pathlib_h_diagonal2sdp ( vector  preprev,
vector  prev,
vector  point,
vector  end 
)

This heuristic consider both straight and diagonal moves, But has a separate cost for diagonal moves.

Definition at line 98 of file costs.qc.

References fabs(), normalize(), pathlib_movecost, pathlib_movecost_diag, vector(), and vlen().

99 {
100  //h_diagonal(n) = min(abs(n.x-goal.x), abs(n.y-goal.y))
101  //h_straight(n) = (abs(n.x-goal.x) + abs(n.y-goal.y))
102  //h(n) = D2 * h_diagonal(n) + D * (h_straight(n) - 2*h_diagonal(n)))
103 
104  float hx = fabs(point.x - end.x);
105  float hy = fabs(point.y - end.y);
106  float hz = fabs(point.z - end.z);
107 
108  float h_diag = min3(hx,hy,hz);
109  float h_str = hx + hy + hz;
110 
111  float h = pathlib_movecost_diag * h_diag;
112  h += pathlib_movecost * (h_str - 2 * h_diag);
113 
114  vector d1 = normalize(preprev - point);
115  vector d2 = normalize(prev - point);
116  float m = vlen(d1 - d2);
117 
118  return h * m;
119 }
prev
Definition: all.qh:66
float pathlib_movecost
Definition: pathlib.qh:51
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float pathlib_movecost_diag
Definition: pathlib.qh:52
+ Here is the call graph for this function:

◆ pathlib_h_diagonal3()

float pathlib_h_diagonal3 ( vector  a,
vector  b 
)

Definition at line 122 of file costs.qc.

References fabs(), pathlib_movecost, and pathlib_movecost_diag.

123 {
124  float hx = fabs(a.x - b.x);
125  float hy = fabs(a.y - b.y);
126  float hz = fabs(a.z - b.z);
127 
128  float h_diag = min3(hx,hy,hz);
129  float h_str = hx + hy + hz;
130 
131  float h = pathlib_movecost_diag * h_diag;
132  h += pathlib_movecost * (h_str - 2 * h_diag);
133 
134  return h;
135 }
float pathlib_movecost
Definition: pathlib.qh:51
float pathlib_movecost_diag
Definition: pathlib.qh:52
+ Here is the call graph for this function:

◆ pathlib_h_euclidean()

float pathlib_h_euclidean ( vector  a,
vector  b 
)

This heuristic only considers the straight line distance.

Usually means a lower H then G, resulting in A* spreading more (and running slower).

Definition at line 65 of file costs.qc.

References vlen().

66 {
67  return vlen(a - b);
68 }
+ Here is the call graph for this function:

◆ pathlib_h_manhattan()

float pathlib_h_manhattan ( vector  a,
vector  b 
)

Manhattan heuristic means we expect to move up, down left or right No diagonal moves expected.

(like moving between city blocks)

Definition at line 34 of file costs.qc.

References fabs(), and pathlib_gridsize.

35 {
36  //h(n) = D * (abs(n.x-goal.x) + abs(n.y-goal.y))
37 
38  float h = fabs(a.x - b.x);
39  h += fabs(a.y - b.y);
40  h *= pathlib_gridsize;
41 
42  return h;
43 }
float pathlib_gridsize
Definition: pathlib.qh:50
+ Here is the call graph for this function:

◆ pathlib_h_none()

float pathlib_h_none ( vector  preprev,
vector  prev 
)

Definition at line 101 of file pathlib.qh.

References buildpath_nodefilter(), entity(), parent, pathlib_heuristic(), pathlib_makenode(), pathlib_wpp_waypointcallback(), to, and vector().

Referenced by pathlib_waypointpath().

101 { return 0; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_heuristic()

var float pathlib_heuristic ( vector  from,
vector  to 
)

Referenced by pathlib_astar(), pathlib_h_none(), pathlib_makenode_adaptive(), pathlib_waypointpath(), pathlib_wpp_opencb(), and pathlib_wpp_openncb().

+ Here is the caller graph for this function:

◆ pathlib_makenode()

var bool pathlib_makenode ( entity  parent,
vector  start,
vector  to,
vector  goal,
float  cost 
)

Referenced by pathlib_astar(), pathlib_expandnode_box(), pathlib_expandnode_star(), and pathlib_h_none().

+ Here is the caller graph for this function:

◆ pathlib_movenode()

var vector pathlib_movenode ( entity  this,
vector  start,
vector  end,
float  doedge 
)

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

+ Here is the caller graph for this function:

◆ pathlib_swimnode()

vector pathlib_swimnode ( entity  this,
vector  start,
vector  end,
float  doedge 
)

Definition at line 45 of file movenode.qc.

References CONTENT_EMPTY, CONTENT_WATER, fsnap(), MOVE_WORLDONLY, movenode_boxmax, movenode_boxmin, pathlib_gridsize, pathlib_movenode_goodnode, pathlib_wateroutnode(), and trace_fraction.

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

46 {
48 
49  if(pointcontents(start) != CONTENT_WATER)
50  return end;
51 
52  end.x = fsnap(end.x, pathlib_gridsize);
53  end.y = fsnap(end.y, pathlib_gridsize);
54 
55  if(pointcontents(end) == CONTENT_EMPTY)
56  return pathlib_wateroutnode(this, start, end, doedge);
57 
58  tracebox(start, movenode_boxmin,movenode_boxmax, end, MOVE_WORLDONLY, this);
59  if(trace_fraction == 1)
61 
62  return end;
63 }
vector pathlib_wateroutnode(entity this, vector start, vector end, float doedge)
Definition: movenode.qc:11
const float CONTENT_EMPTY
Definition: csprogsdefs.qc:236
const float CONTENT_WATER
Definition: csprogsdefs.qc:238
float pathlib_gridsize
Definition: pathlib.qh:50
vector movenode_boxmin
Definition: pathlib.qh:74
bool pathlib_movenode_goodnode
Definition: pathlib.qh:75
vector movenode_boxmax
Definition: pathlib.qh:73
float MOVE_WORLDONLY
float trace_fraction
Definition: csprogsdefs.qc:36
ERASEABLE float fsnap(float val, float fsize)
Definition: math.qh:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_walknode()

vector pathlib_walknode ( entity  this,
vector  start,
vector  end,
float  doedge 
)

Definition at line 88 of file movenode.qc.

References a_think(), direction, entity(), fsnap(), LOG_DEBUG, LOG_TRACE, MOVE_WORLDONLY, movenode_boxmax, movenode_boxmin, movenode_boxup, movenode_maxdrop, movenode_stepsize, movenode_stepup, normalize(), pathlib_gridsize, pathlib_movenode_goodnode, rint(), setorigin(), setthink, spawn(), time, trace_endpos, trace_fraction, vector(), vlen(), and vtos().

Referenced by buildpath_nodefilter_moveskip(), pathlib_astar(), pathlib_close_node(), and pathlib_makenode_adaptive().

89 {
90  vector point;
91 
92  LOG_DEBUG("Walking node from ", vtos(start), " to ", vtos(end));
93 
95 
96  end.x = fsnap(end.x,pathlib_gridsize);
97  end.y = fsnap(end.y,pathlib_gridsize);
98  start.x = fsnap(start.x,pathlib_gridsize);
99  start.y = fsnap(start.y,pathlib_gridsize);
100 
101  // Find the floor
102  traceline(start + movenode_stepup, start - movenode_maxdrop, MOVE_WORLDONLY, this);
103  if(trace_fraction == 1.0)
104  {
105  entity a;
106  a = spawn();
107  setthink(a, a_think);
108  a.nextthink = time;
109  setorigin(a, start + movenode_stepup);
110  a.pos1 = trace_endpos;
111  //start - movenode_maxdrop
112  a.cnt = time + 10;
113 
114  LOG_TRACE("I cant walk on air!");
115  return trace_endpos;
116  }
117 
118  start = trace_endpos;
119 
120  // Find the direcion, without Z
121  vector s = start;
122  vector e = end;
123  //e_z = 0; s_z = 0;
124  vector direction = normalize(e - s);
125 
126  float distance = vlen(start - end);
127  int steps = rint(distance / movenode_stepsize);
128 
129  vector last_point = start;
130  for(int i = 1; i < steps; ++i)
131  {
132  point = last_point + (direction * movenode_stepsize);
133  traceline(point + movenode_stepup,point - movenode_maxdrop,MOVE_WORLDONLY,this);
134  if(trace_fraction == 1.0)
135  return trace_endpos;
136 
137  last_point = trace_endpos;
138  }
139 
140  point = last_point + (direction * movenode_stepsize);
141  point.x = fsnap(point.x,pathlib_gridsize);
142  point.y = fsnap(point.y,pathlib_gridsize);
143 
144  //dprint("end_x: ",ftos(end_x), " end_y: ",ftos(end_y),"\n");
145  //dprint("point_x:",ftos(point_x)," point_y:",ftos(point_y),"\n\n");
146 
147  traceline(point + movenode_stepup, point - movenode_maxdrop,MOVE_WORLDONLY,this);
148  if(trace_fraction == 1.0)
149  return trace_endpos;
150 
151  last_point = trace_endpos;
152 
153  tracebox(start + movenode_boxup, movenode_boxmin,movenode_boxmax, last_point + movenode_boxup, MOVE_WORLDONLY, this);
154  if(trace_fraction != 1.0)
155  return trace_endpos;
156 
158  return last_point;
159 }
int direction
Definition: strafehud.qc:24
entity() spawn
vector movenode_maxdrop
Definition: pathlib.qh:71
vector movenode_boxup
Definition: pathlib.qh:72
void a_think(entity this)
Definition: movenode.qc:79
float pathlib_gridsize
Definition: pathlib.qh:50
vector trace_endpos
Definition: csprogsdefs.qc:37
float movenode_stepsize
Definition: pathlib.qh:69
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector movenode_boxmin
Definition: pathlib.qh:74
vector movenode_stepup
Definition: pathlib.qh:70
#define LOG_TRACE(...)
Definition: log.qh:81
setorigin(ent, v)
#define setthink(e, f)
bool pathlib_movenode_goodnode
Definition: pathlib.qh:75
vector movenode_boxmax
Definition: pathlib.qh:73
float MOVE_WORLDONLY
float time
Definition: csprogsdefs.qc:16
float trace_fraction
Definition: csprogsdefs.qc:36
#define LOG_DEBUG(...)
Definition: log.qh:85
ERASEABLE float fsnap(float val, float fsize)
Definition: math.qh:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_wateroutnode()

vector pathlib_wateroutnode ( entity  this,
vector  start,
vector  end,
float  doedge 
)

Definition at line 11 of file movenode.qc.

References CONTENT_EMPTY, CONTENT_SOLID, fabs(), fsnap(), MOVE_WORLDONLY, movenode_boxmax, movenode_boxmin, pathlib_gridsize, pathlib_movenode_goodnode, trace_endpos, trace_fraction, and vector().

Referenced by pathlib_swimnode().

12 {
13  vector surface;
14 
16 
17  end.x = fsnap(end.x, pathlib_gridsize);
18  end.y = fsnap(end.y, pathlib_gridsize);
19 
20  traceline(end + ('0 0 0.25' * pathlib_gridsize),end - ('0 0 1' * pathlib_gridsize),MOVE_WORLDONLY,this);
21  end = trace_endpos;
22 
23  if (!(pointcontents(end - '0 0 1') == CONTENT_SOLID))
24  return end;
25 
26  for(surface = start ; surface.z < (end.z + 32); ++surface.z)
27  {
28  if(pointcontents(surface) == CONTENT_EMPTY)
29  break;
30  }
31 
32  if(pointcontents(surface + '0 0 1') != CONTENT_EMPTY)
33  return end;
34 
35  tracebox(start + '0 0 64', movenode_boxmin,movenode_boxmax, end + '0 0 64', MOVE_WORLDONLY, this);
36  if(trace_fraction == 1)
38 
39  if(fabs(surface.z - end.z) > 32)
41 
42  return end;
43 }
const float CONTENT_SOLID
Definition: csprogsdefs.qc:237
const float CONTENT_EMPTY
Definition: csprogsdefs.qc:236
float pathlib_gridsize
Definition: pathlib.qh:50
vector trace_endpos
Definition: csprogsdefs.qc:37
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector movenode_boxmin
Definition: pathlib.qh:74
bool pathlib_movenode_goodnode
Definition: pathlib.qh:75
vector movenode_boxmax
Definition: pathlib.qh:73
float MOVE_WORLDONLY
float trace_fraction
Definition: csprogsdefs.qc:36
ERASEABLE float fsnap(float val, float fsize)
Definition: math.qh:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathlib_wpp_waypointcallback()

var float pathlib_wpp_waypointcallback ( entity  wp,
entity  wp_prev 
)

Referenced by pathlib_h_none(), pathlib_waypointpath(), and pathlib_wpp_opencb().

+ Here is the caller graph for this function:

◆ STATIC_INIT()

STATIC_INIT ( g_pathlib_nodes  )

Definition at line 110 of file pathlib.qh.

References IL_NEW.

110 { g_pathlib_nodes = IL_NEW(); }
IntrusiveList g_pathlib_nodes
Definition: pathlib.qh:109
#define IL_NEW()

◆ tile_check()

var bool tile_check ( entity  this,
vector  where 
)

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

+ Here is the caller graph for this function:

◆ tile_check_cross()

bool tile_check_cross ( entity  this,
vector  where 
)

Definition at line 43 of file utility.qc.

References location_isok(), MOVE_WORLDONLY, PLIB_FORWARD, PLIB_RIGHT, tile_check_down, tile_check_size, tile_check_up, trace_endpos, and vector().

Referenced by pathlib_astar(), and tile_check_star().

44 {
45  vector p;
48 
49 
50  // forward-right
51  p = where + f + r;
52  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
53  if (!location_isok(trace_endpos, 1, 0))
54  return false;
55 
56  // Forward-left
57  p = where + f - r;
58  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
59  if (!location_isok(trace_endpos, 1, 0))
60  return false;
61 
62  // Back-right
63  p = where - f + r;
64  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
65  if (!location_isok(trace_endpos, 1 ,0))
66  return false;
67 
68  //Back-left
69  p = where - f - r;
70  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
71  if (!location_isok(trace_endpos, 1, 0))
72  return false;
73 
74  return true;
75 }
bool location_isok(vector point, bool waterok, bool air_isok)
Definition: utility.qc:7
vector tile_check_down
Definition: pathlib.qh:62
vector tile_check_up
Definition: pathlib.qh:61
const vector PLIB_FORWARD
Definition: pathlib.qh:13
vector trace_endpos
Definition: csprogsdefs.qc:37
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const vector PLIB_RIGHT
Definition: pathlib.qh:15
float tile_check_size
Definition: pathlib.qh:63
float MOVE_WORLDONLY
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tile_check_plus()

bool tile_check_plus ( entity  this,
vector  where 
)

Definition at line 77 of file utility.qc.

References location_isok(), MOVE_WORLDONLY, PLIB_FORWARD, PLIB_RIGHT, tile_check_down, tile_check_size, tile_check_up, trace_endpos, and vector().

Referenced by tile_check_star().

78 {
79  vector p;
80 
83 
84  // forward
85  p = where + f;
86  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
87  if (!location_isok(trace_endpos,1,0))
88  return false;
89 
90 
91  //left
92  p = where - r;
93  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
94  if (!location_isok(trace_endpos,1,0))
95  return false;
96 
97  // Right
98  p = where + r;
99  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
100  if (!location_isok(trace_endpos,1,0))
101  return false;
102 
103  //Back
104  p = where - f;
105  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
106  if (!location_isok(trace_endpos,1,0))
107  return false;
108 
109  return true;
110 }
bool location_isok(vector point, bool waterok, bool air_isok)
Definition: utility.qc:7
vector tile_check_down
Definition: pathlib.qh:62
vector tile_check_up
Definition: pathlib.qh:61
const vector PLIB_FORWARD
Definition: pathlib.qh:13
vector trace_endpos
Definition: csprogsdefs.qc:37
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const vector PLIB_RIGHT
Definition: pathlib.qh:15
float tile_check_size
Definition: pathlib.qh:63
float MOVE_WORLDONLY
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tile_check_star()

bool tile_check_star ( entity  this,
vector  where 
)

Definition at line 206 of file utility.qc.

References tile_check_cross(), and tile_check_plus().

207 {
208  if(tile_check_plus(this, where))
209  return tile_check_cross(this, where);
210 
211  return false;
212 }
bool tile_check_cross(entity this, vector where)
Definition: utility.qc:43
bool tile_check_plus(entity this, vector where)
Definition: utility.qc:77
+ Here is the call graph for this function:

Variable Documentation

◆ best_open_node

◆ closedlist

◆ g_pathlib_nodes

IntrusiveList g_pathlib_nodes

Definition at line 109 of file pathlib.qh.

Referenced by dumpnode(), pathlib_cleanup(), pathlib_mknode(), and pathlib_nodeatpoint().

◆ goal_node

◆ is_path_node

bool is_path_node

Definition at line 24 of file pathlib.qh.

◆ movenode_boxmax

vector movenode_boxmax

◆ movenode_boxmin

vector movenode_boxmin

◆ movenode_boxup

vector movenode_boxup

Definition at line 72 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_walknode().

◆ movenode_maxdrop

vector movenode_maxdrop

Definition at line 71 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_walknode().

◆ movenode_stepsize

float movenode_stepsize

Definition at line 69 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_walknode().

◆ movenode_stepup

vector movenode_stepup

Definition at line 70 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_walknode().

◆ openlist

◆ path_next

entity path_next

Definition at line 8 of file pathlib.qh.

◆ path_prev

entity path_prev

Definition at line 9 of file pathlib.qh.

◆ pathlib_bestcash_hits

float pathlib_bestcash_hits

Definition at line 48 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_getbestopen().

◆ pathlib_bestcash_saved

float pathlib_bestcash_saved

Definition at line 49 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_getbestopen().

◆ pathlib_bestopen_searched

float pathlib_bestopen_searched

Definition at line 47 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_getbestopen().

◆ pathlib_closed_cnt

float pathlib_closed_cnt

◆ pathlib_foundgoal

◆ pathlib_gridsize

◆ pathlib_list

entity pathlib_list

Definition at line 7 of file pathlib.qh.

Referenced by pathlib_wpp_bestopen().

◆ pathlib_made_cnt

float pathlib_made_cnt

Definition at line 44 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_mknode().

◆ pathlib_maxtime

const float pathlib_maxtime = 60

Definition at line 57 of file pathlib.qh.

Referenced by pathlib_astar().

◆ pathlib_merge_cnt

float pathlib_merge_cnt

Definition at line 45 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_makenode_adaptive().

◆ pathlib_movecost

◆ pathlib_movecost_diag

◆ pathlib_movecost_waterfactor

float pathlib_movecost_waterfactor

Definition at line 53 of file pathlib.qh.

Referenced by pathlib_astar(), pathlib_g_euclidean_water(), and pathlib_g_static_water().

◆ pathlib_movenode_goodnode

◆ pathlib_node_c

float pathlib_node_c

Definition at line 28 of file pathlib.qh.

◆ pathlib_node_edgeflag_back

const float pathlib_node_edgeflag_back = BIT(4)

Definition at line 34 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_backleft

const float pathlib_node_edgeflag_backleft = BIT(5)

Definition at line 35 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_backright

const float pathlib_node_edgeflag_backright = BIT(6)

Definition at line 36 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_forward

const float pathlib_node_edgeflag_forward = BIT(3)

Definition at line 33 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_forwardleft

const float pathlib_node_edgeflag_forwardleft = BIT(7)

Definition at line 37 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_forwardright

const float pathlib_node_edgeflag_forwardright = BIT(8)

Definition at line 38 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_left

const float pathlib_node_edgeflag_left = BIT(1)

Definition at line 31 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_none

const float pathlib_node_edgeflag_none = BIT(9)

Definition at line 39 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_right

const float pathlib_node_edgeflag_right = BIT(2)

Definition at line 32 of file pathlib.qh.

Referenced by pathlib_expandnode_star(), and tile_check_plus2().

◆ pathlib_node_edgeflag_unknown

const float pathlib_node_edgeflag_unknown = 0

Definition at line 30 of file pathlib.qh.

Referenced by pathlib_expandnode_star().

◆ pathlib_node_edgeflags

float pathlib_node_edgeflags

Definition at line 40 of file pathlib.qh.

◆ pathlib_node_f

float pathlib_node_f

Definition at line 27 of file pathlib.qh.

◆ pathlib_node_g

float pathlib_node_g

Definition at line 25 of file pathlib.qh.

◆ pathlib_node_h

float pathlib_node_h

Definition at line 26 of file pathlib.qh.

◆ pathlib_open_cnt

◆ pathlib_searched_cnt

float pathlib_searched_cnt

◆ pathlib_starttime

float pathlib_starttime

Definition at line 56 of file pathlib.qh.

Referenced by pathlib_astar(), and pathlib_waypointpath().

◆ PLIB_FORWARD

const vector PLIB_FORWARD = '0 1 0'

◆ PLIB_RIGHT

const vector PLIB_RIGHT = '1 0 0'

◆ start_node

entity start_node

Definition at line 22 of file pathlib.qh.

Referenced by pathlib_waypointpath(), and pathlib_waypointpath_step().

◆ tile_check_down

vector tile_check_down

Definition at line 62 of file pathlib.qh.

Referenced by pathlib_astar(), tile_check_cross(), tile_check_plus(), and tile_check_plus2().

◆ tile_check_size

float tile_check_size

Definition at line 63 of file pathlib.qh.

Referenced by pathlib_astar(), tile_check_cross(), and tile_check_plus().

◆ tile_check_up

vector tile_check_up

Definition at line 61 of file pathlib.qh.

Referenced by pathlib_astar(), tile_check_cross(), tile_check_plus(), and tile_check_plus2().