| 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/doorway.h $ |
| 21 | * $Revision: 15 $ |
| 22 | * $Date: 5/05/99 12:58a $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Doorway structures |
| 26 | * |
| 27 | * $Log: /DescentIII/main/doorway.h $ |
| 28 | * |
| 29 | * 15 5/05/99 12:58a Matt |
| 30 | * Added doorway flag to tell the Guide-Bot to ignore the locked state of |
| 31 | * the door. |
| 32 | * |
| 33 | * 14 4/23/99 8:28p Kevin |
| 34 | * trying to get doors working in save/load games |
| 35 | * |
| 36 | * 13 4/20/99 8:35p Matt |
| 37 | * Changed ActivateDoorway() to not exit if a door is locked. It's the |
| 38 | * caller's responsibility to check if the door is openable (if he cares) |
| 39 | * before activating. |
| 40 | * |
| 41 | * 12 4/20/99 6:55p Matt |
| 42 | * Added code to keep a bitmask of all keys held by all players, and to |
| 43 | * allow a robot to open a door if any player has the key(s) for that |
| 44 | * door. |
| 45 | * |
| 46 | * 11 2/06/99 10:03p Matt |
| 47 | * Added keys system |
| 48 | * |
| 49 | * 10 2/04/99 2:05p Matt |
| 50 | * Added blastable doors |
| 51 | * |
| 52 | * 9 1/29/99 12:47p Matt |
| 53 | * Rewrote the doorway system |
| 54 | * |
| 55 | * 8 9/08/98 12:06p Jason |
| 56 | * added automatic reinitting of doors when rooms get deleted |
| 57 | * |
| 58 | * 7 10/06/97 1:03p Samir |
| 59 | * Took out script name. Doorways are objects, and if there is a custom |
| 60 | * script for a doorway, we look at it's object. |
| 61 | * |
| 62 | * 6 10/06/97 1:01p Jason |
| 63 | * made doors work with scripts (sort of) |
| 64 | * |
| 65 | * 5 10/03/97 12:51p Jason |
| 66 | * added GetDoorwayNumFromObject function |
| 67 | * |
| 68 | * 4 10/03/97 12:24p Jason |
| 69 | * added new keys for doorways |
| 70 | * |
| 71 | * 3 9/29/97 12:09p Jason |
| 72 | * added functionality to doorway system |
| 73 | * |
| 74 | * 2 9/12/97 5:38p Jason |
| 75 | * got doors working |
| 76 | * |
| 77 | * 3 3/14/97 12:51p Samir |
| 78 | * Added code to clear active state of doorways. |
| 79 | * |
| 80 | * 2 3/13/97 11:58a Samir |
| 81 | * Added stuff for active doorway and opening/closing |
| 82 | * |
| 83 | * 1 3/12/97 2:08p Samir |
| 84 | * Moved structures and prototypes from door.h |
| 85 | * |
| 86 | * $NoKeywords: $ |
| 87 | */ |
| 88 | |
| 89 | #ifndef DOORWAY_H |
| 90 | #define DOORWAY_H |
| 91 | |
| 92 | #include "pstypes.h" |
| 93 | |
| 94 | // IMPORTANT!!!!!!!!!!! |
| 95 | // "Doors" refers to a predefined door that is in memory |
| 96 | // "Doorways" are specific doors that are in the mine |
| 97 | // So, there can be several Doorways that all point to the same Door |
| 98 | // Get it? If not, talk to Samir or Jason |
| 99 | |
| 100 | // doorway state |
| 101 | #define DOORWAY_STOPPED 0 // door is not moving |
| 102 | #define DOORWAY_OPENING 1 // door is opening |
| 103 | #define DOORWAY_CLOSING 2 // door is closing |
| 104 | #define DOORWAY_WAITING 3 // door is waiting to be closed |
| 105 | #define DOORWAY_OPENING_AUTO 4 // door is opening and will automatically close |
| 106 | |
| 107 | // doorway flags |
| 108 | #define DF_BLASTED 1 // it's been blasted away |
| 109 | #define DF_AUTO 2 // doorway closes after time. |
| 110 | #define DF_LOCKED 4 // doorway can't open for now |
| 111 | #define DF_KEY_ONLY_ONE 8 // only one key is needed to open (not all keys) |
| 112 | #define DF_GB_IGNORE_LOCKED 16 // the Guide-bot ignores the locked state of this door |
| 113 | |
| 114 | // keymasks |
| 115 | #define KF_KEY1 1 // Each key is a bit in the key_mask set in the door/object |
| 116 | #define KF_KEY2 2 |
| 117 | #define KF_KEY3 4 |
| 118 | #define KF_KEY4 8 |
| 119 | |
| 120 | #define MAX_ACTIVE_DOORWAYS 30 |
| 121 | |
| 122 | extern int Num_active_doorways; // number of active doors in game |
| 123 | extern int Active_doorways[MAX_ACTIVE_DOORWAYS]; |
| 124 | |
| 125 | // A doorway (room) in the mine |
| 126 | struct doorway { |
| 127 | int doornum; // door type of this doorway |
| 128 | uint8_t state; // current state of doorway |
| 129 | uint8_t flags; // flags associated with a doorway |
| 130 | uint8_t keys_needed; // used by trigger system. these bits need to be set to activate door |
| 131 | int8_t activenum; // index into active doorways array, or -1 if not active |
| 132 | float position; // current position of door |
| 133 | float dest_pos; // destination position |
| 134 | int sound_handle; // handle of last sound played |
| 135 | }; |
| 136 | |
| 137 | // Macros |
| 138 | |
| 139 | // returns the bitflag for the given key number |
| 140 | #define KEY_FLAG(keynum) (1 << (keynum - 1)) |
| 141 | |
| 142 | // Variables |
| 143 | |
| 144 | // This is a mask of all keys held by all players. Robots use this to determine if a door is openable. |
| 145 | extern int Global_keys; |
| 146 | |
| 147 | // |
| 148 | // Editor Functions |
| 149 | // |
| 150 | |
| 151 | // Define a couple types |
| 152 | struct room; |
| 153 | struct object; |
| 154 | |
| 155 | // Adds a doorway to the specified room |
| 156 | // Returns a pointer to the doorway struct |
| 157 | doorway *DoorwayAdd(room *rp, int doornum); |
| 158 | |
| 159 | // Updates the animation when the door position is changed |
| 160 | void DoorwayUpdateAnimation(room *rp); |
| 161 | |
| 162 | // |
| 163 | // General Functions |
| 164 | // |
| 165 | |
| 166 | // executes all active doorways in the game |
| 167 | void DoorwayDoFrame(); |
| 168 | |
| 169 | // clears the active state of all doorways that are active back to closed |
| 170 | void DoorwayDeactivateAll(); |
| 171 | |
| 172 | // Opens a door and, if it has the auto flag set, closes it |
| 173 | // Does not check to see if the door is openable -- the caller must do that. |
| 174 | void DoorwayActivate(int door_obj_handle); |
| 175 | |
| 176 | // Stops the doorway if it's moving |
| 177 | void DoorwayStop(int door_obj_handle); |
| 178 | |
| 179 | // Locks a given doorway |
| 180 | void DoorwayLockUnlock(int door_obj_handle, bool state); |
| 181 | |
| 182 | // Sets the current position of the door. 0.0 = totally closed, 1.0 = totally open |
| 183 | // Does not check to see if the door is openable -- the caller must do that. |
| 184 | void DoorwaySetPosition(int door_obj_handle, float pos); |
| 185 | |
| 186 | // Called after loading a saved game to rebuild the active list |
| 187 | void DoorwayRebuildActiveList(); |
| 188 | |
| 189 | // Called when a door is blown up |
| 190 | void DoorwayDestroy(object *objp); |
| 191 | |
| 192 | // |
| 193 | // Query Functions |
| 194 | // |
| 195 | |
| 196 | // Returns true if the doorway is locked, else false |
| 197 | bool DoorwayLocked(int door_obj_handle); |
| 198 | |
| 199 | // Returns true if the doorway is locked, else false |
| 200 | bool DoorwayLocked(room *rp); |
| 201 | |
| 202 | // Returns true if the doorway is openable by the specified player, else false |
| 203 | bool DoorwayOpenable(int door_obj_handle, int opener_handle); |
| 204 | |
| 205 | // Returns the current state of the specified door |
| 206 | int DoorwayState(int door_obj_handle); |
| 207 | |
| 208 | // Returns the current position of the door. 0.0 = totally closed, 1.0 = totally open |
| 209 | float DoorwayPosition(room *rp); |
| 210 | |
| 211 | // Returns the current position of the door. 0.0 = totally closed, 1.0 = totally open |
| 212 | float DoorwayPosition(int door_obj_handle); |
| 213 | |
| 214 | // Make old name work |
| 215 | #define DoorwayGetPosition DoorwayPosition |
| 216 | |
| 217 | #endif |