From 6b89899d1b3c8200da4e4db48e3414a6f75903fd Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Sun, 13 Feb 2011 11:23:51 +0000 Subject: [PATCH] Erwan - deprecated the following keywords (see list below for new usage) -- cantcreaturecast => auto=maxCast(creature)0 -- cantspellcast => auto=maxCast(*)0 -- onlyonecast => auto=maxCast(*)1 -- bothcantcast => auto=maxCast(*)0 auto=maxCast(*)0 opponent -- bothnocreature => auto=maxCast(creature)0 auto=maxCast(creature)0 opponent -- oneboth => auto=maxCast(*)1 auto=maxCast(*)1 opponent Strangely enough, I couldn't find most of these keywords in mtg.txt? I also removed variables such as "spellCastedThisTurn" and stuff like that... now if you want to know how many spells were cast in one turn by a given player, use player->game->stack->seenThisTurn("*"). seenThisTurn can take a string representing a TargetChooser, or better, a TargetChooser. I can't guarantee I didn't break anything, but the test suite passes and the AI seems to run ok --- projects/mtg/include/MTGDefinitions.h | 25 ++++---- projects/mtg/include/MTGGameZones.h | 6 +- projects/mtg/include/Player.h | 8 --- projects/mtg/src/AIPlayer.cpp | 83 ++++++++++++------------- projects/mtg/src/GameObserver.cpp | 89 +-------------------------- projects/mtg/src/MTGAbility.cpp | 2 +- projects/mtg/src/MTGDefinitions.cpp | 20 +++--- projects/mtg/src/MTGGameZones.cpp | 9 +++ projects/mtg/src/MTGRules.cpp | 67 +------------------- projects/mtg/src/Player.cpp | 8 --- 10 files changed, 75 insertions(+), 242 deletions(-) diff --git a/projects/mtg/include/MTGDefinitions.h b/projects/mtg/include/MTGDefinitions.h index e503dba08..8429645c4 100644 --- a/projects/mtg/include/MTGDefinitions.h +++ b/projects/mtg/include/MTGDefinitions.h @@ -147,13 +147,13 @@ class Constants CANTLOSE = 59, CANTLIFELOSE = 60, CANTMILLLOSE = 61, - CANTCASTCREATURE = 62, - CANTCAST = 63, - CANTCASTTWO = 64, - STORM = 65, - BOTHCANTCAST = 66, - BOTHNOCREATURE = 67, - ONLYONEBOTH = 68, + SNOWWALK = 62, + NONBASICWALK = 63, + STRONG = 64, + STORM = 65, + PHASING = 66, + SPLITSECOND = 67, + WEAK = 68, AFFINITYARTIFACTS = 69, AFFINITYPLAINS = 70, AFFINITYFOREST = 71, @@ -176,14 +176,11 @@ SNOWPLAINSWALK = 87, SNOWMOUNTAINWALK = 88, SNOWISLANDWALK = 89, SNOWSWAMPWALK = 90, -SNOWWALK = 91, -NONBASICWALK = 92, -STRONG = 93, -WEAK = 94, -PHASING = 95, -SPLITSECOND = 96, - NB_BASIC_ABILITIES = 97, + + + + NB_BASIC_ABILITIES = 91, RARITY_S = 'S', //Special Rarity diff --git a/projects/mtg/include/MTGGameZones.h b/projects/mtg/include/MTGGameZones.h index a3f6bb7ae..1eb9a1aed 100644 --- a/projects/mtg/include/MTGGameZones.h +++ b/projects/mtg/include/MTGGameZones.h @@ -97,7 +97,11 @@ class MTGGameZone { int hasName(string value); int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise int hasX(); - int seenThisTurn(TargetChooser * tc); //How many cards matching a TargetChooser have been put in this zone during the turn + + //How many cards matching a TargetChooser have been put in this zone during the turn + int seenThisTurn(TargetChooser * tc); + int seenThisTurn(string s); + void setOwner(Player * player); MTGCardInstance * lastCardDrawn; static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target); diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index bc25d55dc..40ac434e1 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -28,14 +28,6 @@ public: JQuadPtr mAvatar; int playMode; bool nomaxhandsize; - int castedspellsthisturn; - bool onlyonecast; - int castcount; - bool castrestrictedcreature; - bool castrestrictedspell; - bool onlyoneboth; - bool bothrestrictedspell; - bool bothrestrictedcreature; bool isPoisoned; MTGPlayerCards * game; string deckFile; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 7bb398d47..7ca842b5b 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -1211,20 +1211,21 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty { if (!CanHandleCost(card->getManaCost())) continue; - if (card->hasType(Subtypes::TYPE_CREATURE) && this->castrestrictedcreature && this->castrestrictedspell ) - continue; - if (card->hasType(Subtypes::TYPE_ENCHANTMENT) && this->castrestrictedspell ) - continue; - if (card->hasType(Subtypes::TYPE_ARTIFACT) && this->castrestrictedspell ) - continue; - if (card->hasType(Subtypes::TYPE_SORCERY) && this->castrestrictedspell ) - continue; - if (card->hasType(Subtypes::TYPE_INSTANT) && this->castrestrictedspell ) - continue; - if (card->hasType(Subtypes::TYPE_LAND) && (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY)) - continue; + + if (card->hasType(Subtypes::TYPE_LAND)) + { + if (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY) + continue; + } + else + { + if (game->playRestrictions->canPutIntoZone(card, game->stack) == PlayRestriction::CANT_PLAY) + continue; + } + if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name)) continue; + int currentCost = card->getManaCost()->getConvertedCost(); int hasX = card->getManaCost()->hasX(); if ((currentCost > maxCost || hasX) && pMana->canAfford(card->getManaCost())) @@ -1329,22 +1330,19 @@ int AIPlayerBaka::computeActions() //if theres mana i can use there then potential is true. ipotential = true; } - //look for an instant of ability to interupt with - if((castrestrictedspell == false)&& - (onlyonecast == false || castcount < 2)) - { - if (!nextCardToPlay) - { - nextCardToPlay = FindCardToPlay(icurrentMana, "instant"); - if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) - nextCardToPlay = NULL; - } - if (!nextCardToPlay) - { - selectAbility(); - } + + if (!nextCardToPlay) + { + nextCardToPlay = FindCardToPlay(icurrentMana, "instant"); + if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) + nextCardToPlay = NULL; } + if (!nextCardToPlay) + { + selectAbility(); + } + if (icurrentMana != NULL) delete (icurrentMana); if (nextCardToPlay) @@ -1380,26 +1378,23 @@ int AIPlayerBaka::computeActions() } nextCardToPlay = FindCardToPlay(currentMana, "land"); selectAbility(); - //look for the most expensive creature we can afford - if((castrestrictedspell == false)&& - (onlyonecast == false || castcount < 2)) + + //look for the most expensive creature we can afford. If not found, try enchantment, then artifact, etc... + const char* types[] = {"creature", "enchantment", "artifact", "sorcery", "instant"}; + int count = 0; + while (!nextCardToPlay && count < 5) { - - const char* types[] = {"creature", "enchantment", "artifact", "sorcery", "instant"}; - int count = 0; - while (!nextCardToPlay && count < 5) - { - nextCardToPlay = FindCardToPlay(currentMana, types[count]); - if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) - nextCardToPlay = NULL; - count++; - } - - if (!nextCardToPlay) - { - selectAbility(); - } + nextCardToPlay = FindCardToPlay(currentMana, types[count]); + if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) + nextCardToPlay = NULL; + count++; } + + if (!nextCardToPlay) + { + selectAbility(); + } + if (currentMana != NULL) delete (currentMana); if (nextCardToPlay) diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 98e34fc14..afc72a672 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -108,9 +108,6 @@ void GameObserver::nextGamePhase() if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN) { cleanupPhase(); - currentPlayer->castedspellsthisturn = 0; - currentPlayer->opponent()->castedspellsthisturn = 0; - currentPlayer->castcount = 0; currentPlayer->damageCount = 0; currentPlayer->preventable = 0; currentPlayer->isPoisoned = false; @@ -519,8 +516,6 @@ void GameObserver::gameStateBasedEffects() Player * p = players[i]; MTGGameZone * z = players[i]->game->inPlay; int nbcards = z->nb_cards; - p->onlyonecast = false; - p->opponent()->onlyonecast = false; //------------------------------ if (z->hasAbility(Constants::NOMAXHAND)) { @@ -530,79 +525,7 @@ void GameObserver::gameStateBasedEffects() { p->nomaxhandsize = false; } - //------------------------------ - if (z->hasAbility(Constants::CANTCASTCREATURE)) - { - p->castrestrictedcreature = true; - } - else - { - p->castrestrictedcreature = false; - } - //------------------------------ - if (z->hasAbility(Constants::CANTCAST)) - { - p->castrestrictedspell = true; - } - else - { - p->castrestrictedspell = false; - } - //------------------------------ - if (z->hasAbility(Constants::CANTCASTTWO)) - { - p->onlyonecast = true; - } - else - { - p->onlyonecast = false; - } - //-------------------------------- - if (z->hasAbility(Constants::BOTHCANTCAST)) - { - p->bothrestrictedspell = true; - } - else - { - p->bothrestrictedspell = false; - } - //--------------------------------- - if (z->hasAbility(Constants::BOTHNOCREATURE)) - { - p->bothrestrictedcreature = true; - } - else - { - p->bothrestrictedcreature = false; - } - //----------------------------------- - if (z->hasAbility(Constants::ONLYONEBOTH)) - { - p->onlyoneboth = true; - } - else - { - p->onlyoneboth = false; - } - //------------------------------------ - if (players[0]->bothrestrictedcreature) - players[1]->castrestrictedcreature = true; - //------------------------------------ - if (players[0]->bothrestrictedspell) - players[1]->castrestrictedspell = true; - //------------------------------------ - if (players[0]->onlyoneboth) - players[1]->onlyoneboth = true; - //------------------------------------ - if (players[1]->bothrestrictedcreature) - players[0]->castrestrictedcreature = true; - //------------------------------------ - if (players[1]->bothrestrictedspell) - players[0]->castrestrictedspell = true; - //------------------------------------ - if (players[1]->onlyoneboth) - players[0]->onlyoneboth = true; - //------------------------------------ + ///////////////////////////////////////////////// //handle end of turn effects while we're at it.// ///////////////////////////////////////////////// @@ -627,11 +550,6 @@ void GameObserver::gameStateBasedEffects() c->wasDealtDamage = false; c->damageToController = false; c->damageToOpponent = false; - if (c->has(Constants::ONLYONEBOTH)) - { - c->controller()->castcount = 0; - c->controller()->opponent()->castcount = 0; - } } for (int t = 0; t < nbcards; t++) @@ -668,11 +586,6 @@ void GameObserver::gameStateBasedEffects() if (z->nb_cards == 0) { p->nomaxhandsize = false; - if (!p->bothrestrictedcreature && !p->opponent()->bothrestrictedcreature) - p->castrestrictedcreature = false; - if (!p->bothrestrictedspell && !p->opponent()->bothrestrictedspell) - p->castrestrictedspell = false; - p->onlyonecast = false; } ////////////////////////// // Check auras on a card// diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 2ce97c8ae..1a2ce7dd1 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -65,7 +65,7 @@ int MTGAbility::allowedToCast(MTGCardInstance * card,Player * player) return 0; break; case CASTED_A_SPELL: - if(player->castedspellsthisturn < 1) + if(player->game->stack->seenThisTurn("*") < 1) return 0; break; case ONE_OF_AKIND: diff --git a/projects/mtg/src/MTGDefinitions.cpp b/projects/mtg/src/MTGDefinitions.cpp index fa5118dc9..213d64b48 100644 --- a/projects/mtg/src/MTGDefinitions.cpp +++ b/projects/mtg/src/MTGDefinitions.cpp @@ -89,13 +89,13 @@ const char* Constants::MTGBasicAbilities[] = { "cantlose", "cantlifelose", "cantmilllose", - "cantcreaturecast", - "cantspellcast", - "onlyonecast", + "snowlandwalk", + "nonbasiclandwalk", + "strong",//cant be blocked by creature with less power "storm", - "bothcantcast", - "bothnocreature", - "oneboth", + "phasing", + "split second", + "weak",//cant block creatures with more power "affinityartifacts", "affinityplains", "affinityforests", @@ -117,13 +117,7 @@ const char* Constants::MTGBasicAbilities[] = { "snowplainslandwalk", "snowmountainlandwalk", "snowislandlandwalk", - "snowswamplandwalk", - "snowlandwalk", - "nonbasiclandwalk", - "strong",//cant be blocked by creature with less power - "weak",//cant block creatures with more power - "phasing", - "split second", + "snowswamplandwalk" }; map Constants::MTGBasicAbilitiesMap; diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index b29680538..65c1628db 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -626,6 +626,15 @@ int MTGGameZone::seenThisTurn(TargetChooser * tc) return count; } +int MTGGameZone::seenThisTurn(string targetChooserDefinition) +{ + TargetChooserFactory tcf; + TargetChooser *tc = tcf.createTargetChooser(targetChooserDefinition, NULL); + int result = seenThisTurn(tc); + delete(tc); + return result; +} + void MTGGameZone::cleanupPhase() { diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index e2b8e808b..31f60af72 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -64,20 +64,6 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana) #ifdef WIN32 cost->Dump(); #endif - if (player->castrestrictedspell) - { - return 0; - } - if (player->onlyonecast && player->castcount >= 1) - { - return 0; - } - - if (player->castrestrictedcreature && card->hasType("creature")) - { - return 0; - } - //cost of card. if (playerMana->canAfford(cost)) { @@ -155,27 +141,15 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card) { spell = game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, spellCost, payResult, 0); game->targetChooser = NULL; - player->castedspellsthisturn += 1; - player->opponent()->castedspellsthisturn += 1; - if (player->onlyonecast) - { - player->castcount += 1; - } } else { spell = game->mLayers->stackLayer()->addSpell(copy, NULL, spellCost, payResult, 0); - player->castedspellsthisturn += 1; - player->opponent()->castedspellsthisturn += 1; - if (player->onlyonecast) - { - player->castcount += 1; - } } if (card->has(Constants::STORM)) { - int storm = player->castedspellsthisturn; + int storm = player->game->stack->seenThisTurn("*"); ManaCost * spellCost = player->getManaPool(); for (int i = storm; i > 1; i--) { @@ -272,19 +246,6 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * ManaCost * cost = card->getManaCost(); cost->Dump(); #endif - if (player->castrestrictedspell && !card->hasType("land")) - { - return 0; - } - if (player->onlyonecast && player->castcount >= 1) - { - return 0; - } - - if (player->castrestrictedcreature && card->hasType("creature")) - { - return 0; - } //cost of card. if (playerMana->canAfford(alternateManaCost)) { @@ -350,14 +311,10 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter copy->alternateCostPaid[alternateCostType] = 1; Spell * spell = game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, spellCost, alternateCostType, 0); game->targetChooser = NULL; - player->castedspellsthisturn += 1; - player->opponent()->castedspellsthisturn += 1; - if (player->onlyonecast ) - player->castcount += 1; if (card->has(Constants::STORM)) { - int storm = player->castedspellsthisturn; + int storm = player->game->stack->seenThisTurn("*"); for (int i = storm; i > 1; i--) { game->mLayers->stackLayer()->addSpell(copy, NULL, playerMana, alternateCostType, 1); @@ -595,19 +552,6 @@ int MTGMorphCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana) #ifdef WIN32 cost->Dump(); #endif - if (player->castrestrictedspell && !card->hasType("land")) - { - return 0; - } - if (player->onlyonecast && player->castcount >= 1) - { - return 0; - } - - if (player->castrestrictedcreature && card->hasType("creature")) - { - return 0; - } //cost of card. if (morph && playerMana->canAfford(morph)) { @@ -672,13 +616,6 @@ int MTGMorphCostRule::reactToClick(MTGCardInstance * card) copy->isMorphed = true; copy->power = 2; copy->toughness = 2; - player->castedspellsthisturn += 1; - player->opponent()->castedspellsthisturn += 1; - if (player->onlyonecast) - { - player->castcount += 1; - - } if (!card->has(Constants::STORM)) { copy->X = spell->computeX(copy); diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index ba8aa834c..48ac0c529 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -13,14 +13,6 @@ Damageable(20) deckFileSmall = fileSmall; manaPool = NEW ManaPool(this); nomaxhandsize = false; - castedspellsthisturn = 0; - castrestrictedspell = false; - castrestrictedcreature = false; - bothrestrictedspell = false; - bothrestrictedcreature = false; - onlyoneboth = false; - onlyonecast = false; - castcount = 0; poisonCount = 0; damageCount = 0; preventable = 0;