Revision: 4875
Author: pankdm
Date: Tue Oct 8 23:18:42 2013 UTC
Log: Refactored FizzleToZone
Get rid of common code
Better naming of zone (where we put spell after countering)
More generic syntax: fizzleto(X) where X in [hand, exile, librarytop]
which will give more flexibility later
http://code.google.com/p/wagic/source/detail?r=4875
Modified:
/trunk/projects/mtg/bin/Res/sets/primitives/mtg.txt
/trunk/projects/mtg/include/ActionStack.h
/trunk/projects/mtg/include/AllAbilities.h
/trunk/projects/mtg/src/ActionStack.cpp
/trunk/projects/mtg/src/AllAbilities.cpp
/trunk/projects/mtg/src/MTGAbility.cpp
=======================================
--- /trunk/projects/mtg/bin/Res/sets/primitives/mtg.txt Tue Oct 8 23:18:32
2013 UTC
+++ /trunk/projects/mtg/bin/Res/sets/primitives/mtg.txt Tue Oct 8 23:18:42
2013 UTC
File is too large to display a diff.
=======================================
--- /trunk/projects/mtg/include/ActionStack.h Tue Oct 8 23:17:43 2013 UTC
+++ /trunk/projects/mtg/include/ActionStack.h Tue Oct 8 23:18:42 2013 UTC
@@ -194,6 +194,14 @@
DONT_INTERRUPT_ALL = 2
} InterruptDecision;
+ typedef enum
+ {
+ PUT_IN_GRAVEARD,
+ PUT_IN_HAND,
+ PUT_IN_LIBRARY_TOP,
+ PUT_IN_EXILE
+ } FizzleMode;
+
protected:
JQuadPtr pspIcons[8];
InterruptDecision interruptDecision[2];
@@ -216,8 +224,7 @@
int getPreviousIndex(Interruptible * next, int type = 0, int state =
0 , int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int
state = 0 , int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state =
0 , int display = -1);
- void Fizzle(Interruptible * action);
- void Fizzle(Interruptible * action, int targetZone); //Overloaded
fizzle (0 - 3: graveyard, hand, exile, librarytop)
+ void Fizzle(Interruptible * action, FizzleMode fizzleMode =
PUT_IN_GRAVEARD);
Interruptible * getAt(int id);
void cancelInterruptOffer(InterruptDecision cancelMode =
DONT_INTERRUPT, bool log = true);
void endOfInterruption(bool log = true);
=======================================
--- /trunk/projects/mtg/include/AllAbilities.h Tue Oct 8 23:17:43 2013 UTC
+++ /trunk/projects/mtg/include/AllAbilities.h Tue Oct 8 23:18:42 2013 UTC
@@ -1112,23 +1112,15 @@
class AAFizzler: public ActivatedAbility
{
+public:
+ ActionStack::FizzleMode fizzleMode; // action to do after fizzling
-public:
AAFizzler(GameObserver* observer, int _id, MTGCardInstance * card,
Spell * _target, ManaCost * _cost = NULL);
int resolve();
const char * getMenuText();
AAFizzler* clone() const;
};
-class AAOFizzler: public AAFizzler
-{
-public:
- AAOFizzler( GameObserver* observer, int _id, MTGCardInstance * card,
Spell * _target, int tgtZone, ManaCost * _cost );
- int targetZone;
- int resolve();
- AAOFizzler* clone() const;
-};
-
/*
Generic classes
*/
=======================================
--- /trunk/projects/mtg/src/ActionStack.cpp Tue Oct 8 23:17:43 2013 UTC
+++ /trunk/projects/mtg/src/ActionStack.cpp Tue Oct 8 23:18:42 2013 UTC
@@ -1150,22 +1150,8 @@
return 1;
}
-void ActionStack::Fizzle(Interruptible * action)
-{
- if (!action)
- {
- DebugTrace("ACTIONSTACK ==ERROR==: action is NULL in
ActionStack::Fizzle");
- return;
- }
- if (action->type == ACTION_SPELL)
- {
- Spell * spell = (Spell *) action;
- spell->source->controller()->game->putInGraveyard(spell->source);
- }
- action->state = RESOLVED_NOK;
-}
-
-void ActionStack::Fizzle(Interruptible * action,int targetZone)
+// Fizzle action and put it in targetZone
+void ActionStack::Fizzle(Interruptible * action, FizzleMode fizzleMode)
{
if (!action)
{
@@ -1175,17 +1161,17 @@
if (action->type == ACTION_SPELL)
{
Spell * spell = (Spell *) action;
- switch ( targetZone ) {
- case 0:
+ switch (fizzleMode) {
+ case PUT_IN_GRAVEARD:
spell->source->controller()->game->putInGraveyard(spell->source);
break;
- case 1:
+ case PUT_IN_HAND:
spell->source->controller()->game->putInHand(spell->source);
break;
- case 2:
+ case PUT_IN_EXILE:
spell->source->controller()->game->putInExile(spell->source);
break;
- case 3:
+ case PUT_IN_LIBRARY_TOP:
spell->source->controller()->game->putInLibrary(spell->source);
break;
}
=======================================
--- /trunk/projects/mtg/src/AllAbilities.cpp Tue Oct 8 23:17:43 2013 UTC
+++ /trunk/projects/mtg/src/AllAbilities.cpp Tue Oct 8 23:18:42 2013 UTC
@@ -1314,52 +1314,16 @@
{
aType = MTGAbility::STANDARD_FIZZLER;
target = _target;
-}
-int AAFizzler::resolve()
-{
- ActionStack * stack = game->mLayers->stackLayer();
- //the next section helps Ai correctly recieve its targets for this effect
- if(!target && source->target)
- {
- //ai is casting a spell from its hand to fizzle.
- target = stack->getActionElementFromCard(source->target);
- }
- else if(MTGCardInstance * cTarget = dynamic_cast<MTGCardInstance
*>(target))
- {
- //ai targeted using an ability on a card to fizzle.
- target = stack->getActionElementFromCard(cTarget);
- }
- Spell * sTarget = (Spell *) target;
- MTGCardInstance* sCard = NULL;
- if(sTarget)
- sCard = sTarget->source;
- if(!sCard || !sTarget || sCard->has(Constants::NOFIZZLE))
- return 0;
- stack->Fizzle(sTarget);
- return 1;
-}
-
-const char * AAFizzler::getMenuText()
-{
- return "Fizzle";
-}
-
-AAFizzler* AAFizzler::clone() const
-{
- return NEW AAFizzler(*this);
+ // by default we put the spell to graveyard after fizzling
+ fizzleMode = ActionStack::PUT_IN_GRAVEARD;
}
-AAOFizzler::AAOFizzler( GameObserver* observer, int _id, MTGCardInstance *
card, Spell * _target, int tgtZone, ManaCost * _cost ) :
-AAFizzler( observer, _id, card, _target, _cost )
-{
- targetZone = tgtZone;
-}
-int AAOFizzler::resolve()
+int AAFizzler::resolve()
{
ActionStack * stack = game->mLayers->stackLayer();
//the next section helps Ai correctly recieve its targets for this
effect
- if(!target && source->target)
+ if (!target && source->target)
{
//ai is casting a spell from its hand to fizzle.
target = stack->getActionElementFromCard(source->target);
@@ -1371,19 +1335,23 @@
}
Spell * sTarget = (Spell *) target;
MTGCardInstance* sCard = NULL;
- if(sTarget)
- sCard = sTarget->source;
- if(!sCard || !sTarget || sCard->has(Constants::NOFIZZLE))
+ if (sTarget)
+ sCard = sTarget->source;
+ if (!sCard || !sTarget || sCard->has(Constants::NOFIZZLE))
return 0;
- stack->Fizzle(sTarget, targetZone);
+ stack->Fizzle(sTarget, fizzleMode);
return 1;
}
-AAOFizzler* AAOFizzler::clone() const
+
+const char * AAFizzler::getMenuText()
{
- return NEW AAOFizzler(*this);
+ return "Fizzle";
}
-
+AAFizzler* AAFizzler::clone() const
+{
+ return NEW AAFizzler(*this);
+}
// BanishCard implementations
// Bury
=======================================
--- /trunk/projects/mtg/src/MTGAbility.cpp Tue Oct 8 23:17:43 2013 UTC
+++ /trunk/projects/mtg/src/MTGAbility.cpp Tue Oct 8 23:18:42 2013 UTC
@@ -2015,46 +2015,41 @@
return a;
}
- //Fizzle (counterspell...)
- found = s.find("fizzle");
- if (found != string::npos)
+ // Fizzle (counterspell...) and put to zone
+ // This should always be above "fizzle" section
+ vector<string> splitFizzle = parseBetween(s, "fizzleto(", ")");
+ if (splitFizzle.size())
{
+ // currently only hand, exile and library are supported
+ string zone = splitFizzle[1];
+ ActionStack::FizzleMode fizzleMode = ActionStack::PUT_IN_GRAVEARD;
+ if (zone == "hand")
+ {
+ fizzleMode = ActionStack::PUT_IN_HAND;
+ } else if (zone == "exile")
+ {
+ fizzleMode = ActionStack::PUT_IN_EXILE;
+ } else if (zone == "librarytop")
+ {
+ fizzleMode = ActionStack::PUT_IN_LIBRARY_TOP;
+ }
Spell * starget = NULL;
if (spell)
starget = spell->getNextSpellTarget();
- MTGAbility * a = NEW AAFizzler(observer, id, card, starget);
+ AAFizzler * a = NEW AAFizzler(observer, id, card, starget);
+ a->fizzleMode = fizzleMode;
a->oneShot = 1;
return a;
}
- found = s.find("fizhand");
- if (found != string::npos)
- {
- Spell * starget = NULL;
- if (spell)
- starget = spell->getNextSpellTarget();
- MTGAbility * a = NEW AAOFizzler( observer, id, card, starget, 1,
NULL );
- a->oneShot = 1;
- return a;
- }
- //Fizzle to exile
- found = s.find("fizexile");
- if (found != string::npos)
- {
- Spell * starget = NULL;
- if (spell)
- starget = spell->getNextSpellTarget();
- MTGAbility * a = NEW AAOFizzler( observer, id, card, starget, 2,
NULL );
- a->oneShot = 1;
- return a;
- }
- //Fizzle to top of library
- found = s.find("fizlibrary");
+
+ //Fizzle (counterspell...)
+ found = s.find("fizzle");
if (found != string::npos)
{
Spell * starget = NULL;
if (spell)
starget = spell->getNextSpellTarget();
- MTGAbility * a = NEW AAOFizzler( observer, id, card, starget, 3,
NULL );
+ MTGAbility * a = NEW AAFizzler(observer, id, card, starget);
a->oneShot = 1;
return a;
}