after much testing and corrections, our user Holgern from the forums has completely recreated and reworked the gauntlet mode originally coded for ai vs ai into a completely new way to play wagic, you can choose the number of matchs, various modes, and other wonderful additions. Don't take my word for it, try all the fun new stuff out yourself!

THANK YOU Holgern!
This commit is contained in:
omegablast2002@yahoo.com
2013-03-26 02:10:45 +00:00
parent c994886ca8
commit 810c3967d6
5 changed files with 2767 additions and 43 deletions

View File

@@ -48,6 +48,13 @@ private:
int IsMoreAIDecksUnlocked(DeckStats * stats);
string unlockedTextureName;
JQuadPtr GetUnlockedQuad(string texturename);
bool mTournament;
bool mMatch;
bool mPlayerWin;
int mGamesWon;
int mGamesPlayed;
int mMatchesWon;
int mMatchesPlayed;
public:
int value;
Player * p1, *p2;
@@ -60,6 +67,7 @@ public:
Credits();
~Credits();
void compute(GameObserver* observer, GameApp * _app);
void computeTournament(GameObserver* g, GameApp * _app,bool tournament,bool match, bool playerWin,int gamesWon,int gamesPlayed,int matchesWon,int matchesPlayed);
void Render();
static int unlockRandomSet(bool force = false);
static int unlockSetByName(string name);

View File

@@ -13,6 +13,7 @@
#define CHOOSE_OPPONENT 7
#define NMB_PLAYERS 2 // Number of players in the game. Currently that's always 2.
#ifdef TESTSUITE
class TestSuite;
@@ -22,6 +23,156 @@ class Credits;
class JNetwork;
#endif
/////// Tournament Mod ///////////
#define PLAYER_TOURNAMENT "tournament.dat"
#define AI_TOURNAMENT "/ai/baka/tournament.dat"
#define AI_RESULTS_FILE "/ai/baka/ai_test.csv"
class TDeck{
public:
TDeck(int deck,PlayerType deckType,int victories = 0,int lastWin = 0, int wonMatches=0, int playedMatches=0, int wonGames=0, int playedGames=0);
TDeck();
~TDeck();
int getDeckNumber(){return mDeckNumber;}
void setDeckNumber(int deck){mDeckNumber=deck;}
void setDeckType(PlayerType ptype){mDeckType=ptype;}
PlayerType getDeckType(){return mDeckType;}
bool isAI(){return mDeckType==PLAYER_TYPE_CPU;}
void reset();
void increaseDeckNumber();
void winGame(){mVictories++;mLastWin++;mGamesPlayed++;mWonGames++;}
void winMatch(){mWonMatches++;mMatchesPlayed++;}
void setMatchesWon(int w){mWonMatches=w;}
int getMatchesWon(){return mWonMatches;}
void looseGame(){mLastWin = 0;mGamesPlayed++;}
void looseMatch(){mMatchesPlayed++;}
void drawMatch(){mMatchesPlayed++;}
int getLastWin(){return mLastWin;}
int getVictories(){return mVictories;}
void newMatch(){mVictories=0;mLastWin=0;}
void deleteStats(){mVictories=0;mLastWin=0;mWonMatches=0;mMatchesPlayed=0;mWonGames=0;mGamesPlayed=0;mRanking=0;}
void resetTournament(){mWonMatches=0;}
void setVictories(int v){mVictories=v;}
void setLastWin(int lastWin){mLastWin=lastWin;}
int getGamesPlayed(){return mGamesPlayed;}
void setGamesPlayed(int games){mGamesPlayed=games;}
int getGamesWon(){return mWonGames;}
void setGamesWon(int games){mWonGames=games;}
int getMatchesPlayed(){return mMatchesPlayed;}
void setMatchesPlayed(int matches){mMatchesPlayed=matches;}
void setRanking(int ranking){mRanking=ranking;}
int getRanking(){return mRanking;}
std::string getDeckName();
private:
int mDeckNumber;
PlayerType mDeckType;
int mVictories;
int mLastWin;
int mWonMatches;
int mMatchesPlayed;
int mWonGames;
int mGamesPlayed;
int mRanking;
int mDifficulty;
};
class Tournament{
public:
Tournament();
~Tournament();
void addDeck(int player,int deck,PlayerType deckType);
void addDeck(int player,TDeck newDeck);
int getDeckNumber(int player){return Deck[player].getDeckNumber();}
PlayerType getDeckType(int player){return Deck[player].getDeckType();}
unsigned int getAvailableDecks(){return nmbDecks;}
void setAvailableDecks(unsigned int a){nmbDecks=a;}
void setGamesToPlay(int games){mNbGames=games;}
int getGamesToPlay(){return mNbGames;}
void setMatchType(int gamestoplay,int matchMode,bool swapPlayer=false){mNbGames=gamestoplay;mMatchMode=matchMode;mCompetition=swapPlayer;}
void setMatchMode(int m){mMatchMode=m;}
int getMatchMode(){return mMatchMode;}
int getTournamentMode(){return mTournamentMode;}
bool isGauntlet();
bool isEndlessDemo();
bool isTournament(){return mTournamentMode>0;}
void setTournamentMode(int b){mTournamentMode=b;}
bool getFastTimerMode(){return mFastTimerMode;}
void setFastTimerMode(bool timerMode){mFastTimerMode=timerMode;}
void updateScoreTable(Player * _p0, Player * _p1, int gt = GAME_TYPE_CLASSIC, bool gameEnd=false);
void renderScoreTable();
bool gameFinished(bool,bool);
bool isMatchFinished(){return endOfMatch;}
bool isNextDeckFound(){return nextDeckFound;}
void swapPlayer();
void revertSwapPlayer();
void Start(); //may change the gamephase
void End();
void saveMatchResults();
bool updateTournament();
void save(bool isAI);
bool load(bool isAI, bool loadComplete);
void setOpLevel(int o){mOpLevel=o;}
int getOpLevel(){return mOpLevel;}
void initTournament();
void resetTournamentSelection(); //resets the choosen oppent decks
std::string exportTournamentDescription();
unsigned int getNumberofTournamentDecks(){return TournamentsDecks.size();}
void enableTournamantMode(int tournamentMode, int player = 0);
bool wasScoreDisplayed(){return scoreDisplayed;}
void setScoreDisplayed(bool s){scoreDisplayed=s;}
bool didHumanWin();
int gamesPlayedbyHuman();
int gamesWonbyHuman();
int matchesPlayedbyHuman();
int matchesWonbyHuman();
void calculateRanking();
void initTournamentResults();
void setRankedDeck(int rank,TDeck deck){if (rank<11&&rank>0)sortedTournamentDecks[rank-1]=deck;}
bool checkTournamentFile(bool isAI);
void leaveOutAIvsAIMatches();
void updateScoreforTournament();
int getHardRandomDeck();
int getRandomDeck(bool noEasyDecks);
int remainingDecksToNextStage();
private:
bool mCompetition;
bool mPlayerSwaped;
int mSpeed;
int mNbGames;
int mMatchMode;
int mGamesPlayed;
unsigned int TournamentsDecksID[NMB_PLAYERS];
int gauntletLastDeckNumber[NMB_PLAYERS];
TDeck Deck[NMB_PLAYERS];
std::vector<TDeck> TournamentsDecks;
int mOpLevel;
unsigned int nmbDecks; // number of decks in the last constructed deckmenu
bool mFastTimerMode;
int mTournamentMode;
bool endOfMatch;
bool nextDeckFound;
bool looserDecks; //double KO
// variables for scoretable
bool scoreDisplayed;
JQuadPtr p0Quad;
JQuadPtr p1Quad;
int mgameType;
TDeck sortedTournamentDecks[10];
int mVictories0;
int mVictories1;
bool p0IsAI;
bool p1IsAI;
bool scoreFinal;
bool tournamentFinal;
int scoreMatchesToPlay;
int scoreMatchesPlayed;
};
/////// End Tournament Mod ///////////
class GameStateDuel: public GameState, public JGuiListener
{
private:
@@ -38,6 +189,13 @@ private:
SimplePopup * popupScreen; // used for informational screens, modal
static int selectedPlayerDeckId;
static int selectedAIDeckId;
/////// Tournament Mod ///////////
//std::ofstream ai_file;
SimpleMenu * cnogmenu; // to choose the number of games to play in the match
void setAISpeed();
Tournament* tournament;
bool tournamentSelection;
/////// End Tournament Mod ///////////
bool premadeDeck;
int OpponentsDeckid;
@@ -48,6 +206,7 @@ private:
void initScroller();
void setGamePhase(int newGamePhase);
public:
GameStateDuel(GameApp* parent);
virtual ~GameStateDuel();
@@ -105,6 +264,20 @@ public:
MENUITEM_REMOTE_CLIENT = -18,
MENUITEM_REMOTE_SERVER = -19,
#endif
/////// Tournament Mod ///////////
MENUITEM_SHOW_SCORE = -20,
MENUITEM_SPEED_FAST = -21,
MENUITEM_SPEED_NORMAL = -22,
MENUITEM_GAUNTLET = -23,
MENUITEM_KO_TOURNAMENT = -24,
MENUITEM_RR_TOURNAMENT = -25,
MENUITEM_START_TOURNAMENT = -26,
MENUITEM_ENDLESSDEMO = -27,
MENUITEM_RANDOM_AI_HARD = -28,
MENUITEM_DOUBLEKO_TOURNAMENT = -29,
MENUITEM_FILL_NEXT_STAGE_HARD = -30,
MENUITEM_FILL_NEXT_STAGE = -31,
/////// End Tournament Mod ///////////
MENUITEM_MORE_INFO = kInfoMenuID
};

View File

@@ -243,6 +243,8 @@ AIPlayer * AIPlayerFactory::createAIPlayer(GameObserver *observer, MTGAllCards *
AIPlayerBaka * baka = NEW AIPlayerBaka(observer, deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting));
baka->deckId = deckid;
baka->comboHint = NULL;
if (baka->opponent() && baka->opponent()->isHuman())
baka->setFastTimerMode(false);
return baka;
}

View File

@@ -148,6 +148,13 @@ Credits::Credits()
p1 = NULL;
p2 = NULL;
observer = NULL;
mTournament=false;
mMatch=false;
mPlayerWin=false;
mGamesWon=0;
mGamesPlayed=0;
mMatchesWon=0;
mMatchesPlayed=0;
}
Credits::~Credits()
@@ -327,6 +334,156 @@ void Credits::compute(GameObserver* g, GameApp * _app)
SAFE_DELETE(playerdata);
}
/////// Tournament Mod ///////////
void Credits::computeTournament(GameObserver* g, GameApp * _app,bool tournament,bool match,bool playerWin,int gamesWon,int gamesPlayed,int matchesWon,int matchesPlayed)
{
mTournament=tournament;
mMatch=match;
mPlayerWin=playerWin;
mGamesWon=gamesWon;
mGamesPlayed=gamesPlayed;
mMatchesWon=matchesWon;
mMatchesPlayed=matchesPlayed;
if (!g->turn)
return;
p1 = g->players[0];
p2 = g->players[1];
observer = g;
app = _app;
showMsg = (WRand() % 3);
//no credits when the AI plays :)
if (p1->isAI())
return;
PlayerData * playerdata = NEW PlayerData(MTGCollection());
if (p2->isAI() && mPlayerWin)
{
value = 400;
if (app->gameType != GAME_TYPE_CLASSIC)
value = 200;
int difficulty = options[Options::DIFFICULTY].number;
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number && difficulty)
{
CreditBonus * b = NEW CreditBonus(100 * mGamesWon * difficulty, _("Difficulty Bonus"));
bonus.push_back(b);
}
if (mGamesWon>1)
{
CreditBonus * b = NEW CreditBonus(mGamesWon * 200, _("Won Game Bonus"));
bonus.push_back(b);
}
if (mMatchesWon>1)
{
CreditBonus * b = NEW CreditBonus(mMatchesWon * 200, _("Won Matches Bonus"));
bonus.push_back(b);
}
if ((mGamesWon==mGamesPlayed && mGamesPlayed>0) || (matchesWon==mMatchesPlayed && mMatchesPlayed>0))
{
CreditBonus * b = NEW CreditBonus(500, _("Perfect Bonus"));
bonus.push_back(b);
}
if (mGamesWon>mGamesPlayed*0.80 && mGamesWon<mGamesPlayed)
{
CreditBonus * b = NEW CreditBonus(250, _("Won more then 80 percentage of games"));
bonus.push_back(b);
}
GameOptionAward * goa = NULL;
// <Tasks handling>
// </Tasks handling>
if (unlocked == -1)
{
DeckStats * stats = DeckStats::GetInstance();
stats->load(p1->GetCurrentDeckStatsFile());
unlocked = isDifficultyUnlocked(stats);
if (unlocked)
{
unlockedTextureName = "unlocked.png";
goa = (GameOptionAward*) &options[Options::DIFFICULTY_MODE_UNLOCKED];
goa->giveAward();
}
else
{
for (map<string, Unlockable *>::iterator it = Unlockable::unlockables.begin(); it != Unlockable::unlockables.end(); ++it) {
Unlockable * award = it->second;
if (award->tryToUnlock(g))
{
unlocked = 1;
unlockedString = award->getValue("unlock_text");
unlockedTextureName = award->getValue("unlock_img");
break;
}
}
}
if (!unlocked)
{
// EvilTwin and RandomDeck cannot be unlocked in tournamentmode
// for each won game, one change to unlock a set
for (int i=0;i<mGamesWon;i++){
if (!unlocked)
unlocked = unlockRandomSet();
}
if (unlocked)
{
unlockedTextureName = "set_unlocked.png";
MTGSetInfo * si = setlist.getInfo(unlocked - 1);
if (si)
unlockedString = si->getName(); //Show the set's pretty name for unlocks.
}
}
if (!unlocked)
{
if ((unlocked = IsMoreAIDecksUnlocked(stats)))
{
options[Options::AIDECKS_UNLOCKED].number += 10;
options.save();
unlockedTextureName = "ai_unlocked.png";
}
}
if (unlocked && options[Options::SFXVOLUME].number > 0)
{
WResourceManager::Instance()->PlaySample("bonus.wav");
}
}
vector<CreditBonus *>::iterator it;
if (bonus.size())
{
CreditBonus * b = NEW CreditBonus(value, _("Victory"));
bonus.insert(bonus.begin(), b);
for (it = bonus.begin() + 1; it < bonus.end(); ++it)
value += (*it)->value;
}
playerdata->credits += value;
PriceList::updateKey();
playerdata->taskList->passOneDay();
if (playerdata->taskList->getTaskCount() < 6)
{
playerdata->taskList->addRandomTask();
playerdata->taskList->addRandomTask();
}
}
else
{
unlocked = 0;
playerdata->taskList->passOneDay();
}
playerdata->save();
SAFE_DELETE(playerdata);
}
/////// END Tournament Mod ///////////
JQuadPtr Credits::GetUnlockedQuad(string textureName)
{
if (!textureName.size()) return JQuadPtr();
@@ -367,7 +524,7 @@ void Credits::Render()
{
if (!p1->isAI() && p2->isAI())
{
if (observer->didWin(p1))
if (observer->didWin(p1) || mPlayerWin)
{
sprintf(buffer, _("Congratulations! You earn %i credits").c_str(), value);
JQuadPtr unlockedQuad = GetUnlockedQuad(unlockedTextureName);
@@ -412,7 +569,39 @@ void Credits::Render()
y += 15;
//!!
if (observer->didWin(p1) && this->gameLength != 0)
if (mMatch){
if (mGamesPlayed>0){
sprintf(buffer, _("Games Won: %i of %i (%i %%)").c_str(), mGamesWon,mGamesPlayed, (int)(mGamesWon*100/mGamesPlayed));
f->DrawString(buffer, 10, y);
y += 10;
}
if (value>0 && mGamesPlayed>0){
sprintf(buffer, _("Credits per game: %i").c_str(), (int) (value / mGamesPlayed));
f->DrawString(buffer, 10, y);
y += 10;
}
showMsg = 0;
} else if (mTournament){
if (mGamesPlayed>0){
sprintf(buffer, _("Games Won: %i of %i (%i %%)").c_str(),mGamesWon, mGamesPlayed,(int)(mGamesWon*100/mGamesPlayed));
f->DrawString(buffer, 10, y);
y += 10;
}
if (mMatchesPlayed>0){
sprintf(buffer, _("Matches Won: %i of %i (%i %%)").c_str(),mMatchesWon, mMatchesPlayed,(int)(mMatchesWon*100/mMatchesPlayed));
f->DrawString(buffer, 10, y);
y += 10;
}
if (value>0 && mGamesPlayed>0){
sprintf(buffer, _("Credits per game: %i").c_str(), (int) (value / mGamesPlayed));
f->DrawString(buffer, 10, y);
y += 10;
}
showMsg = 0;
}
else if (observer->didWin(p1) && this->gameLength != 0)
{
sprintf(buffer, _("Game length: %i turns (%i seconds)").c_str(), observer->turn, this->gameLength);
f->DrawString(buffer, 10, y);

File diff suppressed because it is too large Load Diff