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)
44 vector t = plib_points[i];
45 fc = pathlib_heuristic(t,goal) + pathlib_cost(node, t, pathlib_gridsize);
51 plib_points2[0] = plib_points[0];
55 for(int i = 0; i < 8; ++i)
58 entity nap = pathlib_nodeatpoint(plib_points[i]);
61 if(nap.owner == openlist)
68 if(plib_fvals[i] < fc)
72 plib_points2[fc2] = plib_points[i];
77 nap = pathlib_nodeatpoint(plib_points[i]);
79 if not nap.owner == closedlist)
85 pathlib_makenode(node, start, bp, goal, pathlib_gridsize);
87 for(int i = 0; i < 3; ++i)
89 pathlib_makenode(node, start, plib_points2[i], goal, pathlib_gridsize);
92 return pathlib_open_cnt;
95 float pathlib_expandnode_star(entity node, vector start, vector goal)
99 vector where = node.origin;
101 vector f = PLIB_FORWARD * pathlib_gridsize;
102 vector r = PLIB_RIGHT * pathlib_gridsize;
104 if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_unknown)
105 node.pathlib_node_edgeflags = tile_check_plus2(node, node.origin);
107 if(node.pathlib_node_edgeflags == pathlib_node_edgeflag_none)
109 LOG_TRACE("Node at ", vtos(node.origin), " not expanable");
110 return pathlib_open_cnt;
114 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forward)
117 pathlib_makenode(node, start, point, goal, pathlib_movecost);
121 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_back)
124 pathlib_makenode(node, start, point, goal, pathlib_movecost);
128 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_right)
131 pathlib_makenode(node, start, point, goal, pathlib_movecost);
135 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_left)
138 pathlib_makenode(node, start, point, goal, pathlib_movecost);
143 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardright)
145 point = where + f + r;
146 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
150 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardleft)
152 point = where + f - r;
153 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
158 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backright)
160 point = where - f + r;
161 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
165 if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backleft)
167 point = where - f - r;
168 pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
171 return pathlib_open_cnt;
174 float pathlib_expandnode_octagon(entity node, vector start, vector goal)
178 vector where = node.origin;
180 vector f = PLIB_FORWARD * pathlib_gridsize;
181 vector r = PLIB_RIGHT * pathlib_gridsize;
185 pathlib_makenode(node, start, point, goal, pathlib_movecost);
189 pathlib_makenode(node, start, point, goal, pathlib_movecost);
193 pathlib_makenode(node, start, point, goal, pathlib_movecost);
197 pathlib_makenode(node, start, point, goal, pathlib_movecost);
199 f = PLIB_FORWARD * pathlib_gridsize * 0.5;
200 r = PLIB_RIGHT * pathlib_gridsize * 0.5;
203 point = where + f + r;
204 pathlib_makenode(node, start, point, goal, pathlib_movecost);
208 point = where + f - r;
209 pathlib_makenode(node, start, point, goal, pathlib_movecost);
213 point = where - f + r;
214 pathlib_makenode(node, start, point, goal, pathlib_movecost);
217 point = where - f - r;
218 pathlib_makenode(node, start, point, goal, pathlib_movecost);
220 return pathlib_open_cnt;
223 float pathlib_expandnode_box(entity node, vector start, vector goal)
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)
231 //if(vlen(v - node.origin))
232 pathlib_makenode(node,start,v,goal,pathlib_movecost);
235 return pathlib_open_cnt;