]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Some more defs.qh cleanup, update gameplay hash (again)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index 3191a763624cbd0287aa1e988f7a499422f925a6..cbfba4c9f3ef4ae7b2b75d29b4bb559a53c7ab44 100644 (file)
@@ -3,14 +3,16 @@
 #include "selection.qh"
 
 #include "../command/common.qh"
+#include <server/g_damage.qh>
+#include <server/items/items.qh>
 #include <server/mutators/_mod.qh>
 #include "../round_handler.qh"
 #include <server/cheats.qh>
 #include <server/resources.qh>
-#include <common/t_items.qh>
 #include <common/animdecide.qh>
 #include <common/constants.qh>
 #include <common/net_linked.qh>
+#include <common/mapobjects/platforms.qh>
 #include <common/monsters/_mod.qh>
 #include <common/notifications/all.qh>
 #include <common/util.qh>
@@ -55,7 +57,7 @@ bool CL_Weaponentity_CustomizeEntityForClient(entity this, entity client)
 
 vector CL_Weapon_GetShotOrg(int wpn)
 {
-       entity wi = Weapons_from(wpn);
+       entity wi = REGISTRY_GET(Weapons, wpn);
        entity e = spawn();
        CL_WeaponEntity_SetModel(e, wi.mdl, false);
        vector ret = e.movedir;
@@ -366,6 +368,9 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
        bool restartanim;
        if (fr == WFRAME_DONTCHANGE)
        {
+               // this can happen when the weapon entity is newly spawned, since it has a clear state and no previous weapon frame
+               if (this.wframe == WFRAME_DONTCHANGE)
+                       this.wframe = WFRAME_IDLE;
                fr = this.wframe;
                restartanim = false;
        }
@@ -374,14 +379,7 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
                restartanim = fr != WFRAME_IDLE;
        }
 
-       vector a = '0 0 0';
     this.wframe = fr;
-    if (fr == WFRAME_IDLE) a = this.anim_idle;
-    else if (fr == WFRAME_FIRE1) a = this.anim_fire1;
-    else if (fr == WFRAME_FIRE2) a = this.anim_fire2;
-    else  // if (fr == WFRAME_RELOAD)
-        a = this.anim_reload;
-    a.z *= g_weaponratefactor;
 
        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?");
@@ -408,7 +406,7 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
        {
                FOREACH_CLIENT(true, {
                        if(it == actor || (IS_SPEC(it) && it.enemy == actor))
-                               wframe_send(it, this, a, restartanim);
+                               wframe_send(it, this, fr, g_weaponratefactor, restartanim);
                });
        }
 
@@ -445,6 +443,28 @@ bool weaponLocked(entity player)
        return false;
 }
 
+void W_ResetGunAlign(entity player, int preferred_alignment)
+{
+       if(W_DualWielding(player))
+               preferred_alignment = 3; // right align, the second gun will default to left
+
+       // clear current weapon slots' alignments so we can redo the calculations!
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               if (player.(weaponentity))
+                       player.(weaponentity).m_gunalign = 0;
+       }
+
+       // now set the new values
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               if (player.(weaponentity))
+                       player.(weaponentity).m_gunalign = W_GunAlign(player.(weaponentity), preferred_alignment);
+       }
+}
+
 .bool hook_switchweapon;
 
 void W_WeaponFrame(Player actor, .entity weaponentity)
@@ -828,7 +848,7 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
 
 void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity)
 {
-       Weapon w = Weapons_from(weapon_type);
+       Weapon w = REGISTRY_GET(Weapons, weapon_type);
        weapon_dropevent_item = weapon_item;
        w.event(w, player, weaponentity);
 }