]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
improve squad color handling, allow existing color forcing code to work with squads...
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Wed, 17 May 2023 11:56:01 +0000 (13:56 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Wed, 17 May 2023 11:56:01 +0000 (13:56 +0200)
qcsrc/client/csqcmodel_hooks.qc
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/common/gamemodes/gamemode/br/_mod.inc
qcsrc/common/gamemodes/gamemode/br/_mod.qh
qcsrc/common/gamemodes/gamemode/br/br.qc
qcsrc/common/gamemodes/gamemode/br/cl_squad.qc [new file with mode: 0644]
qcsrc/common/gamemodes/gamemode/br/cl_squad.qh [new file with mode: 0644]
qcsrc/common/gamemodes/gamemode/br/sv_br.qc
qcsrc/common/gamemodes/gamemode/br/sv_squad.qc
qcsrc/common/gamemodes/gamemode/br/sv_squad.qh

index 5f421f8d28fbfb9e6928ba1fb514eefc6728cb26..bcf7c31ba808cfc01048f081dde98ba080bfafba 100644 (file)
@@ -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;
index 3914c83ca4df30a0c705372985a0954d81e44d81..4880f77e40fc1b8cbf890743ce09fb8321f98605 100644 (file)
@@ -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);
index 42767d900bcbab16acde0bd31bbd04e7a662a123..41d489e46c15c9ffff54f8b6aadfbd5db898207c 100644 (file)
@@ -16,6 +16,9 @@
 #ifdef SVQC
     #include <common/gamemodes/gamemode/br/sv_dropship.qc>
 #endif
+#ifdef CSQC
+    #include <common/gamemodes/gamemode/br/cl_squad.qc>
+#endif
 #ifdef SVQC
     #include <common/gamemodes/gamemode/br/sv_squad.qc>
 #endif
index 9462da4b056b35b2f403e208042edb2cb728f018..2f1f2fe4b6858961d46f5ef2a57ea938187fa768 100644 (file)
@@ -16,6 +16,9 @@
 #ifdef SVQC
     #include <common/gamemodes/gamemode/br/sv_dropship.qh>
 #endif
+#ifdef CSQC
+    #include <common/gamemodes/gamemode/br/cl_squad.qh>
+#endif
 #ifdef SVQC
     #include <common/gamemodes/gamemode/br/sv_squad.qh>
 #endif
index 1a0663f1439d4f3a5d68678ac1560e9cdf3bce70..74f6a554d2972c4d2ab5208d6a6e5add0ead01f8 100644 (file)
@@ -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 (file)
index 0000000..9c167bc
--- /dev/null
@@ -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 (file)
index 0000000..4440abb
--- /dev/null
@@ -0,0 +1,4 @@
+#pragma once
+
+bool br_isSameSquad(entity this);
+bool br_inSquad();
index 82586602765c561d150ada309de2ca5c76b20317..71f7f9b857470c091d6c3c0c68fe168befd3adab 100644 (file)
@@ -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;
             }
         }
 
index 428b0cd548222099ca81040bce4465aa2f436231..87ee6ac78ac9dd4a2e1b46dec9ccb814aff5f0ff 100644 (file)
@@ -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));
+    }
+}
index 4f8bd40de591b2378eb11df9273b65c5bc86f5be..ac7b7b41216c315c43421f2ce8c0671a75fa3ecc 100644 (file)
@@ -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);