make sure leadlimit is >= 0
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / keepaway / cl_keepaway.qc
1 #include "cl_keepaway.qh"
2
3 #include <client/hud/panel/modicons.qh>
4
5 // Keepaway HUD mod icon
6 int kaball_prevstatus; // last remembered status
7 float kaball_statuschange_time; // time when the status changed
8
9 // we don't need to reset for keepaway since it immediately
10 // autocorrects prevstatus as to if the player has the ball or not
11
12 void HUD_Mod_Keepaway(vector pos, vector mySize)
13 {
14         mod_active = 1; // keepaway should always show the mod HUD
15
16         float BLINK_FACTOR = 0.15;
17         float BLINK_BASE = 0.85;
18         float BLINK_FREQ = 5;
19         float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
20
21         int stat_items = STAT(ITEMS);
22         int kaball = (stat_items/IT_KEY1) & 1;
23
24         if(kaball != kaball_prevstatus)
25         {
26                 kaball_statuschange_time = time;
27                 kaball_prevstatus = kaball;
28         }
29
30         vector kaball_pos, kaball_size;
31
32         if(mySize.x > mySize.y) {
33                 kaball_pos = pos + eX * 0.25 * mySize.x;
34                 kaball_size = vec2(0.5 * mySize.x, mySize.y);
35         } else {
36                 kaball_pos = pos + eY * 0.25 * mySize.y;
37                 kaball_size = vec2(mySize.x, 0.5 * mySize.y);
38         }
39
40         float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
41         float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
42
43         if(kaball_prevstatus && f < 1)
44                 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
45
46         if(kaball)
47                 drawpic_aspect_skin(pos, "keepawayball_carrying", vec2(mySize.x, mySize.y), '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
48 }