From: MirceaKitsune Date: Fri, 8 Jul 2011 22:50:30 +0000 (+0300) Subject: Attempt to port the shownames feature from Xonotic (floating names above players... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2c56e75249796d328ef73cd48fa3dc827c9ed16c;p=voretournament%2Fvoretournament.git Attempt to port the shownames feature from Xonotic (floating names above players). Might still need tweaks before actually working safely. --- diff --git a/data/defaultVT.cfg b/data/defaultVT.cfg index 53935b2c..1baa4ba7 100644 --- a/data/defaultVT.cfg +++ b/data/defaultVT.cfg @@ -335,6 +335,8 @@ net_connecttimeout 30 sv_jumpstep 1 // step up stairs while jumping, makes it easier to reach ledges set ekg 0 "Throw huge amounts of gibs" +seta sv_shownames_cull_distance 2500 "distance after which to not send origin/health/armor of another player" + cl_movement 1 cl_stairsmoothspeed 200 cl_forwardspeed $sv_maxspeed @@ -1146,6 +1148,21 @@ seta hud_contents_water_color "0.4 0.3 0.3" seta hud_contents_stomach_alpha 0.2 "alpha of the stomach color blend when inside it" seta hud_contents_stomach_color "0.3 0.2 0" +seta hud_shownames 1 "draw names and health/armor of nearby players" +seta hud_shownames_enemies 2 "1 = draw names of enemies you point at (TODO), 2 = draw names of all enemies in view" +seta hud_shownames_status 1 "1 = draw health/armor status of teammates" +seta hud_shownames_statusbar_height 4 "height of status bar" +seta hud_shownames_aspect 8 "aspect ratio of total drawing area per name" +seta hud_shownames_fontsize 12 "font size" +seta hud_shownames_decolorize 1 "1 = decolorize name in team games, 2 = decolorize always" +seta hud_shownames_alpha 0.7 "alpha" +seta hud_shownames_resize 1 "enable resizing of the names, then the size cvars will correspond to the maximum size" +seta hud_shownames_mindistance 1000 "start fading alpha/size at this distance" +seta hud_shownames_maxdistance 2500 "alpha/size is 0 at this distance" +seta hud_shownames_antioverlap 1 "if two tags get too close to each other, fade out the one further away from you" +seta hud_shownames_antioverlap_distance 125 "2d distance to other tag after which to fade out" +seta hud_shownames_offset 52 "offset (along z-axis) tag from player origin by this many units" + sbar_info_pos 50 seta sbar_alpha_bg 0.8 "alpha value of the HUD background" seta sbar_alpha_fg 1 "alpha value of the HUD foreground items" diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index e96c53b5..cea3273d 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -657,17 +657,38 @@ float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary) // -------------------------------------------------------------------------- // BEGIN OPTIONAL CSQC FUNCTIONS +void Ent_RemoveEntCS() +{ + entcs_receiver[self.sv_entnum] = world; +} void Ent_ReadEntCS() { + float sf; InterpolateOrigin_Undo(); self.classname = "entcs_receiver"; - self.sv_entnum = ReadByte() - 1; - self.origin_x = ReadShort(); - self.origin_y = ReadShort(); - self.origin_z = ReadShort(); - self.angles_y = ReadByte() * 360.0 / 256; - self.origin_z = self.angles_x = self.angles_z = 0; + sf = ReadByte(); + + if(sf & 1) + self.sv_entnum = ReadByte(); + if(sf & 2) + { + self.origin_x = ReadShort(); + self.origin_y = ReadShort(); + self.origin_z = ReadShort(); + } + if(sf & 4) + { + self.angles_y = ReadByte() * 360.0 / 256; + self.angles_x = self.angles_z = 0; + } + if(sf & 8) + self.healthvalue = ReadByte() * 10; + if(sf & 16) + self.armorvalue = ReadByte() * 10; + + entcs_receiver[self.sv_entnum] = self; + self.entremove = Ent_RemoveEntCS; InterpolateOrigin_Note(); } diff --git a/data/qcsrc/client/View.qc b/data/qcsrc/client/View.qc index ae594dc8..8a5144fb 100644 --- a/data/qcsrc/client/View.qc +++ b/data/qcsrc/client/View.qc @@ -907,6 +907,7 @@ void CSQC_UpdateView(float w, float h) if(self.draw2d) self.draw2d(); self = e; + Draw_ShowNames_All(); // draw radar if( diff --git a/data/qcsrc/client/main.qh b/data/qcsrc/client/main.qh index a158bf27..eac98e3d 100644 --- a/data/qcsrc/client/main.qh +++ b/data/qcsrc/client/main.qh @@ -177,3 +177,5 @@ float calledhooks; .float ping, ping_packetloss, ping_movementloss; .float plhealth, plpredator; + +entity entcs_receiver[255]; // 255 is the engine limit on maxclients diff --git a/data/qcsrc/client/miscfunctions.qc b/data/qcsrc/client/miscfunctions.qc index 0d72bfec..5e098d9a 100644 --- a/data/qcsrc/client/miscfunctions.qc +++ b/data/qcsrc/client/miscfunctions.qc @@ -390,6 +390,33 @@ string ColorTranslateRGB(string s) return s; } +string Team_ColorCode(float teamid) +{ + if (teamid == COLOR_TEAM1) + return "^1"; + else if (teamid == COLOR_TEAM2) + return "^4"; + else if (teamid == COLOR_TEAM3) + return "^3"; + else if (teamid == COLOR_TEAM4) + return "^6"; + else + return "^7"; +} + +// decolorizes and team colors the player name when needed +string playername(string thename, float teamid) +{ + string t; + if (teamplay) + { + t = Team_ColorCode(teamid); + return strcat(t, strdecolorize(thename)); + } + else + return strdecolorize(thename); +} + float cvar_or(string cv, float v) { string s; @@ -691,3 +718,20 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect R_EndPolygon(); } } + +const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map +vector getplayerorigin(float pl) +{ + string s; + entity e; + + s = getplayerkey(pl, "TEMPHACK_origin"); + if(s != "") + return stov(s); + + e = entcs_receiver[pl]; + if(e) + return e.origin; + + return GETPLAYERORIGIN_ERROR; +} diff --git a/data/qcsrc/client/progs.src b/data/qcsrc/client/progs.src index be856594..a5be8b3c 100644 --- a/data/qcsrc/client/progs.src +++ b/data/qcsrc/client/progs.src @@ -26,6 +26,7 @@ movetypes.qh prandom.qh bgmscript.qh +teamplay.qh main.qh sortlist.qc @@ -50,6 +51,9 @@ wall.qc modeleffects.qc target_music.qc +shownames.qh +shownames.qc + Main.qc View.qc interpolate.qc diff --git a/data/qcsrc/server/ent_cs.qc b/data/qcsrc/server/ent_cs.qc index 6635689e..128b14a1 100644 --- a/data/qcsrc/server/ent_cs.qc +++ b/data/qcsrc/server/ent_cs.qc @@ -31,7 +31,7 @@ float entcs_customize() if(other == o) return FALSE; if(other.classname == "player") - if(o.team != other.team) + if(!teamplay || o.team != other.team) if not (radar_showennemies) return FALSE; return TRUE; @@ -39,29 +39,51 @@ float entcs_customize() float entcs_send(entity to, float sf) { - entity o; - o = self.owner; WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS); - WriteByte(MSG_ENTITY, num_for_edict(o)); - WriteShort(MSG_ENTITY, o.origin_x); - WriteShort(MSG_ENTITY, o.origin_y); - WriteShort(MSG_ENTITY, o.origin_z); - WriteByte(MSG_ENTITY, o.angles_y * 256.0 / 360); + WriteByte(MSG_ENTITY, sf); + if(sf & 1) + WriteByte(MSG_ENTITY, num_for_edict(self.owner)-1); + if(sf & 2) + { + WriteShort(MSG_ENTITY, self.origin_x); + WriteShort(MSG_ENTITY, self.origin_y); + WriteShort(MSG_ENTITY, self.origin_z); + } + if(sf & 4) + WriteByte(MSG_ENTITY, self.angles_y * 256.0 / 360); + if(sf & 8) + WriteByte(MSG_ENTITY, self.health / 10); // FIXME use a better scale? + if(sf & 16) + WriteByte(MSG_ENTITY, self.armorvalue / 10); // FIXME use a better scale? return TRUE; }; void entcs_think() { - self.nextthink = time; + self.nextthink = time + 0.033333333333; // increase this to like 0.15 once the client can do smoothing entity o; o = self.owner; - if(o.origin != self.origin || o.angles != self.angles) + if(o.origin != self.origin) { setorigin(self, o.origin); + self.SendFlags |= 2; + } + if(o.angles_y != self.angles_y) + { self.angles = o.angles; - self.SendFlags |= 1; + self.SendFlags |= 4; + } + if(o.health != self.health) + { + self.health = o.health; + self.SendFlags |= 8; + } + if(o.armorvalue != self.armorvalue) + { + self.armorvalue = o.armorvalue; + self.SendFlags |= 16; } };