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