Score.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "Score.h"
  2. using namespace std;
  3. Score::Score()
  4. :m_name("Unloaded"), m_cpuLoad( 40 ), m_winNumber( 0 ), m_hasShield( false )
  5. {
  6. m_hasWeapon[ GUN_ID ] = true;
  7. for ( unsigned int i(2); i < SHOT_NB; i ++ )
  8. {
  9. m_hasWeapon[i] = false;
  10. }
  11. }
  12. Score::~Score()
  13. {
  14. //dtor
  15. }
  16. void Score::load( std::string name )
  17. {
  18. // Chemin
  19. m_name = name;
  20. string chemin("Resources/Saves/" + name + ".txt");
  21. // Flux
  22. ifstream loadStream( chemin.c_str() );
  23. // Lecture
  24. loadStream >> m_cpuLoad;
  25. loadStream >> m_winNumber;
  26. loadStream >> m_hasShield;
  27. for ( unsigned int i(1); i < SHOT_NB; i ++ )
  28. loadStream >> m_hasWeapon[i];
  29. }
  30. void Score::save()
  31. {
  32. // Chemin
  33. string chemin("Resources/Saves/" + m_name + ".txt");
  34. // Flux
  35. ofstream writeStream( chemin.c_str() );
  36. // Ecriture
  37. writeStream << m_cpuLoad << endl;
  38. writeStream << m_winNumber << endl;
  39. writeStream << m_hasShield << endl;
  40. for ( unsigned int i(1); i < SHOT_NB; i ++ )
  41. writeStream << m_hasWeapon[i] << endl;
  42. }
  43. std::string Score::getName()
  44. {
  45. return m_name;
  46. }
  47. Uint32 Score::getCpuLoad()
  48. {
  49. return m_cpuLoad;
  50. }
  51. Uint32 Score::getWinNumber()
  52. {
  53. return m_winNumber;
  54. }
  55. bool Score::hasShield()
  56. {
  57. return m_hasShield;
  58. }
  59. bool Score::hasWeapon( int weapId )
  60. {
  61. if ( weapId < SHOT_NB )
  62. return m_hasWeapon[ weapId ];
  63. else
  64. return false;
  65. }
  66. void Score::addVictory()
  67. {
  68. m_winNumber ++;
  69. }
  70. void Score::giveLoot( std::string planet )
  71. {
  72. // Arme en récompense
  73. if ( planet == "Alderande" )
  74. {
  75. m_hasWeapon[ DISPER_ID ] = true;
  76. return;
  77. }
  78. if ( planet == "Faiz" )
  79. {
  80. m_hasWeapon[ CUTTER_ID ] = true;
  81. return;
  82. }
  83. if ( planet == "Kratarite" )
  84. {
  85. m_hasWeapon[ PHOTO_ID ] = true;
  86. return;
  87. }
  88. if ( planet == "DistantSite2016_UK" )
  89. {
  90. m_hasWeapon[ BREXIT_ID ] = true;
  91. return;
  92. }
  93. if ( planet == "Telurande" )
  94. {
  95. m_hasWeapon[ HECTO_ID ] = true;
  96. return;
  97. }
  98. // Bouclier de combat en recompense
  99. if ( planet == "Titan" )
  100. {
  101. m_hasShield = true;
  102. return;
  103. }
  104. // Sniper
  105. if ( planet == "DistantSite2018_FR" )
  106. {
  107. m_hasWeapon[ SNIPER_ID ] = true;
  108. return;
  109. }
  110. // Sniper
  111. if ( planet == "Chateaubriande" )
  112. {
  113. m_hasWeapon[ MISSILE_ID ] = true;
  114. return;
  115. }
  116. // Majoration du CPU
  117. if ( planet == "BlueMoon" && m_cpuLoad < 100 )
  118. {
  119. m_cpuLoad = 100;
  120. return;
  121. }
  122. if ( planet == "KeplerSite429_M75" && m_cpuLoad < 200 )
  123. {
  124. m_cpuLoad = 200;
  125. return;
  126. }
  127. if ( planet == "Genii" && m_cpuLoad < 300 )
  128. {
  129. m_cpuLoad = 300;
  130. return;
  131. }
  132. }