iphone_start.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. Copyright (C) 2009 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "../doomiphone.h"
  17. /*
  18. ==================
  19. ResumeGame
  20. ==================
  21. */
  22. void ResumeGame() {
  23. if ( levelHasBeenLoaded && !demoplayback ) {
  24. // return to the already started game
  25. iphoneResumeMusic();
  26. drawWeaponSelect = false;
  27. weaponSelected = -1;
  28. automapmode = 0;
  29. advancedemo = false;
  30. menuState = IPM_GAME;
  31. lastState = IPM_GAME;
  32. return;
  33. }
  34. if ( !playState.saveGameIsValid || !G_SaveGameValid() ) {
  35. // they hit "resume game" on the first app lounch, so just start E1M1
  36. mapStart_t map;
  37. map.skill = 1;
  38. map.episode = 1;
  39. map.map = 1;
  40. StartSinglePlayerGame( map );
  41. lastState = IPM_GAME;
  42. } else {
  43. StartSaveGame();
  44. lastState = IPM_GAME;
  45. }
  46. }
  47. /*
  48. ==================
  49. GameSetup
  50. ==================
  51. */
  52. void GameSetup() {
  53. // resume game just goes back to playing, it doesn't load anything
  54. levelHasBeenLoaded = true;
  55. // make sure doom doesn't cycle to the next demo loop and kill the new game
  56. advancedemo = false;
  57. // not in a timedemo yet
  58. timeDemoStart = 0;
  59. iphoneTimeDemo = false;
  60. // display the game next time through the main loop
  61. drawWeaponSelect = false;
  62. weaponSelected = -1;
  63. automapmode = 0;
  64. menuState = IPM_GAME;
  65. demoplayback = false;
  66. levelTimer = false;
  67. levelFragLimit = false;
  68. // single player game
  69. netgame = false;
  70. deathmatch = false;
  71. nomonsters = false;
  72. memset( playeringame, 0, sizeof( playeringame ) );
  73. consoleplayer = 0;
  74. displayplayer = 0;
  75. playeringame[consoleplayer] = 1;
  76. }
  77. /*
  78. =======================
  79. StartSaveGame
  80. Can be called by both the resume game button after launch, or the
  81. load game button after a player death
  82. =======================
  83. */
  84. void StartSaveGame() {
  85. GameSetup();
  86. G_LoadGame( 0, true );
  87. G_DoLoadGame();
  88. }
  89. /*
  90. =======================
  91. StartSinglePlayerGame
  92. =======================
  93. */
  94. void StartSinglePlayerGame( mapStart_t map ) {
  95. playState.map = map;
  96. playState.saveGameIsValid = true; // assume we will save the game on exit
  97. lastState = IPM_GAME;
  98. // mark this level / skill combination as tried
  99. //
  100. mapStats_t *cms = FindMapStats( playState.map.dataset, playState.map.episode, playState.map.map, true );
  101. if ( cms ) {
  102. // if we are at MAX_MAPS, no stat tracking...
  103. cms->completionFlags[playState.map.skill] |= MF_TRIED;
  104. }
  105. GameSetup();
  106. // start the map
  107. G_InitNew( playState.map.skill, playState.map.episode, playState.map.map );
  108. }
  109. /*
  110. =======================
  111. StartNetGame
  112. Begins a game based on the contents of setupPacket
  113. =======================
  114. */
  115. boolean StartNetGame() {
  116. // make sure we are supposed to be in this game
  117. int slot = -1;
  118. for ( int i = 0 ; i < MAXPLAYERS ; i++ ) {
  119. if ( setupPacket.playerID[i] == playerID ) {
  120. slot = i;
  121. }
  122. }
  123. if ( slot == -1 ) {
  124. return false;
  125. }
  126. GameSetup();
  127. consoleplayer = displayplayer = slot;
  128. netgame = true; // respawn without restarting levels
  129. if ( setupPacket.deathmatch ) {
  130. // deathmatch game
  131. deathmatch = setupPacket.deathmatch; // could be either 1 or 2 for altdeath
  132. nomonsters = true;
  133. if ( setupPacket.timelimit > 0 ) {
  134. levelTimer = true;
  135. // 30 hz, minutes
  136. levelTimeCount = setupPacket.timelimit * 30 * 60;
  137. }
  138. if ( setupPacket.fraglimit > 0 ) {
  139. levelFragLimit = true;
  140. levelFragLimitCount = setupPacket.fraglimit;
  141. }
  142. } else {
  143. // coop game
  144. deathmatch = false;
  145. nomonsters = false;
  146. }
  147. for ( int i = 0 ; i < MAXPLAYERS ; i++ ) {
  148. if ( setupPacket.playerID[i] != 0 ) {
  149. playeringame[i] = 1;
  150. } else {
  151. playeringame[i] = 0;
  152. }
  153. }
  154. gametic = 0;
  155. maketic = 1; // allow everyone to run the first frame without waiting for a packet
  156. memset( netcmds, 0, sizeof( netcmds ) );
  157. memset( consistancy, 0, sizeof( consistancy ) );
  158. gameID = setupPacket.gameID;
  159. // start the map
  160. G_InitNew( setupPacket.map.skill, setupPacket.map.episode, setupPacket.map.map );
  161. return true;
  162. }
  163. /*
  164. =======================
  165. StartDemoGame
  166. The demo button has been hit on the main menu
  167. =======================
  168. */
  169. void StartDemoGame( boolean timeDemoMode ) {
  170. if ( levelHasBeenLoaded && !netgame && !demoplayback && usergame && gamestate == GS_LEVEL ) {
  171. // save the current game before starting the demos
  172. levelHasBeenLoaded = false;
  173. G_SaveGame( 0, "quicksave" );
  174. G_DoSaveGame(true);
  175. }
  176. lastState = IPM_GAME;
  177. GameSetup();
  178. if ( timeDemoMode ) {
  179. iphoneTimeDemo = true;
  180. }
  181. // always skip to the next one on each exit from the menu
  182. advancedemo = true;
  183. }