]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/lib/pathlib/movenode.qc
Merge branch 'TimePath/bot_api' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / lib / pathlib / movenode.qc
1 #include "pathlib.qh"
2 #include "utility.qh"
3
4 vector pathlib_wateroutnode(vector start,vector end, float doedge)
5 {SELFPARAM();
6     vector surface;
7
8     pathlib_movenode_goodnode = 0;
9
10     end.x = fsnap(end.x, pathlib_gridsize);
11     end.y = fsnap(end.y, pathlib_gridsize);
12
13     traceline(end + ('0 0 0.25' * pathlib_gridsize),end - ('0 0 1' * pathlib_gridsize),MOVE_WORLDONLY,self);
14     end = trace_endpos;
15
16     if (!(pointcontents(end - '0 0 1') == CONTENT_SOLID))
17         return end;
18
19     for(surface = start ; surface.z < (end.z + 32); ++surface.z)
20     {
21         if(pointcontents(surface) == CONTENT_EMPTY)
22             break;
23     }
24
25     if(pointcontents(surface + '0 0 1') != CONTENT_EMPTY)
26         return end;
27
28     tracebox(start + '0 0 64', movenode_boxmin,movenode_boxmax, end + '0 0 64', MOVE_WORLDONLY, self);
29     if(trace_fraction == 1)
30         pathlib_movenode_goodnode = 1;
31
32     if(fabs(surface.z - end.z) > 32)
33         pathlib_movenode_goodnode = 0;
34
35     return end;
36 }
37
38 vector pathlib_swimnode(vector start,vector end, float doedge)
39 {SELFPARAM();
40     pathlib_movenode_goodnode = 0;
41
42     if(pointcontents(start) != CONTENT_WATER)
43         return end;
44
45     end.x = fsnap(end.x, pathlib_gridsize);
46     end.y = fsnap(end.y, pathlib_gridsize);
47
48     if(pointcontents(end) == CONTENT_EMPTY)
49         return pathlib_wateroutnode( start, end, doedge);
50
51     tracebox(start, movenode_boxmin,movenode_boxmax, end, MOVE_WORLDONLY, self);
52     if(trace_fraction == 1)
53         pathlib_movenode_goodnode = 1;
54
55     return end;
56 }
57
58 vector pathlib_flynode(vector start,vector end, float doedge)
59 {SELFPARAM();
60     pathlib_movenode_goodnode = 0;
61
62     end.x = fsnap(end.x, pathlib_gridsize);
63     end.y = fsnap(end.y, pathlib_gridsize);
64
65     tracebox(start, movenode_boxmin,movenode_boxmax, end, MOVE_WORLDONLY, self);
66     if(trace_fraction == 1)
67         pathlib_movenode_goodnode = 1;
68
69     return end;
70 }
71
72 void a_think()
73 {SELFPARAM();
74     te_lightning1(self,self.origin, self.pos1);
75     if(self.cnt < time)
76         remove(self);
77     else
78         self.nextthink = time + 0.2;
79 }
80
81 vector pathlib_walknode(vector start,vector end,float doedge)
82 {SELFPARAM();
83     vector direction,point,last_point,s,e;
84     float steps, distance, i;
85
86     LOG_TRACE("Walking node from ", vtos(start), " to ", vtos(end), "\n");
87
88     pathlib_movenode_goodnode = 0;
89
90     end.x = fsnap(end.x,pathlib_gridsize);
91     end.y = fsnap(end.y,pathlib_gridsize);
92     start.x = fsnap(start.x,pathlib_gridsize);
93     start.y = fsnap(start.y,pathlib_gridsize);
94
95     // Find the floor
96     traceline(start + movenode_stepup, start - movenode_maxdrop, MOVE_WORLDONLY, self);
97     if(trace_fraction == 1.0)
98     {
99         entity a;
100         a = spawn();
101         a.think = a_think;
102         a.nextthink = time;
103         setorigin(a,start + movenode_stepup);
104         a.pos1 = trace_endpos;
105         //start - movenode_maxdrop
106         a.cnt = time + 10;
107
108         LOG_TRACE("I cant walk on air!\n");
109         return trace_endpos;
110     }
111
112     start = trace_endpos;
113
114     // Find the direcion, without Z
115     s   = start; e   = end;
116     //e_z = 0; s_z = 0;
117     direction = normalize(e - s);
118
119     distance  = vlen(start - end);
120     steps     = rint(distance / movenode_stepsize);
121
122     last_point = start;
123     for(i = 1; i < steps; ++i)
124     {
125         point = last_point + (direction * movenode_stepsize);
126         traceline(point + movenode_stepup,point - movenode_maxdrop,MOVE_WORLDONLY,self);
127         if(trace_fraction == 1.0)
128             return trace_endpos;
129
130         last_point = trace_endpos;
131     }
132
133     point = last_point + (direction * movenode_stepsize);
134     point.x = fsnap(point.x,pathlib_gridsize);
135     point.y = fsnap(point.y,pathlib_gridsize);
136
137     //dprint("end_x:  ",ftos(end_x),  "  end_y:  ",ftos(end_y),"\n");
138     //dprint("point_x:",ftos(point_x),"  point_y:",ftos(point_y),"\n\n");
139
140     traceline(point + movenode_stepup, point - movenode_maxdrop,MOVE_WORLDONLY,self);
141     if(trace_fraction == 1.0)
142         return trace_endpos;
143
144     last_point = trace_endpos;
145
146     tracebox(start + movenode_boxup, movenode_boxmin,movenode_boxmax, last_point + movenode_boxup, MOVE_WORLDONLY, self);
147     if(trace_fraction != 1.0)
148         return trace_endpos;
149
150     pathlib_movenode_goodnode = 1;
151     return last_point;
152 }