[nexuiz-commits] r7089 - in trunk/data/qcsrc: client server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Jun 23 16:15:10 EDT 2009


Author: div0
Date: 2009-06-23 16:15:10 -0400 (Tue, 23 Jun 2009)
New Revision: 7089

Modified:
   trunk/data/qcsrc/client/waypointsprites.qc
   trunk/data/qcsrc/server/waypointsprites.qc
Log:
healthbars for sprites (currently unused)


Modified: trunk/data/qcsrc/client/waypointsprites.qc
===================================================================
--- trunk/data/qcsrc/client/waypointsprites.qc	2009-06-23 19:42:20 UTC (rev 7088)
+++ trunk/data/qcsrc/client/waypointsprites.qc	2009-06-23 20:15:10 UTC (rev 7089)
@@ -17,9 +17,16 @@
 .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 @@
 	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 @@
 		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 @@
 
 	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)

Modified: trunk/data/qcsrc/server/waypointsprites.qc
===================================================================
--- trunk/data/qcsrc/server/waypointsprites.qc	2009-06-23 19:42:20 UTC (rev 7088)
+++ trunk/data/qcsrc/server/waypointsprites.qc	2009-06-23 20:15:10 UTC (rev 7089)
@@ -25,6 +25,24 @@
 	}
 }
 
+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_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);



More information about the nexuiz-commits mailing list