- Added a few "stats" to the main menu. This might slow down loading times on the PSP (needs testing). In that case I'll move it to the options, or optimize it if needed
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-05-19 13:45:53 +00:00
parent f32f5f3793
commit f50d7e30d4
19 changed files with 261 additions and 39 deletions
+16
View File
@@ -1,5 +1,7 @@
#include "../include/config.h"
#include "../include/DeckDataWrapper.h"
#include "../include/MTGDeck.h"
#include "../include/PriceList.h"
DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
parent = deck;
@@ -9,6 +11,7 @@ DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
for (int i = 0; i < deck->totalCards(); i++){
MTGCard * card = deck->_(i);
Add(card);
}
currentposition = 0;
currentColor = -1;
@@ -127,3 +130,16 @@ int DeckDataWrapper::getCount(int color){
if (color == -1) return colors[Constants::MTG_NB_COLORS];
return colors[color];
}
int DeckDataWrapper::totalPrice(){
int total = 0;
PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",this->parent);
map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first;
int nb = (*it).second;
if (nb) total += pricelist->getPrice(current->getMTGId());
}
delete pricelist;
return total;
}
+26
View File
@@ -39,6 +39,32 @@ int DeckStats::percentVictories(string opponentsFile){
}
}
int DeckStats::nbGames(){
int nbgames = 0;
map<string,DeckStat *>::iterator it;
for (it = stats.begin(); it != stats.end(); it++){
DeckStat * d = it->second;
nbgames+=d->nbgames;
}
return nbgames;
}
int DeckStats::percentVictories(){
int victories = 0;
int nbgames = 0;
map<string,DeckStat *>::iterator it;
for (it = stats.begin(); it != stats.end(); it++){
DeckStat * d = it->second;
nbgames+=d->nbgames;
victories+=d->victories;
}
if (nbgames){
return (victories * 100)/nbgames;
}
return 50;
}
void DeckStats::load(Player * player){
char filename[512];
sprintf(filename, RESPATH"/player/stats/%s.txt",player->deckFile.c_str());
-1
View File
@@ -193,7 +193,6 @@ void GameApp::Destroy()
SAFE_DELETE(music);
Translator::EndInstance();
SimpleMenu::destroy();
+80 -3
View File
@@ -6,7 +6,10 @@
#include "../include/GameApp.h"
#include "../include/MTGCard.h"
#include "../include/Translate.h"
#include "../include/DeckStats.h"
#include "../include/PlayerData.h"
#include "../include/utils.h"
#include "../include/DeckDataWrapper.h"
static const char* GAME_VERSION = "WTH?! 0.6.2 - by WilLoW";
#define ALPHA_WARNING 0
@@ -69,6 +72,7 @@ GameStateMenu::GameStateMenu(GameApp* parent): GameState(parent)
mVolume = 0;
splashTex = NULL;
splashQuad = NULL;
scroller = NULL;
}
GameStateMenu::~GameStateMenu() {}
@@ -118,6 +122,8 @@ void GameStateMenu::Create()
}
currentState = MENU_STATE_MAJOR_LOADING_CARDS | MENU_STATE_MINOR_NONE;
scroller = NEW TextScroller(GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT), SCREEN_WIDTH/2 - 100 , SCREEN_HEIGHT-15,200);
}
@@ -137,6 +143,7 @@ void GameStateMenu::Destroy()
SAFE_DELETE(mMovingW);
SAFE_DELETE(movingWTexture);
SAFE_DELETE(bgTexture);
SAFE_DELETE(scroller);
//SAFE_DELETE (bgMusic);
}
@@ -160,9 +167,73 @@ void GameStateMenu::Start(){
hasChosenGameType = 1;
if (GameOptions::GetInstance()->values[OPTIONS_MOMIR_MODE_UNLOCKED].getIntValue()) hasChosenGameType =0;
scrollerSet = 0;
}
void GameStateMenu::fillScroller(){
scroller->Reset();
char buffer[4096];
char buff2[512];
DeckStats * stats = DeckStats::GetInstance();
int totalGames = 0;
for (int j=1; j<6; j++){
sprintf(buffer, RESPATH"/player/stats/player_deck%i.txt",j);
if(fileExists(buffer)){
stats->load(buffer);
int percentVictories = stats->percentVictories();
sprintf(buff2, "You have a %i%% victory ratio with Deck%i",percentVictories,j);
scroller->Add(buff2);
int nbGames = stats->nbGames();
totalGames+= nbGames;
sprintf(buff2, "You have played %i games with Deck%i",nbGames,j);
scroller->Add(buff2);
}
}
if (totalGames){
sprintf(buff2, "You have played a total of %i games",totalGames);
scroller->Add(buff2);
}
GameOptions * go = GameOptions::GetInstance();
if (!go->values[OPTIONS_DIFFICULTY_MODE_UNLOCKED].getIntValue()){
scroller->Add("Unlock the difficult mode for more challenging duels!");
}
if (!go->values[OPTIONS_MOMIR_MODE_UNLOCKED].getIntValue()){
scroller->Add("Interested in playing Momir Basic? You'll have to unlock it first :)");
}
DeckDataWrapper* ddw = NEW DeckDataWrapper(NEW MTGDeck(RESPATH"/player/collection.dat", mParent->cache,mParent->collection));
int totalCards = ddw->getCount();
if (totalCards){
sprintf(buff2, "You have a total of %i cards in your collection",totalCards);
scroller->Add(buff2);
int estimatedValue = ddw->totalPrice();
sprintf(buff2, "The shopkeeper would buy your entire collection for around %i credits",estimatedValue/2);
scroller->Add(buff2);
sprintf(buff2, "The cards in your collection have an average value of %i credits",estimatedValue/totalCards);
scroller->Add(buff2);
}
delete ddw;
PlayerData * playerdata = NEW PlayerData(mParent->collection);
sprintf(buff2, "You currently have %i credits",playerdata->credits);
delete playerdata;
scroller->Add(buff2);
scroller->Add("Need more cards? Go to http://wololo.net/wagic");
scrollerSet = 1;
scroller->setRandom();
}
int GameStateMenu::nextCardSet(){
int found = 0;
if (!mDip){
@@ -245,6 +316,7 @@ void GameStateMenu::Update(float dt)
}
break;
case MENU_STATE_MAJOR_MAINMENU :
if (!scrollerSet) fillScroller();
if (mGuiController!=NULL){
mGuiController->Update(dt);
}
@@ -307,6 +379,8 @@ void GameStateMenu::Update(float dt)
angleW += angleMultiplier * dt;
yW = yW + 5*dt + (yW - 55) *5*dt;
}
scroller->Update(dt);
}
@@ -391,10 +465,13 @@ void GameStateMenu::Render()
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
mFont->SetColor(ARGB(128,255,255,255));
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,SCREEN_HEIGHT-15,JGETEXT_RIGHT);
mFont->DrawString(nbcardsStr,10, SCREEN_HEIGHT-15);
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,5,JGETEXT_RIGHT);
mFont->DrawString(nbcardsStr,10, 5);
mFont->SetScale(1.f);
mFont->SetColor(ARGB(255,255,255,255));
scroller->Render();
if (subMenuController){
subMenuController->Render();
}
+1 -28
View File
@@ -938,12 +938,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
game->addObserver(NEW AConservator(_id,card));
break;
}
/* case 1196: //Counterspell
{
Spell * starget = spell->getNextSpellTarget();
if (starget) game->mLayers->stackLayer()->Fizzle(starget);
break;
} */
case 1197: //Creature Bond
{
game->addObserver(NEW ACreatureBond(_id,card, card->target));
@@ -1593,34 +1588,12 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
}
//Addons ICE-AGE Cards
case 2650: //Pyroclasm Need to be improved copied from hurricane with does 0 dammage to player and does 2 dammage to each creature
{
int x = 2;
for (int i = 0; i < 2 ; i++){
game->mLayers->stackLayer()->addDamage(card, game->players[i], 0);// To be removed ?
for (int j = 0; j < game->players[i]->game->inPlay->nb_cards; j++){
MTGCardInstance * current = game->players[i]->game->inPlay->cards[j];
if (current->isACreature()){
game->mLayers->stackLayer()->addDamage(card, current, x);
}
}
}
break;
}
case 2660: //Word of Blasting
{
card->target->controller()->game->putInGraveyard(card->target);
card->target->controller()->life-= card->target->getManaCost()->getConvertedCost();
break;
}
case 2443: //Dark Banishing
{
if (card->target->hasColor(Constants::MTG_COLOR_BLACK)){
}else{
card->target->controller()->game->putInGraveyard(card->target);
}
break;
}
case 2593: //Thoughtleech
{
game->addObserver(NEW AGiveLifeForTappedType (_id, card, "island"));
+1
View File
@@ -257,6 +257,7 @@ int MTGAllCards::totalCards(){
return (total_cards);
}
int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
string s;
+1
View File
@@ -379,6 +379,7 @@ void MTGLibrary::shuffleTopToBottom(int nbcards){
}
}
MTGGameZone * MTGGameZone::stringToZone(string zoneName, MTGCardInstance * source,MTGCardInstance * target){
Player *p, *p2;
GameObserver * g = GameObserver::GetInstance();
+51
View File
@@ -0,0 +1,51 @@
#include "../include/TextScroller.h"
#include <JLBFont.h>
TextScroller::TextScroller(JLBFont * font, float x, float y, float width, float speed):JGuiObject(0){
mFont = font;
mWidth = width;
mSpeed = speed;
mX = x;
mY = y;
start = -width;
timer = 0;
currentId = 0;
mRandom = 0;
}
void TextScroller::setRandom(int mode){
mRandom = mode;
if (mRandom && strings.size()){
currentId = (rand() % strings.size());
mText = strings[currentId];
}
}
void TextScroller::Add(string text){
if (!strings.size()) mText = text;
strings.push_back(text);
}
void TextScroller::Reset(){
strings.clear();
}
void TextScroller::Update(float dt){
start+=mSpeed*dt;
if (start > mFont->GetStringWidth(mText.c_str())){
start = -mWidth;
if (mRandom){
currentId = (rand() % strings.size());
}else{
currentId++;
if (currentId > strings.size()-1)currentId = 0;
}
mText = strings[currentId];
}
}
void TextScroller::Render(){
mFont->DrawString(mText.c_str(),mX,mY,JGETEXT_LEFT,start,mWidth);
}