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

Function BNode_FindPath

Descent3/bnode.cpp:212–288  ·  view source on GitHub ↗

Ok to use Highest_room_index offset stuff

Source from the content-addressed store, hash-verified

210
211// Ok to use Highest_room_index offset stuff
212bool BNode_FindPath(int start_room, int i, int j, float rad) {
213 bpq PQPath;
214 int counter;
215 pq_item *start_node = new pq_item(i, -1, 0.0f);
216 pq_item *cur_node;
217 bool f_found = false;
218
219 // mprintf(0, "++++++++++\nFind path from %d to %d in room %d\n", i, j, start_room);
220
221 start_room = BOA_INDEX(start_room);
222
223 pq_item **node_list;
224 bn_list *bnlist = BNode_GetBNListPtr(start_room);
225
226 ASSERT(bnlist);
227 ASSERT(i >= 0 && i < bnlist->num_nodes && j >= 0 && j < bnlist->num_nodes);
228
229 node_list = (pq_item **)mem_malloc(bnlist->num_nodes * sizeof(pq_item *));
230 memset(node_list, 0, bnlist->num_nodes * sizeof(pq_item *));
231
232 PQPath.push(start_node);
233
234 while ((cur_node = PQPath.pop())) {
235 node_list[cur_node->node] = cur_node;
236
237 if (cur_node->node == j) {
238 BNode_UpdatePathInfo(node_list, i, j);
239 f_found = true;
240 goto done;
241 }
242
243 int num_edges;
244
245 num_edges = bnlist->nodes[cur_node->node].num_edges;
246
247 for (counter = 0; counter < num_edges; counter++) {
248 int next_node;
249 pq_item *list_item;
250 float new_cost;
251
252 // if(!BOA_PassablePortal(cur_node->roomnum, counter, false, false))
253 // continue;
254
255 if ((next_node = bnlist->nodes[cur_node->node].edges[counter].end_room != start_room))
256 continue;
257
258 next_node = bnlist->nodes[cur_node->node].edges[counter].end_index;
259
260 ASSERT(bnlist->nodes[cur_node->node].edges[counter].cost > 0);
261 new_cost = cur_node->cost + bnlist->nodes[cur_node->node].edges[counter].cost;
262
263 list_item = node_list[next_node];
264
265 if (list_item != NULL && list_item->cost < new_cost)
266 continue;
267
268 if (list_item == NULL) {
269 list_item = new pq_item(next_node, cur_node->node, new_cost);

Callers 3

EBNode_VerifyGraphFunction · 0.85
AIGenerateAltBNodePathFunction · 0.85
AIGenerateBNodePathFunction · 0.85

Calls 4

BNode_GetBNListPtrFunction · 0.85
BNode_UpdatePathInfoFunction · 0.85
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected