]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Unhardcode a few more weapon entity checks
authorMario <mario@smbclan.net>
Sat, 1 Oct 2016 10:34:19 +0000 (20:34 +1000)
committerMario <mario@smbclan.net>
Sat, 1 Oct 2016 10:34:19 +0000 (20:34 +1000)
qcsrc/client/view.qc
qcsrc/common/weapons/weapon.qh
qcsrc/common/weapons/weapon/rifle.qc
qcsrc/common/weapons/weapon/vaporizer.qc
qcsrc/common/weapons/weapon/vortex.qc
qcsrc/server/client.qc
qcsrc/server/g_damage.qc

index 27921b182dd88b6640e7bee3ad61e3c1f5783cb3..ac58fd7927f82668c585e1cd747ca2e7ebc5fb42 100644 (file)
@@ -451,12 +451,17 @@ vector GetCurrentFov(float fov)
                        zoomspeed = 3.5;
 
        zoomdir = button_zoom;
-       entity wepent = viewmodels[0]; // TODO: unhardcode
 
        if(hud == HUD_NORMAL && !spectatee_status)
-       if(wepent.switchweapon == wepent.activeweapon)
-       if((wepent.activeweapon == WEP_VORTEX && !WEP_CVAR(vortex, secondary)) || (wepent.activeweapon == WEP_RIFLE && !WEP_CVAR(rifle, secondary))) // do NOT use switchweapon here
-               zoomdir += button_attack2;
+       {
+               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+               {
+                       entity wepent = viewmodels[slot];
+                       if(wepent.switchweapon == wepent.activeweapon)
+                       if((wepent.activeweapon == WEP_VORTEX && !WEP_CVAR(vortex, secondary)) || (wepent.activeweapon == WEP_RIFLE && !WEP_CVAR(rifle, secondary))) // do NOT use switchweapon here
+                               zoomdir += button_attack2;
+               }
+       }
        if(spectatee_status > 0 || isdemo())
        {
                if(spectatorbutton_zoom)
@@ -1943,7 +1948,14 @@ void CSQC_UpdateView(entity this, float w, float h)
 
        if(autocvar_cl_reticle)
        {
-               Weapon wep = wepent.activeweapon;
+               bool wep_zoomed = false;
+               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+               {
+                       entity wepe = viewmodels[slot];
+                       Weapon wep = wepe.activeweapon;
+                       if(wep != WEP_Null && wep.wr_zoom)
+                               wep_zoomed += wep.wr_zoom(wep, NULL);
+               }
                // 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
@@ -1953,7 +1965,7 @@ void CSQC_UpdateView(entity this, float w, float h)
                        // no zoom reticle while dead
                        reticle_type = 0;
                }
-               else if(wep.wr_zoomreticle(wep) && autocvar_cl_reticle_weapon)
+               else if(wep_zoomed && autocvar_cl_reticle_weapon)
                {
                        if(reticle_image != "") { reticle_type = 2; }
                        else { reticle_type = 0; }
index a83629f9695ae15e8a614164c3228ed6aeeaec50..9d7d11ddba35df57039fd3dab2352d3f784083e1 100644 (file)
@@ -112,8 +112,8 @@ CLASS(Weapon, Object)
     METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
     /** (ALL)    dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
     METHOD(Weapon, wr_config, void(Weapon this)) {}
-    /** (CLIENT) weapon specific zoom reticle */
-    METHOD(Weapon, wr_zoomreticle, bool(Weapon this)) {
+    /** (BOTH) weapon specific zoom reticle */
+    METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
         // no weapon specific image for this weapon
         return false;
     }
index 6dbcd31c280a6593fafeb67a0f1fd338ed5674f9..4794e866a0ce897d1eb0db0aceb538f0aa7fecc0 100644 (file)
@@ -241,6 +241,10 @@ METHOD(Rifle, wr_killmessage, Notification(entity thiswep))
             return WEAPON_RIFLE_MURDER;
     }
 }
+METHOD(Rifle, wr_zoom, bool(entity thiswep, entity actor))
+{
+    return PHYS_INPUT_BUTTON_ATCK2(actor) && WEP_CVAR(rifle, secondary) == 0;
+}
 
 #endif
 #ifdef CSQC
@@ -262,7 +266,7 @@ METHOD(Rifle, wr_init, void(entity thiswep))
         precache_pic("gfx/reticle_nex");
     }
 }
-METHOD(Rifle, wr_zoomreticle, bool(entity thiswep))
+METHOD(Rifle, wr_zoom, bool(entity thiswep, entity actor))
 {
     if(button_zoom || zoomscript_caught)
     {
index 5a9a8735fb96f6f0eace1329680e78686de25f5f..0c0b5b0c3f051ee0a4e9ff4de63aefb50383f1f7 100644 (file)
@@ -501,7 +501,7 @@ METHOD(Vaporizer, wr_init, void(entity thiswep))
         precache_pic("gfx/reticle_nex");
     }
 }
-METHOD(Vaporizer, wr_zoomreticle, bool(entity thiswep))
+METHOD(Vaporizer, wr_zoom, bool(entity thiswep, entity actor))
 {
     if(button_zoom || zoomscript_caught)
     {
index 331885b329d72e7f4e31352c288ffcd3534eaaea..1fbb901d5159bc24a70a26361b437870f1c80363 100644 (file)
@@ -384,6 +384,10 @@ METHOD(Vortex, wr_killmessage, Notification(entity thiswep))
 {
     return WEAPON_VORTEX_MURDER;
 }
+METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
+{
+    return PHYS_INPUT_BUTTON_ATCK2(actor);
+}
 
 #endif
 #ifdef CSQC
@@ -403,7 +407,7 @@ METHOD(Vortex, wr_init, void(entity thiswep))
         precache_pic("gfx/reticle_nex");
     }
 }
-METHOD(Vortex, wr_zoomreticle, bool(entity thiswep))
+METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
 {
     if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
     {
index 205eb0cb396dd0bfc55e0002006b4c4330a09a86..0d4d1e6204001e9ffbee8e26c95ea20a5b6d527d 100644 (file)
@@ -2474,13 +2474,16 @@ void PlayerPreThink (entity this)
        }
 
        // WEAPONTODO: Add weapon request for this
-       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
        if (!zoomstate_set) {
-               SetZoomState(this,
-                       PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this)
-                       || (PHYS_INPUT_BUTTON_ATCK2(this) && this.(weaponentity).m_weapon == WEP_VORTEX)
-                       || (PHYS_INPUT_BUTTON_ATCK2(this) && this.(weaponentity).m_weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)
-               );
+               bool wep_zoomed = false;
+               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+               {
+                       .entity weaponentity = weaponentities[slot];
+                       Weapon thiswep = this.(weaponentity).m_weapon;
+                       if(thiswep != WEP_Null && thiswep.wr_zoom)
+                               wep_zoomed += thiswep.wr_zoom(thiswep, this);
+               }
+               SetZoomState(this, PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this) || wep_zoomed);
     }
 
        if (this.teamkill_soundtime && time > this.teamkill_soundtime)
@@ -2503,6 +2506,7 @@ void PlayerPreThink (entity this)
 
        // WEAPONTODO: Move into weaponsystem somehow
        // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
+       .entity weaponentity = weaponentities[0];
        if (this.(weaponentity).m_weapon == WEP_Null)
                this.clip_load = this.clip_size = 0;
 }
index 531ad6f530642d5218076c1d243d309f1ff5aacf..6b968bc80028ed888c54d5864476de6e7fab4843 100644 (file)
@@ -117,14 +117,15 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype)
 
 string AppendItemcodes(string s, entity player)
 {
-       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
-
-       int w = player.(weaponentity).m_weapon.m_id;
-       //if(w == 0)
-       //      w = player.switchweapon;
-       if(w == 0)
-               w = player.(weaponentity).cnt; // previous weapon!
-       s = strcat(s, ftos(w));
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               int w = player.(weaponentity).m_weapon.m_id;
+               if(w == 0)
+                       w = player.(weaponentity).cnt; // previous weapon
+               if(w != 0 || slot == 0)
+                       s = strcat(s, ftos(w));
+       }
        if(time < player.strength_finished)
                s = strcat(s, "S");
        if(time < player.invincible_finished)