Added badPlaceTeam

This commit is contained in:
smallmodel 2023-10-24 19:30:13 +02:00
parent 64a3b04181
commit dc1be17b2a
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 103 additions and 106 deletions

View file

@ -492,6 +492,10 @@ void PathNode::ArchiveStatic(Archiver& arc)
if (arc.Loading()) { if (arc.Loading()) {
Child[i].numBlockers = 0; Child[i].numBlockers = 0;
for (int j = 0; j < ARRAY_LEN(Child[i].badPlaceTeam); j++) {
Child[i].badPlaceTeam[j] = 0;
}
} }
} }
} }
@ -1086,6 +1090,7 @@ PathNode *PathSearch::DebugNearestStartNode(float *pos, Entity *ent)
vec3_t deltas[128]; vec3_t deltas[128];
vec3_t start; vec3_t start;
vec3_t end; vec3_t end;
int node_count;
cell = GetNodesInCell(pos); cell = GetNodesInCell(pos);
@ -1093,7 +1098,7 @@ PathNode *PathSearch::DebugNearestStartNode(float *pos, Entity *ent)
return NULL; return NULL;
} }
int node_count = NearestNodeSetup(pos, cell, nodes, deltas); node_count = NearestNodeSetup(pos, cell, nodes, deltas);
if (!node_count) { if (!node_count) {
return NULL; return NULL;
@ -1108,13 +1113,16 @@ PathNode *PathSearch::DebugNearestStartNode(float *pos, Entity *ent)
VectorCopy(start, end); VectorCopy(start, end);
VectorAdd(end, deltas[nodes[i]], end); VectorAdd(end, deltas[nodes[i]], end);
Vector vStart = start;
Vector vMins = Vector(-15, -15, 0);
Vector vMaxs = Vector(15, 15, 62);
Vector vEnd = end;
if (G_SightTrace( if (G_SightTrace(
vStart, vMins, vMaxs, vEnd, ent, NULL, MASK_TARGETPATH, qtrue, "PathSearch::DebugNearestStartNode" start,
Vector(-15, -15, 0),
Vector(15, 15, 62),
end,
ent,
NULL,
MASK_TARGETPATH,
qtrue,
"PathSearch::DebugNearestStartNode"
)) { )) {
return node; return node;
} }
@ -1132,6 +1140,7 @@ PathNode *PathSearch::NearestStartNode(float *pos, SimpleActor *ent)
vec3_t deltas[128]; vec3_t deltas[128];
vec3_t start; vec3_t start;
vec3_t end; vec3_t end;
int node_count;
cell = GetNodesInCell(pos); cell = GetNodesInCell(pos);
@ -1139,60 +1148,54 @@ PathNode *PathSearch::NearestStartNode(float *pos, SimpleActor *ent)
return NULL; return NULL;
} }
int node_count = NearestNodeSetup(pos, cell, nodes, deltas); node_count = NearestNodeSetup(pos, cell, nodes, deltas);
int n = 0;
int j = 0;
VectorCopy(pos, start); VectorCopy(pos, start);
start[2] += 32.0f; start[2] += 32.0f;
Vector vMins = Vector(-15, -15, 0);
Vector vMaxs = Vector(15, 15, 62);
for (i = 0; i < node_count; i++) { for (i = 0; i < node_count; i++) {
node = pathnodes[cell->nodes[nodes[i]]]; node = pathnodes[cell->nodes[nodes[i]]];
VectorAdd(start, deltas[nodes[i]], end); VectorAdd(start, deltas[nodes[i]], end);
Vector vStart = start;
Vector vEnd = end;
if (G_SightTrace( if (G_SightTrace(
vStart, start,
vMins, Vector(-15, -15, 0),
vMaxs, Vector(15, 15, 62),
vEnd, end,
(gentity_t *)NULL, ent,
(gentity_t *)NULL, NULL,
1107437825, //FIXME: macro MASK_PATHSOLID,
qtrue, qtrue,
"PathSearch::NearestStartNode 1" "PathSearch::NearestStartNode 1"
)) { )) {
ent->m_NearestNode = node; ent->m_NearestNode = node;
ent->m_vNearestNodePos = end; VectorCopy(end, ent->m_vNearestNodePos);
return node; return node;
} }
} }
if ((ent->m_NearestNode if (ent->m_NearestNode) {
&& (G_SightTrace( if (G_SightTrace(
Vector(start), start,
vMins, Vector(-15, -15, 0),
vMaxs, Vector(15, 15, 62),
ent->m_vNearestNodePos, ent->m_vNearestNodePos,
ent->edict, ent,
(gentity_t *)NULL, NULL,
1073883393, //FIXME: macro MASK_TARGETPATH,
qtrue, qtrue,
"PathSearch::NearestStartNode 2" "PathSearch::NearestStartNode 2"
))) )) {
|| node_count <= 0) { return ent->m_NearestNode;
node = ent->m_NearestNode; }
} else {
node = pathnodes[cell->nodes[nodes[0]]];
} }
return node; if (node_count <= 0) {
return ent->m_NearestNode;
}
return pathnodes[cell->nodes[nodes[0]]];
} }
PathNode *PathSearch::NearestEndNode(float *pos) PathNode *PathSearch::NearestEndNode(float *pos)
@ -1204,6 +1207,7 @@ PathNode *PathSearch::NearestEndNode(float *pos)
vec3_t deltas[128]; vec3_t deltas[128];
vec3_t start; vec3_t start;
vec3_t end; vec3_t end;
int node_count;
cell = GetNodesInCell(pos); cell = GetNodesInCell(pos);
@ -1211,9 +1215,7 @@ PathNode *PathSearch::NearestEndNode(float *pos)
return NULL; return NULL;
} }
int node_count = NearestNodeSetup(pos, cell, nodes, deltas); node_count = NearestNodeSetup(pos, cell, nodes, deltas);
int n = 0;
int j = 0;
if (!node_count) { if (!node_count) {
return NULL; return NULL;
@ -1227,18 +1229,13 @@ PathNode *PathSearch::NearestEndNode(float *pos)
VectorAdd(start, deltas[nodes[i]], end); VectorAdd(start, deltas[nodes[i]], end);
Vector vStart = start;
Vector vMins = Vector(-15, -15, 0);
Vector vMaxs = Vector(15, 15, 62);
Vector vEnd = end;
if (G_SightTrace( if (G_SightTrace(
vStart, start,
vMins, Vector(-15, -15, 0),
vMaxs, Vector(15, 15, 62),
vEnd, end,
(gentity_t *)NULL, (Entity *)nullptr,
(gentity_t *)NULL, (Entity *)nullptr,
MASK_TARGETPATH, MASK_TARGETPATH,
qtrue, qtrue,
"PathSearch::NearestEndNode" "PathSearch::NearestEndNode"
@ -1816,7 +1813,7 @@ void PathSearch::ResetNodes(void)
int i; int i;
int x; int x;
int y; int y;
m_bNodesloaded = false; m_bNodesloaded = false;
m_LoadIndex = -1; m_LoadIndex = -1;
@ -1872,8 +1869,8 @@ void PathSearch::UpdatePathwaysForBadPlace(const Vector& origin, float radius, i
pathway_t& pathway = node->Child[j - 1]; pathway_t& pathway = node->Child[j - 1];
if (PointToSegmentDistanceSquared(origin, pathway.pos1, pathway.pos2) < radiusSqr) { if (PointToSegmentDistanceSquared(origin, pathway.pos1, pathway.pos2) < radiusSqr) {
for (k = 0; k < 2; k++) { for (k = 0; k < 2; k++) {
if ((1 << i) & team) { if ((1 << k) & team) {
pathway.numBlockers += dir; pathway.badPlaceTeam[k] += dir;
} }
} }
} }
@ -2122,10 +2119,10 @@ int PathSearch::FindPath(
return 0; return 0;
} }
total_dist = 1e+12; total_dist = 1e+12f;
if (!maxPath) { if (!maxPath) {
maxPath = 1e+12; maxPath = 1e+12f;
} }
findFrame++; findFrame++;
@ -2135,8 +2132,8 @@ int PathSearch::FindPath(
Node->g = VectorNormalize2D(path_startdir); Node->g = VectorNormalize2D(path_startdir);
VectorSub2D(end, start, path_totaldir); VectorSub2D(end, start, path_totaldir);
Node->h = VectorNormalize2D(path_totaldir); Node->h = VectorNormalize2D(path_totaldir);
Node->Parent = NULL; Node->Parent = NULL;
Node->m_Depth = 3; Node->m_Depth = 3;
Node->findCount = findFrame; Node->findCount = findFrame;
@ -2150,7 +2147,7 @@ int PathSearch::FindPath(
while (open) { while (open) {
Node = open; Node = open;
Node->inopen = false; Node->inopen = false;
open = Node->NextNode; open = Node->NextNode;
if (open) { if (open) {
open->PrevNode = NULL; open->PrevNode = NULL;
@ -2158,7 +2155,7 @@ int PathSearch::FindPath(
if (Node == to) { if (Node == to) {
path_start = start; path_start = start;
path_end = end; path_end = end;
return Node->m_Depth; return Node->m_Depth;
} }
@ -2185,8 +2182,8 @@ int PathSearch::FindPath(
if (NewNode->inopen) { if (NewNode->inopen) {
NewNode->inopen = false; NewNode->inopen = false;
next = NewNode->NextNode; next = NewNode->NextNode;
prev = NewNode->PrevNode; prev = NewNode->PrevNode;
if (next) { if (next) {
next->PrevNode = prev; next->PrevNode = prev;
@ -2194,8 +2191,7 @@ int PathSearch::FindPath(
if (prev) { if (prev) {
prev->NextNode = next; prev->NextNode = next;
} } else {
else {
open = next; open = next;
} }
} }
@ -2212,19 +2208,19 @@ int PathSearch::FindPath(
} }
if (pathway->fallheight <= fallheight) { if (pathway->fallheight <= fallheight) {
NewNode->m_Depth = Node->m_Depth + 1; NewNode->m_Depth = Node->m_Depth + 1;
NewNode->Parent = Node; NewNode->Parent = Node;
NewNode->pathway = i; NewNode->pathway = i;
NewNode->g = (float)g; NewNode->g = (float)g;
NewNode->f = (float)f; NewNode->f = (float)f;
NewNode->m_PathPos = pathway->pos2; NewNode->m_PathPos = pathway->pos2;
NewNode->findCount = findFrame; NewNode->findCount = findFrame;
NewNode->inopen = 1; NewNode->inopen = 1;
if (!open) { if (!open) {
NewNode->NextNode = NULL; NewNode->NextNode = NULL;
NewNode->PrevNode = NULL; NewNode->PrevNode = NULL;
open = NewNode; open = NewNode;
continue; continue;
} }
@ -2233,7 +2229,7 @@ int PathSearch::FindPath(
NewNode->PrevNode = NULL; NewNode->PrevNode = NULL;
open->PrevNode = NewNode; open->PrevNode = NewNode;
open = NewNode; open = NewNode;
continue; continue;
} }
@ -2249,7 +2245,7 @@ int PathSearch::FindPath(
if (next) { if (next) {
next->PrevNode = NewNode; next->PrevNode = NewNode;
} }
prev->NextNode = NewNode; prev->NextNode = NewNode;
NewNode->PrevNode = prev; NewNode->PrevNode = prev;
} }
} }
@ -2623,12 +2619,12 @@ int node_compare(const void *pe1, const void *pe2)
PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActor *ent, float maxPath, float *plane) PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActor *ent, float maxPath, float *plane)
{ {
int i, g; int i, g;
PathNode* NewNode; PathNode *NewNode;
pathway_t* pathway; pathway_t *pathway;
PathNode* prev, * next; PathNode *prev, *next;
int f; int f;
vec2_t delta; vec2_t delta;
Node = NearestStartNode(start, ent); Node = NearestStartNode(start, ent);
if (!Node) { if (!Node) {
@ -2671,7 +2667,7 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
Node->PrevNode = 0; Node->PrevNode = 0;
Node->NextNode = 0; Node->NextNode = 0;
open = Node; open = Node;
if (!open) { if (!open) {
last_error = "unreachable path"; last_error = "unreachable path";
@ -2679,9 +2675,9 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
} }
while (true) { while (true) {
Node = open; Node = open;
Node->inopen = false; Node->inopen = false;
open = Node->NextNode; open = Node->NextNode;
if (open) { if (open) {
open->PrevNode = NULL; open->PrevNode = NULL;
@ -2710,7 +2706,7 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
while (true) { while (true) {
pathway = &Node->Child[--i]; pathway = &Node->Child[--i];
NewNode = PathSearch::pathnodes[pathway->node]; NewNode = PathSearch::pathnodes[pathway->node];
g = (pathway->dist + Node->g + 1.0); g = (pathway->dist + Node->g + 1.0);
if (NewNode->findCount == PathSearch::findFrame) { if (NewNode->findCount == PathSearch::findFrame) {
if (g >= NewNode->g) { if (g >= NewNode->g) {
@ -2743,7 +2739,7 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
if (f >= maxPath) { if (f >= maxPath) {
break; break;
} }
NewNode->m_Depth = Node->m_Depth + 1; NewNode->m_Depth = Node->m_Depth + 1;
NewNode->Parent = Node; NewNode->Parent = Node;
NewNode->pathway = i; NewNode->pathway = i;
@ -2756,7 +2752,7 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
if (!PathSearch::open) { if (!PathSearch::open) {
NewNode->NextNode = NULL; NewNode->NextNode = NULL;
NewNode->PrevNode = NULL; NewNode->PrevNode = NULL;
PathSearch::open = NewNode; PathSearch::open = NewNode;
if (i == 0) { if (i == 0) {
goto weird_lbl; goto weird_lbl;
} }
@ -2765,10 +2761,10 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
} }
if (f <= open->f) { if (f <= open->f) {
NewNode->NextNode = PathSearch::open; NewNode->NextNode = PathSearch::open;
NewNode->PrevNode = NULL; NewNode->PrevNode = NULL;
open->PrevNode = NewNode; open->PrevNode = NewNode;
open = NewNode; open = NewNode;
if (i == 0) { if (i == 0) {
goto weird_lbl; goto weird_lbl;
} }
@ -2778,7 +2774,7 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
prev = open; prev = open;
PathNode* pNextOpenNode; PathNode *pNextOpenNode;
for (pNextOpenNode = open->NextNode; pNextOpenNode; pNextOpenNode = pNextOpenNode->NextNode) { for (pNextOpenNode = open->NextNode; pNextOpenNode; pNextOpenNode = pNextOpenNode->NextNode) {
if (pNextOpenNode->f >= f) { if (pNextOpenNode->f >= f) {
break; break;
@ -2793,7 +2789,7 @@ PathNode *PathSearch::FindCornerNodeForWall(float *start, float *end, SimpleActo
pNextOpenNode->PrevNode = NewNode; pNextOpenNode->PrevNode = NewNode;
} }
prev->NextNode = NewNode; prev->NextNode = NewNode;
NewNode->PrevNode = prev; NewNode->PrevNode = prev;
if (i == 0) { if (i == 0) {
@ -2870,13 +2866,13 @@ int PathSearch::FindPotentialCover(
SimpleActor *pEnt, Vector& vPos, Entity *pEnemy, PathNode **ppFoundNodes, int iMaxFind SimpleActor *pEnt, Vector& vPos, Entity *pEnemy, PathNode **ppFoundNodes, int iMaxFind
) )
{ {
nodeinfo nodes[MAX_PATHNODES]; nodeinfo nodes[MAX_PATHNODES];
int nNodes = 0; int nNodes = 0;
int i; int i;
Vector delta; Vector delta;
PathNode* node; PathNode *node;
Actor* pActor = static_cast<Actor*>(pEnt); Actor *pActor = static_cast<Actor *>(pEnt);
for (i = 0; i < nodecount; i++) { for (i = 0; i < nodecount; i++) {
node = pathnodes[i]; node = pathnodes[i];
@ -2888,7 +2884,7 @@ int PathSearch::FindPotentialCover(
continue; continue;
} }
if (node->IsClaimedByOther(static_cast<Entity*>(pEnt))) { if (node->IsClaimedByOther(static_cast<Entity *>(pEnt))) {
continue; continue;
} }
@ -2903,8 +2899,8 @@ int PathSearch::FindPotentialCover(
continue; continue;
} }
delta = node->origin - pEnt->origin; delta = node->origin - pEnt->origin;
nodes[nNodes].pNode = node; nodes[nNodes].pNode = node;
nodes[nNodes].fDistSquared = delta.lengthSquared(); nodes[nNodes].fDistSquared = delta.lengthSquared();
nNodes++; nNodes++;
} }
@ -3038,7 +3034,7 @@ int PathSearch::NearestNodeSetup(vec3_t pos, MapCell *cell, int *nodes, vec3_t *
continue; continue;
} }
if (node->origin[2] > pos[2] + 94.0f) { if (pos[2] + 94.0f < node->origin[2]) {
continue; continue;
} }

View file

@ -85,6 +85,7 @@ public:
typedef struct { typedef struct {
byte numBlockers; byte numBlockers;
byte badPlaceTeam[2];
short int node; short int node;
short int fallheight; short int fallheight;
float dist; float dist;