From 0ddd75515ed7081b16aa67c79aca7e2694d2e9fe Mon Sep 17 00:00:00 2001 From: div0 Date: Tue, 23 Jun 2009 20:15:10 +0000 Subject: [PATCH] healthbars for sprites (currently unused) git-svn-id: svn://svn.icculus.org/nexuiz/trunk@7089 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/client/waypointsprites.qc | 54 ++++++++++++++++++++++++++++ data/qcsrc/server/waypointsprites.qc | 27 ++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/data/qcsrc/client/waypointsprites.qc b/data/qcsrc/client/waypointsprites.qc index e3eadcc1d..d0a8f9aeb 100644 --- a/data/qcsrc/client/waypointsprites.qc +++ b/data/qcsrc/client/waypointsprites.qc @@ -17,9 +17,16 @@ float waypointsprite_scale; .float maxdistance; .float hideflags; .float spawntime; +.float health; vector SPRITE_SIZE = '256 32 0'; vector SPRITE_HOTSPOT = '128 32 0'; +float SPRITE_HEALTHBAR_WIDTH = 96; +float SPRITE_HEALTHBAR_HEIGHT = 6; +float SPRITE_HEALTHBAR_MARGIN = 4; +float SPRITE_HEALTHBAR_BORDER = 1; +float SPRITE_HEALTHBAR_BORDERALPHA = 1; +float SPRITE_HEALTHBAR_HEALTHALPHA = 0.5; void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, vector rgb, float a, float f) { @@ -49,6 +56,43 @@ void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, ve R_EndPolygon(); } +void drawquad(vector o, vector ri, vector up, string pic, vector rgb, float a, float f) +{ + R_BeginPolygon(pic, f); + R_PolygonVertex(o, '0 0 0', rgb, a); + R_PolygonVertex(o + ri, '1 0 0', rgb, a); + R_PolygonVertex(o + up + ri, '1 1 0', rgb, a); + R_PolygonVertex(o + up, '0 1 0', rgb, a); + R_EndPolygon(); +} + +void drawhealthbar(vector org, float rot, float h, vector sz, vector hotspot, float width, float height, float margin, float border, vector rgb, float a, vector hrgb, float ha, float f) +{ + vector o, ri, up; + float owidth; // outer width + + hotspot = -1 * hotspot; + + // hotspot-relative coordinates of the healthbar corners + o = hotspot; + ri = '1 0 0'; + up = '0 1 0'; + + rot = -rot; // rotate by the opposite angle, as our coordinate system is reversed + o = rotate(o, rot) + org; + ri = rotate(ri, rot); + up = rotate(up, rot); + + owidth = width + 2 * border; + o = o - up * (margin + border + height) + ri * (sz_x - owidth) * 0.5; + + drawquad(o - up * border, ri * owidth, up * border, "", rgb, a, f); + drawquad(o + up * height, ri * owidth, up * border, "", rgb, a, f); + drawquad(o, ri * border, up * height, "", rgb, a, f); + drawquad(o + ri * (owidth - border), ri * border, up * height, "", rgb, a, f); + drawquad(o + ri * border, ri * width * h, up * height, "", hrgb, ha, f); +} + void Draw_WaypointSprite() { string spriteimage; @@ -191,6 +235,11 @@ void Draw_WaypointSprite() spriteimage = strcat("models/sprites/", spriteimage, "_frame", ftos(mod(floor((max(0, time - self.spawntime)) * 2), t))); drawrotpic(o, rot * 90 * DEG2RAD, spriteimage, SPRITE_SIZE * waypointsprite_scale * vidscale, SPRITE_HOTSPOT * waypointsprite_scale * vidscale, '1 1 1', a, DRAWFLAG_MIPMAP); + + if(self.health >= 0) + { + drawhealthbar(o, rot * 90 * DEG2RAD, self.health, SPRITE_SIZE * waypointsprite_scale * vidscale, SPRITE_HOTSPOT * waypointsprite_scale * vidscale, SPRITE_HEALTHBAR_WIDTH, SPRITE_HEALTHBAR_HEIGHT, SPRITE_HEALTHBAR_MARGIN, SPRITE_HEALTHBAR_BORDER, self.teamradar_color, a * SPRITE_HEALTHBAR_BORDERALPHA, self.teamradar_color, a * SPRITE_HEALTHBAR_HEALTHALPHA, DRAWFLAG_NORMAL); + } } void Ent_RemoveWaypointSprite() @@ -215,6 +264,11 @@ void Ent_WaypointSprite() InterpolateOrigin_Undo(); + if(sendflags & 0x80) + self.health = ReadByte() / 255.0; + else + self.health = -1; + if(sendflags & 64) { // unfortunately, this needs to be exact (for the 3D display) diff --git a/data/qcsrc/server/waypointsprites.qc b/data/qcsrc/server/waypointsprites.qc index af26928a4..1a63ba53b 100644 --- a/data/qcsrc/server/waypointsprites.qc +++ b/data/qcsrc/server/waypointsprites.qc @@ -25,6 +25,24 @@ void WaypointSprite_UpdateSprites(entity e, string m1, string m2, string m3) } } +void WaypointSprite_UpdateHealth(entity e, float f) +{ + if(f != e.health) + { + e.health = f; + e.SendFlags |= 0x80; + } +} + +void WaypointSprite_UpdateMaxHealth(entity e, float f) +{ + if(f != e.max_health) + { + e.max_health = f; + e.SendFlags |= 0x80; + } +} + void WaypointSprite_UpdateOrigin(entity e, vector o) { if(o != e.origin) @@ -175,8 +193,17 @@ float WaypointSprite_Customize() float WaypointSprite_SendEntity(entity to, float sendflags) { WriteByte(MSG_ENTITY, ENT_CLIENT_WAYPOINT); + + sendflags = sendflags & 0x7F; + + if(self.max_health) + sendflags |= 0x80; + WriteByte(MSG_ENTITY, sendflags); + if(self.max_health) + WriteByte(MSG_ENTITY, (self.health / self.max_health) * 255.0); + if(sendflags & 64) { WriteCoord(MSG_ENTITY, self.origin_x); -- 2.39.2