1 #include "expandnode.qh"
5 vector plib_points2[8];
9 float pathlib_expandnode_starf(entity node, vector start, vector goal)
13 vector where = node.origin;
15 vector f = PLIB_FORWARD * pathlib_gridsize;
16 vector r = PLIB_RIGHT * pathlib_gridsize;
19 plib_points[0] = where + f;
22 plib_points[1] = where - f;
25 plib_points[2] = where + r;
28 plib_points[3] = where - r;
31 plib_points[4] = where + f + r;
34 plib_points[5] = where + f - r;
37 plib_points[6] = where - f + r;
40 plib_points[7] = where - f - r;
42 for (int i = 0; i < 8; ++i) {
43 vector t = plib_points[i];
44 fc = pathlib_heuristic(t, goal) + pathlib_cost(node, t, pathlib_gridsize);
49 plib_points2[0] = plib_points[0];
53 for (int i = 0; i < 8; ++i) {
55 entity nap = pathlib_nodeatpoint(plib_points[i]);
57 if (nap.owner == openlist) {
65 if (plib_fvals[i] < fc) {
68 plib_points2[fc2] = plib_points[i];
74 nap = pathlib_nodeatpoint(plib_points[i]);
76 if not nap.owner == closedlist)
82 pathlib_makenode(node, start, bp, goal, pathlib_gridsize);
84 for (int i = 0; i < 3; ++i) {
85 pathlib_makenode(node, start, plib_points2[i], goal, pathlib_gridsize);
88 return pathlib_open_cnt;
91 float pathlib_expandnode_star(entity node, vector start, vector goal)
95 vector where = node.origin;
97 vector f = PLIB_FORWARD * pathlib_gridsize;
98 vector r = PLIB_RIGHT * pathlib_gridsize;
100 if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_unknown) {
101 node.pathlib_node_edgeflags = tile_check_plus2(node, node.origin);
104 if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_none) {
105 LOG_TRACE("Node at ", vtos(node.origin), " not expanable");
106 return pathlib_open_cnt;
110 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forward) {
112 pathlib_makenode(node, start, point, goal, pathlib_movecost);
116 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_back) {
118 pathlib_makenode(node, start, point, goal, pathlib_movecost);
122 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_right) {
124 pathlib_makenode(node, start, point, goal, pathlib_movecost);
128 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_left) {
130 pathlib_makenode(node, start, point, goal, pathlib_movecost);
134 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardright) {
135 point = where + f + r;
136 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
140 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardleft) {
141 point = where + f - r;
142 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
146 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backright) {
147 point = where - f + r;
148 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
152 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backleft) {
153 point = where - f - r;
154 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
157 return pathlib_open_cnt;
160 float pathlib_expandnode_octagon(entity node, vector start, vector goal)
164 vector where = node.origin;
166 vector f = PLIB_FORWARD * pathlib_gridsize;
167 vector r = PLIB_RIGHT * pathlib_gridsize;
171 pathlib_makenode(node, start, point, goal, pathlib_movecost);
175 pathlib_makenode(node, start, point, goal, pathlib_movecost);
179 pathlib_makenode(node, start, point, goal, pathlib_movecost);
183 pathlib_makenode(node, start, point, goal, pathlib_movecost);
185 f = PLIB_FORWARD * pathlib_gridsize * 0.5;
186 r = PLIB_RIGHT * pathlib_gridsize * 0.5;
189 point = where + f + r;
190 pathlib_makenode(node, start, point, goal, pathlib_movecost);
194 point = where + f - r;
195 pathlib_makenode(node, start, point, goal, pathlib_movecost);
199 point = where - f + r;
200 pathlib_makenode(node, start, point, goal, pathlib_movecost);
203 point = where - f - r;
204 pathlib_makenode(node, start, point, goal, pathlib_movecost);
206 return pathlib_open_cnt;
209 float pathlib_expandnode_box(entity node, vector start, vector goal)
213 for (v.z = node.origin.z - pathlib_gridsize; v.z <= node.origin.z + pathlib_gridsize; v.z += pathlib_gridsize) {
214 for (v.y = node.origin.y - pathlib_gridsize; v.y <= node.origin.y + pathlib_gridsize; v.y += pathlib_gridsize) {
215 for (v.x = node.origin.x - pathlib_gridsize; v.x <= node.origin.x + pathlib_gridsize; v.x += pathlib_gridsize) {
216 // if(vlen(v - node.origin))
217 pathlib_makenode(node, start, v, goal, pathlib_movecost);
222 return pathlib_open_cnt;