MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / BNode_FindClosestLocalVisibleBNode

Function BNode_FindClosestLocalVisibleBNode

Descent3/bnode.cpp:393–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391}
392
393int BNode_FindClosestLocalVisibleBNode(int roomnum, vector *pos, float rad) {
394 int i, j;
395 float closest_dist = 800.0f;
396 int closest_node = -1;
397 bool f_retry = false;
398
399 float min_bn_rad = rad / 4.0f;
400 if (min_bn_rad > MAX_BNODE_SIZE) {
401 min_bn_rad = MAX_BNODE_SIZE;
402 }
403
404 bn_list *bnlist = BNode_GetBNListPtr(roomnum);
405
406retry:
407
408 for (i = 0; i < bnlist->num_nodes; i++) {
409 float dist = BNode_QuickDist(&bnlist->nodes[i].pos, pos);
410
411 if (dist < closest_dist) {
412 float node_size = 0.0f;
413
414 if (!f_retry) {
415 for (j = 0; j < bnlist->nodes[i].num_edges; j++) {
416 if (bnlist->nodes[i].edges[j].max_rad > node_size) {
417 node_size = bnlist->nodes[i].edges[j].max_rad;
418 }
419 }
420 }
421
422 if (f_retry || node_size >= min_bn_rad) {
423 fvi_query fq;
424 fvi_info hit_info;
425
426 if (!f_retry) {
427 fq.p0 = pos;
428 fq.startroom = (roomnum > Highest_room_index && roomnum <= Highest_room_index + 8)
429 ? GetTerrainRoomFromPos(pos)
430 : roomnum;
431 fq.p1 = &bnlist->nodes[i].pos;
432 fq.rad = min_bn_rad;
433 fq.thisobjnum = -1;
434 fq.ignore_obj_list = NULL;
435 fq.flags = 0;
436 }
437
438 if (f_retry || fvi_FindIntersection(&fq, &hit_info) == HIT_NONE) {
439 closest_dist = dist;
440 closest_node = i;
441 }
442 }
443 }
444 }
445
446 if (closest_node == -1 && !f_retry) {
447 f_retry = true;
448 goto retry;
449 }
450

Callers 2

AIGenerateAltBNodePathFunction · 0.85
AIGenerateBNodePathFunction · 0.85

Calls 5

BNode_GetBNListPtrFunction · 0.85
BNode_QuickDistFunction · 0.85
GetTerrainRoomFromPosFunction · 0.85
fvi_FindIntersectionFunction · 0.85
ps_randFunction · 0.85

Tested by

no test coverage detected