* moved deck saving to end of match. It now only saves when you've actually completed a game.
* added additional meta data for decks when saving them back to file.
- decks saved this way now are split into three regions: creatures, spells and lands. It's more for a visual sorting if a
player wanted to look at the deck outside of the game. It does not impact the deck loading negatively at all. It may
increase performance in cases where the deck was previously defined using the canonical names of the cards as the numeric ids
reduce the work done when looking up the cards by name.
* modified ManaCost toString method.
* added toString method for ManaCostHybrid ( possibly make ManaCostHybrid a subclass of ManaCost)
* added additional operator overloading for ManaCost for printing to cover ManaCost when it's a pointer as well as a copy
( TODO: might want to check if making usage of ManaCost as a copy as opposed to a ptr is really necessary in most cases. )
* added alternate version of "trim" to handle trimming temporary strings as returned by things like ostringstream.str().
- This was necessary since the PSP compiler doesn't do the necessary adjustments for those types of calls.
This commit is contained in:
@@ -27,7 +27,8 @@ public:
|
|||||||
vector<DeckMetaData*> * getPlayerDeckOrderList();
|
vector<DeckMetaData*> * getPlayerDeckOrderList();
|
||||||
vector<DeckMetaData*> * getAIDeckOrderList();
|
vector<DeckMetaData*> * getAIDeckOrderList();
|
||||||
|
|
||||||
void saveDeck ( MTGDeck *deck, int deckId, MTGAllCards *collection );
|
void saveDeck ( const string& deckFilename, MTGAllCards *collection );
|
||||||
|
void saveDeck ( MTGDeck *deck, MTGAllCards *collection );
|
||||||
void AddMetaData( const std::string& filename, bool isAI);
|
void AddMetaData( const std::string& filename, bool isAI);
|
||||||
DeckMetaData* getDeckMetaDataById(int deckId, bool isAI);
|
DeckMetaData* getDeckMetaDataById(int deckId, bool isAI);
|
||||||
DeckMetaData* getDeckMetaDataByFilename(const std::string& filename, bool isAI);
|
DeckMetaData* getDeckMetaDataByFilename(const std::string& filename, bool isAI);
|
||||||
|
|||||||
@@ -132,6 +132,9 @@ private:
|
|||||||
|
|
||||||
class MTGDeck
|
class MTGDeck
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
string getCardBlockText( const string& title, const string& textBlock );
|
||||||
|
void printDetailedDeckText(std::ofstream& file );
|
||||||
protected:
|
protected:
|
||||||
string filename;
|
string filename;
|
||||||
int total_cards;
|
int total_cards;
|
||||||
@@ -141,6 +144,7 @@ public:
|
|||||||
map<int, int> cards;
|
map<int, int> cards;
|
||||||
string meta_desc;
|
string meta_desc;
|
||||||
string meta_name;
|
string meta_name;
|
||||||
|
int meta_id;
|
||||||
string meta_deck_colors;
|
string meta_deck_colors;
|
||||||
int totalCards();
|
int totalCards();
|
||||||
int totalPrice();
|
int totalPrice();
|
||||||
@@ -157,7 +161,7 @@ public:
|
|||||||
int remove(MTGCard * card);
|
int remove(MTGCard * card);
|
||||||
string getFilename();
|
string getFilename();
|
||||||
int save();
|
int save();
|
||||||
int save(string destFileName, bool useExpandedDescriptions, string &deckTitle, string &deckDesc);
|
int save(const string& destFileName, bool useExpandedDescriptions, const string& deckTitle, const string& deckDesc);
|
||||||
MTGCard * getCardById(int id);
|
MTGCard * getCardById(int id);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ class MTGCardInstance;
|
|||||||
class Player;
|
class Player;
|
||||||
|
|
||||||
class ManaCost{
|
class ManaCost{
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, ManaCost& m);
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, ManaCost* m);
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, ManaCost m);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int cost[Constants::MTG_NB_COLORS+1];
|
int cost[Constants::MTG_NB_COLORS+1];
|
||||||
ManaCostHybrid * hybrids[10];
|
ManaCostHybrid * hybrids[10];
|
||||||
@@ -80,9 +85,9 @@ class ManaCost{
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
void Dump();
|
void Dump();
|
||||||
#endif
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const ManaCost& m);
|
|
||||||
|
};
|
||||||
|
|
||||||
class ManaPool:public ManaCost{
|
class ManaPool:public ManaCost{
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -3,16 +3,23 @@
|
|||||||
|
|
||||||
class ManaCostHybrid
|
class ManaCostHybrid
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int color1;
|
int color1;
|
||||||
int color2;
|
int color2;
|
||||||
int value1;
|
int value1;
|
||||||
int value2;
|
int value2;
|
||||||
ManaCostHybrid();
|
ManaCostHybrid();
|
||||||
int hasColor(int color);
|
|
||||||
ManaCostHybrid(int c1, int v1, int c2, int v2);
|
ManaCostHybrid(int c1, int v1, int c2, int v2);
|
||||||
|
|
||||||
void init(int c1, int v1, int c2, int v2);
|
void init(int c1, int v1, int c2, int v2);
|
||||||
|
int hasColor(int color);
|
||||||
|
string toString();
|
||||||
int getConvertedCost();
|
int getConvertedCost();
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, ManaCostHybrid& m);
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, ManaCostHybrid* m);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -74,7 +74,15 @@ namespace wagic
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
#define SPACES " \t\r\n"
|
||||||
//string manipulation methods
|
//string manipulation methods
|
||||||
|
|
||||||
|
// for trimming strings on the fly
|
||||||
|
string trim (const string & s, const string & t = SPACES);
|
||||||
|
string trim_right (const string & s, const string & t = SPACES);
|
||||||
|
string trim_left (const string & s, const string & t = SPACES);
|
||||||
|
|
||||||
|
// trimmning strings inplace
|
||||||
string& trim(string& str);
|
string& trim(string& str);
|
||||||
string& ltrim(string& str);
|
string& ltrim(string& str);
|
||||||
string& rtrim(string& str);
|
string& rtrim(string& str);
|
||||||
|
|||||||
@@ -1182,7 +1182,6 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
|
|||||||
MTGDeck * tempDeck = NEW MTGDeck(deckFile, collection);
|
MTGDeck * tempDeck = NEW MTGDeck(deckFile, collection);
|
||||||
AIPlayerBaka * baka = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, avatarFile);
|
AIPlayerBaka * baka = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, avatarFile);
|
||||||
baka->deckId = deckid;
|
baka->deckId = deckid;
|
||||||
DeckManager::GetInstance()->saveDeck( tempDeck, deckid, collection);
|
|
||||||
SAFE_DELETE(tempDeck);
|
SAFE_DELETE(tempDeck);
|
||||||
return baka;
|
return baka;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,12 +105,12 @@ DeckMetaData* DeckManager::getDeckMetaDataByFilename(const string& filename, boo
|
|||||||
return deck;
|
return deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckManager::saveDeck( MTGDeck *deck, int deckId, MTGAllCards *collection )
|
void DeckManager::saveDeck( MTGDeck *deck, MTGAllCards *collection )
|
||||||
{
|
{
|
||||||
if ( deck->meta_deck_colors == "" )
|
if ( deck->meta_deck_colors == "" )
|
||||||
{
|
{
|
||||||
bool isAI = deck->getFilename().find("baka") != string::npos;
|
bool isAI = deck->getFilename().find("baka") != string::npos;
|
||||||
StatsWrapper *stats = getExtendedStatsForDeckId( deckId, collection, isAI );
|
StatsWrapper *stats = getExtendedStatsForDeckId( deck->meta_id, collection, isAI );
|
||||||
ostringstream manaColorIndex;
|
ostringstream manaColorIndex;
|
||||||
for (int i = Constants::MTG_COLOR_ARTIFACT; i < Constants::MTG_COLOR_LAND; ++i)
|
for (int i = Constants::MTG_COLOR_ARTIFACT; i < Constants::MTG_COLOR_LAND; ++i)
|
||||||
{
|
{
|
||||||
@@ -128,6 +128,18 @@ void DeckManager::saveDeck( MTGDeck *deck, int deckId, MTGAllCards *collection )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckManager::saveDeck( const string& deckFilename, MTGAllCards *collection )
|
||||||
|
{
|
||||||
|
bool isAI = deckFilename.find("baka") != string::npos;
|
||||||
|
DeckMetaData *metaData = getDeckMetaDataByFilename( deckFilename, isAI );
|
||||||
|
if ( metaData->getColorIndex() == "" )
|
||||||
|
{
|
||||||
|
MTGDeck *tempDeck = NEW MTGDeck( deckFilename.c_str(), collection, 0 );
|
||||||
|
saveDeck(tempDeck, collection);
|
||||||
|
SAFE_DELETE( tempDeck );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DeckManager::AddMetaData( const string& filename, bool isAI )
|
void DeckManager::AddMetaData( const string& filename, bool isAI )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ void DeckMenu::RenderDeckManaColors()
|
|||||||
{
|
{
|
||||||
string deckManaColors = mSelectedDeck->getColorIndex();
|
string deckManaColors = mSelectedDeck->getColorIndex();
|
||||||
if ( deckManaColors.compare("") != 0 && ( deckManaColors.length() == 6 ))
|
if ( deckManaColors.compare("") != 0 && ( deckManaColors.length() == 6 ))
|
||||||
{
|
{
|
||||||
|
// due to space constraints don't display icons for colorless mana.
|
||||||
for( int colorIdx = Constants::MTG_COLOR_GREEN; colorIdx < Constants::MTG_COLOR_LAND; ++colorIdx )
|
for( int colorIdx = Constants::MTG_COLOR_GREEN; colorIdx < Constants::MTG_COLOR_LAND; ++colorIdx )
|
||||||
{
|
{
|
||||||
if ( (deckManaColors.at(colorIdx) == '1') != 0)
|
if ( (deckManaColors.at(colorIdx) == '1') != 0)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void DeckMetaData::LoadStats()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fileExists(mStatsFilename.c_str()))
|
if (FileExists(mStatsFilename))
|
||||||
{
|
{
|
||||||
stats->load(mStatsFilename);
|
stats->load(mStatsFilename);
|
||||||
mGamesPlayed = stats->nbGames();
|
mGamesPlayed = stats->nbGames();
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ void StatsWrapper::initStatistics(string deckstats)
|
|||||||
aiDeckNames.clear();
|
aiDeckNames.clear();
|
||||||
aiDeckStats.clear();
|
aiDeckStats.clear();
|
||||||
|
|
||||||
if (fileExists(deckstats.c_str()))
|
if (FileExists(deckstats))
|
||||||
{
|
{
|
||||||
stats->load(deckstats.c_str());
|
stats->load(deckstats.c_str());
|
||||||
percentVictories = stats->percentVictories();
|
percentVictories = stats->percentVictories();
|
||||||
@@ -302,7 +302,7 @@ void StatsWrapper::initStatistics(string deckstats)
|
|||||||
|
|
||||||
void StatsWrapper::updateStats(string filename, MTGAllCards *collection)
|
void StatsWrapper::updateStats(string filename, MTGAllCards *collection)
|
||||||
{
|
{
|
||||||
if (fileExists(filename.c_str()))
|
if (FileExists(filename))
|
||||||
{
|
{
|
||||||
MTGDeck * mtgd = NEW MTGDeck(filename.c_str(), collection);
|
MTGDeck * mtgd = NEW MTGDeck(filename.c_str(), collection);
|
||||||
DeckDataWrapper *deckDataWrapper = NEW DeckDataWrapper(mtgd);
|
DeckDataWrapper *deckDataWrapper = NEW DeckDataWrapper(mtgd);
|
||||||
|
|||||||
@@ -171,8 +171,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI)
|
|||||||
sprintf(deckFileSmall, "player_deck%i", decknb);
|
sprintf(deckFileSmall, "player_deck%i", decknb);
|
||||||
MTGDeck * tempDeck = NEW MTGDeck(deckFile, mParent->collection);
|
MTGDeck * tempDeck = NEW MTGDeck(deckFile, mParent->collection);
|
||||||
mPlayers[playerId] = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall);
|
mPlayers[playerId] = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall);
|
||||||
DeckManager::GetInstance()->saveDeck( tempDeck, decknb, mParent->collection);
|
SAFE_DELETE( tempDeck );
|
||||||
delete tempDeck;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //AI Player, chooses deck
|
{ //AI Player, chooses deck
|
||||||
@@ -224,9 +223,15 @@ void GameStateDuel::End()
|
|||||||
DebugTrace("Ending GameStateDuel");
|
DebugTrace("Ending GameStateDuel");
|
||||||
|
|
||||||
JRenderer::GetInstance()->EnableVSync(false);
|
JRenderer::GetInstance()->EnableVSync(false);
|
||||||
|
if (!premadeDeck && mPlayers[0] && mPlayers[1])
|
||||||
if (!premadeDeck && mPlayers[0] && mPlayers[1]) // save the stats for the game
|
{ // save the stats for the game
|
||||||
mPlayers[0]->End();
|
mPlayers[0]->End();
|
||||||
|
if (mParent->players[1] != PLAYER_TYPE_TESTSUITE)
|
||||||
|
{
|
||||||
|
DeckManager::GetInstance()->saveDeck( mPlayers[1]->deckFile, mParent->collection);
|
||||||
|
DeckManager::GetInstance()->saveDeck( mPlayers[0]->deckFile, mParent->collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if ( !mPlayers[1] && mPlayers[0] )
|
else if ( !mPlayers[1] && mPlayers[0] )
|
||||||
// clean up player object
|
// clean up player object
|
||||||
SAFE_DELETE( mPlayers[0] );
|
SAFE_DELETE( mPlayers[0] );
|
||||||
|
|||||||
+111
-37
@@ -10,6 +10,7 @@
|
|||||||
#include "MTGPack.h"
|
#include "MTGPack.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "DeckManager.h"
|
#include "DeckManager.h"
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#if defined (WIN32) || defined (LINUX)
|
#if defined (WIN32) || defined (LINUX)
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -91,7 +92,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
|||||||
attribute = value;
|
attribute = value;
|
||||||
value = "";
|
value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = Constants::NB_BASIC_ABILITIES - 1; j >= 0; --j)
|
for (int j = Constants::NB_BASIC_ABILITIES - 1; j >= 0; --j)
|
||||||
{
|
{
|
||||||
size_t found = attribute.find(Constants::MTGBasicAbilities[j]);
|
size_t found = attribute.find(Constants::MTGBasicAbilities[j]);
|
||||||
@@ -144,12 +145,12 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ManaCost * cost = primitive->getManaCost())
|
if (ManaCost * cost = primitive->getManaCost())
|
||||||
{
|
{
|
||||||
string value = val;
|
string value = val;
|
||||||
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
||||||
cost->alternative = ManaCost::parseManaCost(value);
|
cost->alternative = ManaCost::parseManaCost(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -329,7 +330,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
primitive->setType(val);
|
primitive->setType(val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -656,7 +657,7 @@ MTGCard * MTGAllCards::getCardByName(string name)
|
|||||||
if (setId != -1 && setId != c->setId) continue;
|
if (setId != -1 && setId != c->setId) continue;
|
||||||
string cardName = c->data->name;
|
string cardName = c->data->name;
|
||||||
std::transform(cardName.begin(), cardName.end(), cardName.begin(), ::tolower);
|
std::transform(cardName.begin(), cardName.end(), cardName.begin(), ::tolower);
|
||||||
if (cardName.compare(name) == 0) return c;
|
if (cardName.compare(name) == 0) return c;
|
||||||
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -693,6 +694,7 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
|
|||||||
size_t slash = filename.find_last_of("/");
|
size_t slash = filename.find_last_of("/");
|
||||||
size_t dot = filename.find(".");
|
size_t dot = filename.find(".");
|
||||||
meta_name = filename.substr(slash + 1, dot - slash - 1);
|
meta_name = filename.substr(slash + 1, dot - slash - 1);
|
||||||
|
meta_id = atoi(meta_name.substr(4).c_str());
|
||||||
wagic::ifstream file(config_file);
|
wagic::ifstream file(config_file);
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
||||||
@@ -807,8 +809,8 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
|
|||||||
MTGCard * card = database->_(i);
|
MTGCard * card = database->_(i);
|
||||||
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 || card->data->hasSubtype(subtype)))
|
||||||
{
|
{
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
@@ -843,8 +845,7 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
|
|||||||
}
|
}
|
||||||
if (subtotal == 0)
|
if (subtotal == 0)
|
||||||
{
|
{
|
||||||
if (rarity == Constants::RARITY_M) return addRandomCards(howmany, setIds, nbSets, Constants::RARITY_R, _subtype, colors,
|
if (rarity == Constants::RARITY_M) return addRandomCards(howmany, setIds, nbSets, Constants::RARITY_R, _subtype, colors, nbcolors);
|
||||||
nbcolors);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < howmany; i++)
|
for (int i = 0; i < howmany; i++)
|
||||||
@@ -893,8 +894,8 @@ int MTGDeck::add(MTGCard * card)
|
|||||||
int MTGDeck::complete()
|
int MTGDeck::complete()
|
||||||
{
|
{
|
||||||
/* (PSY) adds cards to the deck/collection. Makes sure that the deck
|
/* (PSY) adds cards to the deck/collection. Makes sure that the deck
|
||||||
or collection has at least 4 of every implemented card. Does not
|
or collection has at least 4 of every implemented card. Does not
|
||||||
change the number of cards of which already 4 or more are present. */
|
change the number of cards of which already 4 or more are present. */
|
||||||
int id, n;
|
int id, n;
|
||||||
bool StypeIsNothing;
|
bool StypeIsNothing;
|
||||||
size_t databaseSize = database->ids.size();
|
size_t databaseSize = database->ids.size();
|
||||||
@@ -955,7 +956,7 @@ int MTGDeck::save()
|
|||||||
return save(filename, false, meta_name, meta_desc);
|
return save(filename, false, meta_name, meta_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MTGDeck::save(string destFileName, bool useExpandedDescriptions, string &deckTitle, string &deckDesc)
|
int MTGDeck::save(const string& destFileName, bool useExpandedDescriptions, const string& deckTitle, const string& deckDesc)
|
||||||
{
|
{
|
||||||
string tmp = destFileName;
|
string tmp = destFileName;
|
||||||
tmp.append(".tmp"); //not thread safe
|
tmp.append(".tmp"); //not thread safe
|
||||||
@@ -982,18 +983,19 @@ int MTGDeck::save(string destFileName, bool useExpandedDescriptions, string &dec
|
|||||||
}
|
}
|
||||||
file << "#DESC:" << desc << "\n";
|
file << "#DESC:" << desc << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// add in color information
|
|
||||||
bool saveDetailedDeckInfo = options.get( Options::SAVEDETAILEDDECKINFO )->number == 1;
|
bool saveDetailedDeckInfo = options.get( Options::SAVEDETAILEDDECKINFO )->number == 1;
|
||||||
|
|
||||||
if ( filename.find("collection.dat") == string::npos )
|
if ( filename.find("collection.dat") == string::npos )
|
||||||
{
|
{
|
||||||
|
// add in color information
|
||||||
DeckManager *deckManager = DeckManager::GetInstance();
|
DeckManager *deckManager = DeckManager::GetInstance();
|
||||||
file <<"#MANA:";
|
file <<"#MANA:";
|
||||||
|
|
||||||
string deckId = filename.substr( filename.find("/deck")+5, filename.find(".txt") - (filename.find("/deck")+5) );
|
string deckId = filename.substr( filename.find("/deck")+5, filename.find(".txt") - (filename.find("/deck")+5) );
|
||||||
bool isAI = filename.find("ai/baka") != string::npos;
|
bool isAI = filename.find("ai/baka") != string::npos;
|
||||||
StatsWrapper *stats = deckManager->getExtendedStatsForDeckId( atoi(deckId.c_str()), this->database, isAI );
|
StatsWrapper *stats = deckManager->getExtendedStatsForDeckId( atoi(deckId.c_str()), this->database, isAI );
|
||||||
|
|
||||||
for (int i = Constants::MTG_COLOR_ARTIFACT; i < Constants::MTG_COLOR_LAND; ++i)
|
for (int i = Constants::MTG_COLOR_ARTIFACT; i < Constants::MTG_COLOR_LAND; ++i)
|
||||||
{
|
{
|
||||||
if (stats->totalCostPerColor[i] != 0)
|
if (stats->totalCostPerColor[i] != 0)
|
||||||
@@ -1005,24 +1007,10 @@ int MTGDeck::save(string destFileName, bool useExpandedDescriptions, string &dec
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
saveDetailedDeckInfo = false;
|
saveDetailedDeckInfo = false;
|
||||||
|
|
||||||
if (useExpandedDescriptions || saveDetailedDeckInfo)
|
if (useExpandedDescriptions || saveDetailedDeckInfo)
|
||||||
{
|
{
|
||||||
map<int, int>::iterator it;
|
printDetailedDeckText(file);
|
||||||
for (it = cards.begin(); it != cards.end(); it++)
|
|
||||||
{
|
|
||||||
int nbCards = it->second;
|
|
||||||
MTGCard *card = this->getCardById(it->first);
|
|
||||||
if (card == NULL)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
MTGSetInfo *setInfo = setlist.getInfo(card->setId);
|
|
||||||
string setName = setInfo->id;
|
|
||||||
string cardName = card->data->getName();
|
|
||||||
file << cardName << "\t " << "(" << setName << ") *" << nbCards << endl;
|
|
||||||
setInfo = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1043,6 +1031,92 @@ int MTGDeck::save(string destFileName, bool useExpandedDescriptions, string &dec
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
print out an expanded version of the deck to file.
|
||||||
|
This save meta data about each card to allow easy reading of the deck file. It will
|
||||||
|
also save each card by id, to speed up the loading of the deck next time.
|
||||||
|
*/
|
||||||
|
void MTGDeck::printDetailedDeckText(std::ofstream& file )
|
||||||
|
{
|
||||||
|
ostringstream currentCard, creatures, lands, spells, types;
|
||||||
|
map<int, int>::iterator it;
|
||||||
|
for (it = cards.begin(); it != cards.end(); it++)
|
||||||
|
{
|
||||||
|
int cardId = it->first;
|
||||||
|
int nbCards = it->second;
|
||||||
|
MTGCard *card = this->getCardById( cardId );
|
||||||
|
if (card == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MTGSetInfo *setInfo = setlist.getInfo(card->setId);
|
||||||
|
string setName = setInfo->id;
|
||||||
|
string cardName = card->data->getName();
|
||||||
|
string description = card->data->getText();
|
||||||
|
|
||||||
|
currentCard << "#" << nbCards << " x " << cardName << " (" << setName << "), ";
|
||||||
|
|
||||||
|
if ( !card->data->isLand() )
|
||||||
|
currentCard << card->data->getManaCost() << ", ";
|
||||||
|
|
||||||
|
// Add the card's types
|
||||||
|
vector<int>::iterator typeIter;
|
||||||
|
for ( typeIter = card->data->types.begin(); typeIter != card->data->types.end(); ++typeIter )
|
||||||
|
types << Subtypes::subtypesList->find( *typeIter ) << " ";
|
||||||
|
|
||||||
|
currentCard << trim(types.str()) << ", ";
|
||||||
|
types.str(""); // reset the buffer.
|
||||||
|
|
||||||
|
// Add P/T if a creature
|
||||||
|
if ( card->data->isCreature() )
|
||||||
|
currentCard << card->data->getPower() << "/" << card->data->getToughness() << ", ";
|
||||||
|
|
||||||
|
|
||||||
|
if ( card->data->hasRestriction )
|
||||||
|
currentCard << ", " << card->data->otherrestriction;
|
||||||
|
|
||||||
|
map<int,int>::iterator abilityIter;
|
||||||
|
for ( abilityIter = card->data->basicAbilities.begin(); abilityIter != card->data->basicAbilities.end(); ++abilityIter )
|
||||||
|
currentCard << Constants::MTGBasicAbilities[ abilityIter->first ] << "; ";
|
||||||
|
currentCard <<endl;
|
||||||
|
|
||||||
|
for ( int i = 0; i < nbCards; i++ )
|
||||||
|
currentCard << cardId << endl;
|
||||||
|
|
||||||
|
currentCard <<endl;
|
||||||
|
setInfo = NULL;
|
||||||
|
if ( card->data->isLand() )
|
||||||
|
lands<< currentCard.str();
|
||||||
|
else if ( card->data->isCreature() )
|
||||||
|
creatures << currentCard.str();
|
||||||
|
else
|
||||||
|
spells << currentCard.str();
|
||||||
|
currentCard.str("");
|
||||||
|
}
|
||||||
|
file << getCardBlockText( "Creatures", creatures.str() ) << endl;
|
||||||
|
file << getCardBlockText( "Spells", spells.str() ) << endl;
|
||||||
|
file << getCardBlockText( "Lands", lands.str() ) << endl;
|
||||||
|
creatures.str("");
|
||||||
|
spells.str("");
|
||||||
|
lands.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Convience method to print out blocks of card descriptions
|
||||||
|
*/
|
||||||
|
string MTGDeck::getCardBlockText( const string& title, const string& text )
|
||||||
|
{
|
||||||
|
ostringstream oss;
|
||||||
|
string textBlock (text);
|
||||||
|
|
||||||
|
oss << setfill('#') << setw( 40 ) << "#" << endl;
|
||||||
|
oss << "# " << setfill(' ') << setw(34) << left << title << "#" << endl;
|
||||||
|
oss << setfill('#') << setw( 40 ) << "#" << endl;
|
||||||
|
oss << trim(textBlock) << endl;
|
||||||
|
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
//MTGSets
|
//MTGSets
|
||||||
MTGSets setlist; //Our global.
|
MTGSets setlist; //Our global.
|
||||||
|
|
||||||
@@ -1082,7 +1156,7 @@ MTGSetInfo* MTGSets::randomSet(int blockId, int atleast)
|
|||||||
for (int i = a; i < size(); i++)
|
for (int i = a; i < size(); i++)
|
||||||
{
|
{
|
||||||
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) &&
|
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) &&
|
||||||
(atleast == -1 || setinfo[i]->totalCards() >= atleast))
|
(atleast == -1 || setinfo[i]->totalCards() >= atleast))
|
||||||
{
|
{
|
||||||
free(unlocked);
|
free(unlocked);
|
||||||
return setinfo[i];
|
return setinfo[i];
|
||||||
@@ -1091,7 +1165,7 @@ MTGSetInfo* MTGSets::randomSet(int blockId, int atleast)
|
|||||||
for (int i = 0; i < a; i++)
|
for (int i = 0; i < a; i++)
|
||||||
{
|
{
|
||||||
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) &&
|
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) &&
|
||||||
(atleast == -1 || setinfo[i]->totalCards() >= atleast))
|
(atleast == -1 || setinfo[i]->totalCards() >= atleast))
|
||||||
{
|
{
|
||||||
free(unlocked);
|
free(unlocked);
|
||||||
return setinfo[i];
|
return setinfo[i];
|
||||||
|
|||||||
@@ -626,36 +626,49 @@ ManaCost * ManaCost::Diff(ManaCost * _cost)
|
|||||||
string ManaCost::toString()
|
string ManaCost::toString()
|
||||||
{
|
{
|
||||||
ostringstream oss;
|
ostringstream oss;
|
||||||
oss << "\n===ManaCost===\n";
|
|
||||||
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
||||||
{
|
{
|
||||||
if (cost[i])
|
if (cost[i])
|
||||||
{
|
{
|
||||||
oss << Constants::MTGColorChars[i] << ":" << cost[i] << " - ";
|
if ( i == Constants::MTG_COLOR_ARTIFACT)
|
||||||
|
oss << "{" << cost[i] << "}";
|
||||||
|
else
|
||||||
|
for (int colorCount = 0; colorCount < cost[i]; colorCount++ )
|
||||||
|
oss << "{" << Constants::MTGColorChars[i] << "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < nbhybrids; i++)
|
for (unsigned int i = 0; i < nbhybrids; i++)
|
||||||
{
|
{
|
||||||
ManaCostHybrid * h = hybrids[i];
|
oss << hybrids[i];
|
||||||
oss << "H:{" << Constants::MTGColorChars[h->color1] << ":" << h->value1 << "}/{" << Constants::MTGColorChars[h->color2]
|
|
||||||
<< ":" << h->value2 << "}";
|
|
||||||
}
|
}
|
||||||
oss << "\n=============\n";
|
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
void ManaCost::Dump()
|
void ManaCost::Dump()
|
||||||
{
|
{
|
||||||
|
DebugTrace( "\n===ManaCost===" );
|
||||||
DebugTrace( this->toString() );
|
DebugTrace( this->toString() );
|
||||||
|
DebugTrace( "\n=============" );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ostream& operator<<(ostream& out, const ManaCost& m)
|
ostream& operator<<(ostream& out, ManaCost& m)
|
||||||
{
|
{
|
||||||
return out << "(manacost)";
|
return out << m.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, ManaCost* m)
|
||||||
|
{
|
||||||
|
return out << m->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, ManaCost m)
|
||||||
|
{
|
||||||
|
return out << m.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManaPool::init()
|
void ManaPool::init()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "ManaCostHybrid.h"
|
#include "ManaCostHybrid.h"
|
||||||
|
#include "MTGDefinitions.h"
|
||||||
|
|
||||||
ManaCostHybrid::ManaCostHybrid()
|
ManaCostHybrid::ManaCostHybrid()
|
||||||
{
|
{
|
||||||
@@ -33,3 +34,21 @@ int ManaCostHybrid::hasColor(int color)
|
|||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ManaCostHybrid::toString()
|
||||||
|
{
|
||||||
|
ostringstream oss;
|
||||||
|
if ( color1 != 0 && color2 != 0)
|
||||||
|
oss << "{" << Constants::MTGColorChars[color1] << "/" << Constants::MTGColorChars[color2] << "}";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, ManaCostHybrid& r)
|
||||||
|
{
|
||||||
|
return out<< r.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, ManaCostHybrid* r)
|
||||||
|
{
|
||||||
|
return out<< r->toString();
|
||||||
|
}
|
||||||
|
|||||||
+61
-27
@@ -76,6 +76,8 @@ int filesize(const char * filename)
|
|||||||
return file_size;
|
return file_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// check to see if a file exists on the file system.
|
||||||
int fileExists(const char * filename)
|
int fileExists(const char * filename)
|
||||||
{
|
{
|
||||||
wagic::ifstream fichier(filename);
|
wagic::ifstream fichier(filename);
|
||||||
@@ -94,6 +96,42 @@ int fileExists(const char * filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check to see if a file exists on the file system.
|
||||||
|
// this can be used to extract last modified date of a file.
|
||||||
|
bool FileExists(const string& strFilename)
|
||||||
|
{
|
||||||
|
struct stat stFileInfo;
|
||||||
|
bool blnReturn = false;
|
||||||
|
int intStat;
|
||||||
|
|
||||||
|
// Attempt to get the file attributes
|
||||||
|
intStat = stat(strFilename.c_str(),&stFileInfo);
|
||||||
|
if(intStat == 0)
|
||||||
|
{
|
||||||
|
// We were able to get the file attributes
|
||||||
|
// so the file obviously exists.
|
||||||
|
blnReturn = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We were not able to get the file attributes.
|
||||||
|
// This may mean that we don't have permission to
|
||||||
|
// access the folder which contains this file. If you
|
||||||
|
// need to do that level of checking, lookup the
|
||||||
|
// return values of stat which will give you
|
||||||
|
// more details on why stat failed.
|
||||||
|
|
||||||
|
// try to search in the resource directory
|
||||||
|
if ( stat( JGE_GET_RES(strFilename).c_str(), &stFileInfo ) == 0)
|
||||||
|
blnReturn = true;
|
||||||
|
else
|
||||||
|
blnReturn = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(blnReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
|
|
||||||
@@ -198,6 +236,29 @@ u32 ramAvailable(void)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* String manipulation functions */
|
||||||
|
string trim_right (const string & s, const string & t)
|
||||||
|
{
|
||||||
|
string d (s);
|
||||||
|
string::size_type i (d.find_last_not_of (t));
|
||||||
|
if (i == string::npos)
|
||||||
|
return "";
|
||||||
|
else
|
||||||
|
return d.erase (d.find_last_not_of (t) + 1) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
string trim_left (const string & s, const string & t)
|
||||||
|
{
|
||||||
|
string d (s);
|
||||||
|
return d.erase (0, s.find_first_not_of (t)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
string trim (const string & s, const string & t)
|
||||||
|
{
|
||||||
|
string d (s);
|
||||||
|
return trim_left (trim_right (d, t), t) ;
|
||||||
|
}
|
||||||
|
|
||||||
string& trim(string& str)
|
string& trim(string& str)
|
||||||
{
|
{
|
||||||
str = ltrim(str);
|
str = ltrim(str);
|
||||||
@@ -298,31 +359,4 @@ std::string wordWrap(const std::string& sentence, float width, int fontId)
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileExists(const string& strFilename)
|
|
||||||
{
|
|
||||||
struct stat stFileInfo;
|
|
||||||
bool blnReturn;
|
|
||||||
int intStat;
|
|
||||||
|
|
||||||
// Attempt to get the file attributes
|
|
||||||
intStat = stat(strFilename.c_str(),&stFileInfo);
|
|
||||||
if(intStat == 0)
|
|
||||||
{
|
|
||||||
// We were able to get the file attributes
|
|
||||||
// so the file obviously exists.
|
|
||||||
blnReturn = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// We were not able to get the file attributes.
|
|
||||||
// This may mean that we don't have permission to
|
|
||||||
// access the folder which contains this file. If you
|
|
||||||
// need to do that level of checking, lookup the
|
|
||||||
// return values of stat which will give you
|
|
||||||
// more details on why stat failed.
|
|
||||||
blnReturn = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(blnReturn);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user