Debian Codegraph @

editor/ebnode.cpp

raw
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/editor/ebnode.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:37 $
23 * $Author: kevinb $
24 *
25 * BOA Helper Node functions
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 35 10/24/99 7:27p Chris
30 *
31 * 34 10/24/99 7:22p Chris
32 *
33 * 33 10/24/99 5:19p Chris
34 *
35 * 32 9/03/99 10:02a Gwar
36 * use special version of the verify graph function for NEWEDITOR (outputs
37 * error info to a list dialog)
38 *
39 * 31 8/25/99 4:57p Gwar
40 * added a way to select bnodes by clicking on them in the 3D views (for
41 * NEWEDITOR)
42 *
43 * 30 8/20/99 4:26a Gwar
44 * made EBNode_Draw use correct room number in NEWEDITOR
45 *
46 * 29 5/21/99 4:14p Chris
47 * Improved verify
48 *
49 * 28 5/18/99 10:55p Chris
50 * Improved the Bnode verification process
51 *
52 * 27 5/08/99 10:46p Chris
53 * Default to not draw bnodes in the editor
54 *
55 * 26 5/06/99 5:18p Chris
56 * Updated the BNode system - vastly improved error checking and verify
57 *
58 * 25 5/06/99 3:10p Chris
59 * More mprintf in verify
60 *
61 * 23 5/02/99 11:30p Chris
62 *
63 * 22 5/02/99 8:20a Chris
64 * Increased the min edge size
65 *
66 * 21 5/02/99 6:48a Chris
67 * Got rid of zero length edges
68 *
69 * 20 5/02/99 6:16a Chris
70 * Massive bnode error checking improvements
71 *
72 * 19 5/02/99 6:05a Chris
73 *
74 * 18 5/02/99 6:02a Chris
75 *
76 * 17 5/02/99 5:57a Chris
77 *
78 * 16 5/02/99 5:56a Chris
79 *
80 * 15 5/02/99 5:19a Chris
81 * Vastly improved verify...
82 *
83 * 14 5/01/99 3:40p Chris
84 * TOO_SMALL_FOR_ROBOT_PORTALS ARE THROWN OUT
85 *
86 * 13 4/29/99 10:16a Chris
87 * Blocked portals where only being removed from the bnode list if they
88 * where rendered! (Oops)
89 *
90 * 12 4/29/99 1:59a Chris
91 * Added the portal blockage support
92 *
93 * 11 4/28/99 9:17a Chris
94 * Moving nodes now updates edge max_sizes
95 *
96 * 10 4/28/99 9:06a Chris
97 * Improved the first pass of the BNodes
98 *
99 * 9 4/27/99 11:37p Chris
100 * Improving the BNode system
101 *
102 * 8 4/27/99 3:01a Chris
103 * Improving Bnode stuff
104 *
105 * 7 4/26/99 10:31p Chris
106 * Improving the BNode system
107 *
108 * 6 4/26/99 11:11a Chris
109 * Updated Bnode system
110 *
111 * 5 4/25/99 9:02p Chris
112 * Improving the Bnode system
113 *
114 * 4 4/18/99 5:39a Chris
115 * Vastly improved the path node system
116 *
117 * 3 4/15/99 5:49p Chris
118 * Fixed a bug with rendering the BOAPath nodes
119 *
120 * 2 4/14/99 3:13p Chris
121 * Beginning to add BoaNode stuff
122 *
123 * $NoKeywords: $
124 */
125
126 #ifdef NEWEDITOR
127 #include "neweditor/stdafx.h"
128 #include "neweditor/NewEditor.h"
129 #endif
130
131 #include "bnode.h"
132 #include "room.h"
133 #include "mem.h"
134 #include "memory.h"
135 #include "vecmat.h"
136 #include "object.h"
137 #include "3d.h"
138 #include "ebnode.h"
139 #include "findintersection.h"
140 #include "pserror.h"
141 #include "terrain.h"
142 #include "boa.h"
143 #include "aimain.h"
144
145 char EBN_draw_type = EBDRAW_NONE;
146 #define EBN_MAX_NEXT_ROOMS 200
147
148 #define BNODE_VERY_CLOSE_DIST 5.0f
149
150 bool EBNode_VerifyGraph() {
151 bool f_verified = true;
152 int i;
153 int j;
154 int k;
155
156 if (!BNode_allocated) {
157 mprintf(0, "EBNode Verify: No BNodes for this level\n");
158 return false;
159 }
160
161 MakeBOA();
162
163 for (i = Highest_room_index + 1; i <= Highest_room_index + BOA_num_terrain_regions; i++) {
164 bn_list *nlist;
165 nlist = BNode_GetBNListPtr(i);
166 int cur_region = i - Highest_room_index - 1;
167
168 for (j = nlist->num_nodes - 1; j >= 0; j--) {
169 int cell = GetTerrainRoomFromPos(&nlist->nodes[j].pos);
170 if (cur_region != TERRAIN_REGION(cell)) {
171 for (k = 0; k < nlist->nodes[j].num_edges; k++) {
172 if (BOA_INDEX(nlist->nodes[j].edges[k].end_room) >= 0 &&
173 BOA_INDEX(nlist->nodes[j].edges[k].end_room) <= Highest_room_index) {
174 int r = nlist->nodes[j].edges[k].end_room;
175 int p = nlist->nodes[j].edges[k].end_index;
176
177 int x;
178 for (x = 0; x < Rooms[r].num_portals; x++) {
179 if (Rooms[r].portals[x].bnode_index == p) {
180 int cr = Rooms[r].portals[x].croom;
181 int cp = Rooms[r].portals[x].cportal;
182
183 Rooms[cr].portals[cp].bnode_index = -1;
184 }
185 }
186 }
187 }
188
189 EBNode_RemoveNode(i, j);
190 }
191 }
192 }
193
194 for (i = 0; i <= Highest_room_index + BOA_num_terrain_regions; i++) {
195 bn_list *nlist;
196 int j;
197 int k;
198
199 if (i >= 0 && i <= Highest_room_index && !Rooms[i].used)
200 continue;
201
202 if (i <= Highest_room_index && (Rooms[i].flags & RF_EXTERNAL))
203 continue;
204
205 nlist = BNode_GetBNListPtr(i);
206
207 for (j = 0; j < nlist->num_nodes; j++) {
208 for (k = 0; k < nlist->nodes[j].num_edges; k++) {
209 if (nlist->nodes[j].edges[k].max_rad < 5.0f) {
210 mprintf(0, "EBNode Verify: Removed a skinny edge.\n");
211 EBNode_RemoveEdge(j, i, nlist->nodes[j].edges[k].end_index, nlist->nodes[j].edges[k].end_room);
212 k--;
213 }
214 }
215 }
216 }
217
218 // Bash invalid nodes
219 for (i = 0; i <= Highest_room_index; i++) {
220 if (Rooms[i].used) {
221 room *rp = &Rooms[i];
222
223 if (i <= Highest_room_index && (Rooms[i].flags & RF_EXTERNAL))
224 continue;
225
226 for (j = 0; j < Rooms[i].num_portals; j++) {
227 if (Rooms[i].portals[j].bnode_index >= 0 && Rooms[i].portals[j].bnode_index >= Rooms[i].bn_info.num_nodes) {
228 mprintf(0, "EBNode: Bashed an invalid node\n");
229 Rooms[i].portals[j].bnode_index = -1;
230 } else if (Rooms[i].portals[j].bnode_index < 0) {
231 room *rp = &Rooms[i];
232 bool f_add = true;
233
234 if (!((rp->portals[j].flags & PF_BLOCK) && !(rp->portals[j].flags & PF_BLOCK_REMOVABLE))) {
235 f_add = false;
236 }
237
238 if ((rp->portals[j].flags & PF_RENDER_FACES) && !(rp->portals[j].flags & PF_RENDERED_FLYTHROUGH)) {
239 if (!(GameTextures[rp->faces[rp->portals[j].portal_face].tmap].flags & (TF_BREAKABLE | TF_FORCEFIELD))) {
240 f_add = false;
241 }
242 }
243
244 if (rp->portals[j].flags & PF_TOO_SMALL_FOR_ROBOT) {
245 f_add = false;
246 }
247
248 if (f_add) {
249 vector pos;
250 pos = rp->portals[j].path_pnt + rp->faces[rp->portals[j].portal_face].normal * 0.75f;
251 rp->portals[j].bnode_index = EBNode_AddNode(i, &pos, false, false);
252 mprintf(0, "EBNode Verify: Added a portal node\n");
253 }
254 }
255 }
256 }
257 }
258
259 int region;
260 for (region = 0; region < BOA_num_terrain_regions; region++) {
261 for (i = 0; i < BOA_num_connect[region]; i++) {
262 int end_room = BOA_connect[region][i].roomnum;
263 room *rp = &Rooms[end_room];
264 int p = BOA_connect[region][i].portal;
265
266 vector pos;
267 pos = rp->portals[p].path_pnt - rp->faces[rp->portals[p].portal_face].normal * 0.75f;
268
269 int external_room = rp->portals[p].croom;
270 int external_portal = rp->portals[p].cportal;
271 ASSERT(Rooms[external_room].flags & RF_EXTERNAL);
272
273 if (Rooms[external_room].portals[external_portal].bnode_index < 0) {
274 Rooms[external_room].portals[external_portal].bnode_index =
275 EBNode_AddNode(Highest_room_index + region + 1, &pos, false, false);
276 if (Rooms[end_room].portals[p].bnode_index >= 0)
277 EBNode_AddEdge(Rooms[external_room].portals[external_portal].bnode_index, Highest_room_index + region + 1,
278 Rooms[end_room].portals[p].bnode_index, end_room);
279 }
280 }
281 }
282
283 for (i = 0; i <= Highest_room_index; i++) {
284 if (Rooms[i].used) {
285 room *rp = &Rooms[i];
286 if (i <= Highest_room_index && (Rooms[i].flags & RF_EXTERNAL))
287 continue;
288
289 for (j = 0; j < Rooms[i].num_portals; j++) {
290 if ((Rooms[i].portals[j].flags & PF_BLOCK) && !(Rooms[i].portals[j].flags & PF_BLOCK_REMOVABLE)) {
291 if (Rooms[i].portals[j].bnode_index >= 0) {
292 mprintf(0, "EBNode Verify: Removed a node.\n");
293 EBNode_RemoveNode(i, Rooms[i].portals[j].bnode_index);
294 }
295 continue;
296 }
297
298 if ((Rooms[i].portals[j].flags & PF_RENDER_FACES) && !(Rooms[i].portals[j].flags & PF_RENDERED_FLYTHROUGH)) {
299 if (!(GameTextures[Rooms[i].faces[Rooms[i].portals[j].portal_face].tmap].flags &
300 (TF_BREAKABLE | TF_FORCEFIELD))) {
301 if (Rooms[i].portals[j].bnode_index >= 0) {
302 mprintf(0, "EBNode Verify: Removed a node.\n");
303 EBNode_RemoveNode(i, Rooms[i].portals[j].bnode_index);
304 }
305 continue;
306 }
307 }
308
309 if (Rooms[i].portals[j].flags & PF_TOO_SMALL_FOR_ROBOT) {
310 if (Rooms[i].portals[j].bnode_index >= 0) {
311 mprintf(0, "EBNode Verify: Removed a node.\n");
312 EBNode_RemoveNode(i, Rooms[i].portals[j].bnode_index);
313 }
314 continue;
315 }
316
317 if (Rooms[i].portals[j].bnode_index < 0) {
318 if (Rooms[i].flags & RF_EXTERNAL) {
319 int cr = rp->portals[j].croom;
320 int ci = Rooms[cr].portals[rp->portals[j].cportal].bnode_index;
321
322 if (Rooms[cr].flags & RF_EXTERNAL) {
323 continue;
324 }
325
326 vector pos;
327 pos = rp->portals[j].path_pnt + rp->faces[rp->portals[j].portal_face].normal * 0.75f;
328 int roomnum = BOA_INDEX(GetTerrainRoomFromPos(&pos));
329
330 int xxx;
331 for (xxx = 0; xxx < BOA_num_connect[TERRAIN_REGION(roomnum)]; xxx++) {
332 if (BOA_connect[TERRAIN_REGION(roomnum)][xxx].roomnum == cr &&
333 BOA_connect[TERRAIN_REGION(roomnum)][xxx].portal == rp->portals[j].cportal) {
334 break;
335 }
336 }
337
338 if (xxx >= BOA_num_connect[TERRAIN_REGION(roomnum)]) {
339 mprintf(0, "EBNode Verify: External room isn't in terrain region list\n");
340 f_verified = false;
341 continue;
342 }
343
344 rp->portals[j].bnode_index = EBNode_AddNode(roomnum, &pos, false, false);
345 ASSERT(rp->portals[j].bnode_index >= 0);
346 EBNode_AutoEdgeNode(rp->portals[j].bnode_index, roomnum);
347 mprintf(0, "EBNode Verify: Added a node and autoedged it.\n");
348
349 if (ci >= 0) {
350 EBNode_AddEdge(rp->portals[j].bnode_index, roomnum, ci, cr);
351 }
352 } else {
353 vector pos;
354 pos = rp->portals[j].path_pnt + rp->faces[rp->portals[j].portal_face].normal * 0.75f;
355 rp->portals[j].bnode_index = EBNode_AddNode(i, &pos, false, false);
356 ASSERT(rp->portals[j].bnode_index >= 0);
357 EBNode_AutoEdgeNode(rp->portals[j].bnode_index, i);
358 mprintf(0, "EBNode Verify: Added a node and autoedged it.\n");
359
360 int cr = rp->portals[j].croom;
361 int ci = Rooms[cr].portals[rp->portals[j].cportal].bnode_index;
362
363 if (ci < 0) {
364 continue;
365 }
366
367 if (Rooms[cr].flags & RF_EXTERNAL) {
368 vector pos;
369 pos = rp->portals[j].path_pnt - rp->faces[rp->portals[j].portal_face].normal * 0.75f;
370 int roomnum = BOA_INDEX(GetTerrainRoomFromPos(&pos));
371
372 EBNode_AddEdge(rp->portals[j].bnode_index, i, ci, roomnum);
373 } else {
374 if (ci >= 0) {
375 EBNode_AddEdge(rp->portals[j].bnode_index, i, ci, cr);
376 }
377 }
378 }
379 }
380 }
381 }
382 }
383
384 for (i = 0; i <= Highest_room_index + BOA_num_terrain_regions; i++) {
385 bn_list *nlist;
386 int j;
387 int k;
388
389 if (i >= 0 && i <= Highest_room_index && !Rooms[i].used)
390 continue;
391
392 if (i >= 0 && i <= Highest_room_index && (Rooms[i].flags & RF_EXTERNAL))
393 continue;
394
395 nlist = BNode_GetBNListPtr(i);
396
397 for (j = 0; j < nlist->num_nodes; j++) {
398 for (k = 0; k < nlist->nodes[j].num_edges; k++) {
399 if (nlist->nodes[j].edges[k].max_rad < 5.0f) {
400 mprintf(0, "EBNode Verify: Removed a skinny edge.\n");
401 EBNode_RemoveEdge(j, i, nlist->nodes[j].edges[k].end_index, nlist->nodes[j].edges[k].end_room);
402 k--;
403 }
404 }
405
406 for (k = 0; k < nlist->nodes[j].num_edges; k++) {
407 if (nlist->nodes[j].edges[k].end_room <= Highest_room_index && !Rooms[nlist->nodes[j].edges[k].end_room].used) {
408 mprintf(0, "EBNode Verify: Removed a edge to a non-existant room. Room %d, node %d, edge %d\n", i, j, k);
409 EBNode_RemoveEdge(j, i, nlist->nodes[j].edges[k].end_index, nlist->nodes[j].edges[k].end_room);
410 k--;
411 }
412 }
413 }
414 }
415
416 for (i = 0; i <= Highest_room_index + BOA_num_terrain_regions; i++) {
417 bn_list *nlist;
418 int j;
419 int k;
420
421 if (i >= 0 && i <= Highest_room_index && !Rooms[i].used)
422 continue;
423
424 if (i >= 0 && i <= Highest_room_index && (Rooms[i].flags & RF_EXTERNAL))
425 continue;
426
427 nlist = BNode_GetBNListPtr(i);
428
429 for (j = 0; j < nlist->num_nodes; j++) {
430 for (k = 0; k < nlist->nodes[j].num_edges; k++) {
431 if (nlist->nodes[j].edges[k].max_rad < 5.0f) {
432 mprintf(0, "Skinny Edge - from r%d n%d to r%d n%d\n", i, j, nlist->nodes[j].edges[k].end_room,
433 nlist->nodes[j].edges[k].end_index);
434 f_verified = false;
435 }
436 }
437 }
438 }
439
440 for (i = 0; i <= Highest_room_index + BOA_num_terrain_regions; i++) {
441 if (i >= 0 && i <= Highest_room_index && !Rooms[i].used)
442 continue;
443
444 if (i >= 0 && i <= Highest_room_index && (Rooms[i].flags & RF_EXTERNAL))
445 continue;
446
447 bn_list *nlist = BNode_GetBNListPtr(i);
448 ASSERT(nlist);
449
450 for (j = 0; j < nlist->num_nodes; j++) {
451 for (k = j + 1; k < nlist->num_nodes; k++) {
452 if (!BNode_FindPath(i, j, k, 0.0f)) {
453 mprintf(0, "BNODE ERROR: No path from %d to %d in room %d\n", j + 1, k + 1, i);
454 f_verified = false;
455 }
456 }
457 }
458 }
459
460 BNode_verified = f_verified;
461
462 if (f_verified)
463 mprintf(0, "EBNode: VERIFY OK!\n");
464 else
465 mprintf(0, "EBNode: VERIFY FAILED!\n");
466
467 return f_verified;
468 }
469
470 void EBNode_ClearLevel() {
471 int i, j;
472
473 for (i = 0; i <= Highest_room_index + BOA_num_terrain_regions; i++) {
474 if (i >= 0 && i <= Highest_room_index) {
475 if (!Rooms[i].used) {
476 continue;
477 } else {
478 int j;
479
480 for (j = 0; j < Rooms[i].num_portals; j++) {
481 Rooms[i].portals[j].bnode_index = -1;
482 }
483 }
484 }
485
486 bn_list *nlist;
487 nlist = BNode_GetBNListPtr(i);
488
489 ASSERT(nlist);
490
491 for (j = nlist->num_nodes - 1; j >= 0; j--) {
492 if (nlist->nodes[j].edges) {
493 mem_free(nlist->nodes[j].edges);
494 }
495 nlist->nodes[j].edges = NULL;
496 nlist->nodes[j].num_edges = 0;
497 }
498
499 if (nlist->nodes) {
500 mem_free(nlist->nodes);
501 }
502 nlist->nodes = NULL;
503 nlist->num_nodes = 0;
504 }
505
506 BNode_allocated = false;
507 BNode_verified = false;
508 }
509
510 void RemapEdgeNodesEqualAndAbove(int croom, int sroom, int spnt) {
511 int i;
512 int j;
513
514 bn_list *cnlist;
515 cnlist = BNode_GetBNListPtr(croom);
516 if (!cnlist)
517 return;
518
519 for (i = 0; i < cnlist->num_nodes; i++) {
520 for (j = 0; j < cnlist->nodes[i].num_edges; j++) {
521 if (cnlist->nodes[i].edges[j].end_room == sroom && cnlist->nodes[i].edges[j].end_index >= spnt) {
522 // The assert is because all these edges should have been deleted!
523 ASSERT(cnlist->nodes[i].edges[j].end_index != spnt);
524 cnlist->nodes[i].edges[j].end_index--;
525 }
526 }
527 }
528 }
529
530 void RemapPortalNodeIndices(int roomnum, int pnt) {
531 int i;
532
533 if (roomnum >= 0 && roomnum <= Highest_room_index) {
534 ASSERT(Rooms[roomnum].used);
535
536 for (i = 0; i < Rooms[roomnum].num_portals; i++) {
537 if (Rooms[roomnum].portals[i].bnode_index == pnt) {
538 Rooms[roomnum].portals[i].bnode_index = -1;
539 } else if (Rooms[roomnum].portals[i].bnode_index > pnt) {
540 Rooms[roomnum].portals[i].bnode_index--;
541 }
542 }
543 } else {
544 int region = BOA_INDEX(roomnum) - Highest_room_index - 1;
545
546 for (i = 0; i < BOA_num_connect[region]; i++) {
547 int r = BOA_connect[region][i].roomnum;
548 int p = BOA_connect[region][i].portal;
549
550 int cr = Rooms[r].portals[p].croom;
551 int cp = Rooms[r].portals[p].cportal;
552
553 vector pos = Rooms[cr].portals[cp].path_pnt + Rooms[cr].faces[Rooms[cr].portals[cp].portal_face].normal * 0.75f;
554 int cell = GetTerrainRoomFromPos(&pos);
555
556 if (region == TERRAIN_REGION(cell) && Rooms[cr].portals[cp].bnode_index == pnt) {
557 Rooms[cr].portals[cp].bnode_index = -1;
558 }
559 }
560 }
561 }
562
563 void EBNode_RemoveNode(int roomnum, int pnt) {
564 int i;
565
566 BNode_verified = false;
567
568 bn_list *nlist;
569 nlist = BNode_GetBNListPtr(roomnum);
570 if (!nlist)
571 return;
572
573 ASSERT(pnt >= 0 && pnt < nlist->num_nodes);
574
575 // Remove all connects to the world...
576 for (i = nlist->nodes[pnt].num_edges - 1; i >= 0; i--) {
577 EBNode_RemoveEdge(pnt, roomnum, nlist->nodes[pnt].edges[i].end_index, nlist->nodes[pnt].edges[i].end_room);
578 }
579
580 // Copy the nodes down the list
581 for (i = pnt; i < nlist->num_nodes - 1; i++) {
582 nlist->nodes[i] = nlist->nodes[i + 1];
583 }
584
585 nlist->num_nodes--;
586
587 if (nlist->num_nodes == 0) {
588 mem_free(nlist->nodes);
589 nlist->nodes = NULL;
590 } else {
591 nlist->nodes = (bn_node *)mem_realloc(nlist->nodes, sizeof(bn_node) * nlist->num_nodes);
592 }
593
594 // Not super efficient, but works. :)
595 int next_rooms[1000];
596 int num_next_rooms = AIMakeNextRoomList(roomnum, next_rooms, 1000);
597
598 for (i = 0; i < num_next_rooms; i++) {
599 RemapEdgeNodesEqualAndAbove(next_rooms[i], roomnum, pnt);
600 }
601 RemapEdgeNodesEqualAndAbove(roomnum, roomnum, pnt);
602 RemapPortalNodeIndices(roomnum, pnt);
603 }
604
605 void EBNode_RemoveEdge(int spnt, int sroom, int epnt, int eroom, bool f_remove_reverse) {
606 int i;
607
608 BNode_verified = false;
609
610 // Make sure there are no zero length paths
611 if (sroom == eroom && spnt == epnt) {
612 return;
613 }
614
615 bn_list *snlist;
616 snlist = BNode_GetBNListPtr(sroom);
617 bn_list *enlist;
618 enlist = BNode_GetBNListPtr(eroom);
619
620 if (!snlist)
621 return;
622
623 bool f_exists = false;
624 int e_index;
625
626 // Check to see if this edge already exists
627 for (i = 0; i < snlist->nodes[spnt].num_edges; i++) {
628 if (snlist->nodes[spnt].edges[i].end_index == epnt && snlist->nodes[spnt].edges[i].end_room == eroom) {
629 e_index = i;
630 f_exists = true;
631 break;
632 }
633 }
634
635 ASSERT(f_exists);
636
637 // Copy the edges down the list
638 for (i = e_index; i < snlist->nodes[spnt].num_edges - 1; i++) {
639 snlist->nodes[spnt].edges[i] = snlist->nodes[spnt].edges[i + 1];
640 }
641
642 snlist->nodes[spnt].num_edges--;
643
644 if (snlist->nodes[spnt].num_edges == 0) {
645 mem_free(snlist->nodes[spnt].edges);
646 snlist->nodes[spnt].edges = NULL;
647 } else {
648 snlist->nodes[spnt].edges =
649 (bn_edge *)mem_realloc(snlist->nodes[spnt].edges, sizeof(bn_edge) * snlist->nodes[spnt].num_edges);
650 }
651
652 if (f_remove_reverse && enlist) {
653 EBNode_RemoveEdge(epnt, eroom, spnt, sroom, false);
654 }
655 }
656
657 int EBNode_AddNode(int roomnum, vector *pnt, bool f_from_editor, bool f_check_for_close_nodes) {
658 bn_list *nlist;
659 nlist = BNode_GetBNListPtr(roomnum);
660 if (!nlist)
661 return -1;
662
663 BNode_verified = false;
664
665 if (nlist->num_nodes >= MAX_BNODES_PER_ROOM) {
666 #ifndef NEWEDITOR
667 OutrageMessageBox("Too many BOA Nodes for this room/region.\nGet Chris if you need more nodes.");
668 #else
669 OutrageMessageBox("Too many BOA Nodes for this room/region.");
670 #endif
671 return -1;
672 }
673
674 int i;
675 bool f_really_close_neighbor = false;
676 int new_node;
677
678 if (f_check_for_close_nodes) {
679 for (i = 0; i < nlist->num_nodes; i++) {
680 float min_dist = 0.0f;
681
682 if (f_check_for_close_nodes) {
683 min_dist = BNODE_VERY_CLOSE_DIST;
684 }
685
686 if (vm_VectorDistance(&nlist->nodes[i].pos, pnt) <= min_dist) {
687 f_really_close_neighbor = true;
688 break;
689 }
690 }
691
692 if (f_really_close_neighbor) {
693 if (f_from_editor) {
694 #ifndef NEWEDITOR
695 OutrageMessageBox(
696 "This node is really close to another one and isn't needed.\nSee Chris if this is a problem.");
697 #else
698 OutrageMessageBox("This node is really close to another one and isn't needed.");
699 #endif
700 }
701
702 return -1;
703 }
704 }
705 // Makes sure that if there are no nodes, then the node pointer is NULL and that if
706 // there are nodes that the node pointer isn't NULL
707 ASSERT(!((nlist->num_nodes == 0) ^ (nlist->nodes == NULL)));
708
709 new_node = nlist->num_nodes;
710 nlist->num_nodes++;
711
712 if (new_node != 0)
713 nlist->nodes = (bn_node *)mem_realloc(nlist->nodes, sizeof(bn_node) * (nlist->num_nodes));
714 else
715 nlist->nodes = (bn_node *)mem_malloc(sizeof(bn_node));
716
717 nlist->nodes[new_node].edges = NULL;
718 nlist->nodes[new_node].num_edges = 0;
719 nlist->nodes[new_node].pos = *pnt;
720
721 return new_node;
722 }
723
724 int EBNode_InsertNodeOnEdge(int spnt, int sroom, int epnt, int eroom) {
725 int i;
726
727 BNode_verified = false;
728
729 bn_list *snlist;
730 snlist = BNode_GetBNListPtr(sroom);
731 bn_list *enlist;
732 enlist = BNode_GetBNListPtr(eroom);
733
734 bool f_exists = false;
735 int e_index;
736
737 // Check to see if this edge already exists
738 for (i = 0; i < snlist->nodes[spnt].num_edges; i++) {
739 if (snlist->nodes[spnt].edges[i].end_index == epnt && snlist->nodes[spnt].edges[i].end_room == eroom) {
740 e_index = i;
741 f_exists = true;
742 break;
743 }
744 }
745
746 ASSERT(f_exists);
747
748 vector new_pos = (snlist->nodes[spnt].pos + enlist->nodes[epnt].pos) / 2.0f;
749 fvi_info hit_info;
750 hit_info.hit_room = sroom;
751
752 if (sroom != eroom) {
753 fvi_query fq;
754 int fate;
755
756 // shoot a ray from the light position to the current vertex
757 fq.p0 = &snlist->nodes[spnt].pos;
758 fq.p1 = &enlist->nodes[epnt].pos;
759 fq.startroom = (sroom > Highest_room_index && sroom <= Highest_room_index + 8)
760 ? GetTerrainRoomFromPos(&snlist->nodes[spnt].pos)
761 : sroom;
762
763 fq.rad = 0.0f;
764 fq.flags = FQ_IGNORE_RENDER_THROUGH_PORTALS;
765 fq.thisobjnum = -1;
766 fq.ignore_obj_list = NULL;
767
768 fate = fvi_FindIntersection(&fq, &hit_info);
769
770 if (fate != HIT_NONE) {
771 OutrageMessageBox("You can only do this function if the 2 nodes can\nsee each other or are in the same room.\n");
772 return -1;
773 }
774 }
775
776 int n_index = EBNode_AddNode(hit_info.hit_room, &new_pos, false, false);
777 EBNode_AddEdge(n_index, hit_info.hit_room, spnt, sroom);
778 EBNode_AddEdge(n_index, hit_info.hit_room, epnt, eroom);
779
780 EBNode_RemoveEdge(epnt, eroom, spnt, sroom);
781
782 return n_index;
783 }
784
785 float EBNode_DetermineMaxSizeForEdge(int spnt, int sroom, int epnt, int eroom) {
786 bn_list *snlist;
787 snlist = BNode_GetBNListPtr(sroom);
788 bn_list *enlist;
789 enlist = BNode_GetBNListPtr(eroom);
790
791 float size = 0.0f;
792 fvi_info hit_info;
793 fvi_query fq;
794 int fate;
795
796 // shoot a ray from the light position to the current vertex
797 fq.flags = FQ_IGNORE_RENDER_THROUGH_PORTALS;
798 fq.thisobjnum = -1;
799 fq.ignore_obj_list = NULL;
800
801 do {
802 fq.p0 = &snlist->nodes[spnt].pos;
803 fq.p1 = &enlist->nodes[epnt].pos;
804 fq.startroom = (sroom > Highest_room_index && sroom <= Highest_room_index + 8)
805 ? GetTerrainRoomFromPos(&snlist->nodes[spnt].pos)
806 : sroom;
807 fq.rad = size;
808
809 fate = fvi_FindIntersection(&fq, &hit_info);
810
811 if (fate == HIT_NONE) {
812 fq.p0 = &enlist->nodes[epnt].pos;
813 fq.p1 = &snlist->nodes[spnt].pos;
814 fq.startroom = (eroom > Highest_room_index && eroom <= Highest_room_index + 8)
815 ? GetTerrainRoomFromPos(&enlist->nodes[epnt].pos)
816 : eroom;
817 fq.rad = size;
818
819 fate = fvi_FindIntersection(&fq, &hit_info);
820 }
821
822 if (fate == HIT_NONE) {
823 size += 1.0f;
824 }
825 } while (fate == HIT_NONE && size < MAX_BNODE_SIZE + 1.0f);
826
827 return (size - 1.0f);
828 }
829
830 void EBNode_AutoEdgeNode(int spnt, int sroom) {
831 BNode_verified = false;
832
833 bn_list *snlist;
834 snlist = BNode_GetBNListPtr(sroom);
835
836 int i;
837
838 for (i = 0; i < snlist->num_nodes; i++) {
839 if (i != spnt) {
840 fvi_info hit_info;
841 fvi_query fq;
842
843 // check to make sure it is still in the room and valid
844 fq.p0 = &snlist->nodes[spnt].pos;
845 fq.p1 = &snlist->nodes[i].pos;
846 fq.startroom = (sroom > Highest_room_index && sroom <= Highest_room_index + 8)
847 ? GetTerrainRoomFromPos(&snlist->nodes[spnt].pos)
848 : sroom;
849
850 fq.rad = 3.0f;
851 fq.flags = FQ_NO_RELINK;
852 fq.thisobjnum = -1;
853 fq.ignore_obj_list = NULL;
854
855 if (fvi_FindIntersection(&fq, &hit_info) == HIT_NONE) {
856 EBNode_AddEdge(spnt, sroom, i, sroom);
857 }
858 }
859 }
860 }
861
862 void EBNode_AddEdge(int spnt, int sroom, int epnt, int eroom, bool f_add_reverse, float computed_max_rad) {
863 int i;
864
865 BNode_verified = false;
866
867 // Make sure there are no zero length paths
868 if (sroom == eroom && spnt == epnt) {
869 return;
870 }
871
872 bn_list *snlist;
873 snlist = BNode_GetBNListPtr(sroom);
874 bn_list *enlist;
875 enlist = BNode_GetBNListPtr(eroom);
876
877 ASSERT(snlist && enlist);
878
879 bool f_exists = false;
880
881 // Check to see if this edge already exists
882 for (i = 0; i < snlist->nodes[spnt].num_edges; i++) {
883 if (snlist->nodes[spnt].edges[i].end_index == epnt && snlist->nodes[spnt].edges[i].end_room == eroom) {
884 f_exists = true;
885 break;
886 }
887 }
888
889 if (!f_exists) {
890 int new_edge;
891
892 // Makes sure that if there are no edges, then the edge pointer is NULL and that if
893 // there are edges that the edge pointer isn't NULL
894 ASSERT(!((snlist->nodes[spnt].num_edges == 0) ^ (snlist->nodes[spnt].edges == NULL)));
895
896 new_edge = snlist->nodes[spnt].num_edges;
897 snlist->nodes[spnt].num_edges++;
898
899 if (new_edge == 0) {
900 snlist->nodes[spnt].edges = (bn_edge *)mem_malloc(sizeof(bn_edge));
901 } else {
902 snlist->nodes[spnt].edges =
903 (bn_edge *)mem_realloc(snlist->nodes[spnt].edges, sizeof(bn_edge) * snlist->nodes[spnt].num_edges);
904 }
905
906 float cost = vm_VectorDistance(&snlist->nodes[spnt].pos, &enlist->nodes[epnt].pos);
907 if (cost < 1.0f)
908 cost = 1.0f;
909
910 snlist->nodes[spnt].edges[new_edge].cost = (cost < 32767.0f) ? (int16_t)cost : (int16_t)32767;
911 snlist->nodes[spnt].edges[new_edge].end_index = epnt;
912 snlist->nodes[spnt].edges[new_edge].end_room = BOA_INDEX(eroom);
913 snlist->nodes[spnt].edges[new_edge].flags = 0;
914
915 if (f_add_reverse) {
916 snlist->nodes[spnt].edges[new_edge].max_rad = EBNode_DetermineMaxSizeForEdge(spnt, sroom, epnt, eroom);
917 EBNode_AddEdge(epnt, eroom, spnt, sroom, false, snlist->nodes[spnt].edges[new_edge].max_rad);
918 } else {
919 snlist->nodes[spnt].edges[new_edge].max_rad = computed_max_rad;
920 }
921 }
922 }
923
924 void EBNode_MakeDefaultIntraRoomNodes(int roomnum) {
925 int i, j;
926
927 room *rp = &Rooms[roomnum];
928
929 // Adds the nodes from portals
930 for (i = 0; i < rp->num_portals; i++) {
931 vector pos;
932 pos = rp->portals[i].path_pnt + rp->faces[rp->portals[i].portal_face].normal * 0.75f;
933 rp->portals[i].bnode_index = i;
934
935 EBNode_AddNode(roomnum, &pos, false, false);
936 }
937
938 // Adds a node for centerpoint of the room
939 EBNode_AddNode(roomnum, &rp->path_pnt, false, false);
940
941 // Add the edges
942 for (i = 0; i < rp->bn_info.num_nodes; i++) {
943 // Edges go both ways - always
944 for (j = i + 1; j < rp->bn_info.num_nodes; j++) {
945 // Check to see if the center is really close to this edge, if so - Dont make this edge
946 if (i < rp->bn_info.num_nodes - 1 && j < rp->bn_info.num_nodes - 1) {
947 vector vec = rp->portals[j].path_pnt - rp->portals[i].path_pnt;
948 vector cvec = rp->path_pnt - rp->portals[i].path_pnt;
949
950 float len = vm_NormalizeVector(&vec);
951 float cproj = cvec * vec;
952
953 if (len >= cproj && cproj >= 0.0f) {
954 vector cxline = cproj * vec;
955 vector dvec = rp->path_pnt - (rp->portals[i].path_pnt + cxline);
956
957 if (vm_GetMagnitude(&dvec) < 3.0f) {
958 continue;
959 }
960 }
961 }
962
963 fvi_info hit_info;
964 fvi_query fq;
965
966 // check to make sure it is still in the room and valid
967 fq.p0 = &Rooms[roomnum].bn_info.nodes[i].pos;
968 fq.p1 = &Rooms[roomnum].bn_info.nodes[j].pos;
969 fq.startroom = (roomnum > Highest_room_index && roomnum <= Highest_room_index + 8)
970 ? GetTerrainRoomFromPos(&Rooms[roomnum].bn_info.nodes[i].pos)
971 : roomnum;
972
973 fq.rad = 0.1f;
974 fq.flags = FQ_SOLID_PORTALS | FQ_NO_RELINK;
975 fq.thisobjnum = -1;
976 fq.ignore_obj_list = NULL;
977
978 if (fvi_FindIntersection(&fq, &hit_info) != HIT_NONE) {
979 continue;
980 }
981
982 EBNode_AddEdge(i, roomnum, j, roomnum);
983 }
984 }
985 }
986
987 void EBNode_MakeDefaultInterRoomEdges(int roomnum) {
988 int i;
989
990 for (i = 0; i < Rooms[roomnum].num_portals; i++) {
991 if (Rooms[roomnum].portals[i].cportal >= 0 && Rooms[roomnum].portals[i].croom > roomnum &&
992 !(Rooms[Rooms[roomnum].portals[i].croom].flags & RF_EXTERNAL)) {
993 if ((Rooms[roomnum].portals[i].flags & PF_RENDER_FACES) &&
994 !(Rooms[roomnum].portals[i].flags & PF_RENDERED_FLYTHROUGH)) {
995 if (!(GameTextures[Rooms[roomnum].faces[Rooms[roomnum].portals[i].portal_face].tmap].flags &
996 (TF_BREAKABLE | TF_FORCEFIELD))) {
997 continue;
998 }
999 }
1000
1001 EBNode_AddEdge(i, roomnum, Rooms[roomnum].portals[i].cportal, Rooms[roomnum].portals[i].croom);
1002 }
1003 }
1004 }
1005
1006 void EBNode_RemoveNodesAtUnopenablePortals(int roomnum) {
1007 int i;
1008
1009 ASSERT(Rooms[roomnum].num_portals + 1 == Rooms[roomnum].bn_info.num_nodes);
1010
1011 for (i = Rooms[roomnum].num_portals - 1; i >= 0; i--) {
1012 if ((Rooms[roomnum].portals[i].flags & PF_BLOCK) && !(Rooms[roomnum].portals[i].flags & PF_BLOCK_REMOVABLE)) {
1013 EBNode_RemoveNode(roomnum, i);
1014 continue;
1015 }
1016
1017 if ((Rooms[roomnum].portals[i].flags & PF_RENDER_FACES) &&
1018 !(Rooms[roomnum].portals[i].flags & PF_RENDERED_FLYTHROUGH)) {
1019 if (!(GameTextures[Rooms[roomnum].faces[Rooms[roomnum].portals[i].portal_face].tmap].flags &
1020 (TF_BREAKABLE | TF_FORCEFIELD))) {
1021 EBNode_RemoveNode(roomnum, i);
1022 continue;
1023 }
1024 }
1025
1026 if (Rooms[roomnum].portals[i].flags & PF_TOO_SMALL_FOR_ROBOT) {
1027 EBNode_RemoveNode(roomnum, i);
1028 continue;
1029 }
1030 }
1031 }
1032
1033 // void EBNode_VerifyGraph()
1034 //{
1035 /* int i;
1036 int j;
1037 int k;
1038 int l;
1039
1040 for(i = 0; i <= Highest_room_index; i++)
1041 {
1042 if(Rooms[i].used && !(Rooms[i].flags & RF_EXTERNAL))
1043 {
1044 room *rp = &Rooms[i];
1045
1046 for(j = 0; j < rp->bn_info.num_nodes; j++)
1047 {
1048 for(k = 0; k < rp->bn_info.nodes[j].num_edges; k++)
1049 {
1050 ASSERT(!(rp->bn_info.nodes[j].edges[k].end_room == i &&
1051 rp->bn_info.nodes[j].edges[k].end_index == j));
1052
1053 bool f_found = false;
1054
1055 for(l = 0; l <
1056 Rooms[rp->bn_info.nodes[j].edges[k].end_room].bn_info.nodes[rp->bn_info.nodes[j].edges[k].end_index].num_edges; l++)
1057 {
1058 if(Rooms[rp->bn_info.nodes[j].edges[k].end_room].bn_info.nodes[rp->bn_info.nodes[j].edges[k].end_index].edges[l].end_room
1059 == i &&
1060 Rooms[rp->bn_info.nodes[j].edges[k].end_room].bn_info.nodes[rp->bn_info.nodes[j].edges[k].end_index].edges[l].end_index
1061 == j)
1062 {
1063 f_found = true;
1064 break;
1065 }
1066 }
1067
1068 ASSERT(f_found);
1069
1070 for(l = 0; l < rp->bn_info.nodes[j].num_edges; l++)
1071 {
1072 if(l != k)
1073 {
1074 ASSERT(!(rp->bn_info.nodes[j].edges[k].end_room ==
1075 rp->bn_info.nodes[j].edges[l].end_room && rp->bn_info.nodes[j].edges[k].end_index ==
1076 rp->bn_info.nodes[j].edges[l].end_index));
1077 }
1078 }
1079 }
1080 }
1081 }
1082 }
1083 */
1084 //}
1085
1086 void EBNode_MakeDefaultTerrainNodes(int region) {
1087 int i, j;
1088
1089 ASSERT(region >= 0 || region < BOA_num_terrain_regions);
1090
1091 mprintf(0, "TR %d has %d nodes\n", region, BOA_num_connect[region]);
1092
1093 // Adds the nodes from portals
1094 for (i = 0; i < BOA_num_connect[region]; i++) {
1095 int end_room = BOA_connect[region][i].roomnum;
1096 room *rp = &Rooms[end_room];
1097 int p = BOA_connect[region][i].portal;
1098
1099 vector pos;
1100 pos = rp->portals[p].path_pnt - rp->faces[rp->portals[p].portal_face].normal * 0.75f;
1101
1102 int external_room = rp->portals[p].croom;
1103 int external_portal = rp->portals[p].cportal;
1104 ASSERT(Rooms[external_room].flags & RF_EXTERNAL);
1105 Rooms[external_room].portals[external_portal].bnode_index = i;
1106
1107 EBNode_AddNode(Highest_room_index + region + 1, &pos, false, false);
1108 EBNode_AddEdge(i, Highest_room_index + region + 1, p, end_room);
1109 }
1110
1111 // Add the edges
1112 for (i = 0; i < BOA_num_connect[region]; i++) {
1113 // Edges go both ways - always
1114 for (j = i + 1; j < BOA_num_connect[region]; j++) {
1115 EBNode_AddEdge(i, Highest_room_index + region + 1, j, Highest_room_index + region + 1);
1116 }
1117 }
1118 }
1119
1120 void EBNode_MakeFirstPass(void) {
1121 int i;
1122
1123 if (BNode_allocated) {
1124 OutrageMessageBox("The BNode system is already made.\nUse the other functions to modify the graph.");
1125 return;
1126 }
1127
1128 for (i = 0; i <= Highest_room_index; i++) {
1129 ASSERT(Rooms[i].bn_info.num_nodes == 0);
1130
1131 if (Rooms[i].used && !(Rooms[i].flags & RF_EXTERNAL)) {
1132 EBNode_MakeDefaultIntraRoomNodes(i);
1133 }
1134 }
1135
1136 for (i = 0; i < BOA_num_terrain_regions; i++) {
1137 ASSERT(BNode_terrain_list[i].num_nodes == 0);
1138 EBNode_MakeDefaultTerrainNodes(i);
1139 }
1140
1141 // This function assumes that Node(X) goes to Portal(X)
1142 for (i = 0; i <= Highest_room_index; i++) {
1143 if (Rooms[i].used && !(Rooms[i].flags & RF_EXTERNAL)) {
1144 EBNode_MakeDefaultInterRoomEdges(i);
1145 }
1146 }
1147
1148 // This function assumes that Node(X) goes to Portal(X)
1149 for (i = 0; i <= Highest_room_index; i++) {
1150 if (Rooms[i].used && !(Rooms[i].flags & RF_EXTERNAL)) {
1151 EBNode_RemoveNodesAtUnopenablePortals(i);
1152 }
1153 }
1154
1155 for (i = 0; i <= Highest_room_index + BOA_num_terrain_regions; i++) {
1156 bn_list *nlist;
1157 int j;
1158 int k;
1159
1160 if (i >= 0 && i <= Highest_room_index && !Rooms[i].used)
1161 continue;
1162
1163 nlist = BNode_GetBNListPtr(i);
1164
1165 for (j = 0; j < nlist->num_nodes; j++) {
1166 for (k = 0; k < nlist->nodes[j].num_edges; k++) {
1167 if (nlist->nodes[j].edges[k].max_rad < 5.0f) {
1168 EBNode_RemoveEdge(j, i, nlist->nodes[j].edges[k].end_index, nlist->nodes[j].edges[k].end_room);
1169 k--;
1170 }
1171 }
1172 }
1173 }
1174
1175 BNode_allocated = true;
1176 #ifndef NEWEDITOR
1177 EBNode_VerifyGraph();
1178 #else
1179 bool ned_EBNode_VerifyGraph();
1180 ned_EBNode_VerifyGraph();
1181 #endif
1182 }
1183
1184 #ifndef NEWEDITOR
1185 #include "editor/d3edit.h"
1186 #else
1187 #include "neweditor/globals.h"
1188 #include "terrain.h"
1189 #include "renderer.h"
1190 #endif
1191
1192 #include "gr.h"
1193 #include "epath.h"
1194
1195 void EBNode_DrawRoom(int room, grViewport *vp, vector *viewer_eye, matrix *viewer_orient, float zoom,
1196 bool f_current_room = false) {
1197 int i, current_path_index = 0, t;
1198 g3Point rot_points[300];
1199 int sort_index[300];
1200
1201 bn_list *bn_info = BNode_GetBNListPtr(room);
1202
1203 for (i = 0; i < bn_info->num_nodes; i++) {
1204 // int curnode=D3EditState.current_node;
1205 //
1206 g3_RotatePoint(&rot_points[0], &bn_info->nodes[i].pos);
1207 sort_index[0] = 0;
1208
1209 for (t = 0; t < bn_info->nodes[i].num_edges; t++) {
1210
1211 bn_list *ebn_info = BNode_GetBNListPtr(bn_info->nodes[i].edges[t].end_room);
1212
1213 g3_RotatePoint(&rot_points[t + 1], &ebn_info->nodes[bn_info->nodes[i].edges[t].end_index].pos);
1214 sort_index[t + 1] = t + 1;
1215 }
1216
1217 // ddgr_color path_color = (current_path_index==D3EditState.current_path) ? GR_RGB(255,255,255) :
1218 //GR_RGB(36,99,238);
1219 ddgr_color path_color;
1220
1221 if (f_current_room)
1222 path_color = GR_RGB(255, 0, 0);
1223 else
1224 path_color = GR_RGB(100, 0, 0);
1225
1226 int x;
1227 g3Point p1 = rot_points[0];
1228
1229 for (x = 0; x < bn_info->nodes[i].num_edges; x++) {
1230 g3Point p2 = rot_points[x + 1];
1231 g3_DrawLine(path_color, &p1, &p2);
1232 }
1233
1234 for (t = 0; t < bn_info->nodes[i].num_edges + 1; t++) {
1235 for (int k = 0; k < bn_info->nodes[i].num_edges + 1; k++) {
1236 if (rot_points[k].p3_vec.z < rot_points[t].p3_vec.z) {
1237 g3Point temp;
1238 int tindex;
1239
1240 memcpy(&temp, &rot_points[t], sizeof(g3Point));
1241 memcpy(&rot_points[t], &rot_points[k], sizeof(g3Point));
1242 memcpy(&rot_points[k], &temp, sizeof(g3Point));
1243
1244 tindex = sort_index[t];
1245 sort_index[t] = sort_index[k];
1246 sort_index[k] = tindex;
1247 }
1248 }
1249 }
1250 }
1251
1252 int color;
1253 float size;
1254
1255 if (f_current_room) {
1256 color = GR_RGB(0, 128, 160);
1257 size = 0.7f;
1258 } else {
1259 color = GR_RGB(0, 64, 80);
1260 size = 0.5f;
1261 }
1262
1263 for (i = 0; i < bn_info->num_nodes; i++) {
1264 g3_RotatePoint(&rot_points[0], &bn_info->nodes[i].pos);
1265
1266 #ifdef NEWEDITOR
1267 ddgr_color oldcolor;
1268
1269 if (TSearch_on) {
1270 rend_SetPixel(GR_RGB(16, 255, 16), TSearch_x, TSearch_y);
1271 oldcolor = rend_GetPixel(TSearch_x, TSearch_y);
1272 }
1273 #endif
1274
1275 g3_DrawSphere(color, &rot_points[0], size);
1276
1277 #ifdef NEWEDITOR
1278 if (TSearch_on) {
1279 if (rend_GetPixel(TSearch_x, TSearch_y) != oldcolor) {
1280 TSearch_found_type = TSEARCH_FOUND_BNODE;
1281 TSearch_seg = room;
1282 TSearch_face = i;
1283 }
1284 }
1285 #endif
1286
1287 DrawNumber(i + 1, bn_info->nodes[i].pos, size * .5);
1288 }
1289 }
1290
1291 void EBNode_ComputeEdgeCosts(int sroom, int spnt, int eroom, int epnt) {
1292 int i, j;
1293 bool f_found = false;
1294
1295 bn_list *snlist;
1296 snlist = BNode_GetBNListPtr(sroom);
1297 bn_list *enlist;
1298 enlist = BNode_GetBNListPtr(eroom);
1299
1300 for (i = 0; i < snlist->nodes[spnt].num_edges; i++) {
1301 for (j = 0; j < enlist->nodes[epnt].num_edges; j++) {
1302 if ((snlist->nodes[spnt].edges[i].end_index == epnt && snlist->nodes[spnt].edges[i].end_room == eroom) &&
1303 (enlist->nodes[epnt].edges[j].end_index == spnt && enlist->nodes[epnt].edges[j].end_room == sroom)) {
1304 f_found = true;
1305
1306 float cost = vm_VectorDistance(&snlist->nodes[spnt].pos, &enlist->nodes[epnt].pos);
1307 if (cost < 1.0f)
1308 cost = 1.0f;
1309
1310 int16_t scost = (cost < 32767.0f) ? (int16_t)cost : (int16_t)32767;
1311
1312 snlist->nodes[spnt].edges[i].cost = scost;
1313 enlist->nodes[epnt].edges[j].cost = scost;
1314
1315 snlist->nodes[spnt].edges[i].max_rad = enlist->nodes[epnt].edges[j].max_rad =
1316 EBNode_DetermineMaxSizeForEdge(spnt, sroom, epnt, eroom);
1317 }
1318 }
1319 }
1320
1321 ASSERT(f_found == true); // If you get this -- Get Chris!!!!!!!
1322 }
1323
1324 void EBNode_Move(bool f_offset, int roomnum, int pnt, vector *pos) {
1325 bn_list *nlist;
1326 nlist = BNode_GetBNListPtr(roomnum);
1327
1328 int i;
1329 vector npos = *pos;
1330
1331 if (f_offset) {
1332 npos += nlist->nodes[pnt].pos;
1333
1334 fvi_info hit_info;
1335 fvi_query fq;
1336
1337 // check to make sure it is still in the room and valid
1338 fq.p0 = &nlist->nodes[pnt].pos;
1339 fq.p1 = &npos;
1340 fq.startroom = (roomnum > Highest_room_index && roomnum <= Highest_room_index + 8)
1341 ? GetTerrainRoomFromPos(&nlist->nodes[pnt].pos)
1342 : roomnum;
1343
1344 fq.rad = 0.25f;
1345 fq.flags =
1346 FQ_SOLID_PORTALS | FQ_NO_RELINK; // chrishack -- Might want to make FQ_IGNORE_MOVING_OBJECTS into a passed arg
1347 fq.thisobjnum = -1;
1348 fq.ignore_obj_list = NULL;
1349
1350 fvi_FindIntersection(&fq, &hit_info);
1351
1352 npos = hit_info.hit_pnt;
1353 }
1354
1355 nlist->nodes[pnt].pos = npos;
1356
1357 for (i = 0; i < nlist->nodes[pnt].num_edges; i++) {
1358 EBNode_ComputeEdgeCosts(roomnum, pnt, nlist->nodes[pnt].edges[i].end_room, nlist->nodes[pnt].edges[i].end_index);
1359 EBNode_ComputeEdgeCosts(nlist->nodes[pnt].edges[i].end_room, nlist->nodes[pnt].edges[i].end_index, roomnum, pnt);
1360 }
1361 }
1362
1363 void EBNode_Draw(char draw_type, grViewport *vp, vector *viewer_eye, matrix *viewer_orient, float zoom) {
1364 int i;
1365
1366 #ifndef NEWEDITOR
1367 int roomnum = Viewer_object->roomnum;
1368 #else
1369 int roomnum = ROOMNUM(theApp.m_pLevelWnd->m_Prim.roomp);
1370 #endif
1371
1372 switch (draw_type) {
1373 case EBDRAW_NONE:
1374 break;
1375 case EBDRAW_ROOM_AND_NEXT_ROOMS: {
1376 int i;
1377 int next_rooms[1000];
1378 int num_next_rooms = AIMakeNextRoomList(roomnum, next_rooms, 1000);
1379
1380 for (i = 0; i < num_next_rooms; i++) {
1381 EBNode_DrawRoom(next_rooms[i], vp, viewer_eye, viewer_orient, zoom, false);
1382 }
1383 }
1384 case EBDRAW_ROOM:
1385 EBNode_DrawRoom(roomnum, vp, viewer_eye, viewer_orient, zoom, true);
1386 break;
1387 case EBDRAW_LEVEL:
1388 for (i = 0; i <= Highest_room_index; i++) {
1389 if (Rooms[i].used && !(Rooms[i].flags & RF_EXTERNAL)) {
1390 EBNode_DrawRoom(i, vp, viewer_eye, viewer_orient, zoom, i == roomnum);
1391 }
1392 }
1393 for (i = 0; i < BOA_num_terrain_regions; i++) {
1394 EBNode_DrawRoom(Highest_room_index + i + 1, vp, viewer_eye, viewer_orient, zoom,
1395 ROOMNUM_OUTSIDE(roomnum) && (i == TERRAIN_REGION(roomnum)));
1396 }
1397 break;
1398 }
1399 }