]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/cl_vehicles.qc
Merge branch 'terencehill/radiobutton_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / cl_vehicles.qc
1 const string vCROSS_BURST = "gfx/vehicles/crosshair_burst.tga";
2 const string vCROSS_DROP  = "gfx/vehicles/crosshair_drop.tga";
3 const string vCROSS_GUIDE = "gfx/vehicles/crosshair_guide.tga";
4 const string vCROSS_HEAL  = "gfx/vehicles/crosshair_heal.tga";
5 const string vCROSS_HINT  = "gfx/vehicles/crosshair_hint.tga";
6 const string vCROSS_LOCK  = "gfx/vehicles/crosshair_lock.tga";
7 const string vCROSS_RAIN  = "gfx/vehicles/crosshair_rain.tga";
8
9 entity dropmark;
10
11 const int MAX_AXH = 4;
12 entity AuxiliaryXhair[MAX_AXH];
13
14 .string axh_image;
15 .float  axh_fadetime;
16 .int    axh_drawflag;
17
18 float alarm1time;
19 float alarm2time;
20
21 void vehicle_alarm(entity e, int ch, string s0und)
22 {
23         if(!autocvar_cl_vehicles_alarm)
24                 return;
25
26         _sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE);
27 }
28
29 void AuxiliaryXhair_Draw2D()
30 {SELFPARAM();
31         if (scoreboard_showscores)
32                 return;
33
34         vector size = draw_getimagesize(self.axh_image) * autocvar_cl_vehicles_crosshair_size;
35         vector pos = project_3d_to_2d(self.move_origin) - 0.5 * size;
36
37         if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight))
38         {
39                 pos.z = 0;
40                 size.z = 0;
41                 drawpic(pos, self.axh_image, size, self.colormod, autocvar_crosshair_alpha * self.alpha, self.axh_drawflag);
42         }
43
44         if(time - self.cnt > self.axh_fadetime)
45                 self.draw2d = func_null;
46 }
47
48 void Net_AuXair2(bool bIsNew)
49 {
50         int axh_id      = bound(0, ReadByte(), MAX_AXH);
51         entity axh              = AuxiliaryXhair[axh_id];
52
53         if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
54         {
55                 axh                                     = spawn();
56                 axh.draw2d                      = func_null;
57                 axh.drawmask            = MASK_NORMAL;
58                 axh.axh_drawflag        = DRAWFLAG_ADDITIVE;
59                 axh.axh_fadetime        = 0.1;
60                 axh.axh_image           = vCROSS_HINT;
61                 axh.alpha                       = 1;
62                 AuxiliaryXhair[axh_id] = axh;
63         }
64
65         axh.move_origin_x       = ReadCoord();
66         axh.move_origin_y       = ReadCoord();
67         axh.move_origin_z       = ReadCoord();
68         axh.colormod_x          = ReadByte() / 255;
69         axh.colormod_y          = ReadByte() / 255;
70         axh.colormod_z          = ReadByte() / 255;
71         axh.cnt                         = time;
72         axh.draw2d                      = AuxiliaryXhair_Draw2D;
73 }
74
75 void Net_VehicleSetup()
76 {SELFPARAM();
77         int hud_id = ReadByte();
78
79         // hud_id == 0 means we exited a vehicle, so stop alarm sound/s
80         if(hud_id == 0)
81         {
82                 sound(self, CH_TRIGGER_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
83                 sound(self, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
84                 return;
85         }
86
87         // Init auxiliary crosshairs
88         for(int i = 0; i < MAX_AXH; ++i)
89         {
90                 entity axh = AuxiliaryXhair[i];
91
92                 if(axh != world && !wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
93                         remove(axh);
94
95                 axh              = spawn();
96                 axh.draw2d       = func_null;
97                 axh.drawmask     = MASK_NORMAL;
98                 axh.axh_drawflag = DRAWFLAG_NORMAL;
99                 axh.axh_fadetime = 0.1;
100                 axh.axh_image    = vCROSS_HINT;
101                 axh.alpha        = 1;
102                 AuxiliaryXhair[i] = axh;
103         }
104
105         if(hud_id == HUD_BUMBLEBEE_GUN)
106         {
107                 AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons
108                 AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun
109         }
110         else { VEH_ACTION(hud_id, VR_SETUP); }
111 }
112
113 void Vehicles_drawHUD(
114         string vehicle,
115         string vehicleWeapon1,
116         string vehicleWeapon2,
117         string iconAmmo1,
118         vector colorAmmo1,
119         string iconAmmo2,
120         vector colorAmmo2,
121         string crosshair)
122 {SELFPARAM();
123         if(autocvar_r_letterbox)
124                 return;
125
126         if(scoreboard_showscores)
127                 return;
128
129         // Initialize
130         vector hudSize = '0 0 0';
131         vector hudPos  = '0 0 0';
132         vector tmpSize = '0 0 0';
133         vector tmpPos  = '0 0 0';
134
135         float hudAlpha = autocvar_hud_panel_fg_alpha;
136         float barAlpha = autocvar_hud_progressbar_alpha * hudAlpha;
137         float blinkValue = 0.55 + sin(time * 7) * 0.45;
138
139         float health  = getstati(STAT_VEHICLESTAT_HEALTH)  * 0.01;
140         float shield  = getstati(STAT_VEHICLESTAT_SHIELD)  * 0.01;
141         float energy  = getstati(STAT_VEHICLESTAT_ENERGY)  * 0.01;
142         float ammo1   = getstati(STAT_VEHICLESTAT_AMMO1)   * 0.01;
143         float reload1 = getstati(STAT_VEHICLESTAT_RELOAD1) * 0.01;
144         float ammo2   = getstati(STAT_VEHICLESTAT_AMMO2)   * 0.01;
145         float reload2 = getstati(STAT_VEHICLESTAT_RELOAD2) * 0.01;
146
147         // HACK to deal with the inconsistent use of the vehicle stats
148         ammo1 = (ammo1) ? ammo1 : energy;
149
150         // Frame
151         string frame = strcat(hud_skin_path, "/vehicle_frame");
152         if (precache_pic(frame) == "")
153                 frame = "gfx/hud/default/vehicle_frame";
154
155         hudSize  = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale;
156         hudPos.x = (vid_conwidth - hudSize.x) / 2;
157         hudPos.y = vid_conheight - hudSize.y;
158
159         if(teamplay && autocvar_hud_panel_bg_color_team)
160                 drawpic(hudPos, frame, hudSize, myteamcolors * autocvar_hud_panel_bg_color_team, autocvar_hud_panel_bg_alpha, DRAWFLAG_NORMAL);
161         else
162                 drawpic(hudPos, frame, hudSize, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha, DRAWFLAG_NORMAL);
163
164         if(!autocvar__vehicles_shownchasemessage && time < vh_notice_time)
165         {
166                 float tmpblinkValue = 0.55 + sin(time * 3) * 0.45;
167                 tmpPos.x = hudPos.x + hudSize.x * (96/256) - tmpSize.x;
168                 tmpPos.y = hudPos.y;
169                 tmpSize = '1 1 1' * hud_fontsize;
170                 drawstring(tmpPos, sprintf(_("Press %s"), getcommandkey("dropweapon", "dropweapon")), tmpSize, '1 0 0' + '0 1 1' * tmpblinkValue, hudAlpha, DRAWFLAG_NORMAL);
171         }
172
173         // Model
174         tmpSize.x = hudSize.x / 3;
175         tmpSize.y = hudSize.y;
176         tmpPos.x  = hudPos.x + hudSize.x / 3;
177         tmpPos.y  = hudPos.y;
178
179         if(health < 0.25)
180                 drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL);
181         else
182                 drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health  + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL);
183
184         if(vehicleWeapon1)
185                 drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL);
186         if(vehicleWeapon2)
187                 drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL);
188
189         drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL);
190
191         // Health bar
192         tmpSize.y = hudSize.y / 2;
193         tmpPos.x  = hudPos.x + hudSize.x * (32/768);
194         tmpPos.y  = hudPos.y;
195
196         drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y);
197         drawpic_skin(tmpPos, "vehicle_bar_northwest", tmpSize, autocvar_hud_progressbar_health_color, barAlpha, DRAWFLAG_NORMAL);
198
199         // Shield bar
200         tmpPos.y = hudPos.y + hudSize.y / 2;
201
202         drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - shield)), tmpPos.y, tmpSize.x, tmpSize.y);
203         drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL);
204
205         // Ammo1 bar
206         tmpPos.x = hudPos.x + hudSize.x * (480/768);
207         tmpPos.y = hudPos.y;
208
209         if(ammo1)
210                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y);
211         else
212                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y);
213
214         drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL);
215
216         // Ammo2 bar
217         tmpPos.y = hudPos.y + hudSize.y / 2;
218
219         if(ammo2)
220                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y);
221         else
222                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y);
223
224         drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL);
225         drawresetcliparea();
226
227         // Health icon
228         tmpSize.x = hudSize.x * (80/768);
229         tmpSize.y = hudSize.y * (80/256);
230         tmpPos.x  = hudPos.x + hudSize.x * (64/768);
231         tmpPos.y  = hudPos.y + hudSize.y * (48/256);
232
233         if(health < 0.25)
234         {
235                 if(alarm1time < time)
236                 {
237                         alarm1time = time + 2;
238                         vehicle_alarm(self, CH_PAIN_SINGLE, SND(VEH_ALARM));
239                 }
240                 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
241         }
242         else
243         {
244                 if(alarm1time)
245                 {
246                         vehicle_alarm(self, CH_PAIN_SINGLE, SND(Null));
247                         alarm1time = 0;
248                 }
249                 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
250         }
251
252         // Shield icon
253         tmpPos.y = hudPos.y + hudSize.y / 2;
254
255         if(shield < 0.25)
256         {
257                 if(alarm2time < time)
258                 {
259                         alarm2time = time + 1;
260                         vehicle_alarm(self, CH_TRIGGER_SINGLE, SND(VEH_ALARM_SHIELD));
261                 }
262                 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
263         }
264         else
265         {
266                 if(alarm2time)
267                 {
268                         vehicle_alarm(self, CH_TRIGGER_SINGLE, SND(Null));
269                         alarm2time = 0;
270                 }
271                 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
272         }
273
274         // Ammo1 icon
275         tmpPos.x = hudPos.x + hudSize.x * (624/768);
276         tmpPos.y = hudPos.y + hudSize.y * (48/256);
277
278         if(iconAmmo1)
279         {
280                 if(ammo1)
281                         drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
282                 else
283                         drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
284         }
285
286         // Ammo2 icon
287         tmpPos.y = hudPos.y + hudSize.y / 2;
288
289         if(iconAmmo2)
290         {
291                 if(ammo2)
292                         drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
293                 else
294                         drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
295         }
296
297         // Bumblebee gunner crosshairs
298         if(hud == VEH_BUMBLEBEE.vehicleid)
299         {
300                 tmpSize = '1 1 1' * hud_fontsize;
301                 tmpPos.x = hudPos.x + hudSize.x * (520/768);
302
303                 if(!AuxiliaryXhair[1].draw2d)
304                 {
305                         tmpPos.y = hudPos.y + hudSize.y * (96/256) - tmpSize.y;
306                         drawstring(tmpPos, _("No right gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
307                 }
308
309                 if(!AuxiliaryXhair[2].draw2d)
310                 {
311                         tmpPos.y = hudPos.y + hudSize.y * (160/256);
312                         drawstring(tmpPos, _("No left gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
313                 }
314         }
315
316         // Raptor bomb crosshair
317         if(hud == VEH_RAPTOR.vehicleid && weapon2mode != RSM_FLARE)
318         {
319                 vector where;
320
321                 if(!dropmark)
322                 {
323                         dropmark = spawn();
324                         dropmark.owner = self;
325                         dropmark.gravity = 1;
326                 }
327
328                 if(reload2 == 1)
329                 {
330                         setorigin(dropmark, pmove_org);
331                         dropmark.velocity = pmove_vel;
332                         tracetoss(dropmark, self);
333
334                         where = project_3d_to_2d(trace_endpos);
335
336                         setorigin(dropmark, trace_endpos);
337                         tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size;
338
339                         if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
340                         {
341                                 where.x -= tmpSize.x * 0.5;
342                                 where.y -= tmpSize.y * 0.5;
343                                 where.z = 0;
344                                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
345                                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
346                         }
347                         dropmark.cnt = time + 5;
348                 }
349                 else
350                 {
351                         if(dropmark.cnt > time)
352                         {
353                                 where = project_3d_to_2d(dropmark.origin);
354                                 tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size * 1.25;
355
356                                 if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
357                                 {
358                                         where.x -= tmpSize.x * 0.5;
359                                         where.y -= tmpSize.y * 0.5;
360                                         where.z = 0;
361                                         drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
362                                         drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
363                                 }
364                         }
365                 }
366         }
367
368         // Crosshair
369         if(crosshair)
370         {
371                 tmpSize  = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size;
372                 tmpPos.x = (vid_conwidth - tmpSize.x) / 2;
373                 tmpPos.y = (vid_conheight - tmpSize.y) / 2;
374
375                 drawpic(tmpPos, crosshair, tmpSize, '1 1 1', autocvar_crosshair_alpha, DRAWFLAG_NORMAL);
376         }
377 }