Skip to content

Commit

Permalink
HUD: Show flag carrier in hud_teaminfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Svensson authored and dsvensson committed Aug 28, 2022
1 parent 6676071 commit f9e2b5a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions fragstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ cvar_t cl_useimagesinfraglog = {"cl_useimagesinfraglog", "0"};
#define FUH_FRAGFILE_VERSION_1_00 "1.00" /* for compatibility with fuh */
#define FRAGFILE_VERSION_1_00 "ezquake-1.00" /* fuh suggest such format */

void Update_FlagStatus(int player_num, char *team, qbool got_flag);

typedef enum msgtype_s {
mt_fragged,
mt_frags,
Expand Down Expand Up @@ -686,6 +688,7 @@ static void Stats_ParsePrintLine(const char *s, cfrags_format *cff, int offset)
case mt_flagtouch:
{
fragstats[i].touches++;
Update_FlagStatus(i, player1->team, true);
if (cl.playernum == i || (i == Cam_TrackNum() && cl.spectator))
VX_TrackerFlagTouch(fragstats[i].touches);
flag_touched = true;
Expand All @@ -694,6 +697,7 @@ static void Stats_ParsePrintLine(const char *s, cfrags_format *cff, int offset)
case mt_flagdrop:
{
fragstats[i].fumbles++;
Update_FlagStatus(i, player1->team, false);
if (cl.playernum == i || (i == Cam_TrackNum() && cl.spectator))
VX_TrackerFlagDrop(fragstats[i].fumbles);
flag_dropped = true;
Expand All @@ -702,6 +706,7 @@ static void Stats_ParsePrintLine(const char *s, cfrags_format *cff, int offset)
case mt_flagcap:
{
fragstats[i].captures++;
Update_FlagStatus(i, player1->team, false);
if (cl.playernum == i || (i == Cam_TrackNum() && cl.spectator))
VX_TrackerFlagCapture(fragstats[i].captures);
flag_captured = true;
Expand Down
38 changes: 36 additions & 2 deletions hud_teaminfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,17 @@ static int SCR_HudDrawTeamInfoPlayer(ti_player_t *ti_cl, float x, int y, int max
x += (Player_GetTrackId(cl.players[ti_cl->client].userid) >= 10 ? 2 : 1) * font_width;
break;

case 'c':
if (!width_only) {
if (ti_cl->items & IT_KEY1) {
Draw_SString(x, y, "&cf00R", scale, proportional);
} else if (ti_cl->items & IT_KEY2) {
Draw_SString(x, y, "&c00fB", scale, proportional);
}
}
x += font_width;
break;

case '%': // wow, %% result in one %, how smart
if (!width_only) {
Draw_SString(x, y, "%", scale, proportional);
Expand Down Expand Up @@ -607,6 +618,13 @@ void SCR_Draw_TeamInfo(void)
}
}

#define FLAGS_RUNES_MASK (IT_SIGIL1 | IT_SIGIL2 | IT_SIGIL3 | IT_SIGIL4 | IT_KEY1 | IT_KEY2)

static inline int Filter_FlagsAndRunes(int client, int stats)
{
return (ti_clients[client].items & FLAGS_RUNES_MASK) | (stats & ~FLAGS_RUNES_MASK);
}

void Parse_TeamInfo(char *s)
{
int client;
Expand All @@ -629,10 +647,26 @@ void Parse_TeamInfo(char *s)
ti_clients[client].org[2] = atoi(Cmd_Argv(4));
ti_clients[client].health = atoi(Cmd_Argv(5));
ti_clients[client].armor = atoi(Cmd_Argv(6));
ti_clients[client].items = atoi(Cmd_Argv(7));
ti_clients[client].items = Filter_FlagsAndRunes(client, atoi(Cmd_Argv(7)));
strlcpy(ti_clients[client].nick, Cmd_Argv(8), TEAMINFO_NICKLEN); // nick is optional
}

void Update_FlagStatus(int player_num, char *team, qbool got_flag)
{
int flag = IT_KEY1 | IT_KEY2;
if (!strcmp(team, "blue")) {
flag = IT_KEY1;
} else if (!strcmp(team, "red")) {
flag = IT_KEY2;
}

if (got_flag) {
ti_clients[player_num].items |= flag;
} else {
ti_clients[player_num].items &= ~flag;
}
}

static void Update_TeamInfo(void)
{
int i;
Expand Down Expand Up @@ -664,7 +698,7 @@ static void Update_TeamInfo(void)

ti_clients[i].health = bound(0, st[STAT_HEALTH], 999);
ti_clients[i].armor = bound(0, st[STAT_ARMOR], 999);
ti_clients[i].items = st[STAT_ITEMS];
ti_clients[i].items = Filter_FlagsAndRunes(i, st[STAT_ITEMS]);
ti_clients[i].nick[0] = 0; // sad, we don't have nick, will use name
}
}
Expand Down

0 comments on commit f9e2b5a

Please sign in to comment.