diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index acb28f401..ca7b73302 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -804,7 +804,6 @@ public: { if(!source->isInPlay()) return 0; - // TODO: C6246: Clarify e, is this independant of the "e" declared outside this scope? WEvent * e = NEW WEventVampire(victems[w],victems[w],source); game->receiveEvent(e); victems[w] = NULL; @@ -4705,7 +4704,6 @@ public: { if (value_before_modification) { - // TODO: C6246: Clarify _target, is this independant of the "_target" declared as the member var of this class? Damageable * _target = (Damageable *) target; game->mLayers->stackLayer()->addDamage(source, _target, 2); } diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index c0115e29e..d51107c1c 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -156,11 +156,11 @@ bool AIPlayer::tapLandsForMana(ManaCost * cost, MTGCardInstance * target) { used[card] = true; int doUse = 1; - for (int colorsIdx = Constants::MTG_NB_COLORS - 1; colorsIdx >= 0; colorsIdx--) + for (int i = Constants::MTG_NB_COLORS - 1; i >= 0; i--) { - if (diff->getCost(colorsIdx) && amp->output->getCost(colorsIdx)) + if (diff->getCost(i) && amp->output->getCost(i)) { - diff->remove(colorsIdx, 1); + diff->remove(i, 1); doUse = 0; break; } @@ -513,8 +513,7 @@ int AIAction::getEfficiency() case MTGAbility::MANA_PRODUCER://only way to hit this condition is nested manaabilities, ai skips manaproducers by defualt when finding an ability to use. { MTGCardInstance * _target = (MTGCardInstance *) (a->target); - // TODO: C6246: Clarify a, is this independant of the "a" declared outside this scope? - MTGAbility * a = AbilityFactory::getCoreAbility(ability); + MTGAbility * a = AbilityFactory::getCoreAbility(ability); efficiency = 0; //trying to encourage Ai to use his foreach manaproducers in first main diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index ba08f82a2..cbc94f9f7 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -604,9 +604,9 @@ void GameObserver::gameStateBasedEffects() for(int w = 0;w < z->nb_cards;w++) { int colored = 0; - for (int colorIdx = Constants::MTG_COLOR_GREEN; colorIdx <= Constants::MTG_COLOR_WHITE; ++colorIdx) + for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; ++i) { - if (z->cards[w]->hasColor(colorIdx)) + if (z->cards[w]->hasColor(i)) ++colored; } if(colored > 1) @@ -770,8 +770,7 @@ void GameObserver::Affinity() { reduce = card->controller()->game->battlefield->countByType(type.c_str()); } - - for(int reductionIdx = 0; reductionIdx < reduce; reductionIdx++) + for(int i = 0; i < reduce;i++) { if(card->getManaCost()->getCost(color) > 0) card->getManaCost()->remove(color,1); diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index bcc66ae83..b7d751b19 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -972,10 +972,9 @@ bool GameOptionAward::read(string input) int i; for (i = 0; i < 5; i++) tvals[i] = 0; - i = 0; string buf; - for (size_t t = 0; t < input.size(); t++) + for (size_t t = 0, i = 0; t < input.size(); t++) { if (!isdigit(input[t])) { diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 078802648..d7909b320 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -1512,7 +1512,7 @@ int GameStateDeckViewer::loadDeck(int deckid) { MTGCard * current = myDeck->getCard(i, true); int howmanyinDeck = myDeck->count(current); - for (int numCardsInCollection = myCollection->count(current); numCardsInCollection < howmanyinDeck; numCardsInCollection++) + for (int i = myCollection->count(current); i < howmanyinDeck; i++) { bPure = false; if (cheatmode) diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 220e1ae16..db180061b 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -561,6 +561,7 @@ void GameStateDuel::Render() { case DUEL_STATE_END: { + JRenderer * r = JRenderer::GetInstance(); r->FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(200,0,0,0)); credits->Render(); #ifdef TESTSUITE diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index a6c69ac87..3b16b10e4 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -292,11 +292,11 @@ int GameStateMenu::nextDirectory(const char * root, const char * file) while (!found && (mDit = readdir(mDip))) { sprintf(mCurrentSetFileName, "%s/%s/%s", root, mDit->d_name, file); - wagic::ifstream setFile(mCurrentSetFileName); - if (setFile) + wagic::ifstream file(mCurrentSetFileName); + if (file) { sprintf(mCurrentSetName, "%s", mDit->d_name); - setFile.close(); + file.close(); found = 1; } } diff --git a/projects/mtg/src/GuiCombat.cpp b/projects/mtg/src/GuiCombat.cpp index 48fa355f5..6c2de46e7 100644 --- a/projects/mtg/src/GuiCombat.cpp +++ b/projects/mtg/src/GuiCombat.cpp @@ -459,7 +459,6 @@ int GuiCombat::receiveEventPlus(WEvent* e) attackers.push_back(t); return 1; } - // TODO: C6246: Clarify event, which event are you referring to? else if (WEventCreatureBlocker* event = dynamic_cast(e)) { for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it) @@ -478,7 +477,6 @@ int GuiCombat::receiveEventPlus(WEvent* e) } return 0; } - // TODO: C6246: Clarify event, which event are you referring to? else if (WEventCreatureBlockerRank* event = dynamic_cast(e)) { for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it) @@ -545,7 +543,6 @@ int GuiCombat::receiveEventMinus(WEvent* e) } return 0; } - // TODO: C6246: Clarify event, which event are you referring to? else if (WEventCreatureBlocker* event = dynamic_cast(e)) { for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it) @@ -560,7 +557,6 @@ int GuiCombat::receiveEventMinus(WEvent* e) } return 0; } - // TODO: C6246: Clarify event->to->id, which event are you referring to? else if (WEventPhaseChange* event = dynamic_cast(e)) { if (Constants::MTG_PHASE_COMBATDAMAGE == event->to->id) @@ -568,7 +564,6 @@ int GuiCombat::receiveEventMinus(WEvent* e) else cursor_pos = NONE; } - // TODO: C6246: Clarify event->step, which event are you referring to? else if (WEventCombatStepChange* event = dynamic_cast(e)) switch (event->step) { diff --git a/projects/mtg/src/GuiPlay.cpp b/projects/mtg/src/GuiPlay.cpp index 18ba3f2c4..fec6b0d60 100644 --- a/projects/mtg/src/GuiPlay.cpp +++ b/projects/mtg/src/GuiPlay.cpp @@ -356,7 +356,6 @@ int GuiPlay::receiveEventPlus(WEvent * e) return 1; } } - // TODO: C6246: Clarify event, which event are you referring to? else if (WEventCreatureAttacker* event = dynamic_cast(e)) { if (NULL != event->after) @@ -369,7 +368,6 @@ int GuiPlay::receiveEventPlus(WEvent * e) { Replace(); } - // TODO: C6246: Clarify event, which event are you referring to? else if (WEventCardTap* event = dynamic_cast(e)) { if (CardView* cv = dynamic_cast(event->card->view)) @@ -385,7 +383,6 @@ int GuiPlay::receiveEventPlus(WEvent * e) } return 1; } - // TODO: C6246: Clarify event, which event are you referring to? else if (WEventPhaseChange *event = dynamic_cast(e)) { if (Constants::MTG_PHASE_COMBATEND == event->to->id) diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index e60680500..9871ff2f2 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1618,11 +1618,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG size_t end = s.find("]", start); string s1 = s.substr(start + 1, end - start - 1); int phase = Constants::MTG_PHASE_UPKEEP; - for (int phaseIdx = 0; phaseIdx < Constants::NB_MTG_PHASES; phaseIdx++) + for (int i = 0; i < Constants::NB_MTG_PHASES; i++) { - if (s1.find(Constants::MTGPhaseCodeNames[phaseIdx]) != string::npos) + if (s1.find(Constants::MTGPhaseCodeNames[i]) != string::npos) { - phase = phaseIdx; + phase = i; } } bool opponentturn = true,myturn = true; @@ -1685,13 +1685,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG int once = 0; if (seperator != string::npos) { - for (int phaseIdx = 0; phaseIdx < Constants::NB_MTG_PHASES; phaseIdx++) + for (int i = 0; i < Constants::NB_MTG_PHASES; i++) { if (s1.find("next") != string::npos) once = 1; - if (s1.find(Constants::MTGPhaseCodeNames[phaseIdx]) != string::npos) + if (s1.find(Constants::MTGPhaseCodeNames[i]) != string::npos) { - phase = phaseIdx; + phase = i; } } s1 = s1.substr(0, seperator - 1); @@ -2297,12 +2297,12 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } //Cast/Play Restrictions - for (size_t castPlayIdx = 0; castPlayIdx < kMaxCastKeywordsCount; ++castPlayIdx) + for (size_t i = 0; i < kMaxCastKeywordsCount; ++i) { - found = s.find(kMaxCastKeywords[castPlayIdx]); + found = s.find(kMaxCastKeywords[i]); if (found != string::npos) { - size_t header = kMaxCastKeywords[castPlayIdx].size(); + size_t header = kMaxCastKeywords[i].size(); size_t end = s.find(")"); string targetsString = s.substr(found + header, end - found - header); TargetChooserFactory tcf; @@ -2329,7 +2329,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { return NEW AInstantCastRestrictionUEOT(id, card, t, castTargets, value, modifyExisting, kMaxCastZones[i], who); } - return NEW ACastRestriction(id, card, t, castTargets, value, modifyExisting, kMaxCastZones[castPlayIdx], who); + return NEW ACastRestriction(id, card, t, castTargets, value, modifyExisting, kMaxCastZones[i], who); //TODO NEW ACastRestrictionUntilEndOfTurn(id, card, t, value, modifyExisting, kMaxCastZones[i], who); } } @@ -2578,11 +2578,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { size_t real_end = transformsParamsString.find("))", found); size_t end = transformsParamsString.find(",", found); - if (end == string::npos) end = real_end; - - stypesStartIndex = found + 12; + size_t stypesStartIndex = found + 12; extraTransforms.append(transformsParamsString.substr(stypesStartIndex, real_end - stypesStartIndex).c_str()); transformsParamsString.erase(stypesStartIndex, real_end - stypesStartIndex); } @@ -2599,13 +2597,14 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG vector newAbilitiesList; storedString.erase(); storedString.append(extraTransforms); - extraTransforms.erase(); - + extraTransforms.erase(); + for (unsigned int i = 0 ; i < abilities.size() ; i++) + { + if(abilities[i].empty()) + abilities.erase(abilities.begin()+i); + } for(unsigned int j = 0;j < abilities.size();j++) { - if (abilities[j].empty()) - continue; - if(abilities[j].find("setpower=") != string::npos) { newpowerfound = true; @@ -3206,10 +3205,8 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int if (dryMode) { result = abilityEfficiency(a, card->controller(), mode, tc); - - for (vector::iterator it = v.begin(); it != v.end(); ++it ) - SAFE_DELETE(*it); - + for (size_t i = 0; i < v.size(); ++i) + SAFE_DELETE(v[i]); return result; } @@ -3491,7 +3488,6 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) MTGInPlay * inplay = game->players[i]->game->inPlay; for (int j = inplay->nb_cards - 1; j >= 0; j--) { - // TODO: C6246: Clarify card, is this independant of the "card" declared outside this scope? MTGCardInstance * card = inplay->cards[j]; if (card->owner == player && card->hasType(Subtypes::TYPE_ARTIFACT)) { @@ -3648,14 +3644,14 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) case 3410: //Seed of Innocence { GameObserver * game = GameObserver::GetInstance(); - for (int playerIdx = 0; playerIdx < 2; playerIdx++) + for (int i = 0; i < 2; i++) { - for (int j = 0; j < game->players[playerIdx]->game->inPlay->nb_cards; j++) + for (int j = 0; j < game->players[i]->game->inPlay->nb_cards; j++) { - MTGCardInstance * current = game->players[playerIdx]->game->inPlay->cards[j]; + MTGCardInstance * current = game->players[i]->game->inPlay->cards[j]; if (current->hasType("Artifact")) { - game->players[playerIdx]->game->putInGraveyard(current); + game->players[i]->game->putInGraveyard(current); current->controller()->gainLife(current->getManaCost()->getConvertedCost()); } } @@ -3812,6 +3808,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) if (card->hasType(Subtypes::TYPE_INSTANT) || card->hasType(Subtypes::TYPE_SORCERY)) { + MTGPlayerCards * zones = card->controller()->game; if (card->alternateCostPaid[ManaCost::MANA_PAID_WITH_BUYBACK] > 0) { zones->putInZone(card, zones->stack, zones->hand); diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 07477f3ef..54ecfc893 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -426,10 +426,10 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card) if (card->has(Constants::STORM)) { int storm = player->game->stack->seenThisTurn("*", Constants::CAST_ALL) + player->opponent()->game->stack->seenThisTurn("*", Constants::CAST_ALL); - ManaCost * stormSpellCost = player->getManaPool(); + ManaCost * spellCost = player->getManaPool(); for (int i = storm; i > 1; i--) { - spell = game->mLayers->stackLayer()->addSpell(copy, NULL, stormSpellCost, payResult, 1); + spell = game->mLayers->stackLayer()->addSpell(copy, NULL, spellCost, payResult, 1); } }//end of storm diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index f6721382b..b001126fb 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -140,14 +140,15 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan manaCost->addExtraCost(NEW MillCost(tc)); break; case 'n': //return unblocked attacker cost + TargetChooserFactory tcf; tc = tcf.createTargetChooser("creature|myBattlefield", c); manaCost->addExtraCost(NEW Ninja(tc)); break; case 'p' : { SAFE_DELETE(tc); - start = value.find("("); - end = value.rfind(")"); + size_t start = value.find("("); + size_t end = value.rfind(")"); string manaType = value.substr(start + 1, end - start - 1); manaCost->addExtraCost(NEW LifeorManaCost(NULL,manaType)); break; @@ -171,15 +172,15 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan separator2 = value.find(",", separator + 1); } SAFE_DELETE(tc); - size_t targetIndexStart = string::npos; + size_t target_start = string::npos; if (separator2 != string::npos) { - targetIndexStart = value.find(",", separator2 + 1); + target_start = value.find(",", separator2 + 1); } - size_t targetIndexEnd = counter_end; - if (targetIndexStart != string::npos && targetIndexEnd != string::npos) + size_t target_end = counter_end; + if (target_start != string::npos && target_end != string::npos) { - string target = value.substr(targetIndexStart + 1, targetIndexEnd - 1 - targetIndexStart); + string target = value.substr(target_start + 1, target_end - 1 - target_start); tc = tcf.createTargetChooser(target, c); } manaCost->addExtraCost(NEW CounterCost(counter, tc)); @@ -194,7 +195,6 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan { for (int i = 0; i < 2; i++) { - // TODO: C6246: Clarify c, is this independant of the "c" declared outside this scope? char c = value[i]; if (c >= '0' && c <= '9') { @@ -215,13 +215,13 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan } if (values[0] > 0 || values[1] > 0) manaCost->addHybrid(colors[0], values[0], colors[1], values[1]); - } - else - { - manaCost->add(Constants::MTG_COLOR_ARTIFACT, intvalue); - } - break; } + else + { + manaCost->add(Constants::MTG_COLOR_ARTIFACT, intvalue); + } + break; + } } } s = s.substr(end + 1); diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index ccd791d63..286fd22df 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -484,7 +484,6 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta else if (attribute.find("share!") != string::npos) { size_t start = attribute.find("share!"); - // TODO: C6246: Clarify end, is this independant of the "end" declared outside this scope? size_t end = attribute.rfind("!"); string CDtype = attribute.substr(start + 6,end - start); if( card && card->isSpell() && card->backupTargets[0]->typeAsTarget() == TARGET_STACKACTION) @@ -547,7 +546,6 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta else { size_t start = attribute.find("{"); - // TODO: C6246: Clarify end, is this independant of the "end" declared outside this scope? size_t end = attribute.find("}"); string counterString = attribute.substr(start + 1, end - start - 1); AbilityFactory abf;