6 #include "movetypes.qh"
8 #include "teamradar.qh"
9 #include "waypointsprites.qh"
11 #include "../common/teams.qh"
13 #include "../server/tturrets/include/turrets_early.qh"
15 #include "../warpzonelib/anglestransform.qh"
16 #include "../warpzonelib/mathlib.qh"
29 void turret_tid2info(float _tid);
30 void turret_precache(float _tid);
31 float turret_is_precache[TID_LAST];
33 void turrets_precache()
35 turret_precache(TID_COMMON);
38 void turret_precache(int _tid)
40 if (!turret_is_precache[TID_COMMON])
42 precache_sound ("weapons/rocket_impact.wav");
43 precache_model ("models/turrets/base-gib1.md3");
44 precache_model ("models/turrets/base-gib2.md3");
45 precache_model ("models/turrets/base-gib3.md3");
46 precache_model ("models/turrets/base-gib4.md3");
47 precache_model ("models/turrets/head-gib1.md3");
48 precache_model ("models/turrets/head-gib2.md3");
49 precache_model ("models/turrets/head-gib3.md3");
50 precache_model ("models/turrets/head-gib4.md3");
51 precache_model ("models/turrets/base.md3");
52 precache_model ("models/turrets/rocket.md3");
54 turret_tid2info(_tid);
55 if(turret_is_precache[_tid])
61 precache_model ("models/turrets/ewheel-base2.md3");
62 precache_model ("models/turrets/ewheel-gun1.md3");
65 precache_model ("models/turrets/flac.md3");
68 precache_model ("models/turrets/reactor.md3");
71 precache_model ("models/turrets/hellion.md3");
74 precache_model ("models/turrets/hk.md3");
77 precache_model ("models/turrets/machinegun.md3");
78 precache_sound ("weapons/uzi_fire.wav");
81 precache_model ("models/turrets/mlrs.md3");
84 precache_model ("models/turrets/phaser.md3");
85 precache_model ("models/turrets/phaser_beam.md3");
86 precache_sound ("turrets/phaser.wav");
89 precache_model ("models/turrets/plasma.md3");
92 precache_model ("models/turrets/plasmad.md3");
95 precache_model ("models/turrets/tesla_head.md3");
96 precache_model ("models/turrets/tesla_base.md3");
99 precache_model ("models/turrets/walker_head_minigun.md3");
100 precache_model ("models/turrets/walker_body.md3");
101 precache_sound ("weapons/uzi_fire.wav");
104 turret_is_precache[_tid] = true;
107 void turret_tid2info(float _tid)
109 tid2info_base = "models/turrets/base.md3";
110 tid2info_min = '-32 -32 0';
111 tid2info_max = '32 32 64';
116 tid2info_base = "models/turrets/ewheel-base2.md3";
117 tid2info_head = "models/turrets/ewheel-gun1.md3";
118 tid2info_name = "eWheel";
121 tid2info_head = "models/turrets/flac.md3";
122 tid2info_name = "Flac Cannon";
125 tid2info_head = "models/turrets/reactor.md3";
126 tid2info_name = "Fusion Reactor";
127 tid2info_min = '-34 -34 0';
128 tid2info_max = '34 34 90';
131 tid2info_head = "models/turrets/hellion.md3";
132 tid2info_name = "Hellion";
135 tid2info_head = "models/turrets/hk.md3";
136 tid2info_name = "Hunter-Killer";
139 tid2info_head = "models/turrets/machinegun.md3";
140 tid2info_name = "Machinegun";
143 tid2info_head = "models/turrets/mlrs.md3";
144 tid2info_name = "MLRS";
147 tid2info_head = "models/turrets/phaser.md3";
148 tid2info_name = "Phaser";
151 tid2info_head = "models/turrets/plasma.md3";
152 tid2info_name = "Plasma";
154 case TID_PLASMA_DUAL:
155 tid2info_head = "models/turrets/plasmad.md3";
156 tid2info_name = "Dual Plasma";
159 tid2info_base = "models/turrets/tesla_base.md3";
160 tid2info_head = "models/turrets/tesla_head.md3";
161 tid2info_name = "Tesla coil";
162 tid2info_min = '-60 -60 0';
163 tid2info_max ='60 60 128';
166 tid2info_base = "models/turrets/walker_body.md3";
167 tid2info_head = "models/turrets/walker_head_minigun.md3";
168 tid2info_name = "Walker";
169 tid2info_min = '-70 -70 0';
170 tid2info_max = '70 70 95';
177 remove(self.tur_head);
178 //remove(self.enemy);
179 self.tur_head = world;
182 class(Turret) .vector glowmod;
183 void turret_changeteam()
185 switch(self.team - 1)
187 case NUM_TEAM_1: // Red
188 self.glowmod = '2 0 0';
189 self.teamradar_color = '1 0 0';
192 case NUM_TEAM_2: // Blue
193 self.glowmod = '0 0 2';
194 self.teamradar_color = '0 0 1';
197 case NUM_TEAM_3: // Yellow
198 self.glowmod = '1 1 0';
199 self.teamradar_color = '1 1 0';
202 case NUM_TEAM_4: // Pink
203 self.glowmod = '1 0 1';
204 self.teamradar_color = '1 0 1';
209 self.colormap = 1024 + (self.team - 1) * 17;
211 self.tur_head.colormap = self.colormap;
212 self.tur_head.glowmod = self.glowmod;
216 void turret_head_draw()
218 self.drawmask = MASK_NORMAL;
225 dt = time - self.move_time;
226 self.move_time = time;
230 self.tur_head.angles += dt * self.tur_head.move_avelocity;
232 if (self.health < 127)
237 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
242 pointparticles(particleeffectnum("smoke_large"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
246 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
252 if(self.netname == "")
255 if(!autocvar_g_waypointsprite_turrets)
258 if(autocvar_cl_hidewaypoints)
261 float dist = vlen(self.origin - view_origin);
262 float t = (GetPlayerColor(player_localnum) + 1);
267 if(autocvar_cl_vehicles_hud_tactical)
268 if(dist < 10240 && t != self.team)
270 // TODO: Vehicle tactical hud
271 o = project_3d_to_2d(self.origin + '0 0 32');
273 || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
274 || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
275 || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
276 || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
277 return; // Dont draw wp's for turrets out of view
279 if(hud != HUD_NORMAL)
287 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
288 txt = "gfx/vehicles/vth-mover.tga";
290 txt = "gfx/vehicles/vth-stationary.tga";
292 vector pz = drawgetimagesize(txt) * 0.25;
293 drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.75, DRAWFLAG_NORMAL);
299 if(dist > self.maxdistance)
302 string spriteimage = self.netname;
303 float a = self.alpha * autocvar_hud_panel_fg_alpha;
304 vector rgb = spritelookupcolor(spriteimage, self.teamradar_color);
307 if(self.maxdistance > waypointsprite_normdistance)
308 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
309 else if(self.maxdistance > 0)
310 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
314 self.teamradar_color = '1 0 1';
315 printf("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage);
319 if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
322 txt = spritelookuptext(spriteimage);
324 if(time - floor(time) > 0.5 && t == self.team)
326 if(self.helpme && time < self.helpme)
328 a *= SPRITE_HELPME_BLINK;
329 txt = sprintf(_("%s under attack!"), txt);
332 a *= spritelookupblinkvalue(spriteimage);
335 if(autocvar_g_waypointsprite_uppercase)
336 txt = strtoupper(txt);
347 rgb = fixrgbexcess(rgb);
349 o = project_3d_to_2d(self.origin + '0 0 64');
351 || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
352 || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
353 || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
354 || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
355 return; // Dont draw wp's for turrets out of view
359 float edgedistance_min, crosshairdistance;
360 edgedistance_min = min((o.y - (vid_conheight * waypointsprite_edgeoffset_top)),
361 (o.x - (vid_conwidth * waypointsprite_edgeoffset_left)),
362 (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o.x,
363 (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o.y);
365 float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
367 crosshairdistance = sqrt( pow(o.x - vid_conwidth/2, 2) + pow(o.y - vid_conheight/2, 2) );
369 t = waypointsprite_scale * vidscale;
370 a *= waypointsprite_alpha;
373 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
374 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
376 if (edgedistance_min < waypointsprite_edgefadedistance) {
377 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
378 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
380 if(crosshairdistance < waypointsprite_crosshairfadedistance) {
381 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
382 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
385 o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
386 o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
393 0.5 * SPRITE_HEALTHBAR_WIDTH * t,
394 0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
395 SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
396 SPRITE_HEALTHBAR_BORDER * t,
399 a * SPRITE_HEALTHBAR_BORDERALPHA,
401 a * SPRITE_HEALTHBAR_HEALTHALPHA,
406 void turret_walker_draw()
410 dt = time - self.move_time;
411 self.move_time = time;
415 fixedmakevectors(self.angles);
416 movelib_groundalign4point(300, 100, 0.25, 45);
417 setorigin(self, self.origin + self.velocity * dt);
418 self.tur_head.angles += dt * self.tur_head.move_avelocity;
419 self.angles_y = self.move_angles.y;
421 if (self.health < 127)
423 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
426 void turret_ewheel_draw()
430 dt = time - self.move_time;
431 self.move_time = time;
435 fixedmakevectors(self.angles);
436 setorigin(self, self.origin + self.velocity * dt);
437 self.tur_head.angles += dt * self.tur_head.move_avelocity;
438 self.angles_y = self.move_angles.y;
440 if (self.health < 127)
442 te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
445 void turret_construct()
447 if(self.tur_head == world)
448 self.tur_head = spawn();
450 turret_tid2info(self.turret_type);
451 self.netname = tid2info_name;
453 setorigin(self, self.origin);
454 setmodel(self, tid2info_base);
455 setmodel(self.tur_head, tid2info_head);
456 setsize(self, tid2info_min, tid2info_max);
457 setsize(self.tur_head, '0 0 0', '0 0 0');
459 if(self.turret_type == TID_EWHEEL)
460 setattachment(self.tur_head, self, "");
462 setattachment(self.tur_head, self, "tag_head");
464 self.tur_head.classname = "turret_head";
465 self.tur_head.owner = self;
466 self.tur_head.move_movetype = MOVETYPE_NOCLIP;
467 self.move_movetype = MOVETYPE_NOCLIP;
468 self.tur_head.angles = self.angles;
470 self.solid = SOLID_BBOX;
471 self.tur_head.solid = SOLID_NOT;
472 self.movetype = MOVETYPE_NOCLIP;
473 self.tur_head.movetype = MOVETYPE_NOCLIP;
474 self.draw = turret_draw;
475 self.entremove = turret_remove;
476 self.drawmask = MASK_NORMAL;
477 self.tur_head.drawmask = MASK_NORMAL;
478 self.anim_start_time = 0;
479 self.draw2d = turret_draw2d;
480 self.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
481 self.teamradar_color = '1 0 0';
484 if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
487 self.movetype = MOVETYPE_BOUNCE;
488 self.move_movetype = MOVETYPE_BOUNCE;
489 self.move_origin = self.origin;
490 self.move_time = time;
491 switch(self.turret_type)
494 self.draw = turret_ewheel_draw;
497 self.draw = turret_walker_draw;
504 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
505 void turret_gibboom();
506 void turret_gib_draw()
508 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
510 self.drawmask = MASK_NORMAL;
514 if(time >= self.nextthink)
522 self.alpha = bound(0, self.nextthink - time, 1);
523 if(self.alpha < ALPHA_MIN_VISIBLE)
528 void turret_gibboom()
532 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
533 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
535 for (i = 1; i < 5; i = i + 1)
536 turret_gibtoss(strcat("models/turrets/head-gib", ftos(i), ".md3"), self.origin + '0 0 2', self.velocity + randomvec() * 700, '0 0 0', false);
539 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
543 traceline(_from, _to, MOVE_NOMONSTERS, world);
548 setorigin(gib, _from);
549 setmodel(gib, _model);
550 gib.colormod = _cmod;
551 gib.solid = SOLID_CORPSE;
552 gib.draw = turret_gib_draw;
554 setsize(gib, '-1 -1 -1', '1 1 1');
557 gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
558 gib.effects = EF_FLAME;
561 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
564 gib.move_movetype = MOVETYPE_BOUNCE;
565 gib.move_origin = _from;
566 setorigin(gib, _from);
567 gib.move_velocity = _to;
568 gib.move_avelocity = prandomvec() * 32;
569 gib.move_time = time;
570 gib.damageforcescale = 1;
571 gib.classname = "turret_gib";
579 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
580 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
581 turret_tid2info(self.turret_type);
582 if (!autocvar_cl_nogibs)
585 if(self.turret_type == TID_EWHEEL)
586 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);
587 else if (self.turret_type == TID_WALKER)
588 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);
589 else if (self.turret_type == TID_TESLA)
590 turret_gibtoss(tid2info_base, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
595 turret_gibtoss("models/turrets/base-gib2.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
596 turret_gibtoss("models/turrets/base-gib3.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
597 turret_gibtoss("models/turrets/base-gib4.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
600 turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 8', '0 0 0', '0 0 0', true);
602 entity headgib = turret_gibtoss(tid2info_head, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
605 headgib.angles = headgib.move_angles = self.tur_head.angles;
606 headgib.avelocity = headgib.move_avelocity = self.tur_head.move_avelocity + randomvec() * 45;
607 headgib.avelocity_y = headgib.move_avelocity_y = headgib.move_avelocity.y * 5;
608 headgib.gravity = 0.5;
613 setmodel(self, "null");
614 setmodel(self.tur_head, "null");
623 self.turret_type = ReadByte();
625 self.origin_x = ReadCoord();
626 self.origin_y = ReadCoord();
627 self.origin_z = ReadCoord();
628 setorigin(self, self.origin);
630 self.angles_x = ReadAngle();
631 self.angles_y = ReadAngle();
633 turret_precache(self.turret_type);
635 self.colormap = 1024;
636 self.glowmod = '0 1 1';
637 self.tur_head.colormap = self.colormap;
638 self.tur_head.glowmod = self.glowmod;
643 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
644 self.tur_head = spawn();
646 self.tur_head.move_angles_x = ReadShort();
647 self.tur_head.move_angles_y = ReadShort();
648 //self.tur_head.angles = self.angles + self.tur_head.move_angles;
649 self.tur_head.angles = self.tur_head.move_angles;
654 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
655 self.tur_head = spawn();
657 self.tur_head.move_avelocity_x = ReadShort();
658 self.tur_head.move_avelocity_y = ReadShort();
663 self.origin_x = ReadShort();
664 self.origin_y = ReadShort();
665 self.origin_z = ReadShort();
666 setorigin(self, self.origin);
668 self.velocity_x = ReadShort();
669 self.velocity_y = ReadShort();
670 self.velocity_z = ReadShort();
672 self.move_angles_y = ReadShort();
674 self.move_time = time;
675 self.move_velocity = self.velocity;
676 self.move_origin = self.origin;
681 self.frame1time = ReadCoord();
682 self.frame = ReadByte();
687 int _tmp = ReadByte();
688 if(_tmp != self.team)
695 if(_tmp == 0 && self.health != 0)
697 else if(self.health && self.health != _tmp)
698 self.helpme = servertime + 10;
702 //self.enemy.health = self.health / 255;