]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/view.qc
Viewmodel: mimic player model effects
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / view.qc
index 1475bf232603a540b62886e7f35080f74cc7700b..95167a1c4c752c4189d6a6e5568f02b6d0c2d5fa 100644 (file)
@@ -1,36 +1,65 @@
-#include "_all.qh"
 
 #include "announcer.qh"
 #include "hook.qh"
 #include "hud.qh"
 #include "hud_config.qh"
 #include "mapvoting.qh"
-#include "noise.qh"
 #include "scoreboard.qh"
 #include "shownames.qh"
-#include "waypointsprites.qh"
+#include "quickmenu.qh"
 
 #include "mutators/events.qh"
 
+#include "../common/anim.qh"
 #include "../common/constants.qh"
 #include "../common/mapinfo.qh"
-#include "../common/nades.qh"
+#include "../common/gamemodes/all.qh"
+#include "../common/nades/all.qh"
 #include "../common/stats.qh"
 #include "../common/triggers/target/music.qh"
 #include "../common/teams.qh"
-#include "../common/util.qh"
 
+#include "../common/vehicles/all.qh"
 #include "../common/weapons/all.qh"
+#include "../common/viewloc.qh"
+#include "../common/minigames/cl_minigames.qh"
+#include "../common/minigames/cl_minigames_hud.qh"
 
-#include "../csqcmodellib/cl_player.qh"
+#include "../lib/csqcmodel/cl_player.qh"
 
-#include "../warpzonelib/client.qh"
-#include "../warpzonelib/common.qh"
-#include "../warpzonelib/mathlib.qh"
+#include "../lib/warpzone/client.qh"
+#include "../lib/warpzone/common.qh"
+
+#define EFMASK_CHEAP (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NODRAW | EF_NOSHADOW | EF_SELECTABLE | EF_TELEPORT_BIT)
+
+void viewmodel_draw(entity this)
+{
+       int mask = (intermission || (getstati(STAT_HEALTH) <= 0) || autocvar_chase_active) ? 0 : MASK_NORMAL;
+       int c = stof(getplayerkeyvalue(current_player, "colors"));
+       vector g = colormapPaletteColor(c & 0x0F, true) * 2;
+       entity me = CSQCModel_server2csqc(player_localentnum);
+       int fx = ((me.csqcmodel_effects & EFMASK_CHEAP)
+               | EF_NODEPTHTEST)
+               &~ (EF_FULLBRIGHT); // can mask team color, so get rid of it
+       for (entity e = this; e; e = e.weaponchild)
+       {
+               e.drawmask = mask;
+               e.colormap = c;
+               e.glowmod = g;
+               e.csqcmodel_effects = fx;
+               WITH(entity, self, e, CSQCModel_Effects_Apply());
+       }
+}
+
+entity viewmodel;
+STATIC_INIT(viewmodel) {
+    viewmodel = new(viewmodel);
+       viewmodel.draw = viewmodel_draw;
+}
 
 entity porto;
 vector polyline[16];
-void Porto_Draw()
+void Porto_Draw(entity this)
 {
        vector p, dir, ang, q, nextdir;
        float portal_number, portal1_idx;
@@ -134,6 +163,7 @@ vector GetCurrentFov(float fov)
 
        zoomdir = button_zoom;
        if(hud == HUD_NORMAL)
+       if(switchweapon == activeweapon)
        if((activeweapon == WEP_VORTEX.m_id && vortex_scope) || (activeweapon == WEP_RIFLE.m_id && rifle_scope)) // do NOT use switchweapon here
                zoomdir += button_attack2;
        if(spectatee_status > 0 || isdemo())
@@ -323,6 +353,7 @@ float TrueAimCheck()
        {
                case WEP_TUBA.m_id: // no aim
                case WEP_PORTO.m_id: // shoots from eye
+               case WEP_NEXBALL.m_id: // shoots from eye
                case WEP_HOOK.m_id: // no trueaim
                case WEP_MORTAR.m_id: // toss curve
                        return SHOTTYPE_HITWORLD;
@@ -395,8 +426,6 @@ float TrueAimCheck()
        return SHOTTYPE_HITWORLD;
 }
 
-void CSQC_common_hud(void);
-
 void PostInit(void);
 void CSQC_Demo_Camera();
 float HUD_WouldDrawScoreboard();
@@ -429,7 +458,7 @@ vector liquidcolor_prev;
 float eventchase_current_distance;
 float eventchase_running;
 bool WantEventchase()
-{
+{SELFPARAM();
        if(autocvar_cl_orthoview)
                return false;
        if(intermission)
@@ -440,7 +469,9 @@ bool WantEventchase()
        {
                if(hud != HUD_NORMAL && (autocvar_cl_eventchase_vehicle || spectatee_status > 0))
                        return true;
-               if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WepSet_FromWeapon(WEP_PORTO.m_id)))
+               if(MUTATOR_CALLHOOK(WantEventchase, self))
+                       return true;
+               if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WepSet_FromWeapon(WEP_NEXBALL.m_id)))
                        return true;
                if(autocvar_cl_eventchase_death && (getstati(STAT_HEALTH) <= 0))
                {
@@ -456,9 +487,16 @@ bool WantEventchase()
        return false;
 }
 
-vector damage_blurpostprocess, content_blurpostprocess;
+void HUD_Crosshair_Vehicle()
+{
+       if(hud != HUD_BUMBLEBEE_GUN)
+       {
+               Vehicle info = get_vehicleinfo(hud);
+               info.vr_crosshair(info);
+       }
+}
 
-float checkfail[16];
+vector damage_blurpostprocess, content_blurpostprocess;
 
 float unaccounted_damage = 0;
 void UpdateDamage()
@@ -474,7 +512,7 @@ void UpdateDamage()
        if (damage_dealt_time != damage_dealt_time_prev)
        {
                unaccounted_damage += unaccounted_damage_new;
-               dprint("dmg total: ", ftos(unaccounted_damage), " (+", ftos(unaccounted_damage_new), ")", "\n");
+               LOG_TRACE("dmg total: ", ftos(unaccounted_damage), " (+", ftos(unaccounted_damage_new), ")", "\n");
        }
        damage_dealt_time_prev = damage_dealt_time;
 
@@ -485,7 +523,7 @@ void UpdateDamage()
        spectatee_status_prev = spectatee_status;
 }
 
-void UpdateHitsound()
+void HitSound()
 {
        // varying sound pitch
 
@@ -514,12 +552,12 @@ void UpdateHitsound()
                                pitch_shift = mirror_value + (mirror_value - pitch_shift);
                        }
 
-                       dprint("dmg total (dmg): ", ftos(unaccounted_damage), " , pitch shift: ", ftos(pitch_shift), "\n");
+                       LOG_TRACE("dmg total (dmg): ", ftos(unaccounted_damage), " , pitch shift: ", ftos(pitch_shift), "\n");
 
                        // todo: avoid very long and very short sounds from wave stretching using different sound files? seems unnecessary
                        // todo: normalize sound pressure levels? seems unnecessary
 
-                       sound7(world, CH_INFO, "misc/hit.wav", VOL_BASE, ATTN_NONE, pitch_shift * 100, 0);
+                       sound7(world, CH_INFO, SND(HIT), VOL_BASE, ATTN_NONE, pitch_shift * 100, 0);
                }
                unaccounted_damage = 0;
                hitsound_time_prev = time;
@@ -529,44 +567,31 @@ void UpdateHitsound()
        float typehit_time = getstatf(STAT_TYPEHIT_TIME);
        if (COMPARE_INCREASING(typehit_time, typehit_time_prev) > autocvar_cl_hitsound_antispam_time)
        {
-               sound(world, CH_INFO, "misc/typehit.wav", VOL_BASE, ATTN_NONE);
+               sound(world, CH_INFO, SND_TYPEHIT, VOL_BASE, ATTN_NONE);
                typehit_time_prev = typehit_time;
        }
 }
 
-void UpdateCrosshair()
-{
+void HUD_Crosshair()
+{SELFPARAM();
        static float rainbow_last_flicker;
-    static vector rainbow_prev_color;
+       static vector rainbow_prev_color;
        entity e = self;
        float f, i, j;
        vector v;
-       if(getstati(STAT_FROZEN))
-               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, ((getstatf(STAT_REVIVE_PROGRESS)) ? ('0.25 0.90 1' + ('1 0 0' * getstatf(STAT_REVIVE_PROGRESS)) + ('0 1 1' * getstatf(STAT_REVIVE_PROGRESS) * -1)) : '0.25 0.90 1'), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
-       else if (getstatf(STAT_HEALING_ORB)>time)
-               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, NADE_TYPE_HEAL.m_color, autocvar_hud_colorflash_alpha*getstatf(STAT_HEALING_ORB_ALPHA), DRAWFLAG_ADDITIVE);
-       if(!intermission)
-       if(getstatf(STAT_NADE_TIMER) && autocvar_cl_nade_timer) // give nade top priority, as it's a matter of life and death
-       {
-               DrawCircleClippedPic(eX * 0.5 * vid_conwidth + eY * 0.6 * vid_conheight, 0.1 * vid_conheight, "gfx/crosshair_ring.tga", getstatf(STAT_NADE_TIMER), '0.25 0.90 1' + ('1 0 0' * getstatf(STAT_NADE_TIMER)) - ('0 1 1' * getstatf(STAT_NADE_TIMER)), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
-               drawstring_aspect(eY * 0.64 * vid_conheight, ((autocvar_cl_nade_timer == 2) ? _("Nade timer") : ""), eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
-       }
-       else 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);
-       }
-
-       if(autocvar_r_letterbox == 0)
-               if(autocvar_viewsize < 120)
-                       CSQC_common_hud();
-
-       // crosshair goes VERY LAST
-       if(!scoreboard_active && !camera_active && intermission != 2 && spectatee_status != -1 && hud == HUD_NORMAL && !csqcplayer.viewloc)
+       if(!scoreboard_active && !camera_active && intermission != 2 &&
+               spectatee_status != -1 && !csqcplayer.viewloc &&
+               !HUD_MinigameMenu_IsOpened() )
        {
                if (!autocvar_crosshair_enabled) // main toggle for crosshair rendering
                        return;
 
+               if (hud != HUD_NORMAL)
+               {
+                       HUD_Crosshair_Vehicle();
+                       return;
+               }
+
                string wcross_style;
                float wcross_alpha, wcross_resolution;
                wcross_style = autocvar_crosshair;
@@ -1006,18 +1031,60 @@ void UpdateCrosshair()
        }
 }
 
+void HUD_Draw()
+{
+       if(getstati(STAT_FROZEN))
+               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, ((getstatf(STAT_REVIVE_PROGRESS)) ? ('0.25 0.90 1' + ('1 0 0' * getstatf(STAT_REVIVE_PROGRESS)) + ('0 1 1' * getstatf(STAT_REVIVE_PROGRESS) * -1)) : '0.25 0.90 1'), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
+       else if (getstatf(STAT_HEALING_ORB)>time)
+               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, NADE_TYPE_HEAL.m_color, autocvar_hud_colorflash_alpha*getstatf(STAT_HEALING_ORB_ALPHA), DRAWFLAG_ADDITIVE);
+       if(!intermission)
+       if(getstatf(STAT_NADE_TIMER) && autocvar_cl_nade_timer) // give nade top priority, as it's a matter of life and death
+       {
+               DrawCircleClippedPic(eX * 0.5 * vid_conwidth + eY * 0.6 * vid_conheight, 0.1 * vid_conheight, "gfx/crosshair_ring.tga", getstatf(STAT_NADE_TIMER), '0.25 0.90 1' + ('1 0 0' * getstatf(STAT_NADE_TIMER)) - ('0 1 1' * getstatf(STAT_NADE_TIMER)), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
+               drawstring_aspect(eY * 0.64 * vid_conheight, ((autocvar_cl_nade_timer == 2) ? _("Nade timer") : ""), eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
+       }
+       else 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);
+       }
+
+       if(autocvar_r_letterbox == 0)
+               if(autocvar_viewsize < 120)
+               {
+                       if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
+                               Accuracy_LoadLevels();
+
+                       HUD_Main();
+                       HUD_DrawScoreboard();
+               }
+
+       // crosshair goes VERY LAST
+       UpdateDamage();
+       HUD_Crosshair();
+       HitSound();
+}
+
+bool ov_enabled;
+float oldr_nearclip;
+float oldr_farclip_base;
+float oldr_farclip_world;
+float oldr_novis;
+float oldr_useportalculling;
+float oldr_useinfinitefarclip;
+
 const int BUTTON_3 = 4;
 const int BUTTON_4 = 8;
 float cl_notice_run();
 float prev_myteam;
 int lasthud;
 float vh_notice_time;
+void WaypointSprite_Load();
 void CSQC_UpdateView(float w, float h)
-{
+{SELFPARAM();
        entity e;
        float fov;
        float f;
-       int i;
        vector vf_size, vf_min;
        float a;
 
@@ -1047,22 +1114,6 @@ void CSQC_UpdateView(float w, float h)
        button_attack2 = (input_buttons & BUTTON_3);
        button_zoom = (input_buttons & BUTTON_4);
 
-#define CHECKFAIL_ASSERT(flag,func,parm,val) do {                                                                   \
-       float 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;                                                                                      \
-       }                                                                                                               \
-} while(0)
-       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);
-       CHECKFAIL_ASSERT(2, cvar, "\{114}\{95}\{115}\{104}\{111}\{119}\{100}\{105}\{115}\{97}\{98}\{108}\{101}\{100}\{101}\{112}\{116}\{104}\{116}\{101}\{115}\{116}", 0);
-       CHECKFAIL_ASSERT(3, cvar, "\{114}\{95}\{115}\{104}\{111}\{119}\{111}\{118}\{101}\{114}\{100}\{114}\{97}\{119}", 0);
-       CHECKFAIL_ASSERT(4, cvar, "\{114}\{95}\{115}\{104}\{111}\{119}\{108}\{105}\{103}\{104}\{116}", 0);
-       CHECKFAIL_ASSERT(5, cvar, "\{114}\{95}\{115}\{104}\{111}\{119}\{115}\{104}\{97}\{100}\{111}\{119}\{118}\{111}\{108}\{117}\{109}\{101}\{115}", 0);
-       CHECKFAIL_ASSERT(6, cvar, "\{114}\{95}\{115}\{104}\{111}\{119}\{111}\{118}\{101}\{114}\{100}\{114}\{97}\{119}", 0);
-
        vf_size = getpropertyvec(VF_SIZE);
        vf_min = getpropertyvec(VF_MIN);
        vid_width = vf_size.x;
@@ -1084,8 +1135,7 @@ void CSQC_UpdateView(float w, float h)
        if(myteam != prev_myteam)
        {
                myteamcolors = colormapPaletteColor(myteam, 1);
-               for(i = 0; i < HUD_PANEL_NUM; ++i)
-                       hud_panel[i].update_time = time;
+               FOREACH(hud_panels, true, LAMBDA(it.update_time = time));
                prev_myteam = myteam;
        }
 
@@ -1113,16 +1163,35 @@ void CSQC_UpdateView(float w, float h)
        if(autocvar_chase_active <= 0) // greater than 0 means it's enabled manually, and this code is skipped
        {
                float vehicle_chase = (hud != HUD_NORMAL && (autocvar_cl_eventchase_vehicle || spectatee_status > 0));
-               if(WantEventchase())
+               float ons_roundlost = (gametype == MAPINFO_TYPE_ONSLAUGHT && getstati(STAT_ROUNDLOST));
+               entity gen = world;
+
+               if(ons_roundlost)
+               {
+                       entity e;
+                       for(e = world; (e = find(e, classname, "onslaught_generator")); )
+                       {
+                               if(e.health <= 0)
+                               {
+                                       gen = e;
+                                       break;
+                               }
+                       }
+                       if(!gen)
+                               ons_roundlost = FALSE; // don't enforce the 3rd person camera if there is no dead generator to show
+               }
+               if(WantEventchase() || (!autocvar_cl_orthoview && ons_roundlost))
                {
                        eventchase_running = true;
 
                        // 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 = (csqcplayer ? csqcplayer.origin : pmove_org);
+                       if(ons_roundlost) { current_view_origin = gen.origin; }
 
                        // detect maximum viewoffset and use it
                        vector view_offset = autocvar_cl_eventchase_viewoffset;
                        if(vehicle_chase && autocvar_cl_eventchase_vehicle_viewoffset) { view_offset = autocvar_cl_eventchase_vehicle_viewoffset; }
+                       if(ons_roundlost) { view_offset = autocvar_cl_eventchase_generator_viewoffset; }
 
                        if(view_offset)
                        {
@@ -1139,6 +1208,7 @@ void CSQC_UpdateView(float w, float h)
                        // make the camera smooth back
                        float chase_distance = autocvar_cl_eventchase_distance;
                        if(vehicle_chase && autocvar_cl_eventchase_vehicle_distance) { chase_distance = autocvar_cl_eventchase_vehicle_distance; }
+                       if(ons_roundlost) { chase_distance = autocvar_cl_eventchase_generator_distance; }
 
                        if(autocvar_cl_eventchase_speed && eventchase_current_distance < chase_distance)
                                eventchase_current_distance += autocvar_cl_eventchase_speed * (chase_distance - eventchase_current_distance) * frametime; // slow down the further we get
@@ -1179,7 +1249,7 @@ void CSQC_UpdateView(float w, float h)
        }
 
        // do lockview after event chase camera so that it still applies whenever necessary.
-       if(autocvar_cl_lockview || (!autocvar_hud_cursormode && (autocvar__hud_configure && spectatee_status <= 0 || intermission > 1)))
+       if(autocvar_cl_lockview || (!autocvar_hud_cursormode && (autocvar__hud_configure && spectatee_status <= 0 || intermission > 1 || QuickMenu_IsOpened())))
        {
                setproperty(VF_ORIGIN, freeze_org);
                setproperty(VF_ANGLES, freeze_ang);
@@ -1192,6 +1262,18 @@ void CSQC_UpdateView(float w, float h)
 
        WarpZone_FixView();
        //WarpZone_FixPMove();
+       {
+               static string name_last;
+               string name = get_weaponinfo(switchingweapon).mdl;
+               if (name != name_last)
+               {
+                   name_last = name;
+                       CL_WeaponEntity_SetModel(viewmodel, name);
+                       updateanim(viewmodel);
+                       if (!viewmodel.animstate_override)
+                               setanim(viewmodel, viewmodel.anim_idle, true, false, false);
+               }
+       }
 
        vector ov_org = '0 0 0';
        vector ov_mid = '0 0 0';
@@ -1227,6 +1309,16 @@ void CSQC_UpdateView(float w, float h)
                if((dist = vlen(vec3(ov_worldmax.x, ov_worldmin.y, ov_worldmax.z) - ov_org)) > ov_furthest) { ov_furthest = dist; }
                if((dist = vlen(vec3(ov_worldmax.x, ov_worldmax.y, ov_worldmax.z) - ov_org)) > ov_furthest) { ov_furthest = dist; }
 
+               if(!ov_enabled)
+               {
+                       oldr_nearclip = cvar("r_nearclip");
+                       oldr_farclip_base = cvar("r_farclip_base");
+                       oldr_farclip_world = cvar("r_farclip_world");
+                       oldr_novis = cvar("r_novis");
+                       oldr_useportalculling = cvar("r_useportalculling");
+                       oldr_useinfinitefarclip = cvar("r_useinfinitefarclip");
+               }
+
                cvar_settemp("r_nearclip", ftos(ov_nearest));
                cvar_settemp("r_farclip_base", ftos(ov_furthest));
                cvar_settemp("r_farclip_world", "0");
@@ -1237,8 +1329,10 @@ void CSQC_UpdateView(float w, float h)
                setproperty(VF_ORIGIN, ov_org);
                setproperty(VF_ANGLES, '90 0 0');
 
+               ov_enabled = true;
+
                #if 0
-               printf("OrthoView: org = %s, angles = %s, distance = %f, nearest = %f, furthest = %f\n",
+               LOG_INFOF("OrthoView: org = %s, angles = %s, distance = %f, nearest = %f, furthest = %f\n",
                        vtos(ov_org),
                        vtos(getpropertyvec(VF_ANGLES)),
                        ov_distance,
@@ -1246,6 +1340,19 @@ void CSQC_UpdateView(float w, float h)
                        ov_furthest);
                #endif
        }
+       else
+       {
+               if(ov_enabled)
+               {
+                       cvar_set("r_nearclip", ftos(oldr_nearclip));
+                       cvar_set("r_farclip_base", ftos(oldr_farclip_base));
+                       cvar_set("r_farclip_world", ftos(oldr_farclip_world));
+                       cvar_set("r_novis", ftos(oldr_novis));
+                       cvar_set("r_useportalculling", ftos(oldr_useportalculling));
+                       cvar_set("r_useinfinitefarclip", ftos(oldr_useinfinitefarclip));
+               }
+               ov_enabled = false;
+       }
 
        // Render the Scene
        view_origin = getpropertyvec(VF_ORIGIN);
@@ -1428,11 +1535,9 @@ void CSQC_UpdateView(float w, float h)
           mousepos = mousepos*0.5 + getmousepos();
         */
 
-       e = self;
-       for(self = world; (self = nextent(self)); )
-               if(self.draw)
-                       self.draw();
-       self = e;
+       for(entity e = NULL; (e = nextent(e)); ) if (e.draw) {
+               WITH(entity, self, e, e.draw(e));
+       }
 
        addentities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS);
        renderscene();
@@ -1495,6 +1600,7 @@ void CSQC_UpdateView(float w, float h)
 
        if(autocvar_cl_reticle)
        {
+               Weapon wep = get_weaponinfo(activeweapon);
                // 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
@@ -1504,7 +1610,7 @@ void CSQC_UpdateView(float w, float h)
                        // no zoom reticle while dead
                        reticle_type = 0;
                }
-               else if(WEP_ACTION(activeweapon, WR_ZOOMRETICLE) && autocvar_cl_reticle_weapon)
+               else if(wep.wr_zoomreticle(wep) && autocvar_cl_reticle_weapon)
                {
                        if(reticle_image != "") { reticle_type = 2; }
                        else { reticle_type = 0; }
@@ -1675,16 +1781,15 @@ void CSQC_UpdateView(float w, float h)
                        if(autocvar_cl_gentle_damage == 2)
                        {
                                if(myhealth_flash < pain_threshold) // only randomize when the flash is gone
-                               {
                                        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);
+                       if(myhealth_flash_temp > 0)
+                               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
+               else if(myhealth_flash_temp > 0)
                        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.
@@ -1767,18 +1872,14 @@ void CSQC_UpdateView(float w, float h)
          } else */
 
        // draw 2D entities
-       e = self;
-       for(self = world; (self = nextent(self)); )
-               if(self.draw2d)
-                       self.draw2d();
-       self = e;
+       for (entity e = NULL; (e = nextent(e)); ) if (e.draw2d) {
+               WITH(entity, self, e, e.draw2d(e));
+       }
        Draw_ShowNames_All();
 
        scoreboard_active = HUD_WouldDrawScoreboard();
 
-       UpdateDamage();
-       UpdateCrosshair();
-       UpdateHitsound();
+       HUD_Draw();
 
        if(NextFrameCommand)
        {
@@ -1815,12 +1916,12 @@ void CSQC_UpdateView(float w, float h)
 
        if(autocvar__hud_configure)
                HUD_Panel_Mouse();
-
-    if(hud && !intermission)
-    if(hud == HUD_BUMBLEBEE_GUN)
-       CSQC_BUMBLE_GUN_HUD();
-    else
-               VEH_ACTION(hud, VR_HUD);
+       else if ( HUD_MinigameMenu_IsOpened() || minigame_isactive() )
+               HUD_Minigame_Mouse();
+       else if(QuickMenu_IsOpened())
+               QuickMenu_Mouse();
+       else
+               HUD_Radar_Mouse();
 
        cl_notice_run();
 
@@ -1830,20 +1931,6 @@ void CSQC_UpdateView(float w, float h)
 }
 
 
-void CSQC_common_hud(void)
-{
-       if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
-               Accuracy_LoadLevels();
-
-       HUD_Main(); // always run these functions for alpha checks
-       HUD_DrawScoreboard();
-
-       // scoreboard/accuracy, map/gametype voting screen
-       if (scoreboard_active || intermission == 2)
-               HUD_Reset();
-}
-
-
 // following vectors must be global to allow seamless switching between camera modes
 vector camera_offset, current_camera_offset, mouse_angles, current_angles, current_origin, current_position;
 void CSQC_Demo_Camera()