]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
path_waypoint.qc for a* over the exsisting waypoint systm
authorJakob MG <jakob_mg@hotmail.com>
Fri, 2 Apr 2010 19:07:13 +0000 (21:07 +0200)
committerJakob MG <jakob_mg@hotmail.com>
Fri, 2 Apr 2010 19:07:13 +0000 (21:07 +0200)
qcsrc/server/pathlib/debug.qc
qcsrc/server/pathlib/expandnode.qc
qcsrc/server/pathlib/main.qc
qcsrc/server/pathlib/movenode.qc
qcsrc/server/pathlib/path_waypoint.qc [new file with mode: 0644]
qcsrc/server/pathlib/pathlib.qh
qcsrc/server/pathlib/utility.qc

index ac6249f9936365667bd50f2a9f34b5a8a8dd101c..bad8516de6b1b7ab7392f9b93425ba1eca4c2399 100644 (file)
@@ -56,7 +56,7 @@ void pathlib_showsquare2(entity node ,vector ncolor,float align)
 
     if(align)
     {
-        traceline(node.origin + '0 0 32',node.origin - '0 0 128',MOVE_WORLDONLY,node);
+        traceline(node.origin + '0 0 32', node.origin - '0 0 128', MOVE_WORLDONLY, node);
         node.angles = vectoangles(trace_plane_normal);
         node.angles_x -= 90;
     }
index 81c0cd1e7ead44850ebb525ab62f3cc57ccf5a6d..4647fea1392abdba4013b61f2b2c6c99fdde31bb 100644 (file)
@@ -40,7 +40,7 @@ float pathlib_expandnode_starf(entity node, vector start, vector goal)
     for(i=0;i < 8; ++i)
     {
         t = plib_points[i];
-        fc  = pathlib_heuristic(t,goal) + pathlib_cost(node,t,pathlib_gridsize);
+        fc  = pathlib_heuristic(t,goal) + pathlib_cost(node, t, pathlib_gridsize);
         plib_fvals[i] = fc;
 
     }
@@ -77,11 +77,11 @@ float pathlib_expandnode_starf(entity node, vector start, vector goal)
         */
     }
 
-    pathlib_makenode(node,start,bp,goal,pathlib_gridsize);
+    pathlib_makenode(node, start, bp, goal, pathlib_gridsize);
 
     for(i = 0; i < 3; ++i)
     {
-        pathlib_makenode(node,start,plib_points2[i],goal,pathlib_gridsize);
+        pathlib_makenode(node, start, plib_points2[i], goal, pathlib_gridsize);
     }
 
     return pathlib_open_cnt;
@@ -89,44 +89,79 @@ float pathlib_expandnode_starf(entity node, vector start, vector goal)
 
 float pathlib_expandnode_star(entity node, vector start, vector goal)
 {
-    vector point,where,f,r;
+    vector point, where, f, r;
 
     where = node.origin;
 
     f = PLIB_FORWARD * pathlib_gridsize;
     r = PLIB_RIGHT   * pathlib_gridsize;
 
+    if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_unknown)
+        node.pathlib_node_edgeflags = tile_check_plus2(node.origin);
+
+    if(node.pathlib_node_edgeflags == pathlib_node_edgeflag_none)
+    {
+        dprint("Node at ", vtos(node.origin), " not expanable");
+        return pathlib_open_cnt;
+    }
+
     // Forward
-    point = where + f;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forward)
+    {
+        point = where + f;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost);
+    }
 
     // Back
-    point = where - f;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_back)
+    {
+        point = where - f;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost);
+    }
 
     // Right
-    point = where + r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+        if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_right)
+    {
+        point = where + r;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost);
+    }
 
     // Left
-    point = where - r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_left)
+    {
+        point = where - r;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost);
+
+    }
 
     // Forward-right
-    point = where + f + r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost_diag);
+    if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardright)
+    {
+        point = where + f + r;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
+    }
 
     // Forward-left
-    point = where + f - r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost_diag);
+    if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardleft)
+    {
+        point = where + f - r;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
+
+    }
 
     // Back-right
-    point = where - f + r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost_diag);
+    if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backright)
+    {
+        point = where - f + r;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
+    }
 
     // Back-left
-    point = where - f - r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost_diag);
+    if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backleft)
+    {
+        point = where - f - r;
+        pathlib_makenode(node, start, point, goal, pathlib_movecost_diag);
+    }
 
     return pathlib_open_cnt;
 }
@@ -142,40 +177,40 @@ float pathlib_expandnode_octagon(entity node, vector start, vector goal)
 
     // Forward
     point = where + f;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
     // Back
     point = where - f;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
     // Right
     point = where + r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
     // Left
     point = where - r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
     f = PLIB_FORWARD * pathlib_gridsize * 0.5;
     r = PLIB_RIGHT   * pathlib_gridsize * 0.5;
 
     // Forward-right
     point = where + f + r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
 
     // Forward-left
     point = where + f - r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
 
     // Back-right
     point = where - f + r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
     // Back-left
     point = where - f - r;
-    pathlib_makenode(node,start,point,goal,pathlib_movecost);
+    pathlib_makenode(node, start, point, goal, pathlib_movecost);
 
     return pathlib_open_cnt;
 }
index 6d5a785cc61e72e3cfca1f537c60d95b8c905af3..d89e923bad1d8e8a4117e5ea6fb5447532ad06cb 100644 (file)
@@ -28,7 +28,7 @@ entity pathlib_mknode(vector where,entity parent)
     node = pathlib_nodeatpoint(where);
     if(node)
     {
-        mark_error(where,60);
+        mark_error(where, 60);
         return node;
     }
 
@@ -40,19 +40,12 @@ entity pathlib_mknode(vector where,entity parent)
     node.owner        = openlist;
     node.path_prev    = parent;
 
-    setmodel(node,"models/pathlib/square.md3");
-    setsize(node,'0 0 0','0 0 0');
-    node.colormod = randomvec() * 2;
-    node.alpha = 0.25;
-    node.scale     = pathlib_gridsize / 512.001;
 
-    //pathlib_showsquare2(node,'1 1 1',0);//(node.medium & CONTENT_EMPTY));
+    setsize(node, '0 0 0', '0 0 0');
+
     setorigin(node, where);
     node.medium = pointcontents(where);
-
-    mark_info(where,60);
-    //pathlib_showsquare(where,1,30);
-
+    pathlib_showsquare(where, 1 ,15);
 
     ++pathlib_made_cnt;
     ++pathlib_open_cnt;
@@ -70,6 +63,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
 
     if(inwater(parent.origin))
     {
+        dprint("FromWater\n");
         pathlib_expandnode = pathlib_expandnode_box;
         pathlib_movenode   = pathlib_swimnode;
     }
@@ -77,11 +71,13 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     {
         if(inwater(to))
         {
+            dprint("ToWater\n");
             pathlib_expandnode = pathlib_expandnode_box;
             pathlib_movenode   = pathlib_walknode;
         }
         else
         {
+            dprint("LandToLoand\n");
             //if(edge_check(parent.origin))
             //    return 0;
 
@@ -94,6 +90,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     node = pathlib_nodeatpoint(to);
     if(node)
     {
+        dprint("NodeAtPoint\n");
         ++pathlib_merge_cnt;
 
         if(node.owner == openlist)
@@ -120,9 +117,17 @@ 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.origin, to, 0);
+
     if not(pathlib_movenode_goodnode)
+    {
+        //pathlib_showsquare(where, 0 ,30);
+        //pathlib_showsquare(parent.origin, 1 ,30);
+        dprint("pathlib_movenode_goodnode = 0\n");
         return 0;
+    }
+
+    //pathlib_showsquare(where, 1 ,30);
 
     if(pathlib_nodeatpoint(where))
     {
@@ -132,15 +137,20 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
         return 0;
     }
 
+
     if(doedge)
         if not (tile_check(where))
+        {
+            dprint("tile_check fail\n");
+            pathlib_showsquare(where, 0 ,30);
             return 0;
+        }
+
 
     h = pathlib_heuristic(where,goal);
     g = pathlib_cost(parent,where,cost);
     f = g + h;
 
-
     /*
     node = findradius(where,pathlib_gridsize * 0.5);
     while(node)
@@ -175,7 +185,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go
     }
     */
 
-    node = pathlib_mknode(where,parent);
+    node = pathlib_mknode(where, parent);
     node.pathlib_node_h = h;
     node.pathlib_node_g = g;
     node.pathlib_node_f = f;
@@ -358,17 +368,23 @@ entity pathlib_astar(vector from,vector to)
 
     // Select water<->land capable node make/link
     pathlib_makenode     = pathlib_makenode_adaptive;
+
     // Select XYZ cost estimate
     //pathlib_heuristic    = pathlib_h_diagonal3;
     pathlib_heuristic    = pathlib_h_diagonal;
+
     // Select distance + waterfactor cost
     pathlib_cost         = pathlib_g_euclidean_water;
+
     // Select star expander
     pathlib_expandnode   = pathlib_expandnode_star;
+
     // Select walk simulation movement test
     pathlib_movenode     = pathlib_walknode;
+
     // Filter final nodes by direction
     buildpath_nodefilter = buildpath_nodefilter_directional;
+
     // Filter tiles with cross pattern
     tile_check = tile_check_cross;
 
@@ -400,31 +416,37 @@ entity pathlib_astar(vector from,vector to)
     pathlib_gridsize       = 128;
     pathlib_movecost       = pathlib_gridsize;
     pathlib_movecost_diag  = vlen(('1 1 0' * pathlib_gridsize));
-    pathlib_movecost_waterfactor = 1;
+    pathlib_movecost_waterfactor = 25000000;
     pathlib_foundgoal      = 0;
 
-    movenode_boxmax   = self.maxs * 1.25;
-    movenode_boxmin   = self.mins * 1.25;
+    movenode_boxmax   = self.maxs * 1.1;
+    movenode_boxmin   = self.mins * 1.1;
 
-    movenode_stepsize = 32;
+    movenode_stepsize = pathlib_gridsize * 0.25;
 
-    tile_check_size = 65;
+    tile_check_size = pathlib_gridsize * 0.5;
+    tile_check_up   = '0 0 2' * pathlib_gridsize;
     tile_check_up   = '0 0 128';
-    tile_check_down = '0 0 128';
+    tile_check_down = '0 0 3' * pathlib_gridsize;
+    tile_check_down = '0 0 256';
 
+    //movenode_stepup   = '0 0 128';
     movenode_stepup   = '0 0 36';
-    movenode_maxdrop  = '0 0 128';
+    movenode_maxdrop  = '0 0 512';
+    //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");
-    path = pathlib_mknode(from,world);
-    pathlib_close_node(path,to);
+    path = pathlib_mknode(from, world);
+    pathlib_close_node(path, to);
     if(pathlib_foundgoal)
     {
         dprint("AStar: Goal found on first node!\n");
@@ -439,7 +461,7 @@ entity pathlib_astar(vector from,vector to)
         return open;
     }
 
-    if(pathlib_expandnode(path,from,to) <= 0)
+    if(pathlib_expandnode(path, from, to) <= 0)
     {
         dprint("AStar path fail.\n");
         pathlib_cleanup();
@@ -449,11 +471,11 @@ entity pathlib_astar(vector from,vector to)
 
     best_open_node = pathlib_getbestopen();
     n = best_open_node;
-    pathlib_close_node(best_open_node,to);
+    pathlib_close_node(best_open_node, to);
     if(inwater(n.origin))
-        pathlib_expandnode_box(n,from,to);
+        pathlib_expandnode_box(n, from, to);
     else
-        pathlib_expandnode_star(n,from,to);
+        pathlib_expandnode_star(n, from, to);
 
     while(pathlib_open_cnt)
     {
index 59973b0456354747ef0c9f4bb5e03d5075b52126..9369fb4d69f2a179ff47ac74c8677e49349a1449 100644 (file)
@@ -66,11 +66,22 @@ vector pathlib_flynode(vector start,vector end)
     return end;
 }
 
+void a_think()
+{
+    te_lightning1(self,self.origin, self.pos1);
+    if(self.cnt < time)
+        remove(self);
+    else
+        self.nextthink = time + 0.2;
+}
+
 vector pathlib_walknode(vector start,vector end,float doedge)
 {
     vector direction,point,last_point,s,e;
     float steps, distance, i;
 
+    dprint("Walking node from ", vtos(start), " to ", vtos(end), "\n");
+
     pathlib_movenode_goodnode = 0;
 
     end_x = fsnap(end_x,pathlib_gridsize);
@@ -79,9 +90,21 @@ vector pathlib_walknode(vector start,vector end,float doedge)
     start_y = fsnap(start_y,pathlib_gridsize);
 
     // Find the floor
-    traceline(start + movenode_stepup, start - movenode_maxdrop,MOVE_WORLDONLY,self);
+    traceline(start + movenode_stepup, start - movenode_maxdrop, MOVE_WORLDONLY, self);
     if(trace_fraction == 1.0)
+    {
+        entity a;
+        a = spawn();
+        a.think = a_think;
+        a.nextthink = time;
+        setorigin(a,start + movenode_stepup);
+        a.pos1 = trace_endpos;
+        //start - movenode_maxdrop
+        a.cnt = time + 10;
+
+        dprint("I cant walk on air!\n");
         return trace_endpos;
+    }
 
     start = trace_endpos;
 
diff --git a/qcsrc/server/pathlib/path_waypoint.qc b/qcsrc/server/pathlib/path_waypoint.qc
new file mode 100644 (file)
index 0000000..cf123db
--- /dev/null
@@ -0,0 +1,317 @@
+.entity list;
+
+entity pathlib_wpp_goal;
+entity pathlib_wpp_start;
+
+void pathlib_wpp_close(entity wp)
+{
+    --pathlib_open_cnt;
+    ++pathlib_closed_cnt;
+
+    wp.list = closedlist;
+    wp.colormod = '0 1 1';
+
+    if(wp == best_open_node)
+        best_open_node = world;
+
+    if(wp == pathlib_wpp_goal)
+        pathlib_foundgoal = TRUE;
+}
+
+float pathlib_wpp_open(entity wp, entity child, float cost)
+{
+    float g, h, f;
+
+    if(child.list == closedlist)
+        return FALSE;
+
+    g = wp.pathlib_node_g + vlen(child.origin - wp.origin); //cost;
+    h = vlen(child.origin - pathlib_wpp_goal.origin);
+    f = g + h;
+
+
+    child.colormod = '1 0 1';
+    child.path_prev = wp;
+    child.list = openlist;
+    child.pathlib_node_g = g;
+    child.pathlib_node_h = h;
+    child.pathlib_node_f = f;
+
+    ++pathlib_open_cnt;
+
+    if(best_open_node.pathlib_node_f > f)
+        best_open_node = child;
+
+    return TRUE;
+}
+
+float pathlib_wpp_expand(entity wp)
+{
+
+    if(wp.wp00) pathlib_wpp_open(wp,wp.wp00,wp.wp00mincost); else return 0;
+    if(wp.wp01) pathlib_wpp_open(wp,wp.wp01,wp.wp01mincost); else return 1;
+    if(wp.wp02) pathlib_wpp_open(wp,wp.wp02,wp.wp02mincost); else return 2;
+    if(wp.wp03) pathlib_wpp_open(wp,wp.wp03,wp.wp03mincost); else return 3;
+    if(wp.wp04) pathlib_wpp_open(wp,wp.wp04,wp.wp04mincost); else return 4;
+    if(wp.wp05) pathlib_wpp_open(wp,wp.wp05,wp.wp05mincost); else return 5;
+    if(wp.wp06) pathlib_wpp_open(wp,wp.wp06,wp.wp06mincost); else return 6;
+    if(wp.wp07) pathlib_wpp_open(wp,wp.wp07,wp.wp07mincost); else return 7;
+    if(wp.wp08) pathlib_wpp_open(wp,wp.wp08,wp.wp08mincost); else return 8;
+    if(wp.wp09) pathlib_wpp_open(wp,wp.wp09,wp.wp09mincost); else return 9;
+    if(wp.wp10) pathlib_wpp_open(wp,wp.wp10,wp.wp10mincost); else return 10;
+    if(wp.wp11) pathlib_wpp_open(wp,wp.wp11,wp.wp11mincost); else return 11;
+    if(wp.wp12) pathlib_wpp_open(wp,wp.wp12,wp.wp12mincost); else return 12;
+    if(wp.wp13) pathlib_wpp_open(wp,wp.wp13,wp.wp13mincost); else return 13;
+    if(wp.wp14) pathlib_wpp_open(wp,wp.wp14,wp.wp14mincost); else return 14;
+    if(wp.wp15) pathlib_wpp_open(wp,wp.wp15,wp.wp15mincost); else return 15;
+    if(wp.wp16) pathlib_wpp_open(wp,wp.wp16,wp.wp16mincost); else return 16;
+    if(wp.wp17) pathlib_wpp_open(wp,wp.wp17,wp.wp17mincost); else return 17;
+    if(wp.wp18) pathlib_wpp_open(wp,wp.wp18,wp.wp18mincost); else return 18;
+    if(wp.wp19) pathlib_wpp_open(wp,wp.wp19,wp.wp19mincost); else return 19;
+    if(wp.wp20) pathlib_wpp_open(wp,wp.wp20,wp.wp20mincost); else return 20;
+    if(wp.wp21) pathlib_wpp_open(wp,wp.wp21,wp.wp21mincost); else return 21;
+    if(wp.wp22) pathlib_wpp_open(wp,wp.wp22,wp.wp22mincost); else return 22;
+    if(wp.wp23) pathlib_wpp_open(wp,wp.wp23,wp.wp23mincost); else return 23;
+    if(wp.wp24) pathlib_wpp_open(wp,wp.wp24,wp.wp24mincost); else return 24;
+    if(wp.wp25) pathlib_wpp_open(wp,wp.wp25,wp.wp25mincost); else return 25;
+    if(wp.wp26) pathlib_wpp_open(wp,wp.wp26,wp.wp26mincost); else return 26;
+    if(wp.wp27) pathlib_wpp_open(wp,wp.wp27,wp.wp27mincost); else return 27;
+    if(wp.wp28) pathlib_wpp_open(wp,wp.wp28,wp.wp28mincost); else return 28;
+    if(wp.wp29) pathlib_wpp_open(wp,wp.wp29,wp.wp29mincost); else return 29;
+    if(wp.wp30) pathlib_wpp_open(wp,wp.wp30,wp.wp30mincost); else return 30;
+    if(wp.wp31) pathlib_wpp_open(wp,wp.wp31,wp.wp31mincost); else return 31;
+
+}
+
+entity pathlib_wpp_bestopen()
+{
+    entity n, best;
+
+    if(best_open_node)
+        return best_open_node;
+
+    n = findchainentity(list, openlist);
+    /*
+    if not(n)
+    {
+        dprint("pathlib_waypointpath: No more open nodes, path fail.\n");
+        return world;
+    }
+    */
+
+    best = n;
+    while(n)
+    {
+        if(n.pathlib_node_f < best.pathlib_node_f)
+            best = n;
+
+        n = n.chain;
+    }
+
+    return best;
+
+}
+
+entity pathlib_waypointpath(entity from, entity to)
+{
+    entity n;
+    float ptime;
+
+
+    ptime = gettime(GETTIME_REALTIME);
+    pathlib_starttime = ptime;
+
+    if not(openlist)
+        openlist       = spawn();
+
+    if not(closedlist)
+        closedlist     = spawn();
+
+    pathlib_closed_cnt       = 0;
+    pathlib_open_cnt         = 0;
+    pathlib_searched_cnt     = 0;
+
+    pathlib_foundgoal      = FALSE;
+
+
+    dprint("pathlib_waypointpath init\n");
+
+    // Initialize waypoint grid
+    n = findchainentity(owner, waypoint_master);
+    while (n)
+    {
+        n.list = world;
+        n.pathlib_node_g = 0;
+        n.pathlib_node_f = 0;
+        n.pathlib_node_h = 0;
+
+        setmodel(n, "models/runematch/rune.mdl");
+        n.effects = EF_LOWPRECISION;
+        n.colormod = '0 0 0';
+        n.scale = 1;
+
+        n = n.chain;
+    }
+
+    pathlib_wpp_goal  = to;
+    pathlib_wpp_start = from;
+
+    from.list = closedlist;
+    bprint("Expanding ",ftos(pathlib_wpp_expand(from))," links\n");
+    if(pathlib_open_cnt <= 0)
+    {
+        dprint("pathlib_waypointpath: Start waypoint not linked! aborting.\n");
+        return world;
+    }
+
+    return world;
+}
+
+entity pathlib_waypointpath_step()
+{
+    entity n;
+
+
+    /*
+    if((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime)
+    {
+        dprint("pathlib_waypointpath: Path took to long to compute!\n");
+        return world;
+    }
+    */
+
+    n = pathlib_wpp_bestopen();
+    if(!n)
+    {
+        bprint("Cannot find best open node, abort.\n");
+        return world;
+    }
+    pathlib_wpp_close(n);
+
+    if(pathlib_foundgoal)
+    {
+        bprint("Target found. Rebuilding and filtering path...\n");
+        // to-do rebuild (follow path_prev from n untill it hits from) and return path.
+
+        n = pathlib_wpp_goal;
+        while(n != pathlib_wpp_start)
+        {
+            n.scale = 3;
+            n = n.path_prev;
+        }
+        pathlib_wpp_start.colormod = '0 0 1';
+        pathlib_wpp_goal.colormod = '1 0 0';
+
+        return n;
+    }
+
+    bprint("Expanding ",ftos(pathlib_wpp_expand(n))," links\n");
+
+
+    return world;
+}
+
+void plas_think()
+{
+    pathlib_waypointpath_step();
+    if(pathlib_foundgoal)
+        return;
+    self.nextthink = time + 0.1;
+}
+
+void pathlib_waypointpath_autostep()
+{
+    entity n;
+    n = spawn();
+    n.think = plas_think;
+    n.nextthink = time + 0.1;
+}
+
+/*
+entity pathlib_wpp_goal;
+entity pathlib_wpp_start;
+entity pathlib_waypointpath(entity from, entity to)
+{
+    entity path, start, end, open, n, ln;
+    float ptime, ftime, ctime;
+
+
+    ptime = gettime(GETTIME_REALTIME);
+    pathlib_starttime = ptime;
+
+    if not(openlist)
+        openlist       = spawn();
+
+    if not(closedlist)
+        closedlist     = spawn();
+
+    pathlib_closed_cnt       = 0;
+    pathlib_open_cnt         = 0;
+    pathlib_searched_cnt     = 0;
+
+    pathlib_foundgoal      = FALSE;
+
+
+    dprint("pathlib_waypointpath init\n");
+
+    // Initialize waypoint grid
+    n = findchainentity(owner, waypoint_master);
+    while (n)
+    {
+        n.list = world;
+        n.pathlib_node_g = 0;
+        n.pathlib_node_f = 0;
+        n.pathlib_node_h = 0;
+        setmodel(n, "models/runematch/rune.mdl");
+        n.effects = EF_LOWPRECISION;
+        n.colormod = '1 1 1';
+        n.scale = 1;
+    }
+
+    pathlib_wpp_goal = to;
+    pathlib_wpp_start = from;
+
+    from.list = closedlist;
+    pathlib_wpp_expand(from);
+    if(pathlib_open_cnt <= 0)
+    {
+        dprint("pathlib_waypointpath: Start waypoint not linked! aborting.\n");
+        return world;
+    }
+
+    while(pathlib_open_cnt)
+    {
+        if((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime)
+        {
+            dprint("pathlib_waypointpath: Path took to long to compute!\n");
+            return world;
+        }
+
+        n = findentity(world, list, openlist);
+        if not(n)
+        {
+            dprint("pathlib_waypointpath: No more open nodes, path fail.\n");
+            return world;
+        }
+
+        pathlib_wpp_close(n);
+        pathlib_wpp_expand(n);
+
+        if(pathlib_foundgoal)
+        {
+            dprint("Target found. Rebuilding and filtering path...\n");
+            // to-do rebuild (follow path_prev from n untill it hits from) and return path.
+            n = to;
+            do
+            {
+                n.scale = 3;
+                n = n.path_prev;
+            }while(n != from);
+
+            return world;
+        }
+    }
+
+    return world;
+}
+*/
index 19f6ef083be8d924ccbc6b7e768c29a094fe5584..1ceadbc8480faf5473f58fe16a28691c3fa80b97 100644 (file)
@@ -17,6 +17,7 @@ void pathlib_showpath2(entity path);
 
 entity openlist;
 entity closedlist;
+entity edgelist;
 entity goal_node;
 
 .float is_path_node;
@@ -24,6 +25,18 @@ entity goal_node;
 .float pathlib_node_h;
 .float pathlib_node_f;
 
+#define pathlib_node_edgeflag_unknown        0
+#define pathlib_node_edgeflag_left           2
+#define pathlib_node_edgeflag_right          4
+#define pathlib_node_edgeflag_forward        8
+#define pathlib_node_edgeflag_back           16
+#define pathlib_node_edgeflag_backleft       32
+#define pathlib_node_edgeflag_backright      64
+#define pathlib_node_edgeflag_forwardleft    128
+#define pathlib_node_edgeflag_forwardright   256
+#define pathlib_node_edgeflag_none           512
+.float pathlib_node_edgeflags;
+
 float pathlib_open_cnt;
 float pathlib_closed_cnt;
 float pathlib_made_cnt;
@@ -39,7 +52,7 @@ float pathlib_movecost_waterfactor;
 float pathlib_foundgoal;
 
 float pathlib_starttime;
-#define pathlib_maxtime 5
+#define pathlib_maxtime 60
 
 entity best_open_node;
 
@@ -97,3 +110,4 @@ var float  buildpath_nodefilter(vector n,vector c,vector p);
 #include "costs.qc"
 #include "expandnode.qc"
 #include "main.qc"
+#include "path_waypoint.qc"
index 81d06b2c9a6d494b73ebf5dbce42aee8a3a1efd5..5d9fc3d9788c38aab12173b5c7054e3b45e7d2b2 100644 (file)
@@ -90,28 +90,29 @@ float tile_check_cross(vector where)
     f = PLIB_FORWARD * tile_check_size;
     r = PLIB_RIGHT   * tile_check_size;
 
+
     // forward-right
     p = where + f + r;
-    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
-    if not (location_isok(trace_endpos,1,0))
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if not (location_isok(trace_endpos, 1, 0))
         return 0;
 
     // Forward-left
     p = where + f - r;
-    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
-    if not (location_isok(trace_endpos,1,0))
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if not (location_isok(trace_endpos, 1, 0))
         return 0;
 
     // Back-right
     p = where - f + r;
-    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
-    if not (location_isok(trace_endpos,1,0))
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if not (location_isok(trace_endpos, 1 ,0))
         return 0;
 
     //Back-left
     p = where - f - r;
-    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
-    if not (location_isok(trace_endpos,1,0))
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if not (location_isok(trace_endpos, 1, 0))
         return 0;
 
     return 1;
@@ -130,13 +131,13 @@ float tile_check_plus(vector where)
     if not (location_isok(trace_endpos,1,0))
         return 0;
 
+
     //left
     p = where - r;
     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
     if not (location_isok(trace_endpos,1,0))
         return 0;
 
-
     // Right
     p = where + r;
     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
@@ -152,6 +153,100 @@ float tile_check_plus(vector where)
     return 1;
 }
 
+float tile_check_plus2(vector where)
+{
+    vector p,f,r;
+    float i,e;
+
+    f = PLIB_FORWARD * pathlib_gridsize;
+    r = PLIB_RIGHT   * pathlib_gridsize;
+
+//#define pathlib_node_edgeflag_left    2
+//#define pathlib_node_edgeflag_right   4
+//#define pathlib_node_edgeflag_forward 8
+//#define pathlib_node_edgeflag_back    16
+
+    // forward
+    p = where + f;
+    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
+    if (location_isok(trace_endpos,1,0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_forward;
+    }
+
+
+    //left
+    p = where - r;
+    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
+    if (location_isok(trace_endpos,1,0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_left;
+    }
+
+
+    // Right
+    p = where + r;
+    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
+    if (location_isok(trace_endpos,1,0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_right;
+    }
+
+    //Back
+    p = where - f;
+    traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
+    if (location_isok(trace_endpos,1,0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_back;
+    }
+
+    // forward-right
+    p = where + f + r;
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if (location_isok(trace_endpos, 1, 0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_forwardright;
+    }
+
+    // Forward-left
+    p = where + f - r;
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if (location_isok(trace_endpos, 1, 0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_forwardleft;
+    }
+
+    // Back-right
+    p = where - f + r;
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if (location_isok(trace_endpos, 1 ,0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_backright;
+    }
+
+    //Back-left
+    p = where - f - r;
+    traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self);
+    if (location_isok(trace_endpos, 1, 0))
+    {
+       ++i;
+       e |= pathlib_node_edgeflag_backleft;
+    }
+
+
+    if(i == 0)
+        e = pathlib_node_edgeflag_none;
+
+    return e;
+}
+
 float tile_check_star(vector where)
 {
     if(tile_check_plus(where))