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