reverted latest change
This commit is contained in:
@@ -24,7 +24,6 @@ private:
|
|||||||
string mAvatarFilename;
|
string mAvatarFilename;
|
||||||
string mColorIndex;
|
string mColorIndex;
|
||||||
|
|
||||||
map<int,int> mAlternateCardMap;
|
|
||||||
// statistical information
|
// statistical information
|
||||||
int mGamesPlayed, mVictories, mPercentVictories, mDifficulty;
|
int mGamesPlayed, mVictories, mPercentVictories, mDifficulty;
|
||||||
|
|
||||||
@@ -45,7 +44,6 @@ public:
|
|||||||
string getColorIndex();
|
string getColorIndex();
|
||||||
int getAvatarId(int deckId);
|
int getAvatarId(int deckId);
|
||||||
string getStatsSummary();
|
string getStatsSummary();
|
||||||
map<int,int>& getAlternateMappings();
|
|
||||||
|
|
||||||
int getDeckId();
|
int getDeckId();
|
||||||
int getGamesPlayed();
|
int getGamesPlayed();
|
||||||
|
|||||||
@@ -120,7 +120,6 @@ public:
|
|||||||
MTGCard * _(int id);
|
MTGCard * _(int id);
|
||||||
MTGCard * getCardById(int id);
|
MTGCard * getCardById(int id);
|
||||||
MTGCard * getCardByName(string name);
|
MTGCard * getCardByName(string name);
|
||||||
MTGCard * getCard(string inputText);
|
|
||||||
int load(const char * config_file, const char * setName = NULL, int autoload = 1);
|
int load(const char * config_file, const char * setName = NULL, int autoload = 1);
|
||||||
int countByType(const char * _type);
|
int countByType(const char * _type);
|
||||||
int countByColor(int color);
|
int countByColor(int color);
|
||||||
@@ -155,14 +154,13 @@ protected:
|
|||||||
public:
|
public:
|
||||||
MTGAllCards * database;
|
MTGAllCards * database;
|
||||||
map<int, int> cards;
|
map<int, int> cards;
|
||||||
map<int, int> alternates;
|
|
||||||
string meta_desc;
|
string meta_desc;
|
||||||
string meta_name;
|
string meta_name;
|
||||||
int meta_id;
|
int meta_id;
|
||||||
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);
|
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,
|
int addRandomCards(int howmany, int * setIds = NULL, int nbSets = 0, int rarity = -1, const char * subtype = NULL,
|
||||||
int * colors = NULL, int nbcolors = 0);
|
int * colors = NULL, int nbcolors = 0);
|
||||||
int add(int cardid);
|
int add(int cardid);
|
||||||
|
|||||||
@@ -1180,8 +1180,17 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
|
|||||||
sprintf(deckFileSmall, "ai_baka_deck%i", deckid);
|
sprintf(deckFileSmall, "ai_baka_deck%i", deckid);
|
||||||
}
|
}
|
||||||
DeckStats * stats = DeckStats::GetInstance();
|
DeckStats * stats = DeckStats::GetInstance();
|
||||||
|
int deckSetting = NULL;
|
||||||
MTGDeck * tempDeck = NEW MTGDeck(deckFile, collection, 0);
|
int diff = stats->percentVictories();
|
||||||
|
if (diff >= 65)
|
||||||
|
{
|
||||||
|
deckSetting = HARD;
|
||||||
|
}
|
||||||
|
else if (diff < 65)
|
||||||
|
{
|
||||||
|
deckSetting = EASY;
|
||||||
|
}
|
||||||
|
MTGDeck * tempDeck = NEW MTGDeck(deckFile, collection,0,deckSetting);
|
||||||
AIPlayerBaka * baka = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, avatarFile);
|
AIPlayerBaka * baka = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, avatarFile);
|
||||||
baka->deckId = deckid;
|
baka->deckId = deckid;
|
||||||
SAFE_DELETE(tempDeck);
|
SAFE_DELETE(tempDeck);
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ void DeckMetaData::LoadDeck()
|
|||||||
mDescription = trim(deck.meta_desc);
|
mDescription = trim(deck.meta_desc);
|
||||||
mDeckId = atoi((mFilename.substr(mFilename.find("deck") + 4, mFilename.find(".txt"))).c_str());
|
mDeckId = atoi((mFilename.substr(mFilename.find("deck") + 4, mFilename.find(".txt"))).c_str());
|
||||||
mDeckLoaded = true;
|
mDeckLoaded = true;
|
||||||
mAlternateCardMap = deck.alternates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -182,11 +181,6 @@ string DeckMetaData::getStatsSummary()
|
|||||||
return statsSummary.str();
|
return statsSummary.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
map<int,int>& DeckMetaData::getAlternateMappings()
|
|
||||||
{
|
|
||||||
return mAlternateCardMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckMetaData::setColorIndex(const string& colorIndex)
|
void DeckMetaData::setColorIndex(const string& colorIndex)
|
||||||
{
|
{
|
||||||
mColorIndex = colorIndex;
|
mColorIndex = colorIndex;
|
||||||
|
|||||||
@@ -676,18 +676,16 @@ MTGCard * MTGAllCards::getCardByName(string name)
|
|||||||
if (!name.size()) return NULL;
|
if (!name.size()) return NULL;
|
||||||
if (name[0] == '#') return NULL;
|
if (name[0] == '#') return NULL;
|
||||||
|
|
||||||
map<string, MTGCard * >::iterator cached = mtgCardByNameCache.end();
|
map<string, MTGCard * >::iterator cached = mtgCardByNameCache.find(name);
|
||||||
if ( mtgCardByNameCache.size() > 0 )
|
|
||||||
cached = mtgCardByNameCache.find(name);
|
|
||||||
if (cached!= mtgCardByNameCache.end())
|
if (cached!= mtgCardByNameCache.end())
|
||||||
{
|
{
|
||||||
return cached->second;
|
return cached->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cardId = atoi(name.c_str());
|
int cardnb = atoi(name.c_str());
|
||||||
if (cardId)
|
if (cardnb)
|
||||||
{
|
{
|
||||||
MTGCard * result = getCardById(cardId);
|
MTGCard * result = getCardById(cardnb);
|
||||||
mtgCardByNameCache[name] = result;
|
mtgCardByNameCache[name] = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -744,7 +742,7 @@ int MTGDeck::totalPrice()
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_only)
|
MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_only,int difficultyRating)
|
||||||
{
|
{
|
||||||
total_cards = 0;
|
total_cards = 0;
|
||||||
database = _allcards;
|
database = _allcards;
|
||||||
@@ -777,44 +775,58 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
|
|||||||
meta_desc.append(s.substr(found + 5));
|
meta_desc.append(s.substr(found + 5));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
found = s.find("toggledifficulty:");
|
|
||||||
if (found != string::npos)
|
|
||||||
{
|
|
||||||
string cards = s.substr(found + 17);
|
|
||||||
size_t separator = cards.find("|");
|
|
||||||
string cardeasy = cards.substr(0,separator);
|
|
||||||
string cardhard = cards.substr(separator + 1);
|
|
||||||
MTGCard *sourceCard = MTGCollection()->getCardByName( cardeasy );
|
|
||||||
MTGCard *alternateCard = MTGCollection()->getCardByName( cardhard );
|
|
||||||
if ( alternateCard && sourceCard )
|
|
||||||
alternates.insert( make_pair( sourceCard->getMTGId(), alternateCard->getMTGId()));
|
|
||||||
else
|
|
||||||
DebugTrace("Failed to map card Alternates: [" << cardeasy << "] and [" << cardhard << "]");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (meta_only) break;
|
if (meta_only) break;
|
||||||
int numberOfCopies = 1;
|
int nb = 1;
|
||||||
size_t found = s.find(" *");
|
size_t found = s.find(" *");
|
||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
numberOfCopies = atoi(s.substr(found + 2).c_str());
|
nb = atoi(s.substr(found + 2).c_str());
|
||||||
s = s.substr(0, found);
|
s = s.substr(0, found);
|
||||||
}
|
}
|
||||||
MTGCard *card = database->getCardByName( s );
|
size_t diff = s.find("toggledifficulty:");
|
||||||
if ( card )
|
if(diff != string::npos)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numberOfCopies; i++)
|
string cards = s.substr(diff + 17);
|
||||||
|
size_t separator = cards.find("|");
|
||||||
|
string cardeasy = cards.substr(0,separator);
|
||||||
|
string cardhard = cards.substr(separator + 1);
|
||||||
|
if(difficultyRating == HARD)
|
||||||
{
|
{
|
||||||
add(card);
|
s = cardhard;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s = cardeasy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int cardnb = atoi(s.c_str());
|
||||||
|
if (cardnb)
|
||||||
|
{
|
||||||
|
add(cardnb);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DebugTrace("could not find Card matching name: " << s);
|
size_t found = s.find(" *");
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
nb = atoi(s.substr(found + 2).c_str());
|
||||||
|
s = s.substr(0, found);
|
||||||
|
}
|
||||||
|
MTGCard * card = database->getCardByName(s);
|
||||||
|
if (card)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < nb; i++)
|
||||||
|
{
|
||||||
|
add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugTrace("could not find Card matching name: " << s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "DeckManager.h"
|
|
||||||
#include "DeckMetaData.h"
|
|
||||||
#include "MTGGameZones.h"
|
#include "MTGGameZones.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "GameOptions.h"
|
#include "GameOptions.h"
|
||||||
@@ -45,20 +43,10 @@ MTGPlayerCards::MTGPlayerCards(MTGDeck * deck)
|
|||||||
void MTGPlayerCards::initDeck(MTGDeck * deck)
|
void MTGPlayerCards::initDeck(MTGDeck * deck)
|
||||||
{
|
{
|
||||||
resetLibrary();
|
resetLibrary();
|
||||||
bool isAI = deck->getFilename().find("baka") != string::npos;
|
|
||||||
DeckMetaData *deckMeta = DeckManager::GetInstance()->getDeckMetaDataById( deck->meta_id, isAI);
|
|
||||||
map<int,int> alternatesMap = deckMeta->getAlternateMappings();
|
|
||||||
bool useAlternates = deckMeta->getVictoryPercentage() >= 65;
|
|
||||||
map<int, int>::iterator it;
|
map<int, int>::iterator it;
|
||||||
for (it = deck->cards.begin(); it != deck->cards.end(); it++)
|
for (it = deck->cards.begin(); it != deck->cards.end(); it++)
|
||||||
{
|
{
|
||||||
int cardId = it->first;
|
MTGCard * card = deck->getCardById(it->first);
|
||||||
if (useAlternates && isAI)
|
|
||||||
{
|
|
||||||
if ( alternatesMap.find( cardId ) != alternatesMap.end() )
|
|
||||||
cardId = alternatesMap[ cardId ];
|
|
||||||
}
|
|
||||||
MTGCard * card = deck->getCardById(cardId);
|
|
||||||
if (card)
|
if (card)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < it->second; i++)
|
for (int i = 0; i < it->second; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user