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