]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/pathlib/utility.qc
My first GIT commit :) Implements UT2k4 style air-jumping (jumping again in mid air...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / pathlib / utility.qc
1 float fsnap(float val,float fsize)
2 {
3     return rint(val / fsize) * fsize;
4 }
5
6 vector vsnap(vector point,float fsize)
7 {
8     vector vret;
9
10     vret_x = rint(point_x / fsize) * fsize;
11     vret_y = rint(point_y / fsize) * fsize;
12     vret_z = ceil(point_z / fsize) * fsize;
13
14     return vret;
15 }
16
17 float location_isok(vector point, float water_isok, float air_isok)
18 {
19     float pc,pc2;
20
21     if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
22         return 0;
23
24     pc  = pointcontents(point);
25     pc2 = pointcontents(point - '0 0 1');
26
27     switch(pc)
28     {
29         case CONTENT_SOLID:
30             break;
31
32         case CONTENT_SLIME:
33             break;
34
35         case CONTENT_LAVA:
36             break;
37
38         case CONTENT_SKY:
39             break;
40
41         case CONTENT_EMPTY:
42             if (pc2 == CONTENT_SOLID)
43                 return 1;
44
45             if (pc2 == CONTENT_EMPTY)
46                 if(air_isok)
47                     return 1;
48
49             if (pc2 == CONTENT_WATER)
50                 if(water_isok)
51                     return 1;
52
53             break;
54
55         case CONTENT_WATER:
56             if (water_isok)
57                 return 1;
58
59             break;
60     }
61
62     return 0;
63 }
64
65 entity pathlib_nodeatpoint(vector where)
66 {
67     entity node;
68
69     ++pathlib_searched_cnt;
70
71     where_x = fsnap(where_x,pathlib_gridsize);
72     where_y = fsnap(where_y,pathlib_gridsize);
73
74     node = findradius(where,pathlib_gridsize * 0.5);
75     while(node)
76     {
77         if(node.is_path_node == TRUE)
78             return node;
79
80         node = node.chain;
81     }
82
83     return world;
84 }
85
86 float tile_check_cross(vector where)
87 {
88     vector p,f,r;
89
90     f = PLIB_FORWARD * tile_check_size;
91     r = PLIB_RIGHT   * tile_check_size;
92
93     // forward-right
94     p = where + f + r;
95     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
96     if not (location_isok(trace_endpos,1,0))
97         return 0;
98
99     // Forward-left
100     p = where + f - r;
101     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
102     if not (location_isok(trace_endpos,1,0))
103         return 0;
104
105     // Back-right
106     p = where - f + r;
107     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
108     if not (location_isok(trace_endpos,1,0))
109         return 0;
110
111     //Back-left
112     p = where - f - r;
113     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
114     if not (location_isok(trace_endpos,1,0))
115         return 0;
116
117     return 1;
118 }
119
120 float tile_check_plus(vector where)
121 {
122     vector p,f,r;
123
124     f = PLIB_FORWARD * tile_check_size;
125     r = PLIB_RIGHT   * tile_check_size;
126
127     // forward
128     p = where + f;
129     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
130     if not (location_isok(trace_endpos,1,0))
131         return 0;
132
133     //left
134     p = where - r;
135     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
136     if not (location_isok(trace_endpos,1,0))
137         return 0;
138
139
140     // Right
141     p = where + r;
142     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
143     if not (location_isok(trace_endpos,1,0))
144         return 0;
145
146     //Back
147     p = where - f;
148     traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
149     if not (location_isok(trace_endpos,1,0))
150         return 0;
151
152     return 1;
153 }
154
155 float tile_check_star(vector where)
156 {
157     if(tile_check_plus(where))
158         return tile_check_cross(where);
159
160     return 0;
161 }
162