| 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/controls.h $ |
| 21 | * $Revision: 36 $ |
| 22 | * $Date: 10/21/99 6:04p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Game controls header |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/controls.h $ |
| 28 | * |
| 29 | * 36 10/21/99 6:04p Matt |
| 30 | * Mac merge |
| 31 | * |
| 32 | * 35 7/15/99 5:39p Samir |
| 33 | * upped max joystick sensitivity to 4.0 from 2.0. |
| 34 | * |
| 35 | * 34 4/30/99 10:52p Samir |
| 36 | * fixed energy-to-shield usage and made Load and Save COnfig take a |
| 37 | * pilot. |
| 38 | * |
| 39 | * 33 4/24/99 6:29p Jason |
| 40 | * changed mouse sensitivity |
| 41 | * |
| 42 | * 32 3/22/99 6:20p Jeff |
| 43 | * added 2 more audio taunts. a mulitplayer event when someone plays an |
| 44 | * audio taunt. option to disable audio taunts. |
| 45 | * |
| 46 | * 31 2/26/99 2:13a Samir |
| 47 | * added audio taunt keys. |
| 48 | * |
| 49 | * 30 2/16/99 12:07p Samir |
| 50 | * redid controller config with new ui. |
| 51 | * |
| 52 | * 29 1/13/99 6:37a Jeff |
| 53 | * fixed object.h. There were numerous struct declarations that were the |
| 54 | * same name as the instance of the struct (gcc doesn't like this). |
| 55 | * Changed the struct name. Also added some #ifdef's for linux build, |
| 56 | * along with fixing case-sensitive includes |
| 57 | * |
| 58 | * 28 12/09/98 1:09p Jason |
| 59 | * second draft of automap |
| 60 | * |
| 61 | * 27 12/02/98 11:39a Samir |
| 62 | * added better code to handle changes in controller function list for |
| 63 | * pilot files (needed to have a constant giving number of controller |
| 64 | * functions in demo 1.0) |
| 65 | * |
| 66 | * 26 11/30/98 4:54p Samir |
| 67 | * added rear view config item. |
| 68 | * |
| 69 | * 25 11/30/98 1:09p Samir |
| 70 | * added rear view toggle. |
| 71 | * |
| 72 | * 24 10/21/98 10:36a Samir |
| 73 | * added code to turn on or off joystick or mouse. |
| 74 | * |
| 75 | * 23 10/08/98 10:52a Samir |
| 76 | * added countermeasure and weapon cycling. |
| 77 | * |
| 78 | * 22 9/17/98 3:24p Samir |
| 79 | * added headlight configuration. |
| 80 | * |
| 81 | * 21 8/31/98 6:49p Jeff |
| 82 | * made inventory and countermeasure keys customizable |
| 83 | * |
| 84 | * 20 8/31/98 12:39p Samir |
| 85 | * added code to resume controllers when restoring game mode. |
| 86 | * |
| 87 | * 19 6/18/98 4:44p Samir |
| 88 | * added changes for multiple configs for joystick controls. |
| 89 | * |
| 90 | * 18 5/19/98 3:36p Samir |
| 91 | * added automap key. |
| 92 | * |
| 93 | * 17 5/12/98 3:04p Samir |
| 94 | * added button control for pbh. |
| 95 | * |
| 96 | * 16 4/27/98 7:24p Samir |
| 97 | * poll controller at specified rate. |
| 98 | * |
| 99 | * 15 4/09/98 2:23p Jason |
| 100 | * added guided/afterburner stuff |
| 101 | * |
| 102 | * 14 4/08/98 3:44p Samir |
| 103 | * added toggle bank and configuration for afterburner |
| 104 | * |
| 105 | * 13 4/02/98 7:58p Samir |
| 106 | * Fixed up control setting saving and restoring. |
| 107 | * |
| 108 | * 12 3/13/98 8:55p Jeff |
| 109 | * Various changes to move control configuration into Pilot file |
| 110 | * |
| 111 | * 11 2/16/98 7:15p Matt |
| 112 | * Added fire_secondary_down_state |
| 113 | * |
| 114 | * 10 2/16/98 3:01p Samir |
| 115 | * Added fire_primary_down_state and changed some configuration. |
| 116 | * |
| 117 | * 9 2/15/98 7:06p Samir |
| 118 | * Added functions to save controller state. |
| 119 | * |
| 120 | * 8 2/12/98 8:48p Matt |
| 121 | * Changed controls system to keep the reading of the controls seperate |
| 122 | * from using the results. Got rid of the Controls global. |
| 123 | * |
| 124 | * 7 1/12/98 6:28p Samir |
| 125 | * New keys for sliding and use RCTRL for firing too. |
| 126 | * |
| 127 | * 6 12/05/97 10:59a Samir |
| 128 | * Somewhat revised controls for keyboard. Joystick now has variable |
| 129 | * sensitivity. |
| 130 | * |
| 131 | * 5 12/03/97 7:32p Samir |
| 132 | * More D2 like keyboard movement. |
| 133 | * |
| 134 | * 4 11/05/97 3:45p Samir |
| 135 | * InitControls will close the previous call to InitControls. |
| 136 | * |
| 137 | * 3 10/30/97 4:02p Matt |
| 138 | * Added the flare |
| 139 | * |
| 140 | * 2 8/29/97 1:49p Samir |
| 141 | * Added toggliing slide. |
| 142 | * |
| 143 | * 8 4/24/97 12:10p Samir |
| 144 | * Added weapon firing for primary and secondary weapons. |
| 145 | * |
| 146 | * 7 4/23/97 1:06p Samir |
| 147 | * Implemented Suspend and Resume Controls as well as newer control system |
| 148 | * |
| 149 | * 6 4/17/97 2:48p Samir |
| 150 | * ReadFlyingControls renamed from read_flying_controls to match naming |
| 151 | * convention rules. |
| 152 | * |
| 153 | * 5 4/16/97 1:03p Samir |
| 154 | * Added fire primary button information |
| 155 | * |
| 156 | * 4 4/14/97 3:29p Samir |
| 157 | * Implemented game controls structure. |
| 158 | * |
| 159 | * 3 4/14/97 12:55p Samir |
| 160 | * Added primary fire button |
| 161 | * |
| 162 | * 2 4/11/97 2:15p Samir |
| 163 | * game controls functions defined for movement. |
| 164 | * |
| 165 | * $NoKeywords: $ |
| 166 | */ |
| 167 | |
| 168 | #ifndef CONTROLS_H |
| 169 | #define CONTROLS_H |
| 170 | |
| 171 | #include "object.h" |
| 172 | #include "Controller.h" |
| 173 | |
| 174 | class gameController; |
| 175 | class pilot; |
| 176 | |
| 177 | #define READF_MOUSE 0x2 |
| 178 | #define READF_JOY 0x1 |
| 179 | #define JOY_AXIS_SENS_RANGE 4.0f |
| 180 | #define MSE_AXIS_SENS_RANGE 4.0f |
| 181 | |
| 182 | // used to set or get axis sensitivity |
| 183 | #define HEADING_AXIS 0 |
| 184 | #define PITCH_AXIS 1 |
| 185 | #define BANK_AXIS 2 |
| 186 | #define HORIZONTAL_AXIS 3 |
| 187 | #define VERTICAL_AXIS 4 |
| 188 | #define THROTTLE_AXIS 5 |
| 189 | |
| 190 | // Controller functions |
| 191 | const int NUM_CTLFUNCS_DEMOv1_0 = 63; |
| 192 | const int NUM_CONTROLLER_FUNCTIONS = 73; |
| 193 | |
| 194 | const int ctfFORWARD_THRUSTAXIS = 0, ctfFORWARD_THRUSTKEY = 1, ctfREVERSE_THRUSTKEY = 2, ctfUP_THRUSTAXIS = 3, |
| 195 | ctfUP_THRUSTKEY = 4, ctfDOWN_THRUSTKEY = 5, ctfRIGHT_THRUSTAXIS = 6, ctfRIGHT_THRUSTKEY = 7, |
| 196 | ctfLEFT_THRUSTKEY = 8, ctfPITCH_DOWNAXIS = 9, ctfPITCH_DOWNKEY = 10, ctfPITCH_UPKEY = 11, |
| 197 | ctfBANK_RIGHTAXIS = 12, ctfBANK_RIGHTKEY = 13, ctfBANK_LEFTKEY = 14, ctfHEADING_RIGHTAXIS = 15, |
| 198 | ctfHEADING_RIGHTKEY = 16, ctfHEADING_LEFTKEY = 17, ctfFIREPRIMARY_BUTTON = 18, ctfFIREPRIMARY_KEY = 19, |
| 199 | ctfFIREPRIMARY_KEY2 = 20, ctfFIRESECONDARY_BUTTON = 21, ctfFIRESECONDARY_KEY = 22, ctfTOGGLE_SLIDEKEY = 23, |
| 200 | ctfTOGGLE_SLIDEBUTTON = 24, ctfFIREFLARE_KEY = 25, ctfFIREFLARE_BUTTON = 26, ctfUP_BUTTON = 27, |
| 201 | ctfDOWN_BUTTON = 28, ctfLEFT_BUTTON = 29, ctfRIGHT_BUTTON = 30, ctfAFTERBURN_KEY = 31, |
| 202 | ctfAFTERBURN_BUTTON = 32, ctfFORWARD_BUTTON = 33, ctfREVERSE_BUTTON = 34, ctfTOGGLE_BANKKEY = 35, |
| 203 | ctfTOGGLE_BANKBUTTON = 36, ctfHEADING_LEFTBUTTON = 37, ctfHEADING_RIGHTBUTTON = 38, ctfPITCH_UPBUTTON = 39, |
| 204 | ctfPITCH_DOWNBUTTON = 40, ctfBANK_LEFTBUTTON = 41, ctfBANK_RIGHTBUTTON = 42, ctfAUTOMAP_KEY = 43, |
| 205 | ctfPREV_INVKEY = 44, ctfNEXT_INVKEY = 45, ctfINV_USEKEY = 46, ctfPREV_CNTMSKEY = 47, ctfNEXT_CNTMSKEY = 48, |
| 206 | ctfCNTMS_USEKEY = 49, ctfHEADLIGHT_KEY = 50, ctfHEADLIGHT_BUTTON = 51, ctfAUTOMAP_BUTTON = 52, |
| 207 | ctfPREV_INVBTN = 53, ctfNEXT_INVBTN = 54, ctfINV_USEBTN = 55, ctfPREV_CNTMSBTN = 56, ctfNEXT_CNTMSBTN = 57, |
| 208 | ctfCNTMS_USEBTN = 58, ctfWPNSEL_PCYCLEKEY = 59, ctfWPNSEL_PCYCLEBTN = 60, ctfWPNSEL_SCYCLEKEY = 61, |
| 209 | ctfWPNSEL_SCYCLEBTN = 62, ctfREARVIEW_KEY = 63, ctfREARVIEW_BTN = 64, ctfAUDIOTAUNT1_KEY = 65, |
| 210 | ctfAUDIOTAUNT1_BTN = 66, ctfAUDIOTAUNT2_KEY = 67, ctfAUDIOTAUNT2_BTN = 68, ctfAUDIOTAUNT3_KEY = 69, |
| 211 | ctfAUDIOTAUNT3_BTN = 70, ctfAUDIOTAUNT4_KEY = 71, ctfAUDIOTAUNT4_BTN = 72; |
| 212 | |
| 213 | struct game_controls { |
| 214 | // movement values |
| 215 | // these values are from -1.0 to 1.0.- |
| 216 | float pitch_thrust; |
| 217 | float heading_thrust; |
| 218 | float bank_thrust; |
| 219 | float vertical_thrust; |
| 220 | float sideways_thrust; |
| 221 | float forward_thrust; |
| 222 | float afterburn_thrust; |
| 223 | |
| 224 | // these values modify thrust |
| 225 | bool toggle_slide; |
| 226 | bool toggle_bank; |
| 227 | |
| 228 | // this is for weapon control |
| 229 | int fire_primary_down_count; |
| 230 | bool fire_primary_down_state; |
| 231 | float fire_primary_down_time; |
| 232 | int fire_secondary_down_count; |
| 233 | bool fire_secondary_down_state; |
| 234 | float fire_secondary_down_time; |
| 235 | |
| 236 | // The flare |
| 237 | int fire_flare_down_count; |
| 238 | int rearview_down_count; |
| 239 | bool rearview_down_state; |
| 240 | }; |
| 241 | |
| 242 | // This value should be set at initialization time. Use for remote controlling. |
| 243 | extern char *Controller_ip; |
| 244 | |
| 245 | // Controller object. |
| 246 | extern gameController *Controller; |
| 247 | |
| 248 | // determines if controller is being polled. |
| 249 | extern bool Control_poll_flag; |
| 250 | |
| 251 | // |
| 252 | extern ct_function Controller_needs[NUM_CONTROLLER_FUNCTIONS]; |
| 253 | |
| 254 | // initializes control system |
| 255 | void InitControls(); |
| 256 | void CloseControls(); |
| 257 | |
| 258 | // polls controller at a certain framerate. |
| 259 | void PollControls(); |
| 260 | |
| 261 | // suspends and or resumes the control system. this deactivates or reactivates any |
| 262 | // preemptive controller polling we setup. |
| 263 | void SuspendControls(); |
| 264 | void ResumeControls(); |
| 265 | |
| 266 | // Read the keyboard & other controllers. Fills in the specified structure. |
| 267 | void ReadPlayerControls(game_controls *controls); |
| 268 | |
| 269 | // reinits the controller, hence restoring default controller configurations |
| 270 | void RestoreDefaultControls(); |
| 271 | |
| 272 | // load in controller configurations |
| 273 | void LoadControlConfig(pilot *plt = NULL); |
| 274 | |
| 275 | // save controller configurations. |
| 276 | void SaveControlConfig(pilot *plt = NULL); |
| 277 | |
| 278 | // Reads movement only |
| 279 | void DoMovement(game_controls *controls); |
| 280 | |
| 281 | #endif |