default.bind.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. if ( isObject( moveMap ) )
  23. moveMap.delete();
  24. new ActionMap(moveMap);
  25. //------------------------------------------------------------------------------
  26. // Non-remapable binds
  27. //------------------------------------------------------------------------------
  28. function escapeFromGame()
  29. {
  30. if ( $Server::ServerType $= "SinglePlayer" )
  31. MessageBoxYesNo( "Exit", "Exit from this Mission?", "disconnect();", "");
  32. else
  33. MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
  34. }
  35. moveMap.bindCmd(keyboard, "escape", "", "handleEscape();");
  36. function showPlayerList(%val)
  37. {
  38. if (%val)
  39. PlayerListGui.toggle();
  40. }
  41. moveMap.bind( keyboard, F2, showPlayerList );
  42. function hideHUDs(%val)
  43. {
  44. if (%val)
  45. HudlessPlayGui.toggle();
  46. }
  47. moveMap.bind(keyboard, "ctrl h", hideHUDs);
  48. function doScreenShotHudless(%val)
  49. {
  50. if(%val)
  51. {
  52. canvas.setContent(HudlessPlayGui);
  53. //doScreenshot(%val);
  54. schedule(10, 0, "doScreenShot", %val);
  55. }
  56. else
  57. canvas.setContent(PlayGui);
  58. }
  59. moveMap.bind(keyboard, "alt p", doScreenShotHudless);
  60. //------------------------------------------------------------------------------
  61. // Movement Keys
  62. //------------------------------------------------------------------------------
  63. $movementSpeed = 1; // m/s
  64. function setSpeed(%speed)
  65. {
  66. if(%speed)
  67. $movementSpeed = %speed;
  68. }
  69. function moveleft(%val)
  70. {
  71. $mvLeftAction = %val * $movementSpeed;
  72. }
  73. function moveright(%val)
  74. {
  75. $mvRightAction = %val * $movementSpeed;
  76. }
  77. function moveforward(%val)
  78. {
  79. $mvForwardAction = %val * $movementSpeed;
  80. }
  81. function movebackward(%val)
  82. {
  83. $mvBackwardAction = %val * $movementSpeed;
  84. }
  85. function moveup(%val)
  86. {
  87. %object = ServerConnection.getControlObject();
  88. if(%object.isInNamespaceHierarchy("Camera"))
  89. $mvUpAction = %val * $movementSpeed;
  90. }
  91. function movedown(%val)
  92. {
  93. %object = ServerConnection.getControlObject();
  94. if(%object.isInNamespaceHierarchy("Camera"))
  95. $mvDownAction = %val * $movementSpeed;
  96. }
  97. function turnLeft( %val )
  98. {
  99. $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  100. }
  101. function turnRight( %val )
  102. {
  103. $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  104. }
  105. function panUp( %val )
  106. {
  107. $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  108. }
  109. function panDown( %val )
  110. {
  111. $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  112. }
  113. function getMouseAdjustAmount(%val)
  114. {
  115. // based on a default camera FOV of 90'
  116. return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
  117. }
  118. function getGamepadAdjustAmount(%val)
  119. {
  120. // based on a default camera FOV of 90'
  121. return(%val * ($cameraFov / 90) * 0.01) * 10.0;
  122. }
  123. function yaw(%val)
  124. {
  125. %yawAdj = getMouseAdjustAmount(%val);
  126. if(ServerConnection.isControlObjectRotDampedCamera())
  127. {
  128. // Clamp and scale
  129. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  130. %yawAdj *= 0.5;
  131. }
  132. $mvYaw += %yawAdj;
  133. }
  134. function pitch(%val)
  135. {
  136. %pitchAdj = getMouseAdjustAmount(%val);
  137. if(ServerConnection.isControlObjectRotDampedCamera())
  138. {
  139. // Clamp and scale
  140. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  141. %pitchAdj *= 0.5;
  142. }
  143. $mvPitch += %pitchAdj;
  144. }
  145. function jump(%val)
  146. {
  147. $mvTriggerCount2++;
  148. }
  149. function gamePadMoveX( %val )
  150. {
  151. if(%val > 0)
  152. {
  153. $mvRightAction = %val * $movementSpeed;
  154. $mvLeftAction = 0;
  155. }
  156. else
  157. {
  158. $mvRightAction = 0;
  159. $mvLeftAction = -%val * $movementSpeed;
  160. }
  161. }
  162. function gamePadMoveY( %val )
  163. {
  164. if(%val > 0)
  165. {
  166. $mvForwardAction = %val * $movementSpeed;
  167. $mvBackwardAction = 0;
  168. }
  169. else
  170. {
  171. $mvForwardAction = 0;
  172. $mvBackwardAction = -%val * $movementSpeed;
  173. }
  174. }
  175. function gamepadYaw(%val)
  176. {
  177. %yawAdj = getGamepadAdjustAmount(%val);
  178. if(ServerConnection.isControlObjectRotDampedCamera())
  179. {
  180. // Clamp and scale
  181. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  182. %yawAdj *= 0.5;
  183. }
  184. if(%yawAdj > 0)
  185. {
  186. $mvYawLeftSpeed = %yawAdj;
  187. $mvYawRightSpeed = 0;
  188. }
  189. else
  190. {
  191. $mvYawLeftSpeed = 0;
  192. $mvYawRightSpeed = -%yawAdj;
  193. }
  194. }
  195. function gamepadPitch(%val)
  196. {
  197. %pitchAdj = getGamepadAdjustAmount(%val);
  198. if(ServerConnection.isControlObjectRotDampedCamera())
  199. {
  200. // Clamp and scale
  201. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  202. %pitchAdj *= 0.5;
  203. }
  204. if(%pitchAdj > 0)
  205. {
  206. $mvPitchDownSpeed = %pitchAdj;
  207. $mvPitchUpSpeed = 0;
  208. }
  209. else
  210. {
  211. $mvPitchDownSpeed = 0;
  212. $mvPitchUpSpeed = -%pitchAdj;
  213. }
  214. }
  215. moveMap.bind( keyboard, a, moveleft );
  216. moveMap.bind( keyboard, d, moveright );
  217. moveMap.bind( keyboard, left, moveleft );
  218. moveMap.bind( keyboard, right, moveright );
  219. moveMap.bind( keyboard, w, moveforward );
  220. moveMap.bind( keyboard, s, movebackward );
  221. moveMap.bind( keyboard, up, moveforward );
  222. moveMap.bind( keyboard, down, movebackward );
  223. moveMap.bind( keyboard, e, moveup );
  224. moveMap.bind( keyboard, c, movedown );
  225. moveMap.bind( keyboard, space, jump );
  226. moveMap.bind( mouse, xaxis, yaw );
  227. moveMap.bind( mouse, yaxis, pitch );
  228. moveMap.bind( gamepad, thumbrx, "D", "-0.23 0.23", gamepadYaw );
  229. moveMap.bind( gamepad, thumbry, "D", "-0.23 0.23", gamepadPitch );
  230. moveMap.bind( gamepad, thumblx, "D", "-0.23 0.23", gamePadMoveX );
  231. moveMap.bind( gamepad, thumbly, "D", "-0.23 0.23", gamePadMoveY );
  232. moveMap.bind( gamepad, btn_a, jump );
  233. moveMap.bindCmd( gamepad, btn_back, "disconnect();", "" );
  234. moveMap.bindCmd(gamepad, dpadl, "toggleLightColorViz();", "");
  235. moveMap.bindCmd(gamepad, dpadu, "toggleDepthViz();", "");
  236. moveMap.bindCmd(gamepad, dpadd, "toggleNormalsViz();", "");
  237. moveMap.bindCmd(gamepad, dpadr, "toggleLightSpecularViz();", "");
  238. // ----------------------------------------------------------------------------
  239. // Stance/pose
  240. // ----------------------------------------------------------------------------
  241. function doCrouch(%val)
  242. {
  243. $mvTriggerCount3++;
  244. }
  245. moveMap.bind(keyboard, lcontrol, doCrouch);
  246. moveMap.bind(gamepad, btn_b, doCrouch);
  247. function doSprint(%val)
  248. {
  249. $mvTriggerCount5++;
  250. }
  251. moveMap.bind(keyboard, lshift, doSprint);
  252. //------------------------------------------------------------------------------
  253. // Mouse Trigger
  254. //------------------------------------------------------------------------------
  255. function mouseFire(%val)
  256. {
  257. $mvTriggerCount0++;
  258. }
  259. //function altTrigger(%val)
  260. //{
  261. //$mvTriggerCount1++;
  262. //}
  263. moveMap.bind( mouse, button0, mouseFire );
  264. //moveMap.bind( mouse, button1, altTrigger );
  265. //------------------------------------------------------------------------------
  266. // Gamepad Trigger
  267. //------------------------------------------------------------------------------
  268. function gamepadFire(%val)
  269. {
  270. if(%val > 0.1 && !$gamepadFireTriggered)
  271. {
  272. $gamepadFireTriggered = true;
  273. $mvTriggerCount0++;
  274. }
  275. else if(%val <= 0.1 && $gamepadFireTriggered)
  276. {
  277. $gamepadFireTriggered = false;
  278. $mvTriggerCount0++;
  279. }
  280. }
  281. function gamepadAltTrigger(%val)
  282. {
  283. if(%val > 0.1 && !$gamepadAltTriggerTriggered)
  284. {
  285. $gamepadAltTriggerTriggered = true;
  286. $mvTriggerCount1++;
  287. }
  288. else if(%val <= 0.1 && $gamepadAltTriggerTriggered)
  289. {
  290. $gamepadAltTriggerTriggered = false;
  291. $mvTriggerCount1++;
  292. }
  293. }
  294. moveMap.bind(gamepad, triggerr, gamepadFire);
  295. moveMap.bind(gamepad, triggerl, gamepadAltTrigger);
  296. //------------------------------------------------------------------------------
  297. // Zoom and FOV functions
  298. //------------------------------------------------------------------------------
  299. if($Player::CurrentFOV $= "")
  300. $Player::CurrentFOV = $pref::Player::DefaultFOV / 2;
  301. // toggleZoomFOV() works by dividing the CurrentFOV by 2. Each time that this
  302. // toggle is hit it simply divides the CurrentFOV by 2 once again. If the
  303. // FOV is reduced below a certain threshold then it resets to equal half of the
  304. // DefaultFOV value. This gives us 4 zoom levels to cycle through.
  305. function toggleZoomFOV()
  306. {
  307. $Player::CurrentFOV = $Player::CurrentFOV / 2;
  308. if($Player::CurrentFOV < 5)
  309. resetCurrentFOV();
  310. if(ServerConnection.zoomed)
  311. setFOV($Player::CurrentFOV);
  312. else
  313. {
  314. setFov(ServerConnection.getControlCameraDefaultFov());
  315. }
  316. }
  317. function resetCurrentFOV()
  318. {
  319. $Player::CurrentFOV = ServerConnection.getControlCameraDefaultFov() / 2;
  320. }
  321. function turnOffZoom()
  322. {
  323. ServerConnection.zoomed = false;
  324. setFov(ServerConnection.getControlCameraDefaultFov());
  325. Reticle.setVisible(true);
  326. zoomReticle.setVisible(false);
  327. // Rather than just disable the DOF effect, we want to set it to the level's
  328. // preset values.
  329. //DOFPostEffect.disable();
  330. ppOptionsUpdateDOFSettings();
  331. }
  332. function setZoomFOV(%val)
  333. {
  334. if(%val)
  335. toggleZoomFOV();
  336. }
  337. function toggleZoom(%val)
  338. {
  339. if (%val)
  340. {
  341. ServerConnection.zoomed = true;
  342. setFov($Player::CurrentFOV);
  343. Reticle.setVisible(false);
  344. zoomReticle.setVisible(true);
  345. DOFPostEffect.setAutoFocus( true );
  346. DOFPostEffect.setFocusParams( 0.5, 0.5, 50, 500, -5, 5 );
  347. DOFPostEffect.enable();
  348. }
  349. else
  350. {
  351. turnOffZoom();
  352. }
  353. }
  354. function mouseButtonZoom(%val)
  355. {
  356. toggleZoom(%val);
  357. }
  358. moveMap.bind(keyboard, f, setZoomFOV); // f for field of view
  359. moveMap.bind(keyboard, z, toggleZoom); // z for zoom
  360. moveMap.bind( mouse, button1, mouseButtonZoom );
  361. //------------------------------------------------------------------------------
  362. // Camera & View functions
  363. //------------------------------------------------------------------------------
  364. function toggleFreeLook( %val )
  365. {
  366. if ( %val )
  367. $mvFreeLook = true;
  368. else
  369. $mvFreeLook = false;
  370. }
  371. function toggleFirstPerson(%val)
  372. {
  373. if (%val)
  374. {
  375. ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
  376. }
  377. }
  378. function toggleCamera(%val)
  379. {
  380. if (%val)
  381. commandToServer('ToggleCamera');
  382. }
  383. moveMap.bind( keyboard, v, toggleFreeLook ); // v for vanity
  384. moveMap.bind(keyboard, tab, toggleFirstPerson );
  385. moveMap.bind(keyboard, "alt c", toggleCamera);
  386. moveMap.bind( gamepad, btn_start, toggleCamera );
  387. moveMap.bind( gamepad, btn_x, toggleFirstPerson );
  388. // ----------------------------------------------------------------------------
  389. // Misc. Player stuff
  390. // ----------------------------------------------------------------------------
  391. // Gideon does not have these animations, so the player does not need access to
  392. // them. Commenting instead of removing so as to retain an example for those
  393. // who will want to use a player model that has these animations and wishes to
  394. // use them.
  395. //moveMap.bindCmd(keyboard, "ctrl w", "commandToServer('playCel',\"wave\");", "");
  396. //moveMap.bindCmd(keyboard, "ctrl s", "commandToServer('playCel',\"salute\");", "");
  397. moveMap.bindCmd(keyboard, "ctrl k", "commandToServer('suicide');", "");
  398. //------------------------------------------------------------------------------
  399. // Item manipulation
  400. //------------------------------------------------------------------------------
  401. moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"Ryder\");", "");
  402. moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"Lurker\");", "");
  403. moveMap.bindCmd(keyboard, "3", "commandToServer('use',\"LurkerGrenadeLauncher\");", "");
  404. moveMap.bindCmd(keyboard, "4", "commandToServer('use',\"ProxMine\");", "");
  405. moveMap.bindCmd(keyboard, "5", "commandToServer('use',\"DeployableTurret\");", "");
  406. moveMap.bindCmd(keyboard, "r", "commandToServer('reloadWeapon');", "");
  407. function unmountWeapon(%val)
  408. {
  409. if (%val)
  410. commandToServer('unmountWeapon');
  411. }
  412. moveMap.bind(keyboard, 0, unmountWeapon);
  413. function throwWeapon(%val)
  414. {
  415. if (%val)
  416. commandToServer('Throw', "Weapon");
  417. }
  418. function tossAmmo(%val)
  419. {
  420. if (%val)
  421. commandToServer('Throw', "Ammo");
  422. }
  423. moveMap.bind(keyboard, "alt w", throwWeapon);
  424. moveMap.bind(keyboard, "alt a", tossAmmo);
  425. function nextWeapon(%val)
  426. {
  427. if (%val)
  428. commandToServer('cycleWeapon', "next");
  429. }
  430. function prevWeapon(%val)
  431. {
  432. if (%val)
  433. commandToServer('cycleWeapon', "prev");
  434. }
  435. function mouseWheelWeaponCycle(%val)
  436. {
  437. if (%val < 0)
  438. commandToServer('cycleWeapon', "next");
  439. else if (%val > 0)
  440. commandToServer('cycleWeapon', "prev");
  441. }
  442. moveMap.bind(keyboard, q, nextWeapon);
  443. moveMap.bind(keyboard, "ctrl q", prevWeapon);
  444. moveMap.bind(mouse, "zaxis", mouseWheelWeaponCycle);
  445. //------------------------------------------------------------------------------
  446. // Message HUD functions
  447. //------------------------------------------------------------------------------
  448. function pageMessageHudUp( %val )
  449. {
  450. if ( %val )
  451. pageUpMessageHud();
  452. }
  453. function pageMessageHudDown( %val )
  454. {
  455. if ( %val )
  456. pageDownMessageHud();
  457. }
  458. function resizeMessageHud( %val )
  459. {
  460. if ( %val )
  461. cycleMessageHudSize();
  462. }
  463. moveMap.bind(keyboard, u, toggleMessageHud );
  464. //moveMap.bind(keyboard, y, teamMessageHud );
  465. moveMap.bind(keyboard, "pageUp", pageMessageHudUp );
  466. moveMap.bind(keyboard, "pageDown", pageMessageHudDown );
  467. moveMap.bind(keyboard, "p", resizeMessageHud );
  468. //------------------------------------------------------------------------------
  469. // Demo recording functions
  470. //------------------------------------------------------------------------------
  471. function startRecordingDemo( %val )
  472. {
  473. if ( %val )
  474. startDemoRecord();
  475. }
  476. function stopRecordingDemo( %val )
  477. {
  478. if ( %val )
  479. stopDemoRecord();
  480. }
  481. moveMap.bind( keyboard, F3, startRecordingDemo );
  482. moveMap.bind( keyboard, F4, stopRecordingDemo );
  483. //------------------------------------------------------------------------------
  484. // Theora Video Capture (Records a movie file)
  485. //------------------------------------------------------------------------------
  486. function toggleMovieRecording(%val)
  487. {
  488. if (!%val)
  489. return;
  490. %movieEncodingType = "THEORA"; // Valid encoder values are "PNG" and "THEORA" (default).
  491. %movieFPS = 30; // video capture frame rate.
  492. if (!$RecordingMovie)
  493. {
  494. // locate a non-existent filename to use
  495. for(%i = 0; %i < 1000; %i++)
  496. {
  497. %num = %i;
  498. if(%num < 10)
  499. %num = "0" @ %num;
  500. if(%num < 100)
  501. %num = "0" @ %num;
  502. %filePath = "movies/movie" @ %num;
  503. if(!isfile(%filePath))
  504. break;
  505. }
  506. if(%i == 1000)
  507. return;
  508. // Start the movie recording
  509. recordMovie(%filePath, %movieFPS, %movieEncodingType);
  510. }
  511. else
  512. {
  513. // Stop the current recording
  514. stopMovie();
  515. }
  516. }
  517. // Key binding works at any time and not just while in a game.
  518. GlobalActionMap.bind(keyboard, "alt m", toggleMovieRecording);
  519. //------------------------------------------------------------------------------
  520. // Helper Functions
  521. //------------------------------------------------------------------------------
  522. function dropCameraAtPlayer(%val)
  523. {
  524. if (%val)
  525. commandToServer('dropCameraAtPlayer');
  526. }
  527. function dropPlayerAtCamera(%val)
  528. {
  529. if (%val)
  530. commandToServer('DropPlayerAtCamera');
  531. }
  532. moveMap.bind(keyboard, "F8", dropCameraAtPlayer);
  533. moveMap.bind(keyboard, "F7", dropPlayerAtCamera);
  534. function bringUpOptions(%val)
  535. {
  536. if (%val)
  537. Canvas.pushDialog(OptionsDlg);
  538. }
  539. GlobalActionMap.bind(keyboard, "ctrl o", bringUpOptions);
  540. //------------------------------------------------------------------------------
  541. // Debugging Functions
  542. //------------------------------------------------------------------------------
  543. function showMetrics(%val)
  544. {
  545. if(%val)
  546. {
  547. if(!Canvas.isMember(FrameOverlayGui))
  548. metrics("fps gfx shadow sfx terrain groundcover forest net");
  549. else
  550. metrics("");
  551. }
  552. }
  553. GlobalActionMap.bind(keyboard, "ctrl F2", showMetrics);
  554. //------------------------------------------------------------------------------
  555. //
  556. // Start profiler by pressing ctrl f3
  557. // ctrl f3 - starts profile that will dump to console and file
  558. //
  559. function doProfile(%val)
  560. {
  561. if (%val)
  562. {
  563. // key down -- start profile
  564. echo("Starting profile session...");
  565. profilerReset();
  566. profilerEnable(true);
  567. }
  568. else
  569. {
  570. // key up -- finish off profile
  571. echo("Ending profile session...");
  572. profilerDumpToFile("profilerDumpToFile" @ getSimTime() @ ".txt");
  573. profilerEnable(false);
  574. }
  575. }
  576. GlobalActionMap.bind(keyboard, "ctrl F3", doProfile);
  577. //------------------------------------------------------------------------------
  578. // Misc.
  579. //------------------------------------------------------------------------------
  580. GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
  581. GlobalActionMap.bindCmd(keyboard, "alt k", "cls();","");
  582. GlobalActionMap.bindCmd(keyboard, "alt enter", "", "Canvas.attemptFullscreenToggle();");
  583. GlobalActionMap.bindCmd(keyboard, "F1", "", "contextHelp();");
  584. moveMap.bindCmd(keyboard, "n", "toggleNetGraph();", "");
  585. // ----------------------------------------------------------------------------
  586. // Useful vehicle stuff
  587. // ----------------------------------------------------------------------------
  588. // Trace a line along the direction the crosshair is pointing
  589. // If you find a car with a player in it...eject them
  590. function carjack()
  591. {
  592. %player = LocalClientConnection.getControlObject();
  593. if (%player.getClassName() $= "Player")
  594. {
  595. %eyeVec = %player.getEyeVector();
  596. %startPos = %player.getEyePoint();
  597. %endPos = VectorAdd(%startPos, VectorScale(%eyeVec, 1000));
  598. %target = ContainerRayCast(%startPos, %endPos, $TypeMasks::VehicleObjectType);
  599. if (%target)
  600. {
  601. // See if anyone is mounted in the car's driver seat
  602. %mount = %target.getMountNodeObject(0);
  603. // Can only carjack bots
  604. // remove '&& %mount.getClassName() $= "AIPlayer"' to allow you
  605. // to carjack anyone/anything
  606. if (%mount && %mount.getClassName() $= "AIPlayer")
  607. {
  608. commandToServer('carUnmountObj', %mount);
  609. }
  610. }
  611. }
  612. }
  613. // Bind the keys to the carjack command
  614. moveMap.bindCmd(keyboard, "ctrl z", "carjack();", "");
  615. // Starting vehicle action map code
  616. if ( isObject( vehicleMap ) )
  617. vehicleMap.delete();
  618. new ActionMap(vehicleMap);
  619. // The key command for flipping the car
  620. vehicleMap.bindCmd(keyboard, "ctrl x", "commandToServer(\'flipCar\');", "");
  621. function getOut()
  622. {
  623. vehicleMap.pop();
  624. moveMap.push();
  625. commandToServer('dismountVehicle');
  626. }
  627. function brakeLights()
  628. {
  629. // Turn on/off the Cheetah's head lights.
  630. commandToServer('toggleBrakeLights');
  631. }
  632. function brake(%val)
  633. {
  634. commandToServer('toggleBrakeLights');
  635. $mvTriggerCount2++;
  636. }
  637. vehicleMap.bind( keyboard, w, moveforward );
  638. vehicleMap.bind( keyboard, s, movebackward );
  639. vehicleMap.bind( keyboard, up, moveforward );
  640. vehicleMap.bind( keyboard, down, movebackward );
  641. vehicleMap.bind( mouse, xaxis, yaw );
  642. vehicleMap.bind( mouse, yaxis, pitch );
  643. vehicleMap.bind( mouse, button0, mouseFire );
  644. vehicleMap.bind( mouse, button1, altTrigger );
  645. vehicleMap.bindCmd(keyboard, "ctrl f","getout();","");
  646. vehicleMap.bind(keyboard, space, brake);
  647. vehicleMap.bindCmd(keyboard, "l", "brakeLights();", "");
  648. vehicleMap.bindCmd(keyboard, "escape", "", "handleEscape();");
  649. vehicleMap.bind( keyboard, v, toggleFreeLook ); // v for vanity
  650. //vehicleMap.bind(keyboard, tab, toggleFirstPerson );
  651. vehicleMap.bind(keyboard, "alt c", toggleCamera);
  652. // bind the left thumbstick for steering
  653. vehicleMap.bind( gamepad, thumblx, "D", "-0.23 0.23", gamepadYaw );
  654. // bind the gas, break, and reverse buttons
  655. vehicleMap.bind( gamepad, btn_a, moveforward );
  656. vehicleMap.bind( gamepad, btn_b, brake );
  657. vehicleMap.bind( gamepad, btn_x, movebackward );
  658. // bind exiting the vehicle to a button
  659. vehicleMap.bindCmd(gamepad, btn_y,"getout();","");
  660. // ----------------------------------------------------------------------------
  661. // Oculus Rift
  662. // ----------------------------------------------------------------------------
  663. function OVRSensorRotEuler(%pitch, %roll, %yaw)
  664. {
  665. //echo("Sensor euler: " @ %pitch SPC %roll SPC %yaw);
  666. $mvRotZ0 = %yaw;
  667. $mvRotX0 = %pitch;
  668. $mvRotY0 = %roll;
  669. }
  670. $mvRotIsEuler0 = true;
  671. $OculusVR::GenerateAngleAxisRotationEvents = false;
  672. $OculusVR::GenerateEulerRotationEvents = true;
  673. moveMap.bind( oculusvr, ovr_sensorrotang0, OVRSensorRotEuler );