No code change. Reformat code

This commit is contained in:
techdragon.nguyen@gmail.com
2010-12-11 22:42:48 +00:00
parent b3650bcccf
commit fe75493ffa
8 changed files with 2208 additions and 2018 deletions
+146 -148
View File
@@ -625,7 +625,7 @@ public:
int power; int power;
int toughness; int toughness;
string name; string name;
string menu; string menu;
AACounter(int id, MTGCardInstance * source, MTGCardInstance * target, const char * _name, int power, int toughness, int nb, AACounter(int id, MTGCardInstance * source, MTGCardInstance * target, const char * _name, int power, int toughness, int nb,
ManaCost * cost = NULL, int doTap = 0); ManaCost * cost = NULL, int doTap = 0);
@@ -1019,7 +1019,7 @@ public:
who = who; who = who;
tokenId = 0; tokenId = 0;
if (!multiplier) this->multiplier = NEW WParsedInt(1); if (!multiplier) this->multiplier = NEW WParsedInt(1);
//TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class; //TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class;
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++) for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++)
{ {
@@ -1192,8 +1192,8 @@ public:
ABasicAbilityModifier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int _modifier = 1) : ABasicAbilityModifier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int _modifier = 1) :
MTGAbility(_id, _source, _target), modifier(_modifier), ability(_ability) MTGAbility(_id, _source, _target), modifier(_modifier), ability(_ability)
{ {
aType = MTGAbility::STANDARDABILITYGRANT; aType = MTGAbility::STANDARDABILITYGRANT;
abilitygranted = ability; abilitygranted = ability;
} }
int addToGame() int addToGame()
@@ -1251,8 +1251,8 @@ public:
int _modifier = 1, int _tap = 1) : int _modifier = 1, int _tap = 1) :
TargetAbility(_id, _source, _cost, 0, _tap), modifier(_modifier), ability(_ability) TargetAbility(_id, _source, _cost, 0, _tap), modifier(_modifier), ability(_ability)
{ {
aType = MTGAbility::STANDARDABILITYGRANT; aType = MTGAbility::STANDARDABILITYGRANT;
abilitygranted = ability; abilitygranted = ability;
nbTargets = 0; nbTargets = 0;
tc = _tc; tc = _tc;
if (!tc) tc = NEW CreatureTargetChooser(_source); if (!tc) tc = NEW CreatureTargetChooser(_source);
@@ -1325,8 +1325,8 @@ public:
AInstantBasicAbilityModifierUntilEOT(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int value) : AInstantBasicAbilityModifierUntilEOT(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int value) :
InstantAbility(_id, _source, _target), ability(_ability), value(value) InstantAbility(_id, _source, _target), ability(_ability), value(value)
{ {
aType = MTGAbility::STANDARDABILITYGRANT; aType = MTGAbility::STANDARDABILITYGRANT;
abilitygranted = ability; abilitygranted = ability;
} }
int addToGame() int addToGame()
@@ -1375,8 +1375,8 @@ public:
{ {
target = _target; target = _target;
ability = NEW AInstantBasicAbilityModifierUntilEOT(_id, _source, _target, _ability, _value); ability = NEW AInstantBasicAbilityModifierUntilEOT(_id, _source, _target, _ability, _value);
aType = MTGAbility::STANDARDABILITYGRANT; aType = MTGAbility::STANDARDABILITYGRANT;
abilitygranted = _ability; abilitygranted = _ability;
} }
int isReactingToClick(MTGCardInstance * card, ManaCost * cost = NULL) int isReactingToClick(MTGCardInstance * card, ManaCost * cost = NULL)
@@ -1430,7 +1430,7 @@ public:
ASpellCastLife(int id, MTGCardInstance * _source, CardDescriptor _trigger, ManaCost * _cost, int _life) : ASpellCastLife(int id, MTGCardInstance * _source, CardDescriptor _trigger, ManaCost * _cost, int _life) :
MTGAbility(id, _source), trigger(_trigger), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) MTGAbility(id, _source), trigger(_trigger), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL)
{ {
aType = MTGAbility::LIFER; aType = MTGAbility::LIFER;
} }
ASpellCastLife(int id, MTGCardInstance * _source, int color, ManaCost * _cost, int _life) : ASpellCastLife(int id, MTGCardInstance * _source, int color, ManaCost * _cost, int _life) :
MTGAbility(id, _source), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) MTGAbility(id, _source), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL)
@@ -2270,84 +2270,84 @@ public:
SAFE_DELETE(ability); SAFE_DELETE(ability);
} }
const char * getMenuText() const char * getMenuText()
{ {
if (AAMover * move = dynamic_cast<AAMover *>(ability)) if (AAMover * move = dynamic_cast<AAMover *>(ability))
{ {
MTGGameZone * dest = move->destinationZone(); MTGGameZone * dest = move->destinationZone();
GameObserver * g = GameObserver::GetInstance(); GameObserver * g = GameObserver::GetInstance();
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
// Move card to hand // Move card to hand
if (dest == g->players[i]->game->hand) if (dest == g->players[i]->game->hand)
{ {
if (tc->targetsZone(g->players[i]->game->inPlay)) if (tc->targetsZone(g->players[i]->game->inPlay))
{ {
return "Bounce"; return "Bounce";
} }
else if (tc->targetsZone(g->players[i]->game->graveyard)) else if (tc->targetsZone(g->players[i]->game->graveyard))
{ {
return "Reclaim"; return "Reclaim";
} }
else if (tc->targetsZone(g->opponent()->game->hand)) else if (tc->targetsZone(g->opponent()->game->hand))
{ {
return "Steal"; return "Steal";
} }
} }
// Move card to graveyard // Move card to graveyard
else if (dest == g->players[i]->game->graveyard) else if (dest == g->players[i]->game->graveyard)
{ {
if (tc->targetsZone(g->players[i]->game->inPlay)) if (tc->targetsZone(g->players[i]->game->inPlay))
{ {
return "Sacrifice"; return "Sacrifice";
} }
else if (tc->targetsZone(g->players[i]->game->hand)) else if (tc->targetsZone(g->players[i]->game->hand))
{ {
return "Discard"; return "Discard";
} }
else if (tc->targetsZone(g->opponent()->game->hand)) else if (tc->targetsZone(g->opponent()->game->hand))
{ {
return "Opponent Discards"; return "Opponent Discards";
} }
} }
// move card to library // move card to library
else if (dest == g->players[i]->game->library) else if (dest == g->players[i]->game->library)
{ {
if (tc->targetsZone(g->players[i]->game->graveyard)) if (tc->targetsZone(g->players[i]->game->graveyard))
{ {
return "Recycle"; return "Recycle";
} }
else else
{ {
return "Put in Library"; return "Put in Library";
} }
} }
// move card to battlefield // move card to battlefield
else if (dest == g->players[i]->game->battlefield && tc->targetsZone(g->players[i]->game->graveyard)) else if (dest == g->players[i]->game->battlefield && tc->targetsZone(g->players[i]->game->graveyard))
{ {
return "Reanimate"; return "Reanimate";
} }
// move card in play ( different from battlefield? ) // move card in play ( different from battlefield? )
else if (dest == g->players[i]->game->inPlay) else if (dest == g->players[i]->game->inPlay)
{ {
return "Put in Play"; return "Put in Play";
} }
// move card into exile // move card into exile
else if (dest == g->players[i]->game->exile) else if (dest == g->players[i]->game->exile)
{ {
return "Exile"; return "Exile";
} }
// move card from Library // move card from Library
else if (tc->targetsZone(g->players[i]->game->library)) else if (tc->targetsZone(g->players[i]->game->library))
{ {
return "Fetch"; return "Fetch";
} }
} }
return "Move"; return "Move";
} }
else else
return ability->getMenuText(); return ability->getMenuText();
} }
ALord * clone() const ALord * clone() const
{ {
@@ -3175,8 +3175,8 @@ public:
{ {
for (int i = 0; i < nbOpponents; i++) for (int i = 0; i < nbOpponents; i++)
{ {
if (game->isInPlay(opponents[i])) if (game->isInPlay(opponents[i]))
opponents[i]->destroy(); opponents[i]->destroy();
} }
} }
} }
@@ -3288,7 +3288,7 @@ public:
list<int> oldcolors; list<int> oldcolors;
list<int> oldtypes; list<int> oldtypes;
bool remove; bool remove;
string menu; string menu;
ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities); ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities);
int addToGame(); int addToGame();
@@ -3305,7 +3305,7 @@ public:
list<int> abilities; list<int> abilities;
list<int> types; list<int> types;
list<int> colors; list<int> colors;
string menu; string menu;
AForeverTransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities); AForeverTransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities);
int addToGame(); int addToGame();
@@ -3344,12 +3344,12 @@ public:
class ASwapPTUEOT: public InstantAbility class ASwapPTUEOT: public InstantAbility
{ {
public: public:
ASwapPT * ability; ASwapPT * ability;
ASwapPTUEOT(int id, MTGCardInstance * source, MTGCardInstance * target); ASwapPTUEOT(int id, MTGCardInstance * source, MTGCardInstance * target);
int resolve(); int resolve();
const char * getMenuText(); const char * getMenuText();
ASwapPTUEOT * clone() const; ASwapPTUEOT * clone() const;
~ASwapPTUEOT(); ~ASwapPTUEOT();
}; };
//becomes ability //becomes ability
@@ -4027,61 +4027,61 @@ public:
AErgRaiders * a = NEW AErgRaiders(*this); AErgRaiders * a = NEW AErgRaiders(*this);
a->isClone = 1; a->isClone = 1;
return a; return a;
} }
}; };
//Fastbond //Fastbond
class AFastbond: public TriggeredAbility class AFastbond: public TriggeredAbility
{ {
public: public:
int alreadyPlayedALand; int alreadyPlayedALand;
int previous; int previous;
AFastbond(int _id, MTGCardInstance * card) : AFastbond(int _id, MTGCardInstance * card) :
TriggeredAbility(_id, card) TriggeredAbility(_id, card)
{ {
alreadyPlayedALand = 0; alreadyPlayedALand = 0;
if (source->controller()->landsPlayerCanStillPlay == 0) if (source->controller()->landsPlayerCanStillPlay == 0)
{ {
alreadyPlayedALand = 1; alreadyPlayedALand = 1;
source->controller()->landsPlayerCanStillPlay += 1; source->controller()->landsPlayerCanStillPlay += 1;
source->controller()->canPutLandsIntoPlay = true; source->controller()->canPutLandsIntoPlay = true;
} }
previous = source->controller()->landsPlayerCanStillPlay; previous = source->controller()->landsPlayerCanStillPlay;
} }
void Update(float dt) void Update(float dt)
{ {
if (newPhase != currentPhase && newPhase == Constants::MTG_PHASE_UNTAP) if (newPhase != currentPhase && newPhase == Constants::MTG_PHASE_UNTAP)
{ {
alreadyPlayedALand = 0; alreadyPlayedALand = 0;
} }
TriggeredAbility::Update(dt); TriggeredAbility::Update(dt);
} }
int trigger() int trigger()
{ {
if (source->controller()->landsPlayerCanStillPlay == 0 && previous >= 1) if (source->controller()->landsPlayerCanStillPlay == 0 && previous >= 1)
{ {
previous = 0; previous = 0;
source->controller()->canPutLandsIntoPlay = true; source->controller()->canPutLandsIntoPlay = true;
source->controller()->landsPlayerCanStillPlay += 1; source->controller()->landsPlayerCanStillPlay += 1;
if (alreadyPlayedALand) return 1; if (alreadyPlayedALand) return 1;
alreadyPlayedALand = 1; alreadyPlayedALand = 1;
return 0; return 0;
} }
previous = source->controller()->landsPlayerCanStillPlay; previous = source->controller()->landsPlayerCanStillPlay;
return 0; return 0;
} }
int resolve() int resolve()
{ {
game->mLayers->stackLayer()->addDamage(source, source->controller(), 1); game->mLayers->stackLayer()->addDamage(source, source->controller(), 1);
game->mLayers->stackLayer()->resolve(); game->mLayers->stackLayer()->resolve();
return 1; return 1;
} }
virtual ostream& toString(ostream& out) const virtual ostream& toString(ostream& out) const
{ {
out << "AFastbond ::: alreadyPlayedALand : " << alreadyPlayedALand << " ; previous : " << previous << " ("; out << "AFastbond ::: alreadyPlayedALand : " << alreadyPlayedALand << " ; previous : " << previous << " (";
return TriggeredAbility::toString(out) << ")"; return TriggeredAbility::toString(out) << ")";
@@ -5222,10 +5222,8 @@ public:
// utility functions // utility functions
void PopulateColorIndexVector( list<int>& colors, const string& colorsString, char delimiter = ','); void PopulateColorIndexVector(list<int>& colors, const string& colorsString, char delimiter = ',');
void PopulateAbilityIndexVector( list<int>& abilities, const string& abilitiesString, char delimiter = ','); void PopulateAbilityIndexVector(list<int>& abilities, const string& abilitiesString, char delimiter = ',');
void PopulateSubtypesIndexVector( list<int>& subtypes, const string& subtypesString, char delimiter = ' '); void PopulateSubtypesIndexVector(list<int>& subtypes, const string& subtypesString, char delimiter = ' ');
#endif #endif
+218 -173
View File
@@ -9,140 +9,172 @@
#include "WEvent.h" #include "WEvent.h"
#include "CardSelector.h" #include "CardSelector.h"
class OtherAbilitiesEventReceiver:public MTGAbility{ class OtherAbilitiesEventReceiver: public MTGAbility
{
public: public:
int testDestroy(); int testDestroy();
int receiveEvent(WEvent * event); int receiveEvent(WEvent * event);
OtherAbilitiesEventReceiver(int _id); OtherAbilitiesEventReceiver(int _id);
OtherAbilitiesEventReceiver * clone() const; OtherAbilitiesEventReceiver * clone() const;
}; };
class MTGPutInPlayRule:public MTGAbility{ class MTGPutInPlayRule: public MTGAbility
public: {
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); public:
int reactToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int testDestroy(); int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
MTGPutInPlayRule(int _id); virtual ostream& toString(ostream& out) const;
const char * getMenuText(){return "Play Card Normally";} MTGPutInPlayRule(int _id);
virtual MTGPutInPlayRule * clone() const; const char * getMenuText()
{
return "Play Card Normally";
}
virtual MTGPutInPlayRule * clone() const;
}; };
class MTGAlternativeCostRule:public MTGAbility{ class MTGAlternativeCostRule: public MTGAbility
public: {
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); public:
int reactToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int testDestroy(); int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
MTGAlternativeCostRule(int _id); virtual ostream& toString(ostream& out) const;
const char * getMenuText(){return "Pay Alternative Cost";} MTGAlternativeCostRule(int _id);
virtual MTGAlternativeCostRule * clone() const; const char * getMenuText()
{
return "Pay Alternative Cost";
}
virtual MTGAlternativeCostRule * clone() const;
}; };
class MTGBuyBackRule:public MTGAbility{ class MTGBuyBackRule: public MTGAbility
public: {
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); public:
int reactToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int testDestroy(); int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
MTGBuyBackRule(int _id); virtual ostream& toString(ostream& out) const;
const char * getMenuText(){return "Cast And Buy Back";} MTGBuyBackRule(int _id);
virtual MTGBuyBackRule * clone() const; const char * getMenuText()
{
return "Cast And Buy Back";
}
virtual MTGBuyBackRule * clone() const;
}; };
class MTGFlashBackRule:public MTGAbility{ class MTGFlashBackRule: public MTGAbility
public: {
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); public:
int reactToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int testDestroy(); int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
MTGFlashBackRule(int _id); virtual ostream& toString(ostream& out) const;
const char * getMenuText(){return "Flash Back";} MTGFlashBackRule(int _id);
virtual MTGFlashBackRule * clone() const; const char * getMenuText()
{
return "Flash Back";
}
virtual MTGFlashBackRule * clone() const;
}; };
class MTGRetraceRule:public MTGAbility{ class MTGRetraceRule: public MTGAbility
public: {
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); public:
int reactToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int testDestroy(); int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
MTGRetraceRule(int _id); virtual ostream& toString(ostream& out) const;
const char * getMenuText(){return "Retrace";} MTGRetraceRule(int _id);
virtual MTGRetraceRule * clone() const; const char * getMenuText()
{
return "Retrace";
}
virtual MTGRetraceRule * clone() const;
}; };
class MTGAttackRule:public MTGAbility, public Limitor{ class MTGAttackRule: public MTGAbility, public Limitor
public: {
virtual bool select(Target*); public:
virtual bool greyout(Target*); virtual bool select(Target*);
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); virtual bool greyout(Target*);
int reactToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int testDestroy(); int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
MTGAttackRule(int _id); virtual ostream& toString(ostream& out) const;
const char * getMenuText(){return "Attacker";} MTGAttackRule(int _id);
int receiveEvent(WEvent * event); const char * getMenuText()
virtual MTGAttackRule * clone() const; {
return "Attacker";
}
int receiveEvent(WEvent * event);
virtual MTGAttackRule * clone() const;
}; };
/* handles combat trigger send recieve events*/ /* handles combat trigger send recieve events*/
class MTGCombatTriggersRule:public MTGAbility{ class MTGCombatTriggersRule: public MTGAbility
public: {
MTGCombatTriggersRule(int _id); public:
int receiveEvent(WEvent * event); MTGCombatTriggersRule(int _id);
virtual ostream& toString(ostream& out) const; int receiveEvent(WEvent * event);
int testDestroy(); virtual ostream& toString(ostream& out) const;
virtual MTGCombatTriggersRule * clone() const; int testDestroy();
virtual MTGCombatTriggersRule * clone() const;
}; };
class MTGBlockRule:public MTGAbility{ class MTGBlockRule: public MTGAbility
public: {
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); public:
int reactToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int testDestroy(); int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
MTGBlockRule(int _id); virtual ostream& toString(ostream& out) const;
const char * getMenuText(){return "Blocker";} MTGBlockRule(int _id);
virtual MTGBlockRule * clone() const; const char * getMenuText()
{
return "Blocker";
}
virtual MTGBlockRule * clone() const;
}; };
/* Persist Rule */ /* Persist Rule */
class MTGPersistRule:public MTGAbility{ class MTGPersistRule: public MTGAbility
public: {
MTGPersistRule(int _id); public:
int receiveEvent(WEvent * event); MTGPersistRule(int _id);
virtual ostream& toString(ostream& out) const; int receiveEvent(WEvent * event);
int testDestroy(); virtual ostream& toString(ostream& out) const;
virtual MTGPersistRule * clone() const; int testDestroy();
virtual MTGPersistRule * clone() const;
}; };
//affinity rules //affinity rules
class MTGAffinityRule:public MTGAbility{ class MTGAffinityRule: public MTGAbility
public: {
MTGAffinityRule(int _id); public:
int receiveEvent(WEvent * event); MTGAffinityRule(int _id);
virtual ostream& toString(ostream& out) const; int receiveEvent(WEvent * event);
int testDestroy(); virtual ostream& toString(ostream& out) const;
virtual MTGAffinityRule * clone() const; int testDestroy();
virtual MTGAffinityRule * clone() const;
}; };
//unearths destruction if leaves play effect //unearths destruction if leaves play effect
class MTGUnearthRule:public MTGAbility{ class MTGUnearthRule: public MTGAbility
public: {
MTGUnearthRule(int _id); public:
int receiveEvent(WEvent * event); MTGUnearthRule(int _id);
virtual ostream& toString(ostream& out) const; int receiveEvent(WEvent * event);
int testDestroy(); virtual ostream& toString(ostream& out) const;
virtual MTGUnearthRule * clone() const; int testDestroy();
virtual MTGUnearthRule * clone() const;
}; };
class MTGTokensCleanup:public MTGAbility{ class MTGTokensCleanup: public MTGAbility
public: {
vector<MTGCardInstance *> list; public:
MTGTokensCleanup(int _id); vector<MTGCardInstance *> list;
int receiveEvent(WEvent * event); MTGTokensCleanup(int _id);
int testDestroy(); int receiveEvent(WEvent * event);
virtual MTGTokensCleanup * clone() const; int testDestroy();
virtual MTGTokensCleanup * clone() const;
}; };
/* /*
@@ -151,99 +183,112 @@ class MTGTokensCleanup:public MTGAbility{
* owners' graveyards. This is called the "legend rule." If only one of those permanents is * owners' graveyards. This is called the "legend rule." If only one of those permanents is
* legendary, this rule doesn't apply. * legendary, this rule doesn't apply.
*/ */
class MTGLegendRule:public ListMaintainerAbility{ class MTGLegendRule: public ListMaintainerAbility
public: {
MTGLegendRule(int _id); public:
int canBeInList(MTGCardInstance * card); MTGLegendRule(int _id);
int added(MTGCardInstance * card); int canBeInList(MTGCardInstance * card);
int removed(MTGCardInstance * card); int added(MTGCardInstance * card);
int testDestroy(); int removed(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const; int testDestroy();
virtual MTGLegendRule * clone() const; virtual ostream& toString(ostream& out) const;
virtual MTGLegendRule * clone() const;
}; };
class MTGMomirRule: public MTGAbility
class MTGMomirRule:public MTGAbility{ {
private: private:
int genRandomCreatureId(int convertedCost); int genRandomCreatureId(int convertedCost);
static vector<int> pool[20]; static vector<int> pool[20];
static int initialized; static int initialized;
int textAlpha; int textAlpha;
string text; string text;
public: public:
int alreadyplayed; int alreadyplayed;
MTGAllCards * collection; MTGAllCards * collection;
MTGCardInstance * genCreature(int id); MTGCardInstance * genCreature(int id);
int testDestroy(); int testDestroy();
void Update(float dt); void Update(float dt);
void Render(); void Render();
MTGMomirRule(int _id, MTGAllCards * _collection); MTGMomirRule(int _id, MTGAllCards * _collection);
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card); int reactToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card, int id); int reactToClick(MTGCardInstance * card, int id);
const char * getMenuText(){return "Momir";} const char * getMenuText()
virtual ostream& toString(ostream& out) const; {
virtual MTGMomirRule * clone() const; return "Momir";
}
virtual ostream& toString(ostream& out) const;
virtual MTGMomirRule * clone() const;
}; };
/* LifeLink */ /* LifeLink */
class MTGLifelinkRule:public MTGAbility{ class MTGLifelinkRule: public MTGAbility
public: {
MTGLifelinkRule(int _id); public:
MTGLifelinkRule(int _id);
int receiveEvent(WEvent * event); int receiveEvent(WEvent * event);
int testDestroy(); int testDestroy();
virtual ostream& toString(ostream& out) const; virtual ostream& toString(ostream& out) const;
virtual MTGLifelinkRule * clone() const; virtual MTGLifelinkRule * clone() const;
}; };
/* Deathtouch */ /* Deathtouch */
class MTGDeathtouchRule:public MTGAbility{ class MTGDeathtouchRule: public MTGAbility
public: {
MTGDeathtouchRule(int _id); public:
MTGDeathtouchRule(int _id);
int receiveEvent(WEvent * event); int receiveEvent(WEvent * event);
int testDestroy(); int testDestroy();
const char * getMenuText(){return "Deathtouch";} const char * getMenuText()
{
return "Deathtouch";
}
virtual MTGDeathtouchRule * clone() const; virtual MTGDeathtouchRule * clone() const;
}; };
/* HUD Display */ /* HUD Display */
class HUDString { class HUDString
{
public: public:
string value; string value;
float timestamp; float timestamp;
int quantity; int quantity;
HUDString(string s, float ts):value(s),timestamp(ts){quantity = 1;}; HUDString(string s, float ts) :
value(s), timestamp(ts)
{
quantity = 1;
}
;
}; };
class HUDDisplay:public MTGAbility{ class HUDDisplay: public MTGAbility
{
private: private:
list<HUDString *> events; list<HUDString *> events;
float timestamp; float timestamp;
float popdelay; float popdelay;
WFont * f; WFont * f;
float maxWidth; float maxWidth;
int addEvent(string s); int addEvent(string s);
public: public:
int testDestroy(); int testDestroy();
int receiveEvent(WEvent * event); int receiveEvent(WEvent * event);
void Update(float dt); void Update(float dt);
void Render(); void Render();
HUDDisplay(int _id); HUDDisplay(int _id);
~HUDDisplay(); ~HUDDisplay();
virtual HUDDisplay * clone() const; virtual HUDDisplay * clone() const;
}; };
#endif #endif
+21 -22
View File
@@ -22,27 +22,27 @@ public:
MODE_TEST_SUITE, MODE_HUMAN, MODE_AI, MODE_TEST_SUITE, MODE_HUMAN, MODE_AI,
}; };
JTexture * mAvatarTex; JTexture * mAvatarTex;
JQuad * mAvatar; JQuad * mAvatar;
int playMode; int playMode;
bool canPutLandsIntoPlay; bool canPutLandsIntoPlay;
int landsPlayerCanStillPlay; int landsPlayerCanStillPlay;
bool nomaxhandsize; bool nomaxhandsize;
int castedspellsthisturn; int castedspellsthisturn;
bool onlyonecast; bool onlyonecast;
int castcount; int castcount;
bool nocreatureinstant; bool nocreatureinstant;
bool nospellinstant; bool nospellinstant;
bool onlyoneinstant; bool onlyoneinstant;
bool castrestrictedcreature; bool castrestrictedcreature;
bool castrestrictedspell; bool castrestrictedspell;
bool onlyoneboth; bool onlyoneboth;
bool bothrestrictedspell; bool bothrestrictedspell;
bool bothrestrictedcreature; bool bothrestrictedcreature;
MTGPlayerCards * game; MTGPlayerCards * game;
string deckFile; string deckFile;
string deckFileSmall; string deckFileSmall;
string deckName; string deckName;
Player(MTGDeck * deck, string deckFile, string deckFileSmall); Player(MTGDeck * deck, string deckFile, string deckFileSmall);
virtual ~Player(); virtual ~Player();
@@ -71,7 +71,6 @@ public:
return 0; return 0;
} }
virtual int isAI() virtual int isAI()
{ {
return 0; return 0;
+1205 -1145
View File
File diff suppressed because it is too large Load Diff
+141 -101
View File
@@ -1,7 +1,6 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "AllAbilities.h" #include "AllAbilities.h"
//Activated Abilities //Activated Abilities
//Generic Activated Abilities //Generic Activated Abilities
@@ -21,19 +20,22 @@ int GenericActivatedAbility::resolve()
SAFE_DELETE(diff); SAFE_DELETE(diff);
//SAFE_DELETE(abilityCost); this line has been reported as a bug. removing it doesn't seem to break anything, although I didn't get any error in the test suite by leaving it either, so... leaving it for now as a comment, in case. //SAFE_DELETE(abilityCost); this line has been reported as a bug. removing it doesn't seem to break anything, although I didn't get any error in the test suite by leaving it either, so... leaving it for now as a comment, in case.
ability->target = target; //may have been updated... ability->target = target; //may have been updated...
if (ability) return ability->resolve(); if (ability)
return ability->resolve();
return 0; return 0;
} }
const char * GenericActivatedAbility::getMenuText() const char * GenericActivatedAbility::getMenuText()
{ {
if (ability) return ability->getMenuText(); if (ability)
return ability->getMenuText();
return "Error"; return "Error";
} }
int GenericActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana) int GenericActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{ {
if (limitPerTurn && counters >= limitPerTurn) return 0; if (limitPerTurn && counters >= limitPerTurn)
return 0;
return ActivatedAbility::isReactingToClick(card, mana); return ActivatedAbility::isReactingToClick(card, mana);
} }
@@ -48,8 +50,10 @@ void GenericActivatedAbility::Update(float dt)
int GenericActivatedAbility::testDestroy() int GenericActivatedAbility::testDestroy()
{ {
if (!activeZone) return ActivatedAbility::testDestroy(); if (!activeZone)
if (activeZone->hasCard(source)) return 0; return ActivatedAbility::testDestroy();
if (activeZone->hasCard(source))
return 0;
return 1; return 1;
} }
@@ -195,7 +199,8 @@ int AADepleter::resolve()
MTGLibrary * library = player->game->library; MTGLibrary * library = player->game->library;
for (int i = 0; i < nbcards; i++) for (int i = 0; i < nbcards; i++)
{ {
if (library->nb_cards) player->game->putInZone(library->cards[library->nb_cards - 1], library, player->game->graveyard); if (library->nb_cards)
player->game->putInZone(library->cards[library->nb_cards - 1], library, player->game->graveyard);
} }
} }
return 1; return 1;
@@ -249,7 +254,8 @@ AACounter::AACounter(int id, MTGCardInstance * source, MTGCardInstance * target,
ActivatedAbility(id, source, cost, 0, doTap), nb(nb), power(power), toughness(toughness), name(_name) ActivatedAbility(id, source, cost, 0, doTap), nb(nb), power(power), toughness(toughness), name(_name)
{ {
this->target = target; this->target = target;
if (name.find("Level")) aType = MTGAbility::STANDARD_LEVELUP; if (name.find("Level"))
aType = MTGAbility::STANDARD_LEVELUP;
menu = ""; menu = "";
} }
@@ -283,34 +289,34 @@ int AACounter::resolve()
const char* AACounter::getMenuText() const char* AACounter::getMenuText()
{ {
if(menu.size()) if (menu.size())
{ {
return menu.c_str(); return menu.c_str();
} }
char buffer[128]; char buffer[128];
if(name.size()) if (name.size())
{ {
string s = name; string s = name;
menu.append(s.c_str()); menu.append(s.c_str());
} }
if(power != 0 || toughness != 0) if (power != 0 || toughness != 0)
{ {
sprintf(buffer, " %i/%i", power,toughness); sprintf(buffer, " %i/%i", power, toughness);
menu.append(buffer); menu.append(buffer);
} }
menu.append(" Counter"); menu.append(" Counter");
if(nb != 1) if (nb != 1)
{ {
sprintf(buffer, ": %i", nb); sprintf(buffer, ": %i", nb);
menu.append(buffer); menu.append(buffer);
} }
sprintf(menuText, "%s",menu.c_str()); sprintf(menuText, "%s", menu.c_str());
return menuText; return menuText;
} }
AACounter * AACounter::clone() const AACounter * AACounter::clone() const
{ {
@@ -329,7 +335,8 @@ AAFizzler::AAFizzler(int _id, MTGCardInstance * card, Spell * _target, ManaCost
int AAFizzler::resolve() int AAFizzler::resolve()
{ {
Spell * _target = (Spell *) target; Spell * _target = (Spell *) target;
if (target && _target->source->has(Constants::NOFIZZLE)) return 0; if (target && _target->source->has(Constants::NOFIZZLE))
return 0;
game->mLayers->stackLayer()->Fizzle(_target); game->mLayers->stackLayer()->Fizzle(_target);
return 1; return 1;
} }
@@ -350,7 +357,8 @@ AAFizzler* AAFizzler::clone() const
AABanishCard::AABanishCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _banishmentType) : AABanishCard::AABanishCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _banishmentType) :
ActivatedAbility(_id, _source, NULL), banishmentType(_banishmentType) ActivatedAbility(_id, _source, NULL), banishmentType(_banishmentType)
{ {
if (_target) target = _target; if (_target)
target = _target;
} }
const char * AABanishCard::getMenuText() const char * AABanishCard::getMenuText()
@@ -577,7 +585,7 @@ AAFrozen * AAFrozen::clone() const
AALifer::AALifer(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * life, ManaCost * _cost, int _tap, int who) : AALifer::AALifer(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * life, ManaCost * _cost, int _tap, int who) :
ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), life(life) ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), life(life)
{ {
aType = MTGAbility::LIFER; aType = MTGAbility::LIFER;
} }
int AALifer::resolve() int AALifer::resolve()
@@ -657,10 +665,10 @@ AACloner::AACloner(int _id, MTGCardInstance * _source, MTGCardInstance * _target
string abilitiesStringList) : string abilitiesStringList) :
ActivatedAbility(_id, _source, _cost, 0, 0), who(who) ActivatedAbility(_id, _source, _cost, 0, 0), who(who)
{ {
aType = MTGAbility::CLONING; aType = MTGAbility::CLONING;
target = _target; target = _target;
source = _source; source = _source;
if ( abilitiesStringList.size() > 0 ) if (abilitiesStringList.size() > 0)
{ {
PopulateAbilityIndexVector(awith, abilitiesStringList); PopulateAbilityIndexVector(awith, abilitiesStringList);
PopulateColorIndexVector(colors, abilitiesStringList); PopulateColorIndexVector(colors, abilitiesStringList);
@@ -676,8 +684,10 @@ int AACloner::resolve()
MTGCardInstance * myClone = NULL; MTGCardInstance * myClone = NULL;
MTGCard* clone = (_target->isToken ? _target : GameApp::collection->getCardById(_target->getId())); MTGCard* clone = (_target->isToken ? _target : GameApp::collection->getCardById(_target->getId()));
if (who != 1) myClone = NEW MTGCardInstance(clone, source->controller()->game); if (who != 1)
if (who == 1) myClone = NEW MTGCardInstance(clone, source->controller()->opponent()->game); myClone = NEW MTGCardInstance(clone, source->controller()->game);
if (who == 1)
myClone = NEW MTGCardInstance(clone, source->controller()->opponent()->game);
if (who != 1) if (who != 1)
source->controller()->game->temp->addCard(myClone); source->controller()->game->temp->addCard(myClone);
else else
@@ -703,7 +713,8 @@ int AACloner::resolve()
const char * AACloner::getMenuText() const char * AACloner::getMenuText()
{ {
if (who == 1) return "Clone For Opponent"; if (who == 1)
return "Clone For Opponent";
return "Clone"; return "Clone";
} }
@@ -772,7 +783,8 @@ AAMoreLandPlz::~AAMoreLandPlz()
AAMover::AAMover(int _id, MTGCardInstance * _source, MTGCardInstance * _target, string dest, ManaCost * _cost, int doTap) : AAMover::AAMover(int _id, MTGCardInstance * _source, MTGCardInstance * _target, string dest, ManaCost * _cost, int doTap) :
ActivatedAbility(_id, _source, _cost, 0, doTap), destination(dest) ActivatedAbility(_id, _source, _cost, 0, doTap), destination(dest)
{ {
if (_target) target = _target; if (_target)
target = _target;
} }
MTGGameZone * AAMover::destinationZone() MTGGameZone * AAMover::destinationZone()
@@ -1019,7 +1031,7 @@ AATapper::AATapper(int id, MTGCardInstance * card, MTGCardInstance * _target, Ma
ActivatedAbility(id, card, _cost, 0, doTap) ActivatedAbility(id, card, _cost, 0, doTap)
{ {
target = _target; target = _target;
aType = MTGAbility::TAPPER; aType = MTGAbility::TAPPER;
} }
int AATapper::resolve() int AATapper::resolve()
@@ -1051,7 +1063,7 @@ AAUntapper::AAUntapper(int id, MTGCardInstance * card, MTGCardInstance * _target
ActivatedAbility(id, card, _cost, 0, doTap) ActivatedAbility(id, card, _cost, 0, doTap)
{ {
target = _target; target = _target;
aType = MTGAbility::UNTAPPER; aType = MTGAbility::UNTAPPER;
} }
int AAUntapper::resolve() int AAUntapper::resolve()
@@ -1156,7 +1168,6 @@ AAWinGame * AAWinGame::clone() const
return a; return a;
} }
//Generic Abilities //Generic Abilities
//May Abilities //May Abilities
@@ -1175,7 +1186,8 @@ void MayAbility::Update(float dt)
triggered = 1; triggered = 1;
if (TargetAbility * ta = dynamic_cast<TargetAbility *>(ability)) if (TargetAbility * ta = dynamic_cast<TargetAbility *>(ability))
{ {
if (!ta->tc->validTargetsExist()) return; if (!ta->tc->validTargetsExist())
return;
} }
game->mLayers->actionLayer()->setMenuObject(source, must); game->mLayers->actionLayer()->setMenuObject(source, must);
game->mLayers->stackLayer()->setIsInterrupting(source->controller()); game->mLayers->stackLayer()->setIsInterrupting(source->controller());
@@ -1189,15 +1201,19 @@ const char * MayAbility::getMenuText()
int MayAbility::testDestroy() int MayAbility::testDestroy()
{ {
if (!triggered) return 0; if (!triggered)
if (game->mLayers->actionLayer()->menuObject) return 0; return 0;
if (game->mLayers->actionLayer()->getIndexOf(mClone) != -1) return 0; if (game->mLayers->actionLayer()->menuObject)
return 0;
if (game->mLayers->actionLayer()->getIndexOf(mClone) != -1)
return 0;
return 1; return 1;
} }
int MayAbility::isReactingToTargetClick(Targetable * card) int MayAbility::isReactingToTargetClick(Targetable * card)
{ {
if (card == source) return 1; if (card == source)
return 1;
return 0; return 0;
} }
@@ -1226,7 +1242,8 @@ MayAbility::~MayAbility()
MultiAbility::MultiAbility(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, int _tap) : MultiAbility::MultiAbility(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, int _tap) :
ActivatedAbility(_id, card, _cost, 0, _tap) ActivatedAbility(_id, card, _cost, 0, _tap)
{ {
if (_target) target = _target; if (_target)
target = _target;
} }
int MultiAbility::Add(MTGAbility * ability) int MultiAbility::Add(MTGAbility * ability)
@@ -1240,9 +1257,11 @@ int MultiAbility::resolve()
vector<int>::size_type sz = abilities.size(); vector<int>::size_type sz = abilities.size();
for (unsigned int i = 0; i < sz; i++) for (unsigned int i = 0; i < sz; i++)
{ {
if (abilities[i] == NULL) continue; if (abilities[i] == NULL)
continue;
Targetable * backup = abilities[i]->target; Targetable * backup = abilities[i]->target;
if (target && target != source && abilities[i]->target == abilities[i]->source) abilities[i]->target = target; if (target && target != source && abilities[i]->target == abilities[i]->source)
abilities[i]->target = target;
abilities[i]->resolve(); abilities[i]->resolve();
abilities[i]->target = backup; abilities[i]->target = backup;
} }
@@ -1251,7 +1270,8 @@ int MultiAbility::resolve()
const char * MultiAbility::getMenuText() const char * MultiAbility::getMenuText()
{ {
if (abilities.size()) return abilities[0]->getMenuText(); if (abilities.size())
return abilities[0]->getMenuText();
return ""; return "";
} }
@@ -1275,7 +1295,6 @@ MultiAbility::~MultiAbility()
abilities.clear(); abilities.clear();
} }
//Generic Target Ability //Generic Target Ability
GenericTargetAbility::GenericTargetAbility(int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, GenericTargetAbility::GenericTargetAbility(int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a,
ManaCost * _cost, int _tap, int limit, int restrictions, MTGGameZone * dest) : ManaCost * _cost, int _tap, int limit, int restrictions, MTGGameZone * dest) :
@@ -1283,13 +1302,15 @@ GenericTargetAbility::GenericTargetAbility(int _id, MTGCardInstance * _source, T
{ {
ability = a; ability = a;
MTGAbility * core = AbilityFactory::getCoreAbility(a); MTGAbility * core = AbilityFactory::getCoreAbility(a);
if (dynamic_cast<AACopier *> (core)) tc->other = true; //http://code.google.com/p/wagic/issues/detail?id=209 (avoid inifinite loop) if (dynamic_cast<AACopier *> (core))
tc->other = true; //http://code.google.com/p/wagic/issues/detail?id=209 (avoid inifinite loop)
counters = 0; counters = 0;
} }
const char * GenericTargetAbility::getMenuText() const char * GenericTargetAbility::getMenuText()
{ {
if (!ability) return "Error"; if (!ability)
return "Error";
MTGAbility * core = AbilityFactory::getCoreAbility(ability); MTGAbility * core = AbilityFactory::getCoreAbility(ability);
if (AAMover * move = dynamic_cast<AAMover *>(core)) if (AAMover * move = dynamic_cast<AAMover *>(core))
@@ -1318,7 +1339,9 @@ const char * GenericTargetAbility::getMenuText()
{ {
return "Reanimate"; return "Reanimate";
} }
else if ((tc->targetsZone(g->players[i]->game->inPlay) && dest == g->players[i]->game->library) || dest == g->players[i]->game->library ) else if ((tc->targetsZone(g->players[i]->game->inPlay)
&& dest == g->players[i]->game->library)
|| dest == g->players[i]->game->library)
{ {
return "Put in Library"; return "Put in Library";
} }
@@ -1361,7 +1384,8 @@ int GenericTargetAbility::resolve()
int GenericTargetAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana) int GenericTargetAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{ {
if (limitPerTurn && counters >= limitPerTurn) return 0; if (limitPerTurn && counters >= limitPerTurn)
return 0;
return TargetAbility::isReactingToClick(card, mana); return TargetAbility::isReactingToClick(card, mana);
} }
@@ -1376,8 +1400,10 @@ void GenericTargetAbility::Update(float dt)
int GenericTargetAbility::testDestroy() int GenericTargetAbility::testDestroy()
{ {
if (!activeZone) return TargetAbility::testDestroy(); if (!activeZone)
if (activeZone->hasCard(source)) return 0; return TargetAbility::testDestroy();
if (activeZone->hasCard(source))
return 0;
return 1; return 1;
} }
@@ -1388,7 +1414,8 @@ GenericTargetAbility * GenericTargetAbility::clone() const
a->ability = ability->clone(); a->ability = ability->clone();
a->cost = NEW ManaCost(); a->cost = NEW ManaCost();
a->cost->copy(cost); a->cost->copy(cost);
if (tc) a->tc = tc->clone(); if (tc)
a->tc = tc->clone();
return a; return a;
} }
@@ -1461,19 +1488,23 @@ ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * t
PopulateColorIndexVector(colors, sabilities); PopulateColorIndexVector(colors, sabilities);
remove = false; remove = false;
if (stypes == "removesubtypes") remove = true; if (stypes == "removesubtypes")
remove = true;
if (stypes == "allsubtypes" || stypes == "removesubtypes") if (stypes == "allsubtypes" || stypes == "removesubtypes")
{ {
for (int i = Subtypes::LAST_TYPE + 1;; i++) for (int i = Subtypes::LAST_TYPE + 1;; i++)
{ {
string s = Subtypes::subtypesList->find(i); string s = Subtypes::subtypesList->find(i);
{ {
if (s == "") break; if (s == "")
if (s.find(" ") != string::npos) continue; break;
if (s == "Nothing" || s == "Swamp" || s == "Plains" || s == "Mountain" || s == "Forest" || s == "Island" || s if (s.find(" ") != string::npos)
== "Shrine" || s == "Basic" || s == "Colony" || s == "Desert" || s == "Dismiss" || s == "Equipment" || s continue;
== "Everglades" || s == "Grasslands" || s == "Lair" || s == "Level" || s == "Levelup" || s == "Mine" || s if (s == "Nothing" || s == "Swamp" || s == "Plains" || s == "Mountain" || s == "Forest"
== "Oasis" || s == "World" || s == "Aura") || s == "Island" || s == "Shrine" || s == "Basic" || s == "Colony" || s == "Desert"
|| s == "Dismiss" || s == "Equipment" || s == "Everglades" || s == "Grasslands" || s == "Lair"
|| s == "Level" || s == "Levelup" || s == "Mine" || s == "Oasis" || s == "World" || s == "Aura"
)
{//dont add "nothing" or land type to this card. {//dont add "nothing" or land type to this card.
} }
else else
@@ -1488,7 +1519,7 @@ ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * t
PopulateSubtypesIndexVector(types, stypes); PopulateSubtypesIndexVector(types, stypes);
} }
menu = stypes; menu = stypes;
} }
int ATransformer::addToGame() int ATransformer::addToGame()
@@ -1500,13 +1531,16 @@ int ATransformer::addToGame()
_target = _target->next; _target = _target->next;
for (int j = 0; j < Constants::MTG_NB_COLORS; j++) for (int j = 0; j < Constants::MTG_NB_COLORS; j++)
{ {
if (_target->hasColor(j)) oldcolors.push_back(j); if (_target->hasColor(j))
oldcolors.push_back(j);
} }
for (int j = Subtypes::LAST_TYPE + 1;; j++) for (int j = Subtypes::LAST_TYPE + 1;; j++)
{ {
string otypes = Subtypes::subtypesList->find(j); string otypes = Subtypes::subtypesList->find(j);
if (otypes == "") break; if (otypes == "")
if (otypes.find(" ") != string::npos) continue; break;
if (otypes.find(" ") != string::npos)
continue;
if (_target->hasSubtype(j)) if (_target->hasSubtype(j))
{ {
oldtypes.push_back(j); oldtypes.push_back(j);
@@ -1554,7 +1588,8 @@ int ATransformer::destroy()
list<int>::iterator it; list<int>::iterator it;
for (it = types.begin(); it != types.end(); it++) for (it = types.begin(); it != types.end(); it++)
{ {
if (remove == false) _target->removeType(*it); if (remove == false)
_target->removeType(*it);
} }
for (it = colors.begin(); it != colors.end(); it++) for (it = colors.begin(); it != colors.end(); it++)
{ {
@@ -1572,7 +1607,8 @@ int ATransformer::destroy()
{ {
for (it = oldtypes.begin(); it != oldtypes.end(); it++) for (it = oldtypes.begin(); it != oldtypes.end(); it++)
{ {
if (!_target->hasSubtype(*it)) _target->addType(*it); if (!_target->hasSubtype(*it))
_target->addType(*it);
} }
} }
} }
@@ -1608,7 +1644,7 @@ AForeverTransformer::AForeverTransformer(int id, MTGCardInstance * source, MTGCa
PopulateAbilityIndexVector(abilities, sabilities); PopulateAbilityIndexVector(abilities, sabilities);
PopulateColorIndexVector(colors, sabilities); PopulateColorIndexVector(colors, sabilities);
PopulateSubtypesIndexVector(types, stypes); PopulateSubtypesIndexVector(types, stypes);
menu = stypes; menu = stypes;
} }
int AForeverTransformer::addToGame() int AForeverTransformer::addToGame()
@@ -1673,7 +1709,7 @@ int ATransformerUEOT::resolve()
} }
const char * ATransformerUEOT::getMenuText() const char * ATransformerUEOT::getMenuText()
{ {
return ability->getMenuText(); return ability->getMenuText();
} }
ATransformerUEOT * ATransformerUEOT::clone() const ATransformerUEOT * ATransformerUEOT::clone() const
@@ -1707,7 +1743,7 @@ int ATransformerFOREVER::resolve()
const char * ATransformerFOREVER::getMenuText() const char * ATransformerFOREVER::getMenuText()
{ {
return ability->getMenuText(); return ability->getMenuText();
} }
ATransformerFOREVER * ATransformerFOREVER::clone() const ATransformerFOREVER * ATransformerFOREVER::clone() const
@@ -1740,7 +1776,7 @@ int ASwapPTUEOT::resolve()
const char * ASwapPTUEOT::getMenuText() const char * ASwapPTUEOT::getMenuText()
{ {
return ability->getMenuText(); return ability->getMenuText();
} }
ASwapPTUEOT * ASwapPTUEOT::clone() const ASwapPTUEOT * ASwapPTUEOT::clone() const
@@ -1766,7 +1802,7 @@ ABecomes::ABecomes(int id, MTGCardInstance * source, MTGCardInstance * target, s
PopulateAbilityIndexVector(abilities, sabilities); PopulateAbilityIndexVector(abilities, sabilities);
PopulateColorIndexVector(colors, sabilities); PopulateColorIndexVector(colors, sabilities);
PopulateSubtypesIndexVector(types, stypes); PopulateSubtypesIndexVector(types, stypes);
menu = stypes; menu = stypes;
} }
int ABecomes::addToGame() int ABecomes::addToGame()
@@ -1824,7 +1860,8 @@ const char * ABecomes::getMenuText()
ABecomes * ABecomes::clone() const ABecomes * ABecomes::clone() const
{ {
ABecomes * a = NEW ABecomes(*this); ABecomes * a = NEW ABecomes(*this);
if (a->wppt) a->wppt = NEW WParsedPT(*(a->wppt)); if (a->wppt)
a->wppt = NEW WParsedPT(*(a->wppt));
a->isClone = 1; a->isClone = 1;
return a; return a;
} }
@@ -1887,9 +1924,11 @@ int APreventDamageTypes::addToGame()
} }
TargetChooserFactory tcf; TargetChooserFactory tcf;
TargetChooser *toTc = tcf.createTargetChooser(to, source, this); TargetChooser *toTc = tcf.createTargetChooser(to, source, this);
if (toTc) toTc->targetter = NULL; if (toTc)
toTc->targetter = NULL;
TargetChooser *fromTc = tcf.createTargetChooser(from, source, this); TargetChooser *fromTc = tcf.createTargetChooser(from, source, this);
if (fromTc) fromTc->targetter = NULL; if (fromTc)
fromTc->targetter = NULL;
if (type != 1 && type != 2) if (type != 1 && type != 2)
{//not adding this creates a memory leak. {//not adding this creates a memory leak.
re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, DAMAGE_COMBAT); re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, DAMAGE_COMBAT);
@@ -1974,7 +2013,7 @@ AUpkeep::AUpkeep(int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _co
ActivatedAbility(_id, card, _cost, restrictions, _tap), NestedAbility(a), phase(_phase), once(_once) ActivatedAbility(_id, card, _cost, restrictions, _tap), NestedAbility(a), phase(_phase), once(_once)
{ {
paidThisTurn = 0; paidThisTurn = 0;
aType = MTGAbility::UPCOST; aType = MTGAbility::UPCOST;
} }
void AUpkeep::Update(float dt) void AUpkeep::Update(float dt)
@@ -1990,14 +2029,16 @@ void AUpkeep::Update(float dt)
{ {
ability->resolve(); ability->resolve();
} }
if (newPhase == phase + 1 && once) once = 2; if (newPhase == phase + 1 && once)
once = 2;
} }
ActivatedAbility::Update(dt); ActivatedAbility::Update(dt);
} }
int AUpkeep::isReactingToClick(MTGCardInstance * card, ManaCost * mana) int AUpkeep::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{ {
if (currentPhase != phase || paidThisTurn || once >= 2) return 0; if (currentPhase != phase || paidThisTurn || once >= 2)
return 0;
return ActivatedAbility::isReactingToClick(card, mana); return ActivatedAbility::isReactingToClick(card, mana);
} }
@@ -2028,48 +2069,47 @@ AUpkeep * AUpkeep::clone() const
AUpkeep::~AUpkeep() AUpkeep::~AUpkeep()
{ {
if (!isClone) if (!isClone)
SAFE_DELETE(ability); SAFE_DELETE(ability);
} }
// utility functions // utility functions
// Given a delimited string of abilities, add the ones to the list that are "Basic" MTG abilities // Given a delimited string of abilities, add the ones to the list that are "Basic" MTG abilities
void PopulateAbilityIndexVector( list<int>& abilities, const string& abilityStringList, char delimiter ) void PopulateAbilityIndexVector(list<int>& abilities, const string& abilityStringList, char delimiter)
{ {
vector<string> abilitiesList = split( abilityStringList, delimiter); vector<string> abilitiesList = split(abilityStringList, delimiter);
for ( vector<string>::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter) for (vector<string>::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter)
{ {
int abilityIndex = Constants::GetBasicAbilityIndex( *iter ); int abilityIndex = Constants::GetBasicAbilityIndex(*iter);
if (abilityIndex != -1) if (abilityIndex != -1)
abilities.push_back( abilityIndex ); abilities.push_back(abilityIndex);
} }
} }
void PopulateColorIndexVector(list<int>& colors, const string& colorStringList, char delimiter)
void PopulateColorIndexVector( list<int>& colors, const string& colorStringList, char delimiter )
{ {
vector<string> abilitiesList = split( colorStringList, delimiter); vector<string> abilitiesList = split(colorStringList, delimiter);
for ( vector<string>::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter) for (vector<string>::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter)
{ {
for (int colorIndex = Constants::MTG_COLOR_ARTIFACT; colorIndex < Constants::MTG_NB_COLORS; ++colorIndex) for (int colorIndex = Constants::MTG_COLOR_ARTIFACT; colorIndex < Constants::MTG_NB_COLORS; ++colorIndex)
{ {
// if the text is not a basic ability but contains a valid color add it to the color vector // if the text is not a basic ability but contains a valid color add it to the color vector
if ( (Constants::GetBasicAbilityIndex( *iter ) != -1) && ((*iter).find( Constants::MTGColorStrings[ colorIndex ] ) != string::npos) ) if ((Constants::GetBasicAbilityIndex(*iter) != -1)
&& ((*iter).find(Constants::MTGColorStrings[colorIndex]) != string::npos))
colors.push_back(colorIndex); colors.push_back(colorIndex);
} }
} }
} }
void PopulateSubtypesIndexVector( list<int>& types, const string& subTypesStringList, char delimiter) void PopulateSubtypesIndexVector(list<int>& types, const string& subTypesStringList, char delimiter)
{ {
vector<string> subTypesList = split( subTypesStringList, delimiter); vector<string> subTypesList = split(subTypesStringList, delimiter);
for (vector<string>::iterator it = subTypesList.begin(); it != subTypesList.end(); ++it) for (vector<string>::iterator it = subTypesList.begin(); it != subTypesList.end(); ++it)
{ {
string subtype = *it; string subtype = *it;
size_t id = Subtypes::subtypesList->find( subtype ); size_t id = Subtypes::subtypesList->find(subtype);
if ( id != string::npos ) if (id != string::npos)
types.push_back(id); types.push_back(id);
} }
} }
+340 -337
View File
@@ -72,19 +72,19 @@ void GameObserver::nextPlayer()
void GameObserver::nextGamePhase() void GameObserver::nextGamePhase()
{ {
Phase * cPhaseOld = phaseRing->getCurrentPhase(); Phase * cPhaseOld = phaseRing->getCurrentPhase();
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE) if (cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE)
if (FIRST_STRIKE == combatStep || END_FIRST_STRIKE == combatStep || DAMAGE == combatStep) if ((FIRST_STRIKE == combatStep) || (END_FIRST_STRIKE == combatStep) || (DAMAGE == combatStep))
{ {
nextCombatStep(); nextCombatStep();
return; return;
} }
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS) if (cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS)
if (BLOCKERS == combatStep || TRIGGERS == combatStep) if (BLOCKERS == combatStep || TRIGGERS == combatStep)
{ {
nextCombatStep(); nextCombatStep();
return; return;
} }
phaseRing->forward(); phaseRing->forward();
@@ -99,25 +99,25 @@ void GameObserver::nextGamePhase()
currentGamePhase = cPhase->id; currentGamePhase = cPhase->id;
if (Constants::MTG_PHASE_COMBATDAMAGE == currentGamePhase) if (Constants::MTG_PHASE_COMBATDAMAGE == currentGamePhase)
nextCombatStep(); nextCombatStep();
if (currentPlayer != cPhase->player) if (currentPlayer != cPhase->player)
nextPlayer(); nextPlayer();
//init begin of turn //init begin of turn
if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN) if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN)
{ {
cleanupPhase(); cleanupPhase();
currentPlayer->canPutLandsIntoPlay = true; currentPlayer->canPutLandsIntoPlay = true;
currentPlayer->landsPlayerCanStillPlay = 1; currentPlayer->landsPlayerCanStillPlay = 1;
currentPlayer->castedspellsthisturn = 0; currentPlayer->castedspellsthisturn = 0;
currentPlayer->opponent()->castedspellsthisturn = 0; currentPlayer->opponent()->castedspellsthisturn = 0;
currentPlayer->castcount = 0; currentPlayer->castcount = 0;
currentPlayer->nocreatureinstant = false; currentPlayer->nocreatureinstant = false;
currentPlayer->nospellinstant = false; currentPlayer->nospellinstant = false;
currentPlayer->onlyoneinstant = false; currentPlayer->onlyoneinstant = false;
currentPlayer->damageCount = 0; currentPlayer->damageCount = 0;
currentPlayer->preventable = 0; currentPlayer->preventable = 0;
mLayers->actionLayer()->cleanGarbage(); //clean abilities history for this turn; mLayers->actionLayer()->cleanGarbage(); //clean abilities history for this turn;
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn; mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
mLayers->actionLayer()->Update(0); mLayers->actionLayer()->Update(0);
@@ -147,7 +147,7 @@ void GameObserver::nextGamePhase()
switch (currentGamePhase) switch (currentGamePhase)
{ {
case Constants::MTG_PHASE_UNTAP: case Constants::MTG_PHASE_UNTAP:
DebugTrace("Untap Phase ------------- Turn " << turn ); DebugTrace("Untap Phase ------------- Turn " << turn );
untapPhase(); untapPhase();
break; break;
case Constants::MTG_PHASE_DRAW: case Constants::MTG_PHASE_DRAW:
@@ -198,37 +198,39 @@ void GameObserver::nextCombatStep()
void GameObserver::userRequestNextGamePhase() void GameObserver::userRequestNextGamePhase()
{ {
if (mLayers->stackLayer()->getNext(NULL, 0, NOT_RESOLVED)) if (mLayers->stackLayer()->getNext(NULL, 0, NOT_RESOLVED))
return; return;
if (getCurrentTargetChooser()) if (getCurrentTargetChooser())
return; return;
//if (mLayers->actionLayer()->isWaitingForAnswer()) //if (mLayers->actionLayer()->isWaitingForAnswer())
// return; // return;
// Wil 12/5/10: additional check, not quite understanding why TargetChooser doesn't seem active at this point. // Wil 12/5/10: additional check, not quite understanding why TargetChooser doesn't seem active at this point.
// If we deem that an extra cost payment needs to be made, don't allow the next game phase to proceed. // If we deem that an extra cost payment needs to be made, don't allow the next game phase to proceed.
// Here's what I find weird - if the extra cost is something like a sacrifice, doesn't that imply a TargetChooser? // Here's what I find weird - if the extra cost is something like a sacrifice, doesn't that imply a TargetChooser?
if (WaitForExtraPayment(NULL)) if (WaitForExtraPayment(NULL))
return; return;
bool executeNextPhaseImmediately = true; bool executeNextPhaseImmediately = true;
Phase * cPhaseOld = phaseRing->getCurrentPhase(); Phase * cPhaseOld = phaseRing->getCurrentPhase();
if ((cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == ORDER) || (cPhaseOld->id if ((cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == ORDER)
== Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == TRIGGERS) || cPhaseOld->id || (cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == TRIGGERS)
== Constants::MTG_PHASE_COMBATDAMAGE || opponent()->isAI() || (cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE)
|| options[Options::optionInterrupt(currentGamePhase)].number) || opponent()->isAI()
{ || options[Options::optionInterrupt(currentGamePhase)].number
executeNextPhaseImmediately = false; )
} {
executeNextPhaseImmediately = false;
}
if (executeNextPhaseImmediately) if (executeNextPhaseImmediately)
{ {
nextGamePhase(); nextGamePhase();
} }
else else
{ {
mLayers->stackLayer()->AddNextGamePhase(); mLayers->stackLayer()->AddNextGamePhase();
} }
} }
@@ -254,8 +256,8 @@ void GameObserver::startGame(Rules * rules)
{ {
turn = 0; turn = 0;
mRules = rules; mRules = rules;
if (rules) if (rules)
rules->initPlayers(); rules->initPlayers();
options.automaticStyle(players[0], players[1]); options.automaticStyle(players[0], players[1]);
@@ -266,8 +268,8 @@ void GameObserver::startGame(Rules * rules)
currentPlayer = players[0]; currentPlayer = players[0];
currentActionPlayer = currentPlayer; currentActionPlayer = currentPlayer;
phaseRing = NEW PhaseRing(players, nbPlayers); phaseRing = NEW PhaseRing(players, nbPlayers);
if (rules) if (rules)
rules->initGame(); rules->initGame();
//Preload images from hand //Preload images from hand
if (!players[0]->isAI()) if (!players[0]->isAI())
@@ -346,12 +348,12 @@ void GameObserver::Update(float dt)
{ {
Player * player = currentPlayer; Player * player = currentPlayer;
if (Constants::MTG_PHASE_COMBATBLOCKERS == currentGamePhase && BLOCKERS == combatStep) if (Constants::MTG_PHASE_COMBATBLOCKERS == currentGamePhase && BLOCKERS == combatStep)
player = player->opponent(); player = player->opponent();
currentActionPlayer = player; currentActionPlayer = player;
if (isInterrupting) if (isInterrupting)
player = isInterrupting; player = isInterrupting;
mLayers->Update(dt, player); mLayers->Update(dt, player);
while (mLayers->actionLayer()->stuffHappened) while (mLayers->actionLayer()->stuffHappened)
@@ -359,8 +361,8 @@ void GameObserver::Update(float dt)
mLayers->actionLayer()->Update(0); mLayers->actionLayer()->Update(0);
} }
gameStateBasedEffects(); gameStateBasedEffects();
oldGamePhase = currentGamePhase; oldGamePhase = currentGamePhase;
} }
//applies damage to creatures after updates //applies damage to creatures after updates
@@ -368,268 +370,269 @@ void GameObserver::Update(float dt)
//Handles game state based effects //Handles game state based effects
void GameObserver::gameStateBasedEffects() void GameObserver::gameStateBasedEffects()
{ {
//check land playability at start; as we want this effect to happen reguardless of unresolved //check land playability at start; as we want this effect to happen reguardless of unresolved
//effects or menus actions //effects or menus actions
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
if(players[i]->landsPlayerCanStillPlay <= 0) if (players[i]->landsPlayerCanStillPlay <= 0)
{ {
players[i]->canPutLandsIntoPlay = false; players[i]->canPutLandsIntoPlay = false;
} }
else else
{ {
players[i]->canPutLandsIntoPlay = true; players[i]->canPutLandsIntoPlay = true;
} }
} }
if (mLayers->stackLayer()->count(0, NOT_RESOLVED) != 0) if (mLayers->stackLayer()->count(0, NOT_RESOLVED) != 0)
return; return;
if (mLayers->actionLayer()->menuObject) if (mLayers->actionLayer()->menuObject)
return; return;
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()) if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer())
return; return;
//////////////////////// ////////////////////////
//---apply damage-----// //---apply damage-----//
//after combat effects// //after combat effects//
//////////////////////// ////////////////////////
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
MTGGameZone * zone = players[i]->game->inPlay; MTGGameZone * zone = players[i]->game->inPlay;
for (int j = zone->nb_cards - 1; j >= 0; j--) for (int j = zone->nb_cards - 1; j >= 0; j--)
{ {
MTGCardInstance * card = zone->cards[j]; MTGCardInstance * card = zone->cards[j];
card->afterDamage(); card->afterDamage();
//Remove auras that don't have a valid target anymore //Remove auras that don't have a valid target anymore
if (card->target && !isInPlay(card->target) && !card->hasType("equipment")) if (card->target && !isInPlay(card->target) && !card->hasType("equipment"))
{ {
players[i]->game->putInGraveyard(card); players[i]->game->putInGraveyard(card);
} }
} }
} }
//------------------------------------- //-------------------------------------
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
//life checks/poison checks also checks cant win or lose.// //life checks/poison checks also checks cant win or lose.//
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
if (players[i]->life <= 0) if (players[i]->life <= 0)
{ {
int cantlosers = 0; int cantlosers = 0;
MTGGameZone * z = players[i]->game->inPlay; MTGGameZone * z = players[i]->game->inPlay;
int nbcards = z->nb_cards; int nbcards = z->nb_cards;
for (int j = 0; j < nbcards; ++j) for (int j = 0; j < nbcards; ++j)
{ {
MTGCardInstance * c = z->cards[j]; MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTLOSE) || c->has(Constants::CANTLIFELOSE)) if (c->has(Constants::CANTLOSE) || c->has(Constants::CANTLIFELOSE))
{ {
cantlosers++; cantlosers++;
} }
} }
MTGGameZone * k = players[i]->opponent()->game->inPlay; MTGGameZone * k = players[i]->opponent()->game->inPlay;
int onbcards = k->nb_cards; int onbcards = k->nb_cards;
for (int m = 0; m < onbcards; ++m) for (int m = 0; m < onbcards; ++m)
{ {
MTGCardInstance * e = k->cards[m]; MTGCardInstance * e = k->cards[m];
if (e->has(Constants::CANTWIN)) if (e->has(Constants::CANTWIN))
{ {
cantlosers++; cantlosers++;
} }
} }
if (cantlosers < 1) if (cantlosers < 1)
{ {
gameOver = players[i]; gameOver = players[i];
} }
if (players[i]->poisonCount >= 10) if (players[i]->poisonCount >= 10)
{ {
gameOver = players[i]; gameOver = players[i];
} }
} }
} }
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//-------------card based states effects------------// //-------------card based states effects------------//
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//ie:cantcast; extra land; extra turn;no max hand;--// //ie:cantcast; extra land; extra turn;no max hand;--//
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
//checks if a player has a card which has the stated ability in play. //checks if a player has a card which has the stated ability in play.
Player * p = players[i]; Player * p = players[i];
MTGGameZone * z = players[i]->game->inPlay; MTGGameZone * z = players[i]->game->inPlay;
int nbcards = z->nb_cards; int nbcards = z->nb_cards;
p->onlyonecast = false; p->onlyonecast = false;
p->opponent()->onlyonecast = false; p->opponent()->onlyonecast = false;
//------------------------------ //------------------------------
if (z->hasAbility(Constants::NOMAXHAND)) if (z->hasAbility(Constants::NOMAXHAND))
{ {
p->nomaxhandsize = true; p->nomaxhandsize = true;
} }
else else
{ {
p->nomaxhandsize = false; p->nomaxhandsize = false;
} }
//------------------------------ //------------------------------
if (z->hasAbility(Constants::CANTCASTCREATURE)) if (z->hasAbility(Constants::CANTCASTCREATURE))
{ {
p->castrestrictedcreature = true; p->castrestrictedcreature = true;
} }
else else
{ {
p->castrestrictedcreature = false; p->castrestrictedcreature = false;
} }
//------------------------------ //------------------------------
if (z->hasAbility(Constants::CANTCAST)) if (z->hasAbility(Constants::CANTCAST))
{ {
p->castrestrictedspell = true; p->castrestrictedspell = true;
} }
else else
{ {
p->castrestrictedspell = false; p->castrestrictedspell = false;
} }
//------------------------------ //------------------------------
if (z->hasAbility(Constants::CANTCASTTWO)) if (z->hasAbility(Constants::CANTCASTTWO))
{ {
p->onlyonecast = true; p->onlyonecast = true;
} }
else else
{ {
p->onlyonecast = false; p->onlyonecast = false;
} }
//-------------------------------- //--------------------------------
if (z->hasAbility(Constants::BOTHCANTCAST)) if (z->hasAbility(Constants::BOTHCANTCAST))
{ {
p->bothrestrictedspell = true; p->bothrestrictedspell = true;
} }
else else
{ {
p->bothrestrictedspell = false; p->bothrestrictedspell = false;
} }
//--------------------------------- //---------------------------------
if (z->hasAbility(Constants::BOTHNOCREATURE)) if (z->hasAbility(Constants::BOTHNOCREATURE))
{ {
p->bothrestrictedcreature = true; p->bothrestrictedcreature = true;
} }
else else
{ {
p->bothrestrictedcreature = false; p->bothrestrictedcreature = false;
} }
//----------------------------------- //-----------------------------------
if (z->hasAbility(Constants::ONLYONEBOTH)) if (z->hasAbility(Constants::ONLYONEBOTH))
{ {
p->onlyoneboth = true; p->onlyoneboth = true;
} }
else else
{ {
p->onlyoneboth = false; p->onlyoneboth = false;
} }
//------------------------------------ //------------------------------------
if(players[0]->bothrestrictedcreature) if (players[0]->bothrestrictedcreature)
players[1]->castrestrictedcreature = true; players[1]->castrestrictedcreature = true;
//------------------------------------ //------------------------------------
if(players[0]->bothrestrictedspell) if (players[0]->bothrestrictedspell)
players[1]->castrestrictedspell = true; players[1]->castrestrictedspell = true;
//------------------------------------ //------------------------------------
if(players[0]->onlyoneboth) if (players[0]->onlyoneboth)
players[1]->onlyoneboth = true; players[1]->onlyoneboth = true;
//------------------------------------ //------------------------------------
if(players[1]->bothrestrictedcreature) if (players[1]->bothrestrictedcreature)
players[0]->castrestrictedcreature = true; players[0]->castrestrictedcreature = true;
//------------------------------------ //------------------------------------
if(players[1]->bothrestrictedspell) if (players[1]->bothrestrictedspell)
players[0]->castrestrictedspell = true; players[0]->castrestrictedspell = true;
//------------------------------------ //------------------------------------
if(players[1]->onlyoneboth) if (players[1]->onlyoneboth)
players[0]->onlyoneboth = true; players[0]->onlyoneboth = true;
//------------------------------------ //------------------------------------
///////////////////////////////////////////////// /////////////////////////////////////////////////
//handle end of turn effects while we're at it.// //handle end of turn effects while we're at it.//
///////////////////////////////////////////////// /////////////////////////////////////////////////
if( currentGamePhase == Constants::MTG_PHASE_ENDOFTURN) if (currentGamePhase == Constants::MTG_PHASE_ENDOFTURN)
{ {
for (int j = 0; j < nbcards; ++j) for (int j = 0; j < nbcards; ++j)
{ {
MTGCardInstance * c = z->cards[j]; MTGCardInstance * c = z->cards[j];
while (c->flanked) while (c->flanked)
{//undoes the flanking on a card {//undoes the flanking on a card
c->power += 1; c->power += 1;
c->addToToughness(1); c->addToToughness(1);
c->flanked -= 1; c->flanked -= 1;
} }
if (c->has(Constants::TREASON)) if (c->has(Constants::TREASON))
{ {
WEvent * e = NEW WEventCardSacrifice(c); WEvent * e = NEW WEventCardSacrifice(c);
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
game->receiveEvent(e); game->receiveEvent(e);
p->game->putInGraveyard(c); p->game->putInGraveyard(c);
} }
if (c->has(Constants::UNEARTH)) if (c->has(Constants::UNEARTH)) p->game->putInExile(c);
p->game->putInExile(c); if (c->fresh) c->fresh = 0;
if (c->fresh) if (c->has(Constants::ONLYONEBOTH))
c->fresh = 0; {
if (c->has(Constants::ONLYONEBOTH)) c->controller()->castcount = 0;
{ c->controller()->opponent()->castcount = 0;
c->controller()->castcount = 0; }
c->controller()->opponent()->castcount = 0;
}
} }
MTGGameZone * f = p->game->graveyard; MTGGameZone * f = p->game->graveyard;
for (int k = 0; k < f->nb_cards; k++) for (int k = 0; k < f->nb_cards; k++)
{ {
MTGCardInstance * card = f->cards[k]; MTGCardInstance * card = f->cards[k];
card->fresh = 0; card->fresh = 0;
} }
} }
if(z->nb_cards == 0) if (z->nb_cards == 0)
{ {
p->nomaxhandsize = false; p->nomaxhandsize = false;
if(!p->bothrestrictedcreature && !p->opponent()->bothrestrictedcreature) if (!p->bothrestrictedcreature && !p->opponent()->bothrestrictedcreature)
p->castrestrictedcreature = false; p->castrestrictedcreature = false;
if(!p->bothrestrictedspell && !p->opponent()->bothrestrictedspell) if (!p->bothrestrictedspell && !p->opponent()->bothrestrictedspell)
p->castrestrictedspell = false; p->castrestrictedspell = false;
p->onlyonecast = false; p->onlyonecast = false;
} }
} }
/////////////////////////////////// ///////////////////////////////////
//phase based state effects------// //phase based state effects------//
/////////////////////////////////// ///////////////////////////////////
if (combatStep == TRIGGERS) if (combatStep == TRIGGERS)
{ {
if (!mLayers->stackLayer()->getNext(NULL, 0, NOT_RESOLVED) && !targetChooser && !mLayers->actionLayer()->isWaitingForAnswer()) if (!mLayers->stackLayer()->getNext(NULL, 0, NOT_RESOLVED) && !targetChooser
&& !mLayers->actionLayer()->isWaitingForAnswer())
mLayers->stackLayer()->AddNextCombatStep(); mLayers->stackLayer()->AddNextCombatStep();
} }
//Auto skip Phases //Auto skip Phases
GameObserver * game = game->GetInstance(); GameObserver * game = game->GetInstance();
int skipLevel = (game->currentPlayer->playMode == Player::MODE_TEST_SUITE) ? Constants::ASKIP_NONE : options[Options::ASPHASES].number; int skipLevel = (game->currentPlayer->playMode == Player::MODE_TEST_SUITE) ? Constants::ASKIP_NONE
int nrCreatures = currentPlayer->game->inPlay->countByType("Creature"); : options[Options::ASPHASES].number;
int nrCreatures = currentPlayer->game->inPlay->countByType("Creature");
if (skipLevel == Constants::ASKIP_SAFE || skipLevel == Constants::ASKIP_FULL) if (skipLevel == Constants::ASKIP_SAFE || skipLevel == Constants::ASKIP_FULL)
{ {
if ((opponent()->isAI() && !(isInterrupting)) && (currentGamePhase == Constants::MTG_PHASE_UNTAP || currentGamePhase if ((opponent()->isAI() && !(isInterrupting)) && ((currentGamePhase == Constants::MTG_PHASE_UNTAP)
== Constants::MTG_PHASE_DRAW || currentGamePhase == Constants::MTG_PHASE_COMBATBEGIN || ((currentGamePhase || (currentGamePhase == Constants::MTG_PHASE_DRAW) || (currentGamePhase == Constants::MTG_PHASE_COMBATBEGIN)
== Constants::MTG_PHASE_COMBATATTACKERS) && (nrCreatures == 0)) || currentGamePhase || ((currentGamePhase == Constants::MTG_PHASE_COMBATATTACKERS) && (nrCreatures == 0))
== Constants::MTG_PHASE_COMBATEND || currentGamePhase == Constants::MTG_PHASE_ENDOFTURN || currentGamePhase == Constants::MTG_PHASE_COMBATEND || currentGamePhase == Constants::MTG_PHASE_ENDOFTURN
|| ((currentGamePhase == Constants::MTG_PHASE_CLEANUP) && (currentPlayer->game->hand->nb_cards < 8)))) || ((currentGamePhase == Constants::MTG_PHASE_CLEANUP) && (currentPlayer->game->hand->nb_cards < 8))))
userRequestNextGamePhase(); userRequestNextGamePhase();
} }
if (skipLevel == Constants::ASKIP_FULL) if (skipLevel == Constants::ASKIP_FULL)
{ {
if ((opponent()->isAI() && !(isInterrupting)) && (currentGamePhase == Constants::MTG_PHASE_UPKEEP || currentGamePhase if ((opponent()->isAI() && !(isInterrupting)) && (currentGamePhase == Constants::MTG_PHASE_UPKEEP
== Constants::MTG_PHASE_COMBATDAMAGE)) || currentGamePhase == Constants::MTG_PHASE_COMBATDAMAGE))
userRequestNextGamePhase(); userRequestNextGamePhase();
} }
} }
void GameObserver::Render() void GameObserver::Render()
{ {
mLayers->Render(); mLayers->Render();
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()) if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer())
JRenderer::GetInstance()->DrawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(255,255,0,0)); JRenderer::GetInstance()->DrawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(255,255,0,0));
if (mExtraPayment) if (mExtraPayment)
mExtraPayment->Render(); mExtraPayment->Render();
for (int i = 0; i < nbPlayers; ++i) for (int i = 0; i < nbPlayers; ++i)
{ {
players[i]->Render(); players[i]->Render();
@@ -701,8 +704,8 @@ void GameObserver::stackObjectClicked(Interruptible * action)
else else
{ {
int 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);
} }
} }
@@ -729,8 +732,8 @@ bool GameObserver::WaitForExtraPayment(MTGCardInstance * card)
int GameObserver::cardClick(MTGCardInstance * card, Targetable * object) int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
{ {
Player * clickedPlayer = NULL; Player * clickedPlayer = NULL;
if (!card) if (!card)
clickedPlayer = ((Player *) object); clickedPlayer = ((Player *) object);
if (targetChooser) if (targetChooser)
{ {
int result; int result;
@@ -763,10 +766,10 @@ int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
return 1; return 1;
} }
if (WaitForExtraPayment(card)) if (WaitForExtraPayment(card))
return 1; return 1;
int reaction = 0; int reaction = 0;
if (ORDER == combatStep) if (ORDER == combatStep)
{ {
@@ -793,22 +796,22 @@ int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
} }
reaction = mLayers->actionLayer()->isReactingToClick(card); reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1) if (reaction == -1)
return mLayers->actionLayer()->reactToClick(card); return 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)
return mLayers->actionLayer()->reactToTargetClick(object); return mLayers->actionLayer()->reactToTargetClick(object);
} }
if (!card) if (!card)
return 0; 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
&& currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize == false) && currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize == false)
{ {
currentPlayer->game->putInGraveyard(card); currentPlayer->game->putInGraveyard(card);
} }
@@ -840,9 +843,9 @@ int GameObserver::untap(MTGCardInstance * card)
return 0; return 0;
} }
if (card->has(Constants::DOESNOTUNTAP)) if (card->has(Constants::DOESNOTUNTAP))
return 0; return 0;
if (card->frozen > 0) if (card->frozen > 0)
return 0; return 0;
card->attemptUntap(); card->attemptUntap();
return 1; return 1;
} }
@@ -850,8 +853,8 @@ int GameObserver::untap(MTGCardInstance * card)
TargetChooser * GameObserver::getCurrentTargetChooser() TargetChooser * GameObserver::getCurrentTargetChooser()
{ {
TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser(); TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser();
if (_tc) if (_tc)
return _tc; return _tc;
return targetChooser; return targetChooser;
} }
@@ -860,8 +863,8 @@ int GameObserver::isInPlay(MTGCardInstance * card)
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
if (players[i]->game->isInPlay(card)) if (players[i]->game->isInPlay(card))
return 1; return 1;
} }
return 0; return 0;
} }
@@ -884,11 +887,11 @@ void GameObserver::untapPhase()
int GameObserver::receiveEvent(WEvent * e) int GameObserver::receiveEvent(WEvent * e)
{ {
if (!e) if (!e)
return 0; return 0;
eventsQueue.push(e); eventsQueue.push(e);
if (eventsQueue.size() > 1) if (eventsQueue.size() > 1)
return -1; //resolving events can generate more events return -1; //resolving events can generate more events
int result = 0; int result = 0;
while (eventsQueue.size()) while (eventsQueue.size())
{ {
@@ -906,8 +909,8 @@ int GameObserver::receiveEvent(WEvent * e)
Player * GameObserver::currentlyActing() Player * GameObserver::currentlyActing()
{ {
if (isInterrupting) if (isInterrupting)
return isInterrupting; return isInterrupting;
return currentActionPlayer; return currentActionPlayer;
} }
+3 -3
View File
@@ -21,7 +21,7 @@ bool GuiStatic::Leaving(JButton key)
GuiAvatar::GuiAvatar(float x, float y, bool hasFocus, Player * player, Corner corner, GuiAvatars* parent) : GuiAvatar::GuiAvatar(float x, float y, bool hasFocus, Player * player, Corner corner, GuiAvatars* parent) :
GuiStatic(static_cast<float> (GuiAvatar::Height), x, y, hasFocus, parent), avatarRed(255), currentLife(player->life), GuiStatic(static_cast<float> (GuiAvatar::Height), x, y, hasFocus, parent), avatarRed(255), currentLife(player->life),
currentpoisonCount(player->poisonCount), corner(corner), player(player) currentpoisonCount(player->poisonCount), corner(corner), player(player)
{ {
type = GUI_AVATAR; type = GUI_AVATAR;
} }
@@ -135,7 +135,7 @@ void GuiAvatar::Render()
ostream& GuiAvatar::toString(ostream& out) const ostream& GuiAvatar::toString(ostream& out) const
{ {
return out << "GuiAvatar ::: avatarRed : " << avatarRed << " ; currentLife : " << currentLife << " ; currentpoisonCount : " return out << "GuiAvatar ::: avatarRed : " << avatarRed << " ; currentLife : " << currentLife << " ; currentpoisonCount : "
<< currentpoisonCount << " ; player : " << player; << currentpoisonCount << " ; player : " << player;
} }
void GuiGameZone::toggleDisplay() void GuiGameZone::toggleDisplay()
@@ -166,7 +166,7 @@ void GuiGameZone::Render()
if (mHasFocus) if (mHasFocus)
JRenderer::GetInstance()->FillRect(actX, actY, quad->mWidth * scale * actZ, quad->mHeight * scale * actZ, JRenderer::GetInstance()->FillRect(actX, actY, quad->mWidth * scale * actZ, quad->mHeight * scale * actZ,
ARGB(abs(128 - wave),255,255,255)); ARGB(abs(128 - wave),255,255,255));
//Number of cards //Number of cards
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
+134 -89
View File
@@ -19,9 +19,11 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
Player * currentPlayer = game->currentPlayer; Player * currentPlayer = game->currentPlayer;
if (!player->game->hand->hasCard(card)) if (!player->game->hand->hasCard(card))
return 0; return 0;
if ((game->turn < 1) && (cardsinhand != 0) && (card->basicAbilities[Constants::LEYLINE]) && game->currentGamePhase if ((game->turn < 1) && (cardsinhand != 0) && (card->basicAbilities[Constants::LEYLINE])
== Constants::MTG_PHASE_FIRSTMAIN && game->players[0]->game->graveyard->nb_cards == 0 && game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
&& game->players[0]->game->exile->nb_cards == 0) && game->players[0]->game->graveyard->nb_cards == 0
&& game->players[0]->game->exile->nb_cards == 0
)
{ {
Player * p = game->currentPlayer; Player * p = game->currentPlayer;
if (card->basicAbilities[Constants::LEYLINE]) if (card->basicAbilities[Constants::LEYLINE])
@@ -35,15 +37,18 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
} }
if (card->hasType("land")) if (card->hasType("land"))
{ {
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (game->currentGamePhase if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay
== Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
)
{ {
return 1; return 1;
} }
} }
else if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && !game->isInterrupting else if ((card->hasType("instant")) || card->has(Constants::FLASH)
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase || (player == currentPlayer && !game->isInterrupting
== Constants::MTG_PHASE_SECONDMAIN))) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))
)
{ {
ManaCost * playerMana = player->getManaPool(); ManaCost * playerMana = player->getManaPool();
ManaCost * cost = card->getManaCost(); ManaCost * cost = card->getManaCost();
@@ -241,15 +246,17 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
return 0; return 0;
if (card->hasType("land")) if (card->hasType("land"))
{ {
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (game->currentGamePhase if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay
== Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
{ || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
)
return 1; return 1;
}
} }
else if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && !game->isInterrupting else if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase && !game->isInterrupting
== Constants::MTG_PHASE_SECONDMAIN))) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))
)
{ {
ManaCost * playerMana = player->getManaPool(); ManaCost * playerMana = player->getManaPool();
ManaCost * cost = card->getManaCost(); ManaCost * cost = card->getManaCost();
@@ -431,14 +438,14 @@ int MTGBuyBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
if (card->hasType("land")) if (card->hasType("land"))
{ {
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (game->currentGamePhase if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (game->currentGamePhase
== Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)) == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))
{ {
return 1; return 1;
} }
} }
else if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && !game->isInterrupting else if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && !game->isInterrupting
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase
== Constants::MTG_PHASE_SECONDMAIN))) == Constants::MTG_PHASE_SECONDMAIN)))
{ {
ManaCost * playerMana = player->getManaPool(); ManaCost * playerMana = player->getManaPool();
ManaCost * cost = card->getManaCost(); ManaCost * cost = card->getManaCost();
@@ -455,11 +462,11 @@ int MTGBuyBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{ {
return 0; return 0;
} }
if (player->nospellinstant == true ) if (player->nospellinstant == true)
{ {
return 0; return 0;
} }
if (player->onlyoneinstant == true ) if (player->onlyoneinstant == true)
{ {
if (player->castcount >= 1) if (player->castcount >= 1)
{ {
@@ -621,9 +628,11 @@ int MTGFlashBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
return 0; return 0;
if (!card->getManaCost()->FlashBack) if (!card->getManaCost()->FlashBack)
return 0; return 0;
if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && !game->isInterrupting if ((card->hasType("instant")) || card->has(Constants::FLASH)
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase || (player == currentPlayer && !game->isInterrupting
== Constants::MTG_PHASE_SECONDMAIN))) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))
)
{ {
ManaCost * playerMana = player->getManaPool(); ManaCost * playerMana = player->getManaPool();
ManaCost * cost = card->getManaCost(); ManaCost * cost = card->getManaCost();
@@ -640,11 +649,11 @@ int MTGFlashBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{ {
return 0; return 0;
} }
if (player->nospellinstant == true ) if (player->nospellinstant == true)
{ {
return 0; return 0;
} }
if (player->onlyoneinstant == true ) if (player->onlyoneinstant == true)
{ {
if (player->castcount >= 1) if (player->castcount >= 1)
{ {
@@ -732,7 +741,7 @@ int MTGFlashBackRule::reactToClick(MTGCardInstance * card)
game->targetChooser = NULL; game->targetChooser = NULL;
player->castedspellsthisturn += 1; player->castedspellsthisturn += 1;
player->opponent()->castedspellsthisturn += 1; player->opponent()->castedspellsthisturn += 1;
if (player->onlyonecast == true || player->onlyoneinstant == true ) if (player->onlyonecast == true || player->onlyoneinstant == true)
{ {
player->castcount += 1; player->castcount += 1;
} }
@@ -805,9 +814,11 @@ int MTGRetraceRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
return 0; return 0;
if (!card->getManaCost()->Retrace) if (!card->getManaCost()->Retrace)
return 0; return 0;
if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && !game->isInterrupting if ((card->hasType("instant")) || card->has(Constants::FLASH)
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase || (player == currentPlayer && !game->isInterrupting
== Constants::MTG_PHASE_SECONDMAIN))) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))
)
{ {
ManaCost * playerMana = player->getManaPool(); ManaCost * playerMana = player->getManaPool();
ManaCost * cost = card->getManaCost(); ManaCost * cost = card->getManaCost();
@@ -824,11 +835,11 @@ int MTGRetraceRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{ {
return 0; return 0;
} }
if (player->nospellinstant == true ) if (player->nospellinstant == true)
{ {
return 0; return 0;
} }
if (player->onlyoneinstant == true ) if (player->onlyoneinstant == true)
{ {
if (player->castcount >= 1) if (player->castcount >= 1)
{ {
@@ -874,7 +885,8 @@ int MTGRetraceRule::reactToClick(MTGCardInstance * card)
{ {
cost->Retrace->setExtraCostsAction(this, card); cost->Retrace->setExtraCostsAction(this, card);
game->mExtraPayment = cost->Retrace->extraCosts; game->mExtraPayment = cost->Retrace->extraCosts;
card->paymenttype = MTGAbility::RETRACE_COST;; card->paymenttype = MTGAbility::RETRACE_COST;
;
return 0; return 0;
} }
} }
@@ -912,7 +924,7 @@ int MTGRetraceRule::reactToClick(MTGCardInstance * card)
game->targetChooser = NULL; game->targetChooser = NULL;
player->castedspellsthisturn += 1; player->castedspellsthisturn += 1;
player->opponent()->castedspellsthisturn += 1; player->opponent()->castedspellsthisturn += 1;
if (player->onlyonecast == true || player->onlyoneinstant == true ) if (player->onlyonecast == true || player->onlyoneinstant == true)
{ {
player->castcount += 1; player->castcount += 1;
} }
@@ -1013,8 +1025,10 @@ int MTGAttackRule::receiveEvent(WEvent *e)
for (int i = 0; i < z->nb_cards; i++) for (int i = 0; i < z->nb_cards; i++)
{ {
MTGCardInstance * card = z->cards[i]; MTGCardInstance * card = z->cards[i];
if (!card->isAttacker() && card->has(Constants::MUSTATTACK)) reactToClick(card); if (!card->isAttacker() && card->has(Constants::MUSTATTACK))
if (!card->isAttacker() && card->has(Constants::TREASON) && p->isAI()) reactToClick(card); reactToClick(card);
if (!card->isAttacker() && card->has(Constants::TREASON) && p->isAI())
reactToClick(card);
if (card->isAttacker() && card->isTapped()) if (card->isAttacker() && card->isTapped())
card->setAttacker(0); card->setAttacker(0);
if (card->isAttacker() && !card->has(Constants::VIGILANCE)) if (card->isAttacker() && !card->has(Constants::VIGILANCE))
@@ -1223,8 +1237,9 @@ MTGBlockRule::MTGBlockRule(int _id) :
int MTGBlockRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana) int MTGBlockRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{ {
if (currentPhase == Constants::MTG_PHASE_COMBATBLOCKERS && !game->isInterrupting && card->controller() if (currentPhase == Constants::MTG_PHASE_COMBATBLOCKERS && !game->isInterrupting
== game->currentlyActing()) && card->controller() == game->currentlyActing()
)
{ {
if (card->canBlock()) if (card->canBlock())
return 1; return 1;
@@ -1245,8 +1260,8 @@ int MTGBlockRule::reactToClick(MTGCardInstance * card)
canDefend = card->toggleDefenser(currentOpponent); canDefend = card->toggleDefenser(currentOpponent);
DebugTrace("Defenser Toggle: " << card->getName() << endl DebugTrace("Defenser Toggle: " << card->getName() << endl
<< "- canDefend: " << (canDefend == 0) << endl << "- canDefend: " << (canDefend == 0) << endl
<< "- currentOpponent: " << currentOpponent); << "- currentOpponent: " << currentOpponent);
result = (canDefend || currentOpponent == NULL); result = (canDefend || currentOpponent == NULL);
} }
return 1; return 1;
@@ -1291,7 +1306,7 @@ MTGMomirRule::MTGMomirRule(int _id, MTGAllCards * _collection) :
{ {
MTGCard * card = collection->collection[collection->ids[i]]; MTGCard * card = collection->collection[collection->ids[i]];
if (card->data->isCreature() && (card->getRarity() != Constants::RARITY_T) && //remove tokens if (card->data->isCreature() && (card->getRarity() != Constants::RARITY_T) && //remove tokens
card->setId != MTGSets::INTERNAL_SET //remove cards that are defined in primitives. Those are workarounds (usually tokens) and should only be used internally card->setId != MTGSets::INTERNAL_SET //remove cards that are defined in primitives. Those are workarounds (usually tokens) and should only be used internally
) )
{ {
int convertedCost = card->data->getManaCost()->getConvertedCost(); int convertedCost = card->data->getManaCost()->getConvertedCost();
@@ -1315,8 +1330,10 @@ int MTGMomirRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
Player * currentPlayer = game->currentPlayer; Player * currentPlayer = game->currentPlayer;
if (!player->game->hand->hasCard(card)) if (!player->game->hand->hasCard(card))
return 0; return 0;
if (player == currentPlayer && !game->isInterrupting && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN if (player == currentPlayer && !game->isInterrupting
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
)
{ {
return 1; return 1;
} }
@@ -1414,8 +1431,9 @@ void MTGMomirRule::Render()
ostream& MTGMomirRule::toString(ostream& out) const ostream& MTGMomirRule::toString(ostream& out) const
{ {
out << "MTGMomirRule ::: pool : " << pool << " ; initialized : " << initialized << " ; textAlpha : " << textAlpha << " ; text " out << "MTGMomirRule ::: pool : " << pool << " ; initialized : " << initialized << " ; textAlpha : " << textAlpha
<< text << " ; alreadyplayed : " << alreadyplayed << " ; collection : " << collection << "("; << " ; text " << text << " ; alreadyplayed : " << alreadyplayed
<< " ; collection : " << collection << "(";
return MTGAbility::toString(out) << ")"; return MTGAbility::toString(out) << ")";
} }
@@ -1487,7 +1505,7 @@ int HUDDisplay::receiveEvent(WEvent * event)
{ {
char buffer[512]; char buffer[512];
sprintf(buffer, "%s: %i -> %s", _(ed->damage->source->name).c_str(), ed->damage->damage, _( sprintf(buffer, "%s: %i -> %s", _(ed->damage->source->name).c_str(), ed->damage->damage, _(
ed->damage->target->getDisplayName()).c_str()); ed->damage->target->getDisplayName()).c_str());
string s = buffer; string s = buffer;
return addEvent(s); return addEvent(s);
} }
@@ -1615,23 +1633,23 @@ MTGUnearthRule::MTGUnearthRule(int _id) :
int MTGUnearthRule::receiveEvent(WEvent * event) int MTGUnearthRule::receiveEvent(WEvent * event)
{ {
if (event->type == WEvent::CHANGE_ZONE) if (event->type == WEvent::CHANGE_ZONE)
{ {
WEventZoneChange * e = (WEventZoneChange *) event; WEventZoneChange * e = (WEventZoneChange *) event;
MTGCardInstance * card = e->card->previous; MTGCardInstance * card = e->card->previous;
if (e->from == e->card->controller()->game->battlefield && e->to == e->card->controller()->game->graveyard) if (e->from == e->card->controller()->game->battlefield && e->to == e->card->controller()->game->graveyard)
{ {
e->card->fresh = 1; e->card->fresh = 1;
} }
if (e->to == e->card->controller()->game->battlefield) if (e->to == e->card->controller()->game->battlefield)
{ {
e->card->fresh = 1; e->card->fresh = 1;
} }
if (card && card->basicAbilities[Constants::UNEARTH]) if (card && card->basicAbilities[Constants::UNEARTH])
{ {
int ok = 0; int ok = 0;
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
Player * p = game->players[i]; Player * p = game->players[i];
if (e->from == p->game->inPlay) if (e->from == p->game->inPlay)
ok = 1; ok = 1;
@@ -1696,10 +1714,19 @@ int MTGAffinityRule::receiveEvent(WEvent * event)
//when cards with affinity enter you hand from anywhere a redux is applied to them for the artifacts in play. //when cards with affinity enter you hand from anywhere a redux is applied to them for the artifacts in play.
if (ok == 1) if (ok == 1)
{//enters play from anywhere {//enters play from anywhere
if (e->from == p->game->graveyard || e->from == p->game->hand || e->from == p->game->library || e->from if (e->from == p->game->graveyard
== p->game->exile || e->from == p->game->stack || e->from == p->opponent()->game->battlefield || e->from == p->game->hand
|| e->from == p->game->temp || e->from == p->game->battlefield) || e->from == p->game->library
|| e->from == p->game->exile
|| e->from == p->game->stack
|| e->from == p->opponent()->game->battlefield
|| e->from == p->game->temp
|| e->from == p->game->battlefield
)
{ {
// TODO:
// what happens if there are any cards with two or more affinity abilities? If no such card exist
// then could this block be changed to use else if? That will save on the number of operations.
MTGCardInstance * card = e->card->previous; MTGCardInstance * card = e->card->previous;
if (card && card->has(Constants::AFFINITYARTIFACTS)) if (card && card->has(Constants::AFFINITYARTIFACTS))
{ {
@@ -1743,13 +1770,14 @@ int MTGAffinityRule::receiveEvent(WEvent * event)
{ {
MTGCardInstance * c = z->cards[j]; MTGCardInstance * c = z->cards[j];
int check = e->card->getManaCost()->getConvertedCost(); int check = e->card->getManaCost()->getConvertedCost();
if ((e->card->has(Constants::AFFINITYARTIFACTS) && c->hasSubtype("artifact")) || (e->card->has( if ((e->card->has(Constants::AFFINITYARTIFACTS) && c->hasSubtype("artifact"))
Constants::AFFINITYSWAMP) && c->hasSubtype("swamp")) || (e->card->has( || (e->card->has(Constants::AFFINITYSWAMP) && c->hasSubtype("swamp"))
Constants::AFFINITYMOUNTAIN) && c->hasSubtype("moutain")) || (e->card->has( || (e->card->has(Constants::AFFINITYMOUNTAIN) && c->hasSubtype("moutain"))
Constants::AFFINITYPLAINS) && c->hasSubtype("plains")) || (e->card->has( || (e->card->has(Constants::AFFINITYPLAINS) && c->hasSubtype("plains"))
Constants::AFFINITYISLAND) && c->hasSubtype("island")) || (e->card->has( || (e->card->has(Constants::AFFINITYISLAND) && c->hasSubtype("island"))
Constants::AFFINITYFOREST) && c->hasSubtype("forest")) || (e->card->has( || (e->card->has(Constants::AFFINITYFOREST) && c->hasSubtype("forest"))
Constants::AFFINITYGREENCREATURES) && c->hasColor(1) && c->isCreature())) || (e->card->has(Constants::AFFINITYGREENCREATURES) && c->hasColor(1) && c->isCreature())
)
{ {
if (check > 0) if (check > 0)
{ {
@@ -1776,8 +1804,13 @@ int MTGAffinityRule::receiveEvent(WEvent * event)
ok = 2;//card enters play ok = 2;//card enters play
if (ok == 2) if (ok == 2)
{//enters play from anywhere {//enters play from anywhere
if (e->from == p->game->graveyard || e->from == p->game->hand || e->from == p->game->library || e->from if (e->from == p->game->graveyard
== p->game->exile || e->from == p->game->stack || e->from == p->game->temp) || e->from == p->game->hand
|| e->from == p->game->library
|| e->from == p->game->exile
|| e->from == p->game->stack
|| e->from == p->game->temp
)
{ {
//--redux effect //--redux effect
MTGGameZone * z = card->controller()->game->hand; MTGGameZone * z = card->controller()->game->hand;
@@ -1817,13 +1850,14 @@ int MTGAffinityRule::receiveEvent(WEvent * event)
for (int j = 0; j < nbcards; ++j) for (int j = 0; j < nbcards; ++j)
{ {
MTGCardInstance * c = z->cards[j]; MTGCardInstance * c = z->cards[j];
if ((c->has(Constants::AFFINITYARTIFACTS) && etype.find("art") != string::npos) || (c->has( if ((c->has(Constants::AFFINITYARTIFACTS) && etype.find("art") != string::npos)
Constants::AFFINITYSWAMP) && etype.find("swa") != string::npos) || (c->has( || (c->has(Constants::AFFINITYSWAMP) && etype.find("swa") != string::npos)
Constants::AFFINITYMOUNTAIN) && etype.find("mou") != string::npos) || (c->has( || (c->has(Constants::AFFINITYMOUNTAIN) && etype.find("mou") != string::npos)
Constants::AFFINITYPLAINS) && etype.find("pla") != string::npos) || (c->has( || (c->has(Constants::AFFINITYPLAINS) && etype.find("pla") != string::npos)
Constants::AFFINITYISLAND) && etype.find("isl") != string::npos) || (c->has( || (c->has(Constants::AFFINITYISLAND) && etype.find("isl") != string::npos)
Constants::AFFINITYFOREST) && etype.find("for") != string::npos) || (c->has( || (c->has(Constants::AFFINITYFOREST) && etype.find("for") != string::npos)
Constants::AFFINITYGREENCREATURES) && etype.find("cre") != string::npos)) || (c->has(Constants::AFFINITYGREENCREATURES) && etype.find("cre") != string::npos)
)
{ {
if (c->getManaCost()->getConvertedCost() > 0) if (c->getManaCost()->getConvertedCost() > 0)
{ {
@@ -1839,9 +1873,15 @@ int MTGAffinityRule::receiveEvent(WEvent * event)
}//--end of redux bracket ok == 2 }//--end of redux bracket ok == 2
//--------- //---------
ok = 0; ok = 0;
if (e->to == p->game->graveyard || e->to == p->game->hand || e->to == p->game->library || e->to == p->game->exile if (e->to == p->game->graveyard
|| e->to == p->game->stack || e->to == p->opponent()->game->battlefield) || e->to == p->game->hand
|| e->to == p->game->library
|| e->to == p->game->exile
|| e->to == p->game->stack
|| e->to == p->opponent()->game->battlefield
)
ok = 3;//card leaves play ok = 3;//card leaves play
if (ok == 3) if (ok == 3)
{//leave play from your battlefield {//leave play from your battlefield
if (e->from == p->game->battlefield) if (e->from == p->game->battlefield)
@@ -1883,13 +1923,14 @@ int MTGAffinityRule::receiveEvent(WEvent * event)
for (int j = 0; j < nbcards; ++j) for (int j = 0; j < nbcards; ++j)
{ {
MTGCardInstance * c = z->cards[j]; MTGCardInstance * c = z->cards[j];
if (c && ((c->has(Constants::AFFINITYARTIFACTS) && etype.find("art") != string::npos) || (c->has( if (c && ((c->has(Constants::AFFINITYARTIFACTS) && etype.find("art") != string::npos)
Constants::AFFINITYSWAMP) && etype.find("swa") != string::npos) || (c->has( || (c->has(Constants::AFFINITYSWAMP) && etype.find("swa") != string::npos)
Constants::AFFINITYMOUNTAIN) && etype.find("mou") != string::npos) || (c->has( || (c->has(Constants::AFFINITYMOUNTAIN) && etype.find("mou") != string::npos)
Constants::AFFINITYPLAINS) && etype.find("pla") != string::npos) || (c->has( || (c->has(Constants::AFFINITYPLAINS) && etype.find("pla") != string::npos)
Constants::AFFINITYISLAND) && etype.find("isl") != string::npos) || (c->has( || (c->has(Constants::AFFINITYISLAND) && etype.find("isl") != string::npos)
Constants::AFFINITYFOREST) && etype.find("for") != string::npos) || (c->has( || (c->has(Constants::AFFINITYFOREST) && etype.find("for") != string::npos)
Constants::AFFINITYGREENCREATURES) && etype.find("cre") != string::npos))) || (c->has(Constants::AFFINITYGREENCREATURES) && etype.find("cre") != string::npos))
)
{ {
if (c->reduxamount > 0) if (c->reduxamount > 0)
{ {
@@ -1911,21 +1952,25 @@ int MTGAffinityRule::receiveEvent(WEvent * event)
} }
return 0; return 0;
} }
ostream& MTGAffinityRule::toString(ostream& out) const ostream& MTGAffinityRule::toString(ostream& out) const
{ {
out << "MTGAffinityRule ::: ("; out << "MTGAffinityRule ::: (";
return MTGAbility::toString(out) << ")"; return MTGAbility::toString(out) << ")";
} }
int MTGAffinityRule::testDestroy() int MTGAffinityRule::testDestroy()
{ {
return 0; return 0;
} }
MTGAffinityRule * MTGAffinityRule::clone() const MTGAffinityRule * MTGAffinityRule::clone() const
{ {
MTGAffinityRule * a = NEW MTGAffinityRule(*this); MTGAffinityRule * a = NEW MTGAffinityRule(*this);
a->isClone = 1; a->isClone = 1;
return a; return a;
} }
//------------------------------------------------------------------- //-------------------------------------------------------------------
MTGTokensCleanup::MTGTokensCleanup(int _id) : MTGTokensCleanup::MTGTokensCleanup(int _id) :