inputCommands.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. function escapeFromGame()
  23. {
  24. disconnect();
  25. }
  26. function showPlayerList(%val)
  27. {
  28. if (%val)
  29. PlayerListGui.toggle();
  30. }
  31. function hideHUDs(%val)
  32. {
  33. if (%val)
  34. HudlessPlayGui.toggle();
  35. }
  36. function doScreenShotHudless(%val)
  37. {
  38. if(%val)
  39. {
  40. canvas.setContent(HudlessPlayGui);
  41. //doScreenshot(%val);
  42. schedule(10, 0, "doScreenShot", %val);
  43. }
  44. else
  45. canvas.setContent(PlayGui);
  46. }
  47. $movementSpeed = 1; // m/s
  48. function setSpeed(%speed)
  49. {
  50. if(%speed)
  51. $movementSpeed = %speed;
  52. }
  53. function moveleft(%val)
  54. {
  55. $mvLeftAction = %val * $movementSpeed;
  56. }
  57. function moveright(%val)
  58. {
  59. $mvRightAction = %val * $movementSpeed;
  60. }
  61. function moveforward(%val)
  62. {
  63. $mvForwardAction = %val * $movementSpeed;
  64. }
  65. function movebackward(%val)
  66. {
  67. $mvBackwardAction = %val * $movementSpeed;
  68. }
  69. function moveup(%val)
  70. {
  71. %object = ServerConnection.getControlObject();
  72. if(%object.isInNamespaceHierarchy("Camera"))
  73. $mvUpAction = %val * $movementSpeed;
  74. }
  75. function movedown(%val)
  76. {
  77. %object = ServerConnection.getControlObject();
  78. if(%object.isInNamespaceHierarchy("Camera"))
  79. $mvDownAction = %val * $movementSpeed;
  80. }
  81. function turnLeft( %val )
  82. {
  83. $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  84. }
  85. function turnRight( %val )
  86. {
  87. $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  88. }
  89. function panUp( %val )
  90. {
  91. $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  92. }
  93. function panDown( %val )
  94. {
  95. $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  96. }
  97. function getMouseAdjustAmount(%val)
  98. {
  99. // based on a default camera FOV of 90'
  100. return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
  101. }
  102. function getGamepadAdjustAmount(%val)
  103. {
  104. // based on a default camera FOV of 90'
  105. return(%val * ($cameraFov / 90) * 0.01) * 10.0;
  106. }
  107. function yaw(%val)
  108. {
  109. %yawAdj = getMouseAdjustAmount(%val);
  110. if(ServerConnection.isControlObjectRotDampedCamera())
  111. {
  112. // Clamp and scale
  113. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  114. %yawAdj *= 0.5;
  115. }
  116. $mvYaw += %yawAdj;
  117. }
  118. function pitch(%val)
  119. {
  120. %pitchAdj = getMouseAdjustAmount(%val);
  121. if(ServerConnection.isControlObjectRotDampedCamera())
  122. {
  123. // Clamp and scale
  124. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  125. %pitchAdj *= 0.5;
  126. }
  127. $mvPitch += %pitchAdj;
  128. }
  129. function jump(%val)
  130. {
  131. $mvTriggerCount2++;
  132. }
  133. function gamePadMoveX( %val )
  134. {
  135. if(%val > 0)
  136. {
  137. $mvRightAction = %val * $movementSpeed;
  138. $mvLeftAction = 0;
  139. }
  140. else
  141. {
  142. $mvRightAction = 0;
  143. $mvLeftAction = -%val * $movementSpeed;
  144. }
  145. }
  146. function gamePadMoveY( %val )
  147. {
  148. if(%val > 0)
  149. {
  150. $mvForwardAction = %val * $movementSpeed;
  151. $mvBackwardAction = 0;
  152. }
  153. else
  154. {
  155. $mvForwardAction = 0;
  156. $mvBackwardAction = -%val * $movementSpeed;
  157. }
  158. }
  159. function gamepadYaw(%val)
  160. {
  161. %yawAdj = getGamepadAdjustAmount(%val);
  162. if(ServerConnection.isControlObjectRotDampedCamera())
  163. {
  164. // Clamp and scale
  165. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  166. %yawAdj *= 0.5;
  167. }
  168. if(%yawAdj > 0)
  169. {
  170. $mvYawLeftSpeed = %yawAdj;
  171. $mvYawRightSpeed = 0;
  172. }
  173. else
  174. {
  175. $mvYawLeftSpeed = 0;
  176. $mvYawRightSpeed = -%yawAdj;
  177. }
  178. }
  179. function gamepadPitch(%val)
  180. {
  181. %pitchAdj = getGamepadAdjustAmount(%val);
  182. if(ServerConnection.isControlObjectRotDampedCamera())
  183. {
  184. // Clamp and scale
  185. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  186. %pitchAdj *= 0.5;
  187. }
  188. if(%pitchAdj > 0)
  189. {
  190. $mvPitchDownSpeed = %pitchAdj;
  191. $mvPitchUpSpeed = 0;
  192. }
  193. else
  194. {
  195. $mvPitchDownSpeed = 0;
  196. $mvPitchUpSpeed = -%pitchAdj;
  197. }
  198. }
  199. function doCrouch(%val)
  200. {
  201. $mvTriggerCount3++;
  202. }
  203. function doSprint(%val)
  204. {
  205. $mvTriggerCount5++;
  206. }
  207. function mouseFire(%val)
  208. {
  209. $mvTriggerCount0++;
  210. }
  211. function gamepadFire(%val)
  212. {
  213. if(%val > 0.1 && !$gamepadFireTriggered)
  214. {
  215. $gamepadFireTriggered = true;
  216. $mvTriggerCount0++;
  217. }
  218. else if(%val <= 0.1 && $gamepadFireTriggered)
  219. {
  220. $gamepadFireTriggered = false;
  221. $mvTriggerCount0++;
  222. }
  223. }
  224. function gamepadAltTrigger(%val)
  225. {
  226. if(%val > 0.1 && !$gamepadAltTriggerTriggered)
  227. {
  228. $gamepadAltTriggerTriggered = true;
  229. $mvTriggerCount1++;
  230. }
  231. else if(%val <= 0.1 && $gamepadAltTriggerTriggered)
  232. {
  233. $gamepadAltTriggerTriggered = false;
  234. $mvTriggerCount1++;
  235. }
  236. }
  237. function toggleZoomFOV()
  238. {
  239. $Player::CurrentFOV = $Player::CurrentFOV / 2;
  240. if($Player::CurrentFOV < 5)
  241. resetCurrentFOV();
  242. if(ServerConnection.zoomed)
  243. setFOV($Player::CurrentFOV);
  244. else
  245. {
  246. setFov(ServerConnection.getControlCameraDefaultFov());
  247. }
  248. }
  249. function resetCurrentFOV()
  250. {
  251. $Player::CurrentFOV = ServerConnection.getControlCameraDefaultFov() / 2;
  252. }
  253. function turnOffZoom()
  254. {
  255. ServerConnection.zoomed = false;
  256. setFov(ServerConnection.getControlCameraDefaultFov());
  257. Reticle.setVisible(true);
  258. zoomReticle.setVisible(false);
  259. // Rather than just disable the DOF effect, we want to set it to the level's
  260. // preset values.
  261. //DOFPostEffect.disable();
  262. ppOptionsUpdateDOFSettings();
  263. }
  264. function setZoomFOV(%val)
  265. {
  266. if(%val)
  267. toggleZoomFOV();
  268. }
  269. function toggleZoom(%val)
  270. {
  271. if (%val)
  272. {
  273. ServerConnection.zoomed = true;
  274. setFov($Player::CurrentFOV);
  275. Reticle.setVisible(false);
  276. zoomReticle.setVisible(true);
  277. DOFPostEffect.setAutoFocus( true );
  278. DOFPostEffect.setFocusParams( 0.5, 0.5, 50, 500, -5, 5 );
  279. DOFPostEffect.enable();
  280. }
  281. else
  282. {
  283. turnOffZoom();
  284. }
  285. }
  286. function mouseButtonZoom(%val)
  287. {
  288. toggleZoom(%val);
  289. }
  290. function toggleFreeLook( %val )
  291. {
  292. if ( %val )
  293. $mvFreeLook = true;
  294. else
  295. $mvFreeLook = false;
  296. }
  297. function toggleFirstPerson(%val)
  298. {
  299. if (%val)
  300. {
  301. ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
  302. }
  303. }
  304. function toggleCamera(%val)
  305. {
  306. if (%val)
  307. commandToServer('ToggleCamera');
  308. }
  309. function unmountWeapon(%val)
  310. {
  311. if (%val)
  312. commandToServer('unmountWeapon');
  313. }
  314. function throwWeapon(%val)
  315. {
  316. if (%val)
  317. commandToServer('Throw', "Weapon");
  318. }
  319. function tossAmmo(%val)
  320. {
  321. if (%val)
  322. commandToServer('Throw', "Ammo");
  323. }
  324. function nextWeapon(%val)
  325. {
  326. if (%val)
  327. commandToServer('cycleWeapon', "next");
  328. }
  329. function prevWeapon(%val)
  330. {
  331. if (%val)
  332. commandToServer('cycleWeapon', "prev");
  333. }
  334. function mouseWheelWeaponCycle(%val)
  335. {
  336. if (%val < 0)
  337. commandToServer('cycleWeapon', "next");
  338. else if (%val > 0)
  339. commandToServer('cycleWeapon', "prev");
  340. }
  341. function pageMessageHudUp( %val )
  342. {
  343. if ( %val )
  344. pageUpMessageHud();
  345. }
  346. function pageMessageHudDown( %val )
  347. {
  348. if ( %val )
  349. pageDownMessageHud();
  350. }
  351. function resizeMessageHud( %val )
  352. {
  353. if ( %val )
  354. cycleMessageHudSize();
  355. }
  356. function startRecordingDemo( %val )
  357. {
  358. if ( %val )
  359. startDemoRecord();
  360. }
  361. function stopRecordingDemo( %val )
  362. {
  363. if ( %val )
  364. stopDemoRecord();
  365. }
  366. function dropCameraAtPlayer(%val)
  367. {
  368. if (%val)
  369. commandToServer('dropCameraAtPlayer');
  370. }
  371. function dropPlayerAtCamera(%val)
  372. {
  373. if (%val)
  374. commandToServer('DropPlayerAtCamera');
  375. }
  376. function bringUpOptions(%val)
  377. {
  378. if (%val)
  379. Canvas.pushDialog(OptionsDlg);
  380. }
  381. GlobalActionMap.bind(keyboard, "ctrl o", bringUpOptions);
  382. //------------------------------------------------------------------------------
  383. // Debugging Functions
  384. //------------------------------------------------------------------------------
  385. function showMetrics(%val)
  386. {
  387. if(%val)
  388. {
  389. if(!Canvas.isMember(FrameOverlayGui))
  390. metrics("fps gfx shadow sfx terrain groundcover forest net");
  391. else
  392. metrics("");
  393. }
  394. }
  395. GlobalActionMap.bind(keyboard, "ctrl F2", showMetrics);
  396. //------------------------------------------------------------------------------
  397. //
  398. // Start profiler by pressing ctrl f3
  399. // ctrl f3 - starts profile that will dump to console and file
  400. //
  401. function doProfile(%val)
  402. {
  403. if (%val)
  404. {
  405. // key down -- start profile
  406. echo("Starting profile session...");
  407. profilerReset();
  408. profilerEnable(true);
  409. }
  410. else
  411. {
  412. // key up -- finish off profile
  413. echo("Ending profile session...");
  414. profilerDumpToFile("profilerDumpToFile" @ getSimTime() @ ".txt");
  415. profilerEnable(false);
  416. }
  417. }
  418. // Trace a line along the direction the crosshair is pointing
  419. // If you find a car with a player in it...eject them
  420. function carjack()
  421. {
  422. %player = LocalClientConnection.getControlObject();
  423. if (%player.getClassName() $= "Player")
  424. {
  425. %eyeVec = %player.getEyeVector();
  426. %startPos = %player.getEyePoint();
  427. %endPos = VectorAdd(%startPos, VectorScale(%eyeVec, 1000));
  428. %target = ContainerRayCast(%startPos, %endPos, $TypeMasks::VehicleObjectType);
  429. if (%target)
  430. {
  431. // See if anyone is mounted in the car's driver seat
  432. %mount = %target.getMountNodeObject(0);
  433. // Can only carjack bots
  434. // remove '&& %mount.getClassName() $= "AIPlayer"' to allow you
  435. // to carjack anyone/anything
  436. if (%mount && %mount.getClassName() $= "AIPlayer")
  437. {
  438. commandToServer('carUnmountObj', %mount);
  439. }
  440. }
  441. }
  442. }
  443. function getOut()
  444. {
  445. vehicleMap.pop();
  446. moveMap.push();
  447. commandToServer('dismountVehicle');
  448. }
  449. function brakeLights()
  450. {
  451. // Turn on/off the Cheetah's head lights.
  452. commandToServer('toggleBrakeLights');
  453. }
  454. function brake(%val)
  455. {
  456. commandToServer('toggleBrakeLights');
  457. $mvTriggerCount2++;
  458. }