reformatting code according to guidelines defined at
http://wololo.net/forum/viewtopic.php?f=35&t=2235&start=10
This commit is contained in:
@@ -6,34 +6,42 @@
|
||||
#include "AIStats.h"
|
||||
#include "AllAbilities.h"
|
||||
|
||||
|
||||
MTGAbility * AIMomirPlayer::momirAbility = NULL;
|
||||
|
||||
AIMomirPlayer::AIMomirPlayer(MTGDeck * deck, string file, string fileSmall, string avatarFile) : AIPlayerBaka(deck, file, fileSmall, avatarFile) {
|
||||
AIMomirPlayer::AIMomirPlayer(MTGDeck * deck, string file, string fileSmall, string avatarFile) :
|
||||
AIPlayerBaka(deck, file, fileSmall, avatarFile)
|
||||
{
|
||||
momirAbility = NULL;
|
||||
agressivity = 100;
|
||||
}
|
||||
|
||||
int AIMomirPlayer::getEfficiency(AIAction * action){
|
||||
int AIMomirPlayer::getEfficiency(AIAction * action)
|
||||
{
|
||||
MTGAbility * ability = action->ability;
|
||||
if (ability->cost && !(ability->cost->isExtraPaymentSet())) return 0; //Does not handle abilities with sacrifice yet
|
||||
if (ability->cost && !(ability->cost->isExtraPaymentSet()))
|
||||
return 0; //Does not handle abilities with sacrifice yet
|
||||
int efficiency = AIPlayerBaka::getEfficiency(action);
|
||||
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (g->getCurrentGamePhase() < Constants::MTG_PHASE_FIRSTMAIN) return 0;
|
||||
if (g->getCurrentGamePhase() < Constants::MTG_PHASE_FIRSTMAIN)
|
||||
return 0;
|
||||
return efficiency;
|
||||
}
|
||||
|
||||
MTGAbility * AIMomirPlayer::getMomirAbility(){
|
||||
if (momirAbility) return momirAbility;
|
||||
MTGAbility * AIMomirPlayer::getMomirAbility()
|
||||
{
|
||||
if (momirAbility)
|
||||
return momirAbility;
|
||||
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
momirAbility = g->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR);
|
||||
return momirAbility;
|
||||
}
|
||||
|
||||
int AIMomirPlayer::momir(){
|
||||
if (!game->hand->nb_cards) return 0; //nothing to discard :/
|
||||
int AIMomirPlayer::momir()
|
||||
{
|
||||
if (!game->hand->nb_cards)
|
||||
return 0; //nothing to discard :/
|
||||
int result = 0;
|
||||
int opponentCreatures = getCreaturesInfo(opponent(), INFO_NBCREATURES);
|
||||
int myCreatures = getCreaturesInfo(this, INFO_NBCREATURES );
|
||||
@@ -42,19 +50,25 @@ int AIMomirPlayer::momir(){
|
||||
SAFE_DELETE(potentialMana);
|
||||
int efficiency = 100;
|
||||
int chance = 1 + (WRand() % 100);
|
||||
if (converted == 5 && myCreatures > opponentCreatures && game->hand->nb_cards<4) efficiency = 5 ; //Strategy: skip 5 drop
|
||||
if (converted == 7 && myCreatures > opponentCreatures && game->hand->nb_cards<2) efficiency = 50; //Strategy: 7 drops have bad upkeep costs and the AI doesn't handle those right now...
|
||||
if (converted > 8 ) converted = 8;
|
||||
if (converted == 8) efficiency = 100 - (myCreatures-opponentCreatures);
|
||||
if (converted == 5 && myCreatures > opponentCreatures && game->hand->nb_cards < 4)
|
||||
efficiency = 5; //Strategy: skip 5 drop
|
||||
if (converted == 7 && myCreatures > opponentCreatures && game->hand->nb_cards < 2)
|
||||
efficiency = 50; //Strategy: 7 drops have bad upkeep costs and the AI doesn't handle those right now...
|
||||
if (converted > 8)
|
||||
converted = 8;
|
||||
if (converted == 8)
|
||||
efficiency = 100 - (myCreatures - opponentCreatures);
|
||||
|
||||
if (efficiency >= chance){
|
||||
int _cost[] = {Constants::MTG_COLOR_ARTIFACT,converted};
|
||||
if (efficiency >= chance)
|
||||
{
|
||||
int _cost[] = { Constants::MTG_COLOR_ARTIFACT, converted };
|
||||
ManaCost * cost = NEW ManaCost(_cost);
|
||||
MTGAbility * ability = getMomirAbility();
|
||||
MTGCardInstance * card = game->hand->cards[0];
|
||||
if (ability->isReactingToClick(card,cost)){
|
||||
if (ability->isReactingToClick(card, cost))
|
||||
{
|
||||
tapLandsForMana(cost);
|
||||
AIAction * a = NEW AIAction(ability,card);
|
||||
AIAction * a = NEW AIAction(ability, card);
|
||||
clickstream.push(a);
|
||||
result = 1;
|
||||
}
|
||||
@@ -63,41 +77,49 @@ int AIMomirPlayer::momir(){
|
||||
return result;
|
||||
}
|
||||
|
||||
int AIMomirPlayer::computeActions(){
|
||||
//Part of the strategy goes here. When should we put a land into play ?
|
||||
/*
|
||||
Another gift from Alex Majlaton on my first day playing Momir, and it has served me well ever since. It goes a little something like this: (a) if you are on the play, hit your Two through Four, skip your Five, and then hit all the way to Eight; (b) if you are on the draw and your opponent skips his One, you make Two through Eight; (c) if you are on the draw and your opponent hits a One, you match him drop-for-drop for the rest of the game.
|
||||
int AIMomirPlayer::computeActions()
|
||||
{
|
||||
//Part of the strategy goes here. When should we put a land into play ?
|
||||
/*
|
||||
Another gift from Alex Majlaton on my first day playing Momir, and it has served me well ever since. It goes a little something like this: (a) if you are on the play, hit your Two through Four, skip your Five, and then hit all the way to Eight; (b) if you are on the draw and your opponent skips his One, you make Two through Eight; (c) if you are on the draw and your opponent hits a One, you match him drop-for-drop for the rest of the game.
|
||||
|
||||
You skip your Five on the play because it is the weakest drop. There are plenty of serviceable guys there, but very few bombs compared to other drops
|
||||
the general rule is this: if you want to get to Eight, you have to skip two drops on the play and one drop on the draw.
|
||||
*/
|
||||
You skip your Five on the play because it is the weakest drop. There are plenty of serviceable guys there, but very few bombs compared to other drops
|
||||
the general rule is this: if you want to get to Eight, you have to skip two drops on the play and one drop on the draw.
|
||||
*/
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
Player * p = g->currentPlayer;
|
||||
if (!(g->currentlyActing() == this)) return 0;
|
||||
if (chooseTarget()) return 1;
|
||||
if (!(g->currentlyActing() == this))
|
||||
return 0;
|
||||
if (chooseTarget())
|
||||
return 1;
|
||||
int currentGamePhase = g->getCurrentGamePhase();
|
||||
if (g->isInterrupting == this){ // interrupting
|
||||
if (g->isInterrupting == this)
|
||||
{ // interrupting
|
||||
selectAbility();
|
||||
return 1;
|
||||
}else if (p == this && g->mLayers->stackLayer()->count(0,NOT_RESOLVED) == 0){ //standard actions
|
||||
}
|
||||
else if (p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0)
|
||||
{ //standard actions
|
||||
CardDescriptor cd;
|
||||
MTGCardInstance * card = NULL;
|
||||
|
||||
|
||||
switch(currentGamePhase){
|
||||
switch (currentGamePhase)
|
||||
{
|
||||
case Constants::MTG_PHASE_FIRSTMAIN:
|
||||
{
|
||||
ManaCost * potentialMana = getPotentialMana();
|
||||
int converted = potentialMana->getConvertedCost();
|
||||
SAFE_DELETE(potentialMana);
|
||||
if (canPutLandsIntoPlay && ( converted <8 || game->hand->nb_cards > 1) ){
|
||||
if (canPutLandsIntoPlay && (converted < 8 || game->hand->nb_cards > 1))
|
||||
{
|
||||
//Attempt to put land into play
|
||||
cd.init();
|
||||
cd.setColor(Constants::MTG_COLOR_LAND);
|
||||
card = cd.match(game->hand);
|
||||
if (card){
|
||||
if (card)
|
||||
{
|
||||
MTGAbility * putIntoPlay = g->mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY);
|
||||
AIAction * a = NEW AIAction(putIntoPlay,card); //TODO putinplay action
|
||||
AIAction * a = NEW AIAction(putIntoPlay, card); //TODO putinplay action
|
||||
clickstream.push(a);
|
||||
return 1;
|
||||
}
|
||||
@@ -118,4 +140,3 @@ the general rule is this: if you want to get to Eight, you have to skip two drop
|
||||
return AIPlayerBaka::computeActions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+550
-321
File diff suppressed because it is too large
Load Diff
+102
-59
@@ -7,75 +7,94 @@
|
||||
#include "WEvent.h"
|
||||
#include "AllAbilities.h"
|
||||
//TODO:better comments this is too cryptic to work on by anyone but original coder.
|
||||
bool compare_aistats(AIStat * first, AIStat * second){
|
||||
float damage1 = static_cast<float>(first->value / first->occurences);
|
||||
float damage2 = static_cast<float>(second->value / second->occurences);
|
||||
bool compare_aistats(AIStat * first, AIStat * second)
|
||||
{
|
||||
float damage1 = static_cast<float> (first->value / first->occurences);
|
||||
float damage2 = static_cast<float> (second->value / second->occurences);
|
||||
return (damage1 > damage2);
|
||||
}
|
||||
|
||||
AIStats::AIStats(Player * _player, char * _filename){
|
||||
AIStats::AIStats(Player * _player, char * _filename)
|
||||
{
|
||||
filename = _filename;
|
||||
load(_filename);
|
||||
player = _player;
|
||||
}
|
||||
|
||||
AIStats::~AIStats(){
|
||||
AIStats::~AIStats()
|
||||
{
|
||||
list<AIStat *>::iterator it;
|
||||
for ( it=stats.begin() ; it != stats.end(); it++ ){
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
AIStat * stat = *it;
|
||||
delete stat;
|
||||
}
|
||||
}
|
||||
|
||||
void AIStats::updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier){
|
||||
void AIStats::updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier)
|
||||
{
|
||||
MTGCard * card = cardInstance->model;
|
||||
AIStat * stat = find(card);
|
||||
if (!stat){
|
||||
stat = NEW AIStat(card->getMTGId(),0,1,0);
|
||||
if (!stat)
|
||||
{
|
||||
stat = NEW AIStat(card->getMTGId(), 0, 1, 0);
|
||||
stats.push_back(stat);
|
||||
}
|
||||
if (damage->target == player){
|
||||
stat->value+= multiplier * STATS_PLAYER_MULTIPLIER * damage->damage;
|
||||
}else if (damage->target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){
|
||||
MTGCardInstance * target = (MTGCardInstance *)damage->target;
|
||||
if (target->controller() == player && !target->isInPlay()){
|
||||
if (damage->target == player)
|
||||
{
|
||||
stat->value += multiplier * STATS_PLAYER_MULTIPLIER * damage->damage;
|
||||
}
|
||||
else if (damage->target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
||||
{
|
||||
MTGCardInstance * target = (MTGCardInstance *) damage->target;
|
||||
if (target->controller() == player && !target->isInPlay())
|
||||
{
|
||||
//One of my creatures got lethal damage...
|
||||
stat->value+= multiplier * STATS_CREATURE_MULTIPLIER * damage->damage;
|
||||
stat->value += multiplier * STATS_CREATURE_MULTIPLIER * damage->damage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int AIStats::receiveEvent(WEvent * event){
|
||||
WEventDamage * e = dynamic_cast<WEventDamage *>(event);
|
||||
if (!e) return 0; //we take only Damage events into accountright now
|
||||
int AIStats::receiveEvent(WEvent * event)
|
||||
{
|
||||
WEventDamage * e = dynamic_cast<WEventDamage *> (event);
|
||||
if (!e)
|
||||
return 0; //we take only Damage events into accountright now
|
||||
Damage * damage = e->damage;
|
||||
MTGGameZone * opponentZone = player->opponent()->game->inPlay;
|
||||
|
||||
MTGCardInstance * card = damage->source;
|
||||
updateStatsCard(card,damage);
|
||||
updateStatsCard(card, damage);
|
||||
|
||||
//Auras on damage source can be the cause
|
||||
for (int i = 0; i < opponentZone->nb_cards; ++i){
|
||||
for (int i = 0; i < opponentZone->nb_cards; ++i)
|
||||
{
|
||||
MTGCardInstance * aura = opponentZone->cards[i];
|
||||
if (aura->target == card){
|
||||
updateStatsCard(aura,damage, STATS_AURA_MULTIPLIER);
|
||||
if (aura->target == card)
|
||||
{
|
||||
updateStatsCard(aura, damage, STATS_AURA_MULTIPLIER);
|
||||
}
|
||||
}
|
||||
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
//Lords
|
||||
map<MTGCardInstance *, int> lords;
|
||||
for (int i = 1; i < g->mLayers->actionLayer()->mCount; i++){ //0 is not a mtgability...hackish
|
||||
MTGAbility * a = ((MTGAbility *)g->mLayers->actionLayer()->mObjects[i]);
|
||||
if (ALord * al = dynamic_cast<ALord*>(a)) {
|
||||
if (al->cards.find(card)!= al->cards.end() && opponentZone->hasCard(al->source)){
|
||||
for (int i = 1; i < g->mLayers->actionLayer()->mCount; i++)
|
||||
{ //0 is not a mtgability...hackish
|
||||
MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]);
|
||||
if (ALord * al = dynamic_cast<ALord*>(a))
|
||||
{
|
||||
if (al->cards.find(card) != al->cards.end() && opponentZone->hasCard(al->source))
|
||||
{
|
||||
lords[al->source] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (size_t nb = lords.size()){
|
||||
for (map<MTGCardInstance *, int>::iterator it = lords.begin();it !=lords.end();++it){
|
||||
updateStatsCard(it->first,damage, STATS_LORD_MULTIPLIER/nb);
|
||||
if (size_t nb = lords.size())
|
||||
{
|
||||
for (map<MTGCardInstance *, int>::iterator it = lords.begin(); it != lords.end(); ++it)
|
||||
{
|
||||
updateStatsCard(it->first, damage, STATS_LORD_MULTIPLIER / nb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,17 +102,23 @@ int AIStats::receiveEvent(WEvent * event){
|
||||
return 1; //is this meant to return 0 or 1?
|
||||
}
|
||||
//TODO:what does this do?
|
||||
bool AIStats::isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue ){
|
||||
if (stats.size()<max) return tooSmallCountsForTrue;
|
||||
bool AIStats::isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue)
|
||||
{
|
||||
if (stats.size() < max)
|
||||
return tooSmallCountsForTrue;
|
||||
unsigned int n = 0;
|
||||
MTGCard * source = card->model;
|
||||
int id = source->getMTGId();
|
||||
list<AIStat *>::iterator it;
|
||||
for ( it=stats.begin() ; it != stats.end(); it++ ){
|
||||
if (n >= max) return false;
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
if (n >= max)
|
||||
return false;
|
||||
AIStat * stat = *it;
|
||||
if (stat->source == id){
|
||||
if ((stat->value + card->DangerRanking()) >=3) return true;
|
||||
if (stat->source == id)
|
||||
{
|
||||
if ((stat->value + card->DangerRanking()) >= 3)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
n++;
|
||||
@@ -101,45 +126,57 @@ bool AIStats::isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCou
|
||||
return false;
|
||||
}
|
||||
|
||||
AIStat * AIStats::find(MTGCard * source){
|
||||
AIStat * AIStats::find(MTGCard * source)
|
||||
{
|
||||
int id = source->getMTGId();
|
||||
list<AIStat *>::iterator it;
|
||||
for ( it=stats.begin() ; it != stats.end(); it++ ){
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
AIStat * stat = *it;
|
||||
if (stat->source == id) return stat;
|
||||
if (stat->source == id)
|
||||
return stat;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void AIStats::load(char * filename){
|
||||
void AIStats::load(char * filename)
|
||||
{
|
||||
std::ifstream file(filename);
|
||||
std::string s;
|
||||
|
||||
if(file){
|
||||
while(std::getline(file,s)){
|
||||
if (file)
|
||||
{
|
||||
while (std::getline(file, s))
|
||||
{
|
||||
int cardid = atoi(s.c_str());
|
||||
std::getline(file,s);
|
||||
std::getline(file, s);
|
||||
int value = atoi(s.c_str());
|
||||
std::getline(file,s);
|
||||
std::getline(file, s);
|
||||
int direct = atoi(s.c_str());
|
||||
AIStat * stat = NEW AIStat(cardid,value,1,direct);
|
||||
AIStat * stat = NEW AIStat(cardid, value, 1, direct);
|
||||
stats.push_back(stat);
|
||||
}
|
||||
file.close();
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO Error management
|
||||
}
|
||||
}
|
||||
void AIStats::save(){
|
||||
void AIStats::save()
|
||||
{
|
||||
std::ofstream file(filename.c_str());
|
||||
char writer[128];
|
||||
if (file){
|
||||
if (file)
|
||||
{
|
||||
list<AIStat *>::iterator it;
|
||||
for ( it=stats.begin() ; it != stats.end(); it++ ){
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
AIStat * stat = *it;
|
||||
if (stat->value > 0){
|
||||
sprintf(writer,"%i\n%i\n%i\n", stat->source,stat->value/2,stat->direct);
|
||||
file<<writer;
|
||||
if (stat->value > 0)
|
||||
{
|
||||
sprintf(writer, "%i\n%i\n%i\n", stat->source, stat->value / 2, stat->direct);
|
||||
file << writer;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
@@ -147,24 +184,30 @@ void AIStats::save(){
|
||||
|
||||
}
|
||||
|
||||
void AIStats::Render(){
|
||||
void AIStats::Render()
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
float x0 = 10;
|
||||
if (player == g->players[1]) x0 = 280;
|
||||
JRenderer::GetInstance()->FillRoundRect(x0,10,200,180,5,ARGB(50,0,0,0));
|
||||
if (player == g->players[1])
|
||||
x0 = 280;
|
||||
JRenderer::GetInstance()->FillRoundRect(x0, 10, 200, 180, 5, ARGB(50,0,0,0));
|
||||
|
||||
WFont * f = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
int i = 0;
|
||||
char buffer[512];
|
||||
list<AIStat *>::iterator it;
|
||||
for (it = stats.begin(); it !=stats.end(); ++it){
|
||||
if (i>10) break;
|
||||
for (it = stats.begin(); it != stats.end(); ++it)
|
||||
{
|
||||
if (i > 10)
|
||||
break;
|
||||
AIStat * stat = *it;
|
||||
if (stat->value > 0){
|
||||
if (stat->value > 0)
|
||||
{
|
||||
MTGCard * card = GameApp::collection->getCardById(stat->source);
|
||||
if (card) {
|
||||
if (card)
|
||||
{
|
||||
sprintf(buffer, "%s %i", card->data->getName().c_str(), stat->value);
|
||||
f->DrawString(buffer,x0+5,10 + 16 *(float)i);
|
||||
f->DrawString(buffer, x0 + 5, 10 + 16 * (float) i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include "Targetable.h"
|
||||
#include "TargetChooser.h"
|
||||
|
||||
ActionElement::ActionElement(int id):JGuiObject(id){
|
||||
ActionElement::ActionElement(int id) :
|
||||
JGuiObject(id)
|
||||
{
|
||||
activeState = INACTIVE;
|
||||
modal = 0;
|
||||
waitingForAnswer = 0;
|
||||
@@ -15,24 +17,30 @@ ActionElement::ActionElement(int id):JGuiObject(id){
|
||||
isClone = 0;
|
||||
}
|
||||
|
||||
ActionElement::~ActionElement(){
|
||||
if (!isClone){
|
||||
ActionElement::~ActionElement()
|
||||
{
|
||||
if (!isClone)
|
||||
{
|
||||
SAFE_DELETE(tc);
|
||||
}
|
||||
}
|
||||
|
||||
int ActionElement::getActivity(){
|
||||
int ActionElement::getActivity()
|
||||
{
|
||||
|
||||
return activeState;
|
||||
}
|
||||
|
||||
|
||||
int ActionElement::isReactingToTargetClick(Targetable * object){
|
||||
if (object && object->typeAsTarget() == TARGET_CARD) return isReactingToClick((MTGCardInstance *)object);
|
||||
int ActionElement::isReactingToTargetClick(Targetable * object)
|
||||
{
|
||||
if (object && object->typeAsTarget() == TARGET_CARD)
|
||||
return isReactingToClick((MTGCardInstance *) object);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ActionElement::reactToTargetClick(Targetable * object){
|
||||
if (object->typeAsTarget() == TARGET_CARD) return reactToClick((MTGCardInstance *)object);
|
||||
int ActionElement::reactToTargetClick(Targetable * object)
|
||||
{
|
||||
if (object->typeAsTarget() == TARGET_CARD)
|
||||
return reactToClick((MTGCardInstance *) object);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,22 +5,28 @@
|
||||
#include "Targetable.h"
|
||||
#include "WEvent.h"
|
||||
|
||||
MTGAbility* ActionLayer::getAbility(int type){
|
||||
for (int i = 1; i < mCount; i++){
|
||||
MTGAbility * a = ((MTGAbility *)mObjects[i]);
|
||||
if (a->aType == type){
|
||||
MTGAbility* ActionLayer::getAbility(int type)
|
||||
{
|
||||
for (int i = 1; i < mCount; i++)
|
||||
{
|
||||
MTGAbility * a = ((MTGAbility *) mObjects[i]);
|
||||
if (a->aType == type)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ActionLayer::moveToGarbage(ActionElement * e){
|
||||
int ActionLayer::moveToGarbage(ActionElement * e)
|
||||
{
|
||||
int i = getIndexOf(e);
|
||||
if (i != -1){
|
||||
if (isWaitingForAnswer() == e) setCurrentWaitingAction(NULL);
|
||||
if (i != -1)
|
||||
{
|
||||
if (isWaitingForAnswer() == e)
|
||||
setCurrentWaitingAction(NULL);
|
||||
e->destroy();
|
||||
mObjects.erase(mObjects.begin()+i);
|
||||
mObjects.erase(mObjects.begin() + i);
|
||||
mCount--;
|
||||
garbage.push_back(e);
|
||||
return 1;
|
||||
@@ -29,194 +35,241 @@ int ActionLayer::moveToGarbage(ActionElement * e){
|
||||
|
||||
}
|
||||
|
||||
int ActionLayer::cleanGarbage(){
|
||||
for (size_t i = 0; i < garbage.size(); ++i){
|
||||
delete(garbage[i]);
|
||||
int ActionLayer::cleanGarbage()
|
||||
{
|
||||
for (size_t i = 0; i < garbage.size(); ++i)
|
||||
{
|
||||
delete (garbage[i]);
|
||||
}
|
||||
garbage.clear();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ActionLayer::reactToClick(ActionElement * ability, MTGCardInstance * card){
|
||||
int ActionLayer::reactToClick(ActionElement * ability, MTGCardInstance * card)
|
||||
{
|
||||
int result = ability->reactToClick(card);
|
||||
if (result) stuffHappened = 1;
|
||||
if (result)
|
||||
stuffHappened = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int ActionLayer::reactToTargetClick(ActionElement* ability, Targetable * card){
|
||||
int ActionLayer::reactToTargetClick(ActionElement* ability, Targetable * card)
|
||||
{
|
||||
int result = ability->reactToTargetClick(card);
|
||||
if (result) stuffHappened = 1;
|
||||
if (result)
|
||||
stuffHappened = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ActionLayer::CheckUserInput(JButton key){
|
||||
bool ActionLayer::CheckUserInput(JButton key)
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (g->waitForExtraPayment && key == JGE_BTN_SEC){
|
||||
if (g->waitForExtraPayment && key == JGE_BTN_SEC)
|
||||
{
|
||||
g->waitForExtraPayment = NULL;
|
||||
return 1;
|
||||
}
|
||||
if (menuObject){
|
||||
if (menuObject)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i=0;i<mCount;i++){
|
||||
if (mObjects[i]!=NULL){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if (currentAction->CheckUserInput(key)) return true;
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
if (currentAction->CheckUserInput(key))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ActionLayer::Update(float dt){
|
||||
void ActionLayer::Update(float dt)
|
||||
{
|
||||
stuffHappened = 0;
|
||||
if (menuObject){
|
||||
if (menuObject)
|
||||
{
|
||||
abilitiesMenu->Update(dt);
|
||||
return;
|
||||
}
|
||||
modal = 0;
|
||||
GameObserver* game = GameObserver::GetInstance();
|
||||
for (int i=mCount -1 ;i>=0;i--){
|
||||
if (mObjects[i]!= NULL){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
for (int i = mCount - 1; i >= 0; i--)
|
||||
{
|
||||
if (mObjects[i] != NULL)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
if (currentAction->testDestroy())
|
||||
game->removeObserver(currentAction);
|
||||
}
|
||||
}
|
||||
int newPhase = game->getCurrentGamePhase();
|
||||
for (int i=0;i<mCount;i++){
|
||||
if (mObjects[i]!=NULL){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
currentAction->newPhase = newPhase;
|
||||
currentAction->Update(dt);
|
||||
currentAction->currentPhase = newPhase;
|
||||
}
|
||||
}
|
||||
|
||||
if (cantCancel){
|
||||
if (cantCancel)
|
||||
{
|
||||
ActionElement * ae = isWaitingForAnswer();
|
||||
if (ae && !ae->tc->validTargetsExist()) {
|
||||
if (ae && !ae->tc->validTargetsExist())
|
||||
{
|
||||
cantCancel = 0;
|
||||
cancelCurrentAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ActionLayer::Render (){
|
||||
if (menuObject){
|
||||
void ActionLayer::Render()
|
||||
{
|
||||
if (menuObject)
|
||||
{
|
||||
abilitiesMenu->Render();
|
||||
return;
|
||||
}
|
||||
for (int i=0;i<mCount;i++){
|
||||
if (mObjects[i]!=NULL){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
currentAction->Render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ActionLayer::setCurrentWaitingAction(ActionElement * ae){
|
||||
void ActionLayer::setCurrentWaitingAction(ActionElement * ae)
|
||||
{
|
||||
assert(!ae || !currentWaitingAction);//this assert causes crashes when may abilities overlap each other on ai. this conidiation is preexsiting.
|
||||
currentWaitingAction = ae;
|
||||
if (!ae) cantCancel = 0;
|
||||
if (!ae)
|
||||
cantCancel = 0;
|
||||
}
|
||||
|
||||
TargetChooser * ActionLayer::getCurrentTargetChooser(){
|
||||
TargetChooser * ActionLayer::getCurrentTargetChooser()
|
||||
{
|
||||
if (currentWaitingAction && currentWaitingAction->waitingForAnswer)
|
||||
return currentWaitingAction->tc;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ActionLayer::cancelCurrentAction(){
|
||||
int ActionLayer::cancelCurrentAction()
|
||||
{
|
||||
ActionElement * ae = isWaitingForAnswer();
|
||||
if (!ae) return 0;
|
||||
if (cantCancel && ae->tc->validTargetsExist()) return 0;
|
||||
if (!ae)
|
||||
return 0;
|
||||
if (cantCancel && ae->tc->validTargetsExist())
|
||||
return 0;
|
||||
ae->waitingForAnswer = 0; //TODO MOVE THIS IN ActionElement
|
||||
setCurrentWaitingAction(NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ActionElement * ActionLayer::isWaitingForAnswer(){
|
||||
ActionElement * ActionLayer::isWaitingForAnswer()
|
||||
{
|
||||
if (currentWaitingAction && currentWaitingAction->waitingForAnswer)
|
||||
return currentWaitingAction;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ActionLayer::stillInUse(MTGCardInstance * card){
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if(currentAction->stillInUse(card)) return 1;
|
||||
int ActionLayer::stillInUse(MTGCardInstance * card)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
if (currentAction->stillInUse(card))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ActionLayer::receiveEventPlus(WEvent * event){
|
||||
int ActionLayer::receiveEventPlus(WEvent * event)
|
||||
{
|
||||
int result = 0;
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
result += currentAction->receiveEvent(event);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ActionLayer::isReactingToTargetClick(Targetable * card){
|
||||
int ActionLayer::isReactingToTargetClick(Targetable * card)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (isWaitingForAnswer()) return -1;
|
||||
if (isWaitingForAnswer())
|
||||
return -1;
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
result += currentAction->isReactingToTargetClick(card);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ActionLayer::reactToTargetClick(Targetable * card){
|
||||
int ActionLayer::reactToTargetClick(Targetable * card)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
ActionElement * ae = isWaitingForAnswer();
|
||||
if (ae) return reactToTargetClick(ae,card);
|
||||
if (ae)
|
||||
return reactToTargetClick(ae, card);
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
result += currentAction->reactToTargetClick(card);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//TODO Simplify with only object !!!
|
||||
int ActionLayer::isReactingToClick(MTGCardInstance * card){
|
||||
int ActionLayer::isReactingToClick(MTGCardInstance * card)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (isWaitingForAnswer()) return -1;
|
||||
if (isWaitingForAnswer())
|
||||
return -1;
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
result += currentAction->isReactingToClick(card);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ActionLayer::reactToClick(MTGCardInstance * card){
|
||||
int ActionLayer::reactToClick(MTGCardInstance * card)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
ActionElement * ae = isWaitingForAnswer();
|
||||
if (ae) return reactToClick(ae,card);
|
||||
if (ae)
|
||||
return reactToClick(ae, card);
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
result += reactToClick(currentAction,card);
|
||||
if (result) return result;
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
result += reactToClick(currentAction, card);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ActionLayer::setMenuObject(Targetable * object, bool must){
|
||||
if (!object){
|
||||
void ActionLayer::setMenuObject(Targetable * object, bool must)
|
||||
{
|
||||
if (!object)
|
||||
{
|
||||
DebugTrace("FATAL: ActionLayer::setMenuObject");
|
||||
return;
|
||||
}
|
||||
@@ -224,40 +277,51 @@ void ActionLayer::setMenuObject(Targetable * object, bool must){
|
||||
|
||||
SAFE_DELETE(abilitiesMenu);
|
||||
|
||||
abilitiesMenu = NEW SimpleMenu(10, this, Fonts::MAIN_FONT, 100, 100,object->getDisplayName().c_str());
|
||||
abilitiesMenu = NEW SimpleMenu(10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str());
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if (currentAction->isReactingToTargetClick(object)){
|
||||
abilitiesMenu->Add(i,currentAction->getMenuText());
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||
if (currentAction->isReactingToTargetClick(object))
|
||||
{
|
||||
abilitiesMenu->Add(i, currentAction->getMenuText());
|
||||
}
|
||||
}
|
||||
if (!must) abilitiesMenu->Add(kCancelMenuID, "Cancel");
|
||||
else cantCancel = 1;
|
||||
if (!must)
|
||||
abilitiesMenu->Add(kCancelMenuID, "Cancel");
|
||||
else
|
||||
cantCancel = 1;
|
||||
modal = 1;
|
||||
}
|
||||
|
||||
void ActionLayer::doReactTo(int menuIndex){
|
||||
void ActionLayer::doReactTo(int menuIndex)
|
||||
{
|
||||
|
||||
if (menuObject){
|
||||
if (menuObject)
|
||||
{
|
||||
int controlid = abilitiesMenu->mObjects[menuIndex]->GetId();
|
||||
DebugTrace("ActionLayer::doReactTo " << controlid);
|
||||
ButtonPressed(0,controlid);
|
||||
ButtonPressed(0, controlid);
|
||||
}
|
||||
}
|
||||
|
||||
void ActionLayer::ButtonPressed(int controllerid, int controlid){
|
||||
if (controlid != -1){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[controlid];
|
||||
void ActionLayer::ButtonPressed(int controllerid, int controlid)
|
||||
{
|
||||
if (controlid != -1)
|
||||
{
|
||||
ActionElement * currentAction = (ActionElement *) mObjects[controlid];
|
||||
currentAction->reactToTargetClick(menuObject);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObserver::GetInstance()->mLayers->stackLayer()->endOfInterruption();
|
||||
}
|
||||
menuObject = 0;
|
||||
|
||||
}
|
||||
|
||||
ActionLayer::ActionLayer(){
|
||||
ActionLayer::ActionLayer()
|
||||
{
|
||||
menuObject = NULL;
|
||||
abilitiesMenu = NULL;
|
||||
stuffHappened = 0;
|
||||
@@ -265,9 +329,11 @@ ActionLayer::ActionLayer(){
|
||||
cantCancel = 0;
|
||||
}
|
||||
|
||||
ActionLayer::~ActionLayer(){
|
||||
for (int i=mCount-1;i>=0;i--){
|
||||
moveToGarbage((ActionElement *)mObjects[i]);
|
||||
ActionLayer::~ActionLayer()
|
||||
{
|
||||
for (int i = mCount - 1; i >= 0; i--)
|
||||
{
|
||||
moveToGarbage((ActionElement *) mObjects[i]);
|
||||
}
|
||||
SAFE_DELETE(abilitiesMenu);
|
||||
cleanGarbage();
|
||||
|
||||
+584
-358
File diff suppressed because it is too large
Load Diff
@@ -3,8 +3,11 @@
|
||||
|
||||
// BanishCard implementations
|
||||
|
||||
AABanishCard::AABanishCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost=NULL, int _banishmentType = -1):ActivatedAbility(_id, _source,_cost),banishmentType(_banishmentType) {
|
||||
if (_target) target = _target;
|
||||
AABanishCard::AABanishCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = -1) :
|
||||
ActivatedAbility(_id, _source, _cost), banishmentType(_banishmentType)
|
||||
{
|
||||
if (_target)
|
||||
target = _target;
|
||||
}
|
||||
|
||||
const char * AABanishCard::getMenuText()
|
||||
@@ -18,7 +21,8 @@ int AABanishCard::resolve()
|
||||
return 0;
|
||||
}
|
||||
|
||||
AABanishCard * AABanishCard::clone() const{
|
||||
AABanishCard * AABanishCard::clone() const
|
||||
{
|
||||
AABanishCard * a = NEW AABanishCard(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
@@ -26,58 +30,74 @@ AABanishCard * AABanishCard::clone() const{
|
||||
|
||||
// Bury
|
||||
|
||||
AABuryCard::AABuryCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL , int _banishmentType = 0):AABanishCard(_id, _source, _target, _cost, AABanishCard::BURY)
|
||||
{}
|
||||
AABuryCard::AABuryCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType =
|
||||
0) :
|
||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::BURY)
|
||||
{
|
||||
}
|
||||
|
||||
int AABuryCard::resolve(){
|
||||
int AABuryCard::resolve()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(_target){
|
||||
if (_target)
|
||||
{
|
||||
return _target->bury();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * AABuryCard::getMenuText(){
|
||||
const char * AABuryCard::getMenuText()
|
||||
{
|
||||
return "Bury";
|
||||
}
|
||||
|
||||
AABuryCard * AABuryCard::clone() const{
|
||||
AABuryCard * AABuryCard::clone() const
|
||||
{
|
||||
AABuryCard * a = NEW AABuryCard(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
// Destroy
|
||||
|
||||
AADestroyCard::AADestroyCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = 0):AABanishCard(_id, _source, _target, _cost, AABanishCard::DESTROY)
|
||||
{}
|
||||
AADestroyCard::AADestroyCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = 0) :
|
||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::DESTROY)
|
||||
{
|
||||
}
|
||||
|
||||
int AADestroyCard::resolve(){
|
||||
int AADestroyCard::resolve()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(_target){
|
||||
if (_target)
|
||||
{
|
||||
return _target->destroy();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * AADestroyCard::getMenuText(){
|
||||
const char * AADestroyCard::getMenuText()
|
||||
{
|
||||
return "Destroy";
|
||||
}
|
||||
|
||||
AADestroyCard * AADestroyCard::clone() const{
|
||||
AADestroyCard * AADestroyCard::clone() const
|
||||
{
|
||||
AADestroyCard * a = NEW AADestroyCard(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
// Sacrifice
|
||||
AASacrificeCard::AASacrificeCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = 0):AABanishCard(_id, _source, _target, _cost, AABanishCard::SACRIFICE) {
|
||||
AASacrificeCard::AASacrificeCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = 0) :
|
||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::SACRIFICE)
|
||||
{
|
||||
}
|
||||
|
||||
int AASacrificeCard::resolve(){
|
||||
int AASacrificeCard::resolve()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(_target){
|
||||
if (_target)
|
||||
{
|
||||
Player * p = _target->controller();
|
||||
WEvent * e = NEW WEventCardSacrifice(_target);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
@@ -88,11 +108,13 @@ int AASacrificeCard::resolve(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * AASacrificeCard::getMenuText(){
|
||||
const char * AASacrificeCard::getMenuText()
|
||||
{
|
||||
return "Sacrifice";
|
||||
}
|
||||
|
||||
AASacrificeCard * AASacrificeCard::clone() const{
|
||||
AASacrificeCard * AASacrificeCard::clone() const
|
||||
{
|
||||
AASacrificeCard * a = NEW AASacrificeCard(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
@@ -100,12 +122,17 @@ AASacrificeCard * AASacrificeCard::clone() const{
|
||||
|
||||
// Discard
|
||||
|
||||
AADiscardCard::AADiscardCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = 0):AABanishCard(_id, _source, _target, _cost, AABanishCard::DISCARD) {
|
||||
AADiscardCard::AADiscardCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL,
|
||||
int _banishmentType = 0) :
|
||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::DISCARD)
|
||||
{
|
||||
}
|
||||
|
||||
int AADiscardCard::resolve(){
|
||||
int AADiscardCard::resolve()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(_target){
|
||||
if (_target)
|
||||
{
|
||||
Player * p = _target->controller();
|
||||
WEvent * e = NEW WEventCardDiscard(_target);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
@@ -116,49 +143,69 @@ int AADiscardCard::resolve(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * AADiscardCard::getMenuText(){
|
||||
const char * AADiscardCard::getMenuText()
|
||||
{
|
||||
return "Discard";
|
||||
}
|
||||
|
||||
AADiscardCard * AADiscardCard::clone() const{
|
||||
AADiscardCard * AADiscardCard::clone() const
|
||||
{
|
||||
AADiscardCard * a = NEW AADiscardCard(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
//Mana Redux
|
||||
AManaRedux::AManaRedux(int id, MTGCardInstance * source, MTGCardInstance * target,int amount,int type):MTGAbility(id,source,target),amount(amount),type(type) {
|
||||
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||
AManaRedux::AManaRedux(int id, MTGCardInstance * source, MTGCardInstance * target, int amount, int type) :
|
||||
MTGAbility(id, source, target), amount(amount), type(type)
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
}
|
||||
|
||||
int AManaRedux::addToGame(){
|
||||
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||
if(amount < 0){
|
||||
int AManaRedux::addToGame()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if (amount < 0)
|
||||
{
|
||||
amount = abs(amount);
|
||||
if(_target->getManaCost()->hasColor(type)){
|
||||
if(_target->getManaCost()->getConvertedCost() >= 1){
|
||||
_target->getManaCost()->remove(type,amount);
|
||||
if(_target->getManaCost()->alternative > 0){
|
||||
_target->getManaCost()->alternative->remove(type,amount);}
|
||||
if(_target->getManaCost()->BuyBack > 0){
|
||||
_target->getManaCost()->BuyBack->remove(type,amount);}
|
||||
if (_target->getManaCost()->hasColor(type))
|
||||
{
|
||||
if (_target->getManaCost()->getConvertedCost() >= 1)
|
||||
{
|
||||
_target->getManaCost()->remove(type, amount);
|
||||
if (_target->getManaCost()->alternative > 0)
|
||||
{
|
||||
_target->getManaCost()->alternative->remove(type, amount);
|
||||
}
|
||||
if (_target->getManaCost()->BuyBack > 0)
|
||||
{
|
||||
_target->getManaCost()->BuyBack->remove(type, amount);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
_target->getManaCost()->add(type,amount);
|
||||
if(_target->getManaCost()->alternative > 0){
|
||||
_target->getManaCost()->alternative->add(type,amount);}
|
||||
if(_target->getManaCost()->BuyBack > 0){
|
||||
_target->getManaCost()->BuyBack->add(type,amount);}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_target->getManaCost()->add(type, amount);
|
||||
if (_target->getManaCost()->alternative > 0)
|
||||
{
|
||||
_target->getManaCost()->alternative->add(type, amount);
|
||||
}
|
||||
if (_target->getManaCost()->BuyBack > 0)
|
||||
{
|
||||
_target->getManaCost()->BuyBack->add(type, amount);
|
||||
}
|
||||
}
|
||||
return MTGAbility::addToGame();
|
||||
}
|
||||
|
||||
AManaRedux * AManaRedux::clone() const {
|
||||
AManaRedux * AManaRedux::clone() const
|
||||
{
|
||||
AManaRedux * a = NEW AManaRedux(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
AManaRedux::~AManaRedux(){}
|
||||
AManaRedux::~AManaRedux()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "Subtypes.h"
|
||||
#include "Counters.h"
|
||||
|
||||
|
||||
CardDescriptor::CardDescriptor(): MTGCardInstance(){
|
||||
CardDescriptor::CardDescriptor() : MTGCardInstance()
|
||||
{
|
||||
init();
|
||||
counterName = "";
|
||||
counterPower = 0;
|
||||
@@ -19,7 +19,8 @@ CardDescriptor::CardDescriptor(): MTGCardInstance(){
|
||||
convertedManacost = -1;
|
||||
}
|
||||
|
||||
int CardDescriptor::init(){
|
||||
int CardDescriptor::init()
|
||||
{
|
||||
int result = MTGCardInstance::init();
|
||||
attacker = 0;
|
||||
defenser = NULL;
|
||||
@@ -31,23 +32,28 @@ int CardDescriptor::init(){
|
||||
return result;
|
||||
}
|
||||
|
||||
void CardDescriptor::unsecureSetTapped(int i){
|
||||
void CardDescriptor::unsecureSetTapped(int i)
|
||||
{
|
||||
tapped = i;
|
||||
}
|
||||
|
||||
void CardDescriptor::unsecuresetfresh(int k){
|
||||
void CardDescriptor::unsecuresetfresh(int k)
|
||||
{
|
||||
fresh = k;
|
||||
}
|
||||
|
||||
void CardDescriptor::setNegativeSubtype( string value){
|
||||
void CardDescriptor::setNegativeSubtype(string value)
|
||||
{
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
addType(-id);
|
||||
}
|
||||
|
||||
// Very generic function to compare a value to a criterion.
|
||||
// Should be easily transferable to a more generic class if desired.
|
||||
bool CardDescriptor::valueInRange(int comparisonMode, int value, int criterion){
|
||||
switch (comparisonMode){
|
||||
bool CardDescriptor::valueInRange(int comparisonMode, int value, int criterion)
|
||||
{
|
||||
switch (comparisonMode)
|
||||
{
|
||||
case COMPARISON_AT_MOST:
|
||||
return (value <= criterion);
|
||||
case COMPARISON_AT_LEAST:
|
||||
@@ -64,148 +70,220 @@ bool CardDescriptor::valueInRange(int comparisonMode, int value, int criterion){
|
||||
return false;
|
||||
}
|
||||
|
||||
MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
|
||||
MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card)
|
||||
{
|
||||
int found = 1;
|
||||
for (size_t i = 0; i< types.size(); i++){
|
||||
for (size_t i = 0; i < types.size(); i++)
|
||||
{
|
||||
found = 0;
|
||||
if (types[i] >= 0){
|
||||
if (types[i] >= 0)
|
||||
{
|
||||
|
||||
if (card->hasSubtype(types[i]) || (Subtypes::subtypesList->find(card->getLCName(),false) == types[i])){
|
||||
if (card->hasSubtype(types[i]) || (Subtypes::subtypesList->find(card->getLCName(), false) == types[i]))
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
if (!card->hasSubtype(-types[i]) && (Subtypes::subtypesList->find(card->getLCName(), false) != -types[i])){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!card->hasSubtype(-types[i]) && (Subtypes::subtypesList->find(card->getLCName(), false) != -types[i]))
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) return NULL;
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; i++){
|
||||
if (colors[i] == 1){
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
if (colors[i] == 1)
|
||||
{
|
||||
found = 0;
|
||||
if(card->hasColor(i)){
|
||||
if (card->hasColor(i))
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (colors[i] == -1){
|
||||
else if (colors[i] == -1)
|
||||
{
|
||||
found = 0;
|
||||
if(!card->hasColor(i)){
|
||||
if (!card->hasColor(i))
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) return NULL;
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
// Quantified restrictions are always AND-ed:
|
||||
if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power) ) return NULL;
|
||||
if (toughnessComparisonMode && !valueInRange(toughnessComparisonMode, card->getToughness(), toughness) ) return NULL;
|
||||
if (manacostComparisonMode && !valueInRange(manacostComparisonMode, card->getManaCost()->getConvertedCost(), convertedManacost) ) return NULL;
|
||||
if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power))
|
||||
return NULL;
|
||||
if (toughnessComparisonMode && !valueInRange(toughnessComparisonMode, card->getToughness(), toughness))
|
||||
return NULL;
|
||||
if (manacostComparisonMode && !valueInRange(manacostComparisonMode, card->getManaCost()->getConvertedCost(), convertedManacost))
|
||||
return NULL;
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){
|
||||
MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card)
|
||||
{
|
||||
MTGCardInstance * match = card;
|
||||
for (size_t i = 0; i< types.size(); i++){
|
||||
if (types[i] >= 0){
|
||||
if (!card->hasSubtype(types[i]) && !(Subtypes::subtypesList->find(card->getLCName(),false) == types[i])){
|
||||
for (size_t i = 0; i < types.size(); i++)
|
||||
{
|
||||
if (types[i] >= 0)
|
||||
{
|
||||
if (!card->hasSubtype(types[i]) && !(Subtypes::subtypesList->find(card->getLCName(), false) == types[i]))
|
||||
{
|
||||
match = NULL;
|
||||
}
|
||||
}else{
|
||||
if(card->hasSubtype(-types[i]) || (Subtypes::subtypesList->find(card->getLCName(),false) == -types[i])){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (card->hasSubtype(-types[i]) || (Subtypes::subtypesList->find(card->getLCName(), false) == -types[i]))
|
||||
{
|
||||
match = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; i++){
|
||||
if ((colors[i] == 1 && !card->hasColor(i))||(colors[i] == -1 && card->hasColor(i))){
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
if ((colors[i] == 1 && !card->hasColor(i)) || (colors[i] == -1 && card->hasColor(i)))
|
||||
{
|
||||
match = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power) ) match = NULL;
|
||||
if (toughnessComparisonMode && !valueInRange(toughnessComparisonMode, card->getToughness(), toughness) ) match = NULL;
|
||||
if (manacostComparisonMode && !valueInRange(manacostComparisonMode, card->getManaCost()->getConvertedCost(), convertedManacost) ) match = NULL;
|
||||
if (powerComparisonMode && !valueInRange(powerComparisonMode, card->getPower(), power))
|
||||
match = NULL;
|
||||
if (toughnessComparisonMode && !valueInRange(toughnessComparisonMode, card->getToughness(), toughness))
|
||||
match = NULL;
|
||||
if (manacostComparisonMode && !valueInRange(manacostComparisonMode, card->getManaCost()->getConvertedCost(), convertedManacost))
|
||||
match = NULL;
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
MTGCardInstance * CardDescriptor::match(MTGCardInstance * card){
|
||||
MTGCardInstance * CardDescriptor::match(MTGCardInstance * card)
|
||||
{
|
||||
|
||||
MTGCardInstance * match = card;
|
||||
if (mode == CD_AND){
|
||||
if (mode == CD_AND)
|
||||
{
|
||||
match = match_and(card);
|
||||
}else{
|
||||
match=match_or(card);
|
||||
}
|
||||
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
match = match_or(card);
|
||||
}
|
||||
|
||||
//Abilities
|
||||
for(map<int,int>::const_iterator it = basicAbilities.begin(); it != basicAbilities.end(); ++it){
|
||||
for (map<int, int>::const_iterator it = basicAbilities.begin(); it != basicAbilities.end(); ++it)
|
||||
{
|
||||
int j = it->first;
|
||||
if ((basicAbilities[j] == 1 && !card->basicAbilities[j]) || (basicAbilities[j] == -1 && card->basicAbilities[j])){
|
||||
if ((basicAbilities[j] == 1 && !card->basicAbilities[j]) || (basicAbilities[j] == -1 && card->basicAbilities[j]))
|
||||
{
|
||||
match = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped())){
|
||||
if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped()))
|
||||
{
|
||||
match = NULL;
|
||||
}
|
||||
|
||||
if ((fresh == -1 && card->fresh) || (fresh == 1 && !card->fresh)){
|
||||
if ((fresh == -1 && card->fresh) || (fresh == 1 && !card->fresh))
|
||||
{
|
||||
match = NULL;
|
||||
}
|
||||
|
||||
if ((isToken== -1 && card->isToken) || (isToken == 1 && !card->isToken)){
|
||||
if ((isToken == -1 && card->isToken) || (isToken == 1 && !card->isToken))
|
||||
{
|
||||
match = NULL;
|
||||
}
|
||||
if (attacker == 1){
|
||||
if (defenser == &AnyCard){
|
||||
if (!card->attacker && !card->defenser) match = NULL;
|
||||
}else{
|
||||
if (!card->attacker) match = NULL;
|
||||
if (attacker == 1)
|
||||
{
|
||||
if (defenser == &AnyCard)
|
||||
{
|
||||
if (!card->attacker && !card->defenser)
|
||||
match = NULL;
|
||||
}
|
||||
}else if (attacker == -1){
|
||||
if (defenser == &NoCard){
|
||||
if (card->attacker || card->defenser) match = NULL;
|
||||
}else{
|
||||
if (card->attacker) match = NULL;
|
||||
else
|
||||
{
|
||||
if (!card->attacker)
|
||||
match = NULL;
|
||||
}
|
||||
}else{
|
||||
if (defenser == &NoCard){
|
||||
if (card->defenser) match = NULL;
|
||||
}else if (defenser == &AnyCard){
|
||||
if (!card->defenser) match = NULL;
|
||||
}else{
|
||||
}
|
||||
else if (attacker == -1)
|
||||
{
|
||||
if (defenser == &NoCard)
|
||||
{
|
||||
if (card->attacker || card->defenser)
|
||||
match = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (card->attacker)
|
||||
match = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (defenser == &NoCard)
|
||||
{
|
||||
if (card->defenser)
|
||||
match = NULL;
|
||||
}
|
||||
else if (defenser == &AnyCard)
|
||||
{
|
||||
if (!card->defenser)
|
||||
match = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we don't care about the attack/blocker state
|
||||
}
|
||||
}
|
||||
|
||||
//Counters
|
||||
if (anyCounter) {
|
||||
if (!(card->counters->mCount)) {
|
||||
if (anyCounter)
|
||||
{
|
||||
if (!(card->counters->mCount))
|
||||
{
|
||||
match = NULL;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
int hasCounter = 0;
|
||||
for (int i = 0; i < card->counters->mCount; i++) {
|
||||
if (card->counters->counters[i]->nb > 0) hasCounter = 1;
|
||||
for (int i = 0; i < card->counters->mCount; i++)
|
||||
{
|
||||
if (card->counters->counters[i]->nb > 0)
|
||||
hasCounter = 1;
|
||||
}
|
||||
if (!hasCounter) match = NULL;
|
||||
if (!hasCounter)
|
||||
match = NULL;
|
||||
}
|
||||
}else{
|
||||
if (counterComparisonMode) {
|
||||
Counter * targetCounter = card->counters->hasCounter(counterName.c_str(),counterPower,counterToughness);
|
||||
if (targetCounter) {
|
||||
if (!valueInRange(counterComparisonMode,targetCounter->nb,counterNB)) match = NULL;
|
||||
} else {
|
||||
if (counterComparisonMode != COMPARISON_LESS && counterComparisonMode != COMPARISON_AT_MOST) match = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (counterComparisonMode)
|
||||
{
|
||||
Counter * targetCounter = card->counters->hasCounter(counterName.c_str(), counterPower, counterToughness);
|
||||
if (targetCounter)
|
||||
{
|
||||
if (!valueInRange(counterComparisonMode, targetCounter->nb, counterNB))
|
||||
match = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (counterComparisonMode != COMPARISON_LESS && counterComparisonMode != COMPARISON_AT_MOST)
|
||||
match = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,18 +291,24 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card){
|
||||
return match;
|
||||
}
|
||||
|
||||
MTGCardInstance * CardDescriptor::match(MTGGameZone * zone){
|
||||
MTGCardInstance * CardDescriptor::match(MTGGameZone * zone)
|
||||
{
|
||||
return (nextmatch(zone, NULL));
|
||||
}
|
||||
|
||||
MTGCardInstance * CardDescriptor::nextmatch(MTGGameZone * zone, MTGCardInstance * previous){
|
||||
MTGCardInstance * CardDescriptor::nextmatch(MTGGameZone * zone, MTGCardInstance * previous)
|
||||
{
|
||||
int found = 0;
|
||||
if (NULL == previous) found = 1;
|
||||
for(int i=0; i < zone->nb_cards; i++){
|
||||
if(found && match(zone->cards[i])){
|
||||
if (NULL == previous)
|
||||
found = 1;
|
||||
for (int i = 0; i < zone->nb_cards; i++)
|
||||
{
|
||||
if (found && match(zone->cards[i]))
|
||||
{
|
||||
return zone->cards[i];
|
||||
}
|
||||
if (zone->cards[i] == previous){
|
||||
if (zone->cards[i] == previous)
|
||||
{
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
#include "MTGGameZones.h"
|
||||
#include "GameObserver.h"
|
||||
|
||||
CardDisplay::CardDisplay() : mId(0), game(GameObserver::GetInstance()) {
|
||||
CardDisplay::CardDisplay() :
|
||||
mId(0), game(GameObserver::GetInstance())
|
||||
{
|
||||
tc = NULL;
|
||||
listener = NULL;
|
||||
nb_displayed_items = 7;
|
||||
@@ -17,7 +19,10 @@ CardDisplay::CardDisplay() : mId(0), game(GameObserver::GetInstance()) {
|
||||
zone = NULL;
|
||||
}
|
||||
|
||||
CardDisplay::CardDisplay(int id, GameObserver* game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc, int _nb_displayed_items ) : mId(id), game(game), x(_x), y(_y) {
|
||||
CardDisplay::CardDisplay(int id, GameObserver* game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc,
|
||||
int _nb_displayed_items) :
|
||||
mId(id), game(game), x(_x), y(_y)
|
||||
{
|
||||
tc = _tc;
|
||||
listener = _listener;
|
||||
nb_displayed_items = _nb_displayed_items;
|
||||
@@ -27,47 +32,62 @@ CardDisplay::CardDisplay(int id, GameObserver* game, int _x, int _y, JGuiListene
|
||||
zone = NULL;
|
||||
}
|
||||
|
||||
void CardDisplay::AddCard(MTGCardInstance * _card){
|
||||
CardGui * card = NEW CardView(CardView::nullZone, _card, static_cast<float>(x + 20 + (mCount - start_item) * 30), static_cast<float>(y + 25));
|
||||
void CardDisplay::AddCard(MTGCardInstance * _card)
|
||||
{
|
||||
CardGui * card = NEW CardView(CardView::nullZone, _card, static_cast<float> (x + 20 + (mCount - start_item) * 30),
|
||||
static_cast<float> (y + 25));
|
||||
Add(card);
|
||||
}
|
||||
|
||||
void CardDisplay::init(MTGGameZone * zone){
|
||||
void CardDisplay::init(MTGGameZone * zone)
|
||||
{
|
||||
resetObjects();
|
||||
if (!zone) return;
|
||||
start_item = 0;
|
||||
for (int i= 0; i< zone->nb_cards; i++){
|
||||
for (int i = 0; i < zone->nb_cards; i++)
|
||||
{
|
||||
AddCard(zone->cards[i]);
|
||||
}
|
||||
if (mCount) mObjects[0]->Entering();
|
||||
}
|
||||
|
||||
void CardDisplay::rotateLeft(){
|
||||
if (start_item==0) return;
|
||||
for (int i = 0; i<mCount; i++){
|
||||
CardGui * cardg = (CardGui *)mObjects[i];
|
||||
cardg->x+=30;
|
||||
void CardDisplay::rotateLeft()
|
||||
{
|
||||
if (start_item == 0) return;
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
CardGui * cardg = (CardGui *) mObjects[i];
|
||||
cardg->x += 30;
|
||||
}
|
||||
start_item --;
|
||||
start_item--;
|
||||
}
|
||||
|
||||
void CardDisplay::rotateRight(){
|
||||
if (start_item==mCount-1) return;
|
||||
for (int i= 0; i<mCount; i++){
|
||||
CardGui * cardg = (CardGui *)mObjects[i];
|
||||
cardg->x-=30;
|
||||
void CardDisplay::rotateRight()
|
||||
{
|
||||
if (start_item == mCount - 1) return;
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
CardGui * cardg = (CardGui *) mObjects[i];
|
||||
cardg->x -= 30;
|
||||
}
|
||||
start_item ++;
|
||||
start_item++;
|
||||
}
|
||||
|
||||
void CardDisplay::Update(float dt){
|
||||
void CardDisplay::Update(float dt)
|
||||
{
|
||||
bool update = false;
|
||||
|
||||
if (zone){
|
||||
if (zone)
|
||||
{
|
||||
int size = zone->cards.size();
|
||||
for (int i = start_item; i< start_item + nb_displayed_items && i < mCount; i++){
|
||||
if (i > size - 1) {update = true; break;}
|
||||
CardGui * cardg = (CardGui *)mObjects[i];
|
||||
for (int i = start_item; i < start_item + nb_displayed_items && i < mCount; i++)
|
||||
{
|
||||
if (i > size - 1)
|
||||
{
|
||||
update = true;
|
||||
break;
|
||||
}
|
||||
CardGui * cardg = (CardGui *) mObjects[i];
|
||||
if (cardg->card != zone->cards[i]) update = true;
|
||||
}
|
||||
}
|
||||
@@ -75,20 +95,21 @@ void CardDisplay::Update(float dt){
|
||||
if (update) init(zone);
|
||||
}
|
||||
|
||||
bool CardDisplay::CheckUserInput(int x, int y) {
|
||||
bool CardDisplay::CheckUserInput(int x, int y)
|
||||
{
|
||||
unsigned int distance2;
|
||||
unsigned int minDistance2 = -1;
|
||||
int n = mCurr;
|
||||
JButton key;
|
||||
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
if (JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
for(int i = 0; i < mCount; i++)
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
int top, left;
|
||||
if(mObjects[i]->getTopLeft(top, left))
|
||||
if (mObjects[i]->getTopLeft(top, left))
|
||||
{
|
||||
distance2 = (top-y)*(top-y) + (left-x)*(left-x);
|
||||
if(distance2 < minDistance2)
|
||||
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
||||
if (distance2 < minDistance2)
|
||||
{
|
||||
minDistance2 = distance2;
|
||||
n = i;
|
||||
@@ -96,17 +117,21 @@ bool CardDisplay::CheckUserInput(int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
if(n < mCurr)
|
||||
if (n < mCurr)
|
||||
key = JGE_BTN_LEFT;
|
||||
else
|
||||
key = JGE_BTN_RIGHT;
|
||||
|
||||
if (n<start_item) {
|
||||
if (n < start_item)
|
||||
{
|
||||
rotateLeft();
|
||||
} else if (n>= mCount) {
|
||||
n = mCount-1;
|
||||
}
|
||||
if (n>= start_item + nb_displayed_items) {
|
||||
else if (n >= mCount)
|
||||
{
|
||||
n = mCount - 1;
|
||||
}
|
||||
if (n >= start_item + nb_displayed_items)
|
||||
{
|
||||
rotateRight();
|
||||
}
|
||||
|
||||
@@ -122,26 +147,30 @@ bool CardDisplay::CheckUserInput(int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CardDisplay::CheckUserInput(JButton key){
|
||||
bool CardDisplay::CheckUserInput(JButton key)
|
||||
{
|
||||
if (JGE_BTN_SEC == key || JGE_BTN_PRI == key || JGE_BTN_UP == key || JGE_BTN_DOWN == key)
|
||||
{
|
||||
if (listener){
|
||||
if (listener)
|
||||
{
|
||||
listener->ButtonPressed(mId, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!mCount)
|
||||
return false;
|
||||
if (!mCount) return false;
|
||||
|
||||
if (mActionButton == key)
|
||||
{
|
||||
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
|
||||
CardGui * cardg = (CardGui *)mObjects[mCurr];
|
||||
if (tc) {
|
||||
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed())
|
||||
{
|
||||
CardGui * cardg = (CardGui *) mObjects[mCurr];
|
||||
if (tc)
|
||||
{
|
||||
tc->toggleTarget(cardg->card);
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (game) game->ButtonPressed(cardg);
|
||||
return true;
|
||||
}
|
||||
@@ -149,37 +178,44 @@ bool CardDisplay::CheckUserInput(JButton key){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
switch(key)
|
||||
switch (key)
|
||||
{
|
||||
case JGE_BTN_LEFT :
|
||||
case JGE_BTN_LEFT:
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
if (n<start_item) {
|
||||
if (n< 0) {
|
||||
if (n < start_item)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
n = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
rotateLeft();
|
||||
}
|
||||
}
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT)){
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case JGE_BTN_RIGHT :
|
||||
case JGE_BTN_RIGHT:
|
||||
{
|
||||
int n = mCurr;
|
||||
n++;
|
||||
if (n>= mCount) {
|
||||
n = mCount-1;
|
||||
if (n >= mCount)
|
||||
{
|
||||
n = mCount - 1;
|
||||
}
|
||||
if (n>= start_item + nb_displayed_items) {
|
||||
if (n >= start_item + nb_displayed_items)
|
||||
{
|
||||
rotateRight();
|
||||
}
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT)){
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
@@ -191,21 +227,28 @@ bool CardDisplay::CheckUserInput(JButton key){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CardDisplay::Render(){
|
||||
void CardDisplay::Render()
|
||||
{
|
||||
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->DrawRect(static_cast<float>(x), static_cast<float>(y), static_cast<float>(nb_displayed_items * 30 + 20), 50, ARGB(255,255,255,255));
|
||||
r->DrawRect(static_cast<float> (x), static_cast<float> (y), static_cast<float> (nb_displayed_items * 30 + 20), 50,
|
||||
ARGB(255,255,255,255));
|
||||
if (!mCount) return;
|
||||
for (int i = start_item; i< start_item + nb_displayed_items && i < mCount; i++){
|
||||
if (mObjects[i]){
|
||||
for (int i = start_item; i < start_item + nb_displayed_items && i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i])
|
||||
{
|
||||
mObjects[i]->Render();
|
||||
if (tc){
|
||||
CardGui * cardg = (CardGui *)mObjects[i];
|
||||
if( tc->alreadyHasTarget(cardg->card)){
|
||||
r->DrawCircle(cardg->x + 5, cardg->y+5,5, ARGB(255,255,0,0));
|
||||
}else if (!tc->canTarget(cardg->card)){
|
||||
r->FillRect(cardg->x,cardg->y,30,40,ARGB(200,0,0,0));
|
||||
if (tc)
|
||||
{
|
||||
CardGui * cardg = (CardGui *) mObjects[i];
|
||||
if (tc->alreadyHasTarget(cardg->card))
|
||||
{
|
||||
r->DrawCircle(cardg->x + 5, cardg->y + 5, 5, ARGB(255,255,0,0));
|
||||
}
|
||||
else if (!tc->canTarget(cardg->card))
|
||||
{
|
||||
r->FillRect(cardg->x, cardg->y, 30, 40, ARGB(200,0,0,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,7 +258,7 @@ void CardDisplay::Render(){
|
||||
if (mCount && mObjects[mCurr] != NULL)
|
||||
{
|
||||
mObjects[mCurr]->Render();
|
||||
CardGui * cardg = ((CardGui *)mObjects[mCurr]);
|
||||
CardGui * cardg = ((CardGui *) mObjects[mCurr]);
|
||||
Pos pos = Pos(CardGui::BigWidth / 2, CardGui::BigHeight / 2 - 10, 1.0, 0.0, 220);
|
||||
int drawMode = DrawMode::kNormal;
|
||||
if (game)
|
||||
@@ -231,10 +274,10 @@ void CardDisplay::Render(){
|
||||
|
||||
ostream& CardDisplay::toString(ostream& out) const
|
||||
{
|
||||
return (out << "CardDisplay ::: x,y : " << x << "," << y << " ; start_item : " << start_item << " ; nb_displayed_items " << nb_displayed_items << " ; tc : " << tc << " ; listener : " << listener);
|
||||
return (out << "CardDisplay ::: x,y : " << x << "," << y << " ; start_item : " << start_item << " ; nb_displayed_items "
|
||||
<< nb_displayed_items << " ; tc : " << tc << " ; listener : " << listener);
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const CardDisplay& m)
|
||||
{
|
||||
return m.toString(out);
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include "../include/GameOptions.h"
|
||||
#include "../include/CardEffect.h"
|
||||
|
||||
CardEffect::CardEffect(CardGui* target) : target(target)
|
||||
CardEffect::CardEffect(CardGui* target) :
|
||||
target(target)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
+296
-160
@@ -26,32 +26,44 @@ namespace
|
||||
{
|
||||
inline float SineHelperFunction(const float& value)
|
||||
{
|
||||
return sinf(2*M_PI*(value)/256.0f);
|
||||
return sinf(2 * M_PI * (value) / 256.0f);
|
||||
}
|
||||
|
||||
inline float CosineHelperFunction(const float& value)
|
||||
{
|
||||
return cosf(2*M_PI*(value-35)/256.0f);
|
||||
return cosf(2 * M_PI * (value - 35) / 256.0f);
|
||||
}
|
||||
}
|
||||
|
||||
CardGui::CardGui(MTGCardInstance* card, float x, float y) : PlayGuiObject(Height, x, y, false), card(card) {}
|
||||
CardGui::CardGui(MTGCardInstance* card, const Pos& ref) : PlayGuiObject(Height, ref, false), card(card) {}
|
||||
CardGui::CardGui(MTGCardInstance* card, float x, float y) :
|
||||
PlayGuiObject(Height, x, y, false), card(card)
|
||||
{
|
||||
}
|
||||
CardGui::CardGui(MTGCardInstance* card, const Pos& ref) :
|
||||
PlayGuiObject(Height, ref, false), card(card)
|
||||
{
|
||||
}
|
||||
|
||||
CardView::CardView(const SelectorZone owner, MTGCardInstance* card, float x, float y) : CardGui(card, x, y), owner(owner) {
|
||||
CardView::CardView(const SelectorZone owner, MTGCardInstance* card, float x, float y) :
|
||||
CardGui(card, x, y), owner(owner)
|
||||
{
|
||||
const Pos* ref = card->view;
|
||||
while (card)
|
||||
{
|
||||
if (ref == card->view) card->view = this;
|
||||
if (ref == card->view)
|
||||
card->view = this;
|
||||
card = card->next;
|
||||
}
|
||||
}
|
||||
|
||||
CardView::CardView(const SelectorZone owner, MTGCardInstance* card, const Pos& ref) : CardGui(card, ref), owner(owner) {
|
||||
CardView::CardView(const SelectorZone owner, MTGCardInstance* card, const Pos& ref) :
|
||||
CardGui(card, ref), owner(owner)
|
||||
{
|
||||
const Pos* r = card->view;
|
||||
while (card)
|
||||
{
|
||||
if (r == card->view) card->view = this;
|
||||
if (r == card->view)
|
||||
card->view = this;
|
||||
card = card->next;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +81,7 @@ void CardGui::DrawCard(const Pos& inPosition, int inMode)
|
||||
|
||||
void CardGui::DrawCard(MTGCard* inCard, const Pos& inPosition, int inMode)
|
||||
{
|
||||
switch(inMode)
|
||||
switch (inMode)
|
||||
{
|
||||
case DrawMode::kNormal:
|
||||
RenderBig(inCard, inPosition);
|
||||
@@ -82,7 +94,6 @@ void CardGui::DrawCard(MTGCard* inCard, const Pos& inPosition, int inMode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CardGui::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
@@ -91,33 +102,39 @@ void CardGui::Render()
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
|
||||
TargetChooser * tc = NULL;
|
||||
if (game) tc = game->getCurrentTargetChooser();
|
||||
if (game)
|
||||
tc = game->getCurrentTargetChooser();
|
||||
|
||||
bool alternate = true;
|
||||
JQuad * quad = resources.RetrieveCard(card,CACHE_THUMB);
|
||||
JQuad * quad = resources.RetrieveCard(card, CACHE_THUMB);
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
//On pcs we render the big image if the thumbnail is not available
|
||||
if (!quad) quad = resources.RetrieveCard(card);
|
||||
#endif
|
||||
if (quad) alternate = false;
|
||||
else quad = AlternateThumbQuad(card);
|
||||
if (quad)
|
||||
alternate = false;
|
||||
else
|
||||
quad = AlternateThumbQuad(card);
|
||||
|
||||
float cardScale = quad ? 40 / quad->mHeight : 1;
|
||||
float scale = actZ * cardScale;
|
||||
|
||||
JQuad* shadow = NULL;
|
||||
if (actZ > 1) {
|
||||
if (actZ > 1)
|
||||
{
|
||||
shadow = resources.GetQuad("shadow");
|
||||
shadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,255,255,255));
|
||||
renderer->RenderQuad(shadow, actX + (actZ-1)*15, actY + (actZ-1)*15, actT, 28*actZ/16, 40*actZ/16);
|
||||
renderer->RenderQuad(shadow, actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
|
||||
}
|
||||
|
||||
if (quad) {
|
||||
if (quad)
|
||||
{
|
||||
quad->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
|
||||
renderer->RenderQuad(quad, actX, actY, actT, scale, scale);
|
||||
}
|
||||
|
||||
if (alternate) {
|
||||
if (alternate)
|
||||
{
|
||||
mFont->SetColor(ARGB(static_cast<unsigned char>(actA), 0, 0, 0));
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE * 0.5f * actZ);
|
||||
mFont->DrawString(_(card->getName()), actX - actZ * Width / 2 + 1, actY - actZ * Height / 2 + 1);
|
||||
@@ -135,101 +152,148 @@ void CardGui::Render()
|
||||
else if (card->hasSubtype("island"))
|
||||
icon = resources.GetQuad("c_blue");
|
||||
|
||||
|
||||
if (icon){
|
||||
if (icon)
|
||||
{
|
||||
icon->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
|
||||
renderer->RenderQuad(icon, actX, actY, 0);
|
||||
icon->SetColor(ARGB(255,255,255,255)); //Putting color back as this quad is shared
|
||||
}
|
||||
|
||||
}
|
||||
//draws the numbers power/toughness
|
||||
if (card->isCreature()){
|
||||
//draws the numbers power/toughness
|
||||
if (card->isCreature())
|
||||
{
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
char buffer[200];
|
||||
sprintf(buffer, "%i/%i",card->power,card->life);
|
||||
renderer->FillRect(actX - (12*actZ) , actY + 6* actZ, 25*actZ, 12*actZ, ARGB(((static_cast<unsigned char>(actA))/2),0,0,0));
|
||||
sprintf(buffer, "%i/%i", card->power, card->life);
|
||||
renderer->FillRect(actX - (12 * actZ), actY + 6 * actZ, 25 * actZ, 12 * actZ,
|
||||
ARGB(((static_cast<unsigned char>(actA))/2),0,0,0));
|
||||
mFont->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
|
||||
mFont->SetScale(actZ);
|
||||
mFont->DrawString(buffer, actX - 10*actZ , actY + 8*actZ);
|
||||
mFont->DrawString(buffer, actX - 10 * actZ, actY + 8 * actZ);
|
||||
mFont->SetScale(1);
|
||||
}
|
||||
|
||||
if (card->counters->mCount > 0) {
|
||||
if (card->counters->mCount > 0)
|
||||
{
|
||||
unsigned c = -1;
|
||||
for (int i = 0; i < card->counters->mCount; i++) {
|
||||
if (card->counters->counters[i]->name != "") c = i; break;
|
||||
for (int i = 0; i < card->counters->mCount; i++)
|
||||
{
|
||||
if (card->counters->counters[i]->name != "")
|
||||
c = i;
|
||||
break;
|
||||
}
|
||||
if (c + 1) {
|
||||
if (c + 1)
|
||||
{
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
char buffer[200];
|
||||
sprintf(buffer, "%i",card->counters->counters[0]->nb);
|
||||
sprintf(buffer, "%i", card->counters->counters[0]->nb);
|
||||
mFont->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
|
||||
mFont->SetScale(actZ);
|
||||
mFont->DrawString(buffer, actX - 10*actZ , actY -(12 * actZ));
|
||||
mFont->DrawString(buffer, actX - 10 * actZ, actY - (12 * actZ));
|
||||
mFont->SetScale(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (tc && !tc->canTarget(card)) {
|
||||
if (!shadow) shadow = resources.GetQuad("shadow");
|
||||
if (tc && !tc->canTarget(card))
|
||||
{
|
||||
if (!shadow)
|
||||
shadow = resources.GetQuad("shadow");
|
||||
shadow->SetColor(ARGB(200,255,255,255));
|
||||
renderer->RenderQuad(shadow, actX, actY, actT, (28*actZ + 1)/16 , 40*actZ/16);
|
||||
renderer->RenderQuad(shadow, actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16);
|
||||
}
|
||||
|
||||
PlayGuiObject::Render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
JQuad * CardGui::AlternateThumbQuad(MTGCard * card){
|
||||
JQuad * CardGui::AlternateThumbQuad(MTGCard * card)
|
||||
{
|
||||
JQuad * q;
|
||||
|
||||
if(card->data->countColors() > 1){
|
||||
if (card->data->countColors() > 1)
|
||||
{
|
||||
q = resources.RetrieveTempQuad("gold_thumb.jpg");
|
||||
}
|
||||
else{
|
||||
switch(card->data->getColor())
|
||||
else
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT : q = resources.RetrieveTempQuad("artifact_thumb.jpg");break;
|
||||
case Constants::MTG_COLOR_GREEN: q = resources.RetrieveTempQuad("green_thumb.jpg");break;
|
||||
case Constants::MTG_COLOR_BLUE : q = resources.RetrieveTempQuad("blue_thumb.jpg");break;
|
||||
case Constants::MTG_COLOR_RED : q = resources.RetrieveTempQuad("red_thumb.jpg");break;
|
||||
case Constants::MTG_COLOR_BLACK: q = resources.RetrieveTempQuad("black_thumb.jpg");break;
|
||||
case Constants::MTG_COLOR_WHITE: q = resources.RetrieveTempQuad("white_thumb.jpg");break;
|
||||
case Constants::MTG_COLOR_LAND : q = resources.RetrieveTempQuad("land_thumb.jpg");break;
|
||||
default: q = resources.RetrieveTempQuad("gold_thumb.jpg");break;
|
||||
switch (card->data->getColor())
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT:
|
||||
q = resources.RetrieveTempQuad("artifact_thumb.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_GREEN:
|
||||
q = resources.RetrieveTempQuad("green_thumb.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLUE:
|
||||
q = resources.RetrieveTempQuad("blue_thumb.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_RED:
|
||||
q = resources.RetrieveTempQuad("red_thumb.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLACK:
|
||||
q = resources.RetrieveTempQuad("black_thumb.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_WHITE:
|
||||
q = resources.RetrieveTempQuad("white_thumb.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_LAND:
|
||||
q = resources.RetrieveTempQuad("land_thumb.jpg");
|
||||
break;
|
||||
default:
|
||||
q = resources.RetrieveTempQuad("gold_thumb.jpg");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(q && q->mTex)
|
||||
q->SetHotSpot(static_cast<float>(q->mTex->mWidth/2),static_cast<float>(q->mTex->mHeight/2));
|
||||
if (q && q->mTex)
|
||||
q->SetHotSpot(static_cast<float> (q->mTex->mWidth / 2), static_cast<float> (q->mTex->mHeight / 2));
|
||||
return q;
|
||||
}
|
||||
|
||||
void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
|
||||
{
|
||||
// Draw the "unknown" card model
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
JQuad * q;
|
||||
|
||||
float x = pos.actX;
|
||||
|
||||
if(card->data->countColors() > 1) {
|
||||
q = resources.RetrieveTempQuad("gold.jpg");
|
||||
} else {
|
||||
switch(card->data->getColor())
|
||||
if (card->data->countColors() > 1)
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT: q = resources.RetrieveTempQuad("artifact.jpg");break;
|
||||
case Constants::MTG_COLOR_GREEN: q = resources.RetrieveTempQuad("green.jpg");break;
|
||||
case Constants::MTG_COLOR_BLUE : q = resources.RetrieveTempQuad("blue.jpg");break;
|
||||
case Constants::MTG_COLOR_RED : q = resources.RetrieveTempQuad("red.jpg");break;
|
||||
case Constants::MTG_COLOR_BLACK: q = resources.RetrieveTempQuad("black.jpg");break;
|
||||
case Constants::MTG_COLOR_WHITE: q = resources.RetrieveTempQuad("white.jpg");break;
|
||||
case Constants::MTG_COLOR_LAND: q = resources.RetrieveTempQuad("land.jpg");break;
|
||||
default: q = resources.RetrieveTempQuad("gold.jpg");break;
|
||||
q = resources.RetrieveTempQuad("gold.jpg");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (card->data->getColor())
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT:
|
||||
q = resources.RetrieveTempQuad("artifact.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_GREEN:
|
||||
q = resources.RetrieveTempQuad("green.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLUE:
|
||||
q = resources.RetrieveTempQuad("blue.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_RED:
|
||||
q = resources.RetrieveTempQuad("red.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLACK:
|
||||
q = resources.RetrieveTempQuad("black.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_WHITE:
|
||||
q = resources.RetrieveTempQuad("white.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_LAND:
|
||||
q = resources.RetrieveTempQuad("land.jpg");
|
||||
break;
|
||||
default:
|
||||
q = resources.RetrieveTempQuad("gold.jpg");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(q && q->mTex){
|
||||
q->SetHotSpot(static_cast<float>(q->mTex->mWidth/2),static_cast<float>(q->mTex->mHeight/2));
|
||||
if (q && q->mTex)
|
||||
{
|
||||
q->SetHotSpot(static_cast<float> (q->mTex->mWidth / 2), static_cast<float> (q->mTex->mHeight / 2));
|
||||
|
||||
float scale = pos.actZ * 250 / q->mHeight;
|
||||
q->SetColor(ARGB((int)pos.actA,255,255,255));
|
||||
@@ -247,7 +311,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
float w = font->GetStringWidth(name) * kWidthScaleFactor * pos.actZ;
|
||||
if (w > BigWidth - 30)
|
||||
font->SetScale((BigWidth - 30) / w);
|
||||
font->DrawString(name, x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (25 - BigHeight / 2)*pos.actZ);
|
||||
font->DrawString(name, x + (22 - BigWidth / 2) * pos.actZ, pos.actY + (25 - BigHeight / 2) * pos.actZ);
|
||||
}
|
||||
|
||||
// Write the description
|
||||
@@ -257,7 +321,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
unsigned i = 0;
|
||||
unsigned h = neofont ? 14 : 11;
|
||||
for (std::vector<string>::const_iterator it = txt.begin(); it != txt.end(); ++it, ++i)
|
||||
font->DrawString(it->c_str(), x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (-BigHeight/2 + 80 + h * i)*pos.actZ);
|
||||
font->DrawString(it->c_str(), x + (22 - BigWidth / 2) * pos.actZ, pos.actY + (-BigHeight / 2 + 80 + h * i) * pos.actZ);
|
||||
}
|
||||
|
||||
// Write the strength
|
||||
@@ -266,7 +330,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
char buffer[32];
|
||||
sprintf(buffer, "%i/%i", card->data->power, card->data->toughness);
|
||||
float w = font->GetStringWidth(buffer) * kWidthScaleFactor;
|
||||
font->DrawString(buffer, x + (65 - w / 2)*pos.actZ, pos.actY + (106)*pos.actZ);
|
||||
font->DrawString(buffer, x + (65 - w / 2) * pos.actZ, pos.actY + (106) * pos.actZ);
|
||||
}
|
||||
|
||||
// Mana
|
||||
@@ -279,17 +343,25 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
float yOffset = -112;
|
||||
while ((h = manacost->getHybridCost(j)))
|
||||
{
|
||||
float scale = pos.actZ * 0.05f * cosf(2*M_PI*((float)t)/256.0f);
|
||||
float scale = pos.actZ * 0.05f * cosf(2 * M_PI * ((float) t) / 256.0f);
|
||||
|
||||
if (scale < 0)
|
||||
{
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float)t))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)t))*pos.actZ, 0, 0.4f + scale, 0.4f + scale);
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float)v))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)v))*pos.actZ, 0, 0.4f - scale, 0.4f - scale);
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
|
||||
+ scale);
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
|
||||
- scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (- 12 * j + 75 + 3 * SineHelperFunction((float)v))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)v))*pos.actZ, 0, 0.4f - scale, 0.4f - scale);
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (- 12 * j + 75 + 3 * SineHelperFunction((float)t))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)t))*pos.actZ, 0, 0.4f + scale, 0.4f + scale);
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
|
||||
- scale);
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
|
||||
+ scale);
|
||||
}
|
||||
++j;
|
||||
}
|
||||
@@ -297,7 +369,8 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
{
|
||||
for (int cost = manacost->getCost(i); cost > 0; --cost)
|
||||
{
|
||||
renderer->RenderQuad(manaIcons[i], x + (-12*j + 75)*pos.actZ, pos.actY + (yOffset)*pos.actZ, 0, 0.4f * pos.actZ, 0.4f * pos.actZ);
|
||||
renderer->RenderQuad(manaIcons[i], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f
|
||||
* pos.actZ, 0.4f * pos.actZ);
|
||||
++j;
|
||||
}
|
||||
}
|
||||
@@ -306,9 +379,10 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
{
|
||||
char buffer[10];
|
||||
sprintf(buffer, "%d", cost);
|
||||
renderer->RenderQuad(manaIcons[0], x + (- 12*j + 75)*pos.actZ, pos.actY +(yOffset)*pos.actZ, 0, 0.4f * pos.actZ, 0.4f * pos.actZ);
|
||||
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
|
||||
0.4f * pos.actZ);
|
||||
float w = font->GetStringWidth(buffer);
|
||||
font->DrawString(buffer, x +(- 12*j + 76 - w/2)*pos.actZ, pos.actY + (yOffset - 5)*pos.actZ);
|
||||
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
|
||||
++j;
|
||||
}
|
||||
//Has X?
|
||||
@@ -316,9 +390,10 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
{
|
||||
char buffer[10];
|
||||
sprintf(buffer, "X");
|
||||
renderer->RenderQuad(manaIcons[0], x + (- 12*j + 75)*pos.actZ, pos.actY +(yOffset)*pos.actZ, 0, 0.4f * pos.actZ, 0.4f * pos.actZ);
|
||||
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
|
||||
0.4f * pos.actZ);
|
||||
float w = font->GetStringWidth(buffer);
|
||||
font->DrawString(buffer, x +(- 12*j + 76 - w/2)*pos.actZ, pos.actY + (yOffset - 5)*pos.actZ);
|
||||
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,29 +402,33 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
string s = "";
|
||||
for (int i = card->data->types.size() - 1; i > 0; --i)
|
||||
{
|
||||
if(card->data->basicAbilities[Constants::CHANGELING]){// this avoids drawing the list of subtypes on changeling cards.
|
||||
if (card->data->basicAbilities[Constants::CHANGELING])
|
||||
{// this avoids drawing the list of subtypes on changeling cards.
|
||||
s += _("Shapeshifter - ");
|
||||
break;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
s += _(Subtypes::subtypesList->find(card->data->types[i]));
|
||||
s += _(" - ");
|
||||
}
|
||||
}
|
||||
if(card->data->types.size())
|
||||
if (card->data->types.size())
|
||||
s += _(Subtypes::subtypesList->find(card->data->types[0]));
|
||||
else
|
||||
{
|
||||
DebugTrace("Typeless card: " << setlist[card->setId].c_str() << card->data->getName() << card->getId());
|
||||
DebugTrace ("Typeless card: " << setlist[card->setId].c_str() << card->data->getName() << card->getId());
|
||||
}
|
||||
|
||||
font->DrawString(s.c_str(), x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (49 - BigHeight / 2)*pos.actZ);
|
||||
}
|
||||
}
|
||||
|
||||
//expansion and rarity
|
||||
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
|
||||
{
|
||||
//expansion and rarity
|
||||
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
|
||||
{
|
||||
char buf[512];
|
||||
switch(card->getRarity()){
|
||||
switch(card->getRarity())
|
||||
{
|
||||
case Constants::RARITY_M:
|
||||
sprintf(buf,_("%s Mythic").c_str(),setlist[card->setId].c_str());
|
||||
break;
|
||||
@@ -388,15 +467,16 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos){
|
||||
break; //Leave black
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
font->SetScale(backup_scale);
|
||||
}
|
||||
|
||||
font->SetScale(backup_scale);
|
||||
}
|
||||
|
||||
void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
|
||||
{
|
||||
|
||||
if (!quad) return;
|
||||
if (!quad)
|
||||
return;
|
||||
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
JQuad * q;
|
||||
@@ -404,23 +484,43 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
float x = pos.actX;
|
||||
float displayScale = 250 / BigHeight;
|
||||
|
||||
if(card->data->countColors() > 1) {
|
||||
q = resources.RetrieveTempQuad("gold.jpg");
|
||||
} else {
|
||||
switch(card->data->getColor())
|
||||
if (card->data->countColors() > 1)
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT: q = resources.RetrieveTempQuad("artifact.jpg");break;
|
||||
case Constants::MTG_COLOR_GREEN: q = resources.RetrieveTempQuad("green.jpg");break;
|
||||
case Constants::MTG_COLOR_BLUE : q = resources.RetrieveTempQuad("blue.jpg");break;
|
||||
case Constants::MTG_COLOR_RED : q = resources.RetrieveTempQuad("red.jpg");break;
|
||||
case Constants::MTG_COLOR_BLACK: q = resources.RetrieveTempQuad("black.jpg");break;
|
||||
case Constants::MTG_COLOR_WHITE: q = resources.RetrieveTempQuad("white.jpg");break;
|
||||
case Constants::MTG_COLOR_LAND: q = resources.RetrieveTempQuad("land.jpg");break;
|
||||
default: q = resources.RetrieveTempQuad("gold.jpg");break;
|
||||
q = resources.RetrieveTempQuad("gold.jpg");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (card->data->getColor())
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT:
|
||||
q = resources.RetrieveTempQuad("artifact.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_GREEN:
|
||||
q = resources.RetrieveTempQuad("green.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLUE:
|
||||
q = resources.RetrieveTempQuad("blue.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_RED:
|
||||
q = resources.RetrieveTempQuad("red.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLACK:
|
||||
q = resources.RetrieveTempQuad("black.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_WHITE:
|
||||
q = resources.RetrieveTempQuad("white.jpg");
|
||||
break;
|
||||
case Constants::MTG_COLOR_LAND:
|
||||
q = resources.RetrieveTempQuad("land.jpg");
|
||||
break;
|
||||
default:
|
||||
q = resources.RetrieveTempQuad("gold.jpg");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(q && q->mTex){
|
||||
q->SetHotSpot(static_cast<float>(q->mTex->mWidth/2), static_cast<float>(q->mTex->mHeight/2));
|
||||
if (q && q->mTex)
|
||||
{
|
||||
q->SetHotSpot(static_cast<float> (q->mTex->mWidth / 2), static_cast<float> (q->mTex->mHeight / 2));
|
||||
|
||||
float scale = pos.actZ * displayScale * BigHeight / q->mHeight;
|
||||
q->SetColor(ARGB((int)pos.actA,255,255,255));
|
||||
@@ -434,11 +534,12 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
quad->SetColor(ARGB((int)pos.actA,255,255,255));
|
||||
float imgScale = pos.actZ * (displayScale * (BigWidth - 15)) / quad->mWidth;
|
||||
float imgY = pos.actY - (20 * imgScale);
|
||||
if (nbTextLines > 6) {
|
||||
if (nbTextLines > 6)
|
||||
{
|
||||
imgY -= 10 * imgScale;
|
||||
imgScale *= 0.75;
|
||||
}
|
||||
renderer->RenderQuad(quad, x, imgY , pos.actT, imgScale, imgScale);
|
||||
renderer->RenderQuad(quad, x, imgY, pos.actT, imgScale, imgScale);
|
||||
|
||||
// Write the title
|
||||
WFont * font = resources.GetWFont(Fonts::MAGIC_FONT);
|
||||
@@ -452,17 +553,17 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
float w = font->GetStringWidth(name) * kWidthScaleFactor * pos.actZ;
|
||||
if (w > BigWidth - 30)
|
||||
font->SetScale((BigWidth - 30) / w);
|
||||
font->DrawString(name, x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (25 - BigHeight / 2)*pos.actZ);
|
||||
font->DrawString(name, x + (22 - BigWidth / 2) * pos.actZ, pos.actY + (25 - BigHeight / 2) * pos.actZ);
|
||||
}
|
||||
|
||||
// Write the description
|
||||
{
|
||||
font->SetScale(kWidthScaleFactor * pos.actZ);
|
||||
float imgBottom = imgY + (imgScale * quad->mHeight/2);
|
||||
float imgBottom = imgY + (imgScale * quad->mHeight / 2);
|
||||
unsigned i = 0;
|
||||
unsigned h = neofont ? 14 : 11;
|
||||
for (std::vector<string>::const_iterator it = txt.begin(); it != txt.end(); ++it, ++i)
|
||||
font->DrawString(it->c_str(), x + (22 - BigWidth / 2)*pos.actZ, imgBottom + (h * i*pos.actZ));
|
||||
font->DrawString(it->c_str(), x + (22 - BigWidth / 2) * pos.actZ, imgBottom + (h * i * pos.actZ));
|
||||
}
|
||||
|
||||
// Write the strength
|
||||
@@ -471,7 +572,7 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
char buffer[32];
|
||||
sprintf(buffer, "%i/%i", card->data->power, card->data->toughness);
|
||||
float w = font->GetStringWidth(buffer) * kWidthScaleFactor;
|
||||
font->DrawString(buffer, x + (65 - w / 2)*pos.actZ, pos.actY + (106)*pos.actZ);
|
||||
font->DrawString(buffer, x + (65 - w / 2) * pos.actZ, pos.actY + (106) * pos.actZ);
|
||||
}
|
||||
|
||||
// Mana
|
||||
@@ -484,17 +585,25 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
float yOffset = -112;
|
||||
while ((h = manacost->getHybridCost(j)))
|
||||
{
|
||||
float scale = pos.actZ * 0.05f * cosf(2*M_PI*((float)t)/256.0f);
|
||||
float scale = pos.actZ * 0.05f * cosf(2 * M_PI * ((float) t) / 256.0f);
|
||||
|
||||
if (scale < 0)
|
||||
{
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float)t))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)t))*pos.actZ, 0, 0.4f + scale, 0.4f + scale);
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float)v))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)v))*pos.actZ, 0, 0.4f - scale, 0.4f - scale);
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
|
||||
+ scale);
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
|
||||
- scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (- 12 * j + 75 + 3 * SineHelperFunction((float)v))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)v))*pos.actZ, 0, 0.4f - scale, 0.4f - scale);
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (- 12 * j + 75 + 3 * SineHelperFunction((float)t))*pos.actZ, pos.actY + (yOffset + 3 * CosineHelperFunction((float)t))*pos.actZ, 0, 0.4f + scale, 0.4f + scale);
|
||||
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
|
||||
- scale);
|
||||
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
|
||||
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
|
||||
+ scale);
|
||||
}
|
||||
++j;
|
||||
}
|
||||
@@ -502,7 +611,8 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
{
|
||||
for (int cost = manacost->getCost(i); cost > 0; --cost)
|
||||
{
|
||||
renderer->RenderQuad(manaIcons[i], x + (-12*j + 75)*pos.actZ, pos.actY + (yOffset)*pos.actZ, 0, 0.4f * pos.actZ, 0.4f * pos.actZ);
|
||||
renderer->RenderQuad(manaIcons[i], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f
|
||||
* pos.actZ, 0.4f * pos.actZ);
|
||||
++j;
|
||||
}
|
||||
}
|
||||
@@ -511,9 +621,10 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
{
|
||||
char buffer[10];
|
||||
sprintf(buffer, "%d", cost);
|
||||
renderer->RenderQuad(manaIcons[0], x + (- 12*j + 75)*pos.actZ, pos.actY +(yOffset)*pos.actZ, 0, 0.4f * pos.actZ, 0.4f * pos.actZ);
|
||||
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
|
||||
0.4f * pos.actZ);
|
||||
float w = font->GetStringWidth(buffer);
|
||||
font->DrawString(buffer, x +(- 12*j + 76 - w/2)*pos.actZ, pos.actY + (yOffset - 5)*pos.actZ);
|
||||
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
|
||||
++j;
|
||||
}
|
||||
//Has X?
|
||||
@@ -521,9 +632,10 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
{
|
||||
char buffer[10];
|
||||
sprintf(buffer, "X");
|
||||
renderer->RenderQuad(manaIcons[0], x + (- 12*j + 75)*pos.actZ, pos.actY +(yOffset)*pos.actZ, 0, 0.4f * pos.actZ, 0.4f * pos.actZ);
|
||||
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
|
||||
0.4f * pos.actZ);
|
||||
float w = font->GetStringWidth(buffer);
|
||||
font->DrawString(buffer, x +(- 12*j + 76 - w/2)*pos.actZ, pos.actY + (yOffset - 5)*pos.actZ);
|
||||
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,21 +647,22 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
s += _(Subtypes::subtypesList->find(card->data->types[i]));
|
||||
s += _(" - ");
|
||||
}
|
||||
if(card->data->types.size())
|
||||
if (card->data->types.size())
|
||||
s += _(Subtypes::subtypesList->find(card->data->types[0]));
|
||||
else
|
||||
{
|
||||
DebugTrace("Typeless card: " << setlist[card->setId].c_str() << card->data->getName() << card->getId());
|
||||
DebugTrace ("Typeless card: " << setlist[card->setId].c_str() << card->data->getName() << card->getId());
|
||||
}
|
||||
|
||||
font->DrawString(s.c_str(), x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (49 - BigHeight / 2)*pos.actZ);
|
||||
}
|
||||
}
|
||||
|
||||
//expansion and rarity
|
||||
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
|
||||
{
|
||||
//expansion and rarity
|
||||
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
|
||||
{
|
||||
char buf[512];
|
||||
switch(card->getRarity()){
|
||||
switch(card->getRarity())
|
||||
{
|
||||
case Constants::RARITY_M:
|
||||
sprintf(buf,_("%s Mythic").c_str(),setlist[card->setId].c_str());
|
||||
break;
|
||||
@@ -588,25 +701,29 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) {
|
||||
break; //Leave black
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
font->SetScale(backup_scale);
|
||||
}
|
||||
|
||||
void CardGui::AlternateRenderBig(const Pos& pos){
|
||||
AlternateRender(card,pos);
|
||||
font->SetScale(backup_scale);
|
||||
}
|
||||
|
||||
void CardGui::AlternateRenderBig(const Pos& pos)
|
||||
{
|
||||
AlternateRender(card, pos);
|
||||
RenderCountersBig(pos);
|
||||
}
|
||||
|
||||
//Renders a big card on screen. Defaults to the "alternate" rendering if no image is found
|
||||
void CardGui::RenderBig(MTGCard* card, const Pos& pos){
|
||||
void CardGui::RenderBig(MTGCard* card, const Pos& pos)
|
||||
{
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
|
||||
float x = pos.actX;
|
||||
|
||||
JQuad * quad = resources.RetrieveCard(card);
|
||||
if (quad){
|
||||
if (quad->mHeight < quad->mWidth) {
|
||||
if (quad)
|
||||
{
|
||||
if (quad->mHeight < quad->mWidth)
|
||||
{
|
||||
return TinyCropRender(card, pos, quad);
|
||||
}
|
||||
quad->SetColor(ARGB(255,255,255,255));
|
||||
@@ -617,7 +734,7 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos){
|
||||
|
||||
//No card found, attempt to render the thumbnail instead (better than nothing, even if it gets super stretched)
|
||||
JQuad * q;
|
||||
if ((q = resources.RetrieveCard(card,CACHE_THUMB)))
|
||||
if ((q = resources.RetrieveCard(card, CACHE_THUMB)))
|
||||
{
|
||||
float scale = pos.actZ * 250 / q->mHeight;
|
||||
q->SetColor(ARGB(255,255,255,255));
|
||||
@@ -626,56 +743,75 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos){
|
||||
}
|
||||
|
||||
// If we come here, we do not have the picture.
|
||||
AlternateRender(card,pos);
|
||||
AlternateRender(card, pos);
|
||||
}
|
||||
|
||||
void CardGui::RenderCountersBig(const Pos& pos){
|
||||
void CardGui::RenderCountersBig(const Pos& pos)
|
||||
{
|
||||
// Write Named Counters
|
||||
if (card->counters) {
|
||||
if (card->counters)
|
||||
{
|
||||
WFont * font = resources.GetWFont(Fonts::MAGIC_FONT);
|
||||
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
|
||||
font->SetScale(kWidthScaleFactor * pos.actZ);
|
||||
std::vector<string> txt = card->formattedText();
|
||||
unsigned i = txt.size() + 1;
|
||||
Counter * c = NULL;
|
||||
for (int t = 0; t < card->counters->mCount; t++, i++) {
|
||||
if (c) {
|
||||
for (int t = 0; t < card->counters->mCount; t++, i++)
|
||||
{
|
||||
if (c)
|
||||
{
|
||||
c = card->counters->getNext(c);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
c = card->counters->counters[0];
|
||||
}
|
||||
if (c->nb > 0) {
|
||||
if (c->nb > 0)
|
||||
{
|
||||
char buf[512];
|
||||
if (c->name != "") {
|
||||
if (c->name != "")
|
||||
{
|
||||
std::string s = c->name;
|
||||
s[0] = toupper(s[0]);
|
||||
sprintf(buf,_("%s counters: %i").c_str(),s.c_str(),c->nb);
|
||||
}else{
|
||||
sprintf(buf,_("%i/%i counters: %i").c_str(),c->power,c->toughness,c->nb);
|
||||
sprintf(buf, _("%s counters: %i").c_str(), s.c_str(), c->nb);
|
||||
}
|
||||
font->DrawString(buf, pos.actX + (22 - BigWidth / 2)*pos.actZ, pos.actY + (-BigHeight/2 + 80 + 11 * i)*pos.actZ);
|
||||
else
|
||||
{
|
||||
sprintf(buf, _("%i/%i counters: %i").c_str(), c->power, c->toughness, c->nb);
|
||||
}
|
||||
font->DrawString(buf, pos.actX + (22 - BigWidth / 2) * pos.actZ, pos.actY + (-BigHeight / 2 + 80 + 11 * i)
|
||||
* pos.actZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CardGui::RenderBig(const Pos& pos){
|
||||
RenderBig(card,pos);
|
||||
void CardGui::RenderBig(const Pos& pos)
|
||||
{
|
||||
RenderBig(card, pos);
|
||||
RenderCountersBig(pos);
|
||||
}
|
||||
|
||||
MTGCardInstance* CardView::getCard()
|
||||
{
|
||||
return card;
|
||||
}
|
||||
|
||||
|
||||
MTGCardInstance* CardView::getCard() { return card; }
|
||||
|
||||
TransientCardView::TransientCardView(MTGCardInstance* card, float x, float y) : CardGui(card, x, y){}
|
||||
TransientCardView::TransientCardView(MTGCardInstance* card, const Pos& ref) : CardGui(card, ref) {};
|
||||
TransientCardView::TransientCardView(MTGCardInstance* card, float x, float y) :
|
||||
CardGui(card, x, y)
|
||||
{
|
||||
}
|
||||
TransientCardView::TransientCardView(MTGCardInstance* card, const Pos& ref) :
|
||||
CardGui(card, ref)
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
ostream& CardView::toString(ostream& out) const
|
||||
{
|
||||
return (CardGui::toString(out) << " : CardView ::: card : " << card
|
||||
<< "; actX,actY : " << actX << "," << actY << "; t : " << t
|
||||
<< " ; actT : " << actT);
|
||||
return (CardGui::toString(out) << " : CardView ::: card : " << card << "; actX,actY : " << actX << "," << actY << "; t : "
|
||||
<< t << " ; actT : " << actT);
|
||||
}
|
||||
ostream& CardGui::toString(ostream& out) const
|
||||
{
|
||||
|
||||
@@ -8,18 +8,19 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
CardPrimitive::CardPrimitive(){
|
||||
CardPrimitive::CardPrimitive()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
CardPrimitive::CardPrimitive(CardPrimitive * source){
|
||||
for (map<int,int>::const_iterator it = source->basicAbilities.begin(); it != source->basicAbilities.end(); ++it)
|
||||
CardPrimitive::CardPrimitive(CardPrimitive * source)
|
||||
{
|
||||
for (map<int, int>::const_iterator it = source->basicAbilities.begin(); it != source->basicAbilities.end(); ++it)
|
||||
basicAbilities[it->first] = source->basicAbilities[it->first];
|
||||
|
||||
for (size_t i = 0; i< source->types.size(); ++i)
|
||||
for (size_t i = 0; i < source->types.size(); ++i)
|
||||
types.push_back(source->types[i]);
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; ++i)
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; ++i)
|
||||
colors[i] = source->colors[i];
|
||||
manaCost.copy(source->getManaCost());
|
||||
|
||||
@@ -30,13 +31,14 @@ CardPrimitive::CardPrimitive(CardPrimitive * source){
|
||||
toughness = source->toughness;
|
||||
|
||||
magicText = source->magicText;
|
||||
for(map<string,string>::const_iterator it = source->magicTexts.begin(); it != source->magicTexts.end(); ++it)
|
||||
for (map<string, string>::const_iterator it = source->magicTexts.begin(); it != source->magicTexts.end(); ++it)
|
||||
magicTexts[it->first] = source->magicTexts[it->first];
|
||||
spellTargetType = source->spellTargetType;
|
||||
alias = source->alias;
|
||||
}
|
||||
|
||||
int CardPrimitive::init(){
|
||||
int CardPrimitive::init()
|
||||
{
|
||||
basicAbilities.clear();
|
||||
|
||||
types.clear();
|
||||
@@ -57,35 +59,44 @@ const vector<string>& CardPrimitive::formattedText()
|
||||
{
|
||||
std::string s = text;
|
||||
std::string::size_type found = s.find_first_of("{}");
|
||||
while (found!=string::npos)
|
||||
while (found != string::npos)
|
||||
{
|
||||
s[found] = '/';
|
||||
found = s.find_first_of("{}", found + 1);
|
||||
}
|
||||
while (s.length() > 0)
|
||||
{
|
||||
std::string::size_type len = neofont ? 24 :33;
|
||||
std::string::size_type len = neofont ? 24 : 33;
|
||||
std::string::size_type cut = s.find_first_of("., \t)", 0);
|
||||
if (cut >= len || cut == string::npos)
|
||||
{
|
||||
// Fix for single byte character in some complex language like Chinese
|
||||
u8 * src = (u8 *)s.c_str();
|
||||
if (neofont) {
|
||||
u8 * src = (u8 *) s.c_str();
|
||||
if (neofont)
|
||||
{
|
||||
len = 0;
|
||||
std::string::size_type limit = 24;
|
||||
while (*src != 0) {
|
||||
if (*src > 0x80) { // Non-ASCII
|
||||
if (len + 2 > limit && !(((*src & 0xF0) == 0xA0) && ((*(src+1) & 0xF0) == 0xA0))) break;
|
||||
src += 2; len += 2;
|
||||
while (*src != 0)
|
||||
{
|
||||
if (*src > 0x80)
|
||||
{ // Non-ASCII
|
||||
if (len + 2 > limit && !(((*src & 0xF0) == 0xA0) && ((*(src + 1) & 0xF0) == 0xA0)))
|
||||
break;
|
||||
src += 2;
|
||||
len += 2;
|
||||
}
|
||||
else { // ASCII
|
||||
if (*src == '/' && (*(src+1) & 0xF0) == 0xA0) limit += 3;
|
||||
if (len + 1 > limit && (*src == '+' || *src == '-' || *src == '/')) break;
|
||||
src += 1; len += 1;
|
||||
else
|
||||
{ // ASCII
|
||||
if (*src == '/' && (*(src + 1) & 0xF0) == 0xA0)
|
||||
limit += 3;
|
||||
if (len + 1 > limit && (*src == '+' || *src == '-' || *src == '/'))
|
||||
break;
|
||||
src += 1;
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
ftdText.push_back(s.substr(0,len));
|
||||
ftdText.push_back(s.substr(0, len));
|
||||
if (s.length() > len)
|
||||
s = s.substr(len, s.length() - len);
|
||||
else
|
||||
@@ -97,14 +108,15 @@ const vector<string>& CardPrimitive::formattedText()
|
||||
while (newcut < len && newcut != string::npos)
|
||||
{
|
||||
// neofont use space to separate one line
|
||||
u8 * src = (u8 *)s.c_str();
|
||||
if (neofont && *src > 0x80) break;
|
||||
u8 * src = (u8 *) s.c_str();
|
||||
if (neofont && *src > 0x80)
|
||||
break;
|
||||
cut = newcut;
|
||||
newcut = s.find_first_of("., \t)", newcut + 1);
|
||||
}
|
||||
ftdText.push_back(s.substr(0,cut+1));
|
||||
if (s.length() > cut+1)
|
||||
s = s.substr(cut+1,s.length() - cut - 1);
|
||||
ftdText.push_back(s.substr(0, cut + 1));
|
||||
if (s.length() > cut + 1)
|
||||
s = s.substr(cut + 1, s.length() - cut - 1);
|
||||
else
|
||||
s = "";
|
||||
}
|
||||
@@ -113,199 +125,237 @@ const vector<string>& CardPrimitive::formattedText()
|
||||
return ftdText;
|
||||
}
|
||||
|
||||
|
||||
bool CardPrimitive::isCreature(){
|
||||
bool CardPrimitive::isCreature()
|
||||
{
|
||||
return hasSubtype(Subtypes::TYPE_CREATURE);
|
||||
}
|
||||
bool CardPrimitive::isLand(){
|
||||
bool CardPrimitive::isLand()
|
||||
{
|
||||
return hasSubtype(Subtypes::TYPE_LAND);
|
||||
}
|
||||
bool CardPrimitive::isSpell(){
|
||||
bool CardPrimitive::isSpell()
|
||||
{
|
||||
return (!isCreature() && !isLand());
|
||||
}
|
||||
|
||||
void CardPrimitive::setColor(string _color, int removeAllOthers){
|
||||
if(_color.compare("blue")==0) return setColor(Constants::MTG_COLOR_BLUE,removeAllOthers);
|
||||
if(_color.compare("red")==0) return setColor(Constants::MTG_COLOR_RED,removeAllOthers);
|
||||
if(_color.compare("green")==0) return setColor(Constants::MTG_COLOR_GREEN,removeAllOthers);
|
||||
if(_color.compare("black")==0) return setColor(Constants::MTG_COLOR_BLACK,removeAllOthers);
|
||||
if(_color.compare("white")==0) return setColor(Constants::MTG_COLOR_WHITE,removeAllOthers);
|
||||
if(_color.compare("artifact")==0) return setColor(Constants::MTG_COLOR_ARTIFACT,removeAllOthers);
|
||||
void CardPrimitive::setColor(string _color, int removeAllOthers)
|
||||
{
|
||||
if (_color.compare("blue") == 0)
|
||||
return setColor(Constants::MTG_COLOR_BLUE, removeAllOthers);
|
||||
if (_color.compare("red") == 0)
|
||||
return setColor(Constants::MTG_COLOR_RED, removeAllOthers);
|
||||
if (_color.compare("green") == 0)
|
||||
return setColor(Constants::MTG_COLOR_GREEN, removeAllOthers);
|
||||
if (_color.compare("black") == 0)
|
||||
return setColor(Constants::MTG_COLOR_BLACK, removeAllOthers);
|
||||
if (_color.compare("white") == 0)
|
||||
return setColor(Constants::MTG_COLOR_WHITE, removeAllOthers);
|
||||
if (_color.compare("artifact") == 0)
|
||||
return setColor(Constants::MTG_COLOR_ARTIFACT, removeAllOthers);
|
||||
}
|
||||
|
||||
void CardPrimitive::setColor(int _color, int removeAllOthers){
|
||||
void CardPrimitive::setColor(int _color, int removeAllOthers)
|
||||
{
|
||||
if (removeAllOthers)
|
||||
for (int i=0; i<Constants::MTG_NB_COLORS; i++) colors[i] = 0;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
colors[i] = 0;
|
||||
colors[_color] = 1;
|
||||
}
|
||||
|
||||
void CardPrimitive::removeColor(int _color){
|
||||
void CardPrimitive::removeColor(int _color)
|
||||
{
|
||||
colors[_color] = 0;
|
||||
}
|
||||
|
||||
int CardPrimitive::getColor(){
|
||||
for (int i=1; i<Constants::MTG_NB_COLORS; i++)
|
||||
if (colors[i]) return i;
|
||||
int CardPrimitive::getColor()
|
||||
{
|
||||
for (int i = 1; i < Constants::MTG_NB_COLORS; i++)
|
||||
if (colors[i])
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CardPrimitive::hasColor(int color){
|
||||
int CardPrimitive::hasColor(int color)
|
||||
{
|
||||
return (colors[color]);
|
||||
}
|
||||
|
||||
int CardPrimitive::countColors(){
|
||||
int CardPrimitive::countColors()
|
||||
{
|
||||
int result = 0;
|
||||
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; ++i)
|
||||
if (hasColor(i)) ++result;
|
||||
if (hasColor(i))
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
|
||||
void CardPrimitive::setManaCost(string s){
|
||||
void CardPrimitive::setManaCost(string s)
|
||||
{
|
||||
ManaCost::parseManaCost(s, &manaCost);
|
||||
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; i++){
|
||||
if (manaCost.hasColor(i)){
|
||||
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; i++)
|
||||
{
|
||||
if (manaCost.hasColor(i))
|
||||
{
|
||||
setColor(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CardPrimitive::setType(const string& _type_text){
|
||||
void CardPrimitive::setType(const string& _type_text)
|
||||
{
|
||||
setSubtype(_type_text);
|
||||
}
|
||||
|
||||
void CardPrimitive::addType(char * _type_text){
|
||||
void CardPrimitive::addType(char * _type_text)
|
||||
{
|
||||
setSubtype(_type_text);
|
||||
}
|
||||
|
||||
void CardPrimitive::setSubtype(const string& value){
|
||||
void CardPrimitive::setSubtype(const string& value)
|
||||
{
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
addType(id);
|
||||
}
|
||||
|
||||
void CardPrimitive::addType(int id){
|
||||
void CardPrimitive::addType(int id)
|
||||
{
|
||||
types.push_back(id);
|
||||
}
|
||||
|
||||
|
||||
//TODO Definitely move some of these functions to CardInstance. There is no reason to remove a type from an CardPrimitive since they represent the Database
|
||||
//Removes a type from the types of a given card
|
||||
//If removeAll is true, removes all occurences of this type, otherwise only removes the first occurence
|
||||
int CardPrimitive::removeType(string value, int removeAll){
|
||||
int CardPrimitive::removeType(string value, int removeAll)
|
||||
{
|
||||
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
return removeType(id, removeAll);
|
||||
}
|
||||
|
||||
int CardPrimitive::removeType(int id, int removeAll){
|
||||
int CardPrimitive::removeType(int id, int removeAll)
|
||||
{
|
||||
int result = 0;
|
||||
for (int i = types.size() -1 ; i >=0; i--){
|
||||
if (types[i] == id){
|
||||
types.erase(types.begin()+i);
|
||||
for (int i = types.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if (types[i] == id)
|
||||
{
|
||||
types.erase(types.begin() + i);
|
||||
result++;
|
||||
if (!removeAll) return result;
|
||||
if (!removeAll)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void CardPrimitive::setText(const string& value){
|
||||
void CardPrimitive::setText(const string& value)
|
||||
{
|
||||
text = value;
|
||||
}
|
||||
|
||||
const char * CardPrimitive::getText(){
|
||||
const char * CardPrimitive::getText()
|
||||
{
|
||||
return text.c_str();
|
||||
}
|
||||
|
||||
void CardPrimitive::addMagicText(string value){
|
||||
void CardPrimitive::addMagicText(string value)
|
||||
{
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
||||
if (magicText.size()) magicText.append("\n");
|
||||
if (magicText.size())
|
||||
magicText.append("\n");
|
||||
magicText.append(value);
|
||||
}
|
||||
|
||||
void CardPrimitive::addMagicText(string value, string key){
|
||||
void CardPrimitive::addMagicText(string value, string key)
|
||||
{
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
||||
if (magicTexts[key].size()) magicTexts[key].append("\n");
|
||||
if (magicTexts[key].size())
|
||||
magicTexts[key].append("\n");
|
||||
magicTexts[key].append(value);
|
||||
}
|
||||
|
||||
void CardPrimitive::setName(const string& value) {
|
||||
void CardPrimitive::setName(const string& value)
|
||||
{
|
||||
name = value;
|
||||
lcname = value;
|
||||
std::transform(lcname.begin(), lcname.end(), lcname.begin(), ::tolower);
|
||||
//This is a bug fix for plague rats and the "foreach ability"
|
||||
//Right now we add names as types, so that they get recognized
|
||||
if (lcname.at(value.length()-1) == 's') Subtypes::subtypesList->find(lcname);
|
||||
if (lcname.at(value.length() - 1) == 's')
|
||||
Subtypes::subtypesList->find(lcname);
|
||||
}
|
||||
|
||||
const string CardPrimitive::getName() const{
|
||||
const string CardPrimitive::getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
const string CardPrimitive::getLCName() const{
|
||||
const string CardPrimitive::getLCName() const
|
||||
{
|
||||
return lcname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ManaCost* CardPrimitive::getManaCost(){
|
||||
ManaCost* CardPrimitive::getManaCost()
|
||||
{
|
||||
return &manaCost;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CardPrimitive::hasType(int _type){
|
||||
for (size_t i = 0; i<types.size(); i++)
|
||||
bool CardPrimitive::hasType(int _type)
|
||||
{
|
||||
for (size_t i = 0; i < types.size(); i++)
|
||||
if (types[i] == _type)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CardPrimitive::hasSubtype(int _subtype){
|
||||
bool CardPrimitive::hasSubtype(int _subtype)
|
||||
{
|
||||
return hasType(_subtype);
|
||||
}
|
||||
|
||||
bool CardPrimitive::hasType(const char * _type){
|
||||
bool CardPrimitive::hasType(const char * _type)
|
||||
{
|
||||
int id = Subtypes::subtypesList->find(_type);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
bool CardPrimitive::hasSubtype(const char * _subtype){
|
||||
bool CardPrimitive::hasSubtype(const char * _subtype)
|
||||
{
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
bool CardPrimitive::hasSubtype(string _subtype){
|
||||
bool CardPrimitive::hasSubtype(string _subtype)
|
||||
{
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
int CardPrimitive::has(int basicAbility){
|
||||
int CardPrimitive::has(int basicAbility)
|
||||
{
|
||||
return basicAbilities[basicAbility];
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// Creature specific
|
||||
//---------------------------------------------
|
||||
void CardPrimitive::setPower(int _power){
|
||||
void CardPrimitive::setPower(int _power)
|
||||
{
|
||||
power = _power;
|
||||
}
|
||||
|
||||
int CardPrimitive::getPower(){
|
||||
int CardPrimitive::getPower()
|
||||
{
|
||||
return power;
|
||||
}
|
||||
|
||||
void CardPrimitive::setToughness(int _toughness){
|
||||
void CardPrimitive::setToughness(int _toughness)
|
||||
{
|
||||
toughness = _toughness;
|
||||
}
|
||||
|
||||
int CardPrimitive::getToughness(){
|
||||
int CardPrimitive::getToughness()
|
||||
{
|
||||
return toughness;
|
||||
}
|
||||
|
||||
+264
-101
@@ -16,35 +16,80 @@ using std::cout;
|
||||
#undef True
|
||||
#endif
|
||||
|
||||
struct Left : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{ return ref->x - test->x > fabs(ref->y - test->y); } };
|
||||
struct Right : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{ return test->x - ref->x > fabs(ref->y - test->y); } };
|
||||
struct Up : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{ return ref->y - test->y > fabs(ref->x - test->x); } };
|
||||
struct Down : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{ return test->y - ref->y > fabs(ref->x - test->x); } };
|
||||
struct Diff : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{ return ref != test; } };
|
||||
struct True : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{ return true; } };
|
||||
struct Left: public Exp
|
||||
{
|
||||
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{
|
||||
return ref->x - test->x > fabs(ref->y - test->y);
|
||||
}
|
||||
};
|
||||
struct Right: public Exp
|
||||
{
|
||||
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{
|
||||
return test->x - ref->x > fabs(ref->y - test->y);
|
||||
}
|
||||
};
|
||||
struct Up: public Exp
|
||||
{
|
||||
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{
|
||||
return ref->y - test->y > fabs(ref->x - test->x);
|
||||
}
|
||||
};
|
||||
struct Down: public Exp
|
||||
{
|
||||
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{
|
||||
return test->y - ref->y > fabs(ref->x - test->x);
|
||||
}
|
||||
};
|
||||
struct Diff: public Exp
|
||||
{
|
||||
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{
|
||||
return ref != test;
|
||||
}
|
||||
};
|
||||
struct True: public Exp
|
||||
{
|
||||
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
CardSelector::SelectorMemory::SelectorMemory(PlayGuiObject* object) :
|
||||
object(object)
|
||||
{
|
||||
if (object)
|
||||
{
|
||||
x = object->x;
|
||||
y = object->y;
|
||||
}
|
||||
}
|
||||
CardSelector::SelectorMemory::SelectorMemory()
|
||||
{
|
||||
object = NULL;
|
||||
x = y = 0;
|
||||
}
|
||||
|
||||
CardSelector::SelectorMemory::SelectorMemory(PlayGuiObject* object) : object(object) { if (object) { x = object->x; y = object->y; } }
|
||||
CardSelector::SelectorMemory::SelectorMemory() { object = NULL; x = y = 0; }
|
||||
|
||||
|
||||
CardSelector::CardSelector(DuelLayers* duel) : active(NULL), duel(duel), limitor(NULL), bigpos(300, 150, 1.0, 0.0, 220) {}
|
||||
CardSelector::CardSelector(DuelLayers* duel) :
|
||||
active(NULL), duel(duel), limitor(NULL), bigpos(300, 150, 1.0, 0.0, 220)
|
||||
{
|
||||
}
|
||||
|
||||
void CardSelector::Add(CardSelector::Target* target)
|
||||
{
|
||||
if (NULL == active)
|
||||
if (NULL == limitor || limitor->select(active))
|
||||
active = target;
|
||||
CardView* c = dynamic_cast<CardView*>(target);
|
||||
if (c) c->zoom = 1.0f;
|
||||
c = dynamic_cast<CardView*>(active);
|
||||
if (c) c->zoom = 1.4f;
|
||||
CardView* c = dynamic_cast<CardView*> (target);
|
||||
if (c)
|
||||
c->zoom = 1.0f;
|
||||
c = dynamic_cast<CardView*> (active);
|
||||
if (c)
|
||||
c->zoom = 1.4f;
|
||||
cards.push_back(target);
|
||||
}
|
||||
|
||||
@@ -55,55 +100,84 @@ void CardSelector::Remove(CardSelector::Target* card)
|
||||
{
|
||||
if (active == *it)
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.0f;
|
||||
active = closest<Diff>(cards, limitor, active);
|
||||
c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f;
|
||||
CardView* c = dynamic_cast<CardView*> (active);
|
||||
if (c)
|
||||
c->zoom = 1.0f;
|
||||
active = closest<Diff> (cards, limitor, active);
|
||||
c = dynamic_cast<CardView*> (active);
|
||||
if (c)
|
||||
c->zoom = 1.4f;
|
||||
}
|
||||
if (active == *it) active = NULL;
|
||||
if (active == *it)
|
||||
active = NULL;
|
||||
cards.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CardSelector::Target* CardSelector::fetchMemory(SelectorMemory& memory) {
|
||||
if (NULL == memory.object) return NULL;
|
||||
CardSelector::Target* CardSelector::fetchMemory(SelectorMemory& memory)
|
||||
{
|
||||
if (NULL == memory.object)
|
||||
return NULL;
|
||||
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
if (*it == memory.object) {
|
||||
if (*it == memory.object)
|
||||
{
|
||||
if ((NULL == limitor) || (limitor->select(memory.object)))
|
||||
return memory.object;
|
||||
else break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
// We come here if the card is not in the selector any more, or if
|
||||
// it is there but it is now refused by the limitor.
|
||||
return closest<True>(cards, limitor, memory.x, memory.y);
|
||||
return closest<True> (cards, limitor, memory.x, memory.y);
|
||||
}
|
||||
|
||||
void CardSelector::Push() {
|
||||
void CardSelector::Push()
|
||||
{
|
||||
memoryStack.push(SelectorMemory(active));
|
||||
}
|
||||
|
||||
void CardSelector::Pop() {
|
||||
void CardSelector::Pop()
|
||||
{
|
||||
Target* oldactive = active;
|
||||
if (!memoryStack.empty()) {
|
||||
if (!memoryStack.empty())
|
||||
{
|
||||
active = fetchMemory(memoryStack.top());
|
||||
memoryStack.pop();
|
||||
CardView::SelectorZone oldowner;
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = CardView::nullZone;
|
||||
if (CardView::nullZone != oldowner) lasts[oldowner] = SelectorMemory(oldactive);
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive))
|
||||
oldowner = q->owner;
|
||||
else
|
||||
oldowner = CardView::nullZone;
|
||||
if (CardView::nullZone != oldowner)
|
||||
lasts[oldowner] = SelectorMemory(oldactive);
|
||||
}
|
||||
if (active != oldactive) {
|
||||
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0f; } //Is this needed, I think it is one in Leaving(0) ?
|
||||
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f; } //Is this needed, I think it is one in Entering() ?
|
||||
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active) active->Entering();
|
||||
if (active != oldactive)
|
||||
{
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (oldactive);
|
||||
if (c)
|
||||
c->zoom = 1.0f;
|
||||
} //Is this needed, I think it is one in Leaving(0) ?
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (active);
|
||||
if (c)
|
||||
c->zoom = 1.4f;
|
||||
} //Is this needed, I think it is one in Entering() ?
|
||||
if (oldactive)
|
||||
oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active)
|
||||
active->Entering();
|
||||
}
|
||||
}
|
||||
|
||||
bool CardSelector::CheckUserInput(JButton key)
|
||||
{
|
||||
if (!active) {
|
||||
if (!active)
|
||||
{
|
||||
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
if ((NULL == limitor) || (limitor->select(*it))) {
|
||||
if ((NULL == limitor) || (limitor->select(*it)))
|
||||
{
|
||||
active = *it;
|
||||
active->Entering();
|
||||
return true;
|
||||
@@ -111,7 +185,8 @@ bool CardSelector::CheckUserInput(JButton key)
|
||||
return true;
|
||||
}
|
||||
Target* oldactive = active;
|
||||
switch (key) {
|
||||
switch (key)
|
||||
{
|
||||
case JGE_BTN_SEC:
|
||||
GameObserver::GetInstance()->cancelCurrentAction();
|
||||
return true;
|
||||
@@ -120,20 +195,20 @@ bool CardSelector::CheckUserInput(JButton key)
|
||||
return true;
|
||||
break;
|
||||
case JGE_BTN_LEFT:
|
||||
active = closest<Left>(cards, limitor, active);
|
||||
active = closest<Left> (cards, limitor, active);
|
||||
break;
|
||||
case JGE_BTN_RIGHT:
|
||||
active = closest<Right>(cards, limitor, active);
|
||||
active = closest<Right> (cards, limitor, active);
|
||||
break;
|
||||
case JGE_BTN_UP:
|
||||
active = closest<Up>(cards, limitor, active);
|
||||
active = closest<Up> (cards, limitor, active);
|
||||
break;
|
||||
case JGE_BTN_DOWN:
|
||||
active = closest<Down>(cards, limitor, active);
|
||||
active = closest<Down> (cards, limitor, active);
|
||||
break;
|
||||
case JGE_BTN_CANCEL:
|
||||
mDrawMode = (mDrawMode+1) % DrawMode::kNumDrawModes;
|
||||
if(mDrawMode == DrawMode::kText)
|
||||
mDrawMode = (mDrawMode + 1) % DrawMode::kNumDrawModes;
|
||||
if (mDrawMode == DrawMode::kText)
|
||||
options[Options::DISABLECARDS].number = 1;
|
||||
else
|
||||
options[Options::DISABLECARDS].number = 0;
|
||||
@@ -141,20 +216,44 @@ bool CardSelector::CheckUserInput(JButton key)
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (active != oldactive) {
|
||||
if (active != oldactive)
|
||||
{
|
||||
CardView::SelectorZone oldowner, owner;
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = CardView::nullZone;
|
||||
if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = CardView::nullZone;
|
||||
if (oldowner != owner) {
|
||||
if (CardView::nullZone != owner) {
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive))
|
||||
oldowner = q->owner;
|
||||
else
|
||||
oldowner = CardView::nullZone;
|
||||
if (CardView *q = dynamic_cast<CardView*>(active))
|
||||
owner = q->owner;
|
||||
else
|
||||
owner = CardView::nullZone;
|
||||
if (oldowner != owner)
|
||||
{
|
||||
if (CardView::nullZone != owner)
|
||||
{
|
||||
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
|
||||
switch (key)
|
||||
{
|
||||
case JGE_BTN_LEFT: if (old->x < oldactive->x) active = old; break;
|
||||
case JGE_BTN_RIGHT: if (old->x > oldactive->x) active = old; break;
|
||||
case JGE_BTN_UP: if (old->y < oldactive->y) active = old; break;
|
||||
case JGE_BTN_DOWN: if (old->y > oldactive->y) active = old; break;
|
||||
default: if (old) active = old; break;
|
||||
case JGE_BTN_LEFT:
|
||||
if (old->x < oldactive->x)
|
||||
active = old;
|
||||
break;
|
||||
case JGE_BTN_RIGHT:
|
||||
if (old->x > oldactive->x)
|
||||
active = old;
|
||||
break;
|
||||
case JGE_BTN_UP:
|
||||
if (old->y < oldactive->y)
|
||||
active = old;
|
||||
break;
|
||||
case JGE_BTN_DOWN:
|
||||
if (old->y > oldactive->y)
|
||||
active = old;
|
||||
break;
|
||||
default:
|
||||
if (old)
|
||||
active = old;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lasts[oldowner] = SelectorMemory(oldactive);
|
||||
@@ -164,7 +263,7 @@ bool CardSelector::CheckUserInput(JButton key)
|
||||
{
|
||||
// active card hasn't changed - that means we're probably at an edge of the battlefield.
|
||||
// check if we're not already a selected avatar - if not, select one depending whether we're going up/down.
|
||||
GuiAvatar* avatar = dynamic_cast<GuiAvatar*>(active);
|
||||
GuiAvatar* avatar = dynamic_cast<GuiAvatar*> (active);
|
||||
if (!avatar)
|
||||
{
|
||||
if (key == JGE_BTN_DOWN)
|
||||
@@ -177,20 +276,33 @@ bool CardSelector::CheckUserInput(JButton key)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (active != oldactive) {
|
||||
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0f; }
|
||||
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f; }
|
||||
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active) active->Entering();
|
||||
if (active != oldactive)
|
||||
{
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (oldactive);
|
||||
if (c)
|
||||
c->zoom = 1.0f;
|
||||
}
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (active);
|
||||
if (c)
|
||||
c->zoom = 1.4f;
|
||||
}
|
||||
if (oldactive)
|
||||
oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active)
|
||||
active->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CardSelector::CheckUserInput(int x, int y)
|
||||
{
|
||||
if (!active) {
|
||||
if (!active)
|
||||
{
|
||||
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
if ((NULL == limitor) || (limitor->select(*it))) {
|
||||
if ((NULL == limitor) || (limitor->select(*it)))
|
||||
{
|
||||
active = *it;
|
||||
active->Entering();
|
||||
return true;
|
||||
@@ -198,43 +310,68 @@ bool CardSelector::CheckUserInput(int x, int y)
|
||||
return true;
|
||||
}
|
||||
Target* oldactive = active;
|
||||
active = closest<True>(cards, limitor, static_cast<float>(x), static_cast<float>(y));
|
||||
active = closest<True> (cards, limitor, static_cast<float> (x), static_cast<float> (y));
|
||||
|
||||
if (active != oldactive) {
|
||||
if (active != oldactive)
|
||||
{
|
||||
CardView::SelectorZone oldowner, owner;
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = CardView::nullZone;
|
||||
if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = CardView::nullZone;
|
||||
if (oldowner != owner) {
|
||||
if (CardView::nullZone != owner) {
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive))
|
||||
oldowner = q->owner;
|
||||
else
|
||||
oldowner = CardView::nullZone;
|
||||
if (CardView *q = dynamic_cast<CardView*>(active))
|
||||
owner = q->owner;
|
||||
else
|
||||
owner = CardView::nullZone;
|
||||
if (oldowner != owner)
|
||||
{
|
||||
if (CardView::nullZone != owner)
|
||||
{
|
||||
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
|
||||
if (old) active = old;
|
||||
if (old)
|
||||
active = old;
|
||||
}
|
||||
lasts[oldowner] = SelectorMemory(oldactive);
|
||||
}
|
||||
}
|
||||
if (active != oldactive) {
|
||||
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0f; }
|
||||
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f; }
|
||||
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active) active->Entering();
|
||||
if (active != oldactive)
|
||||
{
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (oldactive);
|
||||
if (c)
|
||||
c->zoom = 1.0f;
|
||||
}
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (active);
|
||||
if (c)
|
||||
c->zoom = 1.4f;
|
||||
}
|
||||
if (oldactive)
|
||||
oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active)
|
||||
active->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CardSelector::Update(float dt) {
|
||||
void CardSelector::Update(float dt)
|
||||
{
|
||||
float boundary = duel->RightBoundary();
|
||||
float position = boundary - CardGui::BigWidth / 2;
|
||||
if (CardView* c = dynamic_cast<CardView*>(active))
|
||||
if ((c->x + CardGui::Width / 2 > position - CardGui::BigWidth / 2) &&
|
||||
(c->x - CardGui::Width / 2 < position + CardGui::BigWidth / 2))
|
||||
if ((c->x + CardGui::Width / 2 > position - CardGui::BigWidth / 2) && (c->x - CardGui::Width / 2 < position
|
||||
+ CardGui::BigWidth / 2))
|
||||
position = CardGui::BigWidth / 2 - 10;
|
||||
if (position < CardGui::BigWidth / 2) position = CardGui::BigWidth / 2;
|
||||
if (position < CardGui::BigWidth / 2)
|
||||
position = CardGui::BigWidth / 2;
|
||||
bigpos.x = position;
|
||||
bigpos.Update(dt);
|
||||
}
|
||||
|
||||
void CardSelector::Render() {
|
||||
if (active) {
|
||||
void CardSelector::Render()
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
active->Render();
|
||||
if (CardView* card = dynamic_cast<CardView*>(active))
|
||||
{
|
||||
@@ -243,46 +380,72 @@ void CardSelector::Render() {
|
||||
}
|
||||
}
|
||||
|
||||
void CardSelector::Limit(LimitorFunctor<PlayGuiObject>* limitor, CardView::SelectorZone destzone) {
|
||||
void CardSelector::Limit(LimitorFunctor<PlayGuiObject>* limitor, CardView::SelectorZone destzone)
|
||||
{
|
||||
this->limitor = limitor;
|
||||
if (limitor && !limitor->select(active)) {
|
||||
if (limitor && !limitor->select(active))
|
||||
{
|
||||
PlayGuiObject* oldactive = active;
|
||||
CardView::SelectorZone oldowner;
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = CardView::nullZone;
|
||||
if (oldowner != destzone) {
|
||||
if (CardView *q = dynamic_cast<CardView*>(oldactive))
|
||||
oldowner = q->owner;
|
||||
else
|
||||
oldowner = CardView::nullZone;
|
||||
if (oldowner != destzone)
|
||||
{
|
||||
if (CardView::nullZone != destzone)
|
||||
if (PlayGuiObject* old = fetchMemory(lasts[destzone]))
|
||||
active = old;
|
||||
lasts[oldowner] = SelectorMemory(oldactive);
|
||||
}
|
||||
|
||||
if (limitor && !limitor->select(active)) {
|
||||
if (limitor && !limitor->select(active))
|
||||
{
|
||||
active = NULL;
|
||||
for (vector<PlayGuiObject*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
if (limitor->select(*it)) {
|
||||
if (limitor->select(*it))
|
||||
{
|
||||
active = *it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (active != oldactive) {
|
||||
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0f; }
|
||||
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f; }
|
||||
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active) active->Entering();
|
||||
if (active != oldactive)
|
||||
{
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (oldactive);
|
||||
if (c)
|
||||
c->zoom = 1.0f;
|
||||
}
|
||||
{
|
||||
CardView* c = dynamic_cast<CardView*> (active);
|
||||
if (c)
|
||||
c->zoom = 1.4f;
|
||||
}
|
||||
if (oldactive)
|
||||
oldactive->Leaving(JGE_BTN_NONE);
|
||||
if (active)
|
||||
active->Entering();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CardSelector::PushLimitor() {
|
||||
if (NULL == limitor) return;
|
||||
void CardSelector::PushLimitor()
|
||||
{
|
||||
if (NULL == limitor)
|
||||
return;
|
||||
CardView::SelectorZone owner;
|
||||
if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = CardView::nullZone;
|
||||
if (CardView *q = dynamic_cast<CardView*>(active))
|
||||
owner = q->owner;
|
||||
else
|
||||
owner = CardView::nullZone;
|
||||
limitorStack.push(make_pair(limitor, owner));
|
||||
}
|
||||
|
||||
void CardSelector::PopLimitor() {
|
||||
if (limitorStack.empty()) return;
|
||||
void CardSelector::PopLimitor()
|
||||
{
|
||||
if (limitorStack.empty())
|
||||
return;
|
||||
Limit(limitorStack.top().first, limitorStack.top().second);
|
||||
limitorStack.pop();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include "Navigator.h"
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
namespace CardSelectorSingleton
|
||||
{
|
||||
static CardSelectorBase* sCardSelectorInstance = NULL;
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
#ifndef _CLOSEST_H_
|
||||
#define _CLOSEST_H_
|
||||
|
||||
template <typename T, typename Target>
|
||||
template<typename T, typename Target>
|
||||
static inline Target* closest(vector<Target*>& cards, Limitor* limitor, Target* ref)
|
||||
{
|
||||
Target* card = ref;
|
||||
float curdist = 1000000.0f; // This is bigger than any possible distance
|
||||
for (typename vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
if (!T::test(ref, (*it))) continue;
|
||||
if ((*it)->actA < 32) continue;
|
||||
if ((NULL != limitor) && (!limitor->select(*it))) continue;
|
||||
if (!T::test(ref, (*it)))
|
||||
continue;
|
||||
if ((*it)->actA < 32)
|
||||
continue;
|
||||
if ((NULL != limitor) && (!limitor->select(*it)))
|
||||
continue;
|
||||
if (ref)
|
||||
{
|
||||
float dist = ((*it)->x - ref->x) * ((*it)->x - ref->x) + ((*it)->y - ref->y) * ((*it)->y - ref->y);
|
||||
@@ -26,15 +29,17 @@ static inline Target* closest(vector<Target*>& cards, Limitor* limitor, Target*
|
||||
return card;
|
||||
}
|
||||
|
||||
template <typename T, typename Target>
|
||||
template<typename T, typename Target>
|
||||
static inline Target* closest(vector<Target*>& cards, Limitor* limitor, float x, float y)
|
||||
{
|
||||
Target* card = NULL;
|
||||
float curdist = 1000000.0f; // This is bigger than any possible distance
|
||||
for (typename vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
if ((*it)->actA < 32) continue;
|
||||
if ((NULL != limitor) && (!limitor->select(*it))) continue;
|
||||
if ((*it)->actA < 32)
|
||||
continue;
|
||||
if ((NULL != limitor) && (!limitor->select(*it)))
|
||||
continue;
|
||||
float dist = ((*it)->x - x) * ((*it)->x - x) + ((*it)->y - y) * ((*it)->y - y);
|
||||
if (dist < curdist)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,18 @@
|
||||
#include "Counters.h"
|
||||
#include "MTGCardInstance.h"
|
||||
|
||||
Counter::Counter(MTGCardInstance * _target, int _power, int _toughness){
|
||||
init(_target,"",_power, _toughness);
|
||||
}
|
||||
Counter::Counter(MTGCardInstance * _target, const char * _name,int _power, int _toughness ){
|
||||
init(_target,_name,_power, _toughness);
|
||||
Counter::Counter(MTGCardInstance * _target, int _power, int _toughness)
|
||||
{
|
||||
init(_target, "", _power, _toughness);
|
||||
}
|
||||
|
||||
int Counter::init(MTGCardInstance * _target,const char * _name, int _power, int _toughness){
|
||||
Counter::Counter(MTGCardInstance * _target, const char * _name, int _power, int _toughness)
|
||||
{
|
||||
init(_target, _name, _power, _toughness);
|
||||
}
|
||||
|
||||
int Counter::init(MTGCardInstance * _target, const char * _name, int _power, int _toughness)
|
||||
{
|
||||
target = _target;
|
||||
name = _name;
|
||||
power = _power;
|
||||
@@ -19,72 +23,92 @@ int Counter::init(MTGCardInstance * _target,const char * _name, int _power, int
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Counter::sameAs(const char * _name, int _power, int _toughness){
|
||||
if (power == 0 && toughness == 0) return (name.compare(_name) == 0);
|
||||
bool Counter::sameAs(const char * _name, int _power, int _toughness)
|
||||
{
|
||||
if (power == 0 && toughness == 0)
|
||||
return (name.compare(_name) == 0);
|
||||
return (power == _power && toughness == _toughness);
|
||||
}
|
||||
|
||||
bool Counter::cancels(int _power, int _toughness){
|
||||
if (power == 0 && toughness == 0) return false;
|
||||
bool Counter::cancels(int _power, int _toughness)
|
||||
{
|
||||
if (power == 0 && toughness == 0)
|
||||
return false;
|
||||
return (power == -_power && toughness == -_toughness);
|
||||
}
|
||||
|
||||
int Counter::added(){
|
||||
if (power != 0 || toughness != 0){
|
||||
target->power+= power;
|
||||
int Counter::added()
|
||||
{
|
||||
if (power != 0 || toughness != 0)
|
||||
{
|
||||
target->power += power;
|
||||
target->addToToughness(toughness);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Counter::removed(){
|
||||
if (power != 0 || toughness != 0){
|
||||
target->power-= power;
|
||||
int Counter::removed()
|
||||
{
|
||||
if (power != 0 || toughness != 0)
|
||||
{
|
||||
target->power -= power;
|
||||
target->addToToughness(-toughness);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Counters::Counters(MTGCardInstance * _target):target(_target){
|
||||
Counters::Counters(MTGCardInstance * _target) :
|
||||
target(_target)
|
||||
{
|
||||
mCount = 0;
|
||||
}
|
||||
Counters::~Counters(){
|
||||
for (int i = 0; i < mCount; i++){
|
||||
Counters::~Counters()
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
SAFE_DELETE(counters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int Counters::addCounter(const char * _name,int _power, int _toughness){
|
||||
for (int i = 0; i < mCount; i++){
|
||||
if (counters[i]->cancels( _power,_toughness) && counters[i]->nb > 0){
|
||||
int Counters::addCounter(const char * _name, int _power, int _toughness)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (counters[i]->cancels(_power, _toughness) && counters[i]->nb > 0)
|
||||
{
|
||||
counters[i]->removed();
|
||||
counters[i]->nb--;
|
||||
return mCount;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < mCount; i++){
|
||||
if (counters[i]->sameAs(_name, _power,_toughness)){
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (counters[i]->sameAs(_name, _power, _toughness))
|
||||
{
|
||||
counters[i]->added();
|
||||
counters[i]->nb++;
|
||||
return mCount;
|
||||
}
|
||||
}
|
||||
Counter * counter = NEW Counter(target,_name, _power, _toughness);
|
||||
Counter * counter = NEW Counter(target, _name, _power, _toughness);
|
||||
counters[mCount] = counter;
|
||||
counter->added();
|
||||
mCount++;
|
||||
return mCount;
|
||||
}
|
||||
|
||||
int Counters::addCounter(int _power, int _toughness){
|
||||
return addCounter("",_power, _toughness);
|
||||
int Counters::addCounter(int _power, int _toughness)
|
||||
{
|
||||
return addCounter("", _power, _toughness);
|
||||
}
|
||||
|
||||
int Counters::init(){
|
||||
for (int i = mCount-1; i >= 0; i--){
|
||||
while (counters[i]->nb >= 1) {
|
||||
int Counters::init()
|
||||
{
|
||||
for (int i = mCount - 1; i >= 0; i--)
|
||||
{
|
||||
while (counters[i]->nb >= 1)
|
||||
{
|
||||
counters[i]->removed();
|
||||
counters[i]->nb--;
|
||||
}
|
||||
@@ -92,10 +116,14 @@ int Counters::init(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Counters::removeCounter(const char * _name,int _power, int _toughness){
|
||||
for (int i = 0; i < mCount; i++){
|
||||
if (counters[i]->sameAs(_name, _power,_toughness)){
|
||||
if (counters[i]->nb < 1) return 0;
|
||||
int Counters::removeCounter(const char * _name, int _power, int _toughness)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (counters[i]->sameAs(_name, _power, _toughness))
|
||||
{
|
||||
if (counters[i]->nb < 1)
|
||||
return 0;
|
||||
counters[i]->removed();
|
||||
counters[i]->nb--;
|
||||
return mCount;
|
||||
@@ -104,28 +132,38 @@ int Counters::removeCounter(const char * _name,int _power, int _toughness){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Counters::removeCounter(int _power, int _toughness){
|
||||
return removeCounter("",_power, _toughness);
|
||||
int Counters::removeCounter(int _power, int _toughness)
|
||||
{
|
||||
return removeCounter("", _power, _toughness);
|
||||
}
|
||||
|
||||
Counter * Counters::hasCounter(const char * _name,int _power, int _toughness){
|
||||
for (int i = 0; i < mCount; i++){
|
||||
if (counters[i]->sameAs(_name, _power,_toughness)){
|
||||
if (counters[i]->nb > 0) return counters[i];
|
||||
Counter * Counters::hasCounter(const char * _name, int _power, int _toughness)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (counters[i]->sameAs(_name, _power, _toughness))
|
||||
{
|
||||
if (counters[i]->nb > 0)
|
||||
return counters[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Counter * Counters::hasCounter(int _power , int _toughness ){
|
||||
return hasCounter("",_power, _toughness);
|
||||
Counter * Counters::hasCounter(int _power, int _toughness)
|
||||
{
|
||||
return hasCounter("", _power, _toughness);
|
||||
}
|
||||
|
||||
Counter * Counters::getNext(Counter * previous){
|
||||
Counter * Counters::getNext(Counter * previous)
|
||||
{
|
||||
int found = 0;
|
||||
for (int i = 0; i < mCount ; i++){
|
||||
if (found && counters[i]->nb > 0) return counters[i];
|
||||
if (counters[i] == previous) found = 1;
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (found && counters[i]->nb > 0)
|
||||
return counters[i];
|
||||
if (counters[i] == previous)
|
||||
found = 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+174
-101
@@ -11,78 +11,93 @@
|
||||
#include "GameStateShop.h"
|
||||
#include "PlayerData.h"
|
||||
|
||||
CreditBonus::CreditBonus(int _value, string _text){
|
||||
CreditBonus::CreditBonus(int _value, string _text)
|
||||
{
|
||||
value = _value;
|
||||
text = _text;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CreditBonus::Render(float x, float y, WFont * font){
|
||||
void CreditBonus::Render(float x, float y, WFont * font)
|
||||
{
|
||||
char buffer[512];
|
||||
sprintf(buffer, "%s: %i", text.c_str(), value);
|
||||
font->DrawString(buffer,x,y);
|
||||
}
|
||||
font->DrawString(buffer, x, y);
|
||||
}
|
||||
|
||||
Credits::Credits(){
|
||||
Credits::Credits()
|
||||
{
|
||||
unlockedTex = NULL;
|
||||
unlockedQuad = NULL;
|
||||
unlocked = -1;
|
||||
p1 = NULL;
|
||||
p2 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Credits::~Credits(){
|
||||
Credits::~Credits()
|
||||
{
|
||||
resources.Release(unlockedTex);
|
||||
for (unsigned int i = 0; i<bonus.size(); ++i)
|
||||
for (unsigned int i = 0; i < bonus.size(); ++i)
|
||||
if (bonus[i])
|
||||
delete bonus[i];
|
||||
bonus.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
void Credits::compute(Player * _p1, Player * _p2, GameApp * _app)
|
||||
{
|
||||
p1 = _p1;
|
||||
p2 = _p2;
|
||||
app = _app;
|
||||
showMsg = (WRand() % 3);
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (!g->turn) return;
|
||||
if (!g->turn)
|
||||
return;
|
||||
PlayerData * playerdata = NEW PlayerData(app->collection);
|
||||
if (!p1->isAI() && p2->isAI() && p1!= g->gameOver){
|
||||
if (!p1->isAI() && p2->isAI() && p1 != g->gameOver)
|
||||
{
|
||||
gameLength = time(0) - g->startedAt;
|
||||
value = 400;
|
||||
if (app->gameType != GAME_TYPE_CLASSIC) value = 200;
|
||||
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*difficulty, _("Difficulty Bonus"));
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number && difficulty)
|
||||
{
|
||||
CreditBonus * b = NEW CreditBonus(100 * difficulty, _("Difficulty Bonus"));
|
||||
bonus.push_back(b);
|
||||
}
|
||||
|
||||
if (p1->life == 1) {
|
||||
if (p1->life == 1)
|
||||
{
|
||||
CreditBonus * b = NEW CreditBonus(111, _("'Live dangerously and you live right' Bonus"));
|
||||
bonus.push_back(b);
|
||||
}
|
||||
|
||||
int diff = p1->life - p2->life;
|
||||
if (diff < 0) diff = 0;
|
||||
if (diff > 500) diff = 500;
|
||||
if (diff){
|
||||
if (diff < 0)
|
||||
diff = 0;
|
||||
if (diff > 500)
|
||||
diff = 500;
|
||||
if (diff)
|
||||
{
|
||||
CreditBonus * b = NEW CreditBonus(diff, _("Life Delta Bonus"));
|
||||
bonus.push_back(b);
|
||||
}
|
||||
|
||||
if (p1->game->library->nb_cards == 0) {
|
||||
if (p1->game->library->nb_cards == 0)
|
||||
{
|
||||
CreditBonus * b = NEW CreditBonus(391, _("'Decree of Theophilus' Bonus"));
|
||||
bonus.push_back(b);
|
||||
}
|
||||
|
||||
if ((p2->game->library->nb_cards == 0) && p1->game->library->nb_cards) {
|
||||
if ((p2->game->library->nb_cards == 0) && p1->game->library->nb_cards)
|
||||
{
|
||||
CreditBonus * b = NEW CreditBonus(p1->game->library->nb_cards * 3, _("Miller Bonus"));
|
||||
bonus.push_back(b);
|
||||
}
|
||||
|
||||
if (g->turn < 15) {
|
||||
CreditBonus * b = NEW CreditBonus((20 - g->turn)*17, _("'Fast and Furious' Bonus"));
|
||||
if (g->turn < 15)
|
||||
{
|
||||
CreditBonus * b = NEW CreditBonus((20 - g->turn) * 17, _("'Fast and Furious' Bonus"));
|
||||
bonus.push_back(b);
|
||||
}
|
||||
|
||||
@@ -93,7 +108,8 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
|
||||
char buffer[512];
|
||||
|
||||
for (vector<Task*>::iterator it = finishedTasks.begin(); it!=finishedTasks.end(); it++) {
|
||||
for (vector<Task*>::iterator it = finishedTasks.begin(); it != finishedTasks.end(); it++)
|
||||
{
|
||||
sprintf(buffer, _("Task: %s").c_str(), (*it)->getShortDesc().c_str());
|
||||
CreditBonus * b = NEW CreditBonus((*it)->getReward(), buffer);
|
||||
bonus.push_back(b);
|
||||
@@ -101,42 +117,55 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
}
|
||||
// </Tasks handling>
|
||||
|
||||
if (unlocked == -1){
|
||||
if (unlocked == -1)
|
||||
{
|
||||
unlocked = isDifficultyUnlocked();
|
||||
if (unlocked){
|
||||
if (unlocked)
|
||||
{
|
||||
unlockedTex = resources.RetrieveTexture("unlocked.png");
|
||||
unlockedQuad = resources.RetrieveQuad("unlocked.png", 2, 2, 396, 96);
|
||||
goa = (GameOptionAward*) &options[Options::DIFFICULTY_MODE_UNLOCKED];
|
||||
goa->giveAward();
|
||||
options.save();
|
||||
} else if ((unlocked = isMomirUnlocked())) {
|
||||
}
|
||||
else if ((unlocked = isMomirUnlocked()))
|
||||
{
|
||||
unlockedTex = resources.RetrieveTexture("momir_unlocked.png");
|
||||
unlockedQuad = resources.RetrieveQuad("momir_unlocked.png", 2, 2, 396, 96);
|
||||
goa = (GameOptionAward*) &options[Options::MOMIR_MODE_UNLOCKED];
|
||||
goa->giveAward();
|
||||
options.save();
|
||||
} else if ((unlocked = isEvilTwinUnlocked())) {
|
||||
}
|
||||
else if ((unlocked = isEvilTwinUnlocked()))
|
||||
{
|
||||
unlockedTex = resources.RetrieveTexture("eviltwin_unlocked.png");
|
||||
unlockedQuad = resources.RetrieveQuad("eviltwin_unlocked.png", 2, 2, 396, 96);
|
||||
goa = (GameOptionAward*) &options[Options::EVILTWIN_MODE_UNLOCKED];
|
||||
goa->giveAward();
|
||||
options.save();
|
||||
}else if((unlocked = isRandomDeckUnlocked())) {
|
||||
}
|
||||
else if ((unlocked = isRandomDeckUnlocked()))
|
||||
{
|
||||
unlockedTex = resources.RetrieveTexture("randomdeck_unlocked.png");
|
||||
unlockedQuad = resources.RetrieveQuad("randomdeck_unlocked.png", 2, 2, 396, 96);
|
||||
goa = (GameOptionAward*) &options[Options::RANDOMDECK_MODE_UNLOCKED];
|
||||
goa->giveAward();
|
||||
options.save();
|
||||
}else if((unlocked = unlockRandomSet())) {
|
||||
}
|
||||
else if ((unlocked = unlockRandomSet()))
|
||||
{
|
||||
unlockedTex = resources.RetrieveTexture("set_unlocked.png");
|
||||
unlockedQuad = resources.RetrieveQuad("set_unlocked.png", 2, 2, 396, 96);
|
||||
MTGSetInfo * si = setlist.getInfo(unlocked - 1);
|
||||
if(si) unlockedString = si->getName(); //Show the set's pretty name for unlocks.
|
||||
if (si)
|
||||
unlockedString = si->getName(); //Show the set's pretty name for unlocks.
|
||||
}
|
||||
|
||||
if (unlocked && options[Options::SFXVOLUME].number > 0){
|
||||
if (unlocked && options[Options::SFXVOLUME].number > 0)
|
||||
{
|
||||
JSample * sample = resources.RetrieveSample("bonus.wav");
|
||||
if (sample){
|
||||
if (sample)
|
||||
{
|
||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||
}
|
||||
}
|
||||
@@ -144,24 +173,26 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
}
|
||||
|
||||
vector<CreditBonus *>::iterator it;
|
||||
if (bonus.size()){
|
||||
if (bonus.size())
|
||||
{
|
||||
CreditBonus * b = NEW CreditBonus(value, _("Victory"));
|
||||
bonus.insert(bonus.begin(),b);
|
||||
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) {
|
||||
if (playerdata->taskList->getTaskCount() < 6)
|
||||
{
|
||||
playerdata->taskList->addRandomTask();
|
||||
playerdata->taskList->addRandomTask();
|
||||
}
|
||||
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
unlocked = 0;
|
||||
playerdata->taskList->passOneDay();
|
||||
}
|
||||
@@ -170,8 +201,10 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
SAFE_DELETE(playerdata);
|
||||
}
|
||||
|
||||
void Credits::Render(){
|
||||
if (!p1) return;
|
||||
void Credits::Render()
|
||||
{
|
||||
if (!p1)
|
||||
return;
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
WFont * f = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
@@ -184,110 +217,142 @@ void Credits::Render(){
|
||||
f3->SetScale(1);
|
||||
f3->SetColor(ARGB(255,255,255,255));
|
||||
char buffer[512];
|
||||
if (!g->turn){
|
||||
sprintf(buffer, "%s", _("Please check your deck (not enough cards?)").c_str() );
|
||||
}else{
|
||||
if (!p1->isAI() && p2->isAI() ){
|
||||
if (g->gameOver != p1){
|
||||
sprintf (buffer, _("Congratulations! You earn %i credits").c_str(), value);
|
||||
if (unlockedQuad){
|
||||
if (!g->turn)
|
||||
{
|
||||
sprintf(buffer, "%s", _("Please check your deck (not enough cards?)").c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!p1->isAI() && p2->isAI())
|
||||
{
|
||||
if (g->gameOver != p1)
|
||||
{
|
||||
sprintf(buffer, _("Congratulations! You earn %i credits").c_str(), value);
|
||||
if (unlockedQuad)
|
||||
{
|
||||
showMsg = 0;
|
||||
r->RenderQuad(unlockedQuad, 20, 20);
|
||||
}
|
||||
if(unlockedString.size()){
|
||||
f2->DrawString(unlockedString.c_str(),SCREEN_WIDTH/2, 80,JGETEXT_CENTER);
|
||||
if (unlockedString.size())
|
||||
{
|
||||
f2->DrawString(unlockedString.c_str(), SCREEN_WIDTH / 2, 80, JGETEXT_CENTER);
|
||||
}
|
||||
}else{
|
||||
sprintf (buffer, "%s", _("You have been defeated").c_str());
|
||||
}
|
||||
}else{
|
||||
else
|
||||
{
|
||||
sprintf(buffer, "%s", _("You have been defeated").c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int winner = 2;
|
||||
if (g->gameOver !=p1){
|
||||
if (g->gameOver != p1)
|
||||
{
|
||||
winner = 1;
|
||||
}
|
||||
int p0life = p1->life;
|
||||
sprintf(buffer, _("Player %i wins (%i)").c_str(), winner, p0life );
|
||||
sprintf(buffer, _("Player %i wins (%i)").c_str(), winner, p0life);
|
||||
}
|
||||
}
|
||||
|
||||
float y = 130;
|
||||
|
||||
if (showMsg == 1) y = 50;
|
||||
vector<CreditBonus *>:: iterator it;
|
||||
for ( it=bonus.begin() ; it < bonus.end(); ++it){
|
||||
(*it)->Render(10,y,f3);
|
||||
y+=12;
|
||||
if (showMsg == 1)
|
||||
y = 50;
|
||||
vector<CreditBonus *>::iterator it;
|
||||
for (it = bonus.begin(); it < bonus.end(); ++it)
|
||||
{
|
||||
(*it)->Render(10, y, f3);
|
||||
y += 12;
|
||||
}
|
||||
f2->DrawString(buffer, 10, y);
|
||||
y+=15;
|
||||
y += 15;
|
||||
|
||||
//!!
|
||||
if (g->gameOver != p1) {
|
||||
if (g->gameOver != p1)
|
||||
{
|
||||
sprintf(buffer, _("Game length: %i turns (%i seconds)").c_str(), g->turn, this->gameLength);
|
||||
f->DrawString(buffer, 10, y);
|
||||
y += 10;
|
||||
sprintf(buffer, _("Credits per minute: %i").c_str(), (int)(60*value/this->gameLength));
|
||||
sprintf(buffer, _("Credits per minute: %i").c_str(), (int) (60 * value / this->gameLength));
|
||||
f->DrawString(buffer, 10, y);
|
||||
y += 10;
|
||||
showMsg = 0;
|
||||
}
|
||||
|
||||
if (showMsg == 1){
|
||||
f2->DrawString(_("Please support this project!").c_str() ,10,y+15);
|
||||
f->DrawString(_("Wagic is free, open source, and developed on the little free time I have").c_str() ,10,y+30);
|
||||
f->DrawString(_("If you enjoy this game, please consider donating a few bucks").c_str() ,10,y+42);
|
||||
f->DrawString(_("(Seriously, donate or I'll kill this cute little bunny)").c_str() ,10,y+54);
|
||||
f->DrawString(_("Thanks in advance for your support.").c_str() ,10,y+66);
|
||||
f2->DrawString("-> http://wololo.net/wagic" ,10,y+78);
|
||||
if (showMsg == 1)
|
||||
{
|
||||
f2->DrawString(_("Please support this project!").c_str(), 10, y + 15);
|
||||
f->DrawString(_("Wagic is free, open source, and developed on the little free time I have").c_str(), 10, y + 30);
|
||||
f->DrawString(_("If you enjoy this game, please consider donating a few bucks").c_str(), 10, y + 42);
|
||||
f->DrawString(_("(Seriously, donate or I'll kill this cute little bunny)").c_str(), 10, y + 54);
|
||||
f->DrawString(_("Thanks in advance for your support.").c_str(), 10, y + 66);
|
||||
f2->DrawString("-> http://wololo.net/wagic", 10, y + 78);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int Credits::isDifficultyUnlocked(){
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number) return 0;
|
||||
int Credits::isDifficultyUnlocked()
|
||||
{
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number)
|
||||
return 0;
|
||||
int nbAIDecks = 0;
|
||||
int found = 1;
|
||||
int wins = 0;
|
||||
DeckStats * stats = DeckStats::GetInstance();
|
||||
stats->load(p1);
|
||||
while (found){
|
||||
while (found)
|
||||
{
|
||||
found = 0;
|
||||
char buffer[512];
|
||||
char aiSmallDeckName[512];
|
||||
sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(),nbAIDecks+1);
|
||||
if(fileExists(buffer)){
|
||||
sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(), nbAIDecks + 1);
|
||||
if (fileExists(buffer))
|
||||
{
|
||||
found = 1;
|
||||
nbAIDecks++;
|
||||
sprintf(aiSmallDeckName, "ai_baka_deck%i",nbAIDecks);
|
||||
sprintf(aiSmallDeckName, "ai_baka_deck%i", nbAIDecks);
|
||||
int percentVictories = stats->percentVictories(string(aiSmallDeckName));
|
||||
if (percentVictories >=67) wins++;
|
||||
if (wins >= 10) return 1;
|
||||
if (percentVictories >= 67)
|
||||
wins++;
|
||||
if (wins >= 10)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Credits::isMomirUnlocked(){
|
||||
if (options[Options::MOMIR_MODE_UNLOCKED].number) return 0;
|
||||
if (p1->game->inPlay->countByType("land") == 8) return 1;
|
||||
int Credits::isMomirUnlocked()
|
||||
{
|
||||
if (options[Options::MOMIR_MODE_UNLOCKED].number)
|
||||
return 0;
|
||||
if (p1->game->inPlay->countByType("land") == 8)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Credits::isEvilTwinUnlocked(){
|
||||
if (options[Options::EVILTWIN_MODE_UNLOCKED].number) return 0;
|
||||
if (p1->game->inPlay->nb_cards && (p1->game->inPlay->nb_cards == p2->game->inPlay->nb_cards)) return 1;
|
||||
int Credits::isEvilTwinUnlocked()
|
||||
{
|
||||
if (options[Options::EVILTWIN_MODE_UNLOCKED].number)
|
||||
return 0;
|
||||
if (p1->game->inPlay->nb_cards && (p1->game->inPlay->nb_cards == p2->game->inPlay->nb_cards))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Credits::isRandomDeckUnlocked(){
|
||||
if (0 == options[Options::DIFFICULTY].number) return 0;
|
||||
if (options[Options::RANDOMDECK_MODE_UNLOCKED].number) return 0;
|
||||
if (p1->life >= 20 ) return 1;
|
||||
int Credits::isRandomDeckUnlocked()
|
||||
{
|
||||
if (0 == options[Options::DIFFICULTY].number)
|
||||
return 0;
|
||||
if (options[Options::RANDOMDECK_MODE_UNLOCKED].number)
|
||||
return 0;
|
||||
if (p1->life >= 20)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Credits::addCreditBonus(int value){
|
||||
int Credits::addCreditBonus(int value)
|
||||
{
|
||||
PlayerData * playerdata = NEW PlayerData();
|
||||
playerdata->credits += value;
|
||||
playerdata->save();
|
||||
@@ -298,8 +363,9 @@ int Credits::addCreditBonus(int 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) {
|
||||
*/
|
||||
int Credits::addCardToCollection(int cardId, MTGDeck * collection)
|
||||
{
|
||||
return collection->add(cardId);
|
||||
}
|
||||
|
||||
@@ -307,7 +373,8 @@ int Credits::addCardToCollection(int cardId, MTGDeck * collection) {
|
||||
* 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) {
|
||||
int Credits::addCardToCollection(int cardId)
|
||||
{
|
||||
MTGAllCards * ac = GameApp::collection;
|
||||
PlayerData * playerdata = NEW PlayerData(ac);
|
||||
int result = addCardToCollection(cardId, playerdata->collection);
|
||||
@@ -315,9 +382,11 @@ int Credits::addCardToCollection(int cardId) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int Credits::unlockSetByName(string name){
|
||||
int Credits::unlockSetByName(string name)
|
||||
{
|
||||
int setId = setlist.findSet(name);
|
||||
if (setId < 0) return 0;
|
||||
if (setId < 0)
|
||||
return 0;
|
||||
|
||||
GameOptionAward* goa = (GameOptionAward*) &options[Options::optionSet(setId)];
|
||||
goa->giveAward();
|
||||
@@ -326,16 +395,20 @@ int Credits::unlockSetByName(string name){
|
||||
|
||||
}
|
||||
|
||||
int Credits::unlockRandomSet(bool force){
|
||||
int Credits::unlockRandomSet(bool force)
|
||||
{
|
||||
int setId = WRand() % setlist.size();
|
||||
|
||||
if (force) {
|
||||
if (force)
|
||||
{
|
||||
int init = setId;
|
||||
bool found = false;
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (1 != options[Options::optionSet(setId)].number)
|
||||
found = true;
|
||||
else {
|
||||
else
|
||||
{
|
||||
setId++;
|
||||
if (setId == setlist.size())
|
||||
setId = 0;
|
||||
|
||||
+128
-77
@@ -8,53 +8,64 @@
|
||||
#include "WResourceManager.h"
|
||||
#include "GameObserver.h"
|
||||
|
||||
Damage::Damage(MTGCardInstance * source, Damageable * target) {
|
||||
Damage::Damage(MTGCardInstance * source, Damageable * target)
|
||||
{
|
||||
init(source, target, source->getPower(), DAMAGE_OTHER);
|
||||
}
|
||||
|
||||
Damage::Damage(MTGCardInstance * source, Damageable * target, int damage,int _typeOfDamage) {
|
||||
Damage::Damage(MTGCardInstance * source, Damageable * target, int damage, int _typeOfDamage)
|
||||
{
|
||||
init(source, target, damage, _typeOfDamage);
|
||||
}
|
||||
|
||||
void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage, int _typeOfDamage){
|
||||
void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage, int _typeOfDamage)
|
||||
{
|
||||
typeOfDamage = _typeOfDamage;
|
||||
target = _target;
|
||||
source = _source;
|
||||
|
||||
|
||||
if (_damage < 0) _damage = 0; //Negative damages cannot happen
|
||||
if (_damage < 0)
|
||||
_damage = 0; //Negative damages cannot happen
|
||||
damage = _damage;
|
||||
mHeight = 40;
|
||||
type = ACTION_DAMAGE;
|
||||
}
|
||||
|
||||
int Damage::resolve(){
|
||||
if (damage <0) damage = 0; //Negative damages cannot happen
|
||||
int Damage::resolve()
|
||||
{
|
||||
if (damage < 0)
|
||||
damage = 0; //Negative damages cannot happen
|
||||
state = RESOLVED_OK;
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
WEvent * e = NEW WEventDamage(this);
|
||||
//Replacement Effects
|
||||
e = g->replacementEffects->replace(e);
|
||||
if (!e) return 0;
|
||||
WEventDamage * ev = dynamic_cast<WEventDamage*>(e);
|
||||
if (!ev) {
|
||||
if (!e)
|
||||
return 0;
|
||||
WEventDamage * ev = dynamic_cast<WEventDamage*> (e);
|
||||
if (!ev)
|
||||
{
|
||||
g->receiveEvent(e);
|
||||
return 0;
|
||||
}
|
||||
damage = ev->damage->damage;
|
||||
target = ev->damage->target;
|
||||
if (!damage) return 0;
|
||||
if (!damage)
|
||||
return 0;
|
||||
|
||||
//asorbing effects for cards controller-----------
|
||||
//asorbing effects for cards controller-----------
|
||||
|
||||
//reserved for culmulitive absorb ability coding
|
||||
//reserved for culmulitive absorb ability coding
|
||||
|
||||
//prevent next damage-----------------------------
|
||||
if((target)->preventable >= 1) {
|
||||
int preventing =(target)->preventable;
|
||||
for(int k = preventing; k > 0;k--){
|
||||
if ((target)->preventable >= 1)
|
||||
{
|
||||
int preventing = (target)->preventable;
|
||||
for (int k = preventing; k > 0; k--)
|
||||
{
|
||||
//the following keeps preventable from ADDING toughness/life if damage was less then preventable amount.
|
||||
for (int i = damage; i >= 1; i--){
|
||||
for (int i = damage; i >= 1; i--)
|
||||
{
|
||||
(target)->preventable -= 1;
|
||||
damage -= 1;
|
||||
break;//does the redux of damage 1 time, breaks the loop to deincrement preventing and start the loop over.
|
||||
@@ -63,36 +74,46 @@ int Damage::resolve(){
|
||||
}
|
||||
|
||||
//set prevent next damage back to 0 if it is equal to less then 0
|
||||
if((target)->preventable < 0){
|
||||
if ((target)->preventable < 0)
|
||||
{
|
||||
(target)->preventable = 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){
|
||||
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||
if ((_target)->protectedAgainst(source)) damage = 0;
|
||||
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if ((_target)->protectedAgainst(source))
|
||||
damage = 0;
|
||||
//rulings = 10/4/2004 The damage prevention ability works even if it has no counters, as long as some effect keeps its toughness above zero.
|
||||
//these creature are essentially immune to damage. however 0/-1 effects applied through lords or counters can kill them.
|
||||
if ((_target)->has(Constants::PHANTOM)) {
|
||||
if ((_target)->has(Constants::PHANTOM))
|
||||
{
|
||||
damage = 0;
|
||||
(_target)->counters->removeCounter(1,1);
|
||||
(_target)->counters->removeCounter(1, 1);
|
||||
}
|
||||
if ((_target)->has(Constants::ABSORB)) {
|
||||
if ((_target)->has(Constants::ABSORB))
|
||||
{
|
||||
damage -= 1;
|
||||
}
|
||||
if ((_target)->has(Constants::WILTING)) {
|
||||
for (int j = damage; j > 0; j--){
|
||||
(_target)->counters->addCounter(-1,-1);
|
||||
if ((_target)->has(Constants::WILTING))
|
||||
{
|
||||
for (int j = damage; j > 0; j--)
|
||||
{
|
||||
(_target)->counters->addCounter(-1, -1);
|
||||
}
|
||||
damage = 0;
|
||||
}
|
||||
if ((_target)->has(Constants::VIGOR)){
|
||||
for (int j = damage; j > 0; j--){
|
||||
(_target)->counters->addCounter(1,1);
|
||||
if ((_target)->has(Constants::VIGOR))
|
||||
{
|
||||
for (int j = damage; j > 0; j--)
|
||||
{
|
||||
(_target)->counters->addCounter(1, 1);
|
||||
}
|
||||
damage = 0;
|
||||
}
|
||||
if (!damage){
|
||||
if (!damage)
|
||||
{
|
||||
state = RESOLVED_NOK;
|
||||
delete (e);
|
||||
return 0;
|
||||
@@ -102,33 +123,46 @@ int Damage::resolve(){
|
||||
|
||||
int a = damage;
|
||||
|
||||
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE &&
|
||||
(source->has(Constants::WITHER) || source->has(Constants::INFECT))){
|
||||
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE && (source->has(Constants::WITHER) || source->has(
|
||||
Constants::INFECT)))
|
||||
{
|
||||
// Damage for WITHER or poison on creatures. This should probably go in replacement effects
|
||||
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||
for (int i = 0; i < damage; i++){
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
for (int i = 0; i < damage; i++)
|
||||
{
|
||||
_target->counters->addCounter(-1, -1);
|
||||
}
|
||||
|
||||
} else if (target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::INFECT)) {
|
||||
}
|
||||
else if (target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::INFECT))
|
||||
{
|
||||
// Poison on player
|
||||
Player * _target = (Player *)target;
|
||||
Player * _target = (Player *) target;
|
||||
_target->poisonCount += damage;//this will be changed to poison counters.
|
||||
} else if (target->type_as_damageable == DAMAGEABLE_PLAYER &&
|
||||
( source->has(Constants::POISONTOXIC) || source->has(Constants::POISONTWOTOXIC) || source->has(Constants::POISONTHREETOXIC) )) {
|
||||
}
|
||||
else if (target->type_as_damageable == DAMAGEABLE_PLAYER && (source->has(Constants::POISONTOXIC) ||
|
||||
source->has(Constants::POISONTWOTOXIC) || source->has(Constants::POISONTHREETOXIC)))
|
||||
{
|
||||
//Damage + 1, 2, or 3 poison counters on player
|
||||
Player * _target = (Player *)target;
|
||||
Player * _target = (Player *) target;
|
||||
a = target->dealDamage(damage);
|
||||
target->damageCount += damage;
|
||||
if (source->has(Constants::POISONTOXIC)) {
|
||||
if (source->has(Constants::POISONTOXIC))
|
||||
{
|
||||
_target->poisonCount += 1;
|
||||
}else if (source->has(Constants::POISONTWOTOXIC)) {
|
||||
}
|
||||
else if (source->has(Constants::POISONTWOTOXIC))
|
||||
{
|
||||
_target->poisonCount += 2;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
_target->poisonCount += 3;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// "Normal" case,
|
||||
//return the left over amount after effects have been applied to them.
|
||||
a = target->dealDamage(damage);
|
||||
@@ -139,28 +173,35 @@ int Damage::resolve(){
|
||||
g->receiveEvent(e);
|
||||
return a;
|
||||
}
|
||||
void Damage::Render(){
|
||||
void Damage::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
char buffer[200];
|
||||
sprintf(buffer, _("Deals %i damage to").c_str(), damage);
|
||||
mFont->DrawString(buffer, x + 20 , y, JGETEXT_LEFT);
|
||||
mFont->DrawString(buffer, x + 20, y, JGETEXT_LEFT);
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
JQuad * quad = resources.RetrieveCard(source,CACHE_THUMB);
|
||||
if (quad){
|
||||
JQuad * quad = resources.RetrieveCard(source, CACHE_THUMB);
|
||||
if (quad)
|
||||
{
|
||||
float scale = 30 / quad->mHeight;
|
||||
renderer->RenderQuad(quad, x , y , 0,scale,scale);
|
||||
}else{
|
||||
mFont->DrawString(_(source->getName()).c_str(),x,y-15);
|
||||
renderer->RenderQuad(quad, x, y, 0, scale, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
mFont->DrawString(_(source->getName()).c_str(), x, y - 15);
|
||||
}
|
||||
quad = target->getIcon();
|
||||
if (quad){
|
||||
if (quad)
|
||||
{
|
||||
float scale = 30 / quad->mHeight;
|
||||
renderer->RenderQuad(quad, x + 150 , y , 0,scale,scale);
|
||||
}else{
|
||||
renderer->RenderQuad(quad, x + 150, y, 0, scale, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
||||
mFont->DrawString(_(((MTGCardInstance *)target)->getName()).c_str(),x+120,y);
|
||||
mFont->DrawString(_(((MTGCardInstance *) target)->getName()).c_str(), x + 120, y);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -171,43 +212,53 @@ ostream& Damage::toString(ostream& out) const
|
||||
return out;
|
||||
}
|
||||
|
||||
DamageStack::DamageStack() {
|
||||
DamageStack::DamageStack()
|
||||
{
|
||||
currentState = -1;
|
||||
type = ACTION_DAMAGES;
|
||||
}
|
||||
|
||||
|
||||
/* Damage Stack resolve process:
|
||||
1 - apply damages to targets. For each of them, send an event to the GameObserver (for Damage triggers)
|
||||
2 - Once this is done, send a "Damage Stakc Resolved" event to the GameObserver
|
||||
3 - Once that message is received on the DamageStack's side, do the "afterDamage" effects (send to graveyard, etc...)
|
||||
Using events in 2 and 3 guarantees that the "send to graveyard" effect will only apply AFTER Damaged triggers are applied
|
||||
*/
|
||||
int DamageStack::resolve(){
|
||||
for (int i = mCount-1; i>= 0; i--){
|
||||
Damage * damage = (Damage*)mObjects[i];
|
||||
if (damage->state == NOT_RESOLVED) damage->resolve();
|
||||
1 - apply damages to targets. For each of them, send an event to the GameObserver (for Damage triggers)
|
||||
2 - Once this is done, send a "Damage Stakc Resolved" event to the GameObserver
|
||||
3 - Once that message is received on the DamageStack's side, do the "afterDamage" effects (send to graveyard, etc...)
|
||||
Using events in 2 and 3 guarantees that the "send to graveyard" effect will only apply AFTER Damaged triggers are applied
|
||||
*/
|
||||
int DamageStack::resolve()
|
||||
{
|
||||
for (int i = mCount - 1; i >= 0; i--)
|
||||
{
|
||||
Damage * damage = (Damage*) mObjects[i];
|
||||
if (damage->state == NOT_RESOLVED)
|
||||
damage->resolve();
|
||||
}
|
||||
GameObserver::GetInstance()->receiveEvent(NEW WEventDamageStackResolved());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int DamageStack::receiveEvent(WEvent * e) {
|
||||
WEventDamageStackResolved *event = dynamic_cast<WEventDamageStackResolved*>(e);
|
||||
if (!event) return 0;
|
||||
int DamageStack::receiveEvent(WEvent * e)
|
||||
{
|
||||
WEventDamageStackResolved *event = dynamic_cast<WEventDamageStackResolved*> (e);
|
||||
if (!event)
|
||||
return 0;
|
||||
|
||||
for (int i = mCount-1; i>= 0; i--){
|
||||
Damage * damage = (Damage*)mObjects[i];
|
||||
if (damage->state == RESOLVED_OK) damage->target->afterDamage();
|
||||
for (int i = mCount - 1; i >= 0; i--)
|
||||
{
|
||||
Damage * damage = (Damage*) mObjects[i];
|
||||
if (damage->state == RESOLVED_OK)
|
||||
damage->target->afterDamage();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DamageStack::Render(){
|
||||
void DamageStack::Render()
|
||||
{
|
||||
float currenty = y;
|
||||
for (int i= 0; i < mCount; i++){
|
||||
Damage * damage = (Damage*)mObjects[i];
|
||||
if (damage->state == NOT_RESOLVED){
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
Damage * damage = (Damage*) mObjects[i];
|
||||
if (damage->state == NOT_RESOLVED)
|
||||
{
|
||||
damage->x = x;
|
||||
damage->y = currenty;
|
||||
currenty += damage->mHeight;
|
||||
|
||||
@@ -3,40 +3,55 @@
|
||||
#include "DamagerDamaged.h"
|
||||
|
||||
/*
|
||||
Temporary objects that store the damages dealt to/from creatures during the combat phase
|
||||
*/
|
||||
Temporary objects that store the damages dealt to/from creatures during the combat phase
|
||||
*/
|
||||
|
||||
DamagerDamaged::DamagerDamaged(MTGCardInstance* card, float x, float y, bool show, Player * damageSelecter) : TransientCardView(card, x, y), show(show), damageSelecter(damageSelecter) {}
|
||||
DamagerDamaged::DamagerDamaged(MTGCardInstance* card, const Pos& ref, bool show, Player * damageSelecter) : TransientCardView(card, ref), show(show), damageSelecter(damageSelecter) {}
|
||||
DamagerDamaged::DamagerDamaged(MTGCardInstance* card, float x, float y, bool show, Player * damageSelecter) :
|
||||
TransientCardView(card, x, y), show(show), damageSelecter(damageSelecter)
|
||||
{
|
||||
}
|
||||
DamagerDamaged::DamagerDamaged(MTGCardInstance* card, const Pos& ref, bool show, Player * damageSelecter) :
|
||||
TransientCardView(card, ref), show(show), damageSelecter(damageSelecter)
|
||||
{
|
||||
}
|
||||
|
||||
DamagerDamaged::~DamagerDamaged(){}
|
||||
DamagerDamaged::~DamagerDamaged()
|
||||
{
|
||||
}
|
||||
|
||||
int DamagerDamaged::sumDamages(){
|
||||
int DamagerDamaged::sumDamages()
|
||||
{
|
||||
int total = 0;
|
||||
for (vector<Damage>::iterator i = damages.begin(); i != damages.end(); ++i)
|
||||
total += i->damage;
|
||||
return total;
|
||||
}
|
||||
|
||||
bool DamagerDamaged::hasLethalDamage(){
|
||||
bool DamagerDamaged::hasLethalDamage()
|
||||
{
|
||||
return (sumDamages() >= card->life);
|
||||
}
|
||||
|
||||
void DamagerDamaged::addDamage(int damage, DamagerDamaged* source){
|
||||
void DamagerDamaged::addDamage(int damage, DamagerDamaged* source)
|
||||
{
|
||||
for (vector<Damage>::iterator i = damages.begin(); i != damages.end(); ++i)
|
||||
if (i->source == source->card){
|
||||
if (i->source == source->card)
|
||||
{
|
||||
i->damage += damage;
|
||||
if (0 >= i->damage) damages.erase(i);
|
||||
if (0 >= i->damage)
|
||||
damages.erase(i);
|
||||
return;
|
||||
}
|
||||
if (0 < damage) damages.push_back(Damage(source->card, card, damage,DAMAGE_COMBAT));
|
||||
if (0 < damage)
|
||||
damages.push_back(Damage(source->card, card, damage, DAMAGE_COMBAT));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int DamagerDamaged::removeDamagesFrom(DamagerDamaged* source){
|
||||
int DamagerDamaged::removeDamagesFrom(DamagerDamaged* source)
|
||||
{
|
||||
for (vector<Damage>::iterator i = damages.begin(); i != damages.end(); ++i)
|
||||
if (i->source == source->card){
|
||||
if (i->source == source->card)
|
||||
{
|
||||
int damage = i->damage;
|
||||
damages.erase(i);
|
||||
return damage;
|
||||
@@ -57,15 +72,15 @@ void DamagerDamaged::Render(CombatStep mode)
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case BLOCKERS :
|
||||
case TRIGGERS :
|
||||
case ORDER :
|
||||
case BLOCKERS:
|
||||
case TRIGGERS:
|
||||
case ORDER:
|
||||
mFont->SetColor(ARGB(92,255,255,255));
|
||||
break;
|
||||
case FIRST_STRIKE :
|
||||
case END_FIRST_STRIKE :
|
||||
case DAMAGE :
|
||||
case END_DAMAGE :
|
||||
case FIRST_STRIKE:
|
||||
case END_FIRST_STRIKE:
|
||||
case DAMAGE:
|
||||
case END_DAMAGE:
|
||||
mFont->SetColor(ARGB(255, 255, 64, 0));
|
||||
break;
|
||||
}
|
||||
@@ -76,11 +91,17 @@ void DamagerDamaged::Render(CombatStep mode)
|
||||
|
||||
}
|
||||
|
||||
|
||||
AttackerDamaged::AttackerDamaged(MTGCardInstance* card, float x, float y, bool show, Player * damageSelecter) : DamagerDamaged(card, x, y, show, damageSelecter) {}
|
||||
AttackerDamaged::AttackerDamaged(MTGCardInstance* card, const Pos& ref, bool show, Player * damageSelecter) : DamagerDamaged(card, ref, show, damageSelecter) {}
|
||||
|
||||
AttackerDamaged::~AttackerDamaged(){
|
||||
for (vector<DefenserDamaged*>::iterator q = blockers.begin(); q != blockers.end(); ++q)
|
||||
delete(*q);
|
||||
AttackerDamaged::AttackerDamaged(MTGCardInstance* card, float x, float y, bool show, Player * damageSelecter) :
|
||||
DamagerDamaged(card, x, y, show, damageSelecter)
|
||||
{
|
||||
}
|
||||
AttackerDamaged::AttackerDamaged(MTGCardInstance* card, const Pos& ref, bool show, Player * damageSelecter) :
|
||||
DamagerDamaged(card, ref, show, damageSelecter)
|
||||
{
|
||||
}
|
||||
|
||||
AttackerDamaged::~AttackerDamaged()
|
||||
{
|
||||
for (vector<DefenserDamaged*>::iterator q = blockers.begin(); q != blockers.end(); ++q)
|
||||
delete (*q);
|
||||
}
|
||||
|
||||
@@ -5,20 +5,25 @@
|
||||
#include "PriceList.h"
|
||||
#include "WDataSrc.h"
|
||||
|
||||
DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
|
||||
DeckDataWrapper::DeckDataWrapper(MTGDeck * deck)
|
||||
{
|
||||
parent = deck;
|
||||
loadMatches(deck);
|
||||
}
|
||||
|
||||
void DeckDataWrapper::save(){
|
||||
if(parent){
|
||||
void DeckDataWrapper::save()
|
||||
{
|
||||
if (parent)
|
||||
{
|
||||
Rebuild(parent);
|
||||
parent->save();
|
||||
}
|
||||
}
|
||||
|
||||
void DeckDataWrapper::save(string filepath, bool useExpandedCardNames, string &deckTitle, string &deckDesc){
|
||||
if(parent){
|
||||
void DeckDataWrapper::save(string filepath, bool useExpandedCardNames, string &deckTitle, string &deckDesc)
|
||||
{
|
||||
if (parent)
|
||||
{
|
||||
Rebuild(parent);
|
||||
parent->save(filepath, useExpandedCardNames, deckTitle, deckDesc);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
#include "GameApp.h"
|
||||
#include <iomanip>
|
||||
|
||||
DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const char * _title, DeckDataWrapper *_selectedDeck, StatsWrapper *stats)
|
||||
: DeckMenu( id, listener, fontId, _title ), selectedDeck(_selectedDeck), stw( stats )
|
||||
DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const char * _title, DeckDataWrapper *_selectedDeck,
|
||||
StatsWrapper *stats) :
|
||||
DeckMenu(id, listener, fontId, _title), selectedDeck(_selectedDeck), stw(stats)
|
||||
{
|
||||
backgroundName = "DeckEditorMenuBackdrop";
|
||||
|
||||
|
||||
deckTitle = selectedDeck ? selectedDeck->parent->meta_name : "";
|
||||
|
||||
mX = 123;
|
||||
@@ -37,26 +37,26 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const
|
||||
|
||||
float scrollerWidth = 80;
|
||||
SAFE_DELETE(scroller); // need to delete the scroller init in the base class
|
||||
scroller = NEW TextScroller(Fonts::MAIN_FONT, 40 , 230, scrollerWidth, 100, 1, 1);
|
||||
scroller = NEW TextScroller(Fonts::MAIN_FONT, 40, 230, scrollerWidth, 100, 1, 1);
|
||||
|
||||
}
|
||||
|
||||
void DeckEditorMenu::Render()
|
||||
{
|
||||
JRenderer *r = JRenderer::GetInstance();
|
||||
r->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(200,0,0,0));
|
||||
r->FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(200,0,0,0));
|
||||
|
||||
DeckMenu::Render();
|
||||
if ( deckTitle.size() > 0 )
|
||||
if (deckTitle.size() > 0)
|
||||
{
|
||||
WFont *mainFont = resources.GetWFont( Fonts::OPTION_FONT );
|
||||
WFont *mainFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
DWORD currentColor = mainFont->GetColor();
|
||||
mainFont->SetColor( ARGB(255,255,255,255) );
|
||||
mainFont->DrawString( deckTitle.c_str(), statsX + (statsWidth / 2), statsHeight / 2 , JGETEXT_CENTER);
|
||||
mainFont->SetColor( currentColor );
|
||||
mainFont->SetColor(ARGB(255,255,255,255));
|
||||
mainFont->DrawString(deckTitle.c_str(), statsX + (statsWidth / 2), statsHeight / 2, JGETEXT_CENTER);
|
||||
mainFont->SetColor(currentColor);
|
||||
}
|
||||
|
||||
if ( stw && selectedDeck )
|
||||
if (stw && selectedDeck)
|
||||
drawDeckStatistics();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,17 +4,16 @@
|
||||
#include "Player.h"
|
||||
#include <JRenderer.h>
|
||||
|
||||
void DeckManager::updateMetaDataList( vector<DeckMetaData *> * refList, bool isAI )
|
||||
void DeckManager::updateMetaDataList(vector<DeckMetaData *> * refList, bool isAI)
|
||||
{
|
||||
if (refList)
|
||||
{
|
||||
vector<DeckMetaData *> * inputList = isAI? &aiDeckOrderList : &playerDeckOrderList;
|
||||
vector<DeckMetaData *> * inputList = isAI ? &aiDeckOrderList : &playerDeckOrderList;
|
||||
inputList->clear();
|
||||
inputList->assign( refList->begin(), refList -> end() );
|
||||
inputList->assign(refList->begin(), refList -> end());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vector<DeckMetaData *> * DeckManager::getPlayerDeckOrderList()
|
||||
{
|
||||
return &playerDeckOrderList;
|
||||
@@ -25,7 +24,6 @@ vector<DeckMetaData *> * DeckManager::getAIDeckOrderList()
|
||||
return &aiDeckOrderList;
|
||||
}
|
||||
|
||||
|
||||
DeckManager * DeckManager::mInstance = NULL;
|
||||
bool DeckManager::instanceFlag = false;
|
||||
|
||||
@@ -39,10 +37,9 @@ void DeckManager::EndInstance()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeckManager* DeckManager::GetInstance()
|
||||
{
|
||||
if ( !instanceFlag )
|
||||
if (!instanceFlag)
|
||||
{
|
||||
mInstance = NEW DeckManager();
|
||||
instanceFlag = true;
|
||||
@@ -51,14 +48,13 @@ DeckManager* DeckManager::GetInstance()
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
|
||||
// p1 is assumed to be the player you want stats for
|
||||
// p2 is the opponent
|
||||
int DeckManager::getDifficultyRating( Player *statsPlayer, Player *player )
|
||||
int DeckManager::getDifficultyRating(Player *statsPlayer, Player *player)
|
||||
{
|
||||
DeckMetaDataList * metas = DeckMetaDataList::decksMetaData;
|
||||
|
||||
DeckMetaData *meta = metas->get( player->deckFile, statsPlayer );
|
||||
DeckMetaData *meta = metas->get(player->deckFile, statsPlayer);
|
||||
|
||||
return meta->getDifficulty();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ hgeParticleSystem* DeckMenu::stars = NULL;
|
||||
// * descriptive information 125
|
||||
// *** Need to make this configurable in a file somewhere to allow for class reuse
|
||||
|
||||
DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _title, const float& mFontScale): JGuiController(id, listener), fontId(fontId), menuFontScale( mFontScale ) {
|
||||
DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _title, const float& mFontScale) :
|
||||
JGuiController(id, listener), fontId(fontId), menuFontScale(mFontScale)
|
||||
{
|
||||
|
||||
backgroundName = "DeckMenuBackdrop";
|
||||
|
||||
@@ -60,11 +62,11 @@ DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _tit
|
||||
menuInitialized = false;
|
||||
|
||||
float scrollerWidth = 80;
|
||||
scroller = NEW TextScroller(Fonts::MAIN_FONT, 40 , 230, scrollerWidth, 100, 1, 1);
|
||||
scroller = NEW TextScroller(Fonts::MAIN_FONT, 40, 230, scrollerWidth, 100, 1, 1);
|
||||
|
||||
autoTranslate = true;
|
||||
maxItems = 7;
|
||||
mHeight = 2 * kVerticalMargin + ( maxItems * kLineHeight );
|
||||
mHeight = 2 * kVerticalMargin + (maxItems * kLineHeight);
|
||||
|
||||
// we want to cap the deck titles to 15 characters to avoid overflowing deck names
|
||||
title = _(_title);
|
||||
@@ -76,7 +78,7 @@ DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _tit
|
||||
timeOpen = 0;
|
||||
closed = false;
|
||||
|
||||
if ( mFont->GetStringWidth( title.c_str() ) > titleWidth )
|
||||
if (mFont->GetStringWidth(title.c_str()) > titleWidth)
|
||||
titleFontScale = 0.75f;
|
||||
else
|
||||
titleFontScale = 1.0f;
|
||||
@@ -90,7 +92,6 @@ DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _tit
|
||||
updateScroller();
|
||||
}
|
||||
|
||||
|
||||
void DeckMenu::RenderBackground()
|
||||
{
|
||||
ostringstream bgFilename;
|
||||
@@ -100,8 +101,8 @@ void DeckMenu::RenderBackground()
|
||||
if (loadBackground)
|
||||
{
|
||||
JQuad *background = resources.RetrieveTempQuad(bgFilename.str(), TEXTURE_SUB_5551);
|
||||
if ( background )
|
||||
JRenderer::GetInstance()->RenderQuad( background, 0, 0 );
|
||||
if (background)
|
||||
JRenderer::GetInstance()->RenderQuad(background, 0, 0);
|
||||
else
|
||||
loadBackground = false;
|
||||
}
|
||||
@@ -110,10 +111,11 @@ void DeckMenu::RenderBackground()
|
||||
void DeckMenu::initMenuItems()
|
||||
{
|
||||
float sY = mY + kVerticalMargin;
|
||||
for (int i = startId; i < startId + mCount; ++i) {
|
||||
for (int i = startId; i < startId + mCount; ++i)
|
||||
{
|
||||
float y = mY + kVerticalMargin + i * kLineHeight;
|
||||
DeckMenuItem * currentMenuItem = static_cast<DeckMenuItem*>(mObjects[i]);
|
||||
currentMenuItem->Relocate( mX, y );
|
||||
DeckMenuItem * currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
|
||||
currentMenuItem->Relocate(mX, y);
|
||||
if (currentMenuItem->hasFocus())
|
||||
sY = y;
|
||||
}
|
||||
@@ -132,21 +134,26 @@ void DeckMenu::Render()
|
||||
timeOpen = 0;
|
||||
menuInitialized = true;
|
||||
}
|
||||
if (timeOpen < 1) height *= timeOpen > 0 ? timeOpen : -timeOpen;
|
||||
if (timeOpen < 1)
|
||||
height *= timeOpen > 0 ? timeOpen : -timeOpen;
|
||||
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
stars->Render();
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (int i = startId; i < startId + maxItems ; i++){
|
||||
if (i > mCount-1) break;
|
||||
DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*>(mObjects[i]);
|
||||
if ( currentMenuItem->mY - kLineHeight * startId < mY + height - kLineHeight + 7) {
|
||||
if ( currentMenuItem->hasFocus()){
|
||||
// display the avatar image
|
||||
if ( currentMenuItem->imageFilename.size() > 0 )
|
||||
for (int i = startId; i < startId + maxItems; i++)
|
||||
{
|
||||
JQuad * quad = resources.RetrieveTempQuad( currentMenuItem->imageFilename, TEXTURE_SUB_AVATAR );
|
||||
if (i > mCount - 1)
|
||||
break;
|
||||
DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
|
||||
if (currentMenuItem->mY - kLineHeight * startId < mY + height - kLineHeight + 7)
|
||||
{
|
||||
if (currentMenuItem->hasFocus())
|
||||
{
|
||||
// display the avatar image
|
||||
if (currentMenuItem->imageFilename.size() > 0)
|
||||
{
|
||||
JQuad * quad = resources.RetrieveTempQuad(currentMenuItem->imageFilename, TEXTURE_SUB_AVATAR);
|
||||
if (quad)
|
||||
renderer->RenderQuad(quad, avatarX, avatarY);
|
||||
}
|
||||
@@ -157,50 +164,51 @@ void DeckMenu::Render()
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
|
||||
// fill in the statistical portion
|
||||
if ( currentMenuItem->meta )
|
||||
if (currentMenuItem->meta)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Deck: " << currentMenuItem->meta->getName() << endl;
|
||||
oss << currentMenuItem->meta->getStatsSummary();
|
||||
|
||||
mainFont->DrawString( oss.str(), statsX, statsY );
|
||||
mainFont->DrawString(oss.str(), statsX, statsY);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
mFont->SetColor(ARGB(150,255,255,255));
|
||||
}
|
||||
mFont->SetScale( menuFontScale );
|
||||
currentMenuItem->RenderWithOffset(-kLineHeight*startId);
|
||||
mFont->SetScale(menuFontScale);
|
||||
currentMenuItem->RenderWithOffset(-kLineHeight * startId);
|
||||
}
|
||||
}
|
||||
|
||||
RenderBackground();
|
||||
|
||||
|
||||
if (!title.empty())
|
||||
{
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->SetScale( titleFontScale );
|
||||
mFont->SetScale(titleFontScale);
|
||||
mFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER);
|
||||
}
|
||||
mFont->SetScale( 1.0f );
|
||||
mFont->SetScale(1.0f);
|
||||
scroller->Render();
|
||||
|
||||
}
|
||||
|
||||
void DeckMenu::Update(float dt){
|
||||
void DeckMenu::Update(float dt)
|
||||
{
|
||||
JGuiController::Update(dt);
|
||||
if (mCurr > startId + maxItems-1)
|
||||
startId = mCurr - maxItems +1;
|
||||
if (mCurr > startId + maxItems - 1)
|
||||
startId = mCurr - maxItems + 1;
|
||||
else if (mCurr < startId)
|
||||
startId = mCurr;
|
||||
stars->Update(dt);
|
||||
selectionT += 3*dt;
|
||||
selectionT += 3 * dt;
|
||||
selectionY += (selectionTargetY - selectionY) * 8 * dt;
|
||||
|
||||
float starsX = starsOffsetX + ((mWidth - 2 * kHorizontalMargin)*(1+cos(selectionT))/2);
|
||||
float starsY = selectionY + 5 * cos(selectionT*2.35f) + kLineHeight / 2 - kLineHeight * startId;
|
||||
stars->MoveTo( starsX, starsY);
|
||||
float starsX = starsOffsetX + ((mWidth - 2 * kHorizontalMargin) * (1 + cos(selectionT)) / 2);
|
||||
float starsY = selectionY + 5 * cos(selectionT * 2.35f) + kLineHeight / 2 - kLineHeight * startId;
|
||||
stars->MoveTo(starsX, starsY);
|
||||
if (timeOpen < 0)
|
||||
{
|
||||
timeOpen += dt * 10;
|
||||
@@ -220,10 +228,12 @@ void DeckMenu::Update(float dt){
|
||||
scroller->Update(dt);
|
||||
}
|
||||
|
||||
void DeckMenu::Add(int id, const char * text,string desc, bool forceFocus, DeckMetaData * deckMetaData) {
|
||||
DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0, mY + kVerticalMargin + mCount*kLineHeight, (mCount == 0), autoTranslate, deckMetaData);
|
||||
void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, DeckMetaData * deckMetaData)
|
||||
{
|
||||
DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0, mY + kVerticalMargin + mCount * kLineHeight,
|
||||
(mCount == 0), autoTranslate, deckMetaData);
|
||||
Translator * t = Translator::GetInstance();
|
||||
map<string,string>::iterator it = t->deckValues.find(text);
|
||||
map<string, string>::iterator it = t->deckValues.find(text);
|
||||
if (it != t->deckValues.end()) //translate decks desc
|
||||
menuItem->desc = it->second;
|
||||
else
|
||||
@@ -232,9 +242,10 @@ void DeckMenu::Add(int id, const char * text,string desc, bool forceFocus, DeckM
|
||||
JGuiController::Add(menuItem);
|
||||
if (mCount <= maxItems)
|
||||
mHeight += kLineHeight;
|
||||
if (forceFocus){
|
||||
if (forceFocus)
|
||||
{
|
||||
mObjects[mCurr]->Leaving(JGE_BTN_DOWN);
|
||||
mCurr = mCount-1;
|
||||
mCurr = mCount - 1;
|
||||
menuItem->Entering();
|
||||
}
|
||||
}
|
||||
@@ -244,25 +255,25 @@ void DeckMenu::updateScroller()
|
||||
// add all the items from the Tasks db.
|
||||
TaskList taskList;
|
||||
scroller->Reset();
|
||||
for (vector<Task*>::iterator it = taskList.tasks.begin(); it!=taskList.tasks.end(); it++)
|
||||
for (vector<Task*>::iterator it = taskList.tasks.begin(); it != taskList.tasks.end(); it++)
|
||||
{
|
||||
ostringstream taskDescription;
|
||||
taskDescription << "[ " << setw(4) << (*it)->getReward() << " / " << (*it)->getExpiration() << " ] " << (*it)->getDesc() << endl;
|
||||
scroller->Add( taskDescription.str() );
|
||||
taskDescription << "[ " << setw(4) << (*it)->getReward() << " / " << (*it)->getExpiration() << " ] "
|
||||
<< (*it)->getDesc() << endl;
|
||||
scroller->Add(taskDescription.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DeckMenu::Close()
|
||||
{
|
||||
timeOpen = -1.0;
|
||||
stars->Stop(true);
|
||||
}
|
||||
|
||||
|
||||
void DeckMenu::destroy(){
|
||||
void DeckMenu::destroy()
|
||||
{
|
||||
SAFE_DELETE(DeckMenu::stars);
|
||||
}
|
||||
}
|
||||
|
||||
DeckMenu::~DeckMenu()
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define ITEM_PX_WIDTH 190.f
|
||||
|
||||
DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData)
|
||||
: JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
||||
: JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
||||
{
|
||||
if (autoTranslate)
|
||||
mText = _(text);
|
||||
@@ -18,21 +18,20 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f
|
||||
//in the future we might want to replace this with a horizontal scrolling of long strings
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
while (mFont->GetStringWidth(mText.c_str()) > ITEM_PX_WIDTH)
|
||||
mText.erase(mText.size()-1);
|
||||
mText.erase(mText.size() - 1);
|
||||
|
||||
mHasFocus = hasFocus;
|
||||
if (hasFocus)
|
||||
Entering();
|
||||
|
||||
meta = deckMetaData;
|
||||
if ( meta && meta->getAvatarFilename().size() > 0 )
|
||||
if (meta && meta->getAvatarFilename().size() > 0)
|
||||
this->imageFilename = meta->getAvatarFilename();
|
||||
else
|
||||
this->imageFilename = "avatar.jpg";
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DeckMenuItem::RenderWithOffset(float yOffset)
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
@@ -50,14 +49,12 @@ void DeckMenuItem::Entering()
|
||||
parent->selectionTargetY = mY;
|
||||
}
|
||||
|
||||
|
||||
bool DeckMenuItem::Leaving(JButton key)
|
||||
{
|
||||
mHasFocus = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DeckMenuItem::ButtonPressed()
|
||||
{
|
||||
return true;
|
||||
@@ -88,7 +85,6 @@ ostream& DeckMenuItem::toString(ostream& out) const
|
||||
<< " ; mX,mY : " << mX << "," << mY;
|
||||
}
|
||||
|
||||
|
||||
DeckMenuItem::~DeckMenuItem()
|
||||
{
|
||||
meta = NULL;
|
||||
|
||||
@@ -9,33 +9,34 @@
|
||||
//Merge this with DeckStats
|
||||
//Have this class handle all the Meta Data rather than relying on MTGDeck. Then MTGDeck would have a MetaData object...
|
||||
|
||||
|
||||
DeckMetaDataList * DeckMetaDataList::decksMetaData = NEW DeckMetaDataList();
|
||||
|
||||
DeckMetaData::DeckMetaData(){
|
||||
DeckMetaData::DeckMetaData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DeckMetaData::DeckMetaData(string filename, Player * statsPlayer){
|
||||
DeckMetaData::DeckMetaData(string filename, Player * statsPlayer)
|
||||
{
|
||||
load(filename);
|
||||
}
|
||||
|
||||
|
||||
void DeckMetaData::loadStatsForPlayer( Player * statsPlayer, string deckStatsFileName )
|
||||
void DeckMetaData::loadStatsForPlayer(Player * statsPlayer, string deckStatsFileName)
|
||||
{
|
||||
DeckStats * stats = DeckStats::GetInstance();
|
||||
if ( statsPlayer )
|
||||
if (statsPlayer)
|
||||
{
|
||||
stats->load(statsPlayer);
|
||||
DeckStat * opponentDeckStats = stats->getDeckStat(deckStatsFileName);
|
||||
if ( opponentDeckStats )
|
||||
if (opponentDeckStats)
|
||||
{
|
||||
_percentVictories = stats->percentVictories(deckStatsFileName);
|
||||
_victories = opponentDeckStats->victories;
|
||||
_nbGamesPlayed = opponentDeckStats->nbgames;
|
||||
ostringstream oss;
|
||||
int oppDeckId = atoi ( deckStatsFileName.substr( deckStatsFileName.find("deck") + 4, deckStatsFileName.find_last_of(".") ).c_str() );
|
||||
int avatarId = getAvatarId( oppDeckId );
|
||||
int deckFilenameOffset = deckStatsFileName.find("deck") + 4;
|
||||
int oppDeckId = atoi(deckStatsFileName.substr(deckFilenameOffset, deckStatsFileName.find_last_of(".")).c_str());
|
||||
int avatarId = getAvatarId(oppDeckId);
|
||||
oss << "avatar" << avatarId << ".jpg";
|
||||
_avatarFilename = oss.str();
|
||||
if (_percentVictories < 34)
|
||||
@@ -54,13 +55,14 @@ void DeckMetaData::loadStatsForPlayer( Player * statsPlayer, string deckStatsFil
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "avatar" << getAvatarId( _deckid ) << ".jpg";
|
||||
oss << "avatar" << getAvatarId(_deckid) << ".jpg";
|
||||
_avatarFilename = oss.str();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fileExists(deckStatsFileName.c_str())){
|
||||
if (fileExists(deckStatsFileName.c_str()))
|
||||
{
|
||||
stats->load(deckStatsFileName.c_str());
|
||||
_nbGamesPlayed = stats->nbGames();
|
||||
_percentVictories = stats->percentVictories();
|
||||
@@ -70,47 +72,54 @@ void DeckMetaData::loadStatsForPlayer( Player * statsPlayer, string deckStatsFil
|
||||
}
|
||||
|
||||
// since we only have 100 stock avatar images, we need to recylce the images for deck numbers > 99
|
||||
int DeckMetaData::getAvatarId( int deckId )
|
||||
int DeckMetaData::getAvatarId(int deckId)
|
||||
{
|
||||
int avatarId = deckId % 100;
|
||||
if ( deckId >= 100 && avatarId == 0)
|
||||
if (deckId >= 100 && avatarId == 0)
|
||||
return 100;
|
||||
|
||||
return avatarId;
|
||||
}
|
||||
|
||||
void DeckMetaData::load(string filename){
|
||||
MTGDeck * mtgd = NEW MTGDeck(filename.c_str(),NULL,1);
|
||||
_name = trim( mtgd->meta_name );
|
||||
_desc = trim( mtgd->meta_desc );
|
||||
_deckid = atoi( (filename.substr( filename.find("deck") + 4, filename.find(".txt") )).c_str() );
|
||||
void DeckMetaData::load(string filename)
|
||||
{
|
||||
MTGDeck * mtgd = NEW MTGDeck(filename.c_str(), NULL, 1);
|
||||
_name = trim(mtgd->meta_name);
|
||||
_desc = trim(mtgd->meta_desc);
|
||||
_deckid = atoi((filename.substr(filename.find("deck") + 4, filename.find(".txt"))).c_str());
|
||||
_percentVictories = 0;
|
||||
_nbGamesPlayed = 0;
|
||||
_filename = filename;
|
||||
_victories = 0;
|
||||
delete(mtgd);
|
||||
delete (mtgd);
|
||||
}
|
||||
|
||||
|
||||
DeckMetaDataList::~DeckMetaDataList(){
|
||||
for(map<string,DeckMetaData *>::iterator it = values.begin(); it != values.end(); ++it){
|
||||
DeckMetaDataList::~DeckMetaDataList()
|
||||
{
|
||||
for (map<string, DeckMetaData *>::iterator it = values.begin(); it != values.end(); ++it)
|
||||
{
|
||||
SAFE_DELETE(it->second);
|
||||
}
|
||||
values.clear();
|
||||
}
|
||||
|
||||
void DeckMetaDataList::invalidate(string filename){
|
||||
map<string,DeckMetaData *>::iterator it = values.find(filename);
|
||||
if (it !=values.end()){
|
||||
void DeckMetaDataList::invalidate(string filename)
|
||||
{
|
||||
map<string, DeckMetaData *>::iterator it = values.find(filename);
|
||||
if (it != values.end())
|
||||
{
|
||||
SAFE_DELETE(it->second);
|
||||
values.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
DeckMetaData * DeckMetaDataList::get(string filename, Player * statsPlayer){
|
||||
map<string,DeckMetaData *>::iterator it = values.find(filename);
|
||||
if (it ==values.end()){
|
||||
if (fileExists(filename.c_str())) {
|
||||
DeckMetaData * DeckMetaDataList::get(string filename, Player * statsPlayer)
|
||||
{
|
||||
map<string, DeckMetaData *>::iterator it = values.find(filename);
|
||||
if (it == values.end())
|
||||
{
|
||||
if (fileExists(filename.c_str()))
|
||||
{
|
||||
values[filename] = NEW DeckMetaData(filename, statsPlayer);
|
||||
}
|
||||
}
|
||||
@@ -145,7 +154,6 @@ int DeckMetaData::getGamesPlayed()
|
||||
return _nbGamesPlayed;
|
||||
}
|
||||
|
||||
|
||||
int DeckMetaData::getVictories()
|
||||
{
|
||||
return _victories;
|
||||
@@ -164,7 +172,7 @@ int DeckMetaData::getDifficulty()
|
||||
string DeckMetaData::getDifficultyString()
|
||||
{
|
||||
string difficultyString = "Normal";
|
||||
switch( _difficulty )
|
||||
switch (_difficulty)
|
||||
{
|
||||
case HARD:
|
||||
difficultyString = "Hard";
|
||||
|
||||
+112
-71
@@ -6,147 +6,183 @@
|
||||
|
||||
DeckStats * DeckStats::mInstance = NULL;
|
||||
|
||||
int DeckStat::percentVictories(){
|
||||
if (nbgames == 0) return 50;
|
||||
int DeckStat::percentVictories()
|
||||
{
|
||||
if (nbgames == 0)
|
||||
return 50;
|
||||
return (100 * victories / nbgames);
|
||||
}
|
||||
|
||||
DeckStats * DeckStats::GetInstance(){
|
||||
if (!mInstance){
|
||||
DeckStats * DeckStats::GetInstance()
|
||||
{
|
||||
if (!mInstance)
|
||||
{
|
||||
mInstance = NEW DeckStats();
|
||||
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
void DeckStats::cleanStats(){
|
||||
map<string,DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++){
|
||||
void DeckStats::cleanStats()
|
||||
{
|
||||
map<string, DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
SAFE_DELETE(it->second);
|
||||
}
|
||||
|
||||
stats.clear();
|
||||
}
|
||||
|
||||
DeckStats::~DeckStats(){
|
||||
DeckStats::~DeckStats()
|
||||
{
|
||||
cleanStats();
|
||||
}
|
||||
|
||||
int DeckStats::percentVictories(string opponentsFile){
|
||||
map<string,DeckStat *>::iterator it = stats.find(opponentsFile);
|
||||
if (it == stats.end()){
|
||||
int DeckStats::percentVictories(string opponentsFile)
|
||||
{
|
||||
map<string, DeckStat *>::iterator it = stats.find(opponentsFile);
|
||||
if (it == stats.end())
|
||||
{
|
||||
return 50;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
return (it->second->percentVictories());
|
||||
}
|
||||
}
|
||||
|
||||
DeckStat* DeckStats::getDeckStat(string opponentsFile){
|
||||
map<string,DeckStat *>::iterator it = stats.find(opponentsFile);
|
||||
if (it == stats.end()){
|
||||
DeckStat* DeckStats::getDeckStat(string opponentsFile)
|
||||
{
|
||||
map<string, DeckStat *>::iterator it = stats.find(opponentsFile);
|
||||
if (it == stats.end())
|
||||
{
|
||||
return NULL;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
int DeckStats::nbGames(){
|
||||
int DeckStats::nbGames()
|
||||
{
|
||||
int nbgames = 0;
|
||||
map<string,DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++){
|
||||
map<string, DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
DeckStat * d = it->second;
|
||||
nbgames+=d->nbgames;
|
||||
nbgames += d->nbgames;
|
||||
}
|
||||
return nbgames;
|
||||
}
|
||||
|
||||
|
||||
int DeckStats::percentVictories(){
|
||||
int DeckStats::percentVictories()
|
||||
{
|
||||
int victories = 0;
|
||||
int nbgames = 0;
|
||||
map<string,DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++){
|
||||
map<string, DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
DeckStat * d = it->second;
|
||||
nbgames+=d->nbgames;
|
||||
victories+=d->victories;
|
||||
nbgames += d->nbgames;
|
||||
victories += d->victories;
|
||||
}
|
||||
if (nbgames){
|
||||
return (victories * 100)/nbgames;
|
||||
if (nbgames)
|
||||
{
|
||||
return (victories * 100) / nbgames;
|
||||
}
|
||||
return 50;
|
||||
}
|
||||
|
||||
void DeckStats::load(Player * player){
|
||||
void DeckStats::load(Player * player)
|
||||
{
|
||||
char filename[512];
|
||||
sprintf(filename,"stats/%s.txt",player->deckFileSmall.c_str());
|
||||
sprintf(filename, "stats/%s.txt", player->deckFileSmall.c_str());
|
||||
load(options.profileFile(filename).c_str());
|
||||
}
|
||||
|
||||
void DeckStats::load(const char * filename){
|
||||
void DeckStats::load(const char * filename)
|
||||
{
|
||||
cleanStats();
|
||||
std::ifstream file(filename);
|
||||
std::string s;
|
||||
|
||||
if(file){
|
||||
while(std::getline(file,s)){
|
||||
if (file)
|
||||
{
|
||||
while (std::getline(file, s))
|
||||
{
|
||||
string deckfile = s;
|
||||
std::getline(file,s);
|
||||
std::getline(file, s);
|
||||
int games = atoi(s.c_str());
|
||||
std::getline(file,s);
|
||||
std::getline(file, s);
|
||||
int victories = atoi(s.c_str());
|
||||
map<string,DeckStat *>::iterator it = stats.find(deckfile);
|
||||
if (it == stats.end()){
|
||||
stats[deckfile] = NEW DeckStat(games,victories);
|
||||
map<string, DeckStat *>::iterator it = stats.find(deckfile);
|
||||
if (it == stats.end())
|
||||
{
|
||||
stats[deckfile] = NEW DeckStat(games, victories);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void DeckStats::save(Player * player){
|
||||
void DeckStats::save(Player * player)
|
||||
{
|
||||
char filename[512];
|
||||
sprintf(filename,"stats/%s.txt",player->deckFileSmall.c_str());
|
||||
sprintf(filename, "stats/%s.txt", player->deckFileSmall.c_str());
|
||||
save(options.profileFile(filename).c_str());
|
||||
}
|
||||
|
||||
void DeckStats::save(const char * filename){
|
||||
void DeckStats::save(const char * filename)
|
||||
{
|
||||
std::ofstream file(filename);
|
||||
char writer[512];
|
||||
if (file){
|
||||
map<string,DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++){
|
||||
sprintf(writer,"%s\n", it->first.c_str());
|
||||
file<<writer;
|
||||
sprintf(writer,"%i\n", it->second->nbgames);
|
||||
file<<writer;
|
||||
sprintf(writer,"%i\n", it->second->victories);
|
||||
file<<writer;
|
||||
if (file)
|
||||
{
|
||||
map<string, DeckStat *>::iterator it;
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
sprintf(writer, "%s\n", it->first.c_str());
|
||||
file << writer;
|
||||
sprintf(writer, "%i\n", it->second->nbgames);
|
||||
file << writer;
|
||||
sprintf(writer, "%i\n", it->second->victories);
|
||||
file << writer;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void DeckStats::saveStats(Player *player, Player *opponent, GameObserver * game){
|
||||
void DeckStats::saveStats(Player *player, Player *opponent, GameObserver * game)
|
||||
{
|
||||
int victory = 1;
|
||||
if (!game->gameOver){
|
||||
if (player->life == opponent->life) return;
|
||||
if (player->life < opponent->life) victory = 0;
|
||||
}else if (game->gameOver == player) {
|
||||
if (!game->gameOver)
|
||||
{
|
||||
if (player->life == opponent->life)
|
||||
return;
|
||||
if (player->life < opponent->life)
|
||||
victory = 0;
|
||||
}
|
||||
else if (game->gameOver == player)
|
||||
{
|
||||
victory = 0;
|
||||
}
|
||||
load(player);
|
||||
map<string,DeckStat *>::iterator it = stats.find(opponent->deckFileSmall);
|
||||
if (it == stats.end()){
|
||||
stats[opponent->deckFileSmall] = NEW DeckStat(1,victory);
|
||||
}else{
|
||||
it->second->victories+=victory;
|
||||
it->second->nbgames+=1;
|
||||
map<string, DeckStat *>::iterator it = stats.find(opponent->deckFileSmall);
|
||||
if (it == stats.end())
|
||||
{
|
||||
stats[opponent->deckFileSmall] = NEW DeckStat(1, victory);
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second->victories += victory;
|
||||
it->second->nbgames += 1;
|
||||
}
|
||||
save(player);
|
||||
}
|
||||
|
||||
|
||||
StatsWrapper::StatsWrapper( int deckId )
|
||||
StatsWrapper::StatsWrapper(int deckId)
|
||||
{
|
||||
// Load deck statistics
|
||||
char buffer[512];
|
||||
@@ -157,7 +193,8 @@ StatsWrapper::StatsWrapper( int deckId )
|
||||
sprintf(buffer, "stats/player_deck%i.txt", deckId);
|
||||
string deckstats = options.profileFile(buffer);
|
||||
|
||||
if(fileExists(deckstats.c_str())){
|
||||
if (fileExists(deckstats.c_str()))
|
||||
{
|
||||
stats->load(deckstats.c_str());
|
||||
percentVictories = stats->percentVictories();
|
||||
gamesPlayed = stats->nbGames();
|
||||
@@ -165,20 +202,23 @@ StatsWrapper::StatsWrapper( int deckId )
|
||||
// Detailed deck statistics against AI
|
||||
int found = 1;
|
||||
int nbDecks = 0;
|
||||
while (found){
|
||||
while (found)
|
||||
{
|
||||
found = 0;
|
||||
char buffer[512];
|
||||
char smallDeckName[512];
|
||||
sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks+1);
|
||||
if(fileExists(buffer)){
|
||||
MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1);
|
||||
sprintf(buffer, "%s/deck%i.txt", RESPATH"/ai/baka", nbDecks + 1);
|
||||
if (fileExists(buffer))
|
||||
{
|
||||
MTGDeck * mtgd = NEW MTGDeck(buffer, NULL, 1);
|
||||
found = 1;
|
||||
nbDecks++;
|
||||
|
||||
sprintf(smallDeckName, "%s_deck%i","ai_baka",nbDecks);
|
||||
sprintf(smallDeckName, "%s_deck%i", "ai_baka", nbDecks);
|
||||
DeckStat* deckStat = stats->getDeckStat(string(smallDeckName));
|
||||
|
||||
if ((deckStat != NULL) && (deckStat->nbgames>0)) {
|
||||
if ((deckStat != NULL) && (deckStat->nbgames > 0))
|
||||
{
|
||||
int percentVictories = stats->percentVictories(string(smallDeckName));
|
||||
aiDeckNames.push_back(string(mtgd->meta_name));
|
||||
aiDeckStats.push_back(deckStat);
|
||||
@@ -188,7 +228,8 @@ StatsWrapper::StatsWrapper( int deckId )
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
gamesPlayed = 0;
|
||||
percentVictories = 0;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#include "Trash.h"
|
||||
#include "DuelLayers.h"
|
||||
|
||||
void DuelLayers::init(){
|
||||
void DuelLayers::init()
|
||||
{
|
||||
|
||||
GameObserver* go = GameObserver::GetInstance();
|
||||
|
||||
@@ -44,8 +45,8 @@ void DuelLayers::init(){
|
||||
//Other display elements
|
||||
action->Add(NEW HUDDisplay(-1));
|
||||
|
||||
Add(NEW GuiMana(20,20,go->players[1]));
|
||||
Add(NEW GuiMana(440,20,go->players[0]));
|
||||
Add(NEW GuiMana(20, 20, go->players[1]));
|
||||
Add(NEW GuiMana(440, 20, go->players[0]));
|
||||
Add(stack = NEW ActionStack(go));
|
||||
Add(combat = NEW GuiCombat(go));
|
||||
Add(action);
|
||||
@@ -59,22 +60,29 @@ void DuelLayers::init(){
|
||||
Add(NEW GuiBackground());
|
||||
}
|
||||
|
||||
void DuelLayers::CheckUserInput(int isAI){
|
||||
void DuelLayers::CheckUserInput(int isAI)
|
||||
{
|
||||
JButton key;
|
||||
int x, y;
|
||||
while ((key = JGE::GetInstance()->ReadButton()))
|
||||
{
|
||||
if ((!isAI) && (0 != key))
|
||||
{
|
||||
if (stack->CheckUserInput(key)) break;
|
||||
if (combat->CheckUserInput(key)) break;
|
||||
if (avatars->CheckUserInput(key)) break; //avatars need to check their input before action (CTRL_CROSS)
|
||||
if (action->CheckUserInput(key)) break;
|
||||
if (hand->CheckUserInput(key)) break;
|
||||
if (CardSelectorSingleton::Instance()->CheckUserInput(key)) break;
|
||||
if (stack->CheckUserInput(key))
|
||||
break;
|
||||
if (combat->CheckUserInput(key))
|
||||
break;
|
||||
if (avatars->CheckUserInput(key))
|
||||
break; //avatars need to check their input before action (CTRL_CROSS)
|
||||
if (action->CheckUserInput(key))
|
||||
break;
|
||||
if (hand->CheckUserInput(key))
|
||||
break;
|
||||
if (CardSelectorSingleton::Instance()->CheckUserInput(key))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
if (JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
if (avatars->CheckUserInput(x, y))
|
||||
{
|
||||
@@ -89,21 +97,26 @@ void DuelLayers::CheckUserInput(int isAI){
|
||||
|
||||
void DuelLayers::Update(float dt, Player * currentPlayer)
|
||||
{
|
||||
for (int i = 0; i < nbitems; ++i) objects[i]->Update(dt);
|
||||
for (int i = 0; i < nbitems; ++i)
|
||||
objects[i]->Update(dt);
|
||||
int isAI = currentPlayer->isAI();
|
||||
if (isAI) currentPlayer->Act(dt);
|
||||
if (isAI)
|
||||
currentPlayer->Act(dt);
|
||||
CheckUserInput(isAI);
|
||||
}
|
||||
|
||||
ActionStack * DuelLayers::stackLayer(){
|
||||
ActionStack * DuelLayers::stackLayer()
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
GuiCombat * DuelLayers::combatLayer(){
|
||||
GuiCombat * DuelLayers::combatLayer()
|
||||
{
|
||||
return combat;
|
||||
}
|
||||
|
||||
ActionLayer * DuelLayers::actionLayer(){
|
||||
ActionLayer * DuelLayers::actionLayer()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -112,9 +125,13 @@ GuiAvatars * DuelLayers::GetAvatars()
|
||||
return avatars;
|
||||
}
|
||||
|
||||
DuelLayers::DuelLayers() : nbitems(0) {}
|
||||
DuelLayers::DuelLayers() :
|
||||
nbitems(0)
|
||||
{
|
||||
}
|
||||
|
||||
DuelLayers::~DuelLayers(){
|
||||
DuelLayers::~DuelLayers()
|
||||
{
|
||||
int _nbitems = nbitems;
|
||||
nbitems = 0;
|
||||
for (int i = 0; i < _nbitems; ++i)
|
||||
@@ -127,34 +144,39 @@ DuelLayers::~DuelLayers(){
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < waiters.size(); ++i)
|
||||
delete(waiters[i]);
|
||||
delete (waiters[i]);
|
||||
Trash::cleanup();
|
||||
|
||||
CardSelectorSingleton::Terminate();
|
||||
mCardSelector = NULL;
|
||||
}
|
||||
|
||||
void DuelLayers::Add(GuiLayer * layer){
|
||||
void DuelLayers::Add(GuiLayer * layer)
|
||||
{
|
||||
objects.push_back(layer);
|
||||
nbitems++;
|
||||
}
|
||||
|
||||
void DuelLayers::Remove(){
|
||||
void DuelLayers::Remove()
|
||||
{
|
||||
--nbitems;
|
||||
}
|
||||
|
||||
void DuelLayers::Render(){
|
||||
void DuelLayers::Render()
|
||||
{
|
||||
bool focusMakesItThrough = true;
|
||||
for (int i = 0; i < nbitems; ++i)
|
||||
{
|
||||
objects[i]->hasFocus = focusMakesItThrough;
|
||||
if (objects[i]->modal) focusMakesItThrough = false;
|
||||
if (objects[i]->modal)
|
||||
focusMakesItThrough = false;
|
||||
}
|
||||
for (int i = nbitems - 1; i >= 0; --i)
|
||||
objects[i]->Render();
|
||||
}
|
||||
|
||||
int DuelLayers::receiveEvent(WEvent * e){
|
||||
int DuelLayers::receiveEvent(WEvent * e)
|
||||
{
|
||||
|
||||
#if 0
|
||||
#define PRINT_IF(type) { type *foo = dynamic_cast<type*>(e); if (foo) cout << "Is a " #type " " << *foo << endl; }
|
||||
@@ -189,7 +211,8 @@ int DuelLayers::receiveEvent(WEvent * e){
|
||||
const Pos* ref = card->view;
|
||||
while (card)
|
||||
{
|
||||
if (ref == card->view) card->view = p;
|
||||
if (ref == card->view)
|
||||
card->view = p;
|
||||
card = card->next;
|
||||
}
|
||||
}
|
||||
|
||||
+286
-153
@@ -7,18 +7,21 @@
|
||||
#include "Player.h"
|
||||
#include "Counters.h"
|
||||
|
||||
ExtraCost::ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc)
|
||||
: tc(_tc), source(NULL), target(NULL), mCostRenderString(inCostRenderString)
|
||||
ExtraCost::ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc) :
|
||||
tc(_tc), source(NULL), target(NULL), mCostRenderString(inCostRenderString)
|
||||
{
|
||||
if (tc) tc->targetter = NULL;
|
||||
if (tc)
|
||||
tc->targetter = NULL;
|
||||
}
|
||||
|
||||
ExtraCost::~ExtraCost(){
|
||||
ExtraCost::~ExtraCost()
|
||||
{
|
||||
SAFE_DELETE(tc);
|
||||
}
|
||||
|
||||
int ExtraCost::setSource(MTGCardInstance * _source){
|
||||
source=_source;
|
||||
int ExtraCost::setSource(MTGCardInstance * _source)
|
||||
{
|
||||
source = _source;
|
||||
if (tc)
|
||||
{
|
||||
tc->source = _source;
|
||||
@@ -32,21 +35,25 @@ int ExtraCost::setSource(MTGCardInstance * _source){
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ExtraCost::Render(){
|
||||
void ExtraCost::Render()
|
||||
{
|
||||
if (!mCostRenderString.empty())
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(mCostRenderString, 20 ,20, JGETEXT_LEFT);
|
||||
mFont->DrawString(mCostRenderString, 20, 20, JGETEXT_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
int ExtraCost::setPayment(MTGCardInstance * card){
|
||||
int ExtraCost::setPayment(MTGCardInstance * card)
|
||||
{
|
||||
int result = 0;
|
||||
if (tc) {
|
||||
if (tc)
|
||||
{
|
||||
result = tc->addTarget(card);
|
||||
if (result) {
|
||||
if (result)
|
||||
{
|
||||
target = card;
|
||||
}
|
||||
}
|
||||
@@ -54,22 +61,28 @@ int ExtraCost::setPayment(MTGCardInstance * card){
|
||||
}
|
||||
|
||||
//life cost
|
||||
LifeCost * LifeCost::clone() const{
|
||||
LifeCost * LifeCost::clone() const
|
||||
{
|
||||
LifeCost * ec = NEW LifeCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
LifeCost::LifeCost(TargetChooser *_tc)
|
||||
: ExtraCost("Life", _tc){
|
||||
LifeCost::LifeCost(TargetChooser *_tc) :
|
||||
ExtraCost("Life", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int LifeCost::doPay(){
|
||||
int LifeCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
if (target)
|
||||
{
|
||||
_target->controller()->life -= 1;
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -77,221 +90,288 @@ int LifeCost::doPay(){
|
||||
|
||||
//discard a card at random as a cost
|
||||
//DiscardRandom cost
|
||||
DiscardRandomCost * DiscardRandomCost::clone() const{
|
||||
DiscardRandomCost * DiscardRandomCost::clone() const
|
||||
{
|
||||
DiscardRandomCost * ec = NEW DiscardRandomCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc)
|
||||
: ExtraCost("Discard Random", _tc){
|
||||
DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc) :
|
||||
ExtraCost("Discard Random", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int DiscardRandomCost::canPay(){
|
||||
int DiscardRandomCost::canPay()
|
||||
{
|
||||
MTGGameZone * z = target->controller()->game->hand;
|
||||
int nbcards = z->nb_cards;
|
||||
if(nbcards < 1) return 0;
|
||||
if(nbcards == 1 && z->hasCard(source)) return 0;
|
||||
if (nbcards < 1)
|
||||
return 0;
|
||||
if (nbcards == 1 && z->hasCard(source))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DiscardRandomCost::doPay(){
|
||||
int DiscardRandomCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
_target->controller()->game->discardRandom(_target->controller()->game->hand,source);
|
||||
if (target)
|
||||
{
|
||||
_target->controller()->game->discardRandom(_target->controller()->game->hand, source);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//a choosen discard
|
||||
|
||||
DiscardCost * DiscardCost::clone() const{
|
||||
DiscardCost * DiscardCost::clone() const
|
||||
{
|
||||
DiscardCost * ec = NEW DiscardCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
DiscardCost::DiscardCost(TargetChooser *_tc)
|
||||
: ExtraCost("Choose card to Discard", _tc){
|
||||
DiscardCost::DiscardCost(TargetChooser *_tc) :
|
||||
ExtraCost("Choose card to Discard", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int DiscardCost::doPay(){
|
||||
int DiscardCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
if (target)
|
||||
{
|
||||
WEvent * e = NEW WEventCardDiscard(target);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(e);
|
||||
_target->controller()->game->putInGraveyard(_target);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//to library cost
|
||||
|
||||
ToLibraryCost * ToLibraryCost::clone() const{
|
||||
ToLibraryCost * ToLibraryCost::clone() const
|
||||
{
|
||||
ToLibraryCost * ec = NEW ToLibraryCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
ToLibraryCost::ToLibraryCost(TargetChooser *_tc)
|
||||
: ExtraCost("Put a card on top of Library", _tc){
|
||||
ToLibraryCost::ToLibraryCost(TargetChooser *_tc) :
|
||||
ExtraCost("Put a card on top of Library", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int ToLibraryCost::doPay(){
|
||||
int ToLibraryCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
if (target)
|
||||
{
|
||||
_target->controller()->game->putInLibrary(target);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Mill yourself as a cost
|
||||
MillCost * MillCost::clone() const{
|
||||
MillCost * MillCost::clone() const
|
||||
{
|
||||
MillCost * ec = NEW MillCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
MillCost::MillCost(TargetChooser *_tc)
|
||||
: ExtraCost("Deplete", _tc){
|
||||
MillCost::MillCost(TargetChooser *_tc) :
|
||||
ExtraCost("Deplete", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int MillCost::canPay(){
|
||||
int MillCost::canPay()
|
||||
{
|
||||
MTGGameZone * z = target->controller()->game->library;
|
||||
int nbcards = z->nb_cards;
|
||||
if(nbcards < 1) return 0;
|
||||
if (nbcards < 1)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int MillCost::doPay(){
|
||||
int MillCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
_target->controller()->game->putInZone(_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards-1],_target->controller()->game->library, _target->controller()->game->graveyard);
|
||||
if (target)
|
||||
{
|
||||
_target->controller()->game->putInZone(
|
||||
_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1],
|
||||
_target->controller()->game->library, _target->controller()->game->graveyard);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MillExileCost::MillExileCost(TargetChooser *_tc)
|
||||
: MillCost( _tc){
|
||||
MillExileCost::MillExileCost(TargetChooser *_tc) :
|
||||
MillCost(_tc)
|
||||
{
|
||||
// override the base string here
|
||||
mCostRenderString = "Deplete To Exile";
|
||||
}
|
||||
|
||||
int MillExileCost::doPay(){
|
||||
int MillExileCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
_target->controller()->game->putInZone(_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards-1],
|
||||
_target->controller()->game->library,
|
||||
_target->controller()->game->exile);
|
||||
if (target)
|
||||
{
|
||||
_target->controller()->game->putInZone(
|
||||
_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1],
|
||||
_target->controller()->game->library, _target->controller()->game->exile);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Tap target cost
|
||||
TapTargetCost * TapTargetCost::clone() const{
|
||||
TapTargetCost * TapTargetCost::clone() const
|
||||
{
|
||||
TapTargetCost * ec = NEW TapTargetCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
TapTargetCost::TapTargetCost(TargetChooser *_tc)
|
||||
: ExtraCost("Tap Target", _tc){
|
||||
TapTargetCost::TapTargetCost(TargetChooser *_tc) :
|
||||
ExtraCost("Tap Target", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int TapTargetCost::doPay(){
|
||||
int TapTargetCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
if (target)
|
||||
{
|
||||
_target->tap();
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//exile as cost
|
||||
ExileTargetCost * ExileTargetCost::clone() const{
|
||||
ExileTargetCost * ExileTargetCost::clone() const
|
||||
{
|
||||
ExileTargetCost * ec = NEW ExileTargetCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
ExileTargetCost::ExileTargetCost(TargetChooser *_tc)
|
||||
: ExtraCost("Exile Target", _tc){
|
||||
ExileTargetCost::ExileTargetCost(TargetChooser *_tc) :
|
||||
ExtraCost("Exile Target", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int ExileTargetCost::doPay(){
|
||||
int ExileTargetCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
if (target)
|
||||
{
|
||||
target->controller()->game->putInExile(target);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Bounce as cost
|
||||
BounceTargetCost * BounceTargetCost::clone() const{
|
||||
BounceTargetCost * BounceTargetCost::clone() const
|
||||
{
|
||||
BounceTargetCost * ec = NEW BounceTargetCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
BounceTargetCost::BounceTargetCost(TargetChooser *_tc)
|
||||
: ExtraCost("Return Target to Hand", _tc){
|
||||
BounceTargetCost::BounceTargetCost(TargetChooser *_tc) :
|
||||
ExtraCost("Return Target to Hand", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int BounceTargetCost::doPay(){
|
||||
int BounceTargetCost::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
if (target)
|
||||
{
|
||||
target->controller()->game->putInHand(target);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Bounce as cost for ninja
|
||||
Ninja * Ninja::clone() const{
|
||||
Ninja * Ninja::clone() const
|
||||
{
|
||||
Ninja * ec = NEW Ninja(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
Ninja::Ninja(TargetChooser *_tc)
|
||||
: ExtraCost("Select unblocked attacker", _tc){
|
||||
Ninja::Ninja(TargetChooser *_tc) :
|
||||
ExtraCost("Select unblocked attacker", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int Ninja::isPaymentSet(){
|
||||
int Ninja::isPaymentSet()
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
int currentPhase = g->getCurrentGamePhase();
|
||||
if (target && ((target->isAttacker() && target->blocked == true) || target->isAttacker() < 1 || currentPhase != Constants::MTG_PHASE_COMBATBLOCKERS)){ tc->removeTarget(target);target = NULL; return 0;}
|
||||
if(target) return 1;
|
||||
if (target && ((target->isAttacker() && target->blocked == true) || target->isAttacker() < 1 || currentPhase
|
||||
!= Constants::MTG_PHASE_COMBATBLOCKERS))
|
||||
{
|
||||
tc->removeTarget(target);
|
||||
target = NULL;
|
||||
return 0;
|
||||
}
|
||||
if (target)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Ninja::doPay(){
|
||||
int Ninja::doPay()
|
||||
{
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if(target){
|
||||
if (target)
|
||||
{
|
||||
target->controller()->game->putInHand(target);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -300,24 +380,30 @@ int Ninja::doPay(){
|
||||
//endbouncetargetcostforninja
|
||||
//------------------------------------------------------------
|
||||
|
||||
SacrificeCost * SacrificeCost::clone() const{
|
||||
SacrificeCost * SacrificeCost::clone() const
|
||||
{
|
||||
SacrificeCost * ec = NEW SacrificeCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
return ec;
|
||||
}
|
||||
|
||||
SacrificeCost::SacrificeCost(TargetChooser *_tc)
|
||||
: ExtraCost("Sacrifice", _tc){
|
||||
SacrificeCost::SacrificeCost(TargetChooser *_tc) :
|
||||
ExtraCost("Sacrifice", _tc)
|
||||
{
|
||||
}
|
||||
|
||||
int SacrificeCost::doPay(){
|
||||
if(target){
|
||||
int SacrificeCost::doPay()
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
WEvent * e = NEW WEventCardSacrifice(target);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(e);
|
||||
target->controller()->game->putInGraveyard(target);
|
||||
target = NULL;
|
||||
if (tc) tc->initTargets();
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -325,27 +411,36 @@ int SacrificeCost::doPay(){
|
||||
|
||||
//Counter costs
|
||||
|
||||
CounterCost * CounterCost::clone() const{
|
||||
CounterCost * CounterCost::clone() const
|
||||
{
|
||||
CounterCost * ec = NEW CounterCost(*this);
|
||||
if (tc) ec->tc = tc->clone();
|
||||
if (counter) ec->counter = NEW Counter(counter->target, counter->name.c_str(),counter->power, counter->toughness);
|
||||
if (tc)
|
||||
ec->tc = tc->clone();
|
||||
if (counter)
|
||||
ec->counter = NEW Counter(counter->target, counter->name.c_str(), counter->power, counter->toughness);
|
||||
return ec;
|
||||
}
|
||||
|
||||
CounterCost::CounterCost(Counter * _counter,TargetChooser *_tc)
|
||||
: ExtraCost("Counters", _tc) {
|
||||
CounterCost::CounterCost(Counter * _counter, TargetChooser *_tc) :
|
||||
ExtraCost("Counters", _tc)
|
||||
{
|
||||
counter = _counter;
|
||||
hasCounters = 0;
|
||||
}
|
||||
|
||||
int CounterCost::setPayment(MTGCardInstance *card){
|
||||
if (tc) {
|
||||
int CounterCost::setPayment(MTGCardInstance *card)
|
||||
{
|
||||
if (tc)
|
||||
{
|
||||
int result = tc->addTarget(card);
|
||||
if (result) {
|
||||
if (counter->nb >= 0) return 1; //add counters always possible
|
||||
if (result)
|
||||
{
|
||||
if (counter->nb >= 0)
|
||||
return 1; //add counters always possible
|
||||
target = card;
|
||||
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness);
|
||||
if (targetCounter && targetCounter->nb >= - counter->nb) {
|
||||
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(), counter->power, counter->toughness);
|
||||
if (targetCounter && targetCounter->nb >= -counter->nb)
|
||||
{
|
||||
hasCounters = 1;
|
||||
return result;
|
||||
}
|
||||
@@ -354,41 +449,56 @@ int CounterCost::setPayment(MTGCardInstance *card){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CounterCost::isPaymentSet(){
|
||||
if (!target) return 0;
|
||||
if (counter->nb >=0) return 1; //add counters always possible
|
||||
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness);
|
||||
if (targetCounter && targetCounter->nb >= - counter->nb) {
|
||||
int CounterCost::isPaymentSet()
|
||||
{
|
||||
if (!target)
|
||||
return 0;
|
||||
if (counter->nb >= 0)
|
||||
return 1; //add counters always possible
|
||||
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(), counter->power, counter->toughness);
|
||||
if (targetCounter && targetCounter->nb >= -counter->nb)
|
||||
{
|
||||
hasCounters = 1;
|
||||
}
|
||||
if (target && hasCounters) return 1;
|
||||
if (target && hasCounters)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CounterCost::canPay(){
|
||||
int CounterCost::canPay()
|
||||
{
|
||||
// if target needs to be chosen, then move on.
|
||||
if (tc) return 1;
|
||||
if (counter->nb >=0) return 1; //add counters always possible
|
||||
if (tc)
|
||||
return 1;
|
||||
if (counter->nb >= 0)
|
||||
return 1; //add counters always possible
|
||||
// otherwise, move on only if target has enough counters
|
||||
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness);
|
||||
if (targetCounter && targetCounter->nb >= - counter->nb) return 1;
|
||||
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(), counter->power, counter->toughness);
|
||||
if (targetCounter && targetCounter->nb >= -counter->nb)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CounterCost::doPay(){
|
||||
if (!target) return 0;
|
||||
int CounterCost::doPay()
|
||||
{
|
||||
if (!target)
|
||||
return 0;
|
||||
|
||||
if (counter->nb >=0) { //Add counters as a cost
|
||||
for (int i = 0; i < counter->nb; i++) {
|
||||
target->counters->addCounter(counter->name.c_str(),counter->power,counter->toughness);
|
||||
if (counter->nb >= 0)
|
||||
{ //Add counters as a cost
|
||||
for (int i = 0; i < counter->nb; i++)
|
||||
{
|
||||
target->counters->addCounter(counter->name.c_str(), counter->power, counter->toughness);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//remove counters as a cost
|
||||
if (hasCounters) {
|
||||
for (int i = 0; i < - counter->nb; i++) {
|
||||
target->counters->removeCounter(counter->name.c_str(),counter->power,counter->toughness);
|
||||
if (hasCounters)
|
||||
{
|
||||
for (int i = 0; i < -counter->nb; i++)
|
||||
{
|
||||
target->counters->removeCounter(counter->name.c_str(), counter->power, counter->toughness);
|
||||
}
|
||||
hasCounters = 0;
|
||||
return 1;
|
||||
@@ -396,86 +506,109 @@ int CounterCost::doPay(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
CounterCost::~CounterCost(){
|
||||
CounterCost::~CounterCost()
|
||||
{
|
||||
SAFE_DELETE(counter);
|
||||
}
|
||||
|
||||
//
|
||||
//Container
|
||||
//
|
||||
ExtraCosts::ExtraCosts(){
|
||||
ExtraCosts::ExtraCosts()
|
||||
{
|
||||
action = NULL;
|
||||
source = NULL;
|
||||
}
|
||||
|
||||
ExtraCosts * ExtraCosts::clone() const{
|
||||
ExtraCosts * ExtraCosts::clone() const
|
||||
{
|
||||
ExtraCosts * ec = NEW ExtraCosts(*this);
|
||||
ec->costs.clear();
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
ec->costs.push_back(costs[i]->clone());
|
||||
}
|
||||
return ec;
|
||||
}
|
||||
|
||||
void ExtraCosts::Render(){
|
||||
void ExtraCosts::Render()
|
||||
{
|
||||
//TODO cool window and stuff...
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
costs[i]->Render();
|
||||
}
|
||||
}
|
||||
|
||||
int ExtraCosts::setAction(MTGAbility * _action, MTGCardInstance * _card){
|
||||
int ExtraCosts::setAction(MTGAbility * _action, MTGCardInstance * _card)
|
||||
{
|
||||
action = _action;
|
||||
source = _card;
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
costs[i]->setSource(_card);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ExtraCosts::reset(){
|
||||
int ExtraCosts::reset()
|
||||
{
|
||||
action = NULL;
|
||||
source = NULL;
|
||||
//TODO set all payments to "unset"
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ExtraCosts::tryToSetPayment(MTGCardInstance * card){
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
if (int result = costs[i]->setPayment(card)) return result;
|
||||
int ExtraCosts::tryToSetPayment(MTGCardInstance * card)
|
||||
{
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
if (int result = costs[i]->setPayment(card))
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ExtraCosts::isPaymentSet(){
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
if (!costs[i]->isPaymentSet()) return 0;
|
||||
int ExtraCosts::isPaymentSet()
|
||||
{
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
if (!costs[i]->isPaymentSet())
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ExtraCosts::canPay(){
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
if (!costs[i]->canPay()) return 0;
|
||||
int ExtraCosts::canPay()
|
||||
{
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
if (!costs[i]->canPay())
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ExtraCosts::doPay(){
|
||||
int ExtraCosts::doPay()
|
||||
{
|
||||
int result = 0;
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
result+=costs[i]->doPay();
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
result += costs[i]->doPay();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ExtraCosts::~ExtraCosts(){
|
||||
for (size_t i = 0; i < costs.size(); i++){
|
||||
ExtraCosts::~ExtraCosts()
|
||||
{
|
||||
for (size_t i = 0; i < costs.size(); i++)
|
||||
{
|
||||
SAFE_DELETE(costs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ExtraCosts::Dump(){
|
||||
void ExtraCosts::Dump()
|
||||
{
|
||||
DebugTrace("=====\nDumping ExtraCosts=====\n");
|
||||
DebugTrace("NbElements: " << costs.size());
|
||||
}
|
||||
|
||||
+124
-94
@@ -27,21 +27,22 @@
|
||||
#define DEFAULT_DURATION .25
|
||||
|
||||
MTGAllCards * GameApp::collection = NULL;
|
||||
int GameApp::players[] = {0,0};
|
||||
int GameApp::players[] = { 0, 0 };
|
||||
int GameApp::HasMusic = 1;
|
||||
JMusic * GameApp::music = NULL;
|
||||
string GameApp::currentMusicFile = "";
|
||||
string GameApp::systemError = "";
|
||||
|
||||
JQuad* manaIcons[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
JQuad* manaIcons[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
|
||||
|
||||
GameState::GameState(GameApp* parent): mParent(parent)
|
||||
GameState::GameState(GameApp* parent) :
|
||||
mParent(parent)
|
||||
{
|
||||
mEngine = JGE::GetInstance();
|
||||
}
|
||||
|
||||
|
||||
GameApp::GameApp(): JApp()
|
||||
GameApp::GameApp() :
|
||||
JApp()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
nbUpdates = 0;
|
||||
@@ -54,7 +55,7 @@ GameApp::GameApp(): JApp()
|
||||
|
||||
mScreenShotCount = 0;
|
||||
|
||||
for (int i=0; i < GAME_STATE_MAX ; i++)
|
||||
for (int i = 0; i < GAME_STATE_MAX; i++)
|
||||
mGameStates[i] = NULL;
|
||||
|
||||
mShowDebugInfo = false;
|
||||
@@ -62,7 +63,6 @@ GameApp::GameApp(): JApp()
|
||||
players[1] = 0;
|
||||
gameType = GAME_TYPE_CLASSIC;
|
||||
|
||||
|
||||
mCurrentState = NULL;
|
||||
mNextState = NULL;
|
||||
collection = NULL;
|
||||
@@ -70,15 +70,13 @@ GameApp::GameApp(): JApp()
|
||||
music = NULL;
|
||||
}
|
||||
|
||||
|
||||
GameApp::~GameApp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GameApp::Create()
|
||||
{
|
||||
srand((unsigned int)time(0)); // initialize random
|
||||
srand((unsigned int) time(0)); // initialize random
|
||||
#ifndef QT_CONFIG
|
||||
#if defined (WIN32)
|
||||
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
|
||||
@@ -86,16 +84,18 @@ void GameApp::Create()
|
||||
pspFpuSetEnable(0); //disable FPU Exceptions until we find where the FPU errors come from
|
||||
#endif
|
||||
#endif //QT_CONFIG
|
||||
|
||||
//_CrtSetBreakAlloc(368);
|
||||
LOG("starting Game");
|
||||
|
||||
//Find the Res folder
|
||||
std::ifstream mfile("Res.txt");
|
||||
string resPath;
|
||||
if(mfile){
|
||||
if (std::getline(mfile, resPath)) {
|
||||
if (resPath[resPath.size()-1] == '\r') resPath.erase(resPath.size()-1); //Handle DOS files
|
||||
if (mfile)
|
||||
{
|
||||
if (std::getline(mfile, resPath))
|
||||
{
|
||||
if (resPath[resPath.size() - 1] == '\r')
|
||||
resPath.erase(resPath.size() - 1); //Handle DOS files
|
||||
//TODO ERROR Handling if file does not exist
|
||||
JFileSystem::GetInstance()->SetResourceRoot(trim(resPath));
|
||||
}
|
||||
@@ -104,7 +104,6 @@ void GameApp::Create()
|
||||
LOG("Res Root:");
|
||||
LOG(JFileSystem::GetInstance()->GetResourceRoot().c_str());
|
||||
|
||||
|
||||
//Link this to our settings manager.
|
||||
options.theGame = this;
|
||||
|
||||
@@ -130,35 +129,44 @@ void GameApp::Create()
|
||||
|
||||
LOG("Loading Textures");
|
||||
LOG("--Loading menuicons.png");
|
||||
resources.RetrieveTexture("menuicons.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("menuicons.png", RETRIEVE_MANAGE);
|
||||
LOG("---Gettings menuicons.png quads");
|
||||
//Creating thes quad in this specific order allows us to have them in the correct order to call them by integer id
|
||||
manaIcons[Constants::MTG_COLOR_GREEN] = resources.RetrieveQuad("menuicons.png", 2 + 0*36, 38, 32, 32, "c_green",RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_BLUE] = resources.RetrieveQuad("menuicons.png", 2 + 1*36, 38, 32, 32, "c_blue",RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_RED] = resources.RetrieveQuad("menuicons.png", 2 + 3*36, 38, 32, 32, "c_red",RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_BLACK] = resources.RetrieveQuad("menuicons.png", 2 + 2*36, 38, 32, 32, "c_black",RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_WHITE] = resources.RetrieveQuad("menuicons.png", 2 + 4*36, 38, 32, 32, "c_white",RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_LAND] = resources.RetrieveQuad("menuicons.png", 2 + 5*36, 38, 32, 32, "c_land",RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_ARTIFACT] = resources.RetrieveQuad("menuicons.png", 2 + 6*36, 38, 32, 32, "c_artifact",RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_GREEN] = resources.RetrieveQuad("menuicons.png", 2 + 0 * 36, 38, 32, 32, "c_green",
|
||||
RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_BLUE] = resources.RetrieveQuad("menuicons.png", 2 + 1 * 36, 38, 32, 32, "c_blue",
|
||||
RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_RED] = resources.RetrieveQuad("menuicons.png", 2 + 3 * 36, 38, 32, 32, "c_red", RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_BLACK] = resources.RetrieveQuad("menuicons.png", 2 + 2 * 36, 38, 32, 32, "c_black",
|
||||
RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_WHITE] = resources.RetrieveQuad("menuicons.png", 2 + 4 * 36, 38, 32, 32, "c_white",
|
||||
RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_LAND] = resources.RetrieveQuad("menuicons.png", 2 + 5 * 36, 38, 32, 32, "c_land",
|
||||
RETRIEVE_MANAGE);
|
||||
manaIcons[Constants::MTG_COLOR_ARTIFACT] = resources.RetrieveQuad("menuicons.png", 2 + 6 * 36, 38, 32, 32, "c_artifact",
|
||||
RETRIEVE_MANAGE);
|
||||
|
||||
|
||||
for (int i = sizeof(manaIcons)/sizeof(manaIcons[0]) - 1; i >= 0; --i)
|
||||
if (manaIcons[i]) manaIcons[i]->SetHotSpot(16,16);
|
||||
for (int i = sizeof(manaIcons) / sizeof(manaIcons[0]) - 1; i >= 0; --i)
|
||||
if (manaIcons[i])
|
||||
manaIcons[i]->SetHotSpot(16, 16);
|
||||
|
||||
LOG("--Loading back.jpg");
|
||||
resources.RetrieveTexture("back.jpg",RETRIEVE_MANAGE);
|
||||
JQuad * jq = resources.RetrieveQuad("back.jpg", 0, 0, 0, 0, "back",RETRIEVE_MANAGE);
|
||||
if (jq) jq->SetHotSpot(jq->mWidth/2, jq->mHeight/2);
|
||||
resources.RetrieveTexture("back.jpg", RETRIEVE_MANAGE);
|
||||
JQuad * jq = resources.RetrieveQuad("back.jpg", 0, 0, 0, 0, "back", RETRIEVE_MANAGE);
|
||||
if (jq)
|
||||
jq->SetHotSpot(jq->mWidth / 2, jq->mHeight / 2);
|
||||
|
||||
resources.RetrieveTexture("back_thumb.jpg",RETRIEVE_MANAGE);
|
||||
resources.RetrieveQuad("back_thumb.jpg", 0, 0, MTG_MINIIMAGE_WIDTH, MTG_MINIIMAGE_HEIGHT, "back_thumb",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("back_thumb.jpg", RETRIEVE_MANAGE);
|
||||
resources.RetrieveQuad("back_thumb.jpg", 0, 0, MTG_MINIIMAGE_WIDTH, MTG_MINIIMAGE_HEIGHT, "back_thumb", RETRIEVE_MANAGE);
|
||||
|
||||
LOG("--Loading particles.png");
|
||||
resources.RetrieveTexture("particles.png",RETRIEVE_MANAGE);
|
||||
jq = resources.RetrieveQuad("particles.png", 0, 0, 32, 32, "particles",RETRIEVE_MANAGE);
|
||||
if (jq) jq->SetHotSpot(16,16);
|
||||
jq = resources.RetrieveQuad("particles.png", 64, 0, 32, 32, "stars",RETRIEVE_MANAGE);
|
||||
if (jq) jq->SetHotSpot(16,16);
|
||||
resources.RetrieveTexture("particles.png", RETRIEVE_MANAGE);
|
||||
jq = resources.RetrieveQuad("particles.png", 0, 0, 32, 32, "particles", RETRIEVE_MANAGE);
|
||||
if (jq)
|
||||
jq->SetHotSpot(16, 16);
|
||||
jq = resources.RetrieveQuad("particles.png", 64, 0, 32, 32, "stars", RETRIEVE_MANAGE);
|
||||
if (jq)
|
||||
jq->SetHotSpot(16, 16);
|
||||
|
||||
LOG("--Loading fonts");
|
||||
string lang = options[Options::LANG].str;
|
||||
@@ -166,23 +174,26 @@ void GameApp::Create()
|
||||
resources.InitFonts(lang);
|
||||
|
||||
LOG("--Loading various textures");
|
||||
resources.RetrieveTexture("phasebar.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("wood.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("gold.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("goldglow.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("backdrop.jpg",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("handback.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("BattleIcon.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("DefenderIcon.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("shadow.png",RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("phasebar.png", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("wood.png", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("gold.png", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("goldglow.png", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("backdrop.jpg", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("handback.png", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("BattleIcon.png", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("DefenderIcon.png", RETRIEVE_MANAGE);
|
||||
resources.RetrieveTexture("shadow.png", RETRIEVE_MANAGE);
|
||||
|
||||
jq = resources.RetrieveQuad("BattleIcon.png", 0, 0, 25, 25,"BattleIcon",RETRIEVE_MANAGE);
|
||||
if (jq) jq->SetHotSpot(12, 12);
|
||||
jq = resources.RetrieveQuad("DefenderIcon.png", 0, 0, 24, 23,"DefenderIcon",RETRIEVE_MANAGE);
|
||||
if (jq) jq->SetHotSpot(12, 12);
|
||||
jq = resources.RetrieveQuad("shadow.png", 0, 0, 16, 16,"shadow",RETRIEVE_MANAGE);
|
||||
if (jq) jq->SetHotSpot(8, 8);
|
||||
jq = resources.RetrieveQuad("phasebar.png",0,0,0,0,"phasebar",RETRIEVE_MANAGE);
|
||||
jq = resources.RetrieveQuad("BattleIcon.png", 0, 0, 25, 25, "BattleIcon", RETRIEVE_MANAGE);
|
||||
if (jq)
|
||||
jq->SetHotSpot(12, 12);
|
||||
jq = resources.RetrieveQuad("DefenderIcon.png", 0, 0, 24, 23, "DefenderIcon", RETRIEVE_MANAGE);
|
||||
if (jq)
|
||||
jq->SetHotSpot(12, 12);
|
||||
jq = resources.RetrieveQuad("shadow.png", 0, 0, 16, 16, "shadow", RETRIEVE_MANAGE);
|
||||
if (jq)
|
||||
jq->SetHotSpot(8, 8);
|
||||
jq = resources.RetrieveQuad("phasebar.png", 0, 0, 0, 0, "phasebar", RETRIEVE_MANAGE);
|
||||
|
||||
LOG("Init Collection");
|
||||
collection = NEW MTGAllCards();
|
||||
@@ -224,29 +235,29 @@ void GameApp::Create()
|
||||
LOG("Game Creation Done.");
|
||||
}
|
||||
|
||||
|
||||
void GameApp::LoadGameStates()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GameApp::Destroy()
|
||||
{
|
||||
LOG("==Destroying GameApp==");
|
||||
for (int i=GAME_STATE_MENU;i<=GAME_STATE_MAX-1;i++)
|
||||
for (int i = GAME_STATE_MENU; i <= GAME_STATE_MAX - 1; i++)
|
||||
{
|
||||
if (mGameStates[i])
|
||||
{
|
||||
if (mGameStates[i]){
|
||||
mGameStates[i]->Destroy();
|
||||
SAFE_DELETE(mGameStates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (collection){
|
||||
if (collection)
|
||||
{
|
||||
collection->destroyAllCards();
|
||||
SAFE_DELETE(collection);
|
||||
}
|
||||
delete(DeckStats::GetInstance());
|
||||
delete (DeckStats::GetInstance());
|
||||
|
||||
SAFE_DELETE(Subtypes::subtypesList);
|
||||
SAFE_DELETE(DeckMetaDataList::decksMetaData);
|
||||
@@ -264,11 +275,10 @@ void GameApp::Destroy()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GameApp::Update()
|
||||
{
|
||||
if (systemError.size()) return;
|
||||
if (systemError.size())
|
||||
return;
|
||||
JGE* mEngine = JGE::GetInstance();
|
||||
if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonClick(JGE_BTN_CANCEL))
|
||||
{
|
||||
@@ -277,7 +287,8 @@ void GameApp::Update()
|
||||
JRenderer::GetInstance()->ScreenShot(s);
|
||||
}
|
||||
//Exit when START and X ARE PRESSED SIMULTANEOUSLY
|
||||
if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_SEC)){
|
||||
if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_SEC))
|
||||
{
|
||||
mEngine->End();
|
||||
return;
|
||||
}
|
||||
@@ -291,20 +302,24 @@ void GameApp::Update()
|
||||
dt = 35.0f;
|
||||
|
||||
TransitionBase * mTrans = NULL;
|
||||
if (mCurrentState){
|
||||
if (mCurrentState)
|
||||
{
|
||||
mCurrentState->Update(dt);
|
||||
if(mGameStates[GAME_STATE_TRANSITION] == mCurrentState)
|
||||
if (mGameStates[GAME_STATE_TRANSITION] == mCurrentState)
|
||||
mTrans = (TransitionBase *) mGameStates[GAME_STATE_TRANSITION];
|
||||
}
|
||||
//Check for finished transitions.
|
||||
if(mTrans && mTrans->Finished()){
|
||||
if (mTrans && mTrans->Finished())
|
||||
{
|
||||
mTrans->End();
|
||||
if(mTrans->to != NULL && !mTrans->bAnimationOnly){
|
||||
if (mTrans->to != NULL && !mTrans->bAnimationOnly)
|
||||
{
|
||||
mCurrentState = mTrans->to;
|
||||
SAFE_DELETE(mGameStates[GAME_STATE_TRANSITION]);
|
||||
mCurrentState->Start();
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
mCurrentState = mTrans->from;
|
||||
SAFE_DELETE(mGameStates[GAME_STATE_TRANSITION]);
|
||||
}
|
||||
@@ -331,13 +346,14 @@ void GameApp::Update()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GameApp::Render()
|
||||
{
|
||||
if (systemError.size()){
|
||||
if (systemError.size())
|
||||
{
|
||||
fprintf(stderr, "%s", systemError.c_str());
|
||||
WFont * mFont= resources.GetWFont(Fonts::MAIN_FONT);
|
||||
if (mFont) mFont->DrawString(systemError.c_str(),1,1);
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
if (mFont)
|
||||
mFont->DrawString(systemError.c_str(), 1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -359,7 +375,8 @@ void GameApp::Render()
|
||||
WFont * mFont= resources.GetWFont(Fonts::MAIN_FONT);
|
||||
char buf[512];
|
||||
sprintf(buf, "avg:%.02f - %.02f fps",totalFPS/nbUpdates, fps);
|
||||
if (mFont) {
|
||||
if (mFont)
|
||||
{
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(buf, 10, SCREEN_HEIGHT-15);
|
||||
}
|
||||
@@ -372,70 +389,83 @@ void GameApp::SetNextState(int state)
|
||||
mNextState = mGameStates[state];
|
||||
}
|
||||
|
||||
void GameApp::Pause(){
|
||||
void GameApp::Pause()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameApp::Resume(){
|
||||
void GameApp::Resume()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameApp::DoTransition(int trans, int tostate, float dur, bool animonly){
|
||||
void GameApp::DoTransition(int trans, int tostate, float dur, bool animonly)
|
||||
{
|
||||
TransitionBase * tb = NULL;
|
||||
GameState * toState = NULL;
|
||||
if(options[Options::TRANSITIONS].number != 0){
|
||||
if(tostate != GAME_STATE_NONE)
|
||||
if (options[Options::TRANSITIONS].number != 0)
|
||||
{
|
||||
if (tostate != GAME_STATE_NONE)
|
||||
SetNextState(tostate);
|
||||
return;
|
||||
}
|
||||
|
||||
if(tostate > GAME_STATE_NONE && tostate < GAME_STATE_MAX)
|
||||
if (tostate > GAME_STATE_NONE && tostate < GAME_STATE_MAX)
|
||||
toState = mGameStates[tostate];
|
||||
|
||||
if(mGameStates[GAME_STATE_TRANSITION]){
|
||||
tb =(TransitionBase*) mGameStates[GAME_STATE_TRANSITION];
|
||||
if(toState)
|
||||
if (mGameStates[GAME_STATE_TRANSITION])
|
||||
{
|
||||
tb = (TransitionBase*) mGameStates[GAME_STATE_TRANSITION];
|
||||
if (toState)
|
||||
tb->to = toState; //Additional calls to transition merely update the destination.
|
||||
return;
|
||||
}
|
||||
|
||||
if(dur < 0)
|
||||
if (dur < 0)
|
||||
dur = DEFAULT_DURATION; // Default to this value.
|
||||
switch(trans){
|
||||
switch (trans)
|
||||
{
|
||||
case TRANSITION_FADE_IN:
|
||||
tb = NEW TransitionFade(this,mCurrentState,toState,dur,true);
|
||||
tb = NEW TransitionFade(this, mCurrentState, toState, dur, true);
|
||||
break;
|
||||
case TRANSITION_FADE:
|
||||
default:
|
||||
tb = NEW TransitionFade(this,mCurrentState,toState,dur,false);
|
||||
tb = NEW TransitionFade(this, mCurrentState, toState, dur, false);
|
||||
}
|
||||
if(tb){
|
||||
if (tb)
|
||||
{
|
||||
tb->bAnimationOnly = animonly;
|
||||
mGameStates[GAME_STATE_TRANSITION] = tb;
|
||||
mGameStates[GAME_STATE_TRANSITION]->Start();
|
||||
mCurrentState = tb; //The old current state is ended inside our transition.
|
||||
} else if(toState) { //Somehow failed, just do standard SetNextState behaviour
|
||||
}
|
||||
else if (toState)
|
||||
{ //Somehow failed, just do standard SetNextState behavior
|
||||
mNextState = toState;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GameApp::DoAnimation(int trans, float dur){
|
||||
DoTransition(trans,GAME_STATE_NONE,dur,true);
|
||||
void GameApp::DoAnimation(int trans, float dur)
|
||||
{
|
||||
DoTransition(trans, GAME_STATE_NONE, dur, true);
|
||||
}
|
||||
|
||||
void GameApp::playMusic(string filename, bool loop) {
|
||||
void GameApp::playMusic(string filename, bool loop)
|
||||
{
|
||||
if (filename.compare(currentMusicFile) == 0)
|
||||
return;
|
||||
|
||||
if (music) {
|
||||
if (music)
|
||||
{
|
||||
JSoundSystem::GetInstance()->StopMusic(music);
|
||||
SAFE_DELETE(music);
|
||||
}
|
||||
|
||||
if (HasMusic && options[Options::MUSICVOLUME].number > 0){
|
||||
if (HasMusic && options[Options::MUSICVOLUME].number > 0)
|
||||
{
|
||||
music = resources.ssLoadMusic(filename.c_str());
|
||||
if (music) JSoundSystem::GetInstance()->PlayMusic(music, loop);
|
||||
if (music)
|
||||
JSoundSystem::GetInstance()->PlayMusic(music, loop);
|
||||
currentMusicFile = filename;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ static char GameName[] = "Wagic";
|
||||
JApp* JGameLauncher::GetGameApp()
|
||||
{
|
||||
return NEW GameApp();
|
||||
};
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
char *JGameLauncher::GetName()
|
||||
@@ -28,7 +28,6 @@ char *JGameLauncher::GetName()
|
||||
return GameName;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
u32 JGameLauncher::GetInitFlags()
|
||||
{
|
||||
|
||||
+316
-190
@@ -11,7 +11,6 @@
|
||||
|
||||
GameObserver * GameObserver::mInstance = NULL;
|
||||
|
||||
|
||||
GameObserver* GameObserver::GetInstance()
|
||||
{
|
||||
|
||||
@@ -24,13 +23,15 @@ void GameObserver::EndInstance()
|
||||
SAFE_DELETE(mInstance);
|
||||
}
|
||||
|
||||
void GameObserver::Init(Player * _players[], int _nbplayers){
|
||||
void GameObserver::Init(Player * _players[], int _nbplayers)
|
||||
{
|
||||
mInstance = NEW GameObserver(_players, _nbplayers);
|
||||
}
|
||||
|
||||
|
||||
GameObserver::GameObserver(Player * _players[], int _nb_players){
|
||||
for (int i = 0; i < _nb_players;i ++){
|
||||
GameObserver::GameObserver(Player * _players[], int _nb_players)
|
||||
{
|
||||
for (int i = 0; i < _nb_players; i++)
|
||||
{
|
||||
players[i] = _players[i];
|
||||
}
|
||||
currentPlayer = NULL;
|
||||
@@ -50,38 +51,47 @@ GameObserver::GameObserver(Player * _players[], int _nb_players){
|
||||
mRules = NULL;
|
||||
}
|
||||
|
||||
int GameObserver::getCurrentGamePhase(){
|
||||
int GameObserver::getCurrentGamePhase()
|
||||
{
|
||||
return currentGamePhase;
|
||||
}
|
||||
|
||||
|
||||
Player * GameObserver::opponent(){
|
||||
int index = (currentPlayerId+1)%nbPlayers;
|
||||
Player * GameObserver::opponent()
|
||||
{
|
||||
int index = (currentPlayerId + 1) % nbPlayers;
|
||||
return players[index];
|
||||
}
|
||||
|
||||
|
||||
void GameObserver::nextPlayer(){
|
||||
void GameObserver::nextPlayer()
|
||||
{
|
||||
turn++;
|
||||
currentPlayerId = (currentPlayerId+1)%nbPlayers;
|
||||
currentPlayerId = (currentPlayerId + 1) % nbPlayers;
|
||||
currentPlayer = players[currentPlayerId];
|
||||
currentActionPlayer = currentPlayer;
|
||||
combatStep = BLOCKERS;
|
||||
}
|
||||
void GameObserver::nextGamePhase(){
|
||||
void GameObserver::nextGamePhase()
|
||||
{
|
||||
Phase * cPhaseOld = phaseRing->getCurrentPhase();
|
||||
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE)
|
||||
if (FIRST_STRIKE == combatStep || END_FIRST_STRIKE == combatStep || DAMAGE == combatStep) {
|
||||
nextCombatStep(); return;
|
||||
if (FIRST_STRIKE == combatStep || END_FIRST_STRIKE == combatStep || DAMAGE == combatStep)
|
||||
{
|
||||
nextCombatStep();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS)
|
||||
if (BLOCKERS == combatStep || TRIGGERS == combatStep) { nextCombatStep(); return; }
|
||||
if (BLOCKERS == combatStep || TRIGGERS == combatStep)
|
||||
{
|
||||
nextCombatStep();
|
||||
return;
|
||||
}
|
||||
|
||||
phaseRing->forward();
|
||||
|
||||
//Go directly to end of combat if no attackers
|
||||
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATATTACKERS && !(currentPlayer->game->inPlay->getNextAttacker(NULL))){
|
||||
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATATTACKERS && !(currentPlayer->game->inPlay->getNextAttacker(NULL)))
|
||||
{
|
||||
phaseRing->forward();
|
||||
phaseRing->forward();
|
||||
}
|
||||
@@ -92,11 +102,12 @@ void GameObserver::nextGamePhase(){
|
||||
if (Constants::MTG_PHASE_COMBATDAMAGE == currentGamePhase)
|
||||
nextCombatStep();
|
||||
|
||||
if (currentPlayer != cPhase->player) nextPlayer();
|
||||
|
||||
if (currentPlayer != cPhase->player)
|
||||
nextPlayer();
|
||||
|
||||
//init begin of turn
|
||||
if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN){
|
||||
if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN)
|
||||
{
|
||||
cleanupPhase();
|
||||
currentPlayer->canPutLandsIntoPlay = 1;
|
||||
currentPlayer->castedspellsthisturn = 0;
|
||||
@@ -110,7 +121,8 @@ void GameObserver::nextGamePhase(){
|
||||
mLayers->actionLayer()->cleanGarbage(); //clean abilities history for this turn;
|
||||
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
|
||||
mLayers->actionLayer()->Update(0);
|
||||
for (int i=0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
delete (players[i]->game->garbage);
|
||||
players[i]->game->garbage = NEW MTGGameZone();
|
||||
players[i]->game->garbage->setOwner(players[i]);
|
||||
@@ -122,16 +134,18 @@ void GameObserver::nextGamePhase(){
|
||||
for (int i = 0; i < 2; ++i)
|
||||
players[i]->getManaPool()->init();
|
||||
|
||||
if (currentGamePhase == Constants::MTG_PHASE_AFTER_EOT){
|
||||
if (currentGamePhase == Constants::MTG_PHASE_AFTER_EOT)
|
||||
{
|
||||
//Auto Hand cleaning, in case the player didn't do it himself
|
||||
while(currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize < 1)
|
||||
while (currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize < 1)
|
||||
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
|
||||
mLayers->actionLayer()->Update(0);
|
||||
return nextGamePhase();
|
||||
}
|
||||
|
||||
//Phase Specific actions
|
||||
switch(currentGamePhase){
|
||||
switch (currentGamePhase)
|
||||
{
|
||||
case Constants::MTG_PHASE_UNTAP:
|
||||
untapPhase();
|
||||
break;
|
||||
@@ -146,7 +160,8 @@ void GameObserver::nextGamePhase(){
|
||||
}
|
||||
}
|
||||
|
||||
int GameObserver::cancelCurrentAction(){
|
||||
int GameObserver::cancelCurrentAction()
|
||||
{
|
||||
SAFE_DELETE(targetChooser);
|
||||
return mLayers->actionLayer()->cancelCurrentAction();
|
||||
}
|
||||
@@ -155,32 +170,45 @@ void GameObserver::nextCombatStep()
|
||||
{
|
||||
switch (combatStep)
|
||||
{
|
||||
case BLOCKERS :
|
||||
case BLOCKERS:
|
||||
receiveEvent(NEW WEventBlockersChosen());
|
||||
receiveEvent(NEW WEventCombatStepChange(combatStep = TRIGGERS));
|
||||
return;
|
||||
|
||||
case TRIGGERS : receiveEvent(NEW WEventCombatStepChange(combatStep = ORDER)); return;
|
||||
case ORDER : receiveEvent(NEW WEventCombatStepChange(combatStep = FIRST_STRIKE)); return;
|
||||
case FIRST_STRIKE : receiveEvent(NEW WEventCombatStepChange(combatStep = END_FIRST_STRIKE)); return;
|
||||
case END_FIRST_STRIKE : receiveEvent(NEW WEventCombatStepChange(combatStep = DAMAGE)); return;
|
||||
case DAMAGE : receiveEvent(NEW WEventCombatStepChange(combatStep = END_DAMAGE)); return;
|
||||
case END_DAMAGE : ; // Nothing : go to next phase
|
||||
case TRIGGERS:
|
||||
receiveEvent(NEW WEventCombatStepChange(combatStep = ORDER));
|
||||
return;
|
||||
case ORDER:
|
||||
receiveEvent(NEW WEventCombatStepChange(combatStep = FIRST_STRIKE));
|
||||
return;
|
||||
case FIRST_STRIKE:
|
||||
receiveEvent(NEW WEventCombatStepChange(combatStep = END_FIRST_STRIKE));
|
||||
return;
|
||||
case END_FIRST_STRIKE:
|
||||
receiveEvent(NEW WEventCombatStepChange(combatStep = DAMAGE));
|
||||
return;
|
||||
case DAMAGE:
|
||||
receiveEvent(NEW WEventCombatStepChange(combatStep = END_DAMAGE));
|
||||
return;
|
||||
case END_DAMAGE:
|
||||
; // Nothing : go to next phase
|
||||
}
|
||||
}
|
||||
|
||||
void GameObserver::userRequestNextGamePhase(){
|
||||
if (mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)) return;
|
||||
if (getCurrentTargetChooser()) return;
|
||||
void GameObserver::userRequestNextGamePhase()
|
||||
{
|
||||
if (mLayers->stackLayer()->getNext(NULL, 0, NOT_RESOLVED))
|
||||
return;
|
||||
if (getCurrentTargetChooser())
|
||||
return;
|
||||
|
||||
bool executeNextPhaseImmediately = true;
|
||||
|
||||
Phase * cPhaseOld = phaseRing->getCurrentPhase();
|
||||
if ((cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == ORDER) ||
|
||||
(cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == TRIGGERS)||
|
||||
cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE ||
|
||||
opponent()->isAI() ||
|
||||
options[Options::optionInterrupt(currentGamePhase)].number)
|
||||
if ((cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == ORDER) || (cPhaseOld->id
|
||||
== Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == TRIGGERS) || cPhaseOld->id
|
||||
== Constants::MTG_PHASE_COMBATDAMAGE || opponent()->isAI()
|
||||
|| options[Options::optionInterrupt(currentGamePhase)].number)
|
||||
{
|
||||
executeNextPhaseImmediately = false;
|
||||
}
|
||||
@@ -195,7 +223,8 @@ void GameObserver::userRequestNextGamePhase(){
|
||||
}
|
||||
}
|
||||
|
||||
int GameObserver::forceShuffleLibraries(){
|
||||
int GameObserver::forceShuffleLibraries()
|
||||
{
|
||||
int result = 0;
|
||||
if (players[0]->game->library->needShuffle)
|
||||
{
|
||||
@@ -212,13 +241,14 @@ int GameObserver::forceShuffleLibraries(){
|
||||
return result;
|
||||
}
|
||||
|
||||
void GameObserver::startGame(Rules * rules){
|
||||
void GameObserver::startGame(Rules * rules)
|
||||
{
|
||||
turn = 0;
|
||||
mRules = rules;
|
||||
if (rules)
|
||||
rules->initPlayers();
|
||||
|
||||
options.automaticStyle(players[0],players[1]);
|
||||
options.automaticStyle(players[0], players[1]);
|
||||
|
||||
mLayers = NEW DuelLayers();
|
||||
mLayers->init();
|
||||
@@ -226,39 +256,44 @@ void GameObserver::startGame(Rules * rules){
|
||||
currentPlayerId = 0;
|
||||
currentPlayer = players[0];
|
||||
currentActionPlayer = currentPlayer;
|
||||
phaseRing = NEW PhaseRing(players,nbPlayers);
|
||||
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++){
|
||||
resources.RetrieveCard(players[0]->game->hand->cards[i],CACHE_THUMB);
|
||||
if (!players[0]->isAI())
|
||||
{
|
||||
for (int i = 0; i < players[0]->game->hand->nb_cards; i++)
|
||||
{
|
||||
resources.RetrieveCard(players[0]->game->hand->cards[i], CACHE_THUMB);
|
||||
resources.RetrieveCard(players[0]->game->hand->cards[i]);
|
||||
}
|
||||
}
|
||||
|
||||
startedAt = time(0);
|
||||
|
||||
|
||||
//Difficult mode special stuff
|
||||
if (!players[0]->isAI() && players[1]->isAI()){
|
||||
if (!players[0]->isAI() && players[1]->isAI())
|
||||
{
|
||||
int difficulty = options[Options::DIFFICULTY].number;
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number && difficulty) {
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number && difficulty)
|
||||
{
|
||||
Player * p = players[1];
|
||||
for (int level=0; level < difficulty; level ++){
|
||||
for (int level = 0; level < difficulty; level++)
|
||||
{
|
||||
MTGCardInstance * card = NULL;
|
||||
MTGGameZone * z = p->game->library;
|
||||
for (int j = 0; j<z->nb_cards; j++){
|
||||
for (int j = 0; j < z->nb_cards; j++)
|
||||
{
|
||||
MTGCardInstance * _card = z->cards[j];
|
||||
if (_card->hasType("land")){
|
||||
if (_card->hasType("land"))
|
||||
{
|
||||
card = _card;
|
||||
j = z->nb_cards;
|
||||
}
|
||||
}
|
||||
if (card){
|
||||
if (card)
|
||||
{
|
||||
MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack);
|
||||
Spell * spell = NEW Spell(copy);
|
||||
spell->resolve();
|
||||
@@ -269,77 +304,78 @@ void GameObserver::startGame(Rules * rules){
|
||||
}
|
||||
}
|
||||
|
||||
void GameObserver::addObserver(MTGAbility * observer){
|
||||
void GameObserver::addObserver(MTGAbility * observer)
|
||||
{
|
||||
mLayers->actionLayer()->Add(observer);
|
||||
}
|
||||
|
||||
|
||||
void GameObserver::removeObserver(ActionElement * observer){
|
||||
if (observer)mLayers->actionLayer()->moveToGarbage(observer);
|
||||
void GameObserver::removeObserver(ActionElement * observer)
|
||||
{
|
||||
if (observer)
|
||||
mLayers->actionLayer()->moveToGarbage(observer);
|
||||
|
||||
else
|
||||
{} //TODO log error
|
||||
{
|
||||
} //TODO log error
|
||||
}
|
||||
|
||||
GameObserver::~GameObserver(){
|
||||
GameObserver::~GameObserver()
|
||||
{
|
||||
LOG("==Destroying GameObserver==");
|
||||
SAFE_DELETE(targetChooser);
|
||||
SAFE_DELETE(mLayers);
|
||||
SAFE_DELETE(phaseRing);
|
||||
SAFE_DELETE(replacementEffects);
|
||||
for (int i = 0; i < nbPlayers; ++i){
|
||||
for (int i = 0; i < nbPlayers; ++i)
|
||||
{
|
||||
SAFE_DELETE(players[i]);
|
||||
}
|
||||
LOG("==GameObserver Destroyed==");
|
||||
}
|
||||
|
||||
void GameObserver::Update(float dt){
|
||||
void GameObserver::Update(float dt)
|
||||
{
|
||||
Player * player = currentPlayer;
|
||||
if (Constants::MTG_PHASE_COMBATBLOCKERS == currentGamePhase && BLOCKERS == combatStep)
|
||||
player = player->opponent();
|
||||
|
||||
currentActionPlayer = player;
|
||||
if (isInterrupting) player = isInterrupting;
|
||||
mLayers->Update(dt,player);
|
||||
if (isInterrupting)
|
||||
player = isInterrupting;
|
||||
mLayers->Update(dt, player);
|
||||
|
||||
while (mLayers->actionLayer()->stuffHappened){
|
||||
while (mLayers->actionLayer()->stuffHappened)
|
||||
{
|
||||
mLayers->actionLayer()->Update(0);
|
||||
}
|
||||
stateEffects();
|
||||
oldGamePhase = currentGamePhase;
|
||||
|
||||
|
||||
if (combatStep == TRIGGERS)
|
||||
{
|
||||
if (!mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED))
|
||||
if (!mLayers->stackLayer()->getNext(NULL, 0, NOT_RESOLVED))
|
||||
{
|
||||
mLayers->stackLayer()->AddNextCombatStep();
|
||||
}
|
||||
}
|
||||
|
||||
//Auto skip Phases
|
||||
int skipLevel = (player->playMode == Player::MODE_TEST_SUITE) ? Constants::ASKIP_NONE :
|
||||
options[Options::ASPHASES].number;
|
||||
int skipLevel = (player->playMode == Player::MODE_TEST_SUITE) ? Constants::ASKIP_NONE : options[Options::ASPHASES].number;
|
||||
int nrCreatures = currentPlayer->game->inPlay->countByType("Creature");
|
||||
|
||||
if (skipLevel == Constants::ASKIP_SAFE || skipLevel == Constants::ASKIP_FULL) {
|
||||
if ((opponent()->isAI() && !(isInterrupting)) &&
|
||||
(
|
||||
currentGamePhase == Constants::MTG_PHASE_UNTAP
|
||||
|| currentGamePhase == Constants::MTG_PHASE_DRAW
|
||||
|| currentGamePhase == Constants::MTG_PHASE_COMBATBEGIN
|
||||
|| ((currentGamePhase == Constants::MTG_PHASE_COMBATATTACKERS) && (nrCreatures == 0))
|
||||
|| currentGamePhase == Constants::MTG_PHASE_COMBATEND
|
||||
|| currentGamePhase == Constants::MTG_PHASE_ENDOFTURN
|
||||
|| ((currentGamePhase == Constants::MTG_PHASE_CLEANUP) && (currentPlayer->game->hand->nb_cards < 8))
|
||||
))
|
||||
if (skipLevel == Constants::ASKIP_SAFE || skipLevel == Constants::ASKIP_FULL)
|
||||
{
|
||||
if ((opponent()->isAI() && !(isInterrupting)) && (currentGamePhase == Constants::MTG_PHASE_UNTAP || currentGamePhase
|
||||
== Constants::MTG_PHASE_DRAW || currentGamePhase == Constants::MTG_PHASE_COMBATBEGIN || ((currentGamePhase
|
||||
== Constants::MTG_PHASE_COMBATATTACKERS) && (nrCreatures == 0)) || currentGamePhase
|
||||
== Constants::MTG_PHASE_COMBATEND || currentGamePhase == Constants::MTG_PHASE_ENDOFTURN
|
||||
|| ((currentGamePhase == Constants::MTG_PHASE_CLEANUP) && (currentPlayer->game->hand->nb_cards < 8))))
|
||||
userRequestNextGamePhase();
|
||||
}
|
||||
if (skipLevel == Constants::ASKIP_FULL) {
|
||||
if ((opponent()->isAI() && !(isInterrupting)) &&
|
||||
(currentGamePhase == Constants::MTG_PHASE_UPKEEP
|
||||
|| currentGamePhase == Constants::MTG_PHASE_COMBATDAMAGE
|
||||
))
|
||||
if (skipLevel == Constants::ASKIP_FULL)
|
||||
{
|
||||
if ((opponent()->isAI() && !(isInterrupting)) && (currentGamePhase == Constants::MTG_PHASE_UPKEEP || currentGamePhase
|
||||
== Constants::MTG_PHASE_COMBATDAMAGE))
|
||||
userRequestNextGamePhase();
|
||||
|
||||
}
|
||||
@@ -349,78 +385,95 @@ void GameObserver::Update(float dt){
|
||||
//Players life test
|
||||
void GameObserver::stateEffects()
|
||||
{
|
||||
if (mLayers->stackLayer()->count(0,NOT_RESOLVED) != 0) return;
|
||||
if (mLayers->actionLayer()->menuObject) return;
|
||||
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()) return;
|
||||
for (int i =0; i < 2; i++){
|
||||
if (mLayers->stackLayer()->count(0, NOT_RESOLVED) != 0)
|
||||
return;
|
||||
if (mLayers->actionLayer()->menuObject)
|
||||
return;
|
||||
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer())
|
||||
return;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
MTGGameZone * zone = players[i]->game->inPlay;
|
||||
for (int j = zone->nb_cards-1 ; j>=0; j--){
|
||||
for (int j = zone->nb_cards - 1; j >= 0; j--)
|
||||
{
|
||||
MTGCardInstance * card = zone->cards[j];
|
||||
card->afterDamage();
|
||||
|
||||
//Remove auras that don't have a valid target anymore
|
||||
if (card->target && !isInPlay(card->target) && !card->hasType("equipment")){
|
||||
if (card->target && !isInPlay(card->target) && !card->hasType("equipment"))
|
||||
{
|
||||
players[i]->game->putInGraveyard(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i =0; i < 2; i++)
|
||||
if (players[i]->life <= 0){
|
||||
for (int i = 0; i < 2; i++)
|
||||
if (players[i]->life <= 0)
|
||||
{
|
||||
int cantlosers = 0;
|
||||
MTGGameZone * z = players[i]->game->inPlay;
|
||||
int nbcards = z->nb_cards;
|
||||
for (int j = 0; j < nbcards; ++j){
|
||||
for (int j = 0; j < nbcards; ++j)
|
||||
{
|
||||
MTGCardInstance * c = z->cards[j];
|
||||
if (c->has(Constants::CANTLOSE) || c->has(Constants::CANTLIFELOSE)){
|
||||
if (c->has(Constants::CANTLOSE) || c->has(Constants::CANTLIFELOSE))
|
||||
{
|
||||
cantlosers++;
|
||||
}
|
||||
}
|
||||
MTGGameZone * k = players[i]->opponent()->game->inPlay;
|
||||
int onbcards = k->nb_cards;
|
||||
for (int m = 0; m < onbcards; ++m){
|
||||
for (int m = 0; m < onbcards; ++m)
|
||||
{
|
||||
MTGCardInstance * e = k->cards[m];
|
||||
if (e->has(Constants::CANTWIN)){
|
||||
if (e->has(Constants::CANTWIN))
|
||||
{
|
||||
cantlosers++;
|
||||
}
|
||||
}
|
||||
if(cantlosers < 1){
|
||||
if (cantlosers < 1)
|
||||
{
|
||||
gameOver = players[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i =0; i < 2; i++)
|
||||
if (players[i]->poisonCount >= 10) gameOver = players[i];
|
||||
for (int i = 0; i < 2; i++)
|
||||
if (players[i]->poisonCount >= 10)
|
||||
gameOver = players[i];
|
||||
}
|
||||
|
||||
|
||||
void GameObserver::Render()
|
||||
{
|
||||
mLayers->Render();
|
||||
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer())
|
||||
JRenderer::GetInstance()->DrawRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(255,255,0,0));
|
||||
JRenderer::GetInstance()->DrawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(255,255,0,0));
|
||||
if (waitForExtraPayment)
|
||||
waitForExtraPayment->Render();
|
||||
for (int i = 0; i < nbPlayers; ++i){
|
||||
for (int i = 0; i < nbPlayers; ++i)
|
||||
{
|
||||
players[i]->Render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void GameObserver::ButtonPressed(PlayGuiObject * target){
|
||||
void GameObserver::ButtonPressed(PlayGuiObject * target)
|
||||
{
|
||||
DebugTrace("GAMEOBSERVER Click");
|
||||
if (CardView* cardview = dynamic_cast<CardView*>(target)){
|
||||
if (CardView* cardview = dynamic_cast<CardView*>(target))
|
||||
{
|
||||
MTGCardInstance * card = cardview->getCard();
|
||||
cardClick(card, card);
|
||||
}
|
||||
else if (GuiLibrary* library = dynamic_cast<GuiLibrary*>(target)){
|
||||
if (library->showCards){
|
||||
else if (GuiLibrary* library = dynamic_cast<GuiLibrary*>(target))
|
||||
{
|
||||
if (library->showCards)
|
||||
{
|
||||
library->toggleDisplay();
|
||||
forceShuffleLibraries();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
TargetChooser * _tc = this->getCurrentTargetChooser();
|
||||
if (_tc && _tc->targetsZone(library->zone)){
|
||||
if (_tc && _tc->targetsZone(library->zone))
|
||||
{
|
||||
library->toggleDisplay();
|
||||
library->zone->needShuffle = true;
|
||||
}
|
||||
@@ -428,53 +481,78 @@ void GameObserver::ButtonPressed(PlayGuiObject * target){
|
||||
}
|
||||
else if (GuiGraveyard* graveyard = dynamic_cast<GuiGraveyard*>(target))
|
||||
graveyard->toggleDisplay();
|
||||
//opponenthand
|
||||
//opponenthand
|
||||
else if (GuiOpponentHand* opponentHand = dynamic_cast<GuiOpponentHand*>(target))
|
||||
if (opponentHand->showCards){
|
||||
if (opponentHand->showCards)
|
||||
{
|
||||
opponentHand->toggleDisplay();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
TargetChooser * _tc = this->getCurrentTargetChooser();
|
||||
if (_tc && _tc->targetsZone(opponentHand->zone)){
|
||||
if (_tc && _tc->targetsZone(opponentHand->zone))
|
||||
{
|
||||
opponentHand->toggleDisplay();
|
||||
}
|
||||
}
|
||||
//end opponenthand
|
||||
else if (GuiAvatar* avatar = dynamic_cast<GuiAvatar*>(target)){
|
||||
//end opponenthand
|
||||
else if (GuiAvatar* avatar = dynamic_cast<GuiAvatar*>(target))
|
||||
{
|
||||
cardClick(NULL, avatar->player);
|
||||
}
|
||||
}
|
||||
|
||||
void GameObserver::stackObjectClicked(Interruptible * action){
|
||||
if (targetChooser != NULL){
|
||||
void GameObserver::stackObjectClicked(Interruptible * action)
|
||||
{
|
||||
if (targetChooser != NULL)
|
||||
{
|
||||
int result = targetChooser->toggleTarget(action);
|
||||
if (result == TARGET_OK_FULL){
|
||||
if (result == TARGET_OK_FULL)
|
||||
{
|
||||
cardClick(cardWaitingForTargets);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
|
||||
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(action);
|
||||
if (reaction == -1)
|
||||
mLayers->actionLayer()->reactToTargetClick(action);
|
||||
}
|
||||
}
|
||||
|
||||
void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
|
||||
void GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
|
||||
{
|
||||
Player * clickedPlayer = NULL;
|
||||
if (!card) clickedPlayer = ((Player *)object);
|
||||
if (targetChooser){
|
||||
if (!card)
|
||||
clickedPlayer = ((Player *) object);
|
||||
if (targetChooser)
|
||||
{
|
||||
int result;
|
||||
if (card) {
|
||||
if (card == cardWaitingForTargets){
|
||||
if (card)
|
||||
{
|
||||
if (card == cardWaitingForTargets)
|
||||
{
|
||||
int _result = targetChooser->ForceTargetListReady();
|
||||
if (_result){
|
||||
if (_result)
|
||||
{
|
||||
result = TARGET_OK_FULL;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
result = targetChooser->targetsReadyCheck();
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
result = targetChooser->toggleTarget(card);
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
result = targetChooser->toggleTarget(clickedPlayer);
|
||||
}
|
||||
if (result == TARGET_OK_FULL)
|
||||
@@ -483,11 +561,14 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
|
||||
return;
|
||||
}
|
||||
|
||||
if (waitForExtraPayment){
|
||||
if (card){
|
||||
if (waitForExtraPayment)
|
||||
{
|
||||
if (card)
|
||||
{
|
||||
waitForExtraPayment->tryToSetPayment(card);
|
||||
}
|
||||
if (waitForExtraPayment->isPaymentSet()){
|
||||
if (waitForExtraPayment->isPaymentSet())
|
||||
{
|
||||
mLayers->actionLayer()->reactToClick(waitForExtraPayment->action, waitForExtraPayment->source);
|
||||
waitForExtraPayment = NULL;
|
||||
}
|
||||
@@ -500,141 +581,181 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
|
||||
return;
|
||||
}
|
||||
|
||||
if (card && card->paymenttype <= 0){//card played as normal.
|
||||
if (card && card->paymenttype <= 0)
|
||||
{//card played as normal.
|
||||
|
||||
/* Fix for Issue http://code.google.com/p/wagic/issues/detail?id=270
|
||||
put into play is hopefully the only ability causing that kind of trouble
|
||||
If the same kind of issue occurs with other abilities, let's think of a cleaner solution
|
||||
*/
|
||||
if (targetChooser) {
|
||||
if (targetChooser)
|
||||
{
|
||||
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY);
|
||||
a->reactToClick(card);
|
||||
return;
|
||||
}
|
||||
|
||||
reaction = mLayers->actionLayer()->isReactingToClick(card);
|
||||
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
|
||||
if (reaction == -1)
|
||||
mLayers->actionLayer()->reactToClick(card);
|
||||
}
|
||||
/* added same fix for buyback and alternative cost, the varible "paymenttype = int" only serves one purpose, to tell this bug fix what menu item you clicked on...all alternative cost or play methods suffered from the fix because if the card contained "target=" it would automatically force the play method to putinplayrule...even charge you the original mana cost.*/
|
||||
else if (card && card->paymenttype == 1){//this is alternitive cost
|
||||
if (targetChooser) {
|
||||
else if (card && card->paymenttype == 1)
|
||||
{//this is alternitive cost
|
||||
if (targetChooser)
|
||||
{
|
||||
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::ALTERNATIVE_COST);
|
||||
a->reactToClick(card);
|
||||
return;
|
||||
}
|
||||
|
||||
reaction = mLayers->actionLayer()->isReactingToClick(card);
|
||||
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
|
||||
if (reaction == -1)
|
||||
mLayers->actionLayer()->reactToClick(card);
|
||||
}
|
||||
//--------------
|
||||
else if (card && card->paymenttype == 2){//this is buyback
|
||||
if (targetChooser) {
|
||||
//--------------
|
||||
else if (card && card->paymenttype == 2)
|
||||
{//this is buyback
|
||||
if (targetChooser)
|
||||
{
|
||||
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::BUYBACK_COST);
|
||||
a->reactToClick(card);
|
||||
return;
|
||||
}
|
||||
|
||||
reaction = mLayers->actionLayer()->isReactingToClick(card);
|
||||
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
|
||||
if (reaction == -1)
|
||||
mLayers->actionLayer()->reactToClick(card);
|
||||
}
|
||||
//=====================
|
||||
else if (card && card->paymenttype == 3){//this is Flashback
|
||||
if (targetChooser) {
|
||||
else if (card && card->paymenttype == 3)
|
||||
{//this is Flashback
|
||||
if (targetChooser)
|
||||
{
|
||||
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::FLASHBACK_COST);
|
||||
a->reactToClick(card);
|
||||
return;
|
||||
}
|
||||
|
||||
reaction = mLayers->actionLayer()->isReactingToClick(card);
|
||||
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
|
||||
if (reaction == -1)
|
||||
mLayers->actionLayer()->reactToClick(card);
|
||||
}
|
||||
//=====================
|
||||
else if (card && card->paymenttype == 4){//this is retrace
|
||||
if (targetChooser) {
|
||||
else if (card && card->paymenttype == 4)
|
||||
{//this is retrace
|
||||
if (targetChooser)
|
||||
{
|
||||
MTGAbility * a = mLayers->actionLayer()->getAbility(MTGAbility::RETRACE_COST);
|
||||
a->reactToClick(card);
|
||||
return;
|
||||
}
|
||||
|
||||
reaction = mLayers->actionLayer()->isReactingToClick(card);
|
||||
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
|
||||
if (reaction == -1)
|
||||
mLayers->actionLayer()->reactToClick(card);
|
||||
}
|
||||
//=====================
|
||||
else{//this handles abilities on a menu...not just when card is being played
|
||||
else
|
||||
{//this handles abilities on a menu...not just when card is being played
|
||||
reaction = mLayers->actionLayer()->isReactingToTargetClick(object);
|
||||
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(object);
|
||||
if (reaction == -1)
|
||||
mLayers->actionLayer()->reactToTargetClick(object);
|
||||
}
|
||||
|
||||
if (reaction == -1) return;
|
||||
if (reaction == -1)
|
||||
return;
|
||||
|
||||
if (!card) return;
|
||||
if (!card)
|
||||
return;
|
||||
|
||||
//Current player's hand
|
||||
if (currentPlayer->game->hand->hasCard(card) && currentGamePhase == Constants::MTG_PHASE_CLEANUP && currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize < 1){
|
||||
if (currentPlayer->game->hand->hasCard(card) && currentGamePhase == Constants::MTG_PHASE_CLEANUP
|
||||
&& currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize < 1)
|
||||
{
|
||||
currentPlayer->game->putInGraveyard(card);
|
||||
}else if (reaction){
|
||||
if (reaction == 1){
|
||||
}
|
||||
else if (reaction)
|
||||
{
|
||||
if (reaction == 1)
|
||||
{
|
||||
mLayers->actionLayer()->reactToClick(card);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
mLayers->actionLayer()->setMenuObject(object);
|
||||
}
|
||||
}else if (card->isTapped() && card->controller() == currentPlayer){
|
||||
}
|
||||
else if (card->isTapped() && card->controller() == currentPlayer)
|
||||
{
|
||||
untap(card);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int GameObserver::untap(MTGCardInstance * card) {
|
||||
if (!card->isUntapping()){
|
||||
int GameObserver::untap(MTGCardInstance * card)
|
||||
{
|
||||
if (!card->isUntapping())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (card->has(Constants::DOESNOTUNTAP)) return 0;
|
||||
if (card->frozen > 0) return 0;
|
||||
if (card->has(Constants::DOESNOTUNTAP))
|
||||
return 0;
|
||||
if (card->frozen > 0)
|
||||
return 0;
|
||||
card->attemptUntap();
|
||||
return 1;
|
||||
}
|
||||
|
||||
TargetChooser * GameObserver::getCurrentTargetChooser(){
|
||||
TargetChooser * GameObserver::getCurrentTargetChooser()
|
||||
{
|
||||
TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser();
|
||||
if (_tc) return _tc;
|
||||
if (_tc)
|
||||
return _tc;
|
||||
return targetChooser;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Returns true if the card is in one of the player's play zone */
|
||||
int GameObserver::isInPlay(MTGCardInstance * card){
|
||||
for (int i = 0; i < 2; i++){
|
||||
if (players[i]->game->isInPlay(card)) return 1;
|
||||
int GameObserver::isInPlay(MTGCardInstance * card)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (players[i]->game->isInPlay(card))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GameObserver::draw(){
|
||||
void GameObserver::draw()
|
||||
{
|
||||
currentPlayer->game->drawFromLibrary();
|
||||
}
|
||||
|
||||
void GameObserver::cleanupPhase(){
|
||||
void GameObserver::cleanupPhase()
|
||||
{
|
||||
currentPlayer->cleanupPhase();
|
||||
opponent()->cleanupPhase();
|
||||
}
|
||||
|
||||
void GameObserver::untapPhase(){
|
||||
void GameObserver::untapPhase()
|
||||
{
|
||||
currentPlayer->inPlay()->untapAll();
|
||||
}
|
||||
|
||||
int GameObserver::receiveEvent(WEvent * e){
|
||||
if (!e) return 0;
|
||||
int GameObserver::receiveEvent(WEvent * e)
|
||||
{
|
||||
if (!e)
|
||||
return 0;
|
||||
eventsQueue.push(e);
|
||||
if (eventsQueue.size() > 1) return -1; //resolving events can generate more events
|
||||
if (eventsQueue.size() > 1)
|
||||
return -1; //resolving events can generate more events
|
||||
int result = 0;
|
||||
while(eventsQueue.size()){
|
||||
while (eventsQueue.size())
|
||||
{
|
||||
WEvent * ev = eventsQueue.front();
|
||||
result += mLayers->receiveEvent(ev);
|
||||
for (int i = 0; i < 2; ++i){
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
result += players[i]->receiveEvent(ev);
|
||||
}
|
||||
SAFE_DELETE(ev);
|
||||
@@ -643,18 +764,23 @@ int GameObserver::receiveEvent(WEvent * e){
|
||||
return result;
|
||||
}
|
||||
|
||||
Player * GameObserver::currentlyActing(){
|
||||
if (isInterrupting) return isInterrupting;
|
||||
Player * GameObserver::currentlyActing()
|
||||
{
|
||||
if (isInterrupting)
|
||||
return isInterrupting;
|
||||
return currentActionPlayer;
|
||||
}
|
||||
|
||||
//TODO CORRECT THIS MESS
|
||||
int GameObserver::targetListIsSet(MTGCardInstance * card){
|
||||
if (targetChooser == NULL){
|
||||
int GameObserver::targetListIsSet(MTGCardInstance * card)
|
||||
{
|
||||
if (targetChooser == NULL)
|
||||
{
|
||||
TargetChooserFactory tcf;
|
||||
targetChooser = tcf.createTargetChooser(card);
|
||||
cardWaitingForTargets = card;
|
||||
if (targetChooser == NULL){
|
||||
if (targetChooser == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
+385
-256
File diff suppressed because it is too large
Load Diff
@@ -13,35 +13,39 @@
|
||||
// TODO: revise sorting strategy to allow other types of sorting. Currently, it is hardwired to use
|
||||
// sortByName to do the sorting. This was done since the menu item display is done in insertion order.
|
||||
|
||||
vector<DeckMetaData *> GameState::fillDeckMenu( SimpleMenu * _menu, const string& path, const string& smallDeckPrefix, Player * statsPlayer){
|
||||
vector<DeckMetaData *> GameState::fillDeckMenu(SimpleMenu * _menu, const string& path, const string& smallDeckPrefix,
|
||||
Player * statsPlayer)
|
||||
{
|
||||
bool translate = _menu->autoTranslate;
|
||||
_menu->autoTranslate = false;
|
||||
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData( path, smallDeckPrefix, statsPlayer );
|
||||
renderDeckMenu( _menu, deckMetaDataVector);
|
||||
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer);
|
||||
renderDeckMenu(_menu, deckMetaDataVector);
|
||||
_menu->autoTranslate = translate;
|
||||
|
||||
return deckMetaDataVector;
|
||||
}
|
||||
|
||||
vector<DeckMetaData *> GameState::fillDeckMenu( DeckMenu * _menu, const string& path, const string& smallDeckPrefix, Player * statsPlayer){
|
||||
vector<DeckMetaData *> GameState::fillDeckMenu(DeckMenu * _menu, const string& path, const string& smallDeckPrefix,
|
||||
Player * statsPlayer)
|
||||
{
|
||||
bool translate = _menu->autoTranslate;
|
||||
_menu->autoTranslate = false;
|
||||
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData( path, smallDeckPrefix, statsPlayer );
|
||||
renderDeckMenu( _menu, deckMetaDataVector);
|
||||
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer);
|
||||
renderDeckMenu(_menu, deckMetaDataVector);
|
||||
_menu->autoTranslate = translate;
|
||||
|
||||
return deckMetaDataVector;
|
||||
}
|
||||
|
||||
|
||||
vector<DeckMetaData *> GameState::getValidDeckMetaData( const string& path, const string& smallDeckPrefix, Player * statsPlayer)
|
||||
vector<DeckMetaData *> GameState::getValidDeckMetaData(const string& path, const string& smallDeckPrefix, Player * statsPlayer)
|
||||
{
|
||||
vector<DeckMetaData*> retList;
|
||||
|
||||
DeckMetaDataList * metas = DeckMetaDataList::decksMetaData;
|
||||
int found = 1;
|
||||
int nbDecks = 1;
|
||||
while (found){
|
||||
while (found)
|
||||
{
|
||||
found = 0;
|
||||
std::ostringstream filename;
|
||||
filename << path << "/deck" << nbDecks << ".txt";
|
||||
@@ -49,34 +53,34 @@ vector<DeckMetaData *> GameState::getValidDeckMetaData( const string& path, cons
|
||||
if (meta)
|
||||
{
|
||||
found = 1;
|
||||
if (statsPlayer){
|
||||
if (statsPlayer)
|
||||
{
|
||||
std::ostringstream smallDeckName;
|
||||
smallDeckName << smallDeckPrefix << "_deck" << nbDecks;
|
||||
meta->loadStatsForPlayer( statsPlayer, smallDeckName.str());
|
||||
meta->loadStatsForPlayer(statsPlayer, smallDeckName.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream playerStatsDeckName;
|
||||
playerStatsDeckName << "stats/player_deck" << nbDecks << ".txt";
|
||||
string deckstats = options.profileFile(playerStatsDeckName.str());
|
||||
meta->loadStatsForPlayer( NULL, deckstats );
|
||||
meta->loadStatsForPlayer(NULL, deckstats);
|
||||
}
|
||||
|
||||
retList.push_back( meta );
|
||||
retList.push_back(meta);
|
||||
nbDecks++;
|
||||
}
|
||||
meta = NULL;
|
||||
}
|
||||
|
||||
std::sort( retList.begin(), retList.end(), sortByName);
|
||||
std::sort(retList.begin(), retList.end(), sortByName);
|
||||
|
||||
return retList;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// build a menu with the given deck list and return a vector of the deck ids created.
|
||||
void GameState::renderDeckMenu ( SimpleMenu * _menu, const vector<DeckMetaData *>& deckMetaDataList )
|
||||
void GameState::renderDeckMenu(SimpleMenu * _menu, const vector<DeckMetaData *>& deckMetaDataList)
|
||||
{
|
||||
int deckNumber = 1;
|
||||
for (vector<DeckMetaData *>::const_iterator i = deckMetaDataList.begin(); i != deckMetaDataList.end(); i++)
|
||||
@@ -84,13 +88,12 @@ void GameState::renderDeckMenu ( SimpleMenu * _menu, const vector<DeckMetaData *
|
||||
DeckMetaData * deckMetaData = *i;
|
||||
string deckName = deckMetaData -> getName();
|
||||
string deckDescription = deckMetaData -> getDescription();
|
||||
_menu->Add( deckNumber++ ,deckName.c_str(), deckDescription.c_str());
|
||||
_menu->Add(deckNumber++, deckName.c_str(), deckDescription.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build a menu with the given deck list and return a vector of the deck ids created.
|
||||
void GameState::renderDeckMenu ( DeckMenu * _menu, const vector<DeckMetaData *>& deckMetaDataList )
|
||||
void GameState::renderDeckMenu(DeckMenu * _menu, const vector<DeckMetaData *>& deckMetaDataList)
|
||||
{
|
||||
int deckNumber = 1;
|
||||
for (vector<DeckMetaData *>::const_iterator i = deckMetaDataList.begin(); i != deckMetaDataList.end(); i++)
|
||||
@@ -99,17 +102,15 @@ void GameState::renderDeckMenu ( DeckMenu * _menu, const vector<DeckMetaData *>&
|
||||
string deckName = deckMetaData -> getName();
|
||||
string deckDescription = deckMetaData -> getDescription();
|
||||
//int deckId = deckMetaData -> getDeckId(); //do we need this?
|
||||
_menu->Add( deckNumber++ ,deckName.c_str(), deckDescription.c_str(), false, deckMetaData);
|
||||
_menu->Add(deckNumber++, deckName.c_str(), deckDescription.c_str(), false, deckMetaData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// deck sorting routines
|
||||
bool sortByName( DeckMetaData * d1, DeckMetaData * d2 )
|
||||
bool sortByName(DeckMetaData * d1, DeckMetaData * d2)
|
||||
{
|
||||
return strcmp( d1->getName().c_str(), d2->getName().c_str()) < 0;
|
||||
return strcmp(d1->getName().c_str(), d2->getName().c_str()) < 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//end deck sorting routine
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
This is where the player views their awards, etc.
|
||||
*/
|
||||
*/
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include <JRenderer.h>
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "GameOptions.h"
|
||||
#include "DeckDataWrapper.h"
|
||||
|
||||
enum ENUM_AWARDS_STATE{
|
||||
STATE_LISTVIEW,
|
||||
STATE_DETAILS,
|
||||
enum ENUM_AWARDS_STATE
|
||||
{
|
||||
STATE_LISTVIEW, STATE_DETAILS,
|
||||
};
|
||||
|
||||
namespace
|
||||
@@ -23,11 +23,14 @@ namespace
|
||||
const int kBackToMainMenuID = 1;
|
||||
}
|
||||
|
||||
GameStateAwards::GameStateAwards(GameApp* parent): GameState(parent){
|
||||
GameStateAwards::GameStateAwards(GameApp* parent) :
|
||||
GameState(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GameStateAwards::~GameStateAwards() {
|
||||
GameStateAwards::~GameStateAwards()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +41,7 @@ void GameStateAwards::End()
|
||||
SAFE_DELETE(listview);
|
||||
SAFE_DELETE(setSrc);
|
||||
|
||||
if(saveMe)
|
||||
if (saveMe)
|
||||
options.save();
|
||||
}
|
||||
void GameStateAwards::Start()
|
||||
@@ -61,56 +64,57 @@ void GameStateAwards::Start()
|
||||
WGuiHeader * wgh = NEW WGuiHeader("Achievements");
|
||||
listview->Add(wgh);
|
||||
|
||||
aw = NEW WGuiAward(Options::DIFFICULTY_MODE_UNLOCKED,"Difficulty Modes","Achieved a 66% victory ratio.");
|
||||
btn = NEW WGuiButton(aw,-103,Options::DIFFICULTY_MODE_UNLOCKED,this);
|
||||
aw = NEW WGuiAward(Options::DIFFICULTY_MODE_UNLOCKED, "Difficulty Modes", "Achieved a 66% victory ratio.");
|
||||
btn = NEW WGuiButton(aw, -103, Options::DIFFICULTY_MODE_UNLOCKED, this);
|
||||
listview->Add(btn);
|
||||
|
||||
aw = NEW WGuiAward(Options::MOMIR_MODE_UNLOCKED,"Momir Mode","Won with exactly 8 lands.");
|
||||
btn = NEW WGuiButton(aw,-103,Options::MOMIR_MODE_UNLOCKED,this);
|
||||
aw = NEW WGuiAward(Options::MOMIR_MODE_UNLOCKED, "Momir Mode", "Won with exactly 8 lands.");
|
||||
btn = NEW WGuiButton(aw, -103, Options::MOMIR_MODE_UNLOCKED, this);
|
||||
listview->Add(btn);
|
||||
|
||||
aw = NEW WGuiAward(Options::EVILTWIN_MODE_UNLOCKED,"Evil Twin Mode","Won with same army size.");
|
||||
btn = NEW WGuiButton(aw,-103,Options::EVILTWIN_MODE_UNLOCKED,this);
|
||||
aw = NEW WGuiAward(Options::EVILTWIN_MODE_UNLOCKED, "Evil Twin Mode", "Won with same army size.");
|
||||
btn = NEW WGuiButton(aw, -103, Options::EVILTWIN_MODE_UNLOCKED, this);
|
||||
listview->Add(btn);
|
||||
|
||||
aw = NEW WGuiAward(Options::RANDOMDECK_MODE_UNLOCKED,"Random Deck Mode","Won against a higher difficulty.");
|
||||
btn = NEW WGuiButton(aw,-103,Options::RANDOMDECK_MODE_UNLOCKED,this);
|
||||
aw = NEW WGuiAward(Options::RANDOMDECK_MODE_UNLOCKED, "Random Deck Mode", "Won against a higher difficulty.");
|
||||
btn = NEW WGuiButton(aw, -103, Options::RANDOMDECK_MODE_UNLOCKED, this);
|
||||
listview->Add(btn);
|
||||
|
||||
aw = NEW WGuiAward(Options::AWARD_COLLECTOR,"Valuable Collection","Collection valued over 10,000c.","Collection Info");
|
||||
btn = NEW WGuiButton(aw,-103,Options::AWARD_COLLECTOR,this);
|
||||
aw = NEW WGuiAward(Options::AWARD_COLLECTOR, "Valuable Collection", "Collection valued over 10,000c.", "Collection Info");
|
||||
btn = NEW WGuiButton(aw, -103, Options::AWARD_COLLECTOR, this);
|
||||
listview->Add(btn);
|
||||
|
||||
wgh = NEW WGuiHeader("");
|
||||
listview->Add(wgh);
|
||||
|
||||
int locked = 0;
|
||||
for (int i = 0; i < setlist.size(); i++){
|
||||
for (int i = 0; i < setlist.size(); i++)
|
||||
{
|
||||
MTGSetInfo * si = setlist.getInfo(i);
|
||||
if(!si)
|
||||
if (!si)
|
||||
continue;
|
||||
if(!options[Options::optionSet(i)].number){
|
||||
if (!options[Options::optionSet(i)].number)
|
||||
{
|
||||
locked++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!si->author.size())
|
||||
sprintf(buf,_("%i cards.").c_str(),si->totalCards());
|
||||
else if(si->year > 0)
|
||||
sprintf(buf,_("%s (%i): %i cards").c_str(),si->author.c_str(),si->year,si->totalCards());
|
||||
if (!si->author.size())
|
||||
sprintf(buf, _("%i cards.").c_str(), si->totalCards());
|
||||
else if (si->year > 0)
|
||||
sprintf(buf, _("%s (%i): %i cards").c_str(), si->author.c_str(), si->year, si->totalCards());
|
||||
else
|
||||
sprintf(buf,_("%s: %i cards.").c_str(),si->author.c_str(),si->totalCards());
|
||||
sprintf(buf, _("%s: %i cards.").c_str(), si->author.c_str(), si->totalCards());
|
||||
|
||||
|
||||
aw = NEW WGuiAward(Options::optionSet(i),si->getName(),buf,"Card Spoiler");
|
||||
aw = NEW WGuiAward(Options::optionSet(i), si->getName(), buf, "Card Spoiler");
|
||||
aw->mFlags = WGuiItem::NO_TRANSLATE;
|
||||
btn = NEW WGuiButton(aw,-103,Options::optionSet(i),this);
|
||||
btn = NEW WGuiButton(aw, -103, Options::optionSet(i), this);
|
||||
listview->Add(btn);
|
||||
}
|
||||
if(locked)
|
||||
sprintf(buf,_("%i locked sets remain.").c_str(),locked);
|
||||
if (locked)
|
||||
sprintf(buf, _("%i locked sets remain.").c_str(), locked);
|
||||
else
|
||||
sprintf(buf,_("Unlocked all %i sets.").c_str(),setlist.size());
|
||||
sprintf(buf, _("Unlocked all %i sets.").c_str(), setlist.size());
|
||||
|
||||
wgh->setDisplay(buf);
|
||||
wgh->mFlags = WGuiItem::NO_TRANSLATE;
|
||||
@@ -128,69 +132,76 @@ void GameStateAwards::Destroy()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GameStateAwards::Render()
|
||||
{
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->ClearScreen(ARGB(0,0,0,0));
|
||||
|
||||
JQuad * mBg = resources.RetrieveTempQuad("awardback.jpg",TEXTURE_SUB_5551);
|
||||
if(mBg)
|
||||
JQuad * mBg = resources.RetrieveTempQuad("awardback.jpg", TEXTURE_SUB_5551);
|
||||
if (mBg)
|
||||
r->RenderQuad(mBg, 0, 0);
|
||||
|
||||
switch(mState){
|
||||
switch (mState)
|
||||
{
|
||||
case STATE_LISTVIEW:
|
||||
if(listview)
|
||||
if (listview)
|
||||
listview->Render();
|
||||
break;
|
||||
case STATE_DETAILS:
|
||||
if(detailview)
|
||||
if (detailview)
|
||||
detailview->Render();
|
||||
break;
|
||||
}
|
||||
|
||||
if(showMenu && menu)
|
||||
if (showMenu && menu)
|
||||
menu->Render();
|
||||
}
|
||||
|
||||
void GameStateAwards::Update(float dt)
|
||||
{
|
||||
if(mEngine->GetButtonClick(JGE_BTN_CANCEL))
|
||||
if (mEngine->GetButtonClick(JGE_BTN_CANCEL))
|
||||
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
|
||||
|
||||
if(showMenu){
|
||||
if (showMenu)
|
||||
{
|
||||
menu->Update(dt);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
JButton key;
|
||||
while ((key = JGE::GetInstance()->ReadButton())){
|
||||
switch(key){
|
||||
while ((key = JGE::GetInstance()->ReadButton()))
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case JGE_BTN_MENU:
|
||||
showMenu = true;
|
||||
SAFE_DELETE(menu);
|
||||
menu = NEW SimpleMenu(-102, this,Fonts::MENU_FONT, 50,170);
|
||||
if(mState == STATE_DETAILS)
|
||||
menu = NEW SimpleMenu(-102, this, Fonts::MENU_FONT, 50, 170);
|
||||
if (mState == STATE_DETAILS)
|
||||
menu->Add(kBackToTrophiesID, "Back to Trophies");
|
||||
menu->Add(kBackToMainMenuID, "Back to Main Menu");
|
||||
menu->Add(kCancelMenuID, "Cancel");
|
||||
break;
|
||||
case JGE_BTN_PREV:
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
break;
|
||||
case JGE_BTN_SEC:
|
||||
if(mState == STATE_LISTVIEW)
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
else{
|
||||
if (mState == STATE_LISTVIEW)
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
else
|
||||
{
|
||||
mState = STATE_LISTVIEW;
|
||||
SAFE_DELETE(detailview);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(mState == STATE_LISTVIEW && listview){
|
||||
if (mState == STATE_LISTVIEW && listview)
|
||||
{
|
||||
listview->CheckUserInput(key);
|
||||
listview->Update(dt);
|
||||
}
|
||||
else if(mState == STATE_DETAILS && detailview){
|
||||
else if (mState == STATE_DETAILS && detailview)
|
||||
{
|
||||
detailview->CheckUserInput(key);
|
||||
detailview->Update(dt);
|
||||
}
|
||||
@@ -198,15 +209,16 @@ void GameStateAwards::Update(float dt)
|
||||
}
|
||||
}
|
||||
}
|
||||
if(setSrc)
|
||||
if (setSrc)
|
||||
setSrc->Update(dt);
|
||||
}
|
||||
|
||||
bool GameStateAwards::enterSet(int setid){
|
||||
bool GameStateAwards::enterSet(int setid)
|
||||
{
|
||||
MTGSetInfo * si = setlist.getInfo(setid);
|
||||
map<int, MTGCard *>::iterator it;
|
||||
|
||||
if(!si)
|
||||
if (!si)
|
||||
return false;
|
||||
|
||||
SAFE_DELETE(detailview);
|
||||
@@ -220,12 +232,13 @@ bool GameStateAwards::enterSet(int setid){
|
||||
|
||||
detailview = NEW WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP);
|
||||
|
||||
WGuiList * spoiler = NEW WGuiList("Spoiler",setSrc);
|
||||
WGuiList * spoiler = NEW WGuiList("Spoiler", setSrc);
|
||||
spoiler->setX(210);
|
||||
spoiler->setWidth(SCREEN_WIDTH - 220);
|
||||
for(int t=0;t<setSrc->Size();t++){
|
||||
for (int t = 0; t < setSrc->Size(); t++)
|
||||
{
|
||||
MTGCard * c = setSrc->getCard(t);
|
||||
if(c)
|
||||
if (c)
|
||||
spoiler->Add(NEW WGuiItem(c->data->name));
|
||||
}
|
||||
setSrc->setOffset(0);
|
||||
@@ -238,11 +251,12 @@ bool GameStateAwards::enterSet(int setid){
|
||||
detailview->Entering(JGE_BTN_NONE);
|
||||
return true;
|
||||
}
|
||||
bool GameStateAwards::enterStats(int option){
|
||||
if(option != Options::AWARD_COLLECTOR)
|
||||
bool GameStateAwards::enterStats(int option)
|
||||
{
|
||||
if (option != Options::AWARD_COLLECTOR)
|
||||
return false;
|
||||
DeckDataWrapper* ddw = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), mParent->collection));
|
||||
if(!ddw)
|
||||
if (!ddw)
|
||||
return false;
|
||||
|
||||
SAFE_DELETE(detailview);
|
||||
@@ -252,8 +266,9 @@ bool GameStateAwards::enterStats(int option){
|
||||
detailview->Entering(JGE_BTN_NONE);
|
||||
|
||||
//Discover favorite set
|
||||
if(setlist.size() > 0){
|
||||
int * counts = (int*)calloc(setlist.size(),sizeof(int));
|
||||
if (setlist.size() > 0)
|
||||
{
|
||||
int * counts = (int*) calloc(setlist.size(), sizeof(int));
|
||||
int setid = -1;
|
||||
int dupes = 0;
|
||||
MTGCard * many = NULL;
|
||||
@@ -261,61 +276,69 @@ bool GameStateAwards::enterStats(int option){
|
||||
MTGCard * strong = NULL;
|
||||
MTGCard * tough = NULL;
|
||||
|
||||
for (int t=0;t<ddw->Size();t++){
|
||||
for (int t = 0; t < ddw->Size(); t++)
|
||||
{
|
||||
MTGCard * c = ddw->getCard(t);
|
||||
if(!c)
|
||||
if (!c)
|
||||
continue;
|
||||
int count = ddw->count(c);
|
||||
if(!c->data->isLand() && (many == NULL || count > dupes)){
|
||||
if (!c->data->isLand() && (many == NULL || count > dupes))
|
||||
{
|
||||
many = c;
|
||||
dupes = count;
|
||||
}
|
||||
counts[c->setId]+=count;
|
||||
if(costly == NULL
|
||||
|| c->data->getManaCost()->getConvertedCost() > costly->data->getManaCost()->getConvertedCost())
|
||||
counts[c->setId] += count;
|
||||
if (costly == NULL || c->data->getManaCost()->getConvertedCost() > costly->data->getManaCost()->getConvertedCost())
|
||||
costly = c;
|
||||
|
||||
if(c->data->isCreature() && (strong == NULL || c->data->getPower() > strong->data->getPower()))
|
||||
if (c->data->isCreature() && (strong == NULL || c->data->getPower() > strong->data->getPower()))
|
||||
strong = c;
|
||||
|
||||
if(c->data->isCreature() && (tough == NULL || c->data->getToughness() > tough->data->getToughness()))
|
||||
if (c->data->isCreature() && (tough == NULL || c->data->getToughness() > tough->data->getToughness()))
|
||||
tough = c;
|
||||
}
|
||||
for(int i=0;i<setlist.size();i++){
|
||||
if(setid < 0 || counts[i] > counts[setid])
|
||||
for (int i = 0; i < setlist.size(); i++)
|
||||
{
|
||||
if (setid < 0 || counts[i] > counts[setid])
|
||||
setid = i;
|
||||
}
|
||||
free(counts);
|
||||
|
||||
char buf[1024];
|
||||
sprintf(buf,_("Total Value: %ic").c_str(),ddw->totalPrice());
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));//ddw->colors
|
||||
sprintf(buf, _("Total Value: %ic").c_str(), ddw->totalPrice());
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));//ddw->colors
|
||||
|
||||
sprintf(buf,_("Total Cards (including duplicates): %i").c_str(),ddw->getCount(WSrcDeck::UNFILTERED_COPIES));
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));//ddw->colors
|
||||
sprintf(buf, _("Total Cards (including duplicates): %i").c_str(), ddw->getCount(WSrcDeck::UNFILTERED_COPIES));
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));//ddw->colors
|
||||
|
||||
sprintf(buf,_("Unique Cards: %i").c_str(),ddw->getCount(WSrcDeck::UNFILTERED_UNIQUE));
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));
|
||||
sprintf(buf, _("Unique Cards: %i").c_str(), ddw->getCount(WSrcDeck::UNFILTERED_UNIQUE));
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
|
||||
|
||||
if(many){
|
||||
sprintf(buf,_("Most Duplicates: %i (%s)").c_str(),dupes,many->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));
|
||||
if (many)
|
||||
{
|
||||
sprintf(buf, _("Most Duplicates: %i (%s)").c_str(), dupes, many->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
|
||||
}
|
||||
if(setid >= 0){
|
||||
sprintf(buf,_("Favorite Set: %s").c_str(),setlist[setid].c_str());
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));
|
||||
if (setid >= 0)
|
||||
{
|
||||
sprintf(buf, _("Favorite Set: %s").c_str(), setlist[setid].c_str());
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
|
||||
}
|
||||
if(costly){
|
||||
sprintf(buf,_("Highest Mana Cost: %i (%s)").c_str(),costly->data->getManaCost()->getConvertedCost(),costly->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));
|
||||
if (costly)
|
||||
{
|
||||
sprintf(buf, _("Highest Mana Cost: %i (%s)").c_str(), costly->data->getManaCost()->getConvertedCost(),
|
||||
costly->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
|
||||
}
|
||||
if(strong){
|
||||
sprintf(buf,_("Most Powerful: %i (%s)").c_str(),strong->data->getPower(),strong->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));
|
||||
if (strong)
|
||||
{
|
||||
sprintf(buf, _("Most Powerful: %i (%s)").c_str(), strong->data->getPower(), strong->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
|
||||
}
|
||||
if(tough){
|
||||
sprintf(buf,_("Toughest: %i (%s)").c_str(),tough->data->getToughness(),strong->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf,WGuiItem::NO_TRANSLATE));
|
||||
if (tough)
|
||||
{
|
||||
sprintf(buf, _("Toughest: %i (%s)").c_str(), tough->data->getToughness(), strong->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,10 +348,11 @@ bool GameStateAwards::enterStats(int option){
|
||||
}
|
||||
void GameStateAwards::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
if(controllerId == -102)
|
||||
switch (controlId){
|
||||
if (controllerId == -102)
|
||||
switch (controlId)
|
||||
{
|
||||
case kBackToMainMenuID:
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
showMenu = false;
|
||||
break;
|
||||
case kBackToTrophiesID:
|
||||
@@ -340,14 +364,18 @@ void GameStateAwards::ButtonPressed(int controllerId, int controlId)
|
||||
showMenu = false;
|
||||
break;
|
||||
}
|
||||
else if(controllerId == -103){
|
||||
int setid = controlId-Options::SET_UNLOCKS;
|
||||
else if (controllerId == -103)
|
||||
{
|
||||
int setid = controlId - Options::SET_UNLOCKS;
|
||||
|
||||
if(controlId >= Options::SET_UNLOCKS && enterSet(setid)){
|
||||
if (controlId >= Options::SET_UNLOCKS && enterSet(setid))
|
||||
{
|
||||
mState = STATE_DETAILS;
|
||||
mDetailItem = controlId;
|
||||
|
||||
}else if(controlId == Options::AWARD_COLLECTOR && enterStats(controlId)){
|
||||
}
|
||||
else if (controlId == Options::AWARD_COLLECTOR && enterStats(controlId))
|
||||
{
|
||||
mState = STATE_DETAILS;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+226
-147
@@ -27,7 +27,7 @@
|
||||
const float MENU_FONT_SCALE = 1.0f;
|
||||
|
||||
enum ENUM_DUEL_STATE
|
||||
{
|
||||
{
|
||||
DUEL_STATE_START,
|
||||
DUEL_STATE_END,
|
||||
DUEL_STATE_CHOOSE_DECK1,
|
||||
@@ -40,20 +40,22 @@ enum ENUM_DUEL_STATE
|
||||
DUEL_STATE_BACK_TO_MAIN_MENU,
|
||||
DUEL_STATE_MENU,
|
||||
DUEL_STATE_ERROR
|
||||
};
|
||||
};
|
||||
|
||||
enum ENUM_DUEL_MENUS
|
||||
{
|
||||
{
|
||||
DUEL_MENU_GAME_MENU,
|
||||
DUEL_MENU_CHOOSE_DECK,
|
||||
DUEL_MENU_CHOOSE_OPPONENT
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) {
|
||||
for (int i = 0; i<2; i ++){
|
||||
deck[i]=NULL;
|
||||
mPlayers[i]=NULL;
|
||||
GameStateDuel::GameStateDuel(GameApp* parent) :
|
||||
GameState(parent)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
deck[i] = NULL;
|
||||
mPlayers[i] = NULL;
|
||||
}
|
||||
premadeDeck = false;
|
||||
game = NULL;
|
||||
@@ -69,7 +71,8 @@ GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) {
|
||||
|
||||
}
|
||||
|
||||
GameStateDuel::~GameStateDuel() {
|
||||
GameStateDuel::~GameStateDuel()
|
||||
{
|
||||
End();
|
||||
|
||||
}
|
||||
@@ -78,8 +81,7 @@ void GameStateDuel::Start()
|
||||
{
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
renderer->EnableVSync(true);
|
||||
OpponentsDeckid=0;
|
||||
|
||||
OpponentsDeckid = 0;
|
||||
|
||||
#ifdef TESTSUITE
|
||||
SAFE_DELETE(testSuite);
|
||||
@@ -92,98 +94,114 @@ void GameStateDuel::Start()
|
||||
menu = NULL;
|
||||
|
||||
int decksneeded = 0;
|
||||
for (int i = 0; i<2; i ++){
|
||||
if (mParent->players[i] == PLAYER_TYPE_HUMAN){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (mParent->players[i] == PLAYER_TYPE_HUMAN)
|
||||
{
|
||||
decksneeded = 1;
|
||||
|
||||
deckmenu = NEW DeckMenu(DUEL_MENU_CHOOSE_DECK, this, Fonts::OPTION_FONT, "Choose a Deck", MENU_FONT_SCALE);
|
||||
|
||||
DeckManager *deckManager = DeckManager::GetInstance();
|
||||
vector<DeckMetaData *> playerDeckList = getValidDeckMetaData( options.profileFile() );
|
||||
vector<DeckMetaData *> playerDeckList = getValidDeckMetaData(options.profileFile());
|
||||
int nbDecks = playerDeckList.size();
|
||||
|
||||
if (nbDecks)
|
||||
{
|
||||
decksneeded = 0;
|
||||
if (nbDecks > 1 )
|
||||
deckmenu->Add( MENUITEM_RANDOM_PLAYER, "Random", "Play with a random deck." );
|
||||
if (nbDecks > 1)
|
||||
deckmenu->Add(MENUITEM_RANDOM_PLAYER, "Random", "Play with a random deck.");
|
||||
}
|
||||
|
||||
renderDeckMenu( deckmenu, playerDeckList );
|
||||
renderDeckMenu(deckmenu, playerDeckList);
|
||||
// save the changes to the player deck list maintained in DeckManager
|
||||
deckManager->updateMetaDataList( &playerDeckList, false);
|
||||
deckManager->updateMetaDataList(&playerDeckList, false);
|
||||
playerDeckList.clear();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(deckmenu){
|
||||
if (decksneeded){
|
||||
if (deckmenu)
|
||||
{
|
||||
if (decksneeded)
|
||||
{
|
||||
//translate deck creating desc
|
||||
Translator * t = Translator::GetInstance();
|
||||
map<string,string>::iterator it = t->deckValues.find("Create your Deck!");
|
||||
map<string, string>::iterator it = t->deckValues.find("Create your Deck!");
|
||||
if (it != t->deckValues.end())
|
||||
deckmenu->Add( MENUITEM_NEW_DECK, "Create your Deck!", it->second);
|
||||
deckmenu->Add(MENUITEM_NEW_DECK, "Create your Deck!", it->second);
|
||||
else
|
||||
deckmenu->Add( MENUITEM_NEW_DECK, "Create your Deck!", "Highly recommended to get\nthe full Wagic experience!");
|
||||
deckmenu->Add(MENUITEM_NEW_DECK, "Create your Deck!", "Highly recommended to get\nthe full Wagic experience!");
|
||||
premadeDeck = true;
|
||||
fillDeckMenu(deckmenu,JGE_GET_RES("player/premade"));
|
||||
fillDeckMenu(deckmenu, JGE_GET_RES("player/premade"));
|
||||
}
|
||||
deckmenu->Add( MENUITEM_NEW_DECK, "New Deck...", "Create a new deck to play with.");
|
||||
deckmenu->Add( MENUITEM_CANCEL, "Main Menu", "Return to Main Menu");
|
||||
deckmenu->Add(MENUITEM_NEW_DECK, "New Deck...", "Create a new deck to play with.");
|
||||
deckmenu->Add(MENUITEM_CANCEL, "Main Menu", "Return to Main Menu");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; ++i){
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
mPlayers[i] = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
|
||||
if (decknb) {
|
||||
if (!isAI) { //Human Player
|
||||
void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI)
|
||||
{
|
||||
if (decknb)
|
||||
{
|
||||
if (!isAI)
|
||||
{ //Human Player
|
||||
char deckFile[255];
|
||||
if(premadeDeck)
|
||||
sprintf(deckFile, JGE_GET_RES("player/premade/deck%i.txt").c_str(),decknb);
|
||||
if (premadeDeck)
|
||||
sprintf(deckFile, JGE_GET_RES("player/premade/deck%i.txt").c_str(), decknb);
|
||||
else
|
||||
sprintf(deckFile, "%s/deck%i.txt",options.profileFile().c_str(), decknb);
|
||||
sprintf(deckFile, "%s/deck%i.txt", options.profileFile().c_str(), decknb);
|
||||
char deckFileSmall[255];
|
||||
sprintf(deckFileSmall, "player_deck%i",decknb);
|
||||
sprintf(deckFileSmall, "player_deck%i", decknb);
|
||||
MTGDeck * tempDeck = NEW MTGDeck(deckFile, mParent->collection);
|
||||
mPlayers[playerId] = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall);
|
||||
|
||||
deck[playerId] = mPlayers[playerId]->game;
|
||||
delete tempDeck;
|
||||
}
|
||||
else { //AI Player, chooses deck
|
||||
else
|
||||
{ //AI Player, chooses deck
|
||||
AIPlayerFactory playerCreator;
|
||||
Player * opponent = NULL;
|
||||
if (playerId == 1) opponent = mPlayers[0];
|
||||
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,opponent,decknb);
|
||||
if (playerId == 1)
|
||||
opponent = mPlayers[0];
|
||||
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection, opponent, decknb);
|
||||
deck[playerId] = mPlayers[playerId]->game;
|
||||
}
|
||||
}
|
||||
else { //Random deck
|
||||
else
|
||||
{ //Random deck
|
||||
AIPlayerFactory playerCreator;
|
||||
Player * opponent = NULL;
|
||||
if (playerId == 1) opponent = mPlayers[0];
|
||||
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,opponent);
|
||||
if (playerId == 1)
|
||||
opponent = mPlayers[0];
|
||||
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection, opponent);
|
||||
deck[playerId] = mPlayers[playerId]->game;
|
||||
}
|
||||
}
|
||||
|
||||
void GameStateDuel::initRand(unsigned int seed){
|
||||
if (!seed) seed = time(0);
|
||||
void GameStateDuel::initRand(unsigned int seed)
|
||||
{
|
||||
if (!seed)
|
||||
seed = time(0);
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
#ifdef TESTSUITE
|
||||
void GameStateDuel::loadTestSuitePlayers(){
|
||||
void GameStateDuel::loadTestSuitePlayers()
|
||||
{
|
||||
if (!testSuite) return;
|
||||
initRand(testSuite->seed);
|
||||
SAFE_DELETE(game);
|
||||
for (int i = 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
mPlayers[i] = NEW TestSuiteAI(testSuite, i);
|
||||
deck[i] = mPlayers[i]->game;
|
||||
}
|
||||
@@ -192,7 +210,8 @@ void GameStateDuel::loadTestSuitePlayers(){
|
||||
GameObserver::Init(mPlayers, 2);
|
||||
game = GameObserver::GetInstance();
|
||||
game->startGame(rules);
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR){
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR)
|
||||
{
|
||||
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
|
||||
}
|
||||
}
|
||||
@@ -207,14 +226,16 @@ void GameStateDuel::End()
|
||||
|
||||
if (mPlayers[0] && mPlayers[1]) // save the stats for the game
|
||||
mPlayers[0]->End();
|
||||
else // clean up player object
|
||||
else
|
||||
// clean up player object
|
||||
SAFE_DELETE( mPlayers[0] );
|
||||
|
||||
GameObserver::EndInstance();
|
||||
game = NULL;
|
||||
premadeDeck = false;
|
||||
|
||||
for (int i = 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
mPlayers[i] = NULL;
|
||||
deck[i] = NULL;
|
||||
}
|
||||
@@ -230,12 +251,13 @@ void GameStateDuel::End()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//TODO Move This to utils or ResourceManager. Don't we have more generic functions that can do that?
|
||||
bool GameStateDuel::MusicExist(string FileName){
|
||||
bool GameStateDuel::MusicExist(string FileName)
|
||||
{
|
||||
string filepath = JGE_GET_RES(resources.musicFile(FileName));
|
||||
std::ifstream file(filepath.c_str());
|
||||
if (file) {
|
||||
if (file)
|
||||
{
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
@@ -243,16 +265,18 @@ bool GameStateDuel::MusicExist(string FileName){
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameStateDuel::ensureOpponentMenu(){
|
||||
if (!opponentMenu){
|
||||
void GameStateDuel::ensureOpponentMenu()
|
||||
{
|
||||
if (!opponentMenu)
|
||||
{
|
||||
opponentMenu = NEW DeckMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Fonts::OPTION_FONT, "Choose Your Opponent", MENU_FONT_SCALE);
|
||||
opponentMenu->Add( MENUITEM_RANDOM_AI, "Random");
|
||||
opponentMenu->Add(MENUITEM_RANDOM_AI, "Random");
|
||||
if (options[Options::EVILTWIN_MODE_UNLOCKED].number)
|
||||
opponentMenu->Add( MENUITEM_EVIL_TWIN, "Evil Twin", _("Can you play against yourself?").c_str());
|
||||
opponentMenu->Add(MENUITEM_EVIL_TWIN, "Evil Twin", _("Can you play against yourself?").c_str());
|
||||
DeckManager * deckManager = DeckManager::GetInstance();
|
||||
vector<DeckMetaData* > opponentDeckList = fillDeckMenu( opponentMenu, JGE_GET_RES("ai/baka"), "ai_baka", mPlayers[0]);
|
||||
vector<DeckMetaData*> opponentDeckList = fillDeckMenu(opponentMenu, JGE_GET_RES("ai/baka"), "ai_baka", mPlayers[0]);
|
||||
deckManager->updateMetaDataList(&opponentDeckList, true);
|
||||
opponentMenu->Add( MENUITEM_CANCEL, "Cancel", _("Choose a different player deck").c_str());
|
||||
opponentMenu->Add(MENUITEM_CANCEL, "Cancel", _("Choose a different player deck").c_str());
|
||||
opponentDeckList.clear();
|
||||
}
|
||||
}
|
||||
@@ -266,109 +290,141 @@ void GameStateDuel::Update(float dt)
|
||||
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
|
||||
break;
|
||||
case DUEL_STATE_CHOOSE_DECK1:
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR){
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR)
|
||||
{
|
||||
rules = NEW Rules("momir.txt");
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
} else if (mParent->gameType == GAME_TYPE_RANDOM1){
|
||||
rules = NEW Rules ("random1.txt");
|
||||
}
|
||||
else if (mParent->gameType == GAME_TYPE_RANDOM1)
|
||||
{
|
||||
rules = NEW Rules("random1.txt");
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
}else if (mParent->gameType == GAME_TYPE_RANDOM2) {
|
||||
rules = NEW Rules ("random2.txt");
|
||||
}
|
||||
else if (mParent->gameType == GAME_TYPE_RANDOM2)
|
||||
{
|
||||
rules = NEW Rules("random2.txt");
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
}
|
||||
#ifdef TESTSUITE
|
||||
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
|
||||
if (testSuite && testSuite->loadNext()){
|
||||
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE)
|
||||
{
|
||||
if (testSuite && testSuite->loadNext())
|
||||
{
|
||||
rules = NEW Rules("testsuite.txt");
|
||||
loadTestSuitePlayers();
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
testSuite->pregameTests();
|
||||
testSuite->initGame();
|
||||
}else{
|
||||
if (!game){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!game)
|
||||
{
|
||||
mGamePhase = DUEL_STATE_ERROR;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
mGamePhase = DUEL_STATE_END;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else{
|
||||
if (!rules) rules = NEW Rules("mtg.txt");
|
||||
else
|
||||
{
|
||||
if (!rules)
|
||||
rules = NEW Rules("mtg.txt");
|
||||
if (mParent->players[0] == PLAYER_TYPE_HUMAN)
|
||||
deckmenu->Update(dt);
|
||||
else{
|
||||
else
|
||||
{
|
||||
loadPlayer(0);
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DUEL_STATE_CHOOSE_DECK1_TO_2:
|
||||
if (deckmenu->closed) mGamePhase = DUEL_STATE_CHOOSE_DECK2;
|
||||
else deckmenu->Update(dt);
|
||||
if (deckmenu->closed)
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK2;
|
||||
else
|
||||
deckmenu->Update(dt);
|
||||
break;
|
||||
case DUEL_STATE_CHOOSE_DECK2:
|
||||
if (mParent->players[1] == PLAYER_TYPE_HUMAN)
|
||||
deckmenu->Update(dt);
|
||||
else{
|
||||
if (mParent->players[0] == PLAYER_TYPE_HUMAN){
|
||||
else
|
||||
{
|
||||
if (mParent->players[0] == PLAYER_TYPE_HUMAN)
|
||||
{
|
||||
ensureOpponentMenu();
|
||||
opponentMenu->Update(dt);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
loadPlayer(1);
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DUEL_STATE_CHOOSE_DECK2_TO_PLAY:
|
||||
if (mParent->players[1] == PLAYER_TYPE_HUMAN){
|
||||
if (deckmenu->closed) mGamePhase = DUEL_STATE_PLAY;
|
||||
else deckmenu->Update(dt);
|
||||
if (mParent->players[1] == PLAYER_TYPE_HUMAN)
|
||||
{
|
||||
if (deckmenu->closed)
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
else
|
||||
deckmenu->Update(dt);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
ensureOpponentMenu();
|
||||
if (opponentMenu->closed) mGamePhase = DUEL_STATE_PLAY;
|
||||
else opponentMenu->Update(dt);
|
||||
if (opponentMenu->closed)
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
else
|
||||
opponentMenu->Update(dt);
|
||||
}
|
||||
break;
|
||||
case DUEL_STATE_PLAY:
|
||||
if (!game){
|
||||
if (!game)
|
||||
{
|
||||
GameObserver::Init(mPlayers, 2);
|
||||
game = GameObserver::GetInstance();
|
||||
game->startGame(rules);
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR){
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR)
|
||||
{
|
||||
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
|
||||
}
|
||||
|
||||
//start of in game music code
|
||||
musictrack = "";
|
||||
//check opponent id and choose the music track based on it
|
||||
if(OpponentsDeckid) {
|
||||
if (OpponentsDeckid)
|
||||
{
|
||||
char temp[4096];
|
||||
sprintf(temp,"ai_baka_music%i.mp3",OpponentsDeckid);
|
||||
sprintf(temp, "ai_baka_music%i.mp3", OpponentsDeckid);
|
||||
musictrack.assign(temp);
|
||||
}
|
||||
else if(mParent->gameType == GAME_TYPE_CLASSIC)
|
||||
else if (mParent->gameType == GAME_TYPE_CLASSIC)
|
||||
musictrack = "ai_baka_music.mp3";
|
||||
else if(mParent->gameType == GAME_TYPE_MOMIR)
|
||||
else if (mParent->gameType == GAME_TYPE_MOMIR)
|
||||
musictrack = "ai_baka_music_momir.mp3";
|
||||
else if(mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2)
|
||||
else if (mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2)
|
||||
musictrack = "ai_baka_music_random.mp3";
|
||||
|
||||
if(!MusicExist(musictrack))
|
||||
if (!MusicExist(musictrack))
|
||||
musictrack = "ai_baka_music.mp3";
|
||||
|
||||
GameApp::playMusic(musictrack);
|
||||
}
|
||||
game->Update(dt);
|
||||
if (game->gameOver){
|
||||
if (game->gameOver)
|
||||
{
|
||||
if (game->players[1]->playMode != Player::MODE_TEST_SUITE)
|
||||
credits->compute(game->players[0],game->players[1], mParent);
|
||||
credits->compute(game->players[0], game->players[1], mParent);
|
||||
mGamePhase = DUEL_STATE_END;
|
||||
#ifdef TESTSUITE
|
||||
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
|
||||
if (testSuite->loadNext()){
|
||||
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE)
|
||||
{
|
||||
if (testSuite->loadNext())
|
||||
{
|
||||
loadTestSuitePlayers();
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
testSuite->initGame();
|
||||
@@ -378,25 +434,27 @@ void GameStateDuel::Update(float dt)
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
|
||||
if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU)
|
||||
{
|
||||
End();
|
||||
Start();
|
||||
}
|
||||
}
|
||||
if (mEngine->GetButtonClick(JGE_BTN_MENU)) {
|
||||
if (!menu) {
|
||||
menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, Fonts::MENU_FONT, SCREEN_WIDTH/2-100, 25, game->players[1]->deckName.c_str());
|
||||
if (mEngine->GetButtonClick(JGE_BTN_MENU))
|
||||
{
|
||||
if (!menu)
|
||||
{
|
||||
menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25,
|
||||
game->players[1]->deckName.c_str());
|
||||
int cardsinhand = game->players[0]->game->hand->nb_cards;
|
||||
|
||||
//almosthumane - mulligan
|
||||
if ((game->turn < 1) && (cardsinhand != 0)
|
||||
&& game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|
||||
&& game->players[0]->game->inPlay->nb_cards == 0
|
||||
&& game->players[0]->game->graveyard->nb_cards == 0
|
||||
&& game->players[0]->game->exile->nb_cards == 0) //1st Play Check
|
||||
if ((game->turn < 1) && (cardsinhand != 0) && game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|
||||
&& game->players[0]->game->inPlay->nb_cards == 0 && game->players[0]->game->graveyard->nb_cards
|
||||
== 0 && game->players[0]->game->exile->nb_cards == 0) //1st Play Check
|
||||
//IF there was no play at the moment automatically mulligan
|
||||
{
|
||||
menu->Add( MENUITEM_MULLIGAN, "Mulligan");
|
||||
menu->Add(MENUITEM_MULLIGAN, "Mulligan");
|
||||
}
|
||||
//END almosthumane - mulligan
|
||||
menu->Add(MENUITEM_MAIN_MENU, "Back to main menu");
|
||||
@@ -410,15 +468,18 @@ void GameStateDuel::Update(float dt)
|
||||
break;
|
||||
case DUEL_STATE_CANCEL:
|
||||
menu->Update(dt);
|
||||
if (menu->closed) {
|
||||
if (menu->closed)
|
||||
{
|
||||
mGamePhase = DUEL_STATE_PLAY;
|
||||
SAFE_DELETE(menu);
|
||||
}
|
||||
break;
|
||||
case DUEL_STATE_BACK_TO_MAIN_MENU:
|
||||
if(menu){
|
||||
if (menu)
|
||||
{
|
||||
menu->Update(dt);
|
||||
if (menu->closed) {
|
||||
if (menu->closed)
|
||||
{
|
||||
PlayerData * playerdata = NEW PlayerData(mParent->collection);
|
||||
playerdata->taskList->passOneDay();
|
||||
playerdata->taskList->save();
|
||||
@@ -426,7 +487,7 @@ void GameStateDuel::Update(float dt)
|
||||
SAFE_DELETE(menu);
|
||||
}
|
||||
}
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
|
||||
break;
|
||||
default:
|
||||
@@ -435,7 +496,6 @@ void GameStateDuel::Update(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GameStateDuel::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
@@ -450,27 +510,35 @@ void GameStateDuel::Render()
|
||||
case DUEL_STATE_END:
|
||||
{
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(200,0,0,0));
|
||||
r->FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(200,0,0,0));
|
||||
credits->Render();
|
||||
#ifdef TESTSUITE
|
||||
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
|
||||
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE)
|
||||
{
|
||||
r->ClearScreen(ARGB(255,0,0,0));
|
||||
char buf[4096];
|
||||
int nbFailed = testSuite->nbFailed;
|
||||
int nbTests = testSuite->nbTests;
|
||||
if (!nbFailed){
|
||||
if (!nbFailed)
|
||||
{
|
||||
sprintf(buf, "All %i tests successful!", nbTests);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "%i tests out of %i FAILED!", nbFailed, nbTests);
|
||||
}
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(buf,0,SCREEN_HEIGHT/2);
|
||||
nbFailed = testSuite->nbAIFailed;
|
||||
nbTests = testSuite->nbAITests;
|
||||
if (nbTests){
|
||||
if (!nbFailed){
|
||||
if (nbTests)
|
||||
{
|
||||
if (!nbFailed)
|
||||
{
|
||||
sprintf(buf, "AI Tests: All %i tests successful!", nbTests);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "AI Tests: %i tests out of %i FAILED!", nbFailed, nbTests);
|
||||
}
|
||||
mFont->DrawString(buf,0,SCREEN_HEIGHT/2+20);
|
||||
@@ -482,7 +550,7 @@ void GameStateDuel::Render()
|
||||
case DUEL_STATE_ERROR:
|
||||
{
|
||||
r->ClearScreen(ARGB(200,0,0,0));
|
||||
mFont->DrawString(_("AN ERROR OCCURRED, CHECK FILE NAMES").c_str(),0,SCREEN_HEIGHT/2);
|
||||
mFont->DrawString(_("AN ERROR OCCURRED, CHECK FILE NAMES").c_str(), 0, SCREEN_HEIGHT / 2);
|
||||
break;
|
||||
}
|
||||
case DUEL_STATE_CHOOSE_DECK1:
|
||||
@@ -490,8 +558,9 @@ void GameStateDuel::Render()
|
||||
case DUEL_STATE_CHOOSE_DECK2:
|
||||
case DUEL_STATE_CHOOSE_DECK2_TO_PLAY:
|
||||
if (mParent->gameType != GAME_TYPE_CLASSIC)
|
||||
mFont->DrawString(_("LOADING DECKS").c_str(),0,SCREEN_HEIGHT/2);
|
||||
else{
|
||||
mFont->DrawString(_("LOADING DECKS").c_str(), 0, SCREEN_HEIGHT / 2);
|
||||
else
|
||||
{
|
||||
if (opponentMenu)
|
||||
opponentMenu->Render();
|
||||
else if (deckmenu)
|
||||
@@ -500,32 +569,36 @@ void GameStateDuel::Render()
|
||||
}
|
||||
break;
|
||||
case DUEL_STATE_ERROR_NO_DECK:
|
||||
mFont->DrawString(_("NO DECK AVAILABLE,").c_str(),0,SCREEN_HEIGHT/2);
|
||||
mFont->DrawString(_("PRESS CIRCLE TO GO TO THE DECK EDITOR!").c_str(),0,SCREEN_HEIGHT/2 + 20);
|
||||
mFont->DrawString(_("NO DECK AVAILABLE,").c_str(), 0, SCREEN_HEIGHT / 2);
|
||||
mFont->DrawString(_("PRESS CIRCLE TO GO TO THE DECK EDITOR!").c_str(), 0, SCREEN_HEIGHT / 2 + 20);
|
||||
break;
|
||||
case DUEL_STATE_MENU:
|
||||
case DUEL_STATE_CANCEL:
|
||||
case DUEL_STATE_BACK_TO_MAIN_MENU:
|
||||
if (game) {
|
||||
r->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(100,0,0,0));
|
||||
if (game)
|
||||
{
|
||||
r->FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(100,0,0,0));
|
||||
char buffer[4096];
|
||||
sprintf(buffer,_("Turn:%i").c_str(),game->turn);
|
||||
sprintf(buffer, _("Turn:%i").c_str(), game->turn);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(buffer,SCREEN_WIDTH/2,0,JGETEXT_CENTER);
|
||||
mFont->DrawString(buffer, SCREEN_WIDTH / 2, 0, JGETEXT_CENTER);
|
||||
}
|
||||
if(menu)
|
||||
if (menu)
|
||||
menu->Render();
|
||||
}
|
||||
}
|
||||
|
||||
void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
|
||||
void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
int deckNumber = controlId;
|
||||
DeckManager * deckManager = DeckManager::GetInstance();
|
||||
int aiDeckSize = deckManager->getAIDeckOrderList()->size();
|
||||
switch (controllerId){
|
||||
switch (controllerId)
|
||||
{
|
||||
case DUEL_MENU_CHOOSE_OPPONENT:
|
||||
{
|
||||
switch(controlId){
|
||||
switch (controlId)
|
||||
{
|
||||
case MENUITEM_RANDOM_AI:
|
||||
loadPlayer(1);
|
||||
opponentMenu->Close();
|
||||
@@ -538,15 +611,15 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
|
||||
{
|
||||
opponentMenu->Close();
|
||||
deckmenu->Close();
|
||||
mParent->SetNextState( DUEL_STATE_CHOOSE_DECK1 );
|
||||
mParent->SetNextState(DUEL_STATE_CHOOSE_DECK1);
|
||||
mGamePhase = DUEL_MENU_GAME_MENU;
|
||||
break;
|
||||
}
|
||||
else if ( controlId != MENUITEM_EVIL_TWIN && aiDeckSize > 0) // evil twin
|
||||
deckNumber = deckManager->getAIDeckOrderList()->at( controlId - 1 )->getDeckId();
|
||||
else if (controlId != MENUITEM_EVIL_TWIN && aiDeckSize > 0) // evil twin
|
||||
deckNumber = deckManager->getAIDeckOrderList()->at(controlId - 1)->getDeckId();
|
||||
|
||||
loadPlayer(1,deckNumber,1);
|
||||
OpponentsDeckid=deckNumber;
|
||||
loadPlayer(1, deckNumber, 1);
|
||||
OpponentsDeckid = deckNumber;
|
||||
opponentMenu->Close();
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
|
||||
break;
|
||||
@@ -555,36 +628,40 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
|
||||
}
|
||||
case DUEL_MENU_CHOOSE_DECK:
|
||||
{
|
||||
if ( controlId == MENUITEM_RANDOM_PLAYER ) // Random Player Deck Selection
|
||||
if (controlId == MENUITEM_RANDOM_PLAYER) // Random Player Deck Selection
|
||||
{
|
||||
vector<DeckMetaData *> * playerDeckList = deckManager->getPlayerDeckOrderList();
|
||||
deckNumber = playerDeckList->at(WRand() * 1001 % (playerDeckList->size()) )->getDeckId();
|
||||
loadPlayer( 0, deckNumber );
|
||||
deckNumber = playerDeckList->at(WRand() * 1001 % (playerDeckList->size()))->getDeckId();
|
||||
loadPlayer(0, deckNumber);
|
||||
deckmenu->Close();
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
|
||||
break;
|
||||
}
|
||||
else if (controlId == MENUITEM_MAIN_MENU || controlId == MENUITEM_CANCEL ) // user clicked on "Cancel"
|
||||
else if (controlId == MENUITEM_MAIN_MENU || controlId == MENUITEM_CANCEL) // user clicked on "Cancel"
|
||||
{
|
||||
if (deckmenu)
|
||||
deckmenu->Close();
|
||||
mGamePhase = DUEL_STATE_BACK_TO_MAIN_MENU;
|
||||
break;
|
||||
}
|
||||
if (controlId < 0){
|
||||
if (controlId < 0)
|
||||
{
|
||||
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
|
||||
return;
|
||||
}
|
||||
if (mGamePhase == DUEL_STATE_CHOOSE_DECK1){
|
||||
if (mGamePhase == DUEL_STATE_CHOOSE_DECK1)
|
||||
{
|
||||
vector<DeckMetaData *> * playerDeck = deckManager->getPlayerDeckOrderList();
|
||||
if ( !premadeDeck && controlId > 0 )
|
||||
deckNumber = playerDeck->at( controlId - 1 )->getDeckId();
|
||||
loadPlayer(0,deckNumber);
|
||||
if (!premadeDeck && controlId > 0)
|
||||
deckNumber = playerDeck->at(controlId - 1)->getDeckId();
|
||||
loadPlayer(0, deckNumber);
|
||||
deckmenu->Close();
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK1_TO_2;
|
||||
playerDeck = NULL;
|
||||
}else{
|
||||
loadPlayer(1,controlId);
|
||||
}
|
||||
else
|
||||
{
|
||||
loadPlayer(1, controlId);
|
||||
deckmenu->Close();
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
|
||||
}
|
||||
@@ -609,12 +686,14 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
|
||||
|
||||
int cardsinhand = game->players[0]->game->hand->nb_cards;
|
||||
|
||||
for (int i = 0 ; i < cardsinhand; i ++) //Discard hand
|
||||
game->currentPlayer->game->putInZone(game->currentPlayer->game->hand->cards[0],game->currentPlayer->game->hand ,game->currentPlayer->game->library);
|
||||
for (int i = 0; i < cardsinhand; i++) //Discard hand
|
||||
game->currentPlayer->game->putInZone(game->currentPlayer->game->hand->cards[0], game->currentPlayer->game->hand,
|
||||
game->currentPlayer->game->library);
|
||||
|
||||
game->currentPlayer->game->library->shuffle(); //Shuffle
|
||||
|
||||
for (int i = 0; i < (cardsinhand-1); i ++) game->draw(); //Draw hand with 1 less card penalty //almhum
|
||||
for (int i = 0; i < (cardsinhand - 1); i++)
|
||||
game->draw(); //Draw hand with 1 less card penalty //almhum
|
||||
menu->Close();
|
||||
mGamePhase = DUEL_STATE_CANCEL;
|
||||
break;
|
||||
|
||||
+273
-181
@@ -25,9 +25,8 @@ static const char* GAME_VERSION = "WTH?! 0.13.1 - by wololo";
|
||||
#define MIN_ANGLE_MULTIPLIER 0.4f
|
||||
static const float STEP_ANGLE_MULTIPLIER = 0.0002f;
|
||||
|
||||
|
||||
enum ENUM_MENU_STATE_MAJOR
|
||||
{
|
||||
{
|
||||
MENU_STATE_MAJOR_MAINMENU = 0x01,
|
||||
MENU_STATE_MAJOR_SUBMENU = 0x02,
|
||||
MENU_STATE_MAJOR_LOADING_MENU = 0x03,
|
||||
@@ -37,16 +36,15 @@ enum ENUM_MENU_STATE_MAJOR
|
||||
MENU_STATE_MAJOR_LANG = 0x07,
|
||||
|
||||
MENU_STATE_MAJOR = 0xFF
|
||||
};
|
||||
};
|
||||
|
||||
enum ENUM_MENU_STATE_MINOR
|
||||
{
|
||||
{
|
||||
MENU_STATE_MINOR_NONE = 0,
|
||||
MENU_STATE_MINOR_SUBMENU_CLOSING = 0x100,
|
||||
MENU_STATE_MINOR_FADEIN = 0x200,
|
||||
MENU_STATE_MINOR = 0xF00
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -67,8 +65,8 @@ enum
|
||||
SUBMENUITEM_STORY,
|
||||
};
|
||||
|
||||
|
||||
GameStateMenu::GameStateMenu(GameApp* parent): GameState(parent)
|
||||
GameStateMenu::GameStateMenu(GameApp* parent) :
|
||||
GameState(parent)
|
||||
{
|
||||
mGuiController = NULL;
|
||||
subMenuController = NULL;
|
||||
@@ -85,8 +83,9 @@ GameStateMenu::GameStateMenu(GameApp* parent): GameState(parent)
|
||||
primitivesLoadCounter = -1;
|
||||
}
|
||||
|
||||
GameStateMenu::~GameStateMenu() {}
|
||||
|
||||
GameStateMenu::~GameStateMenu()
|
||||
{
|
||||
}
|
||||
|
||||
void GameStateMenu::Create()
|
||||
{
|
||||
@@ -99,11 +98,14 @@ void GameStateMenu::Create()
|
||||
int n = 0;
|
||||
char buf[512];
|
||||
|
||||
for (int i=0;i<5;i++){
|
||||
for (int j=0;j<2;j++){
|
||||
sprintf(buf,"menuicons%d%d",i,j);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
sprintf(buf, "menuicons%d%d", i, j);
|
||||
mIcons[n] = resources.RetrieveQuad("menuicons.png", 2 + i * 36.0f, 2.0f + j * 36.0f, 32.0f, 32.0f, buf);
|
||||
if(mIcons[n]) mIcons[n]->SetHotSpot(16,16);
|
||||
if (mIcons[n])
|
||||
mIcons[n]->SetHotSpot(16, 16);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
@@ -111,14 +113,17 @@ void GameStateMenu::Create()
|
||||
currentState = MENU_STATE_MAJOR_LOADING_CARDS;
|
||||
bool langChosen = false;
|
||||
string lang = options[Options::LANG].str;
|
||||
if (lang.size()){
|
||||
if (lang.size())
|
||||
{
|
||||
lang = JGE_GET_RES("lang/") + lang + ".txt";
|
||||
if (fileExists(lang.c_str())) langChosen = true;
|
||||
if (fileExists(lang.c_str()))
|
||||
langChosen = true;
|
||||
}
|
||||
if (!langChosen){
|
||||
if (!langChosen)
|
||||
{
|
||||
currentState = MENU_STATE_MAJOR_LANG | MENU_STATE_MINOR_NONE;
|
||||
}
|
||||
scroller = NEW TextScroller(Fonts::MAIN_FONT, SCREEN_WIDTH/2 - 90 , SCREEN_HEIGHT-17,180);
|
||||
scroller = NEW TextScroller(Fonts::MAIN_FONT, SCREEN_WIDTH / 2 - 90, SCREEN_HEIGHT - 17, 180);
|
||||
scrollerSet = 0;
|
||||
|
||||
splashTex = NULL;
|
||||
@@ -126,8 +131,6 @@ void GameStateMenu::Create()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GameStateMenu::Destroy()
|
||||
{
|
||||
SAFE_DELETE(mGuiController);
|
||||
@@ -137,7 +140,8 @@ void GameStateMenu::Destroy()
|
||||
SAFE_DELETE(scroller);
|
||||
}
|
||||
|
||||
void GameStateMenu::Start(){
|
||||
void GameStateMenu::Start()
|
||||
{
|
||||
LOG("GameStateMenu::Start");
|
||||
JRenderer::GetInstance()->EnableVSync(true);
|
||||
subMenuController = NULL;
|
||||
@@ -155,7 +159,8 @@ void GameStateMenu::Start(){
|
||||
bgTexture = resources.RetrieveTexture("menutitle.png", RETRIEVE_LOCK);
|
||||
mBg = resources.RetrieveQuad("menutitle.png", 0, 0, 256, 166); // Create background quad for rendering.
|
||||
|
||||
if (mBg) mBg->SetHotSpot(128,50);
|
||||
if (mBg)
|
||||
mBg->SetHotSpot(128, 50);
|
||||
|
||||
if (MENU_STATE_MAJOR_MAINMENU == currentState)
|
||||
currentState = currentState | MENU_STATE_MINOR_FADEIN;
|
||||
@@ -163,18 +168,23 @@ void GameStateMenu::Start(){
|
||||
wallpaper = "";
|
||||
}
|
||||
|
||||
void GameStateMenu::genNbCardsStr(){
|
||||
void GameStateMenu::genNbCardsStr()
|
||||
{
|
||||
//How many cards total ?
|
||||
PlayerData * playerdata = NEW PlayerData(mParent->collection);
|
||||
if(playerdata && !options[Options::ACTIVE_PROFILE].isDefault())
|
||||
sprintf(nbcardsStr, _("%s: %i cards (%i) (%i unique)").c_str(), options[Options::ACTIVE_PROFILE].str.c_str(), playerdata->collection->totalCards(), mParent->collection->totalCards(), mParent->collection->primitives.size());
|
||||
if (playerdata && !options[Options::ACTIVE_PROFILE].isDefault())
|
||||
sprintf(nbcardsStr, _("%s: %i cards (%i) (%i unique)").c_str(), options[Options::ACTIVE_PROFILE].str.c_str(),
|
||||
playerdata->collection->totalCards(), mParent->collection->totalCards(),
|
||||
mParent->collection->primitives.size());
|
||||
else
|
||||
sprintf(nbcardsStr, _("%i cards (%i unique)").c_str(), mParent->collection->totalCards(), mParent->collection->primitives.size());
|
||||
sprintf(nbcardsStr, _("%i cards (%i unique)").c_str(), mParent->collection->totalCards(),
|
||||
mParent->collection->primitives.size());
|
||||
|
||||
SAFE_DELETE(playerdata);
|
||||
}
|
||||
|
||||
void GameStateMenu::fillScroller(){
|
||||
void GameStateMenu::fillScroller()
|
||||
{
|
||||
scroller->Reset();
|
||||
char buffer[4096];
|
||||
char buff2[512];
|
||||
@@ -182,23 +192,26 @@ void GameStateMenu::fillScroller(){
|
||||
DeckStats * stats = DeckStats::GetInstance();
|
||||
int totalGames = 0;
|
||||
|
||||
for (int j=1; j<6; j++){
|
||||
sprintf(buffer, "stats/player_deck%i.txt",j);
|
||||
for (int j = 1; j < 6; j++)
|
||||
{
|
||||
sprintf(buffer, "stats/player_deck%i.txt", j);
|
||||
string deckstats = options.profileFile(buffer);
|
||||
if(fileExists(deckstats.c_str())){
|
||||
if (fileExists(deckstats.c_str()))
|
||||
{
|
||||
stats->load(deckstats.c_str());
|
||||
int percentVictories = stats->percentVictories();
|
||||
|
||||
sprintf(buff2, _("You have a %i%% victory ratio with Deck%i").c_str(),percentVictories,j);
|
||||
sprintf(buff2, _("You have a %i%% victory ratio with Deck%i").c_str(), percentVictories, j);
|
||||
scroller->Add(buff2);
|
||||
int nbGames = stats->nbGames();
|
||||
totalGames+= nbGames;
|
||||
sprintf(buff2, _("You have played %i games with Deck%i").c_str(),nbGames,j);
|
||||
totalGames += nbGames;
|
||||
sprintf(buff2, _("You have played %i games with Deck%i").c_str(), nbGames, j);
|
||||
scroller->Add(buff2);
|
||||
}
|
||||
}
|
||||
if (totalGames){
|
||||
sprintf(buff2, _("You have played a total of %i games").c_str(),totalGames);
|
||||
if (totalGames)
|
||||
{
|
||||
sprintf(buff2, _("You have played a total of %i games").c_str(), totalGames);
|
||||
scroller->Add(buff2);
|
||||
}
|
||||
|
||||
@@ -217,27 +230,30 @@ void GameStateMenu::fillScroller(){
|
||||
|
||||
//Unlocked sets
|
||||
int nbunlocked = 0;
|
||||
for (int i = 0; i < setlist.size(); i++){
|
||||
if (1 == options[Options::optionSet(i)].number) nbunlocked++;
|
||||
for (int i = 0; i < setlist.size(); i++)
|
||||
{
|
||||
if (1 == options[Options::optionSet(i)].number)
|
||||
nbunlocked++;
|
||||
}
|
||||
sprintf(buff2, _("You have unlocked %i expansions out of %i").c_str(),nbunlocked, setlist.size());
|
||||
sprintf(buff2, _("You have unlocked %i expansions out of %i").c_str(), nbunlocked, setlist.size());
|
||||
scroller->Add(buff2);
|
||||
|
||||
PlayerData * playerdata = NEW PlayerData(mParent->collection);
|
||||
int totalCards = playerdata->collection->totalCards();
|
||||
if (totalCards){
|
||||
sprintf(buff2, _("You have a total of %i cards in your collection").c_str(),totalCards);
|
||||
if (totalCards)
|
||||
{
|
||||
sprintf(buff2, _("You have a total of %i cards in your collection").c_str(), totalCards);
|
||||
scroller->Add(buff2);
|
||||
|
||||
int estimatedValue = playerdata->collection->totalPrice();
|
||||
sprintf(buff2, _("The shopkeeper would buy your entire collection for around %i credits").c_str(),estimatedValue/2);
|
||||
sprintf(buff2, _("The shopkeeper would buy your entire collection for around %i credits").c_str(), estimatedValue / 2);
|
||||
scroller->Add(buff2);
|
||||
|
||||
sprintf(buff2, _("The cards in your collection have an average value of %i credits").c_str(),estimatedValue/totalCards);
|
||||
sprintf(buff2, _("The cards in your collection have an average value of %i credits").c_str(), estimatedValue / totalCards);
|
||||
scroller->Add(buff2);
|
||||
}
|
||||
|
||||
sprintf(buff2, _("You currently have %i credits").c_str(),playerdata->credits);
|
||||
sprintf(buff2, _("You currently have %i credits").c_str(), playerdata->credits);
|
||||
SAFE_DELETE(playerdata);
|
||||
scroller->Add(buff2);
|
||||
|
||||
@@ -248,28 +264,35 @@ void GameStateMenu::fillScroller(){
|
||||
scrollerSet = 1;
|
||||
scroller->setRandom();
|
||||
}
|
||||
void GameStateMenu::resetDirectory(){
|
||||
if(mDip != NULL) {
|
||||
void GameStateMenu::resetDirectory()
|
||||
{
|
||||
if (mDip != NULL)
|
||||
{
|
||||
closedir(mDip);
|
||||
mDip = NULL;
|
||||
}
|
||||
}
|
||||
int GameStateMenu::nextDirectory(const char * root, const char * file){
|
||||
int GameStateMenu::nextDirectory(const char * root, const char * file)
|
||||
{
|
||||
int found = 0;
|
||||
if (!mDip){
|
||||
if (!mDip)
|
||||
{
|
||||
mDip = opendir(root);
|
||||
}
|
||||
|
||||
while (!found && (mDit = readdir(mDip))){
|
||||
while (!found && (mDit = readdir(mDip)))
|
||||
{
|
||||
sprintf(mCurrentSetFileName, "%s/%s/%s", root, mDit->d_name, file);
|
||||
std::ifstream file(mCurrentSetFileName);
|
||||
if(file){
|
||||
if (file)
|
||||
{
|
||||
sprintf(mCurrentSetName, "%s", mDit->d_name);
|
||||
file.close();
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (!found) resetDirectory();
|
||||
if (!found)
|
||||
resetDirectory();
|
||||
return found;
|
||||
}
|
||||
|
||||
@@ -281,19 +304,24 @@ void GameStateMenu::End()
|
||||
SAFE_DELETE(mGuiController);
|
||||
}
|
||||
|
||||
string GameStateMenu::loadRandomWallpaper() {
|
||||
string GameStateMenu::loadRandomWallpaper()
|
||||
{
|
||||
if (wallpaper.size())
|
||||
return wallpaper;
|
||||
|
||||
vector<string> wallpapers;
|
||||
std::ifstream file(JGE_GET_RES("graphics/wallpapers.txt").c_str());
|
||||
|
||||
if (!file) return wallpaper;
|
||||
if (!file)
|
||||
return wallpaper;
|
||||
|
||||
string s;
|
||||
while (std::getline(file,s)) {
|
||||
if (!s.size()) continue;
|
||||
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
|
||||
while (std::getline(file, s))
|
||||
{
|
||||
if (!s.size())
|
||||
continue;
|
||||
if (s[s.size() - 1] == '\r')
|
||||
s.erase(s.size() - 1); //Handle DOS files
|
||||
wallpapers.push_back(s);
|
||||
}
|
||||
|
||||
@@ -303,63 +331,79 @@ string GameStateMenu::loadRandomWallpaper() {
|
||||
|
||||
}
|
||||
|
||||
string GameStateMenu::getLang(string s){
|
||||
if (!s.size()) return "";
|
||||
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
|
||||
string GameStateMenu::getLang(string s)
|
||||
{
|
||||
if (!s.size())
|
||||
return "";
|
||||
if (s[s.size() - 1] == '\r')
|
||||
s.erase(s.size() - 1); //Handle DOS files
|
||||
size_t found = s.find("#LANG:");
|
||||
if (found != 0) return "";
|
||||
if (found != 0)
|
||||
return "";
|
||||
return s.substr(6);
|
||||
}
|
||||
|
||||
void GameStateMenu::setLang(int id){
|
||||
options[Options::LANG].str = langs[id-1];
|
||||
void GameStateMenu::setLang(int id)
|
||||
{
|
||||
options[Options::LANG].str = langs[id - 1];
|
||||
options.save();
|
||||
}
|
||||
|
||||
void GameStateMenu::loadLangMenu(){
|
||||
void GameStateMenu::loadLangMenu()
|
||||
{
|
||||
LOG("GameStateMenu::loadLangMenu");
|
||||
subMenuController = NEW SimpleMenu( MENU_LANGUAGE_SELECTION, this, Fonts::MENU_FONT, 150,60);
|
||||
if (!subMenuController) return;
|
||||
subMenuController = NEW SimpleMenu(MENU_LANGUAGE_SELECTION, this, Fonts::MENU_FONT, 150, 60);
|
||||
if (!subMenuController)
|
||||
return;
|
||||
resetDirectory();
|
||||
if (!mDip){
|
||||
if (!mDip)
|
||||
{
|
||||
mDip = opendir(JGE_GET_RES("lang").c_str());
|
||||
}
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
while ((mDit = readdir(mDip)))
|
||||
{
|
||||
string filename = JGE_GET_RES("lang/");
|
||||
filename += mDit->d_name;
|
||||
std::ifstream file(filename.c_str());
|
||||
string s;
|
||||
string lang;
|
||||
if(file){
|
||||
if(std::getline(file,s)){
|
||||
if (file)
|
||||
{
|
||||
if (std::getline(file, s))
|
||||
{
|
||||
lang = getLang(s);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
if (lang.size()){
|
||||
if (lang.size())
|
||||
{
|
||||
langChoices = true;
|
||||
string filen = mDit->d_name;
|
||||
langs.push_back(filen.substr(0,filen.size()-4));
|
||||
subMenuController->Add(langs.size(),lang.c_str());
|
||||
langs.push_back(filen.substr(0, filen.size() - 4));
|
||||
subMenuController->Add(langs.size(), lang.c_str());
|
||||
}
|
||||
}
|
||||
resetDirectory();
|
||||
LOG("GameStateMenu::loadLangMenu - Done");
|
||||
}
|
||||
|
||||
void GameStateMenu::listPrimitives(){
|
||||
void GameStateMenu::listPrimitives()
|
||||
{
|
||||
LOG("GameStateMenu::listPrimitives");
|
||||
resetDirectory();
|
||||
if (!mDip){
|
||||
if (!mDip)
|
||||
{
|
||||
mDip = opendir(JGE_GET_RES("sets/primitives/").c_str());
|
||||
}
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
while ((mDit = readdir(mDip)))
|
||||
{
|
||||
string filename = JGE_GET_RES("sets/primitives/");
|
||||
filename += mDit->d_name;
|
||||
std::ifstream file(filename.c_str());
|
||||
if(!file) continue;
|
||||
if (!file)
|
||||
continue;
|
||||
file.close();
|
||||
primitives.push_back(filename);
|
||||
}
|
||||
@@ -368,17 +412,25 @@ void GameStateMenu::listPrimitives(){
|
||||
LOG("GameStateMenu::listPrimitives - Done");
|
||||
}
|
||||
|
||||
void GameStateMenu::ensureMGuiController(){
|
||||
if (!mGuiController) {
|
||||
void GameStateMenu::ensureMGuiController()
|
||||
{
|
||||
if (!mGuiController)
|
||||
{
|
||||
mGuiController = NEW JGuiController(100, this);
|
||||
if (mGuiController) {
|
||||
if (mGuiController)
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::MENU_FONT);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_PLAY, mFont, "Play", 80, 50 + SCREEN_HEIGHT/2, mIcons[8], mIcons[9],"particle1.psi",resources.GetQuad("particles"), true));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_DECKEDITOR, mFont, "Deck Editor", 160, 50 + SCREEN_HEIGHT/2, mIcons[2], mIcons[3],"particle2.psi",resources.GetQuad("particles")));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_SHOP, mFont, "Shop", 240, 50 + SCREEN_HEIGHT/2, mIcons[0], mIcons[1],"particle3.psi",resources.GetQuad("particles")));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_OPTIONS, mFont, "Options", 320, 50 + SCREEN_HEIGHT/2, mIcons[6], mIcons[7],"particle4.psi",resources.GetQuad("particles")));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_EXIT, mFont, "Exit", 400, 50 + SCREEN_HEIGHT/2, mIcons[4], mIcons[5],"particle5.psi",resources.GetQuad("particles")));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_PLAY, mFont, "Play", 80, 50 + SCREEN_HEIGHT / 2, mIcons[8], mIcons[9],
|
||||
"particle1.psi", resources.GetQuad("particles"), true));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_DECKEDITOR, mFont, "Deck Editor", 160, 50 + SCREEN_HEIGHT / 2, mIcons[2],
|
||||
mIcons[3], "particle2.psi", resources.GetQuad("particles")));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_SHOP, mFont, "Shop", 240, 50 + SCREEN_HEIGHT / 2, mIcons[0], mIcons[1],
|
||||
"particle3.psi", resources.GetQuad("particles")));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_OPTIONS, mFont, "Options", 320, 50 + SCREEN_HEIGHT / 2, mIcons[6], mIcons[7],
|
||||
"particle4.psi", resources.GetQuad("particles")));
|
||||
mGuiController->Add(NEW MenuItem(MENUITEM_EXIT, mFont, "Exit", 400, 50 + SCREEN_HEIGHT / 2, mIcons[4], mIcons[5],
|
||||
"particle5.psi", resources.GetQuad("particles")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -386,35 +438,45 @@ void GameStateMenu::ensureMGuiController(){
|
||||
void GameStateMenu::Update(float dt)
|
||||
{
|
||||
timeIndex += dt * 2;
|
||||
switch (MENU_STATE_MAJOR & currentState) {
|
||||
case MENU_STATE_MAJOR_LANG :
|
||||
if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR)) {
|
||||
if (!subMenuController) loadLangMenu();
|
||||
switch (MENU_STATE_MAJOR & currentState)
|
||||
{
|
||||
case MENU_STATE_MAJOR_LANG:
|
||||
if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR))
|
||||
{
|
||||
if (!subMenuController)
|
||||
loadLangMenu();
|
||||
}
|
||||
if(!langChoices){
|
||||
if (!langChoices)
|
||||
{
|
||||
currentState = MENU_STATE_MAJOR_LOADING_CARDS;
|
||||
SAFE_DELETE(subMenuController);
|
||||
}
|
||||
else
|
||||
subMenuController->Update(dt);
|
||||
break;
|
||||
case MENU_STATE_MAJOR_LOADING_CARDS :
|
||||
if (primitivesLoadCounter == -1){
|
||||
case MENU_STATE_MAJOR_LOADING_CARDS:
|
||||
if (primitivesLoadCounter == -1)
|
||||
{
|
||||
listPrimitives();
|
||||
Translator::GetInstance()->init();
|
||||
}
|
||||
if (primitivesLoadCounter < (int)(primitives.size())){
|
||||
mParent->collection->load(primitives[primitivesLoadCounter].c_str() );
|
||||
if (primitivesLoadCounter < (int) (primitives.size()))
|
||||
{
|
||||
mParent->collection->load(primitives[primitivesLoadCounter].c_str());
|
||||
primitivesLoadCounter++;
|
||||
break;
|
||||
}
|
||||
primitivesLoadCounter = primitives.size() + 1;
|
||||
if (mReadConf){
|
||||
if (mReadConf)
|
||||
{
|
||||
mParent->collection->load(mCurrentSetFileName, mCurrentSetName);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
mReadConf = 1;
|
||||
}
|
||||
if (!nextDirectory(JGE_GET_RES("sets/").c_str(),"_cards.dat")){
|
||||
if (!nextDirectory(JGE_GET_RES("sets/").c_str(), "_cards.dat"))
|
||||
{
|
||||
//Remove temporary translations
|
||||
Translator::GetInstance()->tempValues.clear();
|
||||
|
||||
@@ -423,7 +485,7 @@ void GameStateMenu::Update(float dt)
|
||||
"Total CardPrimitives: " << mParent->collection->primitives.size() << std::endl << "==");
|
||||
|
||||
//Force default, if necessary.
|
||||
if(options[Options::ACTIVE_PROFILE].str == "")
|
||||
if (options[Options::ACTIVE_PROFILE].str == "")
|
||||
options[Options::ACTIVE_PROFILE].str = "Default";
|
||||
|
||||
//Release splash texture
|
||||
@@ -433,10 +495,13 @@ void GameStateMenu::Update(float dt)
|
||||
|
||||
//check for deleted collection / first-timer
|
||||
std::ifstream file(options.profileFile(PLAYER_COLLECTION).c_str());
|
||||
if(file){
|
||||
if (file)
|
||||
{
|
||||
file.close();
|
||||
currentState = MENU_STATE_MAJOR_MAINMENU;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState = MENU_STATE_MAJOR_FIRST_TIME;
|
||||
}
|
||||
|
||||
@@ -448,67 +513,79 @@ void GameStateMenu::Update(float dt)
|
||||
resources.ResetCacheLimits();
|
||||
}
|
||||
break;
|
||||
case MENU_STATE_MAJOR_FIRST_TIME :
|
||||
case MENU_STATE_MAJOR_FIRST_TIME:
|
||||
currentState &= MENU_STATE_MAJOR_MAINMENU;
|
||||
options.reloadProfile(); //Handles building a new deck, if needed.
|
||||
break;
|
||||
case MENU_STATE_MAJOR_MAINMENU :
|
||||
if (!scrollerSet) fillScroller();
|
||||
case MENU_STATE_MAJOR_MAINMENU:
|
||||
if (!scrollerSet)
|
||||
fillScroller();
|
||||
ensureMGuiController();
|
||||
if (mGuiController)
|
||||
mGuiController->Update(dt);
|
||||
if(mEngine->GetButtonState(JGE_BTN_NEXT)) //Hook for GameStateAward state
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_AWARDS); //TODO: A slide transition would be nice.
|
||||
if (mEngine->GetButtonState(JGE_BTN_NEXT)) //Hook for GameStateAward state
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_AWARDS); //TODO: A slide transition would be nice.
|
||||
break;
|
||||
case MENU_STATE_MAJOR_SUBMENU :
|
||||
case MENU_STATE_MAJOR_SUBMENU:
|
||||
if (subMenuController)
|
||||
subMenuController->Update(dt);
|
||||
ensureMGuiController();
|
||||
mGuiController->Update(dt);
|
||||
break;
|
||||
case MENU_STATE_MAJOR_DUEL :
|
||||
if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR)) {
|
||||
if (!hasChosenGameType){
|
||||
case MENU_STATE_MAJOR_DUEL:
|
||||
if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR))
|
||||
{
|
||||
if (!hasChosenGameType)
|
||||
{
|
||||
currentState = MENU_STATE_MAJOR_SUBMENU;
|
||||
subMenuController = NEW SimpleMenu( MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150,60);
|
||||
if (subMenuController){
|
||||
subMenuController->Add(SUBMENUITEM_CLASSIC,"Classic");
|
||||
subMenuController = NEW SimpleMenu(MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60);
|
||||
if (subMenuController)
|
||||
{
|
||||
subMenuController->Add(SUBMENUITEM_CLASSIC, "Classic");
|
||||
if (options[Options::MOMIR_MODE_UNLOCKED].number)
|
||||
subMenuController->Add(SUBMENUITEM_MOMIR, "Momir Basic");
|
||||
if (options[Options::RANDOMDECK_MODE_UNLOCKED].number){
|
||||
if (options[Options::RANDOMDECK_MODE_UNLOCKED].number)
|
||||
{
|
||||
subMenuController->Add(SUBMENUITEM_RANDOM1, "Random 1 Color");
|
||||
subMenuController->Add(SUBMENUITEM_RANDOM2, "Random 2 Colors");
|
||||
}
|
||||
subMenuController->Add(SUBMENUITEM_STORY,"Story");
|
||||
subMenuController->Add(SUBMENUITEM_STORY, "Story");
|
||||
subMenuController->Add(SUBMENUITEM_CANCEL, "Cancel");
|
||||
}
|
||||
}else{
|
||||
if (mParent->gameType == GAME_TYPE_STORY )
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mParent->gameType == GAME_TYPE_STORY)
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_STORY);
|
||||
else
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_DUEL);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_DUEL);
|
||||
currentState = MENU_STATE_MAJOR_MAINMENU;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (MENU_STATE_MINOR & currentState){
|
||||
case MENU_STATE_MINOR_SUBMENU_CLOSING :
|
||||
if (!subMenuController){ //http://code.google.com/p/wagic/issues/detail?id=379
|
||||
switch (MENU_STATE_MINOR & currentState)
|
||||
{
|
||||
case MENU_STATE_MINOR_SUBMENU_CLOSING:
|
||||
if (!subMenuController)
|
||||
{ //http://code.google.com/p/wagic/issues/detail?id=379
|
||||
currentState &= ~MENU_STATE_MINOR_SUBMENU_CLOSING;
|
||||
break;
|
||||
}
|
||||
if (subMenuController->closed) {
|
||||
if (subMenuController->closed)
|
||||
{
|
||||
SAFE_DELETE(subMenuController);
|
||||
currentState &= ~MENU_STATE_MINOR_SUBMENU_CLOSING;
|
||||
} else
|
||||
}
|
||||
else
|
||||
subMenuController->Update(dt);
|
||||
break;
|
||||
case MENU_STATE_MINOR_NONE :
|
||||
case MENU_STATE_MINOR_NONE:
|
||||
;// Nothing to do.
|
||||
}
|
||||
|
||||
if(mEngine->GetButtonState(JGE_BTN_PREV)) {
|
||||
if (mEngine->GetButtonState(JGE_BTN_PREV))
|
||||
{
|
||||
//Reset deck of cards
|
||||
angleMultiplier = MIN_ANGLE_MULTIPLIER;
|
||||
yW = 55;
|
||||
@@ -516,129 +593,143 @@ void GameStateMenu::Update(float dt)
|
||||
|
||||
if (yW <= 55)
|
||||
{
|
||||
if (mEngine->GetButtonState(JGE_BTN_PRI)) angleMultiplier += STEP_ANGLE_MULTIPLIER;
|
||||
else angleMultiplier *= 0.9999f;
|
||||
if (angleMultiplier > MAX_ANGLE_MULTIPLIER) angleMultiplier = MAX_ANGLE_MULTIPLIER;
|
||||
else if (angleMultiplier < MIN_ANGLE_MULTIPLIER) angleMultiplier = MIN_ANGLE_MULTIPLIER;
|
||||
if (mEngine->GetButtonState(JGE_BTN_PRI))
|
||||
angleMultiplier += STEP_ANGLE_MULTIPLIER;
|
||||
else
|
||||
angleMultiplier *= 0.9999f;
|
||||
if (angleMultiplier > MAX_ANGLE_MULTIPLIER)
|
||||
angleMultiplier = MAX_ANGLE_MULTIPLIER;
|
||||
else if (angleMultiplier < MIN_ANGLE_MULTIPLIER)
|
||||
angleMultiplier = MIN_ANGLE_MULTIPLIER;
|
||||
|
||||
if (mEngine->GetButtonState(JGE_BTN_CANCEL) && (dt != 0))
|
||||
{
|
||||
angleMultiplier = (cos(timeIndex)*angleMultiplier - M_PI/3.0f - 0.1f - angleW) / dt;
|
||||
yW = yW + 5*dt + (yW - 45) *5* dt;
|
||||
angleMultiplier = (cos(timeIndex) * angleMultiplier - M_PI / 3.0f - 0.1f - angleW) / dt;
|
||||
yW = yW + 5 * dt + (yW - 45) * 5 * dt;
|
||||
}
|
||||
else
|
||||
angleW = cos(timeIndex)*angleMultiplier - M_PI/3.0f - 0.1f;
|
||||
angleW = cos(timeIndex) * angleMultiplier - M_PI / 3.0f - 0.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
angleW += angleMultiplier * dt;
|
||||
yW = yW + 5*dt + (yW - 55) *5*dt;
|
||||
yW = yW + 5 * dt + (yW - 55) * 5 * dt;
|
||||
}
|
||||
|
||||
scroller->Update(dt);
|
||||
if((currentState & MENU_STATE_MINOR) == MENU_STATE_MINOR_FADEIN){
|
||||
if ((currentState & MENU_STATE_MINOR) == MENU_STATE_MINOR_FADEIN)
|
||||
{
|
||||
currentState = currentState ^ MENU_STATE_MINOR_FADEIN;
|
||||
mParent->DoAnimation( TRANSITION_FADE_IN, 0.15f );
|
||||
mParent->DoAnimation(TRANSITION_FADE_IN, 0.15f);
|
||||
}
|
||||
}
|
||||
|
||||
void GameStateMenu::Render()
|
||||
{
|
||||
if((currentState & MENU_STATE_MINOR) == MENU_STATE_MINOR_FADEIN)
|
||||
if ((currentState & MENU_STATE_MINOR) == MENU_STATE_MINOR_FADEIN)
|
||||
return;
|
||||
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
WFont * mFont = resources.GetWFont(Fonts::MENU_FONT);
|
||||
if ((currentState & MENU_STATE_MAJOR) == MENU_STATE_MAJOR_LANG){
|
||||
}else if ((currentState & MENU_STATE_MAJOR) == MENU_STATE_MAJOR_LOADING_CARDS){
|
||||
if(!splashTex){
|
||||
splashTex = resources.RetrieveTexture("splash.jpg",RETRIEVE_LOCK);
|
||||
if ((currentState & MENU_STATE_MAJOR) == MENU_STATE_MAJOR_LANG)
|
||||
{
|
||||
}
|
||||
else if ((currentState & MENU_STATE_MAJOR) == MENU_STATE_MAJOR_LOADING_CARDS)
|
||||
{
|
||||
if (!splashTex)
|
||||
{
|
||||
splashTex = resources.RetrieveTexture("splash.jpg", RETRIEVE_LOCK);
|
||||
mSplash = resources.RetrieveTempQuad("splash.jpg");
|
||||
}
|
||||
if (mSplash)
|
||||
renderer->RenderQuad(mSplash,0,0);
|
||||
else {
|
||||
renderer->RenderQuad(mSplash, 0, 0);
|
||||
else
|
||||
{
|
||||
string wp = loadRandomWallpaper();
|
||||
if (wp.size()) {
|
||||
if (wp.size())
|
||||
{
|
||||
JTexture * wpTex = resources.RetrieveTexture(wp);
|
||||
if (wpTex) {
|
||||
if (wpTex)
|
||||
{
|
||||
JQuad * wpQuad = resources.RetrieveTempQuad(wp);
|
||||
renderer->RenderQuad(wpQuad,0,0,0,SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight);
|
||||
renderer->RenderQuad(wpQuad, 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
char text[512];
|
||||
if (mCurrentSetName[0]) {
|
||||
if (mCurrentSetName[0])
|
||||
{
|
||||
sprintf(text, _("LOADING SET: %s").c_str(), mCurrentSetName);
|
||||
}else{
|
||||
if (primitivesLoadCounter <= (int)(primitives.size()))
|
||||
sprintf(text,"LOADING PRIMITIVES");
|
||||
}
|
||||
else
|
||||
sprintf(text,"LOADING...");
|
||||
{
|
||||
if (primitivesLoadCounter <= (int) (primitives.size()))
|
||||
sprintf(text, "LOADING PRIMITIVES");
|
||||
else
|
||||
sprintf(text, "LOADING...");
|
||||
}
|
||||
mFont->SetColor(ARGB(170,0,0,0));
|
||||
mFont->DrawString(text,SCREEN_WIDTH/2 + 2 ,SCREEN_HEIGHT - 50 + 2,JGETEXT_CENTER);
|
||||
mFont->DrawString(text, SCREEN_WIDTH / 2 + 2, SCREEN_HEIGHT - 50 + 2, JGETEXT_CENTER);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(text,SCREEN_WIDTH/2,SCREEN_HEIGHT - 50,JGETEXT_CENTER);
|
||||
}else{
|
||||
mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
PIXEL_TYPE colors[] =
|
||||
mFont->DrawString(text, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 50, JGETEXT_CENTER);
|
||||
}
|
||||
else
|
||||
{
|
||||
mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
PIXEL_TYPE colors[] = {
|
||||
|
||||
ARGB(255,3,3,0),
|
||||
ARGB(255,8,8,0),
|
||||
ARGB(255,21,21,10),
|
||||
ARGB(255,50,50,30),
|
||||
};
|
||||
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,colors);
|
||||
ARGB(255,3,3,0), ARGB(255,8,8,0), ARGB(255,21,21,10), ARGB(255,50,50,30), };
|
||||
renderer->FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, colors);
|
||||
|
||||
if (mGuiController)
|
||||
mGuiController->Render();
|
||||
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
mFont->SetColor(ARGB(128,255,255,255));
|
||||
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-74,5,JGETEXT_RIGHT);
|
||||
mFont->DrawString(nbcardsStr,10, 5);
|
||||
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH - 74, 5, JGETEXT_RIGHT);
|
||||
mFont->DrawString(nbcardsStr, 10, 5);
|
||||
mFont->SetScale(1.f);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
|
||||
renderer->FillRoundRect(SCREEN_WIDTH/2 - 100,SCREEN_HEIGHT, 191,6,5,ARGB(100,10,5,0));
|
||||
renderer->FillRoundRect(SCREEN_WIDTH / 2 - 100, SCREEN_HEIGHT, 191, 6, 5, ARGB(100,10,5,0));
|
||||
scroller->Render();
|
||||
|
||||
|
||||
if(mBg)
|
||||
renderer->RenderQuad(mBg,SCREEN_WIDTH/2,50);
|
||||
if (mBg)
|
||||
renderer->RenderQuad(mBg, SCREEN_WIDTH / 2, 50);
|
||||
|
||||
JQuad * jq = resources.RetrieveTempQuad("button_shoulder.png");
|
||||
if(jq){
|
||||
if (jq)
|
||||
{
|
||||
int alp = 255;
|
||||
if(options.newAward())
|
||||
alp = (int)(sin(timeIndex) * 255);
|
||||
if (options.newAward())
|
||||
alp = (int) (sin(timeIndex) * 255);
|
||||
float olds = mFont->GetScale();
|
||||
mFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
jq->SetColor(ARGB(abs(alp),255,255,255));
|
||||
mFont->SetColor(ARGB(abs(alp),0,0,0));
|
||||
string s = _("Trophy Room");;
|
||||
string s = _("Trophy Room");
|
||||
;
|
||||
mFont->SetScale(1.0f);
|
||||
mFont->SetScale(50.0f/mFont->GetStringWidth(s.c_str()));
|
||||
renderer->RenderQuad(jq, SCREEN_WIDTH-64, 2);
|
||||
mFont->DrawString(s,SCREEN_WIDTH-10,9,JGETEXT_RIGHT);
|
||||
mFont->SetScale(50.0f / mFont->GetStringWidth(s.c_str()));
|
||||
renderer->RenderQuad(jq, SCREEN_WIDTH - 64, 2);
|
||||
mFont->DrawString(s, SCREEN_WIDTH - 10, 9, JGETEXT_RIGHT);
|
||||
mFont = resources.GetWFont(Fonts::MENU_FONT);
|
||||
mFont->SetScale(olds);
|
||||
}
|
||||
}
|
||||
if (subMenuController){
|
||||
if (subMenuController)
|
||||
{
|
||||
subMenuController->Render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GameStateMenu::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::MENU_FONT);
|
||||
|
||||
DebugTrace("GameStateMenu: controllerId " << controllerId << " selected");
|
||||
switch (controllerId){
|
||||
switch (controllerId)
|
||||
{
|
||||
case MENU_LANGUAGE_SELECTION:
|
||||
setLang(controlId);
|
||||
resources.ReloadWFonts(); // Fix for choosing Chinese language at first time.
|
||||
@@ -653,13 +744,14 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId)
|
||||
switch (controlId)
|
||||
{
|
||||
case MENUITEM_PLAY:
|
||||
subMenuController = NEW SimpleMenu( MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150,60);
|
||||
if (subMenuController){
|
||||
subMenuController->Add(SUBMENUITEM_1PLAYER,"1 Player");
|
||||
subMenuController = NEW SimpleMenu(MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60);
|
||||
if (subMenuController)
|
||||
{
|
||||
subMenuController->Add(SUBMENUITEM_1PLAYER, "1 Player");
|
||||
// TODO Put 2 players mode back
|
||||
// This requires to fix the hand (to accept 2 players) OR to implement network game
|
||||
//subMenuController->Add(SUBMENUITEM_2PLAYER, "2 Players");
|
||||
subMenuController->Add(SUBMENUITEM_DEMO,"Demo");
|
||||
subMenuController->Add(SUBMENUITEM_DEMO, "Demo");
|
||||
subMenuController->Add(SUBMENUITEM_CANCEL, "Cancel");
|
||||
#ifdef TESTSUITE
|
||||
subMenuController->Add(SUBMENUITEM_TESTSUITE, "Test Suite");
|
||||
@@ -668,13 +760,13 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId)
|
||||
}
|
||||
break;
|
||||
case MENUITEM_DECKEDITOR:
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_DECK_VIEWER);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_DECK_VIEWER);
|
||||
break;
|
||||
case MENUITEM_SHOP:
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_SHOP);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_SHOP);
|
||||
break;
|
||||
case MENUITEM_OPTIONS:
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_OPTIONS);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_OPTIONS);
|
||||
break;
|
||||
case MENUITEM_EXIT:
|
||||
mEngine->End();
|
||||
|
||||
@@ -17,8 +17,13 @@ namespace
|
||||
|
||||
}
|
||||
|
||||
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent), mReload(false), grabber(NULL), optionsMenu(NULL), optionsTabs(NULL) {}
|
||||
GameStateOptions::~GameStateOptions() {}
|
||||
GameStateOptions::GameStateOptions(GameApp* parent) :
|
||||
GameState(parent), mReload(false), grabber(NULL), optionsMenu(NULL), optionsTabs(NULL)
|
||||
{
|
||||
}
|
||||
GameStateOptions::~GameStateOptions()
|
||||
{
|
||||
}
|
||||
|
||||
void GameStateOptions::Start()
|
||||
{
|
||||
@@ -33,11 +38,14 @@ void GameStateOptions::Start()
|
||||
|
||||
optionsList->Add(NEW WGuiHeader("General Options"));
|
||||
if (GameApp::HasMusic)
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::MUSICVOLUME,"Music volume",100,10,100),OptionVolume::getInstance()));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::SFXVOLUME,"SFX volume",100,10,100),OptionVolume::getInstance()));
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number){
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::DIFFICULTY,"Difficulty",3,1,0),OptionDifficulty::getInstance()));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::ECON_DIFFICULTY,"Economic Difficuly",Constants::ECON_EASY)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::MUSICVOLUME, "Music volume", 100, 10, 100),
|
||||
OptionVolume::getInstance()));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::SFXVOLUME, "SFX volume", 100, 10, 100), OptionVolume::getInstance()));
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number)
|
||||
{
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::DIFFICULTY, "Difficulty", 3, 1, 0),
|
||||
OptionDifficulty::getInstance()));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::ECON_DIFFICULTY, "Economic Difficuly", Constants::ECON_EASY)));
|
||||
}
|
||||
optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDS, "Seconds to pause for an Interrupt", 20, 1));
|
||||
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYSPELLS, "Interrupt my spells"));
|
||||
@@ -48,30 +56,30 @@ void GameStateOptions::Start()
|
||||
|
||||
optionsList = NEW WGuiList("Game");
|
||||
optionsList->Add(NEW WGuiHeader("Interface Options"));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::CLOSEDHAND,"Closed hand",1,1,0)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::HANDDIRECTION,"Hand direction",1,1,0)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::MANADISPLAY,"Mana display",2,1,0)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::CLOSEDHAND, "Closed hand", 1, 1, 0)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::HANDDIRECTION, "Hand direction", 1, 1, 0)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::MANADISPLAY, "Mana display", 2, 1, 0)));
|
||||
optionsList->Add(NEW OptionInteger(Options::REVERSETRIGGERS, "Reverse left and right triggers"));
|
||||
optionsList->Add(NEW OptionInteger(Options::DISABLECARDS,"Disable card images"));
|
||||
optionsList->Add(NEW OptionInteger(Options::TRANSITIONS,"Disable screen transitions"));
|
||||
optionsList->Add(NEW OptionInteger(Options::DISABLECARDS, "Disable card images"));
|
||||
optionsList->Add(NEW OptionInteger(Options::TRANSITIONS, "Disable screen transitions"));
|
||||
optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information"));
|
||||
optionsTabs->Add(optionsList);
|
||||
|
||||
optionsList = NEW WGuiList("User");
|
||||
optionsList->Add(NEW WGuiHeader("User Options"));
|
||||
WDecoConfirm * cPrf = NEW WDecoConfirm(this,NEW OptionProfile(mParent,this));
|
||||
WDecoConfirm * cPrf = NEW WDecoConfirm(this, NEW OptionProfile(mParent, this));
|
||||
cPrf->confirm = "Use this Profile";
|
||||
OptionThemeStyle * ots = NEW OptionThemeStyle("Theme Style");
|
||||
OptionDirectory * od = NEW OptionTheme(ots);
|
||||
WDecoConfirm * cThm = NEW WDecoConfirm(this,od);
|
||||
WDecoConfirm * cThm = NEW WDecoConfirm(this, od);
|
||||
cThm->confirm = "Use this Theme";
|
||||
|
||||
WDecoConfirm * cStyle = NEW WDecoConfirm(this,ots);
|
||||
WDecoConfirm * cStyle = NEW WDecoConfirm(this, ots);
|
||||
cStyle->confirm = "Use this Style";
|
||||
|
||||
optionsList->Add(NEW WGuiSplit(cPrf,cThm));
|
||||
optionsList->Add(NEW WGuiSplit(cPrf, cThm));
|
||||
optionsList->Add(cStyle);
|
||||
optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"),-102, kNewProfileID, this));
|
||||
optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"), -102, kNewProfileID, this));
|
||||
|
||||
optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::CHEATMODE, "Enable cheat mode")));
|
||||
optionsTabs->Add(optionsList);
|
||||
@@ -81,12 +89,14 @@ void GameStateOptions::Start()
|
||||
WDecoStyled * wAdv = NEW WDecoStyled(NEW WGuiHeader("The following options require a restart."));
|
||||
wAdv->mStyle = WDecoStyled::DS_STYLE_ALERT;
|
||||
optionsList->Add(wAdv);
|
||||
WDecoConfirm * cLang = NEW WDecoConfirm(this,NEW OptionLanguage("Language"));
|
||||
WDecoConfirm * cLang = NEW WDecoConfirm(this, NEW OptionLanguage("Language"));
|
||||
cLang->confirm = "Use this Language";
|
||||
optionsList->Add(cLang);
|
||||
WDecoEnum * oGra = NEW WDecoEnum(NEW OptionInteger(Options::MAX_GRADE,"Minimum Card Grade",Constants::GRADE_DANGEROUS,1,Constants::GRADE_BORDERLINE,"",Constants::GRADE_SUPPORTED));
|
||||
WDecoEnum * oGra = NEW WDecoEnum(NEW OptionInteger(Options::MAX_GRADE, "Minimum Card Grade", Constants::GRADE_DANGEROUS, 1,
|
||||
Constants::GRADE_BORDERLINE, "", Constants::GRADE_SUPPORTED));
|
||||
optionsList->Add(oGra);
|
||||
WDecoEnum * oASPhases = NEW WDecoEnum(NEW OptionInteger(Options::ASPHASES,"Phase Skip Automation",Constants::ASKIP_FULL,1,Constants::ASKIP_NONE,"",Constants::ASKIP_NONE));
|
||||
WDecoEnum * oASPhases = NEW WDecoEnum(NEW OptionInteger(Options::ASPHASES, "Phase Skip Automation", Constants::ASKIP_FULL, 1,
|
||||
Constants::ASKIP_NONE, "", Constants::ASKIP_NONE));
|
||||
optionsList->Add(oASPhases);
|
||||
optionsTabs->Add(optionsList);
|
||||
|
||||
@@ -97,7 +107,7 @@ void GameStateOptions::Start()
|
||||
optionsList->failMsg = "";
|
||||
optionsTabs->Add(optionsList);
|
||||
|
||||
optionsMenu = NEW SimpleMenu(-102, this,Fonts::MENU_FONT, 50,170);
|
||||
optionsMenu = NEW SimpleMenu(-102, this, Fonts::MENU_FONT, 50, 170);
|
||||
optionsMenu->Add(kBackToMainMenuID, "Back to Main Menu");
|
||||
optionsMenu->Add(kSaveAndBackToMainMenuID, "Save & Back to Main Menu");
|
||||
optionsMenu->Add(kCancelMenuID, "Cancel");
|
||||
@@ -105,7 +115,6 @@ void GameStateOptions::Start()
|
||||
optionsTabs->Entering(JGE_BTN_NONE);
|
||||
}
|
||||
|
||||
|
||||
void GameStateOptions::End()
|
||||
{
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
@@ -113,17 +122,19 @@ void GameStateOptions::End()
|
||||
SAFE_DELETE(optionsMenu);
|
||||
}
|
||||
|
||||
|
||||
void GameStateOptions::Update(float dt)
|
||||
{
|
||||
timer += dt * 10;
|
||||
|
||||
if(options.keypadActive()){
|
||||
if (options.keypadActive())
|
||||
{
|
||||
options.keypadUpdate(dt);
|
||||
|
||||
if(newProfile != ""){
|
||||
if (newProfile != "")
|
||||
{
|
||||
newProfile = options.keypadFinish();
|
||||
if(newProfile != ""){
|
||||
if (newProfile != "")
|
||||
{
|
||||
options[Options::ACTIVE_PROFILE] = newProfile;
|
||||
options.reloadProfile(false);
|
||||
optionsTabs->Reload();
|
||||
@@ -131,7 +142,9 @@ void GameStateOptions::Update(float dt)
|
||||
newProfile = "";
|
||||
}
|
||||
}
|
||||
else switch(mState){
|
||||
else
|
||||
switch (mState)
|
||||
{
|
||||
default:
|
||||
case SAVE:
|
||||
switch (optionsTabs->needsConfirm())
|
||||
@@ -143,7 +156,7 @@ void GameStateOptions::Update(float dt)
|
||||
optionsTabs->save();
|
||||
JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number);
|
||||
JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number);
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
mState = SHOW_OPTIONS;
|
||||
break;
|
||||
case WGuiBase::CONFIRM_NEED:
|
||||
@@ -151,16 +164,20 @@ void GameStateOptions::Update(float dt)
|
||||
break;
|
||||
}
|
||||
// Note : No break here : must continue to continue updating the menu elements.
|
||||
case SHOW_OPTIONS: {
|
||||
case SHOW_OPTIONS:
|
||||
{
|
||||
JGE* j = JGE::GetInstance();
|
||||
JButton key;
|
||||
if (grabber) {
|
||||
if (grabber)
|
||||
{
|
||||
LocalKeySym sym;
|
||||
if (LOCAL_KEY_NONE != (sym = j->ReadLocalKey()))
|
||||
grabber->KeyPressed(sym);
|
||||
}
|
||||
else while ((key = JGE::GetInstance()->ReadButton())){
|
||||
if(!optionsTabs->CheckUserInput(key) && key == JGE_BTN_MENU)
|
||||
else
|
||||
while ((key = JGE::GetInstance()->ReadButton()))
|
||||
{
|
||||
if (!optionsTabs->CheckUserInput(key) && key == JGE_BTN_MENU)
|
||||
mState = SHOW_OPTIONS_MENU;
|
||||
}
|
||||
optionsTabs->Update(dt);
|
||||
@@ -170,7 +187,8 @@ void GameStateOptions::Update(float dt)
|
||||
optionsMenu->Update(dt);
|
||||
break;
|
||||
}
|
||||
if(mReload){
|
||||
if (mReload)
|
||||
{
|
||||
options.reloadProfile(true);
|
||||
Translator::EndInstance();
|
||||
Translator::GetInstance()->init();
|
||||
@@ -229,43 +247,45 @@ void GameStateOptions::Render()
|
||||
float pos = startpos;
|
||||
int size = sizeof(CreditsText) / sizeof(CreditsText[0]);
|
||||
|
||||
for (int i = 0; i < size; i++){
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
pos = startpos + 20 * i;
|
||||
if (pos > -20 && pos < SCREEN_HEIGHT + 20){
|
||||
mFont->DrawString(CreditsText[i],SCREEN_WIDTH/2,pos ,JGETEXT_CENTER);
|
||||
if (pos > -20 && pos < SCREEN_HEIGHT + 20)
|
||||
{
|
||||
mFont->DrawString(CreditsText[i], SCREEN_WIDTH / 2, pos, JGETEXT_CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
if (pos < -20)
|
||||
timer = 0;
|
||||
|
||||
|
||||
optionsTabs->Render();
|
||||
|
||||
if(mState == SHOW_OPTIONS_MENU)
|
||||
if (mState == SHOW_OPTIONS_MENU)
|
||||
optionsMenu->Render();
|
||||
|
||||
if(options.keypadActive())
|
||||
if (options.keypadActive())
|
||||
options.keypadRender();
|
||||
}
|
||||
|
||||
void GameStateOptions::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
//Exit menu?
|
||||
if(controllerId == -102)
|
||||
switch (controlId){
|
||||
if (controllerId == -102)
|
||||
switch (controlId)
|
||||
{
|
||||
case kSaveAndBackToMainMenuID:
|
||||
mState = SAVE;
|
||||
break;
|
||||
//Set Audio volume
|
||||
case kBackToMainMenuID:
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
break;
|
||||
case kCancelMenuID:
|
||||
mState = SHOW_OPTIONS;
|
||||
break;
|
||||
case kNewProfileID:
|
||||
options.keypadStart("",&newProfile);
|
||||
options.keypadStart("", &newProfile);
|
||||
options.keypadTitle("New Profile");
|
||||
break;
|
||||
case kReloadID:
|
||||
@@ -274,11 +294,15 @@ void GameStateOptions::ButtonPressed(int controllerId, int controlId)
|
||||
}
|
||||
else
|
||||
optionsTabs->ButtonPressed(controllerId, controlId);
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
void GameStateOptions::GrabKeyboard(KeybGrabber* g) {
|
||||
void GameStateOptions::GrabKeyboard(KeybGrabber* g)
|
||||
{
|
||||
grabber = g;
|
||||
}
|
||||
void GameStateOptions::UngrabKeyboard(const KeybGrabber* g) {
|
||||
if (g == grabber) grabber = NULL;
|
||||
void GameStateOptions::UngrabKeyboard(const KeybGrabber* g)
|
||||
{
|
||||
if (g == grabber)
|
||||
grabber = NULL;
|
||||
}
|
||||
|
||||
+385
-254
File diff suppressed because it is too large
Load Diff
@@ -6,17 +6,20 @@
|
||||
#include "GameApp.h"
|
||||
#include <dirent.h>
|
||||
|
||||
GameStateStory::GameStateStory(GameApp* parent): GameState(parent) {
|
||||
GameStateStory::GameStateStory(GameApp* parent) :
|
||||
GameState(parent)
|
||||
{
|
||||
flow = NULL;
|
||||
menu = NULL;
|
||||
}
|
||||
|
||||
GameStateStory::~GameStateStory() {
|
||||
GameStateStory::~GameStateStory()
|
||||
{
|
||||
End();
|
||||
}
|
||||
|
||||
|
||||
void GameStateStory::loadStoriesMenu(const char * root){
|
||||
void GameStateStory::loadStoriesMenu(const char * root)
|
||||
{
|
||||
SAFE_DELETE(menu);
|
||||
stories.clear();
|
||||
DIR *mDip;
|
||||
@@ -24,11 +27,13 @@ void GameStateStory::loadStoriesMenu(const char * root){
|
||||
|
||||
mDip = opendir(root);
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
while ((mDit = readdir(mDip)))
|
||||
{
|
||||
char buffer[4096];
|
||||
sprintf(buffer, "%s%s/story.xml", root, mDit->d_name);
|
||||
std::ifstream file(buffer);
|
||||
if(file){
|
||||
if (file)
|
||||
{
|
||||
string fname = mDit->d_name;
|
||||
stories.push_back(fname);
|
||||
file.close();
|
||||
@@ -36,74 +41,95 @@ void GameStateStory::loadStoriesMenu(const char * root){
|
||||
}
|
||||
closedir(mDip);
|
||||
|
||||
switch(stories.size()){
|
||||
switch (stories.size())
|
||||
{
|
||||
case 0:
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
break;
|
||||
case 1:
|
||||
flow = NEW StoryFlow(stories[0]);
|
||||
break;
|
||||
default:
|
||||
menu = NEW SimpleMenu(103, this, Fonts::MENU_FONT, 150,60);
|
||||
for (size_t i = 0; i < stories.size(); ++i){
|
||||
menu = NEW SimpleMenu(103, this, Fonts::MENU_FONT, 150, 60);
|
||||
for (size_t i = 0; i < stories.size(); ++i)
|
||||
{
|
||||
menu->Add(i, stories[i].c_str());
|
||||
}
|
||||
menu->Add(kCancelMenuID, "Cancel");
|
||||
}
|
||||
}
|
||||
|
||||
void GameStateStory::Start() {
|
||||
void GameStateStory::Start()
|
||||
{
|
||||
flow = NULL;
|
||||
menu = NULL;
|
||||
loadStoriesMenu(JGE_GET_RES("campaigns/").c_str());
|
||||
}
|
||||
|
||||
void GameStateStory::Update(float dt) {
|
||||
if (!menu && mEngine->GetButtonClick(JGE_BTN_MENU)){
|
||||
menu = NEW SimpleMenu(100, this, Fonts::MENU_FONT, SCREEN_WIDTH/2-100, 25);
|
||||
menu->Add(0,"Back to main menu");
|
||||
void GameStateStory::Update(float dt)
|
||||
{
|
||||
if (!menu && mEngine->GetButtonClick(JGE_BTN_MENU))
|
||||
{
|
||||
menu = NEW SimpleMenu(100, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25);
|
||||
menu->Add(0, "Back to main menu");
|
||||
menu->Add(kCancelMenuID, "Cancel");
|
||||
}
|
||||
if (menu) {
|
||||
if (menu)
|
||||
{
|
||||
menu->Update(dt);
|
||||
if (menu->closed)
|
||||
SAFE_DELETE(menu);
|
||||
//return;
|
||||
}
|
||||
if (flow){
|
||||
if (flow->currentPageId == "End") {
|
||||
if (mEngine->GetButtonClick(JGE_BTN_OK) || mEngine->GetButtonClick(JGE_BTN_SEC)){
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
if (flow)
|
||||
{
|
||||
if (flow->currentPageId == "End")
|
||||
{
|
||||
if (mEngine->GetButtonClick(JGE_BTN_OK) || mEngine->GetButtonClick(JGE_BTN_SEC))
|
||||
{
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
}
|
||||
}
|
||||
flow->Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void GameStateStory::Render() {
|
||||
if (flow) flow->Render();
|
||||
if (menu) menu->Render();
|
||||
void GameStateStory::Render()
|
||||
{
|
||||
if (flow)
|
||||
flow->Render();
|
||||
if (menu)
|
||||
menu->Render();
|
||||
}
|
||||
|
||||
void GameStateStory::End() {
|
||||
void GameStateStory::End()
|
||||
{
|
||||
SAFE_DELETE(flow);
|
||||
SAFE_DELETE(menu);
|
||||
}
|
||||
|
||||
void GameStateStory::ButtonPressed(int controllerId, int controlId) {
|
||||
void GameStateStory::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
menu->Close();
|
||||
|
||||
switch (controllerId){
|
||||
switch (controllerId)
|
||||
{
|
||||
case 100:
|
||||
if (controlId == -1){
|
||||
}else {
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
if (controlId == -1)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (controlId == -1){
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
}else {
|
||||
if (controlId == -1)
|
||||
{
|
||||
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
|
||||
}
|
||||
else
|
||||
{
|
||||
flow = NEW StoryFlow(stories[controlId]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,49 +9,63 @@
|
||||
#include "OptionItem.h"
|
||||
#include "GameOptions.h"
|
||||
|
||||
TransitionBase::TransitionBase(GameApp* parent, GameState* _from, GameState* _to, float duration): GameState(parent){
|
||||
TransitionBase::TransitionBase(GameApp* parent, GameState* _from, GameState* _to, float duration) :
|
||||
GameState(parent)
|
||||
{
|
||||
from = _from;
|
||||
to = _to;
|
||||
mDuration = duration;
|
||||
bAnimationOnly = false;
|
||||
}
|
||||
TransitionBase::~TransitionBase(){
|
||||
if(!bAnimationOnly){
|
||||
if(from)
|
||||
TransitionBase::~TransitionBase()
|
||||
{
|
||||
if (!bAnimationOnly)
|
||||
{
|
||||
if (from)
|
||||
from->End();
|
||||
}
|
||||
}
|
||||
void TransitionBase::Update(float dt){
|
||||
if(from && !Finished())
|
||||
void TransitionBase::Update(float dt)
|
||||
{
|
||||
if (from && !Finished())
|
||||
from->Update(dt);
|
||||
mElapsed += dt;
|
||||
}
|
||||
|
||||
void TransitionBase::ButtonPressed(int controllerId, int controlId){
|
||||
if(!from) return;
|
||||
JGuiListener * jgl = dynamic_cast<JGuiListener*>(from);
|
||||
if(jgl)
|
||||
jgl->ButtonPressed(controllerId,controlId);
|
||||
void TransitionBase::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
if (!from)
|
||||
return;
|
||||
JGuiListener * jgl = dynamic_cast<JGuiListener*> (from);
|
||||
if (jgl)
|
||||
jgl->ButtonPressed(controllerId, controlId);
|
||||
}
|
||||
|
||||
void TransitionBase::Start() {
|
||||
void TransitionBase::Start()
|
||||
{
|
||||
mElapsed = 0;
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
void TransitionBase::End() {
|
||||
void TransitionBase::End()
|
||||
{
|
||||
mElapsed = 0;
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
void TransitionFade::Render(){
|
||||
if(from)
|
||||
void TransitionFade::Render()
|
||||
{
|
||||
if (from)
|
||||
from->Render();
|
||||
float fade = 255*mElapsed/mDuration;
|
||||
if(mReversed)
|
||||
float fade = 255 * mElapsed / mDuration;
|
||||
if (mReversed)
|
||||
fade = 255 - fade;
|
||||
JRenderer::GetInstance()->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB((int)fade,0,0,0));
|
||||
JRenderer::GetInstance()->FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB((int)fade,0,0,0));
|
||||
}
|
||||
|
||||
TransitionFade::TransitionFade(GameApp* p, GameState* f, GameState* t, float dur, bool reversed):
|
||||
TransitionBase(p, f,t,dur) {
|
||||
TransitionFade::TransitionFade(GameApp* p, GameState* f, GameState* t, float dur, bool reversed) :
|
||||
TransitionBase(p, f, t, dur)
|
||||
{
|
||||
mReversed = reversed;
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
@@ -7,22 +7,23 @@
|
||||
|
||||
#define LIB_GRAVE_OFFSET 230
|
||||
|
||||
GuiAvatars::GuiAvatars() : active(NULL)
|
||||
GuiAvatars::GuiAvatars() :
|
||||
active(NULL)
|
||||
{
|
||||
Add(self = NEW GuiAvatar (SCREEN_WIDTH, SCREEN_HEIGHT, false,
|
||||
GameObserver::GetInstance()->players[0], GuiAvatar::BOTTOM_RIGHT, this));
|
||||
Add(selfGraveyard = NEW GuiGraveyard(SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width/2 - 5, SCREEN_HEIGHT - GuiAvatar::Height - 5, false,
|
||||
GameObserver::GetInstance()->players[0], this));
|
||||
Add(selfLibrary = NEW GuiLibrary (SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width/2 - 5 , SCREEN_HEIGHT - GuiAvatar::Height - 5 + GuiGameZone::Height + 5, false,
|
||||
GameObserver::GetInstance()->players[0], this));
|
||||
Add(self = NEW GuiAvatar(SCREEN_WIDTH, SCREEN_HEIGHT, false, GameObserver::GetInstance()->players[0], GuiAvatar::BOTTOM_RIGHT, this));
|
||||
Add(selfGraveyard = NEW GuiGraveyard(SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width / 2 - 5, SCREEN_HEIGHT - GuiAvatar::Height - 5, false, GameObserver::GetInstance()->players[0], this));
|
||||
Add(selfLibrary = NEW GuiLibrary(SCREEN_WIDTH - GuiAvatar::Width - GuiGameZone::Width / 2 - 5, SCREEN_HEIGHT - GuiAvatar::Height - 5 + GuiGameZone::Height + 5, false, GameObserver::GetInstance()->players[0], this));
|
||||
|
||||
Add(opponent = NEW GuiAvatar (0, 0, false, GameObserver::GetInstance()->players[1], GuiAvatar::TOP_LEFT, this));
|
||||
Add(opponent = NEW GuiAvatar(0, 0, false, GameObserver::GetInstance()->players[1], GuiAvatar::TOP_LEFT, this));
|
||||
opponent->zoom = 0.9f;
|
||||
//opponenthandveiw button
|
||||
Add(opponentHand = NEW GuiOpponentHand(-30 + GuiAvatar::Width * 1.2 - GuiGameZone::Width / 2, 35 + GuiGameZone::Height - 10, false, GameObserver::GetInstance()->players[1], this));
|
||||
Add(opponentHand = NEW GuiOpponentHand(-30 + GuiAvatar::Width * 1.2 - GuiGameZone::Width / 2, 35 + GuiGameZone::Height - 10,
|
||||
false, GameObserver::GetInstance()->players[1], this));
|
||||
//opponenthandveiwends
|
||||
Add(opponentGraveyard = NEW GuiGraveyard(5 + GuiAvatar::Width * 1.2 - GuiGameZone::Width / 2, 5, false, GameObserver::GetInstance()->players[1], this));
|
||||
Add(opponentLibrary = NEW GuiLibrary (5 + GuiAvatar::Width *1.2 - GuiGameZone::Width / 2, 5 + GuiGameZone::Height + 5, false, GameObserver::GetInstance()->players[1], this));
|
||||
Add(opponentGraveyard = NEW GuiGraveyard(5 + GuiAvatar::Width * 1.2 - GuiGameZone::Width / 2, 5, false,
|
||||
GameObserver::GetInstance()->players[1], this));
|
||||
Add(opponentLibrary = NEW GuiLibrary(5 + GuiAvatar::Width * 1.2 - GuiGameZone::Width / 2, 5 + GuiGameZone::Height + 5, false,
|
||||
GameObserver::GetInstance()->players[1], this));
|
||||
|
||||
CardSelectorSingleton::Instance()->Add(self);
|
||||
CardSelectorSingleton::Instance()->Add(selfGraveyard);
|
||||
@@ -34,7 +35,8 @@ GuiAvatars::GuiAvatars() : active(NULL)
|
||||
selfGraveyard->alpha = selfLibrary->alpha = opponentGraveyard->alpha = opponentLibrary->alpha = opponentHand->alpha = 0;
|
||||
}
|
||||
|
||||
float GuiAvatars::LeftBoundarySelf(){
|
||||
float GuiAvatars::LeftBoundarySelf()
|
||||
{
|
||||
return SCREEN_WIDTH - 10;
|
||||
}
|
||||
|
||||
@@ -47,7 +49,7 @@ void GuiAvatars::Activate(PlayGuiObject* c)
|
||||
c->zoom = 1.2f;
|
||||
c->mHasFocus = true;
|
||||
|
||||
if ((opponentGraveyard == c) || (opponentLibrary == c) || (opponent == c)|| (opponentHand == c) )
|
||||
if ((opponentGraveyard == c) || (opponentLibrary == c) || (opponent == c) || (opponentHand == c))
|
||||
{
|
||||
opponentGraveyard->alpha = opponentLibrary->alpha = opponentHand->alpha = 128.0f;
|
||||
active = opponent;
|
||||
@@ -59,7 +61,8 @@ void GuiAvatars::Activate(PlayGuiObject* c)
|
||||
self->zoom = 1.0f;
|
||||
active = self;
|
||||
}
|
||||
if (opponent != c && self != c) c->alpha = 255.0f;
|
||||
if (opponent != c && self != c)
|
||||
c->alpha = 255.0f;
|
||||
}
|
||||
void GuiAvatars::Deactivate(PlayGuiObject* c)
|
||||
{
|
||||
@@ -69,9 +72,11 @@ void GuiAvatars::Deactivate(PlayGuiObject* c)
|
||||
{
|
||||
opponentGraveyard->alpha = opponentLibrary->alpha = opponentHand->alpha = 0;
|
||||
opponent->zoom = 0.9f;
|
||||
active = NULL;}
|
||||
else if ((selfGraveyard == c) || (selfLibrary == c) ||(self == c))
|
||||
{ selfGraveyard->alpha = selfLibrary->alpha = 0;
|
||||
active = NULL;
|
||||
}
|
||||
else if ((selfGraveyard == c) || (selfLibrary == c) || (self == c))
|
||||
{
|
||||
selfGraveyard->alpha = selfLibrary->alpha = 0;
|
||||
self->zoom = 0.3f;
|
||||
active = NULL;
|
||||
}
|
||||
@@ -90,25 +95,39 @@ int GuiAvatars::receiveEventMinus(WEvent* e)
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool GuiAvatars::CheckUserInput(JButton key){
|
||||
if (self->CheckUserInput(key)) return true;
|
||||
if (opponent->CheckUserInput(key)) return true;
|
||||
if (selfGraveyard->CheckUserInput(key)) return true;
|
||||
if (opponentGraveyard->CheckUserInput(key)) return true;
|
||||
if (opponentHand->CheckUserInput(key)) return true;
|
||||
if (selfLibrary->CheckUserInput(key)) return true;
|
||||
if (opponentLibrary->CheckUserInput(key)) return true;
|
||||
bool GuiAvatars::CheckUserInput(JButton key)
|
||||
{
|
||||
if (self->CheckUserInput(key))
|
||||
return true;
|
||||
if (opponent->CheckUserInput(key))
|
||||
return true;
|
||||
if (selfGraveyard->CheckUserInput(key))
|
||||
return true;
|
||||
if (opponentGraveyard->CheckUserInput(key))
|
||||
return true;
|
||||
if (opponentHand->CheckUserInput(key))
|
||||
return true;
|
||||
if (selfLibrary->CheckUserInput(key))
|
||||
return true;
|
||||
if (opponentLibrary->CheckUserInput(key))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiAvatars::CheckUserInput(int x, int y){
|
||||
// if (self->CheckUserInput(key)) return true;
|
||||
// if (opponent->CheckUserInput(key)) return true;
|
||||
if (selfGraveyard->CheckUserInput(x, y)) return true;
|
||||
if (opponentGraveyard->CheckUserInput(x, y)) return true;
|
||||
if (opponentHand->CheckUserInput(x, y)) return true;
|
||||
if (selfLibrary->CheckUserInput(x, y)) return true;
|
||||
if (opponentLibrary->CheckUserInput(x, y)) return true;
|
||||
bool GuiAvatars::CheckUserInput(int x, int y)
|
||||
{
|
||||
// if (self->CheckUserInput(key)) return true;
|
||||
// if (opponent->CheckUserInput(key)) return true;
|
||||
if (selfGraveyard->CheckUserInput(x, y))
|
||||
return true;
|
||||
if (opponentGraveyard->CheckUserInput(x, y))
|
||||
return true;
|
||||
if (opponentHand->CheckUserInput(x, y))
|
||||
return true;
|
||||
if (selfLibrary->CheckUserInput(x, y))
|
||||
return true;
|
||||
if (opponentLibrary->CheckUserInput(x, y))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -128,10 +147,13 @@ void GuiAvatars::Render()
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
float w = 54;
|
||||
float h = 54;
|
||||
if (opponent == active){
|
||||
r->FillRect(opponent->actX, opponent->actY, w * opponent->actZ , h * opponent->actZ, ARGB(200,0,0,0));
|
||||
}else if (self == active){
|
||||
r->FillRect(self->actX - w * self->actZ, self->actY - h * self->actZ, w * self->actZ , h * self->actZ, ARGB(200,0,0,0));
|
||||
if (opponent == active)
|
||||
{
|
||||
r->FillRect(opponent->actX, opponent->actY, w * opponent->actZ, h * opponent->actZ, ARGB(200,0,0,0));
|
||||
}
|
||||
else if (self == active)
|
||||
{
|
||||
r->FillRect(self->actX - w * self->actZ, self->actY - h * self->actZ, w * self->actZ, h * self->actZ, ARGB(200,0,0,0));
|
||||
}
|
||||
GuiLayer::Render();
|
||||
|
||||
|
||||
@@ -18,12 +18,15 @@ void GuiBackground::Render()
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
JQuad * quad = NULL;
|
||||
GameObserver * go = GameObserver::GetInstance();
|
||||
if (go && go->mRules && go->mRules->bg.size()) {
|
||||
if (go && go->mRules && go->mRules->bg.size())
|
||||
{
|
||||
quad = resources.RetrieveTempQuad(go->mRules->bg);
|
||||
}
|
||||
if (!quad) {
|
||||
if (!quad)
|
||||
{
|
||||
quad = resources.RetrieveTempQuad("backdrop.jpg");
|
||||
}
|
||||
if (!quad) return;
|
||||
if (!quad)
|
||||
return;
|
||||
renderer->RenderQuad(quad, 0, 18);
|
||||
}
|
||||
|
||||
+238
-114
@@ -16,27 +16,37 @@ const float kZoom_level1 = 1.4f;
|
||||
const float kZoom_level2 = 2.2f;
|
||||
const float kZoom_level3 = 2.7f;
|
||||
|
||||
struct Left : public Exp { static inline bool test(DamagerDamaged* ref, DamagerDamaged* test)
|
||||
{ return ref->y == test->y && ref->x > test->x && test->show; } };
|
||||
struct Right : public Exp { static inline bool test(DamagerDamaged* ref, DamagerDamaged* test)
|
||||
{ return ref->y == test->y && ref->x < test->x && test->show; } };
|
||||
struct Left: public Exp
|
||||
{
|
||||
static inline bool test(DamagerDamaged* ref, DamagerDamaged* test)
|
||||
{
|
||||
return ref->y == test->y && ref->x > test->x && test->show;
|
||||
}
|
||||
};
|
||||
struct Right: public Exp
|
||||
{
|
||||
static inline bool test(DamagerDamaged* ref, DamagerDamaged* test)
|
||||
{
|
||||
return ref->y == test->y && ref->x < test->x && test->show;
|
||||
}
|
||||
};
|
||||
|
||||
JTexture* GuiCombat::ok_tex = NULL;
|
||||
|
||||
GuiCombat::GuiCombat(GameObserver* go) : GuiLayer(), go(go), active(false), activeAtk(NULL),
|
||||
ok(SCREEN_WIDTH - MARGIN, 210, 1, 0, 255),
|
||||
enemy_avatar(SCREEN_WIDTH - MARGIN, TOP_LINE, 2, 0, 255),
|
||||
cursor_pos(NONE), step(DAMAGE)
|
||||
GuiCombat::GuiCombat(GameObserver* go) :
|
||||
GuiLayer(), go(go), active(false), activeAtk(NULL), ok(SCREEN_WIDTH - MARGIN, 210, 1, 0, 255), enemy_avatar(SCREEN_WIDTH
|
||||
- MARGIN, TOP_LINE, 2, 0, 255), cursor_pos(NONE), step(DAMAGE)
|
||||
{
|
||||
if(NULL == ok_tex)
|
||||
if (NULL == ok_tex)
|
||||
{
|
||||
ok_tex = resources.RetrieveTexture("Ok.png",RETRIEVE_LOCK);
|
||||
ok_tex = resources.RetrieveTexture("Ok.png", RETRIEVE_LOCK);
|
||||
}
|
||||
}
|
||||
|
||||
GuiCombat::~GuiCombat()
|
||||
{
|
||||
if(ok_tex){
|
||||
if (ok_tex)
|
||||
{
|
||||
resources.Release(ok_tex);
|
||||
ok_tex = NULL;
|
||||
}
|
||||
@@ -45,12 +55,13 @@ GuiCombat::~GuiCombat()
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
static inline void repos(typename vector<T*>::iterator begin, typename vector<T*>::iterator end, signed size = -1)
|
||||
{
|
||||
for (typename vector<T*>::iterator it = begin; it != end; ++it)
|
||||
if ((*it)->show) ++size;
|
||||
float space = (SCREEN_WIDTH - 2*MARGIN) / size;
|
||||
if ((*it)->show)
|
||||
++size;
|
||||
float space = (SCREEN_WIDTH - 2 * MARGIN) / size;
|
||||
float pos = MARGIN;
|
||||
for (typename vector<T*>::iterator it = begin; it != end; ++it)
|
||||
if ((*it)->show)
|
||||
@@ -77,11 +88,14 @@ void GuiCombat::remaskBlkViews(AttackerDamaged* before, AttackerDamaged* after)
|
||||
{
|
||||
for (vector<DefenserDamaged*>::iterator q = after->blockers.begin(); q != after->blockers.end(); ++q)
|
||||
{
|
||||
(*q)->actX = MARGIN; (*q)->y = TOP_LINE;
|
||||
(*q)->zoom = kZoom_level2; (*q)->t = 0;
|
||||
(*q)->actX = MARGIN;
|
||||
(*q)->y = TOP_LINE;
|
||||
(*q)->zoom = kZoom_level2;
|
||||
(*q)->t = 0;
|
||||
}
|
||||
repos<DefenserDamaged>(after->blockers.begin(), after->blockers.end(), after->card->has(Constants::TRAMPLE) ? 0 : -1);
|
||||
enemy_avatar.actX = MARGIN; enemy_avatar.x = SCREEN_WIDTH - MARGIN;
|
||||
repos<DefenserDamaged> (after->blockers.begin(), after->blockers.end(), after->card->has(Constants::TRAMPLE) ? 0 : -1);
|
||||
enemy_avatar.actX = MARGIN;
|
||||
enemy_avatar.x = SCREEN_WIDTH - MARGIN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,9 +103,15 @@ void GuiCombat::validateDamage()
|
||||
{
|
||||
switch (step)
|
||||
{
|
||||
case FIRST_STRIKE : go->nextCombatStep(); break;
|
||||
case DAMAGE : go->nextGamePhase(); break;
|
||||
default: cout << "COMBAT : Cannot validate damage in this phase" << endl; break;
|
||||
case FIRST_STRIKE:
|
||||
go->nextCombatStep();
|
||||
break;
|
||||
case DAMAGE:
|
||||
go->nextGamePhase();
|
||||
break;
|
||||
default:
|
||||
cout << "COMBAT : Cannot validate damage in this phase" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,12 +123,14 @@ void GuiCombat::autoaffectDamage(AttackerDamaged* attacker, CombatStep step)
|
||||
{
|
||||
(*it)->clearDamage();
|
||||
unsigned actual_damage = MIN(damage, (unsigned)MAX((*it)->card->toughness, 0));
|
||||
if (attacker->card->has(Constants::DEATHTOUCH) && actual_damage > 1) actual_damage = 1;
|
||||
if (attacker->card->has(Constants::DEATHTOUCH) && actual_damage > 1)
|
||||
actual_damage = 1;
|
||||
(*it)->addDamage(actual_damage, attacker);
|
||||
attacker->addDamage((*it)->card->stepPower(step), *it);
|
||||
damage -= actual_damage;
|
||||
}
|
||||
if (damage > 0 && attacker->blockers.size() > 0 && !attacker->card->has(Constants::TRAMPLE)) attacker->blockers[0]->addDamage(damage, attacker);
|
||||
if (damage > 0 && attacker->blockers.size() > 0 && !attacker->card->has(Constants::TRAMPLE))
|
||||
attacker->blockers[0]->addDamage(damage, attacker);
|
||||
}
|
||||
|
||||
void GuiCombat::addOne(DefenserDamaged* blocker, CombatStep step)
|
||||
@@ -118,45 +140,65 @@ void GuiCombat::addOne(DefenserDamaged* blocker, CombatStep step)
|
||||
for (vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it)
|
||||
{
|
||||
damage -= (*it)->sumDamages();
|
||||
if (0 > damage) { (*it)->addDamage(-1, activeAtk); break; }
|
||||
if (0 > damage)
|
||||
{
|
||||
(*it)->addDamage(-1, activeAtk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void GuiCombat::removeOne(DefenserDamaged* blocker, CombatStep step)
|
||||
{
|
||||
blocker->addDamage(-1, activeAtk);
|
||||
for (vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it)
|
||||
if (activeAtk->card->has(Constants::DEATHTOUCH) ? ((*it)->sumDamages() < 1) : (!(*it)->hasLethalDamage())) { (*it)->addDamage(1, activeAtk); return; }
|
||||
if (!activeAtk->card->has(Constants::TRAMPLE) && activeAtk->blockers.size() > 0) activeAtk->blockers.back()->addDamage(1, activeAtk);
|
||||
if (activeAtk->card->has(Constants::DEATHTOUCH) ? ((*it)->sumDamages() < 1) : (!(*it)->hasLethalDamage()))
|
||||
{
|
||||
(*it)->addDamage(1, activeAtk);
|
||||
return;
|
||||
}
|
||||
if (!activeAtk->card->has(Constants::TRAMPLE) && activeAtk->blockers.size() > 0)
|
||||
activeAtk->blockers.back()->addDamage(1, activeAtk);
|
||||
}
|
||||
|
||||
bool GuiCombat::clickOK(){
|
||||
bool GuiCombat::clickOK()
|
||||
{
|
||||
active = activeAtk = NULL;
|
||||
cursor_pos = NONE;
|
||||
switch (step)
|
||||
{
|
||||
case BLOCKERS :
|
||||
case TRIGGERS :
|
||||
assert(false); return false; // that should not happen
|
||||
case BLOCKERS:
|
||||
case TRIGGERS:
|
||||
assert(false);
|
||||
return false; // that should not happen
|
||||
|
||||
case ORDER : go->nextGamePhase(); return true;
|
||||
case FIRST_STRIKE : return false;
|
||||
case DAMAGE : validateDamage(); return true;
|
||||
case END_FIRST_STRIKE : return false;
|
||||
case END_DAMAGE : return false; // nothing;
|
||||
case ORDER:
|
||||
go->nextGamePhase();
|
||||
return true;
|
||||
case FIRST_STRIKE:
|
||||
return false;
|
||||
case DAMAGE:
|
||||
validateDamage();
|
||||
return true;
|
||||
case END_FIRST_STRIKE:
|
||||
return false;
|
||||
case END_DAMAGE:
|
||||
return false; // nothing;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiCombat::CheckUserInput(JButton key)
|
||||
{
|
||||
if (NONE == cursor_pos) return false;
|
||||
if (NONE == cursor_pos)
|
||||
return false;
|
||||
DamagerDamaged* oldActive = active;
|
||||
switch (key)
|
||||
{
|
||||
case JGE_BTN_OK:
|
||||
if (BLK == cursor_pos)
|
||||
{
|
||||
if (ORDER == step) go->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); }
|
||||
if (ORDER == step)
|
||||
go->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); }
|
||||
else
|
||||
{
|
||||
signed damage = activeAtk->card->stepPower(step);
|
||||
@@ -164,12 +206,14 @@ bool GuiCombat::CheckUserInput(JButton key)
|
||||
damage -= (*it)->sumDamages();
|
||||
signed now = active->sumDamages();
|
||||
damage -= now;
|
||||
if (damage > 0) addOne(active, step);
|
||||
if (damage > 0)
|
||||
addOne(active, step);
|
||||
else if (activeAtk->card->has(Constants::DEATHTOUCH))
|
||||
for (; now >= 1; --now)
|
||||
removeOne(active, step);
|
||||
else
|
||||
if (activeAtk->card->has(Constants::DEATHTOUCH))
|
||||
for (; now >= 1; --now) removeOne(active, step);
|
||||
else
|
||||
for (now -= active->card->toughness; now >= 0; --now) removeOne(active, step);
|
||||
for (now -= active->card->toughness; now >= 0; --now)
|
||||
removeOne(active, step);
|
||||
}
|
||||
}
|
||||
else if (ATK == cursor_pos)
|
||||
@@ -194,25 +238,43 @@ bool GuiCombat::CheckUserInput(JButton key)
|
||||
case JGE_BTN_LEFT:
|
||||
switch (cursor_pos)
|
||||
{
|
||||
case NONE : break;
|
||||
case OK :
|
||||
for (vector<AttackerDamaged*>::reverse_iterator it = attackers.rbegin(); it != attackers.rend(); ++it) if ((*it)->show) { active = *it; break; }
|
||||
activeAtk = static_cast<AttackerDamaged*>(active);
|
||||
case NONE:
|
||||
break;
|
||||
case OK:
|
||||
for (vector<AttackerDamaged*>::reverse_iterator it = attackers.rbegin(); it != attackers.rend(); ++it)
|
||||
if ((*it)->show)
|
||||
{
|
||||
active = *it;
|
||||
break;
|
||||
}
|
||||
activeAtk = static_cast<AttackerDamaged*> (active);
|
||||
cursor_pos = ATK;
|
||||
break;
|
||||
case ATK :
|
||||
case ATK:
|
||||
{
|
||||
DamagerDamaged* old = active;
|
||||
active = closest<Left>(attackers, NULL, static_cast<AttackerDamaged*>(active));
|
||||
activeAtk = static_cast<AttackerDamaged*>(active);
|
||||
if (old != active) { if (old) old->zoom = kZoom_none; if (active) active->zoom = kZoom_level1; }
|
||||
active = closest<Left> (attackers, NULL, static_cast<AttackerDamaged*> (active));
|
||||
activeAtk = static_cast<AttackerDamaged*> (active);
|
||||
if (old != active)
|
||||
{
|
||||
if (old)
|
||||
old->zoom = kZoom_none;
|
||||
if (active)
|
||||
active->zoom = kZoom_level1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BLK :
|
||||
case BLK:
|
||||
{
|
||||
DamagerDamaged* old = active;
|
||||
active = closest<Left>(activeAtk->blockers, NULL, static_cast<DefenserDamaged*>(active));
|
||||
if (old != active) { if (old) old->zoom = kZoom_none; if (active) active->zoom = kZoom_level1; }
|
||||
active = closest<Left> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active));
|
||||
if (old != active)
|
||||
{
|
||||
if (old)
|
||||
old->zoom = kZoom_none;
|
||||
if (active)
|
||||
active->zoom = kZoom_level1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -220,72 +282,101 @@ bool GuiCombat::CheckUserInput(JButton key)
|
||||
case JGE_BTN_RIGHT:
|
||||
switch (cursor_pos)
|
||||
{
|
||||
case NONE :
|
||||
case OK : break;
|
||||
case BLK :
|
||||
case NONE:
|
||||
case OK:
|
||||
break;
|
||||
case BLK:
|
||||
{
|
||||
DamagerDamaged* old = active;
|
||||
active = closest<Right>(activeAtk->blockers, NULL, static_cast<DefenserDamaged*>(active));
|
||||
if (old != active) { if (old) old->zoom = kZoom_none; if (active) active->zoom = kZoom_level1; }
|
||||
active = closest<Right> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active));
|
||||
if (old != active)
|
||||
{
|
||||
if (old)
|
||||
old->zoom = kZoom_none;
|
||||
if (active)
|
||||
active->zoom = kZoom_level1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATK :
|
||||
case ATK:
|
||||
{
|
||||
DamagerDamaged* old = active;
|
||||
active = closest<Right>(attackers, NULL, static_cast<AttackerDamaged*>(active));
|
||||
if (active == oldActive) { active = activeAtk = NULL; cursor_pos = OK; }
|
||||
active = closest<Right> (attackers, NULL, static_cast<AttackerDamaged*> (active));
|
||||
if (active == oldActive)
|
||||
{
|
||||
active = activeAtk = NULL;
|
||||
cursor_pos = OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (old != active) {
|
||||
if (old) old->zoom = kZoom_none;
|
||||
if (active) active->zoom = kZoom_level1;
|
||||
if (old != active)
|
||||
{
|
||||
if (old)
|
||||
old->zoom = kZoom_none;
|
||||
if (active)
|
||||
active->zoom = kZoom_level1;
|
||||
}
|
||||
activeAtk = static_cast<AttackerDamaged*>(active);
|
||||
activeAtk = static_cast<AttackerDamaged*> (active);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case JGE_BTN_DOWN:
|
||||
if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) break;
|
||||
if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0)
|
||||
break;
|
||||
removeOne(active, step);
|
||||
break;
|
||||
case JGE_BTN_UP:
|
||||
if (ORDER == step || BLK != cursor_pos) break;
|
||||
if (ORDER == step || BLK != cursor_pos)
|
||||
break;
|
||||
addOne(active, step);
|
||||
break;
|
||||
case JGE_BTN_PRI:
|
||||
active = activeAtk = NULL; cursor_pos = OK;
|
||||
active = activeAtk = NULL;
|
||||
cursor_pos = OK;
|
||||
break;
|
||||
case JGE_BTN_NEXT:
|
||||
if (!options[Options::REVERSETRIGGERS].number) return false;
|
||||
active = activeAtk = NULL; cursor_pos = OK;
|
||||
if (!options[Options::REVERSETRIGGERS].number)
|
||||
return false;
|
||||
active = activeAtk = NULL;
|
||||
cursor_pos = OK;
|
||||
break;
|
||||
case JGE_BTN_PREV:
|
||||
if (options[Options::REVERSETRIGGERS].number) return false;
|
||||
active = activeAtk = NULL; cursor_pos = OK;
|
||||
if (options[Options::REVERSETRIGGERS].number)
|
||||
return false;
|
||||
active = activeAtk = NULL;
|
||||
cursor_pos = OK;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
if (oldActive != active)
|
||||
{
|
||||
if (oldActive && oldActive != activeAtk) oldActive->zoom = kZoom_level2;
|
||||
if (active) active->zoom = kZoom_level3;
|
||||
if (ATK == cursor_pos) remaskBlkViews(dynamic_cast<AttackerDamaged*>(oldActive), static_cast<AttackerDamaged*>(active));
|
||||
if (oldActive && oldActive != activeAtk)
|
||||
oldActive->zoom = kZoom_level2;
|
||||
if (active)
|
||||
active->zoom = kZoom_level3;
|
||||
if (ATK == cursor_pos)
|
||||
remaskBlkViews(dynamic_cast<AttackerDamaged*> (oldActive), static_cast<AttackerDamaged*> (active));
|
||||
}
|
||||
if (OK == cursor_pos) ok.zoom = 1.5; else ok.zoom = kZoom_none;
|
||||
if (OK == cursor_pos)
|
||||
ok.zoom = 1.5;
|
||||
else
|
||||
ok.zoom = kZoom_none;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiCombat::Render()
|
||||
{
|
||||
if (NONE == cursor_pos) return;
|
||||
if (NONE == cursor_pos)
|
||||
return;
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
renderer->FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(200,0,0,0));
|
||||
|
||||
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
|
||||
if ((*it)->show) (*it)->Render(step);
|
||||
if ((*it)->show)
|
||||
(*it)->Render(step);
|
||||
if (activeAtk)
|
||||
{
|
||||
signed damage = activeAtk->card->stepPower(step);
|
||||
@@ -294,7 +385,8 @@ void GuiCombat::Render()
|
||||
(*q)->Render(step);
|
||||
damage -= (*q)->sumDamages();
|
||||
}
|
||||
if (damage < 0) damage = 0;
|
||||
if (damage < 0)
|
||||
damage = 0;
|
||||
if (activeAtk->card->has(Constants::TRAMPLE))
|
||||
{
|
||||
go->opponent()->mAvatar->SetHotSpot(18, 25);
|
||||
@@ -302,12 +394,14 @@ void GuiCombat::Render()
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mFont->SetColor(ARGB(255, 255, 64, 0));
|
||||
{
|
||||
char buf[10]; sprintf(buf, "%i", damage);
|
||||
char buf[10];
|
||||
sprintf(buf, "%i", damage);
|
||||
mFont->DrawString(buf, enemy_avatar.actX - 25, enemy_avatar.actY - 40);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ok_tex) {
|
||||
if (ok_tex)
|
||||
{
|
||||
JQuad *ok_quad = resources.RetrieveTempQuad("Ok.png");
|
||||
ok_quad->SetHotSpot(28, 22);
|
||||
ok.Render(ok_quad);
|
||||
@@ -335,15 +429,18 @@ int GuiCombat::resolve() // Returns the number of damage objects dealt this turn
|
||||
dmg -= (*q)->sumDamages();
|
||||
}
|
||||
|
||||
if (dmg > 0 && ( (!attacker->blocked) || attacker->has(Constants::TRAMPLE)) ) stack->Add(NEW Damage((*it)->card, go->opponent(), dmg, DAMAGE_COMBAT));
|
||||
if (dmg > 0 && ((!attacker->blocked) || attacker->has(Constants::TRAMPLE)))
|
||||
stack->Add(NEW Damage((*it)->card, go->opponent(), dmg, DAMAGE_COMBAT));
|
||||
for (vector<Damage>::iterator d = (*it)->damages.begin(); d != (*it)->damages.end(); ++d)
|
||||
stack->Add(NEW Damage(*d));
|
||||
}
|
||||
int v = stack->mCount;
|
||||
if (v > 0){
|
||||
if (v > 0)
|
||||
{
|
||||
go->mLayers->stackLayer()->Add(stack);
|
||||
go->mLayers->stackLayer()->resolve(); // This will delete the damage stack which will in turn delete the Damage it contains
|
||||
}else
|
||||
}
|
||||
else
|
||||
SAFE_DELETE(stack);
|
||||
return v;
|
||||
}
|
||||
@@ -352,7 +449,8 @@ int GuiCombat::receiveEventPlus(WEvent* e)
|
||||
{
|
||||
if (WEventCreatureAttacker* event = dynamic_cast<WEventCreatureAttacker*>(e))
|
||||
{
|
||||
if (NULL == event->after) return 0;
|
||||
if (NULL == event->after)
|
||||
return 0;
|
||||
AttackerDamaged* t = NEW AttackerDamaged(event->card, *(event->card->view), true, NULL);
|
||||
attackers.push_back(t);
|
||||
return 1;
|
||||
@@ -363,7 +461,9 @@ int GuiCombat::receiveEventPlus(WEvent* e)
|
||||
if ((*it)->card == event->after)
|
||||
{
|
||||
DefenserDamaged* t = NEW DefenserDamaged(event->card, *(event->card->view), true, NULL);
|
||||
t->y = t->actY = TOP_LINE; t->actT = t->t = 0; t->actZ = t->zoom = kZoom_level2;
|
||||
t->y = t->actY = TOP_LINE;
|
||||
t->actT = t->t = 0;
|
||||
t->actZ = t->zoom = kZoom_level2;
|
||||
(*it)->blockers.push_back(t);
|
||||
return 1;
|
||||
}
|
||||
@@ -375,10 +475,16 @@ int GuiCombat::receiveEventPlus(WEvent* e)
|
||||
if ((*it)->card == event->attacker)
|
||||
{
|
||||
vector<DefenserDamaged*>::iterator it1, it2;
|
||||
for (it1 = (*it)->blockers.begin(); it1 != (*it)->blockers.end(); ++it1) if ((*it1)->card == event->card) break;
|
||||
if ((*it)->blockers.end() == it1) return 1;
|
||||
for (it2 = (*it)->blockers.begin(); it2 != (*it)->blockers.end(); ++it2) if ((*it2)->card == event->exchangeWith) break;
|
||||
if ((*it)->blockers.end() == it2) return 1;
|
||||
for (it1 = (*it)->blockers.begin(); it1 != (*it)->blockers.end(); ++it1)
|
||||
if ((*it1)->card == event->card)
|
||||
break;
|
||||
if ((*it)->blockers.end() == it1)
|
||||
return 1;
|
||||
for (it2 = (*it)->blockers.begin(); it2 != (*it)->blockers.end(); ++it2)
|
||||
if ((*it2)->card == event->exchangeWith)
|
||||
break;
|
||||
if ((*it)->blockers.end() == it2)
|
||||
return 1;
|
||||
float x = (*it1)->x;
|
||||
(*it1)->x = (*it2)->x;
|
||||
(*it2)->x = x;
|
||||
@@ -395,10 +501,11 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
||||
if (go->players[0]->game->inPlay == event->from || go->players[1]->game->inPlay == event->from)
|
||||
{
|
||||
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
|
||||
if ((*it)->card == event->card->previous || (*it)->card == event->card )
|
||||
if ((*it)->card == event->card->previous || (*it)->card == event->card)
|
||||
{
|
||||
AttackerDamaged* d = *it;
|
||||
if (activeAtk == *it) activeAtk = NULL;
|
||||
if (activeAtk == *it)
|
||||
activeAtk = NULL;
|
||||
attackers.erase(it);
|
||||
trash(d);
|
||||
return 1;
|
||||
@@ -416,7 +523,8 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
||||
}
|
||||
if (WEventCreatureAttacker* event = dynamic_cast<WEventCreatureAttacker*>(e))
|
||||
{
|
||||
if (NULL == event->before) return 0;
|
||||
if (NULL == event->before)
|
||||
return 0;
|
||||
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
|
||||
if ((*it)->card == event->card)
|
||||
{
|
||||
@@ -443,8 +551,10 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
||||
}
|
||||
else if (WEventPhaseChange* event = dynamic_cast<WEventPhaseChange*>(e))
|
||||
{
|
||||
if (Constants::MTG_PHASE_COMBATDAMAGE == event->to->id) step = BLOCKERS;
|
||||
else cursor_pos = NONE;
|
||||
if (Constants::MTG_PHASE_COMBATDAMAGE == event->to->id)
|
||||
step = BLOCKERS;
|
||||
else
|
||||
cursor_pos = NONE;
|
||||
}
|
||||
else if (WEventCombatStepChange* event = dynamic_cast<WEventCombatStepChange*>(e))
|
||||
switch (event->step)
|
||||
@@ -458,8 +568,13 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
||||
|
||||
case ORDER:
|
||||
{
|
||||
if (ORDER == step) return 0; // Why do I take this twice ? >.>
|
||||
if (!go->currentPlayer->displayStack()) { go->nextCombatStep(); return 1; }
|
||||
if (ORDER == step)
|
||||
return 0; // Why do I take this twice ? >.>
|
||||
if (!go->currentPlayer->displayStack())
|
||||
{
|
||||
go->nextCombatStep();
|
||||
return 1;
|
||||
}
|
||||
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
|
||||
{
|
||||
(*it)->show = (1 < (*it)->blockers.size());
|
||||
@@ -470,15 +585,17 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
||||
if ((*it)->show)
|
||||
{
|
||||
(*it)->y = 210;
|
||||
(*it)->zoom = kZoom_level2; (*it)->t = 0;
|
||||
if (!active) active = *it;
|
||||
(*it)->zoom = kZoom_level2;
|
||||
(*it)->t = 0;
|
||||
if (!active)
|
||||
active = *it;
|
||||
}
|
||||
repos<AttackerDamaged>(attackers.begin(), attackers.end(), 0);
|
||||
repos<AttackerDamaged> (attackers.begin(), attackers.end(), 0);
|
||||
if (active)
|
||||
{
|
||||
active->zoom = kZoom_level3;
|
||||
activeAtk = static_cast<AttackerDamaged*>(active);
|
||||
remaskBlkViews(NULL, static_cast<AttackerDamaged*>(active));
|
||||
activeAtk = static_cast<AttackerDamaged*> (active);
|
||||
remaskBlkViews(NULL, static_cast<AttackerDamaged*> (active));
|
||||
cursor_pos = ATK;
|
||||
step = ORDER;
|
||||
}
|
||||
@@ -489,7 +606,8 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
||||
case FIRST_STRIKE:
|
||||
step = FIRST_STRIKE;
|
||||
for (inner_iterator attacker = attackers.begin(); attacker != attackers.end(); ++attacker)
|
||||
if ((*attacker)->card->has(Constants::FIRSTSTRIKE) || (*attacker)->card->has(Constants::DOUBLESTRIKE)) goto DAMAGE;
|
||||
if ((*attacker)->card->has(Constants::FIRSTSTRIKE) || (*attacker)->card->has(Constants::DOUBLESTRIKE))
|
||||
goto DAMAGE;
|
||||
go->nextCombatStep();
|
||||
break;
|
||||
case END_FIRST_STRIKE:
|
||||
@@ -500,27 +618,33 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
||||
go->nextCombatStep();
|
||||
//else go->mLayers->stackLayer()->AddNextGamePhase(); //uncomment to add "interrupt" offer after first strike, rather than giving priority to current player
|
||||
return 1;
|
||||
case DAMAGE: DAMAGE:
|
||||
step = event->step;
|
||||
if (!go->currentPlayer->displayStack()) {
|
||||
((AIPlayer *)go->currentPlayer)->affectCombatDamages(step);
|
||||
case DAMAGE:
|
||||
DAMAGE: step = event->step;
|
||||
if (!go->currentPlayer->displayStack())
|
||||
{
|
||||
((AIPlayer *) go->currentPlayer)->affectCombatDamages(step);
|
||||
go->nextGamePhase();
|
||||
return 1;
|
||||
}
|
||||
for (inner_iterator attacker = attackers.begin(); attacker != attackers.end(); ++attacker)
|
||||
autoaffectDamage(*attacker, step);
|
||||
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
|
||||
(*it)->show = ((*it)->card->has(Constants::DOUBLESTRIKE) || ((*it)->card->has(Constants::FIRSTSTRIKE) ^ (DAMAGE == step))) &&
|
||||
(((*it)->card->has(Constants::TRAMPLE) ? (size_t) 0 : (size_t) 1) < (*it)->blockers.size()
|
||||
);
|
||||
repos<AttackerDamaged>(attackers.begin(), attackers.end(), 0);
|
||||
(*it)->show = ((*it)->card->has(Constants::DOUBLESTRIKE) || ((*it)->card->has(Constants::FIRSTSTRIKE) ^ (DAMAGE
|
||||
== step))) && (((*it)->card->has(Constants::TRAMPLE) ? (size_t) 0 : (size_t) 1)
|
||||
< (*it)->blockers.size());
|
||||
repos<AttackerDamaged> (attackers.begin(), attackers.end(), 0);
|
||||
active = NULL;
|
||||
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it) if ((*it)->show) { active = *it; break; }
|
||||
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
|
||||
if ((*it)->show)
|
||||
{
|
||||
active = *it;
|
||||
break;
|
||||
}
|
||||
if (active)
|
||||
{
|
||||
active->zoom = kZoom_level3;
|
||||
activeAtk = static_cast<AttackerDamaged*>(active);
|
||||
remaskBlkViews(NULL, static_cast<AttackerDamaged*>(active));
|
||||
activeAtk = static_cast<AttackerDamaged*> (active);
|
||||
remaskBlkViews(NULL, static_cast<AttackerDamaged*> (active));
|
||||
cursor_pos = ATK;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -7,19 +7,21 @@ GuiFrame::GuiFrame()
|
||||
{
|
||||
if (resources.GetTexture("wood.png"))
|
||||
wood = resources.RetrieveQuad("wood.png", 0, 0, SCREEN_WIDTH, 28);
|
||||
else{
|
||||
else
|
||||
{
|
||||
wood = NULL;
|
||||
GameApp::systemError += "Can't load wood texture : " __FILE__ "\n";
|
||||
}
|
||||
|
||||
|
||||
goldGlow = gold1 = gold2 = NULL;
|
||||
if (resources.GetTexture("gold.png")){
|
||||
if (resources.GetTexture("gold.png"))
|
||||
{
|
||||
gold1 = resources.RetrieveQuad("gold.png", 0, 0, SCREEN_WIDTH, 6, "gold1");
|
||||
gold2 = resources.RetrieveQuad("gold.png", 0, 6, SCREEN_WIDTH, 6, "gold2");
|
||||
if (resources.GetTexture("goldglow.png"))
|
||||
goldGlow = resources.RetrieveQuad("goldglow.png", 1, 1, SCREEN_WIDTH - 2, 18);
|
||||
if (gold2){
|
||||
if (gold2)
|
||||
{
|
||||
gold2->SetColor(ARGB(127, 255, 255, 255));
|
||||
gold2->SetHFlip(true);
|
||||
}
|
||||
@@ -27,7 +29,6 @@ GuiFrame::GuiFrame()
|
||||
|
||||
step = 0.0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
GuiFrame::~GuiFrame()
|
||||
@@ -37,19 +38,24 @@ GuiFrame::~GuiFrame()
|
||||
void GuiFrame::Render()
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
float sized = step / 4; if (sized > SCREEN_WIDTH) sized -= SCREEN_WIDTH;
|
||||
float sized = step / 4;
|
||||
if (sized > SCREEN_WIDTH)
|
||||
sized -= SCREEN_WIDTH;
|
||||
renderer->RenderQuad(wood, 0, 0);
|
||||
if(gold1){
|
||||
if (gold1)
|
||||
{
|
||||
renderer->RenderQuad(gold1, -sized, 16);
|
||||
renderer->RenderQuad(gold1, -sized + 479, 16);
|
||||
|
||||
if(goldGlow){
|
||||
if (goldGlow)
|
||||
{
|
||||
goldGlow->SetColor(ARGB((100+(rand()%50)), 255, 255, 255));
|
||||
renderer->RenderQuad(goldGlow, -sized, 9);
|
||||
renderer->RenderQuad(goldGlow, -sized + 480, 9);
|
||||
}
|
||||
|
||||
if(gold2){
|
||||
if (gold2)
|
||||
{
|
||||
renderer->RenderQuad(gold2, step / 2, 16);
|
||||
renderer->RenderQuad(gold2, step / 2 - 479, 16);
|
||||
}
|
||||
@@ -59,5 +65,6 @@ void GuiFrame::Render()
|
||||
void GuiFrame::Update(float dt)
|
||||
{
|
||||
step += dt * 5;
|
||||
if (step > 2*SCREEN_WIDTH) step -= 2*SCREEN_WIDTH;
|
||||
if (step > 2 * SCREEN_WIDTH)
|
||||
step -= 2 * SCREEN_WIDTH;
|
||||
}
|
||||
|
||||
@@ -20,25 +20,32 @@ bool HandLimitor::select(Target* t)
|
||||
{
|
||||
if (CardView* c = dynamic_cast<CardView*>(t))
|
||||
return hand->isInHand(c);
|
||||
else return false;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
bool HandLimitor::greyout(Target* t)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
HandLimitor::HandLimitor(GuiHand* hand) : hand(hand) {}
|
||||
HandLimitor::HandLimitor(GuiHand* hand) :
|
||||
hand(hand)
|
||||
{
|
||||
}
|
||||
|
||||
GuiHand::GuiHand(MTGHand* hand) : GuiLayer(), hand(hand)
|
||||
GuiHand::GuiHand(MTGHand* hand) :
|
||||
GuiLayer(), hand(hand)
|
||||
{
|
||||
back = resources.RetrieveTempQuad("handback.png");
|
||||
if(back) back->SetTextureRect(1, 0, 100, 250);
|
||||
else GameApp::systemError = "Error loading hand texture : " __FILE__;
|
||||
if (back)
|
||||
back->SetTextureRect(1, 0, 100, 250);
|
||||
else
|
||||
GameApp::systemError = "Error loading hand texture : " __FILE__;
|
||||
}
|
||||
|
||||
GuiHand::~GuiHand()
|
||||
{
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
delete(*it);
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
void GuiHand::Update(float dt)
|
||||
@@ -54,7 +61,10 @@ bool GuiHand::isInHand(CardView* card)
|
||||
return (it != cards.end());
|
||||
}
|
||||
|
||||
GuiHandOpponent::GuiHandOpponent(MTGHand* hand) : GuiHand(hand) {}
|
||||
GuiHandOpponent::GuiHandOpponent(MTGHand* hand) :
|
||||
GuiHand(hand)
|
||||
{
|
||||
}
|
||||
|
||||
void GuiHandOpponent::Render()
|
||||
{
|
||||
@@ -71,19 +81,21 @@ void GuiHandOpponent::Render()
|
||||
}
|
||||
}
|
||||
|
||||
GuiHandSelf::GuiHandSelf(MTGHand* hand) : GuiHand(hand), state(Closed), backpos(ClosedX, SCREEN_HEIGHT - 250, 1.0, 0, 255)
|
||||
GuiHandSelf::GuiHandSelf(MTGHand* hand) :
|
||||
GuiHand(hand), state(Closed), backpos(ClosedX, SCREEN_HEIGHT - 250, 1.0, 0, 255)
|
||||
{
|
||||
limitor = NEW HandLimitor(this);
|
||||
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
|
||||
{
|
||||
backpos.t = M_PI/2;
|
||||
backpos.t = M_PI / 2;
|
||||
backpos.y = ClosedY;
|
||||
backpos.x = SCREEN_WIDTH - 30 * 7 - 14;
|
||||
backpos.UpdateNow();
|
||||
}
|
||||
}
|
||||
|
||||
GuiHandSelf::~GuiHandSelf(){
|
||||
GuiHandSelf::~GuiHandSelf()
|
||||
{
|
||||
SAFE_DELETE(limitor);
|
||||
}
|
||||
|
||||
@@ -99,7 +111,8 @@ void GuiHandSelf::Repos()
|
||||
y = 40.0;
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
(*it)->x = ClosedRowX; (*it)->y = y;
|
||||
(*it)->x = ClosedRowX;
|
||||
(*it)->y = y;
|
||||
y += dist;
|
||||
}
|
||||
}
|
||||
@@ -109,27 +122,34 @@ void GuiHandSelf::Repos()
|
||||
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
|
||||
{
|
||||
y = SCREEN_WIDTH - 30;
|
||||
float dist = 240.0f / cards.size(); if (dist > 30) dist = 30; else y = SCREEN_WIDTH - 15;
|
||||
float dist = 240.0f / cards.size();
|
||||
if (dist > 30)
|
||||
dist = 30;
|
||||
else
|
||||
y = SCREEN_WIDTH - 15;
|
||||
for (vector<CardView*>::reverse_iterator it = cards.rbegin(); it != cards.rend(); ++it)
|
||||
{
|
||||
(*it)->x = y;
|
||||
(*it)->y = SCREEN_HEIGHT - 30;
|
||||
y -= dist;
|
||||
(*it)->alpha = static_cast<float>(q ? 0 : 255);
|
||||
(*it)->alpha = static_cast<float> (q ? 0 : 255);
|
||||
}
|
||||
backpos.x = y + SCREEN_HEIGHT - 14;
|
||||
}
|
||||
else
|
||||
{
|
||||
float dist = 224.0f / ((cards.size() + 1) / 2); if (dist > 65) dist = 65;
|
||||
float dist = 224.0f / ((cards.size() + 1) / 2);
|
||||
if (dist > 65)
|
||||
dist = 65;
|
||||
bool flip = false;
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
(*it)->x = flip ? RightRowX : LeftRowX;
|
||||
(*it)->y = y;
|
||||
if (flip) y += dist;
|
||||
if (flip)
|
||||
y += dist;
|
||||
flip = !flip;
|
||||
(*it)->alpha = static_cast<float>(q ? 0 : 255);
|
||||
(*it)->alpha = static_cast<float> (q ? 0 : 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,9 +161,11 @@ bool GuiHandSelf::CheckUserInput(JButton key)
|
||||
if (trigger == key)
|
||||
{
|
||||
state = (Open == state ? Closed : Open);
|
||||
if (Open == state) CardSelectorSingleton::Instance()->Push();
|
||||
if (Open == state)
|
||||
CardSelectorSingleton::Instance()->Push();
|
||||
CardSelectorSingleton::Instance()->Limit(Open == state ? limitor : NULL, CardView::handZone);
|
||||
if (Closed == state) CardSelectorSingleton::Instance()->Pop();
|
||||
if (Closed == state)
|
||||
CardSelectorSingleton::Instance()->Pop();
|
||||
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
|
||||
backpos.y = Open == state ? OpenY : ClosedY;
|
||||
else
|
||||
@@ -153,12 +175,14 @@ bool GuiHandSelf::CheckUserInput(JButton key)
|
||||
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
(*it)->y = SCREEN_HEIGHT + 30; (*it)->UpdateNow();
|
||||
(*it)->y = SCREEN_HEIGHT + 30;
|
||||
(*it)->UpdateNow();
|
||||
}
|
||||
else
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
(*it)->x = SCREEN_WIDTH + 30; (*it)->UpdateNow();
|
||||
(*it)->x = SCREEN_WIDTH + 30;
|
||||
(*it)->UpdateNow();
|
||||
}
|
||||
}
|
||||
Repos();
|
||||
@@ -167,7 +191,6 @@ bool GuiHandSelf::CheckUserInput(JButton key)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void GuiHandSelf::Update(float dt)
|
||||
{
|
||||
backpos.Update(dt);
|
||||
@@ -177,14 +200,16 @@ void GuiHandSelf::Update(float dt)
|
||||
void GuiHandSelf::Render()
|
||||
{
|
||||
//Empty hand
|
||||
if (state == Open && cards.size() == 0){
|
||||
if (state == Open && cards.size() == 0)
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mFont->SetColor(ARGB(255,255,0,0));
|
||||
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number){
|
||||
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
|
||||
{
|
||||
back->SetColor(ARGB(255,255,0,0));
|
||||
JRenderer::GetInstance()->RenderQuad(back,backpos.actX, backpos.actY, backpos.actT, backpos.actZ, backpos.actZ);
|
||||
JRenderer::GetInstance()->RenderQuad(back, backpos.actX, backpos.actY, backpos.actT, backpos.actZ, backpos.actZ);
|
||||
back->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString("0",SCREEN_WIDTH - 10,backpos.actY);
|
||||
mFont->DrawString("0", SCREEN_WIDTH - 10, backpos.actY);
|
||||
}
|
||||
else
|
||||
backpos.Render(back);
|
||||
@@ -202,7 +227,8 @@ float GuiHandSelf::LeftBoundary()
|
||||
float min = SCREEN_WIDTH + 10;
|
||||
if (OptionClosedHand::VISIBLE == options[Options::CLOSEDHAND].number || state == Open)
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
if ((*it)->x - CardGui::Width / 2 < min) min = (*it)->x - CardGui::Width / 2;
|
||||
if ((*it)->x - CardGui::Width / 2 < min)
|
||||
min = (*it)->x - CardGui::Width / 2;
|
||||
return min;
|
||||
}
|
||||
|
||||
@@ -212,7 +238,8 @@ int GuiHandSelf::receiveEventPlus(WEvent* e)
|
||||
if (hand == ev->to)
|
||||
{
|
||||
CardView* card;
|
||||
if (ev->card->view) {
|
||||
if (ev->card->view)
|
||||
{
|
||||
|
||||
//fix for http://code.google.com/p/wagic/issues/detail?id=462.
|
||||
// We don't want a card in the hand to have an alpha of 0
|
||||
@@ -222,7 +249,7 @@ int GuiHandSelf::receiveEventPlus(WEvent* e)
|
||||
}
|
||||
else
|
||||
card = NEW CardView(CardView::handZone, ev->card, ClosedRowX, 0);
|
||||
card->t = 6*M_PI;
|
||||
card->t = 6 * M_PI;
|
||||
cards.push_back(card);
|
||||
CardSelectorSingleton::Instance()->Add(card);
|
||||
Repos();
|
||||
@@ -260,7 +287,8 @@ int GuiHandOpponent::receiveEventPlus(WEvent* e)
|
||||
card = NEW CardView(CardView::handZone, event->card, *(event->card->view));
|
||||
else
|
||||
card = NEW CardView(CardView::handZone, event->card, ClosedRowX, 0);
|
||||
card->alpha = 255; card->t = -4*M_PI;
|
||||
card->alpha = 255;
|
||||
card->t = -4 * M_PI;
|
||||
cards.push_back(card);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include "GuiLayers.h"
|
||||
#include "Player.h"
|
||||
|
||||
GuiLayer::GuiLayer(){
|
||||
GuiLayer::GuiLayer()
|
||||
{
|
||||
modal = 0;
|
||||
hasFocus = false;
|
||||
mCount = 0;
|
||||
@@ -11,20 +12,24 @@ GuiLayer::GuiLayer(){
|
||||
mActionButton = JGE_BTN_OK;
|
||||
}
|
||||
|
||||
GuiLayer::~GuiLayer(){
|
||||
GuiLayer::~GuiLayer()
|
||||
{
|
||||
resetObjects();
|
||||
}
|
||||
|
||||
void GuiLayer::Add(JGuiObject *object){
|
||||
void GuiLayer::Add(JGuiObject *object)
|
||||
{
|
||||
mObjects.push_back(object);
|
||||
mCount++;
|
||||
}
|
||||
|
||||
int GuiLayer::Remove(JGuiObject *object){
|
||||
for (int i=0;i<mCount;i++)
|
||||
if (mObjects[i]==object){
|
||||
int GuiLayer::Remove(JGuiObject *object)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] == object)
|
||||
{
|
||||
delete mObjects[i];
|
||||
mObjects.erase(mObjects.begin()+i);
|
||||
mObjects.erase(mObjects.begin() + i);
|
||||
mCount--;
|
||||
if (mCurr == mCount)
|
||||
mCurr = 0;
|
||||
@@ -33,25 +38,28 @@ int GuiLayer::Remove(JGuiObject *object){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GuiLayer::getMaxId(){
|
||||
int GuiLayer::getMaxId()
|
||||
{
|
||||
return mCount;
|
||||
}
|
||||
|
||||
void GuiLayer::Render(){
|
||||
for (int i=0;i<mCount;i++)
|
||||
if (mObjects[i]!=NULL)
|
||||
void GuiLayer::Render()
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL)
|
||||
mObjects[i]->Render();
|
||||
}
|
||||
|
||||
void GuiLayer::Update(float dt){
|
||||
for (int i=0;i<mCount;i++)
|
||||
if (mObjects[i]!=NULL)
|
||||
void GuiLayer::Update(float dt)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL)
|
||||
mObjects[i]->Update(dt);
|
||||
}
|
||||
|
||||
|
||||
void GuiLayer::resetObjects(){
|
||||
for (int i=0;i<mCount;i++)
|
||||
void GuiLayer::resetObjects()
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i])
|
||||
delete mObjects[i];
|
||||
mObjects.clear();
|
||||
@@ -59,15 +67,18 @@ void GuiLayer::resetObjects(){
|
||||
mCurr = 0;
|
||||
}
|
||||
|
||||
int GuiLayer::getIndexOf(JGuiObject * object){
|
||||
for (int i=0; i<mCount; i++){
|
||||
int GuiLayer::getIndexOf(JGuiObject * object)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] == object)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
JGuiObject * GuiLayer::getByIndex(int index){
|
||||
JGuiObject * GuiLayer::getByIndex(int index)
|
||||
{
|
||||
return mObjects[index];
|
||||
}
|
||||
|
||||
|
||||
+124
-85
@@ -7,48 +7,52 @@
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) : Pos(x, y, 0.5, 0.0, 255), f(-1), destx(destx), desty(desty), mode(ALIVE), color(color)
|
||||
ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) :
|
||||
Pos(x, y, 0.5, 0.0, 255), f(-1), destx(destx), desty(desty), mode(ALIVE), color(color)
|
||||
{
|
||||
hgeParticleSystemInfo * psi = NULL;
|
||||
JQuad * mq = resources.GetQuad("stars");
|
||||
|
||||
if(!mq){
|
||||
if (!mq)
|
||||
{
|
||||
particleSys = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (color)
|
||||
{
|
||||
case Constants::MTG_COLOR_RED :
|
||||
psi = resources.RetrievePSI("manared.psi",mq);
|
||||
case Constants::MTG_COLOR_RED:
|
||||
psi = resources.RetrievePSI("manared.psi", mq);
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLUE :
|
||||
psi = resources.RetrievePSI("manablue.psi",mq);
|
||||
case Constants::MTG_COLOR_BLUE:
|
||||
psi = resources.RetrievePSI("manablue.psi", mq);
|
||||
break;
|
||||
case Constants::MTG_COLOR_GREEN :
|
||||
psi = resources.RetrievePSI("managreen.psi",mq);
|
||||
case Constants::MTG_COLOR_GREEN:
|
||||
psi = resources.RetrievePSI("managreen.psi", mq);
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLACK :
|
||||
psi = resources.RetrievePSI("manablack.psi",mq);
|
||||
case Constants::MTG_COLOR_BLACK:
|
||||
psi = resources.RetrievePSI("manablack.psi", mq);
|
||||
break;
|
||||
case Constants::MTG_COLOR_WHITE :
|
||||
psi = resources.RetrievePSI("manawhite.psi",mq);
|
||||
case Constants::MTG_COLOR_WHITE:
|
||||
psi = resources.RetrievePSI("manawhite.psi", mq);
|
||||
break;
|
||||
default :
|
||||
psi = resources.RetrievePSI("mana.psi",mq);
|
||||
default:
|
||||
psi = resources.RetrievePSI("mana.psi", mq);
|
||||
}
|
||||
|
||||
if(!psi){
|
||||
if (!psi)
|
||||
{
|
||||
psi = NEW hgeParticleSystemInfo();
|
||||
if(!psi)
|
||||
if (!psi)
|
||||
return;
|
||||
hgeParticleSystemInfo * defaults = resources.RetrievePSI("mana.psi",mq);
|
||||
if(defaults){
|
||||
memcpy(psi,defaults,sizeof(hgeParticleSystemInfo));
|
||||
hgeParticleSystemInfo * defaults = resources.RetrievePSI("mana.psi", mq);
|
||||
if (defaults)
|
||||
{
|
||||
memcpy(psi, defaults, sizeof(hgeParticleSystemInfo));
|
||||
}
|
||||
else{
|
||||
memset(psi,0,sizeof(hgeParticleSystemInfo));
|
||||
else
|
||||
{
|
||||
memset(psi, 0, sizeof(hgeParticleSystemInfo));
|
||||
|
||||
//Default values for particle system! Cribbed from mana.psi
|
||||
//Really, we should just be loading that and then changing colors...
|
||||
@@ -65,24 +69,25 @@ ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) : Pos(
|
||||
psi->sprite = mq;
|
||||
}
|
||||
|
||||
switch(color){
|
||||
case Constants::MTG_COLOR_RED :
|
||||
switch (color)
|
||||
{
|
||||
case Constants::MTG_COLOR_RED:
|
||||
psi->colColorStart.SetHWColor(ARGB(161,240,40,44));
|
||||
psi->colColorEnd.SetHWColor(ARGB(14,242,155,153));
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLUE :
|
||||
case Constants::MTG_COLOR_BLUE:
|
||||
psi->colColorStart.SetHWColor(ARGB(161,28,40,224));
|
||||
psi->colColorEnd.SetHWColor(ARGB(14,255,255,255));
|
||||
break;
|
||||
case Constants::MTG_COLOR_GREEN :
|
||||
case Constants::MTG_COLOR_GREEN:
|
||||
psi->colColorStart.SetHWColor(ARGB(161,36,242,44));
|
||||
psi->colColorEnd.SetHWColor(ARGB(14,129,244,153));
|
||||
break;
|
||||
case Constants::MTG_COLOR_BLACK :
|
||||
case Constants::MTG_COLOR_BLACK:
|
||||
psi->colColorStart.SetHWColor(ARGB(161,210,117,210));
|
||||
psi->colColorEnd.SetHWColor(ARGB(14,80,56,80));
|
||||
break;
|
||||
case Constants::MTG_COLOR_WHITE :
|
||||
case Constants::MTG_COLOR_WHITE:
|
||||
psi->colColorStart.SetHWColor(ARGB(151,151,127,38));
|
||||
psi->colColorEnd.SetHWColor(ARGB(8,255,255,255));
|
||||
break;
|
||||
@@ -105,19 +110,19 @@ ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) : Pos(
|
||||
|
||||
particleSys->FireAt(x, y);
|
||||
|
||||
zoomP1 = 0.2f + 0.1f * ((float)rand() / (float)RAND_MAX);
|
||||
zoomP2 = 0.2f + 0.1f * ((float)rand() / (float)RAND_MAX);
|
||||
zoomP3 = 2 * M_PI * ((float)rand() / (float)RAND_MAX);
|
||||
zoomP4 = 2 * M_PI * ((float)rand() / (float)RAND_MAX);
|
||||
zoomP5 = 0.5f + ((float)rand() / (float)RAND_MAX);
|
||||
zoomP6 = 0.5f + ((float)rand() / (float)RAND_MAX);
|
||||
zoomP1 = 0.2f + 0.1f * ((float) rand() / (float) RAND_MAX);
|
||||
zoomP2 = 0.2f + 0.1f * ((float) rand() / (float) RAND_MAX);
|
||||
zoomP3 = 2 * M_PI * ((float) rand() / (float) RAND_MAX);
|
||||
zoomP4 = 2 * M_PI * ((float) rand() / (float) RAND_MAX);
|
||||
zoomP5 = 0.5f + ((float) rand() / (float) RAND_MAX);
|
||||
zoomP6 = 0.5f + ((float) rand() / (float) RAND_MAX);
|
||||
|
||||
xP1 = 2 * M_PI * ((float)rand() / (float)RAND_MAX);
|
||||
xP2 = 5 + 30 * ((float)rand() / (float)RAND_MAX);
|
||||
xP3 = 0.5f + ((float)rand() / (float)RAND_MAX);
|
||||
yP1 = 2 * M_PI * ((float)rand() / (float)RAND_MAX);
|
||||
yP2 = 5 + 10 * ((float)rand() / (float)RAND_MAX);
|
||||
yP3 = 0.5f + ((float)rand() / (float)RAND_MAX);
|
||||
xP1 = 2 * M_PI * ((float) rand() / (float) RAND_MAX);
|
||||
xP2 = 5 + 30 * ((float) rand() / (float) RAND_MAX);
|
||||
xP3 = 0.5f + ((float) rand() / (float) RAND_MAX);
|
||||
yP1 = 2 * M_PI * ((float) rand() / (float) RAND_MAX);
|
||||
yP2 = 5 + 10 * ((float) rand() / (float) RAND_MAX);
|
||||
yP3 = 0.5f + ((float) rand() / (float) RAND_MAX);
|
||||
|
||||
actT = 0;
|
||||
tP1 = 0;
|
||||
@@ -130,7 +135,7 @@ ManaIcon::~ManaIcon()
|
||||
|
||||
void ManaIcon::Render()
|
||||
{
|
||||
if(!particleSys)
|
||||
if (!particleSys)
|
||||
return;
|
||||
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
@@ -152,37 +157,46 @@ void ManaIcon::Update(float dt, float shift)
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case DROPPING :
|
||||
case DROPPING:
|
||||
f += dt * 700;
|
||||
actY += f * dt;
|
||||
if (actY > SCREEN_HEIGHT * 2) mode = DEAD;
|
||||
if (actY > SCREEN_HEIGHT * 2)
|
||||
mode = DEAD;
|
||||
break;
|
||||
case WITHERING :
|
||||
case WITHERING:
|
||||
actT += dt * 4;
|
||||
actZ /= f; zoomP1 /= f; zoomP2 /= f;
|
||||
actZ /= f;
|
||||
zoomP1 /= f;
|
||||
zoomP2 /= f;
|
||||
f -= dt;
|
||||
actZ *= f; zoomP1 *= f; zoomP2 *= f;
|
||||
actZ *= f;
|
||||
zoomP1 *= f;
|
||||
zoomP2 *= f;
|
||||
yP1 += yP3 * dt;
|
||||
actY = y + yP2 * sinf(M_PI * yP1);
|
||||
if (f < 0) mode = DEAD;
|
||||
if (f < 0)
|
||||
mode = DEAD;
|
||||
break;
|
||||
case ALIVE :
|
||||
case ALIVE:
|
||||
x += 10 * dt * (destx - x);
|
||||
y += 10 * dt * (desty + shift - y);
|
||||
yP1 += yP3 * dt;
|
||||
actY = y + yP2 * sinf(M_PI * yP1);
|
||||
|
||||
if (particleSys && (fabs(destx - x) < 5) && (fabs(desty + shift - y) < 5)){
|
||||
if (OptionManaDisplay::STATIC == options[Options::MANADISPLAY].number){
|
||||
if (particleSys && (fabs(destx - x) < 5) && (fabs(desty + shift - y) < 5))
|
||||
{
|
||||
if (OptionManaDisplay::STATIC == options[Options::MANADISPLAY].number)
|
||||
{
|
||||
SAFE_DELETE(particleSys); //Static Mana Only: avoid expensive particle processing
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DEAD :
|
||||
case DEAD:
|
||||
break;
|
||||
}
|
||||
|
||||
if (particleSys){
|
||||
if (particleSys)
|
||||
{
|
||||
particleSys->MoveTo(actX, actY);
|
||||
particleSys->Update(dt);
|
||||
}
|
||||
@@ -192,27 +206,33 @@ void ManaIcon::Wither()
|
||||
{
|
||||
mode = WITHERING;
|
||||
f = 1.0;
|
||||
if (particleSys) particleSys->Stop();
|
||||
if (particleSys)
|
||||
particleSys->Stop();
|
||||
}
|
||||
void ManaIcon::Drop()
|
||||
{
|
||||
mode = DROPPING;
|
||||
if (f < 0) f = 0;
|
||||
if (particleSys) particleSys->Stop();
|
||||
if (f < 0)
|
||||
f = 0;
|
||||
if (particleSys)
|
||||
particleSys->Stop();
|
||||
}
|
||||
|
||||
GuiMana::GuiMana(float x, float y, Player *p):x(x),y(y),owner(p)
|
||||
GuiMana::GuiMana(float x, float y, Player *p) :
|
||||
x(x), y(y), owner(p)
|
||||
{
|
||||
}
|
||||
|
||||
GuiMana::~GuiMana(){
|
||||
for (vector<ManaIcon*>::iterator it = manas.begin(); it != manas.end(); ++it){
|
||||
delete(*it);
|
||||
GuiMana::~GuiMana()
|
||||
{
|
||||
for (vector<ManaIcon*>::iterator it = manas.begin(); it != manas.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiMana::RenderStatic(){
|
||||
void GuiMana::RenderStatic()
|
||||
{
|
||||
int values[Constants::MTG_NB_COLORS];
|
||||
int totalColors = 0;
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
@@ -220,34 +240,42 @@ void GuiMana::RenderStatic(){
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; ++i)
|
||||
values[i] = 0;
|
||||
for (vector<ManaIcon*>::iterator it = manas.begin(); it != manas.end(); ++it)
|
||||
if (ManaIcon::ALIVE == (*it)->mode) {
|
||||
if (ManaIcon::ALIVE == (*it)->mode)
|
||||
{
|
||||
values[(*it)->color]++;
|
||||
if (values[(*it)->color] == 1) totalColors++;
|
||||
if (values[(*it)->color] == 1)
|
||||
totalColors++;
|
||||
}
|
||||
|
||||
if (!totalColors) return;
|
||||
if (!totalColors)
|
||||
return;
|
||||
|
||||
float x0 = x - 20*totalColors;
|
||||
if (x0 < 10) x0 = 10;
|
||||
float xEnd = x0 + 20*totalColors;
|
||||
r->FillRoundRect(x0, y - 5, static_cast<float>(20 * totalColors + 5), 20, 2, ARGB(128,0,0,0));
|
||||
float x0 = x - 20 * totalColors;
|
||||
if (x0 < 10)
|
||||
x0 = 10;
|
||||
float xEnd = x0 + 20 * totalColors;
|
||||
r->FillRoundRect(x0, y - 5, static_cast<float> (20 * totalColors + 5), 20, 2, ARGB(128,0,0,0));
|
||||
|
||||
int offset = 0;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; ++i){
|
||||
if (values[i]){
|
||||
offset-=20;
|
||||
r->RenderQuad(manaIcons[i],xEnd + 15 + offset, y + 5, 0, 0.7f, 0.7f);
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; ++i)
|
||||
{
|
||||
if (values[i])
|
||||
{
|
||||
offset -= 20;
|
||||
r->RenderQuad(manaIcons[i], xEnd + 15 + offset, y + 5, 0, 0.7f, 0.7f);
|
||||
}
|
||||
}
|
||||
r->FillRoundRect(x0, y, static_cast<float>(20 * totalColors + 5), 8, 2, ARGB(100,0,0,0));
|
||||
r->FillRoundRect(x0, y, static_cast<float> (20 * totalColors + 5), 8, 2, ARGB(100,0,0,0));
|
||||
offset = 0;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; ++i){
|
||||
if (values[i]){
|
||||
offset-=20;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; ++i)
|
||||
{
|
||||
if (values[i])
|
||||
{
|
||||
offset -= 20;
|
||||
char buf[4];
|
||||
sprintf(buf,"%i",values[i]);
|
||||
sprintf(buf, "%i", values[i]);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(buf,xEnd+offset + 9, y);
|
||||
mFont->DrawString(buf, xEnd + offset + 9, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,14 +289,20 @@ void GuiMana::Render()
|
||||
RenderStatic();
|
||||
}
|
||||
|
||||
bool remove_dead(ManaIcon* m) { return ManaIcon::DEAD != m->mode; }
|
||||
bool remove_dead(ManaIcon* m)
|
||||
{
|
||||
return ManaIcon::DEAD != m->mode;
|
||||
}
|
||||
|
||||
void GuiMana::Update(float dt)
|
||||
{
|
||||
{
|
||||
float shift = 0;
|
||||
for (vector<ManaIcon*>::iterator it = manas.begin(); it != manas.end(); ++it)
|
||||
{ (*it)->Update(dt, shift); shift += 15; }
|
||||
{
|
||||
(*it)->Update(dt, shift);
|
||||
shift += 15;
|
||||
}
|
||||
}
|
||||
vector<ManaIcon*>::iterator it = partition(manas.begin(), manas.end(), &remove_dead);
|
||||
if (it != manas.end())
|
||||
@@ -283,23 +317,27 @@ int GuiMana::receiveEventPlus(WEvent* e)
|
||||
{
|
||||
if (WEventEngageMana *event = dynamic_cast<WEventEngageMana*>(e))
|
||||
{
|
||||
if (event->destination != owner->getManaPool()) return 0;
|
||||
if (event->destination != owner->getManaPool())
|
||||
return 0;
|
||||
if (event->card && event->card->view)
|
||||
manas.push_back(NEW ManaIcon(event->color, event->card->view->actX, event->card->view->actY, x, y));
|
||||
else
|
||||
manas.push_back(NEW ManaIcon(event->color, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, x, y));
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GuiMana::receiveEventMinus(WEvent* e)
|
||||
{
|
||||
if (WEventConsumeMana *event = dynamic_cast<WEventConsumeMana*>(e))
|
||||
{
|
||||
if (event->source != owner->getManaPool()) return 0;
|
||||
if (event->source != owner->getManaPool())
|
||||
return 0;
|
||||
for (vector<ManaIcon*>::iterator it = manas.begin(); it != manas.end(); ++it)
|
||||
if ((event->color == (*it)->color) && (ManaIcon::ALIVE == (*it)->mode)) {
|
||||
if ((event->color == (*it)->color) && (ManaIcon::ALIVE == (*it)->mode))
|
||||
{
|
||||
(*it)->Wither();
|
||||
return 1;
|
||||
}
|
||||
@@ -307,7 +345,8 @@ int GuiMana::receiveEventMinus(WEvent* e)
|
||||
}
|
||||
else if (WEventEmptyManaPool *event2 = dynamic_cast<WEventEmptyManaPool*>(e))
|
||||
{
|
||||
if (event2->source != owner->getManaPool()) return 0;
|
||||
if (event2->source != owner->getManaPool())
|
||||
return 0;
|
||||
for (vector<ManaIcon*>::iterator it = manas.begin(); it != manas.end(); ++it)
|
||||
(*it)->Drop();
|
||||
return 1;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "GuiMessageBox.h"
|
||||
|
||||
bool GuiMessageBox::CheckUserInput(JButton key){
|
||||
bool GuiMessageBox::CheckUserInput(JButton key)
|
||||
{
|
||||
if (mActionButton == key)
|
||||
{
|
||||
if (mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
|
||||
@@ -17,10 +18,10 @@ bool GuiMessageBox::CheckUserInput(JButton key){
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
if (n<0)
|
||||
if (n < 0)
|
||||
{
|
||||
if ((mStyle&JGUI_STYLE_WRAPPING))
|
||||
n = mCount-1;
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = mCount - 1;
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
@@ -36,12 +37,12 @@ bool GuiMessageBox::CheckUserInput(JButton key){
|
||||
{
|
||||
int n = mCurr;
|
||||
n++;
|
||||
if (n>mCount-1)
|
||||
if (n > mCount - 1)
|
||||
{
|
||||
if ((mStyle&JGUI_STYLE_WRAPPING))
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = 0;
|
||||
else
|
||||
n = mCount-1;
|
||||
n = mCount - 1;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Translate.h"
|
||||
|
||||
/*
|
||||
static int colors[] =
|
||||
static int colors[] =
|
||||
{
|
||||
ARGB(255, 255, 255, 255),
|
||||
ARGB(255, 255, 000, 000),
|
||||
@@ -21,7 +21,7 @@ static int colors[] =
|
||||
ARGB(255, 255, 255, 255),
|
||||
ARGB(255, 255, 255, 255)
|
||||
};
|
||||
*/
|
||||
*/
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -32,23 +32,25 @@ namespace
|
||||
const float ICONSCALE = 1.5;
|
||||
const float CENTER = SCREEN_HEIGHT_F / 2 + 10;
|
||||
|
||||
|
||||
void DrawGlyph(JQuad* inQuad, int inGlyph, float inY, float inAngle, unsigned int inP, float inScale)
|
||||
{
|
||||
float xPos = static_cast<float>((inP + inGlyph * (int)(kWidth+1)) % (kPhases * (int)(kWidth+1)));
|
||||
float xPos = static_cast<float> ((inP + inGlyph * (int) (kWidth + 1)) % (kPhases * (int) (kWidth + 1)));
|
||||
inQuad->SetTextureRect(xPos, 0, kWidth, kHeight);
|
||||
JRenderer::GetInstance()->RenderQuad(inQuad, 0, inY, 0.0, inScale, inScale);
|
||||
}
|
||||
}
|
||||
|
||||
GuiPhaseBar::GuiPhaseBar() : phase(NULL), angle(0.0f)
|
||||
GuiPhaseBar::GuiPhaseBar() :
|
||||
phase(NULL), angle(0.0f)
|
||||
{
|
||||
JQuad * quad = NULL;
|
||||
if ((quad = resources.GetQuad("phasebar")) != NULL){
|
||||
if ((quad = resources.GetQuad("phasebar")) != NULL)
|
||||
{
|
||||
quad->mHeight = kHeight;
|
||||
quad->mWidth = kWidth;
|
||||
}
|
||||
else GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
||||
else
|
||||
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
||||
}
|
||||
|
||||
GuiPhaseBar::~GuiPhaseBar()
|
||||
@@ -57,7 +59,10 @@ GuiPhaseBar::~GuiPhaseBar()
|
||||
|
||||
void GuiPhaseBar::Update(float dt)
|
||||
{
|
||||
if (angle > 3*dt) angle -= 3*dt; else angle = 0;
|
||||
if (angle > 3 * dt)
|
||||
angle -= 3 * dt;
|
||||
else
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
void GuiPhaseBar::Render()
|
||||
@@ -67,7 +72,7 @@ void GuiPhaseBar::Render()
|
||||
|
||||
JRenderer::GetInstance()->DrawLine(0, CENTER, SCREEN_WIDTH, CENTER, ARGB(255, 255, 255, 255));
|
||||
|
||||
unsigned int p = (phase->id + kPhases - 4) * (int)(kWidth+1);
|
||||
unsigned int p = (phase->id + kPhases - 4) * (int) (kWidth + 1);
|
||||
float centerYPosition = CENTER + (kWidth / 2) * angle * ICONSCALE / (M_PI / 6) - ICONSCALE * kWidth / 4;
|
||||
float yPos = centerYPosition;
|
||||
float scale = 0;
|
||||
@@ -88,9 +93,9 @@ void GuiPhaseBar::Render()
|
||||
|
||||
if (angle > 0)
|
||||
{
|
||||
scale = ICONSCALE * sinf(angle)/2;
|
||||
scale = ICONSCALE * sinf(angle) / 2;
|
||||
yPos -= kWidth * scale;
|
||||
float xPos = static_cast<float>(p % (kPhases * (int)(kWidth+1)));
|
||||
float xPos = static_cast<float> (p % (kPhases * (int) (kWidth + 1)));
|
||||
quad->SetTextureRect(xPos, kHeight, kWidth, kHeight);
|
||||
JRenderer::GetInstance()->RenderQuad(quad, 0, yPos, 0.0, scale, scale);
|
||||
}
|
||||
@@ -99,28 +104,35 @@ void GuiPhaseBar::Render()
|
||||
WFont * font = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
string currentP = _("your turn");
|
||||
string interrupt = "";
|
||||
if (g->currentPlayer == g->players[1]){
|
||||
if (g->currentPlayer == g->players[1])
|
||||
{
|
||||
currentP = _("opponent's turn");
|
||||
}
|
||||
font->SetColor(ARGB(255, 255, 255, 255));
|
||||
if (g->currentlyActing()->isAI()){
|
||||
if (g->currentlyActing()->isAI())
|
||||
{
|
||||
font->SetColor(ARGB(255, 128, 128, 128));
|
||||
}
|
||||
if (g->currentlyActing() != g->currentPlayer){
|
||||
if (g->currentPlayer == g->players[0]) {
|
||||
interrupt = _(" - ")+_("opponent plays");
|
||||
}else{
|
||||
interrupt = _(" - ")+_("you play");
|
||||
if (g->currentlyActing() != g->currentPlayer)
|
||||
{
|
||||
if (g->currentPlayer == g->players[0])
|
||||
{
|
||||
interrupt = _(" - ") + _("opponent plays");
|
||||
}
|
||||
else
|
||||
{
|
||||
interrupt = _(" - ") + _("you play");
|
||||
}
|
||||
}
|
||||
|
||||
char buf[64]; sprintf(buf, _("(%s%s) %s").c_str(), currentP.c_str(),interrupt.c_str(),_(PhaseRing::phaseName(phase->id)).c_str());
|
||||
font->DrawString(buf, SCREEN_WIDTH-5, 2,JGETEXT_RIGHT);
|
||||
char buf[64];
|
||||
sprintf(buf, _("(%s%s) %s").c_str(), currentP.c_str(), interrupt.c_str(), _(PhaseRing::phaseName(phase->id)).c_str());
|
||||
font->DrawString(buf, SCREEN_WIDTH - 5, 2, JGETEXT_RIGHT);
|
||||
}
|
||||
|
||||
int GuiPhaseBar::receiveEventMinus(WEvent *e)
|
||||
{
|
||||
WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*>(e);
|
||||
WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*> (e);
|
||||
if (event)
|
||||
{
|
||||
angle = M_PI / 6;
|
||||
|
||||
+142
-69
@@ -13,8 +13,10 @@ const float GuiPlay::VERTHEIGHT = 80.0f;
|
||||
void GuiPlay::CardStack::reset(unsigned total, float x, float y)
|
||||
{
|
||||
this->total = total;
|
||||
this->x = 0; baseX = x;
|
||||
this->y = 0; baseY = y;
|
||||
this->x = 0;
|
||||
baseX = x;
|
||||
this->y = 0;
|
||||
baseY = y;
|
||||
}
|
||||
|
||||
void GuiPlay::CardStack::RenderSpell(MTGCardInstance* card, iterator begin, iterator end, float x, float y)
|
||||
@@ -23,8 +25,9 @@ void GuiPlay::CardStack::RenderSpell(MTGCardInstance* card, iterator begin, iter
|
||||
{
|
||||
if ((*begin)->card->target == card)
|
||||
{
|
||||
RenderSpell(card, begin+1, end, x, y - 10);
|
||||
(*begin)->x = x; (*begin)->y = y;
|
||||
RenderSpell(card, begin + 1, end, x, y - 10);
|
||||
(*begin)->x = x;
|
||||
(*begin)->y = y;
|
||||
(*begin)->Render();
|
||||
return;
|
||||
}
|
||||
@@ -32,8 +35,12 @@ void GuiPlay::CardStack::RenderSpell(MTGCardInstance* card, iterator begin, iter
|
||||
}
|
||||
}
|
||||
|
||||
GuiPlay::HorzStack::HorzStack() {}
|
||||
GuiPlay::VertStack::VertStack() {}
|
||||
GuiPlay::HorzStack::HorzStack()
|
||||
{
|
||||
}
|
||||
GuiPlay::VertStack::VertStack()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiPlay::VertStack::reset(unsigned total, float x, float y)
|
||||
{
|
||||
@@ -49,18 +56,28 @@ void GuiPlay::HorzStack::Render(CardView* card, iterator begin, iterator end)
|
||||
|
||||
void GuiPlay::HorzStack::Enstack(CardView* card)
|
||||
{
|
||||
card->x = x + baseX; card->y = y + baseY;
|
||||
if (total < 8) x += CARD_WIDTH;
|
||||
else if (total < 16) x += (SCREEN_WIDTH - 200 - baseX) / total;
|
||||
else x += (SCREEN_WIDTH - 50 - baseX) / total;
|
||||
card->x = x + baseX;
|
||||
card->y = y + baseY;
|
||||
if (total < 8)
|
||||
x += CARD_WIDTH;
|
||||
else if (total < 16)
|
||||
x += (SCREEN_WIDTH - 200 - baseX) / total;
|
||||
else
|
||||
x += (SCREEN_WIDTH - 50 - baseX) / total;
|
||||
}
|
||||
|
||||
void GuiPlay::VertStack::Enstack(CardView* card)
|
||||
{
|
||||
if (0 == count % 3) { x += CARD_WIDTH; y = 0; }
|
||||
card->x = x + baseX; card->y = y + baseY;
|
||||
if (0 == count % 3)
|
||||
{
|
||||
x += CARD_WIDTH;
|
||||
y = 0;
|
||||
}
|
||||
card->x = x + baseX;
|
||||
card->y = y + baseY;
|
||||
y += 12;
|
||||
if (++count == total - 1 && y == 12)
|
||||
y += 12;
|
||||
if (++count == total-1 && y == 12) y += 12;
|
||||
}
|
||||
|
||||
void GuiPlay::VertStack::Render(CardView* card, iterator begin, iterator end)
|
||||
@@ -69,17 +86,38 @@ void GuiPlay::VertStack::Render(CardView* card, iterator begin, iterator end)
|
||||
card->Render();
|
||||
}
|
||||
|
||||
inline float GuiPlay::VertStack::nextX() { if (0 == count) return x + CARD_WIDTH; else return x; }
|
||||
inline float GuiPlay::VertStack::nextX()
|
||||
{
|
||||
if (0 == count)
|
||||
return x + CARD_WIDTH;
|
||||
else
|
||||
return x;
|
||||
}
|
||||
|
||||
GuiPlay::BattleField::BattleField() : attackers(0), blockers(0), height(0.0), red(0), colorFlow(0) {}
|
||||
GuiPlay::BattleField::BattleField() :
|
||||
attackers(0), blockers(0), height(0.0), red(0), colorFlow(0)
|
||||
{
|
||||
}
|
||||
const float GuiPlay::BattleField::HEIGHT = 80.0f;
|
||||
void GuiPlay::BattleField::addAttacker(MTGCardInstance*) { ++attackers; colorFlow = 1; }
|
||||
void GuiPlay::BattleField::removeAttacker(MTGCardInstance*) { --attackers; }
|
||||
void GuiPlay::BattleField::reset(float x, float y) { HorzStack::reset(0, x, y); currentAttacker = 1; }
|
||||
void GuiPlay::BattleField::addAttacker(MTGCardInstance*)
|
||||
{
|
||||
++attackers;
|
||||
colorFlow = 1;
|
||||
}
|
||||
void GuiPlay::BattleField::removeAttacker(MTGCardInstance*)
|
||||
{
|
||||
--attackers;
|
||||
}
|
||||
void GuiPlay::BattleField::reset(float x, float y)
|
||||
{
|
||||
HorzStack::reset(0, x, y);
|
||||
currentAttacker = 1;
|
||||
}
|
||||
void GuiPlay::BattleField::EnstackAttacker(CardView* card)
|
||||
{
|
||||
GameObserver* game = GameObserver::GetInstance();
|
||||
card->x = currentAttacker * (HORZWIDTH-20) / (attackers + 1); card->y = baseY + (game->players[0] == card->card->controller() ? 20 + y : -20 - y);
|
||||
card->x = currentAttacker * (HORZWIDTH - 20) / (attackers + 1);
|
||||
card->y = baseY + (game->players[0] == card->card->controller() ? 20 + y : -20 - y);
|
||||
++currentAttacker;
|
||||
// JRenderer::GetInstance()->RenderQuad(resources.GetQuad("BattleIcon"), card->actX, card->actY, 0, 0.5 + 0.1 * sinf(JGE::GetInstance()->GetTime()), 0.5 + 0.1 * sinf(JGE::GetInstance()->GetTime()));
|
||||
}
|
||||
@@ -87,9 +125,11 @@ void GuiPlay::BattleField::EnstackBlocker(CardView* card)
|
||||
{
|
||||
GameObserver* game = GameObserver::GetInstance();
|
||||
MTGCardInstance * c = card->card;
|
||||
if (!c) return;
|
||||
if (!c)
|
||||
return;
|
||||
int offset = 0;
|
||||
if (c->defenser && c->defenser->view){
|
||||
if (c->defenser && c->defenser->view)
|
||||
{
|
||||
offset = c->defenser->getDefenserRank(c);
|
||||
card->x = c->defenser->view->x + 5 * offset;
|
||||
}
|
||||
@@ -102,10 +142,13 @@ void GuiPlay::BattleField::Update(float dt)
|
||||
else
|
||||
height += 10 * dt * (HEIGHT - height);
|
||||
|
||||
if (colorFlow){
|
||||
red+= static_cast<int>(colorFlow * 300 * dt);
|
||||
if (red < 0) red = 0;
|
||||
if (red > 70) red = 70;
|
||||
if (colorFlow)
|
||||
{
|
||||
red += static_cast<int> (colorFlow * 300 * dt);
|
||||
if (red < 0)
|
||||
red = 0;
|
||||
if (red > 70)
|
||||
red = 70;
|
||||
}
|
||||
}
|
||||
void GuiPlay::BattleField::Render()
|
||||
@@ -114,45 +157,58 @@ void GuiPlay::BattleField::Render()
|
||||
JRenderer::GetInstance()->FillRect(22, SCREEN_HEIGHT / 2 + 10 - height / 2, 250, height, ARGB(127, red, 0, 0));
|
||||
}
|
||||
|
||||
GuiPlay::GuiPlay(GameObserver* game) : game(game)
|
||||
GuiPlay::GuiPlay(GameObserver* game) :
|
||||
game(game)
|
||||
{
|
||||
end_spells = cards.end();
|
||||
}
|
||||
|
||||
GuiPlay::~GuiPlay()
|
||||
{
|
||||
for (iterator it = cards.begin(); it != cards.end(); ++it){
|
||||
delete(*it);
|
||||
for (iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
bool isSpell(CardView* c) { return c->card->isSpell() && !c->card->isCreature(); }
|
||||
bool isSpell(CardView* c)
|
||||
{
|
||||
return c->card->isSpell() && !c->card->isCreature();
|
||||
}
|
||||
void GuiPlay::Replace()
|
||||
{
|
||||
unsigned opponentSpellsN = 0, selfSpellsN = 0, opponentLandsN = 0, opponentCreaturesN = 0,
|
||||
battleFieldAttackersN = 0, battleFieldBlockersN = 0, selfCreaturesN = 0, selfLandsN = 0;
|
||||
unsigned opponentSpellsN = 0, selfSpellsN = 0, opponentLandsN = 0, opponentCreaturesN = 0, battleFieldAttackersN = 0,
|
||||
battleFieldBlockersN = 0, selfCreaturesN = 0, selfLandsN = 0;
|
||||
|
||||
end_spells = stable_partition(cards.begin(), cards.end(), &isSpell);
|
||||
|
||||
for (iterator it = cards.begin(); it != end_spells; ++it)
|
||||
if (!(*it)->card->target)
|
||||
{
|
||||
if (game->players[0] == (*it)->card->controller()) ++selfSpellsN;
|
||||
else ++opponentSpellsN;
|
||||
if (game->players[0] == (*it)->card->controller())
|
||||
++selfSpellsN;
|
||||
else
|
||||
++opponentSpellsN;
|
||||
}
|
||||
for (iterator it = end_spells; it != cards.end(); ++it)
|
||||
{
|
||||
if ((*it)->card->isCreature())
|
||||
{
|
||||
if ((*it)->card->isAttacker()) ++battleFieldAttackersN;
|
||||
else if ((*it)->card->isDefenser()) ++battleFieldBlockersN;
|
||||
else if (game->players[0] == (*it)->card->controller()) ++selfCreaturesN;
|
||||
else ++opponentCreaturesN;
|
||||
if ((*it)->card->isAttacker())
|
||||
++battleFieldAttackersN;
|
||||
else if ((*it)->card->isDefenser())
|
||||
++battleFieldBlockersN;
|
||||
else if (game->players[0] == (*it)->card->controller())
|
||||
++selfCreaturesN;
|
||||
else
|
||||
++opponentCreaturesN;
|
||||
}
|
||||
else if ((*it)->card->isLand())
|
||||
{
|
||||
if (game->players[0] == (*it)->card->controller()) ++selfLandsN;
|
||||
else ++opponentLandsN;
|
||||
if (game->players[0] == (*it)->card->controller())
|
||||
++selfLandsN;
|
||||
else
|
||||
++opponentLandsN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,13 +218,15 @@ void GuiPlay::Replace()
|
||||
for (iterator it = cards.begin(); it != end_spells; ++it)
|
||||
if (!(*it)->card->target)
|
||||
{
|
||||
if (game->players[0] == (*it)->card->controller()) selfSpells.Enstack(*it);
|
||||
else opponentSpells.Enstack(*it);
|
||||
if (game->players[0] == (*it)->card->controller())
|
||||
selfSpells.Enstack(*it);
|
||||
else
|
||||
opponentSpells.Enstack(*it);
|
||||
}
|
||||
|
||||
float x = 24 + opponentSpells.nextX();
|
||||
//seperated the varible X into 2 different varibles. There are 2 players here!!
|
||||
//we should not be using a single varible to determine the positioning of cards!!
|
||||
//seperated the varible X into 2 different varibles. There are 2 players here!!
|
||||
//we should not be using a single varible to determine the positioning of cards!!
|
||||
float myx = 24 + selfSpells.nextX();
|
||||
opponentLands.reset(opponentLandsN, x, 50);
|
||||
opponentCreatures.reset(opponentCreaturesN, x, 95);
|
||||
@@ -176,20 +234,25 @@ void GuiPlay::Replace()
|
||||
selfCreatures.reset(selfCreaturesN, myx, 195);
|
||||
selfLands.reset(selfLandsN, myx, 240);
|
||||
|
||||
|
||||
for (iterator it = end_spells; it != cards.end(); ++it)
|
||||
{
|
||||
if ((*it)->card->isCreature())
|
||||
{
|
||||
if ((*it)->card->isAttacker()) battleField.EnstackAttacker(*it);
|
||||
else if ((*it)->card->isDefenser()) battleField.EnstackBlocker(*it);
|
||||
else if (game->players[0] == (*it)->card->controller()) selfCreatures.Enstack(*it);
|
||||
else opponentCreatures.Enstack(*it);
|
||||
if ((*it)->card->isAttacker())
|
||||
battleField.EnstackAttacker(*it);
|
||||
else if ((*it)->card->isDefenser())
|
||||
battleField.EnstackBlocker(*it);
|
||||
else if (game->players[0] == (*it)->card->controller())
|
||||
selfCreatures.Enstack(*it);
|
||||
else
|
||||
opponentCreatures.Enstack(*it);
|
||||
}
|
||||
else if ((*it)->card->isLand())
|
||||
{
|
||||
if (game->players[0] == (*it)->card->controller()) selfLands.Enstack(*it);
|
||||
else opponentLands.Enstack(*it);
|
||||
if (game->players[0] == (*it)->card->controller())
|
||||
selfLands.Enstack(*it);
|
||||
else
|
||||
opponentLands.Enstack(*it);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,18 +264,26 @@ void GuiPlay::Render()
|
||||
for (iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
if ((*it)->card->isLand())
|
||||
{
|
||||
if (game->players[0] == (*it)->card->controller()) selfLands.Render(*it, cards.begin(), end_spells);
|
||||
else opponentLands.Render(*it, cards.begin(), end_spells);
|
||||
if (game->players[0] == (*it)->card->controller())
|
||||
selfLands.Render(*it, cards.begin(), end_spells);
|
||||
else
|
||||
opponentLands.Render(*it, cards.begin(), end_spells);
|
||||
}
|
||||
else if ((*it)->card->isCreature())
|
||||
{
|
||||
if (game->players[0] == (*it)->card->controller()) selfCreatures.Render(*it, cards.begin(), end_spells);
|
||||
else opponentCreatures.Render(*it, cards.begin(), end_spells);
|
||||
if (game->players[0] == (*it)->card->controller())
|
||||
selfCreatures.Render(*it, cards.begin(), end_spells);
|
||||
else
|
||||
opponentCreatures.Render(*it, cards.begin(), end_spells);
|
||||
}
|
||||
else{
|
||||
if (!(*it)->card->target) {
|
||||
if (game->players[0] == (*it)->card->controller()) selfSpells.Render(*it, cards.begin(), end_spells);
|
||||
else opponentSpells.Render(*it, cards.begin(), end_spells);
|
||||
else
|
||||
{
|
||||
if (!(*it)->card->target)
|
||||
{
|
||||
if (game->players[0] == (*it)->card->controller())
|
||||
selfSpells.Render(*it, cards.begin(), end_spells);
|
||||
else
|
||||
opponentSpells.Render(*it, cards.begin(), end_spells);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,11 +299,11 @@ int GuiPlay::receiveEventPlus(WEvent * e)
|
||||
{
|
||||
if (WEventZoneChange *event = dynamic_cast<WEventZoneChange*>(e))
|
||||
{
|
||||
if ((game->players[0]->inPlay() == event->to) ||
|
||||
(game->players[1]->inPlay() == event->to))
|
||||
if ((game->players[0]->inPlay() == event->to) || (game->players[1]->inPlay() == event->to))
|
||||
{
|
||||
CardView * card;
|
||||
if (event->card->view){
|
||||
if (event->card->view)
|
||||
{
|
||||
//fix for http://code.google.com/p/wagic/issues/detail?id=462.
|
||||
// We don't want a card in the hand to have an alpha of 0
|
||||
event->card->view->alpha = 255;
|
||||
@@ -260,7 +331,7 @@ int GuiPlay::receiveEventPlus(WEvent * e)
|
||||
battleField.removeAttacker(event->card);
|
||||
Replace();
|
||||
}
|
||||
else if (dynamic_cast<WEventCreatureBlocker*>(e))
|
||||
else if (dynamic_cast<WEventCreatureBlocker*> (e))
|
||||
{
|
||||
Replace();
|
||||
}
|
||||
@@ -274,9 +345,10 @@ int GuiPlay::receiveEventPlus(WEvent * e)
|
||||
}
|
||||
else if (WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*>(e))
|
||||
{
|
||||
if (Constants::MTG_PHASE_COMBATEND == event->to->id) battleField.colorFlow = -1;
|
||||
if (Constants::MTG_PHASE_COMBATEND == event->to->id)
|
||||
battleField.colorFlow = -1;
|
||||
}
|
||||
else if (dynamic_cast<WEventCardChangeType*>(e))
|
||||
else if (dynamic_cast<WEventCardChangeType*> (e))
|
||||
Replace();
|
||||
return 0;
|
||||
}
|
||||
@@ -285,13 +357,14 @@ int GuiPlay::receiveEventMinus(WEvent * e)
|
||||
{
|
||||
if (WEventZoneChange *event = dynamic_cast<WEventZoneChange*>(e))
|
||||
{
|
||||
if ((game->players[0]->inPlay() == event->from) ||
|
||||
(game->players[1]->inPlay() == event->from))
|
||||
if ((game->players[0]->inPlay() == event->from) || (game->players[1]->inPlay() == event->from))
|
||||
for (iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
if (event->card->previous == (*it)->card || event->card == (*it)->card )
|
||||
if (event->card->previous == (*it)->card || event->card == (*it)->card)
|
||||
{
|
||||
if (event->card->previous && event->card->previous->attacker) battleField.removeAttacker(event->card->previous);
|
||||
else if (event->card->attacker) battleField.removeAttacker(event->card);
|
||||
if (event->card->previous && event->card->previous->attacker)
|
||||
battleField.removeAttacker(event->card->previous);
|
||||
else if (event->card->attacker)
|
||||
battleField.removeAttacker(event->card);
|
||||
CardView* cv = *it;
|
||||
CardSelectorSingleton::Instance()->Remove(cv);
|
||||
cards.erase(it);
|
||||
|
||||
+114
-77
@@ -3,18 +3,26 @@
|
||||
#include "Trash.h"
|
||||
#include "GuiStatic.h"
|
||||
|
||||
GuiStatic::GuiStatic(float desiredHeight, float x, float y, bool hasFocus, GuiAvatars* parent) : PlayGuiObject(desiredHeight, x, y, hasFocus), parent(parent) {}
|
||||
GuiStatic::GuiStatic(float desiredHeight, float x, float y, bool hasFocus, GuiAvatars* parent) :
|
||||
PlayGuiObject(desiredHeight, x, y, hasFocus), parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void GuiStatic::Entering()
|
||||
{
|
||||
parent->Activate(this);
|
||||
}
|
||||
|
||||
bool GuiStatic::Leaving(JButton key)
|
||||
{
|
||||
parent->Deactivate(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
GuiAvatar::GuiAvatar(float x, float y, bool hasFocus, Player * player, Corner corner, GuiAvatars* parent) : GuiStatic(static_cast<float>(GuiAvatar::Height), x, y, hasFocus, parent), avatarRed(255), currentLife(player->life),currentpoisonCount(player->poisonCount), corner(corner), player(player) {
|
||||
GuiAvatar::GuiAvatar(float x, float y, bool hasFocus, Player * player, Corner corner, GuiAvatars* parent) :
|
||||
GuiStatic(static_cast<float> (GuiAvatar::Height), x, y, hasFocus, parent), avatarRed(255), currentLife(player->life),
|
||||
currentpoisonCount(player->poisonCount), corner(corner), player(player)
|
||||
{
|
||||
type = GUI_AVATAR;
|
||||
}
|
||||
|
||||
@@ -28,19 +36,23 @@ void GuiAvatar::Render()
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
//Avatar
|
||||
int lifeDiff = life - currentLife;
|
||||
if (lifeDiff < 0 && currentLife > 0){
|
||||
avatarRed = 192 + (3* 255 * lifeDiff) / currentLife / 4;
|
||||
if (avatarRed < 0) avatarRed = 0;
|
||||
if (lifeDiff < 0 && currentLife > 0)
|
||||
{
|
||||
avatarRed = 192 + (3 * 255 * lifeDiff) / currentLife / 4;
|
||||
if (avatarRed < 0)
|
||||
avatarRed = 0;
|
||||
}
|
||||
int poisonDiff = poisonCount - currentpoisonCount;
|
||||
if (poisonDiff < 0 && currentpoisonCount > 0){
|
||||
avatarRed = 192 + (3* 255 * poisonDiff) / currentpoisonCount / 4;
|
||||
if (avatarRed < 0) avatarRed = 0;
|
||||
if (poisonDiff < 0 && currentpoisonCount > 0)
|
||||
{
|
||||
avatarRed = 192 + (3 * 255 * poisonDiff) / currentpoisonCount / 4;
|
||||
if (avatarRed < 0)
|
||||
avatarRed = 0;
|
||||
}
|
||||
currentpoisonCount = poisonCount;
|
||||
currentLife = life;
|
||||
|
||||
r->FillRect(actX+2, actY+2, Width * actZ, Height *actZ, ARGB((int)(actA / 2), 0, 0, 0));
|
||||
r->FillRect(actX + 2, actY + 2, Width * actZ, Height * actZ, ARGB((int)(actA / 2), 0, 0, 0));
|
||||
|
||||
float x0 = actX;
|
||||
float y0 = actY;
|
||||
@@ -48,84 +60,86 @@ void GuiAvatar::Render()
|
||||
JQuad * quad = player->mAvatar;
|
||||
if (quad)
|
||||
{
|
||||
if (corner == BOTTOM_RIGHT){
|
||||
if (corner == BOTTOM_RIGHT)
|
||||
{
|
||||
x0 -= quad->mWidth * actZ;
|
||||
y0 -= quad->mHeight * actZ;
|
||||
}
|
||||
switch (corner)
|
||||
{
|
||||
case TOP_LEFT : quad->SetHotSpot(0, 0); break;
|
||||
case BOTTOM_RIGHT : quad->SetHotSpot(35, 50); break;
|
||||
case TOP_LEFT:
|
||||
quad->SetHotSpot(0, 0);
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
quad->SetHotSpot(35, 50);
|
||||
break;
|
||||
}
|
||||
quad->SetColor(ARGB((int)actA, 255, avatarRed, avatarRed));
|
||||
r->RenderQuad(quad, actX, actY, actT, actZ, actZ);
|
||||
if (mHasFocus){
|
||||
r->FillRect(x0,x0,quad->mWidth * actZ,quad->mHeight * actZ, ARGB(abs(128 - wave),255,255,255));
|
||||
if (mHasFocus)
|
||||
{
|
||||
r->FillRect(x0, x0, quad->mWidth * actZ, quad->mHeight * actZ, ARGB(abs(128 - wave),255,255,255));
|
||||
}
|
||||
}
|
||||
|
||||
if (avatarRed < 255){
|
||||
if (avatarRed < 255)
|
||||
{
|
||||
avatarRed += 3;
|
||||
if (avatarRed > 255)
|
||||
avatarRed = 255;
|
||||
}
|
||||
|
||||
|
||||
if (game->currentPlayer == player)
|
||||
r->DrawRect(x0-1, y0-1, 36 * actZ, 51*actZ, ARGB((int)actA, 0, 255, 0));
|
||||
r->DrawRect(x0 - 1, y0 - 1, 36 * actZ, 51 * actZ, ARGB((int)actA, 0, 255, 0));
|
||||
else if (game->currentActionPlayer == player)
|
||||
r->DrawRect(x0, y0, 34 *actZ, 49 * actZ, ARGB((int)actA, 0, 0, 255));
|
||||
r->DrawRect(x0, y0, 34 * actZ, 49 * actZ, ARGB((int)actA, 0, 0, 255));
|
||||
if (game->isInterrupting == player)
|
||||
r->DrawRect(x0, y0, 34 * actZ, 49*actZ, ARGB((int)actA, 255, 0, 0));
|
||||
|
||||
|
||||
|
||||
r->DrawRect(x0, y0, 34 * actZ, 49 * actZ, ARGB((int)actA, 255, 0, 0));
|
||||
|
||||
//Life
|
||||
char buffer[5];
|
||||
sprintf(buffer, "%i",life);
|
||||
sprintf(buffer, "%i", life);
|
||||
switch (corner)
|
||||
{
|
||||
case TOP_LEFT :
|
||||
case TOP_LEFT:
|
||||
mFont->SetColor(ARGB((int)actA / 4, 0, 0, 0));
|
||||
mFont->DrawString(buffer, actX+2, actY+2);
|
||||
mFont->DrawString(buffer, actX + 2, actY + 2);
|
||||
mFont->SetColor(ARGB((int)actA, 255, 255, 255));
|
||||
mFont->DrawString(buffer, actX+1, actY+1);
|
||||
mFont->DrawString(buffer, actX + 1, actY + 1);
|
||||
break;
|
||||
case BOTTOM_RIGHT :
|
||||
case BOTTOM_RIGHT:
|
||||
mFont->SetColor(ARGB((int)actA, 255, 255, 255));
|
||||
mFont->DrawString(buffer, actX, actY-10, JGETEXT_RIGHT);
|
||||
mFont->DrawString(buffer, actX, actY - 10, JGETEXT_RIGHT);
|
||||
break;
|
||||
}
|
||||
//poison
|
||||
char poison[5];
|
||||
if(poisonCount > 0){
|
||||
sprintf(poison, "%i",poisonCount);
|
||||
if (poisonCount > 0)
|
||||
{
|
||||
sprintf(poison, "%i", poisonCount);
|
||||
switch (corner)
|
||||
{
|
||||
case TOP_LEFT :
|
||||
case TOP_LEFT:
|
||||
mFont->SetColor(ARGB((int)actA / 1, 0, 255, 0));
|
||||
mFont->DrawString(poison, actX+2, actY+10);
|
||||
mFont->DrawString(poison, actX + 2, actY + 10);
|
||||
break;
|
||||
case BOTTOM_RIGHT :
|
||||
case BOTTOM_RIGHT:
|
||||
mFont->SetColor(ARGB((int)actA / 1 ,0, 255, 0));
|
||||
mFont->DrawString(poison, actX, actY-20, JGETEXT_RIGHT);
|
||||
mFont->DrawString(poison, actX, actY - 20, JGETEXT_RIGHT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PlayGuiObject::Render();
|
||||
}
|
||||
|
||||
ostream& GuiAvatar::toString(ostream& out) const
|
||||
{
|
||||
return out << "GuiAvatar ::: avatarRed : " << avatarRed
|
||||
<< " ; currentLife : " << currentLife
|
||||
<< " ; currentpoisonCount : " << currentpoisonCount
|
||||
<< " ; player : " << player;
|
||||
return out << "GuiAvatar ::: avatarRed : " << avatarRed << " ; currentLife : " << currentLife << " ; currentpoisonCount : "
|
||||
<< currentpoisonCount << " ; player : " << player;
|
||||
}
|
||||
|
||||
|
||||
void GuiGameZone::toggleDisplay(){
|
||||
void GuiGameZone::toggleDisplay()
|
||||
{
|
||||
if (showCards)
|
||||
showCards = 0;
|
||||
else
|
||||
@@ -135,8 +149,8 @@ void GuiGameZone::toggleDisplay(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiGameZone::Render(){
|
||||
void GuiGameZone::Render()
|
||||
{
|
||||
//Texture
|
||||
JQuad * quad = resources.GetQuad("back_thumb");
|
||||
float scale = defaultHeight / quad->mHeight;
|
||||
@@ -145,57 +159,68 @@ void GuiGameZone::Render(){
|
||||
JRenderer::GetInstance()->RenderQuad(quad, actX, actY, 0.0, scale * actZ, scale * actZ);
|
||||
|
||||
float x0 = actX;
|
||||
if (x0 < SCREEN_WIDTH/2) {
|
||||
x0+=7;
|
||||
if (x0 < SCREEN_WIDTH / 2)
|
||||
{
|
||||
x0 += 7;
|
||||
}
|
||||
|
||||
if (mHasFocus)
|
||||
JRenderer::GetInstance()->FillRect(actX,actY,quad->mWidth * scale * actZ,quad->mHeight *scale * actZ, ARGB(abs(128 - wave),255,255,255));
|
||||
JRenderer::GetInstance()->FillRect(actX, actY, quad->mWidth * scale * actZ, quad->mHeight * scale * actZ,
|
||||
ARGB(abs(128 - wave),255,255,255));
|
||||
|
||||
//Number of cards
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
char buffer[11];
|
||||
int mAlpha = (int)(actA);
|
||||
sprintf(buffer,"%i", zone->nb_cards);
|
||||
int mAlpha = (int) (actA);
|
||||
sprintf(buffer, "%i", zone->nb_cards);
|
||||
mFont->SetColor(ARGB(mAlpha,0,0,0));
|
||||
mFont->DrawString(buffer, x0+1, actY+1);
|
||||
if (actA > 120) mAlpha = 255;
|
||||
mFont->DrawString(buffer, x0 + 1, actY + 1);
|
||||
if (actA > 120)
|
||||
mAlpha = 255;
|
||||
mFont->SetColor(ARGB(mAlpha,255,255,255));
|
||||
mFont->DrawString(buffer, x0, actY);
|
||||
|
||||
|
||||
|
||||
if (showCards) cd->Render();
|
||||
if (showCards)
|
||||
cd->Render();
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
(*it)->Render();
|
||||
PlayGuiObject::Render();
|
||||
}
|
||||
|
||||
void GuiGameZone::ButtonPressed(int controllerId, int controlId){
|
||||
void GuiGameZone::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
GameObserver::GetInstance()->ButtonPressed(this);
|
||||
}
|
||||
|
||||
bool GuiGameZone::CheckUserInput(JButton key){
|
||||
if (showCards) return cd->CheckUserInput(key);
|
||||
bool GuiGameZone::CheckUserInput(JButton key)
|
||||
{
|
||||
if (showCards)
|
||||
return cd->CheckUserInput(key);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiGameZone::CheckUserInput(int x, int y){
|
||||
if (showCards) return cd->CheckUserInput(x, y);
|
||||
bool GuiGameZone::CheckUserInput(int x, int y)
|
||||
{
|
||||
if (showCards)
|
||||
return cd->CheckUserInput(x, y);
|
||||
return false;
|
||||
}
|
||||
|
||||
void GuiGameZone::Update(float dt){
|
||||
if (showCards) cd->Update(dt);
|
||||
void GuiGameZone::Update(float dt)
|
||||
{
|
||||
if (showCards)
|
||||
cd->Update(dt);
|
||||
PlayGuiObject::Update(dt);
|
||||
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it){
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
{
|
||||
CardView * c = (*it);
|
||||
c->Update(dt);
|
||||
|
||||
//Dirty fix for http://code.google.com/p/wagic/issues/detail?id=113
|
||||
if (fabs(c->actX - c->x) < 0.01 && fabs(c->actY - c->y)< 0.01){
|
||||
if (fabs(c->actX - c->x) < 0.01 && fabs(c->actY - c->y) < 0.01)
|
||||
{
|
||||
cards.erase(it);
|
||||
trash(c);
|
||||
return;
|
||||
@@ -203,26 +228,30 @@ void GuiGameZone::Update(float dt){
|
||||
}
|
||||
}
|
||||
|
||||
GuiGameZone::GuiGameZone(float x, float y, bool hasFocus, MTGGameZone* zone, GuiAvatars* parent): GuiStatic(static_cast<float>(GuiGameZone::Height), x, y, hasFocus, parent), zone(zone){
|
||||
cd = NEW CardDisplay(0, GameObserver::GetInstance(), static_cast<int>(x), static_cast<int>(y), this);
|
||||
GuiGameZone::GuiGameZone(float x, float y, bool hasFocus, MTGGameZone* zone, GuiAvatars* parent) :
|
||||
GuiStatic(static_cast<float> (GuiGameZone::Height), x, y, hasFocus, parent), zone(zone)
|
||||
{
|
||||
cd = NEW CardDisplay(0, GameObserver::GetInstance(), static_cast<int> (x), static_cast<int> (y), this);
|
||||
cd->zone = zone;
|
||||
showCards = 0;
|
||||
}
|
||||
|
||||
GuiGameZone::~GuiGameZone(){
|
||||
if (cd) delete cd;
|
||||
GuiGameZone::~GuiGameZone()
|
||||
{
|
||||
if (cd)
|
||||
delete cd;
|
||||
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
|
||||
delete(*it);
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
ostream& GuiGameZone::toString(ostream& out) const
|
||||
{
|
||||
return out << "GuiGameZone ::: zone : " << zone
|
||||
<< " ; cd : " << cd
|
||||
<< " ; showCards : " << showCards;
|
||||
return out << "GuiGameZone ::: zone : " << zone << " ; cd : " << cd << " ; showCards : " << showCards;
|
||||
}
|
||||
|
||||
GuiGraveyard::GuiGraveyard(float x, float y, bool hasFocus, Player * player, GuiAvatars* parent) : GuiGameZone(x, y, hasFocus, player->game->graveyard, parent), player(player) {
|
||||
GuiGraveyard::GuiGraveyard(float x, float y, bool hasFocus, Player * player, GuiAvatars* parent) :
|
||||
GuiGameZone(x, y, hasFocus, player->game->graveyard, parent), player(player)
|
||||
{
|
||||
type = GUI_GRAVEYARD;
|
||||
}
|
||||
|
||||
@@ -236,7 +265,10 @@ int GuiGraveyard::receiveEventPlus(WEvent* e)
|
||||
t = NEW CardView(CardView::nullZone, event->card, *(event->card->view));
|
||||
else
|
||||
t = NEW CardView(CardView::nullZone, event->card, x, y);
|
||||
t->x = x + Width / 2; t->y = y + Height / 2; t->zoom = 0.6f; t->alpha = 0;
|
||||
t->x = x + Width / 2;
|
||||
t->y = y + Height / 2;
|
||||
t->zoom = 0.6f;
|
||||
t->alpha = 0;
|
||||
cards.push_back(t);
|
||||
return 1;
|
||||
}
|
||||
@@ -263,9 +295,10 @@ ostream& GuiGraveyard::toString(ostream& out) const
|
||||
return out << "GuiGraveyard :::";
|
||||
}
|
||||
|
||||
|
||||
//opponenthand begins
|
||||
GuiOpponentHand::GuiOpponentHand(float x, float y, bool hasFocus, Player * player, GuiAvatars* parent) : GuiGameZone(x, y, hasFocus, player->game->hand, parent), player(player) {
|
||||
GuiOpponentHand::GuiOpponentHand(float x, float y, bool hasFocus, Player * player, GuiAvatars* parent) :
|
||||
GuiGameZone(x, y, hasFocus, player->game->hand, parent), player(player)
|
||||
{
|
||||
type = GUI_OPPONENTHAND;
|
||||
}
|
||||
|
||||
@@ -279,7 +312,10 @@ int GuiOpponentHand::receiveEventPlus(WEvent* e)
|
||||
t = NEW CardView(CardView::nullZone, event->card, *(event->card->view));
|
||||
else
|
||||
t = NEW CardView(CardView::nullZone, event->card, x, y);
|
||||
t->x = x + Width / 2; t->y = y + Height / 2; t->zoom = 0.6f; t->alpha = 0;
|
||||
t->x = x + Width / 2;
|
||||
t->y = y + Height / 2;
|
||||
t->zoom = 0.6f;
|
||||
t->alpha = 0;
|
||||
cards.push_back(t);
|
||||
return 1;
|
||||
}
|
||||
@@ -306,11 +342,12 @@ ostream& GuiOpponentHand::toString(ostream& out) const
|
||||
return out << "GuiOpponentHand :::";
|
||||
}
|
||||
|
||||
GuiLibrary::GuiLibrary(float x, float y, bool hasFocus, Player * player, GuiAvatars* parent) : GuiGameZone(x, y, hasFocus,player->game->library, parent), player(player) {
|
||||
GuiLibrary::GuiLibrary(float x, float y, bool hasFocus, Player * player, GuiAvatars* parent) :
|
||||
GuiGameZone(x, y, hasFocus, player->game->library, parent), player(player)
|
||||
{
|
||||
type = GUI_LIBRARY;
|
||||
}
|
||||
|
||||
|
||||
ostream& GuiLibrary::toString(ostream& out) const
|
||||
{
|
||||
return out << "GuiLibrary :::";
|
||||
|
||||
+1727
-1099
File diff suppressed because it is too large
Load Diff
@@ -13,15 +13,18 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
MTGCard::MTGCard(){
|
||||
MTGCard::MTGCard()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
MTGCard::MTGCard(int set_id){
|
||||
MTGCard::MTGCard(int set_id)
|
||||
{
|
||||
init();
|
||||
setId = set_id;
|
||||
}
|
||||
MTGCard::MTGCard(MTGCard * source){
|
||||
MTGCard::MTGCard(MTGCard * source)
|
||||
{
|
||||
|
||||
strcpy(image_name, source->image_name);
|
||||
rarity = source->rarity;
|
||||
@@ -30,7 +33,8 @@ MTGCard::MTGCard(MTGCard * source){
|
||||
data = source->data;
|
||||
}
|
||||
|
||||
int MTGCard::init(){
|
||||
int MTGCard::init()
|
||||
{
|
||||
setId = 0;
|
||||
mtgid = 0;
|
||||
data = NULL;
|
||||
@@ -38,34 +42,43 @@ int MTGCard::init(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void MTGCard::setMTGId(int id){
|
||||
void MTGCard::setMTGId(int id)
|
||||
{
|
||||
mtgid = id;
|
||||
if (id < 0){
|
||||
if (id < 0)
|
||||
{
|
||||
sprintf(image_name, "%dt.jpg", -mtgid);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(image_name, "%d.jpg", mtgid);
|
||||
}
|
||||
}
|
||||
|
||||
int MTGCard::getMTGId() const {
|
||||
int MTGCard::getMTGId() const
|
||||
{
|
||||
return mtgid;
|
||||
}
|
||||
int MTGCard::getId() const {
|
||||
int MTGCard::getId() const
|
||||
{
|
||||
return mtgid;
|
||||
}
|
||||
char MTGCard::getRarity() const {
|
||||
char MTGCard::getRarity() const
|
||||
{
|
||||
return rarity;
|
||||
}
|
||||
|
||||
void MTGCard::setRarity(char _rarity){
|
||||
void MTGCard::setRarity(char _rarity)
|
||||
{
|
||||
rarity = _rarity;
|
||||
}
|
||||
|
||||
char * MTGCard::getImageName() {
|
||||
char * MTGCard::getImageName()
|
||||
{
|
||||
return image_name;
|
||||
}
|
||||
|
||||
void MTGCard::setPrimitive(CardPrimitive * cp){
|
||||
void MTGCard::setPrimitive(CardPrimitive * cp)
|
||||
{
|
||||
data = cp;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+526
-308
File diff suppressed because it is too large
Load Diff
@@ -27,90 +27,90 @@ const string Constants::kKickerKeyword = "kicker";
|
||||
|
||||
|
||||
const char* Constants::MTGBasicAbilities[] = {
|
||||
"trample",
|
||||
"forestwalk",
|
||||
"islandwalk",
|
||||
"mountainwalk",
|
||||
"swampwalk",
|
||||
"plainswalk",
|
||||
"flying",
|
||||
"first strike",
|
||||
"double strike",
|
||||
"fear",
|
||||
"flash",
|
||||
"haste",
|
||||
"lifelink",
|
||||
"reach",
|
||||
"shroud",
|
||||
"vigilance",
|
||||
"defender",
|
||||
"banding",
|
||||
"protection from green",
|
||||
"protection from blue",
|
||||
"protection from red",
|
||||
"protection from black",
|
||||
"protection from white",
|
||||
"unblockable",
|
||||
"wither",
|
||||
"persist",
|
||||
"retrace",
|
||||
"exalted",
|
||||
"nofizzle",
|
||||
"shadow",
|
||||
"reachshadow",
|
||||
"foresthome",
|
||||
"islandhome",
|
||||
"mountainhome",
|
||||
"swamphome",
|
||||
"plainshome",
|
||||
"cloud",
|
||||
"cantattack",
|
||||
"mustattack",
|
||||
"cantblock",
|
||||
"doesnotuntap",
|
||||
"opponentshroud",
|
||||
"indestructible",
|
||||
"intimidate",
|
||||
"deathtouch",
|
||||
"horsemanship",
|
||||
"cantregen",
|
||||
"oneblocker",
|
||||
"infect",
|
||||
"poisontoxic",
|
||||
"poisontwotoxic",
|
||||
"poisonthreetoxic",
|
||||
"phantom",//prevents damage and remove 1 +1/+1 counter
|
||||
"wilting",//source takes damage in the form of -1/-1 counters.
|
||||
"vigor",//instead of taking damage the source gains +1/+1 counters
|
||||
"changeling",//this card is every creature type at all times
|
||||
"absorb",//timeshifted sliver ability. if damage would be dealt to card, prevent 1 of that damage.
|
||||
"treason",
|
||||
"unearth",
|
||||
"cantlose",
|
||||
"cantlifelose",
|
||||
"cantmilllose",
|
||||
"cantcreaturecast",
|
||||
"cantspellcast",
|
||||
"onlyonecast",
|
||||
"storm",
|
||||
"bothcantcast",
|
||||
"bothnocreature",
|
||||
"oneboth",
|
||||
"affinityartifacts",
|
||||
"affinityplains",
|
||||
"affinityforests",
|
||||
"affinityislands",
|
||||
"affinitymountains",
|
||||
"affinityswamps",
|
||||
"affinitygreencreatures",
|
||||
"cantwin",
|
||||
"nomaxhand",
|
||||
"leyline",
|
||||
"playershroud",
|
||||
"controllershroud",
|
||||
"sunburst",
|
||||
"flanking",
|
||||
"exiledeath",
|
||||
"trample",
|
||||
"forestwalk",
|
||||
"islandwalk",
|
||||
"mountainwalk",
|
||||
"swampwalk",
|
||||
"plainswalk",
|
||||
"flying",
|
||||
"first strike",
|
||||
"double strike",
|
||||
"fear",
|
||||
"flash",
|
||||
"haste",
|
||||
"lifelink",
|
||||
"reach",
|
||||
"shroud",
|
||||
"vigilance",
|
||||
"defender",
|
||||
"banding",
|
||||
"protection from green",
|
||||
"protection from blue",
|
||||
"protection from red",
|
||||
"protection from black",
|
||||
"protection from white",
|
||||
"unblockable",
|
||||
"wither",
|
||||
"persist",
|
||||
"retrace",
|
||||
"exalted",
|
||||
"nofizzle",
|
||||
"shadow",
|
||||
"reachshadow",
|
||||
"foresthome",
|
||||
"islandhome",
|
||||
"mountainhome",
|
||||
"swamphome",
|
||||
"plainshome",
|
||||
"cloud",
|
||||
"cantattack",
|
||||
"mustattack",
|
||||
"cantblock",
|
||||
"doesnotuntap",
|
||||
"opponentshroud",
|
||||
"indestructible",
|
||||
"intimidate",
|
||||
"deathtouch",
|
||||
"horsemanship",
|
||||
"cantregen",
|
||||
"oneblocker",
|
||||
"infect",
|
||||
"poisontoxic",
|
||||
"poisontwotoxic",
|
||||
"poisonthreetoxic",
|
||||
"phantom",//prevents damage and remove 1 +1/+1 counter
|
||||
"wilting",//source takes damage in the form of -1/-1 counters.
|
||||
"vigor",//instead of taking damage the source gains +1/+1 counters
|
||||
"changeling",//this card is every creature type at all times
|
||||
"absorb",//timeshifted sliver ability. if damage would be dealt to card, prevent 1 of that damage.
|
||||
"treason",
|
||||
"unearth",
|
||||
"cantlose",
|
||||
"cantlifelose",
|
||||
"cantmilllose",
|
||||
"cantcreaturecast",
|
||||
"cantspellcast",
|
||||
"onlyonecast",
|
||||
"storm",
|
||||
"bothcantcast",
|
||||
"bothnocreature",
|
||||
"oneboth",
|
||||
"affinityartifacts",
|
||||
"affinityplains",
|
||||
"affinityforests",
|
||||
"affinityislands",
|
||||
"affinitymountains",
|
||||
"affinityswamps",
|
||||
"affinitygreencreatures",
|
||||
"cantwin",
|
||||
"nomaxhand",
|
||||
"leyline",
|
||||
"playershroud",
|
||||
"controllershroud",
|
||||
"sunburst",
|
||||
"flanking",
|
||||
"exiledeath",
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,28 +2,32 @@
|
||||
|
||||
#include "MTGGamePhase.h"
|
||||
|
||||
|
||||
MTGGamePhase::MTGGamePhase(int id):ActionElement(id){
|
||||
MTGGamePhase::MTGGamePhase(int id) :
|
||||
ActionElement(id)
|
||||
{
|
||||
animation = 0;
|
||||
currentState = -1;
|
||||
mFont= resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mFont->SetBase(0); // using 2nd font
|
||||
}
|
||||
|
||||
|
||||
void MTGGamePhase::Update(float dt){
|
||||
void MTGGamePhase::Update(float dt)
|
||||
{
|
||||
|
||||
int newState = GameObserver::GetInstance()->getCurrentGamePhase();
|
||||
if (newState != currentState){
|
||||
if (newState != currentState)
|
||||
{
|
||||
activeState = ACTIVE;
|
||||
animation = 4;
|
||||
currentState = newState;
|
||||
}
|
||||
|
||||
|
||||
if (animation > 0){
|
||||
animation -- ;
|
||||
}else{
|
||||
if (animation > 0)
|
||||
{
|
||||
animation--;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeState = INACTIVE;
|
||||
animation = 0;
|
||||
|
||||
@@ -31,9 +35,11 @@ void MTGGamePhase::Update(float dt){
|
||||
|
||||
}
|
||||
|
||||
bool MTGGamePhase::CheckUserInput(JButton key){
|
||||
bool MTGGamePhase::CheckUserInput(JButton key)
|
||||
{
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
if (activeState == INACTIVE){
|
||||
if (activeState == INACTIVE)
|
||||
{
|
||||
JButton trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
|
||||
if ((trigger == key) && game->currentActionPlayer == game->currentlyActing())
|
||||
{
|
||||
@@ -45,11 +51,12 @@ bool MTGGamePhase::CheckUserInput(JButton key){
|
||||
return false;
|
||||
}
|
||||
|
||||
MTGGamePhase * MTGGamePhase::clone() const{
|
||||
MTGGamePhase * MTGGamePhase::clone() const
|
||||
{
|
||||
MTGGamePhase * a = NEW MTGGamePhase(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
ostream& MTGGamePhase::toString(ostream& out) const
|
||||
{
|
||||
|
||||
+432
-318
File diff suppressed because it is too large
Load Diff
+189
-100
@@ -13,179 +13,238 @@
|
||||
|
||||
MTGPack MTGPacks::defaultBooster;
|
||||
|
||||
int MTGPackEntryRandom::addCard(WSrcCards *pool, MTGDeck *to){
|
||||
int MTGPackEntryRandom::addCard(WSrcCards *pool, MTGDeck *to)
|
||||
{
|
||||
int fails = 0;
|
||||
if(!pool) return 1;
|
||||
if (!pool)
|
||||
return 1;
|
||||
WCFilterFactory * ff = WCFilterFactory::GetInstance();
|
||||
WCardFilter * oldf = pool->unhookFilters();
|
||||
pool->addFilter(ff->Construct(filter));
|
||||
fails = pool->addRandomCards(to,copies);
|
||||
fails = pool->addRandomCards(to, copies);
|
||||
pool->clearFilters();
|
||||
pool->addFilter(oldf);
|
||||
return fails;
|
||||
}
|
||||
int MTGPackEntrySpecific::addCard(WSrcCards *pool, MTGDeck *to){
|
||||
int MTGPackEntrySpecific::addCard(WSrcCards *pool, MTGDeck *to)
|
||||
{
|
||||
int fails = 0;
|
||||
//Ignores pool entirely.
|
||||
MTGAllCards * ac = GameApp::collection;
|
||||
|
||||
if(!card) return copies;
|
||||
for(int i=0;i<copies;i++)
|
||||
if (!card)
|
||||
return copies;
|
||||
for (int i = 0; i < copies; i++)
|
||||
to->add(card);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MTGPackSlot::add(WSrcCards * ocean, MTGDeck *to, int carryover){
|
||||
if(!entries.size()) return copies;
|
||||
int MTGPackSlot::add(WSrcCards * ocean, MTGDeck *to, int carryover)
|
||||
{
|
||||
if (!entries.size())
|
||||
return copies;
|
||||
int fails = 0;
|
||||
int amt = copies + carryover;
|
||||
WSrcCards * myPool = NULL;
|
||||
if(pool.size()) myPool = MTGPack::getPool(pool);
|
||||
if(!myPool) myPool = ocean;
|
||||
for(int i=0;i<amt;i++){
|
||||
if (pool.size())
|
||||
myPool = MTGPack::getPool(pool);
|
||||
if (!myPool)
|
||||
myPool = ocean;
|
||||
for (int i = 0; i < amt; i++)
|
||||
{
|
||||
size_t pos = rand() % entries.size();
|
||||
while(pos < entries.size() && entries[pos]->addCard(myPool,to))
|
||||
while (pos < entries.size() && entries[pos]->addCard(myPool, to))
|
||||
pos++;
|
||||
if(pos == entries.size())
|
||||
if (pos == entries.size())
|
||||
fails++;
|
||||
}
|
||||
if(myPool != ocean)
|
||||
if (myPool != ocean)
|
||||
SAFE_DELETE(myPool);
|
||||
return fails;
|
||||
}
|
||||
|
||||
WSrcCards * MTGPack::getPool(string poolstr){
|
||||
WSrcCards * MTGPack::getPool(string poolstr)
|
||||
{
|
||||
WSrcCards * mySrc = NULL;
|
||||
size_t s = poolstr.find("all");
|
||||
WCFilterFactory * ff = WCFilterFactory::GetInstance();
|
||||
|
||||
if(s == string::npos){ //Default to just unlocked cards
|
||||
if (s == string::npos)
|
||||
{ //Default to just unlocked cards
|
||||
mySrc = NEW WSrcUnlockedCards();
|
||||
s = poolstr.find("unlocked");
|
||||
string sub = poolstr;
|
||||
if(s != string::npos) sub = poolstr.substr(s+8);
|
||||
if(sub.size()){
|
||||
if (s != string::npos)
|
||||
sub = poolstr.substr(s + 8);
|
||||
if (sub.size())
|
||||
{
|
||||
mySrc->addFilter(ff->Construct(sub));
|
||||
mySrc->bakeFilters();
|
||||
}
|
||||
}
|
||||
else{ //Use everything.
|
||||
else
|
||||
{ //Use everything.
|
||||
mySrc = NEW WSrcCards();
|
||||
string sub = poolstr.substr(s+3);
|
||||
if(sub.size()){
|
||||
string sub = poolstr.substr(s + 3);
|
||||
if (sub.size())
|
||||
{
|
||||
mySrc->addFilter(ff->Construct(sub));
|
||||
mySrc->loadMatches(GameApp::collection);
|
||||
mySrc->bakeFilters();
|
||||
}else
|
||||
}
|
||||
else
|
||||
mySrc->loadMatches(GameApp::collection);
|
||||
}
|
||||
mySrc->Shuffle();
|
||||
return mySrc;
|
||||
}
|
||||
|
||||
void MTGPackSlot::addEntry(MTGPackEntry*item){
|
||||
if(item)
|
||||
void MTGPackSlot::addEntry(MTGPackEntry*item)
|
||||
{
|
||||
if (item)
|
||||
entries.push_back(item);
|
||||
}
|
||||
int MTGPack::assemblePack(MTGDeck *to){
|
||||
int MTGPack::assemblePack(MTGDeck *to)
|
||||
{
|
||||
int carryover = 0;
|
||||
WSrcCards * p = getPool(pool);
|
||||
if(!p) return -1;
|
||||
if (!p)
|
||||
return -1;
|
||||
p->Shuffle();
|
||||
|
||||
for(size_t i=0;i<slotss.size();i++){
|
||||
carryover = slotss[i]->add(p,to,carryover);
|
||||
if(carryover > 0)
|
||||
for (size_t i = 0; i < slotss.size(); i++)
|
||||
{
|
||||
carryover = slotss[i]->add(p, to, carryover);
|
||||
if (carryover > 0)
|
||||
carryover = carryover; //This means we're failing.
|
||||
}
|
||||
SAFE_DELETE(p);
|
||||
return carryover;
|
||||
}
|
||||
void MTGPack::countCards(){
|
||||
void MTGPack::countCards()
|
||||
{
|
||||
minCards = 0;
|
||||
maxCards = 0;
|
||||
for(size_t i=0;i<slotss.size();i++){
|
||||
for (size_t i = 0; i < slotss.size(); i++)
|
||||
{
|
||||
MTGPackSlot * ps = slotss[i];
|
||||
int top = 0;
|
||||
int bot = 999999999;
|
||||
for(size_t y=0;y<ps->entries.size();y++){
|
||||
for (size_t y = 0; y < ps->entries.size(); y++)
|
||||
{
|
||||
int test = ps->entries[y]->copies * ps->copies;
|
||||
if(test > top) top = test;
|
||||
if(test < bot) bot = test;
|
||||
if (test > top)
|
||||
top = test;
|
||||
if (test < bot)
|
||||
bot = test;
|
||||
}
|
||||
maxCards += top;
|
||||
minCards += bot;
|
||||
}
|
||||
}
|
||||
void MTGPack::load(string filename){
|
||||
void MTGPack::load(string filename)
|
||||
{
|
||||
//TODO Placeholder until XML format available.
|
||||
TiXmlDocument packfile(filename.c_str());
|
||||
if(!packfile.LoadFile())
|
||||
if (!packfile.LoadFile())
|
||||
return;
|
||||
TiXmlHandle hDoc(&packfile);
|
||||
TiXmlElement * pPack;
|
||||
pPack = hDoc.FirstChildElement().Element();
|
||||
if(!pPack ){
|
||||
if (!pPack)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
//root should be "pack"
|
||||
string tag = pPack->Value();
|
||||
std::transform(tag.begin(),tag.end(),tag.begin(),::tolower);
|
||||
if(tag != "pack")
|
||||
std::transform(tag.begin(), tag.end(), tag.begin(), ::tolower);
|
||||
if (tag != "pack")
|
||||
return;
|
||||
//After validating, handle actual loading.
|
||||
TiXmlElement * pSlot;
|
||||
const char * holder = NULL;
|
||||
holder = pPack->Attribute("price");
|
||||
if(holder) price = atoi(holder); else price = Constants::PRICE_BOOSTER;
|
||||
if (holder)
|
||||
price = atoi(holder);
|
||||
else
|
||||
price = Constants::PRICE_BOOSTER;
|
||||
holder = pPack->Attribute("pool");
|
||||
if(holder) pool = holder; else pool = "";
|
||||
if (holder)
|
||||
pool = holder;
|
||||
else
|
||||
pool = "";
|
||||
holder = pPack->Attribute("type");
|
||||
if(holder){
|
||||
if (holder)
|
||||
{
|
||||
type = holder;
|
||||
}else type = "Booster";
|
||||
}
|
||||
else
|
||||
type = "Booster";
|
||||
holder = pPack->Attribute("name");
|
||||
if(holder) name = holder; else name = "Special";
|
||||
if (holder)
|
||||
name = holder;
|
||||
else
|
||||
name = "Special";
|
||||
holder = pPack->Attribute("requires");
|
||||
if(holder) check = holder;
|
||||
if (holder)
|
||||
check = holder;
|
||||
holder = pPack->Attribute("sort");
|
||||
if(holder) sort = holder; else sort = "";
|
||||
std::transform(sort.begin(),sort.end(),sort.begin(),::tolower);
|
||||
if (holder)
|
||||
sort = holder;
|
||||
else
|
||||
sort = "";
|
||||
std::transform(sort.begin(), sort.end(), sort.begin(), ::tolower);
|
||||
|
||||
for (pSlot=pPack->FirstChildElement();pSlot!=NULL;pSlot=pSlot->NextSiblingElement()){
|
||||
for (pSlot = pPack->FirstChildElement(); pSlot != NULL; pSlot = pSlot->NextSiblingElement())
|
||||
{
|
||||
TiXmlElement * pEntry;
|
||||
//Load slot.
|
||||
tag = pSlot->Value();
|
||||
std::transform(tag.begin(),tag.end(),tag.begin(),::tolower);
|
||||
if(tag != "slot") continue;
|
||||
std::transform(tag.begin(), tag.end(), tag.begin(), ::tolower);
|
||||
if (tag != "slot")
|
||||
continue;
|
||||
MTGPackSlot * s = NEW MTGPackSlot();
|
||||
slotss.push_back(s);
|
||||
holder = pSlot->Attribute("copies");
|
||||
if(holder) s->copies = atoi(holder);
|
||||
else s->copies = 1;
|
||||
if (holder)
|
||||
s->copies = atoi(holder);
|
||||
else
|
||||
s->copies = 1;
|
||||
holder = pSlot->Attribute("pool");
|
||||
if(holder) s->pool = holder;
|
||||
if (holder)
|
||||
s->pool = holder;
|
||||
|
||||
for(pEntry = pSlot->FirstChildElement();pEntry!=NULL;pEntry=pEntry->NextSiblingElement()){
|
||||
for (pEntry = pSlot->FirstChildElement(); pEntry != NULL; pEntry = pEntry->NextSiblingElement())
|
||||
{
|
||||
tag = pEntry->Value();
|
||||
std::transform(tag.begin(),tag.end(),tag.begin(),::tolower);
|
||||
if(tag == "card"){ //Load specific card
|
||||
std::transform(tag.begin(), tag.end(), tag.begin(), ::tolower);
|
||||
if (tag == "card")
|
||||
{ //Load specific card
|
||||
MTGPackEntrySpecific * es = NEW MTGPackEntrySpecific();
|
||||
holder = pEntry->Attribute("copies");
|
||||
if(holder) es->copies = atoi(holder);
|
||||
else es->copies = 1;
|
||||
if (holder)
|
||||
es->copies = atoi(holder);
|
||||
else
|
||||
es->copies = 1;
|
||||
es->card = GameApp::collection->getCardByName(pEntry->Value());
|
||||
s->addEntry(es);
|
||||
}else if(tag == "random_card"){ //Load random card
|
||||
}
|
||||
else if (tag == "random_card")
|
||||
{ //Load random card
|
||||
MTGPackEntryRandom * er = NEW MTGPackEntryRandom();
|
||||
holder = pEntry->Attribute("copies");
|
||||
if(holder) er->copies = atoi(holder);
|
||||
else er->copies = 1;
|
||||
if (holder)
|
||||
er->copies = atoi(holder);
|
||||
else
|
||||
er->copies = 1;
|
||||
const char * text = pEntry->GetText();
|
||||
if(text) er->filter = text;
|
||||
if (text)
|
||||
er->filter = text;
|
||||
s->addEntry(er);
|
||||
}else if(tag == "nothing"){
|
||||
}
|
||||
else if (tag == "nothing")
|
||||
{
|
||||
MTGPackEntryNothing * nt = NEW MTGPackEntryNothing();
|
||||
s->addEntry(nt);
|
||||
}
|
||||
@@ -195,42 +254,57 @@ void MTGPack::load(string filename){
|
||||
countCards();
|
||||
return;
|
||||
}
|
||||
MTGPackSlot::~MTGPackSlot(){
|
||||
for(size_t t=0;t<entries.size();t++){
|
||||
MTGPackSlot::~MTGPackSlot()
|
||||
{
|
||||
for (size_t t = 0; t < entries.size(); t++)
|
||||
{
|
||||
SAFE_DELETE(entries[t]);
|
||||
}
|
||||
entries.clear();
|
||||
}
|
||||
MTGPack::~MTGPack(){
|
||||
for(size_t t=0;t<slotss.size();t++){
|
||||
MTGPack::~MTGPack()
|
||||
{
|
||||
for (size_t t = 0; t < slotss.size(); t++)
|
||||
{
|
||||
SAFE_DELETE(slotss[t]);
|
||||
}
|
||||
slotss.clear();
|
||||
}
|
||||
MTGPacks::~MTGPacks(){
|
||||
for(size_t t=0;t<packs.size();t++){
|
||||
MTGPacks::~MTGPacks()
|
||||
{
|
||||
for (size_t t = 0; t < packs.size(); t++)
|
||||
{
|
||||
SAFE_DELETE(packs[t]);
|
||||
}
|
||||
packs.clear();
|
||||
}
|
||||
MTGPack * MTGPacks::randomPack(int key){
|
||||
if(!key) key = rand();
|
||||
MTGPack * MTGPacks::randomPack(int key)
|
||||
{
|
||||
if (!key)
|
||||
key = rand();
|
||||
size_t s = packs.size();
|
||||
if(!s) return NULL;
|
||||
return packs[key%s];
|
||||
if (!s)
|
||||
return NULL;
|
||||
return packs[key % s];
|
||||
}
|
||||
void MTGPacks::loadAll(){
|
||||
void MTGPacks::loadAll()
|
||||
{
|
||||
DIR *mDip = opendir(JGE_GET_RES("packs/").c_str());
|
||||
struct dirent *mDit;
|
||||
if(!mDip) return;
|
||||
if (!mDip)
|
||||
return;
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
while ((mDit = readdir(mDip)))
|
||||
{
|
||||
char myFilename[4096];
|
||||
sprintf(myFilename, JGE_GET_RES("packs/%s").c_str(), mDit->d_name);
|
||||
if(mDit->d_name[0] == '.') continue;
|
||||
if(!strcmp(mDit->d_name,"default_booster.txt")) continue;
|
||||
if (mDit->d_name[0] == '.')
|
||||
continue;
|
||||
if (!strcmp(mDit->d_name, "default_booster.txt"))
|
||||
continue;
|
||||
MTGPack * p = NEW MTGPack(myFilename);
|
||||
if(!p->isValid()){
|
||||
if (!p->isValid())
|
||||
{
|
||||
SAFE_DELETE(p);
|
||||
continue;
|
||||
}
|
||||
@@ -238,24 +312,28 @@ void MTGPacks::loadAll(){
|
||||
}
|
||||
closedir(mDip);
|
||||
}
|
||||
string MTGPack::getName(){
|
||||
string MTGPack::getName()
|
||||
{
|
||||
string n = _(name);
|
||||
string t = _(type);
|
||||
char buf[1024];
|
||||
if(minCards != maxCards)
|
||||
sprintf(buf,"%s %s (%i-%i cards)",n.c_str(),t.c_str(),minCards,maxCards);
|
||||
if (minCards != maxCards)
|
||||
sprintf(buf, "%s %s (%i-%i cards)", n.c_str(), t.c_str(), minCards, maxCards);
|
||||
else
|
||||
sprintf(buf,"%s %s (%i cards)",n.c_str(),t.c_str(),maxCards);
|
||||
sprintf(buf, "%s %s (%i cards)", n.c_str(), t.c_str(), maxCards);
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool MTGPack::meetsRequirements(){
|
||||
bool MTGPack::meetsRequirements()
|
||||
{
|
||||
bool unlocked = true;
|
||||
WCFilterFactory * ff = WCFilterFactory::GetInstance();
|
||||
WSrcCards * myC = getPool(pool);
|
||||
if(!myC || myC->Size() < maxCards) unlocked = false; //Top pool lacks cards.
|
||||
if (!myC || myC->Size() < maxCards)
|
||||
unlocked = false; //Top pool lacks cards.
|
||||
SAFE_DELETE(myC);
|
||||
if(!check.size() || !unlocked) return unlocked;
|
||||
if (!check.size() || !unlocked)
|
||||
return unlocked;
|
||||
myC = NEW WSrcUnlockedCards(); //Requirements are independent of pool;
|
||||
WCardFilter * cf = ff->Construct(check);
|
||||
unlocked = !myC->isEmptySet(cf); //Quick check for empty set status.
|
||||
@@ -264,9 +342,11 @@ bool MTGPack::meetsRequirements(){
|
||||
return unlocked;
|
||||
}
|
||||
|
||||
bool MTGPack::isUnlocked(){
|
||||
if(unlockStatus == 0){
|
||||
if(meetsRequirements())
|
||||
bool MTGPack::isUnlocked()
|
||||
{
|
||||
if (unlockStatus == 0)
|
||||
{
|
||||
if (meetsRequirements())
|
||||
unlockStatus = 1;
|
||||
else
|
||||
unlockStatus = -1;
|
||||
@@ -274,23 +354,30 @@ bool MTGPack::isUnlocked(){
|
||||
return (unlockStatus > 0);
|
||||
}
|
||||
|
||||
MTGPack * MTGPacks::getDefault(){
|
||||
if(!defaultBooster.isValid()){
|
||||
MTGPack * MTGPacks::getDefault()
|
||||
{
|
||||
if (!defaultBooster.isValid())
|
||||
{
|
||||
defaultBooster.load(JGE_GET_RES("packs/default_booster.txt"));
|
||||
defaultBooster.unlockStatus = 1;
|
||||
if(!defaultBooster.isValid()){
|
||||
MTGPackSlot * ps = NEW MTGPackSlot(); ps->copies = 1;
|
||||
if (!defaultBooster.isValid())
|
||||
{
|
||||
MTGPackSlot * ps = NEW MTGPackSlot();
|
||||
ps->copies = 1;
|
||||
ps->addEntry(NEW MTGPackEntryRandom("rarity:mythic;"));
|
||||
for(int i=0;i<7;i++)
|
||||
for (int i = 0; i < 7; i++)
|
||||
ps->addEntry(NEW MTGPackEntryRandom("rarity:rare;"));
|
||||
defaultBooster.slotss.push_back(ps);
|
||||
ps = NEW MTGPackSlot(); ps->copies = 3;
|
||||
ps = NEW MTGPackSlot();
|
||||
ps->copies = 3;
|
||||
ps->addEntry(NEW MTGPackEntryRandom("rarity:uncommon;"));
|
||||
defaultBooster.slotss.push_back(ps);
|
||||
ps = NEW MTGPackSlot(); ps->copies = 1;
|
||||
ps = NEW MTGPackSlot();
|
||||
ps->copies = 1;
|
||||
ps->addEntry(NEW MTGPackEntryRandom("rarity:land;&type:basic;"));
|
||||
defaultBooster.slotss.push_back(ps);
|
||||
ps = NEW MTGPackSlot(); ps->copies = 10;
|
||||
ps = NEW MTGPackSlot();
|
||||
ps->copies = 10;
|
||||
ps->addEntry(NEW MTGPackEntryRandom("rarity:common;"));
|
||||
defaultBooster.slotss.push_back(ps);
|
||||
defaultBooster.bValid = true;
|
||||
@@ -300,9 +387,11 @@ MTGPack * MTGPacks::getDefault(){
|
||||
return &defaultBooster;
|
||||
}
|
||||
|
||||
void MTGPacks::refreshUnlocked(){
|
||||
for(size_t t=0;t<packs.size();t++){
|
||||
if(packs[t]->unlockStatus < 0)
|
||||
void MTGPacks::refreshUnlocked()
|
||||
{
|
||||
for (size_t t = 0; t < packs.size(); t++)
|
||||
{
|
||||
if (packs[t]->unlockStatus < 0)
|
||||
packs[t]->unlockStatus = 0;
|
||||
}
|
||||
}
|
||||
|
||||
+1154
-486
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,22 @@
|
||||
#include "MTGSpellStack.h"
|
||||
|
||||
MTGSpellStack::MTGSpellStack(){
|
||||
MTGSpellStack::MTGSpellStack()
|
||||
{
|
||||
cursor = -1;
|
||||
}
|
||||
|
||||
void MTGSpellStack::addSpell(Ability * ability){
|
||||
void MTGSpellStack::addSpell(Ability * ability)
|
||||
{
|
||||
cursor++;
|
||||
spellStack[cursor] ability;
|
||||
}
|
||||
|
||||
int MTGSpellStack::resolve(){
|
||||
int MTGSpellStack::resolve()
|
||||
{
|
||||
if (cursor < 0)
|
||||
return 0;
|
||||
int result = cursor;
|
||||
cursor--;
|
||||
(spellStack[cursor + 1])->resolve();
|
||||
return (result+1);
|
||||
return (result + 1);
|
||||
}
|
||||
|
||||
@@ -3,15 +3,18 @@
|
||||
//---------------------------------------------
|
||||
//Card Instance
|
||||
//--------------------------------------------
|
||||
MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to): model(card){
|
||||
MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to) :
|
||||
model(card)
|
||||
{
|
||||
belongs_to = _belongs_to;
|
||||
}
|
||||
|
||||
int MTGCardInstance::isInPlay(){
|
||||
int MTGCardInstance::isInPlay()
|
||||
{
|
||||
return belongs_to->isInPlay(this);
|
||||
}
|
||||
|
||||
|
||||
JQuad * MTGCardInstance::getQuad(TexturesCache * cache){
|
||||
JQuad * MTGCardInstance::getQuad(TexturesCache * cache)
|
||||
{
|
||||
return model->getQuad(cache);
|
||||
}
|
||||
|
||||
+331
-182
@@ -9,73 +9,103 @@
|
||||
#include "WEvent.h"
|
||||
#include "MTGAbility.h"
|
||||
|
||||
|
||||
ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstance * c){
|
||||
ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstance * c)
|
||||
{
|
||||
ManaCost * manaCost;
|
||||
if (_manaCost){
|
||||
if (_manaCost)
|
||||
{
|
||||
manaCost = _manaCost;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
manaCost = NEW ManaCost();
|
||||
}
|
||||
int state = 0;
|
||||
size_t start = 0;
|
||||
size_t end = 0;
|
||||
while (!s.empty() && state != -1){
|
||||
switch(state){
|
||||
while (!s.empty() && state != -1)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
start = s.find_first_of("{");
|
||||
if (start == string::npos){
|
||||
if (start == string::npos)
|
||||
{
|
||||
return manaCost;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
end = s.find_first_of("}");
|
||||
if (end == string::npos){
|
||||
if (end == string::npos)
|
||||
{
|
||||
state = -1;
|
||||
}else{
|
||||
string value = s.substr(start+1, end - 1 - start);
|
||||
}
|
||||
else
|
||||
{
|
||||
string value = s.substr(start + 1, end - 1 - start);
|
||||
|
||||
if (value == "u") {
|
||||
if (value == "u")
|
||||
{
|
||||
manaCost->add(Constants::MTG_COLOR_BLUE, 1);
|
||||
} else if (value == "b") {
|
||||
}
|
||||
else if (value == "b")
|
||||
{
|
||||
manaCost->add(Constants::MTG_COLOR_BLACK, 1);
|
||||
} else if (value == "w") {
|
||||
}
|
||||
else if (value == "w")
|
||||
{
|
||||
manaCost->add(Constants::MTG_COLOR_WHITE, 1);
|
||||
} else if (value == "g") {
|
||||
}
|
||||
else if (value == "g")
|
||||
{
|
||||
manaCost->add(Constants::MTG_COLOR_GREEN, 1);
|
||||
} else if (value == "r") {
|
||||
}
|
||||
else if (value == "r")
|
||||
{
|
||||
manaCost->add(Constants::MTG_COLOR_RED, 1);
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//Parse target for extraCosts
|
||||
TargetChooserFactory tcf;
|
||||
TargetChooser * tc = NULL;
|
||||
size_t target_start = value.find("(");
|
||||
size_t target_end = value.find(")");
|
||||
if (target_start!=string::npos && target_end!=string::npos){
|
||||
string target = value.substr(target_start+1, target_end-1 - target_start);
|
||||
tc = tcf.createTargetChooser(target,c);
|
||||
if (target_start != string::npos && target_end != string::npos)
|
||||
{
|
||||
string target = value.substr(target_start + 1, target_end - 1 - target_start);
|
||||
tc = tcf.createTargetChooser(target, c);
|
||||
}
|
||||
|
||||
//switch on the first letter. If two costs share their first letter, add an "if" within the switch
|
||||
switch(value[0]) {
|
||||
switch (value[0])
|
||||
{
|
||||
case 'x':
|
||||
manaCost->x();
|
||||
break;
|
||||
case 't': //Tap
|
||||
if (value == "t"){
|
||||
if (value == "t")
|
||||
{
|
||||
//default Tap is handled outside of Manacost
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
manaCost->addExtraCost(NEW TapTargetCost(tc));
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (value == "s2l") { //Send To Library Cost (move from anywhere to Library)
|
||||
if (value == "s2l")
|
||||
{ //Send To Library Cost (move from anywhere to Library)
|
||||
manaCost->addExtraCost(NEW ToLibraryCost(tc));
|
||||
} else { //Sacrifice
|
||||
}
|
||||
else
|
||||
{ //Sacrifice
|
||||
manaCost->addExtraCost(NEW SacrificeCost(tc));
|
||||
}
|
||||
break;
|
||||
@@ -86,16 +116,22 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
|
||||
manaCost->addExtraCost(NEW BounceTargetCost(tc));
|
||||
break;
|
||||
case 'l':
|
||||
if (value == "l2e") { //Mill to exile yourself as a cost (Library 2 Exile)
|
||||
if (value == "l2e")
|
||||
{ //Mill to exile yourself as a cost (Library 2 Exile)
|
||||
manaCost->addExtraCost(NEW MillExileCost(tc));
|
||||
} else { //Life cost
|
||||
}
|
||||
else
|
||||
{ //Life cost
|
||||
manaCost->addExtraCost(NEW LifeCost(tc));
|
||||
}
|
||||
break;
|
||||
case 'd': //DiscardRandom cost
|
||||
if (value == "d"){
|
||||
if (value == "d")
|
||||
{
|
||||
manaCost->addExtraCost(NEW DiscardRandomCost(tc));
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
manaCost->addExtraCost(NEW DiscardCost(tc));
|
||||
}
|
||||
break;
|
||||
@@ -112,24 +148,27 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
|
||||
size_t counter_start = value.find("(");
|
||||
size_t counter_end = value.find(")", counter_start);
|
||||
AbilityFactory abf;
|
||||
string counterString = value.substr(counter_start+1,counter_end-counter_start-1);
|
||||
Counter * counter = abf.parseCounter(counterString,c);
|
||||
size_t separator = value.find(",",counter_start);
|
||||
string counterString = value.substr(counter_start + 1, counter_end - counter_start - 1);
|
||||
Counter * counter = abf.parseCounter(counterString, c);
|
||||
size_t separator = value.find(",", counter_start);
|
||||
size_t separator2 = string::npos;
|
||||
if (separator != string::npos) {
|
||||
separator2 = value.find(",",separator + 1);
|
||||
if (separator != string::npos)
|
||||
{
|
||||
separator2 = value.find(",", separator + 1);
|
||||
}
|
||||
SAFE_DELETE(tc);
|
||||
size_t target_start = string::npos;
|
||||
if (separator2 != string::npos) {
|
||||
target_start = value.find(",",separator2+1);
|
||||
if (separator2 != string::npos)
|
||||
{
|
||||
target_start = value.find(",", separator2 + 1);
|
||||
}
|
||||
size_t target_end = counter_end;
|
||||
if (target_start!=string::npos && target_end!=string::npos){
|
||||
string target = value.substr(target_start+1, target_end-1 - target_start);
|
||||
tc = tcf.createTargetChooser(target,c);
|
||||
if (target_start != string::npos && target_end != string::npos)
|
||||
{
|
||||
string target = value.substr(target_start + 1, target_end - 1 - target_start);
|
||||
tc = tcf.createTargetChooser(target, c);
|
||||
}
|
||||
manaCost->addExtraCost(NEW CounterCost(counter,tc));
|
||||
manaCost->addExtraCost(NEW CounterCost(counter, tc));
|
||||
break;
|
||||
}
|
||||
default: //uncolored cost and hybrid costs
|
||||
@@ -137,15 +176,22 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
|
||||
int intvalue = atoi(value.c_str());
|
||||
int colors[2];
|
||||
int values[2];
|
||||
if (intvalue < 10 && value.size() > 1){
|
||||
for (int i = 0; i < 2; i++){
|
||||
if (intvalue < 10 && value.size() > 1)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
char c = value[i];
|
||||
if (c >='0' && c <='9'){
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
colors[i] = Constants::MTG_COLOR_ARTIFACT;
|
||||
values[i] = c - '0';
|
||||
}else{
|
||||
for (int j = 0; j < Constants::MTG_NB_COLORS; j++){
|
||||
if (c == Constants::MTGColorChars[j]){
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < Constants::MTG_NB_COLORS; j++)
|
||||
{
|
||||
if (c == Constants::MTGColorChars[j])
|
||||
{
|
||||
colors[i] = j;
|
||||
values[i] = 1;
|
||||
}
|
||||
@@ -153,7 +199,9 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
|
||||
}
|
||||
}
|
||||
manaCost->addHybrid(colors[0], values[0], colors[1], values[1]);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
manaCost->add(Constants::MTG_COLOR_ARTIFACT, intvalue);
|
||||
}
|
||||
break;
|
||||
@@ -171,56 +219,62 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
ManaCost::ManaCost(){
|
||||
ManaCost::ManaCost()
|
||||
{
|
||||
init();
|
||||
}
|
||||
ManaCost::ManaCost(int _cost[], int nb_elems){
|
||||
ManaCost::ManaCost(int _cost[], int nb_elems)
|
||||
{
|
||||
init();
|
||||
int i;
|
||||
int total = nb_elems;
|
||||
for (i = 0; i < total; i++){
|
||||
cost[_cost[i*2]] = _cost[i*2 + 1];
|
||||
for (i = 0; i < total; i++)
|
||||
{
|
||||
cost[_cost[i * 2]] = _cost[i * 2 + 1];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ManaCost::ManaCost(ManaCost * _manaCost){
|
||||
ManaCost::ManaCost(ManaCost * _manaCost)
|
||||
{
|
||||
init();
|
||||
int i;
|
||||
for (i=0; i<= Constants::MTG_NB_COLORS; i++){
|
||||
for (i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
cost[i] = _manaCost->getCost(i);
|
||||
}
|
||||
}
|
||||
|
||||
ManaCost::~ManaCost(){
|
||||
for (unsigned int i = 0; i < nbhybrids ; i++){
|
||||
ManaCost::~ManaCost()
|
||||
{
|
||||
for (unsigned int i = 0; i < nbhybrids; i++)
|
||||
{
|
||||
SAFE_DELETE(hybrids[i]);
|
||||
}
|
||||
|
||||
SAFE_DELETE(extraCosts);
|
||||
|
||||
SAFE_DELETE(kicker);
|
||||
|
||||
SAFE_DELETE(alternative);
|
||||
|
||||
SAFE_DELETE(BuyBack);
|
||||
|
||||
SAFE_DELETE(FlashBack);
|
||||
|
||||
SAFE_DELETE(Retrace);
|
||||
}
|
||||
|
||||
void ManaCost::x(){
|
||||
void ManaCost::x()
|
||||
{
|
||||
cost[Constants::MTG_NB_COLORS] = 1;
|
||||
}
|
||||
|
||||
int ManaCost::hasX(){
|
||||
int ManaCost::hasX()
|
||||
{
|
||||
return cost[Constants::MTG_NB_COLORS];
|
||||
}
|
||||
|
||||
void ManaCost::init(){
|
||||
void ManaCost::init()
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<= Constants::MTG_NB_COLORS; i++){
|
||||
for (i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
cost[i] = 0;
|
||||
}
|
||||
nbhybrids = 0;
|
||||
@@ -233,165 +287,214 @@ void ManaCost::init(){
|
||||
Retrace = NULL;
|
||||
}
|
||||
|
||||
|
||||
void ManaCost::copy(ManaCost * _manaCost){
|
||||
if (!_manaCost) return;
|
||||
for (unsigned int i = 0; i <= Constants::MTG_NB_COLORS; i++){
|
||||
void ManaCost::copy(ManaCost * _manaCost)
|
||||
{
|
||||
if (!_manaCost)
|
||||
return;
|
||||
for (unsigned int i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
cost[i] = _manaCost->getCost(i);
|
||||
}
|
||||
for (unsigned int i = 0; i < nbhybrids ; i++){
|
||||
for (unsigned int i = 0; i < nbhybrids; i++)
|
||||
{
|
||||
SAFE_DELETE(hybrids[i]);
|
||||
}
|
||||
for (unsigned int i = 0; i < _manaCost->nbhybrids; i++){
|
||||
for (unsigned int i = 0; i < _manaCost->nbhybrids; i++)
|
||||
{
|
||||
hybrids[i] = NEW ManaCostHybrid((*_manaCost->hybrids[i]));
|
||||
}
|
||||
nbhybrids = _manaCost->nbhybrids;
|
||||
|
||||
SAFE_DELETE(extraCosts);
|
||||
if (_manaCost->extraCosts){
|
||||
if (_manaCost->extraCosts)
|
||||
{
|
||||
extraCosts = _manaCost->extraCosts->clone();
|
||||
}
|
||||
|
||||
SAFE_DELETE(kicker);
|
||||
if (_manaCost->kicker){
|
||||
if (_manaCost->kicker)
|
||||
{
|
||||
kicker = NEW ManaCost();
|
||||
kicker->copy(_manaCost->kicker);
|
||||
}
|
||||
SAFE_DELETE(alternative);
|
||||
if (_manaCost->alternative){
|
||||
if (_manaCost->alternative)
|
||||
{
|
||||
alternative = NEW ManaCost();
|
||||
alternative->copy(_manaCost->alternative);
|
||||
}
|
||||
SAFE_DELETE(BuyBack);
|
||||
if (_manaCost->BuyBack){
|
||||
if (_manaCost->BuyBack)
|
||||
{
|
||||
BuyBack = NEW ManaCost();
|
||||
BuyBack->copy(_manaCost->BuyBack);
|
||||
}
|
||||
SAFE_DELETE(FlashBack);
|
||||
if (_manaCost->FlashBack){
|
||||
if (_manaCost->FlashBack)
|
||||
{
|
||||
FlashBack = NEW ManaCost();
|
||||
FlashBack->copy(_manaCost->FlashBack);
|
||||
}
|
||||
SAFE_DELETE(Retrace);
|
||||
if (_manaCost->Retrace){
|
||||
if (_manaCost->Retrace)
|
||||
{
|
||||
Retrace = NEW ManaCost();
|
||||
Retrace->copy(_manaCost->Retrace);
|
||||
}
|
||||
}
|
||||
|
||||
int ManaCost::getCost(int color){
|
||||
int ManaCost::getCost(int color)
|
||||
{
|
||||
return cost[color];
|
||||
}
|
||||
|
||||
ManaCostHybrid * ManaCost::getHybridCost(unsigned int i){
|
||||
if (nbhybrids <= i) return NULL;
|
||||
ManaCostHybrid * ManaCost::getHybridCost(unsigned int i)
|
||||
{
|
||||
if (nbhybrids <= i)
|
||||
return NULL;
|
||||
return hybrids[i];
|
||||
}
|
||||
|
||||
int ManaCost::hasColor(int color){
|
||||
if (cost[color]) return 1;
|
||||
for (unsigned int i = 0; i < nbhybrids; i++){
|
||||
if (hybrids[i]->hasColor(color)) return 1;
|
||||
int ManaCost::hasColor(int color)
|
||||
{
|
||||
if (cost[color])
|
||||
return 1;
|
||||
for (unsigned int i = 0; i < nbhybrids; i++)
|
||||
{
|
||||
if (hybrids[i]->hasColor(color))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManaCost::isNull(){
|
||||
if (getConvertedCost()) return 0;
|
||||
if (extraCosts) return 0;
|
||||
int ManaCost::isNull()
|
||||
{
|
||||
if (getConvertedCost())
|
||||
return 0;
|
||||
if (extraCosts)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ManaCost::getConvertedCost(){
|
||||
int ManaCost::getConvertedCost()
|
||||
{
|
||||
int result = 0;
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
result += cost[i];
|
||||
}
|
||||
for (unsigned int i = 0; i < nbhybrids; i++){
|
||||
result+= hybrids[i]->getConvertedCost();
|
||||
for (unsigned int i = 0; i < nbhybrids; i++)
|
||||
{
|
||||
result += hybrids[i]->getConvertedCost();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ManaCost::remove(int color, int value){
|
||||
int ManaCost::remove(int color, int value)
|
||||
{
|
||||
cost[color] -= value;
|
||||
if(cost[color] < 0){cost[color] = 0;}
|
||||
if (cost[color] < 0)
|
||||
{
|
||||
cost[color] = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ManaCost::add(int color, int value){
|
||||
if(value < 0) value = 0;
|
||||
int ManaCost::add(int color, int value)
|
||||
{
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
cost[color] += value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ManaCost::add(ManaCost * _cost){
|
||||
if(!_cost) return 0;
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
cost[i]+= _cost->getCost(i);
|
||||
int ManaCost::add(ManaCost * _cost)
|
||||
{
|
||||
if (!_cost)
|
||||
return 0;
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
cost[i] += _cost->getCost(i);
|
||||
}
|
||||
for (unsigned int i = 0; i < _cost->nbhybrids; i++){
|
||||
for (unsigned int i = 0; i < _cost->nbhybrids; i++)
|
||||
{
|
||||
hybrids[nbhybrids] = NEW ManaCostHybrid((*_cost->hybrids[i]));
|
||||
nbhybrids++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
string ManaCost::toString(){
|
||||
string ManaCost::toString()
|
||||
{
|
||||
return "ManaCost - Todo";
|
||||
}
|
||||
|
||||
|
||||
int ManaCost::addHybrid(int c1, int v1, int c2, int v2){
|
||||
ManaCostHybrid * h = NEW ManaCostHybrid(c1,v1,c2,v2);
|
||||
int ManaCost::addHybrid(int c1, int v1, int c2, int v2)
|
||||
{
|
||||
ManaCostHybrid * h = NEW ManaCostHybrid(c1, v1, c2, v2);
|
||||
hybrids[nbhybrids] = h;
|
||||
nbhybrids++;
|
||||
return nbhybrids;
|
||||
}
|
||||
|
||||
int ManaCost::addExtraCost(ExtraCost * _cost){
|
||||
if (!extraCosts) extraCosts = NEW ExtraCosts();
|
||||
int ManaCost::addExtraCost(ExtraCost * _cost)
|
||||
{
|
||||
if (!extraCosts)
|
||||
extraCosts = NEW ExtraCosts();
|
||||
extraCosts->costs.push_back(_cost);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int ManaCost::isExtraPaymentSet(){
|
||||
if (!extraCosts) return 1;
|
||||
int ManaCost::isExtraPaymentSet()
|
||||
{
|
||||
if (!extraCosts)
|
||||
return 1;
|
||||
return extraCosts->isPaymentSet();
|
||||
}
|
||||
|
||||
int ManaCost::canPayExtra(){
|
||||
if (!extraCosts) return 1;
|
||||
int ManaCost::canPayExtra()
|
||||
{
|
||||
if (!extraCosts)
|
||||
return 1;
|
||||
return extraCosts->canPay();
|
||||
}
|
||||
|
||||
int ManaCost::doPayExtra(){
|
||||
if (!extraCosts) return 0;
|
||||
int ManaCost::doPayExtra()
|
||||
{
|
||||
if (!extraCosts)
|
||||
return 0;
|
||||
return extraCosts->doPay(); //TODO reset ?
|
||||
}
|
||||
|
||||
int ManaCost::setExtraCostsAction(MTGAbility * action, MTGCardInstance * card){
|
||||
if (extraCosts) extraCosts->setAction(action, card);
|
||||
int ManaCost::setExtraCostsAction(MTGAbility * action, MTGCardInstance * card)
|
||||
{
|
||||
if (extraCosts)
|
||||
extraCosts->setAction(action, card);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ManaCost::pay(ManaCost * _cost){
|
||||
int ManaCost::pay(ManaCost * _cost)
|
||||
{
|
||||
int result = MANA_PAID;
|
||||
ManaCost * toPay = NEW ManaCost();
|
||||
toPay->copy(_cost);
|
||||
|
||||
if (toPay->kicker){
|
||||
if (toPay->kicker)
|
||||
{
|
||||
toPay->add(toPay->kicker);
|
||||
if (!canAfford(toPay)){
|
||||
if (!canAfford(toPay))
|
||||
{
|
||||
toPay->copy(_cost);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
result = MANA_PAID_WITH_KICKER;
|
||||
}
|
||||
}
|
||||
|
||||
ManaCost * diff = Diff(toPay);
|
||||
for (int i=0; i < Constants::MTG_NB_COLORS; i++){
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
cost[i] = diff->getCost(i);
|
||||
}
|
||||
delete diff;
|
||||
@@ -401,20 +504,25 @@ int ManaCost::pay(ManaCost * _cost){
|
||||
}
|
||||
|
||||
//return 1 if _cost can be paid with current data, 0 otherwise
|
||||
int ManaCost::canAfford(ManaCost * _cost){
|
||||
int ManaCost::canAfford(ManaCost * _cost)
|
||||
{
|
||||
ManaCost * diff = Diff(_cost);
|
||||
int positive = diff->isPositive();
|
||||
delete diff;
|
||||
if (positive){
|
||||
if (positive)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManaCost::isPositive(){
|
||||
for (int i=0; i < Constants::MTG_NB_COLORS; i++){
|
||||
int ManaCost::isPositive()
|
||||
{
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
|
||||
if (cost[i] < 0){
|
||||
if (cost[i] < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -422,88 +530,111 @@ int ManaCost::isPositive(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ManaCost::randomDiffHybrids(ManaCost * _cost, int diff[]){
|
||||
void ManaCost::randomDiffHybrids(ManaCost * _cost, int diff[])
|
||||
{
|
||||
int _nbhybrids = _cost->nbhybrids;
|
||||
for (int i = 0; i < _nbhybrids; i++){
|
||||
for (int i = 0; i < _nbhybrids; i++)
|
||||
{
|
||||
ManaCostHybrid * h = _cost->hybrids[i];
|
||||
diff[h->color1 * 2 +1]-= h->value1;
|
||||
diff[h->color1 * 2 + 1] -= h->value1;
|
||||
}
|
||||
}
|
||||
|
||||
int ManaCost::tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]){
|
||||
if (!_nbhybrids) return 1;
|
||||
int ManaCost::tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[])
|
||||
{
|
||||
if (!_nbhybrids)
|
||||
return 1;
|
||||
int result = 0;
|
||||
ManaCostHybrid * h = _hybrids[_nbhybrids -1];
|
||||
if (diff[h->color1 * 2 +1] >= h->value1){
|
||||
diff[h->color1 * 2 +1]-= h->value1;
|
||||
result = tryToPayHybrids(_hybrids,_nbhybrids -1, diff);
|
||||
if (result) return 1;
|
||||
diff[h->color1 * 2 +1]+= h->value1;
|
||||
ManaCostHybrid * h = _hybrids[_nbhybrids - 1];
|
||||
if (diff[h->color1 * 2 + 1] >= h->value1)
|
||||
{
|
||||
diff[h->color1 * 2 + 1] -= h->value1;
|
||||
result = tryToPayHybrids(_hybrids, _nbhybrids - 1, diff);
|
||||
if (result)
|
||||
return 1;
|
||||
diff[h->color1 * 2 + 1] += h->value1;
|
||||
}
|
||||
if (diff[h->color2 * 2 +1] >= h->value2){
|
||||
diff[h->color2 * 2 +1]-= h->value2;
|
||||
result = tryToPayHybrids(_hybrids,_nbhybrids -1, diff);
|
||||
if (result) return 1;
|
||||
diff[h->color2 * 2 +1]+= h->value2;
|
||||
if (diff[h->color2 * 2 + 1] >= h->value2)
|
||||
{
|
||||
diff[h->color2 * 2 + 1] -= h->value2;
|
||||
result = tryToPayHybrids(_hybrids, _nbhybrids - 1, diff);
|
||||
if (result)
|
||||
return 1;
|
||||
diff[h->color2 * 2 + 1] += h->value2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//compute the difference between two mana costs
|
||||
ManaCost * ManaCost::Diff(ManaCost * _cost){
|
||||
int diff[(Constants::MTG_NB_COLORS + 1 )* 2];
|
||||
ManaCost * ManaCost::Diff(ManaCost * _cost)
|
||||
{
|
||||
int diff[(Constants::MTG_NB_COLORS + 1) * 2];
|
||||
diff[Constants::MTG_NB_COLORS * 2] = Constants::MTG_NB_COLORS;
|
||||
for (int i=0; i < Constants::MTG_NB_COLORS; i++){
|
||||
diff[i*2] = i;
|
||||
diff[i*2 +1] = cost[i] - _cost->getCost(i);
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
diff[i * 2] = i;
|
||||
diff[i * 2 + 1] = cost[i] - _cost->getCost(i);
|
||||
}
|
||||
int hybridResult = tryToPayHybrids(_cost->hybrids, _cost->nbhybrids, diff);
|
||||
if (!hybridResult) randomDiffHybrids(_cost,diff);
|
||||
if (!hybridResult)
|
||||
randomDiffHybrids(_cost, diff);
|
||||
|
||||
//Colorless mana, special case
|
||||
int colorless_idx = Constants::MTG_COLOR_ARTIFACT * 2 + 1;
|
||||
if (diff[colorless_idx] < 0){
|
||||
for (int i=0; i < Constants::MTG_NB_COLORS; i++){
|
||||
if (diff[i*2 + 1] > 0){
|
||||
if (diff[i*2 + 1] + diff[colorless_idx] > 0){
|
||||
diff[i*2 + 1] += diff[colorless_idx];
|
||||
if (diff[colorless_idx] < 0)
|
||||
{
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
if (diff[i * 2 + 1] > 0)
|
||||
{
|
||||
if (diff[i * 2 + 1] + diff[colorless_idx] > 0)
|
||||
{
|
||||
diff[i * 2 + 1] += diff[colorless_idx];
|
||||
diff[colorless_idx] = 0;
|
||||
break;
|
||||
}else{
|
||||
diff[colorless_idx] += diff[i*2 + 1];
|
||||
diff[i*2 + 1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff[colorless_idx] += diff[i * 2 + 1];
|
||||
diff[i * 2 + 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Cost X
|
||||
if (_cost->hasX()){
|
||||
if (_cost->hasX())
|
||||
{
|
||||
diff[Constants::MTG_NB_COLORS * 2 + 1] = 0;
|
||||
for (int i=0; i < Constants::MTG_NB_COLORS; i++){
|
||||
if (diff[i*2 + 1] > 0){
|
||||
diff[Constants::MTG_NB_COLORS * 2 + 1] += diff[i*2 + 1];
|
||||
diff[i*2 + 1] = 0;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
if (diff[i * 2 + 1] > 0)
|
||||
{
|
||||
diff[Constants::MTG_NB_COLORS * 2 + 1] += diff[i * 2 + 1];
|
||||
diff[i * 2 + 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ManaCost * result = NEW ManaCost(diff, Constants::MTG_NB_COLORS +1);
|
||||
ManaCost * result = NEW ManaCost(diff, Constants::MTG_NB_COLORS + 1);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
void ManaCost::Dump(){
|
||||
void ManaCost::Dump()
|
||||
{
|
||||
DebugTrace("\n===ManaCost===\n");
|
||||
for (int i=0; i<= Constants::MTG_NB_COLORS; i++){
|
||||
if (cost[i]) {
|
||||
for (int i=0; i<= Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
if (cost[i])
|
||||
{
|
||||
DebugTrace(Constants::MTGColorChars[i] << ":" << cost[i] << " - ");
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i=0; i< nbhybrids; i++){
|
||||
for (unsigned int i=0; i< nbhybrids; i++)
|
||||
{
|
||||
ManaCostHybrid * h = hybrids[i];
|
||||
DebugTrace("H:{" << Constants::MTGColorChars[h->color1] << ":" << h->value1 << "}/{" << Constants::MTGColorChars[h->color2] << ":" << h->value2 << "}");
|
||||
}
|
||||
@@ -517,55 +648,73 @@ ostream& operator<<(ostream& out, const ManaCost& m)
|
||||
return out << "(manacost)";
|
||||
}
|
||||
|
||||
|
||||
void ManaPool::init(){
|
||||
void ManaPool::init()
|
||||
{
|
||||
ManaCost::init();
|
||||
WEvent * e = NEW WEventEmptyManaPool(this);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
}
|
||||
|
||||
ManaPool::ManaPool(Player * player):ManaCost(),player(player){}
|
||||
ManaPool::ManaPool(ManaCost * _manaCost,Player * player):ManaCost(_manaCost),player(player){}
|
||||
ManaPool::ManaPool(Player * player) :
|
||||
ManaCost(), player(player)
|
||||
{
|
||||
}
|
||||
ManaPool::ManaPool(ManaCost * _manaCost, Player * player) :
|
||||
ManaCost(_manaCost), player(player)
|
||||
{
|
||||
}
|
||||
|
||||
int ManaPool::remove (int color, int value){
|
||||
int ManaPool::remove(int color, int value)
|
||||
{
|
||||
int result = ManaCost::remove(color, value);
|
||||
for (int i = 0; i < value; ++i){
|
||||
for (int i = 0; i < value; ++i)
|
||||
{
|
||||
WEvent * e = NEW WEventConsumeMana(color, this);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ManaPool::add(int color, int value, MTGCardInstance * source ){
|
||||
int ManaPool::add(int color, int value, MTGCardInstance * source)
|
||||
{
|
||||
int result = ManaCost::add(color, value);
|
||||
for (int i = 0; i < value; ++i){
|
||||
WEvent * e = NEW WEventEngageMana(color, source,this);
|
||||
for (int i = 0; i < value; ++i)
|
||||
{
|
||||
WEvent * e = NEW WEventEngageMana(color, source, this);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ManaPool::add(ManaCost * _cost, MTGCardInstance * source){
|
||||
if(!_cost) return 0;
|
||||
int ManaPool::add(ManaCost * _cost, MTGCardInstance * source)
|
||||
{
|
||||
if (!_cost)
|
||||
return 0;
|
||||
int result = ManaCost::add(_cost);
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
for (int j = 0; j < _cost->getCost(i); j++){
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
for (int j = 0; j < _cost->getCost(i); j++)
|
||||
{
|
||||
WEvent * e = NEW WEventEngageMana(i, source, this);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int ManaPool::pay (ManaCost * _cost){
|
||||
int ManaPool::pay(ManaCost * _cost)
|
||||
{
|
||||
int current[Constants::MTG_NB_COLORS];
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
current[i] = cost[i];
|
||||
}
|
||||
|
||||
int result = ManaCost::pay(_cost);
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
for (unsigned int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
int value = current[i] - cost[i];
|
||||
for (int j = 0; j <value; j++){
|
||||
for (int j = 0; j < value; j++)
|
||||
{
|
||||
WEvent * e = NEW WEventConsumeMana(i, this);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
|
||||
|
||||
@@ -2,27 +2,34 @@
|
||||
|
||||
#include "ManaCostHybrid.h"
|
||||
|
||||
ManaCostHybrid::ManaCostHybrid(){
|
||||
init(0,0,0,0);
|
||||
ManaCostHybrid::ManaCostHybrid()
|
||||
{
|
||||
init(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
ManaCostHybrid::ManaCostHybrid(int c1,int v1,int c2,int v2){
|
||||
init(c1,v1,c2,v2);
|
||||
ManaCostHybrid::ManaCostHybrid(int c1, int v1, int c2, int v2)
|
||||
{
|
||||
init(c1, v1, c2, v2);
|
||||
}
|
||||
|
||||
void ManaCostHybrid::init(int c1,int v1,int c2,int v2){
|
||||
void ManaCostHybrid::init(int c1, int v1, int c2, int v2)
|
||||
{
|
||||
color1 = c1;
|
||||
color2 = c2;
|
||||
value1 = v1;
|
||||
value2 = v2;
|
||||
}
|
||||
|
||||
int ManaCostHybrid::getConvertedCost(){
|
||||
if (value2 > value1) return value2;
|
||||
int ManaCostHybrid::getConvertedCost()
|
||||
{
|
||||
if (value2 > value1)
|
||||
return value2;
|
||||
return value1;
|
||||
}
|
||||
|
||||
int ManaCostHybrid::hasColor(int color){
|
||||
if (((color1 == color) && value1) || ((color2 == color) && value2)) return 1;
|
||||
int ManaCostHybrid::hasColor(int color)
|
||||
{
|
||||
if (((color1 == color) && value1) || ((color2 == color) && value2))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include "GameOptions.h"
|
||||
#include "Translate.h"
|
||||
|
||||
MenuItem::MenuItem(int id, WFont *font, string text, float x, float y, JQuad * _off, JQuad * _on, const char * particle, JQuad * particleTex, bool hasFocus): JGuiObject(id), mFont(font), mX(x), mY(y)
|
||||
MenuItem::MenuItem(int id, WFont *font, string text, float x, float y, JQuad * _off, JQuad * _on, const char * particle,
|
||||
JQuad * particleTex, bool hasFocus) :
|
||||
JGuiObject(id), mFont(font), mX(x), mY(y)
|
||||
{
|
||||
mText = _(text);
|
||||
updatedSinceLastRender = 1;
|
||||
@@ -23,26 +25,17 @@ MenuItem::MenuItem(int id, WFont *font, string text, float x, float y, JQuad * _
|
||||
Entering();
|
||||
}
|
||||
|
||||
|
||||
void MenuItem::Render()
|
||||
{
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
|
||||
|
||||
if (mHasFocus)
|
||||
{
|
||||
PIXEL_TYPE start = ARGB(46,255,255,200);
|
||||
if(mParticleSys)
|
||||
if (mParticleSys)
|
||||
start = mParticleSys->info.colColorStart.GetHWColor();
|
||||
|
||||
PIXEL_TYPE colors[] =
|
||||
{
|
||||
ARGB(0,0,0,0),
|
||||
start,
|
||||
ARGB(0,0,0,0),
|
||||
start,
|
||||
};
|
||||
renderer->FillRect(255,0,SCREEN_WIDTH-155,SCREEN_HEIGHT,colors);
|
||||
PIXEL_TYPE colors[] = { ARGB(0,0,0,0), start, ARGB(0,0,0,0), start, };
|
||||
renderer->FillRect(255, 0, SCREEN_WIDTH - 155, SCREEN_HEIGHT, colors);
|
||||
// set additive blending
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
mParticleSys->Render();
|
||||
@@ -50,17 +43,17 @@ void MenuItem::Render()
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
onQuad->SetColor(ARGB(70,255,255,255));
|
||||
renderer->RenderQuad(onQuad, SCREEN_WIDTH , SCREEN_HEIGHT/2 , 0,8,8);
|
||||
renderer->RenderQuad(onQuad, SCREEN_WIDTH, SCREEN_HEIGHT / 2, 0, 8, 8);
|
||||
onQuad->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(mText.c_str(), SCREEN_WIDTH/2, 20 + 3*SCREEN_HEIGHT/4, JGETEXT_CENTER);
|
||||
renderer->RenderQuad(onQuad, mX , mY , 0,mScale,mScale);
|
||||
mFont->DrawString(mText.c_str(), SCREEN_WIDTH / 2, 20 + 3 * SCREEN_HEIGHT / 4, JGETEXT_CENTER);
|
||||
renderer->RenderQuad(onQuad, mX, mY, 0, mScale, mScale);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer->RenderQuad(offQuad, mX , mY , 0,mScale,mScale);
|
||||
renderer->RenderQuad(offQuad, mX, mY, 0, mScale, mScale);
|
||||
}
|
||||
updatedSinceLastRender= 0;
|
||||
updatedSinceLastRender = 0;
|
||||
}
|
||||
|
||||
void MenuItem::Update(float dt)
|
||||
@@ -69,13 +62,13 @@ void MenuItem::Update(float dt)
|
||||
lastDt = dt;
|
||||
if (mScale < mTargetScale)
|
||||
{
|
||||
mScale += 8.0f*dt;
|
||||
mScale += 8.0f * dt;
|
||||
if (mScale > mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
}
|
||||
else if (mScale > mTargetScale)
|
||||
{
|
||||
mScale -= 8.0f*dt;
|
||||
mScale -= 8.0f * dt;
|
||||
if (mScale < mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
}
|
||||
@@ -83,9 +76,6 @@ void MenuItem::Update(float dt)
|
||||
mParticleSys->Update(dt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MenuItem::Entering()
|
||||
{
|
||||
|
||||
@@ -94,7 +84,6 @@ void MenuItem::Entering()
|
||||
mTargetScale = 1.3f;
|
||||
}
|
||||
|
||||
|
||||
bool MenuItem::Leaving(JButton key)
|
||||
{
|
||||
mParticleSys->Stop(true);
|
||||
@@ -103,28 +92,21 @@ bool MenuItem::Leaving(JButton key)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MenuItem::ButtonPressed()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
MenuItem::~MenuItem(){
|
||||
if (mParticleSys) delete mParticleSys;
|
||||
MenuItem::~MenuItem()
|
||||
{
|
||||
if (mParticleSys)
|
||||
delete mParticleSys;
|
||||
}
|
||||
|
||||
ostream& MenuItem::toString(ostream& out) const
|
||||
{
|
||||
return out << "MenuItem ::: mHasFocus : " << mHasFocus
|
||||
<< " ; mFont : " << mFont
|
||||
<< " ; mText : " << mText
|
||||
<< " ; mX,mY : " << mX << "," << mY
|
||||
<< " ; updatedSinceLastRender : " << updatedSinceLastRender
|
||||
<< " ; lastDt : " << lastDt
|
||||
<< " ; mScale : " << mScale
|
||||
<< " ; mTargetScale : " << mTargetScale
|
||||
<< " ; onQuad : " << onQuad
|
||||
<< " ; offQuad : " << offQuad
|
||||
<< " ; mParticleSys : " << mParticleSys;
|
||||
return out << "MenuItem ::: mHasFocus : " << mHasFocus << " ; mFont : " << mFont << " ; mText : " << mText << " ; mX,mY : "
|
||||
<< mX << "," << mY << " ; updatedSinceLastRender : " << updatedSinceLastRender << " ; lastDt : " << lastDt
|
||||
<< " ; mScale : " << mScale << " ; mTargetScale : " << mTargetScale << " ; onQuad : " << onQuad
|
||||
<< " ; offQuad : " << offQuad << " ; mParticleSys : " << mParticleSys;
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace
|
||||
}
|
||||
|
||||
/**
|
||||
** Helper class to Navigator. Represents a group of cards on the battlefield.
|
||||
*/
|
||||
** Helper class to Navigator. Represents a group of cards on the battlefield.
|
||||
*/
|
||||
class CardZone
|
||||
{
|
||||
public:
|
||||
@@ -39,7 +39,8 @@ public:
|
||||
/*
|
||||
**
|
||||
*/
|
||||
CardZone() : mCurrentCard(0)
|
||||
CardZone() :
|
||||
mCurrentCard(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -203,13 +204,14 @@ public:
|
||||
};
|
||||
|
||||
/*
|
||||
** Derivation of CardZone, but with special key handling for the grid style layout,
|
||||
** where we need to navigate up/down as well as left/right
|
||||
*/
|
||||
class GridCardZone : public CardZone
|
||||
** Derivation of CardZone, but with special key handling for the grid style layout,
|
||||
** where we need to navigate up/down as well as left/right
|
||||
*/
|
||||
class GridCardZone: public CardZone
|
||||
{
|
||||
public:
|
||||
GridCardZone(bool inEnforceAxisAlignment = false) : mEnforceAxisAlignment(inEnforceAxisAlignment)
|
||||
GridCardZone(bool inEnforceAxisAlignment = false) :
|
||||
mEnforceAxisAlignment(inEnforceAxisAlignment)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -224,25 +226,30 @@ public:
|
||||
for (size_t index = 0; index < mCards.size(); ++index)
|
||||
{
|
||||
// skip yourself
|
||||
if (mCurrentCard == index) continue;
|
||||
if (mCurrentCard == index)
|
||||
continue;
|
||||
|
||||
// skip if the card isn't on the same axis that we're stepping in
|
||||
// this flag is an optional override. If enabled, it forces you to only be able to thumb over to the next card
|
||||
// that is exactly on the same x or y coordinate axis - any card not strictly parallel is ignored.
|
||||
if (mEnforceAxisAlignment)
|
||||
{
|
||||
if ((isHorizontal && mCards[mCurrentCard]->y != mCards[index]->y) ||
|
||||
(!isHorizontal && mCards[mCurrentCard]->x != mCards[index]->x))
|
||||
if ((isHorizontal && mCards[mCurrentCard]->y != mCards[index]->y) || (!isHorizontal && mCards[mCurrentCard]->x
|
||||
!= mCards[index]->x))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// if it's going in the wrong direction, skip
|
||||
if (inKey == JGE_BTN_RIGHT && mCards[index]->x <= mCards[mCurrentCard]->x) continue;
|
||||
if (inKey == JGE_BTN_LEFT && mCards[index]->x >= mCards[mCurrentCard]->x) continue;
|
||||
if (inKey == JGE_BTN_DOWN && mCards[index]->y <= mCards[mCurrentCard]->y) continue;
|
||||
if (inKey == JGE_BTN_UP && mCards[index]->y >= mCards[mCurrentCard]->y) continue;
|
||||
if (inKey == JGE_BTN_RIGHT && mCards[index]->x <= mCards[mCurrentCard]->x)
|
||||
continue;
|
||||
if (inKey == JGE_BTN_LEFT && mCards[index]->x >= mCards[mCurrentCard]->x)
|
||||
continue;
|
||||
if (inKey == JGE_BTN_DOWN && mCards[index]->y <= mCards[mCurrentCard]->y)
|
||||
continue;
|
||||
if (inKey == JGE_BTN_UP && mCards[index]->y >= mCards[mCurrentCard]->y)
|
||||
continue;
|
||||
|
||||
// we've found a card on the same axis, stash its value & compare against the previous
|
||||
float yDiff = fabs(mCards[mCurrentCard]->y - mCards[index]->y);
|
||||
@@ -280,8 +287,8 @@ protected:
|
||||
};
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
class HandCardZone: public GridCardZone
|
||||
{
|
||||
public:
|
||||
@@ -307,37 +314,37 @@ public:
|
||||
};
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
class LandCardZone : public GridCardZone
|
||||
**
|
||||
*/
|
||||
class LandCardZone: public GridCardZone
|
||||
{
|
||||
public:
|
||||
virtual CardZone* EnterZone(JButton inDirection);
|
||||
};
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
class CreatureCardZone : public GridCardZone
|
||||
**
|
||||
*/
|
||||
class CreatureCardZone: public GridCardZone
|
||||
{
|
||||
public:
|
||||
virtual CardZone* EnterZone(JButton inDirection);
|
||||
};
|
||||
|
||||
/*
|
||||
** The base class dictates normally, if you enter a zone and it's empty, move to
|
||||
** the next zone in the same direction.
|
||||
** Adding an override here - if there are no creatures in play but there are land,
|
||||
** and we're moving horizontally, jump up to the land instead
|
||||
*/
|
||||
** The base class dictates normally, if you enter a zone and it's empty, move to
|
||||
** the next zone in the same direction.
|
||||
** Adding an override here - if there are no creatures in play but there are land,
|
||||
** and we're moving horizontally, jump up to the land instead
|
||||
*/
|
||||
CardZone* CreatureCardZone::EnterZone(JButton inDirection)
|
||||
{
|
||||
if ((inDirection == JGE_BTN_LEFT || inDirection == JGE_BTN_RIGHT) && mCards.empty())
|
||||
{
|
||||
LandCardZone* landZone = dynamic_cast<LandCardZone*>(mNeighbours[JGE_BTN_DOWN]);
|
||||
LandCardZone* landZone = dynamic_cast<LandCardZone*> (mNeighbours[JGE_BTN_DOWN]);
|
||||
if (landZone == NULL)
|
||||
{
|
||||
landZone = dynamic_cast<LandCardZone*>(mNeighbours[JGE_BTN_UP]);
|
||||
landZone = dynamic_cast<LandCardZone*> (mNeighbours[JGE_BTN_UP]);
|
||||
}
|
||||
|
||||
if (landZone && !landZone->mCards.empty())
|
||||
@@ -350,17 +357,17 @@ CardZone* CreatureCardZone::EnterZone(JButton inDirection)
|
||||
}
|
||||
|
||||
/*
|
||||
** Same pattern to the CreatureCardZone pattern - if moving through an empty land zone,
|
||||
** set the focus on the land zone if it has cards
|
||||
*/
|
||||
** Same pattern to the CreatureCardZone pattern - if moving through an empty land zone,
|
||||
** set the focus on the land zone if it has cards
|
||||
*/
|
||||
CardZone* LandCardZone::EnterZone(JButton inDirection)
|
||||
{
|
||||
if ((inDirection == JGE_BTN_LEFT || inDirection == JGE_BTN_RIGHT) && mCards.empty())
|
||||
{
|
||||
CreatureCardZone* creatureZone = dynamic_cast<CreatureCardZone*>(mNeighbours[JGE_BTN_DOWN]);
|
||||
CreatureCardZone* creatureZone = dynamic_cast<CreatureCardZone*> (mNeighbours[JGE_BTN_DOWN]);
|
||||
if (creatureZone == NULL)
|
||||
{
|
||||
creatureZone = dynamic_cast<CreatureCardZone*>(mNeighbours[JGE_BTN_UP]);
|
||||
creatureZone = dynamic_cast<CreatureCardZone*> (mNeighbours[JGE_BTN_UP]);
|
||||
}
|
||||
|
||||
if (creatureZone && !creatureZone->mCards.empty())
|
||||
@@ -372,12 +379,11 @@ CardZone* LandCardZone::EnterZone(JButton inDirection)
|
||||
return CardZone::EnterZone(inDirection);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Constructor. All the navigation logic is initialized here, by pairing up each card zone with a set of neighbours.
|
||||
*/
|
||||
Navigator::Navigator(DuelLayers* inDuelLayers)
|
||||
: mDrawPosition(kDefaultCardPosition), mDuelLayers(inDuelLayers), mLimitorEnabled(false)
|
||||
** Constructor. All the navigation logic is initialized here, by pairing up each card zone with a set of neighbours.
|
||||
*/
|
||||
Navigator::Navigator(DuelLayers* inDuelLayers) :
|
||||
mDrawPosition(kDefaultCardPosition), mDuelLayers(inDuelLayers), mLimitorEnabled(false)
|
||||
{
|
||||
assert(mDuelLayers);
|
||||
|
||||
@@ -473,8 +479,8 @@ Navigator::Navigator(DuelLayers* inDuelLayers)
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
Navigator::~Navigator()
|
||||
{
|
||||
std::map<int, CardZone*>::iterator iter = mCardZones.begin();
|
||||
@@ -483,9 +489,10 @@ Navigator::~Navigator()
|
||||
SAFE_DELETE(iter->second);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
bool Navigator::CheckUserInput(JButton inKey)
|
||||
{
|
||||
bool result = true;
|
||||
@@ -506,8 +513,8 @@ bool Navigator::CheckUserInput(JButton inKey)
|
||||
HandleKeyStroke(inKey);
|
||||
break;
|
||||
case JGE_BTN_CANCEL:
|
||||
mDrawMode = (mDrawMode+1) % DrawMode::kNumDrawModes;
|
||||
if(mDrawMode == DrawMode::kText)
|
||||
mDrawMode = (mDrawMode + 1) % DrawMode::kNumDrawModes;
|
||||
if (mDrawMode == DrawMode::kText)
|
||||
options[Options::DISABLECARDS].number = 1;
|
||||
else
|
||||
options[Options::DISABLECARDS].number = 0;
|
||||
@@ -526,16 +533,16 @@ bool Navigator::CheckUserInput(int x, int y)
|
||||
}
|
||||
|
||||
/*
|
||||
** reposition the selected card's draw location
|
||||
*/
|
||||
** reposition the selected card's draw location
|
||||
*/
|
||||
void Navigator::Update(float dt)
|
||||
{
|
||||
float boundary = mDuelLayers->RightBoundary();
|
||||
float position = boundary - CardGui::BigWidth / 2;
|
||||
if (GetCurrentCard() != NULL)
|
||||
{
|
||||
if ((GetCurrentCard()->x + CardGui::Width / 2 > position - CardGui::BigWidth / 2) &&
|
||||
(GetCurrentCard()->x - CardGui::Width / 2 < position + CardGui::BigWidth / 2))
|
||||
if ((GetCurrentCard()->x + CardGui::Width / 2 > position - CardGui::BigWidth / 2) && (GetCurrentCard()->x - CardGui::Width
|
||||
/ 2 < position + CardGui::BigWidth / 2))
|
||||
{
|
||||
position = CardGui::BigWidth / 2 - 10;
|
||||
}
|
||||
@@ -549,23 +556,23 @@ void Navigator::Update(float dt)
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
PlayGuiObject* Navigator::GetCurrentCard()
|
||||
{
|
||||
return mCurrentZone ? mCurrentZone->GetCurrentCard() : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
void Navigator::Render()
|
||||
{
|
||||
if (GetCurrentCard() != NULL)
|
||||
{
|
||||
GetCurrentCard()->Render();
|
||||
|
||||
CardView* card = dynamic_cast<CardView*>(GetCurrentCard());
|
||||
CardView* card = dynamic_cast<CardView*> (GetCurrentCard());
|
||||
if (card)
|
||||
{
|
||||
card->DrawCard(mDrawPosition, mDrawMode);
|
||||
@@ -574,8 +581,8 @@ void Navigator::Render()
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
void Navigator::HandleKeyStroke(JButton inKey)
|
||||
{
|
||||
assert(mCurrentZone);
|
||||
@@ -593,22 +600,22 @@ void Navigator::HandleKeyStroke(JButton inKey)
|
||||
}
|
||||
|
||||
/*
|
||||
** unused. This is CardSelector specific.
|
||||
*/
|
||||
** unused. This is CardSelector specific.
|
||||
*/
|
||||
void Navigator::PopLimitor()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
** same as above.
|
||||
*/
|
||||
** same as above.
|
||||
*/
|
||||
void Navigator::PushLimitor()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
void Navigator::Limit(LimitorFunctor<PlayGuiObject>* inLimitor, CardView::SelectorZone inZone)
|
||||
{
|
||||
mLimitorEnabled = (inLimitor != NULL);
|
||||
@@ -637,12 +644,12 @@ void Navigator::Limit(LimitorFunctor<PlayGuiObject>* inLimitor, CardView::Select
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
int Navigator::CardToCardZone(PlayGuiObject* inCard)
|
||||
{
|
||||
int result = kCardZone_Unknown;
|
||||
GuiAvatar* avatar = dynamic_cast<GuiAvatar*>(inCard);
|
||||
GuiAvatar* avatar = dynamic_cast<GuiAvatar*> (inCard);
|
||||
if (avatar)
|
||||
{
|
||||
if (avatar->player->isAI())
|
||||
@@ -655,7 +662,7 @@ int Navigator::CardToCardZone(PlayGuiObject* inCard)
|
||||
}
|
||||
}
|
||||
|
||||
GuiGraveyard* graveyard = dynamic_cast<GuiGraveyard*>(inCard);
|
||||
GuiGraveyard* graveyard = dynamic_cast<GuiGraveyard*> (inCard);
|
||||
if (graveyard)
|
||||
{
|
||||
if (graveyard->player->isAI())
|
||||
@@ -668,7 +675,7 @@ int Navigator::CardToCardZone(PlayGuiObject* inCard)
|
||||
}
|
||||
}
|
||||
|
||||
GuiLibrary* library = dynamic_cast<GuiLibrary*>(inCard);
|
||||
GuiLibrary* library = dynamic_cast<GuiLibrary*> (inCard);
|
||||
if (library)
|
||||
{
|
||||
if (library->player->isAI())
|
||||
@@ -681,13 +688,13 @@ int Navigator::CardToCardZone(PlayGuiObject* inCard)
|
||||
}
|
||||
}
|
||||
|
||||
GuiOpponentHand* opponentHand = dynamic_cast<GuiOpponentHand*>(inCard);
|
||||
GuiOpponentHand* opponentHand = dynamic_cast<GuiOpponentHand*> (inCard);
|
||||
if (opponentHand)
|
||||
{
|
||||
result = kCardZone_AIHand;
|
||||
}
|
||||
|
||||
CardView* card = dynamic_cast<CardView*>(inCard);
|
||||
CardView* card = dynamic_cast<CardView*> (inCard);
|
||||
{
|
||||
if (card)
|
||||
{
|
||||
@@ -731,7 +738,8 @@ int Navigator::CardToCardZone(PlayGuiObject* inCard)
|
||||
result = isAI ? kCardZone_AIEnchantmentsAndArtifacts : kCardZone_PlayerEnchantmentsAndArtifacts;
|
||||
}
|
||||
}
|
||||
else assert(false);
|
||||
else
|
||||
assert(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -745,8 +753,8 @@ int Navigator::CardToCardZone(PlayGuiObject* inCard)
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
void Navigator::Add(PlayGuiObject* card)
|
||||
{
|
||||
// figure out what card's been added, add it to the appropriate pile
|
||||
@@ -758,8 +766,8 @@ void Navigator::Add(PlayGuiObject* card)
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
**
|
||||
*/
|
||||
void Navigator::Remove(PlayGuiObject* card)
|
||||
{
|
||||
int zone = CardToCardZone(card);
|
||||
|
||||
+287
-146
@@ -9,26 +9,32 @@
|
||||
#include <dirent.h>
|
||||
|
||||
//OptionItem
|
||||
OptionItem::OptionItem( int _id, string _displayValue): WGuiItem(_displayValue) {
|
||||
OptionItem::OptionItem(int _id, string _displayValue) :
|
||||
WGuiItem(_displayValue)
|
||||
{
|
||||
id = _id;
|
||||
mFocus=false;
|
||||
mFocus = false;
|
||||
}
|
||||
|
||||
//OptionInteger
|
||||
void OptionInteger::Render(){
|
||||
void OptionInteger::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
mFont->SetColor(getColor(WGuiColor::TEXT));
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
|
||||
mFont->DrawString(_(displayValue).c_str(), x + 2, y + 3);
|
||||
char buf[512];
|
||||
if (maxValue == 1){
|
||||
if (maxValue == 1)
|
||||
{
|
||||
if (value)
|
||||
sprintf(buf, "%s", _("Yes").c_str());
|
||||
else
|
||||
sprintf(buf, "%s", _("No").c_str());
|
||||
}else{
|
||||
if(value == defValue && strDefault.size())
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == defValue && strDefault.size())
|
||||
sprintf(buf, "%s", _(strDefault).c_str());
|
||||
else
|
||||
sprintf(buf, "%i", value);
|
||||
@@ -36,7 +42,9 @@ void OptionInteger::Render(){
|
||||
mFont->DrawString(buf, width - 5, y + 3, JGETEXT_RIGHT);
|
||||
}
|
||||
|
||||
OptionInteger::OptionInteger(int _id, string _displayValue, int _maxValue, int _increment, int _defV, string _sDef, int _minValue): OptionItem(_id, _displayValue){
|
||||
OptionInteger::OptionInteger(int _id, string _displayValue, int _maxValue, int _increment, int _defV, string _sDef, int _minValue) :
|
||||
OptionItem(_id, _displayValue)
|
||||
{
|
||||
defValue = _defV;
|
||||
strDefault = _sDef;
|
||||
maxValue = _maxValue;
|
||||
@@ -47,25 +55,29 @@ OptionInteger::OptionInteger(int _id, string _displayValue, int _maxValue, int _
|
||||
y = 0;
|
||||
}
|
||||
|
||||
void OptionInteger::setData(){
|
||||
if(id != INVALID_OPTION)
|
||||
void OptionInteger::setData()
|
||||
{
|
||||
if (id != INVALID_OPTION)
|
||||
options[id] = GameOption(value);
|
||||
}
|
||||
|
||||
//Option Select
|
||||
void OptionSelect::initSelections(){
|
||||
void OptionSelect::initSelections()
|
||||
{
|
||||
//Find currently active bit in the list.
|
||||
for (size_t i = 0; i < selections.size(); ++i)
|
||||
if (selections[i] == options[id].str)
|
||||
value = i;
|
||||
}
|
||||
|
||||
void OptionSelect::Entering(JButton key){
|
||||
void OptionSelect::Entering(JButton key)
|
||||
{
|
||||
OptionItem::Entering(key);
|
||||
prior_value = value;
|
||||
}
|
||||
|
||||
void OptionSelect::Render(){
|
||||
void OptionSelect::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
mFont->SetColor(getColor(WGuiColor::TEXT));
|
||||
|
||||
@@ -75,66 +87,81 @@ void OptionSelect::Render(){
|
||||
if (value < selections.size())
|
||||
mFont->DrawString(_(selections[value]).c_str(), x + width - 10, y + 2, JGETEXT_RIGHT);
|
||||
else
|
||||
mFont->DrawString(_("Unset").c_str(),x + width - 10, y + 2, JGETEXT_RIGHT);
|
||||
mFont->DrawString(_("Unset").c_str(), x + width - 10, y + 2, JGETEXT_RIGHT);
|
||||
}
|
||||
|
||||
void OptionSelect::setData(){
|
||||
if(id == INVALID_OPTION) return;
|
||||
void OptionSelect::setData()
|
||||
{
|
||||
if (id == INVALID_OPTION)
|
||||
return;
|
||||
|
||||
if (value < selections.size())
|
||||
options[id] = GameOption(selections[value]);
|
||||
}
|
||||
bool OptionSelect::Selectable(){
|
||||
bool OptionSelect::Selectable()
|
||||
{
|
||||
return (selections.size() > 1);
|
||||
}
|
||||
|
||||
void OptionSelect::addSelection(string s){
|
||||
void OptionSelect::addSelection(string s)
|
||||
{
|
||||
selections.push_back(s);
|
||||
}
|
||||
|
||||
//OptionProfile
|
||||
const string OptionProfile::DIRTESTER = "collection.dat";
|
||||
OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) : OptionDirectory(JGE_GET_RES("profiles"), Options::ACTIVE_PROFILE, "Profile", DIRTESTER){
|
||||
OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) :
|
||||
OptionDirectory(JGE_GET_RES("profiles"), Options::ACTIVE_PROFILE, "Profile", DIRTESTER)
|
||||
{
|
||||
app = _app;
|
||||
listener = jgl;
|
||||
height=60;
|
||||
height = 60;
|
||||
addSelection("Default");
|
||||
sort(selections.begin(),selections.end());
|
||||
sort(selections.begin(), selections.end());
|
||||
mFocus = false;
|
||||
initSelections();
|
||||
populate();
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
void OptionProfile::initSelections() {
|
||||
void OptionProfile::initSelections()
|
||||
{
|
||||
OptionSelect::initSelections();
|
||||
initialValue = value;
|
||||
}
|
||||
|
||||
void OptionProfile::addSelection(string s){
|
||||
void OptionProfile::addSelection(string s)
|
||||
{
|
||||
OptionDirectory::addSelection(s);
|
||||
|
||||
//Check how many options... if 1, we're not selectable.
|
||||
if(selections.size() > 1)
|
||||
if (selections.size() > 1)
|
||||
canSelect = true;
|
||||
else
|
||||
canSelect = false;
|
||||
|
||||
}
|
||||
void OptionProfile::updateValue(){
|
||||
|
||||
void OptionProfile::updateValue()
|
||||
{
|
||||
value++;
|
||||
if (value > selections.size() - 1)
|
||||
value=0;
|
||||
value = 0;
|
||||
|
||||
populate();
|
||||
}
|
||||
|
||||
void OptionProfile::Reload(){
|
||||
void OptionProfile::Reload()
|
||||
{
|
||||
OptionDirectory::Reload();
|
||||
populate();
|
||||
}
|
||||
void OptionProfile::populate(){
|
||||
|
||||
void OptionProfile::populate()
|
||||
{
|
||||
string temp = options[Options::ACTIVE_PROFILE].str;
|
||||
if (value >= selections.size()){ //TODO fail gracefully.
|
||||
if (value >= selections.size())
|
||||
{ //TODO fail gracefully.
|
||||
return;
|
||||
}
|
||||
options[Options::ACTIVE_PROFILE].str = selections[value];
|
||||
@@ -143,9 +170,11 @@ void OptionProfile::populate(){
|
||||
int unlocked = 0, sets = setlist.size();
|
||||
std::ifstream file(options.profileFile(PLAYER_SETTINGS).c_str());
|
||||
std::string s;
|
||||
if(file){
|
||||
while(std::getline(file,s)){
|
||||
if(s.substr(0, 9) == "unlocked_")
|
||||
if (file)
|
||||
{
|
||||
while (std::getline(file, s))
|
||||
{
|
||||
if (s.substr(0, 9) == "unlocked_")
|
||||
unlocked++;
|
||||
}
|
||||
file.close();
|
||||
@@ -154,32 +183,34 @@ void OptionProfile::populate(){
|
||||
options[Options::ACTIVE_PROFILE] = temp;
|
||||
|
||||
char buf[512], format[512];
|
||||
sprintf(format,"%s\n%s\n%s\n",_("Credits: %i").c_str(),_("Cards: %i").c_str(),_("Sets: %i (of %i)").c_str());
|
||||
sprintf(buf,format,pdata->credits,pdata->collection->totalCards(),unlocked,sets);
|
||||
sprintf(format, "%s\n%s\n%s\n", _("Credits: %i").c_str(), _("Cards: %i").c_str(), _("Sets: %i (of %i)").c_str());
|
||||
sprintf(buf, format, pdata->credits, pdata->collection->totalCards(), unlocked, sets);
|
||||
preview = buf;
|
||||
|
||||
SAFE_DELETE(pdata);
|
||||
}
|
||||
|
||||
void OptionProfile::Render(){
|
||||
void OptionProfile::Render()
|
||||
{
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
WFont * mFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
mFont->SetScale(1);
|
||||
int spacing = 2+(int)mFont->GetHeight();
|
||||
int spacing = 2 + (int) mFont->GetHeight();
|
||||
|
||||
float pX, pY;
|
||||
pX = x;
|
||||
pY = y;
|
||||
char buf[512];
|
||||
if(selections[value] == "Default")
|
||||
sprintf(buf,"player/avatar.jpg");
|
||||
if (selections[value] == "Default")
|
||||
sprintf(buf, "player/avatar.jpg");
|
||||
else
|
||||
sprintf(buf,"profiles/%s/avatar.jpg",selections[value].c_str());
|
||||
sprintf(buf, "profiles/%s/avatar.jpg", selections[value].c_str());
|
||||
string filename = buf;
|
||||
JQuad * mAvatar = resources.RetrieveTempQuad(filename,TEXTURE_SUB_EXACT);
|
||||
JQuad * mAvatar = resources.RetrieveTempQuad(filename, TEXTURE_SUB_EXACT);
|
||||
|
||||
if(mAvatar){
|
||||
renderer->RenderQuad(mAvatar,x,pY);
|
||||
if (mAvatar)
|
||||
{
|
||||
renderer->RenderQuad(mAvatar, x, pY);
|
||||
pX += 40;
|
||||
}
|
||||
|
||||
@@ -191,74 +222,97 @@ void OptionProfile::Render(){
|
||||
mFont->SetScale(1.0f);
|
||||
|
||||
}
|
||||
void OptionProfile::Entering(JButton key){
|
||||
|
||||
void OptionProfile::Entering(JButton key)
|
||||
{
|
||||
mFocus = true;
|
||||
initialValue = value;
|
||||
}
|
||||
|
||||
void OptionProfile::confirmChange(bool confirmed){
|
||||
void OptionProfile::confirmChange(bool confirmed)
|
||||
{
|
||||
if (initialValue >= selections.size())
|
||||
return;
|
||||
|
||||
int result;
|
||||
|
||||
if(confirmed) result = value;
|
||||
else result = initialValue;
|
||||
if (confirmed)
|
||||
result = value;
|
||||
else
|
||||
result = initialValue;
|
||||
|
||||
options[Options::ACTIVE_PROFILE] = selections[result];
|
||||
value = result;
|
||||
|
||||
populate();
|
||||
if(listener && confirmed){
|
||||
listener->ButtonPressed(-102,5);
|
||||
if (listener && confirmed)
|
||||
{
|
||||
listener->ButtonPressed(-102, 5);
|
||||
initialValue = value;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//OptionThemeStyle
|
||||
OptionThemeStyle::OptionThemeStyle(string _displayValue) : OptionSelect(Options::GUI_STYLE,_displayValue)
|
||||
OptionThemeStyle::OptionThemeStyle(string _displayValue) :
|
||||
OptionSelect(Options::GUI_STYLE, _displayValue)
|
||||
{
|
||||
Reload();
|
||||
initSelections();
|
||||
};
|
||||
bool OptionThemeStyle::Visible() {
|
||||
return (selections.size() > 1);
|
||||
};
|
||||
void OptionThemeStyle::confirmChange(bool confirmed){
|
||||
options.getStyleMan()->determineActive(NULL,NULL);
|
||||
}
|
||||
void OptionThemeStyle::Reload(){
|
||||
|
||||
bool OptionThemeStyle::Visible()
|
||||
{
|
||||
return (selections.size() > 1);
|
||||
}
|
||||
|
||||
void OptionThemeStyle::confirmChange(bool confirmed)
|
||||
{
|
||||
options.getStyleMan()->determineActive(NULL, NULL);
|
||||
}
|
||||
|
||||
void OptionThemeStyle::Reload()
|
||||
{
|
||||
selections.clear();
|
||||
addSelection("Dynamic");
|
||||
map<string,WStyle*>::iterator it;
|
||||
map<string, WStyle*>::iterator it;
|
||||
|
||||
StyleManager * sm = options.getStyleMan();
|
||||
for(it=sm->styles.begin();it!=sm->styles.end();it++)
|
||||
for (it = sm->styles.begin(); it != sm->styles.end(); it++)
|
||||
addSelection(it->first);
|
||||
}
|
||||
//OptionLanguage
|
||||
OptionLanguage::OptionLanguage(string _displayValue) : OptionSelect(Options::LANG,_displayValue)
|
||||
OptionLanguage::OptionLanguage(string _displayValue) :
|
||||
OptionSelect(Options::LANG, _displayValue)
|
||||
{
|
||||
Reload();
|
||||
initSelections();
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
void OptionLanguage::setData(){
|
||||
if(id == INVALID_OPTION) return;
|
||||
void OptionLanguage::setData()
|
||||
{
|
||||
if (id == INVALID_OPTION)
|
||||
return;
|
||||
|
||||
if (value < selections.size()){
|
||||
if (value < selections.size())
|
||||
{
|
||||
options[id] = GameOption(actual_data[value]);
|
||||
Translator::EndInstance();
|
||||
Translator::GetInstance()->init();
|
||||
Translator::GetInstance()->tempValues.clear();
|
||||
}
|
||||
}
|
||||
void OptionLanguage::confirmChange(bool confirmed){
|
||||
if(!confirmed)
|
||||
|
||||
void OptionLanguage::confirmChange(bool confirmed)
|
||||
{
|
||||
if (!confirmed)
|
||||
value = prior_value;
|
||||
else{
|
||||
else
|
||||
{
|
||||
setData();
|
||||
if(Changed()){
|
||||
if (Changed())
|
||||
{
|
||||
options[id] = GameOption(actual_data[value]);
|
||||
Translator::EndInstance();
|
||||
Translator::GetInstance()->init();
|
||||
@@ -267,75 +321,100 @@ void OptionLanguage::confirmChange(bool confirmed){
|
||||
prior_value = value;
|
||||
}
|
||||
}
|
||||
void OptionLanguage::Reload(){
|
||||
|
||||
void OptionLanguage::Reload()
|
||||
{
|
||||
struct dirent *mDit;
|
||||
DIR *mDip;
|
||||
|
||||
mDip = opendir(JGE_GET_RES("lang").c_str());
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
while ((mDit = readdir(mDip)))
|
||||
{
|
||||
string filename = JGE_GET_RES("lang/");
|
||||
filename += mDit->d_name;
|
||||
std::ifstream file(filename.c_str());
|
||||
string s;
|
||||
string lang;
|
||||
if(file){
|
||||
if(std::getline(file,s)){
|
||||
if (!s.size()){
|
||||
if (file)
|
||||
{
|
||||
if (std::getline(file, s))
|
||||
{
|
||||
if (!s.size())
|
||||
{
|
||||
lang = "";
|
||||
}else{
|
||||
if (s[s.size()-1] == '\r')
|
||||
s.erase(s.size()-1); //Handle DOS files
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s[s.size() - 1] == '\r')
|
||||
s.erase(s.size() - 1); //Handle DOS files
|
||||
size_t found = s.find("#LANG:");
|
||||
if (found != 0) lang = "";
|
||||
else lang = s.substr(6);
|
||||
if (found != 0)
|
||||
lang = "";
|
||||
else
|
||||
lang = s.substr(6);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
if (lang.size()){
|
||||
if (lang.size())
|
||||
{
|
||||
string filen = mDit->d_name;
|
||||
addSelection(filen.substr(0,filen.size()-4),lang);
|
||||
addSelection(filen.substr(0, filen.size() - 4), lang);
|
||||
}
|
||||
}
|
||||
closedir(mDip);
|
||||
initSelections();
|
||||
}
|
||||
void OptionLanguage::addSelection(string s,string show){
|
||||
|
||||
void OptionLanguage::addSelection(string s, string show)
|
||||
{
|
||||
selections.push_back(show);
|
||||
actual_data.push_back(s);
|
||||
}
|
||||
void OptionLanguage::initSelections(){
|
||||
|
||||
void OptionLanguage::initSelections()
|
||||
{
|
||||
//Find currently active bit in the list.
|
||||
for(size_t i=0;i<actual_data.size();i++){
|
||||
if(actual_data[i] == options[id].str)
|
||||
for (size_t i = 0; i < actual_data.size(); i++)
|
||||
{
|
||||
if (actual_data[i] == options[id].str)
|
||||
value = i;
|
||||
}
|
||||
}
|
||||
bool OptionLanguage::Visible(){
|
||||
if(selections.size() > 1)
|
||||
|
||||
bool OptionLanguage::Visible()
|
||||
{
|
||||
if (selections.size() > 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool OptionLanguage::Selectable(){
|
||||
if(selections.size() > 1)
|
||||
|
||||
bool OptionLanguage::Selectable()
|
||||
{
|
||||
if (selections.size() > 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//OptionDirectory
|
||||
void OptionDirectory::Reload(){
|
||||
void OptionDirectory::Reload()
|
||||
{
|
||||
DIR *mDip;
|
||||
struct dirent *mDit;
|
||||
char buf[PATH_MAX];
|
||||
mDip = opendir(root.c_str());
|
||||
|
||||
if (!mDip) return;
|
||||
if (!mDip)
|
||||
return;
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
sprintf(buf,"%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
|
||||
while ((mDit = readdir(mDip)))
|
||||
{
|
||||
sprintf(buf, "%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
|
||||
std::ifstream file(buf);
|
||||
if (!file) continue;
|
||||
if (!file)
|
||||
continue;
|
||||
file.close();
|
||||
if (find(selections.begin(), selections.end(), mDit->d_name) == selections.end())
|
||||
addSelection(mDit->d_name);
|
||||
@@ -346,18 +425,23 @@ void OptionDirectory::Reload(){
|
||||
initSelections();
|
||||
}
|
||||
|
||||
OptionDirectory::OptionDirectory(string root, int id, string displayValue, string type): OptionSelect(id, displayValue), root(root), type(type){
|
||||
OptionDirectory::OptionDirectory(string root, int id, string displayValue, string type) :
|
||||
OptionSelect(id, displayValue), root(root), type(type)
|
||||
{
|
||||
DIR *mDip;
|
||||
struct dirent *mDit;
|
||||
char buf[PATH_MAX];
|
||||
|
||||
mDip = opendir(root.c_str());
|
||||
if(!mDip) return;
|
||||
if (!mDip)
|
||||
return;
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
sprintf(buf,"%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
|
||||
while ((mDit = readdir(mDip)))
|
||||
{
|
||||
sprintf(buf, "%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
|
||||
std::ifstream file(buf);
|
||||
if (!file) continue;
|
||||
if (!file)
|
||||
continue;
|
||||
file.close();
|
||||
addSelection(mDit->d_name);
|
||||
}
|
||||
@@ -368,100 +452,125 @@ OptionDirectory::OptionDirectory(string root, int id, string displayValue, strin
|
||||
}
|
||||
|
||||
const string OptionTheme::DIRTESTER = "preview.png";
|
||||
OptionTheme::OptionTheme(OptionThemeStyle * style) : OptionDirectory(JGE_GET_RES("themes"), Options::ACTIVE_THEME, "Current Theme", DIRTESTER){
|
||||
OptionTheme::OptionTheme(OptionThemeStyle * style) :
|
||||
OptionDirectory(JGE_GET_RES("themes"), Options::ACTIVE_THEME, "Current Theme", DIRTESTER)
|
||||
{
|
||||
addSelection("Default");
|
||||
sort(selections.begin(),selections.end());
|
||||
sort(selections.begin(), selections.end());
|
||||
initSelections();
|
||||
mFocus=false;
|
||||
mFocus = false;
|
||||
bChecked = false;
|
||||
ts = style;
|
||||
}
|
||||
JQuad * OptionTheme::getImage(){
|
||||
|
||||
JQuad * OptionTheme::getImage()
|
||||
{
|
||||
char buf[512];
|
||||
string val = selections[value];
|
||||
if(val == "Default")
|
||||
sprintf(buf,"graphics/preview.png");
|
||||
if (val == "Default")
|
||||
sprintf(buf, "graphics/preview.png");
|
||||
else
|
||||
sprintf(buf,"themes/%s/preview.png",val.c_str());
|
||||
sprintf(buf, "themes/%s/preview.png", val.c_str());
|
||||
string filename = buf;
|
||||
return resources.RetrieveTempQuad(filename,TEXTURE_SUB_EXACT);
|
||||
return resources.RetrieveTempQuad(filename, TEXTURE_SUB_EXACT);
|
||||
}
|
||||
|
||||
float OptionTheme::getHeight(){
|
||||
float OptionTheme::getHeight()
|
||||
{
|
||||
return 130;
|
||||
};
|
||||
void OptionTheme::updateValue(){
|
||||
}
|
||||
|
||||
void OptionTheme::updateValue()
|
||||
{
|
||||
OptionDirectory::updateValue();
|
||||
bChecked = false;
|
||||
}
|
||||
|
||||
void OptionTheme::Render(){
|
||||
void OptionTheme::Render()
|
||||
{
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
char buf[512];
|
||||
if(!bChecked){
|
||||
if (!bChecked)
|
||||
{
|
||||
author = "";
|
||||
bChecked = true;
|
||||
if(selections[value] == "Default")
|
||||
sprintf(buf,JGE_GET_RES("graphics/themeinfo.txt").c_str());
|
||||
if (selections[value] == "Default")
|
||||
sprintf(buf, JGE_GET_RES("graphics/themeinfo.txt").c_str());
|
||||
else
|
||||
sprintf(buf,JGE_GET_RES("themes/%s/themeinfo.txt").c_str(),selections[value].c_str());
|
||||
sprintf(buf, JGE_GET_RES("themes/%s/themeinfo.txt").c_str(), selections[value].c_str());
|
||||
std::ifstream file(buf);
|
||||
if(file){
|
||||
if (file)
|
||||
{
|
||||
string temp;
|
||||
std::getline(file,temp);
|
||||
for(unsigned int x=0;x<17,x<temp.size();x++){
|
||||
if(isprint(temp[x])) //Clear stuff that breaks mFont->DrawString, cuts to 16 chars.
|
||||
std::getline(file, temp);
|
||||
for (unsigned int x = 0; x < 17, x < temp.size(); x++)
|
||||
{
|
||||
if (isprint(temp[x])) //Clear stuff that breaks mFont->DrawString, cuts to 16 chars.
|
||||
author += temp[x];
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
sprintf(buf,_("Theme: %s").c_str(),selections[value].c_str());
|
||||
sprintf(buf, _("Theme: %s").c_str(), selections[value].c_str());
|
||||
|
||||
JQuad * q = getImage();
|
||||
if(q){
|
||||
if (q)
|
||||
{
|
||||
float scale = 128 / q->mHeight;
|
||||
renderer->RenderQuad(q,x, y,0,scale,scale);
|
||||
renderer->RenderQuad(q, x, y, 0, scale, scale);
|
||||
}
|
||||
|
||||
WFont * mFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
mFont->SetColor(getColor(WGuiColor::TEXT_HEADER));
|
||||
mFont->DrawString(buf, x + 2, y + 2);
|
||||
if(bChecked && author.size()){
|
||||
if (bChecked && author.size())
|
||||
{
|
||||
mFont->SetColor(getColor(WGuiColor::TEXT_BODY));
|
||||
mFont->SetScale(0.8f);
|
||||
float hi = mFont->GetHeight();
|
||||
sprintf(buf,_("Artist: %s").c_str(),author.c_str());
|
||||
sprintf(buf, _("Artist: %s").c_str(), author.c_str());
|
||||
mFont->DrawString(buf, x + 2, y + getHeight() - hi);
|
||||
mFont->SetScale(1);
|
||||
}
|
||||
}
|
||||
|
||||
bool OptionTheme::Visible(){
|
||||
if(selections.size() <= 1)
|
||||
bool OptionTheme::Visible()
|
||||
{
|
||||
if (selections.size() <= 1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OptionTheme::confirmChange(bool confirmed){
|
||||
void OptionTheme::confirmChange(bool confirmed)
|
||||
{
|
||||
bChecked = false;
|
||||
if(!confirmed)
|
||||
if (!confirmed)
|
||||
value = prior_value;
|
||||
else{
|
||||
else
|
||||
{
|
||||
setData();
|
||||
options.getStyleMan()->loadRules();
|
||||
if(ts) ts->Reload();
|
||||
if (ts)
|
||||
ts->Reload();
|
||||
|
||||
resources.Refresh(); //Update images
|
||||
prior_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
OptionKey::OptionKey(GameStateOptions* g, LocalKeySym from, JButton to) : WGuiItem(""), from(from), to(to), grabbed(false), g(g), btnMenu(NULL) {}
|
||||
OptionKey::OptionKey(GameStateOptions* g, LocalKeySym from, JButton to) :
|
||||
WGuiItem(""), from(from), to(to), grabbed(false), g(g), btnMenu(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void OptionKey::Update(float dt) { if (btnMenu) btnMenu->Update(dt); }
|
||||
void OptionKey::Render() {
|
||||
void OptionKey::Update(float dt)
|
||||
{
|
||||
if (btnMenu)
|
||||
btnMenu->Update(dt);
|
||||
}
|
||||
void OptionKey::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
mFont->SetColor(getColor(WGuiColor::TEXT));
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
@@ -488,10 +597,13 @@ void OptionKey::Render() {
|
||||
mFont->DrawString(rep2.first, width - 4, y + 3, JGETEXT_RIGHT);
|
||||
}
|
||||
}
|
||||
bool OptionKey::CheckUserInput(JButton key) {
|
||||
|
||||
bool OptionKey::CheckUserInput(JButton key)
|
||||
{
|
||||
if (btnMenu)
|
||||
return btnMenu->CheckUserInput(key);
|
||||
if (JGE_BTN_OK == key) {
|
||||
if (JGE_BTN_OK == key)
|
||||
{
|
||||
grabbed = true;
|
||||
g->GrabKeyboard(this);
|
||||
return true;
|
||||
@@ -499,44 +611,73 @@ bool OptionKey::CheckUserInput(JButton key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static const JButton btnList[] = {JGE_BTN_MENU, JGE_BTN_CTRL, JGE_BTN_RIGHT,
|
||||
JGE_BTN_LEFT, JGE_BTN_UP, JGE_BTN_DOWN,
|
||||
JGE_BTN_OK, JGE_BTN_CANCEL, JGE_BTN_PRI,
|
||||
JGE_BTN_SEC, JGE_BTN_PREV, JGE_BTN_NEXT,
|
||||
static const JButton btnList[] =
|
||||
{
|
||||
JGE_BTN_MENU,
|
||||
JGE_BTN_CTRL,
|
||||
JGE_BTN_RIGHT,
|
||||
JGE_BTN_LEFT,
|
||||
JGE_BTN_UP,
|
||||
JGE_BTN_DOWN,
|
||||
JGE_BTN_OK,
|
||||
JGE_BTN_CANCEL,
|
||||
JGE_BTN_PRI,
|
||||
JGE_BTN_SEC,
|
||||
JGE_BTN_PREV,
|
||||
JGE_BTN_NEXT,
|
||||
#ifdef LINUX
|
||||
JGE_BTN_FULLSCREEN,
|
||||
#endif
|
||||
JGE_BTN_NONE};
|
||||
void OptionKey::KeyPressed(LocalKeySym key) {
|
||||
JGE_BTN_NONE
|
||||
};
|
||||
|
||||
void OptionKey::KeyPressed(LocalKeySym key)
|
||||
{
|
||||
from = key;
|
||||
g->UngrabKeyboard(this);
|
||||
grabbed = false;
|
||||
|
||||
btnMenu = NEW SimpleMenu(0, this, Fonts::MENU_FONT, 80, 10);
|
||||
for (int i = sizeof(btnList) / sizeof(btnList[0]) - 1; i >= 0; --i) {
|
||||
for (int i = sizeof(btnList) / sizeof(btnList[0]) - 1; i >= 0; --i)
|
||||
{
|
||||
const KeyRep& rep = translateKey(btnList[i]);
|
||||
btnMenu->Add(i, rep.first.c_str());
|
||||
}
|
||||
}
|
||||
bool OptionKey::isModal() { return grabbed || btnMenu; }
|
||||
bool OptionKey::isModal()
|
||||
{
|
||||
return grabbed || btnMenu;
|
||||
}
|
||||
|
||||
void OptionKey::Overlay()
|
||||
{
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
WFont * mFont = resources.GetWFont(Fonts::OPTION_FONT);
|
||||
mFont->SetColor(ARGB(255, 0, 0, 0));
|
||||
if (grabbed) {
|
||||
if (grabbed)
|
||||
{
|
||||
static const float x = 30, y = 45;
|
||||
renderer->FillRoundRect(x, y, SCREEN_WIDTH - 2*x, 50, 2, ARGB(200, 200, 200, 255));
|
||||
renderer->FillRoundRect(x, y, SCREEN_WIDTH - 2 * x, 50, 2, ARGB(200, 200, 200, 255));
|
||||
string msg = _("Press a key to associate.");
|
||||
mFont->DrawString(msg, (SCREEN_WIDTH - mFont->GetStringWidth(msg.c_str())) / 2, y + 20);
|
||||
}
|
||||
else if (btnMenu)
|
||||
btnMenu->Render();
|
||||
}
|
||||
void OptionKey::ButtonPressed(int controllerId, int controlId) {
|
||||
|
||||
void OptionKey::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
to = btnList[controlId];
|
||||
SAFE_DELETE(btnMenu);
|
||||
btnMenu = NULL;
|
||||
}
|
||||
bool OptionKey::Visible() { return JGE_BTN_NONE != to || LOCAL_KEY_NONE == from || btnMenu != NULL; }
|
||||
bool OptionKey::Selectable() { return JGE_BTN_NONE != to || LOCAL_KEY_NONE == from || btnMenu != NULL; }
|
||||
|
||||
bool OptionKey::Visible()
|
||||
{
|
||||
return JGE_BTN_NONE != to || LOCAL_KEY_NONE == from || btnMenu != NULL;
|
||||
}
|
||||
|
||||
bool OptionKey::Selectable()
|
||||
{
|
||||
return JGE_BTN_NONE != to || LOCAL_KEY_NONE == from || btnMenu != NULL;
|
||||
}
|
||||
|
||||
@@ -5,80 +5,92 @@
|
||||
#include "Player.h"
|
||||
#include "WEvent.h"
|
||||
|
||||
|
||||
//Parses a string and gives phase numer
|
||||
int PhaseRing::phaseStrToInt(string s){
|
||||
int PhaseRing::phaseStrToInt(string s)
|
||||
{
|
||||
if (s.compare("untap") == 0) return Constants::MTG_PHASE_UNTAP;
|
||||
if (s.compare("upkeep") == 0)return Constants::MTG_PHASE_UPKEEP;
|
||||
if (s.compare("draw") == 0)return Constants::MTG_PHASE_DRAW;
|
||||
if (s.compare("firstmain") == 0)return Constants::MTG_PHASE_FIRSTMAIN;
|
||||
if (s.compare("combatbegin") == 0)return Constants::MTG_PHASE_COMBATBEGIN;
|
||||
if (s.compare("combatattackers") == 0)return Constants::MTG_PHASE_COMBATATTACKERS;
|
||||
if (s.compare("combatblockers") == 0)return Constants::MTG_PHASE_COMBATBLOCKERS;
|
||||
if (s.compare("combatdamage") == 0)return Constants::MTG_PHASE_COMBATDAMAGE;
|
||||
if (s.compare("combatend") == 0)return Constants::MTG_PHASE_COMBATEND;
|
||||
if (s.compare("secondmain") == 0)return Constants::MTG_PHASE_SECONDMAIN;
|
||||
if (s.compare("endofturn") == 0)return Constants::MTG_PHASE_ENDOFTURN;
|
||||
if (s.compare("cleanup") == 0)return Constants::MTG_PHASE_CLEANUP;
|
||||
if (s.compare("upkeep") == 0) return Constants::MTG_PHASE_UPKEEP;
|
||||
if (s.compare("draw") == 0) return Constants::MTG_PHASE_DRAW;
|
||||
if (s.compare("firstmain") == 0) return Constants::MTG_PHASE_FIRSTMAIN;
|
||||
if (s.compare("combatbegin") == 0) return Constants::MTG_PHASE_COMBATBEGIN;
|
||||
if (s.compare("combatattackers") == 0) return Constants::MTG_PHASE_COMBATATTACKERS;
|
||||
if (s.compare("combatblockers") == 0) return Constants::MTG_PHASE_COMBATBLOCKERS;
|
||||
if (s.compare("combatdamage") == 0) return Constants::MTG_PHASE_COMBATDAMAGE;
|
||||
if (s.compare("combatend") == 0) return Constants::MTG_PHASE_COMBATEND;
|
||||
if (s.compare("secondmain") == 0) return Constants::MTG_PHASE_SECONDMAIN;
|
||||
if (s.compare("endofturn") == 0) return Constants::MTG_PHASE_ENDOFTURN;
|
||||
if (s.compare("cleanup") == 0) return Constants::MTG_PHASE_CLEANUP;
|
||||
DebugTrace("PHASERING: Unknown Phase name: " << s);
|
||||
|
||||
return Constants::MTG_PHASE_FIRSTMAIN;
|
||||
}
|
||||
|
||||
/* Creates a New phase ring with the default rules */
|
||||
PhaseRing::PhaseRing(Player* players[], int nbPlayers){
|
||||
for (int i = 0; i < nbPlayers; i++){
|
||||
for (int j = 0; j < Constants::NB_MTG_PHASES; j++){
|
||||
Phase * phase = NEW Phase(j,players[i]);
|
||||
PhaseRing::PhaseRing(Player* players[], int nbPlayers)
|
||||
{
|
||||
for (int i = 0; i < nbPlayers; i++)
|
||||
{
|
||||
for (int j = 0; j < Constants::NB_MTG_PHASES; j++)
|
||||
{
|
||||
Phase * phase = NEW Phase(j, players[i]);
|
||||
addPhase(phase);
|
||||
}
|
||||
}
|
||||
current = ring.begin();
|
||||
}
|
||||
|
||||
PhaseRing::~PhaseRing(){
|
||||
PhaseRing::~PhaseRing()
|
||||
{
|
||||
list<Phase *>::iterator it;
|
||||
for (it = ring.begin(); it != ring.end(); it++){
|
||||
for (it = ring.begin(); it != ring.end(); it++)
|
||||
{
|
||||
Phase * currentPhase = *it;
|
||||
delete(currentPhase);
|
||||
delete (currentPhase);
|
||||
}
|
||||
}
|
||||
|
||||
//Tells if next phase will be another Damage phase rather than combat ends
|
||||
bool PhaseRing::extraDamagePhase(int id){
|
||||
bool PhaseRing::extraDamagePhase(int id)
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (id != Constants::MTG_PHASE_COMBATEND) return false;
|
||||
if (g->combatStep != END_FIRST_STRIKE) return false;
|
||||
for (int j = 0; j < 2; ++j){
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
MTGGameZone * z = g->players[j]->game->inPlay;
|
||||
for (int i= 0; i < z->nb_cards; ++i){
|
||||
for (int i = 0; i < z->nb_cards; ++i)
|
||||
{
|
||||
MTGCardInstance * card = z->cards[i];
|
||||
if ((card->isAttacker() || card->isDefenser()) && !(card->has(Constants::FIRSTSTRIKE) || card->has(Constants::DOUBLESTRIKE))) return true;
|
||||
if ((card->isAttacker() || card->isDefenser()) && !(card->has(Constants::FIRSTSTRIKE) || card->has(
|
||||
Constants::DOUBLESTRIKE))) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * PhaseRing::phaseName(int id){
|
||||
const char * PhaseRing::phaseName(int id)
|
||||
{
|
||||
if (extraDamagePhase(id)) return "Combat Damage (2)";
|
||||
return Constants::MTGPhaseNames[id];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Phase * PhaseRing::getCurrentPhase(){
|
||||
if (current == ring.end()){
|
||||
Phase * PhaseRing::getCurrentPhase()
|
||||
{
|
||||
if (current == ring.end())
|
||||
{
|
||||
current = ring.begin();
|
||||
}
|
||||
return *current;
|
||||
}
|
||||
|
||||
Phase * PhaseRing::forward(bool sendEvents){
|
||||
Phase * PhaseRing::forward(bool sendEvents)
|
||||
{
|
||||
Phase * cPhaseOld = *current;
|
||||
if (current != ring.end()) current++;
|
||||
if (current == ring.end()) current = ring.begin();
|
||||
|
||||
if (sendEvents) {
|
||||
if (sendEvents)
|
||||
{
|
||||
//Warn the layers about the phase Change
|
||||
WEvent * e = NEW WEventPhaseChange(cPhaseOld, *current);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
@@ -87,9 +99,11 @@ Phase * PhaseRing::forward(bool sendEvents){
|
||||
return *current;
|
||||
}
|
||||
|
||||
Phase * PhaseRing::goToPhase(int id, Player * player, bool sendEvents){
|
||||
Phase * PhaseRing::goToPhase(int id, Player * player, bool sendEvents)
|
||||
{
|
||||
Phase * currentPhase = *current;
|
||||
while(currentPhase->id !=id || currentPhase->player != player){ //Dangerous, risk for inifinte loop !
|
||||
while (currentPhase->id != id || currentPhase->player != player)
|
||||
{ //Dangerous, risk for inifinte loop !
|
||||
|
||||
DebugTrace("PhasingRing: goToPhase called, current phase is " << phaseName(currentPhase->id));
|
||||
|
||||
@@ -98,37 +112,45 @@ Phase * PhaseRing::goToPhase(int id, Player * player, bool sendEvents){
|
||||
return currentPhase;
|
||||
}
|
||||
|
||||
|
||||
int PhaseRing::addPhase(Phase * phase){
|
||||
int PhaseRing::addPhase(Phase * phase)
|
||||
{
|
||||
ring.push_back(phase);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PhaseRing::addPhaseBefore(int id, Player* player,int after_id, Player * after_player, int allOccurences){
|
||||
int PhaseRing::addPhaseBefore(int id, Player* player, int after_id, Player * after_player, int allOccurences)
|
||||
{
|
||||
int result = 0;
|
||||
list<Phase *>::iterator it;
|
||||
for (it = ring.begin(); it != ring.end(); it++){
|
||||
for (it = ring.begin(); it != ring.end(); it++)
|
||||
{
|
||||
Phase * currentPhase = *it;
|
||||
if (currentPhase->id == after_id && currentPhase->player == after_player){
|
||||
if (currentPhase->id == after_id && currentPhase->player == after_player)
|
||||
{
|
||||
result++;
|
||||
ring.insert(it,NEW Phase(id,player));
|
||||
ring.insert(it, NEW Phase(id, player));
|
||||
if (!allOccurences) return 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int PhaseRing::removePhase (int id, Player * player, int allOccurences){
|
||||
int PhaseRing::removePhase(int id, Player * player, int allOccurences)
|
||||
{
|
||||
int result = 0;
|
||||
list<Phase *>::iterator it = ring.begin();
|
||||
while (it != ring.end()){
|
||||
while (it != ring.end())
|
||||
{
|
||||
Phase * currentPhase = *it;
|
||||
if (currentPhase->id == id && currentPhase->player == player){
|
||||
if (currentPhase->id == id && currentPhase->player == player)
|
||||
{
|
||||
if (current == it) current++; //Avoid our cursor to get invalidated
|
||||
it = ring.erase(it);
|
||||
delete(currentPhase);
|
||||
delete (currentPhase);
|
||||
result++;
|
||||
if (!allOccurences) return 1;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,18 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus) : JGuiObject(0), Pos(x, y, 1.0, 0.0, 255) {
|
||||
PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus) :
|
||||
JGuiObject(0), Pos(x, y, 1.0, 0.0, 255)
|
||||
{
|
||||
defaultHeight = desiredHeight;
|
||||
mHeight = desiredHeight;
|
||||
mHasFocus = hasFocus;
|
||||
type = 0;
|
||||
wave = 0;
|
||||
}
|
||||
PlayGuiObject::PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus) : JGuiObject(0), Pos(ref) {
|
||||
PlayGuiObject::PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus) :
|
||||
JGuiObject(0), Pos(ref)
|
||||
{
|
||||
defaultHeight = desiredHeight;
|
||||
mHeight = desiredHeight;
|
||||
mHasFocus = hasFocus;
|
||||
@@ -19,23 +23,21 @@ PlayGuiObject::PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus)
|
||||
wave = 0;
|
||||
}
|
||||
|
||||
|
||||
void PlayGuiObject::Update(float dt){
|
||||
void PlayGuiObject::Update(float dt)
|
||||
{
|
||||
if (mHasFocus && mHeight < defaultHeight * 1.2)
|
||||
{
|
||||
mHeight += defaultHeight * 0.8f * dt;
|
||||
// fprintf(stderr, "increasing size to %f - %d", mHeight, GetId() );
|
||||
|
||||
if (mHeight > defaultHeight * 1.2f)
|
||||
mHeight = defaultHeight * 1.2f;
|
||||
if (mHeight > defaultHeight * 1.2f) mHeight = defaultHeight * 1.2f;
|
||||
}
|
||||
else if (!mHasFocus && mHeight > defaultHeight)
|
||||
{
|
||||
mHeight -= defaultHeight * 0.8f * dt;
|
||||
if (mHeight < defaultHeight)
|
||||
mHeight = defaultHeight;
|
||||
if (mHeight < defaultHeight) mHeight = defaultHeight;
|
||||
}
|
||||
wave = (wave +2 * (int) (100 * dt) ) % 255;
|
||||
wave = (wave + 2 * (int) (100 * dt)) % 255;
|
||||
for (vector<Effect*>::iterator it = effects.begin(); it != effects.end(); ++it)
|
||||
(*it)->Update(dt);
|
||||
Pos::Update(dt);
|
||||
|
||||
@@ -7,86 +7,98 @@
|
||||
|
||||
int PlayGuiObjectController::showBigCards = 1;
|
||||
|
||||
int PlayGuiObjectController::getClosestItem(int direction){
|
||||
int PlayGuiObjectController::getClosestItem(int direction)
|
||||
{
|
||||
return getClosestItem(direction, 35);
|
||||
}
|
||||
|
||||
|
||||
int PlayGuiObjectController::getClosestItem(int direction, float tolerance){
|
||||
if (mCount == 0){
|
||||
int PlayGuiObjectController::getClosestItem(int direction, float tolerance)
|
||||
{
|
||||
if (mCount == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (mCount == 1){
|
||||
if (mCount == 1)
|
||||
{
|
||||
return mCurr;
|
||||
}
|
||||
|
||||
float maxDist = SCREEN_WIDTH * SCREEN_WIDTH;
|
||||
PlayGuiObject * current = (PlayGuiObject *)mObjects[mCurr];
|
||||
PlayGuiObject * current = (PlayGuiObject *) mObjects[mCurr];
|
||||
int closest_match = -1;
|
||||
int available = 0;
|
||||
float x0, y0, x1, y1;
|
||||
x0 = current->x;
|
||||
y0 = current->y;
|
||||
for (int i=0;i<mCount;i++){
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (i == mCurr) continue;
|
||||
PlayGuiObject * other = (PlayGuiObject *) mObjects[i];
|
||||
x1 = other->x;
|
||||
y1 = other->y;
|
||||
float dist = (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1);
|
||||
if (dist>=maxDist) continue;
|
||||
float dist = (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1);
|
||||
if (dist >= maxDist) continue;
|
||||
//Potential match !
|
||||
int ok = 0;
|
||||
switch(direction){
|
||||
switch (direction)
|
||||
{
|
||||
case DIR_DOWN:
|
||||
if (y1 > y0){
|
||||
if (y1 > y0)
|
||||
{
|
||||
available = 1;
|
||||
if (fabs(x0-x1) < tolerance ) ok = 1;
|
||||
if (fabs(x0 - x1) < tolerance) ok = 1;
|
||||
}
|
||||
break;
|
||||
case DIR_UP:
|
||||
if (y1 < y0){
|
||||
if (y1 < y0)
|
||||
{
|
||||
available = 1;
|
||||
if (fabs(x0-x1) < tolerance ) ok = 1;
|
||||
if (fabs(x0 - x1) < tolerance) ok = 1;
|
||||
}
|
||||
break;
|
||||
case DIR_LEFT:
|
||||
if (x1 < x0){
|
||||
if (x1 < x0)
|
||||
{
|
||||
available = 1;
|
||||
if (fabs(y0-y1) < tolerance ) ok = 1;
|
||||
if (fabs(y0 - y1) < tolerance) ok = 1;
|
||||
}
|
||||
break;
|
||||
case DIR_RIGHT:
|
||||
if (x1 > x0){
|
||||
if (x1 > x0)
|
||||
{
|
||||
available = 1;
|
||||
if (fabs(y0-y1) < tolerance ) ok = 1;
|
||||
if (fabs(y0 - y1) < tolerance) ok = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ok){
|
||||
if (ok)
|
||||
{
|
||||
closest_match = i;
|
||||
maxDist = dist;
|
||||
}
|
||||
}
|
||||
if (closest_match == -1){
|
||||
if (available) return getClosestItem(direction,tolerance+5);
|
||||
if (closest_match == -1)
|
||||
{
|
||||
if (available) return getClosestItem(direction, tolerance + 5);
|
||||
return mCurr;
|
||||
}
|
||||
return closest_match;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PlayGuiObjectController::Update(float dt){
|
||||
last_user_move +=dt;
|
||||
for (int i=0;i<mCount;i++){
|
||||
if (mObjects[i]!=NULL){
|
||||
void PlayGuiObjectController::Update(float dt)
|
||||
{
|
||||
last_user_move += dt;
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL)
|
||||
{
|
||||
mObjects[i]->Update(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool PlayGuiObjectController::CheckUserInput(JButton key){
|
||||
bool PlayGuiObjectController::CheckUserInput(JButton key)
|
||||
{
|
||||
/*
|
||||
if (!mCount)
|
||||
return false;
|
||||
|
||||
+43
-28
@@ -5,10 +5,9 @@
|
||||
#include "DeckStats.h"
|
||||
#include "ManaCost.h"
|
||||
|
||||
|
||||
|
||||
|
||||
Player::Player(MTGDeck * deck, string file, string fileSmall) : Damageable(20){
|
||||
Player::Player(MTGDeck * deck, string file, string fileSmall) :
|
||||
Damageable(20)
|
||||
{
|
||||
deckFile = file;
|
||||
deckFileSmall = fileSmall;
|
||||
manaPool = NEW ManaPool(this);
|
||||
@@ -29,20 +28,22 @@ Player::Player(MTGDeck * deck, string file, string fileSmall) : Damageable(20){
|
||||
mAvatarTex = NULL;
|
||||
type_as_damageable = DAMAGEABLE_PLAYER;
|
||||
playMode = MODE_HUMAN;
|
||||
if ( deck != NULL )
|
||||
if (deck != NULL)
|
||||
{
|
||||
game = NEW MTGPlayerCards( deck );
|
||||
game = NEW MTGPlayerCards(deck);
|
||||
game->setOwner(this);
|
||||
deckName = deck->meta_name;
|
||||
}
|
||||
}
|
||||
|
||||
/*Method to call at the end of a game, before all objects involved in the game are destroyed */
|
||||
void Player::End(){
|
||||
DeckStats::GetInstance()->saveStats(this, opponent(),GameObserver::GetInstance());
|
||||
void Player::End()
|
||||
{
|
||||
DeckStats::GetInstance()->saveStats(this, opponent(), GameObserver::GetInstance());
|
||||
}
|
||||
|
||||
Player::~Player(){
|
||||
Player::~Player()
|
||||
{
|
||||
SAFE_DELETE(manaPool);
|
||||
SAFE_DELETE(game);
|
||||
resources.Release(mAvatarTex);
|
||||
@@ -50,72 +51,86 @@ Player::~Player(){
|
||||
mAvatarTex = NULL;
|
||||
}
|
||||
|
||||
void Player::loadAvatar(string file){
|
||||
if (mAvatarTex) {
|
||||
void Player::loadAvatar(string file)
|
||||
{
|
||||
if (mAvatarTex)
|
||||
{
|
||||
resources.Release(mAvatarTex);
|
||||
mAvatar = NULL;
|
||||
mAvatarTex = NULL;
|
||||
}
|
||||
mAvatarTex = resources.RetrieveTexture(file,RETRIEVE_LOCK,TEXTURE_SUB_AVATAR);
|
||||
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);
|
||||
mAvatar = resources.RetrieveQuad(file, 0, 0, 35, 50, "playerAvatar", RETRIEVE_NORMAL, TEXTURE_SUB_AVATAR);
|
||||
else
|
||||
mAvatar = NULL;
|
||||
}
|
||||
|
||||
const string Player::getDisplayName() const {
|
||||
const string Player::getDisplayName() const
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (this == g->players[0]) return "Player 1";
|
||||
return "Player 2";
|
||||
}
|
||||
|
||||
MTGInPlay * Player::inPlay(){
|
||||
MTGInPlay * Player::inPlay()
|
||||
{
|
||||
return game->inPlay;
|
||||
}
|
||||
|
||||
int Player::getId(){
|
||||
int Player::getId()
|
||||
{
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
for (int i= 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (game->players[i] == this) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
JQuad * Player::getIcon(){
|
||||
JQuad * Player::getIcon()
|
||||
{
|
||||
return mAvatar;
|
||||
}
|
||||
|
||||
Player * Player::opponent(){
|
||||
Player * Player::opponent()
|
||||
{
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
if (!game) return NULL;
|
||||
return this == game->players[0] ? game->players[1] : game->players[0];
|
||||
}
|
||||
|
||||
|
||||
HumanPlayer::HumanPlayer(MTGDeck * deck, string file, string fileSmall) : Player(deck, file, fileSmall) {
|
||||
HumanPlayer::HumanPlayer(MTGDeck * deck, string file, string fileSmall) :
|
||||
Player(deck, file, fileSmall)
|
||||
{
|
||||
loadAvatar("avatar.jpg");
|
||||
playMode = MODE_HUMAN;
|
||||
}
|
||||
|
||||
|
||||
ManaPool * Player::getManaPool(){
|
||||
ManaPool * Player::getManaPool()
|
||||
{
|
||||
return manaPool;
|
||||
}
|
||||
|
||||
int Player::afterDamage(){
|
||||
int Player::afterDamage()
|
||||
{
|
||||
return life;
|
||||
}
|
||||
int Player::poisoned(){
|
||||
int Player::poisoned()
|
||||
{
|
||||
return poisonCount;
|
||||
}
|
||||
int Player::damaged(){
|
||||
int Player::damaged()
|
||||
{
|
||||
return damageCount;
|
||||
}
|
||||
int Player::prevented(){
|
||||
int Player::prevented()
|
||||
{
|
||||
return preventable;
|
||||
}
|
||||
//Cleanup phase at the end of a turn
|
||||
void Player::cleanupPhase(){
|
||||
void Player::cleanupPhase()
|
||||
{
|
||||
game->inPlay->cleanupPhase();
|
||||
game->graveyard->cleanupPhase();
|
||||
}
|
||||
|
||||
@@ -5,17 +5,21 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
PlayerData::PlayerData(){
|
||||
PlayerData::PlayerData()
|
||||
{
|
||||
init();
|
||||
}
|
||||
PlayerData::PlayerData(MTGAllCards * allcards){
|
||||
|
||||
PlayerData::PlayerData(MTGAllCards * allcards)
|
||||
{
|
||||
init();
|
||||
|
||||
//COLLECTION
|
||||
if (allcards) collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards);
|
||||
}
|
||||
|
||||
void PlayerData::init() {
|
||||
void PlayerData::init()
|
||||
{
|
||||
collection = NULL;
|
||||
|
||||
//CREDITS
|
||||
@@ -23,33 +27,33 @@ void PlayerData::init() {
|
||||
|
||||
std::ifstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
|
||||
std::string s;
|
||||
if(file){
|
||||
if(std::getline(file,s)){
|
||||
if (file)
|
||||
{
|
||||
if (std::getline(file, s))
|
||||
{
|
||||
credits = atoi(s.c_str());
|
||||
}else{
|
||||
}
|
||||
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;
|
||||
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;
|
||||
if (i == string::npos) continue;
|
||||
|
||||
string key = s.substr(0,i);
|
||||
string value = s.substr(i+1);
|
||||
if (key.size() < 3)
|
||||
continue;
|
||||
string key = s.substr(0, i);
|
||||
string value = s.substr(i + 1);
|
||||
if (key.size() < 3) continue;
|
||||
|
||||
if(key[0] != 's')
|
||||
continue;
|
||||
if (key[0] != 's') continue;
|
||||
key = key.substr(2);
|
||||
storySaves[key]=value;
|
||||
storySaves[key] = value;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -57,16 +61,19 @@ void PlayerData::init() {
|
||||
taskList = NEW TaskList(options.profileFile(PLAYER_TASKS).c_str());
|
||||
}
|
||||
|
||||
int PlayerData::save(){
|
||||
int PlayerData::save()
|
||||
{
|
||||
std::ofstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
|
||||
char writer[512];
|
||||
if (file){
|
||||
sprintf(writer,"%i\n", credits);
|
||||
file<<writer;
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -77,7 +84,8 @@ int PlayerData::save(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
PlayerData::~PlayerData(){
|
||||
PlayerData::~PlayerData()
|
||||
{
|
||||
SAFE_DELETE(collection);
|
||||
SAFE_DELETE(taskList);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
#include "JRenderer.h"
|
||||
#include "Pos.h"
|
||||
|
||||
Pos::Pos(float x, float y, float z, float t, float a) : actX(x), actY(y), actZ(z), actT(t), actA(a), x(x), y(y), zoom(z), t(t), alpha(a) {}
|
||||
Pos::Pos(float x, float y, float z, float t, float a) :
|
||||
actX(x), actY(y), actZ(z), actT(t), actA(a), x(x), y(y), zoom(z), t(t), alpha(a)
|
||||
{
|
||||
}
|
||||
void Pos::Update(float dt)
|
||||
{
|
||||
if (dt > 0.05f)
|
||||
dt = 0.05f;
|
||||
if (dt > 0.05f) dt = 0.05f;
|
||||
actX += 10 * dt * (x - actX);
|
||||
actY += 10 * dt * (y - actY);
|
||||
actT += 10 * dt * (t - actT);
|
||||
@@ -17,9 +19,15 @@ void Pos::Update(float dt)
|
||||
|
||||
void Pos::UpdateNow()
|
||||
{
|
||||
actX = x; actY = y; actT = t; actZ = zoom; actA = alpha;
|
||||
actX = x;
|
||||
actY = y;
|
||||
actT = t;
|
||||
actZ = zoom;
|
||||
actA = alpha;
|
||||
}
|
||||
void Pos::Render()
|
||||
{
|
||||
}
|
||||
void Pos::Render(){}
|
||||
void Pos::Render(JQuad* quad)
|
||||
{
|
||||
quad->SetColor(ARGB((int)actA, 255, 255, 255));
|
||||
|
||||
@@ -4,47 +4,55 @@
|
||||
|
||||
int PriceList::randomKey = 0;
|
||||
|
||||
PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collection(_collection){
|
||||
PriceList::PriceList(const char * _filename, MTGAllCards * _collection) :
|
||||
collection(_collection)
|
||||
{
|
||||
filename = _filename;
|
||||
std::ifstream file(_filename);
|
||||
std::string cardid;
|
||||
std::string price;
|
||||
if(file){
|
||||
while(std::getline(file,cardid)){
|
||||
std::getline(file,price);
|
||||
prices[atoi(cardid.c_str())]= atoi(price.c_str());
|
||||
if (file)
|
||||
{
|
||||
while (std::getline(file, cardid))
|
||||
{
|
||||
std::getline(file, price);
|
||||
prices[atoi(cardid.c_str())] = atoi(price.c_str());
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
if(randomKey == 0)
|
||||
randomKey = rand();
|
||||
if (randomKey == 0) randomKey = rand();
|
||||
}
|
||||
|
||||
|
||||
PriceList::~PriceList(){
|
||||
PriceList::~PriceList()
|
||||
{
|
||||
}
|
||||
|
||||
int PriceList::save(){
|
||||
int PriceList::save()
|
||||
{
|
||||
std::ofstream file(filename.c_str());
|
||||
char writer[20];
|
||||
if (file){
|
||||
map<int,int>::iterator it=prices.begin();
|
||||
while(it != prices.end()){
|
||||
sprintf(writer,"%i\n%i\n", (*it).first, (*it).second);
|
||||
if (file)
|
||||
{
|
||||
map<int, int>::iterator it = prices.begin();
|
||||
while (it != prices.end())
|
||||
{
|
||||
sprintf(writer, "%i\n%i\n", (*it).first, (*it).second);
|
||||
it++;
|
||||
file<<writer;
|
||||
file << writer;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
int PriceList::getPrice(int cardId){
|
||||
map<int,int>::iterator it = prices.find(cardId);
|
||||
int PriceList::getPrice(int cardId)
|
||||
{
|
||||
map<int, int>::iterator it = prices.find(cardId);
|
||||
if (it != prices.end()) return (*it).second;
|
||||
|
||||
char rarity = collection->getCardById(cardId)->getRarity();
|
||||
switch(rarity){
|
||||
switch (rarity)
|
||||
{
|
||||
case Constants::RARITY_M:
|
||||
return Constants::PRICE_1M;
|
||||
break;
|
||||
@@ -70,37 +78,51 @@ int PriceList::getPrice(int cardId){
|
||||
|
||||
}
|
||||
|
||||
int PriceList::setPrice(int cardId, int price){
|
||||
int PriceList::setPrice(int cardId, int price)
|
||||
{
|
||||
prices[cardId] = price;
|
||||
return price;
|
||||
}
|
||||
int PriceList::getSellPrice(int cardid){
|
||||
int PriceList::getSellPrice(int cardid)
|
||||
{
|
||||
return getPrice(cardid);
|
||||
}
|
||||
float PriceList::difficultyScalar(float price, int cardid){
|
||||
float badluck = (float)(abs(cardid + randomKey) % 201) / 100; //Float between 0 and 2.
|
||||
float PriceList::difficultyScalar(float price, int cardid)
|
||||
{
|
||||
float badluck = (float) (abs(cardid + randomKey) % 201) / 100; //Float between 0 and 2.
|
||||
|
||||
switch(options[Options::ECON_DIFFICULTY].number){
|
||||
switch (options[Options::ECON_DIFFICULTY].number)
|
||||
{
|
||||
case Constants::ECON_EASY:
|
||||
badluck -= 1.5; price /= 2; break; //Price from .25x to .75x, .25x more likely.
|
||||
case Constants::ECON_NORMAL: default:
|
||||
badluck /= 2; break; //price from 1x to 2x, even probability.
|
||||
badluck -= 1.5;
|
||||
price /= 2;
|
||||
break; //Price from .25x to .75x, .25x more likely.
|
||||
case Constants::ECON_NORMAL:
|
||||
default:
|
||||
badluck /= 2;
|
||||
break; //price from 1x to 2x, even probability.
|
||||
case Constants::ECON_HARD:
|
||||
price *= 1.5; break; //price from 1.5x to 3x, 3x being twice as likely.
|
||||
price *= 1.5;
|
||||
break; //price from 1.5x to 3x, 3x being twice as likely.
|
||||
case Constants::ECON_LUCK:
|
||||
badluck += .25; return price*badluck; break; //Price from .25x to 2.25x, randomly.
|
||||
badluck += .25;
|
||||
return price * badluck;
|
||||
break; //Price from .25x to 2.25x, randomly.
|
||||
}
|
||||
if(badluck > 1) badluck = 1;
|
||||
else if(badluck < -1) badluck = -1;
|
||||
if (badluck > 1)
|
||||
badluck = 1;
|
||||
else if (badluck < -1) badluck = -1;
|
||||
return (price + price * badluck);
|
||||
}
|
||||
int PriceList::getPurchasePrice(int cardid){
|
||||
float p = difficultyScalar((float)getPrice(cardid),cardid);
|
||||
if(p < 2) p = 2; //Prevents "Sell for 0 credits"
|
||||
return (int)p;
|
||||
int PriceList::getPurchasePrice(int cardid)
|
||||
{
|
||||
float p = difficultyScalar((float) getPrice(cardid), cardid);
|
||||
if (p < 2) p = 2; //Prevents "Sell for 0 credits"
|
||||
return (int) p;
|
||||
}
|
||||
int PriceList::getOtherPrice(int amt){
|
||||
float p = difficultyScalar((float)amt,0);
|
||||
if(p < 2) p = 2;
|
||||
return (int)p;
|
||||
int PriceList::getOtherPrice(int amt)
|
||||
{
|
||||
float p = difficultyScalar((float) amt, 0);
|
||||
if (p < 2) p = 2;
|
||||
return (int) p;
|
||||
}
|
||||
|
||||
@@ -4,29 +4,32 @@
|
||||
#include "MTGCardInstance.h"
|
||||
#include "TargetChooser.h"
|
||||
|
||||
|
||||
|
||||
REDamagePrevention::REDamagePrevention(MTGAbility * source, TargetChooser *tcSource, TargetChooser *tcTarget, int damage, bool oneShot, int typeOfDamage):source(source), tcSource(tcSource), tcTarget(tcTarget), damage(damage), oneShot(oneShot), typeOfDamage(typeOfDamage){
|
||||
REDamagePrevention::REDamagePrevention(MTGAbility * source, TargetChooser *tcSource, TargetChooser *tcTarget, int damage,
|
||||
bool oneShot, int typeOfDamage) :
|
||||
source(source), tcSource(tcSource), tcTarget(tcTarget), damage(damage), oneShot(oneShot), typeOfDamage(typeOfDamage)
|
||||
{
|
||||
}
|
||||
|
||||
WEvent * REDamagePrevention::replace (WEvent *event){
|
||||
WEvent * REDamagePrevention::replace(WEvent *event)
|
||||
{
|
||||
if (!event) return event;
|
||||
if (!damage) return event;
|
||||
WEventDamage * e = dynamic_cast<WEventDamage*>(event);
|
||||
WEventDamage * e = dynamic_cast<WEventDamage*> (event);
|
||||
if (!e) return event;
|
||||
Damage *d = e->damage;
|
||||
if (d->typeOfDamage != typeOfDamage && typeOfDamage != DAMAGE_ALL_TYPES) return event;
|
||||
if ((!tcSource || tcSource->canTarget(d->source)) &&
|
||||
(!tcTarget || tcTarget->canTarget(d->target))
|
||||
){
|
||||
if (damage == -1){
|
||||
if ((!tcSource || tcSource->canTarget(d->source)) && (!tcTarget || tcTarget->canTarget(d->target)))
|
||||
{
|
||||
if (damage == -1)
|
||||
{
|
||||
d->damage = 0;
|
||||
delete event;
|
||||
if (oneShot) damage = 0;
|
||||
return NULL;
|
||||
}
|
||||
if (damage >= d->damage){
|
||||
damage-= d->damage;
|
||||
if (damage >= d->damage)
|
||||
{
|
||||
damage -= d->damage;
|
||||
d->damage = 0;
|
||||
delete event;
|
||||
return NULL;
|
||||
@@ -39,17 +42,22 @@ WEvent * REDamagePrevention::replace (WEvent *event){
|
||||
}
|
||||
return event;
|
||||
}
|
||||
REDamagePrevention::~REDamagePrevention(){
|
||||
REDamagePrevention::~REDamagePrevention()
|
||||
{
|
||||
SAFE_DELETE(tcSource);
|
||||
SAFE_DELETE(tcTarget);
|
||||
}
|
||||
|
||||
ReplacementEffects::ReplacementEffects(){}
|
||||
ReplacementEffects::ReplacementEffects()
|
||||
{
|
||||
}
|
||||
|
||||
WEvent * ReplacementEffects::replace(WEvent *e){
|
||||
WEvent * ReplacementEffects::replace(WEvent *e)
|
||||
{
|
||||
list<ReplacementEffect *>::iterator it;
|
||||
|
||||
for ( it=modifiers.begin() ; it != modifiers.end(); it++ ){
|
||||
for (it = modifiers.begin(); it != modifiers.end(); it++)
|
||||
{
|
||||
ReplacementEffect *re = *it;
|
||||
WEvent * newEvent = re->replace(e);
|
||||
if (!newEvent) return NULL;
|
||||
@@ -58,21 +66,25 @@ WEvent * ReplacementEffects::replace(WEvent *e){
|
||||
return e;
|
||||
}
|
||||
|
||||
int ReplacementEffects::add(ReplacementEffect * re){
|
||||
int ReplacementEffects::add(ReplacementEffect * re)
|
||||
{
|
||||
modifiers.push_back(re);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ReplacementEffects::remove (ReplacementEffect *re){
|
||||
int ReplacementEffects::remove(ReplacementEffect *re)
|
||||
{
|
||||
modifiers.remove(re);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ReplacementEffects::~ReplacementEffects(){
|
||||
ReplacementEffects::~ReplacementEffects()
|
||||
{
|
||||
list<ReplacementEffect *>::iterator it;
|
||||
for ( it=modifiers.begin() ; it != modifiers.end(); it++ ){
|
||||
for (it = modifiers.begin(); it != modifiers.end(); it++)
|
||||
{
|
||||
ReplacementEffect *re = *it;
|
||||
delete(re);
|
||||
delete (re);
|
||||
}
|
||||
modifiers.clear();
|
||||
}
|
||||
|
||||
+259
-152
@@ -11,7 +11,8 @@
|
||||
#include "DeckManager.h"
|
||||
#include "AIPlayer.h"
|
||||
|
||||
int Rules::getMTGId(string cardName){
|
||||
int Rules::getMTGId(string cardName)
|
||||
{
|
||||
int cardnb = atoi(cardName.c_str());
|
||||
if (cardnb) return cardnb;
|
||||
if (cardName.compare("*") == 0) return -1; //Any card
|
||||
@@ -21,14 +22,18 @@ int Rules::getMTGId(string cardName){
|
||||
return 0;
|
||||
}
|
||||
|
||||
MTGCardInstance * Rules::getCardByMTGId(int mtgid){
|
||||
MTGCardInstance * Rules::getCardByMTGId(int mtgid)
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
for (int i = 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Player * p = g->players[i];
|
||||
MTGGameZone * zones[] = {p->game->library,p->game->hand, p->game->inPlay, p->game->graveyard};
|
||||
for (int j = 0; j < 4; j++){
|
||||
MTGGameZone * zones[] = { p->game->library, p->game->hand, p->game->inPlay, p->game->graveyard };
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
MTGGameZone * zone = zones[j];
|
||||
for (int k = 0; k < zone->nb_cards; k++){
|
||||
for (int k = 0; k < zone->nb_cards; k++)
|
||||
{
|
||||
MTGCardInstance * card = zone->cards[k];
|
||||
if (!card) return NULL;
|
||||
if (card->getMTGId() == mtgid) return card;
|
||||
@@ -38,7 +43,8 @@ MTGCardInstance * Rules::getCardByMTGId(int mtgid){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RulesPlayerData::RulesPlayerData(){
|
||||
RulesPlayerData::RulesPlayerData()
|
||||
{
|
||||
life = 20;
|
||||
poisonCount = 0;
|
||||
damageCount = 0;
|
||||
@@ -47,121 +53,170 @@ RulesPlayerData::RulesPlayerData(){
|
||||
avatar = "";
|
||||
}
|
||||
|
||||
RulesPlayerData::~RulesPlayerData(){
|
||||
RulesPlayerData::~RulesPlayerData()
|
||||
{
|
||||
SAFE_DELETE(manapool);
|
||||
}
|
||||
|
||||
RulesPlayerZone::RulesPlayerZone(){
|
||||
RulesPlayerZone::RulesPlayerZone()
|
||||
{
|
||||
}
|
||||
|
||||
void RulesPlayerZone::add(int cardId){
|
||||
void RulesPlayerZone::add(int cardId)
|
||||
{
|
||||
cards.push_back(cardId);
|
||||
}
|
||||
|
||||
RulesState::RulesState(){
|
||||
RulesState::RulesState()
|
||||
{
|
||||
phase = Constants::MTG_PHASE_FIRSTMAIN;
|
||||
player = 0;
|
||||
}
|
||||
|
||||
void RulesState::parsePlayerState(int playerId, string s){
|
||||
void RulesState::parsePlayerState(int playerId, string s)
|
||||
{
|
||||
size_t limiter = s.find("=");
|
||||
if (limiter == string::npos) limiter = s.find(":");
|
||||
string areaS;
|
||||
int area;
|
||||
if (limiter != string::npos){
|
||||
areaS = s.substr(0,limiter);
|
||||
if (areaS.compare("graveyard") == 0){
|
||||
if (limiter != string::npos)
|
||||
{
|
||||
areaS = s.substr(0, limiter);
|
||||
if (areaS.compare("graveyard") == 0)
|
||||
{
|
||||
area = 0;
|
||||
}else if(areaS.compare("library") == 0){
|
||||
}
|
||||
else if (areaS.compare("library") == 0)
|
||||
{
|
||||
area = 1;
|
||||
}else if(areaS.compare("hand") == 0){
|
||||
}
|
||||
else if (areaS.compare("hand") == 0)
|
||||
{
|
||||
area = 2;
|
||||
}else if(areaS.compare("inplay") == 0 || areaS.compare("battlefield") == 0 ){
|
||||
}
|
||||
else if (areaS.compare("inplay") == 0 || areaS.compare("battlefield") == 0)
|
||||
{
|
||||
area = 3;
|
||||
}else if(areaS.compare("life") == 0){
|
||||
playerData[playerId].life = atoi((s.substr(limiter+1)).c_str());
|
||||
}
|
||||
else if (areaS.compare("life") == 0)
|
||||
{
|
||||
playerData[playerId].life = atoi((s.substr(limiter + 1)).c_str());
|
||||
return;
|
||||
}else if(areaS.compare("poisonCount") == 0){
|
||||
playerData[playerId].poisonCount = atoi((s.substr(limiter+1)).c_str());
|
||||
}
|
||||
else if (areaS.compare("poisonCount") == 0)
|
||||
{
|
||||
playerData[playerId].poisonCount = atoi((s.substr(limiter + 1)).c_str());
|
||||
return;
|
||||
}else if(areaS.compare("damageCount") == 0){
|
||||
playerData[playerId].damageCount = atoi((s.substr(limiter+1)).c_str());
|
||||
}
|
||||
else if (areaS.compare("damageCount") == 0)
|
||||
{
|
||||
playerData[playerId].damageCount = atoi((s.substr(limiter + 1)).c_str());
|
||||
return;
|
||||
}else if(areaS.compare("preventable") == 0){
|
||||
playerData[playerId].preventable = atoi((s.substr(limiter+1)).c_str());
|
||||
}
|
||||
else if (areaS.compare("preventable") == 0)
|
||||
{
|
||||
playerData[playerId].preventable = atoi((s.substr(limiter + 1)).c_str());
|
||||
return;
|
||||
}else if(areaS.compare("avatar") == 0){
|
||||
playerData[playerId].avatar = s.substr(limiter+1);
|
||||
}
|
||||
else if (areaS.compare("avatar") == 0)
|
||||
{
|
||||
playerData[playerId].avatar = s.substr(limiter + 1);
|
||||
return;
|
||||
}else if(areaS.compare("manapool") == 0){
|
||||
}
|
||||
else if (areaS.compare("manapool") == 0)
|
||||
{
|
||||
SAFE_DELETE(playerData[playerId].manapool);
|
||||
playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter+1));
|
||||
playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter + 1));
|
||||
return;
|
||||
}else if(areaS.compare("auto") == 0){
|
||||
playerData[playerId].extraRules.push_back(s.substr(limiter+1));
|
||||
}
|
||||
else if (areaS.compare("auto") == 0)
|
||||
{
|
||||
playerData[playerId].extraRules.push_back(s.substr(limiter + 1));
|
||||
return;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // ERROR
|
||||
}
|
||||
s = s.substr(limiter+1);
|
||||
while (s.size()){
|
||||
s = s.substr(limiter + 1);
|
||||
while (s.size())
|
||||
{
|
||||
unsigned int value;
|
||||
limiter = s.find(",");
|
||||
if (limiter != string::npos){
|
||||
value = Rules::getMTGId(s.substr(0,limiter));
|
||||
s = s.substr(limiter+1);
|
||||
}else{
|
||||
if (limiter != string::npos)
|
||||
{
|
||||
value = Rules::getMTGId(s.substr(0, limiter));
|
||||
s = s.substr(limiter + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = Rules::getMTGId(s);
|
||||
s = "";
|
||||
}
|
||||
if (value) playerData[playerId].zones[area].add(value);
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
//ERROR
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Rules::addExtraRules(){
|
||||
void Rules::addExtraRules()
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
|
||||
int id = g->mLayers->actionLayer()->getMaxId();
|
||||
for (int i = 0; i < 2; ++i){
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
Player * p = g->players[i];
|
||||
//Trick so that the abilities don't die;
|
||||
MTGCardInstance::ExtraRules[i].currentZone = p->game->inPlay;
|
||||
MTGCardInstance::ExtraRules[i].lastController = p;
|
||||
for (size_t j = 0; j< initState.playerData[i].extraRules.size(); ++j){
|
||||
for (size_t j = 0; j < initState.playerData[i].extraRules.size(); ++j)
|
||||
{
|
||||
AbilityFactory af;
|
||||
MTGPlayerCards * hand = NULL;
|
||||
int handsize = 7;
|
||||
int difficultyRating = 0;
|
||||
MTGAbility * a = af.parseMagicLine(initState.playerData[i].extraRules[j], id++, NULL,&MTGCardInstance::ExtraRules[i]);
|
||||
if(p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode != GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode != GAME_TYPE_STORY)//keep this out of mimor and other game modes.
|
||||
MTGAbility * a = af.parseMagicLine(initState.playerData[i].extraRules[j], id++, NULL, &MTGCardInstance::ExtraRules[i]);
|
||||
if (p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
|
||||
!= GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode
|
||||
!= GAME_TYPE_STORY)//keep this out of mimor and other game modes.
|
||||
{
|
||||
difficultyRating = DeckManager::getDifficultyRating( g->players[0], g->players[1] );
|
||||
difficultyRating = DeckManager::getDifficultyRating(g->players[0], g->players[1]);
|
||||
}
|
||||
|
||||
if (a){
|
||||
if (a->oneShot){
|
||||
if(p->isAI() && a->aType == MTGAbility::STANDARD_DRAW && difficultyRating == EASY && p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode != GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode != GAME_TYPE_STORY)//stupid protections to keep this out of mimor and other game modes.
|
||||
if (a)
|
||||
{
|
||||
if (a->oneShot)
|
||||
{
|
||||
if (p->isAI() && a->aType == MTGAbility::STANDARD_DRAW && difficultyRating == EASY && p->playMode
|
||||
!= Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
|
||||
!= GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode
|
||||
!= GAME_TYPE_STORY)//stupid protections to keep this out of mimor and other game modes.
|
||||
{
|
||||
handsize = a->nbcardAmount;
|
||||
((AIPlayer *)p)->forceBestAbilityUse = true;
|
||||
((AIPlayer *)p)->agressivity += 100;
|
||||
hand->OptimizedHand(handsize,3,1,3);//easy decks get a major boost, open hand is 2lands,1 creature under 3 mana,3spells under 3 mana.
|
||||
((AIPlayer *) p)->forceBestAbilityUse = true;
|
||||
((AIPlayer *) p)->agressivity += 100;
|
||||
hand->OptimizedHand(handsize, 3, 1, 3);//easy decks get a major boost, open hand is 2lands,1 creature under 3 mana,3spells under 3 mana.
|
||||
}
|
||||
else if(p->isAI() && a->aType == MTGAbility::STANDARD_DRAW && difficultyRating == NORMAL && p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode != GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode != GAME_TYPE_STORY)//stupid protections to keep this out of mimor and other game modes.
|
||||
else if (p->isAI() && a->aType == MTGAbility::STANDARD_DRAW && difficultyRating == NORMAL && p->playMode
|
||||
!= Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
|
||||
!= GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode
|
||||
!= GAME_TYPE_STORY)//stupid protections to keep this out of mimor and other game modes.
|
||||
{
|
||||
handsize = a->nbcardAmount;
|
||||
hand->OptimizedHand(handsize,1,0,2);//give the Ai deck a tiny boost by giving it 1 land and 2 spells under 3 manacost.
|
||||
}else{//resolve normally if the deck is listed as hard.
|
||||
hand->OptimizedHand(handsize, 1, 0, 2);//give the Ai deck a tiny boost by giving it 1 land and 2 spells under 3 manacost.
|
||||
}
|
||||
else
|
||||
{//resolve normally if the deck is listed as hard.
|
||||
a->resolve();
|
||||
}
|
||||
delete(a);
|
||||
}else{
|
||||
delete (a);
|
||||
}
|
||||
else
|
||||
{
|
||||
a->addToGame();
|
||||
}
|
||||
|
||||
@@ -169,14 +224,19 @@ void Rules::addExtraRules(){
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j< extraRules.size(); ++j){
|
||||
for (size_t j = 0; j < extraRules.size(); ++j)
|
||||
{
|
||||
AbilityFactory af;
|
||||
MTGAbility * a = af.parseMagicLine(extraRules[j], id++, NULL,&MTGCardInstance::ExtraRules[0]);
|
||||
if (a){
|
||||
if (a->oneShot){
|
||||
MTGAbility * a = af.parseMagicLine(extraRules[j], id++, NULL, &MTGCardInstance::ExtraRules[0]);
|
||||
if (a)
|
||||
{
|
||||
if (a->oneShot)
|
||||
{
|
||||
a->resolve();
|
||||
delete(a);
|
||||
}else{
|
||||
delete (a);
|
||||
}
|
||||
else
|
||||
{
|
||||
a->addToGame();
|
||||
}
|
||||
}
|
||||
@@ -184,48 +244,49 @@ void Rules::addExtraRules(){
|
||||
|
||||
}
|
||||
|
||||
Player * Rules::loadPlayerMomir(int isAI){
|
||||
Player * Rules::loadPlayerMomir(int isAI)
|
||||
{
|
||||
string deckFileSmall = "momir";
|
||||
char empty[] = "";
|
||||
|
||||
MTGDeck * tempDeck = NEW MTGDeck(GameApp::collection); //Autogenerate a momir deck. Leave the "momir.txt" bits below for stats.
|
||||
tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Forest");
|
||||
tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Plains");
|
||||
tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Swamp");
|
||||
tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Mountain");
|
||||
tempDeck->addRandomCards(12, 0,0,Constants::RARITY_L,"Island");
|
||||
tempDeck->addRandomCards(12, 0, 0, Constants::RARITY_L, "Forest");
|
||||
tempDeck->addRandomCards(12, 0, 0, Constants::RARITY_L, "Plains");
|
||||
tempDeck->addRandomCards(12, 0, 0, Constants::RARITY_L, "Swamp");
|
||||
tempDeck->addRandomCards(12, 0, 0, Constants::RARITY_L, "Mountain");
|
||||
tempDeck->addRandomCards(12, 0, 0, Constants::RARITY_L, "Island");
|
||||
|
||||
Player *player = NULL;
|
||||
if (!isAI) // Human Player
|
||||
player = NEW HumanPlayer(tempDeck, options.profileFile("momir.txt","",true).c_str(), deckFileSmall);
|
||||
player = NEW HumanPlayer(tempDeck, options.profileFile("momir.txt", "", true).c_str(), deckFileSmall);
|
||||
else
|
||||
player = NEW AIMomirPlayer(tempDeck, options.profileFile("momir.txt","",true).c_str(), deckFileSmall, empty);
|
||||
player = NEW AIMomirPlayer(tempDeck, options.profileFile("momir.txt", "", true).c_str(), deckFileSmall, empty);
|
||||
|
||||
delete tempDeck;
|
||||
return player;
|
||||
}
|
||||
|
||||
Player * Rules::loadPlayerRandom(int isAI, int mode){
|
||||
Player * Rules::loadPlayerRandom(int isAI, int mode)
|
||||
{
|
||||
int color1 = 1 + WRand() % 5;
|
||||
int color2 = 1 + WRand() % 5;
|
||||
int color0 = Constants::MTG_COLOR_ARTIFACT;
|
||||
if (mode == GAME_TYPE_RANDOM1) color2 = color1;
|
||||
int colors[]={color1,color2,color0};
|
||||
int colors[] = { color1, color2, color0 };
|
||||
int nbcolors = 3;
|
||||
|
||||
string lands[] = {"forest", "forest", "island", "mountain", "swamp", "plains", "forest"};
|
||||
|
||||
string lands[] = { "forest", "forest", "island", "mountain", "swamp", "plains", "forest" };
|
||||
|
||||
MTGDeck * tempDeck = NEW MTGDeck(GameApp::collection);
|
||||
tempDeck->addRandomCards(9,0,0,-1,lands[color1].c_str());
|
||||
tempDeck->addRandomCards(9,0,0,-1,lands[color2].c_str());
|
||||
tempDeck->addRandomCards(1,0,0,'U',"land");
|
||||
tempDeck->addRandomCards(1,0,0,'R',"land");
|
||||
tempDeck->addRandomCards(12,0,0,-1,"creature",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"sorcery",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"enchantment",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"instant",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"artifact",colors,nbcolors);
|
||||
tempDeck->addRandomCards(9, 0, 0, -1, lands[color1].c_str());
|
||||
tempDeck->addRandomCards(9, 0, 0, -1, lands[color2].c_str());
|
||||
tempDeck->addRandomCards(1, 0, 0, 'U', "land");
|
||||
tempDeck->addRandomCards(1, 0, 0, 'R', "land");
|
||||
tempDeck->addRandomCards(12, 0, 0, -1, "creature", colors, nbcolors);
|
||||
tempDeck->addRandomCards(2, 0, 0, -1, "sorcery", colors, nbcolors);
|
||||
tempDeck->addRandomCards(2, 0, 0, -1, "enchantment", colors, nbcolors);
|
||||
tempDeck->addRandomCards(2, 0, 0, -1, "instant", colors, nbcolors);
|
||||
tempDeck->addRandomCards(2, 0, 0, -1, "artifact", colors, nbcolors);
|
||||
|
||||
string deckFile = "random";
|
||||
string deckFileSmall = "random";
|
||||
@@ -239,52 +300,60 @@ Player * Rules::loadPlayerRandom(int isAI, int mode){
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
Player * Rules::initPlayer(int playerId){
|
||||
Player * Rules::initPlayer(int playerId)
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
Player * p = g->players[playerId];
|
||||
if (!p) {
|
||||
if (!p)
|
||||
{
|
||||
int isAI = 1;
|
||||
if (GameApp::players[playerId] == PLAYER_TYPE_HUMAN) isAI = 0;
|
||||
switch(gamemode){
|
||||
switch (gamemode)
|
||||
{
|
||||
case GAME_TYPE_MOMIR:
|
||||
return loadPlayerMomir(isAI);
|
||||
case GAME_TYPE_CLASSIC:
|
||||
return NULL; //Error for the time being
|
||||
case GAME_TYPE_RANDOM1:
|
||||
return loadPlayerRandom(isAI,GAME_TYPE_RANDOM1);
|
||||
return loadPlayerRandom(isAI, GAME_TYPE_RANDOM1);
|
||||
case GAME_TYPE_RANDOM2:
|
||||
return loadPlayerRandom(isAI,GAME_TYPE_RANDOM2);
|
||||
return loadPlayerRandom(isAI, GAME_TYPE_RANDOM2);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
MTGDeck * Rules::buildDeck( int playerId){
|
||||
MTGDeck * Rules::buildDeck(int playerId)
|
||||
{
|
||||
int nbcards = 0;
|
||||
MTGDeck * deck = NEW MTGDeck(GameApp::collection);
|
||||
for (int j = 0; j < 4; j++){
|
||||
for (size_t k = 0; k < initState.playerData[playerId].zones[j].cards.size(); k++){
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
for (size_t k = 0; k < initState.playerData[playerId].zones[j].cards.size(); k++)
|
||||
{
|
||||
int cardid = initState.playerData[playerId].zones[j].cards[k];
|
||||
deck->add(cardid);
|
||||
nbcards++;
|
||||
}
|
||||
}
|
||||
if (!nbcards){
|
||||
delete(deck);
|
||||
if (!nbcards)
|
||||
{
|
||||
delete (deck);
|
||||
return NULL;
|
||||
}
|
||||
return deck;
|
||||
}
|
||||
|
||||
|
||||
void Rules::initPlayers(){
|
||||
void Rules::initPlayers()
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
for (int i = 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Player * p = initPlayer(i);
|
||||
g->players[i] = p;
|
||||
MTGDeck * deck = buildDeck(i);
|
||||
if (deck) {
|
||||
if (deck)
|
||||
{
|
||||
p->game->initDeck(deck);
|
||||
SAFE_DELETE(deck);
|
||||
p->game->setOwner(p);
|
||||
@@ -292,7 +361,8 @@ void Rules::initPlayers(){
|
||||
}
|
||||
}
|
||||
|
||||
void Rules::initGame(){
|
||||
void Rules::initGame()
|
||||
{
|
||||
//Put the GameObserver in the initial state
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
DebugTrace("RULES Init Game\n");
|
||||
@@ -305,84 +375,106 @@ void Rules::initGame(){
|
||||
g->phaseRing->goToPhase(initState.phase, g->currentPlayer);
|
||||
g->currentGamePhase = initState.phase;
|
||||
|
||||
|
||||
for (int i = 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Player * p = g->players[i];
|
||||
p->life = initState.playerData[i].life;
|
||||
p->poisonCount = initState.playerData[i].poisonCount;
|
||||
p->damageCount = initState.playerData[i].damageCount;
|
||||
p->preventable = initState.playerData[i].preventable;
|
||||
p->getManaPool()->copy(initState.playerData[i].manapool);
|
||||
if (initState.playerData[i].avatar.size()) {
|
||||
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 * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay };
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
MTGGameZone * zone = playerZones[j];
|
||||
for (size_t k = 0; k < initState.playerData[i].zones[j].cards.size(); k++){
|
||||
for (size_t k = 0; k < initState.playerData[i].zones[j].cards.size(); k++)
|
||||
{
|
||||
MTGCardInstance * card = getCardByMTGId(initState.playerData[i].zones[j].cards[k]);
|
||||
if (card && zone != p->game->library){
|
||||
if (zone == p->game->inPlay){
|
||||
if (card && zone != p->game->library)
|
||||
{
|
||||
if (zone == p->game->inPlay)
|
||||
{
|
||||
MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack);
|
||||
Spell * spell = NEW Spell(copy);
|
||||
spell->resolve();
|
||||
delete spell;
|
||||
}else{
|
||||
if (!p->game->library->hasCard(card)){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!p->game->library->hasCard(card))
|
||||
{
|
||||
LOG ("RULES ERROR, CARD NOT FOUND IN LIBRARY\n");
|
||||
}
|
||||
p->game->putInZone(card,p->game->library,zone);
|
||||
p->game->putInZone(card, p->game->library, zone);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!card)
|
||||
{
|
||||
LOG ("RULES ERROR, card is NULL\n");
|
||||
}
|
||||
}else{
|
||||
if (!card) { LOG ("RULES ERROR, card is NULL\n"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
addExtraRules();
|
||||
DebugTrace("RULES Init Game Done !\n");
|
||||
DebugTrace("RULES Init Game Done !\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RulesPlayerZone::cleanup(){
|
||||
void RulesPlayerZone::cleanup()
|
||||
{
|
||||
cards.clear();
|
||||
}
|
||||
|
||||
void RulesPlayerData::cleanup(){
|
||||
void RulesPlayerData::cleanup()
|
||||
{
|
||||
if (manapool) delete manapool;
|
||||
manapool = NULL;
|
||||
manapool = NEW ManaCost();
|
||||
for (int i = 0; i < 5; i++){
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
zones[i].cleanup();
|
||||
}
|
||||
life=20;
|
||||
poisonCount=0;
|
||||
damageCount=0;
|
||||
preventable=0;
|
||||
life = 20;
|
||||
poisonCount = 0;
|
||||
damageCount = 0;
|
||||
preventable = 0;
|
||||
}
|
||||
|
||||
void RulesState::cleanup(){
|
||||
for (int i = 0; i < 2; i++){
|
||||
void RulesState::cleanup()
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
playerData[i].cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void Rules::cleanup(){
|
||||
void Rules::cleanup()
|
||||
{
|
||||
initState.cleanup();
|
||||
}
|
||||
|
||||
Rules::Rules(string filename, string _bg){
|
||||
Rules::Rules(string filename, string _bg)
|
||||
{
|
||||
bg = _bg;
|
||||
load(filename);
|
||||
}
|
||||
|
||||
int Rules::load(string _filename){
|
||||
int Rules::load(string _filename)
|
||||
{
|
||||
|
||||
char filename[4096];
|
||||
if (fileExists(_filename.c_str())){
|
||||
if (fileExists(_filename.c_str()))
|
||||
{
|
||||
sprintf(filename, "%s", _filename.c_str());
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(filename, JGE_GET_RES("rules/%s").c_str(), _filename.c_str());
|
||||
}
|
||||
std::ifstream file(filename);
|
||||
@@ -394,43 +486,57 @@ int Rules::load(string _filename){
|
||||
if (!file) return 0;
|
||||
|
||||
cleanup();
|
||||
while(std::getline(file,s)){
|
||||
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[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
|
||||
if (s[0] == '#') continue;
|
||||
std::transform( s.begin(), s.end(), s.begin(),::tolower );
|
||||
if (s.find("include ") == 0) {
|
||||
load (s.substr(8));
|
||||
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
||||
if (s.find("include ") == 0)
|
||||
{
|
||||
load(s.substr(8));
|
||||
continue;
|
||||
}
|
||||
if (s.compare("[init]") == 0) {
|
||||
if (s.compare("[init]") == 0)
|
||||
{
|
||||
state = PARSE_INIT;
|
||||
continue;
|
||||
}
|
||||
if (s.compare("[players]") == 0) {
|
||||
if (s.compare("[players]") == 0)
|
||||
{
|
||||
state = PARSE_PLAYERS;
|
||||
continue;
|
||||
}
|
||||
if (s.compare("[player1]") == 0) {
|
||||
if (s.compare("[player1]") == 0)
|
||||
{
|
||||
state = PARSE_PLAYER1;
|
||||
continue;
|
||||
}
|
||||
if (s.compare("[player2]") == 0) {
|
||||
if (s.compare("[player2]") == 0)
|
||||
{
|
||||
state = PARSE_PLAYER2;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(state){
|
||||
switch (state)
|
||||
{
|
||||
case PARSE_UNDEFINED:
|
||||
break;
|
||||
case PARSE_INIT:
|
||||
if (s.find("auto=") == 0){
|
||||
if (s.find("auto=") == 0)
|
||||
{
|
||||
extraRules.push_back(s.substr(5));
|
||||
}else if (s.find("mode=") == 0) {
|
||||
}
|
||||
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{
|
||||
}
|
||||
else if (s.find("player=") == 0)
|
||||
{
|
||||
initState.player = atoi(s.substr(7).c_str()) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
initState.phase = PhaseRing::phaseStrToInt(s);
|
||||
}
|
||||
break;
|
||||
@@ -450,9 +556,10 @@ int Rules::load(string _filename){
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Rules::strToGameMode(string s){
|
||||
if (s.compare("momir")==0) return GAME_TYPE_MOMIR;
|
||||
if (s.compare("random1")==0) return GAME_TYPE_RANDOM1;
|
||||
if (s.compare("random2")==0) return GAME_TYPE_RANDOM2;
|
||||
int Rules::strToGameMode(string s)
|
||||
{
|
||||
if (s.compare("momir") == 0) return GAME_TYPE_MOMIR;
|
||||
if (s.compare("random1") == 0) return GAME_TYPE_RANDOM1;
|
||||
if (s.compare("random2") == 0) return GAME_TYPE_RANDOM2;
|
||||
return GAME_TYPE_CLASSIC;
|
||||
}
|
||||
|
||||
+273
-226
@@ -6,24 +6,23 @@
|
||||
#include "../include/Translate.h"
|
||||
#include <hge/hgedistort.h>
|
||||
|
||||
float ShopItems::_x1[] = { 79, 19, 27, 103, 154, 187, 102, 144, 198, 133, 183 };
|
||||
float ShopItems::_y1[] = { 150, 194, 222, 167, 164, 156, 195, 190, 175, 220, 220 };
|
||||
|
||||
float ShopItems::_x2[] = { 103, 48, 74, 135, 183, 215, 138, 181, 231, 171, 225 };
|
||||
float ShopItems::_y2[] = { 155, 179, 218, 165, 166, 155, 195, 186, 177, 225, 216 };
|
||||
|
||||
float ShopItems::_x1[] = { 79, 19, 27,103,154,187,102,144,198,133,183};
|
||||
float ShopItems::_y1[] = {150,194,222,167,164,156,195,190,175,220,220};
|
||||
float ShopItems::_x3[] = { 48, 61, 9, 96, 139, 190, 81, 146, 187, 97, 191 };
|
||||
float ShopItems::_y3[] = { 164, 205, 257, 184, 180, 170, 219, 212, 195, 251, 252 };
|
||||
|
||||
float ShopItems::_x2[] = {103, 48, 74,135,183,215,138,181,231,171,225};
|
||||
float ShopItems::_y2[] = {155,179,218,165,166,155,195,186,177,225,216};
|
||||
float ShopItems::_x4[] = { 76, 90, 65, 131, 171, 221, 123, 187, 225, 141, 237 };
|
||||
float ShopItems::_y4[] = { 169, 188, 250, 182, 182, 168, 220, 208, 198, 259, 245 };
|
||||
|
||||
float ShopItems::_x3[] = { 48, 61, 9, 96,139,190, 81,146,187, 97,191};
|
||||
float ShopItems::_y3[] = {164,205,257,184,180,170,219,212,195,251,252};
|
||||
|
||||
float ShopItems::_x4[] = { 76, 90, 65,131,171,221,123,187,225,141,237};
|
||||
float ShopItems::_y4[] = {169,188,250,182,182,168,220,208,198,259,245};
|
||||
|
||||
|
||||
ShopItem::ShopItem(int id, WFont *font, char* text, JQuad * _quad,JQuad * _thumb, float _xy[], bool hasFocus, int _price): JGuiObject(id), mFont(font), mText(text), quad(_quad), thumb(_thumb), price(_price)
|
||||
ShopItem::ShopItem(int id, WFont *font, char* text, JQuad * _quad, JQuad * _thumb, float _xy[], bool hasFocus, int _price) :
|
||||
JGuiObject(id), mFont(font), mText(text), quad(_quad), thumb(_thumb), price(_price)
|
||||
{
|
||||
for (int i = 0; i < 8; ++i){
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
xy[i] = _xy[i];
|
||||
}
|
||||
quantity = 10;
|
||||
@@ -34,26 +33,29 @@ ShopItem::ShopItem(int id, WFont *font, char* text, JQuad * _quad,JQuad * _thumb
|
||||
mScale = 1.0f;
|
||||
mTargetScale = 1.0f;
|
||||
|
||||
mesh=NEW hgeDistortionMesh(2,2);
|
||||
mesh = NEW hgeDistortionMesh(2, 2);
|
||||
mesh->SetTexture(thumb->mTex);
|
||||
float x0,y0,w0,h0;
|
||||
thumb->GetTextureRect(&x0,&y0,&w0,&h0);
|
||||
mesh->SetTextureRect(x0,y0,w0,h0);
|
||||
float x0, y0, w0, h0;
|
||||
thumb->GetTextureRect(&x0, &y0, &w0, &h0);
|
||||
mesh->SetTextureRect(x0, y0, w0, h0);
|
||||
mesh->Clear(ARGB(0xFF,0xFF,0xFF,0xFF));
|
||||
mesh->SetDisplacement(0, 0, xy[0],xy[1], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 0, xy[2] - w0,xy[3], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(0, 1,xy[4],xy[5]-h0, HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 1, xy[6]-w0,xy[7]-h0, HGEDISP_NODE);
|
||||
mesh->SetColor(1,1,ARGB(255,100,100,100));
|
||||
mesh->SetColor(0,1,ARGB(255,100,100,100));
|
||||
mesh->SetColor(1,0,ARGB(255,100,100,100));
|
||||
mesh->SetColor(0,0,ARGB(255,200,200,200));
|
||||
if (hasFocus)
|
||||
Entering();
|
||||
mesh->SetDisplacement(0, 0, xy[0], xy[1], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 0, xy[2] - w0, xy[3], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(0, 1, xy[4], xy[5] - h0, HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 1, xy[6] - w0, xy[7] - h0, HGEDISP_NODE);
|
||||
mesh->SetColor(1, 1, ARGB(255,100,100,100));
|
||||
mesh->SetColor(0, 1, ARGB(255,100,100,100));
|
||||
mesh->SetColor(1, 0, ARGB(255,100,100,100));
|
||||
mesh->SetColor(0, 0, ARGB(255,200,200,200));
|
||||
if (hasFocus) Entering();
|
||||
}
|
||||
|
||||
ShopItem::ShopItem(int id, WFont *font, int _cardid, float _xy[], bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw): JGuiObject(id), mFont(font), price(_price){
|
||||
for (int i = 0; i < 8; ++i){
|
||||
ShopItem::ShopItem(int id, WFont *font, int _cardid, float _xy[], bool hasFocus, MTGAllCards * collection, int _price,
|
||||
DeckDataWrapper * ddw) :
|
||||
JGuiObject(id), mFont(font), price(_price)
|
||||
{
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
xy[i] = _xy[i];
|
||||
}
|
||||
mHasFocus = hasFocus;
|
||||
@@ -61,8 +63,7 @@ ShopItem::ShopItem(int id, WFont *font, int _cardid, float _xy[], bool hasFocus,
|
||||
mScale = 1.0f;
|
||||
mTargetScale = 1.0f;
|
||||
|
||||
if (hasFocus)
|
||||
Entering();
|
||||
if (hasFocus) Entering();
|
||||
|
||||
card = collection->getCardById(_cardid);
|
||||
updateCount(ddw);
|
||||
@@ -76,38 +77,38 @@ ShopItem::ShopItem(int id, WFont *font, int _cardid, float _xy[], bool hasFocus,
|
||||
updateThumb();
|
||||
}
|
||||
|
||||
|
||||
int ShopItem::updateCount(DeckDataWrapper * ddw){
|
||||
int ShopItem::updateCount(DeckDataWrapper * ddw)
|
||||
{
|
||||
if (!card) return 0;
|
||||
nameCount = ddw->countByName(card);
|
||||
return nameCount;
|
||||
}
|
||||
|
||||
ShopItem::~ShopItem(){
|
||||
ShopItem::~ShopItem()
|
||||
{
|
||||
OutputDebugString("delete shopitem\n");
|
||||
if(thumb)
|
||||
resources.Release(thumb->mTex);
|
||||
if (thumb) resources.Release(thumb->mTex);
|
||||
SAFE_DELETE(mesh);
|
||||
}
|
||||
|
||||
const char * ShopItem::getText(){
|
||||
const char * ShopItem::getText()
|
||||
{
|
||||
return mText.c_str();
|
||||
}
|
||||
|
||||
void ShopItem::updateThumb(){
|
||||
if(card == NULL)
|
||||
return;
|
||||
void ShopItem::updateThumb()
|
||||
{
|
||||
if (card == NULL) return;
|
||||
|
||||
if(thumb && mRelease)
|
||||
resources.Release(thumb->mTex);
|
||||
if (thumb && mRelease) resources.Release(thumb->mTex);
|
||||
mRelease = false;
|
||||
|
||||
if(mesh)
|
||||
if (mesh)
|
||||
SAFE_DELETE(mesh);
|
||||
else if(thumb)
|
||||
else if (thumb)
|
||||
SAFE_DELETE(thumb);
|
||||
|
||||
thumb = resources.RetrieveCard(card,RETRIEVE_LOCK,TEXTURE_SUB_THUMB);
|
||||
thumb = resources.RetrieveCard(card, RETRIEVE_LOCK, TEXTURE_SUB_THUMB);
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
//On pcs we render the big image if the thumbnail is not available
|
||||
if (!thumb) thumb = resources.RetrieveCard(card,RETRIEVE_LOCK);
|
||||
@@ -117,62 +118,80 @@ void ShopItem::updateThumb(){
|
||||
else
|
||||
mRelease = true;
|
||||
|
||||
|
||||
if (thumb){
|
||||
mesh=NEW hgeDistortionMesh(2,2);
|
||||
if (thumb)
|
||||
{
|
||||
mesh = NEW hgeDistortionMesh(2, 2);
|
||||
mesh->SetTexture(thumb->mTex);
|
||||
float x0,y0,w0,h0;
|
||||
thumb->GetTextureRect(&x0,&y0,&w0,&h0);
|
||||
mesh->SetTextureRect(x0,y0,w0,h0);
|
||||
float x0, y0, w0, h0;
|
||||
thumb->GetTextureRect(&x0, &y0, &w0, &h0);
|
||||
mesh->SetTextureRect(x0, y0, w0, h0);
|
||||
mesh->Clear(ARGB(0xFF,0xFF,0xFF,0xFF));
|
||||
mesh->SetDisplacement(0, 0, xy[0],xy[1], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 0, xy[2] - w0,xy[3], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(0, 1,xy[4],xy[5]-h0, HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 1, xy[6]-w0,xy[7]-h0, HGEDISP_NODE);
|
||||
mesh->SetColor(1,1,ARGB(255,100,100,100));
|
||||
mesh->SetColor(0,1,ARGB(255,100,100,100));
|
||||
mesh->SetColor(1,0,ARGB(255,100,100,100));
|
||||
mesh->SetColor(0,0,ARGB(255,200,200,200));
|
||||
}else{
|
||||
mesh->SetDisplacement(0, 0, xy[0], xy[1], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 0, xy[2] - w0, xy[3], HGEDISP_NODE);
|
||||
mesh->SetDisplacement(0, 1, xy[4], xy[5] - h0, HGEDISP_NODE);
|
||||
mesh->SetDisplacement(1, 1, xy[6] - w0, xy[7] - h0, HGEDISP_NODE);
|
||||
mesh->SetColor(1, 1, ARGB(255,100,100,100));
|
||||
mesh->SetColor(0, 1, ARGB(255,100,100,100));
|
||||
mesh->SetColor(1, 0, ARGB(255,100,100,100));
|
||||
mesh->SetColor(0, 0, ARGB(255,200,200,200));
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ShopItem::Render(){
|
||||
if (mHasFocus){
|
||||
void ShopItem::Render()
|
||||
{
|
||||
if (mHasFocus)
|
||||
{
|
||||
mFont->SetColor(ARGB(255,255,255,0));
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
}
|
||||
if (!quantity){
|
||||
if (!quantity)
|
||||
{
|
||||
mFont->SetColor(ARGB(255,128,128,128));
|
||||
}
|
||||
|
||||
if (card){
|
||||
if (nameCount){
|
||||
if (card)
|
||||
{
|
||||
if (nameCount)
|
||||
{
|
||||
char buffer[512];
|
||||
sprintf(buffer, "%s (%i)", _(card->data->name).c_str(), nameCount );
|
||||
sprintf(buffer, "%s (%i)", _(card->data->name).c_str(), nameCount);
|
||||
mText = buffer;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
mText = _(card->data->name).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
|
||||
if (mesh){
|
||||
mesh->Render(0,0);
|
||||
}else{
|
||||
if (mesh)
|
||||
{
|
||||
mesh->Render(0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ERROR Management
|
||||
}
|
||||
if (mHasFocus){
|
||||
if (mHasFocus)
|
||||
{
|
||||
if (card) quad = resources.RetrieveCard(card);
|
||||
if (quad){
|
||||
float scale = 0.9 * 285/ quad->mHeight;
|
||||
if (quad)
|
||||
{
|
||||
float scale = 0.9 * 285 / quad->mHeight;
|
||||
quad->SetColor(ARGB(255,255,255,255));
|
||||
renderer->RenderQuad(quad,SCREEN_WIDTH - 105,SCREEN_HEIGHT/2 - 5,0, scale,scale);
|
||||
}else{
|
||||
if (card) CardGui::alternateRender(card,Pos(SCREEN_WIDTH - 105,SCREEN_HEIGHT/2 - 5,0.9f* 285/250, 0,255));
|
||||
renderer->RenderQuad(quad, SCREEN_WIDTH - 105, SCREEN_HEIGHT / 2 - 5, 0, scale, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (card) CardGui::alternateRender(card, Pos(SCREEN_WIDTH - 105, SCREEN_HEIGHT / 2 - 5, 0.9f * 285 / 250, 0, 255));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -180,116 +199,126 @@ void ShopItem::Render(){
|
||||
|
||||
void ShopItem::Update(float dt)
|
||||
{
|
||||
if (mScale < mTargetScale){
|
||||
mScale += 8.0f*dt;
|
||||
if (mScale > mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
}else if (mScale > mTargetScale){
|
||||
mScale -= 8.0f*dt;
|
||||
if (mScale < mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
{
|
||||
mScale += 8.0f * dt;
|
||||
if (mScale > mTargetScale) mScale = mTargetScale;
|
||||
}
|
||||
else if (mScale > mTargetScale)
|
||||
{
|
||||
mScale -= 8.0f * dt;
|
||||
if (mScale < mTargetScale) mScale = mTargetScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ShopItem::Entering()
|
||||
{
|
||||
for (int i = 0; i < 2; ++i){
|
||||
for (int j = 0; j < 2; ++j){
|
||||
mesh->SetColor(i,j,ARGB(255,255,255,255));
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
mesh->SetColor(i, j, ARGB(255,255,255,255));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mHasFocus = true;
|
||||
mTargetScale = 1.2f;
|
||||
}
|
||||
|
||||
|
||||
bool ShopItem::Leaving(JButton key)
|
||||
{
|
||||
mesh->SetColor(1,1,ARGB(255,100,100,100));
|
||||
mesh->SetColor(0,1,ARGB(255,100,100,100));
|
||||
mesh->SetColor(1,0,ARGB(255,100,100,100));
|
||||
mesh->SetColor(0,0,ARGB(255,200,200,200));
|
||||
mesh->SetColor(1, 1, ARGB(255,100,100,100));
|
||||
mesh->SetColor(0, 1, ARGB(255,100,100,100));
|
||||
mesh->SetColor(1, 0, ARGB(255,100,100,100));
|
||||
mesh->SetColor(0, 0, ARGB(255,200,200,200));
|
||||
|
||||
mHasFocus = false;
|
||||
mTargetScale = 1.0f;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ShopItem::ButtonPressed()
|
||||
{
|
||||
return (quantity >0);
|
||||
return (quantity > 0);
|
||||
}
|
||||
|
||||
|
||||
ShopItems::ShopItems(int id, JGuiListener* listener, WFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]): JGuiController(id, listener), mX(x), mY(y), mFont(font), collection(_collection){
|
||||
ShopItems::ShopItems(int id, JGuiListener* listener, WFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]) :
|
||||
JGuiController(id, listener), mX(x), mY(y), mFont(font), collection(_collection)
|
||||
{
|
||||
mHeight = 0;
|
||||
showPriceDialog = -1;
|
||||
dialog = NULL;
|
||||
pricelist = NEW PriceList(RESPATH"/settings/prices.dat",_collection);
|
||||
pricelist = NEW PriceList(RESPATH"/settings/prices.dat", _collection);
|
||||
playerdata = NEW PlayerData(_collection);
|
||||
display = NULL;
|
||||
for (int i=0; i < SHOP_BOOSTERS; i++){
|
||||
for (int i = 0; i < SHOP_BOOSTERS; i++)
|
||||
{
|
||||
setIds[i] = _setIds[i];
|
||||
};
|
||||
myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), _collection));
|
||||
showCardList = true;
|
||||
|
||||
mBgAA = NULL;
|
||||
mBgAATex = resources.RetrieveTexture("shop_aliasing.png",RETRIEVE_LOCK);
|
||||
if(mBgAATex){
|
||||
mBgAATex = resources.RetrieveTexture("shop_aliasing.png", RETRIEVE_LOCK);
|
||||
if (mBgAATex)
|
||||
{
|
||||
mBgAA = resources.RetrieveQuad("shop_aliasing.png");
|
||||
mBgAA->SetTextureRect(0,1,250,119);
|
||||
mBgAA->SetTextureRect(0, 1, 250, 119);
|
||||
}
|
||||
|
||||
lightAlpha = 0;
|
||||
alphaChange = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ShopItems::Add(int cardid){
|
||||
void ShopItems::Add(int cardid)
|
||||
{
|
||||
int rnd = (rand() % 20);
|
||||
int price = pricelist->getPrice(cardid);
|
||||
price = price + price * (rnd -10)/100;
|
||||
float xy[] = {_x1[mCount],_y1[mCount],_x2[mCount],_y2[mCount],_x3[mCount],_y3[mCount],_x4[mCount],_y4[mCount]};
|
||||
JGuiController::Add(NEW ShopItem(mCount, mFont, cardid, xy, (mCount == 0),collection, price,myCollection));
|
||||
price = price + price * (rnd - 10) / 100;
|
||||
float xy[] = { _x1[mCount], _y1[mCount], _x2[mCount], _y2[mCount], _x3[mCount], _y3[mCount], _x4[mCount], _y4[mCount] };
|
||||
JGuiController::Add(NEW ShopItem(mCount, mFont, cardid, xy, (mCount == 0), collection, price, myCollection));
|
||||
mHeight += 22;
|
||||
}
|
||||
|
||||
void ShopItems::Add(char * text, JQuad * quad,JQuad * thumb, int price){
|
||||
float xy[] = {_x1[mCount],_y1[mCount],_x2[mCount],_y2[mCount],_x3[mCount],_y3[mCount],_x4[mCount],_y4[mCount]};
|
||||
void ShopItems::Add(char * text, JQuad * quad, JQuad * thumb, int price)
|
||||
{
|
||||
float xy[] = { _x1[mCount], _y1[mCount], _x2[mCount], _y2[mCount], _x3[mCount], _y3[mCount], _x4[mCount], _y4[mCount] };
|
||||
JGuiController::Add(NEW ShopItem(mCount, mFont, text, quad, thumb, xy, (mCount == 0), price));
|
||||
mHeight += 22;
|
||||
}
|
||||
|
||||
void ShopItems::Update(float dt){
|
||||
void ShopItems::Update(float dt)
|
||||
{
|
||||
|
||||
if (display){
|
||||
if (display)
|
||||
{
|
||||
display->Update(dt);
|
||||
}else{
|
||||
if (showPriceDialog!=-1){
|
||||
ShopItem * item = ((ShopItem *)mObjects[showPriceDialog]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (showPriceDialog != -1)
|
||||
{
|
||||
ShopItem * item = ((ShopItem *) mObjects[showPriceDialog]);
|
||||
int price = item->price;
|
||||
char buffer[4096];
|
||||
sprintf(buffer,"%s : %i credits",item->getText(),price);
|
||||
if(!dialog){
|
||||
dialog = NEW SimpleMenu(1,this,Constants::MENU_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
|
||||
dialog->Add(1,"Yes");
|
||||
dialog->Add(2,"No");
|
||||
if(options[Options::CHEATMODE].number) {
|
||||
dialog->Add(3,"*Steal 1,000 credits*");
|
||||
sprintf(buffer, "%s : %i credits", item->getText(), price);
|
||||
if (!dialog)
|
||||
{
|
||||
dialog = NEW SimpleMenu(1, this, Constants::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, buffer);
|
||||
dialog->Add(1, "Yes");
|
||||
dialog->Add(2, "No");
|
||||
if (options[Options::CHEATMODE].number)
|
||||
{
|
||||
dialog->Add(3, "*Steal 1,000 credits*");
|
||||
}
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
dialog->Update(dt);
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
SAFE_DELETE(dialog);
|
||||
JGuiController::Update(dt);
|
||||
}
|
||||
@@ -297,156 +326,173 @@ void ShopItems::Update(float dt){
|
||||
}
|
||||
|
||||
alphaChange = (500 - (rand() % 1000)) * dt;
|
||||
lightAlpha+= alphaChange;
|
||||
lightAlpha += alphaChange;
|
||||
if (lightAlpha < 0) lightAlpha = 0;
|
||||
if (lightAlpha > 50) lightAlpha = 50;
|
||||
}
|
||||
|
||||
|
||||
void ShopItems::Render(){
|
||||
void ShopItems::Render()
|
||||
{
|
||||
JGuiController::Render();
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
|
||||
if (mBgAA) r->RenderQuad(mBgAA, 0, SCREEN_HEIGHT - 127);
|
||||
|
||||
if (mBgAA)
|
||||
r->RenderQuad(mBgAA,0,SCREEN_HEIGHT-127);
|
||||
|
||||
JQuad * quad = resources.RetrieveTempQuad("shop_light.jpg",TEXTURE_SUB_5551);
|
||||
if (quad){
|
||||
JQuad * quad = resources.RetrieveTempQuad("shop_light.jpg", TEXTURE_SUB_5551);
|
||||
if (quad)
|
||||
{
|
||||
r->EnableTextureFilter(false);
|
||||
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
quad->SetColor(ARGB(lightAlpha,255,255,255));
|
||||
r->RenderQuad(quad,0,0);
|
||||
r->RenderQuad(quad, 0, 0);
|
||||
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
r->EnableTextureFilter(true);
|
||||
}
|
||||
|
||||
|
||||
if (display) display->Render();
|
||||
|
||||
if (showPriceDialog!=-1){
|
||||
if(dialog){
|
||||
if (showPriceDialog != -1)
|
||||
{
|
||||
if (dialog)
|
||||
{
|
||||
dialog->Render();
|
||||
}
|
||||
}
|
||||
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
char c[4096];
|
||||
r->FillRect(0,SCREEN_HEIGHT-17,SCREEN_WIDTH,17,ARGB(128,0,0,0));
|
||||
r->FillRect(0, SCREEN_HEIGHT - 17, SCREEN_WIDTH, 17, ARGB(128,0,0,0));
|
||||
sprintf(c, "%s", _("[]:other cards").c_str());
|
||||
unsigned int len = 4 + mFont->GetStringWidth(c);
|
||||
mFont->DrawString(c,SCREEN_WIDTH-len,SCREEN_HEIGHT-14);
|
||||
mFont->DrawString(c, SCREEN_WIDTH - len, SCREEN_HEIGHT - 14);
|
||||
|
||||
char credits[512];
|
||||
sprintf(credits,_("credits: %i").c_str(), playerdata->credits);
|
||||
sprintf(credits, _("credits: %i").c_str(), playerdata->credits);
|
||||
mFont->SetColor(ARGB(200,0,0,0));
|
||||
mFont->DrawString(credits, 5, SCREEN_HEIGHT - 12);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(credits, 5, SCREEN_HEIGHT - 14);
|
||||
|
||||
if(mCurr >= 0){
|
||||
if (mCurr >= 0)
|
||||
{
|
||||
mFont->SetColor(ARGB(255,255,255,0));
|
||||
ShopItem * item = ((ShopItem *)mObjects[mCurr]);
|
||||
mFont->DrawString(item->mText.c_str(), SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT - 14,JGETEXT_CENTER);
|
||||
ShopItem * item = ((ShopItem *) mObjects[mCurr]);
|
||||
mFont->DrawString(item->mText.c_str(), SCREEN_WIDTH / 2 - 50, SCREEN_HEIGHT - 14, JGETEXT_CENTER);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
}
|
||||
|
||||
if (showCardList){
|
||||
r->FillRoundRect(290,5, 160, mCount * 20 + 15,5,ARGB(200,0,0,0));
|
||||
if (showCardList)
|
||||
{
|
||||
r->FillRoundRect(290, 5, 160, mCount * 20 + 15, 5, ARGB(200,0,0,0));
|
||||
|
||||
for (int i = 0; i< mCount; ++i){
|
||||
for (int i = 0; i < mCount; ++i)
|
||||
{
|
||||
if (!mObjects[i]) continue;
|
||||
ShopItem * s = (ShopItem *)(mObjects[i]);
|
||||
if (i == mCurr) mFont->SetColor(ARGB(255,255,255,0));
|
||||
else mFont->SetColor(ARGB(255,255,255,255));
|
||||
ShopItem * s = (ShopItem *) (mObjects[i]);
|
||||
if (i == mCurr)
|
||||
mFont->SetColor(ARGB(255,255,255,0));
|
||||
else
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
char buffer[512];
|
||||
sprintf(buffer, "%s", s->getText());
|
||||
float x = 300;
|
||||
float y = 10 + 20*i;
|
||||
mFont->DrawString(buffer,x,y);
|
||||
float y = 10 + 20 * i;
|
||||
mFont->DrawString(buffer, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShopItems::pricedialog(int id, int mode){
|
||||
if (mode){
|
||||
void ShopItems::pricedialog(int id, int mode)
|
||||
{
|
||||
if (mode)
|
||||
{
|
||||
showPriceDialog = id;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
showPriceDialog = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void ShopItems::ButtonPressed(int controllerId, int controlId){
|
||||
if (controllerId == 12){
|
||||
void ShopItems::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
if (controllerId == 12)
|
||||
{
|
||||
safeDeleteDisplay();
|
||||
return;
|
||||
}
|
||||
|
||||
ShopItem * item = ((ShopItem *)mObjects[showPriceDialog]);
|
||||
ShopItem * item = ((ShopItem *) mObjects[showPriceDialog]);
|
||||
int price = item->price;
|
||||
switch(controlId){
|
||||
switch (controlId)
|
||||
{
|
||||
case 1:
|
||||
if (playerdata->credits >= price){
|
||||
if (playerdata->credits >= price)
|
||||
{
|
||||
playerdata->credits -= price;
|
||||
if (item->card){
|
||||
if (item->card)
|
||||
{
|
||||
int rnd = (rand() % 25);
|
||||
price = price + (rnd * price)/100;
|
||||
pricelist->setPrice(item->card->getMTGId(),price);
|
||||
price = price + (rnd * price) / 100;
|
||||
pricelist->setPrice(item->card->getMTGId(), price);
|
||||
playerdata->collection->add(item->card);
|
||||
item->quantity--;
|
||||
myCollection->Add(item->card);
|
||||
item->nameCount++;
|
||||
item->price = price;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
safeDeleteDisplay();
|
||||
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
|
||||
display = NEW CardDisplay(12, NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT / 2, this, NULL, 5);
|
||||
|
||||
MTGDeck * tempDeck = NEW MTGDeck(playerdata->collection->database);
|
||||
int rare_or_mythic = Constants::RARITY_R;
|
||||
int rnd = rand() % 8;
|
||||
if (rnd == 0) rare_or_mythic = Constants::RARITY_M;
|
||||
int sets[] = {setIds[showPriceDialog]};
|
||||
int sets[] = { setIds[showPriceDialog] };
|
||||
MTGSetInfo* si = setlist.getInfo(setIds[showPriceDialog]);
|
||||
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::RARE], sets,1,rare_or_mythic);
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::UNCOMMON], sets,1,Constants::RARITY_U);
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::COMMON], sets,1,Constants::RARITY_C);
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::LAND], sets,1,Constants::RARITY_L);
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::RARE], sets, 1, rare_or_mythic);
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::UNCOMMON], sets, 1, Constants::RARITY_U);
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::COMMON], sets, 1, Constants::RARITY_C);
|
||||
tempDeck->addRandomCards(si->booster[MTGSetInfo::LAND], sets, 1, Constants::RARITY_L);
|
||||
|
||||
//Check for duplicates. Does not guarentee none, just makes them extremely unlikely.
|
||||
//Code is kind of inefficient, but shouldn't be used often enough to matter.
|
||||
int loops=0;
|
||||
for(map<int,int>::iterator it = tempDeck->cards.begin();it!= tempDeck->cards.end() && loops < 15;it++,loops++){
|
||||
int loops = 0;
|
||||
for (map<int, int>::iterator it = tempDeck->cards.begin(); it != tempDeck->cards.end() && loops < 15; it++, loops++)
|
||||
{
|
||||
int dupes = it->second - 1;
|
||||
if(dupes <= 0)
|
||||
continue;
|
||||
if (dupes <= 0) continue;
|
||||
|
||||
for(int x=0;x<dupes;x++)
|
||||
for (int x = 0; x < dupes; x++)
|
||||
tempDeck->remove(it->first);
|
||||
|
||||
int rarity = (int) tempDeck->database->getCardById(it->first)->getRarity();
|
||||
tempDeck->addRandomCards(dupes,sets,1,rarity);
|
||||
tempDeck->addRandomCards(dupes, sets, 1, rarity);
|
||||
it = tempDeck->cards.begin();
|
||||
}
|
||||
|
||||
playerdata->collection->add(tempDeck);
|
||||
myCollection->Add(tempDeck);
|
||||
|
||||
for (int j = 0; j < mCount; j++){
|
||||
ShopItem * si = ((ShopItem *)mObjects[j]);
|
||||
for (int j = 0; j < mCount; j++)
|
||||
{
|
||||
ShopItem * si = ((ShopItem *) mObjects[j]);
|
||||
si->updateCount(myCollection);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for(int cycle=0;cycle<4;cycle++)
|
||||
for (map<int,int>::iterator it = tempDeck->cards.begin(); it!=tempDeck->cards.end(); it++){
|
||||
for (int cycle = 0; cycle < 4; cycle++)
|
||||
for (map<int, int>::iterator it = tempDeck->cards.begin(); it != tempDeck->cards.end(); it++)
|
||||
{
|
||||
MTGCard * c = tempDeck->getCardById(it->first);
|
||||
char rarity = c->getRarity();
|
||||
if((cycle == 0 && rarity == Constants::RARITY_L)
|
||||
|| (cycle == 1 && rarity == Constants::RARITY_C)
|
||||
|| (cycle == 2 && rarity == Constants::RARITY_U)
|
||||
|| (cycle == 3 && (rarity == Constants::RARITY_R || rarity == Constants::RARITY_M)))
|
||||
for (int j = 0; j < it->second; j++){
|
||||
if ((cycle == 0 && rarity == Constants::RARITY_L) || (cycle == 1 && rarity == Constants::RARITY_C)
|
||||
|| (cycle == 2 && rarity == Constants::RARITY_U) || (cycle == 3 && (rarity
|
||||
== Constants::RARITY_R || rarity == Constants::RARITY_M))) for (int j = 0; j < it->second; j++)
|
||||
{
|
||||
MTGCardInstance * card = NEW MTGCardInstance(c, NULL);
|
||||
displayCards[i] = card;
|
||||
display->AddCard(card);
|
||||
@@ -456,21 +502,24 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
|
||||
delete tempDeck;
|
||||
}
|
||||
//Check if we just scored an award...
|
||||
if(myCollection && myCollection->totalPrice() > 10000){
|
||||
GameOptionAward * goa = dynamic_cast<GameOptionAward *>(&options[Options::AWARD_COLLECTOR]);
|
||||
if(goa)
|
||||
goa->giveAward();
|
||||
if (myCollection && myCollection->totalPrice() > 10000)
|
||||
{
|
||||
GameOptionAward * goa = dynamic_cast<GameOptionAward *> (&options[Options::AWARD_COLLECTOR]);
|
||||
if (goa) goa->giveAward();
|
||||
}
|
||||
showPriceDialog = -1;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
//error not enough money
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (item->card){
|
||||
if (item->card)
|
||||
{
|
||||
int rnd = (rand() % 25);
|
||||
price = price - (rnd * price)/100;
|
||||
pricelist->setPrice(item->card->getMTGId(),price);
|
||||
price = price - (rnd * price) / 100;
|
||||
pricelist->setPrice(item->card->getMTGId(), price);
|
||||
}
|
||||
showPriceDialog = -1;
|
||||
break;
|
||||
@@ -480,25 +529,29 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ShopItems::safeDeleteDisplay(){
|
||||
void ShopItems::safeDeleteDisplay()
|
||||
{
|
||||
if (!display) return;
|
||||
for (int i = 0; i < display->mCount; i++){
|
||||
for (int i = 0; i < display->mCount; i++)
|
||||
{
|
||||
delete displayCards[i];
|
||||
}
|
||||
SAFE_DELETE(display);
|
||||
}
|
||||
|
||||
void ShopItems::saveAll(){
|
||||
void ShopItems::saveAll()
|
||||
{
|
||||
savePriceList();
|
||||
playerdata->save();
|
||||
}
|
||||
|
||||
void ShopItems::savePriceList(){
|
||||
void ShopItems::savePriceList()
|
||||
{
|
||||
pricelist->save();
|
||||
}
|
||||
|
||||
ShopItems::~ShopItems(){
|
||||
ShopItems::~ShopItems()
|
||||
{
|
||||
SAFE_DELETE(pricelist);
|
||||
SAFE_DELETE(playerdata);
|
||||
SAFE_DELETE(dialog);
|
||||
@@ -509,45 +562,39 @@ ShopItems::~ShopItems(){
|
||||
|
||||
ostream& ShopItem::toString(ostream& out) const
|
||||
{
|
||||
return out << "ShopItem ::: mHasFocus : " << mHasFocus
|
||||
<< " ; mFont : " << mFont
|
||||
<< " ; mText : " << mText
|
||||
<< " ; quad : " << quad
|
||||
<< " ; thumb : " << thumb
|
||||
<< " ; mScale : " << mScale
|
||||
<< " ; mTargetScale : " << mTargetScale
|
||||
<< " ; nameCount : " << nameCount
|
||||
<< " ; quantity : " << quantity
|
||||
<< " ; card : " << card
|
||||
<< " ; price : " << price;
|
||||
return out << "ShopItem ::: mHasFocus : " << mHasFocus << " ; mFont : " << mFont << " ; mText : " << mText << " ; quad : "
|
||||
<< quad << " ; thumb : " << thumb << " ; mScale : " << mScale << " ; mTargetScale : " << mTargetScale
|
||||
<< " ; nameCount : " << nameCount << " ; quantity : " << quantity << " ; card : " << card << " ; price : "
|
||||
<< price;
|
||||
}
|
||||
|
||||
bool ShopItems::CheckUserInput(JButton key){
|
||||
if (display && display->CheckUserInput(key))
|
||||
return true;
|
||||
if (showPriceDialog == -1) {
|
||||
JButton buttons[] = {JGE_BTN_LEFT, JGE_BTN_DOWN, JGE_BTN_RIGHT, JGE_BTN_UP, JGE_BTN_OK};
|
||||
bool ShopItems::CheckUserInput(JButton key)
|
||||
{
|
||||
if (display && display->CheckUserInput(key)) return true;
|
||||
if (showPriceDialog == -1)
|
||||
{
|
||||
JButton buttons[] = { JGE_BTN_LEFT, JGE_BTN_DOWN, JGE_BTN_RIGHT, JGE_BTN_UP, JGE_BTN_OK };
|
||||
for (int i = 0; i < 5; ++i)
|
||||
if (key == buttons[i])
|
||||
showCardList = false;
|
||||
if (key == buttons[i]) showCardList = false;
|
||||
|
||||
if (key == JGE_BTN_CANCEL) {
|
||||
if (key == JGE_BTN_CANCEL)
|
||||
{
|
||||
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
|
||||
vector<JGuiObject*>::iterator it;
|
||||
for(it=mObjects.begin();it!=mObjects.end();it++){
|
||||
ShopItem * si = dynamic_cast<ShopItem*>(*it);
|
||||
if(si)
|
||||
si->updateThumb();
|
||||
for (it = mObjects.begin(); it != mObjects.end(); it++)
|
||||
{
|
||||
ShopItem * si = dynamic_cast<ShopItem*> (*it);
|
||||
if (si) si->updateThumb();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (key == JGE_BTN_SEC){
|
||||
if (key == JGE_BTN_SEC)
|
||||
{
|
||||
showCardList = !showCardList;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(dialog)
|
||||
return dialog->CheckUserInput(key);
|
||||
else if (dialog) return dialog->CheckUserInput(key);
|
||||
|
||||
return JGuiController::CheckUserInput(key);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ JTexture* SimpleMenu::sideTex = NULL;
|
||||
WFont* SimpleMenu::titleFont = NULL;
|
||||
hgeParticleSystem* SimpleMenu::stars = NULL;
|
||||
|
||||
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems): JGuiController(id, listener), fontId(fontId){
|
||||
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems) :
|
||||
JGuiController(id, listener), fontId(fontId)
|
||||
{
|
||||
autoTranslate = true;
|
||||
mHeight = 2 * kVerticalMargin;
|
||||
mWidth = 0;
|
||||
@@ -41,17 +43,16 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, floa
|
||||
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
if (!spadeLTex) spadeLTex= resources.RetrieveTexture("spade_ul.png", RETRIEVE_MANAGE);
|
||||
if (!spadeLTex) spadeLTex = resources.RetrieveTexture("spade_ul.png", RETRIEVE_MANAGE);
|
||||
if (!spadeRTex) spadeRTex = resources.RetrieveTexture("spade_ur.png", RETRIEVE_MANAGE);
|
||||
if (!jewelTex) jewelTex= renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM);
|
||||
if (!jewelTex) jewelTex = renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM);
|
||||
if (!sideTex) sideTex = resources.RetrieveTexture("menuside.png", RETRIEVE_MANAGE);
|
||||
if (NULL == spadeL) spadeL = resources.RetrieveQuad("spade_ul.png", 0, 0, 11, 11, "spade_ul", RETRIEVE_MANAGE);
|
||||
if (NULL == spadeR) spadeR = resources.RetrieveQuad("spade_ur.png", 0, 0, 11, 11, "spade_ur", RETRIEVE_MANAGE);
|
||||
if (NULL == jewel) jewel = NEW JQuad(jewelTex, 1, 1, 3, 3);
|
||||
if (NULL == side) side = resources.RetrieveQuad("menuside.png", 1, 1, 1, 7,"menuside", RETRIEVE_MANAGE);
|
||||
if (NULL == side) side = resources.RetrieveQuad("menuside.png", 1, 1, 1, 7, "menuside", RETRIEVE_MANAGE);
|
||||
|
||||
if (NULL == stars)
|
||||
stars = NEW hgeParticleSystem(resources.RetrievePSI("stars.psi", resources.GetQuad("stars")));
|
||||
if (NULL == stars) stars = NEW hgeParticleSystem(resources.RetrievePSI("stars.psi", resources.GetQuad("stars")));
|
||||
|
||||
stars->FireAt(mX, mY);
|
||||
}
|
||||
@@ -76,30 +77,35 @@ void SimpleMenu::drawVertPole(float x, float y, float height)
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
float offset = (spadeR->mHeight - kPoleWidth) / 2;
|
||||
renderer->RenderQuad(side, x + kPoleWidth, y, M_PI/2, height);
|
||||
renderer->RenderQuad(side, x + kPoleWidth, y, M_PI / 2, height);
|
||||
spadeR->SetHFlip(false);
|
||||
spadeL->SetHFlip(true);
|
||||
renderer->RenderQuad(spadeR, x + kPoleWidth + offset, y - offset, M_PI/2);
|
||||
renderer->RenderQuad(spadeL, x + kPoleWidth + offset, y - offset + height, M_PI/2);
|
||||
renderer->RenderQuad(spadeR, x + kPoleWidth + offset, y - offset, M_PI / 2);
|
||||
renderer->RenderQuad(spadeL, x + kPoleWidth + offset, y - offset + height, M_PI / 2);
|
||||
|
||||
renderer->RenderQuad(jewel, x - 1, y - 1);
|
||||
renderer->RenderQuad(jewel, x - 1, y + height - 1);
|
||||
}
|
||||
|
||||
void SimpleMenu::Render() {
|
||||
void SimpleMenu::Render()
|
||||
{
|
||||
WFont * titleFont = resources.GetWFont(Fonts::SMALLFACE_FONT);
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
if (0 == mWidth) {
|
||||
if (0 == mWidth)
|
||||
{
|
||||
float sY = mY + kVerticalMargin;
|
||||
for (int i = startId; i < startId + mCount; ++i) {
|
||||
float width = (static_cast<SimpleMenuItem*>(mObjects[i]))->GetWidth();
|
||||
for (int i = startId; i < startId + mCount; ++i)
|
||||
{
|
||||
float width = (static_cast<SimpleMenuItem*> (mObjects[i]))->GetWidth();
|
||||
if (mWidth < width) mWidth = width;
|
||||
}
|
||||
if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) mWidth = titleFont->GetStringWidth(title.c_str());
|
||||
mWidth += 2*kHorizontalMargin;
|
||||
for (int i = startId; i < startId + mCount; ++i) {
|
||||
if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) mWidth = titleFont->GetStringWidth(
|
||||
title.c_str());
|
||||
mWidth += 2 * kHorizontalMargin;
|
||||
for (int i = startId; i < startId + mCount; ++i)
|
||||
{
|
||||
float y = mY + kVerticalMargin + i * kLineHeight;
|
||||
SimpleMenuItem * smi = static_cast<SimpleMenuItem*>(mObjects[i]);
|
||||
SimpleMenuItem * smi = static_cast<SimpleMenuItem*> (mObjects[i]);
|
||||
smi->Relocate(mX + mWidth / 2, y);
|
||||
if (smi->hasFocus()) sY = y;
|
||||
}
|
||||
@@ -126,49 +132,64 @@ void SimpleMenu::Render() {
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
mFont->SetScale(1.0f);
|
||||
if (!title.empty())
|
||||
titleFont->DrawString(title.c_str(), mX+mWidth/2, mY - 3, JGETEXT_CENTER);
|
||||
for (int i = startId; i < startId + maxItems ; i++){
|
||||
if (i > mCount-1) break;
|
||||
if ((static_cast<SimpleMenuItem*>(mObjects[i]))->mY - kLineHeight * startId < mY + height - kLineHeight + 7) {
|
||||
if (static_cast<SimpleMenuItem*>(mObjects[i])->hasFocus()){
|
||||
resources.GetWFont(Fonts::MAIN_FONT)->DrawString(static_cast<SimpleMenuItem*>(mObjects[i])->desc.c_str(),mX+mWidth+10,mY+15);
|
||||
if (!title.empty()) titleFont->DrawString(title.c_str(), mX + mWidth / 2, mY - 3, JGETEXT_CENTER);
|
||||
for (int i = startId; i < startId + maxItems; i++)
|
||||
{
|
||||
if (i > mCount - 1) break;
|
||||
if ((static_cast<SimpleMenuItem*> (mObjects[i]))->mY - kLineHeight * startId < mY + height - kLineHeight + 7)
|
||||
{
|
||||
if (static_cast<SimpleMenuItem*> (mObjects[i])->hasFocus())
|
||||
{
|
||||
resources.GetWFont(Fonts::MAIN_FONT)->DrawString(static_cast<SimpleMenuItem*> (mObjects[i])->desc.c_str(), mX
|
||||
+ mWidth + 10, mY + 15);
|
||||
mFont->SetColor(ARGB(255,255,255,0));
|
||||
} else
|
||||
}
|
||||
else
|
||||
mFont->SetColor(ARGB(150,255,255,255));
|
||||
(static_cast<SimpleMenuItem*>(mObjects[i]))->RenderWithOffset(-kLineHeight*startId);
|
||||
(static_cast<SimpleMenuItem*> (mObjects[i]))->RenderWithOffset(-kLineHeight * startId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleMenu::Update(float dt){
|
||||
void SimpleMenu::Update(float dt)
|
||||
{
|
||||
JGuiController::Update(dt);
|
||||
if (mCurr > startId + maxItems-1)
|
||||
startId = mCurr - maxItems +1;
|
||||
else if (mCurr < startId)
|
||||
startId = mCurr;
|
||||
if (mCurr > startId + maxItems - 1)
|
||||
startId = mCurr - maxItems + 1;
|
||||
else if (mCurr < startId) startId = mCurr;
|
||||
stars->Update(dt);
|
||||
selectionT += 3*dt;
|
||||
selectionT += 3 * dt;
|
||||
selectionY += (selectionTargetY - selectionY) * 8 * dt;
|
||||
stars->MoveTo(mX + kHorizontalMargin + ((mWidth-2 * kHorizontalMargin) * (1+cos(selectionT))/2),
|
||||
selectionY + 5 * cos( selectionT * 2.35f ) + kLineHeight / 2 - kLineHeight * startId);
|
||||
if (timeOpen < 0) {
|
||||
stars->MoveTo(mX + kHorizontalMargin + ((mWidth - 2 * kHorizontalMargin) * (1 + cos(selectionT)) / 2), selectionY + 5 * cos(
|
||||
selectionT * 2.35f) + kLineHeight / 2 - kLineHeight * startId);
|
||||
if (timeOpen < 0)
|
||||
{
|
||||
timeOpen += dt * 10;
|
||||
if (timeOpen >= 0) { timeOpen = 0; closed = true; stars->FireAt(mX, mY); }
|
||||
} else {
|
||||
if (timeOpen >= 0)
|
||||
{
|
||||
timeOpen = 0;
|
||||
closed = true;
|
||||
stars->FireAt(mX, mY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
closed = false;
|
||||
timeOpen += dt * 10;
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleMenu::Add(int id, const char * text,string desc, bool forceFocus){
|
||||
SimpleMenuItem * smi = NEW SimpleMenuItem(this, id, fontId, text, 0, mY + kVerticalMargin + mCount*kLineHeight, (mCount == 0), autoTranslate);
|
||||
void SimpleMenu::Add(int id, const char * text, string desc, bool forceFocus)
|
||||
{
|
||||
SimpleMenuItem * smi = NEW SimpleMenuItem(this, id, fontId, text, 0, mY + kVerticalMargin + mCount * kLineHeight,
|
||||
(mCount == 0), autoTranslate);
|
||||
smi->desc = desc;
|
||||
JGuiController::Add(smi);
|
||||
if (mCount <= maxItems) mHeight += kLineHeight;
|
||||
if (forceFocus){
|
||||
if (forceFocus)
|
||||
{
|
||||
mObjects[mCurr]->Leaving(JGE_BTN_DOWN);
|
||||
mCurr = mCount-1;
|
||||
mCurr = mCount - 1;
|
||||
smi->Entering();
|
||||
}
|
||||
}
|
||||
@@ -179,7 +200,8 @@ void SimpleMenu::Close()
|
||||
stars->Stop(true);
|
||||
}
|
||||
|
||||
void SimpleMenu::destroy(){
|
||||
void SimpleMenu::destroy()
|
||||
{
|
||||
SAFE_DELETE(SimpleMenu::jewel);
|
||||
SAFE_DELETE(SimpleMenu::stars);
|
||||
SAFE_DELETE(SimpleMenu::jewelTex);
|
||||
|
||||
@@ -4,20 +4,21 @@
|
||||
#include "Translate.h"
|
||||
#include "WResourceManager.h"
|
||||
|
||||
SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate): JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
||||
SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate) :
|
||||
JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
||||
{
|
||||
if (autoTranslate) mText = _(text);
|
||||
else mText = text;
|
||||
if (autoTranslate)
|
||||
mText = _(text);
|
||||
else
|
||||
mText = text;
|
||||
mHasFocus = hasFocus;
|
||||
|
||||
mScale = 1.0f;
|
||||
mTargetScale = 1.0f;
|
||||
|
||||
if (hasFocus)
|
||||
Entering();
|
||||
if (hasFocus) Entering();
|
||||
}
|
||||
|
||||
|
||||
void SimpleMenuItem::RenderWithOffset(float yOffset)
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
@@ -33,33 +34,28 @@ void SimpleMenuItem::Update(float dt)
|
||||
{
|
||||
if (mScale < mTargetScale)
|
||||
{
|
||||
mScale += 8.0f*dt;
|
||||
if (mScale > mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
mScale += 8.0f * dt;
|
||||
if (mScale > mTargetScale) mScale = mTargetScale;
|
||||
}
|
||||
else if (mScale > mTargetScale)
|
||||
{
|
||||
mScale -= 8.0f*dt;
|
||||
if (mScale < mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
mScale -= 8.0f * dt;
|
||||
if (mScale < mTargetScale) mScale = mTargetScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SimpleMenuItem::Entering()
|
||||
{
|
||||
mHasFocus = true;
|
||||
parent->selectionTargetY = mY;
|
||||
}
|
||||
|
||||
|
||||
bool SimpleMenuItem::Leaving(JButton key)
|
||||
{
|
||||
mHasFocus = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SimpleMenuItem::ButtonPressed()
|
||||
{
|
||||
return true;
|
||||
|
||||
+155
-151
@@ -5,7 +5,6 @@
|
||||
#include "GameApp.h"
|
||||
#include "Translate.h"
|
||||
|
||||
|
||||
#define ALPHA_COLUMNS 8
|
||||
#define ALPHA_ROWS 8
|
||||
|
||||
@@ -14,17 +13,22 @@
|
||||
#define KPD_LEFT 2
|
||||
#define KPD_RIGHT 3
|
||||
|
||||
SimpleKey::SimpleKey( string _ds, int _id){
|
||||
displayValue = _ds; id = _id;
|
||||
for(int x=0;x<4;x++)
|
||||
SimpleKey::SimpleKey(string _ds, int _id)
|
||||
{
|
||||
displayValue = _ds;
|
||||
id = _id;
|
||||
for (int x = 0; x < 4; x++)
|
||||
adjacency[x] = KPD_NOWHERE;
|
||||
}
|
||||
|
||||
void SimplePad::linkKeys(int from, int to, int dir){
|
||||
void SimplePad::linkKeys(int from, int to, int dir)
|
||||
{
|
||||
|
||||
if(keys[from] && keys[to]){
|
||||
if (keys[from] && keys[to])
|
||||
{
|
||||
keys[from]->adjacency[dir] = to;
|
||||
switch(dir){
|
||||
switch (dir)
|
||||
{
|
||||
case KPD_UP:
|
||||
case KPD_LEFT:
|
||||
dir++;
|
||||
@@ -36,7 +40,8 @@ void SimplePad::linkKeys(int from, int to, int dir){
|
||||
}
|
||||
}
|
||||
|
||||
SimplePad::SimplePad(){
|
||||
SimplePad::SimplePad()
|
||||
{
|
||||
nbitems = 0;
|
||||
bActive = false;
|
||||
selected = 0;
|
||||
@@ -49,64 +54,59 @@ SimplePad::SimplePad(){
|
||||
buf[1] = '\0';
|
||||
SimpleKey * k;
|
||||
|
||||
for(int x=0;x<KPD_MAX;x++)
|
||||
for (int x = 0; x < KPD_MAX; x++)
|
||||
keys[x] = NULL;
|
||||
|
||||
//Add the alphabet. We cheat a bit here.
|
||||
for(int x='a';x<='z';x++)
|
||||
for (int x = 'a'; x <= 'z'; x++)
|
||||
{
|
||||
buf[0] = x;
|
||||
k=Add(buf,x);
|
||||
int idx = x-'a';
|
||||
k = Add(buf, x);
|
||||
int idx = x - 'a';
|
||||
|
||||
if(idx > KPD_A)
|
||||
k->adjacency[KPD_LEFT] = idx-1;
|
||||
if(idx < KPD_Z)
|
||||
k->adjacency[KPD_RIGHT] = idx+1;
|
||||
if(idx > ALPHA_COLUMNS)
|
||||
k->adjacency[KPD_UP] = idx-1-ALPHA_COLUMNS;
|
||||
if (idx > KPD_A) k->adjacency[KPD_LEFT] = idx - 1;
|
||||
if (idx < KPD_Z) k->adjacency[KPD_RIGHT] = idx + 1;
|
||||
if (idx > ALPHA_COLUMNS)
|
||||
k->adjacency[KPD_UP] = idx - 1 - ALPHA_COLUMNS;
|
||||
else
|
||||
k->adjacency[KPD_UP] = KPD_INPUT;
|
||||
if(idx < 25-ALPHA_COLUMNS)
|
||||
k->adjacency[KPD_DOWN] = idx+1+ALPHA_COLUMNS;
|
||||
if (idx < 25 - ALPHA_COLUMNS) k->adjacency[KPD_DOWN] = idx + 1 + ALPHA_COLUMNS;
|
||||
}
|
||||
|
||||
Add(_("Spacebar"),KPD_SPACE);
|
||||
Add(_("Spacebar"), KPD_SPACE);
|
||||
|
||||
for(int x=25-ALPHA_COLUMNS;x<26;x++)
|
||||
for (int x = 25 - ALPHA_COLUMNS; x < 26; x++)
|
||||
keys[x]->adjacency[KPD_DOWN] = KPD_SPACE;
|
||||
|
||||
k=Add(_("Confirm"),KPD_OK);
|
||||
k = Add(_("Confirm"), KPD_OK);
|
||||
keys[KPD_Z]->adjacency[KPD_RIGHT] = KPD_OK;
|
||||
k->adjacency[KPD_UP] = KPD_CAPS;
|
||||
k->adjacency[KPD_LEFT] = KPD_Z;
|
||||
k->adjacency[KPD_DOWN] = KPD_CANCEL;
|
||||
|
||||
k=Add(_("Cancel"),KPD_CANCEL);
|
||||
k = Add(_("Cancel"), KPD_CANCEL);
|
||||
k->adjacency[KPD_UP] = KPD_OK;
|
||||
k->adjacency[KPD_LEFT] = KPD_SPACE;
|
||||
|
||||
k=Add(_("Del"),KPD_DEL);
|
||||
k = Add(_("Del"), KPD_DEL);
|
||||
keys[KPD_I]->adjacency[KPD_RIGHT] = KPD_DEL;
|
||||
k->adjacency[KPD_UP] = KPD_9;
|
||||
k->adjacency[KPD_DOWN] = KPD_CAPS;
|
||||
k->adjacency[KPD_LEFT] = KPD_I;
|
||||
|
||||
k=Add(_("Caps"),KPD_CAPS);
|
||||
k = Add(_("Caps"), KPD_CAPS);
|
||||
keys[KPD_R]->adjacency[KPD_RIGHT] = KPD_CAPS;
|
||||
keys[KPD_R]->adjacency[KPD_DOWN] = KPD_Z;
|
||||
k->adjacency[KPD_UP] = KPD_DEL;
|
||||
k->adjacency[KPD_DOWN] = KPD_OK;
|
||||
k->adjacency[KPD_LEFT] = KPD_R;
|
||||
|
||||
|
||||
for(int x=0;x<10;x++){
|
||||
buf[0] = '0'+x;
|
||||
Add(buf,KPD_0+x);
|
||||
if(x < 8)
|
||||
linkKeys(KPD_0+x,KPD_A+x,KPD_DOWN);
|
||||
if(x > 0)
|
||||
linkKeys(KPD_0+x,KPD_0+x-1,KPD_LEFT);
|
||||
for (int x = 0; x < 10; x++)
|
||||
{
|
||||
buf[0] = '0' + x;
|
||||
Add(buf, KPD_0 + x);
|
||||
if (x < 8) linkKeys(KPD_0 + x, KPD_A + x, KPD_DOWN);
|
||||
if (x > 0) linkKeys(KPD_0 + x, KPD_0 + x - 1, KPD_LEFT);
|
||||
}
|
||||
|
||||
keys[KPD_8]->adjacency[KPD_DOWN] = KPD_DEL;
|
||||
@@ -121,59 +121,60 @@ SimplePad::SimplePad(){
|
||||
|
||||
SimplePad::~SimplePad()
|
||||
{
|
||||
for(int x=0;x<KPD_MAX;x++)
|
||||
for (int x = 0; x < KPD_MAX; x++)
|
||||
SAFE_DELETE(keys[x]);
|
||||
}
|
||||
|
||||
SimpleKey * SimplePad::Add(string display, unsigned char id)
|
||||
{
|
||||
if (nbitems >= KPD_MAX) return NULL;
|
||||
|
||||
SimpleKey * SimplePad::Add(string display, unsigned char id){
|
||||
if(nbitems >= KPD_MAX)
|
||||
return NULL;
|
||||
|
||||
keys[nbitems++] = NEW SimpleKey(display,id);
|
||||
return keys[nbitems-1];
|
||||
keys[nbitems++] = NEW SimpleKey(display, id);
|
||||
return keys[nbitems - 1];
|
||||
}
|
||||
void SimplePad::pressKey(unsigned char key){
|
||||
void SimplePad::pressKey(unsigned char key)
|
||||
{
|
||||
string input = "";
|
||||
|
||||
if(isalpha(key)) {
|
||||
if(bCapslock)
|
||||
if (isalpha(key))
|
||||
{
|
||||
if (bCapslock)
|
||||
input += toupper(key);
|
||||
else
|
||||
input += key;
|
||||
|
||||
if(cursor < buffer.size())
|
||||
cursor++;
|
||||
if (cursor < buffer.size()) cursor++;
|
||||
|
||||
buffer.insert(cursor,input);
|
||||
buffer.insert(cursor, input);
|
||||
|
||||
//Auto swap capitalization
|
||||
if(bCapslock && buffer.size() == 1)
|
||||
bCapslock = !bCapslock;
|
||||
if (bCapslock && buffer.size() == 1) bCapslock = !bCapslock;
|
||||
}
|
||||
else if(key == KPD_SPACE){
|
||||
if(cursor < buffer.size())
|
||||
cursor++;
|
||||
buffer.insert(cursor," ");
|
||||
else if (key == KPD_SPACE)
|
||||
{
|
||||
if (cursor < buffer.size()) cursor++;
|
||||
buffer.insert(cursor, " ");
|
||||
}
|
||||
else if(key == KPD_CAPS)
|
||||
else if (key == KPD_CAPS)
|
||||
bCapslock = !bCapslock;
|
||||
else if(key == KPD_DEL) {
|
||||
if(!buffer.size())
|
||||
return;
|
||||
else if (key == KPD_DEL)
|
||||
{
|
||||
if (!buffer.size()) return;
|
||||
|
||||
if(cursor >= buffer.size()) {
|
||||
if (cursor >= buffer.size())
|
||||
{
|
||||
cursor = buffer.size();
|
||||
buffer = buffer.substr(0,cursor-1);
|
||||
buffer = buffer.substr(0, cursor - 1);
|
||||
}
|
||||
else
|
||||
buffer = buffer.substr(0,cursor) + buffer.substr(cursor+1);
|
||||
buffer = buffer.substr(0, cursor) + buffer.substr(cursor + 1);
|
||||
|
||||
cursor--;
|
||||
}
|
||||
else if(key == KPD_OK)
|
||||
else if (key == KPD_OK)
|
||||
Finish();
|
||||
else if(key == KPD_CANCEL) {
|
||||
else if (key == KPD_CANCEL)
|
||||
{
|
||||
bCanceled = true;
|
||||
Finish();
|
||||
}
|
||||
@@ -181,21 +182,19 @@ void SimplePad::pressKey(unsigned char key){
|
||||
}
|
||||
void SimplePad::MoveSelection(unsigned char moveto)
|
||||
{
|
||||
if(!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9 )
|
||||
if (!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9)
|
||||
moveto = KPD_INPUT;
|
||||
else if(!bShowCancel && moveto == KPD_CANCEL )
|
||||
moveto = KPD_SPACE;
|
||||
else if (!bShowCancel && moveto == KPD_CANCEL) moveto = KPD_SPACE;
|
||||
|
||||
if (selected < KPD_MAX && selected >= 0)
|
||||
priorKey = selected;
|
||||
if (selected < KPD_MAX && selected >= 0) priorKey = selected;
|
||||
|
||||
if (moveto < KPD_MAX)
|
||||
selected = moveto;
|
||||
else if (moveto == KPD_INPUT)
|
||||
selected = KPD_INPUT;
|
||||
else if (moveto == KPD_INPUT) selected = KPD_INPUT;
|
||||
}
|
||||
|
||||
void SimplePad::Update(float dt){
|
||||
void SimplePad::Update(float dt)
|
||||
{
|
||||
JGE * mEngine = JGE::GetInstance();
|
||||
JButton key = mEngine->ReadButton();
|
||||
|
||||
@@ -207,47 +206,44 @@ void SimplePad::Update(float dt){
|
||||
else
|
||||
Finish();
|
||||
}
|
||||
else if (key == JGE_BTN_CTRL)
|
||||
bCapslock = !bCapslock;
|
||||
else if (key == JGE_BTN_CTRL) bCapslock = !bCapslock;
|
||||
|
||||
if (selected == KPD_SPACE){
|
||||
if (selected == KPD_SPACE)
|
||||
{
|
||||
if (bShowCancel && mEngine->GetButtonClick(JGE_BTN_RIGHT))
|
||||
selected = KPD_CANCEL;
|
||||
else if (key == JGE_BTN_LEFT || key == JGE_BTN_RIGHT
|
||||
|| key == JGE_BTN_UP || key == JGE_BTN_DOWN)
|
||||
selected = priorKey;
|
||||
else if (key == JGE_BTN_LEFT || key == JGE_BTN_RIGHT || key == JGE_BTN_UP || key == JGE_BTN_DOWN) selected = priorKey;
|
||||
} //Moving within/from the text field.
|
||||
else if (selected == KPD_INPUT){
|
||||
if (key == JGE_BTN_DOWN )
|
||||
selected = priorKey;
|
||||
if (key == JGE_BTN_LEFT && cursor > 0) cursor--;
|
||||
else if (selected == KPD_INPUT)
|
||||
{
|
||||
if (key == JGE_BTN_DOWN) selected = priorKey;
|
||||
if (key == JGE_BTN_LEFT && cursor > 0)
|
||||
cursor--;
|
||||
else if (key == JGE_BTN_RIGHT && cursor < buffer.size()) cursor++;
|
||||
}
|
||||
else if (selected >= 0 && keys[selected]){
|
||||
else if (selected >= 0 && keys[selected])
|
||||
{
|
||||
if (key == JGE_BTN_LEFT)
|
||||
MoveSelection(keys[selected]->adjacency[KPD_LEFT]);
|
||||
else if (key == JGE_BTN_RIGHT)
|
||||
MoveSelection(keys[selected]->adjacency[KPD_RIGHT]);
|
||||
else if (key == JGE_BTN_RIGHT) MoveSelection(keys[selected]->adjacency[KPD_RIGHT]);
|
||||
if (key == JGE_BTN_DOWN)
|
||||
MoveSelection(keys[selected]->adjacency[KPD_DOWN]);
|
||||
else if (key == JGE_BTN_UP)
|
||||
MoveSelection(keys[selected]->adjacency[KPD_UP]);
|
||||
else if (key == JGE_BTN_UP) MoveSelection(keys[selected]->adjacency[KPD_UP]);
|
||||
}
|
||||
|
||||
|
||||
//These bits require a valid key...
|
||||
if (selected >= 0 && selected < nbitems && keys[selected])
|
||||
if (key == JGE_BTN_OK)
|
||||
pressKey(keys[selected]->id);
|
||||
if (buffer.size() > 0 && key == JGE_BTN_SEC)
|
||||
buffer = buffer.substr(0, buffer.size() - 1);
|
||||
if (buffer.size() && key == JGE_BTN_PREV) {
|
||||
if (selected >= 0 && selected < nbitems && keys[selected]) if (key == JGE_BTN_OK) pressKey(keys[selected]->id);
|
||||
if (buffer.size() > 0 && key == JGE_BTN_SEC) buffer = buffer.substr(0, buffer.size() - 1);
|
||||
if (buffer.size() && key == JGE_BTN_PREV)
|
||||
{
|
||||
if (cursor > 0) cursor--;
|
||||
}
|
||||
else if (key == JGE_BTN_NEXT) {
|
||||
else if (key == JGE_BTN_NEXT)
|
||||
{
|
||||
if (cursor < buffer.size())
|
||||
cursor++;
|
||||
else {
|
||||
else
|
||||
{
|
||||
buffer += ' ';
|
||||
cursor = buffer.size();
|
||||
}
|
||||
@@ -259,9 +255,10 @@ void SimplePad::Update(float dt){
|
||||
//Clear input buffer.
|
||||
mEngine->ResetInput();
|
||||
}
|
||||
void SimplePad::Start(string value, string * _dest) {
|
||||
void SimplePad::Start(string value, string * _dest)
|
||||
{
|
||||
bActive = true;
|
||||
bCanceled=false;
|
||||
bCanceled = false;
|
||||
buffer = value;
|
||||
original = buffer;
|
||||
dest = _dest;
|
||||
@@ -271,7 +268,8 @@ void SimplePad::Start(string value, string * _dest) {
|
||||
mEngine->ResetInput();
|
||||
}
|
||||
|
||||
string SimplePad::Finish() {
|
||||
string SimplePad::Finish()
|
||||
{
|
||||
bActive = false;
|
||||
|
||||
//Clear input buffer.
|
||||
@@ -279,131 +277,137 @@ string SimplePad::Finish() {
|
||||
mEngine->ResetInput();
|
||||
|
||||
//Return result.
|
||||
if(bCanceled){
|
||||
if (bCanceled)
|
||||
{
|
||||
dest = NULL;
|
||||
return original;
|
||||
}else{ //Strip trailing spaces.
|
||||
string whitespaces (" \t\f\v\n\r");
|
||||
size_t found=buffer.find_last_not_of(whitespaces);
|
||||
if (found!=string::npos)
|
||||
buffer.erase(found+1);
|
||||
}
|
||||
else
|
||||
{ //Strip trailing spaces.
|
||||
string whitespaces(" \t\f\v\n\r");
|
||||
size_t found = buffer.find_last_not_of(whitespaces);
|
||||
if (found != string::npos)
|
||||
buffer.erase(found + 1);
|
||||
else
|
||||
buffer = "";
|
||||
}
|
||||
|
||||
if(dest != NULL){
|
||||
dest->clear(); dest->insert(0,buffer);
|
||||
if (dest != NULL)
|
||||
{
|
||||
dest->clear();
|
||||
dest->insert(0, buffer);
|
||||
dest = NULL;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void SimplePad::Render(){
|
||||
void SimplePad::Render()
|
||||
{
|
||||
//This could use some cleaning up to make margins more explicit
|
||||
WFont * mFont = resources.GetWFont(Fonts::MENU_FONT);
|
||||
|
||||
float offX = 0, offY = 0;
|
||||
float kH = mFont->GetHeight();
|
||||
float hSpacing = mFont->GetStringWidth("W");
|
||||
float rowLen = mFont->GetStringWidth("JKLMNOPQR") + 14*7;
|
||||
float rowLen = mFont->GetStringWidth("JKLMNOPQR") + 14 * 7;
|
||||
float vSpacing = 0;
|
||||
float kW = hSpacing;
|
||||
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
|
||||
|
||||
vSpacing = kH+8;
|
||||
|
||||
vSpacing = kH + 8;
|
||||
|
||||
offY = vSpacing;
|
||||
if(bShowNumpad)
|
||||
offY += kH+14;
|
||||
if (bShowNumpad) offY += kH + 14;
|
||||
//Draw Keypad Background.
|
||||
renderer->FillRoundRect(mX-kW,mY-kH,(kW+12)*13,(kH+14)*5+offY,2,ARGB(180,0,0,0));
|
||||
renderer->FillRoundRect(mX - kW, mY - kH, (kW + 12) * 13, (kH + 14) * 5 + offY, 2, ARGB(180,0,0,0));
|
||||
offY = vSpacing;
|
||||
//Draw text entry bubble
|
||||
renderer->FillRoundRect(mX-kW/2,mY+offY,(kW+12)*11+kW/2,kH,2,ARGB(255,255,255,255));
|
||||
renderer->FillRoundRect(mX - kW / 2, mY + offY, (kW + 12) * 11 + kW / 2, kH, 2, ARGB(255,255,255,255));
|
||||
|
||||
//Draw text-entry title, if we've got one.
|
||||
if(title != ""){
|
||||
mFont->DrawString(_(title.c_str()),mX,mY);
|
||||
if (title != "")
|
||||
{
|
||||
mFont->DrawString(_(title.c_str()), mX, mY);
|
||||
}
|
||||
mY+=kH+12;
|
||||
mY += kH + 12;
|
||||
|
||||
//Draw cursor.
|
||||
if(cursor < buffer.size())
|
||||
if (cursor < buffer.size())
|
||||
{
|
||||
kW = mFont->GetStringWidth(buffer.substr(cursor,1).c_str());
|
||||
renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cursor).c_str()),mY+kH-4,
|
||||
kW,4,2,ARGB(150,150,150,0));
|
||||
kW = mFont->GetStringWidth(buffer.substr(cursor, 1).c_str());
|
||||
renderer->FillRoundRect(mX + mFont->GetStringWidth(buffer.substr(0, cursor).c_str()), mY + kH - 4, kW, 4, 2,
|
||||
ARGB(150,150,150,0));
|
||||
}
|
||||
else
|
||||
{
|
||||
cursor = buffer.size();
|
||||
renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cursor).c_str()),mY+kH-4,
|
||||
kW,4,2,ARGB(150,150,150,0));
|
||||
renderer->FillRoundRect(mX + mFont->GetStringWidth(buffer.substr(0, cursor).c_str()), mY + kH - 4, kW, 4, 2,
|
||||
ARGB(150,150,150,0));
|
||||
}
|
||||
|
||||
mFont->SetColor(ARGB(255,0,0,0));
|
||||
mFont->DrawString(buffer.c_str(),mX,mY);
|
||||
mFont->DrawString(buffer.c_str(), mX, mY);
|
||||
offY += kH + 12;
|
||||
|
||||
if(!bShowNumpad)
|
||||
vSpacing -= kH + 12;
|
||||
if (!bShowNumpad) vSpacing -= kH + 12;
|
||||
|
||||
for(int x=0;x<nbitems;x++)
|
||||
if(keys[x]){
|
||||
for (int x = 0; x < nbitems; x++)
|
||||
if (keys[x])
|
||||
{
|
||||
|
||||
if((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_9 && !bShowNumpad))
|
||||
continue;
|
||||
if ((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_9 && !bShowNumpad)) continue;
|
||||
|
||||
switch(x){
|
||||
switch (x)
|
||||
{
|
||||
case KPD_0:
|
||||
offX = 0;
|
||||
offY = vSpacing;
|
||||
break;
|
||||
case KPD_A:
|
||||
offX = 0;
|
||||
offY = vSpacing+(kH+12)*1;
|
||||
offY = vSpacing + (kH + 12) * 1;
|
||||
break;
|
||||
case KPD_J:
|
||||
offX = 0;
|
||||
offY = vSpacing+(kH+12)*2;
|
||||
offY = vSpacing + (kH + 12) * 2;
|
||||
break;
|
||||
case KPD_S:
|
||||
offX = 0;
|
||||
offY = vSpacing+(kH+12)*3;
|
||||
offY = vSpacing + (kH + 12) * 3;
|
||||
break;
|
||||
case KPD_SPACE:
|
||||
offX = 0;
|
||||
offY = vSpacing+(kH+12)*4;
|
||||
offY = vSpacing + (kH + 12) * 4;
|
||||
break;
|
||||
case KPD_OK:
|
||||
offX = rowLen + hSpacing;
|
||||
offY = vSpacing+(kH+12)*3;
|
||||
offY = vSpacing + (kH + 12) * 3;
|
||||
break;
|
||||
case KPD_CANCEL:
|
||||
offX = rowLen + hSpacing;
|
||||
offY = vSpacing+(kH+12)*4;
|
||||
offY = vSpacing + (kH + 12) * 4;
|
||||
break;
|
||||
case KPD_DEL:
|
||||
offX = rowLen + hSpacing;
|
||||
offY = vSpacing+(kH+12)*1;
|
||||
offY = vSpacing + (kH + 12) * 1;
|
||||
break;
|
||||
case KPD_CAPS:
|
||||
offX = rowLen + hSpacing;
|
||||
offY = vSpacing+(kH+12)*2;
|
||||
offY = vSpacing + (kH + 12) * 2;
|
||||
break;
|
||||
}
|
||||
|
||||
kW = mFont->GetStringWidth(keys[x]->displayValue.c_str());
|
||||
//Render a key.
|
||||
if(x != selected){
|
||||
renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,ARGB(180,50,50,50));
|
||||
if (x != selected)
|
||||
{
|
||||
renderer->FillRoundRect(mX + offX - 4, mY + offY - 4, kW + 8, kH + 4, 2, ARGB(180,50,50,50));
|
||||
mFont->SetColor(ARGB(255,255,255,0));
|
||||
}
|
||||
else{
|
||||
renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,ARGB(255,100,100,100));
|
||||
else
|
||||
{
|
||||
renderer->FillRoundRect(mX + offX - 4, mY + offY - 4, kW + 8, kH + 4, 2, ARGB(255,100,100,100));
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
}
|
||||
|
||||
@@ -411,20 +415,20 @@ void SimplePad::Render(){
|
||||
vkey[1] = '\0';
|
||||
vkey[0] = keys[x]->id;
|
||||
|
||||
|
||||
if(isalpha(vkey[0])) {
|
||||
if(bCapslock) vkey[0] = toupper(vkey[0]);
|
||||
mFont->DrawString(vkey,mX+offX,mY+offY);
|
||||
if (isalpha(vkey[0]))
|
||||
{
|
||||
if (bCapslock) vkey[0] = toupper(vkey[0]);
|
||||
mFont->DrawString(vkey, mX + offX, mY + offY);
|
||||
}
|
||||
else
|
||||
mFont->DrawString(keys[x]->displayValue.c_str(),mX+offX,mY+offY);
|
||||
mFont->DrawString(keys[x]->displayValue.c_str(), mX + offX, mY + offY);
|
||||
offX += kW + 14;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int SimplePad::cursorPos(){
|
||||
if(cursor > buffer.size())
|
||||
return buffer.size();
|
||||
unsigned int SimplePad::cursorPos()
|
||||
{
|
||||
if (cursor > buffer.size()) return buffer.size();
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
+259
-167
@@ -11,7 +11,6 @@
|
||||
#include "WFont.h"
|
||||
#include <JFileSystem.h>
|
||||
|
||||
|
||||
#define LINE_SPACE 2
|
||||
#define SPACE_BEFORE_CHOICES 10
|
||||
|
||||
@@ -21,46 +20,59 @@ 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) {
|
||||
StoryDialogElement::StoryDialogElement(float x, float y, int id) :
|
||||
JGuiObject(id), mX(x), mY(y)
|
||||
{
|
||||
}
|
||||
|
||||
StoryText::StoryText(string text, float _mX, float _mY, string _align, int _font, int id):StoryDialogElement(_mX,_mY, id), text(text), font(_font) {
|
||||
StoryText::StoryText(string text, float _mX, float _mY, string _align, int _font, int id) :
|
||||
StoryDialogElement(_mX, _mY, id), text(text), font(_font)
|
||||
{
|
||||
align = JGETEXT_LEFT;
|
||||
if (_align.compare("center") == 0) {
|
||||
if (_align.compare("center") == 0)
|
||||
{
|
||||
align = JGETEXT_CENTER;
|
||||
if (mX == 0)
|
||||
mX = SCREEN_WIDTH/2;
|
||||
}else if (_align.compare("right") == 0) {
|
||||
align = JGETEXT_RIGHT;
|
||||
if (mX == 0)
|
||||
mX = SCREEN_WIDTH - 10;
|
||||
if (mX == 0) mX = SCREEN_WIDTH / 2;
|
||||
}
|
||||
if (align == JGETEXT_LEFT && mX <= 0){
|
||||
else if (_align.compare("right") == 0)
|
||||
{
|
||||
align = JGETEXT_RIGHT;
|
||||
if (mX == 0) mX = SCREEN_WIDTH - 10;
|
||||
}
|
||||
if (align == JGETEXT_LEFT && mX <= 0)
|
||||
{
|
||||
mX += 10; //left margin
|
||||
}
|
||||
}
|
||||
void StoryText::Render() {
|
||||
void StoryText::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(font);
|
||||
mFont->SetColor(ARGB(200,255,255,255));
|
||||
mFont->SetScale(1.0);
|
||||
mFont->DrawString(text.c_str(), mX, mY, align);
|
||||
}
|
||||
|
||||
float StoryText::getHeight() {
|
||||
float StoryText::getHeight()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(font);
|
||||
return mFont->GetHeight();
|
||||
}
|
||||
|
||||
void StoryText::Update(float dt){
|
||||
void StoryText::Update(float dt)
|
||||
{
|
||||
//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) {
|
||||
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) {
|
||||
if (_type.compare("unlockset") == 0)
|
||||
{
|
||||
type = STORY_REWARD_SET;
|
||||
} else if (_type.compare("card") == 0) {
|
||||
}
|
||||
else if (_type.compare("card") == 0)
|
||||
{
|
||||
type = STORY_REWARD_CARD;
|
||||
}
|
||||
value = _value;
|
||||
@@ -68,36 +80,42 @@ float StoryText::getHeight() {
|
||||
|
||||
}
|
||||
|
||||
void StoryReward::Render(){
|
||||
if (rewardDone <=0)
|
||||
return;
|
||||
void StoryReward::Render()
|
||||
{
|
||||
if (rewardDone <= 0) return;
|
||||
StoryText::Render();
|
||||
}
|
||||
|
||||
void StoryReward::Update(float dt){
|
||||
if (rewardDone)
|
||||
return;
|
||||
void StoryReward::Update(float dt)
|
||||
{
|
||||
if (rewardDone) return;
|
||||
|
||||
int result = 0;
|
||||
|
||||
switch (type){
|
||||
switch (type)
|
||||
{
|
||||
case STORY_REWARD_CREDITS:
|
||||
result = Credits::addCreditBonus(atoi(value.c_str()));
|
||||
break;
|
||||
case STORY_REWARD_SET:
|
||||
{
|
||||
if (value.size()) {
|
||||
if (value.size())
|
||||
{
|
||||
result = Credits::unlockSetByName(value);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Credits::unlockRandomSet(true);
|
||||
}
|
||||
if (!result) break;
|
||||
MTGSetInfo * si = setlist.getInfo(result - 1);
|
||||
if(si) {
|
||||
if (si)
|
||||
{
|
||||
string unlockedString = si->getName();
|
||||
size_t pos = text.find("${SET}");
|
||||
if (pos != string::npos) {
|
||||
text.replace(pos,pos + 6,unlockedString);
|
||||
if (pos != string::npos)
|
||||
{
|
||||
text.replace(pos, pos + 6, unlockedString);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -106,26 +124,32 @@ void StoryReward::Update(float dt){
|
||||
{
|
||||
int cardId = 0;
|
||||
MTGCard * card = NULL;
|
||||
if (value.size()) {
|
||||
if (value.size())
|
||||
{
|
||||
card = GameApp::collection->getCardByName(value);
|
||||
if (card) {
|
||||
if (card)
|
||||
{
|
||||
cardId = card->getId();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
cardId = GameApp::collection->randomCardId();
|
||||
card = GameApp::collection->getCardById(cardId);
|
||||
}
|
||||
|
||||
if (!cardId) break;
|
||||
|
||||
if (!collection) {
|
||||
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());
|
||||
if (pos != string::npos && card)
|
||||
{
|
||||
text.replace(pos, pos + 7, card->data->getName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -133,67 +157,80 @@ void StoryReward::Update(float dt){
|
||||
break;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
if (!result)
|
||||
{
|
||||
rewardDone = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rewardsEnabled) {
|
||||
if (!rewardsEnabled)
|
||||
{
|
||||
rewardDone = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rewardSoundPlayed && options[Options::SFXVOLUME].number > 0){
|
||||
if (!rewardSoundPlayed && options[Options::SFXVOLUME].number > 0)
|
||||
{
|
||||
JSample * sample = resources.RetrieveSample("bonus.wav");
|
||||
if (sample){
|
||||
if (sample)
|
||||
{
|
||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||
}
|
||||
rewardSoundPlayed = 1;
|
||||
}
|
||||
rewardDone = 1;
|
||||
}
|
||||
}
|
||||
|
||||
ostream& StoryText::toString(ostream& out) const
|
||||
ostream& StoryText::toString(ostream& out) const
|
||||
{
|
||||
return out << "StoryText ::: text : " << text;
|
||||
}
|
||||
|
||||
StoryImage::StoryImage(string img, float mX, float mY):StoryDialogElement(mX,mY), img(img) {
|
||||
StoryImage::StoryImage(string img, float mX, float mY) :
|
||||
StoryDialogElement(mX, mY), img(img)
|
||||
{
|
||||
|
||||
}
|
||||
void StoryImage::Render() {
|
||||
void StoryImage::Render()
|
||||
{
|
||||
JQuad * quad = resources.RetrieveTempQuad(img);
|
||||
if (quad) {
|
||||
if (quad)
|
||||
{
|
||||
float x = mX;
|
||||
if (mX == -1) {
|
||||
x = SCREEN_WIDTH/2;
|
||||
quad->SetHotSpot(quad->mWidth/2, 0);
|
||||
if (mX == -1)
|
||||
{
|
||||
x = SCREEN_WIDTH / 2;
|
||||
quad->SetHotSpot(quad->mWidth / 2, 0);
|
||||
}
|
||||
JRenderer::GetInstance()->RenderQuad(quad,x, mY);
|
||||
JRenderer::GetInstance()->RenderQuad(quad, x, mY);
|
||||
}
|
||||
}
|
||||
|
||||
float StoryImage::getHeight() {
|
||||
JQuad * quad = resources.RetrieveQuad(img);
|
||||
if (quad) {
|
||||
float StoryImage::getHeight()
|
||||
{
|
||||
JQuad * quad = resources.RetrieveQuad(img);
|
||||
if (quad)
|
||||
{
|
||||
return quad->mHeight;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StoryImage::Update(float dt){
|
||||
void StoryImage::Update(float dt)
|
||||
{
|
||||
//Nothing for now
|
||||
}
|
||||
}
|
||||
|
||||
ostream& StoryImage::toString(ostream& out) const
|
||||
ostream& StoryImage::toString(ostream& out) const
|
||||
{
|
||||
return out << "StoryImage ::: img : " << img;
|
||||
}
|
||||
|
||||
StoryPage::StoryPage(StoryFlow * mParent):mParent(mParent){
|
||||
StoryPage::StoryPage(StoryFlow * mParent) :
|
||||
mParent(mParent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void StoryChoice::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(font);
|
||||
@@ -203,7 +240,8 @@ void StoryChoice::Render()
|
||||
mFont->DrawString(text.c_str(), mX, mY, align);
|
||||
}
|
||||
|
||||
float StoryChoice::getHeight() {
|
||||
float StoryChoice::getHeight()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(font);
|
||||
return mFont->GetHeight() * mScale;
|
||||
}
|
||||
@@ -212,26 +250,22 @@ void StoryChoice::Update(float dt)
|
||||
{
|
||||
if (mScale < mTargetScale)
|
||||
{
|
||||
mScale += 8.0f*dt;
|
||||
if (mScale > mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
mScale += 8.0f * dt;
|
||||
if (mScale > mTargetScale) mScale = mTargetScale;
|
||||
}
|
||||
else if (mScale > mTargetScale)
|
||||
{
|
||||
mScale -= 8.0f*dt;
|
||||
if (mScale < mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
mScale -= 8.0f * dt;
|
||||
if (mScale < mTargetScale) mScale = mTargetScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void StoryChoice::Entering()
|
||||
{
|
||||
mHasFocus = true;
|
||||
mTargetScale = 1.2f;
|
||||
}
|
||||
|
||||
|
||||
bool StoryChoice::Leaving(JButton key)
|
||||
{
|
||||
mHasFocus = false;
|
||||
@@ -239,14 +273,11 @@ bool StoryChoice::Leaving(JButton key)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool StoryChoice::ButtonPressed()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool StoryChoice::hasFocus()
|
||||
{
|
||||
return mHasFocus;
|
||||
@@ -257,19 +288,21 @@ ostream& StoryChoice::toString(ostream& out) const
|
||||
return out << "StoryChoice ::: mHasFocus : " << mHasFocus;
|
||||
}
|
||||
|
||||
|
||||
StoryChoice::StoryChoice(string pageId, string text, int JGOid, float mX, float mY, string _align, int _font, bool hasFocus):StoryText(text, mX, mY, _align, _font, JGOid),pageId(pageId),mHasFocus(hasFocus){
|
||||
StoryChoice::StoryChoice(string pageId, string text, int JGOid, float mX, float mY, string _align, int _font, bool hasFocus) :
|
||||
StoryText(text, mX, mY, _align, _font, JGOid), pageId(pageId), mHasFocus(hasFocus)
|
||||
{
|
||||
mScale = 1.0f;
|
||||
mTargetScale = 1.0f;
|
||||
if(hasFocus) mTargetScale = 1.2f;
|
||||
if (hasFocus) mTargetScale = 1.2f;
|
||||
}
|
||||
|
||||
//Actually loads a duel
|
||||
void StoryDuel::init(){
|
||||
void StoryDuel::init()
|
||||
{
|
||||
Player * players[2];
|
||||
|
||||
char folder[255], deckFile[255],deckFileSmall[255];
|
||||
sprintf(folder, JGE_GET_RES(CAMPAIGNS_FOLDER"%s/%s").c_str() ,mParent->folder.c_str(), pageId.c_str());
|
||||
char folder[255], deckFile[255], deckFileSmall[255];
|
||||
sprintf(folder, JGE_GET_RES(CAMPAIGNS_FOLDER"%s/%s").c_str(), mParent->folder.c_str(), pageId.c_str());
|
||||
|
||||
sprintf(deckFile, "%s/deck.txt", folder);
|
||||
MTGDeck * tempDeck = NEW MTGDeck(deckFile, GameApp::collection);
|
||||
@@ -277,7 +310,7 @@ void StoryDuel::init(){
|
||||
players[0] = NEW HumanPlayer(tempDeck, deckFile, deckFileSmall);
|
||||
SAFE_DELETE(tempDeck);
|
||||
|
||||
sprintf(deckFile,"%s/opponent_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(tempDeck, deckFile, deckFileSmall, "baka.jpg");
|
||||
@@ -292,122 +325,157 @@ void StoryDuel::init(){
|
||||
rules->gamemode = GAME_TYPE_STORY;
|
||||
game->startGame(rules);
|
||||
}
|
||||
StoryDuel::StoryDuel(TiXmlElement* root,StoryFlow * mParent): StoryPage(mParent) {
|
||||
|
||||
StoryDuel::StoryDuel(TiXmlElement* root, StoryFlow * mParent) :
|
||||
StoryPage(mParent)
|
||||
{
|
||||
game = NULL;
|
||||
rules = NULL;
|
||||
pageId = root->Attribute("id");
|
||||
for (TiXmlNode* node = root->FirstChild(); node; node = node->NextSibling()) {
|
||||
for (TiXmlNode* node = root->FirstChild(); node; node = node->NextSibling())
|
||||
{
|
||||
TiXmlElement* element = node->ToElement();
|
||||
if (element) {
|
||||
if (element)
|
||||
{
|
||||
const char* textC = element->GetText();
|
||||
if (strcmp(element->Value(), "onwin")==0) {
|
||||
if (strcmp(element->Value(), "onwin") == 0)
|
||||
{
|
||||
onWin = textC;
|
||||
}
|
||||
else if (strcmp(element->Value(), "onlose")==0) {
|
||||
else if (strcmp(element->Value(), "onlose") == 0)
|
||||
{
|
||||
onLose = textC;
|
||||
} else if (strcmp(element->Value(), "bg")==0) {
|
||||
}
|
||||
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 {
|
||||
}
|
||||
else
|
||||
{
|
||||
StoryPage::loadElement(element); //Father
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StoryDuel::~StoryDuel(){
|
||||
StoryDuel::~StoryDuel()
|
||||
{
|
||||
SAFE_DELETE(rules);
|
||||
if(game)GameObserver::EndInstance();
|
||||
game=NULL;
|
||||
if (game) GameObserver::EndInstance();
|
||||
game = NULL;
|
||||
}
|
||||
|
||||
void StoryDuel::Update(float dt){
|
||||
void StoryDuel::Update(float dt)
|
||||
{
|
||||
if (!game) init();
|
||||
game->Update(dt);
|
||||
if (game->gameOver){
|
||||
if (game->gameOver == game->players[1]) mParent->gotoPage(onWin);
|
||||
else mParent->gotoPage(onLose);
|
||||
if (game->gameOver)
|
||||
{
|
||||
if (game->gameOver == game->players[1])
|
||||
mParent->gotoPage(onWin);
|
||||
else
|
||||
mParent->gotoPage(onLose);
|
||||
GameObserver::EndInstance();
|
||||
game=NULL;
|
||||
game = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void StoryDuel::Render(){
|
||||
if(!game) return;
|
||||
void StoryDuel::Render()
|
||||
{
|
||||
if (!game) return;
|
||||
game->Render();
|
||||
}
|
||||
|
||||
string StoryPage::safeAttribute(TiXmlElement* element, string attribute) {
|
||||
string StoryPage::safeAttribute(TiXmlElement* element, string attribute)
|
||||
{
|
||||
string s;
|
||||
if (element->Attribute(attribute.c_str())){
|
||||
if (element->Attribute(attribute.c_str()))
|
||||
{
|
||||
s = element->Attribute(attribute.c_str());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
int StoryPage::loadElement(TiXmlElement* element) {
|
||||
int StoryPage::loadElement(TiXmlElement* element)
|
||||
{
|
||||
if (!element) return 0;
|
||||
const char* textC = element->GetText();
|
||||
string text = textC;
|
||||
if (strcmp(element->Value(), "music")==0) {
|
||||
if (strcmp(element->Value(), "music") == 0)
|
||||
{
|
||||
musicFile = string("campaigns/").append(mParent->folder).append("/").append(text);
|
||||
if (!fileExists(musicFile.c_str()))
|
||||
musicFile = text;
|
||||
if (!fileExists(musicFile.c_str())) musicFile = text;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent):StoryPage(mParent), JGuiListener(), JGuiController(1,NULL) {
|
||||
StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
|
||||
StoryPage(mParent), JGuiListener(), JGuiController(1, NULL)
|
||||
{
|
||||
|
||||
currentY = 0;
|
||||
|
||||
for (TiXmlNode* node = root->FirstChild(); node; node = node->NextSibling()) {
|
||||
for (TiXmlNode* node = root->FirstChild(); node; node = node->NextSibling())
|
||||
{
|
||||
TiXmlElement* element = node->ToElement();
|
||||
if (element) {
|
||||
if (element)
|
||||
{
|
||||
string sX = safeAttribute(element, "x");
|
||||
float x = static_cast<float>(atof(sX.c_str()));
|
||||
if (x > 0 && x < 1){
|
||||
float x = static_cast<float> (atof(sX.c_str()));
|
||||
if (x > 0 && x < 1)
|
||||
{
|
||||
x = SCREEN_WIDTH_F * x;
|
||||
}
|
||||
string sY = safeAttribute(element,"y");
|
||||
float y = static_cast<float>(atof(sY.c_str()));
|
||||
if (y > 0 && y < 1){
|
||||
string sY = safeAttribute(element, "y");
|
||||
float y = static_cast<float> (atof(sY.c_str()));
|
||||
if (y > 0 && y < 1)
|
||||
{
|
||||
y = SCREEN_HEIGHT_F * y;
|
||||
}
|
||||
string align = safeAttribute(element,"align");
|
||||
string align = safeAttribute(element, "align");
|
||||
const char* textC = element->GetText();
|
||||
string text = textC;
|
||||
string sFont = safeAttribute(element,"font");
|
||||
string sFont = safeAttribute(element, "font");
|
||||
int font = atoi(sFont.c_str());
|
||||
|
||||
if (strcmp(element->Value(), "text")==0) {
|
||||
graphics.push_back(NEW StoryText(text,x,y,align, font));
|
||||
if (strcmp(element->Value(), "text") == 0)
|
||||
{
|
||||
graphics.push_back(NEW StoryText(text, x, y, align, font));
|
||||
}
|
||||
else if (strcmp(element->Value(), "title")==0) {
|
||||
graphics.push_back(NEW StoryText(text,x,y,"center", Fonts::MENU_FONT));
|
||||
else if (strcmp(element->Value(), "title") == 0)
|
||||
{
|
||||
graphics.push_back(NEW StoryText(text, x, y, "center", Fonts::MENU_FONT));
|
||||
}
|
||||
else if (strcmp(element->Value(), "img")==0) {
|
||||
else if (strcmp(element->Value(), "img") == 0)
|
||||
{
|
||||
//special case to force center
|
||||
if (sX.compare("") == 0 ){
|
||||
if (sX.compare("") == 0)
|
||||
{
|
||||
x = -1;
|
||||
}
|
||||
string img = string("campaigns/").append(mParent->folder).append("/").append(text);
|
||||
graphics.push_back(NEW StoryImage(img,x,y));
|
||||
graphics.push_back(NEW StoryImage(img, x, y));
|
||||
}
|
||||
else if (strcmp(element->Value(), "answer")==0){
|
||||
else if (strcmp(element->Value(), "answer") == 0)
|
||||
{
|
||||
string id = element->Attribute("goto");
|
||||
if (!align.size()) align = "center";
|
||||
int i = mObjects.size();
|
||||
StoryChoice * sc = NEW StoryChoice(id,text,i,x, y , align, font, (i==0));
|
||||
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 {
|
||||
}
|
||||
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
|
||||
{
|
||||
StoryPage::loadElement(element); //Father
|
||||
}
|
||||
}
|
||||
@@ -416,12 +484,15 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent):StoryPage(mPar
|
||||
|
||||
}
|
||||
|
||||
void StoryDialog::Update(float dt){
|
||||
for (size_t i = 0; i < graphics.size(); ++i){
|
||||
void StoryDialog::Update(float dt)
|
||||
{
|
||||
for (size_t i = 0; i < graphics.size(); ++i)
|
||||
{
|
||||
graphics[i]->Update(dt);
|
||||
}
|
||||
|
||||
if (StoryReward::collection) {
|
||||
if (StoryReward::collection)
|
||||
{
|
||||
StoryReward::collection->save();
|
||||
SAFE_DELETE(StoryReward::collection);
|
||||
}
|
||||
@@ -431,11 +502,12 @@ void StoryDialog::Update(float dt){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void StoryDialog::RenderElement(StoryDialogElement * elmt) {
|
||||
void StoryDialog::RenderElement(StoryDialogElement * elmt)
|
||||
{
|
||||
float mYBackup = elmt->mY;
|
||||
if (! elmt->mY) elmt->mY = currentY;
|
||||
if (elmt->mY == -1) {
|
||||
if (!elmt->mY) elmt->mY = currentY;
|
||||
if (elmt->mY == -1)
|
||||
{
|
||||
elmt->mY = previousY;
|
||||
}
|
||||
elmt->Render();
|
||||
@@ -444,71 +516,83 @@ void StoryDialog::RenderElement(StoryDialogElement * elmt) {
|
||||
elmt->mY = mYBackup;
|
||||
}
|
||||
|
||||
void StoryDialog::Render() {
|
||||
void StoryDialog::Render()
|
||||
{
|
||||
currentY = 2;
|
||||
previousY = currentY;
|
||||
for (size_t i = 0; i < graphics.size(); ++i){
|
||||
StoryDialogElement * elmt = (StoryDialogElement *)(graphics[i]);
|
||||
if (mCount && elmt == mObjects[0])
|
||||
currentY += SPACE_BEFORE_CHOICES;
|
||||
for (size_t i = 0; i < graphics.size(); ++i)
|
||||
{
|
||||
StoryDialogElement * elmt = (StoryDialogElement *) (graphics[i]);
|
||||
if (mCount && elmt == mObjects[0]) currentY += SPACE_BEFORE_CHOICES;
|
||||
RenderElement(elmt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void StoryDialog::ButtonPressed(int controllerid,int controlid) {
|
||||
mParent->gotoPage(((StoryChoice *)mObjects[controlid])->pageId);
|
||||
void StoryDialog::ButtonPressed(int controllerid, int controlid)
|
||||
{
|
||||
mParent->gotoPage(((StoryChoice *) mObjects[controlid])->pageId);
|
||||
}
|
||||
|
||||
StoryDialog::~StoryDialog(){
|
||||
StoryDialog::~StoryDialog()
|
||||
{
|
||||
mCount = 0; //avoid parent deleting
|
||||
for (size_t i = 0; i < graphics.size(); ++i){
|
||||
delete(graphics[i]);
|
||||
for (size_t i = 0; i < graphics.size(); ++i)
|
||||
{
|
||||
delete (graphics[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StoryFlow::StoryFlow(string folder): folder(folder){
|
||||
StoryFlow::StoryFlow(string folder) :
|
||||
folder(folder)
|
||||
{
|
||||
string path = "campaigns/";
|
||||
path.append(folder).append("/story.xml");
|
||||
parse(path);
|
||||
}
|
||||
|
||||
|
||||
StoryPage * StoryFlow::loadPage(TiXmlElement* element){
|
||||
StoryPage * StoryFlow::loadPage(TiXmlElement* element)
|
||||
{
|
||||
TiXmlNode* typeNode = element->FirstChild("type");
|
||||
if (!typeNode) return NULL;
|
||||
StoryPage * result = NULL;
|
||||
const char* type = typeNode->ToElement()->GetText();
|
||||
if (strcmp(type, "duel")==0){
|
||||
result = NEW StoryDuel(element,this);
|
||||
}else{
|
||||
result = NEW StoryDialog(element,this);
|
||||
if (strcmp(type, "duel") == 0)
|
||||
{
|
||||
result = NEW StoryDuel(element, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = NEW StoryDialog(element, this);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
bool StoryFlow::_gotoPage(string id){
|
||||
bool StoryFlow::_gotoPage(string id)
|
||||
{
|
||||
StoryReward::rewardSoundPlayed = false;
|
||||
if (pages.find(id) == pages.end()) {
|
||||
if (pages.find(id) == pages.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
currentPageId = id;
|
||||
if (pages[currentPageId]->musicFile.size()) {
|
||||
if (pages[currentPageId]->musicFile.size())
|
||||
{
|
||||
GameApp::playMusic(pages[currentPageId]->musicFile);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StoryFlow::gotoPage(string id){
|
||||
bool StoryFlow::gotoPage(string id)
|
||||
{
|
||||
StoryReward::rewardsEnabled = true;
|
||||
return _gotoPage(id);
|
||||
}
|
||||
|
||||
bool StoryFlow::loadPageId(string id) {
|
||||
bool StoryFlow::loadPageId(string id)
|
||||
{
|
||||
StoryReward::rewardsEnabled = false;
|
||||
return _gotoPage(id);
|
||||
}
|
||||
@@ -530,10 +614,13 @@ bool StoryFlow::parse(string path)
|
||||
fileSystem->CloseFile();
|
||||
delete[] xmlBuffer;
|
||||
|
||||
for (TiXmlNode* node = doc.FirstChild(); node; node = node->NextSibling()) {
|
||||
for (TiXmlNode* node = doc.FirstChild(); node; node = node->NextSibling())
|
||||
{
|
||||
TiXmlElement* element = node->ToElement();
|
||||
if (element != NULL) {
|
||||
if (strcmp(element->Value(), "page")==0) {
|
||||
if (element != NULL)
|
||||
{
|
||||
if (strcmp(element->Value(), "page") == 0)
|
||||
{
|
||||
string id = element->Attribute("id");
|
||||
|
||||
DebugTrace("parsing " << id << "...");
|
||||
@@ -542,7 +629,8 @@ bool StoryFlow::parse(string path)
|
||||
pages[id] = sp;
|
||||
if (!currentPageId.size()) gotoPage(id);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
//Error
|
||||
}
|
||||
}
|
||||
@@ -550,28 +638,32 @@ 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);
|
||||
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;
|
||||
}
|
||||
|
||||
void StoryFlow::Update(float dt){
|
||||
void StoryFlow::Update(float dt)
|
||||
{
|
||||
pages[currentPageId]->Update(dt);
|
||||
|
||||
}
|
||||
|
||||
void StoryFlow::Render(){
|
||||
void StoryFlow::Render()
|
||||
{
|
||||
pages[currentPageId]->Render();
|
||||
|
||||
}
|
||||
|
||||
StoryFlow::~StoryFlow(){
|
||||
for (map<string,StoryPage*>::iterator i = pages.begin(); i != pages.end(); ++i){
|
||||
StoryFlow::~StoryFlow()
|
||||
{
|
||||
for (map<string, StoryPage*>::iterator i = pages.begin(); i != pages.end(); ++i)
|
||||
{
|
||||
SAFE_DELETE(i->second);
|
||||
}
|
||||
pages.clear();
|
||||
|
||||
@@ -9,123 +9,140 @@
|
||||
#include "StyleManager.h"
|
||||
#include "../../../JGE/src/tinyxml/tinyxml.h"
|
||||
|
||||
void StyleManager::killRules(){
|
||||
void StyleManager::killRules()
|
||||
{
|
||||
activeStyle = "";
|
||||
vector<WStyleRule*>::iterator i;
|
||||
for(i=rules.begin();i!=rules.end();i++)
|
||||
for (i = rules.begin(); i != rules.end(); i++)
|
||||
SAFE_DELETE(*i);
|
||||
rules.clear();
|
||||
|
||||
map<string,WStyle*>::iterator mi;
|
||||
for(mi=styles.begin();mi!=styles.end();mi++){
|
||||
map<string, WStyle*>::iterator mi;
|
||||
for (mi = styles.begin(); mi != styles.end(); mi++)
|
||||
{
|
||||
SAFE_DELETE(mi->second);
|
||||
}
|
||||
styles.clear();
|
||||
}
|
||||
|
||||
StyleManager::StyleManager(){
|
||||
StyleManager::StyleManager()
|
||||
{
|
||||
loadRules();
|
||||
}
|
||||
|
||||
StyleManager::~StyleManager(){
|
||||
StyleManager::~StyleManager()
|
||||
{
|
||||
killRules();
|
||||
}
|
||||
|
||||
|
||||
string WStyle::stylized(string filename){
|
||||
if(mapping.find(filename) != mapping.end())
|
||||
return mapping[filename];
|
||||
string WStyle::stylized(string filename)
|
||||
{
|
||||
if (mapping.find(filename) != mapping.end()) return mapping[filename];
|
||||
return filename;
|
||||
}
|
||||
void StyleManager::loadRules(){
|
||||
|
||||
void StyleManager::loadRules()
|
||||
{
|
||||
killRules();
|
||||
//TODO Placeholder until XML format available.
|
||||
string filename = JGE_GET_RES(resources.graphicsFile("style.txt"));
|
||||
TiXmlDocument xmlfile(filename.c_str());
|
||||
if(!xmlfile.LoadFile())
|
||||
return;
|
||||
if (!xmlfile.LoadFile()) return;
|
||||
TiXmlHandle hDoc(&xmlfile);
|
||||
TiXmlElement * pRule;
|
||||
for(pRule = hDoc.FirstChildElement().Element();pRule!=NULL;pRule=pRule->NextSiblingElement()){
|
||||
for (pRule = hDoc.FirstChildElement().Element(); pRule != NULL; pRule = pRule->NextSiblingElement())
|
||||
{
|
||||
//root should be "pack"
|
||||
string tag = pRule->Value();
|
||||
std::transform(tag.begin(),tag.end(),tag.begin(),::tolower);
|
||||
if(tag == "activebg"){
|
||||
std::transform(tag.begin(), tag.end(), tag.begin(), ::tolower);
|
||||
if (tag == "activebg")
|
||||
{
|
||||
//After validating, handle actual loading.
|
||||
TiXmlElement * pSlot;
|
||||
const char * holder = NULL;
|
||||
holder = pRule->Attribute("source");
|
||||
if(holder) playerSrc = atoi(holder); else playerSrc = -1;
|
||||
if (holder)
|
||||
playerSrc = atoi(holder);
|
||||
else
|
||||
playerSrc = -1;
|
||||
|
||||
for (pSlot=pRule->FirstChildElement();pSlot!=NULL;pSlot=pSlot->NextSiblingElement()){
|
||||
for (pSlot = pRule->FirstChildElement(); pSlot != NULL; pSlot = pSlot->NextSiblingElement())
|
||||
{
|
||||
//Load slot.
|
||||
tag = pSlot->Value();
|
||||
std::transform(tag.begin(),tag.end(),tag.begin(),::tolower);
|
||||
if(tag != "case") continue;
|
||||
std::transform(tag.begin(), tag.end(), tag.begin(), ::tolower);
|
||||
if (tag != "case") continue;
|
||||
|
||||
WStyleRule * r = NEW WStyleRule();
|
||||
rules.push_back(r);
|
||||
|
||||
holder = pSlot->Attribute("rule");
|
||||
if(holder) r->filter = holder;
|
||||
if (holder) r->filter = holder;
|
||||
r->style = pSlot->GetText();
|
||||
}
|
||||
} else if(tag == "style"){
|
||||
}
|
||||
else if (tag == "style")
|
||||
{
|
||||
TiXmlElement * pSlot;
|
||||
const char * holder = NULL;
|
||||
holder = pRule->Attribute("name");
|
||||
if(!holder) continue;
|
||||
if (!holder) continue;
|
||||
string sname = holder;
|
||||
WStyle * s = NEW WStyle();
|
||||
|
||||
for (pSlot=pRule->FirstChildElement();pSlot!=NULL;pSlot=pSlot->NextSiblingElement()){
|
||||
for (pSlot = pRule->FirstChildElement(); pSlot != NULL; pSlot = pSlot->NextSiblingElement())
|
||||
{
|
||||
|
||||
tag = pSlot->Value();
|
||||
std::transform(tag.begin(),tag.end(),tag.begin(),::tolower);
|
||||
if(tag.size() && pSlot->GetText())
|
||||
s->mapping[tag] = pSlot->GetText();
|
||||
std::transform(tag.begin(), tag.end(), tag.begin(), ::tolower);
|
||||
if (tag.size() && pSlot->GetText()) s->mapping[tag] = pSlot->GetText();
|
||||
}
|
||||
if(styles[sname]) SAFE_DELETE(styles[sname]);
|
||||
if (styles[sname])
|
||||
SAFE_DELETE(styles[sname]);
|
||||
styles[sname] = s;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
determineActive(NULL,NULL);
|
||||
determineActive(NULL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
WStyle * StyleManager::get() {
|
||||
if(styles.find(activeStyle) != styles.end())
|
||||
return styles[activeStyle];
|
||||
WStyle * StyleManager::get()
|
||||
{
|
||||
if (styles.find(activeStyle) != styles.end()) return styles[activeStyle];
|
||||
return NULL;
|
||||
};
|
||||
}
|
||||
|
||||
void StyleManager::determineActive(MTGDeck * p1, MTGDeck * p2)
|
||||
{
|
||||
string check = options[Options::GUI_STYLE].str;
|
||||
if(check.size() && styles.find(check) != styles.end()){
|
||||
if (check.size() && styles.find(check) != styles.end())
|
||||
{
|
||||
string prior = activeStyle;
|
||||
activeStyle = check;
|
||||
if(prior != activeStyle)
|
||||
resources.Refresh();
|
||||
if (prior != activeStyle) resources.Refresh();
|
||||
return;
|
||||
}
|
||||
topRule = -1; topSize = 0;
|
||||
topRule = -1;
|
||||
topSize = 0;
|
||||
|
||||
MTGDeck * tempDeck = NEW MTGDeck(GameApp::collection);
|
||||
if(p1 && playerSrc != 2) tempDeck->add(p1);
|
||||
if(p2 && playerSrc != 1) tempDeck->add(p2);
|
||||
if (p1 && playerSrc != 2) tempDeck->add(p1);
|
||||
if (p2 && playerSrc != 1) tempDeck->add(p2);
|
||||
WCFilterFactory * ff = WCFilterFactory::GetInstance();
|
||||
|
||||
if(tempDeck){
|
||||
if (tempDeck)
|
||||
{
|
||||
DeckDataWrapper * ddw = NEW DeckDataWrapper(tempDeck);
|
||||
for(int r=0;r<(int)rules.size();r++){
|
||||
for (int r = 0; r < (int) rules.size(); r++)
|
||||
{
|
||||
ddw->clearFilters();
|
||||
ddw->addFilter(ff->Construct(rules[r]->filter));
|
||||
ddw->validate();
|
||||
int ct = ddw->getCount(WSrcDeck::FILTERED_COPIES);
|
||||
if(ct > topSize) {
|
||||
if (ct > topSize)
|
||||
{
|
||||
topRule = r;
|
||||
topSize = ct;
|
||||
}
|
||||
@@ -136,12 +153,11 @@ void StyleManager::determineActive(MTGDeck * p1, MTGDeck * p2)
|
||||
|
||||
string prior = activeStyle;
|
||||
activeStyle = "";
|
||||
if(topRule >= 0){
|
||||
map<string,WStyle*>::iterator mi = styles.find(rules[topRule]->style);
|
||||
if(mi != styles.end())
|
||||
activeStyle = mi->first;
|
||||
if (topRule >= 0)
|
||||
{
|
||||
map<string, WStyle*>::iterator mi = styles.find(rules[topRule]->style);
|
||||
if (mi != styles.end()) activeStyle = mi->first;
|
||||
}
|
||||
if(prior != activeStyle)
|
||||
resources.Refresh();
|
||||
if (prior != activeStyle) resources.Refresh();
|
||||
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
Subtypes * Subtypes::subtypesList = NEW Subtypes();
|
||||
|
||||
|
||||
Subtypes::Subtypes(){
|
||||
Subtypes::Subtypes()
|
||||
{
|
||||
//Add the more common types, so that they can be accessed through ints
|
||||
//these should be added in the same order as the enum defined in subtypes.h!!!
|
||||
find("Creature");
|
||||
@@ -17,23 +17,26 @@ Subtypes::Subtypes(){
|
||||
find("Legendary");
|
||||
}
|
||||
|
||||
int Subtypes::find(string value, bool forceAdd){
|
||||
if (value[0]>=97 && value[0]<=122) value[0]-=32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
|
||||
map<string,int>::iterator it = values.find(value);
|
||||
int Subtypes::find(string value, bool forceAdd)
|
||||
{
|
||||
if (value[0] >= 97 && value[0] <= 122) value[0] -= 32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
|
||||
map<string, int>::iterator it = values.find(value);
|
||||
if (it != values.end()) return it->second;
|
||||
if (!forceAdd) return 0;
|
||||
int id = (int)(valuesById.size() + 1);
|
||||
int id = (int) (valuesById.size() + 1);
|
||||
values[value] = id;
|
||||
valuesById.push_back(value);
|
||||
return id;
|
||||
}
|
||||
|
||||
int Subtypes::find(const char * subtype, bool forceAdd){
|
||||
int Subtypes::find(const char * subtype, bool forceAdd)
|
||||
{
|
||||
string value = subtype;
|
||||
return find(value, forceAdd);
|
||||
}
|
||||
|
||||
string Subtypes::find(unsigned int id){
|
||||
string Subtypes::find(unsigned int id)
|
||||
{
|
||||
if (valuesById.size() < id || !id) return "";
|
||||
return valuesById[id - 1];
|
||||
}
|
||||
|
||||
+527
-293
File diff suppressed because it is too large
Load Diff
@@ -6,19 +6,24 @@
|
||||
#include "Damage.h"
|
||||
#include "ActionStack.h"
|
||||
|
||||
TargetsList::TargetsList(){
|
||||
TargetsList::TargetsList()
|
||||
{
|
||||
cursor = 0;
|
||||
}
|
||||
|
||||
TargetsList::TargetsList(Targetable * _targets[], int nbtargets){
|
||||
for (int i = 0; i < nbtargets; i++){
|
||||
TargetsList::TargetsList(Targetable * _targets[], int nbtargets)
|
||||
{
|
||||
for (int i = 0; i < nbtargets; i++)
|
||||
{
|
||||
targets[i] = _targets[i];
|
||||
}
|
||||
cursor = nbtargets;
|
||||
}
|
||||
|
||||
int TargetsList::addTarget(Targetable * target){
|
||||
if (!alreadyHasTarget(target)){
|
||||
int TargetsList::addTarget(Targetable * target)
|
||||
{
|
||||
if (!alreadyHasTarget(target))
|
||||
{
|
||||
targets[cursor] = target;
|
||||
cursor++;
|
||||
return 1;
|
||||
@@ -27,17 +32,21 @@ int TargetsList::addTarget(Targetable * target){
|
||||
|
||||
}
|
||||
|
||||
|
||||
int TargetsList::alreadyHasTarget(Targetable * target){
|
||||
for (int i=0; i<cursor; i++){
|
||||
int TargetsList::alreadyHasTarget(Targetable * target)
|
||||
{
|
||||
for (int i = 0; i < cursor; i++)
|
||||
{
|
||||
if (targets[i] == target) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TargetsList::removeTarget(Targetable * target){
|
||||
for (int i=0; i<cursor; i++){
|
||||
if (targets[i] == target) {
|
||||
int TargetsList::removeTarget(Targetable * target)
|
||||
{
|
||||
for (int i = 0; i < cursor; i++)
|
||||
{
|
||||
if (targets[i] == target)
|
||||
{
|
||||
targets[i] = targets[cursor];
|
||||
targets[cursor] = NULL;
|
||||
cursor--;
|
||||
@@ -47,23 +56,28 @@ int TargetsList::removeTarget(Targetable * target){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int TargetsList::toggleTarget(Targetable * target){
|
||||
if (alreadyHasTarget(target)){
|
||||
int TargetsList::toggleTarget(Targetable * target)
|
||||
{
|
||||
if (alreadyHasTarget(target))
|
||||
{
|
||||
|
||||
return removeTarget(target);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return addTarget(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Targetable * TargetsList::getNextTarget(Targetable * previous , int type){
|
||||
Targetable * TargetsList::getNextTarget(Targetable * previous, int type)
|
||||
{
|
||||
int found = 0;
|
||||
if (!previous) found = 1;
|
||||
for (int i = 0; i < cursor; i++){
|
||||
if (found && (type == -1 || targets[i]->typeAsTarget() == type)){
|
||||
for (int i = 0; i < cursor; i++)
|
||||
{
|
||||
if (found && (type == -1 || targets[i]->typeAsTarget() == type))
|
||||
{
|
||||
return (targets[i]);
|
||||
}
|
||||
if (targets[i] == previous) found = 1;
|
||||
@@ -71,23 +85,27 @@ Targetable * TargetsList::getNextTarget(Targetable * previous , int type){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MTGCardInstance * TargetsList::getNextCardTarget(MTGCardInstance * previous){
|
||||
return ((MTGCardInstance *)getNextTarget(previous, TARGET_CARD));
|
||||
MTGCardInstance * TargetsList::getNextCardTarget(MTGCardInstance * previous)
|
||||
{
|
||||
return ((MTGCardInstance *) getNextTarget(previous, TARGET_CARD));
|
||||
}
|
||||
|
||||
|
||||
Player * TargetsList::getNextPlayerTarget(Player * previous){
|
||||
return ((Player *)getNextTarget(previous, TARGET_PLAYER));
|
||||
Player * TargetsList::getNextPlayerTarget(Player * previous)
|
||||
{
|
||||
return ((Player *) getNextTarget(previous, TARGET_PLAYER));
|
||||
}
|
||||
|
||||
|
||||
Interruptible * TargetsList::getNextInterruptible(Interruptible * previous, int type){
|
||||
Interruptible * TargetsList::getNextInterruptible(Interruptible * previous, int type)
|
||||
{
|
||||
int found = 0;
|
||||
if (!previous) found = 1;
|
||||
for (int i = 0; i < cursor; i++){
|
||||
if (found && targets[i]->typeAsTarget() == TARGET_STACKACTION){
|
||||
for (int i = 0; i < cursor; i++)
|
||||
{
|
||||
if (found && targets[i]->typeAsTarget() == TARGET_STACKACTION)
|
||||
{
|
||||
Interruptible * action = (Interruptible *) targets[i];
|
||||
if (action->type==type){
|
||||
if (action->type == type)
|
||||
{
|
||||
return action;
|
||||
}
|
||||
}
|
||||
@@ -96,33 +114,46 @@ Interruptible * TargetsList::getNextInterruptible(Interruptible * previous, int
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Spell * TargetsList::getNextSpellTarget(Spell * previous){
|
||||
Spell * TargetsList::getNextSpellTarget(Spell * previous)
|
||||
{
|
||||
Spell * spell = (Spell *) getNextInterruptible(previous, ACTION_SPELL);
|
||||
return spell;
|
||||
}
|
||||
|
||||
//How about DAMAGESTacks ??
|
||||
Damage * TargetsList::getNextDamageTarget(Damage * previous){
|
||||
Damage * damage = (Damage * ) getNextInterruptible(previous, ACTION_DAMAGE);
|
||||
Damage * TargetsList::getNextDamageTarget(Damage * previous)
|
||||
{
|
||||
Damage * damage = (Damage *) getNextInterruptible(previous, ACTION_DAMAGE);
|
||||
return damage;
|
||||
}
|
||||
|
||||
Damageable * TargetsList::getNextDamageableTarget(Damageable * previous){
|
||||
Damageable * TargetsList::getNextDamageableTarget(Damageable * previous)
|
||||
{
|
||||
int found = 0;
|
||||
if (!previous) found = 1;
|
||||
for (int i = 0; i < cursor; i++){
|
||||
for (int i = 0; i < cursor; i++)
|
||||
{
|
||||
|
||||
if (targets[i]->typeAsTarget() == TARGET_PLAYER){
|
||||
if (found){
|
||||
if (targets[i]->typeAsTarget() == TARGET_PLAYER)
|
||||
{
|
||||
if (found)
|
||||
{
|
||||
return ((Player *) targets[i]);
|
||||
}else{
|
||||
if ((Player *)targets[i] == previous) found = 1;
|
||||
}
|
||||
}else if(targets[i]->typeAsTarget() == TARGET_CARD){
|
||||
if (found){
|
||||
else
|
||||
{
|
||||
if ((Player *) targets[i] == previous) found = 1;
|
||||
}
|
||||
}
|
||||
else if (targets[i]->typeAsTarget() == TARGET_CARD)
|
||||
{
|
||||
if (found)
|
||||
{
|
||||
return ((MTGCardInstance *) targets[i]);
|
||||
}else{
|
||||
if ((MTGCardInstance *)targets[i] == previous) found = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((MTGCardInstance *) targets[i] == previous) found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+464
-287
File diff suppressed because it is too large
Load Diff
+320
-172
@@ -13,29 +13,34 @@ using std::string;
|
||||
|
||||
// NULL is sent in place of a MTGDeck since there is no way to create a MTGDeck without a proper deck file.
|
||||
// TestSuiteAI will be responsible for managing its own deck state.
|
||||
TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId):AIPlayerBaka(NULL, "testsuite", "testsuite", "baka.jpg") {
|
||||
TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId) :
|
||||
AIPlayerBaka(NULL, "testsuite", "testsuite", "baka.jpg")
|
||||
{
|
||||
this->game = _suite->buildDeck(playerId);
|
||||
game->setOwner( this );
|
||||
game->setOwner(this);
|
||||
suite = _suite;
|
||||
timer = 0;
|
||||
playMode = MODE_TEST_SUITE;
|
||||
this->deckName = "Test Suite AI";
|
||||
}
|
||||
|
||||
|
||||
MTGCardInstance * TestSuiteAI::getCard(string action){
|
||||
MTGCardInstance * TestSuiteAI::getCard(string action)
|
||||
{
|
||||
int mtgid = Rules::getMTGId(action);
|
||||
if (mtgid) return Rules::getCardByMTGId(mtgid);
|
||||
|
||||
//This mostly handles tokens
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
std::transform(action.begin(), action.end(), action.begin(),::tolower );
|
||||
for (int i = 0; i < 2; i++){
|
||||
std::transform(action.begin(), action.end(), action.begin(), ::tolower);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Player * p = g->players[i];
|
||||
MTGGameZone * zones[] = {p->game->library,p->game->hand, p->game->inPlay, p->game->graveyard};
|
||||
for (int j = 0; j < 4; j++){
|
||||
MTGGameZone * zones[] = { p->game->library, p->game->hand, p->game->inPlay, p->game->graveyard };
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
MTGGameZone * zone = zones[j];
|
||||
for (int k = 0; k < zone->nb_cards; k++){
|
||||
for (int k = 0; k < zone->nb_cards; k++)
|
||||
{
|
||||
MTGCardInstance * card = zone->cards[k];
|
||||
if (!card) return NULL;
|
||||
string name = card->getLCName();
|
||||
@@ -47,38 +52,43 @@ MTGCardInstance * TestSuiteAI::getCard(string action){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Interruptible * TestSuite::getActionByMTGId(int mtgid){
|
||||
ActionStack * as= GameObserver::GetInstance()->mLayers->stackLayer();
|
||||
Interruptible * TestSuite::getActionByMTGId(int mtgid)
|
||||
{
|
||||
ActionStack * as = GameObserver::GetInstance()->mLayers->stackLayer();
|
||||
Interruptible * action = NULL;
|
||||
while ((action = as->getNext(action,0,0,1))){
|
||||
if (action->source && action->source->getMTGId() == mtgid){
|
||||
while ((action = as->getNext(action, 0, 0, 1)))
|
||||
{
|
||||
if (action->source && action->source->getMTGId() == mtgid)
|
||||
{
|
||||
return action;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int TestSuiteAI::displayStack(){
|
||||
int TestSuiteAI::displayStack()
|
||||
{
|
||||
if (playMode == MODE_AI) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TestSuiteAI::Act(float dt){
|
||||
int TestSuiteAI::Act(float dt)
|
||||
{
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
g->gameOver = NULL; // Prevent draw rule from losing the game
|
||||
if (playMode == MODE_AI && suite->aiMaxCalls) {
|
||||
if (playMode == MODE_AI && suite->aiMaxCalls)
|
||||
{
|
||||
suite->aiMaxCalls--;
|
||||
suite->timerLimit = 40; //TODO Remove this limitation when AI is not using a stupid timer anymore...
|
||||
AIPlayerBaka::Act(dt);
|
||||
}
|
||||
if (playMode == MODE_HUMAN){
|
||||
if (playMode == MODE_HUMAN)
|
||||
{
|
||||
g->mLayers->CheckUserInput(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
timer+= 1;
|
||||
timer += 1;
|
||||
if (timer < suite->timerLimit) return 1;
|
||||
timer = 0;
|
||||
|
||||
@@ -87,15 +97,18 @@ int TestSuiteAI::Act(float dt){
|
||||
// DamageResolverLayer * drl = g->mLayers->combatLayer();
|
||||
DebugTrace("TESTSUITE command: " << action);
|
||||
|
||||
if (g->mLayers->stackLayer()->askIfWishesToInterrupt == this){
|
||||
if(action.compare("no") != 0 && action.compare("yes") != 0){
|
||||
if (g->mLayers->stackLayer()->askIfWishesToInterrupt == this)
|
||||
{
|
||||
if (action.compare("no") != 0 && action.compare("yes") != 0)
|
||||
{
|
||||
g->mLayers->stackLayer()->cancelInterruptOffer();
|
||||
suite->currentAction--;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (action == ""){
|
||||
if (action == "")
|
||||
{
|
||||
//end of game
|
||||
suite->assertGame();
|
||||
g->gameOver = g->players[0];
|
||||
@@ -103,67 +116,83 @@ int TestSuiteAI::Act(float dt){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (action.compare("eot")== 0){
|
||||
if (action.compare("eot") == 0)
|
||||
{
|
||||
if (g->getCurrentGamePhase() != Constants::MTG_PHASE_CLEANUP) suite->currentAction--;
|
||||
g->userRequestNextGamePhase();
|
||||
}
|
||||
else if (action.compare("human")==0){
|
||||
else if (action.compare("human") == 0)
|
||||
{
|
||||
DebugTrace("TESTSUITE You have control");
|
||||
playMode = MODE_HUMAN;
|
||||
return 1;
|
||||
}
|
||||
else if (action.compare("ai")==0){
|
||||
else if (action.compare("ai") == 0)
|
||||
{
|
||||
DebugTrace("TESTSUITE Switching to AI");
|
||||
playMode = MODE_AI;
|
||||
return 1;
|
||||
}
|
||||
else if (action.compare("next")==0){
|
||||
else if (action.compare("next") == 0)
|
||||
{
|
||||
GuiCombat * gc = g->mLayers->combatLayer();
|
||||
if (ORDER == g->combatStep || DAMAGE == g->combatStep)
|
||||
gc->clickOK();
|
||||
else g->userRequestNextGamePhase();
|
||||
else
|
||||
g->userRequestNextGamePhase();
|
||||
}
|
||||
else if (action.compare("yes")==0)
|
||||
else if (action.compare("yes") == 0)
|
||||
g->mLayers->stackLayer()->setIsInterrupting(this);
|
||||
else if (action.compare("endinterruption")==0)
|
||||
else if (action.compare("endinterruption") == 0)
|
||||
g->mLayers->stackLayer()->endOfInterruption();
|
||||
else if(action.compare("no")==0){
|
||||
if (g->mLayers->stackLayer()->askIfWishesToInterrupt == this)
|
||||
g->mLayers->stackLayer()->cancelInterruptOffer();
|
||||
}else if(action.find("choice ")!=string::npos){
|
||||
else if (action.compare("no") == 0)
|
||||
{
|
||||
if (g->mLayers->stackLayer()->askIfWishesToInterrupt == this) g->mLayers->stackLayer()->cancelInterruptOffer();
|
||||
}
|
||||
else if (action.find("choice ") != string::npos)
|
||||
{
|
||||
DebugTrace("TESTSUITE choice !!!");
|
||||
int choice = atoi(action.substr(action.find("choice ") + 7).c_str());
|
||||
g->mLayers->actionLayer()->doReactTo(choice);
|
||||
}else if(action.find(" -momir- ")!=string::npos){
|
||||
}
|
||||
else if (action.find(" -momir- ") != string::npos)
|
||||
{
|
||||
int start = action.find(" -momir- ");
|
||||
int cardId = Rules::getMTGId(action.substr(start + 9).c_str());
|
||||
int cardIdHand = Rules::getMTGId(action.substr(0,start).c_str());
|
||||
MTGMomirRule * a = ((MTGMomirRule *)g->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR));
|
||||
int cardIdHand = Rules::getMTGId(action.substr(0, start).c_str());
|
||||
MTGMomirRule * a = ((MTGMomirRule *) g->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR));
|
||||
a->reactToClick(Rules::getCardByMTGId(cardIdHand), cardId);
|
||||
g->mLayers->actionLayer()->stuffHappened = 1;
|
||||
}else if(action.find("p1")!=string::npos || action.find("p2")!=string::npos){
|
||||
}
|
||||
else if (action.find("p1") != string::npos || action.find("p2") != string::npos)
|
||||
{
|
||||
Player * p = g->players[1];
|
||||
size_t start = action.find("p1");
|
||||
if (start != string::npos) p = g->players[0];
|
||||
g->cardClick(NULL, p);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
int mtgid = Rules::getMTGId(action);
|
||||
Interruptible * toInterrupt = NULL;
|
||||
if (mtgid){
|
||||
if (mtgid)
|
||||
{
|
||||
DebugTrace("TESTSUITE CARD ID:" << mtgid);
|
||||
toInterrupt = suite->getActionByMTGId(mtgid);
|
||||
}
|
||||
|
||||
if (toInterrupt) {
|
||||
if (toInterrupt)
|
||||
{
|
||||
g->stackObjectClicked(toInterrupt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
MTGCardInstance * card = getCard(action);
|
||||
if (card) {
|
||||
if (card)
|
||||
{
|
||||
DebugTrace("TESTSUITE Clicking ON: " << card->name);
|
||||
card->currentZone->needShuffle = true; //mimic library shuffle
|
||||
g->cardClick(card,card);
|
||||
g->cardClick(card, card);
|
||||
g->forceShuffleLibraries(); //mimic library shuffle
|
||||
return 1;
|
||||
}
|
||||
@@ -171,96 +200,126 @@ int TestSuiteAI::Act(float dt){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
TestSuiteActions::TestSuiteActions(){
|
||||
TestSuiteActions::TestSuiteActions()
|
||||
{
|
||||
nbitems = 0;
|
||||
}
|
||||
|
||||
void TestSuiteActions::add(string s){
|
||||
void TestSuiteActions::add(string s)
|
||||
{
|
||||
actions[nbitems] = s;
|
||||
nbitems++;
|
||||
}
|
||||
|
||||
TestSuitePlayerData::TestSuitePlayerData(){
|
||||
TestSuitePlayerData::TestSuitePlayerData()
|
||||
{
|
||||
life = 20;
|
||||
manapool = NEW ManaCost();
|
||||
}
|
||||
|
||||
TestSuitePlayerData::~TestSuitePlayerData(){
|
||||
TestSuitePlayerData::~TestSuitePlayerData()
|
||||
{
|
||||
SAFE_DELETE(manapool);
|
||||
}
|
||||
|
||||
TestSuitePlayerZone::TestSuitePlayerZone(){
|
||||
TestSuitePlayerZone::TestSuitePlayerZone()
|
||||
{
|
||||
nbitems = 0;
|
||||
}
|
||||
|
||||
void TestSuitePlayerZone::add(int cardId){
|
||||
void TestSuitePlayerZone::add(int cardId)
|
||||
{
|
||||
cards[nbitems] = cardId;
|
||||
nbitems++;
|
||||
}
|
||||
|
||||
TestSuiteState::TestSuiteState(){
|
||||
TestSuiteState::TestSuiteState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestSuiteState::parsePlayerState(int playerId, string s){
|
||||
void TestSuiteState::parsePlayerState(int playerId, string s)
|
||||
{
|
||||
size_t limiter = s.find(":");
|
||||
string areaS;
|
||||
int area;
|
||||
if (limiter != string::npos){
|
||||
areaS = s.substr(0,limiter);
|
||||
if (areaS.compare("graveyard") == 0){
|
||||
if (limiter != string::npos)
|
||||
{
|
||||
areaS = s.substr(0, limiter);
|
||||
if (areaS.compare("graveyard") == 0)
|
||||
{
|
||||
area = 0;
|
||||
}else if(areaS.compare("library") == 0){
|
||||
}
|
||||
else if (areaS.compare("library") == 0)
|
||||
{
|
||||
area = 1;
|
||||
}else if(areaS.compare("hand") == 0){
|
||||
}
|
||||
else if (areaS.compare("hand") == 0)
|
||||
{
|
||||
area = 2;
|
||||
}else if(areaS.compare("inplay") == 0 || areaS.compare("battlefield") == 0 ){
|
||||
}
|
||||
else if (areaS.compare("inplay") == 0 || areaS.compare("battlefield") == 0)
|
||||
{
|
||||
area = 3;
|
||||
}else if(areaS.compare("life") == 0){
|
||||
playerData[playerId].life = atoi((s.substr(limiter+1)).c_str());
|
||||
}
|
||||
else if (areaS.compare("life") == 0)
|
||||
{
|
||||
playerData[playerId].life = atoi((s.substr(limiter + 1)).c_str());
|
||||
return;
|
||||
}else if(areaS.compare("manapool") == 0){
|
||||
}
|
||||
else if (areaS.compare("manapool") == 0)
|
||||
{
|
||||
SAFE_DELETE(playerData[playerId].manapool);
|
||||
playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter+1));
|
||||
playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter + 1));
|
||||
return;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // ERROR
|
||||
}
|
||||
s = s.substr(limiter+1);
|
||||
while (s.size()){
|
||||
s = s.substr(limiter + 1);
|
||||
while (s.size())
|
||||
{
|
||||
unsigned int value;
|
||||
limiter = s.find(",");
|
||||
if (limiter != string::npos){
|
||||
string ss = s.substr(0,limiter); // ss is needed because trim requires a non-const reference,
|
||||
if (limiter != string::npos)
|
||||
{
|
||||
string ss = s.substr(0, limiter); // ss is needed because trim requires a non-const reference,
|
||||
value = Rules::getMTGId(trim(ss)); // while in g++ functions cannot take non-const references from temporary values
|
||||
s = s.substr(limiter+1);
|
||||
}else{
|
||||
s = s.substr(limiter + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = Rules::getMTGId(trim(s));
|
||||
s = "";
|
||||
}
|
||||
if (value) playerData[playerId].zones[area].add(value);
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
//ERROR
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string TestSuite::getNextAction(){
|
||||
string TestSuite::getNextAction()
|
||||
{
|
||||
currentAction++;
|
||||
if (actions.nbitems && currentAction <= actions.nbitems){
|
||||
return actions.actions[currentAction-1];
|
||||
if (actions.nbitems && currentAction <= actions.nbitems)
|
||||
{
|
||||
return actions.actions[currentAction - 1];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
MTGPlayerCards * TestSuite::buildDeck( int playerId){
|
||||
MTGPlayerCards * TestSuite::buildDeck(int playerId)
|
||||
{
|
||||
int list[100];
|
||||
int nbcards = 0;
|
||||
for (int j = 0; j < 4; j++){
|
||||
for (int k = 0; k < initState.playerData[playerId].zones[j].nbitems; k++){
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
for (int k = 0; k < initState.playerData[playerId].zones[j].nbitems; k++)
|
||||
{
|
||||
int cardid = initState.playerData[playerId].zones[j].cards[k];
|
||||
list[nbcards] = cardid;
|
||||
nbcards++;
|
||||
@@ -270,14 +329,18 @@ MTGPlayerCards * TestSuite::buildDeck( int playerId){
|
||||
return deck;
|
||||
}
|
||||
|
||||
void TestSuite::initGame(){
|
||||
void TestSuite::initGame()
|
||||
{
|
||||
//The first test runs slowly, the other ones run faster.
|
||||
//This way a human can see what happens when testing a specific file,
|
||||
// or go faster when it comes to the whole test suite.
|
||||
//Warning, putting this value too low (< 3) will give unexpected results
|
||||
if (!timerLimit){
|
||||
if (!timerLimit)
|
||||
{
|
||||
timerLimit = 40;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
timerLimit = 3;
|
||||
}
|
||||
//Put the GameObserver in the initial state
|
||||
@@ -285,40 +348,55 @@ void TestSuite::initGame(){
|
||||
DebugTrace("TESTSUITE Init Game");
|
||||
g->phaseRing->goToPhase(initState.phase, g->players[0]);
|
||||
g->currentGamePhase = initState.phase;
|
||||
for (int i = 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
AIPlayer * p = (AIPlayer *) (g->players[i]);
|
||||
p->forceBestAbilityUse = forceAbility;
|
||||
p->life = initState.playerData[i].life;
|
||||
p->getManaPool()->copy(initState.playerData[i].manapool);
|
||||
MTGGameZone * playerZones[] = {p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay};
|
||||
for (int j = 0; j < 4; j++){
|
||||
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];
|
||||
for (int k = 0; k < initState.playerData[i].zones[j].nbitems; k++){
|
||||
for (int k = 0; k < initState.playerData[i].zones[j].nbitems; k++)
|
||||
{
|
||||
MTGCardInstance * card = Rules::getCardByMTGId(initState.playerData[i].zones[j].cards[k]);
|
||||
if (card && zone != p->game->library){
|
||||
if (zone == p->game->inPlay){
|
||||
if (card && zone != p->game->library)
|
||||
{
|
||||
if (zone == p->game->inPlay)
|
||||
{
|
||||
MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack);
|
||||
Spell * spell = NEW Spell(copy);
|
||||
spell->resolve();
|
||||
if (!summoningSickness && p->game->inPlay->nb_cards>k) p->game->inPlay->cards[k]->summoningSickness = 0;
|
||||
if (!summoningSickness && p->game->inPlay->nb_cards > k) p->game->inPlay->cards[k]->summoningSickness = 0;
|
||||
delete spell;
|
||||
}else{
|
||||
if (!p->game->library->hasCard(card)){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!p->game->library->hasCard(card))
|
||||
{
|
||||
LOG ("TESTUITE ERROR, CARD NOT FOUND IN LIBRARY\n");
|
||||
}
|
||||
p->game->putInZone(card,p->game->library,zone);
|
||||
p->game->putInZone(card, p->game->library, zone);
|
||||
}
|
||||
}else{
|
||||
if (!card) { LOG ("TESTUITE ERROR, card is NULL\n"); }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!card)
|
||||
{
|
||||
LOG ("TESTUITE ERROR, card is NULL\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DebugTrace("TESTUITE Init Game Done !");
|
||||
}
|
||||
DebugTrace("TESTUITE Init Game Done !");
|
||||
}
|
||||
int TestSuite::Log(const char * text){
|
||||
ofstream file (JGE_GET_RES("test/results.html").c_str(),ios_base::app);
|
||||
if (file){
|
||||
int TestSuite::Log(const char * text)
|
||||
{
|
||||
ofstream file(JGE_GET_RES("test/results.html").c_str(), ios_base::app);
|
||||
if (file)
|
||||
{
|
||||
file << text;
|
||||
file << "\n";
|
||||
file.close();
|
||||
@@ -328,54 +406,72 @@ int TestSuite::Log(const char * text){
|
||||
return 1;
|
||||
|
||||
}
|
||||
int TestSuite::assertGame(){
|
||||
int TestSuite::assertGame()
|
||||
{
|
||||
//compare the game state with the results
|
||||
char result[4096];
|
||||
sprintf(result,"<h3>%s</h3>",files[currentfile-1].c_str());
|
||||
sprintf(result, "<h3>%s</h3>", files[currentfile - 1].c_str());
|
||||
Log(result);
|
||||
|
||||
int error = 0;
|
||||
bool wasAI = false;
|
||||
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (g->currentGamePhase != endState.phase){
|
||||
sprintf(result, "<span class=\"error\">==phase problem. Expected %i, got %i==</span><br />",endState.phase, g->currentGamePhase);
|
||||
if (g->currentGamePhase != endState.phase)
|
||||
{
|
||||
sprintf(result, "<span class=\"error\">==phase problem. Expected %i, got %i==</span><br />", endState.phase,
|
||||
g->currentGamePhase);
|
||||
Log(result);
|
||||
error++;
|
||||
}
|
||||
for (int i = 0; i < 2; i++){
|
||||
TestSuiteAI * p = (TestSuiteAI *)(g->players[i]);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
TestSuiteAI * p = (TestSuiteAI *) (g->players[i]);
|
||||
if (p->playMode == Player::MODE_AI) wasAI = true;
|
||||
|
||||
if (p->life != endState.playerData[i].life){
|
||||
sprintf(result, "<span class=\"error\">==life problem for player %i. Expected %i, got %i==</span><br />",i,endState.playerData[i].life, p->life);
|
||||
if (p->life != endState.playerData[i].life)
|
||||
{
|
||||
sprintf(result, "<span class=\"error\">==life problem for player %i. Expected %i, got %i==</span><br />", i,
|
||||
endState.playerData[i].life, p->life);
|
||||
Log(result);
|
||||
error++;
|
||||
}
|
||||
if (! p->getManaPool()->canAfford(endState.playerData[i].manapool)){
|
||||
sprintf(result, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />",endState.playerData[i].manapool->getConvertedCost(),p->getManaPool()->getConvertedCost(),i);
|
||||
if (!p->getManaPool()->canAfford(endState.playerData[i].manapool))
|
||||
{
|
||||
sprintf(result, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />",
|
||||
endState.playerData[i].manapool->getConvertedCost(), p->getManaPool()->getConvertedCost(), i);
|
||||
Log(result);
|
||||
error++;
|
||||
}
|
||||
if(! endState.playerData[i].manapool->canAfford(p->getManaPool())){
|
||||
sprintf(result, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />",endState.playerData[i].manapool->getConvertedCost(),p->getManaPool()->getConvertedCost(),i);
|
||||
if (!endState.playerData[i].manapool->canAfford(p->getManaPool()))
|
||||
{
|
||||
sprintf(result, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />",
|
||||
endState.playerData[i].manapool->getConvertedCost(), p->getManaPool()->getConvertedCost(), i);
|
||||
Log(result);
|
||||
error++;
|
||||
|
||||
}
|
||||
MTGGameZone * playerZones[] = {p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay};
|
||||
for (int j = 0; j < 4; j++){
|
||||
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];
|
||||
if (zone->nb_cards != endState.playerData[i].zones[j].nbitems){
|
||||
sprintf(result, "<span class=\"error\">==Card number not the same in player %i's %s==, expected %i, got %i</span><br />",i, zone->getName(), endState.playerData[i].zones[j].nbitems, zone->nb_cards);
|
||||
if (zone->nb_cards != endState.playerData[i].zones[j].nbitems)
|
||||
{
|
||||
sprintf(
|
||||
result,
|
||||
"<span class=\"error\">==Card number not the same in player %i's %s==, expected %i, got %i</span><br />",
|
||||
i, zone->getName(), endState.playerData[i].zones[j].nbitems, zone->nb_cards);
|
||||
Log(result);
|
||||
error++;
|
||||
}
|
||||
for (int k = 0; k < endState.playerData[i].zones[j].nbitems; k++){
|
||||
for (int k = 0; k < endState.playerData[i].zones[j].nbitems; k++)
|
||||
{
|
||||
int cardid = endState.playerData[i].zones[j].cards[k];
|
||||
if (cardid != -1){
|
||||
if (cardid != -1)
|
||||
{
|
||||
MTGCardInstance * card = Rules::getCardByMTGId(cardid);
|
||||
if (!card || !zone->hasCard(card)){
|
||||
if (!card || !zone->hasCard(card))
|
||||
{
|
||||
sprintf(result, "<span class=\"error\">==Card ID not the same. Didn't find %i</span><br />", cardid);
|
||||
Log(result);
|
||||
error++;
|
||||
@@ -384,15 +480,20 @@ int TestSuite::assertGame(){
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wasAI) {
|
||||
if (wasAI)
|
||||
{
|
||||
nbAITests++;
|
||||
if (error) {
|
||||
if (error)
|
||||
{
|
||||
nbAIFailed++;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTests++;
|
||||
if (error) {
|
||||
if (error)
|
||||
{
|
||||
nbFailed++;
|
||||
return 0;
|
||||
}
|
||||
@@ -401,8 +502,9 @@ int TestSuite::assertGame(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
|
||||
collection=_collection;
|
||||
TestSuite::TestSuite(const char * filename, MTGAllCards* _collection)
|
||||
{
|
||||
collection = _collection;
|
||||
timerLimit = 0;
|
||||
std::ifstream file(filename);
|
||||
std::string s;
|
||||
@@ -416,12 +518,15 @@ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
|
||||
seed = 0;
|
||||
forceAbility = false;
|
||||
aiMaxCalls = -1;
|
||||
if(file){
|
||||
while(std::getline(file,s)){
|
||||
if (file)
|
||||
{
|
||||
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[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
|
||||
if (s[0] == '/' && s[1] == '*') comment = 1;
|
||||
if (s[0] && s[0] != '#' && !comment){
|
||||
if (s[0] && s[0] != '#' && !comment)
|
||||
{
|
||||
files[nbfiles] = s;
|
||||
nbfiles++;
|
||||
}
|
||||
@@ -430,8 +535,9 @@ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
|
||||
file.close();
|
||||
}
|
||||
|
||||
ofstream file2 (JGE_GET_RES("/test/results.html").c_str());
|
||||
if (file2){
|
||||
ofstream file2(JGE_GET_RES("/test/results.html").c_str());
|
||||
if (file2)
|
||||
{
|
||||
file2 << "<html><head>";
|
||||
#ifdef WIN32
|
||||
file2 << "<meta http-equiv=\"refresh\" content=\"10\" >";
|
||||
@@ -445,46 +551,55 @@ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
|
||||
|
||||
}
|
||||
|
||||
int TestSuite::loadNext(){
|
||||
int TestSuite::loadNext()
|
||||
{
|
||||
summoningSickness = 0;
|
||||
seed = 0;
|
||||
aiMaxCalls = -1;
|
||||
if (!nbfiles) return 0;
|
||||
if (currentfile >= nbfiles) return 0;
|
||||
currentfile++;
|
||||
if (!load(files[currentfile-1].c_str())) return loadNext();
|
||||
else cout << "Starting test : " << files[currentfile-1] << endl;
|
||||
if (!load(files[currentfile - 1].c_str()))
|
||||
return loadNext();
|
||||
else
|
||||
cout << "Starting test : " << files[currentfile - 1] << endl;
|
||||
//load(files[currentfile].c_str());
|
||||
//currentfile++;
|
||||
return currentfile;
|
||||
}
|
||||
|
||||
|
||||
void TestSuiteActions::cleanup(){
|
||||
void TestSuiteActions::cleanup()
|
||||
{
|
||||
nbitems = 0;
|
||||
}
|
||||
|
||||
void TestSuitePlayerZone::cleanup(){
|
||||
void TestSuitePlayerZone::cleanup()
|
||||
{
|
||||
nbitems = 0;
|
||||
}
|
||||
|
||||
void TestSuitePlayerData::cleanup(){
|
||||
void TestSuitePlayerData::cleanup()
|
||||
{
|
||||
if (manapool) delete manapool;
|
||||
manapool = NULL;
|
||||
manapool = NEW ManaCost();
|
||||
for (int i = 0; i < 5; i++){
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
zones[i].cleanup();
|
||||
}
|
||||
life=20;
|
||||
life = 20;
|
||||
}
|
||||
|
||||
void TestSuiteState::cleanup(){
|
||||
for (int i = 0; i < 2; i++){
|
||||
void TestSuiteState::cleanup()
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
playerData[i].cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void TestSuite::cleanup(){
|
||||
void TestSuite::cleanup()
|
||||
{
|
||||
currentAction = 0;
|
||||
initState.cleanup();
|
||||
endState.cleanup();
|
||||
@@ -492,7 +607,8 @@ void TestSuite::cleanup(){
|
||||
loadRandValues("");
|
||||
}
|
||||
|
||||
int TestSuite::load(const char * _filename){
|
||||
int TestSuite::load(const char * _filename)
|
||||
{
|
||||
summoningSickness = 0;
|
||||
forceAbility = false;
|
||||
gameType = GAME_TYPE_CLASSIC;
|
||||
@@ -505,110 +621,142 @@ int TestSuite::load(const char * _filename){
|
||||
int state = -1;
|
||||
|
||||
// std::cout << std::endl << std::endl << "!!!" << file << std::endl << std::endl;
|
||||
if(file){
|
||||
if (file)
|
||||
{
|
||||
cleanup();
|
||||
while(std::getline(file,s)){
|
||||
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[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
|
||||
if (s[0] == '#') continue;
|
||||
std::transform( s.begin(), s.end(), s.begin(),::tolower );
|
||||
if (s.compare("summoningsickness") == 0) {
|
||||
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
||||
if (s.compare("summoningsickness") == 0)
|
||||
{
|
||||
summoningSickness = 1;
|
||||
continue;
|
||||
}
|
||||
if (s.compare("forceability") == 0) {
|
||||
if (s.compare("forceability") == 0)
|
||||
{
|
||||
forceAbility = true;
|
||||
continue;
|
||||
}
|
||||
if (s.find("seed ") == 0) {
|
||||
if (s.find("seed ") == 0)
|
||||
{
|
||||
seed = atoi(s.substr(5).c_str());
|
||||
continue;
|
||||
}
|
||||
if (s.find("rvalues:") == 0) {
|
||||
if (s.find("rvalues:") == 0)
|
||||
{
|
||||
loadRandValues(s.substr(8).c_str());
|
||||
continue;
|
||||
}
|
||||
if (s.find("aicalls ") == 0) {
|
||||
if (s.find("aicalls ") == 0)
|
||||
{
|
||||
aiMaxCalls = atoi(s.substr(8).c_str());
|
||||
continue;
|
||||
}
|
||||
if (s.compare("momir") == 0) {
|
||||
if (s.compare("momir") == 0)
|
||||
{
|
||||
gameType = GAME_TYPE_MOMIR;
|
||||
continue;
|
||||
}
|
||||
switch(state){
|
||||
switch (state)
|
||||
{
|
||||
case -1:
|
||||
if (s.compare("[init]") == 0) state++;
|
||||
break;
|
||||
case 0:
|
||||
if (s.compare("[player1]") == 0){
|
||||
if (s.compare("[player1]") == 0)
|
||||
{
|
||||
state++;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
initState.phase = PhaseRing::phaseStrToInt(s);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (s.compare("[player2]") == 0){
|
||||
if (s.compare("[player2]") == 0)
|
||||
{
|
||||
state++;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
initState.parsePlayerState(0, s);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (s.compare("[do]") == 0){
|
||||
if (s.compare("[do]") == 0)
|
||||
{
|
||||
state++;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
initState.parsePlayerState(1, s);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (s.compare("[assert]") == 0){
|
||||
if (s.compare("[assert]") == 0)
|
||||
{
|
||||
state++;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
actions.add(s);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (s.compare("[player1]") == 0){
|
||||
if (s.compare("[player1]") == 0)
|
||||
{
|
||||
state++;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
endState.phase = PhaseRing::phaseStrToInt(s);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (s.compare("[player2]") == 0){
|
||||
if (s.compare("[player2]") == 0)
|
||||
{
|
||||
state++;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
endState.parsePlayerState(0, s);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (s.compare("[end]") == 0){
|
||||
if (s.compare("[end]") == 0)
|
||||
{
|
||||
state++;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
endState.parsePlayerState(1, s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void TestSuite::pregameTests(){
|
||||
void TestSuite::pregameTests()
|
||||
{
|
||||
//Test Booster Generation
|
||||
srand(1024);
|
||||
char result[1024];
|
||||
ShopBooster sb;
|
||||
for(int i=0;i<5;i++){
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
nbTests++;
|
||||
sprintf(result, "<h3>pregame/BoosterTest#%i</h3>", i);
|
||||
Log(result);
|
||||
if(!sb.unitTest())
|
||||
nbFailed++;
|
||||
if (!sb.unitTest()) nbFailed++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
#include "utils.h"
|
||||
#include "WFont.h"
|
||||
|
||||
enum {
|
||||
HORIZONTAL_SCROLLER = 0,
|
||||
VERTICAL_SCROLLER = 1
|
||||
enum
|
||||
{
|
||||
HORIZONTAL_SCROLLER = 0, VERTICAL_SCROLLER = 1
|
||||
};
|
||||
|
||||
|
||||
TextScroller::TextScroller(int fontId, float x, float y, float width, float speed, int scrollerType, size_t numItems ): JGuiObject(0), fontId(fontId){
|
||||
TextScroller::TextScroller(int fontId, float x, float y, float width, float speed, int scrollerType, size_t numItems) :
|
||||
JGuiObject(0), fontId(fontId)
|
||||
{
|
||||
mWidth = width;
|
||||
mSpeed = speed;
|
||||
minimumItems = numItems;
|
||||
@@ -24,38 +25,46 @@ TextScroller::TextScroller(int fontId, float x, float y, float width, float spee
|
||||
scrollDirection = scrollerType;
|
||||
}
|
||||
|
||||
void TextScroller::setRandom(int mode){
|
||||
void TextScroller::setRandom(int mode)
|
||||
{
|
||||
mRandom = mode;
|
||||
if (mRandom && strings.size()){
|
||||
if (mRandom && strings.size())
|
||||
{
|
||||
currentId = (rand() % strings.size());
|
||||
mText = strings[currentId];
|
||||
}
|
||||
}
|
||||
|
||||
void TextScroller::Add(string text){
|
||||
void TextScroller::Add(string text)
|
||||
{
|
||||
if (!strings.size()) mText = text;
|
||||
strings.push_back(text);
|
||||
}
|
||||
|
||||
void TextScroller::Reset(){
|
||||
void TextScroller::Reset()
|
||||
{
|
||||
strings.clear();
|
||||
currentId = 0;
|
||||
}
|
||||
|
||||
void TextScroller::Update(float dt){
|
||||
if(!strings.size())
|
||||
return;
|
||||
if ( scrollDirection == HORIZONTAL_SCROLLER )
|
||||
void TextScroller::Update(float dt)
|
||||
{
|
||||
if (!strings.size()) return;
|
||||
if (scrollDirection == HORIZONTAL_SCROLLER)
|
||||
{
|
||||
start+=mSpeed*dt;
|
||||
start += mSpeed * dt;
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
if (start > mFont->GetStringWidth(mText.c_str())){
|
||||
if (start > mFont->GetStringWidth(mText.c_str()))
|
||||
{
|
||||
start = -mWidth;
|
||||
if (mRandom){
|
||||
if (mRandom)
|
||||
{
|
||||
currentId = (rand() % strings.size());
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
currentId++;
|
||||
if (currentId >= strings.size())currentId = 0;
|
||||
if (currentId >= strings.size()) currentId = 0;
|
||||
}
|
||||
mText = strings[currentId];
|
||||
}
|
||||
@@ -64,41 +73,35 @@ void TextScroller::Update(float dt){
|
||||
{
|
||||
// we want to display 2 at a time
|
||||
ostringstream scrollerText;
|
||||
if ( timer == 0 )
|
||||
if (timer == 0)
|
||||
{
|
||||
size_t nbItemsToDisplay = ( minimumItems < strings.size() ? minimumItems : strings.size());
|
||||
for ( size_t idx = 0; idx < nbItemsToDisplay; ++idx)
|
||||
size_t nbItemsToDisplay = (minimumItems < strings.size() ? minimumItems : strings.size());
|
||||
for (size_t idx = 0; idx < nbItemsToDisplay; ++idx)
|
||||
{
|
||||
size_t index = (currentId + idx) % strings.size();
|
||||
scrollerText << strings[index];
|
||||
}
|
||||
currentId++;
|
||||
if ( currentId >= strings.size())
|
||||
currentId = 0;
|
||||
mText = wordWrap( scrollerText.str(), (int) mWidth );
|
||||
if (currentId >= strings.size()) currentId = 0;
|
||||
mText = wordWrap(scrollerText.str(), (int) mWidth);
|
||||
}
|
||||
timer = ++timer % ((int) mSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
void TextScroller::Render(){
|
||||
void TextScroller::Render()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
if ( scrollDirection == HORIZONTAL_SCROLLER )
|
||||
mFont->DrawString(mText.c_str(),mX,mY,JGETEXT_LEFT,start,mWidth);
|
||||
if (scrollDirection == HORIZONTAL_SCROLLER)
|
||||
mFont->DrawString(mText.c_str(), mX, mY, JGETEXT_LEFT, start, mWidth);
|
||||
else
|
||||
mFont->DrawString(mText.c_str(), mX, mY );
|
||||
mFont->DrawString(mText.c_str(), mX, mY);
|
||||
}
|
||||
|
||||
ostream& TextScroller::toString(ostream& out) const
|
||||
{
|
||||
return out << "TextScroller ::: mText : " << mText
|
||||
<< " ; tempText : " << tempText
|
||||
<< " ; mWidth : " << mWidth
|
||||
<< " ; mSpeed : " << mSpeed
|
||||
<< " ; mX,mY : " << mX << "," << mY
|
||||
<< " ; start : " << start
|
||||
<< " ; timer : " << timer
|
||||
<< " ; strings : ?" // << strings
|
||||
<< " ; currentId : " << currentId
|
||||
<< " ; mRandom : " << mRandom;
|
||||
return out << "TextScroller ::: mText : " << mText << " ; tempText : " << tempText << " ; mWidth : " << mWidth
|
||||
<< " ; mSpeed : " << mSpeed << " ; mX,mY : " << mX << "," << mY << " ; start : " << start << " ; timer : "
|
||||
<< timer << " ; strings : ?" // << strings
|
||||
<< " ; currentId : " << currentId << " ; mRandom : " << mRandom;
|
||||
}
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
#include "MTGCardInstance.h"
|
||||
#include "CardDescriptor.h"
|
||||
|
||||
|
||||
ThisDescriptor::~ThisDescriptor(){
|
||||
ThisDescriptor::~ThisDescriptor()
|
||||
{
|
||||
//nothing to do for now
|
||||
}
|
||||
|
||||
//Returns the amount by which a value passes the comparison.
|
||||
int ThisDescriptor::matchValue(int value){
|
||||
switch (comparisonMode){
|
||||
int ThisDescriptor::matchValue(int value)
|
||||
{
|
||||
switch (comparisonMode)
|
||||
{
|
||||
case COMPARISON_AT_MOST:
|
||||
return (comparisonCriterion - value + 1);
|
||||
case COMPARISON_AT_LEAST:
|
||||
@@ -29,20 +31,23 @@ int ThisDescriptor::matchValue(int value){
|
||||
return 0;
|
||||
}
|
||||
|
||||
ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s)
|
||||
{
|
||||
size_t found;
|
||||
|
||||
string whitespaces (" \t\f\v\n\r");
|
||||
string whitespaces(" \t\f\v\n\r");
|
||||
|
||||
found=s.find_last_not_of(whitespaces);
|
||||
if (found!=string::npos)
|
||||
s.erase(found+1);
|
||||
else return NULL;
|
||||
found = s.find_last_not_of(whitespaces);
|
||||
if (found != string::npos)
|
||||
s.erase(found + 1);
|
||||
else
|
||||
return NULL;
|
||||
|
||||
found=s.find_first_not_of(whitespaces);
|
||||
if (found!=string::npos)
|
||||
s.erase(0,found);
|
||||
else return NULL;
|
||||
found = s.find_first_not_of(whitespaces);
|
||||
if (found != string::npos)
|
||||
s.erase(0, found);
|
||||
else
|
||||
return NULL;
|
||||
|
||||
//set comparison mode
|
||||
//equal, greater, and less must remain above the others, otherwise the others may never be used.
|
||||
@@ -51,37 +56,43 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
int opLength = 0;
|
||||
|
||||
found = s.find("=");
|
||||
if (found != string::npos){
|
||||
if (found != string::npos)
|
||||
{
|
||||
mode = COMPARISON_EQUAL;
|
||||
found2 = found + 1;
|
||||
opLength = 1;
|
||||
}
|
||||
found = s.find(">");
|
||||
if (found != string::npos){
|
||||
if (found != string::npos)
|
||||
{
|
||||
mode = COMPARISON_GREATER;
|
||||
found2 = found + 1;
|
||||
opLength = 1;
|
||||
}
|
||||
found = s.find("<");
|
||||
if (found != string::npos){
|
||||
if (found != string::npos)
|
||||
{
|
||||
mode = COMPARISON_LESS;
|
||||
found2 = found + 1;
|
||||
opLength = 1;
|
||||
}
|
||||
found = s.find("<=");
|
||||
if (found != string::npos){
|
||||
if (found != string::npos)
|
||||
{
|
||||
mode = COMPARISON_AT_MOST;
|
||||
found2 = found + 2;
|
||||
opLength = 2;
|
||||
}
|
||||
found = s.find(">=");
|
||||
if (found != string::npos){
|
||||
if (found != string::npos)
|
||||
{
|
||||
mode = COMPARISON_AT_LEAST;
|
||||
found2 = found + 2;
|
||||
opLength = 2;
|
||||
}
|
||||
found = s.find("!=");
|
||||
if (found != string::npos){
|
||||
if (found != string::npos)
|
||||
{
|
||||
mode = COMPARISON_UNEQUAL;
|
||||
found2 = found + 2;
|
||||
opLength = 2;
|
||||
@@ -91,7 +102,8 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
//get comparison criterion
|
||||
int criterionFound = 0;
|
||||
int criterion = 1;
|
||||
if ((found2 != string::npos) && (found2 < s.length())){
|
||||
if ((found2 != string::npos) && (found2 < s.length()))
|
||||
{
|
||||
criterion = atoi(s.substr(found2).c_str());
|
||||
criterionFound = 1;
|
||||
}
|
||||
@@ -99,16 +111,19 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//counters
|
||||
found = s.find("counter{");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
size_t start = s.find("{");
|
||||
size_t end = s.find("}");
|
||||
string counterString = s.substr(start+1,end-start-1);
|
||||
string counterString = s.substr(start + 1, end - start - 1);
|
||||
AbilityFactory abf;
|
||||
Counter * counter = abf.parseCounter(counterString,NULL);
|
||||
if (counter) {
|
||||
Counter * counter = abf.parseCounter(counterString, NULL);
|
||||
if (counter)
|
||||
{
|
||||
if (criterionFound) counter->nb = criterion;
|
||||
ThisCounter * td = NEW ThisCounter(counter);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -118,9 +133,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//any counter
|
||||
found = s.find("counters");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisCounterAny * td = NEW ThisCounterAny(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -129,9 +146,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//equips
|
||||
found = s.find("gear");//still same meaning, better wording to word conflict with MTGAbility equip.
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisEquip * td = NEW ThisEquip(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -140,9 +159,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//whenever this creature attacks do effect
|
||||
found = s.find("attacking");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisAttacked * td = NEW ThisAttacked(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -151,9 +172,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//whenever this creature attacks do effect
|
||||
found = s.find("notblocked");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisNotBlocked * td = NEW ThisNotBlocked(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -162,9 +185,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//controller life
|
||||
found = s.find("opponentlife");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisOpponentlife * td = NEW ThisOpponentlife(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -173,9 +198,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//controller life
|
||||
found = s.find("controllerlife");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisControllerlife * td = NEW ThisControllerlife(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -184,9 +211,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//power
|
||||
found = s.find("power");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisPower * td = NEW ThisPower(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -195,9 +224,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
//toughness
|
||||
found = s.find("toughness");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisToughness * td = NEW ThisToughness(criterion);
|
||||
if (td) {
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -206,9 +237,11 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
|
||||
// X
|
||||
found = s.find("x");
|
||||
if (found != string::npos) {
|
||||
if (found != string::npos)
|
||||
{
|
||||
ThisX * td = NEW ThisX(criterion);
|
||||
if (td){
|
||||
if (td)
|
||||
{
|
||||
td->comparisonMode = mode;
|
||||
return td;
|
||||
}
|
||||
@@ -218,117 +251,148 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ThisCounter::ThisCounter(Counter * _counter){
|
||||
ThisCounter::ThisCounter(Counter * _counter)
|
||||
{
|
||||
counter = _counter;
|
||||
comparisonCriterion = counter->nb;
|
||||
}
|
||||
|
||||
ThisCounter::ThisCounter(int power, int toughness, int nb, const char * name){
|
||||
counter = NEW Counter(NULL,name,power,toughness);
|
||||
ThisCounter::ThisCounter(int power, int toughness, int nb, const char * name)
|
||||
{
|
||||
counter = NEW Counter(NULL, name, power, toughness);
|
||||
comparisonCriterion = nb;
|
||||
}
|
||||
|
||||
int ThisCounter::match(MTGCardInstance * card){
|
||||
Counter * targetCounter = card->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness);
|
||||
if (targetCounter){
|
||||
int ThisCounter::match(MTGCardInstance * card)
|
||||
{
|
||||
Counter * targetCounter = card->counters->hasCounter(counter->name.c_str(), counter->power, counter->toughness);
|
||||
if (targetCounter)
|
||||
{
|
||||
return matchValue(targetCounter->nb);
|
||||
}else{
|
||||
switch (comparisonMode) {
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (comparisonMode)
|
||||
{
|
||||
case COMPARISON_LESS:
|
||||
return comparisonCriterion;
|
||||
case COMPARISON_AT_MOST:
|
||||
return comparisonCriterion + 1;
|
||||
case COMPARISON_UNEQUAL:
|
||||
if (comparisonCriterion) return 1;
|
||||
else return 0;
|
||||
if (comparisonCriterion)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
case COMPARISON_EQUAL:
|
||||
if (comparisonCriterion) return 0;
|
||||
else return 1;
|
||||
default :
|
||||
if (comparisonCriterion)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ThisCounter::~ThisCounter() {
|
||||
ThisCounter::~ThisCounter()
|
||||
{
|
||||
SAFE_DELETE(counter);
|
||||
}
|
||||
|
||||
ThisOpponentlife::ThisOpponentlife(int olife){
|
||||
ThisOpponentlife::ThisOpponentlife(int olife)
|
||||
{
|
||||
comparisonCriterion = olife;
|
||||
}
|
||||
|
||||
int ThisOpponentlife::match(MTGCardInstance * card){
|
||||
int ThisOpponentlife::match(MTGCardInstance * card)
|
||||
{
|
||||
return matchValue(card->controller()->opponent()->life);
|
||||
}
|
||||
|
||||
ThisControllerlife::ThisControllerlife(int life){
|
||||
ThisControllerlife::ThisControllerlife(int life)
|
||||
{
|
||||
comparisonCriterion = life;
|
||||
}
|
||||
|
||||
int ThisControllerlife::match(MTGCardInstance * card){
|
||||
int ThisControllerlife::match(MTGCardInstance * card)
|
||||
{
|
||||
return matchValue(card->controller()->life);
|
||||
}
|
||||
|
||||
ThisPower::ThisPower(int power){
|
||||
ThisPower::ThisPower(int power)
|
||||
{
|
||||
comparisonCriterion = power;
|
||||
}
|
||||
|
||||
int ThisPower::match(MTGCardInstance * card){
|
||||
int ThisPower::match(MTGCardInstance * card)
|
||||
{
|
||||
return matchValue(card->power);
|
||||
}
|
||||
|
||||
ThisEquip::ThisEquip(int equipment){
|
||||
ThisEquip::ThisEquip(int equipment)
|
||||
{
|
||||
comparisonCriterion = equipment;
|
||||
}
|
||||
int ThisEquip::match(MTGCardInstance * card){
|
||||
int ThisEquip::match(MTGCardInstance * card)
|
||||
{
|
||||
return matchValue(card->equipment);
|
||||
}
|
||||
|
||||
ThisAttacked::ThisAttacked(int attack){
|
||||
ThisAttacked::ThisAttacked(int attack)
|
||||
{
|
||||
|
||||
comparisonCriterion = attack;
|
||||
}
|
||||
|
||||
int ThisAttacked::match(MTGCardInstance * card){
|
||||
int ThisAttacked::match(MTGCardInstance * card)
|
||||
{
|
||||
|
||||
return matchValue(card->didattacked);
|
||||
}
|
||||
|
||||
ThisNotBlocked::ThisNotBlocked(int unblocked){
|
||||
ThisNotBlocked::ThisNotBlocked(int unblocked)
|
||||
{
|
||||
|
||||
comparisonCriterion = unblocked;
|
||||
}
|
||||
|
||||
int ThisNotBlocked::match(MTGCardInstance * card){
|
||||
int ThisNotBlocked::match(MTGCardInstance * card)
|
||||
{
|
||||
|
||||
return matchValue(card->notblocked);
|
||||
}
|
||||
|
||||
ThisToughness::ThisToughness(int toughness){
|
||||
ThisToughness::ThisToughness(int toughness)
|
||||
{
|
||||
comparisonCriterion = toughness;
|
||||
}
|
||||
|
||||
int ThisToughness::match(MTGCardInstance * card){
|
||||
int ThisToughness::match(MTGCardInstance * card)
|
||||
{
|
||||
return matchValue(card->toughness);
|
||||
}
|
||||
|
||||
ThisCounterAny::ThisCounterAny(int nb){
|
||||
ThisCounterAny::ThisCounterAny(int nb)
|
||||
{
|
||||
comparisonCriterion = nb;
|
||||
}
|
||||
|
||||
int ThisCounterAny::match(MTGCardInstance * card){
|
||||
int ThisCounterAny::match(MTGCardInstance * card)
|
||||
{
|
||||
int result = 0;
|
||||
for (int i = 0; i < card->counters->mCount; i++) {
|
||||
for (int i = 0; i < card->counters->mCount; i++)
|
||||
{
|
||||
result += card->counters->counters[i]->nb;
|
||||
}
|
||||
return matchValue(result);
|
||||
}
|
||||
|
||||
ThisX::ThisX(int x){
|
||||
ThisX::ThisX(int x)
|
||||
{
|
||||
comparisonCriterion = x;
|
||||
}
|
||||
|
||||
int ThisX::match(MTGCardInstance * card){
|
||||
int ThisX::match(MTGCardInstance * card)
|
||||
{
|
||||
return matchValue(card->X);
|
||||
}
|
||||
@@ -2,22 +2,24 @@
|
||||
|
||||
#include "Token.h"
|
||||
|
||||
Token::Token(string _name, MTGCardInstance * source, int _power, int _toughness):MTGCardInstance(){
|
||||
Token::Token(string _name, MTGCardInstance * source, int _power, int _toughness) :
|
||||
MTGCardInstance()
|
||||
{
|
||||
isToken = true;
|
||||
tokenSource = source;
|
||||
power = _power;
|
||||
toughness = _toughness;
|
||||
life=toughness;
|
||||
life = toughness;
|
||||
lifeOrig = life;
|
||||
rarity = Constants::RARITY_T;
|
||||
name = _name;
|
||||
if (name.size() && name[0]>=97 && name[0]<=122) name[0]-=32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
|
||||
setMTGId(- source->getMTGId());
|
||||
if (name.size() && name[0] >= 97 && name[0] <= 122) name[0] -= 32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
|
||||
setMTGId(-source->getMTGId());
|
||||
setId = source->setId;
|
||||
model = this;
|
||||
data=this;
|
||||
data = this;
|
||||
owner = source->owner;
|
||||
belongs_to=source->controller()->game;
|
||||
belongs_to = source->controller()->game;
|
||||
attacker = 0;
|
||||
defenser = NULL;
|
||||
banding = NULL;
|
||||
|
||||
@@ -5,26 +5,31 @@
|
||||
|
||||
Translator * Translator::mInstance = NULL;
|
||||
|
||||
Translator * Translator::GetInstance(){
|
||||
Translator * Translator::GetInstance()
|
||||
{
|
||||
if (!mInstance) mInstance = NEW Translator();
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
void Translator::EndInstance(){
|
||||
void Translator::EndInstance()
|
||||
{
|
||||
SAFE_DELETE(mInstance);
|
||||
}
|
||||
|
||||
int Translator::Add(string from, string to){
|
||||
int Translator::Add(string from, string to)
|
||||
{
|
||||
values[from] = to;
|
||||
return 1;
|
||||
}
|
||||
|
||||
string Translator::translate(string value){
|
||||
string Translator::translate(string value)
|
||||
{
|
||||
//if (!initDone) init();
|
||||
map<string,string>::iterator it = values.find(value);
|
||||
map<string, string>::iterator it = values.find(value);
|
||||
if (it != values.end()) return it->second;
|
||||
#if defined DEBUG_TRANSLATE
|
||||
if (checkMisses){
|
||||
if (checkMisses)
|
||||
{
|
||||
map<string,int>::iterator it2 = dontCareValues.find(value);
|
||||
if (it2 == dontCareValues.end())
|
||||
missingValues[value] = 1;
|
||||
@@ -33,15 +38,17 @@ string Translator::translate(string value){
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Translator::~Translator(){
|
||||
Translator::~Translator()
|
||||
{
|
||||
#if defined DEBUG_TRANSLATE
|
||||
if (!checkMisses) return;
|
||||
std::ofstream file(JGE_GET_RES("lang/missing.txt").c_str());
|
||||
char writer[4096];
|
||||
if (file){
|
||||
if (file)
|
||||
{
|
||||
map<string,int>::iterator it;
|
||||
for (it = missingValues.begin(); it!=missingValues.end(); it++){
|
||||
for (it = missingValues.begin(); it!=missingValues.end(); it++)
|
||||
{
|
||||
sprintf(writer,"%s=\n", it->first.c_str());
|
||||
file<<writer;
|
||||
}
|
||||
@@ -49,28 +56,32 @@ Translator::~Translator(){
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Translator::Translator(){
|
||||
Translator::Translator()
|
||||
{
|
||||
initDone = false;
|
||||
neofont = false;
|
||||
//init();
|
||||
}
|
||||
|
||||
void Translator::load(string filename, map<string,string> * dictionary) {
|
||||
void Translator::load(string filename, map<string, string> * dictionary)
|
||||
{
|
||||
std::ifstream file(filename.c_str());
|
||||
|
||||
if(file){
|
||||
if (file)
|
||||
{
|
||||
string s;
|
||||
initDone = true;
|
||||
#if defined DEBUG_TRANSLATE
|
||||
checkMisses = 1;
|
||||
#endif
|
||||
while(std::getline(file,s)){
|
||||
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[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
|
||||
size_t found = s.find('=');
|
||||
if (found == string::npos) continue;
|
||||
string s1 = s.substr(0,found);
|
||||
string s2 = s.substr(found+1);
|
||||
string s1 = s.substr(0, found);
|
||||
string s2 = s.substr(found + 1);
|
||||
(*dictionary)[s1] = s2;
|
||||
}
|
||||
file.close();
|
||||
@@ -80,9 +91,11 @@ void Translator::load(string filename, map<string,string> * dictionary) {
|
||||
if (!checkMisses) return;
|
||||
std::ifstream file2(JGE_GET_RES("lang/dontcare.txt").c_str());
|
||||
|
||||
if(file2){
|
||||
if(file2)
|
||||
{
|
||||
string s;
|
||||
while(std::getline(file2,s)){
|
||||
while(std::getline(file2,s))
|
||||
{
|
||||
if (!s.size()) continue;
|
||||
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
|
||||
size_t found = s.find('=');
|
||||
@@ -95,42 +108,47 @@ void Translator::load(string filename, map<string,string> * dictionary) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Translator::initCards(){
|
||||
void Translator::initCards()
|
||||
{
|
||||
string lang = options[Options::LANG].str;
|
||||
if (!lang.size()) return;
|
||||
string cards_dict = JGE_GET_RES("lang/") + lang + "_cards.txt";
|
||||
load(cards_dict,&tempValues);
|
||||
load(cards_dict, &tempValues);
|
||||
}
|
||||
|
||||
void Translator::initDecks(){
|
||||
void Translator::initDecks()
|
||||
{
|
||||
string lang = options[Options::LANG].str;
|
||||
if (!lang.size()) return;
|
||||
string decks_dict = JGE_GET_RES("lang/") + lang + "_decks.txt";
|
||||
|
||||
// Load file
|
||||
std::ifstream file(decks_dict.c_str());
|
||||
if(file){
|
||||
if (file)
|
||||
{
|
||||
string s;
|
||||
initDone = true;
|
||||
while(std::getline(file,s)){
|
||||
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[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
|
||||
// Translate '@' to '\n'
|
||||
// Note: general language files don't include any line-break infomation
|
||||
char * sp = (char *)s.c_str();
|
||||
char * sp = (char *) s.c_str();
|
||||
for (int i = 0; sp[i]; i++)
|
||||
if (sp[i] == '@') sp[i] = '\n';
|
||||
size_t found = s.find('=');
|
||||
if (found == string::npos) continue;
|
||||
string s1 = s.substr(0,found);
|
||||
string s2 = s.substr(found+1);
|
||||
string s1 = s.substr(0, found);
|
||||
string s2 = s.substr(found + 1);
|
||||
deckValues[s1] = s2;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void Translator::init() {
|
||||
void Translator::init()
|
||||
{
|
||||
#if defined DEBUG_TRANSLATE
|
||||
checkMisses = 0;
|
||||
#endif
|
||||
@@ -138,7 +156,8 @@ void Translator::init() {
|
||||
if (!lang.size()) return;
|
||||
string name = JGE_GET_RES("lang/") + lang + ".txt";
|
||||
|
||||
if (fileExists(name.c_str())){
|
||||
if (fileExists(name.c_str()))
|
||||
{
|
||||
// fixup for multibyte support.
|
||||
std::transform(lang.begin(), lang.end(), lang.begin(), ::tolower);
|
||||
if (lang.compare("cn") == 0 || lang.compare("jp") == 0)
|
||||
@@ -146,14 +165,15 @@ void Translator::init() {
|
||||
else
|
||||
neofont = false;
|
||||
initDone = true;
|
||||
load(name,&values);
|
||||
load(name, &values);
|
||||
}
|
||||
|
||||
initCards();
|
||||
initDecks();
|
||||
}
|
||||
|
||||
string _(string toTranslate){
|
||||
string _(string toTranslate)
|
||||
{
|
||||
Translator * t = Translator::GetInstance();
|
||||
return t->translate(toTranslate);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ static map<const LocalKeySym, KeyRep> fattable;
|
||||
static map<const JButton, KeyRep> slimtable;
|
||||
|
||||
#ifdef LINUX
|
||||
const KeyRep& translateKey(LocalKeySym key) {
|
||||
const KeyRep& translateKey(LocalKeySym key)
|
||||
{
|
||||
{
|
||||
map<const LocalKeySym, KeyRep>::iterator res;
|
||||
if ((res = fattable.find(key)) != fattable.end())
|
||||
@@ -34,8 +35,8 @@ const KeyRep& translateKey(LocalKeySym key) {
|
||||
#else
|
||||
#ifdef WIN32
|
||||
|
||||
|
||||
const KeyRep& translateKey(LocalKeySym key) {
|
||||
const KeyRep& translateKey(LocalKeySym key)
|
||||
{
|
||||
{
|
||||
map<const LocalKeySym, KeyRep>::iterator res;
|
||||
if ((res = fattable.find(key)) != fattable.end())
|
||||
@@ -57,7 +58,6 @@ const KeyRep& translateKey(LocalKeySym key) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char buf[256];
|
||||
memset(buf, 0, 256);
|
||||
|
||||
@@ -67,7 +67,8 @@ const KeyRep& translateKey(LocalKeySym key) {
|
||||
s = buf;
|
||||
|
||||
KeyRep k;
|
||||
if (0 == s.length()) {
|
||||
if (0 == s.length())
|
||||
{
|
||||
char*str = NEW char[11];
|
||||
sprintf(str, "%d", key);
|
||||
k = make_pair(str, static_cast<JQuad*>(NULL));
|
||||
@@ -79,8 +80,8 @@ const KeyRep& translateKey(LocalKeySym key) {
|
||||
}
|
||||
#else // PSP
|
||||
|
||||
|
||||
const KeyRep& translateKey(LocalKeySym key) {
|
||||
const KeyRep& translateKey(LocalKeySym key)
|
||||
{
|
||||
map<const LocalKeySym, KeyRep>::iterator res;
|
||||
if ((res = fattable.find(key)) == fattable.end())
|
||||
{
|
||||
@@ -104,12 +105,12 @@ const KeyRep& translateKey(LocalKeySym key) {
|
||||
{
|
||||
char* str = NEW char[11];
|
||||
sprintf(str, "%d", (int) key);
|
||||
fattable[key] = make_pair(str, static_cast<JQuad*>(static_cast<JQuad*>(NULL)));
|
||||
fattable[key] = make_pair(str, static_cast<JQuad*> (static_cast<JQuad*> (NULL)));
|
||||
}
|
||||
res = fattable.find(key);
|
||||
}
|
||||
KeyRep& k = res->second;
|
||||
switch(key)
|
||||
switch (key)
|
||||
{
|
||||
case PSP_CTRL_SELECT : k.second = resources.RetrieveQuad("iconspsp.png", (float)2*32, 32, 64, 32, "PSP_CTRL_SELECT", RETRIEVE_NORMAL); break;
|
||||
case PSP_CTRL_START : k.second = resources.RetrieveQuad("iconspsp.png", (float)0*32, 32, 64, 32, "PSP_CTRL_START", RETRIEVE_NORMAL); break;
|
||||
@@ -183,12 +184,12 @@ const KeyRep& translateKey(JButton key) {
|
||||
{
|
||||
char* str = NEW char[11];
|
||||
sprintf(str, "%d", key);
|
||||
slimtable[key] = make_pair(str, static_cast<JQuad*>(static_cast<JQuad*>(NULL)));
|
||||
slimtable[key] = make_pair(str, static_cast<JQuad*> (static_cast<JQuad*> (NULL)));
|
||||
}
|
||||
res = slimtable.find(key);
|
||||
}
|
||||
KeyRep& k = res->second;
|
||||
switch(key)
|
||||
switch (key)
|
||||
{
|
||||
case JGE_BTN_CTRL : k.second = resources.RetrieveQuad("iconspsp.png", (float)2*32, 32, 64, 32, "PSP_CTRL_SELECT", RETRIEVE_NORMAL); break;
|
||||
case JGE_BTN_MENU : k.second = resources.RetrieveQuad("iconspsp.png", (float)0*32, 32, 64, 32, "PSP_CTRL_START", RETRIEVE_NORMAL); break;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "DamagerDamaged.h"
|
||||
#include "Trash.h"
|
||||
|
||||
template <class T>
|
||||
template<class T>
|
||||
void TrashBin<T>::put_out()
|
||||
{
|
||||
for (typename std::vector<T*>::iterator it = bin.begin(); it != bin.end(); ++it)
|
||||
|
||||
@@ -10,38 +10,44 @@
|
||||
#endif
|
||||
|
||||
//WResource
|
||||
WResource::~WResource(){
|
||||
WResource::~WResource()
|
||||
{
|
||||
}
|
||||
WResource::WResource(){
|
||||
|
||||
WResource::WResource()
|
||||
{
|
||||
locks = WRES_UNLOCKED;
|
||||
lastTime = resources.nowTime();
|
||||
loadedMode = 0;
|
||||
}
|
||||
|
||||
bool WResource::isLocked(){
|
||||
bool WResource::isLocked()
|
||||
{
|
||||
return (locks != WRES_UNLOCKED);
|
||||
}
|
||||
|
||||
bool WResource::isPermanent(){
|
||||
bool WResource::isPermanent()
|
||||
{
|
||||
return (locks == WRES_PERMANENT);
|
||||
}
|
||||
|
||||
void WResource::deadbolt(){
|
||||
if(locks <= WRES_MAX_LOCK)
|
||||
locks = WRES_PERMANENT;
|
||||
void WResource::deadbolt()
|
||||
{
|
||||
if (locks <= WRES_MAX_LOCK) locks = WRES_PERMANENT;
|
||||
}
|
||||
|
||||
void WResource::lock(){
|
||||
if(locks < WRES_MAX_LOCK)
|
||||
locks++;
|
||||
void WResource::lock()
|
||||
{
|
||||
if (locks < WRES_MAX_LOCK) locks++;
|
||||
}
|
||||
|
||||
void WResource::unlock(bool force){
|
||||
if(force)
|
||||
void WResource::unlock(bool force)
|
||||
{
|
||||
if (force)
|
||||
locks = 0;
|
||||
else if(locks > WRES_UNLOCKED){
|
||||
if(locks <= WRES_MAX_LOCK)
|
||||
locks--;
|
||||
else if (locks > WRES_UNLOCKED)
|
||||
{
|
||||
if (locks <= WRES_MAX_LOCK) locks--;
|
||||
}
|
||||
else
|
||||
#ifdef DEBUG_CACHE
|
||||
@@ -52,7 +58,8 @@ void WResource::unlock(bool force){
|
||||
|
||||
}
|
||||
|
||||
void WResource::hit(){
|
||||
void WResource::hit()
|
||||
{
|
||||
lastTime = resources.nowTime();
|
||||
}
|
||||
|
||||
@@ -62,56 +69,63 @@ WCachedResource::~WCachedResource()
|
||||
}
|
||||
|
||||
//WCachedTexture
|
||||
WCachedTexture::WCachedTexture(){
|
||||
WCachedTexture::WCachedTexture()
|
||||
{
|
||||
texture = NULL;
|
||||
}
|
||||
|
||||
WCachedTexture::~WCachedTexture(){
|
||||
if(texture)
|
||||
WCachedTexture::~WCachedTexture()
|
||||
{
|
||||
if (texture)
|
||||
SAFE_DELETE(texture);
|
||||
|
||||
if(!trackedQuads.size())
|
||||
return;
|
||||
if (!trackedQuads.size()) return;
|
||||
|
||||
vector<WTrackedQuad*>::iterator it;
|
||||
WTrackedQuad * tq = NULL;
|
||||
|
||||
for(it=trackedQuads.begin();it!=trackedQuads.end();it++){
|
||||
for (it = trackedQuads.begin(); it != trackedQuads.end(); it++)
|
||||
{
|
||||
tq = (*it);
|
||||
SAFE_DELETE(tq);
|
||||
}
|
||||
trackedQuads.clear();
|
||||
}
|
||||
|
||||
JTexture * WCachedTexture::Actual(){
|
||||
JTexture * WCachedTexture::Actual()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
bool WCachedTexture::isLocked(){
|
||||
if(locks != WRES_UNLOCKED)
|
||||
return true;
|
||||
|
||||
for(vector<WTrackedQuad*>::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){
|
||||
if((*it)->isLocked())
|
||||
return true;
|
||||
bool WCachedTexture::isLocked()
|
||||
{
|
||||
if (locks != WRES_UNLOCKED) return true;
|
||||
|
||||
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it++)
|
||||
{
|
||||
if ((*it)->isLocked()) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WCachedTexture::ReleaseQuad(JQuad* quad){
|
||||
if(quad == NULL)
|
||||
return false;
|
||||
bool WCachedTexture::ReleaseQuad(JQuad* quad)
|
||||
{
|
||||
if (quad == NULL) return false;
|
||||
|
||||
WTrackedQuad * tq = NULL;
|
||||
vector<WTrackedQuad*>::iterator nit;
|
||||
for(vector<WTrackedQuad*>::iterator it = trackedQuads.begin();it!=trackedQuads.end();it=nit){
|
||||
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it = nit)
|
||||
{
|
||||
nit = it;
|
||||
nit++;
|
||||
if((*it) && (*it)->quad == quad ){
|
||||
if ((*it) && (*it)->quad == quad)
|
||||
{
|
||||
tq = (*it);
|
||||
tq->unlock();
|
||||
|
||||
if(!tq->isLocked()){
|
||||
if (!tq->isLocked())
|
||||
{
|
||||
SAFE_DELETE(tq);
|
||||
trackedQuads.erase(it);
|
||||
}
|
||||
@@ -122,8 +136,9 @@ bool WCachedTexture::ReleaseQuad(JQuad* quad){
|
||||
return false;
|
||||
}
|
||||
|
||||
WTrackedQuad * WCachedTexture::GetTrackedQuad(float offX, float offY, float width, float height,string resname){
|
||||
if(!texture) return NULL;
|
||||
WTrackedQuad * WCachedTexture::GetTrackedQuad(float offX, float offY, float width, float height, string resname)
|
||||
{
|
||||
if (!texture) return NULL;
|
||||
|
||||
bool allocated = false;
|
||||
WTrackedQuad * tq = NULL;
|
||||
@@ -131,38 +146,41 @@ WTrackedQuad * WCachedTexture::GetTrackedQuad(float offX, float offY, float widt
|
||||
|
||||
vector<WTrackedQuad*>::iterator it;
|
||||
|
||||
if(width == 0.0f || width > static_cast<float>(texture->mWidth))
|
||||
width = static_cast<float>(texture->mWidth);
|
||||
if(height == 0.0f || height > static_cast<float>(texture->mHeight))
|
||||
height = static_cast<float>(texture->mHeight);
|
||||
if (width == 0.0f || width > static_cast<float> (texture->mWidth)) width = static_cast<float> (texture->mWidth);
|
||||
if (height == 0.0f || height > static_cast<float> (texture->mHeight)) height = static_cast<float> (texture->mHeight);
|
||||
|
||||
for(it = trackedQuads.begin();it!=trackedQuads.end();it++){
|
||||
if((*it) && (*it)->resname == resname){
|
||||
for (it = trackedQuads.begin(); it != trackedQuads.end(); it++)
|
||||
{
|
||||
if ((*it) && (*it)->resname == resname)
|
||||
{
|
||||
tq = (*it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!tq){
|
||||
if (!tq)
|
||||
{
|
||||
allocated = true;
|
||||
tq = NEW WTrackedQuad(resname);
|
||||
if(!tq) return NULL;
|
||||
if (!tq) return NULL;
|
||||
}
|
||||
|
||||
quad = tq->quad;
|
||||
|
||||
if(!quad){
|
||||
quad = NEW JQuad(texture,offX,offY,width,height);
|
||||
/*
|
||||
There's a risk this erases the texture calling the quad creation.... Erwan 2010/03/13
|
||||
if (!quad)
|
||||
{
|
||||
quad = NEW JQuad(texture, offX, offY, width, height);
|
||||
/*
|
||||
There's a risk this erases the texture calling the quad creation.... Erwan 2010/03/13
|
||||
if(!quad) {
|
||||
//Probably out of memory. Try again.
|
||||
resources.Cleanup();
|
||||
quad = NEW JQuad(texture,offX,offY,width,height);
|
||||
}
|
||||
*/
|
||||
if(!quad){
|
||||
if(allocated && tq)
|
||||
*/
|
||||
if (!quad)
|
||||
{
|
||||
if (allocated && tq)
|
||||
SAFE_DELETE(tq);
|
||||
fprintf(stderr, "WCACHEDRESOURCE:GetTrackedQuad - Quad is null\n");
|
||||
return NULL; //Probably a crash.
|
||||
@@ -174,88 +192,98 @@ There's a risk this erases the texture calling the quad creation.... Erwan 2010/
|
||||
}
|
||||
|
||||
//Update JQ's values to what we called this with.
|
||||
quad->SetTextureRect(offX,offY,width,height);
|
||||
quad->SetTextureRect(offX, offY, width, height);
|
||||
return tq;
|
||||
|
||||
}
|
||||
|
||||
JQuad * WCachedTexture::GetQuad(float offX, float offY, float width, float height,string resname){
|
||||
WTrackedQuad * tq = GetTrackedQuad(offX,offY,width,height,resname);
|
||||
JQuad * WCachedTexture::GetQuad(float offX, float offY, float width, float height, string resname)
|
||||
{
|
||||
WTrackedQuad * tq = GetTrackedQuad(offX, offY, width, height, resname);
|
||||
|
||||
if(tq)
|
||||
return tq->quad;
|
||||
if (tq) return tq->quad;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
JQuad * WCachedTexture::GetQuad(string resname){
|
||||
JQuad * WCachedTexture::GetQuad(string resname)
|
||||
{
|
||||
vector<WTrackedQuad*>::iterator it;
|
||||
|
||||
for(it = trackedQuads.begin();it!=trackedQuads.end();it++){
|
||||
if((*it) && (*it)->resname == resname){
|
||||
for (it = trackedQuads.begin(); it != trackedQuads.end(); it++)
|
||||
{
|
||||
if ((*it) && (*it)->resname == resname)
|
||||
{
|
||||
return (*it)->quad;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
JQuad * WCachedTexture::GetCard(float offX, float offY, float width, float height, string resname){
|
||||
JQuad * jq = GetQuad(offX,offY,width,height,resname);
|
||||
if(jq)
|
||||
jq->SetHotSpot(static_cast<float>(jq->mTex->mWidth / 2), static_cast<float>(jq->mTex->mHeight / 2));
|
||||
JQuad * WCachedTexture::GetCard(float offX, float offY, float width, float height, string resname)
|
||||
{
|
||||
JQuad * jq = GetQuad(offX, offY, width, height, resname);
|
||||
if (jq) jq->SetHotSpot(static_cast<float> (jq->mTex->mWidth / 2), static_cast<float> (jq->mTex->mHeight / 2));
|
||||
|
||||
return jq;
|
||||
}
|
||||
|
||||
unsigned long WCachedTexture::size(){
|
||||
if(!texture) return 0;
|
||||
unsigned long WCachedTexture::size()
|
||||
{
|
||||
if (!texture) return 0;
|
||||
|
||||
unsigned int pixel_size = 4;
|
||||
#if defined WIN32 || defined LINUX
|
||||
#else
|
||||
pixel_size = JRenderer::GetInstance()->PixelSize(texture->mTextureFormat);
|
||||
#endif
|
||||
return texture->mTexHeight*texture->mTexWidth*pixel_size;
|
||||
return texture->mTexHeight * texture->mTexWidth * pixel_size;
|
||||
}
|
||||
|
||||
bool WCachedTexture::isGood(){
|
||||
bool WCachedTexture::isGood()
|
||||
{
|
||||
return (texture != NULL);
|
||||
}
|
||||
|
||||
void WCachedTexture::Refresh(){
|
||||
void WCachedTexture::Refresh()
|
||||
{
|
||||
int error = 0;
|
||||
JTexture* old = texture;
|
||||
texture = NULL;
|
||||
|
||||
if(!Attempt(mFilename,loadedMode, error))
|
||||
if (!Attempt(mFilename, loadedMode, error))
|
||||
SAFE_DELETE(texture);
|
||||
|
||||
if(!texture)
|
||||
if (!texture)
|
||||
texture = old;
|
||||
else
|
||||
SAFE_DELETE(old);
|
||||
|
||||
for(vector<WTrackedQuad*>::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){
|
||||
if((*it) && (*it)->quad)
|
||||
(*it)->quad->mTex = texture;
|
||||
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it++)
|
||||
{
|
||||
if ((*it) && (*it)->quad) (*it)->quad->mTex = texture;
|
||||
}
|
||||
}
|
||||
|
||||
bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
||||
bool WCachedTexture::Attempt(string filename, int submode, int & error)
|
||||
{
|
||||
mFilename = filename;
|
||||
int format = TEXTURE_FORMAT;
|
||||
loadedMode = submode;
|
||||
string realname;
|
||||
|
||||
//Form correct filename.
|
||||
if(submode & TEXTURE_SUB_EXACT)
|
||||
if (submode & TEXTURE_SUB_EXACT)
|
||||
realname = filename;
|
||||
else if(submode & TEXTURE_SUB_CARD){
|
||||
if(submode & TEXTURE_SUB_THUMB){
|
||||
for(string::size_type i= 0;i < filename.size();i++){
|
||||
if(filename[i] == '\\' || filename[i] == '/'){
|
||||
filename.insert(i+1,"thumbnails/");
|
||||
else if (submode & TEXTURE_SUB_CARD)
|
||||
{
|
||||
if (submode & TEXTURE_SUB_THUMB)
|
||||
{
|
||||
for (string::size_type i = 0; i < filename.size(); i++)
|
||||
{
|
||||
if (filename[i] == '\\' || filename[i] == '/')
|
||||
{
|
||||
filename.insert(i + 1, "thumbnails/");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -263,37 +291,38 @@ bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
||||
}
|
||||
realname = resources.cardFile(filename);
|
||||
}
|
||||
else{
|
||||
if(submode & TEXTURE_SUB_THUMB)
|
||||
filename.insert(0,"thumbnails/");
|
||||
else
|
||||
{
|
||||
if (submode & TEXTURE_SUB_THUMB) filename.insert(0, "thumbnails/");
|
||||
|
||||
if(submode & TEXTURE_SUB_AVATAR)
|
||||
if (submode & TEXTURE_SUB_AVATAR)
|
||||
realname = resources.avatarFile(filename);
|
||||
else
|
||||
realname = resources.graphicsFile(filename);
|
||||
}
|
||||
|
||||
//Apply pixel mode
|
||||
if(submode & TEXTURE_SUB_5551)
|
||||
format = GU_PSM_5551;
|
||||
if (submode & TEXTURE_SUB_5551) format = GU_PSM_5551;
|
||||
|
||||
if(!realname.size()){
|
||||
if (!realname.size())
|
||||
{
|
||||
error = CACHE_ERROR_404;
|
||||
return false;
|
||||
}
|
||||
|
||||
texture = JRenderer::GetInstance()->LoadTexture(realname.c_str(),TEX_TYPE_USE_VRAM,format);
|
||||
texture = JRenderer::GetInstance()->LoadTexture(realname.c_str(), TEX_TYPE_USE_VRAM, format);
|
||||
|
||||
//Failure.
|
||||
if(!texture){
|
||||
if (!texture)
|
||||
{
|
||||
error = CACHE_ERROR_BAD;
|
||||
if(!fileExists(realname.c_str()))
|
||||
error = CACHE_ERROR_404;
|
||||
if (!fileExists(realname.c_str())) error = CACHE_ERROR_404;
|
||||
return false;
|
||||
}
|
||||
|
||||
//Failure of a different sort.
|
||||
if(texture->mTexId == INVALID_MTEX){
|
||||
if (texture->mTexId == INVALID_MTEX)
|
||||
{
|
||||
SAFE_DELETE(texture);
|
||||
error = CACHE_ERROR_BAD;
|
||||
return false;
|
||||
@@ -304,43 +333,49 @@ bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
||||
}
|
||||
|
||||
//WCachedSample
|
||||
WCachedSample::WCachedSample(){
|
||||
WCachedSample::WCachedSample()
|
||||
{
|
||||
sample = NULL;
|
||||
}
|
||||
|
||||
WCachedSample::~WCachedSample(){
|
||||
WCachedSample::~WCachedSample()
|
||||
{
|
||||
SAFE_DELETE(sample);
|
||||
}
|
||||
|
||||
JSample * WCachedSample::Actual(){
|
||||
JSample * WCachedSample::Actual()
|
||||
{
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
unsigned long WCachedSample::size(){
|
||||
if(!sample || !sample->mSample)
|
||||
return 0;
|
||||
unsigned long WCachedSample::size()
|
||||
{
|
||||
if (!sample || !sample->mSample) return 0;
|
||||
return sample->fileSize();
|
||||
}
|
||||
|
||||
bool WCachedSample::isGood(){
|
||||
if(!sample || !sample->mSample)
|
||||
return false;
|
||||
bool WCachedSample::isGood()
|
||||
{
|
||||
if (!sample || !sample->mSample) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
void WCachedSample::Refresh(){
|
||||
|
||||
void WCachedSample::Refresh()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool WCachedSample::Attempt(string filename, int submode, int & error){
|
||||
bool WCachedSample::Attempt(string filename, int submode, int & error)
|
||||
{
|
||||
loadedMode = submode;
|
||||
|
||||
sample = JSoundSystem::GetInstance()->LoadSample(resources.sfxFile(filename).c_str());
|
||||
|
||||
if(!isGood()){
|
||||
if (!isGood())
|
||||
{
|
||||
SAFE_DELETE(sample);
|
||||
if(!fileExists(filename.c_str()))
|
||||
if (!fileExists(filename.c_str()))
|
||||
error = CACHE_ERROR_404;
|
||||
else
|
||||
error = CACHE_ERROR_BAD;
|
||||
@@ -353,28 +388,31 @@ bool WCachedSample::Attempt(string filename, int submode, int & error){
|
||||
|
||||
//WCachedParticles
|
||||
|
||||
bool WCachedParticles::isGood(){
|
||||
if(!particles)
|
||||
return false;
|
||||
bool WCachedParticles::isGood()
|
||||
{
|
||||
if (!particles) return false;
|
||||
return true;
|
||||
}
|
||||
unsigned long WCachedParticles::size(){
|
||||
if(!particles)
|
||||
return 0; //Sizeof(pointer)
|
||||
|
||||
unsigned long WCachedParticles::size()
|
||||
{
|
||||
if (!particles) return 0; //Sizeof(pointer)
|
||||
|
||||
return sizeof(hgeParticleSystemInfo);
|
||||
}
|
||||
|
||||
//Only effects future particle systems, of course.
|
||||
void WCachedParticles::Refresh(){
|
||||
void WCachedParticles::Refresh()
|
||||
{
|
||||
hgeParticleSystemInfo * old = particles;
|
||||
|
||||
int error = 0;
|
||||
Attempt(mFilename,loadedMode,error);
|
||||
Attempt(mFilename, loadedMode, error);
|
||||
|
||||
if(isGood())
|
||||
if (isGood())
|
||||
SAFE_DELETE(old);
|
||||
else{
|
||||
else
|
||||
{
|
||||
SAFE_DELETE(particles);
|
||||
particles = old;
|
||||
}
|
||||
@@ -382,11 +420,13 @@ void WCachedParticles::Refresh(){
|
||||
return;
|
||||
}
|
||||
|
||||
bool WCachedParticles::Attempt(string filename, int submode, int & error){
|
||||
bool WCachedParticles::Attempt(string filename, int submode, int & error)
|
||||
{
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
|
||||
if(!fileSys->OpenFile(resources.graphicsFile(filename))){
|
||||
if (!fileSys->OpenFile(resources.graphicsFile(filename)))
|
||||
{
|
||||
error = CACHE_ERROR_404;
|
||||
return false;
|
||||
}
|
||||
@@ -403,32 +443,44 @@ bool WCachedParticles::Attempt(string filename, int submode, int & error){
|
||||
fileSys->ReadFile(&(particles->nEmission), sizeof(hgeParticleSystemInfo));
|
||||
fileSys->CloseFile();
|
||||
|
||||
particles->sprite=NULL;
|
||||
particles->sprite = NULL;
|
||||
error = CACHE_ERROR_NONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
hgeParticleSystemInfo * WCachedParticles::Actual(){
|
||||
hgeParticleSystemInfo * WCachedParticles::Actual()
|
||||
{
|
||||
return particles;
|
||||
}
|
||||
|
||||
WCachedParticles::WCachedParticles(){
|
||||
WCachedParticles::WCachedParticles()
|
||||
{
|
||||
particles = NULL;
|
||||
}
|
||||
WCachedParticles::~WCachedParticles(){
|
||||
WCachedParticles::~WCachedParticles()
|
||||
{
|
||||
SAFE_DELETE(particles);
|
||||
}
|
||||
|
||||
//WTrackedQuad
|
||||
unsigned long WTrackedQuad::size() {
|
||||
unsigned long WTrackedQuad::size()
|
||||
{
|
||||
return sizeof(JQuad);
|
||||
}
|
||||
bool WTrackedQuad::isGood(){
|
||||
|
||||
bool WTrackedQuad::isGood()
|
||||
{
|
||||
return (quad != NULL);
|
||||
}
|
||||
WTrackedQuad::WTrackedQuad(string _resname) {
|
||||
quad = NULL; resname = _resname;
|
||||
|
||||
WTrackedQuad::WTrackedQuad(string _resname)
|
||||
{
|
||||
quad = NULL;
|
||||
resname = _resname;
|
||||
}
|
||||
WTrackedQuad::~WTrackedQuad() {
|
||||
if(quad) SAFE_DELETE(quad);
|
||||
|
||||
WTrackedQuad::~WTrackedQuad()
|
||||
{
|
||||
if (quad)
|
||||
SAFE_DELETE(quad);
|
||||
}
|
||||
|
||||
+361
-246
@@ -7,66 +7,83 @@
|
||||
#include "Subtypes.h"
|
||||
|
||||
//WSyncable
|
||||
bool WSyncable::Hook(WSyncable* s){
|
||||
if(hooked)
|
||||
return false;
|
||||
bool WSyncable::Hook(WSyncable* s)
|
||||
{
|
||||
if (hooked) return false;
|
||||
hooked = s;
|
||||
return true;
|
||||
}
|
||||
int WSyncable::getPos(){
|
||||
if(hooked)
|
||||
return hooked->getPos()+currentPos;
|
||||
|
||||
int WSyncable::getPos()
|
||||
{
|
||||
if (hooked) return hooked->getPos() + currentPos;
|
||||
return currentPos;
|
||||
}
|
||||
bool WSyncable::next(){
|
||||
if(hooked)
|
||||
return hooked->next();
|
||||
|
||||
bool WSyncable::next()
|
||||
{
|
||||
if (hooked) return hooked->next();
|
||||
++currentPos;
|
||||
return true;
|
||||
}
|
||||
bool WSyncable::prev(){
|
||||
if(hooked)
|
||||
return hooked->prev();
|
||||
|
||||
bool WSyncable::prev()
|
||||
{
|
||||
if (hooked) return hooked->prev();
|
||||
--currentPos;
|
||||
return true;
|
||||
}
|
||||
|
||||
//WSrcImage
|
||||
JQuad * WSrcImage::getImage( int offset){
|
||||
JQuad * WSrcImage::getImage(int offset)
|
||||
{
|
||||
return resources.RetrieveTempQuad(filename);
|
||||
}
|
||||
|
||||
WSrcImage::WSrcImage(string s){
|
||||
WSrcImage::WSrcImage(string s)
|
||||
{
|
||||
filename = s;
|
||||
}
|
||||
|
||||
//WSrcCards
|
||||
WSrcCards::WSrcCards(float delay){
|
||||
WSrcCards::WSrcCards(float delay)
|
||||
{
|
||||
mDelay = delay;
|
||||
mLastInput = 0;
|
||||
currentPos = 0;
|
||||
filtersRoot=NULL;
|
||||
filtersRoot = NULL;
|
||||
}
|
||||
JQuad * WSrcCards::getImage( int offset){
|
||||
|
||||
JQuad * WSrcCards::getImage(int offset)
|
||||
{
|
||||
#if defined WIN32 || defined LINUX //Loading delay only on PSP.
|
||||
#else
|
||||
if(mDelay && mLastInput < mDelay){
|
||||
return resources.RetrieveCard(getCard(offset),RETRIEVE_EXISTING);
|
||||
if (mDelay && mLastInput < mDelay)
|
||||
{
|
||||
return resources.RetrieveCard(getCard(offset), RETRIEVE_EXISTING);
|
||||
}
|
||||
#endif
|
||||
return resources.RetrieveCard(getCard(offset));
|
||||
}
|
||||
JQuad * WSrcCards::getThumb( int offset){
|
||||
return resources.RetrieveCard(getCard(offset),RETRIEVE_THUMB);
|
||||
|
||||
JQuad * WSrcCards::getThumb(int offset)
|
||||
{
|
||||
return resources.RetrieveCard(getCard(offset), RETRIEVE_THUMB);
|
||||
}
|
||||
WSrcCards::~WSrcCards(){
|
||||
|
||||
WSrcCards::~WSrcCards()
|
||||
{
|
||||
clearFilters();
|
||||
cards.clear();
|
||||
}
|
||||
void WSrcCards::bakeFilters(){
|
||||
|
||||
void WSrcCards::bakeFilters()
|
||||
{
|
||||
vector<MTGCard*> temp;
|
||||
|
||||
setOffset(0);
|
||||
for(int t=0;t<Size();t++){
|
||||
for (int t = 0; t < Size(); t++)
|
||||
{
|
||||
temp.push_back(getCard(t));
|
||||
}
|
||||
setOffset(0);
|
||||
@@ -76,48 +93,52 @@ void WSrcCards::bakeFilters(){
|
||||
return;
|
||||
}
|
||||
|
||||
bool WSrcCards::matchesFilters(MTGCard * c){
|
||||
if(!c) return false;
|
||||
if(!filtersRoot) return true;
|
||||
bool WSrcCards::matchesFilters(MTGCard * c)
|
||||
{
|
||||
if (!c) return false;
|
||||
if (!filtersRoot) return true;
|
||||
return filtersRoot->isMatch(c);
|
||||
}
|
||||
int WSrcCards::Size(bool all){
|
||||
if(!all && filtersRoot)
|
||||
return (int) validated.size();
|
||||
|
||||
int WSrcCards::Size(bool all)
|
||||
{
|
||||
if (!all && filtersRoot) return (int) validated.size();
|
||||
return (int) cards.size();
|
||||
}
|
||||
MTGCard * WSrcCards::getCard(int offset, bool ignore){
|
||||
|
||||
MTGCard * WSrcCards::getCard(int offset, bool ignore)
|
||||
{
|
||||
int oldpos;
|
||||
int size = (int) cards.size();
|
||||
MTGCard * c = NULL;
|
||||
if(!ignore && filtersRoot)
|
||||
size = (int) validated.size();
|
||||
if (!ignore && filtersRoot) size = (int) validated.size();
|
||||
|
||||
if(!size)
|
||||
return NULL;
|
||||
if (!size) return NULL;
|
||||
|
||||
oldpos = currentPos;
|
||||
if(offset != 0)
|
||||
currentPos += offset;
|
||||
while(currentPos < 0)
|
||||
currentPos = size+currentPos;
|
||||
if (offset != 0) currentPos += offset;
|
||||
while (currentPos < 0)
|
||||
currentPos = size + currentPos;
|
||||
currentPos = currentPos % size;
|
||||
|
||||
if(!ignore && filtersRoot)
|
||||
if (!ignore && filtersRoot)
|
||||
c = cards[validated[currentPos]];
|
||||
else
|
||||
c = cards[currentPos];
|
||||
currentPos = oldpos;
|
||||
return c;
|
||||
}
|
||||
int WSrcCards::loadMatches(MTGAllCards* ac){
|
||||
|
||||
int WSrcCards::loadMatches(MTGAllCards* ac)
|
||||
{
|
||||
map<int, MTGCard *>::iterator it;
|
||||
int count = 0;
|
||||
if(!ac)
|
||||
return count;
|
||||
if (!ac) return count;
|
||||
|
||||
for(it=ac->collection.begin();it!=ac->collection.end();it++){
|
||||
if(it->second && (matchesFilters(it->second))){
|
||||
for (it = ac->collection.begin(); it != ac->collection.end(); it++)
|
||||
{
|
||||
if (it->second && (matchesFilters(it->second)))
|
||||
{
|
||||
cards.push_back(it->second);
|
||||
count++;
|
||||
}
|
||||
@@ -125,14 +146,17 @@ int WSrcCards::loadMatches(MTGAllCards* ac){
|
||||
validate();
|
||||
return count;
|
||||
}
|
||||
int WSrcCards::loadMatches(MTGDeck * deck){
|
||||
|
||||
int WSrcCards::loadMatches(MTGDeck * deck)
|
||||
{
|
||||
map<int, int>::iterator it;
|
||||
int count = 0;
|
||||
if(!deck)
|
||||
return count;
|
||||
for(it=deck->cards.begin();it!=deck->cards.end();it++){
|
||||
if (!deck) return count;
|
||||
for (it = deck->cards.begin(); it != deck->cards.end(); it++)
|
||||
{
|
||||
MTGCard * c = deck->getCardById(it->first);
|
||||
if(c && (matchesFilters(c))){
|
||||
if (c && (matchesFilters(c)))
|
||||
{
|
||||
cards.push_back(c);
|
||||
count++;
|
||||
}
|
||||
@@ -140,18 +164,21 @@ int WSrcCards::loadMatches(MTGDeck * deck){
|
||||
validate();
|
||||
return count;
|
||||
}
|
||||
int WSrcCards::loadMatches(WSrcCards* src, bool all){
|
||||
|
||||
int WSrcCards::loadMatches(WSrcCards* src, bool all)
|
||||
{
|
||||
int count = 0;
|
||||
if(!src)
|
||||
return count;
|
||||
if (!src) return count;
|
||||
|
||||
MTGCard * c = NULL;
|
||||
size_t t = 0;
|
||||
int oldp = src->getOffset();
|
||||
src->setOffset(0);
|
||||
for(int t=0;t<src->Size(all);t++){
|
||||
c = src->getCard(t,all);
|
||||
if(matchesFilters(c)){
|
||||
for (int t = 0; t < src->Size(all); t++)
|
||||
{
|
||||
c = src->getCard(t, all);
|
||||
if (matchesFilters(c))
|
||||
{
|
||||
cards.push_back(c);
|
||||
count++;
|
||||
}
|
||||
@@ -160,16 +187,20 @@ int WSrcCards::loadMatches(WSrcCards* src, bool all){
|
||||
validate();
|
||||
return count;
|
||||
}
|
||||
int WSrcCards::addRandomCards(MTGDeck * i, int howmany){
|
||||
if(!cards.size() || (filtersRoot && !validated.size()))
|
||||
return howmany;
|
||||
for(int x=0;x<howmany;x++){
|
||||
if(validated.size()){
|
||||
|
||||
int WSrcCards::addRandomCards(MTGDeck * i, int howmany)
|
||||
{
|
||||
if (!cards.size() || (filtersRoot && !validated.size())) return howmany;
|
||||
for (int x = 0; x < howmany; x++)
|
||||
{
|
||||
if (validated.size())
|
||||
{
|
||||
size_t pos = rand() % validated.size();
|
||||
MTGCard * c = cards[validated[pos]];
|
||||
i->add(c);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
size_t pos = rand() % cards.size();
|
||||
i->add(cards[pos]);
|
||||
}
|
||||
@@ -177,36 +208,45 @@ int WSrcCards::addRandomCards(MTGDeck * i, int howmany){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WSrcCards::addToDeck(MTGDeck * i, int num){
|
||||
int WSrcCards::addToDeck(MTGDeck * i, int num)
|
||||
{
|
||||
int oldpos = getOffset();
|
||||
int added = 0;
|
||||
int cycles = 0;
|
||||
|
||||
if(!i){
|
||||
if(num < 0)
|
||||
return 0;
|
||||
if (!i)
|
||||
{
|
||||
if (num < 0) return 0;
|
||||
return num;
|
||||
}
|
||||
|
||||
setOffset(0);
|
||||
if(num < 0){ //Add it all;
|
||||
if (num < 0)
|
||||
{ //Add it all;
|
||||
MTGCard * c;
|
||||
for(;;){
|
||||
for (;;)
|
||||
{
|
||||
c = getCard();
|
||||
if(!c || !next())
|
||||
break;
|
||||
if (!c || !next()) break;
|
||||
i->add(c);
|
||||
}
|
||||
}else while(added < num){
|
||||
}
|
||||
else
|
||||
while (added < num)
|
||||
{
|
||||
MTGCard * c = getCard();
|
||||
if(!next() || !c){
|
||||
if(++cycles == WSrcCards::MAX_CYCLES){ //Abort the search, too many cycles.
|
||||
if (!next() || !c)
|
||||
{
|
||||
if (++cycles == WSrcCards::MAX_CYCLES)
|
||||
{ //Abort the search, too many cycles.
|
||||
setOffset(oldpos);
|
||||
return num - added;
|
||||
}
|
||||
setOffset(0);
|
||||
continue;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
i->add(c);
|
||||
added++;
|
||||
}
|
||||
@@ -214,44 +254,46 @@ int WSrcCards::addToDeck(MTGDeck * i, int num){
|
||||
setOffset(oldpos);
|
||||
return 0;
|
||||
}
|
||||
bool WSrcCards::next(){
|
||||
|
||||
bool WSrcCards::next()
|
||||
{
|
||||
int oldpos = currentPos;
|
||||
bool bMatch = true;
|
||||
int size = (int)cards.size();
|
||||
if(filtersRoot)
|
||||
size = (int)validated.size();
|
||||
if(currentPos+1 >= size)
|
||||
return false;
|
||||
int size = (int) cards.size();
|
||||
if (filtersRoot) size = (int) validated.size();
|
||||
if (currentPos + 1 >= size) return false;
|
||||
currentPos++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WSrcCards::prev(){
|
||||
bool WSrcCards::prev()
|
||||
{
|
||||
int oldpos = currentPos;
|
||||
bool bMatch = true;
|
||||
if(currentPos == 0)
|
||||
return false;
|
||||
if (currentPos == 0) return false;
|
||||
|
||||
currentPos--;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WSrcCards::setOffset(int pos){
|
||||
if(pos < 0 || pos >= (int) cards.size())
|
||||
return false;
|
||||
bool WSrcCards::setOffset(int pos)
|
||||
{
|
||||
if (pos < 0 || pos >= (int) cards.size()) return false;
|
||||
|
||||
currentPos = pos;
|
||||
if(!matchesFilters(cards[currentPos]))
|
||||
return next();
|
||||
if (!matchesFilters(cards[currentPos])) return next();
|
||||
|
||||
return true;
|
||||
}
|
||||
void WSrcCards::Shuffle(){
|
||||
|
||||
void WSrcCards::Shuffle()
|
||||
{
|
||||
vector<MTGCard*> a;
|
||||
MTGCard * temp;
|
||||
vector<MTGCard*>::iterator k;
|
||||
|
||||
while(cards.size()){
|
||||
while (cards.size())
|
||||
{
|
||||
k = cards.begin();
|
||||
k += rand() % cards.size();
|
||||
temp = *k;
|
||||
@@ -259,7 +301,8 @@ void WSrcCards::Shuffle(){
|
||||
a.push_back(temp);
|
||||
}
|
||||
#if defined WIN32 || defined LINUX //PC performs a double shuffle for less streaking.
|
||||
while(a.size()){
|
||||
while(a.size())
|
||||
{
|
||||
k = a.begin();
|
||||
k += rand() % a.size();
|
||||
temp = *k;
|
||||
@@ -271,310 +314,381 @@ void WSrcCards::Shuffle(){
|
||||
#endif
|
||||
validate();
|
||||
}
|
||||
void WSrcCards::validate(){
|
||||
|
||||
void WSrcCards::validate()
|
||||
{
|
||||
validated.clear();
|
||||
updateCounts();
|
||||
if(!filtersRoot) return;
|
||||
for(size_t t=0;t<cards.size();t++){
|
||||
if(matchesFilters(cards[t]))
|
||||
validated.push_back(t);
|
||||
if (!filtersRoot) return;
|
||||
for (size_t t = 0; t < cards.size(); t++)
|
||||
{
|
||||
if (matchesFilters(cards[t])) validated.push_back(t);
|
||||
}
|
||||
}
|
||||
bool WSrcCards::thisCard(int mtgid){
|
||||
for(size_t t=0;t<cards.size();t++){
|
||||
if(cards[t] && cards[t]->getId() == mtgid){
|
||||
|
||||
bool WSrcCards::thisCard(int mtgid)
|
||||
{
|
||||
for (size_t t = 0; t < cards.size(); t++)
|
||||
{
|
||||
if (cards[t] && cards[t]->getId() == mtgid)
|
||||
{
|
||||
currentPos = (int) t;
|
||||
return matchesFilters(cards[currentPos]);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool WSrcCards::isEmptySet(WCardFilter * f){
|
||||
|
||||
bool WSrcCards::isEmptySet(WCardFilter * f)
|
||||
{
|
||||
size_t max = cards.size();
|
||||
if(validated.size()) max = validated.size();
|
||||
if(!f) return (max > 0);
|
||||
for(size_t t=0;t<max;t++){
|
||||
if(validated.size()){
|
||||
if(f->isMatch(cards[validated[t]]))
|
||||
return false;
|
||||
}else if(f->isMatch(cards[t]))
|
||||
return false;
|
||||
if (validated.size()) max = validated.size();
|
||||
if (!f) return (max > 0);
|
||||
for (size_t t = 0; t < max; t++)
|
||||
{
|
||||
if (validated.size())
|
||||
{
|
||||
if (f->isMatch(cards[validated[t]])) return false;
|
||||
}
|
||||
else if (f->isMatch(cards[t])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WSrcCards::addFilter(WCardFilter * f) {
|
||||
if(filtersRoot == NULL)
|
||||
void WSrcCards::addFilter(WCardFilter * f)
|
||||
{
|
||||
if (filtersRoot == NULL)
|
||||
filtersRoot = f;
|
||||
else
|
||||
filtersRoot = NEW WCFilterAND(f,filtersRoot);
|
||||
filtersRoot = NEW WCFilterAND(f, filtersRoot);
|
||||
validate();
|
||||
currentPos = 0;
|
||||
}
|
||||
float WSrcCards::filterFee(){
|
||||
if(filtersRoot)
|
||||
return filtersRoot->filterFee();
|
||||
float WSrcCards::filterFee()
|
||||
{
|
||||
if (filtersRoot) return filtersRoot->filterFee();
|
||||
return 0;
|
||||
};
|
||||
void WSrcCards::clearFilters() {
|
||||
}
|
||||
|
||||
void WSrcCards::clearFilters()
|
||||
{
|
||||
SAFE_DELETE(filtersRoot);
|
||||
validated.clear();
|
||||
}
|
||||
WCardFilter* WSrcCards::unhookFilters(){
|
||||
WCardFilter* WSrcCards::unhookFilters()
|
||||
{
|
||||
WCardFilter* temp = filtersRoot;
|
||||
filtersRoot = NULL;
|
||||
clearFilters();
|
||||
return temp;
|
||||
}
|
||||
void WSrcCards::Sort(int method){
|
||||
switch(method){
|
||||
|
||||
void WSrcCards::Sort(int method)
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case WSrcCards::SORT_COLLECTOR:
|
||||
std::sort(cards.begin(),cards.end(),WCSortCollector());
|
||||
std::sort(cards.begin(), cards.end(), WCSortCollector());
|
||||
break;
|
||||
case WSrcCards::SORT_RARITY:
|
||||
std::sort(cards.begin(),cards.end(),WCSortRarity());
|
||||
std::sort(cards.begin(), cards.end(), WCSortRarity());
|
||||
break;
|
||||
case WSrcCards::SORT_ALPHA:
|
||||
default:
|
||||
std::sort(cards.begin(),cards.end(),WCSortAlpha());
|
||||
std::sort(cards.begin(), cards.end(), WCSortAlpha());
|
||||
break;
|
||||
}
|
||||
validate();
|
||||
}
|
||||
|
||||
//WSrcUnlockedCards
|
||||
WSrcUnlockedCards::WSrcUnlockedCards(float delay): WSrcCards(delay){
|
||||
WSrcUnlockedCards::WSrcUnlockedCards(float delay) :
|
||||
WSrcCards(delay)
|
||||
{
|
||||
MTGAllCards * ac = GameApp::collection;
|
||||
map<int, MTGCard*>::iterator it;
|
||||
|
||||
char * unlocked = NULL;
|
||||
unlocked = (char *)calloc(setlist.size(),sizeof(char));
|
||||
unlocked = (char *) calloc(setlist.size(), sizeof(char));
|
||||
//Figure out which sets are available.
|
||||
for (int i = 0; i < setlist.size(); i++){
|
||||
for (int i = 0; i < setlist.size(); i++)
|
||||
{
|
||||
unlocked[i] = options[Options::optionSet(i)].number;
|
||||
}
|
||||
|
||||
for(it=ac->collection.begin();it!=ac->collection.end();it++){
|
||||
if(it->second && unlocked[it->second->setId])
|
||||
cards.push_back(it->second);
|
||||
for (it = ac->collection.begin(); it != ac->collection.end(); it++)
|
||||
{
|
||||
if (it->second && unlocked[it->second->setId]) cards.push_back(it->second);
|
||||
}
|
||||
if(unlocked){
|
||||
if (unlocked)
|
||||
{
|
||||
free(unlocked);
|
||||
unlocked = NULL;
|
||||
}
|
||||
|
||||
|
||||
if(cards.size()){
|
||||
if (cards.size())
|
||||
{
|
||||
Shuffle();
|
||||
currentPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//WSrcDeck
|
||||
int WSrcDeck::loadMatches(MTGDeck * deck){
|
||||
int WSrcDeck::loadMatches(MTGDeck * deck)
|
||||
{
|
||||
map<int, int>::iterator it;
|
||||
int count = 0;
|
||||
if(!deck)
|
||||
return count;
|
||||
for(it=deck->cards.begin();it!=deck->cards.end();it++){
|
||||
if (!deck) return count;
|
||||
for (it = deck->cards.begin(); it != deck->cards.end(); it++)
|
||||
{
|
||||
MTGCard * c = deck->getCardById(it->first);
|
||||
if(c && matchesFilters(c)){
|
||||
Add(c,it->second);
|
||||
if (c && matchesFilters(c))
|
||||
{
|
||||
Add(c, it->second);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
validate();
|
||||
return count;
|
||||
}
|
||||
void WSrcDeck::updateCounts(){
|
||||
|
||||
void WSrcDeck::updateCounts()
|
||||
{
|
||||
vector<MTGCard*>::iterator it;
|
||||
map<int,int>::iterator ccount;
|
||||
map<int, int>::iterator ccount;
|
||||
clearCounts();
|
||||
for(it=cards.begin();it!=cards.end();it++){
|
||||
for (it = cards.begin(); it != cards.end(); it++)
|
||||
{
|
||||
ccount = copies.find((*it)->getMTGId());
|
||||
if(ccount == copies.end()) continue;
|
||||
addCount((*it),ccount->second);
|
||||
if (ccount == copies.end()) continue;
|
||||
addCount((*it), ccount->second);
|
||||
}
|
||||
}
|
||||
void WSrcDeck::clearCounts(){
|
||||
|
||||
void WSrcDeck::clearCounts()
|
||||
{
|
||||
counts[UNFILTERED_MIN_COPIES] = -1;
|
||||
counts[UNFILTERED_MAX_COPIES] = 0;
|
||||
for(int i=0;i<MAX_COUNTS;i++)
|
||||
for (int i = 0; i < MAX_COUNTS; i++)
|
||||
counts[i] = 0;
|
||||
}
|
||||
void WSrcDeck::addCount(MTGCard * c, int qty){
|
||||
if(!c || !c->data) return;
|
||||
map<int,int>::iterator cp = copies.find(c->getMTGId());
|
||||
|
||||
if(matchesFilters(c)){
|
||||
counts[FILTERED_COPIES]+=qty;
|
||||
if(qty > 0 && cp != copies.end() && (*cp).second == qty ) counts[FILTERED_UNIQUE]++;
|
||||
else if(qty < 0 && (cp == copies.end() || (*cp).second == 0) ) counts[FILTERED_UNIQUE]--;
|
||||
void WSrcDeck::addCount(MTGCard * c, int qty)
|
||||
{
|
||||
if (!c || !c->data) return;
|
||||
map<int, int>::iterator cp = copies.find(c->getMTGId());
|
||||
|
||||
if (matchesFilters(c))
|
||||
{
|
||||
counts[FILTERED_COPIES] += qty;
|
||||
if (qty > 0 && cp != copies.end() && (*cp).second == qty)
|
||||
counts[FILTERED_UNIQUE]++;
|
||||
else if (qty < 0 && (cp == copies.end() || (*cp).second == 0)) counts[FILTERED_UNIQUE]--;
|
||||
}
|
||||
counts[UNFILTERED_COPIES] += qty;
|
||||
if(qty > 0 && cp != copies.end() && (*cp).second == qty ) counts[UNFILTERED_UNIQUE]++;
|
||||
else if(qty < 0 && (cp == copies.end() || (*cp).second == 0) ) counts[UNFILTERED_UNIQUE]--;
|
||||
for(int i=Constants::MTG_COLOR_ARTIFACT;i<=Constants::MTG_COLOR_LAND;i++)
|
||||
if (c->data->hasColor(i)) counts[i]+= qty;
|
||||
if(counts[UNFILTERED_MIN_COPIES] < 0 || qty < counts[UNFILTERED_MIN_COPIES]) counts[UNFILTERED_MIN_COPIES] = qty;
|
||||
if(qty > counts[UNFILTERED_MAX_COPIES]) counts[UNFILTERED_MAX_COPIES] = qty;
|
||||
if (qty > 0 && cp != copies.end() && (*cp).second == qty)
|
||||
counts[UNFILTERED_UNIQUE]++;
|
||||
else if (qty < 0 && (cp == copies.end() || (*cp).second == 0)) counts[UNFILTERED_UNIQUE]--;
|
||||
for (int i = Constants::MTG_COLOR_ARTIFACT; i <= Constants::MTG_COLOR_LAND; i++)
|
||||
if (c->data->hasColor(i)) counts[i] += qty;
|
||||
if (counts[UNFILTERED_MIN_COPIES] < 0 || qty < counts[UNFILTERED_MIN_COPIES]) counts[UNFILTERED_MIN_COPIES] = qty;
|
||||
if (qty > counts[UNFILTERED_MAX_COPIES]) counts[UNFILTERED_MAX_COPIES] = qty;
|
||||
}
|
||||
int WSrcDeck::Add(MTGCard * c, int quantity){
|
||||
if(!c) return 0;
|
||||
if(copies.find(c->getMTGId()) == copies.end()){
|
||||
|
||||
int WSrcDeck::Add(MTGCard * c, int quantity)
|
||||
{
|
||||
if (!c) return 0;
|
||||
if (copies.find(c->getMTGId()) == copies.end())
|
||||
{
|
||||
cards.push_back(c);
|
||||
}
|
||||
copies[c->getMTGId()] += quantity;
|
||||
addCount(c,quantity);
|
||||
addCount(c, quantity);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WSrcDeck::Remove(MTGCard * c, int quantity, bool erase){
|
||||
if(!c) return 0;
|
||||
map<int,int>::iterator it = copies.find(c->getMTGId());
|
||||
if(it == copies.end()) return 0;
|
||||
int WSrcDeck::Remove(MTGCard * c, int quantity, bool erase)
|
||||
{
|
||||
if (!c) return 0;
|
||||
map<int, int>::iterator it = copies.find(c->getMTGId());
|
||||
if (it == copies.end()) return 0;
|
||||
int amt = it->second;
|
||||
if(amt < quantity)
|
||||
return 0;
|
||||
if (amt < quantity) return 0;
|
||||
amt -= quantity;
|
||||
it->second = amt;
|
||||
if(erase && amt == 0){
|
||||
if (erase && amt == 0)
|
||||
{
|
||||
copies.erase(it);
|
||||
vector<MTGCard*>::iterator i = find(cards.begin(),cards.end(),c);
|
||||
if(i != cards.end())
|
||||
cards.erase(i);
|
||||
vector<MTGCard*>::iterator i = find(cards.begin(), cards.end(), c);
|
||||
if (i != cards.end()) cards.erase(i);
|
||||
}
|
||||
addCount(c,-quantity);
|
||||
addCount(c, -quantity);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void WSrcDeck::Rebuild(MTGDeck * d){
|
||||
void WSrcDeck::Rebuild(MTGDeck * d)
|
||||
{
|
||||
d->removeAll();
|
||||
map<int,int>::iterator it;
|
||||
for ( it=copies.begin() ; it != copies.end(); it++ ){
|
||||
for (int i = 0; i < it->second; i++){
|
||||
map<int, int>::iterator it;
|
||||
for (it = copies.begin(); it != copies.end(); it++)
|
||||
{
|
||||
for (int i = 0; i < it->second; i++)
|
||||
{
|
||||
d->add(it->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int WSrcDeck::count(MTGCard * c){
|
||||
if(!c)
|
||||
return counts[UNFILTERED_COPIES];
|
||||
if(copies.find(c->getMTGId()) == copies.end())
|
||||
return 0;
|
||||
int WSrcDeck::count(MTGCard * c)
|
||||
{
|
||||
if (!c) return counts[UNFILTERED_COPIES];
|
||||
if (copies.find(c->getMTGId()) == copies.end()) return 0;
|
||||
return copies[c->getMTGId()];
|
||||
}
|
||||
|
||||
int WSrcDeck::countByName(MTGCard * card, bool editions){
|
||||
int WSrcDeck::countByName(MTGCard * card, bool editions)
|
||||
{
|
||||
string name = card->data->getLCName();
|
||||
int total = 0;
|
||||
vector<MTGCard*>::iterator it;
|
||||
for(it = cards.begin();it!=cards.end();it++){
|
||||
if(*it && (*it)->data->getLCName() == name){
|
||||
if(editions)
|
||||
for (it = cards.begin(); it != cards.end(); it++)
|
||||
{
|
||||
if (*it && (*it)->data->getLCName() == name)
|
||||
{
|
||||
if (editions)
|
||||
total++;
|
||||
else{
|
||||
map<int,int>::iterator mi = copies.find((*it)->getMTGId());
|
||||
if(mi != copies.end())
|
||||
total += mi->second;
|
||||
else
|
||||
{
|
||||
map<int, int>::iterator mi = copies.find((*it)->getMTGId());
|
||||
if (mi != copies.end()) total += mi->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
int WSrcDeck::getCount(int count){
|
||||
if(count < 0 || count >=MAX_COUNTS)
|
||||
return counts[UNFILTERED_COPIES];
|
||||
|
||||
int WSrcDeck::getCount(int count)
|
||||
{
|
||||
if (count < 0 || count >= MAX_COUNTS) return counts[UNFILTERED_COPIES];
|
||||
return counts[count];
|
||||
}
|
||||
int WSrcDeck::totalPrice(){
|
||||
|
||||
int WSrcDeck::totalPrice()
|
||||
{
|
||||
int total = 0;
|
||||
PriceList * pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),GameApp::collection);
|
||||
map<int,int>::iterator it;
|
||||
for ( it=copies.begin() ; it != copies.end(); it++ ){
|
||||
PriceList * pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(), GameApp::collection);
|
||||
map<int, int>::iterator it;
|
||||
for (it = copies.begin(); it != copies.end(); it++)
|
||||
{
|
||||
int nb = it->second;
|
||||
if (nb) total += pricelist->getPrice(it->first);
|
||||
}
|
||||
SAFE_DELETE(pricelist);
|
||||
return total;
|
||||
}
|
||||
|
||||
//WSrcDeckViewer
|
||||
WSrcDeckViewer::WSrcDeckViewer(WSrcCards * _active, WSrcCards * _inactive): WSrcCards(0.2f) {
|
||||
WSrcDeckViewer::WSrcDeckViewer(WSrcCards * _active, WSrcCards * _inactive) :
|
||||
WSrcCards(0.2f)
|
||||
{
|
||||
active = _active;
|
||||
inactive = _inactive;
|
||||
}
|
||||
|
||||
void WSrcDeckViewer::swapSrc(){
|
||||
void WSrcDeckViewer::swapSrc()
|
||||
{
|
||||
WSrcCards * temp = active;
|
||||
active = inactive;
|
||||
inactive = temp;
|
||||
}
|
||||
WSrcDeckViewer::~WSrcDeckViewer(){
|
||||
|
||||
WSrcDeckViewer::~WSrcDeckViewer()
|
||||
{
|
||||
//Do nothing.
|
||||
}
|
||||
|
||||
//Sorting methods:
|
||||
int WCSortRarity::rareToInt(char r){
|
||||
switch(r){
|
||||
default: case Constants::RARITY_T: return 0;
|
||||
case Constants::RARITY_L: return 1;
|
||||
case Constants::RARITY_C: return 2;
|
||||
case Constants::RARITY_U: return 3;
|
||||
case Constants::RARITY_R: return 4;
|
||||
case Constants::RARITY_M: return 5;
|
||||
case Constants::RARITY_S: return 6;
|
||||
int WCSortRarity::rareToInt(char r)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
default:
|
||||
case Constants::RARITY_T:
|
||||
return 0;
|
||||
case Constants::RARITY_L:
|
||||
return 1;
|
||||
case Constants::RARITY_C:
|
||||
return 2;
|
||||
case Constants::RARITY_U:
|
||||
return 3;
|
||||
case Constants::RARITY_R:
|
||||
return 4;
|
||||
case Constants::RARITY_M:
|
||||
return 5;
|
||||
case Constants::RARITY_S:
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
bool WCSortRarity::operator()(const MTGCard*l, const MTGCard*r){
|
||||
if(!l || !r || !l->data || !r->data)
|
||||
return false;
|
||||
|
||||
bool WCSortRarity::operator()(const MTGCard*l, const MTGCard*r)
|
||||
{
|
||||
if (!l || !r || !l->data || !r->data) return false;
|
||||
return (rareToInt(l->getRarity()) < rareToInt(r->getRarity()));
|
||||
}
|
||||
bool WCSortAlpha::operator()(const MTGCard*l, const MTGCard*r){
|
||||
if(!l || !r || !l->data || !r->data)
|
||||
return false;
|
||||
|
||||
bool WCSortAlpha::operator()(const MTGCard*l, const MTGCard*r)
|
||||
{
|
||||
if (!l || !r || !l->data || !r->data) return false;
|
||||
string ln = l->data->getLCName();
|
||||
string rn = r->data->getLCName();
|
||||
if(ln == rn)
|
||||
return l->getMTGId() < r->getMTGId();
|
||||
if (ln == rn) return l->getMTGId() < r->getMTGId();
|
||||
return (ln < rn);
|
||||
}
|
||||
bool WCSortCollector::operator()(const MTGCard*l, const MTGCard*r){
|
||||
if(!l || !r || !l->data || !r->data)
|
||||
return false;
|
||||
|
||||
if(l->setId != r->setId)
|
||||
return (l->setId < r->setId);
|
||||
bool WCSortCollector::operator()(const MTGCard*l, const MTGCard*r)
|
||||
{
|
||||
if (!l || !r || !l->data || !r->data) return false;
|
||||
|
||||
if (l->setId != r->setId) return (l->setId < r->setId);
|
||||
|
||||
int lc, rc;
|
||||
lc = l->data->countColors(); rc = r->data->countColors();
|
||||
if(lc == 0) lc = 999;
|
||||
if(rc == 0) rc = 999;
|
||||
lc = l->data->countColors();
|
||||
rc = r->data->countColors();
|
||||
if (lc == 0) lc = 999;
|
||||
if (rc == 0) rc = 999;
|
||||
|
||||
int isW = (int)l->data->hasColor(Constants::MTG_COLOR_WHITE) - (int) r->data->hasColor(Constants::MTG_COLOR_WHITE);
|
||||
int isU = (int)l->data->hasColor(Constants::MTG_COLOR_BLUE) - (int) r->data->hasColor(Constants::MTG_COLOR_BLUE);
|
||||
int isB = (int)l->data->hasColor(Constants::MTG_COLOR_BLACK) - (int) r->data->hasColor(Constants::MTG_COLOR_BLACK);
|
||||
int isR = (int)l->data->hasColor(Constants::MTG_COLOR_RED) - (int) r->data->hasColor(Constants::MTG_COLOR_RED);
|
||||
int isG = (int)l->data->hasColor(Constants::MTG_COLOR_GREEN) - (int) r->data->hasColor(Constants::MTG_COLOR_GREEN);
|
||||
int isArt = (int)l->data->hasType(Subtypes::TYPE_ARTIFACT) - (int) r->data->hasType(Subtypes::TYPE_ARTIFACT);
|
||||
int isLand = (int)l->data->hasType(Subtypes::TYPE_LAND) - (int) r->data->hasType(Subtypes::TYPE_LAND);
|
||||
int isW = (int) l->data->hasColor(Constants::MTG_COLOR_WHITE) - (int) r->data->hasColor(Constants::MTG_COLOR_WHITE);
|
||||
int isU = (int) l->data->hasColor(Constants::MTG_COLOR_BLUE) - (int) r->data->hasColor(Constants::MTG_COLOR_BLUE);
|
||||
int isB = (int) l->data->hasColor(Constants::MTG_COLOR_BLACK) - (int) r->data->hasColor(Constants::MTG_COLOR_BLACK);
|
||||
int isR = (int) l->data->hasColor(Constants::MTG_COLOR_RED) - (int) r->data->hasColor(Constants::MTG_COLOR_RED);
|
||||
int isG = (int) l->data->hasColor(Constants::MTG_COLOR_GREEN) - (int) r->data->hasColor(Constants::MTG_COLOR_GREEN);
|
||||
int isArt = (int) l->data->hasType(Subtypes::TYPE_ARTIFACT) - (int) r->data->hasType(Subtypes::TYPE_ARTIFACT);
|
||||
int isLand = (int) l->data->hasType(Subtypes::TYPE_LAND) - (int) r->data->hasType(Subtypes::TYPE_LAND);
|
||||
|
||||
//Nested if hell. TODO: Farm these out to their own objects as a user-defined filter/sort system.
|
||||
if(!isLand){
|
||||
int isBasic = (int)l->data->hasType("Basic") - (int) r->data->hasType("Basic");
|
||||
if(!isBasic){
|
||||
if(!isArt){
|
||||
if(lc == rc){
|
||||
if(!isG){
|
||||
if(!isR){
|
||||
if(!isB){
|
||||
if(!isU){
|
||||
if(!isW){
|
||||
if (!isLand)
|
||||
{
|
||||
int isBasic = (int) l->data->hasType("Basic") - (int) r->data->hasType("Basic");
|
||||
if (!isBasic)
|
||||
{
|
||||
if (!isArt)
|
||||
{
|
||||
if (lc == rc)
|
||||
{
|
||||
if (!isG)
|
||||
{
|
||||
if (!isR)
|
||||
{
|
||||
if (!isB)
|
||||
{
|
||||
if (!isU)
|
||||
{
|
||||
if (!isW)
|
||||
{
|
||||
string ln = l->data->getLCName();
|
||||
string rn = r->data->getLCName();
|
||||
if(ln.substr(0,4) == "the ")
|
||||
ln = ln.substr(4);
|
||||
if(rn.substr(0,4) == "the ")
|
||||
rn = rn.substr(4);
|
||||
if (ln.substr(0, 4) == "the ") ln = ln.substr(4);
|
||||
if (rn.substr(0, 4) == "the ") rn = rn.substr(4);
|
||||
return (ln < rn);
|
||||
}
|
||||
return (isW < 0);
|
||||
@@ -591,7 +705,8 @@ bool WCSortCollector::operator()(const MTGCard*l, const MTGCard*r){
|
||||
}
|
||||
return (isArt < 0);
|
||||
}
|
||||
else return(isBasic < 0);
|
||||
else
|
||||
return (isBasic < 0);
|
||||
}
|
||||
return (isLand < 0);
|
||||
}
|
||||
+137
-46
@@ -6,127 +6,218 @@
|
||||
#include "Damage.h"
|
||||
#include "PhaseRing.h"
|
||||
|
||||
WEvent::WEvent(int type) : type(type){}
|
||||
WEvent::WEvent(int type) :
|
||||
type(type)
|
||||
{
|
||||
}
|
||||
|
||||
WEventZoneChange::WEventZoneChange(MTGCardInstance * card, MTGGameZone * from, MTGGameZone *to) : WEvent(CHANGE_ZONE), card(card), from(from), to(to){}
|
||||
WEventZoneChange::WEventZoneChange(MTGCardInstance * card, MTGGameZone * from, MTGGameZone *to) :
|
||||
WEvent(CHANGE_ZONE), card(card), from(from), to(to)
|
||||
{
|
||||
}
|
||||
|
||||
WEventDamage::WEventDamage(Damage *damage) : WEvent(DAMAGE), damage(damage){}
|
||||
WEventDamage::WEventDamage(Damage *damage) :
|
||||
WEvent(DAMAGE), damage(damage)
|
||||
{
|
||||
}
|
||||
|
||||
WEventDamageStackResolved::WEventDamageStackResolved() : WEvent(){}
|
||||
WEventDamageStackResolved::WEventDamageStackResolved() :
|
||||
WEvent()
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardUpdate::WEventCardUpdate(MTGCardInstance * card) : WEvent(), card(card) {};
|
||||
WEventCardUpdate::WEventCardUpdate(MTGCardInstance * card) :
|
||||
WEvent(), card(card)
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
WEventPhaseChange::WEventPhaseChange(Phase * from, Phase * to) : WEvent(CHANGE_PHASE), from(from), to(to){}
|
||||
WEventPhaseChange::WEventPhaseChange(Phase * from, Phase * to) :
|
||||
WEvent(CHANGE_PHASE), from(from), to(to)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardTap::WEventCardTap(MTGCardInstance * card, bool before, bool after) : WEventCardUpdate(card), before(before), after(after){}
|
||||
WEventCardTap::WEventCardTap(MTGCardInstance * card, bool before, bool after) :
|
||||
WEventCardUpdate(card), before(before), after(after)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardTappedForMana::WEventCardTappedForMana(MTGCardInstance * card, bool before, bool after) : WEventCardUpdate(card), before(before), after(after){}
|
||||
WEventCardTappedForMana::WEventCardTappedForMana(MTGCardInstance * card, bool before, bool after) :
|
||||
WEventCardUpdate(card), before(before), after(after)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardAttacked::WEventCardAttacked(MTGCardInstance * card) : WEventCardUpdate(card){}
|
||||
WEventCardAttacked::WEventCardAttacked(MTGCardInstance * card) :
|
||||
WEventCardUpdate(card)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardAttackedAlone::WEventCardAttackedAlone(MTGCardInstance * card) : WEventCardUpdate(card){}
|
||||
WEventCardAttackedAlone::WEventCardAttackedAlone(MTGCardInstance * card) :
|
||||
WEventCardUpdate(card)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardAttackedNotBlocked::WEventCardAttackedNotBlocked(MTGCardInstance * card) : WEventCardUpdate(card){}
|
||||
WEventCardAttackedNotBlocked::WEventCardAttackedNotBlocked(MTGCardInstance * card) :
|
||||
WEventCardUpdate(card)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardAttackedBlocked::WEventCardAttackedBlocked(MTGCardInstance * card) : WEventCardUpdate(card){}
|
||||
WEventCardAttackedBlocked::WEventCardAttackedBlocked(MTGCardInstance * card) :
|
||||
WEventCardUpdate(card)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardBlocked::WEventCardBlocked(MTGCardInstance * card) : WEventCardUpdate(card){}
|
||||
WEventCardBlocked::WEventCardBlocked(MTGCardInstance * card) :
|
||||
WEventCardUpdate(card)
|
||||
{
|
||||
}
|
||||
|
||||
WEventcardDraw::WEventcardDraw(Player * player,int nb_cards) : player(player), nb_cards(nb_cards){}
|
||||
WEventcardDraw::WEventcardDraw(Player * player, int nb_cards) :
|
||||
player(player), nb_cards(nb_cards)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardSacrifice::WEventCardSacrifice(MTGCardInstance * card) : WEventCardUpdate(card){}
|
||||
WEventCardSacrifice::WEventCardSacrifice(MTGCardInstance * card) :
|
||||
WEventCardUpdate(card)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardDiscard::WEventCardDiscard(MTGCardInstance * card) : WEventCardUpdate(card){}
|
||||
WEventCardDiscard::WEventCardDiscard(MTGCardInstance * card) :
|
||||
WEventCardUpdate(card)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCardChangeType::WEventCardChangeType(MTGCardInstance * card, int type, bool before, bool after) : WEventCardUpdate(card), type(type), before(before), after(after){}
|
||||
WEventCardChangeType::WEventCardChangeType(MTGCardInstance * card, int type, bool before, bool after) :
|
||||
WEventCardUpdate(card), type(type), before(before), after(after)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCreatureAttacker::WEventCreatureAttacker(MTGCardInstance * card, Targetable * before, Targetable * after) : WEventCardUpdate(card), before(before), after(after){}
|
||||
WEventCreatureAttacker::WEventCreatureAttacker(MTGCardInstance * card, Targetable * before, Targetable * after) :
|
||||
WEventCardUpdate(card), before(before), after(after)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCreatureBlocker::WEventCreatureBlocker(MTGCardInstance * card, MTGCardInstance * from,MTGCardInstance * to) : WEventCardUpdate(card), before(from), after(to){}
|
||||
WEventCreatureBlocker::WEventCreatureBlocker(MTGCardInstance * card, MTGCardInstance * from, MTGCardInstance * to) :
|
||||
WEventCardUpdate(card), before(from), after(to)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCreatureBlockerRank::WEventCreatureBlockerRank(MTGCardInstance * card, MTGCardInstance * exchangeWith, MTGCardInstance * attacker) : WEventCardUpdate(card), exchangeWith(exchangeWith), attacker(attacker){}
|
||||
WEventCreatureBlockerRank::WEventCreatureBlockerRank(MTGCardInstance * card, MTGCardInstance * exchangeWith,
|
||||
MTGCardInstance * attacker) :
|
||||
WEventCardUpdate(card), exchangeWith(exchangeWith), attacker(attacker)
|
||||
{
|
||||
}
|
||||
|
||||
WEventEngageMana::WEventEngageMana(int color, MTGCardInstance* card, ManaPool * destination) : WEvent(), color(color), card(card), destination(destination) {}
|
||||
WEventConsumeMana::WEventConsumeMana(int color, ManaPool * source) : WEvent(), color(color),source(source) {}
|
||||
WEventEmptyManaPool::WEventEmptyManaPool(ManaPool * source) : WEvent(), source(source){}
|
||||
WEventEngageMana::WEventEngageMana(int color, MTGCardInstance* card, ManaPool * destination) :
|
||||
WEvent(), color(color), card(card), destination(destination)
|
||||
{
|
||||
}
|
||||
WEventConsumeMana::WEventConsumeMana(int color, ManaPool * source) :
|
||||
WEvent(), color(color), source(source)
|
||||
{
|
||||
}
|
||||
WEventEmptyManaPool::WEventEmptyManaPool(ManaPool * source) :
|
||||
WEvent(), source(source)
|
||||
{
|
||||
}
|
||||
|
||||
WEventCombatStepChange::WEventCombatStepChange(CombatStep step) : WEvent(), step(step) {};
|
||||
WEventCombatStepChange::WEventCombatStepChange(CombatStep step) :
|
||||
WEvent(), step(step)
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
Targetable * WEventDamage::getTarget(int target) {
|
||||
switch (target) {
|
||||
case TARGET_TO :
|
||||
Targetable * WEventDamage::getTarget(int target)
|
||||
{
|
||||
switch (target)
|
||||
{
|
||||
case TARGET_TO:
|
||||
return damage->target;
|
||||
case TARGET_FROM :
|
||||
case TARGET_FROM:
|
||||
return damage->source;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int WEventDamage::getValue() {
|
||||
int WEventDamage::getValue()
|
||||
{
|
||||
return damage->damage;
|
||||
}
|
||||
|
||||
Targetable * WEventZoneChange::getTarget(int target) {
|
||||
Targetable * WEventZoneChange::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardAttacked::getTarget(int target) {
|
||||
Targetable * WEventCardAttacked::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardAttackedAlone::getTarget(int target) {
|
||||
Targetable * WEventCardAttackedAlone::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardSacrifice::getTarget(int target) {
|
||||
Targetable * WEventCardSacrifice::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardDiscard::getTarget(int target) {
|
||||
Targetable * WEventCardDiscard::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardAttackedNotBlocked::getTarget(int target) {
|
||||
Targetable * WEventCardAttackedNotBlocked::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardAttackedBlocked::getTarget(int target) {
|
||||
switch (target) {
|
||||
case TARGET_TO :
|
||||
Targetable * WEventCardAttackedBlocked::getTarget(int target)
|
||||
{
|
||||
switch (target)
|
||||
{
|
||||
case TARGET_TO:
|
||||
return card;
|
||||
case TARGET_FROM :
|
||||
case TARGET_FROM:
|
||||
return card->getNextOpponent();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardBlocked::getTarget(int target) {
|
||||
switch (target) {
|
||||
case TARGET_TO :
|
||||
Targetable * WEventCardBlocked::getTarget(int target)
|
||||
{
|
||||
switch (target)
|
||||
{
|
||||
case TARGET_TO:
|
||||
return card;
|
||||
case TARGET_FROM :
|
||||
case TARGET_FROM:
|
||||
return card->getNextOpponent();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardTap::getTarget(int target){
|
||||
Targetable * WEventCardTap::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventCardTappedForMana::getTarget(int target){
|
||||
Targetable * WEventCardTappedForMana::getTarget(int target)
|
||||
{
|
||||
if (target) return card;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Targetable * WEventcardDraw::getTarget(Player * player){
|
||||
Targetable * WEventcardDraw::getTarget(Player * player)
|
||||
{
|
||||
if (player) return player;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+279
-203
@@ -7,108 +7,129 @@
|
||||
//WCFilterFactory
|
||||
WCFilterFactory* WCFilterFactory::me = NULL;
|
||||
|
||||
WCFilterFactory* WCFilterFactory::GetInstance() {
|
||||
if(!me)
|
||||
me = NEW WCFilterFactory();
|
||||
WCFilterFactory* WCFilterFactory::GetInstance()
|
||||
{
|
||||
if (!me) me = NEW WCFilterFactory();
|
||||
return me;
|
||||
}
|
||||
void WCFilterFactory::Destroy(){
|
||||
void WCFilterFactory::Destroy()
|
||||
{
|
||||
SAFE_DELETE(me);
|
||||
}
|
||||
size_t WCFilterFactory::findNext(string src, size_t start,char open, char close){
|
||||
size_t WCFilterFactory::findNext(string src, size_t start, char open, char close)
|
||||
{
|
||||
int num = 0;
|
||||
for(size_t x=start;x<src.size();x++){
|
||||
if(src[x] == open)
|
||||
num++;
|
||||
if(src[x] == close){
|
||||
for (size_t x = start; x < src.size(); x++)
|
||||
{
|
||||
if (src[x] == open) num++;
|
||||
if (src[x] == close)
|
||||
{
|
||||
num--;
|
||||
if(num == 0)
|
||||
return x;
|
||||
if (num == 0) return x;
|
||||
}
|
||||
}
|
||||
return string::npos;
|
||||
}
|
||||
WCardFilter * WCFilterFactory::Construct(string src){
|
||||
WCardFilter * WCFilterFactory::Construct(string src)
|
||||
{
|
||||
size_t x = 0;
|
||||
string whitespaces (" \t\f\v\n\r");
|
||||
string whitespaces(" \t\f\v\n\r");
|
||||
x = src.find_first_not_of(whitespaces);
|
||||
if(x != string::npos) src = src.substr(x);
|
||||
if (x != string::npos) src = src.substr(x);
|
||||
|
||||
if(!src.size())
|
||||
return NEW WCFilterNULL(); //Empty string.
|
||||
if (!src.size()) return NEW WCFilterNULL(); //Empty string.
|
||||
|
||||
|
||||
for(size_t i=0;i<src.size();i++){
|
||||
for (size_t i = 0; i < src.size(); i++)
|
||||
{
|
||||
unsigned char c = src[i];
|
||||
if(isspace(c))
|
||||
continue;
|
||||
if(c == '('){ //Parenthesis
|
||||
size_t endp = findNext(src,i);
|
||||
if(endp != string::npos){
|
||||
WCFilterGROUP * g = NEW WCFilterGROUP(Construct(src.substr(i+1,endp-1)));
|
||||
if(endp < src.size()){
|
||||
if(src[endp+1] == '|')
|
||||
return NEW WCFilterOR(g,Construct(src.substr(endp+2)));
|
||||
else if(src[endp+1] == '&')
|
||||
return NEW WCFilterAND(g,Construct(src.substr(endp+2)));
|
||||
if (isspace(c)) continue;
|
||||
if (c == '(')
|
||||
{ //Parenthesis
|
||||
size_t endp = findNext(src, i);
|
||||
if (endp != string::npos)
|
||||
{
|
||||
WCFilterGROUP * g = NEW WCFilterGROUP(Construct(src.substr(i + 1, endp - 1)));
|
||||
if (endp < src.size())
|
||||
{
|
||||
if (src[endp + 1] == '|')
|
||||
return NEW WCFilterOR(g, Construct(src.substr(endp + 2)));
|
||||
else if (src[endp + 1] == '&')
|
||||
return NEW WCFilterAND(g, Construct(src.substr(endp + 2)));
|
||||
else
|
||||
return g;
|
||||
}
|
||||
}
|
||||
else
|
||||
return NEW WCFilterNULL();
|
||||
}else if(c == '{'){ //Negation
|
||||
size_t endp = findNext(src,i,'{','}');
|
||||
if(endp != string::npos){
|
||||
WCFilterNOT * g = NEW WCFilterNOT(Construct(src.substr(i+1,endp-1)));
|
||||
if(endp < src.size()){
|
||||
if(src[endp+1] == '|')
|
||||
return NEW WCFilterOR(g,Construct(src.substr(endp+2)));
|
||||
else if(src[endp+1] == '&')
|
||||
return NEW WCFilterAND(g,Construct(src.substr(endp+2)));
|
||||
}
|
||||
else if (c == '{')
|
||||
{ //Negation
|
||||
size_t endp = findNext(src, i, '{', '}');
|
||||
if (endp != string::npos)
|
||||
{
|
||||
WCFilterNOT * g = NEW WCFilterNOT(Construct(src.substr(i + 1, endp - 1)));
|
||||
if (endp < src.size())
|
||||
{
|
||||
if (src[endp + 1] == '|')
|
||||
return NEW WCFilterOR(g, Construct(src.substr(endp + 2)));
|
||||
else if (src[endp + 1] == '&')
|
||||
return NEW WCFilterAND(g, Construct(src.substr(endp + 2)));
|
||||
else
|
||||
return g;
|
||||
}
|
||||
}
|
||||
else
|
||||
return NEW WCFilterNULL();
|
||||
}else if(c == '&'){ //And
|
||||
return NEW WCFilterAND(Construct(src.substr(0,i)),Construct(src.substr(i+1)));
|
||||
}
|
||||
else if(c == '|'){ //Or
|
||||
return NEW WCFilterOR(Construct(src.substr(0,i)),Construct(src.substr(i+1)));
|
||||
else if (c == '&')
|
||||
{ //And
|
||||
return NEW WCFilterAND(Construct(src.substr(0, i)), Construct(src.substr(i + 1)));
|
||||
}
|
||||
else if (c == '|')
|
||||
{ //Or
|
||||
return NEW WCFilterOR(Construct(src.substr(0, i)), Construct(src.substr(i + 1)));
|
||||
}
|
||||
}
|
||||
return Leaf(src);
|
||||
}
|
||||
|
||||
WCardFilter * WCFilterFactory::Leaf(string src){
|
||||
WCardFilter * WCFilterFactory::Leaf(string src)
|
||||
{
|
||||
string filter;
|
||||
string whitespaces (" \t\f\v\n\r");
|
||||
string whitespaces(" \t\f\v\n\r");
|
||||
size_t x = src.find_first_not_of(whitespaces);
|
||||
if(x != string::npos) src = src.substr(x);
|
||||
if (x != string::npos) src = src.substr(x);
|
||||
|
||||
for(size_t i=0;i<src.size();i++){
|
||||
for (size_t i = 0; i < src.size(); i++)
|
||||
{
|
||||
unsigned char c = src[i];
|
||||
if(isspace(c))
|
||||
continue;
|
||||
if(c == '('){ //Scan to ')', call Construct.
|
||||
size_t end = src.find(")",i);
|
||||
if(end != string::npos){
|
||||
string expr = src.substr(i+1,i-end);
|
||||
if (isspace(c)) continue;
|
||||
if (c == '(')
|
||||
{ //Scan to ')', call Construct.
|
||||
size_t end = src.find(")", i);
|
||||
if (end != string::npos)
|
||||
{
|
||||
string expr = src.substr(i + 1, i - end);
|
||||
return NEW WCFilterGROUP(Construct(expr));
|
||||
}
|
||||
}else if(c == '{'){ //Scan to '}', call Construct.
|
||||
size_t end = src.find("}",i);
|
||||
if(end != string::npos){
|
||||
string expr = src.substr(i+1,i-end);
|
||||
}
|
||||
else if (c == '{')
|
||||
{ //Scan to '}', call Construct.
|
||||
size_t end = src.find("}", i);
|
||||
if (end != string::npos)
|
||||
{
|
||||
string expr = src.substr(i + 1, i - end);
|
||||
return NEW WCFilterNOT(Construct(expr));
|
||||
}
|
||||
}else if(c == ':'){ //Scan ahead to ';', inbetween this is an argument
|
||||
size_t end = src.find(";",i);
|
||||
if(end != string::npos && filter.size()){
|
||||
string arg = src.substr(i+1,end-i-1);
|
||||
return Terminal(filter,arg);
|
||||
}
|
||||
else if (c == ':')
|
||||
{ //Scan ahead to ';', inbetween this is an argument
|
||||
size_t end = src.find(";", i);
|
||||
if (end != string::npos && filter.size())
|
||||
{
|
||||
string arg = src.substr(i + 1, end - i - 1);
|
||||
return Terminal(filter, arg);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -118,214 +139,257 @@ WCardFilter * WCFilterFactory::Leaf(string src){
|
||||
return NEW WCFilterNULL();
|
||||
}
|
||||
|
||||
WCardFilter * WCFilterFactory::Terminal(string src, string arg){
|
||||
WCardFilter * WCFilterFactory::Terminal(string src, string arg)
|
||||
{
|
||||
string type;
|
||||
for(size_t x=0;x<src.size();x++){
|
||||
if(isspace(src[x])) continue;
|
||||
for (size_t x = 0; x < src.size(); x++)
|
||||
{
|
||||
if (isspace(src[x])) continue;
|
||||
type += src[x];
|
||||
}
|
||||
std::transform(type.begin(),type.end(),type.begin(),::tolower);
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
|
||||
if(type == "r" || type == "rarity")
|
||||
if (type == "r" || type == "rarity")
|
||||
return NEW WCFilterRarity(arg);
|
||||
else if(type == "c" || type == "color")
|
||||
else if (type == "c" || type == "color")
|
||||
return NEW WCFilterColor(arg);
|
||||
else if(type == "xc" || type == "xcolor")
|
||||
else if (type == "xc" || type == "xcolor")
|
||||
return NEW WCFilterOnlyColor(arg);
|
||||
else if(type == "s" || type == "set")
|
||||
else if (type == "s" || type == "set")
|
||||
return NEW WCFilterSet(arg);
|
||||
else if(type == "alpha")
|
||||
else if (type == "alpha")
|
||||
return NEW WCFilterLetter(arg);
|
||||
else if(type == "t" || type == "type")
|
||||
else if (type == "t" || type == "type")
|
||||
return NEW WCFilterType(arg);
|
||||
else if(type == "a" || type == "ability")
|
||||
else if (type == "a" || type == "ability")
|
||||
return NEW WCFilterAbility(arg);
|
||||
else if(type == "cmc")
|
||||
else if (type == "cmc")
|
||||
return NEW WCFilterCMC(arg);
|
||||
else if(type == "produces" || type == "ma")
|
||||
else if (type == "produces" || type == "ma")
|
||||
return NEW WCFilterProducesColor(arg);
|
||||
else if(type == "pow" || type == "power")
|
||||
else if (type == "pow" || type == "power")
|
||||
return NEW WCFilterPower(arg);
|
||||
else if(type == "tgh" || type == "tough" || type == "toughness")
|
||||
return NEW WCFilterToughness(arg);
|
||||
else if (type == "tgh" || type == "tough" || type == "toughness") return NEW WCFilterToughness(arg);
|
||||
|
||||
return NEW WCFilterNULL();
|
||||
}
|
||||
//WCFilterLetter
|
||||
WCFilterLetter::WCFilterLetter(string arg){
|
||||
if(!arg.size())
|
||||
WCFilterLetter::WCFilterLetter(string arg)
|
||||
{
|
||||
if (!arg.size())
|
||||
alpha = 'a';
|
||||
else
|
||||
alpha = tolower(arg[0]);
|
||||
}
|
||||
bool WCFilterLetter::isMatch(MTGCard * c){
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
bool WCFilterLetter::isMatch(MTGCard * c)
|
||||
{
|
||||
if (!c || !c->data) return false;
|
||||
string s = c->data->getLCName();
|
||||
if(!s.size())
|
||||
return false;
|
||||
if(s[0] == alpha || (alpha == '#' && (isdigit(s[0]) || ispunct(s[0]))))
|
||||
return true;
|
||||
if (!s.size()) return false;
|
||||
if (s[0] == alpha || (alpha == '#' && (isdigit(s[0]) || ispunct(s[0])))) return true;
|
||||
return false;
|
||||
}
|
||||
string WCFilterLetter::getCode(){
|
||||
string WCFilterLetter::getCode()
|
||||
{
|
||||
char buf[24];
|
||||
sprintf(buf,"alpha:%c;",alpha);
|
||||
sprintf(buf, "alpha:%c;", alpha);
|
||||
return buf;
|
||||
}
|
||||
//WCFilterSet
|
||||
WCFilterSet::WCFilterSet(string arg){
|
||||
WCFilterSet::WCFilterSet(string arg)
|
||||
{
|
||||
setid = setlist.findSet(arg);
|
||||
}
|
||||
|
||||
string WCFilterSet::getCode(){
|
||||
string WCFilterSet::getCode()
|
||||
{
|
||||
char buf[256];
|
||||
sprintf(buf,"set:%s;",setlist[setid].c_str());
|
||||
sprintf(buf, "set:%s;", setlist[setid].c_str());
|
||||
return buf;
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
//WCFilterColor
|
||||
bool WCFilterColor::isMatch(MTGCard * c){
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
bool WCFilterColor::isMatch(MTGCard * c)
|
||||
{
|
||||
if (!c || !c->data) return false;
|
||||
return (c->data->hasColor(color) > 0);
|
||||
}
|
||||
string WCFilterColor::getCode(){
|
||||
string WCFilterColor::getCode()
|
||||
{
|
||||
char buf[12];
|
||||
char c = '?';
|
||||
if(color < 0 || color >= Constants::MTG_NB_COLORS)
|
||||
c = Constants::MTGColorChars[color];
|
||||
sprintf(buf,"color:%c;",c);
|
||||
if (color < 0 || color >= Constants::MTG_NB_COLORS) c = Constants::MTGColorChars[color];
|
||||
sprintf(buf, "color:%c;", c);
|
||||
return buf;
|
||||
};
|
||||
WCFilterColor::WCFilterColor(string arg){
|
||||
}
|
||||
;
|
||||
WCFilterColor::WCFilterColor(string arg)
|
||||
{
|
||||
color = -1;
|
||||
char c = tolower(arg[0]);
|
||||
for(int i=0;i<Constants::MTG_NB_COLORS;i++){
|
||||
if(Constants::MTGColorChars[i] == c){
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
if (Constants::MTGColorChars[i] == c)
|
||||
{
|
||||
color = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//WCFilterOnlyColor
|
||||
bool WCFilterOnlyColor::isMatch(MTGCard * c){
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
for(int i=0;i<Constants::MTG_NB_COLORS;i++){
|
||||
if(i == color) continue;
|
||||
if(c->data->hasColor(i) > 0)
|
||||
return false;
|
||||
bool WCFilterOnlyColor::isMatch(MTGCard * c)
|
||||
{
|
||||
if (!c || !c->data) return false;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
if (i == color) continue;
|
||||
if (c->data->hasColor(i) > 0) return false;
|
||||
}
|
||||
return (c->data->hasColor(color) > 0);
|
||||
}
|
||||
string WCFilterOnlyColor::getCode(){
|
||||
string WCFilterOnlyColor::getCode()
|
||||
{
|
||||
char buf[12];
|
||||
char c = '?';
|
||||
if(color < 0 || color >= Constants::MTG_NB_COLORS)
|
||||
c = Constants::MTGColorChars[color];
|
||||
sprintf(buf,"xcolor:%c;",c);
|
||||
if (color < 0 || color >= Constants::MTG_NB_COLORS) c = Constants::MTGColorChars[color];
|
||||
sprintf(buf, "xcolor:%c;", c);
|
||||
return buf;
|
||||
}
|
||||
//WCFilterProducesColor
|
||||
bool WCFilterProducesColor::isMatch(MTGCard * c){
|
||||
bool WCFilterProducesColor::isMatch(MTGCard * c)
|
||||
{
|
||||
bool bMatch = false;
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
if (!c || !c->data) return false;
|
||||
string s = c->data->magicText;
|
||||
size_t t = s.find("add");
|
||||
while(t != string::npos){
|
||||
s = s.substr(t+3);
|
||||
while (t != string::npos)
|
||||
{
|
||||
s = s.substr(t + 3);
|
||||
ManaCost * mc = ManaCost::parseManaCost(s);
|
||||
if(mc->hasColor(color) > 0) {bMatch = true; SAFE_DELETE(mc); break;}
|
||||
if (mc->hasColor(color) > 0)
|
||||
{
|
||||
bMatch = true;
|
||||
SAFE_DELETE(mc);
|
||||
break;
|
||||
}
|
||||
SAFE_DELETE(mc);
|
||||
t = s.find("add");
|
||||
}
|
||||
return bMatch;
|
||||
}
|
||||
string WCFilterProducesColor::getCode(){
|
||||
string WCFilterProducesColor::getCode()
|
||||
{
|
||||
char buf[12];
|
||||
char c = '?';
|
||||
if(color < 0 || color >= Constants::MTG_NB_COLORS)
|
||||
c = Constants::MTGColorChars[color];
|
||||
sprintf(buf,"produces:%c;",c);
|
||||
if (color < 0 || color >= Constants::MTG_NB_COLORS) c = Constants::MTGColorChars[color];
|
||||
sprintf(buf, "produces:%c;", c);
|
||||
return buf;
|
||||
}
|
||||
//WCFilterNumeric
|
||||
WCFilterNumeric::WCFilterNumeric(string arg){
|
||||
WCFilterNumeric::WCFilterNumeric(string arg)
|
||||
{
|
||||
number = atoi(arg.c_str());
|
||||
}
|
||||
//WCFilterCMC
|
||||
bool WCFilterCMC::isMatch(MTGCard * c){
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
bool WCFilterCMC::isMatch(MTGCard * c)
|
||||
{
|
||||
if (!c || !c->data) return false;
|
||||
ManaCost * mc = c->data->getManaCost();
|
||||
return (mc->getConvertedCost() == number);
|
||||
}
|
||||
|
||||
string WCFilterCMC::getCode(){
|
||||
string WCFilterCMC::getCode()
|
||||
{
|
||||
char buf[64];
|
||||
sprintf(buf,"cmc:%i;",number);
|
||||
sprintf(buf, "cmc:%i;", number);
|
||||
return buf;
|
||||
}
|
||||
//WCFilterPower
|
||||
bool WCFilterPower::isMatch(MTGCard * c){
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
bool WCFilterPower::isMatch(MTGCard * c)
|
||||
{
|
||||
if (!c || !c->data) return false;
|
||||
return (c->data->getPower() == number);
|
||||
}
|
||||
string WCFilterPower::getCode(){
|
||||
string WCFilterPower::getCode()
|
||||
{
|
||||
char buf[64];
|
||||
sprintf(buf,"power:%i;",number);
|
||||
sprintf(buf, "power:%i;", number);
|
||||
return buf;
|
||||
}
|
||||
//WCFilterPower
|
||||
bool WCFilterToughness::isMatch(MTGCard * c){
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
bool WCFilterToughness::isMatch(MTGCard * c)
|
||||
{
|
||||
if (!c || !c->data) return false;
|
||||
return (c->data->getToughness() == number);
|
||||
}
|
||||
string WCFilterToughness::getCode(){
|
||||
string WCFilterToughness::getCode()
|
||||
{
|
||||
char buf[64];
|
||||
sprintf(buf,"toughness:%i;",number);
|
||||
sprintf(buf, "toughness:%i;", number);
|
||||
return buf;
|
||||
}
|
||||
//WCFilterRarity
|
||||
float WCFilterRarity::filterFee(){
|
||||
switch(rarity){
|
||||
case 'M': return 2.0f;
|
||||
case 'R': return 1.0f;
|
||||
case 'U': return 0.5f;
|
||||
case 'C': return 0.2f;
|
||||
float WCFilterRarity::filterFee()
|
||||
{
|
||||
switch (rarity)
|
||||
{
|
||||
case 'M':
|
||||
return 2.0f;
|
||||
case 'R':
|
||||
return 1.0f;
|
||||
case 'U':
|
||||
return 0.5f;
|
||||
case 'C':
|
||||
return 0.2f;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
bool WCFilterRarity::isMatch(MTGCard * c){
|
||||
if(!c || !c->data)
|
||||
return false;
|
||||
if(rarity == 'A') return true; //A for "Any" or "All"
|
||||
bool WCFilterRarity::isMatch(MTGCard * c)
|
||||
{
|
||||
if (!c || !c->data) return false;
|
||||
if (rarity == 'A') return true; //A for "Any" or "All"
|
||||
return (c->getRarity() == rarity);
|
||||
}
|
||||
string WCFilterRarity::getCode(){
|
||||
string WCFilterRarity::getCode()
|
||||
{
|
||||
char buf[64];
|
||||
const char* rarities[8] = {"any","token","land","common","uncommon","rare","mythic","special"};
|
||||
const char* rarities[8] = { "any", "token", "land", "common", "uncommon", "rare", "mythic", "special" };
|
||||
int x = 0;
|
||||
switch(rarity){
|
||||
case 'S': x=7; break;
|
||||
case 'M': x=6; break;
|
||||
case 'R': x=5; break;
|
||||
case 'U': x=4; break;
|
||||
case 'C': x=3; break;
|
||||
case 'L': x=2; break;
|
||||
case 'T': x=1; break;
|
||||
switch (rarity)
|
||||
{
|
||||
case 'S':
|
||||
x = 7;
|
||||
break;
|
||||
case 'M':
|
||||
x = 6;
|
||||
break;
|
||||
case 'R':
|
||||
x = 5;
|
||||
break;
|
||||
case 'U':
|
||||
x = 4;
|
||||
break;
|
||||
case 'C':
|
||||
x = 3;
|
||||
break;
|
||||
case 'L':
|
||||
x = 2;
|
||||
break;
|
||||
case 'T':
|
||||
x = 1;
|
||||
break;
|
||||
}
|
||||
sprintf(buf,"rarity:%s;",rarities[x]);
|
||||
sprintf(buf, "rarity:%s;", rarities[x]);
|
||||
return buf;
|
||||
};
|
||||
WCFilterRarity::WCFilterRarity(string arg){
|
||||
}
|
||||
;
|
||||
WCFilterRarity::WCFilterRarity(string arg)
|
||||
{
|
||||
rarity = -1;
|
||||
char c = toupper(arg[0]);
|
||||
switch(c){
|
||||
switch (c)
|
||||
{
|
||||
case 'S':
|
||||
case 'M':
|
||||
case 'R':
|
||||
@@ -339,36 +403,42 @@ WCFilterRarity::WCFilterRarity(string arg){
|
||||
rarity = 'A';
|
||||
}
|
||||
//WCFilterAbility
|
||||
bool WCFilterAbility::isMatch(MTGCard * c){
|
||||
if(ability < 0)
|
||||
return false;
|
||||
map<int,int>::iterator it = c->data->basicAbilities.find(ability);
|
||||
bool WCFilterAbility::isMatch(MTGCard * c)
|
||||
{
|
||||
if (ability < 0) return false;
|
||||
map<int, int>::iterator it = c->data->basicAbilities.find(ability);
|
||||
|
||||
if(it != c->data->basicAbilities.end()){
|
||||
if(it->second > 0)
|
||||
return true;
|
||||
if (it != c->data->basicAbilities.end())
|
||||
{
|
||||
if (it->second > 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
WCFilterAbility::WCFilterAbility(string arg){
|
||||
std::transform(arg.begin(),arg.end(),arg.begin(),::tolower);
|
||||
for(int i = 0;i<Constants::NB_BASIC_ABILITIES;i++){
|
||||
if(arg == Constants::MTGBasicAbilities[i]){
|
||||
WCFilterAbility::WCFilterAbility(string arg)
|
||||
{
|
||||
std::transform(arg.begin(), arg.end(), arg.begin(), ::tolower);
|
||||
for (int i = 0; i < Constants::NB_BASIC_ABILITIES; i++)
|
||||
{
|
||||
if (arg == Constants::MTGBasicAbilities[i])
|
||||
{
|
||||
ability = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ability = -1;
|
||||
}
|
||||
string WCFilterAbility::getCode(){
|
||||
string WCFilterAbility::getCode()
|
||||
{
|
||||
char buf[64];
|
||||
if(ability < 0 || ability >= Constants::NB_BASIC_ABILITIES)
|
||||
return "";
|
||||
sprintf(buf,"ability:%s;",Constants::MTGBasicAbilities[ability]);
|
||||
if (ability < 0 || ability >= Constants::NB_BASIC_ABILITIES) return "";
|
||||
sprintf(buf, "ability:%s;", Constants::MTGBasicAbilities[ability]);
|
||||
return buf;
|
||||
};
|
||||
float WCFilterAbility::filterFee(){
|
||||
switch(ability){
|
||||
}
|
||||
;
|
||||
float WCFilterAbility::filterFee()
|
||||
{
|
||||
switch (ability)
|
||||
{
|
||||
case Constants::SHROUD:
|
||||
case Constants::DEATHTOUCH:
|
||||
case Constants::UNBLOCKABLE:
|
||||
@@ -404,50 +474,56 @@ float WCFilterAbility::filterFee(){
|
||||
return 0.0f;
|
||||
}
|
||||
//WCFilterType
|
||||
bool WCFilterType::isMatch(MTGCard * c){
|
||||
bool WCFilterType::isMatch(MTGCard * c)
|
||||
{
|
||||
return c->data->hasType(type.c_str());
|
||||
}
|
||||
string WCFilterType::getCode(){
|
||||
string WCFilterType::getCode()
|
||||
{
|
||||
char buf[4068];
|
||||
sprintf(buf,"type:%s;",type.c_str());
|
||||
sprintf(buf, "type:%s;", type.c_str());
|
||||
return buf;
|
||||
}
|
||||
//Misc. filter code
|
||||
float WCFilterAND::filterFee(){
|
||||
float WCFilterAND::filterFee()
|
||||
{
|
||||
return lhs->filterFee() + rhs->filterFee();
|
||||
}
|
||||
float WCFilterOR::filterFee(){
|
||||
if(lhs->filterFee() > rhs->filterFee())
|
||||
return lhs->filterFee();
|
||||
float WCFilterOR::filterFee()
|
||||
{
|
||||
if (lhs->filterFee() > rhs->filterFee()) return lhs->filterFee();
|
||||
return rhs->filterFee();
|
||||
}
|
||||
string WCFilterNOT::getCode(){
|
||||
string WCFilterNOT::getCode()
|
||||
{
|
||||
char buf[4068];
|
||||
sprintf(buf,"{%s}",kid->getCode().c_str());
|
||||
sprintf(buf, "{%s}", kid->getCode().c_str());
|
||||
return buf;
|
||||
}
|
||||
string WCFilterGROUP::getCode(){
|
||||
string WCFilterGROUP::getCode()
|
||||
{
|
||||
char buf[4068];
|
||||
sprintf(buf,"(%s)",kid->getCode().c_str());
|
||||
sprintf(buf, "(%s)", kid->getCode().c_str());
|
||||
return buf;
|
||||
}
|
||||
|
||||
string WCFilterAND::getCode(){
|
||||
string WCFilterAND::getCode()
|
||||
{
|
||||
char buf[4068];
|
||||
sprintf(buf,"%s&%s",lhs->getCode().c_str(),rhs->getCode().c_str());
|
||||
sprintf(buf, "%s&%s", lhs->getCode().c_str(), rhs->getCode().c_str());
|
||||
return buf;
|
||||
}
|
||||
string WCFilterOR::getCode(){
|
||||
string WCFilterOR::getCode()
|
||||
{
|
||||
char buf[4068];
|
||||
sprintf(buf,"%s|%s",lhs->getCode().c_str(),rhs->getCode().c_str());
|
||||
sprintf(buf, "%s|%s", lhs->getCode().c_str(), rhs->getCode().c_str());
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
bool WCFilterOR::isMatch(MTGCard *c){
|
||||
if(lhs->isMatch(c))
|
||||
return true;
|
||||
if(rhs->isMatch(c))
|
||||
return true;
|
||||
bool WCFilterOR::isMatch(MTGCard *c)
|
||||
{
|
||||
if (lhs->isMatch(c)) return true;
|
||||
if (rhs->isMatch(c)) return true;
|
||||
return false;
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
+303
-213
@@ -34,18 +34,27 @@ static PIXEL_TYPE gencolor(int id, PIXEL_TYPE color)
|
||||
#endif
|
||||
r0 = g0 = b0 = 255;
|
||||
|
||||
switch (id) {
|
||||
switch (id)
|
||||
{
|
||||
case Fonts::MAIN_FONT: // simon 245, 228, 156
|
||||
r0 = 245; g0 = 228; b0 = 156;
|
||||
r0 = 245;
|
||||
g0 = 228;
|
||||
b0 = 156;
|
||||
break;
|
||||
case Fonts::MENU_FONT: // f3 255, 252, 175
|
||||
r0 = 255; g0 = 252; b0 = 175;
|
||||
r0 = 255;
|
||||
g0 = 252;
|
||||
b0 = 175;
|
||||
break;
|
||||
case Fonts::MAGIC_FONT: // magic 219, 255, 151
|
||||
r0 = 219; g0 = 255; b0 = 151;
|
||||
r0 = 219;
|
||||
g0 = 255;
|
||||
b0 = 151;
|
||||
break;
|
||||
case Fonts::SMALLFACE_FONT: // smallface 255, 255, 255
|
||||
r0 = 255; g0 = 255; b0 = 255;
|
||||
r0 = 255;
|
||||
g0 = 255;
|
||||
b0 = 255;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
@@ -84,7 +93,7 @@ static inline int charWidth(const u8 s)
|
||||
// 1's. This may happen when changing from chinese to japanese because the
|
||||
// encoding for chinese is not regular.
|
||||
// static const int sizes[] = {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 3, 4};
|
||||
static const int sizes[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4};
|
||||
static const int sizes[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4 };
|
||||
#if 0
|
||||
// Reactivate to support being called on trailing bytes. This is not needed at the moment
|
||||
// as this function will always be passed leading bytes.
|
||||
@@ -93,21 +102,20 @@ static inline int charWidth(const u8 s)
|
||||
return sizes[s >> 4];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
JRenderer * WFBFont::mRenderer = NULL;
|
||||
|
||||
WLBFont::WLBFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM)
|
||||
: WFont(inFontID)
|
||||
WLBFont::WLBFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM) :
|
||||
WFont(inFontID)
|
||||
{
|
||||
string path(fontname);
|
||||
if (path.size() > 4 ) path = path.substr(0, path.size() - 4); //some stupid manipulation because of the way Font works in JGE
|
||||
if (path.size() > 4) path = path.substr(0, path.size() - 4); //some stupid manipulation because of the way Font works in JGE
|
||||
it = NEW JLBFont(path.c_str(), lineheight, useVideoRAM);
|
||||
}
|
||||
|
||||
WFBFont::WFBFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM)
|
||||
: WFont(inFontID)
|
||||
WFBFont::WFBFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM) :
|
||||
WFont(inFontID)
|
||||
{
|
||||
mRenderer = JRenderer::GetInstance();
|
||||
|
||||
@@ -123,21 +131,20 @@ WFBFont::WFBFont(int inFontID, const char *fontname, int lineheight, bool useVid
|
||||
sprintf(engFileName, "%s.asc", tmpFileName);
|
||||
JFileSystem *fileSys = JFileSystem::GetInstance();
|
||||
int size = 0;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
unsigned short chars;
|
||||
unsigned char width;
|
||||
unsigned char height;
|
||||
} sizeStr = {0, 0, 0};
|
||||
} sizeStr = { 0, 0, 0 };
|
||||
|
||||
if (!fileSys->OpenFile(engFileName))
|
||||
return;
|
||||
if (!fileSys->OpenFile(engFileName)) return;
|
||||
size = fileSys->GetFileSize();
|
||||
mStdFont = NEW u8[size];
|
||||
fileSys->ReadFile(mStdFont, size);
|
||||
fileSys->CloseFile();
|
||||
|
||||
if (!fileSys->OpenFile(fontname))
|
||||
return;
|
||||
if (!fileSys->OpenFile(fontname)) return;
|
||||
fileSys->ReadFile(&sizeStr, 4); // Works only for little-endian machines (PSP and PC are)
|
||||
size = sizeStr.chars * sizeStr.width * sizeStr.height / 2;
|
||||
mExtraFont = NEW u8[size]; // 4 bits for a pixel
|
||||
@@ -152,8 +159,8 @@ WFBFont::WFBFont(int inFontID, const char *fontname, int lineheight, bool useVid
|
||||
mScale = 1.0f;
|
||||
|
||||
// using 4-bit(half-byte) to store 1 pixel
|
||||
mBytesPerRow = static_cast<unsigned int>(mFontSize / 2);
|
||||
mBytesPerChar = static_cast<unsigned int>(mBytesPerRow*mFontSize);
|
||||
mBytesPerRow = static_cast<unsigned int> (mFontSize / 2);
|
||||
mBytesPerChar = static_cast<unsigned int> (mBytesPerRow * mFontSize);
|
||||
|
||||
mCacheImageWidth = 256;
|
||||
mCacheImageHeight = 256;
|
||||
@@ -171,15 +178,14 @@ WFBFont::WFBFont(int inFontID, const char *fontname, int lineheight, bool useVid
|
||||
mTexture = mRenderer->CreateTexture(mCacheImageWidth, mCacheImageHeight, true);
|
||||
|
||||
int index = 0;
|
||||
for (int y = 0; y < mRow; y++) {
|
||||
for (int x = 0; x < mCol; x++) {
|
||||
for (int y = 0; y < mRow; y++)
|
||||
{
|
||||
for (int x = 0; x < mCol; x++)
|
||||
{
|
||||
mGBCode[index] = -1;
|
||||
mSprites[index] = NEW JQuad(mTexture,
|
||||
static_cast<float>(x*mFontSize),
|
||||
static_cast<float>(y*mFontSize),
|
||||
static_cast<float>(mFontSize),
|
||||
static_cast<float>(mFontSize));
|
||||
mSprites[index]->SetHotSpot(static_cast<float>(mFontSize / 2), static_cast<float>(mFontSize / 2));
|
||||
mSprites[index] = NEW JQuad(mTexture, static_cast<float> (x * mFontSize), static_cast<float> (y * mFontSize),
|
||||
static_cast<float> (mFontSize), static_cast<float> (mFontSize));
|
||||
mSprites[index]->SetHotSpot(static_cast<float> (mFontSize / 2), static_cast<float> (mFontSize / 2));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@@ -191,21 +197,20 @@ WFBFont::~WFBFont()
|
||||
SAFE_DELETE(mExtraFont);
|
||||
SAFE_DELETE(mTexture);
|
||||
|
||||
if (mSprites) {
|
||||
for (int i = 0; i < mCacheSize; i++) {
|
||||
if (mSprites[i])
|
||||
delete mSprites[i];
|
||||
if (mSprites)
|
||||
{
|
||||
for (int i = 0; i < mCacheSize; i++)
|
||||
{
|
||||
if (mSprites[i]) delete mSprites[i];
|
||||
}
|
||||
delete [] mSprites;
|
||||
delete[] mSprites;
|
||||
}
|
||||
|
||||
if (NULL != mIndex) delete[] mIndex;
|
||||
|
||||
if (mGBCode)
|
||||
delete [] mGBCode;
|
||||
if (mGBCode) delete[] mGBCode;
|
||||
|
||||
if (mCharBuffer)
|
||||
delete [] mCharBuffer;
|
||||
if (mCharBuffer) delete[] mCharBuffer;
|
||||
}
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
@@ -223,7 +228,7 @@ static void SwizzlePlot(u8* out, PIXEL_TYPE color, int i, int j, unsigned int wi
|
||||
unsigned int block_address = block_index << 7;
|
||||
|
||||
u8* p = out + (block_address + x + (y << 4));
|
||||
PIXEL_TYPE* dest = (PIXEL_TYPE *)p;
|
||||
PIXEL_TYPE* dest = (PIXEL_TYPE *) p;
|
||||
*dest = color;
|
||||
}
|
||||
#endif
|
||||
@@ -238,14 +243,11 @@ int WFBFont::PreCacheChar(const u8 *ch)
|
||||
|
||||
code = this->GetCode(ch, &charLength);
|
||||
|
||||
if (mGBCode[mCurr] != -1)
|
||||
for (int i = 0; i < mCacheSize; i++)
|
||||
if (mGBCode[i] == code)
|
||||
return i;
|
||||
if (mGBCode[mCurr] != -1) for (int i = 0; i < mCacheSize; i++)
|
||||
if (mGBCode[i] == code) return i;
|
||||
|
||||
int index = mCurr++;
|
||||
if (mCurr >= mCacheSize)
|
||||
mCurr = 0;
|
||||
if (mCurr >= mCacheSize) mCurr = 0;
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
int x = 0;
|
||||
@@ -254,31 +256,35 @@ int WFBFont::PreCacheChar(const u8 *ch)
|
||||
#else
|
||||
u8* pTexture = (u8*) mTexture->mBits;
|
||||
int x;
|
||||
int y = (int)mSprites[index]->mY;
|
||||
int y = (int) mSprites[index]->mY;
|
||||
#endif
|
||||
|
||||
if (doubleWidthChar(ch)) {
|
||||
if (doubleWidthChar(ch))
|
||||
{
|
||||
if (mIndex) code = mIndex[code];
|
||||
size = mFontSize;
|
||||
src = mExtraFont + code * mBytesPerChar;
|
||||
offset = 0;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
size = mFontSize / 2;
|
||||
src = mStdFont + code * (mFontSize * size / 2);
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
// set up the font texture buffer
|
||||
for (unsigned int i = 0; i < mFontSize; i++) {
|
||||
for (unsigned int i = 0; i < mFontSize; i++)
|
||||
{
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
x = 0;
|
||||
#else
|
||||
x = (int)mSprites[index]->mX;
|
||||
x = (int) mSprites[index]->mX;
|
||||
#endif
|
||||
unsigned int j = 0;
|
||||
#if 1
|
||||
for (; j < offset; j++) {
|
||||
for (; j < offset; j++)
|
||||
{
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
mCharBuffer[y * mFontSize + x] = ARGB(0, 0, 0, 0);
|
||||
#else
|
||||
@@ -287,7 +293,8 @@ int WFBFont::PreCacheChar(const u8 *ch)
|
||||
x++;
|
||||
}
|
||||
#endif
|
||||
for (; j < offset + size; j++) {
|
||||
for (; j < offset + size; j++)
|
||||
{
|
||||
// as 4-bit(half-byte) stores 1 pixel
|
||||
// get out the proper data according to the even or odd quality of the counter
|
||||
gray = src[(i * size + j - offset) / 2];
|
||||
@@ -300,7 +307,8 @@ int WFBFont::PreCacheChar(const u8 *ch)
|
||||
#endif
|
||||
x++;
|
||||
}
|
||||
for (; j < mFontSize; j++) {
|
||||
for (; j < mFontSize; j++)
|
||||
{
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
mCharBuffer[y * mFontSize + x] = ARGB(0, 0, 0, 0);
|
||||
#else
|
||||
@@ -325,8 +333,9 @@ int WFBFont::PreCacheChar(const u8 *ch)
|
||||
|
||||
void WFBFont::DrawString(const char *s, float x, float y, int align, float leftOffset, float width)
|
||||
{
|
||||
u8 * str = (u8 *)s;
|
||||
if (*str < 0x80) {
|
||||
u8 * str = (u8 *) s;
|
||||
if (*str < 0x80)
|
||||
{
|
||||
// tricky: the single byte font is always mFontID + kSingleByteFontOffset!
|
||||
// See WResourceManager::InitFonts()
|
||||
WFont * mFont = resources.GetWFont(mFontID + Fonts::kSingleByteFontOffset);
|
||||
@@ -341,7 +350,8 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
y += (mFontSize * mScale) / 2;
|
||||
// Warning : non-left alignment is not supported for multiline strings
|
||||
// (this is because GetStringWidth is not aware of line breaks).
|
||||
switch (align) {
|
||||
switch (align)
|
||||
{
|
||||
case JGETEXT_RIGHT:
|
||||
x -= GetStringWidth(s);
|
||||
break;
|
||||
@@ -360,35 +370,45 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
float yy = y;
|
||||
int index = 0;
|
||||
|
||||
while (*src != 0) {
|
||||
while (*src != 0)
|
||||
{
|
||||
if (yy > SCREEN_HEIGHT_F) // don't render or count outside the buttom of viewport
|
||||
return;
|
||||
else if (yy + mFontSize < 0.0f) { // don't render when outside the top of viewport, but counted
|
||||
if (*src < 0x20) { // control characters
|
||||
if (*src == 0x0a) { // NEWLINE
|
||||
xx = x;
|
||||
yy += (mFontSize*mScale);
|
||||
}
|
||||
src += 1;
|
||||
}
|
||||
else {
|
||||
xx += (mFontSize*mScale);
|
||||
|
||||
if (xx >= width) {
|
||||
xx = x;
|
||||
yy += (mFontSize*mScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (*src < 0x20) { // control characters
|
||||
if (*src == 0x0a) { // NEWLINE
|
||||
else if (yy + mFontSize < 0.0f)
|
||||
{ // don't render when outside the top of viewport, but counted
|
||||
if (*src < 0x20)
|
||||
{ // control characters
|
||||
if (*src == 0x0a)
|
||||
{ // NEWLINE
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
src += 1;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
xx += (mFontSize * mScale);
|
||||
|
||||
if (xx >= width)
|
||||
{
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*src < 0x20)
|
||||
{ // control characters
|
||||
if (*src == 0x0a)
|
||||
{ // NEWLINE
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
src += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int mana = this->GetMana(src);
|
||||
bool doubleW = doubleWidthChar(src);
|
||||
index = PreCacheChar(src);
|
||||
@@ -400,45 +420,58 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
float xPos0 = xPos;
|
||||
float charW0 = charW;
|
||||
float delta = doubleW ? (charW * mScale) : (charW * mScale / 2);
|
||||
if (leftOffset) {
|
||||
if (leftOffset < 0) {
|
||||
if (leftOffset)
|
||||
{
|
||||
if (leftOffset < 0)
|
||||
{
|
||||
xx -= leftOffset;
|
||||
leftOffset = 0;
|
||||
}
|
||||
else if (leftOffset - delta > 0) {
|
||||
else if (leftOffset - delta > 0)
|
||||
{
|
||||
leftOffset -= delta;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
xPos += leftOffset / mScale;
|
||||
delta -= leftOffset;
|
||||
leftOffset = 0;
|
||||
charW = delta / mScale;
|
||||
}
|
||||
}
|
||||
else if (width) {
|
||||
if (xx > x + width)
|
||||
return;
|
||||
if (xx + delta > x + width) {
|
||||
else if (width)
|
||||
{
|
||||
if (xx > x + width) return;
|
||||
if (xx + delta > x + width)
|
||||
{
|
||||
delta = x + width - xx;
|
||||
charW = delta / mScale;
|
||||
}
|
||||
}
|
||||
|
||||
if (mana >= 0) {
|
||||
if (mana >= 0)
|
||||
{
|
||||
int mana2 = -1;
|
||||
if (*src == '/' && (mana2 = this->GetMana(src+1)) >= 0) { // hybrid mana cost
|
||||
if (*src == '/' && (mana2 = this->GetMana(src + 1)) >= 0)
|
||||
{ // hybrid mana cost
|
||||
src += 1 + charWidth(*src);
|
||||
unsigned char t = (JGE::GetInstance()->GetTime() / 3) & 0xFF;
|
||||
unsigned char v = t + 127;
|
||||
float scale = 0.05f * cosf(2*M_PI*((float)t)/256.0f);
|
||||
if (scale < 0) {
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2*M_PI*((float)t)/256.0f), yy + 3 * cosf(2*M_PI*((float)(t-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2*M_PI*((float)v)/256.0f), yy + 3 * cosf(2*M_PI*((float)(v-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
float scale = 0.05f * cosf(2 * M_PI * ((float) t) / 256.0f);
|
||||
if (scale < 0)
|
||||
{
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
}
|
||||
else {
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2*M_PI*((float)v)/256.0f), yy + 3 * cosf(2*M_PI*((float)(v-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2*M_PI*((float)t)/256.0f), yy + 3 * cosf(2*M_PI*((float)(t-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
else
|
||||
{
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
}
|
||||
mana = Constants::MTG_NB_COLORS + 1; // do not draw colorless cost in hybrid mana cost
|
||||
}
|
||||
@@ -447,7 +480,8 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
mRenderer->BindTexture(mTexture); // manaIcons use different texture, so we need to rebind it.
|
||||
}
|
||||
|
||||
if (mana <= 0) {
|
||||
if (mana <= 0)
|
||||
{
|
||||
mSprites[index]->SetTextureRect(xPos, yPos, charW, charHeight);
|
||||
mSprites[index]->SetColor(mColor);
|
||||
mRenderer->RenderQuad(mSprites[index], xx, yy, 0, mScale, mScale);
|
||||
@@ -456,7 +490,8 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
|
||||
xx += delta;
|
||||
|
||||
if (xx >= 480) {
|
||||
if (xx >= 480)
|
||||
{
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
@@ -467,7 +502,7 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
|
||||
void WFBFont::DrawString(std::string s, float x, float y, int align, float leftOffset, float width)
|
||||
{
|
||||
DrawString(s.c_str(),x,y,align,leftOffset,width);
|
||||
DrawString(s.c_str(), x, y, align, leftOffset, width);
|
||||
}
|
||||
|
||||
void WFBFont::SetColor(PIXEL_TYPE color)
|
||||
@@ -478,11 +513,13 @@ void WFBFont::SetColor(PIXEL_TYPE color)
|
||||
|
||||
float WFBFont::GetStringWidth(const char *s) const
|
||||
{
|
||||
u8 * src = (u8 *)s;
|
||||
u8 * src = (u8 *) s;
|
||||
int width = 0;
|
||||
|
||||
if (doubleWidthChar(src)) {
|
||||
while (*src != 0) {
|
||||
if (doubleWidthChar(src))
|
||||
{
|
||||
while (*src != 0)
|
||||
{
|
||||
// Add the number of single-char widths according to whether
|
||||
// this is a single or double-width char.
|
||||
width += (doubleWidthChar(src)) ? 2 : 1;
|
||||
@@ -490,7 +527,8 @@ float WFBFont::GetStringWidth(const char *s) const
|
||||
}
|
||||
return width * mFontSize * mScale / 2;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(mFontID + Fonts::kSingleByteFontOffset);
|
||||
mFont->SetScale(GetScale());
|
||||
return mFont->GetStringWidth(s);
|
||||
@@ -503,8 +541,14 @@ void WFBFont::SetScale(float scale)
|
||||
mScale = scale;
|
||||
}
|
||||
|
||||
float WFBFont::GetScale() const {return mScale;}
|
||||
float WFBFont::GetHeight() const {return (mFontSize * mScale);}
|
||||
float WFBFont::GetScale() const
|
||||
{
|
||||
return mScale;
|
||||
}
|
||||
float WFBFont::GetHeight() const
|
||||
{
|
||||
return (mFontSize * mScale);
|
||||
}
|
||||
|
||||
// Legacy : GBK encoding
|
||||
WGBKFont::WGBKFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM) :
|
||||
@@ -525,15 +569,13 @@ WGBKFont::WGBKFont(int inFontID, const char *fontname, int lineheight, bool useV
|
||||
JFileSystem *fileSys = JFileSystem::GetInstance();
|
||||
int size = 0;
|
||||
|
||||
if (!fileSys->OpenFile(fontname))
|
||||
return;
|
||||
if (!fileSys->OpenFile(fontname)) return;
|
||||
size = fileSys->GetFileSize();
|
||||
mExtraFont = NEW u8[size];
|
||||
fileSys->ReadFile(mExtraFont, size);
|
||||
fileSys->CloseFile();
|
||||
|
||||
if (!fileSys->OpenFile(engFileName))
|
||||
return;
|
||||
if (!fileSys->OpenFile(engFileName)) return;
|
||||
size = fileSys->GetFileSize();
|
||||
mStdFont = NEW u8[size];
|
||||
fileSys->ReadFile(mStdFont, size);
|
||||
@@ -547,8 +589,8 @@ WGBKFont::WGBKFont(int inFontID, const char *fontname, int lineheight, bool useV
|
||||
mScale = 1.0f;
|
||||
|
||||
// using 4-bit(half-byte) to store 1 pixel
|
||||
mBytesPerRow = static_cast<unsigned int>(mFontSize / 2);
|
||||
mBytesPerChar = static_cast<unsigned int>(mBytesPerRow*mFontSize);
|
||||
mBytesPerRow = static_cast<unsigned int> (mFontSize / 2);
|
||||
mBytesPerChar = static_cast<unsigned int> (mBytesPerRow * mFontSize);
|
||||
|
||||
mCacheImageWidth = 256;
|
||||
mCacheImageHeight = 256;
|
||||
@@ -566,15 +608,14 @@ WGBKFont::WGBKFont(int inFontID, const char *fontname, int lineheight, bool useV
|
||||
mTexture = mRenderer->CreateTexture(mCacheImageWidth, mCacheImageHeight, true);
|
||||
|
||||
int index = 0;
|
||||
for (int y = 0; y < mRow; y++) {
|
||||
for (int x = 0; x < mCol; x++) {
|
||||
for (int y = 0; y < mRow; y++)
|
||||
{
|
||||
for (int x = 0; x < mCol; x++)
|
||||
{
|
||||
mGBCode[index] = -1;
|
||||
mSprites[index] = NEW JQuad(mTexture,
|
||||
static_cast<float>(x*mFontSize),
|
||||
static_cast<float>(y*mFontSize),
|
||||
static_cast<float>(mFontSize),
|
||||
static_cast<float>(mFontSize));
|
||||
mSprites[index]->SetHotSpot(static_cast<float>(mFontSize / 2), static_cast<float>(mFontSize / 2));
|
||||
mSprites[index] = NEW JQuad(mTexture, static_cast<float> (x * mFontSize), static_cast<float> (y * mFontSize),
|
||||
static_cast<float> (mFontSize), static_cast<float> (mFontSize));
|
||||
mSprites[index]->SetHotSpot(static_cast<float> (mFontSize / 2), static_cast<float> (mFontSize / 2));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@@ -589,17 +630,20 @@ int WGBKFont::PreCacheChar(const u8 *ch)
|
||||
u8 gray;
|
||||
|
||||
#if 0
|
||||
if (*ch > 0xA0 && *(ch + 1) > 0xA0) {
|
||||
if (*ch > 0xA0 && *(ch + 1) > 0xA0)
|
||||
{
|
||||
// get offset to the proper character bits (GB2312 encoding)
|
||||
code = (((u32)(*ch - 0xA1)) * 0x5E + ((u32)(*(ch + 1) - 0xA1)));
|
||||
charLength = 2;
|
||||
}
|
||||
else if (*ch > 0x80) {
|
||||
else if (*ch > 0x80)
|
||||
{
|
||||
// get offset to the character space's bits (GBK encoding)
|
||||
code = 0;
|
||||
charLength = 2;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
code = ((u32)*ch);
|
||||
charLength = 1;
|
||||
}
|
||||
@@ -607,14 +651,11 @@ int WGBKFont::PreCacheChar(const u8 *ch)
|
||||
code = this->GetCode(ch, &charLength);
|
||||
#endif
|
||||
|
||||
if (mGBCode[mCurr] != -1)
|
||||
for (int i = 0; i < mCacheSize; i++)
|
||||
if (mGBCode[i] == code)
|
||||
return i;
|
||||
if (mGBCode[mCurr] != -1) for (int i = 0; i < mCacheSize; i++)
|
||||
if (mGBCode[i] == code) return i;
|
||||
|
||||
int index = mCurr++;
|
||||
if (mCurr >= mCacheSize)
|
||||
mCurr = 0;
|
||||
if (mCurr >= mCacheSize) mCurr = 0;
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
int x = 0;
|
||||
@@ -623,32 +664,36 @@ int WGBKFont::PreCacheChar(const u8 *ch)
|
||||
#else
|
||||
u8* pTexture = (u8*) mTexture->mBits;
|
||||
int x;
|
||||
int y = (int)mSprites[index]->mY;
|
||||
int y = (int) mSprites[index]->mY;
|
||||
#endif
|
||||
|
||||
if (mIndex) code = mIndex[code];
|
||||
|
||||
if (GBKDoubleWidthChar(ch)) {
|
||||
if (GBKDoubleWidthChar(ch))
|
||||
{
|
||||
size = mFontSize;
|
||||
src = mExtraFont + code * mBytesPerChar;
|
||||
offset = 0;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
size = mFontSize / 2;
|
||||
src = mStdFont + code * (mFontSize * size / 2);
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
// set up the font texture buffer
|
||||
for (unsigned int i = 0; i < mFontSize; i++) {
|
||||
for (unsigned int i = 0; i < mFontSize; i++)
|
||||
{
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
x = 0;
|
||||
#else
|
||||
x = (int)mSprites[index]->mX;
|
||||
x = (int) mSprites[index]->mX;
|
||||
#endif
|
||||
unsigned int j = 0;
|
||||
#if 1
|
||||
for (; j < offset; j++) {
|
||||
for (; j < offset; j++)
|
||||
{
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
mCharBuffer[y * mFontSize + x] = ARGB(0, 0, 0, 0);
|
||||
#else
|
||||
@@ -657,7 +702,8 @@ int WGBKFont::PreCacheChar(const u8 *ch)
|
||||
x++;
|
||||
}
|
||||
#endif
|
||||
for (; j < offset + size; j++) {
|
||||
for (; j < offset + size; j++)
|
||||
{
|
||||
// as 4-bit(half-byte) stores 1 pixel
|
||||
// get out the proper data according to the even or odd quality of the counter
|
||||
gray = src[(i * size + j - offset) / 2];
|
||||
@@ -670,7 +716,8 @@ int WGBKFont::PreCacheChar(const u8 *ch)
|
||||
#endif
|
||||
x++;
|
||||
}
|
||||
for (; j < mFontSize; j++) {
|
||||
for (; j < mFontSize; j++)
|
||||
{
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
mCharBuffer[y * mFontSize + x] = ARGB(0, 0, 0, 0);
|
||||
#else
|
||||
@@ -695,9 +742,12 @@ int WGBKFont::PreCacheChar(const u8 *ch)
|
||||
|
||||
void WGBKFont::DrawString(const char *s, float x, float y, int align, float leftOffset, float width)
|
||||
{
|
||||
unsigned char c = *(unsigned short *)s & 0xFF;
|
||||
if (ISGBK(c) || (s[1] == ':' && s[2] == ' ')) {}
|
||||
else {
|
||||
unsigned char c = *(unsigned short *) s & 0xFF;
|
||||
if (ISGBK(c) || (s[1] == ':' && s[2] == ' '))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
// tricky: the single byte font is always mFontID + kSingleByteFontOffset!
|
||||
// See WResourceManager::InitFonts()
|
||||
WFont * mFont = resources.GetWFont(mFontID + Fonts::kSingleByteFontOffset);
|
||||
@@ -707,12 +757,13 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
return;
|
||||
}
|
||||
|
||||
u8 * str = (u8 *)s;
|
||||
u8 * str = (u8 *) s;
|
||||
|
||||
// (0, 0) refers to the center of the word, so fix it to the upper-left corner
|
||||
x += (mFontSize * mScale) / 2;
|
||||
y += (mFontSize * mScale) / 2;
|
||||
switch (align) {
|
||||
switch (align)
|
||||
{
|
||||
case JGETEXT_RIGHT:
|
||||
x -= GetStringWidth(s);
|
||||
break;
|
||||
@@ -731,50 +782,62 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
float yy = y;
|
||||
int index = 0;
|
||||
|
||||
bool dualByteFont=true;
|
||||
bool dualByteFont = true;
|
||||
|
||||
while (*src != 0) {
|
||||
while (*src != 0)
|
||||
{
|
||||
if (yy > SCREEN_HEIGHT_F) // don't render or count outside the buttom of viewport
|
||||
return;
|
||||
else if (yy + mFontSize < 0.0f) { // don't render when outside the top of viewport, but counted
|
||||
if (*src < 0x20) { // control characters
|
||||
if (*src == 0x0a) { // NEWLINE
|
||||
xx = x;
|
||||
yy += (mFontSize*mScale);
|
||||
}
|
||||
src += 1;
|
||||
}
|
||||
else {
|
||||
if (*src > 0x80) // 2-bytes char
|
||||
src += 2;
|
||||
else
|
||||
src += 1;
|
||||
|
||||
xx += (mFontSize*mScale);
|
||||
|
||||
if (xx >= 480) {
|
||||
xx = x;
|
||||
yy += (mFontSize*mScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (*src < 0x20) { // control characters
|
||||
if (*src == 0x0a) { // NEWLINE
|
||||
else if (yy + mFontSize < 0.0f)
|
||||
{ // don't render when outside the top of viewport, but counted
|
||||
if (*src < 0x20)
|
||||
{ // control characters
|
||||
if (*src == 0x0a)
|
||||
{ // NEWLINE
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
src += 1;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (*src > 0x80) // 2-bytes char
|
||||
src += 2;
|
||||
else
|
||||
src += 1;
|
||||
|
||||
xx += (mFontSize * mScale);
|
||||
|
||||
if (xx >= 480)
|
||||
{
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*src < 0x20)
|
||||
{ // control characters
|
||||
if (*src == 0x0a)
|
||||
{ // NEWLINE
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
src += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int mana = -1;
|
||||
if (*src > 0x80) { // 2-bytes char
|
||||
if (*src > 0x80)
|
||||
{ // 2-bytes char
|
||||
mana = this->GetMana(src);
|
||||
index = PreCacheChar(src);
|
||||
src += 2;
|
||||
dualByteFont = true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
index = PreCacheChar(src);
|
||||
src += 1;
|
||||
dualByteFont = false;
|
||||
@@ -786,45 +849,58 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
float xPos0 = xPos;
|
||||
float charW0 = charW;
|
||||
float delta = (dualByteFont) ? (charW * mScale) : (charW * mScale / 2);
|
||||
if (leftOffset) {
|
||||
if (leftOffset < 0) {
|
||||
if (leftOffset)
|
||||
{
|
||||
if (leftOffset < 0)
|
||||
{
|
||||
xx -= leftOffset;
|
||||
leftOffset = 0;
|
||||
}
|
||||
else if (leftOffset - delta > 0) {
|
||||
else if (leftOffset - delta > 0)
|
||||
{
|
||||
leftOffset -= delta;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
xPos += leftOffset / mScale;
|
||||
delta -= leftOffset;
|
||||
leftOffset = 0;
|
||||
charW = delta / mScale;
|
||||
}
|
||||
}
|
||||
else if (width) {
|
||||
if (xx > x + width)
|
||||
return;
|
||||
if (xx + delta > x + width) {
|
||||
else if (width)
|
||||
{
|
||||
if (xx > x + width) return;
|
||||
if (xx + delta > x + width)
|
||||
{
|
||||
delta = x + width - xx;
|
||||
charW = delta / mScale;
|
||||
}
|
||||
}
|
||||
|
||||
if (mana >= 0) {
|
||||
if (mana >= 0)
|
||||
{
|
||||
int mana2 = -1;
|
||||
if (*src == '/' && (mana2 = this->GetMana(src+1)) >= 0) { // hybrid mana cost
|
||||
if (*src == '/' && (mana2 = this->GetMana(src + 1)) >= 0)
|
||||
{ // hybrid mana cost
|
||||
src += 3;
|
||||
unsigned char t = (JGE::GetInstance()->GetTime() / 3) & 0xFF;
|
||||
unsigned char v = t + 127;
|
||||
float scale = 0.05f * cosf(2*M_PI*((float)t)/256.0f);
|
||||
if (scale < 0) {
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2*M_PI*((float)t)/256.0f), yy + 3 * cosf(2*M_PI*((float)(t-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2*M_PI*((float)v)/256.0f), yy + 3 * cosf(2*M_PI*((float)(v-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
float scale = 0.05f * cosf(2 * M_PI * ((float) t) / 256.0f);
|
||||
if (scale < 0)
|
||||
{
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
}
|
||||
else {
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2*M_PI*((float)v)/256.0f), yy + 3 * cosf(2*M_PI*((float)(v-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2*M_PI*((float)t)/256.0f), yy + 3 * cosf(2*M_PI*((float)(t-35))/256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
else
|
||||
{
|
||||
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
|
||||
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
|
||||
}
|
||||
mana = Constants::MTG_NB_COLORS + 1; // donot draw colorless cost in hybrid mana cost
|
||||
}
|
||||
@@ -833,7 +909,8 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
mRenderer->BindTexture(mTexture); // manaIcons use different texture, so we need to rebind it.
|
||||
}
|
||||
|
||||
if (mana <= 0) {
|
||||
if (mana <= 0)
|
||||
{
|
||||
mSprites[index]->SetTextureRect(xPos, yPos, charW, charHeight);
|
||||
mSprites[index]->SetColor(mColor);
|
||||
mRenderer->RenderQuad(mSprites[index], xx, yy, 0, mScale, mScale);
|
||||
@@ -842,7 +919,8 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
|
||||
xx += delta;
|
||||
|
||||
if (xx >= 480) {
|
||||
if (xx >= 480)
|
||||
{
|
||||
xx = x;
|
||||
yy += (mFontSize * mScale);
|
||||
}
|
||||
@@ -853,19 +931,23 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
|
||||
float WGBKFont::GetStringWidth(const char *s) const
|
||||
{
|
||||
unsigned char c = *(unsigned short *)s & 0xFF;
|
||||
unsigned char c = *(unsigned short *) s & 0xFF;
|
||||
|
||||
if (ISGBK(c)) {
|
||||
u8 * src = (u8 *)s;
|
||||
if (ISGBK(c))
|
||||
{
|
||||
u8 * src = (u8 *) s;
|
||||
float xx = 0;
|
||||
bool dualByteFont = true;
|
||||
|
||||
while (*src != 0) {
|
||||
if (*src > 0x80) { // Chinese and Japanese
|
||||
while (*src != 0)
|
||||
{
|
||||
if (*src > 0x80)
|
||||
{ // Chinese and Japanese
|
||||
src += 2;
|
||||
dualByteFont = true;
|
||||
}
|
||||
else { // Latin 1
|
||||
else
|
||||
{ // Latin 1
|
||||
src += 1;
|
||||
dualByteFont = false;
|
||||
}
|
||||
@@ -876,7 +958,8 @@ float WGBKFont::GetStringWidth(const char *s) const
|
||||
}
|
||||
return xx;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(mFontID + Fonts::kSingleByteFontOffset);
|
||||
mFont->SetScale(GetScale());
|
||||
return mFont->GetStringWidth(s);
|
||||
@@ -888,16 +971,19 @@ int WGBKFont::GetCode(const u8 *ch, int *charLength) const
|
||||
int code = 0;
|
||||
*charLength = 2;
|
||||
|
||||
if (*ch > 0xA0 && *(ch + 1) > 0xA0) {
|
||||
if (*ch > 0xA0 && *(ch + 1) > 0xA0)
|
||||
{
|
||||
// get offset to the proper character bits (GB2312 encoding)
|
||||
code = (((u32)(*ch - 0xA1)) * 0x5E + ((u32)(*(ch + 1) - 0xA1)));
|
||||
}
|
||||
else if (*ch > 0x80) {
|
||||
else if (*ch > 0x80)
|
||||
{
|
||||
// get offset to the character space's bits (GBK encoding)
|
||||
code = 0;
|
||||
}
|
||||
else {
|
||||
code = ((u32)*ch);
|
||||
else
|
||||
{
|
||||
code = ((u32) * ch);
|
||||
*charLength = 1;
|
||||
}
|
||||
return code;
|
||||
@@ -908,7 +994,8 @@ int WGBKFont::GetMana(const u8 *ch) const
|
||||
int mana = -1;
|
||||
|
||||
if (*ch != 0xa3) return mana;
|
||||
switch (*(ch+1)) {
|
||||
switch (*(ch + 1))
|
||||
{
|
||||
case 0xC7:
|
||||
mana = Constants::MTG_COLOR_GREEN;
|
||||
break;
|
||||
@@ -930,8 +1017,7 @@ int WGBKFont::GetMana(const u8 *ch) const
|
||||
mana = Constants::MTG_UNCOLORED;
|
||||
break;
|
||||
default:
|
||||
if (*(ch+1) >= 0xB0 && *(ch+1) <= 0xB9)
|
||||
mana = Constants::MTG_UNCOLORED;
|
||||
if (*(ch + 1) >= 0xB0 && *(ch + 1) <= 0xB9) mana = Constants::MTG_UNCOLORED;
|
||||
}
|
||||
return mana;
|
||||
}
|
||||
@@ -946,19 +1032,23 @@ int WUFont::GetCode(const u8 *ch, int *charLength) const
|
||||
|
||||
// For a description of the binary representation, look at wikipedia://utf-8
|
||||
|
||||
if ((*ch & 0xF8) == 0xF0) { // Four bytes
|
||||
if ((*ch & 0xF8) == 0xF0)
|
||||
{ // Four bytes
|
||||
*charLength = 4;
|
||||
code = ((*ch * 0x7) << 18) + ((*(ch+1) & 0x3F) << 12) + ((*(ch+2) & 0x3F) << 6) + ((*(ch+3) * 0x3F));
|
||||
code = ((*ch * 0x7) << 18) + ((*(ch + 1) & 0x3F) << 12) + ((*(ch + 2) & 0x3F) << 6) + ((*(ch + 3) * 0x3F));
|
||||
}
|
||||
else if ((*ch & 0xF0) == 0xE0) { // Three bytes
|
||||
else if ((*ch & 0xF0) == 0xE0)
|
||||
{ // Three bytes
|
||||
*charLength = 3;
|
||||
code = ((*ch & 0xF) << 12) + ((*(ch+1) & 0x3F) << 6) + ((*(ch+2) & 0x3F));
|
||||
code = ((*ch & 0xF) << 12) + ((*(ch + 1) & 0x3F) << 6) + ((*(ch + 2) & 0x3F));
|
||||
}
|
||||
else if ((*ch & 0xE0) == 0xC0) { // Two bytes
|
||||
else if ((*ch & 0xE0) == 0xC0)
|
||||
{ // Two bytes
|
||||
*charLength = 2;
|
||||
code = ((*ch & 0x1F) << 6) + ((*(ch+2) & 0x3F));
|
||||
code = ((*ch & 0x1F) << 6) + ((*(ch + 2) & 0x3F));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*charLength = 1;
|
||||
code = *ch;
|
||||
}
|
||||
@@ -987,9 +1077,10 @@ int WUFont::GetMana(const u8 *ch) const
|
||||
return Constants::MTG_UNCOLORED;
|
||||
}
|
||||
*/
|
||||
if (*ch != 0xef || *(ch+1) != 0xbc) return -1;
|
||||
if (*ch != 0xef || *(ch + 1) != 0xbc) return -1;
|
||||
ch += 2;
|
||||
switch (*ch) {
|
||||
switch (*ch)
|
||||
{
|
||||
case 0xa7: // G : 0xefbca7
|
||||
return Constants::MTG_COLOR_GREEN;
|
||||
case 0xb5: // U : 0xefbcb5
|
||||
@@ -1005,8 +1096,7 @@ int WUFont::GetMana(const u8 *ch) const
|
||||
case 0xb9: // Y : 0xefbcb9
|
||||
return Constants::MTG_UNCOLORED;
|
||||
default:
|
||||
if (*ch >= 0x90 && *ch <= 0x99)
|
||||
return Constants::MTG_UNCOLORED;
|
||||
if (*ch >= 0x90 && *ch <= 0x99) return Constants::MTG_UNCOLORED;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
+1086
-831
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user