7 void turret_tid2info(float _tid);
8 void turret_precache(float _tid);
9 float turret_is_precache[TID_LAST];
11 void turrets_precache()
13 turret_precache(TID_COMMON);
16 void turret_precache(float _tid)
18 if (!turret_is_precache[TID_COMMON])
20 precache_sound ("weapons/rocket_impact.wav");
21 precache_model ("models/turrets/base-gib1.md3");
22 precache_model ("models/turrets/base-gib2.md3");
23 precache_model ("models/turrets/base-gib3.md3");
24 precache_model ("models/turrets/base-gib4.md3");
25 precache_model ("models/turrets/head-gib1.md3");
26 precache_model ("models/turrets/head-gib2.md3");
27 precache_model ("models/turrets/head-gib3.md3");
28 precache_model ("models/turrets/head-gib4.md3");
29 precache_model ("models/turrets/terrainbase.md3");
30 precache_model ("models/turrets/base.md3");
31 precache_model ("models/turrets/rocket.md3");
33 turret_tid2info(_tid);
34 if(turret_is_precache[_tid])
40 precache_model ("models/turrets/ewheel-base2.md3");
41 precache_model ("models/turrets/ewheel-gun1.md3");
44 precache_model ("models/turrets/flac.md3");
47 precache_model ("models/turrets/reactor.md3");
50 precache_model ("models/turrets/hellion.md3");
53 precache_model ("models/turrets/hk.md3");
56 precache_model ("models/turrets/machinegun.md3");
57 precache_sound ("weapons/uzi_fire.wav");
60 precache_model ("models/turrets/mlrs.md3");
63 precache_model ("models/turrets/phaser.md3");
64 precache_model ("models/turrets/phaser_beam.md3");
65 precache_sound ("turrets/phaser.wav");
68 precache_model ("models/turrets/plasma.md3");
71 precache_model ("models/turrets/plasmad.md3");
74 precache_model ("models/turrets/tesla_head.md3");
75 precache_model ("models/turrets/tesla_base.md3");
78 precache_model ("models/turrets/walker_head_minigun.md3");
79 precache_model ("models/turrets/walker_body.md3");
80 precache_sound ("weapons/uzi_fire.wav");
83 turret_is_precache[_tid] = TRUE;
86 void turret_tid2info(float _tid)
88 tid2info_base = "models/turrets/base.md3";
89 tid2info_min = '-32 -32 0';
90 tid2info_max = '32 32 64';
95 tid2info_base = "models/turrets/ewheel-base2.md3";
96 tid2info_head = "models/turrets/ewheel-gun1.md3";
97 tid2info_name = "eWheel";
100 tid2info_head = "models/turrets/flac.md3";
101 tid2info_name = "Flac Cannon";
104 tid2info_head = "models/turrets/reactor.md3";
105 tid2info_name = "Fusion Reactor";
106 tid2info_min = '-34 -34 0';
107 tid2info_max = '34 34 90';
110 tid2info_head = "models/turrets/hellion.md3";
111 tid2info_name = "Hellion";
114 tid2info_head = "models/turrets/hk.md3";
115 tid2info_name = "Hunter-Killer";
118 tid2info_head = "models/turrets/machinegun.md3";
119 tid2info_name = "Machinegun";
122 tid2info_head = "models/turrets/mlrs.md3";
123 tid2info_name = "MLRS";
126 tid2info_head = "models/turrets/phaser.md3";
127 tid2info_name = "Phaser";
130 tid2info_head = "models/turrets/plasma.md3";
131 tid2info_name = "Plasma";
133 case TID_PLASMA_DUAL:
134 tid2info_head = "models/turrets/plasmad.md3";
135 tid2info_name = "Dual Plasma";
138 tid2info_base = "models/turrets/tesla_base.md3";
139 tid2info_head = "models/turrets/tesla_head.md3";
140 tid2info_name = "Tesla coil";
141 tid2info_min = '-60 -60 0';
142 tid2info_max ='60 60 128';
145 tid2info_base = "models/turrets/walker_body.md3";
146 tid2info_head = "models/turrets/walker_head_minigun.md3";
147 tid2info_name = "Walker";
148 tid2info_min = '-70 -70 0';
149 tid2info_max = '70 70 95';
156 remove(self.tur_head);
157 //remove(self.enemy);
158 self.tur_head = world;
162 void turret_changeteam()
164 switch(self.team - 1)
166 case NUM_TEAM_1: // Red
167 self.glowmod = '2 0 0';
168 self.teamradar_color = '1 0 0';
171 case NUM_TEAM_2: // Blue
172 self.glowmod = '0 0 2';
173 self.teamradar_color = '0 0 1';
176 case NUM_TEAM_3: // Yellow
177 self.glowmod = '1 1 0';
178 self.teamradar_color = '1 1 0';
181 case NUM_TEAM_4: // Pink
182 self.glowmod = '1 0 1';
183 self.teamradar_color = '1 0 1';
188 self.colormap = 1024 + (self.team - 1) * 17;
190 self.tur_head.colormap = self.colormap;
191 self.tur_head.glowmod = self.glowmod;
195 void turret_head_draw()
197 self.drawmask = MASK_NORMAL;
204 dt = time - self.move_time;
205 self.move_time = time;
209 self.tur_head.angles += dt * self.tur_head.move_avelocity;
211 if (self.health < 127)
216 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
221 pointparticles(particleeffectnum("smoke_large"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
225 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
231 if(self.netname == "")
234 if(!autocvar_g_waypointsprite_turrets)
237 if(autocvar_cl_hidewaypoints)
240 float dist = vlen(self.origin - view_origin);
241 float t = (GetPlayerColor(player_localnum) + 1);
246 if(autocvar_cl_vehicles_hud_tactical)
247 if(dist < 10240 && t != self.team)
249 // TODO: Vehicle tactical hud
250 o = project_3d_to_2d(self.origin + '0 0 32');
252 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
253 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
254 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
255 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
256 return; // Dont draw wp's for turrets out of view
258 if(hud != HUD_NORMAL)
260 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
261 txt = "gfx/vehicles/vth-mover.tga";
263 txt = "gfx/vehicles/vth-stationary.tga";
265 vector pz = drawgetimagesize(txt) * 0.25;
266 drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.75, DRAWFLAG_NORMAL);
270 if(dist > self.maxdistance)
273 string spriteimage = self.netname;
274 float a = self.alpha * autocvar_hud_panel_fg_alpha;
275 vector rgb = spritelookupcolor(spriteimage, self.teamradar_color);
278 if(self.maxdistance > waypointsprite_normdistance)
279 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
280 else if(self.maxdistance > 0)
281 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
285 self.teamradar_color = '1 0 1';
286 printf("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage);
290 if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
293 txt = spritelookuptext(spriteimage);
295 if(time - floor(time) > 0.5 && t == self.team)
297 if(self.helpme && time < self.helpme)
299 a *= SPRITE_HELPME_BLINK;
300 txt = sprintf(_("%s under attack!"), txt);
303 a *= spritelookupblinkvalue(spriteimage);
306 if(autocvar_g_waypointsprite_uppercase)
307 txt = strtoupper(txt);
318 rgb = fixrgbexcess(rgb);
320 o = project_3d_to_2d(self.origin + '0 0 64');
322 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
323 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
324 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
325 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
326 return; // Dont draw wp's for turrets out of view
330 float edgedistance_min, crosshairdistance;
331 edgedistance_min = min((o_y - (vid_conheight * waypointsprite_edgeoffset_top)),
332 (o_x - (vid_conwidth * waypointsprite_edgeoffset_left)),
333 (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o_x,
334 (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o_y);
336 float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
338 crosshairdistance = sqrt( pow(o_x - vid_conwidth/2, 2) + pow(o_y - vid_conheight/2, 2) );
340 t = waypointsprite_scale * vidscale;
341 a *= waypointsprite_alpha;
344 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
345 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
347 if (edgedistance_min < waypointsprite_edgefadedistance) {
348 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
349 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
351 if(crosshairdistance < waypointsprite_crosshairfadedistance) {
352 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
353 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
356 o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
357 o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
364 0.5 * SPRITE_HEALTHBAR_WIDTH * t,
365 0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
366 SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
367 SPRITE_HEALTHBAR_BORDER * t,
370 a * SPRITE_HEALTHBAR_BORDERALPHA,
372 a * SPRITE_HEALTHBAR_HEALTHALPHA,
377 void turret_walker_draw()
381 dt = time - self.move_time;
382 self.move_time = time;
386 fixedmakevectors(self.angles);
387 movelib_groundalign4point(300, 100, 0.25, 45);
388 setorigin(self, self.origin + self.velocity * dt);
389 self.tur_head.angles += dt * self.tur_head.move_avelocity;
390 self.angles_y = self.move_angles_y;
392 if (self.health < 127)
394 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
397 void turret_ewheel_draw()
401 dt = time - self.move_time;
402 self.move_time = time;
406 fixedmakevectors(self.angles);
407 setorigin(self, self.origin + self.velocity * dt);
408 self.tur_head.angles += dt * self.tur_head.move_avelocity;
409 self.angles_y = self.move_angles_y;
411 if (self.health < 127)
413 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
416 void(entity e, entity tagentity, string tagname) setattachment = #443;
417 void turret_construct()
419 if(self.tur_head == world)
420 self.tur_head = spawn();
422 turret_tid2info(self.turret_type);
423 self.netname = tid2info_name;
425 setorigin(self, self.origin);
426 setmodel(self, tid2info_base);
427 setmodel(self.tur_head, tid2info_head);
428 setsize(self, tid2info_min, tid2info_max);
429 setsize(self.tur_head, '0 0 0', '0 0 0');
431 if(self.turret_type == TID_EWHEEL)
432 setattachment(self.tur_head, self, "");
434 setattachment(self.tur_head, self, "tag_head");
436 self.tur_head.classname = "turret_head";
437 self.tur_head.owner = self;
438 self.tur_head.move_movetype = MOVETYPE_NOCLIP;
439 self.move_movetype = MOVETYPE_NOCLIP;
440 self.tur_head.angles = self.angles;
442 self.solid = SOLID_BBOX;
443 self.tur_head.solid = SOLID_NOT;
444 self.movetype = MOVETYPE_NOCLIP;
445 self.tur_head.movetype = MOVETYPE_NOCLIP;
446 self.draw = turret_draw;
447 self.entremove = turret_remove;
448 self.drawmask = MASK_NORMAL;
449 self.tur_head.drawmask = MASK_NORMAL;
450 self.anim_start_time = 0;
451 self.draw2d = turret_draw2d;
452 self.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
453 self.teamradar_color = '1 0 0';
456 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
459 self.movetype = MOVETYPE_BOUNCE;
460 self.move_movetype = MOVETYPE_BOUNCE;
461 self.move_origin = self.origin;
462 self.move_time = time;
463 switch(self.turret_type)
466 self.draw = turret_ewheel_draw;
469 self.draw = turret_walker_draw;
476 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
477 void turret_gibboom();
478 void turret_gib_draw()
480 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
482 self.drawmask = MASK_NORMAL;
486 if(time >= self.nextthink)
494 self.alpha = bound(0, self.nextthink - time, 1);
495 if(self.alpha < ALPHA_MIN_VISIBLE)
500 void turret_gibboom()
504 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
505 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
507 for (i = 1; i < 5; i = i + 1)
508 turret_gibtoss(strcat("models/turrets/head-gib", ftos(i), ".md3"), self.origin + '0 0 2', self.velocity + randomvec() * 700, '0 0 0', FALSE);
511 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
515 traceline(_from, _to, MOVE_NOMONSTERS, world);
520 setorigin(gib, _from);
521 setmodel(gib, _model);
522 gib.colormod = _cmod;
523 gib.solid = SOLID_CORPSE;
524 gib.draw = turret_gib_draw;
526 setsize(gib, '-1 -1 -1', '1 1 1');
529 gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
530 gib.effects = EF_FLAME;
533 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
536 gib.move_movetype = MOVETYPE_BOUNCE;
537 gib.move_origin = _from;
538 setorigin(gib, _from);
539 gib.move_velocity = _to;
540 gib.move_avelocity = prandomvec() * 32;
541 gib.move_time = time;
542 gib.damageforcescale = 1;
543 gib.classname = "turret_gib";
551 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
552 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
553 turret_tid2info(self.turret_type);
554 if (!autocvar_cl_nogibs)
557 if(self.turret_type == TID_EWHEEL)
558 turret_gibtoss(tid2info_base, self.origin + '0 0 18', self.velocity + '0 0 400' + '0.1 0.1 1' * (random() * 400), '-1 -1 -1', TRUE);
559 else if (self.turret_type == TID_WALKER)
560 turret_gibtoss(tid2info_base, self.origin + '0 0 18', self.velocity + '0 0 300' + '0.1 0.1 1' * (random() * 200), '-1 -1 -1', TRUE);
561 else if (self.turret_type == TID_TESLA)
562 turret_gibtoss(tid2info_base, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', FALSE);
567 turret_gibtoss("models/turrets/base-gib2.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', FALSE);
568 turret_gibtoss("models/turrets/base-gib3.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', FALSE);
569 turret_gibtoss("models/turrets/base-gib4.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', FALSE);
572 turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 8', '0 0 0', '0 0 0', TRUE);
574 entity headgib = turret_gibtoss(tid2info_head, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', TRUE);
577 headgib.angles = headgib.move_angles = self.tur_head.angles;
578 headgib.avelocity = headgib.move_avelocity = self.tur_head.move_avelocity + randomvec() * 45;
579 headgib.avelocity_y = headgib.move_avelocity_y = headgib.move_avelocity_y * 5;
580 headgib.gravity = 0.5;
585 setmodel(self, "null");
586 setmodel(self.tur_head, "null");
596 self.turret_type = ReadByte();
598 self.origin_x = ReadCoord();
599 self.origin_y = ReadCoord();
600 self.origin_z = ReadCoord();
601 setorigin(self, self.origin);
603 self.angles_x = ReadAngle();
604 self.angles_y = ReadAngle();
606 turret_precache(self.turret_type);
608 self.colormap = 1024;
609 self.glowmod = '0 1 1';
610 self.tur_head.colormap = self.colormap;
611 self.tur_head.glowmod = self.glowmod;
616 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
617 self.tur_head = spawn();
619 self.tur_head.move_angles_x = ReadShort();
620 self.tur_head.move_angles_y = ReadShort();
621 //self.tur_head.angles = self.angles + self.tur_head.move_angles;
622 self.tur_head.angles = self.tur_head.move_angles;
627 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
628 self.tur_head = spawn();
630 self.tur_head.move_avelocity_x = ReadShort();
631 self.tur_head.move_avelocity_y = ReadShort();
636 self.origin_x = ReadShort();
637 self.origin_y = ReadShort();
638 self.origin_z = ReadShort();
639 setorigin(self, self.origin);
641 self.velocity_x = ReadShort();
642 self.velocity_y = ReadShort();
643 self.velocity_z = ReadShort();
645 self.move_angles_y = ReadShort();
647 self.move_time = time;
648 self.move_velocity = self.velocity;
649 self.move_origin = self.origin;
654 self.frame1time = ReadCoord();
655 self.frame = ReadByte();
662 if(_tmp != self.team)
669 if(_tmp == 0 && self.health != 0)
671 else if(self.health && self.health != _tmp)
672 self.helpme = servertime + 10;
676 //self.enemy.health = self.health / 255;