From 5005f69a6978e5730e84c61c9321d202ef5432df Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Wed, 13 Oct 2010 15:24:52 +0000 Subject: [PATCH] added current AI deck name to "start" menu while dueling --- projects/mtg/include/AIMomirPlayer.h | 2 +- projects/mtg/include/AIPlayer.h | 4 ++-- projects/mtg/include/AllAbilities.h | 2 ++ projects/mtg/include/GameStateDuel.h | 3 ++- projects/mtg/include/Player.h | 6 ++++-- projects/mtg/src/AIMomirPlayer.cpp | 2 +- projects/mtg/src/AIPlayer.cpp | 12 +++++++----- projects/mtg/src/GameStateDuel.cpp | 21 +++++++++++---------- projects/mtg/src/Player.cpp | 17 ++++++++++++----- projects/mtg/src/Rules.cpp | 21 +++++++++++---------- projects/mtg/src/StoryFlow.cpp | 4 ++-- projects/mtg/src/TestSuiteAI.cpp | 8 ++++++-- 12 files changed, 61 insertions(+), 41 deletions(-) diff --git a/projects/mtg/include/AIMomirPlayer.h b/projects/mtg/include/AIMomirPlayer.h index bc86657c4..56721b50d 100644 --- a/projects/mtg/include/AIMomirPlayer.h +++ b/projects/mtg/include/AIMomirPlayer.h @@ -6,7 +6,7 @@ class AIMomirPlayer:public AIPlayerBaka{ public: - AIMomirPlayer(MTGPlayerCards * deck, string file, string fileSmall, string avatarFile); + AIMomirPlayer(MTGDeck * deck, string file, string fileSmall, string avatarFile); int getEfficiency(AIAction * action); int momir(); int computeActions(); diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index 73bdcbbd0..e86c47fad 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -71,7 +71,7 @@ class AIPlayer: public Player{ void Render(); AIStats * stats; ManaCost * getPotentialMana(MTGCardInstance * card = NULL); - AIPlayer(MTGPlayerCards * deck, string deckFile, string deckFileSmall); + AIPlayer(MTGDeck * deck, string deckFile, string deckFileSmall); virtual ~AIPlayer(); virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0); virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL); @@ -94,7 +94,7 @@ class AIPlayerBaka: public AIPlayer{ MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type); public: int deckId; - AIPlayerBaka(MTGPlayerCards * deck, string deckFile, string deckfileSmall, string avatarFile); + AIPlayerBaka(MTGDeck * deck, string deckFile, string deckfileSmall, string avatarFile); virtual int Act(float dt); void initTimer(); virtual int computeActions(); diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index df675221d..10d389dc6 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -374,6 +374,8 @@ public: int resolve(){ vector::size_type sz = abilities.size(); for (unsigned int i = 0; i < sz; i++){ + if (abilities[i] == NULL) + continue; Targetable * backup = abilities[i]->target; if (target && target!= source && abilities[i]->target == abilities[i]->source) abilities[i]->target = target; abilities[i]->resolve(); diff --git a/projects/mtg/include/GameStateDuel.h b/projects/mtg/include/GameStateDuel.h index c93a2fbba..7559b2cee 100644 --- a/projects/mtg/include/GameStateDuel.h +++ b/projects/mtg/include/GameStateDuel.h @@ -60,7 +60,8 @@ class GameStateDuel: public GameState, public JGuiListener MENUITEM_RANDOM_PLAYER = -11, MENUITEM_RANDOM_AI = -12, MENUITEM_MAIN_MENU = -13, - MENUITEM_EVIL_TWIN = -14 + MENUITEM_EVIL_TWIN = -14, + MENUITEM_MULLIGAN = -15 }; }; diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index 5d774a4e2..8a0604b12 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -6,6 +6,7 @@ #include "Damage.h" #include "Targetable.h" +class MTGDeck; class MTGPlayerCards; class MTGInPlay; class ManaPool; @@ -45,7 +46,7 @@ class Player: public Damageable{ int poisoned(); int damaged(); int prevented(); - Player(MTGPlayerCards * deck, string deckFile, string deckFileSmall); + Player(MTGDeck * deck, string deckFile, string deckFileSmall); virtual ~Player(); void unTapPhase(); MTGInPlay * inPlay(); @@ -58,6 +59,7 @@ class Player: public Damageable{ JQuad * getIcon(); string deckFile; string deckFileSmall; + string deckName; virtual int receiveEvent(WEvent * event){return 0;}; virtual void Render(){}; @@ -66,7 +68,7 @@ class Player: public Damageable{ class HumanPlayer: public Player{ public: - HumanPlayer(MTGPlayerCards * deck, string deckFile, string deckFileSmall); + HumanPlayer(MTGDeck * deck, string deckFile, string deckFileSmall); HumanPlayer(string deckFile); }; diff --git a/projects/mtg/src/AIMomirPlayer.cpp b/projects/mtg/src/AIMomirPlayer.cpp index c31565743..61f1252f5 100644 --- a/projects/mtg/src/AIMomirPlayer.cpp +++ b/projects/mtg/src/AIMomirPlayer.cpp @@ -8,7 +8,7 @@ MTGAbility * AIMomirPlayer::momirAbility = NULL; -AIMomirPlayer::AIMomirPlayer(MTGPlayerCards * deck, string file, string fileSmall, string avatarFile) : AIPlayerBaka(deck, file, fileSmall, avatarFile) { +AIMomirPlayer::AIMomirPlayer(MTGDeck * deck, string file, string fileSmall, string avatarFile) : AIPlayerBaka(deck, file, fileSmall, avatarFile) { momirAbility = NULL; agressivity = 100; } diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 16089f408..814d8a04a 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -30,7 +30,7 @@ int AIAction::Act(){ return 0; } -AIPlayer::AIPlayer(MTGPlayerCards * deck, string file, string fileSmall) : Player(deck, file, fileSmall) { +AIPlayer::AIPlayer(MTGDeck * deck, string file, string fileSmall) : Player(deck, file, fileSmall) { nextCardToPlay = NULL; stats = NULL; agressivity = 50; @@ -605,10 +605,11 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op } MTGDeck * tempDeck = NEW MTGDeck(deckFile, collection); - MTGPlayerCards * deck = NEW MTGPlayerCards(tempDeck); + //MTGPlayerCards * deck = NEW MTGPlayerCards(tempDeck); + AIPlayerBaka * baka = NEW AIPlayerBaka(tempDeck,deckFile, deckFileSmall, avatarFile); + baka->deckId = deckid; + delete tempDeck; - AIPlayerBaka * baka = NEW AIPlayerBaka(deck,deckFile, deckFileSmall, avatarFile); - baka->deckId = deckid; return baka; } @@ -664,7 +665,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty return nextCardToPlay; } -AIPlayerBaka::AIPlayerBaka(MTGPlayerCards * deck, string file, string fileSmall, string avatarFile) : AIPlayer(deck, file, fileSmall) { +AIPlayerBaka::AIPlayerBaka(MTGDeck * deck, string file, string fileSmall, string avatarFile) : AIPlayer(deck, file, fileSmall) { mAvatarTex = resources.RetrieveTexture(avatarFile,RETRIEVE_LOCK,TEXTURE_SUB_AVATAR); if(!mAvatarTex){ @@ -680,6 +681,7 @@ AIPlayerBaka::AIPlayerBaka(MTGPlayerCards * deck, string file, string fileSmall, initTimer(); } + void AIPlayerBaka::initTimer(){ timer = 0.1f; } diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index ea131ce82..28e2a6c5e 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -146,11 +146,12 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){ char deckFileSmall[255]; sprintf(deckFileSmall, "player_deck%i",decknb); MTGDeck * tempDeck = NEW MTGDeck(deckFile, mParent->collection); - deck[playerId] = NEW MTGPlayerCards(tempDeck); + mPlayers[playerId] = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall); + + deck[playerId] = mPlayers[playerId]->game; delete tempDeck; - mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFile, deckFileSmall); } - else { //AI Player, chose deck + else { //AI Player, chooses deck AIPlayerFactory playerCreator; Player * opponent = NULL; if (playerId == 1) opponent = mPlayers[0]; @@ -371,7 +372,7 @@ void GameStateDuel::Update(float dt) } if (mEngine->GetButtonClick(JGE_BTN_MENU)) { if (!menu) { - menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, Constants::MENU_FONT, SCREEN_WIDTH/2-100, 25); + menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, Constants::MENU_FONT, SCREEN_WIDTH/2-100, 25, game->players[1]->deckName.c_str()); int cardsinhand = game->players[0]->game->hand->nb_cards; //almosthumane - mulligan @@ -382,11 +383,11 @@ void GameStateDuel::Update(float dt) && game->players[0]->game->exile->nb_cards == 0) //1st Play Check //IF there was no play at the moment automatically mulligan { - menu->Add(14,"Mulligan"); + menu->Add( MENUITEM_MULLIGAN, "Mulligan"); } //END almosthumane - mulligan - menu->Add(12, "Back to main menu"); - menu->Add(13, "Cancel"); + menu->Add(MENUITEM_MAIN_MENU, "Back to main menu"); + menu->Add(MENUITEM_CANCEL, "Cancel"); } mGamePhase = DUEL_STATE_MENU; } @@ -577,15 +578,15 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) { switch (controlId) { - case 12: + case MENUITEM_MAIN_MENU: menu->Close(); mGamePhase = DUEL_STATE_BACK_TO_MAIN_MENU; break; - case 13: + case MENUITEM_CANCEL: menu->Close(); mGamePhase = DUEL_STATE_CANCEL; break; - case 14: + case MENUITEM_MULLIGAN: //almosthumane - mulligan { diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index 492d5cb4f..66b7b1833 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -5,11 +5,11 @@ #include "../include/ManaCost.h" -Player::Player(MTGPlayerCards * deck, string file, string fileSmall) : Damageable(20){ + + +Player::Player(MTGDeck * deck, string file, string fileSmall) : Damageable(20){ deckFile = file; deckFileSmall = fileSmall; - game = deck; - game->setOwner(this); manaPool = NEW ManaPool(this); canPutLandsIntoPlay = 1; nomaxhandsize = 0; @@ -28,6 +28,12 @@ Player::Player(MTGPlayerCards * deck, string file, string fileSmall) : Damageabl mAvatarTex = NULL; type_as_damageable = DAMAGEABLE_PLAYER; playMode = MODE_HUMAN; + if ( deck != NULL ) + { + game = NEW MTGPlayerCards( deck ); + game->setOwner(this); + deckName = deck->meta_name; + } } /*Method to call at the end of a game, before all objects involved in the game are destroyed */ @@ -37,6 +43,7 @@ void Player::End(){ Player::~Player(){ SAFE_DELETE(manaPool); + SAFE_DELETE(game); resources.Release(mAvatarTex); mAvatar = NULL; mAvatarTex = NULL; @@ -83,13 +90,13 @@ Player * Player::opponent(){ return this == game->players[0] ? game->players[1] : game->players[0]; } -HumanPlayer::HumanPlayer(MTGPlayerCards * deck, string file, string fileSmall) : Player(deck, file, fileSmall) { + +HumanPlayer::HumanPlayer(MTGDeck * deck, string file, string fileSmall) : Player(deck, file, fileSmall) { loadAvatar("avatar.jpg"); playMode = MODE_HUMAN; } - ManaPool * Player::getManaPool(){ return manaPool; } diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index fb1c7439d..da9e0d337 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -164,7 +164,7 @@ void Rules::addExtraRules(){ Player * Rules::loadPlayerMomir(int isAI){ string deckFileSmall = "momir"; char empty[] = ""; - + MTGDeck * tempDeck = NEW MTGDeck(GameApp::collection); //Autogenerate a momir deck. Leave the "momir.txt" bits below for stats. tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Forest"); tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Plains"); @@ -172,13 +172,14 @@ Player * Rules::loadPlayerMomir(int isAI){ tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Mountain"); tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Island"); - MTGPlayerCards * deck = NEW MTGPlayerCards( tempDeck); - delete tempDeck; + Player *player = NULL; if (!isAI) // Human Player - return NEW HumanPlayer(deck, options.profileFile("momir.txt","",true).c_str(), deckFileSmall); + player = NEW HumanPlayer(tempDeck, options.profileFile("momir.txt","",true).c_str(), deckFileSmall); else - return NEW AIMomirPlayer(deck, options.profileFile("momir.txt","",true).c_str(), deckFileSmall, empty); + player = NEW AIMomirPlayer(tempDeck, options.profileFile("momir.txt","",true).c_str(), deckFileSmall, empty); + delete tempDeck; + return player; } Player * Rules::loadPlayerRandom(int isAI, int mode){ @@ -206,13 +207,13 @@ Player * Rules::loadPlayerRandom(int isAI, int mode){ string deckFile = "random"; string deckFileSmall = "random"; - MTGPlayerCards * deck = NEW MTGPlayerCards(tempDeck); - delete tempDeck; - + Player *player = NULL; if (!isAI) // Human Player - return NEW HumanPlayer(deck, deckFile, deckFileSmall); + player = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall); else - return NEW AIPlayerBaka(deck,deckFile, deckFileSmall, ""); + player = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, ""); + + return player; } diff --git a/projects/mtg/src/StoryFlow.cpp b/projects/mtg/src/StoryFlow.cpp index e7d511fca..02b0f4270 100644 --- a/projects/mtg/src/StoryFlow.cpp +++ b/projects/mtg/src/StoryFlow.cpp @@ -274,13 +274,13 @@ void StoryDuel::init(){ sprintf(deckFile, "%s/deck.txt", folder); MTGDeck * tempDeck = NEW MTGDeck(deckFile, GameApp::collection); sprintf(deckFileSmall, "campaign_%s", mParent->folder.c_str()); - players[0] = NEW HumanPlayer(NEW MTGPlayerCards(tempDeck),deckFile,deckFileSmall); + players[0] = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall); SAFE_DELETE(tempDeck); sprintf(deckFile,"%s/opponent_deck.txt", folder); tempDeck = NEW MTGDeck(deckFile, GameApp::collection); sprintf(deckFileSmall, "campaign_ennemy_%s_%s", mParent->folder.c_str(), pageId.c_str()); - players[1] = NEW AIPlayerBaka(NEW MTGPlayerCards(tempDeck),deckFile,deckFileSmall,"baka.jpg"); + players[1] = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, "baka.jpg"); SAFE_DELETE(tempDeck); string rulesFile = folder; diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 00b687398..e7572a74b 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -11,11 +11,15 @@ #include using std::string; - -TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId):AIPlayerBaka(_suite->buildDeck(playerId),"testsuite", "testsuite","baka.jpg"){ +// NULL is sent in place of a MTGDeck since there is no way to create a MTGDeck without a proper deck file. +// TestSuiteAI will be responsible for managing its own deck state. +TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId):AIPlayerBaka(NULL, "testsuite", "testsuite", "baka.jpg") { + this->game = _suite->buildDeck(playerId); + game->setOwner( this ); suite = _suite; timer = 0; playMode = MODE_TEST_SUITE; + this->deckName = "Test Suite AI"; }