diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 8ca14a32e..e74942aba 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -1227,17 +1227,15 @@ public: class AADrawer: public ActivatedAbilityTP { public: - WParsedInt *nbcards; - WParsedInt *RefreshedNbcards; - + string nbcardsStr; - AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, WParsedInt * nbcards,string nbcardsStr, int _tap = 0, int who = + AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost,string nbcardsStr, int _tap = 0, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); AADrawer * clone() const; - ~AADrawer(); + int getNumCards(); }; //lands, allows to play more land during a turn: @@ -1261,14 +1259,12 @@ class AALifer: public ActivatedAbilityTP { public: string life_s; - WParsedInt *life; - WParsedInt *RefreshedLife; - AALifer(int _id, MTGCardInstance * card, Targetable * _target,string life_s, WParsedInt * life, ManaCost * _cost = NULL, int _tap = 0, + AALifer(int _id, MTGCardInstance * card, Targetable * _target,string life_s, ManaCost * _cost = NULL, int _tap = 0, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); AALifer * clone() const; - ~AALifer(); + int getLife(); }; @@ -3274,16 +3270,14 @@ public: class AADamager: public ActivatedAbilityTP { public: - WParsedInt * damage; - WParsedInt * RefreshedDamage; string d; - AADamager(int _id, MTGCardInstance * _source, Targetable * _target,WParsedInt * damage, string d, ManaCost * _cost = NULL, + AADamager(int _id, MTGCardInstance * _source, Targetable * _target, string d, ManaCost * _cost = NULL, int doTap = 0, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); + int getDamage(); AADamager * clone() const; - ~AADamager(); }; @@ -3319,11 +3313,11 @@ class TADamager: public TargetAbility { public: - TADamager(int id, MTGCardInstance * card, ManaCost * _cost,WParsedInt *damage, string d, TargetChooser * _tc = NULL, int _tap = 0) : + TADamager(int id, MTGCardInstance * card, ManaCost * _cost, string d, TargetChooser * _tc = NULL, int _tap = 0) : TargetAbility(id, card, _tc, _cost, 0, _tap) { if (!tc) tc = NEW DamageableTargetChooser(card); - ability = NEW AADamager(id, card, NULL,damage, d); + ability = NEW AADamager(id, card, NULL, d); } TADamager * clone() const @@ -5432,16 +5426,13 @@ public: class AADepleter: public ActivatedAbilityTP { public: - WParsedInt * nbcards; - WParsedInt * RefreshedNbcards; string nbcardsStr; - AADepleter(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * nbcards,string nbcardsStr, ManaCost * _cost = NULL, int _tap = 0, + AADepleter(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost = NULL, int _tap = 0, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); AADepleter * clone() const; - ~AADepleter(); }; //Shuffle @@ -5492,16 +5483,13 @@ public: class AARandomDiscarder: public ActivatedAbilityTP { public: - WParsedInt * nbcards; - WParsedInt * RefreshedNbcards; string nbcardsStr; - AARandomDiscarder(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * nbcards,string nbcardsStr, ManaCost * _cost = NULL, + AARandomDiscarder(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost = NULL, int _tap = 0, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); AARandomDiscarder * clone() const; - ~AARandomDiscarder(); }; //Minion of Leshrac diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index df365bfd3..11cb4d008 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -124,7 +124,6 @@ class MTGAbility: public ActionElement{ int aType; int naType; int abilitygranted; - int nbcardAmount; MTGCardInstance * source; MTGAbility(int id, MTGCardInstance * card); MTGAbility(int id, MTGCardInstance * _source, Targetable * _target); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 79d57cde7..23fcdae8c 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -238,13 +238,13 @@ int AIAction::getEfficiency() { efficiency = 0; } - else if (aad->damage->getValue() >= target->toughness) + else if (aad->getDamage() >= target->toughness) { efficiency = 100; } else if (target->toughness) { - efficiency = (50 * aad->damage->getValue()) / target->toughness; + efficiency = (50 * aad->getDamage()) / target->toughness; } else { @@ -592,6 +592,7 @@ int AIAction::getEfficiency() } case MTGAbility::STANDARD_DRAW: { + AADrawer * drawer = (AADrawer *)a; //adding this case since i played a few games where Ai litterally decided to mill himself to death. fastest and easiest win ever. //this should help a little, tho ultimately it will be decided later what the best course of action is. efficiency = 0; @@ -602,7 +603,7 @@ int AIAction::getEfficiency() { efficiency -= 70; } - if ((a->nbcardAmount >= p->game->library->nb_cards && p->isAI()) || (p->game->hand->nb_cards > 10 && p->isAI())) + if ((drawer->getNumCards() >= p->game->library->nb_cards && p->isAI()) || (p->game->hand->nb_cards > 10 && p->isAI())) { //if the amount im drawing will mill me to death or i have more then 10 cards in hand, eff is 0; efficiency = 0; diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 6f5008363..62268bbba 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -142,9 +142,9 @@ AADamagePrevent::~AADamagePrevent() } //AADamager -AADamager::AADamager(int _id, MTGCardInstance * _source, Targetable * _target,WParsedInt * damage, string d, ManaCost * _cost, int doTap, +AADamager::AADamager(int _id, MTGCardInstance * _source, Targetable * _target, string d, ManaCost * _cost, int doTap, int who) : - ActivatedAbilityTP(_id, _source, _target, _cost, doTap, who),damage(damage), d(d) + ActivatedAbilityTP(_id, _source, _target, _cost, doTap, who), d(d) { aType = MTGAbility::DAMAGER; } @@ -154,15 +154,20 @@ AADamager::AADamager(int _id, MTGCardInstance * _source, Targetable * _target,WP Damageable * _target = (Damageable *) getTarget(); if (_target) { - RefreshedDamage = NEW WParsedInt(d, NULL, (MTGCardInstance *)source); - game->mLayers->stackLayer()->addDamage(source, _target, RefreshedDamage->getValue()); + WParsedInt damage(d, NULL, (MTGCardInstance *)source); + game->mLayers->stackLayer()->addDamage(source, _target, damage.getValue()); game->mLayers->stackLayer()->resolve(); - delete RefreshedDamage; return 1; } return 0; } + int AADamager::getDamage() + { + WParsedInt damage(d, NULL, (MTGCardInstance *)source); + return damage.getValue(); + } + const char * AADamager::getMenuText() { return "Damage"; @@ -171,21 +176,16 @@ AADamager::AADamager(int _id, MTGCardInstance * _source, Targetable * _target,WP AADamager * AADamager::clone() const { AADamager * a = NEW AADamager(*this); - a->damage = NEW WParsedInt(*(a->damage)); a->isClone = 1; return a; } -AADamager::~AADamager() -{ -SAFE_DELETE(damage); -} //AADepleter -AADepleter::AADepleter(int _id, MTGCardInstance * card, Targetable * _target,WParsedInt * nbcards,string nbcardsStr, ManaCost * _cost, int _tap, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), nbcards(nbcards),nbcardsStr(nbcardsStr) +AADepleter::AADepleter(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost, int _tap, int who) : + ActivatedAbilityTP(_id, card, _target, _cost, _tap, who),nbcardsStr(nbcardsStr) { -RefreshedNbcards = NULL; + } int AADepleter::resolve() { @@ -194,7 +194,7 @@ RefreshedNbcards = NULL; Player * player; if (_target) { - RefreshedNbcards = NEW WParsedInt(nbcardsStr, NULL, source); + WParsedInt numCards(nbcardsStr, NULL, source); if (_target->typeAsTarget() == TARGET_CARD) { player = ((MTGCardInstance *) _target)->controller(); @@ -204,12 +204,11 @@ RefreshedNbcards = NULL; player = (Player *) _target; } MTGLibrary * library = player->game->library; - for (int i = 0; i < RefreshedNbcards->getValue(); i++) + for (int i = 0; i < numCards.getValue(); i++) { if (library->nb_cards) player->game->putInZone(library->cards[library->nb_cards - 1], library, player->game->graveyard); } - delete RefreshedNbcards; } return 1; } @@ -225,11 +224,7 @@ AADepleter * AADepleter::clone() const a->isClone = 1; return a; } -AADepleter::~AADepleter() -{ -if(!isClone) -SAFE_DELETE(nbcards); -} + //AACopier AACopier::AACopier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost) : ActivatedAbility(_id, _source, _cost, 0, 0) @@ -647,12 +642,11 @@ AADiscardCard * AADiscardCard::clone() const return a; } -AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost,WParsedInt * nbcards, string nbcardsStr, int _tap, +AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, string nbcardsStr, int _tap, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, _tap, who),nbcards(nbcards), nbcardsStr(nbcardsStr) + ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), nbcardsStr(nbcardsStr) { aType = MTGAbility::STANDARD_DRAW; - nbcardAmount = nbcards->getValue(); } int AADrawer::resolve() @@ -661,7 +655,7 @@ AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCo Player * player; if (_target) { - RefreshedNbcards = NEW WParsedInt(nbcardsStr, NULL, source); + WParsedInt numCards(nbcardsStr, NULL, source); if (_target->typeAsTarget() == TARGET_CARD) { player = ((MTGCardInstance *) _target)->controller(); @@ -670,13 +664,18 @@ AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCo { player = (Player *) _target; } - game->mLayers->stackLayer()->addDraw(player, RefreshedNbcards->getValue()); + game->mLayers->stackLayer()->addDraw(player, numCards.getValue()); game->mLayers->stackLayer()->resolve(); - delete RefreshedNbcards; } return 1; } + int AADrawer::getNumCards() + { + WParsedInt numCards(nbcardsStr, NULL, source); + return numCards.getValue(); + } + const char * AADrawer::getMenuText() { return "Draw"; @@ -685,16 +684,10 @@ const char * AADrawer::getMenuText() AADrawer * AADrawer::clone() const { AADrawer * a = NEW AADrawer(*this); - a->nbcards = NEW WParsedInt(*(this->nbcards)); a->isClone = 1; return a; } -AADrawer::~AADrawer() -{ - SAFE_DELETE(nbcards); -} - // AAFrozen: Prevent a card from untapping during next untap phase AAFrozen::AAFrozen(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost, int doTap) : ActivatedAbility(id, card, _cost, 0, doTap) @@ -1247,8 +1240,8 @@ AADynamic::~AADynamic() } //AALifer -AALifer::AALifer(int _id, MTGCardInstance * card, Targetable * _target, string life_s, WParsedInt * life, ManaCost * _cost, int _tap, int who) : -ActivatedAbilityTP(_id, card, _target, _cost, _tap, who),life_s(life_s), life(life) +AALifer::AALifer(int _id, MTGCardInstance * card, Targetable * _target, string life_s, ManaCost * _cost, int _tap, int who) : +ActivatedAbilityTP(_id, card, _target, _cost, _tap, who),life_s(life_s) { aType = MTGAbility::LIFER; } @@ -1259,37 +1252,38 @@ int AALifer::resolve() if (!_target) return 0; - RefreshedLife = NEW WParsedInt(life_s, NULL, source); + WParsedInt life(life_s, NULL, source); if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) { _target = ((MTGCardInstance *) _target)->controller(); } Player *player = (Player*)_target; - player->gainOrLoseLife(RefreshedLife->getValue()); + player->gainOrLoseLife(life.getValue()); - delete RefreshedLife; return 1; } +int AALifer::getLife() +{ + WParsedInt life(life_s, NULL, source); + return life.getValue(); +} + const char * AALifer::getMenuText() { -if(life->getValue() < 0) -return "Life Loss"; + if(getLife() < 0) + return "Life Loss"; return "Life"; } AALifer * AALifer::clone() const { AALifer * a = NEW AALifer(*this); - a->life = NEW WParsedInt(*(a->life)); a->isClone = 1; return a; } -AALifer::~AALifer() -{ - SAFE_DELETE(life); -} + //Lifeset AALifeSet::AALifeSet(int _id, MTGCardInstance * _source, Targetable * _target, WParsedInt * life, ManaCost * _cost, int doTap, @@ -1636,9 +1630,9 @@ AAOnlyOne * AAOnlyOne::clone() const } //Random Discard -AARandomDiscarder::AARandomDiscarder(int _id, MTGCardInstance * card, Targetable * _target,WParsedInt * nbcards,string nbcardsStr, ManaCost * _cost, +AARandomDiscarder::AARandomDiscarder(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost, int _tap, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), nbcards(nbcards),nbcardsStr(nbcardsStr) + ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), nbcardsStr(nbcardsStr) { } @@ -1658,13 +1652,13 @@ int AARandomDiscarder::resolve() } - RefreshedNbcards = NEW WParsedInt(nbcardsStr, NULL, source); - for (int i = 0; i < RefreshedNbcards->intValue; i++) + WParsedInt numCards(nbcardsStr, NULL, source); + for (int i = 0; i < numCards.intValue; i++) { player->game->discardRandom(player->game->hand, source); } } - delete RefreshedNbcards; + return 1; } @@ -1677,13 +1671,8 @@ AARandomDiscarder * AARandomDiscarder::clone() const { AARandomDiscarder * a = NEW AARandomDiscarder(*this); a->isClone = 1; - a->nbcards = NEW WParsedInt(nbcardsStr, NULL, source); return a; } -AARandomDiscarder ::~AARandomDiscarder () -{ -SAFE_DELETE(nbcards); -} // Shuffle AAShuffle::AAShuffle(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, int _tap, int who) : diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 112b3b755..cec12311d 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -2004,11 +2004,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { d = s.substr(start + 1); } - WParsedInt * damage = NEW WParsedInt(d, spell, card); + Targetable * t = NULL; if (spell) t = spell->getNextTarget(); - MTGAbility * a = NEW AADamager(id, card, t,damage, d, NULL, 0, who); + MTGAbility * a = NEW AADamager(id, card, t, d, NULL, 0, who); a->oneShot = 1; return a; } @@ -2100,11 +2100,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { life_s = s.substr(start + 1); } - WParsedInt * life = NEW WParsedInt(life_s, spell, card); Targetable * t = NULL; if (spell) t = spell->getNextTarget(); - MTGAbility * a = NEW AALifer(id, card, t,life_s, life, NULL, 0, who); + MTGAbility * a = NEW AALifer(id, card, t, life_s, NULL, 0, who); a->oneShot = 1; return a; } @@ -2136,11 +2135,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { nbcardsStr = s.substr(start + 1); } - WParsedInt * nbcards = NEW WParsedInt(nbcardsStr, spell, card); Targetable * t = NULL; if (spell) t = spell->getNextTarget(); - MTGAbility * a = NEW AADrawer(id, card, t, NULL,nbcards ,nbcardsStr, 0, who); + MTGAbility * a = NEW AADrawer(id, card, t, NULL,nbcardsStr, 0, who); a->oneShot = 1; return a; } @@ -2183,11 +2181,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { nbcardsStr = s.substr(start + 1); } - WParsedInt * nbcards = NEW WParsedInt(nbcardsStr, spell, card); Targetable * t = NULL; if (spell) t = spell->getNextTarget(); - MTGAbility * a = NEW AADepleter(id, card, t,nbcards ,nbcardsStr, NULL, 0, who); + MTGAbility * a = NEW AADepleter(id, card, t ,nbcardsStr, NULL, 0, who); a->oneShot = 1; return a; } @@ -2253,12 +2250,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { nbcardsStr = s.substr(start + 1); } - WParsedInt * nbcards = NEW WParsedInt(nbcardsStr, spell, card); - Targetable * t = NULL; if (spell) t = spell->getNextPlayerTarget(); - MTGAbility * a = NEW AARandomDiscarder(id, card, t, nbcards,nbcardsStr, NULL, 0, who); + MTGAbility * a = NEW AARandomDiscarder(id, card, t, nbcardsStr, NULL, 0, who); a->oneShot = 1; return a; } @@ -2742,7 +2737,7 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode, Targ if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; if (AALifer * abi = dynamic_cast(a)) - return abi->life > 0 ? BAKA_EFFECT_GOOD : BAKA_EFFECT_BAD; + return abi->getLife() > 0 ? BAKA_EFFECT_GOOD : BAKA_EFFECT_BAD; if (AAAlterPoison * abi = dynamic_cast(a)) return abi->poison > 0 ? BAKA_EFFECT_GOOD : BAKA_EFFECT_BAD; if (dynamic_cast (a)) diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index 3fcf2ca21..af9fc15ea 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -8,6 +8,7 @@ #include "MTGGameZones.h" #include "MTGAbility.h" +#include "AllAbilities.h" #include "DeckManager.h" #include "AIPlayer.h" #include @@ -199,7 +200,7 @@ void Rules::addExtraRules() != GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode != GAME_TYPE_STORY)//stupid protections to keep this out of mimor and other game modes. { - handsize = a->nbcardAmount; + handsize = ((AADrawer *)a)->getNumCards(); ((AIPlayer *) p)->forceBestAbilityUse = true; ((AIPlayer *) p)->agressivity += 100; hand->OptimizedHand(p,handsize, 3, 1, 3);//easy decks get a major boost, open hand is 2lands,1 creature under 3 mana,3spells under 3 mana. @@ -209,7 +210,7 @@ void Rules::addExtraRules() != GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode != GAME_TYPE_STORY)//stupid protections to keep this out of mimor and other game modes. { - handsize = a->nbcardAmount; + handsize = ((AADrawer *)a)->getNumCards(); hand->OptimizedHand(p,handsize, 1, 0, 2);//give the Ai deck a tiny boost by giving it 1 land and 2 spells under 3 manacost. }else if (( !p->isAI() && Optimizedhandcheat) && a->aType == MTGAbility::STANDARD_DRAW && p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode