]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/View.qc
race: checkpoints with spawnflag FINISH are now a separate finish CP
[divverent/nexuiz.git] / data / qcsrc / client / View.qc
1 #define spider_rocket_icon "gfx/spiderbot/rocket_ico.tga"
2 #define spider_rocket_targ "gfx/spiderbot/target.tga"
3 #define SPIDER_CROSS "textures/spiderbot/cross.tga"
4 #define rkt_size 32
5 #define rld_size_x 256
6 #define rld_size_y 16
7
8 entity porto;
9 vector polyline[16];
10 float trace_dphitcontents;
11 float trace_networkentity;
12 float Q3SURFACEFLAG_SLICK = 2; // low friction surface
13 float DPCONTENTS_SOLID = 1; // blocks player movement
14 float DPCONTENTS_BODY = 32; // blocks player movement
15 float DPCONTENTS_CORPSE = 64; // blocks player movement
16 float DPCONTENTS_PLAYERCLIP = 256; // blocks player movement
17 void Porto_Draw()
18 {
19         vector p, dir, ang, q, nextdir;
20         float idx, portal_number, portal1_idx;
21
22         if(activeweapon != WEP_PORTO || spectatee_status || gametype == GAME_NEXBALL)
23                 return;
24         if(intermission == 1)
25                 return;
26         if(intermission == 2)
27                 return;
28         if (getstati(STAT_HEALTH) <= 0)
29                 return;
30
31         dir = view_forward;
32
33         if(angles_held_status)
34         {
35                 makevectors(angles_held);
36                 dir = v_forward;
37         }
38
39         p = view_origin;
40
41         polyline[0] = p;
42         idx = 1;
43         portal_number = 0;
44         nextdir = dir;
45
46         for(;;)
47         {
48                 dir = nextdir;
49                 traceline(p, p + 65536 * dir, TRUE, porto);
50                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
51                         return;
52                 nextdir = dir - 2 * (dir * trace_plane_normal) * trace_plane_normal; // mirror dir at trace_plane_normal
53                 p = trace_endpos;
54                 polyline[idx] = p;
55                 ++idx;
56                 if(idx >= 16)
57                         return;
58                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
59                         continue;
60                 ++portal_number;
61                 ang = vectoangles2(trace_plane_normal, dir);
62                 ang_x = -ang_x;
63                 makevectors(ang);
64                 if(!CheckWireframeBox(porto, p - 48 * v_right - 48 * v_up + 16 * v_forward, 96 * v_right, 96 * v_up, 96 * v_forward))
65                         return;
66                 if(portal_number == 1)
67                         portal1_idx = idx;
68                 if(portal_number >= 2)
69                         break;
70         }
71
72         while(idx >= 2)
73         {
74                 p = polyline[idx-2];
75                 q = polyline[idx-1];
76                 if(idx == 2)
77                         p = p - view_up * 16;
78                 if(idx-1 >= portal1_idx)
79                 {
80                         Draw_CylindricLine(p, q, 4, "", 1, 0, '0 0 1', 0.5, DRAWFLAG_NORMAL);
81                 }
82                 else
83                 {
84                         Draw_CylindricLine(p, q, 4, "", 1, 0, '1 0 0', 0.5, DRAWFLAG_NORMAL);
85                 }
86                 --idx;
87         }
88 }
89
90 /**
91  * Checks whether the server initiated a map restart (stat_game_starttime changed)
92  *
93  * TODO: Use a better solution where a common shared entitiy is used that contains
94  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
95  * and STAT_FRAGLIMIT to be auto-sent)
96  */
97 void CheckForGamestartChange() {
98         float startTime;
99         startTime = getstatf(STAT_GAMESTARTTIME);
100         if (previous_game_starttime != startTime) {
101                 if ((time + 5.0) < startTime) {
102                         //if connecting to server while restart was active don't always play prepareforbattle
103                         sound(self, CHAN_VOICE, "announcer/robotic/prepareforbattle.wav", VOL_BASEVOICE, ATTN_NONE);
104                 }
105                 if (time < startTime) {
106                         restartAnnouncer = spawn();
107                         restartAnnouncer.think = restartAnnouncer_Think;
108                         restartAnnouncer.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
109                 }
110         }
111         previous_game_starttime = startTime;
112 }
113
114 void Porto_Init()
115 {
116         porto = spawn();
117         porto.classname = "porto";
118         porto.draw = Porto_Draw;
119         porto.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
120 }
121
122 float drawtime;
123
124 float tan(float x)
125 {
126         return sin(x) / cos(x);
127 }
128 float atan2(float y, float x)
129 {
130         vector v;
131         v = '1 0 0' * x + '0 1 0' * y;
132         v = vectoangles(v);
133         return v_y * 0.01745329251994329576;
134 }
135
136 vector GetCurrentFov(float fov)
137 {
138         float zoomsensitivity, zoomspeed, zoomfactor, zoomdir;
139
140         zoomsensitivity = cvar("cl_zoomsensitivity");
141         zoomfactor = cvar("cl_zoomfactor");
142         if(zoomfactor < 1 || zoomfactor > 16)
143                 zoomfactor = 2.5;
144         zoomspeed = cvar("cl_zoomspeed");
145         if(zoomspeed >= 0)
146                 if(zoomspeed < 0.5 || zoomspeed > 16)
147                         zoomspeed = 3.5;
148
149         zoomdir = button_zoom;
150         if(getstati(STAT_ACTIVEWEAPON) == WEP_NEX) // do NOT use switchweapon here
151                 zoomdir += button_attack2;
152         if(spectatee_status > 0 || isdemo())
153         {
154                 if(spectatorbutton_zoom)
155                         zoomdir = 0 + !zoomdir;
156                         // do not even THINK about removing this 0
157                         // _I_ know what I am doing
158                         // fteqcc does not
159         }
160
161         if(zoomdir)
162                 zoomin_effect = 0;
163
164         if(zoomin_effect || camera_active)
165         {
166                 current_viewzoom = min(1, current_viewzoom + drawframetime);
167         }
168         else
169         {
170                 if(zoomspeed < 0) // instant zoom
171                 {
172                         if(zoomdir)
173                                 current_viewzoom = 1 / zoomfactor;
174                         else
175                                 current_viewzoom = 1;
176                 }
177                 else
178                 {
179                         if(zoomdir)
180                                 current_viewzoom = 1 / bound(1, 1 / current_viewzoom + drawframetime * zoomspeed * (zoomfactor - 1), zoomfactor);
181                         else
182                                 current_viewzoom = bound(1 / zoomfactor, current_viewzoom + drawframetime * zoomspeed * (1 - 1 / zoomfactor), 1);
183                 }
184         }
185
186         if(almost_equals(current_viewzoom, 1))
187                 current_zoomfraction = 0;
188         else if(almost_equals(current_viewzoom, 1/zoomfactor))
189                 current_zoomfraction = 1;
190         else
191                 current_zoomfraction = (current_viewzoom - 1) / (1/zoomfactor - 1);
192
193         if(zoomsensitivity < 1)
194                 setsensitivityscale(pow(current_viewzoom, 1 - zoomsensitivity));
195         else
196                 setsensitivityscale(1);
197
198         float frustumx, frustumy, fovx, fovy;
199         frustumy = tan(fov * 0.00872664625997164788) * 0.75 * current_viewzoom;
200         frustumx = frustumy * vid_width / vid_height / vid_pixelheight;
201         fovx = atan2(frustumx, 1) / 0.00872664625997164788;
202         fovy = atan2(frustumy, 1) / 0.00872664625997164788;
203
204         return '1 0 0' * fovx + '0 1 0' * fovy;
205 }
206
207 // this function must match W_SetupShot!
208 float zoomscript_caught;
209 entity trueaim;
210
211 #define SHOTTYPE_HITTEAM 1
212 #define SHOTTYPE_HITOBSTRUCTION 2
213 #define SHOTTYPE_HITWORLD 3
214 #define SHOTTYPE_HITENEMY 4
215
216 void TrueAim_Init()
217 {
218         trueaim = spawn();
219         trueaim.classname = "trueaim";
220         trueaim.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
221 }
222
223 float EnemyHitCheck(vector start, vector mi, vector ma, vector end)
224 {
225         float t;
226         tracebox(start, mi, ma, end, MOVE_NORMAL, trueaim);
227         if(trace_networkentity < 1)
228                 return SHOTTYPE_HITWORLD;
229         if(trace_networkentity > maxclients)
230                 return SHOTTYPE_HITWORLD;
231         t = GetPlayerColor(trace_networkentity - 1);
232         if(teamplay)
233         if(t == myteam)
234                 return SHOTTYPE_HITTEAM;
235         if(t == COLOR_SPECTATOR)
236                 return SHOTTYPE_HITWORLD;
237         return SHOTTYPE_HITENEMY;
238 }
239
240 float TrueAimCheck()
241 {
242         float nudge = 1; // added to traceline target and subtracted from result
243         vector vecs, trueaimpoint, w_shotorg;
244         vector mi, ma, dv;
245         float shottype;
246
247         mi = ma = '0 0 0';
248
249         switch(activeweapon)
250         {
251                 case WEP_TUBA: // no aim
252                 case WEP_PORTO: // shoots from eye
253                 case WEP_HOOK: // no trueaim
254                 case WEP_GRENADE_LAUNCHER: // toss curve
255                         return SHOTTYPE_HITWORLD;
256                 case WEP_CAMPINGRIFLE:
257                         if(zoomscript_caught)
258                                 return EnemyHitCheck(view_origin, '0 0 0', '0 0 0', view_origin + view_forward * MAX_SHOT_DISTANCE);
259                         break;
260                 case WEP_ROCKET_LAUNCHER: // projectile has a size!
261                         mi = '-3 -3 -3';
262                         ma = '3 3 3';
263                         break;
264                 case WEP_SEEKER: // projectile has a size!
265                         mi = '-2 -2 -2';
266                         ma = '2 2 2';
267                         break;
268                 case WEP_ELECTRO: // projectile has a size!
269                         mi = '0 0 -3';
270                         ma = '0 0 -3';
271                         break;
272         }
273
274         vecs = decompressShotOrigin(getstati(STAT_SHOTORG));
275
276         traceline(view_origin, view_origin + view_forward * MAX_SHOT_DISTANCE, MOVE_NOMONSTERS, trueaim);
277         trueaimpoint = trace_endpos;
278
279         if(vecs_x > 0)
280                 vecs_y = -vecs_y;
281         else
282                 vecs = '0 0 0';
283
284         dv = view_right * vecs_y + view_up * vecs_z;
285         w_shotorg = view_origin + dv;
286
287         // now move the vecs forward as much as requested if possible
288         tracebox(w_shotorg, mi, ma, w_shotorg + view_forward * (vecs_x + nudge), MOVE_NORMAL, trueaim); // FIXME this MOVE_NORMAL part will misbehave a little in csqc
289         w_shotorg = trace_endpos - view_forward * nudge;
290
291         shottype = EnemyHitCheck(w_shotorg, mi, ma, trueaimpoint);
292         if(shottype != SHOTTYPE_HITWORLD)
293                 return shottype;
294
295         // now test whether we will actually hit the trueaimpoint...
296         tracebox(w_shotorg, mi, ma, trueaimpoint, MOVE_NOMONSTERS, trueaim);
297
298         if(vlen(trace_endpos - trueaimpoint) > vlen(ma - mi) + 1)
299                 // yes, this is an ugly hack... but it seems good enough to find out whether the test hits the same place as the initial trace
300                 return SHOTTYPE_HITOBSTRUCTION;
301         
302         return SHOTTYPE_HITWORLD;
303 }
304
305 void CSQC_common_hud(void);
306
307 void CSQC_kh_hud(void);
308 void CSQC_ctf_hud(void);
309 void PostInit(void);
310 void CSQC_Demo_Camera();
311 float Sbar_WouldDrawScoreboard ();
312 float view_set;
313 float camera_mode;
314 string NextFrameCommand;
315 void CSQC_spider_HUD();
316 void CSQC_UpdateView(float w, float h)
317 {
318         entity e;
319         float fov;
320         float f, i, j;
321
322         dprint_load();
323         WaypointSprite_Load();
324
325         myteam = GetPlayerColor(player_localentnum - 1);
326
327         ticrate = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
328
329         // Render the Scene
330         if(!intermission || !view_set)
331         {
332                 view_origin = pmove_org + '0 0 1' * getstati(STAT_VIEWHEIGHT);
333                 view_angles = input_angles;
334                 makevectors(view_angles);
335                 view_forward = v_forward;
336                 view_right = v_right;
337                 view_up = v_up;
338                 view_set = 1;
339         }
340
341         vid_width = w;
342         vid_height = h;
343
344 #ifdef BLURTEST
345         if(time > blurtest_time0 && time < blurtest_time1)
346         {
347                 float r, t;
348
349                 t = (time - blurtest_time0) / (blurtest_time1 - blurtest_time0);
350                 r = t * blurtest_radius;
351                 f = 1 / pow(t, blurtest_power) - 1;
352
353                 cvar_set("r_glsl_postprocess", "1");
354                 cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(r), " ", ftos(f), " 0 0"));
355         }
356         else
357         {
358                 cvar_set("r_glsl_postprocess", "0");
359                 cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");
360         }
361 #endif
362
363         Fog_Force();
364
365         drawframetime = max(0.000001, time - drawtime);
366         drawtime = time;
367
368         // watch for gametype changes here...
369         // in ParseStuffCMD the cmd isn't executed yet :/
370         // might even be better to add the gametype to TE_CSQC_INIT...?
371         if(!postinit)
372                 PostInit();
373
374         CheckForGamestartChange();
375         maptimeAnnouncer();
376
377         fov = cvar("fov");
378         if(button_zoom || fov <= 59.5)
379         {
380                 if(!zoomscript_caught)
381                 {
382                         localcmd("+button4\n");
383                         zoomscript_caught = 1;
384                         ignore_plus_zoom += 1;
385                 }
386         }
387         else
388         {
389                 if(zoomscript_caught)
390                 {
391                         localcmd("-button4\n");
392                         zoomscript_caught = 0;
393                         ignore_minus_zoom += 1;
394                 }
395         }
396
397         sbar_alpha_fg = cvar("sbar_alpha_fg" );
398         sbar_currentammo = cvar("sbar_showcurrentammo");
399         sbar_hudselector = cvar("sbar_hudselector");
400         sbar_hud_accuracy = cvar("sbar_hud_accuracy");
401         ColorTranslateMode = cvar("cl_stripcolorcodes");
402         activeweapon = getstati(STAT_SWITCHWEAPON);
403         f = cvar("teamplay");
404         if(f != teamplay)
405         {
406                 teamplay = f;
407                 Sbar_InitScores();
408         }
409
410         if(last_weapon != activeweapon) {
411                 weapontime = time;
412                 last_weapon = activeweapon;
413         }
414
415         // ALWAYS Clear Current Scene First
416         R_ClearScene();
417
418         // Assign Standard Viewflags
419         // Draw the World (and sky)
420         R_SetView(VF_DRAWWORLD, 1);
421
422         // Set the console size vars
423         vid_conwidth = cvar("vid_conwidth");
424         vid_conheight = cvar("vid_conheight");
425         vid_pixelheight = cvar("vid_pixelheight");
426
427         R_SetView(VF_FOV, GetCurrentFov(fov));
428
429         // Camera for demo playback
430         if(camera_active)
431         {
432                 if(cvar("camera_enable"))
433                         CSQC_Demo_Camera();
434                 else
435                 {
436                         cvar_set("chase_active", ftos(chase_active_backup));
437                         cvar_set("cl_demo_mousegrab", "0");
438                         camera_active = FALSE;
439                 }
440         }
441 #ifdef CAMERATEST
442         else if(cvar("camera_enable"))
443 #else
444         else if(cvar("camera_enable") && isdemo())
445 #endif
446         {
447                 // Enable required Darkplaces cvars
448                 chase_active_backup = cvar("chase_active");
449                 cvar_set("chase_active", "2");
450                 cvar_set("cl_demo_mousegrab", "1");
451                 camera_active = TRUE;
452                 camera_mode = FALSE;
453         }
454
455         // Draw the Crosshair
456         float scoreboard_active;
457         scoreboard_active = Sbar_WouldDrawScoreboard();
458         R_SetView(VF_DRAWCROSSHAIR, 0); //Make sure engine crosshairs are always hidden
459
460         // Draw the Engine Status Bar (the default Quake HUD)
461         R_SetView(VF_DRAWENGINESBAR, 0);
462
463         // fetch this one only once per frame
464         sbar_showbinds = cvar("sbar_showbinds");
465         sbar_showbinds_limit = cvar("sbar_showbinds_limit");
466
467         // Update the mouse position
468         /*
469         mousepos_x = vid_conwidth;
470         mousepos_y = vid_conheight;
471         mousepos = mousepos*0.5 + getmousepos();
472         */
473
474         R_AddEntities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS);
475
476         e = self;
477         for(self = world; (self = nextent(self)); )
478                 if(self.draw)
479                         self.draw();
480         self = e;
481         R_RenderScene();
482
483         // now switch to 2D drawing mode by calling a 2D drawing function
484         // then polygon drawing will draw as 2D stuff, and NOT get queued until the
485         // next R_RenderScene call
486         drawstring('0 0 0', "", '1 1 0', '1 1 1', 0, 0);
487
488         // Draw the mouse cursor
489         // NOTE: drawpic must happen after R_RenderScene for some reason
490         //drawpic(getmousepos(), "gfx/cursor.tga", '11 14 0', '1 1 1', 1, 0);
491         //drawstring('50 50', ftos(game), '10 10 0', '1 1 1', 1, 0);
492         //self = edict_num(player_localnum);
493         //drawstring('0 0', vtos(pmove_org), '8 8 0', '1 1 1', 1, 0);
494         //drawstring('0 8', strcat("ORG: ", vtos(self.origin), " state: ", ftos(self.ctf_state), " HP: ", ftos(self.health)), '8 8 0', '1 1 1', 1, 0);
495         // as long as the ctf part isn't in, this is useless
496         if(menu_visible)
497                 menu_show();
498
499         /*if(gametype == GAME_CTF)
500         {
501                 ctf_view();
502         } else */
503
504         // draw 2D entities
505         e = self;
506         for(self = world; (self = nextent(self)); )
507                 if(self.draw2d)
508                         self.draw2d();
509         self = e;
510
511         // draw radar
512         if(
513                 ons_showmap
514                 ||
515                 (
516                         !scoreboard_active
517                         &&
518                         cvar_string("cl_teamradar") != "0"
519                         &&
520                         (
521                                 cvar("cl_teamradar") == 2
522                                 ||
523                                 teamplay
524                         )
525                 )
526         )
527                 teamradar_view();
528
529         if (cvar("cl_showpressedkeys")) // draw pressed keys when spectating and playing
530         {
531                 if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2)
532                         Sbar_DrawPressedKeys();
533         }
534         
535         if (cvar("cl_showspeed"))
536                 Sbar_ShowSpeed();
537         
538         // draw sbar
539         if(cvar("r_letterbox") == 0)
540                 Sbar_DrawCenterPrint(); // draw centerprint messages even if viewsize >= 120
541
542     float hud;
543     hud = getstati(STAT_HUD);
544     if(hud == HUD_SPIDEBOT)
545     {
546         vector sz;
547         CSQC_spider_HUD();
548         sz = drawgetimagesize(SPIDER_CROSS);
549         sz_x *= cvar_or("cl_vehicle_spiderbot_cross_size",1);
550         sz_y *= cvar_or("cl_vehicle_spiderbot_cross_size",1);
551         drawpic('0.5 0 0' * (vid_conwidth - sz_x) + '0 0.5 0' * (vid_conheight - sz_y), SPIDER_CROSS, sz, '1 1 1', cvar_or("cl_vehicle_spiderbot_cross_alpha",0.6), DRAWFLAG_NORMAL);
552     }
553     else
554     {
555         if(cvar("r_letterbox") == 0)
556             if(cvar("viewsize") < 120)
557                 CSQC_common_hud();
558
559         // crosshair goes VERY LAST
560         if(!scoreboard_active && !ons_showmap && !camera_active) {
561             // TrueAim check
562             float shottype;
563
564             if(cvar("crosshair_hittest"))
565                 shottype = TrueAimCheck();
566             else
567                 shottype = SHOTTYPE_HITWORLD;
568
569             string wcross_style;
570             wcross_style = cvar_string("crosshair");
571
572             if (wcross_style != "0") {
573                 vector wcross_color, wcross_size;
574                 string wcross_wep, wcross_name;
575                 float wcross_alpha, wcross_sizefloat;
576
577                 wcross_color_x = cvar("crosshair_color_red");
578                 wcross_color_y = cvar("crosshair_color_green");
579                 wcross_color_z = cvar("crosshair_color_blue");
580                 wcross_alpha = cvar("crosshair_color_alpha");
581                 wcross_sizefloat = cvar("crosshair_size");
582                 if (cvar("crosshair_per_weapon")) {
583                     e = get_weaponinfo(activeweapon);
584                     if (e && e.netname != "")
585                     {
586                         wcross_wep = e.netname;
587                         wcross_style = cvar_string(strcat("crosshair_", wcross_wep));
588                         if(wcross_style == "")
589                             wcross_style = e.netname;
590
591                         if(!cvar("crosshair_color_override"))
592                         {
593                             wcross_color_x = cvar(strcat("crosshair_", wcross_wep, "_color_red"));
594                             wcross_color_y = cvar(strcat("crosshair_", wcross_wep, "_color_green"));
595                             wcross_color_z = cvar(strcat("crosshair_", wcross_wep, "_color_blue"));
596                         }
597
598                         wcross_alpha *= cvar(strcat("crosshair_", wcross_wep, "_color_alpha"));
599                         wcross_sizefloat *= cvar(strcat("crosshair_", wcross_wep, "_size"));
600                     }
601                 }
602
603                 wcross_name = strcat("gfx/crosshair", wcross_style);
604
605                                 if(shottype == SHOTTYPE_HITENEMY)
606                                         wcross_sizefloat *= cvar("crosshair_hittest"); // is not queried if hittest is 0
607                                 if(shottype == SHOTTYPE_HITTEAM)
608                                         wcross_sizefloat /= cvar("crosshair_hittest"); // is not queried if hittest is 0
609
610                 wcross_size = drawgetimagesize(wcross_name);
611                 wcross_size_x *= wcross_sizefloat;
612                 wcross_size_y *= wcross_sizefloat;
613
614                 if(shottype == SHOTTYPE_HITENEMY || shottype == SHOTTYPE_HITWORLD)
615                 {
616                     drawpic('0.5 0 0' * (vid_conwidth - wcross_size_x) + '0 0.5 0' * (vid_conheight - wcross_size_y), wcross_name, wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
617                 }
618                 else
619                 {
620                     wcross_alpha *= 0.04 * 0.75;
621                     for(i = -2; i <= 2; ++i)
622                         for(j = -2; j <= 2; ++j)
623                             drawpic('0.5 0 0' * (vid_conwidth - wcross_size_x + i) + '0 0.5 0' * (vid_conheight - wcross_size_y + j), wcross_name, wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
624                 }
625             }
626         }
627     }
628
629         if(NextFrameCommand)
630         {
631                 localcmd("\n", NextFrameCommand, "\n");
632                 NextFrameCommand = string_null;
633         }
634 }
635
636 void Sbar_Draw();
637 void CSQC_spider_HUD()
638 {
639     float rockets,reload,heat,hp,shield,i;
640     vector p,pp;
641
642     rockets = getstati(STAT_SPIDERBOT_ROCKETS);
643     heat    = min(getstatf(STAT_SPIDERBOT_HEAT),1);
644     reload  = min(getstatf(STAT_SPIDERBOT_RELOAD),1);
645     hp      = min(getstatf(STAT_SPIDERBOT_HEALTH),1);
646     shield  = min(getstatf(STAT_SPIDERBOT_SHIELD),1);
647
648     // Draw health bar
649     p = '0.5 0 0' * (vid_conwidth - (rkt_size * 8));
650     p = p + '0 1 0' * vid_conheight - '0 32 0';
651     //pp = ('0 1 0' * hp) + ('1 0 0' * (1-hp));
652     drawfill(p, '256 0 0' * shield + '0 8 0' , '0.5 0.5 1', 0.75, DRAWFLAG_NORMAL);
653     p_y += 8;
654     drawfill(p, '256 0 0' * hp + '0 8 0' , '0 1 0', 0.75, DRAWFLAG_NORMAL);
655     p_x += 256 * hp;
656     drawfill(p, '256 0 0' * (1-hp) + '0 8 0' , '0 0 0', 0.75, DRAWFLAG_NORMAL);
657
658     // Draw minigun heat indicator
659     p = '0.5 0 0' * (vid_conwidth - 256);
660     p = p + '0 1 0' * vid_conheight - '0 34  0';
661     drawfill(p, '256 0 0' * (1-heat) + '0 2 0' ,'0 0 1', 0.5, DRAWFLAG_NORMAL);
662     p_x += 256 * (1-heat);
663     drawfill(p, '256 0 0' * heat  + '0 2 0' , '1 0 0', 0.5, DRAWFLAG_NORMAL);
664
665     // Draw rocket icons for loaded/empty tubes.
666     pp = '0.5 0 0' * (vid_conwidth - (rkt_size * 8));
667     pp += '0 1 0' * vid_conheight - '0 64 0';
668     for(i = 0; i < 8; ++i)
669     {
670         p = pp + '1 0 0' * (rkt_size * i);
671         if(rockets == 8)
672         {
673             if(floor(reload * 8) == i)
674             {
675                 drawpic(p, spider_rocket_icon, '1 1 0' * rkt_size, '1 0 0' + '0 1 0' * ((reload*8)-i), 0.75 , DRAWFLAG_NORMAL);
676             }
677             else if(i < reload * 8)
678                 drawpic(p, spider_rocket_icon, '1 1 0' * rkt_size, '1 1 0', 0.75 , DRAWFLAG_NORMAL);
679             else
680                 drawpic(p, spider_rocket_icon, '1 1 0' * rkt_size, '0.5 0.5 0.5', 0.75, DRAWFLAG_NORMAL);
681         }
682         else
683         {
684             if(i < rockets)
685                 drawpic(p, spider_rocket_icon, '1 1 0' * rkt_size, '0 0 0', 0.25, DRAWFLAG_NORMAL);
686             else
687                 drawpic(p, spider_rocket_icon, '1 1 0' * rkt_size, '0 1 0' * reload, 0.75, DRAWFLAG_NORMAL);
688         }
689     }
690
691         if (sb_showscores)
692         {
693                 Sbar_DrawScoreboard();
694                 Sbar_DrawCenterPrint();
695         }
696
697 }
698 void CSQC_common_hud(void)
699 {
700
701         // Sbar_SortFrags(); done in Sbar_Draw
702     float hud;
703     hud = getstati(STAT_HUD);
704
705     //hud = 10;
706     switch(hud)
707     {
708         case HUD_NORMAL:
709             Sbar_Draw();
710             break;
711
712         case HUD_SPIDEBOT:
713             CSQC_spider_HUD();
714             break;
715     }
716 }
717
718
719 // following vectors must be global to allow seamless switching between camera modes
720 vector camera_offset, current_camera_offset, mouse_angles, current_angles, current_origin, current_position;
721 void CSQC_Demo_Camera()
722 {
723         float speed, attenuation, dimensions;
724         vector tmp, delta;
725
726         if( cvar("camera_reset") || !camera_mode )
727         {
728                 camera_offset = '0 0 0';
729                 current_angles = '0 0 0';
730                 camera_direction = '0 0 0';
731                 camera_offset_z += 30;
732                 camera_offset_x += 30 * -cos(current_angles_y * DEG2RAD);
733                 camera_offset_y += 30 * -sin(current_angles_y * DEG2RAD);
734                 current_origin = view_origin;
735                 current_camera_offset  = camera_offset;
736                 cvar_set("camera_reset", "0");
737                 camera_mode = CAMERA_CHASE;
738         }
739
740         // Camera angles
741         if( camera_roll )
742                 mouse_angles_z += camera_roll * cvar("camera_speed_roll");
743
744         if(cvar("camera_look_player"))
745         {
746                 local vector dir;
747                 local float n;
748
749                 dir = normalize(view_origin - current_position);
750                 n = mouse_angles_z;
751                 mouse_angles = vectoangles(dir);
752                 mouse_angles_x = mouse_angles_x * -1;
753                 mouse_angles_z = n;
754         }
755         else
756         {
757                 tmp = getmousepos() * 0.1;
758                 if(vlen(tmp)>cvar("camera_mouse_treshold"))
759                 {
760                         mouse_angles_x += tmp_y * cos(mouse_angles_z * DEG2RAD) + (tmp_x * sin(mouse_angles_z * DEG2RAD));
761                         mouse_angles_y -= tmp_x * cos(mouse_angles_z * DEG2RAD) + (tmp_y * -sin(mouse_angles_z * DEG2RAD));
762                 }
763         }
764
765         while (mouse_angles_x < -180) mouse_angles_x = mouse_angles_x + 360;
766         while (mouse_angles_x > 180) mouse_angles_x = mouse_angles_x - 360;
767         while (mouse_angles_y < -180) mouse_angles_y = mouse_angles_y + 360;
768         while (mouse_angles_y > 180) mouse_angles_y = mouse_angles_y - 360;
769
770         // Fix difference when angles don't have the same sign
771         delta = '0 0 0';
772         if(mouse_angles_y < -60 && current_angles_y > 60)
773                 delta = '0 360 0';
774         if(mouse_angles_y > 60 && current_angles_y < -60)
775                 delta = '0 -360 0';
776
777         if(cvar("camera_look_player"))
778                 attenuation = cvar("camera_look_attenuation");
779         else
780                 attenuation = cvar("camera_speed_attenuation");
781
782         attenuation = 1 / max(1, attenuation);
783         current_angles += (mouse_angles - current_angles + delta) * attenuation;
784
785         while (current_angles_x < -180) current_angles_x = current_angles_x + 360;
786         while (current_angles_x > 180) current_angles_x = current_angles_x - 360;
787         while (current_angles_y < -180) current_angles_y = current_angles_y + 360;
788         while (current_angles_y > 180) current_angles_y = current_angles_y - 360;
789
790         // Camera position
791         tmp = '0 0 0';
792         dimensions = 0;
793
794         if( camera_direction_x )
795         {
796                 tmp_x = camera_direction_x * cos(current_angles_y * DEG2RAD);
797                 tmp_y = camera_direction_x * sin(current_angles_y * DEG2RAD);
798                 if( cvar("camera_forward_follows") && !cvar("camera_look_player") )
799                         tmp_z = camera_direction_x * -sin(current_angles_x * DEG2RAD);
800                 ++dimensions;
801         }
802
803         if( camera_direction_y )
804         {
805                 tmp_x += camera_direction_y * -sin(current_angles_y * DEG2RAD);
806                 tmp_y += camera_direction_y * cos(current_angles_y * DEG2RAD) * cos(current_angles_z * DEG2RAD);
807                 tmp_z += camera_direction_y * sin(current_angles_z * DEG2RAD);
808                 ++dimensions;
809         }
810
811         if( camera_direction_z )
812         {
813                 tmp_z += camera_direction_z * cos(current_angles_z * DEG2RAD);
814                 ++dimensions;
815         }
816
817         if(cvar("camera_free"))
818                 speed = cvar("camera_speed_free");
819         else
820                 speed = cvar("camera_speed_chase");
821
822         if(dimensions)
823         {
824                 speed = speed * sqrt(1 / dimensions);
825                 camera_offset += tmp * speed;
826         }
827
828         current_camera_offset += (camera_offset - current_camera_offset) * attenuation;
829
830         // Camera modes
831         if( cvar("camera_free") )
832         {
833                 if ( camera_mode == CAMERA_CHASE )
834                 {
835                         current_camera_offset = current_origin + current_camera_offset;
836                         camera_offset = current_origin + camera_offset;
837                 }
838
839                 camera_mode = CAMERA_FREE;
840                 current_position = current_camera_offset;
841         }
842         else
843         {
844                 if ( camera_mode == CAMERA_FREE )
845                 {
846                         current_origin = view_origin;
847                         camera_offset = camera_offset - current_origin;
848                         current_camera_offset = current_camera_offset - current_origin;
849                 }
850
851                 camera_mode = CAMERA_CHASE;
852
853                 if(cvar("camera_chase_smoothly"))
854                         current_origin += (view_origin - current_origin) * attenuation;
855                 else
856                         current_origin = view_origin;
857
858                 current_position = current_origin + current_camera_offset;
859         }
860
861         R_SetView(VF_ANGLES, current_angles);
862         R_SetView(VF_ORIGIN, current_position);
863 }