| 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/BOA.h $ |
| 21 | * $Revision: 34 $ |
| 22 | * $Date: 4/30/99 5:40p $ |
| 23 | * $Author: Jason $ |
| 24 | * |
| 25 | * BOA Header |
| 26 | * |
| 27 | * $Log: /DescentIII/main/BOA.h $ |
| 28 | * |
| 29 | * 34 4/30/99 5:40p Jason |
| 30 | * fixed some issues with release builds |
| 31 | * |
| 32 | * 33 4/29/99 5:43p Chris |
| 33 | * Added the check for bad center points |
| 34 | * |
| 35 | * 32 4/26/99 11:11a Chris |
| 36 | * Updated Bnode system |
| 37 | * |
| 38 | * 31 4/20/99 8:55p Chris |
| 39 | * Fixed problem with robots not being able to open locked doors that a |
| 40 | * player has the key for. |
| 41 | * |
| 42 | * 30 4/18/99 5:39a Chris |
| 43 | * Vastly improved the path node system |
| 44 | * |
| 45 | * 29 2/25/99 5:43p Chris |
| 46 | * Massive improvement to BOA and AI (again) |
| 47 | * |
| 48 | * 28 2/24/99 12:27p Chris |
| 49 | * Fixed problems with GB finding robots/room he couldn't get to. Fixed |
| 50 | * problems with forcefields(sound prop. and path finding). Fixed |
| 51 | * problems with small portals. |
| 52 | * |
| 53 | * 27 2/12/99 11:22a Chris |
| 54 | * Updated what BOA uses for BOA_cost_array. It is not just the distance |
| 55 | * from the center of the room to the center of the portal. It was this + |
| 56 | * the dist to the next room's center. The reason for this change was it |
| 57 | * makes it easier to compute the exact BOA_DIST for sounds. This is |
| 58 | * because the two distances are seperated (so from the start pos, we do a |
| 59 | * vm_Vect dist from the start point to the portal)... Hmmm.... |
| 60 | * |
| 61 | * 26 2/09/99 12:41p Chris |
| 62 | * |
| 63 | * 25 2/09/99 12:40p Chris |
| 64 | * More aipath stuff has been merged with the new BOA |
| 65 | * |
| 66 | * 24 2/09/99 12:17p Chris |
| 67 | * |
| 68 | * 23 2/09/99 9:58a Chris |
| 69 | * Massive BOA update :) Terrain happy now. Vis happy now. Sound happy |
| 70 | * now. |
| 71 | * |
| 72 | * 22 1/11/99 2:14p Chris |
| 73 | * Massive work on OSIRIS and AI |
| 74 | * |
| 75 | * 21 12/11/98 1:55p Chris |
| 76 | * Reduced BOA's size and changed how it works with no path situations |
| 77 | * |
| 78 | * 20 12/09/98 10:41a Jason |
| 79 | * fixed BOA problems with lighting |
| 80 | * |
| 81 | * 19 9/16/98 12:07p Chris |
| 82 | * Improved BOA AABB computation with room checksums |
| 83 | * |
| 84 | * 18 8/04/98 2:32p Chris |
| 85 | * Improved attach code added more fixes to the AABB partial computation |
| 86 | * patch |
| 87 | * |
| 88 | * 17 8/03/98 5:47p Chris |
| 89 | * Improved the partial AABB computation |
| 90 | * |
| 91 | * 16 7/21/98 2:14p Chris |
| 92 | * Some FVI speedups - not done |
| 93 | * |
| 94 | * 15 7/20/98 5:39p Jason |
| 95 | * fixed MACRO bug |
| 96 | * |
| 97 | * 14 7/20/98 4:45p Jason |
| 98 | * added BOA vis table stuff |
| 99 | * |
| 100 | * 13 7/16/98 8:29p Chris |
| 101 | * Intermediate checkin |
| 102 | * |
| 103 | * 12 7/16/98 8:29p Chris |
| 104 | * Partial implementation of the new collide code |
| 105 | * |
| 106 | * 11 5/03/98 8:36p Chris |
| 107 | * Additional debug info |
| 108 | * |
| 109 | * 10 4/28/98 12:01p Matt |
| 110 | * Dropped MAX_PATH_PORTALS from 100 down to 40. |
| 111 | * |
| 112 | * 9 4/22/98 6:38p Matt |
| 113 | * Added SourceSafe header |
| 114 | * |
| 115 | */ |
| 116 | |
| 117 | #ifndef _BOA_H__ |
| 118 | #define _BOA_H__ |
| 119 | |
| 120 | #include "room.h" |
| 121 | #include "terrain.h" |
| 122 | |
| 123 | #define MAX_PATH_PORTALS 40 |
| 124 | #define MAX_BOA_TERRAIN_REGIONS 8 |
| 125 | |
| 126 | extern float BOA_cost_array[MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS][MAX_PATH_PORTALS]; |
| 127 | extern uint16_t BOA_Array[MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS][MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS]; |
| 128 | extern int BOA_mine_checksum; |
| 129 | extern int BOA_AABB_checksum; |
| 130 | extern int BOA_vis_checksum; |
| 131 | extern bool BOA_vis_valid; |
| 132 | extern int BOA_AABB_ROOM_checksum[MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS]; |
| 133 | |
| 134 | //-- Priority Queue |
| 135 | class q_item { |
| 136 | public: |
| 137 | q_item(int room_index, int par, float n_cost) { |
| 138 | roomnum = room_index; |
| 139 | parent = par; |
| 140 | cost = n_cost; |
| 141 | next = NULL; |
| 142 | } |
| 143 | |
| 144 | int roomnum; |
| 145 | int parent; |
| 146 | float cost; |
| 147 | |
| 148 | q_item *next; |
| 149 | }; |
| 150 | |
| 151 | class pq { |
| 152 | q_item *q_head; |
| 153 | |
| 154 | public: |
| 155 | pq() { q_head = NULL; } |
| 156 | |
| 157 | void push(q_item *new_node) { |
| 158 | new_node->next = q_head; |
| 159 | q_head = new_node; |
| 160 | } |
| 161 | |
| 162 | q_item *pop() { |
| 163 | q_item *cur_item = q_head; |
| 164 | q_item *prev_item = NULL; |
| 165 | q_item *best_item = q_head; |
| 166 | q_item *best_prev_item = NULL; |
| 167 | |
| 168 | if (q_head == NULL) |
| 169 | return NULL; |
| 170 | |
| 171 | while (cur_item != NULL) { |
| 172 | if (cur_item->cost < best_item->cost) { |
| 173 | |
| 174 | best_prev_item = prev_item; |
| 175 | best_item = cur_item; |
| 176 | } |
| 177 | |
| 178 | prev_item = cur_item; |
| 179 | cur_item = cur_item->next; |
| 180 | } |
| 181 | |
| 182 | // Actually remove this item from the list |
| 183 | if (best_item == q_head) { |
| 184 | q_head = best_item->next; |
| 185 | } else { |
| 186 | best_prev_item->next = best_item->next; |
| 187 | } |
| 188 | |
| 189 | return best_item; |
| 190 | } |
| 191 | }; |
| 192 | |
| 193 | // Next Segment Info |
| 194 | #define BOA_ROOM_MASK 0x03FF |
| 195 | |
| 196 | #define BOA_TERRAIN_INDEX (Highest_room_index + 1) |
| 197 | #define BOA_INDEX(x) ((ROOMNUM_OUTSIDE(x) ? (TERRAIN_REGION(x) + Highest_room_index + 1) : x)) |
| 198 | #define BOA_NO_PATH (Highest_room_index + 9) |
| 199 | |
| 200 | #define BOA_NEXT_ROOM(a, b) (BOA_Array[a][b] & BOA_ROOM_MASK) |
| 201 | |
| 202 | // Visability Info |
| 203 | |
| 204 | #define BOAF_VIS 0x0400 |
| 205 | |
| 206 | #define BOA_GET_VIS(a, b) (BOA_vis_valid ? ((BOA_Array[a][b] & BOAF_VIS) != 0) : 1) |
| 207 | |
| 208 | // Set if a sound could prop between these to areas |
| 209 | #define BOA_SOUND_PROP 0x0800 |
| 210 | |
| 211 | // Distance from segment to segment Info |
| 212 | |
| 213 | #define BOA_DIST_MASK 0x3000 |
| 214 | |
| 215 | #define BOA_VNEAR_DIST 0.0 |
| 216 | #define BOA_NEAR_DIST 100.0 |
| 217 | #define BOA_FAR_DIST 200.0 |
| 218 | #define BOA_VFAR_DIST 300.0 |
| 219 | |
| 220 | #define BOAF_VNEAR_DIST 0x0000 // 0.0 to 100.0 |
| 221 | #define BOAF_NEAR_DIST 0x1000 // 100.0 to 200.0 |
| 222 | #define BOAF_FAR_DIST 0x2000 // 200.0 to 300.0 |
| 223 | #define BOAF_VFAR_DIST 0x3000 // 300.0+ |
| 224 | |
| 225 | #define BOA_GET_DIST(a, b) ((BOA_Array[a][b] & BOA_DIST_MASK) != 0) |
| 226 | |
| 227 | // Possible Blockage Info |
| 228 | |
| 229 | #define BOAF_BLOCKAGE 0x4000 |
| 230 | #define BOA_HAS_POSSIBLE_BLOCKAGE(a, b) ((BOA_Array[a][b] & BOAF_BLOCKAGE) != 0) |
| 231 | |
| 232 | // Path have a sport in it that is too small for a robot to get through |
| 233 | #define BOAF_TOO_SMALL_FOR_ROBOT 0x8000 |
| 234 | #define BOA_TOO_SMALL_FOR_ROBOT(a, b) ((BOA_Array[a][b] & BOAF_TOO_SMALL_FOR_ROBOT) != 0) |
| 235 | |
| 236 | struct connect_data { |
| 237 | int roomnum; |
| 238 | int portal; |
| 239 | }; |
| 240 | |
| 241 | extern int BOA_num_mines; |
| 242 | extern int BOA_num_terrain_regions; |
| 243 | extern int BOA_num_connect[MAX_BOA_TERRAIN_REGIONS]; |
| 244 | extern connect_data BOA_connect[MAX_BOA_TERRAIN_REGIONS][MAX_PATH_PORTALS]; |
| 245 | |
| 246 | void MakeBOA(void); |
| 247 | |
| 248 | // Goes through all the rooms and determines their visibility in relation to one another |
| 249 | void MakeBOAVisTable(bool from_lighting = 0); |
| 250 | |
| 251 | // Computes the AABBs for the level |
| 252 | void ComputeAABB(bool f_full); |
| 253 | |
| 254 | bool BOA_ComputeMinDist(int start_room, int end_room, float max_check_dist, float *dist, int *num_blockages = NULL); |
| 255 | bool BOA_ComputePropDist(int start_room, vector *start_pos, int end_room, vector *end_pos, float *dist, |
| 256 | int *num_blockages); |
| 257 | bool BOA_IsSoundAudible(int start_room, int end_room); |
| 258 | bool BOA_IsVisible(int start_room, int end_room); |
| 259 | bool BOA_HasPossibleBlockage(int start_room, int end_room); |
| 260 | int BOA_GetNextRoom(int start_room, int end_room); |
| 261 | int BOA_DetermineStartRoomPortal(int start_room, vector *start_pos, int end_room, vector *end_pos, |
| 262 | bool f_for_sound = false, bool f_making_robot_path_invalid_list = false, |
| 263 | int *blocked_portal = NULL); |
| 264 | bool BOA_PassablePortal(int room, int portal_index, bool f_for_sound = false, |
| 265 | bool f_making_robot_path_invalid_list = false); |
| 266 | bool BOA_LockedDoor(object *obj, int roomnum); |
| 267 | void BOA_ComputePathPoints(char *message = NULL, int len = 0); |
| 268 | int BOAGetMineChecksum(); |
| 269 | |
| 270 | #endif |