added current AI deck name to "start" menu while dueling

This commit is contained in:
techdragon.nguyen@gmail.com
2010-10-13 15:24:52 +00:00
parent bb6267bbe4
commit 5005f69a69
12 changed files with 61 additions and 41 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
class AIMomirPlayer:public AIPlayerBaka{ class AIMomirPlayer:public AIPlayerBaka{
public: public:
AIMomirPlayer(MTGPlayerCards * deck, string file, string fileSmall, string avatarFile); AIMomirPlayer(MTGDeck * deck, string file, string fileSmall, string avatarFile);
int getEfficiency(AIAction * action); int getEfficiency(AIAction * action);
int momir(); int momir();
int computeActions(); int computeActions();
+2 -2
View File
@@ -71,7 +71,7 @@ class AIPlayer: public Player{
void Render(); void Render();
AIStats * stats; AIStats * stats;
ManaCost * getPotentialMana(MTGCardInstance * card = NULL); ManaCost * getPotentialMana(MTGCardInstance * card = NULL);
AIPlayer(MTGPlayerCards * deck, string deckFile, string deckFileSmall); AIPlayer(MTGDeck * deck, string deckFile, string deckFileSmall);
virtual ~AIPlayer(); virtual ~AIPlayer();
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0); virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL); virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL);
@@ -94,7 +94,7 @@ class AIPlayerBaka: public AIPlayer{
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type); MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
public: public:
int deckId; 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); virtual int Act(float dt);
void initTimer(); void initTimer();
virtual int computeActions(); virtual int computeActions();
+2
View File
@@ -374,6 +374,8 @@ public:
int resolve(){ int resolve(){
vector<int>::size_type sz = abilities.size(); vector<int>::size_type sz = abilities.size();
for (unsigned int i = 0; i < sz; i++){ for (unsigned int i = 0; i < sz; i++){
if (abilities[i] == NULL)
continue;
Targetable * backup = abilities[i]->target; Targetable * backup = abilities[i]->target;
if (target && target!= source && abilities[i]->target == abilities[i]->source) abilities[i]->target = target; if (target && target!= source && abilities[i]->target == abilities[i]->source) abilities[i]->target = target;
abilities[i]->resolve(); abilities[i]->resolve();
+2 -1
View File
@@ -60,7 +60,8 @@ class GameStateDuel: public GameState, public JGuiListener
MENUITEM_RANDOM_PLAYER = -11, MENUITEM_RANDOM_PLAYER = -11,
MENUITEM_RANDOM_AI = -12, MENUITEM_RANDOM_AI = -12,
MENUITEM_MAIN_MENU = -13, MENUITEM_MAIN_MENU = -13,
MENUITEM_EVIL_TWIN = -14 MENUITEM_EVIL_TWIN = -14,
MENUITEM_MULLIGAN = -15
}; };
}; };
+4 -2
View File
@@ -6,6 +6,7 @@
#include "Damage.h" #include "Damage.h"
#include "Targetable.h" #include "Targetable.h"
class MTGDeck;
class MTGPlayerCards; class MTGPlayerCards;
class MTGInPlay; class MTGInPlay;
class ManaPool; class ManaPool;
@@ -45,7 +46,7 @@ class Player: public Damageable{
int poisoned(); int poisoned();
int damaged(); int damaged();
int prevented(); int prevented();
Player(MTGPlayerCards * deck, string deckFile, string deckFileSmall); Player(MTGDeck * deck, string deckFile, string deckFileSmall);
virtual ~Player(); virtual ~Player();
void unTapPhase(); void unTapPhase();
MTGInPlay * inPlay(); MTGInPlay * inPlay();
@@ -58,6 +59,7 @@ class Player: public Damageable{
JQuad * getIcon(); JQuad * getIcon();
string deckFile; string deckFile;
string deckFileSmall; string deckFileSmall;
string deckName;
virtual int receiveEvent(WEvent * event){return 0;}; virtual int receiveEvent(WEvent * event){return 0;};
virtual void Render(){}; virtual void Render(){};
@@ -66,7 +68,7 @@ class Player: public Damageable{
class HumanPlayer: public Player{ class HumanPlayer: public Player{
public: public:
HumanPlayer(MTGPlayerCards * deck, string deckFile, string deckFileSmall); HumanPlayer(MTGDeck * deck, string deckFile, string deckFileSmall);
HumanPlayer(string deckFile); HumanPlayer(string deckFile);
}; };
+1 -1
View File
@@ -8,7 +8,7 @@
MTGAbility * AIMomirPlayer::momirAbility = NULL; 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; momirAbility = NULL;
agressivity = 100; agressivity = 100;
} }
+7 -5
View File
@@ -30,7 +30,7 @@ int AIAction::Act(){
return 0; 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; nextCardToPlay = NULL;
stats = NULL; stats = NULL;
agressivity = 50; agressivity = 50;
@@ -605,10 +605,11 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
} }
MTGDeck * tempDeck = NEW MTGDeck(deckFile, collection); 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; delete tempDeck;
AIPlayerBaka * baka = NEW AIPlayerBaka(deck,deckFile, deckFileSmall, avatarFile);
baka->deckId = deckid;
return baka; return baka;
} }
@@ -664,7 +665,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
return nextCardToPlay; 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); mAvatarTex = resources.RetrieveTexture(avatarFile,RETRIEVE_LOCK,TEXTURE_SUB_AVATAR);
if(!mAvatarTex){ if(!mAvatarTex){
@@ -680,6 +681,7 @@ AIPlayerBaka::AIPlayerBaka(MTGPlayerCards * deck, string file, string fileSmall,
initTimer(); initTimer();
} }
void AIPlayerBaka::initTimer(){ void AIPlayerBaka::initTimer(){
timer = 0.1f; timer = 0.1f;
} }
+11 -10
View File
@@ -146,11 +146,12 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
char deckFileSmall[255]; char deckFileSmall[255];
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);
deck[playerId] = NEW MTGPlayerCards(tempDeck); mPlayers[playerId] = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall);
deck[playerId] = mPlayers[playerId]->game;
delete tempDeck; delete tempDeck;
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFile, deckFileSmall);
} }
else { //AI Player, chose deck else { //AI Player, chooses deck
AIPlayerFactory playerCreator; AIPlayerFactory playerCreator;
Player * opponent = NULL; Player * opponent = NULL;
if (playerId == 1) opponent = mPlayers[0]; if (playerId == 1) opponent = mPlayers[0];
@@ -371,7 +372,7 @@ void GameStateDuel::Update(float dt)
} }
if (mEngine->GetButtonClick(JGE_BTN_MENU)) { if (mEngine->GetButtonClick(JGE_BTN_MENU)) {
if (!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; int cardsinhand = game->players[0]->game->hand->nb_cards;
//almosthumane - mulligan //almosthumane - mulligan
@@ -382,11 +383,11 @@ void GameStateDuel::Update(float dt)
&& game->players[0]->game->exile->nb_cards == 0) //1st Play Check && game->players[0]->game->exile->nb_cards == 0) //1st Play Check
//IF there was no play at the moment automatically mulligan //IF there was no play at the moment automatically mulligan
{ {
menu->Add(14,"Mulligan"); menu->Add( MENUITEM_MULLIGAN, "Mulligan");
} }
//END almosthumane - mulligan //END almosthumane - mulligan
menu->Add(12, "Back to main menu"); menu->Add(MENUITEM_MAIN_MENU, "Back to main menu");
menu->Add(13, "Cancel"); menu->Add(MENUITEM_CANCEL, "Cancel");
} }
mGamePhase = DUEL_STATE_MENU; mGamePhase = DUEL_STATE_MENU;
} }
@@ -577,15 +578,15 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
switch (controlId) switch (controlId)
{ {
case 12: case MENUITEM_MAIN_MENU:
menu->Close(); menu->Close();
mGamePhase = DUEL_STATE_BACK_TO_MAIN_MENU; mGamePhase = DUEL_STATE_BACK_TO_MAIN_MENU;
break; break;
case 13: case MENUITEM_CANCEL:
menu->Close(); menu->Close();
mGamePhase = DUEL_STATE_CANCEL; mGamePhase = DUEL_STATE_CANCEL;
break; break;
case 14: case MENUITEM_MULLIGAN:
//almosthumane - mulligan //almosthumane - mulligan
{ {
+12 -5
View File
@@ -5,11 +5,11 @@
#include "../include/ManaCost.h" #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; deckFile = file;
deckFileSmall = fileSmall; deckFileSmall = fileSmall;
game = deck;
game->setOwner(this);
manaPool = NEW ManaPool(this); manaPool = NEW ManaPool(this);
canPutLandsIntoPlay = 1; canPutLandsIntoPlay = 1;
nomaxhandsize = 0; nomaxhandsize = 0;
@@ -28,6 +28,12 @@ Player::Player(MTGPlayerCards * deck, string file, string fileSmall) : Damageabl
mAvatarTex = NULL; mAvatarTex = NULL;
type_as_damageable = DAMAGEABLE_PLAYER; type_as_damageable = DAMAGEABLE_PLAYER;
playMode = MODE_HUMAN; 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 */ /*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(){ Player::~Player(){
SAFE_DELETE(manaPool); SAFE_DELETE(manaPool);
SAFE_DELETE(game);
resources.Release(mAvatarTex); resources.Release(mAvatarTex);
mAvatar = NULL; mAvatar = NULL;
mAvatarTex = NULL; mAvatarTex = NULL;
@@ -83,13 +90,13 @@ Player * Player::opponent(){
return this == game->players[0] ? game->players[1] : game->players[0]; 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"); loadAvatar("avatar.jpg");
playMode = MODE_HUMAN; playMode = MODE_HUMAN;
} }
ManaPool * Player::getManaPool(){ ManaPool * Player::getManaPool(){
return manaPool; return manaPool;
} }
+11 -10
View File
@@ -164,7 +164,7 @@ void Rules::addExtraRules(){
Player * Rules::loadPlayerMomir(int isAI){ Player * Rules::loadPlayerMomir(int isAI){
string deckFileSmall = "momir"; string deckFileSmall = "momir";
char empty[] = ""; char empty[] = "";
MTGDeck * tempDeck = NEW MTGDeck(GameApp::collection); //Autogenerate a momir deck. Leave the "momir.txt" bits below for stats. 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,"Forest");
tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Plains"); 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,"Mountain");
tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Island"); tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Island");
MTGPlayerCards * deck = NEW MTGPlayerCards( tempDeck); Player *player = NULL;
delete tempDeck;
if (!isAI) // Human Player 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 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){ Player * Rules::loadPlayerRandom(int isAI, int mode){
@@ -206,13 +207,13 @@ Player * Rules::loadPlayerRandom(int isAI, int mode){
string deckFile = "random"; string deckFile = "random";
string deckFileSmall = "random"; string deckFileSmall = "random";
MTGPlayerCards * deck = NEW MTGPlayerCards(tempDeck); Player *player = NULL;
delete tempDeck;
if (!isAI) // Human Player if (!isAI) // Human Player
return NEW HumanPlayer(deck, deckFile, deckFileSmall); player = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall);
else else
return NEW AIPlayerBaka(deck,deckFile, deckFileSmall, ""); player = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, "");
return player;
} }
+2 -2
View File
@@ -274,13 +274,13 @@ void StoryDuel::init(){
sprintf(deckFile, "%s/deck.txt", folder); sprintf(deckFile, "%s/deck.txt", folder);
MTGDeck * tempDeck = NEW MTGDeck(deckFile, GameApp::collection); MTGDeck * tempDeck = NEW MTGDeck(deckFile, GameApp::collection);
sprintf(deckFileSmall, "campaign_%s", mParent->folder.c_str()); 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); SAFE_DELETE(tempDeck);
sprintf(deckFile,"%s/opponent_deck.txt", folder); sprintf(deckFile,"%s/opponent_deck.txt", folder);
tempDeck = NEW MTGDeck(deckFile, GameApp::collection); tempDeck = NEW MTGDeck(deckFile, GameApp::collection);
sprintf(deckFileSmall, "campaign_ennemy_%s_%s", mParent->folder.c_str(), pageId.c_str()); 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); SAFE_DELETE(tempDeck);
string rulesFile = folder; string rulesFile = folder;
+6 -2
View File
@@ -11,11 +11,15 @@
#include <string> #include <string>
using std::string; using std::string;
// NULL is sent in place of a MTGDeck since there is no way to create a MTGDeck without a proper deck file.
TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId):AIPlayerBaka(_suite->buildDeck(playerId),"testsuite", "testsuite","baka.jpg"){ // 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; suite = _suite;
timer = 0; timer = 0;
playMode = MODE_TEST_SUITE; playMode = MODE_TEST_SUITE;
this->deckName = "Test Suite AI";
} }