2 #include "waypointsprites.qh"
4 #include "../server/movelib.qh"
12 void turret_tid2info(float _tid);
13 void turret_precache(float _tid);
14 float turret_is_precache[TID_LAST];
16 void turrets_precache()
18 turret_precache(TID_COMMON);
21 void turret_precache(int _tid)
23 if (!turret_is_precache[TID_COMMON])
25 precache_sound ("weapons/rocket_impact.wav");
26 precache_model ("models/turrets/base-gib1.md3");
27 precache_model ("models/turrets/base-gib2.md3");
28 precache_model ("models/turrets/base-gib3.md3");
29 precache_model ("models/turrets/base-gib4.md3");
30 precache_model ("models/turrets/head-gib1.md3");
31 precache_model ("models/turrets/head-gib2.md3");
32 precache_model ("models/turrets/head-gib3.md3");
33 precache_model ("models/turrets/head-gib4.md3");
34 precache_model ("models/turrets/terrainbase.md3");
35 precache_model ("models/turrets/base.md3");
36 precache_model ("models/turrets/rocket.md3");
38 turret_tid2info(_tid);
39 if(turret_is_precache[_tid])
45 precache_model ("models/turrets/ewheel-base2.md3");
46 precache_model ("models/turrets/ewheel-gun1.md3");
49 precache_model ("models/turrets/flac.md3");
52 precache_model ("models/turrets/reactor.md3");
55 precache_model ("models/turrets/hellion.md3");
58 precache_model ("models/turrets/hk.md3");
61 precache_model ("models/turrets/machinegun.md3");
62 precache_sound ("weapons/uzi_fire.wav");
65 precache_model ("models/turrets/mlrs.md3");
68 precache_model ("models/turrets/phaser.md3");
69 precache_model ("models/turrets/phaser_beam.md3");
70 precache_sound ("turrets/phaser.wav");
73 precache_model ("models/turrets/plasma.md3");
76 precache_model ("models/turrets/plasmad.md3");
79 precache_model ("models/turrets/tesla_head.md3");
80 precache_model ("models/turrets/tesla_base.md3");
83 precache_model ("models/turrets/walker_head_minigun.md3");
84 precache_model ("models/turrets/walker_body.md3");
85 precache_sound ("weapons/uzi_fire.wav");
88 turret_is_precache[_tid] = true;
91 void turret_tid2info(float _tid)
93 tid2info_base = "models/turrets/base.md3";
94 tid2info_min = '-32 -32 0';
95 tid2info_max = '32 32 64';
100 tid2info_base = "models/turrets/ewheel-base2.md3";
101 tid2info_head = "models/turrets/ewheel-gun1.md3";
102 tid2info_name = "eWheel";
105 tid2info_head = "models/turrets/flac.md3";
106 tid2info_name = "Flac Cannon";
109 tid2info_head = "models/turrets/reactor.md3";
110 tid2info_name = "Fusion Reactor";
111 tid2info_min = '-34 -34 0';
112 tid2info_max = '34 34 90';
115 tid2info_head = "models/turrets/hellion.md3";
116 tid2info_name = "Hellion";
119 tid2info_head = "models/turrets/hk.md3";
120 tid2info_name = "Hunter-Killer";
123 tid2info_head = "models/turrets/machinegun.md3";
124 tid2info_name = "Machinegun";
127 tid2info_head = "models/turrets/mlrs.md3";
128 tid2info_name = "MLRS";
131 tid2info_head = "models/turrets/phaser.md3";
132 tid2info_name = "Phaser";
135 tid2info_head = "models/turrets/plasma.md3";
136 tid2info_name = "Plasma";
138 case TID_PLASMA_DUAL:
139 tid2info_head = "models/turrets/plasmad.md3";
140 tid2info_name = "Dual Plasma";
143 tid2info_base = "models/turrets/tesla_base.md3";
144 tid2info_head = "models/turrets/tesla_head.md3";
145 tid2info_name = "Tesla coil";
146 tid2info_min = '-60 -60 0';
147 tid2info_max ='60 60 128';
150 tid2info_base = "models/turrets/walker_body.md3";
151 tid2info_head = "models/turrets/walker_head_minigun.md3";
152 tid2info_name = "Walker";
153 tid2info_min = '-70 -70 0';
154 tid2info_max = '70 70 95';
161 remove(self.tur_head);
162 //remove(self.enemy);
163 self.tur_head = world;
167 void turret_changeteam()
169 switch(self.team - 1)
171 case NUM_TEAM_1: // Red
172 self.glowmod = '2 0 0';
173 self.teamradar_color = '1 0 0';
176 case NUM_TEAM_2: // Blue
177 self.glowmod = '0 0 2';
178 self.teamradar_color = '0 0 1';
181 case NUM_TEAM_3: // Yellow
182 self.glowmod = '1 1 0';
183 self.teamradar_color = '1 1 0';
186 case NUM_TEAM_4: // Pink
187 self.glowmod = '1 0 1';
188 self.teamradar_color = '1 0 1';
193 self.colormap = 1024 + (self.team - 1) * 17;
195 self.tur_head.colormap = self.colormap;
196 self.tur_head.glowmod = self.glowmod;
200 void turret_head_draw()
202 self.drawmask = MASK_NORMAL;
209 dt = time - self.move_time;
210 self.move_time = time;
214 self.tur_head.angles += dt * self.tur_head.move_avelocity;
216 if (self.health < 127)
221 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
226 pointparticles(particleeffectnum("smoke_large"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
230 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
236 if(self.netname == "")
239 if(!autocvar_g_waypointsprite_turrets)
242 if(autocvar_cl_hidewaypoints)
245 float dist = vlen(self.origin - view_origin);
246 float t = (GetPlayerColor(player_localnum) + 1);
251 if(autocvar_cl_vehicles_hud_tactical)
252 if(dist < 10240 && t != self.team)
254 // TODO: Vehicle tactical hud
255 o = project_3d_to_2d(self.origin + '0 0 32');
257 || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
258 || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
259 || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
260 || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
261 return; // Dont draw wp's for turrets out of view
263 if(hud != HUD_NORMAL)
271 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
272 txt = "gfx/vehicles/vth-mover.tga";
274 txt = "gfx/vehicles/vth-stationary.tga";
276 vector pz = drawgetimagesize(txt) * 0.25;
277 drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.75, DRAWFLAG_NORMAL);
283 if(dist > self.maxdistance)
286 string spriteimage = self.netname;
287 float a = self.alpha * autocvar_hud_panel_fg_alpha;
288 vector rgb = spritelookupcolor(spriteimage, self.teamradar_color);
291 if(self.maxdistance > waypointsprite_normdistance)
292 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
293 else if(self.maxdistance > 0)
294 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
298 self.teamradar_color = '1 0 1';
299 printf("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage);
303 if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
306 txt = spritelookuptext(spriteimage);
308 if(time - floor(time) > 0.5 && t == self.team)
310 if(self.helpme && time < self.helpme)
312 a *= SPRITE_HELPME_BLINK;
313 txt = sprintf(_("%s under attack!"), txt);
316 a *= spritelookupblinkvalue(spriteimage);
319 if(autocvar_g_waypointsprite_uppercase)
320 txt = strtoupper(txt);
331 rgb = fixrgbexcess(rgb);
333 o = project_3d_to_2d(self.origin + '0 0 64');
335 || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
336 || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
337 || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
338 || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
339 return; // Dont draw wp's for turrets out of view
343 float edgedistance_min, crosshairdistance;
344 edgedistance_min = min((o.y - (vid_conheight * waypointsprite_edgeoffset_top)),
345 (o.x - (vid_conwidth * waypointsprite_edgeoffset_left)),
346 (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o.x,
347 (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o.y);
349 float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
351 crosshairdistance = sqrt( pow(o.x - vid_conwidth/2, 2) + pow(o.y - vid_conheight/2, 2) );
353 t = waypointsprite_scale * vidscale;
354 a *= waypointsprite_alpha;
357 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
358 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
360 if (edgedistance_min < waypointsprite_edgefadedistance) {
361 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
362 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
364 if(crosshairdistance < waypointsprite_crosshairfadedistance) {
365 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
366 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
369 o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
370 o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
377 0.5 * SPRITE_HEALTHBAR_WIDTH * t,
378 0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
379 SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
380 SPRITE_HEALTHBAR_BORDER * t,
383 a * SPRITE_HEALTHBAR_BORDERALPHA,
385 a * SPRITE_HEALTHBAR_HEALTHALPHA,
390 void turret_walker_draw()
394 dt = time - self.move_time;
395 self.move_time = time;
399 fixedmakevectors(self.angles);
400 movelib_groundalign4point(300, 100, 0.25, 45);
401 setorigin(self, self.origin + self.velocity * dt);
402 self.tur_head.angles += dt * self.tur_head.move_avelocity;
403 self.angles_y = self.move_angles.y;
405 if (self.health < 127)
407 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
410 void turret_ewheel_draw()
414 dt = time - self.move_time;
415 self.move_time = time;
419 fixedmakevectors(self.angles);
420 setorigin(self, self.origin + self.velocity * dt);
421 self.tur_head.angles += dt * self.tur_head.move_avelocity;
422 self.angles_y = self.move_angles.y;
424 if (self.health < 127)
426 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
429 void turret_construct()
431 if(self.tur_head == world)
432 self.tur_head = spawn();
434 turret_tid2info(self.turret_type);
435 self.netname = tid2info_name;
437 setorigin(self, self.origin);
438 setmodel(self, tid2info_base);
439 setmodel(self.tur_head, tid2info_head);
440 setsize(self, tid2info_min, tid2info_max);
441 setsize(self.tur_head, '0 0 0', '0 0 0');
443 if(self.turret_type == TID_EWHEEL)
444 setattachment(self.tur_head, self, "");
446 setattachment(self.tur_head, self, "tag_head");
448 self.tur_head.classname = "turret_head";
449 self.tur_head.owner = self;
450 self.tur_head.move_movetype = MOVETYPE_NOCLIP;
451 self.move_movetype = MOVETYPE_NOCLIP;
452 self.tur_head.angles = self.angles;
454 self.solid = SOLID_BBOX;
455 self.tur_head.solid = SOLID_NOT;
456 self.movetype = MOVETYPE_NOCLIP;
457 self.tur_head.movetype = MOVETYPE_NOCLIP;
458 self.draw = turret_draw;
459 self.entremove = turret_remove;
460 self.drawmask = MASK_NORMAL;
461 self.tur_head.drawmask = MASK_NORMAL;
462 self.anim_start_time = 0;
463 self.draw2d = turret_draw2d;
464 self.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
465 self.teamradar_color = '1 0 0';
468 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
471 self.movetype = MOVETYPE_BOUNCE;
472 self.move_movetype = MOVETYPE_BOUNCE;
473 self.move_origin = self.origin;
474 self.move_time = time;
475 switch(self.turret_type)
478 self.draw = turret_ewheel_draw;
481 self.draw = turret_walker_draw;
488 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
489 void turret_gibboom();
490 void turret_gib_draw()
492 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
494 self.drawmask = MASK_NORMAL;
498 if(time >= self.nextthink)
506 self.alpha = bound(0, self.nextthink - time, 1);
507 if(self.alpha < ALPHA_MIN_VISIBLE)
512 void turret_gibboom()
516 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
517 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
519 for (i = 1; i < 5; i = i + 1)
520 turret_gibtoss(strcat("models/turrets/head-gib", ftos(i), ".md3"), self.origin + '0 0 2', self.velocity + randomvec() * 700, '0 0 0', false);
523 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
527 traceline(_from, _to, MOVE_NOMONSTERS, world);
532 setorigin(gib, _from);
533 setmodel(gib, _model);
534 gib.colormod = _cmod;
535 gib.solid = SOLID_CORPSE;
536 gib.draw = turret_gib_draw;
538 setsize(gib, '-1 -1 -1', '1 1 1');
541 gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
542 gib.effects = EF_FLAME;
545 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
548 gib.move_movetype = MOVETYPE_BOUNCE;
549 gib.move_origin = _from;
550 setorigin(gib, _from);
551 gib.move_velocity = _to;
552 gib.move_avelocity = prandomvec() * 32;
553 gib.move_time = time;
554 gib.damageforcescale = 1;
555 gib.classname = "turret_gib";
563 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
564 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
565 turret_tid2info(self.turret_type);
566 if (!autocvar_cl_nogibs)
569 if(self.turret_type == TID_EWHEEL)
570 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);
571 else if (self.turret_type == TID_WALKER)
572 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);
573 else if (self.turret_type == TID_TESLA)
574 turret_gibtoss(tid2info_base, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
579 turret_gibtoss("models/turrets/base-gib2.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
580 turret_gibtoss("models/turrets/base-gib3.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
581 turret_gibtoss("models/turrets/base-gib4.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
584 turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 8', '0 0 0', '0 0 0', true);
586 entity headgib = turret_gibtoss(tid2info_head, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
589 headgib.angles = headgib.move_angles = self.tur_head.angles;
590 headgib.avelocity = headgib.move_avelocity = self.tur_head.move_avelocity + randomvec() * 45;
591 headgib.avelocity_y = headgib.move_avelocity_y = headgib.move_avelocity.y * 5;
592 headgib.gravity = 0.5;
597 setmodel(self, "null");
598 setmodel(self.tur_head, "null");
607 self.turret_type = ReadByte();
609 self.origin_x = ReadCoord();
610 self.origin_y = ReadCoord();
611 self.origin_z = ReadCoord();
612 setorigin(self, self.origin);
614 self.angles_x = ReadAngle();
615 self.angles_y = ReadAngle();
617 turret_precache(self.turret_type);
619 self.colormap = 1024;
620 self.glowmod = '0 1 1';
621 self.tur_head.colormap = self.colormap;
622 self.tur_head.glowmod = self.glowmod;
627 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
628 self.tur_head = spawn();
630 self.tur_head.move_angles_x = ReadShort();
631 self.tur_head.move_angles_y = ReadShort();
632 //self.tur_head.angles = self.angles + self.tur_head.move_angles;
633 self.tur_head.angles = self.tur_head.move_angles;
638 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
639 self.tur_head = spawn();
641 self.tur_head.move_avelocity_x = ReadShort();
642 self.tur_head.move_avelocity_y = ReadShort();
647 self.origin_x = ReadShort();
648 self.origin_y = ReadShort();
649 self.origin_z = ReadShort();
650 setorigin(self, self.origin);
652 self.velocity_x = ReadShort();
653 self.velocity_y = ReadShort();
654 self.velocity_z = ReadShort();
656 self.move_angles_y = ReadShort();
658 self.move_time = time;
659 self.move_velocity = self.velocity;
660 self.move_origin = self.origin;
665 self.frame1time = ReadCoord();
666 self.frame = ReadByte();
671 int _tmp = ReadByte();
672 if(_tmp != self.team)
679 if(_tmp == 0 && self.health != 0)
681 else if(self.health && self.health != _tmp)
682 self.helpme = servertime + 10;
686 //self.enemy.health = self.health / 255;