From 01fdcfdfecf32aa8f23b9907c305758dc8dd9fd2 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Tue, 14 Feb 2017 22:30:50 +0800 Subject: [PATCH] zpos and zone display added zone position (adjust dynamically), also inverts the display of the zone so we always get the top/recent one... the library zpos is inverted so if we choose to target the top 5 zpos like target(*[zpos>=5|mylibrary), it will do from top to bottom... this is only for AI so we can add alternate code for them since they cant use reveal atm, we can make them target within allowed range... Also this commit disabled the new legend and planeswalker rule since it conflicts with reveal ability, unless I/We figure it out, I recommend to use the old one... --- projects/mtg/include/CardDescriptor.h | 6 ++- projects/mtg/include/MTGCardInstance.h | 1 + projects/mtg/src/CardDescriptor.cpp | 14 ++++-- projects/mtg/src/CardDisplay.cpp | 11 +++-- projects/mtg/src/CardGui.cpp | 11 ++++- projects/mtg/src/GameObserver.cpp | 10 +++++ projects/mtg/src/MTGCardInstance.cpp | 1 + projects/mtg/src/MTGRules.cpp | 59 +++++++++++++++++++++++--- projects/mtg/src/TargetChooser.cpp | 10 ++++- 9 files changed, 104 insertions(+), 19 deletions(-) diff --git a/projects/mtg/include/CardDescriptor.h b/projects/mtg/include/CardDescriptor.h index 23adcfe5c..daa9aa365 100644 --- a/projects/mtg/include/CardDescriptor.h +++ b/projects/mtg/include/CardDescriptor.h @@ -39,6 +39,8 @@ class CardDescriptor: public MTGCardInstance int manacostComparisonMode; int counterComparisonMode; int convertedManacost; // might fit better into MTGCardInstance? + int zposComparisonMode; + int zposition; int anyCounter; int init(); CardDescriptor(); @@ -68,12 +70,12 @@ class CardDescriptor: public MTGCardInstance int CDdamager; int CDgeared; int CDblocked; - int CDcanProduceC; + /*int CDcanProduceC; int CDcanProduceG; int CDcanProduceU; int CDcanProduceR; int CDcanProduceB; - int CDcanProduceW; + int CDcanProduceW;*/ int CDnocolor; }; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 2d8e9f328..3e6f60620 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -114,6 +114,7 @@ public: int CountedObjects; int kicked; int dredge; + int zpos; bool isDualWielding; bool stillNeeded; Player * lastController; diff --git a/projects/mtg/src/CardDescriptor.cpp b/projects/mtg/src/CardDescriptor.cpp index ce412411a..5be1448a7 100644 --- a/projects/mtg/src/CardDescriptor.cpp +++ b/projects/mtg/src/CardDescriptor.cpp @@ -18,6 +18,8 @@ CardDescriptor::CardDescriptor() manacostComparisonMode = COMPARISON_NONE; counterComparisonMode = COMPARISON_NONE; convertedManacost = -1; + zposComparisonMode = COMPARISON_NONE; + zposition = -1; compareName =""; nameComparisonMode = COMPARISON_NONE; colorComparisonMode = COMPARISON_NONE; @@ -26,12 +28,12 @@ CardDescriptor::CardDescriptor() CDdamager = 0; CDgeared = 0; CDblocked = 0; - CDcanProduceC = 0; + /*CDcanProduceC = 0; CDcanProduceG = 0; CDcanProduceU = 0; CDcanProduceR = 0; CDcanProduceB = 0; - CDcanProduceW = 0; + CDcanProduceW = 0;*/ CDnocolor = 0; } @@ -145,6 +147,8 @@ MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card) return NULL; if (manacostComparisonMode && !valueInRange(manacostComparisonMode, card->myconvertedcost, convertedManacost)) return NULL; + if (zposComparisonMode && !valueInRange(zposComparisonMode, card->zpos, zposition)) + return NULL; if (nameComparisonMode && compareName != card->name) return NULL; return card; @@ -186,6 +190,8 @@ MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card) match = NULL; if (manacostComparisonMode && !valueInRange(manacostComparisonMode, card->myconvertedcost, convertedManacost)) match = NULL; + if (zposComparisonMode && !valueInRange(zposComparisonMode, card->zpos, zposition)) + match = NULL; if(nameComparisonMode && compareName != card->name) match = NULL; @@ -256,7 +262,7 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card) match = NULL; } } - + /* if ((CDcanProduceC == -1 && card->canproduceC == 1) || (CDcanProduceC == 1 && card->canproduceC == 0)) { match = NULL; @@ -286,7 +292,7 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card) { match = NULL; } - + */ if ((CDnocolor == -1 && card->getColor() == 0)) { match = NULL; diff --git a/projects/mtg/src/CardDisplay.cpp b/projects/mtg/src/CardDisplay.cpp index 5ad0a38bd..7675763d0 100644 --- a/projects/mtg/src/CardDisplay.cpp +++ b/projects/mtg/src/CardDisplay.cpp @@ -44,9 +44,11 @@ void CardDisplay::init(MTGGameZone * zone) resetObjects(); if (!zone) return; start_item = 0; - for (int i = 0; i < zone->nb_cards; i++) + vector newCD (zone->cards.rbegin(), zone->cards.rend()); + for (int i = 0; i < zone->nb_cards; i++)//invert display so the top will always be the first one to show { - AddCard(zone->cards[i]); + //AddCard(zone->cards[i]); + AddCard(newCD[i]); } if (mObjects.size()) mObjects[0]->Entering(); } @@ -78,7 +80,8 @@ void CardDisplay::Update(float dt) bool update = false; if (zone) - { + {//invert display so the top will always be the first one to show + vector newCD (zone->cards.rbegin(), zone->cards.rend()); int size = zone->cards.size(); for (int i = start_item; i < start_item + nb_displayed_items && i < (int)(mObjects.size()); i++) { @@ -88,7 +91,7 @@ void CardDisplay::Update(float dt) break; } CardGui * cardg = (CardGui *) mObjects[i]; - if (cardg->card != zone->cards[i]) update = true; + if (cardg->card != newCD[i]) update = true; } } PlayGuiObjectController::Update(dt); diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 13f75e4b6..bfd80dea4 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -545,7 +545,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos) JRenderer * renderer = JRenderer::GetInstance(); JQuadPtr q; MTGCardInstance * thiscard = dynamic_cast (card); - + int zpos = 0; float x = pos.actX; vectoritems = gModRules.cardgui.background; @@ -569,6 +569,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos) //draw black border ingame only if(thiscard && thiscard->getObserver()) { + zpos = thiscard->zpos; renderer->FillRoundRect((pos.actX - (pos.actZ * 84.f))-11.5f,(pos.actY - (pos.actZ * 119.7f))-14.f,pos.actZ * 168.f + 6.5f,pos.actZ * 239.4f + 12.f,8.f,ARGB(255,5,5,5)); renderer->DrawRoundRect((pos.actX - (pos.actZ * 84.f))-11.5f,(pos.actY - (pos.actZ * 119.7f))-14.f,pos.actZ * 168.f + 6.5f,pos.actZ * 239.4f + 12.f,8.f,ARGB(50,240,240,240)); } @@ -732,7 +733,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos) if (found != string::npos) { stringstream st; - st << card->getMTGId(); + st << "id:" << card->getMTGId() << " zpos:" << zpos; formattedfield = FormattedData(formattedfield, "mtgid", st.str()); } @@ -1509,6 +1510,12 @@ bool CardGui::FilterCard(MTGCard * _card,string filter) { cd.setToughness(comparisonCriterion); cd.toughnessComparisonMode = comparisonMode; + //zpos restrictions + } + else if (attribute.find("zpos") != string::npos) + {//using > or < don't have effect unless like this: >= or <= or = + cd.zposition = comparisonCriterion; + cd.zposComparisonMode = comparisonMode; //Manacost restrictions } else if (attribute.find("manacost") != string::npos) diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 413319edd..94d6397af 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -672,6 +672,16 @@ void GameObserver::gameStateBasedEffects() for (int i = 0; i < ManaCost::MANA_PAID_WITH_BESTOW +1; i++) card->alternateCostPaid[i] = 0; } + //test zone position + if(card && (isInGrave(card)||isInHand(card)||isInExile(card))) + { + card->zpos = w+1; + } + else if(card && (isInLibrary(card))) + {//invert so we get the top one... + int onum = w+1; + card->zpos = abs(onum - zone->nb_cards)+1; + } } diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index be1c0b1fe..d05eaf718 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -237,6 +237,7 @@ void MTGCardInstance::initMTGCI() stillNeeded = true; kicked = 0; dredge = 0; + zpos = 0; chooseacolor = -1; chooseasubtype = ""; coinSide = -1; diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index d981838b5..a8bcbcbf3 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -3257,14 +3257,17 @@ int MTGLegendRule::added(MTGCardInstance * card) { map::iterator it; int destroy = 0; - + vectoroldCards; for (it = cards.begin(); it != cards.end(); it++) { MTGCardInstance * comparison = (*it).first; if (comparison != card && comparison->controller() == card->controller() && !(comparison->getName().compare(card->getName()))) - if (!(game->getCurrentTargetChooser() || game->mLayers->actionLayer()->isWaitingForAnswer())) + if (!(game->getCurrentTargetChooser() || game->mLayers->actionLayer()->isWaitingForAnswer())) + { + oldCards.push_back(comparison); destroy = 1; - } + } + }/* if(destroy) { vectorselection; @@ -3287,6 +3290,27 @@ int MTGLegendRule::added(MTGCardInstance * card) SAFE_DELETE(LegendruleGeneric); MTGAbility * menuChoice = NEW MenuAbility(game, game->mLayers->actionLayer()->getMaxId(), NULL, myClone,true,selection,card->controller(),"Legendary Rule"); menuChoice->addToGame(); + }*/ + //reverted to old since this new code conflicts with reveal targetchooser + if(destroy) + { + vectorselection; + MultiAbility * multi = NEW MultiAbility(game, game->mLayers->actionLayer()->getMaxId(), card, card, NULL); + for(unsigned int i = 0;i < oldCards.size();i++) + { + AAMover *a = NEW AAMover(game, game->mLayers->actionLayer()->getMaxId(), card, oldCards[i],"ownergraveyard","Keep New"); + a->oneShot = true; + multi->Add(a); + } + multi->oneShot = 1; + MTGAbility * a1 = multi; + selection.push_back(a1); + AAMover *b = NEW AAMover(game, game->mLayers->actionLayer()->getMaxId(), card, card,"ownergraveyard","Keep Old"); + b->oneShot = true; + MTGAbility * b1 = b; + selection.push_back(b1); + MTGAbility * menuChoice = NEW MenuAbility(game, game->mLayers->actionLayer()->getMaxId(), card, card,true,selection,card->controller(),"Legendary Rule"); + menuChoice->addToGame(); } return 1; } @@ -3341,9 +3365,12 @@ int MTGPlaneWalkerRule::added(MTGCardInstance * card) { MTGCardInstance * comparison = (*it).first; if (comparison != card && comparison->types == card->types && comparison->controller() == card->controller()) - if (!(game->getCurrentTargetChooser() || game->mLayers->actionLayer()->isWaitingForAnswer())) + if (!(game->getCurrentTargetChooser() || game->mLayers->actionLayer()->isWaitingForAnswer())) + { + oldCards.push_back(comparison); destroy = 1; - } + } + }/* if (destroy) { vectorselection; @@ -3366,6 +3393,28 @@ int MTGPlaneWalkerRule::added(MTGCardInstance * card) SAFE_DELETE(PWruleGeneric); MTGAbility * menuChoice = NEW MenuAbility(game, game->mLayers->actionLayer()->getMaxId(), NULL, myClone,true,selection,card->controller(),"Planeswalker Uniqueness Rule"); menuChoice->addToGame(); + }*/ + //reverted to old since this new code conflicts with reveal targetchooser + if (destroy) + { + vectorselection; + + MultiAbility * multi = NEW MultiAbility(game,game->mLayers->actionLayer()->getMaxId(), card, card, NULL); + for(unsigned int i = 0;i < oldCards.size();i++) + { + AAMover *a = NEW AAMover(game, game->mLayers->actionLayer()->getMaxId(), card, oldCards[i],"ownergraveyard","Keep New"); + a->oneShot = true; + multi->Add(a); + } + multi->oneShot = 1; + MTGAbility * a1 = multi; + selection.push_back(a1); + AAMover *b = NEW AAMover(game, game->mLayers->actionLayer()->getMaxId(), card, card,"ownergraveyard","Keep Old"); + b->oneShot = true; + MTGAbility * b1 = b; + selection.push_back(b1); + MTGAbility * menuChoice = NEW MenuAbility(game, game->mLayers->actionLayer()->getMaxId(), card, card,true,selection,card->controller(),"Planeswalker Rule"); + menuChoice->addToGame(); } return 1; } diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index be0466166..a80822c21 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -579,7 +579,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDdamager = 1; } - } + }/* //can produce mana else if (attribute.find("cmana") != string::npos) { @@ -646,7 +646,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDcanProduceW = 1; } - } + }*/ else if (attribute.find("multicolor") != string::npos) { //card is multicolored? @@ -674,6 +674,12 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->setToughness(comparisonCriterion); cd->toughnessComparisonMode = comparisonMode; + //zpos restrictions + } + else if (attribute.find("zpos") != string::npos) + { + cd->zposition = comparisonCriterion; + cd->zposComparisonMode = comparisonMode; //Manacost restrictions } else if (attribute.find("manacost") != string::npos)