Game.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #ifndef __GAME_H
  13. #define __GAME_H 1
  14. #include <GameMP/PlayerSettings.h>
  15. #include <GameMP/SessionProperties.h>
  16. #define GAME_SHELL_VER "V012"
  17. #define AXIS_ACTIONS_CT 9
  18. #define SENSITIVITY_SLIDER_POSITIONS 25
  19. // all available axis-actions are listed here
  20. #define AXIS_MOVE_UD 0
  21. #define AXIS_MOVE_LR 1
  22. #define AXIS_MOVE_FB 2
  23. #define AXIS_TURN_UD 3
  24. #define AXIS_TURN_LR 4
  25. #define AXIS_TURN_BK 5
  26. #define AXIS_LOOK_UD 6
  27. #define AXIS_LOOK_LR 7
  28. #define AXIS_LOOK_BK 8
  29. enum ConsoleState {
  30. CS_OFF,
  31. CS_ON,
  32. CS_TURNINGON,
  33. CS_TURNINGOFF,
  34. CS_ONINBACKGROUND,
  35. CS_TALK,
  36. };
  37. class CGameTimerHandler : public CTimerHandler
  38. {
  39. public:
  40. /* This is called every TickQuantum seconds. */
  41. virtual void HandleTimer(void);
  42. };
  43. class CAxisAction {
  44. public:
  45. INDEX aa_iAxisAction; // to which axis this object referes to
  46. FLOAT aa_fSensitivity; // percentage of maximum sensitivity (0..100)
  47. FLOAT aa_fDeadZone; // percentage of deadzone (0..100)
  48. BOOL aa_bInvert; // if controler's axis should be inverted
  49. BOOL aa_bRelativeControler; // if this is controler of type "relative"
  50. BOOL aa_bSmooth; // if controler's axis should be smoothed
  51. // this is value for applying to "angle" or "movement" and it
  52. // is calculated from invert flag and sensitivity attributes
  53. // (i.e. for rotation colud be: AXIS_ROTATION_SPEED*sensitivity*(-1)(if should invert axis)
  54. FLOAT aa_fAxisInfluence;
  55. FLOAT aa_fLastReading; // last reading of this axis (for smoothing)
  56. FLOAT aa_fAbsolute; // absolute value of the axis (integrated from previous readings)
  57. };
  58. class CButtonAction {
  59. public:
  60. // default constructor
  61. CButtonAction();
  62. CListNode ba_lnNode;
  63. INDEX ba_iFirstKey;
  64. BOOL ba_bFirstKeyDown;
  65. INDEX ba_iSecondKey;
  66. BOOL ba_bSecondKeyDown;
  67. CTString ba_strName;
  68. CTString ba_strCommandLineWhenPressed;
  69. CTString ba_strCommandLineWhenReleased;
  70. // Assignment operator.
  71. virtual CButtonAction &operator=(CButtonAction &baOriginal);
  72. virtual void Read_t( CTStream &istrm); // throw char*
  73. virtual void Write_t( CTStream &ostrm); // throw char*
  74. };
  75. /*
  76. * Class containing information concerning controls system
  77. */
  78. class CControls {
  79. public:
  80. // list of mounted button actions
  81. CListHead ctrl_lhButtonActions;
  82. // objects describing mounted controler's axis (mouse L/R, joy U/D) and their
  83. // attributes (sensitivity, intvertness, type (relative/absolute) ...)
  84. CAxisAction ctrl_aaAxisActions[ AXIS_ACTIONS_CT];
  85. FLOAT ctrl_fSensitivity; // global sensitivity for all axes
  86. BOOL ctrl_bInvertLook; // inverts up/down looking
  87. BOOL ctrl_bSmoothAxes; // smooths axes movements
  88. // operations
  89. CControls(void); // default constructor
  90. virtual ~CControls(void); // default destructor
  91. // Assignment operator.
  92. virtual CControls &operator=(CControls &ctrlOriginal);
  93. // depending on axis attributes and type (rotation or translation), calculates axis
  94. // influence factors for all axis actions
  95. virtual void CalculateInfluencesForAllAxis(void);
  96. // get current reading of an axis
  97. virtual FLOAT GetAxisValue(INDEX iAxis);
  98. // check if these controls use any joystick
  99. virtual BOOL UsesJoystick(void);
  100. // switches button and axis action mounters to defaults
  101. virtual void SwitchAxesToDefaults(void);
  102. virtual void SwitchToDefaults(void);
  103. virtual void DoButtonActions(void);
  104. virtual void CreateAction(const CPlayerCharacter &pc, CPlayerAction &paAction, BOOL bPreScan);
  105. virtual CButtonAction &AddButtonAction(void);
  106. virtual void RemoveButtonAction( CButtonAction &baButtonAction);
  107. virtual void Load_t( CTFileName fnFile); // throw char *
  108. virtual void Save_t( CTFileName fnFile); // throw char *
  109. };
  110. class CLocalPlayer
  111. {
  112. public:
  113. // Attributes
  114. BOOL lp_bActive;
  115. INDEX lp_iPlayer;
  116. CPlayerSource *lp_pplsPlayerSource;
  117. UBYTE lp_ubPlayerControlsState[2048]; // current state of player controls that are local to the player
  118. // Construction
  119. CLocalPlayer( void)
  120. {
  121. lp_pplsPlayerSource = NULL;
  122. lp_bActive = FALSE;
  123. memset(lp_ubPlayerControlsState, 0, sizeof(lp_ubPlayerControlsState)) ;
  124. };
  125. };
  126. #define HIGHSCORE_COUNT 10
  127. class CHighScoreEntry {
  128. public:
  129. CTString hse_strPlayer;
  130. enum CSessionProperties::GameDifficulty hse_gdDifficulty;
  131. TIME hse_tmTime;
  132. INDEX hse_ctKills;
  133. INDEX hse_ctScore;
  134. public:
  135. CHighScoreEntry(void);
  136. };
  137. /*
  138. * Class responsible for handling game interface
  139. */
  140. class CGame {
  141. public:
  142. enum ConsoleState gm_csConsoleState;
  143. enum ConsoleState gm_csComputerState;
  144. CTFileName gm_fnSaveFileName;
  145. CTString gam_strCustomLevel;
  146. CTString gam_strSessionName;
  147. CTString gam_strJoinAddress;
  148. CTString gam_strConsoleInputBuffer;
  149. CTString gm_astrAxisNames[AXIS_ACTIONS_CT];
  150. CHighScoreEntry gm_ahseHighScores[HIGHSCORE_COUNT];
  151. INDEX gm_iLastSetHighScore;
  152. CPlayerCharacter gm_apcPlayers[8];
  153. CControls gm_actrlControls[8];
  154. CControls gm_ctrlControlsExtra;
  155. INDEX gm_iSinglePlayer;
  156. INDEX gm_iWEDSinglePlayer;
  157. enum SplitScreenCfg {
  158. SSC_DEDICATED = -2,
  159. SSC_OBSERVER = -1,
  160. SSC_PLAY1 = 0,
  161. SSC_PLAY2 = 1,
  162. SSC_PLAY3 = 2,
  163. SSC_PLAY4 = 3,
  164. };
  165. enum SplitScreenCfg gm_MenuSplitScreenCfg;
  166. enum SplitScreenCfg gm_StartSplitScreenCfg;
  167. enum SplitScreenCfg gm_CurrentSplitScreenCfg;
  168. // Attributes
  169. CGameTimerHandler m_gthGameTimerHandler;
  170. BOOL gm_bGameOn;
  171. BOOL gm_bMenuOn; // set by serioussam.exe to notify that menu is active
  172. BOOL gm_bFirstLoading; // set by serioussam.exe to notify first loading
  173. BOOL gm_bProfileDemo; // demo profiling required
  174. // network provider itself
  175. CNetworkProvider gm_npNetworkProvider;
  176. // network provider's description
  177. CTString gm_strNetworkProvider;
  178. // controls that are local to each player
  179. SLONG gm_slPlayerControlsSize;
  180. void *gm_pvGlobalPlayerControls;
  181. // index of local player
  182. // (-1) if not active
  183. INDEX gm_aiMenuLocalPlayers[ 4];
  184. INDEX gm_aiStartLocalPlayers[ 4];
  185. // players that are currently playing on local machine (up to 4)
  186. CLocalPlayer gm_lpLocalPlayers[ 4];
  187. // Operations
  188. void InitInternal(void);
  189. void EndInternal(void);
  190. BOOL StartProviderFromName(void);
  191. void SetupLocalPlayers( void);
  192. BOOL AddPlayers(void);
  193. SLONG PackHighScoreTable(void);
  194. void RecordHighScore(void);
  195. void UnpackHighScoreTable(SLONG slSize);
  196. void SaveThumbnail(const CTFileName &fnm);
  197. CTFileName GetQuickSaveName(BOOL bSave);
  198. void GameHandleTimer(void);
  199. virtual void LoadPlayersAndControls(void);
  200. virtual void SavePlayersAndControls(void);
  201. virtual void Load_t( void);
  202. virtual void Save_t( void);
  203. // set properties for a quick start session
  204. virtual void SetQuickStartSession(CSessionProperties &sp);
  205. // set properties for a single player session
  206. virtual void SetSinglePlayerSession(CSessionProperties &sp);
  207. // set properties for a multiplayer session
  208. virtual void SetMultiPlayerSession(CSessionProperties &sp);
  209. // game loop functions
  210. #define GRV_SHOWEXTRAS (1L<<0) // add extra stuff like console, weapon, pause
  211. virtual void GameRedrawView(CDrawPort *pdpDrawport, ULONG ulFlags);
  212. virtual void GameMainLoop(void);
  213. // console functions
  214. virtual void ConsoleKeyDown(MSG msg);
  215. virtual void ConsoleChar(MSG msg);
  216. virtual void ConsoleRender(CDrawPort *pdpDrawport);
  217. virtual void ConsolePrintLastLines(CDrawPort *pdpDrawport);
  218. // computer functions
  219. virtual void ComputerMouseMove(PIX pixX, PIX pixY);
  220. virtual void ComputerKeyDown(MSG msg);
  221. virtual void ComputerRender(CDrawPort *pdpDrawport);
  222. virtual void ComputerForceOff();
  223. // loading hook functions
  224. virtual void EnableLoadingHook(CDrawPort *pdpDrawport);
  225. virtual void DisableLoadingHook(void);
  226. // get default description for a game (for save games/demos)
  227. virtual CTString GetDefaultGameDescription(BOOL bWithInfo);
  228. // game start/end functions
  229. virtual BOOL NewGame(const CTString &strSessionName, const CTFileName &fnWorld,
  230. class CSessionProperties &sp);
  231. virtual BOOL JoinGame(CNetworkSession &session);
  232. virtual BOOL LoadGame(const CTFileName &fnGame);
  233. virtual BOOL SaveGame(const CTFileName &fnGame);
  234. virtual void StopGame(void);
  235. virtual BOOL StartDemoPlay(const CTFileName &fnDemo);
  236. virtual BOOL StartDemoRec(const CTFileName &fnDemo);
  237. virtual void StopDemoRec(void);
  238. virtual INDEX GetPlayersCount(void);
  239. virtual INDEX GetLivePlayersCount(void);
  240. // printout and dump extensive demo profile report
  241. virtual CTString DemoReportFragmentsProfile( INDEX iRate);
  242. virtual CTString DemoReportAnalyzedProfile(void);
  243. // functions called from world editor
  244. virtual void Initialize(const CTFileName &fnGameSettings);
  245. virtual void End(void);
  246. virtual void QuickTest(const CTFileName &fnMapName,
  247. CDrawPort *pdpDrawport, CViewPort *pvpViewport);
  248. // interface rendering functions
  249. virtual void LCDInit(void);
  250. virtual void LCDEnd(void);
  251. virtual void LCDPrepare(FLOAT fFade);
  252. virtual void LCDSetDrawport(CDrawPort *pdp);
  253. virtual void LCDDrawBox(PIX pixUL, PIX pixDR, PIXaabbox2D &box, COLOR col);
  254. virtual void LCDScreenBox(COLOR col);
  255. virtual void LCDScreenBoxOpenLeft(COLOR col);
  256. virtual void LCDScreenBoxOpenRight(COLOR col);
  257. virtual void LCDRenderClouds1(void);
  258. virtual void LCDRenderClouds2(void);
  259. void LCDRenderCloudsForComp(void);
  260. void LCDRenderCompGrid(void);
  261. virtual void LCDRenderGrid(void);
  262. virtual void LCDDrawPointer(PIX pixI, PIX pixJ);
  263. virtual COLOR LCDGetColor(COLOR colDefault, const char *strName);
  264. virtual COLOR LCDFadedColor(COLOR col);
  265. virtual COLOR LCDBlinkingColor(COLOR col0, COLOR col1);
  266. // menu interface functions
  267. virtual void MenuPreRenderMenu(const char *strMenuName);
  268. virtual void MenuPostRenderMenu(const char *strMenuName);
  269. };
  270. #endif