1 #include "cl_turrets.qh"
3 void turret_remove(entity this)
11 void turret_changeteam(entity this)
13 this.glowmod = Team_ColorRGB(this.team - 1) * 2;
14 this.teamradar_color = Team_ColorRGB(this.team - 1);
17 this.colormap = 1024 + (this.team - 1) * 17;
19 this.tur_head.colormap = this.colormap;
20 this.tur_head.glowmod = this.glowmod;
25 void turret_head_draw(entity this)
27 this.drawmask = MASK_NORMAL;
30 void turret_draw(entity this)
34 dt = time - this.move_time;
35 this.move_time = time;
39 this.tur_head.angles += dt * this.tur_head.avelocity;
41 if (GetResource(this, RES_HEALTH) < 127)
46 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
49 if(GetResource(this, RES_HEALTH) < 85)
51 pointparticles(EFFECT_SMOKE_LARGE, (this.origin + (randomvec() * 80)), '0 0 0', 1);
53 if(GetResource(this, RES_HEALTH) < 32)
55 pointparticles(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
59 void turret_draw2d(entity this)
61 if(this.netname == "")
64 if(!autocvar_g_waypointsprite_turrets)
67 if(autocvar_cl_hidewaypoints)
70 float dist = vlen(this.origin - view_origin);
71 float t = (entcs_GetTeam(player_localnum) + 1);
76 if(autocvar_cl_vehicles_hud_tactical)
77 if(dist < 10240 && t != this.team)
79 // TODO: Vehicle tactical hud
80 o = project_3d_to_2d(this.origin + '0 0 32');
82 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
83 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
84 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
85 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
86 return; // Dont draw wp's for turrets out of view
90 if((get_turretinfo(this.m_id)).spawnflags & TUR_FLAG_MOVE)
91 txt = "gfx/vehicles/turret_moving";
93 txt = "gfx/vehicles/turret_stationary";
95 vector pz = drawgetimagesize(txt) * autocvar_cl_vehicles_crosshair_size;
96 drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.7, DRAWFLAG_NORMAL);
100 if(dist > this.maxdistance)
103 string spriteimage = this.netname;
104 float a = this.alpha * autocvar_hud_panel_fg_alpha;
105 vector rgb = spritelookupcolor(this, spriteimage, this.teamradar_color);
108 if(this.maxdistance > waypointsprite_normdistance)
109 a *= (bound(0, (this.maxdistance - dist) / (this.maxdistance - waypointsprite_normdistance), 1) ** waypointsprite_distancealphaexponent);
110 else if(this.maxdistance > 0)
111 a *= (bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1) ** waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
115 this.teamradar_color = '1 0 1';
116 LOG_INFOF("WARNING: sprite of name %s has no color, using pink so you notice it", spriteimage);
119 txt = spritelookuptext(this, spriteimage);
121 if(time - floor(time) > 0.5 && t == this.team)
123 if(this.helpme && time < this.helpme)
125 a *= SPRITE_HELPME_BLINK;
126 txt = sprintf(_("%s under attack!"), txt);
129 a *= spritelookupblinkvalue(this, spriteimage);
132 if(autocvar_g_waypointsprite_uppercase)
133 txt = strtoupper(txt);
144 rgb = fixrgbexcess(rgb);
146 o = project_3d_to_2d(this.origin + '0 0 64');
148 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
149 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
150 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
151 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
152 return; // Dont draw wp's for turrets out of view
156 float edgedistance_min = min((o.y - (vid_conheight * waypointsprite_edgeoffset_top)),
157 (o_x - (vid_conwidth * waypointsprite_edgeoffset_left)),
158 (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o_x,
159 (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o_y);
161 float crosshairdistance = sqrt( ((o.x - vid_conwidth/2) ** 2) + ((o.y - vid_conheight/2) ** 2) );
163 t = waypointsprite_scale;
164 a *= waypointsprite_alpha;
167 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
168 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
170 if (edgedistance_min < waypointsprite_edgefadedistance) {
171 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
172 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
174 if(crosshairdistance < waypointsprite_crosshairfadedistance) {
175 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
176 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
179 bool draw_healthbar = ((this.helpme && time < this.helpme) || !autocvar_g_waypointsprite_turrets_onlyhurt || hud != HUD_NORMAL);
180 bool draw_text = autocvar_g_waypointsprite_turrets_text;
182 if(draw_healthbar || draw_text) // make sure it's actually being drawn
184 o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
188 o = drawsprite_TextOrIcon(true, o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
195 GetResource(this, RES_HEALTH) / 255,
198 0.5 * SPRITE_HEALTHBAR_WIDTH * t,
199 0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
200 SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
201 SPRITE_HEALTHBAR_BORDER * t,
204 a * SPRITE_HEALTHBAR_BORDERALPHA,
206 a * SPRITE_HEALTHBAR_HEALTHALPHA,
212 void turret_construct(entity this, bool isnew)
214 entity tur = get_turretinfo(this.m_id);
216 if(this.tur_head == NULL)
217 this.tur_head = spawn();
219 this.netname = tur.turret_name;
221 setorigin(this, this.origin);
222 _setmodel(this, tur.model);
223 _setmodel(this.tur_head, tur.head_model);
224 setsize(this, tur.m_mins, tur.m_maxs);
225 setsize(this.tur_head, '0 0 0', '0 0 0');
227 if(this.m_id == TUR_EWHEEL.m_id)
228 setattachment(this.tur_head, this, "");
230 setattachment(this.tur_head, this, "tag_head");
232 this.tur_head.classname = "turret_head";
233 this.tur_head.owner = this;
234 set_movetype(this.tur_head, MOVETYPE_NOCLIP);
235 set_movetype(this, MOVETYPE_NOCLIP);
236 this.tur_head.angles = this.angles;
237 SetResourceExplicit(this, RES_HEALTH, 255);
238 this.solid = SOLID_BBOX;
239 this.tur_head.solid = SOLID_NOT;
240 set_movetype(this, MOVETYPE_NOCLIP);
241 set_movetype(this.tur_head, MOVETYPE_NOCLIP);
242 this.draw = turret_draw;
243 this.entremove = turret_remove;
244 this.drawmask = MASK_NORMAL;
245 this.tur_head.drawmask = MASK_NORMAL;
246 this.anim_start_time = 0;
247 this.draw2d = turret_draw2d;
248 this.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
249 this.teamradar_color = '1 0 0';
254 IL_PUSH(g_drawables, this);
255 IL_PUSH(g_drawables_2d, this);
258 tur.tr_setup(tur, this);
261 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
262 void turret_gibboom(entity this);
263 void turret_gib_draw(entity this)
265 Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
267 this.drawmask = MASK_NORMAL;
271 if(time >= this.nextthink)
273 turret_gibboom(this);
279 this.alpha = bound(0, this.nextthink - time, 1);
280 if(this.alpha < ALPHA_MIN_VISIBLE)
285 void turret_gibboom(entity this)
287 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
288 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
290 for (int j = 1; j < 5; j = j + 1)
291 turret_gibtoss(strcat("models/turrets/head-gib", ftos(j), ".md3"), this.origin + '0 0 2', this.velocity + randomvec() * 700, '0 0 0', false);
294 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
298 traceline(_from, _to, MOVE_NOMONSTERS, NULL);
302 gib = new(turret_gib);
303 setorigin(gib, _from);
304 _setmodel(gib, _model);
305 gib.colormod = _cmod;
306 gib.solid = SOLID_CORPSE;
307 gib.draw = turret_gib_draw;
309 setsize(gib, '-1 -1 -1', '1 1 1');
312 gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
313 gib.effects = EF_FLAME;
316 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
319 set_movetype(gib, MOVETYPE_BOUNCE);
320 setorigin(gib, _from);
322 gib.avelocity = prandomvec() * 32;
323 gib.move_time = time;
324 gib.damageforcescale = 1;
329 void turret_die(entity this)
331 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
332 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
333 if (!autocvar_cl_nogibs)
336 if(this.m_id == TUR_EWHEEL.m_id)
337 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);
338 else if (this.m_id == TUR_WALKER.m_id)
339 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);
340 else if (this.m_id == TUR_TESLA.m_id)
341 turret_gibtoss((get_turretinfo(this.m_id)).model, this.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
346 turret_gibtoss("models/turrets/base-gib2.md3", this.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
347 turret_gibtoss("models/turrets/base-gib3.md3", this.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
348 turret_gibtoss("models/turrets/base-gib4.md3", this.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
351 turret_gibtoss("models/turrets/base-gib1.md3", this.origin + '0 0 8', '0 0 0', '0 0 0', true);
353 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);
356 headgib.angles = this.tur_head.angles;
357 headgib.avelocity = this.tur_head.avelocity + randomvec() * 45;
358 headgib.avelocity_y = headgib.avelocity_y * 5;
359 headgib.gravity = 0.5;
364 setmodel(this, MDL_Null);
365 setmodel(this.tur_head, MDL_Null);
368 NET_HANDLE(ENT_CLIENT_TURRET, bool isnew)
375 this.m_id = ReadByte();
377 this.origin = ReadVector();
378 setorigin(this, this.origin);
380 this.angles = ReadAngleVector2D();
382 turret_construct(this, isnew);
383 this.colormap = 1024;
384 this.glowmod = '0 1 1';
385 this.tur_head.colormap = this.colormap;
386 this.tur_head.glowmod = this.glowmod;
391 if(this.tur_head == NULL) // aparenly this can happpen before TNSF_SETUP. great.
392 this.tur_head = spawn();
394 this.tur_head.angles_x = ReadShort();
395 this.tur_head.angles_y = ReadShort();
396 //this.tur_head.angles = this.angles + this.tur_head.angles;
401 if(this.tur_head == NULL) // aparenly this can happpen before TNSF_SETUP. great.
402 this.tur_head = spawn();
404 this.tur_head.avelocity_x = ReadShort();
405 this.tur_head.avelocity_y = ReadShort();
410 this.origin = ReadVector();
411 setorigin(this, this.origin);
413 this.velocity = ReadVector();
415 this.angles_y = ReadShort();
417 this.move_time = time;
422 this.frame1time = ReadCoord();
423 this.frame = ReadByte();
430 if(_tmp != this.team)
433 turret_changeteam(this);
437 float myhp = GetResource(this, RES_HEALTH);
438 if(_tmp == 0 && myhp != 0)
440 else if(myhp && myhp > _tmp)
441 this.helpme = servertime + 10;
442 else if(myhp && myhp < _tmp)
443 this.helpme = 0; // we're being healed, don't spam help me waypoints
445 SetResourceExplicit(this, RES_HEALTH, _tmp);