]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Offhand: fix machinegun (still needs .clip_load > 0)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index b725cbd195c60caab1521c659abad2763b7e14f0..a6961aec87196383bb63f383e850fc873c7f92fb 100644 (file)
@@ -47,7 +47,7 @@ float W_WeaponSpeedFactor()
 }
 
 
-void(float fr, float t, void() func) weapon_thinkf;
+void weapon_thinkf(float fr, float t, void(Weapon thiswep, bool fire1, bool fire2) func);
 
 float CL_Weaponentity_CustomizeEntityForClient()
 {SELFPARAM();
@@ -117,12 +117,12 @@ void CL_WeaponEntity_SetModel(string name)
                // if there is a child entity, hide it until we're sure we use it
                if (self.weaponentity)
                        self.weaponentity.model = "";
-               setmodel(self, W_Model(strcat("v_", name, ".md3")));
+               _setmodel(self, W_Model(strcat("v_", name, ".md3")));
                v_shot_idx = gettagindex(self, "shot"); // used later
                if(!v_shot_idx)
                        v_shot_idx = gettagindex(self, "tag_shot");
 
-               setmodel(self, W_Model(strcat("h_", name, ".iqm")));
+               _setmodel(self, W_Model(strcat("h_", name, ".iqm")));
                // preset some defaults that work great for renamed zym files (which don't need an animinfo)
                self.anim_fire1  = animfixfps(self, '0 1 0.01', '0 0 0');
                self.anim_fire2  = animfixfps(self, '1 1 0.01', '0 0 0');
@@ -135,14 +135,14 @@ void CL_WeaponEntity_SetModel(string name)
                {
                        if (!self.weaponentity)
                                self.weaponentity = spawn();
-                       setmodel(self.weaponentity, W_Model(strcat("v_", name, ".md3")));
+                       _setmodel(self.weaponentity, W_Model(strcat("v_", name, ".md3")));
                        setattachment(self.weaponentity, self, "weapon");
                }
                else if(gettagindex(self, "tag_weapon"))
                {
                        if (!self.weaponentity)
                                self.weaponentity = spawn();
-                       setmodel(self.weaponentity, W_Model(strcat("v_", name, ".md3")));
+                       _setmodel(self.weaponentity, W_Model(strcat("v_", name, ".md3")));
                        setattachment(self.weaponentity, self, "tag_weapon");
                }
                else
@@ -376,7 +376,7 @@ void CL_ExteriorWeaponentity_Think()
                self.dmg = self.owner.modelindex;
                self.deadflag = self.owner.deadflag;
                if (self.owner.weaponname != "")
-                       setmodel(self, W_Model(strcat("v_", self.owner.weaponname, ".md3")));
+                       _setmodel(self, W_Model(strcat("v_", self.owner.weaponname, ".md3")));
                else
                        self.model = "";
 
@@ -411,7 +411,7 @@ void CL_SpawnWeaponentity(entity e)
        view.classname = "weaponentity";
        view.solid = SOLID_NOT;
        view.owner = e;
-       setmodel(view, ""); // precision set when changed
+       setmodel(view, MDL_Null); // precision set when changed
        setorigin(view, '0 0 0');
        view.angles = '0 0 0';
        view.viewmodelforclient = e;
@@ -434,7 +434,7 @@ void CL_SpawnWeaponentity(entity e)
 }
 
 // Weapon subs
-void w_clear()
+void w_clear(Weapon thiswep, bool fire1, bool fire2)
 {SELFPARAM();
        if (self.weapon != -1)
        {
@@ -448,7 +448,7 @@ void w_clear()
        }
 }
 
-void w_ready()
+void w_ready(Weapon thiswep, bool fire1, bool fire2)
 {SELFPARAM();
        if (self.weaponentity)
                self.weaponentity.state = WS_READY;
@@ -460,7 +460,7 @@ void w_ready()
 float weapon_prepareattack_checkammo(float secondary)
 {SELFPARAM();
        if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
-       if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
+       if (!_WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
        {
                // always keep the Mine Layer if we placed mines, so that we can detonate them
                entity mine;
@@ -474,11 +474,11 @@ float weapon_prepareattack_checkammo(float secondary)
 
                if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
                {
-                       sound (self, CH_WEAPON_A, W_Sound("dryfire"), VOL_BASE, ATTEN_NORM);
+                       sound (self, CH_WEAPON_A, SND_DRYFIRE, VOL_BASE, ATTEN_NORM);
                        self.prevdryfire = time;
                }
 
-               if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
+               if(_WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
                {
                        if(time - self.prevwarntime > 1)
                        {
@@ -565,7 +565,7 @@ float weapon_prepareattack(float secondary, float attacktime)
                return false;
 }
 
-void weapon_thinkf(float fr, float t, void() func)
+void weapon_thinkf(float fr, float t, void(Weapon thiswep, bool fire1, bool fire2) func)
 {SELFPARAM();
        vector a;
        vector of, or, ou;
@@ -669,7 +669,8 @@ void W_WeaponFrame()
        if(forbidWeaponUse(self))
        if(self.weaponentity.state != WS_CLEAR)
        {
-               w_ready();
+               Weapon wpn = get_weaponinfo(self.weapon);
+               w_ready(wpn, self.BUTTON_ATCK, self.BUTTON_ATCK2);
                return;
        }
 
@@ -702,7 +703,7 @@ void W_WeaponFrame()
                        self.weaponname = newwep.mdl;
                        self.bulletcounter = 0;
                        self.ammo_field = newwep.ammo_field;
-                       WEP_ACTION(self.switchweapon, WR_SETUP);
+                       _WEP_ACTION(self.switchweapon, WR_SETUP);
                        self.weaponentity.state = WS_RAISE;
 
                        // set our clip load to the load of the weapon we switched to, if it's reloadable
@@ -732,7 +733,7 @@ void W_WeaponFrame()
                        if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
                        {
                        #endif
-                               sound(self, CH_WEAPON_SINGLE, W_Sound("weapon_switch"), VOL_BASE, ATTN_NORM);
+                               sound(self, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
                                self.weaponentity.state = WS_DROP;
                                weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
                        #ifndef INDEPENDENT_ATTACK_FINISHED
@@ -767,10 +768,18 @@ void W_WeaponFrame()
                v_right = ri;
                v_up = up;
 
-               if(w)
-                       WEP_ACTION(self.weapon, WR_THINK);
-               else
-                       WEP_ACTION(self.weapon, WR_GONETHINK);
+               {
+                       bool key_pressed = self.BUTTON_HOOK;
+               Weapon wpn = self.offhand;
+               if (wpn.offhand_think) wpn.offhand_think(wpn, self, key_pressed);
+        }
+
+               if (w) {
+                       entity e = get_weaponinfo(self.weapon);
+                       if (e.wr_think) e.wr_think(e, self.BUTTON_ATCK, self.BUTTON_ATCK2);
+               } else {
+                       _WEP_ACTION(self.weapon, WR_GONETHINK);
+               }
 
                if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
                {
@@ -779,7 +788,8 @@ void W_WeaponFrame()
                                v_forward = fo;
                                v_right = ri;
                                v_up = up;
-                               self.weapon_think();
+                               Weapon wpn = get_weaponinfo(self.weapon);
+                               self.weapon_think(wpn, self.BUTTON_ATCK, self.BUTTON_ATCK2);
                        }
                        else
                                bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
@@ -819,9 +829,8 @@ void W_AttachToShotorg(entity flash, vector offset)
        }
 }
 
-void W_DecreaseAmmo(float ammo_use)
+void W_DecreaseAmmo(Weapon wep, float ammo_use)
 {SELFPARAM();
-       entity wep = get_weaponinfo(self.weapon);
 
        if(cvar("g_overkill"))
        if(self.ok_use_ammocharge)
@@ -863,7 +872,7 @@ void W_DecreaseAmmo(float ammo_use)
 .float reload_complain;
 .string reload_sound;
 
-void W_ReloadedAndReady()
+void W_ReloadedAndReady(Weapon thiswep, bool fire1, bool fire2)
 {SELFPARAM();
        // finish the reloading process, and do the ammo transfer
 
@@ -887,7 +896,8 @@ void W_ReloadedAndReady()
 
        //ATTACK_FINISHED(self) -= self.reload_time - 1;
 
-       w_ready();
+       Weapon wpn = get_weaponinfo(self.weapon);
+       w_ready(wpn, self.BUTTON_ATCK, self.BUTTON_ATCK2);
 }
 
 void W_Reload(float sent_ammo_min, string sent_sound)
@@ -927,12 +937,12 @@ void W_Reload(float sent_ammo_min, string sent_sound)
        {
                if(IS_REAL_CLIENT(self) && self.reload_complain < time)
                {
-                       play2(self, W_Sound("unavailable"));
+                       play2(self, SND(UNAVAILABLE));
                        sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
                        self.reload_complain = time + 1;
                }
                // switch away if the amount of ammo is not enough to keep using this weapon
-               if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
+               if (!(_WEP_ACTION(self.weapon, WR_CHECKAMMO1) + _WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
                {
                        self.clip_load = -1; // reload later
                        W_SwitchToOtherWeapon(self);
@@ -951,7 +961,7 @@ void W_Reload(float sent_ammo_min, string sent_sound)
 
        // now begin the reloading process
 
-       sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
+       _sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
 
        // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
        // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
@@ -971,6 +981,6 @@ void W_DropEvent(float event, entity player, float weapon_type, entity weapon_it
 {SELFPARAM();
        setself(player);
        weapon_dropevent_item = weapon_item;
-       WEP_ACTION(weapon_type, event);
+       _WEP_ACTION(weapon_type, event);
        setself(this);
 }