X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fweapons%2Fselection.qc;h=737ddc8adcbf8e2c25ad3e14a1644f9bde97d450;hb=eb6fabc8b16e23fcf0704ecf97685dffa7387bb7;hp=b301da6f2e46ff7eb44cf0929fbce458b0537deb;hpb=bd2645ddf4d7e7ca133ae7a87c3b85521e5a7e7b;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index b301da6f2..737ddc8ad 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -17,28 +17,28 @@ void Send_WeaponComplain(entity e, float wpn, float type) WriteByte(MSG_ONE, type); } -float client_hasweapon(entity cl, float wpn, float andammo, float complain) -{SELFPARAM(); +bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain) +{ float f; - if(time < self.hasweapon_complain_spam) + if (time < cl.hasweapon_complain_spam) complain = 0; // ignore hook button when using other offhand equipment if (cl.offhand != OFFHAND_HOOK) - if (wpn == WEP_HOOK.m_id && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(Weapons_from(wpn)))) + if (wpn == WEP_HOOK && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) complain = 0; - if(complain) - self.hasweapon_complain_spam = time + 0.2; + if (complain) + cl.hasweapon_complain_spam = time + 0.2; - if (wpn < WEP_FIRST || wpn > WEP_LAST) + if (wpn == WEP_Null) { if (complain) - sprint(self, "Invalid weapon\n"); + sprint(cl, "Invalid weapon\n"); return false; } - if (cl.weapons & WepSet_FromWeapon(Weapons_from(wpn))) + if (cl.weapons & WepSet_FromWeapon(wpn)) { if (andammo) { @@ -48,17 +48,14 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) } else { - setself(cl); - Weapon w = Weapons_from(wpn); - f = w.wr_checkammo1(w) + w.wr_checkammo2(w); + WITH(entity, self, cl, f = wpn.wr_checkammo1(wpn) + wpn.wr_checkammo2(wpn)); // always allow selecting the Mine Layer if we placed mines, so that we can detonate them entity mine; - if(wpn == WEP_MINE_LAYER.m_id) - for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self) + if(wpn == WEP_MINE_LAYER) + for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == cl) f = 1; - setself(this); } if (!f) { @@ -66,7 +63,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) if(IS_REAL_CLIENT(cl)) { play2(cl, SND(UNAVAILABLE)); - Send_WeaponComplain (cl, wpn, 0); + Send_WeaponComplain (cl, wpn.m_id, 0); } return false; } @@ -77,15 +74,15 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) { // DRESK - 3/16/07 // Report Proper Weapon Status / Modified Weapon Ownership Message - if (weaponsInMap & WepSet_FromWeapon(Weapons_from(wpn))) + if (weaponsInMap & WepSet_FromWeapon(wpn)) { - Send_WeaponComplain(cl, wpn, 1); + Send_WeaponComplain(cl, wpn.m_id, 1); if(autocvar_g_showweaponspawns) { entity e; - for(e = world; (e = findfloat(e, weapon, wpn)); ) + for(e = world; (e = findfloat(e, weapon, wpn.m_id)); ) { if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2) continue; @@ -95,18 +92,18 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) WP_Weapon, 1, 0, world, e.origin + ('0 0 1' * e.maxs.z) * 1.2, - self, 0, + cl, 0, world, enemy, 0, RADARICON_NONE ); - wp.wp_extra = wpn; + wp.wp_extra = wpn.m_id; } } } else { - Send_WeaponComplain (cl, wpn, 2); + Send_WeaponComplain (cl, wpn.m_id, 2); } play2(cl, SND(UNAVAILABLE)); @@ -145,15 +142,13 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa if(wep.impulse != imp) continue; - float i, have_other = false; - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { - Weapon e = Weapons_from(i); + bool have_other = false; + FOREACH(Weapons, it != WEP_Null, { if(i != weaponwant) - if(e.impulse == imp || imp < 0) - if((pl.weapons & (e.m_wepset)) || (weaponsInMap & (e.m_wepset))) + if(it.impulse == imp || imp < 0) + if((pl.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) have_other = true; - } + }); // skip weapons we don't own that aren't normal and aren't in the map if(!(pl.weapons & wepset)) @@ -163,7 +158,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa ++c; - if(!skipmissing || client_hasweapon(pl, weaponwant, true, false)) + if(!skipmissing || client_hasweapon(pl, wep, true, false)) { if(switchtonext) return weaponwant; @@ -203,15 +198,13 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa if(wep.impulse != imp) continue; - float i, have_other = false; - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { - Weapon w = Weapons_from(i); + bool have_other = false; + FOREACH(Weapons, it != WEP_Null, { if(i != weaponwant) - if(w.impulse == imp || imp < 0) - if((pl.weapons & (w.m_wepset)) || (weaponsInMap & (w.m_wepset))) + if(it.impulse == imp || imp < 0) + if((pl.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) have_other = true; - } + }); // skip weapons we don't own that aren't normal and aren't in the map if(!(pl.weapons & wepset)) @@ -222,7 +215,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa --c; if(c == 0) { - client_hasweapon(pl, weaponwant, true, true); + client_hasweapon(pl, wep, true, true); break; } } @@ -230,8 +223,9 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa return 0; } -void W_SwitchWeapon_Force(entity e, float w) +void W_SwitchWeapon_Force(entity e, Weapon wep) { + int w = wep.m_id; e.cnt = e.switchweapon; e.switchweapon = w; e.selectweapon = w; @@ -252,20 +246,20 @@ void W_SwitchToOtherWeapon(entity pl) else ww = w_getbestweapon(pl); if(ww) - W_SwitchWeapon_Force(pl, ww); + W_SwitchWeapon_Force(pl, Weapons_from(ww)); } -void W_SwitchWeapon(float imp) +void W_SwitchWeapon(Weapon w) {SELFPARAM(); + int imp = w.m_id; if (self.switchweapon != imp) { - if (client_hasweapon(self, imp, true, true)) - W_SwitchWeapon_Force(self, imp); + if (client_hasweapon(self, w, true, true)) + W_SwitchWeapon_Force(self, w); else self.selectweapon = imp; // update selectweapon ANYWAY } else if(!forbidWeaponUse(self)) { - Weapon w = Weapons_from(self.weapon); w.wr_reload(w); } } @@ -275,7 +269,7 @@ void W_CycleWeapon(string weaponorder, float dir) float w; w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true); if(w > 0) - W_SwitchWeapon(w); + W_SwitchWeapon(Weapons_from(w)); } void W_NextWeaponOnImpulse(float imp) @@ -283,7 +277,7 @@ void W_NextWeaponOnImpulse(float imp) float w; w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0)); if(w > 0) - W_SwitchWeapon(w); + W_SwitchWeapon(Weapons_from(w)); } // next weapon @@ -311,8 +305,9 @@ void W_PreviousWeapon(float list) // previously used if exists and has ammo, (second) best otherwise void W_LastWeapon() {SELFPARAM(); - if(client_hasweapon(self, self.cnt, true, false)) - W_SwitchWeapon(self.cnt); + Weapon wep = Weapons_from(self.cnt); + if(client_hasweapon(self, wep, true, false)) + W_SwitchWeapon(wep); else W_SwitchToOtherWeapon(self); }