- Reward system in Story mode (currently, either credits or random set)
- Rules now accept for player 2 to start (see story mode "block" stage)
- Story mode now has an autosave/autoload mechanism. This is for convenience but also to prevent people from abusing the reward mechanism too easily.
- possibility to choose an avatar for both players through the rules (see example in story mode)
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-05-09 08:14:01 +00:00
parent 11a259d786
commit b1079942af
21 changed files with 326 additions and 53 deletions
+29 -5
View File
@@ -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<CreditBonus *>::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.
}
+2
View File
@@ -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++){
+2 -2
View File
@@ -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;
+1 -3
View File
@@ -76,9 +76,7 @@ void GameStateStory::Update(float dt) {
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
}
}
else {
flow->Update(dt);
}
flow->Update(dt);
}
}
+9 -7
View File
@@ -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;
+14 -5
View File
@@ -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");
}
+43 -4
View File
@@ -5,7 +5,19 @@
#include <string.h>
#include <stdio.h>
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<<writer;
//Story Saves
for (map<string,string>::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;
}
+19 -2
View File
@@ -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);
}
+114 -12
View File
@@ -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 <JLBFont.h>
#include <JGE.h>
#include <JFileSystem.h>
@@ -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<string,string>::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);
}
+10 -6
View File
@@ -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){