Jeck - Change to deck viewer mana producer counting function, fix potential problem with mana producer filtering.

This commit is contained in:
wagic.jeck
2010-03-02 04:04:11 +00:00
parent 034e61e9fa
commit b5dc729f58
2 changed files with 27 additions and 34 deletions
+18 -30
View File
@@ -1087,48 +1087,34 @@ void GameStateDeckViewer::updateStats() {
} }
// Lets look for mana producing abilities // Lets look for mana producing abilities
MTGCardInstance * cin;
MTGAbility * ab = NULL;
int found; int found;
// TODO: Creating card instance for the sole purpose of getting the card abilities is dirty. Do something about it.
cin = new MTGCardInstance(current, NULL);
vector<string> abilityStrings; vector<string> abilityStrings;
string thisstring = current->data->magicText; string thisstring = current->data->magicText;
StringExplode(thisstring, "\n", &abilityStrings); StringExplode(thisstring, "\n", &abilityStrings);
/*char buf[4096]; for(int v=0;v<abilityStrings.size();v++){
sprintf(buf, "Card: %s Ability count:%i Iterating....", (current->name).c_str(),(int)abilityStrings.size()); string s = abilityStrings[v];
OutputDebugString(buf);*/ size_t t = s.find("add");
if(t != string::npos){
for (int i=0; i<(int)abilityStrings.size(); i++) { s = s.substr(t+3);
found = abilityStrings.at(i).find("add"); ManaCost * mc = ManaCost::parseManaCost(s);
if (found != (int)string::npos){ //Parse only mana abilities for (int j=0; j<Constants::MTG_NB_COLORS;j++){
AbilityFactory af; if(mc->hasColor(j)){
ab = af.parseMagicLine(abilityStrings.at(i),0,0,cin); if (current->data->isLand()) {
AManaProducer * amp = dynamic_cast<AManaProducer*>(ab); if (current->data->hasType("Basic")) {
stw.countBasicLandsPerColor[j] += currentCount;
if (amp){
//OutputDebugString("M ");
for (int j=0; j<Constants::MTG_NB_COLORS;j++){
if (amp->output->hasColor(j)) {
if (current->data->isLand()) {
if (current->data->hasType("Basic")) {
stw.countBasicLandsPerColor[j] += currentCount;
} else {
stw.countLandsPerColor[j] += currentCount;
}
} else { } else {
stw.countNonLandProducersPerColor[j] += currentCount; stw.countLandsPerColor[j] += currentCount;
} }
} else {
stw.countNonLandProducersPerColor[j] += currentCount;
} }
} }
} }
SAFE_DELETE(ab); SAFE_DELETE(mc);
} }
} }
SAFE_DELETE(cin);
// Add to the per color counters // Add to the per color counters
// a. regular costs // a. regular costs
@@ -1388,6 +1374,7 @@ int GameStateDeckViewer::loadDeck(int deckid){
myDeck->validate(); myDeck->validate();
myCollection->validate(); myCollection->validate();
} }
// Load deck statistics // Load deck statistics
// TODO: Code cleanup (Copypasted with slight changes from GameStateMenu.cpp) // TODO: Code cleanup (Copypasted with slight changes from GameStateMenu.cpp)
char buffer[512]; char buffer[512];
@@ -1521,7 +1508,8 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
pricelist->setPrice(card->getMTGId(),price*2); pricelist->setPrice(card->getMTGId(),price*2);
playerdata->collection->remove(card->getMTGId()); playerdata->collection->remove(card->getMTGId());
displayed_deck->Remove(card,1); displayed_deck->Remove(card,1);
displayed_deck->validate(); displayed_deck->validate();
stw.needUpdate = true;
loadIndexes(); loadIndexes();
} }
} }
+9 -4
View File
@@ -229,14 +229,19 @@ string WCFilterOnlyColor::getCode(){
} }
//WCFilterProducesColor //WCFilterProducesColor
bool WCFilterProducesColor::isMatch(MTGCard * c){ bool WCFilterProducesColor::isMatch(MTGCard * c){
bool bMatch = false;
if(!c || !c->data) if(!c || !c->data)
return false; return false;
string s = c->data->magicText; string s = c->data->magicText;
size_t t = s.find("add"); size_t t = s.find("add");
if(t == string::npos) while(t != string::npos){
return false; s = s.substr(t+3);
ManaCost * mc = ManaCost::parseManaCost(s.substr(t)); ManaCost * mc = ManaCost::parseManaCost(s);
return (mc->hasColor(color) > 0); if(mc->hasColor(color) > 0) {bMatch = true; SAFE_DELETE(mc); break;}
SAFE_DELETE(mc);
t = s.find("add");
}
return bMatch;
} }
string WCFilterProducesColor::getCode(){ string WCFilterProducesColor::getCode(){
char buf[12]; char buf[12];