patch-Main_cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. $OpenBSD: patch-Main_cpp,v 1.1 2003/04/15 13:17:59 wilfried Exp $
  2. --- Main.cpp.orig Wed Apr 2 10:57:33 2003
  3. +++ Main.cpp Mon Apr 14 11:54:54 2003
  4. @@ -60,6 +60,8 @@ int GunChannel = 1;
  5. Mix_Chunk *pRicochetSound = NULL;
  6. Mix_Chunk *pExplosionSound = NULL;
  7. Mix_Chunk *pDeathSound = NULL;
  8. +bool Sounds = true;
  9. +bool PlaySounds = true;
  10. #endif
  11. list<UnitData> Tanks;
  12. @@ -96,7 +98,7 @@ int main (int argc, char *argv[])
  13. // Check command line
  14. if ( argc > 1 )
  15. {
  16. - for ( int i = 1; i <= argc; i++ )
  17. + for ( int i = 1; i < argc; i++ )
  18. {
  19. // Version
  20. if ( strcmp (argv[i], "-v") == 0 || strcmp (argv[i], "--version") == 0 )
  21. @@ -111,12 +113,25 @@ int main (int argc, char *argv[])
  22. return 0;
  23. }
  24. + #ifdef SOUND
  25. + // Sound
  26. + if ( strcmp (argv[i], "-s") == 0 || strcmp (argv[i], "--no-sound") == 0 )
  27. + {
  28. + cout << "Disabling sounds\n";
  29. + Sounds = false;
  30. + continue;
  31. + }
  32. + #endif
  33. +
  34. // Help
  35. if ( strcmp (argv[i], "--help") == 0 )
  36. {
  37. cout << "Usage: oilwar [OPTION]\n\n";
  38. cout << "Options\n";
  39. cout << " -v, --version Display version information and exit.\n";
  40. + #ifdef SOUND
  41. + cout << " -s, --no-sound Disable sounds\n";
  42. + #endif
  43. cout << " --help Display this help and exit.\n";
  44. cout << "\nData and score file locations\n";
  45. cout << " Data dir: " << DATA_DIR << '\n';
  46. @@ -150,11 +165,15 @@ int main (int argc, char *argv[])
  47. }
  48. #ifdef SOUND
  49. - // Open audio
  50. - if ( Mix_OpenAudio (22050, AUDIO_S16, 2, 4096) )
  51. + if ( Sounds )
  52. {
  53. - cerr << "Unable to open audio: " << Mix_GetError () << endl;
  54. - return 1;
  55. + // Open audio
  56. + if ( Mix_OpenAudio (22050, AUDIO_S16, 2, 4096) )
  57. + {
  58. + cerr << "Unable to open audio: " << Mix_GetError () << endl;
  59. + cout << "Disabling sound\n";
  60. + Sounds = false;
  61. + }
  62. }
  63. #endif
  64. @@ -166,11 +185,14 @@ int main (int argc, char *argv[])
  65. pBitmaps = LoadImage ("bitmaps.png", true);
  66. #ifdef SOUND
  67. - // Load sounds
  68. - pGunSound = LoadSound ("singlegunshot.wav");
  69. - pRicochetSound = LoadSound ("bulletricochet.wav");
  70. - pExplosionSound = LoadSound ("explode.wav");
  71. - pDeathSound = LoadSound ("gasp.wav");
  72. + if ( Sounds )
  73. + {
  74. + // Load sounds
  75. + pGunSound = LoadSound ("singlegunshot.wav");
  76. + pRicochetSound = LoadSound ("bulletricochet.wav");
  77. + pExplosionSound = LoadSound ("explode.wav");
  78. + pDeathSound = LoadSound ("gasp.wav");
  79. + }
  80. #endif
  81. // Load highscores
  82. @@ -214,6 +236,12 @@ int main (int argc, char *argv[])
  83. case SDLK_ESCAPE:
  84. Running = false;
  85. break;
  86. + #ifdef SOUND
  87. + case SDLK_s:
  88. + // Toggle sounds
  89. + PlaySounds = !PlaySounds;
  90. + break;
  91. + #endif
  92. case SDLK_F10:
  93. cout << "Saving screenshot to shot.bmp" << endl;
  94. SDL_SaveBMP (pScreen, "shot.bmp");
  95. @@ -317,6 +345,7 @@ int main (int argc, char *argv[])
  96. Explosion (int (grenade->x + 0.5f), int (grenade->y + 0.5f));
  97. #ifdef SOUND
  98. + if ( Sounds && PlaySounds )
  99. Mix_PlayChannel (-1, pExplosionSound, 0);
  100. #endif
  101. @@ -433,6 +462,7 @@ int main (int argc, char *argv[])
  102. }
  103. #ifdef SOUND
  104. + if ( Sounds && PlaySounds )
  105. Mix_PlayChannel (-1, pExplosionSound, 0);
  106. #endif
  107. }
  108. @@ -658,8 +688,11 @@ void FireGun (Sint16 x, Sint16 y)
  109. #ifdef SOUND
  110. // Sounds
  111. - Mix_PlayChannel (-1, pDeathSound, 0);
  112. - Mix_PlayChannel (GunChannel, pGunSound, 0);
  113. + if ( Sounds && PlaySounds )
  114. + {
  115. + Mix_PlayChannel (-1, pDeathSound, 0);
  116. + Mix_PlayChannel (GunChannel, pGunSound, 0);
  117. + }
  118. #endif
  119. break;
  120. @@ -674,7 +707,8 @@ void FireGun (Sint16 x, Sint16 y)
  121. {
  122. #ifdef SOUND
  123. // Sounds
  124. - Mix_PlayChannel (GunChannel, pGunSound, 0);
  125. + if ( Sounds && PlaySounds )
  126. + Mix_PlayChannel (GunChannel, pGunSound, 0);
  127. #endif
  128. tank->hits++;
  129. @@ -692,13 +726,14 @@ void FireGun (Sint16 x, Sint16 y)
  130. #ifdef SOUND
  131. // Sounds
  132. - Mix_PlayChannel (-1, pExplosionSound, 0);
  133. + if ( Sounds && PlaySounds )
  134. + Mix_PlayChannel (-1, pExplosionSound, 0);
  135. #endif
  136. break;
  137. }
  138. #ifdef SOUND
  139. - else
  140. + else if ( Sounds && PlaySounds )
  141. Mix_PlayChannel (-1, pRicochetSound, 0);
  142. #endif
  143. }
  144. @@ -713,7 +748,8 @@ void FireGun (Sint16 x, Sint16 y)
  145. #ifdef SOUND
  146. // Sounds
  147. - Mix_PlayChannel (GunChannel, pGunSound, 0);
  148. + if ( Sounds && PlaySounds )
  149. + Mix_PlayChannel (GunChannel, pGunSound, 0);
  150. #endif
  151. }
  152. }