]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/cl_vehicles.qc
Merge branch 'master' into Mario/vehicles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / cl_vehicles.qc
1 #define hud_bg "gfx/vehicles/frame.tga"
2 #define hud_sh "gfx/vehicles/vh-shield.tga"
3
4 #define hud_hp_bar "gfx/vehicles/bar_up_left.tga"
5 #define hud_hp_ico "gfx/vehicles/health.tga"
6 #define hud_sh_bar "gfx/vehicles/bar_dwn_left.tga"
7 #define hud_sh_ico "gfx/vehicles/shield.tga"
8
9 #define hud_ammo1_bar "gfx/vehicles/bar_up_right.tga"
10 #define hud_ammo1_ico "gfx/vehicles/bullets.tga"
11 #define hud_ammo2_bar "gfx/vehicles/bar_dwn_right.tga"
12 #define hud_ammo2_ico "gfx/vehicles/rocket.tga"
13 #define hud_energy "gfx/vehicles/energy.tga"
14
15 entity dropmark;
16 var float autocvar_cl_vehicles_hudscale = 0.5;
17 var float autocvar_cl_vehicles_hudalpha = 0.75;
18
19 void CSQC_BUMBLE_GUN_HUD();
20
21 const float MAX_AXH = 4;
22 entity AuxiliaryXhair[MAX_AXH];
23
24 .string axh_image;
25 .float  axh_fadetime;
26 .float  axh_drawflag;
27 .float  axh_scale;
28
29 #define bumb_ico  "gfx/vehicles/bumb.tga"
30 #define bumb_lgun  "gfx/vehicles/bumb_lgun.tga"
31 #define bumb_rgun  "gfx/vehicles/bumb_rgun.tga"
32
33 #define bumb_gun_ico  "gfx/vehicles/bumb_side.tga"
34 #define bumb_gun_gun  "gfx/vehicles/bumb_side_gun.tga"
35
36 float alarm1time;
37 float alarm2time;
38
39 void vehicle_alarm(entity e, float ch, string s0und)
40 {
41         if(!autocvar_cl_vehicles_alarm)
42                 return;
43
44         sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE);
45 }
46
47 void AuxiliaryXhair_Draw2D()
48 {
49         vector loc, psize;
50
51         psize = self.axh_scale * draw_getimagesize(self.axh_image);
52         loc = project_3d_to_2d(self.move_origin) - 0.5 * psize;
53         if(!(loc_z < 0 || loc_x < 0 || loc_y < 0 || loc_x > vid_conwidth || loc_y > vid_conheight))
54         {
55                 loc_z = 0;
56                 psize_z = 0;
57                 drawpic(loc, self.axh_image, psize, self.colormod, self.alpha, self.axh_drawflag);
58         }
59
60         if(time - self.cnt > self.axh_fadetime)
61                 self.draw2d = func_null;
62 }
63
64 void Net_AuXair2(float bIsNew)
65 {
66         float axh_id    = bound(0, ReadByte(), MAX_AXH);
67         entity axh              = AuxiliaryXhair[axh_id];
68
69         if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
70         {
71                 axh                                     = spawn();
72                 axh.draw2d                      = func_null;
73                 axh.drawmask            = MASK_NORMAL;
74                 axh.axh_drawflag        = DRAWFLAG_ADDITIVE;
75                 axh.axh_fadetime        = 0.1;
76                 axh.axh_image           = "gfx/vehicles/axh-ring.tga";
77                 axh.axh_scale           = 1;
78                 axh.alpha                       = 1;
79                 AuxiliaryXhair[axh_id] = axh;
80         }
81
82         axh.move_origin_x       = ReadCoord();
83         axh.move_origin_y       = ReadCoord();
84         axh.move_origin_z       = ReadCoord();
85         axh.colormod_x          = ReadByte() / 255;
86         axh.colormod_y          = ReadByte() / 255;
87         axh.colormod_z          = ReadByte() / 255;
88         axh.cnt                         = time;
89         axh.draw2d                      = AuxiliaryXhair_Draw2D;
90 }
91
92 void Net_VehicleSetup()
93 {
94         float i;
95
96         float hud_id = ReadByte();
97
98         // hud_id == 0 means we exited a vehicle, so stop alarm sound/s
99         if(hud_id == 0)
100         {
101                 sound(self, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_BASEVOICE, ATTEN_NONE);
102                 sound(self, CH_PAIN_SINGLE, "misc/null.wav", VOL_BASEVOICE, ATTEN_NONE);
103                 return;
104         }
105
106         // Init auxiliary crosshairs
107         entity axh;
108         for(i = 0; i < MAX_AXH; ++i)
109         {
110                 axh = AuxiliaryXhair[i];
111                 if(axh != world && !wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
112                         remove(axh);
113
114                 axh                                     = spawn();
115                 axh.draw2d                      = func_null;
116                 axh.drawmask            = MASK_NORMAL;
117                 axh.axh_drawflag        = DRAWFLAG_NORMAL;
118                 axh.axh_fadetime        = 0.1;
119                 axh.axh_image           = "gfx/vehicles/axh-ring.tga";
120                 axh.axh_scale           = 1;
121                 axh.alpha                       = 1;
122                 AuxiliaryXhair[i]       = axh;
123         }
124
125         VEH_ACTION(hud_id, VR_SETUP);
126
127         if(hud_id == HUD_BUMBLEBEE_GUN)
128         {
129                 // Plasma cannons
130                 AuxiliaryXhair[0].axh_image   = "gfx/vehicles/axh-bracket.tga";
131                 AuxiliaryXhair[0].axh_scale   = 0.25;
132                 // Raygun
133                 AuxiliaryXhair[1].axh_image   = "gfx/vehicles/axh-bracket.tga";
134                 AuxiliaryXhair[1].axh_scale   = 0.25;
135         }
136 }
137
138 void CSQC_BUMBLE_GUN_HUD()
139 {
140
141         if(autocvar_r_letterbox)
142                 return;
143
144         vector picsize, hudloc = '0 0 0', pic2size, picloc;
145
146         // Fetch health & ammo stats
147         HUD_GETVEHICLESTATS
148
149         picsize = draw_getimagesize(hud_bg) * autocvar_cl_vehicles_hudscale;
150         hudloc_y = vid_conheight - picsize_y;
151         hudloc_x = vid_conwidth * 0.5 - picsize_x * 0.5;
152
153         drawpic(hudloc, hud_bg, picsize, '1 1 1', autocvar_cl_vehicles_hudalpha, DRAWFLAG_NORMAL);
154
155         shield  *= 0.01;
156         vh_health  *= 0.01;
157         energy  *= 0.01;
158         reload1 *= 0.01;
159
160         pic2size = draw_getimagesize(bumb_gun_ico) * (autocvar_cl_vehicles_hudscale * 0.8);
161         picloc = picsize * 0.5 - pic2size * 0.5;
162
163         if(vh_health < 0.25)
164                 drawpic(hudloc + picloc, bumb_gun_ico, pic2size,  '1 0 0' + '0 1 1' * sin(time * 8),  1, DRAWFLAG_NORMAL);
165         else
166                 drawpic(hudloc + picloc, bumb_gun_ico, pic2size,  '1 1 1' * vh_health  + '1 0 0' * (1 - vh_health),  1, DRAWFLAG_NORMAL);
167
168         drawpic(hudloc + picloc, bumb_gun_gun, pic2size, '1 1 1' * energy   + '1 0 0' * (1 - energy),   1, DRAWFLAG_NORMAL);
169         drawpic(hudloc + picloc, hud_sh, pic2size,  '1 1 1', shield, DRAWFLAG_NORMAL);
170
171 // Health bar
172         picsize = draw_getimagesize(hud_hp_bar) * autocvar_cl_vehicles_hudscale;
173         picloc = '69 69 0' * autocvar_cl_vehicles_hudscale;
174         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - vh_health)), 0, vid_conwidth, vid_conheight);
175         drawpic(hudloc + picloc, hud_hp_bar, picsize, '1 1 1', 1 , DRAWFLAG_NORMAL);
176         drawresetcliparea();
177 // ..  and icon
178         picsize = draw_getimagesize(hud_hp_ico) * autocvar_cl_vehicles_hudscale;
179         picloc = '37 65 0' * autocvar_cl_vehicles_hudscale;
180         if(vh_health < 0.25)
181         {
182                 if(alarm1time < time)
183                 {
184                         alarm1time = time + 2;
185                         vehicle_alarm(self, CH_PAIN_SINGLE, "vehicles/alarm.wav");
186                 }
187
188                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
189         }
190         else
191         {
192                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
193                 if(alarm1time)
194                 {
195                         vehicle_alarm(self, CH_PAIN_SINGLE, "misc/null.wav");
196                         alarm1time = 0;
197                 }
198         }
199
200 // Shield bar
201         picsize = draw_getimagesize(hud_sh_bar) * autocvar_cl_vehicles_hudscale;
202         picloc = '69 140 0' * autocvar_cl_vehicles_hudscale;
203         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - shield)), 0, vid_conwidth, vid_conheight);
204         drawpic(hudloc + picloc, hud_sh_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
205         drawresetcliparea();
206 // ..  and icon
207         picloc = '40 136 0' * autocvar_cl_vehicles_hudscale;
208         picsize = draw_getimagesize(hud_sh_ico) * autocvar_cl_vehicles_hudscale;
209         if(shield < 0.25)
210         {
211                 if(alarm2time < time)
212                 {
213                         alarm2time = time + 1;
214                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "vehicles/alarm_shield.wav");
215                 }
216                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
217         }
218         else
219         {
220                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
221                 if(alarm2time)
222                 {
223                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "misc/null.wav");
224                         alarm2time = 0;
225                 }
226         }
227
228 // Gun bar
229         picsize = draw_getimagesize(hud_ammo1_bar) * autocvar_cl_vehicles_hudscale;
230         picloc = '450 69 0' * autocvar_cl_vehicles_hudscale;
231         drawsetcliparea(hudloc_x + picloc_x, picloc_y, picsize_x * energy, vid_conheight);
232         drawpic(hudloc + picloc, hud_ammo1_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
233         drawresetcliparea();
234
235 // ..  and icon
236         picsize = 1.5 * draw_getimagesize(hud_energy) * autocvar_cl_vehicles_hudscale;
237         picloc = '664 60 0' * autocvar_cl_vehicles_hudscale;
238         if(energy < 0.2)
239                 drawpic(hudloc + picloc, hud_energy, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
240         else
241                 drawpic(hudloc + picloc, hud_energy, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
242
243         if (scoreboard_showscores)
244                 HUD_DrawScoreboard();
245         /*
246         else
247         {
248                 picsize = draw_getimagesize(waki_xhair);
249                 picsize_x *= 0.5;
250                 picsize_y *= 0.5;
251
252
253                 drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), waki_xhair, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
254         }
255         */
256 }
257
258 void RaptorCBShellfragDraw()
259 {
260         if(wasfreed(self))
261                 return;
262
263         Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
264         self.move_avelocity += randomvec() * 15;
265         self.renderflags = 0;
266
267         if(self.cnt < time)
268                 self.alpha = bound(0, self.nextthink - time, 1);
269
270         if(self.alpha < ALPHA_MIN_VISIBLE)
271                 remove(self);
272 }
273
274 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
275 {
276         entity sfrag;
277
278         sfrag = spawn();
279         setmodel(sfrag, "models/vehicles/clusterbomb_fragment.md3");
280         setorigin(sfrag, _org);
281
282         sfrag.move_movetype = MOVETYPE_BOUNCE;
283         sfrag.gravity = 0.15;
284         sfrag.solid = SOLID_CORPSE;
285
286         sfrag.draw = RaptorCBShellfragDraw;
287
288         sfrag.move_origin = sfrag.origin = _org;
289         sfrag.move_velocity = _vel;
290         sfrag.move_avelocity = prandomvec() * vlen(sfrag.move_velocity);
291         sfrag.angles = self.move_angles = _ang;
292
293         sfrag.move_time = time;
294         sfrag.damageforcescale = 4;
295
296         sfrag.nextthink = time + 3;
297         sfrag.cnt = time + 2;
298         sfrag.alpha = 1;
299         sfrag.drawmask = MASK_NORMAL;
300 }