From 685626128ab66318e82ec994872335bf6d0ec599 Mon Sep 17 00:00:00 2001 From: "wrenczes@gmail.com" Date: Tue, 2 Nov 2010 09:26:37 +0000 Subject: [PATCH] Minor refactor of AACloner::resolve() - two code paths were complete duplicates except for the MTGCard*. --- projects/mtg/include/AllAbilities.h | 75 +++++++++++------------------ projects/mtg/src/Navigator.cpp | 15 ++++-- 2 files changed, 38 insertions(+), 52 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index b7787a64b..d879a84cf 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -787,54 +787,33 @@ public: } - int resolve(){ - MTGCardInstance * _target = (MTGCardInstance *) target; - if(_target && !_target->isToken){ - MTGCardInstance * myClone; - MTGCard * clone = GameApp::collection->getCardById(_target->getId()); - myClone = NULL; - if(who != 1) myClone = NEW MTGCardInstance(clone,source->controller()->game); - if(who == 1) myClone = NEW MTGCardInstance(clone,source->controller()->opponent()->game); - if(who != 1) source->controller()->game->temp->addCard(myClone); - else source->controller()->opponent()->game->temp->addCard(myClone); - Spell * spell = NEW Spell(myClone); - spell->resolve(); - spell->source->isToken = 1; - spell->source->fresh = 1; - list::iterator it; - for ( it=awith.begin() ; it != awith.end(); it++ ){ - spell->source->basicAbilities[*it] = 1; - } - for ( it=colors.begin() ; it != colors.end(); it++ ){ - spell->source->setColor(*it); - } - delete spell; - return 1; - } - if(_target && _target->isToken){ - MTGCardInstance * myClone; - MTGCardInstance * clone = _target; - myClone = NULL; - if(who != 1) myClone = NEW MTGCardInstance(clone,source->controller()->game); - if(who == 1) myClone = NEW MTGCardInstance(clone,source->controller()->opponent()->game); - if(who != 1) source->controller()->game->temp->addCard(myClone); - else source->controller()->opponent()->game->temp->addCard(myClone); - Spell * spell = NEW Spell(myClone); - spell->resolve(); - spell->source->isToken = 1; - spell->source->fresh = 1; - list::iterator it; - for ( it=awith.begin() ; it != awith.end(); it++ ){ - spell->source->basicAbilities[*it] = 1; - } - for ( it=colors.begin() ; it != colors.end(); it++ ){ - spell->source->setColor(*it); - } - delete spell; - return 1; - } - return 0; - } + int resolve(){ + MTGCardInstance * _target = (MTGCardInstance *) target; + if(_target) + { + MTGCardInstance * myClone = NULL; + MTGCard* clone = (_target->isToken ? _target : GameApp::collection->getCardById(_target->getId())); + + if(who != 1) myClone = NEW MTGCardInstance(clone,source->controller()->game); + if(who == 1) myClone = NEW MTGCardInstance(clone,source->controller()->opponent()->game); + if(who != 1) source->controller()->game->temp->addCard(myClone); + else source->controller()->opponent()->game->temp->addCard(myClone); + Spell * spell = NEW Spell(myClone); + spell->resolve(); + spell->source->isToken = 1; + spell->source->fresh = 1; + list::iterator it; + for ( it=awith.begin() ; it != awith.end(); it++ ){ + spell->source->basicAbilities[*it] = 1; + } + for ( it=colors.begin() ; it != colors.end(); it++ ){ + spell->source->setColor(*it); + } + delete spell; + return 1; + } + return 0; + } const char * getMenuText(){ if(who == 1) return "Clone For Opponent"; diff --git a/projects/mtg/src/Navigator.cpp b/projects/mtg/src/Navigator.cpp index e8434e74a..3e9ed83d6 100644 --- a/projects/mtg/src/Navigator.cpp +++ b/projects/mtg/src/Navigator.cpp @@ -6,6 +6,8 @@ namespace { const Pos kDefaultCardPosition(300, 150, 1.0, 0.0, 220); + // the diagonal length of a card, doubled + const float kOverrideDistance = sqrtf(powf(CardGui::Width, 2) + powf(CardGui::Height, 2)) * 2; enum { @@ -246,7 +248,11 @@ public: float yDiff = fabs(mCards[mCurrentCard]->y - mCards[index]->y); float xDiff = fabs(mCards[mCurrentCard]->x - mCards[index]->x); float distance = sqrtf(yDiff * yDiff + xDiff * xDiff); - if (distance < minDistance) + + // CardSelector does this thing where if the distance in the axis you're moving is less than the distance od the card on the opposite axis, + // it would ignore the move - this made for some weird behavior where the UI wouldn't let you move in certain directions when a card looked reachable. + // instead, I'm using a different logic - if there's a card in the direction that you're stepping, and it's within a defined radius, go for it. + if (distance < minDistance && distance < kOverrideDistance) { minDistance = distance; selectedCardIndex = index; @@ -714,11 +720,12 @@ int Navigator::CardToCardZone(PlayGuiObject* inCard) else if (card->getCard()->isSpell()) { - //if (card->getCard()->target != NULL) - // isAI = card->getCard()->target->owner->isAI(); + if (card->getCard()->target != NULL) + isAI = card->getCard()->target->owner->isAI(); + // nasty hack: the lines above don't always work, as when an enchantment comes into play, its ability hasn't been activated yet, // so it doesn't yet have a target. Instead, we now look at the card's position, if it's in the top half of the screen, it goes into an AI zone - isAI = card->y < JRenderer::GetInstance()->GetActualHeight() / 2; + //isAI = card->y < JRenderer::GetInstance()->GetActualHeight() / 2; // enchantments that target creatures are treated as part of the creature zone if (card->getCard()->spellTargetType.find("creature") != string::npos)