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