| 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.cpp $ |
| 21 | * $Revision: 106 $ |
| 22 | * $Date: 4/19/00 5:28p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Game controls processor |
| 26 | * |
| 27 | * $Log: /DescentIII/main/Controls.cpp $ |
| 28 | * |
| 29 | * 106 4/19/00 5:28p Matt |
| 30 | * From Duane for 1.4 |
| 31 | * Changed "ifdef Mac" to "ifndef Mac" |
| 32 | * |
| 33 | * 105 3/20/00 12:03p Matt |
| 34 | * Merge of Duane's post-1.3 changes. |
| 35 | * Misc Mac controller stuff (Mac only) |
| 36 | * |
| 37 | * 104 1/25/00 12:11a Jason |
| 38 | * Fixed keyboard ramping that got commented out during a mac merge. |
| 39 | * |
| 40 | * 103 10/22/99 1:16p Matt |
| 41 | * Fixed bug from previous integration. |
| 42 | * |
| 43 | * 102 10/22/99 1:12p Matt |
| 44 | * Mac merge |
| 45 | * |
| 46 | * 101 10/22/99 12:50p Matt |
| 47 | * Restored whitespace removed in version 99, and changed the controller |
| 48 | * table to its version 1.0 state. (This actually removes all the changes |
| 49 | * made for version 99.) |
| 50 | * |
| 51 | * 100 8/11/99 6:06p Samir |
| 52 | * mouse invert toggle slide functional. |
| 53 | * |
| 54 | * 99 7/28/99 4:20p Kevin |
| 55 | * Mac |
| 56 | * |
| 57 | * 98 7/20/99 4:53p Samir |
| 58 | * added ability to manually set the deadzone for a controller. |
| 59 | * |
| 60 | * 97 7/16/99 11:16a Samir |
| 61 | * fixed afterburner thrust clipping bug. |
| 62 | * |
| 63 | * 96 5/10/99 9:25p Jeff |
| 64 | * first phase of Rock 'n' Ride support added |
| 65 | * |
| 66 | * 95 4/30/99 10:52p Samir |
| 67 | * fixed energy-to-shield usage and made Load and Save COnfig take a |
| 68 | * pilot. |
| 69 | * |
| 70 | * 94 4/24/99 6:44p Jeff |
| 71 | * added functions for theif so he can steal things other than weapons |
| 72 | * |
| 73 | * 93 4/14/99 2:50a Jeff |
| 74 | * fixed some case mismatched #includes |
| 75 | * |
| 76 | * 92 4/01/99 11:27a Samir |
| 77 | * added default mouse button bindings. |
| 78 | * |
| 79 | * 91 3/25/99 9:57a Kevin |
| 80 | * Fixed the way toggle slide works |
| 81 | * |
| 82 | * 90 3/22/99 6:20p Jeff |
| 83 | * added 2 more audio taunts. a mulitplayer event when someone plays an |
| 84 | * audio taunt. option to disable audio taunts. |
| 85 | * |
| 86 | * 89 3/05/99 5:23p Samir |
| 87 | * joystick button audio taunt control fixed. |
| 88 | * |
| 89 | * 88 3/05/99 2:44p Samir |
| 90 | * needs to be cleaned up later, but mouse and joystick sensitivities are |
| 91 | * read in always, and set by the controller system. A cancel method |
| 92 | * needs to be implemented for these functions. |
| 93 | * |
| 94 | * 87 3/04/99 8:07p Samir |
| 95 | * pre assignment of r axis enabled once again. |
| 96 | * |
| 97 | * 86 3/01/99 12:19a Samir |
| 98 | * mask controller states on create controller. |
| 99 | * |
| 100 | * 85 2/26/99 2:13a Samir |
| 101 | * added audio taunt keys. |
| 102 | * |
| 103 | * 84 2/23/99 7:33p Samir |
| 104 | * don't configure bank through joystick by default. |
| 105 | * |
| 106 | * 83 2/23/99 2:00p Samir |
| 107 | * added keyboard ramping slider. |
| 108 | * |
| 109 | * 82 2/15/99 7:48p Jeff |
| 110 | * new pilot file class and read/write system checked in...should be more |
| 111 | * robust than old |
| 112 | * |
| 113 | * 81 2/09/99 1:28a Jeff |
| 114 | * added code to let D3 process multiplayer games in the background if |
| 115 | * game is not in focus. |
| 116 | * |
| 117 | * 80 2/06/99 6:58p Jeff |
| 118 | * removed mprintf for suspend/resume (annoying in automap) |
| 119 | * |
| 120 | * 79 2/04/99 4:22p Jeff |
| 121 | * put in sanity mprintf's in suspend/resume controls |
| 122 | * |
| 123 | * 78 1/31/99 7:25p Matt |
| 124 | * Renamed a bunch of functions to have HUD capitalized |
| 125 | * |
| 126 | * 77 1/28/99 3:58p Jeff |
| 127 | * localization update |
| 128 | * |
| 129 | * 76 1/06/99 6:45p Kevin |
| 130 | * |
| 131 | * 75 12/14/98 11:06a Jason |
| 132 | * changes for 1.1 |
| 133 | * |
| 134 | * 74 12/08/98 10:27a Samir |
| 135 | * default player controls include mouse controls. |
| 136 | * |
| 137 | * 73 12/07/98 5:37p Jason |
| 138 | * first pass at automap |
| 139 | * |
| 140 | * 72 12/03/98 11:06a Samir |
| 141 | * added axis sensitivity |
| 142 | * |
| 143 | * 71 12/02/98 7:02p Samir |
| 144 | * reduces key pitch and heading ramp times. |
| 145 | * |
| 146 | * 70 12/02/98 12:23p Samir |
| 147 | * fixed behavior of bank and slide toggles so they are read before both |
| 148 | * keyboard and joystick. |
| 149 | * |
| 150 | * 69 12/02/98 11:37a Samir |
| 151 | * improved ramping of keyboard. |
| 152 | * |
| 153 | * 68 11/30/98 4:56p Samir |
| 154 | * oops. took out mprintf. |
| 155 | * |
| 156 | * 67 11/30/98 4:54p Samir |
| 157 | * added rear view config item. |
| 158 | * |
| 159 | * 66 11/30/98 1:09p Samir |
| 160 | * added rear view toggle. |
| 161 | * |
| 162 | * 65 10/24/98 2:16p Samir |
| 163 | * moved pollcontrols to controls.cpp, readplayercontrols. |
| 164 | * |
| 165 | * 64 10/22/98 4:11p Samir |
| 166 | * put inventory keys back in. |
| 167 | * |
| 168 | * 63 10/22/98 2:40p Samir |
| 169 | * took out inventory keys for demo. |
| 170 | * |
| 171 | * 62 10/21/98 11:55p Samir |
| 172 | * added sensitivity slider functionality. |
| 173 | * |
| 174 | * 61 10/21/98 7:03p Samir |
| 175 | * D2 Default controls |
| 176 | * |
| 177 | * 60 10/21/98 10:36a Samir |
| 178 | * added code to turn on or off joystick or mouse. |
| 179 | * |
| 180 | * 59 10/18/98 7:24p Samir |
| 181 | * cycle down weapons, use Frametime for controller buttons. |
| 182 | * |
| 183 | * 58 10/17/98 7:32p Samir |
| 184 | * added to controller needs, the extra flags section per function. |
| 185 | * |
| 186 | * 57 10/14/98 1:02p Jason |
| 187 | * fixed FindSoundName issues |
| 188 | * |
| 189 | * 56 10/12/98 5:12p Samir |
| 190 | * toggle bank key works. |
| 191 | * |
| 192 | * 55 10/11/98 2:58a Jeff |
| 193 | * hooked in Automap key |
| 194 | * |
| 195 | * 54 10/08/98 6:43p Samir |
| 196 | * took out mprintf. |
| 197 | * |
| 198 | * 53 10/08/98 1:24p Samir |
| 199 | * use ramping technique for keyboard pitch and heading. |
| 200 | * |
| 201 | * 52 10/08/98 10:52a Samir |
| 202 | * added countermeasure and weapon cycling. |
| 203 | * |
| 204 | * 51 9/28/98 10:07a Jason |
| 205 | * fixed MISC keyboard input while inputting messages |
| 206 | * |
| 207 | * 50 9/21/98 3:21p Jason |
| 208 | * bound headlight to a key |
| 209 | * |
| 210 | * 49 9/17/98 3:24p Samir |
| 211 | * added headlight configuration. |
| 212 | * |
| 213 | * 48 9/01/98 5:11p Samir |
| 214 | * no additvie afterburner control. |
| 215 | * |
| 216 | * 47 8/31/98 6:49p Jeff |
| 217 | * made inventory and countermeasure keys customizable |
| 218 | * |
| 219 | * 46 8/31/98 12:39p Samir |
| 220 | * added code to resume controllers when restoring game mode. |
| 221 | * |
| 222 | * 45 8/15/98 2:45p Matt |
| 223 | * Took out unneeded include |
| 224 | * |
| 225 | * 44 6/29/98 7:17p Samir |
| 226 | * took out annoying mprintf |
| 227 | * |
| 228 | * 43 6/29/98 6:42p Samir |
| 229 | * Properly handle controller pausing and resumption. |
| 230 | * |
| 231 | * 42 6/18/98 4:44p Samir |
| 232 | * added changes for multiple configs for joystick controls. |
| 233 | * |
| 234 | * 41 6/16/98 10:38a Jeff |
| 235 | * localization, strings pulled out to stringtable.h and d3.str |
| 236 | * |
| 237 | * 40 5/28/98 1:08p Samir |
| 238 | * flipped bank button calcs. |
| 239 | * |
| 240 | * 39 5/26/98 7:09p Samir |
| 241 | * pitch now 75% of maximum instead of 50% as asked by Chris and Craig. |
| 242 | * |
| 243 | * 38 5/19/98 3:36p Samir |
| 244 | * added automap key. |
| 245 | * |
| 246 | * 37 5/12/98 3:04p Samir |
| 247 | * added button control for pbh. |
| 248 | * |
| 249 | * 36 5/12/98 10:38a Samir |
| 250 | * pitch rate halved. |
| 251 | * |
| 252 | * 35 5/11/98 4:53p Samir |
| 253 | * added axis sliding, config. |
| 254 | * |
| 255 | * 34 5/01/98 3:52p Samir |
| 256 | * fixed up hat and keyboard sliding. |
| 257 | * |
| 258 | * 33 4/30/98 7:00p Samir |
| 259 | * reset afterburner thrust every frame. |
| 260 | * |
| 261 | * 32 4/28/98 11:45a Samir |
| 262 | * make keyboard controls match to framerate. |
| 263 | * |
| 264 | * 31 4/27/98 7:24p Samir |
| 265 | * poll controller at specified rate. |
| 266 | * |
| 267 | * 30 4/09/98 2:22p Jason |
| 268 | * added guided/afterburner stuff |
| 269 | * |
| 270 | * 29 4/08/98 3:44p Samir |
| 271 | * added toggle bank and configuration for afterburner |
| 272 | * |
| 273 | * 28 4/02/98 7:58p Samir |
| 274 | * Fixed up control setting saving and restoring. |
| 275 | * |
| 276 | * 27 3/24/98 11:21a Samir |
| 277 | * adjusted key sensitivity. |
| 278 | * |
| 279 | * 26 3/20/98 1:19p Jeff |
| 280 | * Changes made to use Default_pilot string for pilot filename to use. |
| 281 | * |
| 282 | * 25 3/16/98 3:53p Jason |
| 283 | * added hud input message stuff |
| 284 | * |
| 285 | * 24 3/16/98 3:26p Samir |
| 286 | * Fixed controller need ID and index discrepancy. |
| 287 | * |
| 288 | * 23 3/16/98 11:03a Luke |
| 289 | * Don't reset controls again., |
| 290 | * |
| 291 | * 22 3/13/98 8:55p Jeff |
| 292 | * Various changes to move control configuration into Pilot file |
| 293 | * |
| 294 | * 21 3/10/98 5:21p Samir |
| 295 | * banking should be proper. |
| 296 | * |
| 297 | * 20 3/02/98 5:54p Samir |
| 298 | * Don't run any controls if not in game interface mode. |
| 299 | * |
| 300 | * 19 2/16/98 9:27p Samir |
| 301 | * Added banking. |
| 302 | * |
| 303 | * 18 2/16/98 3:01p Samir |
| 304 | * Added fire_primary_down_state and changed some configuration. |
| 305 | * |
| 306 | * 17 2/15/98 7:06p Samir |
| 307 | * Added functions to save controller state. |
| 308 | * |
| 309 | * 16 2/12/98 8:48p Matt |
| 310 | * Changed controls system to keep the reading of the controls seperate |
| 311 | * from using the results. Got rid of the Controls global. |
| 312 | * |
| 313 | * 15 1/23/98 6:25p Jason |
| 314 | * Got spray weapons working |
| 315 | * |
| 316 | * 14 1/12/98 6:28p Samir |
| 317 | * New keys for sliding and use RCTRL for firing too. |
| 318 | * |
| 319 | * 13 12/10/97 12:18p Samir |
| 320 | * Tooke oute annoiing printe Fs. |
| 321 | * |
| 322 | * 12 12/10/97 11:16a Samir |
| 323 | * Joystick button timing should be fixed. |
| 324 | * |
| 325 | * 11 12/05/97 12:49p Samir |
| 326 | * Much better hat sliding. |
| 327 | * |
| 328 | * 10 12/05/97 10:59a Samir |
| 329 | * Somewhat revised controls for keyboard. Joystick now has variable |
| 330 | * sensitivity. |
| 331 | * |
| 332 | * 9 12/03/97 7:32p Samir |
| 333 | * More D2 like keyboard movement. |
| 334 | * |
| 335 | * 8 11/12/97 1:13p Jason |
| 336 | * added weapons that can ramp up |
| 337 | * |
| 338 | * 7 11/05/97 3:45p Samir |
| 339 | * InitControls will close the previous call to InitControls. |
| 340 | * |
| 341 | * 6 11/04/97 4:20p Samir |
| 342 | * replaced ctDigital with ctDownCount in some joystick button functions. |
| 343 | * |
| 344 | * 5 10/30/97 4:02p Matt |
| 345 | * Added the flare |
| 346 | * |
| 347 | * 4 9/04/97 4:01p Samir |
| 348 | * This should fix slide toggling with joystick. |
| 349 | * |
| 350 | * 3 8/29/97 1:49p Samir |
| 351 | * Added toggling slide. |
| 352 | * |
| 353 | * 2 8/20/97 5:03p Samir |
| 354 | * Fixed banking controls. |
| 355 | * |
| 356 | * 24 5/21/97 3:53p Samir |
| 357 | * changed ct_need to ct_function. |
| 358 | * |
| 359 | * 23 5/12/97 1:22p Samir |
| 360 | * Don't use timer hook functions anymore. taken care of in controller |
| 361 | * library. |
| 362 | * |
| 363 | * 22 4/24/97 2:09p Samir |
| 364 | * Fixed firing key problems. |
| 365 | * |
| 366 | * 21 4/24/97 12:32p Samir |
| 367 | * Fixed booboo in controls structure. |
| 368 | * |
| 369 | * 20 4/24/97 12:10p Samir |
| 370 | * Added weapon firing for primary and secondary weapons. |
| 371 | * |
| 372 | * 19 4/23/97 1:06p Samir |
| 373 | * Implemented Suspend and Resume Controls as well as newer control system |
| 374 | * |
| 375 | * 18 4/17/97 2:48p Samir |
| 376 | * ReadFlyingControls renamed from read_flying_controls to match naming |
| 377 | * convention rules. |
| 378 | * |
| 379 | * 17 4/16/97 3:28p Samir |
| 380 | * Poll twice for better keeping track of buttons. Should find a lot |
| 381 | * better way of doing this. |
| 382 | * |
| 383 | * 16 4/16/97 1:03p Samir |
| 384 | * Added fire primary button information |
| 385 | * |
| 386 | * 15 4/14/97 3:29p Samir |
| 387 | * Implemented game controls structure. |
| 388 | * |
| 389 | * 14 4/14/97 12:55p Samir |
| 390 | * Added primary fire button |
| 391 | * |
| 392 | * 13 4/11/97 5:11p Samir |
| 393 | * Added external controller throttle control. |
| 394 | * |
| 395 | * 12 4/11/97 4:54p Samir |
| 396 | * Fixed joystick pitch translation (invert for real flight stick control) |
| 397 | * |
| 398 | * 11 4/11/97 4:09 PM Jeremy |
| 399 | * changed include of "stdlib.h" to <stdlib.h> |
| 400 | * |
| 401 | * 10 4/11/97 2:14p Samir |
| 402 | * Revamped input of controller data. |
| 403 | * |
| 404 | * $NoKeywords: $ |
| 405 | */ |
| 406 | |
| 407 | #include "controls.h" |
| 408 | |
| 409 | #include "object.h" |
| 410 | #include "pserror.h" |
| 411 | #include "game.h" |
| 412 | #include "ddio.h" |
| 413 | #include "joystick.h" |
| 414 | #include "descent.h" |
| 415 | #include "mono.h" |
| 416 | #include "weapon.h" |
| 417 | #include "Controller.h" |
| 418 | #include "Macros.h" |
| 419 | #include "gamesequence.h" |
| 420 | #include "pilot.h" |
| 421 | #include "hud.h" |
| 422 | #include "stringtable.h" |
| 423 | #include "TelCom.h" |
| 424 | #include "multi.h" |
| 425 | #include "args.h" |
| 426 | |
| 427 | #include "player.h" |
| 428 | |
| 429 | #include "hlsoundlib.h" |
| 430 | #include "sounds.h" |
| 431 | #include "soundload.h" |
| 432 | |
| 433 | #include <stdlib.h> |
| 434 | #include <memory.h> |
| 435 | |
| 436 | float Key_ramp_speed = 0.5f; |
| 437 | |
| 438 | #define CONTROL_POLL_RATE (1.0f / 25.0f) |
| 439 | #define KEY_RAMPUP_TIME Key_ramp_speed |
| 440 | #define POV_SENSITIVITY 1.3f |
| 441 | #define LIMIT_PITCH 0.75f |
| 442 | #define LIMIT_HEADING 1.0f |
| 443 | #define LIMIT_BANK 1.0f |
| 444 | #define LIMIT_HORIZ 1.0f |
| 445 | #define LIMIT_VERT 1.0f |
| 446 | #define LIMIT_FORWARD 1.0f |
| 447 | |
| 448 | struct tSensitivity { |
| 449 | float p, b, h, x, y, z; |
| 450 | float op, ob, oh, ox, oy, oz; |
| 451 | }; |
| 452 | |
| 453 | // GLOBALS |
| 454 | |
| 455 | char *Controller_ip = NULL; // IP of controller, if any. |
| 456 | gameController *Controller = NULL; |
| 457 | bool Control_poll_flag = false; // determines if system is polling controls now. |
| 458 | |
| 459 | static bool Control_system_init = false; |
| 460 | static float Control_interval_time = 0.0f; |
| 461 | static float Control_current_time; |
| 462 | static float Control_frametime; |
| 463 | static float Key_pitch_ramp_time = 0.0f; |
| 464 | static float Key_heading_ramp_time = 0.0f; |
| 465 | |
| 466 | static tSensitivity Key_ramp; |
| 467 | |
| 468 | // PROTOTYPES |
| 469 | |
| 470 | static void DoKeyboardMovement(game_controls *controls); |
| 471 | static void DoControllerMovement(game_controls *controls); |
| 472 | static void DoWeapons(game_controls *controls); |
| 473 | static void DoKeyboardWeapons(game_controls *controls); |
| 474 | static void DoControllerWeapons(game_controls *controls); |
| 475 | static void DoMisc(game_controls *contols); |
| 476 | static void DoKeyboardMisc(game_controls *controls); |
| 477 | static void DoControllerMisc(game_controls *controls); |
| 478 | // MTS: no implementation! |
| 479 | void DoCommands(); |
| 480 | |
| 481 | static void ToggleHeadlightControlState(); |
| 482 | |
| 483 | // LIST OF NEEDS |
| 484 | ct_function Controller_needs[NUM_CONTROLLER_FUNCTIONS] = { |
| 485 | {ctfFORWARD_THRUSTAXIS, ctAnalog, ctAxis, ctAxis, 0, 0, 0, 0}, |
| 486 | {ctfFORWARD_THRUSTKEY, ctTime, ctKey, ctKey, KEY_A, 0, 0, 0}, |
| 487 | {ctfREVERSE_THRUSTKEY, ctTime, ctKey, ctKey, KEY_Z, 0, 0, 0}, |
| 488 | {ctfFORWARD_BUTTON, ctTime, ctButton, ctButton, 0, 0, 0, 0}, |
| 489 | {ctfREVERSE_BUTTON, ctTime, ctButton, ctButton, 0, 0, 0, 0}, |
| 490 | {ctfUP_THRUSTAXIS, ctAnalog, ctAxis, ctAxis, CT_V_AXIS, 0, 0, 0}, |
| 491 | {ctfUP_BUTTON, ctDigital, ctPOV, ctButton, JOYPOV_UP, 0, 0, 0}, |
| 492 | {ctfUP_THRUSTKEY, ctTime, ctKey, ctKey, KEY_PADMINUS, 0, 0, 0}, |
| 493 | {ctfDOWN_BUTTON, ctDigital, ctPOV, ctButton, JOYPOV_DOWN, 0, 0, 0}, |
| 494 | {ctfDOWN_THRUSTKEY, ctTime, ctKey, ctKey, KEY_PADPLUS, 0, 0, 0}, |
| 495 | {ctfRIGHT_THRUSTAXIS, ctAnalog, ctAxis, ctAxis, CT_U_AXIS, 0, 0, 0}, |
| 496 | {ctfRIGHT_BUTTON, ctDigital, ctPOV, ctButton, JOYPOV_RIGHT, 0, 0, 0}, |
| 497 | {ctfRIGHT_THRUSTKEY, ctTime, ctKey, ctKey, KEY_PAD3, 0, 0, 0}, |
| 498 | {ctfLEFT_BUTTON, ctDigital, ctPOV, ctButton, JOYPOV_LEFT, 0, 0, 0}, |
| 499 | {ctfLEFT_THRUSTKEY, ctTime, ctKey, ctKey, KEY_PAD1, 0, 0, 0}, |
| 500 | {ctfPITCH_DOWNAXIS, ctAnalog, ctAxis, ctMouseAxis, CT_Y_AXIS, CT_Y_AXIS, 0, 0}, |
| 501 | {ctfPITCH_DOWNKEY, ctTime, ctKey, ctKey, KEY_UP, KEY_PAD8, 0, 0}, |
| 502 | {ctfPITCH_DOWNBUTTON, ctDigital, ctButton, ctButton, 0, 0, 0, 0}, |
| 503 | {ctfPITCH_UPKEY, ctTime, ctKey, ctKey, KEY_DOWN, KEY_PAD2, 0, 0}, |
| 504 | {ctfPITCH_UPBUTTON, ctDigital, ctButton, ctButton, 0, 0, 0, 0}, |
| 505 | {ctfBANK_RIGHTAXIS, ctAnalog, ctAxis, ctAxis, CT_R_AXIS, 0, 0, 0}, |
| 506 | {ctfBANK_RIGHTKEY, ctTime, ctKey, ctKey, KEY_E, KEY_PAD9, 0, 0}, |
| 507 | {ctfBANK_RIGHTBUTTON, ctDigital, ctButton, ctButton, 0, 0, 0, 0}, |
| 508 | {ctfBANK_LEFTKEY, ctTime, ctKey, ctKey, KEY_Q, KEY_PAD7, 0, 0}, |
| 509 | {ctfBANK_LEFTBUTTON, ctDigital, ctButton, ctButton, 0, 0, 0, 0}, |
| 510 | {ctfHEADING_RIGHTAXIS, ctAnalog, ctAxis, ctMouseAxis, CT_X_AXIS, CT_X_AXIS, 0, 0}, |
| 511 | {ctfHEADING_RIGHTKEY, ctTime, ctKey, ctKey, KEY_RIGHT, KEY_PAD6, 0, 0}, |
| 512 | {ctfHEADING_RIGHTBUTTON, ctDigital, ctButton, ctButton, 0, 0, 0, 0}, |
| 513 | {ctfHEADING_LEFTKEY, ctTime, ctKey, ctKey, KEY_LEFT, KEY_PAD4, 0, 0}, |
| 514 | {ctfHEADING_LEFTBUTTON, ctDigital, ctButton, ctButton, 0, 0, 0, 0}, |
| 515 | {ctfFIREPRIMARY_BUTTON, ctTime, ctButton, ctMouseButton, 1, 1, 0, 0}, |
| 516 | {ctfFIREPRIMARY_KEY, ctTime, ctKey, ctKey, KEY_LCTRL, KEY_RCTRL, 0, 0}, |
| 517 | {ctfFIREPRIMARY_KEY2, ctTime, ctKey, ctKey, 0, 0, 0, 0}, |
| 518 | {ctfFIRESECONDARY_BUTTON, ctTime, ctButton, ctMouseButton, 2, 2, 0, 0}, |
| 519 | {ctfFIRESECONDARY_KEY, ctTime, ctKey, ctKey, KEY_SPACEBAR, 0, 0, 0}, |
| 520 | {ctfTOGGLE_SLIDEBUTTON, ctTime, ctButton, ctButton, 0, 0, 0, 0}, |
| 521 | {ctfTOGGLE_SLIDEKEY, ctTime, ctKey, ctKey, KEY_LALT, 0, 0, 0}, |
| 522 | {ctfTOGGLE_BANKBUTTON, ctTime, ctButton, ctButton, 0, 0, 0, 0}, |
| 523 | {ctfTOGGLE_BANKKEY, ctTime, ctKey, ctKey, 0, 0, 0, 0}, |
| 524 | {ctfFIREFLARE_BUTTON, ctTime, ctButton, ctMouseButton, 3, 3, 0, 0}, |
| 525 | {ctfFIREFLARE_KEY, ctDownCount, ctKey, ctKey, KEY_F, 0, 0, 0}, |
| 526 | {ctfAFTERBURN_BUTTON, ctTime, ctButton, ctButton, 0, 0, 0, 0}, |
| 527 | {ctfAFTERBURN_KEY, ctTime, ctKey, ctKey, KEY_S, 0, 0, 0}, |
| 528 | {ctfAUTOMAP_KEY, ctDownCount, ctKey, ctKey, KEY_TAB, 0, 0, 0}, |
| 529 | {ctfPREV_INVKEY, ctDownCount, ctKey, ctKey, KEY_LBRACKET, 0, 0, 0}, |
| 530 | {ctfNEXT_INVKEY, ctDownCount, ctKey, ctKey, KEY_RBRACKET, 0, 0, 0}, |
| 531 | {ctfINV_USEKEY, ctDownCount, ctKey, ctKey, KEY_BACKSLASH, 0, 0, 0}, |
| 532 | {ctfPREV_CNTMSKEY, ctDownCount, ctKey, ctKey, KEY_SEMICOL, 0, 0, 0}, |
| 533 | {ctfNEXT_CNTMSKEY, ctDownCount, ctKey, ctKey, KEY_RAPOSTRO, 0, 0, 0}, |
| 534 | {ctfCNTMS_USEKEY, ctDownCount, ctKey, ctKey, KEY_ENTER, 0, 0, 0}, |
| 535 | {ctfHEADLIGHT_KEY, ctDownCount, ctKey, ctKey, KEY_H, 0, 0, 0}, |
| 536 | {ctfHEADLIGHT_BUTTON, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 537 | {ctfAUTOMAP_BUTTON, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 538 | {ctfPREV_INVBTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 539 | {ctfNEXT_INVBTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 540 | {ctfINV_USEBTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 541 | {ctfPREV_CNTMSBTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 542 | {ctfNEXT_CNTMSBTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 543 | {ctfCNTMS_USEBTN, ctDownCount, ctButton, ctMouseButton, 4, 4, 0, 0}, |
| 544 | {ctfWPNSEL_PCYCLEKEY, ctDownCount, ctKey, ctKey, KEY_COMMA, 0, 0, 0}, |
| 545 | {ctfWPNSEL_PCYCLEBTN, ctDownCount, ctButton, ctMouseButton, 0, 5, 0, 0}, |
| 546 | {ctfWPNSEL_SCYCLEKEY, ctDownCount, ctKey, ctKey, KEY_PERIOD, 0, 0, 0}, |
| 547 | {ctfWPNSEL_SCYCLEBTN, ctDownCount, ctButton, ctMouseButton, 0, 6, 0, 0}, |
| 548 | {ctfREARVIEW_KEY, ctDownCount, ctKey, ctKey, KEY_R, 0, 0, 0}, |
| 549 | {ctfREARVIEW_BTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 550 | {ctfAUDIOTAUNT1_KEY, ctDownCount, ctKey, ctKey, 0, 0, 0, 0}, |
| 551 | {ctfAUDIOTAUNT1_BTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 552 | {ctfAUDIOTAUNT2_KEY, ctDownCount, ctKey, ctKey, 0, 0, 0, 0}, |
| 553 | {ctfAUDIOTAUNT2_BTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 554 | {ctfAUDIOTAUNT3_KEY, ctDownCount, ctKey, ctKey, 0, 0, 0, 0}, |
| 555 | {ctfAUDIOTAUNT3_BTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}, |
| 556 | {ctfAUDIOTAUNT4_KEY, ctDownCount, ctKey, ctKey, 0, 0, 0, 0}, |
| 557 | {ctfAUDIOTAUNT4_BTN, ctDownCount, ctButton, ctButton, 0, 0, 0, 0}}; |
| 558 | |
| 559 | // ramping macros |
| 560 | static inline float ramp_control_value(float val, float limit, float &ramp_state, float &old_ramp_delta) { |
| 561 | float sign = val / fabs(val), old_sign = old_ramp_delta / fabs(old_ramp_delta); |
| 562 | if (sign != old_sign) |
| 563 | ramp_state = -ramp_state; |
| 564 | ramp_state = (val != 0) ? (ramp_state + val) : 0.0f; |
| 565 | ramp_state = (ramp_state > limit) ? limit : (ramp_state < -limit) ? (-limit) : ramp_state; |
| 566 | old_ramp_delta = val; |
| 567 | |
| 568 | return ramp_state; |
| 569 | } |
| 570 | |
| 571 | // INITIALIZATION FUNCTIONS |
| 572 | |
| 573 | void InitControls() { |
| 574 | // Create controller object |
| 575 | if (Control_system_init) |
| 576 | return; |
| 577 | |
| 578 | Control_system_init = true; |
| 579 | |
| 580 | Controller = CreateController(NUM_CONTROLLER_FUNCTIONS, Controller_needs, Controller_ip); |
| 581 | if (Controller == NULL) |
| 582 | Error(TXT_ERRUNINITCNT); |
| 583 | Controller->mask_controllers(false, false); |
| 584 | Controller->mask_controllers(true, true); |
| 585 | |
| 586 | Controller->mask_controllers((Current_pilot.read_controller & READF_JOY) ? true : false, |
| 587 | (Current_pilot.read_controller & READF_MOUSE) ? true : false); |
| 588 | |
| 589 | Controller->set_axis_sensitivity(ctMouseAxis, CT_X_AXIS, Current_pilot.mouse_sensitivity[0]); |
| 590 | Controller->set_axis_sensitivity(ctMouseAxis, CT_Y_AXIS, Current_pilot.mouse_sensitivity[1]); |
| 591 | Controller->set_axis_sensitivity(ctMouseAxis, CT_Z_AXIS, Current_pilot.mouse_sensitivity[0]); |
| 592 | Controller->set_axis_sensitivity(ctAxis, CT_X_AXIS, Current_pilot.joy_sensitivity[0]); |
| 593 | Controller->set_axis_sensitivity(ctAxis, CT_Y_AXIS, Current_pilot.joy_sensitivity[1]); |
| 594 | Controller->set_axis_sensitivity(ctAxis, CT_Z_AXIS, Current_pilot.joy_sensitivity[2]); |
| 595 | Controller->set_axis_sensitivity(ctAxis, CT_R_AXIS, Current_pilot.joy_sensitivity[3]); |
| 596 | Controller->set_axis_sensitivity(ctAxis, CT_U_AXIS, Current_pilot.joy_sensitivity[4]); |
| 597 | Controller->set_axis_sensitivity(ctAxis, CT_V_AXIS, Current_pilot.joy_sensitivity[5]); |
| 598 | |
| 599 | int i; |
| 600 | i = FindArg("-deadzone0"); |
| 601 | if (i > 0) { |
| 602 | Controller->set_controller_deadzone(0, atof(GameArgs[i + 1])); |
| 603 | } |
| 604 | i = FindArg("-deadzone1"); |
| 605 | if (i > 0) { |
| 606 | Controller->set_controller_deadzone(1, atof(GameArgs[i + 1])); |
| 607 | } |
| 608 | |
| 609 | Key_ramp_speed = Current_pilot.key_ramping; // DAJ added to restore ramping |
| 610 | |
| 611 | SuspendControls(); |
| 612 | |
| 613 | // start controller time. |
| 614 | Control_current_time = Control_interval_time = timer_GetTime(); |
| 615 | Key_ramp.op = Key_ramp.p = 0.0f; |
| 616 | Key_ramp.ob = Key_ramp.b = 0.0f; |
| 617 | Key_ramp.oh = Key_ramp.h = 0.0f; |
| 618 | Key_ramp.ox = Key_ramp.x = 0.0f; |
| 619 | Key_ramp.oy = Key_ramp.y = 0.0f; |
| 620 | Key_ramp.oz = Key_ramp.z = 0.0f; |
| 621 | |
| 622 | // Initialize preemptive controller system for non-positonal data. |
| 623 | mprintf(0, "Initialized control system.\n"); |
| 624 | } |
| 625 | |
| 626 | void CloseControls() { |
| 627 | if (!Control_system_init) |
| 628 | return; |
| 629 | ResumeControls(); |
| 630 | DestroyController(Controller); |
| 631 | Controller = NULL; |
| 632 | mprintf(0, "Closing control system.\n"); |
| 633 | Control_system_init = false; |
| 634 | } |
| 635 | |
| 636 | // reinits the controller, hence restoring default controller configurations |
| 637 | void RestoreDefaultControls() { |
| 638 | ResumeControls(); |
| 639 | DestroyController(Controller); |
| 640 | Controller = CreateController(NUM_CONTROLLER_FUNCTIONS, Controller_needs, Controller_ip); |
| 641 | if (Controller == NULL) |
| 642 | Error(TXT_ERRUNINITCNT); |
| 643 | SuspendControls(); |
| 644 | |
| 645 | Controller->mask_controllers((Current_pilot.read_controller & READF_JOY) ? true : false, |
| 646 | (Current_pilot.read_controller & READF_MOUSE) ? true : false); |
| 647 | Controller->set_axis_sensitivity(ctMouseAxis, CT_X_AXIS, Current_pilot.mouse_sensitivity[0]); |
| 648 | Controller->set_axis_sensitivity(ctMouseAxis, CT_Y_AXIS, Current_pilot.mouse_sensitivity[1]); |
| 649 | Controller->set_axis_sensitivity(ctMouseAxis, CT_Z_AXIS, Current_pilot.mouse_sensitivity[0]); |
| 650 | Controller->set_axis_sensitivity(ctAxis, CT_X_AXIS, Current_pilot.joy_sensitivity[0]); |
| 651 | Controller->set_axis_sensitivity(ctAxis, CT_Y_AXIS, Current_pilot.joy_sensitivity[1]); |
| 652 | Controller->set_axis_sensitivity(ctAxis, CT_Z_AXIS, Current_pilot.joy_sensitivity[2]); |
| 653 | Controller->set_axis_sensitivity(ctAxis, CT_R_AXIS, Current_pilot.joy_sensitivity[3]); |
| 654 | Controller->set_axis_sensitivity(ctAxis, CT_U_AXIS, Current_pilot.joy_sensitivity[4]); |
| 655 | Controller->set_axis_sensitivity(ctAxis, CT_V_AXIS, Current_pilot.joy_sensitivity[5]); |
| 656 | } |
| 657 | |
| 658 | void SuspendControls() { |
| 659 | if (!Controller) |
| 660 | return; |
| 661 | |
| 662 | Control_poll_flag = false; |
| 663 | Controller->suspend(); |
| 664 | } |
| 665 | |
| 666 | void ResumeControls() { |
| 667 | if (!Controller) |
| 668 | return; |
| 669 | |
| 670 | Controller->resume(); |
| 671 | Controller->flush(); |
| 672 | ddio_KeyFlush(); |
| 673 | ddio_MouseQueueFlush(); |
| 674 | |
| 675 | Control_poll_flag = true; |
| 676 | |
| 677 | // set pilot defaults for controller outside of assignment |
| 678 | Controller->mask_controllers((Current_pilot.read_controller & READF_JOY) ? true : false, |
| 679 | (Current_pilot.read_controller & READF_MOUSE) ? true : false); |
| 680 | Controller->set_axis_sensitivity(ctMouseAxis, CT_X_AXIS, Current_pilot.mouse_sensitivity[0]); |
| 681 | Controller->set_axis_sensitivity(ctMouseAxis, CT_Y_AXIS, Current_pilot.mouse_sensitivity[1]); |
| 682 | Controller->set_axis_sensitivity(ctMouseAxis, CT_Z_AXIS, Current_pilot.mouse_sensitivity[0]); |
| 683 | Controller->set_axis_sensitivity(ctAxis, CT_X_AXIS, Current_pilot.joy_sensitivity[0]); |
| 684 | Controller->set_axis_sensitivity(ctAxis, CT_Y_AXIS, Current_pilot.joy_sensitivity[1]); |
| 685 | Controller->set_axis_sensitivity(ctAxis, CT_Z_AXIS, Current_pilot.joy_sensitivity[2]); |
| 686 | Controller->set_axis_sensitivity(ctAxis, CT_R_AXIS, Current_pilot.joy_sensitivity[3]); |
| 687 | Controller->set_axis_sensitivity(ctAxis, CT_U_AXIS, Current_pilot.joy_sensitivity[4]); |
| 688 | Controller->set_axis_sensitivity(ctAxis, CT_V_AXIS, Current_pilot.joy_sensitivity[5]); |
| 689 | |
| 690 | int i; |
| 691 | i = FindArg("-deadzone0"); |
| 692 | if (i > 0) { |
| 693 | Controller->set_controller_deadzone(0, atof(GameArgs[i + 1])); |
| 694 | } |
| 695 | i = FindArg("-deadzone1"); |
| 696 | if (i > 0) { |
| 697 | Controller->set_controller_deadzone(1, atof(GameArgs[i + 1])); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | // INTERFACE FUNCTIONS |
| 702 | |
| 703 | void PollControls() { |
| 704 | // only read at the specified rate to keep things consistant. manager control system timer |
| 705 | if (!Control_poll_flag) |
| 706 | return; |
| 707 | if (Controller) |
| 708 | Controller->poll(); |
| 709 | /* |
| 710 | Control_current_time += Frametime; |
| 711 | Control_frametime = Control_current_time - Control_interval_time; |
| 712 | if (Control_frametime >= CONTROL_POLL_RATE) { |
| 713 | Control_interval_time = Control_current_time; |
| 714 | if (Controller) |
| 715 | Controller->poll(); |
| 716 | } |
| 717 | */ |
| 718 | } |
| 719 | |
| 720 | // Read the keyboard & other controllers. Fills in the specified structure. |
| 721 | void ReadPlayerControls(game_controls *controls) { |
| 722 | if (!Control_system_init) { |
| 723 | memset(controls, 0, sizeof(game_controls)); |
| 724 | return; |
| 725 | } |
| 726 | //@@ Control_frametime = Frametime; |
| 727 | // keyboard uses game frametime |
| 728 | // controller uses polled control frametime |
| 729 | |
| 730 | if (!Control_poll_flag) { |
| 731 | memset(controls, 0, sizeof(game_controls)); |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | PollControls(); |
| 736 | DoWeapons(controls); // controls for weapon firing operations |
| 737 | DoMisc(controls); |
| 738 | DoMovement(controls); // controls for moving the object |
| 739 | |
| 740 | // only read at the specified rate to keep things consistant. manager control system timer |
| 741 | // Control_current_time += Frametime; |
| 742 | // Control_frametime = Control_current_time - Control_interval_time; |
| 743 | // if (Control_frametime >= CONTROL_POLL_RATE) { |
| 744 | // Control_interval_time = Control_current_time; |
| 745 | // DoMovement(controls); // controls for moving the object |
| 746 | // return 1; |
| 747 | //} |
| 748 | // else |
| 749 | // return 0; |
| 750 | } |
| 751 | |
| 752 | // --------------------------------------------------------------------------- |
| 753 | // CONTROL FUNCTIONS |
| 754 | // MOVEMENT |
| 755 | // --------------------------------------------------------------------------- |
| 756 | |
| 757 | void DoMovement(game_controls *controls) { |
| 758 | controls->sideways_thrust = 0.0f; |
| 759 | controls->vertical_thrust = 0.0f; |
| 760 | controls->forward_thrust = 0.0f; |
| 761 | controls->pitch_thrust = 0.0f; |
| 762 | controls->bank_thrust = 0.0f; |
| 763 | controls->heading_thrust = 0.0f; |
| 764 | controls->afterburn_thrust = 0.0f; |
| 765 | |
| 766 | // only read controls in game interface mode. |
| 767 | if (Game_interface_mode != GAME_INTERFACE) |
| 768 | return; |
| 769 | |
| 770 | // keyboard (always do this first.) |
| 771 | if (!Doing_input_message) |
| 772 | DoKeyboardMovement(controls); |
| 773 | |
| 774 | // controller |
| 775 | DoControllerMovement(controls); |
| 776 | |
| 777 | // clip controller values |
| 778 | if (controls->pitch_thrust > LIMIT_PITCH) |
| 779 | controls->pitch_thrust = LIMIT_PITCH; |
| 780 | if (controls->pitch_thrust < -LIMIT_PITCH) |
| 781 | controls->pitch_thrust = -LIMIT_PITCH; |
| 782 | if (controls->heading_thrust > LIMIT_HEADING) |
| 783 | controls->heading_thrust = LIMIT_HEADING; |
| 784 | if (controls->heading_thrust < -LIMIT_HEADING) |
| 785 | controls->heading_thrust = -LIMIT_HEADING; |
| 786 | if (controls->bank_thrust > LIMIT_BANK) |
| 787 | controls->bank_thrust = LIMIT_BANK; |
| 788 | if (controls->bank_thrust < -LIMIT_BANK) |
| 789 | controls->bank_thrust = -LIMIT_BANK; |
| 790 | if (controls->sideways_thrust > LIMIT_HORIZ) |
| 791 | controls->sideways_thrust = LIMIT_HORIZ; |
| 792 | if (controls->sideways_thrust < -LIMIT_HORIZ) |
| 793 | controls->sideways_thrust = -LIMIT_HORIZ; |
| 794 | if (controls->vertical_thrust > LIMIT_VERT) |
| 795 | controls->vertical_thrust = LIMIT_VERT; |
| 796 | if (controls->vertical_thrust < -LIMIT_VERT) |
| 797 | controls->vertical_thrust = -LIMIT_VERT; |
| 798 | |
| 799 | if (controls->forward_thrust > LIMIT_FORWARD) |
| 800 | controls->forward_thrust = LIMIT_FORWARD; |
| 801 | if (controls->forward_thrust < -LIMIT_FORWARD) |
| 802 | controls->forward_thrust = -LIMIT_FORWARD; |
| 803 | |
| 804 | if (controls->afterburn_thrust > LIMIT_FORWARD) |
| 805 | controls->afterburn_thrust = LIMIT_FORWARD; |
| 806 | if (controls->afterburn_thrust < -LIMIT_FORWARD) |
| 807 | controls->afterburn_thrust = -LIMIT_FORWARD; |
| 808 | |
| 809 | mprintf_at(1, 5, 30, "ch:%.2f ", controls->heading_thrust); |
| 810 | |
| 811 | // if (controls->pitch_thrust || controls->heading_thrust) |
| 812 | // mprintf(0, "p:%.2f h:%.2f\n", controls->pitch_thrust, controls->heading_thrust); |
| 813 | } |
| 814 | |
| 815 | void DoKeyboardMovement(game_controls *controls) { |
| 816 | float dx, dy, dz, dp, dh, db, d_afterburn; |
| 817 | ct_packet key_x1, key_x0, key_y1, key_y0, key_z1, key_z0; |
| 818 | ct_packet key_p1, key_p0, key_h1, key_h0, key_b1, key_b0; |
| 819 | ct_packet key_afterburn; |
| 820 | |
| 821 | // read controls |
| 822 | Controller->get_packet(ctfFORWARD_THRUSTKEY, &key_z1); |
| 823 | Controller->get_packet(ctfREVERSE_THRUSTKEY, &key_z0); |
| 824 | Controller->get_packet(ctfUP_THRUSTKEY, &key_y1); |
| 825 | Controller->get_packet(ctfDOWN_THRUSTKEY, &key_y0); |
| 826 | Controller->get_packet(ctfRIGHT_THRUSTKEY, &key_x1); |
| 827 | Controller->get_packet(ctfLEFT_THRUSTKEY, &key_x0); |
| 828 | Controller->get_packet(ctfPITCH_DOWNKEY, &key_p1); |
| 829 | Controller->get_packet(ctfPITCH_UPKEY, &key_p0); |
| 830 | Controller->get_packet(ctfBANK_RIGHTKEY, &key_b1); |
| 831 | Controller->get_packet(ctfBANK_LEFTKEY, &key_b0); |
| 832 | Controller->get_packet(ctfHEADING_RIGHTKEY, &key_h1); |
| 833 | Controller->get_packet(ctfHEADING_LEFTKEY, &key_h0); |
| 834 | |
| 835 | Controller->get_packet(ctfAFTERBURN_KEY, &key_afterburn); |
| 836 | |
| 837 | // check keyboard controls first. |
| 838 | |
| 839 | // do thrust and orientation controls. since packet contains time since last call, frametime is taken into |
| 840 | // account. note that the ctDigital packets are for those rare cases where a key is down, but there is no key down |
| 841 | // time registered as of yet, which happens on some systems. |
| 842 | dx = (key_x1.value - key_x0.value); |
| 843 | dy = (key_y1.value - key_y0.value); |
| 844 | dz = (key_z1.value - key_z0.value); |
| 845 | dp = (key_p1.value - key_p0.value); |
| 846 | db = (key_b0.value - key_b1.value); |
| 847 | dh = (key_h1.value - key_h0.value); |
| 848 | |
| 849 | d_afterburn = (key_afterburn.value); |
| 850 | |
| 851 | controls->sideways_thrust += |
| 852 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dx, KEY_RAMPUP_TIME, Key_ramp.x, Key_ramp.ox) / KEY_RAMPUP_TIME) : dx; |
| 853 | controls->vertical_thrust += |
| 854 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dy, KEY_RAMPUP_TIME, Key_ramp.y, Key_ramp.oy) / KEY_RAMPUP_TIME) : dy; |
| 855 | controls->forward_thrust += |
| 856 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dz, KEY_RAMPUP_TIME, Key_ramp.z, Key_ramp.oz) / KEY_RAMPUP_TIME) : dz; |
| 857 | |
| 858 | controls->afterburn_thrust += d_afterburn / Frametime; |
| 859 | |
| 860 | if (!controls->toggle_slide && !controls->toggle_bank) { |
| 861 | // clamp pitch ramp time to limits. |
| 862 | controls->pitch_thrust += |
| 863 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dp, KEY_RAMPUP_TIME, Key_ramp.p, Key_ramp.op) / KEY_RAMPUP_TIME) : dp; |
| 864 | controls->heading_thrust += |
| 865 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dh, KEY_RAMPUP_TIME, Key_ramp.h, Key_ramp.oh) / KEY_RAMPUP_TIME) : dh; |
| 866 | } |
| 867 | |
| 868 | if (controls->toggle_slide) { |
| 869 | controls->sideways_thrust += |
| 870 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dh, KEY_RAMPUP_TIME, Key_ramp.h, Key_ramp.oh) / KEY_RAMPUP_TIME) : dh; |
| 871 | controls->vertical_thrust += |
| 872 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dp, KEY_RAMPUP_TIME, Key_ramp.p, Key_ramp.op) / KEY_RAMPUP_TIME) : dp; |
| 873 | } |
| 874 | if (controls->toggle_bank) { |
| 875 | controls->bank_thrust += |
| 876 | (KEY_RAMPUP_TIME) ? (ramp_control_value(dh, KEY_RAMPUP_TIME, Key_ramp.h, Key_ramp.oh) / KEY_RAMPUP_TIME) : dh; |
| 877 | } else { |
| 878 | controls->bank_thrust += |
| 879 | (KEY_RAMPUP_TIME) ? (ramp_control_value(db, KEY_RAMPUP_TIME, Key_ramp.b, Key_ramp.ob) / KEY_RAMPUP_TIME) : db; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | // VERY IMPORTANT: All the movement thrust values are set in the keyboard movement |
| 884 | // handler. So we adjust those values in this function based off of the remaining |
| 885 | // controller element stataes. |
| 886 | |
| 887 | void DoControllerMovement(game_controls *controls) { |
| 888 | ct_packet ctl_x, ctl_y, ctl_z, ctl_p, ctl_b, ctl_h; |
| 889 | ct_packet ctl_povl, ctl_povr, ctl_povu, ctl_povd, ctl_fb, ctl_rb; |
| 890 | ct_packet ctl_afterburn; |
| 891 | ct_packet ctl_pub, ctl_pdb, ctl_hlb, ctl_hrb, ctl_blb, ctl_brb; |
| 892 | |
| 893 | // read controls |
| 894 | Controller->get_packet(ctfFORWARD_THRUSTAXIS, &ctl_z); |
| 895 | Controller->get_packet(ctfUP_THRUSTAXIS, &ctl_y); |
| 896 | Controller->get_packet(ctfRIGHT_THRUSTAXIS, &ctl_x); |
| 897 | Controller->get_packet(ctfPITCH_DOWNAXIS, &ctl_p); |
| 898 | Controller->get_packet(ctfBANK_RIGHTAXIS, &ctl_b); |
| 899 | Controller->get_packet(ctfHEADING_RIGHTAXIS, &ctl_h); |
| 900 | Controller->get_packet(ctfUP_BUTTON, &ctl_povu); |
| 901 | Controller->get_packet(ctfDOWN_BUTTON, &ctl_povd); |
| 902 | Controller->get_packet(ctfRIGHT_BUTTON, &ctl_povr); |
| 903 | Controller->get_packet(ctfLEFT_BUTTON, &ctl_povl); |
| 904 | Controller->get_packet(ctfFORWARD_BUTTON, &ctl_fb); |
| 905 | Controller->get_packet(ctfREVERSE_BUTTON, &ctl_rb); |
| 906 | Controller->get_packet(ctfAFTERBURN_BUTTON, &ctl_afterburn); |
| 907 | Controller->get_packet(ctfHEADING_LEFTBUTTON, &ctl_hlb); |
| 908 | Controller->get_packet(ctfHEADING_RIGHTBUTTON, &ctl_hrb); |
| 909 | Controller->get_packet(ctfPITCH_UPBUTTON, &ctl_pub); |
| 910 | Controller->get_packet(ctfPITCH_DOWNBUTTON, &ctl_pdb); |
| 911 | Controller->get_packet(ctfBANK_LEFTBUTTON, &ctl_blb); |
| 912 | Controller->get_packet(ctfBANK_RIGHTBUTTON, &ctl_brb); |
| 913 | |
| 914 | // check for joystick movement |
| 915 | // mprintf(0, "p:%f h:%f b:%f\n", ctl_p.value, ctl_h.value, ctl_b.value); |
| 916 | // mprintf(0, "u:%d d:%d l:%d r:%d\n", (int)ctl_povu.value, (int)ctl_povd.value, (int)ctl_povl.value, (int)ctl_povr.value); |
| 917 | |
| 918 | // do x and y thrust |
| 919 | controls->sideways_thrust += ctl_x.value; |
| 920 | controls->vertical_thrust += -ctl_y.value; |
| 921 | |
| 922 | // invert throttle alue for real flight model controls |
| 923 | controls->forward_thrust += -ctl_z.value; |
| 924 | |
| 925 | // do banking |
| 926 | if (controls->toggle_bank) { |
| 927 | controls->bank_thrust += -ctl_h.value; |
| 928 | } else { |
| 929 | controls->bank_thrust += -ctl_b.value; |
| 930 | } |
| 931 | |
| 932 | // do slide if toggled |
| 933 | if (controls->toggle_slide) { |
| 934 | controls->sideways_thrust += ctl_h.value; |
| 935 | if ((ctl_p.flags & CTPK_MOUSE) && !FindArg("-invertmouseslide")) { |
| 936 | controls->vertical_thrust += (-ctl_p.value); |
| 937 | } else { |
| 938 | controls->vertical_thrust += ctl_p.value; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | // do standard pitch and heading. |
| 943 | if (!controls->toggle_slide && !controls->toggle_bank) { |
| 944 | controls->pitch_thrust += -ctl_p.value; |
| 945 | controls->heading_thrust += ctl_h.value; |
| 946 | } |
| 947 | |
| 948 | // do afterburn button control |
| 949 | if (!controls->afterburn_thrust) { |
| 950 | // mprintf(0, "aft=%.4f\n", ctl_afterburn.value); |
| 951 | controls->afterburn_thrust = ((ctl_afterburn.value) / Frametime); |
| 952 | } |
| 953 | |
| 954 | // do button heading |
| 955 | if (ctl_hlb.value) |
| 956 | controls->heading_thrust += (-1.0f); |
| 957 | if (ctl_hrb.value) |
| 958 | controls->heading_thrust += (1.0f); |
| 959 | |
| 960 | // do button pitch |
| 961 | if (ctl_pub.value) |
| 962 | controls->pitch_thrust += (-1.0f); |
| 963 | if (ctl_pdb.value) |
| 964 | controls->pitch_thrust += (1.0f); |
| 965 | |
| 966 | // do forward thrust based off of button values. |
| 967 | controls->forward_thrust += ((ctl_fb.value - ctl_rb.value) / Frametime); |
| 968 | |
| 969 | // do button banking |
| 970 | if (ctl_blb.value) |
| 971 | controls->bank_thrust += (1.0f); |
| 972 | if (ctl_brb.value) |
| 973 | controls->bank_thrust += (-1.0f); |
| 974 | |
| 975 | // do button sliding. use control frametime to set sliding times per frame. |
| 976 | // note that vertical and sideways thrusts are dependent on what the keyboard controller |
| 977 | // set these values to. so we save our own slidetimes. |
| 978 | if (ctl_povu.value) { |
| 979 | controls->vertical_thrust += (1.0f); |
| 980 | } |
| 981 | if (ctl_povd.value) { |
| 982 | controls->vertical_thrust -= (1.0f); |
| 983 | } |
| 984 | if (ctl_povr.value) { |
| 985 | controls->sideways_thrust += (1.0f); |
| 986 | } |
| 987 | if (ctl_povl.value) { |
| 988 | controls->sideways_thrust -= (1.0f); |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | // --------------------------------------------------------------------------- |
| 993 | // CONTROL FUNCTIONS |
| 994 | // WEAPONS |
| 995 | // --------------------------------------------------------------------------- |
| 996 | |
| 997 | void DoWeapons(game_controls *controls) { |
| 998 | // reset some values |
| 999 | controls->fire_primary_down_count = 0; |
| 1000 | controls->fire_primary_down_time = 0; |
| 1001 | controls->fire_primary_down_state = false; |
| 1002 | controls->fire_secondary_down_count = 0; |
| 1003 | controls->fire_secondary_down_time = 0; |
| 1004 | controls->fire_flare_down_count = 0; |
| 1005 | |
| 1006 | // only read controls in game interface mode. |
| 1007 | if (Game_interface_mode != GAME_INTERFACE) |
| 1008 | return; |
| 1009 | |
| 1010 | // Reads in values to Controls structure |
| 1011 | if (!Doing_input_message) |
| 1012 | DoKeyboardWeapons(controls); |
| 1013 | |
| 1014 | DoControllerWeapons(controls); |
| 1015 | } |
| 1016 | |
| 1017 | void DoKeyboardWeapons(game_controls *controls) { |
| 1018 | ct_packet fire_primary_key_time; |
| 1019 | ct_packet fire_secondary_key_time; |
| 1020 | ct_packet fire_flare_key_count; |
| 1021 | ct_packet automap_key; |
| 1022 | ct_packet cycle_prim, cycle_sec; |
| 1023 | int i; |
| 1024 | |
| 1025 | // read controls |
| 1026 | Controller->get_packet(ctfFIREPRIMARY_KEY, &fire_primary_key_time); |
| 1027 | Controller->get_packet(ctfFIRESECONDARY_KEY, &fire_secondary_key_time); |
| 1028 | Controller->get_packet(ctfFIREFLARE_KEY, &fire_flare_key_count); |
| 1029 | Controller->get_packet(ctfAUTOMAP_KEY, &automap_key); |
| 1030 | Controller->get_packet(ctfWPNSEL_PCYCLEKEY, &cycle_prim); |
| 1031 | Controller->get_packet(ctfWPNSEL_SCYCLEKEY, &cycle_sec); |
| 1032 | |
| 1033 | // weapon fire |
| 1034 | if (fire_primary_key_time.value > 0) { |
| 1035 | controls->fire_primary_down_state = true; |
| 1036 | controls->fire_primary_down_count = 1; |
| 1037 | controls->fire_primary_down_time = fire_primary_key_time.value; |
| 1038 | } |
| 1039 | |
| 1040 | if (fire_secondary_key_time.value > 0) { |
| 1041 | controls->fire_secondary_down_count = 1; |
| 1042 | controls->fire_secondary_down_time = fire_secondary_key_time.value; |
| 1043 | } |
| 1044 | |
| 1045 | // flare |
| 1046 | controls->fire_flare_down_count = fire_flare_key_count.value; |
| 1047 | |
| 1048 | // automap |
| 1049 | if (automap_key.value) { |
| 1050 | Game_interface_mode = GAME_TELCOM_AUTOMAP; |
| 1051 | } |
| 1052 | |
| 1053 | // do cycling weapons |
| 1054 | for (i = 0; i < (int)cycle_prim.value; i++) |
| 1055 | SwitchPlayerWeapon(PW_PRIMARY); |
| 1056 | |
| 1057 | for (i = 0; i < (int)cycle_sec.value; i++) |
| 1058 | SwitchPlayerWeapon(PW_SECONDARY); |
| 1059 | } |
| 1060 | |
| 1061 | void DoControllerWeapons(game_controls *controls) { |
| 1062 | ct_packet fire_primary_count, fire_primary_time; |
| 1063 | ct_packet fire_secondary_count, fire_secondary_time; |
| 1064 | ct_packet fire_flare_count; |
| 1065 | ct_packet cycle_prim, cycle_sec; |
| 1066 | ct_packet automap_key; |
| 1067 | int i; |
| 1068 | |
| 1069 | // read controls |
| 1070 | Controller->get_packet(ctfFIREPRIMARY_BUTTON, &fire_primary_time); |
| 1071 | Controller->get_packet(ctfFIREPRIMARY_BUTTON, &fire_primary_count, ctDownCount); |
| 1072 | Controller->get_packet(ctfFIRESECONDARY_BUTTON, &fire_secondary_time); |
| 1073 | Controller->get_packet(ctfFIRESECONDARY_BUTTON, &fire_secondary_count, ctDownCount); |
| 1074 | Controller->get_packet(ctfFIREFLARE_BUTTON, &fire_flare_count, ctDownCount); |
| 1075 | Controller->get_packet(ctfWPNSEL_PCYCLEBTN, &cycle_prim); |
| 1076 | Controller->get_packet(ctfWPNSEL_SCYCLEBTN, &cycle_sec); |
| 1077 | Controller->get_packet(ctfAUTOMAP_BUTTON, &automap_key); |
| 1078 | |
| 1079 | // weapon fire |
| 1080 | if (fire_primary_count.value > 0 || fire_primary_time.value) { |
| 1081 | controls->fire_primary_down_state = true; |
| 1082 | controls->fire_primary_down_count = (int)fire_primary_count.value; |
| 1083 | controls->fire_primary_down_time = fire_primary_time.value; |
| 1084 | } |
| 1085 | if (fire_secondary_count.value > 0 || fire_secondary_time.value) { |
| 1086 | controls->fire_secondary_down_count = (int)fire_secondary_count.value; |
| 1087 | controls->fire_secondary_down_time = fire_secondary_time.value; |
| 1088 | } |
| 1089 | |
| 1090 | // Flare |
| 1091 | if (fire_flare_count.value > 0) |
| 1092 | controls->fire_flare_down_count = (int)fire_flare_count.value; |
| 1093 | |
| 1094 | // automap |
| 1095 | if (automap_key.value) { |
| 1096 | Game_interface_mode = GAME_TELCOM_AUTOMAP; |
| 1097 | } |
| 1098 | |
| 1099 | // do cycling weapons |
| 1100 | for (i = 0; i < (int)cycle_prim.value; i++) |
| 1101 | SwitchPlayerWeapon(PW_PRIMARY); |
| 1102 | |
| 1103 | for (i = 0; i < (int)cycle_sec.value; i++) |
| 1104 | SwitchPlayerWeapon(PW_SECONDARY); |
| 1105 | } |
| 1106 | |
| 1107 | void DoMisc(game_controls *controls) { |
| 1108 | controls->toggle_slide = false; |
| 1109 | controls->toggle_bank = false; |
| 1110 | controls->rearview_down_count = 0; |
| 1111 | controls->rearview_down_state = false; |
| 1112 | |
| 1113 | if (!Doing_input_message) |
| 1114 | DoKeyboardMisc(controls); |
| 1115 | DoControllerMisc(controls); |
| 1116 | |
| 1117 | //@@ if (!toggle_rearview_switch.value && Rearview_key_down) { |
| 1118 | //@@ Rearview_key_down = false; |
| 1119 | //@@ ToggleRearView(0); |
| 1120 | //@@ } |
| 1121 | //@@ else if (toggle_rearview_switch.value && !Rearview_key_down) { |
| 1122 | //@@ Rearview_key_down = true; |
| 1123 | //@@ ToggleRearView(1); |
| 1124 | //@@ } |
| 1125 | //@@ else if (!Rearview_key_down) { |
| 1126 | //@@ for (i = 0; i < (int)toggle_rearview.value; i++) |
| 1127 | //@@ ToggleRearView(); |
| 1128 | //@@ } |
| 1129 | } |
| 1130 | |
| 1131 | // use the currently selected inventory item |
| 1132 | extern bool UseInventoryItem(); |
| 1133 | // use the currently selected countermeasure |
| 1134 | extern bool UseCountermeasure(); |
| 1135 | |
| 1136 | // Inventory/CounterMeasure states |
| 1137 | void DoKeyboardMisc(game_controls *controls) { |
| 1138 | static int energy_to_shields_id = -1; |
| 1139 | int type, id, i; |
| 1140 | |
| 1141 | ct_packet prev_inv_key, next_inv_key; |
| 1142 | ct_packet prev_cntm_key, next_cntm_key; |
| 1143 | ct_packet use_inv_key, use_inv_key_digital, use_cntm_key, use_taunt[4]; |
| 1144 | ct_packet toggle_headlight; |
| 1145 | ct_packet toggle_rearview, toggle_rearview_switch; |
| 1146 | ct_packet key_slide1, key_bank; |
| 1147 | |
| 1148 | // read controls |
| 1149 | Controller->get_packet(ctfPREV_INVKEY, &prev_inv_key); |
| 1150 | Controller->get_packet(ctfNEXT_INVKEY, &next_inv_key); |
| 1151 | Controller->get_packet(ctfPREV_CNTMSKEY, &prev_cntm_key); |
| 1152 | Controller->get_packet(ctfNEXT_CNTMSKEY, &next_cntm_key); |
| 1153 | Controller->get_packet(ctfINV_USEKEY, &use_inv_key); |
| 1154 | Controller->get_packet(ctfINV_USEKEY, &use_inv_key_digital, ctDigital); |
| 1155 | Controller->get_packet(ctfCNTMS_USEKEY, &use_cntm_key); |
| 1156 | Controller->get_packet(ctfHEADLIGHT_KEY, &toggle_headlight); |
| 1157 | Controller->get_packet(ctfREARVIEW_KEY, &toggle_rearview); |
| 1158 | Controller->get_packet(ctfREARVIEW_KEY, &toggle_rearview_switch, ctDigital); |
| 1159 | Controller->get_packet(ctfAUDIOTAUNT1_KEY, &use_taunt[0]); |
| 1160 | Controller->get_packet(ctfAUDIOTAUNT2_KEY, &use_taunt[1]); |
| 1161 | Controller->get_packet(ctfAUDIOTAUNT3_KEY, &use_taunt[2]); |
| 1162 | Controller->get_packet(ctfAUDIOTAUNT4_KEY, &use_taunt[3]); |
| 1163 | |
| 1164 | Controller->get_packet(ctfTOGGLE_SLIDEKEY, &key_slide1); |
| 1165 | Controller->get_packet(ctfTOGGLE_BANKKEY, &key_bank); |
| 1166 | |
| 1167 | // check modifiers like toggles |
| 1168 | if (key_slide1.value) { |
| 1169 | controls->toggle_slide = true; |
| 1170 | } |
| 1171 | if (key_bank.value) { |
| 1172 | controls->toggle_bank = true; |
| 1173 | } |
| 1174 | |
| 1175 | // downcount, only once for audiotaunts |
| 1176 | if (use_taunt[0].value != 0.0f) { |
| 1177 | MultiSendRequestPlayTaunt(0); |
| 1178 | } |
| 1179 | if (use_taunt[1].value != 0.0f) { |
| 1180 | MultiSendRequestPlayTaunt(1); |
| 1181 | } |
| 1182 | if (use_taunt[2].value != 0.0f) { |
| 1183 | MultiSendRequestPlayTaunt(2); |
| 1184 | } |
| 1185 | if (use_taunt[3].value != 0.0f) { |
| 1186 | MultiSendRequestPlayTaunt(3); |
| 1187 | } |
| 1188 | |
| 1189 | // these are all down count values (so do operation X times) |
| 1190 | for (i = 0; i < (int)prev_cntm_key.value; i++) |
| 1191 | CounterMeasuresSwitch(false); |
| 1192 | |
| 1193 | for (i = 0; i < (int)next_cntm_key.value; i++) |
| 1194 | CounterMeasuresSwitch(true); |
| 1195 | |
| 1196 | for (i = 0; i < (int)use_cntm_key.value; i++) |
| 1197 | UseCountermeasure(); |
| 1198 | |
| 1199 | for (i = 0; i < (int)prev_inv_key.value; i++) { |
| 1200 | if (Players[Player_num].inventory.Size() == 1) { |
| 1201 | if (Players[Player_num].inventory.GetPosName()) |
| 1202 | AddHUDMessage(TXT_WPNSELECT, Players[Player_num].inventory.GetPosName()); |
| 1203 | } |
| 1204 | InventorySwitch(false); |
| 1205 | } |
| 1206 | |
| 1207 | for (i = 0; i < (int)next_inv_key.value; i++) { |
| 1208 | if (Players[Player_num].inventory.Size() == 1) { |
| 1209 | if (Players[Player_num].inventory.GetPosName()) |
| 1210 | AddHUDMessage(TXT_WPNSELECT, Players[Player_num].inventory.GetPosName()); |
| 1211 | } |
| 1212 | InventorySwitch(true); |
| 1213 | } |
| 1214 | |
| 1215 | // do energy to shield hack |
| 1216 | if (energy_to_shields_id == -1) { |
| 1217 | energy_to_shields_id = FindObjectIDName("Converter"); |
| 1218 | } |
| 1219 | Players[Player_num].inventory.GetPosTypeID(type, id); |
| 1220 | if (use_inv_key_digital.value) { |
| 1221 | if (type == OBJ_POWERUP && id == energy_to_shields_id) { |
| 1222 | // the player has an energy->shields converter |
| 1223 | DoEnergyToShields(Player_num); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | // do standard inventory use. |
| 1228 | for (i = 0; i < (int)use_inv_key.value; i++) { |
| 1229 | // Inventory use is special cased for Energy->Shields converter |
| 1230 | if (type == OBJ_POWERUP && id == energy_to_shields_id) { |
| 1231 | continue; |
| 1232 | } else { |
| 1233 | // handle use inventory keypress |
| 1234 | UseInventoryItem(); |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | for (i = 0; i < (int)toggle_headlight.value; i++) |
| 1239 | ToggleHeadlightControlState(); |
| 1240 | |
| 1241 | // rear view toggling. |
| 1242 | controls->rearview_down_count += toggle_rearview.value; |
| 1243 | controls->rearview_down_state = toggle_rearview_switch.value ? true : false; |
| 1244 | } |
| 1245 | |
| 1246 | void DoControllerMisc(game_controls *controls) { |
| 1247 | static int energy_to_shields_id = -1; |
| 1248 | int i; |
| 1249 | |
| 1250 | ct_packet prev_inv, next_inv; |
| 1251 | ct_packet prev_cntm, next_cntm; |
| 1252 | ct_packet use_inv, use_cntm; |
| 1253 | ct_packet toggle_headlight; |
| 1254 | ct_packet toggle_rearview, toggle_rearview_switch; |
| 1255 | ct_packet ctl_bank, ctl_slide, use_taunt[4]; |
| 1256 | |
| 1257 | // read controls |
| 1258 | Controller->get_packet(ctfPREV_INVBTN, &prev_inv); |
| 1259 | Controller->get_packet(ctfNEXT_INVBTN, &next_inv); |
| 1260 | Controller->get_packet(ctfPREV_CNTMSBTN, &prev_cntm); |
| 1261 | Controller->get_packet(ctfNEXT_CNTMSBTN, &next_cntm); |
| 1262 | Controller->get_packet(ctfINV_USEBTN, &use_inv); |
| 1263 | Controller->get_packet(ctfCNTMS_USEBTN, &use_cntm); |
| 1264 | Controller->get_packet(ctfHEADLIGHT_BUTTON, &toggle_headlight); |
| 1265 | Controller->get_packet(ctfREARVIEW_BTN, &toggle_rearview); |
| 1266 | Controller->get_packet(ctfREARVIEW_BTN, &toggle_rearview_switch, ctDigital); |
| 1267 | Controller->get_packet(ctfAUDIOTAUNT1_BTN, &use_taunt[0]); |
| 1268 | Controller->get_packet(ctfAUDIOTAUNT2_BTN, &use_taunt[1]); |
| 1269 | Controller->get_packet(ctfAUDIOTAUNT3_BTN, &use_taunt[2]); |
| 1270 | Controller->get_packet(ctfAUDIOTAUNT4_BTN, &use_taunt[3]); |
| 1271 | |
| 1272 | Controller->get_packet(ctfTOGGLE_SLIDEBUTTON, &ctl_slide); |
| 1273 | Controller->get_packet(ctfTOGGLE_BANKBUTTON, &ctl_bank); |
| 1274 | |
| 1275 | // check modifiers like toggles |
| 1276 | if (ctl_slide.value) { |
| 1277 | controls->toggle_slide = true; |
| 1278 | } |
| 1279 | if (ctl_bank.value) { |
| 1280 | controls->toggle_bank = true; |
| 1281 | } |
| 1282 | |
| 1283 | // downcount, only once for audiotaunts |
| 1284 | if (use_taunt[0].value != 0.0f) { |
| 1285 | MultiSendRequestPlayTaunt(0); |
| 1286 | } |
| 1287 | if (use_taunt[1].value != 0.0f) { |
| 1288 | MultiSendRequestPlayTaunt(1); |
| 1289 | } |
| 1290 | if (use_taunt[2].value != 0.0f) { |
| 1291 | MultiSendRequestPlayTaunt(2); |
| 1292 | } |
| 1293 | if (use_taunt[3].value != 0.0f) { |
| 1294 | MultiSendRequestPlayTaunt(3); |
| 1295 | } |
| 1296 | |
| 1297 | // these are all down count values (so do operation X times) |
| 1298 | for (i = 0; i < (int)prev_cntm.value; i++) |
| 1299 | CounterMeasuresSwitch(false); |
| 1300 | |
| 1301 | for (i = 0; i < (int)next_cntm.value; i++) |
| 1302 | CounterMeasuresSwitch(true); |
| 1303 | |
| 1304 | for (i = 0; i < (int)use_cntm.value; i++) |
| 1305 | UseCountermeasure(); |
| 1306 | |
| 1307 | for (i = 0; i < (int)prev_inv.value; i++) { |
| 1308 | if (Players[Player_num].inventory.Size() == 1) { |
| 1309 | if (Players[Player_num].inventory.GetPosName()) |
| 1310 | AddHUDMessage(TXT_WPNSELECT, Players[Player_num].inventory.GetPosName()); |
| 1311 | } |
| 1312 | InventorySwitch(false); |
| 1313 | } |
| 1314 | |
| 1315 | for (i = 0; i < (int)next_inv.value; i++) { |
| 1316 | if (Players[Player_num].inventory.Size() == 1) { |
| 1317 | if (Players[Player_num].inventory.GetPosName()) |
| 1318 | AddHUDMessage(TXT_WPNSELECT, Players[Player_num].inventory.GetPosName()); |
| 1319 | } |
| 1320 | InventorySwitch(true); |
| 1321 | } |
| 1322 | |
| 1323 | for (i = 0; i < (int)use_inv.value; i++) { |
| 1324 | int type, id; |
| 1325 | |
| 1326 | if (energy_to_shields_id == -1) |
| 1327 | energy_to_shields_id = FindObjectIDName("Converter"); |
| 1328 | |
| 1329 | // Inventory use is special cased for Energy->Shields converter |
| 1330 | Players[Player_num].inventory.GetPosTypeID(type, id); |
| 1331 | if (type == OBJ_POWERUP && id == energy_to_shields_id) { |
| 1332 | // the player has an energy->shields converter |
| 1333 | DoEnergyToShields(Player_num); |
| 1334 | } else { |
| 1335 | // handle use inventory keypress |
| 1336 | UseInventoryItem(); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | for (i = 0; i < (int)toggle_headlight.value; i++) |
| 1341 | ToggleHeadlightControlState(); |
| 1342 | |
| 1343 | // rear view toggling. |
| 1344 | controls->rearview_down_count += toggle_rearview.value; |
| 1345 | if (!controls->rearview_down_state) |
| 1346 | controls->rearview_down_state = toggle_rearview_switch.value ? true : false; |
| 1347 | } |
| 1348 | |
| 1349 | // sets the internal controller config to the current pilot's configuration. |
| 1350 | void LoadControlConfig(pilot *plt) { |
| 1351 | int j; |
| 1352 | if (!plt) |
| 1353 | plt = &Current_pilot; |
| 1354 | |
| 1355 | for (int i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) { |
| 1356 | int id = Current_pilot.controls[i].id; |
| 1357 | ct_type type[2]; |
| 1358 | ct_config_data ccfgdata; |
| 1359 | uint8_t flags[2]; |
| 1360 | |
| 1361 | type[0] = plt->controls[i].type[0]; |
| 1362 | type[1] = plt->controls[i].type[1]; |
| 1363 | ccfgdata = plt->controls[i].value; |
| 1364 | flags[0] = plt->controls[i].flags[0]; |
| 1365 | flags[1] = plt->controls[i].flags[1]; |
| 1366 | |
| 1367 | Controller->set_controller_function(id, type, ccfgdata, flags); |
| 1368 | } |
| 1369 | for (j = 0; j < N_MOUSE_AXIS; j++) { |
| 1370 | Controller->set_axis_sensitivity(ctMouseAxis, j + 1, plt->mouse_sensitivity[j]); |
| 1371 | } |
| 1372 | for (j = 0; j < N_JOY_AXIS; j++) { |
| 1373 | Controller->set_axis_sensitivity(ctAxis, j + 1, plt->joy_sensitivity[j]); |
| 1374 | } |
| 1375 | |
| 1376 | Key_ramp_speed = plt->key_ramping; |
| 1377 | } |
| 1378 | |
| 1379 | // saves the internal controller config of current pilot. if the controller changes, then calling |
| 1380 | // LoadControlConfig will restore ONLY VALID configurations. |
| 1381 | void SaveControlConfig(pilot *plt) { |
| 1382 | int j; |
| 1383 | if (!plt) |
| 1384 | plt = &Current_pilot; |
| 1385 | |
| 1386 | for (int i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) { |
| 1387 | ct_type ctype[2]; |
| 1388 | ct_config_data ccfgdata; |
| 1389 | uint8_t flags[2]; |
| 1390 | Controller->get_controller_function(Controller_needs[i].id, ctype, &ccfgdata, flags); |
| 1391 | |
| 1392 | plt->controls[i].id = Controller_needs[i].id; |
| 1393 | plt->controls[i].type[0] = ctype[0]; |
| 1394 | plt->controls[i].type[1] = ctype[1]; |
| 1395 | plt->controls[i].value = ccfgdata; |
| 1396 | plt->controls[i].flags[0] = flags[0]; |
| 1397 | plt->controls[i].flags[1] = flags[1]; |
| 1398 | } |
| 1399 | |
| 1400 | for (j = 0; j < N_MOUSE_AXIS; j++) { |
| 1401 | float sens = Controller->get_axis_sensitivity(ctMouseAxis, j + 1); |
| 1402 | plt->mouse_sensitivity[j] = sens; |
| 1403 | } |
| 1404 | for (j = 0; j < N_JOY_AXIS; j++) { |
| 1405 | float sens = Controller->get_axis_sensitivity(ctAxis, j + 1); |
| 1406 | plt->joy_sensitivity[j] = sens; |
| 1407 | } |
| 1408 | |
| 1409 | plt->key_ramping = Key_ramp_speed; |
| 1410 | } |
| 1411 | |
| 1412 | void ToggleHeadlightControlState() { |
| 1413 | if (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_STOLEN) { |
| 1414 | // player has no headlight right now |
| 1415 | AddHUDMessage(TXT_DONTHAVEHEADLIGHT); |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | if (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) |
| 1420 | Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT; |
| 1421 | else |
| 1422 | Players[Player_num].flags |= PLAYER_FLAGS_HEADLIGHT; |
| 1423 | |
| 1424 | Sound_system.Play2dSound(SOUND_HEADLIGHT); |
| 1425 | AddHUDMessage(TXT_HEADLIGHTTURNED, |
| 1426 | Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT ? TXT_STRING_ON : TXT_STRING_OFF); |
| 1427 | } |