This repository has been archived on 2024-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
nekohook/modules/source2013/sdk/game/client/playerenumerator.h
2020-08-04 13:13:01 -04:00

65 lines
1.6 KiB
C++

//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef PLAYERENUMERATOR_H
#define PLAYERENUMERATOR_H
#ifdef _WIN32
#pragma once
#endif
#include "ehandle.h"
#include "ispatialpartition.h"
#include "utlvector.h"
class C_BaseEntity;
class CPlayerEnumerator : public IPartitionEnumerator {
DECLARE_CLASS_NOBASE(CPlayerEnumerator);
public:
// Forced constructor
CPlayerEnumerator(float radius, Vector vecOrigin) {
m_flRadiusSquared = radius * radius;
m_vecOrigin = vecOrigin;
m_Objects.RemoveAll();
}
int GetObjectCount() { return m_Objects.Size(); }
C_BaseEntity *GetObject(int index) {
if (index < 0 || index >= GetObjectCount()) return NULL;
return m_Objects[index];
}
// Actual work code
virtual IterationRetval_t EnumElement(IHandleEntity *pHandleEntity) {
C_BaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle(
pHandleEntity->GetRefEHandle());
if (pEnt == NULL) return ITERATION_CONTINUE;
if (!pEnt->IsPlayer()) return ITERATION_CONTINUE;
Vector deltaPos = pEnt->GetAbsOrigin() - m_vecOrigin;
if (deltaPos.LengthSqr() > m_flRadiusSquared) return ITERATION_CONTINUE;
CHandle<C_BaseEntity> h;
h = pEnt;
m_Objects.AddToTail(h);
return ITERATION_CONTINUE;
}
public:
// Data members
float m_flRadiusSquared;
Vector m_vecOrigin;
CUtlVector<CHandle<C_BaseEntity> > m_Objects;
};
#endif // PLAYERENUMERATOR_H