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