Xonotic
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 pos, vector mySize)
 

Function Documentation

◆ HUD_Mod_KH()

void HUD_Mod_KH ( vector  pos,
vector  mySize 
)

Definition at line 8 of file cl_keyhunt.qc.

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

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  }
88 
89  // Draw icons
90 
91  i = 0;
92 
93  while(team1_keys--)
94  if(myteam == NUM_TEAM_1 && carrying_keys)
95  {
96  drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
97  --carrying_keys;
98  }
99  else
100  drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
101 
102  while(team2_keys--)
103  if(myteam == NUM_TEAM_2 && carrying_keys)
104  {
105  drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
106  --carrying_keys;
107  }
108  else
109  drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
110 
111  while(team3_keys--)
112  if(myteam == NUM_TEAM_3 && carrying_keys)
113  {
114  drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
115  --carrying_keys;
116  }
117  else
118  drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
119 
120  while(team4_keys--)
121  if(myteam == NUM_TEAM_4 && carrying_keys)
122  {
123  drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
124  --carrying_keys;
125  }
126  else
127  drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
128 
129  while(dropped_keys--)
130  drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
131 }
float state
Definition: subs.qh:32
float alpha
Definition: items.qc:14
const int NUM_TEAM_2
Definition: teams.qh:19
const vector eY
Definition: vector.qh:45
ERASEABLE float blink(float base, float range, float freq)
Definition: util.qc:2044
bool mod_active
Definition: modicons.qh:7
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:78
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const int NUM_TEAM_4
Definition: teams.qh:21
const float M_PI
Definition: csprogsdefs.qc:269
const vector eX
Definition: vector.qh:44
#define vec2(...)
Definition: vector.qh:90
const int NUM_TEAM_1
Definition: teams.qh:18
float time
Definition: csprogsdefs.qc:16
const int NUM_TEAM_3
Definition: teams.qh:20
vector KH_SLOTS[4]
Definition: cl_keyhunt.qc:6
+ Here is the call graph for this function: