]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Merge branch 'master' into martin-t/globals
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index d791fc798e3056c1eb8dd6c5931561f4b282871e..936b64f2ba71b50743739c9afbfa52c1db92fb5b 100644 (file)
@@ -373,10 +373,6 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
                restartanim = fr != WFRAME_IDLE;
        }
 
-       vector of = v_forward;
-       vector or = v_right;
-       vector ou = v_up;
-
        vector a = '0 0 0';
     this.wframe = fr;
     if (fr == WFRAME_IDLE) a = this.anim_idle;
@@ -386,10 +382,6 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
         a = this.anim_reload;
     a.z *= g_weaponratefactor;
 
-       v_forward = of;
-       v_right = or;
-       v_up = ou;
-
        if (this.weapon_think == w_ready && func != w_ready && this.state == WS_RAISE) backtrace(
                        "Tried to override initial weapon think function - should this really happen?");
 
@@ -435,13 +427,20 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
        }
 }
 
-bool forbidWeaponUse(entity player)
+bool weaponUseForbidden(entity player)
+{
+       if (round_handler_IsActive() && !round_handler_IsRoundStarted()) return true;
+       if (MUTATOR_CALLHOOK(ForbidWeaponUse, player)) return true;
+       return false;
+}
+
+bool weaponLocked(entity player)
 {
        if (time < game_starttime && !sv_ready_restart_after_countdown) return true;
        if (player.player_blocked) return true;
        if (game_stopped) return true;
        if (STAT(FROZEN, player)) return true;
-       if (MUTATOR_CALLHOOK(ForbidWeaponUse, player)) return true;
+       if (MUTATOR_CALLHOOK(LockWeapon, player)) return true;
        return false;
 }
 
@@ -454,15 +453,15 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
        entity this = actor.(weaponentity);
        if (frametime) this.weapon_frametime = frametime;
 
-       if (!this || GetResourceAmount(actor, RESOURCE_HEALTH) < 1) return;  // Dead player can't use weapons and injure impulse commands
+       if (!this || GetResource(actor, RES_HEALTH) < 1) return;  // Dead player can't use weapons and injure impulse commands
 
        int button_atck = PHYS_INPUT_BUTTON_ATCK(actor);
        int button_atck2 = PHYS_INPUT_BUTTON_ATCK2(actor);
 
-       if (round_handler_IsActive() && !round_handler_IsRoundStarted())
+       if (weaponUseForbidden(actor))
                button_atck = button_atck2 = 0; // forbid primary and secondary fire, switching is allowed
 
-       if (forbidWeaponUse(actor))
+       if (weaponLocked(actor))
        {
                if (this.state != WS_CLEAR)
                {
@@ -500,10 +499,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                return;
        }
 
-       makevectors(actor.v_angle);
-       vector fo = v_forward;  // save them in case the weapon think functions change it
-       vector ri = v_right;
-       vector up = v_up;
+       MAKE_VECTORS_NEW(actor.v_angle, fo, ri, up);
 
        // Change weapon
        if (this.m_weapon != this.m_switchweapon)
@@ -591,7 +587,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                bool block_weapon = false;
                {
                        bool key_pressed = PHYS_INPUT_BUTTON_HOOK(actor) && !actor.vehicle;
-                       if (round_handler_IsActive() && !round_handler_IsRoundStarted())
+                       if (weaponUseForbidden(actor))
                                key_pressed = false;
 
                        Weapon off = actor.offhand;
@@ -692,9 +688,9 @@ void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponenti
                w_ent.clip_load -= ammo_use;
                w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
        }
-       else if (wep.ammo_type != RESOURCE_NONE)
+       else if (wep.ammo_type != RES_NONE)
        {
-               float ammo = GetResourceAmount(actor, wep.ammo_type);
+               float ammo = GetResource(actor, wep.ammo_type);
                if (ammo < ammo_use)
                {
                        backtrace(sprintf(
@@ -707,7 +703,7 @@ void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponenti
                                ammo
                                             ));
                }
-               SetResourceAmount(actor, wep.ammo_type, ammo - ammo_use);
+               SetResource(actor, wep.ammo_type, ammo - ammo_use);
        }
 }
 
@@ -727,17 +723,17 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int
        w_ent.clip_load = w_ent.old_clip_load;  // restore the ammo counter, in case we still had ammo in the weapon before reloading
 
        // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
-       if (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_type == RESOURCE_NONE)
+       if (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_type == RES_NONE)
        {
                w_ent.clip_load = w_ent.reload_ammo_amount;
        }
        else
        {
                // make sure we don't add more ammo than we have
-               float ammo = GetResourceAmount(actor, wpn.ammo_type);
+               float ammo = GetResource(actor, wpn.ammo_type);
                float load = min(w_ent.reload_ammo_amount - w_ent.clip_load, ammo);
                w_ent.clip_load += load;
-               SetResourceAmount(actor, wpn.ammo_type, ammo - load);
+               SetResource(actor, wpn.ammo_type, ammo - load);
        }
        w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
 
@@ -779,9 +775,9 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
        if (this.clip_load >= this.reload_ammo_amount) return;
 
        // no ammo, so nothing to load
-       if (e.ammo_type != RESOURCE_NONE)
+       if (e.ammo_type != RES_NONE)
        {
-               if (!GetResourceAmount(actor, e.ammo_type) && this.reload_ammo_min)
+               if (!GetResource(actor, e.ammo_type) && this.reload_ammo_min)
                {
                        if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                        {