-Fixed bug with fountain of youth
-New alternate format for decks
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-04-02 12:50:18 +00:00
parent 3e1bcbfd22
commit 5952b382a2
13 changed files with 132 additions and 56 deletions
+3 -2
View File
@@ -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;
}
+7 -5
View File
@@ -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;
}
+50 -1
View File
@@ -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; i<total_cards; i++){
if (setId!=-1 && setId != collection[i]->setId) 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{
+18
View File
@@ -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 <time.h>
@@ -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; i<deck->totalCards(); i++){
MTGCard * card = deck->collection[i];
if (card){
MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
library->addCard(newCard);
}
}
}
MTGPlayerCards::~MTGPlayerCards(){
+23 -14
View File
@@ -5,7 +5,7 @@
#include <string>
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;
}
-27
View File
@@ -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){