]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/pathlib/utility.qc
Merge branch 'master' into terencehill/infomessages_panel_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / pathlib / utility.qc
1 #include "utility.qh"
2
3 #include "pathlib.qh"
4
5 float location_isok(vector point, float water_isok, float air_isok)
6 {
7     float pc,pc2;
8
9     if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
10         return 0;
11
12     pc  = pointcontents(point);
13     pc2 = pointcontents(point - '0 0 1');
14
15     switch(pc)
16     {
17         case CONTENT_SOLID:
18             break;
19
20         case CONTENT_SLIME:
21             break;
22
23         case CONTENT_LAVA:
24             break;
25
26         case CONTENT_SKY:
27             break;
28
29         case CONTENT_EMPTY:
30             if (pc2 == CONTENT_SOLID)
31                 return 1;
32
33             if (pc2 == CONTENT_EMPTY)
34                 if(air_isok)
35                     return 1;
36
37             if (pc2 == CONTENT_WATER)
38                 if(water_isok)
39                     return 1;
40
41             break;
42
43         case CONTENT_WATER:
44             if (water_isok)
45                 return 1;
46
47             break;
48     }
49
50     return 0;
51 }
52
53 entity pathlib_nodeatpoint(vector where)
54 {
55     entity node;
56
57     ++pathlib_searched_cnt;
58
59     where.x = fsnap(where.x,pathlib_gridsize);
60     where.y = fsnap(where.y,pathlib_gridsize);
61
62     node = findradius(where,pathlib_gridsize * 0.5);
63     while(node)
64     {
65         if(node.is_path_node == true)
66             return node;
67
68         node = node.chain;
69     }
70
71     return NULL;
72 }
73
74 float tile_check_cross(entity this, vector where)
75 {
76     vector p,f,r;
77
78     f = PLIB_FORWARD * tile_check_size;
79     r = PLIB_RIGHT   * tile_check_size;
80
81
82     // forward-right
83     p = where + f + r;
84     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
85     if (!location_isok(trace_endpos, 1, 0))
86         return 0;
87
88     // Forward-left
89     p = where + f - r;
90     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
91     if (!location_isok(trace_endpos, 1, 0))
92         return 0;
93
94     // Back-right
95     p = where - f + r;
96     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
97     if (!location_isok(trace_endpos, 1 ,0))
98         return 0;
99
100     //Back-left
101     p = where - f - r;
102     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
103     if (!location_isok(trace_endpos, 1, 0))
104         return 0;
105
106     return 1;
107 }
108
109 float tile_check_plus(entity this, vector where)
110 {
111     vector p,f,r;
112
113     f = PLIB_FORWARD * tile_check_size;
114     r = PLIB_RIGHT   * tile_check_size;
115
116     // forward
117     p = where + f;
118     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
119     if (!location_isok(trace_endpos,1,0))
120         return 0;
121
122
123     //left
124     p = where - r;
125     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
126     if (!location_isok(trace_endpos,1,0))
127         return 0;
128
129     // Right
130     p = where + r;
131     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
132     if (!location_isok(trace_endpos,1,0))
133         return 0;
134
135     //Back
136     p = where - f;
137     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
138     if (!location_isok(trace_endpos,1,0))
139         return 0;
140
141     return 1;
142 }
143
144 float tile_check_plus2(entity this, vector where)
145 {
146     vector p,f,r;
147     float i = 0, e = 0;
148
149     f = PLIB_FORWARD * pathlib_gridsize;
150     r = PLIB_RIGHT   * pathlib_gridsize;
151
152 //#define pathlib_node_edgeflag_left    2
153 //#define pathlib_node_edgeflag_right   4
154 //#define pathlib_node_edgeflag_forward 8
155 //#define pathlib_node_edgeflag_back    16
156
157     // forward
158     p = where + f;
159     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
160     if (location_isok(trace_endpos,1,0))
161     {
162        ++i;
163        e |= pathlib_node_edgeflag_forward;
164     }
165
166
167     //left
168     p = where - r;
169     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
170     if (location_isok(trace_endpos,1,0))
171     {
172        ++i;
173        e |= pathlib_node_edgeflag_left;
174     }
175
176
177     // Right
178     p = where + r;
179     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
180     if (location_isok(trace_endpos,1,0))
181     {
182        ++i;
183        e |= pathlib_node_edgeflag_right;
184     }
185
186     //Back
187     p = where - f;
188     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this);
189     if (location_isok(trace_endpos,1,0))
190     {
191        ++i;
192        e |= pathlib_node_edgeflag_back;
193     }
194
195     // forward-right
196     p = where + f + r;
197     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
198     if (location_isok(trace_endpos, 1, 0))
199     {
200        ++i;
201        e |= pathlib_node_edgeflag_forwardright;
202     }
203
204     // Forward-left
205     p = where + f - r;
206     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
207     if (location_isok(trace_endpos, 1, 0))
208     {
209        ++i;
210        e |= pathlib_node_edgeflag_forwardleft;
211     }
212
213     // Back-right
214     p = where - f + r;
215     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
216     if (location_isok(trace_endpos, 1 ,0))
217     {
218        ++i;
219        e |= pathlib_node_edgeflag_backright;
220     }
221
222     //Back-left
223     p = where - f - r;
224     traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this);
225     if (location_isok(trace_endpos, 1, 0))
226     {
227        ++i;
228        e |= pathlib_node_edgeflag_backleft;
229     }
230
231
232     if(i == 0)
233         e = pathlib_node_edgeflag_none;
234
235     return e;
236 }
237
238 float tile_check_star(entity this, vector where)
239 {
240     if(tile_check_plus(this, where))
241         return tile_check_cross(this, where);
242
243     return 0;
244 }
245