]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/pathlib/main.qc
Merge branch 'Mario/intrusive' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / pathlib / main.qc
index d0c70b2b88dff8e9ec43c838c5f2b7dc4eb9907b..b07d86384cea58417eca4f60159440662401d4fd 100644 (file)
@@ -6,15 +6,11 @@
 
 void pathlib_deletepath(entity start)
 {
-    entity e;
-
-    e = findchainentity(owner, start);
-    while(e)
+    FOREACH_ENTITY_ENT(owner, start,
     {
-        e.think = SUB_Remove_self;
-        e.nextthink = time;
-        e = e.chain;
-    }
+        setthink(it, SUB_Remove);
+        it.nextthink = time;
+    });
 }
 
 //#define PATHLIB_NODEEXPIRE 0.05
@@ -23,7 +19,7 @@ const float PATHLIB_NODEEXPIRE = 20;
 void dumpnode(entity n)
 {
     n.is_path_node = false;
-    n.think        = SUB_Remove_self;
+    setthink(n, SUB_Remove);
     n.nextthink    = time;
 }
 
@@ -49,7 +45,7 @@ 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;
@@ -133,7 +129,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
         return 1;
     }
 
-    where = pathlib_movenode(parent.origin, to, 0);
+    where = pathlib_movenode(parent, parent.origin, to, 0);
 
     if (!pathlib_movenode_goodnode)
     {
@@ -155,7 +151,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
 
 
     if(doedge)
-        if (!tile_check(where))
+        if (!tile_check(parent, where))
         {
             LOG_TRACE("tile_check fail\n");
 #if DEBUGPATHING
@@ -180,7 +176,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
             {
                 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);
@@ -218,9 +214,6 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
 
 entity pathlib_getbestopen()
 {
-    entity node;
-    entity bestnode;
-
     if(best_open_node)
     {
         ++pathlib_bestcash_hits;
@@ -229,19 +222,14 @@ entity pathlib_getbestopen()
         return best_open_node;
     }
 
-    node = findchainentity(owner,openlist);
-    if(!node)
-        return world;
-
-    bestnode = node;
-    while(node)
+    entity bestnode = NULL;
+    FOREACH_ENTITY_ENT(owner, openlist,
     {
-        ++pathlib_bestopen_seached;
-        if(node.pathlib_node_f < bestnode.pathlib_node_f)
-            bestnode = node;
+        ++pathlib_bestopen_searched;
 
-        node = node.chain;
-    }
+        if(!bestnode || it.pathlib_node_f < bestnode.pathlib_node_f)
+            bestnode = it;
+    });
 
     return bestnode;
 }
@@ -256,18 +244,18 @@ void pathlib_close_node(entity node,vector goal)
     }
 
     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;
@@ -278,13 +266,13 @@ void pathlib_close_node(entity node,vector goal)
 
 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)
     {
         /*
@@ -292,7 +280,7 @@ void pathlib_cleanup()
         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);
@@ -300,13 +288,13 @@ void pathlib_cleanup()
     }
 
     if(openlist)
-        remove(openlist);
+        delete(openlist);
 
     if(closedlist)
-        remove(closedlist);
+        delete(closedlist);
 
-    openlist       = world;
-    closedlist     = world;
+    openlist       = NULL;
+    closedlist     = NULL;
 
 }
 
@@ -327,7 +315,7 @@ float buildpath_nodefilter_directional(vector n,vector c,vector p)
     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;
@@ -336,9 +324,9 @@ float buildpath_nodefilter_directional(vector n,vector c,vector p)
     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;
 
@@ -364,7 +352,7 @@ entity path_build(entity next, vector where, entity prev, entity start)
     path.owner     = start;
     path.path_next = next;
 
-    setorigin(path,where);
+    setorigin(path, where);
 
     if(!next)
         path.classname = "path_end";
@@ -379,8 +367,8 @@ entity path_build(entity next, vector where, entity prev, entity start)
     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;
 
@@ -432,7 +420,7 @@ entity pathlib_astar(vector from,vector to)
     pathlib_made_cnt         = 0;
     pathlib_merge_cnt        = 0;
     pathlib_searched_cnt     = 0;
-    pathlib_bestopen_seached = 0;
+    pathlib_bestopen_searched = 0;
     pathlib_bestcash_hits    = 0;
     pathlib_bestcash_saved   = 0;
 
@@ -442,8 +430,8 @@ entity pathlib_astar(vector from,vector to)
     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;
 
@@ -468,7 +456,7 @@ entity pathlib_astar(vector from,vector to)
     //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)
     {
@@ -476,7 +464,7 @@ entity pathlib_astar(vector from,vector to)
 
         open           = new(path_end);
         open.owner     = open;
-        setorigin(open,path.origin);
+        setorigin(open, path.origin);
 
         pathlib_cleanup();
 
@@ -488,7 +476,7 @@ entity pathlib_astar(vector from,vector to)
         LOG_TRACE("AStar path fail.\n");
         pathlib_cleanup();
 
-        return world;
+        return NULL;
     }
 
     best_open_node = pathlib_getbestopen();
@@ -510,7 +498,7 @@ entity pathlib_astar(vector from,vector to)
             LOG_TRACE("Nodes -  closed: ", ftos(pathlib_closed_cnt),"\n");
 
             pathlib_cleanup();
-            return world;
+            return NULL;
         }
 
         best_open_node = pathlib_getbestopen();
@@ -528,8 +516,8 @@ entity pathlib_astar(vector from,vector to)
             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;
@@ -561,7 +549,7 @@ entity pathlib_astar(vector from,vector to)
             LOG_TRACE("Nodes -          merged: ", ftos(pathlib_merge_cnt),"\n");
             LOG_TRACE("Nodes -          closed: ", ftos(pathlib_closed_cnt),"\n");
             LOG_TRACE("Nodes -        searched: ", ftos(pathlib_searched_cnt),"\n");
-            LOG_TRACE("Nodes bestopen searched: ", ftos(pathlib_bestopen_seached),"\n");
+            LOG_TRACE("Nodes bestopen searched: ", ftos(pathlib_bestopen_searched),"\n");
             LOG_TRACE("Nodes bestcash -   hits: ", ftos(pathlib_bestcash_hits),"\n");
             LOG_TRACE("Nodes bestcash -   save: ", ftos(pathlib_bestcash_saved),"\n");
             LOG_TRACE("AStar done.\n");
@@ -574,5 +562,5 @@ entity pathlib_astar(vector from,vector to)
 
     pathlib_cleanup();
 
-    return world;
+    return NULL;
 }