return false;
}
-float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing, .entity weaponentity)
+float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, bool complain, bool skipmissing, .entity weaponentity)
{
// We cannot tokenize in this function, as GiveItems calls this
// function. Thus we must use car/cdr.
if(dir == 0)
switchtonext = 1;
+ // complain-specific vars
int c = 0;
+ entity wepcomplain = NULL;
+ int wepcomplainindex = 0;
string rest = weaponorder;
while(rest != "")
if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
continue;
- ++c;
+ if(complain)
+ {
+ if(!wepcomplain || this.weaponcomplainindex == c)
+ {
+ wepcomplain = wep;
+ wepcomplainindex = c;
+ }
+ ++c;
+ }
if(!skipmissing || client_hasweapon(this, wep, weaponentity, true, false))
{
else
return first_valid;
}
+
// complain (but only for one weapon on the button that has been pressed)
if(complain)
{
- this.weaponcomplainindex += 1;
- c = (this.weaponcomplainindex % c) + 1;
- rest = weaponorder;
- while(rest != "")
- {
- weaponwant = stof(car(rest)); rest = cdr(rest);
- wep = REGISTRY_GET(Weapons, weaponwant);
- wepset = wep.m_wepset;
- if(imp >= 0)
- if(wep.impulse != imp)
- continue;
-
- bool have_other = false;
- FOREACH(Weapons, it != WEP_Null, {
- if(i != weaponwant)
- if(it.impulse == imp || imp < 0)
- if((STAT(WEAPONS, this) | weaponsInMap) & it.m_wepset)
- have_other = true;
- });
-
- // skip weapons we don't own that aren't normal and aren't in the map
- if(!(STAT(WEAPONS, this) & wepset))
- if(!(weaponsInMap & wepset))
- if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
- continue;
-
- --c;
- if(c == 0)
- {
- client_hasweapon(this, wep, weaponentity, true, true);
- break;
- }
- }
+ this.weaponcomplainindex = wepcomplainindex + 1;
+ client_hasweapon(this, wepcomplain, weaponentity, true, true);
}
return 0;
}
void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity)
{
float w;
- w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true, weaponentity);
+ w = W_GetCycleWeapon(this, weaponorder, dir, -1, true, true, weaponentity);
if(w > 0)
W_SwitchWeapon(this, REGISTRY_GET(Weapons, w), weaponentity);
}
void W_NextWeaponOnImpulse(entity this, float imp, .entity weaponentity)
{
float w;
- w = W_GetCycleWeapon(this, CS_CVAR(this).cvar_cl_weaponpriority, +1, imp, 1, (CS_CVAR(this).cvar_cl_weaponimpulsemode == 0), weaponentity);
+ w = W_GetCycleWeapon(this, CS_CVAR(this).cvar_cl_weaponpriority, +1, imp, true, (CS_CVAR(this).cvar_cl_weaponimpulsemode == 0), weaponentity);
if(w > 0)
W_SwitchWeapon(this, REGISTRY_GET(Weapons, w), weaponentity);
}
bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andammo, bool complain);
.int weaponcomplainindex;
-float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing, .entity weaponentity);
+float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, bool complain, bool skipmissing, .entity weaponentity);
#define w_getbestweapon(ent,wepent) REGISTRY_GET(Weapons, W_GetCycleWeapon(ent, CS_CVAR(ent).cvar_cl_weaponpriority, 0, -1, false, true, wepent))