diff --git a/projects/mtg/bin/Res/sets/10E/_cards.dat b/projects/mtg/bin/Res/sets/10E/_cards.dat index d3667ed1c..9953b9597 100644 --- a/projects/mtg/bin/Res/sets/10E/_cards.dat +++ b/projects/mtg/bin/Res/sets/10E/_cards.dat @@ -666,7 +666,7 @@ subtype=Forest [/card] [card] text={2}, {T}: You gain 1 life. -auto={2},{T}:life 1 +auto={2},{T}:life:1 id=135273 name=Fountain of Youth rarity=U diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index b0e9976f8..6b18cb05c 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -50,6 +50,7 @@ foratog.txt force_of_nature.txt force_of_nature2.txt force_of_nature3.txt +fountain_of_youth.txt ghost_warden.txt giant_growth.txt giant_growth2.txt diff --git a/projects/mtg/bin/Res/test/fountain_of_youth.txt b/projects/mtg/bin/Res/test/fountain_of_youth.txt new file mode 100644 index 000000000..1a907e628 --- /dev/null +++ b/projects/mtg/bin/Res/test/fountain_of_youth.txt @@ -0,0 +1,17 @@ +#Testing Does fountain of youth give +1 life ? +[INIT] +FIRSTMAIN +[PLAYER1] +inplay:fountain of youth +manapool:{2} +[PLAYER2] +[DO] +fountain of youth +[ASSERT] +FIRSTMAIN +[PLAYER1] +inplay:fountain of youth +manapool:{0} +life:21 +[PLAYER2] +[END] \ No newline at end of file diff --git a/projects/mtg/include/MTGDeck.h b/projects/mtg/include/MTGDeck.h index 0dea84d56..cd5272383 100644 --- a/projects/mtg/include/MTGDeck.h +++ b/projects/mtg/include/MTGDeck.h @@ -35,6 +35,7 @@ class MtgSets{ static MtgSets * SetsList; MtgSets(); int Add(const char * subtype); + int find(string value); }; @@ -59,6 +60,7 @@ class MTGAllCards { MTGAllCards(const char * config_file, const char * set_name); MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache); MTGCard * getCardById(int id); + MTGCard * getCardByName(string name); int load(const char * config_file, const char * setName, int autoload = 1); int countByType(const char * _type); int countByColor(int color); diff --git a/projects/mtg/include/MTGGameZones.h b/projects/mtg/include/MTGGameZones.h index 5713a0b1e..1fa83811b 100644 --- a/projects/mtg/include/MTGGameZones.h +++ b/projects/mtg/include/MTGGameZones.h @@ -10,6 +10,7 @@ using std::map; #define MTG_MAX_PLAYER_CARDS 100 class MTGAllCards; +class MTGDeck; class MTGCardInstance; class Player; @@ -88,6 +89,7 @@ class MTGPlayerCards { MTGAllCards * collection; MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize); + MTGPlayerCards(MTGAllCards * _collection, MTGDeck * deck); ~MTGPlayerCards(); void initGame(int shuffle = 1, int draw = 1); void setOwner(Player * player); diff --git a/projects/mtg/include/TestSuiteAI.h b/projects/mtg/include/TestSuiteAI.h index fbb4bf6ac..e72dbe9b7 100644 --- a/projects/mtg/include/TestSuiteAI.h +++ b/projects/mtg/include/TestSuiteAI.h @@ -37,16 +37,19 @@ class TestSuitePlayerData{ +class TestSuite; class TestSuiteState{ public: int phase; - void parsePlayerState(int playerId, string s); + void parsePlayerState(int playerId, string s,TestSuite * suite); TestSuiteState(); TestSuitePlayerData playerData[2]; void cleanup(); }; + class TestSuite{ public: + MTGAllCards* collection; int summoningSickness; float timerLimit; int currentAction; @@ -57,10 +60,10 @@ class TestSuite{ int nbfiles; int currentfile; void load(const char * filename); - TestSuite(const char * filename); + TestSuite(const char * filename,MTGAllCards* _collection); void initGame(); int assertGame(); - MTGPlayerCards * buildDeck(MTGAllCards * collection, int playerId); + MTGPlayerCards * buildDeck(int playerId); string getNextAction(); int phaseStrToInt(string s); MTGCardInstance * getCardByMTGId(int mtgid); @@ -68,6 +71,7 @@ class TestSuite{ int loadNext(); void cleanup(); int Log(const char * text); + int getMTGId(string name); }; @@ -75,7 +79,7 @@ class TestSuiteAI:public AIPlayer{ public: TestSuite * suite; float timer; - TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId); + TestSuiteAI(TestSuite * suite, int playerId); virtual int Act(float dt); virtual int displayStack(){return 1;} diff --git a/projects/mtg/include/utils.h b/projects/mtg/include/utils.h index d46a045e3..fe593472c 100644 --- a/projects/mtg/include/utils.h +++ b/projects/mtg/include/utils.h @@ -30,10 +30,8 @@ using std::string; -int lowercase(string source); int filesize(const char * filename); -int readfile_to_ints(const char * filename, int * out_buffer); int fileExists(const char * filename); #ifdef LINUX diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 0f4e1967c..3abcacb6e 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -551,8 +551,9 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, MTGPlayerCa OutputDebugString(debuf); #endif int deck_cards_ids[100]; - int nb_elements = readfile_to_ints(deckFile, deck_cards_ids); - MTGPlayerCards * deck = NEW MTGPlayerCards(collection,deck_cards_ids, nb_elements); + MTGDeck * tempDeck = NEW MTGDeck(deckFile, NULL, collection); + MTGPlayerCards * deck = NEW MTGPlayerCards(collection,tempDeck); + delete tempDeck; AIPlayerBaka * baka = NEW AIPlayerBaka(deck,deckFileSmall, avatarFile); return baka; } diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index b63ef5ea0..44acb5304 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -66,7 +66,7 @@ void GameStateDuel::Start() #ifdef TESTSUITE if (testSuite) delete testSuite; - testSuite = NEW TestSuite(RESPATH"/test/_tests.txt"); + testSuite = NEW TestSuite(RESPATH"/test/_tests.txt",mParent->collection); #endif @@ -117,9 +117,11 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){ sprintf(deckFile, RESPATH"/player/deck%i.txt",decknb); char deckFileSmall[255]; sprintf(deckFileSmall, "player_deck%i",decknb); - int deck_cards_ids[100]; - int nb_elements = readfile_to_ints(deckFile, deck_cards_ids); - deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements); + //int deck_cards_ids[100]; + //int nb_elements = readfile_to_ints(deckFile, deck_cards_ids); + MTGDeck * tempDeck = NEW MTGDeck(deckFile, NULL, mParent->collection); + deck[playerId] = NEW MTGPlayerCards(mParent->collection,tempDeck); + delete tempDeck; mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall); }else{ //AI Player, chose deck AIPlayerFactory playerCreator; @@ -141,7 +143,7 @@ void GameStateDuel::loadTestSuitePlayers(){ if (mPlayers[i]){ delete mPlayers[i]; } - mPlayers[i] = NEW TestSuiteAI(mParent->collection,testSuite, i); + mPlayers[i] = NEW TestSuiteAI(testSuite, i); OutputDebugString ("loading suite 2\n"); deck[i] = mPlayers[i]->game; } diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index fb39ee2ea..26b2c1456 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -30,6 +30,16 @@ int MtgSets::Add(const char * name){ return nb_items - 1; } +int MtgSets::find(string name){ + std::transform(name.begin(), name.end(), name.begin(),::tolower ); + for (int i = 0; i < nb_items; i++){ + string set = values[i]; + std::transform(set.begin(), set.end(), set.begin(),::tolower );; + if (set.compare(name) == 0) return i; + } + return -1; +} + int MTGAllCards::processConfLine(string s, MTGCard *card){ unsigned int i = s.find_first_of("="); @@ -279,6 +289,29 @@ MTGCard * MTGAllCards::getCardById(int id){ return 0; } +MTGCard * MTGAllCards::getCardByName(string name){ + if (!name.size()) return NULL; + if (name[0] == '#') return NULL; + std::transform(name.begin(), name.end(), name.begin(),::tolower ); + int setId = -1; + size_t found = name.find(" ("); + if (found != string::npos){ + size_t end = name.find(")"); + string setName = name.substr(found+2,end-found-2); + name = name.substr(0,found); + setId = MtgSets::SetsList->find(setName); + } + for (int i=0; isetId) continue; + string cardName = collection[i]->name; + std::transform(cardName.begin(), cardName.end(), cardName.begin(),::tolower ); + if (cardName.compare(name) == 0) return collection[i]; + + } + return NULL; +} + + MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){ @@ -292,7 +325,23 @@ MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * if(file){ while(std::getline(file,s)){ int cardnb = atoi(s.c_str()); - if (cardnb) add(cardnb); + if (cardnb){ + add(cardnb); + }else{ + int nb = 1; + size_t found = s.find(" *"); + if (found != string::npos){ + nb = atoi(s.substr(found+2).c_str()); + s=s.substr(0,found); + OutputDebugString(s.c_str()); + } + MTGCard * card = allcards->getCardByName(s); + if (card){ + for (int i = 0; i < nb; i++){ + add(card); + } + } + } } file.close(); }else{ diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 8dbf2130c..001de4683 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -3,6 +3,7 @@ #include "../include/Player.h" #include "../include/GameOptions.h" #include "../include/WEvent.h" +#include "../include/MTGDeck.h" #if defined (WIN32) || defined (LINUX) #include @@ -27,6 +28,23 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi +} + + + +MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection,MTGDeck * deck){ + init(); + collection = _collection; + for (int i=0; itotalCards(); i++){ + MTGCard * card = deck->collection[i]; + if (card){ + MTGCardInstance * newCard = NEW MTGCardInstance(card, this); + library->addCard(newCard); + } + } + + + } MTGPlayerCards::~MTGPlayerCards(){ diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 92ca3f18f..b1c3cbc00 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -5,7 +5,7 @@ #include using std::string; -TestSuiteAI::TestSuiteAI(MTGAllCards* collection, TestSuite * _suite, int playerId):AIPlayer(_suite->buildDeck(collection, playerId),"testsuite"){ +TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId):AIPlayer(_suite->buildDeck(playerId),"testsuite"){ suite = _suite; timer= 0; mAvatarTex = JRenderer::GetInstance()->LoadTexture("ai/baka/avatar.jpg", TEX_TYPE_USE_VRAM); @@ -14,6 +14,14 @@ TestSuiteAI::TestSuiteAI(MTGAllCards* collection, TestSuite * _suite, int player } } +int TestSuite::getMTGId(string cardName){ + int cardnb = atoi(cardName.c_str()); + if (cardnb) return cardnb; + MTGCard * card = collection->getCardByName(cardName); + if (card) return card->getMTGId(); + return 0; +} + MTGCardInstance * TestSuite::getCardByMTGId(int mtgid){ GameObserver * g = GameObserver::GetInstance(); for (int i = 0; i < 2; i++){ @@ -90,7 +98,7 @@ int TestSuiteAI::Act(float dt){ int choice = atoi(action.substr(action.find("choice ") + 7).c_str()); g->mLayers->actionLayer()->doReactTo(choice); }else{ - int mtgid = atoi(action.c_str()); + int mtgid = suite->getMTGId(action); if (mtgid){ Interruptible * toInterrupt = suite->getActionByMTGId(mtgid); if (toInterrupt){ @@ -140,7 +148,7 @@ TestSuiteState::TestSuiteState(){ } -void TestSuiteState::parsePlayerState(int playerId, string s){ +void TestSuiteState::parsePlayerState(int playerId, string s, TestSuite * suite){ unsigned int limiter = s.find(":"); string areaS; int area; @@ -169,13 +177,13 @@ void TestSuiteState::parsePlayerState(int playerId, string s){ unsigned int value; limiter = s.find(","); if (limiter != string::npos){ - value = atoi(s.substr(0,limiter).c_str()); - s = s.substr(limiter+1); + value = suite->getMTGId(s.substr(0,limiter)); + s = s.substr(limiter+1); }else{ - value = atoi(s.c_str()); - s = ""; + value = suite->getMTGId(s); + s = ""; } - playerData[playerId].zones[area].add(value); + if (value) playerData[playerId].zones[area].add(value); } }else{ //ERROR @@ -192,7 +200,7 @@ string TestSuite::getNextAction(){ } -MTGPlayerCards * TestSuite::buildDeck(MTGAllCards * collection, int playerId){ +MTGPlayerCards * TestSuite::buildDeck( int playerId){ int list[100]; int nbcards = 0; for (int j = 0; j < 4; j++){ @@ -324,7 +332,8 @@ int TestSuite::assertGame(){ return 1; } -TestSuite::TestSuite(const char * filename){ +TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){ + collection=_collection; timerLimit = 0; std::ifstream file(filename); std::string s; @@ -451,14 +460,14 @@ void TestSuite::load(const char * _filename){ if (s.compare("[player2]") == 0){ state++; }else{ - initState.parsePlayerState(0, s); + initState.parsePlayerState(0, s,this); } break; case 2: if (s.compare("[do]") == 0){ state++; }else{ - initState.parsePlayerState(1, s); + initState.parsePlayerState(1, s,this); } break; case 3: @@ -479,14 +488,14 @@ void TestSuite::load(const char * _filename){ if (s.compare("[player2]") == 0){ state++; }else{ - endState.parsePlayerState(0, s); + endState.parsePlayerState(0, s,this); } break; case 6: if (s.compare("[end]") == 0){ state++; }else{ - endState.parsePlayerState(1, s); + endState.parsePlayerState(1, s,this); } break; } diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index 6d27889b8..bdb047750 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -2,13 +2,6 @@ #include "../include/utils.h" -int lowercase(string sBuffer) { - std::transform( sBuffer.begin(), sBuffer.end(), sBuffer.begin(), - ::tolower ); - return 1; -} - - @@ -35,26 +28,6 @@ int filesize(const char * filename){ } - -int readfile_to_ints(const char * filename, int * out_buffer){ - std::ifstream fichier(filename); - std::string s; - unsigned int count = 0; - if(fichier){ - while(std::getline(fichier,s)){ - int value = atoi(s.c_str()); - if (value){ - out_buffer[count] = value; - ++count; - } - } - - } - fichier.close(); - return count; - -} - int fileExists(const char * filename){ std::ifstream fichier(filename); if(fichier){