Erwan
- bug fix in JGE++ audio (improve HBL compatibility) - Added new rewards in story mode: random card, card (either by "name" or id), specific set - Story mode: added possibility to choose music, and bg for duel. -- See "01. Where it all begins" for examples of new features
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "../include/MTGDeck.h"
|
||||
#include "../include/GameObserver.h"
|
||||
#include "../include/GameStateShop.h"
|
||||
#include "../include/PlayerData.h"
|
||||
|
||||
CreditBonus::CreditBonus(int _value, string _text){
|
||||
value = _value;
|
||||
@@ -289,6 +290,37 @@ int Credits::addCreditBonus(int value){
|
||||
SAFE_DELETE(playerdata);
|
||||
return value;
|
||||
}
|
||||
/*
|
||||
* adds a Card to a deck
|
||||
* @param cardId id of the card
|
||||
* @param collection deck representing player's collection
|
||||
*/
|
||||
int Credits::addCardToCollection(int cardId, MTGDeck * collection) {
|
||||
return collection->add(cardId);
|
||||
}
|
||||
|
||||
/*
|
||||
* adds a Card to player's collection
|
||||
* prefer to call the above function if you want to add several cards, since saving is expensive
|
||||
*/
|
||||
int Credits::addCardToCollection(int cardId) {
|
||||
MTGAllCards * ac = GameApp::collection;
|
||||
PlayerData * playerdata = NEW PlayerData(ac);
|
||||
int result = addCardToCollection(cardId, playerdata->collection);
|
||||
playerdata->collection->save();
|
||||
return result;
|
||||
}
|
||||
|
||||
int Credits::unlockSetByName(string name){
|
||||
int setId = setlist.findSet(name);
|
||||
if (setId < 0) 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.
|
||||
|
||||
}
|
||||
|
||||
int Credits::unlockRandomSet(bool force){
|
||||
int setId = WRand() % setlist.size();
|
||||
|
||||
@@ -254,7 +254,8 @@ void GameApp::Destroy()
|
||||
SAFE_DELETE(Subtypes::subtypesList);
|
||||
SAFE_DELETE(DeckMetaDataList::decksMetaData);
|
||||
|
||||
SAFE_DELETE(music);
|
||||
playMusic("none");
|
||||
|
||||
Translator::EndInstance();
|
||||
WCFilterFactory::Destroy();
|
||||
SimpleMenu::destroy();
|
||||
@@ -426,3 +427,15 @@ void GameApp::DoTransition(int trans, int tostate, float dur, bool animonly){
|
||||
void GameApp::DoAnimation(int trans, float dur){
|
||||
DoTransition(trans,GAME_STATE_NONE,dur,true);
|
||||
}
|
||||
|
||||
void GameApp::playMusic(string filename, bool loop) {
|
||||
if (music) {
|
||||
JSoundSystem::GetInstance()->StopMusic(music);
|
||||
SAFE_DELETE(music);
|
||||
}
|
||||
|
||||
if (HasMusic && options[Options::MUSICVOLUME].number > 0){
|
||||
music = resources.ssLoadMusic(filename.c_str());
|
||||
if (music) JSoundSystem::GetInstance()->PlayMusic(music, loop);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ GameObserver::GameObserver(Player * _players[], int _nb_players){
|
||||
phaseRing = NULL;
|
||||
replacementEffects = NEW ReplacementEffects();
|
||||
combatStep = BLOCKERS;
|
||||
mRules = NULL;
|
||||
}
|
||||
|
||||
int GameObserver::getCurrentGamePhase(){
|
||||
@@ -187,6 +188,7 @@ int GameObserver::forceShuffleLibraries(){
|
||||
|
||||
void GameObserver::startGame(Rules * rules){
|
||||
turn = 0;
|
||||
mRules = rules;
|
||||
if (rules)
|
||||
rules->initPlayers();
|
||||
|
||||
@@ -200,6 +202,7 @@ void GameObserver::startGame(Rules * rules){
|
||||
if (rules)
|
||||
rules->initGame();
|
||||
|
||||
|
||||
|
||||
//Preload images from hand
|
||||
if (!players[0]->isAI()){
|
||||
|
||||
@@ -168,16 +168,7 @@ void GameStateDeckViewer::Start()
|
||||
//init welcome menu
|
||||
updateDecks();
|
||||
|
||||
if (GameApp::HasMusic && options[Options::MUSICVOLUME].number > 0){
|
||||
if (GameApp::music){
|
||||
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
||||
SAFE_DELETE(GameApp::music);
|
||||
}
|
||||
GameApp::music = resources.ssLoadMusic("track1.mp3");
|
||||
if (GameApp::music){
|
||||
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
|
||||
}
|
||||
}
|
||||
GameApp::playMusic("track1.mp3");
|
||||
|
||||
loadIndexes();
|
||||
mEngine->ResetInput();
|
||||
@@ -188,10 +179,7 @@ void GameStateDeckViewer::Start()
|
||||
void GameStateDeckViewer::End()
|
||||
{
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
if (GameApp::music){
|
||||
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
||||
SAFE_DELETE(GameApp::music);
|
||||
}
|
||||
|
||||
SAFE_DELETE(welcome_menu);
|
||||
SAFE_DELETE(menu);
|
||||
SAFE_DELETE(subMenu);
|
||||
|
||||
@@ -173,11 +173,7 @@ void GameStateDuel::End()
|
||||
OutputDebugString("Ending GamestateDuel\n");
|
||||
#endif
|
||||
SAFE_DELETE(deckmenu);
|
||||
//stop game music
|
||||
if (GameApp::music){
|
||||
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
||||
SAFE_DELETE(GameApp::music);
|
||||
}
|
||||
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
if (mPlayers[0] && mPlayers[1]) mPlayers[0]->End();
|
||||
GameObserver::EndInstance();
|
||||
@@ -304,13 +300,8 @@ void GameStateDuel::Update(float dt)
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR){
|
||||
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
|
||||
}
|
||||
//stop menu music
|
||||
if (GameApp::music){
|
||||
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
||||
SAFE_DELETE(GameApp::music);
|
||||
}
|
||||
|
||||
//start of in game music code
|
||||
if (GameApp::HasMusic && options[Options::MUSICVOLUME].number > 0){
|
||||
musictrack = "";
|
||||
//check opponent id and choose the music track based on it
|
||||
if(OpponentsDeckid) {
|
||||
@@ -328,12 +319,7 @@ void GameStateDuel::Update(float dt)
|
||||
if(!MusicExist(musictrack))
|
||||
musictrack = "ai_baka_music.mp3";
|
||||
|
||||
if (MusicExist(musictrack)){
|
||||
GameApp::music = resources.ssLoadMusic(musictrack.c_str());
|
||||
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
|
||||
}
|
||||
}
|
||||
//end of music code
|
||||
GameApp::playMusic(musictrack);
|
||||
}
|
||||
game->Update(dt);
|
||||
if (game->gameOver){
|
||||
|
||||
@@ -135,15 +135,7 @@ void GameStateMenu::Start(){
|
||||
subMenuController = NULL;
|
||||
SAFE_DELETE(mGuiController);
|
||||
|
||||
if (GameApp::HasMusic && !GameApp::music && options[Options::MUSICVOLUME].number > 0){
|
||||
GameApp::music = resources.ssLoadMusic("Track0.mp3");
|
||||
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
|
||||
}
|
||||
|
||||
if (GameApp::HasMusic && GameApp::music && options[Options::MUSICVOLUME].number == 0){
|
||||
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
||||
SAFE_DELETE(GameApp::music);
|
||||
}
|
||||
GameApp::playMusic("Track0.mp3");
|
||||
|
||||
hasChosenGameType = 0;
|
||||
mParent->gameType = GAME_TYPE_CLASSIC;
|
||||
|
||||
@@ -53,6 +53,7 @@ GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {
|
||||
|
||||
GameStateShop::~GameStateShop() {
|
||||
End();
|
||||
|
||||
}
|
||||
|
||||
void GameStateShop::Create(){
|
||||
@@ -74,7 +75,7 @@ void GameStateShop::Start(){
|
||||
bigSync = 0;
|
||||
shopMenu = NEW WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP, true, &bigSync);
|
||||
MTGAllCards * ac = GameApp::collection;
|
||||
playerdata = NEW PlayerData(ac);;
|
||||
playerdata = NEW PlayerData(ac);
|
||||
myCollection = NEW DeckDataWrapper(playerdata->collection);
|
||||
pricelist = NEW PriceList(RESPATH"/settings/prices.dat",ac);
|
||||
for(int i=0;i<SHOP_SLOTS;i++){
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "../include/config.h"
|
||||
#include "../include/GameApp.h"
|
||||
#include "../include/GuiBackground.h"
|
||||
#include "../include/GameObserver.h"
|
||||
#include "../include/Rules.h"
|
||||
|
||||
GuiBackground::GuiBackground()
|
||||
{
|
||||
@@ -13,5 +15,14 @@ GuiBackground::~GuiBackground()
|
||||
void GuiBackground::Render()
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
renderer->RenderQuad(resources.RetrieveTempQuad("backdrop.jpg"), 0, 18);
|
||||
JQuad * quad = NULL;
|
||||
GameObserver * go = GameObserver::GetInstance();
|
||||
if (go && go->mRules && go->mRules->bg.size()) {
|
||||
quad = resources.RetrieveTempQuad(go->mRules->bg);
|
||||
}
|
||||
if (!quad) {
|
||||
quad = resources.RetrieveTempQuad("backdrop.jpg");
|
||||
}
|
||||
if (!quad) return;
|
||||
renderer->RenderQuad(quad, 0, 18);
|
||||
}
|
||||
|
||||
@@ -426,6 +426,12 @@ MTGCard * MTGAllCards::_(int index){
|
||||
MTGCard * MTGAllCards::getCardByName(string name){
|
||||
if (!name.size()) return NULL;
|
||||
if (name[0] == '#') return NULL;
|
||||
|
||||
int cardnb = atoi(name.c_str());
|
||||
if (cardnb){
|
||||
return getCardById(cardnb);
|
||||
}
|
||||
|
||||
std::transform(name.begin(), name.end(), name.begin(),::tolower );
|
||||
int setId = -1;
|
||||
size_t found = name.find(" (");
|
||||
|
||||
@@ -330,9 +330,9 @@ void Rules::cleanup(){
|
||||
initState.cleanup();
|
||||
}
|
||||
|
||||
Rules::Rules(string filename){
|
||||
Rules::Rules(string filename, string _bg){
|
||||
bg = _bg;
|
||||
load(filename);
|
||||
|
||||
}
|
||||
|
||||
int Rules::load(string _filename){
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "../include/Rules.h"
|
||||
#include "../include/Credits.h"
|
||||
#include "../include/PlayerData.h"
|
||||
#include "../include/MTGDeck.h"
|
||||
#include <JLBFont.h>
|
||||
#include <JGE.h>
|
||||
#include <JFileSystem.h>
|
||||
@@ -18,6 +19,7 @@ float StoryDialog::currentY = 2;
|
||||
float StoryDialog::previousY = 2;
|
||||
bool StoryReward::rewardSoundPlayed = false;
|
||||
bool StoryReward::rewardsEnabled = true;
|
||||
MTGDeck * StoryReward::collection = NULL;
|
||||
|
||||
StoryDialogElement::StoryDialogElement(float x, float y, int id): JGuiObject(id), mX(x),mY(y) {
|
||||
}
|
||||
@@ -58,6 +60,8 @@ float StoryText::getHeight() {
|
||||
type = STORY_REWARD_CREDITS;
|
||||
if (_type.compare("unlockset") == 0) {
|
||||
type = STORY_REWARD_SET;
|
||||
} else if (_type.compare("card") == 0) {
|
||||
type = STORY_REWARD_CARD;
|
||||
}
|
||||
value = _value;
|
||||
rewardDone = 0;
|
||||
@@ -82,7 +86,12 @@ void StoryReward::Update(float dt){
|
||||
break;
|
||||
case STORY_REWARD_SET:
|
||||
{
|
||||
result = Credits::unlockRandomSet(true);
|
||||
if (value.size()) {
|
||||
result = Credits::unlockSetByName(value);
|
||||
} else {
|
||||
result = Credits::unlockRandomSet(true);
|
||||
}
|
||||
if (!result) break;
|
||||
MTGSetInfo * si = setlist.getInfo(result - 1);
|
||||
if(si) {
|
||||
string unlockedString = si->getName();
|
||||
@@ -93,6 +102,33 @@ void StoryReward::Update(float dt){
|
||||
}
|
||||
break;
|
||||
}
|
||||
case STORY_REWARD_CARD:
|
||||
{
|
||||
int cardId = 0;
|
||||
MTGCard * card = NULL;
|
||||
if (value.size()) {
|
||||
card = GameApp::collection->getCardByName(value);
|
||||
if (card) {
|
||||
cardId = card->getId();
|
||||
}
|
||||
} else {
|
||||
cardId = GameApp::collection->randomCardId();
|
||||
card = GameApp::collection->getCardById(cardId);
|
||||
}
|
||||
|
||||
if (!cardId) break;
|
||||
|
||||
if (!collection) {
|
||||
collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), GameApp::collection);
|
||||
}
|
||||
|
||||
result = Credits::addCardToCollection(cardId, collection);
|
||||
size_t pos = text.find("${CARD}");
|
||||
if (pos != string::npos && card) {
|
||||
text.replace(pos,pos + 7,card->data->getName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -228,7 +264,7 @@ StoryChoice::StoryChoice(string pageId, string text, int JGOid, float mX, float
|
||||
if(hasFocus) mTargetScale = 1.2f;
|
||||
}
|
||||
|
||||
//Actually loads "game"
|
||||
//Actually loads a duel
|
||||
void StoryDuel::init(){
|
||||
Player * players[2];
|
||||
|
||||
@@ -249,7 +285,7 @@ void StoryDuel::init(){
|
||||
|
||||
string rulesFile = folder;
|
||||
rulesFile.append("/rules.txt");
|
||||
rules = NEW Rules(rulesFile);
|
||||
rules = NEW Rules(rulesFile, bg);
|
||||
|
||||
GameObserver::Init(players, 2);
|
||||
game = GameObserver::GetInstance();
|
||||
@@ -263,15 +299,18 @@ StoryDuel::StoryDuel(TiXmlElement* root,StoryFlow * mParent): StoryPage(mParent)
|
||||
for (TiXmlNode* node = root->FirstChild(); node; node = node->NextSibling()) {
|
||||
TiXmlElement* element = node->ToElement();
|
||||
if (element) {
|
||||
if (strcmp(element->Value(), "onwin")==0) {
|
||||
const char* textC = element->GetText();
|
||||
const char* textC = element->GetText();
|
||||
if (strcmp(element->Value(), "onwin")==0) {
|
||||
onWin = textC;
|
||||
}
|
||||
else if (strcmp(element->Value(), "onlose")==0) {
|
||||
const char* textC = element->GetText();
|
||||
onLose = textC;
|
||||
}else {
|
||||
//Error
|
||||
} else if (strcmp(element->Value(), "bg")==0) {
|
||||
string text = textC;
|
||||
bg = string("campaigns/").append(mParent->folder).append("/").append(text);
|
||||
if (!fileExists(bg.c_str())) bg = text;
|
||||
} else {
|
||||
StoryPage::loadElement(element); //Father
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,7 +338,7 @@ void StoryDuel::Render(){
|
||||
game->Render();
|
||||
}
|
||||
|
||||
string StoryDialog::safeAttribute(TiXmlElement* element, string attribute) {
|
||||
string StoryPage::safeAttribute(TiXmlElement* element, string attribute) {
|
||||
string s;
|
||||
if (element->Attribute(attribute.c_str())){
|
||||
s = element->Attribute(attribute.c_str());
|
||||
@@ -307,6 +346,18 @@ string StoryDialog::safeAttribute(TiXmlElement* element, string attribute) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int StoryPage::loadElement(TiXmlElement* element) {
|
||||
if (!element) return 0;
|
||||
const char* textC = element->GetText();
|
||||
string text = textC;
|
||||
if (strcmp(element->Value(), "music")==0) {
|
||||
musicFile = string("campaigns/").append(mParent->folder).append("/").append(text);
|
||||
if (!fileExists(musicFile.c_str()))
|
||||
musicFile = text;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent):StoryPage(mParent), JGuiListener(), JGuiController(1,NULL) {
|
||||
|
||||
@@ -357,7 +408,7 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent):StoryPage(mPar
|
||||
string value = safeAttribute(element,"value");
|
||||
graphics.push_back(NEW StoryReward(type, value, text,x,y,align, font));
|
||||
}else {
|
||||
//Error
|
||||
StoryPage::loadElement(element); //Father
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,6 +421,11 @@ void StoryDialog::Update(float dt){
|
||||
graphics[i]->Update(dt);
|
||||
}
|
||||
|
||||
if (StoryReward::collection) {
|
||||
StoryReward::collection->save();
|
||||
SAFE_DELETE(StoryReward::collection);
|
||||
}
|
||||
|
||||
JButton key = mEngine->ReadButton();
|
||||
CheckUserInput(key);
|
||||
|
||||
@@ -441,6 +497,9 @@ bool StoryFlow::_gotoPage(string id){
|
||||
return false;
|
||||
}
|
||||
currentPageId = id;
|
||||
if (pages[currentPageId]->musicFile.size()) {
|
||||
GameApp::playMusic(pages[currentPageId]->musicFile);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -476,9 +535,15 @@ bool StoryFlow::parse(string path)
|
||||
if (element != NULL) {
|
||||
if (strcmp(element->Value(), "page")==0) {
|
||||
string id = element->Attribute("id");
|
||||
|
||||
OutputDebugString("\nparsing ");
|
||||
OutputDebugString(id.c_str());
|
||||
OutputDebugString("...\n");
|
||||
|
||||
StoryPage * sp = loadPage(element);
|
||||
pages[id] = sp;
|
||||
if (!currentPageId.size()) gotoPage(id);
|
||||
OutputDebugString("OK\n");
|
||||
}
|
||||
else {
|
||||
//Error
|
||||
|
||||
@@ -700,9 +700,15 @@ string WResourceManager::musicFile(const string filename){
|
||||
sprintf(defdir,"sound/%s",filename.c_str());
|
||||
if(fileOK(defdir,true))
|
||||
return defdir;
|
||||
|
||||
|
||||
//Failure. Check raw faile.
|
||||
sprintf(defdir,"%s",filename.c_str());
|
||||
if(fileOK(defdir,true))
|
||||
return defdir;
|
||||
|
||||
|
||||
//Complete abject failure. Probably a crash...
|
||||
return defdir;
|
||||
return "";
|
||||
}
|
||||
|
||||
string WResourceManager::sfxFile(const string filename){
|
||||
@@ -826,7 +832,9 @@ void WResourceManager::autoResize(){
|
||||
}
|
||||
|
||||
JMusic * WResourceManager::ssLoadMusic(const char *fileName){
|
||||
return JSoundSystem::GetInstance()->LoadMusic(musicFile(fileName).c_str());
|
||||
string file = musicFile(fileName);
|
||||
if (!file.size()) return NULL;
|
||||
return JSoundSystem::GetInstance()->LoadMusic(file.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user