- 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

@@ -3101,7 +3101,8 @@ public:
{ {
for (int i = 0; i < nbOpponents; i++) for (int i = 0; i < nbOpponents; i++)
{ {
opponents[i]->destroy(); if (game->isInPlay(opponents[i]))
opponents[i]->destroy();
} }
} }
} }

View File

@@ -24,7 +24,6 @@ using namespace std;
class GameObserver{ class GameObserver{
protected: protected:
int reaction;
static GameObserver * mInstance; static GameObserver * mInstance;
MTGCardInstance * cardWaitingForTargets; MTGCardInstance * cardWaitingForTargets;
queue<WEvent *> eventsQueue; queue<WEvent *> eventsQueue;
@@ -54,7 +53,7 @@ class GameObserver{
TargetChooser * getCurrentTargetChooser(); TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action); void stackObjectClicked(Interruptible * action);
void cardClick(MTGCardInstance * card,Targetable * _object = NULL ); int cardClick(MTGCardInstance * card,Targetable * _object = NULL );
int getCurrentGamePhase(); int getCurrentGamePhase();
void nextCombatStep(); void nextCombatStep();
void userRequestNextGamePhase(); void userRequestNextGamePhase();

View File

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

View File

@@ -43,7 +43,6 @@ GameObserver::GameObserver(Player * _players[], int _nb_players)
targetChooser = NULL; targetChooser = NULL;
cardWaitingForTargets = NULL; cardWaitingForTargets = NULL;
waitForExtraPayment = NULL; waitForExtraPayment = NULL;
reaction = 0;
gameOver = NULL; gameOver = NULL;
phaseRing = NULL; phaseRing = NULL;
replacementEffects = NEW ReplacementEffects(); replacementEffects = NEW ReplacementEffects();
@@ -518,13 +517,13 @@ void GameObserver::stackObjectClicked(Interruptible * action)
} }
else else
{ {
reaction = mLayers->actionLayer()->isReactingToTargetClick(action); int reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
if (reaction == -1) if (reaction == -1)
mLayers->actionLayer()->reactToTargetClick(action); mLayers->actionLayer()->reactToTargetClick(action);
} }
} }
void GameObserver::cardClick(MTGCardInstance * card, Targetable * object) int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
{ {
Player * clickedPlayer = NULL; Player * clickedPlayer = NULL;
if (!card) if (!card)
@@ -558,7 +557,7 @@ void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
if (result == TARGET_OK_FULL) if (result == TARGET_OK_FULL)
card = cardWaitingForTargets; card = cardWaitingForTargets;
else else
return; return 1;
} }
if (waitForExtraPayment) if (waitForExtraPayment)
@@ -572,17 +571,24 @@ void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
mLayers->actionLayer()->reactToClick(waitForExtraPayment->action, waitForExtraPayment->source); mLayers->actionLayer()->reactToClick(waitForExtraPayment->action, waitForExtraPayment->source);
waitForExtraPayment = NULL; waitForExtraPayment = NULL;
} }
return; return 1;
} }
int reaction = 0;
if (ORDER == combatStep) if (ORDER == combatStep)
{ {
card->defenser->raiseBlockerRankOrder(card); card->defenser->raiseBlockerRankOrder(card);
return; return 1;
} }
if (card && card->paymenttype <= 0) if (card)
{//card played as normal. {
//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 /* 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 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) if (targetChooser)
{ {
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY); MTGAbility * a = mLayers->actionLayer()->getAbility(card->paymenttype);
a->reactToClick(card); return a->reactToClick(card);
return;
} }
reaction = mLayers->actionLayer()->isReactingToClick(card); reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1) 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 else
{//this handles abilities on a menu...not just when card is being played {//this handles abilities on a menu...not just when card is being played
reaction = mLayers->actionLayer()->isReactingToTargetClick(object); reaction = mLayers->actionLayer()->isReactingToTargetClick(object);
if (reaction == -1) if (reaction == -1)
mLayers->actionLayer()->reactToTargetClick(object); return mLayers->actionLayer()->reactToTargetClick(object);
} }
if (reaction == -1)
return;
if (!card) if (!card)
return; return 0;
//Current player's hand //Current player's hand
if (currentPlayer->game->hand->hasCard(card) && currentGamePhase == Constants::MTG_PHASE_CLEANUP 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) if (reaction == 1)
{ {
mLayers->actionLayer()->reactToClick(card); return mLayers->actionLayer()->reactToClick(card);
} }
else else
{ {
mLayers->actionLayer()->setMenuObject(object); mLayers->actionLayer()->setMenuObject(object);
return 1;
} }
} }
else if (card->isTapped() && card->controller() == currentPlayer) else if (card->isTapped() && card->controller() == currentPlayer)
{ {
untap(card); return untap(card);
} }
return 0;
} }
int GameObserver::untap(MTGCardInstance * card) int GameObserver::untap(MTGCardInstance * card)

View File

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

View File

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