+#include "main.qh"
#include "pathlib.qh"
#include "utility.qh"
e = findchainentity(owner, start);
while(e)
{
- e.think = SUB_Remove_self;
+ setthink(e, SUB_Remove);
e.nextthink = time;
e = e.chain;
}
void dumpnode(entity n)
{
n.is_path_node = false;
- n.think = SUB_Remove_self;
+ setthink(n, SUB_Remove);
n.nextthink = time;
}
-#ifdef DEBUGPATHING
+#if DEBUGPATHING
void pathlib_showpath(entity start);
void pathlib_showpath2(entity path);
+void pathlib_showsquare(vector where,float goodsquare,float _lifetime);
#endif
-void pathlib_showsquare(vector where,float goodsquare,float _lifetime);
-void pathlib_showsquare2(entity node ,vector ncolor,float align);
entity pathlib_mknode(vector where,entity parent)
{
node = spawn();
- node.think = SUB_Remove_self;
+ setthink(node, SUB_Remove);
node.nextthink = time + PATHLIB_NODEEXPIRE;
node.is_path_node = true;
node.owner = openlist;
setorigin(node, where);
node.medium = pointcontents(where);
+#if DEBUGPATHING
pathlib_showsquare(where, 1 ,15);
-
+#endif
++pathlib_made_cnt;
++pathlib_open_cnt;
return 1;
}
- where = pathlib_movenode(parent.origin, to, 0);
+ where = pathlib_movenode(parent, parent.origin, to, 0);
if (!pathlib_movenode_goodnode)
{
if(doedge)
- if (!tile_check(where))
+ if (!tile_check(parent, where))
{
LOG_TRACE("tile_check fail\n");
+#if DEBUGPATHING
pathlib_showsquare(where, 0 ,30);
+#endif
return 0;
}
{
if(node.pathlib_node_g > g)
{
- //pathlib_movenode(where,node.origin,0);
+ //pathlib_movenode(node, where,node.origin,0);
//if(pathlib_movenode_goodnode)
//{
//mark_error(node.origin + '0 0 128',30);
node = findchainentity(owner,openlist);
if(!node)
- return world;
+ return NULL;
bestnode = node;
while(node)
}
if(node == best_open_node)
- best_open_node = world;
+ best_open_node = NULL;
++pathlib_closed_cnt;
--pathlib_open_cnt;
node.owner = closedlist;
- if(vlen(node.origin - goal) <= pathlib_gridsize)
+ if(vdist(node.origin - goal, <=, pathlib_gridsize))
{
vector goalmove;
- goalmove = pathlib_walknode(node.origin,goal,1);
+ goalmove = pathlib_walknode(node, node.origin, goal, 1);
if(pathlib_movenode_goodnode)
{
goal_node = node;
void pathlib_cleanup()
{
- best_open_node = world;
+ best_open_node = NULL;
//return;
entity node;
- node = findfloat(world,is_path_node, true);
+ node = findfloat(NULL,is_path_node, true);
while(node)
{
/*
node.pathlib_node_g = 0;
node.pathlib_node_h = 0;
node.pathlib_node_f = 0;
- node.path_prev = world;
+ node.path_prev = NULL;
*/
dumpnode(node);
if(closedlist)
remove(closedlist);
- openlist = world;
- closedlist = world;
+ openlist = NULL;
+ closedlist = NULL;
}
d2 = normalize(p - c);
d1 = normalize(c - n);
- if(vlen(d1-d2) < 0.25)
+ if(vdist(d1 - d2, <, 0.25))
{
//mark_error(c,30);
return 1;
return 0;
}
-float buildpath_nodefilter_moveskip(vector n,vector c,vector p)
+float buildpath_nodefilter_moveskip(entity this, vector n,vector c,vector p)
{
- pathlib_walknode(p,n,1);
+ pathlib_walknode(this, p, n, 1);
if(pathlib_movenode_goodnode)
return 1;
path.owner = start;
path.path_next = next;
- setorigin(path,where);
+ setorigin(path, where);
if(!next)
path.classname = "path_end";
return path;
}
-entity pathlib_astar(vector from,vector to)
-{SELFPARAM();
+entity pathlib_astar(entity this, vector from,vector to)
+{
entity path, start, end, open, n, ln;
float ptime, ftime, ctime;
pathlib_movecost_waterfactor = 25000000;
pathlib_foundgoal = 0;
- movenode_boxmax = self.maxs * 1.1;
- movenode_boxmin = self.mins * 1.1;
+ movenode_boxmax = this.maxs * 1.1;
+ movenode_boxmin = this.mins * 1.1;
movenode_stepsize = pathlib_gridsize * 0.25;
//to_z += 32;
LOG_TRACE("AStar init\n");
- path = pathlib_mknode(from, world);
+ path = pathlib_mknode(from, NULL);
pathlib_close_node(path, to);
if(pathlib_foundgoal)
{
open = new(path_end);
open.owner = open;
- setorigin(open,path.origin);
+ setorigin(open, path.origin);
pathlib_cleanup();
LOG_TRACE("AStar path fail.\n");
pathlib_cleanup();
- return world;
+ return NULL;
}
best_open_node = pathlib_getbestopen();
LOG_TRACE("Nodes - closed: ", ftos(pathlib_closed_cnt),"\n");
pathlib_cleanup();
- return world;
+ return NULL;
}
best_open_node = pathlib_getbestopen();
ftime = gettime(GETTIME_REALTIME);
ptime = ftime - ptime;
- start = path_build(world,path.origin,world,world);
- end = path_build(world,goal_node.origin,world,start);
+ start = path_build(NULL,path.origin,NULL,NULL);
+ end = path_build(NULL,goal_node.origin,NULL,start);
ln = end;
open = goal_node;
ctime = gettime(GETTIME_REALTIME) - ctime;
-#ifdef DEBUGPATHING
+#if DEBUGPATHING
pathlib_showpath2(start);
LOG_TRACE("Time used - pathfinding: ", ftos(ptime),"\n");
pathlib_cleanup();
- return world;
+ return NULL;
}