1 #include "cl_turrets.qh"
2 void turret_remove(entity this)
10 void turret_changeteam(entity this)
12 this.glowmod = Team_ColorRGB(this.team - 1) * 2;
13 this.teamradar_color = Team_ColorRGB(this.team - 1);
16 this.colormap = 1024 + (this.team - 1) * 17;
18 this.tur_head.colormap = this.colormap;
19 this.tur_head.glowmod = this.glowmod;
24 void turret_head_draw(entity this)
26 this.drawmask = MASK_NORMAL;
29 void turret_draw(entity this)
33 dt = time - this.move_time;
34 this.move_time = time;
38 this.tur_head.angles += dt * this.tur_head.avelocity;
40 if (this.health < 127)
45 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
50 pointparticles(EFFECT_SMOKE_LARGE, (this.origin + (randomvec() * 80)), '0 0 0', 1);
54 pointparticles(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
58 void turret_draw2d(entity this)
60 if(this.netname == "")
63 if(!autocvar_g_waypointsprite_turrets)
66 if(autocvar_cl_hidewaypoints)
69 float dist = vlen(this.origin - view_origin);
70 float t = (entcs_GetTeam(player_localnum) + 1);
75 if(autocvar_cl_vehicles_hud_tactical)
76 if(dist < 10240 && t != this.team)
78 // TODO: Vehicle tactical hud
79 o = project_3d_to_2d(this.origin + '0 0 32');
81 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
82 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
83 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
84 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
85 return; // Dont draw wp's for turrets out of view
89 if((get_turretinfo(this.m_id)).spawnflags & TUR_FLAG_MOVE)
90 txt = "gfx/vehicles/turret_moving.tga";
92 txt = "gfx/vehicles/turret_stationary.tga";
94 vector pz = drawgetimagesize(txt) * autocvar_cl_vehicles_crosshair_size;
95 drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.7, DRAWFLAG_NORMAL);
99 if(dist > this.maxdistance)
102 string spriteimage = this.netname;
103 float a = this.alpha * autocvar_hud_panel_fg_alpha;
104 vector rgb = spritelookupcolor(this, spriteimage, this.teamradar_color);
107 if(this.maxdistance > waypointsprite_normdistance)
108 a *= pow(bound(0, (this.maxdistance - dist) / (this.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
109 else if(this.maxdistance > 0)
110 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
114 this.teamradar_color = '1 0 1';
115 LOG_INFOF("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage);
119 if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
122 txt = spritelookuptext(this, spriteimage);
124 if(time - floor(time) > 0.5 && t == this.team)
126 if(this.helpme && time < this.helpme)
128 a *= SPRITE_HELPME_BLINK;
129 txt = sprintf(_("%s under attack!"), txt);
132 a *= spritelookupblinkvalue(this, spriteimage);
135 if(autocvar_g_waypointsprite_uppercase)
136 txt = strtoupper(txt);
147 rgb = fixrgbexcess(rgb);
149 o = project_3d_to_2d(this.origin + '0 0 64');
151 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
152 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
153 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
154 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
155 return; // Dont draw wp's for turrets out of view
159 float edgedistance_min, crosshairdistance;
160 edgedistance_min = min((o_y - (vid_conheight * waypointsprite_edgeoffset_top)),
161 (o_x - (vid_conwidth * waypointsprite_edgeoffset_left)),
162 (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o_x,
163 (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o_y);
165 float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
167 crosshairdistance = sqrt( pow(o_x - vid_conwidth/2, 2) + pow(o_y - vid_conheight/2, 2) );
169 t = waypointsprite_scale * vidscale;
170 a *= waypointsprite_alpha;
173 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
174 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
176 if (edgedistance_min < waypointsprite_edgefadedistance) {
177 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
178 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
180 if(crosshairdistance < waypointsprite_crosshairfadedistance) {
181 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
182 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
185 o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
186 o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
193 0.5 * SPRITE_HEALTHBAR_WIDTH * t,
194 0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
195 SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
196 SPRITE_HEALTHBAR_BORDER * t,
199 a * SPRITE_HEALTHBAR_BORDERALPHA,
201 a * SPRITE_HEALTHBAR_HEALTHALPHA,
206 void turret_construct(entity this, bool isnew)
208 entity tur = get_turretinfo(this.m_id);
210 if(this.tur_head == NULL)
211 this.tur_head = spawn();
213 this.netname = tur.turret_name;
215 setorigin(this, this.origin);
216 _setmodel(this, tur.model);
217 _setmodel(this.tur_head, tur.head_model);
218 setsize(this, tur.mins, tur.maxs);
219 setsize(this.tur_head, '0 0 0', '0 0 0');
221 if(this.m_id == TUR_EWHEEL.m_id)
222 setattachment(this.tur_head, this, "");
224 setattachment(this.tur_head, this, "tag_head");
226 this.tur_head.classname = "turret_head";
227 this.tur_head.owner = this;
228 set_movetype(this.tur_head, MOVETYPE_NOCLIP);
229 set_movetype(this, MOVETYPE_NOCLIP);
230 this.tur_head.angles = this.angles;
232 this.solid = SOLID_BBOX;
233 this.tur_head.solid = SOLID_NOT;
234 set_movetype(this, MOVETYPE_NOCLIP);
235 set_movetype(this.tur_head, MOVETYPE_NOCLIP);
236 this.draw = turret_draw;
237 this.entremove = turret_remove;
238 this.drawmask = MASK_NORMAL;
239 this.tur_head.drawmask = MASK_NORMAL;
240 this.anim_start_time = 0;
241 this.draw2d = turret_draw2d;
242 this.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
243 this.teamradar_color = '1 0 0';
248 IL_PUSH(g_drawables, this);
249 IL_PUSH(g_drawables_2d, this);
252 tur.tr_setup(tur, this);
255 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
256 void turret_gibboom(entity this);
257 void turret_gib_draw(entity this)
259 Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
261 this.drawmask = MASK_NORMAL;
265 if(time >= this.nextthink)
267 turret_gibboom(this);
273 this.alpha = bound(0, this.nextthink - time, 1);
274 if(this.alpha < ALPHA_MIN_VISIBLE)
279 void turret_gibboom(entity this)
281 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
282 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
284 for (int j = 1; j < 5; j = j + 1)
285 turret_gibtoss(strcat("models/turrets/head-gib", ftos(j), ".md3"), this.origin + '0 0 2', this.velocity + randomvec() * 700, '0 0 0', false);
288 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
292 traceline(_from, _to, MOVE_NOMONSTERS, NULL);
296 gib = new(turret_gib);
297 setorigin(gib, _from);
298 _setmodel(gib, _model);
299 gib.colormod = _cmod;
300 gib.solid = SOLID_CORPSE;
301 gib.draw = turret_gib_draw;
303 setsize(gib, '-1 -1 -1', '1 1 1');
306 gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
307 gib.effects = EF_FLAME;
310 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
313 set_movetype(gib, MOVETYPE_BOUNCE);
314 setorigin(gib, _from);
316 gib.avelocity = prandomvec() * 32;
317 gib.move_time = time;
318 gib.damageforcescale = 1;
323 void turret_die(entity this)
325 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
326 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
327 if (!autocvar_cl_nogibs)
330 if(this.m_id == TUR_EWHEEL.m_id)
331 turret_gibtoss((get_turretinfo(this.m_id)).model, this.origin + '0 0 18', this.velocity + '0 0 400' + '0.1 0.1 1' * (random() * 400), '-1 -1 -1', true);
332 else if (this.m_id == TUR_WALKER.m_id)
333 turret_gibtoss((get_turretinfo(this.m_id)).model, this.origin + '0 0 18', this.velocity + '0 0 300' + '0.1 0.1 1' * (random() * 200), '-1 -1 -1', true);
334 else if (this.m_id == TUR_TESLA.m_id)
335 turret_gibtoss((get_turretinfo(this.m_id)).model, this.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
340 turret_gibtoss("models/turrets/base-gib2.md3", this.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
341 turret_gibtoss("models/turrets/base-gib3.md3", this.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
342 turret_gibtoss("models/turrets/base-gib4.md3", this.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
345 turret_gibtoss("models/turrets/base-gib1.md3", this.origin + '0 0 8', '0 0 0', '0 0 0', true);
347 entity headgib = turret_gibtoss((get_turretinfo(this.m_id)).head_model, this.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
350 headgib.angles = this.tur_head.angles;
351 headgib.avelocity = this.tur_head.avelocity + randomvec() * 45;
352 headgib.avelocity_y = headgib.avelocity_y * 5;
353 headgib.gravity = 0.5;
358 setmodel(this, MDL_Null);
359 setmodel(this.tur_head, MDL_Null);
362 NET_HANDLE(ENT_CLIENT_TURRET, bool isnew)
369 this.m_id = ReadByte();
371 this.origin_x = ReadCoord();
372 this.origin_y = ReadCoord();
373 this.origin_z = ReadCoord();
374 setorigin(this, this.origin);
376 this.angles_x = ReadAngle();
377 this.angles_y = ReadAngle();
379 turret_construct(this, isnew);
380 this.colormap = 1024;
381 this.glowmod = '0 1 1';
382 this.tur_head.colormap = this.colormap;
383 this.tur_head.glowmod = this.glowmod;
388 if(this.tur_head == NULL) // aparenly this can happpen before TNSF_SETUP. great.
389 this.tur_head = spawn();
391 this.tur_head.angles_x = ReadShort();
392 this.tur_head.angles_y = ReadShort();
393 //this.tur_head.angles = this.angles + this.tur_head.angles;
398 if(this.tur_head == NULL) // aparenly this can happpen before TNSF_SETUP. great.
399 this.tur_head = spawn();
401 this.tur_head.avelocity_x = ReadShort();
402 this.tur_head.avelocity_y = ReadShort();
407 this.origin_x = ReadShort();
408 this.origin_y = ReadShort();
409 this.origin_z = ReadShort();
410 setorigin(this, this.origin);
412 this.velocity_x = ReadShort();
413 this.velocity_y = ReadShort();
414 this.velocity_z = ReadShort();
416 this.angles_y = ReadShort();
418 this.move_time = time;
423 this.frame1time = ReadCoord();
424 this.frame = ReadByte();
431 if(_tmp != this.team)
434 turret_changeteam(this);
438 if(_tmp == 0 && this.health != 0)
440 else if(this.health && this.health != _tmp)
441 this.helpme = servertime + 10;
445 //this.enemy.health = this.health / 255;