Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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.
float pathlib_h_diagonal2 (vector a, vector b)
 This heuristic consider both straight and diagonal moves, but has a separate cost for diagonal moves.
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.
float pathlib_h_diagonal3 (vector a, vector b)
float pathlib_h_euclidean (vector a, vector b)
 This heuristic only considers the straight line distance.
float pathlib_h_manhattan (vector a, vector b)
 Manhattan heuristic means we expect to move up, down left or right No diagonal moves expected.

Function Documentation

◆ pathlib_g_euclidean()

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

Definition at line 16 of file costs.qc.

17{
18 return parent.pathlib_node_g + vlen(parent.origin - to);
19}
entity parent
Definition animhost.qc:7
float vlen(vector v)

References entity(), parent, vector, and vlen().

◆ pathlib_g_euclidean_water()

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

Definition at line 21 of file costs.qc.

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}
#define inwater(point)
Definition pathlib.qh:11
float pathlib_movecost_waterfactor
Definition pathlib.qh:53

References entity(), inwater, parent, pathlib_movecost_waterfactor, vector, and vlen().

Referenced by pathlib_astar().

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

References entity(), parent, and vector.

◆ pathlib_g_static_water()

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

Definition at line 8 of file costs.qc.

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}

References entity(), inwater, parent, pathlib_movecost_waterfactor, and vector.

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

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 fabs(float f)
float max(float f,...)
float pathlib_movecost
Definition pathlib.qh:51

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

Referenced by pathlib_astar().

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

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 min(float f,...)
float pathlib_movecost_diag
Definition pathlib.qh:52

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

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

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:71
vector normalize(vector v)
vector
Definition self.qh:92

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

◆ pathlib_h_diagonal3()

float pathlib_h_diagonal3 ( vector a,
vector b )

Definition at line 122 of file costs.qc.

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}

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

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

66{
67 return vlen(a - b);
68}

References vector, and vlen().

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

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);
41
42 return h;
43}
float pathlib_gridsize
Definition pathlib.qh:50

References fabs(), pathlib_gridsize, and vector.