]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Merge branch 'master' into cloudwalk9/mgburstfix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index 86988b6e084a7e3e74d9c0a52ad6457f4f3e776c..f1655b632269bb79a4c6b4ae732b2886f928c77d 100644 (file)
@@ -50,7 +50,7 @@ bool CL_Weaponentity_CustomizeEntityForClient(entity this, entity client)
 {
        this.viewmodelforclient = this.owner;
        if (IS_SPEC(client) && client.enemy == this.owner) this.viewmodelforclient = client;
-       return true;
+       return false;
 }
 
 vector CL_Weapon_GetShotOrg(int wpn)
@@ -163,6 +163,7 @@ void CL_ExteriorWeaponentity_Think(entity this)
     Weapon wep = this.owner.(weaponentity).m_weapon;
        if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors, this.owner.(weaponentity));
        this.colormap = this.owner.colormap;
+       this.skin = w_ent.skin;
 
        CSQCMODEL_AUTOUPDATE(this);
 }
@@ -292,9 +293,8 @@ bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponenti
 
        if (attacktime >= 0)
        {
-               int slot = weaponslot(weaponentity);
                // don't fire if previous attack is not finished
-               if (ATTACK_FINISHED(actor, slot) > time + actor.(weaponentity).weapon_frametime * 0.5) return false;
+               if (ATTACK_FINISHED(actor, weaponentity) > time + actor.(weaponentity).weapon_frametime * 0.5) return false;
                entity this = actor.(weaponentity);
                // don't fire while changing weapon
                if (this.state != WS_READY) return false;
@@ -313,16 +313,17 @@ void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary,
        // if the weapon hasn't been firing continuously, reset the timer
        if (attacktime >= 0)
        {
-               int slot = weaponslot(weaponentity);
-               if (ATTACK_FINISHED(actor, slot) < time - this.weapon_frametime * 1.5)
+               if (ATTACK_FINISHED(actor, weaponentity) < time - this.weapon_frametime * 1.5)
                {
-                       ATTACK_FINISHED(actor, slot) = time;
+                       ATTACK_FINISHED(actor, weaponentity) = time;
                        // dprint("resetting attack finished to ", ftos(time), "\n");
                }
-               ATTACK_FINISHED(actor, slot) = ATTACK_FINISHED(actor, slot) + attacktime * W_WeaponRateFactor(actor);
+               float arate = W_WeaponRateFactor(actor);
+               ATTACK_FINISHED(actor, weaponentity) = ATTACK_FINISHED(actor, weaponentity) + attacktime * arate;
 
                if(autocvar_g_weaponswitch_debug_alternate && W_DualWielding(actor))
                {
+                       int slot = weaponslot(weaponentity);
                        for(int wepslot = 0; wepslot < MAX_WEAPONSLOTS; ++wepslot)
                        {
                                if(slot == wepslot)
@@ -330,15 +331,17 @@ void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary,
                                .entity wepent = weaponentities[wepslot];
                                if(actor.(wepent) && actor.(wepent).m_weapon != WEP_Null)
                                {
-                                       if (ATTACK_FINISHED(actor, wepslot) < time - actor.(wepent).weapon_frametime * 1.5)
-                                               ATTACK_FINISHED(actor, wepslot) = time;
-                                       ATTACK_FINISHED(actor, wepslot) = ATTACK_FINISHED(actor, wepslot) + (attacktime * W_WeaponRateFactor(actor)) * 0.5;
+                                       if(ATTACK_FINISHED(actor, wepent) > time + actor.(wepent).weapon_frametime * 0.5)
+                                               continue; // still cooling down!
+                                       if (ATTACK_FINISHED(actor, wepent) < time - actor.(wepent).weapon_frametime * 1.5)
+                                               ATTACK_FINISHED(actor, wepent) = time;
+                                       ATTACK_FINISHED(actor, wepent) = ATTACK_FINISHED(actor, wepent) + (attacktime * arate) / MAX_WEAPONSLOTS;
                                }
                        }
                }
        }
        this.bulletcounter += 1;
-       // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, slot)), "\n");
+       // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, weaponentity)), "\n");
 }
 
 bool weapon_prepareattack(Weapon thiswep, entity actor, .entity weaponentity, bool secondary, float attacktime)
@@ -433,13 +436,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;
 }
 
@@ -452,15 +462,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)
                {
@@ -554,7 +564,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                                entity oldwep = this.m_weapon;
 
                                // set up weapon switch think in the future, and start drop anim
-                               if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + this.weapon_frametime * 0.5)
+                               if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponentity) <= time + this.weapon_frametime * 0.5)
                                {
                                        sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
                                        this.state = WS_DROP;
@@ -567,7 +577,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
 
        // LordHavoc: network timing test code
        // if (actor.button0)
-       //      print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, slot)), " >= ", ftos(this.weapon_nextthink), "\n");
+       //      print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, weaponentity)), " >= ", ftos(this.weapon_nextthink), "\n");
 
        Weapon w = this.m_weapon;
 
@@ -589,7 +599,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;
@@ -690,14 +700,14 @@ 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(
                                "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
-                               "Please notify Samual immediately with a copy of this backtrace!\n",
+                               "Please notify the developers immediately with a copy of this backtrace!\n",
                                ammo_use,
                                wep.netname,
                                GetAmmoPicture(wep.ammo_type),
@@ -705,7 +715,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);
        }
 }
 
@@ -725,17 +735,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;
 
@@ -743,7 +753,7 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int
        // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
        // so your weapon is disabled for a few seconds without reason
 
-       // ATTACK_FINISHED(actor, slot) -= w_ent.reload_time - 1;
+       // ATTACK_FINISHED(actor, weaponentity) -= w_ent.reload_time - 1;
 
        w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
 }
@@ -777,9 +787,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))
                        {
@@ -799,7 +809,6 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
                        }
                }
        }
-
        if (this)
        {
                if (this.wframe == WFRAME_RELOAD) return;
@@ -816,7 +825,7 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
        // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
        // so your weapon is disabled for a few seconds without reason
 
-       // ATTACK_FINISHED(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + this.reload_time + 1;
+       // ATTACK_FINISHED(actor, weaponentity) = max(time, ATTACK_FINISHED(actor, weaponentity)) + this.reload_time + 1;
 
        weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady);