From 8a49d2af5171d6b360f6451c6e09cbd41ff652ff Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Sat, 4 Dec 2010 18:25:59 +0000 Subject: [PATCH] moved the gaurds i introduced in r2734 into the function selectAbility() as a static bool as suggested by jean, its much cleaner this way. --- projects/mtg/include/AIPlayer.h | 1 - projects/mtg/src/AIMomirPlayer.cpp | 12 ++------ projects/mtg/src/AIPlayer.cpp | 46 +++++++++--------------------- projects/mtg/src/ActionStack.cpp | 2 +- 4 files changed, 17 insertions(+), 44 deletions(-) diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index c6d8bb06f..3f9492130 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -59,7 +59,6 @@ protected: //Variables used by Test suite MTGCardInstance * nextCardToPlay; queue clickstream; - bool mFindingAbility;//is Ai currently looking for an activated ability to use? void tapLandsForMana(ManaCost * cost, MTGCardInstance * card = NULL); int orderBlockers(); int combatDamages(); diff --git a/projects/mtg/src/AIMomirPlayer.cpp b/projects/mtg/src/AIMomirPlayer.cpp index 8710804ac..847deb7af 100644 --- a/projects/mtg/src/AIMomirPlayer.cpp +++ b/projects/mtg/src/AIMomirPlayer.cpp @@ -85,11 +85,7 @@ int AIMomirPlayer::computeActions() int currentGamePhase = g->getCurrentGamePhase(); if (g->isInterrupting == this) { // interrupting - if (!mFindingAbility)//if not looking for an activated ability to use, then go ahead and look now. - { - mFindingAbility = true; - selectAbility(); - } + selectAbility(); return 1; } else if (p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) @@ -123,11 +119,7 @@ int AIMomirPlayer::computeActions() break; } case Constants::MTG_PHASE_SECONDMAIN: - if (!mFindingAbility)//if not looking for an activated ability to use, then go ahead and look now. - { - mFindingAbility = true; - selectAbility(); - } + selectAbility(); return 1; break; default: diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index f50122397..99f0a85c5 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -43,7 +43,6 @@ AIPlayer::AIPlayer(MTGDeck * deck, string file, string fileSmall) : agressivity = 50; forceBestAbilityUse = false; Checked = false; - mFindingAbility = false; playMode = Player::MODE_AI; } @@ -594,6 +593,14 @@ int AIPlayer::createAbilityTargets(MTGAbility * a, MTGCardInstance * c, map ranking; list::iterator it; GameObserver * g = GameObserver::GetInstance(); @@ -646,7 +653,7 @@ int AIPlayer::selectAbility() if (a && a != it2->first) delete (it2->first); } } - mFindingAbility = false; + mFindingAbility = false;//ok to start looking again. return 1; } @@ -1127,11 +1134,6 @@ int AIPlayerBaka::computeActions() { GameObserver * g = GameObserver::GetInstance(); Player * p = g->currentPlayer; - mFindingAbility = false; - //set to false at start of compute actions, - //Ai will then selectAbility often before this function is done running - //each time setting it to true until the end of selectAbility() function is reached - //this prevents overlaps of selectAbility function. if (!(g->currentlyActing() == this)) return 0; if (g->mLayers->actionLayer()->menuObject) { @@ -1142,11 +1144,7 @@ int AIPlayerBaka::computeActions() int currentGamePhase = g->getCurrentGamePhase(); if (g->isInterrupting == this) { // interrupting - if (!mFindingAbility)//if not looking for an activated ability to use, then go ahead and look now. - { - mFindingAbility = true; - selectAbility(); - } + selectAbility(); return 1; } else if (p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) @@ -1167,11 +1165,7 @@ int AIPlayerBaka::computeActions() potential = true; } nextCardToPlay = FindCardToPlay(currentMana, "land"); - if (!mFindingAbility)//if not looking for an activated ability to use, then go ahead and look now. - { - mFindingAbility = true; - selectAbility(); - } + selectAbility(); //look for the most expensive creature we can afford if (castrestrictedspell == 0 && nospellinstant == 0) { @@ -1205,11 +1199,7 @@ int AIPlayerBaka::computeActions() } if (!nextCardToPlay) { - if (!mFindingAbility)//if not looking for an activated ability to use, then go ahead and look now. - { - mFindingAbility = true; - selectAbility(); - } + selectAbility(); } } } @@ -1257,11 +1247,7 @@ int AIPlayerBaka::computeActions() } else { - if (!mFindingAbility)//if not looking for an activated ability to use, then go ahead and look now. - { - mFindingAbility = true; - selectAbility(); - } + selectAbility(); } if (p->getManaPool()->getConvertedCost() > 0 && Checked == false)//not the best thing ever, but allows the Ai a chance to double check if its mana pool has something before moving on, atleast one time. { @@ -1277,11 +1263,7 @@ int AIPlayerBaka::computeActions() Checked = false; break; default: - if (!mFindingAbility)//if not looking for an activated ability to use, then go ahead and look now. - { - mFindingAbility = true; - selectAbility(); - } + selectAbility(); break; } } diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index 33284ea1b..4dc4c8d58 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -903,7 +903,7 @@ bool ActionStack::CheckUserInput(JButton key) { mCurr = n; mObjects[mCurr]->Entering(); - DebugTrace ("ACTIONSTACK UP TO mCurr = " << mCurr); + DebugTrace("ACTIONSTACK UP TO mCurr = " << mCurr); } } return true;