From 501af1652a5d6f71d6b4d36f36f22dfaf700f4a8 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 4 Dec 2011 15:42:03 +0100 Subject: [PATCH] audit usage of player_localentnum and spectatee_status to also work with FTEQW --- qcsrc/client/Defs.qc | 2 +- qcsrc/client/Main.qc | 11 +- qcsrc/client/View.qc | 3 + qcsrc/client/ctf.qc | 219 -------------------------------- qcsrc/client/hud.qc | 18 ++- qcsrc/client/main.qh | 8 -- qcsrc/client/progs.src | 2 - qcsrc/client/scoreboard.qc | 8 +- qcsrc/client/shownames.qc | 4 + qcsrc/client/tturrets.qc | 2 +- qcsrc/client/waypointsprites.qc | 2 +- 11 files changed, 38 insertions(+), 241 deletions(-) delete mode 100644 qcsrc/client/ctf.qc diff --git a/qcsrc/client/Defs.qc b/qcsrc/client/Defs.qc index a1a32404d..901380c1b 100644 --- a/qcsrc/client/Defs.qc +++ b/qcsrc/client/Defs.qc @@ -28,7 +28,7 @@ entity world; float time; float frametime; -float player_localentnum; //the entnum +float player_localentnum; //the entnum of the VIEW entity float player_localnum; //the playernum float maxclients; //a constant filled in by the engine. gah, portability eh? diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index 90f1fcb33..2252f6f61 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -67,6 +67,11 @@ void CSQC_Init(void) float i; +#ifdef COMPAT_XON050_ENGINE + // old engine lacks implementation of player_localnum + player_localnum = player_localentnum - 1; +#endif + binddb = db_create(); tempdb = db_create(); ClientProgsDB = db_load("client.db"); @@ -806,7 +811,7 @@ void Ent_ClientData() if(f & 2) { newspectatee_status = ReadByte(); - if(newspectatee_status == player_localentnum) + if(newspectatee_status == player_localnum + 1) newspectatee_status = -1; // observing } else @@ -840,6 +845,8 @@ void Ent_ClientData() prev_health = -1; } spectatee_status = newspectatee_status; + + // non-COMPAT_XON050_ENGINE: we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum } void Ent_Nagger() @@ -1286,7 +1293,7 @@ void Net_ReadRace() strunzone(grecordholder[pos-1]); grecordholder[pos-1] = strzone(ReadString()); grecordtime[pos-1] = ReadInt24_t(); - if(grecordholder[pos-1] == GetPlayerName(player_localentnum -1)) + if(grecordholder[pos-1] == GetPlayerName(player_localnum)) race_myrank = pos; break; case RACE_NET_SERVER_STATUS: diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index ca9841b53..d9f6df7ee 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -371,6 +371,7 @@ void CSQC_UpdateView(float w, float h) vector v; vector vf_size, vf_min; float a; + hud = getstati(STAT_HUD); if(checkextension("DP_CSQC_MINFPS_QUALITY")) @@ -407,9 +408,11 @@ void CSQC_UpdateView(float w, float h) WaypointSprite_Load(); +#ifdef COMPAT_XON050_ENGINE if(spectatee_status) myteam = GetPlayerColor(spectatee_status - 1); else +#endif myteam = GetPlayerColor(player_localentnum - 1); ticrate = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE); diff --git a/qcsrc/client/ctf.qc b/qcsrc/client/ctf.qc deleted file mode 100644 index 5bf6639b5..000000000 --- a/qcsrc/client/ctf.qc +++ /dev/null @@ -1,219 +0,0 @@ -#ifdef CTF_EXAMPLE - -// NOTE: This file contains lots of debugging stuff -// it is not really used... can be seen as another sample... - -string STR_PLAYER = "player"; -#define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; ) - -string ctf_temp_1; -float order_page; - -void menu_close() -{ - menu_visible = false; - menu_show = menu_show_error; - menu_action = menu_sub_null; - - /*if(ctf_temp_1) - strunzone(ctf_temp_1);*/ - - localcmd("\nin_bindmap 0 0;"); -} - -void order_menu_render() -{ - vector ps, po; - float i, p, n; - string frags, color; - ps = '0 200 0'; - po = '0 8 0'; - - color = getplayerkeyvalue(player_localentnum-1, "topcolor"); - - if(getstati(STAT_CTF_STATE) == CTF_STATE_COMMANDER) { - drawstring(ps, _("----- Order Menu -----"), '8 8 0', '1 1 0', 1, 0); ps += po; - drawstring(ps, sprintf(_("Order: %s"), ctf_temp_1), '8 8 0', '1 1 0', 1, 0); ps += po; - drawcolorcodedstring(ps, _("1) ^3previous page"), '8 8 0', 1, 0); ps += po; - drawcolorcodedstring(ps, _("2) ^3next page"), '8 8 0', 1, 0); ps += po; - for((n = 2), (p = i = 0); i < maxclients && n > 0; ++i) { - frags = getplayerkeyvalue(i, "frags"); - if(!frags || (i+1) == player_localentnum) - continue; - if(frags == "-666" || getplayerkeyvalue(i, "topcolor") != color) // FIXME use GetPlayerTeam - continue; - ++p; - if(p > (8*order_page)) - { - // only render current page - ++n; - if(n == 10) - n = 0; - drawcolorcodedstring(ps, strcat(ftos(n), ") ", GetPlayerName(i), " : ", ftos(getstatf(STAT_CTF_STATE))), '8 8 0', 1, 0); ps += po; - } - } - drawstring(ps, _("ESC) Exit Menu"), '8 8 0', '1 1 0', 1, 0); ps += po; - } else { - menu_close(); - } -} - -float order_menu_action(float bInputType, float nPrimary, float nSecondary) -{ - string arg; - float p, i, n, chose; - string frags, color; - if(bInputType != 0) // key down wanted - return FALSE; - - arg = chr2str(nSecondary); - chose = stof(chr2str(nPrimary)); - //str2chr - if(arg == "1") { - color = getplayerkeyvalue(player_localentnum-1, "topcolor"); - ++order_page; - for(p = i = 0; i < maxclients; ++i) { - frags = getplayerkeyvalue(i, "frags"); - if(!frags || (i+1) == player_localentnum) - continue; - if(frags == "-666" || getplayerkeyvalue(i, "topcolor") != color) // FIXME use GetPlayerTeam - continue; - ++p; - } - if(p <= (8*order_page)) // no ppl on page - order_page = 0; - } else if(arg == "2") { - color = getplayerkeyvalue(player_localentnum-1, "topcolor"); - --order_page; - if(order_page < 0) { - for(p = i = 0; i < maxclients; ++i) { - frags = getplayerkeyvalue(i, "frags"); - if(!frags || (i+1) == player_localentnum) - continue; - if(frags == "-666" || getplayerkeyvalue(i, "topcolor") != color) // FIXME use GetPlayerTeam - continue; - ++p; - } - order_page = floor(p/8); - } - } else if(chose >= 3 && chose <= 9 || arg == "0") { // the 10 needs extra checking, assuming that stof(astring) returns 0 - if(chose == 0) - chose = 10; - n = 2; - color = getplayerkeyvalue(player_localentnum-1, "topcolor"); - for(p = i = 0; i < maxclients && n > 0; ++i) { - frags = getplayerkeyvalue(i, "frags"); - if(!frags || (i+1) == player_localentnum) - continue; - if(frags == "-666" || getplayerkeyvalue(i, "topcolor") != color) // FIXME use GetPlayerTeam - continue; - ++p; - if(p > (8*order_page)) - { - // only render current page - ++n; - if(n == chose) { - n = 0; - break; - } - } - } - if(n == 0) { - //print(sprintf(_("Issuing order to: %d\n"), i+1)); - //print(strcat("cmd order #", ftos(i+1), " ", ctf_temp_1, ";\n")); - localcmd(strcat("\ncmd order #", ftos(i+1), " ", ctf_temp_1, ";")); - } else { - print(sprintf(_("Couldn't find player %d\n"), chose)); - } - return TRUE; - } else if(nSecondary == K_ESCAPE) { - strunzone(ctf_temp_1); - menu_close(); - } else { - //print(sprintf(_("Menu action %s does not exist.\n"), arg)); - return FALSE; - } - return TRUE; -} - -void order_menu_show() -{ - order_page = 0; - menu_show = order_menu_render; - menu_action = order_menu_action; -} - - -void ctf_menu_render() -{ - vector ps, po; - ps = '0 200 0'; - po = '0 8 0'; - - if(getstati(STAT_CTF_STATE) == CTF_STATE_COMMANDER) { - drawstring(ps, _("----- Command Menu -----"), '8 8 0', '1 1 0', 1, 0); ps += po; - drawstring(ps, _("Issue orders:"), '8 8 0', '1 1 0', 1, 0); ps += po; - drawstring(ps, _(" 1) Attack"), '8 8 0', '1 1 0', 1, 0); - drawstring(ps + '80 0 0', " \x0F", '8 8 0', '1 1 1', 1, 0); ps += po; - drawstring(ps, strcat(_(" 2) Defend"), " \x0E"), '8 8 0', '1 1 0', 1, 0); ps += po; - ps += po; - drawstring(ps, _("3) Resign from command."), '8 8 0', '1 1 0', 1, 0); ps += po; - drawstring(ps, _("ESC) Exit Menu"), '8 8 0', '1 1 0', 1, 0); ps += po; - } else { - menu_close(); - } -} - -float ctf_menu_action(float bInputType, float nPrimary, float nSecondary) -{ - string arg; - if(bInputType != 0) // key down wanted - return FALSE; - - arg = chr2str(nSecondary); - - if(arg == "1") { - ctf_temp_1 = strzone("attack"); - order_menu_show(); - } else if(arg == "2") { - ctf_temp_1 = strzone("defend"); - order_menu_show(); - } else if(arg == "3") { - localcmd("\ncmd order resign;"); - menu_close(); - } else if(nSecondary == K_ESCAPE) { - menu_close(); - } else { - //print(strcat("Menu action ", arg, " does not exist.\n")); - return FALSE; - } - return TRUE; -} - -void ctf_menu_show() -{ - if(getstati(STAT_CTF_STATE) < 0) - return; - menu_show = ctf_menu_render; - menu_action = ctf_menu_action; - menu_visible = TRUE; - //menu_default_binds(); -} - -void ctf_view() -{ - float stat; - stat = getstati(STAT_CTF_STATE); - if(stat == CTF_STATE_ATTACK) { - drawpic('0 0 0', "gfx/ctf_ic_atk.tga", '64 64 0', '1 1 1', 1, 0); - } else if(stat == CTF_STATE_DEFEND) { - drawpic('0 0 0', "gfx/ctf_ic_def.tga", '64 64 0', '1 1 1', 1, 0); - } else if(stat == CTF_STATE_COMMANDER) { - drawstring('0 0 0', _("You're commander!"), '8 8 0', '1 1 1', 1, 0); - } else if(stat < 0) { - } else { - drawstring('0 0 0', _("Awaiting orders..."), '8 8 0', '1 1 1', 0.5, 0); - } -} - -#endif diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index e2cdbab6f..86b49761e 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -2694,7 +2694,11 @@ void HUD_Score(void) string sign; vector distribution_color; entity tm, pl, me; +#ifdef COMPAT_XON050_ENGINE me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1]; +#else + me = playerslots[player_localentnum - 1]; +#endif if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD string timer, distrtimer; @@ -3569,7 +3573,7 @@ void HUD_Mod_Race(vector pos, vector mySize) { mod_active = 1; // race should never hide the mod icons panel entity me; - me = playerslots[player_localentnum - 1]; + me = playerslots[player_localnum]; float t, score; float f; // yet another function has this score = me.(scores[ps_primary]); @@ -3677,7 +3681,7 @@ void HUD_Mod_Race(vector pos, vector mySize) drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL); drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL); } else if(race_status == 2) { - if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank) + if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank) drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankgreen", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL); else drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankyellow", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL); @@ -4123,7 +4127,11 @@ void HUD_InfoMessages(void) if(spectatee_status == -1) s = _("^1Observing"); else +#ifdef COMPAT_XON050_ENGINE s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(spectatee_status - 1)); +#else + s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(player_localentnum - 1)); +#endif drawInfoMessage(s) if(spectatee_status == -1) @@ -4146,7 +4154,7 @@ void HUD_InfoMessages(void) else if(gametype == GAME_LMS) { entity sk; - sk = playerslots[player_localentnum - 1]; + sk = playerslots[player_localnum]; if(sk.(scores[ps_primary]) >= 666) s = _("^1Match has already begun"); else if(sk.(scores[ps_primary]) > 0) @@ -4885,7 +4893,11 @@ void HUD_Main (void) drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL); } +#ifdef COMPAT_XON050_ENGINE current_player = (spectatee_status > 0) ? spectatee_status : player_localentnum; +#else + current_player = player_localentnum; +#endif // draw the dock if(autocvar_hud_dock != "" && autocvar_hud_dock != "0") diff --git a/qcsrc/client/main.qh b/qcsrc/client/main.qh index 499e84b6e..bd9ffe64c 100644 --- a/qcsrc/client/main.qh +++ b/qcsrc/client/main.qh @@ -17,14 +17,6 @@ float menu_visible; var void() menu_show; var float(float bInputType, float nPrimary, float nSecondary) menu_action; -// -------------------------------------------------------------------------- -// CTF - -#ifdef CTF_EXAMPLE -void() ctf_menu_show; -string ctf_temp_1; -#endif - // -------------------------------------------------------------------------- // Onslaught diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src index a4d8b70b1..06b3e8b7b 100644 --- a/qcsrc/client/progs.src +++ b/qcsrc/client/progs.src @@ -42,8 +42,6 @@ sortlist.qc miscfunctions.qc teamplay.qc -ctf.qc - teamradar.qc hud_config.qc hud.qc diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index d4c2043e6..3124b4b9b 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -894,7 +894,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz { if(pl.team != tm.team) continue; - HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i); + HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localnum), i); pos_y += 1.25 * hud_fontsize_y; ++i; } @@ -903,7 +903,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz { if(pl.team == COLOR_SPECTATOR) continue; - HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), i); + HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localnum), i); pos_y += 1.25 * hud_fontsize_y; ++i; } @@ -1147,7 +1147,7 @@ vector HUD_DrawScoreboardRankings(vector pos, entity pl, vector rgb, vector bg_ continue; n = grecordholder[i]; p = race_PlaceName(i+1); - if(grecordholder[i] == GetPlayerName(player_localentnum - 1)) + if(grecordholder[i] == GetPlayerName(player_localnum)) drawfill(pos, '1 0 0' * sbwidth + '0 1.25 0' * hud_fontsize_y, hl_rgb, scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL); else if(!mod(i, 2) && scoreboard_highlight) drawfill(pos, '1 0 0' * sbwidth + '0 1.25 0' * hud_fontsize_y, hl_rgb, scoreboard_highlight_alpha, DRAWFLAG_NORMAL); @@ -1296,7 +1296,7 @@ void HUD_DrawScoreboard() if(pl.team != COLOR_SPECTATOR) continue; pos_y += 1.25 * hud_fontsize_y; - HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1), specs); + HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localnum), specs); ++specs; } diff --git a/qcsrc/client/shownames.qc b/qcsrc/client/shownames.qc index 21e8bcd42..d5e24888d 100644 --- a/qcsrc/client/shownames.qc +++ b/qcsrc/client/shownames.qc @@ -13,7 +13,11 @@ void Draw_ShowNames(entity ent) if(!autocvar_hud_shownames) return; +#ifdef COMPAT_XON050_ENGINE if((ent.sv_entnum == player_localentnum) || (ent.sv_entnum == spectatee_status)) // ent is me or person i'm spectating +#else + if(ent.sv_entnum == player_localentnum) // ent is me or person i'm spectating +#endif if not (autocvar_hud_shownames_self && autocvar_chase_active) return; diff --git a/qcsrc/client/tturrets.qc b/qcsrc/client/tturrets.qc index f4a53ca19..89f1be7fa 100644 --- a/qcsrc/client/tturrets.qc +++ b/qcsrc/client/tturrets.qc @@ -264,7 +264,7 @@ void turret_draw2d() return; string spriteimage = self.netname; - float t = (GetPlayerColor(player_localentnum - 1) + 1); + float t = (GetPlayerColor(player_localnum) + 1); float a = self.alpha * autocvar_hud_panel_fg_alpha; vector rgb = spritelookupcolor(spriteimage, self.teamradar_color); diff --git a/qcsrc/client/waypointsprites.qc b/qcsrc/client/waypointsprites.qc index ac85f8c65..6d9b0ee8b 100644 --- a/qcsrc/client/waypointsprites.qc +++ b/qcsrc/client/waypointsprites.qc @@ -403,7 +403,7 @@ void Draw_WaypointSprite() InterpolateOrigin_Do(); - t = GetPlayerColor(player_localentnum - 1) + 1; + t = GetPlayerColor(player_localnum) + 1; spriteimage = ""; -- 2.39.2