X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fweapons%2Fselection.qc;h=737ddc8adcbf8e2c25ad3e14a1644f9bde97d450;hb=eb6fabc8b16e23fcf0704ecf97685dffa7387bb7;hp=da9b00a184e218338bad00edef85439f52f86c4f;hpb=61a847dbaab291d205cc9684b6d1a6e9bdad6375;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index da9b00a18..737ddc8ad 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -1,41 +1,41 @@ #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/weapons.qh" +#include "../../common/items/item.qh" +#include "../../common/weapons/all.qh" +#include "../../common/mutators/mutator/waypoints/waypointsprites.qh" // 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) +bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain) { float f; - entity oldself; - if(time < self.hasweapon_complain_spam) + if (time < cl.hasweapon_complain_spam) complain = 0; - if(wpn == WEP_HOOK && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) - complain = 0; + // ignore hook button when using other offhand equipment + if (cl.offhand != OFFHAND_HOOK) + 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(wpn)) @@ -48,26 +48,22 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) } else { - oldself = self; - self = cl; - f = WEP_ACTION(wpn, WR_CHECKAMMO1); - f = f + WEP_ACTION(wpn, WR_CHECKAMMO2); + 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) - for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self) + for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == cl) f = 1; - self = oldself; } if (!f) { if (complain) if(IS_REAL_CLIENT(cl)) { - play2(cl, "weapons/unavailable.wav"); - Send_WeaponComplain (cl, wpn, 0); + play2(cl, SND(UNAVAILABLE)); + Send_WeaponComplain (cl, wpn.m_id, 0); } return false; } @@ -80,42 +76,43 @@ 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); + 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; if(!(e.flags & FL_ITEM)) continue; - WaypointSprite_Spawn( - (get_weaponinfo(wpn)).wpmodel, + entity wp = WaypointSprite_Spawn( + WP_Weapon, 1, 0, world, e.origin + ('0 0 1' * e.maxs.z) * 1.2, - self, 0, + cl, 0, world, enemy, 0, - RADARICON_NONE, '0 0 0' + RADARICON_NONE ); + wp.wp_extra = wpn.m_id; } } } else { - Send_WeaponComplain (cl, wpn, 2); + Send_WeaponComplain (cl, wpn.m_id, 2); } - play2(cl, "weapons/unavailable.wav"); + play2(cl, SND(UNAVAILABLE)); } return false; } float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing) -{ +{SELFPARAM(); // 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; @@ -139,20 +136,19 @@ 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((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)) @@ -162,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; @@ -196,20 +192,19 @@ 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((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)) @@ -220,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; } } @@ -228,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; @@ -239,51 +235,54 @@ void W_SwitchWeapon_Force(entity e, float w) void W_SwitchToOtherWeapon(entity pl) { // 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)) + int ww; + WepSet set = WepSet_FromWeapon(Weapons_from(pl.weapon)); + if(pl.weapons & set) { - pl.weapons &= ~WepSet_FromWeapon(w); + pl.weapons &= ~set; ww = w_getbestweapon(pl); - pl.weapons |= WepSet_FromWeapon(w); + pl.weapons |= set; } 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()) { WEP_ACTION(self.weapon, WR_RELOAD); } + else if(!forbidWeaponUse(self)) { + w.wr_reload(w); + } } void W_CycleWeapon(string weaponorder, float dir) -{ +{SELFPARAM(); 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) -{ +{SELFPARAM(); 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 void W_NextWeapon(float list) -{ +{SELFPARAM(); if(list == 0) W_CycleWeapon(weaponorder_byid, -1); else if(list == 1) @@ -294,7 +293,7 @@ void W_NextWeapon(float list) // prev weapon void W_PreviousWeapon(float list) -{ +{SELFPARAM(); if(list == 0) W_CycleWeapon(weaponorder_byid, +1); else if(list == 1) @@ -304,10 +303,11 @@ 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)) - W_SwitchWeapon(self.cnt); +void W_LastWeapon() +{SELFPARAM(); + Weapon wep = Weapons_from(self.cnt); + if(client_hasweapon(self, wep, true, false)) + W_SwitchWeapon(wep); else W_SwitchToOtherWeapon(self); }