Xonotic
costs.qc File Reference
#include "costs.qh"
+ Include dependency graph for costs.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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...
 

Function Documentation

◆ 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: