game/server/server_weapon.c
/*	Cycle through currently avaliable weapons.
*/
Cycle through currently avaliable weapons.
Cycle through currently avaliable weapons .
void Weapon_Cycle(ServerEntity_t *eEntity, bool bForward)
{
	if(eEntity->local.dAttackFinished > Server.dTime)
	{
		return;
	}
	Weapon_t *cur_weapon = Weapon_GetCurrentWeapon(eEntity);
	if(!cur_weapon)
	{
		return;
	}
	if(cur_weapon < Weapons || cur_weapon > LAST_WEAPON)
	{
		Engine.Con_Warning("Weapon_Cycle: cur_weapon outside of Weapons array!\n");
		return;
	}
	Weapon_t *next_weapon = cur_weapon;
	do
	{
		if(bForward)
		{
			++next_weapon;
		}
		else{
			--next_weapon;
		}
		if(next_weapon < Weapons)
		{
			next_weapon = LAST_WEAPON;
		}
		else if(next_weapon > LAST_WEAPON)
		{
			next_weapon = Weapons;
		}
		Item_t *nw_item = Item_GetItem(next_weapon->iItem);
		if(nw_item == NULL)
		{
			Engine.Con_Warning("Weapon_Cycle: Found weapon with no matching item (iItem = %d)!\n", next_weapon->iItem);
			continue;
		}
		if(Item_CheckInventory(nw_item, eEntity)
			&& (Weapon_CheckPrimaryAmmo(next_weapon, eEntity) || Weapon_CheckSecondaryAmmo(next_weapon, eEntity)))
		{
			Weapon_SetActive(next_weapon, eEntity, true);
			break;
		}
	} while(next_weapon != cur_weapon);
}
void Weapon_Cycle ( ServerEntity_t * eEntity , bool bForward ) { if ( eEntity -> local . dAttackFinished > Server . dTime ) { return ; } Weapon_t * cur_weapon = Weapon_GetCurrentWeapon ( eEntity ) ; if ( ! cur_weapon ) { return ; } if ( cur_weapon < Weapons || cur_weapon > LAST_WEAPON ) { Engine . Con_Warning ( " \n " ) ; return ; } Weapon_t * next_weapon = cur_weapon ; do { if ( bForward ) { ++ next_weapon ; } else { -- next_weapon ; } if ( next_weapon < Weapons ) { next_weapon = LAST_WEAPON ; } else if ( next_weapon > LAST_WEAPON ) { next_weapon = Weapons ; } Item_t * nw_item = Item_GetItem ( next_weapon -> iItem ) ; if ( nw_item == NULL ) { Engine . Con_Warning ( " \n " , next_weapon -> iItem ) ; continue ; } if ( Item_CheckInventory ( nw_item , eEntity ) && ( Weapon_CheckPrimaryAmmo ( next_weapon , eEntity ) || Weapon_CheckSecondaryAmmo ( next_weapon , eEntity ) ) ) { Weapon_SetActive ( next_weapon , eEntity , true ) ; break ; } } while ( next_weapon != cur_weapon ) ; }
Cycle through currently avaliable weapons.
Cycle through currently avaliable weapons .
/* Start at our current weapon... */ /* ...move up/down the Weapons array... */ /* ...loop around if we run off the end... */ /* ...get the backing item... */ /* ...check the weapon is in our inventory and has some ammo... */ /* ...everything's ok, switch to it! */ /* ...keep looping until we come back to our current weapon... */