| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/bnode.cpp $ |
| 21 | * $Revision: 23 $ |
| 22 | * $Date: 10/21/99 2:36p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * BOA Helper Node functions |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/bnode.cpp $ |
| 28 | * |
| 29 | * 23 10/21/99 2:36p Matt |
| 30 | * Mac merge |
| 31 | * |
| 32 | * 22 10/08/99 4:27p Chris |
| 33 | * Removed a needless ASSERT |
| 34 | * |
| 35 | * 21 5/20/99 8:09p Chris |
| 36 | * Patched up the bnode crashes |
| 37 | * |
| 38 | * 20 5/19/99 2:40p Chris |
| 39 | * |
| 40 | * 19 5/13/99 4:23p Matt |
| 41 | * Fixed, hopefully, a problem remapping nodes. |
| 42 | * |
| 43 | * 18 5/10/99 10:07p Ardussi |
| 44 | * changes to compile on Mac |
| 45 | * |
| 46 | * 17 5/09/99 11:43p Chris |
| 47 | * Fixed a bug with no generating a random node (worst case for the |
| 48 | * terrain) |
| 49 | * |
| 50 | * 16 5/09/99 5:24p Chris |
| 51 | * Maxed the bnode distance to the AI_SEE distance |
| 52 | * |
| 53 | * 15 5/06/99 5:18p Chris |
| 54 | * Updated the BNode system - vastly improved error checking and verify |
| 55 | * |
| 56 | * 14 5/02/99 6:16a Chris |
| 57 | * Massive bnode error checking improvements |
| 58 | * |
| 59 | * 13 5/01/99 4:06p Jeff |
| 60 | * fixed #include for linux |
| 61 | * |
| 62 | * 12 4/28/99 8:27a Chris |
| 63 | * |
| 64 | * 11 4/28/99 5:33a Chris |
| 65 | * Further improved the BNode system. (It actually works inside and |
| 66 | * outside now) |
| 67 | * |
| 68 | * 10 4/27/99 11:37p Chris |
| 69 | * Improving the BNode system |
| 70 | * |
| 71 | * 9 4/27/99 3:01a Chris |
| 72 | * Improving Bnode stuff |
| 73 | * |
| 74 | * 8 4/26/99 11:11a Chris |
| 75 | * Updated Bnode system |
| 76 | * |
| 77 | * 7 4/25/99 8:57p Chris |
| 78 | * Improving the Bnode system |
| 79 | * |
| 80 | * 6 4/18/99 4:35p Matt |
| 81 | * Changed BNode_FreeRoom() to take a room pointer instead of a room |
| 82 | * number, since it was being called for rooms in the scrap buffer, which |
| 83 | * weren't in the room list. Also added code to InitRoom() to init the |
| 84 | * bnode data. |
| 85 | * |
| 86 | * 5 4/18/99 6:50a Chris |
| 87 | * |
| 88 | * 4 4/18/99 5:39a Chris |
| 89 | * Vastly improved the path node system |
| 90 | * |
| 91 | * 3 4/15/99 5:48p Chris |
| 92 | * Fixed a bug with rendering the BOAPath nodes |
| 93 | * |
| 94 | * 2 4/14/99 3:12p Chris |
| 95 | * Beginning to add BoaNode stuff |
| 96 | * |
| 97 | * $NoKeywords: $ |
| 98 | */ |
| 99 | |
| 100 | |
| 101 | #include "memory.h" |
| 102 | #include "bnode.h"cxx . . $ `<file>/Descent3/bnode.h`/ |
| 103 | #include "room.h"cxx . . $ `<file>/Descent3/room.h`/ |
| 104 | #include "mem.h"cxx . . $ `<file>/mem/mem.h`/ |
| 105 | #include "vecmat.h"cxx . . $ `<file>/lib/vecmat.h`/ |
| 106 | #include "terrain.h"cxx . . $ `<file>/Descent3/terrain.h`/ |
| 107 | #include "room.h"cxx . . $ `<file>/Descent3/room.h`/ |
| 108 | #include "findintersection.h"cxx . . $ `<file>/physics/findintersection.h`/ |
| 109 | #include "BOA.h"cxx . . $ `<file>/Descent3/BOA.h`/ |
| 110 | #include "psrand.h"cxx . . $ `<file>/misc/psrand.h`/ |
| 111 | |
| 112 | bn_listcxx . . $ bn_list# BNode_terrain_listcxx . . $ BNode_terrain_list.[8]; |
| 113 | bool BNode_allocatedcxx . . $ BNode_allocated. = false; |
| 114 | bool BNode_verifiedcxx . . $ BNode_verified. = false; |
| 115 | |
| 116 | //-- Priority Queue |
| 117 | class pq_itemcxx . . $ pq_item# { |
| 118 | public: |
| 119 | pq_itemcxx . . $ pq_item#pq_item(c2f439e40e2f19ed).(int node_index, int parent_node, float n_cost) { |
| 120 | nodecxx . . $ pq_item#node. = node_index; |
| 121 | p_nodecxx . . $ pq_item#p_node. = parent_node; |
| 122 | costcxx . . $ pq_item#cost. = n_cost; |
| 123 | nextcxx . . $ pq_item#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 124 | } |
| 125 | |
| 126 | int nodecxx . . $ pq_item#node.; |
| 127 | int p_nodecxx . . $ pq_item#p_node.; |
| 128 | float costcxx . . $ pq_item#cost.; |
| 129 | |
| 130 | pq_itemcxx . . $ pq_item# *nextcxx . . $ pq_item#next.; |
| 131 | }; |
| 132 | |
| 133 | class bpqcxx . . $ bpq# { |
| 134 | pq_itemcxx . . $ pq_item# *q_headcxx . . $ bpq#q_head.; |
| 135 | |
| 136 | public: |
| 137 | bpqcxx . . $ bpq#bpq(49f6e7a06ebc5aa8).() { q_headcxx . . $ bpq#q_head. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; } |
| 138 | |
| 139 | void pushcxx . . $ bpq#push(fbe0471b53dd2954).(pq_itemcxx . . $ pq_item# *new_node) { |
| 140 | new_node->nextcxx . . $ pq_item#next. = q_headcxx . . $ bpq#q_head.; |
| 141 | q_headcxx . . $ bpq#q_head. = new_node; |
| 142 | } |
| 143 | |
| 144 | pq_itemcxx . . $ pq_item# *popcxx . . $ bpq#pop(e4b3b654327da6e2).() { |
| 145 | pq_itemcxx . . $ pq_item# *cur_item = q_headcxx . . $ bpq#q_head.; |
| 146 | pq_itemcxx . . $ pq_item# *prev_item = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 147 | pq_itemcxx . . $ pq_item# *best_item = q_headcxx . . $ bpq#q_head.; |
| 148 | pq_itemcxx . . $ pq_item# *best_prev_item = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 149 | |
| 150 | if (q_headcxx . . $ bpq#q_head. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 151 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 152 | |
| 153 | while (cur_item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 154 | if (cur_item->costcxx . . $ pq_item#cost. < best_item->costcxx . . $ pq_item#cost.) { |
| 155 | |
| 156 | best_prev_item = prev_item; |
| 157 | best_item = cur_item; |
| 158 | } |
| 159 | |
| 160 | prev_item = cur_item; |
| 161 | cur_item = cur_item->nextcxx . . $ pq_item#next.; |
| 162 | } |
| 163 | |
| 164 | // Actually remove this item from the list |
| 165 | if (best_item == q_headcxx . . $ bpq#q_head.) { |
| 166 | q_headcxx . . $ bpq#q_head. = best_item->nextcxx . . $ pq_item#next.; |
| 167 | } else { |
| 168 | best_prev_item->nextcxx . . $ pq_item#next. = best_item->nextcxx . . $ pq_item#next.; |
| 169 | } |
| 170 | |
| 171 | return best_item; |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | static float BNode_QuickDistcxx . . $ BNode_QuickDist(a0b9c8659ecc16b8).(vectorcxx . . $ vector# *pos1, vectorcxx . . $ vector# *pos2) { |
| 176 | return fabscxx . . $ fabs(fbcf3211dfe1bfd1).(pos1->xcxx . . $ vector#x. - pos2->xcxx . . $ vector#x.) + fabscxx . . $ fabs(fbcf3211dfe1bfd1).(pos1->ycxx . . $ vector#y. - pos2->ycxx . . $ vector#y.) + fabscxx . . $ fabs(fbcf3211dfe1bfd1).(pos1->zcxx . . $ vector#z. - pos2->zcxx . . $ vector#z.); |
| 177 | } |
| 178 | |
| 179 | int BNode_Pathcxx . . $ BNode_Path.[MAX_BNODES_PER_ROOMcxx . . $ `Descent3/bnode.h:80:9`!]; |
| 180 | int BNode_PathNumNodescxx . . $ BNode_PathNumNodes.; |
| 181 | |
| 182 | static void BNode_UpdatePathInfocxx . . $ BNode_UpdatePathInfo(bd6a066f82c8e3e5).(pq_itemcxx . . $ pq_item# **node_list, int start, int end) { |
| 183 | int cur_node = end; |
| 184 | int i; |
| 185 | |
| 186 | BNode_PathNumNodescxx . . $ BNode_PathNumNodes. = 0; |
| 187 | |
| 188 | // mprintf(0, "start crash loop\n"); |
| 189 | while (cur_node != -1) { |
| 190 | BNode_Pathcxx . . $ BNode_Path.[BNode_PathNumNodescxx . . $ BNode_PathNumNodes.++] = cur_node; |
| 191 | cur_node = node_list[cur_node]->p_nodecxx . . $ pq_item#p_node.; |
| 192 | } |
| 193 | // mprintf(0, "end crash loop\n"); |
| 194 | |
| 195 | // Reverse the list (so it is what we want) |
| 196 | for (i = 0; i < (BNode_PathNumNodescxx . . $ BNode_PathNumNodes. >> 1); i++) { |
| 197 | int temp; |
| 198 | |
| 199 | temp = BNode_Pathcxx . . $ BNode_Path.[i]; |
| 200 | BNode_Pathcxx . . $ BNode_Path.[i] = BNode_Pathcxx . . $ BNode_Path.[BNode_PathNumNodescxx . . $ BNode_PathNumNodes. - i - 1]; |
| 201 | BNode_Pathcxx . . $ BNode_Path.[BNode_PathNumNodescxx . . $ BNode_PathNumNodes. - i - 1] = temp; |
| 202 | } |
| 203 | |
| 204 | /* for(i = 0; i < BNode_PathNumNodes; i++) |
| 205 | { |
| 206 | mprintf(0, "Node %d\n", BNode_Path[i]); |
| 207 | } |
| 208 | */ |
| 209 | } |
| 210 | |
| 211 | // Ok to use Highest_room_index offset stuff |
| 212 | bool BNode_FindPathcxx . . $ BNode_FindPath(88bfc9447631a049).(int start_room, int i, int j, float rad) { |
| 213 | bpqcxx . . $ bpq# PQPathcxx . . $ bpq#bpq(49f6e7a06ebc5aa8).; |
| 214 | int counter; |
| 215 | pq_itemcxx . . $ pq_item# *start_node = new pq_itemcxx . . $ pq_item#(i, -1, 0.0f); |
| 216 | pq_itemcxx . . $ 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_INDEXcxx . . $ `Descent3/BOA.h:197:9`!(start_room); |
| 222 | |
| 223 | pq_itemcxx . . $ pq_item# **node_list; |
| 224 | bn_listcxx . . $ bn_list# *bnlist = BNode_GetBNListPtrcxx . . $ BNode_GetBNListPtr(a42128dcaf4239a4).(start_room); |
| 225 | |
| 226 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(bnlist); |
| 227 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(i >= 0 && i < bnlist->num_nodes && j >= 0 && j < bnlist->num_nodes); |
| 228 | |
| 229 | node_list = (pq_itemcxx . . $ pq_item# **)mem_malloccxx . . $ `mem/mem.h:79:9`!(bnlist->num_nodes * sizeof(pq_item *)); |
| 230 | memset(node_list, 0, bnlist->num_nodescxx . . $ bn_list#num_nodes. * sizeof(pq_itemcxx . . $ pq_item# *)); |
| 231 | |
| 232 | PQPath.pushcxx . . $ bpq#push(fbe0471b53dd2954).(start_node); |
| 233 | |
| 234 | while ((cur_node = PQPath.popcxx . . $ bpq#pop(e4b3b654327da6e2).())) { |
| 235 | node_list[cur_node->nodecxx . . $ pq_item#node.] = cur_node; |
| 236 | |
| 237 | if (cur_node->nodecxx . . $ pq_item#node. == j) { |
| 238 | BNode_UpdatePathInfocxx . . $ BNode_UpdatePathInfo(bd6a066f82c8e3e5).(node_list, i, j); |
| 239 | f_found = true; |
| 240 | goto done; |
| 241 | } |
| 242 | |
| 243 | int num_edges; |
| 244 | |
| 245 | num_edges = bnlist->nodescxx . . $ bn_list#nodes.[cur_node->nodecxx . . $ pq_item#node.].num_edgescxx . . $ bn_node#num_edges.; |
| 246 | |
| 247 | for (counter = 0; counter < num_edges; counter++) { |
| 248 | int next_node; |
| 249 | pq_itemcxx . . $ 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->nodescxx . . $ bn_list#nodes.[cur_node->nodecxx . . $ pq_item#node.].edgescxx . . $ bn_node#edges.[counter].end_roomcxx . . $ bn_edge#end_room. != start_room)) |
| 256 | continue; |
| 257 | |
| 258 | next_node = bnlist->nodescxx . . $ bn_list#nodes.[cur_node->nodecxx . . $ pq_item#node.].edgescxx . . $ bn_node#edges.[counter].end_indexcxx . . $ bn_edge#end_index.; |
| 259 | |
| 260 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(bnlist->nodes[cur_node->node].edges[counter].cost > 0); |
| 261 | new_cost = cur_node->costcxx . . $ pq_item#cost. + bnlist->nodescxx . . $ bn_list#nodes.[cur_node->nodecxx . . $ pq_item#node.].edgescxx . . $ bn_node#edges.[counter].costcxx . . $ bn_edge#cost.; |
| 262 | |
| 263 | list_item = node_list[next_node]; |
| 264 | |
| 265 | if (list_item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! && list_item->costcxx . . $ pq_item#cost. < new_cost) |
| 266 | continue; |
| 267 | |
| 268 | if (list_item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 269 | list_item = new pq_itemcxx . . $ pq_item#(next_node, cur_node->nodecxx . . $ pq_item#node., new_cost); |
| 270 | |
| 271 | node_list[next_node] = list_item; |
| 272 | PQPath.pushcxx . . $ bpq#push(fbe0471b53dd2954).(list_item); |
| 273 | } else { |
| 274 | list_item->costcxx . . $ pq_item#cost. = new_cost; |
| 275 | list_item->p_nodecxx . . $ pq_item#p_node. = cur_node->nodecxx . . $ pq_item#node.; |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | done: |
| 281 | for (counter = 0; counter < bnlist->num_nodescxx . . $ bn_list#num_nodes.; counter++) { |
| 282 | if (node_list[counter]) |
| 283 | delete node_list[counter]; |
| 284 | } |
| 285 | |
| 286 | mem_freecxx . . $ `mem/mem.h:80:9`!(node_list); // DAJ LEAKFIX |
| 287 | return f_found; |
| 288 | } |
| 289 | |
| 290 | // TODO: MTS: Unused? |
| 291 | int BNode_GenerateBestPathThroughRoomcxx . . $ BNode_GenerateBestPathThroughRoom(33ce28741e1d1f22).(int sroom, int spnt, int croom, int eroom, int eportal, int max_nodes, |
| 292 | vectorcxx . . $ vector# *pos_list) { |
| 293 | return -1; |
| 294 | } |
| 295 | |
| 296 | static char BNode_viscxx . . $ BNode_vis.[MAX_BNODES_PER_ROOMcxx . . $ `Descent3/bnode.h:80:9`!]; |
| 297 | #define VIS_NO_CHECKcxx . . $ `Descent3/bnode.cpp:297:9`! 2 |
| 298 | #define VIS_OKcxx . . $ `Descent3/bnode.cpp:298:9`! 1 |
| 299 | #define VIS_NOcxx . . $ `Descent3/bnode.cpp:299:9`! 2 |
| 300 | |
| 301 | int BNode_FindDirLocalVisibleBNodecxx . . $ BNode_FindDirLocalVisibleBNode(d2d3175ccbf91b7d).(int roomnum, vectorcxx . . $ vector# *pos, vectorcxx . . $ vector# *fvec, float rad) { |
| 302 | int i; |
| 303 | float best_dot = -1.01f; |
| 304 | float closest_dist = 800.0f; |
| 305 | int closest_node = -1; |
| 306 | bool f_retry = false; |
| 307 | |
| 308 | float min_bn_rad = rad / 4.0f; |
| 309 | if (min_bn_rad > MAX_BNODE_SIZEcxx . . $ `Descent3/bnode.h:78:9`!) { |
| 310 | min_bn_rad = MAX_BNODE_SIZEcxx . . $ `Descent3/bnode.h:78:9`!; |
| 311 | } |
| 312 | |
| 313 | bn_listcxx . . $ bn_list# *bnlist = BNode_GetBNListPtrcxx . . $ BNode_GetBNListPtr(a42128dcaf4239a4).(roomnum); |
| 314 | |
| 315 | retry: |
| 316 | |
| 317 | for (i = 0; i < bnlist->num_nodescxx . . $ bn_list#num_nodes.; i++) { |
| 318 | vectorcxx . . $ vector# to = bnlist->nodescxx . . $ bn_list#nodes.[i].poscxx . . $ bn_node#pos. -cxx . . $ operator-(b77b703cd1e43e33). *pos; |
| 319 | float dist = vm_NormalizeVectorcxx . . $ vm_NormalizeVector(4939a7e530383cd4).(&to); |
| 320 | |
| 321 | if (dist < closest_dist) { |
| 322 | float dot = *fvec *cxx . . $ `operator*`(4a721543d64e126a). to; |
| 323 | |
| 324 | if (dot > 0.0f || f_retry) { |
| 325 | float node_size = 0.0f; |
| 326 | |
| 327 | /* if(!f_retry) |
| 328 | { |
| 329 | for(j = 0; j < bnlist->nodes[i].num_edges; j++) |
| 330 | { |
| 331 | if(bnlist->nodes[i].edges[j].max_rad > node_size) |
| 332 | { |
| 333 | node_size = bnlist->nodes[i].edges[j].max_rad; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | */ |
| 338 | if (!f_retry || (f_retry && BNode_viscxx . . $ BNode_vis.[i] == VIS_NO_CHECKcxx . . $ `Descent3/bnode.cpp:297:9`!)) { |
| 339 | fvi_querycxx . . $ fvi_query# fq; |
| 340 | fvi_infocxx . . $ fvi_info# hit_info; |
| 341 | |
| 342 | fq.p0cxx . . $ fvi_query#p0. = pos; |
| 343 | fq.startroomcxx . . $ fvi_query#startroom. = (roomnum > Highest_room_indexcxx . . $ Highest_room_index. && roomnum <= Highest_room_indexcxx . . $ Highest_room_index. + 8) |
| 344 | ? GetTerrainRoomFromPoscxx . . $ GetTerrainRoomFromPos(177d9005acf670a0).(pos) |
| 345 | : roomnum; |
| 346 | fq.p1cxx . . $ fvi_query#p1. = &bnlist->nodescxx . . $ bn_list#nodes.[i].poscxx . . $ bn_node#pos.; |
| 347 | fq.radcxx . . $ fvi_query#rad. = min_bn_rad; |
| 348 | fq.thisobjnumcxx . . $ fvi_query#thisobjnum. = -1; |
| 349 | fq.ignore_obj_listcxx . . $ fvi_query#ignore_obj_list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 350 | fq.flagscxx . . $ fvi_query#flags. = FQ_CHECK_OBJScxx . . $ `lib/findintersection_external.h:59:9`! | FQ_NO_RELINKcxx . . $ `lib/findintersection_external.h:73:9`! | FQ_IGNORE_NON_LIGHTMAP_OBJECTScxx . . $ `lib/findintersection_external.h:68:9`!; |
| 351 | |
| 352 | if (fvi_FindIntersectioncxx . . $ fvi_FindIntersection(e1c4d7bd350effc8).(&fq, &hit_info) == HIT_NONEcxx . . $ `lib/findintersection_external.h:45:9`!) { |
| 353 | BNode_viscxx . . $ BNode_vis.[i] = VIS_OKcxx . . $ `Descent3/bnode.cpp:298:9`!; |
| 354 | best_dot = dot; |
| 355 | closest_node = i; |
| 356 | } else { |
| 357 | if (!f_retry) { |
| 358 | BNode_viscxx . . $ BNode_vis.[i] = VIS_NOcxx . . $ `Descent3/bnode.cpp:299:9`!; |
| 359 | } else { |
| 360 | if (BNode_viscxx . . $ BNode_vis.[i] == VIS_OKcxx . . $ `Descent3/bnode.cpp:298:9`!) { |
| 361 | closest_node = i; |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | } else { |
| 366 | if (f_retry && BNode_viscxx . . $ BNode_vis.[i] == VIS_OKcxx . . $ `Descent3/bnode.cpp:298:9`!) { |
| 367 | closest_node = i; |
| 368 | } |
| 369 | } |
| 370 | } else { |
| 371 | BNode_viscxx . . $ BNode_vis.[i] = VIS_NO_CHECKcxx . . $ `Descent3/bnode.cpp:297:9`!; |
| 372 | } |
| 373 | } else { |
| 374 | BNode_viscxx . . $ BNode_vis.[i] = VIS_NO_CHECKcxx . . $ `Descent3/bnode.cpp:297:9`!; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (closest_node == -1 && !f_retry) { |
| 379 | f_retry = true; |
| 380 | goto retry; |
| 381 | } |
| 382 | |
| 383 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(bnlist->num_nodes > 0); |
| 384 | if (closest_node == -1 && bnlist->num_nodescxx . . $ bn_list#num_nodes. > 0) { |
| 385 | closest_node = ps_randcxx . . $ ps_rand(b126dc7c1de90089).() % bnlist->num_nodescxx . . $ bn_list#num_nodes.; |
| 386 | } |
| 387 | |
| 388 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(closest_node != -1); |
| 389 | |
| 390 | return closest_node; |
| 391 | } |
| 392 | |
| 393 | int BNode_FindClosestLocalVisibleBNodecxx . . $ BNode_FindClosestLocalVisibleBNode(fadc9d1e831a2875).(int roomnum, vectorcxx . . $ 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_SIZEcxx . . $ `Descent3/bnode.h:78:9`!) { |
| 401 | min_bn_rad = MAX_BNODE_SIZEcxx . . $ `Descent3/bnode.h:78:9`!; |
| 402 | } |
| 403 | |
| 404 | bn_listcxx . . $ bn_list# *bnlist = BNode_GetBNListPtrcxx . . $ BNode_GetBNListPtr(a42128dcaf4239a4).(roomnum); |
| 405 | |
| 406 | retry: |
| 407 | |
| 408 | for (i = 0; i < bnlist->num_nodescxx . . $ bn_list#num_nodes.; i++) { |
| 409 | float dist = BNode_QuickDistcxx . . $ BNode_QuickDist(a0b9c8659ecc16b8).(&bnlist->nodescxx . . $ bn_list#nodes.[i].poscxx . . $ bn_node#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->nodescxx . . $ bn_list#nodes.[i].num_edgescxx . . $ bn_node#num_edges.; j++) { |
| 416 | if (bnlist->nodescxx . . $ bn_list#nodes.[i].edgescxx . . $ bn_node#edges.[j].max_radcxx . . $ bn_edge#max_rad. > node_size) { |
| 417 | node_size = bnlist->nodescxx . . $ bn_list#nodes.[i].edgescxx . . $ bn_node#edges.[j].max_radcxx . . $ bn_edge#max_rad.; |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if (f_retry || node_size >= min_bn_rad) { |
| 423 | fvi_querycxx . . $ fvi_query# fq; |
| 424 | fvi_infocxx . . $ fvi_info# hit_info; |
| 425 | |
| 426 | if (!f_retry) { |
| 427 | fq.p0cxx . . $ fvi_query#p0. = pos; |
| 428 | fq.startroomcxx . . $ fvi_query#startroom. = (roomnum > Highest_room_indexcxx . . $ Highest_room_index. && roomnum <= Highest_room_indexcxx . . $ Highest_room_index. + 8) |
| 429 | ? GetTerrainRoomFromPoscxx . . $ GetTerrainRoomFromPos(177d9005acf670a0).(pos) |
| 430 | : roomnum; |
| 431 | fq.p1cxx . . $ fvi_query#p1. = &bnlist->nodescxx . . $ bn_list#nodes.[i].poscxx . . $ bn_node#pos.; |
| 432 | fq.radcxx . . $ fvi_query#rad. = min_bn_rad; |
| 433 | fq.thisobjnumcxx . . $ fvi_query#thisobjnum. = -1; |
| 434 | fq.ignore_obj_listcxx . . $ fvi_query#ignore_obj_list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 435 | fq.flagscxx . . $ fvi_query#flags. = 0; |
| 436 | } |
| 437 | |
| 438 | if (f_retry || fvi_FindIntersectioncxx . . $ fvi_FindIntersection(e1c4d7bd350effc8).(&fq, &hit_info) == HIT_NONEcxx . . $ `lib/findintersection_external.h:45:9`!) { |
| 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 | |
| 451 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(bnlist->num_nodes > 0); |
| 452 | if (closest_node == -1 && bnlist->num_nodescxx . . $ bn_list#num_nodes. > 0) { |
| 453 | closest_node = ps_randcxx . . $ ps_rand(b126dc7c1de90089).() % bnlist->num_nodescxx . . $ bn_list#num_nodes.; |
| 454 | } |
| 455 | |
| 456 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(closest_node != -1); |
| 457 | |
| 458 | return closest_node; |
| 459 | } |
| 460 | |
| 461 | bn_listcxx . . $ bn_list# *BNode_GetBNListPtrcxx . . $ BNode_GetBNListPtr(a42128dcaf4239a4).(int roomnum, bool f_in_load_level) { |
| 462 | if (roomnum == -1) { |
| 463 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 464 | } else if (roomnum >= 0 && roomnum <= Highest_room_indexcxx . . $ Highest_room_index.) { |
| 465 | // if(!f_in_load_level) |
| 466 | // { |
| 467 | // ASSERT(!(Rooms[roomnum].flags & RF_EXTERNAL)); |
| 468 | // } |
| 469 | |
| 470 | if (!Roomscxx . . $ Rooms.[roomnum].usedcxx . . $ room#used.) { |
| 471 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 472 | } |
| 473 | |
| 474 | roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[roomnum]; |
| 475 | return &rp->bn_infocxx . . $ room#bn_info.; |
| 476 | } else if (ROOMNUM_OUTSIDEcxx . . $ `lib/object_external_struct.h:127:9`!(roomnum)) { |
| 477 | return &BNode_terrain_listcxx . . $ BNode_terrain_list.[TERRAIN_REGIONcxx . . $ TERRAIN_REGION(7864480464b09eea).(roomnum)]; |
| 478 | } else if (roomnum <= Highest_room_indexcxx . . $ Highest_room_index. + 8) { |
| 479 | return &BNode_terrain_listcxx . . $ BNode_terrain_list.[roomnum - Highest_room_indexcxx . . $ Highest_room_index. - 1]; |
| 480 | } |
| 481 | |
| 482 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 483 | } |
| 484 | |
| 485 | void BNode_ClearBNodeInfocxx . . $ BNode_ClearBNodeInfo(49f6e7a06ebc5aa8).(void) { |
| 486 | int i, j; |
| 487 | |
| 488 | for (i = 0; i < 8; i++) { |
| 489 | if (BNode_allocatedcxx . . $ BNode_allocated.) { |
| 490 | for (j = 0; j < BNode_terrain_listcxx . . $ BNode_terrain_list.[i].num_nodescxx . . $ bn_list#num_nodes.; j++) { |
| 491 | if (BNode_terrain_listcxx . . $ BNode_terrain_list.[i].nodescxx . . $ bn_list#nodes.[j].num_edgescxx . . $ bn_node#num_edges.) { |
| 492 | mem_freecxx . . $ `mem/mem.h:80:9`!(BNode_terrain_list[i].nodes[j].edges); |
| 493 | } |
| 494 | } |
| 495 | mem_freecxx . . $ `mem/mem.h:80:9`!(BNode_terrain_list[i].nodes); |
| 496 | } |
| 497 | |
| 498 | BNode_terrain_listcxx . . $ BNode_terrain_list.[i].num_nodescxx . . $ bn_list#num_nodes. = 0; |
| 499 | BNode_terrain_listcxx . . $ BNode_terrain_list.[i].nodescxx . . $ bn_list#nodes. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 500 | } |
| 501 | |
| 502 | BNode_allocatedcxx . . $ BNode_allocated. = false; |
| 503 | BNode_verifiedcxx . . $ BNode_verified. = false; |
| 504 | } |
| 505 | |
| 506 | // Unused? |
| 507 | bool BNode_MakeSubPathcxx . . $ BNode_MakeSubPath(3f0e138fc249eae5).(int16_tcxx . . $ int16_t# sroom, int16_tcxx . . $ int16_t# spnt, int16_tcxx . . $ int16_t# eroom, int16_tcxx . . $ int16_t# epnt, int flags, float size, int16_tcxx . . $ int16_t# *roomlist, |
| 508 | int16_tcxx . . $ int16_t# *pnts, int max_elements) { |
| 509 | return false; |
| 510 | } |
| 511 | |
| 512 | void BNode_FreeRoomcxx . . $ BNode_FreeRoom(cd8c4e8cd0ee4c38).(roomcxx . . $ room# *rp) { |
| 513 | int i; |
| 514 | |
| 515 | for (i = 0; i < rp->bn_infocxx . . $ room#bn_info..num_nodescxx . . $ bn_list#num_nodes.; i++) { |
| 516 | if (rp->bn_infocxx . . $ room#bn_info..nodescxx . . $ bn_list#nodes.[i].num_edgescxx . . $ bn_node#num_edges.) { |
| 517 | mem_freecxx . . $ `mem/mem.h:80:9`!(rp->bn_info.nodes[i].edges); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | if (rp->bn_infocxx . . $ room#bn_info..num_nodescxx . . $ bn_list#num_nodes.) { |
| 522 | mem_freecxx . . $ `mem/mem.h:80:9`!(rp->bn_info.nodes); |
| 523 | rp->bn_infocxx . . $ room#bn_info..nodescxx . . $ bn_list#nodes. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 524 | rp->bn_infocxx . . $ room#bn_info..num_nodescxx . . $ bn_list#num_nodes. = 0; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | void BNode_RemapTerrainRoomscxx . . $ BNode_RemapTerrainRooms(3e454b8ccf442868).(int old_hri, int new_hri) { |
| 529 | int delta = new_hri - old_hri; |
| 530 | int i; |
| 531 | |
| 532 | if (!BNode_allocatedcxx . . $ BNode_allocated.) |
| 533 | return; |
| 534 | |
| 535 | if (delta == 0) |
| 536 | return; |
| 537 | |
| 538 | if (new_hri < 0) |
| 539 | return; |
| 540 | |
| 541 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(delta <= 1); |
| 542 | |
| 543 | for (i = 0; i <= new_hri + BOA_num_terrain_regionscxx . . $ BOA_num_terrain_regions.; i++) { |
| 544 | |
| 545 | if ((i <= new_hri && Roomscxx . . $ Rooms.[i].usedcxx . . $ room#used.) || (i > new_hri)) { |
| 546 | int j; |
| 547 | int k; |
| 548 | |
| 549 | // Skip external rooms |
| 550 | if ((i <= new_hri) && (Roomscxx . . $ Rooms.[i].flagscxx . . $ room#flags. & RF_EXTERNALcxx . . $ `Descent3/room_external.h:177:9`!)) |
| 551 | continue; |
| 552 | |
| 553 | bn_listcxx . . $ bn_list# *bnlist = BNode_GetBNListPtrcxx . . $ BNode_GetBNListPtr(a42128dcaf4239a4).(i); |
| 554 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(bnlist); |
| 555 | |
| 556 | for (j = 0; j < bnlist->num_nodescxx . . $ bn_list#num_nodes.; j++) { |
| 557 | for (k = 0; k < bnlist->nodescxx . . $ bn_list#nodes.[j].num_edgescxx . . $ bn_node#num_edges.; k++) { |
| 558 | if (bnlist->nodescxx . . $ bn_list#nodes.[j].edgescxx . . $ bn_node#edges.[k].end_roomcxx . . $ bn_edge#end_room. >= new_hri) { |
| 559 | bnlist->nodescxx . . $ bn_list#nodes.[j].edgescxx . . $ bn_node#edges.[k].end_roomcxx . . $ bn_edge#end_room. += delta; |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | } |