]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/client/View.qc
Base blur amount on swallow progress. The screen will blur at full configured intensi...
[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         vecs = decompressShotOrigin(getstati(STAT_SHOTORG));\r
207 \r
208         traceline(view_origin, view_origin + view_forward * MAX_SHOT_DISTANCE, mv, ta);\r
209         trueaimpoint = trace_endpos;\r
210 \r
211         if(vecs_x > 0)\r
212                 vecs_y = -vecs_y;\r
213         else\r
214                 vecs = '0 0 0';\r
215 \r
216         dv = view_right * vecs_y + view_up * vecs_z;\r
217         w_shotorg = view_origin + dv;\r
218 \r
219         // now move the vecs forward as much as requested if possible\r
220         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
221         w_shotorg = trace_endpos - view_forward * nudge;\r
222 \r
223         tracebox(w_shotorg, mi, ma, trueaimpoint, MOVE_NORMAL, ta);\r
224         shottype = EnemyHitCheck();\r
225         if(shottype != SHOTTYPE_HITWORLD)\r
226                 return shottype;\r
227 \r
228 #if 0\r
229         // FIXME WHY DOES THIS NOT WORK FOR THE ROCKET LAUNCHER?\r
230         // or rather, I know why, but see no fix\r
231         if(vlen(trace_endpos - trueaimpoint) > vlen(ma) + vlen(mi) + 1)\r
232                 // 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
233                 return SHOTTYPE_HITOBSTRUCTION;\r
234 #endif\r
235 \r
236         return SHOTTYPE_HITWORLD;\r
237 }\r
238 \r
239 void CSQC_common_hud(void);\r
240 \r
241 void CSQC_kh_hud(void);\r
242 void CSQC_ctf_hud(void);\r
243 void PostInit(void);\r
244 void CSQC_Demo_Camera();\r
245 float Sbar_WouldDrawScoreboard ();\r
246 float last_health, last_spectatee;\r
247 float camera_mode;\r
248 float reticle_type;\r
249 float chase_active_old;\r
250 float artwork_fade;\r
251 float pickup_crosshair_time, pickup_crosshair_size, pickup_flash_time, vore_flash_laststate;\r
252 float spawnfov_current;\r
253 float myhealth, myhealth_prev, myhealth_flash;\r
254 float contentavgalpha, liquidalpha_prev;\r
255 float old_blurradius, old_bluralpha, old_cartoon_intensity;\r
256 float stomachsplash_alpha;\r
257 float eventchase_current_distance;\r
258 float helper_pause, helper_health, helper_armor, helper_ammo, helper_speed, helper_stomachload;\r
259 vector freeze_org, freeze_ang;\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         float a;\r
273         float respawned;\r
274 \r
275         vector reticle_pos, reticle_size;\r
276         vector splash_pos, splash_size;\r
277         vector artwork_pos, artwork_size;\r
278 \r
279         WaypointSprite_Load();\r
280 \r
281         if(spectatee_status)\r
282                 myteam = GetPlayerColor(spectatee_status - 1);\r
283         else\r
284                 myteam = GetPlayerColor(player_localentnum - 1);\r
285 \r
286         ticrate = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);\r
287         vo = '0 0 1' * getstati(STAT_VIEWHEIGHT);\r
288 \r
289         warpzone_fixview_origin = pmove_org + vo;\r
290         warpzone_fixview_angles = input_angles;\r
291         WarpZone_FixView();\r
292         pmove_org = warpzone_fixview_origin - vo;\r
293         input_angles = warpzone_fixview_angles;\r
294 \r
295         if((last_health <= 0 && getstati(STAT_HEALTH) > 0) || (!spectatee_status && last_spectatee)) // also cover switching from a spectator to a player instantly\r
296         if not(spectatee_status && last_spectatee != spectatee_status) // not if we switched players and that detects a different health\r
297                 respawned = TRUE; // stays true for one frame\r
298 \r
299         // helper system\r
300         if(cvar("cl_helper"))\r
301         if not(getstati(STAT_ARMOR) < g_power || time <= power_boot)\r
302         {\r
303                 if(intermission || respawned || spectatee_status < 0 || getstati(STAT_HEALTH) <= 0 || getstati(STAT_VORE_EATEN))\r
304                 {\r
305                         // Set these helper messages as having been triggered, so that the player must first reach them before they complain.\r
306                         // Otherwise, if you don't have any start armor for instance, the helper will complain about low armor when we spawn.\r
307                         helper_health = TRUE;\r
308                         helper_armor = TRUE;\r
309                         helper_ammo = TRUE;\r
310                         helper_stomachload = TRUE;\r
311                 }\r
312                 else if(helper_pause <= time)\r
313                 {\r
314                         // health helper\r
315                         if(getstati(STAT_HEALTH) <= cvar("cl_helper_item_health"))\r
316                         {\r
317                                 if(cvar("cl_helper_item_health") && !helper_health)\r
318                                 {\r
319                                         sound(self, CHAN_VOICE, strcat("helper/", cvar_string("cl_helper_voice"), "/health.wav"), VOL_BASEVOICE, ATTN_NONE);\r
320                                         helper_health = TRUE;\r
321                                         helper_pause = time + cvar("cl_helper_pause");\r
322                                         helper_ammo = time + cvar("cl_helper_pause");\r
323                                 }\r
324                         }\r
325                         else if(helper_health)\r
326                                 helper_health = FALSE;\r
327 \r
328                         // armor helper\r
329                         if(getstati(STAT_ARMOR) <= cvar("cl_helper_item_armor"))\r
330                         {\r
331                                 if(cvar("cl_helper_item_armor") && !helper_armor)\r
332                                 {\r
333                                         sound(self, CHAN_VOICE, strcat("helper/", cvar_string("cl_helper_voice"), "/armor.wav"), VOL_BASEVOICE, ATTN_NONE);\r
334                                         helper_armor = TRUE;\r
335                                         helper_pause = time + cvar("cl_helper_pause");\r
336                                 }\r
337                         }\r
338                         else if(helper_armor)\r
339                                 helper_armor = FALSE;\r
340 \r
341                         // ammo helper\r
342                         if(getstati(STAT_FUEL) <= cvar("cl_helper_item_ammo_fuel"))\r
343                         {\r
344                                 if(cvar("cl_helper_item_ammo_fuel") && !helper_ammo)\r
345                                 {\r
346                                         sound(self, CHAN_VOICE, strcat("helper/", cvar_string("cl_helper_voice"), "/ammo.wav"), VOL_BASEVOICE, ATTN_NONE);\r
347                                         helper_ammo = TRUE;\r
348                                         helper_pause = time + cvar("cl_helper_pause");\r
349                                 }\r
350                         }\r
351                         else if(helper_ammo)\r
352                                 helper_ammo = FALSE;\r
353 \r
354                         // speed helper\r
355                         if(vlen(pmove_vel) >= cvar("cl_helper_item_speed"))\r
356                         {\r
357                                 if(cvar("cl_helper_item_speed") && !helper_speed)\r
358                                 {\r
359                                         sound(self, CHAN_VOICE, strcat("helper/", cvar_string("cl_helper_voice"), "/speed.wav"), VOL_BASEVOICE, ATTN_NONE);\r
360                                         helper_speed = TRUE;\r
361                                         helper_pause = time + cvar("cl_helper_pause");\r
362                                 }\r
363                         }\r
364                         else if(helper_speed)\r
365                                 helper_speed = FALSE;\r
366 \r
367                         // stomach load helper\r
368                         if(getstati(STAT_VORE_LOAD) / getstati(STAT_VORE_MAXLOAD) >= cvar("cl_helper_item_stomachload"))\r
369                         {\r
370                                 if(cvar("cl_helper_item_stomachload") && !helper_stomachload)\r
371                                 {\r
372                                         sound(self, CHAN_VOICE, strcat("helper/", cvar_string("cl_helper_voice"), "/stomachload.wav"), VOL_BASEVOICE, ATTN_NONE);\r
373                                         helper_stomachload = TRUE;\r
374                                         helper_pause = time + cvar("cl_helper_pause");\r
375                                 }\r
376                         }\r
377                         else if(helper_stomachload)\r
378                                 helper_stomachload = FALSE;\r
379                 }\r
380         }\r
381 \r
382         // event chase camera\r
383         if(cvar("chase_active") <= 0) // greater than 0 means it's enabled manually, and this code is skipped\r
384         {\r
385                 if(spectatee_status >= 0 && (cvar("cl_eventchase_death") && getstati(STAT_HEALTH) <= 0 && !intermission && !getstati(STAT_VORE_EATEN)) || intermission)\r
386                 {\r
387                         // make special vector since we can't use view_origin (It is one frame old as of this code, it gets set later with the results this code makes.)\r
388                         vector current_view_origin = getpropertyvec(VF_ORIGIN);\r
389                         \r
390                         // We must enable chase_active to get a third person view (weapon viewmodel hidden and own player model showing).\r
391                         // Ideally, there should be another way to enable third person cameras, such as through setproperty()\r
392                         if(!cvar("chase_active"))\r
393                                 cvar_set("chase_active", "-1"); // -1 enables chase_active while marking it as set by this code, and not by the user (which would be 1)\r
394 \r
395                         // make the camera smooth back\r
396                         if(cvar("cl_eventchase_speed") && eventchase_current_distance < cvar("cl_eventchase_distance"))\r
397                                 eventchase_current_distance += cvar("cl_eventchase_speed") * (cvar("cl_eventchase_distance") - eventchase_current_distance) * frametime; // slow down the further we get\r
398                         else if(eventchase_current_distance != cvar("cl_eventchase_distance"))\r
399                                 eventchase_current_distance = cvar("cl_eventchase_distance");\r
400 \r
401                         vector eventchase_target_origin;\r
402                         makevectors(view_angles);\r
403                         // pass 1, used to check where the camera would go and obtain the trace_fraction\r
404                         eventchase_target_origin = current_view_origin - v_forward * eventchase_current_distance;\r
405                         WarpZone_TraceLine(current_view_origin, eventchase_target_origin, MOVE_WORLDONLY, self);\r
406                         // pass 2, also multiplying view_forward with trace_fraction, to prevent the camera from going through walls\r
407                         // The 0.1 subtraction is to not limit the camera precisely at the wall surface, as that allows the view to poke through\r
408                         eventchase_target_origin = current_view_origin - v_forward * eventchase_current_distance * (trace_fraction - 0.1);\r
409                         WarpZone_TraceLine(current_view_origin, eventchase_target_origin, MOVE_WORLDONLY, self);\r
410 \r
411                         setproperty(VF_ORIGIN, trace_endpos);\r
412                         setproperty(VF_ANGLES, WarpZone_TransformVAngles(WarpZone_trace_transform, view_angles));\r
413                 }\r
414                 else if(cvar("chase_active") < 0) // time to disable chase_active if it was set by this code\r
415                 {\r
416                         cvar_set("chase_active", "0");\r
417                         eventchase_current_distance = 0; // start from 0 next time\r
418                 }\r
419         }\r
420 \r
421         if(frametime)\r
422         {\r
423                 float apply_fov;\r
424                 apply_fov = cvar("menu_fov");\r
425                 if(g_healthsize_center >= 0 && cvar("cl_healthsize_fov") && spectatee_status >= 0)\r
426                         apply_fov += (g_healthsize_center - bound(g_healthsize_min, getstati(STAT_HEALTH), g_healthsize_max)) * cvar("cl_healthsize_fov");\r
427                 if(cvar("fov") != apply_fov)\r
428                         cvar_set("fov", ftos(apply_fov));\r
429         }\r
430 \r
431         float apply_idlescale;\r
432         if(cvar("cl_vore_vieweffects_idlescale_prey") && frametime)\r
433         {\r
434                 apply_idlescale += getstatf(STAT_VORE_PROGRESS_PREY) * cvar("cl_vore_vieweffects_idlescale_prey");\r
435                 if(cvar("v_idlescale") != apply_idlescale)\r
436                         cvar_set("v_idlescale", ftos(apply_idlescale));\r
437         }\r
438         if(cvar("cl_vore_vieweffects_idlescale_predator") && frametime)\r
439         {\r
440                 apply_idlescale += getstatf(STAT_VORE_PROGRESS_PRED) * cvar("cl_vore_vieweffects_idlescale_predator");\r
441                 if(cvar("v_idlescale") != apply_idlescale)\r
442                         cvar_set("v_idlescale", ftos(apply_idlescale));\r
443         }\r
444         if(cvar("cl_vore_vieweffects_idlescale_stomach") && frametime)\r
445         {\r
446                 apply_idlescale += getstati(STAT_VORE_EATEN) * cvar("cl_vore_vieweffects_idlescale_stomach");\r
447                 if(cvar("v_idlescale") != apply_idlescale)\r
448                         cvar_set("v_idlescale", ftos(apply_idlescale));\r
449         }\r
450 \r
451         // do lockview after event chase camera so that it still applies whenever necessary.\r
452         if(intermission > 1)\r
453         {\r
454                 setproperty(VF_ORIGIN, freeze_org);\r
455                 setproperty(VF_ANGLES, freeze_ang);\r
456         }\r
457         else\r
458         {\r
459                 freeze_org = getpropertyvec(VF_ORIGIN);\r
460                 freeze_ang = getpropertyvec(VF_ANGLES);\r
461         }\r
462 \r
463         // Render the Scene\r
464         view_origin = getpropertyvec(VF_ORIGIN);\r
465         view_angles = getpropertyvec(VF_ANGLES);\r
466         makevectors(view_angles);\r
467         view_forward = v_forward;\r
468         view_right = v_right;\r
469         view_up = v_up;\r
470 \r
471         vid_width = w;\r
472         vid_height = h;\r
473 \r
474 #ifdef BLURTEST\r
475         if(time > blurtest_time0 && time < blurtest_time1)\r
476         {\r
477                 float r, t;\r
478 \r
479                 t = (time - blurtest_time0) / (blurtest_time1 - blurtest_time0);\r
480                 r = t * blurtest_radius;\r
481                 f = 1 / pow(t, blurtest_power) - 1;\r
482 \r
483                 cvar_set("r_glsl_postprocess", "1");\r
484                 cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(r), " ", ftos(f), " 0 0"));\r
485         }\r
486         else\r
487         {\r
488                 cvar_set("r_glsl_postprocess", "0");\r
489                 cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");\r
490         }\r
491 #endif\r
492 \r
493         TargetMusic_Advance();\r
494         Fog_Force();\r
495 \r
496         drawframetime = max(0.000001, time - drawtime);\r
497         drawtime = time;\r
498 \r
499         // watch for gametype changes here...\r
500         // in ParseStuffCMD the cmd isn't executed yet :/\r
501         // might even be better to add the gametype to TE_CSQC_INIT...?\r
502         if(!postinit)\r
503                 PostInit();\r
504 \r
505         if(intermission && !isdemo() && !(calledhooks & HOOK_END))\r
506                 if(calledhooks & HOOK_START)\r
507                 {\r
508                         localcmd("\ncl_hook_gameend;");\r
509                         if(g_campaign)\r
510                                 localcmd("\ncl_hook_campaign_gameend;");\r
511                         calledhooks |= HOOK_END;\r
512                 }\r
513 \r
514         CheckForGamestartChange();\r
515         serverAnnouncer();\r
516         maptimeAnnouncer();\r
517         carrierAnnouncer();\r
518 \r
519         fov = cvar("fov");\r
520         if(button_zoom || fov <= 59.5)\r
521         {\r
522                 if(!zoomscript_caught)\r
523                 {\r
524                         localcmd("+button4\n");\r
525                         zoomscript_caught = 1;\r
526                         ignore_plus_zoom += 1;\r
527                 }\r
528         }\r
529         else\r
530         {\r
531                 if(zoomscript_caught)\r
532                 {\r
533                         localcmd("-button4\n");\r
534                         zoomscript_caught = 0;\r
535                         ignore_minus_zoom += 1;\r
536                 }\r
537         }\r
538 \r
539         sbar_alpha_fg = cvar("sbar_alpha_fg" ) * (1 - cvar("_menu_alpha"));\r
540         sbar_hudselector = cvar("sbar_hudselector");\r
541         sbar_accuracy_hud = cvar_or("sbar_accuracy_hud", 1);\r
542         ColorTranslateMode = cvar("cl_stripcolorcodes");\r
543         activeweapon = getstati(STAT_SWITCHWEAPON);\r
544         f = cvar("teamplay");\r
545         if(f != teamplay)\r
546         {\r
547                 teamplay = f;\r
548                 Sbar_InitScores();\r
549         }\r
550 \r
551         if(last_weapon != activeweapon) {\r
552                 weapontime = time;\r
553                 last_weapon = activeweapon;\r
554         }\r
555 \r
556         // ALWAYS Clear Current Scene First\r
557         R_ClearScene();\r
558 \r
559         if(checkextension("DP_CSQC_ROTATEMOVES"))\r
560         {\r
561                 setproperty(VF_ORIGIN, view_origin);\r
562                 setproperty(VF_ANGLES, view_angles);\r
563         }\r
564 \r
565         // Assign Standard Viewflags\r
566         // Draw the World (and sky)\r
567         setproperty(VF_DRAWWORLD, 1);\r
568 \r
569         // Set the console size vars\r
570         vid_conwidth = cvar("vid_conwidth");\r
571         vid_conheight = cvar("vid_conheight");\r
572         vid_pixelheight = cvar("vid_pixelheight");\r
573 \r
574         // spawn fov effect\r
575         if(cvar("cl_spawnfov"))\r
576         {\r
577                 if(respawned)\r
578                         spawnfov_current = 1 + cvar("cl_spawnfov");\r
579 \r
580                 if(spawnfov_current > 1)\r
581                         spawnfov_current -= cvar("cl_spawnfov_speed") * frametime;\r
582                 else\r
583                         spawnfov_current = 1;\r
584                 fov *= spawnfov_current;\r
585         }\r
586 \r
587         if(respawned)\r
588         {\r
589                 if(g_power_reboot_spawn)\r
590                         power_boot = time + g_power_reboot;\r
591                 else\r
592                         power_boot = time;\r
593         }\r
594 \r
595         setproperty(VF_FOV, GetCurrentFov(fov));\r
596 \r
597         // Camera for demo playback\r
598         if(camera_active)\r
599         {\r
600                 if(cvar("camera_enable"))\r
601                         CSQC_Demo_Camera();\r
602                 else\r
603                 {\r
604                         cvar_set("chase_active", ftos(chase_active_backup));\r
605                         cvar_set("cl_demo_mousegrab", "0");\r
606                         camera_active = FALSE;\r
607                 }\r
608         }\r
609 #ifdef CAMERATEST\r
610         else if(cvar("camera_enable"))\r
611 #else\r
612         else if(cvar("camera_enable") && isdemo())\r
613 #endif\r
614         {\r
615                 // Enable required Darkplaces cvars\r
616                 chase_active_backup = cvar("chase_active");\r
617                 cvar_set("chase_active", "2");\r
618                 cvar_set("cl_demo_mousegrab", "1");\r
619                 camera_active = TRUE;\r
620                 camera_mode = FALSE;\r
621         }\r
622 \r
623         // Draw the Crosshair\r
624         float scoreboard_active;\r
625         scoreboard_active = Sbar_WouldDrawScoreboard();\r
626         setproperty(VF_DRAWCROSSHAIR, 0); //Make sure engine crosshairs are always hidden\r
627 \r
628         // Draw the Engine Status Bar (the default Quake HUD)\r
629         setproperty(VF_DRAWENGINESBAR, 0);\r
630 \r
631         // fetch this one only once per frame\r
632         sbar_showbinds = cvar("sbar_showbinds");\r
633         sbar_showbinds_limit = cvar("sbar_showbinds_limit");\r
634 \r
635         // Update the mouse position\r
636         /*\r
637            mousepos_x = vid_conwidth;\r
638            mousepos_y = vid_conheight;\r
639            mousepos = mousepos*0.5 + getmousepos();\r
640          */\r
641 \r
642         e = self;\r
643         for(self = world; (self = nextent(self)); )\r
644                 if(self.draw)\r
645                         self.draw();\r
646         self = e;\r
647 \r
648         R_AddEntities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS);\r
649         R_RenderScene();\r
650 \r
651         // now switch to 2D drawing mode by calling a 2D drawing function\r
652         // then polygon drawing will draw as 2D stuff, and NOT get queued until the\r
653         // next R_RenderScene call\r
654         drawstring('0 0 0', "", '1 1 0', '1 1 1', 0, 0);\r
655 \r
656         // Draw the aiming reticle for weapons that use it\r
657         // reticle_type is changed to the item we are zooming / aiming with, to decide which reticle to use\r
658         // It must be a persisted float for fading out to work properly (you let go of the zoom button for\r
659         // the view to go back to normal, so reticle_type would become 0 as we fade out)\r
660         if(spectatee_status || getstati(STAT_HEALTH) <= 0)\r
661                 reticle_type = 0; // prevent reticle from showing during the respawn zoom effect or for spectators\r
662         else if(activeweapon && (button_zoom || zoomscript_caught))\r
663                 reticle_type = 2; // weapon zoom\r
664         else if(button_zoom || zoomscript_caught)\r
665                 reticle_type = 1; // normal zoom\r
666 \r
667         if (reticle_type)\r
668         {\r
669                 if(cvar("cl_reticle_stretch"))\r
670                 {\r
671                         reticle_size_x = vid_conwidth;\r
672                         reticle_size_y = vid_conheight;\r
673                         reticle_pos_x = 0;\r
674                         reticle_pos_y = 0;\r
675                 }\r
676                 else\r
677                 {\r
678                         reticle_size_x = max(vid_conwidth, vid_conheight);\r
679                         reticle_size_y = max(vid_conwidth, vid_conheight);\r
680                         reticle_pos_x = (vid_conwidth - reticle_size_x) / 2;\r
681                         reticle_pos_y = (vid_conheight - reticle_size_y) / 2;\r
682                 }\r
683 \r
684                 f = current_zoomfraction;\r
685                 if(zoomscript_caught)\r
686                         f = 1;\r
687                 if(cvar("cl_reticle_item_normal"))\r
688                 {\r
689                         if(reticle_type == 1 && f)\r
690                                 drawpic(reticle_pos, "gfx/reticle_normal", reticle_size, '1 1 1', f * cvar("cl_reticle_item_normal"), DRAWFLAG_NORMAL);\r
691                 }\r
692                 if(cvar("cl_reticle_item_weapon"))\r
693                 {\r
694                         if(reticle_type == 2 && f)\r
695                                 drawpic(reticle_pos, "gfx/reticle_weapon", reticle_size, '1 1 1', f * cvar("cl_reticle_item_weapon"), DRAWFLAG_NORMAL);\r
696                 }\r
697         }\r
698 \r
699         // screen effects\r
700         if(cvar("hud_contents"))\r
701         {\r
702                 float contentalpha_temp, incontent, liquidalpha, contentfadetime;\r
703                 vector liquidcolor;\r
704 \r
705                 if (getstati(STAT_VORE_EATEN))\r
706                 {\r
707                         liquidalpha = cvar("hud_contents_stomach_alpha");\r
708                         liquidcolor = stov(cvar_string("hud_contents_stomach_color"));\r
709                         incontent = 1;\r
710                 }\r
711                 else if(getstatf(STAT_VORE_PROGRESS_PREY))\r
712                 {\r
713                         liquidalpha = cvar("hud_contents_swallow_alpha");\r
714                         liquidcolor = stov(cvar_string("hud_contents_swallow_color"));\r
715                         incontent = getstatf(STAT_VORE_PROGRESS_PREY); // based on the swallow progress\r
716                 }\r
717                 else\r
718                 {\r
719                         switch(pointcontents(view_origin))\r
720                         {\r
721                                 case CONTENT_WATER:\r
722                                         liquidalpha = cvar("hud_contents_water_alpha");\r
723                                         liquidcolor = stov(cvar_string("hud_contents_water_color"));\r
724                                         incontent = 1;\r
725                                         break;\r
726                                         \r
727                                 case CONTENT_LAVA:\r
728                                         liquidalpha = cvar("hud_contents_lava_alpha");\r
729                                         liquidcolor = stov(cvar_string("hud_contents_lava_color"));\r
730                                         incontent = 1;\r
731                                         break;  \r
732                                                                 \r
733                                 case CONTENT_SLIME:\r
734                                         liquidalpha = cvar("hud_contents_slime_alpha");\r
735                                         liquidcolor = stov(cvar_string("hud_contents_slime_color"));\r
736                                         incontent = 1;\r
737                                         break;\r
738                                         \r
739                                 default:\r
740                                         liquidalpha = 0;\r
741                                         liquidcolor = '0 0 0';\r
742                                         incontent = 0;\r
743                                         break;\r
744                         }\r
745                 }\r
746                 \r
747                 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
748                 { // also lets delcare previous values for blending properties, this way it isn't reset until after you have entered a different content\r
749                         contentfadetime = cvar("hud_contents_fadeintime");\r
750                         liquidalpha_prev = liquidalpha;\r
751                         liquidcolor_prev = liquidcolor;\r
752                 }\r
753                 else\r
754                         contentfadetime = cvar("hud_contents_fadeouttime");\r
755                         \r
756                 contentalpha_temp = bound(0, drawframetime / max(0.0001, contentfadetime), 1);\r
757                 contentavgalpha = contentavgalpha * (1 - contentalpha_temp) + incontent * contentalpha_temp;\r
758 \r
759                 if(contentavgalpha)\r
760                         drawfill('0 0 0', '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, liquidcolor_prev, contentavgalpha * liquidalpha_prev, DRAWFLAG_NORMAL);\r
761 \r
762                 if(cvar("hud_postprocessing"))\r
763                 {\r
764                         if(cvar("hud_contents_liquid_blur") && contentavgalpha)\r
765                         {\r
766                                 // when inside the stomach, we use different blur settings than when we're inside other fluids\r
767                                 content_blurpostprocess_x = 1;\r
768                                 if(getstati(STAT_VORE_EATEN))\r
769                                 {\r
770                                         content_blurpostprocess_y = contentavgalpha * cvar("hud_contents_stomach_blur");\r
771                                         content_blurpostprocess_z = contentavgalpha * cvar("hud_contents_stomach_blur_alpha");\r
772                                 }\r
773                                 else\r
774                                 {\r
775                                         content_blurpostprocess_y = contentavgalpha * cvar("hud_contents_liquid_blur");\r
776                                         content_blurpostprocess_z = contentavgalpha * cvar("hud_contents_liquid_blur_alpha");\r
777                                 }\r
778                         }\r
779                         else\r
780                         {\r
781                                 content_blurpostprocess_x = 0;\r
782                                 content_blurpostprocess_y = 0;\r
783                                 content_blurpostprocess_z = 0;\r
784                         }\r
785                 }\r
786         }\r
787 \r
788         if(cvar("hud_damage"))\r
789         {\r
790                 splash_size_x = max(vid_conwidth, vid_conheight);\r
791                 splash_size_y = max(vid_conwidth, vid_conheight);\r
792                 splash_pos_x = (vid_conwidth - splash_size_x) / 2;\r
793                 splash_pos_y = (vid_conheight - splash_size_y) / 2;\r
794 \r
795                 float myhealth_flash_temp;\r
796                 myhealth = getstati(STAT_HEALTH);\r
797 \r
798                 // fade out\r
799                 myhealth_flash = max(0, myhealth_flash - cvar("hud_damage_fade_rate") * frametime);\r
800                 // add new damage\r
801                 myhealth_flash = bound(0, myhealth_flash + dmg_take * cvar("hud_damage_factor"), cvar("hud_damage_maxalpha"));\r
802 \r
803                 float pain_threshold, pain_threshold_lower, pain_threshold_lower_health;\r
804                 pain_threshold = cvar("hud_damage_pain_threshold");\r
805                 pain_threshold_lower = cvar("hud_damage_pain_threshold_lower");\r
806                 pain_threshold_lower_health = cvar("hud_damage_pain_threshold_lower_health");\r
807 \r
808                 if(pain_threshold_lower && myhealth < pain_threshold_lower_health)\r
809                 {\r
810                         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
811                 }\r
812 \r
813                 myhealth_flash_temp = bound(0, myhealth_flash - pain_threshold, 1);\r
814 \r
815                 if(myhealth_prev < 1)\r
816                 {\r
817                         if(myhealth >= 1)\r
818                         {\r
819                                 myhealth_flash = 0; // just spawned, clear the flash immediately\r
820                                 myhealth_flash_temp = 0;\r
821                         }\r
822                         else\r
823                         {\r
824                                 myhealth_flash += cvar("hud_damage_fade_rate") * frametime; // dead\r
825                         }\r
826                 }\r
827 \r
828                 if(spectatee_status == -1 || intermission)\r
829                 {\r
830                         myhealth_flash = 0; // observing, or match ended\r
831                         myhealth_flash_temp = 0;\r
832                 }\r
833 \r
834                 myhealth_prev = myhealth;\r
835 \r
836                 if(cvar("cl_gentle_damage") || cvar("cl_gentle"))\r
837                 {\r
838                         if(cvar("cl_gentle_damage") == 2)\r
839                         {\r
840                                 if(myhealth_flash < pain_threshold) // only randomize when the flash is gone\r
841                                 {\r
842                                         myhealth_gentlergb = '1 0 0' * random() + '0 1 0' * random() + '0 0 1' * random();\r
843                                 }\r
844                         }\r
845                         else\r
846                                 myhealth_gentlergb = stov(cvar_string("hud_damage_gentle_color"));\r
847 \r
848                         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
849                 }\r
850                 else\r
851                         drawpic(splash_pos, "gfx/blood", splash_size, stov(cvar_string("hud_damage_color")), bound(0, myhealth_flash_temp, 1) * cvar("hud_damage"), DRAWFLAG_NORMAL);\r
852 \r
853                 if(cvar("hud_postprocessing"))\r
854                 {\r
855                         if(cvar("hud_damage_blur") && myhealth_flash_temp)\r
856                         {\r
857                                 damage_blurpostprocess_x = 1;\r
858                                 damage_blurpostprocess_y = bound(0, myhealth_flash_temp, 1) * cvar("hud_damage_blur");\r
859                                 damage_blurpostprocess_z = bound(0, myhealth_flash_temp, 1) * cvar("hud_damage_blur_alpha");\r
860                         }\r
861                         else\r
862                         {\r
863                                 damage_blurpostprocess_x = 0;\r
864                                 damage_blurpostprocess_y = 0;\r
865                                 damage_blurpostprocess_z = 0;\r
866                         }\r
867                 }\r
868         }\r
869 \r
870         if(cvar("hud_stomach"))\r
871         {\r
872                 if(getstati(STAT_VORE_EATEN))\r
873                 {\r
874                         if(stomachsplash_alpha < cvar("hud_stomach"))\r
875                                 stomachsplash_alpha += cvar("hud_stomach_fade_in") * frametime;\r
876                         else\r
877                                 stomachsplash_alpha = cvar("hud_stomach");\r
878                 }\r
879                 else if(getstati(STAT_HEALTH) > 0)\r
880                 {\r
881                         if(stomachsplash_alpha > 0)\r
882                                 stomachsplash_alpha -= cvar("hud_stomach_fade_out") * frametime;\r
883                         else\r
884                                 stomachsplash_alpha = 0;\r
885                 }\r
886 \r
887                 if(respawned)\r
888                         stomachsplash_alpha = 0; // we respawned, remove the effect\r
889                 if(spectatee_status == -1)\r
890                         stomachsplash_alpha = 0;\r
891 \r
892                 stomachsplash_alpha = bound(0, stomachsplash_alpha, 1);\r
893                 drawpic(splash_pos, "gfx/food", splash_size, stov(cvar_string("hud_stomach_color")), stomachsplash_alpha, DRAWFLAG_NORMAL);\r
894         }\r
895 \r
896         if(cvar("hud_postprocessing"))\r
897         {\r
898                 // all of this should be done in the engine eventually\r
899 \r
900                 // disable damage blur when dead, but keep content blur\r
901                 if(getstati(STAT_HEALTH) <= 0)\r
902                         damage_blurpostprocess = '0 0 0';\r
903 \r
904                 // enable or disable rendering types if they are used or not\r
905                 if(cvar("r_glsl_postprocess_uservec1_enable") != (cvar("hud_postprocessing_maxbluralpha") != 0))\r
906                         cvar_set("r_glsl_postprocess_uservec1_enable", ftos(cvar("hud_postprocessing_maxbluralpha") != 0));\r
907                 if(cvar("r_glsl_postprocess_uservec2_enable") != (cvar("hud_cartoon") != 0))\r
908                         cvar_set("r_glsl_postprocess_uservec2_enable", ftos(cvar("hud_cartoon") != 0));\r
909 \r
910                 // lets apply the postprocess effects from the previous two functions if needed\r
911                 if((damage_blurpostprocess_x || content_blurpostprocess_x) && cvar("chase_active") >= 0) // not while the event chase camera is active\r
912                 {\r
913                         float blurradius = bound(0, damage_blurpostprocess_y + content_blurpostprocess_y, cvar("hud_postprocessing_maxblurradius"));\r
914                         float bluralpha = bound(0, damage_blurpostprocess_z + content_blurpostprocess_z, cvar("hud_postprocessing_maxbluralpha"));\r
915                         if(blurradius != old_blurradius || bluralpha != old_bluralpha) // reduce cvar_set spam as much as possible\r
916                         {\r
917                                 cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(blurradius), " ", ftos(bluralpha), " 0 0"));\r
918                                 old_blurradius = blurradius;\r
919                                 old_bluralpha = bluralpha;\r
920                         }\r
921                 }\r
922                 else if(cvar_string("r_glsl_postprocess_uservec1") != "0 0 0 0") // reduce cvar_set spam as much as possible\r
923                 {\r
924                         cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");\r
925                         old_blurradius = 0;\r
926                         old_bluralpha = 0;\r
927                 }\r
928 \r
929                 if(cvar("hud_cartoon"))\r
930                 {\r
931                         // When having the strength or invincible powerups, cartoon lines will be white instead of black.\r
932                         // As powerup time goes under 5 seconds (warning time), lines will fade from white to nothing then from nothing back to black.\r
933                         float cartoon_intensity, cartoon_powerup;\r
934                         cartoon_intensity = -cvar("hud_cartoon");\r
935                         cartoon_powerup = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 5) + bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 5);\r
936                         cartoon_powerup = bound(0, cartoon_powerup, 5);\r
937                         if (cartoon_powerup && cvar("chase_active") >= 0) // not while the event chase camera is active\r
938                                 cartoon_intensity *= 1 - cartoon_powerup / 2.5; // cycle between -1 and 1\r
939 \r
940                         if(cartoon_intensity != old_cartoon_intensity) // reduce cvar_set spam as much as possible\r
941                         {\r
942                                 cvar_set("r_glsl_postprocess_uservec2", strcat("0 ", ftos(cartoon_intensity), " ", cvar_string("hud_cartoon_tolerance"), " 0"));\r
943                                 old_cartoon_intensity = cartoon_intensity;\r
944                         }\r
945                 }\r
946                 else if(cvar_string("r_glsl_postprocess_uservec2") != "0 0 0 0") // reduce cvar_set spam as much as possible\r
947                 {\r
948                         cvar_set("r_glsl_postprocess_uservec2", "0 0 0 0");\r
949                         old_cartoon_intensity = 0;\r
950                 }\r
951         }\r
952 \r
953         if(cvar("hud_postprocessing") && !cvar("hud_postprocessing_maxbluralpha"))\r
954         if(cvar("r_glsl_postprocess_uservec1_enable"))\r
955         {\r
956                 // don't allow blur to get stuck on if we disable the cvar while damaged\r
957                 cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");\r
958                 cvar_set("r_glsl_postprocess_uservec1_enable", "0");\r
959         }\r
960         if(cvar("hud_postprocessing") && !cvar("hud_cartoon"))\r
961         if(cvar("r_glsl_postprocess_uservec2_enable"))\r
962         {\r
963                 // don't allow sharpen to get stuck on if we disable the cvar while powered up\r
964                 cvar_set("r_glsl_postprocess_uservec2", "0 0 0 0");\r
965                 cvar_set("r_glsl_postprocess_uservec2_enable", "0");\r
966         }\r
967 \r
968         if(cvar("hud_postprocessing"))\r
969         {\r
970                 // change saturation based on the amount of armor we have\r
971                 // ranges between 0.5 and 1 saturation, over 0 armor and half the armor limit\r
972 \r
973                 if(cvar("hud_saturation") && armor_max && spectatee_status != -1 && getstati(STAT_HEALTH) > 0)\r
974                 {\r
975                         float saturation;\r
976                         saturation = 0.5 + (getstati(STAT_ARMOR) / armor_max);\r
977                         saturation = bound(0, saturation, 1);\r
978 \r
979                         if(cvar("r_glsl_saturation") != saturation)\r
980                                 cvar_set("r_glsl_saturation", ftos(saturation));\r
981                 }\r
982                 else if(cvar("r_glsl_saturation") != 1)\r
983                         cvar_set("r_glsl_saturation", "1");\r
984         }\r
985 \r
986         float target_volume;\r
987         if(cvar("cl_vore_cutvolume_sound") && frametime)\r
988         {\r
989                 // sound volume cutting\r
990                 target_volume = 0;\r
991                 if(getstatf(STAT_VORE_PROGRESS_PREY))\r
992                         target_volume = getstatf(STAT_VORE_PROGRESS_PREY);\r
993                 else if(getstati(STAT_VORE_EATEN))\r
994                         target_volume = 1;\r
995                 target_volume = cvar("menu_volume") * (1 - target_volume * cvar("cl_vore_cutvolume_sound"));\r
996 \r
997                 if(cvar("volume") != target_volume) // reduce cvar_set spam as much as possible\r
998                         cvar_set("volume", ftos(target_volume));\r
999         }\r
1000         if(cvar("cl_vore_cutvolume_music") && frametime)\r
1001         {\r
1002                 // music volume cutting\r
1003                 target_volume = 0;\r
1004                 if(getstatf(STAT_VORE_PROGRESS_PREY))\r
1005                         target_volume = getstatf(STAT_VORE_PROGRESS_PREY);\r
1006                 else if(getstati(STAT_VORE_EATEN))\r
1007                         target_volume = 1;\r
1008                 target_volume = cvar("menu_bgmvolume") * (1 - target_volume * cvar("cl_vore_cutvolume_music"));\r
1009 \r
1010                 if(cvar("bgmvolume") != target_volume) // reduce cvar_set spam as much as possible\r
1011                         cvar_set("bgmvolume", ftos(target_volume));\r
1012         }\r
1013 \r
1014         // Draw the mouse cursor\r
1015         // NOTE: drawpic must happen after R_RenderScene for some reason\r
1016         //drawpic(getmousepos(), "gfx/cursor.tga", '11 14 0', '1 1 1', 1, 0);\r
1017         //drawstring('50 50', ftos(game), '10 10 0', '1 1 1', 1, 0);\r
1018         //self = edict_num(player_localnum);\r
1019         //drawstring('0 0', vtos(pmove_org), '8 8 0', '1 1 1', 1, 0);\r
1020         //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
1021         // as long as the ctf part isn't in, this is useless\r
1022         if(menu_visible)\r
1023                 menu_show();\r
1024 \r
1025         /*if(gametype == GAME_CTF)\r
1026           {\r
1027           ctf_view();\r
1028           } else */\r
1029 \r
1030         // draw 2D entities\r
1031         e = self;\r
1032         for(self = world; (self = nextent(self)); )\r
1033                 if(self.draw2d)\r
1034                         self.draw2d();\r
1035         self = e;\r
1036         Draw_ShowNames_All();\r
1037 \r
1038         // draw radar\r
1039         if(\r
1040                         showmap\r
1041                         ||\r
1042                         (\r
1043                          !scoreboard_active\r
1044                          &&\r
1045                          cvar_string("cl_radar") != "0"\r
1046                          &&\r
1047                          (\r
1048                           cvar("cl_radar") == 2\r
1049                           ||\r
1050                           teamplay\r
1051                          )\r
1052                         )\r
1053           )\r
1054                 radar_view();\r
1055 \r
1056         // Draw artwork and play intermission music\r
1057         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
1058         {\r
1059                 if(cvar("cl_artwork"))\r
1060                 {\r
1061                         if(artwork_image == "")\r
1062                         {\r
1063                                 if(getstati(STAT_WINNING)) // we are the winner\r
1064                                 {\r
1065                                         if(cvar("cl_artwork_win"))\r
1066                                         {\r
1067                                                 artwork_image = strcat("gfx/artwork_won_", ftos(floor(1 + (random() * cvar("cl_artwork_win")))));\r
1068                                                 artwork_image = strzone(artwork_image);\r
1069                                         }\r
1070                                 }\r
1071                                 else // we have lost\r
1072                                 {\r
1073                                         if(cvar("cl_artwork_lose"))\r
1074                                         {\r
1075                                                 artwork_image = strcat("gfx/artwork_lost_", ftos(floor(1 + (random() * cvar("cl_artwork_lose")))));\r
1076                                                 artwork_image = strzone(artwork_image);\r
1077                                         }\r
1078                                 }\r
1079                         }\r
1080 \r
1081                         if(cvar("cl_artwork_stretch"))\r
1082                         {\r
1083                                 artwork_size_x = vid_conwidth;\r
1084                                 artwork_size_y = vid_conheight;\r
1085                                 artwork_pos_x = 0;\r
1086                                 artwork_pos_y = 0;\r
1087                         }\r
1088                         else\r
1089                         {\r
1090                                 artwork_size_x = max(vid_conwidth, vid_conheight);\r
1091                                 artwork_size_y = max(vid_conwidth, vid_conheight);\r
1092                                 artwork_pos_x = (vid_conwidth - artwork_size_x) / 2;\r
1093                                 artwork_pos_y = (vid_conheight - artwork_size_y) / 2;\r
1094                         }\r
1095 \r
1096                         if(artwork_fade < cvar("cl_artwork_alpha") && cvar("cl_artwork_fade"))\r
1097                                 artwork_fade += frametime * cvar("cl_artwork_fade");\r
1098                         else\r
1099                                 artwork_fade = cvar("cl_artwork_alpha");\r
1100 \r
1101                         if(artwork_image != "")\r
1102                                 drawpic(artwork_pos, artwork_image, artwork_size, '1 1 1', artwork_fade, DRAWFLAG_NORMAL);\r
1103                 }\r
1104 \r
1105                 if(cvar("cl_intermission") && intermission_song == "") // don't start the song each frame\r
1106                 {\r
1107                         if(getstati(STAT_WINNING))\r
1108                                 intermission_song = cvar_string("cl_intermission_cdtrack_win");\r
1109                         else\r
1110                                 intermission_song = cvar_string("cl_intermission_cdtrack_lose");\r
1111                         if(intermission_song != "")\r
1112                         {\r
1113                                 localcmd(strcat("\ncd play ", intermission_song, "\n"));\r
1114                                 intermission_song = strzone(intermission_song);\r
1115                         }\r
1116                 }\r
1117         }\r
1118         else\r
1119         {\r
1120                 artwork_fade = 0;\r
1121                 if(artwork_image != "")\r
1122                 {\r
1123                         strunzone(artwork_image);\r
1124                         artwork_image = "";\r
1125                 }\r
1126 \r
1127                 if(intermission_song != "")\r
1128                 {\r
1129                         strunzone(intermission_song);\r
1130                         intermission_song = "";\r
1131                 }\r
1132         }\r
1133 \r
1134         // draw sbar\r
1135         if(cvar("r_letterbox") == 0) {\r
1136                 if (cvar("cl_showpressedkeys")) { // draw pressed keys when spectating and playing\r
1137                         if(spectatee_status > 0 || cvar("cl_showpressedkeys") >= 2)\r
1138                                 Sbar_DrawPressedKeys();\r
1139                 }\r
1140 \r
1141                 if (cvar("cl_showspeed"))\r
1142                         Sbar_ShowSpeed();\r
1143                 if (cvar("cl_showacceleration"))\r
1144                         Sbar_ShowAcceleration();\r
1145 \r
1146                 Sbar_DrawCenterPrint(); // draw centerprint messages even if viewsize >= 120\r
1147         }\r
1148 \r
1149         float weapon_clipload, weapon_clipsize, ring_scale;\r
1150 \r
1151         float swallow_indicator;\r
1152         if(cvar("crosshair_swallowindicator"))\r
1153                 swallow_indicator = getstati(STAT_VORE_CANSWALLOW);\r
1154 \r
1155         float hud;\r
1156         hud = getstati(STAT_HUD);\r
1157 \r
1158         if(cvar("r_letterbox") == 0)\r
1159                 if(cvar("viewsize") < 120 && sbar_hudselector)\r
1160                         CSQC_common_hud();\r
1161 \r
1162         if(sbar_hudselector) // flashes require some HUD components to work\r
1163         {\r
1164                 if(cvar("cl_flash_pickup"))\r
1165                 if(pickup_flash_time < getstatf(STAT_LAST_PICKUP))\r
1166                 {\r
1167                         localcmd(strcat("bf ", cvar_string("cl_flash_pickup_color"), " ", cvar_string("cl_flash_pickup"), "\n"));\r
1168                         pickup_flash_time = getstatf(STAT_LAST_PICKUP);\r
1169                 }\r
1170                 if(cvar("cl_flash_vore"))\r
1171                 {\r
1172                         float vore_flash_state;\r
1173                         if(getstati(STAT_VORE_EATEN))\r
1174                                 vore_flash_state = -1;\r
1175                         else\r
1176                                 vore_flash_state = hud_total_prey;\r
1177 \r
1178                         if not(spectatee_status && last_spectatee != spectatee_status) // not if we switched players and that detects a different stomach load\r
1179                         {\r
1180                                 if(vore_flash_state > vore_flash_laststate && vore_flash_state > 0) // stomach load is bigger, so we ate someone\r
1181                                         localcmd(strcat("bf ", cvar_string("cl_flash_vore_color_pred"), " ", cvar_string("cl_flash_vore"), "\n"));\r
1182                                 if(vore_flash_state < vore_flash_laststate && vore_flash_state < 0) // -1 means we have been eaten\r
1183                                         localcmd(strcat("bf ", cvar_string("cl_flash_vore_color_prey"), " ", cvar_string("cl_flash_vore"), "\n"));\r
1184                         }\r
1185 \r
1186                         // always update the last vore state, or the flash can be triggered when switching spectated players one frame after\r
1187                         vore_flash_laststate = vore_flash_state;\r
1188                 }\r
1189                 if(cvar("cl_flash_respawn"))\r
1190                 if(respawned)\r
1191                         localcmd(strcat("bf ", cvar_string("cl_flash_respawn_color"), " ", cvar_string("cl_flash_respawn"), "\n"));\r
1192         }\r
1193 \r
1194         if not(getstati(STAT_VORE_EATEN)) // crosshair is useless if we're in the stomach\r
1195         if not(getstati(STAT_ARMOR) < g_power || time <= power_boot)\r
1196         {\r
1197                 // crosshair goes VERY LAST\r
1198                 if(!scoreboard_active && !showmap && !camera_active) {\r
1199                         // TrueAim check\r
1200                         float shottype;\r
1201                         // wcross_origin = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;\r
1202                         wcross_origin = project_3d_to_2d(view_origin + MAX_SHOT_DISTANCE * view_forward);\r
1203                         wcross_origin_z = 0;\r
1204                         if(cvar("crosshair_hittest"))\r
1205                         if(!swallow_indicator)\r
1206                         {\r
1207                                 vector wcross_oldorigin;\r
1208                                 wcross_oldorigin = wcross_origin;\r
1209                                 shottype = TrueAimCheck();\r
1210                                 if(shottype == SHOTTYPE_HITWORLD)\r
1211                                 {\r
1212                                         v = wcross_origin - wcross_oldorigin;\r
1213                                         v_x /= vid_conwidth;\r
1214                                         v_y /= vid_conheight;\r
1215                                         if(vlen(v) > 0.01)\r
1216                                                 shottype = SHOTTYPE_HITOBSTRUCTION;\r
1217                                 }\r
1218                                 if(!cvar("crosshair_hittest_showimpact"))\r
1219                                         wcross_origin = wcross_oldorigin;\r
1220                         }\r
1221                         else\r
1222                                 shottype = SHOTTYPE_HITWORLD;\r
1223 \r
1224                         string wcross_style;\r
1225 \r
1226                         if(swallow_indicator  > 1)\r
1227                                 wcross_style = "_canswallow_team.tga";\r
1228                         else if(swallow_indicator > 0)\r
1229                                 wcross_style = "_canswallow.tga";\r
1230                         else if(swallow_indicator < 0)\r
1231                                 wcross_style = "_canswallow_no.tga";\r
1232                         else\r
1233                         {\r
1234                                 // normal crosshair, based on what weapon we have and what firing type we can use\r
1235                                 if(!activeweapon)\r
1236                                         wcross_style = cvar_string("crosshair");\r
1237                                 else if(getstati(STAT_CROSSHAIR_STYLE))\r
1238                                         wcross_style = cvar_string("crosshair_secondary");\r
1239                                 else\r
1240                                         wcross_style = cvar_string("crosshair_primary");\r
1241                         }\r
1242 \r
1243                         if (wcross_style != "0") {\r
1244                                 vector wcross_color, wcross_size;\r
1245                                 string wcross_name;\r
1246                                 float wcross_alpha, wcross_scale, wcross_blur, wcross_resolution;\r
1247 \r
1248                                 if(swallow_indicator && (cvar("crosshair_swallowindicator_color_red") || cvar("crosshair_swallowindicator_color_green") || cvar("crosshair_swallowindicator_color_blue")))\r
1249                                 {\r
1250                                         wcross_color_x = cvar("crosshair_swallowindicator_color_red");\r
1251                                         wcross_color_y = cvar("crosshair_swallowindicator_color_green");\r
1252                                         wcross_color_z = cvar("crosshair_swallowindicator_color_blue");\r
1253                                 }\r
1254                                 else if(cvar("crosshair_color_by_health"))\r
1255                                 {\r
1256                                         local float x = getstati(STAT_HEALTH);\r
1257                                         \r
1258                                         //x = red\r
1259                                         //y = green\r
1260                                         //z = blue\r
1261                                         \r
1262                                         wcross_color_z = 0;\r
1263                                         \r
1264                                         if(x > 200)\r
1265                                         {\r
1266                                                 wcross_color_x = 0;\r
1267                                                 wcross_color_y = 1;\r
1268                                         }\r
1269                                         else if(x > 150)\r
1270                                         {\r
1271                                                 wcross_color_x = 0.4 - (x-150)*0.02 * 0.4;\r
1272                                                 wcross_color_y = 0.9 + (x-150)*0.02 * 0.1;\r
1273                                         }\r
1274                                         else if(x > 100)\r
1275                                         {\r
1276                                                 wcross_color_x = 1 - (x-100)*0.02 * 0.6;\r
1277                                                 wcross_color_y = 1 - (x-100)*0.02 * 0.1;\r
1278                                                 wcross_color_z = 1 - (x-100)*0.02;\r
1279                                         }\r
1280                                         else if(x > 50)\r
1281                                         {\r
1282                                                 wcross_color_x = 1;\r
1283                                                 wcross_color_y = 1;\r
1284                                                 wcross_color_z = 0.2 + (x-50)*0.02 * 0.8;  \r
1285                                         }\r
1286                                         else if(x > 20)\r
1287                                         {\r
1288                                                 wcross_color_x = 1;\r
1289                                                 wcross_color_y = (x-20)*90/27/100;\r
1290                                                 wcross_color_z = (x-20)*90/27/100 * 0.2;\r
1291                                         }\r
1292                                         else\r
1293                                         {\r
1294                                                 wcross_color_x = 1;\r
1295                                                 wcross_color_y = 0;\r
1296                                         }\r
1297                                 }\r
1298                                 else\r
1299                                         wcross_color = stov(cvar_string("crosshair_color"));\r
1300                                 wcross_alpha = cvar("crosshair_alpha");\r
1301                                 wcross_resolution = cvar("crosshair_size");\r
1302 \r
1303                                 if(!activeweapon)\r
1304                                 if(!swallow_indicator)\r
1305                                 {\r
1306                                         if(cvar("crosshair_unarmed_dim_color"))\r
1307                                                 wcross_color *= cvar("crosshair_unarmed_dim_color");\r
1308                                         if(cvar("crosshair_unarmed_dim_alpha"))\r
1309                                                 wcross_alpha *= cvar("crosshair_unarmed_dim_alpha");\r
1310                                 }\r
1311 \r
1312                                 wcross_name = strcat("gfx/crosshair", wcross_style);\r
1313 \r
1314                                 if(cvar("crosshair_effect_scalefade"))\r
1315                                 {\r
1316                                         wcross_scale = wcross_resolution;\r
1317                                         wcross_resolution = 1;\r
1318                                 }\r
1319                                 else\r
1320                                 {\r
1321                                         wcross_scale = 1;\r
1322                                 }\r
1323                                 if(swallow_indicator)\r
1324                                         wcross_scale *= cvar("crosshair_swallowindicator_size");\r
1325 \r
1326                                 if(cvar("crosshair_pickup"))\r
1327                                 {\r
1328                                         if(pickup_crosshair_time < getstatf(STAT_LAST_PICKUP))\r
1329                                         {\r
1330                                                 pickup_crosshair_size = 1;\r
1331                                                 pickup_crosshair_time = getstatf(STAT_LAST_PICKUP);\r
1332                                         }\r
1333 \r
1334                                         if(pickup_crosshair_size > 0)\r
1335                                                 pickup_crosshair_size -= cvar("crosshair_pickup_speed") * frametime;\r
1336                                         else\r
1337                                                 pickup_crosshair_size = 0;\r
1338 \r
1339                                         wcross_scale += sin(pickup_crosshair_size) * cvar("crosshair_pickup");\r
1340                                 }\r
1341 \r
1342                                 if(shottype == SHOTTYPE_HITENEMY)\r
1343                                         wcross_scale *= cvar("crosshair_hittest"); // is not queried if hittest is 0\r
1344                                 if(shottype == SHOTTYPE_HITTEAM)\r
1345                                         wcross_scale /= cvar("crosshair_hittest"); // is not queried if hittest is 0\r
1346 \r
1347                                 f = cvar("crosshair_effect_speed");\r
1348                                 if(wcross_scale != wcross_scale_goal_prev || wcross_alpha != wcross_alpha_goal_prev || wcross_color != wcross_color_goal_prev)\r
1349                                 {\r
1350                                         wcross_changedonetime = time + f;\r
1351                                 }\r
1352                                 if(wcross_name != wcross_name_goal_prev || wcross_resolution != wcross_resolution_goal_prev)\r
1353                                 {\r
1354                                         wcross_name_changestarttime = time;\r
1355                                         wcross_name_changedonetime = time + f;\r
1356                                         if(wcross_name_goal_prev_prev)\r
1357                                                 strunzone(wcross_name_goal_prev_prev);\r
1358                                         wcross_name_goal_prev_prev = wcross_name_goal_prev;\r
1359                                         wcross_name_goal_prev = strzone(wcross_name);\r
1360                                         wcross_name_alpha_goal_prev_prev = wcross_name_alpha_goal_prev;\r
1361                                         wcross_resolution_goal_prev_prev = wcross_resolution_goal_prev;\r
1362                                         wcross_resolution_goal_prev = wcross_resolution;\r
1363                                 }\r
1364 \r
1365                                 wcross_scale_goal_prev = wcross_scale;\r
1366                                 wcross_alpha_goal_prev = wcross_alpha;\r
1367                                 wcross_color_goal_prev = wcross_color;\r
1368 \r
1369                                 if(shottype == SHOTTYPE_HITTEAM || (shottype == SHOTTYPE_HITOBSTRUCTION && cvar("crosshair_hittest_blur") && !cvar("chase_active")))\r
1370                                 {\r
1371                                         wcross_blur = 1;\r
1372                                         wcross_alpha *= 0.75;\r
1373                                 }\r
1374                                 else\r
1375                                         wcross_blur = 0;\r
1376                                 // *_prev is at time-frametime\r
1377                                 // * is at wcross_changedonetime+f\r
1378                                 // what do we have at time?\r
1379                                 if(time < wcross_changedonetime)\r
1380                                 {\r
1381                                         f = frametime / (wcross_changedonetime - time + frametime);\r
1382                                         wcross_scale = f * wcross_scale + (1 - f) * wcross_scale_prev;\r
1383                                         wcross_alpha = f * wcross_alpha + (1 - f) * wcross_alpha_prev;\r
1384                                         wcross_color = f * wcross_color + (1 - f) * wcross_color_prev;\r
1385                                 }\r
1386 \r
1387                                 wcross_scale_prev = wcross_scale;\r
1388                                 wcross_alpha_prev = wcross_alpha;\r
1389                                 wcross_color_prev = wcross_color;\r
1390 \r
1391                                 wcross_scale *= 1 - cvar("_menu_alpha");\r
1392                                 wcross_alpha *= 1 - cvar("_menu_alpha");\r
1393 \r
1394 #define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \\r
1395                                 do \\r
1396                                 { \\r
1397                                         if(wcross_blur > 0) \\r
1398                                         { \\r
1399                                                 for(i = -2; i <= 2; ++i) \\r
1400                                                         for(j = -2; j <= 2; ++j) \\r
1401                                                                 M(i,j,sz,wcross_name,wcross_alpha*0.04); \\r
1402                                         } \\r
1403                                         else \\r
1404                                         { \\r
1405                                                 M(0,0,sz,wcross_name,wcross_alpha); \\r
1406                                         } \\r
1407                                 } \\r
1408                                 while(0)\r
1409 \r
1410 #define CROSSHAIR_DRAW_SINGLE(i,j,sz,wcross_name,wcross_alpha) \\r
1411                                 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
1412 \r
1413 #define CROSSHAIR_DRAW(sz,wcross_name,wcross_alpha) \\r
1414                                 CROSSHAIR_DO_BLUR(CROSSHAIR_DRAW_SINGLE,sz,wcross_name,wcross_alpha)\r
1415 \r
1416                                 if(time < wcross_name_changedonetime && wcross_name != wcross_name_goal_prev_prev && wcross_name_goal_prev_prev)\r
1417                                 {\r
1418                                         f = (wcross_name_changedonetime - time) / (wcross_name_changedonetime - wcross_name_changestarttime);\r
1419                                         wcross_size = drawgetimagesize(wcross_name_goal_prev_prev) * wcross_scale;\r
1420                                         CROSSHAIR_DRAW(wcross_resolution_goal_prev_prev, wcross_name_goal_prev_prev, wcross_alpha * f * wcross_name_alpha_goal_prev_prev);\r
1421                                         f = 1 - f;\r
1422                                 }\r
1423                                 else\r
1424                                 {\r
1425                                         f = 1;\r
1426                                 }\r
1427 \r
1428                                 wcross_size = drawgetimagesize(wcross_name) * wcross_scale;\r
1429                                 CROSSHAIR_DRAW(wcross_resolution, wcross_name, wcross_alpha * f);\r
1430                                 wcross_name_alpha_goal_prev = f;\r
1431 \r
1432                                 // ring around crosshair representing ammo left in weapon clip\r
1433                                 weapon_clipload = getstati(STAT_WEAPON_CLIPLOAD);\r
1434                                 a = cvar("crosshair_ring_alpha");\r
1435                                 if (weapon_clipload && a)\r
1436                                 if (!swallow_indicator)\r
1437                                 {\r
1438                                         weapon_clipsize = getstati(STAT_WEAPON_CLIPSIZE);\r
1439                                         ring_scale = cvar("crosshair_ring_size");\r
1440                                         f = bound(0, weapon_clipload / weapon_clipsize, 1);\r
1441                                         DrawCircleClippedPic(wcross_origin, wcross_size_x * ring_scale, "gfx/crosshair_ring.tga", f, wcross_color, wcross_alpha * a, DRAWFLAG_ADDITIVE);\r
1442                                 }\r
1443                         }\r
1444                 }\r
1445                 else\r
1446                 {\r
1447                         wcross_scale_prev = 0;\r
1448                         wcross_alpha_prev = 0;\r
1449                         wcross_scale_goal_prev = 0;\r
1450                         wcross_alpha_goal_prev = 0;\r
1451                         wcross_changedonetime = 0;\r
1452                         if(wcross_name_goal_prev)\r
1453                                 strunzone(wcross_name_goal_prev);\r
1454                         wcross_name_goal_prev = string_null;\r
1455                         if(wcross_name_goal_prev_prev)\r
1456                                 strunzone(wcross_name_goal_prev_prev);\r
1457                         wcross_name_goal_prev_prev = string_null;\r
1458                         wcross_name_changestarttime = 0;\r
1459                         wcross_name_changedonetime = 0;\r
1460                         wcross_name_alpha_goal_prev = 0;\r
1461                         wcross_name_alpha_goal_prev_prev = 0;\r
1462                         wcross_resolution_goal_prev = 0;\r
1463                         wcross_resolution_goal_prev_prev = 0;\r
1464                 }\r
1465         }\r
1466 \r
1467         if(NextFrameCommand)\r
1468         {\r
1469                 localcmd("\n", NextFrameCommand, "\n");\r
1470                 NextFrameCommand = string_null;\r
1471         }\r
1472 \r
1473         // we must do this check AFTER a frame was rendered, or it won't work\r
1474         if(cs_project_is_b0rked == 0)\r
1475         {\r
1476                 string w0, h0;\r
1477                 w0 = cvar_string("vid_conwidth");\r
1478                 h0 = cvar_string("vid_conheight");\r
1479                 //setproperty(VF_VIEWPORT, '0 0 0', '640 480 0');\r
1480                 //setproperty(VF_FOV, '90 90 0');\r
1481                 setproperty(VF_ORIGIN, '0 0 0');\r
1482                 setproperty(VF_ANGLES, '0 0 0');\r
1483                 setproperty(VF_PERSPECTIVE, 1);\r
1484                 makevectors('0 0 0');\r
1485                 vector v1, v2;\r
1486                 cvar_set("vid_conwidth", "800");\r
1487                 cvar_set("vid_conheight", "600");\r
1488                 v1 = cs_project(v_forward);\r
1489                 cvar_set("vid_conwidth", "640");\r
1490                 cvar_set("vid_conheight", "480");\r
1491                 v2 = cs_project(v_forward);\r
1492                 if(v1 == v2)\r
1493                         cs_project_is_b0rked = 1;\r
1494                 else\r
1495                         cs_project_is_b0rked = -1;\r
1496                 cvar_set("vid_conwidth", w0);\r
1497                 cvar_set("vid_conheight", h0);\r
1498         }\r
1499 \r
1500         // be safe against triggerbots until everyone has the fixed engine\r
1501         // this call is meant to overwrite the trace globals by something\r
1502         // unsuspicious\r
1503         traceline('0 0 0', '0 0 0', MOVE_WORLDONLY, world);\r
1504 \r
1505         // this cvar must be constantly updated on the server\r
1506         if(chase_active_old != cvar("chase_active"))\r
1507         {\r
1508                 localcmd("sendcvar chase_active\n");\r
1509                 chase_active_old = cvar("chase_active");\r
1510         }\r
1511 \r
1512         // update some stats to be detected next frame\r
1513         last_health = getstati(STAT_HEALTH);\r
1514         last_spectatee = spectatee_status;\r
1515 }\r
1516 \r
1517 void Sbar_Draw();\r
1518 \r
1519 void CSQC_common_hud(void)\r
1520 {\r
1521         // Sbar_SortFrags(); done in Sbar_Draw\r
1522         float hud;\r
1523         hud = getstati(STAT_HUD);\r
1524 \r
1525         //hud = 10;\r
1526         switch(hud)\r
1527         {\r
1528                 case HUD_NORMAL:\r
1529                         Sbar_Draw();\r
1530                         break;\r
1531         }\r
1532 }\r
1533 \r
1534 \r
1535 // following vectors must be global to allow seamless switching between camera modes\r
1536 vector camera_offset, current_camera_offset, mouse_angles, current_angles, current_origin, current_position;\r
1537 void CSQC_Demo_Camera()\r
1538 {\r
1539         float speed, attenuation, dimensions;\r
1540         vector tmp, delta;\r
1541 \r
1542         if( cvar("camera_reset") || !camera_mode )\r
1543         {\r
1544                 camera_offset = '0 0 0';\r
1545                 current_angles = '0 0 0';\r
1546                 camera_direction = '0 0 0';\r
1547                 camera_offset_z += 30;\r
1548                 camera_offset_x += 30 * -cos(current_angles_y * DEG2RAD);\r
1549                 camera_offset_y += 30 * -sin(current_angles_y * DEG2RAD);\r
1550                 current_origin = view_origin;\r
1551                 current_camera_offset  = camera_offset;\r
1552                 cvar_set("camera_reset", "0");\r
1553                 camera_mode = CAMERA_CHASE;\r
1554         }\r
1555 \r
1556         // Camera angles\r
1557         if( camera_roll )\r
1558                 mouse_angles_z += camera_roll * cvar("camera_speed_roll");\r
1559 \r
1560         if(cvar("camera_look_player"))\r
1561         {\r
1562                 local vector dir;\r
1563                 local float n;\r
1564 \r
1565                 dir = normalize(view_origin - current_position);\r
1566                 n = mouse_angles_z;\r
1567                 mouse_angles = vectoangles(dir);\r
1568                 mouse_angles_x = mouse_angles_x * -1;\r
1569                 mouse_angles_z = n;\r
1570         }\r
1571         else\r
1572         {\r
1573                 tmp = getmousepos() * 0.1;\r
1574                 if(vlen(tmp)>cvar("camera_mouse_treshold"))\r
1575                 {\r
1576                         mouse_angles_x += tmp_y * cos(mouse_angles_z * DEG2RAD) + (tmp_x * sin(mouse_angles_z * DEG2RAD));\r
1577                         mouse_angles_y -= tmp_x * cos(mouse_angles_z * DEG2RAD) + (tmp_y * -sin(mouse_angles_z * DEG2RAD));\r
1578                 }\r
1579         }\r
1580 \r
1581         while (mouse_angles_x < -180) mouse_angles_x = mouse_angles_x + 360;\r
1582         while (mouse_angles_x > 180) mouse_angles_x = mouse_angles_x - 360;\r
1583         while (mouse_angles_y < -180) mouse_angles_y = mouse_angles_y + 360;\r
1584         while (mouse_angles_y > 180) mouse_angles_y = mouse_angles_y - 360;\r
1585 \r
1586         // Fix difference when angles don't have the same sign\r
1587         delta = '0 0 0';\r
1588         if(mouse_angles_y < -60 && current_angles_y > 60)\r
1589                 delta = '0 360 0';\r
1590         if(mouse_angles_y > 60 && current_angles_y < -60)\r
1591                 delta = '0 -360 0';\r
1592 \r
1593         if(cvar("camera_look_player"))\r
1594                 attenuation = cvar("camera_look_attenuation");\r
1595         else\r
1596                 attenuation = cvar("camera_speed_attenuation");\r
1597 \r
1598         attenuation = 1 / max(1, attenuation);\r
1599         current_angles += (mouse_angles - current_angles + delta) * attenuation;\r
1600 \r
1601         while (current_angles_x < -180) current_angles_x = current_angles_x + 360;\r
1602         while (current_angles_x > 180) current_angles_x = current_angles_x - 360;\r
1603         while (current_angles_y < -180) current_angles_y = current_angles_y + 360;\r
1604         while (current_angles_y > 180) current_angles_y = current_angles_y - 360;\r
1605 \r
1606         // Camera position\r
1607         tmp = '0 0 0';\r
1608         dimensions = 0;\r
1609 \r
1610         if( camera_direction_x )\r
1611         {\r
1612                 tmp_x = camera_direction_x * cos(current_angles_y * DEG2RAD);\r
1613                 tmp_y = camera_direction_x * sin(current_angles_y * DEG2RAD);\r
1614                 if( cvar("camera_forward_follows") && !cvar("camera_look_player") )\r
1615                         tmp_z = camera_direction_x * -sin(current_angles_x * DEG2RAD);\r
1616                 ++dimensions;\r
1617         }\r
1618 \r
1619         if( camera_direction_y )\r
1620         {\r
1621                 tmp_x += camera_direction_y * -sin(current_angles_y * DEG2RAD);\r
1622                 tmp_y += camera_direction_y * cos(current_angles_y * DEG2RAD) * cos(current_angles_z * DEG2RAD);\r
1623                 tmp_z += camera_direction_y * sin(current_angles_z * DEG2RAD);\r
1624                 ++dimensions;\r
1625         }\r
1626 \r
1627         if( camera_direction_z )\r
1628         {\r
1629                 tmp_z += camera_direction_z * cos(current_angles_z * DEG2RAD);\r
1630                 ++dimensions;\r
1631         }\r
1632 \r
1633         if(cvar("camera_free"))\r
1634                 speed = cvar("camera_speed_free");\r
1635         else\r
1636                 speed = cvar("camera_speed_chase");\r
1637 \r
1638         if(dimensions)\r
1639         {\r
1640                 speed = speed * sqrt(1 / dimensions);\r
1641                 camera_offset += tmp * speed;\r
1642         }\r
1643 \r
1644         current_camera_offset += (camera_offset - current_camera_offset) * attenuation;\r
1645 \r
1646         // Camera modes\r
1647         if( cvar("camera_free") )\r
1648         {\r
1649                 if ( camera_mode == CAMERA_CHASE )\r
1650                 {\r
1651                         current_camera_offset = current_origin + current_camera_offset;\r
1652                         camera_offset = current_origin + camera_offset;\r
1653                 }\r
1654 \r
1655                 camera_mode = CAMERA_FREE;\r
1656                 current_position = current_camera_offset;\r
1657         }\r
1658         else\r
1659         {\r
1660                 if ( camera_mode == CAMERA_FREE )\r
1661                 {\r
1662                         current_origin = view_origin;\r
1663                         camera_offset = camera_offset - current_origin;\r
1664                         current_camera_offset = current_camera_offset - current_origin;\r
1665                 }\r
1666 \r
1667                 camera_mode = CAMERA_CHASE;\r
1668 \r
1669                 if(cvar("camera_chase_smoothly"))\r
1670                         current_origin += (view_origin - current_origin) * attenuation;\r
1671                 else\r
1672                         current_origin = view_origin;\r
1673 \r
1674                 current_position = current_origin + current_camera_offset;\r
1675         }\r
1676 \r
1677         setproperty(VF_ANGLES, current_angles);\r
1678         setproperty(VF_ORIGIN, current_position);\r
1679 }\r