Allow entities other than SimpleActor for finding covers and sniper nodes

This commit is contained in:
smallmodel 2024-10-08 20:31:50 +02:00
parent d467b68187
commit feb76f4fb4
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 42 additions and 20 deletions

View file

@ -322,8 +322,10 @@ int PathSearch::FindPath(
PathNode *to; PathNode *to;
if (ent) { if (ent) {
// Added in OPM
// Check for simple actor
if (ent->IsSubclassOfActor()) { if (ent->IsSubclassOfActor()) {
Node = NearestStartNode(start, (SimpleActor *)ent); Node = NearestStartNode(start, static_cast<SimpleActor*>(ent));
} else { } else {
Node = DebugNearestStartNode(start, ent); Node = DebugNearestStartNode(start, ent);
} }
@ -505,8 +507,10 @@ int PathSearch::FindPathNear(
vec2_t delta; vec2_t delta;
if (ent) { if (ent) {
// Added in OPM
// Check for simple actor
if (ent->IsSubclassOfActor()) { if (ent->IsSubclassOfActor()) {
Node = NearestStartNode(start, (SimpleActor *)ent); Node = NearestStartNode(start, static_cast<SimpleActor*>(ent));
} else { } else {
Node = DebugNearestStartNode(start, ent); Node = DebugNearestStartNode(start, ent);
} }
@ -678,8 +682,10 @@ int PathSearch::FindPathAway(
fMinSafeDistSquared = fMinSafeDist * fMinSafeDist; fMinSafeDistSquared = fMinSafeDist * fMinSafeDist;
if (ent) { if (ent) {
// Added in OPM
// Check for simple actor
if (ent->IsSubclassOfActor()) { if (ent->IsSubclassOfActor()) {
Node = NearestStartNode(start, (SimpleActor *)ent); Node = NearestStartNode(start, static_cast<SimpleActor*>(ent));
} else { } else {
Node = DebugNearestStartNode(start, ent); Node = DebugNearestStartNode(start, ent);
} }
@ -825,7 +831,7 @@ int PathSearch::FindPathAway(
} }
PathNode *PathSearch::FindCornerNodeForWall( PathNode *PathSearch::FindCornerNodeForWall(
const vec3_t start, const vec3_t end, SimpleActor *ent, float maxPath, const vec4_t plane const vec3_t start, const vec3_t end, Entity *ent, float maxPath, const vec4_t plane
) )
{ {
int i, g; int i, g;
@ -836,7 +842,18 @@ PathNode *PathSearch::FindCornerNodeForWall(
vec2_t delta; vec2_t delta;
vec2_t dir; vec2_t dir;
Node = NearestStartNode(start, ent); if (ent) {
// Added in OPM
// Check for simple actor
if (ent->IsSubclassOfActor()) {
Node = NearestStartNode(start, static_cast<SimpleActor*>(ent));
} else {
Node = DebugNearestStartNode(start, ent);
}
} else {
Node = DebugNearestStartNode(start);
}
if (!Node) { if (!Node) {
last_error = "couldn't find start node"; last_error = "couldn't find start node";
return NULL; return NULL;
@ -982,7 +999,7 @@ PathNode *PathSearch::FindCornerNodeForWall(
return NULL; return NULL;
} }
PathNode *PathSearch::FindCornerNodeForExactPath(SimpleActor *pSelf, Sentient *enemy, float fMaxPath) PathNode *PathSearch::FindCornerNodeForExactPath(Entity *pSelf, Sentient *enemy, float fMaxPath)
{ {
PathNode *pPathNode[4096]; PathNode *pPathNode[4096];
PathNode *pParentNode; PathNode *pParentNode;
@ -996,7 +1013,12 @@ PathNode *PathSearch::FindCornerNodeForExactPath(SimpleActor *pSelf, Sentient *e
return NULL; return NULL;
} }
vEyePos = pSelf->EyePosition(); if (pSelf->IsSubclassOfActor()) {
vEyePos = static_cast<SimpleActor*>(pSelf)->EyePosition();
} else {
vEyePos = pSelf->origin + Vector(0, 0, pSelf->maxs.z);
}
vEyeDelta = vEyePos - pSelf->origin; vEyeDelta = vEyePos - pSelf->origin;
for (pParentNode = Node->Parent, i = 0; pParentNode; pParentNode = pParentNode->Parent, i++) { for (pParentNode = Node->Parent, i = 0; pParentNode; pParentNode = pParentNode->Parent, i++) {
@ -2358,7 +2380,7 @@ int node_compare(const void *pe1, const void *pe2)
} }
int PathSearch::FindPotentialCover( int PathSearch::FindPotentialCover(
SimpleActor *pEnt, Vector& vPos, Entity *pEnemy, PathNode **ppFoundNodes, int iMaxFind Entity *pEnt, Vector& vPos, Entity *pEnemy, PathNode **ppFoundNodes, int iMaxFind
) )
{ {
nodeinfo nodes[MAX_PATHNODES]; nodeinfo nodes[MAX_PATHNODES];
@ -2414,7 +2436,7 @@ int PathSearch::FindPotentialCover(
return nNodes; return nNodes;
} }
PathNode *PathSearch::FindNearestSniperNode(SimpleActor *pEnt, Vector& vPos, Entity *pEnemy) PathNode *PathSearch::FindNearestSniperNode(Entity*pEnt, Vector& vPos, Entity *pEnemy)
{ {
Actor *pSelf = (Actor *)pEnt; Actor *pSelf = (Actor *)pEnt;
PathNode *pNode; PathNode *pNode;
@ -3286,7 +3308,7 @@ int PathSearch::NearestNodeSetup(const vec3_t pos, MapCell *cell, int *nodes, ve
return n; return n;
} }
PathNode *PathSearch::FindNearestCover(SimpleActor *pEnt, Vector& vPos, Entity *pEnemy) PathNode *PathSearch::FindNearestCover(Entity *pEnt, Vector& vPos, Entity *pEnemy)
{ {
// not found in ida // not found in ida
return NULL; return NULL;

View file

@ -66,6 +66,7 @@ extern int path_checksthisframe;
class Path; class Path;
class PathNode; class PathNode;
class SimpleActor;
#define NUM_WIDTH_VALUES 16 #define NUM_WIDTH_VALUES 16
#define WIDTH_STEP 8 #define WIDTH_STEP 8
@ -292,7 +293,7 @@ public:
static MapCell *GetNodesInCell(const vec3_t pos); static MapCell *GetNodesInCell(const vec3_t pos);
static class PathNode *DebugNearestStartNode(const vec3_t pos, Entity *ent = NULL); static class PathNode *DebugNearestStartNode(const vec3_t pos, Entity *ent = NULL);
static class PathNode *NearestStartNode(const vec3_t pos, class SimpleActor *ent); static class PathNode *NearestStartNode(const vec3_t pos, SimpleActor *ent);
static class PathNode *NearestEndNode(const vec3_t pos); static class PathNode *NearestEndNode(const vec3_t pos);
static int DebugNearestNodeList(const vec3_t pos, PathNode **nodelist, int iMaxNodes); static int DebugNearestNodeList(const vec3_t pos, PathNode **nodelist, int iMaxNodes);
static int DebugNearestNodeList2(const vec3_t pos, PathNode **nodelist, int iMaxNodes); static int DebugNearestNodeList2(const vec3_t pos, PathNode **nodelist, int iMaxNodes);
@ -341,15 +342,14 @@ public:
float fLeashDistSquared, float fLeashDistSquared,
int fallheight int fallheight
); );
static class PathNode *FindCornerNodeForWall(
const vec3_t start, const vec3_t end, class SimpleActor *ent, float maxPath, const vec4_t plane static class PathNode *
); FindCornerNodeForWall(const vec3_t start, const vec3_t end, Entity *ent, float maxPath, const vec4_t plane);
static class PathNode *FindCornerNodeForExactPath(class SimpleActor *self, Sentient *enemy, float fMaxPath); static class PathNode *FindCornerNodeForExactPath(Entity *self, Sentient *enemy, float fMaxPath);
static int static int FindPotentialCover(Entity *pEnt, Vector& vPos, Entity *pEnemy, PathNode **ppFoundNodes, int iMaxFind);
FindPotentialCover(class SimpleActor *pEnt, Vector& vPos, Entity *pEnemy, PathNode **ppFoundNodes, int iMaxFind); static void PlayerCover(class Player *pPlayer);
static void PlayerCover(class Player *pPlayer); static class PathNode *FindNearestCover(Entity *pEnt, Vector& vPos, Entity *pEnemy);
static class PathNode *FindNearestCover(class SimpleActor *pEnt, Vector& vPos, Entity *pEnemy); static class PathNode *FindNearestSniperNode(Entity *pEnt, Vector& vPos, Entity *pEnemy);
static class PathNode *FindNearestSniperNode(class SimpleActor *pEnt, Vector& vPos, Entity *pEnemy);
private: private:
static int NearestNodeSetup(const vec3_t pos, MapCell *cell, int *nodes, vec3_t *deltas); static int NearestNodeSetup(const vec3_t pos, MapCell *cell, int *nodes, vec3_t *deltas);