Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. void Battle::struggle() {
  2. // TO-DO
  3. //----------------
  4. // 14/06/2019 07:55
  5.  
  6. int const SAPPHIRE = 1; // index of sapphire jade
  7. int const EMERALD = 2; // ... emerald jade
  8. int const AQUAMARINE = 3; // ... aquamarine crystal
  9.  
  10. int const D_ARTAGMAN = 0; // index of musketeer
  11. int const ATHOS = 1;
  12. int const PORTHOS = 2;
  13. int const ARAMIS = 3;
  14.  
  15. int const QUEZACOLT = 11; // index of the monster
  16. int const BAHAMIT = 12;
  17. int const CERBERUS = 21;
  18. int const IFRIT = 22;
  19. int const SIREN = 31;
  20. int const LEVIATHAN = 32;
  21.  
  22. for (int i = 0; i < numOfEvents; i++) {
  23.  
  24. int currentID = firstMusketeer; // index of the musketeer at present
  25. bool emptyCrystal = true;
  26. bool emptySapphire = true; // none has Sapphire
  27. Musketeer* p = &musketeers[currentID]; // first musketeer
  28. if (events[i] % 100 == -11 || events[i] % 100 == -12) { // Quezacolt, Bahamut: SAPPHIRE
  29. int* pCrys = p->getCystalPointer(SAPPHIRE);
  30. if (pCrys == NULL) {
  31. for (int j = 0; j < NUM_OF_MUSKETEERS; j++) {
  32. Musketeer* a = &musketeers[(currentID + j) % NUM_OF_MUSKETEERS]; // Pointing to the next one
  33. if (a->getCystalPointer(SAPPHIRE) != NULL) // if this one has Sapphire
  34. emptyCrystal = false;
  35. } // if none has Crystal (empryCrystal=true), the LOOP will end
  36. }
  37. if (emptyCrystal) {
  38. // Lost HP
  39. p->setHP(p->getHP() - p->getDam(events[i], currentID));
  40. // p->setHP = p->getHP - p->getDam(events[i], currentID);
  41.  
  42. if (p->getHP() > 0)
  43. currentID = (currentID + 1) % NUM_OF_MUSKETEERS; // update next one
  44. else if (p->getHP() < 1) {
  45. p->setHP(0);
  46. currentID = (currentID + 1) % NUM_OF_MUSKETEERS; // update next one
  47. }
  48. }
  49. if (currentID == ARAMIS) {
  50. if (musketeers[ARAMIS].getCystalPointer(SAPPHIRE) != NULL) { // SAPPHIRE exists
  51. int* temp = musketeers[ARAMIS].getCystalPointer(SAPPHIRE);
  52. this->manager->deallocate(temp); // lv-- (deallocate this pointer)
  53. }
  54. else { // Find the others
  55. for (int j = 0; j < NUM_OF_MUSKETEERS - 1; j++) { // Find the rest 3 ones
  56. currentID = (currentID + 1) % NUM_OF_MUSKETEERS;
  57. if (musketeers[currentID].getCystalPointer(SAPPHIRE) != NULL) {
  58. this->manager->deallocate(musketeers[currentID].getCystalPointer(SAPPHIRE));
  59. emptySapphire = false; // SAPPHIRE exists
  60. }
  61. else { // if SAPPHIRE doesn't exists
  62. for (int x = 0; x < NUM_OF_MUSKETEERS; x++) { // traverse the musketeers
  63. for (int y = 2; y <= NUM_OF_CYSTAL; y++) { // traverse the crystals
  64. int* jade = musketeers[currentID].getCystalPointer(y);
  65. int level = *jade;
  66. // Check the conditional of the Crystal
  67. if (level > 1 && 10 * level < musketeers[ARAMIS].getHP()) {
  68. musketeers[currentID].setCystalPointer(SAPPHIRE, jade);
  69. this->manager->deallocate(musketeers[currentID].getCystalPointer(SAPPHIRE)); // SAAPPHIRE lv--
  70. musketeers[ARAMIS].setHP(musketeers[ARAMIS].getHP() - 10 * (*jade)); // Update ARAMIS's HP
  71. musketeers[currentID].setCystalPointer(y, NULL); // delete Crystal(position: y)
  72. }
  73. else {
  74. int damageAramis = p->getDam(events[i], ARAMIS);
  75. musketeers[ARAMIS].setHP(musketeers[ARAMIS].getHP() - damageAramis);
  76. }
  77. }
  78. currentID = (currentID + 1) % NUM_OF_MUSKETEERS; // point to the next one
  79. }
  80.  
  81. }
  82. }
  83. }
  84. }
  85. else {
  86. if (musketeers[currentID].getCystalPointer(SAPPHIRE) != NULL) { // check if this one has SAPPHIRE
  87. int* jade = musketeers[currentID].getCystalPointer(SAPPHIRE);
  88. this->manager->deallocate(jade); // if have, lv--
  89. }
  90. else { // Find the others
  91. emptySapphire = true;
  92. for (int j = 0; j < NUM_OF_MUSKETEERS - 1; j++) {
  93. currentID = (currentID + 1) % NUM_OF_MUSKETEERS;
  94. if (musketeers[currentID].getCystalPointer(SAPPHIRE) != NULL) {
  95. this->manager->deallocate(musketeers[currentID].getCystalPointer(SAPPHIRE));
  96. emptySapphire = false; // SAPPHIRE exists
  97. }
  98. }
  99. if (emptyCrystal) {
  100. int dam = p->getDam(events[i], currentID);
  101. musketeers[currentID].setHP(musketeers[currentID].getHP() - dam);
  102. }
  103. }
  104. }
  105. }
  106.  
  107. // COLLECTING Crystal
  108. if (events[i] > 0) {
  109. int index = p->getCrystal(events[i]); // index of Crystal
  110. int level = p->getX(events[i]); // level of Crystal
  111. int* jade = musketeers[i].getCystalPointer(index);
  112. if (jade == NULL)
  113. for (int j = 0; j < level; j++)
  114. manager->allocate(jade); // lv++
  115. else if (*jade < level)
  116. for (int j = *jade; j < level; j++)
  117. manager->allocate(jade);
  118. }
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement