about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-11-18 14:24:34 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-11-18 14:24:34 +0000
commitd4d1691fea007b04ad21686e8622efbbe53e9768 (patch)
tree5f7fcde7a4a3ef5efb4c9c09835ba561e6b2337e /src
parentdda8f6b33ee05acdf23883c91a0897a464b84061 (diff)
downloadzcatch-d4d1691fea007b04ad21686e8622efbbe53e9768.tar.gz
zcatch-d4d1691fea007b04ad21686e8622efbbe53e9768.zip
fixed so that the skins are sent over correctly and that team color overrides everything
Diffstat (limited to 'src')
-rw-r--r--src/game/client/cl_skin.cpp47
-rw-r--r--src/game/client/cl_skin.h2
-rw-r--r--src/game/client/game_client.cpp26
-rw-r--r--src/game/client/menu2.cpp50
-rw-r--r--src/game/server/game_server.cpp35
-rw-r--r--src/game/server/srv_common.cpp17
-rw-r--r--src/game/server/srv_common.h6
7 files changed, 98 insertions, 85 deletions
diff --git a/src/game/client/cl_skin.cpp b/src/game/client/cl_skin.cpp
index 6e450b4f..292b0a99 100644
--- a/src/game/client/cl_skin.cpp
+++ b/src/game/client/cl_skin.cpp
@@ -80,3 +80,50 @@ int skin_find(const char *name)
 	return -1;
 }
 
+
+
+
+// these converter functions were nicked from some random internet pages
+static float hue_to_rgb(float v1, float v2, float h)
+{
+   if(h < 0) h += 1;
+   if(h > 1) h -= 1;
+   if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h;
+   if((2 * h) < 1) return v2;
+   if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6;
+   return v1;
+}
+
+vec3 hsl_to_rgb(vec3 in)
+{
+	float v1, v2;
+	vec3 out;
+
+	if(in.s == 0)
+	{
+		out.r = in.l;
+		out.g = in.l;
+		out.b = in.l;
+	}
+	else
+	{
+		if(in.l < 0.5f) 
+			v2 = in.l * (1 + in.s);
+		else           
+			v2 = (in.l+in.s) - (in.s*in.l);
+
+		v1 = 2 * in.l - v2;
+
+		out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f));
+		out.g = hue_to_rgb(v1, v2, in.h);
+		out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f));
+	} 
+
+	return out;
+}
+
+vec4 skin_get_color(int v)
+{
+	vec3 r = hsl_to_rgb(vec3((v>>16)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f));
+	return vec4(r.r, r.g, r.b, 1.0f);
+}
diff --git a/src/game/client/cl_skin.h b/src/game/client/cl_skin.h
index 84dbc5f2..0b5875b3 100644
--- a/src/game/client/cl_skin.h
+++ b/src/game/client/cl_skin.h
@@ -1,3 +1,4 @@
+#include "../vmath.h"
 
 // do this better and nicer
 typedef struct 
@@ -8,6 +9,7 @@ typedef struct
 	const char term[1];
 } skin;
 
+vec4 skin_get_color(int v);
 void skin_init();
 int skin_num();
 const skin *skin_get(int index);
diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp
index 5698fc05..d9c2ba53 100644
--- a/src/game/client/game_client.cpp
+++ b/src/game/client/game_client.cpp
@@ -4,7 +4,6 @@
 #include <string.h>
 
 extern "C" {
-	#include <engine/external/glfw/include/GL/glfw.h> // DEBUG TESTING
 	#include <engine/client/ui.h>
 	#include <engine/config.h>
 };
@@ -26,10 +25,6 @@ enum
 	CHN_WORLD,
 };
 
-// red team color = 54090
-// blue team color = 10998628
-
-
 data_container *data = 0x0;
 
 int gametype = GAMETYPE_DM;
@@ -855,7 +850,9 @@ void send_info(bool start)
 		msg_pack_start(MSG_CHANGEINFO, MSGFLAG_VITAL);
 	msg_pack_string(config.player_name, 64);
 	msg_pack_string(config.player_skin, 64);
+	msg_pack_int(config.player_use_custom_color);
 	msg_pack_int(config.player_color_body);
+	msg_pack_int(config.player_color_feet);
 	msg_pack_end();
 	client_send_msg();
 }
@@ -2640,19 +2637,28 @@ extern "C" void modc_message(int msg)
 		int cid = msg_unpack_int();
 		const char *name = msg_unpack_string();
 		const char *skinname = msg_unpack_string();
-		int color = msg_unpack_int();
-		(void)color;
+		
 		strncpy(client_datas[cid].name, name, 64);
 		strncpy(client_datas[cid].skin_name, skinname, 64);
-		client_datas[cid].skin_info.color_body = vec4(1,1,1,1); //color;
-		client_datas[cid].skin_info.color_feet = vec4(1,1,1,1); //color;
+		
+		int use_custom_color = msg_unpack_int();
+		client_datas[cid].skin_info.color_body = skin_get_color(msg_unpack_int());
+		client_datas[cid].skin_info.color_feet = skin_get_color(msg_unpack_int());
 		client_datas[cid].skin_info.size = 64;
 		
 		// find new skin
 		client_datas[cid].skin_id = skin_find(client_datas[cid].skin_name);
 		if(client_datas[cid].skin_id < 0)
 			client_datas[cid].skin_id = 0;
-		client_datas[cid].skin_info.texture = skin_get(client_datas[cid].skin_id)->org_texture;
+		
+		if(use_custom_color)
+			client_datas[cid].skin_info.texture = skin_get(client_datas[cid].skin_id)->color_texture;
+		else
+		{
+			client_datas[cid].skin_info.texture = skin_get(client_datas[cid].skin_id)->org_texture;
+			client_datas[cid].skin_info.color_body = vec4(1,1,1,1);
+			client_datas[cid].skin_info.color_feet = vec4(1,1,1,1);
+		}
 	}
 	else if(msg == MSG_READY_TO_ENTER)
 	{
diff --git a/src/game/client/menu2.cpp b/src/game/client/menu2.cpp
index f1c0ac72..53d80235 100644
--- a/src/game/client/menu2.cpp
+++ b/src/game/client/menu2.cpp
@@ -1012,52 +1012,6 @@ static void menu2_render_serverbrowser(RECT main_view)
 	}
 }
 
-
-// these converter functions were nicked from some random internet pages
-static float hue_to_rgb(float v1, float v2, float h)
-{
-   if(h < 0) h += 1;
-   if(h > 1) h -= 1;
-   if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h;
-   if((2 * h) < 1) return v2;
-   if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6;
-   return v1;
-}
-
-vec3 hsl_to_rgb(vec3 in)
-{
-	float v1, v2;
-	vec3 out;
-
-	if(in.s == 0)
-	{
-		out.r = in.l;
-		out.g = in.l;
-		out.b = in.l;
-	}
-	else
-	{
-		if(in.l < 0.5f) 
-			v2 = in.l * (1 + in.s);
-		else           
-			v2 = (in.l+in.s) - (in.s*in.l);
-
-		v1 = 2 * in.l - v2;
-
-		out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f));
-		out.g = hue_to_rgb(v1, v2, in.h);
-		out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f));
-	} 
-
-	return out;
-}
-
-static vec4 get_color(int v)
-{
-	vec3 r = hsl_to_rgb(vec3((v>>16)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f));
-	return vec4(r.r, r.g, r.b, 1.0f);
-}
-
 static void menu2_render_settings_player(RECT main_view)
 {
 	RECT button;
@@ -1176,8 +1130,8 @@ static void menu2_render_settings_player(RECT main_view)
 		info.color_feet = vec4(1,1,1,1);
 		if(config.player_use_custom_color)
 		{
-			info.color_body = get_color(config.player_color_body);
-			info.color_feet = get_color(config.player_color_feet);
+			info.color_body = skin_get_color(config.player_color_body);
+			info.color_feet = skin_get_color(config.player_color_feet);
 			info.texture = s->color_texture;
 		}
 			
diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp
index 06dafb72..9a02a95d 100644
--- a/src/game/server/game_server.cpp
+++ b/src/game/server/game_server.cpp
@@ -1520,7 +1520,9 @@ void send_info(int who, int to_who)
 	msg_pack_int(who);
 	msg_pack_string(server_clientname(who), 64);
 	msg_pack_string(players[who].skin_name, 64);
-	msg_pack_int(players[who].skin_color);
+	msg_pack_int(players[who].use_custom_color);
+	msg_pack_int(players[who].color_body);
+	msg_pack_int(players[who].color_feet);
 	msg_pack_end();
 	server_send_msg(to_who);
 }
@@ -1550,34 +1552,13 @@ void mods_connected(int client_id)
 	players[client_id].init();
 	players[client_id].client_id = client_id;
 
-	//dbg_msg("game", "join player='%d:%s'", client_id, server_clientname(client_id));
+	//dbg_msg("game", "connected player='%d:%s'", client_id, server_clientname(client_id));
 
 	// Check which team the player should be on
 	if(gameobj->gametype == GAMETYPE_DM)
 		players[client_id].team = 0;
 	else
 		players[client_id].team = gameobj->getteam(client_id);
-
-	//
-	/*
-	msg_pack_start(MSG_SETINFO, MSGFLAG_VITAL);
-	msg_pack_int(client_id);
-	msg_pack_string(server_clientname(client_id), 64);
-	msg_pack_end();
-	server_send_msg(-1);
-
-	for(int i = 0; i < MAX_CLIENTS; i++)
-	{
-		if(players[client_id].client_id != -1)
-		{
-			msg_pack_start(MSG_SETINFO, MSGFLAG_VITAL);
-			msg_pack_int(i);
-			msg_pack_string(server_clientname(i), 64);
-			msg_pack_end();
-			server_send_msg(client_id);
-		}
-	}*/
-
 }
 
 void mods_client_drop(int client_id)
@@ -1614,7 +1595,9 @@ void mods_message(int msg, int client_id)
 	{
 		const char *name = msg_unpack_string();
 		const char *skin_name = msg_unpack_string();
-		int skin_color = msg_unpack_int();
+		players[client_id].use_custom_color = msg_unpack_int();
+		players[client_id].color_body = msg_unpack_int();
+		players[client_id].color_feet = msg_unpack_int();
 
 		// check for invalid chars
 		const char *p = name;
@@ -1625,7 +1608,6 @@ void mods_message(int msg, int client_id)
 			p++;
 		}
 
-
 		//
 		if(msg == MSG_CHANGEINFO && strcmp(name, server_clientname(client_id)) != 0)
 		{
@@ -1637,7 +1619,8 @@ void mods_message(int msg, int client_id)
 		//send_set_name(client_id, players[client_id].name, name);
 		strncpy(players[client_id].skin_name, skin_name, 64);
 		server_setclientname(client_id, name);
-		players[client_id].skin_color = skin_color;
+		
+		gameobj->on_player_info_change(&players[client_id]);
 		
 		if(msg == MSG_STARTINFO)
 		{
diff --git a/src/game/server/srv_common.cpp b/src/game/server/srv_common.cpp
index 638d31c6..c97433d3 100644
--- a/src/game/server/srv_common.cpp
+++ b/src/game/server/srv_common.cpp
@@ -110,6 +110,23 @@ void gameobject::post_reset()
 	}
 }
 
+
+	
+void gameobject::on_player_info_change(class player *p)
+{
+	const int team_colors[2] = {54090, 10998628};
+	if(is_teamplay)
+	{
+		if(p->team >= 0 || p->team <= 1)
+		{
+			p->use_custom_color = 1;
+			p->color_body = team_colors[p->team];
+			p->color_feet = team_colors[p->team];
+		}
+	}
+}
+
+
 void gameobject::on_player_death(class player *victim, class player *killer, int weapon)
 {
 	// do scoreing
diff --git a/src/game/server/srv_common.h b/src/game/server/srv_common.h
index 4b84b272..a780dd73 100644
--- a/src/game/server/srv_common.h
+++ b/src/game/server/srv_common.h
@@ -138,6 +138,8 @@ public:
 	virtual void on_player_spawn(class player *p) {}
 	virtual void on_player_death(class player *victim, class player *killer, int weapon);
 	
+	virtual void on_player_info_change(class player *p);
+	
 	virtual void snap(int snapping_client);
 	virtual int getteam(int notthisid);
 };
@@ -241,7 +243,9 @@ public:
 	//
 	int client_id;
 	char skin_name[64];
-	int skin_color;
+	int use_custom_color;
+	int color_body;
+	int color_feet;
 
 	// input	
 	player_input previnput;