Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_ctf.qc
Go to the documentation of this file.
1#include "cl_ctf.qh"
2
4#include <client/draw.qh>
5#include <client/hud/_mod.qh>
7
8// CTF HUD modicon section
12
19
21void HUD_Mod_CTF(vector pos, vector mySize, bool should_draw)
22{
23 if (!should_draw)
24 return;
25
26 vector redflag_pos, blueflag_pos, yellowflag_pos, pinkflag_pos, neutralflag_pos;
27 vector flag_size;
28 float f; // every function should have that
29
30 int redflag, blueflag, yellowflag, pinkflag, neutralflag; // current status
31 float redflag_statuschange_elapsedtime = 0, blueflag_statuschange_elapsedtime = 0, yellowflag_statuschange_elapsedtime = 0, pinkflag_statuschange_elapsedtime = 0, neutralflag_statuschange_elapsedtime = 0; // time since the status changed
32 bool ctf_oneflag; // one-flag CTF mode enabled/disabled
33 bool ctf_stalemate; // currently in stalemate
34 int stat_items = STAT(OBJECTIVE_STATUS);
35 float fs, fs2, fs3, size1, size2;
36 vector e1, e2;
37
38 int nteams = autocvar__teams_available;
39
40 redflag = (stat_items/CTF_RED_FLAG_TAKEN) & 3;
41 blueflag = (stat_items/CTF_BLUE_FLAG_TAKEN) & 3;
42 yellowflag = (stat_items/CTF_YELLOW_FLAG_TAKEN) & 3;
43 pinkflag = (stat_items/CTF_PINK_FLAG_TAKEN) & 3;
44 neutralflag = (stat_items/CTF_NEUTRAL_FLAG_TAKEN) & 3;
45
46 ctf_oneflag = (stat_items & CTF_FLAG_NEUTRAL);
47
48 ctf_stalemate = (stat_items & CTF_STALEMATE);
49
50 mod_active = (redflag || blueflag || yellowflag || pinkflag || neutralflag || (stat_items & CTF_SHIELDED));
51
53 redflag = 1;
54 blueflag = 2;
55 if (nteams & BIT(2))
56 yellowflag = 2;
57 if (nteams & BIT(3))
58 pinkflag = 3;
59 ctf_oneflag = neutralflag = 0; // disable neutral flag in hud editor?
60 }
61
62 // when status CHANGES, set old status into prevstatus and current status into status
63 #define X(team) MACRO_BEGIN \
64 if (team##flag != team##flag_prevframe) { \
65 team##flag_statuschange_time = time; \
66 team##flag_prevstatus = team##flag_prevframe; \
67 team##flag_prevframe = team##flag; \
68 } \
69 team##flag_statuschange_elapsedtime = time - team##flag_statuschange_time; \
70 MACRO_END
71 X(red);
72 X(blue);
73 X(yellow);
74 X(pink);
75 X(neutral);
76 #undef X
77
78 #define X(team, cond) \
79 string team##_icon = string_null, team##_icon_prevstatus = string_null; \
80 int team##_alpha, team##_alpha_prevstatus; \
81 team##_alpha = team##_alpha_prevstatus = 1; \
82 MACRO_BEGIN \
83 switch (team##flag) { \
84 case 1: team##_icon = "flag_" #team "_taken"; break; \
85 case 2: team##_icon = "flag_" #team "_lost"; break; \
86 case 3: team##_icon = "flag_" #team "_carrying"; team##_alpha = blink(0.85, 0.15, 5); break; \
87 default: \
88 if ((stat_items & CTF_SHIELDED) && (cond)) { \
89 team##_icon = "flag_" #team "_shielded"; \
90 } else { \
91 team##_icon = string_null; \
92 } \
93 break; \
94 } \
95 switch (team##flag_prevstatus) { \
96 case 1: team##_icon_prevstatus = "flag_" #team "_taken"; break; \
97 case 2: team##_icon_prevstatus = "flag_" #team "_lost"; break; \
98 case 3: team##_icon_prevstatus = "flag_" #team "_carrying"; team##_alpha_prevstatus = blink(0.85, 0.15, 5); break; \
99 default: \
100 if (team##flag == 3) { \
101 team##_icon_prevstatus = "flag_" #team "_carrying"; /* make it more visible */\
102 } else if((stat_items & CTF_SHIELDED) && (cond)) { \
103 team##_icon_prevstatus = "flag_" #team "_shielded"; \
104 } else { \
105 team##_icon_prevstatus = string_null; \
106 } \
107 break; \
108 } \
109 MACRO_END
110 X(red, myteam != NUM_TEAM_1 && (nteams & BIT(0)));
111 X(blue, myteam != NUM_TEAM_2 && (nteams & BIT(1)));
112 X(yellow, myteam != NUM_TEAM_3 && (nteams & BIT(2)));
113 X(pink, myteam != NUM_TEAM_4 && (nteams & BIT(3)));
114 X(neutral, ctf_oneflag);
115 #undef X
116
117 int tcount = 2;
118 if(nteams & BIT(2))
119 tcount = 3;
120 if(nteams & BIT(3))
121 tcount = 4;
122
123 if (ctf_oneflag) {
124 // hacky, but these aren't needed
125 red_icon = red_icon_prevstatus = blue_icon = blue_icon_prevstatus = yellow_icon = yellow_icon_prevstatus = pink_icon = pink_icon_prevstatus = string_null;
126 fs = fs2 = fs3 = 1;
127 } else switch (tcount) {
128 default:
129 case 2: fs = 0.5; fs2 = 0.5; fs3 = 0.5; break;
130 case 3: fs = 1; fs2 = 0.35; fs3 = 0.35; break;
131 case 4: fs = 0.75; fs2 = 0.25; fs3 = 0.5; break;
132 }
133
134 if (mySize_x > mySize_y) {
135 size1 = mySize_x;
136 size2 = mySize_y;
137 e1 = eX;
138 e2 = eY;
139 } else {
140 size1 = mySize_y;
141 size2 = mySize_x;
142 e1 = eY;
143 e2 = eX;
144 }
145
146 switch (myteam) {
147 default:
148 case NUM_TEAM_1: {
149 redflag_pos = pos;
150 blueflag_pos = pos + eX * fs2 * size1;
151 yellowflag_pos = pos - eX * fs2 * size1;
152 pinkflag_pos = pos + eX * fs3 * size1;
153 break;
154 }
155 case NUM_TEAM_2: {
156 redflag_pos = pos + eX * fs2 * size1;
157 blueflag_pos = pos;
158 yellowflag_pos = pos - eX * fs2 * size1;
159 pinkflag_pos = pos + eX * fs3 * size1;
160 break;
161 }
162 case NUM_TEAM_3: {
163 redflag_pos = pos + eX * fs3 * size1;
164 blueflag_pos = pos - eX * fs2 * size1;
165 yellowflag_pos = pos;
166 pinkflag_pos = pos + eX * fs2 * size1;
167 break;
168 }
169 case NUM_TEAM_4: {
170 redflag_pos = pos - eX * fs2 * size1;
171 blueflag_pos = pos + eX * fs3 * size1;
172 yellowflag_pos = pos + eX * fs2 * size1;
173 pinkflag_pos = pos;
174 break;
175 }
176 }
177 neutralflag_pos = pos;
178 flag_size = e1 * fs * size1 + e2 * size2;
179
180 #define X(team) MACRO_BEGIN \
181 f = bound(0, team##flag_statuschange_elapsedtime * 2, 1); \
182 if (team##_icon && ctf_stalemate) \
183 drawpic_aspect_skin(team##flag_pos, "flag_stalemate", flag_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); \
184 if (team##_icon_prevstatus && f < 1) \
185 drawpic_aspect_skin_expanding(team##flag_pos, team##_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * team##_alpha_prevstatus, DRAWFLAG_NORMAL, f); \
186 if (team##_icon) \
187 drawpic_aspect_skin(team##flag_pos, team##_icon, flag_size, '1 1 1', panel_fg_alpha * team##_alpha * f, DRAWFLAG_NORMAL); \
188 MACRO_END
189 X(red);
190 X(blue);
191 X(yellow);
192 X(pink);
193 X(neutral);
194 #undef X
195}
196
198
199REGISTER_MUTATOR(cl_ctf, true);
200
201MUTATOR_HOOKFUNCTION(cl_ctf, ShowRankings)
202{
203 if(autocvar_hud_panel_scoreboard_ctf_leaderboard && ISGAMETYPE(CTF) && STAT(CTF_SHOWLEADERBOARD))
204 {
205 M_ARGV(0, string) = _("Capture time rankings");
206 return true;
207 }
208}
#define REGISTER_MUTATOR(...)
Definition base.qh:295
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
int pinkflag_prevstatus
Definition cl_ctf.qc:10
void HUD_Mod_CTF_Reset()
Definition cl_ctf.qc:13
int neutralflag_prevframe
Definition cl_ctf.qc:9
float pinkflag_statuschange_time
Definition cl_ctf.qc:11
void HUD_Mod_CTF(vector pos, vector mySize, bool should_draw)
Definition cl_ctf.qc:21
bool autocvar_hud_panel_scoreboard_ctf_leaderboard
Definition cl_ctf.qc:197
int blueflag_prevframe
Definition cl_ctf.qc:9
int redflag_prevframe
Definition cl_ctf.qc:9
#define X(team)
int yellowflag_prevframe
Definition cl_ctf.qc:9
int blueflag_prevstatus
Definition cl_ctf.qc:10
int yellowflag_prevstatus
Definition cl_ctf.qc:10
float neutralflag_statuschange_time
Definition cl_ctf.qc:11
int redflag_prevstatus
Definition cl_ctf.qc:10
int autocvar__teams_available
Definition cl_ctf.qc:20
float redflag_statuschange_time
Definition cl_ctf.qc:11
int neutralflag_prevstatus
Definition cl_ctf.qc:10
float yellowflag_statuschange_time
Definition cl_ctf.qc:11
int pinkflag_prevframe
Definition cl_ctf.qc:9
float blueflag_statuschange_time
Definition cl_ctf.qc:11
#define ISGAMETYPE(NAME)
Definition main.qh:46
#define M_ARGV(x, type)
Definition events.qh:17
const int CTF_SHIELDED
Definition ctf.qh:57
const int CTF_YELLOW_FLAG_TAKEN
Definition ctf.qh:47
const int CTF_PINK_FLAG_TAKEN
Definition ctf.qh:50
const int CTF_RED_FLAG_TAKEN
Definition ctf.qh:41
const int CTF_FLAG_NEUTRAL
Definition ctf.qh:56
const int CTF_STALEMATE
Definition ctf.qh:58
const int CTF_BLUE_FLAG_TAKEN
Definition ctf.qh:44
const int CTF_NEUTRAL_FLAG_TAKEN
Definition ctf.qh:53
bool autocvar__hud_configure
Definition hud_config.qh:3
#define STAT(...)
Definition stats.qh:82
bool mod_active
Definition modicons.qh:7
string string_null
Definition nil.qh:9
vector
Definition self.qh:92
bool ctf_stalemate
Definition sv_ctf.qh:143
bool ctf_oneflag
Definition sv_ctf.qh:170
int myteam
Definition teams.qh:60
const int NUM_TEAM_2
Definition teams.qh:14
const int NUM_TEAM_4
Definition teams.qh:16
const int NUM_TEAM_3
Definition teams.qh:15
const int NUM_TEAM_1
Definition teams.qh:13
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44