Properly support team field on trigger_multiple
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / scores_rules.qc
1 #include "scores_rules.qh"
2
3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5 #include "client.qh"
6 #include "scores.qh"
7 #include <common/gamemodes/rules.qh>
8 #include "teamplay.qh"
9
10 int ScoreRules_teams;
11
12 void CheckAllowedTeams (entity for_whom);
13
14 int NumTeams(int teams)
15 {
16         return boolean(teams & BIT(0)) + boolean(teams & BIT(1)) + boolean(teams & BIT(2)) + boolean(teams & BIT(3));
17 }
18
19 int AvailableTeams()
20 {
21         return NumTeams(ScoreRules_teams);
22         // NOTE: this method is unreliable, as forced teams set the c* globals to weird values
23         //return boolean(c1 >= 0) + boolean(c2 >= 0) + boolean(c3 >= 0) + boolean(c4 >= 0);
24 }
25
26 // NOTE: ST_constants may not be >= MAX_TEAMSCORE
27 // scores that should be in all modes:
28 void ScoreRules_basics(int teams, float sprio, float stprio, float score_enabled)
29 {
30         FOREACH(Scores, true, {
31                 ScoreInfo_SetLabel_PlayerScore(it, "", 0);
32     });
33         for(int i = 0; i < MAX_TEAMSCORE; ++i)
34                 ScoreInfo_SetLabel_TeamScore(i, "", 0);
35
36         ScoreRules_teams = teams;
37
38         if(score_enabled)
39                 ScoreInfo_SetLabel_TeamScore  (ST_SCORE,        "score",     stprio);
40
41         if (!INDEPENDENT_PLAYERS)
42                 ScoreInfo_SetLabel_PlayerScore(SP_KILLS,        "kills",     0);
43
44         ScoreInfo_SetLabel_PlayerScore(SP_DEATHS,       "deaths",    SFL_LOWER_IS_BETTER);
45
46         if (!INDEPENDENT_PLAYERS)
47         {
48                 ScoreInfo_SetLabel_PlayerScore(SP_SUICIDES,     "suicides",  SFL_LOWER_IS_BETTER);
49                 ScoreInfo_SetLabel_PlayerScore(SP_TEAMKILLS,     "teamkills", SFL_LOWER_IS_BETTER);
50         }
51
52         if(score_enabled)
53                 ScoreInfo_SetLabel_PlayerScore(SP_SCORE,        "score",     sprio);
54
55         ScoreInfo_SetLabel_PlayerScore(SP_DMG, "dmg", 0);
56         ScoreInfo_SetLabel_PlayerScore(SP_DMGTAKEN, "dmgtaken", SFL_LOWER_IS_BETTER);
57         ScoreInfo_SetLabel_PlayerScore(SP_ELO, "elo", 0);
58 }
59 void ScoreRules_basics_end()
60 {
61         ScoreInfo_Init(ScoreRules_teams);
62 }
63 void ScoreRules_generic()
64 {
65     int teams = 0;
66         if (teamplay) {
67                 CheckAllowedTeams(NULL);
68                 if (c1 >= 0) teams |= BIT(0);
69                 if (c2 >= 0) teams |= BIT(1);
70                 if (c3 >= 0) teams |= BIT(2);
71                 if (c4 >= 0) teams |= BIT(3);
72         }
73         GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {});
74 }