]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/pathlib/main.qc
Rename a few parameters and locals named x, y, z
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / pathlib / main.qc
index f097e8a0fec8199dabff0c0501307ab768bfe703..36c7c1d3147968284bf8a478c68f145cb7e965e6 100644 (file)
@@ -1,4 +1,4 @@
-#include "../_all.qh"
+#include "main.qh"
 
 #include "pathlib.qh"
 #include "utility.qh"
@@ -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;
-        e.nextthink = time;
-        e = e.chain;
-    }
+        setthink(it, SUB_Remove);
+        it.nextthink = time;
+    });
 }
 
 //#define PATHLIB_NODEEXPIRE 0.05
@@ -23,10 +19,17 @@ const float PATHLIB_NODEEXPIRE = 20;
 void dumpnode(entity n)
 {
     n.is_path_node = false;
-    n.think        = SUB_Remove;
+    setthink(n, SUB_Remove);
     n.nextthink    = time;
 }
 
+#if DEBUGPATHING
+void pathlib_showpath(entity start);
+void pathlib_showpath2(entity path);
+void pathlib_showsquare(vector where,float goodsquare,float _lifetime);
+#endif
+
+
 entity pathlib_mknode(vector where,entity parent)
 {
     entity node;
@@ -42,7 +45,7 @@ entity pathlib_mknode(vector where,entity parent)
 
     node = spawn();
 
-    node.think        = SUB_Remove;
+    setthink(node, SUB_Remove);
     node.nextthink    = time + PATHLIB_NODEEXPIRE;
     node.is_path_node = true;
     node.owner        = openlist;
@@ -52,9 +55,9 @@ entity pathlib_mknode(vector where,entity parent)
     setsize(node, '0 0 0', '0 0 0');
 
     setorigin(node, where);
-    node.medium = pointcontents(where);
+#if DEBUGPATHING
     pathlib_showsquare(where, 1 ,15);
-
+#endif
     ++pathlib_made_cnt;
     ++pathlib_open_cnt;
 
@@ -71,7 +74,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
 
     if(inwater(parent.origin))
     {
-        LOG_TRACE("FromWater\n");
+        LOG_TRACE("FromWater");
         pathlib_expandnode = pathlib_expandnode_box;
         pathlib_movenode   = pathlib_swimnode;
     }
@@ -79,13 +82,13 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     {
         if(inwater(to))
         {
-            LOG_TRACE("ToWater\n");
+            LOG_TRACE("ToWater");
             pathlib_expandnode = pathlib_expandnode_box;
             pathlib_movenode   = pathlib_walknode;
         }
         else
         {
-            LOG_TRACE("LandToLoand\n");
+            LOG_TRACE("LandToLoand");
             //if(edge_check(parent.origin))
             //    return 0;
 
@@ -98,7 +101,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     node = pathlib_nodeatpoint(to);
     if(node)
     {
-        LOG_TRACE("NodeAtPoint\n");
+        LOG_TRACE("NodeAtPoint");
         ++pathlib_merge_cnt;
 
         if(node.owner == openlist)
@@ -125,13 +128,13 @@ 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)
     {
         //pathlib_showsquare(where, 0 ,30);
         //pathlib_showsquare(parent.origin, 1 ,30);
-        LOG_TRACE("pathlib_movenode_goodnode = 0\n");
+        LOG_TRACE("pathlib_movenode_goodnode = 0");
         return 0;
     }
 
@@ -139,18 +142,20 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
 
     if(pathlib_nodeatpoint(where))
     {
-        LOG_TRACE("NAP WHERE :",vtos(where),"\n");
-        LOG_TRACE("not NAP TO:",vtos(to),"\n");
-        LOG_TRACE("NAP-NNAP:",ftos(vlen(to-where)),"\n\n");
+        LOG_TRACE("NAP WHERE :",vtos(where));
+        LOG_TRACE("not NAP TO:",vtos(to));
+        LOG_TRACE("NAP-NNAP:",ftos(vlen(to-where)));
         return 0;
     }
 
 
     if(doedge)
-        if (!tile_check(where))
+        if (!tile_check(parent, where))
         {
-            LOG_TRACE("tile_check fail\n");
+            LOG_TRACE("tile_check fail");
+#if DEBUGPATHING
             pathlib_showsquare(where, 0 ,30);
+#endif
             return 0;
         }
 
@@ -170,7 +175,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);
@@ -208,9 +213,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;
@@ -219,19 +221,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;
 }
@@ -241,23 +238,23 @@ void pathlib_close_node(entity node,vector goal)
 
     if(node.owner == closedlist)
     {
-        LOG_TRACE("Pathlib: Tried to close a closed node!\n");
+        LOG_TRACE("Pathlib: Tried to close a closed node!");
         return;
     }
 
     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;
@@ -268,13 +265,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)
     {
         /*
@@ -282,7 +279,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);
@@ -290,21 +287,21 @@ void pathlib_cleanup()
     }
 
     if(openlist)
-        remove(openlist);
+        delete(openlist);
 
     if(closedlist)
-        remove(closedlist);
+        delete(closedlist);
 
-    openlist       = world;
-    closedlist     = world;
+    openlist       = NULL;
+    closedlist     = NULL;
 
 }
 
-float Cosine_Interpolate(float a, float b, float x)
+float Cosine_Interpolate(float a, float b, float c)
 {
     float ft,f;
 
-       ft = x * 3.1415927;
+       ft = c * 3.1415927;
        f = (1 - cos(ft)) * 0.5;
 
        return  a*(1-f) + b*f;
@@ -317,7 +314,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;
@@ -326,9 +323,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;
 
@@ -354,7 +351,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";
@@ -369,8 +366,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;
 
@@ -422,7 +419,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;
 
@@ -432,8 +429,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;
 
@@ -457,17 +454,16 @@ entity pathlib_astar(vector from,vector to)
     to.y = fsnap(to.y, pathlib_gridsize);
     //to_z += 32;
 
-    LOG_TRACE("AStar init\n");
-    path = pathlib_mknode(from, world);
+    LOG_TRACE("AStar init");
+    path = pathlib_mknode(from, NULL);
     pathlib_close_node(path, to);
     if(pathlib_foundgoal)
     {
-        LOG_TRACE("AStar: Goal found on first node!\n");
+        LOG_TRACE("AStar: Goal found on first node!");
 
-        open           = spawn();
+        open           = new(path_end);
         open.owner     = open;
-        open.classname = "path_end";
-        setorigin(open,path.origin);
+        setorigin(open, path.origin);
 
         pathlib_cleanup();
 
@@ -476,10 +472,10 @@ entity pathlib_astar(vector from,vector to)
 
     if(pathlib_expandnode(path, from, to) <= 0)
     {
-        LOG_TRACE("AStar path fail.\n");
+        LOG_TRACE("AStar path fail.");
         pathlib_cleanup();
 
-        return world;
+        return NULL;
     }
 
     best_open_node = pathlib_getbestopen();
@@ -494,14 +490,14 @@ entity pathlib_astar(vector from,vector to)
     {
         if((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime)
         {
-            LOG_TRACE("Path took to long to compute!\n");
-            LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt),"\n");
-            LOG_TRACE("Nodes -    open: ", ftos(pathlib_open_cnt),"\n");
-            LOG_TRACE("Nodes -  merged: ", ftos(pathlib_merge_cnt),"\n");
-            LOG_TRACE("Nodes -  closed: ", ftos(pathlib_closed_cnt),"\n");
+            LOG_TRACE("Path took to long to compute!");
+            LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt));
+            LOG_TRACE("Nodes -    open: ", ftos(pathlib_open_cnt));
+            LOG_TRACE("Nodes -  merged: ", ftos(pathlib_merge_cnt));
+            LOG_TRACE("Nodes -  closed: ", ftos(pathlib_closed_cnt));
 
             pathlib_cleanup();
-            return world;
+            return NULL;
         }
 
         best_open_node = pathlib_getbestopen();
@@ -515,12 +511,12 @@ entity pathlib_astar(vector from,vector to)
 
         if(pathlib_foundgoal)
         {
-            LOG_TRACE("Target found. Rebuilding and filtering path...\n");
+            LOG_TRACE("Target found. Rebuilding and filtering path...");
             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;
@@ -539,31 +535,31 @@ entity pathlib_astar(vector from,vector to)
             ctime = gettime(GETTIME_REALTIME) - ctime;
 
 
-#ifdef DEBUGPATHING
+#if DEBUGPATHING
             pathlib_showpath2(start);
 
-            LOG_TRACE("Time used -      pathfinding: ", ftos(ptime),"\n");
-            LOG_TRACE("Time used - rebuild & filter: ", ftos(ftime),"\n");
-            LOG_TRACE("Time used -          cleanup: ", ftos(ctime),"\n");
-            LOG_TRACE("Time used -            total: ", ftos(ptime + ftime + ctime),"\n");
-            LOG_TRACE("Time used -         # frames: ", ftos(ceil((ptime + ftime + ctime) / sys_frametime)),"\n\n");
-            LOG_TRACE("Nodes -         created: ", ftos(pathlib_made_cnt),"\n");
-            LOG_TRACE("Nodes -            open: ", ftos(pathlib_open_cnt),"\n");
-            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 bestcash -   hits: ", ftos(pathlib_bestcash_hits),"\n");
-            LOG_TRACE("Nodes bestcash -   save: ", ftos(pathlib_bestcash_saved),"\n");
-            LOG_TRACE("AStar done.\n");
+            LOG_TRACE("Time used -      pathfinding: ", ftos(ptime));
+            LOG_TRACE("Time used - rebuild & filter: ", ftos(ftime));
+            LOG_TRACE("Time used -          cleanup: ", ftos(ctime));
+            LOG_TRACE("Time used -            total: ", ftos(ptime + ftime + ctime));
+            LOG_TRACE("Time used -         # frames: ", ftos(ceil((ptime + ftime + ctime) / sys_frametime)));
+            LOG_TRACE("Nodes -         created: ", ftos(pathlib_made_cnt));
+            LOG_TRACE("Nodes -            open: ", ftos(pathlib_open_cnt));
+            LOG_TRACE("Nodes -          merged: ", ftos(pathlib_merge_cnt));
+            LOG_TRACE("Nodes -          closed: ", ftos(pathlib_closed_cnt));
+            LOG_TRACE("Nodes -        searched: ", ftos(pathlib_searched_cnt));
+            LOG_TRACE("Nodes bestopen searched: ", ftos(pathlib_bestopen_searched));
+            LOG_TRACE("Nodes bestcash -   hits: ", ftos(pathlib_bestcash_hits));
+            LOG_TRACE("Nodes bestcash -   save: ", ftos(pathlib_bestcash_saved));
+            LOG_TRACE("AStar done.");
 #endif
             return start;
         }
     }
 
-    LOG_TRACE("A* Faild to find a path! Try a smaller gridsize.\n");
+    LOG_TRACE("A* Faild to find a path! Try a smaller gridsize.");
 
     pathlib_cleanup();
 
-    return world;
+    return NULL;
 }