]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/View.qc
Merge remote branch 'origin/fruitiex/precache_crosshair_ring'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / View.qc
index ed1f303e2fafe11c4830f5ccc787b768fbabeb81..9953af664b7b4db76233623bfa69a9c8d2aa166c 100644 (file)
@@ -79,11 +79,11 @@ void Porto_Draw()
                        p = p - view_up * 16;
                if(idx-1 >= portal1_idx)
                {
-                       Draw_CylindricLine(p, q, 4, "", 1, 0, '0 0 1', 0.5, DRAWFLAG_NORMAL);
+                       Draw_CylindricLine(p, q, 4, "", 1, 0, '0 0 1', 0.5, DRAWFLAG_NORMAL, view_origin);
                }
                else
                {
-                       Draw_CylindricLine(p, q, 4, "", 1, 0, '1 0 0', 0.5, DRAWFLAG_NORMAL);
+                       Draw_CylindricLine(p, q, 4, "", 1, 0, '1 0 0', 0.5, DRAWFLAG_NORMAL, view_origin);
                }
                --idx;
        }
@@ -102,7 +102,7 @@ void CheckForGamestartChange() {
        if (previous_game_starttime != startTime) {
                if ((time + 5.0) < startTime) {
                        //if connecting to server while restart was active don't always play prepareforbattle
-                       sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/prepareforbattle.wav"), VOL_BASEVOICE, ATTN_NONE);
+                       sound(world, CHAN_AUTO, strcat("announcer/", cvar_string("cl_announcer"), "/prepareforbattle.wav"), VOL_BASEVOICE, ATTN_NONE);
                }
                if (time < startTime) {
                        restartAnnouncer = spawn();
@@ -137,7 +137,7 @@ vector GetCurrentFov(float fov)
                        zoomspeed = 3.5;
 
        zoomdir = button_zoom;
-       if(getstati(STAT_ACTIVEWEAPON) == WEP_NEX) // do NOT use switchweapon here
+       if((getstati(STAT_ACTIVEWEAPON) == WEP_NEX && nex_scope) || (getstati(STAT_ACTIVEWEAPON) == WEP_CAMPINGRIFLE && campingrifle_scope)) // do NOT use switchweapon here
                zoomdir += button_attack2;
        if(spectatee_status > 0 || isdemo())
        {
@@ -347,6 +347,7 @@ void CSQC_SPIDER_HUD();
 void CSQC_RAPTOR_HUD();
 
 vector freeze_pmove_org, freeze_input_angles;
+entity nightvision_noise, nightvision_noise2;
 
 void CSQC_UpdateView(float w, float h)
 {
@@ -354,6 +355,12 @@ void CSQC_UpdateView(float w, float h)
        float fov;
        float f, i, j;
        vector v, vo;
+       vector vf_size, vf_min;
+
+       vf_size = R_SetView3fv(VF_SIZE);
+       vf_min = R_SetView3fv(VF_MIN);
+       vid_width = vf_size_x;
+       vid_height = vf_size_y;
 
        vector reticle_pos, reticle_size;
 
@@ -375,7 +382,7 @@ void CSQC_UpdateView(float w, float h)
        input_angles = warpzone_fixview_cl_viewangles;
        view_angles = warpzone_fixview_angles;
 
-       if(cvar("cl_lockview") || hud_configure)
+       if(cvar("cl_lockview") || autocvar__hud_configure)
        {
                pmove_org = freeze_pmove_org;
                input_angles = view_angles = freeze_input_angles;
@@ -398,9 +405,6 @@ void CSQC_UpdateView(float w, float h)
                view_set = 1;
        }
 
-       vid_width = w;
-       vid_height = h;
-
 #ifdef BLURTEST
        if(time > blurtest_time0 && time < blurtest_time1)
        {
@@ -435,7 +439,7 @@ void CSQC_UpdateView(float w, float h)
        if(intermission && !isdemo() && !(calledhooks & HOOK_END))
                if(calledhooks & HOOK_START)
                {
-                       localcmd("\ncl_hook_gameend;");
+                       localcmd("\ncl_hook_gameend\n");
                        calledhooks |= HOOK_END;
                }
 
@@ -477,11 +481,21 @@ void CSQC_UpdateView(float w, float h)
        if(last_weapon != activeweapon) {
                weapontime = time;
                last_weapon = activeweapon;
+
+               e = get_weaponinfo(activeweapon);
+               if(e.netname != "")
+                       localcmd(strcat("\ncl_hook_activeweapon ", e.netname), "\n");
+               else
+                       localcmd("\ncl_hook_activeweapon none\n");
        }
 
        // ALWAYS Clear Current Scene First
        R_ClearScene();
 
+       // FIXME engine bug? VF_SIZE and VF_MIN are not restored to sensible values by this
+       R_SetView(VF_SIZE, vf_size);
+       R_SetView(VF_MIN, vf_min);
+
        // Assign Standard Viewflags
        // Draw the World (and sky)
        R_SetView(VF_DRAWWORLD, 1);
@@ -552,15 +566,65 @@ void CSQC_UpdateView(float w, float h)
        // next R_RenderScene call
        drawstring('0 0 0', "", '1 1 0', '1 1 1', 0, 0);
 
+       if(cvar("r_fakelight") >= 2 || cvar("r_fullbright"))
+       {
+               // apply night vision effect
+               vector rgb, tc_00, tc_01, tc_10, tc_11;
+               float a;
+
+               if(!nightvision_noise)
+               {
+                       nightvision_noise = spawn();
+                       nightvision_noise.classname = "nightvision_noise";
+               }
+               if(!nightvision_noise2)
+               {
+                       nightvision_noise2 = spawn();
+                       nightvision_noise2.classname = "nightvision_noise2";
+               }
+
+               // color tint in yellow
+               drawfill('0 0 0', cvar("vid_conwidth") * '1 0 0' + cvar("vid_conheight") * '0 1 0', '0.5 1 0.3', 1, DRAWFLAG_MODULATE);
+
+               // draw BG
+               a = Noise_Pink(nightvision_noise, frametime * 1.5) * 0.05 + 0.15;
+               rgb = '1 1 1';
+               tc_00 = '0 0 0' + '0.2 0 0' * sin(time * 0.3) + '0 0.3 0' * cos(time * 0.7);
+               tc_01 = '0 2.25 0' + '0.6 0 0' * cos(time * 1.2) - '0 0.3 0' * sin(time * 2.2);
+               tc_10 = '1.5 0 0' - '0.2 0 0' * sin(time * 0.5) + '0 0.5 0' * cos(time * 1.7);
+               //tc_11 = '1 1 0' + '0.6 0 0' * sin(time * 0.6) + '0 0.3 0' * cos(time * 0.1);
+               tc_11 = tc_01 + tc_10 - tc_00;
+               R_BeginPolygon("gfx/nightvision-bg.tga", DRAWFLAG_ADDITIVE);
+               R_PolygonVertex('0 0 0', tc_00, rgb, a);
+               R_PolygonVertex(cvar("vid_conwidth") * '1 0 0', tc_10, rgb, a);
+               R_PolygonVertex(cvar("vid_conwidth") * '1 0 0' + cvar("vid_conheight") * '0 1 0', tc_11, rgb, a);
+               R_PolygonVertex(cvar("vid_conheight") * '0 1 0', tc_01, rgb, a);
+               R_EndPolygon();
+
+               // draw FG
+               a = Noise_Pink(nightvision_noise2, frametime * 0.1) * 0.05 + 0.12;
+               rgb = '0.3 0.6 0.4' + '0.1 0.4 0.2' * Noise_White(nightvision_noise2, frametime);
+               tc_00 = '0 0 0' + '1 0 0' * Noise_White(nightvision_noise2, frametime) + '0 1 0' * Noise_White(nightvision_noise2, frametime);
+               tc_01 = tc_00 + '0 3 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.2);
+               tc_10 = tc_00 + '2 0 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.3);
+               tc_11 = tc_01 + tc_10 - tc_00;
+               R_BeginPolygon("gfx/nightvision-fg.tga", DRAWFLAG_ADDITIVE);
+               R_PolygonVertex('0 0 0', tc_00, rgb, a);
+               R_PolygonVertex(cvar("vid_conwidth") * '1 0 0', tc_10, rgb, a);
+               R_PolygonVertex(cvar("vid_conwidth") * '1 0 0' + cvar("vid_conheight") * '0 1 0', tc_11, rgb, a);
+               R_PolygonVertex(cvar("vid_conheight") * '0 1 0', tc_01, rgb, a);
+               R_EndPolygon();
+       }
+
        // Draw the aiming reticle for weapons that use it
        // 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)
                reticle_type = 0; // prevent reticle from showing during the respawn zoom effect or for spectators
-       else if(button_zoom)
+       else if(button_zoom || zoomscript_caught)
                reticle_type = 1; // normal zoom
-       else if(activeweapon == WEP_NEX && button_attack2)
+       else if(activeweapon == WEP_NEX && button_attack2 || activeweapon == WEP_CAMPINGRIFLE && button_attack2)
                reticle_type = 2; // nex zoom
 
        if(cvar("cl_reticle_stretch"))
@@ -578,17 +642,20 @@ void CSQC_UpdateView(float w, float h)
                reticle_pos_y = (vid_conheight - reticle_size_y) / 2;
        }
 
+       f = current_zoomfraction;
+       if(zoomscript_caught)
+               f = 1;
        if(cvar("cl_reticle_item_normal"))
        {
-               precache_pic("textures/reticle_normal");
-               if(reticle_type == 1 && current_zoomfraction)
-                       drawpic(reticle_pos, "textures/reticle_normal", reticle_size, '1 1 1', current_zoomfraction * cvar("cl_reticle_item_normal"), DRAWFLAG_NORMAL);
+               precache_pic("gfx/reticle_normal");
+               if(reticle_type == 1 && f)
+                       drawpic(reticle_pos, "gfx/reticle_normal", reticle_size, '1 1 1', f * cvar("cl_reticle_item_normal"), DRAWFLAG_NORMAL);
        }
        if(cvar("cl_reticle_item_nex"))
        {
-               precache_pic("textures/reticle_nex");
-               if(reticle_type == 2 && current_zoomfraction)
-                       drawpic(reticle_pos, "textures/reticle_nex", reticle_size, '1 1 1', current_zoomfraction * cvar("cl_reticle_item_nex"), DRAWFLAG_NORMAL);
+               precache_pic("gfx/reticle_nex");
+               if(reticle_type == 2 && f)
+                       drawpic(reticle_pos, "gfx/reticle_nex", reticle_size, '1 1 1', f * cvar("cl_reticle_item_nex"), DRAWFLAG_NORMAL);
        }
 
        // Draw the mouse cursor
@@ -614,11 +681,6 @@ void CSQC_UpdateView(float w, float h)
                        self.draw2d();
        self = e;
 
-       // draw hud
-       if(cvar("r_letterbox") == 0) {
-               HUD_DrawCenterPrint(); // draw centerprint messages even if viewsize >= 120
-       }
-
        float hud;
        hud = getstati(STAT_HUD);
        if(hud == HUD_SPIDERBOT)
@@ -635,8 +697,27 @@ void CSQC_UpdateView(float w, float h)
                        if(cvar("viewsize") < 120)
                                CSQC_common_hud();
 
+
+               precache_pic("gfx/nex_ring.tga");
+               // ring around crosshair representing velocity-dependent damage for the nex
+               if (activeweapon == WEP_NEX)
+               {
+                       float f, a, curvel;
+                       vector rgb;
+
+                       rgb_x = cvar("crosshair_nexvelocity_color_red");
+                       rgb_y = cvar("crosshair_nexvelocity_color_green");
+                       rgb_z = cvar("crosshair_nexvelocity_color_blue");
+                       a = cvar("crosshair_nexvelocity_alpha");
+
+                       curvel = vlen('1 0 0' * pmove_vel_x + '0 1 0' * pmove_vel_y);
+                       f = bound(0, (curvel - nex_minvelocity) / (nex_maxvelocity - nex_minvelocity), 1);
+
+                       DrawCircleClippedPic('0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight, 0.1 * vid_conheight, "gfx/nex_ring.tga", f, rgb, a, DRAWFLAG_ADDITIVE);
+               }
+
                // crosshair goes VERY LAST
-               if(!scoreboard_active && !camera_active) {
+               if(!scoreboard_active && !camera_active && intermission != 2) {
                        // TrueAim check
                        float shottype;
                        float bullets, ring_scale;
@@ -766,13 +847,13 @@ void CSQC_UpdateView(float w, float h)
                                if (activeweapon == WEP_CAMPINGRIFLE)
                                {
                                        ring_scale = cvar("crosshair_campingrifle_ring_size");
-                                       bullets = bound(0, getstati(STAT_BULLETS_LOADED), 8);
+                                       bullets = bound(0, getstati(STAT_BULLETS_LOADED), 4);
                                }
                                else
                                        bullets = 0;
 
 #define CROSSHAIR_DRAW_RING(i,j,sz,wcross_name,wcross_alpha) \
-                               drawpic(wcross_origin - ('0.5 0 0' * (sz * wcross_size_x * ring_scale + i * wcross_blur) + '0 0.5 0' * (sz * wcross_size_y * ring_scale + j * wcross_blur)), strcat("gfx/hud/", cvar_string("hud_skin"), "/rifle_ring_", ftos(bullets)), sz * wcross_size * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL)
+                               drawpic(wcross_origin - ('0.5 0 0' * (sz * wcross_size_x * ring_scale + i * wcross_blur) + '0 0.5 0' * (sz * wcross_size_y * ring_scale + j * wcross_blur)), strcat("gfx/rifle_ring_", ftos(bullets)), sz * wcross_size * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL)
 
 #define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \
                                do \
@@ -813,7 +894,12 @@ void CSQC_UpdateView(float w, float h)
                                {
                                        CROSSHAIR_DO_BLUR(CROSSHAIR_DRAW_RING, wcross_resolution, wcross_name, wcross_alpha);
                                }
+
                                CROSSHAIR_DRAW(wcross_resolution, wcross_name, wcross_alpha * f);
+
+                               if(cvar("crosshair_dot"))
+                                       CROSSHAIR_DRAW(wcross_resolution * cvar("crosshair_dot_size"), "gfx/crosshairdot.tga", wcross_alpha * f * cvar("crosshair_dot_alpha"));
+
                                wcross_name_alpha_goal_prev = f;
                        }
                }
@@ -872,8 +958,13 @@ void CSQC_UpdateView(float w, float h)
                cvar_set("vid_conheight", h0);
        }
 
-       if(hud_configure)
+       if(autocvar__hud_configure)
                HUD_Panel_Mouse();
+
+       // let's reset the view back to normal for the end
+       R_SetView(VF_MIN, '0 0 0');
+       R_SetView(VF_SIZE, '1 0 0' * w + '0 1 0' * h);
+
        // be safe against triggerbots until everyone has the fixed engine
        // this call is meant to overwrite the trace globals by something
        // unsuspicious
@@ -1183,23 +1274,41 @@ void CSQC_common_hud(void)
        switch(hud)
        {
                case HUD_NORMAL:
-                       // hud first
-                       HUD_Main();
+                       // do some accuracy var caching
+                       float i;
+                       if(!(gametype == GAME_RACE || gametype == GAME_CTS))
+                       {
+                               acc_levels = tokenize(cvar_string("hud_panel_weapons_accuracy_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));
+                       }
+
+                       HUD_Main(); // always run these functions for alpha checks
+                       HUD_DrawScoreboard();
 
-                       // scoreboard/accuracy
-                       if (intermission == 2 && !scoreboard_showaccuracy && !scoreboard_showscores) // map voting screen
+                       if (scoreboard_showscores || scoreboard_showscores_force || getstati(STAT_HEALTH) <= 0 || intermission == 1) // scoreboard/accuracy
+                       {       
+                               HUD_Reset();
+                               // HUD_DrawScoreboard takes care of centerprint_start
+                       }
+                       else if (intermission == 2) // map voting screen
                        {
                                HUD_FinaleOverlay();
                                HUD_Reset();
-                       }
-                       else if(scoreboard_showaccuracy && spectatee_status != -1)
-                               HUD_DrawAccuracyStats();
-                       else
-                               HUD_DrawScoreboard();
 
-                       if (scoreboard_showscores || scoreboard_showaccuracy || scoreboard_showscores_force || getstati(STAT_HEALTH) <= 0 || intermission == 1)
-                               HUD_Reset();
+                               centerprint_start_x = 0;
+                               centerprint_start_y = cvar("scr_centerpos") * vid_conheight;
+                       }
+                       else // hud
+                       {
+                               centerprint_start_x = 0;
+                               centerprint_start_y = cvar("scr_centerpos") * vid_conheight;
+                       }
 
+                       HUD_DrawCenterPrint();
                        break;
 
                case HUD_SPIDERBOT: