From: Jakob MG Date: Tue, 29 Nov 2011 14:04:38 +0000 (+0100) Subject: Waypointsprites / healthbars for turrets #woxblox# X-Git-Tag: xonotic-v0.6.0~35^2~34 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d93e78bf058a42deec82590d3fba8c1bf92933be;p=xonotic%2Fxonotic-data.pk3dir.git Waypointsprites / healthbars for turrets #woxblox# --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 450808f00..a855c4583 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1288,6 +1288,9 @@ alias "g_waypointsprite_toggle" "toggle cl_hidewaypoints" // key for that? seta cl_hidewaypoints 0 "disable static waypoints, only show team waypoints" +seta g_waypointsprites_turrets 1 "disable turret waypoints" +seta g_waypointsprites_turrets_maxdist 4000 "max distace for turret sprites" + // command extension alias qc_cmd "sv_cmd $*" // menu QC will override this to menu_cmd alias adminmsg "sv_cmd adminmsg $*" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index acdfe6d51..0270b020e 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -151,6 +151,9 @@ float autocvar_g_waypointsprite_normdistance; float autocvar_g_waypointsprite_scale; float autocvar_g_waypointsprite_spam; float autocvar_g_waypointsprite_timealphaexponent; +float autocvar_g_waypointsprites_turrets; +float autocvar_g_waypointsprites_turrets_maxdist; + float autocvar_hud_colorflash_alpha; float autocvar_hud_configure_bg_minalpha; float autocvar_hud_configure_checkcollisions; diff --git a/qcsrc/client/tturrets.qc b/qcsrc/client/tturrets.qc index 8fc65b360..e81a1c398 100644 --- a/qcsrc/client/tturrets.qc +++ b/qcsrc/client/tturrets.qc @@ -154,6 +154,7 @@ void turret_tid2info(float _tid) void turret_remove() { remove(self.tur_head); + //remove(self.enemy); self.tur_head = world; } @@ -164,18 +165,22 @@ void turret_changeteam() { case COLOR_TEAM1: // Red self.glowmod = '2 0 0'; + self.teamradar_color = '1 0 0'; break; case COLOR_TEAM2: // Blue self.glowmod = '0 0 2'; + self.teamradar_color = '0 0 1'; break; case COLOR_TEAM3: // Yellow self.glowmod = '1 1 0'; + self.teamradar_color = '1 1 0'; break; case COLOR_TEAM4: // Pink self.glowmod = '1 0 1'; + self.teamradar_color = '1 0 1'; break; } @@ -218,6 +223,149 @@ void turret_draw() if(self.health < 32) if(dt < 0.015) pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1); + +} + +void turret_draw2d() +{ + if(self.netname == "") + return; + + if(autocvar_cl_hidewaypoints) // also check g_waypointsprites_turrets after next release (needs changed to clients default/config .cfg) + return; + + float dist = vlen(self.origin - view_origin); + vector o; + /* + // TODO: Vehicle tactical hud + o = project_3d_to_2d(self.origin + '0 0 32'); + if(o_z < 0 + || o_x < (vid_conwidth * waypointsprite_edgeoffset_left) + || o_y < (vid_conheight * waypointsprite_edgeoffset_top) + || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) + || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom))) + return; // Dont draw wp's for turrets out of view + o_z = 0; + if(hud != HUD_NORMAL) + { + switch(hud) + { + case HUD_SPIDERBOT: + case HUD_WAKIZASHI: + case HUD_RAPTOR: + vector pz = drawgetimagesize("gfx/vehicles/axh-bracket.tga") * 0.25; + drawpic(o - pz * 0.5 , "gfx/vehicles/axh-bracket.tga", pz , '1 1 1', 0.75, DRAWFLAG_NORMAL); + break; + } + } + */ + + if(dist > self.maxdistance) + return; + + string spriteimage = self.netname; + float t = (GetPlayerColor(player_localentnum - 1) + 1); + float a = self.alpha * autocvar_hud_panel_fg_alpha; + vector rgb = spritelookupcolor(spriteimage, self.teamradar_color); + + + if(self.maxdistance > waypointsprite_normdistance) + a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent); + else if(self.maxdistance > 0) + a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha; + + if(rgb == '0 0 0') + { + self.teamradar_color = '1 0 1'; + print(sprintf("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage)); + } + + string txt = self.netname; + if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam) + txt = _("Spam"); + else + txt = spritelookuptext(spriteimage); + + if(time - floor(time) > 0.5 && t == self.team) + { + if(self.helpme && time < self.helpme) + { + a *= SPRITE_HELPME_BLINK; + txt = sprintf(_("%s under attack!"), txt); + } + else + a *= spritelookupblinkvalue(spriteimage); + } + + if(autocvar_g_waypointsprite_uppercase) + txt = strtoupper(txt); + + if(a > 1) + { + rgb *= a; + a = 1; + } + + if(a <= 0) + return; + + rgb = fixrgbexcess(rgb); + + o = project_3d_to_2d(self.origin + '0 0 64'); + if(o_z < 0 + || o_x < (vid_conwidth * waypointsprite_edgeoffset_left) + || o_y < (vid_conheight * waypointsprite_edgeoffset_top) + || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) + || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom))) + return; // Dont draw wp's for turrets out of view + + o_z = 0; + + float edgedistance_min, crosshairdistance; + edgedistance_min = min4((o_y - (vid_conheight * waypointsprite_edgeoffset_top)), + (o_x - (vid_conwidth * waypointsprite_edgeoffset_left)), + (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o_x, + (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o_y); + + float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height); + + crosshairdistance = sqrt( pow(o_x - vid_conwidth/2, 2) + pow(o_y - vid_conheight/2, 2) ); + + t = waypointsprite_scale * vidscale; + a *= waypointsprite_alpha; + + { + a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1))); + t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1))); + } + if (edgedistance_min < waypointsprite_edgefadedistance) { + a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1))); + t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1))); + } + if(crosshairdistance < waypointsprite_crosshairfadedistance) { + a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1))); + t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1))); + } + + o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t); + o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt); + drawhealthbar( + o, + 0, + self.health / 255, + '0 0 0', + '0 0 0', + 0.5 * SPRITE_HEALTHBAR_WIDTH * t, + 0.5 * SPRITE_HEALTHBAR_HEIGHT * t, + SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize, + SPRITE_HEALTHBAR_BORDER * t, + 0, + rgb, + a * SPRITE_HEALTHBAR_BORDERALPHA, + rgb, + a * SPRITE_HEALTHBAR_HEALTHALPHA, + DRAWFLAG_NORMAL + ); } void turret_walker_draw() @@ -231,12 +379,8 @@ void turret_walker_draw() fixedmakevectors(self.angles); movelib_groundalign4point(300, 100, 0.25); - setorigin(self, self.origin + self.velocity * dt); - setorigin(self.tur_head, gettaginfo(self, gettagindex(self, "tag_head"))); - self.tur_head.angles += dt * self.tur_head.move_avelocity; - self.angles_y = self.move_angles_y; if (self.health < 127) @@ -253,18 +397,9 @@ void turret_ewheel_draw() if(dt <= 0) return; - fixedmakevectors(self.angles); - movelib_groundalign4point(300, 100, 0.25); - + fixedmakevectors(self.angles); setorigin(self, self.origin + self.velocity * dt); - setorigin(self.tur_head, self.origin); - self.tur_head.angles += dt * self.tur_head.move_avelocity; - - // Simulate banking - //self.angles_z -= self.angles_z * dt * 2; - //self.angles_z = bound(-45, self.angles_z + ((self.move_angles_y - self.angles_y * -25) * dt), 45); - self.angles_y = self.move_angles_y; if (self.health < 127) @@ -272,12 +407,14 @@ void turret_ewheel_draw() te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); } +void(entity e, entity tagentity, string tagname) setattachment = #443; void turret_construct() { if(self.tur_head == world) self.tur_head = spawn(); turret_tid2info(self.turret_type); + self.netname = tid2info_name; setorigin(self, self.origin); setmodel(self, tid2info_base); @@ -286,12 +423,10 @@ void turret_construct() setsize(self.tur_head, '0 0 0', '0 0 0'); if(self.turret_type == TID_EWHEEL) - setorigin(self.tur_head, '0 0 0'); - else if (self.turret_type == TID_WALKER) - setorigin(self.tur_head, '0 0 0'); + setattachment(self.tur_head, self, ""); else - setorigin(self.tur_head, gettaginfo(self, gettagindex(self, "tag_head"))); - + setattachment(self.tur_head, self, "tag_head"); + self.tur_head.classname = "turret_head"; self.tur_head.owner = self; self.tur_head.move_movetype = MOVETYPE_NOCLIP; @@ -306,14 +441,19 @@ void turret_construct() self.entremove = turret_remove; self.drawmask = MASK_NORMAL; self.tur_head.drawmask = MASK_NORMAL; - self.anim_start_time = 0; + self.anim_start_time = 0; + self.draw2d = turret_draw2d; + self.maxdistance = 4000; // use g_waypointsprites_turrets_maxdist after next release (needs changed to cleint's default) + self.teamradar_color = '1 0 0'; + self.alpha = 1; + if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER) { self.gravity = 1; self.movetype = MOVETYPE_BOUNCE; self.move_movetype = MOVETYPE_BOUNCE; self.move_origin = self.origin; - self.move_time = time; + self.move_time = time; switch(self.turret_type) { case TID_EWHEEL: @@ -321,6 +461,8 @@ void turret_construct() break; case TID_WALKER: self.draw = turret_walker_draw; + break; + } } } @@ -464,7 +606,8 @@ void ent_turret() { self.tur_head.move_angles_x = ReadShort(); self.tur_head.move_angles_y = ReadShort(); - self.tur_head.angles = self.angles + self.tur_head.move_angles; + //self.tur_head.angles = self.angles + self.tur_head.move_angles; + self.tur_head.angles = self.tur_head.move_angles; } if(sf & TNSF_AVEL) @@ -510,8 +653,10 @@ void ent_turret() _tmp = ReadByte(); if(_tmp == 0 && self.health != 0) turret_die(); + else if(self.health && self.health != _tmp) + self.helpme = servertime + 10; self.health = _tmp; } - + //self.enemy.health = self.health / 255; }