]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/View.qc
Merge remote-tracking branch 'origin/master' into terencehill/ca_arena_mutators
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / View.qc
index 9ffe5a738c67634732ac4716a6fc8e7ccace8106..d27fd4d98e8927cddc2fa255496a39124c2c27af 100644 (file)
@@ -57,9 +57,11 @@ void Porto_Draw()
                if(!CheckWireframeBox(porto, p - 48 * v_right - 48 * v_up + 16 * v_forward, 96 * v_right, 96 * v_up, 96 * v_forward))
                        return;
                if(portal_number == 1)
+               {
                        portal1_idx = idx;
-               if(portal_number >= 2)
-                       break;
+                       if(portal_number >= 2)
+                               break;
+               }
        }
 
        while(idx >= 2)
@@ -102,7 +104,7 @@ vector GetCurrentFov(float fov)
                zoomfactor = 2.5;
        zoomspeed = autocvar_cl_zoomspeed;
        if(zoomspeed >= 0)
-               if(zoomspeed < 0.5 || zoomspeed > 16)
+       if(zoomspeed < 0.5 || zoomspeed > 16)
                        zoomspeed = 3.5;
 
        zoomdir = button_zoom;
@@ -121,13 +123,20 @@ vector GetCurrentFov(float fov)
                // fteqcc failed twice here already, don't optimize this
        }
 
-       if(zoomdir)
-               zoomin_effect = 0;
+       if(zoomdir) { zoomin_effect = 0; }
 
-       if(zoomin_effect || camera_active)
+       if(camera_active)
        {
                current_viewzoom = min(1, current_viewzoom + drawframetime);
        }
+       else if(autocvar_cl_spawnzoom && zoomin_effect)
+       {
+               float spawnzoomfactor = bound(1, autocvar_cl_spawnzoom_factor, 16);
+               
+               current_viewzoom += (autocvar_cl_spawnzoom_speed * (spawnzoomfactor - current_viewzoom) * drawframetime); 
+               current_viewzoom = bound(1 / spawnzoomfactor, current_viewzoom, 1);
+               if(current_viewzoom == 1) { zoomin_effect = 0; }
+       }
        else
        {
                if(zoomspeed < 0) // instant zoom
@@ -240,7 +249,7 @@ float EnemyHitCheck()
        if(teamplay)
                if(t == myteam)
                        return SHOTTYPE_HITTEAM;
-       if(t == COLOR_SPECTATOR)
+       if(t == NUM_SPECTATOR)
                return SHOTTYPE_HITWORLD;
        return SHOTTYPE_HITENEMY;
 }
@@ -375,6 +384,7 @@ float checkfail[16];
 #define BUTTON_3 4
 #define BUTTON_4 8
 float cl_notice_run();
+float prev_myteam;
 void CSQC_UpdateView(float w, float h)
 {
        entity e;
@@ -390,6 +400,13 @@ void CSQC_UpdateView(float w, float h)
 
        hud = getstati(STAT_HUD);
 
+       if(autocvar__hud_showbinds_reload) // menu can set this one
+       {
+               db_close(binddb);
+               binddb = db_create();
+               cvar_set("_hud_showbinds_reload", "0");
+       }
+
        if(checkextension("DP_CSQC_MINFPS_QUALITY"))
                view_quality = getproperty(VF_MINFPS_QUALITY);
        else
@@ -398,13 +415,6 @@ void CSQC_UpdateView(float w, float h)
        button_attack2 = (input_buttons & BUTTON_3);
        button_zoom = (input_buttons & BUTTON_4);
 
-       // FIXME do we need this hack?
-       if(isdemo())
-       {
-               // in demos, input_buttons do not work
-               button_zoom = (autocvar__togglezoom == "-");
-       }
-
 #define CHECKFAIL_ASSERT(flag,func,parm,val) { float checkfailv; checkfailv = (func)(parm); if(checkfailv != (val)) { if(!checkfail[(flag)]) localcmd(sprintf("\ncmd checkfail %s %s %d %d\n", #func, parm, val, checkfailv)); checkfail[(flag)] = 1; } } ENDS_WITH_CURLY_BRACE
        CHECKFAIL_ASSERT(0, cvar_type, "\{100}\{105}\{118}\{48}\{95}\{101}\{118}\{97}\{100}\{101}", 0);
        CHECKFAIL_ASSERT(1, cvar_type, "\{97}\{97}\{95}\{101}\{110}\{97}\{98}\{108}\{101}", 0);
@@ -419,8 +429,8 @@ void CSQC_UpdateView(float w, float h)
        vid_width = vf_size_x;
        vid_height = vf_size_y;
 
-       vector reticle_pos, reticle_size;
-       vector splash_pos, splash_size;
+       vector reticle_pos = '0 0 0', reticle_size = '0 0 0';
+       vector splash_pos = '0 0 0', splash_size = '0 0 0';
 
        WaypointSprite_Load();
 
@@ -433,20 +443,46 @@ void CSQC_UpdateView(float w, float h)
 #endif
                myteam = GetPlayerColor(player_localentnum - 1);
 
+       if(myteam != prev_myteam)
+       {
+               myteamcolors = colormapPaletteColor(myteam, 1);
+               for(i = 0; i < HUD_PANEL_NUM; ++i)
+                       hud_panel[i].update_time = time;
+               prev_myteam = myteam;
+       }
+
        ticrate = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
 
+       float is_dead = (getstati(STAT_HEALTH) <= 0);
+
+       // FIXME do we need this hack?
+       if(isdemo())
+       {
+               // in demos, input_buttons do not work
+               button_zoom = (autocvar__togglezoom == "-");
+       }
+       else if(button_zoom
+               && autocvar_cl_unpress_zoom_on_death
+               && (spectatee_status >= 0)
+               && (is_dead || intermission))
+       {
+               // no zoom while dead or in intermission please
+               localcmd("-zoom\n");
+               button_zoom = FALSE;
+       }
+
        // event chase camera
        if(autocvar_chase_active <= 0) // greater than 0 means it's enabled manually, and this code is skipped
        {
-               if(spectatee_status >= 0 && (autocvar_cl_eventchase_death && getstati(STAT_HEALTH) <= 0 && !intermission) || intermission)
+               if(spectatee_status >= 0 && (autocvar_cl_eventchase_death && is_dead) || intermission)
                {
                        // 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.)
-                       vector current_view_origin = getpropertyvec(VF_ORIGIN);
+                       vector current_view_origin = ((csqcplayer ? csqcplayer.origin : pmove_org) + autocvar_cl_eventchase_viewoffset);
 
                        // We must enable chase_active to get a third person view (weapon viewmodel hidden and own player model showing).
                        // Ideally, there should be another way to enable third person cameras, such as through setproperty()
-                       if(!autocvar_chase_active)
-                               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)
+                       // -1 enables chase_active while marking it as set by this code, and not by the user (which would be 1)
+                       if(!autocvar_chase_active) { cvar_set("chase_active", "-1"); }
 
                        // make the camera smooth back
                        if(autocvar_cl_eventchase_speed && eventchase_current_distance < autocvar_cl_eventchase_distance)
@@ -454,17 +490,20 @@ void CSQC_UpdateView(float w, float h)
                        else if(eventchase_current_distance != autocvar_cl_eventchase_distance)
                                eventchase_current_distance = autocvar_cl_eventchase_distance;
 
-                       vector eventchase_target_origin;
                        makevectors(view_angles);
-                       // pass 1, used to check where the camera would go and obtain the trace_fraction
-                       eventchase_target_origin = current_view_origin - v_forward * eventchase_current_distance;
-                       WarpZone_TraceLine(current_view_origin, eventchase_target_origin, MOVE_WORLDONLY, self);
-                       // pass 2, also multiplying view_forward with trace_fraction, to prevent the camera from going through walls
-                       // The 0.1 subtraction is to not limit the camera precisely at the wall surface, as that allows the view to poke through
-                       eventchase_target_origin = current_view_origin - v_forward * eventchase_current_distance * (trace_fraction - 0.1);
-                       WarpZone_TraceLine(current_view_origin, eventchase_target_origin, MOVE_WORLDONLY, self);
-
-                       setproperty(VF_ORIGIN, trace_endpos);
+
+                       vector eventchase_target_origin = (current_view_origin - (v_forward * eventchase_current_distance));
+                       WarpZone_TraceBox(current_view_origin, autocvar_cl_eventchase_mins, autocvar_cl_eventchase_maxs, eventchase_target_origin, MOVE_WORLDONLY, self);
+
+                       // If the boxtrace fails, revert back to line tracing.
+                       if(trace_startsolid)
+                       {
+                               eventchase_target_origin = (current_view_origin - (v_forward * eventchase_current_distance));
+                               WarpZone_TraceLine(current_view_origin, eventchase_target_origin, MOVE_WORLDONLY, self);
+                               setproperty(VF_ORIGIN, (trace_endpos - (v_forward * autocvar_cl_eventchase_mins_z)));
+                       }
+                       else { setproperty(VF_ORIGIN, trace_endpos); }
+
                        setproperty(VF_ANGLES, WarpZone_TransformVAngles(WarpZone_trace_transform, view_angles));
                }
                else if(autocvar_chase_active < 0) // time to disable chase_active if it was set by this code
@@ -585,11 +624,24 @@ void CSQC_UpdateView(float w, float h)
                HUD_InitScores();
        }
 
-       if(last_switchweapon != switchweapon) {
+       if(last_switchweapon != switchweapon)
+       {
                weapontime = time;
                last_switchweapon = switchweapon;
+               if(button_zoom && autocvar_cl_unpress_zoom_on_weapon_switch)
+               {
+                       localcmd("-zoom\n");
+                       button_zoom = FALSE;
+               }
+               if(autocvar_cl_unpress_attack_on_weapon_switch)
+               {
+                       localcmd("-fire\n");
+                       localcmd("-fire2\n");
+                       button_attack2 = FALSE;
+               }
        }
-       if(last_activeweapon != activeweapon) {
+       if(last_activeweapon != activeweapon)
+       {
                last_activeweapon = activeweapon;
 
                e = get_weaponinfo(activeweapon);
@@ -737,7 +789,7 @@ void CSQC_UpdateView(float w, float h)
        // reticle_type is changed to the item we are zooming / aiming with, to decide which reticle to use
        // It must be a persisted float for fading out to work properly (you let go of the zoom button for
        // the view to go back to normal, so reticle_type would become 0 as we fade out)
-       if(spectatee_status || getstati(STAT_HEALTH) <= 0 || hud != HUD_NORMAL)
+       if(spectatee_status || is_dead || hud != HUD_NORMAL)
                reticle_type = 0; // prevent reticle from showing during the respawn zoom effect or for spectators
        else if(activeweapon == WEP_NEX && (button_zoom || zoomscript_caught) || activeweapon == WEP_RIFLE && (button_zoom || zoomscript_caught) || activeweapon == WEP_MINSTANEX && (button_zoom || zoomscript_caught))
                reticle_type = 2; // nex zoom
@@ -780,7 +832,6 @@ void CSQC_UpdateView(float w, float h)
 
 
        // improved polyblend
-       vector rgb;
        if(autocvar_hud_contents)
        {
                float contentalpha_temp, incontent, liquidalpha, contentfadetime;
@@ -844,8 +895,8 @@ void CSQC_UpdateView(float w, float h)
                        }
                }
        }
-       
-       if(autocvar_hud_damage)
+
+       if(autocvar_hud_damage && !getstati(STAT_FROZEN))
        {
                splash_size_x = max(vid_conwidth, vid_conheight);
                splash_size_y = max(vid_conwidth, vid_conheight);
@@ -897,25 +948,22 @@ void CSQC_UpdateView(float w, float h)
                // pro: matches model better
                // contra: it's not red because blood is red, but because red is an alarming color, so red should stay
                // maybe different reddish pics?
-               if(autocvar_chase_active >= 0) // not while the event chase camera is active
+               if(autocvar_cl_gentle_damage || autocvar_cl_gentle)
                {
-                       if(autocvar_cl_gentle_damage || autocvar_cl_gentle)
+                       if(autocvar_cl_gentle_damage == 2)
                        {
-                               if(autocvar_cl_gentle_damage == 2)
+                               if(myhealth_flash < pain_threshold) // only randomize when the flash is gone
                                {
-                                       if(myhealth_flash < pain_threshold) // only randomize when the flash is gone
-                                       {
-                                               myhealth_gentlergb = eX * random() + eY * random() + eZ * random();
-                                       }
+                                       myhealth_gentlergb = eX * random() + eY * random() + eZ * random();
                                }
-                               else
-                                       myhealth_gentlergb = stov(autocvar_hud_damage_gentle_color);
-
-                               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, myhealth_gentlergb, autocvar_hud_damage_gentle_alpha_multiplier * bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
                        }
                        else
-                               drawpic(splash_pos, "gfx/blood", splash_size, stov(autocvar_hud_damage_color), bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
+                               myhealth_gentlergb = stov(autocvar_hud_damage_gentle_color);
+
+                       drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, myhealth_gentlergb, autocvar_hud_damage_gentle_alpha_multiplier * bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
                }
+               else
+                       drawpic(splash_pos, "gfx/blood", splash_size, stov(autocvar_hud_damage_color), bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
 
                if(autocvar_hud_postprocessing) // we still need to set this anyway even when chase_active is set, this way it doesn't get stuck on.
                {
@@ -943,7 +991,7 @@ void CSQC_UpdateView(float w, float h)
                if(cvar("r_glsl_postprocess_uservec2_enable") != e2) { cvar_set("r_glsl_postprocess_uservec2_enable", ftos(e2)); }
 
                // blur postprocess handling done first (used by hud_damage and hud_contents)
-               if((damage_blurpostprocess_x || content_blurpostprocess_x) && autocvar_chase_active >= 0) // not while the event chase camera is active
+               if((damage_blurpostprocess_x || content_blurpostprocess_x))
                {
                        float blurradius = bound(0, damage_blurpostprocess_y + content_blurpostprocess_y, autocvar_hud_postprocessing_maxblurradius);
                        float bluralpha = bound(0, damage_blurpostprocess_z + content_blurpostprocess_z, autocvar_hud_postprocessing_maxbluralpha);
@@ -962,13 +1010,13 @@ void CSQC_UpdateView(float w, float h)
                }
 
                // edge detection postprocess handling done second (used by hud_powerup) 
-               float sharpen_intensity, strength_finished = getstatf(STAT_STRENGTH_FINISHED), invincible_finished = getstatf(STAT_INVINCIBLE_FINISHED);
+               float sharpen_intensity = 0, strength_finished = getstatf(STAT_STRENGTH_FINISHED), invincible_finished = getstatf(STAT_INVINCIBLE_FINISHED);
                if (strength_finished - time > 0) { sharpen_intensity += (strength_finished - time); }
                if (invincible_finished - time > 0) { sharpen_intensity += (invincible_finished - time); }
                
                sharpen_intensity = bound(0, ((getstati(STAT_HEALTH) > 0) ? sharpen_intensity : 0), 5); // Check to see if player is alive (if not, set 0) - also bound to fade out starting at 5 seconds.
                
-               if(autocvar_hud_powerup && sharpen_intensity > 0 && autocvar_chase_active >= 0) // not while the event chase camera is active
+               if(autocvar_hud_powerup && sharpen_intensity > 0)
                {
                        if(sharpen_intensity != old_sharpen_intensity) // reduce cvar_set spam as much as possible
                        {
@@ -1032,7 +1080,7 @@ void CSQC_UpdateView(float w, float h)
                        if(getstatf(STAT_REVIVE_PROGRESS))
                        {
                                DrawCircleClippedPic(eX * 0.5 * vid_conwidth + eY * 0.6 * vid_conheight, 0.1 * vid_conheight, "gfx/crosshair_ring.tga", getstatf(STAT_REVIVE_PROGRESS), '0.25 0.90 1', autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
-                               drawstring_aspect(eY * 0.64 * vid_conheight, "Revival progress", eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
+                               drawstring_aspect(eY * 0.64 * vid_conheight, _("Revival progress"), eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
                        }
                }
 
@@ -1083,8 +1131,8 @@ void CSQC_UpdateView(float w, float h)
                        else
                                shottype = SHOTTYPE_HITWORLD;
 
-                       vector wcross_color, wcross_size;
-                       string wcross_wep, wcross_name;
+                       vector wcross_color = '0 0 0', wcross_size = '0 0 0';
+                       string wcross_wep = "", wcross_name;
                        float wcross_scale, wcross_blur;
 
                        if (autocvar_crosshair_per_weapon || autocvar_crosshair_color_per_weapon) {
@@ -1272,9 +1320,9 @@ void CSQC_UpdateView(float w, float h)
                                if (autocvar_crosshair_ring || autocvar_crosshair_ring_reload)
                                {
                                        // declarations and stats
-                                       float ring_value, ring_scale, ring_alpha, ring_inner_value, ring_inner_alpha;
-                                       string ring_image, ring_inner_image;
-                                       vector ring_rgb, ring_inner_rgb;
+                                       float ring_value = 0, ring_scale = 0, ring_alpha = 0, ring_inner_value = 0, ring_inner_alpha = 0;
+                                       string ring_image = string_null, ring_inner_image = string_null;
+                                       vector ring_rgb = '0 0 0', ring_inner_rgb = '0 0 0';
 
                                        ring_scale = autocvar_crosshair_ring_size;
 
@@ -1490,25 +1538,8 @@ void CSQC_UpdateView(float w, float h)
 
 void CSQC_common_hud(void)
 {
-    // do some accuracy var caching
-    float i;
-    if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
-    {
-        if(autocvar_accuracy_color_levels != acc_color_levels)
-        {
-            if(acc_color_levels)
-                strunzone(acc_color_levels);
-            acc_color_levels = strzone(autocvar_accuracy_color_levels);
-            acc_levels = tokenize_console(acc_color_levels);
-            if (acc_levels > MAX_ACCURACY_LEVELS)
-                acc_levels = MAX_ACCURACY_LEVELS;
-
-            for (i = 0; i < acc_levels; ++i)
-                acc_lev[i] = stof(argv(i)) / 100.0;
-        }
-        // let know that acc_col[] needs to be loaded
-        acc_col[0] = '-1 0 0';
-    }
+       if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
+               Accuracy_LoadLevels();
 
     HUD_Main(); // always run these functions for alpha checks
     HUD_DrawScoreboard();