diff --git a/projects/mtg/include/CardPrimitive.h b/projects/mtg/include/CardPrimitive.h index 064478bc5..f02cd7d16 100644 --- a/projects/mtg/include/CardPrimitive.h +++ b/projects/mtg/include/CardPrimitive.h @@ -103,7 +103,7 @@ public: bool hasSubtype(int _subtype); bool hasSubtype(const string& _subtype); bool hasType(int _type); - bool hasType(const char * type); + bool hasType(const string& type); void setManaCost(const string& value); ManaCost * getManaCost(); diff --git a/projects/mtg/include/DeckEditorMenu.h b/projects/mtg/include/DeckEditorMenu.h index d252785ec..6191d88bb 100644 --- a/projects/mtg/include/DeckEditorMenu.h +++ b/projects/mtg/include/DeckEditorMenu.h @@ -17,7 +17,7 @@ private: StatsWrapper *stw; public: - DeckEditorMenu(int id, JGuiListener* listener = NULL, int fontId = 1, const char * _title = "", DeckDataWrapper *selectedDeck = NULL, StatsWrapper *stats = NULL); + DeckEditorMenu(int id, JGuiListener* listener = NULL, int fontId = 1, const string& _title = "", DeckDataWrapper *selectedDeck = NULL, StatsWrapper *stats = NULL); void Render(); virtual ~DeckEditorMenu(); }; diff --git a/projects/mtg/include/DeckMenu.h b/projects/mtg/include/DeckMenu.h index 0f2376634..fa3035efd 100644 --- a/projects/mtg/include/DeckMenu.h +++ b/projects/mtg/include/DeckMenu.h @@ -79,7 +79,7 @@ public: virtual void Render(); virtual void Update(float dt); using JGuiController::Add; - virtual void Add(int id, const char * Text, string desc = "", bool forceFocus = false, DeckMetaData *deckMetaData = NULL); + virtual void Add(int id, const string& Text, const string& desc = "", bool forceFocus = false, DeckMetaData *deckMetaData = NULL); virtual void Close(); void updateScroller(); void RenderBackground(); diff --git a/projects/mtg/include/DeckMenuItem.h b/projects/mtg/include/DeckMenuItem.h index 67d48e9b5..53ee35d5e 100644 --- a/projects/mtg/include/DeckMenuItem.h +++ b/projects/mtg/include/DeckMenuItem.h @@ -77,9 +77,7 @@ public: } // Setters - void setDescription( const string description ) { mDescription = description; }; - - ; + void setDescription( const string& description ) { mDescription = description; } }; #endif diff --git a/projects/mtg/include/DeckStats.h b/projects/mtg/include/DeckStats.h index 428b538c8..39238c533 100644 --- a/projects/mtg/include/DeckStats.h +++ b/projects/mtg/include/DeckStats.h @@ -98,7 +98,7 @@ public: string getManaColorIndex(); void updateStats(string filename, MTGAllCards * collection); void updateStats(DeckDataWrapper *mtgDeck); - int countCardsByType(const char * _type, DeckDataWrapper * myDeck); + int countCardsByType(const string& _type, DeckDataWrapper * myDeck); float noLuck(int n, int a, int x); vector aiDeckNames; diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index 281e742ba..5b3bfcbbe 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -98,8 +98,8 @@ class GameObserver{ int cardClick(MTGCardInstance * card,Targetable * _object = NULL, bool log = true); GamePhase getCurrentGamePhase(); void setCurrentGamePhase(GamePhase phase) { mCurrentGamePhase = phase; }; - const char * getCurrentGamePhaseName(); - const char * getNextGamePhaseName(); + const string& getCurrentGamePhaseName(); + const string& getNextGamePhaseName(); void nextCombatStep(); void userRequestNextGamePhase(bool allowInterrupt = true, bool log = true); void cleanupPhase(); diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 7317c4142..ab708e5db 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -129,11 +129,11 @@ public: //types - void addType(char * type_text); + void addType(const string& type_text); virtual void addType(int id); - void setType(const char * type_text); - void setSubtype( string value); - int removeType(string value, int removeAll = 0); + void setType(const string& type_text); + void setSubtype(const string &value); + int removeType(const 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. diff --git a/projects/mtg/include/MTGDeck.h b/projects/mtg/include/MTGDeck.h index 3fe38b5f2..577d83c8f 100644 --- a/projects/mtg/include/MTGDeck.h +++ b/projects/mtg/include/MTGDeck.h @@ -19,7 +19,7 @@ class MTGPack; class MTGSetInfo { public: - MTGSetInfo(string _id); + MTGSetInfo(const string& _id); ~MTGSetInfo(); string id; //Short name: 10E, RAV, etc. Automatic from folder. string author; //Author of set, for crediting mod makers, etc. @@ -70,7 +70,7 @@ public: MTGSets(); ~MTGSets(); - int Add(const char * subtype); + int Add(const string& subtype); int findSet(string value); int findBlock(string s); int size(); @@ -127,8 +127,10 @@ public: MTGCard * getCardByName(string name); void loadFolder(const string& folder, const string& filename="" ); - int load(const char * config_file, const char * setName = NULL, int autoload = 1); - int countByType(const char * _type); + int load(const string& config_file); + int load(const string& config_file, const string& setName); + int load(const string& config_file, int set_id); + int countByType(const string& _type); int countByColor(int color); int countBySet(int setId); int totalCards(); @@ -218,8 +220,8 @@ public: int totalCards(); int totalPrice(); MTGDeck(MTGAllCards * _allcards); - MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_only = 0,int difficultySetting = 0); - int addRandomCards(int howmany, int * setIds = NULL, int nbSets = 0, int rarity = -1, const char * subtype = NULL, + MTGDeck(const string& config_file, MTGAllCards * _allcards, int meta_only = 0,int difficultySetting = 0); + int addRandomCards(int howmany, int * setIds = NULL, int nbSets = 0, int rarity = -1, const string& subtype = "", int * colors = NULL, int nbcolors = 0); int add(int cardid); int add(MTGDeck * deck); // adds the contents of "deck" into myself diff --git a/projects/mtg/include/MTGDefinitions.h b/projects/mtg/include/MTGDefinitions.h index 0db903015..86d11e14d 100644 --- a/projects/mtg/include/MTGDefinitions.h +++ b/projects/mtg/include/MTGDefinitions.h @@ -293,7 +293,7 @@ class Constants static map MTGBasicAbilitiesMap; static const char* MTGBasicAbilities[]; - static const char* MTGPhaseNames[]; + static const string MTGPhaseNames[]; static const char* MTGPhaseCodeNames[]; static int GetBasicAbilityIndex(string mtgAbility); diff --git a/projects/mtg/include/PhaseRing.h b/projects/mtg/include/PhaseRing.h index 2c116c1bf..3c3afd7cd 100644 --- a/projects/mtg/include/PhaseRing.h +++ b/projects/mtg/include/PhaseRing.h @@ -62,7 +62,7 @@ public: int addCombatAfter(Player* player, int after_id, bool withMain = false); int addPhaseAfter(GamePhase id, Player* player, int after_id); int removePhase(int id); - const char * phaseName(int id); + const string& phaseName(int id); static GamePhase phaseStrToInt(string s); static string phaseIntToStr(int id); diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index 6509bc217..4e4fe8948 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -57,7 +57,7 @@ void NextGamePhase::Render() if (observer->currentActionPlayer == observer->players[1]) playerId = 2; - sprintf(buffer, "%s %i : %s", _("Player").c_str(), playerId, observer->getNextGamePhaseName()); + sprintf(buffer, "%s %i : %s", _("Player").c_str(), playerId, observer->getNextGamePhaseName().c_str()); mFont->DrawString(buffer, x + 15, y+10, JGETEXT_LEFT); mFont->SetScale(DEFAULT_MAIN_FONT_SCALE); diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index 9946f138a..e564fb84e 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -344,7 +344,7 @@ bool CardPrimitive::hasSubtype(int _subtype) return hasType(_subtype); } -bool CardPrimitive::hasType(const char * _type) +bool CardPrimitive::hasType(const string& _type) { int id = MTGAllCards::findType(_type); return hasType(id); diff --git a/projects/mtg/src/DeckEditorMenu.cpp b/projects/mtg/src/DeckEditorMenu.cpp index 5af4b183a..f88695d9a 100644 --- a/projects/mtg/src/DeckEditorMenu.cpp +++ b/projects/mtg/src/DeckEditorMenu.cpp @@ -7,7 +7,7 @@ #include #include "Translate.h" -DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const char * _title, DeckDataWrapper *_selectedDeck, StatsWrapper *stats) : +DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const string& _title, DeckDataWrapper *_selectedDeck, StatsWrapper *stats) : DeckMenu(id, listener, fontId, _title), selectedDeck(_selectedDeck), stw(stats) { backgroundName = "DeckEditorMenuBackdrop"; diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index 98122f87a..8524fc90e 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -370,7 +370,7 @@ void DeckMenu::Update(float dt) } -void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, DeckMetaData * deckMetaData) +void DeckMenu::Add(int id, const string& text, const string& desc, bool forceFocus, DeckMetaData * deckMetaData) { DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0, mY + DeckMenuConst::kVerticalMargin + mCount * DeckMenuConst::kLineHeight, (mCount == 0), mAutoTranslate, deckMetaData); diff --git a/projects/mtg/src/DeckStats.cpp b/projects/mtg/src/DeckStats.cpp index 9f50b2a7c..677760bb6 100644 --- a/projects/mtg/src/DeckStats.cpp +++ b/projects/mtg/src/DeckStats.cpp @@ -587,7 +587,7 @@ void StatsWrapper::updateStats(DeckDataWrapper *myDeck) // This should probably be cached in DeckDataWrapper // or at least be calculated for all common types in one go -int StatsWrapper::countCardsByType(const char * _type, DeckDataWrapper * myDeck) +int StatsWrapper::countCardsByType(const string& _type, DeckDataWrapper * myDeck) { int result = 0; for (int i = 0; i < myDeck->Size(true); i++) diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 7d16dfdd1..ed01c26d5 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -110,12 +110,12 @@ GamePhase GameObserver::getCurrentGamePhase() return mCurrentGamePhase; } -const char* GameObserver::getCurrentGamePhaseName() +const string& GameObserver::getCurrentGamePhaseName() { return phaseRing->phaseName(mCurrentGamePhase); } -const char* GameObserver::getNextGamePhaseName() +const string& GameObserver::getNextGamePhaseName() { return phaseRing->phaseName((mCurrentGamePhase + 1) % MTG_PHASE_CLEANUP); } diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index b82265623..43b63a9df 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -818,9 +818,9 @@ void GameSettings::createUsersFirstDeck(int setId) mCollection->addRandomCards(10, 0, 0, Constants::RARITY_L, "Island"); //Starter Deck - mCollection->addRandomCards(3, sets, 1, Constants::RARITY_R, NULL); - mCollection->addRandomCards(9, sets, 1, Constants::RARITY_U, NULL); - mCollection->addRandomCards(48, sets, 1, Constants::RARITY_C, NULL); + mCollection->addRandomCards(3, sets, 1, Constants::RARITY_R); + mCollection->addRandomCards(9, sets, 1, Constants::RARITY_U); + mCollection->addRandomCards(48, sets, 1, Constants::RARITY_C); //Boosters for (int i = 0; i < 2; i++) diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index a44f1aae2..b1855b014 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -254,22 +254,22 @@ void MTGCardInstance::addType(int type) SAFE_DELETE(e); } -void MTGCardInstance::addType(char * type_text) +void MTGCardInstance::addType(const string& type_text) { setSubtype(type_text); } -void MTGCardInstance::setType(const char * type_text) +void MTGCardInstance::setType(const string& type_text) { setSubtype(type_text); } -void MTGCardInstance::setSubtype(string value) +void MTGCardInstance::setSubtype(const string& value) { int id = MTGAllCards::findType(value); addType(id); } -int MTGCardInstance::removeType(string value, int removeAll) +int MTGCardInstance::removeType(const string& value, int removeAll) { int id = MTGAllCards::findType(value); return removeType(id, removeAll); diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index c97b838a3..7359271b7 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -381,10 +381,20 @@ void MTGAllCards::loadFolder(const string& infolder, const string& filename ) } } -int MTGAllCards::load(const char * config_file, const char * set_name, int) +int MTGAllCards::load(const string &config_file) +{ + return load(config_file, MTGSets::INTERNAL_SET); +} + +int MTGAllCards::load(const string& config_file, const string &set_name) +{ + const int set_id = setlist.Add(set_name); + return load(config_file, set_id); +} + +int MTGAllCards::load(const string &config_file, int set_id) { conf_read_mode = 0; - const int set_id = set_name ? setlist.Add(set_name) : MTGSets::INTERNAL_SET; MTGSetInfo *si = setlist.getInfo(set_id); int lineNumber = 0; @@ -532,7 +542,7 @@ int MTGAllCards::countBySet(int setId) } //TODO more efficient way ? -int MTGAllCards::countByType(const char * _type) +int MTGAllCards::countByType(const string &_type) { int result = 0; map::iterator it; @@ -772,7 +782,7 @@ int MTGDeck::totalPrice() return total; } -MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_only,int difficultyRating) +MTGDeck::MTGDeck(const string& config_file, MTGAllCards * _allcards, int meta_only, int difficultyRating) { total_cards = 0; database = _allcards; @@ -879,7 +889,7 @@ MTGCard * MTGDeck::getCardById(int mtgId) return database->getCardById(mtgId); } -int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, const char * _subtype, int * colors, int nbcolors) +int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, const string &_subtype, int * colors, int nbcolors) { if (howmany <= 0) return 1; @@ -900,8 +910,8 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c int collectionTotal = database->totalCards(); if (!collectionTotal) return 0; - char subtype[4096]; - if (_subtype) sprintf(subtype, "%s", _subtype); + string subtype; + if (_subtype.size()) subtype = _subtype; vector subcollection; int subtotal = 0; @@ -911,7 +921,7 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c int r = card->getRarity(); if (r != Constants::RARITY_T && (rarity == -1 || r == rarity) && // remove tokens card->setId != MTGSets::INTERNAL_SET && //remove cards that are defined in primitives. Those are workarounds (usually tokens) and should only be used internally - (!_subtype || card->data->hasSubtype(subtype))) + (!_subtype.size() || card->data->hasSubtype(subtype))) { int ok = 0; @@ -1265,7 +1275,7 @@ MTGSetInfo* MTGSets::randomSet(int blockId, int atleast) int blockSize(int blockId); -int MTGSets::Add(const char * name) +int MTGSets::Add(const string& name) { int setid = findSet(name); if (setid != -1) return setid; @@ -1344,7 +1354,7 @@ MTGSetInfo::~MTGSetInfo() SAFE_DELETE(mPack); } -MTGSetInfo::MTGSetInfo(string _id) +MTGSetInfo::MTGSetInfo(const string& _id) { string whitespaces(" \t\f\v\n\r"); id = _id; diff --git a/projects/mtg/src/MTGDefinitions.cpp b/projects/mtg/src/MTGDefinitions.cpp index 1ebf044f8..eaecce696 100644 --- a/projects/mtg/src/MTGDefinitions.cpp +++ b/projects/mtg/src/MTGDefinitions.cpp @@ -162,7 +162,7 @@ int Constants::GetColorStringIndex(string mtgColor) return -1; } -const char* Constants::MTGPhaseNames[] = +const string Constants::MTGPhaseNames[] = { "---", "Untap", diff --git a/projects/mtg/src/PhaseRing.cpp b/projects/mtg/src/PhaseRing.cpp index 330790099..bb9fb82e3 100644 --- a/projects/mtg/src/PhaseRing.cpp +++ b/projects/mtg/src/PhaseRing.cpp @@ -142,9 +142,10 @@ bool PhaseRing::extraDamagePhase(int id) return false; } -const char * PhaseRing::phaseName(int id) +const string& PhaseRing::phaseName(int id) { - if (extraDamagePhase(id)) return "Combat Damage (2)"; + static const string combatPhase2("Combat Damage (2)"); + if (extraDamagePhase(id)) return combatPhase2; return Constants::MTGPhaseNames[id]; } diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index eeb279fd2..bb7e236ce 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -350,8 +350,8 @@ void TestSuiteGame::assertGame() if (observer->getCurrentGamePhase() != endState.phase) { sprintf(result, "==phase problem. Expected [ %s ](%i), got [ %s ](%i)==
", - Constants::MTGPhaseNames[endState.phase],endState.phase, - Constants::MTGPhaseNames[observer->getCurrentGamePhase()], observer->getCurrentGamePhase()); + Constants::MTGPhaseNames[endState.phase].c_str(),endState.phase, + Constants::MTGPhaseNames[observer->getCurrentGamePhase()].c_str(), observer->getCurrentGamePhase()); Log(result); error++; }