Training.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. ** Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: training.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the training library core.
  10. **
  11. ** History:
  12. */
  13. #include "pch.h"
  14. #include "Training.h"
  15. #include "Mission2.h"
  16. #include "Mission3.h"
  17. #include "Mission4.h"
  18. #include "Mission5.h"
  19. #include "Mission6.h"
  20. namespace Training
  21. {
  22. //------------------------------------------------------------------------------
  23. // global variabes
  24. //------------------------------------------------------------------------------
  25. ControlData g_allowableControlScalars; // yaw, pitch, roll, throttle
  26. ControlData g_inputControls; // yaw, pitch, roll, throttle - the ones the player is actually inputing
  27. ControlData g_setInputControls; // yaw, pitch, roll, throttle - the ones we are forcing on the player
  28. int g_iAllowableActionMask;
  29. int g_iSetInputAction; // fire, afterburners, ... - the ones we force on the player
  30. TrainingMission* g_pMission = 0;
  31. bool g_bIsMission7;
  32. //------------------------------------------------------------------------------
  33. // primary interface to the training missions
  34. //------------------------------------------------------------------------------
  35. bool StartMission (int iMissionIndex)
  36. {
  37. // assign default values to the control masks
  38. g_allowableControlScalars.jsValues[c_axisYaw] = 1.0f;
  39. g_allowableControlScalars.jsValues[c_axisPitch] = 1.0f;
  40. g_allowableControlScalars.jsValues[c_axisRoll] = 1.0f;
  41. g_allowableControlScalars.jsValues[c_axisThrottle] = 1.0f;
  42. g_iAllowableActionMask = 0xffffffff;
  43. // be sure the set controls are cleared
  44. g_setInputControls.jsValues[c_axisYaw] = NA;
  45. g_setInputControls.jsValues[c_axisPitch] = NA;
  46. g_setInputControls.jsValues[c_axisRoll] = NA;
  47. g_setInputControls.jsValues[c_axisThrottle] = NA;
  48. g_iSetInputAction = 0;
  49. // set the HUD overlay back to nothing
  50. ClearTrainingOverlay ();
  51. // clear the mission 7 flag
  52. g_bIsMission7 = false;
  53. // create the appropriate mission, and start it
  54. switch (iMissionIndex)
  55. {
  56. case c_TM_2_Basic_Flight:
  57. g_pMission = new Mission2;
  58. break;
  59. case c_TM_3_Basic_Weaponry:
  60. g_pMission = new Mission3;
  61. break;
  62. case c_TM_4_Enemy_Engagement:
  63. g_pMission = new Mission4;
  64. break;
  65. case c_TM_5_Command_View:
  66. g_pMission = new Mission5;
  67. break;
  68. case c_TM_6_Practice_Arena:
  69. g_pMission = new Mission6;
  70. break;
  71. case c_TM_7_Live:
  72. g_bIsMission7 = true;
  73. // fall through
  74. default:
  75. // create no mission
  76. return false;
  77. }
  78. assert (g_pMission);
  79. g_pMission->Start ();
  80. // start training missions with the throttle off
  81. trekClient.OverrideThrottle (-1.0f);
  82. // return true to indicate that we started a mission
  83. return true;
  84. }
  85. //------------------------------------------------------------------------------
  86. bool HandleMission (void)
  87. {
  88. // handle the mission if necessary
  89. if (g_pMission and g_pMission->Frame ())
  90. {
  91. TrainingMission* pMission = g_pMission;
  92. g_pMission = 0;
  93. delete pMission;
  94. }
  95. return false;
  96. }
  97. //------------------------------------------------------------------------------
  98. bool EndMission (void)
  99. {
  100. if (g_bIsMission7)
  101. g_bIsMission7 = false;
  102. if (g_pMission)
  103. {
  104. g_pMission->Terminate ();
  105. return true;
  106. }
  107. return false;
  108. }
  109. //------------------------------------------------------------------------------
  110. void SetSkipPostSlideshow (void)
  111. {
  112. if (g_pMission)
  113. g_pMission->SetSkipPostSlideshow ();
  114. }
  115. //------------------------------------------------------------------------------
  116. bool IsTraining (void)
  117. {
  118. return g_pMission ? true : false;
  119. }
  120. //------------------------------------------------------------------------------
  121. bool IsInstalled (void)
  122. {
  123. return true;
  124. /*
  125. char szFilename[MAX_PATH + 1];
  126. HRESULT hr = UTL::getFile ("trainingsounddef", ".mdl", szFilename, true, true);
  127. return (hr == S_OK);
  128. */
  129. }
  130. //------------------------------------------------------------------------------
  131. int GetTrainingMissionID (void)
  132. {
  133. if (g_bIsMission7)
  134. return c_TM_7_Live;
  135. else if (g_pMission)
  136. return g_pMission->GetMissionID ();
  137. return NA;
  138. }
  139. //------------------------------------------------------------------------------
  140. SectorID GetStartSectorID (void)
  141. {
  142. assert (g_pMission);
  143. return g_pMission->GetStartSectorID ();
  144. }
  145. //------------------------------------------------------------------------------
  146. void SetupShipAndCamera (void)
  147. {
  148. assert (g_pMission);
  149. g_pMission->SetupShipAndCamera ();
  150. }
  151. //------------------------------------------------------------------------------
  152. // event trapping
  153. //------------------------------------------------------------------------------
  154. void RecordChat (ChatTarget recipient)
  155. {
  156. if (g_pMission)
  157. g_pMission->RecordChat (recipient);
  158. }
  159. //------------------------------------------------------------------------------
  160. bool RecordKeyPress (TrekKey key)
  161. {
  162. if (g_pMission)
  163. return g_pMission->RecordKeyPress (key);
  164. return true;
  165. }
  166. //------------------------------------------------------------------------------
  167. bool ShipLanded (void)
  168. {
  169. if (g_pMission)
  170. return g_pMission->ShipLanded ();
  171. return true;
  172. }
  173. //------------------------------------------------------------------------------
  174. void ShipDied (ImodelIGC* pLauncher)
  175. {
  176. if (g_pMission)
  177. g_pMission->ShipDied (pLauncher);
  178. }
  179. //------------------------------------------------------------------------------
  180. bool RestoreShip (void)
  181. {
  182. if (g_pMission)
  183. return g_pMission->RestoreShip ();
  184. return true;
  185. }
  186. //------------------------------------------------------------------------------
  187. // control constraint functions - note that these could be inlined
  188. //------------------------------------------------------------------------------
  189. ControlData& ApproveControls (ControlData& inputControls)
  190. {
  191. // copy the input controls for later retrieval
  192. g_inputControls = inputControls;
  193. // the fundamental limiter here is a multiplier that allows the commander of
  194. // the training mission to scale the control inputs as s/he sees fit. for the
  195. // most part, I expect that these values will be 0.0f or 1.0f
  196. inputControls.jsValues[c_axisYaw] *= g_allowableControlScalars.jsValues[c_axisYaw];
  197. inputControls.jsValues[c_axisPitch] *= g_allowableControlScalars.jsValues[c_axisPitch];
  198. inputControls.jsValues[c_axisRoll] *= g_allowableControlScalars.jsValues[c_axisRoll];
  199. // the throttle is mapping the range -1.0f to 1.0f from the joystick to the
  200. // more useful range 0.0f to 1.0f, as a result we have to translate the value
  201. // before scaling, then translate it back
  202. inputControls.jsValues[c_axisThrottle] = ((inputControls.jsValues[c_axisThrottle] + 1.0f) * g_allowableControlScalars.jsValues[c_axisThrottle]) - 1.0f;
  203. // here we check to see if the controls are specifically being overridden, and
  204. // if they are, we set them explicitly
  205. if (g_setInputControls.jsValues[c_axisYaw] != NA)
  206. inputControls.jsValues[c_axisYaw] = g_setInputControls.jsValues[c_axisYaw];
  207. if (g_setInputControls.jsValues[c_axisPitch] != NA)
  208. inputControls.jsValues[c_axisPitch] = g_setInputControls.jsValues[c_axisPitch];
  209. if (g_setInputControls.jsValues[c_axisRoll] != NA)
  210. inputControls.jsValues[c_axisRoll] = g_setInputControls.jsValues[c_axisRoll];
  211. if (g_setInputControls.jsValues[c_axisThrottle] != NA)
  212. inputControls.jsValues[c_axisThrottle] = (g_setInputControls.jsValues[c_axisThrottle] * 2.0f) - 1.0f;
  213. // the manipulated data is returned so it can be expressly used as a
  214. // parameter in a function call
  215. return inputControls;
  216. }
  217. //------------------------------------------------------------------------------
  218. int ApproveActions (int iInputMask)
  219. {
  220. // this gives the commander control over the actions by allowing her to
  221. // mask out the control inputs. The mask is combined with the actual
  222. // inputs using a "bitwise and", effectively disabling inputs whose mask
  223. // bit is not 1
  224. iInputMask &= g_iAllowableActionMask;
  225. // turn on whatever controls are being forced on
  226. iInputMask |= g_iSetInputAction;
  227. // return the result
  228. return iInputMask;
  229. }
  230. //------------------------------------------------------------------------------
  231. }