fix random segmentation fault

should fix the crash -> rain of filth in test suite
This commit is contained in:
Anthony Calosa
2017-02-03 10:30:14 +08:00
parent d26e9da6c4
commit dc696a0f45
2 changed files with 35 additions and 33 deletions
+19 -19
View File
@@ -781,53 +781,53 @@ private:
} }
else if (s == "olandg") else if (s == "olandg")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_GREEN, target->controller()->opponent()); intValue = countManaProducedby(Constants::MTG_COLOR_GREEN, target, target->controller()->opponent());
} }
else if (s == "olandu") else if (s == "olandu")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_BLUE, target->controller()->opponent()); intValue = countManaProducedby(Constants::MTG_COLOR_BLUE, target, target->controller()->opponent());
} }
else if (s == "olandr") else if (s == "olandr")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_RED, target->controller()->opponent()); intValue = countManaProducedby(Constants::MTG_COLOR_RED, target, target->controller()->opponent());
} }
else if (s == "olandb") else if (s == "olandb")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_BLACK, target->controller()->opponent()); intValue = countManaProducedby(Constants::MTG_COLOR_BLACK, target, target->controller()->opponent());
} }
else if (s == "olandw") else if (s == "olandw")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_WHITE, target->controller()->opponent()); intValue = countManaProducedby(Constants::MTG_COLOR_WHITE, target, target->controller()->opponent());
} }
else if (s == "olandc") else if (s == "olandc")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_ARTIFACT, target->controller()->opponent()) + intValue = countManaProducedby(Constants::MTG_COLOR_ARTIFACT, target, target->controller()->opponent()) +
countManaProducedby(Constants::MTG_COLOR_WASTE, target->controller()->opponent()); countManaProducedby(Constants::MTG_COLOR_WASTE, target, target->controller()->opponent());
} }
else if (s == "plandg") else if (s == "plandg")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_GREEN, target->controller()); intValue = countManaProducedby(Constants::MTG_COLOR_GREEN, target, target->controller());
} }
else if (s == "plandu") else if (s == "plandu")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_BLUE, target->controller()); intValue = countManaProducedby(Constants::MTG_COLOR_BLUE, target, target->controller());
} }
else if (s == "plandr") else if (s == "plandr")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_RED, target->controller()); intValue = countManaProducedby(Constants::MTG_COLOR_RED, target, target->controller());
} }
else if (s == "plandb") else if (s == "plandb")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_BLACK, target->controller()); intValue = countManaProducedby(Constants::MTG_COLOR_BLACK, target, target->controller());
} }
else if (s == "plandw") else if (s == "plandw")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_WHITE, target->controller()); intValue = countManaProducedby(Constants::MTG_COLOR_WHITE, target, target->controller());
} }
else if (s == "plandc") else if (s == "plandc")
{ {
intValue = countManaProducedby(Constants::MTG_COLOR_ARTIFACT, target->controller()) + intValue = countManaProducedby(Constants::MTG_COLOR_ARTIFACT, target, target->controller()) +
countManaProducedby(Constants::MTG_COLOR_WASTE, target->controller()); countManaProducedby(Constants::MTG_COLOR_WASTE, target, target->controller());
} }
else if (s == "cantargetmycre")// can target my creature else if (s == "cantargetmycre")// can target my creature
{ {
@@ -1122,7 +1122,7 @@ public:
return count; return count;
} }
/*int countManaProducedby(int color, MTGCardInstance * target, Player * player) int countManaProducedby(int color, MTGCardInstance * target, Player * player)
{ {
int count = 0; int count = 0;
for (size_t i = 0; i < target->getObserver()->mLayers->actionLayer()->manaObjects.size(); i++) for (size_t i = 0; i < target->getObserver()->mLayers->actionLayer()->manaObjects.size(); i++)
@@ -1134,9 +1134,9 @@ public:
count += 1; count += 1;
} }
return count; return count;
}*/ }
int countManaProducedby(int color, Player * player) /*int countManaProducedby(int color, Player * player)
{ {
int count = 0; int count = 0;
for (int i = 0; i < player->game->battlefield->nb_cards; i++) for (int i = 0; i < player->game->battlefield->nb_cards; i++)
@@ -1155,7 +1155,7 @@ public:
count += 1; count += 1;
} }
return count; return count;
} }*/
WParsedInt(int value = 0) WParsedInt(int value = 0)
{ {
@@ -2066,7 +2066,7 @@ class AACopier: public ActivatedAbility
{ {
public: public:
bool isactivated; bool isactivated;
vector<MTGAbility *> currentAbilities; //vector<MTGAbility *> currentAbilities;
MTGAbility * andAbility; MTGAbility * andAbility;
AACopier(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL); AACopier(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL);
int resolve(); int resolve();
+16 -14
View File
@@ -711,25 +711,27 @@ void GameObserver::gameStateBasedEffects()
card->myPair = NULL; card->myPair = NULL;
} }
///set basic land mana objects canproduce ///set basic land mana objects canproduce
for (size_t gg = 0; gg < mLayers->actionLayer()->manaObjects.size(); gg++) /*for (size_t gg = 0; gg < mLayers->actionLayer()->manaObjects.size(); gg++)
{ {
MTGAbility * aa = ((MTGAbility *) mLayers->actionLayer()->manaObjects[gg]); MTGAbility * aa = ((MTGAbility *) mLayers->actionLayer()->manaObjects[gg]);
//AManaProducer * amp = dynamic_cast<AManaProducer*> (aa); //AManaProducer * amp = dynamic_cast<AManaProducer*> (aa);
if(aa != NULL)
if (dynamic_cast<AManaProducer*> (aa) && (dynamic_cast<AManaProducer*> (aa))->source->isLand() && (dynamic_cast<AManaProducer*> (aa))->source == card)
{ {
if (card->hasType("forest") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_GREEN)) if (dynamic_cast<AManaProducer*> (aa) && (dynamic_cast<AManaProducer*> (aa))->source->isLand() && (dynamic_cast<AManaProducer*> (aa))->source == card)
card->canproduceG = 1; {
if (card->hasType("island") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_BLUE)) if (card->hasType("forest") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_GREEN))
card->canproduceU = 1; card->canproduceG = 1;
if (card->hasType("mountain") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_RED)) if (card->hasType("island") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_BLUE))
card->canproduceR = 1; card->canproduceU = 1;
if (card->hasType("swamp") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_BLACK)) if (card->hasType("mountain") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_RED))
card->canproduceB = 1; card->canproduceR = 1;
if (card->hasType("plains") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_WHITE)) if (card->hasType("swamp") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_BLACK))
card->canproduceW = 1; card->canproduceB = 1;
if (card->hasType("plains") && ((AManaProducer*)aa)->output->hasColor(Constants::MTG_COLOR_WHITE))
card->canproduceW = 1;
}
} }
} }*/
///clear imprints ///clear imprints
if(isInPlay(card) && card->imprintedCards.size()) if(isInPlay(card) && card->imprintedCards.size())
{ {