Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_keyhunt.qc File Reference
Include dependency graph for cl_keyhunt.qc:
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 pos, vector mySize)

Variables

vector KH_SLOTS [4]

Function Documentation

◆ HUD_Mod_KH()

void HUD_Mod_KH ( vector pos,
vector mySize )

Definition at line 8 of file cl_keyhunt.qc.

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

Variable Documentation

◆ KH_SLOTS

vector KH_SLOTS[4]

Definition at line 6 of file cl_keyhunt.qc.

Referenced by HUD_Mod_KH().