1 void turret_remove(entity this)
9 void turret_changeteam()
11 self.glowmod = Team_ColorRGB(self.team - 1) * 2;
12 self.teamradar_color = Team_ColorRGB(self.team - 1);
15 self.colormap = 1024 + (self.team - 1) * 17;
17 self.tur_head.colormap = self.colormap;
18 self.tur_head.glowmod = self.glowmod;
22 void turret_head_draw()
24 self.drawmask = MASK_NORMAL;
27 void turret_draw(entity this)
31 dt = time - this.move_time;
32 this.move_time = time;
36 this.tur_head.angles += dt * this.tur_head.move_avelocity;
38 if (this.health < 127)
43 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
48 pointparticles(EFFECT_SMOKE_LARGE, (this.origin + (randomvec() * 80)), '0 0 0', 1);
52 pointparticles(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
56 void turret_draw2d(entity this)
58 if(this.netname == "")
61 if(!autocvar_g_waypointsprite_turrets)
64 if(autocvar_cl_hidewaypoints)
67 float dist = vlen(this.origin - view_origin);
68 float t = (entcs_GetTeam(player_localnum) + 1);
73 if(autocvar_cl_vehicles_hud_tactical)
74 if(dist < 10240 && t != this.team)
76 // TODO: Vehicle tactical hud
77 o = project_3d_to_2d(this.origin + '0 0 32');
79 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
80 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
81 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
82 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
83 return; // Dont draw wp's for turrets out of view
87 if((get_turretinfo(this.m_id)).spawnflags & TUR_FLAG_MOVE)
88 txt = "gfx/vehicles/turret_moving.tga";
90 txt = "gfx/vehicles/turret_stationary.tga";
92 vector pz = drawgetimagesize(txt) * autocvar_cl_vehicles_crosshair_size;
93 drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.7, DRAWFLAG_NORMAL);
97 if(dist > this.maxdistance)
100 string spriteimage = this.netname;
101 float a = this.alpha * autocvar_hud_panel_fg_alpha;
102 vector rgb = spritelookupcolor(this, spriteimage, this.teamradar_color);
105 if(this.maxdistance > waypointsprite_normdistance)
106 a *= pow(bound(0, (this.maxdistance - dist) / (this.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
107 else if(this.maxdistance > 0)
108 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
112 this.teamradar_color = '1 0 1';
113 LOG_INFOF("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage);
117 if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
120 txt = spritelookuptext(spriteimage);
122 if(time - floor(time) > 0.5 && t == this.team)
124 if(this.helpme && time < this.helpme)
126 a *= SPRITE_HELPME_BLINK;
127 txt = sprintf(_("%s under attack!"), txt);
130 a *= spritelookupblinkvalue(spriteimage);
133 if(autocvar_g_waypointsprite_uppercase)
134 txt = strtoupper(txt);
145 rgb = fixrgbexcess(rgb);
147 o = project_3d_to_2d(this.origin + '0 0 64');
149 || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
150 || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
151 || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
152 || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
153 return; // Dont draw wp's for turrets out of view
157 float edgedistance_min, crosshairdistance;
158 edgedistance_min = min((o_y - (vid_conheight * waypointsprite_edgeoffset_top)),
159 (o_x - (vid_conwidth * waypointsprite_edgeoffset_left)),
160 (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o_x,
161 (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o_y);
163 float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
165 crosshairdistance = sqrt( pow(o_x - vid_conwidth/2, 2) + pow(o_y - vid_conheight/2, 2) );
167 t = waypointsprite_scale * vidscale;
168 a *= waypointsprite_alpha;
171 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
172 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
174 if (edgedistance_min < waypointsprite_edgefadedistance) {
175 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
176 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
178 if(crosshairdistance < waypointsprite_crosshairfadedistance) {
179 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
180 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
183 o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
184 o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
191 0.5 * SPRITE_HEALTHBAR_WIDTH * t,
192 0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
193 SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
194 SPRITE_HEALTHBAR_BORDER * t,
197 a * SPRITE_HEALTHBAR_BORDERALPHA,
199 a * SPRITE_HEALTHBAR_HEALTHALPHA,
204 void turret_construct()
206 entity tur = get_turretinfo(self.m_id);
208 if(self.tur_head == world)
209 self.tur_head = spawn();
211 self.netname = tur.turret_name;
213 setorigin(self, self.origin);
214 _setmodel(self, tur.model);
215 _setmodel(self.tur_head, tur.head_model);
216 setsize(self, tur.mins, tur.maxs);
217 setsize(self.tur_head, '0 0 0', '0 0 0');
219 if(self.m_id == TUR_EWHEEL.m_id)
220 setattachment(self.tur_head, self, "");
222 setattachment(self.tur_head, self, "tag_head");
224 self.tur_head.classname = "turret_head";
225 self.tur_head.owner = self;
226 self.tur_head.move_movetype = MOVETYPE_NOCLIP;
227 self.move_movetype = MOVETYPE_NOCLIP;
228 self.tur_head.angles = self.angles;
230 self.solid = SOLID_BBOX;
231 self.tur_head.solid = SOLID_NOT;
232 self.movetype = MOVETYPE_NOCLIP;
233 self.tur_head.movetype = MOVETYPE_NOCLIP;
234 self.draw = turret_draw;
235 self.entremove = turret_remove;
236 self.drawmask = MASK_NORMAL;
237 self.tur_head.drawmask = MASK_NORMAL;
238 self.anim_start_time = 0;
239 self.draw2d = turret_draw2d;
240 self.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
241 self.teamradar_color = '1 0 0';
244 tur.tr_setup(tur, self);
247 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
248 void turret_gibboom(entity this);
249 void turret_gib_draw(entity this)
251 Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
253 this.drawmask = MASK_NORMAL;
257 if(time >= this.nextthink)
259 turret_gibboom(this);
265 this.alpha = bound(0, this.nextthink - time, 1);
266 if(this.alpha < ALPHA_MIN_VISIBLE)
271 void turret_gibboom(entity this)
273 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
274 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
276 for (int j = 1; j < 5; j = j + 1)
277 turret_gibtoss(strcat("models/turrets/head-gib", ftos(j), ".md3"), this.origin + '0 0 2', this.velocity + randomvec() * 700, '0 0 0', false);
280 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
284 traceline(_from, _to, MOVE_NOMONSTERS, world);
288 gib = new(turret_gib);
289 setorigin(gib, _from);
290 _setmodel(gib, _model);
291 gib.colormod = _cmod;
292 gib.solid = SOLID_CORPSE;
293 gib.draw = turret_gib_draw;
295 setsize(gib, '-1 -1 -1', '1 1 1');
298 gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
299 gib.effects = EF_FLAME;
302 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
305 gib.move_movetype = MOVETYPE_BOUNCE;
306 gib.move_origin = _from;
307 setorigin(gib, _from);
308 gib.move_velocity = _to;
309 gib.move_avelocity = prandomvec() * 32;
310 gib.move_time = time;
311 gib.damageforcescale = 1;
318 sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
319 pointparticles(EFFECT_ROCKET_EXPLODE, self.origin, '0 0 0', 1);
320 if (!autocvar_cl_nogibs)
323 if(self.m_id == TUR_EWHEEL.m_id)
324 turret_gibtoss((get_turretinfo(self.m_id)).model, self.origin + '0 0 18', self.velocity + '0 0 400' + '0.1 0.1 1' * (random() * 400), '-1 -1 -1', true);
325 else if (self.m_id == TUR_WALKER.m_id)
326 turret_gibtoss((get_turretinfo(self.m_id)).model, self.origin + '0 0 18', self.velocity + '0 0 300' + '0.1 0.1 1' * (random() * 200), '-1 -1 -1', true);
327 else if (self.m_id == TUR_TESLA.m_id)
328 turret_gibtoss((get_turretinfo(self.m_id)).model, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
333 turret_gibtoss("models/turrets/base-gib2.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
334 turret_gibtoss("models/turrets/base-gib3.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
335 turret_gibtoss("models/turrets/base-gib4.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
338 turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 8', '0 0 0', '0 0 0', true);
340 entity headgib = turret_gibtoss((get_turretinfo(self.m_id)).head_model, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
343 headgib.angles = headgib.move_angles = self.tur_head.angles;
344 headgib.avelocity = headgib.move_avelocity = self.tur_head.move_avelocity + randomvec() * 45;
345 headgib.avelocity_y = headgib.move_avelocity_y = headgib.move_avelocity_y * 5;
346 headgib.gravity = 0.5;
351 setmodel(self, MDL_Null);
352 setmodel(self.tur_head, MDL_Null);
355 NET_HANDLE(ENT_CLIENT_TURRET, bool isnew)
362 self.m_id = ReadByte();
364 self.origin_x = ReadCoord();
365 self.origin_y = ReadCoord();
366 self.origin_z = ReadCoord();
367 setorigin(self, self.origin);
369 self.angles_x = ReadAngle();
370 self.angles_y = ReadAngle();
373 self.colormap = 1024;
374 self.glowmod = '0 1 1';
375 self.tur_head.colormap = self.colormap;
376 self.tur_head.glowmod = self.glowmod;
381 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
382 self.tur_head = spawn();
384 self.tur_head.move_angles_x = ReadShort();
385 self.tur_head.move_angles_y = ReadShort();
386 //self.tur_head.angles = self.angles + self.tur_head.move_angles;
387 self.tur_head.angles = self.tur_head.move_angles;
392 if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
393 self.tur_head = spawn();
395 self.tur_head.move_avelocity_x = ReadShort();
396 self.tur_head.move_avelocity_y = ReadShort();
401 self.origin_x = ReadShort();
402 self.origin_y = ReadShort();
403 self.origin_z = ReadShort();
404 setorigin(self, self.origin);
406 self.velocity_x = ReadShort();
407 self.velocity_y = ReadShort();
408 self.velocity_z = ReadShort();
410 self.move_angles_y = ReadShort();
412 self.move_time = time;
413 self.move_velocity = self.velocity;
414 self.move_origin = self.origin;
419 self.frame1time = ReadCoord();
420 self.frame = ReadByte();
427 if(_tmp != self.team)
434 if(_tmp == 0 && self.health != 0)
436 else if(self.health && self.health != _tmp)
437 self.helpme = servertime + 10;
441 //self.enemy.health = self.health / 255;