Skip to content

Commit

Permalink
Close #24
Browse files Browse the repository at this point in the history
  • Loading branch information
xtreme8000 committed May 7, 2018
1 parent 1c41016 commit 4fb567c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/common.h
Expand Up @@ -139,8 +139,9 @@ extern unsigned int chat_color[2][10];
extern float chat_timer[2][10];
extern char chat_popup[256];
extern float chat_popup_timer;
extern float chat_popup_duration;
void chat_add(int channel, unsigned int color, const char* msg);
void chat_showpopup(const char* msg);
void chat_showpopup(const char* msg, float duration);

#define SCREEN_NONE 0
#define SCREEN_TEAM_SELECT 1
Expand Down
4 changes: 2 additions & 2 deletions src/hud.c
Expand Up @@ -788,7 +788,7 @@ static void hud_ingame_render(float scalex, float scalef) {
sprintf(play_time,"Playing for %im%is",(int)window_time()/60,(int)window_time()%60);
font_render(settings.window_width-font_length(27.0F*scalef,play_time),settings.window_height,27.0F*scalef,play_time);
}
if(window_time()-chat_popup_timer<0.4F) {
if(window_time()-chat_popup_timer<chat_popup_duration) {
glColor3f(1.0F,0.0F,0.0F);
font_render((settings.window_width-font_length(53.0F*scalef,chat_popup))/2.0F,settings.window_height/2.0F,53.0F*scalef,chat_popup);
}
Expand Down Expand Up @@ -938,7 +938,7 @@ static void hud_ingame_mouseclick(int button, int action, int mods) {
}
if(local_player_ammo==0 && window_time()-players[local_player_id].item_showup>=0.5F) {
sound_create(NULL,SOUND_LOCAL,&sound_empty,0.0F,0.0F,0.0F);
chat_showpopup("RELOAD");
chat_showpopup("RELOAD",0.4F);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.c
Expand Up @@ -42,10 +42,12 @@ void chat_add(int channel, unsigned int color, const char* msg) {
}
char chat_popup[256] = {};
float chat_popup_timer = 0.0F;
float chat_popup_duration = 0.0F;

void chat_showpopup(const char* msg) {
void chat_showpopup(const char* msg, float duration) {
strcpy(chat_popup,msg);
chat_popup_timer = window_time();
chat_popup_duration = duration;
}

void drawScene(float dt) {
Expand Down
27 changes: 25 additions & 2 deletions src/network.c
Expand Up @@ -662,53 +662,76 @@ void read_PacketMoveObject(void* data, int len) {
void read_PacketIntelCapture(void* data, int len) {
struct PacketIntelCapture* p = (struct PacketIntelCapture*)data;
if(gamestate.gamemode_type==GAMEMODE_CTF && p->player_id<PLAYERS_MAX) {
char capture_str[128];
switch(players[p->player_id].team) {
case TEAM_1:
gamestate.gamemode.ctf.team_1_score++;
sprintf(capture_str,"%s has captured the %s Intel",players[p->player_id].name,gamestate.team_2.name);
break;
case TEAM_2:
gamestate.gamemode.ctf.team_2_score++;
sprintf(capture_str,"%s has captured the %s Intel",players[p->player_id].name,gamestate.team_1.name);
break;
}
//TODO: play horn.wav, show win message etc.
sound_create(NULL,SOUND_LOCAL,p->winning?&sound_horn:&sound_pickup,0.0F,0.0F,0.0F);
players[p->player_id].score += 10;
chat_add(0,0x0000FF,capture_str);
if(p->winning) {
switch(players[p->player_id].team) {
case TEAM_1:
sprintf(capture_str,"%s Team Wins!",gamestate.team_1.name);
break;
case TEAM_2:
sprintf(capture_str,"%s Team Wins!",gamestate.team_2.name);
break;
}
chat_showpopup(capture_str,5.0F);
}
}
}

void read_PacketIntelDrop(void* data, int len) {
struct PacketIntelDrop* p = (struct PacketIntelDrop*)data;
if(gamestate.gamemode_type==GAMEMODE_CTF && p->player_id<PLAYERS_MAX) {
char drop_str[128];
switch(players[p->player_id].team) {
case TEAM_1:
gamestate.gamemode.ctf.team_2_intel = 0; //drop opposing team's intel
gamestate.gamemode.ctf.team_2_intel_location.dropped.x = p->x;
gamestate.gamemode.ctf.team_2_intel_location.dropped.y = p->y;
gamestate.gamemode.ctf.team_2_intel_location.dropped.z = p->z;
sprintf(drop_str,"%s has dropped the %s Intel",players[p->player_id].name,gamestate.team_2.name);
break;
case TEAM_2:
gamestate.gamemode.ctf.team_1_intel = 0;
gamestate.gamemode.ctf.team_1_intel_location.dropped.x = p->x;
gamestate.gamemode.ctf.team_1_intel_location.dropped.y = p->y;
gamestate.gamemode.ctf.team_1_intel_location.dropped.z = p->z;
sprintf(drop_str,"%s has dropped the %s Intel",players[p->player_id].name,gamestate.team_1.name);
break;
}
chat_add(0,0x0000FF,drop_str);
}
}

void read_PacketIntelPickup(void* data, int len) {
struct PacketIntelPickup* p = (struct PacketIntelPickup*)data;
if(gamestate.gamemode_type==GAMEMODE_CTF && p->player_id<PLAYERS_MAX) {
char pickup_str[128];
switch(players[p->player_id].team) {
case TEAM_1:
gamestate.gamemode.ctf.team_2_intel = 1; //pickup opposing team's intel
gamestate.gamemode.ctf.team_2_intel_location.held.player_id = p->player_id;
sprintf(pickup_str,"%s has the %s Intel",players[p->player_id].name,gamestate.team_2.name);
break;
case TEAM_2:
gamestate.gamemode.ctf.team_1_intel = 1;
gamestate.gamemode.ctf.team_1_intel_location.held.player_id = p->player_id;
sprintf(pickup_str,"%s has the %s Intel",players[p->player_id].name,gamestate.team_1.name);
break;
}
chat_add(0,0x0000FF,pickup_str);
sound_create(NULL,SOUND_LOCAL,&sound_pickup,0.0F,0.0F,0.0F);
}
}

Expand Down Expand Up @@ -897,7 +920,7 @@ int network_update() {
break;
}
case ENET_EVENT_TYPE_DISCONNECT:
chat_showpopup("DISCONNECTED");
chat_showpopup("DISCONNECTED",10.0F);
printf("server disconnected!\n");
event.peer->data = NULL;
network_connected = 0;
Expand Down

0 comments on commit 4fb567c

Please sign in to comment.