diff --git a/projects/mtg/bin/Res/campaigns/01.Where it all begins/_gfx/willow.jpg b/projects/mtg/bin/Res/campaigns/01.Where it all begins/_gfx/willow.jpg new file mode 100644 index 000000000..5c4ddcace Binary files /dev/null and b/projects/mtg/bin/Res/campaigns/01.Where it all begins/_gfx/willow.jpg differ diff --git a/projects/mtg/bin/Res/campaigns/01.Where it all begins/block/rules.txt b/projects/mtg/bin/Res/campaigns/01.Where it all begins/block/rules.txt new file mode 100644 index 000000000..41f232477 --- /dev/null +++ b/projects/mtg/bin/Res/campaigns/01.Where it all begins/block/rules.txt @@ -0,0 +1,11 @@ +[INIT] +mode=mtg +player=2 +phase=combat_attackers +[PLAYER1] +inplay:grizzly bears +life:1 +auto=@movedTo(*|graveyard): winGame controller +[PLAYER2] +inplay:raging goblin +auto=lord(goblin) mustattack \ No newline at end of file diff --git a/projects/mtg/bin/Res/campaigns/01.Where it all begins/story.xml b/projects/mtg/bin/Res/campaigns/01.Where it all begins/story.xml index 215e46794..3c285568b 100644 --- a/projects/mtg/bin/Res/campaigns/01.Where it all begins/story.xml +++ b/projects/mtg/bin/Res/campaigns/01.Where it all begins/story.xml @@ -10,7 +10,8 @@ in my life, enough to understand the basics of their craft... I want to know more -Take me back to the menu +Take me back to the menu +Continue @@ -138,13 +139,48 @@ - Block your opponent's attacking creatures during the "blockers" phase of his turn. There are lots of other phases but we'll discuss them later +Continue + + + +dialog +blocking +Now let's block! +Your opponent will attack you with one of its creatures. +When comes the "blockers" phase, I want you to click on your own creature +to block his attack +If you don't, his creature will kill you + +Continue + + + +duel +block_ok +block_try_again + + + +dialog +Oh well +Your opponent killed you +Be sure to click once on your grizzly bears when the opponent attacks you +Let's try again! + + + +dialog +Great! +You now understand the basics of the combat phase Continue End CONGRATULATIONS! -This is the end of this tutorial, -now time for you to fight some real ennemies! +This is the end of this tutorial. +Here's a 1000 credits coupon to get you started, come and visit my shop! +And I'm nice, I unlocked ${SET} for you! +Now time for you to fight some real ennemies! Click on the action button to go back to the main menu diff --git a/projects/mtg/bin/Res/campaigns/01.Where it all begins/tap_mana/rules.txt b/projects/mtg/bin/Res/campaigns/01.Where it all begins/tap_mana/rules.txt index 95dc6ce73..0dd073317 100644 --- a/projects/mtg/bin/Res/campaigns/01.Where it all begins/tap_mana/rules.txt +++ b/projects/mtg/bin/Res/campaigns/01.Where it all begins/tap_mana/rules.txt @@ -1,6 +1,7 @@ [INIT] mode=mtg [PLAYER1] +avatar:campaigns/01.Where it all begins/_gfx/willow.jpg inplay:forest auto=@tapped(land|myinplay):wingame controller auto=@next combatbegins:wingame opponent \ No newline at end of file diff --git a/projects/mtg/include/Credits.h b/projects/mtg/include/Credits.h index 0ebe1d838..efa82e2f1 100644 --- a/projects/mtg/include/Credits.h +++ b/projects/mtg/include/Credits.h @@ -29,7 +29,6 @@ private: int isMomirUnlocked(); int isEvilTwinUnlocked(); int isRandomDeckUnlocked(); - int unlockRandomSet(); public: int value; Player * p1, *p2; @@ -44,6 +43,8 @@ public: ~Credits(); void compute(Player * _p1, Player * _p2, GameApp * _app); void Render(); + static int unlockRandomSet(bool force = false); + static int addCreditBonus(int value); }; #endif diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index 80437f4bf..0b277b2eb 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -30,10 +30,10 @@ class GameObserver{ queue eventsQueue; int nbPlayers; - int currentPlayerId; int untap(MTGCardInstance * card); public: + int currentPlayerId; CombatStep combatStep; int turn; int forceShuffleLibraries(); diff --git a/projects/mtg/include/PhaseRing.h b/projects/mtg/include/PhaseRing.h index f4697ffe4..2e63b6ef0 100644 --- a/projects/mtg/include/PhaseRing.h +++ b/projects/mtg/include/PhaseRing.h @@ -26,8 +26,8 @@ private: list ring; list::iterator current; Phase * getCurrentPhase(); - Phase * forward(); - Phase * goToPhase(int id, Player * player); + Phase * forward(bool sendEvents = true); + Phase * goToPhase(int id, Player * player,bool sendEvents = true); PhaseRing(Player* players[], int nbPlayers=2); ~PhaseRing(); int addPhase(Phase * phase); diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index 8b535a851..76b91a001 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -40,6 +40,7 @@ class Player: public Damageable{ virtual int receiveEvent(WEvent * event){return 0;}; virtual void Render(){}; + void loadAvatar(string file); }; class HumanPlayer: public Player{ diff --git a/projects/mtg/include/PlayerData.h b/projects/mtg/include/PlayerData.h index 6721fc3a8..71605bb2a 100644 --- a/projects/mtg/include/PlayerData.h +++ b/projects/mtg/include/PlayerData.h @@ -6,10 +6,13 @@ class PlayerData{ protected: + void init(); public: int credits; + mapstorySaves; MTGDeck * collection; TaskList * taskList; + PlayerData(); //This doesn't init the collection, do not use it to manipulate the player's collection PlayerData(MTGAllCards * allcards); ~PlayerData(); int save(); diff --git a/projects/mtg/include/Rules.h b/projects/mtg/include/Rules.h index 5811f77fb..9efa81004 100644 --- a/projects/mtg/include/Rules.h +++ b/projects/mtg/include/Rules.h @@ -25,6 +25,7 @@ class RulesPlayerData{ public: vector extraRules; int life; + string avatar; ManaCost * manapool; RulesPlayerZone zones[5]; RulesPlayerData(); @@ -36,6 +37,7 @@ class RulesPlayerData{ class RulesState{ public: int phase; + int player; void parsePlayerState(int playerId, string s); RulesState(); RulesPlayerData playerData[2]; diff --git a/projects/mtg/include/StoryFlow.h b/projects/mtg/include/StoryFlow.h index 1285540e8..1c39b3625 100644 --- a/projects/mtg/include/StoryFlow.h +++ b/projects/mtg/include/StoryFlow.h @@ -45,6 +45,25 @@ StoryImage(string img, float mX, float mY); float getHeight(); }; +class StoryReward:public StoryText { +public: + enum { + STORY_REWARD_CREDITS, + STORY_REWARD_SET + }; + + int rewardDone; + string value; + int type; + + StoryReward(string _type, string _value, string text, float _mX, float _mY, string align = "center", int font = 0, int id = 0); + void Update(float dt); + void Render(); + + static bool rewardSoundPlayed; + static bool rewardsEnabled; +}; + class StoryChoice:public StoryText { public: string pageId; @@ -110,6 +129,7 @@ private: mappages; bool parse(string filename); StoryPage * loadPage(TiXmlElement* element); + bool _gotoPage(string id); public: string currentPageId; string folder; @@ -117,6 +137,7 @@ public: ~StoryFlow(); bool gotoPage(string id); + bool loadPageId(string id); void Update(float dt); void Render(); }; diff --git a/projects/mtg/src/Credits.cpp b/projects/mtg/src/Credits.cpp index 4003d4ace..74b526c29 100644 --- a/projects/mtg/src/Credits.cpp +++ b/projects/mtg/src/Credits.cpp @@ -40,7 +40,7 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){ p1 = _p1; p2 = _p2; app = _app; - showMsg = (WRand() % 5); + showMsg = (WRand() % 3); GameObserver * g = GameObserver::GetInstance(); if (!g->turn) return; PlayerData * playerdata = NEW PlayerData(app->collection); @@ -126,18 +126,17 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){ }else if((unlocked = unlockRandomSet())) { unlockedTex = resources.RetrieveTexture("set_unlocked.png"); unlockedQuad = resources.RetrieveQuad("set_unlocked.png", 2, 2, 396, 96); - goa = (GameOptionAward*) &options[Options::optionSet(unlocked - 1)]; - goa->giveAward(); - options.save(); MTGSetInfo * si = setlist.getInfo(unlocked - 1); if(si) unlockedString = si->getName(); //Show the set's pretty name for unlocks. } + if (unlocked && options[Options::SFXVOLUME].number > 0){ JSample * sample = resources.RetrieveSample("bonus.wav"); if (sample){ JSoundSystem::GetInstance()->PlaySample(sample); } } + } vector::iterator it; @@ -283,11 +282,36 @@ int Credits::isRandomDeckUnlocked(){ return 0; } -int Credits::unlockRandomSet(){ +int Credits::addCreditBonus(int value){ + PlayerData * playerdata = NEW PlayerData(); + playerdata->credits += value; + playerdata->save(); + SAFE_DELETE(playerdata); + return value; +} + +int Credits::unlockRandomSet(bool force){ int setId = WRand() % setlist.size(); + if (force) { + int init = setId; + boolean found = false; + do { + if (1 != options[Options::optionSet(setId)].number) + found = true; + else { + setId++; + if (setId == setlist.size()) + setId = 0; + } + } while (setId != init && !found); + } + if (1 == options[Options::optionSet(setId)].number) return 0; + GameOptionAward* goa = (GameOptionAward*) &options[Options::optionSet(setId)]; + goa->giveAward(); + options.save(); return setId + 1; //We add 1 here to show success/failure. Be sure to subtract later. } diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index cd898f96e..540b16492 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -193,12 +193,14 @@ void GameObserver::startGame(Rules * rules){ mLayers = NEW DuelLayers(); mLayers->init(); + currentPlayerId = 0; currentPlayer = players[0]; currentActionPlayer = currentPlayer; phaseRing = NEW PhaseRing(players,nbPlayers); if (rules) rules->initGame(); + //Preload images from hand if (!players[0]->isAI()){ for (int i=0; i< players[0]->game->hand->nb_cards; i++){ diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index 7ecb37efa..41eee9188 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -12,9 +12,9 @@ static const char* GAME_VERSION = "WTH?! 0.11.1 - by wololo"; -#define DEFAULT_ANGLE_MULTIPLIER 0.4 +#define DEFAULT_ANGLE_MULTIPLIER 0.4f #define MAX_ANGLE_MULTIPLIER (3*M_PI) -#define MIN_ANGLE_MULTIPLIER 0.4 +#define MIN_ANGLE_MULTIPLIER 0.4f static const double STEP_ANGLE_MULTIPLIER = 0.0002; diff --git a/projects/mtg/src/GameStateStory.cpp b/projects/mtg/src/GameStateStory.cpp index 18c9a6b47..ae3f90063 100644 --- a/projects/mtg/src/GameStateStory.cpp +++ b/projects/mtg/src/GameStateStory.cpp @@ -76,9 +76,7 @@ void GameStateStory::Update(float dt) { mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); } } - else { - flow->Update(dt); - } + flow->Update(dt); } } diff --git a/projects/mtg/src/PhaseRing.cpp b/projects/mtg/src/PhaseRing.cpp index 53af810b3..695a20905 100644 --- a/projects/mtg/src/PhaseRing.cpp +++ b/projects/mtg/src/PhaseRing.cpp @@ -73,30 +73,32 @@ Phase * PhaseRing::getCurrentPhase(){ return *current; } -Phase * PhaseRing::forward(){ +Phase * PhaseRing::forward(bool sendEvents){ Phase * cPhaseOld = *current; if (current != ring.end()) current++; if (current == ring.end()) current = ring.begin(); - //Warn the layers about the phase Change - WEvent * e = NEW WEventPhaseChange(cPhaseOld, *current); - GameObserver::GetInstance()->receiveEvent(e); - //delete e; + if (sendEvents) { + //Warn the layers about the phase Change + WEvent * e = NEW WEventPhaseChange(cPhaseOld, *current); + GameObserver::GetInstance()->receiveEvent(e); + } return *current; } -Phase * PhaseRing::goToPhase(int id, Player * player){ +Phase * PhaseRing::goToPhase(int id, Player * player, bool sendEvents){ Phase * currentPhase = *current; while(currentPhase->id !=id || currentPhase->player != player){ //Dangerous, risk for inifinte loop ! #ifdef WIN32 OutputDebugString("goto"); #endif - currentPhase = forward(); + currentPhase = forward(sendEvents); } return currentPhase; } + int PhaseRing::addPhase(Phase * phase){ ring.push_back(phase); return 1; diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index 403db4fb1..4c7d7aed3 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -29,6 +29,19 @@ Player::~Player(){ mAvatarTex = NULL; } +void Player::loadAvatar(string file){ + if (mAvatarTex) { + resources.Release(mAvatarTex); + mAvatar = NULL; + mAvatarTex = NULL; + } + mAvatarTex = resources.RetrieveTexture(file,RETRIEVE_LOCK,TEXTURE_SUB_AVATAR); + if (mAvatarTex) + mAvatar = resources.RetrieveQuad(file,0,0,35,50,"playerAvatar",RETRIEVE_NORMAL,TEXTURE_SUB_AVATAR); + else + mAvatar = NULL; +} + const string Player::getDisplayName() const { GameObserver * g = GameObserver::GetInstance(); if (this == g->players[0]) return "Player 1"; @@ -58,11 +71,7 @@ Player * Player::opponent(){ } HumanPlayer::HumanPlayer(MTGPlayerCards * deck, string file, string fileSmall) : Player(deck, file, fileSmall) { - mAvatarTex = resources.RetrieveTexture("avatar.jpg",RETRIEVE_LOCK,TEXTURE_SUB_AVATAR); - if (mAvatarTex) - mAvatar = resources.RetrieveQuad("avatar.jpg",0,0,35,50,"playerAvatar",RETRIEVE_NORMAL,TEXTURE_SUB_AVATAR); - else - mAvatar = NULL; + loadAvatar("avatar.jpg"); } diff --git a/projects/mtg/src/PlayerData.cpp b/projects/mtg/src/PlayerData.cpp index 02ec36bc0..e4415bed5 100644 --- a/projects/mtg/src/PlayerData.cpp +++ b/projects/mtg/src/PlayerData.cpp @@ -5,7 +5,19 @@ #include #include +PlayerData::PlayerData(){ + init(); +} PlayerData::PlayerData(MTGAllCards * allcards){ + init(); + + //COLLECTION + if (allcards) collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards); +} + +void PlayerData::init() { + collection = NULL; + //CREDITS credits = 3000; //Default value @@ -17,23 +29,50 @@ PlayerData::PlayerData(MTGAllCards * allcards){ }else{ //TODO error management } + + //Story Saves + while(std::getline(file,s)){ + if (!s.size()) + continue; + if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files + if (s.size() && s[0] == '#') + continue; + size_t i = s.find_first_of("="); + if (i == string::npos) + continue; + + string key = s.substr(0,i); + string value = s.substr(i+1); + if (key.size() < 3) + continue; + + if(key[0] != 's') + continue; + key = key.substr(2); + storySaves[key]=value; + } file.close(); } - //COLLECTION - collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards); taskList = NEW TaskList(options.profileFile(PLAYER_TASKS).c_str()); } int PlayerData::save(){ std::ofstream file(options.profileFile(PLAYER_SAVEFILE).c_str()); - char writer[64]; + char writer[512]; if (file){ sprintf(writer,"%i\n", credits); file<::iterator it =storySaves.begin(); it !=storySaves.end(); ++it){ + sprintf(writer,"s %s=%s\n", it->first.c_str(),it->second.c_str()); + file << writer; + } + file.close(); } - collection->save(); + if (collection) collection->save(); taskList->save(); return 1; } diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index fb5f63b2c..10886f73b 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -40,6 +40,7 @@ MTGCardInstance * Rules::getCardByMTGId(int mtgid){ RulesPlayerData::RulesPlayerData(){ life = 20; manapool = NEW ManaCost(); + avatar = ""; } RulesPlayerData::~RulesPlayerData(){ @@ -55,7 +56,7 @@ void RulesPlayerZone::add(int cardId){ RulesState::RulesState(){ phase = Constants::MTG_PHASE_FIRSTMAIN; - + player = 0; } void RulesState::parsePlayerState(int playerId, string s){ @@ -76,6 +77,9 @@ void RulesState::parsePlayerState(int playerId, string s){ }else if(areaS.compare("life") == 0){ playerData[playerId].life = atoi((s.substr(limiter+1)).c_str()); return; + }else if(areaS.compare("avatar") == 0){ + playerData[playerId].avatar = s.substr(limiter+1); + return; }else if(areaS.compare("manapool") == 0){ SAFE_DELETE(playerData[playerId].manapool); playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter+1)); @@ -256,12 +260,23 @@ void Rules::initGame(){ //Put the GameObserver in the initial state GameObserver * g = GameObserver::GetInstance(); OutputDebugString("RULES Init Game\n"); - g->phaseRing->goToPhase(initState.phase, g->players[0]); + + //Set the current player/phase + g->currentPlayer = g->players[initState.player]; + g->currentActionPlayer = g->currentPlayer; + g->currentPlayerId = initState.player; + g->phaseRing->goToPhase(0, g->currentPlayer, false); + g->phaseRing->goToPhase(initState.phase, g->currentPlayer); g->currentGamePhase = initState.phase; + + for (int i = 0; i < 2; i++){ Player * p = g->players[i]; p->life = initState.playerData[i].life; p->getManaPool()->copy(initState.playerData[i].manapool); + if (initState.playerData[i].avatar.size()) { + p->loadAvatar(initState.playerData[i].avatar); + } MTGGameZone * playerZones[] = {p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay}; for (int j = 0; j < 4; j++){ MTGGameZone * zone = playerZones[j]; @@ -371,6 +386,8 @@ int Rules::load(string _filename){ extraRules.push_back(s.substr(5)); }else if (s.find("mode=") == 0) { gamemode = strToGameMode(s.substr(5)); + }else if (s.find("player=") == 0) { + initState.player = atoi(s.substr(7).c_str())-1; }else{ initState.phase = PhaseRing::phaseStrToInt(s); } diff --git a/projects/mtg/src/StoryFlow.cpp b/projects/mtg/src/StoryFlow.cpp index d1ae365ce..7c995adc0 100644 --- a/projects/mtg/src/StoryFlow.cpp +++ b/projects/mtg/src/StoryFlow.cpp @@ -4,6 +4,8 @@ #include "../include/WResourceManager.h" #include "../include/AIPlayer.h" #include "../include/Rules.h" +#include "../include/Credits.h" +#include "../include/PlayerData.h" #include #include #include @@ -14,6 +16,8 @@ float StoryDialog::currentY = 2; float StoryDialog::previousY = 2; +bool StoryReward::rewardSoundPlayed = false; +bool StoryReward::rewardsEnabled = true; StoryDialogElement::StoryDialogElement(float x, float y, int id): JGuiObject(id), mX(x),mY(y) { } @@ -49,6 +53,70 @@ float StoryText::getHeight() { //Nothing for now } + + StoryReward::StoryReward(string _type, string _value, string text, float _mX, float _mY, string _align, int _font, int id):StoryText(text,_mX,_mY, _align, _font, id) { + type = STORY_REWARD_CREDITS; + if (_type.compare("unlockset") == 0) { + type = STORY_REWARD_SET; + } + value = _value; + rewardDone = 0; + +} + +void StoryReward::Render(){ + if (rewardDone <=0) + return; + StoryText::Render(); +} + +void StoryReward::Update(float dt){ + if (rewardDone) + return; + + int result = 0; + + switch (type){ + case STORY_REWARD_CREDITS: + result = Credits::addCreditBonus(atoi(value.c_str())); + break; + case STORY_REWARD_SET: + { + result = Credits::unlockRandomSet(true); + MTGSetInfo * si = setlist.getInfo(result - 1); + if(si) { + string unlockedString = si->getName(); + size_t pos = text.find("${SET}"); + if (pos != string::npos) { + text.replace(pos,pos + 6,unlockedString); + } + } + break; + } + default: + break; + } + + if (!result) { + rewardDone = -1; + return; + } + + if (!rewardsEnabled) { + rewardDone = -1; + return; + } + + if (!rewardSoundPlayed && options[Options::SFXVOLUME].number > 0){ + JSample * sample = resources.RetrieveSample("bonus.wav"); + if (sample){ + JSoundSystem::GetInstance()->PlaySample(sample); + } + rewardSoundPlayed = 1; + } + rewardDone = 1; + } + ostream& StoryText::toString(ostream& out) const { return out << "StoryText ::: text : " << text; @@ -90,15 +158,6 @@ StoryPage::StoryPage(StoryFlow * mParent):mParent(mParent){ } - -StoryFlow::StoryFlow(string folder): folder(folder){ - string path = "campaigns/"; - path.append(folder).append("/story.xml"); - parse(path); -} - - - void StoryChoice::Render() { JLBFont * mFont = resources.GetJLBFont(font); @@ -182,7 +241,7 @@ void StoryDuel::init(){ players[0] = NEW HumanPlayer(NEW MTGPlayerCards(tempDeck),deckFile,deckFileSmall); SAFE_DELETE(tempDeck); - sprintf(deckFile,"%s/ennemy_deck.txt", folder); + 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"); @@ -293,6 +352,10 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent):StoryPage(mPar StoryChoice * sc = NEW StoryChoice(id,text,i,x, y , align, font, (i==0)); graphics.push_back(sc); Add(sc); + }else if (strcmp(element->Value(), "reward")==0){ + string type = safeAttribute(element,"type"); + string value = safeAttribute(element,"value"); + graphics.push_back(NEW StoryReward(type, value, text,x,y,align, font)); }else { //Error } @@ -330,7 +393,7 @@ void StoryDialog::Render() { previousY = currentY; for (size_t i = 0; i < graphics.size(); ++i){ StoryDialogElement * elmt = (StoryDialogElement *)(graphics[i]); - if (elmt == mObjects[0]) + if (mCount && elmt == mObjects[0]) currentY += SPACE_BEFORE_CHOICES; RenderElement(elmt); } @@ -348,6 +411,14 @@ StoryDialog::~StoryDialog(){ } } + +StoryFlow::StoryFlow(string folder): folder(folder){ + string path = "campaigns/"; + path.append(folder).append("/story.xml"); + parse(path); +} + + StoryPage * StoryFlow::loadPage(TiXmlElement* element){ TiXmlNode* typeNode = element->FirstChild("type"); if (!typeNode) return NULL; @@ -361,12 +432,28 @@ StoryPage * StoryFlow::loadPage(TiXmlElement* element){ return result; } + + // -bool StoryFlow::gotoPage(string id){ +bool StoryFlow::_gotoPage(string id){ + StoryReward::rewardSoundPlayed = false; + if (pages.find(id) == pages.end()) { + return false; + } currentPageId = id; return true; } +bool StoryFlow::gotoPage(string id){ + StoryReward::rewardsEnabled = true; + return _gotoPage(id); +} + +bool StoryFlow::loadPageId(string id) { + StoryReward::rewardsEnabled = false; + return _gotoPage(id); +} + bool StoryFlow::parse(string path) { JFileSystem *fileSystem = JFileSystem::GetInstance(); @@ -399,6 +486,15 @@ bool StoryFlow::parse(string path) } } + //autoLoad + PlayerData * pd = NEW PlayerData(); + map::iterator it = pd->storySaves.find(folder); + if (it!=pd->storySaves.end()) { + if (it->second.compare("End") !=0) + loadPageId(it->second); + } + SAFE_DELETE(pd); + return true; } @@ -417,4 +513,10 @@ StoryFlow::~StoryFlow(){ SAFE_DELETE(i->second); } pages.clear(); + + //autoSave progress + PlayerData * pd = NEW PlayerData(); + pd->storySaves[folder] = currentPageId; + pd->save(); + SAFE_DELETE(pd); } diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index 9d6ca120e..61a173c6d 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -586,13 +586,17 @@ string WResourceManager::avatarFile(const string filename){ return buf; //Failure. Check graphics - char graphdir[512]; - sprintf(graphdir,"graphics/%s",filename.c_str()); - if(fileOK(graphdir,true)) - return graphdir; - + sprintf(buf,"graphics/%s",filename.c_str()); + if(fileOK(buf,true)) + return buf; + + //Failure. Check raw faile. + sprintf(buf,"%s",filename.c_str()); + if(fileOK(buf,true)) + return buf; + //Complete abject failure. Probably a crash... - return graphdir; + return ""; } string WResourceManager::cardFile(const string filename){