Xonotic
utility.qc File Reference
#include "utility.qh"
#include <common/stats.qh>
#include <common/weapons/_all.qh>
#include <server/pathlib/pathlib.qh>
+ Include dependency graph for utility.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool location_isok (vector point, bool waterok, bool air_isok)
 
entity pathlib_nodeatpoint (vector where)
 
bool tile_check_cross (entity this, vector where)
 
bool tile_check_plus (entity this, vector where)
 
float tile_check_plus2 (entity this, vector where)
 
bool tile_check_star (entity this, vector where)
 

Function Documentation

◆ location_isok()

bool location_isok ( vector  point,
bool  waterok,
bool  air_isok 
)

Definition at line 7 of file utility.qc.

References CONTENT_EMPTY, CONTENT_SOLID, CONTENT_WATER, Q3SURFACEFLAG_SKY, and trace_dphitq3surfaceflags.

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

8 {
10  return false;
11 
12  int pc = pointcontents(point);
13  int pc2 = pointcontents(point - '0 0 1');
14 
15  if(pc == CONTENT_EMPTY && pc2 == CONTENT_SOLID)
16  return true;
17  if(pc == CONTENT_EMPTY && pc2 == CONTENT_WATER && waterok)
18  return true;
19  if(pc == CONTENT_EMPTY && pc2 == CONTENT_EMPTY && air_isok)
20  return true;
21  if(pc == CONTENT_WATER && waterok)
22  return true;
23  return false;
24 }
float trace_dphitq3surfaceflags
const float CONTENT_SOLID
Definition: csprogsdefs.qc:237
const float CONTENT_EMPTY
Definition: csprogsdefs.qc:236
float Q3SURFACEFLAG_SKY
const float CONTENT_WATER
Definition: csprogsdefs.qc:238
+ Here is the caller graph for this function:

◆ pathlib_nodeatpoint()

entity pathlib_nodeatpoint ( vector  where)

Definition at line 26 of file utility.qc.

References entity(), fsnap(), g_pathlib_nodes, IL_EACH, NULL, pathlib_gridsize, pathlib_searched_cnt, and vdist.

Referenced by pathlib_makenode_adaptive(), and pathlib_mknode().

27 {
29 
30  where.x = fsnap(where.x,pathlib_gridsize);
31  where.y = fsnap(where.y,pathlib_gridsize);
32 
33  entity found = NULL; // TODO: using FOREACH_ENTITY_RADIUS here causes mutex loop warnings, this may need a proper fix!
34  IL_EACH(g_pathlib_nodes, it.is_path_node && vdist(it.origin - where, <, pathlib_gridsize * 0.5),
35  {
36  found = it;
37  break;
38  });
39 
40  return found;
41 }
#define IL_EACH(this, cond, body)
IntrusiveList g_pathlib_nodes
Definition: pathlib.qh:109
entity() spawn
float pathlib_searched_cnt
Definition: pathlib.qh:46
float pathlib_gridsize
Definition: pathlib.qh:50
#define NULL
Definition: post.qh:17
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
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:

◆ 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_plus2()

float tile_check_plus2 ( entity  this,
vector  where 
)

Definition at line 112 of file utility.qc.

References location_isok(), MOVE_WORLDONLY, pathlib_gridsize, 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, PLIB_FORWARD, PLIB_RIGHT, tile_check_down, tile_check_up, trace_endpos, and vector().

Referenced by pathlib_expandnode_star().

113 {
114  vector p;
115  int j = 0, e = 0;
116 
119 
120 //#define pathlib_node_edgeflag_left 2
121 //#define pathlib_node_edgeflag_right 4
122 //#define pathlib_node_edgeflag_forward 8
123 //#define pathlib_node_edgeflag_back 16
124 
125  // forward
126  p = where + f;
127  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
128  if (location_isok(trace_endpos,1,0))
129  {
130  ++j;
132  }
133 
134 
135  //left
136  p = where - r;
137  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
138  if (location_isok(trace_endpos,1,0))
139  {
140  ++j;
142  }
143 
144 
145  // Right
146  p = where + r;
147  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
148  if (location_isok(trace_endpos,1,0))
149  {
150  ++j;
152  }
153 
154  //Back
155  p = where - f;
156  traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
157  if (location_isok(trace_endpos,1,0))
158  {
159  ++j;
161  }
162 
163  // forward-right
164  p = where + f + r;
165  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
166  if (location_isok(trace_endpos, 1, 0))
167  {
168  ++j;
170  }
171 
172  // Forward-left
173  p = where + f - r;
174  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
175  if (location_isok(trace_endpos, 1, 0))
176  {
177  ++j;
179  }
180 
181  // Back-right
182  p = where - f + r;
183  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
184  if (location_isok(trace_endpos, 1 ,0))
185  {
186  ++j;
188  }
189 
190  //Back-left
191  p = where - f - r;
192  traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
193  if (location_isok(trace_endpos, 1, 0))
194  {
195  ++j;
197  }
198 
199 
200  if(j == 0)
202 
203  return e;
204 }
bool location_isok(vector point, bool waterok, bool air_isok)
Definition: utility.qc:7
const float pathlib_node_edgeflag_backright
Definition: pathlib.qh:36
vector tile_check_down
Definition: pathlib.qh:62
const float pathlib_node_edgeflag_forwardleft
Definition: pathlib.qh:37
vector tile_check_up
Definition: pathlib.qh:61
const vector PLIB_FORWARD
Definition: pathlib.qh:13
const float pathlib_node_edgeflag_left
Definition: pathlib.qh:31
float pathlib_gridsize
Definition: pathlib.qh:50
vector trace_endpos
Definition: csprogsdefs.qc:37
const float pathlib_node_edgeflag_back
Definition: pathlib.qh:34
vector(float skel, float bonenum) _skel_get_boneabs_hidden
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
const float pathlib_node_edgeflag_forward
Definition: pathlib.qh:33
float MOVE_WORLDONLY
const float pathlib_node_edgeflag_right
Definition: pathlib.qh:32
const float pathlib_node_edgeflag_forwardright
Definition: pathlib.qh:38
+ 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: