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