Skip to content

Commit

Permalink
Deprecate SurroundingAreasCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
KitRifty committed Aug 2, 2023
1 parent 0409b81 commit e48b7a3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
4 changes: 2 additions & 2 deletions extension/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ConVar* sourcemod_version = nullptr;
IBaseNPC_Tools* g_pBaseNPCTools = new BaseNPC_Tools_API;
std::vector<sp_nativeinfo_t> gNatives;

DEFINEHANDLEOBJ(SurroundingAreasCollector, CUtlVector< CNavArea* >);
DEFINEHANDLEOBJ(AreasCollector, CUtlVector< CNavArea* >);

ConVar* g_cvDeveloper = nullptr;
extern ConVar* NextBotSpeedLookAheadRange;
Expand Down Expand Up @@ -102,7 +102,7 @@ bool CBaseNPCExt::SDK_OnLoad(char* error, size_t maxlength, bool late) {
GETGAMEDATAOFFSET("CBaseEntity::Event_Killed", iOffset);
SH_MANUALHOOK_RECONFIGURE(MEvent_Killed, iOffset, 0, 0);

CREATEHANDLETYPE(SurroundingAreasCollector);
CREATEHANDLETYPE(AreasCollector);

sharesys->AddDependency(myself, "bintools.ext", true, true);
sharesys->AddDependency(myself, "sdktools.ext", true, true);
Expand Down
4 changes: 2 additions & 2 deletions extension/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extern HandleType_t HANDLENAME(PluginPathFollower);
extern HandleType_t HANDLENAME(PluginBotReply);
extern HandleType_t HANDLENAME(PluginBotEntityFilter);

extern HandleType_t HANDLENAME(SurroundingAreasCollector);
extern HandleType_t HANDLENAME(TSurroundingAreasCollector);
extern HandleType_t HANDLENAME(AreasCollector);
extern HandleType_t HANDLENAME(TAreasCollector);

extern HandleType_t g_CellArrayHandle;
extern HandleType_t g_KeyValueType;
Expand Down
16 changes: 9 additions & 7 deletions extension/natives/nav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

namespace natives::nav {

namespace surroundingareas {
namespace collector {

inline CUtlVector<CNavArea*>* Get(IPluginContext* context, const cell_t param) {
HandleSecurity security;
security.pOwner = nullptr;
security.pIdentity = myself->GetIdentity();
Handle_t hndlObject = static_cast<Handle_t>(param);
CUtlVector<CNavArea*>* collector = nullptr;
READHANDLE(hndlObject, SurroundingAreasCollector, collector)
READHANDLE(hndlObject, AreasCollector, collector)
return collector;
}

Expand All @@ -36,6 +36,8 @@ cell_t GetElement(IPluginContext* context, const cell_t* params) {

void setup(std::vector<sp_nativeinfo_t>& natives) {
sp_nativeinfo_t list[] = {
{"AreasCollector.Count", GetCount},
{"AreasCollector.Get", GetElement},
{"SurroundingAreasCollector.Count", GetCount},
{"SurroundingAreasCollector.Get", GetElement},
};
Expand Down Expand Up @@ -106,7 +108,7 @@ class CCollectorAddToTail {
cell_t CollectSurroundingAreas(IPluginContext* context, const cell_t* params) {
CUtlVector<CNavArea*> *pCollector = new CUtlVector<CNavArea*>;
CollectSurroundingAreas( pCollector, (CNavArea*)PawnAddressToPtr(params[2]), sp_ctof(params[3]), sp_ctof(params[4]), sp_ctof(params[5]));
return CREATEHANDLE(SurroundingAreasCollector, pCollector);
return CREATEHANDLE(AreasCollector, pCollector);
}

cell_t CollectAreasOverlappingExtent(IPluginContext* context, const cell_t* params) {
Expand All @@ -125,7 +127,7 @@ cell_t CollectAreasOverlappingExtent(IPluginContext* context, const cell_t* para
CCollectorAddToTail addToTail(pCollector);

ToolsNavMesh->ForAllAreasOverlappingExtent(addToTail, extent);
return CREATEHANDLE(SurroundingAreasCollector, pCollector);
return CREATEHANDLE(AreasCollector, pCollector);
}

cell_t CollectAreasInRadius(IPluginContext* context, const cell_t* params) {
Expand All @@ -139,7 +141,7 @@ cell_t CollectAreasInRadius(IPluginContext* context, const cell_t* params) {
CCollectorAddToTail addToTail(pCollector);

ToolsNavMesh->ForAllAreasInRadius(addToTail, pos, radius);
return CREATEHANDLE(SurroundingAreasCollector, pCollector);
return CREATEHANDLE(AreasCollector, pCollector);
}

cell_t CollectAreasAlongLine(IPluginContext* context, const cell_t* params) {
Expand All @@ -152,7 +154,7 @@ cell_t CollectAreasAlongLine(IPluginContext* context, const cell_t* params) {
CCollectorAddToTail addToTail(pCollector);

*reachedEndAddr = ToolsNavMesh->ForAllAreasAlongLine(addToTail, startArea, endArea) ? 1 : 0;
return CREATEHANDLE(SurroundingAreasCollector, pCollector);
return CREATEHANDLE(AreasCollector, pCollector);
}

class SMPathCost : public IPathCost
Expand Down Expand Up @@ -254,7 +256,7 @@ cell_t BuildPath(IPluginContext* context, const cell_t* params) {

void setup(std::vector<sp_nativeinfo_t>& natives) {
area::setup(natives);
surroundingareas::setup(natives);
collector::setup(natives);

tf::nav::setup(natives);

Expand Down
25 changes: 17 additions & 8 deletions scripting/include/cbasenpc/nav.inc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ enum CNavMesh
};

methodmap SurroundingAreasCollector < Handle
{
#pragma deprecated Use AreasCollector.Get() instead.
public native CNavArea Get(int index);

#pragma deprecated Use AreasCollector.Count() instead.
public native int Count();
};

methodmap AreasCollector < SurroundingAreasCollector
{
public native CNavArea Get(int index);
public native int Count();
Expand Down Expand Up @@ -238,29 +247,29 @@ methodmap CNavMesh
* @param travelDistanceLimit Maximum travel distance
* @param maxStepUpLimit Maximum step height
* @param maxDropDownLimit Maximum drop down height limit
* @return SurroundingAreasCollector iterator. You must delete this
* @return AreasCollector iterator. You must delete this
* when you are done with it.
*/
public native SurroundingAreasCollector CollectSurroundingAreas(CNavArea startArea, float travelDistanceLimit = 1500.0, float maxStepUpLimit = 18.0, float maxDropDownLimit = 100.0);
public native AreasCollector CollectSurroundingAreas(CNavArea startArea, float travelDistanceLimit = 1500.0, float maxStepUpLimit = 18.0, float maxDropDownLimit = 100.0);

/**
* Collects all areas that overlap the box defined by the given `mins` and `maxs`
* vectors.
*
* @param mins World vector of the minimum corner of the box.
* @param maxs World vector of the maximum corner of the box.
* @return SurroundingAreasCollector iterator. You must delete this when you are done with it.
* @return AreasCollector iterator. You must delete this when you are done with it.
*/
public native SurroundingAreasCollector CollectAreasOverlappingExtent(const float mins[3], const float maxs[3]);
public native AreasCollector CollectAreasOverlappingExtent(const float mins[3], const float maxs[3]);

/**
* Collects all areas whose center is within the radius of the given position.
*
* @param pos Position to search for.
* @param radius Radius
* @return SurroundingAreasCollector iterator. You must delete this when you are done with it.
* @return AreasCollector iterator. You must delete this when you are done with it.
*/
public native SurroundingAreasCollector CollectAreasInRadius(const float pos[3], float radius);
public native AreasCollector CollectAreasInRadius(const float pos[3], float radius);

/**
* Steps through the nav mesh and collects all areas along the line between `startArea` and `endArea`.
Expand All @@ -269,9 +278,9 @@ methodmap CNavMesh
* @param endArea End area
* @param reachedEnd Optional. Set to true if collection reached the end area, false if it doesn't reach it
* (no mesh between, bad connection, etc).
* @return SurroundingAreasCollector iterator. You must delete this when you are done with it.
* @return AreasCollector iterator. You must delete this when you are done with it.
*/
public native SurroundingAreasCollector CollectAreasAlongLine(CNavArea startArea, CNavArea endArea, bool &reachedEnd = false);
public native AreasCollector CollectAreasAlongLine(CNavArea startArea, CNavArea endArea, bool &reachedEnd = false);

/**
* Given an ID, return the associated area.
Expand Down

0 comments on commit e48b7a3

Please sign in to comment.