1 //--// Some support routines //--//
3 #define anglemodss(a) (a - floor(a / 360) * 360)
4 float(float v) anglemods =
6 v = v - 360 * floor(v / 360);
9 float safeangle(float a)
11 if((a > -361) && (a < 361))
14 a -= (360 * floor(a / 360));
19 float shortangle_f(float ang1,float ang2)
35 vector shortangle_v(vector ang1,vector ang2)
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);
46 vector shortangle_vxy(vector ang1,vector ang2)
50 vtmp_x = shortangle_f(ang1_x,ang2_x);
51 vtmp_y = shortangle_f(ang1_y,ang2_y);
57 vector real_origin(entity ent)
66 v = v + ((e.absmin + e.absmax) * 0.5);
70 v = v + ((ent.absmin + ent.absmax) * 0.5);
74 // Plug this into wherever precache is done.
75 void g_turrets_common_precash()
77 precache_model ("models/turrets/c512.md3");
78 precache_model ("models/marker.md3");
87 self.think = SUB_Remove;
88 self.nextthink = time;
96 self.nextthink = time;
99 void mark_error(vector where,float lifetime)
104 err.classname = "error_marker";
105 setmodel(err,"models/marker.md3");
106 setorigin(err,where);
107 err.movetype = MOVETYPE_NONE;
108 err.think = marker_think;
109 err.nextthink = time;
112 err.cnt = lifetime + time;
115 void mark_info(vector where,float lifetime)
120 err.classname = "info_marker";
121 setmodel(err,"models/marker.md3");
122 setorigin(err,where);
123 err.movetype = MOVETYPE_NONE;
124 err.think = marker_think;
125 err.nextthink = time;
128 err.cnt = lifetime + time;
131 entity mark_misc(vector where,float lifetime)
136 err.classname = "mark_misc";
137 setmodel(err,"models/marker.md3");
138 setorigin(err,where);
139 err.movetype = MOVETYPE_NONE;
140 err.think = marker_think;
141 err.nextthink = time;
144 err.cnt = lifetime + time;
149 * Paint a v_color colord circle on target onwho
150 * that fades away over f_time
152 void paint_target(entity onwho, float f_size, vector v_color, float f_time)
157 setmodel(e, "models/turrets/c512.md3"); // precision set above
158 e.scale = (f_size/512);
159 //setsize(e, '0 0 0', '0 0 0');
160 //setattachment(e,onwho,"");
161 setorigin(e,onwho.origin + '0 0 1');
163 e.movetype = MOVETYPE_FLY;
165 e.velocity = (v_color * 32); // + '0 0 1' * 64;
167 e.colormod = v_color;
168 SUB_SetFade(e,time,f_time);
171 void paint_target2(entity onwho, float f_size, vector v_color, float f_time)
176 setmodel(e, "models/turrets/c512.md3"); // precision set above
177 e.scale = (f_size/512);
178 setsize(e, '0 0 0', '0 0 0');
180 setorigin(e,onwho.origin + '0 0 1');
182 e.movetype = MOVETYPE_FLY;
184 e.velocity = (v_color * 32); // + '0 0 1' * 64;
185 e.avelocity_x = -128;
187 e.colormod = v_color;
188 SUB_SetFade(e,time,f_time);
191 void paint_target3(vector where, float f_size, vector v_color, float f_time)
195 setmodel(e, "models/turrets/c512.md3"); // precision set above
196 e.scale = (f_size/512);
197 setsize(e, '0 0 0', '0 0 0');
198 setorigin(e,where+ '0 0 1');
199 e.movetype = MOVETYPE_NONE;
200 e.velocity = '0 0 0';
201 e.colormod = v_color;
202 SUB_SetFade(e,time,f_time);
206 * Return the angle between two enteties
208 vector angleofs(entity from, entity to)
212 // makevectors(from.angles);
213 v_res = normalize(to.origin - from.origin);
214 v_res = vectoangles(v_res);
215 v_res = v_res - from.angles;
217 if (v_res_x < 0) v_res_x += 360;
218 if (v_res_x > 180) v_res_x -= 360;
220 if (v_res_y < 0) v_res_y += 360;
221 if (v_res_y > 180) v_res_y -= 360;
226 vector angleofs2(entity from, vector to)
230 // makevectors(from.angles);
231 v_res = normalize(to - from.origin);
232 v_res = vectoangles(v_res);
233 v_res = v_res - from.angles;
235 if (v_res_x < 0) v_res_x += 360;
236 if (v_res_x > 180) v_res_x -= 360;
238 if (v_res_y < 0) v_res_y += 360;
239 if (v_res_y > 180) v_res_y -= 360;
244 vector angleofs3(vector from,vector from_a, entity to)
248 // makevectors(from.angles);
249 v_res = normalize(to.origin - from);
250 v_res = vectoangles(v_res);
251 v_res = v_res - from_a;
253 if (v_res_x < 0) v_res_x += 360;
254 if (v_res_x > 180) v_res_x -= 360;
256 if (v_res_y < 0) v_res_y += 360;
257 if (v_res_y > 180) v_res_y -= 360;
262 float turret_tag_setup()
266 dprint("Call to turret_tag_setup with self.tur_head missing!\n");
267 self.tur_shotorg = '0 0 0';
271 setorigin(self.tur_head,gettaginfo(self,gettagindex(self,"tag_head")));
272 self.tur_shotorg = gettaginfo(self.tur_head,gettagindex(self.tur_head,"tag_fire"));
274 v_forward = normalize(v_forward);
279 float turret_tag_fire_update()
283 dprint("Call to turret_tag_fire_update with self.tur_head missing!\n");
284 self.tur_shotorg = '0 0 0';
288 self.tur_shotorg = gettaginfo(self.tur_head,gettagindex(self.tur_head,"tag_fire"));
289 v_forward = normalize(v_forward);
291 //dprint("update: tur_shotorg: ",vtos(self.tur_shotorg)," origin:", vtos(self.tur_head.origin), " angels: ", vtos(self.tur_head.angles),"\n");
296 void FireImoBeam (vector start,vector end,vector smin,vector smax,
297 float bforce,float f_dmg,float f_velfactor, float deathtype)
300 local vector hitloc, force, endpoint, dir;
303 dir = normalize(end - start);
304 force = dir * bforce;
306 // go a little bit into the wall because we need to hit this wall later
309 // trace multiple times until we hit a wall, each obstacle will be made unsolid.
310 // note down which entities were hit so we can damage them later
313 tracebox(start, smin, smax, end, FALSE, self);
315 // if it is world we can't hurt it so stop now
316 if (trace_ent == world || trace_fraction == 1)
319 if (trace_ent.solid == SOLID_BSP)
322 // make the entity non-solid so we can hit the next one
323 trace_ent.railgunhit = TRUE;
324 trace_ent.railgunhitloc = end;
325 trace_ent.railgunhitsolidbackup = trace_ent.solid;
327 // stop if this is a wall
329 // make the entity non-solid
330 trace_ent.solid = SOLID_NOT;
333 endpoint = trace_endpos;
335 // find all the entities the railgun hit and restore their solid state
336 ent = findfloat(world, railgunhit, TRUE);
339 // restore their solid type
340 ent.solid = ent.railgunhitsolidbackup;
341 ent = findfloat(ent, railgunhit, TRUE);
344 // find all the entities the railgun hit and hurt them
345 ent = findfloat(world, railgunhit, TRUE);
348 // get the details we need to call the damage function
349 hitloc = ent.railgunhitloc;
350 ent.railgunhitloc = '0 0 0';
351 ent.railgunhitsolidbackup = SOLID_NOT;
352 ent.railgunhit = FALSE;
357 Damage (ent, self, self, f_dmg, deathtype, hitloc, force);
358 ent.velocity = ent.velocity * f_velfactor;
359 //ent.alpha = 0.25 + random() * 0.75;
362 // advance to the next entity
363 ent = findfloat(ent, railgunhit, TRUE);
365 trace_endpos = endpoint;
368 void turrets_precache_debug_models()
370 precache_model ("models/turrets/c512.md3");
371 precache_model ("models/pathlib/goodsquare.md3");
372 precache_model ("models/pathlib/badsquare.md3");
373 precache_model ("models/pathlib/square.md3");
374 precache_model ("models/pathlib/edge.md3");
377 void turrets_precash()
379 precache_model ("models/turrets/base-gib1.md3");
380 precache_model ("models/turrets/base-gib2.md3");
381 precache_model ("models/turrets/base-gib3.md3");
382 precache_model ("models/turrets/base-gib4.md3");
384 precache_model ("models/turrets/head-gib1.md3");
385 precache_model ("models/turrets/head-gib2.md3");
386 precache_model ("models/turrets/head-gib3.md3");
387 precache_model ("models/turrets/head-gib4.md3");
388 precache_model ("models/turrets/terrainbase.md3");
390 //precache_model ("models/turrets/base.md3");
391 //precache_model ("models/turrets/flac.md3");
392 //precache_model ("models/turrets/pd_proj.md3");
393 //precache_model ("models/turrets/reactor.md3");
394 //precache_model ("models/turrets/mlrs_rocket.md3");
395 //precache_model ("models/turrets/hellion.md3");
396 //precache_model ("models/turrets/hunter2.md3");
397 //precache_model ("models/turrets/hk.md3");
398 //precache_model ("models/turrets/machinegun.md3");
399 //precache_model ("models/turrets/rocket.md3");
400 //precache_model ("models/turrets/mlrs.md3");
401 //precache_model ("models/turrets/phaser.md3");
402 //precache_model ("models/turrets/phaser_beam.md3");
403 //precache_model ("models/turrets/plasmad.md3");
404 //precache_model ("models/turrets/plasma.md3");
405 //precache_model ("models/turrets/tesla_head.md3");
406 //precache_model ("models/turrets/tesla_base.md3");
407 //turrets_precache_debug_models();