From 3c1457fc2b145f8e563bada7ee91fba516b52cc4 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Wed, 17 May 2023 13:56:01 +0200 Subject: [PATCH] improve squad color handling, allow existing color forcing code to work with squads and show the squad color in the scoreboard --- qcsrc/client/csqcmodel_hooks.qc | 17 +++++--- qcsrc/client/hud/panel/scoreboard.qc | 16 ++++++++ qcsrc/common/gamemodes/gamemode/br/_mod.inc | 3 ++ qcsrc/common/gamemodes/gamemode/br/_mod.qh | 3 ++ qcsrc/common/gamemodes/gamemode/br/br.qc | 1 + .../common/gamemodes/gamemode/br/cl_squad.qc | 41 +++++++++++++++++++ .../common/gamemodes/gamemode/br/cl_squad.qh | 4 ++ qcsrc/common/gamemodes/gamemode/br/sv_br.qc | 3 +- .../common/gamemodes/gamemode/br/sv_squad.qc | 20 +++++++++ .../common/gamemodes/gamemode/br/sv_squad.qh | 1 + 10 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 qcsrc/common/gamemodes/gamemode/br/cl_squad.qc create mode 100644 qcsrc/common/gamemodes/gamemode/br/cl_squad.qh diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index 5f421f8d2..bcf7c31ba 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -203,6 +203,8 @@ void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer) if(teamplay) isfriend = (cm == 1024 + 17 * myteam); + else if(ISGAMETYPE(BR)) + isfriend = br_isSameSquad(this); else isfriend = islocalplayer; @@ -248,14 +250,19 @@ void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer) if ((team_count == 2) && (myteam != NUM_SPECTATOR) && (fpc == 2 || fpc == 4 || fpc == 5)) forceplayercolors_enabled = true; } + else if (ISGAMETYPE(BR)) + { + if (br_inSquad() && (fpc == 2 || fpc == 5)) + forceplayercolors_enabled = true; + } else { - if ((!(ISGAMETYPE(BR) && STAT(SQUADCOLORS)) && fpc == 1) || fpc == 2) + if (fpc == 1 || fpc == 2) forceplayercolors_enabled = true; } // forceplayercolors too - if(teamplay) + if(teamplay || ISGAMETYPE(BR)) { // own team's color is never forced int forcecolor_friend = 0, forcecolor_enemy = 0; @@ -267,7 +274,7 @@ void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer) if(forceplayercolors_enabled) forcecolor_enemy = 1024 + autocvar__cl_color; - if(forcecolor_enemy && !forcecolor_friend) + if(!ISGAMETYPE(BR) && forcecolor_enemy && !forcecolor_friend) { // only enemy color is forced? // verify it is not equal to the friend color @@ -275,7 +282,7 @@ void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer) forcecolor_enemy = 0; } - if(forcecolor_friend && !forcecolor_enemy) + if(!ISGAMETYPE(BR) && forcecolor_friend && !forcecolor_enemy) { // only friend color is forced? // verify it is not equal to the enemy color @@ -288,7 +295,7 @@ void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer) forcecolor_friend = 0; } - if(cm == 1024 + 17 * myteam) + if((!ISGAMETYPE(BR) && (cm == 1024 + 17 * myteam)) || (ISGAMETYPE(BR) && br_isSameSquad(this))) { if(forcecolor_friend) this.colormap = forcecolor_friend; diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index 3914c83ca..4880f77e4 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -753,6 +753,22 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field) case SP_DMG: case SP_DMGTAKEN: return sprintf("%.1f k", pl.(scores(field)) / 1000); + case SP_BR_SQUAD: + tmp = pl.(scores(field)); + if(tmp == 0) + return string_null; + + if(STAT(SQUADCOLORS)) + { + int f = entcs_GetClientColors(pl.sv_entnum); + sbt_field_icon0 = "gfx/scoreboard/playercolor_base"; + sbt_field_icon1 = "gfx/scoreboard/playercolor_shirt"; + sbt_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0); + sbt_field_icon2 = "gfx/scoreboard/playercolor_pants"; + sbt_field_icon2_rgb = colormapPaletteColor(f % 16, 1); + } + return ftos(tmp); + default: case SP_SCORE: tmp = pl.(scores(field)); f = scores_flags(field); diff --git a/qcsrc/common/gamemodes/gamemode/br/_mod.inc b/qcsrc/common/gamemodes/gamemode/br/_mod.inc index 42767d900..41d489e46 100644 --- a/qcsrc/common/gamemodes/gamemode/br/_mod.inc +++ b/qcsrc/common/gamemodes/gamemode/br/_mod.inc @@ -16,6 +16,9 @@ #ifdef SVQC #include #endif +#ifdef CSQC + #include +#endif #ifdef SVQC #include #endif diff --git a/qcsrc/common/gamemodes/gamemode/br/_mod.qh b/qcsrc/common/gamemodes/gamemode/br/_mod.qh index 9462da4b0..2f1f2fe4b 100644 --- a/qcsrc/common/gamemodes/gamemode/br/_mod.qh +++ b/qcsrc/common/gamemodes/gamemode/br/_mod.qh @@ -16,6 +16,9 @@ #ifdef SVQC #include #endif +#ifdef CSQC + #include +#endif #ifdef SVQC #include #endif diff --git a/qcsrc/common/gamemodes/gamemode/br/br.qc b/qcsrc/common/gamemodes/gamemode/br/br.qc index 1a0663f14..74f6a554d 100644 --- a/qcsrc/common/gamemodes/gamemode/br/br.qc +++ b/qcsrc/common/gamemodes/gamemode/br/br.qc @@ -2,4 +2,5 @@ #ifdef GAMEQC REGISTER_NET_LINKED(ENT_CLIENT_RING) +REGISTER_NET_TEMP(TE_CSQC_BR_SQUAD) #endif diff --git a/qcsrc/common/gamemodes/gamemode/br/cl_squad.qc b/qcsrc/common/gamemodes/gamemode/br/cl_squad.qc new file mode 100644 index 000000000..9c167bc77 --- /dev/null +++ b/qcsrc/common/gamemodes/gamemode/br/cl_squad.qc @@ -0,0 +1,41 @@ +#include "cl_squad.qh" + +int csqcsquad_cnt = 0; +int csqcsquad[255]; // 255 is the engine limit on maxclients + +NET_HANDLE(TE_CSQC_BR_SQUAD, bool isNew) +{ + csqcsquad_cnt = ReadByte(); + + if(csqcsquad_cnt == 0) + { + LOG_SEVERE("server sent empty squad data"); + return true; + } + + for(int i = 0; i < csqcsquad_cnt; ++i) + { + int entnum = ReadByte(); + csqcsquad[i] = entnum; + } + + return true; +} + +bool br_isSameSquad(entity this) +{ + for(int i = 0; i < csqcsquad_cnt; ++i) + { + int member = csqcsquad[i]; + + if(this.entnum == member) + return true; + } + + return false; +} + +bool br_inSquad() +{ + return (csqcsquad_cnt > 0); +} diff --git a/qcsrc/common/gamemodes/gamemode/br/cl_squad.qh b/qcsrc/common/gamemodes/gamemode/br/cl_squad.qh new file mode 100644 index 000000000..4440abb01 --- /dev/null +++ b/qcsrc/common/gamemodes/gamemode/br/cl_squad.qh @@ -0,0 +1,4 @@ +#pragma once + +bool br_isSameSquad(entity this); +bool br_inSquad(); diff --git a/qcsrc/common/gamemodes/gamemode/br/sv_br.qc b/qcsrc/common/gamemodes/gamemode/br/sv_br.qc index 825866027..71f7f9b85 100644 --- a/qcsrc/common/gamemodes/gamemode/br/sv_br.qc +++ b/qcsrc/common/gamemodes/gamemode/br/sv_br.qc @@ -1219,6 +1219,7 @@ void br_Start(){ FOREACH_CLIENT(IS_REAL_CLIENT(it), { + br_SendSquad(it); STAT(SQUADCOLORS, it) = squads_colored; }); @@ -1231,7 +1232,7 @@ void br_Start(){ for(entity member = it.br_squad_first; member; member = member.br_squad_next) { - member.colormap = 1024 + squad_color; + member.clientcolors = 1024 + squad_color; } } diff --git a/qcsrc/common/gamemodes/gamemode/br/sv_squad.qc b/qcsrc/common/gamemodes/gamemode/br/sv_squad.qc index 428b0cd54..87ee6ac78 100644 --- a/qcsrc/common/gamemodes/gamemode/br/sv_squad.qc +++ b/qcsrc/common/gamemodes/gamemode/br/sv_squad.qc @@ -49,6 +49,9 @@ int br_SquadUpdateInfo() FOREACH_CLIENT(IS_REAL_CLIENT(it), { + if(IN_SQUAD(it)) + br_SendSquad(it); + STAT(SQUADSALIVE, it) = alive_squads; STAT(PLAYERSALIVE, it) = alive_players; }); @@ -162,3 +165,20 @@ entity br_SquadFindLastAlive(entity squad, bool healthy_only) return last_alive; } + +void br_SendSquad(entity to) +{ + msg_entity = to; + entity squad = to.br_squad; + + if(!squad) + return; + + WriteHeader(MSG_ONE, TE_CSQC_BR_SQUAD); + WriteByte(MSG_ONE, squad.br_squad_members); + + for(entity member = squad.br_squad_first; member; member = member.br_squad_next) + { + WriteByte(MSG_ONE, etof(member)); + } +} diff --git a/qcsrc/common/gamemodes/gamemode/br/sv_squad.qh b/qcsrc/common/gamemodes/gamemode/br/sv_squad.qh index 4f8bd40de..ac7b7b412 100644 --- a/qcsrc/common/gamemodes/gamemode/br/sv_squad.qh +++ b/qcsrc/common/gamemodes/gamemode/br/sv_squad.qh @@ -28,3 +28,4 @@ void br_SquadMember_Remove(entity player); bool br_SquadIsBotsOnly(entity squad); entity br_SquadGetRandomAvail(); entity br_SquadFindLastAlive(entity squad, bool healthy_only); +void br_SendSquad(entity to); -- 2.39.2