]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/View.qc
Merge remote branch 'origin/master' into samual/hud_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / View.qc
index 3347c360a83e70210b99329bbf236376e49191d8..a90788526f2e5e12c9296e9b62722c71b7f0b4c5 100644 (file)
@@ -127,7 +127,7 @@ vector GetCurrentFov(float fov)
 
        zoomdir = button_zoom;
        if(hud == HUD_NORMAL)
-       if((getstati(STAT_ACTIVEWEAPON) == WEP_NEX && nex_scope) || (getstati(STAT_ACTIVEWEAPON) == WEP_RIFLE && rifle_scope)) // do NOT use switchweapon here
+       if((activeweapon == WEP_NEX && nex_scope) || (activeweapon == WEP_RIFLE && rifle_scope)) // do NOT use switchweapon here
                zoomdir += button_attack2;
        if(spectatee_status > 0 || isdemo())
        {
@@ -417,22 +417,14 @@ void CSQC_UpdateView(float w, float h)
 
        ticrate = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
 
-       if(autocvar_cl_lockview || (autocvar__hud_configure && spectatee_status <= 0) || intermission > 1)
-       {
-               R_SetView(VF_ORIGIN, freeze_org);
-               R_SetView(VF_ANGLES, freeze_ang);
-       }
-       else
-       {
-               freeze_org = R_SetView3fv(VF_ORIGIN);
-               freeze_ang = R_SetView3fv(VF_ANGLES);
-       }
-
        // 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)
                {
+                       // 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 = R_SetView3fv(VF_ORIGIN);
+                       
                        // 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 R_SetView()
                        if(!autocvar_chase_active)
@@ -447,13 +439,12 @@ void CSQC_UpdateView(float w, float h)
                        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 = freeze_org - v_forward * eventchase_current_distance;
-
-                       WarpZone_TraceLine(freeze_org, eventchase_target_origin, MOVE_WORLDONLY, self);
+                       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 = freeze_org - v_forward * eventchase_current_distance * (trace_fraction - 0.1);
-                       WarpZone_TraceLine(freeze_org, eventchase_target_origin, MOVE_WORLDONLY, self);
+                       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);
 
                        R_SetView(VF_ORIGIN, trace_endpos);
                        R_SetView(VF_ANGLES, WarpZone_TransformVAngles(WarpZone_trace_transform, view_angles));
@@ -464,6 +455,18 @@ void CSQC_UpdateView(float w, float h)
                        eventchase_current_distance = 0; // start from 0 next time
                }
        }
+       
+       // do lockview after event chase camera so that it still applies whenever necessary.
+       if(autocvar_cl_lockview || (autocvar__hud_configure && spectatee_status <= 0) || intermission > 1)
+       {
+               R_SetView(VF_ORIGIN, freeze_org);
+               R_SetView(VF_ANGLES, freeze_ang);
+       }
+       else
+       {
+               freeze_org = R_SetView3fv(VF_ORIGIN);
+               freeze_ang = R_SetView3fv(VF_ANGLES);
+       }
 
        WarpZone_FixView();
        //WarpZone_FixPMove();
@@ -541,7 +544,16 @@ void CSQC_UpdateView(float w, float h)
        }
 
        ColorTranslateMode = autocvar_cl_stripcolorcodes;
-       activeweapon = getstati(STAT_SWITCHWEAPON);
+
+       // next WANTED weapon (for HUD)
+       switchweapon = getstati(STAT_SWITCHWEAPON);
+
+       // currently switching-to weapon (for crosshair)
+       switchingweapon = getstati(STAT_SWITCHINGWEAPON);
+
+       // actually active weapon (for zoom)
+       activeweapon = getstati(STAT_ACTIVEWEAPON);
+
        f = (serverflags & SERVERFLAG_TEAMPLAY);
        if(f != teamplay)
        {
@@ -549,9 +561,12 @@ void CSQC_UpdateView(float w, float h)
                HUD_InitScores();
        }
 
-       if(last_weapon != activeweapon) {
+       if(last_switchweapon != switchweapon) {
                weapontime = time;
-               last_weapon = activeweapon;
+               last_switchweapon = switchweapon;
+       }
+       if(last_activeweapon != activeweapon) {
+               last_activeweapon = activeweapon;
 
                e = get_weaponinfo(activeweapon);
                if(e.netname != "")
@@ -850,6 +865,10 @@ void CSQC_UpdateView(float w, float h)
 
                myhealth_prev = myhealth;
 
+               // IDEA: change damage color/picture based on player model for robot/alien species?
+               // 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_cl_gentle_damage || autocvar_cl_gentle)
                {
                        if(autocvar_cl_gentle_damage == 2)
@@ -1027,7 +1046,7 @@ void CSQC_UpdateView(float w, float h)
                        float wcross_scale, wcross_blur;
 
                        if (autocvar_crosshair_per_weapon || autocvar_crosshair_color_per_weapon) {
-                               e = get_weaponinfo(activeweapon);
+                               e = get_weaponinfo(switchingweapon);
                                if (e && e.netname != "")
                                {
                                        wcross_wep = e.netname;
@@ -1050,7 +1069,7 @@ void CSQC_UpdateView(float w, float h)
                                wcross_color = stov(cvar_string(strcat("crosshair_", wcross_wep, "_color")));
                        else if(autocvar_crosshair_color_by_health)
                        {
-                               local float x = getstati(STAT_HEALTH);
+                               float x = getstati(STAT_HEALTH);
 
                                //x = red
                                //y = green
@@ -1156,7 +1175,7 @@ void CSQC_UpdateView(float w, float h)
 
                        f = autocvar_crosshair_effect_speed;
                        if(f < 0)
-                               f *= -2 * g_weaponswitchdelay;
+                               f *= -2 * g_weaponswitchdelay; // anim starts when weapon has been lowered and new weapon comes up
                        if(wcross_scale != wcross_scale_goal_prev || wcross_alpha != wcross_alpha_goal_prev || wcross_color != wcross_color_goal_prev)
                        {
                                wcross_changedonetime = time + f;
@@ -1279,6 +1298,14 @@ void CSQC_UpdateView(float w, float h)
                                                        ring_image = "gfx/crosshair_ring.tga";
                                        }
 
+                                       // if in weapon switch animation, fade ring out/in
+                                       if(g_weaponswitchdelay > 0)
+                                       {
+                                               f = (time - wcross_name_changestarttime) / g_weaponswitchdelay;
+                                               if(f > 0 && f < 2)
+                                                       ring_alpha *= fabs(1 - f);
+                                       }
+
                                        if (autocvar_crosshair_ring_inner && ring_inner_value) // lets draw a ring inside a ring so you can ring while you ring
                                                DrawCircleClippedPic(wcross_origin, wcross_size_x * ring_scale, ring_inner_image, ring_inner_value, ring_inner_rgb, wcross_alpha * ring_inner_alpha, DRAWFLAG_ADDITIVE);
 
@@ -1489,8 +1516,8 @@ void CSQC_Demo_Camera()
 
        if(autocvar_camera_look_player)
        {
-               local vector dir;
-               local float n;
+               vector dir;
+               float n;
 
                dir = normalize(view_origin - current_position);
                n = mouse_angles_z;