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

View File

@@ -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();

View File

@@ -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();
};

View File

@@ -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();

View File

@@ -77,9 +77,7 @@ public:
}
// Setters
void setDescription( const string description ) { mDescription = description; };
;
void setDescription( const string& description ) { mDescription = description; }
};
#endif

View File

@@ -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<string> aiDeckNames;

View File

@@ -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();

View File

@@ -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.

View File

@@ -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

View File

@@ -293,7 +293,7 @@ class Constants
static map<string,int> MTGBasicAbilitiesMap;
static const char* MTGBasicAbilities[];
static const char* MTGPhaseNames[];
static const string MTGPhaseNames[];
static const char* MTGPhaseCodeNames[];
static int GetBasicAbilityIndex(string mtgAbility);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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";

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,
mY + DeckMenuConst::kVerticalMargin + mCount * DeckMenuConst::kLineHeight, (mCount == 0), mAutoTranslate, deckMetaData);

View File

@@ -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++)

View File

@@ -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);
}

View File

@@ -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++)

View File

@@ -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);

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;
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;

View File

@@ -162,7 +162,7 @@ int Constants::GetColorStringIndex(string mtgColor)
return -1;
}
const char* Constants::MTGPhaseNames[] =
const string Constants::MTGPhaseNames[] =
{
"---",
"Untap",

View File

@@ -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];
}

View File

@@ -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++;
}