Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_keyhunt.qh File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void HUD_Mod_KH (vector myPos, vector mySize, bool should_draw)

Function Documentation

◆ HUD_Mod_KH()

void HUD_Mod_KH ( vector myPos,
vector mySize,
bool should_draw )

Definition at line 8 of file cl_keyhunt.qc.

9{
10 if (!should_draw)
11 return;
12
13 mod_active = 1; // keyhunt should never hide the mod icons panel
14
15 // Read current state
16 int state = STAT(OBJECTIVE_STATUS);
17 if(!state) return;
18
19 int i, key_state;
20 int all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
21 all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
22
23 for(i = 0; i < 4; ++i)
24 {
25 key_state = (bitshift(state, i * -5) & 31) - 1;
26
27 if(key_state == -1)
28 continue;
29
30 if(key_state == 30)
31 {
32 ++carrying_keys;
33 key_state = myteam;
34 }
35
36 switch(key_state)
37 {
38 case NUM_TEAM_1: ++team1_keys; break;
39 case NUM_TEAM_2: ++team2_keys; break;
40 case NUM_TEAM_3: ++team3_keys; break;
41 case NUM_TEAM_4: ++team4_keys; break;
42 case 29: ++dropped_keys; break;
43 }
44
45 ++all_keys;
46 }
47
48 // Calculate slot measurements
49 vector slot_size;
50 if(all_keys == 4 && mySize.x * 0.5 < mySize.y && mySize.y * 0.5 < mySize.x)
51 {
52 // Quadratic arrangement
53 slot_size = vec2(mySize.x * 0.5, mySize.y * 0.5);
54 KH_SLOTS[0] = pos;
55 KH_SLOTS[1] = pos + eX * slot_size.x;
56 KH_SLOTS[2] = pos + eY * slot_size.y;
57 KH_SLOTS[3] = pos + eX * slot_size.x + eY * slot_size.y;
58 }
59 else
60 {
61 if(mySize.x > mySize.y)
62 {
63 // Horizontal arrangement
64 slot_size = vec2(mySize.x / all_keys, mySize.y);
65 for(i = 0; i < all_keys; ++i)
66 KH_SLOTS[i] = pos + eX * slot_size.x * i;
67 }
68 else
69 {
70 // Vertical arrangement
71 slot_size = vec2(mySize.x, mySize.y / all_keys);
72 for(i = 0; i < all_keys; ++i)
73 KH_SLOTS[i] = pos + eY * slot_size.y * i;
74 }
75 }
76
77 // Make icons blink in case of RUN HERE
78
79 float alpha = 1;
80 if(carrying_keys)
81 {
82 float blink = 0.6 + sin(2 * M_PI * time) * 0.4; // Oscillate between 0.2 and 1
83 switch(myteam)
84 {
85 case NUM_TEAM_1: if(team1_keys == all_keys) alpha = blink; break;
86 case NUM_TEAM_2: if(team2_keys == all_keys) alpha = blink; break;
87 case NUM_TEAM_3: if(team3_keys == all_keys) alpha = blink; break;
88 case NUM_TEAM_4: if(team4_keys == all_keys) alpha = blink; break;
89 }
90 }
92
93 // Draw icons
94
95 i = 0;
96
97 while(team1_keys--)
98 if(myteam == NUM_TEAM_1 && carrying_keys)
99 {
100 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
101 --carrying_keys;
102 }
103 else
104 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
105
106 while(team2_keys--)
107 if(myteam == NUM_TEAM_2 && carrying_keys)
108 {
109 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
110 --carrying_keys;
111 }
112 else
113 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
114
115 while(team3_keys--)
116 if(myteam == NUM_TEAM_3 && carrying_keys)
117 {
118 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
119 --carrying_keys;
120 }
121 else
122 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
123
124 while(team4_keys--)
125 if(myteam == NUM_TEAM_4 && carrying_keys)
126 {
127 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
128 --carrying_keys;
129 }
130 else
131 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
132
133 while(dropped_keys--)
134 drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
135}
vector KH_SLOTS[4]
Definition cl_keyhunt.qc:6
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:78
float alpha
Definition items.qc:13
ERASEABLE float blink(float base, float range, float freq)
Definition util.qc:2274
const float DRAWFLAG_NORMAL
float time
int state
float panel_fg_alpha
Definition hud.qh:169
#define STAT(...)
Definition stats.qh:82
#define M_PI
Definition mathlib.qh:108
float sin(float f)
bool mod_active
Definition modicons.qh:7
vector
Definition self.qh:92
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
#define vec2(...)
Definition vector.qh:90

References alpha, blink(), DRAWFLAG_NORMAL, drawpic_aspect_skin, eX, eY, KH_SLOTS, M_PI, mod_active, myteam, NUM_TEAM_1, NUM_TEAM_2, NUM_TEAM_3, NUM_TEAM_4, panel_fg_alpha, sin(), STAT, state, time, vec2, and vector.

Referenced by KeyHunt::void().