X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fserver%2Fweapons%2Fselection.qc;h=868d6b041b0dc9207fa5fbe6920ad6286d04699e;hb=1217fce596f1b9769ffb6f479e3abbd4f77af5ef;hp=482b3180a0078222670860bf9fcb2eec018b509a;hpb=a5b077eb799e456094034cdc0dd0d5b5a7e1119e;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index 482b3180a..868d6b041 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -1,3 +1,13 @@ +#include "selection.qh" +#include "../_all.qh" + +#include "weaponsystem.qh" +#include "../t_items.qh" +#include "../waypointsprites.qh" +#include "../../common/constants.qh" +#include "../../common/util.qh" +#include "../../common/weapons/all.qh" + // switch between weapons void Send_WeaponComplain(entity e, float wpn, float type) { @@ -16,9 +26,9 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) if(time < self.hasweapon_complain_spam) complain = 0; - if(wpn == WEP_HOOK && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) + if(wpn == WEP_HOOK.m_id && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) complain = 0; - + if(complain) self.hasweapon_complain_spam = time + 0.2; @@ -26,7 +36,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) { if (complain) sprint(self, "Invalid weapon\n"); - return FALSE; + return false; } if (cl.weapons & WepSet_FromWeapon(wpn)) { @@ -45,7 +55,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) // always allow selecting the Mine Layer if we placed mines, so that we can detonate them entity mine; - if(wpn == WEP_MINE_LAYER) + if(wpn == WEP_MINE_LAYER.m_id) for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self) f = 1; @@ -59,10 +69,10 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) play2(cl, "weapons/unavailable.wav"); Send_WeaponComplain (cl, wpn, 0); } - return FALSE; + return false; } } - return TRUE; + return true; } if (complain) { @@ -78,14 +88,14 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) for(e = world; (e = findfloat(e, weapon, wpn)); ) { - if(e.classname == "droppedweapon") + if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2) continue; if(!(e.flags & FL_ITEM)) continue; WaypointSprite_Spawn( (get_weaponinfo(wpn)).wpmodel, 1, 0, - world, e.origin, + world, e.origin + ('0 0 1' * e.maxs.z) * 1.2, self, 0, world, enemy, 0, @@ -101,15 +111,15 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) play2(cl, "weapons/unavailable.wav"); } - return FALSE; + return false; } float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing) { // We cannot tokenize in this function, as GiveItems calls this // function. Thus we must use car/cdr. - float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c; - string rest; + float weaponwant, first_valid, prev_valid, switchtonext, switchtolast; + WepSet wepset = '0 0 0'; switchtonext = switchtolast = 0; first_valid = prev_valid = 0; float weaponcur; @@ -123,26 +133,36 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa if(dir == 0) switchtonext = 1; - c = 0; + int c = 0; - rest = weaponorder; + string rest = weaponorder; while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); wep = get_weaponinfo(weaponwant); + wepset = WepSet_FromWeapon(weaponwant); if(imp >= 0) - if(wep.impulse != imp) - continue; + if(wep.impulse != imp) + continue; + + float i, have_other = false; + for(i = WEP_FIRST; i <= WEP_LAST; ++i) + { + if(i != weaponwant) + if((get_weaponinfo(i)).impulse == imp || imp < 0) + if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i))) + have_other = true; + } // skip weapons we don't own that aren't normal and aren't in the map - if(!(pl.weapons & WepSet_FromWeapon(weaponwant))) - if(!((get_weaponinfo(weaponwant)).spawnflags & WEP_FLAG_NORMAL)) - if(!(weaponsInMap & WepSet_FromWeapon(weaponwant))) - continue; + if(!(pl.weapons & wepset)) + if(!(weaponsInMap & wepset)) + if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) + continue; ++c; - if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE)) + if(!skipmissing || client_hasweapon(pl, weaponwant, true, false)) { if(switchtonext) return weaponwant; @@ -171,26 +191,36 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa if(complain) { self.weaponcomplainindex += 1; - c = mod(self.weaponcomplainindex, c) + 1; + c = (self.weaponcomplainindex % c) + 1; rest = weaponorder; while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); wep = get_weaponinfo(weaponwant); + wepset = WepSet_FromWeapon(weaponwant); if(imp >= 0) if(wep.impulse != imp) continue; + float i, have_other = false; + for(i = WEP_FIRST; i <= WEP_LAST; ++i) + { + if(i != weaponwant) + if((get_weaponinfo(i)).impulse == imp || imp < 0) + if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i))) + have_other = true; + } + // skip weapons we don't own that aren't normal and aren't in the map - if(!(pl.weapons & WepSet_FromWeapon(weaponwant))) - if(!((get_weaponinfo(weaponwant)).spawnflags & WEP_FLAG_NORMAL)) - if(!(weaponsInMap & WepSet_FromWeapon(weaponwant))) - continue; + if(!(pl.weapons & wepset)) + if(!(weaponsInMap & wepset)) + if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) + continue; --c; if(c == 0) { - client_hasweapon(pl, weaponwant, TRUE, TRUE); + client_hasweapon(pl, weaponwant, true, true); break; } } @@ -227,18 +257,18 @@ void W_SwitchWeapon(float imp) { if (self.switchweapon != imp) { - if (client_hasweapon(self, imp, TRUE, TRUE)) + if (client_hasweapon(self, imp, true, true)) W_SwitchWeapon_Force(self, imp); else self.selectweapon = imp; // update selectweapon ANYWAY } - else { WEP_ACTION(self.weapon, WR_RELOAD); } + else if(!forbidWeaponUse(self)) { WEP_ACTION(self.weapon, WR_RELOAD); } } void W_CycleWeapon(string weaponorder, float dir) { float w; - w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE); + w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true); if(w > 0) W_SwitchWeapon(w); } @@ -276,7 +306,7 @@ void W_PreviousWeapon(float list) // previously used if exists and has ammo, (second) best otherwise void W_LastWeapon(void) { - if(client_hasweapon(self, self.cnt, TRUE, FALSE)) + if(client_hasweapon(self, self.cnt, true, false)) W_SwitchWeapon(self.cnt); else W_SwitchToOtherWeapon(self);