]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_weaponsystem.qc
simplify some hacks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_weaponsystem.qc
index db6ef79913938c8d625b42614ca9a28389a5fed2..1208766e21a99fca98117786b7391e0cb312d6f4 100644 (file)
@@ -148,7 +148,7 @@ void W_PlayStrengthSound(entity player) // void W_PlayStrengthSound
 void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector mi, vector ma, float antilag, float recoil, string snd, float chan, float maxdamage, float range)
 {
        float nudge = 1; // added to traceline target and subtracted from result
-       local float oldsolid;
+       float oldsolid;
        vector vecs, dv;
        oldsolid = ent.dphitcontentsmask;
        if(ent.weapon == WEP_RIFLE)
@@ -185,8 +185,6 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m
                vecs = ent.weaponentity.movedir;
        else
                vecs = '0 0 0';
-       if(debug_shotorg != '0 0 0')
-               vecs = debug_shotorg;
 
        dv = v_right * -vecs_y + v_up * vecs_z;
        w_shotorg = ent.origin + ent.view_ofs + dv;
@@ -261,7 +259,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m
 
        // nudge w_shotend so a trace to w_shotend hits
        w_shotend = w_shotend + normalize(w_shotend - w_shotorg) * nudge;
-};
+}
 
 #define W_SetupShot_Dir_ProjectileSize(ent,s_forward,mi,ma,antilag,recoil,snd,chan,maxdamage) W_SetupShot_Dir_ProjectileSize_Range(ent, s_forward, mi, ma, antilag, recoil, snd, chan, maxdamage, MAX_SHOT_DISTANCE)
 #define W_SetupShot_ProjectileSize(ent,mi,ma,antilag,recoil,snd,chan,maxdamage) W_SetupShot_Dir_ProjectileSize(ent, v_forward, mi, ma, antilag, recoil, snd, chan, maxdamage)
@@ -558,7 +556,7 @@ void CL_Weaponentity_Think()
        }
 
        self.angles = '0 0 0';
-       local float f;
+       float f;
        f = 0;
        if (self.state == WS_RAISE && !intermission_running)
        {
@@ -575,7 +573,7 @@ void CL_Weaponentity_Think()
                f = 1;
                self.angles_x = -90 * f * f;
        }
-};
+}
 
 void CL_ExteriorWeaponentity_Think()
 {
@@ -609,10 +607,6 @@ void CL_ExteriorWeaponentity_Think()
                }
                else
                        setattachment(self, self.owner, "bip01 r hand");
-
-               // if that didn't find a tag, hide the exterior weapon model
-               if (!self.tag_index)
-                       self.model = "";
        }
        self.effects = self.owner.effects;
        if(sv_pitch_min == sv_pitch_max)
@@ -681,7 +675,9 @@ void CL_ExteriorWeaponentity_Think()
 
        self.glowmod = self.owner.weaponentity_glowmod;
        self.colormap = self.owner.colormap;
-};
+
+       CSQCMODEL_AUTOUPDATE();
+}
 
 // spawning weaponentity for client
 void CL_SpawnWeaponentity()
@@ -708,7 +704,14 @@ void CL_SpawnWeaponentity()
        self.exteriorweaponentity.angles = '0 0 0';
        self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
        self.exteriorweaponentity.nextthink = time;
-};
+
+       {
+               entity oldself = self;
+               self = self.exteriorweaponentity;
+               CSQCMODEL_AUTOINIT();
+               self = oldself;
+       }
+}
 
 void Send_WeaponComplain (entity e, float wpn, string wpnname, float type)
 {
@@ -724,8 +727,8 @@ void Send_WeaponComplain (entity e, float wpn, string wpnname, float type)
 
 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
 {
-       local float weaponbit, f;
-       local entity oldself;
+       float weaponbit, f;
+       entity oldself;
 
        if(time < self.hasweapon_complain_spam)
                complain = 0;
@@ -755,7 +758,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                f = f + weapon_action(wpn, WR_CHECKAMMO2);
 
                                // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
-                               local entity mine;
+                               entity mine;
                                if(wpn == WEP_MINE_LAYER)
                                for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
                                        f = 1;
@@ -820,7 +823,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                play2(cl, "weapons/unavailable.wav");
        }
        return FALSE;
-};
+}
 
 // Weapon subs
 void w_clear()
@@ -835,14 +838,14 @@ void w_clear()
                self.weaponentity.state = WS_CLEAR;
                self.weaponentity.effects = 0;
        }
-};
+}
 
 void w_ready()
 {
        if (self.weaponentity)
                self.weaponentity.state = WS_READY;
        weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
-};
+}
 
 // Setup weapon for client (after this raise frame will be launched)
 void weapon_setup(float windex)
@@ -850,14 +853,14 @@ void weapon_setup(float windex)
        entity e;
        e = get_weaponinfo(windex);
        self.items &~= IT_AMMO;
-       self.items = self.items | e.items;
+       self.items = self.items | (e.items & IT_AMMO);
 
        // the two weapon entities will notice this has changed and update their models
        self.weapon = windex;
        self.switchingweapon = windex; // to make sure
        self.weaponname = e.mdl;
        self.bulletcounter = 0;
-};
+}
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
 void W_SwitchToOtherWeapon(entity pl)
@@ -871,14 +874,24 @@ void W_SwitchToOtherWeapon(entity pl)
        if(ww)
                W_SwitchWeapon_Force(pl, ww);
 }
+
+string PrimaryOrSecondary(float secondary)
+{
+       if(secondary)
+               return "secondary";
+       else
+               return "primary";
+}
+
 .float prevdryfire;
+.float prevwarntime;
 float weapon_prepareattack_checkammo(float secondary)
 {
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
        if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
        {
                // always keep the Mine Layer if we placed mines, so that we can detonate them
-               local entity mine;
+               entity mine;
                if(self.weapon == WEP_MINE_LAYER)
                for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
                        return FALSE;
@@ -889,7 +902,19 @@ float weapon_prepareattack_checkammo(float secondary)
                        self.prevdryfire = time;
                }
 
-               W_SwitchToOtherWeapon(self);
+               if(weapon_action(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
+               {
+                       if(time - self.prevwarntime > 1)
+                       {
+                               sprint(self, strcat("^2", W_Name(self.weapon), " ", PrimaryOrSecondary(secondary), "^7 is unable to fire, but its ^2", PrimaryOrSecondary(1 - secondary), "^7 can.\n"));
+                       }
+                       self.prevwarntime = time;
+               }
+               else // this weapon is totally unable to fire, switch to another one
+               {
+                       W_SwitchToOtherWeapon(self);
+               }
+               
                return FALSE;
        }
        return TRUE;
@@ -906,7 +931,7 @@ float weapon_prepareattack_check(float secondary, float attacktime)
                return FALSE;
        }
 
-       if (timeoutStatus == 2) //don't allow the player to shoot while game is paused
+       if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
                return FALSE;
 
        // do not even think about shooting if switching
@@ -1037,12 +1062,12 @@ void weapon_thinkf(float fr, float t, void() func)
                        setanim(self, anim, FALSE, TRUE, TRUE);
                }
        }
-};
+}
 
 void weapon_boblayer1(float spd, vector org)
 {
        // VorteX: haste can be added here
-};
+}
 
 vector W_CalculateProjectileVelocity(vector pvelocity, vector mvelocity, float forceAbsolute)
 {