- some code cleanup, as I am trying to figure out the root cause for issue 548
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-12-05 14:13:42 +00:00
parent 59864cbcb7
commit c7a17a0e57
6 changed files with 46 additions and 94 deletions

View File

@@ -605,14 +605,18 @@ int AIPlayer::createAbilityTargets(MTGAbility * a, MTGCardInstance * c, map<AIAc
int AIPlayer::selectAbility()
{
static bool mFindingAbility = false;
//this gaurd is put in place to prevent Ai from
static bool findingAbility = false;
//this guard is put in place to prevent Ai from
//ever running selectAbility() function WHILE its already doing so.
if (mFindingAbility)
// Break if this happens in debug mode. If this happens, it's actually a bug
assert(!findingAbility);
if (findingAbility)
{//is already looking kick me out of this function!
return 0;
}
mFindingAbility = true;//im looking now safely!
findingAbility = true;//im looking now safely!
map<AIAction *, int, CmpAbilities> ranking;
list<int>::iterator it;
GameObserver * g = GameObserver::GetInstance();
@@ -665,7 +669,7 @@ int AIPlayer::selectAbility()
if (a && a != it2->first) delete (it2->first);
}
}
mFindingAbility = false;//ok to start looking again.
findingAbility = false;//ok to start looking again.
return 1;
}
@@ -709,7 +713,7 @@ int AIPlayer::chooseTarget(TargetChooser * _tc, Player * forceTarget)
tc = gameObs->getCurrentTargetChooser();
}
if (!tc) return 0;
tc->initTargets(); //cleanup the targetchooser just in case.
if (!(gameObs->currentlyActing() == this)) return 0;
Player * target = forceTarget;

View File

@@ -43,7 +43,6 @@ GameObserver::GameObserver(Player * _players[], int _nb_players)
targetChooser = NULL;
cardWaitingForTargets = NULL;
waitForExtraPayment = NULL;
reaction = 0;
gameOver = NULL;
phaseRing = NULL;
replacementEffects = NEW ReplacementEffects();
@@ -518,13 +517,13 @@ void GameObserver::stackObjectClicked(Interruptible * action)
}
else
{
reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
int reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
if (reaction == -1)
mLayers->actionLayer()->reactToTargetClick(action);
}
}
void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
{
Player * clickedPlayer = NULL;
if (!card)
@@ -558,7 +557,7 @@ void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
if (result == TARGET_OK_FULL)
card = cardWaitingForTargets;
else
return;
return 1;
}
if (waitForExtraPayment)
@@ -572,17 +571,24 @@ void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
mLayers->actionLayer()->reactToClick(waitForExtraPayment->action, waitForExtraPayment->source);
waitForExtraPayment = NULL;
}
return;
return 1;
}
int reaction = 0;
if (ORDER == combatStep)
{
card->defenser->raiseBlockerRankOrder(card);
return;
return 1;
}
if (card && card->paymenttype <= 0)
{//card played as normal.
if (card)
{
//card played as normal, alternative cost, buyback, flashback, retrace.
//the varible "paymenttype = int" only serves one purpose, to tell this bug fix what menu item you clicked on...
// all alternative cost or play methods suffered from the fix because if the card contained "target="
// it would automatically force the play method to putinplayrule...even charge you the original mana cost.
/* Fix for Issue http://code.google.com/p/wagic/issues/detail?id=270
put into play is hopefully the only ability causing that kind of trouble
@@ -590,84 +596,23 @@ void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
*/
if (targetChooser)
{
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY);
a->reactToClick(card);
return;
MTGAbility * a = mLayers->actionLayer()->getAbility(card->paymenttype);
return a->reactToClick(card);
}
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1)
mLayers->actionLayer()->reactToClick(card);
return mLayers->actionLayer()->reactToClick(card);
}
/* added same fix for buyback and alternative cost, the varible "paymenttype = int" only serves one purpose, to tell this bug fix what menu item you clicked on...all alternative cost or play methods suffered from the fix because if the card contained "target=" it would automatically force the play method to putinplayrule...even charge you the original mana cost.*/
else if (card && card->paymenttype == 1)
{//this is alternitive cost
if (targetChooser)
{
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::ALTERNATIVE_COST);
a->reactToClick(card);
return;
}
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1)
mLayers->actionLayer()->reactToClick(card);
}
//--------------
else if (card && card->paymenttype == 2)
{//this is buyback
if (targetChooser)
{
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::BUYBACK_COST);
a->reactToClick(card);
return;
}
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1)
mLayers->actionLayer()->reactToClick(card);
}
//=====================
else if (card && card->paymenttype == 3)
{//this is Flashback
if (targetChooser)
{
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::FLASHBACK_COST);
a->reactToClick(card);
return;
}
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1)
mLayers->actionLayer()->reactToClick(card);
}
//=====================
else if (card && card->paymenttype == 4)
{//this is retrace
if (targetChooser)
{
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::RETRACE_COST);
a->reactToClick(card);
return;
}
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1)
mLayers->actionLayer()->reactToClick(card);
}
//=====================
else
{//this handles abilities on a menu...not just when card is being played
reaction = mLayers->actionLayer()->isReactingToTargetClick(object);
if (reaction == -1)
mLayers->actionLayer()->reactToTargetClick(object);
return mLayers->actionLayer()->reactToTargetClick(object);
}
if (reaction == -1)
return;
if (!card)
return;
return 0;
//Current player's hand
if (currentPlayer->game->hand->hasCard(card) && currentGamePhase == Constants::MTG_PHASE_CLEANUP
@@ -679,18 +624,21 @@ void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
{
if (reaction == 1)
{
mLayers->actionLayer()->reactToClick(card);
return mLayers->actionLayer()->reactToClick(card);
}
else
{
mLayers->actionLayer()->setMenuObject(object);
return 1;
}
}
else if (card->isTapped() && card->controller() == currentPlayer)
{
untap(card);
return untap(card);
}
return 0;
}
int GameObserver::untap(MTGCardInstance * card)

View File

@@ -120,7 +120,7 @@ void MTGCardInstance::initMTGCI()
equipment = NULL;
boughtback = 0;
flashedback = 0;
paymenttype = 0;
paymenttype = MTGAbility::PUT_INTO_PLAY;
reduxamount = 0;
summoningSickness = 1;
preventable = 0;

View File

@@ -307,7 +307,7 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card)
{
if (cost->alternative->isExtraPaymentSet())
{
card->paymenttype = 1;
card->paymenttype = MTGAbility::ALTERNATIVE_COST;
if (!game->targetListIsSet(card))
{
return 0;
@@ -317,7 +317,7 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card)
{
cost->alternative->setExtraCostsAction(this, card);
game->waitForExtraPayment = cost->alternative->extraCosts;
card->paymenttype = 1;
card->paymenttype = MTGAbility::ALTERNATIVE_COST;
return 0;
}
}
@@ -496,7 +496,7 @@ int MTGBuyBackRule::reactToClick(MTGCardInstance * card)
{
if (cost->BuyBack->isExtraPaymentSet())
{
card->paymenttype = 2;
card->paymenttype = MTGAbility::BUYBACK_COST;
if (!game->targetListIsSet(card))
{
return 0;
@@ -506,7 +506,7 @@ int MTGBuyBackRule::reactToClick(MTGCardInstance * card)
{
cost->BuyBack->setExtraCostsAction(this, card);
game->waitForExtraPayment = cost->BuyBack->extraCosts;
card->paymenttype = 2;
card->paymenttype = MTGAbility::BUYBACK_COST;
return 0;
}
}
@@ -680,7 +680,7 @@ int MTGFlashBackRule::reactToClick(MTGCardInstance * card)
{
if (cost->FlashBack->isExtraPaymentSet())
{
card->paymenttype = 3;
card->paymenttype = MTGAbility::FLASHBACK_COST;
if (!game->targetListIsSet(card))
{
return 0;
@@ -690,7 +690,7 @@ int MTGFlashBackRule::reactToClick(MTGCardInstance * card)
{
cost->FlashBack->setExtraCostsAction(this, card);
game->waitForExtraPayment = cost->FlashBack->extraCosts;
card->paymenttype = 3;
card->paymenttype = MTGAbility::FLASHBACK_COST;
return 0;
}
}
@@ -864,7 +864,7 @@ int MTGRetraceRule::reactToClick(MTGCardInstance * card)
{
if (cost->Retrace->isExtraPaymentSet())
{
card->paymenttype = 4;
card->paymenttype = MTGAbility::RETRACE_COST;
if (!game->targetListIsSet(card))
{
return 0;
@@ -874,7 +874,7 @@ int MTGRetraceRule::reactToClick(MTGCardInstance * card)
{
cost->Retrace->setExtraCostsAction(this, card);
game->waitForExtraPayment = cost->Retrace->extraCosts;
card->paymenttype = 4;
card->paymenttype = MTGAbility::RETRACE_COST;;
return 0;
}
}