diff --git a/projects/mtg/include/AIMomirPlayer.h b/projects/mtg/include/AIMomirPlayer.h index 3693ccc8d..39ca3fc95 100644 --- a/projects/mtg/include/AIMomirPlayer.h +++ b/projects/mtg/include/AIMomirPlayer.h @@ -6,12 +6,12 @@ class AIMomirPlayer: public AIPlayerBaka { public: - AIMomirPlayer(string file, string fileSmall, string avatarFile, MTGDeck * deck = NULL); + AIMomirPlayer(GameObserver *observer, string file, string fileSmall, string avatarFile, MTGDeck * deck = NULL); int getEfficiency(OrderedAIAction * action); int momir(); int computeActions(); static MTGAbility * momirAbility; - static MTGAbility * getMomirAbility(); + MTGAbility * getMomirAbility(); }; #endif diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index dff566b86..5fea490f8 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -88,7 +88,7 @@ public: virtual int receiveEvent(WEvent * event); virtual void Render(); - AIPlayer(string deckFile, string deckFileSmall, MTGDeck * deck = NULL); + AIPlayer(GameObserver *observer, string deckFile, string deckFileSmall, MTGDeck * deck = NULL); virtual ~AIPlayer(); virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget = NULL, MTGCardInstance * Chosencard = NULL, bool checkonly = false) = 0; @@ -105,9 +105,9 @@ public: class AIPlayerFactory{ public: - AIPlayer * createAIPlayer(MTGAllCards * collection, Player * opponent, int deckid = 0); + AIPlayer * createAIPlayer(GameObserver *observer, MTGAllCards * collection, Player * opponent, int deckid = 0); #ifdef AI_CHANGE_TESTING - AIPlayer * createAIPlayerTest(MTGAllCards * collection, Player * opponent, string folder); + AIPlayer * createAIPlayerTest(GameObserver *observer, MTGAllCards * collection, Player * opponent, string folder); #endif }; diff --git a/projects/mtg/include/AIPlayerBaka.h b/projects/mtg/include/AIPlayerBaka.h index e3dac21b7..305e0e72b 100644 --- a/projects/mtg/include/AIPlayerBaka.h +++ b/projects/mtg/include/AIPlayerBaka.h @@ -114,7 +114,7 @@ class AIPlayerBaka: public AIPlayer{ vectorgotPayments; int deckId; - AIPlayerBaka(string deckFile, string deckfileSmall, string avatarFile, MTGDeck * deck = NULL); + AIPlayerBaka(GameObserver *observer, string deckFile, string deckfileSmall, string avatarFile, MTGDeck * deck = NULL); virtual int Act(float dt); void initTimer(); virtual int computeActions(); @@ -129,4 +129,4 @@ class AIPlayerBaka: public AIPlayer{ virtual int createAbilityTargets(MTGAbility * a, MTGCardInstance * c, RankingContainer& ranking); }; -#endif \ No newline at end of file +#endif diff --git a/projects/mtg/include/AIPlayerBakaB.h b/projects/mtg/include/AIPlayerBakaB.h index 0007c8b2f..f41ae68f4 100644 --- a/projects/mtg/include/AIPlayerBakaB.h +++ b/projects/mtg/include/AIPlayerBakaB.h @@ -49,7 +49,7 @@ protected: public: - AIPlayerBakaB(string deckFile, string deckfileSmall, string avatarFile, MTGDeck * deck = NULL); + AIPlayerBakaB(GameObserver *observer, string deckFile, string deckfileSmall, string avatarFile, MTGDeck * deck = NULL); virtual int Act(float dt); void initTimer(); virtual int computeActions(); @@ -66,4 +66,4 @@ protected: #endif -#endif \ No newline at end of file +#endif diff --git a/projects/mtg/include/ActionLayer.h b/projects/mtg/include/ActionLayer.h index 7af89a0a5..911624a4e 100644 --- a/projects/mtg/include/ActionLayer.h +++ b/projects/mtg/include/ActionLayer.h @@ -29,7 +29,7 @@ public: virtual void Render(); virtual void Update(float dt); bool CheckUserInput(JButton key); - ActionLayer(); + ActionLayer(GameObserver *observer); ~ActionLayer(); int cancelCurrentAction(); ActionElement * isWaitingForAnswer(); diff --git a/projects/mtg/include/ActionStack.h b/projects/mtg/include/ActionStack.h index 62b089026..68e8bd997 100644 --- a/projects/mtg/include/ActionStack.h +++ b/projects/mtg/include/ActionStack.h @@ -83,8 +83,8 @@ public: return TARGET_STACKACTION; } - Interruptible(int inID = 0, bool hasFocus = false) - : PlayGuiObject(40, x, y, inID, hasFocus), state(NOT_RESOLVED), display(0), source(NULL) + Interruptible(GameObserver* observer, int inID = 0, bool hasFocus = false) + : Targetable(observer), PlayGuiObject(40, x, y, inID, hasFocus), state(NOT_RESOLVED), display(0), source(NULL) { } @@ -112,7 +112,7 @@ public: void Render(); virtual ostream& toString(ostream& out) const; virtual const string getDisplayName() const; - NextGamePhase(int id); + NextGamePhase(GameObserver* observer, int id); }; class Spell: public Interruptible @@ -125,8 +125,8 @@ public: ManaCost * cost; int payResult; int computeX(MTGCardInstance * card); - Spell(MTGCardInstance* _source); - Spell(int id, MTGCardInstance* _source, TargetChooser *_tc, ManaCost * _cost, int payResult); + Spell(GameObserver* observer, MTGCardInstance* _source); + Spell(GameObserver* observer, int id, MTGCardInstance* _source, TargetChooser *_tc, ManaCost * _cost, int payResult); ~Spell(); int resolve(); void Render(); @@ -151,7 +151,7 @@ public: void Render(); virtual ostream& toString(ostream& out) const; virtual const string getDisplayName() const; - StackAbility(int id, MTGAbility * _ability); + StackAbility(GameObserver* observer, int id, MTGAbility * _ability); }; class PutInGraveyard: public Interruptible { @@ -161,7 +161,7 @@ public: int resolve(); void Render(); virtual ostream& toString(ostream& out) const; - PutInGraveyard(int id, MTGCardInstance * _card); + PutInGraveyard(GameObserver* observer, int id, MTGCardInstance * _card); }; @@ -173,7 +173,7 @@ public: int resolve(); void Render(); virtual ostream& toString(ostream& out) const; - DrawAction(int id, Player * _player, int _nbcards); + DrawAction(GameObserver* observer, int id, Player * _player, int _nbcards); }; class LifeAction: public Interruptible @@ -184,14 +184,13 @@ public: int resolve(); void Render(); virtual ostream& toString(ostream& out) const; - LifeAction(int id, Damageable * _target, int amount); + LifeAction(GameObserver* observer, int id, Damageable * _target, int amount); }; class ActionStack :public GuiLayer { protected: JQuadPtr pspIcons[8]; - GameObserver* game; int interruptDecision[2]; float timer; int currentState; diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 0b7729971..aaa6571aa 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -115,12 +115,11 @@ private: { replace(theType.begin(), theType.end(), ':', '|'); } - TargetChooserFactory tf; + TargetChooserFactory tf(card->getObserver()); TargetChooser * tc = tf.createTargetChooser(theType.c_str(),NULL); - GameObserver * game = game->GetInstance(); for (int i = 0; i < 2; i++) { - Player * p = game->players[i]; + Player * p = card->getObserver()->players[i]; MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library }; for (int k = 0; k < 4; k++) { @@ -286,9 +285,9 @@ public: TargetChooser * toTcCard, *fromTcCard; bool sourceUntapped; bool isSuspended; - TrCardAddedToZone(int id, MTGCardInstance * source, TargetZoneChooser * toTcZone, TargetChooser * toTcCard, + TrCardAddedToZone(GameObserver* observer, int id, MTGCardInstance * source, TargetZoneChooser * toTcZone, TargetChooser * toTcCard, TargetZoneChooser * fromTcZone = NULL, TargetChooser * fromTcCard = NULL,bool once = false,bool sourceUntapped = false,bool isSuspended = false) : - Trigger(id, source, once), toTcZone(toTcZone), fromTcZone(fromTcZone), toTcCard(toTcCard), fromTcCard(fromTcCard),sourceUntapped(sourceUntapped),isSuspended(isSuspended) + Trigger(observer, id, source, once), toTcZone(toTcZone), fromTcZone(fromTcZone), toTcCard(toTcCard), fromTcCard(fromTcCard),sourceUntapped(sourceUntapped),isSuspended(isSuspended) { }; @@ -335,8 +334,8 @@ class TrCardTapped: public Trigger { public: bool tap; - TrCardTapped(int id, MTGCardInstance * source, TargetChooser * tc, bool tap = true, bool once = false) : - Trigger(id, source, once, tc), tap(tap) + TrCardTapped(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc, bool tap = true, bool once = false) : + Trigger(observer, id, source, once, tc), tap(tap) { } @@ -360,8 +359,8 @@ class TrCardTappedformana: public Trigger { public: bool tap; - TrCardTappedformana(int id, MTGCardInstance * source, TargetChooser * tc, bool tap = true, bool once = false) : - Trigger(id, source, once, tc), tap(tap) + TrCardTappedformana(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc, bool tap = true, bool once = false) : + Trigger(observer, id, source, once, tc), tap(tap) { } @@ -395,10 +394,10 @@ public: bool notBlockedTrigger; bool attackBlockedTrigger; bool blockingTrigger; - TrCombatTrigger(int id, MTGCardInstance * source, TargetChooser * tc,TargetChooser * fromTc = NULL, + TrCombatTrigger(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc,TargetChooser * fromTc = NULL, bool once = false,bool limitOnceATurn = false,bool sourceUntapped = false,bool opponentPoisoned = false, bool attackingTrigger = false,bool attackedAloneTrigger = false,bool notBlockedTrigger = false,bool attackBlockedTrigger = false,bool blockingTrigger = false) : - Trigger(id, source,once, tc), fromTc(fromTc),limitOnceATurn(limitOnceATurn),sourceUntapped(sourceUntapped),opponentPoisoned(opponentPoisoned), + Trigger(observer, id, source,once, tc), fromTc(fromTc),limitOnceATurn(limitOnceATurn),sourceUntapped(sourceUntapped),opponentPoisoned(opponentPoisoned), attackingTrigger(attackingTrigger),attackedAloneTrigger(attackedAloneTrigger),notBlockedTrigger(notBlockedTrigger), attackBlockedTrigger(attackBlockedTrigger),blockingTrigger(blockingTrigger) { @@ -504,8 +503,8 @@ class TrcardDrawn: public Trigger { public: - TrcardDrawn(int id, MTGCardInstance * source, TargetChooser * tc,bool once = false) : - Trigger(id, source,once, tc) + TrcardDrawn(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc,bool once = false) : + Trigger(observer, id, source,once, tc) { } @@ -527,8 +526,8 @@ public: class TrCardSacrificed: public Trigger { public: - TrCardSacrificed(int id, MTGCardInstance * source, TargetChooser * tc,bool once = false) : - Trigger(id, source, once, tc) + TrCardSacrificed(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc,bool once = false) : + Trigger(observer, id, source, once, tc) { } @@ -550,8 +549,8 @@ public: class TrCardDiscarded: public Trigger { public: - TrCardDiscarded(int id, MTGCardInstance * source, TargetChooser * tc,bool once = false) : - Trigger(id, source, once, tc) + TrCardDiscarded(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc,bool once = false) : + Trigger(observer, id, source, once, tc) { } @@ -577,8 +576,8 @@ public: bool sourceUntapped; bool limitOnceATurn; int triggeredTurn; - TrDamaged(int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL, int type = 0,bool sourceUntapped = false,bool limitOnceATurn = false,bool once = false) : - Trigger(id, source, once, tc), fromTc(fromTc), type(type) , sourceUntapped(sourceUntapped),limitOnceATurn(limitOnceATurn) + TrDamaged(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL, int type = 0,bool sourceUntapped = false,bool limitOnceATurn = false,bool once = false) : + Trigger(observer, id, source, once, tc), fromTc(fromTc), type(type) , sourceUntapped(sourceUntapped),limitOnceATurn(limitOnceATurn) { triggeredTurn = -1; } @@ -587,8 +586,7 @@ public: { WEventDamage * e = dynamic_cast (event); if (!e) return 0; - GameObserver * g = GameObserver::GetInstance(); - if (limitOnceATurn && triggeredTurn == g->turn) + if (limitOnceATurn && triggeredTurn == game->turn) return 0; if (sourceUntapped && source->isTapped() == 1) return 0; @@ -599,7 +597,7 @@ public: e->damage->target->thatmuch = e->damage->damage; e->damage->source->thatmuch = e->damage->damage; this->source->thatmuch = e->damage->damage; - triggeredTurn = g->turn; + triggeredTurn = game->turn; return 1; } @@ -621,8 +619,8 @@ public: TargetChooser * fromTc; int type;//this allows damagenoncombat and combatdamage to share this trigger bool sourceUntapped; - TrLifeGained(int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL, int type = 0,bool sourceUntapped = false,bool once = false) : - Trigger(id, source, once , tc), fromTc(fromTc), type(type) , sourceUntapped(sourceUntapped) + TrLifeGained(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL, int type = 0,bool sourceUntapped = false,bool once = false) : + Trigger(observer, id, source, once , tc), fromTc(fromTc), type(type) , sourceUntapped(sourceUntapped) { } @@ -658,8 +656,8 @@ class TrVampired: public Trigger { public: TargetChooser * fromTc; - TrVampired(int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL,bool once = false) : - Trigger(id, source, once, tc), fromTc(fromTc) + TrVampired(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL,bool once = false) : + Trigger(observer, id, source, once, tc), fromTc(fromTc) { } @@ -697,8 +695,8 @@ class TrTargeted: public Trigger public: TargetChooser * fromTc; int type; - TrTargeted(int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL, int type = 0,bool once = false) : - Trigger(id, source, once, tc), fromTc(fromTc), type(type) + TrTargeted(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc, TargetChooser * fromTc = NULL, int type = 0,bool once = false) : + Trigger(observer, id, source, once, tc), fromTc(fromTc), type(type) { } @@ -729,8 +727,8 @@ class TrCounter: public Trigger public: Counter * counter; int type; - TrCounter(int id, MTGCardInstance * source, Counter * counter, TargetChooser * tc, int type = 0,bool once = false) : - Trigger(id, source, once, tc),counter(counter), type(type) + TrCounter(GameObserver* observer, int id, MTGCardInstance * source, Counter * counter, TargetChooser * tc, int type = 0,bool once = false) : + Trigger(observer, id, source, once, tc),counter(counter), type(type) { } @@ -770,7 +768,7 @@ public: bool mIsImage; int mLimit; - ATutorialMessage(MTGCardInstance * source, string message, int limit = 1); + ATutorialMessage(GameObserver* observer, MTGCardInstance * source, string message, int limit = 1); void Update(float dt); bool CheckUserInput(JButton key); @@ -801,7 +799,7 @@ public: string name; string menu; - AACounter(int id, MTGCardInstance * source, MTGCardInstance * target,string counterstring, const char * _name, int power, int toughness, int nb,int maxNb = 0, + AACounter(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target,string counterstring, const char * _name, int power, int toughness, int nb,int maxNb = 0, ManaCost * cost = NULL); int resolve(); @@ -820,7 +818,7 @@ public: string menu; bool all; - AARemoveAllCounter(int id, MTGCardInstance * source, MTGCardInstance * target, const char * _name, int power, int toughness, int nb, + AARemoveAllCounter(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, const char * _name, int power, int toughness, int nb, bool all,ManaCost * cost = NULL); int resolve(); @@ -832,7 +830,7 @@ public: class AAResetDamage: public ActivatedAbility { public: - AAResetDamage(int id, MTGCardInstance * source, MTGCardInstance * target, ManaCost * cost = NULL); + AAResetDamage(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, ManaCost * cost = NULL); int resolve(); const char* getMenuText(); AAResetDamage * clone() const; @@ -842,7 +840,7 @@ class AAFizzler: public ActivatedAbility { public: - AAFizzler(int _id, MTGCardInstance * card, Spell * _target, ManaCost * _cost = NULL); + AAFizzler(GameObserver* observer, int _id, MTGCardInstance * card, Spell * _target, ManaCost * _cost = NULL); int resolve(); const char * getMenuText(); AAFizzler* clone() const; @@ -858,7 +856,7 @@ public: MTGAbility * delayedAbility; int type; string Cond; - IfThenAbility(int _id,MTGAbility * delayedAbility = NULL, MTGCardInstance * _source=NULL, Targetable * target = NULL, int type = 1,string Cond = ""); + IfThenAbility(GameObserver* observer, int _id,MTGAbility * delayedAbility = NULL, MTGCardInstance * _source=NULL, Targetable * target = NULL, int type = 1,string Cond = ""); int resolve(); const char * getMenuText(); IfThenAbility * clone() const; @@ -874,7 +872,7 @@ public: Player * previousInterrupter; MTGAbility * mClone; - MayAbility(int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must = false); + MayAbility(GameObserver* observer, int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must = false); void Update(float dt); @@ -900,7 +898,7 @@ public: MTGAbility * mClone; vectorabilities; Player * who; - MenuAbility(int _id, Targetable * target, MTGCardInstance * _source, bool must = false, vectorabilities = vector(),Player * who = NULL); + MenuAbility(GameObserver* observer, int _id, Targetable * target, MTGCardInstance * _source, bool must = false, vectorabilities = vector(),Player * who = NULL); void Update(float dt); int resolve(); const char * getMenuText(); @@ -916,7 +914,7 @@ public: class AAProliferate: public ActivatedAbility { public: - AAProliferate(int id, MTGCardInstance * source, Targetable * target,ManaCost * cost = NULL); + AAProliferate(GameObserver* observer, int id, MTGCardInstance * source, Targetable * target,ManaCost * cost = NULL); int resolve(); const char* getMenuText(); AAProliferate * clone() const; @@ -931,7 +929,7 @@ public: //Maintains abilities created by this instance, for cleanup vector clones; - MultiAbility(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost); + MultiAbility(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost); int Add(MTGAbility * ability); int resolve(); int addToGame(); @@ -950,7 +948,7 @@ public: string newName; string castRestriction; - GenericActivatedAbility(string newName,string castRestriction,int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", + GenericActivatedAbility(GameObserver* observer, string newName,string castRestriction,int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", int restrictions = 0, MTGGameZone * dest = NULL); int resolve(); const char * getMenuText(); @@ -966,7 +964,7 @@ public: class AACopier: public ActivatedAbility { public: - AACopier(int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL); + AACopier(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL); int resolve(); const char * getMenuText(); AACopier * clone() const; @@ -975,7 +973,7 @@ public: class AAPhaseOut: public ActivatedAbility { public: - AAPhaseOut(int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL); + AAPhaseOut(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL); int resolve(); const char * getMenuText(); AAPhaseOut * clone() const; @@ -989,7 +987,7 @@ public: list awith; list colors; - AACloner(int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL, int who = 0, + AACloner(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL, int who = 0, string abilitiesStringList = ""); int resolve(); const char * getMenuText(); @@ -1004,7 +1002,7 @@ class AAMover: public ActivatedAbility public: string destination; MTGAbility * andAbility; - AAMover(int _id, MTGCardInstance * _source, MTGCardInstance * _target, string dest, ManaCost * _cost = NULL); + AAMover(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, string dest, ManaCost * _cost = NULL); MTGGameZone * destinationZone(Targetable * target = NULL); int resolve(); const char * getMenuText(); @@ -1018,7 +1016,7 @@ public: class AABuryCard: public ActivatedAbility { public: - AABuryCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target); + AABuryCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target); int resolve(); const char * getMenuText(); AABuryCard * clone() const; @@ -1027,7 +1025,7 @@ public: class AADestroyCard: public ActivatedAbility { public: - AADestroyCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target); + AADestroyCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target); int resolve(); const char * getMenuText(); AADestroyCard * clone() const; @@ -1036,7 +1034,7 @@ public: class AASacrificeCard: public ActivatedAbility { public: - AASacrificeCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target); + AASacrificeCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target); int resolve(); const char * getMenuText(); AASacrificeCard * clone() const; @@ -1045,7 +1043,7 @@ public: class AADiscardCard: public ActivatedAbility { public: - AADiscardCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target); + AADiscardCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target); int resolve(); const char * getMenuText(); AADiscardCard * clone() const; @@ -1063,7 +1061,7 @@ public: string newName; string castRestriction; - GenericTargetAbility(string newName, string castRestriction, int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, ManaCost * _cost = NULL, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", int restrictions = 0, MTGGameZone * dest = NULL); + GenericTargetAbility(GameObserver* observer, string newName, string castRestriction, int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, ManaCost * _cost = NULL, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", int restrictions = 0, MTGGameZone * dest = NULL); const char * getMenuText(); ~GenericTargetAbility(); GenericTargetAbility * clone() const; @@ -1079,8 +1077,8 @@ public: class ACycle: public ActivatedAbility { public: - ACycle(int _id, MTGCardInstance * card, Targetable * _target) : - ActivatedAbility(_id, card) + ACycle(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target) : + ActivatedAbility(observer, _id, card) { target = _target; } @@ -1088,7 +1086,6 @@ public: int resolve() { WEvent * e = NEW WEventCardDiscard(source); - GameObserver * game = GameObserver::GetInstance(); game->receiveEvent(e); source->controller()->game->putInGraveyard(source); source->controller()->game->drawFromLibrary(); @@ -1112,8 +1109,8 @@ public: class ANinja: public ActivatedAbility { public: - ANinja(int _id, MTGCardInstance * card, Targetable * _target) : - ActivatedAbility(_id, card) + ANinja(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target) : + ActivatedAbility(observer, _id, card) { target = _target; } @@ -1125,7 +1122,7 @@ public: return 0; MTGCardInstance * copy = _target->controller()->game->putInZone(_target,_target->currentZone, source->controller()->game->temp); - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(game, copy); spell->resolve(); MTGCardInstance * newcard = spell->source; newcard->summoningSickness = 0; @@ -1151,8 +1148,8 @@ public: class ACombatRemoval: public ActivatedAbility { public: - ACombatRemoval(int _id, MTGCardInstance * card, Targetable * _target) : - ActivatedAbility(_id, card) + ACombatRemoval(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target) : + ActivatedAbility(observer, _id, card) { target = _target; } @@ -1186,7 +1183,7 @@ public: string nbcardsStr; - AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost,string nbcardsStr, int who = + AADrawer(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost,string nbcardsStr, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -1206,7 +1203,7 @@ public: int zoneId; // identifier of the zone id impacted by the restriction Player * targetPlayer; // Reference to the player impacted by the restriction (for restriction deletion purpose) - ACastRestriction(int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who = TargetChooser::UNSET); + ACastRestriction(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who = TargetChooser::UNSET); int addToGame(); int destroy(); const char * getMenuText(); @@ -1222,7 +1219,7 @@ public: ACastRestriction * ability; - AInstantCastRestrictionUEOT(int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who = TargetChooser::UNSET); + AInstantCastRestrictionUEOT(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); AInstantCastRestrictionUEOT * clone() const; @@ -1234,7 +1231,7 @@ class AALifer: public ActivatedAbilityTP { public: string life_s; - AALifer(int _id, MTGCardInstance * card, Targetable * _target,string life_s, ManaCost * _cost = NULL, + AALifer(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target,string life_s, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -1247,7 +1244,7 @@ public: class AAWinGame: public ActivatedAbilityTP { public: - AAWinGame(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost = NULL, int who = + AAWinGame(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -1266,8 +1263,8 @@ public: int modifier; int ability; bool value_before_modification; - ABasicAbilityModifier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int _modifier = 1) : - MTGAbility(_id, _source, _target), modifier(_modifier), ability(_ability) + ABasicAbilityModifier(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int _modifier = 1) : + MTGAbility(observer, _id, _source, _target), modifier(_modifier), ability(_ability) { aType = MTGAbility::STANDARDABILITYGRANT; abilitygranted = ability; @@ -1316,8 +1313,8 @@ public: bool stateBeforeActivation; int ability; int value; - AInstantBasicAbilityModifierUntilEOT(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int value) - : InstantAbility(_id, _source, _target), ability(_ability), value(value) + AInstantBasicAbilityModifierUntilEOT(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int value) + : InstantAbility(observer, _id, _source, _target), ability(_ability), value(value) { aType = MTGAbility::STANDARDABILITYGRANT; abilitygranted = ability; @@ -1364,12 +1361,12 @@ class ABasicAbilityAuraModifierUntilEOT: public ActivatedAbility { public: AInstantBasicAbilityModifierUntilEOT * ability; - ABasicAbilityAuraModifierUntilEOT(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost, + ABasicAbilityAuraModifierUntilEOT(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost, int _ability, int _value = 1) : - ActivatedAbility(_id, _source, _cost, 0) + ActivatedAbility(observer, _id, _source, _cost, 0) { target = _target; - ability = NEW AInstantBasicAbilityModifierUntilEOT(_id, _source, _target, _ability, _value); + ability = NEW AInstantBasicAbilityModifierUntilEOT(observer, _id, _source, _target, _ability, _value); aType = MTGAbility::STANDARDABILITYGRANT; abilitygranted = _ability; } @@ -1421,13 +1418,13 @@ public: int life; MTGCardInstance * lastUsedOn; MTGCardInstance * lastChecked; - ASpellCastLife(int id, MTGCardInstance * _source, CardDescriptor _trigger, ManaCost * _cost, int _life) : - MTGAbility(id, _source), trigger(_trigger), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) + ASpellCastLife(GameObserver* observer, int id, MTGCardInstance * _source, CardDescriptor _trigger, ManaCost * _cost, int _life) : + MTGAbility(observer, id, _source), trigger(_trigger), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) { aType = MTGAbility::LIFER; } - ASpellCastLife(int id, MTGCardInstance * _source, int color, ManaCost * _cost, int _life) : - MTGAbility(id, _source), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) + ASpellCastLife(GameObserver* observer, int id, MTGCardInstance * _source, int color, ManaCost * _cost, int _life) : + MTGAbility(observer, id, _source), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) { trigger.setColor(color); } @@ -1487,8 +1484,8 @@ class AUnBlocker: public MTGAbility { public: ManaCost * cost; - AUnBlocker(int id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost) : - MTGAbility(id, _source, _target), cost(_cost) + AUnBlocker(GameObserver* observer, int id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost) : + MTGAbility(observer, id, _source, _target), cost(_cost) { } @@ -1531,8 +1528,8 @@ class AProtectionFrom: public MTGAbility public: TargetChooser * fromTc; string tcstr; - AProtectionFrom(int id, MTGCardInstance * _source, MTGCardInstance * _target, TargetChooser *fromTc,string tcstr) : - MTGAbility(id, _source, _target), fromTc(fromTc),tcstr(tcstr) + AProtectionFrom(GameObserver* observer, int id, MTGCardInstance * _source, MTGCardInstance * _target, TargetChooser *fromTc,string tcstr) : + MTGAbility(observer, id, _source, _target), fromTc(fromTc),tcstr(tcstr) { } @@ -1575,8 +1572,8 @@ class ACantBeTargetFrom: public MTGAbility { public: TargetChooser * fromTc; - ACantBeTargetFrom(int id, MTGCardInstance * _source, MTGCardInstance * _target, TargetChooser *fromTc) : - MTGAbility(id, _source, _target), fromTc(fromTc) + ACantBeTargetFrom(GameObserver* observer, int id, MTGCardInstance * _source, MTGCardInstance * _target, TargetChooser *fromTc) : + MTGAbility(observer, id, _source, _target), fromTc(fromTc) { } @@ -1612,8 +1609,8 @@ class ACantBeBlockedBy: public MTGAbility { public: TargetChooser * fromTc; - ACantBeBlockedBy(int id, MTGCardInstance * _source, MTGCardInstance * _target, TargetChooser *fromTc) : - MTGAbility(id, _source, _target), fromTc(fromTc) + ACantBeBlockedBy(GameObserver* observer, int id, MTGCardInstance * _source, MTGCardInstance * _target, TargetChooser *fromTc) : + MTGAbility(observer, id, _source, _target), fromTc(fromTc) { } @@ -1652,8 +1649,8 @@ public: WParsedPT * wppt; string PT; bool nonstatic; - APowerToughnessModifier(int id, MTGCardInstance * _source, MTGCardInstance * _target, WParsedPT * wppt,string PT,bool nonstatic) : - MTGAbility(id, _source, _target), wppt(wppt),PT(PT),nonstatic(nonstatic) + APowerToughnessModifier(GameObserver* observer, int id, MTGCardInstance * _source, MTGCardInstance * _target, WParsedPT * wppt,string PT,bool nonstatic) : + MTGAbility(observer, id, _source, _target), wppt(wppt),PT(PT),nonstatic(nonstatic) { aType = MTGAbility::STANDARD_PUMP; } @@ -1719,8 +1716,8 @@ public: class GenericInstantAbility: public InstantAbility, public NestedAbility { public: - GenericInstantAbility(int _id, MTGCardInstance * _source, Damageable * _target, MTGAbility * ability) : - InstantAbility(_id, _source, _target), NestedAbility(ability) + GenericInstantAbility(GameObserver* observer, int _id, MTGCardInstance * _source, Damageable * _target, MTGAbility * ability) : + InstantAbility(observer, _id, _source, _target), NestedAbility(ability) { ability->target = _target; } @@ -1761,8 +1758,8 @@ class ACircleOfProtection: public TargetAbility protected: map current; public: - ACircleOfProtection(int _id, MTGCardInstance * source, int _color) : - TargetAbility(_id, source, NEW SpellOrPermanentTargetChooser(source, _color), NEW ManaCost(), 0) + ACircleOfProtection(GameObserver* observer, int _id, MTGCardInstance * source, int _color) : + TargetAbility(observer, _id, source, NEW SpellOrPermanentTargetChooser(source->owner->getObserver(), source, _color), NEW ManaCost(), 0) { getCost()->add(Constants::MTG_COLOR_ARTIFACT, 1); tc->targetter = NULL; //Circle of Protection doesn't use the word "source" @@ -1777,7 +1774,7 @@ public: _target = starget->source; } if (!_target) return 0; - REDamagePrevention * re = NEW REDamagePrevention(this, NEW CardTargetChooser(_target, NULL), NEW PlayerTargetChooser(0, 1, + REDamagePrevention * re = NEW REDamagePrevention(this, NEW CardTargetChooser(game, _target, NULL), NEW PlayerTargetChooser(game, 0, 1, source->controller())); current[re] = 1; game->replacementEffects->add(re); @@ -1821,8 +1818,8 @@ public: class AStandardRegenerate: public ActivatedAbility { public: - AStandardRegenerate(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL) : - ActivatedAbility(_id, _source, _cost, 0) + AStandardRegenerate(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL) : + ActivatedAbility(observer, _id, _source, _cost, 0) { target = _target; aType = MTGAbility::STANDARD_REGENERATE; @@ -1859,9 +1856,9 @@ public: int life; int phase; int onlyIfTargetTapped; - ARegularLifeModifierAura(int id, MTGCardInstance * _source, MTGCardInstance * _target, int _phase, int _life, + ARegularLifeModifierAura(GameObserver* observer, int id, MTGCardInstance * _source, MTGCardInstance * _target, int _phase, int _life, int _onlyIfTargetTapped = 0) : - MTGAbility(id, _source, _target), life(_life), phase(_phase), onlyIfTargetTapped(_onlyIfTargetTapped) + MTGAbility(observer, id, _source, _target), life(_life), phase(_phase), onlyIfTargetTapped(_onlyIfTargetTapped) { } @@ -1900,8 +1897,8 @@ class AExalted: public TriggeredAbility public: int power, toughness; MTGCardInstance * luckyWinner; - AExalted(int _id, MTGCardInstance * _source, int _power = 1, int _toughness = 1) : - TriggeredAbility(_id, _source), power(_power), toughness(_toughness) + AExalted(GameObserver* observer, int _id, MTGCardInstance * _source, int _power = 1, int _toughness = 1) : + TriggeredAbility(observer, _id, _source), power(_power), toughness(_toughness) { luckyWinner = NULL; } @@ -1968,9 +1965,9 @@ public: int mini, maxi; bool miniFound, maxiFound, compareZone; int amount[2]; - AAsLongAs(int _id, MTGCardInstance * _source, Damageable * _target, TargetChooser * _tc, int _includeSelf, + AAsLongAs(GameObserver* observer, int _id, MTGCardInstance * _source, Damageable * _target, TargetChooser * _tc, int _includeSelf, MTGAbility * ability, int mini = 0, int maxi = 0,bool miniFound = false,bool maxiFound = false,bool compareZone = false) : - ListMaintainerAbility(_id, _source, _target), NestedAbility(ability), mini(mini), maxi(maxi),miniFound(miniFound),maxiFound(maxiFound),compareZone(compareZone) + ListMaintainerAbility(observer, _id, _source, _target), NestedAbility(ability), mini(mini), maxi(maxi),miniFound(miniFound),maxiFound(maxiFound),compareZone(compareZone) { for (int j = 0; j < 2; j++) amount[j] = 0; @@ -1993,7 +1990,6 @@ public: void findMatchingAmount() { int Value = 0; - GameObserver * game = game->GetInstance(); for (int i = 0; i < 2; i++) { Player * p = game->players[i]; @@ -2136,8 +2132,8 @@ public: int includeSelf; map abilities; - ALord(int _id, MTGCardInstance * card, TargetChooser * _tc, int _includeSelf, MTGAbility * a) : - ListMaintainerAbility(_id, card), NestedAbility(a) + ALord(GameObserver* observer, int _id, MTGCardInstance * card, TargetChooser * _tc, int _includeSelf, MTGAbility * a) : + ListMaintainerAbility(observer, _id, card), NestedAbility(a) { tc = _tc; tc->targetter = NULL; @@ -2195,7 +2191,7 @@ public: } if (oneShot) { - MTGAbility * wrapper = NEW GenericInstantAbility(1, source, d, a); + MTGAbility * wrapper = NEW GenericInstantAbility(game, 1, source, d, a); wrapper->addToGame(); } else @@ -2256,8 +2252,8 @@ public: int includeSelf; map skills; - ATeach(int _id, MTGCardInstance * card, TargetChooser * _tc, int _includeSelf, MTGAbility * a) : - ListMaintainerAbility(_id, card), NestedAbility(a) + ATeach(GameObserver* observer, int _id, MTGCardInstance * card, TargetChooser * _tc, int _includeSelf, MTGAbility * a) : + ListMaintainerAbility(observer, _id, card), NestedAbility(a) { tc = _tc; tc->targetter = NULL; @@ -2340,7 +2336,7 @@ public: } if (oneShot) { - MTGAbility * wrapper = NEW GenericInstantAbility(1, source, d, a); + MTGAbility * wrapper = NEW GenericInstantAbility(game, 1, source, d, a); wrapper->addToGame(); } else @@ -2370,7 +2366,7 @@ public: class AAConnect: public InstantAbility { public: - AAConnect(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); + AAConnect(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); int resolve(); AAConnect * clone() const; }; @@ -2380,9 +2376,9 @@ class AEquip: public TargetAbility { public: vector currentAbilities; - AEquip(int _id, MTGCardInstance * _source, ManaCost * _cost = NULL, int restrictions = + AEquip(GameObserver* observer, int _id, MTGCardInstance * _source, ManaCost * _cost = NULL, int restrictions = ActivatedAbility::AS_SORCERY) : - TargetAbility(_id, _source, NULL, _cost, restrictions) + TargetAbility(observer, _id, _source, NULL, _cost, restrictions) { aType = MTGAbility::STANDARD_EQUIP; } @@ -2409,7 +2405,7 @@ public: SAFE_DELETE(a); continue; } - GameObserver::GetInstance()->removeObserver(currentAbilities[i]); + game->removeObserver(currentAbilities[i]); } currentAbilities.clear(); return 1; @@ -2421,7 +2417,7 @@ public: source->target->equipment += 1; source->parentCards.push_back(equipped); source->target->childrenCards.push_back((MTGCardInstance*)source); - AbilityFactory af; + AbilityFactory af(game); af.getAbilities(¤tAbilities, NULL, source); for (size_t i = 0; i < currentAbilities.size(); ++i) { @@ -2501,9 +2497,9 @@ public: MTGCardInstance * myToken; vector currentAbilities; Player * tokenReciever; - ATokenCreator(int _id, MTGCardInstance * _source, Targetable * _target, ManaCost * _cost, int tokenId,string starfound, WParsedInt * multiplier = NULL, + ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, ManaCost * _cost, int tokenId,string starfound, WParsedInt * multiplier = NULL, int who = 0,bool aLivingWeapon = false) : - ActivatedAbility(_id, _source, _cost, 0), tokenId(tokenId), starfound(starfound),multiplier(multiplier), who(who),aLivingWeapon(aLivingWeapon) + ActivatedAbility(observer, _id, _source, _cost, 0), tokenId(tokenId), starfound(starfound),multiplier(multiplier), who(who),aLivingWeapon(aLivingWeapon) { if (!multiplier) this->multiplier = NEW WParsedInt(1); MTGCard * card = MTGCollection()->getCardById(tokenId); @@ -2511,9 +2507,9 @@ public: battleReady = false; } - ATokenCreator(int _id, MTGCardInstance * _source, Targetable * _target, ManaCost * _cost, string sname, string stypes, int _power, int _toughness, + ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, ManaCost * _cost, string sname, string stypes, int _power, int _toughness, string sabilities, string starfound,WParsedInt * multiplier = NULL, int who = 0,bool aLivingWeapon = false,string spt = "") : - ActivatedAbility(_id, _source, _cost, 0),sabilities(sabilities),starfound(starfound), multiplier(multiplier), who(who),aLivingWeapon(aLivingWeapon),spt(spt) + ActivatedAbility(observer, _id, _source, _cost, 0),sabilities(sabilities),starfound(starfound), multiplier(multiplier), who(who),aLivingWeapon(aLivingWeapon),spt(spt) { power = _power; toughness = _toughness; @@ -2622,7 +2618,7 @@ public: } setTokenOwner(); tokenReciever->game->temp->addCard(myToken); - Spell * spell = NEW Spell(myToken); + Spell * spell = NEW Spell(game, myToken); spell->resolve(); myToken = spell->source; spell->source->owner = tokenReciever; @@ -2665,10 +2661,9 @@ public: void livingWeaponToken(MTGCardInstance * card) { - GameObserver * g = GameObserver::GetInstance(); - for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) + for (size_t i = 1; i < game->mLayers->actionLayer()->mObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); + MTGAbility * a = ((MTGAbility *) game->mLayers->actionLayer()->mObjects[i]); if (a->aType == MTGAbility::STANDARD_EQUIP && a->source == source) { AEquip* ae = dynamic_cast(a); @@ -2722,9 +2717,9 @@ public: int mini; int maxi; map abilities; - AForeach(int _id, MTGCardInstance * card, Damageable * _target, TargetChooser * _tc, int _includeSelf, MTGAbility * a, + AForeach(GameObserver* observer, int _id, MTGCardInstance * card, Damageable * _target, TargetChooser * _tc, int _includeSelf, MTGAbility * a, int mini = 0, int maxi = 0) : - ListMaintainerAbility(_id, card, _target), NestedAbility(a), mini(mini), maxi(maxi) + ListMaintainerAbility(observer, _id, card, _target), NestedAbility(a), mini(mini), maxi(maxi) { tc = _tc; tc->targetter = NULL; @@ -2813,8 +2808,8 @@ class AThis: public MTGAbility, public NestedAbility public: MTGAbility * a; ThisDescriptor * td; - AThis(int _id, MTGCardInstance * _source, Damageable * _target, ThisDescriptor * _td, MTGAbility * ability) : - MTGAbility(_id, _source, _target), NestedAbility(ability) + AThis(GameObserver* observer, int _id, MTGCardInstance * _source, Damageable * _target, ThisDescriptor * _td, MTGAbility * ability) : + MTGAbility(observer, _id, _source, _target), NestedAbility(ability) { td = _td; ability->source = source; @@ -2899,8 +2894,8 @@ class AThisForEach: public MTGAbility, public NestedAbility public: ThisDescriptor * td; vector abilities; - AThisForEach(int _id, MTGCardInstance * _source, Damageable * _target, ThisDescriptor * _td, MTGAbility * ability) : - MTGAbility(_id, _source, _target), NestedAbility(ability) + AThisForEach(GameObserver* observer, int _id, MTGCardInstance * _source, Damageable * _target, ThisDescriptor * _td, MTGAbility * ability) : + MTGAbility(observer, _id, _source, _target), NestedAbility(ability) { td = _td; ability->source = source; @@ -3005,7 +3000,7 @@ class AASetHand: public ActivatedAbilityTP public: int hand; - AASetHand(int _id, MTGCardInstance * _source, Targetable * _target, int hand, ManaCost * _cost = NULL, + AASetHand(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, int hand, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -3019,7 +3014,7 @@ class AALifeSet: public ActivatedAbilityTP public: WParsedInt * life; - AALifeSet(int _id, MTGCardInstance * _source, Targetable * _target, WParsedInt * life, ManaCost * _cost = NULL, + AALifeSet(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, WParsedInt * life, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -3035,7 +3030,7 @@ class AADamager: public ActivatedAbilityTP public: string d; - AADamager(int _id, MTGCardInstance * _source, Targetable * _target, string d, ManaCost * _cost = NULL, + AADamager(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, string d, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -3050,7 +3045,7 @@ class AADamagePrevent: public ActivatedAbilityTP public: int preventing; - AADamagePrevent(int _id, MTGCardInstance * _source, Targetable * _target, int preventing, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); + AADamagePrevent(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, int preventing, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); AADamagePrevent * clone() const; @@ -3063,7 +3058,7 @@ class AAAlterPoison: public ActivatedAbilityTP public: int poison; - AAAlterPoison(int _id, MTGCardInstance * _source, Targetable * _target, int poison, ManaCost * _cost = NULL, + AAAlterPoison(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, int poison, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -3075,11 +3070,11 @@ class TADamager: public TargetAbility { public: - TADamager(int id, MTGCardInstance * card, ManaCost * _cost, string d, TargetChooser * _tc = NULL) : - TargetAbility(id, card, _tc, _cost, 0) + TADamager(GameObserver* observer, int id, MTGCardInstance * card, ManaCost * _cost, string d, TargetChooser * _tc = NULL) : + TargetAbility(observer, id, card, _tc, _cost, 0) { - if (!tc) tc = NEW DamageableTargetChooser(card); - ability = NEW AADamager(id, card, NULL, d); + if (!tc) tc = NEW DamageableTargetChooser(game, card); + ability = NEW AADamager(game, id, card, NULL, d); } TADamager * clone() const @@ -3092,7 +3087,7 @@ public: class AATapper: public ActivatedAbility { public: - AATapper(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); + AATapper(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); int resolve(); const char * getMenuText(); AATapper * clone() const; @@ -3102,7 +3097,7 @@ public: class AAUntapper: public ActivatedAbility { public: - AAUntapper(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); + AAUntapper(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); int resolve(); const char * getMenuText(); AAUntapper * clone() const; @@ -3114,7 +3109,7 @@ class AAWhatsMax: public ActivatedAbility public: int value; - AAWhatsMax(int id, MTGCardInstance * card, MTGCardInstance * source, ManaCost * _cost = NULL, int value = 0); + AAWhatsMax(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * source, ManaCost * _cost = NULL, int value = 0); int resolve(); AAWhatsMax * clone() const; }; @@ -3123,7 +3118,7 @@ public: class AAFrozen: public ActivatedAbility { public: - AAFrozen(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); + AAFrozen(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); int resolve(); const char * getMenuText(); AAFrozen * clone() const; @@ -3133,7 +3128,7 @@ class AANewTarget: public ActivatedAbility { public: bool retarget; - AANewTarget(int id, MTGCardInstance * card, MTGCardInstance * _target,bool retarget = false, ManaCost * _cost = NULL); + AANewTarget(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target,bool retarget = false, ManaCost * _cost = NULL); int resolve(); const char * getMenuText(); AANewTarget * clone() const; @@ -3143,7 +3138,7 @@ class AAMorph: public ActivatedAbility { public: vector currentAbilities; - AAMorph(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); + AAMorph(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); int resolve(); int testDestroy(); const char * getMenuText(); @@ -3206,7 +3201,7 @@ MTGAbility * storedAbility; MTGAbility * clonedStored; string menu; - AADynamic(int id, MTGCardInstance * card, Damageable * _target,int type = 0,int effect = 0,int who = 0,int amountsource = 1,MTGAbility * storedAbility = NULL, ManaCost * _cost = NULL); + AADynamic(GameObserver* observer, int id, MTGCardInstance * card, Damageable * _target,int type = 0,int effect = 0,int who = 0,int amountsource = 1,MTGAbility * storedAbility = NULL, ManaCost * _cost = NULL); int resolve(); int activateStored(); const char * getMenuText(); @@ -3220,8 +3215,8 @@ class ASwapPT: public InstantAbility public: int oldpower; int oldtoughness; - ASwapPT(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - InstantAbility(_id, _source, _target) + ASwapPT(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + InstantAbility(observer, _id, _source, _target) { target = _target; } @@ -3283,9 +3278,9 @@ public: int controller; int nbcards; MTGGameZone * zone; - ALifeZoneLink(int _id, MTGCardInstance * card, int _phase, int _condition, int _life = -1, int _controller = 0, + ALifeZoneLink(GameObserver* observer, int _id, MTGCardInstance * card, int _phase, int _condition, int _life = -1, int _controller = 0, MTGGameZone * _zone = NULL) : - MTGAbility(_id, card) + MTGAbility(observer, _id, card) { phase = _phase; condition = _condition; @@ -3346,8 +3341,8 @@ class AStrongLandLinkCreature: public MTGAbility { public: char land[20]; - AStrongLandLinkCreature(int _id, MTGCardInstance * _source, const char * _land) : - MTGAbility(_id, _source) + AStrongLandLinkCreature(GameObserver* observer, int _id, MTGCardInstance * _source, const char * _land) : + MTGAbility(observer, _id, _source) { sprintf(land, "%s", _land); } @@ -3387,8 +3382,8 @@ class AControlStealAura: public MTGAbility { public: Player * originalController; - AControlStealAura(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - MTGAbility(_id, _source, _target) + AControlStealAura(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + MTGAbility(observer, _id, _source, _target) { originalController = _target->controller(); MTGCardInstance * copy = _target->changeController(game->currentlyActing()); @@ -3422,8 +3417,8 @@ class ABloodThirst: public MTGAbility { public: int amount; - ABloodThirst(int id, MTGCardInstance * source, MTGCardInstance * target, int amount) : - MTGAbility(id, source, target), amount(amount) + ABloodThirst(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, int amount) : + MTGAbility(observer, id, source, target), amount(amount) { } @@ -3458,7 +3453,7 @@ MTGCardInstance * manaReducer; int amount; int tempAmount; int type; - AAlterCost(int id, MTGCardInstance * source, MTGCardInstance * target, int amount, int type); + AAlterCost(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, int amount, int type); int addToGame(); int testDestroy(); void refreshCost(MTGCardInstance * card = NULL); @@ -3494,7 +3489,7 @@ public: bool newAbilityFound; bool aForever; - ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector newAbilitiesList,bool newAbilityFound = false,bool aForever = false); + ATransformer(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector newAbilitiesList,bool newAbilityFound = false,bool aForever = false); int addToGame(); int reapplyCountersBonus(MTGCardInstance * rtarget= NULL,bool powerapplied=false,bool toughnessapplied=false); int destroy(); @@ -3517,7 +3512,7 @@ public: bool newAbilityFound; bool aForever; - ATransformerInstant(int id, MTGCardInstance * source, MTGCardInstance * target, string types = "", string abilities = "",string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vectornewAbilitiesList = vector(),bool newAbilityFound = false,bool aForever = false); + ATransformerInstant(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, string types = "", string abilities = "",string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vectornewAbilitiesList = vector(),bool newAbilityFound = false,bool aForever = false); int resolve(); const char * getMenuText(); ATransformerInstant * clone() const; @@ -3533,7 +3528,7 @@ public: string s; bool nonstatic; WParsedPT * newWppt; - PTInstant(int id, MTGCardInstance * source, MTGCardInstance * target, WParsedPT * wppt,string s = "",bool nonstatic = false); + PTInstant(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, WParsedPT * wppt,string s = "",bool nonstatic = false); int resolve(); const char * getMenuText(); PTInstant * clone() const; @@ -3545,7 +3540,7 @@ class ASwapPTUEOT: public InstantAbility { public: ASwapPT * ability; - ASwapPTUEOT(int id, MTGCardInstance * source, MTGCardInstance * target); + ASwapPTUEOT(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target); int resolve(); const char * getMenuText(); ASwapPTUEOT * clone() const; @@ -3559,7 +3554,7 @@ public: REDamagePrevention * re; int type; - APreventDamageTypes(int id, MTGCardInstance * source, string to, string from, int type = 0); + APreventDamageTypes(GameObserver* observer, int id, MTGCardInstance * source, string to, string from, int type = 0); int addToGame(); int destroy(); APreventDamageTypes * clone() const; @@ -3571,7 +3566,7 @@ class ACounterShroud: public MTGAbility public: Counter * counter; RECountersPrevention * re; - ACounterShroud(int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter = NULL); + ACounterShroud(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter = NULL); int addToGame(); int destroy(); ACounterShroud * clone() const; @@ -3583,7 +3578,7 @@ class ACounterTracker: public MTGAbility public: string scounter; int removed; - ACounterTracker(int id, MTGCardInstance * source, MTGCardInstance * target, string scounter = ""); + ACounterTracker(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, string scounter = ""); int addToGame(); int destroy(); int testDestroy(); @@ -3595,7 +3590,7 @@ class ALoseAbilities: public MTGAbility { public: vector storedAbilities; - ALoseAbilities(int id, MTGCardInstance * source, MTGCardInstance * target); + ALoseAbilities(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target); int addToGame(); int destroy(); ALoseAbilities * clone() const; @@ -3607,7 +3602,7 @@ class ALoseSubtypes: public MTGAbility public: int parentType; vector storedSubtypes; - ALoseSubtypes(int id, MTGCardInstance * source, MTGCardInstance * target, int parentType); + ALoseSubtypes(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, int parentType); int addToGame(); int destroy(); ALoseSubtypes * clone() const; @@ -3620,7 +3615,7 @@ public: APreventDamageTypes * ability; vector clones; int type; - APreventDamageTypesUEOT(int id, MTGCardInstance * source, string to, string from, int type = 0); + APreventDamageTypesUEOT(GameObserver* observer, int id, MTGCardInstance * source, string to, string from, int type = 0); int resolve(); int destroy(); const char * getMenuText(); @@ -3637,7 +3632,7 @@ public: string counterName; int next; - AVanishing(int _id, MTGCardInstance * card, ManaCost * _cost, int restrictions = 0,int amount = 0,string counterName = ""); + AVanishing(GameObserver* observer, int _id, MTGCardInstance * card, ManaCost * _cost, int restrictions = 0,int amount = 0,string counterName = ""); void Update(float dt); int resolve(); const char * getMenuText(); @@ -3656,7 +3651,7 @@ public: int currentage; ManaCost * backupMana; - AUpkeep(int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, int restrictions = 0, int _phase = + AUpkeep(GameObserver* observer, int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, int restrictions = 0, int _phase = Constants::MTG_PHASE_UPKEEP, int _once = 0,bool Cumulative = false); int receiveEvent(WEvent * event); void Update(float dt); @@ -3684,7 +3679,7 @@ public: bool once; Player * abilityOwner; - APhaseAction(int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions = 0, int _phase = + APhaseAction(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions = 0, int _phase = Constants::MTG_PHASE_UPKEEP,bool forcedestroy = false,bool next = true,bool myturn = true,bool opponentturn = true,bool once = false); void Update(float dt); int resolve(); @@ -3699,7 +3694,7 @@ class APhaseActionGeneric: public InstantAbility public: string sAbility; APhaseAction * ability; - APhaseActionGeneric(int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions = 0, int _phase = + APhaseActionGeneric(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions = 0, int _phase = Constants::MTG_PHASE_UPKEEP,bool forcedestroy = false,bool next = true,bool myturn = false,bool opponentturn = false,bool once = false); int resolve(); const char * getMenuText(); @@ -3718,7 +3713,7 @@ public: MTGCardInstance * Blinked; bool resolved; MTGAbility * stored; - ABlink(int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot=false,bool blinkForSource = false,bool blinkhand = false,MTGAbility * stored = NULL); + ABlink(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot=false,bool blinkForSource = false,bool blinkhand = false,MTGAbility * stored = NULL); void Update(float dt); void resolveBlink(); int resolve(); @@ -3736,7 +3731,7 @@ public: bool blinkhand; ABlink * ability; MTGAbility * stored; - ABlinkGeneric(int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot=false,bool blinkForSource = false,bool blinkhand = false,MTGAbility * stored = NULL); + ABlinkGeneric(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot=false,bool blinkForSource = false,bool blinkhand = false,MTGAbility * stored = NULL); int resolve(); const char * getMenuText(); ABlinkGeneric * clone() const; @@ -3756,14 +3751,13 @@ public: int nbcards; int init; - AAladdinsLamp(int id, MTGCardInstance * card) : - TargetAbility(id, card) + AAladdinsLamp(GameObserver* observer, int id, MTGCardInstance * card) : + TargetAbility(observer, id, card), cd(1, game, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, NULL) { setCost(NEW ManaCost(), true); getCost()->x(); - cd = CardDisplay(1, game, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, NULL); int zones[] = { MTGGameZone::MY_LIBRARY }; - tc = NEW TargetZoneChooser(zones, 1, source); + tc = NEW TargetZoneChooser(game, zones, 1, source); nbcards = 0; init = 0; } @@ -3836,8 +3830,8 @@ class AArmageddonClock: public MTGAbility public: int counters; ManaCost cost; - AArmageddonClock(int id, MTGCardInstance * _source) : - MTGAbility(id, _source) + AArmageddonClock(GameObserver* observer, int id, MTGCardInstance * _source) : + MTGAbility(observer, id, _source) { counters = 0; int8_t _cost[] = { Constants::MTG_COLOR_ARTIFACT, 4 }; @@ -3854,9 +3848,9 @@ public: } else if (newPhase == Constants::MTG_PHASE_DRAW && counters > 0 && game->currentPlayer->game->inPlay->hasCard(source)) { //End of upkeep = beginning of draw - GameObserver::GetInstance()->mLayers->stackLayer()->addDamage(source, GameObserver::GetInstance()->players[0], + game->mLayers->stackLayer()->addDamage(source, game->players[0], counters); - GameObserver::GetInstance()->mLayers->stackLayer()->addDamage(source, GameObserver::GetInstance()->players[1], + game->mLayers->stackLayer()->addDamage(source, game->players[1], counters); } } @@ -3898,8 +3892,8 @@ class AConservator: public MTGAbility public: int canprevent; ManaCost cost; - AConservator(int _id, MTGCardInstance * _source) : - MTGAbility(_id, _source) + AConservator(GameObserver* observer, int _id, MTGCardInstance * _source) : + MTGAbility(observer, _id, _source) { canprevent = 0; int8_t _cost[] = { Constants::MTG_COLOR_ARTIFACT, 2 }; @@ -3993,8 +3987,8 @@ class AFarmstead: public ActivatedAbility { public: int usedThisTurn; - AFarmstead(int _id, MTGCardInstance * source, MTGCardInstance * _target) : - ActivatedAbility(_id, source, 0, 1) + AFarmstead(GameObserver* observer, int _id, MTGCardInstance * source, MTGCardInstance * _target) : + ActivatedAbility(observer, _id, source, 0, 1) { int8_t _cost[] = { Constants::MTG_COLOR_WHITE, 2 }; setCost(NEW ManaCost(_cost, 1), true); @@ -4043,8 +4037,8 @@ class AKjeldoranFrostbeast: public MTGAbility public: MTGCardInstance * opponents[20]; int nbOpponents; - AKjeldoranFrostbeast(int _id, MTGCardInstance * _source) : - MTGAbility(_id, _source) + AKjeldoranFrostbeast(GameObserver* observer, int _id, MTGCardInstance * _source) : + MTGAbility(observer, _id, _source) { nbOpponents = 0; } @@ -4063,7 +4057,7 @@ public: nbOpponents++; opponent = source->getNextOpponent(opponent); } - if (source->isInPlay()) + if (source->isInPlay(game)) { for (int i = 0; i < nbOpponents; i++) { @@ -4101,8 +4095,8 @@ public: class AAnimateDead: public MTGAbility { public: - AAnimateDead(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - MTGAbility(_id, _source, _target) + AAnimateDead(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + MTGAbility(observer, _id, _source, _target) { MTGCardInstance * card = _target; @@ -4110,7 +4104,7 @@ public: //AbilityFactory af; MTGCardInstance * copy = source->controller()->game->putInZone(card, _target->controller()->game->graveyard, source->controller()->game->temp); - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(game, copy); spell->resolve(); target = spell->source; card = spell->source; @@ -4143,8 +4137,8 @@ class AErgRaiders: public MTGAbility { public: int attackedThisTurn; - AErgRaiders(int _id, MTGCardInstance * _source) : - MTGAbility(_id, _source) + AErgRaiders(GameObserver* observer, int _id, MTGCardInstance * _source) : + MTGAbility(observer, _id, _source) { attackedThisTurn = 1; } @@ -4195,11 +4189,11 @@ public: TargetChooser * counter; MaxPerTurnRestriction * landsRestriction; int landsPlayedThisTurn; - AFastbond(int _id, MTGCardInstance * card) : - TriggeredAbility(_id, card) + AFastbond(GameObserver* observer, int _id, MTGCardInstance * card) : + TriggeredAbility(observer, _id, card) { - counter = NEW TypeTargetChooser("land"); + counter = NEW TypeTargetChooser(game, "land"); landsPlayedThisTurn = source->controller()->game->inPlay->seenThisTurn(counter, Constants::CAST_ALL); PlayRestrictions * restrictions = source->controller()->game->playRestrictions; landsRestriction = restrictions->getMaxPerTurnRestrictionByTargetChooser(counter); @@ -4263,8 +4257,8 @@ public: class AJandorsRing: public ActivatedAbility { public: - AJandorsRing(int _id, MTGCardInstance * _source) : - ActivatedAbility(_id, _source, NEW ManaCost()) + AJandorsRing(GameObserver* observer, int _id, MTGCardInstance * _source) : + ActivatedAbility(observer, _id, _source, NEW ManaCost()) { getCost()->add(Constants::MTG_COLOR_ARTIFACT, 2); } @@ -4298,8 +4292,8 @@ public: class AKudzu: public TargetAbility { public: - AKudzu(int _id, MTGCardInstance * card, MTGCardInstance * _target) : - TargetAbility(_id, card, NEW TypeTargetChooser("land", card)) + AKudzu(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * _target) : + TargetAbility(observer, _id, card, NEW TypeTargetChooser(observer, "land", card)) { tc->toggleTarget(_target); target = _target; @@ -4312,7 +4306,7 @@ public: if (wect->before == false && wect->after == true && wect->card == target) { MTGCardInstance * _target = (MTGCardInstance *) target; - if (!_target->isInPlay()) return 0; + if (!_target->isInPlay(game)) return 0; target = _target->controller()->game->putInGraveyard(_target); reactToClick(source); return 1; @@ -4325,7 +4319,7 @@ public: int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL) { MTGCardInstance * _target = (MTGCardInstance *) target; - if (card == source && (!_target || !_target->isInPlay())) + if (card == source && (!_target || !_target->isInPlay(game))) { DebugTrace("Kudzu Reacts to click !"); return 1; @@ -4373,8 +4367,8 @@ class APowerLeak: public TriggeredAbility public: int damagesToDealThisTurn; ManaCost cost; - APowerLeak(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - TriggeredAbility(_id, _source, _target) + APowerLeak(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + TriggeredAbility(observer, _id, _source, _target) { cost.add(Constants::MTG_COLOR_ARTIFACT, 1); damagesToDealThisTurn = 0; @@ -4440,8 +4434,8 @@ public: class ASacrifice: public InstantAbility { public: - ASacrifice(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - InstantAbility(_id, _source) + ASacrifice(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + InstantAbility(observer, _id, _source) { target = _target; } @@ -4449,7 +4443,7 @@ public: int resolve() { MTGCardInstance * _target = (MTGCardInstance *) target; - if (_target->isInPlay()) + if (_target->isInPlay(game)) { game->currentlyActing()->game->putInGraveyard(_target); int x = _target->getManaCost()->getConvertedCost(); @@ -4473,8 +4467,8 @@ public: class AEarthbind: public ABasicAbilityModifier { public: - AEarthbind(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - ABasicAbilityModifier(_id, _source, _target, Constants::FLYING, 0) + AEarthbind(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + ABasicAbilityModifier(observer, _id, _source, _target, Constants::FLYING, 0) { if (value_before_modification) { @@ -4498,8 +4492,8 @@ public: class AFireball: public InstantAbility { public: - AFireball(int _id, MTGCardInstance * card, Spell * spell, int x) : - InstantAbility(_id, card) + AFireball(GameObserver* observer, int _id, MTGCardInstance * card, Spell * spell, int x) : + InstantAbility(observer, _id, card) { int nbtargets = spell->getNbTargets(); int totaldamage = x + 1 - nbtargets; @@ -4530,8 +4524,8 @@ class AIslandSanctuary: public MTGAbility public: int initThisTurn; vector effectedCards; - AIslandSanctuary(int _id, MTGCardInstance * _source) : - MTGAbility(_id, _source) + AIslandSanctuary(GameObserver* observer, int _id, MTGCardInstance * _source) : + MTGAbility(observer, _id, _source) { initThisTurn = 0; } @@ -4597,8 +4591,8 @@ class AStasis: public ActivatedAbility { public: int paidThisTurn; - AStasis(int _id, MTGCardInstance * card) : - ActivatedAbility(_id, card, NEW ManaCost(), 0) + AStasis(GameObserver* observer, int _id, MTGCardInstance * card) : + ActivatedAbility(observer, _id, card, NEW ManaCost(), 0) { paidThisTurn = 1; getCost()->add(Constants::MTG_COLOR_BLUE, 1); @@ -4669,8 +4663,8 @@ class ABasilik: public MTGAbility public: MTGCardInstance * opponents[20]; int nbOpponents; - ABasilik(int _id, MTGCardInstance * _source) : - MTGAbility(_id, _source) + ABasilik(GameObserver* observer, int _id, MTGCardInstance * _source) : + MTGAbility(observer, _id, _source) { nbOpponents = 0; } @@ -4717,7 +4711,7 @@ class AADepleter: public ActivatedAbilityTP public: string nbcardsStr; - AADepleter(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost = NULL, + AADepleter(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -4728,7 +4722,7 @@ public: class AAShuffle: public ActivatedAbilityTP { public: - AAShuffle(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost = NULL, int who = + AAShuffle(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -4742,7 +4736,7 @@ public: ManaCost * mManaDesc; bool mRemoveAll; - AARemoveMana(int _id, MTGCardInstance * card, Targetable * _target, string ManaDesc, int who = TargetChooser::UNSET); + AARemoveMana(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, string ManaDesc, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); AARemoveMana * clone() const; @@ -4756,7 +4750,7 @@ class AARandomDiscarder: public ActivatedAbilityTP public: string nbcardsStr; - AARandomDiscarder(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost = NULL, + AARandomDiscarder(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int resolve(); const char * getMenuText(); @@ -4768,8 +4762,8 @@ class AMinionofLeshrac: public TargetAbility { public: int paidThisTurn; - AMinionofLeshrac(int _id, MTGCardInstance * source) : - TargetAbility(_id, source, NEW TypeTargetChooser("creature"), 0, 1) + AMinionofLeshrac(GameObserver* observer, int _id, MTGCardInstance * source) : + TargetAbility(observer, _id, source, NEW TypeTargetChooser(game, "creature"), 0, 1) { paidThisTurn = 1; } @@ -4830,8 +4824,8 @@ public: int ToughnessModifier; int MaxOpponent; - ARampageAbility(int _id, MTGCardInstance * _source, int _PowerModifier, int _ToughnessModifier, int _MaxOpponent) : - MTGAbility(_id, _source) + ARampageAbility(GameObserver* observer, int _id, MTGCardInstance * _source, int _PowerModifier, int _ToughnessModifier, int _MaxOpponent) : + MTGAbility(observer, _id, _source) { PowerModifier = _PowerModifier; ToughnessModifier = _ToughnessModifier; @@ -4871,8 +4865,8 @@ class AFlankerAbility: public MTGAbility public: MTGCardInstance * opponents[20]; int nbOpponents; - AFlankerAbility(int _id, MTGCardInstance * _source) : - MTGAbility(_id, _source) + AFlankerAbility(GameObserver* observer, int _id, MTGCardInstance * _source) : + MTGAbility(observer, _id, _source) { nbOpponents = 0; } @@ -4923,8 +4917,8 @@ public: int PowerModifier; int ToughnessModifier; - ABushidoAbility(int _id, MTGCardInstance * _source, int _PowerModifier, int _ToughnessModifier) : - MTGAbility(_id, _source) + ABushidoAbility(GameObserver* observer, int _id, MTGCardInstance * _source, int _PowerModifier, int _ToughnessModifier) : + MTGAbility(observer, _id, _source) { PowerModifier = _PowerModifier; ToughnessModifier = _ToughnessModifier; @@ -4975,8 +4969,8 @@ class ASpiritLinkAbility: public MTGAbility public: MTGCardInstance * source; bool combatonly; - ASpiritLinkAbility(int _id, MTGCardInstance * _source,bool combatonly = false) : - MTGAbility(_id, _source),source(_source),combatonly(combatonly) + ASpiritLinkAbility(GameObserver* observer, int _id, MTGCardInstance * _source,bool combatonly = false) : + MTGAbility(observer, _id, _source),source(_source),combatonly(combatonly) { } int receiveEvent(WEvent * event) @@ -5008,8 +5002,8 @@ class AInstantControlSteal: public InstantAbility public: Player * TrueController; Player * TheftController; - AInstantControlSteal(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - InstantAbility(_id, _source, _target) + AInstantControlSteal(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + InstantAbility(observer, _id, _source, _target) { TrueController = _target->controller(); TheftController = source->controller(); diff --git a/projects/mtg/include/CardDisplay.h b/projects/mtg/include/CardDisplay.h index ac294ee9e..c282d46a4 100644 --- a/projects/mtg/include/CardDisplay.h +++ b/projects/mtg/include/CardDisplay.h @@ -10,13 +10,12 @@ class MTGCardInstance; class CardDisplay: public PlayGuiObjectController { int mId; - GameObserver* game; public: int x, y, start_item, nb_displayed_items; MTGGameZone * zone; TargetChooser * tc; JGuiListener * listener; - CardDisplay(); + CardDisplay(GameObserver* game); CardDisplay(int id, GameObserver* game, int x, int y, JGuiListener * listener = NULL, TargetChooser * tc = NULL, int nb_displayed_items = 7); void AddCard(MTGCardInstance * _card); diff --git a/projects/mtg/include/CardSelector.h b/projects/mtg/include/CardSelector.h index 82dd4eae1..fa3917f36 100644 --- a/projects/mtg/include/CardSelector.h +++ b/projects/mtg/include/CardSelector.h @@ -24,8 +24,9 @@ class CardSelectorBase: public GuiLayer { public: - CardSelectorBase(int inDrawMode = DrawMode::kNormal) : - mDrawMode(inDrawMode) + CardSelectorBase(GameObserver *observer, int inDrawMode = DrawMode::kNormal) : + GuiLayer(observer), mDrawMode(inDrawMode) + { } ; @@ -70,7 +71,7 @@ protected: PlayGuiObject* fetchMemory(SelectorMemory&); public: - CardSelector(DuelLayers*); + CardSelector(GameObserver *observer, DuelLayers*); void Add(PlayGuiObject*); void Remove(PlayGuiObject*); bool CheckUserInput(JButton key); diff --git a/projects/mtg/include/CardSelectorSingleton.h b/projects/mtg/include/CardSelectorSingleton.h index 5e0e9d3f7..81f513d6f 100644 --- a/projects/mtg/include/CardSelectorSingleton.h +++ b/projects/mtg/include/CardSelectorSingleton.h @@ -18,7 +18,7 @@ namespace CardSelectorSingleton /* ** Create the singleton pointer. Instance() isn't valid until this is called. */ - CardSelectorBase* Create(DuelLayers* inDuelLayers); + CardSelectorBase* Create(GameObserver* observer, DuelLayers* inDuelLayers); /* ** Teardown the singleton pointer instance. diff --git a/projects/mtg/include/Credits.h b/projects/mtg/include/Credits.h index 2addc8f59..dc3ea86b4 100644 --- a/projects/mtg/include/Credits.h +++ b/projects/mtg/include/Credits.h @@ -38,6 +38,7 @@ private: public: int value; Player * p1, *p2; + GameObserver* observer; GameApp * app; int showMsg; int unlocked; @@ -45,7 +46,7 @@ public: vector bonus; Credits(); ~Credits(); - void compute(Player * _p1, Player * _p2, GameApp * _app); + void compute(GameObserver* observer, GameApp * _app); void Render(); static int unlockRandomSet(bool force = false); static int unlockSetByName(string name); diff --git a/projects/mtg/include/Damage.h b/projects/mtg/include/Damage.h index 650f00ea3..13a9bdd24 100644 --- a/projects/mtg/include/Damage.h +++ b/projects/mtg/include/Damage.h @@ -23,20 +23,22 @@ class Damageable:public Targetable protected: public: int life; - int handsize; + int handsize; int poisonCount; int damageCount; int preventable; int thatmuch; int lifeLostThisTurn; int type_as_damageable; - Damageable(int _life){life=_life;lifeLostThisTurn = 0;}; - int getLife(){return life;}; - virtual int dealDamage(int damage){life-=damage;return life;}; - virtual int afterDamage(){return 0;} - virtual int poisoned(){return 0;} - virtual int prevented(){return 0;} - virtual JQuadPtr getIcon(){return JQuadPtr();} + Damageable(GameObserver* observer, int _life) + : Targetable(observer) + {life=_life;lifeLostThisTurn = 0;}; + int getLife(){return life;}; + virtual int dealDamage(int damage){life-=damage;return life;}; + virtual int afterDamage(){return 0;} + virtual int poisoned(){return 0;} + virtual int prevented(){return 0;} + virtual JQuadPtr getIcon(){return JQuadPtr();} }; class Damage: public Interruptible @@ -48,8 +50,8 @@ class Damage: public Interruptible int typeOfDamage; int damage; void Render(); - Damage(MTGCardInstance* source, Damageable * target); - Damage(MTGCardInstance* source, Damageable * target, int damage, int typeOfDamage = DAMAGE_OTHER); + Damage(GameObserver* observer, MTGCardInstance* source, Damageable * target); + Damage(GameObserver* observer, MTGCardInstance* source, Damageable * target, int damage, int typeOfDamage = DAMAGE_OTHER); int resolve(); virtual ostream& toString(ostream& out) const; }; @@ -58,14 +60,17 @@ class DamageStack : public GuiLayer, public Interruptible { protected: int currentState; - GameObserver* game; public: int receiveEvent(WEvent * event); int resolve(); void Render(); virtual ostream& toString(ostream& out) const; - DamageStack(); + DamageStack(GameObserver *observer); }; +ostream& operator<<(ostream& out, const Damageable& p); + +istream& operator>>(istream& in, Damageable& p); + #endif diff --git a/projects/mtg/include/DuelLayers.h b/projects/mtg/include/DuelLayers.h index ef4f5dca6..931df1446 100644 --- a/projects/mtg/include/DuelLayers.h +++ b/projects/mtg/include/DuelLayers.h @@ -35,7 +35,7 @@ public: ActionStack * stackLayer(); GuiCombat * combatLayer(); GuiAvatars * GetAvatars(); - void init(); + void init(GameObserver* go); virtual void Update(float dt, Player * player); void CheckUserInput(int isAI); void Render(); diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index e670e90b7..f1909905b 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -24,13 +24,13 @@ using namespace std; class GameObserver{ protected: - static GameObserver * mInstance; MTGCardInstance * cardWaitingForTargets; queue eventsQueue; int nbPlayers; int untap(MTGCardInstance * card); bool WaitForExtraPayment(MTGCardInstance* card); + void initialize(); public: int currentPlayerId; @@ -56,19 +56,20 @@ class GameObserver{ int cardClick(MTGCardInstance * card,Targetable * _object = NULL ); int getCurrentGamePhase(); + const char * getCurrentGamePhaseName(); + const char * getNextGamePhaseName(); void nextCombatStep(); void userRequestNextGamePhase(); void nextGamePhase(); void cleanupPhase(); void nextPlayer(); - static void Init(Player * _players[], int _nbplayers); - static GameObserver * GetInstance(); - static void EndInstance(); + void setPlayers(Player * _players[], int _nbplayers); Player * currentPlayer; Player * currentActionPlayer; Player * isInterrupting; Player * opponent(); Player * currentlyActing(); + GameObserver(); GameObserver(Player * _players[], int _nbplayers); ~GameObserver(); void gameStateBasedEffects(); @@ -86,6 +87,7 @@ class GameObserver{ void Update(float dt); void Render(); void ButtonPressed(PlayGuiObject*); + int getPlayersNumber() {return nbPlayers;}; int receiveEvent(WEvent * event); bool connectRule; diff --git a/projects/mtg/include/GuiAvatars.h b/projects/mtg/include/GuiAvatars.h index d5f6ff29b..d14a60772 100644 --- a/projects/mtg/include/GuiAvatars.h +++ b/projects/mtg/include/GuiAvatars.h @@ -17,7 +17,7 @@ protected: GuiAvatar* active; public: - GuiAvatars(); + GuiAvatars(GameObserver *observer); ~GuiAvatars(); GuiAvatar* GetSelf(); diff --git a/projects/mtg/include/GuiBackground.h b/projects/mtg/include/GuiBackground.h index 3d16466f5..8e1b41ba5 100644 --- a/projects/mtg/include/GuiBackground.h +++ b/projects/mtg/include/GuiBackground.h @@ -10,7 +10,7 @@ protected: JQuad* quad; public: - GuiBackground(); + GuiBackground(GameObserver* observer); ~GuiBackground(); virtual void Render(); }; diff --git a/projects/mtg/include/GuiCardsController.h b/projects/mtg/include/GuiCardsController.h index 4212ae9d5..da1c1e525 100644 --- a/projects/mtg/include/GuiCardsController.h +++ b/projects/mtg/include/GuiCardsController.h @@ -6,8 +6,10 @@ class GuiCardsController: public PlayGuiObjectController { public: - GuiCardsController(){} - ; + GuiCardsController(GameObserver*observer) + : PlayGuiObjectController(observer) + { + }; }; #endif diff --git a/projects/mtg/include/GuiCombat.h b/projects/mtg/include/GuiCombat.h index e30d45e14..9cbbea10b 100644 --- a/projects/mtg/include/GuiCombat.h +++ b/projects/mtg/include/GuiCombat.h @@ -10,7 +10,6 @@ class GuiCombat: public GuiLayer { protected: - GameObserver* go; DamagerDamaged* active; AttackerDamaged* activeAtk; static JTexture* ok_tex; diff --git a/projects/mtg/include/GuiFrame.h b/projects/mtg/include/GuiFrame.h index b124526b3..2f68f8005 100644 --- a/projects/mtg/include/GuiFrame.h +++ b/projects/mtg/include/GuiFrame.h @@ -11,7 +11,7 @@ protected: float step; public: - GuiFrame(); + GuiFrame(GameObserver* observer); ~GuiFrame(); virtual void Render(); void Update(float dt); diff --git a/projects/mtg/include/GuiHand.h b/projects/mtg/include/GuiHand.h index e38411776..826e13487 100644 --- a/projects/mtg/include/GuiHand.h +++ b/projects/mtg/include/GuiHand.h @@ -36,7 +36,7 @@ protected: vector cards; public: - GuiHand(MTGHand* hand); + GuiHand(GameObserver* observer, MTGHand* hand); ~GuiHand(); void Update(float dt); bool isInHand(CardView*); @@ -47,7 +47,7 @@ public: class GuiHandOpponent : public GuiHand { public: - GuiHandOpponent(MTGHand* hand); + GuiHandOpponent(GameObserver* observer, MTGHand* hand); virtual void Render(); virtual int receiveEventPlus(WEvent* e); virtual int receiveEventMinus(WEvent* e); @@ -65,7 +65,7 @@ protected: Pos backpos; public: - GuiHandSelf(MTGHand* hand); + GuiHandSelf(GameObserver* observer, MTGHand* hand); ~GuiHandSelf(); virtual int receiveEventPlus(WEvent* e); virtual int receiveEventMinus(WEvent* e); diff --git a/projects/mtg/include/GuiLayers.h b/projects/mtg/include/GuiLayers.h index 666af4d10..d5e572be2 100644 --- a/projects/mtg/include/GuiLayers.h +++ b/projects/mtg/include/GuiLayers.h @@ -16,6 +16,7 @@ class GuiLayer { protected: JButton mActionButton; + GameObserver* observer; public: int mCurr; vector mObjects; @@ -26,7 +27,7 @@ public: bool hasFocus; virtual void resetObjects(); int getMaxId(); - GuiLayer(); + GuiLayer(GameObserver *observer); virtual ~GuiLayer(); virtual void Update(float dt); virtual bool CheckUserInput(JButton key) diff --git a/projects/mtg/include/GuiPhaseBar.h b/projects/mtg/include/GuiPhaseBar.h index e49c929a8..038256635 100644 --- a/projects/mtg/include/GuiPhaseBar.h +++ b/projects/mtg/include/GuiPhaseBar.h @@ -13,7 +13,7 @@ protected: float zoomFactor; public: - GuiPhaseBar(); + GuiPhaseBar(GameObserver* observer); ~GuiPhaseBar(); void Update(float dt); virtual void Render(); diff --git a/projects/mtg/include/GuiPlay.h b/projects/mtg/include/GuiPlay.h index 209f15791..eacc5eeac 100644 --- a/projects/mtg/include/GuiPlay.h +++ b/projects/mtg/include/GuiPlay.h @@ -71,7 +71,6 @@ protected: class Spells: public VertStack {}; protected: - GameObserver* game; Creatures selfCreatures, opponentCreatures; BattleField battleField; Lands selfLands, opponentLands; diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 78dc62bd8..4ff4f515a 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -130,10 +130,10 @@ public: int abilitygranted; MTGCardInstance * source; - static int allowedToCast(MTGCardInstance* card, Player* player); - static int allowedToAltCast(MTGCardInstance* card, Player* player); - MTGAbility(int id, MTGCardInstance * card); - MTGAbility(int id, MTGCardInstance * _source, Targetable * _target); + int allowedToCast(MTGCardInstance* card, Player* player); + int allowedToAltCast(MTGCardInstance* card, Player* player); + MTGAbility(GameObserver* observer, int id, MTGCardInstance * card); + MTGAbility(GameObserver* observer, int id, MTGCardInstance * _source, Targetable * _target); MTGAbility(const MTGAbility& copyFromMe); virtual int testDestroy(); virtual ~MTGAbility(); @@ -226,8 +226,8 @@ public: class TriggeredAbility : public MTGAbility { public: - TriggeredAbility(int id, MTGCardInstance* card); - TriggeredAbility(int id, MTGCardInstance* _source, Targetable* _target); + TriggeredAbility(GameObserver* observer, int id, MTGCardInstance* card); + TriggeredAbility(GameObserver* observer, int id, MTGCardInstance* _source, Targetable* _target); virtual void Update(float dt); virtual void Render() @@ -259,7 +259,7 @@ private: bool mActiveTrigger; public: - Trigger(int id, MTGCardInstance * source, bool once, TargetChooser * _tc = NULL); + Trigger(GameObserver* observer, int id, MTGCardInstance * source, bool once, TargetChooser * _tc = NULL); int resolve() { return 0; //This is a trigger, this function should not be called @@ -284,7 +284,7 @@ public: int uses; string castRestriction; - ActivatedAbility(int id, MTGCardInstance* card, ManaCost* _cost = NULL, int _restrictions = NO_RESTRICTION, string limit = "", MTGAbility* sideEffect = NULL, string usesBeforeSideEffects = "",string castRestriction = ""); + ActivatedAbility(GameObserver* observer, int id, MTGCardInstance* card, ManaCost* _cost = NULL, int _restrictions = NO_RESTRICTION, string limit = "", MTGAbility* sideEffect = NULL, string usesBeforeSideEffects = "",string castRestriction = ""); virtual ~ActivatedAbility(); virtual void Update(float dt) @@ -308,8 +308,8 @@ public: class TargetAbility : public ActivatedAbility, public NestedAbility { public: - TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0, string castRestriction = ""); - TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0, string castRestriction = ""); + TargetAbility(GameObserver* observer, int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0, string castRestriction = ""); + TargetAbility(GameObserver* observer, int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0, string castRestriction = ""); ~TargetAbility(); virtual int reactToClick(MTGCardInstance * card); @@ -327,8 +327,8 @@ public: int init; virtual void Update(float dt); virtual int testDestroy(); - InstantAbility(int _id, MTGCardInstance * source); - InstantAbility(int _id, MTGCardInstance * source,Targetable * _target); + InstantAbility(GameObserver* observer, int _id, MTGCardInstance * source); + InstantAbility(GameObserver* observer, int _id, MTGCardInstance * source,Targetable * _target); virtual int resolve() { @@ -346,18 +346,18 @@ public: map cards; map checkCards; map players; - ListMaintainerAbility(int _id) - : MTGAbility(_id, NULL) + ListMaintainerAbility(GameObserver* observer, int _id) + : MTGAbility(observer, _id, NULL) { } - ListMaintainerAbility(int _id, MTGCardInstance *_source) - : MTGAbility(_id, _source) + ListMaintainerAbility(GameObserver* observer, int _id, MTGCardInstance *_source) + : MTGAbility(observer, _id, _source) { } - ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target) - : MTGAbility(_id, _source, _target) + ListMaintainerAbility(GameObserver* observer, int _id, MTGCardInstance *_source,Damageable * _target) + : MTGAbility(observer, _id, _source, _target) { } @@ -399,7 +399,7 @@ public: bool lifelost; int lifeamount; bool once,activeTrigger; - TriggerAtPhase(int id, MTGCardInstance * source, Targetable * target,int _phaseId, int who = 0,bool sourceUntapped = false,bool sourceTap = false,bool lifelost = false, int lifeamount = 0, bool once = false); + TriggerAtPhase(GameObserver* observer, int id, MTGCardInstance * source, Targetable * target,int _phaseId, int who = 0,bool sourceUntapped = false,bool sourceTap = false,bool lifelost = false, int lifeamount = 0, bool once = false); virtual int trigger(); int resolve(){return 0;}; virtual TriggerAtPhase* clone() const; @@ -412,7 +412,7 @@ public: bool sourceUntapped; bool sourceTap; bool once,activeTrigger; - TriggerNextPhase(int id, MTGCardInstance * source, Targetable * target,int _phaseId, int who = 0,bool sourceUntapped = false,bool sourceTap = false,bool once = false); + TriggerNextPhase(GameObserver* observer, int id, MTGCardInstance * source, Targetable * target,int _phaseId, int who = 0,bool sourceUntapped = false,bool sourceTap = false,bool once = false); virtual TriggerNextPhase* clone() const; virtual int testDestroy(); @@ -425,7 +425,7 @@ public: TriggeredAbility * t; queue targets; MTGAbility * destroyCondition; - GenericTriggeredAbility(int id, MTGCardInstance * _source, TriggeredAbility * _t, MTGAbility * a,MTGAbility * dc = NULL, Targetable * _target = NULL); + GenericTriggeredAbility(GameObserver* observer, int id, MTGCardInstance * _source, TriggeredAbility * _t, MTGAbility * a,MTGAbility * dc = NULL, Targetable * _target = NULL); virtual int trigger(); virtual int triggerOnEvent(WEvent * e); virtual int resolve(); @@ -450,10 +450,12 @@ private: MTGAbility * getAlternateCost( string s, int id, Spell *spell, MTGCardInstance *card ); MTGAbility * getManaReduxAbility(string s, int id, Spell *spell, MTGCardInstance *card, MTGCardInstance *target); TargetChooser * parseSimpleTC(const std::string& s, const std::string& starter, MTGCardInstance *card, bool forceNoTarget = true); + GameObserver *observer; public: - static int parseRestriction(string s); - static int parseCastRestrictions(MTGCardInstance * card, Player * player, string restrictions); + AbilityFactory(GameObserver *observer) : observer(observer) {}; + int parseRestriction(string s); + int parseCastRestrictions(MTGCardInstance * card, Player * player, string restrictions); Counter * parseCounter(string s, MTGCardInstance * target, Spell * spell = NULL); int parsePowerToughness(string s, int *power, int *toughness); int getAbilities(vector * v, Spell * spell, MTGCardInstance * card = NULL, int id = 0, MTGGameZone * dest = NULL); @@ -478,7 +480,7 @@ class ActivatedAbilityTP : public ActivatedAbility { public: int who; - ActivatedAbilityTP(int id, MTGCardInstance * card, Targetable * _target = NULL, ManaCost * cost=NULL, int who = TargetChooser::UNSET); + ActivatedAbilityTP(GameObserver* observer, int id, MTGCardInstance * card, Targetable * _target = NULL, ManaCost * cost=NULL, int who = TargetChooser::UNSET); Targetable * getTarget(); }; @@ -486,7 +488,7 @@ class InstantAbilityTP : public InstantAbility { public: int who; - InstantAbilityTP(int id, MTGCardInstance * card, Targetable * _target = NULL, int who = TargetChooser::UNSET); + InstantAbilityTP(GameObserver* observer, int id, MTGCardInstance * card, Targetable * _target = NULL, int who = TargetChooser::UNSET); Targetable * getTarget(); }; @@ -494,7 +496,7 @@ class AbilityTP : public MTGAbility { public: int who; - AbilityTP(int id, MTGCardInstance * card, Targetable * _target = NULL, int who = TargetChooser::UNSET); + AbilityTP(GameObserver* observer, int id, MTGCardInstance * card, Targetable * _target = NULL, int who = TargetChooser::UNSET); Targetable * getTarget(); @@ -513,7 +515,7 @@ public: string menutext; ManaCost * output; int tap; - AManaProducer(int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); + AManaProducer(GameObserver* observer, int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost = NULL, int who = TargetChooser::UNSET); int isReactingToClick(MTGCardInstance * _card, ManaCost * mana = NULL); int resolve(); int reactToClick(MTGCardInstance* _card); diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 4eceb5efa..2d1fe3f85 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -196,7 +196,7 @@ public: void eventattackedblocked(MTGCardInstance * opponent); void eventblocked(MTGCardInstance * opponent); - int isInPlay(); + int isInPlay(GameObserver* game); JSample * getSample(); JQuadPtr getIcon(); diff --git a/projects/mtg/include/MTGGamePhase.h b/projects/mtg/include/MTGGamePhase.h index 5f6eaedd8..91ff995d8 100644 --- a/projects/mtg/include/MTGGamePhase.h +++ b/projects/mtg/include/MTGGamePhase.h @@ -14,9 +14,10 @@ protected: int currentState; WFont * mFont; static MTGGamePhase* instance; + GameObserver* observer; public: - MTGGamePhase(int id); + MTGGamePhase(GameObserver* g, int id); static MTGGamePhase* GetInstance() { return instance; }; virtual void Update(float dt); bool CheckUserInput(JButton key); diff --git a/projects/mtg/include/MTGGameZones.h b/projects/mtg/include/MTGGameZones.h index b11329ac9..55ea571c0 100644 --- a/projects/mtg/include/MTGGameZones.h +++ b/projects/mtg/include/MTGGameZones.h @@ -108,9 +108,9 @@ class MTGGameZone { void setOwner(Player * player); MTGCardInstance * lastCardDrawn; - static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target); + static MTGGameZone * stringToZone(GameObserver *g, string zoneName, MTGCardInstance * source, MTGCardInstance * target); static int zoneStringToId(string zoneName); - static MTGGameZone *intToZone(int zoneId, MTGCardInstance * source = NULL,MTGCardInstance * target = NULL); + static MTGGameZone *intToZone(GameObserver *g, int zoneId, MTGCardInstance * source = NULL,MTGCardInstance * target = NULL); static MTGGameZone *intToZone(int zoneId, Player * source, Player * target = NULL); bool needShuffle; virtual const char * getName(){return "zone";}; @@ -177,7 +177,7 @@ public: MTGGameZone * temp; MTGPlayerCards(); - MTGPlayerCards(int * idList, int idListSize); + MTGPlayerCards(Player*, int * idList, int idListSize); MTGPlayerCards(MTGDeck * deck); ~MTGPlayerCards(); void initGame(int shuffle = 1, int draw = 1); @@ -200,6 +200,7 @@ public: }; ostream& operator<<(ostream&, const MTGGameZone&); +istream& operator>>(istream&, MTGGameZone&); ostream& operator<<(ostream&, const MTGPlayerCards&); istream& operator>>(istream&, MTGPlayerCards&); diff --git a/projects/mtg/include/MTGRules.h b/projects/mtg/include/MTGRules.h index f1aa85d55..04ce7056b 100644 --- a/projects/mtg/include/MTGRules.h +++ b/projects/mtg/include/MTGRules.h @@ -15,7 +15,7 @@ class OtherAbilitiesEventReceiver: public MTGAbility public: int testDestroy(); int receiveEvent(WEvent * event); - OtherAbilitiesEventReceiver(int _id); + OtherAbilitiesEventReceiver(GameObserver* observer, int _id); OtherAbilitiesEventReceiver * clone() const; }; @@ -58,7 +58,7 @@ public: int testDestroy(); void Update(float dt); void Render(); - MTGEventBonus(int _id); + MTGEventBonus(GameObserver* observer, int _id); virtual MTGEventBonus * clone() const; }; @@ -69,7 +69,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGPutInPlayRule(int _id); + MTGPutInPlayRule(GameObserver* observer, int _id); const char * getMenuText() { return "cast card normally"; @@ -84,7 +84,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGKickerRule(int _id); + MTGKickerRule(GameObserver* observer, int _id); const char * getMenuText() { return "pay kicker"; @@ -104,7 +104,7 @@ public: int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGAlternativeCostRule(int _id); + MTGAlternativeCostRule(GameObserver* observer, int _id); const char * getMenuText() { if(alternativeName.size()) @@ -121,7 +121,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGBuyBackRule(int _id); + MTGBuyBackRule(GameObserver* observer, int _id); const char * getMenuText() { return "cast and buy back"; @@ -137,7 +137,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGFlashBackRule(int _id); + MTGFlashBackRule(GameObserver* observer, int _id); const char * getMenuText() { return "flash back"; @@ -152,7 +152,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGRetraceRule(int _id); + MTGRetraceRule(GameObserver* observer, int _id); const char * getMenuText() { return "retrace"; @@ -168,7 +168,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGMorphCostRule(int _id); + MTGMorphCostRule(GameObserver* observer, int _id); const char * getMenuText() { return "play morphed"; @@ -185,7 +185,7 @@ public: int testDestroy(); string suspendmenu; virtual ostream& toString(ostream& out) const; - MTGSuspendRule(int _id); + MTGSuspendRule(GameObserver* observer, int _id); const char * getMenuText() { suspendmenu = "suspend"; @@ -208,7 +208,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGAttackRule(int _id); + MTGAttackRule(GameObserver* observer, int _id); const char * getMenuText() { return "Attacker"; @@ -221,7 +221,7 @@ public: class MTGCombatTriggersRule: public MTGAbility { public: - MTGCombatTriggersRule(int _id); + MTGCombatTriggersRule(GameObserver* observer, int _id); int receiveEvent(WEvent * event); virtual ostream& toString(ostream& out) const; int testDestroy(); @@ -235,7 +235,7 @@ public: int reactToClick(MTGCardInstance * card); int testDestroy(); virtual ostream& toString(ostream& out) const; - MTGBlockRule(int _id); + MTGBlockRule(GameObserver* observer, int _id); const char * getMenuText() { return "Blocker"; @@ -247,7 +247,7 @@ public: class MTGPersistRule: public MTGAbility { public: - MTGPersistRule(int _id); + MTGPersistRule(GameObserver* observer, int _id); int receiveEvent(WEvent * event); virtual ostream& toString(ostream& out) const; int testDestroy(); @@ -257,7 +257,7 @@ public: class MTGVampireRule: public MTGAbility { public: - MTGVampireRule(int _id); + MTGVampireRule(GameObserver* observer, int _id); map > victems; int receiveEvent(WEvent * event); virtual ostream& toString(ostream& out) const; @@ -268,7 +268,7 @@ public: class MTGUnearthRule: public MTGAbility { public: - MTGUnearthRule(int _id); + MTGUnearthRule(GameObserver* observer, int _id); int receiveEvent(WEvent * event); virtual ostream& toString(ostream& out) const; int testDestroy(); @@ -278,7 +278,7 @@ class MTGTokensCleanup: public MTGAbility { public: vector list; - MTGTokensCleanup(int _id); + MTGTokensCleanup(GameObserver* observer, int _id); int receiveEvent(WEvent * event); int testDestroy(); virtual MTGTokensCleanup * clone() const; @@ -293,7 +293,7 @@ public: class MTGLegendRule: public ListMaintainerAbility { public: - MTGLegendRule(int _id); + MTGLegendRule(GameObserver* observer, int _id); int canBeInList(MTGCardInstance * card); int added(MTGCardInstance * card); int removed(MTGCardInstance * card); @@ -304,7 +304,7 @@ public: class MTGPlaneWalkerRule: public ListMaintainerAbility { public: - MTGPlaneWalkerRule(int _id); + MTGPlaneWalkerRule(GameObserver* observer, int _id); int canBeInList(MTGCardInstance * card); int added(MTGCardInstance * card); int removed(MTGCardInstance * card); @@ -330,7 +330,7 @@ public: int testDestroy(); void Update(float dt); void Render(); - MTGMomirRule(int _id, MTGAllCards * _collection); + MTGMomirRule(GameObserver* observer, int _id, MTGAllCards * _collection); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); int reactToClick(MTGCardInstance * card); int reactToClick(MTGCardInstance * card, int id); @@ -353,7 +353,7 @@ public: MTGAllCards * collection; MTGCardInstance * genEquip(int id); int testDestroy(); - MTGStoneHewerRule(int _id, MTGAllCards * _collection); + MTGStoneHewerRule(GameObserver* observer, int _id, MTGAllCards * _collection); int receiveEvent(WEvent * event); const char * getMenuText() { @@ -367,7 +367,7 @@ class MTGHermitRule: public MTGAbility { public: int testDestroy(); - MTGHermitRule(int _id); + MTGHermitRule(GameObserver* observer, int _id); int receiveEvent(WEvent * event); const char * getMenuText() { @@ -380,7 +380,7 @@ public: class MTGLifelinkRule: public MTGAbility { public: - MTGLifelinkRule(int _id); + MTGLifelinkRule(GameObserver* observer, int _id); int receiveEvent(WEvent * event); @@ -395,7 +395,7 @@ public: class MTGDeathtouchRule: public MTGAbility { public: - MTGDeathtouchRule(int _id); + MTGDeathtouchRule(GameObserver* observer, int _id); int receiveEvent(WEvent * event); @@ -412,7 +412,7 @@ public: class ParentChildRule: public MTGAbility { public: - ParentChildRule(int _id); + ParentChildRule(GameObserver* observer, int _id); int receiveEvent(WEvent * event); virtual ostream& toString(ostream& out) const; int testDestroy(); @@ -448,7 +448,7 @@ public: int receiveEvent(WEvent * event); void Update(float dt); void Render(); - HUDDisplay(int _id); + HUDDisplay(GameObserver* observer, int _id); ~HUDDisplay(); virtual HUDDisplay * clone() const; }; diff --git a/projects/mtg/include/PhaseRing.h b/projects/mtg/include/PhaseRing.h index 2337ab4c0..0a7a23b92 100644 --- a/projects/mtg/include/PhaseRing.h +++ b/projects/mtg/include/PhaseRing.h @@ -10,6 +10,7 @@ using namespace std; */ class Player; +class GameObserver; typedef enum { @@ -37,19 +38,20 @@ public: class PhaseRing { private: - static bool extraDamagePhase(int id); + bool extraDamagePhase(int id); + GameObserver* observer; public: list ring; list::iterator current; Phase * getCurrentPhase(); Phase * forward(bool sendEvents = true); Phase * goToPhase(int id, Player * player, bool sendEvents = true); - PhaseRing(Player* players[], int nbPlayers = 2); + PhaseRing(GameObserver* observer); ~PhaseRing(); int addPhase(Phase * phase); int addPhaseBefore(int id, Player* player, int after_id, Player * after_player, int allOccurences = 1); int removePhase(int id, Player * player, int allOccurences = 1); - static const char * phaseName(int id); + const char * phaseName(int id); static int phaseStrToInt(string s); }; diff --git a/projects/mtg/include/PlayGuiObjectController.h b/projects/mtg/include/PlayGuiObjectController.h index 5a92cf65b..7a947855e 100644 --- a/projects/mtg/include/PlayGuiObjectController.h +++ b/projects/mtg/include/PlayGuiObjectController.h @@ -15,7 +15,8 @@ protected: public: virtual void Update(float dt); virtual bool CheckUserInput(JButton key); - PlayGuiObjectController() + PlayGuiObjectController(GameObserver *observer) + : GuiLayer(observer) { last_user_move = 0; } diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index 1f0ade57b..fc52150aa 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -24,6 +24,7 @@ public: MODE_AI }; + string mAvatarName; JTexture * mAvatarTex; JQuadPtr mAvatar; int playMode; @@ -35,9 +36,9 @@ public: string deckName; string phaseRing; int offerInterruptOnPhase; - Player(string deckFile, string deckFileSmall, MTGDeck * deck = NULL); + Player(GameObserver *observer, string deckFile, string deckFileSmall, MTGDeck * deck = NULL); virtual ~Player(); - + virtual void setObserver(GameObserver*g); virtual void End(); virtual int displayStack() { @@ -94,17 +95,17 @@ public: ** Returns the path to the stats file of currently selected deck. */ std::string GetCurrentDeckStatsFile(); + + friend istream& operator>>(istream& in, Player& p); }; class HumanPlayer: public Player { public: - HumanPlayer(string deckFile, string deckFileSmall, MTGDeck * deck = NULL); - HumanPlayer(string deckFile); + HumanPlayer(GameObserver *observer, string deckFile, string deckFileSmall = "", MTGDeck * deck = NULL); }; ostream& operator<<(ostream&, const Player&); -istream& operator>>(istream& in, Player& p); #endif diff --git a/projects/mtg/include/Rules.h b/projects/mtg/include/Rules.h index f2bd214cf..f8b16efb5 100644 --- a/projects/mtg/include/Rules.h +++ b/projects/mtg/include/Rules.h @@ -10,31 +10,15 @@ class Player; class MTGPlayerCards; class MTGDeck; class MTGCardInstance; +class GameObserver; #define MAX_RULES_CARDS 4096; -class RulesPlayerZone -{ -public: - vector cards; - void add(int cardid); - RulesPlayerZone(); - void cleanup(); -}; - class RulesPlayerData { public: vector extraRules; - string phaseRing; - int offerInterruptOnPhase; - int life; - int poisonCount; - int damageCount; - int preventable; - string avatar; - ManaCost * manapool; - RulesPlayerZone zones[5]; + Player* player; RulesPlayerData(); ~RulesPlayerData(); void cleanup(); @@ -55,9 +39,9 @@ public: class Rules { protected: - Player * loadPlayerMomir(int isAI); - Player * loadPlayerRandom(int isAI, int mode); - Player * initPlayer(int playerId); + Player * loadPlayerMomir(GameObserver* observer, int isAI); + Player * loadPlayerRandom(GameObserver* observer, int isAI, int mode); + Player * initPlayer(GameObserver *observer, int playerId); MTGDeck * buildDeck(int playerId); int strToGameMode(string s); bool postUpdateInitDone; @@ -84,17 +68,17 @@ public: static int loadAllRules(); static void unloadAllRules(); static Rules * getRulesByFilename(string _filename); - void initPlayers(); + void initPlayers(GameObserver *observer); bool canChooseDeck(); //True if the players get to select their decks, false if the decks are automatically generated by the mode - void addExtraRules(); - void initGame(); + void addExtraRules(GameObserver *observer); + void initGame(GameObserver* observer); //second part of the initialization, needs to happen after the first update call - void postUpdateInit(); + void postUpdateInit(GameObserver* observer); void cleanup(); vector extraRules; RulesState initState; static int getMTGId(string name); - static MTGCardInstance * getCardByMTGId(int mtgid); + static MTGCardInstance * getCardByMTGId(GameObserver* observer, int mtgid); }; diff --git a/projects/mtg/include/TargetChooser.h b/projects/mtg/include/TargetChooser.h index b323a9428..12e8ab214 100644 --- a/projects/mtg/include/TargetChooser.h +++ b/projects/mtg/include/TargetChooser.h @@ -36,8 +36,9 @@ public: }; bool other; bool withoutProtections; - TargetChooser(MTGCardInstance * card = NULL, int _maxtargets = UNLITMITED_TARGETS, bool other = false, bool targetMin = false); + TargetChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _maxtargets = UNLITMITED_TARGETS, bool other = false, bool targetMin = false); Player * Owner; + GameObserver *observer; MTGCardInstance * source; MTGCardInstance * targetter; //Optional, usually equals source, used for protection from... int maxtargets; @@ -96,7 +97,9 @@ public: class TargetChooserFactory { + GameObserver* observer; public: + TargetChooserFactory(GameObserver *observer) : observer(observer) {}; TargetChooser * createTargetChooser(string s, MTGCardInstance * card, MTGAbility * ability = NULL); TargetChooser * createTargetChooser(MTGCardInstance * card); }; @@ -110,8 +113,8 @@ public: bool targetsZone(MTGGameZone * z); bool targetsZone(MTGGameZone * z,MTGCardInstance * mSource); bool withoutProtections; - TargetZoneChooser(MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); - TargetZoneChooser(int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); + TargetZoneChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); + TargetZoneChooser(GameObserver *observer, int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); virtual bool canTarget(Targetable * _card,bool withoutProtections = false); int setAllZones(); virtual TargetZoneChooser * clone() const; @@ -124,7 +127,7 @@ protected: MTGCardInstance * validTarget; public: bool withoutProtections; - CardTargetChooser(MTGCardInstance * card, MTGCardInstance * source, int * zones = NULL, int nbzones = 0); + CardTargetChooser(GameObserver *observer, MTGCardInstance * card, MTGCardInstance * source, int * zones = NULL, int nbzones = 0); virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual CardTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); @@ -136,8 +139,8 @@ public: int nbtypes; int types[10]; bool withoutProtections; - TypeTargetChooser(const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); - TypeTargetChooser(const char * _type, int * _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); + TypeTargetChooser(GameObserver *observer, const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); + TypeTargetChooser(GameObserver *observer, const char * _type, int * _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false); void addType(int type); void addType(const char * type); virtual bool canTarget(Targetable * target,bool withoutProtections = false); @@ -149,13 +152,13 @@ class DamageableTargetChooser: public TypeTargetChooser { public: bool withoutProtections; - DamageableTargetChooser(int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false) : - TypeTargetChooser("creature",_zones, _nbzones, card, _maxtargets, other, targetMin) + DamageableTargetChooser(GameObserver *observer, int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false) : + TypeTargetChooser(observer, "creature",_zones, _nbzones, card, _maxtargets, other, targetMin) { } ; - DamageableTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false) : - TypeTargetChooser("creature", card, _maxtargets, other, targetMin) + DamageableTargetChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false) : + TypeTargetChooser(observer, "creature", card, _maxtargets, other, targetMin) { } ; @@ -170,7 +173,7 @@ protected: Player * p; //In Case we can only target a specific player public: bool withoutProtections; - PlayerTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1, Player *_p = NULL); + PlayerTargetChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _maxtargets = 1, Player *_p = NULL); virtual bool canTarget(Targetable * target, bool withoutProtections = false); virtual PlayerTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); @@ -181,8 +184,8 @@ class DescriptorTargetChooser: public TargetZoneChooser public: CardDescriptor * cd; bool withoutProtections; - DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false,bool targetMin = false); - DescriptorTargetChooser(CardDescriptor * _cd, int * _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false,bool targetMin = false); + DescriptorTargetChooser(GameObserver *observer, CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false,bool targetMin = false); + DescriptorTargetChooser(GameObserver *observer, CardDescriptor * _cd, int * _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false,bool targetMin = false); virtual bool canTarget(Targetable * target,bool withoutProtections = false); ~DescriptorTargetChooser(); virtual DescriptorTargetChooser * clone() const; @@ -194,7 +197,7 @@ class SpellTargetChooser: public TargetChooser public: int color; bool withoutProtections; - SpellTargetChooser(MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, bool other = false, bool targetMin = false); + SpellTargetChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, bool other = false, bool targetMin = false); virtual bool canTarget(Targetable * target, bool withoutProtections = false); virtual SpellTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); @@ -205,7 +208,7 @@ class SpellOrPermanentTargetChooser: public TargetZoneChooser public: int color; bool withoutProtections; - SpellOrPermanentTargetChooser(MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, bool other = false, bool targetMin = false); + SpellOrPermanentTargetChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, bool other = false, bool targetMin = false); virtual bool canTarget(Targetable * target, bool withoutProtections = false); virtual SpellOrPermanentTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); @@ -217,7 +220,7 @@ public: int color; int state; bool withoutProtections; - DamageTargetChooser(MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, int state = NOT_RESOLVED); + DamageTargetChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, int state = NOT_RESOLVED); virtual bool canTarget(Targetable * target, bool withoutProtections = false); virtual DamageTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); @@ -230,7 +233,7 @@ public: Targetable * target; int triggerTarget; bool withoutProtections; - TriggerTargetChooser(int _triggerTarget); + TriggerTargetChooser(GameObserver *observer, int _triggerTarget); virtual bool targetsZone(MTGGameZone * z); virtual bool canTarget(Targetable * _target, bool withoutProtections = false); virtual TriggerTargetChooser * clone() const; @@ -241,13 +244,13 @@ class ProliferateChooser: public TypeTargetChooser { public: bool withoutProtections; - ProliferateChooser(int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false) : - TypeTargetChooser("*",_zones, _nbzones, card, _maxtargets, other, targetMin) + ProliferateChooser(GameObserver *observer, int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false, bool targetMin = false) : + TypeTargetChooser(observer, "*",_zones, _nbzones, card, _maxtargets, other, targetMin) { } ; - ProliferateChooser(MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false,bool targetMin = false) : - TypeTargetChooser("*", card, _maxtargets, other,targetMin) + ProliferateChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false,bool targetMin = false) : + TypeTargetChooser(observer, "*", card, _maxtargets, other,targetMin) { } ; @@ -262,13 +265,13 @@ public: bool withoutProtections; int type; TargetChooser * deeperTargeting; - ParentChildChooser(int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1,TargetChooser * deepTc = NULL,int type = 1, bool other = false, bool targetMin = false) : - TypeTargetChooser("*",_zones, _nbzones, card, _maxtargets, other, targetMin),type(type),deeperTargeting(deepTc) + ParentChildChooser(GameObserver *observer, int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1,TargetChooser * deepTc = NULL,int type = 1, bool other = false, bool targetMin = false) : + TypeTargetChooser(observer, "*",_zones, _nbzones, card, _maxtargets, other, targetMin),type(type),deeperTargeting(deepTc) { } ; - ParentChildChooser(MTGCardInstance * card = NULL, int _maxtargets = 1,TargetChooser * deepTc = NULL,int type = 1, bool other = false,bool targetMin = false) : - TypeTargetChooser("*", card, _maxtargets, other,targetMin),type(type),deeperTargeting(deepTc) + ParentChildChooser(GameObserver *observer, MTGCardInstance * card = NULL, int _maxtargets = 1,TargetChooser * deepTc = NULL,int type = 1, bool other = false,bool targetMin = false) : + TypeTargetChooser(observer, "*", card, _maxtargets, other,targetMin),type(type),deeperTargeting(deepTc) { } ; diff --git a/projects/mtg/include/Targetable.h b/projects/mtg/include/Targetable.h index 3a13705c4..68b3d5996 100644 --- a/projects/mtg/include/Targetable.h +++ b/projects/mtg/include/Targetable.h @@ -7,9 +7,14 @@ class Targetable { +protected: + GameObserver* observer; public: + Targetable(GameObserver* observer) : observer(observer) {}; virtual int typeAsTarget() = 0; virtual const string getDisplayName() const = 0; + inline GameObserver* getObserver() { return observer; }; + virtual void setObserver(GameObserver*g) { observer = g; }; }; #endif diff --git a/projects/mtg/include/Tasks.h b/projects/mtg/include/Tasks.h index ca835b10d..a2e213b86 100644 --- a/projects/mtg/include/Tasks.h +++ b/projects/mtg/include/Tasks.h @@ -59,7 +59,7 @@ public: virtual string getShortDesc() = 0; int getExpiration(); int getReward(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app) = 0; + virtual bool isDone(GameObserver* observer, GameApp * _app) = 0; bool isExpired(); void setExpiration(int _expiresIn); void passOneDay(); @@ -100,7 +100,7 @@ public: void addRandomTask(int diff = 100); void removeTask(Task *task); void passOneDay(); - void getDoneTasks(Player * _p1, Player * _p2, GameApp * _app, vector* result); + void getDoneTasks(GameObserver* observer, GameApp * _app, vector* result); int getTaskCount(); void Start(); @@ -121,7 +121,7 @@ public: TaskWinAgainst(int _opponent = 0); virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); }; class TaskSlaughter: public TaskWinAgainst @@ -133,7 +133,7 @@ public: TaskSlaughter(int _opponent = 0, int _targetLife = -15); virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); virtual void storeCustomAttribs(); virtual void restoreCustomAttribs(); virtual void randomize(); @@ -149,7 +149,7 @@ public: TaskDelay(int _opponent = 0, int _turn = 20); virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); virtual void storeCustomAttribs(); virtual void restoreCustomAttribs(); virtual void randomize(); @@ -166,7 +166,7 @@ public: virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); virtual void storeCustomAttribs(); virtual void restoreCustomAttribs(); virtual void randomize(); @@ -183,7 +183,7 @@ public: virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); virtual void storeCustomAttribs(); virtual void restoreCustomAttribs(); virtual void randomize(); @@ -200,7 +200,7 @@ public: virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); virtual void storeCustomAttribs(); virtual void restoreCustomAttribs(); virtual void randomize(); @@ -216,7 +216,7 @@ public: virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); virtual void storeCustomAttribs(); virtual void restoreCustomAttribs(); virtual void randomize(); @@ -232,7 +232,7 @@ public: virtual string createDesc(); virtual string getShortDesc(); - virtual bool isDone(Player * _p1, Player * _p2, GameApp * _app); + virtual bool isDone(GameObserver* observer, GameApp * _app); virtual void storeCustomAttribs(); virtual void restoreCustomAttribs(); virtual void randomize(); diff --git a/projects/mtg/include/TestSuiteAI.h b/projects/mtg/include/TestSuiteAI.h index 05cb35c72..9432b01e1 100644 --- a/projects/mtg/include/TestSuiteAI.h +++ b/projects/mtg/include/TestSuiteAI.h @@ -18,37 +18,18 @@ public: void cleanup(); }; -class TestSuitePlayerZone -{ -public: - int cards[MAX_TESTUITE_CARDS]; - int nbitems; - void add(int cardid); - TestSuitePlayerZone(); - void cleanup(); -}; - -class TestSuitePlayerData -{ -public: - int life; - ManaCost * manapool; - TestSuitePlayerZone zones[5]; - TestSuitePlayerData(); - ~TestSuitePlayerData(); - void cleanup(); - -}; class TestSuite; +class TestSuiteAI; class TestSuiteState { public: int phase; void parsePlayerState(int playerId, string s); TestSuiteState(); - TestSuitePlayerData playerData[2]; - void cleanup(); + + TestSuiteAI* players[2]; + void cleanup(TestSuite*); }; class TestSuitePregame @@ -66,8 +47,6 @@ private: TestSuiteState endState; TestSuiteActions actions; bool forceAbility; - int summoningSickness; - int load(const char * filename); void cleanup(); @@ -77,12 +56,13 @@ public: float timerLimit; int aiMaxCalls; int currentAction; + int summoningSickness; TestSuiteState initState; string getNextAction(); - MTGPlayerCards * buildDeck(int playerId); - Interruptible * getActionByMTGId(int mtgid); - int assertGame(); + MTGPlayerCards * buildDeck(Player*, int playerId); + Interruptible * getActionByMTGId(GameObserver* observer, int mtgid); + int assertGame(GameObserver*); public: int startTime, endTime; @@ -90,7 +70,7 @@ public: unsigned int seed; int nbFailed, nbTests, nbAIFailed, nbAITests; TestSuite(const char * filename); - void initGame(); + void initGame(GameObserver* g); void pregameTests(); int loadNext(); static int Log(const char * text); @@ -106,9 +86,10 @@ private: TestSuite * suite; public: - TestSuiteAI(TestSuite * suite, int playerId); + TestSuiteAI(GameObserver *observer, TestSuite * suite, int playerId); virtual int Act(float dt); virtual int displayStack(); + bool summoningSickness() {return (suite->summoningSickness == 1); } }; #endif diff --git a/projects/mtg/include/ThisDescriptor.h b/projects/mtg/include/ThisDescriptor.h index 1dfb29ea9..7dc869b81 100644 --- a/projects/mtg/include/ThisDescriptor.h +++ b/projects/mtg/include/ThisDescriptor.h @@ -22,7 +22,7 @@ class ThisDescriptor{ class ThisDescriptorFactory{ public: - ThisDescriptor * createThisDescriptor(string s); + ThisDescriptor * createThisDescriptor(GameObserver* observer, string s); }; class ThisCounter:public ThisDescriptor{ diff --git a/projects/mtg/include/Token.h b/projects/mtg/include/Token.h index 5aeb3d8f6..8af818f03 100644 --- a/projects/mtg/include/Token.h +++ b/projects/mtg/include/Token.h @@ -8,6 +8,7 @@ class Token: public MTGCardInstance MTGCardInstance * tokenSource; public: Token(string _name, MTGCardInstance * source, int _power = 0, int _toughness = 0); + Token(int id); }; #endif diff --git a/projects/mtg/src/AIHints.cpp b/projects/mtg/src/AIHints.cpp index 5d2e750a4..19a93e2c2 100644 --- a/projects/mtg/src/AIHints.cpp +++ b/projects/mtg/src/AIHints.cpp @@ -104,7 +104,7 @@ bool AIHints::abilityMatches(MTGAbility * ability, AIHint * hint) vector AIHints::findAbilities(AIHint * hint) { std::vector elems; - ActionLayer * al = GameObserver::GetInstance()->mLayers->actionLayer(); + ActionLayer * al = mPlayer->getObserver()->mLayers->actionLayer(); for (size_t i = 1; i < al->mObjects.size(); i++) //0 is not a mtgability...hackish { diff --git a/projects/mtg/src/AIMomirPlayer.cpp b/projects/mtg/src/AIMomirPlayer.cpp index 2c27ebb79..5eaa180c2 100644 --- a/projects/mtg/src/AIMomirPlayer.cpp +++ b/projects/mtg/src/AIMomirPlayer.cpp @@ -8,8 +8,8 @@ MTGAbility * AIMomirPlayer::momirAbility = NULL; -AIMomirPlayer::AIMomirPlayer(string file, string fileSmall, string avatarFile, MTGDeck * deck) : - AIPlayerBaka(file, fileSmall, avatarFile, deck) +AIMomirPlayer::AIMomirPlayer(GameObserver *observer, string file, string fileSmall, string avatarFile, MTGDeck * deck) : + AIPlayerBaka(observer, file, fileSmall, avatarFile, deck) { momirAbility = NULL; agressivity = 100; @@ -22,8 +22,7 @@ int AIMomirPlayer::getEfficiency(OrderedAIAction * action) if (cost && !(cost->isExtraPaymentSet())) return 0; //Does not handle abilities with sacrifice yet int efficiency = AIPlayerBaka::getEfficiency(action); - GameObserver * g = GameObserver::GetInstance(); - if (g->getCurrentGamePhase() < Constants::MTG_PHASE_FIRSTMAIN) return 0; + if (observer->getCurrentGamePhase() < Constants::MTG_PHASE_FIRSTMAIN) return 0; return efficiency; } @@ -31,8 +30,7 @@ MTGAbility * AIMomirPlayer::getMomirAbility() { if (momirAbility) return momirAbility; - GameObserver * g = GameObserver::GetInstance(); - momirAbility = g->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR); + momirAbility = observer->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR); return momirAbility; } @@ -79,17 +77,17 @@ int AIMomirPlayer::computeActions() You skip your Five on the play because it is the weakest drop. There are plenty of serviceable guys there, but very few bombs compared to other drops the general rule is this: if you want to get to Eight, you have to skip two drops on the play and one drop on the draw. */ - GameObserver * g = GameObserver::GetInstance(); - Player * p = g->currentPlayer; - if (!(g->currentlyActing() == this)) return 0; + + Player * p = observer->currentPlayer; + if (!(observer->currentlyActing() == this)) return 0; if (chooseTarget()) return 1; - int currentGamePhase = g->getCurrentGamePhase(); - if (g->isInterrupting == this) + int currentGamePhase = observer->getCurrentGamePhase(); + if (observer->isInterrupting == this) { // interrupting selectAbility(); return 1; } - else if (p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) + else if (p == this && observer->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) { //standard actions CardDescriptor cd; MTGCardInstance * card = NULL; @@ -111,7 +109,7 @@ int AIMomirPlayer::computeActions() int canPutLandsIntoPlay = game->playRestrictions->canPutIntoZone(card, game->inPlay); if (card && (canPutLandsIntoPlay == PlayRestriction::CAN_PLAY)) { - MTGAbility * putIntoPlay = g->mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY); + MTGAbility * putIntoPlay = observer->mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY); AIAction * a = NEW AIAction(this, putIntoPlay, card); //TODO putinplay action clickstream.push(a); return 1; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 4ed5aa142..b07b3bcd7 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -45,7 +45,7 @@ AIAction::AIAction(Player * owner, MTGCardInstance * c, MTGCardInstance * t) int AIAction::Act() { - GameObserver * g = GameObserver::GetInstance(); + GameObserver * g = owner->getObserver(); if (player && !playerAbilityTarget) { g->cardClick(NULL, player); @@ -85,10 +85,10 @@ int AIAction::Act() int AIAction::clickMultiAct(vector& actionTargets) { - GameObserver * g = GameObserver::GetInstance(); + GameObserver * g = player->getObserver(); TargetChooser * tc = g->getCurrentTargetChooser(); - if(!tc) return 0; bool sourceIncluded = false; + if(!tc) return 0; for(size_t f = 0;f < actionTargets.size();f++) { MTGCardInstance * card = ((MTGCardInstance *) actionTargets[f]); @@ -123,8 +123,8 @@ int AIAction::clickMultiAct(vector& actionTargets) return 1; } -AIPlayer::AIPlayer(string file, string fileSmall, MTGDeck * deck) : - Player(file, fileSmall, deck) +AIPlayer::AIPlayer(GameObserver *observer, string file, string fileSmall, MTGDeck * deck) : + Player(observer, file, fileSmall, deck) { agressivity = 50; forceBestAbilityUse = false; @@ -147,9 +147,8 @@ AIPlayer::~AIPlayer() int AIPlayer::Act(float dt) { - GameObserver * gameObs = GameObserver::GetInstance(); - if (gameObs->currentPlayer == this) - gameObs->userRequestNextGamePhase(); + if (observer->currentPlayer == this) + observer->userRequestNextGamePhase(); return 1; } @@ -217,7 +216,7 @@ int AIPlayer::clickSingleTarget(TargetChooser * tc, vector& potenti } -AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * opponent, int deckid) +AIPlayer * AIPlayerFactory::createAIPlayer(GameObserver *observer, MTGAllCards * collection, Player * opponent, int deckid) { char deckFile[512]; string avatarFilename; // default imagename @@ -268,7 +267,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op } // AIPlayerBaka will delete MTGDeck when it's time - AIPlayerBaka * baka = NEW AIPlayerBaka(deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting)); + AIPlayerBaka * baka = NEW AIPlayerBaka(observer, deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting)); baka->deckId = deckid; return baka; } @@ -284,7 +283,7 @@ void AIPlayer::Render() } #ifdef AI_CHANGE_TESTING -AIPlayer * AIPlayerFactory::createAIPlayerTest(MTGAllCards * collection, Player * opponent, string _folder) +AIPlayer * AIPlayerFactory::createAIPlayerTest(GameObserver *observer, MTGAllCards * collection, Player * opponent, string _folder) { char deckFile[512]; string avatarFilename; // default imagename @@ -312,7 +311,7 @@ AIPlayer * AIPlayerFactory::createAIPlayerTest(MTGAllCards * collection, Player if (!nbdecks) { if (_folder.size()) - return createAIPlayerTest(collection, opponent, ""); + return createAIPlayerTest(observer, collection, opponent, ""); return NULL; } deckid = 1 + WRand() % (nbdecks); @@ -334,8 +333,8 @@ AIPlayer * AIPlayerFactory::createAIPlayerTest(MTGAllCards * collection, Player // AIPlayerBaka will delete MTGDeck when it's time AIPlayerBaka * baka = opponent ? - NEW AIPlayerBakaB(deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting)) : - NEW AIPlayerBaka(deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting)); + NEW AIPlayerBakaB(observer, deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting)) : + NEW AIPlayerBaka(observer, deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting)); baka->deckId = deckid; return baka; } diff --git a/projects/mtg/src/AIPlayerBaka.cpp b/projects/mtg/src/AIPlayerBaka.cpp index 59f7b95e7..287719845 100644 --- a/projects/mtg/src/AIPlayerBaka.cpp +++ b/projects/mtg/src/AIPlayerBaka.cpp @@ -28,7 +28,7 @@ Player * OrderedAIAction::getPlayerTarget() int OrderedAIAction::getEfficiency(AADamager * aad) { Player * playerTarget = getPlayerTarget(); - GameObserver * g = GameObserver::GetInstance(); + GameObserver * g = owner->getObserver(); Player * p = g->currentlyActing(); MTGCardInstance * dTarget = target ? target : dynamic_cast(aad->getTarget()); @@ -68,7 +68,7 @@ int OrderedAIAction::getEfficiency() return efficiency; if (!ability) return 0; - GameObserver * g = GameObserver::GetInstance(); + GameObserver * g = owner->getObserver(); ActionStack * s = g->mLayers->stackLayer(); int currentPhase = g->getCurrentGamePhase(); @@ -271,7 +271,7 @@ int OrderedAIAction::getEfficiency() target = a->source; } - AbilityFactory af; + AbilityFactory af(g); int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); //i do not set a starting eff. on this ability, this allows Ai to sometimes randomly do it as it normally does. int currentPhase = g->getCurrentGamePhase(); @@ -333,7 +333,7 @@ int OrderedAIAction::getEfficiency() //ensuring that Ai grants abilities to creatures during first main, so it can actually use them in combat. //quick note: the eff is multiplied by creatures ranking then divided by the number of cards in hand. //the reason i do this is to encourage more casting and less waste of mana on abilities. - AbilityFactory af; + AbilityFactory af(g); int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); int efficiencyModifier = (25 * target->DangerRanking()); @@ -405,7 +405,7 @@ int OrderedAIAction::getEfficiency() Targetable * _t = alife->getTarget(); efficiency = 100; - AbilityFactory af; + AbilityFactory af(g); int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); if ((suggestion == BAKA_EFFECT_BAD && _t == p) || (suggestion == BAKA_EFFECT_GOOD && _t != p)) @@ -469,7 +469,7 @@ int OrderedAIAction::getEfficiency() default: if (target) { - AbilityFactory af; + AbilityFactory af(g); int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY,NULL,target); if (AADynamic * ady = dynamic_cast(a)) { @@ -749,13 +749,12 @@ bool AIPlayerBaka::payTheManaCost(ManaCost * cost, MTGCardInstance * target,vect } ManaCost * diff = pMana->Diff(cost); delete (pMana); - GameObserver * g = GameObserver::GetInstance(); map used; - for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); ++i) + for (size_t i = 1; i < observer->mLayers->actionLayer()->mObjects.size(); ++i) { //0 is not a mtgability...hackish //Make sure we can use the ability - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->mObjects[i]); AManaProducer * amp = dynamic_cast (a); if (amp && canHandleCost(amp)) { @@ -792,12 +791,11 @@ bool AIPlayerBaka::payTheManaCost(ManaCost * cost, MTGCardInstance * target,vect ManaCost * AIPlayerBaka::getPotentialMana(MTGCardInstance * target) { ManaCost * result = NEW ManaCost(); - GameObserver * g = GameObserver::GetInstance(); map used; - for (size_t i = 0; i < g->mLayers->actionLayer()->manaObjects.size(); i++) + for (size_t i = 0; i < observer->mLayers->actionLayer()->manaObjects.size(); i++) { //Make sure we can use the ability - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->manaObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->manaObjects[i]); AManaProducer * amp = dynamic_cast (a); GenericActivatedAbility * gmp = dynamic_cast(a); if(gmp && canHandleCost(gmp)) @@ -834,7 +832,6 @@ vector AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * if(!cost || (cost && !cost->getConvertedCost())) return vector(); ManaCost * result = NEW ManaCost(); - GameObserver * g = GameObserver::GetInstance(); map used; vectorpayments = vector(); if (this->getManaPool()->getConvertedCost()) @@ -844,9 +841,9 @@ vector AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * } int needColorConverted = cost->getConvertedCost()-int(cost->getCost(0)+cost->getCost(7)); int fullColor = 0; - for (size_t i = 0; i < g->mLayers->actionLayer()->manaObjects.size(); i++) + for (size_t i = 0; i < observer->mLayers->actionLayer()->manaObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->manaObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->manaObjects[i]); AManaProducer * amp = dynamic_cast (a); if(amp && (amp->getCost() && amp->getCost()->extraCosts && !amp->getCost()->extraCosts->canPay())) continue; @@ -946,9 +943,9 @@ vector AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * //{rw}{ub} would be 2 runs of this.90% of the time ai finds it's hybrid in pMana check. bool foundColor1 = false; bool foundColor2 = false; - for (size_t i = 0; i < g->mLayers->actionLayer()->manaObjects.size(); i++) + for (size_t i = 0; i < observer->mLayers->actionLayer()->manaObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->manaObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->manaObjects[i]); AManaProducer * amp = dynamic_cast (a); if (amp && canHandleCost(amp)) { @@ -1010,9 +1007,9 @@ vector AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * { //if we decided to play an "x" ability/card, lets go all out, these effects tend to be game winners. //add the rest of the mana. - for (size_t i = 0; i < g->mLayers->actionLayer()->manaObjects.size(); i++) + for (size_t i = 0; i < observer->mLayers->actionLayer()->manaObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->manaObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->manaObjects[i]); AManaProducer * amp = dynamic_cast (a); if (amp && canHandleCost(amp)) { @@ -1035,21 +1032,20 @@ vector AIPlayerBaka::canPaySunBurst(ManaCost * cost) //note it is still possible to use lotus petal for it's first mana ability and not later for a final color //a search of true sunburst would cause the game to come to a crawl, trust me, this is the "fast" method for sunburst :) ManaCost * result = NEW ManaCost(); - GameObserver * g = GameObserver::GetInstance(); map used; vectorpayments = vector(); int needColorConverted = 6; int fullColor = 0; result->add(this->getManaPool()); - for (size_t i = 0; i < g->mLayers->actionLayer()->manaObjects.size(); i++) + for (size_t i = 0; i < observer->mLayers->actionLayer()->manaObjects.size(); i++) { //Make sure we can use the ability if(fullColor == needColorConverted || fullColor == cost->getConvertedCost()) { - i = g->mLayers->actionLayer()->manaObjects.size(); + i = observer->mLayers->actionLayer()->manaObjects.size(); break; } - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->manaObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->manaObjects[i]); AManaProducer * amp = dynamic_cast (a); if(amp && amp->getCost() && amp->getCost()->extraCosts && !amp->getCost()->extraCosts->canPay()) continue;//pentid prism, has no cost but contains a counter cost, without this check ai will think it can still use this mana. @@ -1084,9 +1080,9 @@ vector AIPlayerBaka::canPaySunBurst(ManaCost * cost) } for(int i = fullColor;i < cost->getConvertedCost();i++) { - for (size_t i = 0; i < g->mLayers->actionLayer()->manaObjects.size(); i++) + for (size_t i = 0; i < observer->mLayers->actionLayer()->manaObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->manaObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->manaObjects[i]); AManaProducer * amp = dynamic_cast (a); if (amp && canHandleCost(amp)) { @@ -1151,10 +1147,9 @@ int AIPlayerBaka::createAbilityTargets(MTGAbility * a, MTGCardInstance * c, Rank return 1; } vectorpotentialTargets; - GameObserver * g = GameObserver::GetInstance(); for (int i = 0; i < 2; i++) { - Player * p = g->players[i]; + Player * p = observer->players[i]; MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay,p->game->stack }; if(a->getActionTc()->canTarget((Targetable*)p)) { @@ -1260,8 +1255,7 @@ int AIPlayerBaka::selectAbility() if (selectHintAbility()) return 1; - GameObserver * go = GameObserver::GetInstance(); - if(go->mLayers->stackLayer()->lastActionController == this) + if(observer->mLayers->stackLayer()->lastActionController == this) { //this is here for 2 reasons, MTG rules state that priority is passed with each action. //without this ai is able to chain cast {t}:damage:1 target(creature) from everything it can all at once. @@ -1271,14 +1265,13 @@ int AIPlayerBaka::selectAbility() RankingContainer ranking; list::iterator it; - GameObserver * g = GameObserver::GetInstance(); vectorabilityPayment = vector(); //This loop is extrmely inefficient. TODO: optimize! ManaCost * totalPotentialMana = getPotentialMana(); totalPotentialMana->add(this->getManaPool()); - for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) + for (size_t i = 1; i < observer->mLayers->actionLayer()->mObjects.size(); i++) { //0 is not a mtgability...hackish - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); + MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->mObjects[i]); //Skip mana abilities for performance if (dynamic_cast (a)) continue; @@ -1353,14 +1346,12 @@ int AIPlayerBaka::selectAbility() int AIPlayerBaka::interruptIfICan() { - GameObserver * g = GameObserver::GetInstance(); - - if (g->mLayers->stackLayer()->askIfWishesToInterrupt == this) + if (observer->mLayers->stackLayer()->askIfWishesToInterrupt == this) { if (!clickstream.empty()) - g->mLayers->stackLayer()->cancelInterruptOffer(); + observer->mLayers->stackLayer()->cancelInterruptOffer(); else - return g->mLayers->stackLayer()->setIsInterrupting(this); + return observer->mLayers->stackLayer()->setIsInterrupting(this); } return 0; } @@ -1368,7 +1359,7 @@ int AIPlayerBaka::interruptIfICan() int AIPlayerBaka::effectBadOrGood(MTGCardInstance * card, int mode, TargetChooser * tc) { int id = card->getMTGId(); - AbilityFactory af; + AbilityFactory af(observer); int autoGuess = af.magicText(id, NULL, card, mode, tc); if (autoGuess) return autoGuess; @@ -1379,12 +1370,11 @@ int AIPlayerBaka::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCard { vector potentialTargets; TargetChooser * tc = _tc; - GameObserver * gameObs = GameObserver::GetInstance(); - if (!(gameObs->currentlyActing() == this)) + if (!(observer->currentlyActing() == this)) return 0; if (!tc) { - tc = gameObs->getCurrentTargetChooser(); + tc = observer->getCurrentTargetChooser(); } if (!tc || !tc->source || tc->maxtargets < 1) return 0; @@ -1395,10 +1385,10 @@ int AIPlayerBaka::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCard potentialTargets.clear(); } //Make sure we own the decision to choose the targets - assert(tc->Owner == gameObs->currentlyActing()); - if (tc && tc->Owner != gameObs->currentlyActing()) + assert(tc->Owner == observer->currentlyActing()); + if (tc && tc->Owner != observer->currentlyActing()) { - gameObs->currentActionPlayer = tc->Owner; + observer->currentActionPlayer = tc->Owner; //this is a hack, but if we hit this condition we are locked in a infinate loop //so lets give the tc to its owner //todo:find the root cause of this. @@ -1413,7 +1403,7 @@ int AIPlayerBaka::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCard int cardEffect = effectBadOrGood(tc->source, MODE_TARGET, tc); if(tc->belongsToAbility.size()) { - AbilityFactory af; + AbilityFactory af(observer); MTGAbility * withoutGuessing = af.parseMagicLine(tc->belongsToAbility,NULL,NULL,tc->source); cardEffect = af.abilityEfficiency(withoutGuessing,this,MODE_TARGET,tc,NULL); delete withoutGuessing; @@ -1461,7 +1451,7 @@ int AIPlayerBaka::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCard { if(tc->maxtargets != 1 && tc->belongsToAbility.size()) { - AbilityFactory af; + AbilityFactory af(observer); MTGAbility * withoutGuessing = af.parseMagicLine(tc->belongsToAbility,NULL,NULL,tc->source); OrderedAIAction * effCheck = NEW OrderedAIAction(this, withoutGuessing,(MTGCardInstance*)tc->source,card); if(effCheck->getEfficiency()) @@ -1504,7 +1494,7 @@ int AIPlayerBaka::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCard //Couldn't find any valid target, //usually that's because we played a card that has bad side effects (ex: when X comes into play, return target land you own to your hand) //so we try again to choose a target in the other player's field... - int cancel = gameObs->cancelCurrentAction(); + int cancel = observer->cancelCurrentAction(); if (!cancel && !forceTarget) return chooseTarget(tc, target->opponent(), NULL, checkOnly); //ERROR!!! @@ -1514,8 +1504,7 @@ int AIPlayerBaka::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCard int AIPlayerBaka::selectMenuOption() { - GameObserver * g = GameObserver::GetInstance(); - ActionLayer * object = g->mLayers->actionLayer(); + ActionLayer * object = observer->mLayers->actionLayer(); int doThis = -1; if (object->menuObject) { @@ -1633,7 +1622,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty //for preformence reason we only look for specific mana if the payment couldn't be made with pmana. if ((currentCost > maxCost || hasX) && (gotPayments.size() || pMana->canAfford(card->getManaCost()))) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * tc = tcf.createTargetChooser(card); int shouldPlayPercentage = 10; if (tc) @@ -1705,7 +1694,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty } if(card->getRestrictions().size()) { - AbilityFactory af; + AbilityFactory af(observer); int canPlay = af.parseCastRestrictions(card,card->controller(),card->getRestrictions()); if(!canPlay) continue; @@ -1746,27 +1735,26 @@ int AIPlayerBaka::computeActions() reasoning:I split this from 2 to 3 else statements, leaving chooseblockers in the 3rd else, the 2nd else is run about 90% of the time over the third, this was causing ai to miss the chance to chooseblockers() when it could have blocked almost 90% of the time.*/ - GameObserver * g = GameObserver::GetInstance(); Player * p = this; - Player * currentP = g->currentlyActing(); + Player * currentP = observer->currentlyActing(); if (!(currentP == p)) return 0; - ActionLayer * object = g->mLayers->actionLayer(); + ActionLayer * object = observer->mLayers->actionLayer(); if (object->menuObject) { int doThis = selectMenuOption(); if(doThis >= 0) { if(object->abilitiesMenu->isMultipleChoice) - g->mLayers->actionLayer()->doMultipleChoice(doThis); + observer->mLayers->actionLayer()->doMultipleChoice(doThis); else - g->mLayers->actionLayer()->doReactTo(doThis); + observer->mLayers->actionLayer()->doReactTo(doThis); } else if(doThis < 0 || object->checkCantCancel()) - g->mLayers->actionLayer()->doReactTo(object->abilitiesMenu->mObjects.size()-1); + observer->mLayers->actionLayer()->doReactTo(object->abilitiesMenu->mObjects.size()-1); return 1; } - TargetChooser * currentTc = g->getCurrentTargetChooser(); + TargetChooser * currentTc = observer->getCurrentTargetChooser(); if(currentTc) { int targetResult = currentTc->Owner == this? chooseTarget():0; @@ -1783,13 +1771,13 @@ int AIPlayerBaka::computeActions() {//is already looking kick me out of this function! return 0; } - Interruptible * action = g->mLayers->stackLayer()->getAt(-1); + Interruptible * action = observer->mLayers->stackLayer()->getAt(-1); Spell * spell = dynamic_cast(action); Player * lastStackActionController = spell ? spell->source->controller() : NULL; - if (g->isInterrupting == this + if (observer->isInterrupting == this && this == currentP //and i am the currentlyActivePlayer - && ((lastStackActionController && lastStackActionController != this) || (g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0))) + && ((lastStackActionController && lastStackActionController != this) || (observer->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0))) //am im not interupting my own spell, or the stack contains nothing. { bool ipotential = false; @@ -1834,9 +1822,9 @@ int AIPlayerBaka::computeActions() findingCard = false; return 1; } - else if(g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) + else if(observer->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) { //standard actions - switch (g->getCurrentGamePhase()) + switch (observer->getCurrentGamePhase()) { case Constants::MTG_PHASE_UPKEEP: selectAbility(); @@ -1904,13 +1892,13 @@ int AIPlayerBaka::computeActions() } case Constants::MTG_PHASE_COMBATATTACKERS: { - if(g->currentPlayer == this)//only on my turns. + if(observer->currentPlayer == this)//only on my turns. chooseAttackers(); break; } case Constants::MTG_PHASE_COMBATBLOCKERS: { - if(g->currentPlayer != this)//only on my opponents turns. + if(observer->currentPlayer != this)//only on my opponents turns. chooseBlockers(); break; } @@ -1924,7 +1912,7 @@ int AIPlayerBaka::computeActions() else { cout << "my turn" << endl; - switch (g->getCurrentGamePhase()) + switch (observer->getCurrentGamePhase()) { case Constants::MTG_PHASE_UPKEEP: case Constants::MTG_PHASE_FIRSTMAIN: @@ -1996,11 +1984,10 @@ int AIPlayerBaka::chooseAttackers() cd.init(); cd.setType("creature"); MTGCardInstance * card = NULL; - GameObserver * g = GameObserver::GetInstance(); - MTGAbility * a = g->mLayers->actionLayer()->getAbility(MTGAbility::MTG_ATTACK_RULE); + MTGAbility * a = observer->mLayers->actionLayer()->getAbility(MTGAbility::MTG_ATTACK_RULE); while ((card = cd.nextmatch(game->inPlay, card))) { - g->mLayers->actionLayer()->reactToClick(a, card); + observer->mLayers->actionLayer()->reactToClick(a, card); } } return 1; @@ -2022,10 +2009,8 @@ int AIPlayerBaka::canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *en int AIPlayerBaka::chooseBlockers() { - GameObserver * g = GameObserver::GetInstance(); - //Should not block during my own turn... - if (g->currentPlayer == this) + if (observer->currentPlayer == this) return 0; map opponentsToughness; int opponentForce = getCreaturesInfo(opponent(), INFO_CREATURESPOWER); @@ -2047,12 +2032,12 @@ int AIPlayerBaka::chooseBlockers() cd.setType("Creature"); cd.unsecureSetTapped(-1); card = NULL; - MTGAbility * a = g->mLayers->actionLayer()->getAbility(MTGAbility::MTG_BLOCK_RULE); + MTGAbility * a = observer->mLayers->actionLayer()->getAbility(MTGAbility::MTG_BLOCK_RULE); // We first try to block the major threats, those that are marked in the Top 3 of our stats while ((card = cd.nextmatch(game->inPlay, card))) { - g->mLayers->actionLayer()->reactToClick(a, card); + observer->mLayers->actionLayer()->reactToClick(a, card); int set = 0; while (!set) { @@ -2076,7 +2061,7 @@ int AIPlayerBaka::chooseBlockers() } else { - g->mLayers->actionLayer()->reactToClick(a, card); + observer->mLayers->actionLayer()->reactToClick(a, card); } } } @@ -2091,7 +2076,7 @@ int AIPlayerBaka::chooseBlockers() { while (card->defenser) { - g->mLayers->actionLayer()->reactToClick(a, card); + observer->mLayers->actionLayer()->reactToClick(a, card); } } } @@ -2102,7 +2087,7 @@ int AIPlayerBaka::chooseBlockers() { if (!card->defenser) { - g->mLayers->actionLayer()->reactToClick(a, card); + observer->mLayers->actionLayer()->reactToClick(a, card); int set = 0; while (!set) { @@ -2116,7 +2101,7 @@ int AIPlayerBaka::chooseBlockers() if (opponentsToughness[attacker] <= 0 || (card->toughness <= attacker->power && opponentForce * 2 < life && !canFirstStrikeKill(card, attacker)) || attacker->nbOpponents() > 1) { - g->mLayers->actionLayer()->reactToClick(a, card); + observer->mLayers->actionLayer()->reactToClick(a, card); } else { @@ -2132,12 +2117,10 @@ int AIPlayerBaka::chooseBlockers() int AIPlayerBaka::orderBlockers() { - - GameObserver * g = GameObserver::GetInstance(); - if (ORDER == g->combatStep && g->currentPlayer == this) + if (ORDER == observer->combatStep && observer->currentPlayer == this) { DebugTrace("AIPLAYER: order blockers"); - g->userRequestNextGamePhase(); //TODO clever rank of blockers + observer->userRequestNextGamePhase(); //TODO clever rank of blockers return 1; } @@ -2146,8 +2129,7 @@ int AIPlayerBaka::orderBlockers() int AIPlayerBaka::affectCombatDamages(CombatStep step) { - GameObserver * g = GameObserver::GetInstance(); - GuiCombat * gc = g->mLayers->combatLayer(); + GuiCombat * gc = observer->mLayers->combatLayer(); for (vector::iterator attacker = gc->attackers.begin(); attacker != gc->attackers.end(); ++attacker) gc->autoaffectDamage(*attacker, step); return 1; @@ -2156,7 +2138,7 @@ int AIPlayerBaka::affectCombatDamages(CombatStep step) //TODO: Deprecate combatDamages int AIPlayerBaka::combatDamages() { - int currentGamePhase = GameObserver::GetInstance()->getCurrentGamePhase(); + int currentGamePhase = observer->getCurrentGamePhase(); if (currentGamePhase == Constants::MTG_PHASE_COMBATBLOCKERS) return orderBlockers(); @@ -2200,8 +2182,8 @@ int AIPlayerBaka::receiveEvent(WEvent * event) } -AIPlayerBaka::AIPlayerBaka(string file, string fileSmall, string avatarFile, MTGDeck * deck) : - AIPlayer(file, fileSmall, deck) +AIPlayerBaka::AIPlayerBaka(GameObserver *observer, string file, string fileSmall, string avatarFile, MTGDeck * deck) : + AIPlayer(observer, file, fileSmall, deck) { nextCardToPlay = NULL; @@ -2236,13 +2218,12 @@ AIPlayerBaka::AIPlayerBaka(string file, string fileSmall, string avatarFile, MTG int AIPlayerBaka::Act(float dt) { - GameObserver * g = GameObserver::GetInstance(); - if (!(g->currentlyActing() == this)) + if (!(observer->currentlyActing() == this)) { return 0; } - int currentGamePhase = g->getCurrentGamePhase(); + int currentGamePhase = observer->getCurrentGamePhase(); oldGamePhase = currentGamePhase; @@ -2263,7 +2244,7 @@ int AIPlayerBaka::Act(float dt) interruptIfICan(); //computeActions only when i have priority - if (!(g->currentlyActing() == this)) + if (!(observer->currentlyActing() == this)) { DebugTrace("Cannot interrupt"); return 0; @@ -2272,14 +2253,14 @@ int AIPlayerBaka::Act(float dt) computeActions(); if (clickstream.empty()) { - if (g->isInterrupting == this) + if (observer->isInterrupting == this) { - g->mLayers->stackLayer()->cancelInterruptOffer(); //endOfInterruption(); + observer->mLayers->stackLayer()->cancelInterruptOffer(); //endOfInterruption(); } else { - if (g->currentActionPlayer == this)//if im not the action player why would i requestnextphase? - g->userRequestNextGamePhase(); + if (observer->currentActionPlayer == this)//if im not the action player why would i requestnextphase? + observer->userRequestNextGamePhase(); } } else diff --git a/projects/mtg/src/AIPlayerBakaB.cpp b/projects/mtg/src/AIPlayerBakaB.cpp index 2b8014c1a..2c9f68b58 100644 --- a/projects/mtg/src/AIPlayerBakaB.cpp +++ b/projects/mtg/src/AIPlayerBakaB.cpp @@ -178,8 +178,8 @@ int AIPlayerBakaB::receiveEvent(WEvent * event) } -AIPlayerBakaB::AIPlayerBakaB(string file, string fileSmall, string avatarFile, MTGDeck * deck) : - AIPlayerBaka(file, fileSmall, avatarFile, deck) +AIPlayerBakaB::AIPlayerBakaB(GameObserver *observer, string file, string fileSmall, string avatarFile, MTGDeck * deck) : + AIPlayerBaka(observer, file, fileSmall, avatarFile, deck) { } diff --git a/projects/mtg/src/AIStats.cpp b/projects/mtg/src/AIStats.cpp index 42cd11b1f..28e05dc93 100644 --- a/projects/mtg/src/AIStats.cpp +++ b/projects/mtg/src/AIStats.cpp @@ -50,7 +50,7 @@ void AIStats::updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, f else if (damage->target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) { MTGCardInstance * target = (MTGCardInstance *) damage->target; - if (target->controller() == player && !target->isInPlay()) + if (target->controller() == player && !target->isInPlay(player->getObserver())) { //One of my creatures got lethal damage... stat->value += static_cast(multiplier * STATS_CREATURE_MULTIPLIER * damage->damage); @@ -79,7 +79,7 @@ int AIStats::receiveEvent(WEvent * event) } } - GameObserver * g = GameObserver::GetInstance(); + GameObserver * g = player->getObserver(); //Lords map lords; for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) @@ -190,7 +190,7 @@ void AIStats::save() void AIStats::Render() { - GameObserver * g = GameObserver::GetInstance(); + GameObserver * g = player->getObserver(); float x0 = 10; if (player == g->players[1]) x0 = 280; diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index f57f821fa..d2e193cf0 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -34,7 +34,7 @@ int ActionLayer::removeFromGame(ActionElement * e) i = getIndexOf(e); //the destroy event might have changed the contents of mObjects, so we get the index again if (i == -1) return 0; //Should not happen, it means we deleted thesame object twice? - AbilityFactory af; + AbilityFactory af(observer); if(MTGAbility * a = dynamic_cast(e)) { AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)e)); @@ -90,10 +90,9 @@ int ActionLayer::reactToTargetClick(ActionElement* ability, Targetable * card) bool ActionLayer::CheckUserInput(JButton key) { - GameObserver * g = GameObserver::GetInstance(); - if (g->mExtraPayment && key == JGE_BTN_SEC) + if (observer->mExtraPayment && key == JGE_BTN_SEC) { - g->mExtraPayment = NULL; + observer->mExtraPayment = NULL; return 1; } if (menuObject) @@ -121,7 +120,6 @@ void ActionLayer::Update(float dt) return; } modal = 0; - GameObserver* game = GameObserver::GetInstance(); for (int i = (int)(mObjects.size()) - 1; i >= 0; i--) { //a dirty hack, there might be cases when the mObject array gets reshaped if an ability removes some of its children abilites @@ -136,10 +134,10 @@ void ActionLayer::Update(float dt) { ActionElement * currentAction = (ActionElement *) mObjects[i]; if (currentAction->testDestroy()) - game->removeObserver(currentAction); + observer->removeObserver(currentAction); } } - int newPhase = game->getCurrentGamePhase(); + int newPhase = observer->getCurrentGamePhase(); for (size_t i = 0; i < mObjects.size(); i++) { if (mObjects[i] != NULL) @@ -429,7 +427,7 @@ void ActionLayer::ButtonPressed(int controllerid, int controlid) } else if (controlid == kCancelMenuID) { - GameObserver::GetInstance()->mLayers->stackLayer()->endOfInterruption(); + observer->mLayers->stackLayer()->endOfInterruption(); menuObject = 0; } else @@ -463,12 +461,13 @@ void ActionLayer::ButtonPressedOnMultipleChoice(int choice) } else if (currentMenuObject == kCancelMenuID) { - GameObserver::GetInstance()->mLayers->stackLayer()->endOfInterruption(); + observer->mLayers->stackLayer()->endOfInterruption(); } menuObject = 0; } -ActionLayer::ActionLayer() +ActionLayer::ActionLayer(GameObserver *observer) + : GuiLayer(observer) { menuObject = NULL; abilitiesMenu = NULL; diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index 4f300e408..c33fb5524 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -34,39 +34,35 @@ NextGamePhase requested by user */ int NextGamePhase::resolve() { - GameObserver::GetInstance()->nextGamePhase(); + observer->nextGamePhase(); return 1; } const string NextGamePhase::getDisplayName() const { std::ostringstream stream; - stream << "NextGamePhase. (Current phase is: " << PhaseRing::phaseName(GameObserver::GetInstance()->getCurrentGamePhase()) - << ")"; + stream << "NextGamePhase. (Current phase is: " << observer->getCurrentGamePhaseName() << ")"; return stream.str(); } void NextGamePhase::Render() { - GameObserver * g = GameObserver::GetInstance(); - int nextPhase = (g->getCurrentGamePhase() + 1) % Constants::MTG_PHASE_CLEANUP; - WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); mFont->SetBase(0); mFont->SetScale(DEFAULT_MAIN_FONT_SCALE); char buffer[200]; int playerId = 1; - if (g->currentActionPlayer == GameObserver::GetInstance()->players[1]) + if (observer->currentActionPlayer == observer->players[1]) playerId = 2; - sprintf(buffer, "%s %i : -> %s", _("Player").c_str(), playerId, _(PhaseRing::phaseName(nextPhase)).c_str()); + sprintf(buffer, "%s %i : -> %s", _("Player").c_str(), playerId, observer->getNextGamePhaseName()); mFont->DrawString(buffer, x + 30, y, JGETEXT_LEFT); } -NextGamePhase::NextGamePhase(int id) : -Interruptible(id) +NextGamePhase::NextGamePhase(GameObserver* observer, int id) : +Interruptible(observer, id) { mHeight = 40; type = ACTION_NEXTGAMEPHASE; @@ -172,8 +168,8 @@ void StackAbility::Render() Interruptible::Render(source, quad.get(), alt1, alt2, action); } -StackAbility::StackAbility(int id, MTGAbility * _ability) : -Interruptible(id), ability(_ability) +StackAbility::StackAbility(GameObserver* observer, int id, MTGAbility * _ability) : +Interruptible(observer, id), ability(_ability) { type = ACTION_ABILITY; } @@ -197,8 +193,8 @@ const string StackAbility::getDisplayName() const /* Spell Cast */ -Spell::Spell(MTGCardInstance * _source) : -Interruptible(0) +Spell::Spell(GameObserver* observer, MTGCardInstance * _source) : +Interruptible(observer, 0) { source = _source; mHeight = 40; @@ -210,8 +206,8 @@ Interruptible(0) source->castMethod = Constants::NOT_CAST; } -Spell::Spell(int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _cost, int payResult) : -Interruptible(id), tc(tc), cost(_cost), payResult(payResult) +Spell::Spell(GameObserver* observer, int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _cost, int payResult) : +Interruptible(observer, id), tc(tc), cost(_cost), payResult(payResult) { if (!cost) cost = NEW ManaCost(); source = _source; @@ -287,7 +283,6 @@ Spell::~Spell() int Spell::resolve() { - GameObserver * game = GameObserver::GetInstance(); if (!source->hasType(Subtypes::TYPE_INSTANT) && !source->hasType(Subtypes::TYPE_SORCERY)) { Player * p = source->controller(); @@ -311,8 +306,8 @@ int Spell::resolve() } } - AbilityFactory af; - af.addAbilities(game->mLayers->actionLayer()->getMaxId(), this); + AbilityFactory af(observer); + af.addAbilities(observer->mLayers->actionLayer()->getMaxId(), this); return 1; } @@ -393,8 +388,8 @@ ostream& Spell::toString(ostream& out) const /* Put a card in graveyard */ -PutInGraveyard::PutInGraveyard(int id, MTGCardInstance * _card) : -Interruptible(id) +PutInGraveyard::PutInGraveyard(GameObserver* observer, int id, MTGCardInstance * _card) : +Interruptible(observer, id) { card = _card; removeFromGame = 0; @@ -403,9 +398,8 @@ Interruptible(id) int PutInGraveyard::resolve() { - GameObserver * g = GameObserver::GetInstance(); MTGGameZone * zone = card->getCurrentZone(); - if (zone == g->players[0]->game->inPlay || zone == g->players[1]->game->inPlay) + if (zone == observer->players[0]->game->inPlay || zone == observer->players[1]->game->inPlay) { card->owner->game->putInZone(card, zone, card->owner->game->graveyard); return 1; @@ -447,8 +441,8 @@ ostream& PutInGraveyard::toString(ostream& out) const } /* Draw a Card */ -DrawAction::DrawAction(int id, Player * _player, int _nbcards) : -Interruptible(id), nbcards(_nbcards), player(_player) +DrawAction::DrawAction(GameObserver* observer, int id, Player * _player, int _nbcards) : +Interruptible(observer, id), nbcards(_nbcards), player(_player) { } @@ -468,7 +462,7 @@ void DrawAction::Render() mFont->SetScale(DEFAULT_MAIN_FONT_SCALE); char buffer[200]; int playerId = 1; - if (player == GameObserver::GetInstance()->players[1]) + if (player == observer->players[1]) playerId = 2; sprintf(buffer, _("Player %i draws %i card").c_str(), playerId, nbcards); mFont->DrawString(buffer, x + 35, y + GetVerticalTextOffset(), JGETEXT_LEFT); @@ -480,8 +474,8 @@ ostream& DrawAction::toString(ostream& out) const return out; } ////// -LifeAction::LifeAction(int id, Damageable * _target, int amount) : -Interruptible(id), amount(amount),target(_target) +LifeAction::LifeAction(GameObserver* observer, int id, Damageable * _target, int amount) : +Interruptible(observer, id), amount(amount),target(_target) { } @@ -514,16 +508,16 @@ ostream& LifeAction::toString(ostream& out) const /* The Action Stack itself */ int ActionStack::addPutInGraveyard(MTGCardInstance * card) { - PutInGraveyard * death = NEW PutInGraveyard(mObjects.size(), card); + PutInGraveyard * death = NEW PutInGraveyard(observer, mObjects.size(), card); addAction(death); return 1; } int ActionStack::addAbility(MTGAbility * ability) { - StackAbility * stackAbility = NEW StackAbility(mObjects.size(), ability); + StackAbility * stackAbility = NEW StackAbility(observer, mObjects.size(), ability); int result = addAction(stackAbility); - if (!game->players[0]->isAI() && ability->source->controller() == game->players[0] && 0 + if (!observer->players[0]->isAI() && ability->source->controller() == observer->players[0] && 0 == options[Options::INTERRUPTMYABILITIES].number) interruptDecision[0] = DONT_INTERRUPT; return result; @@ -531,21 +525,21 @@ int ActionStack::addAbility(MTGAbility * ability) int ActionStack::addDraw(Player * player, int nb_cards) { - DrawAction * draw = NEW DrawAction(mObjects.size(), player, nb_cards); + DrawAction * draw = NEW DrawAction(observer, mObjects.size(), player, nb_cards); addAction(draw); return 1; } int ActionStack::addLife(Damageable * _target, int amount) { - LifeAction * life = NEW LifeAction(mObjects.size(), _target, amount); + LifeAction * life = NEW LifeAction(observer, mObjects.size(), _target, amount); addAction(life); return 1; } int ActionStack::addDamage(MTGCardInstance * _source, Damageable * _target, int _damage) { - Damage * damage = NEW Damage(_source, _target, _damage); + Damage * damage = NEW Damage(observer, _source, _target, _damage); addAction(damage); _source->thatmuch = _damage; _target->thatmuch = _damage; @@ -557,10 +551,9 @@ int ActionStack::AddNextGamePhase() if (getNext(NULL, NOT_RESOLVED)) return 0; - NextGamePhase * next = NEW NextGamePhase(mObjects.size()); + NextGamePhase * next = NEW NextGamePhase(observer, mObjects.size()); addAction(next); - game->currentActionPlayer = game->GetInstance()->currentActionPlayer; - int playerId = (game->currentActionPlayer == game->players[1]) ? 1 : 0; + int playerId = (observer->currentActionPlayer == observer->players[1]) ? 1 : 0; interruptDecision[playerId] = 1; return 1; } @@ -570,7 +563,7 @@ int ActionStack::AddNextCombatStep() if (getNext(NULL, NOT_RESOLVED)) return 0; - NextGamePhase * next = NEW NextGamePhase(mObjects.size()); + NextGamePhase * next = NEW NextGamePhase(observer, mObjects.size()); addAction(next); return 1; } @@ -586,16 +579,16 @@ int ActionStack::setIsInterrupting(Player * player) } // Is it a valid interruption request, or is uninterruptible stuff going on in the game? - if (game->getCurrentTargetChooser()) + if (observer->getCurrentTargetChooser()) { DebugTrace("ActionStack: WARNING - We were asked to interrupt, During Targetchoosing" << endl - << "source: " << (game->getCurrentTargetChooser()->source ? game->getCurrentTargetChooser()->source->name : "None" ) << endl ); + << "source: " << (observer->getCurrentTargetChooser()->source ? observer->getCurrentTargetChooser()->source->name : "None" ) << endl ); return 0; } - int playerId = (player == game->players[1]) ? 1 : 0; + int playerId = (player == observer->players[1]) ? 1 : 0; interruptDecision[playerId] = -1; - game->isInterrupting = player; + observer->isInterrupting = player; return 1; } @@ -606,7 +599,7 @@ int ActionStack::addAction(Interruptible * action) interruptDecision[i] = 0; } Add(action); - lastActionController = game->currentlyActing(); + lastActionController = observer->currentlyActing(); DebugTrace("Action added to stack: " << action->getDisplayName()); return 1; @@ -620,9 +613,9 @@ Spell * ActionStack::addSpell(MTGCardInstance * _source, TargetChooser * tc, Man { mana = NULL; } - Spell * spell = NEW Spell(mObjects.size(), _source, tc, mana, payResult); + Spell * spell = NEW Spell(observer, mObjects.size(), _source, tc, mana, payResult); addAction(spell); - if (!game->players[0]->isAI() && _source->controller() == game->players[0] && 0 == options[Options::INTERRUPTMYSPELLS].number) + if (!observer->players[0]->isAI() && _source->controller() == observer->players[0] && 0 == options[Options::INTERRUPTMYSPELLS].number) interruptDecision[0] = DONT_INTERRUPT; return spell; } @@ -637,7 +630,7 @@ Interruptible * ActionStack::getAt(int id) } ActionStack::ActionStack(GameObserver* game) - : game(game) + : GuiLayer(game) { for (int i = 0; i < 2; i++) interruptDecision[i] = 0; @@ -840,9 +833,9 @@ void ActionStack::Update(float dt) askIfWishesToInterrupt = NULL; //modal = 0; - GameObserver * game = GameObserver::GetInstance(); - TargetChooser * tc = game->getCurrentTargetChooser(); - int newState = game->getCurrentGamePhase(); + + TargetChooser * tc = observer->getCurrentTargetChooser(); + int newState = observer->getCurrentGamePhase(); currentState = newState; if (!tc) checked = 0; @@ -894,33 +887,33 @@ void ActionStack::Update(float dt) { int currentPlayerId = 0; int otherPlayerId = 1; - if (game->currentlyActing() != game->players[0]) + if (observer->currentlyActing() != observer->players[0]) { currentPlayerId = 1; otherPlayerId = 0; } if (interruptDecision[currentPlayerId] == NOT_DECIDED) { - askIfWishesToInterrupt = game->players[currentPlayerId]; - game->isInterrupting = game->players[currentPlayerId]; + askIfWishesToInterrupt = observer->players[currentPlayerId]; + observer->isInterrupting = observer->players[currentPlayerId]; modal = 1; } else if (interruptDecision[currentPlayerId] == INTERRUPT) { - game->isInterrupting = game->players[currentPlayerId]; + observer->isInterrupting = observer->players[currentPlayerId]; } else { if (interruptDecision[otherPlayerId] == NOT_DECIDED) { - askIfWishesToInterrupt = game->players[otherPlayerId]; - game->isInterrupting = game->players[otherPlayerId]; + askIfWishesToInterrupt = observer->players[otherPlayerId]; + observer->isInterrupting = observer->players[otherPlayerId]; modal = 1; } else if (interruptDecision[otherPlayerId] == INTERRUPT) { - game->isInterrupting = game->players[otherPlayerId]; + observer->isInterrupting = observer->players[otherPlayerId]; } else { @@ -962,18 +955,18 @@ void ActionStack::Update(float dt) void ActionStack::cancelInterruptOffer(int cancelMode) { - int playerId = (game->isInterrupting == game->players[1]) ? 1 : 0; + int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0; interruptDecision[playerId] = cancelMode; askIfWishesToInterrupt = NULL; - game->isInterrupting = NULL; + observer->isInterrupting = NULL; timer = -1; } void ActionStack::endOfInterruption() { - int playerId = (game->isInterrupting == game->players[1]) ? 1 : 0; + int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0; interruptDecision[playerId] = 0; - game->isInterrupting = NULL; + observer->isInterrupting = NULL; } bool ActionStack::CheckUserInput(JButton key) @@ -1000,7 +993,7 @@ bool ActionStack::CheckUserInput(JButton key) } return true; } - else if (game->isInterrupting) + else if (observer->isInterrupting) { if (JGE_BTN_SEC == key) { @@ -1045,7 +1038,7 @@ bool ActionStack::CheckUserInput(JButton key) { DebugTrace("ACTIONSTACK CLICKED mCurr = " << mCurr); - game->stackObjectClicked(((Interruptible *) mObjects[mCurr])); + observer->stackObjectClicked(((Interruptible *) mObjects[mCurr])); return true; } return true; //Steal the input to other layers if we're visible diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 3ca231f7a..5ba1d4e08 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -6,9 +6,9 @@ //Activated Abilities //Generic Activated Abilities -GenericActivatedAbility::GenericActivatedAbility(string newName, string castRestriction, int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, +GenericActivatedAbility::GenericActivatedAbility(GameObserver* observer, string newName, string castRestriction, int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, string limit,MTGAbility * sideEffects,string usesBeforeSideEffects, int restrictions, MTGGameZone * dest) : - ActivatedAbility(_id, card, _cost, restrictions,limit,sideEffects,usesBeforeSideEffects,castRestriction), NestedAbility(a), activeZone(dest),newName(newName),castRestriction(castRestriction) + ActivatedAbility(observer, _id, card, _cost, restrictions,limit,sideEffects,usesBeforeSideEffects,castRestriction), NestedAbility(a), activeZone(dest),newName(newName),castRestriction(castRestriction) { counters = 0; target = ability->target; @@ -74,9 +74,9 @@ GenericActivatedAbility::~GenericActivatedAbility() } //AA Alter Poison -AAAlterPoison::AAAlterPoison(int _id, MTGCardInstance * _source, Targetable * _target, int poison, ManaCost * _cost, +AAAlterPoison::AAAlterPoison(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, int poison, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, _source, _target, _cost, who), poison(poison) + ActivatedAbilityTP(observer, _id, _source, _target, _cost, who), poison(poison) { } @@ -105,9 +105,9 @@ AAAlterPoison::~AAAlterPoison() } //Damage Prevent -AADamagePrevent::AADamagePrevent(int _id, MTGCardInstance * _source, Targetable * _target, int preventing, ManaCost * _cost, +AADamagePrevent::AADamagePrevent(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, int preventing, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, _source, _target, _cost, who), preventing(preventing) + ActivatedAbilityTP(observer, _id, _source, _target, _cost, who), preventing(preventing) { aType = MTGAbility::STANDARD_PREVENT; } @@ -137,9 +137,9 @@ AADamagePrevent::~AADamagePrevent() } //AADamager -AADamager::AADamager(int _id, MTGCardInstance * _source, Targetable * _target, string d, ManaCost * _cost, +AADamager::AADamager(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, string d, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, _source, _target, _cost, who), d(d) + ActivatedAbilityTP(observer, _id, _source, _target, _cost, who), d(d) { aType = MTGAbility::DAMAGER; } @@ -175,8 +175,8 @@ AADamager * AADamager::clone() const //AADepleter -AADepleter::AADepleter(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, who),nbcardsStr(nbcardsStr) +AADepleter::AADepleter(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost, int who) : + ActivatedAbilityTP(observer, _id, card, _target, _cost, who),nbcardsStr(nbcardsStr) { } @@ -208,8 +208,8 @@ AADepleter * AADepleter::clone() const } //AACopier -AACopier::AACopier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost) : - ActivatedAbility(_id, _source, _cost, 0) +AACopier::AACopier(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost) : + ActivatedAbility(observer, _id, _source, _cost, 0) { target = _target; } @@ -236,8 +236,8 @@ AACopier * AACopier::clone() const } //phaser -AAPhaseOut::AAPhaseOut(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost) : - ActivatedAbility(_id, _source, _cost, 0) +AAPhaseOut::AAPhaseOut(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost) : + ActivatedAbility(observer, _id, _source, _cost, 0) { target = _target; } @@ -269,9 +269,9 @@ AAPhaseOut * AAPhaseOut::clone() const } //Counters -AACounter::AACounter(int id, MTGCardInstance * source, MTGCardInstance * target,string counterstring, const char * _name, int power, int toughness, +AACounter::AACounter(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target,string counterstring, const char * _name, int power, int toughness, int nb,int maxNb, ManaCost * cost) : - ActivatedAbility(id, source, cost, 0),counterstring(counterstring), nb(nb),maxNb(maxNb), power(power), toughness(toughness), name(_name) + ActivatedAbility(observer, id, source, cost, 0),counterstring(counterstring), nb(nb),maxNb(maxNb), power(power), toughness(toughness), name(_name) { this->target = target; if (name.find("Level") != string::npos || name.find("level") != string::npos) @@ -287,7 +287,7 @@ AACounter::AACounter(int id, MTGCardInstance * source, MTGCardInstance * target, if (target) { MTGCardInstance * _target = (MTGCardInstance *) target; - AbilityFactory af; + AbilityFactory af(game); if(counterstring.size()) { Counter * checkcounter = af.parseCounter(counterstring, source, NULL); @@ -368,8 +368,8 @@ AACounter * AACounter::clone() const } //shield a card from a certain type of counter. -ACounterShroud::ACounterShroud(int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter) : -MTGAbility(id, source),counter(counter),re(NULL) +ACounterShroud::ACounterShroud(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter) : +MTGAbility(observer, id, source),counter(counter),re(NULL) { } @@ -406,8 +406,8 @@ ACounterShroud::~ACounterShroud() } //shield a card from a certain type of counter. -ACounterTracker::ACounterTracker(int id, MTGCardInstance * source, MTGCardInstance * target, string scounter) : -MTGAbility(id, source, target),scounter(scounter) +ACounterTracker::ACounterTracker(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, string scounter) : +MTGAbility(observer, id, source, target),scounter(scounter) { removed = 0; } @@ -415,7 +415,7 @@ MTGAbility(id, source, target),scounter(scounter) int ACounterTracker::addToGame() { MTGCardInstance * _target = (MTGCardInstance*)target; - AbilityFactory af; + AbilityFactory af(game); Counter * counter = af.parseCounter(scounter, _target, NULL); //(Spell*)source); if (!counter) { @@ -441,7 +441,7 @@ int ACounterTracker::addToGame() int ACounterTracker::destroy() { MTGCardInstance * _target = (MTGCardInstance*)target; - AbilityFactory af; + AbilityFactory af(game); Counter * counter = af.parseCounter(scounter, _target, NULL); //(Spell*)source); if (!counter) { @@ -463,7 +463,7 @@ int ACounterTracker::destroy() int ACounterTracker::testDestroy() { - if(this->source->isInPlay()) + if(this->source->isInPlay(game)) return 0; return 1; } @@ -479,9 +479,9 @@ ACounterTracker::~ACounterTracker() } //removeall counters of a certain type or all. -AARemoveAllCounter::AARemoveAllCounter(int id, MTGCardInstance * source, MTGCardInstance * target, const char * _name, int power, int toughness, +AARemoveAllCounter::AARemoveAllCounter(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, const char * _name, int power, int toughness, int nb,bool all, ManaCost * cost) : - ActivatedAbility(id, source, cost, 0), nb(nb), power(power), toughness(toughness), name(_name),all(all) + ActivatedAbility(observer, id, source, cost, 0), nb(nb), power(power), toughness(toughness), name(_name),all(all) { this->target = target; menu = ""; @@ -556,8 +556,8 @@ AARemoveAllCounter * AARemoveAllCounter::clone() const } //proliferate a target -AAProliferate::AAProliferate(int id, MTGCardInstance * source, Targetable * target,ManaCost * cost) : -ActivatedAbility(id, source, cost, 0) +AAProliferate::AAProliferate(GameObserver* observer, int id, MTGCardInstance * source, Targetable * target,ManaCost * cost) : +ActivatedAbility(observer, id, source, cost, 0) { } @@ -569,7 +569,7 @@ int AAProliferate::resolve() vectorpcounters; if(target->typeAsTarget() == TARGET_PLAYER && ((Player*)target)->poisonCount && target != source->controller()) { - MTGAbility * a = NEW AAAlterPoison(game->mLayers->actionLayer()->getMaxId(), source, target, 1, NULL); + MTGAbility * a = NEW AAAlterPoison(game, game->mLayers->actionLayer()->getMaxId(), source, target, 1, NULL); a->oneShot = true; pcounters.push_back(a); } @@ -579,14 +579,14 @@ int AAProliferate::resolve() for(size_t i = 0; i < counters->counters.size(); ++i) { Counter * counter = counters->counters[i]; - MTGAbility * a = NEW AACounter(game->mLayers->actionLayer()->getMaxId(), source, (MTGCardInstance*)target,"", counter->name.c_str(), counter->power, counter->toughness, 1,0); + MTGAbility * a = NEW AACounter(game, game->mLayers->actionLayer()->getMaxId(), source, (MTGCardInstance*)target,"", counter->name.c_str(), counter->power, counter->toughness, 1,0); a->oneShot = true; pcounters.push_back(a); } } if(pcounters.size()) { - MTGAbility * a = NEW MenuAbility(this->GetId(), target, source,false,pcounters); + MTGAbility * a = NEW MenuAbility(game, this->GetId(), target, source,false,pcounters); a->resolve(); } return 1; @@ -610,8 +610,8 @@ AAProliferate::~AAProliferate() // //Reset Damage on creatures - AAResetDamage::AAResetDamage(int id, MTGCardInstance * source, MTGCardInstance * _target, ManaCost * cost): - ActivatedAbility(id, source, cost, 0) + AAResetDamage::AAResetDamage(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * _target, ManaCost * cost): + ActivatedAbility(observer, id, source, cost, 0) { this->target = _target; } @@ -634,8 +634,8 @@ AAResetDamage * AAResetDamage::clone() const // Fizzler -AAFizzler::AAFizzler(int _id, MTGCardInstance * card, Spell * _target, ManaCost * _cost) : -ActivatedAbility(_id, card, _cost, 0) +AAFizzler::AAFizzler(GameObserver* observer, int _id, MTGCardInstance * card, Spell * _target, ManaCost * _cost) : +ActivatedAbility(observer, _id, card, _cost, 0) { aType = MTGAbility::STANDARD_FIZZLER; target = _target; @@ -675,8 +675,8 @@ AAFizzler* AAFizzler::clone() const // BanishCard implementations // Bury -AABuryCard::AABuryCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - ActivatedAbility(_id, _source) +AABuryCard::AABuryCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + ActivatedAbility(observer, _id, _source) { target = _target; } @@ -703,8 +703,8 @@ AABuryCard * AABuryCard::clone() const // Destroy -AADestroyCard::AADestroyCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - ActivatedAbility(_id, _source) +AADestroyCard::AADestroyCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + ActivatedAbility(observer, _id, _source) { target = _target; } @@ -730,8 +730,8 @@ AADestroyCard * AADestroyCard::clone() const } // Sacrifice -AASacrificeCard::AASacrificeCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - ActivatedAbility(_id, _source) +AASacrificeCard::AASacrificeCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + ActivatedAbility(observer, _id, _source) { target = _target; } @@ -743,7 +743,6 @@ int AASacrificeCard::resolve() { Player * p = _target->controller(); WEvent * e = NEW WEventCardSacrifice(_target); - GameObserver * game = GameObserver::GetInstance(); game->receiveEvent(e); p->game->putInGraveyard(_target); return 1; @@ -763,8 +762,8 @@ AASacrificeCard * AASacrificeCard::clone() const // Discard -AADiscardCard::AADiscardCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target) : - ActivatedAbility(_id, _source) +AADiscardCard::AADiscardCard(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : + ActivatedAbility(observer, _id, _source) { target = _target; } @@ -776,7 +775,6 @@ int AADiscardCard::resolve() { Player * p = _target->controller(); WEvent * e = NEW WEventCardDiscard(_target); - GameObserver * game = GameObserver::GetInstance(); game->receiveEvent(e); p->game->putInGraveyard(_target); return 1; @@ -794,9 +792,9 @@ AADiscardCard * AADiscardCard::clone() const return NEW AADiscardCard(*this); } -AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, string nbcardsStr, +AADrawer::AADrawer(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, string nbcardsStr, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, who), nbcardsStr(nbcardsStr) + ActivatedAbilityTP(observer, _id, card, _target, _cost, who), nbcardsStr(nbcardsStr) { aType = MTGAbility::STANDARD_DRAW; } @@ -810,12 +808,11 @@ AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCo WParsedInt numCards(nbcardsStr, NULL, source); game->mLayers->stackLayer()->addDraw(player, numCards.getValue()); game->mLayers->stackLayer()->resolve(); - GameObserver *g = GameObserver::GetInstance(); - for(int i = numCards.getValue(); i > 0;i--) - { - WEvent * e = NEW WEventcardDraw(player, 1); - g->receiveEvent(e); - } + for(int i = numCards.getValue(); i > 0;i--) + { + WEvent * e = NEW WEventcardDraw(player, 1); + game->receiveEvent(e); + } } return 1; } @@ -837,8 +834,8 @@ AADrawer * AADrawer::clone() const } // AAFrozen: Prevent a card from untapping during next untap phase -AAFrozen::AAFrozen(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : -ActivatedAbility(id, card, _cost, 0) +AAFrozen::AAFrozen(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : +ActivatedAbility(observer, id, card, _cost, 0) { target = _target; } @@ -866,8 +863,8 @@ AAFrozen * AAFrozen::clone() const } // chose a new target for an aura or enchantment and equip it note: VERY basic right now. -AANewTarget::AANewTarget(int id, MTGCardInstance * card, MTGCardInstance * _target,bool retarget, ManaCost * _cost) : -ActivatedAbility(id, card, _cost, 0),retarget(retarget) +AANewTarget::AANewTarget(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target,bool retarget, ManaCost * _cost) : +ActivatedAbility(observer, id, card, _cost, 0),retarget(retarget) { target = _target; } @@ -889,7 +886,7 @@ int AANewTarget::resolve() _target = _target->next; MTGCardInstance * refreshed = source->controller()->game->putInZone(_target,_target->currentZone,source->controller()->game->battlefield); - Spell * reUp = NEW Spell(refreshed); + Spell * reUp = NEW Spell(game, refreshed); if(reUp->source->hasSubtype(Subtypes::TYPE_AURA)) { reUp->source->target = source; @@ -898,10 +895,9 @@ int AANewTarget::resolve() if(_target->hasSubtype(Subtypes::TYPE_EQUIPMENT)) { reUp->resolve(); - GameObserver * g = GameObserver::GetInstance(); - for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) + for (size_t i = 1; i < game->mLayers->actionLayer()->mObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); + MTGAbility * a = ((MTGAbility *) game->mLayers->actionLayer()->mObjects[i]); AEquip * eq = dynamic_cast (a); if (eq && eq->source == reUp->source) { @@ -933,8 +929,8 @@ AANewTarget * AANewTarget::clone() const return a; } // morph a card -AAMorph::AAMorph(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : -ActivatedAbility(id, card, _cost, restrictions) +AAMorph::AAMorph(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : +ActivatedAbility(observer, id, card, _cost, restrictions) { target = _target; } @@ -950,7 +946,7 @@ int AAMorph::resolve() while (_target->next) _target = _target->next; - AbilityFactory af; + AbilityFactory af(game); _target->morphed = false; _target->isMorphed = false; _target->turningOver = true; @@ -962,8 +958,7 @@ int AAMorph::resolve() if( a && dynamic_cast (a)) { a->removeFromGame(); - GameObserver * g = GameObserver::GetInstance(); - g->removeObserver(a); + game->removeObserver(a); } if (a) { @@ -991,8 +986,7 @@ int AAMorph::testDestroy() { if(_target->turningOver && !_target->isMorphed && !_target->morphed) { - GameObserver * g = GameObserver::GetInstance(); - g->removeObserver(this); + game->removeObserver(this); return 1; } } @@ -1011,8 +1005,8 @@ AAMorph * AAMorph::clone() const return a; } // AADYNAMIC: dynamic ability builder -AADynamic::AADynamic(int id, MTGCardInstance * card, Damageable * _target,int type,int effect,int who,int amountsource,MTGAbility * storedAbility, ManaCost * _cost) : -ActivatedAbility(id, card, _cost, 0),type(type),effect(effect),who(who),amountsource(amountsource),storedAbility(storedAbility) +AADynamic::AADynamic(GameObserver* observer, int id, MTGCardInstance * card, Damageable * _target,int type,int effect,int who,int amountsource,MTGAbility * storedAbility, ManaCost * _cost) : +ActivatedAbility(observer, id, card, _cost, 0),type(type),effect(effect),who(who),amountsource(amountsource),storedAbility(storedAbility) { target = _target; sourceamount = 0; @@ -1233,15 +1227,15 @@ int AADynamic::resolve() activateStored(); if(tosrc == false) { - PTInstant * a = NEW PTInstant(this->GetId(), source, (MTGCardInstance*)_target,NEW WParsedPT(sourceamount,0)); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source,(MTGCardInstance*)_target, a); + PTInstant * a = NEW PTInstant(game, this->GetId(), source, (MTGCardInstance*)_target,NEW WParsedPT(sourceamount,0)); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source,(MTGCardInstance*)_target, a); wrapper->addToGame(); return 1; } else { - PTInstant * a = NEW PTInstant(this->GetId(), source, OriginalSrc,NEW WParsedPT(sourceamount,0)); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source,OriginalSrc, a); + PTInstant * a = NEW PTInstant(game, this->GetId(), source, OriginalSrc,NEW WParsedPT(sourceamount,0)); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source,OriginalSrc, a); wrapper->addToGame(); return 1; } @@ -1253,15 +1247,15 @@ int AADynamic::resolve() activateStored(); if(tosrc == false) { - PTInstant * a = NEW PTInstant(this->GetId(), source, (MTGCardInstance*)_target,NEW WParsedPT(0,sourceamount)); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source,(MTGCardInstance*)_target, a); + PTInstant * a = NEW PTInstant(game, this->GetId(), source, (MTGCardInstance*)_target,NEW WParsedPT(0,sourceamount)); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source,(MTGCardInstance*)_target, a); wrapper->addToGame(); return 1; } else { - PTInstant * a = NEW PTInstant(this->GetId(), source, OriginalSrc,NEW WParsedPT(0,sourceamount)); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source,OriginalSrc, a); + PTInstant * a = NEW PTInstant(game, this->GetId(), source, OriginalSrc,NEW WParsedPT(0,sourceamount)); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source,OriginalSrc, a); wrapper->addToGame(); return 1; } @@ -1273,15 +1267,15 @@ int AADynamic::resolve() activateStored(); if(tosrc == false) { - PTInstant * a = NEW PTInstant(this->GetId(), source, (MTGCardInstance*)_target,NEW WParsedPT(sourceamount,sourceamount)); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source,(MTGCardInstance*)_target, a); + PTInstant * a = NEW PTInstant(game, this->GetId(), source, (MTGCardInstance*)_target,NEW WParsedPT(sourceamount,sourceamount)); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source,(MTGCardInstance*)_target, a); wrapper->addToGame(); return 1; } else { - PTInstant * a = NEW PTInstant(this->GetId(), source, OriginalSrc,NEW WParsedPT(sourceamount,sourceamount)); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source,OriginalSrc, a); + PTInstant * a = NEW PTInstant(game, this->GetId(), source, OriginalSrc,NEW WParsedPT(sourceamount,sourceamount)); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source,OriginalSrc, a); wrapper->addToGame(); return 1; } @@ -1427,8 +1421,8 @@ AADynamic::~AADynamic() } //AALifer -AALifer::AALifer(int _id, MTGCardInstance * card, Targetable * _target, string life_s, ManaCost * _cost, int who) : -ActivatedAbilityTP(_id, card, _target, _cost, who),life_s(life_s) +AALifer::AALifer(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, string life_s, ManaCost * _cost, int who) : +ActivatedAbilityTP(observer, _id, card, _target, _cost, who),life_s(life_s) { aType = MTGAbility::LIFER; } @@ -1470,9 +1464,9 @@ AALifer * AALifer::clone() const //players max hand size -AASetHand::AASetHand(int _id, MTGCardInstance * _source, Targetable * _target, int hand, ManaCost * _cost, +AASetHand::AASetHand(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, int hand, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, _source, _target, _cost, who), hand(hand) + ActivatedAbilityTP(observer, _id, _source, _target, _cost, who), hand(hand) { } @@ -1500,9 +1494,9 @@ AASetHand * AASetHand::clone() const } //Lifeset -AALifeSet::AALifeSet(int _id, MTGCardInstance * _source, Targetable * _target, WParsedInt * life, ManaCost * _cost, +AALifeSet::AALifeSet(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable * _target, WParsedInt * life, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, _source, _target, _cost, who), life(life) + ActivatedAbilityTP(observer, _id, _source, _target, _cost, who), life(life) { } @@ -1539,9 +1533,9 @@ AALifeSet::~AALifeSet() //AACloner //cloning...this makes a token thats a copy of the target. -AACloner::AACloner(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost, int who, +AACloner::AACloner(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost, int who, string abilitiesStringList) : - ActivatedAbility(_id, _source, _cost, 0), who(who) + ActivatedAbility(observer, _id, _source, _cost, 0), who(who) { aType = MTGAbility::CLONING; target = _target; @@ -1567,7 +1561,7 @@ int AACloner::resolve() MTGCardInstance * myClone = NEW MTGCardInstance(clone, targetPlayer->game); targetPlayer->game->temp->addCard(myClone); - Spell * spell = NEW Spell(myClone); + Spell * spell = NEW Spell(game, myClone); spell->resolve(); spell->source->isToken = 1; spell->source->fresh = 1; @@ -1614,8 +1608,8 @@ AACloner::~AACloner() } // Cast/Play Restriction modifier -ACastRestriction::ACastRestriction(int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who) : - AbilityTP(_id, card, _target, who), restrictionsScope(_restrictionsScope), value(_value), modifyExisting(_modifyExisting),zoneId(_zoneId) +ACastRestriction::ACastRestriction(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who) : + AbilityTP(observer, _id, card, _target, who), restrictionsScope(_restrictionsScope), value(_value), modifyExisting(_modifyExisting),zoneId(_zoneId) { existingRestriction = NULL; targetPlayer = NULL; @@ -1688,16 +1682,16 @@ ACastRestriction::~ACastRestriction() } -AInstantCastRestrictionUEOT::AInstantCastRestrictionUEOT(int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who) : - InstantAbilityTP(_id, card, _target, who) +AInstantCastRestrictionUEOT::AInstantCastRestrictionUEOT(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, TargetChooser * _restrictionsScope, WParsedInt * _value, bool _modifyExisting, int _zoneId, int who) : + InstantAbilityTP(observer, _id, card, _target, who) { - ability = NEW ACastRestriction(_id, card, _target, _restrictionsScope, _value, _modifyExisting, _zoneId, who); + ability = NEW ACastRestriction(observer, _id, card, _target, _restrictionsScope, _value, _modifyExisting, _zoneId, who); } int AInstantCastRestrictionUEOT::resolve() { ACastRestriction * a = ability->clone(); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), a); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source, (Damageable *) (this->target), a); wrapper->addToGame(); return 1; } @@ -1720,8 +1714,8 @@ AInstantCastRestrictionUEOT::~AInstantCastRestrictionUEOT() //AAMover -AAMover::AAMover(int _id, MTGCardInstance * _source, MTGCardInstance * _target, string dest, ManaCost * _cost) : - ActivatedAbility(_id, _source, _cost, 0), destination(dest) +AAMover::AAMover(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, string dest, ManaCost * _cost) : + ActivatedAbility(observer, _id, _source, _cost, 0), destination(dest) { if (_target) target = _target; @@ -1731,7 +1725,7 @@ AAMover::AAMover(int _id, MTGCardInstance * _source, MTGCardInstance * _target, MTGGameZone * AAMover::destinationZone(Targetable * target) { MTGCardInstance * _target = (MTGCardInstance *) target; - return MTGGameZone::stringToZone(destination, source, _target); + return MTGGameZone::stringToZone(game, destination, source, _target); } int AAMover::resolve() @@ -1742,18 +1736,17 @@ int AAMover::resolve() Player* p = _target->controller(); if (p) { - GameObserver * g = GameObserver::GetInstance(); MTGGameZone * fromZone = _target->getCurrentZone(); MTGGameZone * destZone = destinationZone(target); //inplay is a special zone ! for (int i = 0; i < 2; i++) { - if (destZone == g->players[i]->game->inPlay && fromZone != g->players[i]->game->inPlay && fromZone - != g->players[i]->opponent()->game->inPlay) + if (destZone == game->players[i]->game->inPlay && fromZone != game->players[i]->game->inPlay && fromZone + != game->players[i]->opponent()->game->inPlay) { - MTGCardInstance * copy = g->players[i]->game->putInZone(_target, fromZone, g->players[i]->game->temp); - Spell * spell = NEW Spell(copy); + MTGCardInstance * copy = game->players[i]->game->putInZone(_target, fromZone, game->players[i]->game->temp); + Spell * spell = NEW Spell(game, copy); spell->resolve(); if(andAbility) { @@ -1801,57 +1794,56 @@ const char * AAMover::getMenuText() const char * AAMover::getMenuText(TargetChooser * tc) { - GameObserver * g = GameObserver::GetInstance(); MTGGameZone * dest = destinationZone(); for (int i = 0; i < 2; i++) { // Move card to hand - if (dest == g->players[i]->game->hand) + if (dest == game->players[i]->game->hand) { - if (tc->targetsZone(g->players[i]->game->inPlay)) + if (tc->targetsZone(game->players[i]->game->inPlay)) return "Bounce"; - if (tc->targetsZone(g->players[i]->game->graveyard)) + if (tc->targetsZone(game->players[i]->game->graveyard)) return "Reclaim"; - if (tc->targetsZone(g->opponent()->game->hand)) + if (tc->targetsZone(game->opponent()->game->hand)) return "Steal"; } // Move card to graveyard - else if (dest == g->players[i]->game->graveyard) + else if (dest == game->players[i]->game->graveyard) { - if (tc->targetsZone(g->players[i]->game->inPlay)) + if (tc->targetsZone(game->players[i]->game->inPlay)) return "Sacrifice"; - if (tc->targetsZone(g->players[i]->game->hand)) + if (tc->targetsZone(game->players[i]->game->hand)) return "Discard"; - if (tc->targetsZone(g->opponent()->game->hand)) + if (tc->targetsZone(game->opponent()->game->hand)) return "Opponent Discards"; } // move card to library - else if (dest == g->players[i]->game->library) + else if (dest == game->players[i]->game->library) { - if (tc->targetsZone(g->players[i]->game->graveyard)) + if (tc->targetsZone(game->players[i]->game->graveyard)) return "Recycle"; return "Put in Library"; } // move card to battlefield - else if (dest == g->players[i]->game->battlefield) + else if (dest == game->players[i]->game->battlefield) { - if (tc->targetsZone(g->players[i]->game->graveyard)) + if (tc->targetsZone(game->players[i]->game->graveyard)) return "Reanimate"; return "Put in Play"; } // move card into exile - else if (dest == g->players[i]->game->exile) + else if (dest == game->players[i]->game->exile) { return "Exile"; } // move card from Library - else if (tc->targetsZone(g->players[i]->game->library)) + else if (tc->targetsZone(game->players[i]->game->library)) { return "Fetch"; } @@ -1874,9 +1866,9 @@ SAFE_DELETE(andAbility); } //Random Discard -AARandomDiscarder::AARandomDiscarder(int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost, +AARandomDiscarder::AARandomDiscarder(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, who), nbcardsStr(nbcardsStr) + ActivatedAbilityTP(observer, _id, card, _target, _cost, who), nbcardsStr(nbcardsStr) { } @@ -1907,8 +1899,8 @@ AARandomDiscarder * AARandomDiscarder::clone() const } // Shuffle -AAShuffle::AAShuffle(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, who) +AAShuffle::AAShuffle(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, int who) : + ActivatedAbilityTP(observer, _id, card, _target, _cost, who) { } @@ -1934,8 +1926,8 @@ AAShuffle * AAShuffle::clone() const } // Remove Mana From ManaPool -AARemoveMana::AARemoveMana(int _id, MTGCardInstance * card, Targetable * _target, string manaDesc, int who) : - ActivatedAbilityTP(_id, card, _target, NULL, who) +AARemoveMana::AARemoveMana(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, string manaDesc, int who) : + ActivatedAbilityTP(observer, _id, card, _target, NULL, who) { if (!manaDesc.size()) { @@ -1999,8 +1991,8 @@ AARemoveMana::~AARemoveMana() } //Tapper -AATapper::AATapper(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : - ActivatedAbility(id, card, _cost, 0) +AATapper::AATapper(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : + ActivatedAbility(observer, id, card, _cost, 0) { target = _target; aType = MTGAbility::TAPPER; @@ -2029,8 +2021,8 @@ AATapper * AATapper::clone() const } //AA Untapper -AAUntapper::AAUntapper(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : - ActivatedAbility(id, card, _cost, 0) +AAUntapper::AAUntapper(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : + ActivatedAbility(observer, id, card, _cost, 0) { target = _target; aType = MTGAbility::UNTAPPER; @@ -2058,8 +2050,8 @@ AAUntapper * AAUntapper::clone() const return NEW AAUntapper(*this); } -AAWhatsMax::AAWhatsMax(int id, MTGCardInstance * card, MTGCardInstance * source, ManaCost * _cost, int value) : - ActivatedAbility(id, card, _cost, 0), value(value) +AAWhatsMax::AAWhatsMax(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * source, ManaCost * _cost, int value) : + ActivatedAbility(observer, id, card, _cost, 0), value(value) { } @@ -2080,8 +2072,8 @@ AAWhatsMax * AAWhatsMax::clone() const } // Win Game -AAWinGame::AAWinGame(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, int who) : - ActivatedAbilityTP(_id, card, _target, _cost, who) +AAWinGame::AAWinGame(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, int who) : + ActivatedAbilityTP(observer, _id, card, _target, _cost, who) { } @@ -2143,15 +2135,15 @@ AAWinGame * AAWinGame::clone() const //IfThenEffect -IfThenAbility::IfThenAbility(int _id, MTGAbility * delayedAbility, MTGCardInstance * _source, Targetable * _target, int type,string Cond) : -MTGAbility(_id, _source,_target),delayedAbility(delayedAbility), type(type),Cond(Cond) +IfThenAbility::IfThenAbility(GameObserver* observer, int _id, MTGAbility * delayedAbility, MTGCardInstance * _source, Targetable * _target, int type,string Cond) : +MTGAbility(observer, _id, _source,_target),delayedAbility(delayedAbility), type(type),Cond(Cond) { } int IfThenAbility::resolve() { MTGCardInstance * card = (MTGCardInstance*)source; - AbilityFactory af; + AbilityFactory af(game); Targetable* aTarget = (Targetable*)target; int checkCond = af.parseCastRestrictions(card,card->controller(),Cond); if(Cond.find("cantargetcard(") != string::npos) @@ -2160,7 +2152,7 @@ int IfThenAbility::resolve() vectorsplitTarget = parseBetween(Cond, "card(", ")"); if (splitTarget.size()) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(game); condTc = tcf.createTargetChooser(splitTarget[1], source); condTc->targetter = NULL; if(source->target) @@ -2207,8 +2199,8 @@ IfThenAbility::~IfThenAbility() // //May Abilities -MayAbility::MayAbility(int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must) : - MTGAbility(_id, _source), NestedAbility(_ability), must(must) +MayAbility::MayAbility(GameObserver* observer, int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must) : + MTGAbility(observer, _id, _source), NestedAbility(_ability), must(must) { triggered = 0; mClone = NULL; @@ -2216,9 +2208,8 @@ MayAbility::MayAbility(int _id, MTGAbility * _ability, MTGCardInstance * _source void MayAbility::Update(float dt) { - GameObserver * gameObs = GameObserver::GetInstance(); MTGAbility::Update(dt); - if (!triggered && !gameObs->getCurrentTargetChooser()) + if (!triggered && !game->getCurrentTargetChooser()) { triggered = 1; if (TargetAbility * ta = dynamic_cast(ability)) @@ -2281,8 +2272,8 @@ MayAbility::~MayAbility() //Menu building ability Abilities //this will eventaully handle choosen discards/sacrifices. -MenuAbility::MenuAbility(int _id, Targetable * mtarget, MTGCardInstance * _source, bool must,vectorabilities,Player * who) : -MayAbility(_id,NULL,_source,must), must(must),abilities(abilities),who(who) +MenuAbility::MenuAbility(GameObserver* observer, int _id, Targetable * mtarget, MTGCardInstance * _source, bool must,vectorabilities,Player * who) : +MayAbility(observer, _id,NULL,_source,must), must(must),abilities(abilities),who(who) { triggered = 0; mClone = NULL; @@ -2404,8 +2395,8 @@ MenuAbility::~MenuAbility() } /// //MultiAbility : triggers several actions for a cost -MultiAbility::MultiAbility(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost) : - ActivatedAbility(_id, card, _cost, 0) +MultiAbility::MultiAbility(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost) : + ActivatedAbility(observer, _id, card, _cost, 0) { if (_target) target = _target; @@ -2495,9 +2486,9 @@ MultiAbility::~MultiAbility() } //Generic Target Ability -GenericTargetAbility::GenericTargetAbility(string newName, string castRestriction,int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, +GenericTargetAbility::GenericTargetAbility(GameObserver* observer, string newName, string castRestriction,int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, ManaCost * _cost, string limit,MTGAbility * sideEffects,string usesBeforeSideEffects, int restrictions, MTGGameZone * dest) : - TargetAbility(_id, _source, _tc, _cost, restrictions,castRestriction), limit(limit), activeZone(dest),newName(newName),castRestriction(castRestriction) + TargetAbility(observer, _id, _source, _tc, _cost, restrictions,castRestriction), limit(limit), activeZone(dest),newName(newName),castRestriction(castRestriction) { ability = a; MTGAbility * core = AbilityFactory::getCoreAbility(a); @@ -2574,8 +2565,8 @@ GenericTargetAbility::~GenericTargetAbility() } //Alter Cost -AAlterCost::AAlterCost(int id, MTGCardInstance * source, MTGCardInstance * target, int amount, int type) : -MTGAbility(id, source, target), amount(amount), type(type) +AAlterCost::AAlterCost(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, int amount, int type) : +MTGAbility(observer, id, source, target), amount(amount), type(type) { manaReducer = source; } @@ -2615,7 +2606,7 @@ int AAlterCost::addToGame() int AAlterCost::testDestroy() { MTGCardInstance * _target = (MTGCardInstance *)target; - if(!this->manaReducer->isInPlay()) + if(!this->manaReducer->isInPlay(game)) { if (amount > 0) { @@ -2691,8 +2682,8 @@ AAlterCost::~AAlterCost() } // ATransformer -ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector newAbilitiesList,bool newAbilityFound,bool aForever) : - MTGAbility(id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound),aForever(aForever) +ATransformer::ATransformer(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector newAbilitiesList,bool newAbilityFound,bool aForever) : + MTGAbility(observer, id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound),aForever(aForever) { PopulateAbilityIndexVector(abilities, sabilities); @@ -2814,7 +2805,7 @@ int ATransformer::addToGame() { for (unsigned int k = 0 ; k < newAbilitiesList.size();k++) { - AbilityFactory af; + AbilityFactory af(game); MTGAbility * aNew = af.parseMagicLine(newAbilitiesList[k], 0, NULL, _target); if(!aNew) continue; @@ -2992,17 +2983,17 @@ ATransformer::~ATransformer() } //ATransformerInstant -ATransformerInstant::ATransformerInstant(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vectornewAbilitiesList,bool newAbilityFound,bool aForever) : - InstantAbility(id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound),aForever(aForever) +ATransformerInstant::ATransformerInstant(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vectornewAbilitiesList,bool newAbilityFound,bool aForever) : + InstantAbility(observer, id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound),aForever(aForever) { - ability = NEW ATransformer(id, source, target, types, abilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound,aForever); + ability = NEW ATransformer(game, id, source, target, types, abilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound,aForever); aType = MTGAbility::STANDARD_BECOMES; } int ATransformerInstant::resolve() { ATransformer * a = ability->clone(); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), a); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source, (Damageable *) (this->target), a); wrapper->addToGame(); return 1; } @@ -3023,17 +3014,17 @@ ATransformerInstant::~ATransformerInstant() SAFE_DELETE(ability); } //P/t ueot -PTInstant::PTInstant(int id, MTGCardInstance * source, MTGCardInstance * target, WParsedPT * wppt,string s,bool nonstatic) : -InstantAbility(id, source, target), wppt(wppt),s(s),nonstatic(nonstatic) +PTInstant::PTInstant(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target, WParsedPT * wppt,string s,bool nonstatic) : +InstantAbility(observer, id, source, target), wppt(wppt),s(s),nonstatic(nonstatic) { - ability = NEW APowerToughnessModifier(id, source, target, wppt,s,nonstatic); + ability = NEW APowerToughnessModifier(game, id, source, target, wppt,s,nonstatic); aType = MTGAbility::STANDARD_PUMP; } int PTInstant::resolve() { APowerToughnessModifier * a = ability->clone(); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), a); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source, (Damageable *) (this->target), a); wrapper->addToGame(); return 1; } @@ -3055,16 +3046,16 @@ PTInstant::~PTInstant() } // ASwapPTUEOT -ASwapPTUEOT::ASwapPTUEOT(int id, MTGCardInstance * source, MTGCardInstance * target) : - InstantAbility(id, source, target) +ASwapPTUEOT::ASwapPTUEOT(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * target) : + InstantAbility(observer, id, source, target) { - ability = NEW ASwapPT(id, source, target); + ability = NEW ASwapPT(observer, id, source, target); } int ASwapPTUEOT::resolve() { ASwapPT * a = ability->clone(); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), a); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source, (Damageable *) (this->target), a); wrapper->addToGame(); return 1; } @@ -3088,8 +3079,8 @@ ASwapPTUEOT::~ASwapPTUEOT() //ALoseAbilities -ALoseAbilities::ALoseAbilities(int id, MTGCardInstance * source, MTGCardInstance * _target) : - MTGAbility(id, source) +ALoseAbilities::ALoseAbilities(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * _target) : + MTGAbility(observer, id, source) { target = _target; } @@ -3192,8 +3183,8 @@ ALoseAbilities * ALoseAbilities::clone() const } //ALoseSubtypes -ALoseSubtypes::ALoseSubtypes(int id, MTGCardInstance * source, MTGCardInstance * _target, int parentType) : - MTGAbility(id, source), parentType(parentType) +ALoseSubtypes::ALoseSubtypes(GameObserver* observer, int id, MTGCardInstance * source, MTGCardInstance * _target, int parentType) : + MTGAbility(observer, id, source), parentType(parentType) { target = _target; } @@ -3235,8 +3226,8 @@ ALoseSubtypes * ALoseSubtypes::clone() const } //APreventDamageTypes -APreventDamageTypes::APreventDamageTypes(int id, MTGCardInstance * source, string to, string from, int type) : - MTGAbility(id, source), to(to), from(from), type(type) +APreventDamageTypes::APreventDamageTypes(GameObserver* observer, int id, MTGCardInstance * source, string to, string from, int type) : + MTGAbility(observer, id, source), to(to), from(from), type(type) { re = NULL; } @@ -3248,7 +3239,7 @@ int APreventDamageTypes::addToGame() DebugTrace("FATAL:re shouldn't be already set in APreventDamageTypes\n"); return 0; } - TargetChooserFactory tcf; + TargetChooserFactory tcf(game); TargetChooser *toTc = tcf.createTargetChooser(to, source, this); if (toTc) toTc->targetter = NULL; @@ -3291,16 +3282,16 @@ APreventDamageTypes::~APreventDamageTypes() } //APreventDamageTypesUEOT -APreventDamageTypesUEOT::APreventDamageTypesUEOT(int id, MTGCardInstance * source, string to, string from, int type) : - InstantAbility(id, source) +APreventDamageTypesUEOT::APreventDamageTypesUEOT(GameObserver* observer, int id, MTGCardInstance * source, string to, string from, int type) : + InstantAbility(observer, id, source) { - ability = NEW APreventDamageTypes(id, source, to, from, type); + ability = NEW APreventDamageTypes(observer, id, source, to, from, type); } int APreventDamageTypesUEOT::resolve() { APreventDamageTypes * a = ability->clone(); - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), a); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source, (Damageable *) (this->target), a); wrapper->addToGame(); return 1; } @@ -3333,8 +3324,8 @@ APreventDamageTypesUEOT::~APreventDamageTypesUEOT() } //AVanishing creature also fading -AVanishing::AVanishing(int _id, MTGCardInstance * card, ManaCost * _cost, int restrictions, int amount, string counterName) : -MTGAbility(_id, source, target),amount(amount),counterName(counterName) +AVanishing::AVanishing(GameObserver* observer, int _id, MTGCardInstance * card, ManaCost * _cost, int restrictions, int amount, string counterName) : +MTGAbility(observer, _id, source, target),amount(amount),counterName(counterName) { target = card; source = card; @@ -3372,7 +3363,6 @@ void AVanishing::Update(float dt) if (newPhase == Constants::MTG_PHASE_UPKEEP && timeLeft <= 0 && next == 0) { WEvent * e = NEW WEventCardSacrifice(source); - GameObserver * game = GameObserver::GetInstance(); game->receiveEvent(e); source->controller()->game->putInGraveyard(source); } @@ -3405,9 +3395,9 @@ AVanishing::~AVanishing() } //AUpkeep -AUpkeep::AUpkeep(int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, int restrictions, int _phase, +AUpkeep::AUpkeep(GameObserver* observer, int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, int restrictions, int _phase, int _once,bool Cumulative) : - ActivatedAbility(_id, card, _cost, restrictions), NestedAbility(a), phase(_phase), once(_once),Cumulative(Cumulative) + ActivatedAbility(observer, _id, card, _cost, restrictions), NestedAbility(a), phase(_phase), once(_once),Cumulative(Cumulative) { paidThisTurn = 0; aType = MTGAbility::UPCOST; @@ -3503,13 +3493,13 @@ AUpkeep::~AUpkeep() } //A Phase based Action -APhaseAction::APhaseAction(int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions, int _phase,bool forcedestroy,bool next,bool myturn,bool opponentturn,bool once) : -MTGAbility(_id, card),sAbility(sAbility), phase(_phase),forcedestroy(forcedestroy),next(next),myturn(myturn),opponentturn(opponentturn),once(once) +APhaseAction::APhaseAction(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions, int _phase,bool forcedestroy,bool next,bool myturn,bool opponentturn,bool once) : +MTGAbility(observer, _id, card),sAbility(sAbility), phase(_phase),forcedestroy(forcedestroy),next(next),myturn(myturn),opponentturn(opponentturn),once(once) { abilityId = _id; abilityOwner = card->controller(); psMenuText = ""; - AbilityFactory af; + AbilityFactory af(game); ability = af.parseMagicLine(sAbility, abilityId, NULL, NULL); if(ability) psMenuText = ability->getMenuText(); @@ -3542,7 +3532,7 @@ void APhaseAction::Update(float dt) while(_target->next) _target = _target->next; } - AbilityFactory af; + AbilityFactory af(game); MTGAbility * ability = af.parseMagicLine(sAbility, abilityId, NULL, _target); MTGAbility * a = ability->clone(); @@ -3590,11 +3580,11 @@ APhaseAction::~APhaseAction() } // the main ability -APhaseActionGeneric::APhaseActionGeneric(int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions, int _phase,bool forcedestroy,bool next,bool myturn,bool opponentturn,bool once) : - InstantAbility(_id, source, target) +APhaseActionGeneric::APhaseActionGeneric(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions, int _phase,bool forcedestroy,bool next,bool myturn,bool opponentturn,bool once) : + InstantAbility(observer, _id, source, target) { MTGCardInstance * _target = target; - ability = NEW APhaseAction(_id, card,_target, sAbility, restrictions, _phase,forcedestroy,next,myturn,opponentturn,once); + ability = NEW APhaseAction(game, _id, card,_target, sAbility, restrictions, _phase,forcedestroy,next,myturn,opponentturn,once); } int APhaseActionGeneric::resolve() @@ -3624,8 +3614,8 @@ APhaseActionGeneric::~APhaseActionGeneric() } //a blink -ABlink::ABlink(int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot,bool blinkForSource,bool blinkhand,MTGAbility * stored) : -MTGAbility(_id, card),blinkueot(blinkueot),blinkForSource(blinkForSource),blinkhand(blinkhand),stored(stored) +ABlink::ABlink(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot,bool blinkForSource,bool blinkhand,MTGAbility * stored) : +MTGAbility(observer, _id, card),blinkueot(blinkueot),blinkForSource(blinkForSource),blinkhand(blinkhand),stored(stored) { target = _target; Blinked = NULL; @@ -3639,8 +3629,8 @@ void ABlink::Update(float dt) resolved = true; resolveBlink(); } - GameObserver * game = game->GetInstance(); - if ((blinkueot && currentPhase == Constants::MTG_PHASE_ENDOFTURN)||(blinkForSource && !source->isInPlay())) + + if ((blinkueot && currentPhase == Constants::MTG_PHASE_ENDOFTURN)||(blinkForSource && !source->isInPlay(game))) { if(Blinked == NULL) MTGAbility::Update(dt); @@ -3655,11 +3645,11 @@ void ABlink::Update(float dt) _target->owner->game->hand); return; } - Spell * spell = NEW Spell(Blinker); + Spell * spell = NEW Spell(game, Blinker); spell->source->counters->init(); if(spell->source->hasSubtype(Subtypes::TYPE_AURA) && !blinkhand) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(game); TargetChooser * tc = tcf.createTargetChooser(spell->source->spellTargetType,spell->source); if(!tc->validTargetsExist()) { @@ -3754,11 +3744,11 @@ void ABlink::resolveBlink() _target->owner->game->hand); return; } - Spell * spell = NEW Spell(Blinker); + Spell * spell = NEW Spell(game, Blinker); spell->source->counters->init(); if(spell->source->hasSubtype(Subtypes::TYPE_AURA) && !blinkhand) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(game); TargetChooser * tc = tcf.createTargetChooser(spell->source->spellTargetType,spell->source); if(!tc->validTargetsExist()) { @@ -3833,10 +3823,10 @@ ABlink::~ABlink() SAFE_DELETE(stored); } -ABlinkGeneric::ABlinkGeneric(int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot,bool blinkForSource,bool blinkhand,MTGAbility * stored) : - InstantAbility(_id, source, _target) +ABlinkGeneric::ABlinkGeneric(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot,bool blinkForSource,bool blinkhand,MTGAbility * stored) : + InstantAbility(observer, _id, source, _target) { - ability = NEW ABlink(_id,card,_target,blinkueot,blinkForSource,blinkhand,stored); + ability = NEW ABlink(observer, _id,card,_target,blinkueot,blinkForSource,blinkhand,stored); } int ABlinkGeneric::resolve() @@ -3866,8 +3856,8 @@ ABlinkGeneric::~ABlinkGeneric() } // target becomes a parent of card(source) -AAConnect::AAConnect(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : -InstantAbility(id, card, target) +AAConnect::AAConnect(GameObserver* observer, int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : +InstantAbility(observer, id, card, target) { target = _target; } @@ -3884,10 +3874,9 @@ int AAConnect::resolve() //weapon if(source->hasSubtype(Subtypes::TYPE_EQUIPMENT)) { - GameObserver * g = GameObserver::GetInstance(); - for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) + for (size_t i = 1; i < game->mLayers->actionLayer()->mObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); + MTGAbility * a = ((MTGAbility *) game->mLayers->actionLayer()->mObjects[i]); AEquip * eq = dynamic_cast (a); if (eq && eq->source == source) { @@ -3917,7 +3906,8 @@ AAConnect * AAConnect::clone() const ATutorialMessage * ATutorialMessage::Current = NULL; -ATutorialMessage::ATutorialMessage(MTGCardInstance * source, string message, int limit) : MTGAbility(0, source), IconButtonsController(0, 0), mLimit(limit) +ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * source, string message, int limit) + : MTGAbility(observer, 0, source), IconButtonsController(0, 0), mLimit(limit) { mBgTex = NULL; diff --git a/projects/mtg/src/CardDescriptor.cpp b/projects/mtg/src/CardDescriptor.cpp index cd071f163..cfecee6d4 100644 --- a/projects/mtg/src/CardDescriptor.cpp +++ b/projects/mtg/src/CardDescriptor.cpp @@ -225,7 +225,7 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card) { match = NULL; } - Player * p = controller()->opponent(); + Player * p = card->controller()->opponent();//controller()->opponent(); if ((CDopponentDamaged == -1 && card->damageToOpponent && card->controller() == p) || (CDopponentDamaged == 1 && !card->damageToOpponent && card->controller() == p) || (CDopponentDamaged == -1 && card->damageToController && card->controller() == p->opponent()) || (CDopponentDamaged == 1 && !card->damageToController && card->controller() == p->opponent())) { @@ -354,4 +354,4 @@ void CardDescriptor::SetExclusionColor(int _color, int removeAllOthers) mColorExclusions = 0; mColorExclusions |= ConvertColorToBitMask(_color); -} \ No newline at end of file +} diff --git a/projects/mtg/src/CardDisplay.cpp b/projects/mtg/src/CardDisplay.cpp index 34f9e8896..6f3f8e865 100644 --- a/projects/mtg/src/CardDisplay.cpp +++ b/projects/mtg/src/CardDisplay.cpp @@ -7,8 +7,8 @@ #include "MTGGameZones.h" #include "GameObserver.h" -CardDisplay::CardDisplay() : - mId(0), game(GameObserver::GetInstance()) +CardDisplay::CardDisplay(GameObserver* game) : + mId(0), PlayGuiObjectController(game) { tc = NULL; listener = NULL; @@ -21,7 +21,7 @@ CardDisplay::CardDisplay() : CardDisplay::CardDisplay(int id, GameObserver* game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc, int _nb_displayed_items) : - mId(id), game(game), x(_x), y(_y) + mId(id), PlayGuiObjectController(game), x(_x), y(_y) { tc = _tc; listener = _listener; @@ -119,7 +119,7 @@ bool CardDisplay::CheckUserInput(JButton key) } else { - if (game) game->ButtonPressed(cardg); + if (observer) observer->ButtonPressed(cardg); return true; } } @@ -260,7 +260,7 @@ void CardDisplay::Render() CardGui * cardg = ((CardGui *) mObjects[mCurr]); Pos pos = Pos(CardGui::BigWidth / 2, CardGui::BigHeight / 2 - 10, 1.0, 0.0, 220); int drawMode = DrawMode::kNormal; - if (game) + if (observer) { pos.actY = 150; if (x < (CardGui::BigWidth / 2)) pos.actX = SCREEN_WIDTH - 10 - CardGui::BigWidth / 2; diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index a3a499202..ffa0787a2 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -132,7 +132,7 @@ void CardGui::Render() WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); JRenderer * renderer = JRenderer::GetInstance(); - GameObserver * game = GameObserver::GetInstance(); + GameObserver * game = card->getObserver(); TargetChooser * tc = NULL; if (game) @@ -496,9 +496,11 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos) } for (int i = Constants::MTG_NB_COLORS - 2; i >= 1; --i) { - for (int cost = manacost->getCost(i); cost > 0; --cost) + int cost; + + for (cost = manacost->getCost(i); cost > 0; --cost) { - renderer->RenderQuad(manaIcons[i].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f + renderer->RenderQuad(manaIcons[i].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0.0f, 0.4f * pos.actZ, 0.4f * pos.actZ); ++j; } @@ -1030,4 +1032,4 @@ void SimpleCardEffectMask::doEffect(Pos * card) void SimpleCardEffectMask::undoEffect(Pos * card) { card->mask = 0; -} \ No newline at end of file +} diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index f41322f3e..cefde2f3d 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -74,8 +74,8 @@ CardSelector::SelectorMemory::SelectorMemory() x = y = 0; } -CardSelector::CardSelector(DuelLayers* duel) : - active(NULL), duel(duel), limitor(NULL), bigpos(300, 145, 1.0, 0.0, 220) +CardSelector::CardSelector(GameObserver *observer, DuelLayers* duel) : + CardSelectorBase(observer), active(NULL), duel(duel), limitor(NULL), bigpos(300, 145, 1.0, 0.0, 220) { } @@ -195,11 +195,11 @@ bool CardSelector::CheckUserInput(JButton key) switch (key) { case JGE_BTN_SEC: - GameObserver::GetInstance()->cancelCurrentAction(); + observer->cancelCurrentAction(); goto switch_active; break; case JGE_BTN_OK: - GameObserver::GetInstance()->ButtonPressed(active); + observer->ButtonPressed(active); goto switch_active; break; case JGE_BTN_LEFT: diff --git a/projects/mtg/src/CardSelectorSingleton.cpp b/projects/mtg/src/CardSelectorSingleton.cpp index 7d4e817b9..e802aea79 100644 --- a/projects/mtg/src/CardSelectorSingleton.cpp +++ b/projects/mtg/src/CardSelectorSingleton.cpp @@ -12,11 +12,10 @@ namespace CardSelectorSingleton { static CardSelectorBase* sCardSelectorInstance = NULL; - CardSelectorBase* Create(DuelLayers* inDuelLayers) + CardSelectorBase* Create(GameObserver* observer, DuelLayers* inDuelLayers) { if (sCardSelectorInstance == NULL) - sCardSelectorInstance = NEW CardSelector(inDuelLayers); - //sCardSelectorInstance = NEW Navigator(inDuelLayers); + sCardSelectorInstance = NEW CardSelector(observer, inDuelLayers); return sCardSelectorInstance; } diff --git a/projects/mtg/src/Counters.cpp b/projects/mtg/src/Counters.cpp index ce75efb06..e1f996b1d 100644 --- a/projects/mtg/src/Counters.cpp +++ b/projects/mtg/src/Counters.cpp @@ -73,7 +73,7 @@ Counters::~Counters() int Counters::addCounter(const char * _name, int _power, int _toughness) { /*420.5n If a permanent has both a +1/+1 counter and a -1/-1 counter on it, N +1/+1 and N -1/-1 counters are removed from it, where N is the smaller of the number of +1/+1 and -1/-1 counters on it.*/ - GameObserver *g = GameObserver::GetInstance(); + GameObserver *g = target->getObserver(); WEvent * e = NEW WEventCounters(this,_name,_power,_toughness); dynamic_cast(e)->targetCard = this->target; if (e == g->replacementEffects->replace(e)) @@ -144,14 +144,14 @@ int Counters::removeCounter(const char * _name, int _power, int _toughness) return 0; counters[i]->removed(); counters[i]->nb--; - GameObserver *g = GameObserver::GetInstance(); + GameObserver *g = target->getObserver(); WEvent * e = NEW WEventCounters(this,_name,_power,_toughness,false,true); dynamic_cast(e)->targetCard = this->target; g->receiveEvent(e); //special case:if a card is suspended and no longer has a time counter when the last is removed, the card is cast. if (target->suspended && !target->counters->hasCounter("time",0,0)) { - GameObserver * game = game->GetInstance(); + GameObserver * game = target->getObserver(); MTGCardInstance * copy = target->controller()->game->putInZone(target, target->currentZone, target->controller()->game->stack); game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, NULL,1, 0); diff --git a/projects/mtg/src/Credits.cpp b/projects/mtg/src/Credits.cpp index 9ef3ffb0a..5c1664230 100644 --- a/projects/mtg/src/Credits.cpp +++ b/projects/mtg/src/Credits.cpp @@ -29,6 +29,7 @@ Credits::Credits() unlocked = -1; p1 = NULL; p2 = NULL; + observer = NULL; } Credits::~Credits() @@ -39,15 +40,15 @@ Credits::~Credits() bonus.clear(); } -void Credits::compute(Player * _p1, Player * _p2, GameApp * _app) +void Credits::compute(GameObserver* g, GameApp * _app) { - p1 = _p1; - p2 = _p2; - app = _app; - showMsg = (WRand() % 3); - GameObserver * g = GameObserver::GetInstance(); if (!g->turn) return; + p1 = g->players[0]; + p2 = g->players[1]; + observer = g; + app = _app; + showMsg = (WRand() % 3); //no credits when the AI plays :) if (p1->isAI()) @@ -105,7 +106,7 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app) GameOptionAward * goa = NULL; // vector finishedTasks; - playerdata->taskList->getDoneTasks(_p1, _p2, _app, &finishedTasks); + playerdata->taskList->getDoneTasks(g, _app, &finishedTasks); char buffer[512]; @@ -243,7 +244,6 @@ void Credits::Render() { if (!p1) return; - GameObserver * g = GameObserver::GetInstance(); JRenderer * r = JRenderer::GetInstance(); WFont * f = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); WFont * f2 = WResourceManager::Instance()->GetWFont(Fonts::MENU_FONT); @@ -255,7 +255,7 @@ void Credits::Render() f3->SetScale(1); f3->SetColor(ARGB(255,255,255,255)); char buffer[512]; - if (!g->turn) + if (!observer->turn) { sprintf(buffer, "%s", _("Please check your deck (not enough cards?)").c_str()); } @@ -263,7 +263,7 @@ void Credits::Render() { if (!p1->isAI() && p2->isAI()) { - if (g->gameOver != p1) + if (observer->gameOver != p1) { sprintf(buffer, _("Congratulations! You earn %i credits").c_str(), value); JQuadPtr unlockedQuad = GetUnlockedQuad(unlockedTextureName); @@ -285,7 +285,7 @@ void Credits::Render() else { int winner = 2; - if (g->gameOver != p1) + if (observer->gameOver != p1) { winner = 1; } @@ -308,9 +308,9 @@ void Credits::Render() y += 15; //!! - if (g->gameOver != p1) + if (observer->gameOver != p1) { - sprintf(buffer, _("Game length: %i turns (%i seconds)").c_str(), g->turn, this->gameLength); + sprintf(buffer, _("Game length: %i turns (%i seconds)").c_str(), observer->turn, this->gameLength); f->DrawString(buffer, 10, y); y += 10; sprintf(buffer, _("Credits per minute: %i").c_str(), (int) (60 * value / this->gameLength)); diff --git a/projects/mtg/src/Damage.cpp b/projects/mtg/src/Damage.cpp index 4bb9a778c..debc9854c 100644 --- a/projects/mtg/src/Damage.cpp +++ b/projects/mtg/src/Damage.cpp @@ -8,12 +8,14 @@ #include "WResourceManager.h" #include "GameObserver.h" -Damage::Damage(MTGCardInstance * source, Damageable * target) +Damage::Damage(GameObserver* observer, MTGCardInstance * source, Damageable * target) + : Interruptible(observer) { init(source, target, source->getPower(), DAMAGE_OTHER); } -Damage::Damage(MTGCardInstance * source, Damageable * target, int damage, int _typeOfDamage) +Damage::Damage(GameObserver* observer, MTGCardInstance * source, Damageable * target, int damage, int _typeOfDamage) + : Interruptible(observer) { init(source, target, damage, _typeOfDamage); } @@ -36,16 +38,15 @@ int Damage::resolve() if (damage < 0) damage = 0; //Negative damages cannot happen state = RESOLVED_OK; - GameObserver * g = GameObserver::GetInstance(); WEvent * e = NEW WEventDamage(this); //Replacement Effects - e = g->replacementEffects->replace(e); + e = observer->replacementEffects->replace(e); if (!e) return 0; WEventDamage * ev = dynamic_cast (e); if (!ev) { - g->receiveEvent(e); + observer->receiveEvent(e); return 0; } damage = ev->damage->damage; @@ -193,13 +194,12 @@ int Damage::resolve() } target->lifeLostThisTurn += damage; WEvent * lifed = NEW WEventLife((Player*)target,-damage); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(lifed); + observer->receiveEvent(lifed); } } //Send (Damage/Replaced effect) event to listeners - g->receiveEvent(e); + observer->receiveEvent(e); return a; } void Damage::Render() @@ -241,7 +241,8 @@ ostream& Damage::toString(ostream& out) const return out; } -DamageStack::DamageStack() +DamageStack::DamageStack(GameObserver *observer) + : GuiLayer(observer), Interruptible(observer) { currentState = -1; type = ACTION_DAMAGES; @@ -261,7 +262,7 @@ int DamageStack::resolve() if (damage->state == NOT_RESOLVED) damage->resolve(); } - GameObserver::GetInstance()->receiveEvent(NEW WEventDamageStackResolved()); + ((Interruptible*)this)->getObserver()->receiveEvent(NEW WEventDamageStackResolved()); return 1; } @@ -300,3 +301,49 @@ ostream& DamageStack::toString(ostream& out) const { return (out << "DamageStack ::: currentState : " << currentState); } + + +ostream& operator<<(ostream& out, const Damageable& p) +{ + return out; +} + +istream& operator>>(istream& in, Damageable& p) +{ + string s; + streampos pos = in.tellg(); + while(std::getline(in, s)) + { + size_t limiter = s.find("="); + if (limiter == string::npos) limiter = s.find(":"); + string areaS; + if (limiter != string::npos) + { + areaS = s.substr(0, limiter); + if (areaS.compare("life") == 0) + { + p.life = atoi((s.substr(limiter + 1)).c_str()); + } + else if (areaS.compare("poisoncount") == 0) + { + p.poisonCount = atoi((s.substr(limiter + 1)).c_str()); + } + else if (areaS.compare("damagecount") == 0) + { + p.damageCount = atoi((s.substr(limiter + 1)).c_str()); + } + else if (areaS.compare("preventable") == 0) + { + p.preventable = atoi((s.substr(limiter + 1)).c_str()); + } + else + { + in.seekg(pos); + break; + } + } + pos = in.tellg(); + } + + return in; +} diff --git a/projects/mtg/src/DamagerDamaged.cpp b/projects/mtg/src/DamagerDamaged.cpp index 6e5e91f2a..158a8d3dd 100644 --- a/projects/mtg/src/DamagerDamaged.cpp +++ b/projects/mtg/src/DamagerDamaged.cpp @@ -43,7 +43,7 @@ void DamagerDamaged::addDamage(int damage, DamagerDamaged* source) return; } if (0 < damage) - damages.push_back(Damage(source->card, card, damage, DAMAGE_COMBAT)); + damages.push_back(Damage(card->getObserver(), source->card, card, damage, DAMAGE_COMBAT)); return; } diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 92bb67239..fd7b17f51 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -13,39 +13,36 @@ #include "Trash.h" #include "DuelLayers.h" -void DuelLayers::init() +void DuelLayers::init(GameObserver* go) { - - GameObserver* go = GameObserver::GetInstance(); - - mCardSelector = CardSelectorSingleton::Create(this); + mCardSelector = CardSelectorSingleton::Create(go, this); //1 Action Layer - action = NEW ActionLayer(); - action->Add(NEW MTGGamePhase(action->getMaxId())); + action = NEW ActionLayer(go); + action->Add(NEW MTGGamePhase(go, action->getMaxId())); //Add Magic Specific Rules - action->Add(NEW MTGEventBonus(-1)); - action->Add(NEW MTGPutInPlayRule(-1)); - action->Add(NEW MTGKickerRule(-1)); - action->Add(NEW MTGAlternativeCostRule(-1)); - action->Add(NEW MTGBuyBackRule(-1)); - action->Add(NEW MTGFlashBackRule(-1)); - action->Add(NEW MTGRetraceRule(-1)); - action->Add(NEW MTGSuspendRule(-1)); - action->Add(NEW MTGAttackRule(-1)); - action->Add(NEW MTGBlockRule(-1)); - action->Add(NEW MTGCombatTriggersRule(-1)); - action->Add(NEW MTGLegendRule(-1)); - action->Add(NEW MTGPlaneWalkerRule(-1)); - action->Add(NEW MTGTokensCleanup(-1)); // needs to be before persist - action->Add(NEW MTGPersistRule(-1)); - action->Add(NEW MTGVampireRule(-1)); - action->Add(NEW MTGUnearthRule(-1)); - action->Add(NEW MTGLifelinkRule(-1)); - action->Add(NEW MTGDeathtouchRule(-1)); - action->Add(NEW OtherAbilitiesEventReceiver(-1)); - action->Add(NEW MTGMorphCostRule(-1)); + action->Add(NEW MTGEventBonus(go, -1)); + action->Add(NEW MTGPutInPlayRule(go, -1)); + action->Add(NEW MTGKickerRule(go, -1)); + action->Add(NEW MTGAlternativeCostRule(go, -1)); + action->Add(NEW MTGBuyBackRule(go, -1)); + action->Add(NEW MTGFlashBackRule(go, -1)); + action->Add(NEW MTGRetraceRule(go, -1)); + action->Add(NEW MTGSuspendRule(go, -1)); + action->Add(NEW MTGAttackRule(go, -1)); + action->Add(NEW MTGBlockRule(go, -1)); + action->Add(NEW MTGCombatTriggersRule(go, -1)); + action->Add(NEW MTGLegendRule(go, -1)); + action->Add(NEW MTGPlaneWalkerRule(go, -1)); + action->Add(NEW MTGTokensCleanup(go, -1)); // needs to be before persist + action->Add(NEW MTGPersistRule(go, -1)); + action->Add(NEW MTGVampireRule(go, -1)); + action->Add(NEW MTGUnearthRule(go, -1)); + action->Add(NEW MTGLifelinkRule(go, -1)); + action->Add(NEW MTGDeathtouchRule(go, -1)); + action->Add(NEW OtherAbilitiesEventReceiver(go, -1)); + action->Add(NEW MTGMorphCostRule(go, -1)); //Other display elements - action->Add(NEW HUDDisplay(-1)); + action->Add(NEW HUDDisplay(go, -1)); Add(NEW GuiMana(20, 20, go->players[1])); Add(NEW GuiMana(440, 20, go->players[0])); @@ -53,13 +50,13 @@ void DuelLayers::init() Add(combat = NEW GuiCombat(go)); Add(action); Add(mCardSelector); - Add(hand = NEW GuiHandSelf(go->players[0]->game->hand)); - Add(avatars = NEW GuiAvatars()); - Add(NEW GuiHandOpponent(go->players[1]->game->hand)); + Add(hand = NEW GuiHandSelf(go, go->players[0]->game->hand)); + Add(avatars = NEW GuiAvatars(go)); + Add(NEW GuiHandOpponent(go, go->players[1]->game->hand)); Add(NEW GuiPlay(go)); - Add(NEW GuiPhaseBar()); - Add(NEW GuiFrame()); - Add(NEW GuiBackground()); + Add(NEW GuiPhaseBar(go)); + Add(NEW GuiFrame(go)); + Add(NEW GuiBackground(go)); } void DuelLayers::CheckUserInput(int isAI) diff --git a/projects/mtg/src/ExtraCost.cpp b/projects/mtg/src/ExtraCost.cpp index 6b932634c..310de92e0 100644 --- a/projects/mtg/src/ExtraCost.cpp +++ b/projects/mtg/src/ExtraCost.cpp @@ -215,7 +215,7 @@ int DiscardCost::doPay() if (target) { WEvent * e = NEW WEventCardDiscard(target); - GameObserver * game = GameObserver::GetInstance(); + GameObserver * game = target->owner->getObserver(); game->receiveEvent(e); _target->controller()->game->putInGraveyard(_target); target = NULL; @@ -503,10 +503,9 @@ ExtraCost("Select unblocked attacker", _tc) int Ninja::isPaymentSet() { - GameObserver * g = GameObserver::GetInstance(); - int currentPhase = g->getCurrentGamePhase(); - if (target && ((target->isAttacker() && target->blocked) || target->isAttacker() < 1 || currentPhase - != Constants::MTG_PHASE_COMBATBLOCKERS)) + if (target && ((target->isAttacker() && target->blocked) || + target->isAttacker() < 1 || + target->getObserver()->getCurrentGamePhase() != Constants::MTG_PHASE_COMBATBLOCKERS)) { tc->removeTarget(target); target = NULL; @@ -551,7 +550,7 @@ int SacrificeCost::doPay() if (target) { WEvent * e = NEW WEventCardSacrifice(target); - GameObserver * game = GameObserver::GetInstance(); + GameObserver * game = target->owner->getObserver(); game->receiveEvent(e); target->controller()->game->putInGraveyard(target); target = NULL; diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index ed469b65e..f9f31d63e 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -11,35 +11,18 @@ #include "MTGGamePhase.h" #include "GuiPhaseBar.h" -GameObserver * GameObserver::mInstance = NULL; - -GameObserver* GameObserver::GetInstance() +GameObserver::GameObserver() { - return mInstance; + initialize(); } -void GameObserver::EndInstance() +void GameObserver::initialize() { - - SAFE_DELETE(mInstance); -} - -void GameObserver::Init(Player * _players[], int _nbplayers) -{ - mInstance = NEW GameObserver(_players, _nbplayers); -} - -GameObserver::GameObserver(Player * _players[], int _nb_players) -{ - for (int i = 0; i < _nb_players; i++) - { - players[i] = _players[i]; - } currentPlayer = NULL; currentActionPlayer = NULL; isInterrupting = NULL; currentPlayerId = 0; - nbPlayers = _nb_players; + nbPlayers = 0; currentGamePhase = -1; targetChooser = NULL; cardWaitingForTargets = NULL; @@ -52,11 +35,37 @@ GameObserver::GameObserver(Player * _players[], int _nb_players) connectRule = false; } +void GameObserver::setPlayers(Player * _players[], int _nbplayers) +{ + for (int i = 0; i < _nbplayers; i++) + { + players[i] = _players[i]; + players[i]->setObserver(this); + } + nbPlayers = _nbplayers; +} + +GameObserver::GameObserver(Player * _players[], int _nb_players) +{ + initialize(); + setPlayers(_players, _nb_players); +} + int GameObserver::getCurrentGamePhase() { return currentGamePhase; } +const char* GameObserver::getCurrentGamePhaseName() +{ + return phaseRing->phaseName(currentGamePhase); +} + +const char* GameObserver::getNextGamePhaseName() +{ + return phaseRing->phaseName((currentGamePhase + 1) % Constants::MTG_PHASE_CLEANUP); +} + Player * GameObserver::opponent() { int index = (currentPlayerId + 1) % nbPlayers; @@ -130,8 +139,7 @@ void GameObserver::nextGamePhase() while (currentPlayer->game->hand->nb_cards > currentPlayer->handsize && currentPlayer->nomaxhandsize == false) { WEvent * e = NEW WEventCardDiscard(currentPlayer->game->hand->cards[0]); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + receiveEvent(e); currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]); } mLayers->actionLayer()->Update(0); @@ -249,19 +257,19 @@ void GameObserver::startGame(Rules * rules) turn = 0; mRules = rules; if (rules) - rules->initPlayers(); + rules->initPlayers(this); options.automaticStyle(players[0], players[1]); mLayers = NEW DuelLayers(); - mLayers->init(); + mLayers->init(this); currentPlayerId = 0; currentPlayer = players[0]; currentActionPlayer = currentPlayer; - phaseRing = NEW PhaseRing(players, nbPlayers); + phaseRing = NEW PhaseRing(this); if (rules) - rules->initGame(); + rules->initGame(this); //Preload images from hand if (!players[0]->isAI()) @@ -298,7 +306,7 @@ void GameObserver::startGame(Rules * rules) if (card) { MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack); - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(this, copy); spell->resolve(); delete spell; } @@ -455,7 +463,7 @@ void GameObserver::gameStateBasedEffects() ////////////////////////// //forceDestroy over ride// ////////////////////////// - if(card->isInPlay()) + if(card->isInPlay(this)) { card->graveEffects = false; card->exileEffects = false; @@ -471,7 +479,7 @@ void GameObserver::gameStateBasedEffects() check = card->childrenCards[wC]; for(size_t wCC = 0; wCC < card->childrenCards.size();wCC++) { - if(check->isInPlay()) + if(check->isInPlay(this)) { if(check->getName() == card->childrenCards[wCC]->getName() && check != card->childrenCards[wCC]) { @@ -559,7 +567,7 @@ void GameObserver::gameStateBasedEffects() c->flanked -= 1; } c->fresh = 0; - if(c->wasDealtDamage && c->isInPlay()) + if(c->wasDealtDamage && c->isInPlay(this)) c->wasDealtDamage = false; c->damageToController = false; c->damageToOpponent = false; @@ -571,8 +579,7 @@ void GameObserver::gameStateBasedEffects() if (c->has(Constants::TREASON)) { WEvent * e = NEW WEventCardSacrifice(c); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + receiveEvent(e); p->game->putInGraveyard(c); } @@ -632,8 +639,7 @@ void GameObserver::gameStateBasedEffects() } //Auto skip Phases - GameObserver * game = game->GetInstance(); - int skipLevel = (game->currentPlayer->playMode == Player::MODE_TEST_SUITE) ? Constants::ASKIP_NONE + int skipLevel = (currentPlayer->playMode == Player::MODE_TEST_SUITE) ? Constants::ASKIP_NONE : options[Options::ASPHASES].number; int nrCreatures = currentPlayer->game->inPlay->countByType("Creature"); @@ -752,7 +758,7 @@ void GameObserver::Affinity() int reduce = 0; if(card->has(Constants::AFFINITYGREENCREATURES)) { - TargetChooserFactory tf; + TargetChooserFactory tf(this); TargetChooser * tc = tf.createTargetChooser("creature[green]",NULL); reduce = card->controller()->game->battlefield->countByCanTarget(tc); SAFE_DELETE(tc); @@ -968,8 +974,7 @@ int GameObserver::cardClick(MTGCardInstance * card, Targetable * object) && currentPlayer->game->hand->nb_cards > currentPlayer->handsize && currentPlayer->nomaxhandsize == false) { WEvent * e = NEW WEventCardDiscard(currentPlayer->game->hand->cards[0]); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + receiveEvent(e); currentPlayer->game->putInGraveyard(card); } else if (reaction) @@ -1093,7 +1098,7 @@ int GameObserver::targetListIsSet(MTGCardInstance * card) { if (targetChooser == NULL) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(this); targetChooser = tcf.createTargetChooser(card); if (targetChooser == NULL) { diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 4a3a08481..47797d621 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -210,7 +210,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, bool isAI, bool isNetwo sprintf(deckFile, "%s/deck%i.txt", options.profileFile().c_str(), decknb); char deckFileSmall[255]; sprintf(deckFileSmall, "player_deck%i", decknb); - mPlayers[playerId] = NEW HumanPlayer(deckFile, deckFileSmall); + mPlayers[playerId] = NEW HumanPlayer(game, deckFile, deckFileSmall); #ifdef NETWORK_SUPPORT if(isNetwork) { @@ -229,7 +229,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, bool isAI, bool isNetwo AIPlayerFactory playerCreator; Player * opponent = NULL; if (playerId == 1) opponent = mPlayers[0]; - mPlayers[playerId] = playerCreator.createAIPlayer(MTGCollection(), opponent, decknb); + mPlayers[playerId] = playerCreator.createAIPlayer(game, MTGCollection(), opponent, decknb); } } else @@ -239,11 +239,11 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, bool isAI, bool isNetwo if (playerId == 1) opponent = mPlayers[0]; #ifdef AI_CHANGE_TESTING if (mParent->players[0] == PLAYER_TYPE_CPU_TEST) - mPlayers[playerId] = playerCreator.createAIPlayerTest(MTGCollection(), opponent, playerId == 0 ? "ai/bakaA/" : "ai/bakaB/"); + mPlayers[playerId] = playerCreator.createAIPlayerTest(game, MTGCollection(), opponent, playerId == 0 ? "ai/bakaA/" : "ai/bakaB/"); else #endif { - mPlayers[playerId] = playerCreator.createAIPlayer(MTGCollection(), opponent); + mPlayers[playerId] = playerCreator.createAIPlayer(game, MTGCollection(), opponent); } if (mParent->players[playerId] == PLAYER_TYPE_CPU_TEST) @@ -264,18 +264,18 @@ void GameStateDuel::loadTestSuitePlayers() if (!testSuite) return; initRand(testSuite->seed); SAFE_DELETE(game); + game = new GameObserver(); for (int i = 0; i < 2; i++) { - mPlayers[i] = NEW TestSuiteAI(testSuite, i); + mPlayers[i] = new TestSuiteAI(game, testSuite, i); } + game->setPlayers(mPlayers, 2); mParent->gameType = testSuite->gameType; - GameObserver::Init(mPlayers, 2); - game = GameObserver::GetInstance(); game->startGame(mParent->rules); if (mParent->gameType == GAME_TYPE_MOMIR) { - game->addObserver(NEW MTGMomirRule(-1, MTGCollection())); + game->addObserver(NEW MTGMomirRule(game, -1, MTGCollection())); } } #endif @@ -296,9 +296,8 @@ void GameStateDuel::End() else if ( !mPlayers[1] && mPlayers[0] ) // clean up player object SAFE_DELETE( mPlayers[0] ); - GameObserver::EndInstance(); // this will delete both player objects if a game has been played - game = NULL; + SAFE_DELETE(game); premadeDeck = false; for (int i = 0; i < 2; i++) @@ -380,7 +379,7 @@ void GameStateDuel::Update(float dt) { loadTestSuitePlayers(); setGamePhase(DUEL_STATE_PLAY); - testSuite->initGame(); + testSuite->initGame(game); } else { @@ -451,20 +450,19 @@ void GameStateDuel::Update(float dt) case DUEL_STATE_PLAY: if (!game) { - GameObserver::Init(mPlayers, 2); - game = GameObserver::GetInstance(); + game = new GameObserver(mPlayers, 2); game->startGame(mParent->rules); if (mParent->gameType == GAME_TYPE_MOMIR) { - game->addObserver(NEW MTGMomirRule(-1, MTGCollection())); + game->addObserver(NEW MTGMomirRule(game, -1, MTGCollection())); } if (mParent->gameType == GAME_TYPE_STONEHEWER) { - game->addObserver(NEW MTGStoneHewerRule(-1,MTGCollection())); + game->addObserver(NEW MTGStoneHewerRule(game, -1,MTGCollection())); } if (mParent->gameType == GAME_TYPE_HERMIT) { - game->addObserver(NEW MTGHermitRule(-1)); + game->addObserver(NEW MTGHermitRule(game, -1)); } //start of in game music code @@ -490,10 +488,10 @@ void GameStateDuel::Update(float dt) game->Update(dt); //run a "post update" init call in the rules. This is for things such as Manapool, which gets emptied in the update // That's mostly because of a legacy bug, where we use the update sequence for some things when we should use events (such as phase changes) - mParent->rules->postUpdateInit(); + mParent->rules->postUpdateInit(game); if (game->gameOver) { - if (game->players[1]->playMode != Player::MODE_TEST_SUITE) credits->compute(game->players[0], game->players[1], mParent); + if (game->players[1]->playMode != Player::MODE_TEST_SUITE) credits->compute(game, mParent); setGamePhase(DUEL_STATE_END); #ifdef TESTSUITE if (mParent->players[1] == PLAYER_TYPE_TESTSUITE) @@ -502,10 +500,11 @@ void GameStateDuel::Update(float dt) { loadTestSuitePlayers(); setGamePhase(DUEL_STATE_PLAY); - testSuite->initGame(); + testSuite->initGame(game); } - else + else { setGamePhase(DUEL_STATE_END); + } } else #endif diff --git a/projects/mtg/src/GuiAvatars.cpp b/projects/mtg/src/GuiAvatars.cpp index a2911a004..23bdac5f4 100644 --- a/projects/mtg/src/GuiAvatars.cpp +++ b/projects/mtg/src/GuiAvatars.cpp @@ -7,24 +7,24 @@ #define LIB_GRAVE_OFFSET 230 -GuiAvatars::GuiAvatars() : - active(NULL) +GuiAvatars::GuiAvatars(GameObserver* observer) : + GuiLayer(observer), active(NULL) { - Add(self = NEW GuiAvatar(SCREEN_WIDTH, SCREEN_HEIGHT, false, GameObserver::GetInstance()->players[0], GuiAvatar::BOTTOM_RIGHT, this)); + Add(self = NEW GuiAvatar(SCREEN_WIDTH, SCREEN_HEIGHT, false, observer->players[0], GuiAvatar::BOTTOM_RIGHT, this)); self->zoom = 0.9f; - Add(selfGraveyard = NEW GuiGraveyard(SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width / 2 - 11, SCREEN_HEIGHT - GuiAvatar::Height - 1, false, GameObserver::GetInstance()->players[0], this)); - Add(selfLibrary = NEW GuiLibrary(SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width / 2 - 11, SCREEN_HEIGHT - GuiAvatar::Height - 5 + GuiGameZone::Height + 5, false, GameObserver::GetInstance()->players[0], this)); + Add(selfGraveyard = NEW GuiGraveyard(SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width / 2 - 11, SCREEN_HEIGHT - GuiAvatar::Height - 1, false, observer->players[0], this)); + Add(selfLibrary = NEW GuiLibrary(SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width / 2 - 11, SCREEN_HEIGHT - GuiAvatar::Height - 5 + GuiGameZone::Height + 5, false, observer->players[0], this)); - Add(opponent = NEW GuiAvatar(0, 0, false, GameObserver::GetInstance()->players[1], GuiAvatar::TOP_LEFT, this)); + Add(opponent = NEW GuiAvatar(0, 0, false, observer->players[1], GuiAvatar::TOP_LEFT, this)); opponent->zoom = 0.9f; //opponenthandveiw button Add(opponentHand = NEW GuiOpponentHand(-30 + GuiAvatar::Width * 1.2 - GuiGameZone::Width / 2, 35 + GuiGameZone::Height - 10, - false, GameObserver::GetInstance()->players[1], this)); + false, observer->players[1], this)); //opponenthandveiwends Add(opponentGraveyard = NEW GuiGraveyard(5 + GuiAvatar::Width * 1.4 - GuiGameZone::Width / 2, 5, false, - GameObserver::GetInstance()->players[1], this)); + observer->players[1], this)); Add(opponentLibrary = NEW GuiLibrary(5 + GuiAvatar::Width * 1.4 - GuiGameZone::Width / 2, 5 + GuiGameZone::Height + 5, false, - GameObserver::GetInstance()->players[1], this)); + observer->players[1], this)); CardSelectorSingleton::Instance()->Add(self); CardSelectorSingleton::Instance()->Add(selfGraveyard); diff --git a/projects/mtg/src/GuiBackground.cpp b/projects/mtg/src/GuiBackground.cpp index 3de4b474b..dfcbfe232 100644 --- a/projects/mtg/src/GuiBackground.cpp +++ b/projects/mtg/src/GuiBackground.cpp @@ -7,7 +7,8 @@ const std::string kBackdropFile = "backdrop.jpg"; -GuiBackground::GuiBackground() +GuiBackground::GuiBackground(GameObserver* observer) + : GuiLayer(observer) { } @@ -19,10 +20,9 @@ void GuiBackground::Render() { JRenderer* renderer = JRenderer::GetInstance(); JQuadPtr quad; - GameObserver * go = GameObserver::GetInstance(); - if (go && go->mRules && go->mRules->bg.size()) + if (observer && observer->mRules && observer->mRules->bg.size()) { - quad = WResourceManager::Instance()->RetrieveTempQuad(go->mRules->bg); + quad = WResourceManager::Instance()->RetrieveTempQuad(observer->mRules->bg); } if (!quad.get()) { diff --git a/projects/mtg/src/GuiCombat.cpp b/projects/mtg/src/GuiCombat.cpp index c59efa16b..bc35d592d 100644 --- a/projects/mtg/src/GuiCombat.cpp +++ b/projects/mtg/src/GuiCombat.cpp @@ -34,7 +34,7 @@ struct Right: public Exp JTexture* GuiCombat::ok_tex = NULL; GuiCombat::GuiCombat(GameObserver* go) : - GuiLayer(), go(go), active(false), activeAtk(NULL), ok(SCREEN_WIDTH - MARGIN, 210, 1, 0, 255), enemy_avatar(SCREEN_WIDTH + GuiLayer(go), active(false), activeAtk(NULL), ok(SCREEN_WIDTH - MARGIN, 210, 1, 0, 255), enemy_avatar(SCREEN_WIDTH - MARGIN, TOP_LINE, 2, 0, 255), cursor_pos(NONE), step(DAMAGE) { if (NULL == ok_tex) @@ -104,10 +104,10 @@ void GuiCombat::validateDamage() switch (step) { case FIRST_STRIKE: - go->nextCombatStep(); + observer->nextCombatStep(); break; case DAMAGE: - go->nextGamePhase(); + observer->nextGamePhase(); break; default: cout << "COMBAT : Cannot validate damage in this phase" << endl; @@ -172,7 +172,7 @@ bool GuiCombat::clickOK() return false; // that should not happen case ORDER: - go->nextGamePhase(); + observer->nextGamePhase(); return true; case FIRST_STRIKE: return false; @@ -198,7 +198,7 @@ bool GuiCombat::CheckUserInput(JButton key) if (BLK == cursor_pos) { if (ORDER == step) - go->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); } + observer->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); } else { signed damage = activeAtk->card->stepPower(step); @@ -389,8 +389,8 @@ void GuiCombat::Render() damage = 0; if (activeAtk->card->has(Constants::TRAMPLE)) { - go->opponent()->mAvatar->SetHotSpot(18, 25); - enemy_avatar.Render(go->opponent()->mAvatar.get()); + observer->opponent()->mAvatar->SetHotSpot(18, 25); + enemy_avatar.Render(observer->opponent()->mAvatar.get()); WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); mFont->SetColor(ARGB(255, 255, 64, 0)); { @@ -417,7 +417,7 @@ void GuiCombat::Render() int GuiCombat::resolve() // Returns the number of damage objects dealt this turn. { - DamageStack* stack = NEW DamageStack(); + DamageStack* stack = NEW DamageStack(observer); for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it) { MTGCardInstance * attacker = (*it)->card; @@ -430,15 +430,15 @@ int GuiCombat::resolve() // Returns the number of damage objects dealt this turn } if (dmg > 0 && ((!attacker->blocked) || attacker->has(Constants::TRAMPLE))) - stack->Add(NEW Damage((*it)->card, go->opponent(), dmg, DAMAGE_COMBAT)); + stack->Add(NEW Damage(observer, (*it)->card, observer->opponent(), dmg, DAMAGE_COMBAT)); for (vector::iterator d = (*it)->damages.begin(); d != (*it)->damages.end(); ++d) stack->Add(NEW Damage(*d)); } int v = stack->mObjects.size(); if (v > 0) { - go->mLayers->stackLayer()->Add(stack); - go->mLayers->stackLayer()->resolve(); // This will delete the damage stack which will in turn delete the Damage it contains + observer->mLayers->stackLayer()->Add(stack); + observer->mLayers->stackLayer()->resolve(); // This will delete the damage stack which will in turn delete the Damage it contains } else SAFE_DELETE(stack); @@ -506,7 +506,7 @@ int GuiCombat::receiveEventPlus(WEvent* e) int GuiCombat::receiveEventMinus(WEvent* e) { if (WEventZoneChange* event = dynamic_cast(e)) - if (go->players[0]->game->inPlay == event->from || go->players[1]->game->inPlay == event->from) + if (observer->players[0]->game->inPlay == event->from || observer->players[1]->game->inPlay == event->from) { for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it) if ((*it)->card == event->card->previous || (*it)->card == event->card) @@ -578,9 +578,9 @@ int GuiCombat::receiveEventMinus(WEvent* e) { if (ORDER == step) return 0; // Why do I take this twice ? >.> - if (!go->currentPlayer->displayStack()) + if (!observer->currentPlayer->displayStack()) { - go->nextCombatStep(); + observer->nextCombatStep(); return 1; } for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it) @@ -608,7 +608,7 @@ int GuiCombat::receiveEventMinus(WEvent* e) step = ORDER; } else - go->nextGamePhase(); + observer->nextGamePhase(); return 1; } case FIRST_STRIKE: @@ -616,22 +616,22 @@ int GuiCombat::receiveEventMinus(WEvent* e) for (inner_iterator attacker = attackers.begin(); attacker != attackers.end(); ++attacker) if ((*attacker)->card->has(Constants::FIRSTSTRIKE) || (*attacker)->card->has(Constants::DOUBLESTRIKE)) goto DAMAGE; - go->nextCombatStep(); + observer->nextCombatStep(); break; case END_FIRST_STRIKE: step = END_FIRST_STRIKE; for (inner_iterator attacker = attackers.begin(); attacker != attackers.end(); ++attacker) autoaffectDamage(*attacker, FIRST_STRIKE); if (0 == resolve()) - go->nextCombatStep(); + observer->nextCombatStep(); //else go->mLayers->stackLayer()->AddNextGamePhase(); //uncomment to add "interrupt" offer after first strike, rather than giving priority to current player return 1; case DAMAGE: DAMAGE: step = event->step; - if (!go->currentPlayer->displayStack()) + if (!observer->currentPlayer->displayStack()) { - ((AIPlayer *) go->currentPlayer)->affectCombatDamages(step); - go->nextGamePhase(); + ((AIPlayer *) observer->currentPlayer)->affectCombatDamages(step); + observer->nextGamePhase(); return 1; } for (inner_iterator attacker = attackers.begin(); attacker != attackers.end(); ++attacker) @@ -656,12 +656,12 @@ int GuiCombat::receiveEventMinus(WEvent* e) cursor_pos = ATK; } else - go->nextCombatStep(); + observer->nextCombatStep(); return 1; case END_DAMAGE: step = END_DAMAGE; if (0 == resolve()) - go->nextGamePhase(); + observer->nextGamePhase(); return 1; } return 0; diff --git a/projects/mtg/src/GuiFrame.cpp b/projects/mtg/src/GuiFrame.cpp index 19e932939..a61eecfa6 100644 --- a/projects/mtg/src/GuiFrame.cpp +++ b/projects/mtg/src/GuiFrame.cpp @@ -3,7 +3,8 @@ #include "GameApp.h" #include "GuiFrame.h" -GuiFrame::GuiFrame() +GuiFrame::GuiFrame(GameObserver* observer) + : GuiLayer(observer) { if (WResourceManager::Instance()->GetTexture("wood.png")) wood = WResourceManager::Instance()->RetrieveQuad("wood.png", 0, 0, SCREEN_WIDTH, 28); diff --git a/projects/mtg/src/GuiHand.cpp b/projects/mtg/src/GuiHand.cpp index ca5d64e3d..18236f05a 100644 --- a/projects/mtg/src/GuiHand.cpp +++ b/projects/mtg/src/GuiHand.cpp @@ -32,8 +32,8 @@ HandLimitor::HandLimitor(GuiHand* hand) : { } -GuiHand::GuiHand(MTGHand* hand) : - GuiLayer(), hand(hand) +GuiHand::GuiHand(GameObserver* observer, MTGHand* hand) : + GuiLayer(observer), hand(hand) { back = WResourceManager::Instance()->RetrieveTempQuad("handback.png"); if (back.get()) @@ -61,8 +61,8 @@ bool GuiHand::isInHand(CardView* card) return (it != cards.end()); } -GuiHandOpponent::GuiHandOpponent(MTGHand* hand) : - GuiHand(hand) +GuiHandOpponent::GuiHandOpponent(GameObserver* observer, MTGHand* hand) : + GuiHand(observer, hand) { } @@ -81,8 +81,8 @@ void GuiHandOpponent::Render() } } -GuiHandSelf::GuiHandSelf(MTGHand* hand) : - GuiHand(hand), state(Closed), backpos(ClosedX, SCREEN_HEIGHT - 250, 1.0, 0, 255) +GuiHandSelf::GuiHandSelf(GameObserver* observer, MTGHand* hand) : + GuiHand(observer, hand), state(Closed), backpos(ClosedX, SCREEN_HEIGHT - 250, 1.0, 0, 255) { limitor = NEW HandLimitor(this); if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number) diff --git a/projects/mtg/src/GuiLayers.cpp b/projects/mtg/src/GuiLayers.cpp index 5404ec9ca..13baba317 100644 --- a/projects/mtg/src/GuiLayers.cpp +++ b/projects/mtg/src/GuiLayers.cpp @@ -4,7 +4,8 @@ #include "Player.h" #include "AllAbilities.h" -GuiLayer::GuiLayer() +GuiLayer::GuiLayer(GameObserver *observer) + : observer(observer) { modal = 0; hasFocus = false; @@ -20,7 +21,7 @@ GuiLayer::~GuiLayer() void GuiLayer::Add(JGuiObject *object) { mObjects.push_back(object); - AbilityFactory af; + AbilityFactory af(observer); if(MTGAbility * a = dynamic_cast(object)) { AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)object)); @@ -34,7 +35,7 @@ void GuiLayer::Add(JGuiObject *object) int GuiLayer::Remove(JGuiObject *object) { - AbilityFactory af; + AbilityFactory af(observer); if(MTGAbility * a = dynamic_cast(object)) { AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)object)); diff --git a/projects/mtg/src/GuiMana.cpp b/projects/mtg/src/GuiMana.cpp index a67b7013d..8c986a76b 100644 --- a/projects/mtg/src/GuiMana.cpp +++ b/projects/mtg/src/GuiMana.cpp @@ -226,7 +226,7 @@ void ManaIcon::Drop() } GuiMana::GuiMana(float x, float y, Player *p) : - x(x), y(y), owner(p) + GuiLayer(p->getObserver()), x(x), y(y), owner(p) { } diff --git a/projects/mtg/src/GuiPhaseBar.cpp b/projects/mtg/src/GuiPhaseBar.cpp index d2df8513b..7a9199e5c 100644 --- a/projects/mtg/src/GuiPhaseBar.cpp +++ b/projects/mtg/src/GuiPhaseBar.cpp @@ -41,8 +41,8 @@ namespace } } -GuiPhaseBar::GuiPhaseBar() : - PlayGuiObject(0, 0, 106, 0, false), +GuiPhaseBar::GuiPhaseBar(GameObserver* observer) : + PlayGuiObject(0, 0, 106, 0, false), GuiLayer(observer), phase(NULL), angle(0.0f), zoomFactor(ICONSCALE) { JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar"); @@ -96,7 +96,6 @@ bool GuiPhaseBar::Leaving(JButton key) void GuiPhaseBar::Render() { - GameObserver * g = GameObserver::GetInstance(); JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar"); JRenderer::GetInstance()->DrawLine(0, CENTER, SCREEN_WIDTH, CENTER, ARGB(255, 255, 255, 255)); @@ -133,18 +132,18 @@ void GuiPhaseBar::Render() WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); string currentP = _("your turn"); string interrupt = ""; - if (g->currentPlayer == g->players[1]) + if (observer->currentPlayer == observer->players[1]) { currentP = _("opponent's turn"); } font->SetColor(ARGB(255, 255, 255, 255)); - if (g->currentlyActing() && g->currentlyActing()->isAI()) + if (observer->currentlyActing() && observer->currentlyActing()->isAI()) { font->SetColor(ARGB(255, 128, 128, 128)); } - if (g->currentlyActing() != g->currentPlayer) + if (observer->currentlyActing() != observer->currentPlayer) { - if (g->currentPlayer == g->players[0]) + if (observer->currentPlayer == observer->players[0]) { interrupt = _(" - ") + _("opponent plays"); } @@ -155,7 +154,7 @@ void GuiPhaseBar::Render() } char buf[64]; - sprintf(buf, _("(%s%s) %s").c_str(), currentP.c_str(), interrupt.c_str(), _(PhaseRing::phaseName(phase->id)).c_str()); + sprintf(buf, _("(%s%s) %s").c_str(), currentP.c_str(), interrupt.c_str(), observer->phaseRing->phaseName(phase->id)); font->DrawString(buf, SCREEN_WIDTH - 5, 2, JGETEXT_RIGHT); } diff --git a/projects/mtg/src/GuiPlay.cpp b/projects/mtg/src/GuiPlay.cpp index 948280889..38286dca1 100644 --- a/projects/mtg/src/GuiPlay.cpp +++ b/projects/mtg/src/GuiPlay.cpp @@ -122,15 +122,13 @@ void GuiPlay::BattleField::reset(float x, float y) } void GuiPlay::BattleField::EnstackAttacker(CardView* card) { - GameObserver* game = GameObserver::GetInstance(); card->x = currentAttacker * (HORZWIDTH - 20) / (attackers + 1); - card->y = baseY + (game->players[0] == card->card->controller() ? 20 + y : -20 - y); + card->y = baseY + (card->card->getObserver()->players[0] == card->card->controller() ? 20 + y : -20 - y); ++currentAttacker; // JRenderer::GetInstance()->RenderQuad(WResourceManager::Instance()->GetQuad("BattleIcon"), card->actX, card->actY, 0, 0.5 + 0.1 * sinf(JGE::GetInstance()->GetTime()), 0.5 + 0.1 * sinf(JGE::GetInstance()->GetTime())); } void GuiPlay::BattleField::EnstackBlocker(CardView* card) { - GameObserver* game = GameObserver::GetInstance(); MTGCardInstance * c = card->card; if (!c) return; @@ -140,7 +138,7 @@ void GuiPlay::BattleField::EnstackBlocker(CardView* card) offset = c->defenser->getDefenserRank(c); card->x = c->defenser->view->x + 5 * offset; } - card->y = baseY + (game->players[0] == card->card->controller() ? 20 + y + 6 * offset : -20 - y + 6 * offset); + card->y = baseY + (card->card->getObserver()->players[0] == card->card->controller() ? 20 + y + 6 * offset : -20 - y + 6 * offset); } void GuiPlay::BattleField::Update(float dt) { @@ -165,7 +163,7 @@ void GuiPlay::BattleField::Render() } GuiPlay::GuiPlay(GameObserver* game) : - game(game) + GuiLayer(game) { end_spells = cards.end(); } @@ -194,7 +192,7 @@ void GuiPlay::Replace() { if(!(*it)->card->hasSubtype(Subtypes::TYPE_AURA) && !(*it)->card->hasType(Subtypes::TYPE_PLANESWALKER)) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) ++selfSpellsN; else ++opponentSpellsN; @@ -208,14 +206,14 @@ void GuiPlay::Replace() ++battleFieldAttackersN; else if ((*it)->card->isDefenser()) ++battleFieldBlockersN; - else if (game->players[0] == (*it)->card->controller()) + else if (observer->players[0] == (*it)->card->controller()) ++selfCreaturesN; else ++opponentCreaturesN; } else if ((*it)->card->isLand() || (*it)->card->hasType(Subtypes::TYPE_PLANESWALKER)) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) ++selfLandsN; else ++opponentLandsN; @@ -230,7 +228,7 @@ void GuiPlay::Replace() { if(!(*it)->card->hasSubtype(Subtypes::TYPE_AURA) && !(*it)->card->hasType(Subtypes::TYPE_PLANESWALKER)) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) selfSpells.Enstack(*it); else opponentSpells.Enstack(*it); @@ -254,14 +252,14 @@ void GuiPlay::Replace() battleField.EnstackAttacker(*it); else if ((*it)->card->isDefenser()) battleField.EnstackBlocker(*it); - else if (game->players[0] == (*it)->card->controller()) + else if (observer->players[0] == (*it)->card->controller()) selfCreatures.Enstack(*it); else opponentCreatures.Enstack(*it); } else if ((*it)->card->isLand()) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) selfLands.Enstack(*it); else opponentLands.Enstack(*it); @@ -273,7 +271,7 @@ void GuiPlay::Replace() { if ((*it)->card->hasType(Subtypes::TYPE_PLANESWALKER)) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) selfLands.Enstack(*it); else opponentLands.Enstack(*it); @@ -288,14 +286,14 @@ void GuiPlay::Render() for (iterator it = cards.begin(); it != cards.end(); ++it) if ((*it)->card->isLand()) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) selfLands.Render(*it, cards.begin(), end_spells); else opponentLands.Render(*it, cards.begin(), end_spells); } else if ((*it)->card->isCreature()) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) selfCreatures.Render(*it, cards.begin(), end_spells); else opponentCreatures.Render(*it, cards.begin(), end_spells); @@ -304,7 +302,7 @@ void GuiPlay::Render() { if (!(*it)->card->target) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) selfSpells.Render(*it, cards.begin(), end_spells); else opponentSpells.Render(*it, cards.begin(), end_spells); @@ -314,7 +312,7 @@ void GuiPlay::Render() { if (!(*it)->card->target) { - if (game->players[0] == (*it)->card->controller()) + if (observer->players[0] == (*it)->card->controller()) selfPlaneswalker.Render(*it, cards.begin(), end_spells); else opponentPlaneswalker.Render(*it, cards.begin(), end_spells); @@ -333,7 +331,7 @@ int GuiPlay::receiveEventPlus(WEvent * e) { if (WEventZoneChange *event = dynamic_cast(e)) { - if ((game->players[0]->inPlay() == event->to) || (game->players[1]->inPlay() == event->to)) + if ((observer->players[0]->inPlay() == event->to) || (observer->players[1]->inPlay() == event->to)) { CardView * card; if (event->card->view) @@ -413,7 +411,7 @@ int GuiPlay::receiveEventMinus(WEvent * e) { if (WEventZoneChange *event = dynamic_cast(e)) { - if ((game->players[0]->inPlay() == event->from) || (game->players[1]->inPlay() == event->from)) + if ((observer->players[0]->inPlay() == event->from) || (observer->players[1]->inPlay() == event->from)) for (iterator it = cards.begin(); it != cards.end(); ++it) if (event->card->previous == (*it)->card || event->card == (*it)->card) { diff --git a/projects/mtg/src/GuiStatic.cpp b/projects/mtg/src/GuiStatic.cpp index 64824cf39..9543fcc43 100644 --- a/projects/mtg/src/GuiStatic.cpp +++ b/projects/mtg/src/GuiStatic.cpp @@ -28,7 +28,6 @@ GuiAvatar::GuiAvatar(float x, float y, bool hasFocus, Player * player, Corner co void GuiAvatar::Render() { - GameObserver * game = GameObserver::GetInstance(); JRenderer * r = JRenderer::GetInstance(); int life = player->life; int poisonCount = player->poisonCount; @@ -88,11 +87,11 @@ void GuiAvatar::Render() avatarRed = 255; } - if (game->currentPlayer == player) + if (player->getObserver()->currentPlayer == player) r->DrawRect(x0 - 1, y0 - 1, 36 * actZ, 51 * actZ, ARGB((int)actA, 0, 255, 0)); - else if (game->currentActionPlayer == player) + else if (player->getObserver()->currentActionPlayer == player) r->DrawRect(x0, y0, 34 * actZ, 49 * actZ, ARGB((int)actA, 0, 0, 255)); - if (game->isInterrupting == player) + if (player->getObserver()->isInterrupting == player) r->DrawRect(x0, y0, 34 * actZ, 49 * actZ, ARGB((int)actA, 255, 0, 0)); //Life @@ -189,7 +188,7 @@ void GuiGameZone::Render() void GuiGameZone::ButtonPressed(int controllerId, int controlId) { - GameObserver::GetInstance()->ButtonPressed(this); + zone->owner->getObserver()->ButtonPressed(this); } bool GuiGameZone::CheckUserInput(JButton key) @@ -223,7 +222,7 @@ void GuiGameZone::Update(float dt) GuiGameZone::GuiGameZone(float x, float y, bool hasFocus, MTGGameZone* zone, GuiAvatars* parent) : GuiStatic(static_cast (GuiGameZone::Height), x, y, hasFocus, parent), zone(zone) { - cd = NEW CardDisplay(0, GameObserver::GetInstance(), static_cast (x), static_cast (y), this); + cd = NEW CardDisplay(0, zone->owner->getObserver(), static_cast (x), static_cast (y), this); cd->zone = zone; showCards = 0; } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 5901aa2ba..e0c57a157 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -61,34 +61,36 @@ const int kDynamicWhoIds[] = { int MTGAbility::allowedToCast(MTGCardInstance * card,Player * player) { - return AbilityFactory::parseCastRestrictions(card,player,card->getRestrictions()); + AbilityFactory af(game); + return af.parseCastRestrictions(card,player,card->getRestrictions()); } int MTGAbility::allowedToAltCast(MTGCardInstance * card,Player * player) { - return AbilityFactory::parseCastRestrictions(card,player,card->getOtherRestrictions()); + AbilityFactory af(game); + return af.parseCastRestrictions(card,player,card->getOtherRestrictions()); } int AbilityFactory::parseCastRestrictions(MTGCardInstance * card,Player * player,string restrictions) { vector restriction = split(restrictions, ','); - GameObserver * game = game->GetInstance(); - int cPhase = game->getCurrentGamePhase(); + AbilityFactory af(observer); + int cPhase = observer->getCurrentGamePhase(); for(unsigned int i = 0;i < restriction.size();i++) { int checkPhaseBased = parseRestriction(restriction[i]); switch (checkPhaseBased) { case MTGAbility::PLAYER_TURN_ONLY: - if (player != game->currentPlayer) + if (player != observer->currentPlayer) return 0; break; case MTGAbility::OPPONENT_TURN_ONLY: - if (player == game->currentPlayer) + if (player == observer->currentPlayer) return 0; break; case MTGAbility::AS_SORCERY: - if (player != game->currentPlayer) + if (player != observer->currentPlayer) return 0; if (cPhase != Constants::MTG_PHASE_FIRSTMAIN && cPhase != Constants::MTG_PHASE_SECONDMAIN) return 0; @@ -96,14 +98,14 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card,Player * player } if (checkPhaseBased >= MTGAbility::MY_BEFORE_BEGIN && checkPhaseBased <= MTGAbility::MY_AFTER_EOT) { - if (player != game->currentPlayer) + if (player != observer->currentPlayer) return 0; if (cPhase != checkPhaseBased - MTGAbility::MY_BEFORE_BEGIN + Constants::MTG_PHASE_BEFORE_BEGIN) return 0; } if (checkPhaseBased >= MTGAbility::OPPONENT_BEFORE_BEGIN && checkPhaseBased <= MTGAbility::OPPONENT_AFTER_EOT) { - if (player == game->currentPlayer) + if (player == observer->currentPlayer) return 0; if (cPhase != checkPhaseBased - MTGAbility::OPPONENT_BEFORE_BEGIN + Constants::MTG_PHASE_BEFORE_BEGIN) return 0; @@ -139,7 +141,7 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card,Player * player { end = comparasion[i].find(")", found); type = comparasion[i].substr(found + 5, end - found - 5).c_str(); - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * ttc = tcf.createTargetChooser(type,card); mod = atoi(comparasion[i].substr(end+1).c_str()); if(i == 2) @@ -179,7 +181,7 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card,Player * player size_t start = restriction[i].find(":", check); size_t end = restriction[i].find(" ", check); Turn = atoi(restriction[i].substr(start + 1, end - start - 1).c_str()); - if(game->turn < Turn-1) + if(observer->turn < Turn-1) return 0; } check = restriction[i].find("casted a spell"); @@ -222,7 +224,7 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card,Player * player bool isMorbid = false; for(int cp = 0;cp < 2;cp++) { - Player * checkCurrent = game->players[cp]; + Player * checkCurrent = observer->players[cp]; MTGGameZone * grave = checkCurrent->game->graveyard; for(unsigned int gy = 0;gy < grave->cardsSeenThisTurn.size();gy++) { @@ -323,12 +325,11 @@ int AbilityFactory::parseRestriction(string s) int AbilityFactory::countCards(TargetChooser * tc, Player * player, int option) { int result = 0; - GameObserver * game = GameObserver::GetInstance(); for (int i = 0; i < 2; i++) { - if (player && player != game->players[i]) + if (player && player != observer->players[i]) continue; - MTGGameZone * zones[] = { game->players[i]->game->inPlay, game->players[i]->game->graveyard, game->players[i]->game->hand }; + MTGGameZone * zones[] = { observer->players[i]->game->inPlay, observer->players[i]->game->graveyard, observer->players[i]->game->hand }; for (int k = 0; k < 3; k++) { for (int j = zones[k]->nb_cards - 1; j >= 0; j--) @@ -459,7 +460,7 @@ TargetChooser * AbilityFactory::parseSimpleTC(const std::string& s, const std::s } string starget = s.substr(start , end - start); - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * tc = tcf.createTargetChooser(starget, card); if (tc && forceNoTarget) @@ -492,7 +493,7 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string magicText, int { size_t end = s.find(")"); string starget = s.substr(found + 8, end - found - 8); - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser *toTc = NULL; TargetChooser *toTcCard = NULL; @@ -536,20 +537,20 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string magicText, int fromTc = tcf.createTargetChooser(starget, card); fromTc->targetter = NULL; //avoid protection from } - return NEW TrCardAddedToZone(id, card, (TargetZoneChooser *) toTc, toTcCard, (TargetZoneChooser *) fromTc, fromTcCard,once,sourceUntapped,isSuspended); + return NEW TrCardAddedToZone(observer, id, card, (TargetZoneChooser *) toTc, toTcCard, (TargetZoneChooser *) fromTc, fromTcCard,once,sourceUntapped,isSuspended); } //Card unTapped if (TargetChooser *tc = parseSimpleTC(s,"untapped", card)) - return NEW TrCardTapped(id, card, tc, false,once); + return NEW TrCardTapped(observer, id, card, tc, false,once); //Card Tapped if (TargetChooser *tc = parseSimpleTC(s,"tapped", card)) - return NEW TrCardTapped(id, card, tc, true,once); + return NEW TrCardTapped(observer, id, card, tc, true,once); //Card Tapped for mana if (TargetChooser *tc = parseSimpleTC(s,"tappedformana", card)) - return NEW TrCardTappedformana(id, card, tc, true,once); + return NEW TrCardTappedformana(observer, id, card, tc, true,once); //CombatTrigger //Card card attacked and is blocked @@ -585,69 +586,69 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string magicText, int TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrCombatTrigger(id, card, tc, fromTc,once,limitOnceATurn,sourceUntapped,opponentPoisoned, + return NEW TrCombatTrigger(observer, id, card, tc, fromTc,once,limitOnceATurn,sourceUntapped,opponentPoisoned, attackingTrigger,attackedAloneTrigger,notBlockedTrigger,attackBlockedTrigger,blockingTrigger); } //Card card is drawn if (TargetChooser * tc = parseSimpleTC(s, "drawn", card)) - return NEW TrcardDrawn(id, card, tc,once); + return NEW TrcardDrawn(observer, id, card, tc,once); //Card is sacrificed if (TargetChooser * tc = parseSimpleTC(s, "sacrificed", card)) - return NEW TrCardSacrificed(id, card, tc,once); + return NEW TrCardSacrificed(observer, id, card, tc,once); //Card is Discarded if (TargetChooser * tc = parseSimpleTC(s, "discarded", card)) - return NEW TrCardDiscarded(id, card, tc,once); + return NEW TrCardDiscarded(observer, id, card, tc,once); //Card Damaging non combat if (TargetChooser * tc = parseSimpleTC(s, "noncombatdamaged", card)) { TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrDamaged(id, card, tc, fromTc, 2,once); + return NEW TrDamaged(observer, id, card, tc, fromTc, 2,once); } //Card Damaging combat if (TargetChooser * tc = parseSimpleTC(s, "combatdamaged", card)) { TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrDamaged(id, card, tc, fromTc, 1,sourceUntapped,limitOnceATurn,once); + return NEW TrDamaged(observer, id, card, tc, fromTc, 1,sourceUntapped,limitOnceATurn,once); } //Card Damaging if (TargetChooser * tc = parseSimpleTC(s, "damaged", card)) { TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrDamaged(id, card, tc, fromTc, 0,sourceUntapped,limitOnceATurn,once); + return NEW TrDamaged(observer, id, card, tc, fromTc, 0,sourceUntapped,limitOnceATurn,once); } //Lifed if (TargetChooser * tc = parseSimpleTC(s, "lifed", card)) { TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrLifeGained(id, card, tc, fromTc, 0,sourceUntapped,once); + return NEW TrLifeGained(observer, id, card, tc, fromTc, 0,sourceUntapped,once); } //Life Loss if (TargetChooser * tc = parseSimpleTC(s, "lifeloss", card)) { TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrLifeGained(id, card, tc, fromTc,1,sourceUntapped,once); + return NEW TrLifeGained(observer, id, card, tc, fromTc,1,sourceUntapped,once); } //Card Damaged and killed by a creature this turn if (TargetChooser * tc = parseSimpleTC(s, "vampired", card)) { TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrVampired(id, card, tc, fromTc,once); + return NEW TrVampired(observer, id, card, tc, fromTc,once); } //when card becomes the target of a spell or ability if (TargetChooser * tc = parseSimpleTC(s, "targeted", card)) { TargetChooser *fromTc = parseSimpleTC(s, "from", card); - return NEW TrTargeted(id, card, tc, fromTc, 0,once); + return NEW TrTargeted(observer, id, card, tc, fromTc, 0,once); } if (s.find("counteradded(") != string::npos) @@ -655,7 +656,7 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string magicText, int vectorsplitCounter = parseBetween(s,"counteradded(",")"); Counter * counter = parseCounter(splitCounter[1],card,NULL); TargetChooser * tc = parseSimpleTC(s, "from", card); - return NEW TrCounter(id, card, counter, tc, 1,once); + return NEW TrCounter(observer, id, card, counter, tc, 1,once); } if (s.find("counterremoved(") != string::npos) @@ -663,7 +664,7 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string magicText, int vectorsplitCounter = parseBetween(s,"counterremoved(",")"); Counter * counter = parseCounter(splitCounter[1],card,NULL); TargetChooser * tc = parseSimpleTC(s, "from", card); - return NEW TrCounter(id, card, counter, tc, 0,once); + return NEW TrCounter(observer, id, card, counter, tc, 0,once); } int who = 0; @@ -683,7 +684,7 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string magicText, int found = s.find(Constants::MTGPhaseCodeNames[i]); if (found != string::npos) { - return NEW TriggerNextPhase(id, card, target, i, who,sourceUntapped,once); + return NEW TriggerNextPhase(observer, id, card, target, i, who,sourceUntapped,once); } } } @@ -697,7 +698,7 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string magicText, int found = s.find(Constants::MTGPhaseCodeNames[i]); if (found != string::npos) { - return NEW TriggerAtPhase(id, card, target, i, who,sourceUntapped,sourceTap,lifelost,lifeamount,once); + return NEW TriggerAtPhase(observer, id, card, target, i, who,sourceUntapped,sourceTap,lifelost,lifeamount,once); } } } @@ -788,7 +789,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG delete trigger; return NULL; } - return NEW GenericTriggeredAbility(id, card, trigger, a, NULL, target); + return NEW GenericTriggeredAbility(observer, id, card, trigger, a, NULL, target); } } @@ -799,14 +800,14 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitMsg.size()) { string msg = splitMsg[1]; - return NEW ATutorialMessage(card, msg); + return NEW ATutorialMessage(observer, card, msg); } splitMsg = parseBetween(s, "message(", ")"); if (splitMsg.size()) { string msg = splitMsg[1]; - return NEW ATutorialMessage(card, msg, 0); + return NEW ATutorialMessage(observer, card, msg, 0); } } @@ -842,7 +843,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitTarget.size()) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); tc = tcf.createTargetChooser(splitTarget[1], card); if (!isTarget) tc->targetter = NULL; @@ -921,7 +922,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG ae->setCost(cost); if (!tc) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); tc = tcf.createTargetChooser("creature|mybattlefield", card); } ae->setActionTC(tc); @@ -930,9 +931,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (tc) { tc->belongsToAbility = sWithoutTc; - return NEW GenericTargetAbility(newName,castRestriction,id, card, tc, a, cost, limit,sideEffect,usesBeforeSideEffect, restrictions, dest); + return NEW GenericTargetAbility(observer, newName,castRestriction,id, card, tc, a, cost, limit,sideEffect,usesBeforeSideEffect, restrictions, dest); } - return NEW GenericActivatedAbility(newName,castRestriction,id, card, a, cost, limit,sideEffect,usesBeforeSideEffect,restrictions, dest); + return NEW GenericActivatedAbility(observer, newName,castRestriction,id, card, a, cost, limit,sideEffect,usesBeforeSideEffect,restrictions, dest); } SAFE_DELETE(cost); } @@ -967,7 +968,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG string s1 = s.substr(s.find(" then ")+6); MTGAbility * a1 = parseMagicLine(s1, id, spell, card); if(!a1) return NULL; - MTGAbility * a = NEW IfThenAbility(id, a1, card,(Targetable*)target,checkIf[i],cond); + MTGAbility * a = NEW IfThenAbility(observer, id, a1, card,(Targetable*)target,checkIf[i],cond); a->canBeInterrupted = false; a->oneShot = true; if(tc) @@ -990,10 +991,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return NULL; if (tc) - a1 = NEW GenericTargetAbility(newName,castRestriction,id, card, tc, a1); + a1 = NEW GenericTargetAbility(observer, newName,castRestriction,id, card, tc, a1); else - a1 = NEW GenericActivatedAbility(newName,castRestriction,id, card, a1, NULL); - return NEW MayAbility(id, a1, card,mayMust[i]); + a1 = NEW GenericActivatedAbility(observer, newName,castRestriction,id, card, a1, NULL); + return NEW MayAbility(observer, id, a1, card,mayMust[i]); } } @@ -1005,7 +1006,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (!a1) return NULL; - return NEW GenericInstantAbility(1, card, (Damageable *) target, a1); + return NEW GenericInstantAbility(observer, 1, card, (Damageable *) target, a1); } //Upkeep Cost @@ -1026,7 +1027,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { SAFE_DELETE(tc); vector multiEffects = split(s,'&'); - MultiAbility * multi = NEW MultiAbility(id, card, target, NULL); + MultiAbility * multi = NEW MultiAbility(observer, id, card, target, NULL); for(unsigned int i = 0;i < multiEffects.size();i++) { if(!multiEffects[i].empty()) @@ -1089,7 +1090,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { string thisDescriptorString = s.substr(found + header, end - found - header); ThisDescriptorFactory tdf; - ThisDescriptor * td = tdf.createThisDescriptor(thisDescriptorString); + ThisDescriptor * td = tdf.createThisDescriptor(observer, thisDescriptorString); if (!td) { @@ -1127,10 +1128,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG switch (i) { case 0: - result = NEW AThis(id, card, _target, td, a); + result = NEW AThis(observer, id, card, _target, td, a); break; case 1: - result = NEW AThisForEach(id, card, _target, td, a); + result = NEW AThisForEach(observer, id, card, _target, td, a); break; default: result = NULL; @@ -1182,7 +1183,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG s1.replace(other, 6, ""); } string lordTargetsString = s.substr(found + header, end - found - header); - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * lordTargets = tcf.createTargetChooser(lordTargetsString, card); if (!lordTargets) @@ -1244,10 +1245,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG switch (i) { case 0: - result = NEW ALord(id, card, lordTargets, lordIncludeSelf, a); + result = NEW ALord(observer, id, card, lordTargets, lordIncludeSelf, a); break; case 1: - result = NEW AForeach(id, card, _target, lordTargets, lordIncludeSelf, a, mini, maxi); + result = NEW AForeach(observer, id, card, _target, lordTargets, lordIncludeSelf, a, mini, maxi); break; case 2: { @@ -1255,14 +1256,14 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { miniFound = true; } - result = NEW AAsLongAs(id, card, _target, lordTargets, lordIncludeSelf, a, mini, maxi, miniFound, maxiFound, compareZone); + result = NEW AAsLongAs(observer, id, card, _target, lordTargets, lordIncludeSelf, a, mini, maxi, miniFound, maxiFound, compareZone); } break; case 3: - result = NEW ATeach(id, card, lordTargets, lordIncludeSelf, a); + result = NEW ATeach(observer, id, card, lordTargets, lordIncludeSelf, a); break; case 4: - result = NEW ALord(id, card, lordTargets, lordIncludeSelf, a); + result = NEW ALord(observer, id, card, lordTargets, lordIncludeSelf, a); break; default: result = NULL; @@ -1285,8 +1286,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG DebugTrace("ABILITYFACTORY Error parsing: " << s); return NULL; } - a = NEW GenericTargetAbility(newName,castRestriction,id, card, tc, a); - return NEW MayAbility(id, a, card, true); + a = NEW GenericTargetAbility(observer, newName,castRestriction,id, card, tc, a); + return NEW MayAbility(observer, id, a, card, true); } SAFE_DELETE(tc); @@ -1350,7 +1351,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if(!sAbility.empty()) stored = parseMagicLine(sAbility, id, spell, card); - MTGAbility * a = NEW AADynamic(id, card, target,type,effect,who,amountsource,stored); + MTGAbility * a = NEW AADynamic(observer, id, card, target,type,effect,who,amountsource,stored); a->oneShot = 1; return a; } @@ -1371,7 +1372,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("cycling"); if (found != string::npos) { - MTGAbility * a = NEW ACycle(id, card, target); + MTGAbility * a = NEW ACycle(observer, id, card, target); a->oneShot = 1; return a; } @@ -1380,7 +1381,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("ninjutsu"); if (found != string::npos) { - MTGAbility * a = NEW ANinja(id, card, target); + MTGAbility * a = NEW ANinja(observer, id, card, target); a->oneShot = 1; return a; } @@ -1389,7 +1390,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("removefromcombat"); if (found != string::npos) { - MTGAbility * a = NEW ACombatRemoval(id, card, target); + MTGAbility * a = NEW ACombatRemoval(observer, id, card, target); a->oneShot = 1; return a; } @@ -1408,7 +1409,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { stored = parseMagicLine(sAbility, id, spell, card); } - MTGAbility * a = NEW ABlinkGeneric(id, card, target,ueoteffect,forsource,blinkhand,stored); + MTGAbility * a = NEW ABlinkGeneric(observer, id, card, target,ueoteffect,forsource,blinkhand,stored); a->oneShot = 1; return a; } @@ -1420,7 +1421,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG Spell * starget = NULL; if (spell) starget = spell->getNextSpellTarget(); - MTGAbility * a = NEW AAFizzler(id, card, starget); + MTGAbility * a = NEW AAFizzler(observer, id, card, starget); a->oneShot = 1; return a; } @@ -1459,9 +1460,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { MTGCard * safetycard = MTGCollection()->getCardById(tokenId); if (!safetycard) //Error, card not foudn in DB - return NEW ATokenCreator(id, card, target, NULL, "ID NOT FOUND", "ERROR ID",0, 0, "","", NULL,0); + return NEW ATokenCreator(observer, id, card, target, NULL, "ID NOT FOUND", "ERROR ID",0, 0, "","", NULL,0); - ATokenCreator * tok = NEW ATokenCreator(id, card,target, NULL, tokenId, starfound, multiplier, who); + ATokenCreator * tok = NEW ATokenCreator(observer, id, card,target, NULL, tokenId, starfound, multiplier, who); tok->oneShot = 1; return tok; } @@ -1496,7 +1497,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG parsePowerToughness(spt, &power, &toughness); ATokenCreator * tok = NEW ATokenCreator( - id, card,target, NULL, sname, stypes, power + value, toughness + value, + observer, id, card,target, NULL, sname, stypes, power + value, toughness + value, sabilities, starfound, multiplier, who, aLivingWeapon, spt); tok->oneShot = 1; if(aLivingWeapon) @@ -1508,14 +1509,14 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("equip"); if (found != string::npos) { - return NEW AEquip(id, card); + return NEW AEquip(observer, id, card); } //Equipment (attach) found = s.find("attach"); if (found != string::npos) { - return NEW AEquip(id, card, 0, ActivatedAbility::NO_RESTRICTION); + return NEW AEquip(observer, id, card, 0, ActivatedAbility::NO_RESTRICTION); } //MoveTo Move a card from a zone to another @@ -1527,7 +1528,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (card->hasType(Subtypes::TYPE_AURA)) target = card; - MTGAbility * a = NEW AAMover(id, card, target, splitMove[1]); + MTGAbility * a = NEW AAMover(observer, id, card, target, splitMove[1]); a->oneShot = 1; if(s.find("and(") != string::npos) { @@ -1544,7 +1545,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("copy"); if (found != string::npos) { - MTGAbility * a = NEW AACopier(id, card, target); + MTGAbility * a = NEW AACopier(observer, id, card, target); a->oneShot = 1; return a; } @@ -1553,7 +1554,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("phaseout"); if (found != string::npos) { - MTGAbility * a = NEW AAPhaseOut(id, card, target); + MTGAbility * a = NEW AAPhaseOut(observer, id, card, target); a->oneShot = 1; return a; } @@ -1568,7 +1569,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { with = splitWith[1]; } - MTGAbility * a = NEW AACloner(id, card, target, 0, who, with); + MTGAbility * a = NEW AACloner(observer, id, card, target, 0, who, with); a->oneShot = 1; return a; } @@ -1576,28 +1577,28 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //Bury, destroy, sacrifice, reject(discard) if (s.find("bury") != string::npos) { - MTGAbility *a = NEW AABuryCard(id, card, target); + MTGAbility *a = NEW AABuryCard(observer, id, card, target); a->oneShot = 1; return a; } if (s.find("destroy") != string::npos) { - MTGAbility * a = NEW AADestroyCard(id, card, target); + MTGAbility * a = NEW AADestroyCard(observer, id, card, target); a->oneShot = 1; return a; } if (s.find("sacrifice") != string::npos) { - MTGAbility *a = NEW AASacrificeCard(id, card, target); + MTGAbility *a = NEW AASacrificeCard(observer, id, card, target); a->oneShot = 1; return a; } if (s.find("reject") != string::npos) { - MTGAbility *a = NEW AADiscardCard(id, card, target); + MTGAbility *a = NEW AADiscardCard(observer, id, card, target); a->oneShot = 1; return a; } @@ -1635,9 +1636,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG MTGAbility * ab; if (forceUEOT || preventDamageForceOneShot[i]) - ab = NEW APreventDamageTypesUEOT(id, card, to, from, preventDamageTypes[i]); + ab = NEW APreventDamageTypesUEOT(observer, id, card, to, from, preventDamageTypes[i]); else - ab = NEW APreventDamageTypes(id, card, to, from, preventDamageTypes[i]); + ab = NEW APreventDamageTypes(observer, id, card, to, from, preventDamageTypes[i]); if (preventDamageForceOneShot[i]) ab->oneShot = 1; @@ -1650,7 +1651,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("resetdamage"); if (found != string::npos) { - MTGAbility * a = NEW AAResetDamage(id, card, target); + MTGAbility * a = NEW AAResetDamage(observer, id, card, target); a->oneShot = 1; return a; } @@ -1660,7 +1661,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitDamage.size()) { Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AADamager(id, card, t, splitDamage[1], NULL, who); + MTGAbility * a = NEW AADamager(observer, id, card, t, splitDamage[1], NULL, who); a->oneShot = 1; return a; } @@ -1671,7 +1672,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { int poison = atoi(splitPoison[1].c_str()); Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AAAlterPoison(id, card, t, poison, NULL, who); + MTGAbility * a = NEW AAAlterPoison(observer, id, card, t, poison, NULL, who); a->oneShot = 1; return a; } @@ -1682,7 +1683,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { int preventing = atoi(splitPrevent[1].c_str()); Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AADamagePrevent(id, card, t, preventing, NULL, who); + MTGAbility * a = NEW AADamagePrevent(observer, id, card, t, preventing, NULL, who); a->oneShot = 1; return a; } @@ -1693,7 +1694,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { int hand = atoi(splitSetHand[1].c_str()); Damageable * t = spell ? spell->getNextDamageableTarget() : NULL; - MTGAbility * a = NEW AASetHand(id, card, t, hand, NULL, who); + MTGAbility * a = NEW AASetHand(observer, id, card, t, hand, NULL, who); a->oneShot = 1; return a; } @@ -1704,7 +1705,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { WParsedInt * life = NEW WParsedInt(splitLifeset[1], spell, card); Damageable * t = spell ? spell->getNextDamageableTarget() : NULL; - MTGAbility * a = NEW AALifeSet(id, card, t, life, NULL, who); + MTGAbility * a = NEW AALifeSet(observer, id, card, t, life, NULL, who); a->oneShot = 1; return a; } @@ -1714,7 +1715,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitLife.size()) { Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AALifer(id, card, t, splitLife[1], NULL, who); + MTGAbility * a = NEW AALifer(observer, id, card, t, splitLife[1], NULL, who); a->oneShot = 1; return a; } @@ -1724,7 +1725,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (found != string::npos) { Damageable * d = spell ? spell->getNextDamageableTarget() : NULL; - MTGAbility * a = NEW AAWinGame(id, card, d, NULL, who); + MTGAbility * a = NEW AAWinGame(observer, id, card, d, NULL, who); a->oneShot = 1; return a; } @@ -1734,7 +1735,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitDraw.size()) { Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AADrawer(id, card, t, NULL,splitDraw[1], who); + MTGAbility * a = NEW AADrawer(observer, id, card, t, NULL,splitDraw[1], who); a->oneShot = 1; return a; } @@ -1744,7 +1745,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitDeplete.size()) { Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AADepleter(id, card, t , splitDeplete[1], NULL, who); + MTGAbility * a = NEW AADepleter(observer, id, card, t , splitDeplete[1], NULL, who); a->oneShot = 1; return a; } @@ -1754,7 +1755,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (found != string::npos) { Targetable * t = spell? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AAShuffle(id, card, t, NULL, who); + MTGAbility * a = NEW AAShuffle(observer, id, card, t, NULL, who); a->oneShot = 1; return a; } @@ -1764,7 +1765,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitRemove.size()) { Targetable * t = spell? spell->getNextTarget() : NULL; - MTGAbility *a = NEW AARemoveMana(id, card, t, splitRemove[1], who); + MTGAbility *a = NEW AARemoveMana(observer, id, card, t, splitRemove[1], who); a->oneShot = 1; return a; } @@ -1774,7 +1775,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitLoseTypes.size()) { int parentType = Subtypes::subtypesList->find(splitLoseTypes[1]); - return NEW ALoseSubtypes(id, card, target, parentType); + return NEW ALoseSubtypes(observer, id, card, target, parentType); } //Cast/Play Restrictions @@ -1783,7 +1784,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG vector splitCast = parseBetween(s, kMaxCastKeywords[i], ")"); if (splitCast.size()) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * castTargets = tcf.createTargetChooser(splitCast[1], card); vector splitValue = parseBetween(splitCast[2], "", " ", false); @@ -1800,9 +1801,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG Targetable * t = spell? spell->getNextTarget() : NULL; if (card->hasType(Subtypes::TYPE_INSTANT) || card->hasType(Subtypes::TYPE_SORCERY) || forceUEOT) { - return NEW AInstantCastRestrictionUEOT(id, card, t, castTargets, value, modifyExisting, kMaxCastZones[i], who); + return NEW AInstantCastRestrictionUEOT(observer, id, card, t, castTargets, value, modifyExisting, kMaxCastZones[i], who); } - return NEW ACastRestriction(id, card, t, castTargets, value, modifyExisting, kMaxCastZones[i], who); + return NEW ACastRestriction(observer, id, card, t, castTargets, value, modifyExisting, kMaxCastZones[i], who); } } @@ -1811,7 +1812,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitDiscard.size()) { Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AARandomDiscarder(id, card, t, splitDiscard[1], NULL, who); + MTGAbility * a = NEW AARandomDiscarder(observer, id, card, t, splitDiscard[1], NULL, who); a->oneShot = 1; return a; } @@ -1828,13 +1829,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return NULL; } int MaxOpponent = atoi(rampageParameters[1].c_str()); - return NEW ARampageAbility(id, card, power, toughness, MaxOpponent); + return NEW ARampageAbility(observer, id, card, power, toughness, MaxOpponent); } //flanking if (s.find("flanker") != string::npos) { - return NEW AFlankerAbility(id, card); + return NEW AFlankerAbility(observer, id, card); } //spirit link @@ -1842,7 +1843,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (s.find("spiritlink") != string::npos) { bool combatOnly = (s.find("combatspiritlink") != string::npos); - return NEW ASpiritLinkAbility(id, card, combatOnly); + return NEW ASpiritLinkAbility(observer, id, card, combatOnly); } //bushido @@ -1855,13 +1856,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG DebugTrace("MTGAbility Parse error in bushido" << s); return NULL; } - return NEW ABushidoAbility(id, card, power, toughness); + return NEW ABushidoAbility(observer, id, card, power, toughness); } //loseAbilities if (s.find("loseabilities") != string::npos) { - return NEW ALoseAbilities(id, card, target); + return NEW ALoseAbilities(observer, id, card, target); } //counter @@ -1877,7 +1878,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } MTGAbility * a = - NEW AACounter(id, card, target,counterString, counter->name.c_str(), counter->power, counter->toughness, counter->nb,counter->maxNb); + NEW AACounter(observer, id, card, target,counterString, counter->name.c_str(), counter->power, counter->toughness, counter->nb,counter->maxNb); delete (counter); a->oneShot = 1; return a; @@ -1902,7 +1903,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return NULL; } } - MTGAbility * a = NEW ACounterShroud(id, card, target,counter); + MTGAbility * a = NEW ACounterShroud(observer, id, card, target,counter); return a; } //use counters to track by counters to track an efect by counter name. @@ -1910,7 +1911,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitCounterTracking.size()) { string splitCounterTrack = splitCounterTracking[1]; - return NEW ACounterTracker(id, card, target,splitCounterTrack); + return NEW ACounterTracker(observer, id, card, target,splitCounterTrack); } //removes all counters of the specifified type. vector splitRemoveCounter = parseBetween(s, "removeallcounters(", ")"); @@ -1919,7 +1920,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG string counterString = splitRemoveCounter[1]; if(counterString.find("all") != string::npos) { - MTGAbility * a = NEW AARemoveAllCounter(id, card, target, "All", 0, 0, 1, true); + MTGAbility * a = NEW AARemoveAllCounter(observer, id, card, target, "All", 0, 0, 1, true); a->oneShot = 1; return a; } @@ -1932,7 +1933,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } MTGAbility * a = - NEW AARemoveAllCounter(id, card, target, counter->name.c_str(), counter->power, counter->toughness, counter->nb,false); + NEW AARemoveAllCounter(observer, id, card, target, counter->name.c_str(), counter->power, counter->toughness, counter->nb,false); delete (counter); a->oneShot = 1; return a; @@ -1965,30 +1966,30 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } } if (oneShot || forceUEOT || forceForever) - return NEW ATransformerInstant(id, card, target, stypes, sabilities,newPower,ptFound,newToughness,ptFound,vector(),false,forceForever); + return NEW ATransformerInstant(observer, id, card, target, stypes, sabilities,newPower,ptFound,newToughness,ptFound,vector(),false,forceForever); - return NEW ATransformer(id, card, target, stypes, sabilities,newPower,ptFound,newToughness,ptFound,vector(),false,forceForever); + return NEW ATransformer(observer, id, card, target, stypes, sabilities,newPower,ptFound,newToughness,ptFound,vector(),false,forceForever); } //bloodthirst vector splitBloodthirst = parseBetween(s, "bloodthirst:", " ", false); if (splitBloodthirst.size()) { - return NEW ABloodThirst(id, card, target, atoi(splitBloodthirst[1].c_str())); + return NEW ABloodThirst(observer, id, card, target, atoi(splitBloodthirst[1].c_str())); } //Vanishing vector splitVanishing = parseBetween(s, "vanishing:", " ", false); if (splitVanishing.size()) { - return NEW AVanishing(id, card, NULL, restrictions, atoi(splitVanishing[1].c_str()), "time"); + return NEW AVanishing(observer, id, card, NULL, restrictions, atoi(splitVanishing[1].c_str()), "time"); } //Fading vector splitFading = parseBetween(s, "fading:", " ", false); if (splitFading.size()) { - return NEW AVanishing(id, card, NULL, restrictions, atoi(splitFading[1].c_str()), "fade"); + return NEW AVanishing(observer, id, card, NULL, restrictions, atoi(splitFading[1].c_str()), "fade"); } //Alter cost @@ -2059,9 +2060,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } if (oneShot || forceUEOT || forceForever) - return NEW ATransformerInstant(id, card, target, stypes, sabilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound,forceForever); + return NEW ATransformerInstant(observer, id, card, target, stypes, sabilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound,forceForever); - return NEW ATransformer(id, card, target, stypes, sabilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound); + return NEW ATransformer(observer, id, card, target, stypes, sabilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound); } @@ -2076,11 +2077,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { if (card->hasType(Subtypes::TYPE_INSTANT) || card->hasType(Subtypes::TYPE_SORCERY) || forceUEOT) { - return NEW PTInstant(id, card, target, wppt,s,nonstatic); + return NEW PTInstant(observer, id, card, target, wppt,s,nonstatic); } - return NEW APowerToughnessModifier(id, card, target, wppt,s,nonstatic); + return NEW APowerToughnessModifier(observer, id, card, target, wppt,s,nonstatic); } - return NEW PTInstant(id, card, target, wppt,s,nonstatic); + return NEW PTInstant(observer, id, card, target, wppt,s,nonstatic); } else { @@ -2093,7 +2094,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { ManaCost * output = ManaCost::parseManaCost(s.substr(found)); Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AManaProducer(id, card, t, output, NULL, who); + MTGAbility * a = NEW AManaProducer(observer, id, card, t, output, NULL, who); a->oneShot = 1; if(newName.size()) ((AManaProducer*)a)->menutext = newName; @@ -2104,7 +2105,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG vector splitProtection = parseBetween(s, "protection from(", ")"); if (splitProtection.size()) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * fromTc = tcf.createTargetChooser(splitProtection[1], card); if (!fromTc) return NULL; @@ -2115,7 +2116,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { return NULL; //TODO } - return NEW AProtectionFrom(id, card, target, fromTc, splitProtection[1]); + return NEW AProtectionFrom(observer, id, card, target, fromTc, splitProtection[1]); } return NULL; //TODO } @@ -2124,7 +2125,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG vector splitCantTarget = parseBetween(s, "cantbetargetof(", ")"); if (splitCantTarget.size()) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * fromTc = tcf.createTargetChooser(splitCantTarget[1], card); if (!fromTc) return NULL; @@ -2135,7 +2136,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { return NULL; //TODO } - return NEW ACantBeTargetFrom(id, card, target, fromTc); + return NEW ACantBeTargetFrom(observer, id, card, target, fromTc); } return NULL; //TODO } @@ -2144,7 +2145,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG vector splitCantBlock = parseBetween(s, "cantbeblockedby(", ")"); if (splitCantBlock.size()) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(observer); TargetChooser * fromTc = tcf.createTargetChooser(splitCantBlock[1], card); if (!fromTc) return NULL; @@ -2155,7 +2156,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { return NULL; //TODO } - return NEW ACantBeBlockedBy(id, card, target, fromTc); + return NEW ACantBeBlockedBy(observer, id, card, target, fromTc); } return NULL; //TODO } @@ -2164,7 +2165,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("proliferate"); if (found != string::npos) { - MTGAbility * a = NEW AAProliferate(id, card, target); + MTGAbility * a = NEW AAProliferate(observer, id, card, target); a->oneShot = 1; a->canBeInterrupted = false; return a; @@ -2174,7 +2175,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("frozen"); if (found != string::npos) { - MTGAbility * a = NEW AAFrozen(id, card, target); + MTGAbility * a = NEW AAFrozen(observer, id, card, target); a->oneShot = 1; return a; } @@ -2182,7 +2183,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //get a new target if ((s.find("retarget") != string::npos) || s.find("newtarget") != string::npos) { - MTGAbility * a = NEW AANewTarget(id, card,target, (s.find("retarget") != string::npos)); + MTGAbility * a = NEW AANewTarget(observer, id, card,target, (s.find("retarget") != string::npos)); a->oneShot = 1; return a; } @@ -2191,7 +2192,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("morph"); if (found != string::npos) { - MTGAbility * a = NEW AAMorph(id, card, target); + MTGAbility * a = NEW AAMorph(observer, id, card, target); a->oneShot = 1; return a; } @@ -2200,7 +2201,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG vector splitMaxlevel = parseBetween(s, "maxlevel:", " ", false); if (splitMaxlevel.size()) { - MTGAbility * a = NEW AAWhatsMax(id, card, card, NULL, atoi(splitMaxlevel[1].c_str())); + MTGAbility * a = NEW AAWhatsMax(observer, id, card, card, NULL, atoi(splitMaxlevel[1].c_str())); a->oneShot = 1; return a; } @@ -2209,7 +2210,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("swap"); if (found != string::npos) { - MTGAbility * a = NEW ASwapPTUEOT(id, card, target); + MTGAbility * a = NEW ASwapPTUEOT(observer, id, card, target); a->oneShot = 1; return a; } @@ -2218,7 +2219,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("regenerate"); if (found != string::npos) { - MTGAbility * a = NEW AStandardRegenerate(id, card, target); + MTGAbility * a = NEW AStandardRegenerate(observer, id, card, target); a->oneShot = 1; return a; } @@ -2244,11 +2245,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { if (card->hasType(Subtypes::TYPE_INSTANT) || card->hasType(Subtypes::TYPE_SORCERY) || forceUEOT) { - return NEW AInstantBasicAbilityModifierUntilEOT(id, card, target, j, modifier); + return NEW AInstantBasicAbilityModifierUntilEOT(observer, id, card, target, j, modifier); } - return NEW ABasicAbilityModifier(id, card, target, j, modifier); + return NEW ABasicAbilityModifier(observer, id, card, target, j, modifier); } - return NEW ABasicAbilityAuraModifierUntilEOT(id, card, target, NULL, j, modifier); + return NEW ABasicAbilityAuraModifierUntilEOT(observer, id, card, target, NULL, j, modifier); } } @@ -2256,7 +2257,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("untap"); if (found != string::npos) { - MTGAbility * a = NEW AAUntapper(id, card, target); + MTGAbility * a = NEW AAUntapper(observer, id, card, target); a->oneShot = 1; return a; } @@ -2265,7 +2266,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("tap"); if (found != string::npos) { - MTGAbility * a = NEW AATapper(id, card, target); + MTGAbility * a = NEW AATapper(observer, id, card, target); a->oneShot = 1; return a; } @@ -2274,16 +2275,15 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("connectrule"); if(found != string::npos) { - GameObserver * game = GameObserver::GetInstance(); - game->addObserver(NEW ParentChildRule(-1)); - game->connectRule = true; + observer->addObserver(NEW ParentChildRule(observer, -1)); + observer->connectRule = true; return NULL; } //create an association between cards. found = s.find("connect"); if (found != string::npos) { - MTGAbility * a = NEW AAConnect(id, card, target); + MTGAbility * a = NEW AAConnect(observer, id, card, target); a->oneShot = 1; return a; } @@ -2339,7 +2339,7 @@ MTGAbility * AbilityFactory::parseUpkeepAbility(string s,MTGCardInstance * card, delete (cost); return NULL; } - return NEW AUpkeep(id, card, a, cost, restrictions, phase, once,Cumulative);; + return NEW AUpkeep(observer, id, card, a, cost, restrictions, phase, once,Cumulative);; } MTGAbility * AbilityFactory::parsePhaseActionAbility(string s,MTGCardInstance * card,Spell * spell,MTGCardInstance * target, int restrictions,int id) @@ -2373,7 +2373,7 @@ MTGAbility * AbilityFactory::parsePhaseActionAbility(string s,MTGCardInstance * _target = spell->getNextCardTarget(); if(!_target) _target = target; - return NEW APhaseActionGeneric(id, card,_target, trim(splitActions[2]), restrictions, phase,sourceinPlay,next,myturn,opponentturn,once); + return NEW APhaseActionGeneric(observer, id, card,_target, trim(splitActions[2]), restrictions, phase,sourceinPlay,next,myturn,opponentturn,once); } //Tells the AI if the ability should target itself or an ennemy @@ -2542,10 +2542,10 @@ int AbilityFactory::getAbilities(vector * v, Spell * spell, MTGCar { card->graveEffects = false; card->exileEffects = false; - GameObserver * g = GameObserver::GetInstance(); + for (int i = 0; i < 2; ++i) { - MTGPlayerCards * zones = g->players[i]->game; + MTGPlayerCards * zones = observer->players[i]->game; if (dest == zones->hand) { magicText = card->magicTexts["hand"]; @@ -2768,7 +2768,6 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) } _id = magicText(_id, spell); - GameObserver * game = GameObserver::GetInstance(); MTGPlayerCards * zones = card->controller()->game; int id = card->alias; @@ -2776,14 +2775,14 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) { case 1092: //Aladdin's lamp { - AAladdinsLamp * ability = NEW AAladdinsLamp(_id, card); - game->addObserver(ability); + AAladdinsLamp * ability = NEW AAladdinsLamp(observer, _id, card); + observer->addObserver(ability); break; } case 1095: //Armageddon clock { - AArmageddonClock * ability = NEW AArmageddonClock(_id, card); - game->addObserver(ability); + AArmageddonClock * ability = NEW AArmageddonClock(observer, _id, card); + observer->addObserver(ability); break; } @@ -2796,7 +2795,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) else { Spell * starget = spell->getNextSpellTarget(); - game->mLayers->stackLayer()->Fizzle(starget); + observer->mLayers->stackLayer()->Fizzle(starget); } break; } @@ -2815,40 +2814,40 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) } case 1335: //Circle of protection : black { - game->addObserver(NEW ACircleOfProtection(_id, card, Constants::MTG_COLOR_BLACK)); + observer->addObserver(NEW ACircleOfProtection(observer, _id, card, Constants::MTG_COLOR_BLACK)); break; } case 1336: //Circle of protection : blue { - game->addObserver(NEW ACircleOfProtection(_id, card, Constants::MTG_COLOR_BLUE)); + observer->addObserver(NEW ACircleOfProtection(observer, _id, card, Constants::MTG_COLOR_BLUE)); break; } case 1337: //Circle of protection : green { - game->addObserver(NEW ACircleOfProtection(_id, card, Constants::MTG_COLOR_GREEN)); + observer->addObserver(NEW ACircleOfProtection(observer, _id, card, Constants::MTG_COLOR_GREEN)); break; } case 1338: //Circle of protection : red { - game->addObserver(NEW ACircleOfProtection(_id, card, Constants::MTG_COLOR_RED)); + observer->addObserver(NEW ACircleOfProtection(observer, _id, card, Constants::MTG_COLOR_RED)); break; } case 1339: //Circle of protection : white { - game->addObserver(NEW ACircleOfProtection(_id, card, Constants::MTG_COLOR_WHITE)); + observer->addObserver(NEW ACircleOfProtection(observer, _id, card, Constants::MTG_COLOR_WHITE)); break; } case 1102: //Conservator { - game->addObserver(NEW AConservator(_id, card)); + observer->addObserver(NEW AConservator(observer, _id, card)); break; } case 1103: //Crystal Rod { int8_t cost[] = { Constants::MTG_COLOR_ARTIFACT, 1 }; - ASpellCastLife* ability = NEW ASpellCastLife(_id, card, Constants::MTG_COLOR_BLUE, NEW ManaCost(cost, 1), 1); - game->addObserver(ability); + ASpellCastLife* ability = NEW ASpellCastLife(observer, _id, card, Constants::MTG_COLOR_BLUE, NEW ManaCost(cost, 1), 1); + observer->addObserver(ability); break; } case 1152: //Deathlace @@ -2867,42 +2866,42 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) case 1345: //Farmstead { - game->addObserver(NEW AFarmstead(_id, card, card->target)); + observer->addObserver(NEW AFarmstead(observer, _id, card, card->target)); break; } case 1291: //Fireball { int x = computeX(spell, card); - game->addObserver(NEW AFireball(_id, card, spell, x)); + observer->addObserver(NEW AFireball(observer, _id, card, spell, x)); break; } case 1113: //Iron Star { int8_t cost[] = { Constants::MTG_COLOR_ARTIFACT, 1 }; - ASpellCastLife* ability = NEW ASpellCastLife(_id, card, Constants::MTG_COLOR_RED, NEW ManaCost(cost, 1), 1); - game->addObserver(ability); + ASpellCastLife* ability = NEW ASpellCastLife(observer, _id, card, Constants::MTG_COLOR_RED, NEW ManaCost(cost, 1), 1); + observer->addObserver(ability); break; } case 1351: // Island Sanctuary { - game->addObserver(NEW AIslandSanctuary(_id, card)); + observer->addObserver(NEW AIslandSanctuary(observer, _id, card)); break; } case 1114: //Ivory cup { int8_t cost[] = { Constants::MTG_COLOR_ARTIFACT, 1 }; - ASpellCastLife* ability = NEW ASpellCastLife(_id, card, Constants::MTG_COLOR_WHITE, NEW ManaCost(cost, 1), 1); - game->addObserver(ability); + ASpellCastLife* ability = NEW ASpellCastLife(observer, _id, card, Constants::MTG_COLOR_WHITE, NEW ManaCost(cost, 1), 1); + observer->addObserver(ability); break; } case 1117: //Jandors Ring { - game->addObserver(NEW AJandorsRing(_id, card)); + observer->addObserver(NEW AJandorsRing(observer, _id, card)); break; } case 1254: //Kudzu { - game->addObserver(NEW AKudzu(id, card, card->target)); + observer->addObserver(NEW AKudzu(observer, id, card, card->target)); break; } case 1257: //Lifelace @@ -2920,12 +2919,12 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) } case 1124: //Mana Vault (the rest is softcoded!) { - game->addObserver(NEW ARegularLifeModifierAura(_id + 2, card, card, Constants::MTG_PHASE_DRAW, -1, 1)); + observer->addObserver(NEW ARegularLifeModifierAura(observer, _id + 2, card, card, Constants::MTG_PHASE_DRAW, -1, 1)); break; } case 1215: //Power Leak { - game->addObserver(NEW APowerLeak(_id, card, card->target)); + observer->addObserver(NEW APowerLeak(observer, _id, card, card->target)); break; } case 1358: //Purelace @@ -2950,36 +2949,36 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) else { Spell * starget = spell->getNextSpellTarget(); - game->mLayers->stackLayer()->Fizzle(starget); + observer->mLayers->stackLayer()->Fizzle(starget); } break; } case 1139: //The Rack { - game->addObserver(NEW ALifeZoneLink(_id, card, Constants::MTG_PHASE_UPKEEP, -3)); + observer->addObserver(NEW ALifeZoneLink(observer, _id, card, Constants::MTG_PHASE_UPKEEP, -3)); break; } case 1140: //Throne of Bone { int8_t cost[] = { Constants::MTG_COLOR_ARTIFACT, 1 }; - ASpellCastLife* ability = NEW ASpellCastLife(_id, card, Constants::MTG_COLOR_BLACK, NEW ManaCost(cost, 1), 1); - game->addObserver(ability); + ASpellCastLife* ability = NEW ASpellCastLife(observer, _id, card, Constants::MTG_COLOR_BLACK, NEW ManaCost(cost, 1), 1); + observer->addObserver(ability); break; } case 1142: //Wooden Sphere { int8_t cost[] = { Constants::MTG_COLOR_ARTIFACT, 1 }; - ASpellCastLife* ability = NEW ASpellCastLife(_id, card, Constants::MTG_COLOR_GREEN, NEW ManaCost(cost, 1), 1); - game->addObserver(ability); + ASpellCastLife* ability = NEW ASpellCastLife(observer, _id, card, Constants::MTG_COLOR_GREEN, NEW ManaCost(cost, 1), 1); + observer->addObserver(ability); break; } case 1143: //Animate Dead { - AAnimateDead * a = NEW AAnimateDead(_id, card, card->target); - game->addObserver(a); + AAnimateDead * a = NEW AAnimateDead(observer, _id, card, card->target); + observer->addObserver(a); card->target = ((MTGCardInstance *) a->target); break; } @@ -2987,16 +2986,16 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) { Damageable * target = spell->getNextDamageableTarget(); int x = spell->cost->getConvertedCost() - 2; //TODO Fix that !!! + X should be only black mana, that needs to be checked ! - game->mLayers->stackLayer()->addDamage(card, target, x); + observer->mLayers->stackLayer()->addDamage(card, target, x); if (target->life < x) x = target->life; - game->currentlyActing()->gainLife(x); + observer->currentlyActing()->gainLife(x); break; } case 1159: //Erg Raiders { - AErgRaiders* ability = NEW AErgRaiders(_id, card); - game->addObserver(ability); + AErgRaiders* ability = NEW AErgRaiders(observer, _id, card); + observer->addObserver(ability); break; } case 1202: //Hurkyl's Recall @@ -3006,7 +3005,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) { for (int i = 0; i < 2; i++) { - MTGInPlay * inplay = game->players[i]->game->inPlay; + MTGInPlay * inplay = observer->players[i]->game->inPlay; for (int j = inplay->nb_cards - 1; j >= 0; j--) { MTGCardInstance * card = inplay->cards[j]; @@ -3040,14 +3039,14 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) int xCost = computeX(spell, card); for (int i = 0; i < xCost; i++) { - game->opponent()->game->discardRandom(game->opponent()->game->hand, card); + observer->opponent()->game->discardRandom(observer->opponent()->game->hand, card); } break; } case 1176: //Sacrifice { - ASacrifice * ability = NEW ASacrifice(_id, card, card->target); - game->addObserver(ability); + ASacrifice * ability = NEW ASacrifice(observer, _id, card, card->target); + observer->addObserver(ability); break; } case 1224: //Spell Blast @@ -3057,13 +3056,13 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) if (starget) { if (starget->cost->getConvertedCost() <= x) - game->mLayers->stackLayer()->Fizzle(starget); + observer->mLayers->stackLayer()->Fizzle(starget); } break; } case 1194: //Control Magic { - game->addObserver(NEW AControlStealAura(_id, card, card->target)); + observer->addObserver(NEW AControlStealAura(observer, _id, card, card->target)); break; } case 1231: //Volcanic Eruption @@ -3080,13 +3079,13 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) x -= _x; for (int i = 0; i < 2; i++) { - game->mLayers->stackLayer()->addDamage(card, game->players[i], x); - for (int j = 0; j < game->players[i]->game->inPlay->nb_cards; j++) + observer->mLayers->stackLayer()->addDamage(card, observer->players[i], x); + for (int j = 0; j < observer->players[i]->game->inPlay->nb_cards; j++) { - MTGCardInstance * current = game->players[i]->game->inPlay->cards[j]; + MTGCardInstance * current = observer->players[i]->game->inPlay->cards[j]; if (current->isCreature()) { - game->mLayers->stackLayer()->addDamage(card, current, x); + observer->mLayers->stackLayer()->addDamage(card, current, x); } } } @@ -3094,7 +3093,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) } case 1288: //EarthBind { - game->addObserver(NEW AEarthbind(_id, card, card->target)); + observer->addObserver(NEW AEarthbind(observer, _id, card, card->target)); break; } case 1344: //Eye for an Eye @@ -3102,18 +3101,18 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) Damage * damage = spell->getNextDamageTarget(); if (damage) { - game->mLayers->stackLayer()->addDamage(card, damage->source->controller(), damage->damage); + observer->mLayers->stackLayer()->addDamage(card, damage->source->controller(), damage->damage); } break; } case 1243: //Fastbond { - game->addObserver(NEW AFastbond(_id, card)); + observer->addObserver(NEW AFastbond(observer, _id, card)); break; } case 1225: //Stasis { - game->addObserver(NEW AStasis(_id, card)); + observer->addObserver(NEW AStasis(observer, _id, card)); break; } case 1227: //Toughtlace @@ -3133,13 +3132,13 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) case 2474: //Minion of Leshrac { - game->addObserver(NEW AMinionofLeshrac(_id, card)); + observer->addObserver(NEW AMinionofLeshrac(observer, _id, card)); break; } case 2732: //Kjeldoran Frostbeast { - game->addObserver(NEW AKjeldoranFrostbeast(_id, card)); + observer->addObserver(NEW AKjeldoranFrostbeast(observer, _id, card)); break; } @@ -3147,15 +3146,14 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) case 3410: //Seed of Innocence { - GameObserver * game = GameObserver::GetInstance(); for (int i = 0; i < 2; i++) { - for (int j = 0; j < game->players[i]->game->inPlay->nb_cards; j++) + for (int j = 0; j < observer->players[i]->game->inPlay->nb_cards; j++) { - MTGCardInstance * current = game->players[i]->game->inPlay->cards[j]; + MTGCardInstance * current = observer->players[i]->game->inPlay->cards[j]; if (current->hasType("Artifact")) { - game->players[i]->game->putInGraveyard(current); + observer->players[i]->game->putInGraveyard(current); current->controller()->gainLife(current->getManaCost()->getConvertedCost()); } } @@ -3167,7 +3165,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) case 129767: //Threaten { - game->addObserver(NEW AInstantControlSteal(_id, card, card->target)); + observer->addObserver(NEW AInstantControlSteal(observer, _id, card, card->target)); break; } @@ -3187,7 +3185,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) case 135215: //Sylvan Basilisk { - game->addObserver(NEW ABasilik(_id, card)); + observer->addObserver(NEW ABasilik(observer, _id, card)); break; } case 130553:// Beacon of Immortality @@ -3211,7 +3209,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) Player * p = spell->getNextPlayerTarget(); MTGHand * hand = p->game->hand; int damage = hand->nb_cards; - game->mLayers->stackLayer()->addDamage(card, target, damage); + observer->mLayers->stackLayer()->addDamage(card, target, damage); break; } case 130369: // Soulblast @@ -3227,7 +3225,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) damage += current->power; } } - game->mLayers->stackLayer()->addDamage(card, target, damage); + observer->mLayers->stackLayer()->addDamage(card, target, damage); break; } @@ -3259,7 +3257,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) if (library->nb_cards) player->game->putInZone(library->cards[library->nb_cards - 1], library, player->game->graveyard); } - game->currentlyActing()->gainLife(x); + observer->currentlyActing()->gainLife(x); break; } @@ -3277,12 +3275,12 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) if (card->basicAbilities[(int)Constants::EXALTED]) { - game->addObserver(NEW AExalted(_id, card)); + observer->addObserver(NEW AExalted(observer, _id, card)); } if (card->basicAbilities[(int)Constants::FLANKING]) { - game->addObserver(NEW AFlankerAbility(_id, card)); + observer->addObserver(NEW AFlankerAbility(observer, _id, card)); } const int HomeAbilities[] = {(int)Constants::FORESTHOME, (int)Constants::ISLANDHOME, (int)Constants::MOUNTAINHOME, (int)Constants::SWAMPHOME, (int)Constants::PLAINSHOME}; @@ -3291,7 +3289,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell) for (unsigned int i = 0; i < sizeof(HomeAbilities)/sizeof(HomeAbilities[0]); ++i) { if (card->basicAbilities[HomeAbilities[i]]) - game->addObserver(NEW AStrongLandLinkCreature(_id, card, HomeLands[i])); + observer->addObserver(NEW AStrongLandLinkCreature(observer, _id, card, HomeLands[i])); } if(card->previous && card->previous->previous && card->previous->previous->suspended) @@ -3342,7 +3340,7 @@ MTGAbility * AbilityFactory::getManaReduxAbility(string s, int id, Spell *spell, } // figure out the mana cost int amount = atoi(manaCost.c_str()); - return NEW AAlterCost(id, card, target, amount, color); + return NEW AAlterCost(observer, id, card, target, amount, color); } MTGAbility::MTGAbility(const MTGAbility& a): ActionElement(a) @@ -3381,10 +3379,10 @@ MTGAbility::MTGAbility(const MTGAbility& a): ActionElement(a) }; -MTGAbility::MTGAbility(int id, MTGCardInstance * card) : +MTGAbility::MTGAbility(GameObserver* observer, int id, MTGCardInstance * card) : ActionElement(id) { - game = GameObserver::GetInstance(); + game = observer; source = card; target = card; aType = MTGAbility::UNKNOWN; @@ -3394,10 +3392,10 @@ MTGAbility::MTGAbility(int id, MTGCardInstance * card) : canBeInterrupted = true; } -MTGAbility::MTGAbility(int id, MTGCardInstance * _source, Targetable * _target) : +MTGAbility::MTGAbility(GameObserver* observer, int id, MTGCardInstance * _source, Targetable * _target) : ActionElement(id) { - game = GameObserver::GetInstance(); + game = observer; source = _source; target = _target; aType = MTGAbility::UNKNOWN; @@ -3431,20 +3429,19 @@ MTGAbility::~MTGAbility() int MTGAbility::addToGame() { - GameObserver::GetInstance()->addObserver(this); + game->addObserver(this); return 1; } int MTGAbility::removeFromGame() { - GameObserver::GetInstance()->removeObserver(this); + game->addObserver(this); return 1; } //returns 1 if this ability needs to be removed from the list of active abilities int MTGAbility::testDestroy() { -GameObserver * g=g->GetInstance(); if (game->mLayers->stackLayer()->has(this)) return 0; if (waitingForAnswer) @@ -3512,8 +3509,8 @@ NestedAbility::NestedAbility(MTGAbility * _ability) // -ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _cost, int restrictions,string limit,MTGAbility * sideEffect,string usesBeforeSideEffects,string castRestriction) : - MTGAbility(id, card), restrictions(restrictions), needsTapping(0),limit(limit),sideEffect(sideEffect),usesBeforeSideEffects(usesBeforeSideEffects),castRestriction(castRestriction) +ActivatedAbility::ActivatedAbility(GameObserver* observer, int id, MTGCardInstance * card, ManaCost * _cost, int restrictions,string limit,MTGAbility * sideEffect,string usesBeforeSideEffects,string castRestriction) : + MTGAbility(observer, id, card), restrictions(restrictions), needsTapping(0),limit(limit),sideEffect(sideEffect),usesBeforeSideEffects(usesBeforeSideEffects),castRestriction(castRestriction) { counters = 0; setCost(_cost); @@ -3582,7 +3579,7 @@ int ActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana) } if(castRestriction.size()) { - AbilityFactory af; + AbilityFactory af(game); int checkCond = af.parseCastRestrictions(card,card->controller(),castRestriction); if(!checkCond) return 0; @@ -3658,7 +3655,7 @@ int ActivatedAbility::activateAbility() MTGAbility * fmp = NULL; bool wasTappedForMana = false; //taking foreach manaproducers off the stack and sending tapped for mana events. - AbilityFactory af; + AbilityFactory af(game); fmp = af.getCoreAbility(this); AManaProducer * amp = dynamic_cast (this); AManaProducer * femp = dynamic_cast (fmp); @@ -3680,13 +3677,12 @@ int ActivatedAbility::activateAbility() else needsTapping = femp->tap; } - if (needsTapping && (source->isInPlay()|| wasTappedForMana)) + if (needsTapping && (source->isInPlay(game)|| wasTappedForMana)) { if (amp||femp) { - GameObserver *g = GameObserver::GetInstance(); WEvent * e = NEW WEventCardTappedForMana(source, 0, 1); - g->receiveEvent(e); + game->receiveEvent(e); } } if (amp||femp) @@ -3724,7 +3720,7 @@ void ActivatedAbility::activateSideEffect() } else { - GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), sa); + GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source, (Damageable *) (this->target), sa); wrapper->addToGame(); } } @@ -3744,14 +3740,14 @@ ostream& ActivatedAbility::toString(ostream& out) const return MTGAbility::toString(out) << ")"; } -TargetAbility::TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc, ManaCost * _cost, int _playerturnonly, string castRestriction) : - ActivatedAbility(id, card, _cost, _playerturnonly, castRestriction), NestedAbility(NULL) +TargetAbility::TargetAbility(GameObserver* observer, int id, MTGCardInstance * card, TargetChooser * _tc, ManaCost * _cost, int _playerturnonly, string castRestriction) : + ActivatedAbility(observer, id, card, _cost, _playerturnonly, castRestriction), NestedAbility(NULL) { tc = _tc; } -TargetAbility::TargetAbility(int id, MTGCardInstance * card, ManaCost * _cost, int _playerturnonly, string castRestriction) : - ActivatedAbility(id, card, _cost, _playerturnonly, castRestriction), NestedAbility(NULL) +TargetAbility::TargetAbility(GameObserver* observer, int id, MTGCardInstance * card, ManaCost * _cost, int _playerturnonly, string castRestriction) : + ActivatedAbility(observer, id, card, _cost, _playerturnonly, castRestriction), NestedAbility(NULL) { tc = NULL; } @@ -3893,13 +3889,13 @@ ostream& TargetAbility::toString(ostream& out) const // -TriggeredAbility::TriggeredAbility(int id, MTGCardInstance * card, Targetable * _target) : - MTGAbility(id, card, _target) +TriggeredAbility::TriggeredAbility(GameObserver* observer, int id, MTGCardInstance * card, Targetable * _target) : + MTGAbility(observer, id, card, _target) { } -TriggeredAbility::TriggeredAbility(int id, MTGCardInstance * card) : - MTGAbility(id, card) +TriggeredAbility::TriggeredAbility(GameObserver* observer, int id, MTGCardInstance * card) : + MTGAbility(observer, id, card) { } @@ -3933,7 +3929,8 @@ ostream& TriggeredAbility::toString(ostream& out) const } // Trigger -Trigger::Trigger(int id, MTGCardInstance * source, bool once, TargetChooser * _tc): TriggeredAbility(id, source), mOnce(once), mActiveTrigger(true) +Trigger::Trigger(GameObserver* observer, int id, MTGCardInstance * source, bool once, TargetChooser * _tc) + : TriggeredAbility(observer, id, source), mOnce(once), mActiveTrigger(true) { tc = _tc; } @@ -3955,7 +3952,7 @@ int Trigger::triggerOnEvent(WEvent * event) { { if(!source) return 1;//can't check these restrictions without a source aka:in a rule.txt - AbilityFactory af; + AbilityFactory af(game); int checkCond = af.parseCastRestrictions(source,source->controller(),castRestriction); if(!checkCond) return 0; @@ -3964,8 +3961,8 @@ int Trigger::triggerOnEvent(WEvent * event) { } // -InstantAbility::InstantAbility(int _id, MTGCardInstance * source) : - MTGAbility(_id, source) +InstantAbility::InstantAbility(GameObserver* observer, int _id, MTGCardInstance * source) : + MTGAbility(observer, _id, source) { init = 0; } @@ -3978,8 +3975,8 @@ void InstantAbility::Update(float dt) } } -InstantAbility::InstantAbility(int _id, MTGCardInstance * source, Targetable * _target) : - MTGAbility(_id, source, _target) +InstantAbility::InstantAbility(GameObserver* observer, int _id, MTGCardInstance * source, Targetable * _target) : + MTGAbility(observer, _id, source, _target) { init = 0; } @@ -4165,14 +4162,13 @@ ostream& ListMaintainerAbility::toString(ostream& out) const return MTGAbility::toString(out) << ")"; } -TriggerAtPhase::TriggerAtPhase(int id, MTGCardInstance * source, Targetable * target, int _phaseId, int who, bool sourceUntapped, bool sourceTap,bool lifelost,int lifeamount,bool once) : - TriggeredAbility(id, source, target), phaseId(_phaseId), who(who), sourceUntapped(sourceUntapped), sourceTap(sourceTap),lifelost(lifelost),lifeamount(lifeamount),once(once) +TriggerAtPhase::TriggerAtPhase(GameObserver* observer, int id, MTGCardInstance * source, Targetable * target, int _phaseId, int who, bool sourceUntapped, bool sourceTap,bool lifelost,int lifeamount,bool once) : + TriggeredAbility(observer, id, source, target), phaseId(_phaseId), who(who), sourceUntapped(sourceUntapped), sourceTap(sourceTap),lifelost(lifelost),lifeamount(lifeamount),once(once) { activeTrigger = true; - GameObserver * g = GameObserver::GetInstance(); - if (g) + if (game) { - newPhase = g->getCurrentGamePhase(); + newPhase = game->getCurrentGamePhase(); currentPhase = newPhase; } } @@ -4193,7 +4189,6 @@ TriggerAtPhase::TriggerAtPhase(int id, MTGCardInstance * source, Targetable * ta return 0; if (testDestroy()) return 0; // http://code.google.com/p/wagic/issues/detail?id=426 - GameObserver * g = GameObserver::GetInstance(); int result = 0; if (currentPhase != newPhase && newPhase == phaseId) { @@ -4201,22 +4196,22 @@ TriggerAtPhase::TriggerAtPhase(int id, MTGCardInstance * source, Targetable * ta switch (who) { case 1: - if (g->currentPlayer == source->controller()) + if (game->currentPlayer == source->controller()) result = 1; break; case -1: - if (g->currentPlayer != source->controller()) + if (game->currentPlayer != source->controller()) result = 1; break; case -2: if (source->target) { - if (g->currentPlayer == source->target->controller()) + if (game->currentPlayer == source->target->controller()) result = 1; } else { - if (g->currentPlayer == source->controller()) + if (game->currentPlayer == source->controller()) result = 1; } break; @@ -4228,7 +4223,7 @@ TriggerAtPhase::TriggerAtPhase(int id, MTGCardInstance * source, Targetable * ta { if(!source) result = 1;//can't check these restrictions without a source aka:in a rule.txt - AbilityFactory af; + AbilityFactory af(game); int checkCond = af.parseCastRestrictions(source,source->controller(),castRestriction); if(!checkCond) result = 0; @@ -4246,8 +4241,8 @@ TriggerAtPhase* TriggerAtPhase::clone() const return NEW TriggerAtPhase(*this); } -TriggerNextPhase::TriggerNextPhase(int id, MTGCardInstance * source, Targetable * target, int _phaseId, int who,bool sourceUntapped, bool sourceTap,bool once) : - TriggerAtPhase(id, source, target, _phaseId, who, sourceUntapped, sourceTap, once) +TriggerNextPhase::TriggerNextPhase(GameObserver* observer, int id, MTGCardInstance * source, Targetable * target, int _phaseId, int who,bool sourceUntapped, bool sourceTap,bool once) : + TriggerAtPhase(observer, id, source, target, _phaseId, who, sourceUntapped, sourceTap, once) { destroyActivated = 0; activeTrigger = true; @@ -4271,9 +4266,9 @@ TriggerNextPhase* TriggerNextPhase::clone() const return NEW TriggerNextPhase(*this); } -GenericTriggeredAbility::GenericTriggeredAbility(int id, MTGCardInstance * _source, TriggeredAbility * _t, MTGAbility * a, +GenericTriggeredAbility::GenericTriggeredAbility(GameObserver* observer, int id, MTGCardInstance * _source, TriggeredAbility * _t, MTGAbility * a, MTGAbility * dc, Targetable * _target) : - TriggeredAbility(id, _source, _target), NestedAbility(a) + TriggeredAbility(observer, id, _source, _target), NestedAbility(a) { if (!target) target = source; @@ -4353,8 +4348,7 @@ void GenericTriggeredAbility::setTriggerTargets(Targetable * ta, MTGAbility * a) void GenericTriggeredAbility::Update(float dt) { - GameObserver * g = GameObserver::GetInstance(); - int newPhase = g->getCurrentGamePhase(); + int newPhase = game->getCurrentGamePhase(); t->newPhase = newPhase; TriggeredAbility::Update(dt); t->currentPhase = newPhase; @@ -4411,9 +4405,9 @@ GenericTriggeredAbility* GenericTriggeredAbility::clone() const other solutions need to be provided for abilities that add mana (ex: mana flare) */ -AManaProducer::AManaProducer(int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost, +AManaProducer::AManaProducer(GameObserver* observer, int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost, int who) : - ActivatedAbilityTP(id, card, t, _cost, who) + ActivatedAbilityTP(observer, id, card, t, _cost, who) { aType = MTGAbility::MANA_PRODUCER; @@ -4473,10 +4467,10 @@ int AManaProducer::reactToClick(MTGCardInstance * _card) cost->setExtraCostsAction(this, _card); if (!cost->isExtraPaymentSet()) { - GameObserver::GetInstance()->mExtraPayment = cost->extraCosts; + game->mExtraPayment = cost->extraCosts; return 0; } - GameObserver::GetInstance()->currentlyActing()->getManaPool()->pay(cost); + game->currentlyActing()->getManaPool()->pay(cost); cost->doPayExtra(); } @@ -4528,8 +4522,8 @@ AManaProducer * AManaProducer::clone() const } -AbilityTP::AbilityTP(int id, MTGCardInstance * card, Targetable * _target, int who) : - MTGAbility(id, card), who(who) +AbilityTP::AbilityTP(GameObserver* observer, int id, MTGCardInstance * card, Targetable * _target, int who) : + MTGAbility(observer, id, card), who(who) { if (_target) target = _target; @@ -4565,8 +4559,8 @@ Targetable * AbilityTP::getTarget() return NULL; } -ActivatedAbilityTP::ActivatedAbilityTP(int id, MTGCardInstance * card, Targetable * _target, ManaCost * cost, int who) : - ActivatedAbility(id, card, cost, 0), who(who) +ActivatedAbilityTP::ActivatedAbilityTP(GameObserver* observer, int id, MTGCardInstance * card, Targetable * _target, ManaCost * cost, int who) : + ActivatedAbility(observer, id, card, cost, 0), who(who) { if (_target) target = _target; @@ -4602,8 +4596,8 @@ Targetable * ActivatedAbilityTP::getTarget() return NULL; } -InstantAbilityTP::InstantAbilityTP(int id, MTGCardInstance * card, Targetable * _target,int who) : - InstantAbility(id, card), who(who) +InstantAbilityTP::InstantAbilityTP(GameObserver* observer, int id, MTGCardInstance * card, Targetable * _target,int who) : + InstantAbility(observer, id, card), who(who) { if (_target) target = _target; diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index c72fc8b09..8e30fe1bd 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -22,12 +22,12 @@ MTGCardInstance MTGCardInstance::NoCard = MTGCardInstance(); MTGCardInstance MTGCardInstance::ExtraRules[] = { MTGCardInstance(), MTGCardInstance() }; MTGCardInstance::MTGCardInstance() : - CardPrimitive(), MTGCard(), Damageable(0), view(NULL) + CardPrimitive(), MTGCard(), Damageable(0, 0), view(NULL) { initMTGCI(); } MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to) : - CardPrimitive(card->data), MTGCard(card), Damageable(card->data->getToughness()), view(NULL) + CardPrimitive(card->data), MTGCard(card), Damageable((arg_belongs_to->owner)?arg_belongs_to->owner->getObserver():0, card->data->getToughness()), view(NULL) { initMTGCI(); model = card; @@ -78,10 +78,10 @@ void MTGCardInstance::copy(MTGCardInstance * card) //Now this is dirty... int backupid = mtgid; mtgid = source->getId(); - Spell * spell = NEW Spell(this); - AbilityFactory af; - GameObserver * g = GameObserver::GetInstance(); - af.addAbilities(g->mLayers->actionLayer()->getMaxId(), spell); + Spell * spell = NEW Spell(observer, this); + observer = card->observer; + AbilityFactory af(observer); + af.addAbilities(observer->mLayers->actionLayer()->getMaxId(), spell); delete spell; mtgid = backupid; } @@ -220,9 +220,8 @@ void MTGCardInstance::addType(int type) setName(Subtypes::subtypesList->find(type)); WEvent * e = NEW WEventCardChangeType(this, type, before, true); - GameObserver * go = GameObserver::GetInstance(); - if (go) - go->receiveEvent(e); + if (observer) + observer->receiveEvent(e); else SAFE_DELETE(e); } @@ -264,17 +263,15 @@ int MTGCardInstance::removeType(int id, int removeAll) setName(""); } WEvent * e = NEW WEventCardChangeType(this, id, before, after); - GameObserver * go = GameObserver::GetInstance(); - if (go) - go->receiveEvent(e); + if (observer) + observer->receiveEvent(e); else SAFE_DELETE(e); return result; } -int MTGCardInstance::isInPlay() +int MTGCardInstance::isInPlay(GameObserver* game) { - GameObserver * game = GameObserver::GetInstance(); for (int i = 0; i < 2; i++) { MTGGameZone * zone = game->players[i]->game->inPlay; @@ -291,7 +288,7 @@ int MTGCardInstance::afterDamage() doDamageTest = 0; if (!isCreature()) return 0; - if (life <= 0 && isInPlay()) + if (life <= 0 && isInPlay(observer)) { return destroy(); } @@ -344,16 +341,14 @@ void MTGCardInstance::eventattacked() { didattacked = 1; WEvent * e = NEW WEventCardAttacked(this); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + observer->receiveEvent(e); } //sets card as attacked alone and sends events void MTGCardInstance::eventattackedAlone() { WEvent * e = NEW WEventCardAttackedAlone(this); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + observer->receiveEvent(e); } //sets card as attacked and sends events @@ -361,8 +356,7 @@ void MTGCardInstance::eventattackednotblocked() { didattacked = 1; WEvent * e = NEW WEventCardAttackedNotBlocked(this); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + observer->receiveEvent(e); } //sets card as attacked and sends events @@ -370,8 +364,7 @@ void MTGCardInstance::eventattackedblocked(MTGCardInstance * opponent) { didattacked = 1; WEvent * e = NEW WEventCardAttackedBlocked(this,opponent); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + observer->receiveEvent(e); } //sets card as blocking and sends events @@ -379,8 +372,7 @@ void MTGCardInstance::eventblocked(MTGCardInstance * opponent) { didblocked = 1; WEvent * e = NEW WEventCardBlocked(this,opponent); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + observer->receiveEvent(e); } //Taps the card @@ -390,8 +382,7 @@ void MTGCardInstance::tap() return; tapped = 1; WEvent * e = NEW WEventCardTap(this, 0, 1); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + observer->receiveEvent(e); } void MTGCardInstance::untap() @@ -400,8 +391,7 @@ void MTGCardInstance::untap() return; tapped = 0; WEvent * e = NEW WEventCardTap(this, 1, 0); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); + observer->receiveEvent(e); } void MTGCardInstance::setUntapping() @@ -471,8 +461,7 @@ int MTGCardInstance::initAttackersDefensers() int MTGCardInstance::cleanup() { initAttackersDefensers(); - GameObserver * game = GameObserver::GetInstance(); - if (!game || game->currentPlayer == controller()) + if (!observer || observer->currentPlayer == controller()) { summoningSickness = 0; } @@ -489,11 +478,11 @@ int MTGCardInstance::cleanup() int MTGCardInstance::stillInUse() { - GameObserver * game = GameObserver::GetInstance(); - if (game->mLayers->actionLayer()->stillInUse(this)) + if (observer->mLayers->actionLayer()->stillInUse(this)) return 1; if (!previous) return 0; + return previous->stillInUse(); } @@ -540,7 +529,7 @@ int MTGCardInstance::canAttack() return 0; if (!isCreature()) return 0; - if (!isInPlay()) + if (!isInPlay(observer)) return 0; return 1; } @@ -569,7 +558,7 @@ int MTGCardInstance::canBlock() return 0; if (!isCreature()) return 0; - if (!isInPlay()) + if (!isInPlay(observer)) return 0; return 1; } @@ -717,9 +706,8 @@ int MTGCardInstance::setAttacker(int value) previousTarget = p; attacker = value; WEvent * e = NEW WEventCreatureAttacker(this, previousTarget, target); - GameObserver * go = GameObserver::GetInstance(); - if (go) - go->receiveEvent(e); + if (observer) + observer->receiveEvent(e); else SAFE_DELETE(e); return 1; @@ -775,9 +763,8 @@ int MTGCardInstance::raiseBlockerRankOrder(MTGCardInstance * blocker) std::iter_swap(it1, it2); WEvent* e = NEW WEventCreatureBlockerRank(*it1, *it2, this); - GameObserver * go = GameObserver::GetInstance(); - if (go) - go->receiveEvent(e); + if (observer) + observer->receiveEvent(e); else SAFE_DELETE(e); //delete(e); @@ -817,13 +804,12 @@ int MTGCardInstance::addBlocker(MTGCardInstance * blocker) //Returns opponents to this card for this turn. This * should * take into account banding MTGCardInstance * MTGCardInstance::getNextOpponent(MTGCardInstance * previous) { - GameObserver * game = GameObserver::GetInstance(); int foundprevious = 0; if (!previous) foundprevious = 1; if (attacker) { - MTGInPlay * inPlay = game->opponent()->game->inPlay; + MTGInPlay * inPlay = observer->opponent()->game->inPlay; for (int i = 0; i < inPlay->nb_cards; i++) { MTGCardInstance * current = inPlay->cards[i]; @@ -843,7 +829,7 @@ MTGCardInstance * MTGCardInstance::getNextOpponent(MTGCardInstance * previous) } else if (defenser) { - MTGInPlay * inPlay = game->currentPlayer->game->inPlay; + MTGInPlay * inPlay = observer->currentPlayer->game->inPlay; for (int i = 0; i < inPlay->nb_cards; i++) { MTGCardInstance * current = inPlay->cards[i]; @@ -865,10 +851,9 @@ MTGCardInstance * MTGCardInstance::getNextOpponent(MTGCardInstance * previous) int MTGCardInstance::setDefenser(MTGCardInstance * opponent) { - GameObserver * g = GameObserver::GetInstance(); if (defenser) { - if (g->players[0]->game->battlefield->hasCard(defenser) || g->players[1]->game->battlefield->hasCard(defenser)) + if (observer->players[0]->game->battlefield->hasCard(defenser) || observer->players[1]->game->battlefield->hasCard(defenser)) { defenser->removeBlocker(this); } @@ -880,7 +865,7 @@ int MTGCardInstance::setDefenser(MTGCardInstance * opponent) if (defenser) defenser->addBlocker(this); if (e) - g->receiveEvent(e); + observer->receiveEvent(e); return 1; } diff --git a/projects/mtg/src/MTGGamePhase.cpp b/projects/mtg/src/MTGGamePhase.cpp index 9f6339d1b..e5e86d352 100644 --- a/projects/mtg/src/MTGGamePhase.cpp +++ b/projects/mtg/src/MTGGamePhase.cpp @@ -5,8 +5,8 @@ MTGGamePhase* MTGGamePhase::instance = 0; -MTGGamePhase::MTGGamePhase(int id) : - ActionElement(id) +MTGGamePhase::MTGGamePhase(GameObserver* g, int id) : + ActionElement(id), observer(g) { animation = 0; currentState = -1; @@ -18,7 +18,7 @@ MTGGamePhase::MTGGamePhase(int id) : void MTGGamePhase::Update(float dt) { - int newState = GameObserver::GetInstance()->getCurrentGamePhase(); + int newState = observer->getCurrentGamePhase(); if (newState != currentState) { activeState = ACTIVE; @@ -41,13 +41,12 @@ void MTGGamePhase::Update(float dt) bool MTGGamePhase::NextGamePhase() { - GameObserver * game = GameObserver::GetInstance(); if (activeState == INACTIVE) { - if (game->currentActionPlayer == game->currentlyActing()) + if (observer->currentActionPlayer == observer->currentlyActing()) { activeState = ACTIVE; - game->userRequestNextGamePhase(); + observer->userRequestNextGamePhase(); return true; } } diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index e8a7f8e5a..1ac2885cf 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -7,6 +7,9 @@ #include "MTGDeck.h" #include "Subtypes.h" +#include "Rules.h" +#include "Token.h" + #if defined (WIN32) || defined (LINUX) #include #endif @@ -15,14 +18,17 @@ //------------------------------ MTGPlayerCards::MTGPlayerCards() + : owner(0) { init(); } -MTGPlayerCards::MTGPlayerCards(int * idList, int idListSize) +MTGPlayerCards::MTGPlayerCards(Player* player, int * idList, int idListSize) + : owner(player) { init(); int i; + for (i = 0; i < idListSize; i++) { MTGCard * card = MTGCollection()->getCardById(idList[i]); @@ -35,6 +41,7 @@ MTGPlayerCards::MTGPlayerCards(int * idList, int idListSize) } MTGPlayerCards::MTGPlayerCards(MTGDeck * deck) + : owner(0) { init(); initDeck(deck); @@ -116,7 +123,7 @@ void MTGPlayerCards::initGame(int shuffle, int draw) void MTGPlayerCards::OptimizedHand(Player * who,int amount, int lands, int creatures, int othercards) { //give the Ai hand adventage to insure a challanging match. - GameObserver * game = game->GetInstance(); + GameObserver * game = who->getObserver(); game->currentPlayerId = game->currentPlayerId; game->currentPlayer = game->currentPlayer; @@ -231,7 +238,7 @@ void MTGPlayerCards::drawFromLibrary() } if (cantlosers < 1) { - GameObserver::GetInstance()->gameOver = library->owner; + library->owner->getObserver()->gameOver = library->owner; } return; } @@ -315,7 +322,7 @@ MTGCardInstance * MTGPlayerCards::putInHand(MTGCardInstance * card) MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to) { MTGCardInstance * copy = NULL; - GameObserver *g = GameObserver::GetInstance(); + GameObserver *g = owner->getObserver(); if (!from || !to) return card; //Error check @@ -387,7 +394,7 @@ void MTGPlayerCards::discardRandom(MTGGameZone * from, MTGCardInstance * source) return; int r = WRand() % (from->nb_cards); WEvent * e = NEW WEventCardDiscard(from->cards[r]); - GameObserver * game = GameObserver::GetInstance(); + GameObserver * game = owner->getObserver(); game->receiveEvent(e); putInZone(from->cards[r], from, graveyard); } @@ -419,7 +426,7 @@ MTGGameZone::MTGGameZone() : MTGGameZone::~MTGGameZone() { - for (int i = 0; i < nb_cards; i++) + for (int i = 0; i < cards.size(); i++) { SAFE_DELETE( cards[i] ); } @@ -439,6 +446,7 @@ void MTGGameZone::setOwner(Player * player) { cards[i]->owner = player; cards[i]->lastController = player; + cards[i]->setObserver(player->getObserver()); } owner = player; } @@ -647,7 +655,7 @@ int MTGGameZone::seenThisTurn(TargetChooser * tc, int castMethod) int MTGGameZone::seenThisTurn(string targetChooserDefinition, int castMethod) { - TargetChooserFactory tcf; + TargetChooserFactory tcf(owner->getObserver()); TargetChooser *tc = tcf.createTargetChooser(targetChooserDefinition, NULL); int result = seenThisTurn(tc, castMethod); delete(tc); @@ -828,10 +836,10 @@ MTGGameZone * MTGGameZone::intToZone(int zoneId, Player * p, Player * p2) } } -MTGGameZone * MTGGameZone::intToZone(int zoneId, MTGCardInstance * source, MTGCardInstance * target) +MTGGameZone * MTGGameZone::intToZone(GameObserver *g, int zoneId, MTGCardInstance * source, MTGCardInstance * target) { Player *p, *p2; - GameObserver * g = GameObserver::GetInstance(); + if (!source) p = g->currentlyActing(); else @@ -956,9 +964,9 @@ int MTGGameZone::zoneStringToId(string zoneName) return 0; } -MTGGameZone * MTGGameZone::stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target) +MTGGameZone * MTGGameZone::stringToZone(GameObserver *g, string zoneName, MTGCardInstance * source, MTGCardInstance * target) { - return intToZone(zoneStringToId(zoneName), source, target); + return intToZone(g, zoneStringToId(zoneName), source, target); } ostream& MTGGameZone::toString(ostream& out) const @@ -993,6 +1001,7 @@ ostream& operator<<(ostream& out, const MTGGameZone& z) { return z.toString(out); } + ostream& operator<<(ostream& out, const MTGPlayerCards& z) { out << z.library->nb_cards << " "; @@ -1002,28 +1011,107 @@ ostream& operator<<(ostream& out, const MTGPlayerCards& z) return out; } -istream& operator>>(istream& in, MTGPlayerCards& z) +istream& operator>>(istream& in, MTGGameZone& z) { - int nb, mtgid; - in >> nb; - - for (int i = 0; i < z.library->nb_cards; i++) + for (int i = 0; i < z.nb_cards; i++) { - SAFE_DELETE( z.library->cards[i] ); + SAFE_DELETE( z.cards[i] ); } - z.library->cards.clear(); - z.library->cardsMap.clear(); + z.cards.clear(); + z.cardsMap.clear(); - for (int i = 0; i < nb; i++) + string s; + while(std::getline(in, s)) { - in >> mtgid; - MTGCard * card = MTGCollection()->getCardById(mtgid); - if (card) + while(s.size()) { - MTGCardInstance * newCard = NEW MTGCardInstance(card, &z); - z.library->addCard(newCard); + size_t limiter = s.find(","); + MTGCard * card = 0; + string toFind; + if (limiter != string::npos) + { + toFind = trim(s.substr(0, limiter)); + s = s.substr(limiter + 1); + } + else + { + toFind = trim(s); + s = ""; + } + + card = MTGCollection()->getCardByName(toFind); + int id = Rules::getMTGId(toFind); + + if (card) + { + /* For the moment we add the card directly in the final zone. + This is not the normal way and this prevents to resolve spells. + We'll need a fusion operation afterward to cast relevant spells */ + MTGCardInstance * newCard = NEW MTGCardInstance(card, z.owner->game); + z.addCard(newCard); + } + else + { + if(toFind == "*") + z.nb_cards++; + else if ( id < 0 ) + { + // For the moment, we create a dummy Token to please the testsuite + Token* myToken = new Token(id); + z.addCard(myToken); + } + else + { + DebugTrace("Card unfound " << toFind << " " << id); + } + } } } return in; } + +istream& operator>>(istream& in, MTGPlayerCards& z) +{ + string s; + streampos pos = in.tellg(); + + while(std::getline(in, s)) + { + size_t limiter = s.find("="); + if (limiter == string::npos) limiter = s.find(":"); + string areaS; + if (limiter != string::npos) + { + areaS = s.substr(0, limiter); + if (areaS.compare("graveyard") == 0) + { + istringstream stream(s.substr(limiter+1)); + stream >> (*z.graveyard); + } + else if (areaS.compare("library") == 0) + { + istringstream stream(s.substr(limiter+1)); + stream >> (*z.library); + } + else if (areaS.compare("hand") == 0) + { + istringstream stream(s.substr(limiter+1)); + stream >> (*z.hand); + } + else if (areaS.compare("inplay") == 0 || areaS.compare("battlefield") == 0) + { + istringstream stream(s.substr(limiter+1)); + stream >> (*z.battlefield); + } + else + { + in.seekg(pos); + break; + } + } + pos = in.tellg(); + } + + return in; +} diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 574fbd35d..ed978320a 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -7,8 +7,8 @@ #include "Credits.h" #include "AllAbilities.h" -MTGEventBonus::MTGEventBonus(int _id) : -MTGAbility(_id,NULL) +MTGEventBonus::MTGEventBonus(GameObserver* observer, int _id) : +MTGAbility(observer, _id,NULL) { textAlpha = 0; text = ""; @@ -277,8 +277,8 @@ MTGEventBonus * MTGEventBonus::clone() const } // -MTGPutInPlayRule::MTGPutInPlayRule(int _id) : -MTGAbility(_id, NULL) +MTGPutInPlayRule::MTGPutInPlayRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { aType = MTGAbility::PUT_INTO_PLAY; } @@ -300,7 +300,7 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana) if (card->basicAbilities[(int)Constants::LEYLINE]) { MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->temp); - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(game, copy); spell->resolve(); delete spell; } @@ -421,7 +421,7 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card) if (card->isLand()) { MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->temp); - Spell * spell = NEW Spell(0,copy,NULL,NULL, payResult); + Spell * spell = NEW Spell(game, 0,copy,NULL,NULL, payResult); spell->resolve(); delete spellCost; delete spell; @@ -478,8 +478,8 @@ MTGPutInPlayRule * MTGPutInPlayRule::clone() const //kicker -MTGKickerRule::MTGKickerRule(int _id) : -MTGPutInPlayRule(_id) +MTGKickerRule::MTGKickerRule(GameObserver* observer, int _id) : +MTGPutInPlayRule(observer, _id) { aType = MTGAbility::PUT_INTO_PLAY_WITH_KICKER; } @@ -559,7 +559,7 @@ int MTGKickerRule::reactToClick(MTGCardInstance * card) if (card->isLand()) { MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->temp); - Spell * spell = NEW Spell(0,copy,NULL,NULL, ManaCost::MANA_PAID_WITH_KICKER); + Spell * spell = NEW Spell(game, 0,copy,NULL,NULL, ManaCost::MANA_PAID_WITH_KICKER); spell->resolve(); delete spellCost; delete spell; @@ -624,8 +624,8 @@ MTGKickerRule * MTGKickerRule::clone() const //------------------------------------------------------------------------- //------------------------------------------------------------------------- -MTGAlternativeCostRule::MTGAlternativeCostRule(int _id) : -MTGAbility(_id, NULL) +MTGAlternativeCostRule::MTGAlternativeCostRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { aType = MTGAbility::ALTERNATIVE_COST; } @@ -723,7 +723,7 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter if (card->isLand()) { MTGCardInstance * copy = player->game->putInZone(card, card->currentZone, player->game->temp); - Spell * spell = NEW Spell(0,copy,NULL,NULL, alternateCostType); + Spell * spell = NEW Spell(game, 0,copy,NULL,NULL, alternateCostType); copy->alternateCostPaid[alternateCostType] = 1; spell->resolve(); SAFE_DELETE(spell); @@ -781,8 +781,8 @@ MTGAlternativeCostRule * MTGAlternativeCostRule::clone() const //------------------------------------------------------------------------- //buyback follows its own resolving rules -MTGBuyBackRule::MTGBuyBackRule(int _id) : -MTGAlternativeCostRule(_id) +MTGBuyBackRule::MTGBuyBackRule(GameObserver* observer, int _id) : +MTGAlternativeCostRule(observer, _id) { aType = MTGAbility::BUYBACK_COST; } @@ -832,8 +832,8 @@ MTGBuyBackRule * MTGBuyBackRule::clone() const //------------------------------------------------------------------------- //------------------------------------------------------------------------- //flashback follows its own resolving rules -MTGFlashBackRule::MTGFlashBackRule(int _id) : -MTGAlternativeCostRule(_id) +MTGFlashBackRule::MTGFlashBackRule(GameObserver* observer, int _id) : +MTGAlternativeCostRule(observer, _id) { aType = MTGAbility::FLASHBACK_COST; } @@ -880,8 +880,8 @@ MTGFlashBackRule * MTGFlashBackRule::clone() const //------------------------------------------------------------------------- //retrace -MTGRetraceRule::MTGRetraceRule(int _id) : -MTGAlternativeCostRule(_id) +MTGRetraceRule::MTGRetraceRule(GameObserver* observer, int _id) : +MTGAlternativeCostRule(observer, _id) { aType = MTGAbility::RETRACE_COST; } @@ -934,8 +934,8 @@ MTGRetraceRule * MTGRetraceRule::clone() const //------------------------------------------------------------------------- //Suspend -MTGSuspendRule::MTGSuspendRule(int _id) : -MTGAlternativeCostRule(_id) +MTGSuspendRule::MTGSuspendRule(GameObserver* observer, int _id) : +MTGAlternativeCostRule(observer, _id) { aType = MTGAbility::SUSPEND_COST; } @@ -1051,8 +1051,8 @@ MTGSuspendRule * MTGSuspendRule::clone() const //------------------------------------------------------------------------- -MTGMorphCostRule::MTGMorphCostRule(int _id) : - MTGAbility(_id, NULL) +MTGMorphCostRule::MTGMorphCostRule(GameObserver* observer, int _id) : + MTGAbility(observer, _id, NULL) { aType = MTGAbility::MORPH_COST; } @@ -1195,8 +1195,8 @@ bool MTGAttackRule::greyout(Target* t) return true; } -MTGAttackRule::MTGAttackRule(int _id) : -MTGAbility(_id, NULL) +MTGAttackRule::MTGAttackRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { aType = MTGAbility::MTG_ATTACK_RULE; } @@ -1276,8 +1276,8 @@ MTGAttackRule * MTGAttackRule::clone() const } //this rules handles returning cards to combat triggers for activations. -MTGCombatTriggersRule::MTGCombatTriggersRule(int _id) : -MTGAbility(_id, NULL) +MTGCombatTriggersRule::MTGCombatTriggersRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { aType = MTGAbility::MTG_COMBATTRIGGERS_RULE; } @@ -1394,8 +1394,8 @@ MTGCombatTriggersRule * MTGCombatTriggersRule::clone() const } ///------------ -OtherAbilitiesEventReceiver::OtherAbilitiesEventReceiver(int _id) : -MTGAbility(_id, NULL) +OtherAbilitiesEventReceiver::OtherAbilitiesEventReceiver(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } @@ -1405,14 +1405,13 @@ int OtherAbilitiesEventReceiver::receiveEvent(WEvent *e) { if (event->to && (event->to != event->from)) { - GameObserver * g = GameObserver::GetInstance(); for (int i = 0; i < 2; ++i) { - if (event->to == g->players[i]->game->inPlay) + if (event->to == game->players[i]->game->inPlay) return 0; } - AbilityFactory af; - af.magicText(g->mLayers->actionLayer()->getMaxId(), NULL, event->card, 1, 0, event->to); + AbilityFactory af(game); + af.magicText(game->mLayers->actionLayer()->getMaxId(), NULL, event->card, 1, 0, event->to); return 1; } } @@ -1429,8 +1428,8 @@ OtherAbilitiesEventReceiver * OtherAbilitiesEventReceiver::clone() const return NEW OtherAbilitiesEventReceiver(*this); } -MTGBlockRule::MTGBlockRule(int _id) : -MTGAbility(_id, NULL) +MTGBlockRule::MTGBlockRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { aType = MTGAbility::MTG_BLOCK_RULE; } @@ -1494,8 +1493,8 @@ MTGBlockRule * MTGBlockRule::clone() const int MTGMomirRule::initialized = 0; vector MTGMomirRule::pool[20]; -MTGMomirRule::MTGMomirRule(int _id, MTGAllCards * _collection) : -MTGAbility(_id, NULL) +MTGMomirRule::MTGMomirRule(GameObserver* observer, int _id, MTGAllCards * _collection) : +MTGAbility(observer, _id, NULL) { collection = _collection; if (!initialized) @@ -1558,7 +1557,7 @@ int MTGMomirRule::reactToClick(MTGCardInstance * card_to_discard, int cardId) player->game->putInZone(card_to_discard, player->game->hand, player->game->graveyard); player->game->stack->addCard(card); - Spell * spell = NEW Spell(card); + Spell * spell = NEW Spell(game, card); spell->resolve(); spell->source->isToken = 1; delete spell; @@ -1649,8 +1648,8 @@ MTGMomirRule * MTGMomirRule::clone() const int MTGStoneHewerRule::initialized = 0; vector MTGStoneHewerRule::pool[20]; -MTGStoneHewerRule::MTGStoneHewerRule(int _id, MTGAllCards * _collection) : -MTGAbility(_id, NULL) +MTGStoneHewerRule::MTGStoneHewerRule(GameObserver* observer, int _id, MTGAllCards * _collection) : +MTGAbility(observer, _id, NULL) { collection = _collection; if (!initialized) @@ -1682,13 +1681,12 @@ int MTGStoneHewerRule::receiveEvent(WEvent * event) if(card) { game->currentlyActing()->game->temp->addCard(card); - Spell * spell = NEW Spell(card); + Spell * spell = NEW Spell(game, card); spell->resolve(); spell->source->isToken = 1; - GameObserver * g = g->GetInstance(); - for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) + for (size_t i = 1; i < game->mLayers->actionLayer()->mObjects.size(); i++) { - MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); + MTGAbility * a = ((MTGAbility *) game->mLayers->actionLayer()->mObjects[i]); AEquip * eq = dynamic_cast (a); if (eq && eq->source == spell->source) { @@ -1750,8 +1748,8 @@ MTGStoneHewerRule * MTGStoneHewerRule::clone() const //------------------ //Hermit druid mode places a random land from your deck into play during each of your upkeeps -MTGHermitRule::MTGHermitRule(int _id) : -MTGAbility(_id, NULL) +MTGHermitRule::MTGHermitRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } @@ -1773,7 +1771,7 @@ int MTGHermitRule::receiveEvent(WEvent * event) if(lcard) { MTGCardInstance * copy = game->currentPlayer->game->putInZone(lcard,game->currentPlayer->game->library, game->currentPlayer->game->temp); - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(game, copy); spell->resolve(); delete spell; } @@ -1887,8 +1885,8 @@ void HUDDisplay::Render() i++; } } -HUDDisplay::HUDDisplay(int _id) : -MTGAbility(_id, NULL) +HUDDisplay::HUDDisplay(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { timestamp = 0; popdelay = 2; @@ -1913,8 +1911,8 @@ HUDDisplay * HUDDisplay::clone() const } /* Persist */ -MTGPersistRule::MTGPersistRule(int _id) : -MTGAbility(_id, NULL) +MTGPersistRule::MTGPersistRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } ; @@ -1947,7 +1945,7 @@ int MTGPersistRule::receiveEvent(WEvent * event) DebugTrace("MTGRULES: couldn't move card for persist"); return 0; } - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(game, copy); spell->resolve(); spell->source->counters->addCounter(-1, -1); delete spell; @@ -1976,8 +1974,8 @@ MTGPersistRule * MTGPersistRule::clone() const //vampires rule //handled seperately as a rule since we only want one object to send out events that a card was "vampired". //otherwise vampire event is sent per instance of @vampired on the battlefield, multipling the results. -MTGVampireRule::MTGVampireRule(int _id) : -MTGAbility(_id, NULL) +MTGVampireRule::MTGVampireRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } ; @@ -2051,8 +2049,8 @@ MTGVampireRule * MTGVampireRule::clone() const ///////////////////////////////////////////////// //unearth rule---------------------------------- //if the card leaves play, exile it instead. -MTGUnearthRule::MTGUnearthRule(int _id) : -MTGAbility(_id, NULL) +MTGUnearthRule::MTGUnearthRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } ; @@ -2111,8 +2109,8 @@ MTGUnearthRule * MTGUnearthRule::clone() const return NEW MTGUnearthRule(*this); } //token clean up -MTGTokensCleanup::MTGTokensCleanup(int _id) : -MTGAbility(_id, NULL) +MTGTokensCleanup::MTGTokensCleanup(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } @@ -2144,8 +2142,8 @@ MTGTokensCleanup * MTGTokensCleanup::clone() const } /* Legend Rule */ -MTGLegendRule::MTGLegendRule(int _id) : -ListMaintainerAbility(_id) +MTGLegendRule::MTGLegendRule(GameObserver* observer, int _id) : +ListMaintainerAbility(observer, _id) { } ; @@ -2201,8 +2199,8 @@ MTGLegendRule * MTGLegendRule::clone() const } /* PlaneWalker Rule */ -MTGPlaneWalkerRule::MTGPlaneWalkerRule(int _id) : -ListMaintainerAbility(_id) +MTGPlaneWalkerRule::MTGPlaneWalkerRule(GameObserver* observer, int _id) : +ListMaintainerAbility(observer, _id) { } ; @@ -2258,8 +2256,8 @@ MTGPlaneWalkerRule * MTGPlaneWalkerRule::clone() const } /* Lifelink */ -MTGLifelinkRule::MTGLifelinkRule(int _id) : -MTGAbility(_id, NULL) +MTGLifelinkRule::MTGLifelinkRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } ; @@ -2296,8 +2294,8 @@ MTGLifelinkRule * MTGLifelinkRule::clone() const } /* Deathtouch */ -MTGDeathtouchRule::MTGDeathtouchRule(int _id) : -MTGAbility(_id, NULL) +MTGDeathtouchRule::MTGDeathtouchRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } ; @@ -2340,8 +2338,8 @@ MTGDeathtouchRule * MTGDeathtouchRule::clone() const } // //kai mod -ParentChildRule::ParentChildRule(int _id) : -MTGAbility(_id, NULL) +ParentChildRule::ParentChildRule(GameObserver* observer, int _id) : +MTGAbility(observer, _id, NULL) { } ; @@ -2407,4 +2405,4 @@ int ParentChildRule::testDestroy() ParentChildRule * ParentChildRule::clone() const { return NEW ParentChildRule(*this); -} \ No newline at end of file +} diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index adc0bd7db..2269448dd 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -16,6 +16,7 @@ SUPPORT_OBJECT_ANALYTICS(ManaCost) ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstance * c) { ManaCost * manaCost; + GameObserver* g = c?c->getObserver():NULL; if (_manaCost) { manaCost = _manaCost; @@ -75,9 +76,8 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan } else { - //Parse target for extraCosts - TargetChooserFactory tcf; + TargetChooserFactory tcf(g); TargetChooser * tc = NULL; size_t target_start = value.find("("); size_t target_end = value.find(")"); @@ -143,10 +143,12 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan manaCost->addExtraCost(NEW MillCost(tc)); break; case 'n': //return unblocked attacker cost - TargetChooserFactory tcf; - tc = tcf.createTargetChooser("creature|myBattlefield", c); - manaCost->addExtraCost(NEW Ninja(tc)); - break; + { + TargetChooserFactory tcf(g); + tc = tcf.createTargetChooser("creature|myBattlefield", c); + manaCost->addExtraCost(NEW Ninja(tc)); + break; + } case 'p' : { SAFE_DELETE(tc); @@ -165,7 +167,7 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan { size_t counter_start = value.find("("); size_t counter_end = value.find(")", counter_start); - AbilityFactory abf; + AbilityFactory abf(g); string counterString = value.substr(counter_start + 1, counter_end - counter_start - 1); Counter * counter = abf.parseCounter(counterString, c); size_t separator = value.find(",", counter_start); @@ -786,7 +788,7 @@ void ManaPool::init() { ManaCost::init(); WEvent * e = NEW WEventEmptyManaPool(this); - GameObserver::GetInstance()->receiveEvent(e); + player->getObserver()->receiveEvent(e); } ManaPool::ManaPool(Player * player) : @@ -805,7 +807,7 @@ int ManaPool::remove(int color, int value) for (int i = 0; i < value; ++i) { WEvent * e = NEW WEventConsumeMana(color, this); - GameObserver::GetInstance()->receiveEvent(e); + player->getObserver()->receiveEvent(e); } return result; } @@ -816,7 +818,7 @@ int ManaPool::add(int color, int value, MTGCardInstance * source) for (int i = 0; i < value; ++i) { WEvent * e = NEW WEventEngageMana(color, source, this); - GameObserver::GetInstance()->receiveEvent(e); + player->getObserver()->receiveEvent(e); } return result; } @@ -831,7 +833,7 @@ int ManaPool::add(ManaCost * _cost, MTGCardInstance * source) for (int j = 0; j < _cost->getCost(i); j++) { WEvent * e = NEW WEventEngageMana(i, source, this); - GameObserver::GetInstance()->receiveEvent(e); + player->getObserver()->receiveEvent(e); } } return result; @@ -852,7 +854,7 @@ int ManaPool::pay(ManaCost * _cost) for (int j = 0; j < value; j++) { WEvent * e = NEW WEventConsumeMana(i, this); - GameObserver::GetInstance()->receiveEvent(e); + player->getObserver()->receiveEvent(e); } } diff --git a/projects/mtg/src/PhaseRing.cpp b/projects/mtg/src/PhaseRing.cpp index 84727cfdf..969981a31 100644 --- a/projects/mtg/src/PhaseRing.cpp +++ b/projects/mtg/src/PhaseRing.cpp @@ -28,27 +28,28 @@ int PhaseRing::phaseStrToInt(string s) } /* Creates a New phase ring with the default rules */ -PhaseRing::PhaseRing(Player* players[], int nbPlayers) +PhaseRing::PhaseRing(GameObserver* observer) + :observer(observer) { - for (int i = 0; i < nbPlayers; i++) + for (int i = 0; i < observer->getPlayersNumber(); i++) { - if(players[i]->phaseRing.size()) + if(observer->players[i]->phaseRing.size()) { - addPhase(NEW Phase(Constants::MTG_PHASE_BEFORE_BEGIN, players[i])); - vectorcustomRing = split(players[i]->phaseRing,','); + addPhase(NEW Phase(Constants::MTG_PHASE_BEFORE_BEGIN, observer->players[i])); + vectorcustomRing = split(observer->players[i]->phaseRing,','); for (unsigned int k = 0;k < customRing.size(); k++) { int customOrder = phaseStrToInt(customRing[k]); - Phase * phase = NEW Phase(customOrder, players[i]); + Phase * phase = NEW Phase(customOrder, observer->players[i]); addPhase(phase); } - addPhase( NEW Phase(Constants::MTG_PHASE_AFTER_EOT, players[i])); + addPhase( NEW Phase(Constants::MTG_PHASE_AFTER_EOT, observer->players[i])); } else { for (int j = 0; j < Constants::NB_MTG_PHASES; j++) { - Phase * phase = NEW Phase(j, players[i]); + Phase * phase = NEW Phase(j, observer->players[i]); addPhase(phase); } } @@ -69,12 +70,11 @@ PhaseRing::~PhaseRing() //Tells if next phase will be another Damage phase rather than combat ends bool PhaseRing::extraDamagePhase(int id) { - GameObserver * g = GameObserver::GetInstance(); if (id != Constants::MTG_PHASE_COMBATEND) return false; - if (g->combatStep != END_FIRST_STRIKE) return false; + if (observer->combatStep != END_FIRST_STRIKE) return false; for (int j = 0; j < 2; ++j) { - MTGGameZone * z = g->players[j]->game->inPlay; + MTGGameZone * z = observer->players[j]->game->inPlay; for (int i = 0; i < z->nb_cards; ++i) { MTGCardInstance * card = z->cards[i]; @@ -110,7 +110,7 @@ Phase * PhaseRing::forward(bool sendEvents) { //Warn the layers about the phase Change WEvent * e = NEW WEventPhaseChange(cPhaseOld, *current); - GameObserver::GetInstance()->receiveEvent(e); + observer->receiveEvent(e); } return *current; diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index 5c0678002..2154dad3f 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -5,10 +5,14 @@ #include "DeckStats.h" #include "ManaCost.h" -Player::Player(string file, string fileSmall, MTGDeck * deck) : -Damageable(20) +#ifdef TESTSUITE +#include "TestSuiteAI.h" +#endif + +Player::Player(GameObserver *observer, string file, string fileSmall, MTGDeck * deck) : + Damageable(observer, 20), mAvatarName("") { - if(deck == NULL && file != "testsuite" && file != "remote") + if(deck == NULL && file != "testsuite" && file != "remote" && file != "") deck = NEW MTGDeck(file.c_str(), MTGCollection()); game = NULL; @@ -32,10 +36,17 @@ Damageable(20) mDeck = deck; } +void Player::setObserver(GameObserver*g) +{ + observer = g; + // fix card instances direct pointer + game->setOwner(this); +} + /*Method to call at the end of a game, before all objects involved in the game are destroyed */ void Player::End() { - DeckStats::GetInstance()->saveStats(this, opponent(), GameObserver::GetInstance()); + DeckStats::GetInstance()->saveStats(this, opponent(), observer); } Player::~Player() @@ -61,8 +72,7 @@ void Player::loadAvatar(string file) const string Player::getDisplayName() const { - GameObserver * g = GameObserver::GetInstance(); - if (this == g->players[0]) return "Player 1"; + if (this == observer->players[0]) return "Player 1"; return "Player 2"; } @@ -73,10 +83,9 @@ MTGInPlay * Player::inPlay() int Player::getId() { - GameObserver * game = GameObserver::GetInstance(); for (int i = 0; i < 2; i++) { - if (game->players[i] == this) return i; + if (observer->players[i] == this) return i; } return -1; } @@ -88,13 +97,12 @@ JQuadPtr Player::getIcon() Player * Player::opponent() { - GameObserver * game = GameObserver::GetInstance(); - if (!game) return NULL; - return this == game->players[0] ? game->players[1] : game->players[0]; + if (!observer) return NULL; + return this == observer->players[0] ? observer->players[1] : observer->players[0]; } -HumanPlayer::HumanPlayer(string file, string fileSmall, MTGDeck * deck) : - Player(file, fileSmall, deck) +HumanPlayer::HumanPlayer(GameObserver *observer, string file, string fileSmall, MTGDeck * deck) : + Player(observer, file, fileSmall, deck) { loadAvatar("avatar.jpg"); playMode = MODE_HUMAN; @@ -119,8 +127,7 @@ int Player::gainOrLoseLife(int value) //Send life event to listeners WEvent * lifed = NEW WEventLife(this,value); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(lifed); + observer->receiveEvent(lifed); return value; } @@ -203,13 +210,61 @@ ostream& operator<<(ostream& out, const Player& p) istream& operator>>(istream& in, Player& p) { + string s; + streampos pos = in.tellg(); + + in >> *((Damageable*)&p); + + while(std::getline(in, s)) + { + size_t limiter = s.find("="); + if (limiter == string::npos) limiter = s.find(":"); + string areaS; + if (limiter != string::npos) + { + areaS = s.substr(0, limiter); + if (areaS.compare("manapool") == 0) + { + SAFE_DELETE(p.manaPool); + p.manaPool = new ManaPool(&p); + ManaCost::parseManaCost(s.substr(limiter + 1), p.manaPool); + } + else if (areaS.compare("avatar") == 0) + { // We don't load directly for now + p.mAvatarName = s.substr(limiter + 1); + } + else if (areaS.compare("customphasering") == 0) + { + p.phaseRing = s.substr(limiter + 1); + } + else if (areaS.compare("offerinterruptonphase") == 0) + { + for (int i = 0; i < Constants::NB_MTG_PHASES; i++) + { + string phaseStr = Constants::MTGPhaseCodeNames[i]; + if (s.find(phaseStr) != string::npos) + { + p.offerInterruptOnPhase = PhaseRing::phaseStrToInt(phaseStr); + break; + } + } + } + else + { + in.seekg(pos); + break; + } + } + pos = in.tellg(); + } + if(!p.game) { p.game = new MTGPlayerCards(); + p.game->setOwner(&p); } in >> *(p.game); - p.game->setOwner(&p); return in; } diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index e5b81ae88..3af0bb934 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -73,9 +73,8 @@ int Rules::getMTGId(string cardName) return 0; } -MTGCardInstance * Rules::getCardByMTGId(int mtgid) +MTGCardInstance * Rules::getCardByMTGId(GameObserver* g, int mtgid) { - GameObserver * g = GameObserver::GetInstance(); for (int i = 0; i < 2; i++) { Player * p = g->players[i]; @@ -95,27 +94,13 @@ MTGCardInstance * Rules::getCardByMTGId(int mtgid) } RulesPlayerData::RulesPlayerData() + : player(0) { - life = 20; - poisonCount = 0; - damageCount = 0; - preventable = 0; - manapool = NEW ManaCost(); - avatar = ""; } RulesPlayerData::~RulesPlayerData() { - SAFE_DELETE(manapool); -} - -RulesPlayerZone::RulesPlayerZone() -{ -} - -void RulesPlayerZone::add(int cardId) -{ - cards.push_back(cardId); + SAFE_DELETE(player); } RulesState::RulesState() @@ -126,115 +111,37 @@ RulesState::RulesState() void RulesState::parsePlayerState(int playerId, string s) { - size_t limiter = s.find("="); - if (limiter == string::npos) limiter = s.find(":"); - string areaS; - int area = -1; - if (limiter != string::npos) + stringstream stream(s); + stream >> *(playerData[playerId].player); + + while(std::getline(stream, s)) { - areaS = s.substr(0, limiter); - if (areaS.compare("graveyard") == 0) + size_t limiter = s.find("="); + if (limiter == string::npos) limiter = s.find(":"); + string areaS; + if (limiter != string::npos) { - area = 0; - } - else if (areaS.compare("library") == 0) - { - area = 1; - } - else if (areaS.compare("hand") == 0) - { - area = 2; - } - else if (areaS.compare("inplay") == 0 || areaS.compare("battlefield") == 0) - { - area = 3; - } - else if (areaS.compare("life") == 0) - { - playerData[playerId].life = atoi((s.substr(limiter + 1)).c_str()); - return; - } - else if (areaS.compare("poisoncount") == 0) - { - playerData[playerId].poisonCount = atoi((s.substr(limiter + 1)).c_str()); - return; - } - else if (areaS.compare("damagecount") == 0) - { - playerData[playerId].damageCount = atoi((s.substr(limiter + 1)).c_str()); - return; - } - else if (areaS.compare("preventable") == 0) - { - playerData[playerId].preventable = atoi((s.substr(limiter + 1)).c_str()); - return; - } - else if (areaS.compare("avatar") == 0) - { - playerData[playerId].avatar = s.substr(limiter + 1); - return; - } - else if (areaS.compare("manapool") == 0) - { - SAFE_DELETE(playerData[playerId].manapool); - playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter + 1)); - return; - } - else if (areaS.compare("customphasering") == 0) - { - playerData[playerId].phaseRing = s.substr(limiter + 1); - return; - } - else if (areaS.compare("offerinterruptonphase") == 0) - { - for (int i = 0; i < Constants::NB_MTG_PHASES; i++) + areaS = s.substr(0, limiter); + + if (areaS.compare("auto") == 0) { - string phaseStr = Constants::MTGPhaseCodeNames[i]; - if (s.find(phaseStr) != string::npos) - { - playerData[playerId].offerInterruptOnPhase = PhaseRing::phaseStrToInt(phaseStr); - break; - } - } - return; - } - else if (areaS.compare("auto") == 0) - { - playerData[playerId].extraRules.push_back(s.substr(limiter + 1)); - return; - } - else - { - return; // ERROR - } - s = s.substr(limiter + 1); - while (s.size()) - { - unsigned int value; - limiter = s.find(","); - if (limiter != string::npos) - { - value = Rules::getMTGId(s.substr(0, limiter)); - s = s.substr(limiter + 1); + playerData[playerId].extraRules.push_back(s.substr(limiter + 1)); + return; } else { - value = Rules::getMTGId(s); - s = ""; + return; // ERROR } - if (value) playerData[playerId].zones[area].add(value); } - } - else - { - //ERROR + else + { + //ERROR + } } } -void Rules::addExtraRules() +void Rules::addExtraRules(GameObserver* g) { - GameObserver * g = GameObserver::GetInstance(); - int id = g->mLayers->actionLayer()->getMaxId(); for (int i = 0; i < 2; ++i) { @@ -244,7 +151,7 @@ void Rules::addExtraRules() MTGCardInstance::ExtraRules[i].lastController = p; for (size_t j = 0; j < initState.playerData[i].extraRules.size(); ++j) { - AbilityFactory af; + AbilityFactory af(g); MTGPlayerCards * hand = NULL; int handsize = 7; int difficultyRating = 0; @@ -309,7 +216,7 @@ void Rules::addExtraRules() for (size_t j = 0; j < extraRules.size(); ++j) { - AbilityFactory af; + AbilityFactory af(g); MTGAbility * a = af.parseMagicLine(extraRules[j], id++, NULL, &MTGCardInstance::ExtraRules[0]); if (a) { @@ -327,7 +234,7 @@ void Rules::addExtraRules() } -Player * Rules::loadPlayerMomir(int isAI) +Player * Rules::loadPlayerMomir(GameObserver* observer, int isAI) { string deckFileSmall = "momir"; char empty[] = ""; @@ -341,14 +248,14 @@ Player * Rules::loadPlayerMomir(int isAI) Player *player = NULL; if (!isAI) // Human Player - player = NEW HumanPlayer(options.profileFile("momir.txt", "", true).c_str(), deckFileSmall, tempDeck); + player = NEW HumanPlayer(observer, options.profileFile("momir.txt", "", true).c_str(), deckFileSmall, tempDeck); else - player = NEW AIMomirPlayer(options.profileFile("momir.txt", "", true).c_str(), deckFileSmall, empty, tempDeck); + player = NEW AIMomirPlayer(observer, options.profileFile("momir.txt", "", true).c_str(), deckFileSmall, empty, tempDeck); return player; } -Player * Rules::loadPlayerRandom(int isAI, int mode) +Player * Rules::loadPlayerRandom(GameObserver* observer, int isAI, int mode) { int color1 = 1 + WRand() % 5; int color2 = 1 + WRand() % 5; @@ -375,16 +282,15 @@ Player * Rules::loadPlayerRandom(int isAI, int mode) Player *player = NULL; if (!isAI) // Human Player - player = NEW HumanPlayer(deckFile, deckFileSmall, tempDeck); + player = NEW HumanPlayer(observer, deckFile, deckFileSmall, tempDeck); else - player = NEW AIPlayerBaka(deckFile, deckFileSmall, "", tempDeck); + player = NEW AIPlayerBaka(observer, deckFile, deckFileSmall, "", tempDeck); return player; } -Player * Rules::initPlayer(int playerId) +Player * Rules::initPlayer(GameObserver *g, int playerId) { - GameObserver * g = GameObserver::GetInstance(); Player * p = g->players[playerId]; if (!p) { @@ -393,17 +299,17 @@ Player * Rules::initPlayer(int playerId) switch (gamemode) { case GAME_TYPE_MOMIR: - return loadPlayerMomir(isAI); + return loadPlayerMomir(g, isAI); case GAME_TYPE_CLASSIC: return NULL; //Error for the time being case GAME_TYPE_RANDOM1: - return loadPlayerRandom(isAI, GAME_TYPE_RANDOM1); + return loadPlayerRandom(g, isAI, GAME_TYPE_RANDOM1); case GAME_TYPE_RANDOM2: - return loadPlayerRandom(isAI, GAME_TYPE_RANDOM2); + return loadPlayerRandom(g, isAI, GAME_TYPE_RANDOM2); } } - p->phaseRing = initState.playerData[playerId].phaseRing; - p->offerInterruptOnPhase = initState.playerData[playerId].offerInterruptOnPhase; + p->phaseRing = initState.playerData[playerId].player->phaseRing; + p->offerInterruptOnPhase = initState.playerData[playerId].player->offerInterruptOnPhase; return p; } @@ -411,11 +317,17 @@ MTGDeck * Rules::buildDeck(int playerId) { int nbcards = 0; MTGDeck * deck = NEW MTGDeck(MTGCollection()); + + MTGGameZone * loadedPlayerZones[] = { initState.playerData[playerId].player->game->graveyard, + initState.playerData[playerId].player->game->library, + initState.playerData[playerId].player->game->hand, + initState.playerData[playerId].player->game->inPlay }; + for (int j = 0; j < 4; j++) { - for (size_t k = 0; k < initState.playerData[playerId].zones[j].cards.size(); k++) + for (size_t k = 0; k < loadedPlayerZones[j]->cards.size(); k++) { - int cardid = initState.playerData[playerId].zones[j].cards[k]; + int cardid = loadedPlayerZones[j]->cards[k]->getId(); deck->add(cardid); nbcards++; } @@ -428,12 +340,11 @@ MTGDeck * Rules::buildDeck(int playerId) return deck; } -void Rules::initPlayers() +void Rules::initPlayers(GameObserver *g) { - GameObserver * g = GameObserver::GetInstance(); for (int i = 0; i < 2; i++) { - Player * p = initPlayer(i); + Player * p = initPlayer(g, i); g->players[i] = p; MTGDeck * deck = buildDeck(i); if (deck) @@ -445,10 +356,8 @@ void Rules::initPlayers() } } -void Rules::initGame() +void Rules::initGame(GameObserver *g) { - //Put the GameObserver in the initial state - GameObserver * g = GameObserver::GetInstance(); DebugTrace("RULES Init Game\n"); //Set the current player/phase @@ -469,27 +378,31 @@ void Rules::initGame() for (int i = 0; i < 2; i++) { Player * p = g->players[i]; - p->life = initState.playerData[i].life; - p->poisonCount = initState.playerData[i].poisonCount; - p->damageCount = initState.playerData[i].damageCount; - p->preventable = initState.playerData[i].preventable; - if (initState.playerData[i].avatar.size()) + p->life = initState.playerData[i].player->life; + p->poisonCount = initState.playerData[i].player->poisonCount; + p->damageCount = initState.playerData[i].player->damageCount; + p->preventable = initState.playerData[i].player->preventable; + if (initState.playerData[i].player->mAvatarName.size()) { - p->loadAvatar(initState.playerData[i].avatar); + p->loadAvatar(initState.playerData[i].player->mAvatarName); } MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay }; + MTGGameZone * loadedPlayerZones[] = { initState.playerData[i].player->game->graveyard, + initState.playerData[i].player->game->library, + initState.playerData[i].player->game->hand, + initState.playerData[i].player->game->inPlay }; for (int j = 0; j < 4; j++) { MTGGameZone * zone = playerZones[j]; - for (size_t k = 0; k < initState.playerData[i].zones[j].cards.size(); k++) + for (size_t k = 0; k < loadedPlayerZones[j]->cards.size(); k++) { - MTGCardInstance * card = getCardByMTGId(initState.playerData[i].zones[j].cards[k]); + MTGCardInstance * card = getCardByMTGId(g, loadedPlayerZones[j]->cards[k]->getId()); if (card && zone != p->game->library) { if (zone == p->game->inPlay) { MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack); - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(g, copy); spell->resolve(); delete spell; } @@ -512,7 +425,7 @@ void Rules::initGame() } } } - addExtraRules(); + addExtraRules(g); postUpdateInitDone = false; DebugTrace("RULES Init Game Done !\n"); @@ -521,34 +434,20 @@ DebugTrace("RULES Init Game Done !\n"); //This function has all iitialization that can't be done in the "real" init function, // because the first update call messes things up. //It's a hack, ideally, the first update call shouldn't mess the init parameters... -void Rules::postUpdateInit() +void Rules::postUpdateInit(GameObserver* observer) { if (postUpdateInitDone) return; for (int i = 0; i < 2; ++ i) - GameObserver::GetInstance()->players[i]->getManaPool()->add(initState.playerData[i].manapool); + observer->players[i]->getManaPool()->add(initState.playerData[i].player->getManaPool()); // GameObserver::GetInstance()->players[i]->getManaPool()->copy(initState.playerData[i].manapool); postUpdateInitDone = true; } -void RulesPlayerZone::cleanup() -{ - cards.clear(); -} - void RulesPlayerData::cleanup() { - if (manapool) delete manapool; - manapool = NULL; - manapool = NEW ManaCost(); - for (int i = 0; i < 5; i++) - { - zones[i].cleanup(); - } - life = 20; - poisonCount = 0; - damageCount = 0; - preventable = 0; + SAFE_DELETE(player); + player = new Player(NULL, "", ""); } void RulesState::cleanup() diff --git a/projects/mtg/src/StoryFlow.cpp b/projects/mtg/src/StoryFlow.cpp index aaacfb49e..84578704d 100644 --- a/projects/mtg/src/StoryFlow.cpp +++ b/projects/mtg/src/StoryFlow.cpp @@ -310,19 +310,19 @@ void StoryDuel::init() sprintf(deckFile, "%s/deck.txt", folder); sprintf(deckFileSmall, "campaign_%s", mParent->folder.c_str()); - players[0] = NEW HumanPlayer(deckFile, deckFileSmall); + players[0] = NEW HumanPlayer(0, deckFile, deckFileSmall); sprintf(deckFile, "%s/opponent_deck.txt", folder); sprintf(deckFileSmall, "campaign_ennemy_%s_%s", mParent->folder.c_str(), pageId.c_str()); - players[1] = NEW AIPlayerBaka(deckFile, deckFileSmall, "baka.jpg"); + players[1] = NEW AIPlayerBaka(0, deckFile, deckFileSmall, "baka.jpg"); string rulesFile = folder; rulesFile.append("/rules.txt"); rules = NEW Rules(bg); rules->load(rulesFile); - GameObserver::Init(players, 2); - game = GameObserver::GetInstance(); + game = new GameObserver(players, 2); + rules->gamemode = GAME_TYPE_STORY; game->startGame(rules); } @@ -364,8 +364,7 @@ StoryDuel::StoryDuel(TiXmlElement* root, StoryFlow * mParent) : StoryDuel::~StoryDuel() { SAFE_DELETE(rules); - if (game) GameObserver::EndInstance(); - game = NULL; + SAFE_DELETE(game); } void StoryDuel::Update(float dt) @@ -378,8 +377,7 @@ void StoryDuel::Update(float dt) mParent->gotoPage(onWin); else mParent->gotoPage(onLose); - GameObserver::EndInstance(); - game = NULL; + SAFE_DELETE(game); } } diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index de6adb298..c1406d00b 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -23,7 +23,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { MTGCardInstance * target = card->target; if (ability) target = (MTGCardInstance *) (ability->target); - return NEW CardTargetChooser(target, card); + return NEW CardTargetChooser(observer, target, card); }; found = s.find("opponent"); @@ -31,7 +31,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { int maxtargets = 1; Player * opponent = card->controller()->opponent(); - return NEW PlayerTargetChooser(card, maxtargets, opponent); + return NEW PlayerTargetChooser(observer, card, maxtargets, opponent); }; found = s.find("controller"); @@ -39,7 +39,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { int maxtargets = 1; Player * controller = card->controller(); - return NEW PlayerTargetChooser(card, maxtargets, controller); + return NEW PlayerTargetChooser(observer, card, maxtargets, controller); }; found = s.find("other "); @@ -55,10 +55,10 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta if (s.length() > 7 && s.find("[") == 7) { string s1 = s.substr(7, s.find("]")); - if (s1.find("to") != string::npos) return NEW TriggerTargetChooser(WEvent::TARGET_TO); - if (s1.find("from") != string::npos) return NEW TriggerTargetChooser(WEvent::TARGET_FROM); + if (s1.find("to") != string::npos) return NEW TriggerTargetChooser(observer, WEvent::TARGET_TO); + if (s1.find("from") != string::npos) return NEW TriggerTargetChooser(observer, WEvent::TARGET_FROM); } - return NEW TriggerTargetChooser(1); + return NEW TriggerTargetChooser(observer, 1); } found = s.find("player"); @@ -68,15 +68,15 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta size_t several = s.find(""); if (several != string::npos) maxtargets = TargetChooser::UNLITMITED_TARGETS; found = s.find("creature"); - if (found != string::npos) return NEW DamageableTargetChooser(card, maxtargets, other); //Any Damageable target (player, creature) - return NEW PlayerTargetChooser(card, maxtargets); //Any player + if (found != string::npos) return NEW DamageableTargetChooser(observer, card, maxtargets, other); //Any Damageable target (player, creature) + return NEW PlayerTargetChooser(observer, card, maxtargets); //Any player } found = s.find("proliferation"); if (found != string::npos) { int maxtargets = TargetChooser::UNLITMITED_TARGETS; - return NEW ProliferateChooser(card, maxtargets); //Any player + return NEW ProliferateChooser(observer, card, maxtargets); //Any player } string s1; @@ -202,11 +202,11 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta TargetChooser * deeperTc = NULL; if(s1.find("[") != string::npos) { - AbilityFactory af; + AbilityFactory af(observer); vectordeepTc = parseBetween(s1,"[","]"); deeperTc = createTargetChooser(deepTc[1],card); } - return NEW ParentChildChooser(card, maxtargets,deeperTc,s1.find("parents") != string::npos?2:1); + return NEW ParentChildChooser(observer, card, maxtargets,deeperTc,s1.find("parents") != string::npos?2:1); } while (s1.size()) @@ -528,7 +528,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta size_t start = attribute.find("{"); size_t end = attribute.find("}"); string counterString = attribute.substr(start + 1, end - start - 1); - AbilityFactory abf; + AbilityFactory abf(observer); Counter * counter = abf.parseCounter(counterString, card); if (counter) { @@ -603,7 +603,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { if (typeName.compare("*") != 0) cd->setSubtype(typeName); - tc = NEW DescriptorTargetChooser(cd, zones, nbzones, card, maxtargets, other, targetMin); + tc = NEW DescriptorTargetChooser(observer, cd, zones, nbzones, card, maxtargets, other, targetMin); } else { @@ -617,15 +617,15 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { if (typeName.compare("*") == 0) { - return NEW TargetZoneChooser(zones, nbzones, card, maxtargets, other, targetMin); + return NEW TargetZoneChooser(observer, zones, nbzones, card, maxtargets, other, targetMin); } else if (typeName.compare("this") == 0) { - return NEW CardTargetChooser(card, card, zones, nbzones); + return NEW CardTargetChooser(observer, card, card, zones, nbzones); } else { - tc = NEW TypeTargetChooser(typeName.c_str(), zones, nbzones, card, maxtargets, other, targetMin); + tc = NEW TypeTargetChooser(observer, typeName.c_str(), zones, nbzones, card, maxtargets, other, targetMin); } } else @@ -660,7 +660,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(MTGCardInstance * card #if defined (WIN32) || defined (LINUX) DebugTrace("Counter Spell !\n"); #endif - return NEW SpellTargetChooser(card); + return NEW SpellTargetChooser(observer, card); } //Spell Or Permanent case 1282: //ChaosLace @@ -669,22 +669,22 @@ TargetChooser * TargetChooserFactory::createTargetChooser(MTGCardInstance * card case 1227: //ThoughLace case 1257: //Lifelace { - return NEW SpellOrPermanentTargetChooser(card); + return NEW SpellOrPermanentTargetChooser(observer, card); } //Red Spell or Permanent case 1191: //Blue Elemental Blast { - return NEW SpellOrPermanentTargetChooser(card, Constants::MTG_COLOR_RED); + return NEW SpellOrPermanentTargetChooser(observer, card, Constants::MTG_COLOR_RED); } //Blue Spell or Permanent case 1312: //Red Elemental Blast { - return NEW SpellOrPermanentTargetChooser(card, Constants::MTG_COLOR_BLUE); + return NEW SpellOrPermanentTargetChooser(observer, card, Constants::MTG_COLOR_BLUE); } //Damage History case 1344: //Eye for an Eye { - return NEW DamageTargetChooser(card, -1, 1, RESOLVED_OK); + return NEW DamageTargetChooser(observer, card, -1, 1, RESOLVED_OK); } default: { @@ -693,8 +693,8 @@ TargetChooser * TargetChooserFactory::createTargetChooser(MTGCardInstance * card } } -TargetChooser::TargetChooser(MTGCardInstance * card, int _maxtargets, bool _other,bool _targetMin) : - TargetsList() +TargetChooser::TargetChooser(GameObserver *observer, MTGCardInstance * card, int _maxtargets, bool _other,bool _targetMin) : + TargetsList(), observer(observer) { forceTargetListReady = 0; source = card; @@ -705,7 +705,9 @@ TargetChooser::TargetChooser(MTGCardInstance * card, int _maxtargets, bool _othe done = false; attemptsToFill = 0; if(source) - Owner = source->controller(); + Owner = source->controller(); + else + Owner = 0; } //Default targetter : every card can be targetted, unless it is protected from the targetter card @@ -730,7 +732,7 @@ bool TargetChooser::canTarget(Targetable * target,bool withoutProtections) //this is kinda cheating but by default we let auras and equipments always continue to target a phased creature. else if(card->isPhased) return false; - if (source && targetter && card->isInPlay() && !withoutProtections) + if (source && targetter && card->isInPlay(observer) && !withoutProtections) { if (card->has(Constants::SHROUD)) return false; if (card->protectedAgainst(targetter)) return false; @@ -795,7 +797,7 @@ bool TargetChooser::validTargetsExist(int maxTargets) for (int i = 0; i < 2; ++i) { int maxAmount = 0; - Player *p = GameObserver::GetInstance()->players[i]; + Player *p = observer->players[i]; if (canTarget(p)) return true; MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->exile, p->game->stack }; for (int k = 0; k < 6; k++) @@ -820,7 +822,7 @@ int TargetChooser::countValidTargets() int result = 0; for (int i = 0; i < 2; ++i) { - Player *p = GameObserver::GetInstance()->players[i]; + Player *p = observer->players[i]; if(canTarget(p)) result++; MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->exile }; @@ -850,8 +852,8 @@ bool TargetChooser::equals(TargetChooser * tc) /** a specific Card **/ -CardTargetChooser::CardTargetChooser(MTGCardInstance * _card, MTGCardInstance * source, int * _zones, int _nbzones) : - TargetZoneChooser(_zones, _nbzones, source) +CardTargetChooser::CardTargetChooser(GameObserver *observer, MTGCardInstance * _card, MTGCardInstance * source, int * _zones, int _nbzones) : + TargetZoneChooser(observer, _zones, _nbzones, source) { validTarget = _card; } @@ -894,8 +896,8 @@ bool CardTargetChooser::equals(TargetChooser * tc) /** Choose anything that has a given list of types **/ -TypeTargetChooser::TypeTargetChooser(const char * _type, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : - TargetZoneChooser(card, _maxtargets, other,targetMin) +TypeTargetChooser::TypeTargetChooser(GameObserver *observer, const char * _type, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : + TargetZoneChooser(observer, card, _maxtargets, other,targetMin) { int id = Subtypes::subtypesList->find(_type); nbtypes = 0; @@ -904,9 +906,9 @@ TypeTargetChooser::TypeTargetChooser(const char * _type, MTGCardInstance * card, init(default_zones, 2); } -TypeTargetChooser::TypeTargetChooser(const char * _type, int * _zones, int nbzones, MTGCardInstance * card, int _maxtargets, +TypeTargetChooser::TypeTargetChooser(GameObserver *observer, const char * _type, int * _zones, int nbzones, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : - TargetZoneChooser(card, _maxtargets, other,targetMin) + TargetZoneChooser(observer, card, _maxtargets, other,targetMin) { int id = Subtypes::subtypesList->find(_type); nbtypes = 0; @@ -1006,17 +1008,17 @@ bool TypeTargetChooser ::equals(TargetChooser * tc) /** A Target Chooser associated to a Card Descriptor object, for fine tuning of targets description **/ -DescriptorTargetChooser::DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : - TargetZoneChooser(card, _maxtargets, other,targetMin) +DescriptorTargetChooser::DescriptorTargetChooser(GameObserver *observer, CardDescriptor * _cd, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : + TargetZoneChooser(observer, card, _maxtargets, other,targetMin) { int default_zones[] = { MTGGameZone::MY_BATTLEFIELD, MTGGameZone::OPPONENT_BATTLEFIELD }; init(default_zones, 2); cd = _cd; } -DescriptorTargetChooser::DescriptorTargetChooser(CardDescriptor * _cd, int * _zones, int nbzones, MTGCardInstance * card, +DescriptorTargetChooser::DescriptorTargetChooser(GameObserver *observer, CardDescriptor * _cd, int * _zones, int nbzones, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : - TargetZoneChooser(card, _maxtargets, other,targetMin) + TargetZoneChooser(observer, card, _maxtargets, other,targetMin) { if (nbzones == 0) { @@ -1077,14 +1079,14 @@ bool DescriptorTargetChooser::equals(TargetChooser * tc) } /* TargetzoneChooser targets everything in a given zone */ -TargetZoneChooser::TargetZoneChooser(MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : - TargetChooser(card, _maxtargets, other,targetMin) +TargetZoneChooser::TargetZoneChooser(GameObserver *observer, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : + TargetChooser(observer, card, _maxtargets, other,targetMin) { init(NULL, 0); } -TargetZoneChooser::TargetZoneChooser(int * _zones, int _nbzones, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : - TargetChooser(card, _maxtargets, other,targetMin) +TargetZoneChooser::TargetZoneChooser(GameObserver *observer, int * _zones, int _nbzones, MTGCardInstance * card, int _maxtargets, bool other,bool targetMin) : + TargetChooser(observer, card, _maxtargets, other,targetMin) { init(_zones, _nbzones); } @@ -1116,7 +1118,7 @@ bool TargetZoneChooser::canTarget(Targetable * target,bool withoutProtections) for (int i = 0; i < nbzones; i++) { if (zones[i] == MTGGameZone::ALL_ZONES) return true; - if (MTGGameZone::intToZone(zones[i], source, card)->hasCard(card)) return true; + if (MTGGameZone::intToZone(observer, zones[i], source, card)->hasCard(card)) return true; } } else if (target->typeAsTarget() == TARGET_STACKACTION) @@ -1128,7 +1130,7 @@ bool TargetZoneChooser::canTarget(Targetable * target,bool withoutProtections) Spell * spell = (Spell *) action; MTGCardInstance * card = spell->source; for (int i = 0; i < nbzones; i++) - if (MTGGameZone::intToZone(zones[i], source, card)->hasCard(card)) return true; + if (MTGGameZone::intToZone(Owner->getObserver(), zones[i], source, card)->hasCard(card)) return true; } } return false; @@ -1137,7 +1139,7 @@ bool TargetZoneChooser::canTarget(Targetable * target,bool withoutProtections) bool TargetZoneChooser::targetsZone(MTGGameZone * z) { for (int i = 0; i < nbzones; i++) - if (MTGGameZone::intToZone(zones[i], source) == z) return true; + if (MTGGameZone::intToZone(Owner->getObserver(), zones[i], source) == z) return true; return false; } bool TargetZoneChooser::targetsZone(MTGGameZone * z,MTGCardInstance * mSource) @@ -1145,7 +1147,7 @@ bool TargetZoneChooser::targetsZone(MTGGameZone * z,MTGCardInstance * mSource) if(mSource) source = mSource; for (int i = 0; i < nbzones; i++) - if (MTGGameZone::intToZone(zones[i], source) == z) return true; + if (MTGGameZone::intToZone(source->owner->getObserver(), zones[i], source) == z) return true; return false; } @@ -1185,8 +1187,8 @@ bool TargetZoneChooser::equals(TargetChooser * tc) } /* Player Target */ -PlayerTargetChooser::PlayerTargetChooser(MTGCardInstance * card, int _maxtargets, Player *p) : - TargetChooser(card, _maxtargets), p(p) +PlayerTargetChooser::PlayerTargetChooser(GameObserver *observer, MTGCardInstance * card, int _maxtargets, Player *p) : + TargetChooser(observer, card, _maxtargets), p(p) { } @@ -1260,8 +1262,8 @@ bool DamageableTargetChooser::equals(TargetChooser * tc) /*Spell */ -SpellTargetChooser::SpellTargetChooser(MTGCardInstance * card, int _color, int _maxtargets, bool other,bool targetMin) : - TargetChooser(card, _maxtargets, other,targetMin) +SpellTargetChooser::SpellTargetChooser(GameObserver *observer, MTGCardInstance * card, int _color, int _maxtargets, bool other,bool targetMin) : + TargetChooser(observer, card, _maxtargets, other,targetMin) { color = _color; } @@ -1303,8 +1305,8 @@ bool SpellTargetChooser::equals(TargetChooser * tc) } /*Spell or Permanent */ -SpellOrPermanentTargetChooser::SpellOrPermanentTargetChooser(MTGCardInstance * card, int _color, int _maxtargets, bool other,bool targetMin) : - TargetZoneChooser(card, _maxtargets, other,targetMin) +SpellOrPermanentTargetChooser::SpellOrPermanentTargetChooser(GameObserver *observer, MTGCardInstance * card, int _color, int _maxtargets, bool other,bool targetMin) : + TargetZoneChooser(observer, card, _maxtargets, other,targetMin) { int default_zones[] = { MTGGameZone::MY_BATTLEFIELD, MTGGameZone::OPPONENT_BATTLEFIELD }; init(default_zones, 2); @@ -1352,8 +1354,8 @@ bool SpellOrPermanentTargetChooser::equals(TargetChooser * tc) } /*Damage */ -DamageTargetChooser::DamageTargetChooser(MTGCardInstance * card, int _color, int _maxtargets, int _state) : - TargetChooser(card, _maxtargets) +DamageTargetChooser::DamageTargetChooser(GameObserver *observer, MTGCardInstance * card, int _color, int _maxtargets, int _state) : + TargetChooser(observer, card, _maxtargets) { color = _color; state = _state; @@ -1394,7 +1396,8 @@ bool DamageTargetChooser::equals(TargetChooser * tc) return TargetChooser::equals(tc); } -TriggerTargetChooser::TriggerTargetChooser(int _triggerTarget) +TriggerTargetChooser::TriggerTargetChooser(GameObserver *observer, int _triggerTarget) + : TargetChooser(observer) { triggerTarget = _triggerTarget; target = NULL; @@ -1532,4 +1535,4 @@ bool ParentChildChooser::equals(TargetChooser * tc) ParentChildChooser::~ParentChildChooser() { SAFE_DELETE(deeperTargeting); -} \ No newline at end of file +} diff --git a/projects/mtg/src/TargetsList.cpp b/projects/mtg/src/TargetsList.cpp index da3ce8636..da03a4dc0 100644 --- a/projects/mtg/src/TargetsList.cpp +++ b/projects/mtg/src/TargetsList.cpp @@ -20,8 +20,7 @@ int TargetsList::addTarget(Targetable * target) { if (!alreadyHasTarget(target)) { - GameObserver * state = state->GetInstance(); - TargetChooser * tc = state->getCurrentTargetChooser(); + TargetChooser * tc = target->getObserver()->getCurrentTargetChooser(); if(!tc || (tc && tc->maxtargets == 1)) { //because this was originally coded with targets as an array @@ -39,7 +38,6 @@ int TargetsList::addTarget(Targetable * target) } } return 0; - } int TargetsList::alreadyHasTarget(Targetable * target) diff --git a/projects/mtg/src/Tasks.cpp b/projects/mtg/src/Tasks.cpp index d5e0259b0..0b9228a47 100644 --- a/projects/mtg/src/Tasks.cpp +++ b/projects/mtg/src/Tasks.cpp @@ -431,13 +431,13 @@ void TaskList::passOneDay() } } -void TaskList::getDoneTasks(Player * _p1, Player * _p2, GameApp * _app, vector* result) +void TaskList::getDoneTasks(GameObserver* observer, GameApp * _app, vector* result) { result->clear(); // TODO: Return only accepted tasks for (vector::iterator it = tasks.begin(); it != tasks.end(); it++) { - if ((*it)->isDone(_p1, _p2, _app)) + if ((*it)->isDone(observer, _app)) { result->push_back(*it); } @@ -615,11 +615,10 @@ string TaskWinAgainst::getShortDesc() return result; } -bool TaskWinAgainst::isDone(Player * _p1, Player * _p2, GameApp * _app) +bool TaskWinAgainst::isDone(GameObserver* observer, GameApp * _app) { - GameObserver * g = GameObserver::GetInstance(); - AIPlayerBaka * baka = (AIPlayerBaka*) _p2; - return ((baka) && (!_p1->isAI()) && (_p2->isAI()) && (g->gameOver != _p1) // Human player wins + AIPlayerBaka * baka = (AIPlayerBaka*) observer->players[1]; + return ((baka) && (!observer->players[0]->isAI()) && (observer->players[1]->isAI()) && (observer->gameOver != observer->players[0]) // Human player wins && (baka->deckId == opponent)); } @@ -670,9 +669,9 @@ string TaskSlaughter::getShortDesc() return buffer; } -bool TaskSlaughter::isDone(Player * _p1, Player * _p2, GameApp * _app) +bool TaskSlaughter::isDone(GameObserver* observer, GameApp * _app) { - return TaskWinAgainst::isDone(_p1, _p2, _app) && (_p2->life <= targetLife); + return TaskWinAgainst::isDone(observer, _app) && (observer->players[1]->life <= targetLife); } void TaskSlaughter::storeCustomAttribs() @@ -756,10 +755,9 @@ string TaskDelay::getShortDesc() return buffer; } -bool TaskDelay::isDone(Player * _p1, Player * _p2, GameApp * _app) +bool TaskDelay::isDone(GameObserver* observer, GameApp * _app) { - GameObserver * g = GameObserver::GetInstance(); - return TaskWinAgainst::isDone(_p1, _p2, _app) && (afterTurn ? (g->turn >= turn) : (g->turn <= turn)); + return TaskWinAgainst::isDone(observer, _app) && (afterTurn ? (observer->turn >= turn) : (observer->turn <= turn)); } void TaskDelay::storeCustomAttribs() @@ -824,11 +822,10 @@ string TaskImmortal::getShortDesc() return buffer; } -bool TaskImmortal::isDone(Player * _p1, Player * _p2, GameApp * _app) +bool TaskImmortal::isDone(GameObserver *observer, GameApp * _app) { - GameObserver * g = GameObserver::GetInstance(); - return (!_p1->isAI()) && (_p2->isAI()) && (g->gameOver != _p1) // Human player wins - && (_p1->life >= targetLife); + return (!observer->players[0]->isAI()) && (observer->players[1]->isAI()) && (observer->gameOver != observer->players[0]) // Human player wins + && (observer->players[1]->life >= targetLife); } void TaskImmortal::storeCustomAttribs() @@ -920,10 +917,10 @@ string TaskMassiveBurial::getShortDesc() return buffer; } -bool TaskMassiveBurial::isDone(Player * _p1, Player * _p2, GameApp * _app) +bool TaskMassiveBurial::isDone(GameObserver* observer, GameApp * _app) { int countColor = 0; - vector cards = _p2->game->graveyard->cards; + vector cards = observer->players[1]->game->graveyard->cards; for (vector::iterator it = cards.begin(); it != cards.end(); it++) { @@ -1013,11 +1010,10 @@ string TaskWisdom::getShortDesc() return buffer; } -bool TaskWisdom::isDone(Player * _p1, Player * _p2, GameApp * _app) +bool TaskWisdom::isDone(GameObserver* observer, GameApp * _app) { - GameObserver * g = GameObserver::GetInstance(); int countColor = 0; - vector cards = _p1->game->hand->cards; + vector cards = observer->players[0]->game->hand->cards; for (vector::iterator it = cards.begin(); it != cards.end(); it++) { @@ -1027,7 +1023,7 @@ bool TaskWisdom::isDone(Player * _p1, Player * _p2, GameApp * _app) } } - return (!_p1->isAI()) && (_p2->isAI()) && (g->gameOver != _p1) // Human player wins + return (!observer->players[0]->isAI()) && (observer->players[1]->isAI()) && (observer->gameOver != observer->players[0]) // Human player wins && (countColor >= cardCount); } @@ -1095,11 +1091,10 @@ string TaskPacifism::getShortDesc() return buffer; } -bool TaskPacifism::isDone(Player * _p1, Player * _p2, GameApp * _app) +bool TaskPacifism::isDone(GameObserver* observer, GameApp * _app) { - GameObserver * g = GameObserver::GetInstance(); - return (!_p1->isAI()) && (_p2->isAI()) && (g->gameOver != _p1) // Human player wins - && (_p2->life >= lifeSlashCardMin) && ((int) _p2->game->library->cards.size() >= lifeSlashCardMin); + return (!observer->players[0]->isAI()) && (observer->players[1]->isAI()) && (observer->gameOver != observer->players[0]) // Human player wins + && (observer->players[1]->life >= lifeSlashCardMin) && ((int) observer->players[1]->game->library->cards.size() >= lifeSlashCardMin); } void TaskPacifism::storeCustomAttribs() @@ -1154,11 +1149,9 @@ void TaskPacifism::randomize() return buffer; } - bool TaskXX::isDone(Player * _p1, Player * _p2, GameApp * _app) { - GameObserver * g = GameObserver::GetInstance(); + bool TaskXX::isDone(GameObserver* observer, GameApp * _app) { // TODO: Implement - return (!_p1->isAI()) && (_p2->isAI()) && (g->gameOver != _p1) // Human player wins - && ; + return (!observer->players[0]->isAI()) && (observer->players[1]->isAI()) && (observer->gameOver != _p1) // Human player wins } void TaskXX::storeCustomAttribs() { diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 62e02a34e..1e0cb12fd 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -15,11 +15,12 @@ using std::string; // NULL is sent in place of a MTGDeck since there is no way to create a MTGDeck without a proper deck file. // TestSuiteAI will be responsible for managing its own deck state. -TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId) : - AIPlayerBaka("testsuite", "testsuite", "baka.jpg", NULL) +TestSuiteAI::TestSuiteAI(GameObserver *observer, TestSuite * _suite, int playerId) : + AIPlayerBaka(observer, "testsuite", "testsuite", "baka.jpg", NULL) { - this->game = _suite->buildDeck(playerId); + game = _suite->buildDeck(this, playerId); game->setOwner(this); + suite = _suite; timer = 0; playMode = MODE_TEST_SUITE; @@ -29,14 +30,13 @@ TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId) : MTGCardInstance * TestSuiteAI::getCard(string action) { int mtgid = Rules::getMTGId(action); - if (mtgid) return Rules::getCardByMTGId(mtgid); + if (mtgid) return Rules::getCardByMTGId(observer, mtgid); //This mostly handles tokens - GameObserver * g = GameObserver::GetInstance(); std::transform(action.begin(), action.end(), action.begin(), ::tolower); for (int i = 0; i < 2; i++) { - Player * p = g->players[i]; + Player * p = observer->players[i]; MTGGameZone * zones[] = { p->game->library, p->game->hand, p->game->inPlay, p->game->graveyard }; for (int j = 0; j < 4; j++) { @@ -54,9 +54,9 @@ MTGCardInstance * TestSuiteAI::getCard(string action) return NULL; } -Interruptible * TestSuite::getActionByMTGId(int mtgid) +Interruptible * TestSuite::getActionByMTGId(GameObserver* observer, int mtgid) { - ActionStack * as = GameObserver::GetInstance()->mLayers->stackLayer(); + ActionStack * as = observer->mLayers->stackLayer(); Interruptible * action = NULL; while ((action = as->getNext(action, 0, 0, 1))) { @@ -76,14 +76,13 @@ int TestSuiteAI::displayStack() int TestSuiteAI::Act(float dt) { - GameObserver * g = GameObserver::GetInstance(); - g->gameOver = NULL; // Prevent draw rule from losing the game + observer->gameOver = NULL; // Prevent draw rule from losing the game //Last bits of initialization require to be done here, after the first "update" call of the game if (suite->currentAction == 0) { for (int i = 0; i < 2; ++ i) - g->players[i]->getManaPool()->copy(suite->initState.playerData[i].manapool); + observer->players[i]->getManaPool()->copy(suite->initState.players[i]->getManaPool()); } if (playMode == MODE_AI && suite->aiMaxCalls) @@ -94,7 +93,7 @@ int TestSuiteAI::Act(float dt) } if (playMode == MODE_HUMAN) { - g->mLayers->CheckUserInput(0); + observer->mLayers->CheckUserInput(0); suite->currentAction++; //hack to avoid repeating the initialization of manapool return 1; } @@ -104,14 +103,14 @@ int TestSuiteAI::Act(float dt) timer = 0; string action = suite->getNextAction(); - g->mLayers->stackLayer()->Dump(); + observer->mLayers->stackLayer()->Dump(); DebugTrace("TESTSUITE command: " << action); - if (g->mLayers->stackLayer()->askIfWishesToInterrupt == this) + if (observer->mLayers->stackLayer()->askIfWishesToInterrupt == this) { if (action.compare("no") != 0 && action.compare("yes") != 0) { - g->mLayers->stackLayer()->cancelInterruptOffer(); + observer->mLayers->stackLayer()->cancelInterruptOffer(); suite->currentAction--; return 1; } @@ -120,16 +119,16 @@ int TestSuiteAI::Act(float dt) if (action == "") { //end of game - suite->assertGame(); - g->gameOver = g->players[0]; + suite->assertGame(observer); + observer->gameOver = observer->players[0]; DebugTrace("================================ END OF TEST =======================\n"); return 1; } if (action.compare("eot") == 0) { - if (g->getCurrentGamePhase() != Constants::MTG_PHASE_CLEANUP) suite->currentAction--; - g->userRequestNextGamePhase(); + if (observer->getCurrentGamePhase() != Constants::MTG_PHASE_CLEANUP) suite->currentAction--; + observer->userRequestNextGamePhase(); } else if (action.compare("human") == 0) { @@ -157,60 +156,61 @@ int TestSuiteAI::Act(float dt) phaseToGo = i; } } - if(g->currentGamePhase != phaseToGo) + if(observer->currentGamePhase != phaseToGo) suite->currentAction--; else { return 1; } - GuiCombat * gc = g->mLayers->combatLayer(); - if (ORDER == g->combatStep || DAMAGE == g->combatStep) + GuiCombat * gc = observer->mLayers->combatLayer(); + if (ORDER == observer->combatStep || DAMAGE == observer->combatStep) { gc->clickOK(); } else { - g->userRequestNextGamePhase(); + observer->userRequestNextGamePhase(); } } else { - GuiCombat * gc = g->mLayers->combatLayer(); - if (ORDER == g->combatStep || DAMAGE == g->combatStep) + GuiCombat * gc = observer->mLayers->combatLayer(); + if (ORDER == observer->combatStep || DAMAGE == observer->combatStep) gc->clickOK(); else - g->userRequestNextGamePhase(); + observer->userRequestNextGamePhase(); } } else if (action.compare("yes") == 0) - g->mLayers->stackLayer()->setIsInterrupting(this); + observer->mLayers->stackLayer()->setIsInterrupting(this); else if (action.compare("endinterruption") == 0) - g->mLayers->stackLayer()->endOfInterruption(); + observer->mLayers->stackLayer()->endOfInterruption(); else if (action.compare("no") == 0) { - if (g->mLayers->stackLayer()->askIfWishesToInterrupt == this) g->mLayers->stackLayer()->cancelInterruptOffer(); + if (observer->mLayers->stackLayer()->askIfWishesToInterrupt == this) + observer->mLayers->stackLayer()->cancelInterruptOffer(); } else if (action.find("choice ") != string::npos) { DebugTrace("TESTSUITE choice !!!"); int choice = atoi(action.substr(action.find("choice ") + 7).c_str()); - g->mLayers->actionLayer()->doReactTo(choice); + observer->mLayers->actionLayer()->doReactTo(choice); } else if (action.find(" -momir- ") != string::npos) { int start = action.find(" -momir- "); int cardId = Rules::getMTGId(action.substr(start + 9).c_str()); int cardIdHand = Rules::getMTGId(action.substr(0, start).c_str()); - MTGMomirRule * a = ((MTGMomirRule *) g->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR)); - a->reactToClick(Rules::getCardByMTGId(cardIdHand), cardId); - g->mLayers->actionLayer()->stuffHappened = 1; + MTGMomirRule * a = ((MTGMomirRule *) observer->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR)); + a->reactToClick(Rules::getCardByMTGId(observer, cardIdHand), cardId); + observer->mLayers->actionLayer()->stuffHappened = 1; } else if (action.find("p1") != string::npos || action.find("p2") != string::npos) { - Player * p = g->players[1]; + Player * p = observer->players[1]; size_t start = action.find("p1"); - if (start != string::npos) p = g->players[0]; - g->cardClick(NULL, p); + if (start != string::npos) p = observer->players[0]; + observer->cardClick(NULL, p); } else { @@ -219,12 +219,12 @@ int TestSuiteAI::Act(float dt) if (mtgid) { DebugTrace("TESTSUITE CARD ID:" << mtgid); - toInterrupt = suite->getActionByMTGId(mtgid); + toInterrupt = suite->getActionByMTGId(observer, mtgid); } if (toInterrupt) { - g->stackObjectClicked(toInterrupt); + observer->stackObjectClicked(toInterrupt); return 1; } @@ -233,8 +233,8 @@ int TestSuiteAI::Act(float dt) { DebugTrace("TESTSUITE Clicking ON: " << card->name); card->currentZone->needShuffle = true; //mimic library shuffle - g->cardClick(card, card); - g->forceShuffleLibraries(); //mimic library shuffle + observer->cardClick(card, card); + observer->forceShuffleLibraries(); //mimic library shuffle return 1; } } @@ -252,97 +252,20 @@ void TestSuiteActions::add(string s) nbitems++; } -TestSuitePlayerData::TestSuitePlayerData() -{ - life = 20; - manapool = NEW ManaCost(); -} - -TestSuitePlayerData::~TestSuitePlayerData() -{ - SAFE_DELETE(manapool); -} - -TestSuitePlayerZone::TestSuitePlayerZone() -{ - nbitems = 0; -} - -void TestSuitePlayerZone::add(int cardId) -{ - cards[nbitems] = cardId; - nbitems++; -} TestSuiteState::TestSuiteState() { - + players[0] = 0; + players[1] = 0; } void TestSuiteState::parsePlayerState(int playerId, string s) { - size_t limiter = s.find(":"); - string areaS; - int area; - if (limiter != string::npos) - { - areaS = s.substr(0, limiter); - if (areaS.compare("graveyard") == 0) - { - area = 0; - } - else if (areaS.compare("library") == 0) - { - area = 1; - } - else if (areaS.compare("hand") == 0) - { - area = 2; - } - else if (areaS.compare("inplay") == 0 || areaS.compare("battlefield") == 0) - { - area = 3; - } - else if (areaS.compare("life") == 0) - { - playerData[playerId].life = atoi((s.substr(limiter + 1)).c_str()); - return; - } - else if (areaS.compare("manapool") == 0) - { - SAFE_DELETE(playerData[playerId].manapool); - playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter + 1)); - return; - } - else - { - return; // ERROR - } - s = s.substr(limiter + 1); - while (s.size()) - { - unsigned int value; - limiter = s.find(","); - if (limiter != string::npos) - { - string ss = s.substr(0, limiter); // ss is needed because trim requires a non-const reference, - value = Rules::getMTGId(trim(ss)); // while in g++ functions cannot take non-const references from temporary values - s = s.substr(limiter + 1); - } - else - { - value = Rules::getMTGId(trim(s)); - s = ""; - } - if (value) playerData[playerId].zones[area].add(value); - } - } - else - { - //ERROR - } + stringstream stream(s); + stream >> *players[playerId]; } + string TestSuite::getNextAction() { currentAction++; @@ -353,24 +276,38 @@ string TestSuite::getNextAction() return ""; } -MTGPlayerCards * TestSuite::buildDeck(int playerId) +MTGPlayerCards * TestSuite::buildDeck(Player* player, int playerId) { int list[100]; int nbcards = 0; - for (int j = 0; j < 4; j++) + MTGPlayerCards * deck = NULL; + + if(initState.players[playerId]) { - for (int k = 0; k < initState.playerData[playerId].zones[j].nbitems; k++) + MTGGameZone * loadedPlayerZones[] = { initState.players[playerId]->game->graveyard, + initState.players[playerId]->game->library, + initState.players[playerId]->game->hand, + initState.players[playerId]->game->inPlay }; + + for (int j = 0; j < 4; j++) { - int cardid = initState.playerData[playerId].zones[j].cards[k]; - list[nbcards] = cardid; - nbcards++; + for (int k = 0; k < loadedPlayerZones[j]->cards.size(); k++) + { + int cardid = loadedPlayerZones[j]->cards[k]->getId(); + list[nbcards] = cardid; + nbcards++; + } } + deck = NEW MTGPlayerCards(player, list, nbcards); + } + else + { + deck = NEW MTGPlayerCards(); } - MTGPlayerCards * deck = NEW MTGPlayerCards(list, nbcards); return deck; } -void TestSuite::initGame() +void TestSuite::initGame(GameObserver* g) { //The first test runs slowly, the other ones run faster. //This way a human can see what happens when testing a specific file, @@ -384,8 +321,7 @@ void TestSuite::initGame() { timerLimit = 3; } - //Put the GameObserver in the initial state - GameObserver * g = GameObserver::GetInstance(); + DebugTrace("TESTSUITE Init Game"); g->phaseRing->goToPhase(initState.phase, g->players[0]); g->currentGamePhase = initState.phase; @@ -393,20 +329,24 @@ void TestSuite::initGame() { AIPlayerBaka * p = (AIPlayerBaka *) (g->players[i]); p->forceBestAbilityUse = forceAbility; - p->life = initState.playerData[i].life; + p->life = initState.players[i]->life; MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay }; + MTGGameZone * loadedPlayerZones[] = { initState.players[i]->game->graveyard, + initState.players[i]->game->library, + initState.players[i]->game->hand, + initState.players[i]->game->inPlay }; for (int j = 0; j < 4; j++) { MTGGameZone * zone = playerZones[j]; - for (int k = 0; k < initState.playerData[i].zones[j].nbitems; k++) + for (int k = 0; k < loadedPlayerZones[j]->cards.size(); k++) { - MTGCardInstance * card = Rules::getCardByMTGId(initState.playerData[i].zones[j].cards[k]); + MTGCardInstance * card = Rules::getCardByMTGId(g, loadedPlayerZones[j]->cards[k]->getId()); if (card && zone != p->game->library) { if (zone == p->game->inPlay) { MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack); - Spell * spell = NEW Spell(copy); + Spell * spell = NEW Spell(g, copy); spell->resolve(); if (!summoningSickness && p->game->inPlay->nb_cards > k) p->game->inPlay->cards[k]->summoningSickness = 0; delete spell; @@ -431,8 +371,9 @@ void TestSuite::initGame() zone->cardsSeenThisTurn.clear(); //don't consider those cards as having moved in this area during this turn } p->game->stack->cardsSeenThisTurn.clear(); //don't consider those cards as having moved in this area during this turn + } -DebugTrace("TESTUITE Init Game Done !"); + DebugTrace("TESTUITE Init Game Done !"); } int TestSuite::Log(const char * text) { @@ -448,7 +389,7 @@ int TestSuite::Log(const char * text) return 1; } -int TestSuite::assertGame() +int TestSuite::assertGame(GameObserver* g) { //compare the game state with the results char result[4096]; @@ -458,7 +399,6 @@ int TestSuite::assertGame() int error = 0; bool wasAI = false; - GameObserver * g = GameObserver::GetInstance(); if (g->currentGamePhase != endState.phase) { sprintf(result, "==phase problem. Expected [ %s ](%i), got [ %s ](%i)==
", @@ -472,27 +412,27 @@ int TestSuite::assertGame() TestSuiteAI * p = (TestSuiteAI *) (g->players[i]); if (p->playMode == Player::MODE_AI) wasAI = true; - if (p->life != endState.playerData[i].life) + if (p->life != endState.players[i]->life) { sprintf(result, "==life problem for player %i. Expected %i, got %i==
", i, - endState.playerData[i].life, p->life); + endState.players[i]->life, p->life); Log(result); error++; } - if (!p->getManaPool()->canAfford(endState.playerData[i].manapool)) + if (!p->getManaPool()->canAfford(endState.players[i]->getManaPool())) { sprintf(result, "==Mana problem. Was expecting %i but got %i for player %i==
", - endState.playerData[i].manapool->getConvertedCost(), p->getManaPool()->getConvertedCost(), i); + endState.players[i]->getManaPool()->getConvertedCost(), p->getManaPool()->getConvertedCost(), i); Log(result); error++; } - if (!endState.playerData[i].manapool->canAfford(p->getManaPool())) + if (!endState.players[i]->getManaPool()->canAfford(p->getManaPool())) { sprintf(result, "==Mana problem. Was expecting %i but got %i for player %i==
", - endState.playerData[i].manapool->getConvertedCost(), p->getManaPool()->getConvertedCost(), i); + endState.players[i]->getManaPool()->getConvertedCost(), p->getManaPool()->getConvertedCost(), i); Log(result); - if ( endState.playerData[i].manapool->getConvertedCost() == p->getManaPool()->getConvertedCost()) + if ( endState.players[i]->getManaPool()->getConvertedCost() == p->getManaPool()->getConvertedCost()) { sprintf(result, "====(Apparently Mana Color issues since converted cost is the same)==
"); Log(result); @@ -501,27 +441,31 @@ int TestSuite::assertGame() } MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay }; + MTGGameZone * endstateZones[] = { endState.players[i]->game->graveyard, + endState.players[i]->game->library, + endState.players[i]->game->hand, + endState.players[i]->game->inPlay }; for (int j = 0; j < 4; j++) { MTGGameZone * zone = playerZones[j]; - if (zone->nb_cards != endState.playerData[i].zones[j].nbitems) + if (zone->nb_cards != endstateZones[j]->nb_cards) { sprintf( result, "==Card number not the same in player %i's %s==, expected %i, got %i
", - i, zone->getName(), endState.playerData[i].zones[j].nbitems, zone->nb_cards); + i, zone->getName(), endstateZones[j]->nb_cards, zone->nb_cards); Log(result); error++; } - for (int k = 0; k < endState.playerData[i].zones[j].nbitems; k++) + for (int k = 0; k < endstateZones[j]->nb_cards; k++) { - int cardid = endState.playerData[i].zones[j].cards[k]; - if (cardid != -1) - { - MTGCardInstance * card = Rules::getCardByMTGId(cardid); - if (!card || !zone->hasCard(card)) + MTGCardInstance* cardToCheck = (kcards.size())?endstateZones[j]->cards[k]:0; + if(cardToCheck) + { // Can be NULL if used "*" in the testcase. + MTGCardInstance* card = Rules::getCardByMTGId(g, cardToCheck->getId()); + if (card != 0 && !zone->hasCard(card)) { - sprintf(result, "==Card ID not the same. Didn't find %i
", cardid); + sprintf(result, "==Card ID not the same. Didn't find %i
", card->getId()); Log(result); error++; } @@ -637,36 +581,23 @@ void TestSuiteActions::cleanup() nbitems = 0; } -void TestSuitePlayerZone::cleanup() -{ - nbitems = 0; -} -void TestSuitePlayerData::cleanup() -{ - if (manapool) delete manapool; - manapool = NULL; - manapool = NEW ManaCost(); - for (int i = 0; i < 5; i++) - { - zones[i].cleanup(); - } - life = 20; -} - -void TestSuiteState::cleanup() +void TestSuiteState::cleanup(TestSuite* suite) { for (int i = 0; i < 2; i++) { - playerData[i].cleanup(); + SAFE_DELETE(players[i]); } + + players[0] = new TestSuiteAI(0, suite, 0); + players[1] = new TestSuiteAI(0, suite, 1);; } void TestSuite::cleanup() { currentAction = 0; - initState.cleanup(); - endState.cleanup(); + initState.cleanup(this); + endState.cleanup(this); actions.cleanup(); loadRandValues(""); } diff --git a/projects/mtg/src/ThisDescriptor.cpp b/projects/mtg/src/ThisDescriptor.cpp index 84bae62c2..1167225d9 100644 --- a/projects/mtg/src/ThisDescriptor.cpp +++ b/projects/mtg/src/ThisDescriptor.cpp @@ -31,7 +31,7 @@ int ThisDescriptor::matchValue(int value) return 0; } -ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s) +ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(GameObserver* observer, string s) { size_t found; @@ -116,7 +116,7 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s) size_t start = s.find("{"); size_t end = s.find("}"); string counterString = s.substr(start + 1, end - start - 1); - AbilityFactory abf; + AbilityFactory abf(observer); Counter * counter = abf.parseCounter(counterString, NULL); if (counter) { diff --git a/projects/mtg/src/Token.cpp b/projects/mtg/src/Token.cpp index 0be3dd960..9ce93fa85 100644 --- a/projects/mtg/src/Token.cpp +++ b/projects/mtg/src/Token.cpp @@ -26,3 +26,11 @@ Token::Token(string _name, MTGCardInstance * source, int _power, int _toughness) defenser = NULL; banding = NULL; } + +Token::Token(int id) : + MTGCardInstance() +{ + isToken = true; + name = "dummyToken"; + setMTGId(id); +}