98c97ab7c9e636b4376d0f1dee74a73f8c2bedd7
[voretournament/voretournament.git] / data / qcsrc / client / View.qc
1 #define rkt_size 32\r
2 #define rld_size_x 256\r
3 #define rld_size_y 16\r
4 \r
5 entity porto;\r
6 float trace_networkentity;\r
7 float Q3SURFACEFLAG_SLICK = 2; // low friction surface\r
8 float DPCONTENTS_SOLID = 1; // blocks player movement\r
9 float DPCONTENTS_BODY = 32; // blocks player movement\r
10 float DPCONTENTS_CORPSE = 64; // blocks player movement\r
11 float DPCONTENTS_PLAYERCLIP = 256; // blocks player movement\r
12 void Porto_Draw()\r
13 {\r
14         vector dir;\r
15 \r
16         if(spectatee_status)\r
17                 return;\r
18         if(intermission == 1)\r
19                 return;\r
20         if(intermission == 2)\r
21                 return;\r
22         if (getstati(STAT_HEALTH) <= 0)\r
23                 return;\r
24 \r
25         dir = view_forward;\r
26 \r
27         if(angles_held_status)\r
28         {\r
29                 makevectors(angles_held);\r
30                 dir = v_forward;\r
31         }\r
32 }\r
33 \r
34 /**\r
35  * Checks whether the server initiated a map restart (stat_game_starttime changed)\r
36  *\r
37  * TODO: Use a better solution where a common shared entitiy is used that contains\r
38  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT\r
39  * and STAT_FRAGLIMIT to be auto-sent)\r
40  */\r
41 void CheckForGamestartChange() {\r
42         float startTime;\r
43         startTime = getstatf(STAT_GAMESTARTTIME);\r
44         if (previous_game_starttime != startTime) {\r
45                 if ((time + 5.0) < startTime) {\r
46                         //if connecting to server while restart was active don't always play prepareforbattle\r
47                         sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/prepareforbattle.wav"), VOL_BASEVOICE, ATTN_NONE);\r
48                 }\r
49                 if (time < startTime) {\r
50                         restartAnnouncer = spawn();\r
51                         restartAnnouncer.think = restartAnnouncer_Think;\r
52                         restartAnnouncer.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime\r
53                 }\r
54         }\r
55         previous_game_starttime = startTime;\r
56 }\r
57 \r
58 void Porto_Init()\r
59 {\r
60         porto = spawn();\r
61         porto.classname = "porto";\r
62         porto.draw = Porto_Draw;\r
63         porto.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;\r
64 }\r
65 \r
66 float drawtime;\r
67 float avgspeed;\r
68 vector GetCurrentFov(float fov)\r
69 {\r
70         float zoomsensitivity, zoomspeed, zoomfactor, zoomdir, velocityzoom;\r
71 \r
72         zoomsensitivity = cvar("cl_zoomsensitivity");\r
73         zoomfactor = cvar("cl_zoomfactor");\r
74         if(zoomfactor < 1 || zoomfactor > 16)\r
75                 zoomfactor = 2.5;\r
76         zoomspeed = cvar("cl_zoomspeed");\r
77         if(zoomspeed >= 0)\r
78                 if(zoomspeed < 0.5 || zoomspeed > 16)\r
79                         zoomspeed = 3.5;\r
80 \r
81         zoomdir = button_zoom;\r
82         if(spectatee_status > 0 || isdemo())\r
83         {\r
84                 if(spectatorbutton_zoom)\r
85                         zoomdir = 0 + !zoomdir;\r
86                 // do not even THINK about removing this 0\r
87                 // _I_ know what I am doing\r
88                 // fteqcc does not\r
89         }\r
90 \r
91         if(zoomdir)\r
92                 zoomin_effect = 0;\r
93 \r
94         if(zoomin_effect || camera_active)\r
95         {\r
96                 current_viewzoom = min(1, current_viewzoom + drawframetime);\r
97         }\r
98         else\r
99         {\r
100                 if(zoomspeed < 0) // instant zoom\r
101                 {\r
102                         if(zoomdir)\r
103                                 current_viewzoom = 1 / zoomfactor;\r
104                         else\r
105                                 current_viewzoom = 1;\r
106                 }\r
107                 else\r
108                 {\r
109                         if(zoomdir)\r
110                                 current_viewzoom = 1 / bound(1, 1 / current_viewzoom + drawframetime * zoomspeed * (zoomfactor - 1), zoomfactor);\r
111                         else\r
112                                 current_viewzoom = bound(1 / zoomfactor, current_viewzoom + drawframetime * zoomspeed * (1 - 1 / zoomfactor), 1);\r
113                 }\r
114         }\r
115 \r
116         if(almost_equals(current_viewzoom, 1))\r
117                 current_zoomfraction = 0;\r
118         else if(almost_equals(current_viewzoom, 1/zoomfactor))\r
119                 current_zoomfraction = 1;\r
120         else\r
121                 current_zoomfraction = (current_viewzoom - 1) / (1/zoomfactor - 1);\r
122 \r
123         if(zoomsensitivity < 1)\r
124                 setsensitivityscale(pow(current_viewzoom, 1 - zoomsensitivity));\r
125         else\r
126                 setsensitivityscale(1);\r
127 \r
128         velocityzoom = bound(0, drawframetime / max(0.000000001, cvar_or("cl_velocityzoomtime", 0.3)), 1);\r
129         avgspeed = avgspeed * (1 - velocityzoom) + (vlen(pmove_vel) / 1000) * velocityzoom;\r
130         velocityzoom = exp(float2range11(avgspeed * -cvar_or("cl_velocityzoom", 0) / 1) * 1);\r
131 \r
132         //print(ftos(avgspeed), " avgspeed, ", ftos(cvar_or("cl_velocityzoom", 0)), " cvar, ", ftos(velocityzoom), " return\n"); // for debugging\r
133 \r
134         float frustumx, frustumy, fovx, fovy;\r
135         frustumy = tan(fov * M_PI / 360.0) * 0.75 * current_viewzoom * velocityzoom;\r
136         frustumx = frustumy * vid_width / vid_height / vid_pixelheight;\r
137         fovx = atan2(frustumx, 1) / M_PI * 360.0;\r
138         fovy = atan2(frustumy, 1) / M_PI * 360.0;\r
139 \r
140         return '1 0 0' * fovx + '0 1 0' * fovy;\r
141 }\r
142 \r
143 // this function must match W_SetupShot!\r
144 float zoomscript_caught;\r
145 \r
146 vector wcross_origin;\r
147 float wcross_scale_prev, wcross_alpha_prev;\r
148 vector wcross_color_prev;\r
149 float wcross_scale_goal_prev, wcross_alpha_goal_prev;\r
150 vector wcross_color_goal_prev;\r
151 float wcross_changedonetime;\r
152 \r
153 string wcross_name_goal_prev, wcross_name_goal_prev_prev;\r
154 float wcross_resolution_goal_prev, wcross_resolution_goal_prev_prev;\r
155 float wcross_name_changestarttime, wcross_name_changedonetime;\r
156 float wcross_name_alpha_goal_prev, wcross_name_alpha_goal_prev_prev;\r
157 entity trueaim;\r
158 entity trueaim_rifle;\r
159 \r
160 #define SHOTTYPE_HITTEAM 1\r
161 #define SHOTTYPE_HITOBSTRUCTION 2\r
162 #define SHOTTYPE_HITWORLD 3\r
163 #define SHOTTYPE_HITENEMY 4\r
164 \r
165 void TrueAim_Init()\r
166 {\r
167         trueaim = spawn();\r
168         trueaim.classname = "trueaim";\r
169         trueaim.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;\r
170         trueaim_rifle = spawn();\r
171         trueaim_rifle.classname = "trueaim_rifle";\r
172         trueaim_rifle.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_CORPSE;\r
173 }\r
174 \r
175 float EnemyHitCheck()\r
176 {\r
177         float t;\r
178         wcross_origin = project_3d_to_2d(trace_endpos);\r
179         wcross_origin_z = 0;\r
180         if(trace_networkentity < 1)\r
181                 return SHOTTYPE_HITWORLD;\r
182         if(trace_networkentity > maxclients)\r
183                 return SHOTTYPE_HITWORLD;\r
184         t = GetPlayerColor(trace_networkentity - 1);\r
185         if(teamplay)\r
186                 if(t == myteam)\r
187                         return SHOTTYPE_HITTEAM;\r
188         if(t == COLOR_SPECTATOR)\r
189                 return SHOTTYPE_HITWORLD;\r
190         return SHOTTYPE_HITENEMY;\r
191 }\r
192 \r
193 float TrueAimCheck()\r
194 {\r
195         float nudge = 1; // added to traceline target and subtracted from result\r
196         vector vecs, trueaimpoint, w_shotorg;\r
197         vector mi, ma, dv;\r
198         float shottype;\r
199         entity ta;\r
200         float mv;\r
201 \r
202         mi = ma = '0 0 0';\r
203         ta = trueaim;\r
204         mv = MOVE_NOMONSTERS;\r
205 \r
206         switch(activeweapon)\r
207         {\r
208                 case WEP_GRABBER: // no trueaim\r
209         }\r
210 \r
211         vecs = decompressShotOrigin(getstati(STAT_SHOTORG));\r
212 \r
213         traceline(view_origin, view_origin + view_forward * MAX_SHOT_DISTANCE, mv, ta);\r
214         trueaimpoint = trace_endpos;\r
215 \r
216         if(vecs_x > 0)\r
217                 vecs_y = -vecs_y;\r
218         else\r
219                 vecs = '0 0 0';\r
220 \r
221         dv = view_right * vecs_y + view_up * vecs_z;\r
222         w_shotorg = view_origin + dv;\r
223 \r
224         // now move the vecs forward as much as requested if possible\r
225         tracebox(w_shotorg, mi, ma, w_shotorg + view_forward * (vecs_x + nudge), MOVE_NORMAL, ta); // FIXME this MOVE_NORMAL part will misbehave a little in csqc\r
226         w_shotorg = trace_endpos - view_forward * nudge;\r
227 \r
228         tracebox(w_shotorg, mi, ma, trueaimpoint, MOVE_NORMAL, ta);\r
229         shottype = EnemyHitCheck();\r
230         if(shottype != SHOTTYPE_HITWORLD)\r
231                 return shottype;\r
232 \r
233 #if 0\r
234         // FIXME WHY DOES THIS NOT WORK FOR THE ROCKET LAUNCHER?\r
235         // or rather, I know why, but see no fix\r
236         if(vlen(trace_endpos - trueaimpoint) > vlen(ma) + vlen(mi) + 1)\r
237                 // 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
238                 return SHOTTYPE_HITOBSTRUCTION;\r
239 #endif\r
240 \r
241         return SHOTTYPE_HITWORLD;\r
242 }\r
243 \r
244 void CSQC_common_hud(void);\r
245 \r
246 void CSQC_kh_hud(void);\r
247 void CSQC_ctf_hud(void);\r
248 void PostInit(void);\r
249 void CSQC_Demo_Camera();\r
250 float Sbar_WouldDrawScoreboard ();\r
251 float view_set;\r
252 float camera_mode;\r
253 float chase_active_old;\r
254 float artwork_fade;\r
255 float pickup_crosshair_time, pickup_crosshair_size;\r
256 float myhealth, myhealth_prev, myhealth_flash;\r
257 float contentavgalpha, liquidalpha_prev;\r
258 float stomachsplash_alpha, stomachsplash_remove_at_respawn;\r
259 float volume_modify_1, volume_modify_2, volume_modify_default_1, volume_modify_default_2, volume_modify_default_set;\r
260 vector myhealth_gentlergb;\r
261 vector liquidcolor_prev;\r
262 vector damage_blurpostprocess, content_blurpostprocess;\r
263 string artwork_image;\r
264 string intermission_song;\r
265 string NextFrameCommand;\r
266 void CSQC_UpdateView(float w, float h)\r
267 {\r
268         entity e;\r
269         float fov;\r
270         float f, i, j;\r
271         vector v, vo;\r
272 \r
273         vector artwork_pos, artwork_size;\r
274 \r
275         WaypointSprite_Load();\r
276 \r
277         if(spectatee_status)\r
278                 myteam = GetPlayerColor(spectatee_status - 1);\r
279         else\r
280                 myteam = GetPlayerColor(player_localentnum - 1);\r
281 \r
282         ticrate = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);\r
283         vo = '0 0 1' * getstati(STAT_VIEWHEIGHT);\r
284 \r
285         warpzone_fixview_origin = pmove_org + vo;\r
286         warpzone_fixview_angles = input_angles;\r
287         WarpZone_FixView();\r
288         pmove_org = warpzone_fixview_origin - vo;\r
289         input_angles = warpzone_fixview_angles;\r
290 \r
291         // Render the Scene\r
292         if(!intermission || !view_set)\r
293         {\r
294                 view_origin = pmove_org + vo;\r
295                 view_angles = input_angles;\r
296                 makevectors(view_angles);\r
297                 view_forward = v_forward;\r
298                 view_right = v_right;\r
299                 view_up = v_up;\r
300                 view_set = 1;\r
301         }\r
302 \r
303         vid_width = w;\r
304         vid_height = h;\r
305 \r
306 #ifdef BLURTEST\r
307         if(time > blurtest_time0 && time < blurtest_time1)\r
308         {\r
309                 float r, t;\r
310 \r
311                 t = (time - blurtest_time0) / (blurtest_time1 - blurtest_time0);\r
312                 r = t * blurtest_radius;\r
313                 f = 1 / pow(t, blurtest_power) - 1;\r
314 \r
315                 cvar_set("r_glsl_postprocess", "1");\r
316                 cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(r), " ", ftos(f), " 0 0"));\r
317         }\r
318         else\r
319         {\r
320                 cvar_set("r_glsl_postprocess", "0");\r
321                 cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");\r
322         }\r
323 #endif\r
324 \r
325         TargetMusic_Advance();\r
326         Fog_Force();\r
327 \r
328         drawframetime = max(0.000001, time - drawtime);\r
329         drawtime = time;\r
330 \r
331         // watch for gametype changes here...\r
332         // in ParseStuffCMD the cmd isn't executed yet :/\r
333         // might even be better to add the gametype to TE_CSQC_INIT...?\r
334         if(!postinit)\r
335                 PostInit();\r
336 \r
337         if(intermission && !isdemo() && !(calledhooks & HOOK_END))\r
338                 if(calledhooks & HOOK_START)\r
339                 {\r
340                         localcmd("\ncl_hook_gameend;");\r
341                         if(g_campaign)\r
342                                 localcmd("\ncl_hook_campaign_gameend;");\r
343                         calledhooks |= HOOK_END;\r
344                 }\r
345 \r
346         CheckForGamestartChange();\r
347         serverAnnouncer();\r
348         maptimeAnnouncer();\r
349         carrierAnnouncer();\r
350 \r
351         fov = cvar("fov");\r
352         if(button_zoom || fov <= 59.5)\r
353         {\r
354                 if(!zoomscript_caught)\r
355                 {\r
356                         localcmd("+button4\n");\r
357                         zoomscript_caught = 1;\r
358                         ignore_plus_zoom += 1;\r
359                 }\r
360         }\r
361         else\r
362         {\r
363                 if(zoomscript_caught)\r
364                 {\r
365                         localcmd("-button4\n");\r
366                         zoomscript_caught = 0;\r
367                         ignore_minus_zoom += 1;\r
368                 }\r
369         }\r
370 \r
371         sbar_alpha_fg = cvar("sbar_alpha_fg" ) * (1 - cvar("_menu_alpha"));\r
372         sbar_hudselector = cvar("sbar_hudselector");\r
373         sbar_accuracy_hud = cvar_or("sbar_accuracy_hud", 1);\r
374         ColorTranslateMode = cvar("cl_stripcolorcodes");\r
375         activeweapon = getstati(STAT_SWITCHWEAPON);\r
376         f = cvar("teamplay");\r
377         if(f != teamplay)\r
378         {\r
379                 teamplay = f;\r
380                 Sbar_InitScores();\r
381         }\r
382 \r
383         if(last_weapon != activeweapon) {\r
384                 weapontime = time;\r
385                 last_weapon = activeweapon;\r
386         }\r
387 \r
388         // ALWAYS Clear Current Scene First\r
389         R_ClearScene();\r
390 \r
391         // Assign Standard Viewflags\r
392         // Draw the World (and sky)\r
393         R_SetView(VF_DRAWWORLD, 1);\r
394 \r
395         // Set the console size vars\r
396         vid_conwidth = cvar("vid_conwidth");\r
397         vid_conheight = cvar("vid_conheight");\r
398         vid_pixelheight = cvar("vid_pixelheight");\r
399 \r
400         R_SetView(VF_FOV, GetCurrentFov(fov));\r
401 \r
402         // Camera for demo playback\r
403         if(camera_active)\r
404         {\r
405                 if(cvar("camera_enable"))\r
406                         CSQC_Demo_Camera();\r
407                 else\r
408                 {\r
409                         cvar_set("chase_active", ftos(chase_active_backup));\r
410                         cvar_set("cl_demo_mousegrab", "0");\r
411                         camera_active = FALSE;\r
412                 }\r
413         }\r
414 #ifdef CAMERATEST\r
415         else if(cvar("camera_enable"))\r
416 #else\r
417         else if(cvar("camera_enable") && isdemo())\r
418 #endif\r
419         {\r
420                 // Enable required Darkplaces cvars\r
421                 chase_active_backup = cvar("chase_active");\r
422                 cvar_set("chase_active", "2");\r
423                 cvar_set("cl_demo_mousegrab", "1");\r
424                 camera_active = TRUE;\r
425                 camera_mode = FALSE;\r
426         }\r
427 \r
428         // Draw the Crosshair\r
429         float scoreboard_active;\r
430         scoreboard_active = Sbar_WouldDrawScoreboard();\r
431         R_SetView(VF_DRAWCROSSHAIR, 0); //Make sure engine crosshairs are always hidden\r
432 \r
433         // Draw the Engine Status Bar (the default Quake HUD)\r
434         R_SetView(VF_DRAWENGINESBAR, 0);\r
435 \r
436         // fetch this one only once per frame\r
437         sbar_showbinds = cvar("sbar_showbinds");\r
438         sbar_showbinds_limit = cvar("sbar_showbinds_limit");\r
439 \r
440         // Update the mouse position\r
441         /*\r
442            mousepos_x = vid_conwidth;\r
443            mousepos_y = vid_conheight;\r
444            mousepos = mousepos*0.5 + getmousepos();\r
445          */\r
446 \r
447         e = self;\r
448         for(self = world; (self = nextent(self)); )\r
449                 if(self.draw)\r
450                         self.draw();\r
451         self = e;\r
452 \r
453         R_AddEntities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS);\r
454         R_RenderScene();\r
455 \r
456         // now switch to 2D drawing mode by calling a 2D drawing function\r
457         // then polygon drawing will draw as 2D stuff, and NOT get queued until the\r
458         // next R_RenderScene call\r
459         drawstring('0 0 0', "", '1 1 0', '1 1 1', 0, 0);\r
460 \r
461         if(cvar("hud_contents"))\r
462         {\r
463                 float contentalpha_temp, incontent, liquidalpha, contentfadetime;\r
464                 vector liquidcolor;\r
465 \r
466                 if (getstati(STAT_VORE_EATEN))\r
467                 {\r
468                         liquidalpha = cvar("hud_contents_stomach_alpha");\r
469                         liquidcolor = stov(cvar_string("hud_contents_stomach_color"));\r
470                         incontent = 1;\r
471                 }\r
472                 else\r
473                 {\r
474                         switch(pointcontents(view_origin))\r
475                         {\r
476                                 case CONTENT_WATER:\r
477                                         liquidalpha = cvar("hud_contents_water_alpha");\r
478                                         liquidcolor = stov(cvar_string("hud_contents_water_color"));\r
479                                         incontent = 1;\r
480                                         break;\r
481                                         \r
482                                 case CONTENT_LAVA:\r
483                                         liquidalpha = cvar("hud_contents_lava_alpha");\r
484                                         liquidcolor = stov(cvar_string("hud_contents_lava_color"));\r
485                                         incontent = 1;\r
486                                         break;  \r
487                                                                 \r
488                                 case CONTENT_SLIME:\r
489                                         liquidalpha = cvar("hud_contents_slime_alpha");\r
490                                         liquidcolor = stov(cvar_string("hud_contents_slime_color"));\r
491                                         incontent = 1;\r
492                                         break;\r
493                                         \r
494                                 default:\r
495                                         liquidalpha = 0;\r
496                                         liquidcolor = '0 0 0';\r
497                                         incontent = 0;\r
498                                         break;\r
499                         }\r
500                 }\r
501                 \r
502                 if(incontent) // fade in/out at different speeds so you can do e.g. instant fade when entering water and slow when leaving it.\r
503                 { // also lets delcare previous values for blending properties, this way it isn't reset until after you have entered a different content\r
504                         contentfadetime = cvar("hud_contents_fadeintime");\r
505                         liquidalpha_prev = liquidalpha;\r
506                         liquidcolor_prev = liquidcolor;\r
507                 }\r
508                 else\r
509                         contentfadetime = cvar("hud_contents_fadeouttime");\r
510                         \r
511                 contentalpha_temp = bound(0, drawframetime / max(0.0001, contentfadetime), 1);\r
512                 contentavgalpha = contentavgalpha * (1 - contentalpha_temp) + incontent * contentalpha_temp;\r
513                 \r
514                 if(contentavgalpha)\r
515                         drawfill('0 0 0', '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, liquidcolor_prev, contentavgalpha * liquidalpha_prev, DRAWFLAG_NORMAL);\r
516 \r
517                 if(cvar("hud_postprocessing"))\r
518                 {\r
519                         if(cvar("hud_contents_blur"))\r
520                         {\r
521                                 content_blurpostprocess_x = 1;\r
522                                 content_blurpostprocess_y = contentavgalpha * cvar("hud_contents_blur");\r
523                                 content_blurpostprocess_z = contentavgalpha * cvar("hud_contents_blur_alpha");\r
524                         }\r
525                         else\r
526                         {\r
527                                 content_blurpostprocess_x = 0;\r
528                                 content_blurpostprocess_y = 0;\r
529                                 content_blurpostprocess_z = 0;\r
530                         }\r
531                 }\r
532         }\r
533 \r
534         if(cvar("hud_damage"))\r
535         {\r
536                 float myhealth_flash_temp;\r
537                 myhealth = getstati(STAT_HEALTH);\r
538 \r
539                 // fade out\r
540                 myhealth_flash = max(0, myhealth_flash - cvar("hud_damage_fade_rate") * frametime);\r
541                 // add new damage\r
542                 myhealth_flash = bound(0, myhealth_flash + dmg_take * cvar("hud_damage_factor"), cvar("hud_damage_maxalpha"));\r
543 \r
544                 float pain_threshold, pain_threshold_lower, pain_threshold_lower_health;\r
545                 pain_threshold = cvar("hud_damage_pain_threshold");\r
546                 pain_threshold_lower = cvar("hud_damage_pain_threshold_lower");\r
547                 pain_threshold_lower_health = cvar("hud_damage_pain_threshold_lower_health");\r
548 \r
549                 if(pain_threshold_lower && myhealth < pain_threshold_lower_health)\r
550                 {\r
551                         pain_threshold = pain_threshold - max(cvar("hud_damage_pain_threshold_pulsating_min"), fabs(sin(M_PI * time / cvar("hud_damage_pain_threshold_pulsating_period")))) * pain_threshold_lower * (1 - max(0, myhealth)/pain_threshold_lower_health);\r
552                 }\r
553 \r
554                 myhealth_flash_temp = bound(0, myhealth_flash - pain_threshold, 1);\r
555 \r
556                 if(myhealth_prev < 1)\r
557                 {\r
558                         if(myhealth >= 1)\r
559                         {\r
560                                 myhealth_flash = 0; // just spawned, clear the flash immediately\r
561                                 myhealth_flash_temp = 0;\r
562                         }\r
563                         else\r
564                         {\r
565                                 myhealth_flash += cvar("hud_damage_fade_rate") * frametime; // dead\r
566                         }\r
567                 }\r
568 \r
569                 if(spectatee_status == -1 || intermission)\r
570                 {\r
571                         myhealth_flash = 0; // observing, or match ended\r
572                         myhealth_flash_temp = 0;\r
573                 }\r
574 \r
575                 myhealth_prev = myhealth;\r
576 \r
577                 if(cvar("cl_gentle_damage") || cvar("cl_gentle"))\r
578                 {\r
579                         if(cvar("cl_gentle_damage") == 2)\r
580                         {\r
581                                 if(myhealth_flash < pain_threshold) // only randomize when the flash is gone\r
582                                 {\r
583                                         myhealth_gentlergb = '1 0 0' * random() + '0 1 0' * random() + '0 0 1' * random();\r
584                                 }\r
585                         }\r
586                         else\r
587                                 myhealth_gentlergb = stov(cvar_string("hud_damage_gentle_color"));\r
588 \r
589                         drawfill('0 0 0', '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, myhealth_gentlergb, cvar("hud_damage_gentle_alpha_multiplier") * bound(0, myhealth_flash_temp, 1) * cvar("hud_damage"), DRAWFLAG_NORMAL);\r
590                 }\r
591                 else\r
592                         drawpic('0 0 0', "gfx/blood", '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, stov(cvar_string("hud_damage_color")), bound(0, myhealth_flash_temp, 1) * cvar("hud_damage"), DRAWFLAG_NORMAL);\r
593 \r
594                 if(cvar("hud_postprocessing"))\r
595                 {\r
596                         if(cvar("hud_damage_blur"))\r
597                         {\r
598                                 damage_blurpostprocess_x = 1;\r
599                                 damage_blurpostprocess_y = bound(0, myhealth_flash_temp, 1) * cvar("hud_damage_blur");\r
600                                 damage_blurpostprocess_z = bound(0, myhealth_flash_temp, 1) * cvar("hud_damage_blur_alpha");\r
601                         }\r
602                         else\r
603                         {\r
604                                 damage_blurpostprocess_x = 0;\r
605                                 damage_blurpostprocess_y = 0;\r
606                                 damage_blurpostprocess_z = 0;\r
607                         }\r
608                 }\r
609         }\r
610 \r
611         if(cvar("hud_stomach"))\r
612         {\r
613                 if(getstati(STAT_VORE_EATEN))\r
614                 {\r
615                         if(stomachsplash_alpha < cvar("hud_stomach"))\r
616                                 stomachsplash_alpha += cvar("hud_stomach_fade_in") * frametime;\r
617                         else\r
618                                 stomachsplash_alpha = cvar("hud_stomach");\r
619                 }\r
620                 else if(getstati(STAT_HEALTH) > 0)\r
621                 {\r
622                         if(stomachsplash_alpha > 0)\r
623                                 stomachsplash_alpha -= cvar("hud_stomach_fade_out") * frametime;\r
624                         else\r
625                                 stomachsplash_alpha = 0;\r
626                 }\r
627                 if(getstati(STAT_HEALTH) <= 0)\r
628                         stomachsplash_remove_at_respawn = 1; // schedule the effect to be removed next respawn\r
629 \r
630                 if(getstati(STAT_HEALTH) > 0 && stomachsplash_remove_at_respawn)\r
631                         stomachsplash_alpha = stomachsplash_remove_at_respawn = 0; // we respawned, remove the effect\r
632                 if(spectatee_status == -1)\r
633                         stomachsplash_alpha = 0;\r
634 \r
635                 stomachsplash_alpha = bound(0, stomachsplash_alpha, 1);\r
636                 drawpic('0 0 0', "gfx/food", '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, stov(cvar_string("hud_stomach_color")), stomachsplash_alpha, DRAWFLAG_NORMAL);\r
637         }\r
638 \r
639         if(cvar("hud_postprocessing"))\r
640         {\r
641                 // lets apply the postprocess effects from the previous two functions if needed\r
642                 if(damage_blurpostprocess_x || content_blurpostprocess_x)\r
643                 {\r
644                         float blurradius = bound(0, damage_blurpostprocess_y + content_blurpostprocess_y, cvar("hud_postprocessing_maxblurradius"));\r
645                         float bluralpha = bound(0, damage_blurpostprocess_z + content_blurpostprocess_z, cvar("hud_postprocessing_maxbluralpha"));\r
646                         cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(blurradius), " ", ftos(bluralpha), " 0 0"));\r
647                         cvar_set("r_glsl_postprocess_uservec1_enable", "1");\r
648                 }\r
649                 else\r
650                 {\r
651                         cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");\r
652                         cvar_set("r_glsl_postprocess_uservec1_enable", "0");\r
653                 }\r
654 \r
655                 if(cvar("hud_powerup"))\r
656                 {\r
657                         float sharpen_intensity;\r
658                         if (getstatf(STAT_STRENGTH_FINISHED) - time > 0)\r
659                                 sharpen_intensity += (getstatf(STAT_STRENGTH_FINISHED) - time);\r
660                         if (getstatf(STAT_INVINCIBLE_FINISHED) - time > 0)\r
661                                 sharpen_intensity += (getstatf(STAT_INVINCIBLE_FINISHED) - time);\r
662                         sharpen_intensity = bound(0, sharpen_intensity, 5); // powerup warning time is 5 seconds, so fade the effect from there\r
663 \r
664                         if(sharpen_intensity > 0)\r
665                         {\r
666                                 cvar_set("r_glsl_postprocess_uservec2", strcat("0 ", ftos(-sharpen_intensity * cvar("hud_powerup")), " 0 0"));\r
667                                 cvar_set("r_glsl_postprocess_uservec2_enable", "1");\r
668                         }\r
669                         else\r
670                         {\r
671                                 cvar_set("r_glsl_postprocess_uservec2", "0 0 0 0");\r
672                                 cvar_set("r_glsl_postprocess_uservec2_enable", "0");\r
673                         }\r
674                 }\r
675         }\r
676 \r
677         if not(cvar("hud_damage") && cvar("hud_postprocessing"))\r
678         {\r
679                 // don't allow blur to get stuck on if we disable the cvar while damaged\r
680                 cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");\r
681                 cvar_set("r_glsl_postprocess_uservec1_enable", "0");\r
682         }\r
683         if not(cvar("hud_powerup") && cvar("hud_postprocessing"))\r
684         {\r
685                 // don't allow sharpen to get stuck on if we disable the cvar while powered up\r
686                 cvar_set("r_glsl_postprocess_uservec2", "0 0 0 0");\r
687                 cvar_set("r_glsl_postprocess_uservec2_enable", "0");\r
688         }\r
689 \r
690         if(cvar("cl_vore_cutvolume_sound") || cvar("cl_vore_cutvolume_music"))\r
691         {\r
692                 if(!volume_modify_default_set)\r
693                 {\r
694                         // set the initial volume\r
695                         volume_modify_default_1 = cvar("volume");\r
696                         volume_modify_default_2 = cvar("bgmvolume");\r
697                         volume_modify_default_set = TRUE;\r
698                 }\r
699                 if(spectatee_status == -1 || intermission)\r
700                         volume_modify_1 = volume_modify_2 = 1;\r
701                 else if (getstati(STAT_VORE_EATEN))\r
702                 {\r
703                         if (volume_modify_1 > cvar("cl_vore_cutvolume_sound"))\r
704                         {\r
705                                 volume_modify_1 -= cvar("cl_vore_cutvolume_fade") * frametime;\r
706                                 if(volume_modify_1 < cvar("cl_vore_cutvolume_sound"))\r
707                                         volume_modify_1 = cvar("cl_vore_cutvolume_sound");\r
708                         }\r
709                         if (volume_modify_2 > cvar("cl_vore_cutvolume_music"))\r
710                         {\r
711                                 volume_modify_2 -= cvar("cl_vore_cutvolume_fade") * frametime;\r
712                                 if(volume_modify_2 < cvar("cl_vore_cutvolume_music"))\r
713                                         volume_modify_2 = cvar("cl_vore_cutvolume_music");\r
714                         }\r
715                 }\r
716                 else\r
717                 {\r
718                         if (volume_modify_1 < 1)\r
719                         {\r
720                                 volume_modify_1 += cvar("cl_vore_cutvolume_fade") * frametime;\r
721                                 if(volume_modify_1 > 1)\r
722                                         volume_modify_1 = 1;\r
723                         }\r
724                         if (volume_modify_2 < 1)\r
725                         {\r
726                                 volume_modify_2 += cvar("cl_vore_cutvolume_fade") * frametime;\r
727                                 if(volume_modify_2 > 1)\r
728                                         volume_modify_2 = 1;\r
729                         }\r
730                 }\r
731                 cvar_set("volume", ftos(volume_modify_default_1 * volume_modify_1));\r
732                 cvar_set("bgmvolume", ftos(volume_modify_default_2 * volume_modify_2));\r
733                 // TODO: Setting the "volume" cvar is a bad way to go, and modifies the menu slider! We need a better way to go\r
734         }\r
735 \r
736         // Draw the mouse cursor\r
737         // NOTE: drawpic must happen after R_RenderScene for some reason\r
738         //drawpic(getmousepos(), "gfx/cursor.tga", '11 14 0', '1 1 1', 1, 0);\r
739         //drawstring('50 50', ftos(game), '10 10 0', '1 1 1', 1, 0);\r
740         //self = edict_num(player_localnum);\r
741         //drawstring('0 0', vtos(pmove_org), '8 8 0', '1 1 1', 1, 0);\r
742         //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
743         // as long as the ctf part isn't in, this is useless\r
744         if(menu_visible)\r
745                 menu_show();\r
746 \r
747         /*if(gametype == GAME_CTF)\r
748           {\r
749           ctf_view();\r
750           } else */\r
751 \r
752         // draw 2D entities\r
753         e = self;\r
754         for(self = world; (self = nextent(self)); )\r
755                 if(self.draw2d)\r
756                         self.draw2d();\r
757         self = e;\r
758 \r
759         // draw radar\r
760         if(\r
761                         ons_showmap\r
762                         ||\r
763                         (\r
764                          !scoreboard_active\r
765                          &&\r
766                          cvar_string("cl_teamradar") != "0"\r
767                          &&\r
768                          (\r
769                           cvar("cl_teamradar") == 2\r
770                           ||\r
771                           teamplay\r
772                          )\r
773                         )\r
774           )\r
775                 teamradar_view();\r
776 \r
777         // Draw artwork and play intermission music\r
778         if(intermission && !isdemo() && gametype != GAME_RPG && !spectatee_status) // the match has ended. Don't do this for RPG because no one wins or loses there\r
779         {\r
780                 if(cvar("cl_artwork"))\r
781                 {\r
782                         if(artwork_image == "")\r
783                         {\r
784                                 if(getstati(STAT_WINNING)) // we are the winner\r
785                                 {\r
786                                         if(cvar("cl_artwork_win"))\r
787                                         {\r
788                                                 artwork_image = strcat("gfx/artwork_won_", ftos(floor(1 + (random() * cvar("cl_artwork_win")))));\r
789                                                 artwork_image = strzone(artwork_image);\r
790                                         }\r
791                                 }\r
792                                 else // we have lost\r
793                                 {\r
794                                         if(cvar("cl_artwork_lose"))\r
795                                         {\r
796                                                 artwork_image = strcat("gfx/artwork_lost_", ftos(floor(1 + (random() * cvar("cl_artwork_lose")))));\r
797                                                 artwork_image = strzone(artwork_image);\r
798                                         }\r
799                                 }\r
800                         }\r
801 \r
802                         if(cvar("cl_artwork_stretch"))\r
803                         {\r
804                                 artwork_size_x = vid_conwidth;\r
805                                 artwork_size_y = vid_conheight;\r
806                                 artwork_pos_x = 0;\r
807                                 artwork_pos_y = 0;\r
808                         }\r
809                         else\r
810                         {\r
811                                 artwork_size_x = max(vid_conwidth, vid_conheight);\r
812                                 artwork_size_y = max(vid_conwidth, vid_conheight);\r
813                                 artwork_pos_x = (vid_conwidth - artwork_size_x) / 2;\r
814                                 artwork_pos_y = (vid_conheight - artwork_size_y) / 2;\r
815                         }\r
816 \r
817                         if(artwork_fade < cvar("cl_artwork_alpha") && cvar("cl_artwork_fade"))\r
818                                 artwork_fade += frametime * cvar("cl_artwork_fade");\r
819                         else\r
820                                 artwork_fade = cvar("cl_artwork_alpha");\r
821 \r
822                         if(artwork_image != "")\r
823                                 drawpic(artwork_pos, artwork_image, artwork_size, '1 1 1', artwork_fade, DRAWFLAG_NORMAL);\r
824                 }\r
825 \r
826                 if(cvar("cl_intermission") && intermission_song == "") // don't start the song each frame\r
827                 {\r
828                         if(getstati(STAT_WINNING))\r
829                                 intermission_song = cvar_string("cl_intermission_cdtrack_win");\r
830                         else\r
831                                 intermission_song = cvar_string("cl_intermission_cdtrack_lose");\r
832                         if(intermission_song != "")\r
833                         {\r
834                                 localcmd(strcat("\ncd play ", intermission_song, "\n"));\r
835                                 intermission_song = strzone(intermission_song);\r
836                         }\r
837                 }\r
838         }\r
839         else\r
840         {\r
841                 artwork_fade = 0;\r
842                 if(artwork_image != "")\r
843                 {\r
844                         strunzone(artwork_image);\r
845                         artwork_image = "";\r
846                 }\r
847 \r
848                 if(intermission_song != "")\r
849                 {\r
850                         strunzone(intermission_song);\r
851                         intermission_song = "";\r
852                 }\r
853         }\r
854 \r
855         // draw sbar\r
856         if(cvar("r_letterbox") == 0) {\r
857                 if (cvar("cl_showpressedkeys")) { // draw pressed keys when spectating and playing\r
858                         if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2)\r
859                                 Sbar_DrawPressedKeys();\r
860                 }\r
861 \r
862                 if (cvar("cl_showspeed"))\r
863                         Sbar_ShowSpeed();\r
864                 if (cvar("cl_showacceleration"))\r
865                         Sbar_ShowAcceleration();\r
866 \r
867                 Sbar_DrawCenterPrint(); // draw centerprint messages even if viewsize >= 120\r
868         }\r
869 \r
870         float hud;\r
871         hud = getstati(STAT_HUD);\r
872 \r
873         if(cvar("r_letterbox") == 0)\r
874                 if(cvar("viewsize") < 120)\r
875                         CSQC_common_hud();\r
876 \r
877         if not(getstati(STAT_VORE_EATEN)) // crosshair is useless if we're in the stomach\r
878         {\r
879                 // crosshair goes VERY LAST\r
880                 if(!scoreboard_active && !ons_showmap && !camera_active) {\r
881                         // TrueAim check\r
882                         float shottype;\r
883                         // wcross_origin = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;\r
884                         wcross_origin = project_3d_to_2d(view_origin + MAX_SHOT_DISTANCE * view_forward);\r
885                         wcross_origin_z = 0;\r
886                         if(cvar("crosshair_hittest"))\r
887                         {\r
888                                 vector wcross_oldorigin;\r
889                                 wcross_oldorigin = wcross_origin;\r
890                                 shottype = TrueAimCheck();\r
891                                 if(shottype == SHOTTYPE_HITWORLD)\r
892                                 {\r
893                                         v = wcross_origin - wcross_oldorigin;\r
894                                         v_x /= vid_conwidth;\r
895                                         v_y /= vid_conheight;\r
896                                         if(vlen(v) > 0.01)\r
897                                                 shottype = SHOTTYPE_HITOBSTRUCTION;\r
898                                 }\r
899                                 if(!cvar("crosshair_hittest_showimpact"))\r
900                                         wcross_origin = wcross_oldorigin;\r
901                         }\r
902                         else\r
903                                 shottype = SHOTTYPE_HITWORLD;\r
904 \r
905                         string wcross_style;\r
906                         wcross_style = cvar_string("crosshair");\r
907 \r
908                         if (wcross_style != "0") {\r
909                                 vector wcross_color, wcross_size;\r
910                                 string wcross_name;\r
911                                 float wcross_alpha, wcross_scale, wcross_blur, wcross_resolution;\r
912 \r
913                                 wcross_color_x = cvar("crosshair_color_red");\r
914                                 wcross_color_y = cvar("crosshair_color_green");\r
915                                 wcross_color_z = cvar("crosshair_color_blue");\r
916                                 wcross_alpha = cvar("crosshair_color_alpha");\r
917                                 wcross_resolution = cvar("crosshair_size");\r
918 \r
919                                 wcross_name = strcat("gfx/crosshair", wcross_style);\r
920 \r
921                                 if(cvar("crosshair_effect_scalefade"))\r
922                                 {\r
923                                         wcross_scale = wcross_resolution;\r
924                                         wcross_resolution = 1;\r
925                                 }\r
926                                 else\r
927                                 {\r
928                                         wcross_scale = 1;\r
929                                 }\r
930 \r
931                                 if(cvar("crosshair_pickup"))\r
932                                 {\r
933                                         if(pickup_crosshair_time < getstatf(STAT_LAST_PICKUP))\r
934                                         {\r
935                                                 pickup_crosshair_size = 1;\r
936                                                 pickup_crosshair_time = getstatf(STAT_LAST_PICKUP);\r
937                                         }\r
938 \r
939                                         if(pickup_crosshair_size > 0)\r
940                                                 pickup_crosshair_size -= cvar("crosshair_pickup_speed") * frametime;\r
941                                         else\r
942                                                 pickup_crosshair_size = 0;\r
943 \r
944                                         wcross_scale += sin(pickup_crosshair_size) * cvar("crosshair_pickup");\r
945                                 }\r
946 \r
947                                 if(shottype == SHOTTYPE_HITENEMY)\r
948                                         wcross_scale *= cvar("crosshair_hittest"); // is not queried if hittest is 0\r
949                                 if(shottype == SHOTTYPE_HITTEAM)\r
950                                         wcross_scale /= cvar("crosshair_hittest"); // is not queried if hittest is 0\r
951 \r
952                                 f = cvar("crosshair_effect_speed");\r
953                                 if(wcross_scale != wcross_scale_goal_prev || wcross_alpha != wcross_alpha_goal_prev || wcross_color != wcross_color_goal_prev)\r
954                                 {\r
955                                         wcross_changedonetime = time + f;\r
956                                 }\r
957                                 if(wcross_name != wcross_name_goal_prev || wcross_resolution != wcross_resolution_goal_prev)\r
958                                 {\r
959                                         wcross_name_changestarttime = time;\r
960                                         wcross_name_changedonetime = time + f;\r
961                                         if(wcross_name_goal_prev_prev)\r
962                                                 strunzone(wcross_name_goal_prev_prev);\r
963                                         wcross_name_goal_prev_prev = wcross_name_goal_prev;\r
964                                         wcross_name_goal_prev = strzone(wcross_name);\r
965                                         wcross_name_alpha_goal_prev_prev = wcross_name_alpha_goal_prev;\r
966                                         wcross_resolution_goal_prev_prev = wcross_resolution_goal_prev;\r
967                                         wcross_resolution_goal_prev = wcross_resolution;\r
968                                 }\r
969 \r
970                                 wcross_scale_goal_prev = wcross_scale;\r
971                                 wcross_alpha_goal_prev = wcross_alpha;\r
972                                 wcross_color_goal_prev = wcross_color;\r
973 \r
974                                 if(shottype == SHOTTYPE_HITTEAM || (shottype == SHOTTYPE_HITOBSTRUCTION && cvar("crosshair_hittest_blur") && !cvar("chase_active")))\r
975                                 {\r
976                                         wcross_blur = 1;\r
977                                         wcross_alpha *= 0.75;\r
978                                 }\r
979                                 else\r
980                                         wcross_blur = 0;\r
981                                 // *_prev is at time-frametime\r
982                                 // * is at wcross_changedonetime+f\r
983                                 // what do we have at time?\r
984                                 if(time < wcross_changedonetime)\r
985                                 {\r
986                                         f = frametime / (wcross_changedonetime - time + frametime);\r
987                                         wcross_scale = f * wcross_scale + (1 - f) * wcross_scale_prev;\r
988                                         wcross_alpha = f * wcross_alpha + (1 - f) * wcross_alpha_prev;\r
989                                         wcross_color = f * wcross_color + (1 - f) * wcross_color_prev;\r
990                                 }\r
991 \r
992                                 wcross_scale_prev = wcross_scale;\r
993                                 wcross_alpha_prev = wcross_alpha;\r
994                                 wcross_color_prev = wcross_color;\r
995 \r
996                                 wcross_scale *= 1 - cvar("_menu_alpha");\r
997                                 wcross_alpha *= 1 - cvar("_menu_alpha");\r
998 \r
999 #define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \\r
1000                                 do \\r
1001                                 { \\r
1002                                         if(wcross_blur > 0) \\r
1003                                         { \\r
1004                                                 for(i = -2; i <= 2; ++i) \\r
1005                                                         for(j = -2; j <= 2; ++j) \\r
1006                                                                 M(i,j,sz,wcross_name,wcross_alpha*0.04); \\r
1007                                         } \\r
1008                                         else \\r
1009                                         { \\r
1010                                                 M(0,0,sz,wcross_name,wcross_alpha); \\r
1011                                         } \\r
1012                                 } \\r
1013                                 while(0)\r
1014 \r
1015 #define CROSSHAIR_DRAW_SINGLE(i,j,sz,wcross_name,wcross_alpha) \\r
1016                                 drawpic(wcross_origin - ('0.5 0 0' * (sz * wcross_size_x + i * wcross_blur) + '0 0.5 0' * (sz * wcross_size_y + j * wcross_blur)), wcross_name, sz * wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL)\r
1017 \r
1018 #define CROSSHAIR_DRAW(sz,wcross_name,wcross_alpha) \\r
1019                                 CROSSHAIR_DO_BLUR(CROSSHAIR_DRAW_SINGLE,sz,wcross_name,wcross_alpha)\r
1020 \r
1021                                 if(time < wcross_name_changedonetime && wcross_name != wcross_name_goal_prev_prev && wcross_name_goal_prev_prev)\r
1022                                 {\r
1023                                         f = (wcross_name_changedonetime - time) / (wcross_name_changedonetime - wcross_name_changestarttime);\r
1024                                         wcross_size = drawgetimagesize(wcross_name_goal_prev_prev) * wcross_scale;\r
1025                                         CROSSHAIR_DRAW(wcross_resolution_goal_prev_prev, wcross_name_goal_prev_prev, wcross_alpha * f * wcross_name_alpha_goal_prev_prev);\r
1026                                         f = 1 - f;\r
1027                                 }\r
1028                                 else\r
1029                                 {\r
1030                                         f = 1;\r
1031                                 }\r
1032 \r
1033                                 wcross_size = drawgetimagesize(wcross_name) * wcross_scale;\r
1034                                 CROSSHAIR_DRAW(wcross_resolution, wcross_name, wcross_alpha * f);\r
1035                                 wcross_name_alpha_goal_prev = f;\r
1036                         }\r
1037                 }\r
1038                 else\r
1039                 {\r
1040                         wcross_scale_prev = 0;\r
1041                         wcross_alpha_prev = 0;\r
1042                         wcross_scale_goal_prev = 0;\r
1043                         wcross_alpha_goal_prev = 0;\r
1044                         wcross_changedonetime = 0;\r
1045                         if(wcross_name_goal_prev)\r
1046                                 strunzone(wcross_name_goal_prev);\r
1047                         wcross_name_goal_prev = string_null;\r
1048                         if(wcross_name_goal_prev_prev)\r
1049                                 strunzone(wcross_name_goal_prev_prev);\r
1050                         wcross_name_goal_prev_prev = string_null;\r
1051                         wcross_name_changestarttime = 0;\r
1052                         wcross_name_changedonetime = 0;\r
1053                         wcross_name_alpha_goal_prev = 0;\r
1054                         wcross_name_alpha_goal_prev_prev = 0;\r
1055                         wcross_resolution_goal_prev = 0;\r
1056                         wcross_resolution_goal_prev_prev = 0;\r
1057                 }\r
1058         }\r
1059 \r
1060         if(NextFrameCommand)\r
1061         {\r
1062                 localcmd("\n", NextFrameCommand, "\n");\r
1063                 NextFrameCommand = string_null;\r
1064         }\r
1065 \r
1066         // we must do this check AFTER a frame was rendered, or it won't work\r
1067         if(cs_project_is_b0rked == 0)\r
1068         {\r
1069                 string w0, h0;\r
1070                 w0 = cvar_string("vid_conwidth");\r
1071                 h0 = cvar_string("vid_conheight");\r
1072                 //R_SetView(VF_VIEWPORT, '0 0 0', '640 480 0');\r
1073                 //R_SetView(VF_FOV, '90 90 0');\r
1074                 R_SetView(VF_ORIGIN, '0 0 0');\r
1075                 R_SetView(VF_ANGLES, '0 0 0');\r
1076                 R_SetView(VF_PERSPECTIVE, 1);\r
1077                 makevectors('0 0 0');\r
1078                 vector v1, v2;\r
1079                 cvar_set("vid_conwidth", "800");\r
1080                 cvar_set("vid_conheight", "600");\r
1081                 v1 = cs_project(v_forward);\r
1082                 cvar_set("vid_conwidth", "640");\r
1083                 cvar_set("vid_conheight", "480");\r
1084                 v2 = cs_project(v_forward);\r
1085                 if(v1 == v2)\r
1086                         cs_project_is_b0rked = 1;\r
1087                 else\r
1088                         cs_project_is_b0rked = -1;\r
1089                 cvar_set("vid_conwidth", w0);\r
1090                 cvar_set("vid_conheight", h0);\r
1091         }\r
1092 \r
1093         // be safe against triggerbots until everyone has the fixed engine\r
1094         // this call is meant to overwrite the trace globals by something\r
1095         // unsuspicious\r
1096         traceline('0 0 0', '0 0 0', MOVE_WORLDONLY, world);\r
1097 \r
1098         // this cvar must be constantly updated on the server\r
1099         if(chase_active_old != cvar("chase_active"))\r
1100         {\r
1101                 localcmd("sendcvar chase_active\n");\r
1102                 chase_active_old = cvar("chase_active");\r
1103         }\r
1104 }\r
1105 \r
1106 void Sbar_Draw();\r
1107 \r
1108 void CSQC_common_hud(void)\r
1109 {\r
1110         // Sbar_SortFrags(); done in Sbar_Draw\r
1111         float hud;\r
1112         hud = getstati(STAT_HUD);\r
1113 \r
1114         //hud = 10;\r
1115         switch(hud)\r
1116         {\r
1117                 case HUD_NORMAL:\r
1118                         Sbar_Draw();\r
1119                         break;\r
1120         }\r
1121 }\r
1122 \r
1123 \r
1124 // following vectors must be global to allow seamless switching between camera modes\r
1125 vector camera_offset, current_camera_offset, mouse_angles, current_angles, current_origin, current_position;\r
1126 void CSQC_Demo_Camera()\r
1127 {\r
1128         float speed, attenuation, dimensions;\r
1129         vector tmp, delta;\r
1130 \r
1131         if( cvar("camera_reset") || !camera_mode )\r
1132         {\r
1133                 camera_offset = '0 0 0';\r
1134                 current_angles = '0 0 0';\r
1135                 camera_direction = '0 0 0';\r
1136                 camera_offset_z += 30;\r
1137                 camera_offset_x += 30 * -cos(current_angles_y * DEG2RAD);\r
1138                 camera_offset_y += 30 * -sin(current_angles_y * DEG2RAD);\r
1139                 current_origin = view_origin;\r
1140                 current_camera_offset  = camera_offset;\r
1141                 cvar_set("camera_reset", "0");\r
1142                 camera_mode = CAMERA_CHASE;\r
1143         }\r
1144 \r
1145         // Camera angles\r
1146         if( camera_roll )\r
1147                 mouse_angles_z += camera_roll * cvar("camera_speed_roll");\r
1148 \r
1149         if(cvar("camera_look_player"))\r
1150         {\r
1151                 local vector dir;\r
1152                 local float n;\r
1153 \r
1154                 dir = normalize(view_origin - current_position);\r
1155                 n = mouse_angles_z;\r
1156                 mouse_angles = vectoangles(dir);\r
1157                 mouse_angles_x = mouse_angles_x * -1;\r
1158                 mouse_angles_z = n;\r
1159         }\r
1160         else\r
1161         {\r
1162                 tmp = getmousepos() * 0.1;\r
1163                 if(vlen(tmp)>cvar("camera_mouse_treshold"))\r
1164                 {\r
1165                         mouse_angles_x += tmp_y * cos(mouse_angles_z * DEG2RAD) + (tmp_x * sin(mouse_angles_z * DEG2RAD));\r
1166                         mouse_angles_y -= tmp_x * cos(mouse_angles_z * DEG2RAD) + (tmp_y * -sin(mouse_angles_z * DEG2RAD));\r
1167                 }\r
1168         }\r
1169 \r
1170         while (mouse_angles_x < -180) mouse_angles_x = mouse_angles_x + 360;\r
1171         while (mouse_angles_x > 180) mouse_angles_x = mouse_angles_x - 360;\r
1172         while (mouse_angles_y < -180) mouse_angles_y = mouse_angles_y + 360;\r
1173         while (mouse_angles_y > 180) mouse_angles_y = mouse_angles_y - 360;\r
1174 \r
1175         // Fix difference when angles don't have the same sign\r
1176         delta = '0 0 0';\r
1177         if(mouse_angles_y < -60 && current_angles_y > 60)\r
1178                 delta = '0 360 0';\r
1179         if(mouse_angles_y > 60 && current_angles_y < -60)\r
1180                 delta = '0 -360 0';\r
1181 \r
1182         if(cvar("camera_look_player"))\r
1183                 attenuation = cvar("camera_look_attenuation");\r
1184         else\r
1185                 attenuation = cvar("camera_speed_attenuation");\r
1186 \r
1187         attenuation = 1 / max(1, attenuation);\r
1188         current_angles += (mouse_angles - current_angles + delta) * attenuation;\r
1189 \r
1190         while (current_angles_x < -180) current_angles_x = current_angles_x + 360;\r
1191         while (current_angles_x > 180) current_angles_x = current_angles_x - 360;\r
1192         while (current_angles_y < -180) current_angles_y = current_angles_y + 360;\r
1193         while (current_angles_y > 180) current_angles_y = current_angles_y - 360;\r
1194 \r
1195         // Camera position\r
1196         tmp = '0 0 0';\r
1197         dimensions = 0;\r
1198 \r
1199         if( camera_direction_x )\r
1200         {\r
1201                 tmp_x = camera_direction_x * cos(current_angles_y * DEG2RAD);\r
1202                 tmp_y = camera_direction_x * sin(current_angles_y * DEG2RAD);\r
1203                 if( cvar("camera_forward_follows") && !cvar("camera_look_player") )\r
1204                         tmp_z = camera_direction_x * -sin(current_angles_x * DEG2RAD);\r
1205                 ++dimensions;\r
1206         }\r
1207 \r
1208         if( camera_direction_y )\r
1209         {\r
1210                 tmp_x += camera_direction_y * -sin(current_angles_y * DEG2RAD);\r
1211                 tmp_y += camera_direction_y * cos(current_angles_y * DEG2RAD) * cos(current_angles_z * DEG2RAD);\r
1212                 tmp_z += camera_direction_y * sin(current_angles_z * DEG2RAD);\r
1213                 ++dimensions;\r
1214         }\r
1215 \r
1216         if( camera_direction_z )\r
1217         {\r
1218                 tmp_z += camera_direction_z * cos(current_angles_z * DEG2RAD);\r
1219                 ++dimensions;\r
1220         }\r
1221 \r
1222         if(cvar("camera_free"))\r
1223                 speed = cvar("camera_speed_free");\r
1224         else\r
1225                 speed = cvar("camera_speed_chase");\r
1226 \r
1227         if(dimensions)\r
1228         {\r
1229                 speed = speed * sqrt(1 / dimensions);\r
1230                 camera_offset += tmp * speed;\r
1231         }\r
1232 \r
1233         current_camera_offset += (camera_offset - current_camera_offset) * attenuation;\r
1234 \r
1235         // Camera modes\r
1236         if( cvar("camera_free") )\r
1237         {\r
1238                 if ( camera_mode == CAMERA_CHASE )\r
1239                 {\r
1240                         current_camera_offset = current_origin + current_camera_offset;\r
1241                         camera_offset = current_origin + camera_offset;\r
1242                 }\r
1243 \r
1244                 camera_mode = CAMERA_FREE;\r
1245                 current_position = current_camera_offset;\r
1246         }\r
1247         else\r
1248         {\r
1249                 if ( camera_mode == CAMERA_FREE )\r
1250                 {\r
1251                         current_origin = view_origin;\r
1252                         camera_offset = camera_offset - current_origin;\r
1253                         current_camera_offset = current_camera_offset - current_origin;\r
1254                 }\r
1255 \r
1256                 camera_mode = CAMERA_CHASE;\r
1257 \r
1258                 if(cvar("camera_chase_smoothly"))\r
1259                         current_origin += (view_origin - current_origin) * attenuation;\r
1260                 else\r
1261                         current_origin = view_origin;\r
1262 \r
1263                 current_position = current_origin + current_camera_offset;\r
1264         }\r
1265 \r
1266         R_SetView(VF_ANGLES, current_angles);\r
1267         R_SetView(VF_ORIGIN, current_position);\r
1268 }\r