]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/pathlib/expandnode.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / pathlib / expandnode.qc
1 #include "expandnode.qh"
2 #include "pathlib.qh"
3 #include "utility.qh"
4
5 /*
6 vector plib_points2[8];
7 vector plib_points[8];
8 float  plib_fvals[8];
9
10 float pathlib_expandnode_starf(entity node, vector start, vector goal)
11 {
12     float fc;
13
14     vector where = node.origin;
15
16     vector f = PLIB_FORWARD * pathlib_gridsize;
17     vector r = PLIB_RIGHT   * pathlib_gridsize;
18
19     // Forward
20     plib_points[0] = where + f;
21
22     // Back
23     plib_points[1] = where - f;
24
25     // Right
26     plib_points[2] = where + r;
27
28     // Left
29     plib_points[3] = where - r;
30
31     // Forward-right
32     plib_points[4] = where + f + r;
33
34     // Forward-left
35     plib_points[5] = where + f - r;
36
37     // Back-right
38     plib_points[6] = where - f + r;
39
40     // Back-left
41     plib_points[7] = where - f - r;
42
43     for(int i=0;i < 8; ++i)
44     {
45         vector t = plib_points[i];
46         fc  = pathlib_heuristic(t,goal) + pathlib_cost(node, t, pathlib_gridsize);
47         plib_fvals[i] = fc;
48
49     }
50
51     fc = plib_fvals[0];
52     plib_points2[0] = plib_points[0];
53     vector bp;
54     bp = plib_points[0];
55     int fc2 = 0;
56     for(int i = 0; i < 8; ++i)
57     {
58         bool c = false;
59         entity nap = pathlib_nodeatpoint(plib_points[i]);
60         if(nap)
61         {
62             if(nap.owner == openlist)
63                 c = true;
64         }
65         else
66             c = true;
67
68         if(c)
69         if(plib_fvals[i] < fc)
70         {
71             bp = plib_points[i];
72             fc = plib_fvals[i];
73             plib_points2[fc2] = plib_points[i];
74             ++fc2;
75         }
76
77         //nap = pathlib_nodeatpoint(plib_points[i]);
78         //if(nap)
79         //if not nap.owner == closedlist)
80         //{
81         //}
82     }
83
84     pathlib_makenode(node, start, bp, goal, pathlib_gridsize);
85
86     for(int i = 0; i < 3; ++i)
87     {
88         pathlib_makenode(node, start, plib_points2[i], goal, pathlib_gridsize);
89     }
90
91     return pathlib_open_cnt;
92 }
93 */
94
95 float pathlib_expandnode_star(entity node, vector start, vector goal)
96 {
97     vector point;
98
99     vector where = node.origin;
100
101     vector f = PLIB_FORWARD * pathlib_gridsize;
102     vector r = PLIB_RIGHT   * pathlib_gridsize;
103
104     if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_unknown)
105         node.pathlib_node_edgeflags = tile_check_plus2(node, node.origin);
106
107     if(node.pathlib_node_edgeflags == pathlib_node_edgeflag_none)
108     {
109         LOG_TRACE("Node at ", vtos(node.origin), " not expanable");
110         return pathlib_open_cnt;
111     }
112
113     // Forward
114     if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forward)
115     {
116         point = where + f;
117         pathlib_makenode(node, start, point, goal, pathlib_movecost);
118     }
119
120     // Back
121     if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_back)
122     {
123         point = where - f;
124         pathlib_makenode(node, start, point, goal, pathlib_movecost);
125     }
126
127     // Right
128         if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_right)
129     {
130         point = where + r;
131         pathlib_makenode(node, start, point, goal, pathlib_movecost);
132     }
133
134     // Left
135     if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_left)
136     {
137         point = where - r;
138         pathlib_makenode(node, start, point, goal, pathlib_movecost);
139
140     }
141
142     // Forward-right
143     if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardright)
144     {
145         point = where + f + r;
146         pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
147     }
148
149     // Forward-left
150     if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardleft)
151     {
152         point = where + f - r;
153         pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
154
155     }
156
157     // Back-right
158     if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backright)
159     {
160         point = where - f + r;
161         pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
162     }
163
164     // Back-left
165     if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backleft)
166     {
167         point = where - f - r;
168         pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
169     }
170
171     return pathlib_open_cnt;
172 }
173
174 /*
175 float pathlib_expandnode_octagon(entity node, vector start, vector goal)
176 {
177     vector point;
178
179     vector where = node.origin;
180
181     vector f = PLIB_FORWARD * pathlib_gridsize;
182     vector r = PLIB_RIGHT   * pathlib_gridsize;
183
184     // Forward
185     point = where + f;
186     pathlib_makenode(node, start, point, goal, pathlib_movecost);
187
188     // Back
189     point = where - f;
190     pathlib_makenode(node, start, point, goal, pathlib_movecost);
191
192     // Right
193     point = where + r;
194     pathlib_makenode(node, start, point, goal, pathlib_movecost);
195
196     // Left
197     point = where - r;
198     pathlib_makenode(node, start, point, goal, pathlib_movecost);
199
200     f = PLIB_FORWARD * pathlib_gridsize * 0.5;
201     r = PLIB_RIGHT   * pathlib_gridsize * 0.5;
202
203     // Forward-right
204     point = where + f + r;
205     pathlib_makenode(node, start, point, goal, pathlib_movecost);
206
207     // Forward-left
208     point = where + f - r;
209     pathlib_makenode(node, start, point, goal, pathlib_movecost);
210
211     // Back-right
212     point = where - f + r;
213     pathlib_makenode(node, start, point, goal, pathlib_movecost);
214
215     // Back-left
216     point = where - f - r;
217     pathlib_makenode(node, start, point, goal, pathlib_movecost);
218
219     return pathlib_open_cnt;
220 }
221 */
222
223 float pathlib_expandnode_box(entity node, vector start, vector goal)
224 {
225     vector v;
226
227     for(v.z = node.origin.z - pathlib_gridsize; v.z <= node.origin.z + pathlib_gridsize; v.z += pathlib_gridsize)
228     for(v.y = node.origin.y - pathlib_gridsize; v.y <= node.origin.y + pathlib_gridsize; v.y += pathlib_gridsize)
229     for(v.x = node.origin.x - pathlib_gridsize; v.x <= node.origin.x + pathlib_gridsize; v.x += pathlib_gridsize)
230     {
231         //if(vlen(v - node.origin))
232             pathlib_makenode(node,start,v,goal,pathlib_movecost);
233     }
234
235     return pathlib_open_cnt;
236 }