]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/pathlib/main.qc
Merge branch 'master' into terencehill/slider_anim_improvements
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / pathlib / main.qc
index 9658747eeb7122f393d3cde584c63544b35593db..39847f635d220661cf60c9caa56f57f87b06169f 100644 (file)
@@ -1,3 +1,9 @@
+#include "../_all.qh"
+
+#include "pathlib.qh"
+#include "utility.qh"
+#include "../command/common.qh"
+
 void pathlib_deletepath(entity start)
 {
     entity e;
@@ -12,11 +18,11 @@ void pathlib_deletepath(entity start)
 }
 
 //#define PATHLIB_NODEEXPIRE 0.05
-#define PATHLIB_NODEEXPIRE 20
+const float PATHLIB_NODEEXPIRE = 20;
 
 void dumpnode(entity n)
 {
-    n.is_path_node = FALSE;
+    n.is_path_node = false;
     n.think        = SUB_Remove;
     n.nextthink    = time;
 }
@@ -38,7 +44,7 @@ entity pathlib_mknode(vector where,entity parent)
 
     node.think        = SUB_Remove;
     node.nextthink    = time + PATHLIB_NODEEXPIRE;
-    node.is_path_node = TRUE;
+    node.is_path_node = true;
     node.owner        = openlist;
     node.path_prev    = parent;
 
@@ -58,14 +64,14 @@ entity pathlib_mknode(vector where,entity parent)
 float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goal,float cost)
 {
     entity node;
-    float h,g,f,doedge;
+    float h,g,f,doedge = 0;
     vector where;
 
     ++pathlib_searched_cnt;
 
     if(inwater(parent.origin))
     {
-        dprint("FromWater\n");
+        LOG_TRACE("FromWater\n");
         pathlib_expandnode = pathlib_expandnode_box;
         pathlib_movenode   = pathlib_swimnode;
     }
@@ -73,13 +79,13 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     {
         if(inwater(to))
         {
-            dprint("ToWater\n");
+            LOG_TRACE("ToWater\n");
             pathlib_expandnode = pathlib_expandnode_box;
             pathlib_movenode   = pathlib_walknode;
         }
         else
         {
-            dprint("LandToLoand\n");
+            LOG_TRACE("LandToLoand\n");
             //if(edge_check(parent.origin))
             //    return 0;
 
@@ -92,7 +98,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     node = pathlib_nodeatpoint(to);
     if(node)
     {
-        dprint("NodeAtPoint\n");
+        LOG_TRACE("NodeAtPoint\n");
         ++pathlib_merge_cnt;
 
         if(node.owner == openlist)
@@ -110,7 +116,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
                 node.path_prev = parent;
             }
 
-            if not (best_open_node)
+            if (!best_open_node)
                 best_open_node = node;
             else if(best_open_node.pathlib_node_f > node.pathlib_node_f)
                 best_open_node = node;
@@ -121,11 +127,11 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
 
     where = pathlib_movenode(parent.origin, to, 0);
 
-    if not(pathlib_movenode_goodnode)
+    if (!pathlib_movenode_goodnode)
     {
         //pathlib_showsquare(where, 0 ,30);
         //pathlib_showsquare(parent.origin, 1 ,30);
-        dprint("pathlib_movenode_goodnode = 0\n");
+        LOG_TRACE("pathlib_movenode_goodnode = 0\n");
         return 0;
     }
 
@@ -133,17 +139,17 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
 
     if(pathlib_nodeatpoint(where))
     {
-        dprint("NAP WHERE :",vtos(where),"\n");
-        dprint("not NAP TO:",vtos(to),"\n");
-        dprint("NAP-NNAP:",ftos(vlen(to-where)),"\n\n");
+        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");
         return 0;
     }
 
 
     if(doedge)
-        if not (tile_check(where))
+        if (!tile_check(where))
         {
-            dprint("tile_check fail\n");
+            LOG_TRACE("tile_check fail\n");
             pathlib_showsquare(where, 0 ,30);
             return 0;
         }
@@ -157,7 +163,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     node = findradius(where,pathlib_gridsize * 0.5);
     while(node)
     {
-        if(node.is_path_node == TRUE)
+        if(node.is_path_node == true)
         {
             ++pathlib_merge_cnt;
             if(node.owner == openlist)
@@ -175,7 +181,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
                     //}
                 }
 
-                if not (best_open_node)
+                if (!best_open_node)
                     best_open_node = node;
                 else if(best_open_node.pathlib_node_f > node.pathlib_node_f)
                     best_open_node = node;
@@ -192,7 +198,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     node.pathlib_node_g = g;
     node.pathlib_node_f = f;
 
-    if not (best_open_node)
+    if (!best_open_node)
         best_open_node = node;
     else if(best_open_node.pathlib_node_f > node.pathlib_node_f)
         best_open_node = node;
@@ -235,7 +241,7 @@ void pathlib_close_node(entity node,vector goal)
 
     if(node.owner == closedlist)
     {
-        dprint("Pathlib: Tried to close a closed node!\n");
+        LOG_TRACE("Pathlib: Tried to close a closed node!\n");
         return;
     }
 
@@ -255,7 +261,7 @@ void pathlib_close_node(entity node,vector goal)
         if(pathlib_movenode_goodnode)
         {
             goal_node         = node;
-            pathlib_foundgoal = TRUE;
+            pathlib_foundgoal = true;
         }
     }
 }
@@ -268,7 +274,7 @@ void pathlib_cleanup()
 
     entity node;
 
-    node = findfloat(world,is_path_node, TRUE);
+    node = findfloat(world,is_path_node, true);
     while(node)
     {
         /*
@@ -280,7 +286,7 @@ void pathlib_cleanup()
         */
 
         dumpnode(node);
-        node = findfloat(node,is_path_node, TRUE);
+        node = findfloat(node,is_path_node, true);
     }
 
     if(openlist)
@@ -405,10 +411,10 @@ entity pathlib_astar(vector from,vector to)
         pathlib_movenode   = pathlib_swimnode;
     }
 
-    if not(openlist)
+    if (!openlist)
         openlist       = spawn();
 
-    if not(closedlist)
+    if (!closedlist)
         closedlist     = spawn();
 
     pathlib_closed_cnt       = 0;
@@ -443,20 +449,20 @@ entity pathlib_astar(vector from,vector to)
     //movenode_maxdrop  = '0 0 512';
     movenode_boxup    = '0 0 72';
 
-    from_x = fsnap(from_x, pathlib_gridsize);
-    from_y = fsnap(from_y, pathlib_gridsize);
+    from.x = fsnap(from.x, pathlib_gridsize);
+    from.y = fsnap(from.y, pathlib_gridsize);
     //from_z += 32;
 
-    to_x = fsnap(to_x, pathlib_gridsize);
-    to_y = fsnap(to_y, pathlib_gridsize);
+    to.x = fsnap(to.x, pathlib_gridsize);
+    to.y = fsnap(to.y, pathlib_gridsize);
     //to_z += 32;
 
-    dprint("AStar init\n");
+    LOG_TRACE("AStar init\n");
     path = pathlib_mknode(from, world);
     pathlib_close_node(path, to);
     if(pathlib_foundgoal)
     {
-        dprint("AStar: Goal found on first node!\n");
+        LOG_TRACE("AStar: Goal found on first node!\n");
 
         open           = spawn();
         open.owner     = open;
@@ -470,7 +476,7 @@ entity pathlib_astar(vector from,vector to)
 
     if(pathlib_expandnode(path, from, to) <= 0)
     {
-        dprint("AStar path fail.\n");
+        LOG_TRACE("AStar path fail.\n");
         pathlib_cleanup();
 
         return world;
@@ -488,11 +494,11 @@ entity pathlib_astar(vector from,vector to)
     {
         if((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime)
         {
-            dprint("Path took to long to compute!\n");
-            dprint("Nodes - created: ", ftos(pathlib_made_cnt),"\n");
-            dprint("Nodes -    open: ", ftos(pathlib_open_cnt),"\n");
-            dprint("Nodes -  merged: ", ftos(pathlib_merge_cnt),"\n");
-            dprint("Nodes -  closed: ", ftos(pathlib_closed_cnt),"\n");
+            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");
 
             pathlib_cleanup();
             return world;
@@ -509,7 +515,7 @@ entity pathlib_astar(vector from,vector to)
 
         if(pathlib_foundgoal)
         {
-            dprint("Target found. Rebuilding and filtering path...\n");
+            LOG_TRACE("Target found. Rebuilding and filtering path...\n");
             ftime = gettime(GETTIME_REALTIME);
             ptime = ftime - ptime;
 
@@ -536,26 +542,26 @@ entity pathlib_astar(vector from,vector to)
 #ifdef DEBUGPATHING
             pathlib_showpath2(start);
 
-            dprint("Time used -      pathfinding: ", ftos(ptime),"\n");
-            dprint("Time used - rebuild & filter: ", ftos(ftime),"\n");
-            dprint("Time used -          cleanup: ", ftos(ctime),"\n");
-            dprint("Time used -            total: ", ftos(ptime + ftime + ctime),"\n");
-            dprint("Time used -         # frames: ", ftos(ceil((ptime + ftime + ctime) / sys_frametime)),"\n\n");
-            dprint("Nodes -         created: ", ftos(pathlib_made_cnt),"\n");
-            dprint("Nodes -            open: ", ftos(pathlib_open_cnt),"\n");
-            dprint("Nodes -          merged: ", ftos(pathlib_merge_cnt),"\n");
-            dprint("Nodes -          closed: ", ftos(pathlib_closed_cnt),"\n");
-            dprint("Nodes -        searched: ", ftos(pathlib_searched_cnt),"\n");
-            dprint("Nodes bestopen searched: ", ftos(pathlib_bestopen_seached),"\n");
-            dprint("Nodes bestcash -   hits: ", ftos(pathlib_bestcash_hits),"\n");
-            dprint("Nodes bestcash -   save: ", ftos(pathlib_bestcash_saved),"\n");
-            dprint("AStar done.\n");
+            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");
 #endif
             return start;
         }
     }
 
-    dprint("A* Faild to find a path! Try a smaller gridsize.\n");
+    LOG_TRACE("A* Faild to find a path! Try a smaller gridsize.\n");
 
     pathlib_cleanup();