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