cleaned up the kill messages

This commit is contained in:
Magnus Auvinen 2007-07-30 07:05:34 +00:00
parent 8780c2fd9b
commit 57da0cae4f
2 changed files with 31 additions and 46 deletions

View file

@ -391,6 +391,7 @@ static const int chat_max_lines = 10;
struct chatline struct chatline
{ {
int tick; int tick;
int client_id;
char text[512+64]; char text[512+64];
}; };
@ -408,14 +409,11 @@ void chat_add_line(int client_id, const char *line)
{ {
chat_current_line = (chat_current_line+1)%chat_max_lines; chat_current_line = (chat_current_line+1)%chat_max_lines;
chat_lines[chat_current_line].tick = client_tick(); chat_lines[chat_current_line].tick = client_tick();
sprintf(chat_lines[chat_current_line].text, "%s: %s", client_datas[client_id].name, line); // TODO: abit nasty chat_lines[chat_current_line].client_id = client_id;
} if(client_id == -1) // server message
sprintf(chat_lines[chat_current_line].text, "*** %s", line);
void status_add_line(const char *line) else
{ sprintf(chat_lines[chat_current_line].text, "%s: %s", client_datas[client_id].name, line); // TODO: abit nasty
chat_current_line = (chat_current_line+1)%chat_max_lines;
chat_lines[chat_current_line].tick = client_tick();
strcpy(chat_lines[chat_current_line].text, line);
} }
struct killmsg struct killmsg
@ -1354,8 +1352,12 @@ void modc_render()
// pseudo format // pseudo format
float zoom = 3.0f; float zoom = 3.0f;
if(!chat_active && inp_key_pressed('I'))
zoom = 1.0f; if(config.debug)
{
if(!chat_active && inp_key_pressed(input::f8))
zoom = 1.0f;
}
float width = 400*zoom; float width = 400*zoom;
float height = 300*zoom; float height = 300*zoom;
@ -1589,7 +1591,7 @@ void modc_render()
int r = ((chat_current_line-i)+chat_max_lines)%chat_max_lines; int r = ((chat_current_line-i)+chat_max_lines)%chat_max_lines;
if(client_tick() > chat_lines[r].tick+50*15) if(client_tick() > chat_lines[r].tick+50*15)
break; break;
gfx_pretty_text(x, y, 10, chat_lines[r].text); gfx_pretty_text(x, y, 10, chat_lines[r].text);
y -= 8; y -= 8;
} }
@ -1815,18 +1817,4 @@ void modc_message(int msg)
killmsgs[killmsg_current].weapon = msg_unpack_int(); killmsgs[killmsg_current].weapon = msg_unpack_int();
killmsgs[killmsg_current].tick = client_tick(); killmsgs[killmsg_current].tick = client_tick();
} }
else if(msg == MSG_JOIN)
{
int cid = msg_unpack_int();
char message[256];
sprintf(message, "%s joined the game", client_datas[cid].name);
status_add_line(message);
}
else if(msg == MSG_QUIT)
{
int cid = msg_unpack_int();
char message[256];
sprintf(message, "%s quit the game", client_datas[cid].name);
status_add_line(message);
}
} }

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <engine/config.h> #include <engine/config.h>
#include "../game.h" #include "../game.h"
@ -1714,6 +1715,15 @@ void mods_client_input(int client_id, void *input)
} }
} }
void send_chat_all(int cid, const char *msg)
{
msg_pack_start(MSG_CHAT, MSGFLAG_VITAL);
msg_pack_int(cid);
msg_pack_string(msg, 512);
msg_pack_end();
server_send_msg(-1);
}
void mods_client_enter(int client_id) void mods_client_enter(int client_id)
{ {
players[client_id].init(); players[client_id].init();
@ -1754,12 +1764,17 @@ void mods_client_enter(int client_id)
} }
} }
mods_message(MSG_JOIN, client_id); char buf[512];
sprintf(buf, "%s has joined the game", players[client_id].name);
send_chat_all(-1, buf);
} }
void mods_client_drop(int client_id) void mods_client_drop(int client_id)
{ {
mods_message(MSG_QUIT, client_id); char buf[512];
sprintf(buf, "%s has left the game", players[client_id].name);
send_chat_all(-1, buf);
dbg_msg("mods", "client drop %d", client_id); dbg_msg("mods", "client drop %d", client_id);
world.remove_entity(&players[client_id]); world.remove_entity(&players[client_id]);
players[client_id].client_id = -1; players[client_id].client_id = -1;
@ -1769,11 +1784,7 @@ void mods_message(int msg, int client_id)
{ {
if(msg == MSG_SAY) if(msg == MSG_SAY)
{ {
msg_pack_start(MSG_CHAT, MSGFLAG_VITAL); send_chat_all(client_id, msg_unpack_string());
msg_pack_int(client_id);
msg_pack_string(msg_unpack_string(), 512);
msg_pack_end();
server_send_msg(-1);
} }
else if (msg == MSG_SWITCHTEAM) else if (msg == MSG_SWITCHTEAM)
{ {
@ -1782,20 +1793,6 @@ void mods_message(int msg, int client_id)
players[client_id].die(client_id, -1); players[client_id].die(client_id, -1);
players[client_id].score--; players[client_id].score--;
} }
else if (msg == MSG_JOIN)
{
msg_pack_start(MSG_JOIN, MSGFLAG_VITAL);
msg_pack_int(client_id);
msg_pack_end();
server_send_msg(-1);
}
else if (msg == MSG_QUIT)
{
msg_pack_start(MSG_QUIT, MSGFLAG_VITAL);
msg_pack_int(client_id);
msg_pack_end();
server_send_msg(-1);
}
} }
extern unsigned char internal_data[]; extern unsigned char internal_data[];