]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/controlpoint.qc
Reduce spam of "x minutes" and "x fps" strings of a few sliders
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / controlpoint.qc
1 #include "controlpoint.qh"
2 #include "gibs.qh"
3 #include "teamradar.qh"
4 #include "../common/movetypes/movetypes.qh"
5
6 .float alpha;
7 bool cpicon_precached;
8 .int count;
9 .float pain_finished;
10
11 .bool iscaptured;
12
13 .vector cp_origin, cp_bob_origin;
14 .float cp_bob_spd;
15
16 .vector cp_bob_dmg;
17
18 .vector punchangle;
19
20 .float max_health;
21
22 .entity icon_realmodel;
23
24 void cpicon_precache()
25 {
26         if(cpicon_precached)
27                 return; // already precached
28
29         cpicon_precached = true;
30 }
31
32 void cpicon_draw()
33 {SELFPARAM();
34         if(time < self.move_time) { return; }
35
36         if(self.cp_bob_dmg_z > 0)
37                 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 3 * frametime;
38         else
39                 self.cp_bob_dmg_z = 0;
40         self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd));
41         self.cp_bob_spd = self.cp_bob_spd + 1.875 * frametime;
42         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
43
44         if(!self.iscaptured) self.alpha = self.health / self.max_health;
45
46         if(self.iscaptured)
47         {
48                 if (self.punchangle_x > 0)
49                 {
50                         self.punchangle_x = self.punchangle_x - 60 * frametime;
51                         if (self.punchangle_x < 0)
52                                 self.punchangle_x = 0;
53                 }
54                 else if (self.punchangle_x < 0)
55                 {
56                         self.punchangle_x = self.punchangle_x + 60 * frametime;
57                         if (self.punchangle_x > 0)
58                                 self.punchangle_x = 0;
59                 }
60
61                 if (self.punchangle_y > 0)
62                 {
63                         self.punchangle_y = self.punchangle_y - 60 * frametime;
64                         if (self.punchangle_y < 0)
65                                 self.punchangle_y = 0;
66                 }
67                 else if (self.punchangle_y < 0)
68                 {
69                         self.punchangle_y = self.punchangle_y + 60 * frametime;
70                         if (self.punchangle_y > 0)
71                                 self.punchangle_y = 0;
72                 }
73
74                 if (self.punchangle_z > 0)
75                 {
76                         self.punchangle_z = self.punchangle_z - 60 * frametime;
77                         if (self.punchangle_z < 0)
78                                 self.punchangle_z = 0;
79                 }
80                 else if (self.punchangle_z < 0)
81                 {
82                         self.punchangle_z = self.punchangle_z + 60 * frametime;
83                         if (self.punchangle_z > 0)
84                                 self.punchangle_z = 0;
85                 }
86
87                 self.angles_x = self.punchangle_x;
88                 self.angles_y = self.punchangle_y + self.move_angles_y;
89                 self.angles_z = self.punchangle_z;
90                 self.move_angles_y = self.move_angles_y + 45 * frametime;
91         }
92
93         setorigin(self, self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg);
94 }
95
96 void cpicon_damage(float hp)
97 {SELFPARAM();
98         if(!self.iscaptured) { return; }
99
100         if(hp < self.max_health * 0.25)
101                 setmodel(self, MDL_ONS_CP3);
102         else if(hp < self.max_health * 0.50)
103                 setmodel(self, MDL_ONS_CP2);
104         else if(hp < self.max_health * 0.75)
105                 setmodel(self, MDL_ONS_CP1);
106         else if(hp <= self.max_health || hp >= self.max_health)
107                 setmodel(self, MDL_ONS_CP);
108
109         self.punchangle = (2 * randomvec() - '1 1 1') * 45;
110
111         self.cp_bob_dmg_z = (2 * random() - 1) * 15;
112         self.pain_finished = time + 1;
113         self.colormod = '2 2 2';
114
115         setsize(self, CPICON_MIN, CPICON_MAX);
116 }
117
118 void cpicon_construct()
119 {SELFPARAM();
120         self.netname = "Control Point Icon";
121
122         setmodel(self, MDL_ONS_CP);
123         setsize(self, CPICON_MIN, CPICON_MAX);
124
125         if(self.icon_realmodel == world)
126         {
127                 self.icon_realmodel = spawn();
128                 setmodel(self.icon_realmodel, MDL_Null);
129                 setorigin(self.icon_realmodel, self.origin);
130                 setsize(self.icon_realmodel, CPICON_MIN, CPICON_MAX);
131                 self.icon_realmodel.movetype = MOVETYPE_NOCLIP;
132                 self.icon_realmodel.solid = SOLID_NOT;
133                 self.icon_realmodel.move_origin = self.icon_realmodel.origin;
134         }
135
136         if(self.iscaptured) { self.icon_realmodel.solid = SOLID_BBOX; }
137
138         self.move_movetype      = MOVETYPE_NOCLIP;
139         self.solid                      = SOLID_NOT;
140         self.movetype           = MOVETYPE_NOCLIP;
141         self.move_origin        = self.origin;
142         self.move_time          = time;
143         self.drawmask           = MASK_NORMAL;
144         self.alpha                      = 1;
145         self.draw                       = cpicon_draw;
146         self.cp_origin          = self.origin;
147         self.cp_bob_origin      = '0 0 0.1';
148         self.cp_bob_spd         = 0;
149 }
150
151 .vector glowmod;
152 void cpicon_changeteam()
153 {SELFPARAM();
154         if(self.team)
155         {
156                 self.glowmod = Team_ColorRGB(self.team - 1);
157                 self.teamradar_color = Team_ColorRGB(self.team - 1);
158                 self.colormap = 1024 + (self.team - 1) * 17;
159         }
160         else
161         {
162                 self.colormap = 1024;
163                 self.glowmod = '1 1 0';
164                 self.teamradar_color = '1 1 0';
165         }
166 }
167
168 void ent_cpicon()
169 {SELFPARAM();
170         int sf = ReadByte();
171
172         if(sf & CPSF_SETUP)
173         {
174                 self.origin_x = ReadCoord();
175                 self.origin_y = ReadCoord();
176                 self.origin_z = ReadCoord();
177                 setorigin(self, self.origin);
178
179                 self.health = ReadByte();
180                 self.max_health = ReadByte();
181                 self.count = ReadByte();
182                 self.team = ReadByte();
183                 self.iscaptured = ReadByte();
184
185                 if(!self.count)
186                         self.count = (self.health - self.max_health) * frametime;
187
188                 cpicon_changeteam();
189                 cpicon_precache();
190                 cpicon_construct();
191         }
192
193         if(sf & CPSF_STATUS)
194         {
195                 int _tmp = ReadByte();
196                 if(_tmp != self.team)
197                 {
198                         self.team = _tmp;
199                         cpicon_changeteam();
200                 }
201
202                 _tmp = ReadByte();
203
204                 if(_tmp != self.health)
205                         cpicon_damage(_tmp);
206
207                 self.health = _tmp;
208         }
209 }