X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fweapons%2Fselection.qc;h=0288347ee1f1e61bdaa47cc70b93479c04f2f02f;hp=ce464c18e49252562f12f5b2b17e8dcd0716a9dc;hb=c6ebaefab2aca7df4648dac3ccdd4b52de45d0ed;hpb=9a3b01ba5da2726001a5ed74645a15ce764a3675 diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index ce464c18e..0288347ee 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -1,70 +1,93 @@ #include "selection.qh" -#include "../_all.qh" #include "weaponsystem.qh" -#include "../t_items.qh" -#include "../../common/constants.qh" -#include "../../common/util.qh" -#include "../../common/weapons/all.qh" +#include +#include +#include +#include +#include +#include +#include // switch between weapons void Send_WeaponComplain(entity e, float wpn, float type) { msg_entity = e; - WriteByte(MSG_ONE, SVC_TEMPENTITY); - WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN); + WriteHeader(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN); WriteByte(MSG_ONE, wpn); WriteByte(MSG_ONE, type); } -float client_hasweapon(entity cl, float wpn, float andammo, float complain) -{SELFPARAM(); - float f; +void Weapon_whereis(Weapon this, entity cl) +{ + if (!autocvar_g_showweaponspawns) return; + FOREACH_ENTITY_FLOAT(weapon, this.m_id, + { + if (it.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2) + continue; + if (!(it.flags & FL_ITEM)) + continue; + entity wp = WaypointSprite_Spawn( + WP_Weapon, + 1, 0, + NULL, it.origin + ('0 0 1' * it.maxs.z) * 1.2, + cl, 0, + NULL, enemy, + 0, + RADARICON_NONE + ); + wp.wp_extra = this.m_id; + }); +} - if(time < self.hasweapon_complain_spam) - complain = 0; +bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain) +{ + float f = 0; - if(wpn == WEP_HOOK.m_id && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) + if (time < this.hasweapon_complain_spam) complain = 0; - if(complain) - self.hasweapon_complain_spam = time + 0.2; + // ignore hook button when using other offhand equipment + if (this.offhand != OFFHAND_HOOK) + if (wpn == WEP_HOOK && !((this.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) + complain = 0; - if (wpn < WEP_FIRST || wpn > WEP_LAST) + if (complain) + this.hasweapon_complain_spam = time + 0.2; + + if (wpn == WEP_Null) { if (complain) - sprint(self, "Invalid weapon\n"); + sprint(this, "Invalid weapon\n"); return false; } - if (cl.weapons & WepSet_FromWeapon(wpn)) + if (this.weapons & WepSet_FromWeapon(wpn)) { if (andammo) { - if(cl.items & IT_UNLIMITED_WEAPON_AMMO) + if(this.items & IT_UNLIMITED_WEAPON_AMMO) { f = 1; } else { - setself(cl); - f = WEP_ACTION(wpn, WR_CHECKAMMO1); - f = f + WEP_ACTION(wpn, WR_CHECKAMMO2); + f = wpn.wr_checkammo1(wpn, this) + wpn.wr_checkammo2(wpn, this); // 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) - f = 1; - - setself(this); + if(wpn == WEP_MINE_LAYER) + FOREACH_ENTITY_CLASS("mine", it.owner == this, + { + f = 1; + break; // no need to continue + }); } if (!f) { if (complain) - if(IS_REAL_CLIENT(cl)) + if(IS_REAL_CLIENT(this)) { - play2(cl, SND(UNAVAILABLE)); - Send_WeaponComplain (cl, wpn, 0); + play2(this, SND(UNAVAILABLE)); + Send_WeaponComplain (this, wpn.m_id, 0); } return false; } @@ -77,43 +100,21 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) // Report Proper Weapon Status / Modified Weapon Ownership Message if (weaponsInMap & WepSet_FromWeapon(wpn)) { - Send_WeaponComplain(cl, wpn, 1); - - if(autocvar_g_showweaponspawns) - { - entity e; - - for(e = world; (e = findfloat(e, weapon, wpn)); ) - { - if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2) - continue; - if(!(e.flags & FL_ITEM)) - continue; - entity wp = WaypointSprite_Spawn( - WP_Weapon, - 1, 0, - world, e.origin + ('0 0 1' * e.maxs.z) * 1.2, - self, 0, - world, enemy, - 0, - RADARICON_NONE - ); - wp.wp_extra = wpn; - } - } + Send_WeaponComplain(this, wpn.m_id, 1); + Weapon_whereis(wpn, this); } else { - Send_WeaponComplain (cl, wpn, 2); + Send_WeaponComplain (this, wpn.m_id, 2); } - play2(cl, SND(UNAVAILABLE)); + play2(this, SND(UNAVAILABLE)); } return false; } -float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing) -{SELFPARAM(); +float W_GetCycleWeapon(entity this, 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; @@ -123,10 +124,10 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa float weaponcur; entity wep; - if(skipmissing || pl.selectweapon == 0) - weaponcur = pl.switchweapon; + if(skipmissing || this.selectweapon == 0) + weaponcur = PS(this).m_switchweapon.m_id; else - weaponcur = pl.selectweapon; + weaponcur = this.selectweapon; if(dir == 0) switchtonext = 1; @@ -137,30 +138,29 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); - wep = get_weaponinfo(weaponwant); - wepset = WepSet_FromWeapon(weaponwant); + wep = Weapons_from(weaponwant); + wepset = wep.m_wepset; if(imp >= 0) if(wep.impulse != imp) continue; - float i, have_other = false; - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { + bool have_other = false; + FOREACH(Weapons, it != WEP_Null, { if(i != weaponwant) - if((get_weaponinfo(i)).impulse == imp || imp < 0) - if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i))) + if(it.impulse == imp || imp < 0) + if((this.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)) + if(!(this.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(this, wep, true, false)) { if(switchtonext) return weaponwant; @@ -188,29 +188,28 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa // complain (but only for one weapon on the button that has been pressed) if(complain) { - self.weaponcomplainindex += 1; - c = (self.weaponcomplainindex % c) + 1; + this.weaponcomplainindex += 1; + c = (this.weaponcomplainindex % c) + 1; rest = weaponorder; while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); - wep = get_weaponinfo(weaponwant); - wepset = WepSet_FromWeapon(weaponwant); + wep = Weapons_from(weaponwant); + wepset = wep.m_wepset; if(imp >= 0) if(wep.impulse != imp) continue; - float i, have_other = false; - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { + bool have_other = false; + FOREACH(Weapons, it != WEP_Null, { if(i != weaponwant) - if((get_weaponinfo(i)).impulse == imp || imp < 0) - if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i))) + if(it.impulse == imp || imp < 0) + if((this.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)) + if(!(this.weapons & wepset)) if(!(weaponsInMap & wepset)) if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) continue; @@ -218,7 +217,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(this, wep, true, true); break; } } @@ -226,86 +225,94 @@ 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(Player this, Weapon wep) { - e.cnt = e.switchweapon; - e.switchweapon = w; - e.selectweapon = w; + TC(Player, this); TC(Weapon, wep); + this.cnt = PS(this).m_switchweapon.m_id; + PS(this).m_switchweapon = wep; + this.selectweapon = wep.m_id; } // perform weapon to attack (weaponstate and attack_finished check is here) -void W_SwitchToOtherWeapon(entity pl) +void W_SwitchToOtherWeapon(entity this) { // 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 = pl.weapon; - if(pl.weapons & WepSet_FromWeapon(w)) + Weapon ww; + WepSet set = WepSet_FromWeapon(PS(this).m_weapon); + if (this.weapons & set) { - pl.weapons &= ~WepSet_FromWeapon(w); - ww = w_getbestweapon(pl); - pl.weapons |= WepSet_FromWeapon(w); + this.weapons &= ~set; + ww = w_getbestweapon(this); + this.weapons |= set; } else - ww = w_getbestweapon(pl); - if(ww) - W_SwitchWeapon_Force(pl, ww); + { + ww = w_getbestweapon(this); + } + if (ww == WEP_Null) return; + W_SwitchWeapon_Force(this, ww); } -void W_SwitchWeapon(float imp) -{SELFPARAM(); - if (self.switchweapon != imp) +void W_SwitchWeapon(entity this, Weapon w) +{ + if (PS(this).m_switchweapon != w) { - if (client_hasweapon(self, imp, true, true)) - W_SwitchWeapon_Force(self, imp); + if (client_hasweapon(this, w, true, true)) + W_SwitchWeapon_Force(this, w); else - self.selectweapon = imp; // update selectweapon ANYWAY + this.selectweapon = w.m_id; // update selectweapon ANYWAY + } + else if(!forbidWeaponUse(this)) { + entity actor = this; + .entity weaponentity = weaponentities[0]; // TODO: unhardcode + w.wr_reload(w, actor, weaponentity); } - else if(!forbidWeaponUse(self)) { WEP_ACTION(self.weapon, WR_RELOAD); } } -void W_CycleWeapon(string weaponorder, float dir) -{SELFPARAM(); +void W_CycleWeapon(entity this, string weaponorder, float dir) +{ float w; - w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true); + w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true); if(w > 0) - W_SwitchWeapon(w); + W_SwitchWeapon(this, Weapons_from(w)); } -void W_NextWeaponOnImpulse(float imp) -{SELFPARAM(); +void W_NextWeaponOnImpulse(entity this, float imp) +{ float w; - w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0)); + w = W_GetCycleWeapon(this, this.cvar_cl_weaponpriority, +1, imp, 1, (this.cvar_cl_weaponimpulsemode == 0)); if(w > 0) - W_SwitchWeapon(w); + W_SwitchWeapon(this, Weapons_from(w)); } // next weapon -void W_NextWeapon(float list) -{SELFPARAM(); +void W_NextWeapon(entity this, int list) +{ if(list == 0) - W_CycleWeapon(weaponorder_byid, -1); + W_CycleWeapon(this, weaponorder_byid, -1); else if(list == 1) - W_CycleWeapon(self.weaponorder_byimpulse, -1); + W_CycleWeapon(this, this.weaponorder_byimpulse, -1); else if(list == 2) - W_CycleWeapon(self.cvar_cl_weaponpriority, -1); + W_CycleWeapon(this, this.cvar_cl_weaponpriority, -1); } // prev weapon -void W_PreviousWeapon(float list) -{SELFPARAM(); +void W_PreviousWeapon(entity this, float list) +{ if(list == 0) - W_CycleWeapon(weaponorder_byid, +1); + W_CycleWeapon(this, weaponorder_byid, +1); else if(list == 1) - W_CycleWeapon(self.weaponorder_byimpulse, +1); + W_CycleWeapon(this, this.weaponorder_byimpulse, +1); else if(list == 2) - W_CycleWeapon(self.cvar_cl_weaponpriority, +1); + W_CycleWeapon(this, this.cvar_cl_weaponpriority, +1); } // previously used if exists and has ammo, (second) best otherwise -void W_LastWeapon(void) -{SELFPARAM(); - if(client_hasweapon(self, self.cnt, true, false)) - W_SwitchWeapon(self.cnt); +void W_LastWeapon(entity this) +{ + Weapon wep = Weapons_from(this.cnt); + if (client_hasweapon(this, wep, true, false)) + W_SwitchWeapon(this, wep); else - W_SwitchToOtherWeapon(self); + W_SwitchToOtherWeapon(this); }