Substitute more char arrays with strings
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <iomanip>
|
||||
#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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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++)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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++)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<int, MTGCard *>::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<int> 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;
|
||||
|
||||
@@ -162,7 +162,7 @@ int Constants::GetColorStringIndex(string mtgColor)
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* Constants::MTGPhaseNames[] =
|
||||
const string Constants::MTGPhaseNames[] =
|
||||
{
|
||||
"---",
|
||||
"Untap",
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -350,8 +350,8 @@ void TestSuiteGame::assertGame()
|
||||
if (observer->getCurrentGamePhase() != endState.phase)
|
||||
{
|
||||
sprintf(result, "<span class=\"error\">==phase problem. Expected [ %s ](%i), got [ %s ](%i)==</span><br />",
|
||||
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++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user