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