| 666 | } |
| 667 | |
| 668 | static bool AIGenerateAltBNodePath(object *obj, vector *start_pos, int *start_room, vector *end_pos, int *end_room, |
| 669 | ai_path_info *aip, int *slot, int *cur_node, int handle) { |
| 670 | int x; |
| 671 | vector *pos; |
| 672 | bool f_path_exists = true; |
| 673 | |
| 674 | bn_list *bnlist = BNode_GetBNListPtr(*start_room); |
| 675 | int last_node = BNode_FindDirLocalVisibleBNode(*start_room, start_pos, &obj->orient.fvec, obj->size); |
| 676 | if (last_node == -1) { |
| 677 | f_path_exists = false; |
| 678 | goto done; |
| 679 | } |
| 680 | ASSERT(last_node >= 0); |
| 681 | |
| 682 | for (x = 0; x < AIAltPathNumNodes - 1 && f_path_exists; x++) { |
| 683 | int cur_room = BOA_INDEX(AIAltPath[x]); |
| 684 | int next_room = BOA_INDEX(AIAltPath[x + 1]); |
| 685 | |
| 686 | bnlist = BNode_GetBNListPtr(cur_room); |
| 687 | ASSERT(bnlist); |
| 688 | |
| 689 | if (next_room != cur_room && next_room != BOA_NO_PATH) { |
| 690 | int portal = BOA_DetermineStartRoomPortal(cur_room, NULL, next_room, NULL); |
| 691 | if (portal == -1) { |
| 692 | f_path_exists = false; |
| 693 | } else { |
| 694 | int bnode = -1; |
| 695 | |
| 696 | if (cur_room >= 0 && cur_room <= Highest_room_index) { |
| 697 | bnode = Rooms[cur_room].portals[portal].bnode_index; |
| 698 | ASSERT(bnode >= 0 && bnode < BNode_GetBNListPtr(cur_room)->num_nodes); |
| 699 | } else { |
| 700 | int croom = BOA_connect[cur_room - Highest_room_index - 1][portal].roomnum; |
| 701 | int cportal = BOA_connect[cur_room - Highest_room_index - 1][portal].portal; |
| 702 | |
| 703 | int r = Rooms[croom].portals[cportal].croom; |
| 704 | int p = Rooms[croom].portals[cportal].cportal; |
| 705 | |
| 706 | ASSERT(Rooms[r].used && (Rooms[r].flags & RF_EXTERNAL)); |
| 707 | bnode = Rooms[r].portals[p].bnode_index; |
| 708 | // ASSERT(bnode >= 0 && bnode < BNode_GetBNListPtr(r)->num_nodes); |
| 709 | } |
| 710 | |
| 711 | // Add the last room... |
| 712 | bool f_ok = BNode_FindPath(cur_room, last_node, bnode, obj->size); |
| 713 | ASSERT(f_ok); |
| 714 | ASSERT(BNode_PathNumNodes); |
| 715 | |
| 716 | int i; |
| 717 | for (i = 0; i < BNode_PathNumNodes; i++) { |
| 718 | pos = &bnlist->nodes[BNode_Path[i]].pos; |
| 719 | AIPathAddDPathNode(aip, slot, cur_node, pos, cur_room, handle); |
| 720 | } |
| 721 | |
| 722 | int portal = BOA_DetermineStartRoomPortal(next_room, NULL, cur_room, NULL); |
| 723 | if (next_room <= Highest_room_index) { |
| 724 | bnode = Rooms[next_room].portals[portal].bnode_index; |
| 725 | ASSERT(bnode >= 0); |
no test coverage detected