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