diff --git a/projects/mtg/include/CardPrimitive.h b/projects/mtg/include/CardPrimitive.h index 01889d011..0d044e899 100644 --- a/projects/mtg/include/CardPrimitive.h +++ b/projects/mtg/include/CardPrimitive.h @@ -13,7 +13,6 @@ using namespace std; class CardPrimitive { protected: - vector ftdText; string lcname; ManaCost manaCost; @@ -84,7 +83,6 @@ public: void getRestrictions(); void setOtherRestrictions(string _restriction); void getOtherRestrictions(); - const vector& formattedText(); }; diff --git a/projects/mtg/include/MTGCard.h b/projects/mtg/include/MTGCard.h index ff2483358..f7a59feaa 100644 --- a/projects/mtg/include/MTGCard.h +++ b/projects/mtg/include/MTGCard.h @@ -24,6 +24,7 @@ protected: int mtgid; char rarity; char image_name[MTGCARD_NAME_SIZE]; + vector mFormattedText; int init(); public: @@ -33,12 +34,15 @@ public: MTGCard(); MTGCard(int set_id); MTGCard(MTGCard * source); + virtual ~MTGCard(); void setMTGId(int id); void setRarity(char _rarity); //void setImageName( char * value); void setPrimitive(CardPrimitive * cp); + const vector& GetFormattedText(); + int getMTGId() const; int getId() const; char getRarity() const; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 0506183ab..ace35bec4 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -24,43 +24,44 @@ struct Pos; #include using namespace std; -class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { - protected: - int untapping; - int nb_damages; - string sample; - int tapped; - int lifeOrig; - MTGPlayerCards * belongs_to; - MTGCardInstance * getNextPartner(); - void initMTGCI(); - int addBlocker(MTGCardInstance * c); - int removeBlocker(MTGCardInstance * c); - int init(); - public: - int setAttacker(int value); +class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable +{ +protected: + int untapping; + int nb_damages; + string sample; + int tapped; + int lifeOrig; + MTGPlayerCards * belongs_to; + MTGCardInstance * getNextPartner(); + void initMTGCI(); + int addBlocker(MTGCardInstance * c); + int removeBlocker(MTGCardInstance * c); + int init(); +public: + int setAttacker(int value); int setDefenser(MTGCardInstance * c); - MTGGameZone * currentZone; - Pos* view; - int X; - int XX; - int alternateCostPaid[ManaCost::MANA_PAID_WITH_RETRACE + 1]; - int paymenttype; - int castMethod; /* Tells if the card reached its current zone by being cast or not (brought into the zone by an effect). non 0 == cast, 0 == not cast */ - int frozen; - int sunburst; - int equipment; - int auras; - bool wasDealtDamage; - bool damageToOpponent; - bool damageToController; - int reduxamount; - int flanked; - int regenerateTokens; - int isToken; - int origpower; - int origtoughness; - int isMultiColored; + MTGGameZone * currentZone; + Pos* view; + int X; + int XX; + int alternateCostPaid[ManaCost::MANA_PAID_WITH_RETRACE + 1]; + int paymenttype; + int castMethod; /* Tells if the card reached its current zone by being cast or not (brought into the zone by an effect). non 0 == cast, 0 == not cast */ + int frozen; + int sunburst; + int equipment; + int auras; + bool wasDealtDamage; + bool damageToOpponent; + bool damageToController; + int reduxamount; + int flanked; + int regenerateTokens; + int isToken; + int origpower; + int origtoughness; + int isMultiColored; int isBlackAndWhite; int isRedAndBlue; int isBlackAndGreen; @@ -80,7 +81,7 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { bool graveEffects; bool exileEffects; bool suspended; - + int stillInUse(); int didattacked; int didblocked; @@ -88,121 +89,120 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { int fresh; int MaxLevelUp; Player * lastController; - MTGGameZone * getCurrentZone(); - MTGGameZone * previousZone; - MTGCardInstance * previous; - MTGCardInstance * next; - int doDamageTest; - int summoningSickness; - ManaCost reducedCost; - ManaCost increasedCost; - ManaCost * getReducedManaCost(); - ManaCost * getIncreasedManaCost(); + MTGGameZone * getCurrentZone(); + MTGGameZone * previousZone; + MTGCardInstance * previous; + MTGCardInstance * next; + int doDamageTest; + int summoningSickness; + ManaCost reducedCost; + ManaCost increasedCost; + ManaCost * getReducedManaCost(); + ManaCost * getIncreasedManaCost(); - bool matchesCastFilter(int castMethod); + bool matchesCastFilter(int castMethod); - // The recommended method to test for summoning Sickness ! - int hasSummoningSickness(); - MTGCardInstance * changeController(Player * newcontroller); - Player * owner; - Counters * counters; - int typeAsTarget(){return TARGET_CARD;} - const string getDisplayName() const; - MTGCardInstance * target; - Targetable * backupTargets[MAX_TARGETS]; + // The recommended method to test for summoning Sickness ! + int hasSummoningSickness(); + MTGCardInstance * changeController(Player * newcontroller); + Player * owner; + Counters * counters; + int typeAsTarget(){return TARGET_CARD;} + const string getDisplayName() const; + MTGCardInstance * target; + Targetable * backupTargets[MAX_TARGETS]; - //types - void addType(char * type_text); - virtual void addType(int id); - void setType(const char * type_text); - void setSubtype( string value); - int removeType(string value, int removeAll = 0); - int removeType(int value, int removeAll = 0); + //types + void addType(char * type_text); + virtual void addType(int id); + void setType(const char * type_text); + void setSubtype( string value); + int removeType(string value, int removeAll = 0); + int removeType(int value, int removeAll = 0); - //dangerranking is a hint to Ai which creatures are the ones it should be targetting for effects. - int DangerRanking(); - //Combat - bool blocked; //Blocked this turn or not? - MTGCardInstance * defenser; - listblockers; - int attacker; - int toggleDefenser(MTGCardInstance * opponent); - int raiseBlockerRankOrder(MTGCardInstance * blocker); + //dangerranking is a hint to Ai which creatures are the ones it should be targetting for effects. + int DangerRanking(); + //Combat + bool blocked; //Blocked this turn or not? + MTGCardInstance * defenser; + listblockers; + int attacker; + int toggleDefenser(MTGCardInstance * opponent); + int raiseBlockerRankOrder(MTGCardInstance * blocker); - //Returns rank of the card in blockers if it is a blocker of this (starting at 1), 0 otherwise - int getDefenserRank(MTGCardInstance * blocker); - int toggleAttacker(); - MTGCardInstance * banding; // If belongs to a band when attacking - int canBlock(); - int canBlock(MTGCardInstance * opponent); - int canAttack(); - int isAttacker(); - MTGCardInstance * isDefenser(); - int initAttackersDefensers(); - MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL); - int nbOpponents(); - int stepPower(CombatStep step); - int afterDamage(); - int has(int ability); - int cleanup(); + //Returns rank of the card in blockers if it is a blocker of this (starting at 1), 0 otherwise + int getDefenserRank(MTGCardInstance * blocker); + int toggleAttacker(); + MTGCardInstance * banding; // If belongs to a band when attacking + int canBlock(); + int canBlock(MTGCardInstance * opponent); + int canAttack(); + int isAttacker(); + MTGCardInstance * isDefenser(); + int initAttackersDefensers(); + MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL); + int nbOpponents(); + int stepPower(CombatStep step); + int afterDamage(); + int has(int ability); + int cleanup(); - MTGCard * model; - MTGCardInstance(); - MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to); - int regenerate(); - int triggerRegenerate(); - Player * controller(); + MTGCard * model; + MTGCardInstance(); + MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to); + int regenerate(); + int triggerRegenerate(); + Player * controller(); - virtual ~MTGCardInstance(); - int bury(); - int destroy(); + virtual ~MTGCardInstance(); + int bury(); + int destroy(); + int addToToughness(int value); + int setToughness(int value); - int addToToughness(int value); - int setToughness(int value); + vectorprotections; + int addProtection(TargetChooser * tc); + int removeProtection(TargetChooser *tc, int erase = 0); + int protectedAgainst(MTGCardInstance * card); - vectorprotections; - int addProtection(TargetChooser * tc); - int removeProtection(TargetChooser *tc, int erase = 0); - int protectedAgainst(MTGCardInstance * card); + vectorcanttarget; + int addCantBeTarget(TargetChooser * tc); + int removeCantBeTarget(TargetChooser *tc, int erase = 0); + int CantBeTargetby(MTGCardInstance * card); - vectorcanttarget; - int addCantBeTarget(TargetChooser * tc); - int removeCantBeTarget(TargetChooser *tc, int erase = 0); - int CantBeTargetby(MTGCardInstance * card); - - vectorcantBeBlockedBys; - int addCantBeBlockedBy(TargetChooser * tc); - int removeCantBeBlockedBy(TargetChooser *tc, int erase = 0); - int cantBeBlockedBy(MTGCardInstance * card); + vectorcantBeBlockedBys; + int addCantBeBlockedBy(TargetChooser * tc); + int removeCantBeBlockedBy(TargetChooser *tc, int erase = 0); + int cantBeBlockedBy(MTGCardInstance * card); - void copy(MTGCardInstance * card); + void copy(MTGCardInstance * card); - void setUntapping(); - int isUntapping(); - int isTapped(); - void untap(); - void tap(); - void attemptUntap(); + void setUntapping(); + int isUntapping(); + int isTapped(); + void untap(); + void tap(); + void attemptUntap(); - void eventattacked(); - void eventattackedAlone(); - void eventattackednotblocked(); - void eventattackedblocked(MTGCardInstance * opponent); - void eventblocked(MTGCardInstance * opponent); + void eventattacked(); + void eventattackedAlone(); + void eventattackednotblocked(); + void eventattackedblocked(MTGCardInstance * opponent); + void eventblocked(MTGCardInstance * opponent); - int isInPlay(); - JSample * getSample(); + int isInPlay(); + JSample * getSample(); - JQuadPtr getIcon(); + JQuadPtr getIcon(); - ostream& toString(ostream&) const; + ostream& toString(ostream&) const; - static MTGCardInstance AnyCard; - static MTGCardInstance NoCard; + static MTGCardInstance AnyCard; + static MTGCardInstance NoCard; - static MTGCardInstance ExtraRules[2]; + static MTGCardInstance ExtraRules[2]; }; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index d51107c1c..56192ff0b 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -1409,7 +1409,6 @@ int AIPlayerBaka::computeActions() //am im not interupting my own spell, or the stack contains nothing. { findingCard = true; - CardDescriptor cd; ManaCost * icurrentMana = getPotentialMana(); bool ipotential = false; if (icurrentMana->getConvertedCost()) @@ -1454,7 +1453,6 @@ int AIPlayerBaka::computeActions() } else if(p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) { //standard actions - CardDescriptor cd; switch (currentGamePhase) { case Constants::MTG_PHASE_FIRSTMAIN: diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 9aa0bbb85..aff187fd2 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -368,7 +368,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos) // Write the description { font->SetScale(kWidthScaleFactor * pos.actZ); - const std::vector txt = card->data->formattedText(); + const std::vector txt = card->GetFormattedText(); unsigned i = 0; unsigned h = neofont ? 14 : 11; for (std::vector::const_iterator it = txt.begin(); it != txt.end(); ++it, ++i) @@ -577,7 +577,7 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale); } - const std::vector txt = card->data->formattedText(); + const std::vector txt = card->GetFormattedText(); size_t nbTextLines = txt.size(); //Render the image on top of that @@ -785,12 +785,12 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos) void CardGui::RenderCountersBig(const Pos& pos) { // Write Named Counters - if (card->counters) + if (card->counters && card->counters->mCount > 0) { WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT); font->SetColor(ARGB((int)pos.actA, 0, 0, 0)); font->SetScale(kWidthScaleFactor * pos.actZ); - std::vector txt = card->formattedText(); + std::vector txt = card->GetFormattedText(); unsigned i = txt.size() + 1; Counter * c = NULL; for (int t = 0; t < card->counters->mCount; t++, i++) diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index 03cf1831d..5e8aee0ef 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -61,23 +61,6 @@ int CardPrimitive::init() return 1; } -const vector& CardPrimitive::formattedText() -{ - if (ftdText.empty()) - { - std::string s = text; - std::string::size_type found = s.find_first_of("{}"); - while (found != string::npos) - { - s[found] = '/'; - found = s.find_first_of("{}", found + 1); - } - WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT); - mFont->FormatText(s, ftdText); - } - return ftdText; -} - bool CardPrimitive::isCreature() { return hasSubtype(Subtypes::TYPE_CREATURE); diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 064694e3e..fd8a87539 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -251,10 +251,11 @@ void GameApp::Create() JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number); JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number); + DebugTrace("size of MTGCardInstance: " << sizeof(MTGCardInstance)); DebugTrace("size of MTGCard: "<< sizeof(MTGCard)); DebugTrace("size of CardPrimitive: "<< sizeof(CardPrimitive)); DebugTrace("size of ExtraCost: " << sizeof(ExtraCost)); - DebugTrace("Size of ManaCost: " << sizeof(ManaCost)); + DebugTrace("size of ManaCost: " << sizeof(ManaCost)); LOG("Game Creation Done."); } diff --git a/projects/mtg/src/MTGCard.cpp b/projects/mtg/src/MTGCard.cpp index d3bc3ab2e..6262cade2 100644 --- a/projects/mtg/src/MTGCard.cpp +++ b/projects/mtg/src/MTGCard.cpp @@ -23,9 +23,9 @@ MTGCard::MTGCard(int set_id) init(); setId = set_id; } + MTGCard::MTGCard(MTGCard * source) { - strcpy(image_name, source->image_name); rarity = source->rarity; mtgid = source->mtgid; @@ -33,6 +33,10 @@ MTGCard::MTGCard(MTGCard * source) data = source->data; } +MTGCard::~MTGCard() +{ +} + int MTGCard::init() { setId = 0; @@ -82,3 +86,23 @@ void MTGCard::setPrimitive(CardPrimitive * cp) { data = cp; } + +const vector& MTGCard::GetFormattedText() +{ + if (mFormattedText.empty()) + { + if (data != NULL) + { + std::string s = data->text; + std::string::size_type found = s.find_first_of("{}"); + while (found != string::npos) + { + s[found] = '/'; + found = s.find_first_of("{}", found + 1); + } + WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT); + mFont->FormatText(s, mFormattedText); + } + } + return mFormattedText; +} \ No newline at end of file