]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/cl_vehicles.qc
Merge branch 'terencehill/hud_cleanups' 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(entity this)
30 {
31         if (scoreboard_active)
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         } else {
110                 Vehicle info = get_vehicleinfo(hud_id);
111         info.vr_setup(info);
112         }
113 }
114
115 void Vehicles_drawHUD(
116         string vehicle,
117         string vehicleWeapon1,
118         string vehicleWeapon2,
119         string iconAmmo1,
120         vector colorAmmo1,
121         string iconAmmo2,
122         vector colorAmmo2)
123 {
124         SELFPARAM();
125         // Initialize
126         vector tmpSize = '0 0 0';
127         vector tmpPos  = '0 0 0';
128
129         float hudAlpha = autocvar_hud_panel_fg_alpha * hud_fade_alpha;
130         float barAlpha = autocvar_hud_progressbar_alpha * hudAlpha;
131         float blinkValue = 0.55 + sin(time * 7) * 0.45;
132
133         float health  = getstati(STAT_VEHICLESTAT_HEALTH)  * 0.01;
134         float shield  = getstati(STAT_VEHICLESTAT_SHIELD)  * 0.01;
135         float energy  = getstati(STAT_VEHICLESTAT_ENERGY)  * 0.01;
136         float ammo1   = getstati(STAT_VEHICLESTAT_AMMO1)   * 0.01;
137         float reload1 = getstati(STAT_VEHICLESTAT_RELOAD1) * 0.01;
138         float ammo2   = getstati(STAT_VEHICLESTAT_AMMO2)   * 0.01;
139         float reload2 = getstati(STAT_VEHICLESTAT_RELOAD2) * 0.01;
140
141         // HACK to deal with the inconsistent use of the vehicle stats
142         ammo1 = (ammo1) ? ammo1 : energy;
143
144         // Frame
145         string frame = strcat(hud_skin_path, "/vehicle_frame");
146         if (precache_pic(frame) == "")
147                 frame = "gfx/hud/default/vehicle_frame";
148
149         vehicleHud_Size  = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale;
150         vehicleHud_Pos.x = (vid_conwidth - vehicleHud_Size.x) / 2;
151         vehicleHud_Pos.y = vid_conheight - vehicleHud_Size.y;
152
153         if(teamplay && autocvar_hud_panel_bg_color_team)
154                 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, myteamcolors * autocvar_hud_panel_bg_color_team, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
155         else
156                 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
157
158         if(!autocvar__vehicles_shownchasemessage && time < vh_notice_time)
159         {
160                 float tmpblinkValue = 0.55 + sin(time * 3) * 0.45;
161                 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (96/256) - tmpSize.x;
162                 tmpPos.y = vehicleHud_Pos.y;
163                 tmpSize = '1 1 1' * hud_fontsize;
164                 drawstring(tmpPos, sprintf(_("Press %s"), getcommandkey("dropweapon", "dropweapon")), tmpSize, '1 0 0' + '0 1 1' * tmpblinkValue, hudAlpha, DRAWFLAG_NORMAL);
165         }
166
167         // Model
168         tmpSize.x = vehicleHud_Size.x / 3;
169         tmpSize.y = vehicleHud_Size.y;
170         tmpPos.x  = vehicleHud_Pos.x + vehicleHud_Size.x / 3;
171         tmpPos.y  = vehicleHud_Pos.y;
172
173         if(health < 0.25)
174                 drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL);
175         else
176                 drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health  + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL);
177
178         if(vehicleWeapon1)
179                 drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL);
180         if(vehicleWeapon2)
181                 drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL);
182
183         drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL);
184
185         // Health bar
186         tmpSize.y = vehicleHud_Size.y / 2;
187         tmpPos.x  = vehicleHud_Pos.x + vehicleHud_Size.x * (32/768);
188         tmpPos.y  = vehicleHud_Pos.y;
189
190         drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y);
191         drawpic_skin(tmpPos, "vehicle_bar_northwest", tmpSize, autocvar_hud_progressbar_health_color, barAlpha, DRAWFLAG_NORMAL);
192
193         // Shield bar
194         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
195
196         drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - shield)), tmpPos.y, tmpSize.x, tmpSize.y);
197         drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL);
198
199         // Ammo1 bar
200         tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480/768);
201         tmpPos.y = vehicleHud_Pos.y;
202
203         if(ammo1)
204                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y);
205         else
206                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y);
207
208         drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL);
209
210         // Ammo2 bar
211         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
212
213         if(ammo2)
214                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y);
215         else
216                 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y);
217
218         drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL);
219         drawresetcliparea();
220
221         // Health icon
222         tmpSize.x = vehicleHud_Size.x * (80/768);
223         tmpSize.y = vehicleHud_Size.y * (80/256);
224         tmpPos.x  = vehicleHud_Pos.x + vehicleHud_Size.x * (64/768);
225         tmpPos.y  = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
226
227         if(health < 0.25)
228         {
229                 if(alarm1time < time)
230                 {
231                         alarm1time = time + 2;
232                         vehicle_alarm(self, CH_PAIN_SINGLE, SND(VEH_ALARM));
233                 }
234                 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
235         }
236         else
237         {
238                 if(alarm1time)
239                 {
240                         vehicle_alarm(self, CH_PAIN_SINGLE, SND(Null));
241                         alarm1time = 0;
242                 }
243                 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
244         }
245
246         // Shield icon
247         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
248
249         if(shield < 0.25)
250         {
251                 if(alarm2time < time)
252                 {
253                         alarm2time = time + 1;
254                         vehicle_alarm(self, CH_TRIGGER_SINGLE, SND(VEH_ALARM_SHIELD));
255                 }
256                 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
257         }
258         else
259         {
260                 if(alarm2time)
261                 {
262                         vehicle_alarm(self, CH_TRIGGER_SINGLE, SND(Null));
263                         alarm2time = 0;
264                 }
265                 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
266         }
267
268         // Ammo1 icon
269         tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624/768);
270         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
271
272         if(iconAmmo1)
273         {
274                 if(ammo1)
275                         drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
276                 else
277                         drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
278         }
279
280         // Ammo2 icon
281         tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
282
283         if(iconAmmo2)
284         {
285                 if(ammo2)
286                         drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
287                 else
288                         drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
289         }
290 }
291
292 void Vehicles_drawCrosshair(string crosshair)
293 {
294         SELFPARAM();
295         vector tmpSize = '0 0 0';
296         vector tmpPos  = '0 0 0';
297
298         // Crosshair
299         if(crosshair)
300         {
301                 tmpSize  = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size;
302                 tmpPos.x = (vid_conwidth - tmpSize.x) / 2;
303                 tmpPos.y = (vid_conheight - tmpSize.y) / 2;
304
305                 drawpic(tmpPos, crosshair, tmpSize, '1 1 1', autocvar_crosshair_alpha, DRAWFLAG_NORMAL);
306         }
307 }