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

Function AIFindAltPath

Descent3/aipath.cpp:64–206  ·  view source on GitHub ↗

Ok to use Highest_room_index offset stuff

Source from the content-addressed store, hash-verified

62
63// Ok to use Highest_room_index offset stuff
64bool AIFindAltPath(object *obj, int i, int j, float *dist) {
65 i = BOA_INDEX(i);
66 j = BOA_INDEX(j);
67
68 pq PQPath;
69 int counter;
70 q_item *start_node = new q_item(i, -1, 0.0f);
71 q_item *cur_node;
72 bool f_found = false;
73
74 q_item *node_list[MAX_ROOMS + 8];
75
76 // mprintf(0, "AI: Finding an alternate path from %d to %d\n", i, j);
77
78 if (i == -1 || j == -1) {
79 delete start_node;
80 return false;
81 }
82
83 memset(node_list, 0, sizeof(q_item *) * (MAX_ROOMS + 8));
84
85 PQPath.push(start_node);
86
87 while ((cur_node = PQPath.pop())) {
88 node_list[BOA_INDEX(cur_node->roomnum)] = cur_node;
89 ASSERT(BOA_INDEX(cur_node->roomnum) >= 0 && BOA_INDEX(cur_node->roomnum) <= Highest_room_index + 8);
90
91 if (cur_node->roomnum == j) {
92 AIUpdatePathInfo(node_list, i, j);
93 f_found = true;
94 goto done;
95 }
96
97 int num_portals;
98 bool f_room = true;
99 int t_index;
100
101 if (cur_node->roomnum <= Highest_room_index) {
102 num_portals = Rooms[cur_node->roomnum].num_portals;
103 } else {
104 t_index = cur_node->roomnum - Highest_room_index - 1;
105 num_portals = BOA_num_connect[t_index];
106 f_room = false;
107 }
108
109 for (counter = 0; counter < num_portals; counter++) {
110 int next_room;
111 q_item *list_item;
112 float new_cost;
113
114 if (!BOA_PassablePortal(cur_node->roomnum, counter, false, false))
115 continue;
116
117 if (f_room)
118 next_room = Rooms[cur_node->roomnum].portals[counter].croom;
119 else
120 next_room = BOA_connect[t_index][counter].roomnum;
121

Callers 5

osipf_AIIsDestReachableFunction · 0.85
osipf_AIIsObjReachableFunction · 0.85
AIFindRoomWithFlagFunction · 0.85
AIFindObjOfTypeFunction · 0.85
AIPathAllocPathFunction · 0.85

Calls 9

AIUpdatePathInfoFunction · 0.85
BOA_PassablePortalFunction · 0.85
GetTerrainCellFromPosFunction · 0.85
TERRAIN_REGIONFunction · 0.85
BOA_LockedDoorFunction · 0.85
ps_randFunction · 0.85
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected