]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_weaponsystem.qc
Merge branch 'master' into fruitiex/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_weaponsystem.qc
index e7bfc69d0546115d875b0f2502579c20bcafe472..3f8581a432df5685604aaf365af5cf449c9b25e0 100644 (file)
@@ -36,6 +36,7 @@ void W_SwitchWeapon_Force(entity e, float w)
 {
        e.cnt = e.switchweapon;
        e.switchweapon = w;
+       e.selectweapon = w;
 }
 
 .float antilag_debug;
@@ -439,8 +440,8 @@ void CL_Weaponentity_Think()
                        }
                        else
                        {
-                               setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".dpm")); // precision set below
-                               animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".dpm.animinfo");
+                               setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".iqm")); // precision set below
+                               animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".iqm.animinfo");
                                animfile = fopen(animfilename, FILE_READ);
                                // preset some defaults that work great for renamed zym files (which don't need an animinfo)
                                self.anim_fire1  = '0 1 0.01';
@@ -906,6 +907,16 @@ void CL_SpawnWeaponentity()
        self.exteriorweaponentity.nextthink = time;
 };
 
+void Send_WeaponComplain (entity e, float wpn, string wpnname, float type)
+{
+       msg_entity = e;
+       WriteByte(MSG_ONE, SVC_TEMPENTITY);
+       WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
+       WriteByte(MSG_ONE, wpn);
+       WriteString(MSG_ONE, wpnname);
+       WriteByte(MSG_ONE, type);
+}
+
 .float hasweapon_complain_spam;
 
 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
@@ -948,6 +959,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                {
                                        play2(cl, "weapons/unavailable.wav");
                                        sprint(cl, strcat("You don't have any ammo for the ^2", W_Name(wpn), "\n"));
+                                       Send_WeaponComplain (cl, wpn, W_Name(wpn), 0);
                                }
                                return FALSE;
                        }
@@ -961,6 +973,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                if(weaponsInMap & weaponbit)
                {
                        sprint(cl, strcat("You do not have the ^2", W_Name(wpn), "\n") );
+                       Send_WeaponComplain (cl, wpn, W_Name(wpn), 1);
 
                        if(cvar("g_showweaponspawns"))
                        {
@@ -988,7 +1001,10 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                        }
                }
                else
+               {
+                       Send_WeaponComplain (cl, wpn, W_Name(wpn), 2);
                        sprint(cl, strcat("The ^2", W_Name(wpn), "^7 is ^1NOT AVAILABLE^7 in this map\n") );
+               }
 
                play2(cl, "weapons/unavailable.wav");
        }
@@ -1030,29 +1046,39 @@ void weapon_setup(float windex)
 };
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
+void W_SwitchToOtherWeapon(entity pl)
+{
+       // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
+       float w, ww;
+       w = W_WeaponBit(pl.weapon);
+       pl.weapons &~= w;
+       ww = w_getbestweapon(pl);
+       pl.weapons |= w;
+       if(ww)
+               W_SwitchWeapon_Force(pl, ww);
+}
+float weapon_prepareattack_checkammo(float secondary)
+{
+       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+       if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
+       {
+               W_SwitchToOtherWeapon(self);
+               return FALSE;
+       }
+       return TRUE;
+}
 .float race_penalty;
-float weapon_prepareattack(float secondary, float attacktime)
+float weapon_prepareattack_check(float secondary, float attacktime)
 {
+       if(!weapon_prepareattack_checkammo(secondary))
+               return FALSE;
+
        //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
        //if all players readied up and the countdown is running
        if(time < game_starttime || time < self.race_penalty) {
                return FALSE;
        }
 
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-       if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
-       {
-               // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
-               float w, ww;
-               w = W_WeaponBit(self.weapon);
-               self.weapons &~= w;
-               ww = w_getbestweapon(self);
-               self.weapons |= w;
-               if(ww)
-                       W_SwitchWeapon_Force(self, ww);
-               return FALSE;
-       }
-
        if (timeoutStatus == 2) //don't allow the player to shoot while game is paused
                return FALSE;
 
@@ -1069,6 +1095,11 @@ float weapon_prepareattack(float secondary, float attacktime)
                if (self.weaponentity.state != WS_READY)
                        return FALSE;
        }
+
+       return TRUE;
+}
+float weapon_prepareattack_do(float secondary, float attacktime)
+{
        self.weaponentity.state = WS_INUSE;
 
        self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
@@ -1086,7 +1117,17 @@ float weapon_prepareattack(float secondary, float attacktime)
        self.bulletcounter += 1;
        //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
        return TRUE;
-};
+}
+float weapon_prepareattack(float secondary, float attacktime)
+{
+       if(weapon_prepareattack_check(secondary, attacktime))
+       {
+               weapon_prepareattack_do(secondary, attacktime);
+               return TRUE;
+       }
+       else
+               return FALSE;
+}
 
 void weapon_thinkf(float fr, float t, void() func)
 {