]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/scores_rules.qc
make CSQC scores safer against packet loss/rearrangements
[divverent/nexuiz.git] / data / qcsrc / server / scores_rules.qc
1 float c1, c2, c3, c4;
2 void CheckAllowedTeams (entity for_whom);
3
4 // NOTE: SP_ constants may not be >= MAX_SCORE; ST_constants may not be >= MAX_TEAMSCORE
5 // scores that should be in all modes:
6 float ScoreRules_teams;
7 void ScoreRules_basics(float teams, float sprio)
8 {
9         ScoreRules_teams = teams;
10         if(sprio)
11                 ScoreInfo_SetLabel_TeamScore  (ST_SCORE,        "score",     sprio);
12         ScoreInfo_SetLabel_PlayerScore(SP_KILLS,        "kills",     0);
13         ScoreInfo_SetLabel_PlayerScore(SP_DEATHS,       "deaths",    SFL_LOWER_IS_BETTER);
14         ScoreInfo_SetLabel_PlayerScore(SP_SUICIDES,     "suicides",  SFL_LOWER_IS_BETTER);
15         if(sprio)
16                 ScoreInfo_SetLabel_PlayerScore(SP_SCORE,        "score",     sprio);
17 }
18 void ScoreRules_basics_end()
19 {
20         ScoreInfo_Init(ScoreRules_teams);
21 }
22 void ScoreRules_generic()
23 {
24         CheckAllowedTeams(world);
25         if(teamplay)
26         {
27                 CheckAllowedTeams(world);
28                 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY);
29         }
30         else
31                 ScoreRules_basics(0, SFL_SORT_PRIO_PRIMARY);
32         ScoreRules_basics_end();
33 }
34
35 // g_ctf
36 #define ST_CTF_CAPS 1
37 #define SP_CTF_CAPS 4
38 #define SP_CTF_PICKUPS 5
39 #define SP_CTF_FCKILLS 6
40 #define SP_CTF_RETURNS 7
41 void ScoreRules_ctf()
42 {
43         float sp_score, sp_caps;
44         sp_score = sp_caps = 0;
45         switch(cvar("g_ctf_win_mode"))
46         {
47                 case 0: // caps only
48                         sp_caps = SFL_SORT_PRIO_PRIMARY;
49                         break;
50                 case 1: // caps, then score
51                         sp_caps = SFL_SORT_PRIO_PRIMARY;
52                         sp_score = SFL_SORT_PRIO_SECONDARY;
53                         break;
54                 case 2: // score only
55                 default:
56                         sp_score = SFL_SORT_PRIO_PRIMARY;
57                         sp_caps = SFL_SORT_PRIO_SECONDARY; // looks better ;)
58                         break;
59         }
60
61         CheckAllowedTeams(world);
62         ScoreRules_basics(2 + (c3>=0), sp_score); // NOTE this assumes that the rogue team is team 3
63         ScoreInfo_SetLabel_TeamScore  (ST_CTF_CAPS,     "caps",      sp_caps);
64         ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPS,     "caps",      sp_caps);
65         ScoreInfo_SetLabel_PlayerScore(SP_CTF_PICKUPS,  "pickups",   0);
66         ScoreInfo_SetLabel_PlayerScore(SP_CTF_FCKILLS,  "fckills",   0);
67         ScoreInfo_SetLabel_PlayerScore(SP_CTF_RETURNS,  "returns",   0);
68         ScoreRules_basics_end();
69 }
70
71 // g_domination
72 #define ST_DOM_TICKS 1
73 #define SP_DOM_TICKS 4
74 #define SP_DOM_TAKES 5
75 void ScoreRules_dom()
76 {
77         float sp_domticks, sp_score;
78         sp_score = sp_domticks = 0;
79         if(cvar("g_domination_disable_frags"))
80                 sp_domticks = SFL_SORT_PRIO_PRIMARY;
81         else
82                 sp_score = SFL_SORT_PRIO_PRIMARY;
83         CheckAllowedTeams(world);
84         ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), sp_score);
85         ScoreInfo_SetLabel_TeamScore  (ST_DOM_TICKS,    "ticks",     sp_domticks);
86         ScoreInfo_SetLabel_PlayerScore(SP_DOM_TICKS,    "ticks",     sp_domticks);
87         ScoreInfo_SetLabel_PlayerScore(SP_DOM_TAKES,    "takes",     0);
88         ScoreRules_basics_end();
89 }
90
91 // LMS stuff
92 #define SP_LMS_LIVES 4
93 #define SP_LMS_RANK 5
94 void ScoreRules_lms()
95 {
96         ScoreRules_basics(0, 0);
97         ScoreInfo_SetLabel_PlayerScore(SP_LMS_LIVES,    "lives",     SFL_SORT_PRIO_SECONDARY);
98         ScoreInfo_SetLabel_PlayerScore(SP_LMS_RANK,     "rank",      SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE);
99         ScoreRules_basics_end();
100 }
101
102 // Key hunt stuff
103 #define ST_KH_CAPS 1
104 #define SP_KH_CAPS 4
105 #define SP_KH_PUSHES 5
106 #define SP_KH_DESTROYS 6
107 #define SP_KH_PICKUPS 7
108 #define SP_KH_KCKILLS 8
109 #define SP_KH_LOSSES 9
110 void ScoreRules_kh(float teams)
111 {
112         ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY);
113         ScoreInfo_SetLabel_TeamScore  (ST_KH_CAPS,      "caps",      SFL_SORT_PRIO_SECONDARY);
114         ScoreInfo_SetLabel_PlayerScore(SP_KH_CAPS,      "caps",      SFL_SORT_PRIO_SECONDARY);
115         ScoreInfo_SetLabel_PlayerScore(SP_KH_PUSHES,    "pushes",    0);
116         ScoreInfo_SetLabel_PlayerScore(SP_KH_DESTROYS,  "destroyed", SFL_LOWER_IS_BETTER);
117         ScoreInfo_SetLabel_PlayerScore(SP_KH_PICKUPS,   "pickups",   0);
118         ScoreInfo_SetLabel_PlayerScore(SP_KH_KCKILLS,   "kckills",   0);
119         ScoreInfo_SetLabel_PlayerScore(SP_KH_LOSSES,    "losses",    SFL_LOWER_IS_BETTER);
120         ScoreRules_basics_end();
121 }