Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Battle::struggle() {
- // TO-DO
- //----------------
- // 14/06/2019 07:55
- int const SAPPHIRE = 1; // index of sapphire jade
- int const EMERALD = 2; // ... emerald jade
- int const AQUAMARINE = 3; // ... aquamarine crystal
- int const D_ARTAGMAN = 0; // index of musketeer
- int const ATHOS = 1;
- int const PORTHOS = 2;
- int const ARAMIS = 3;
- int const QUEZACOLT = 11; // index of the monster
- int const BAHAMIT = 12;
- int const CERBERUS = 21;
- int const IFRIT = 22;
- int const SIREN = 31;
- int const LEVIATHAN = 32;
- for (int i = 0; i < numOfEvents; i++) {
- int currentID = firstMusketeer; // index of the musketeer at present
- bool emptyCrystal = true;
- bool emptySapphire = true; // none has Sapphire
- Musketeer* p = &musketeers[currentID]; // first musketeer
- if (events[i] % 100 == -11 || events[i] % 100 == -12) { // Quezacolt, Bahamut: SAPPHIRE
- int* pCrys = p->getCystalPointer(SAPPHIRE);
- if (pCrys == NULL) {
- for (int j = 0; j < NUM_OF_MUSKETEERS; j++) {
- Musketeer* a = &musketeers[(currentID + j) % NUM_OF_MUSKETEERS]; // Pointing to the next one
- if (a->getCystalPointer(SAPPHIRE) != NULL) // if this one has Sapphire
- emptyCrystal = false;
- } // if none has Crystal (empryCrystal=true), the LOOP will end
- }
- if (emptyCrystal) {
- // Lost HP
- p->setHP(p->getHP() - p->getDam(events[i], currentID));
- // p->setHP = p->getHP - p->getDam(events[i], currentID);
- if (p->getHP() > 0)
- currentID = (currentID + 1) % NUM_OF_MUSKETEERS; // update next one
- else if (p->getHP() < 1) {
- p->setHP(0);
- currentID = (currentID + 1) % NUM_OF_MUSKETEERS; // update next one
- }
- }
- if (currentID == ARAMIS) {
- if (musketeers[ARAMIS].getCystalPointer(SAPPHIRE) != NULL) { // SAPPHIRE exists
- int* temp = musketeers[ARAMIS].getCystalPointer(SAPPHIRE);
- this->manager->deallocate(temp); // lv-- (deallocate this pointer)
- }
- else { // Find the others
- for (int j = 0; j < NUM_OF_MUSKETEERS - 1; j++) { // Find the rest 3 ones
- currentID = (currentID + 1) % NUM_OF_MUSKETEERS;
- if (musketeers[currentID].getCystalPointer(SAPPHIRE) != NULL) {
- this->manager->deallocate(musketeers[currentID].getCystalPointer(SAPPHIRE));
- emptySapphire = false; // SAPPHIRE exists
- }
- else { // if SAPPHIRE doesn't exists
- for (int x = 0; x < NUM_OF_MUSKETEERS; x++) { // traverse the musketeers
- for (int y = 2; y <= NUM_OF_CYSTAL; y++) { // traverse the crystals
- int* jade = musketeers[currentID].getCystalPointer(y);
- int level = *jade;
- // Check the conditional of the Crystal
- if (level > 1 && 10 * level < musketeers[ARAMIS].getHP()) {
- musketeers[currentID].setCystalPointer(SAPPHIRE, jade);
- this->manager->deallocate(musketeers[currentID].getCystalPointer(SAPPHIRE)); // SAAPPHIRE lv--
- musketeers[ARAMIS].setHP(musketeers[ARAMIS].getHP() - 10 * (*jade)); // Update ARAMIS's HP
- musketeers[currentID].setCystalPointer(y, NULL); // delete Crystal(position: y)
- }
- else {
- int damageAramis = p->getDam(events[i], ARAMIS);
- musketeers[ARAMIS].setHP(musketeers[ARAMIS].getHP() - damageAramis);
- }
- }
- currentID = (currentID + 1) % NUM_OF_MUSKETEERS; // point to the next one
- }
- }
- }
- }
- }
- else {
- if (musketeers[currentID].getCystalPointer(SAPPHIRE) != NULL) { // check if this one has SAPPHIRE
- int* jade = musketeers[currentID].getCystalPointer(SAPPHIRE);
- this->manager->deallocate(jade); // if have, lv--
- }
- else { // Find the others
- emptySapphire = true;
- for (int j = 0; j < NUM_OF_MUSKETEERS - 1; j++) {
- currentID = (currentID + 1) % NUM_OF_MUSKETEERS;
- if (musketeers[currentID].getCystalPointer(SAPPHIRE) != NULL) {
- this->manager->deallocate(musketeers[currentID].getCystalPointer(SAPPHIRE));
- emptySapphire = false; // SAPPHIRE exists
- }
- }
- if (emptyCrystal) {
- int dam = p->getDam(events[i], currentID);
- musketeers[currentID].setHP(musketeers[currentID].getHP() - dam);
- }
- }
- }
- }
- // COLLECTING Crystal
- if (events[i] > 0) {
- int index = p->getCrystal(events[i]); // index of Crystal
- int level = p->getX(events[i]); // level of Crystal
- int* jade = musketeers[i].getCystalPointer(index);
- if (jade == NULL)
- for (int j = 0; j < level; j++)
- manager->allocate(jade); // lv++
- else if (*jade < level)
- for (int j = *jade; j < level; j++)
- manager->allocate(jade);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement