]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/cl_vehicles.qc
b2f87821eea414ca4b6eb764663571d4d1826c4c
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / cl_vehicles.qc
1 #include "cl_vehicles.qh"
2 const string vCROSS_BURST = "gfx/vehicles/crosshair_burst.tga";
3 const string vCROSS_DROP  = "gfx/vehicles/crosshair_drop.tga";
4 const string vCROSS_GUIDE = "gfx/vehicles/crosshair_guide.tga";
5 const string vCROSS_HEAL  = "gfx/vehicles/crosshair_heal.tga";
6 const string vCROSS_HINT  = "gfx/vehicles/crosshair_hint.tga";
7 const string vCROSS_LOCK  = "gfx/vehicles/crosshair_lock.tga";
8 const string vCROSS_RAIN  = "gfx/vehicles/crosshair_rain.tga";
9
10 entity dropmark;
11
12 const int MAX_AXH = 4;
13 entity AuxiliaryXhair[MAX_AXH];
14
15 .string axh_image;
16 .float  axh_fadetime;
17 .int    axh_drawflag;
18
19 float alarm1time;
20 float alarm2time;
21
22 void vehicle_alarm(entity e, int ch, Sound s0und)
23 {
24     TC(Sound, s0und);
25         if(!autocvar_cl_vehicles_alarm)
26                 return;
27
28         sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE);
29 }
30
31 void AuxiliaryXhair_Draw2D(entity this)
32 {
33         if (scoreboard_active)
34                 return;
35
36         vector pos = project_3d_to_2d(this.origin);
37
38         if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight))
39         {
40                 vector size = draw_getimagesize(this.axh_image) * autocvar_cl_vehicles_crosshair_size;
41                 pos.x -= 0.5 * size.x;
42                 pos.y -= 0.5 * size.y;
43                 pos.z = 0;
44                 drawpic(pos, this.axh_image, size, this.colormod, autocvar_crosshair_alpha * this.alpha, this.axh_drawflag);
45         }
46
47         if(time - this.cnt > this.axh_fadetime)
48                 this.draw2d = func_null;
49 }
50
51 NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew)
52 {
53         int sf = ReadByte();
54
55         int axh_id      = bound(0, ReadByte(), MAX_AXH);
56         entity axh = AuxiliaryXhair[axh_id];
57
58         if(axh == NULL || wasfreed(axh))
59         {
60                 axh                                     = new(auxiliary_crosshair);
61                 axh.draw2d                      = func_null;
62                 axh.drawmask            = MASK_NORMAL;
63                 axh.axh_drawflag        = DRAWFLAG_ADDITIVE;
64                 axh.axh_fadetime        = 0.1;
65                 axh.axh_image           = vCROSS_HINT;
66                 axh.alpha                       = 1;
67                 AuxiliaryXhair[axh_id] = axh;
68                 IL_PUSH(g_drawables_2d, axh);
69         }
70
71         if(sf & 2)
72         {
73                 axh.origin_x = ReadCoord();
74                 axh.origin_y = ReadCoord();
75                 axh.origin_z = ReadCoord();
76         }
77
78         if(sf & 4)
79         {
80                 axh.colormod_x = ReadByte() / 255;
81                 axh.colormod_y = ReadByte() / 255;
82                 axh.colormod_z = ReadByte() / 255;
83         }
84
85         axh.cnt                         = time;
86         axh.draw2d                      = AuxiliaryXhair_Draw2D;
87         return true;
88 }
89
90 NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew)
91 {
92         int hud_id = ReadByte();
93         return = true;
94
95         // hud_id == 0 means we exited a vehicle, so stop alarm sound/s
96         // note: HUD_NORMAL is set to 0 currently too, but we'll check both just in case
97         if(hud_id == 0 || hud_id == HUD_NORMAL)
98         {
99                 sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
100                 sound(this, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
101
102                 for(int i = 0; i < MAX_AXH; ++i)
103                 {
104                         entity axh = AuxiliaryXhair[i];
105
106                         if(axh != NULL && !wasfreed(axh))
107                         {
108                                 AuxiliaryXhair[i] = NULL;
109                                 delete(axh);
110                         }
111                 }
112                 return;
113         }
114
115         // Init auxiliary crosshairs
116         for(int i = 0; i < MAX_AXH; ++i)
117         {
118                 entity axh = AuxiliaryXhair[i];
119
120                 if(axh != NULL && !wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
121                         delete(axh);
122
123                 axh              = spawn();
124                 axh.draw2d       = func_null;
125                 axh.drawmask     = MASK_NORMAL;
126                 axh.axh_drawflag = DRAWFLAG_NORMAL;
127                 axh.axh_fadetime = 0.1;
128                 axh.axh_image    = vCROSS_HINT;
129                 axh.alpha        = 1;
130                 AuxiliaryXhair[i] = axh;
131                 IL_PUSH(g_drawables_2d, axh);
132         }
133
134         if(hud_id == HUD_BUMBLEBEE_GUN)
135         {
136                 AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons
137                 AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun
138         } else {
139                 Vehicle info = Vehicles_from(hud_id);
140         info.vr_setup(info, NULL);
141         }
142 }
143
144 void Vehicles_drawHUD(
145         string vehicle,
146         string vehicleWeapon1,
147         string vehicleWeapon2,
148         string iconAmmo1,
149         vector colorAmmo1,
150         string iconAmmo2,
151         vector colorAmmo2)
152 {
153         // Initialize
154         vector tmpSize = '0 0 0';
155         vector tmpPos  = '0 0 0';
156
157         float hudAlpha = autocvar_hud_panel_fg_alpha * hud_fade_alpha;
158         float barAlpha = autocvar_hud_progressbar_alpha * hudAlpha;
159         float blinkValue = 0.55 + sin(time * 7) * 0.45;
160
161         float health  = STAT(VEHICLESTAT_HEALTH)  * 0.01;
162         float shield  = STAT(VEHICLESTAT_SHIELD)  * 0.01;
163         float energy  = STAT(VEHICLESTAT_ENERGY)  * 0.01;
164         float ammo1   = STAT(VEHICLESTAT_AMMO1)   * 0.01;
165         float reload1 = STAT(VEHICLESTAT_RELOAD1) * 0.01;
166         float ammo2   = STAT(VEHICLESTAT_AMMO2)   * 0.01;
167         float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01;
168
169         // HACK to deal with the inconsistent use of the vehicle stats
170         ammo1 = (ammo1) ? ammo1 : energy;
171
172         // Frame
173         string frame = strcat(hud_skin_path, "/vehicle_frame");
174         if (precache_pic(frame) == "")
175                 frame = "gfx/hud/default/vehicle_frame";
176
177         vehicleHud_Size  = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale;
178         vehicleHud_Pos.x = (vid_conwidth - vehicleHud_Size.x) / 2;
179         vehicleHud_Pos.y = vid_conheight - vehicleHud_Size.y;
180
181         if(teamplay && autocvar_hud_panel_bg_color_team)
182                 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, myteamcolors * autocvar_hud_panel_bg_color_team, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
183         else
184                 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
185
186         if(!autocvar__vehicles_shownchasemessage && time < vh_notice_time)
187         {
188                 float tmpblinkValue = 0.55 + sin(time * 3) * 0.45;
189                 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (96/256) - tmpSize.x;
190                 tmpPos.y = vehicleHud_Pos.y;
191                 tmpSize = '1 1 1' * hud_fontsize;
192                 drawstring(tmpPos, sprintf(_("Press %s"), getcommandkey(_("drop weapon"), "dropweapon")), tmpSize, '1 0 0' + '0 1 1' * tmpblinkValue, hudAlpha, DRAWFLAG_NORMAL);
193         }
194
195         // Model
196         tmpSize.x = vehicleHud_Size.x / 3;
197         tmpSize.y = vehicleHud_Size.y;
198         tmpPos.x  = vehicleHud_Pos.x + vehicleHud_Size.x / 3;
199         tmpPos.y  = vehicleHud_Pos.y;
200
201         if(health < 0.25)
202                 drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL);
203         else
204                 drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health  + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL);
205
206         if(vehicleWeapon1)
207                 drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL);
208         if(vehicleWeapon2)
209                 drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL);
210
211         drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL);
212
213         // Health bar
214         tmpSize.y = vehicleHud_Size.y / 2;
215         tmpPos.x  = vehicleHud_Pos.x + vehicleHud_Size.x * (32/768);
216         tmpPos.y  = vehicleHud_Pos.y;
217
218         drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y);
219         drawpic_skin(tmpPos, "vehicle_bar_northwest", tmpSize, autocvar_hud_progressbar_health_color, barAlpha, DRAWFLAG_NORMAL);
220
221         // Shield bar
222         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
223
224         drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - shield)), tmpPos.y, tmpSize.x, tmpSize.y);
225         drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL);
226
227         // Ammo1 bar
228         tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480/768);
229         tmpPos.y = vehicleHud_Pos.y;
230
231         if(ammo1)
232                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y);
233         else
234                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y);
235
236         drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL);
237
238         // Ammo2 bar
239         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
240
241         if(ammo2)
242                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y);
243         else
244                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y);
245
246         drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL);
247         drawresetcliparea();
248
249         // Health icon
250         tmpSize.x = vehicleHud_Size.x * (80/768);
251         tmpSize.y = vehicleHud_Size.y * (80/256);
252         tmpPos.x  = vehicleHud_Pos.x + vehicleHud_Size.x * (64/768);
253         tmpPos.y  = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
254
255         if(health < 0.25)
256         {
257                 if(alarm1time < time)
258                 {
259                         alarm1time = time + 2;
260                         vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_VEH_ALARM);
261                 }
262                 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
263         }
264         else
265         {
266                 if(alarm1time)
267                 {
268                         vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_Null);
269                         alarm1time = 0;
270                 }
271                 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
272         }
273
274         // Shield icon
275         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
276
277         if(shield < 0.25)
278         {
279                 if(alarm2time < time)
280                 {
281                         alarm2time = time + 1;
282                         vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_VEH_ALARM_SHIELD);
283                 }
284                 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
285         }
286         else
287         {
288                 if(alarm2time)
289                 {
290                         vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_Null);
291                         alarm2time = 0;
292                 }
293                 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
294         }
295
296         // Ammo1 icon
297         tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624/768);
298         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
299
300         if(iconAmmo1)
301         {
302                 if(ammo1)
303                         drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
304                 else
305                         drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
306         }
307
308         // Ammo2 icon
309         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
310
311         if(iconAmmo2)
312         {
313                 if(ammo2)
314                         drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
315                 else
316                         drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
317         }
318 }
319
320 void Vehicles_drawCrosshair(string crosshair)
321 {
322         vector tmpSize = '0 0 0';
323         vector tmpPos  = '0 0 0';
324
325         // Crosshair
326         if(crosshair)
327         {
328                 tmpSize  = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size;
329                 tmpPos.x = (vid_conwidth - tmpSize.x) / 2;
330                 tmpPos.y = (vid_conheight - tmpSize.y) / 2;
331
332                 vector wcross_color = '1 1 1';
333                 if(autocvar_cl_vehicles_crosshair_colorize)
334                         wcross_color = crosshair_getcolor(NULL, STAT(VEHICLESTAT_HEALTH));
335
336                 drawpic(tmpPos, crosshair, tmpSize, wcross_color, autocvar_crosshair_alpha, DRAWFLAG_NORMAL);
337         }
338 }