InputSettings.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // InputSettings.cpp
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 03/31/97 JMI Started.
  23. //
  24. // 04/25/97 JMI Added execute input.
  25. //
  26. // 05/13/97 JMI Changed 'Run' to 'Walk'.
  27. // Also, added 'Suicide' and 'NextLevel'.
  28. //
  29. // 05/14/97 JMI Changed key description of Next Level to "NextLevel" b/c
  30. // prefs does not seem to handle spaces in the var name
  31. // correctly.
  32. //
  33. // 05/14/97 JMI Added pick up.
  34. //
  35. // 06/09/97 JMI Swapped default keys for Strafe and Fire.
  36. //
  37. // 06/10/97 JMI Changed m_dDegreesPerSec to m_dMovingSlowDegreesPerSec and
  38. // added m_dMovingFastDegreesPerSec, m_dStillSlowDegreesPerSec,
  39. // m_dStillFastDegreesPerSec, and m_sTapRotationDegrees.
  40. //
  41. // 06/15/97 MJR Removed NextLevel.
  42. //
  43. // 07/03/97 JMI Moved InputInfo and ms_ainputinfo into CInputSettings.
  44. //
  45. // 07/06/97 JMI Changed m_au8PlayKeys[] from a U8 array to a short array,
  46. // m_asPlayKeys[].
  47. // Also, changed g_apszButtonDescriptions to
  48. // g_apszMouseButtonDescriptions.
  49. // Also, changed m_asPlayButtons to m_asPlayMouseButtons.
  50. //
  51. // 07/07/97 JMI Added m_dMouseSensitivityX and m_dMouseSensitivityY.
  52. //
  53. // 07/16/97 JMI Added Weapon10 enum.
  54. //
  55. // 07/25/97 JMI Removed PickUp enum and associated array entries.
  56. //
  57. // 08/04/97 JMI Added DefaultRotations().
  58. // Also, rotations (except for tap) were not saving with the
  59. // same var names they were loading with. Fixed.
  60. //
  61. // 08/10/97 JMI Changed defaults for mouse buttons to typical Doom mouse
  62. // player style.
  63. // Added StrafeLeft and StrafeRight inputs.
  64. // Also, changed Jump to Revive.
  65. //
  66. // 08/12/97 JMI Removed StrafeLeft and StrafeRight inputs. Replaced with
  67. // Strafe2 which can get you the same thing if you combine
  68. // both strafes with an turn arrow key.
  69. // Also, added Run2 which is handy for similar reasons.
  70. //
  71. // 08/24/97 JMI Moved Execute and Suicide to before the weapons and changed
  72. // the weapon descriptions to reflect the actual weapons.
  73. // Also, changed 'No Weapon' to be weapon 0 and 'Mines' to be
  74. // weapon 10.
  75. // Also, changed names for Strafe to Strafe1 and Run to Run1.
  76. //
  77. // 08/27/97 JMI Changed Run1 to Run, Run2 to Run_, Strafe1 to Strafe, and
  78. // Strafe2 to Strafe_. The reason I don't want to set them
  79. // to the same value is b/c these are the values used to
  80. // write them to the INI and have to be different. The deal
  81. // with using the _ is that it doesn't show up in Smash.fnt
  82. // so it looks fine. Cheezy, I know, but quick
  83. // implementation!
  84. //
  85. // 08/27/97 JMI Changed Run_ to Run. and Strafe_ to Strafe. .
  86. //
  87. // 08/27/97 JMI Added pszSaveName to InputInfo. Now saves using
  88. // pszSaveName.
  89. //
  90. // 08/27/97 JMI Added Fire2.
  91. //
  92. // 10/10/97 JMI Added m_sUseJoystick, JoyButtons, InputInfo.sJoyButtons.
  93. //
  94. //////////////////////////////////////////////////////////////////////////////
  95. //
  96. // Implementation for CInputSettings object. Each instance contains settings
  97. // for Postal input.
  98. //
  99. //////////////////////////////////////////////////////////////////////////////
  100. //////////////////////////////////////////////////////////////////////////////
  101. // C Headers -- Must be included before RSPiX.h b/c RSPiX utilizes SHMalloc.
  102. //////////////////////////////////////////////////////////////////////////////
  103. ///////////////////////////////////////////////////////////////////////////////
  104. // RSPiX Headers.
  105. ///////////////////////////////////////////////////////////////////////////////
  106. #include "RSPiX.h"
  107. ///////////////////////////////////////////////////////////////////////////////
  108. // Postal Headers.
  109. ///////////////////////////////////////////////////////////////////////////////
  110. #include "InputSettings.h"
  111. #include "game.h"
  112. #include "keys.h"
  113. //////////////////////////////////////////////////////////////////////////////
  114. // Module specific macros.
  115. //////////////////////////////////////////////////////////////////////////////
  116. //////////////////////////////////////////////////////////////////////////////
  117. // Module specific typedefs.
  118. //////////////////////////////////////////////////////////////////////////////
  119. //////////////////////////////////////////////////////////////////////////////
  120. // Exported (extern) variables.
  121. //////////////////////////////////////////////////////////////////////////////
  122. //////////////////////////////////////////////////////////////////////////////
  123. // Module specific (static) variables / Instantiate class statics.
  124. //////////////////////////////////////////////////////////////////////////////
  125. CInputSettings::InputInfo CInputSettings::ms_ainputinfoOld[CInputSettings::NumInputFunctions] =
  126. { // Description Save Name Default Key Default Mouse Button(s) Default Joy Button(s)
  127. // =========== =========== =========== ======================= =====================
  128. { "Turn Left", "Left", RSP_SK_A, 0, 0, },
  129. { "Turn Right", "Right", RSP_SK_D, 0, 0, },
  130. { "Forward", "Forward", RSP_SK_W, RightButton, 0, },
  131. { "Backward", "Backward", RSP_SK_S, 0, 0, },
  132. { "Up", "Up", 0, 0, 0, },
  133. { "Down", "Down", 0, 0, 0, },
  134. { "Left", "MoveLeft", 0, 0, 0, },
  135. { "Right", "MoveRight", 0, 0, 0, },
  136. { "Strafe Left", "StrafeLeft", 0, 0, 0, },
  137. { "Strafe Right", "StrafeRight", 0, 0, 0, },
  138. { "Walk", "Run1", RSP_SK_SHIFT, 0, 0, },
  139. { "Walk", "Run2", 0, 0, 0, },
  140. { "Strafe", "Strafe1", RSP_SK_ALT, MiddleButton, 0, },
  141. { "Strafe", "Strafe2", 0, 0, 0, },
  142. { "Fire", "Fire", RSP_SK_CONTROL, LeftButton, 0, },
  143. { "Fire", "Fire2", 0, 0, 0, },
  144. { "Fire Left", "FireLeft", 0, 0, 0, },
  145. { "Fire Right", "FireRight", 0, 0, 0, },
  146. { "Fire Up", "FireUp", 0, 0, 0, },
  147. { "Fire Down", "FireDown", 0, 0, 0, },
  148. { "Duck", "Duck", RSP_SK_F, 0, RSP_JOY_BUT_1, },
  149. { "Rejuvenate", "Rejuvenate", RSP_SK_SPACE, 0, RSP_JOY_BUT_1, },
  150. { "Execute", "Execute", RSP_SK_X, 0, RSP_JOY_BUT_3, },
  151. { "Suicide", "Suicide", RSP_SK_K, 0, RSP_JOY_BUT_4, },
  152. { "Next Level", "NextLevel", RSP_SK_F1, 0, RSP_JOY_BUT_2, },
  153. { "Next Weapon", "NextWeapon", RSP_SK_RBRACKET, 0, RSP_JOY_BUT_11, },
  154. { "Prev Weapon", "PrevWeapon", RSP_SK_LBRACKET, 0, RSP_JOY_BUT_10, },
  155. { "NoWeapon", "NoWeapon", RSP_SK_LQUOTE, 0, 0, },
  156. { "MachineGun", "MachineGun", RSP_SK_1, 0, 0, },
  157. { "Shotgun", "Shotgun", RSP_SK_2, 0, 0, },
  158. { "SprayCannon", "SprayCannon", RSP_SK_3, 0, 0, },
  159. { "Grenades", "Grenades", RSP_SK_4, 0, 0, },
  160. { "Missiles", "Missiles", RSP_SK_5, 0, 0, },
  161. { "Heatseekers", "Heatseekers", RSP_SK_6, 0, 0, },
  162. { "Molotovs", "Molotovs", RSP_SK_7, 0, 0, },
  163. { "Napalm", "Napalm", RSP_SK_8, 0, 0, },
  164. { "Flamer", "Flamer", RSP_SK_9, 0, 0, },
  165. { "Mines", "Mines", RSP_SK_0, 0, 0, },
  166. };
  167. CInputSettings::InputInfo CInputSettings::ms_ainputinfo[CInputSettings::NumInputFunctions] =
  168. { // Description Save Name Default Key Default Mouse Button(s) Default Joy Button(s)
  169. // =========== =========== =========== ======================= =====================
  170. { "Turn Left", "Left", 0, 0, 0, },
  171. { "Turn Right", "Right", 0, 0, 0, },
  172. { "Forward", "Forward", 0, 0, 0, },
  173. { "Backward", "Backward", 0, 0, 0, },
  174. { "Up", "Up", RSP_SK_W, 0, 0, },
  175. { "Down", "Down", RSP_SK_S, 0, 0, },
  176. { "Left", "MoveLeft", RSP_SK_A, 0, 0, },
  177. { "Right", "MoveRight", RSP_SK_D, 0, 0, },
  178. { "Strafe Left", "StrafeLeft", 0, 0, 0, },
  179. { "Strafe Right", "StrafeRight", 0, 0, 0, },
  180. { "Walk", "Run1", RSP_SK_SHIFT, 0, 0, },
  181. { "Walk", "Run2", 0, 0, 0, },
  182. { "Strafe", "Strafe1", 0, 0, 0, },
  183. { "Strafe", "Strafe2", 0, 0, 0, },
  184. { "Fire", "Fire", RSP_SK_CONTROL, 0, RSP_JOY_BUT_17, },
  185. { "Fire", "Fire2", 0, 0, 0, },
  186. { "Fire Left", "FireLeft", RSP_SK_LEFT, 0, 0, },
  187. { "Fire Right", "FireRight", RSP_SK_RIGHT, 0, 0, },
  188. { "Fire Up", "FireUp", RSP_SK_UP, 0, 0, },
  189. { "Fire Down", "FireDown", RSP_SK_DOWN, 0, 0, },
  190. { "Duck", "Duck", RSP_SK_F, 0, RSP_JOY_BUT_16, },
  191. { "Rejuvenate", "Rejuvenate", RSP_SK_SPACE, 0, RSP_JOY_BUT_1, },
  192. { "Execute", "Execute", RSP_SK_X, 0, RSP_JOY_BUT_3, },
  193. { "Suicide", "Suicide", RSP_SK_K, 0, RSP_JOY_BUT_4, },
  194. { "Next Level", "NextLevel", RSP_SK_F1, 0, RSP_JOY_BUT_2, },
  195. { "Next Weapon", "NextWeapon", RSP_SK_RBRACKET, 0, RSP_JOY_BUT_11, },
  196. { "Prev Weapon", "PrevWeapon", RSP_SK_LBRACKET, 0, RSP_JOY_BUT_10, },
  197. { "NoWeapon", "NoWeapon", RSP_SK_LQUOTE, 0, 0, },
  198. { "MachineGun", "MachineGun", RSP_SK_1, 0, 0, },
  199. { "Shotgun", "Shotgun", RSP_SK_2, 0, 0, },
  200. { "SprayCannon", "SprayCannon", RSP_SK_3, 0, 0, },
  201. { "Grenades", "Grenades", RSP_SK_4, 0, 0, },
  202. { "Missiles", "Missiles", RSP_SK_5, 0, 0, },
  203. { "Heatseekers", "Heatseekers", RSP_SK_6, 0, 0, },
  204. { "Molotovs", "Molotovs", RSP_SK_7, 0, 0, },
  205. { "Napalm", "Napalm", RSP_SK_8, 0, 0, },
  206. { "Flamer", "Flamer", RSP_SK_9, 0, 0, },
  207. { "Mines", "Mines", RSP_SK_0, 0, 0, },
  208. };
  209. //////////////////////////////////////////////////////////////////////////////
  210. // Module specific (static) protos.
  211. //////////////////////////////////////////////////////////////////////////////
  212. //////////////////////////////////////////////////////////////////////////////
  213. // Functions.
  214. //////////////////////////////////////////////////////////////////////////////
  215. //////////////////////////////////////////////////////////////////////////////
  216. // Set settings to default values
  217. //////////////////////////////////////////////////////////////////////////////
  218. CInputSettings::CInputSettings(void)
  219. {
  220. // There is a separate function for these so outside sources can default
  221. // them at anytime.
  222. DefaultRotations();
  223. m_sUseMouse = FALSE;
  224. m_sUseJoy = FALSE;
  225. m_dMouseSensitivityX = 1.00; // 100%
  226. m_dMouseSensitivityY = 1.00; // 100%
  227. // Set default inputs (in case no INI is loaded).
  228. short i;
  229. for (i = 0; i < NumInputFunctions; i++)
  230. {
  231. m_asPlayKeys[i] = ms_ainputinfo[i].u8DefaultKey;
  232. m_asPlayMouseButtons[i] = ms_ainputinfo[i].sDefMouseButtons;
  233. m_asPlayJoyButtons[i] = ms_ainputinfo[i].sDefJoyButtons;
  234. }
  235. }
  236. //////////////////////////////////////////////////////////////////////////////
  237. // Destructor
  238. //////////////////////////////////////////////////////////////////////////////
  239. CInputSettings::~CInputSettings()
  240. {
  241. }
  242. //////////////////////////////////////////////////////////////////////////////
  243. // Read settings that are stored in preference file
  244. //////////////////////////////////////////////////////////////////////////////
  245. short CInputSettings::LoadPrefs(
  246. RPrefs* pPrefs)
  247. {
  248. short sResult = 0;
  249. pPrefs->GetVal("Input", "WalkTurnRate", m_dMovingSlowDegreesPerSec, &m_dMovingSlowDegreesPerSec);
  250. pPrefs->GetVal("Input", "RunTurnRate", m_dMovingFastDegreesPerSec, &m_dMovingFastDegreesPerSec);
  251. pPrefs->GetVal("Input", "StillSlowTurnRate", m_dStillSlowDegreesPerSec, &m_dStillSlowDegreesPerSec);
  252. pPrefs->GetVal("Input", "StillFastTurnRate", m_dStillFastDegreesPerSec, &m_dStillFastDegreesPerSec);
  253. pPrefs->GetVal("Input", "TapRotationDegrees", m_sTapRotationDegrees, &m_sTapRotationDegrees);
  254. pPrefs->GetVal("Input", "MouseSensitivityX", m_dMouseSensitivityX, &m_dMouseSensitivityX);
  255. pPrefs->GetVal("Input", "MouseSensitivityY", m_dMouseSensitivityY, &m_dMouseSensitivityY);
  256. pPrefs->GetVal("Input", "UseMouse", m_sUseMouse, &m_sUseMouse);
  257. pPrefs->GetVal("Input", "UseJoystick", m_sUseJoy, &m_sUseJoy);
  258. pPrefs->GetVal("Input", "JoyButtonMenuStart", 7, &m_sJoyStartButton);
  259. pPrefs->GetVal("Input", "JoyButtonMenuUp", 12, &m_sJoyMenuUpButton);
  260. pPrefs->GetVal("Input", "JoyButtonMenuDown", 13, &m_sJoyMenuDownButton);
  261. pPrefs->GetVal("Input", "JoyButtonMenuLeft", 14, &m_sJoyMenuLeftButton);
  262. pPrefs->GetVal("Input", "JoyButtonMenuRight", 15, &m_sJoyMenuRightButton);
  263. pPrefs->GetVal("Input", "JoyAxisMenuUp", 4, &m_sJoyMenuUpAxis);
  264. pPrefs->GetVal("Input", "JoyAxisMenuDown", 3, &m_sJoyMenuDownAxis);
  265. pPrefs->GetVal("Input", "JoyAxisMenuLeft", 2, &m_sJoyMenuLeftAxis);
  266. pPrefs->GetVal("Input", "JoyAxisMenuRight", 1, &m_sJoyMenuRightAxis);
  267. pPrefs->GetVal("Input", "JoyButtonMenuConfirm", 1, &m_sJoyMenuConfirmButton);
  268. pPrefs->GetVal("Input", "JoyButtonMenuBack", 2, &m_sJoyMenuBackButton);
  269. pPrefs->GetVal("Input", "JoyButtonMenuBack2", 5, &m_sJoyMenuBackButton2);
  270. pPrefs->GetVal("Input", "JoyButtonMenuDeleteKeybind", 5, &m_sJoyMenuDeleteKeybindButton);
  271. // Game play keys.
  272. short i;
  273. char szDescriptor[256];
  274. for (i = 0; i < NumInputFunctions; i++)
  275. {
  276. pPrefs->GetVal(
  277. "Keys",
  278. ms_ainputinfo[i].pszSaveName,
  279. g_apszKeyDescriptions[m_asPlayKeys[i]],
  280. szDescriptor
  281. );
  282. // Attempt to translate . . .
  283. if (KeyDescriptionToValue(szDescriptor, &(m_asPlayKeys[i]) ) != 0)
  284. {
  285. TRACE("LoadPrefs(): Failed to convert key description %s to key value.\n",
  286. szDescriptor);
  287. }
  288. pPrefs->GetVal(
  289. "Mouse",
  290. ms_ainputinfo[i].pszSaveName,
  291. g_apszMouseButtonDescriptions[MouseBitfieldToIndex(m_asPlayMouseButtons[i])],
  292. szDescriptor
  293. );
  294. // Attempt to translate . . .
  295. if (MouseButtonDescriptionToMask(szDescriptor, &(m_asPlayMouseButtons[i]) ) != 0)
  296. {
  297. TRACE("LoadPrefs(): Failed to convert mouse button description %s to button mask.\n",
  298. szDescriptor);
  299. }
  300. pPrefs->GetVal(
  301. "Joystick",
  302. ms_ainputinfo[i].pszSaveName,
  303. g_apszJoyButtonDescriptions[JoyBitfieldToIndex(m_asPlayJoyButtons[i])],
  304. szDescriptor
  305. );
  306. // Attempt to translate . . .
  307. if (JoyButtonDescriptionToMask(szDescriptor, &(m_asPlayJoyButtons[i]) ) != 0)
  308. {
  309. TRACE("LoadPrefs(): Failed to convert joy button description %s to button mask.\n",
  310. szDescriptor);
  311. }
  312. }
  313. if (!sResult)
  314. {
  315. if (pPrefs->IsError())
  316. sResult = -1;
  317. }
  318. return sResult;
  319. }
  320. //////////////////////////////////////////////////////////////////////////////
  321. // Write settings that are stored in preference file
  322. //////////////////////////////////////////////////////////////////////////////
  323. short CInputSettings::SavePrefs(
  324. RPrefs* pPrefs)
  325. {
  326. pPrefs->SetVal("Input", "WalkTurnRate", m_dMovingSlowDegreesPerSec);
  327. pPrefs->SetVal("Input", "RunTurnRate", m_dMovingFastDegreesPerSec);
  328. pPrefs->SetVal("Input", "StillSlowTurnRate", m_dStillSlowDegreesPerSec);
  329. pPrefs->SetVal("Input", "StillFastTurnRate", m_dStillFastDegreesPerSec);
  330. pPrefs->SetVal("Input", "TapRotationDegrees", m_sTapRotationDegrees);
  331. pPrefs->SetVal("Input", "MouseSensitivityX", m_dMouseSensitivityX);
  332. pPrefs->SetVal("Input", "MouseSensitivityY", m_dMouseSensitivityY);
  333. pPrefs->SetVal("Input", "UseMouse", m_sUseMouse);
  334. pPrefs->SetVal("Input", "UseJoystick", m_sUseJoy);
  335. // Game play input.
  336. short i;
  337. for (i = 0; i < NumInputFunctions; i++)
  338. {
  339. pPrefs->SetVal(
  340. "Keys",
  341. ms_ainputinfo[i].pszSaveName,
  342. g_apszKeyDescriptions[m_asPlayKeys[i]]
  343. );
  344. pPrefs->SetVal(
  345. "Mouse",
  346. ms_ainputinfo[i].pszSaveName,
  347. g_apszMouseButtonDescriptions[MouseBitfieldToIndex(m_asPlayMouseButtons[i])]
  348. );
  349. pPrefs->SetVal(
  350. "Joystick",
  351. ms_ainputinfo[i].pszSaveName,
  352. g_apszJoyButtonDescriptions[JoyBitfieldToIndex(m_asPlayJoyButtons[i])]
  353. );
  354. }
  355. return pPrefs->IsError();
  356. }
  357. //////////////////////////////////////////////////////////////////////////////
  358. // Load settings that are stored in game file
  359. //////////////////////////////////////////////////////////////////////////////
  360. short CInputSettings::LoadGame(
  361. RFile* pFile)
  362. {
  363. return 0;
  364. }
  365. //////////////////////////////////////////////////////////////////////////////
  366. // Save settings that are stored in game file
  367. //////////////////////////////////////////////////////////////////////////////
  368. short CInputSettings::SaveGame(
  369. RFile* pFile)
  370. {
  371. return 0;
  372. }
  373. //////////////////////////////////////////////////////////////////////////////
  374. // Temporarily set settings for demo mode (file is for saving current settings)
  375. //////////////////////////////////////////////////////////////////////////////
  376. short CInputSettings::PreDemo(
  377. RFile* pFile)
  378. {
  379. // Store current keys?
  380. return 0;
  381. }
  382. //////////////////////////////////////////////////////////////////////////////
  383. // Restore settings to what they were prior to demo mode
  384. //////////////////////////////////////////////////////////////////////////////
  385. short CInputSettings::PostDemo(
  386. RFile* pFile)
  387. {
  388. // Restore user keys?
  389. return 0;
  390. }
  391. ///////////////////////////////////////////////////////////////////////////////
  392. // Set rotation values to the defaults.
  393. ///////////////////////////////////////////////////////////////////////////////
  394. void CInputSettings::DefaultRotations(void)
  395. {
  396. m_dMovingSlowDegreesPerSec = 240.0;
  397. m_dMovingFastDegreesPerSec = 300.0;
  398. m_dStillSlowDegreesPerSec = 180.0;
  399. m_dStillFastDegreesPerSec = 240.0;
  400. m_sTapRotationDegrees = 10;
  401. }
  402. ///////////////////////////////////////////////////////////////////////////////
  403. // Internal functions.
  404. ///////////////////////////////////////////////////////////////////////////////
  405. ///////////////////////////////////////////////////////////////////////////////
  406. // EOF
  407. ///////////////////////////////////////////////////////////////////////////////