Flagged numerous peices of code that have local variables that are masking either member variables or variables scoped outside the current scope.

I've marked all the ones I found with the following TODO comment:

TODO: C6246: <blah blah>

a few in particular are the ones related to "oneShot" and "_target".  These are local variables that are declared that
mask either a method parameter or a member variable.
This commit is contained in:
techdragon.nguyen@gmail.com
2011-04-21 10:04:32 +00:00
parent 8ed84aa97d
commit 8bf983e2e5
13 changed files with 70 additions and 53 deletions

View File

@@ -804,6 +804,7 @@ 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;
@@ -4704,6 +4705,7 @@ 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);
}

View File

@@ -156,11 +156,11 @@ bool AIPlayer::tapLandsForMana(ManaCost * cost, MTGCardInstance * target)
{
used[card] = true;
int doUse = 1;
for (int i = Constants::MTG_NB_COLORS - 1; i >= 0; i--)
for (int colorsIdx = Constants::MTG_NB_COLORS - 1; colorsIdx >= 0; colorsIdx--)
{
if (diff->getCost(i) && amp->output->getCost(i))
if (diff->getCost(colorsIdx) && amp->output->getCost(colorsIdx))
{
diff->remove(i, 1);
diff->remove(colorsIdx, 1);
doUse = 0;
break;
}
@@ -513,7 +513,8 @@ 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);
MTGAbility * a = AbilityFactory::getCoreAbility(ability);
// TODO: C6246: Clarify a, is this independant of the "a" declared outside this scope?
MTGAbility * a = AbilityFactory::getCoreAbility(ability);
efficiency = 0;
//trying to encourage Ai to use his foreach manaproducers in first main

View File

@@ -604,9 +604,9 @@ void GameObserver::gameStateBasedEffects()
for(int w = 0;w < z->nb_cards;w++)
{
int colored = 0;
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; ++i)
for (int colorIdx = Constants::MTG_COLOR_GREEN; colorIdx <= Constants::MTG_COLOR_WHITE; ++colorIdx)
{
if (z->cards[w]->hasColor(i))
if (z->cards[w]->hasColor(colorIdx))
++colored;
}
if(colored > 1)
@@ -770,7 +770,8 @@ void GameObserver::Affinity()
{
reduce = card->controller()->game->battlefield->countByType(type.c_str());
}
for(int i = 0; i < reduce;i++)
for(int reductionIdx = 0; reductionIdx < reduce; reductionIdx++)
{
if(card->getManaCost()->getCost(color) > 0)
card->getManaCost()->remove(color,1);

View File

@@ -972,9 +972,10 @@ 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, i = 0; t < input.size(); t++)
for (size_t t = 0; t < input.size(); t++)
{
if (!isdigit(input[t]))
{

View File

@@ -1512,7 +1512,7 @@ int GameStateDeckViewer::loadDeck(int deckid)
{
MTGCard * current = myDeck->getCard(i, true);
int howmanyinDeck = myDeck->count(current);
for (int i = myCollection->count(current); i < howmanyinDeck; i++)
for (int numCardsInCollection = myCollection->count(current); numCardsInCollection < howmanyinDeck; numCardsInCollection++)
{
bPure = false;
if (cheatmode)

View File

@@ -561,7 +561,6 @@ 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

View File

@@ -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 file(mCurrentSetFileName);
if (file)
wagic::ifstream setFile(mCurrentSetFileName);
if (setFile)
{
sprintf(mCurrentSetName, "%s", mDit->d_name);
file.close();
setFile.close();
found = 1;
}
}

View File

@@ -459,6 +459,7 @@ 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<WEventCreatureBlocker*>(e))
{
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
@@ -477,6 +478,7 @@ int GuiCombat::receiveEventPlus(WEvent* e)
}
return 0;
}
// TODO: C6246: Clarify event, which event are you referring to?
else if (WEventCreatureBlockerRank* event = dynamic_cast<WEventCreatureBlockerRank*>(e))
{
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
@@ -543,6 +545,7 @@ int GuiCombat::receiveEventMinus(WEvent* e)
}
return 0;
}
// TODO: C6246: Clarify event, which event are you referring to?
else if (WEventCreatureBlocker* event = dynamic_cast<WEventCreatureBlocker*>(e))
{
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
@@ -557,6 +560,7 @@ 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<WEventPhaseChange*>(e))
{
if (Constants::MTG_PHASE_COMBATDAMAGE == event->to->id)
@@ -564,6 +568,7 @@ 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<WEventCombatStepChange*>(e))
switch (event->step)
{

View File

@@ -356,6 +356,7 @@ int GuiPlay::receiveEventPlus(WEvent * e)
return 1;
}
}
// TODO: C6246: Clarify event, which event are you referring to?
else if (WEventCreatureAttacker* event = dynamic_cast<WEventCreatureAttacker*>(e))
{
if (NULL != event->after)
@@ -368,6 +369,7 @@ int GuiPlay::receiveEventPlus(WEvent * e)
{
Replace();
}
// TODO: C6246: Clarify event, which event are you referring to?
else if (WEventCardTap* event = dynamic_cast<WEventCardTap*>(e))
{
if (CardView* cv = dynamic_cast<CardView*>(event->card->view))
@@ -383,6 +385,7 @@ int GuiPlay::receiveEventPlus(WEvent * e)
}
return 1;
}
// TODO: C6246: Clarify event, which event are you referring to?
else if (WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*>(e))
{
if (Constants::MTG_PHASE_COMBATEND == event->to->id)

View File

@@ -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 i = 0; i < Constants::NB_MTG_PHASES; i++)
for (int phaseIdx = 0; phaseIdx < Constants::NB_MTG_PHASES; phaseIdx++)
{
if (s1.find(Constants::MTGPhaseCodeNames[i]) != string::npos)
if (s1.find(Constants::MTGPhaseCodeNames[phaseIdx]) != string::npos)
{
phase = i;
phase = phaseIdx;
}
}
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 i = 0; i < Constants::NB_MTG_PHASES; i++)
for (int phaseIdx = 0; phaseIdx < Constants::NB_MTG_PHASES; phaseIdx++)
{
if (s1.find("next") != string::npos)
once = 1;
if (s1.find(Constants::MTGPhaseCodeNames[i]) != string::npos)
if (s1.find(Constants::MTGPhaseCodeNames[phaseIdx]) != string::npos)
{
phase = i;
phase = phaseIdx;
}
}
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 i = 0; i < kMaxCastKeywordsCount; ++i)
for (size_t castPlayIdx = 0; castPlayIdx < kMaxCastKeywordsCount; ++castPlayIdx)
{
found = s.find(kMaxCastKeywords[i]);
found = s.find(kMaxCastKeywords[castPlayIdx]);
if (found != string::npos)
{
size_t header = kMaxCastKeywords[i].size();
size_t header = kMaxCastKeywords[castPlayIdx].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[i], who);
return NEW ACastRestriction(id, card, t, castTargets, value, modifyExisting, kMaxCastZones[castPlayIdx], who);
//TODO NEW ACastRestrictionUntilEndOfTurn(id, card, t, value, modifyExisting, kMaxCastZones[i], who);
}
}
@@ -2578,9 +2578,11 @@ 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;
size_t stypesStartIndex = found + 12;
stypesStartIndex = found + 12;
extraTransforms.append(transformsParamsString.substr(stypesStartIndex, real_end - stypesStartIndex).c_str());
transformsParamsString.erase(stypesStartIndex, real_end - stypesStartIndex);
}
@@ -2597,14 +2599,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
vector<string> newAbilitiesList;
storedString.erase();
storedString.append(extraTransforms);
extraTransforms.erase();
for (unsigned int i = 0 ; i < abilities.size() ; i++)
{
if(abilities[i].empty())
abilities.erase(abilities.begin()+i);
}
extraTransforms.erase();
for(unsigned int j = 0;j < abilities.size();j++)
{
if (abilities[j].empty())
continue;
if(abilities[j].find("setpower=") != string::npos)
{
newpowerfound = true;
@@ -3205,8 +3206,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int
if (dryMode)
{
result = abilityEfficiency(a, card->controller(), mode, tc);
for (size_t i = 0; i < v.size(); ++i)
SAFE_DELETE(v[i]);
for (vector<MTGAbility *>::iterator it = v.begin(); it != v.end(); ++it )
SAFE_DELETE(*it);
return result;
}
@@ -3488,6 +3491,7 @@ 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))
{
@@ -3644,14 +3648,14 @@ void AbilityFactory::addAbilities(int _id, Spell * spell)
case 3410: //Seed of Innocence
{
GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2; i++)
for (int playerIdx = 0; playerIdx < 2; playerIdx++)
{
for (int j = 0; j < game->players[i]->game->inPlay->nb_cards; j++)
for (int j = 0; j < game->players[playerIdx]->game->inPlay->nb_cards; j++)
{
MTGCardInstance * current = game->players[i]->game->inPlay->cards[j];
MTGCardInstance * current = game->players[playerIdx]->game->inPlay->cards[j];
if (current->hasType("Artifact"))
{
game->players[i]->game->putInGraveyard(current);
game->players[playerIdx]->game->putInGraveyard(current);
current->controller()->gainLife(current->getManaCost()->getConvertedCost());
}
}
@@ -3808,7 +3812,6 @@ 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);

View File

@@ -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 * spellCost = player->getManaPool();
ManaCost * stormSpellCost = player->getManaPool();
for (int i = storm; i > 1; i--)
{
spell = game->mLayers->stackLayer()->addSpell(copy, NULL, spellCost, payResult, 1);
spell = game->mLayers->stackLayer()->addSpell(copy, NULL, stormSpellCost, payResult, 1);
}
}//end of storm

View File

@@ -140,15 +140,14 @@ 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);
size_t start = value.find("(");
size_t end = value.rfind(")");
start = value.find("(");
end = value.rfind(")");
string manaType = value.substr(start + 1, end - start - 1);
manaCost->addExtraCost(NEW LifeorManaCost(NULL,manaType));
break;
@@ -172,15 +171,15 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
separator2 = value.find(",", separator + 1);
}
SAFE_DELETE(tc);
size_t target_start = string::npos;
size_t targetIndexStart = string::npos;
if (separator2 != string::npos)
{
target_start = value.find(",", separator2 + 1);
targetIndexStart = value.find(",", separator2 + 1);
}
size_t target_end = counter_end;
if (target_start != string::npos && target_end != string::npos)
size_t targetIndexEnd = counter_end;
if (targetIndexStart != string::npos && targetIndexEnd != string::npos)
{
string target = value.substr(target_start + 1, target_end - 1 - target_start);
string target = value.substr(targetIndexStart + 1, targetIndexEnd - 1 - targetIndexStart);
tc = tcf.createTargetChooser(target, c);
}
manaCost->addExtraCost(NEW CounterCost(counter, tc));
@@ -195,6 +194,7 @@ 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);

View File

@@ -484,6 +484,7 @@ 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)
@@ -546,6 +547,7 @@ 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;