3 #include "autocvars.qh"
7 #include "miscfunctions.qh"
9 #include "movetypes.qh"
11 #include "teamradar.qh"
12 #include "waypointsprites.qh"
14 #include "../common/teams.qh"
16 #include "../server/tturrets/include/turrets_early.qh"
18 #include "../warpzonelib/anglestransform.qh"
19 #include "../warpzonelib/mathlib.qh"
32 void turret_tid2info(float _tid);
33 void turret_precache(float _tid);
34 float turret_is_precache[TID_LAST];
36 void turrets_precache()
38 turret_precache(TID_COMMON);
41 void turret_precache(int _tid)
43 if (!turret_is_precache[TID_COMMON])
45 precache_sound ("weapons/rocket_impact.wav");
46 precache_model ("models/turrets/base-gib1.md3");
47 precache_model ("models/turrets/base-gib2.md3");
48 precache_model ("models/turrets/base-gib3.md3");
49 precache_model ("models/turrets/base-gib4.md3");
50 precache_model ("models/turrets/head-gib1.md3");
51 precache_model ("models/turrets/head-gib2.md3");
52 precache_model ("models/turrets/head-gib3.md3");
53 precache_model ("models/turrets/head-gib4.md3");
54 precache_model ("models/turrets/base.md3");
55 precache_model ("models/turrets/rocket.md3");
57 turret_tid2info(_tid);
58 if(turret_is_precache[_tid])
64 precache_model ("models/turrets/ewheel-base2.md3");
65 precache_model ("models/turrets/ewheel-gun1.md3");
68 precache_model ("models/turrets/flac.md3");
71 precache_model ("models/turrets/reactor.md3");
74 precache_model ("models/turrets/hellion.md3");
77 precache_model ("models/turrets/hk.md3");
80 precache_model ("models/turrets/machinegun.md3");
81 precache_sound ("weapons/uzi_fire.wav");
84 precache_model ("models/turrets/mlrs.md3");
87 precache_model ("models/turrets/phaser.md3");
88 precache_model ("models/turrets/phaser_beam.md3");
89 precache_sound ("turrets/phaser.wav");
92 precache_model ("models/turrets/plasma.md3");
95 precache_model ("models/turrets/plasmad.md3");
98 precache_model ("models/turrets/tesla_head.md3");
99 precache_model ("models/turrets/tesla_base.md3");
102 precache_model ("models/turrets/walker_head_minigun.md3");
103 precache_model ("models/turrets/walker_body.md3");
104 precache_sound ("weapons/uzi_fire.wav");
107 turret_is_precache[_tid] = true;
110 void turret_tid2info(float _tid)
112 tid2info_base = "models/turrets/base.md3";
113 tid2info_min = '-32 -32 0';
114 tid2info_max = '32 32 64';
119 tid2info_base = "models/turrets/ewheel-base2.md3";
120 tid2info_head = "models/turrets/ewheel-gun1.md3";
121 tid2info_name = "eWheel";
124 tid2info_head = "models/turrets/flac.md3";
125 tid2info_name = "Flac Cannon";
128 tid2info_head = "models/turrets/reactor.md3";
129 tid2info_name = "Fusion Reactor";
130 tid2info_min = '-34 -34 0';
131 tid2info_max = '34 34 90';
134 tid2info_head = "models/turrets/hellion.md3";
135 tid2info_name = "Hellion";
138 tid2info_head = "models/turrets/hk.md3";
139 tid2info_name = "Hunter-Killer";
142 tid2info_head = "models/turrets/machinegun.md3";
143 tid2info_name = "Machinegun";
146 tid2info_head = "models/turrets/mlrs.md3";
147 tid2info_name = "MLRS";
150 tid2info_head = "models/turrets/phaser.md3";
151 tid2info_name = "Phaser";
154 tid2info_head = "models/turrets/plasma.md3";
155 tid2info_name = "Plasma";
157 case TID_PLASMA_DUAL:
158 tid2info_head = "models/turrets/plasmad.md3";
159 tid2info_name = "Dual Plasma";
162 tid2info_base = "models/turrets/tesla_base.md3";
163 tid2info_head = "models/turrets/tesla_head.md3";
164 tid2info_name = "Tesla coil";
165 tid2info_min = '-60 -60 0';
166 tid2info_max ='60 60 128';
169 tid2info_base = "models/turrets/walker_body.md3";
170 tid2info_head = "models/turrets/walker_head_minigun.md3";
171 tid2info_name = "Walker";
172 tid2info_min = '-70 -70 0';
173 tid2info_max = '70 70 95';
180 remove(self.tur_head);
181 //remove(self.enemy);
182 self.tur_head = world;
185 class(Turret) .vector glowmod;
186 void turret_changeteam()
188 switch(self.team - 1)
190 case NUM_TEAM_1: // Red
191 self.glowmod = '2 0 0';
192 self.teamradar_color = '1 0 0';
195 case NUM_TEAM_2: // Blue
196 self.glowmod = '0 0 2';
197 self.teamradar_color = '0 0 1';
200 case NUM_TEAM_3: // Yellow
201 self.glowmod = '1 1 0';
202 self.teamradar_color = '1 1 0';
205 case NUM_TEAM_4: // Pink
206 self.glowmod = '1 0 1';
207 self.teamradar_color = '1 0 1';
212 self.colormap = 1024 + (self.team - 1) * 17;
214 self.tur_head.colormap = self.colormap;
215 self.tur_head.glowmod = self.glowmod;
219 void turret_head_draw()
221 self.drawmask = MASK_NORMAL;
228 dt = time - self.move_time;
229 self.move_time = time;
233 self.tur_head.angles += dt * self.tur_head.move_avelocity;
235 if (self.health < 127)
240 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
245 pointparticles(particleeffectnum("smoke_large"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
249 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
255 if(self.netname == "")
258 if(!autocvar_g_waypointsprite_turrets)
261 if(autocvar_cl_hidewaypoints)
264 float dist = vlen(self.origin - view_origin);
265 float t = (GetPlayerColor(player_localnum) + 1);
270 if(autocvar_cl_vehicles_hud_tactical)
271 if(dist < 10240 && t != self.team)
273 // TODO: Vehicle tactical hud
274 o = project_3d_to_2d(self.origin + '0 0 32');
276 || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
277 || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
278 || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
279 || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
280 return; // Dont draw wp's for turrets out of view
282 if(hud != HUD_NORMAL)
290 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
291 txt = "gfx/vehicles/vth-mover.tga";
293 txt = "gfx/vehicles/vth-stationary.tga";
295 vector pz = drawgetimagesize(txt) * 0.25;
296 drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.75, DRAWFLAG_NORMAL);
302 if(dist > self.maxdistance)
305 string spriteimage = self.netname;
306 float a = self.alpha * autocvar_hud_panel_fg_alpha;
307 vector rgb = spritelookupcolor(spriteimage, self.teamradar_color);
310 if(self.maxdistance > waypointsprite_normdistance)
311 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
312 else if(self.maxdistance > 0)
313 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
317 self.teamradar_color = '1 0 1';
318 printf("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage);
322 if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
325 txt = spritelookuptext(spriteimage);
327 if(time - floor(time) > 0.5 && t == self.team)
329 if(self.helpme && time < self.helpme)
331 a *= SPRITE_HELPME_BLINK;
332 txt = sprintf(_("%s under attack!"), txt);
335 a *= spritelookupblinkvalue(spriteimage);
338 if(autocvar_g_waypointsprite_uppercase)
339 txt = strtoupper(txt);
350 rgb = fixrgbexcess(rgb);
352 o = project_3d_to_2d(self.origin + '0 0 64');
354 || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
355 || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
356 || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
357 || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
358 return; // Dont draw wp's for turrets out of view
362 float edgedistance_min, crosshairdistance;
363 edgedistance_min = min((o.y - (vid_conheight * waypointsprite_edgeoffset_top)),
364 (o.x - (vid_conwidth * waypointsprite_edgeoffset_left)),
365 (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o.x,
366 (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o.y);
368 float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
370 crosshairdistance = sqrt( pow(o.x - vid_conwidth/2, 2) + pow(o.y - vid_conheight/2, 2) );
372 t = waypointsprite_scale * vidscale;
373 a *= waypointsprite_alpha;
376 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
377 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
379 if (edgedistance_min < waypointsprite_edgefadedistance) {
380 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
381 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
383 if(crosshairdistance < waypointsprite_crosshairfadedistance) {
384 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
385 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
388 o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
389 o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
396 0.5 * SPRITE_HEALTHBAR_WIDTH * t,
397 0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
398 SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
399 SPRITE_HEALTHBAR_BORDER * t,
402 a * SPRITE_HEALTHBAR_BORDERALPHA,
404 a * SPRITE_HEALTHBAR_HEALTHALPHA,
409 void turret_walker_draw()
413 dt = time - self.move_time;
414 self.move_time = time;
418 fixedmakevectors(self.angles);
419 movelib_groundalign4point(300, 100, 0.25, 45);
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_ewheel_draw()
433 dt = time - self.move_time;
434 self.move_time = time;
438 fixedmakevectors(self.angles);
439 setorigin(self, self.origin + self.velocity * dt);
440 self.tur_head.angles += dt * self.tur_head.move_avelocity;
441 self.angles_y = self.move_angles.y;
443 if (self.health < 127)
445 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
448 void turret_construct()
450 if(self.tur_head == world)
451 self.tur_head = spawn();
453 turret_tid2info(self.turret_type);
454 self.netname = tid2info_name;
456 setorigin(self, self.origin);
457 setmodel(self, tid2info_base);
458 setmodel(self.tur_head, tid2info_head);
459 setsize(self, tid2info_min, tid2info_max);
460 setsize(self.tur_head, '0 0 0', '0 0 0');
462 if(self.turret_type == TID_EWHEEL)
463 setattachment(self.tur_head, self, "");
465 setattachment(self.tur_head, self, "tag_head");
467 self.tur_head.classname = "turret_head";
468 self.tur_head.owner = self;
469 self.tur_head.move_movetype = MOVETYPE_NOCLIP;
470 self.move_movetype = MOVETYPE_NOCLIP;
471 self.tur_head.angles = self.angles;
473 self.solid = SOLID_BBOX;
474 self.tur_head.solid = SOLID_NOT;
475 self.movetype = MOVETYPE_NOCLIP;
476 self.tur_head.movetype = MOVETYPE_NOCLIP;
477 self.draw = turret_draw;
478 self.entremove = turret_remove;
479 self.drawmask = MASK_NORMAL;
480 self.tur_head.drawmask = MASK_NORMAL;
481 self.anim_start_time = 0;
482 self.draw2d = turret_draw2d;
483 self.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
484 self.teamradar_color = '1 0 0';
487 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
490 self.movetype = MOVETYPE_BOUNCE;
491 self.move_movetype = MOVETYPE_BOUNCE;
492 self.move_origin = self.origin;
493 self.move_time = time;
494 switch(self.turret_type)
497 self.draw = turret_ewheel_draw;
500 self.draw = turret_walker_draw;
507 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
508 void turret_gibboom();
509 void turret_gib_draw()
511 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
513 self.drawmask = MASK_NORMAL;
517 if(time >= self.nextthink)
525 self.alpha = bound(0, self.nextthink - time, 1);
526 if(self.alpha < ALPHA_MIN_VISIBLE)
531 void turret_gibboom()
535 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
536 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
538 for (i = 1; i < 5; i = i + 1)
539 turret_gibtoss(strcat("models/turrets/head-gib", ftos(i), ".md3"), self.origin + '0 0 2', self.velocity + randomvec() * 700, '0 0 0', false);
542 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
546 traceline(_from, _to, MOVE_NOMONSTERS, world);
551 setorigin(gib, _from);
552 setmodel(gib, _model);
553 gib.colormod = _cmod;
554 gib.solid = SOLID_CORPSE;
555 gib.draw = turret_gib_draw;
557 setsize(gib, '-1 -1 -1', '1 1 1');
560 gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
561 gib.effects = EF_FLAME;
564 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
567 gib.move_movetype = MOVETYPE_BOUNCE;
568 gib.move_origin = _from;
569 setorigin(gib, _from);
570 gib.move_velocity = _to;
571 gib.move_avelocity = prandomvec() * 32;
572 gib.move_time = time;
573 gib.damageforcescale = 1;
574 gib.classname = "turret_gib";
582 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
583 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
584 turret_tid2info(self.turret_type);
585 if (!autocvar_cl_nogibs)
588 if(self.turret_type == TID_EWHEEL)
589 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);
590 else if (self.turret_type == TID_WALKER)
591 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);
592 else if (self.turret_type == TID_TESLA)
593 turret_gibtoss(tid2info_base, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
598 turret_gibtoss("models/turrets/base-gib2.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
599 turret_gibtoss("models/turrets/base-gib3.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
600 turret_gibtoss("models/turrets/base-gib4.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
603 turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 8', '0 0 0', '0 0 0', true);
605 entity headgib = turret_gibtoss(tid2info_head, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
608 headgib.angles = headgib.move_angles = self.tur_head.angles;
609 headgib.avelocity = headgib.move_avelocity = self.tur_head.move_avelocity + randomvec() * 45;
610 headgib.avelocity_y = headgib.move_avelocity_y = headgib.move_avelocity.y * 5;
611 headgib.gravity = 0.5;
616 setmodel(self, "null");
617 setmodel(self.tur_head, "null");
626 self.turret_type = ReadByte();
628 self.origin_x = ReadCoord();
629 self.origin_y = ReadCoord();
630 self.origin_z = ReadCoord();
631 setorigin(self, self.origin);
633 self.angles_x = ReadAngle();
634 self.angles_y = ReadAngle();
636 turret_precache(self.turret_type);
638 self.colormap = 1024;
639 self.glowmod = '0 1 1';
640 self.tur_head.colormap = self.colormap;
641 self.tur_head.glowmod = self.glowmod;
646 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
647 self.tur_head = spawn();
649 self.tur_head.move_angles_x = ReadShort();
650 self.tur_head.move_angles_y = ReadShort();
651 //self.tur_head.angles = self.angles + self.tur_head.move_angles;
652 self.tur_head.angles = self.tur_head.move_angles;
657 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
658 self.tur_head = spawn();
660 self.tur_head.move_avelocity_x = ReadShort();
661 self.tur_head.move_avelocity_y = ReadShort();
666 self.origin_x = ReadShort();
667 self.origin_y = ReadShort();
668 self.origin_z = ReadShort();
669 setorigin(self, self.origin);
671 self.velocity_x = ReadShort();
672 self.velocity_y = ReadShort();
673 self.velocity_z = ReadShort();
675 self.move_angles_y = ReadShort();
677 self.move_time = time;
678 self.move_velocity = self.velocity;
679 self.move_origin = self.origin;
684 self.frame1time = ReadCoord();
685 self.frame = ReadByte();
690 int _tmp = ReadByte();
691 if(_tmp != self.team)
698 if(_tmp == 0 && self.health != 0)
700 else if(self.health && self.health != _tmp)
701 self.helpme = servertime + 10;
705 //self.enemy.health = self.health / 255;