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