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