Substitute more char arrays with strings

This commit is contained in:
Tobias Loose
2013-11-23 12:57:31 +01:00
parent 3f0dd987f0
commit 9ee44ca091
22 changed files with 61 additions and 50 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ public:
bool hasSubtype(int _subtype); bool hasSubtype(int _subtype);
bool hasSubtype(const string& _subtype); bool hasSubtype(const string& _subtype);
bool hasType(int _type); bool hasType(int _type);
bool hasType(const char * type); bool hasType(const string& type);
void setManaCost(const string& value); void setManaCost(const string& value);
ManaCost * getManaCost(); ManaCost * getManaCost();
+1 -1
View File
@@ -17,7 +17,7 @@ private:
StatsWrapper *stw; StatsWrapper *stw;
public: 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(); void Render();
virtual ~DeckEditorMenu(); virtual ~DeckEditorMenu();
}; };
+1 -1
View File
@@ -79,7 +79,7 @@ public:
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
using JGuiController::Add; 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(); virtual void Close();
void updateScroller(); void updateScroller();
void RenderBackground(); void RenderBackground();
+1 -3
View File
@@ -77,9 +77,7 @@ public:
} }
// Setters // Setters
void setDescription( const string description ) { mDescription = description; }; void setDescription( const string& description ) { mDescription = description; }
;
}; };
#endif #endif
+1 -1
View File
@@ -98,7 +98,7 @@ public:
string getManaColorIndex(); string getManaColorIndex();
void updateStats(string filename, MTGAllCards * collection); void updateStats(string filename, MTGAllCards * collection);
void updateStats(DeckDataWrapper *mtgDeck); 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); float noLuck(int n, int a, int x);
vector<string> aiDeckNames; vector<string> aiDeckNames;
+2 -2
View File
@@ -98,8 +98,8 @@ class GameObserver{
int cardClick(MTGCardInstance * card,Targetable * _object = NULL, bool log = true); int cardClick(MTGCardInstance * card,Targetable * _object = NULL, bool log = true);
GamePhase getCurrentGamePhase(); GamePhase getCurrentGamePhase();
void setCurrentGamePhase(GamePhase phase) { mCurrentGamePhase = phase; }; void setCurrentGamePhase(GamePhase phase) { mCurrentGamePhase = phase; };
const char * getCurrentGamePhaseName(); const string& getCurrentGamePhaseName();
const char * getNextGamePhaseName(); const string& getNextGamePhaseName();
void nextCombatStep(); void nextCombatStep();
void userRequestNextGamePhase(bool allowInterrupt = true, bool log = true); void userRequestNextGamePhase(bool allowInterrupt = true, bool log = true);
void cleanupPhase(); void cleanupPhase();
+4 -4
View File
@@ -129,11 +129,11 @@ public:
//types //types
void addType(char * type_text); void addType(const string& type_text);
virtual void addType(int id); virtual void addType(int id);
void setType(const char * type_text); void setType(const string& type_text);
void setSubtype( string value); void setSubtype(const string &value);
int removeType(string value, int removeAll = 0); int removeType(const string &value, int removeAll = 0);
int removeType(int 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. //dangerranking is a hint to Ai which creatures are the ones it should be targetting for effects.
+8 -6
View File
@@ -19,7 +19,7 @@ class MTGPack;
class MTGSetInfo class MTGSetInfo
{ {
public: public:
MTGSetInfo(string _id); MTGSetInfo(const string& _id);
~MTGSetInfo(); ~MTGSetInfo();
string id; //Short name: 10E, RAV, etc. Automatic from folder. string id; //Short name: 10E, RAV, etc. Automatic from folder.
string author; //Author of set, for crediting mod makers, etc. string author; //Author of set, for crediting mod makers, etc.
@@ -70,7 +70,7 @@ public:
MTGSets(); MTGSets();
~MTGSets(); ~MTGSets();
int Add(const char * subtype); int Add(const string& subtype);
int findSet(string value); int findSet(string value);
int findBlock(string s); int findBlock(string s);
int size(); int size();
@@ -127,8 +127,10 @@ public:
MTGCard * getCardByName(string name); MTGCard * getCardByName(string name);
void loadFolder(const string& folder, const string& filename="" ); void loadFolder(const string& folder, const string& filename="" );
int load(const char * config_file, const char * setName = NULL, int autoload = 1); int load(const string& config_file);
int countByType(const char * _type); 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 countByColor(int color);
int countBySet(int setId); int countBySet(int setId);
int totalCards(); int totalCards();
@@ -218,8 +220,8 @@ public:
int totalCards(); int totalCards();
int totalPrice(); int totalPrice();
MTGDeck(MTGAllCards * _allcards); MTGDeck(MTGAllCards * _allcards);
MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_only = 0,int difficultySetting = 0); 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 char * subtype = NULL, int addRandomCards(int howmany, int * setIds = NULL, int nbSets = 0, int rarity = -1, const string& subtype = "",
int * colors = NULL, int nbcolors = 0); int * colors = NULL, int nbcolors = 0);
int add(int cardid); int add(int cardid);
int add(MTGDeck * deck); // adds the contents of "deck" into myself int add(MTGDeck * deck); // adds the contents of "deck" into myself
+1 -1
View File
@@ -293,7 +293,7 @@ class Constants
static map<string,int> MTGBasicAbilitiesMap; static map<string,int> MTGBasicAbilitiesMap;
static const char* MTGBasicAbilities[]; static const char* MTGBasicAbilities[];
static const char* MTGPhaseNames[]; static const string MTGPhaseNames[];
static const char* MTGPhaseCodeNames[]; static const char* MTGPhaseCodeNames[];
static int GetBasicAbilityIndex(string mtgAbility); static int GetBasicAbilityIndex(string mtgAbility);
+1 -1
View File
@@ -62,7 +62,7 @@ public:
int addCombatAfter(Player* player, int after_id, bool withMain = false); int addCombatAfter(Player* player, int after_id, bool withMain = false);
int addPhaseAfter(GamePhase id, Player* player, int after_id); int addPhaseAfter(GamePhase id, Player* player, int after_id);
int removePhase(int id); int removePhase(int id);
const char * phaseName(int id); const string& phaseName(int id);
static GamePhase phaseStrToInt(string s); static GamePhase phaseStrToInt(string s);
static string phaseIntToStr(int id); static string phaseIntToStr(int id);
+1 -1
View File
@@ -57,7 +57,7 @@ void NextGamePhase::Render()
if (observer->currentActionPlayer == observer->players[1]) if (observer->currentActionPlayer == observer->players[1])
playerId = 2; 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->DrawString(buffer, x + 15, y+10, JGETEXT_LEFT);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE); mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
+1 -1
View File
@@ -344,7 +344,7 @@ bool CardPrimitive::hasSubtype(int _subtype)
return hasType(_subtype); return hasType(_subtype);
} }
bool CardPrimitive::hasType(const char * _type) bool CardPrimitive::hasType(const string& _type)
{ {
int id = MTGAllCards::findType(_type); int id = MTGAllCards::findType(_type);
return hasType(id); return hasType(id);
+1 -1
View File
@@ -7,7 +7,7 @@
#include <iomanip> #include <iomanip>
#include "Translate.h" #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) DeckMenu(id, listener, fontId, _title), selectedDeck(_selectedDeck), stw(stats)
{ {
backgroundName = "DeckEditorMenuBackdrop"; backgroundName = "DeckEditorMenuBackdrop";
+1 -1
View File
@@ -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, DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0,
mY + DeckMenuConst::kVerticalMargin + mCount * DeckMenuConst::kLineHeight, (mCount == 0), mAutoTranslate, deckMetaData); mY + DeckMenuConst::kVerticalMargin + mCount * DeckMenuConst::kLineHeight, (mCount == 0), mAutoTranslate, deckMetaData);
+1 -1
View File
@@ -587,7 +587,7 @@ void StatsWrapper::updateStats(DeckDataWrapper *myDeck)
// This should probably be cached in DeckDataWrapper // This should probably be cached in DeckDataWrapper
// or at least be calculated for all common types in one go // 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; int result = 0;
for (int i = 0; i < myDeck->Size(true); i++) for (int i = 0; i < myDeck->Size(true); i++)
+2 -2
View File
@@ -110,12 +110,12 @@ GamePhase GameObserver::getCurrentGamePhase()
return mCurrentGamePhase; return mCurrentGamePhase;
} }
const char* GameObserver::getCurrentGamePhaseName() const string& GameObserver::getCurrentGamePhaseName()
{ {
return phaseRing->phaseName(mCurrentGamePhase); return phaseRing->phaseName(mCurrentGamePhase);
} }
const char* GameObserver::getNextGamePhaseName() const string& GameObserver::getNextGamePhaseName()
{ {
return phaseRing->phaseName((mCurrentGamePhase + 1) % MTG_PHASE_CLEANUP); return phaseRing->phaseName((mCurrentGamePhase + 1) % MTG_PHASE_CLEANUP);
} }
+3 -3
View File
@@ -818,9 +818,9 @@ void GameSettings::createUsersFirstDeck(int setId)
mCollection->addRandomCards(10, 0, 0, Constants::RARITY_L, "Island"); mCollection->addRandomCards(10, 0, 0, Constants::RARITY_L, "Island");
//Starter Deck //Starter Deck
mCollection->addRandomCards(3, sets, 1, Constants::RARITY_R, NULL); mCollection->addRandomCards(3, sets, 1, Constants::RARITY_R);
mCollection->addRandomCards(9, sets, 1, Constants::RARITY_U, NULL); mCollection->addRandomCards(9, sets, 1, Constants::RARITY_U);
mCollection->addRandomCards(48, sets, 1, Constants::RARITY_C, NULL); mCollection->addRandomCards(48, sets, 1, Constants::RARITY_C);
//Boosters //Boosters
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
+4 -4
View File
@@ -254,22 +254,22 @@ void MTGCardInstance::addType(int type)
SAFE_DELETE(e); SAFE_DELETE(e);
} }
void MTGCardInstance::addType(char * type_text) void MTGCardInstance::addType(const string& type_text)
{ {
setSubtype(type_text); setSubtype(type_text);
} }
void MTGCardInstance::setType(const char * type_text) void MTGCardInstance::setType(const string& type_text)
{ {
setSubtype(type_text); setSubtype(type_text);
} }
void MTGCardInstance::setSubtype(string value) void MTGCardInstance::setSubtype(const string& value)
{ {
int id = MTGAllCards::findType(value); int id = MTGAllCards::findType(value);
addType(id); addType(id);
} }
int MTGCardInstance::removeType(string value, int removeAll) int MTGCardInstance::removeType(const string& value, int removeAll)
{ {
int id = MTGAllCards::findType(value); int id = MTGAllCards::findType(value);
return removeType(id, removeAll); return removeType(id, removeAll);
+20 -10
View File
@@ -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; conf_read_mode = 0;
const int set_id = set_name ? setlist.Add(set_name) : MTGSets::INTERNAL_SET;
MTGSetInfo *si = setlist.getInfo(set_id); MTGSetInfo *si = setlist.getInfo(set_id);
int lineNumber = 0; int lineNumber = 0;
@@ -532,7 +542,7 @@ int MTGAllCards::countBySet(int setId)
} }
//TODO more efficient way ? //TODO more efficient way ?
int MTGAllCards::countByType(const char * _type) int MTGAllCards::countByType(const string &_type)
{ {
int result = 0; int result = 0;
map<int, MTGCard *>::iterator it; map<int, MTGCard *>::iterator it;
@@ -772,7 +782,7 @@ int MTGDeck::totalPrice()
return total; 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; total_cards = 0;
database = _allcards; database = _allcards;
@@ -879,7 +889,7 @@ MTGCard * MTGDeck::getCardById(int mtgId)
return database->getCardById(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; 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(); int collectionTotal = database->totalCards();
if (!collectionTotal) return 0; if (!collectionTotal) return 0;
char subtype[4096]; string subtype;
if (_subtype) sprintf(subtype, "%s", _subtype); if (_subtype.size()) subtype = _subtype;
vector<int> subcollection; vector<int> subcollection;
int subtotal = 0; int subtotal = 0;
@@ -911,7 +921,7 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
int r = card->getRarity(); int r = card->getRarity();
if (r != Constants::RARITY_T && (rarity == -1 || r == rarity) && // remove tokens 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 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; int ok = 0;
@@ -1265,7 +1275,7 @@ MTGSetInfo* MTGSets::randomSet(int blockId, int atleast)
int blockSize(int blockId); int blockSize(int blockId);
int MTGSets::Add(const char * name) int MTGSets::Add(const string& name)
{ {
int setid = findSet(name); int setid = findSet(name);
if (setid != -1) return setid; if (setid != -1) return setid;
@@ -1344,7 +1354,7 @@ MTGSetInfo::~MTGSetInfo()
SAFE_DELETE(mPack); SAFE_DELETE(mPack);
} }
MTGSetInfo::MTGSetInfo(string _id) MTGSetInfo::MTGSetInfo(const string& _id)
{ {
string whitespaces(" \t\f\v\n\r"); string whitespaces(" \t\f\v\n\r");
id = _id; id = _id;
+1 -1
View File
@@ -162,7 +162,7 @@ int Constants::GetColorStringIndex(string mtgColor)
return -1; return -1;
} }
const char* Constants::MTGPhaseNames[] = const string Constants::MTGPhaseNames[] =
{ {
"---", "---",
"Untap", "Untap",
+3 -2
View File
@@ -142,9 +142,10 @@ bool PhaseRing::extraDamagePhase(int id)
return false; 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]; return Constants::MTGPhaseNames[id];
} }
+2 -2
View File
@@ -350,8 +350,8 @@ void TestSuiteGame::assertGame()
if (observer->getCurrentGamePhase() != endState.phase) if (observer->getCurrentGamePhase() != endState.phase)
{ {
sprintf(result, "<span class=\"error\">==phase problem. Expected [ %s ](%i), got [ %s ](%i)==</span><br />", sprintf(result, "<span class=\"error\">==phase problem. Expected [ %s ](%i), got [ %s ](%i)==</span><br />",
Constants::MTGPhaseNames[endState.phase],endState.phase, Constants::MTGPhaseNames[endState.phase].c_str(),endState.phase,
Constants::MTGPhaseNames[observer->getCurrentGamePhase()], observer->getCurrentGamePhase()); Constants::MTGPhaseNames[observer->getCurrentGamePhase()].c_str(), observer->getCurrentGamePhase());
Log(result); Log(result);
error++; error++;
} }