From 0ff7e54ff466809a8a33f7ff4c2a0326b1d8b976 Mon Sep 17 00:00:00 2001 From: zethfoxster Date: Thu, 7 Jul 2016 20:47:25 -0400 Subject: [PATCH 1/6] this is a good enough fix as waste is colorless which is artifact, and all we do is barrow the kbitmask from land. --- projects/mtg/src/CardPrimitive.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index 0ed61cd68..bddc43ed4 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -426,6 +426,9 @@ uint8_t CardPrimitive::ConvertColorToBitMask(int inColor) case Constants::MTG_COLOR_LAND: value = kColorBitMask_Land; break; + case Constants::MTG_COLOR_WASTE://the true colorless mana shares the kbitmask of land. kbitmask dictates the color of the quad(no image boarder), and the symbol. nothing more. + value = kColorBitMask_Land; + break; default: break; From c0c52e57df8c7922e512dbca2a9776d65d933e27 Mon Sep 17 00:00:00 2001 From: zethfoxster Date: Fri, 8 Jul 2016 17:48:27 -0400 Subject: [PATCH 2/6] what a dumb typo. surprised it was in the engine that way for so long. --- projects/mtg/include/AllAbilities.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 1abaf0276..6d677c33b 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -6160,7 +6160,7 @@ public: { if(forceDestroy != -1) return 1; - if(!(source->hasType(Subtypes::TYPE_INSTANT)||source->hasType(Subtypes::TYPE_INSTANT)) && !source->isInPlay(game)) + if(!(source->hasType(Subtypes::TYPE_INSTANT)||source->hasType(Subtypes::TYPE_SORCERY)) && !source->isInPlay(game)) return 1; return 0; } From ee91e0698de85cc9da65f2f81c2dbeb4ef8b4b39 Mon Sep 17 00:00:00 2001 From: zethfoxster Date: Sat, 9 Jul 2016 00:11:21 -0400 Subject: [PATCH 3/6] corrected some logic with computenewcost. there is a bug im working on with newaffinity and cards that contain targetchoosers with CD tcs. experimental change also added with lords. im making the abilities grants by lord forcedalive until the lord is removed from game. some instances of forcedalive in master primitives did not contain abilities which resolved, meaning they would contenue even though the source had left play. --- projects/mtg/include/AllAbilities.h | 2 ++ projects/mtg/src/GameObserver.cpp | 5 +++-- projects/mtg/src/MTGCardInstance.cpp | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 6d677c33b..392c89eb4 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -3256,6 +3256,7 @@ public: } else { + a->forcedAlive = 1; a->addToGame(); abilities[d] = a; } @@ -3278,6 +3279,7 @@ public: if (abilities.find(card) != abilities.end() && !(forceDestroy == -1 && forcedAlive == 1)) //only embelms have forcedestroy = -1 and forcedalive = 1 { + abilities[card]->forcedAlive = 0; game->removeObserver(abilities[card]); abilities.erase(card); } diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 3d65cd041..28801ae3c 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -1079,7 +1079,8 @@ void GameObserver::Affinity() } } } - //////////////////////////// + + /////////////////////// bool NewAffinityFound = false; for (unsigned int na = 0; na < card->cardsAbilities.size(); na++) { @@ -1114,7 +1115,7 @@ void GameObserver::Affinity() //only do any of the following if a card with the stated ability is in your hand. //kicker is an addon to normal cost, suspend is not casting. add cost as needed EXACTLY as seen below. card->getManaCost()->resetCosts(); - ManaCost * newCost = NEW ManaCost(); + ManaCost *newCost = NEW ManaCost(); newCost->copy(card->computeNewCost(card, card->getManaCost(), card->model->data->getManaCost())); card->getManaCost()->copy(newCost); SAFE_DELETE(newCost); diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index e5fc325fe..9fcbee96d 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -970,6 +970,14 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos string type = ""; ManaCost * original = NEW ManaCost(); original->copy(Data); + Cost->copy(original); + if (Cost->extraCosts) + { + for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++) + { + Cost->extraCosts->costs[i]->setSource(card); + } + } if (card->getIncreasedManaCost()->getConvertedCost() || card->getReducedManaCost()->getConvertedCost()) {//start1 if (card->getIncreasedManaCost()->getConvertedCost()) @@ -1076,6 +1084,13 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos Cost->extraCosts->costs[i]->setSource(card); } } + if (Cost->extraCosts) + { + for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++) + { + Cost->extraCosts->costs[i]->setSource(card); + } + } int reduce = 0; if (card->has(Constants::AFFINITYGREENCREATURES)) { From 14f65c55b5c627374c3ba19f567670ff7c3b08ef Mon Sep 17 00:00:00 2001 From: zethfoxster Date: Sat, 9 Jul 2016 00:48:08 -0400 Subject: [PATCH 4/6] going to try only updating affinity() when cards move from anywhere to anywhere to help minimize the calls to this function. this atleast allows me to debug albeit slowly the follow issue ive been working to fix. not sure when this was introduced but it was not happening when i first coded this function. manacost->copy() did not slow the game to a crawl. anyways, trinisphere and any card containing other={H(land[basic]|mybattlefield)}{1} name(Pay /1/ and Return a Basic Land to Hand) cost such as this with a CD tc. --- projects/mtg/include/GameObserver.h | 1 + projects/mtg/src/GameObserver.cpp | 33 +++++++++++++++++------------ projects/mtg/src/MTGGameZones.cpp | 1 + 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index 0e1a096eb..6b5fddb79 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -124,6 +124,7 @@ class GameObserver{ void gameStateBasedEffects(); void enchantmentStatus(); void Affinity(); + bool AffinityNeedsUpdate; void addObserver(MTGAbility * observer); bool removeObserver(ActionElement * observer); void startGame(GameType, Rules * rules); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 28801ae3c..9db6fbdb9 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -53,6 +53,7 @@ void GameObserver::cleanup() actionsList.clear(); gameTurn.clear(); OpenedDisplay = NULL; + AffinityNeedsUpdate = false; } GameObserver::~GameObserver() @@ -1092,20 +1093,22 @@ void GameObserver::Affinity() NewAffinityFound = true; } } - bool DoReduceIncrease = false; - if (card->has(Constants::AFFINITYARTIFACTS) || - card->has(Constants::AFFINITYFOREST) || - card->has(Constants::AFFINITYGREENCREATURES) || - card->has(Constants::AFFINITYISLAND) || - card->has(Constants::AFFINITYMOUNTAIN) || - card->has(Constants::AFFINITYPLAINS) || - card->has(Constants::AFFINITYSWAMP) || - card->has(Constants::TRINISPHERE) || - card->getIncreasedManaCost()->getConvertedCost() || - card->getReducedManaCost()->getConvertedCost() || - NewAffinityFound) - DoReduceIncrease = true; - if (!DoReduceIncrease) + //bool DoReduceIncrease = false; + //if (card->has(Constants::AFFINITYARTIFACTS) || + // card->has(Constants::AFFINITYFOREST) || + // card->has(Constants::AFFINITYGREENCREATURES) || + // card->has(Constants::AFFINITYISLAND) || + // card->has(Constants::AFFINITYMOUNTAIN) || + // card->has(Constants::AFFINITYPLAINS) || + // card->has(Constants::AFFINITYSWAMP) || + // card->has(Constants::TRINISPHERE) || + // card->getIncreasedManaCost()->getConvertedCost() || + // card->getReducedManaCost()->getConvertedCost() || + // NewAffinityFound) + // DoReduceIncrease = true; + //if (!DoReduceIncrease) + // continue; + if(!AffinityNeedsUpdate)//we only adjust cost when cards move from anywhere to anywhere. continue; //above we check if there are even any cards that effect cards manacost //if there are none, leave this function. manacost->copy( is a very expensive funtion @@ -1117,6 +1120,7 @@ void GameObserver::Affinity() card->getManaCost()->resetCosts(); ManaCost *newCost = NEW ManaCost(); newCost->copy(card->computeNewCost(card, card->getManaCost(), card->model->data->getManaCost())); + card->getManaCost()->copy(newCost); SAFE_DELETE(newCost); if (card->getManaCost()->getAlternative()) @@ -1171,6 +1175,7 @@ void GameObserver::Affinity() }//end } } + AffinityNeedsUpdate = false; } void GameObserver::Render() diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 8e995dd69..18e697aba 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -328,6 +328,7 @@ MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone bool shufflelibrary = card->basicAbilities[(int)Constants::SHUFFLELIBRARYDEATH]; bool inplaytoinplay = false; bool ripToken = false; + g->AffinityNeedsUpdate = true;//we refresh affinity whenever a card is moved from anywhere to anywhere. if (g->players[0]->game->battlefield->hasName("Rest in Peace")||g->players[1]->game->battlefield->hasName("Rest in Peace")) ripToken = true; //Madness or Put in Play... From b5976035e37d1addf707b41055638d5863873340 Mon Sep 17 00:00:00 2001 From: zethfoxster Date: Sat, 9 Jul 2016 00:58:19 -0400 Subject: [PATCH 5/6] actually i changed my mind, instead lets update affinity after events are processed, that should take into account cards untapping,moving, ect.... --- projects/mtg/src/GameObserver.cpp | 3 ++- projects/mtg/src/MTGGameZones.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 9db6fbdb9..993c9d900 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -1108,7 +1108,7 @@ void GameObserver::Affinity() // DoReduceIncrease = true; //if (!DoReduceIncrease) // continue; - if(!AffinityNeedsUpdate)//we only adjust cost when cards move from anywhere to anywhere. + if(!AffinityNeedsUpdate)//we only adjust cost when events queqes are complete. continue; //above we check if there are even any cards that effect cards manacost //if there are none, leave this function. manacost->copy( is a very expensive funtion @@ -1585,6 +1585,7 @@ int GameObserver::receiveEvent(WEvent * e) SAFE_DELETE(ev); eventsQueue.pop(); } + AffinityNeedsUpdate = true; return result; } diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 18e697aba..8e995dd69 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -328,7 +328,6 @@ MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone bool shufflelibrary = card->basicAbilities[(int)Constants::SHUFFLELIBRARYDEATH]; bool inplaytoinplay = false; bool ripToken = false; - g->AffinityNeedsUpdate = true;//we refresh affinity whenever a card is moved from anywhere to anywhere. if (g->players[0]->game->battlefield->hasName("Rest in Peace")||g->players[1]->game->battlefield->hasName("Rest in Peace")) ripToken = true; //Madness or Put in Play... From f82bc394732ea581750fbfb74fa5ffcba6f77b76 Mon Sep 17 00:00:00 2001 From: zethfoxster Date: Sat, 9 Jul 2016 01:24:55 -0400 Subject: [PATCH 6/6] ok found the massive draw, it was trenisphere. the card lords every single card in the game a mana modifier. affinity normally didnt see these issues cause the cards effected are just either in your hand or the source themselves. but when trin was put in play it would cause 120 cards to have to update thier cost, which can not be done in acceptible cpu time. anyways, this should solve the issue. that card is a desaster, please do not add any more code to support it, though with it in its current state im wondering why its not in supported and is placed in borderline. --- projects/mtg/src/GameObserver.cpp | 56 +++++++++++++++++++------------ 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 993c9d900..37736c980 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -1080,7 +1080,23 @@ void GameObserver::Affinity() } } } - + ///we handle trisnisphere seperately because its a desaster. + if (card->has(Constants::TRINISPHERE)) + { + for (int jj = card->getManaCost()->getConvertedCost(); jj < 3; jj++) + { + card->getManaCost()->add(Constants::MTG_COLOR_ARTIFACT, 1); + card->countTrini++; + } + } + else + { + if (card->countTrini) + { + card->getManaCost()->remove(Constants::MTG_COLOR_ARTIFACT, card->countTrini); + card->countTrini = 0; + } + } /////////////////////// bool NewAffinityFound = false; for (unsigned int na = 0; na < card->cardsAbilities.size(); na++) @@ -1093,28 +1109,26 @@ void GameObserver::Affinity() NewAffinityFound = true; } } - //bool DoReduceIncrease = false; - //if (card->has(Constants::AFFINITYARTIFACTS) || - // card->has(Constants::AFFINITYFOREST) || - // card->has(Constants::AFFINITYGREENCREATURES) || - // card->has(Constants::AFFINITYISLAND) || - // card->has(Constants::AFFINITYMOUNTAIN) || - // card->has(Constants::AFFINITYPLAINS) || - // card->has(Constants::AFFINITYSWAMP) || - // card->has(Constants::TRINISPHERE) || - // card->getIncreasedManaCost()->getConvertedCost() || - // card->getReducedManaCost()->getConvertedCost() || - // NewAffinityFound) - // DoReduceIncrease = true; - //if (!DoReduceIncrease) - // continue; - if(!AffinityNeedsUpdate)//we only adjust cost when events queqes are complete. + bool DoReduceIncrease = false; + if ( + (card->has(Constants::AFFINITYARTIFACTS) || + card->has(Constants::AFFINITYFOREST) || + card->has(Constants::AFFINITYGREENCREATURES) || + card->has(Constants::AFFINITYISLAND) || + card->has(Constants::AFFINITYMOUNTAIN) || + card->has(Constants::AFFINITYPLAINS) || + card->has(Constants::AFFINITYSWAMP) || + card->getIncreasedManaCost()->getConvertedCost() || + card->getReducedManaCost()->getConvertedCost() || + NewAffinityFound) + && + AffinityNeedsUpdate + ) + DoReduceIncrease = true; + if (!DoReduceIncrease) continue; + //above we check if there are even any cards that effect cards manacost - //if there are none, leave this function. manacost->copy( is a very expensive funtion - //1mb a sec to run at all time even when no known reducers or increasers are in play. - //memory snapshot shots pointed to this as such a heavy load that games with many cards inplay - //would slow to a crawl. //only do any of the following if a card with the stated ability is in your hand. //kicker is an addon to normal cost, suspend is not casting. add cost as needed EXACTLY as seen below. card->getManaCost()->resetCosts();