]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/vehicles/vehicles.qc
1daefac011639dbd616acd8bd2fb52977834859a
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / vehicles / vehicles.qc
1 #define spider_rocket_icon "gfx/vehicles/rocket_ico.tga"
2 #define spider_rocket_targ "gfx/vehicles/target.tga"
3 //#define SPIDER_CROSS "textures/spiderbot/cross.tga"
4 #define SPIDER_CROSS "gfx/vehicles/sbot-xhair.tga"
5 #define SPIDER_CROSS2 "gfx/vehicles/sbot-xhair2.tga"
6
7 #define axh1 "gfx/vehicles/sbot-xhair2.tga"
8 #define axh2 "gfx/vehicles/sbot-xhair2.tga"
9 #define axh3 "gfx/vehicles/sbot-xhair2.tga"
10
11 #define spider_h "gfx/vehicles/hud_bg.tga"
12 #define spider_b "gfx/vehicles/sbot.tga"
13 #define spider_r "gfx/vehicles/sbot_rpods.tga"
14 #define spider_g "gfx/vehicles/sbot_mguns.tga"
15 #define spider_s "gfx/vehicles/shiled.tga"
16 #define spider_a1 "gfx/vehicles/sb_rocket.tga"
17 #define spider_a2 "gfx/vehicles/sb_bullets.tga"
18
19 #define raptor_h  "gfx/vehicles/hud_bg.tga"
20 #define raptor_s  "gfx/vehicles/shiled.tga"
21
22 #define raptor_b  "gfx/vehicles/raptor.tga"
23 #define raptor_g1 "gfx/vehicles/raptor_guns.tga"
24 #define raptor_g2 "gfx/vehicles/raptor_bombs.tga"
25 #define raptor_d  "gfx/vehicles/dropcross.tga"
26 #define raptor_c  "gfx/vehicles/raptor_cross.tga"
27
28 entity dropmark;
29
30 void CSQC_WAKIZASHI_HUD();
31 void CSQC_SPIDER_HUD();
32 void CSQC_RAPTOR_HUD();
33
34 #define MAX_AXH 4
35 entity AuxiliaryXhair[MAX_AXH];
36 const var void Draw_Not();
37
38 .string axh_image;
39 .float  axh_fadetime;
40 .float  axh_drawflag;
41 .float  axh_scale;
42
43 void AuxiliaryXhair_Draw2D()
44 {
45     vector loc, psize;
46
47     psize = self.axh_scale * drawgetimagesize(self.axh_image);
48     loc = project_3d_to_2d(self.origin) - 0.5 * psize;
49     if not (loc_z < 0 || loc_x < 0 || loc_y < 0 || loc_x > vid_conwidth || loc_y > vid_conheight)
50     {
51         loc_z = 0;
52         psize_z = 0;
53         drawpic(loc, self.axh_image, psize, self.colormod, self.alpha, self.axh_drawflag);
54     }
55
56     if(time - self.cnt > self.axh_fadetime)
57         self.draw2d = Draw_Not;
58 }
59
60 void Net_Vehicle(float IsNew)
61 {
62     //entnum
63 }
64
65 void Net_AuXair2(float bIsNew)
66 {
67     float axh_id;
68     entity axh;
69
70     axh_id = bound(0, ReadByte(), MAX_AXH);
71     axh = AuxiliaryXhair[axh_id];
72
73     if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
74     {
75         axh               = spawn();
76                 axh.draw2d        = Draw_Not;
77                 axh.drawmask      = MASK_NORMAL;
78                 axh.axh_drawflag  = DRAWFLAG_ADDITIVE;
79                 axh.axh_fadetime  = 0.1;
80                 axh.axh_image     = "gfx/vehicles/axh-ring.tga";
81                 axh.axh_scale     = 1;
82         axh.alpha         = 1;
83                 AuxiliaryXhair[axh_id] = axh;
84     }
85
86     axh.draw2d   = AuxiliaryXhair_Draw2D;
87
88         axh.origin_x = ReadCoord();
89         axh.origin_y = ReadCoord();
90         axh.origin_z = ReadCoord();
91
92         axh.colormod_x = ReadByte() / 255;
93         axh.colormod_y = ReadByte() / 255;
94         axh.colormod_z = ReadByte() / 255;
95     axh.cnt = time;
96 }
97
98
99
100 void VehicleRacerDraw()
101 {
102     Movetype_Physics_NoMatchServer();
103     self.drawmask = MASK_NORMAL;
104 }
105
106 void VehicleRacerRemove()
107 {
108 }
109
110 void Net_VehicleRacer(float bIsNew)
111 {
112     if(bIsNew)
113     {
114         setmodel(self, "models/vehicles/wakizashi.dpm");
115         self.move_movetype = MOVETYPE_BOUNCE;
116         self.entremove = VehicleRacerRemove;
117         setsize(self,  '-60 -60 -20', '60 60 20');
118         self.draw = VehicleRacerDraw;
119         self.scale = 0.5;
120     }
121
122     self.cnt = ReadByte();
123
124     self.origin_x = ReadCoord();
125     self.origin_y = ReadCoord();
126     self.origin_z = ReadCoord();
127
128     self.velocity_x = ReadCoord();
129     self.velocity_y = ReadCoord();
130     self.velocity_z = ReadCoord();
131
132     self.angles_x = ReadAngle();
133     self.angles_y = ReadAngle();
134     self.angles_z = ReadAngle();
135
136     self.move_origin    = self.origin;
137     self.move_velocity  = self.velocity;
138     self.move_angles    = self.angles;
139
140     setorigin(self, self.origin);
141 }
142
143
144
145 void Net_VehicleSetup()
146 {
147
148     float hud_id, i;
149     hud_id = bound(HUD_SPIDERBOT, ReadByte(), HUD_RAPTOR);
150
151     // Init auxiliary crosshairs
152     entity axh;
153     for(i = 0; i < MAX_AXH; ++i)
154     {
155         axh = AuxiliaryXhair[i];
156         if(axh != world && !wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
157             remove(axh);
158
159         axh               = spawn();
160                 axh.draw2d        = Draw_Not;
161                 axh.drawmask      = MASK_NORMAL;
162                 axh.axh_drawflag  = DRAWFLAG_ADDITIVE;
163                 axh.axh_fadetime  = 0.1;
164                 axh.axh_image     = "gfx/vehicles/axh-ring.tga";
165                 axh.axh_scale     = 1;
166         axh.alpha         = 1;
167                 AuxiliaryXhair[i] = axh;
168     }
169
170     switch(hud_id)
171     {
172         case HUD_SPIDERBOT:
173             // Minigun1
174             AuxiliaryXhair[0].axh_image   = "gfx/vehicles/axh-ring.tga";
175             AuxiliaryXhair[0].axh_scale   = 0.25;
176             // Minigun2
177             AuxiliaryXhair[1].axh_image   = "gfx/vehicles/axh-ring.tga";
178             AuxiliaryXhair[1].axh_scale   = 0.25;
179             // Rocket
180             AuxiliaryXhair[2].axh_image   = "gfx/vehicles/axh-special1.tga";
181             AuxiliaryXhair[2].axh_scale   = 0.5;
182             break;
183         case HUD_WAKIZASHI:
184             AuxiliaryXhair[0].axh_image   = "gfx/vehicles/axh-bracket.tga";
185             AuxiliaryXhair[0].axh_scale   = 0.25;
186             break;
187         case HUD_RAPTOR:
188             AuxiliaryXhair[0].axh_image   = "gfx/vehicles/axh-cross.tga";
189             AuxiliaryXhair[0].axh_scale   = 0.5;
190             AuxiliaryXhair[0].alpha       = 0.25;
191
192             AuxiliaryXhair[1].axh_image   = "gfx/vehicles/axh-bracket.tga";
193             AuxiliaryXhair[1].axh_scale   = 0.25;
194             AuxiliaryXhair[1].alpha       = 0.75;
195             AuxiliaryXhair[1].axh_drawflag  = DRAWFLAG_NORMAL;
196
197             break;
198     }
199 }
200 #define HUD_GETSTATS \
201     float health    = getstati(STAT_VEHICLESTAT_HEALTH); \
202         float shield    = getstati(STAT_VEHICLESTAT_SHIELD); \
203         float energy    = getstati(STAT_VEHICLESTAT_ENERGY); \
204         float ammo1     = getstati(STAT_VEHICLESTAT_AMMO1); \
205         float reload1   = getstati(STAT_VEHICLESTAT_RELOAD1); \
206         float ammo2     = getstati(STAT_VEHICLESTAT_AMMO2); \
207         float reload2   = getstati(STAT_VEHICLESTAT_RELOAD2);
208
209 void CSQC_SPIDER_HUD()
210 {
211         vector picsize, hudloc;
212
213     // Fetch health & ammo stats
214         HUD_GETSTATS
215         
216     hudloc_y = 4;
217     hudloc_x = 4;
218     
219     picsize = drawgetimagesize(spider_h) * 0.5;
220     drawpic(hudloc, spider_h, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
221
222     picsize = drawgetimagesize(spider_a2) * 0.5;
223     drawpic(hudloc + '120 96  0', spider_a2, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
224
225     drawstring(hudloc + '145 19  0', strcat(ftos(health), "%"),'15 15 0','0 1 0', 1, DRAWFLAG_NORMAL);
226     drawstring(hudloc + '175 34  0', strcat(ftos(shield), "%"),'15 15 0','0 0 1', 1, DRAWFLAG_NORMAL);
227     drawstring(hudloc + '136 102  0', strcat(ftos(ammo1), "%"),'14 14 0','1 1 0', 1, DRAWFLAG_NORMAL);
228
229     picsize = drawgetimagesize(spider_a1) * 0.85;
230     if(ammo2 == 9)
231     {
232         drawpic(hudloc + '132 54  0', spider_a1, picsize, '-1 -1 -1', 1, DRAWFLAG_NORMAL);
233         drawstring(hudloc + '179 69 0', strcat(ftos(reload2), "%"),'14 14 0','1 1 0', 1, DRAWFLAG_NORMAL);
234     }
235     else
236     {
237         drawpic(hudloc + '132 54  0', spider_a1, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
238         drawstring(hudloc + '179 69  0', strcat(ftos(9 - ammo2), " / 8"),'14 14 0','1 1 0', 1, DRAWFLAG_NORMAL);
239     }
240
241     picsize = drawgetimagesize(spider_b) * 0.5;
242     hudloc_y = 10.5;
243     hudloc_x = 10.5;
244     
245     ammo1  /= 100; 
246     shield /= 100;
247     health /= 100;
248     reload2 /= 100;
249     
250     drawpic(hudloc, spider_s, picsize, '1 1 1', shield, DRAWFLAG_NORMAL);
251     drawpic(hudloc, spider_b, picsize, '0 1 0' * health + '1 0 0' * (1 - health), 1, DRAWFLAG_NORMAL);
252     drawpic(hudloc, spider_r, picsize, '1 1 1' * reload2 + '1 0 0' * (1 - reload2), 1, DRAWFLAG_NORMAL);
253     drawpic(hudloc, spider_g, picsize, '1 1 1' * ammo1 + '1 0 0' *  (1 - ammo1), 1, DRAWFLAG_NORMAL);
254
255
256         if (scoreboard_showscores)
257         {
258                 HUD_DrawScoreboard();
259                 HUD_DrawCenterPrint();
260     }
261     else
262     {
263         picsize = drawgetimagesize(SPIDER_CROSS);
264         picsize_x *= autocvar_cl_vehicle_spiderbot_cross_size;
265         picsize_y *= autocvar_cl_vehicle_spiderbot_cross_size;
266
267         drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), SPIDER_CROSS, picsize, '1 1 1', autocvar_cl_vehicle_spiderbot_cross_alpha, DRAWFLAG_ADDITIVE);
268     }
269 }
270
271
272 void CSQC_RAPTOR_HUD()
273 {
274         if(autocvar_r_letterbox)
275         return;
276         
277         vector picsize, hudloc, vel;
278         float movedt;
279     vector where;
280
281
282     // Fetch health & ammo stats
283     HUD_GETSTATS
284     
285     // Draw the crosshairs
286     picsize = drawgetimagesize("gfx/vehicles/axh-cross.tga");
287     picsize_x *= 0.75;
288     picsize_y *= 0.75;
289     drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), "gfx/vehicles/axh-cross.tga", picsize, '1 0 0' + '0 1 1' * energy, 0.5, DRAWFLAG_ADDITIVE);
290
291     hudloc_y = 4;
292     hudloc_x = 4;
293
294     picsize = drawgetimagesize(raptor_h) * 0.5;
295     drawpic(hudloc, raptor_h, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
296
297     picsize = drawgetimagesize(spider_a2) * 0.5;
298     drawpic(hudloc + '120 96  0', spider_a2, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
299
300     drawstring(hudloc + '145 19  0', strcat(ftos(health), "%"),'15 15 0','0 1 0', 1, DRAWFLAG_NORMAL);
301     drawstring(hudloc + '175 34  0', strcat(ftos(shield), "%"),'15 15 0','0 0 1', 1, DRAWFLAG_NORMAL);
302     drawstring(hudloc + '136 102 0', strcat(ftos(energy), "%"),'15 15 0','0.5 0.5 1', 1, DRAWFLAG_NORMAL);
303
304     health /= 100;
305     shield /= 100;
306     energy /= 100;
307
308     picsize = drawgetimagesize(spider_a1) * 0.85;
309     if(reload2 == 100)
310     {
311         drawpic(hudloc + '132 54  0', spider_a1, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
312         drawstring(hudloc + '179 69  0', strcat(ftos(reload2), "%"),'14 14 0','0 1 0', 0.5, DRAWFLAG_NORMAL);
313     }
314     else
315     {
316         drawpic(hudloc + '132 54  0', spider_a1, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
317         drawstring(hudloc + '179 69  0', strcat(ftos(reload2), "%"),'14 14 0','0 0 1', 1, DRAWFLAG_NORMAL);
318     }
319
320     picsize = drawgetimagesize(raptor_b) * 0.5;
321     hudloc_y = 10.5;
322     hudloc_x = 10.5;
323     reload1 = reload2 / 100;
324     drawpic(hudloc, raptor_s, picsize, '1 1 1', shield, DRAWFLAG_NORMAL);
325     drawpic(hudloc, raptor_b, picsize, '0 1 0' * health + '1 0 0' * (1 - health), 1, DRAWFLAG_NORMAL);
326     drawpic(hudloc, raptor_g1, picsize, '1 1 1' * energy + '1 0 0' * (1 - energy), 1, DRAWFLAG_NORMAL);
327     drawpic(hudloc, raptor_g2, picsize, '1 1 1' * reload1 + '1 0 0' *  (1 - reload1), 1, DRAWFLAG_NORMAL);
328
329     if(!dropmark)
330     {
331         dropmark = spawn();
332         dropmark.owner = self;
333         dropmark.gravity = 1;
334     }
335
336     if(reload2 == 100)
337     {
338         where = dropmark.origin;
339         setorigin(dropmark, pmove_org);
340         dropmark.velocity = pmove_vel;
341         tracetoss(dropmark, self);
342
343         where = project_3d_to_2d(trace_endpos);
344
345         setorigin(dropmark, trace_endpos);
346         picsize = drawgetimagesize(raptor_d) * 0.2;
347
348         if not (where_z < 0 || where_x < 0 || where_y < 0 || where_x > vid_conwidth || where_y > vid_conheight)
349         {
350             where_x -= picsize_x * 0.5;
351             where_y -= picsize_y * 0.5;
352             where_z = 0;
353             drawpic(where, raptor_d, picsize, '0 2 0', 1, DRAWFLAG_ADDITIVE);
354         }
355         dropmark.cnt = time + 5;
356     }
357     else
358     {
359         if(dropmark.cnt > time)
360         {
361             where = project_3d_to_2d(dropmark.origin);
362             picsize = drawgetimagesize(raptor_d) * 0.25;
363
364             if not (where_z < 0 || where_x < 0 || where_y < 0 || where_x > vid_conwidth || where_y > vid_conheight)
365             {
366                 where_x -= picsize_x * 0.5;
367                 where_y -= picsize_y * 0.5;
368                 where_z = 0;
369                 drawpic(where, raptor_d, picsize, '2 0 0', 1, DRAWFLAG_ADDITIVE);
370             }
371         }
372     }
373
374         if (scoreboard_showscores)
375         {
376                 HUD_DrawScoreboard();
377                 HUD_DrawCenterPrint();
378         }
379
380 }
381
382 #define waki_h "gfx/vehicles/hud_bg.tga"
383 #define waki_b "gfx/vehicles/waki.tga"
384 #define waki_e "gfx/vehicles/waki_e.tga"
385 #define waki_g "gfx/vehicles/waki_guns.tga"
386 #define waki_r "gfx/vehicles/waki_rockets.tga"
387 #define waki_s "gfx/vehicles/shiled.tga"
388
389 #define waki_a1 "gfx/vehicles/sb_rocket.tga"
390 #define waki_a2 "gfx/vehicles/sb_cells.tga"
391
392 void CSQC_WAKIZASHI_HUD()
393 {
394         vector picsize, hudloc;
395
396     picsize = drawgetimagesize(SPIDER_CROSS);
397     picsize_x *= autocvar_cl_vehicle_spiderbot_cross_size;
398     picsize_y *= autocvar_cl_vehicle_spiderbot_cross_size;
399     drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), SPIDER_CROSS, picsize, '1 1 1', autocvar_cl_vehicle_spiderbot_cross_alpha, DRAWFLAG_NORMAL);
400
401     /*
402     health  = min(getstatf(STAT_VEHICLESTAT_HEALTH),  1);
403         shield  = min(getstatf(STAT_VEHICLESTAT_SHIELD),  1);
404         energy  = min(getstatf(STAT_VEHICLESTAT_ENERGY),  1);
405         rockets = bound(0,getstatf(STAT_VEHICLESTAT_RELOAD1), 1);
406         */
407     
408     HUD_GETSTATS
409     
410     hudloc_y =  4;
411     hudloc_x = 4;
412
413     picsize = drawgetimagesize(waki_h) * 0.5;
414     drawpic(hudloc, waki_h, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
415
416     picsize = drawgetimagesize(waki_a2) * 0.7;
417     drawpic(hudloc + '116 92  0', waki_a2, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
418
419
420     drawstring(hudloc + '145 19  0', strcat(ftos(health), "%"),'15 15 0','0 1 0', 1, DRAWFLAG_NORMAL);
421     drawstring(hudloc + '175 34  0', strcat(ftos(shield), "%"),'15 15 0','0 0 1', 1, DRAWFLAG_NORMAL);
422     drawstring(hudloc + '136 102  0', strcat(ftos(energy), "%"),'14 14 0','1 1 1', 1, DRAWFLAG_NORMAL);
423
424     picsize = drawgetimagesize(waki_a1) * 0.75;
425     if(reload1 == 100)
426     {
427         drawpic(hudloc + '140 55  0', waki_a1, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
428         drawpic(hudloc + '144 59  0', waki_a1, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
429     }
430     else
431     {
432         drawpic(hudloc + '140 55  0', waki_a1, picsize, '-1 -1 -1', 1, DRAWFLAG_NORMAL);
433         drawpic(hudloc + '144 59  0', waki_a1, picsize, '-1 -1 -1', 1, DRAWFLAG_NORMAL);
434         drawstring(hudloc + '165 69 0', strcat(ftos(reload1), "%"),'14 14 0','1 1 0', 1, DRAWFLAG_NORMAL);
435     }
436
437     picsize = drawgetimagesize(waki_b) * 0.5;
438     hudloc_y = 10.5;
439     hudloc_x = 10.5;
440     
441     health /= 100;
442     energy /= 100;
443     shield /= 100;
444     reload1 /= 100;
445     
446     drawpic(hudloc, waki_s, picsize, '1 1 1', shield, DRAWFLAG_NORMAL);
447     drawpic(hudloc, waki_b, picsize, '0 1 0' * health + '1 0 0'  * (1 - health), 1, DRAWFLAG_NORMAL);
448     drawpic(hudloc, waki_r, picsize, '1 1 1' * reload1 + '1 0 0' * (1 - reload1), 1, DRAWFLAG_NORMAL);
449     drawpic(hudloc, waki_e, picsize, '1 1 1' * energy + '1 0 0'  * (1 - energy), 1, DRAWFLAG_NORMAL);
450
451         if (scoreboard_showscores)
452         {
453                 HUD_DrawScoreboard();
454                 HUD_DrawCenterPrint();
455         }
456
457 }
458
459 void Vehicles_Precache()
460 {
461         precache_model("models/vehicles/bomblet.md3");
462         precache_model("models/vehicles/clusterbomb.md3");
463         precache_model("models/vehicles/clusterbomb_fragment.md3");
464         precache_model("models/vehicles/rocket01.md3");
465         precache_model("models/vehicles/rocket02.md3");
466 }
467
468
469 void RaptorCBShellfragDraw()
470 {
471         Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
472         if(wasfreed(self))
473                 return;
474
475         self.move_avelocity += randomvec() * 15;
476         self.renderflags = 0;
477         if(self.cnt < time)
478         self.alpha = bound(0, self.nextthink - time, 1);
479
480         if(self.alpha < ALPHA_MIN_VISIBLE)
481         remove(self);
482
483 }
484 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
485 {
486     entity sfrag;
487
488     sfrag = spawn();
489     setmodel(sfrag, "models/vehicles/clusterbomb_fragment.md3");
490     setorigin(sfrag, _org);
491
492         sfrag.move_movetype = MOVETYPE_BOUNCE;
493         sfrag.gravity = 0.15;
494         sfrag.solid = SOLID_CORPSE;
495
496         sfrag.draw = RaptorCBShellfragDraw;
497
498         sfrag.move_origin = sfrag.origin = _org;
499         sfrag.move_velocity = _vel;
500         sfrag.move_avelocity = prandomvec() * vlen(sfrag.move_velocity);
501         sfrag.angles = self.move_angles = _ang;
502
503         sfrag.move_time = time;
504         sfrag.damageforcescale = 4;
505
506         sfrag.nextthink = time + 3;
507         sfrag.cnt = time + 2;
508     sfrag.drawmask = MASK_NORMAL;
509
510
511 }