X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fweapons%2Fselection.qc;h=5912261dbf68cf6bca6a47ce8e86db480c2cd2b9;hb=5009dab34356180df0978102855cb2a02d06db84;hp=5df7accc0b93afc2c3066fd56b0c963fc6435063;hpb=26693a3ac060825ce6c7f170d4e65f7ac2a1fb25;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index 5df7accc0..5912261db 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -2,6 +2,7 @@ #include "weaponsystem.qh" #include +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include // switch between weapons void Send_WeaponComplain(entity e, float wpn, float type) @@ -22,10 +24,12 @@ void Send_WeaponComplain(entity e, float wpn, float type) void Weapon_whereis(Weapon this, entity cl) { if (!autocvar_g_showweaponspawns) return; - IL_EACH(g_items, it.weapon == this.m_id && (it.ItemStatus & ITS_AVAILABLE), + IL_EACH(g_items, it.weapon == this.m_id && (!it.team || (it.ItemStatus & ITS_AVAILABLE)), { - if (it.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2) + if (Item_IsLoot(it) && (autocvar_g_showweaponspawns < 2)) + { continue; + } entity wp = WaypointSprite_Spawn( WP_Weapon, -2, 0, @@ -39,20 +43,20 @@ void Weapon_whereis(Weapon this, entity cl) }); } -bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain) +bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andammo, bool complain) { float f = 0; - if (time < this.hasweapon_complain_spam) + if (time < CS(this).hasweapon_complain_spam) complain = 0; // ignore hook button when using other offhand equipment if (this.offhand != OFFHAND_HOOK) - if (wpn == WEP_HOOK && !((this.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) + if (wpn == WEP_HOOK && !((STAT(WEAPONS, this) | weaponsInMap) & WepSet_FromWeapon(wpn))) complain = 0; if (complain) - this.hasweapon_complain_spam = time + 0.2; + CS(this).hasweapon_complain_spam = time + 0.2; if (wpn == WEP_Null) { @@ -60,7 +64,9 @@ bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain) sprint(this, "Invalid weapon\n"); return false; } - if (this.weapons & WepSet_FromWeapon(wpn)) + if (autocvar_g_weaponswitch_debug == 2 && weaponslot(weaponentity) > 0 && !(wpn.spawnflags & WEP_FLAG_DUALWIELD) && !(PS(this).dual_weapons & wpn.m_wepset)) + return false; // no complaints needed + if (STAT(WEAPONS, this) & WepSet_FromWeapon(wpn)) { if (andammo) { @@ -70,11 +76,11 @@ bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain) } else { - f = wpn.wr_checkammo1(wpn, this) + wpn.wr_checkammo2(wpn, this); + f = wpn.wr_checkammo1(wpn, this, weaponentity) + wpn.wr_checkammo2(wpn, this, weaponentity); // always allow selecting the Mine Layer if we placed mines, so that we can detonate them if(wpn == WEP_MINE_LAYER) - IL_EACH(g_mines, it.owner == this, + IL_EACH(g_mines, it.owner == this && it.weaponentity_fld == weaponentity, { f = 1; break; // no need to continue @@ -120,7 +126,7 @@ bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain) return false; } -float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing) +float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing, .entity weaponentity) { // We cannot tokenize in this function, as GiveItems calls this // function. Thus we must use car/cdr. @@ -131,10 +137,10 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl float weaponcur; entity wep; - if(skipmissing || this.selectweapon == 0) - weaponcur = PS(this).m_switchweapon.m_id; + if(skipmissing || this.(weaponentity).selectweapon == 0) + weaponcur = this.(weaponentity).m_switchweapon.m_id; else - weaponcur = this.selectweapon; + weaponcur = this.(weaponentity).selectweapon; if(dir == 0) switchtonext = 1; @@ -155,19 +161,19 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl FOREACH(Weapons, it != WEP_Null, { if(i != weaponwant) if(it.impulse == imp || imp < 0) - if((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) + if((STAT(WEAPONS, this) & (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(!(this.weapons & wepset)) + if(!(STAT(WEAPONS, this) & wepset)) if(!(weaponsInMap & wepset)) if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) continue; ++c; - if(!skipmissing || client_hasweapon(this, wep, true, false)) + if(!skipmissing || client_hasweapon(this, wep, weaponentity, true, false)) { if(switchtonext) return weaponwant; @@ -211,12 +217,12 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl FOREACH(Weapons, it != WEP_Null, { if(i != weaponwant) if(it.impulse == imp || imp < 0) - if((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) + if((STAT(WEAPONS, this) & (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(!(this.weapons & wepset)) + if(!(STAT(WEAPONS, this) & wepset)) if(!(weaponsInMap & wepset)) if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) continue; @@ -224,7 +230,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl --c; if(c == 0) { - client_hasweapon(this, wep, true, true); + client_hasweapon(this, wep, weaponentity, true, true); break; } } @@ -232,97 +238,108 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl return 0; } -void W_SwitchWeapon_Force(Player this, Weapon wep) +void W_SwitchWeapon_Force(Player this, Weapon wep, .entity weaponentity) { - TC(Player, this); TC(Weapon, wep); - this.cnt = PS(this).m_switchweapon.m_id; - PS(this).m_switchweapon = wep; - this.selectweapon = wep.m_id; + TC(Weapon, wep); + this.(weaponentity).cnt = this.(weaponentity).m_switchweapon.m_id; + this.(weaponentity).m_switchweapon = wep; + this.(weaponentity).selectweapon = wep.m_id; } // perform weapon to attack (weaponstate and attack_finished check is here) -void W_SwitchToOtherWeapon(entity this) +void W_SwitchToOtherWeapon(entity this, .entity weaponentity) { // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway) Weapon ww; - WepSet set = WepSet_FromWeapon(PS(this).m_weapon); - if (this.weapons & set) + WepSet set = WepSet_FromWeapon(this.(weaponentity).m_weapon); + if (STAT(WEAPONS, this) & set) { - this.weapons &= ~set; - ww = w_getbestweapon(this); - this.weapons |= set; + STAT(WEAPONS, this) &= ~set; + ww = w_getbestweapon(this, weaponentity); + STAT(WEAPONS, this) |= set; } else { - ww = w_getbestweapon(this); + ww = w_getbestweapon(this, weaponentity); } if (ww == WEP_Null) return; - W_SwitchWeapon_Force(this, ww); + W_SwitchWeapon_Force(this, ww, weaponentity); } -void W_SwitchWeapon(entity this, Weapon w) +bool W_SwitchWeapon(entity this, Weapon w, .entity weaponentity) { - if (PS(this).m_switchweapon != w) + if(this.(weaponentity).m_switchweapon != w) { - if (client_hasweapon(this, w, true, true)) - W_SwitchWeapon_Force(this, w); + if(client_hasweapon(this, w, weaponentity, true, true)) + { + W_SwitchWeapon_Force(this, w, weaponentity); + return true; + } else - this.selectweapon = w.m_id; // update selectweapon ANYWAY - } - else if(!forbidWeaponUse(this)) { - entity actor = this; - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { - .entity weaponentity = weaponentities[slot]; - w.wr_reload(w, actor, weaponentity); + this.(weaponentity).selectweapon = w.m_id; // update selectweapon anyway + return false; } } + else if(!forbidWeaponUse(this)) + { + entity actor = this; + w.wr_reload(w, actor, weaponentity); + } + + return true; // player already has the weapon out or needs to reload +} + +void W_SwitchWeapon_TryOthers(entity this, Weapon w, .entity weaponentity) +{ + if(!W_SwitchWeapon(this, w, weaponentity)) + W_NextWeaponOnImpulse(this, w.impulse, weaponentity); } -void W_CycleWeapon(entity this, string weaponorder, float dir) +void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity) { float w; - w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true); + w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true, weaponentity); if(w > 0) - W_SwitchWeapon(this, Weapons_from(w)); + W_SwitchWeapon(this, Weapons_from(w), weaponentity); } -void W_NextWeaponOnImpulse(entity this, float imp) +void W_NextWeaponOnImpulse(entity this, float imp, .entity weaponentity) { float w; - w = W_GetCycleWeapon(this, this.cvar_cl_weaponpriority, +1, imp, 1, (this.cvar_cl_weaponimpulsemode == 0)); + w = W_GetCycleWeapon(this, CS(this).cvar_cl_weaponpriority, +1, imp, 1, (CS(this).cvar_cl_weaponimpulsemode == 0), weaponentity); if(w > 0) - W_SwitchWeapon(this, Weapons_from(w)); + W_SwitchWeapon(this, Weapons_from(w), weaponentity); } // next weapon -void W_NextWeapon(entity this, int list) +void W_NextWeapon(entity this, int list, .entity weaponentity) { if(list == 0) - W_CycleWeapon(this, weaponorder_byid, -1); + W_CycleWeapon(this, weaponorder_byid, -1, weaponentity); else if(list == 1) - W_CycleWeapon(this, this.weaponorder_byimpulse, -1); + W_CycleWeapon(this, CS(this).weaponorder_byimpulse, -1, weaponentity); else if(list == 2) - W_CycleWeapon(this, this.cvar_cl_weaponpriority, -1); + W_CycleWeapon(this, CS(this).cvar_cl_weaponpriority, -1, weaponentity); } // prev weapon -void W_PreviousWeapon(entity this, float list) +void W_PreviousWeapon(entity this, float list, .entity weaponentity) { if(list == 0) - W_CycleWeapon(this, weaponorder_byid, +1); + W_CycleWeapon(this, weaponorder_byid, +1, weaponentity); else if(list == 1) - W_CycleWeapon(this, this.weaponorder_byimpulse, +1); + W_CycleWeapon(this, CS(this).weaponorder_byimpulse, +1, weaponentity); else if(list == 2) - W_CycleWeapon(this, this.cvar_cl_weaponpriority, +1); + W_CycleWeapon(this, CS(this).cvar_cl_weaponpriority, +1, weaponentity); } // previously used if exists and has ammo, (second) best otherwise -void W_LastWeapon(entity this) +void W_LastWeapon(entity this, .entity weaponentity) { - Weapon wep = Weapons_from(this.cnt); - if (client_hasweapon(this, wep, true, false)) - W_SwitchWeapon(this, wep); + Weapon wep = Weapons_from(this.(weaponentity).cnt); + if (client_hasweapon(this, wep, weaponentity, true, false)) + W_SwitchWeapon(this, wep, weaponentity); else - W_SwitchToOtherWeapon(this); + W_SwitchToOtherWeapon(this, weaponentity); }