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

Function AIGenerateBNodePath

Descent3/aipath.cpp:827–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

825// }
826
827static bool AIGenerateBNodePath(object *obj, vector *start_pos, int *start_room, vector *end_pos, int *end_room,
828 ai_path_info *aip, int *slot, int *cur_node, int handle) {
829 int next_room = BOA_INDEX(*start_room);
830 bool f_path_exists = true;
831 vector *pos;
832
833 bn_list *bnlist; // = BNode_GetBNListPtr(*start_room);
834 int last_node = BNode_FindDirLocalVisibleBNode(*start_room, start_pos, &obj->orient.fvec, obj->size);
835 if (last_node == -1) {
836 f_path_exists = false;
837 goto done;
838 }
839
840 ASSERT(!(next_room >= 0 && next_room <= Highest_room_index && !Rooms[next_room].used));
841
842 // pos = &bnlist->nodes[last_node].pos;
843 // AIPathAddDPathNode(aip, slot, cur_node, pos, *start_room, handle);
844
845 while ((BOA_INDEX(next_room) != BOA_GetNextRoom(next_room, *end_room)) && (next_room != BOA_NO_PATH) &&
846 f_path_exists) {
847 int cur_room;
848
849 cur_room = next_room;
850 next_room = BOA_GetNextRoom(next_room, *end_room);
851 bnlist = BNode_GetBNListPtr(cur_room);
852 ASSERT(bnlist);
853
854 if (next_room != cur_room && next_room != BOA_NO_PATH) {
855 int portal = BOA_DetermineStartRoomPortal(cur_room, NULL, next_room, NULL);
856 if (portal == -1) {
857 f_path_exists = false;
858 } else {
859 int bnode;
860
861 if (cur_room <= Highest_room_index) {
862 bnode = Rooms[cur_room].portals[portal].bnode_index;
863 ASSERT(bnode >= 0 && bnode < BNode_GetBNListPtr(cur_room)->num_nodes);
864 } else {
865 int croom = BOA_connect[cur_room - Highest_room_index - 1][portal].roomnum;
866 int cportal = BOA_connect[cur_room - Highest_room_index - 1][portal].portal;
867
868 int r = Rooms[croom].portals[cportal].croom;
869 int p = Rooms[croom].portals[cportal].cportal;
870
871 ASSERT(Rooms[r].used && (Rooms[r].flags & RF_EXTERNAL));
872 bnode = Rooms[r].portals[p].bnode_index;
873 // ASSERT(bnode >= 0 && bnode < BNode_GetBNListPtr(r)->num_nodes);
874 }
875
876 // Add the last room...
877 bool f_ok = BNode_FindPath(cur_room, last_node, bnode, obj->size);
878 ASSERT(f_ok);
879 ASSERT(BNode_PathNumNodes);
880
881 int i;
882 for (i = 0; i < BNode_PathNumNodes; i++) {
883 pos = &bnlist->nodes[BNode_Path[i]].pos;
884 AIPathAddDPathNode(aip, slot, cur_node, pos, cur_room, handle);

Callers 1

AIPathAllocPathFunction · 0.85

Calls 8

BOA_GetNextRoomFunction · 0.85
BNode_GetBNListPtrFunction · 0.85
BNode_FindPathFunction · 0.85
AIPathAddDPathNodeFunction · 0.85
AIPathFreePathFunction · 0.85

Tested by

no test coverage detected