Xonotic
cl_ctf.qc File Reference
+ Include dependency graph for cl_ctf.qc:

Go to the source code of this file.

Macros

#define X(team)
 
#define X(team, cond)
 
#define X(team)
 

Functions

void HUD_Mod_CTF (vector pos, vector mySize)
 
void HUD_Mod_CTF_Reset ()
 
 MUTATOR_HOOKFUNCTION (cl_ctf, ShowRankings)
 
 REGISTER_MUTATOR (cl_ctf, true)
 

Variables

int autocvar__teams_available
 
bool autocvar_hud_panel_scoreboard_ctf_leaderboard = true
 
int blueflag_prevframe
 
int blueflag_prevstatus
 
float blueflag_statuschange_time
 
int neutralflag_prevframe
 
int neutralflag_prevstatus
 
float neutralflag_statuschange_time
 
int pinkflag_prevframe
 
int pinkflag_prevstatus
 
float pinkflag_statuschange_time
 
int redflag_prevframe
 
int redflag_prevstatus
 
float redflag_statuschange_time
 
int yellowflag_prevframe
 
int yellowflag_prevstatus
 
float yellowflag_statuschange_time
 

Macro Definition Documentation

◆ X [1/3]

#define X (   team)
Value:
if (team##flag != team##flag_prevframe) { \
team##flag_statuschange_time = time; \
team##flag_prevstatus = team##flag_prevframe; \
team##flag_prevframe = team##flag; \
} \
team##flag_statuschange_elapsedtime = time - team##flag_statuschange_time; \
MACRO_END
int team
Definition: main.qh:157
if(IS_DEAD(this))
Definition: impulse.qc:92
float time
Definition: csprogsdefs.qc:16

Referenced by HUD_Mod_CTF(), and UpdatePlayerSounds().

◆ X [2/3]

#define X (   team,
  cond 
)

◆ X [3/3]

#define X (   team)
Value:
MACRO_BEGIN \
f = bound(0, team##flag_statuschange_elapsedtime * 2, 1); \
if (team##_icon && ctf_stalemate) \
drawpic_aspect_skin(team##flag_pos, "flag_stalemate", flag_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); \
if (team##_icon_prevstatus && f < 1) \
drawpic_aspect_skin_expanding(team##flag_pos, team##_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * team##_alpha_prevstatus, DRAWFLAG_NORMAL, f); \
if (team##_icon) \
drawpic_aspect_skin(team##flag_pos, team##_icon, flag_size, '1 1 1', panel_fg_alpha * team##_alpha * f, DRAWFLAG_NORMAL); \
MACRO_END
float panel_fg_alpha
Definition: hud.qh:166
int team
Definition: main.qh:157
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
bool ctf_stalemate
Definition: sv_ctf.qh:134

Function Documentation

◆ HUD_Mod_CTF()

void HUD_Mod_CTF ( vector  pos,
vector  mySize 
)

Definition at line 21 of file cl_ctf.qc.

References autocvar__hud_configure, autocvar__teams_available, BIT, ctf_oneflag, ctf_stalemate, eX, eY, mod_active, NUM_TEAM_1, NUM_TEAM_2, NUM_TEAM_3, NUM_TEAM_4, string_null, vector(), and X.

Referenced by HUD_ModIcons().

22 {
23  vector redflag_pos, blueflag_pos, yellowflag_pos, pinkflag_pos, neutralflag_pos;
24  vector flag_size;
25  float f; // every function should have that
26 
27  int redflag, blueflag, yellowflag, pinkflag, neutralflag; // current status
28  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
29  bool ctf_oneflag; // one-flag CTF mode enabled/disabled
30  bool ctf_stalemate; // currently in stalemate
31  int stat_items = STAT(OBJECTIVE_STATUS);
32  float fs, fs2, fs3, size1, size2;
33  vector e1, e2;
34 
35  int nteams = autocvar__teams_available;
36 
37  redflag = (stat_items/CTF_RED_FLAG_TAKEN) & 3;
38  blueflag = (stat_items/CTF_BLUE_FLAG_TAKEN) & 3;
39  yellowflag = (stat_items/CTF_YELLOW_FLAG_TAKEN) & 3;
40  pinkflag = (stat_items/CTF_PINK_FLAG_TAKEN) & 3;
41  neutralflag = (stat_items/CTF_NEUTRAL_FLAG_TAKEN) & 3;
42 
43  ctf_oneflag = (stat_items & CTF_FLAG_NEUTRAL);
44 
45  ctf_stalemate = (stat_items & CTF_STALEMATE);
46 
47  mod_active = (redflag || blueflag || yellowflag || pinkflag || neutralflag || (stat_items & CTF_SHIELDED));
48 
50  redflag = 1;
51  blueflag = 2;
52  if (nteams & BIT(2))
53  yellowflag = 2;
54  if (nteams & BIT(3))
55  pinkflag = 3;
56  ctf_oneflag = neutralflag = 0; // disable neutral flag in hud editor?
57  }
58 
59  // when status CHANGES, set old status into prevstatus and current status into status
60  #define X(team) MACRO_BEGIN \
61  if (team##flag != team##flag_prevframe) { \
62  team##flag_statuschange_time = time; \
63  team##flag_prevstatus = team##flag_prevframe; \
64  team##flag_prevframe = team##flag; \
65  } \
66  team##flag_statuschange_elapsedtime = time - team##flag_statuschange_time; \
67  MACRO_END
68  X(red);
69  X(blue);
70  X(yellow);
71  X(pink);
72  X(neutral);
73  #undef X
74 
75  #define X(team, cond) \
76  string team##_icon = string_null, team##_icon_prevstatus = string_null; \
77  int team##_alpha, team##_alpha_prevstatus; \
78  team##_alpha = team##_alpha_prevstatus = 1; \
79  MACRO_BEGIN \
80  switch (team##flag) { \
81  case 1: team##_icon = "flag_" #team "_taken"; break; \
82  case 2: team##_icon = "flag_" #team "_lost"; break; \
83  case 3: team##_icon = "flag_" #team "_carrying"; team##_alpha = blink(0.85, 0.15, 5); break; \
84  default: \
85  if ((stat_items & CTF_SHIELDED) && (cond)) { \
86  team##_icon = "flag_" #team "_shielded"; \
87  } else { \
88  team##_icon = string_null; \
89  } \
90  break; \
91  } \
92  switch (team##flag_prevstatus) { \
93  case 1: team##_icon_prevstatus = "flag_" #team "_taken"; break; \
94  case 2: team##_icon_prevstatus = "flag_" #team "_lost"; break; \
95  case 3: team##_icon_prevstatus = "flag_" #team "_carrying"; team##_alpha_prevstatus = blink(0.85, 0.15, 5); break; \
96  default: \
97  if (team##flag == 3) { \
98  team##_icon_prevstatus = "flag_" #team "_carrying"; /* make it more visible */\
99  } else if((stat_items & CTF_SHIELDED) && (cond)) { \
100  team##_icon_prevstatus = "flag_" #team "_shielded"; \
101  } else { \
102  team##_icon_prevstatus = string_null; \
103  } \
104  break; \
105  } \
106  MACRO_END
107  X(red, myteam != NUM_TEAM_1 && (nteams & BIT(0)));
108  X(blue, myteam != NUM_TEAM_2 && (nteams & BIT(1)));
109  X(yellow, myteam != NUM_TEAM_3 && (nteams & BIT(2)));
110  X(pink, myteam != NUM_TEAM_4 && (nteams & BIT(3)));
111  X(neutral, ctf_oneflag);
112  #undef X
113 
114  int tcount = 2;
115  if(nteams & BIT(2))
116  tcount = 3;
117  if(nteams & BIT(3))
118  tcount = 4;
119 
120  if (ctf_oneflag) {
121  // hacky, but these aren't needed
122  red_icon = red_icon_prevstatus = blue_icon = blue_icon_prevstatus = yellow_icon = yellow_icon_prevstatus = pink_icon = pink_icon_prevstatus = string_null;
123  fs = fs2 = fs3 = 1;
124  } else switch (tcount) {
125  default:
126  case 2: fs = 0.5; fs2 = 0.5; fs3 = 0.5; break;
127  case 3: fs = 1; fs2 = 0.35; fs3 = 0.35; break;
128  case 4: fs = 0.75; fs2 = 0.25; fs3 = 0.5; break;
129  }
130 
131  if (mySize_x > mySize_y) {
132  size1 = mySize_x;
133  size2 = mySize_y;
134  e1 = eX;
135  e2 = eY;
136  } else {
137  size1 = mySize_y;
138  size2 = mySize_x;
139  e1 = eY;
140  e2 = eX;
141  }
142 
143  switch (myteam) {
144  default:
145  case NUM_TEAM_1: {
146  redflag_pos = pos;
147  blueflag_pos = pos + eX * fs2 * size1;
148  yellowflag_pos = pos - eX * fs2 * size1;
149  pinkflag_pos = pos + eX * fs3 * size1;
150  break;
151  }
152  case NUM_TEAM_2: {
153  redflag_pos = pos + eX * fs2 * size1;
154  blueflag_pos = pos;
155  yellowflag_pos = pos - eX * fs2 * size1;
156  pinkflag_pos = pos + eX * fs3 * size1;
157  break;
158  }
159  case NUM_TEAM_3: {
160  redflag_pos = pos + eX * fs3 * size1;
161  blueflag_pos = pos - eX * fs2 * size1;
162  yellowflag_pos = pos;
163  pinkflag_pos = pos + eX * fs2 * size1;
164  break;
165  }
166  case NUM_TEAM_4: {
167  redflag_pos = pos - eX * fs2 * size1;
168  blueflag_pos = pos + eX * fs3 * size1;
169  yellowflag_pos = pos + eX * fs2 * size1;
170  pinkflag_pos = pos;
171  break;
172  }
173  }
174  neutralflag_pos = pos;
175  flag_size = e1 * fs * size1 + e2 * size2;
176 
177  #define X(team) MACRO_BEGIN \
178  f = bound(0, team##flag_statuschange_elapsedtime * 2, 1); \
179  if (team##_icon && ctf_stalemate) \
180  drawpic_aspect_skin(team##flag_pos, "flag_stalemate", flag_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); \
181  if (team##_icon_prevstatus && f < 1) \
182  drawpic_aspect_skin_expanding(team##flag_pos, team##_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * team##_alpha_prevstatus, DRAWFLAG_NORMAL, f); \
183  if (team##_icon) \
184  drawpic_aspect_skin(team##flag_pos, team##_icon, flag_size, '1 1 1', panel_fg_alpha * team##_alpha * f, DRAWFLAG_NORMAL); \
185  MACRO_END
186  X(red);
187  X(blue);
188  X(yellow);
189  X(pink);
190  X(neutral);
191  #undef X
192 }
string string_null
Definition: nil.qh:9
const int NUM_TEAM_2
Definition: teams.qh:19
const vector eY
Definition: vector.qh:45
#define X(team)
bool autocvar__hud_configure
Definition: hud_config.qh:3
bool mod_active
Definition: modicons.qh:7
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
int autocvar__teams_available
Definition: cl_ctf.qc:20
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const int NUM_TEAM_4
Definition: teams.qh:21
const vector eX
Definition: vector.qh:44
const int NUM_TEAM_1
Definition: teams.qh:18
bool ctf_stalemate
Definition: sv_ctf.qh:134
bool ctf_oneflag
Definition: sv_ctf.qh:160
const int NUM_TEAM_3
Definition: teams.qh:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HUD_Mod_CTF_Reset()

void HUD_Mod_CTF_Reset ( )

Definition at line 13 of file cl_ctf.qc.

References blueflag_prevframe, blueflag_prevstatus, blueflag_statuschange_time, neutralflag_prevframe, neutralflag_prevstatus, neutralflag_statuschange_time, pinkflag_prevframe, pinkflag_prevstatus, pinkflag_statuschange_time, redflag_prevframe, redflag_prevstatus, redflag_statuschange_time, yellowflag_prevframe, yellowflag_prevstatus, and yellowflag_statuschange_time.

14 {
18 }
int redflag_prevstatus
Definition: cl_ctf.qc:10
float neutralflag_statuschange_time
Definition: cl_ctf.qc:11
int pinkflag_prevstatus
Definition: cl_ctf.qc:10
float yellowflag_statuschange_time
Definition: cl_ctf.qc:11
int neutralflag_prevstatus
Definition: cl_ctf.qc:10
int neutralflag_prevframe
Definition: cl_ctf.qc:9
int pinkflag_prevframe
Definition: cl_ctf.qc:9
int yellowflag_prevframe
Definition: cl_ctf.qc:9
float redflag_statuschange_time
Definition: cl_ctf.qc:11
int yellowflag_prevstatus
Definition: cl_ctf.qc:10
int redflag_prevframe
Definition: cl_ctf.qc:9
int blueflag_prevstatus
Definition: cl_ctf.qc:10
int blueflag_prevframe
Definition: cl_ctf.qc:9
float blueflag_statuschange_time
Definition: cl_ctf.qc:11
float pinkflag_statuschange_time
Definition: cl_ctf.qc:11

◆ MUTATOR_HOOKFUNCTION()

MUTATOR_HOOKFUNCTION ( cl_ctf  ,
ShowRankings   
)

Definition at line 198 of file cl_ctf.qc.

References autocvar_hud_panel_scoreboard_ctf_leaderboard, ISGAMETYPE, and M_ARGV.

199 {
200  if(autocvar_hud_panel_scoreboard_ctf_leaderboard && ISGAMETYPE(CTF) && STAT(CTF_SHOWLEADERBOARD))
201  {
202  M_ARGV(0, string) = _("Capture time rankings");
203  return true;
204  }
205 }
bool autocvar_hud_panel_scoreboard_ctf_leaderboard
Definition: cl_ctf.qc:194
#define M_ARGV(x, type)
Definition: events.qh:17
#define ISGAMETYPE(NAME)
Definition: main.qh:32

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( cl_ctf  ,
true   
)

Variable Documentation

◆ autocvar__teams_available

int autocvar__teams_available

Definition at line 20 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF().

◆ autocvar_hud_panel_scoreboard_ctf_leaderboard

bool autocvar_hud_panel_scoreboard_ctf_leaderboard = true

Definition at line 194 of file cl_ctf.qc.

Referenced by MUTATOR_HOOKFUNCTION().

◆ blueflag_prevframe

int blueflag_prevframe

Definition at line 9 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ blueflag_prevstatus

int blueflag_prevstatus

Definition at line 10 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ blueflag_statuschange_time

float blueflag_statuschange_time

Definition at line 11 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ neutralflag_prevframe

int neutralflag_prevframe

Definition at line 9 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ neutralflag_prevstatus

int neutralflag_prevstatus

Definition at line 10 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ neutralflag_statuschange_time

float neutralflag_statuschange_time

Definition at line 11 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ pinkflag_prevframe

int pinkflag_prevframe

Definition at line 9 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ pinkflag_prevstatus

int pinkflag_prevstatus

Definition at line 10 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ pinkflag_statuschange_time

float pinkflag_statuschange_time

Definition at line 11 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ redflag_prevframe

int redflag_prevframe

Definition at line 9 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ redflag_prevstatus

int redflag_prevstatus

Definition at line 10 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ redflag_statuschange_time

float redflag_statuschange_time

Definition at line 11 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ yellowflag_prevframe

int yellowflag_prevframe

Definition at line 9 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ yellowflag_prevstatus

int yellowflag_prevstatus

Definition at line 10 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().

◆ yellowflag_statuschange_time

float yellowflag_statuschange_time

Definition at line 11 of file cl_ctf.qc.

Referenced by HUD_Mod_CTF_Reset().