]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/system/system_misc.qc
Merge remote-tracking branch 'origin/mrbougo/killspree_bugfix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / system / system_misc.qc
1 /*
2 * Return a angle within +/- 360.
3 */
4 float anglemods(float v)
5 {
6         v = v - 360 * floor(v / 360);
7         
8         if(v >= 180)
9                 return v - 360;
10         else if(v <= -180)
11                 return v + 360;
12         else            
13                 return v;
14 }
15
16 /*
17 * Return the short angle
18 */
19 float shortangle_f(float ang1, float ang2)
20 {
21     if(ang1 > ang2)
22     {
23         if(ang1 > 180)
24             return ang1 - 360;
25     }
26     else
27     {
28         if(ang1 < -180)
29             return ang1 + 360;
30     }
31
32     return ang1;
33 }
34
35 vector shortangle_v(vector ang1, vector ang2)
36 {
37     vector vtmp;
38
39     vtmp_x = shortangle_f(ang1_x,ang2_x);
40     vtmp_y = shortangle_f(ang1_y,ang2_y);
41     vtmp_z = shortangle_f(ang1_z,ang2_z);
42
43     return vtmp;
44 }
45
46 vector shortangle_vxy(vector ang1, vector ang2)
47 {
48     vector vtmp;
49
50     vtmp_x = shortangle_f(ang1_x,ang2_x);
51     vtmp_y = shortangle_f(ang1_y,ang2_y);
52
53     return vtmp;
54 }
55
56
57 /*
58 * Get "real" origin, in worldspace, even if ent is attached to something else.
59 */
60 vector real_origin(entity ent)
61 {
62     entity e;
63     vector v = ((ent.absmin + ent.absmax) * 0.5);
64
65     e = ent.tag_entity;
66     while(e)
67     {
68         v = v + ((e.absmin + e.absmax) * 0.5);
69         e = e.tag_entity;
70     }
71
72     return v;
73 }
74
75 /*
76 * Return the angle between two enteties
77 */
78 vector angleofs(entity from, entity to)
79 {
80     vector v_res;
81     
82     v_res = normalize(to.origin - from.origin);
83     v_res = vectoangles(v_res);
84     v_res = v_res - from.angles;
85
86     if (v_res_x < 0)    v_res_x += 360;
87     if (v_res_x > 180)  v_res_x -= 360;
88
89     if (v_res_y < 0)    v_res_y += 360;
90     if (v_res_y > 180)  v_res_y -= 360;
91
92     return v_res;
93 }
94
95 vector angleofs3(vector from, vector from_a, entity to)
96 {
97     vector v_res;
98     
99     v_res = normalize(to.origin - from);
100     v_res = vectoangles(v_res);
101     v_res = v_res - from_a;
102
103     if (v_res_x < 0)    v_res_x += 360;
104     if (v_res_x > 180)  v_res_x -= 360;
105
106     if (v_res_y < 0)    v_res_y += 360;
107     if (v_res_y > 180)  v_res_y -= 360;
108
109     return v_res;
110 }
111
112 /*
113 * Update self.tur_shotorg by getting up2date bone info
114 * NOTICE this func overwrites the global v_forward, v_right and v_up vectors.
115 */
116 #define turret_tag_fire_update() self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire"));v_forward = normalize(v_forward)
117 float turret_tag_fire_update_s()
118 {
119     if(!self.tur_head)
120     {
121         error("Call to turret_tag_fire_update with self.tur_head missing!\n");
122         self.tur_shotorg = '0 0 0';
123         return FALSE;
124     }
125
126     self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire"));
127     v_forward = normalize(v_forward);
128
129     return TRUE;
130 }
131
132 /*
133 * Railgun-like beam, but has thickness and suppots slowing of target 
134 */
135 void FireImoBeam (vector start, vector end, vector smin, vector smax,
136                   float bforce, float f_dmg, float f_velfactor, float deathtype)
137
138 {
139     vector hitloc, force, endpoint, dir;
140     entity ent;
141
142     dir = normalize(end - start);
143     force = dir * bforce;
144
145     // go a little bit into the wall because we need to hit this wall later
146     end = end + dir;
147
148     // trace multiple times until we hit a wall, each obstacle will be made unsolid.
149     // note down which entities were hit so we can damage them later
150     while (1)
151     {
152         tracebox(start, smin, smax, end, FALSE, self);
153
154         // if it is world we can't hurt it so stop now
155         if (trace_ent == world || trace_fraction == 1)
156             break;
157
158         if (trace_ent.solid == SOLID_BSP)
159             break;
160
161         // make the entity non-solid so we can hit the next one
162         trace_ent.railgunhit = TRUE;
163         trace_ent.railgunhitloc = end;
164         trace_ent.railgunhitsolidbackup = trace_ent.solid;
165
166         // stop if this is a wall
167
168         // make the entity non-solid
169         trace_ent.solid = SOLID_NOT;
170     }
171
172     endpoint = trace_endpos;
173
174     // find all the entities the railgun hit and restore their solid state
175     ent = findfloat(world, railgunhit, TRUE);
176     while (ent)
177     {
178         // restore their solid type
179         ent.solid = ent.railgunhitsolidbackup;
180         ent = findfloat(ent, railgunhit, TRUE);
181     }
182
183     // find all the entities the railgun hit and hurt them
184     ent = findfloat(world, railgunhit, TRUE);
185     while (ent)
186     {
187         // get the details we need to call the damage function
188         hitloc = ent.railgunhitloc;
189         ent.railgunhitloc = '0 0 0';
190         ent.railgunhitsolidbackup = SOLID_NOT;
191         ent.railgunhit = FALSE;
192
193         // apply the damage
194         if (ent.takedamage)
195         {
196             Damage (ent, self, self, f_dmg, deathtype, hitloc, force);
197             ent.velocity = ent.velocity * f_velfactor;
198             //ent.alpha = 0.25 + random() * 0.75;
199         }
200
201         // advance to the next entity
202         ent = findfloat(ent, railgunhit, TRUE);
203     }
204     trace_endpos = endpoint;
205 }
206
207 // Plug this into wherever precache is done.
208 void g_turrets_common_precash()
209 {
210     precache_model ("models/turrets/c512.md3");
211     precache_model ("models/marker.md3");
212 }
213
214 void turrets_precache_debug_models()
215 {
216     precache_model ("models/turrets/c512.md3");
217     precache_model ("models/pathlib/goodsquare.md3");
218     precache_model ("models/pathlib/badsquare.md3");
219     precache_model ("models/pathlib/square.md3");
220     precache_model ("models/pathlib/edge.md3");
221 }
222
223 void turrets_precash()
224 {
225     #ifdef TURRET_DEBUG
226         turrets_precache_debug_models();
227         #endif
228 }
229
230
231 #ifdef TURRET_DEBUG
232 void SUB_Remove();
233 void marker_think()
234 {
235     if(self.cnt)
236     if(self.cnt < time)
237     {
238         self.think = SUB_Remove;
239         self.nextthink = time;
240         return;
241     }
242
243     self.frame += 1;
244     if(self.frame > 29)
245         self.frame = 0;
246
247     self.nextthink = time;
248 }
249
250 void mark_error(vector where,float lifetime)
251 {
252     entity err;
253
254     err = spawn();
255     err.classname = "error_marker";
256     setmodel(err,"models/marker.md3");
257     setorigin(err,where);
258     err.movetype = MOVETYPE_NONE;
259     err.think = marker_think;
260     err.nextthink = time;
261     err.skin = 0;
262     if(lifetime)
263         err.cnt = lifetime + time;
264 }
265
266 void mark_info(vector where,float lifetime)
267 {
268     entity err;
269
270     err = spawn();
271     err.classname = "info_marker";
272     setmodel(err,"models/marker.md3");
273     setorigin(err,where);
274     err.movetype = MOVETYPE_NONE;
275     err.think = marker_think;
276     err.nextthink = time;
277     err.skin = 1;
278     if(lifetime)
279         err.cnt = lifetime + time;
280 }
281
282 entity mark_misc(vector where,float lifetime)
283 {
284     entity err;
285
286     err = spawn();
287     err.classname = "mark_misc";
288     setmodel(err,"models/marker.md3");
289     setorigin(err,where);
290     err.movetype = MOVETYPE_NONE;
291     err.think = marker_think;
292     err.nextthink = time;
293     err.skin = 3;
294     if(lifetime)
295         err.cnt = lifetime + time;
296     return err;
297 }
298
299 /*
300 * Paint a v_color colord circle on target onwho
301 * that fades away over f_time
302 */
303 void paint_target(entity onwho, float f_size, vector v_color, float f_time)
304 {
305     entity e;
306
307     e = spawn();
308     setmodel(e, "models/turrets/c512.md3"); // precision set above
309     e.scale = (f_size/512);
310     //setsize(e, '0 0 0', '0 0 0');
311     //setattachment(e,onwho,"");
312     setorigin(e,onwho.origin + '0 0 1');
313     e.alpha = 0.15;
314     e.movetype = MOVETYPE_FLY;
315
316     e.velocity = (v_color * 32); // + '0 0 1' * 64;
317
318     e.colormod = v_color;
319     SUB_SetFade(e,time,f_time);
320 }
321
322 void paint_target2(entity onwho, float f_size, vector v_color, float f_time)
323 {
324     entity e;
325
326     e = spawn();
327     setmodel(e, "models/turrets/c512.md3"); // precision set above
328     e.scale = (f_size/512);
329     setsize(e, '0 0 0', '0 0 0');
330
331     setorigin(e,onwho.origin + '0 0 1');
332     e.alpha = 0.15;
333     e.movetype = MOVETYPE_FLY;
334
335     e.velocity = (v_color * 32); // + '0 0 1' * 64;
336     e.avelocity_x = -128;
337
338     e.colormod = v_color;
339     SUB_SetFade(e,time,f_time);
340 }
341
342 void paint_target3(vector where, float f_size, vector v_color, float f_time)
343 {
344     entity e;
345     e = spawn();
346     setmodel(e, "models/turrets/c512.md3"); // precision set above
347     e.scale = (f_size/512);
348     setsize(e, '0 0 0', '0 0 0');
349     setorigin(e,where+ '0 0 1');
350     e.movetype = MOVETYPE_NONE;
351     e.velocity = '0 0 0';
352     e.colormod = v_color;
353     SUB_SetFade(e,time,f_time);
354 }
355 #endif