* Remove ^M's.
* Re-indent automatically.
* Remove whitespace at the end of lines.
This commit is contained in:
jean.chalard
2008-11-12 13:45:42 +00:00
parent 6ad6f9b668
commit c97dd1f260
116 changed files with 18073 additions and 18073 deletions

View File

@@ -1,62 +1,62 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _IAPLAYER_H
#define _IAPLAYER_H
#include "Player.h"
#define INFO_NBCREATURES 0
#define INFO_CREATURESPOWER 1
class AIStats;
class AIPlayer: public Player{
protected:
MTGCardInstance * nextCardToPlay;
ManaCost * potentialMana;
void tapLandsForMana(ManaCost * potentialMana, ManaCost * cost);
int checkInterrupt();
int combatDamages();
int chooseAttackers();
int chooseBlockers();
int effectBadOrGood(MTGCardInstance * card);
int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
AIStats * getStats();
public:
virtual int displayStack(){return 0;}
AIStats * stats;
ManaCost * getPotentialMana();
AIPlayer(MTGPlayerCards * _deck, string deckFile);
virtual ~AIPlayer();
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
virtual int chooseTarget(TargetChooser * tc = NULL);
virtual int Act(float dt);
int isAI(){return 1;};
};
class AIPlayerBaka: public AIPlayer{
protected:
int oldGamePhase;
int timer;
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
public:
AIPlayerBaka(MTGPlayerCards * _deck, char * deckFile);
virtual int Act(float dt);
void initTimer();
};
class AIPlayerFactory{
public:
AIPlayer * createAIPlayer(MTGAllCards * collection, MTGPlayerCards * oponents_deck);
};
#endif
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _IAPLAYER_H
#define _IAPLAYER_H
#include "Player.h"
#define INFO_NBCREATURES 0
#define INFO_CREATURESPOWER 1
class AIStats;
class AIPlayer: public Player{
protected:
MTGCardInstance * nextCardToPlay;
ManaCost * potentialMana;
void tapLandsForMana(ManaCost * potentialMana, ManaCost * cost);
int checkInterrupt();
int combatDamages();
int chooseAttackers();
int chooseBlockers();
int effectBadOrGood(MTGCardInstance * card);
int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
AIStats * getStats();
public:
virtual int displayStack(){return 0;}
AIStats * stats;
ManaCost * getPotentialMana();
AIPlayer(MTGPlayerCards * _deck, string deckFile);
virtual ~AIPlayer();
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
virtual int chooseTarget(TargetChooser * tc = NULL);
virtual int Act(float dt);
int isAI(){return 1;};
};
class AIPlayerBaka: public AIPlayer{
protected:
int oldGamePhase;
int timer;
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
public:
AIPlayerBaka(MTGPlayerCards * _deck, char * deckFile);
virtual int Act(float dt);
void initTimer();
};
class AIPlayerFactory{
public:
AIPlayer * createAIPlayer(MTGAllCards * collection, MTGPlayerCards * oponents_deck);
};
#endif

View File

@@ -1,42 +1,42 @@
#ifndef _AISTATS_H_
#define _AISTATS_H_
#define STATS_PLAYER_MULTIPLIER 15
#define STATS_CREATURE_MULTIPLIER 10
#define STATS_AURA_MULTIPLIER 9
#ifndef _AISTATS_H_
#define _AISTATS_H_
#define STATS_PLAYER_MULTIPLIER 15
#define STATS_CREATURE_MULTIPLIER 10
#define STATS_AURA_MULTIPLIER 9
#include <list>
#include <string>
using std::list;
using std::string;
class Player;
class MTGCardInstance;
class MTGCard;
class Damage;
class AIStat{
public:
int source; //MTGId of the card
int value;
int occurences;
bool direct;
AIStat(int _source, int _value, int _occurences, bool _direct):source(_source), value(_value),occurences(_occurences),direct(_direct){};
};
class AIStats{
public:
Player * player;
string filename;
list<AIStat *> stats;
AIStats(Player * _player, char * filename);
~AIStats();
void updateStats();
void load(char * filename);
void save();
AIStat * find(MTGCard * card);
bool isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue = true );
void updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier = 1.0);
};
using std::list;
using std::string;
class Player;
class MTGCardInstance;
class MTGCard;
class Damage;
class AIStat{
public:
int source; //MTGId of the card
int value;
int occurences;
bool direct;
AIStat(int _source, int _value, int _occurences, bool _direct):source(_source), value(_value),occurences(_occurences),direct(_direct){};
};
class AIStats{
public:
Player * player;
string filename;
list<AIStat *> stats;
AIStats(Player * _player, char * filename);
~AIStats();
void updateStats();
void load(char * filename);
void save();
AIStat * find(MTGCard * card);
bool isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue = true );
void updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier = 1.0);
};
#endif

View File

@@ -1,8 +1,8 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _ACTIONELEMENT_H_
#define _ACTIONELEMENT_H_
@@ -18,30 +18,30 @@ class Targetable;
class TargetChooser;
class ActionElement: public JGuiObject{
protected:
int activeState;
protected:
int activeState;
public:
TargetChooser * tc;
int currentPhase;
int newPhase;
int modal;
int waitingForAnswer;
public:
TargetChooser * tc;
int currentPhase;
int newPhase;
int modal;
int waitingForAnswer;
void RenderMessageBackground(float y0, int height);
int getActivity();
virtual void Update(float dt){};
virtual void Render(){};
virtual int testDestroy(){return 0;};
virtual int destroy(){return 0;};
virtual void CheckUserInput(float dt){};
ActionElement(int id);
virtual int isReactingToTargetClick(Targetable * card);
virtual int reactToTargetClick(Targetable * card);
virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual const char * getMenuText(){return "Ability";};
int getActivity();
virtual void Update(float dt){};
virtual void Render(){};
virtual int testDestroy(){return 0;};
virtual int destroy(){return 0;};
virtual void CheckUserInput(float dt){};
ActionElement(int id);
virtual int isReactingToTargetClick(Targetable * card);
virtual int reactToTargetClick(Targetable * card);
virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual const char * getMenuText(){return "Ability";};
};

View File

@@ -1,8 +1,8 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _ACTIONLAYER_H_
#define _ACTIONLAYER_H_
@@ -16,22 +16,22 @@ class Targetable;
class ActionLayer: public GuiLayer, public JGuiListener{
public:
Targetable * menuObject;
SimpleMenu * abilitiesMenu;
virtual void Render();
virtual void Update(float dt);
int unstopableRenderInProgress();
void CheckUserInput(float dt);
ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;};
int isWaitingForAnswer();
int isReactingToTargetClick(Targetable * card);
int reactToTargetClick(Targetable * card);
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int isModal();
void setMenuObject(Targetable * object);
void ButtonPressed(int controllerid, int controlid);
TargetChooser * getCurrentTargetChooser();
Targetable * menuObject;
SimpleMenu * abilitiesMenu;
virtual void Render();
virtual void Update(float dt);
int unstopableRenderInProgress();
void CheckUserInput(float dt);
ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;};
int isWaitingForAnswer();
int isReactingToTargetClick(Targetable * card);
int reactToTargetClick(Targetable * card);
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int isModal();
void setMenuObject(Targetable * object);
void ButtonPressed(int controllerid, int controlid);
TargetChooser * getCurrentTargetChooser();
};

View File

@@ -1,151 +1,151 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _SPELLSTACK_H_
#define _SPELLSTACK_H_
#define MAX_SPELL_TARGETS 10
#define ACTION_SPELL 10
#define ACTION_DAMAGE 11
#define ACTION_DAMAGES 12
#define ACTION_NEXTGAMEPHASE 13
#define ACTION_DRAW 14
#define ACTION_PUTINGRAVEYARD 15
#define ACTION_ABILITY 16
#define NOT_RESOLVED -2
#define RESOLVED_OK 1
#define RESOLVED_NOK -1
#include "../include/PlayGuiObject.h"
#include "GuiLayers.h"
#include "../include/TargetsList.h"
#include "../include/Targetable.h"
class GuiLayer;
class PlayGuiObject;
class MTGCardInstance;
class GameObserver;
class Player;
class Damageable;
class MTGAbility;
class Targetable;
class DamageStack;
class ManaCost;
#define ACTIONSTACK_STANDARD 0
#define ACTIONSTACK_TARGET 1
class Interruptible: public PlayGuiObject, public Targetable{
public:
int state, display;
MTGCardInstance * source;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual int resolve(){return 0;};
virtual void Render(){};
int typeAsTarget(){return TARGET_STACKACTION;};
Interruptible(int id,bool hasFocus = false):PlayGuiObject(id,40,x,y,hasFocus){state=NOT_RESOLVED;display=0;source=NULL;};
};
class NextGamePhase: public Interruptible {
public:
int resolve();
void Render();
NextGamePhase(int id);
};
class Spell: public Interruptible, public TargetsList {
protected:
public:
ManaCost * cost;
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, Targetable * _targets[], int _nbtargets, ManaCost * _cost);
~Spell();
int resolve();
void Render();
};
class StackAbility: public Interruptible {
public:
MTGAbility * ability;
int resolve();
void Render();
StackAbility(int id, MTGAbility * _ability);
};
class PutInGraveyard: public Interruptible {
public:
MTGCardInstance * card;
int removeFromGame;
int resolve();
void Render();
PutInGraveyard(int id, MTGCardInstance * _card);
};
class DrawAction: public Interruptible {
public:
int nbcards;
Player * player;
int resolve();
void Render();
DrawAction(int id, Player * _player, int _nbcards);
};
class ActionStack :public GuiLayer{
protected:
int interruptDecision[2];
int timer;
int currentState;
int mode;
int checked;
void unpackDamageStacks();
void unpackDamageStack(DamageStack * ds);
void repackDamageStacks();
public:
int setIsInterrupting(Player * player);
int count( int type = 0 , int state = 0 , int display = -1);
Interruptible * getPrevious(Interruptible * next, int type = 0, int state = 0 , int display = -1);
int getPreviousIndex(Interruptible * next, int type = 0, int state = 0 , int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
void Fizzle(Interruptible * action);
Interruptible * _(int id);
void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption();
Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt;
int garbageCollect();
int addAction(Interruptible * interruptible);
int addSpell(MTGCardInstance* card, Targetable * targets[], int nbtargets, ManaCost * mana);
int AddNextGamePhase();
int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability);
void Update(float dt);
void CheckUserInput(float dt);
virtual void Render();
ActionStack(int id, GameObserver* _game);
int resolve();
int CombatDamages();
int CombatDamages(int firststrike);
int has(Interruptible * action);
};
#endif
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _SPELLSTACK_H_
#define _SPELLSTACK_H_
#define MAX_SPELL_TARGETS 10
#define ACTION_SPELL 10
#define ACTION_DAMAGE 11
#define ACTION_DAMAGES 12
#define ACTION_NEXTGAMEPHASE 13
#define ACTION_DRAW 14
#define ACTION_PUTINGRAVEYARD 15
#define ACTION_ABILITY 16
#define NOT_RESOLVED -2
#define RESOLVED_OK 1
#define RESOLVED_NOK -1
#include "../include/PlayGuiObject.h"
#include "GuiLayers.h"
#include "../include/TargetsList.h"
#include "../include/Targetable.h"
class GuiLayer;
class PlayGuiObject;
class MTGCardInstance;
class GameObserver;
class Player;
class Damageable;
class MTGAbility;
class Targetable;
class DamageStack;
class ManaCost;
#define ACTIONSTACK_STANDARD 0
#define ACTIONSTACK_TARGET 1
class Interruptible: public PlayGuiObject, public Targetable{
public:
int state, display;
MTGCardInstance * source;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual int resolve(){return 0;};
virtual void Render(){};
int typeAsTarget(){return TARGET_STACKACTION;};
Interruptible(int id,bool hasFocus = false):PlayGuiObject(id,40,x,y,hasFocus){state=NOT_RESOLVED;display=0;source=NULL;};
};
class NextGamePhase: public Interruptible {
public:
int resolve();
void Render();
NextGamePhase(int id);
};
class Spell: public Interruptible, public TargetsList {
protected:
public:
ManaCost * cost;
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, Targetable * _targets[], int _nbtargets, ManaCost * _cost);
~Spell();
int resolve();
void Render();
};
class StackAbility: public Interruptible {
public:
MTGAbility * ability;
int resolve();
void Render();
StackAbility(int id, MTGAbility * _ability);
};
class PutInGraveyard: public Interruptible {
public:
MTGCardInstance * card;
int removeFromGame;
int resolve();
void Render();
PutInGraveyard(int id, MTGCardInstance * _card);
};
class DrawAction: public Interruptible {
public:
int nbcards;
Player * player;
int resolve();
void Render();
DrawAction(int id, Player * _player, int _nbcards);
};
class ActionStack :public GuiLayer{
protected:
int interruptDecision[2];
int timer;
int currentState;
int mode;
int checked;
void unpackDamageStacks();
void unpackDamageStack(DamageStack * ds);
void repackDamageStacks();
public:
int setIsInterrupting(Player * player);
int count( int type = 0 , int state = 0 , int display = -1);
Interruptible * getPrevious(Interruptible * next, int type = 0, int state = 0 , int display = -1);
int getPreviousIndex(Interruptible * next, int type = 0, int state = 0 , int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
void Fizzle(Interruptible * action);
Interruptible * _(int id);
void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption();
Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt;
int garbageCollect();
int addAction(Interruptible * interruptible);
int addSpell(MTGCardInstance* card, Targetable * targets[], int nbtargets, ManaCost * mana);
int AddNextGamePhase();
int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability);
void Update(float dt);
void CheckUserInput(float dt);
virtual void Render();
ActionStack(int id, GameObserver* _game);
int resolve();
int CombatDamages();
int CombatDamages(int firststrike);
int has(Interruptible * action);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -13,36 +13,36 @@ class GameObserver;
class MTGAbility;
class Blocker : public MTGAbility {
protected:
ManaCost * manaCost;
int currentPhase;
void init(ManaCost * _cost);
public:
virtual ManaCost * untapManaCost(){return manaCost;};
virtual int unblock(){return 1;};
Blocker(int id, MTGCardInstance * card, ManaCost * _cost);
Blocker(int id, MTGCardInstance * card);
Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost);
~Blocker();
virtual void Update(float dt);
virtual int destroy();
protected:
ManaCost * manaCost;
int currentPhase;
void init(ManaCost * _cost);
public:
virtual ManaCost * untapManaCost(){return manaCost;};
virtual int unblock(){return 1;};
Blocker(int id, MTGCardInstance * card, ManaCost * _cost);
Blocker(int id, MTGCardInstance * card);
Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost);
~Blocker();
virtual void Update(float dt);
virtual int destroy();
};
class Blockers {
protected:
int cursor;
int blockers[MAX_BLOCKERS];
GameObserver * game;
public:
Blockers();
~Blockers();
int Add (Blocker * ability);
int Remove (Blocker * ability);
int init();
Blocker * next();
int rewind();
int isEmpty();
protected:
int cursor;
int blockers[MAX_BLOCKERS];
GameObserver * game;
public:
Blockers();
~Blockers();
int Add (Blocker * ability);
int Remove (Blocker * ability);
int init();
Blocker * next();
int rewind();
int isEmpty();
};

View File

@@ -1,5 +1,5 @@
/*
A Filter/Mask system for Card Instances to find cards matching specific settings such as color, type, etc...
A Filter/Mask system for Card Instances to find cards matching specific settings such as color, type, etc...
*/
#ifndef _CARDDESCRIPTOR_H_
@@ -12,16 +12,16 @@ A Filter/Mask system for Card Instances to find cards matching specific settings
#define CD_AND 2
class CardDescriptor: public MTGCardInstance{
protected:
MTGCardInstance * match_or(MTGCardInstance * card);
MTGCardInstance * match_and(MTGCardInstance * card);
public:
int mode;
int init();
CardDescriptor();
MTGCardInstance * match(MTGCardInstance * card);
MTGCardInstance * match(MTGGameZone * zone);
MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous);
protected:
MTGCardInstance * match_or(MTGCardInstance * card);
MTGCardInstance * match_and(MTGCardInstance * card);
public:
int mode;
int init();
CardDescriptor();
MTGCardInstance * match(MTGCardInstance * card);
MTGCardInstance * match(MTGGameZone * zone);
MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous);
};
#endif
#endif

View File

@@ -1,32 +1,32 @@
#ifndef _CARD_DISPLAY_H_
#define _CARD_DISPLAY_H_
#include "../include/PlayGuiObjectController.h"
class TargetChooser;
class MTGGameZone;
class MTGCardInstance;
class CardDisplay:public PlayGuiObjectController{
public:
int x, y , start_item, nb_displayed_items;
TargetChooser * tc;
JGuiListener * listener;
CardDisplay();
CardDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc = NULL, int _nb_displayed_items = 7 );
void AddCard(MTGCardInstance * _card);
void rotateLeft();
void rotateRight();
void CheckUserInput(float dt);
void Render();
void init(MTGGameZone * zone);
};
class DefaultTargetDisplay:CardDisplay{
public:
DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, int _nb_displayed_items );
~DefaultTargetDisplay();
};
#endif
#ifndef _CARD_DISPLAY_H_
#define _CARD_DISPLAY_H_
#include "../include/PlayGuiObjectController.h"
class TargetChooser;
class MTGGameZone;
class MTGCardInstance;
class CardDisplay:public PlayGuiObjectController{
public:
int x, y , start_item, nb_displayed_items;
TargetChooser * tc;
JGuiListener * listener;
CardDisplay();
CardDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc = NULL, int _nb_displayed_items = 7 );
void AddCard(MTGCardInstance * _card);
void rotateLeft();
void rotateRight();
void CheckUserInput(float dt);
void Render();
void init(MTGGameZone * zone);
};
class DefaultTargetDisplay:CardDisplay{
public:
DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, int _nb_displayed_items );
~DefaultTargetDisplay();
};
#endif

View File

@@ -12,18 +12,18 @@ class MTGCardInstance;
class PlayGuiObject;
class CardGui: public PlayGuiObject{
protected:
hgeParticleSystem * mParticleSys;
int alpha;
protected:
hgeParticleSystem * mParticleSys;
int alpha;
public:
MTGCardInstance * card;
CardGui(int id, MTGCardInstance * _card, float desiredHeight, float _x=0, float _y=0, bool hasFocus = false);
virtual void Render();
virtual void Update(float dt);
virtual void Update(float dt);
void RenderBig(float x=-1, float y = -1);
static void alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation= 0, float scale=1);
~CardGui();
void RenderBig(float x=-1, float y = -1);
static void alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation= 0, float scale=1);
~CardGui();
};

View File

@@ -6,9 +6,9 @@
class ConstraintResolver {
protected:
public:
static int untap(GameObserver * game, MTGCardInstance * card);
protected:
public:
static int untap(GameObserver * game, MTGCardInstance * card);
};
#endif

View File

@@ -1,43 +1,43 @@
#ifndef _COUNTERS_H_
#define _COUNTERS_H_
#include <string>
using std::string;
class MTGCardInstance;
/* One family of counters. Ex : +1/+1 */
class Counter{
public :
string name;
int nb;
int power, toughness;
MTGCardInstance * target;
Counter(MTGCardInstance * _target, int _power, int _toughness);
Counter(MTGCardInstance * _target, const char * _name,int _power = 0 , int _toughness = 0 );
int init(MTGCardInstance * _target,const char * _name, int _power, int _toughness);
bool sameAs(const char * _name, int _power, int _toughness);
bool cancels(int _power, int _toughness);
int added();
int removed();
};
/* Various families of counters attached to an instance of a card */
class Counters{
public:
int mCount;
Counter * counters[10];
MTGCardInstance * target;
Counters(MTGCardInstance * _target);
~Counters();
int addCounter(const char * _name,int _power = 0, int _toughness = 0);
int addCounter(int _power, int _toughness);
int removeCounter(const char * _name,int _power = 0, int _toughness = 0);
int removeCounter(int _power, int _toughness);
Counter * hasCounter(const char * _name,int _power = 0, int _toughness = 0);
Counter * hasCounter(int _power, int _toughness);
Counter * getNext(Counter * previous = NULL);
};
#endif
#ifndef _COUNTERS_H_
#define _COUNTERS_H_
#include <string>
using std::string;
class MTGCardInstance;
/* One family of counters. Ex : +1/+1 */
class Counter{
public :
string name;
int nb;
int power, toughness;
MTGCardInstance * target;
Counter(MTGCardInstance * _target, int _power, int _toughness);
Counter(MTGCardInstance * _target, const char * _name,int _power = 0 , int _toughness = 0 );
int init(MTGCardInstance * _target,const char * _name, int _power, int _toughness);
bool sameAs(const char * _name, int _power, int _toughness);
bool cancels(int _power, int _toughness);
int added();
int removed();
};
/* Various families of counters attached to an instance of a card */
class Counters{
public:
int mCount;
Counter * counters[10];
MTGCardInstance * target;
Counters(MTGCardInstance * _target);
~Counters();
int addCounter(const char * _name,int _power = 0, int _toughness = 0);
int addCounter(int _power, int _toughness);
int removeCounter(const char * _name,int _power = 0, int _toughness = 0);
int removeCounter(int _power, int _toughness);
Counter * hasCounter(const char * _name,int _power = 0, int _toughness = 0);
Counter * hasCounter(int _power, int _toughness);
Counter * getNext(Counter * previous = NULL);
};
#endif

View File

@@ -14,43 +14,43 @@ class GameObserver;
#define DAMAGEABLE_PLAYER 1
class Damageable {
protected:
protected:
public:
int life;
int type_as_damageable;
Damageable(int _life){life=_life;};
int getLife(){return life;};
virtual int dealDamage(int damage){life-=damage;return life;};
virtual int afterDamage(){return 0;}
virtual JQuad * getIcon(){return NULL;};
public:
int life;
int type_as_damageable;
Damageable(int _life){life=_life;};
int getLife(){return life;};
virtual int dealDamage(int damage){life-=damage;return life;};
virtual int afterDamage(){return 0;}
virtual JQuad * getIcon(){return NULL;};
};
class Damage: public Interruptible {
protected:
void init(MTGCardInstance * _source, Damageable * _target, int _damage);
public:
Damageable * target;
MTGCardInstance * source;
int damage;
void Render();
Damage(int id, MTGCardInstance* _source, Damageable * _target);
Damage(int id, MTGCardInstance* _source, Damageable * _target, int _damage);
int resolve();
protected:
void init(MTGCardInstance * _source, Damageable * _target, int _damage);
public:
Damageable * target;
MTGCardInstance * source;
int damage;
void Render();
Damage(int id, MTGCardInstance* _source, Damageable * _target);
Damage(int id, MTGCardInstance* _source, Damageable * _target, int _damage);
int resolve();
};
class DamageStack :public GuiLayer, public Interruptible{
protected:
int currentState;
protected:
int currentState;
public:
int resolve();
void Render();
int CombatDamages();//Deprecated ?
int CombatDamages(int strike);
DamageStack(int id, GameObserver* _game);
public:
int resolve();
void Render();
int CombatDamages();//Deprecated ?
int CombatDamages(int strike);
DamageStack(int id, GameObserver* _game);
};

View File

@@ -1,38 +1,38 @@
#ifndef _DAMAGERESOLVERLAYER_H_
#define _DAMAGERESOLVERLAYER_H_
#include "../include/PlayGuiObjectController.h"
class MTGCardInstance;
class DamagerDamaged;
class DamageStack;
class DamageResolverLayer:public PlayGuiObjectController{
protected:
int trampleDamage();
public:
int buttonOk;
int currentPhase;
int remainingDamageSteps;
Player * currentChoosingPlayer;
DamageStack * damageStack;
DamagerDamaged * currentSource;
DamageResolverLayer(int id, GameObserver* _game);
int init();
int initResolve();
Player * whoSelectsDamagesDealtBy(MTGCardInstance * card);
int addAutoDamageToOpponents(MTGCardInstance * card);
int addIfNotExists(MTGCardInstance * card, Player * selecter);
int addDamager(MTGCardInstance * card, Player * selecter);
DamagerDamaged * findByCard(MTGCardInstance * card);
int canStopDealDamages();
int resolveDamages();
int isOpponent(DamagerDamaged * a, DamagerDamaged * b);
void nextPlayer();
virtual void Update(float dt);
virtual void CheckUserInput(float dt);
virtual void Render();
};
#endif
#ifndef _DAMAGERESOLVERLAYER_H_
#define _DAMAGERESOLVERLAYER_H_
#include "../include/PlayGuiObjectController.h"
class MTGCardInstance;
class DamagerDamaged;
class DamageStack;
class DamageResolverLayer:public PlayGuiObjectController{
protected:
int trampleDamage();
public:
int buttonOk;
int currentPhase;
int remainingDamageSteps;
Player * currentChoosingPlayer;
DamageStack * damageStack;
DamagerDamaged * currentSource;
DamageResolverLayer(int id, GameObserver* _game);
int init();
int initResolve();
Player * whoSelectsDamagesDealtBy(MTGCardInstance * card);
int addAutoDamageToOpponents(MTGCardInstance * card);
int addIfNotExists(MTGCardInstance * card, Player * selecter);
int addDamager(MTGCardInstance * card, Player * selecter);
DamagerDamaged * findByCard(MTGCardInstance * card);
int canStopDealDamages();
int resolveDamages();
int isOpponent(DamagerDamaged * a, DamagerDamaged * b);
void nextPlayer();
virtual void Update(float dt);
virtual void CheckUserInput(float dt);
virtual void Render();
};
#endif

View File

@@ -1,30 +1,30 @@
#ifndef _DAMAGERDAMAGED_H_
#define _DAMAGERDAMAGED_H_
#include "../include/CardGui.h"
class Player;
class DamagerDamaged:public CardGui{
public:
Player * damageSelecter;
int mCount;
Damage * damages[10];
int damageToDeal;
int dealOneDamage(DamagerDamaged * target);
int addDamage(int damage, DamagerDamaged * source);
int removeDamagesTo(DamagerDamaged * target);
int removeDamagesFrom(DamagerDamaged * source);
int sumDamages();
int hasLethalDamage();
DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus);
~DamagerDamaged();
void Render(Player * currentPlayer);
};
#endif
#ifndef _DAMAGERDAMAGED_H_
#define _DAMAGERDAMAGED_H_
#include "../include/CardGui.h"
class Player;
class DamagerDamaged:public CardGui{
public:
Player * damageSelecter;
int mCount;
Damage * damages[10];
int damageToDeal;
int dealOneDamage(DamagerDamaged * target);
int addDamage(int damage, DamagerDamaged * source);
int removeDamagesTo(DamagerDamaged * target);
int removeDamagesFrom(DamagerDamaged * source);
int sumDamages();
int hasLethalDamage();
DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus);
~DamagerDamaged();
void Render(Player * currentPlayer);
};
#endif

View File

@@ -1,48 +1,48 @@
#ifndef _DECKDATAWRAPPER_H_
#define _DECKDATAWRAPPER_H_
#include "../include/MTGDefinitions.h"
#include "../include/MTGCard.h"
#ifndef _DECKDATAWRAPPER_H_
#define _DECKDATAWRAPPER_H_
#include "../include/MTGDefinitions.h"
#include "../include/MTGCard.h"
#include <map>
#include <string>
using std::map;
using std::string;
class MTGDeck;
class Cmp1 { // compares cards by their name
public:
bool operator()(MTGCard * card1, MTGCard * card2) const {
if (!card2) return true;
if (!card1) return false;
string name1 = card1->name;
string name2 = card2->name;
int result = name1.compare(name2);
if (!result) return card1->getMTGId() < card2->getMTGId();
return ( result < 0);
}
};
class DeckDataWrapper{
public:
int colors[MTG_NB_COLORS+1];
int currentColor;
map<MTGCard *, int,Cmp1> cards;
int currentposition;
MTGDeck * parent;
DeckDataWrapper(MTGDeck * deck);
~DeckDataWrapper();
int Add(MTGCard * card);
int Remove(MTGCard * card);
MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);
void updateCounts(MTGCard * card = NULL, int removed = 0);
void updateCurrentPosition(MTGCard * currentCard,int color = -1);
int getCount(int color = -1);
void save();
};
#endif
using std::map;
using std::string;
class MTGDeck;
class Cmp1 { // compares cards by their name
public:
bool operator()(MTGCard * card1, MTGCard * card2) const {
if (!card2) return true;
if (!card1) return false;
string name1 = card1->name;
string name2 = card2->name;
int result = name1.compare(name2);
if (!result) return card1->getMTGId() < card2->getMTGId();
return ( result < 0);
}
};
class DeckDataWrapper{
public:
int colors[MTG_NB_COLORS+1];
int currentColor;
map<MTGCard *, int,Cmp1> cards;
int currentposition;
MTGDeck * parent;
DeckDataWrapper(MTGDeck * deck);
~DeckDataWrapper();
int Add(MTGCard * card);
int Remove(MTGCard * card);
MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);
void updateCounts(MTGCard * card = NULL, int removed = 0);
void updateCurrentPosition(MTGCard * currentCard,int color = -1);
int getCount(int color = -1);
void save();
};
#endif

View File

@@ -1,34 +1,34 @@
#ifndef _DUELLAYERS_H_
#define _DUELLAYERS_H_
#include "GuiLayers.h"
class MTGGuiHand;
class MTGGuiPlay;
class ActionLayer;
class ActionStack;
class DamageResolverLayer;
class DuelLayers: public GuiLayers{
public:
ActionLayer * actionLayer();
MTGGuiHand * handLayer();
MTGGuiPlay * playLayer();
ActionStack * stackLayer();
DamageResolverLayer * combatLayer();
void init();
};
#include "ActionLayer.h"
#include "GameObserver.h"
#include "MTGGamePhase.h"
#include "MTGGuiHand.h"
#include "MTGGuiPlay.h"
#include "ActionStack.h"
#include "Damage.h"
#endif
#ifndef _DUELLAYERS_H_
#define _DUELLAYERS_H_
#include "GuiLayers.h"
class MTGGuiHand;
class MTGGuiPlay;
class ActionLayer;
class ActionStack;
class DamageResolverLayer;
class DuelLayers: public GuiLayers{
public:
ActionLayer * actionLayer();
MTGGuiHand * handLayer();
MTGGuiPlay * playLayer();
ActionStack * stackLayer();
DamageResolverLayer * combatLayer();
void init();
};
#include "ActionLayer.h"
#include "GameObserver.h"
#include "MTGGamePhase.h"
#include "MTGGuiHand.h"
#include "MTGGuiPlay.h"
#include "ActionStack.h"
#include "Damage.h"
#endif

View File

@@ -1,88 +1,88 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _GAMEAPP_H_
#define _GAMEAPP_H_
#include "../include/Logger.h"
#include <JApp.h>
#include <JGE.h>
#include <JSprite.h>
#include <JLBFont.h>
#include <hge/hgeparticle.h>
#include <JResourceManager.h>
#include "../include/GameState.h"
#include "../include/MTGDeck.h"
#include "../include/MTGCard.h"
#include "../include/MTGGameZones.h"
#include "../include/TexturesCache.h"
#define MAX_STATE 6
#define PLAYER_TYPE_CPU 0
#define PLAYER_TYPE_HUMAN 1
#define PLAYER_TYPE_TESTSUITE 2
class MTGAllCards;
class TexturesCache;
class GameApp: public JApp
{
private:
bool mShowDebugInfo;
int mScreenShotCount;
GameState* mCurrentState;
GameState* mNextState;
GameState* mGameStates[MAX_STATE];
public:
int players[2];
MTGAllCards * collection;
TexturesCache * cache;
GameApp();
virtual ~GameApp();
virtual void Create();
virtual void Destroy();
virtual void Update();
virtual void Render();
virtual void Pause();
virtual void Resume();
void LoadGameStates();
void SetNextState(int state);
static JResourceManager * CommonRes;
static hgeParticleSystem * Particles[6];
static int HasMusic;
};
#endif
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _GAMEAPP_H_
#define _GAMEAPP_H_
#include "../include/Logger.h"
#include <JApp.h>
#include <JGE.h>
#include <JSprite.h>
#include <JLBFont.h>
#include <hge/hgeparticle.h>
#include <JResourceManager.h>
#include "../include/GameState.h"
#include "../include/MTGDeck.h"
#include "../include/MTGCard.h"
#include "../include/MTGGameZones.h"
#include "../include/TexturesCache.h"
#define MAX_STATE 6
#define PLAYER_TYPE_CPU 0
#define PLAYER_TYPE_HUMAN 1
#define PLAYER_TYPE_TESTSUITE 2
class MTGAllCards;
class TexturesCache;
class GameApp: public JApp
{
private:
bool mShowDebugInfo;
int mScreenShotCount;
GameState* mCurrentState;
GameState* mNextState;
GameState* mGameStates[MAX_STATE];
public:
int players[2];
MTGAllCards * collection;
TexturesCache * cache;
GameApp();
virtual ~GameApp();
virtual void Create();
virtual void Destroy();
virtual void Update();
virtual void Render();
virtual void Pause();
virtual void Resume();
void LoadGameStates();
void SetNextState(int state);
static JResourceManager * CommonRes;
static hgeParticleSystem * Particles[6];
static int HasMusic;
};
#endif

View File

@@ -23,49 +23,49 @@ class TargetChooser;
class GameObserver{
protected:
int reaction;
static GameObserver * mInstance;
MTGCardInstance * cardWaitingForTargets;
int reaction;
static GameObserver * mInstance;
MTGCardInstance * cardWaitingForTargets;
int nbPlayers;
int currentPlayerId;
int currentRound;
int targetListIsSet(MTGCardInstance * card);
int targetListIsSet(MTGCardInstance * card);
public:
PhaseRing * phaseRing;
int cancelCurrentAction();
int currentGamePhase;
int oldGamePhase;
TargetChooser * targetChooser;
DuelLayers * mLayers;
Player * gameOver;
Player * players[2]; //created outside
int oldGamePhase;
TargetChooser * targetChooser;
DuelLayers * mLayers;
Player * gameOver;
Player * players[2]; //created outside
MTGGamePhase * gamePhaseManager; //Created Outside ?
TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action);
TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action);
void cardClick(MTGCardInstance * card,Targetable * _object = NULL );
int enteringPhase(int phase);
int getCurrentGamePhase();
void userRequestNextGamePhase();
void nextGamePhase();
void cleanupPhase();
void nextPlayer();
static void Init(Player * _players[], int _nbplayers);
static GameObserver * GetInstance();
static void EndInstance();
void cardClick(MTGCardInstance * card,Targetable * _object = NULL );
int enteringPhase(int phase);
int getCurrentGamePhase();
void userRequestNextGamePhase();
void nextGamePhase();
void cleanupPhase();
void nextPlayer();
static void Init(Player * _players[], int _nbplayers);
static GameObserver * GetInstance();
static void EndInstance();
Player * currentPlayer;
Player * currentActionPlayer;
Player * isInterrupting;
Player * opponent();
Player * currentlyActing();
Player * currentActionPlayer;
Player * isInterrupting;
Player * opponent();
Player * currentlyActing();
GameObserver(Player * _players[], int _nbplayers);
~GameObserver();
~GameObserver();
void setGamePhaseManager(MTGGamePhase * _phases);
void stateEffects();
void stateEffects();
void eventOccured();
void addObserver(MTGAbility * observer);
void removeObserver(ActionElement * observer);
@@ -73,7 +73,7 @@ class GameObserver{
void nextStep();
void untapPhase();
void draw();
int canPutInPlay(MTGCardInstance * card);
int canPutInPlay(MTGCardInstance * card);
void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card);
int isACreature(MTGCardInstance * card);

View File

@@ -1,24 +1,24 @@
#ifndef _GAME_OPTIONS_H_
#define _GAME_OPTIONS_H_
#define MAX_OPTIONS 50
#define OPTIONS_MUSICVOLUME 0
#define OPTIONS_INTERRUPTATENDOFPHASE_OFFSET 1
#define OPTIONS_SAVEFILE "Res/settings/options.txt"
class GameOptions {
public:
int values[MAX_OPTIONS];
static GameOptions * GetInstance();
static void Destroy();
int save();
int load();
private:
GameOptions();
~GameOptions();
static GameOptions* mInstance;
};
#endif
#ifndef _GAME_OPTIONS_H_
#define _GAME_OPTIONS_H_
#define MAX_OPTIONS 50
#define OPTIONS_MUSICVOLUME 0
#define OPTIONS_INTERRUPTATENDOFPHASE_OFFSET 1
#define OPTIONS_SAVEFILE "Res/settings/options.txt"
class GameOptions {
public:
int values[MAX_OPTIONS];
static GameOptions * GetInstance();
static void Destroy();
int save();
int load();
private:
GameOptions();
~GameOptions();
static GameOptions* mInstance;
};
#endif

View File

@@ -1,46 +1,46 @@
#ifndef _GAME_STATE_H_
#define _GAME_STATE_H_
#define FADING_SPEED 350.0f
class JGE;
#include <JSoundSystem.h>
enum _gameSates
{
GAME_STATE_MENU,
GAME_STATE_DUEL,
GAME_STATE_DECK_VIEWER,
GAME_STATE_SHOP,
GAME_STATE_OPTIONS
};
class GameApp;
class GameState
{
protected:
GameApp* mParent;
JGE* mEngine;
public:
static const char * const menuTexts[];
GameState(GameApp* parent);
virtual ~GameState() {}
virtual void Create() {}
virtual void Destroy() {}
virtual void Start() {}
virtual void End() {}
virtual void Update(float dt) = 0;
virtual void Render() = 0;
};
#endif
#ifndef _GAME_STATE_H_
#define _GAME_STATE_H_
#define FADING_SPEED 350.0f
class JGE;
#include <JSoundSystem.h>
enum _gameSates
{
GAME_STATE_MENU,
GAME_STATE_DUEL,
GAME_STATE_DECK_VIEWER,
GAME_STATE_SHOP,
GAME_STATE_OPTIONS
};
class GameApp;
class GameState
{
protected:
GameApp* mParent;
JGE* mEngine;
public:
static const char * const menuTexts[];
GameState(GameApp* parent);
virtual ~GameState() {}
virtual void Create() {}
virtual void Destroy() {}
virtual void Start() {}
virtual void End() {}
virtual void Update(float dt) = 0;
virtual void Render() = 0;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,55 +1,55 @@
#ifndef _GAME_STATE_DUEL_H_
#define _GAME_STATE_DUEL_H_
#include "../include/GameState.h"
#include "_includeAll.h"
#include "../include/SimpleMenu.h"
#define DUEL_START 0
#define DUEL_END 1
#define DUEL_CHOOSE_DECK1 2
#define DUEL_CHOOSE_DECK2 3
#define ERROR_NO_DECK 4
#define DUEL_PLAY 5
#define DUEL_MENU 6
#ifdef TESTSUITE
class TestSuite;
#endif
class GameStateDuel: public GameState, public JGuiListener
{
private:
#ifdef TESTSUITE
TestSuite * testSuite;
#endif
int mGamePhase;
Player * mCurrentPlayer;
Player * mPlayers[2];
MTGPlayerCards * deck[2];
GameObserver * game;
SimpleMenu * deckmenu;
SimpleMenu * menu;
JLBFont* mFont;
void loadPlayer(int playerId, int decknb = 0);
public:
GameStateDuel(GameApp* parent);
virtual ~GameStateDuel();
#ifndef _GAME_STATE_DUEL_H_
#define _GAME_STATE_DUEL_H_
#include "../include/GameState.h"
#include "_includeAll.h"
#include "../include/SimpleMenu.h"
#define DUEL_START 0
#define DUEL_END 1
#define DUEL_CHOOSE_DECK1 2
#define DUEL_CHOOSE_DECK2 3
#define ERROR_NO_DECK 4
#define DUEL_PLAY 5
#define DUEL_MENU 6
#ifdef TESTSUITE
void loadTestSuitePlayers();
#endif
virtual void ButtonPressed(int ControllerId, int ControlId);
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
};
#endif
class TestSuite;
#endif
class GameStateDuel: public GameState, public JGuiListener
{
private:
#ifdef TESTSUITE
TestSuite * testSuite;
#endif
int mGamePhase;
Player * mCurrentPlayer;
Player * mPlayers[2];
MTGPlayerCards * deck[2];
GameObserver * game;
SimpleMenu * deckmenu;
SimpleMenu * menu;
JLBFont* mFont;
void loadPlayer(int playerId, int decknb = 0);
public:
GameStateDuel(GameApp* parent);
virtual ~GameStateDuel();
#ifdef TESTSUITE
void loadTestSuitePlayers();
#endif
virtual void ButtonPressed(int ControllerId, int ControlId);
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
};
#endif

View File

@@ -1,432 +1,432 @@
#ifndef _GAME_STATE_MENU_H_
#define _GAME_STATE_MENU_H_
#include <JGui.h>
#include <dirent.h>
#include "GameState.h"
#include "MenuItem.h"
#include "SimpleMenu.h"
#include "../include/GameOptions.h"
#define STATE_MENU 0
#define STATE_SUBMENU 1
#define STATE_LOADING_MENU 2
#define STATE_LOADING_CARDS 3
#define STATE_FIRST_TIME 4
#define STATE_WARNING 5
#define GAME_VERSION "WTH?! 0.2.2 - by WilLoW"
#define ALPHA_WARNING 0
class GameStateMenu: public GameState, public JGuiListener
{
private:
JGuiController* mGuiController;
SimpleMenu* subMenuController;
JLBFont* mFont;
JQuad * mIcons[10];
JTexture * mIconsTexture;
JTexture * bgTexture;
JQuad * mBg;
float mCreditsYPos;
int currentState;
JMusic * bgMusic;
int mVolume;
char nbcardsStr[400];
DIR *mDip;
struct dirent *mDit;
char mCurrentSetName[10];
char mCurrentSetFileName[512];
int mReadConf;
public:
GameStateMenu(GameApp* parent): GameState(parent)
{
mGuiController = NULL;
subMenuController = NULL;
mIconsTexture = NULL;
bgMusic = NULL;
}
virtual ~GameStateMenu()
{
}
virtual void Create()
{
mDip = NULL;
mReadConf = 0;
mCurrentSetName[0] = 0;
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/menutitle.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 10, 0, 220, 80); // Create background quad for rendering.
mBg->SetHotSpot(105,32);
//load all the icon images
int n = 0;
for (int i=0;i<5;i++)
{
for (int j=0;j<2;j++)
{
mIcons[n] = NEW JQuad(mIconsTexture, 10 + i*32, j*32, 32, 32);
mIcons[n]->SetHotSpot(16,16);
n++;
}
}
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
//mFont->SetBase(0); // using 2nd font
mGuiController = NEW JGuiController(100, this);
//mGuiController->SetShadingBackground(10, 45, 80, 100, ARGB(255,0,0,0));
if (mGuiController)
{
mGuiController->Add(NEW MenuItem(1, mFont, "Play", 80, SCREEN_HEIGHT/2, mIcons[8], mIcons[9],"graphics/particle1.psi",GameApp::CommonRes->GetQuad("particles"), true));
mGuiController->Add(NEW MenuItem(2, mFont, "Deck Editor", 160, SCREEN_HEIGHT/2, mIcons[2], mIcons[3],"graphics/particle2.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(3, mFont, "Shop", 240, SCREEN_HEIGHT/2, mIcons[0], mIcons[1],"graphics/particle3.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(4, mFont, "Options", 320, SCREEN_HEIGHT/2, mIcons[6], mIcons[7],"graphics/particle4.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(5, mFont, "Exit", 400, SCREEN_HEIGHT/2, mIcons[4], mIcons[5],"graphics/particle5.psi",GameApp::CommonRes->GetQuad("particles")));
}
currentState = STATE_LOADING_CARDS;
}
virtual void Destroy()
{
if (mGuiController)
delete mGuiController;
if (subMenuController)
delete subMenuController;
if (mIconsTexture)
delete mIconsTexture;
for (int i = 0; i < 10 ; i++){
delete mIcons[i];
}
if (mBg) delete mBg;
SAFE_DELETE (bgMusic);
}
virtual void Start(){
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
if (GameApp::HasMusic && !bgMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
bgMusic = JSoundSystem::GetInstance()->LoadMusic("sound/track0.mp3");
}
if (bgMusic){
mVolume = 0;
JSoundSystem::GetInstance()->SetVolume(mVolume);
JSoundSystem::GetInstance()->PlayMusic(bgMusic, true);
}
}
/* Retrieves the next set subfolder automatically
*/
int nextCardSet(){
int found = 0;
if (!mDip){
mDip = opendir("Res/sets/");
}
while (!found && (mDit = readdir(mDip))){
sprintf(mCurrentSetFileName, "Res/sets/%s/_cards.dat", mDit->d_name);
std::ifstream file(mCurrentSetFileName);
if(file){
sprintf(mCurrentSetName, "%s", mDit->d_name);
file.close();
found = 1;
}
}
if (!mDit) {
closedir(mDip);
mDip = NULL;
}
return found;
}
virtual void End()
{
//mEngine->EnableVSync(false);
if (bgMusic)
{
JSoundSystem::GetInstance()->StopMusic(bgMusic);
}
JRenderer::GetInstance()->EnableVSync(false);
}
virtual void Update(float dt)
{
if (bgMusic && mVolume < 2*GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME]){
mVolume++;
JSoundSystem::GetInstance()->SetVolume(mVolume/2);
}
if (currentState == STATE_LOADING_CARDS){
if (mReadConf){
mParent->collection->load(mCurrentSetFileName, mCurrentSetName);
}else{
mReadConf = 1;
}
if (!nextCardSet()){
//How many cards total ?
sprintf(nbcardsStr, "Database: %i cards", mParent->collection->totalCards());
//Check for first time comer
std::ifstream file("Res/player/collection.dat");
if(file){
file.close();
currentState = STATE_WARNING;
}else{
currentState = STATE_FIRST_TIME;
}
}
}else if (currentState == STATE_FIRST_TIME){
//Give the player cards from the set for which we have the most variety
int setId = 0;
int maxcards = 0;
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
int value = mParent->collection->countBySet(i);
if (value > maxcards){
maxcards = value;
setId = i;
}
}
createUsersFirstDeck(setId);
currentState = STATE_WARNING;
}else if (currentState == STATE_WARNING){
if (!ALPHA_WARNING){
currentState = STATE_MENU;
}else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) currentState = STATE_MENU;
}
}else{
if (currentState == STATE_MENU && mGuiController!=NULL)
mGuiController->Update(dt);
if (currentState == STATE_SUBMENU){
if( subMenuController != NULL){
subMenuController->Update(dt);
}else{
subMenuController = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
if (subMenuController){
subMenuController->Add(11,"1 Player");
subMenuController->Add(12, "2 Players");
subMenuController->Add(13,"Demo");
subMenuController->Add(14, "Cancel");
#ifdef TESTSUITE
subMenuController->Add(666, "Test Suite");
#endif
}
}
}
}
if (currentState == STATE_WARNING && !ALPHA_WARNING) currentState = STATE_MENU;
}
void createUsersFirstDeck(int setId){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "setID: %i", setId);
OutputDebugString(buf);
#endif
MTGDeck *mCollection = NEW MTGDeck("Res/player/collection.dat", mParent->cache, mParent->collection);
//10 lands of each
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Forest")){
mCollection->addRandomCards(10, -1,RARITY_L,"Forest");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Plains")){
mCollection->addRandomCards(10, -1,RARITY_L,"Plains");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Swamp")){
mCollection->addRandomCards(10, -1,RARITY_L,"Swamp");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Mountain")){
mCollection->addRandomCards(10, -1,RARITY_L,"Mountain");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Island")){
mCollection->addRandomCards(10, -1,RARITY_L,"Island");
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString("1\n");
#endif
//Starter Deck
mCollection->addRandomCards(3, setId,RARITY_R,NULL);
mCollection->addRandomCards(9, setId,RARITY_U,NULL);
mCollection->addRandomCards(48, setId,RARITY_C,NULL);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("2\n");
#endif
//Boosters
for (int i = 0; i< 2; i++){
mCollection->addRandomCards(1, setId,RARITY_R);
mCollection->addRandomCards(3, setId,RARITY_U);
mCollection->addRandomCards(11, setId,RARITY_C);
}
mCollection->save();
delete mCollection;
}
virtual void Render()
{
JRenderer * renderer = JRenderer::GetInstance();
renderer->ClearScreen(ARGB(0,0,0,0));
if (currentState == STATE_LOADING_CARDS){
char text[512];
sprintf(text, "LOADING SET: %s", mCurrentSetName);
mFont->DrawString(text,SCREEN_WIDTH/2,SCREEN_HEIGHT/2,JGETEXT_CENTER);
}else{
PIXEL_TYPE colors[] =
{
ARGB(255,17,17,17),
ARGB(255,17,17,17),
ARGB(255,62,62,62),
ARGB(255,62,62,62)
};
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,colors);
renderer->RenderQuad(mBg, SCREEN_WIDTH/2 , 50);
if (mGuiController!=NULL)
mGuiController->Render();
mFont->SetScale(0.7);
mFont->SetColor(ARGB(128,255,255,255));
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,SCREEN_HEIGHT-15,JGETEXT_RIGHT);
mFont->DrawString(nbcardsStr,10, SCREEN_HEIGHT-15);
mFont->SetScale(1.f);
mFont->SetColor(ARGB(255,255,255,255));
if (currentState == STATE_SUBMENU && subMenuController != NULL){
subMenuController->Render();
}
if (currentState == STATE_WARNING){
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(128,0,0,0));
mFont->DrawString("IMPORTANT NOTE" ,SCREEN_WIDTH/2,10,JGETEXT_CENTER);
mFont->DrawString("This is an alpha version with lots of bugs.",SCREEN_WIDTH/2,35,JGETEXT_CENTER);
mFont->DrawString("It WILL crash your psp" ,SCREEN_WIDTH/2,50,JGETEXT_CENTER);
mFont->DrawString("If you use it anyway, your feedback is welcome" ,SCREEN_WIDTH/2,65,JGETEXT_CENTER);
mFont->DrawString("This freeware game is NOT published or endorsed" ,SCREEN_WIDTH/2,110,JGETEXT_CENTER);
mFont->DrawString("by Wizard of the Coast, Inc." ,SCREEN_WIDTH/2,125,JGETEXT_CENTER);
mFont->DrawString("Infos & updates at http://wololo.net/wagic/" ,SCREEN_WIDTH/2,170,JGETEXT_CENTER);
mFont->DrawString("PRESS CIRCLE TO CONTINUE OR HOME TO QUIT" ,SCREEN_WIDTH/2,210,JGETEXT_CENTER);
}
}
}
virtual void ButtonPressed(int controllerId, int controlId)
{
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "cnotrollerId: %i", controllerId);
OutputDebugString(buf);
#endif
switch (controllerId){
case 101:
createUsersFirstDeck(controlId);
currentState = STATE_MENU;
SAFE_DELETE(subMenuController);
break;
default:
switch (controlId)
{
case 1:
currentState = STATE_SUBMENU;
break;
case 2:
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
break;
case 3:
mParent->SetNextState(GAME_STATE_SHOP);
break;
case 4:
mParent->SetNextState(GAME_STATE_OPTIONS);
break;
case 5:
mEngine->End();
break;
case 11:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 12:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_HUMAN;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 13:
mParent->players[0] = PLAYER_TYPE_CPU;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 14:
currentState = STATE_MENU;
delete subMenuController;
subMenuController = NULL;
break;
#ifdef TESTSUITE
case 666:
mParent->players[0] = PLAYER_TYPE_TESTSUITE;
mParent->players[1] = PLAYER_TYPE_TESTSUITE;
mParent->SetNextState(GAME_STATE_DUEL);
break;
#endif
}
break;
}
}
};
#endif
#ifndef _GAME_STATE_MENU_H_
#define _GAME_STATE_MENU_H_
#include <JGui.h>
#include <dirent.h>
#include "GameState.h"
#include "MenuItem.h"
#include "SimpleMenu.h"
#include "../include/GameOptions.h"
#define STATE_MENU 0
#define STATE_SUBMENU 1
#define STATE_LOADING_MENU 2
#define STATE_LOADING_CARDS 3
#define STATE_FIRST_TIME 4
#define STATE_WARNING 5
#define GAME_VERSION "WTH?! 0.2.2 - by WilLoW"
#define ALPHA_WARNING 0
class GameStateMenu: public GameState, public JGuiListener
{
private:
JGuiController* mGuiController;
SimpleMenu* subMenuController;
JLBFont* mFont;
JQuad * mIcons[10];
JTexture * mIconsTexture;
JTexture * bgTexture;
JQuad * mBg;
float mCreditsYPos;
int currentState;
JMusic * bgMusic;
int mVolume;
char nbcardsStr[400];
DIR *mDip;
struct dirent *mDit;
char mCurrentSetName[10];
char mCurrentSetFileName[512];
int mReadConf;
public:
GameStateMenu(GameApp* parent): GameState(parent)
{
mGuiController = NULL;
subMenuController = NULL;
mIconsTexture = NULL;
bgMusic = NULL;
}
virtual ~GameStateMenu()
{
}
virtual void Create()
{
mDip = NULL;
mReadConf = 0;
mCurrentSetName[0] = 0;
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/menutitle.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 10, 0, 220, 80); // Create background quad for rendering.
mBg->SetHotSpot(105,32);
//load all the icon images
int n = 0;
for (int i=0;i<5;i++)
{
for (int j=0;j<2;j++)
{
mIcons[n] = NEW JQuad(mIconsTexture, 10 + i*32, j*32, 32, 32);
mIcons[n]->SetHotSpot(16,16);
n++;
}
}
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
//mFont->SetBase(0); // using 2nd font
mGuiController = NEW JGuiController(100, this);
//mGuiController->SetShadingBackground(10, 45, 80, 100, ARGB(255,0,0,0));
if (mGuiController)
{
mGuiController->Add(NEW MenuItem(1, mFont, "Play", 80, SCREEN_HEIGHT/2, mIcons[8], mIcons[9],"graphics/particle1.psi",GameApp::CommonRes->GetQuad("particles"), true));
mGuiController->Add(NEW MenuItem(2, mFont, "Deck Editor", 160, SCREEN_HEIGHT/2, mIcons[2], mIcons[3],"graphics/particle2.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(3, mFont, "Shop", 240, SCREEN_HEIGHT/2, mIcons[0], mIcons[1],"graphics/particle3.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(4, mFont, "Options", 320, SCREEN_HEIGHT/2, mIcons[6], mIcons[7],"graphics/particle4.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(5, mFont, "Exit", 400, SCREEN_HEIGHT/2, mIcons[4], mIcons[5],"graphics/particle5.psi",GameApp::CommonRes->GetQuad("particles")));
}
currentState = STATE_LOADING_CARDS;
}
virtual void Destroy()
{
if (mGuiController)
delete mGuiController;
if (subMenuController)
delete subMenuController;
if (mIconsTexture)
delete mIconsTexture;
for (int i = 0; i < 10 ; i++){
delete mIcons[i];
}
if (mBg) delete mBg;
SAFE_DELETE (bgMusic);
}
virtual void Start(){
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
if (GameApp::HasMusic && !bgMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
bgMusic = JSoundSystem::GetInstance()->LoadMusic("sound/track0.mp3");
}
if (bgMusic){
mVolume = 0;
JSoundSystem::GetInstance()->SetVolume(mVolume);
JSoundSystem::GetInstance()->PlayMusic(bgMusic, true);
}
}
/* Retrieves the next set subfolder automatically
*/
int nextCardSet(){
int found = 0;
if (!mDip){
mDip = opendir("Res/sets/");
}
while (!found && (mDit = readdir(mDip))){
sprintf(mCurrentSetFileName, "Res/sets/%s/_cards.dat", mDit->d_name);
std::ifstream file(mCurrentSetFileName);
if(file){
sprintf(mCurrentSetName, "%s", mDit->d_name);
file.close();
found = 1;
}
}
if (!mDit) {
closedir(mDip);
mDip = NULL;
}
return found;
}
virtual void End()
{
//mEngine->EnableVSync(false);
if (bgMusic)
{
JSoundSystem::GetInstance()->StopMusic(bgMusic);
}
JRenderer::GetInstance()->EnableVSync(false);
}
virtual void Update(float dt)
{
if (bgMusic && mVolume < 2*GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME]){
mVolume++;
JSoundSystem::GetInstance()->SetVolume(mVolume/2);
}
if (currentState == STATE_LOADING_CARDS){
if (mReadConf){
mParent->collection->load(mCurrentSetFileName, mCurrentSetName);
}else{
mReadConf = 1;
}
if (!nextCardSet()){
//How many cards total ?
sprintf(nbcardsStr, "Database: %i cards", mParent->collection->totalCards());
//Check for first time comer
std::ifstream file("Res/player/collection.dat");
if(file){
file.close();
currentState = STATE_WARNING;
}else{
currentState = STATE_FIRST_TIME;
}
}
}else if (currentState == STATE_FIRST_TIME){
//Give the player cards from the set for which we have the most variety
int setId = 0;
int maxcards = 0;
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
int value = mParent->collection->countBySet(i);
if (value > maxcards){
maxcards = value;
setId = i;
}
}
createUsersFirstDeck(setId);
currentState = STATE_WARNING;
}else if (currentState == STATE_WARNING){
if (!ALPHA_WARNING){
currentState = STATE_MENU;
}else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) currentState = STATE_MENU;
}
}else{
if (currentState == STATE_MENU && mGuiController!=NULL)
mGuiController->Update(dt);
if (currentState == STATE_SUBMENU){
if( subMenuController != NULL){
subMenuController->Update(dt);
}else{
subMenuController = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
if (subMenuController){
subMenuController->Add(11,"1 Player");
subMenuController->Add(12, "2 Players");
subMenuController->Add(13,"Demo");
subMenuController->Add(14, "Cancel");
#ifdef TESTSUITE
subMenuController->Add(666, "Test Suite");
#endif
}
}
}
}
if (currentState == STATE_WARNING && !ALPHA_WARNING) currentState = STATE_MENU;
}
void createUsersFirstDeck(int setId){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "setID: %i", setId);
OutputDebugString(buf);
#endif
MTGDeck *mCollection = NEW MTGDeck("Res/player/collection.dat", mParent->cache, mParent->collection);
//10 lands of each
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Forest")){
mCollection->addRandomCards(10, -1,RARITY_L,"Forest");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Plains")){
mCollection->addRandomCards(10, -1,RARITY_L,"Plains");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Swamp")){
mCollection->addRandomCards(10, -1,RARITY_L,"Swamp");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Mountain")){
mCollection->addRandomCards(10, -1,RARITY_L,"Mountain");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Island")){
mCollection->addRandomCards(10, -1,RARITY_L,"Island");
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString("1\n");
#endif
//Starter Deck
mCollection->addRandomCards(3, setId,RARITY_R,NULL);
mCollection->addRandomCards(9, setId,RARITY_U,NULL);
mCollection->addRandomCards(48, setId,RARITY_C,NULL);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("2\n");
#endif
//Boosters
for (int i = 0; i< 2; i++){
mCollection->addRandomCards(1, setId,RARITY_R);
mCollection->addRandomCards(3, setId,RARITY_U);
mCollection->addRandomCards(11, setId,RARITY_C);
}
mCollection->save();
delete mCollection;
}
virtual void Render()
{
JRenderer * renderer = JRenderer::GetInstance();
renderer->ClearScreen(ARGB(0,0,0,0));
if (currentState == STATE_LOADING_CARDS){
char text[512];
sprintf(text, "LOADING SET: %s", mCurrentSetName);
mFont->DrawString(text,SCREEN_WIDTH/2,SCREEN_HEIGHT/2,JGETEXT_CENTER);
}else{
PIXEL_TYPE colors[] =
{
ARGB(255,17,17,17),
ARGB(255,17,17,17),
ARGB(255,62,62,62),
ARGB(255,62,62,62)
};
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,colors);
renderer->RenderQuad(mBg, SCREEN_WIDTH/2 , 50);
if (mGuiController!=NULL)
mGuiController->Render();
mFont->SetScale(0.7);
mFont->SetColor(ARGB(128,255,255,255));
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,SCREEN_HEIGHT-15,JGETEXT_RIGHT);
mFont->DrawString(nbcardsStr,10, SCREEN_HEIGHT-15);
mFont->SetScale(1.f);
mFont->SetColor(ARGB(255,255,255,255));
if (currentState == STATE_SUBMENU && subMenuController != NULL){
subMenuController->Render();
}
if (currentState == STATE_WARNING){
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(128,0,0,0));
mFont->DrawString("IMPORTANT NOTE" ,SCREEN_WIDTH/2,10,JGETEXT_CENTER);
mFont->DrawString("This is an alpha version with lots of bugs.",SCREEN_WIDTH/2,35,JGETEXT_CENTER);
mFont->DrawString("It WILL crash your psp" ,SCREEN_WIDTH/2,50,JGETEXT_CENTER);
mFont->DrawString("If you use it anyway, your feedback is welcome" ,SCREEN_WIDTH/2,65,JGETEXT_CENTER);
mFont->DrawString("This freeware game is NOT published or endorsed" ,SCREEN_WIDTH/2,110,JGETEXT_CENTER);
mFont->DrawString("by Wizard of the Coast, Inc." ,SCREEN_WIDTH/2,125,JGETEXT_CENTER);
mFont->DrawString("Infos & updates at http://wololo.net/wagic/" ,SCREEN_WIDTH/2,170,JGETEXT_CENTER);
mFont->DrawString("PRESS CIRCLE TO CONTINUE OR HOME TO QUIT" ,SCREEN_WIDTH/2,210,JGETEXT_CENTER);
}
}
}
virtual void ButtonPressed(int controllerId, int controlId)
{
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "cnotrollerId: %i", controllerId);
OutputDebugString(buf);
#endif
switch (controllerId){
case 101:
createUsersFirstDeck(controlId);
currentState = STATE_MENU;
SAFE_DELETE(subMenuController);
break;
default:
switch (controlId)
{
case 1:
currentState = STATE_SUBMENU;
break;
case 2:
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
break;
case 3:
mParent->SetNextState(GAME_STATE_SHOP);
break;
case 4:
mParent->SetNextState(GAME_STATE_OPTIONS);
break;
case 5:
mEngine->End();
break;
case 11:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 12:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_HUMAN;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 13:
mParent->players[0] = PLAYER_TYPE_CPU;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 14:
currentState = STATE_MENU;
delete subMenuController;
subMenuController = NULL;
break;
#ifdef TESTSUITE
case 666:
mParent->players[0] = PLAYER_TYPE_TESTSUITE;
mParent->players[1] = PLAYER_TYPE_TESTSUITE;
mParent->SetNextState(GAME_STATE_DUEL);
break;
#endif
}
break;
}
}
};
#endif

View File

@@ -1,34 +1,34 @@
#ifndef _GAME_STATE_OPTIONS_H_
#define _GAME_STATE_OPTIONS_H_
#include <JGui.h>
#include "../include/GameState.h"
#define SHOW_OPTIONS 1
#define SHOW_OPTIONS_MENU 2
class GameApp;
class OptionsList;
class SimpleMenu;
class GameStateOptions: public GameState, public JGuiListener
{
public:
SimpleMenu * optionsMenu;
int mState;
OptionsList * optionsList;
GameStateOptions(GameApp* parent);
virtual ~GameStateOptions();
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
void ButtonPressed(int controllerId, int ControlId);
};
#endif
#ifndef _GAME_STATE_OPTIONS_H_
#define _GAME_STATE_OPTIONS_H_
#include <JGui.h>
#include "../include/GameState.h"
#define SHOW_OPTIONS 1
#define SHOW_OPTIONS_MENU 2
class GameApp;
class OptionsList;
class SimpleMenu;
class GameStateOptions: public GameState, public JGuiListener
{
public:
SimpleMenu * optionsMenu;
int mState;
OptionsList * optionsList;
GameStateOptions(GameApp* parent);
virtual ~GameStateOptions();
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
void ButtonPressed(int controllerId, int ControlId);
};
#endif

View File

@@ -1,46 +1,46 @@
#ifndef _GAME_STATE_SHOP_H_
#define _GAME_STATE_SHOP_H_
#include <JGE.h>
#include "../include/GameState.h"
#include "../include/SimpleMenu.h"
#include "../include/ShopItem.h"
#define STATE_BUY 1
#define STATE_SELL 2
#define STAGE_SHOP_MENU 3
#define STAGE_SHOP_SHOP 4
class GameStateShop: public GameState, public JGuiListener
{
private:
ShopItems * shop;
JLBFont * mFont;
JQuad * mBg;
JTexture * bgTexture;
JQuad * mBack;
JTexture * backTexture;
SimpleMenu * menu;
int mStage;
char starterBuffer[128], boosterBuffer[128];
int setId;
public:
GameStateShop(GameApp* parent);
virtual ~GameStateShop();
virtual void Start();
virtual void End();
virtual void Create();
virtual void Destroy();
virtual void Update(float dt);
virtual void Render();
virtual void ButtonPressed(int controllerId, int controlId);
};
#endif
#ifndef _GAME_STATE_SHOP_H_
#define _GAME_STATE_SHOP_H_
#include <JGE.h>
#include "../include/GameState.h"
#include "../include/SimpleMenu.h"
#include "../include/ShopItem.h"
#define STATE_BUY 1
#define STATE_SELL 2
#define STAGE_SHOP_MENU 3
#define STAGE_SHOP_SHOP 4
class GameStateShop: public GameState, public JGuiListener
{
private:
ShopItems * shop;
JLBFont * mFont;
JQuad * mBg;
JTexture * bgTexture;
JQuad * mBack;
JTexture * backTexture;
SimpleMenu * menu;
int mStage;
char starterBuffer[128], boosterBuffer[128];
int setId;
public:
GameStateShop(GameApp* parent);
virtual ~GameStateShop();
virtual void Start();
virtual void End();
virtual void Create();
virtual void Destroy();
virtual void Update(float dt);
virtual void Render();
virtual void ButtonPressed(int controllerId, int controlId);
};
#endif

View File

@@ -5,8 +5,8 @@
#include "PlayGuiObjectController.h"
class GuiCardsController : public PlayGuiObjectController{
public:
GuiCardsController(int id, GameObserver* _game):PlayGuiObjectController(id, _game){};
public:
GuiCardsController(int id, GameObserver* _game):PlayGuiObjectController(id, _game){};
};

View File

@@ -20,9 +20,9 @@ class GuiLayer: public JGuiController{
GameObserver * game;
public:
virtual void resetObjects();
int hasFocus;
int getMaxId();
void RenderMessageBackground(float x0, float y0, float width, int height);
int hasFocus;
int getMaxId();
void RenderMessageBackground(float x0, float y0, float width, int height);
void RenderMessageBackground(float y0, int height);
GuiLayer(int id, GameObserver* _game);
virtual int isModal();
@@ -34,10 +34,10 @@ class GuiLayer: public JGuiController{
int getIndexOf(JGuiObject * object);
JGuiObject * getByIndex (int index);
virtual void Render(){JGuiController::Render();};
int empty(){
if (mCount) return 0;
return 1;
};
int empty(){
if (mCount) return 0;
return 1;
};
};
class GuiLayers{

View File

@@ -1,20 +1,20 @@
#ifndef _LOGGER_H
#define _LOGGER_H_
#ifdef DOLOG
#define LOG(x) Logger::Log(x);
#else
#define LOG(x)
#endif
#define LOG_FILE "Res/debug.txt"
class Logger{
public:
static void Log(char * text);
};
#endif
#ifndef _LOGGER_H
#define _LOGGER_H_
#ifdef DOLOG
#define LOG(x) Logger::Log(x);
#else
#define LOG(x)
#endif
#define LOG_FILE "Res/debug.txt"
class Logger{
public:
static void Log(char * text);
};
#endif

View File

@@ -1,118 +1,118 @@
#ifndef _MTGABILITY_H_
#define _MTGABILITY_H_
class MTGCardInstance;
class GameObserver;
class Spell;
class Damageable;
class PlayGuiObject;
class TargetChooser;
class ManaCost;
class MTGGameZone;
class Player;
#include "ActionElement.h"
#include <string>
#include <map>
using std::string;
using std::map;
#define BAKA_EFFECT_GOOD 10
#define BAKA_EFFECT_BAD 11
class AbilityFactory{
private:
int destroyAllFromTypeInPlay(const char * type, MTGCardInstance * source, int bury = 0);
int destroyAllFromColorInPlay(int color, MTGCardInstance * source, int bury = 0);
int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p);
public:
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL);
void addAbilities(int _id, Spell * spell);
};
class MTGAbility: public ActionElement{
protected:
char menuText[25];
Damageable * target;
GameObserver * game;
public:
MTGCardInstance * source;
MTGAbility(int id, MTGCardInstance * card);
MTGAbility(int id, MTGCardInstance * _source, Damageable * _target);
virtual int testDestroy();
virtual ~MTGAbility();
virtual void Render(){};
virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual void Update(float dt){};
virtual int fireAbility();
virtual int resolve(){return 0;};
};
class TriggeredAbility:public MTGAbility{
public:
TriggeredAbility(int id, MTGCardInstance * card);
TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target);
virtual void Update(float dt);
virtual void Render(){};
virtual int trigger()=0;
virtual int resolve() = 0;
};
class ActivatedAbility:public MTGAbility{
public:
ManaCost * cost;
int playerturnonly;
int needsTapping;
ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual int reactToClick(MTGCardInstance * card);
virtual int isReactingToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual int resolve() = 0;
virtual ~ActivatedAbility();
};
class TargetAbility:public ActivatedAbility{
public:
TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual void Update(float dt);
virtual int reactToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual void Render();
};
class InstantAbility:public MTGAbility{
public:
int init;
virtual void Update(float dt);
virtual int testDestroy();
InstantAbility(int _id, MTGCardInstance * source);
InstantAbility(int _id, MTGCardInstance * source,Damageable * _target);
virtual int resolve(){return 0;};
};
/* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */
class ListMaintainerAbility:public MTGAbility{
public:
map<MTGCardInstance *,bool> cards;
ListMaintainerAbility(int _id):MTGAbility(_id,NULL){};
ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){};
ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){};
virtual void Update(float dt);
virtual int canBeInList(MTGCardInstance * card) = 0;
virtual int added(MTGCardInstance * card) = 0;
virtual int removed(MTGCardInstance * card) = 0;
virtual int destroy();
};
#include "MTGCardInstance.h"
#endif
#ifndef _MTGABILITY_H_
#define _MTGABILITY_H_
class MTGCardInstance;
class GameObserver;
class Spell;
class Damageable;
class PlayGuiObject;
class TargetChooser;
class ManaCost;
class MTGGameZone;
class Player;
#include "ActionElement.h"
#include <string>
#include <map>
using std::string;
using std::map;
#define BAKA_EFFECT_GOOD 10
#define BAKA_EFFECT_BAD 11
class AbilityFactory{
private:
int destroyAllFromTypeInPlay(const char * type, MTGCardInstance * source, int bury = 0);
int destroyAllFromColorInPlay(int color, MTGCardInstance * source, int bury = 0);
int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p);
public:
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL);
void addAbilities(int _id, Spell * spell);
};
class MTGAbility: public ActionElement{
protected:
char menuText[25];
Damageable * target;
GameObserver * game;
public:
MTGCardInstance * source;
MTGAbility(int id, MTGCardInstance * card);
MTGAbility(int id, MTGCardInstance * _source, Damageable * _target);
virtual int testDestroy();
virtual ~MTGAbility();
virtual void Render(){};
virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual void Update(float dt){};
virtual int fireAbility();
virtual int resolve(){return 0;};
};
class TriggeredAbility:public MTGAbility{
public:
TriggeredAbility(int id, MTGCardInstance * card);
TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target);
virtual void Update(float dt);
virtual void Render(){};
virtual int trigger()=0;
virtual int resolve() = 0;
};
class ActivatedAbility:public MTGAbility{
public:
ManaCost * cost;
int playerturnonly;
int needsTapping;
ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual int reactToClick(MTGCardInstance * card);
virtual int isReactingToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual int resolve() = 0;
virtual ~ActivatedAbility();
};
class TargetAbility:public ActivatedAbility{
public:
TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual void Update(float dt);
virtual int reactToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual void Render();
};
class InstantAbility:public MTGAbility{
public:
int init;
virtual void Update(float dt);
virtual int testDestroy();
InstantAbility(int _id, MTGCardInstance * source);
InstantAbility(int _id, MTGCardInstance * source,Damageable * _target);
virtual int resolve(){return 0;};
};
/* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */
class ListMaintainerAbility:public MTGAbility{
public:
map<MTGCardInstance *,bool> cards;
ListMaintainerAbility(int _id):MTGAbility(_id,NULL){};
ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){};
ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){};
virtual void Update(float dt);
virtual int canBeInList(MTGCardInstance * card) = 0;
virtual int added(MTGCardInstance * card) = 0;
virtual int removed(MTGCardInstance * card) = 0;
virtual int destroy();
};
#include "MTGCardInstance.h"
#endif

View File

@@ -1,119 +1,119 @@
#ifndef _MTGCARD_H_
#define _MTGCARD_H_
#define MTGCARD_NAME_SIZE 30
#define MTGCARD_TEXT_SIZE 300
#define MTG_IMAGE_WIDTH 200
#define MTG_IMAGE_HEIGHT 285
#define MAX_TYPES_PER_CARD 10
#include "ManaCost.h"
class TexturesCache;
#include <string>
#include <vector>
using namespace std;
class MTGCard {
protected:
int mtgid;
TexturesCache * mCache;
ManaCost manaCost;
char rarity;
char image_name[MTGCARD_NAME_SIZE];
int init();
public:
string text;
string name;
int colors[MTG_NB_COLORS];
int basicAbilities[NB_BASIC_ABILITIES];
vector<string> formattedText;
string magicText;
int alias;
string spellTargetType;
int formattedTextInit;
int power;
int toughness;
int setId;
static const char * const Colors_To_Text[];
int nb_types;
int types[MAX_TYPES_PER_CARD];
MTGCard();
MTGCard(TexturesCache * cache, int set_id);
MTGCard(MTGCard * source);
JQuad * getQuad(TexturesCache * cache);
JQuad * getQuad(int type=1);
JQuad * getThumb();
void setColor(int _color, int removeAllOthers = 0);
int getColor();
int hasColor(int _color);
const char * colorToString();
void setMTGId(int id);
int getMTGId();
int getId();
int has(int ability);
char getRarity();
void setRarity(char _rarity);
const char * getSetName();
//void setImageName( char * value);
char * getImageName ();
void setText( string value);
const char * getText();
void addMagicText(string value);
void setName( string value);
const char * getName();
void addType(char * type_text);
void addType(int id);
void setType(const char * type_text);
void setSubtype( string value);
int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0);
int hasSubtype(int _subtype);
int hasSubtype(const char * _subtype);
int hasSubtype(string _subtype);
int hasType(int _type);
int hasType(const char * type);
void setManaCost(string value);
ManaCost * getManaCost();
int isACreature();
void setPower(int _power);
int getPower();
void setToughness(int _toughness);
int getToughness();
};
#endif
#ifndef _MTGCARD_H_
#define _MTGCARD_H_
#define MTGCARD_NAME_SIZE 30
#define MTGCARD_TEXT_SIZE 300
#define MTG_IMAGE_WIDTH 200
#define MTG_IMAGE_HEIGHT 285
#define MAX_TYPES_PER_CARD 10
#include "ManaCost.h"
class TexturesCache;
#include <string>
#include <vector>
using namespace std;
class MTGCard {
protected:
int mtgid;
TexturesCache * mCache;
ManaCost manaCost;
char rarity;
char image_name[MTGCARD_NAME_SIZE];
int init();
public:
string text;
string name;
int colors[MTG_NB_COLORS];
int basicAbilities[NB_BASIC_ABILITIES];
vector<string> formattedText;
string magicText;
int alias;
string spellTargetType;
int formattedTextInit;
int power;
int toughness;
int setId;
static const char * const Colors_To_Text[];
int nb_types;
int types[MAX_TYPES_PER_CARD];
MTGCard();
MTGCard(TexturesCache * cache, int set_id);
MTGCard(MTGCard * source);
JQuad * getQuad(TexturesCache * cache);
JQuad * getQuad(int type=1);
JQuad * getThumb();
void setColor(int _color, int removeAllOthers = 0);
int getColor();
int hasColor(int _color);
const char * colorToString();
void setMTGId(int id);
int getMTGId();
int getId();
int has(int ability);
char getRarity();
void setRarity(char _rarity);
const char * getSetName();
//void setImageName( char * value);
char * getImageName ();
void setText( string value);
const char * getText();
void addMagicText(string value);
void setName( string value);
const char * getName();
void addType(char * type_text);
void addType(int id);
void setType(const char * type_text);
void setSubtype( string value);
int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0);
int hasSubtype(int _subtype);
int hasSubtype(const char * _subtype);
int hasSubtype(string _subtype);
int hasType(int _type);
int hasType(const char * type);
void setManaCost(string value);
ManaCost * getManaCost();
int isACreature();
void setPower(int _power);
int getPower();
void setToughness(int _toughness);
int getToughness();
};
#endif

View File

@@ -25,68 +25,68 @@ class Counters;
class MTGCardInstance: public MTGCard, public Damageable, public Targetable {
protected:
int untapping;
int untapping;
int nb_damages;
int lifeOrig;
Blockers * blockers;
int lifeOrig;
Blockers * blockers;
MTGPlayerCards * belongs_to;
MTGAbility * UntapBlockers[10];
void unband();
MTGCardInstance * getNextPartner();
void initMTGCI();
void unband();
MTGCardInstance * getNextPartner();
void initMTGCI();
public:
MTGGameZone * getCurrentZone();
int doDamageTest;
int summoningSickness;
// The recommended method to test for summoning Sickness !
int hasSummoningSickness();
int changeController(Player * newcontroller);
MTGCardInstance * defenser;
float changedZoneRecently;
Player * owner;
Counters * counters;
int typeAsTarget(){return TARGET_CARD;}
int attacker;
MTGCardInstance * banding; // If belongs to a band when attacking
MTGGameZone * getCurrentZone();
int doDamageTest;
int summoningSickness;
// The recommended method to test for summoning Sickness !
int hasSummoningSickness();
int changeController(Player * newcontroller);
MTGCardInstance * defenser;
float changedZoneRecently;
Player * owner;
Counters * counters;
int typeAsTarget(){return TARGET_CARD;}
int attacker;
MTGCardInstance * banding; // If belongs to a band when attacking
MTGCardInstance * target;
int tapped;
void addType(int type);
int canBlock();
int canBlock(MTGCardInstance * opponent);
int canAttack();
int tapped;
void addType(int type);
int canBlock();
int canBlock(MTGCardInstance * opponent);
int canAttack();
int afterDamage();
void setUntapping();
int isUntapping();
int has(int ability);
int cleanup();
int reset();
int isAttacker();
MTGCardInstance * isDefenser();
int toggleDefenser(MTGCardInstance * opponent);
int toggleAttacker();
void setUntapping();
int isUntapping();
int has(int ability);
int cleanup();
int reset();
int isAttacker();
MTGCardInstance * isDefenser();
int toggleDefenser(MTGCardInstance * opponent);
int toggleAttacker();
MTGCard * model;
MTGCardInstance();
MTGCardInstance();
MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to);
Blockers * getBlockers();
Blockers * getBlockers();
void regenerate();
Player * controller();
JQuad * getIcon();
int initAttackersDefensers();
MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL);
int nbOpponents();
~MTGCardInstance();
Player * controller();
JQuad * getIcon();
int initAttackersDefensers();
MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL);
int nbOpponents();
~MTGCardInstance();
int addToToughness(int value);
int setToughness(int value);
int addToToughness(int value);
int setToughness(int value);
CardDescriptor * protections[10];
int nbprotections;
int addProtection(CardDescriptor * cd);
int removeProtection(CardDescriptor *cd, int erase = 0);
int protectedAgainst(MTGCardInstance * card);
CardDescriptor * protections[10];
int nbprotections;
int addProtection(CardDescriptor * cd);
int removeProtection(CardDescriptor *cd, int erase = 0);
int protectedAgainst(MTGCardInstance * card);
// in game
int isTapped();

View File

@@ -1,91 +1,91 @@
#ifndef _MTGDECK_H_
#define _MTGDECK_H_
#define MTG_ERROR -1
#include "../include/MTGDefinitions.h"
#include "../include/GameApp.h"
#include "../include/TexturesCache.h"
#include <string>
using std::string;
class GameApp;
class MTGCard;
#define MAX_SETS 30
class MtgSets{
protected:
public:
int nb_items;
string values[MAX_SETS];
public:
static MtgSets * SetsList;
MtgSets();
int Add(const char * subtype);
};
class MTGAllCards {
protected:
int conf_read_mode;
int conf_fd;
char * conf_buffer;
int read_cursor;
int colorsCount[MTG_NB_COLORS];
int total_cards;
GameApp * parent;
void init();
void initCounters();
public:
TexturesCache * mCache;
MTGCard * _(int i);
MTGCard * collection[TOTAL_NUMBER_OF_CARDS];
MTGAllCards();
~MTGAllCards();
MTGAllCards(TexturesCache * cache);
void destroyAllCards();
MTGAllCards(const char * config_file, const char * set_name);
MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache);
MTGCard * getCardById(int id);
int load(const char * config_file, const char * setName, int autoload = 1);
int countByType(const char * _type);
int countByColor(int color);
int countBySet(int setId);
int readConfLine(int set_id);
int totalCards();
int randomCardId();
private:
int processConfLine(char* file, MTGCard* card);
};
class MTGDeck:public MTGAllCards{
protected:
string filename;
MTGAllCards * allcards;
public:
MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards);
int addRandomCards(int howmany, int setId = -1, int rarity = -1, const char * subtype = NULL);
int add(int cardid);
int remove(int cardid);
int removeAll();
int add(MTGCard * card);
int remove(MTGCard * card);
int save();
};
#endif
#ifndef _MTGDECK_H_
#define _MTGDECK_H_
#define MTG_ERROR -1
#include "../include/MTGDefinitions.h"
#include "../include/GameApp.h"
#include "../include/TexturesCache.h"
#include <string>
using std::string;
class GameApp;
class MTGCard;
#define MAX_SETS 30
class MtgSets{
protected:
public:
int nb_items;
string values[MAX_SETS];
public:
static MtgSets * SetsList;
MtgSets();
int Add(const char * subtype);
};
class MTGAllCards {
protected:
int conf_read_mode;
int conf_fd;
char * conf_buffer;
int read_cursor;
int colorsCount[MTG_NB_COLORS];
int total_cards;
GameApp * parent;
void init();
void initCounters();
public:
TexturesCache * mCache;
MTGCard * _(int i);
MTGCard * collection[TOTAL_NUMBER_OF_CARDS];
MTGAllCards();
~MTGAllCards();
MTGAllCards(TexturesCache * cache);
void destroyAllCards();
MTGAllCards(const char * config_file, const char * set_name);
MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache);
MTGCard * getCardById(int id);
int load(const char * config_file, const char * setName, int autoload = 1);
int countByType(const char * _type);
int countByColor(int color);
int countBySet(int setId);
int readConfLine(int set_id);
int totalCards();
int randomCardId();
private:
int processConfLine(char* file, MTGCard* card);
};
class MTGDeck:public MTGAllCards{
protected:
string filename;
MTGAllCards * allcards;
public:
MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards);
int addRandomCards(int howmany, int setId = -1, int rarity = -1, const char * subtype = NULL);
int add(int cardid);
int remove(int cardid);
int removeAll();
int add(MTGCard * card);
int remove(MTGCard * card);
int save();
};
#endif

View File

@@ -1,176 +1,176 @@
#ifndef _MTGDEFINITION_H_
#define _MTGDEFINITION_H_
#define TOTAL_NUMBER_OF_CARDS 4000
#define MTG_NB_COLORS 7
#define MTG_COLOR_ARTIFACT 0
#define MTG_COLOR_GREEN 1
#define MTG_COLOR_BLUE 2
#define MTG_COLOR_RED 3
#define MTG_COLOR_BLACK 4
#define MTG_COLOR_WHITE 5
#define MTG_COLOR_LAND 6
static char MTGColorChars[] = {'x','g','u','r','b','w','l'};
static const char * MTGColorStrings[] = {"artifact", "green", "blue", "red", "black", "white", "land"};
static int _r[7] = {75, 20, 20, 200,50,255,128};
static int _g[7] = {30, 140, 30, 15, 50,255,128};
static int _b[7] = {20, 0, 140,15, 50,255,128};
#define MTG_UNCOLORED 0
#define MTG_FOREST 1
#define MTG_ISLAND 2
#define MTG_MOUNTAIN 3
#define MTG_SWAMP 4
#define MTG_PLAIN 5
#define MTG_TYPE_CREATURE 10
#define MTG_TYPE_ARTIFACT 11
#define MTG_TYPE_ENCHANTMENT 12
#define MTG_TYPE_SORCERY 13
#define MTG_TYPE_LAND 14
#define MTG_TYPE_INSTANT 15
#define MTG_PHASE_BEFORE_BEGIN 0
#define MTG_PHASE_UNTAP 1
#define MTG_PHASE_UPKEEP 2
#define MTG_PHASE_DRAW 3
#define MTG_PHASE_FIRSTMAIN 4
#define MTG_PHASE_COMBATBEGIN 5
#define MTG_PHASE_COMBATATTACKERS 6
#define MTG_PHASE_COMBATBLOCKERS 7
#define MTG_PHASE_COMBATDAMAGE 8
#define MTG_PHASE_COMBATEND 9
#define MTG_PHASE_SECONDMAIN 10
#define MTG_PHASE_ENDOFTURN 11
#define MTG_PHASE_EOT 11
#define MTG_PHASE_CLEANUP 12
#define MTG_PHASE_AFTER_EOT 13
#define NB_MTG_PHASES 14
#define TRAMPLE 0
#define FORESTWALK 1
#define ISLANDWALK 2
#define MOUNTAINWALK 3
#define SWAMPWALK 4
#define PLAINSWALK 5
#define FLYING 6
#define FIRSTSTRIKE 7
#define DOUBLESTRIKE 8
#define FEAR 9
#define FLASH 10
#define HASTE 11
#define LIFELINK 12
#define REACH 13
#define SHROUD 14
#define VIGILANCE 15
#define DEFENSER 16
#define DEFENDER 16
#define BANDING 17
#define PROTECTIONGREEN 18
#define PROTECTIONBLUE 19
#define PROTECTIONRED 20
#define PROTECTIONBLACK 21
#define PROTECTIONWHITE 22
#define UNBLOCKABLE 23
#define WITHER 24
#define PERSIST 25
#define RETRACE 26
#define EXALTED 27
#define LEGENDARY 28
#define SHADOW 29
#define REACHSHADOW 30
#define FORESTHOME 31
#define ISLANDHOME 32
#define MOUNTAINHOME 33
#define SWAMPHOME 34
#define PLAINSHOME 35
#define FLANKING 36
#define RAMPAGE1 37
#define NB_BASIC_ABILITIES 38
static const char * MTGBasicAbilities[] = {
"trample",
"forestwalk",
"islandwalk",
"mountainwalk",
"swampwalk",
"plainwalk",
"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",
"legendary",
"shadow",
"reachshadow",
"foresthome",
"islandhome",
"moutainhome",
"swamphome",
"plainshome",
"flanking",
"rampage",
};
#define RARITY_M 'M'
#define RARITY_R 'R'
#define RARITY_U 'U'
#define RARITY_C 'C'
#define RARITY_L 'L'
#define MAIN_FONT 0
#define MAGIC_FONT 1
static const char *MTGPhaseNames[] =
{
"---",
"Untap",
"Upkeep",
"Draw",
"Main phase 1",
"Combat begins",
"Attackers",
"Blockers",
"Combat damage",
"Combat ends",
"Main phase 2",
"End of turn",
"cleanup",
"---"
};
#endif
#ifndef _MTGDEFINITION_H_
#define _MTGDEFINITION_H_
#define TOTAL_NUMBER_OF_CARDS 4000
#define MTG_NB_COLORS 7
#define MTG_COLOR_ARTIFACT 0
#define MTG_COLOR_GREEN 1
#define MTG_COLOR_BLUE 2
#define MTG_COLOR_RED 3
#define MTG_COLOR_BLACK 4
#define MTG_COLOR_WHITE 5
#define MTG_COLOR_LAND 6
static char MTGColorChars[] = {'x','g','u','r','b','w','l'};
static const char * MTGColorStrings[] = {"artifact", "green", "blue", "red", "black", "white", "land"};
static int _r[7] = {75, 20, 20, 200,50,255,128};
static int _g[7] = {30, 140, 30, 15, 50,255,128};
static int _b[7] = {20, 0, 140,15, 50,255,128};
#define MTG_UNCOLORED 0
#define MTG_FOREST 1
#define MTG_ISLAND 2
#define MTG_MOUNTAIN 3
#define MTG_SWAMP 4
#define MTG_PLAIN 5
#define MTG_TYPE_CREATURE 10
#define MTG_TYPE_ARTIFACT 11
#define MTG_TYPE_ENCHANTMENT 12
#define MTG_TYPE_SORCERY 13
#define MTG_TYPE_LAND 14
#define MTG_TYPE_INSTANT 15
#define MTG_PHASE_BEFORE_BEGIN 0
#define MTG_PHASE_UNTAP 1
#define MTG_PHASE_UPKEEP 2
#define MTG_PHASE_DRAW 3
#define MTG_PHASE_FIRSTMAIN 4
#define MTG_PHASE_COMBATBEGIN 5
#define MTG_PHASE_COMBATATTACKERS 6
#define MTG_PHASE_COMBATBLOCKERS 7
#define MTG_PHASE_COMBATDAMAGE 8
#define MTG_PHASE_COMBATEND 9
#define MTG_PHASE_SECONDMAIN 10
#define MTG_PHASE_ENDOFTURN 11
#define MTG_PHASE_EOT 11
#define MTG_PHASE_CLEANUP 12
#define MTG_PHASE_AFTER_EOT 13
#define NB_MTG_PHASES 14
#define TRAMPLE 0
#define FORESTWALK 1
#define ISLANDWALK 2
#define MOUNTAINWALK 3
#define SWAMPWALK 4
#define PLAINSWALK 5
#define FLYING 6
#define FIRSTSTRIKE 7
#define DOUBLESTRIKE 8
#define FEAR 9
#define FLASH 10
#define HASTE 11
#define LIFELINK 12
#define REACH 13
#define SHROUD 14
#define VIGILANCE 15
#define DEFENSER 16
#define DEFENDER 16
#define BANDING 17
#define PROTECTIONGREEN 18
#define PROTECTIONBLUE 19
#define PROTECTIONRED 20
#define PROTECTIONBLACK 21
#define PROTECTIONWHITE 22
#define UNBLOCKABLE 23
#define WITHER 24
#define PERSIST 25
#define RETRACE 26
#define EXALTED 27
#define LEGENDARY 28
#define SHADOW 29
#define REACHSHADOW 30
#define FORESTHOME 31
#define ISLANDHOME 32
#define MOUNTAINHOME 33
#define SWAMPHOME 34
#define PLAINSHOME 35
#define FLANKING 36
#define RAMPAGE1 37
#define NB_BASIC_ABILITIES 38
static const char * MTGBasicAbilities[] = {
"trample",
"forestwalk",
"islandwalk",
"mountainwalk",
"swampwalk",
"plainwalk",
"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",
"legendary",
"shadow",
"reachshadow",
"foresthome",
"islandhome",
"moutainhome",
"swamphome",
"plainshome",
"flanking",
"rampage",
};
#define RARITY_M 'M'
#define RARITY_R 'R'
#define RARITY_U 'U'
#define RARITY_C 'C'
#define RARITY_L 'L'
#define MAIN_FONT 0
#define MAGIC_FONT 1
static const char *MTGPhaseNames[] =
{
"---",
"Untap",
"Upkeep",
"Draw",
"Main phase 1",
"Combat begins",
"Attackers",
"Blockers",
"Combat damage",
"Combat ends",
"Main phase 2",
"End of turn",
"cleanup",
"---"
};
#endif

View File

@@ -14,10 +14,10 @@ class MTGGamePhase: public ActionElement {
int currentState;
JLBFont * mFont;
public:
MTGGamePhase(int id);
MTGGamePhase(int id);
virtual void Render();
virtual void Update(float dt);
void CheckUserInput(float dt);
void CheckUserInput(float dt);
};

View File

@@ -1,98 +1,98 @@
#ifndef _MTGGAMEZONES_H_
#define _MTGGAMEZONES_H_
#include <map>
using std::map;
#include "MTGDeck.h"
#include "MTGCardInstance.h"
#define MTG_MAX_PLAYER_CARDS 100
class MTGAllCards;
class MTGCardInstance;
class Player;
class MTGGameZone {
protected:
Player * owner;
public:
//Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array
MTGCardInstance * cards[MTG_MAX_PLAYER_CARDS];
map<MTGCardInstance *,int> cardsMap;
int nb_cards;
MTGGameZone();
~MTGGameZone();
void shuffle();
virtual MTGCardInstance * draw();
void addCard(MTGCardInstance * card);
void debugPrint();
MTGCardInstance * removeCard(MTGCardInstance * card);
MTGCardInstance * hasCard(MTGCardInstance * card);
void cleanupPhase();
int countByType(const char * value);
int hasType(const char * value);
void setOwner(Player * player);
MTGCardInstance * lastCardDrawn;
};
class MTGLibrary: public MTGGameZone {
public:
// MTGLibrary();
void shuffleTopToBottom(int nbcards);
MTGCardInstance * draw();
};
class MTGGraveyard: public MTGGameZone {
public:
// MTGGraveyard();
};
class MTGHand: public MTGGameZone {
public:
};
class MTGStack: public MTGGameZone {
public:
};
class MTGInPlay: public MTGGameZone {
public:
//MTGInPlay();
void untapAll();
MTGCardInstance * getNextAttacker(MTGCardInstance * previous);
MTGCardInstance * getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker);
int nbDefensers( MTGCardInstance * attacker);
int nbPartners(MTGCardInstance * attacker);
};
class MTGPlayerCards {
protected:
void init();
public:
MTGLibrary * library;
MTGGraveyard * graveyard;
MTGHand * hand;
MTGInPlay * inPlay;
MTGStack * stack;
MTGAllCards * collection;
MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize);
~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1);
void setOwner(Player * player);
void discardRandom(MTGGameZone * from);
void drawFromLibrary();
void showHand();
void putInGraveyard(MTGCardInstance * card);
void putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card);
};
#endif
#ifndef _MTGGAMEZONES_H_
#define _MTGGAMEZONES_H_
#include <map>
using std::map;
#include "MTGDeck.h"
#include "MTGCardInstance.h"
#define MTG_MAX_PLAYER_CARDS 100
class MTGAllCards;
class MTGCardInstance;
class Player;
class MTGGameZone {
protected:
Player * owner;
public:
//Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array
MTGCardInstance * cards[MTG_MAX_PLAYER_CARDS];
map<MTGCardInstance *,int> cardsMap;
int nb_cards;
MTGGameZone();
~MTGGameZone();
void shuffle();
virtual MTGCardInstance * draw();
void addCard(MTGCardInstance * card);
void debugPrint();
MTGCardInstance * removeCard(MTGCardInstance * card);
MTGCardInstance * hasCard(MTGCardInstance * card);
void cleanupPhase();
int countByType(const char * value);
int hasType(const char * value);
void setOwner(Player * player);
MTGCardInstance * lastCardDrawn;
};
class MTGLibrary: public MTGGameZone {
public:
// MTGLibrary();
void shuffleTopToBottom(int nbcards);
MTGCardInstance * draw();
};
class MTGGraveyard: public MTGGameZone {
public:
// MTGGraveyard();
};
class MTGHand: public MTGGameZone {
public:
};
class MTGStack: public MTGGameZone {
public:
};
class MTGInPlay: public MTGGameZone {
public:
//MTGInPlay();
void untapAll();
MTGCardInstance * getNextAttacker(MTGCardInstance * previous);
MTGCardInstance * getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker);
int nbDefensers( MTGCardInstance * attacker);
int nbPartners(MTGCardInstance * attacker);
};
class MTGPlayerCards {
protected:
void init();
public:
MTGLibrary * library;
MTGGraveyard * graveyard;
MTGHand * hand;
MTGInPlay * inPlay;
MTGStack * stack;
MTGAllCards * collection;
MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize);
~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1);
void setOwner(Player * player);
void discardRandom(MTGGameZone * from);
void drawFromLibrary();
void showHand();
void putInGraveyard(MTGCardInstance * card);
void putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card);
};
#endif

View File

@@ -17,7 +17,7 @@ class GuiCardscontroller;
class MTGGuiHand: public GuiCardsController{
protected:
int currentId[2];
int currentId[2];
Player * currentPlayer;
int mShowHand;
float mAnimState;

View File

@@ -11,42 +11,42 @@ class GameObserver;
class CardGui;
class MTGGuiPlay: public PlayGuiObjectController {
protected:
int offset;
Player * currentPlayer;
MTGCardInstance * cardsGrid[SCREEN_WIDTH/5][SCREEN_HEIGHT/5];
int nb_creatures;
int nb_spells;
int nb_lands;
int cards_x_limit;
protected:
int offset;
Player * currentPlayer;
MTGCardInstance * cardsGrid[SCREEN_WIDTH/5][SCREEN_HEIGHT/5];
int nb_creatures;
int nb_spells;
int nb_lands;
int cards_x_limit;
JQuad * phaseIcons[24];
JQuad * mGlitter;
int mGlitterAlpha;
float mGlitterX, mGlitterY;
JTexture * mPhaseBarTexture;
JQuad * mIcons[7];
JTexture * mIconsTexture;
JTexture * mBgTex;
JQuad * mBg;
JQuad * phaseIcons[24];
JQuad * mGlitter;
int mGlitterAlpha;
float mGlitterX, mGlitterY;
JTexture * mPhaseBarTexture;
JQuad * mIcons[7];
JTexture * mIconsTexture;
JTexture * mBgTex;
JQuad * mBg;
JTexture * mBgTex2;
JQuad * mBg2;
int alphaBg[4];
void RenderPhaseBar();
void RenderPlayerInfo(int player);
JLBFont* mFont;
JTexture * mBgTex2;
JQuad * mBg2;
int alphaBg[4];
void RenderPhaseBar();
void RenderPlayerInfo(int player);
JLBFont* mFont;
void AddPlayersGuiInfo();
void initCardsDisplay();
void setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode);
void setTargettingCardPosition(CardGui * cardg, int player, int playerTurn);
void adjustCardPosition(CardGui * cardg);
public:
CardGui * getByCard(MTGCardInstance * card);
MTGGuiPlay(int id, GameObserver * game);
~MTGGuiPlay();
void Update(float dt);
void AddPlayersGuiInfo();
void initCardsDisplay();
void setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode);
void setTargettingCardPosition(CardGui * cardg, int player, int playerTurn);
void adjustCardPosition(CardGui * cardg);
public:
CardGui * getByCard(MTGCardInstance * card);
MTGGuiPlay(int id, GameObserver * game);
~MTGGuiPlay();
void Update(float dt);
void CheckUserInput(float dt);
virtual void Render();
void updateCards();

View File

@@ -1,120 +1,120 @@
/* Default observers/Abilities that are added to the game for a standard Magic Game
*/
#ifndef _MTGRULES_H_
#define _MTGRULES_H_
#include "../include/MTGAbility.h"
#include "../include/Counters.h"
class MTGAttackRule:public MTGAbility{
public:
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int testDestroy();
MTGAttackRule(int _id);
const char * getMenuText(){return "Attacker";}
};
class MTGBlockRule:public MTGAbility{
public:
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int testDestroy();
MTGBlockRule(int _id);
const char * getMenuText(){return "Blocker";}
};
/* Persist Rule */
class MTGPersistRule:public ListMaintainerAbility{
public:
MTGPersistRule(int _id):ListMaintainerAbility(_id){};
virtual void Update(float dt){
map<MTGCardInstance *,bool>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * card = ((*it).first);
Player * p = card->controller();
if (p->game->graveyard->hasCard(card)){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 1 !\n");
#endif
p->game->putInZone(card, p->game->graveyard, p->game->hand);
Spell * spell = NEW Spell(card);
p->game->putInZone(card, p->game->hand, p->game->stack);
spell->resolve();
delete spell;
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 2 !\n");
#endif
card->counters->addCounter(-1,-1);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 3 !\n");
#endif
}
}
ListMaintainerAbility::Update(dt);
}
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[PERSIST] && !card->counters->hasCounter(-1,-1) ){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("yay, persist !\n");
#endif
return 1;
}
return 0;
}
int added(MTGCardInstance * card){return 1;}
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
};
/*
* Rule 420.5e (Legend Rule)
* If two or more legendary permanents with the same name are in play, all are put into their
* owners' graveyards. This is called the "legend rule." If only one of those permanents is
* legendary, this rule doesn't apply.
*/
class MTGLegendRule:public ListMaintainerAbility{
public:
MTGLegendRule(int _id):ListMaintainerAbility(_id){};
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[LEGENDARY]){
return 1;
}
return 0;
}
int added(MTGCardInstance * card){
map<MTGCardInstance *,bool>::iterator it;
int destroy = 0;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * comparison = (*it).first;
if (comparison!= card && !strcmp(comparison->getName(), card->getName())){
comparison->owner->game->putInGraveyard(comparison);
destroy = 1;
}
}
if (destroy){
card->owner->game->putInGraveyard(card);
}
return 1;
}
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
};
#endif
/* Default observers/Abilities that are added to the game for a standard Magic Game
*/
#ifndef _MTGRULES_H_
#define _MTGRULES_H_
#include "../include/MTGAbility.h"
#include "../include/Counters.h"
class MTGAttackRule:public MTGAbility{
public:
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int testDestroy();
MTGAttackRule(int _id);
const char * getMenuText(){return "Attacker";}
};
class MTGBlockRule:public MTGAbility{
public:
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int testDestroy();
MTGBlockRule(int _id);
const char * getMenuText(){return "Blocker";}
};
/* Persist Rule */
class MTGPersistRule:public ListMaintainerAbility{
public:
MTGPersistRule(int _id):ListMaintainerAbility(_id){};
virtual void Update(float dt){
map<MTGCardInstance *,bool>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * card = ((*it).first);
Player * p = card->controller();
if (p->game->graveyard->hasCard(card)){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 1 !\n");
#endif
p->game->putInZone(card, p->game->graveyard, p->game->hand);
Spell * spell = NEW Spell(card);
p->game->putInZone(card, p->game->hand, p->game->stack);
spell->resolve();
delete spell;
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 2 !\n");
#endif
card->counters->addCounter(-1,-1);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 3 !\n");
#endif
}
}
ListMaintainerAbility::Update(dt);
}
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[PERSIST] && !card->counters->hasCounter(-1,-1) ){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("yay, persist !\n");
#endif
return 1;
}
return 0;
}
int added(MTGCardInstance * card){return 1;}
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
};
/*
* Rule 420.5e (Legend Rule)
* If two or more legendary permanents with the same name are in play, all are put into their
* owners' graveyards. This is called the "legend rule." If only one of those permanents is
* legendary, this rule doesn't apply.
*/
class MTGLegendRule:public ListMaintainerAbility{
public:
MTGLegendRule(int _id):ListMaintainerAbility(_id){};
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[LEGENDARY]){
return 1;
}
return 0;
}
int added(MTGCardInstance * card){
map<MTGCardInstance *,bool>::iterator it;
int destroy = 0;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * comparison = (*it).first;
if (comparison!= card && !strcmp(comparison->getName(), card->getName())){
comparison->owner->game->putInGraveyard(comparison);
destroy = 1;
}
}
if (destroy){
card->owner->game->putInGraveyard(card);
}
return 1;
}
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
};
#endif

View File

@@ -10,29 +10,29 @@ class ManaCostHybrid;
class ManaCost{
protected:
int cost[MTG_NB_COLORS+1];
ManaCostHybrid * hybrids[10];
int nbhybrids;
ManaCostHybrid * hybrids[10];
int nbhybrids;
public:
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL);
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL);
void init();
void x();
void x();
ManaCost(int _cost[], int nb_elems);
ManaCost();
~ManaCost();
~ManaCost();
ManaCost(ManaCost * _manaCost);
void copy (ManaCost * _manaCost);
int getConvertedCost();
void copy (ManaCost * _manaCost);
int getConvertedCost();
string toString();
int getCost(int color);
int getMainColor();
int hasColor(int color);
int remove (int color, int value);
int getMainColor();
int hasColor(int color);
int remove (int color, int value);
int add(int color, int value);
int addHybrid(int c1, int v1, int c2, int v2);
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
void randomDiffHybrids(ManaCost * _cost, int diff[]);
int add(ManaCost * _cost);
int pay (ManaCost * _cost);
int addHybrid(int c1, int v1, int c2, int v2);
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
void randomDiffHybrids(ManaCost * _cost, int diff[]);
int add(ManaCost * _cost);
int pay (ManaCost * _cost);
//return 1 if _cost can be paid with current data, 0 otherwise
int canAfford(ManaCost * _cost);

View File

@@ -1,17 +1,17 @@
#ifndef _MANACOST_HYBRID_H_
#define _MANACOST_HYBRID_H_
class ManaCostHybrid{
public:
int color1;
int color2;
int value1;
int value2;
ManaCostHybrid();
int hasColor(int color);
ManaCostHybrid(int c1,int v1,int c2,int v2);
void init(int c1,int v1,int c2,int v2);
int getConvertedCost();
};
#endif
#ifndef _MANACOST_HYBRID_H_
#define _MANACOST_HYBRID_H_
class ManaCostHybrid{
public:
int color1;
int color2;
int value1;
int value2;
ManaCostHybrid();
int hasColor(int color);
ManaCostHybrid(int c1,int v1,int c2,int v2);
void init(int c1,int v1,int c2,int v2);
int getConvertedCost();
};
#endif

View File

@@ -1,43 +1,43 @@
#ifndef _MENU_ITEM_H
#define _MENU_ITEM_H
#include <JLBFont.h>
#include <JGui.h>
#include <hge/hgeparticle.h>
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class hgeParticleSystem;
class MenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* const mText;
int mX;
int mY;
int updatedSinceLastRender;
float lastDt;
float mScale;
float mTargetScale;
JQuad * onQuad;
JQuad * offQuad;
hgeParticleSystem* mParticleSys;
public:
MenuItem(int id, JLBFont *font, const char* text, int x, int y, JQuad * _off, JQuad * _on, const char * particle, JQuad * particleQuad, bool hasFocus = false);
~MenuItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif
#ifndef _MENU_ITEM_H
#define _MENU_ITEM_H
#include <JLBFont.h>
#include <JGui.h>
#include <hge/hgeparticle.h>
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class hgeParticleSystem;
class MenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* const mText;
int mX;
int mY;
int updatedSinceLastRender;
float lastDt;
float mScale;
float mTargetScale;
JQuad * onQuad;
JQuad * offQuad;
hgeParticleSystem* mParticleSys;
public:
MenuItem(int id, JLBFont *font, const char* text, int x, int y, JQuad * _off, JQuad * _on, const char * particle, JQuad * particleQuad, bool hasFocus = false);
~MenuItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif

View File

@@ -1,40 +1,40 @@
#ifndef _OPTION_ITEM_H_
#define _OPTION_ITEM_H_
#include <JGui.h>
#include <string>
using std::string;
class OptionItem:public JGuiObject{
public:
string displayValue;
int id, value;
int hasFocus;
int maxValue, increment;
float x, y;
OptionItem(int id, string _displayValue, int _maxValue = 1, int _increment = 1);
~OptionItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving();
void setData();
virtual void updateValue(){value+=increment; if (value>maxValue) value=0;};
};
class OptionsList{
public:
OptionItem * options[20];
int nbitems;
int current;
OptionsList();
~OptionsList();
void Render();
void Update(float dt);
void Add(OptionItem * item);
void save();
};
#endif
#ifndef _OPTION_ITEM_H_
#define _OPTION_ITEM_H_
#include <JGui.h>
#include <string>
using std::string;
class OptionItem:public JGuiObject{
public:
string displayValue;
int id, value;
int hasFocus;
int maxValue, increment;
float x, y;
OptionItem(int id, string _displayValue, int _maxValue = 1, int _increment = 1);
~OptionItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving();
void setData();
virtual void updateValue(){value+=increment; if (value>maxValue) value=0;};
};
class OptionsList{
public:
OptionItem * options[20];
int nbitems;
int current;
OptionsList();
~OptionsList();
void Render();
void Update(float dt);
void Add(OptionItem * item);
void save();
};
#endif

View File

@@ -1,34 +1,34 @@
#ifndef _PHASERING_H_
#define _PHASERING_H_
#include <list>
using std::list;
/*
The class that handles the phases of a turn
*/
class Player;
class Phase{
public:
int id;
Player * player;
Phase(int _id, Player * _player):id(_id),player(_player){};
};
class PhaseRing{
public:
list<Phase *> ring;
list<Phase *>::iterator current;
Phase * getCurrentPhase();
Phase * forward();
Phase * goToPhase(int id, Player * player);
PhaseRing(Player* players[], int nbPlayers=2);
~PhaseRing();
int addPhase(Phase * phase);
int addPhaseBefore(int id, Player* player,int after_id, Player * after_player, int allOccurences = 1);
int removePhase (int id, Player * player, int allOccurences = 1);
};
#endif
#ifndef _PHASERING_H_
#define _PHASERING_H_
#include <list>
using std::list;
/*
The class that handles the phases of a turn
*/
class Player;
class Phase{
public:
int id;
Player * player;
Phase(int _id, Player * _player):id(_id),player(_player){};
};
class PhaseRing{
public:
list<Phase *> ring;
list<Phase *>::iterator current;
Phase * getCurrentPhase();
Phase * forward();
Phase * goToPhase(int id, Player * player);
PhaseRing(Player* players[], int nbPlayers=2);
~PhaseRing();
int addPhase(Phase * phase);
int addPhaseBefore(int id, Player* player,int after_id, Player * after_player, int allOccurences = 1);
int removePhase (int id, Player * player, int allOccurences = 1);
};
#endif

View File

@@ -1,78 +1,78 @@
/*
A class for all interactive objects in the play area (cards, avatars, etc...)
*/
#ifndef _PLAYGUIOBJECT_H_
#define _PLAYGUIOBJECT_H_
#define GUI_AVATAR 1
#define GUI_CARD 2
#define GUI_GRAVEYARD 3
#define GUI_LIBRARY 4
#include <JGui.h>
class MTGGameZone;
class Player;
class CardDisplay;
class PlayGuiObject: public JGuiObject, public JGuiListener{
protected:
public:
int wave;
float mHeight;
float defaultHeight;
bool mHasFocus;
int x;
int y;
int type;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual void Render(){};
virtual void Update(float dt);
PlayGuiObject(int id, float desiredHeight,float _x, float _y, bool hasFocus);
virtual void ButtonPressed(int controllerId, int controlId){};
virtual ~PlayGuiObject(){};
};
class GuiAvatar: public PlayGuiObject{
protected:
/*
A class for all interactive objects in the play area (cards, avatars, etc...)
*/
int avatarRed;
int currentLife;
public:
Player * player;
virtual void Render();
GuiAvatar(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * _player);
};
class GuiGameZone: public PlayGuiObject{
protected:
MTGGameZone * zone;
public:
CardDisplay * cd;
int showCards;
virtual void Render();
virtual void Update(float dt);
GuiGameZone(int id, float desiredHeight,float _x, float _y, bool hasFocus,MTGGameZone * _zone);
~GuiGameZone();
virtual void ButtonPressed(int controllerId, int controlId);
void toggleDisplay();
};
class GuiGraveyard: public GuiGameZone{
public:
GuiGraveyard(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
};
class GuiLibrary: public GuiGameZone{
public:
GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
};
#endif
#ifndef _PLAYGUIOBJECT_H_
#define _PLAYGUIOBJECT_H_
#define GUI_AVATAR 1
#define GUI_CARD 2
#define GUI_GRAVEYARD 3
#define GUI_LIBRARY 4
#include <JGui.h>
class MTGGameZone;
class Player;
class CardDisplay;
class PlayGuiObject: public JGuiObject, public JGuiListener{
protected:
public:
int wave;
float mHeight;
float defaultHeight;
bool mHasFocus;
int x;
int y;
int type;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual void Render(){};
virtual void Update(float dt);
PlayGuiObject(int id, float desiredHeight,float _x, float _y, bool hasFocus);
virtual void ButtonPressed(int controllerId, int controlId){};
virtual ~PlayGuiObject(){};
};
class GuiAvatar: public PlayGuiObject{
protected:
int avatarRed;
int currentLife;
public:
Player * player;
virtual void Render();
GuiAvatar(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * _player);
};
class GuiGameZone: public PlayGuiObject{
protected:
MTGGameZone * zone;
public:
CardDisplay * cd;
int showCards;
virtual void Render();
virtual void Update(float dt);
GuiGameZone(int id, float desiredHeight,float _x, float _y, bool hasFocus,MTGGameZone * _zone);
~GuiGameZone();
virtual void ButtonPressed(int controllerId, int controlId);
void toggleDisplay();
};
class GuiGraveyard: public GuiGameZone{
public:
GuiGraveyard(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
};
class GuiLibrary: public GuiGameZone{
public:
GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
};
#endif

View File

@@ -1,6 +1,6 @@
#ifndef _PLAYGUIOBJECTCONTROLLER_H_
#define _PLAYGUIOBJECTCONTROLLER_H_
#ifndef _PLAYGUIOBJECTCONTROLLER_H_
#define _PLAYGUIOBJECTCONTROLLER_H_
#include "GuiLayers.h"
@@ -8,14 +8,14 @@ class PlayGuiObjectController : public GuiLayer{
protected:
int getClosestItem(int direction);
int getClosestItem(int direction, float tolerance);
static bool showBigCards;
static bool showBigCards;
public:
virtual void Update(float dt);
virtual void CheckUserInput(float dt);
PlayGuiObjectController(int id, GameObserver* _game):GuiLayer(id, _game){};
PlayGuiObjectController(int id, GameObserver* _game):GuiLayer(id, _game){};
virtual void Render(){GuiLayer::Render();};
};
#endif
#endif

View File

@@ -15,33 +15,33 @@ class Player: public Damageable, public Targetable{
ManaCost * manaPool;
public:
int typeAsTarget(){return TARGET_PLAYER;}
virtual int displayStack(){return 1;}
int typeAsTarget(){return TARGET_PLAYER;}
virtual int displayStack(){return 1;}
JTexture * mAvatarTex;
JQuad * mAvatar;
int canPutLandsIntoPlay;
MTGPlayerCards * game;
int testLife();
int afterDamage();
MTGPlayerCards * game;
int testLife();
int afterDamage();
Player(MTGPlayerCards * _deck, string deckFile);
virtual ~Player();
virtual ~Player();
void unTapPhase();
MTGInPlay * inPlay();
ManaCost * getManaPool();
int manaBurn();
void cleanupPhase();
virtual int Act(float dt){return 0;};
virtual int isAI(){return 0;};
Player * opponent();
int getId();
JQuad * getIcon();
string deckFile;
int manaBurn();
void cleanupPhase();
virtual int Act(float dt){return 0;};
virtual int isAI(){return 0;};
Player * opponent();
int getId();
JQuad * getIcon();
string deckFile;
};
class HumanPlayer: public Player{
public:
HumanPlayer(MTGPlayerCards * _deck, char * _deckFile);
};

View File

@@ -1,18 +1,18 @@
#ifndef _PLAYER_DATA_H_
#define _PLAYER_DATA_H_
#define PLAYER_SAVEFILE "Res/player/data.dat"
#include "../include/MTGDeck.h"
class PlayerData{
protected:
public:
int credits;
MTGDeck * collection;
PlayerData(MTGAllCards * allcards);
~PlayerData();
int save();
};
#endif
#ifndef _PLAYER_DATA_H_
#define _PLAYER_DATA_H_
#define PLAYER_SAVEFILE "Res/player/data.dat"
#include "../include/MTGDeck.h"
class PlayerData{
protected:
public:
int credits;
MTGDeck * collection;
PlayerData(MTGAllCards * allcards);
~PlayerData();
int save();
};
#endif

View File

@@ -1,31 +1,31 @@
#ifndef _PRICELIST_H_
#define _PRICELIST_H_
#include<string>
#include "../include/MTGDefinitions.h"
#include "../include/MTGDeck.h"
#include <stdio.h>
class Price{
public:
int cardid;
int price;
Price(int _cardid, int _price);
};
class PriceList{
private:
MTGAllCards * collection;
string filename;
Price * prices[TOTAL_NUMBER_OF_CARDS];
int nbprices;
public:
PriceList(const char * file, MTGAllCards * _collection);
~PriceList();
int save();
int getPrice(int cardId);
int setPrice(int cardId, int price);
};
#endif
#ifndef _PRICELIST_H_
#define _PRICELIST_H_
#include<string>
#include "../include/MTGDefinitions.h"
#include "../include/MTGDeck.h"
#include <stdio.h>
class Price{
public:
int cardid;
int price;
Price(int _cardid, int _price);
};
class PriceList{
private:
MTGAllCards * collection;
string filename;
Price * prices[TOTAL_NUMBER_OF_CARDS];
int nbprices;
public:
PriceList(const char * file, MTGAllCards * _collection);
~PriceList();
int save();
int getPrice(int cardId);
int setPrice(int cardId, int price);
};
#endif

View File

@@ -1,71 +1,71 @@
#ifndef _SHOP_ITEM_H
#define _SHOP_ITEM_H
#include <JGui.h>
#include <JLBFont.h>
#include "SimpleMenu.h"
#include "MTGDeck.h"
#include "../include/PriceList.h"
#include "../include/PlayerData.h"
#include "../include/CardDisplay.h"
#include <string>
using std::string;
class ShopItem:public JGuiObject{
private:
bool mHasFocus;
JLBFont *mFont;
string mText;
int mX;
int mY;
JQuad * quad;
JQuad * thumb;
float mScale;
float mTargetScale;
public:
int quantity;
MTGCard * card;
int price;
ShopItem(int id, JLBFont * font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price);
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,int x, int y, bool hasFocus, int _price);
~ShopItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
const char * getText();
};
class ShopItems:public JGuiController,public JGuiListener{
private:
PlayerData * playerdata;
PriceList * pricelist;
int mX, mY, mHeight;
JLBFont* mFont;
MTGAllCards * collection;
SimpleMenu * dialog;
int showPriceDialog;
int setId;
MTGCardInstance * displayCards[100];
CardDisplay * display;
void safeDeleteDisplay();
public:
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int setId);
~ShopItems();
void Render();
virtual void Update(float dt);
void Add(int cardid);
void Add(char * text, JQuad * quad, JQuad * thumb,int _price);
void pricedialog(int id, int mode=1);
virtual void ButtonPressed(int controllerId, int controlId);
void savePriceList();
void saveAll();
};
#endif
#ifndef _SHOP_ITEM_H
#define _SHOP_ITEM_H
#include <JGui.h>
#include <JLBFont.h>
#include "SimpleMenu.h"
#include "MTGDeck.h"
#include "../include/PriceList.h"
#include "../include/PlayerData.h"
#include "../include/CardDisplay.h"
#include <string>
using std::string;
class ShopItem:public JGuiObject{
private:
bool mHasFocus;
JLBFont *mFont;
string mText;
int mX;
int mY;
JQuad * quad;
JQuad * thumb;
float mScale;
float mTargetScale;
public:
int quantity;
MTGCard * card;
int price;
ShopItem(int id, JLBFont * font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price);
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,int x, int y, bool hasFocus, int _price);
~ShopItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
const char * getText();
};
class ShopItems:public JGuiController,public JGuiListener{
private:
PlayerData * playerdata;
PriceList * pricelist;
int mX, mY, mHeight;
JLBFont* mFont;
MTGAllCards * collection;
SimpleMenu * dialog;
int showPriceDialog;
int setId;
MTGCardInstance * displayCards[100];
CardDisplay * display;
void safeDeleteDisplay();
public:
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int setId);
~ShopItems();
void Render();
virtual void Update(float dt);
void Add(int cardid);
void Add(char * text, JQuad * quad, JQuad * thumb,int _price);
void pricedialog(int id, int mode=1);
virtual void ButtonPressed(int controllerId, int controlId);
void savePriceList();
void saveAll();
};
#endif

View File

@@ -1,24 +1,24 @@
/*
A class for very simple menus structure
*/
#ifndef _SIMPLEMENU_H_
#define _SIMPLEMENU_H_
#include <JGui.h>
#include <JLBFont.h>
#include <string>
class SimpleMenu:public JGuiController{
private:
int mHeight, mWidth, mX, mY;
JLBFont* mFont;
std::string title;
int displaytitle;
public:
SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, int width, const char * _title = NULL);
void Render();
void Add(int id, const char * Text);
};
#endif
/*
A class for very simple menus structure
*/
#ifndef _SIMPLEMENU_H_
#define _SIMPLEMENU_H_
#include <JGui.h>
#include <JLBFont.h>
#include <string>
class SimpleMenu:public JGuiController{
private:
int mHeight, mWidth, mX, mY;
JLBFont* mFont;
std::string title;
int displaytitle;
public:
SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, int width, const char * _title = NULL);
void Render();
void Add(int id, const char * Text);
};
#endif

View File

@@ -1,37 +1,37 @@
#ifndef _SIMPLEMENU_ITEM_H
#define _SIMPLEMENU_ITEM_H
#include <JLBFont.h>
#include <JGui.h>
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class SimpleMenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* mText;
int mX;
int mY;
float mScale;
float mTargetScale;
public:
SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus = false);
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif
#ifndef _SIMPLEMENU_ITEM_H
#define _SIMPLEMENU_ITEM_H
#include <JLBFont.h>
#include <JGui.h>
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class SimpleMenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* mText;
int mX;
int mY;
float mScale;
float mTargetScale;
public:
SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus = false);
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif

View File

@@ -1,25 +1,25 @@
#ifndef _SUBTYPES_H_
#define _SUBTYPES_H_
#include <string>
#include <map>
using std::string;
using std::map;
class Subtypes{
protected:
int nb_items;
map<string,int> values;
public:
static Subtypes * subtypesList;
Subtypes();
int Add(const char * subtype);
int find(const char * subtype);
int Add(string subtype);
int find(string subtype);
};
#endif
#ifndef _SUBTYPES_H_
#define _SUBTYPES_H_
#include <string>
#include <map>
using std::string;
using std::map;
class Subtypes{
protected:
int nb_items;
map<string,int> values;
public:
static Subtypes * subtypesList;
Subtypes();
int Add(const char * subtype);
int find(const char * subtype);
int Add(string subtype);
int find(string subtype);
};
#endif

View File

@@ -23,22 +23,22 @@ class CardDescriptor;
class TargetChooser: public TargetsList {
protected:
int forceTargetListReady;
protected:
int forceTargetListReady;
public:
TargetChooser(MTGCardInstance * card = NULL, int _maxtargets = -1);
public:
TargetChooser(MTGCardInstance * card = NULL, int _maxtargets = -1);
MTGCardInstance * source; //Optionnal source, used for protection from...
int maxtargets; //Set to -1 for "unlimited"
MTGCardInstance * source; //Optionnal source, used for protection from...
int maxtargets; //Set to -1 for "unlimited"
int ForceTargetListReady();
int targetsReadyCheck();
virtual int addTarget(Targetable * target);
virtual int canTarget(Targetable * _target);
virtual int full(){if (maxtargets != -1 && cursor>=maxtargets) {return 1;} else{return 0;}};
virtual int ready(){return cursor;};
int targetListSet();
int ForceTargetListReady();
int targetsReadyCheck();
virtual int addTarget(Targetable * target);
virtual int canTarget(Targetable * _target);
virtual int full(){if (maxtargets != -1 && cursor>=maxtargets) {return 1;} else{return 0;}};
virtual int ready(){return cursor;};
int targetListSet();
};
@@ -46,94 +46,94 @@ public:
class TargetChooserFactory{
public:
TargetChooser * createTargetChooser(string s, MTGCardInstance * card);
TargetChooser * createTargetChooser(string s, MTGCardInstance * card);
TargetChooser * createTargetChooser(MTGCardInstance * card);
};
class TargetZoneChooser:public TargetChooser{
public:
MTGGameZone * zones[6];
int nbzones;
int init(MTGGameZone ** _zones, int _nbzones);
TargetZoneChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
TargetZoneChooser(MTGGameZone ** _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card);
public:
MTGGameZone * zones[6];
int nbzones;
int init(MTGGameZone ** _zones, int _nbzones);
TargetZoneChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
TargetZoneChooser(MTGGameZone ** _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card);
};
class CreatureTargetChooser:public TargetZoneChooser{
public:
int maxpower;
int maxtoughness;
CreatureTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1);
CreatureTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card);
public:
int maxpower;
int maxtoughness;
CreatureTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1);
CreatureTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card);
};
class DamageableTargetChooser:public CreatureTargetChooser{
public:
DamageableTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser( _zones,_nbzones, card, _maxtargets){};
DamageableTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target);
public:
DamageableTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser( _zones,_nbzones, card, _maxtargets){};
DamageableTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target);
};
class PlayerTargetChooser:public TargetChooser{
public:
PlayerTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):TargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target);
public:
PlayerTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):TargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target);
};
class TypeTargetChooser:public TargetZoneChooser{
public:
int nbtypes;
int types[10];
TypeTargetChooser(const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1);
TypeTargetChooser(const char * _type, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
void addType(int type);
void addType(const char * type);
virtual int canTarget(Targetable * targe);
public:
int nbtypes;
int types[10];
TypeTargetChooser(const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1);
TypeTargetChooser(const char * _type, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
void addType(int type);
void addType(const char * type);
virtual int canTarget(Targetable * targe);
};
class DescriptorTargetChooser:public TargetZoneChooser{
public:
CardDescriptor * cd;
DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1);
DescriptorTargetChooser(CardDescriptor * _cd, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * target);
public:
CardDescriptor * cd;
DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1);
DescriptorTargetChooser(CardDescriptor * _cd, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * target);
};
class SpellTargetChooser:public TargetChooser{
public:
int color;
SpellTargetChooser( MTGCardInstance * card = NULL,int _color = -1, int _maxtargets = 1 );
virtual int canTarget(Targetable * target);
public:
int color;
SpellTargetChooser( MTGCardInstance * card = NULL,int _color = -1, int _maxtargets = 1 );
virtual int canTarget(Targetable * target);
};
class SpellOrPermanentTargetChooser:public TargetZoneChooser{
public:
int color;
SpellOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target);
public:
int color;
SpellOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target);
};
class DamageTargetChooser:public TargetChooser{
public:
int color;
int state;
DamageTargetChooser( MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1, int state = NOT_RESOLVED);
virtual int canTarget(Targetable * target);
public:
int color;
int state;
DamageTargetChooser( MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1, int state = NOT_RESOLVED);
virtual int canTarget(Targetable * target);
};
class DamageOrPermanentTargetChooser:public TargetZoneChooser{
public:
int color;
DamageOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target);
public:
int color;
DamageOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target);
};
#endif

View File

@@ -1,13 +1,13 @@
#ifndef _TARGETABLE_H_
#define _TARGETABLE_H_
#define TARGET_CARD 1
#define TARGET_PLAYER 2
#define TARGET_STACKACTION 3
class Targetable{
public:
virtual int typeAsTarget() = 0;
};
#endif
#ifndef _TARGETABLE_H_
#define _TARGETABLE_H_
#define TARGET_CARD 1
#define TARGET_PLAYER 2
#define TARGET_STACKACTION 3
class Targetable{
public:
virtual int typeAsTarget() = 0;
};
#endif

View File

@@ -1,34 +1,34 @@
#ifndef _TARGETSLIST_H_
#define _TARGETSLIST_H_
#define MAX_TARGETS 20
class Targetable;
class MTGCardInstance;
class Player;
class Damageable;
class Spell;
class Interruptible;
class Damage;
class TargetsList{
public:
int cursor;
TargetsList();
TargetsList(Targetable * _targets[], int nbtargets);
Targetable* targets[MAX_TARGETS];
int alreadyHasTarget(Targetable * target);
int removeTarget(Targetable * _card);
int toggleTarget(Targetable * _card);
virtual int addTarget(Targetable * _target);
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous, int type);
void initTargets(){cursor = 0;};
};
#endif
#ifndef _TARGETSLIST_H_
#define _TARGETSLIST_H_
#define MAX_TARGETS 20
class Targetable;
class MTGCardInstance;
class Player;
class Damageable;
class Spell;
class Interruptible;
class Damage;
class TargetsList{
public:
int cursor;
TargetsList();
TargetsList(Targetable * _targets[], int nbtargets);
Targetable* targets[MAX_TARGETS];
int alreadyHasTarget(Targetable * target);
int removeTarget(Targetable * _card);
int toggleTarget(Targetable * _card);
virtual int addTarget(Targetable * _target);
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous, int type);
void initTargets(){cursor = 0;};
};
#endif

View File

@@ -1,85 +1,85 @@
#ifndef _TESTSUITE_AI_H_
#define _TESTSUITE_AI_H_
#define MAX_TESTSUITE_ACTIONS 100
#define MAX_TESTUITE_CARDS 100
#include "../include/AIPlayer.h"
class TestSuiteActions{
public:
int nbitems;
string actions[MAX_TESTSUITE_ACTIONS];
void add(string action);
TestSuiteActions();
void cleanup();
};
class TestSuitePlayerZone{
public:
int cards[MAX_TESTUITE_CARDS];
int nbitems;
void add(int cardid);
TestSuitePlayerZone();
void cleanup();
};
class TestSuitePlayerData{
public:
int life;
ManaCost * manapool;
TestSuitePlayerZone zones[5];
TestSuitePlayerData();
~TestSuitePlayerData();
void cleanup();
};
class TestSuiteState{
public:
int phase;
void parsePlayerState(int playerId, string s);
TestSuiteState();
TestSuitePlayerData playerData[2];
void cleanup();
};
class TestSuite{
public:
float timerLimit;
int currentAction;
TestSuiteState initState;
TestSuiteState endState;
TestSuiteActions actions;
string files[128];
int nbfiles;
int currentfile;
void load(const char * filename);
TestSuite(const char * filename);
void initGame();
int assertGame();
MTGPlayerCards * buildDeck(MTGAllCards * collection, int playerId);
string getNextAction();
int phaseStrToInt(string s);
MTGCardInstance * getCardByMTGId(int mtgid);
Interruptible * getActionByMTGId(int mtgid);
int loadNext();
void cleanup();
int Log(const char * text);
};
class TestSuiteAI:public AIPlayer{
public:
TestSuite * suite;
float timer;
TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId);
virtual int Act(float dt);
virtual int displayStack(){return 1;}
};
#endif
#ifndef _TESTSUITE_AI_H_
#define _TESTSUITE_AI_H_
#define MAX_TESTSUITE_ACTIONS 100
#define MAX_TESTUITE_CARDS 100
#include "../include/AIPlayer.h"
class TestSuiteActions{
public:
int nbitems;
string actions[MAX_TESTSUITE_ACTIONS];
void add(string action);
TestSuiteActions();
void cleanup();
};
class TestSuitePlayerZone{
public:
int cards[MAX_TESTUITE_CARDS];
int nbitems;
void add(int cardid);
TestSuitePlayerZone();
void cleanup();
};
class TestSuitePlayerData{
public:
int life;
ManaCost * manapool;
TestSuitePlayerZone zones[5];
TestSuitePlayerData();
~TestSuitePlayerData();
void cleanup();
};
class TestSuiteState{
public:
int phase;
void parsePlayerState(int playerId, string s);
TestSuiteState();
TestSuitePlayerData playerData[2];
void cleanup();
};
class TestSuite{
public:
float timerLimit;
int currentAction;
TestSuiteState initState;
TestSuiteState endState;
TestSuiteActions actions;
string files[128];
int nbfiles;
int currentfile;
void load(const char * filename);
TestSuite(const char * filename);
void initGame();
int assertGame();
MTGPlayerCards * buildDeck(MTGAllCards * collection, int playerId);
string getNextAction();
int phaseStrToInt(string s);
MTGCardInstance * getCardByMTGId(int mtgid);
Interruptible * getActionByMTGId(int mtgid);
int loadNext();
void cleanup();
int Log(const char * text);
};
class TestSuiteAI:public AIPlayer{
public:
TestSuite * suite;
float timer;
TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId);
virtual int Act(float dt);
virtual int displayStack(){return 1;}
};
#endif

View File

@@ -22,9 +22,9 @@ class CardTexture{
JTexture* tex;
JQuad* quad;
public:
int lastTime;
int type;
int nbpixels;
int lastTime;
int type;
int nbpixels;
int getId();
JQuad * getQuad();
@@ -39,18 +39,18 @@ class TexturesCache{
int lastTime;
int nb_textures;
int delete_previous;
int totalsize;
int totalsize;
CardTexture * cache[MAX_CACHE_OBJECTS];
public:
int isInCache(MTGCard * card, int type=CACHE_CARD);
TexturesCache();
~TexturesCache();
int getOldestQuad();
void removeQuad(int id);
int cleanup();
~TexturesCache();
int getOldestQuad();
void removeQuad(int id);
int cleanup();
int getCacheById(int id, int type=CACHE_CARD);
JQuad * getQuad(MTGCard * card, int type=CACHE_CARD);
JQuad * getThumb(MTGCard * card){return getQuad(card, CACHE_THUMB);};
JQuad * getThumb(MTGCard * card){return getQuad(card, CACHE_THUMB);};
};

View File

@@ -1,22 +1,22 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_
#if defined (WIN32) || defined (LINUX)
#define TESTSUITE 1
#endif
#ifdef _DEBUG
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define NEW new
#endif
#ifdef LINUX
#ifdef _DEBUG
#define OutputDebugString(val) (std::cerr << val);
#else
#define OutputDebugString(val) {}
#endif
#endif
#endif
#ifndef _DEBUG_H_
#define _DEBUG_H_
#if defined (WIN32) || defined (LINUX)
#define TESTSUITE 1
#endif
#ifdef _DEBUG
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define NEW new
#endif
#ifdef LINUX
#ifdef _DEBUG
#define OutputDebugString(val) (std::cerr << val);
#else
#define OutputDebugString(val) {}
#endif
#endif
#endif

View File

@@ -1,50 +1,50 @@
#ifndef _UTILS_H_
#define _UTILS_H_
#include <JGE.h>
#if defined (WIN32) || defined (LINUX)
#else
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspiofilemgr.h>
#include <pspdebug.h>
#include <psputility.h>
#include <pspgu.h>
#include <psprtc.h>
#endif
#include <math.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#define BUFSIZE 600
using std::string;
template <typename T, size_t N>
char ( &_ArraySizeHelper( T (&array)[N] ))[N];
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
int lowercase(string source);
int substr_copy(char *source, char *target, int start, int len);
int append_str(char * s1, char * s2, char * target);
int filesize(const char * filename);
int read_file (const char * filename, char * buffer, int filesize);
int readline (char * in_buffer, char * out_buffer, int cursor);
int readfile_to_ints(const char * filename, int * out_buffer);
#endif
#ifndef _UTILS_H_
#define _UTILS_H_
#include <JGE.h>
#if defined (WIN32) || defined (LINUX)
#else
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspiofilemgr.h>
#include <pspdebug.h>
#include <psputility.h>
#include <pspgu.h>
#include <psprtc.h>
#endif
#include <math.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#define BUFSIZE 600
using std::string;
template <typename T, size_t N>
char ( &_ArraySizeHelper( T (&array)[N] ))[N];
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
int lowercase(string source);
int substr_copy(char *source, char *target, int start, int len);
int append_str(char * s1, char * s2, char * target);
int filesize(const char * filename);
int read_file (const char * filename, char * buffer, int filesize);
int readline (char * in_buffer, char * out_buffer, int cursor);
int readfile_to_ints(const char * filename, int * out_buffer);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,129 +1,129 @@
#include "../include/debug.h"
#include "../include/AIStats.h"
#include "../include/GameObserver.h"
#include "../include/Player.h"
#include "../include/MTGCardInstance.h"
bool compare_aistats(AIStat * first, AIStat * second){
float damage1 = first->value / first->occurences;
float damage2 = second->value/ second->occurences;
return (damage1 > damage2);
}
AIStats::AIStats(Player * _player, char * _filename){
filename = _filename;
load(_filename);
player = _player;
}
AIStats::~AIStats(){
list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){
AIStat * stat = *it;
delete stat;
}
}
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);
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()){
//One of my creatures got lethal damage...
stat->value+= multiplier * STATS_CREATURE_MULTIPLIER * damage->damage;
}
}
}
void AIStats::updateStats(){
GameObserver * game = GameObserver::GetInstance();
ActionStack * as = game->mLayers->stackLayer();
Damage * damage = ((Damage * )as->getNext(NULL,ACTION_DAMAGE, RESOLVED_OK));
MTGGameZone * opponentZone = player->opponent()->game->inPlay;
while(damage){
MTGCardInstance * card = damage->source;
updateStatsCard(card,damage);
//Auras on damage source can be the cause
for (int i=0; i < opponentZone->nb_cards; i++){
MTGCardInstance * aura = opponentZone->cards[i];
if (aura->target == card){
updateStatsCard(aura,damage, STATS_AURA_MULTIPLIER);
}
}
damage = ((Damage * )as->getNext(damage,ACTION_DAMAGE, RESOLVED_OK));
}
stats.sort(compare_aistats);
save();
}
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;
AIStat * stat = *it;
if (stat->source == id){
if (stat->value>=0) return true;
return false;
}
n++;
}
return false;
}
AIStat * AIStats::find(MTGCard * source){
int id = source->getMTGId();
list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){
AIStat * stat = *it;
if (stat->source == id) return stat;
}
return NULL;
}
void AIStats::load(char * filename){
std::ifstream file(filename);
#include "../include/debug.h"
#include "../include/AIStats.h"
#include "../include/GameObserver.h"
#include "../include/Player.h"
#include "../include/MTGCardInstance.h"
bool compare_aistats(AIStat * first, AIStat * second){
float damage1 = first->value / first->occurences;
float damage2 = second->value/ second->occurences;
return (damage1 > damage2);
}
AIStats::AIStats(Player * _player, char * _filename){
filename = _filename;
load(_filename);
player = _player;
}
AIStats::~AIStats(){
list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){
AIStat * stat = *it;
delete stat;
}
}
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);
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()){
//One of my creatures got lethal damage...
stat->value+= multiplier * STATS_CREATURE_MULTIPLIER * damage->damage;
}
}
}
void AIStats::updateStats(){
GameObserver * game = GameObserver::GetInstance();
ActionStack * as = game->mLayers->stackLayer();
Damage * damage = ((Damage * )as->getNext(NULL,ACTION_DAMAGE, RESOLVED_OK));
MTGGameZone * opponentZone = player->opponent()->game->inPlay;
while(damage){
MTGCardInstance * card = damage->source;
updateStatsCard(card,damage);
//Auras on damage source can be the cause
for (int i=0; i < opponentZone->nb_cards; i++){
MTGCardInstance * aura = opponentZone->cards[i];
if (aura->target == card){
updateStatsCard(aura,damage, STATS_AURA_MULTIPLIER);
}
}
damage = ((Damage * )as->getNext(damage,ACTION_DAMAGE, RESOLVED_OK));
}
stats.sort(compare_aistats);
save();
}
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;
AIStat * stat = *it;
if (stat->source == id){
if (stat->value>=0) return true;
return false;
}
n++;
}
return false;
}
AIStat * AIStats::find(MTGCard * source){
int id = source->getMTGId();
list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){
AIStat * stat = *it;
if (stat->source == id) return stat;
}
return NULL;
}
void AIStats::load(char * filename){
std::ifstream file(filename);
std::string s;
if(file){
while(std::getline(file,s)){
int cardid = atoi(s.c_str());
std::getline(file,s);
int value = atoi(s.c_str());
std::getline(file,s);
int direct = atoi(s.c_str());
AIStat * stat = NEW AIStat(cardid,value,1,direct);
stats.push_back(stat);
}
file.close();
}else{
//TODO Error management
}
}
void AIStats::save(){
std::ofstream file(filename.c_str());
char writer[128];
if (file){
list<AIStat *>::iterator 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;
}
}
file.close();
}
if(file){
while(std::getline(file,s)){
int cardid = atoi(s.c_str());
std::getline(file,s);
int value = atoi(s.c_str());
std::getline(file,s);
int direct = atoi(s.c_str());
AIStat * stat = NEW AIStat(cardid,value,1,direct);
stats.push_back(stat);
}
file.close();
}else{
//TODO Error management
}
}
void AIStats::save(){
std::ofstream file(filename.c_str());
char writer[128];
if (file){
list<AIStat *>::iterator 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;
}
}
file.close();
}
}

View File

@@ -4,52 +4,52 @@
#include "../include/TargetChooser.h"
ActionElement::ActionElement(int id):JGuiObject(id){
activeState = INACTIVE;
modal = 0;
waitingForAnswer = 0;
currentPhase = -1;
newPhase = -1;
tc = NULL;
activeState = INACTIVE;
modal = 0;
waitingForAnswer = 0;
currentPhase = -1;
newPhase = -1;
tc = NULL;
}
/*
void ActionElement::RenderMessageBackground(float y0, int _height){
float height = _height;
PIXEL_TYPE colors_up[] =
{
ARGB(0,255,255,255),
ARGB(0,255,255,255),
ARGB(128,255,255,255),
ARGB(128,255,255,255)
};
void ActionElement::RenderMessageBackground(float y0, int _height){
float height = _height;
PIXEL_TYPE colors_up[] =
{
ARGB(0,255,255,255),
ARGB(0,255,255,255),
ARGB(128,255,255,255),
ARGB(128,255,255,255)
};
PIXEL_TYPE colors_down[] =
{
ARGB(128,255,255,255),
ARGB(128,255,255,255),
ARGB(0,255,255,255),
ARGB(0,255,255,255)
};
{
ARGB(128,255,255,255),
ARGB(128,255,255,255),
ARGB(0,255,255,255),
ARGB(0,255,255,255)
};
JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRect(0,y0,SCREEN_WIDTH,height/2,colors_up);
renderer->FillRect(0,y0+height/2,SCREEN_WIDTH,height/2,colors_down);
// mEngine->DrawLine(0,y0,SCREEN_WIDTH,y0,ARGB(128,255,255,255));
// mEngine->DrawLine(0,y0+height,SCREEN_WIDTH,y0+height,ARGB(128,255,255,255));
}*/
}*/
int ActionElement::getActivity(){
return activeState;
return activeState;
}
int ActionElement::isReactingToTargetClick(Targetable * object){
if (object && object->typeAsTarget() == TARGET_CARD) return isReactingToClick((MTGCardInstance *)object);
return 0;
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);
return 0;
}
if (object->typeAsTarget() == TARGET_CARD) return reactToClick((MTGCardInstance *)object);
return 0;
}

View File

@@ -5,195 +5,195 @@
int ActionLayer::unstopableRenderInProgress(){
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->getActivity() > 0){
return 1;
}
}
}
return 0;
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->getActivity() > 0){
return 1;
}
}
}
return 0;
}
void ActionLayer::CheckUserInput(float dt){
if (menuObject){
abilitiesMenu->Update(dt);
return;
}
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
currentAction->CheckUserInput(dt);
}
}
if (menuObject){
abilitiesMenu->Update(dt);
return;
}
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
currentAction->CheckUserInput(dt);
}
}
}
void ActionLayer::Update(float dt){
if (menuObject){
return;
}
modal = 0;
for (int i=mCount -1 ;i>=0;i--){
if (mObjects[i]!= NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->testDestroy()){
currentAction->destroy();
Remove(currentAction);
}
}
}
int newPhase = GameObserver::GetInstance()->getCurrentGamePhase();
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 (menuObject){
return;
}
modal = 0;
for (int i=mCount -1 ;i>=0;i--){
if (mObjects[i]!= NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->testDestroy()){
currentAction->destroy();
Remove(currentAction);
}
}
}
int newPhase = GameObserver::GetInstance()->getCurrentGamePhase();
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;
}
}
}
void ActionLayer::Render (){
if (menuObject){
abilitiesMenu->Render();
return;
}
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
//if (currentAction->getActivity() > 0){
currentAction->Render();
//return;
//}
}
}
if (menuObject){
abilitiesMenu->Render();
return;
}
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
//if (currentAction->getActivity() > 0){
currentAction->Render();
//return;
//}
}
}
}
TargetChooser * ActionLayer::getCurrentTargetChooser(){
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return currentAction->tc;
}
return NULL;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return currentAction->tc;
}
return NULL;
}
int ActionLayer::isWaitingForAnswer(){
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return 1;
}
return 0;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return 1;
}
return 0;
}
int ActionLayer::isReactingToTargetClick(Targetable * card){
int result = 0;
int result = 0;
if (isWaitingForAnswer()) return -1;
if (isWaitingForAnswer()) return -1;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToTargetClick(card);
}
return result;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToTargetClick(card);
}
return result;
}
int ActionLayer::reactToTargetClick(Targetable * card){
int result = 0;
int result = 0;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){
return currentAction->reactToTargetClick(card);
}
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){
return currentAction->reactToTargetClick(card);
}
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->reactToTargetClick(card);
}
return result;
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 result = 0;
int result = 0;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return -1;
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return -1;
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToClick(card);
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToClick(card);
}
return result;
return result;
}
int ActionLayer::reactToClick(MTGCardInstance * card){
int result = 0;
int result = 0;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){
return currentAction->reactToClick(card);
}
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){
return currentAction->reactToClick(card);
}
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->reactToClick(card);
}
return result;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->reactToClick(card);
}
return result;
}
int ActionLayer::isModal(){
if (modal) return 1;
if (menuObject) return 1;
for (int i=0; i<mCount; i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->modal) return 1;
}
return 0;
if (modal) return 1;
if (menuObject) return 1;
for (int i=0; i<mCount; i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->modal) return 1;
}
return 0;
}
void ActionLayer::setMenuObject(Targetable * object){
menuObject = object;
if (abilitiesMenu){
delete abilitiesMenu;
}
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
abilitiesMenu = NEW SimpleMenu(10, this, mFont, 100, 100, 200);
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->isReactingToTargetClick(object)){
abilitiesMenu->Add(i,currentAction->getMenuText());
}
}
abilitiesMenu->Add(-1, "Cancel");
modal = 1;
menuObject = object;
if (abilitiesMenu){
delete abilitiesMenu;
}
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
abilitiesMenu = NEW SimpleMenu(10, this, mFont, 100, 100, 200);
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->isReactingToTargetClick(object)){
abilitiesMenu->Add(i,currentAction->getMenuText());
}
}
abilitiesMenu->Add(-1, "Cancel");
modal = 1;
}
void ActionLayer::ButtonPressed(int controllerid, int controlid){
if (controlid == -1){
if (controlid == -1){
}else{
ActionElement * currentAction = (ActionElement *)mObjects[controlid];
currentAction->reactToTargetClick(menuObject);
}
menuObject = 0;
}else{
ActionElement * currentAction = (ActionElement *)mObjects[controlid];
currentAction->reactToTargetClick(menuObject);
}
menuObject = 0;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,117 +1,117 @@
#include "../include/debug.h"
#include "../include/Blocker.h"
Blocker::Blocker(int id, MTGCardInstance * card):MTGAbility(id, card){
init ( NEW ManaCost());
}
Blocker::Blocker(int id, MTGCardInstance * card, ManaCost * _cost):MTGAbility(id, card){
init(_cost);
}
Blocker::Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost):MTGAbility(id, card,_target){
init(_cost);
}
Blocker::~Blocker(){
delete manaCost;
}
void Blocker::init(ManaCost * _cost){
currentPhase = -1;
manaCost = _cost;
}
//Default behaviour for blockers : they block the card they're attached to
void Blocker::Update(float dt){
game = GameObserver::GetInstance();
int newPhase = game->getCurrentGamePhase();
if (newPhase != currentPhase){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getBlockers()->Add(this);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Adding Blocker to %s \n", _target->model->getName());
OutputDebugString(buf);
#endif
}
currentPhase = newPhase;
}
int Blocker::destroy(){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getBlockers()->Remove(this);
return 1;
}
Blockers::Blockers(){
init();
}
int Blockers::init(){
cursor = -1;
for (int i=0; i< MAX_BLOCKERS ; i++){
blockers[i] = 0;
}
return 1;
}
int Blockers::Add (Blocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 1;
return index;
}
int Blockers::Remove (Blocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 0;
return index;
}
int Blockers::rewind(){
cursor = -1;
return 1;
}
Blocker * Blockers::next(){
cursor++;
game = GameObserver::GetInstance();
while (blockers[cursor] == 0){
cursor ++;
if (cursor == MAX_BLOCKERS){
cursor = -1;
return NULL;
}
}
return (Blocker *) (game->mLayers->actionLayer()->getByIndex(cursor));
}
int Blockers::isEmpty(){
for (int i=0; i< MAX_BLOCKERS ; i++){
if (blockers[i])
return 0;
}
return 1;
}
Blockers::~Blockers(){
}
#include "../include/debug.h"
#include "../include/Blocker.h"
Blocker::Blocker(int id, MTGCardInstance * card):MTGAbility(id, card){
init ( NEW ManaCost());
}
Blocker::Blocker(int id, MTGCardInstance * card, ManaCost * _cost):MTGAbility(id, card){
init(_cost);
}
Blocker::Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost):MTGAbility(id, card,_target){
init(_cost);
}
Blocker::~Blocker(){
delete manaCost;
}
void Blocker::init(ManaCost * _cost){
currentPhase = -1;
manaCost = _cost;
}
//Default behaviour for blockers : they block the card they're attached to
void Blocker::Update(float dt){
game = GameObserver::GetInstance();
int newPhase = game->getCurrentGamePhase();
if (newPhase != currentPhase){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getBlockers()->Add(this);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Adding Blocker to %s \n", _target->model->getName());
OutputDebugString(buf);
#endif
}
currentPhase = newPhase;
}
int Blocker::destroy(){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getBlockers()->Remove(this);
return 1;
}
Blockers::Blockers(){
init();
}
int Blockers::init(){
cursor = -1;
for (int i=0; i< MAX_BLOCKERS ; i++){
blockers[i] = 0;
}
return 1;
}
int Blockers::Add (Blocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 1;
return index;
}
int Blockers::Remove (Blocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 0;
return index;
}
int Blockers::rewind(){
cursor = -1;
return 1;
}
Blocker * Blockers::next(){
cursor++;
game = GameObserver::GetInstance();
while (blockers[cursor] == 0){
cursor ++;
if (cursor == MAX_BLOCKERS){
cursor = -1;
return NULL;
}
}
return (Blocker *) (game->mLayers->actionLayer()->getByIndex(cursor));
}
int Blockers::isEmpty(){
for (int i=0; i< MAX_BLOCKERS ; i++){
if (blockers[i])
return 0;
}
return 1;
}
Blockers::~Blockers(){
}

View File

@@ -1,131 +1,131 @@
#include "../include/debug.h"
#include "../include/CardDescriptor.h"
CardDescriptor::CardDescriptor(): MTGCardInstance(){
init();
mode = CD_AND;
}
int CardDescriptor::init(){
return MTGCardInstance::init();
}
MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
int found = 1;
for (int i = 0; i< nb_types; i++){
found = 0;
if (card->hasSubtype(types[i])){
found = 1;
break;
}
}
if (!found) return NULL;
for (int i = 0; i< MTG_NB_COLORS; i++){
found = 0;
if (colors[i] == 1 && card->hasColor(i)){
found = 1;
break;
}
}
if (!found) return NULL;
return card;
}
MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){
#ifdef WIN32
OutputDebugString("Match AND\n");
#endif
MTGCardInstance * match = card;
for (int i = 0; i< nb_types; i++){
if (!card->hasSubtype(types[i])){
#ifdef WIN32
OutputDebugString(card->name.c_str());
OutputDebugString("Subtype No Match\n");
#endif
match = NULL;
}
}
for (int i = 0; i< MTG_NB_COLORS; i++){
if ((colors[i] == 1 && !card->hasColor(i))||(colors[i] == -1 && card->hasColor(i))){
match = NULL;
#ifdef WIN32
OutputDebugString(card->name.c_str());
OutputDebugString("Color No Match\n");
#endif
}
}
return match;
}
MTGCardInstance * CardDescriptor::match(MTGCardInstance * card){
MTGCardInstance * match = card;
if (mode == CD_AND){
match = match_and(card);
}else{
match=match_or(card);
}
//Abilities
for (int j = 0; j < NB_BASIC_ABILITIES; 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())){
match = NULL;
}
if (attacker == 1){
if ((int)defenser == 1){
if (!card->attacker && !card->defenser) match = NULL;
}else{
if (!card->attacker) match = NULL;
}
}else if (attacker == -1){
if ((int)defenser == -1){
if (card->attacker || card->defenser) match = NULL;
}else{
if (card->attacker) match = NULL;
}
}else{
if ((int)defenser == -1){
if (card->defenser) match = NULL;
}else if ((int)defenser == 1){
if (!card->defenser) match = NULL;
}else{
// we don't care about the attack/blocker state
}
}
return match;
}
MTGCardInstance * CardDescriptor::match(MTGGameZone * zone){
return (nextmatch(zone, NULL));
}
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 defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf,"Card Descriptor MATCH!: %s \n" ,(zone->cards[i])->getName());
OutputDebugString(buf);
#endif
return zone->cards[i];
}
if (zone->cards[i] == previous){
found = 1;
}
}
return NULL;
}
#include "../include/debug.h"
#include "../include/CardDescriptor.h"
CardDescriptor::CardDescriptor(): MTGCardInstance(){
init();
mode = CD_AND;
}
int CardDescriptor::init(){
return MTGCardInstance::init();
}
MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
int found = 1;
for (int i = 0; i< nb_types; i++){
found = 0;
if (card->hasSubtype(types[i])){
found = 1;
break;
}
}
if (!found) return NULL;
for (int i = 0; i< MTG_NB_COLORS; i++){
found = 0;
if (colors[i] == 1 && card->hasColor(i)){
found = 1;
break;
}
}
if (!found) return NULL;
return card;
}
MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){
#ifdef WIN32
OutputDebugString("Match AND\n");
#endif
MTGCardInstance * match = card;
for (int i = 0; i< nb_types; i++){
if (!card->hasSubtype(types[i])){
#ifdef WIN32
OutputDebugString(card->name.c_str());
OutputDebugString("Subtype No Match\n");
#endif
match = NULL;
}
}
for (int i = 0; i< MTG_NB_COLORS; i++){
if ((colors[i] == 1 && !card->hasColor(i))||(colors[i] == -1 && card->hasColor(i))){
match = NULL;
#ifdef WIN32
OutputDebugString(card->name.c_str());
OutputDebugString("Color No Match\n");
#endif
}
}
return match;
}
MTGCardInstance * CardDescriptor::match(MTGCardInstance * card){
MTGCardInstance * match = card;
if (mode == CD_AND){
match = match_and(card);
}else{
match=match_or(card);
}
//Abilities
for (int j = 0; j < NB_BASIC_ABILITIES; 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())){
match = NULL;
}
if (attacker == 1){
if ((int)defenser == 1){
if (!card->attacker && !card->defenser) match = NULL;
}else{
if (!card->attacker) match = NULL;
}
}else if (attacker == -1){
if ((int)defenser == -1){
if (card->attacker || card->defenser) match = NULL;
}else{
if (card->attacker) match = NULL;
}
}else{
if ((int)defenser == -1){
if (card->defenser) match = NULL;
}else if ((int)defenser == 1){
if (!card->defenser) match = NULL;
}else{
// we don't care about the attack/blocker state
}
}
return match;
}
MTGCardInstance * CardDescriptor::match(MTGGameZone * zone){
return (nextmatch(zone, NULL));
}
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 defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf,"Card Descriptor MATCH!: %s \n" ,(zone->cards[i])->getName());
OutputDebugString(buf);
#endif
return zone->cards[i];
}
if (zone->cards[i] == previous){
found = 1;
}
}
return NULL;
}

View File

@@ -1,156 +1,156 @@
#include "../include/debug.h"
#include "../include/CardDisplay.h"
#include "../include/CardGui.h"
#include "../include/TargetChooser.h"
#include "../include/MTGGameZones.h"
CardDisplay::CardDisplay():PlayGuiObjectController(0, GameObserver::GetInstance()){
tc= NULL;
listener = NULL;
nb_displayed_items = 7;
start_item = 0;
x= 0;
y= 0;
}
CardDisplay::CardDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc, int _nb_displayed_items ):PlayGuiObjectController(id, _game), x(_x), y(_y){
tc= _tc;
listener = _listener;
nb_displayed_items = _nb_displayed_items;
start_item = 0;
}
void CardDisplay::AddCard(MTGCardInstance * _card){
CardGui * card = NEW CardGui(mCount, _card, 40, x + 5 + (mCount - start_item) * 30, y + 5, (mCount == 0));
Add(card);
}
void CardDisplay::init(MTGGameZone * zone){
resetObjects();
start_item = 0;
for (int i= 0; i< zone->nb_cards; i++){
AddCard(zone->cards[i]);
}
}
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 --;
}
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 ++;
}
void CardDisplay::CheckUserInput(float dt){
if (mEngine->GetButtonClick(PSP_CTRL_CROSS))
{
if (listener != NULL)
{
listener->ButtonPressed(mId, 0);
return;
}
}
if (!mCount)
return;
#include "../include/debug.h"
#include "../include/CardDisplay.h"
#include "../include/CardGui.h"
#include "../include/TargetChooser.h"
#include "../include/MTGGameZones.h"
if (mEngine->GetButtonClick(mActionButton))
{
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
CardGui * cardg = (CardGui *)mObjects[mCurr];
if (tc)
{
tc->toggleTarget(cardg->card);
return;
}else{
if (game) game->ButtonPressed(mId, cardg);
return;
}
}
}
CardDisplay::CardDisplay():PlayGuiObjectController(0, GameObserver::GetInstance()){
tc= NULL;
listener = NULL;
nb_displayed_items = 7;
start_item = 0;
x= 0;
y= 0;
}
if (mEngine->GetButtonState(PSP_CTRL_LEFT))
{
if (KeyRepeated(PSP_CTRL_LEFT, dt))
{
int n = mCurr;
n--;
if (n<start_item){
if (n< 0){n = 0;}
else{ rotateLeft();}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_LEFT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
}
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT))
{
if (KeyRepeated(PSP_CTRL_RIGHT, dt))
{
int n = mCurr;
n++;
if (n>= mCount){n = mCount-1;}
if (n>= start_item + nb_displayed_items){
rotateRight();
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_RIGHT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
}
}
CardDisplay::CardDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc, int _nb_displayed_items ):PlayGuiObjectController(id, _game), x(_x), y(_y){
tc= _tc;
listener = _listener;
nb_displayed_items = _nb_displayed_items;
start_item = 0;
}
else{
mLastKey = 0;
void CardDisplay::AddCard(MTGCardInstance * _card){
CardGui * card = NEW CardGui(mCount, _card, 40, x + 5 + (mCount - start_item) * 30, y + 5, (mCount == 0));
Add(card);
}
void CardDisplay::init(MTGGameZone * zone){
resetObjects();
start_item = 0;
for (int i= 0; i< zone->nb_cards; i++){
AddCard(zone->cards[i]);
}
}
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 --;
}
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 ++;
}
void CardDisplay::CheckUserInput(float dt){
if (mEngine->GetButtonClick(PSP_CTRL_CROSS))
{
if (listener != NULL)
{
listener->ButtonPressed(mId, 0);
return;
}
}
void CardDisplay::Render(){
JRenderer * r = JRenderer::GetInstance();
r->DrawRect(x,y,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]){
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 (mObjects[mCurr]){
mObjects[mCurr]->Render();
}
}
DefaultTargetDisplay::DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y,JGuiListener * _listener, int _nb_displayed_items ):CardDisplay(id, _game, _x, _y, _listener, NULL, _nb_displayed_items ){
tc = NEW TargetChooser();
}
DefaultTargetDisplay::~DefaultTargetDisplay(){
SAFE_DELETE(tc);
}
}
if (!mCount)
return;
if (mEngine->GetButtonClick(mActionButton))
{
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
CardGui * cardg = (CardGui *)mObjects[mCurr];
if (tc)
{
tc->toggleTarget(cardg->card);
return;
}else{
if (game) game->ButtonPressed(mId, cardg);
return;
}
}
}
if (mEngine->GetButtonState(PSP_CTRL_LEFT))
{
if (KeyRepeated(PSP_CTRL_LEFT, dt))
{
int n = mCurr;
n--;
if (n<start_item){
if (n< 0){n = 0;}
else{ rotateLeft();}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_LEFT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
}
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT))
{
if (KeyRepeated(PSP_CTRL_RIGHT, dt))
{
int n = mCurr;
n++;
if (n>= mCount){n = mCount-1;}
if (n>= start_item + nb_displayed_items){
rotateRight();
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_RIGHT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
}
}
else{
mLastKey = 0;
}
}
void CardDisplay::Render(){
JRenderer * r = JRenderer::GetInstance();
r->DrawRect(x,y,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]){
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 (mObjects[mCurr]){
mObjects[mCurr]->Render();
}
}
DefaultTargetDisplay::DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y,JGuiListener * _listener, int _nb_displayed_items ):CardDisplay(id, _game, _x, _y, _listener, NULL, _nb_displayed_items ){
tc = NEW TargetChooser();
}
DefaultTargetDisplay::~DefaultTargetDisplay(){
SAFE_DELETE(tc);
}

View File

@@ -1,318 +1,318 @@
#include "../include/debug.h"
#include "../include/CardGui.h"
#include <Vector2D.h>
void CardGui::alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation, float scale){
JQuad * mIcons[7];
if (!manaIcons){
mIcons[MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact");
mIcons[MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land");
mIcons[MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white");
mIcons[MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red");
mIcons[MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black");
mIcons[MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue");
mIcons[MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
manaIcons = mIcons;
}
Vector2D v;
Vector2D points[4];
PIXEL_TYPE bgcolor = ARGB(255,128,128,128);
PIXEL_TYPE bgcolor2 = ARGB(255,80,80,80);
char buf[25];
int width = 200;
int height = 285;
JRenderer * renderer = JRenderer::GetInstance();
mFont->SetRotation(rotation);
mFont->SetScale(scale);
int color = card->getColor();
points[0].x = -width/2;
points[0].y = -height/2 ;
points[1].x = width/2;
points[1].y = -height/2;
points[2].x = width/2;
points[2].y = height/2;
points[3].x = -width/2;
points[3].y = height/2;
for (int i=0; i < 4; i++){
points[i].x *= scale;
points[i].y *= scale;
points[i].Rotate(rotation);
}
if (rotation == 0){
renderer->FillRoundRect(x+points[0].x + 2 ,y+points[0].y +2 ,width*scale-8,height*scale-8,2,ARGB(255,_r[color],_g[color],_b[color]));
renderer->FillRect(x+points[0].x + 6 ,y+points[0].y + 6 ,width*scale-12,height*scale-12,bgcolor2);
}else{
for (int i=0; i < 4; i++){
renderer->DrawLine(x + points[i].x,y + points[i].y,x + points[(i+1)%4].x,y + points[(i+1)%4].y,bgcolor);
}
}
ManaCost * manacost = card->getManaCost();
int nbicons = 0;
for (int i = 1; i < MTG_NB_COLORS - 1; i++){
int cost = manacost->getCost(i);
for (int j=0; j < cost; j++){
v.x = (width/2 - 20 - 16*nbicons)*scale;
v.y = ((-height/2) + 20) * scale;
v.Rotate(rotation);
renderer->RenderQuad(manaIcons[i],x+v.x,y+v.y,rotation,0.5*scale, 0.5*scale);
nbicons++;
}
}
int cost = manacost->getCost(0);
if (cost !=0){
v.x = (width/2 - 20 - 16*nbicons)*scale;
v.y = ((-height/2) + 14) * scale;
v.Rotate(rotation);
sprintf(buf,"%i",cost);
mFont->DrawString(buf,x+v.x,y+v.y);
}
if (!card->formattedTextInit){
std::string s(card->getText());
unsigned int found=s.find_first_of("{}");
while (found!=string::npos)
{
s[found]='/';
found=s.find_first_of("{}",found+1);
}
int len = 24;
while (s.length() > 0){
int cut = s.find_first_of("., \t)", 0);
if (cut >= len || cut == -1){
card->formattedText.push_back(s.substr(0,len));
if ((signed int)s.length() > len){
s = s.substr(len,s.length()-len);
}else{
s = "";
}
}else{
int newcut = cut;
while (newcut < len && newcut != -1){
cut = newcut;
newcut = s.find_first_of("., \t)", newcut + 1);
}
card->formattedText.push_back(s.substr(0,cut+1));
if ((signed int)s.length() > cut+1){
s = s.substr(cut+1,s.length()- cut - 1);
}else{
s = "";
}
}
}
card->formattedTextInit = 1;
}
for (unsigned int i=0; i < card->formattedText.size(); i++){
sprintf(buf, "%s", card->formattedText[i].c_str());
v.x = (-width/2 + 12 )*scale;
v.y = ((-height/2) + 50 + 16*i) * scale;
v.Rotate(rotation);
mFont->DrawString(buf,x+v.x,y+v.y);
}
v.x = ((-width/2)+10) * scale;
v.y = ((-height/2) + 25) * scale;
v.Rotate(rotation);
int over = strlen(card->getName()) - 23;
float multiply = 1.4;
if (over > 0){
multiply = 1.1;
}
mFont->SetScale(scale * multiply);
mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color]));
mFont->DrawString(card->getName(),x+v.x,y+v.y);
mFont->SetScale(scale);
mFont->SetColor(ARGB(255,255,255,255));
if (card->isACreature()){
v.x = (width/2-40) * scale;
v.y = (height/2-30) * scale;
v.Rotate(rotation);
sprintf(buf,"%i/%i",card->power,card->toughness);
mFont->DrawString(buf,x+v.x,y+v.y);
}
}
CardGui::CardGui(int id, MTGCardInstance * _card, float desiredHeight,float _x, float _y, bool hasFocus): PlayGuiObject(id, desiredHeight, _x, _y, hasFocus){
LOG("==Creating NEW CardGui Object. CardName:");
LOG(_card->getName());
card = _card;
type = GUI_CARD;
alpha = 255;
mParticleSys = NULL;
if (card->hasColor(MTG_COLOR_RED)){
mParticleSys = GameApp::Particles[3];
}else if (card->hasColor(MTG_COLOR_BLUE)){
mParticleSys = GameApp::Particles[1];
}else if (card->hasColor(MTG_COLOR_GREEN)){
mParticleSys = GameApp::Particles[2];
}else if (card->hasColor(MTG_COLOR_BLACK)){
mParticleSys = GameApp::Particles[4];
}else if (card->hasColor(MTG_COLOR_WHITE)){
mParticleSys = GameApp::Particles[0];
}else{
mParticleSys = GameApp::Particles[5];
}
LOG("==CardGui Object Creation Succesfull");
}
void CardGui::Update(float dt){
alpha = 255;
if (card->changedZoneRecently > 0) alpha = 255.f - 255.f * card->changedZoneRecently;
if (mParticleSys && card->changedZoneRecently == 1.f){
mParticleSys->MoveTo(x+15, y+2*mHeight/3);
mParticleSys->Fire();
}
if (card->changedZoneRecently){
if (mParticleSys) mParticleSys->Update(dt);
card->changedZoneRecently-= (5 *dt);
if (card->changedZoneRecently < 0){
if (mParticleSys) mParticleSys->Stop();
}
if (card->changedZoneRecently < -3){
card->changedZoneRecently = 0;
mParticleSys = NULL;
}
}
PlayGuiObject::Update(dt);
}
void CardGui::RenderBig(float xpos, float ypos){
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getQuad();
if (xpos == -1){
xpos = 300;
if (x > SCREEN_WIDTH / 2)
xpos = 10;
}
if(ypos == -1)
ypos = 20;
if (quad){
quad->SetColor(ARGB(220,255,255,255));
renderer->RenderQuad(quad, xpos , ypos , 0.0f,0.9f,0.9f);
}else{
MTGCard * mtgcard = card->model;
JLBFont * font = GameApp::CommonRes->GetJLBFont("graphics/magic");
CardGui::alternateRender(mtgcard, font, NULL, xpos + 90 , ypos + 130, 0.0f,0.9f);
}
}
void CardGui::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getThumb();
if (!quad || quad->mHeight * 2 < mHeight){
JQuad * quad2 = card->getQuad();
if (quad2)
quad = quad2;
}
float tap = (float)(card->isTapped());
float rotation = M_PI_2 * tap;
if (quad){
float mScale = mHeight / quad->mHeight;
float myX = x + (quad->mHeight/2 * tap * mScale);
float myY = y+(quad->mWidth/2 * tap * mScale);
if (mHeight-defaultHeight){
if (card->isTapped()){
renderer->FillRect(myX + 1*(mHeight-defaultHeight) - quad->mHeight * mScale , myY + 1*(mHeight-defaultHeight) , quad->mHeight * mScale, quad->mWidth * mScale, ARGB(128,0,0,0));
}else{
renderer->FillRect(myX + 1*(mHeight-defaultHeight) , myY + 1*(mHeight-defaultHeight) , quad->mWidth * mScale, quad->mHeight * mScale, ARGB(128,0,0,0));
}
}
quad->SetColor(ARGB( alpha,255,255,255));
GameObserver * game = GameObserver::GetInstance();
TargetChooser * tc = NULL;
if (game) tc = game->getCurrentTargetChooser();
if (tc){
if (!tc->canTarget(card)){
quad->SetColor(ARGB( alpha,50,50,50));
}
}
renderer->RenderQuad(quad, myX , myY , rotation,mScale,mScale);
if (tc && tc->alreadyHasTarget(card)){
if (card->isTapped()){
renderer->FillRect(myX- quad->mHeight * mScale , myY , quad->mHeight * mScale, quad->mWidth * mScale, ARGB(128,255,0,0));
}else{
renderer->FillRect(myX , myY , quad->mWidth * mScale, quad->mHeight * mScale, ARGB(128,255,0,0));
}
}
quad->SetColor(ARGB( alpha,255,255,255));
}else{
int color = card->getColor();
float mScale = mHeight / 64;
float myX = x + (32 * tap * mScale);
float myY = y+(20 * tap * mScale);
char buffer[200];
sprintf(buffer, "%s",card->getName());
mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color]));
if (card->isTapped()){
renderer->FillRect(myX - 64 * mScale , myY , 64 * mScale, 40 * mScale, ARGB(255,0,0,0));
renderer->DrawRect(myX - 64 * mScale , myY , 64 * mScale, 40 * mScale, ARGB(255,_r[color],_g[color],_b[color]));
mFont->SetScale(0.20);
mFont->DrawString(buffer,myX - (64 * mScale)+4,myY + 1);
}else{
renderer->FillRect(myX , myY , 40 * mScale, 64 * mScale, ARGB(255,0,0,0));
renderer->DrawRect(myX , myY , 40 * mScale, 64 * mScale, ARGB(255,_r[color],_g[color],_b[color]));
mFont->SetScale(0.40);
mFont->DrawString(buffer,myX+4,myY + 1);
}
mFont->SetScale(1.0);
}
if (card->isACreature()){
mFont->SetScale(0.75);
char buffer[200];
sprintf(buffer, "%i/%i",card->power,card->life);
renderer->FillRect(x+2,y + mHeight - 12, 25 , 12 ,ARGB(128,0,0,0));
mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buffer,x+4,y + mHeight - 10);
}
if (mParticleSys && card->changedZoneRecently > 0){
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
mParticleSys->Render();
// set normal blending
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
}
}
CardGui::~CardGui(){
LOG("==Destroying CardGui object");
LOG(this->card->getName());
LOG("==CardGui object destruction Successful");
}
#include "../include/debug.h"
#include "../include/CardGui.h"
#include <Vector2D.h>
void CardGui::alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation, float scale){
JQuad * mIcons[7];
if (!manaIcons){
mIcons[MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact");
mIcons[MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land");
mIcons[MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white");
mIcons[MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red");
mIcons[MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black");
mIcons[MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue");
mIcons[MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
manaIcons = mIcons;
}
Vector2D v;
Vector2D points[4];
PIXEL_TYPE bgcolor = ARGB(255,128,128,128);
PIXEL_TYPE bgcolor2 = ARGB(255,80,80,80);
char buf[25];
int width = 200;
int height = 285;
JRenderer * renderer = JRenderer::GetInstance();
mFont->SetRotation(rotation);
mFont->SetScale(scale);
int color = card->getColor();
points[0].x = -width/2;
points[0].y = -height/2 ;
points[1].x = width/2;
points[1].y = -height/2;
points[2].x = width/2;
points[2].y = height/2;
points[3].x = -width/2;
points[3].y = height/2;
for (int i=0; i < 4; i++){
points[i].x *= scale;
points[i].y *= scale;
points[i].Rotate(rotation);
}
if (rotation == 0){
renderer->FillRoundRect(x+points[0].x + 2 ,y+points[0].y +2 ,width*scale-8,height*scale-8,2,ARGB(255,_r[color],_g[color],_b[color]));
renderer->FillRect(x+points[0].x + 6 ,y+points[0].y + 6 ,width*scale-12,height*scale-12,bgcolor2);
}else{
for (int i=0; i < 4; i++){
renderer->DrawLine(x + points[i].x,y + points[i].y,x + points[(i+1)%4].x,y + points[(i+1)%4].y,bgcolor);
}
}
ManaCost * manacost = card->getManaCost();
int nbicons = 0;
for (int i = 1; i < MTG_NB_COLORS - 1; i++){
int cost = manacost->getCost(i);
for (int j=0; j < cost; j++){
v.x = (width/2 - 20 - 16*nbicons)*scale;
v.y = ((-height/2) + 20) * scale;
v.Rotate(rotation);
renderer->RenderQuad(manaIcons[i],x+v.x,y+v.y,rotation,0.5*scale, 0.5*scale);
nbicons++;
}
}
int cost = manacost->getCost(0);
if (cost !=0){
v.x = (width/2 - 20 - 16*nbicons)*scale;
v.y = ((-height/2) + 14) * scale;
v.Rotate(rotation);
sprintf(buf,"%i",cost);
mFont->DrawString(buf,x+v.x,y+v.y);
}
if (!card->formattedTextInit){
std::string s(card->getText());
unsigned int found=s.find_first_of("{}");
while (found!=string::npos)
{
s[found]='/';
found=s.find_first_of("{}",found+1);
}
int len = 24;
while (s.length() > 0){
int cut = s.find_first_of("., \t)", 0);
if (cut >= len || cut == -1){
card->formattedText.push_back(s.substr(0,len));
if ((signed int)s.length() > len){
s = s.substr(len,s.length()-len);
}else{
s = "";
}
}else{
int newcut = cut;
while (newcut < len && newcut != -1){
cut = newcut;
newcut = s.find_first_of("., \t)", newcut + 1);
}
card->formattedText.push_back(s.substr(0,cut+1));
if ((signed int)s.length() > cut+1){
s = s.substr(cut+1,s.length()- cut - 1);
}else{
s = "";
}
}
}
card->formattedTextInit = 1;
}
for (unsigned int i=0; i < card->formattedText.size(); i++){
sprintf(buf, "%s", card->formattedText[i].c_str());
v.x = (-width/2 + 12 )*scale;
v.y = ((-height/2) + 50 + 16*i) * scale;
v.Rotate(rotation);
mFont->DrawString(buf,x+v.x,y+v.y);
}
v.x = ((-width/2)+10) * scale;
v.y = ((-height/2) + 25) * scale;
v.Rotate(rotation);
int over = strlen(card->getName()) - 23;
float multiply = 1.4;
if (over > 0){
multiply = 1.1;
}
mFont->SetScale(scale * multiply);
mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color]));
mFont->DrawString(card->getName(),x+v.x,y+v.y);
mFont->SetScale(scale);
mFont->SetColor(ARGB(255,255,255,255));
if (card->isACreature()){
v.x = (width/2-40) * scale;
v.y = (height/2-30) * scale;
v.Rotate(rotation);
sprintf(buf,"%i/%i",card->power,card->toughness);
mFont->DrawString(buf,x+v.x,y+v.y);
}
}
CardGui::CardGui(int id, MTGCardInstance * _card, float desiredHeight,float _x, float _y, bool hasFocus): PlayGuiObject(id, desiredHeight, _x, _y, hasFocus){
LOG("==Creating NEW CardGui Object. CardName:");
LOG(_card->getName());
card = _card;
type = GUI_CARD;
alpha = 255;
mParticleSys = NULL;
if (card->hasColor(MTG_COLOR_RED)){
mParticleSys = GameApp::Particles[3];
}else if (card->hasColor(MTG_COLOR_BLUE)){
mParticleSys = GameApp::Particles[1];
}else if (card->hasColor(MTG_COLOR_GREEN)){
mParticleSys = GameApp::Particles[2];
}else if (card->hasColor(MTG_COLOR_BLACK)){
mParticleSys = GameApp::Particles[4];
}else if (card->hasColor(MTG_COLOR_WHITE)){
mParticleSys = GameApp::Particles[0];
}else{
mParticleSys = GameApp::Particles[5];
}
LOG("==CardGui Object Creation Succesfull");
}
void CardGui::Update(float dt){
alpha = 255;
if (card->changedZoneRecently > 0) alpha = 255.f - 255.f * card->changedZoneRecently;
if (mParticleSys && card->changedZoneRecently == 1.f){
mParticleSys->MoveTo(x+15, y+2*mHeight/3);
mParticleSys->Fire();
}
if (card->changedZoneRecently){
if (mParticleSys) mParticleSys->Update(dt);
card->changedZoneRecently-= (5 *dt);
if (card->changedZoneRecently < 0){
if (mParticleSys) mParticleSys->Stop();
}
if (card->changedZoneRecently < -3){
card->changedZoneRecently = 0;
mParticleSys = NULL;
}
}
PlayGuiObject::Update(dt);
}
void CardGui::RenderBig(float xpos, float ypos){
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getQuad();
if (xpos == -1){
xpos = 300;
if (x > SCREEN_WIDTH / 2)
xpos = 10;
}
if(ypos == -1)
ypos = 20;
if (quad){
quad->SetColor(ARGB(220,255,255,255));
renderer->RenderQuad(quad, xpos , ypos , 0.0f,0.9f,0.9f);
}else{
MTGCard * mtgcard = card->model;
JLBFont * font = GameApp::CommonRes->GetJLBFont("graphics/magic");
CardGui::alternateRender(mtgcard, font, NULL, xpos + 90 , ypos + 130, 0.0f,0.9f);
}
}
void CardGui::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getThumb();
if (!quad || quad->mHeight * 2 < mHeight){
JQuad * quad2 = card->getQuad();
if (quad2)
quad = quad2;
}
float tap = (float)(card->isTapped());
float rotation = M_PI_2 * tap;
if (quad){
float mScale = mHeight / quad->mHeight;
float myX = x + (quad->mHeight/2 * tap * mScale);
float myY = y+(quad->mWidth/2 * tap * mScale);
if (mHeight-defaultHeight){
if (card->isTapped()){
renderer->FillRect(myX + 1*(mHeight-defaultHeight) - quad->mHeight * mScale , myY + 1*(mHeight-defaultHeight) , quad->mHeight * mScale, quad->mWidth * mScale, ARGB(128,0,0,0));
}else{
renderer->FillRect(myX + 1*(mHeight-defaultHeight) , myY + 1*(mHeight-defaultHeight) , quad->mWidth * mScale, quad->mHeight * mScale, ARGB(128,0,0,0));
}
}
quad->SetColor(ARGB( alpha,255,255,255));
GameObserver * game = GameObserver::GetInstance();
TargetChooser * tc = NULL;
if (game) tc = game->getCurrentTargetChooser();
if (tc){
if (!tc->canTarget(card)){
quad->SetColor(ARGB( alpha,50,50,50));
}
}
renderer->RenderQuad(quad, myX , myY , rotation,mScale,mScale);
if (tc && tc->alreadyHasTarget(card)){
if (card->isTapped()){
renderer->FillRect(myX- quad->mHeight * mScale , myY , quad->mHeight * mScale, quad->mWidth * mScale, ARGB(128,255,0,0));
}else{
renderer->FillRect(myX , myY , quad->mWidth * mScale, quad->mHeight * mScale, ARGB(128,255,0,0));
}
}
quad->SetColor(ARGB( alpha,255,255,255));
}else{
int color = card->getColor();
float mScale = mHeight / 64;
float myX = x + (32 * tap * mScale);
float myY = y+(20 * tap * mScale);
char buffer[200];
sprintf(buffer, "%s",card->getName());
mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color]));
if (card->isTapped()){
renderer->FillRect(myX - 64 * mScale , myY , 64 * mScale, 40 * mScale, ARGB(255,0,0,0));
renderer->DrawRect(myX - 64 * mScale , myY , 64 * mScale, 40 * mScale, ARGB(255,_r[color],_g[color],_b[color]));
mFont->SetScale(0.20);
mFont->DrawString(buffer,myX - (64 * mScale)+4,myY + 1);
}else{
renderer->FillRect(myX , myY , 40 * mScale, 64 * mScale, ARGB(255,0,0,0));
renderer->DrawRect(myX , myY , 40 * mScale, 64 * mScale, ARGB(255,_r[color],_g[color],_b[color]));
mFont->SetScale(0.40);
mFont->DrawString(buffer,myX+4,myY + 1);
}
mFont->SetScale(1.0);
}
if (card->isACreature()){
mFont->SetScale(0.75);
char buffer[200];
sprintf(buffer, "%i/%i",card->power,card->life);
renderer->FillRect(x+2,y + mHeight - 12, 25 , 12 ,ARGB(128,0,0,0));
mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buffer,x+4,y + mHeight - 10);
}
if (mParticleSys && card->changedZoneRecently > 0){
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
mParticleSys->Render();
// set normal blending
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
}
}
CardGui::~CardGui(){
LOG("==Destroying CardGui object");
LOG(this->card->getName());
LOG("==CardGui object destruction Successful");
}

View File

@@ -1,41 +1,41 @@
#include "../include/debug.h"
#include "../include/ConstraintResolver.h"
int ConstraintResolver::untap(GameObserver * game, MTGCardInstance * card){
if (!card->isUntapping()){
return 0;
}
int ok = 1;
ManaCost * untapManaCost = NEW ManaCost();
Blockers * blockers = card->getBlockers();
Blocker * blocker;
blockers->rewind();
Player * player = game->currentPlayer;
while ((blocker = blockers->next())){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "next\n");
OutputDebugString(buf);
#endif
untapManaCost->add(blocker->untapManaCost());
}
if (player->getManaPool()->canAfford(untapManaCost)){
blockers->rewind();
while ((blocker = blockers->next())){
if (!blocker->unblock()){
ok = 0;
break;
}
}
}else{
ok = 0;
}
if (ok) {
player->getManaPool()->pay(untapManaCost);
card->untap();
}
delete untapManaCost;
return ok;
}
#include "../include/debug.h"
#include "../include/ConstraintResolver.h"
int ConstraintResolver::untap(GameObserver * game, MTGCardInstance * card){
if (!card->isUntapping()){
return 0;
}
int ok = 1;
ManaCost * untapManaCost = NEW ManaCost();
Blockers * blockers = card->getBlockers();
Blocker * blocker;
blockers->rewind();
Player * player = game->currentPlayer;
while ((blocker = blockers->next())){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "next\n");
OutputDebugString(buf);
#endif
untapManaCost->add(blocker->untapManaCost());
}
if (player->getManaPool()->canAfford(untapManaCost)){
blockers->rewind();
while ((blocker = blockers->next())){
if (!blocker->unblock()){
ok = 0;
break;
}
}
}else{
ok = 0;
}
if (ok) {
player->getManaPool()->pay(untapManaCost);
card->untap();
}
delete untapManaCost;
return ok;
}

View File

@@ -1,120 +1,120 @@
#include "../include/Counters.h"
#include "../include/debug.h"
#include "../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);
}
int Counter::init(MTGCardInstance * _target,const char * _name, int _power, int _toughness){
target = _target;
name = _name;
power = _power;
toughness = _toughness;
nb = 1;
return 1;
}
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;
return (power == -_power && toughness == -_toughness);
}
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;
target->addToToughness(-toughness);
}
return 1;
}
Counters::Counters(MTGCardInstance * _target):target(_target){
mCount = 0;
}
Counters::~Counters(){
for (int i = 0; i < mCount; i++){
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){
counters[i]->removed();
counters[i]->nb--;
return mCount;
}
}
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);
counters[mCount] = counter;
counter->added();
mCount++;
return mCount;
}
int Counters::addCounter(int _power, int _toughness){
return addCounter("",_power, _toughness);
}
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;
}
}
return 0;
}
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];
}
}
return NULL;
}
Counter * Counters::hasCounter(int _power , int _toughness ){
return hasCounter("",_power, _toughness);
}
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;
}
return NULL;
}
#include "../include/Counters.h"
#include "../include/debug.h"
#include "../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);
}
int Counter::init(MTGCardInstance * _target,const char * _name, int _power, int _toughness){
target = _target;
name = _name;
power = _power;
toughness = _toughness;
nb = 1;
return 1;
}
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;
return (power == -_power && toughness == -_toughness);
}
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;
target->addToToughness(-toughness);
}
return 1;
}
Counters::Counters(MTGCardInstance * _target):target(_target){
mCount = 0;
}
Counters::~Counters(){
for (int i = 0; i < mCount; i++){
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){
counters[i]->removed();
counters[i]->nb--;
return mCount;
}
}
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);
counters[mCount] = counter;
counter->added();
mCount++;
return mCount;
}
int Counters::addCounter(int _power, int _toughness){
return addCounter("",_power, _toughness);
}
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;
}
}
return 0;
}
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];
}
}
return NULL;
}
Counter * Counters::hasCounter(int _power , int _toughness ){
return hasCounter("",_power, _toughness);
}
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;
}
return NULL;
}

View File

@@ -1,142 +1,142 @@
#include "../include/debug.h"
#include "../include/Damage.h"
#include "../include/MTGCardInstance.h"
#include "../include/Counters.h"
Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target): Interruptible(id){
init(_source, _target, _source->getPower());
}
Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target, int _damage): Interruptible(id){
init(_source, _target, _damage);
}
void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage){
target = _target;
source = _source;
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
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){
MTGCardInstance * _target = (MTGCardInstance *)target;
if ((_target)->protectedAgainst(source)) return 0;
// Damage for WITHER on creatures
if (source->has(WITHER)){
for (int i = 0; i < damage; i++){
_target->counters->addCounter(-1, -1);
}
return 1;
}
_target->doDamageTest = 1;
}
int a = target->dealDamage(damage);
return a;
}
void Damage::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
char buffer[200];
sprintf(buffer, "Does %i damage to", damage);
mFont->DrawString(buffer, x + 20 , y, JGETEXT_LEFT);
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = source->getThumb();
if (quad){
float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x , y , 0,scale,scale);
}else{
//TODO
}
quad = target->getIcon();
if (quad){
float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x + 150 , y , 0,scale,scale);
}else{
//TODO
}
}
DamageStack::DamageStack(int id, GameObserver * _game):GuiLayer(id, _game), Interruptible(id){
currentState = -1;
type = ACTION_DAMAGES;
}
int DamageStack::CombatDamages(){
CombatDamages(1);
CombatDamages(0);
return 1;
}
int DamageStack::CombatDamages(int strike){
mHeight = 0;
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
int nbdefensers = defensers->nbDefensers(attacker);
if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){
if (nbdefensers == 0){
Damage * damage = NEW Damage (mCount, attacker, game->opponent());
Add(damage);
}else if (nbdefensers == 1){
Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker));
Add(damage);
}else{
//TODO Fetch list of defensers and allow user to choose targets
Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker));
Add(damage);
}
}
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker);
while (defenser != NULL){
if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){
Damage * damage = NEW Damage (mCount,defenser, attacker);
Add(damage);
}
defenser = defensers->getNextDefenser(defenser, attacker);
}
attacker = attackers->getNextAttacker(attacker);
}
for (int i = 0; i < mCount; i++){
Damage * damage = (Damage*)mObjects[i];
mHeight += damage->mHeight;
}
return mCount;
}
int DamageStack::resolve(){
for (int i = mCount-1; i>= 0; i--){
Damage * damage = (Damage*)mObjects[i];
damage->resolve();
}
for (int i = mCount-1; i>= 0; i--){
Damage * damage = (Damage*)mObjects[i];
damage->target->afterDamage();
}
return 1;
}
void DamageStack::Render(){
int currenty = y;
for (int i= 0; i < mCount; i++){
Damage * damage = (Damage*)mObjects[i];
damage->x = x;
damage->y = currenty;
currenty += damage->mHeight;
damage->Render();
}
}
#include "../include/debug.h"
#include "../include/Damage.h"
#include "../include/MTGCardInstance.h"
#include "../include/Counters.h"
Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target): Interruptible(id){
init(_source, _target, _source->getPower());
}
Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target, int _damage): Interruptible(id){
init(_source, _target, _damage);
}
void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage){
target = _target;
source = _source;
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
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){
MTGCardInstance * _target = (MTGCardInstance *)target;
if ((_target)->protectedAgainst(source)) return 0;
// Damage for WITHER on creatures
if (source->has(WITHER)){
for (int i = 0; i < damage; i++){
_target->counters->addCounter(-1, -1);
}
return 1;
}
_target->doDamageTest = 1;
}
int a = target->dealDamage(damage);
return a;
}
void Damage::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
char buffer[200];
sprintf(buffer, "Does %i damage to", damage);
mFont->DrawString(buffer, x + 20 , y, JGETEXT_LEFT);
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = source->getThumb();
if (quad){
float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x , y , 0,scale,scale);
}else{
//TODO
}
quad = target->getIcon();
if (quad){
float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x + 150 , y , 0,scale,scale);
}else{
//TODO
}
}
DamageStack::DamageStack(int id, GameObserver * _game):GuiLayer(id, _game), Interruptible(id){
currentState = -1;
type = ACTION_DAMAGES;
}
int DamageStack::CombatDamages(){
CombatDamages(1);
CombatDamages(0);
return 1;
}
int DamageStack::CombatDamages(int strike){
mHeight = 0;
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
int nbdefensers = defensers->nbDefensers(attacker);
if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){
if (nbdefensers == 0){
Damage * damage = NEW Damage (mCount, attacker, game->opponent());
Add(damage);
}else if (nbdefensers == 1){
Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker));
Add(damage);
}else{
//TODO Fetch list of defensers and allow user to choose targets
Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker));
Add(damage);
}
}
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker);
while (defenser != NULL){
if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){
Damage * damage = NEW Damage (mCount,defenser, attacker);
Add(damage);
}
defenser = defensers->getNextDefenser(defenser, attacker);
}
attacker = attackers->getNextAttacker(attacker);
}
for (int i = 0; i < mCount; i++){
Damage * damage = (Damage*)mObjects[i];
mHeight += damage->mHeight;
}
return mCount;
}
int DamageStack::resolve(){
for (int i = mCount-1; i>= 0; i--){
Damage * damage = (Damage*)mObjects[i];
damage->resolve();
}
for (int i = mCount-1; i>= 0; i--){
Damage * damage = (Damage*)mObjects[i];
damage->target->afterDamage();
}
return 1;
}
void DamageStack::Render(){
int currenty = y;
for (int i= 0; i < mCount; i++){
Damage * damage = (Damage*)mObjects[i];
damage->x = x;
damage->y = currenty;
currenty += damage->mHeight;
damage->Render();
}
}

View File

@@ -1,359 +1,359 @@
#include "../include/debug.h"
#include "../include/DamageResolverLayer.h"
#include "../include/GameObserver.h"
#include "../include/MTGCardInstance.h"
#include "../include/DamagerDamaged.h"
#include "../include/Damage.h"
DamageResolverLayer::DamageResolverLayer(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPhase = -1;
remainingDamageSteps = 0;
damageStack = NULL;
currentSource = NULL;
buttonOk = 0;
currentChoosingPlayer = NULL;
}
void DamageResolverLayer::Update(float dt){
int newPhase = game->getCurrentGamePhase();
if (newPhase == MTG_PHASE_COMBATDAMAGE){
if (!game->mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)){
if (newPhase != currentPhase){
init();
}
if (remainingDamageSteps && empty()){
initResolve();
}
}
}else{
remainingDamageSteps = 0;
}
currentPhase = newPhase;
PlayGuiObjectController::Update(dt);
}
Player * DamageResolverLayer::whoSelectsDamagesDealtBy(MTGCardInstance * card){
if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay;
int nbdefensers = defensers->nbDefensers(card);
if (nbdefensers == 0) return NULL;
if(nbdefensers == 1 && !card->has(TRAMPLE)) return NULL;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){
if (defenser->has(BANDING)) return game->opponent();
defenser = defensers->getNextDefenser(defenser, card);
}
return game->currentPlayer;
}else{ //Defenser
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
int nbattackers = attackers->nbPartners(card->isDefenser());
if(nbattackers <= 1) return NULL;
if (card->isDefenser()->banding) return game->currentPlayer;
return game->opponent();
}
}
int DamageResolverLayer::addAutoDamageToOpponents(MTGCardInstance * card){
if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay;
int nbdefensers = defensers->nbDefensers(card);
if (nbdefensers == 0){
Damage * damage = NEW Damage (0, card, game->opponent());
damageStack->Add(damage);
}else if (nbdefensers == 1){
Damage * damage = NEW Damage (0, card, defensers->getNextDefenser(NULL, card));
damageStack->Add(damage);
}else{
//SHOULDN'T HAPPEN !
}
}else{ //Defenser
Damage * damage = NEW Damage (mCount,card, card->isDefenser());
damageStack->Add(damage);
}
return 1;
}
int DamageResolverLayer::addIfNotExists(MTGCardInstance * card, Player * selecter){
for (int i = 0; i < mCount; i++){
DamagerDamaged * item = (DamagerDamaged *)mObjects[i];
if (item->card == card) return 0;
}
CardGui * cardg = game->mLayers->playLayer()->getByCard(card);
DamagerDamaged * item = NEW DamagerDamaged(cardg, selecter, mCount == 0);
Add(item);
mCurr = 0;
return 1;
}
//Adds a card and all its opponents to the Damagers' list
int DamageResolverLayer::addDamager(MTGCardInstance * card, Player * selecter){
addIfNotExists(card, selecter);
if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){
addIfNotExists(defenser, whoSelectsDamagesDealtBy(defenser));
defenser = defensers->getNextDefenser(defenser, card);
}
}else{ //Defenser
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGCardInstance * attacker = card->isDefenser();
addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker));
MTGCardInstance * banding = attacker->banding;
if (banding){
attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
if (attacker->banding == banding){
addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker));
}
attacker = attackers->getNextAttacker(attacker);
}
}
}
return 1;
}
int DamageResolverLayer::initResolve(){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "starting resolve, remainingDamagesStep = %i\n", remainingDamageSteps);
OutputDebugString(buf);
#endif
if (damageStack) return 0;
#if defined (WIN32) || defined (LINUX)
sprintf(buf, "damageStack is NULL, we can resolve \n");
OutputDebugString(buf);
#endif
currentSource = NULL;
currentChoosingPlayer = game->currentPlayer;
damageStack = NEW DamageStack(mCount,game);
int strike = 0;
if (remainingDamageSteps == 2) strike = 1;
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
#if defined (WIN32) || defined (LINUX)
sprintf(buf, "attacker : %s \n", attacker->getName());
OutputDebugString(buf);
#endif
if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){
Player * selecter = whoSelectsDamagesDealtBy(attacker);
if (!selecter){
addAutoDamageToOpponents(attacker);
}else{
addDamager(attacker, selecter);
}
}
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker);
while (defenser != NULL){
if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){
Player * selecterb = whoSelectsDamagesDealtBy(defenser);
if (!selecterb){
addAutoDamageToOpponents(defenser);
}else{
addDamager(defenser, selecterb);
}
}
defenser = defensers->getNextDefenser(defenser, attacker);
}
attacker = attackers->getNextAttacker(attacker);
}
if (empty()){
if (!damageStack->empty()){
game->mLayers->stackLayer()->addAction(damageStack);
}else{
SAFE_DELETE(damageStack);
}
remainingDamageSteps--;
damageStack = NULL;
modal = remainingDamageSteps;
}else{
if (canStopDealDamages()) currentChoosingPlayer = game->opponent();
}
return 1;
}
int DamageResolverLayer::init(){
modal = 1;
remainingDamageSteps = 2;
return 1;
}
DamagerDamaged * DamageResolverLayer::findByCard(MTGCardInstance * card){
for (int i =0; i < mCount; i++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->card == card) return current;
}
return NULL;
}
//Returns 1 if all "compulsory" damages have been assigned for current player
int DamageResolverLayer::canStopDealDamages(){
for (int i = 0; i < mCount ; i ++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->damageSelecter==currentChoosingPlayer && current->damageToDeal > 0){
MTGCardInstance * card = current->card;
if (card->controller() == game->currentPlayer){ //Attacker
if (card->has(TRAMPLE)){
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){
DamagerDamaged * _defenser = findByCard(defenser);
if (!_defenser->hasLethalDamage()) return 0;
defenser = defensers->getNextDefenser(defenser, card);
}
}else{
return 0;
}
}else{ //Defenser
return 0;
}
}
}
return 1;
}
int DamageResolverLayer::trampleDamage(){
for (int i = 0; i < mCount ; i ++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->damageToDeal > 0){
MTGCardInstance * card = current->card;
if (card->controller() == game->currentPlayer){ //Attacker
if (card->has(TRAMPLE)){
Damage * damage = NEW Damage(0, card, game->opponent(), current->damageToDeal);
damageStack->Add(damage);
}
}
}
}
return 1;
}
int DamageResolverLayer::resolveDamages(){
trampleDamage();
for (int i = 0; i < mCount ; i++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
for (int j =0; j < current->mCount ; j++){
Damage * damage = NEW Damage(0, current->damages[j]->source, current->damages[j]->target, current->damages[j]->damage);
damageStack->Add(damage);
}
}
game->mLayers->stackLayer()->addAction(damageStack);
remainingDamageSteps--;
resetObjects();
damageStack = NULL;
modal = remainingDamageSteps;
return 1;
}
//a and b are opponents if b is blocking a band in which a belongs or blocking directly a
int DamageResolverLayer::isOpponent(DamagerDamaged * a, DamagerDamaged * b){
MTGCardInstance * carda = a->card;
MTGCardInstance * cardb = b->card;
if (cardb->controller() == game->currentPlayer) {//if b is the attacker switch the cards
carda = cardb;
cardb = a->card;
}
if (cardb->controller() == game->currentPlayer || carda->controller() == game->opponent()) return 0; //Same team, idiot !
if (!carda->banding){
if (cardb->isDefenser() == carda) return 1;
return 0;
}
if (cardb->isDefenser() && cardb->isDefenser()->banding == carda->banding) return 1;
return 0;
}
void DamageResolverLayer::nextPlayer(){
if (currentChoosingPlayer == game->currentPlayer){
currentChoosingPlayer = game->opponent();
if (canStopDealDamages()) resolveDamages();
}else{
resolveDamages();
}
}
void DamageResolverLayer::CheckUserInput(float dt){
if (!mCount) return;
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr];
if (!currentSource || !isOpponent(current,currentSource)){
for (int i = 0; i < mCount; i++){
DamagerDamaged * _current = (DamagerDamaged *) mObjects[i];
if (isOpponent(current,_current)){
currentSource = _current;
break;
}
}
}
if (currentSource){
if (currentSource->damageSelecter == currentChoosingPlayer){
if (isOpponent(current,currentSource)){
if (!currentSource->dealOneDamage(current)){
currentSource->removeDamagesTo(current);
}
}
}
}else{
if (current->damageSelecter == currentChoosingPlayer){
currentSource = current;
}
}
buttonOk = 0;
if (canStopDealDamages()) buttonOk = 1;
}
}else if (mEngine->GetButtonClick(PSP_CTRL_CROSS)){
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr];
if (current->damageSelecter == currentChoosingPlayer){
currentSource = current;
}
}
}else if (mEngine->GetButtonClick(PSP_CTRL_SQUARE)){
if (canStopDealDamages()){
nextPlayer();
//switch to next player or end of selection
}
}else{
PlayGuiObjectController::CheckUserInput(dt);
}
}
void DamageResolverLayer::Render(){
if (!mCount) return;
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRect(0 ,0 , SCREEN_WIDTH , SCREEN_HEIGHT , ARGB(200,0,0,0));
if (currentChoosingPlayer == game->currentPlayer){
mFont->DrawString("Player 1", 0,0);
}else{
mFont->DrawString("Player 2", 0,0);
}
if (currentSource){
currentSource->RenderBig(10, 20);
mFont->DrawString("Current Damager:", 10, 5);
}
for (int i = 0; i < mCount; i++){
((DamagerDamaged *)mObjects[i])->Render(currentChoosingPlayer);
}
if (mObjects[mCurr]){
((DamagerDamaged *)mObjects[mCurr])->Render(currentChoosingPlayer);
}
if (buttonOk){
mFont->DrawString("Damages Assigned, Click Square to Continue", 250, 5);
}
}
#include "../include/debug.h"
#include "../include/DamageResolverLayer.h"
#include "../include/GameObserver.h"
#include "../include/MTGCardInstance.h"
#include "../include/DamagerDamaged.h"
#include "../include/Damage.h"
DamageResolverLayer::DamageResolverLayer(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPhase = -1;
remainingDamageSteps = 0;
damageStack = NULL;
currentSource = NULL;
buttonOk = 0;
currentChoosingPlayer = NULL;
}
void DamageResolverLayer::Update(float dt){
int newPhase = game->getCurrentGamePhase();
if (newPhase == MTG_PHASE_COMBATDAMAGE){
if (!game->mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)){
if (newPhase != currentPhase){
init();
}
if (remainingDamageSteps && empty()){
initResolve();
}
}
}else{
remainingDamageSteps = 0;
}
currentPhase = newPhase;
PlayGuiObjectController::Update(dt);
}
Player * DamageResolverLayer::whoSelectsDamagesDealtBy(MTGCardInstance * card){
if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay;
int nbdefensers = defensers->nbDefensers(card);
if (nbdefensers == 0) return NULL;
if(nbdefensers == 1 && !card->has(TRAMPLE)) return NULL;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){
if (defenser->has(BANDING)) return game->opponent();
defenser = defensers->getNextDefenser(defenser, card);
}
return game->currentPlayer;
}else{ //Defenser
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
int nbattackers = attackers->nbPartners(card->isDefenser());
if(nbattackers <= 1) return NULL;
if (card->isDefenser()->banding) return game->currentPlayer;
return game->opponent();
}
}
int DamageResolverLayer::addAutoDamageToOpponents(MTGCardInstance * card){
if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay;
int nbdefensers = defensers->nbDefensers(card);
if (nbdefensers == 0){
Damage * damage = NEW Damage (0, card, game->opponent());
damageStack->Add(damage);
}else if (nbdefensers == 1){
Damage * damage = NEW Damage (0, card, defensers->getNextDefenser(NULL, card));
damageStack->Add(damage);
}else{
//SHOULDN'T HAPPEN !
}
}else{ //Defenser
Damage * damage = NEW Damage (mCount,card, card->isDefenser());
damageStack->Add(damage);
}
return 1;
}
int DamageResolverLayer::addIfNotExists(MTGCardInstance * card, Player * selecter){
for (int i = 0; i < mCount; i++){
DamagerDamaged * item = (DamagerDamaged *)mObjects[i];
if (item->card == card) return 0;
}
CardGui * cardg = game->mLayers->playLayer()->getByCard(card);
DamagerDamaged * item = NEW DamagerDamaged(cardg, selecter, mCount == 0);
Add(item);
mCurr = 0;
return 1;
}
//Adds a card and all its opponents to the Damagers' list
int DamageResolverLayer::addDamager(MTGCardInstance * card, Player * selecter){
addIfNotExists(card, selecter);
if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){
addIfNotExists(defenser, whoSelectsDamagesDealtBy(defenser));
defenser = defensers->getNextDefenser(defenser, card);
}
}else{ //Defenser
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGCardInstance * attacker = card->isDefenser();
addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker));
MTGCardInstance * banding = attacker->banding;
if (banding){
attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
if (attacker->banding == banding){
addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker));
}
attacker = attackers->getNextAttacker(attacker);
}
}
}
return 1;
}
int DamageResolverLayer::initResolve(){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "starting resolve, remainingDamagesStep = %i\n", remainingDamageSteps);
OutputDebugString(buf);
#endif
if (damageStack) return 0;
#if defined (WIN32) || defined (LINUX)
sprintf(buf, "damageStack is NULL, we can resolve \n");
OutputDebugString(buf);
#endif
currentSource = NULL;
currentChoosingPlayer = game->currentPlayer;
damageStack = NEW DamageStack(mCount,game);
int strike = 0;
if (remainingDamageSteps == 2) strike = 1;
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
#if defined (WIN32) || defined (LINUX)
sprintf(buf, "attacker : %s \n", attacker->getName());
OutputDebugString(buf);
#endif
if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){
Player * selecter = whoSelectsDamagesDealtBy(attacker);
if (!selecter){
addAutoDamageToOpponents(attacker);
}else{
addDamager(attacker, selecter);
}
}
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker);
while (defenser != NULL){
if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){
Player * selecterb = whoSelectsDamagesDealtBy(defenser);
if (!selecterb){
addAutoDamageToOpponents(defenser);
}else{
addDamager(defenser, selecterb);
}
}
defenser = defensers->getNextDefenser(defenser, attacker);
}
attacker = attackers->getNextAttacker(attacker);
}
if (empty()){
if (!damageStack->empty()){
game->mLayers->stackLayer()->addAction(damageStack);
}else{
SAFE_DELETE(damageStack);
}
remainingDamageSteps--;
damageStack = NULL;
modal = remainingDamageSteps;
}else{
if (canStopDealDamages()) currentChoosingPlayer = game->opponent();
}
return 1;
}
int DamageResolverLayer::init(){
modal = 1;
remainingDamageSteps = 2;
return 1;
}
DamagerDamaged * DamageResolverLayer::findByCard(MTGCardInstance * card){
for (int i =0; i < mCount; i++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->card == card) return current;
}
return NULL;
}
//Returns 1 if all "compulsory" damages have been assigned for current player
int DamageResolverLayer::canStopDealDamages(){
for (int i = 0; i < mCount ; i ++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->damageSelecter==currentChoosingPlayer && current->damageToDeal > 0){
MTGCardInstance * card = current->card;
if (card->controller() == game->currentPlayer){ //Attacker
if (card->has(TRAMPLE)){
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){
DamagerDamaged * _defenser = findByCard(defenser);
if (!_defenser->hasLethalDamage()) return 0;
defenser = defensers->getNextDefenser(defenser, card);
}
}else{
return 0;
}
}else{ //Defenser
return 0;
}
}
}
return 1;
}
int DamageResolverLayer::trampleDamage(){
for (int i = 0; i < mCount ; i ++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->damageToDeal > 0){
MTGCardInstance * card = current->card;
if (card->controller() == game->currentPlayer){ //Attacker
if (card->has(TRAMPLE)){
Damage * damage = NEW Damage(0, card, game->opponent(), current->damageToDeal);
damageStack->Add(damage);
}
}
}
}
return 1;
}
int DamageResolverLayer::resolveDamages(){
trampleDamage();
for (int i = 0; i < mCount ; i++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
for (int j =0; j < current->mCount ; j++){
Damage * damage = NEW Damage(0, current->damages[j]->source, current->damages[j]->target, current->damages[j]->damage);
damageStack->Add(damage);
}
}
game->mLayers->stackLayer()->addAction(damageStack);
remainingDamageSteps--;
resetObjects();
damageStack = NULL;
modal = remainingDamageSteps;
return 1;
}
//a and b are opponents if b is blocking a band in which a belongs or blocking directly a
int DamageResolverLayer::isOpponent(DamagerDamaged * a, DamagerDamaged * b){
MTGCardInstance * carda = a->card;
MTGCardInstance * cardb = b->card;
if (cardb->controller() == game->currentPlayer) {//if b is the attacker switch the cards
carda = cardb;
cardb = a->card;
}
if (cardb->controller() == game->currentPlayer || carda->controller() == game->opponent()) return 0; //Same team, idiot !
if (!carda->banding){
if (cardb->isDefenser() == carda) return 1;
return 0;
}
if (cardb->isDefenser() && cardb->isDefenser()->banding == carda->banding) return 1;
return 0;
}
void DamageResolverLayer::nextPlayer(){
if (currentChoosingPlayer == game->currentPlayer){
currentChoosingPlayer = game->opponent();
if (canStopDealDamages()) resolveDamages();
}else{
resolveDamages();
}
}
void DamageResolverLayer::CheckUserInput(float dt){
if (!mCount) return;
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr];
if (!currentSource || !isOpponent(current,currentSource)){
for (int i = 0; i < mCount; i++){
DamagerDamaged * _current = (DamagerDamaged *) mObjects[i];
if (isOpponent(current,_current)){
currentSource = _current;
break;
}
}
}
if (currentSource){
if (currentSource->damageSelecter == currentChoosingPlayer){
if (isOpponent(current,currentSource)){
if (!currentSource->dealOneDamage(current)){
currentSource->removeDamagesTo(current);
}
}
}
}else{
if (current->damageSelecter == currentChoosingPlayer){
currentSource = current;
}
}
buttonOk = 0;
if (canStopDealDamages()) buttonOk = 1;
}
}else if (mEngine->GetButtonClick(PSP_CTRL_CROSS)){
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr];
if (current->damageSelecter == currentChoosingPlayer){
currentSource = current;
}
}
}else if (mEngine->GetButtonClick(PSP_CTRL_SQUARE)){
if (canStopDealDamages()){
nextPlayer();
//switch to next player or end of selection
}
}else{
PlayGuiObjectController::CheckUserInput(dt);
}
}
void DamageResolverLayer::Render(){
if (!mCount) return;
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRect(0 ,0 , SCREEN_WIDTH , SCREEN_HEIGHT , ARGB(200,0,0,0));
if (currentChoosingPlayer == game->currentPlayer){
mFont->DrawString("Player 1", 0,0);
}else{
mFont->DrawString("Player 2", 0,0);
}
if (currentSource){
currentSource->RenderBig(10, 20);
mFont->DrawString("Current Damager:", 10, 5);
}
for (int i = 0; i < mCount; i++){
((DamagerDamaged *)mObjects[i])->Render(currentChoosingPlayer);
}
if (mObjects[mCurr]){
((DamagerDamaged *)mObjects[mCurr])->Render(currentChoosingPlayer);
}
if (buttonOk){
mFont->DrawString("Damages Assigned, Click Square to Continue", 250, 5);
}
}

View File

@@ -1,95 +1,95 @@
#include "../include/debug.h"
#include "../include/DamagerDamaged.h"
DamagerDamaged::DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus):CardGui(0, cardg->card,cardg->defaultHeight,cardg->x,cardg->y, _hasFocus){
mCount = 0;
damageSelecter = _damageSelecter;
damageToDeal = card->power;
}
DamagerDamaged::~DamagerDamaged(){
for (int i = 0; i < mCount; i++){
delete damages[i];
damages[i] = NULL;
}
}
int DamagerDamaged::sumDamages(){
int total = 0;
for (int i = 0; i < mCount; i++){
total += damages[i]->damage;
}
return total;
}
int DamagerDamaged::hasLethalDamage(){
if (sumDamages() >= card->toughness) return 1;
return 0;
}
int DamagerDamaged::dealOneDamage(DamagerDamaged * target){
if (!damageToDeal) return 0;
damageToDeal--;
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "==========\n%s can still deal %i damages\n=============\n", card->getName(), damageToDeal);
OutputDebugString(buf);
#endif
return target->addDamage(1, this);
}
int DamagerDamaged::addDamage(int damage, DamagerDamaged * source){
for (int i = 0; i < mCount; i++){
if (damages[i]->source == source->card){
damages[i]->damage+= damage;
return damage;
}
}
damages[mCount] = NEW Damage(mCount, source->card, this->card,damage);
mCount++;
return damage;
}
int DamagerDamaged::removeDamagesTo(DamagerDamaged * target){
damageToDeal+= target->removeDamagesFrom(this);
return 1;
}
int DamagerDamaged::removeDamagesFrom(DamagerDamaged * source){
for (int i = 0; i < mCount; i++){
if (damages[i]->source == source->card){
int damage = damages[i]->damage;
delete(damages[i]);
damages[i] = NULL;
damages[i] = damages[mCount-1];
mCount--;
return damage;
}
}
return 0;
}
void DamagerDamaged::Render(Player * currentPlayer){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
CardGui::Render();
char buf[4096];
if (currentPlayer != damageSelecter){
if (hasLethalDamage()){
mFont->DrawString("X",x,y);
}
mFont->SetColor(ARGB(255,255,0,0));
sprintf(buf, "%i", sumDamages());
mFont->DrawString(buf,x+5, y+5);
}else{
mFont->SetColor(ARGB(255,0,0,255));
sprintf(buf, "%i", damageToDeal);
mFont->DrawString(buf,x+5, y+5);
}
mFont->SetColor(ARGB(255,255,255,255));
}
#include "../include/debug.h"
#include "../include/DamagerDamaged.h"
DamagerDamaged::DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus):CardGui(0, cardg->card,cardg->defaultHeight,cardg->x,cardg->y, _hasFocus){
mCount = 0;
damageSelecter = _damageSelecter;
damageToDeal = card->power;
}
DamagerDamaged::~DamagerDamaged(){
for (int i = 0; i < mCount; i++){
delete damages[i];
damages[i] = NULL;
}
}
int DamagerDamaged::sumDamages(){
int total = 0;
for (int i = 0; i < mCount; i++){
total += damages[i]->damage;
}
return total;
}
int DamagerDamaged::hasLethalDamage(){
if (sumDamages() >= card->toughness) return 1;
return 0;
}
int DamagerDamaged::dealOneDamage(DamagerDamaged * target){
if (!damageToDeal) return 0;
damageToDeal--;
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "==========\n%s can still deal %i damages\n=============\n", card->getName(), damageToDeal);
OutputDebugString(buf);
#endif
return target->addDamage(1, this);
}
int DamagerDamaged::addDamage(int damage, DamagerDamaged * source){
for (int i = 0; i < mCount; i++){
if (damages[i]->source == source->card){
damages[i]->damage+= damage;
return damage;
}
}
damages[mCount] = NEW Damage(mCount, source->card, this->card,damage);
mCount++;
return damage;
}
int DamagerDamaged::removeDamagesTo(DamagerDamaged * target){
damageToDeal+= target->removeDamagesFrom(this);
return 1;
}
int DamagerDamaged::removeDamagesFrom(DamagerDamaged * source){
for (int i = 0; i < mCount; i++){
if (damages[i]->source == source->card){
int damage = damages[i]->damage;
delete(damages[i]);
damages[i] = NULL;
damages[i] = damages[mCount-1];
mCount--;
return damage;
}
}
return 0;
}
void DamagerDamaged::Render(Player * currentPlayer){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
CardGui::Render();
char buf[4096];
if (currentPlayer != damageSelecter){
if (hasLethalDamage()){
mFont->DrawString("X",x,y);
}
mFont->SetColor(ARGB(255,255,0,0));
sprintf(buf, "%i", sumDamages());
mFont->DrawString(buf,x+5, y+5);
}else{
mFont->SetColor(ARGB(255,0,0,255));
sprintf(buf, "%i", damageToDeal);
mFont->DrawString(buf,x+5, y+5);
}
mFont->SetColor(ARGB(255,255,255,255));
}

View File

@@ -1,131 +1,131 @@
#include "../include/DeckDataWrapper.h"
#include "../include/MTGDeck.h"
DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
parent = deck;
for (int i = 0; i <= MTG_NB_COLORS; i++){
colors[i] = 0;
}
for (int i = 0; i < deck->totalCards(); i++){
MTGCard * card = deck->_(i);
Add(card);
}
currentposition = 0;
currentColor = -1;
}
void DeckDataWrapper::save(){
parent->removeAll();
map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first;
for (int i = 0; i < (*it).second; i++){
parent->add(current);
}
}
parent->save();
}
DeckDataWrapper::~DeckDataWrapper(){
SAFE_DELETE(parent);
}
void DeckDataWrapper::updateCounts(MTGCard * card, int removed){
if (!card){
for (int i = 0; i < MTG_NB_COLORS+1; i++){
colors[i] = 0;
}
map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first;
colors[MTG_NB_COLORS] += (*it).second;
for (int i = 0; i < MTG_NB_COLORS; i++){
if (current->hasColor(i)) colors[i]+=(*it).second;
}
}
}else{
int increment = 1;
if (removed) increment = -1;
colors[MTG_NB_COLORS] += increment;
for (int i = 0; i < MTG_NB_COLORS; i++){
if (card->hasColor(i)) colors[i]+=increment;
}
}
}
int DeckDataWrapper::Add(MTGCard * card){
if(cards.find(card) == cards.end()){
cards[card] = 1;
}else{
cards[card]++;
}
updateCounts(card);
return cards[card];
}
int DeckDataWrapper::Remove(MTGCard * card){
if(cards.find(card) == cards.end() || cards[card] == 0) return 0;
cards[card]--;
updateCounts(card,1);
return 1;
}
MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){
map<MTGCard *,int,Cmp1>::iterator it;
it = cards.find(previous);
int found = 0;
while(1){
if (it == cards.end()){
it = cards.begin();
}else{
it++;
}
if (it == cards.end()) return NULL;
MTGCard * card = (*it).first;
if (card == previous) return NULL;
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
return card;
}
}
}
MTGCard * DeckDataWrapper::getPrevious(MTGCard * next, int color){
map<MTGCard *,int,Cmp1>::iterator it;
it = cards.find(next);
int found = 0;
while(1){
if (it == cards.begin()){
it = cards.end();
}else{
it--;
}
if (it == cards.end()) return NULL;
MTGCard * card = (*it).first;
if (card == next) return NULL;
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
return card;
}
}
}
void DeckDataWrapper::updateCurrentPosition(MTGCard * currentCard, int color){
currentposition = 0;
MTGCard * next = getNext(NULL,color);
while (next){
currentposition+=cards[next];
if (next == currentCard){
next = NULL;
}else{
next = getNext(next,color);
}
}
}
int DeckDataWrapper::getCount(int color){
if (color == -1) return colors[MTG_NB_COLORS];
return colors[color];
}
#include "../include/DeckDataWrapper.h"
#include "../include/MTGDeck.h"
DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
parent = deck;
for (int i = 0; i <= MTG_NB_COLORS; i++){
colors[i] = 0;
}
for (int i = 0; i < deck->totalCards(); i++){
MTGCard * card = deck->_(i);
Add(card);
}
currentposition = 0;
currentColor = -1;
}
void DeckDataWrapper::save(){
parent->removeAll();
map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first;
for (int i = 0; i < (*it).second; i++){
parent->add(current);
}
}
parent->save();
}
DeckDataWrapper::~DeckDataWrapper(){
SAFE_DELETE(parent);
}
void DeckDataWrapper::updateCounts(MTGCard * card, int removed){
if (!card){
for (int i = 0; i < MTG_NB_COLORS+1; i++){
colors[i] = 0;
}
map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first;
colors[MTG_NB_COLORS] += (*it).second;
for (int i = 0; i < MTG_NB_COLORS; i++){
if (current->hasColor(i)) colors[i]+=(*it).second;
}
}
}else{
int increment = 1;
if (removed) increment = -1;
colors[MTG_NB_COLORS] += increment;
for (int i = 0; i < MTG_NB_COLORS; i++){
if (card->hasColor(i)) colors[i]+=increment;
}
}
}
int DeckDataWrapper::Add(MTGCard * card){
if(cards.find(card) == cards.end()){
cards[card] = 1;
}else{
cards[card]++;
}
updateCounts(card);
return cards[card];
}
int DeckDataWrapper::Remove(MTGCard * card){
if(cards.find(card) == cards.end() || cards[card] == 0) return 0;
cards[card]--;
updateCounts(card,1);
return 1;
}
MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){
map<MTGCard *,int,Cmp1>::iterator it;
it = cards.find(previous);
int found = 0;
while(1){
if (it == cards.end()){
it = cards.begin();
}else{
it++;
}
if (it == cards.end()) return NULL;
MTGCard * card = (*it).first;
if (card == previous) return NULL;
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
return card;
}
}
}
MTGCard * DeckDataWrapper::getPrevious(MTGCard * next, int color){
map<MTGCard *,int,Cmp1>::iterator it;
it = cards.find(next);
int found = 0;
while(1){
if (it == cards.begin()){
it = cards.end();
}else{
it--;
}
if (it == cards.end()) return NULL;
MTGCard * card = (*it).first;
if (card == next) return NULL;
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
return card;
}
}
}
void DeckDataWrapper::updateCurrentPosition(MTGCard * currentCard, int color){
currentposition = 0;
MTGCard * next = getNext(NULL,color);
while (next){
currentposition+=cards[next];
if (next == currentCard){
next = NULL;
}else{
next = getNext(next,color);
}
}
}
int DeckDataWrapper::getCount(int color){
if (color == -1) return colors[MTG_NB_COLORS];
return colors[color];
}

View File

@@ -1,63 +1,63 @@
#include "../include/debug.h"
#include "../include/DuelLayers.h"
#include "../include/MTGRules.h"
#include "../include/DamageResolverLayer.h"
void DuelLayers::init(){
#include "../include/debug.h"
#include "../include/DuelLayers.h"
#include "../include/MTGRules.h"
#include "../include/DamageResolverLayer.h"
//0 Stack Layer
ActionStack * mActionStack = NEW ActionStack(0, GameObserver::GetInstance());
//Damage Resolver
DamageResolverLayer * mDamageResolver = NEW DamageResolverLayer(1, GameObserver::GetInstance());
//1 Action Layer
GuiLayer * actionLayer = NEW ActionLayer(2, GameObserver::GetInstance());
MTGGamePhase * phaseManager = NEW MTGGamePhase(actionLayer->getMaxId());
actionLayer->Add(phaseManager);
//Add Magic Specific Rules
actionLayer->Add(NEW MTGAttackRule(-1));
actionLayer->Add(NEW MTGBlockRule(-1));
actionLayer->Add(NEW MTGLegendRule(-1));
actionLayer->Add(NEW MTGPersistRule(-1));
//2 Hand Layer
MTGGuiHand * mGuiHand = NEW MTGGuiHand(3, GameObserver::GetInstance());
//3 Game
MTGGuiPlay * play = NEW MTGGuiPlay(4, GameObserver::GetInstance());
void DuelLayers::init(){
//0 Stack Layer
ActionStack * mActionStack = NEW ActionStack(0, GameObserver::GetInstance());
//Damage Resolver
DamageResolverLayer * mDamageResolver = NEW DamageResolverLayer(1, GameObserver::GetInstance());
//1 Action Layer
GuiLayer * actionLayer = NEW ActionLayer(2, GameObserver::GetInstance());
MTGGamePhase * phaseManager = NEW MTGGamePhase(actionLayer->getMaxId());
actionLayer->Add(phaseManager);
//Add Magic Specific Rules
actionLayer->Add(NEW MTGAttackRule(-1));
actionLayer->Add(NEW MTGBlockRule(-1));
actionLayer->Add(NEW MTGLegendRule(-1));
actionLayer->Add(NEW MTGPersistRule(-1));
//2 Hand Layer
MTGGuiHand * mGuiHand = NEW MTGGuiHand(3, GameObserver::GetInstance());
//3 Game
MTGGuiPlay * play = NEW MTGGuiPlay(4, GameObserver::GetInstance());
Add(mActionStack);
Add(mDamageResolver);
Add(actionLayer);
Add(mGuiHand);
Add(play);
}
ActionStack * DuelLayers::stackLayer(){
return ((ActionStack *) (objects[0]));
}
DamageResolverLayer * DuelLayers::combatLayer(){
return ((DamageResolverLayer *) (objects[1]));
}
ActionLayer * DuelLayers::actionLayer(){
return ((ActionLayer *) (objects[2]));
}
MTGGuiHand * DuelLayers::handLayer(){
return ((MTGGuiHand *) (objects[3]));
}
MTGGuiPlay * DuelLayers::playLayer(){
return ((MTGGuiPlay *) (objects[4]));
}
Add(mActionStack);
Add(mDamageResolver);
Add(actionLayer);
Add(mGuiHand);
Add(play);
}
ActionStack * DuelLayers::stackLayer(){
return ((ActionStack *) (objects[0]));
}
DamageResolverLayer * DuelLayers::combatLayer(){
return ((DamageResolverLayer *) (objects[1]));
}
ActionLayer * DuelLayers::actionLayer(){
return ((ActionLayer *) (objects[2]));
}
MTGGuiHand * DuelLayers::handLayer(){
return ((MTGGuiHand *) (objects[3]));
}
MTGGuiPlay * DuelLayers::playLayer(){
return ((MTGGuiPlay *) (objects[4]));
}

View File

@@ -1,250 +1,250 @@
#include "../include/debug.h"
#include <JGE.h>
#include <JRenderer.h>
#if defined (WIN32) || defined (LINUX)
#else
#include <pspfpu.h>
#endif
#include "../include/GameApp.h"
#include "../include/Subtypes.h"
#include "../include/GameStateDeckViewer.h"
#include "../include/GameStateMenu.h"
#include "../include/GameStateDuel.h"
#include "../include/GameStateOptions.h"
#include "../include/GameStateShop.h"
const char * const GameState::menuTexts[]= {"--NEW--","Deck 1", "Deck 2", "Deck 3", "Deck 4", "Deck 5", "Deck 6"} ;
JResourceManager* GameApp::CommonRes = NEW JResourceManager();
hgeParticleSystem* GameApp::Particles[] = {NULL,NULL,NULL,NULL,NULL,NULL};
int GameApp::HasMusic = 1;
GameState::GameState(GameApp* parent): mParent(parent)
{
mEngine = JGE::GetInstance();
}
GameApp::GameApp(): JApp()
{
mScreenShotCount = 0;
for (int i=0; i < MAX_STATE ; i++)
mGameStates[i] = NULL;
mShowDebugInfo = false;
players[0] = 0;
players[1] = 0;
}
GameApp::~GameApp()
{
}
void GameApp::Create()
{
#if defined (WIN32)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#elif not defined (LINUX)
pspfpu_set_enable(0); //disable FPU Exceptions until we find where the FPU errors come from
#endif
//_CrtSetBreakAlloc(368);
LOG("starting Game");
//Test for Music files presence
std::ifstream file("Res/sound/Track0.mp3");
if(file){
file.close();
}else{
HasMusic = 0;
}
std::ifstream file2("Res/sound/Track1.mp3");
if(file2){
file2.close();
}else{
HasMusic = 0;
}
CommonRes->CreateTexture("graphics/menuicons.png");
//Creating thes quad in this specific order allows us to have them in the correct order to call them by integer id
CommonRes->CreateQuad("c_artifact", "graphics/menuicons.png", 10 + 6*32, 32, 32, 32);
CommonRes->CreateQuad("c_green", "graphics/menuicons.png", 10 + 0*32, 32, 32, 32);
CommonRes->CreateQuad("c_blue", "graphics/menuicons.png", 10 + 1*32, 32, 32, 32);
CommonRes->CreateQuad("c_red", "graphics/menuicons.png", 10 + 3*32, 32, 32, 32);
CommonRes->CreateQuad("c_black", "graphics/menuicons.png", 10 + 2*32, 32, 32, 32);
CommonRes->CreateQuad("c_white", "graphics/menuicons.png", 10 + 4*32, 32, 32, 32);
CommonRes->CreateQuad("c_land", "graphics/menuicons.png", 10 + 5*32, 32, 32, 32);
CommonRes->CreateTexture("sets/back.jpg");
CommonRes->CreateQuad("back", "sets/back.jpg", 0, 0, 200, 285);
CommonRes->CreateTexture("sets/back_thumb.jpg");
CommonRes->CreateQuad("back_thumb", "sets/back_thumb.jpg", 0, 0, 45, 64);
CommonRes->CreateTexture("graphics/particles.png");
CommonRes->CreateQuad("particles", "graphics/particles.png", 0, 0, 32, 32);
CommonRes->GetQuad("particles")->SetHotSpot(16,16);
CommonRes->LoadJLBFont("graphics/f3",16);
CommonRes->LoadJLBFont("graphics/magic",16);
//CommonRes->CreateTexture("graphics/interrupt.png");
//CommonRes->CreateQuad("interrupt", "graphics/interrupt.png", 0, 0, 256, 128);
cache = NEW TexturesCache();
collection = NEW MTGAllCards(cache);
Particles[0] = NEW hgeParticleSystem("graphics/particle1.psi", CommonRes->GetQuad("particles"));
Particles[1] = NEW hgeParticleSystem("graphics/particle2.psi", CommonRes->GetQuad("particles"));
Particles[2] = NEW hgeParticleSystem("graphics/particle3.psi", CommonRes->GetQuad("particles"));
Particles[3] = NEW hgeParticleSystem("graphics/particle4.psi", CommonRes->GetQuad("particles"));
Particles[4] = NEW hgeParticleSystem("graphics/particle5.psi", CommonRes->GetQuad("particles"));
Particles[5] = NEW hgeParticleSystem("graphics/particle7.psi", CommonRes->GetQuad("particles"));
mGameStates[GAME_STATE_DECK_VIEWER] = NEW GameStateDeckViewer(this);
mGameStates[GAME_STATE_DECK_VIEWER]->Create();
mGameStates[GAME_STATE_MENU] = NEW GameStateMenu(this);
mGameStates[GAME_STATE_MENU]->Create();
mGameStates[GAME_STATE_DUEL] = NEW GameStateDuel(this);
mGameStates[GAME_STATE_DUEL]->Create();
mGameStates[GAME_STATE_SHOP] = NEW GameStateShop(this);
mGameStates[GAME_STATE_SHOP]->Create();
mGameStates[GAME_STATE_OPTIONS] = NEW GameStateOptions(this);
mGameStates[GAME_STATE_OPTIONS]->Create();
//mGameStates[GAME_STATE_GAME] = NEW GameStateGAME(this);
mCurrentState = NULL;
mNextState = mGameStates[GAME_STATE_MENU];
}
void GameApp::LoadGameStates()
{
//mGameStates[GAME_STATE_MENU]->Create();
//mGameStates[GAME_STATE_GAME]->Create();
}
void GameApp::Destroy()
{
LOG("==Destroying GameApp==");
for (int i=GAME_STATE_MENU;i<=MAX_STATE-1;i++)
{
if (mGameStates[i]){
mGameStates[i]->Destroy();
delete mGameStates[i];
}
}
for (int i= 0; i < 6; i++){
delete Particles[i];
}
if (collection){
collection->destroyAllCards();
delete collection;
}
if (cache) delete cache;
if (CommonRes) delete CommonRes;
GameOptions::Destroy();
if (Subtypes::subtypesList) delete Subtypes::subtypesList;
if (MtgSets::SetsList) delete MtgSets::SetsList;
LOG("==Destroying GameApp Successful==");
}
void GameApp::Update()
{
JGE* mEngine = JGE::GetInstance();
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE))
{
char s[80];
sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++);
JRenderer::GetInstance()->ScreenShot(s);
}
//Exit when START and X ARE PRESSED SIMULTANEOUSLY
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_CROSS)){
mEngine->End();
return;
}
float dt = mEngine->GetDelta();
if (dt > 35.0f) // min 30 FPS ;)
dt = 35.0f;
if (mCurrentState != NULL)
mCurrentState->Update(dt);
if (mNextState != NULL)
{
if (mCurrentState != NULL)
mCurrentState->End();
mCurrentState = mNextState;
mCurrentState->Start();
mNextState = NULL;
}
}
void GameApp::Render()
{
if (mCurrentState != NULL)
{
mCurrentState->Render();
}
}
void GameApp::SetNextState(int state)
{
mNextState = mGameStates[state];
}
void GameApp::Pause(){
}
void GameApp::Resume(){
}
#include "../include/debug.h"
#include <JGE.h>
#include <JRenderer.h>
#if defined (WIN32) || defined (LINUX)
#else
#include <pspfpu.h>
#endif
#include "../include/GameApp.h"
#include "../include/Subtypes.h"
#include "../include/GameStateDeckViewer.h"
#include "../include/GameStateMenu.h"
#include "../include/GameStateDuel.h"
#include "../include/GameStateOptions.h"
#include "../include/GameStateShop.h"
const char * const GameState::menuTexts[]= {"--NEW--","Deck 1", "Deck 2", "Deck 3", "Deck 4", "Deck 5", "Deck 6"} ;
JResourceManager* GameApp::CommonRes = NEW JResourceManager();
hgeParticleSystem* GameApp::Particles[] = {NULL,NULL,NULL,NULL,NULL,NULL};
int GameApp::HasMusic = 1;
GameState::GameState(GameApp* parent): mParent(parent)
{
mEngine = JGE::GetInstance();
}
GameApp::GameApp(): JApp()
{
mScreenShotCount = 0;
for (int i=0; i < MAX_STATE ; i++)
mGameStates[i] = NULL;
mShowDebugInfo = false;
players[0] = 0;
players[1] = 0;
}
GameApp::~GameApp()
{
}
void GameApp::Create()
{
#if defined (WIN32)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#elif not defined (LINUX)
pspfpu_set_enable(0); //disable FPU Exceptions until we find where the FPU errors come from
#endif
//_CrtSetBreakAlloc(368);
LOG("starting Game");
//Test for Music files presence
std::ifstream file("Res/sound/Track0.mp3");
if(file){
file.close();
}else{
HasMusic = 0;
}
std::ifstream file2("Res/sound/Track1.mp3");
if(file2){
file2.close();
}else{
HasMusic = 0;
}
CommonRes->CreateTexture("graphics/menuicons.png");
//Creating thes quad in this specific order allows us to have them in the correct order to call them by integer id
CommonRes->CreateQuad("c_artifact", "graphics/menuicons.png", 10 + 6*32, 32, 32, 32);
CommonRes->CreateQuad("c_green", "graphics/menuicons.png", 10 + 0*32, 32, 32, 32);
CommonRes->CreateQuad("c_blue", "graphics/menuicons.png", 10 + 1*32, 32, 32, 32);
CommonRes->CreateQuad("c_red", "graphics/menuicons.png", 10 + 3*32, 32, 32, 32);
CommonRes->CreateQuad("c_black", "graphics/menuicons.png", 10 + 2*32, 32, 32, 32);
CommonRes->CreateQuad("c_white", "graphics/menuicons.png", 10 + 4*32, 32, 32, 32);
CommonRes->CreateQuad("c_land", "graphics/menuicons.png", 10 + 5*32, 32, 32, 32);
CommonRes->CreateTexture("sets/back.jpg");
CommonRes->CreateQuad("back", "sets/back.jpg", 0, 0, 200, 285);
CommonRes->CreateTexture("sets/back_thumb.jpg");
CommonRes->CreateQuad("back_thumb", "sets/back_thumb.jpg", 0, 0, 45, 64);
CommonRes->CreateTexture("graphics/particles.png");
CommonRes->CreateQuad("particles", "graphics/particles.png", 0, 0, 32, 32);
CommonRes->GetQuad("particles")->SetHotSpot(16,16);
CommonRes->LoadJLBFont("graphics/f3",16);
CommonRes->LoadJLBFont("graphics/magic",16);
//CommonRes->CreateTexture("graphics/interrupt.png");
//CommonRes->CreateQuad("interrupt", "graphics/interrupt.png", 0, 0, 256, 128);
cache = NEW TexturesCache();
collection = NEW MTGAllCards(cache);
Particles[0] = NEW hgeParticleSystem("graphics/particle1.psi", CommonRes->GetQuad("particles"));
Particles[1] = NEW hgeParticleSystem("graphics/particle2.psi", CommonRes->GetQuad("particles"));
Particles[2] = NEW hgeParticleSystem("graphics/particle3.psi", CommonRes->GetQuad("particles"));
Particles[3] = NEW hgeParticleSystem("graphics/particle4.psi", CommonRes->GetQuad("particles"));
Particles[4] = NEW hgeParticleSystem("graphics/particle5.psi", CommonRes->GetQuad("particles"));
Particles[5] = NEW hgeParticleSystem("graphics/particle7.psi", CommonRes->GetQuad("particles"));
mGameStates[GAME_STATE_DECK_VIEWER] = NEW GameStateDeckViewer(this);
mGameStates[GAME_STATE_DECK_VIEWER]->Create();
mGameStates[GAME_STATE_MENU] = NEW GameStateMenu(this);
mGameStates[GAME_STATE_MENU]->Create();
mGameStates[GAME_STATE_DUEL] = NEW GameStateDuel(this);
mGameStates[GAME_STATE_DUEL]->Create();
mGameStates[GAME_STATE_SHOP] = NEW GameStateShop(this);
mGameStates[GAME_STATE_SHOP]->Create();
mGameStates[GAME_STATE_OPTIONS] = NEW GameStateOptions(this);
mGameStates[GAME_STATE_OPTIONS]->Create();
//mGameStates[GAME_STATE_GAME] = NEW GameStateGAME(this);
mCurrentState = NULL;
mNextState = mGameStates[GAME_STATE_MENU];
}
void GameApp::LoadGameStates()
{
//mGameStates[GAME_STATE_MENU]->Create();
//mGameStates[GAME_STATE_GAME]->Create();
}
void GameApp::Destroy()
{
LOG("==Destroying GameApp==");
for (int i=GAME_STATE_MENU;i<=MAX_STATE-1;i++)
{
if (mGameStates[i]){
mGameStates[i]->Destroy();
delete mGameStates[i];
}
}
for (int i= 0; i < 6; i++){
delete Particles[i];
}
if (collection){
collection->destroyAllCards();
delete collection;
}
if (cache) delete cache;
if (CommonRes) delete CommonRes;
GameOptions::Destroy();
if (Subtypes::subtypesList) delete Subtypes::subtypesList;
if (MtgSets::SetsList) delete MtgSets::SetsList;
LOG("==Destroying GameApp Successful==");
}
void GameApp::Update()
{
JGE* mEngine = JGE::GetInstance();
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE))
{
char s[80];
sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++);
JRenderer::GetInstance()->ScreenShot(s);
}
//Exit when START and X ARE PRESSED SIMULTANEOUSLY
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_CROSS)){
mEngine->End();
return;
}
float dt = mEngine->GetDelta();
if (dt > 35.0f) // min 30 FPS ;)
dt = 35.0f;
if (mCurrentState != NULL)
mCurrentState->Update(dt);
if (mNextState != NULL)
{
if (mCurrentState != NULL)
mCurrentState->End();
mCurrentState = mNextState;
mCurrentState->Start();
mNextState = NULL;
}
}
void GameApp::Render()
{
if (mCurrentState != NULL)
{
mCurrentState->Render();
}
}
void GameApp::SetNextState(int state)
{
mNextState = mGameStates[state];
}
void GameApp::Pause(){
}
void GameApp::Resume(){
}

View File

@@ -1,31 +1,31 @@
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#ifndef _GAMEAPP_H_
#define _GAMEAPP_H_
#include <JApp.h>
class GameApp: public JApp
{
public:
GameApp();
virtual ~GameApp();
virtual void Create();
virtual void Destroy();
virtual void Update();
virtual void Render();
virtual void Pause();
virtual void Resume();
};
#endif
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#ifndef _GAMEAPP_H_
#define _GAMEAPP_H_
#include <JApp.h>
class GameApp: public JApp
{
public:
GameApp();
virtual ~GameApp();
virtual void Create();
virtual void Destroy();
virtual void Update();
virtual void Render();
virtual void Pause();
virtual void Resume();
};
#endif

View File

@@ -1,36 +1,36 @@
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#include "../include/debug.h"
#include <string.h>
#include <JGameLauncher.h>
#include "../include/GameApp.h"
//-------------------------------------------------------------------------------------
JApp* JGameLauncher::GetGameApp()
{
return NEW GameApp();
};
//-------------------------------------------------------------------------------------
char *JGameLauncher::GetName()
{
return strdup("Wagic");
}
//-------------------------------------------------------------------------------------
u32 JGameLauncher::GetInitFlags()
{
return JINIT_FLAG_NORMAL;
}
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#include "../include/debug.h"
#include <string.h>
#include <JGameLauncher.h>
#include "../include/GameApp.h"
//-------------------------------------------------------------------------------------
JApp* JGameLauncher::GetGameApp()
{
return NEW GameApp();
};
//-------------------------------------------------------------------------------------
char *JGameLauncher::GetName()
{
return strdup("Wagic");
}
//-------------------------------------------------------------------------------------
u32 JGameLauncher::GetInitFlags()
{
return JINIT_FLAG_NORMAL;
}

View File

@@ -1,481 +1,481 @@
#include "../include/debug.h"
#include "../include/GameObserver.h"
#include "../include/GameOptions.h"
#include "../include/ConstraintResolver.h"
#include "../include/CardGui.h"
#include "../include/Damage.h"
#include "../include/DamageResolverLayer.h"
#include <JRenderer.h>
GameObserver * GameObserver::mInstance = NULL;
GameObserver* GameObserver::GetInstance()
{
return mInstance;
}
void GameObserver::EndInstance()
{
SAFE_DELETE(mInstance);
}
void GameObserver::Init(Player * _players[], int _nbplayers){
mInstance = NEW GameObserver(_players, _nbplayers);
mInstance->mLayers = NEW DuelLayers();
mInstance->mLayers->init();
}
GameObserver::GameObserver(Player * _players[], int _nb_players){
int i;
for (i =0; i < _nb_players;i ++){
players[i] = _players[i];
}
currentPlayer = players[0];
currentActionPlayer = currentPlayer;
isInterrupting = NULL;
currentPlayerId = 0;
nbPlayers = _nb_players;
currentRound = 1;
currentGamePhase = -1;
targetChooser = NULL;
cardWaitingForTargets = NULL;
reaction = 0;
gameOver = NULL;
phaseRing = NEW PhaseRing(_players,_nb_players);
}
void GameObserver::setGamePhaseManager(MTGGamePhase * _phases){
gamePhaseManager = _phases;
}
int GameObserver::getCurrentGamePhase(){
return currentGamePhase;
}
Player * GameObserver::opponent(){
int index = (currentPlayerId+1)%nbPlayers;
return players[index];
}
int GameObserver::enteringPhase(int phase){
//TODO
return 0;
}
void GameObserver::nextPlayer(){
currentPlayerId = (currentPlayerId+1)%nbPlayers;
currentPlayer = players[currentPlayerId];
currentActionPlayer = currentPlayer;
}
void GameObserver::nextGamePhase(){
phaseRing->forward();
Phase * cPhase = phaseRing->getCurrentPhase();
currentGamePhase = cPhase->id;
if (currentPlayer != cPhase->player) nextPlayer();
//init begin of turn
if (currentGamePhase == MTG_PHASE_BEFORE_BEGIN){
cleanupPhase();
currentPlayer->canPutLandsIntoPlay = 1;
mLayers->actionLayer()->Update(0);
return nextGamePhase();
}
//manaBurn
if (currentGamePhase == MTG_PHASE_UNTAP ||
currentGamePhase == MTG_PHASE_FIRSTMAIN ||
currentGamePhase == MTG_PHASE_COMBATBEGIN ||
currentGamePhase == MTG_PHASE_SECONDMAIN ||
currentGamePhase == MTG_PHASE_ENDOFTURN
){
currentPlayer->manaBurn();
}
//After End of turn
if (currentGamePhase == MTG_PHASE_AFTER_EOT){
//Auto Hand cleaning, in case the player didn't do it himself
while(currentPlayer->game->hand->nb_cards > 7){
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
}
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
mLayers->actionLayer()->Update(0);
return nextGamePhase();
}
//Phase Specific actions
switch(currentGamePhase){
case MTG_PHASE_UNTAP:
untapPhase();
break;
case MTG_PHASE_DRAW:
mLayers->stackLayer()->addDraw(currentPlayer,1);
break;
default:
break;
}
}
int GameObserver::cancelCurrentAction(){
SAFE_DELETE(targetChooser);
return 1;
}
void GameObserver::userRequestNextGamePhase(){
if (mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)) return;
if (getCurrentTargetChooser()) return;
if (mLayers->combatLayer()->remainingDamageSteps) return;
//TODO CHECK POSSIBILITY
if (opponent()->isAI() || GameOptions::GetInstance()->values[OPTIONS_INTERRUPTATENDOFPHASE_OFFSET+currentGamePhase]){
mLayers->stackLayer()->AddNextGamePhase();
}else{
nextGamePhase();
}
}
void GameObserver::startGame(int shuffle, int draw){
int i;
for (i=0; i<nbPlayers; i++){
players[i]->game->initGame(shuffle, draw);
}
phaseRing->goToPhase(MTG_PHASE_FIRSTMAIN, players[0]);
currentGamePhase = MTG_PHASE_FIRSTMAIN;
}
void GameObserver::addObserver(MTGAbility * observer){
mLayers->actionLayer()->Add(observer);
}
void GameObserver::removeObserver(ActionElement * observer){
if (observer){
observer->destroy();
}else{
//TODO log error
}
mLayers->actionLayer()->Remove(observer);
}
GameObserver::~GameObserver(){
LOG("==Destroying GameObserver==");
SAFE_DELETE(targetChooser);
SAFE_DELETE(mLayers);
SAFE_DELETE(phaseRing);
LOG("==GameObserver Destroyed==");
}
void GameObserver::Update(float dt){
Player * player = currentPlayer;
if (currentGamePhase == MTG_PHASE_COMBATBLOCKERS){
player = opponent();
}else if (currentGamePhase == MTG_PHASE_COMBATDAMAGE){
DamageResolverLayer * drl = mLayers->combatLayer();
if (drl->currentChoosingPlayer && drl->mCount) player = drl->currentChoosingPlayer;
}
currentActionPlayer = player;
if (isInterrupting) player = isInterrupting;
mLayers->Update(dt,player);
stateEffects();
oldGamePhase = currentGamePhase;
}
//applies damage to creatures after updates
//Players life test
void GameObserver::stateEffects(){
for (int i =0; i < 2; i++){
MTGGameZone * zone = players[i]->game->inPlay;
for (int j = zone->nb_cards-1 ; j>=0; j--){
MTGCardInstance * card = zone->cards[j];
card->afterDamage();
}
}
for (int i =0; i < 2; i++){
if (players[i]->life <= 0) 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));
}
}
void GameObserver::nextStep(){
}
void GameObserver::ButtonPressed (int controllerId, PlayGuiObject * _object){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Click\n");
#endif
int id = _object->GetId();
if (id >=0){
MTGCardInstance * card = ((CardGui *)_object)->card;
cardClick(card, card);
}
//if (id>= -6 && id <= -3){
if (id== -5 || id == -3){ //TODO libraries ???
GuiGameZone * zone = (GuiGameZone *)_object;
zone->toggleDisplay();
}
if (id == -1 || id == -2){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Click Player !\n");
#endif
cardClick(NULL, ((GuiAvatar *)_object)->player);
}
}
void GameObserver::stackObjectClicked(Interruptible * action){
if (targetChooser != NULL){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser ok \n");
#endif
int result = targetChooser->toggleTarget(action);
if (result == TARGET_OK_FULL){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser Full \n");
#endif
cardClick(cardWaitingForTargets);
}else{
return;
}
}else{
reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(action);
}
}
void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
LOG("==GameObserver::cardClick");
if (card) {LOG(card->getName())};
Player * clickedPlayer = NULL;
if (!card) clickedPlayer = ((Player *)object);
if (targetChooser != NULL){
int result;
if (card) {
if (card == cardWaitingForTargets){
LOG("attempt to close targetting");
int _result = targetChooser->ForceTargetListReady();
if (_result){
result = TARGET_OK_FULL;
}else{
LOG("...but we cant!\n");
result = targetChooser->targetsReadyCheck();
}
}else{
result = targetChooser->toggleTarget(card);
}
}else{
result = targetChooser->toggleTarget(clickedPlayer);
}
if (result == TARGET_OK_FULL){
card = cardWaitingForTargets;
}else{
return;
}
}
if (card){
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
}else{
reaction = mLayers->actionLayer()->isReactingToTargetClick(object);
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(object);
}
if (reaction != -1){
if (!card) return;
if (currentlyActing()->game->hand->hasCard(card)){
//Current player's hand
if (canPutInPlay(card)){
putInPlay(card);
if (card->hasType("land")){
currentPlayer->canPutLandsIntoPlay--;
}
}else if (currentPlayer->game->hand->hasCard(card)){ //Current player's hand
if (currentGamePhase == MTG_PHASE_CLEANUP && currentPlayer->game->hand->nb_cards > 7){
currentPlayer->game->putInGraveyard(card);
}
}
}else if (reaction){
if (reaction == 1){
mLayers->actionLayer()->reactToClick(card);
}else{
mLayers->actionLayer()->setMenuObject(object);
}
}else if (card->isTapped() && card->controller() == currentPlayer){
int a = ConstraintResolver::untap(this, card);
}
}
}
TargetChooser * GameObserver::getCurrentTargetChooser(){
TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser();
if (_tc) return _tc;
return targetChooser;
}
//Check if it is possible to put a card into play
//TODO : improve according to spells in game...
int GameObserver::canPutInPlay(MTGCardInstance * card){
Player * player = currentlyActing();
LOG("CANPUTINPLAY- check if card belongs to current player\n");
if (!player->game->hand->hasCard(card)) return 0;
LOG("CANPUTINPLAY- check if card is land or can be played\n");
if (card->hasType("land")){
LOG("CANPUTINPLAY- card is land - check if can be played\n");
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN)){
LOG("CANPUTINPLAY- Land, ok\n");
return 1;
}
}else if ((card->hasType("instant")) || card->has(FLASH) || (player == currentPlayer && (currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN))){
LOG("CANPUTINPLAY- correct time to play\n");
if (checkManaCost(card)){
LOG("CANPUTINPLAY- ManaCost ok\n");
if (targetListIsSet(card)){
#ifdef LOG
LOG("CANPUTINPLAY- Targets chosen -> OK\n");
#endif
return 1;
}else{
#ifdef LOG
LOG("CANPUTINPLAY- Targets not chosen yet\n");
#endif
return 0;
}
}
}
return 0;
}
void GameObserver::putInPlay(MTGCardInstance * card){
Player * player = currentlyActing();
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
player->getManaPool()->pay(card->getManaCost());
ManaCost * spellCost = previousManaPool->Diff(player->getManaPool());
delete previousManaPool;
if (card->hasType("land")){
Spell * spell = NEW Spell(card);
player->game->putInZone(card, player->game->hand, player->game->stack);
spell->resolve();
delete spellCost;
delete spell;
}else{
if (targetChooser){
mLayers->stackLayer()->addSpell(card,targetChooser->targets,targetChooser->cursor, spellCost);
delete targetChooser;
targetChooser = NULL;
}else{
mLayers->stackLayer()->addSpell(card,NULL,0, spellCost);
}
player->game->putInZone(card, player->game->hand, player->game->stack);
}
}
/* 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;
}
return 0;
}
void GameObserver::draw(){
//TODO checks to allow multiple draw, or no draw, etc...
currentPlayer->game->drawFromLibrary();
}
void GameObserver::cleanupPhase(){
currentPlayer->cleanupPhase();
opponent()->cleanupPhase();
}
void GameObserver::untapPhase(){
currentPlayer->inPlay()->untapAll();
}
int GameObserver::isACreature(MTGCardInstance * card){
return card->isACreature();
}
Player * GameObserver::currentlyActing(){
if (isInterrupting) return isInterrupting;
return currentActionPlayer;
}
int GameObserver::tryToTapOrUntap(MTGCardInstance * card){
int reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction){
if (reaction == 1){
mLayers->actionLayer()->reactToClick(card);
}else{
//TODO, what happens when several abilities react to the click ?
}
return reaction;
}else{
if (card->isTapped() && card->controller() == currentPlayer){
int a = ConstraintResolver::untap(this, card);
return a;
}else{
//TODO Check Spells
//card->tap();
return 0;
}
return 0;
}
}
//TODO CORRECT THIS MESS
int GameObserver::targetListIsSet(MTGCardInstance * card){
if (targetChooser == NULL){
TargetChooserFactory tcf;
targetChooser = tcf.createTargetChooser(card);
cardWaitingForTargets = card;
if (targetChooser == NULL){
return 1;
}
}
return (targetChooser->targetListSet());
}
int GameObserver::checkManaCost(MTGCardInstance * card){
ManaCost * playerMana = currentlyActing()->getManaPool();
ManaCost * cost = card->getManaCost();
if (playerMana->canAfford(cost)){
return 1;
}
return 0;
}
#include "../include/debug.h"
#include "../include/GameObserver.h"
#include "../include/GameOptions.h"
#include "../include/ConstraintResolver.h"
#include "../include/CardGui.h"
#include "../include/Damage.h"
#include "../include/DamageResolverLayer.h"
#include <JRenderer.h>
GameObserver * GameObserver::mInstance = NULL;
GameObserver* GameObserver::GetInstance()
{
return mInstance;
}
void GameObserver::EndInstance()
{
SAFE_DELETE(mInstance);
}
void GameObserver::Init(Player * _players[], int _nbplayers){
mInstance = NEW GameObserver(_players, _nbplayers);
mInstance->mLayers = NEW DuelLayers();
mInstance->mLayers->init();
}
GameObserver::GameObserver(Player * _players[], int _nb_players){
int i;
for (i =0; i < _nb_players;i ++){
players[i] = _players[i];
}
currentPlayer = players[0];
currentActionPlayer = currentPlayer;
isInterrupting = NULL;
currentPlayerId = 0;
nbPlayers = _nb_players;
currentRound = 1;
currentGamePhase = -1;
targetChooser = NULL;
cardWaitingForTargets = NULL;
reaction = 0;
gameOver = NULL;
phaseRing = NEW PhaseRing(_players,_nb_players);
}
void GameObserver::setGamePhaseManager(MTGGamePhase * _phases){
gamePhaseManager = _phases;
}
int GameObserver::getCurrentGamePhase(){
return currentGamePhase;
}
Player * GameObserver::opponent(){
int index = (currentPlayerId+1)%nbPlayers;
return players[index];
}
int GameObserver::enteringPhase(int phase){
//TODO
return 0;
}
void GameObserver::nextPlayer(){
currentPlayerId = (currentPlayerId+1)%nbPlayers;
currentPlayer = players[currentPlayerId];
currentActionPlayer = currentPlayer;
}
void GameObserver::nextGamePhase(){
phaseRing->forward();
Phase * cPhase = phaseRing->getCurrentPhase();
currentGamePhase = cPhase->id;
if (currentPlayer != cPhase->player) nextPlayer();
//init begin of turn
if (currentGamePhase == MTG_PHASE_BEFORE_BEGIN){
cleanupPhase();
currentPlayer->canPutLandsIntoPlay = 1;
mLayers->actionLayer()->Update(0);
return nextGamePhase();
}
//manaBurn
if (currentGamePhase == MTG_PHASE_UNTAP ||
currentGamePhase == MTG_PHASE_FIRSTMAIN ||
currentGamePhase == MTG_PHASE_COMBATBEGIN ||
currentGamePhase == MTG_PHASE_SECONDMAIN ||
currentGamePhase == MTG_PHASE_ENDOFTURN
){
currentPlayer->manaBurn();
}
//After End of turn
if (currentGamePhase == MTG_PHASE_AFTER_EOT){
//Auto Hand cleaning, in case the player didn't do it himself
while(currentPlayer->game->hand->nb_cards > 7){
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
}
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
mLayers->actionLayer()->Update(0);
return nextGamePhase();
}
//Phase Specific actions
switch(currentGamePhase){
case MTG_PHASE_UNTAP:
untapPhase();
break;
case MTG_PHASE_DRAW:
mLayers->stackLayer()->addDraw(currentPlayer,1);
break;
default:
break;
}
}
int GameObserver::cancelCurrentAction(){
SAFE_DELETE(targetChooser);
return 1;
}
void GameObserver::userRequestNextGamePhase(){
if (mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)) return;
if (getCurrentTargetChooser()) return;
if (mLayers->combatLayer()->remainingDamageSteps) return;
//TODO CHECK POSSIBILITY
if (opponent()->isAI() || GameOptions::GetInstance()->values[OPTIONS_INTERRUPTATENDOFPHASE_OFFSET+currentGamePhase]){
mLayers->stackLayer()->AddNextGamePhase();
}else{
nextGamePhase();
}
}
void GameObserver::startGame(int shuffle, int draw){
int i;
for (i=0; i<nbPlayers; i++){
players[i]->game->initGame(shuffle, draw);
}
phaseRing->goToPhase(MTG_PHASE_FIRSTMAIN, players[0]);
currentGamePhase = MTG_PHASE_FIRSTMAIN;
}
void GameObserver::addObserver(MTGAbility * observer){
mLayers->actionLayer()->Add(observer);
}
void GameObserver::removeObserver(ActionElement * observer){
if (observer){
observer->destroy();
}else{
//TODO log error
}
mLayers->actionLayer()->Remove(observer);
}
GameObserver::~GameObserver(){
LOG("==Destroying GameObserver==");
SAFE_DELETE(targetChooser);
SAFE_DELETE(mLayers);
SAFE_DELETE(phaseRing);
LOG("==GameObserver Destroyed==");
}
void GameObserver::Update(float dt){
Player * player = currentPlayer;
if (currentGamePhase == MTG_PHASE_COMBATBLOCKERS){
player = opponent();
}else if (currentGamePhase == MTG_PHASE_COMBATDAMAGE){
DamageResolverLayer * drl = mLayers->combatLayer();
if (drl->currentChoosingPlayer && drl->mCount) player = drl->currentChoosingPlayer;
}
currentActionPlayer = player;
if (isInterrupting) player = isInterrupting;
mLayers->Update(dt,player);
stateEffects();
oldGamePhase = currentGamePhase;
}
//applies damage to creatures after updates
//Players life test
void GameObserver::stateEffects(){
for (int i =0; i < 2; i++){
MTGGameZone * zone = players[i]->game->inPlay;
for (int j = zone->nb_cards-1 ; j>=0; j--){
MTGCardInstance * card = zone->cards[j];
card->afterDamage();
}
}
for (int i =0; i < 2; i++){
if (players[i]->life <= 0) 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));
}
}
void GameObserver::nextStep(){
}
void GameObserver::ButtonPressed (int controllerId, PlayGuiObject * _object){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Click\n");
#endif
int id = _object->GetId();
if (id >=0){
MTGCardInstance * card = ((CardGui *)_object)->card;
cardClick(card, card);
}
//if (id>= -6 && id <= -3){
if (id== -5 || id == -3){ //TODO libraries ???
GuiGameZone * zone = (GuiGameZone *)_object;
zone->toggleDisplay();
}
if (id == -1 || id == -2){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Click Player !\n");
#endif
cardClick(NULL, ((GuiAvatar *)_object)->player);
}
}
void GameObserver::stackObjectClicked(Interruptible * action){
if (targetChooser != NULL){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser ok \n");
#endif
int result = targetChooser->toggleTarget(action);
if (result == TARGET_OK_FULL){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser Full \n");
#endif
cardClick(cardWaitingForTargets);
}else{
return;
}
}else{
reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(action);
}
}
void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
LOG("==GameObserver::cardClick");
if (card) {LOG(card->getName())};
Player * clickedPlayer = NULL;
if (!card) clickedPlayer = ((Player *)object);
if (targetChooser != NULL){
int result;
if (card) {
if (card == cardWaitingForTargets){
LOG("attempt to close targetting");
int _result = targetChooser->ForceTargetListReady();
if (_result){
result = TARGET_OK_FULL;
}else{
LOG("...but we cant!\n");
result = targetChooser->targetsReadyCheck();
}
}else{
result = targetChooser->toggleTarget(card);
}
}else{
result = targetChooser->toggleTarget(clickedPlayer);
}
if (result == TARGET_OK_FULL){
card = cardWaitingForTargets;
}else{
return;
}
}
if (card){
reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
}else{
reaction = mLayers->actionLayer()->isReactingToTargetClick(object);
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(object);
}
if (reaction != -1){
if (!card) return;
if (currentlyActing()->game->hand->hasCard(card)){
//Current player's hand
if (canPutInPlay(card)){
putInPlay(card);
if (card->hasType("land")){
currentPlayer->canPutLandsIntoPlay--;
}
}else if (currentPlayer->game->hand->hasCard(card)){ //Current player's hand
if (currentGamePhase == MTG_PHASE_CLEANUP && currentPlayer->game->hand->nb_cards > 7){
currentPlayer->game->putInGraveyard(card);
}
}
}else if (reaction){
if (reaction == 1){
mLayers->actionLayer()->reactToClick(card);
}else{
mLayers->actionLayer()->setMenuObject(object);
}
}else if (card->isTapped() && card->controller() == currentPlayer){
int a = ConstraintResolver::untap(this, card);
}
}
}
TargetChooser * GameObserver::getCurrentTargetChooser(){
TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser();
if (_tc) return _tc;
return targetChooser;
}
//Check if it is possible to put a card into play
//TODO : improve according to spells in game...
int GameObserver::canPutInPlay(MTGCardInstance * card){
Player * player = currentlyActing();
LOG("CANPUTINPLAY- check if card belongs to current player\n");
if (!player->game->hand->hasCard(card)) return 0;
LOG("CANPUTINPLAY- check if card is land or can be played\n");
if (card->hasType("land")){
LOG("CANPUTINPLAY- card is land - check if can be played\n");
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN)){
LOG("CANPUTINPLAY- Land, ok\n");
return 1;
}
}else if ((card->hasType("instant")) || card->has(FLASH) || (player == currentPlayer && (currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN))){
LOG("CANPUTINPLAY- correct time to play\n");
if (checkManaCost(card)){
LOG("CANPUTINPLAY- ManaCost ok\n");
if (targetListIsSet(card)){
#ifdef LOG
LOG("CANPUTINPLAY- Targets chosen -> OK\n");
#endif
return 1;
}else{
#ifdef LOG
LOG("CANPUTINPLAY- Targets not chosen yet\n");
#endif
return 0;
}
}
}
return 0;
}
void GameObserver::putInPlay(MTGCardInstance * card){
Player * player = currentlyActing();
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
player->getManaPool()->pay(card->getManaCost());
ManaCost * spellCost = previousManaPool->Diff(player->getManaPool());
delete previousManaPool;
if (card->hasType("land")){
Spell * spell = NEW Spell(card);
player->game->putInZone(card, player->game->hand, player->game->stack);
spell->resolve();
delete spellCost;
delete spell;
}else{
if (targetChooser){
mLayers->stackLayer()->addSpell(card,targetChooser->targets,targetChooser->cursor, spellCost);
delete targetChooser;
targetChooser = NULL;
}else{
mLayers->stackLayer()->addSpell(card,NULL,0, spellCost);
}
player->game->putInZone(card, player->game->hand, player->game->stack);
}
}
/* 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;
}
return 0;
}
void GameObserver::draw(){
//TODO checks to allow multiple draw, or no draw, etc...
currentPlayer->game->drawFromLibrary();
}
void GameObserver::cleanupPhase(){
currentPlayer->cleanupPhase();
opponent()->cleanupPhase();
}
void GameObserver::untapPhase(){
currentPlayer->inPlay()->untapAll();
}
int GameObserver::isACreature(MTGCardInstance * card){
return card->isACreature();
}
Player * GameObserver::currentlyActing(){
if (isInterrupting) return isInterrupting;
return currentActionPlayer;
}
int GameObserver::tryToTapOrUntap(MTGCardInstance * card){
int reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction){
if (reaction == 1){
mLayers->actionLayer()->reactToClick(card);
}else{
//TODO, what happens when several abilities react to the click ?
}
return reaction;
}else{
if (card->isTapped() && card->controller() == currentPlayer){
int a = ConstraintResolver::untap(this, card);
return a;
}else{
//TODO Check Spells
//card->tap();
return 0;
}
return 0;
}
}
//TODO CORRECT THIS MESS
int GameObserver::targetListIsSet(MTGCardInstance * card){
if (targetChooser == NULL){
TargetChooserFactory tcf;
targetChooser = tcf.createTargetChooser(card);
cardWaitingForTargets = card;
if (targetChooser == NULL){
return 1;
}
}
return (targetChooser->targetListSet());
}
int GameObserver::checkManaCost(MTGCardInstance * card){
ManaCost * playerMana = currentlyActing()->getManaPool();
ManaCost * cost = card->getManaCost();
if (playerMana->canAfford(cost)){
return 1;
}
return 0;
}

View File

@@ -1,61 +1,61 @@
#include "../include/debug.h"
#include "../include/GameOptions.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
GameOptions* GameOptions::mInstance = NULL;
GameOptions * GameOptions::GetInstance(){
if (mInstance == NULL)
mInstance = NEW GameOptions();
return mInstance;
}
GameOptions::GameOptions(){
for(int i = 0; i < MAX_OPTIONS; i++){
values[i] = 0;
}
load();
}
int GameOptions::load(){
std::ifstream file(OPTIONS_SAVEFILE);
std::string s;
if(file){
for (int i = 0; i < MAX_OPTIONS; i++){
if(std::getline(file,s)){
values[i] = atoi(s.c_str());
}else{
//TODO error management
}
}
file.close();
}
return 1;
}
int GameOptions::save(){
std::ofstream file(OPTIONS_SAVEFILE);
char writer[10];
if (file){
for (int i = 0; i < MAX_OPTIONS; i++){
sprintf(writer,"%i\n", values[i]);
file<<writer;
}
file.close();
}
return 1;
}
GameOptions::~GameOptions(){
}
void GameOptions::Destroy(){
if (mInstance){
delete mInstance;
mInstance = NULL;
}
}
#include "../include/debug.h"
#include "../include/GameOptions.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
GameOptions* GameOptions::mInstance = NULL;
GameOptions * GameOptions::GetInstance(){
if (mInstance == NULL)
mInstance = NEW GameOptions();
return mInstance;
}
GameOptions::GameOptions(){
for(int i = 0; i < MAX_OPTIONS; i++){
values[i] = 0;
}
load();
}
int GameOptions::load(){
std::ifstream file(OPTIONS_SAVEFILE);
std::string s;
if(file){
for (int i = 0; i < MAX_OPTIONS; i++){
if(std::getline(file,s)){
values[i] = atoi(s.c_str());
}else{
//TODO error management
}
}
file.close();
}
return 1;
}
int GameOptions::save(){
std::ofstream file(OPTIONS_SAVEFILE);
char writer[10];
if (file){
for (int i = 0; i < MAX_OPTIONS; i++){
sprintf(writer,"%i\n", values[i]);
file<<writer;
}
file.close();
}
return 1;
}
GameOptions::~GameOptions(){
}
void GameOptions::Destroy(){
if (mInstance){
delete mInstance;
mInstance = NULL;
}
}

View File

@@ -1,305 +1,305 @@
#include "../include/debug.h"
#include "../include/GameStateDuel.h"
#include "../include/utils.h"
#include "../include/AIPlayer.h"
#include "../include/PlayerData.h"
#ifdef TESTSUITE
#include "../include/TestSuiteAI.h"
#endif
GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) {
for (int i = 0; i<2; i ++){
deck[i]=NULL;
mPlayers[i]=NULL;
}
game = NULL;
deckmenu = NULL;
menu = NULL;
#ifdef TESTSUITE
testSuite = NULL;
#endif
}
GameStateDuel::~GameStateDuel() {
End();
}
void GameStateDuel::Start()
{
JRenderer * renderer = JRenderer::GetInstance();
renderer->ResetPrivateVRAM();
renderer->EnableVSync(true);
#ifdef TESTSUITE
if (testSuite) delete testSuite;
testSuite = NEW TestSuite("Res/test/_tests.txt");
#endif
mGamePhase = DUEL_CHOOSE_DECK1;
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetBase(0); // using 2nd font
menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200);
menu->Add(12,"Back to main menu");
menu->Add(13, "Cancel");
int decksneeded = 0;
for (int i = 0; i<2; i ++){
if (mParent->players[i] == PLAYER_TYPE_HUMAN){
if (!deckmenu){
decksneeded = 1;
deckmenu = NEW SimpleMenu(1,this,mFont, 10 , 10, 100, "Choose a Deck");
char buffer[100];
for (int j=1; j<6; j++){
sprintf(buffer, "Res/player/deck%i.txt",j);
std::ifstream file(buffer);
if(file){
deckmenu->Add(j, GameState::menuTexts[j]);
file.close();
decksneeded = 0;
}
}
}
}
}
if (decksneeded)
mGamePhase = ERROR_NO_DECK;
}
void GameStateDuel::loadPlayer(int playerId, int decknb){
if (decknb){ //Human Player
char deckFile[255];
sprintf(deckFile, "Res/player/deck%i.txt",decknb);
char deckFileSmall[255];
sprintf(deckFileSmall, "player_deck%i",decknb);
int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids);
deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements);
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall);
}else{
AIPlayerFactory playerCreator;
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,NULL);
deck[playerId] = mPlayers[playerId]->game;
}
}
#ifdef TESTSUITE
void GameStateDuel::loadTestSuitePlayers(){
OutputDebugString ("loading suite 1\n");
if (!testSuite) return;
for (int i = 0; i < 2; i++){
if (mPlayers[i]){
delete mPlayers[i];
}
mPlayers[i] = NEW TestSuiteAI(mParent->collection,testSuite, i);
OutputDebugString ("loading suite 2\n");
deck[i] = mPlayers[i]->game;
}
if (game) delete game;
game = NULL;
if (!game){
GameObserver::Init(mPlayers, 2);
OutputDebugString ("loading suite 3\n");
game = GameObserver::GetInstance();
OutputDebugString ("loading suite 4\n");
game->startGame(0,0);
OutputDebugString ("loading suite 5\n");
}
}
#endif
void GameStateDuel::End()
{
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Ending GamestateDuel\n");
#endif
GameObserver::EndInstance();
game = NULL;
SAFE_DELETE(deckmenu);
JRenderer::GetInstance()->EnableVSync(false);
for (int i = 0; i < 2; i++){
SAFE_DELETE(mPlayers[i]);
SAFE_DELETE(deck[i]);
}
SAFE_DELETE(menu);
#ifdef TESTSUITE
SAFE_DELETE(testSuite);
#endif
}
void GameStateDuel::Update(float dt)
{
if (mGamePhase == ERROR_NO_DECK){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
}
}else if (mGamePhase == DUEL_CHOOSE_DECK1){
if (mParent->players[0] == PLAYER_TYPE_HUMAN){
deckmenu->Update(dt);
}
#ifdef TESTSUITE
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite && testSuite->loadNext()){
loadTestSuitePlayers();
mGamePhase = DUEL_PLAY;
testSuite->initGame();
char buf[4096];
sprintf(buf, "nb cards in player2's graveyard : %i\n",mPlayers[1]->game->graveyard->nb_cards);
LOG(buf);
}else{
mGamePhase = DUEL_END;
}
}
#endif
else{
loadPlayer(0);
mGamePhase = DUEL_CHOOSE_DECK2;
}
}else if(mGamePhase == DUEL_CHOOSE_DECK2){
if (mParent->players[1] == PLAYER_TYPE_HUMAN){
deckmenu->Update(dt);
}
else{
loadPlayer(1);
mGamePhase = DUEL_PLAY;
}
}else if (mGamePhase == DUEL_PLAY){
if (!game){
GameObserver::Init(mPlayers, 2);
game = GameObserver::GetInstance();
game->startGame();
}
game->Update(dt);
if (game->gameOver){
if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() && mPlayers[0]!= game->gameOver){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "%p - %p", mPlayers[0], game->gameOver);
OutputDebugString(buf);
#endif
PlayerData * playerdata = NEW PlayerData(mParent->collection);
playerdata->credits+= 500;
playerdata->save();
delete playerdata;
}
mGamePhase = DUEL_END;
#ifdef TESTSUITE
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite->loadNext()){
loadTestSuitePlayers();
mGamePhase = DUEL_PLAY;
testSuite->initGame();
}else{
mGamePhase = DUEL_END;
}
}else if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
End();
Start();
}
#endif
mFont->SetColor(ARGB(255,255,255,255));
}
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mGamePhase = DUEL_MENU;
}
}else if (mGamePhase == DUEL_MENU){
menu->Update(dt);
}else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
mParent->SetNextState(GAME_STATE_MENU);
}
}
}
void GameStateDuel::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
if (game)
game->Render();
if (mGamePhase == DUEL_END){
JRenderer::GetInstance()->ClearScreen(ARGB(200,0,0,0));
char buffer[50];
int p0life = mPlayers[0]->life;
if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() ){
if (game->gameOver !=mPlayers[0]){
sprintf (buffer, "Victory! Congratulations, You earn 500 credits");
}else{
sprintf (buffer, "You have been defeated");
}
}else{
int winner = 2;
if (game->gameOver !=mPlayers[0]){
winner = 1;
}
sprintf(buffer, "Player %i wins (%i)", winner, p0life );
}
mFont->DrawString(buffer, 10, 150);
}else if (mGamePhase == DUEL_CHOOSE_DECK1 || mGamePhase == DUEL_CHOOSE_DECK2){
if (deckmenu)
deckmenu->Render();
}else if (mGamePhase == ERROR_NO_DECK){
mFont->DrawString("NO DECK AVAILABLE,",0,SCREEN_HEIGHT/2);
mFont->DrawString("PRESS CIRCLE TO GO TO THE DECK EDITOR!",0,SCREEN_HEIGHT/2 + 20);
}else if (mGamePhase == DUEL_MENU){
menu->Render();
}
}
void GameStateDuel::ButtonPressed(int controllerId, int controlId)
{
switch (controlId)
{
case 1:
case 2:
case 3:
case 4:
case 5:
{
if (mGamePhase == DUEL_CHOOSE_DECK1){
loadPlayer(0,controlId);
mGamePhase = DUEL_CHOOSE_DECK2;
}else{
loadPlayer(1,controlId);
mGamePhase = DUEL_PLAY;
}
break;
}
case 12:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 13:
mGamePhase = DUEL_PLAY;
break;
}
}
#include "../include/debug.h"
#include "../include/GameStateDuel.h"
#include "../include/utils.h"
#include "../include/AIPlayer.h"
#include "../include/PlayerData.h"
#ifdef TESTSUITE
#include "../include/TestSuiteAI.h"
#endif
GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) {
for (int i = 0; i<2; i ++){
deck[i]=NULL;
mPlayers[i]=NULL;
}
game = NULL;
deckmenu = NULL;
menu = NULL;
#ifdef TESTSUITE
testSuite = NULL;
#endif
}
GameStateDuel::~GameStateDuel() {
End();
}
void GameStateDuel::Start()
{
JRenderer * renderer = JRenderer::GetInstance();
renderer->ResetPrivateVRAM();
renderer->EnableVSync(true);
#ifdef TESTSUITE
if (testSuite) delete testSuite;
testSuite = NEW TestSuite("Res/test/_tests.txt");
#endif
mGamePhase = DUEL_CHOOSE_DECK1;
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetBase(0); // using 2nd font
menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200);
menu->Add(12,"Back to main menu");
menu->Add(13, "Cancel");
int decksneeded = 0;
for (int i = 0; i<2; i ++){
if (mParent->players[i] == PLAYER_TYPE_HUMAN){
if (!deckmenu){
decksneeded = 1;
deckmenu = NEW SimpleMenu(1,this,mFont, 10 , 10, 100, "Choose a Deck");
char buffer[100];
for (int j=1; j<6; j++){
sprintf(buffer, "Res/player/deck%i.txt",j);
std::ifstream file(buffer);
if(file){
deckmenu->Add(j, GameState::menuTexts[j]);
file.close();
decksneeded = 0;
}
}
}
}
}
if (decksneeded)
mGamePhase = ERROR_NO_DECK;
}
void GameStateDuel::loadPlayer(int playerId, int decknb){
if (decknb){ //Human Player
char deckFile[255];
sprintf(deckFile, "Res/player/deck%i.txt",decknb);
char deckFileSmall[255];
sprintf(deckFileSmall, "player_deck%i",decknb);
int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids);
deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements);
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall);
}else{
AIPlayerFactory playerCreator;
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,NULL);
deck[playerId] = mPlayers[playerId]->game;
}
}
#ifdef TESTSUITE
void GameStateDuel::loadTestSuitePlayers(){
OutputDebugString ("loading suite 1\n");
if (!testSuite) return;
for (int i = 0; i < 2; i++){
if (mPlayers[i]){
delete mPlayers[i];
}
mPlayers[i] = NEW TestSuiteAI(mParent->collection,testSuite, i);
OutputDebugString ("loading suite 2\n");
deck[i] = mPlayers[i]->game;
}
if (game) delete game;
game = NULL;
if (!game){
GameObserver::Init(mPlayers, 2);
OutputDebugString ("loading suite 3\n");
game = GameObserver::GetInstance();
OutputDebugString ("loading suite 4\n");
game->startGame(0,0);
OutputDebugString ("loading suite 5\n");
}
}
#endif
void GameStateDuel::End()
{
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Ending GamestateDuel\n");
#endif
GameObserver::EndInstance();
game = NULL;
SAFE_DELETE(deckmenu);
JRenderer::GetInstance()->EnableVSync(false);
for (int i = 0; i < 2; i++){
SAFE_DELETE(mPlayers[i]);
SAFE_DELETE(deck[i]);
}
SAFE_DELETE(menu);
#ifdef TESTSUITE
SAFE_DELETE(testSuite);
#endif
}
void GameStateDuel::Update(float dt)
{
if (mGamePhase == ERROR_NO_DECK){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
}
}else if (mGamePhase == DUEL_CHOOSE_DECK1){
if (mParent->players[0] == PLAYER_TYPE_HUMAN){
deckmenu->Update(dt);
}
#ifdef TESTSUITE
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite && testSuite->loadNext()){
loadTestSuitePlayers();
mGamePhase = DUEL_PLAY;
testSuite->initGame();
char buf[4096];
sprintf(buf, "nb cards in player2's graveyard : %i\n",mPlayers[1]->game->graveyard->nb_cards);
LOG(buf);
}else{
mGamePhase = DUEL_END;
}
}
#endif
else{
loadPlayer(0);
mGamePhase = DUEL_CHOOSE_DECK2;
}
}else if(mGamePhase == DUEL_CHOOSE_DECK2){
if (mParent->players[1] == PLAYER_TYPE_HUMAN){
deckmenu->Update(dt);
}
else{
loadPlayer(1);
mGamePhase = DUEL_PLAY;
}
}else if (mGamePhase == DUEL_PLAY){
if (!game){
GameObserver::Init(mPlayers, 2);
game = GameObserver::GetInstance();
game->startGame();
}
game->Update(dt);
if (game->gameOver){
if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() && mPlayers[0]!= game->gameOver){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "%p - %p", mPlayers[0], game->gameOver);
OutputDebugString(buf);
#endif
PlayerData * playerdata = NEW PlayerData(mParent->collection);
playerdata->credits+= 500;
playerdata->save();
delete playerdata;
}
mGamePhase = DUEL_END;
#ifdef TESTSUITE
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite->loadNext()){
loadTestSuitePlayers();
mGamePhase = DUEL_PLAY;
testSuite->initGame();
}else{
mGamePhase = DUEL_END;
}
}else if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
End();
Start();
}
#endif
mFont->SetColor(ARGB(255,255,255,255));
}
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mGamePhase = DUEL_MENU;
}
}else if (mGamePhase == DUEL_MENU){
menu->Update(dt);
}else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
mParent->SetNextState(GAME_STATE_MENU);
}
}
}
void GameStateDuel::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
if (game)
game->Render();
if (mGamePhase == DUEL_END){
JRenderer::GetInstance()->ClearScreen(ARGB(200,0,0,0));
char buffer[50];
int p0life = mPlayers[0]->life;
if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() ){
if (game->gameOver !=mPlayers[0]){
sprintf (buffer, "Victory! Congratulations, You earn 500 credits");
}else{
sprintf (buffer, "You have been defeated");
}
}else{
int winner = 2;
if (game->gameOver !=mPlayers[0]){
winner = 1;
}
sprintf(buffer, "Player %i wins (%i)", winner, p0life );
}
mFont->DrawString(buffer, 10, 150);
}else if (mGamePhase == DUEL_CHOOSE_DECK1 || mGamePhase == DUEL_CHOOSE_DECK2){
if (deckmenu)
deckmenu->Render();
}else if (mGamePhase == ERROR_NO_DECK){
mFont->DrawString("NO DECK AVAILABLE,",0,SCREEN_HEIGHT/2);
mFont->DrawString("PRESS CIRCLE TO GO TO THE DECK EDITOR!",0,SCREEN_HEIGHT/2 + 20);
}else if (mGamePhase == DUEL_MENU){
menu->Render();
}
}
void GameStateDuel::ButtonPressed(int controllerId, int controlId)
{
switch (controlId)
{
case 1:
case 2:
case 3:
case 4:
case 5:
{
if (mGamePhase == DUEL_CHOOSE_DECK1){
loadPlayer(0,controlId);
mGamePhase = DUEL_CHOOSE_DECK2;
}else{
loadPlayer(1,controlId);
mGamePhase = DUEL_PLAY;
}
break;
}
case 12:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 13:
mGamePhase = DUEL_PLAY;
break;
}
}

View File

@@ -1,118 +1,118 @@
#include "../include/debug.h"
#include "../include/GameStateOptions.h"
#include "../include/GameApp.h"
#include "../include/OptionItem.h"
#include "../include/SimpleMenu.h"
#include "../include/GameOptions.h"
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) {
optionsList = NULL;
optionsMenu = NULL;
}
GameStateOptions::~GameStateOptions() {
}
void GameStateOptions::Start()
{
mState = SHOW_OPTIONS;
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
optionsList = NEW OptionsList();
if (GameApp::HasMusic) optionsList->Add(NEW OptionItem(OPTIONS_MUSICVOLUME, "Music volume", 100, 10));
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
optionsMenu->Add(1, "Save & Back to Main Menu");
optionsMenu->Add(2, "Back to Main Menu");
optionsMenu->Add(3, "Cancel");
}
void GameStateOptions::End()
{
JRenderer::GetInstance()->EnableVSync(false);
SAFE_DELETE(optionsList);
}
void GameStateOptions::Update(float dt)
{
if (mState == SHOW_OPTIONS){
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mState = SHOW_OPTIONS_MENU;
}
optionsList->Update(dt);
}else{
optionsMenu->Update(dt);
}
}
void GameStateOptions::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
optionsList->Render();
const char * const CreditsText[] = {
"Wagic, The Homebrew ?! by WilLoW",
"This is a work in progress and it contains bugs, deal with it",
"updates on http://www.wololo.net/wagic",
"",
"Developped with the JGE++ Library",
"http://jge.khors.com",
"",
"this freeware app is not endorsed by Wizards of the Coast, Inc",
};
const char * const MusicText[] = {
"",
"Music by Celestial Aeon Project, under Creative Commons License",
"Their music can be downloaded at http://www.jamendo.com"
};
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetColor(ARGB(255,200,200,200));
mFont->SetScale(0.80);
for (int i = 0; i < 8; i++){
mFont->DrawString(CreditsText[i],SCREEN_WIDTH/2, 40 +18*i,JGETEXT_CENTER);
}
if (GameApp::HasMusic){
for (int i = 0; i < 3; i++){
mFont->DrawString(MusicText[i],SCREEN_WIDTH/2, 40 +18*(8+i),JGETEXT_CENTER);
}
}
mFont->SetScale(1.f);
if (mState == SHOW_OPTIONS_MENU){
optionsMenu->Render();
}
}
void GameStateOptions::ButtonPressed(int controllerId, int controlId)
{
switch (controlId){
case 1:
optionsList->save();
case 2:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 3:
mState = SHOW_OPTIONS;
break;
}
};
#include "../include/debug.h"
#include "../include/GameStateOptions.h"
#include "../include/GameApp.h"
#include "../include/OptionItem.h"
#include "../include/SimpleMenu.h"
#include "../include/GameOptions.h"
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) {
optionsList = NULL;
optionsMenu = NULL;
}
GameStateOptions::~GameStateOptions() {
}
void GameStateOptions::Start()
{
mState = SHOW_OPTIONS;
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
optionsList = NEW OptionsList();
if (GameApp::HasMusic) optionsList->Add(NEW OptionItem(OPTIONS_MUSICVOLUME, "Music volume", 100, 10));
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
optionsMenu->Add(1, "Save & Back to Main Menu");
optionsMenu->Add(2, "Back to Main Menu");
optionsMenu->Add(3, "Cancel");
}
void GameStateOptions::End()
{
JRenderer::GetInstance()->EnableVSync(false);
SAFE_DELETE(optionsList);
}
void GameStateOptions::Update(float dt)
{
if (mState == SHOW_OPTIONS){
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mState = SHOW_OPTIONS_MENU;
}
optionsList->Update(dt);
}else{
optionsMenu->Update(dt);
}
}
void GameStateOptions::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
optionsList->Render();
const char * const CreditsText[] = {
"Wagic, The Homebrew ?! by WilLoW",
"This is a work in progress and it contains bugs, deal with it",
"updates on http://www.wololo.net/wagic",
"",
"Developped with the JGE++ Library",
"http://jge.khors.com",
"",
"this freeware app is not endorsed by Wizards of the Coast, Inc",
};
const char * const MusicText[] = {
"",
"Music by Celestial Aeon Project, under Creative Commons License",
"Their music can be downloaded at http://www.jamendo.com"
};
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetColor(ARGB(255,200,200,200));
mFont->SetScale(0.80);
for (int i = 0; i < 8; i++){
mFont->DrawString(CreditsText[i],SCREEN_WIDTH/2, 40 +18*i,JGETEXT_CENTER);
}
if (GameApp::HasMusic){
for (int i = 0; i < 3; i++){
mFont->DrawString(MusicText[i],SCREEN_WIDTH/2, 40 +18*(8+i),JGETEXT_CENTER);
}
}
mFont->SetScale(1.f);
if (mState == SHOW_OPTIONS_MENU){
optionsMenu->Render();
}
}
void GameStateOptions::ButtonPressed(int controllerId, int controlId)
{
switch (controlId){
case 1:
optionsList->save();
case 2:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 3:
mState = SHOW_OPTIONS;
break;
}
};

View File

@@ -1,5 +1,5 @@
/*
The shop is where the player can buy cards, decks...
The shop is where the player can buy cards, decks...
*/
#include "../include/debug.h"
#include <JRenderer.h>
@@ -12,7 +12,7 @@ GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {}
GameStateShop::~GameStateShop() {
//End(); TODO FIX THAT
//End(); TODO FIX THAT
}
void GameStateShop::Create(){
@@ -24,55 +24,55 @@ void GameStateShop::Create(){
void GameStateShop::Start()
{
menu = NULL;
mFont = GameApp::CommonRes->GetJLBFont("graphics/magic");
mStage = STAGE_SHOP_SHOP;
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/shop.jpg", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 0, 0, 400, 280); // Create background quad for rendering.
backTexture = JRenderer::GetInstance()->LoadTexture("sets/back.jpg", TEX_TYPE_USE_VRAM);
mBack = NEW JQuad(backTexture, 0, 0, 200, 285); // Create background quad for rendering.
menu = NULL;
mFont = GameApp::CommonRes->GetJLBFont("graphics/magic");
mStage = STAGE_SHOP_SHOP;
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/shop.jpg", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 0, 0, 400, 280); // Create background quad for rendering.
backTexture = JRenderer::GetInstance()->LoadTexture("sets/back.jpg", TEX_TYPE_USE_VRAM);
mBack = NEW JQuad(backTexture, 0, 0, 200, 285); // Create background quad for rendering.
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
int sets[500];
int nbsets = 0;
for (int i = 0; i < MtgSets::SetsList->nb_items; i++){
if (mParent->collection->countBySet(i) > 100){ //Only sets with more than 100 cards can get boosters and starters
sets[nbsets] = i;
nbsets++;
}
}
if (nbsets){
setId = sets[(rand() % nbsets)];
}else{
setId = (rand() % MtgSets::SetsList->nb_items);
}
JQuad * mBackThumb = GameApp::CommonRes->GetQuad("back_thumb");
shop = NEW ShopItems(10, this, mFont, 10, 10, mParent->collection, setId);
sprintf(starterBuffer, "%s Starter (60 cards)",MtgSets::SetsList->values[setId].c_str());
sprintf(boosterBuffer, "%s Booster (15 cards)",MtgSets::SetsList->values[setId].c_str());
shop->Add(starterBuffer,mBack,mBackThumb, 6000);
shop->Add(boosterBuffer,mBack,mBackThumb, 1900);
int sets[500];
int nbsets = 0;
for (int i = 0; i < MtgSets::SetsList->nb_items; i++){
if (mParent->collection->countBySet(i) > 100){ //Only sets with more than 100 cards can get boosters and starters
sets[nbsets] = i;
nbsets++;
}
}
if (nbsets){
setId = sets[(rand() % nbsets)];
}else{
setId = (rand() % MtgSets::SetsList->nb_items);
}
JQuad * mBackThumb = GameApp::CommonRes->GetQuad("back_thumb");
shop = NEW ShopItems(10, this, mFont, 10, 10, mParent->collection, setId);
sprintf(starterBuffer, "%s Starter (60 cards)",MtgSets::SetsList->values[setId].c_str());
sprintf(boosterBuffer, "%s Booster (15 cards)",MtgSets::SetsList->values[setId].c_str());
shop->Add(starterBuffer,mBack,mBackThumb, 6000);
shop->Add(boosterBuffer,mBack,mBackThumb, 1900);
for (int i = 0; i < 4; i++){
shop->Add(mParent->collection->randomCardId());
}
shop->Add(mParent->collection->randomCardId());
}
}
void GameStateShop::End()
{
JRenderer::GetInstance()->EnableVSync(false);
if (shop)
SAFE_DELETE(shop);
SAFE_DELETE(mBack);
if(bgTexture)
SAFE_DELETE(bgTexture);
if(mBg)
SAFE_DELETE(mBg);
if(menu)
SAFE_DELETE(menu);
JRenderer::GetInstance()->EnableVSync(false);
if (shop)
SAFE_DELETE(shop);
SAFE_DELETE(mBack);
if(bgTexture)
SAFE_DELETE(bgTexture);
if(mBg)
SAFE_DELETE(mBg);
if(menu)
SAFE_DELETE(menu);
}
void GameStateShop::Destroy(){
@@ -80,52 +80,52 @@ void GameStateShop::Destroy(){
void GameStateShop::Update(float dt)
{
if (mStage == STAGE_SHOP_MENU){
if (menu){
menu->Update(dt);
}else{
menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200);
menu->Add(12,"Save & Back to main menu");
menu->Add(13, "Cancel");
}
}else{
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mStage = STAGE_SHOP_MENU;
}
if (shop)
shop->Update(dt);
}
if (mStage == STAGE_SHOP_MENU){
if (menu){
menu->Update(dt);
}else{
menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200);
menu->Add(12,"Save & Back to main menu");
menu->Add(13, "Cancel");
}
}else{
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mStage = STAGE_SHOP_MENU;
}
if (shop)
shop->Update(dt);
}
}
void GameStateShop::Render()
void GameStateShop::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
if (mBg)JRenderer::GetInstance()->RenderQuad(mBg,0,0);
if (mBg)JRenderer::GetInstance()->RenderQuad(mBg,0,0);
if (shop)
shop->Render();
if (mStage == STAGE_SHOP_MENU && menu){
menu->Render();
}
shop->Render();
if (mStage == STAGE_SHOP_MENU && menu){
menu->Render();
}
}
void GameStateShop::ButtonPressed(int controllerId, int controlId)
{
switch (controllerId){
case 10:
shop->pricedialog(controlId);
break;
case 11:
if (controlId == 12){
shop->saveAll();
mParent->SetNextState(GAME_STATE_MENU);
}else{
mStage = STAGE_SHOP_SHOP;
}
break;
}
switch (controllerId){
case 10:
shop->pricedialog(controlId);
break;
case 11:
if (controlId == 12){
shop->saveAll();
mParent->SetNextState(GAME_STATE_MENU);
}else{
mStage = STAGE_SHOP_SHOP;
}
break;
}
}

View File

@@ -5,7 +5,7 @@
GuiLayer::GuiLayer(int id, GameObserver* _game):JGuiController(id, NULL){
game = _game;
modal = 0;
hasFocus = 0;
hasFocus = 0;
}
GuiLayer::~GuiLayer(){
@@ -13,7 +13,7 @@ GuiLayer::~GuiLayer(){
}
int GuiLayer::getMaxId(){
return mCount;
return mCount;
}
void GuiLayer::Update(float dt){
@@ -24,16 +24,16 @@ void GuiLayer::Update(float dt){
void GuiLayer::resetObjects(){
for (int i=0;i<mCount;i++)
for (int i=0;i<mCount;i++)
if (mObjects[i])
delete mObjects[i];
mCount = 0;
mCurr = 0;
mCount = 0;
mCurr = 0;
}
void GuiLayer::RenderMessageBackground(float x0, float y0, float width, int height){
PIXEL_TYPE colors_up[] =
PIXEL_TYPE colors_up[] =
{
ARGB(0,255,255,255),
ARGB(0,255,255,255),
@@ -52,13 +52,13 @@ void GuiLayer::RenderMessageBackground(float x0, float y0, float width, int heig
JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRect(x0,y0,width,height/2,colors_up);
renderer->FillRect(x0,y0+height/2,width,height/2,colors_down);
// mEngine->DrawLine(0,y0,SCREEN_WIDTH,y0,ARGB(128,255,255,255));
// mEngine->DrawLine(0,y0+height,SCREEN_WIDTH,y0+height,ARGB(128,255,255,255));
}
void GuiLayer::RenderMessageBackground(float y0, int height){
RenderMessageBackground(0,y0,SCREEN_WIDTH, height);
RenderMessageBackground(0,y0,SCREEN_WIDTH, height);
}
@@ -73,14 +73,14 @@ void GuiLayer::setModal(int _modal){
int GuiLayer::getIndexOf(JGuiObject * object){
for (int i=0; i<mCount; i++){
if (mObjects[i] == object)
return i;
}
return -1;
if (mObjects[i] == object)
return i;
}
return -1;
}
JGuiObject * GuiLayer::getByIndex(int index){
return mObjects[index];
return mObjects[index];
}
@@ -89,27 +89,27 @@ GuiLayers::GuiLayers(){
}
GuiLayers::~GuiLayers(){
LOG("==Destroying GuiLayers==");
for (int i=0; i<nbitems; i++){
delete objects[i];
}
LOG("==Destroying GuiLayers Successful==");
LOG("==Destroying GuiLayers==");
for (int i=0; i<nbitems; i++){
delete objects[i];
}
LOG("==Destroying GuiLayers Successful==");
}
int GuiLayers::unstopableRenderInProgress(){
for (int i=0; i<nbitems; i++){
if (objects[i]->unstopableRenderInProgress())
return 1;
return 1;
}
return 0;
return 0;
}
void GuiLayers::Add(GuiLayer * layer){
if (nbitems >=MAX_GUI_LAYERS || nbitems < 0){
LOG("OUT OF BOUND IN GuiLayers Add !!!");
return;
}
if (nbitems >=MAX_GUI_LAYERS || nbitems < 0){
LOG("OUT OF BOUND IN GuiLayers Add !!!");
return;
}
objects[nbitems] = layer;
nbitems++;
}
@@ -121,23 +121,23 @@ void GuiLayers::Remove(){
void GuiLayers::Update(float dt, Player * currentPlayer){
int i;
int modal = 0;
int isAI = currentPlayer->isAI();
int isAI = currentPlayer->isAI();
for (i=0; i<nbitems; i++){
objects[i]->hasFocus = 0;
objects[i]->hasFocus = 0;
objects[i]->Update(dt);
if (!isAI && !modal){
objects[i]->hasFocus = 1;
objects[i]->hasFocus = 1;
objects[i]->CheckUserInput(dt);
modal = objects[i]->isModal();
}
}
if (isAI){
currentPlayer->Act(dt);
}
if (isAI){
currentPlayer->Act(dt);
}
}
void GuiLayers::Render(){
for (int i=nbitems-1; i>=0; i--){
objects[i]->Render();
objects[i]->Render();
}
}

View File

@@ -2,60 +2,60 @@
void GuiMessageBox::CheckUserInput(){
if (mEngine->GetButtonClick(mActionButton))
if (mEngine->GetButtonClick(mActionButton))
{
if (mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
{
if (mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
{
if (mListener != NULL)
{
mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
return;
}
}
if (mListener != NULL)
{
mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
return;
}
}
if (mEngine->GetButtonState(PSP_CTRL_LEFT) || mEngine->GetButtonState(PSP_CTRL_UP) || mEngine->GetAnalogY()<64)
{
if (KeyRepeated(PSP_CTRL_UP, dt))
{
int n = mCurr;
n--;
if (n<0)
{
if ((mStyle&JGUI_STYLE_WRAPPING))
n = mCount-1;
else
n = 0;
}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_UP))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
}
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT) || mEngine->GetButtonState(PSP_CTRL_DOWN) || mEngine->GetAnalogY()>192)
if (mEngine->GetButtonState(PSP_CTRL_LEFT) || mEngine->GetButtonState(PSP_CTRL_UP) || mEngine->GetAnalogY()<64)
{
if (KeyRepeated(PSP_CTRL_UP, dt))
{
if (KeyRepeated(PSP_CTRL_DOWN, dt))
{
int n = mCurr;
n++;
if (n>mCount-1)
{
if ((mStyle&JGUI_STYLE_WRAPPING))
n = 0;
else
n = mCount-1;
}
int n = mCurr;
n--;
if (n<0)
{
if ((mStyle&JGUI_STYLE_WRAPPING))
n = mCount-1;
else
n = 0;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_UP))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
}
else
mLastKey = 0;
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT) || mEngine->GetButtonState(PSP_CTRL_DOWN) || mEngine->GetAnalogY()>192)
{
if (KeyRepeated(PSP_CTRL_DOWN, dt))
{
int n = mCurr;
n++;
if (n>mCount-1)
{
if ((mStyle&JGUI_STYLE_WRAPPING))
n = 0;
else
n = mCount-1;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
}
}
else
mLastKey = 0;
}

View File

@@ -1,23 +1,23 @@
#include "../include/debug.h"
#include "../include/Logger.h"
#include <iostream>
#include <fstream>
using namespace std;
#if defined (WIN32)
#include <windows.h>
#endif
void Logger::Log(char * text){
ofstream file (LOG_FILE,ios_base::app);
if (file){
file << text;
file << "\n";
file.close();
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString(text);
OutputDebugString("\n");
#endif
}
#include "../include/debug.h"
#include "../include/Logger.h"
#include <iostream>
#include <fstream>
using namespace std;
#if defined (WIN32)
#include <windows.h>
#endif
void Logger::Log(char * text){
ofstream file (LOG_FILE,ios_base::app);
if (file){
file << text;
file << "\n";
file.close();
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString(text);
OutputDebugString("\n");
#endif
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,310 +1,310 @@
//------------------------------------------------------
//MTGCard Class
//-------------------------------------------------
//TODO Fill BasicAbilities
#include "../include/debug.h"
#include "../include/MTGCard.h"
#include "../include/TexturesCache.h"
#include "../include/Subtypes.h"
#include <string>
#include <stdlib.h>
using std::string;
const char * const MTGCard::Colors_To_Text[] = {"Artifact", "Green", "Blue", "Red", "Black", "White", "Land"};
MTGCard::MTGCard(){
init();
mCache = NULL;
}
MTGCard::MTGCard(TexturesCache * cache, int set_id){
init();
mCache = cache;
setId = set_id;
}
const char * MTGCard::getSetName(){
return MtgSets::SetsList->values[setId].c_str();
}
MTGCard::MTGCard(MTGCard * source){
mCache = source->mCache;
for (int i = 0; i< NB_BASIC_ABILITIES; i++){
basicAbilities[i] = source->basicAbilities[i];
}
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
types[i] = source->types[i];
}
nb_types = source->nb_types;
for (int i = 0; i< MTG_NB_COLORS; i++){
colors[i] = source->colors[i];
}
manaCost.copy(source->getManaCost());
text = source->text;
name = source->name;
strcpy(image_name, source->image_name);
rarity = source->rarity;
power = source->power;
toughness = source->toughness;
mtgid = source->mtgid;
setId = source->setId;
formattedTextInit = 0;
magicText = source->magicText;
spellTargetType = source->spellTargetType;
alias = source->alias;
}
int MTGCard::init(){
nb_types = 0;
for (int i = 0; i< NB_BASIC_ABILITIES; i++){
basicAbilities[i] = 0;
}
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
types[i] = 0;
}
for (int i = 0; i< MTG_NB_COLORS; i++){
colors[i] = 0;
}
setId = 0;
formattedTextInit = 0;
magicText = "";
spellTargetType = "";
alias = 0;
return 1;
}
JQuad * MTGCard::getQuad(int type){
if (mCache == NULL){
return NULL;
}
return mCache->getQuad(this, type);
}
JQuad * MTGCard::getThumb(){
return getQuad(CACHE_THUMB);
}
JQuad * MTGCard::getQuad(TexturesCache * cache){
return cache->getQuad(this);
}
int MTGCard::isACreature(){
return (hasSubtype("creature"));
}
void MTGCard::setColor(int _color, int removeAllOthers){
if (removeAllOthers){
for (int i=0; i<MTG_NB_COLORS; i++){
colors[i] = 0;
}
}
colors[_color] = 1;
}
int MTGCard::getColor(){
int i = 0;
for (int i=0; i<MTG_NB_COLORS; i++){
if (colors[i]){
return i;
}
}
return 0;
}
int MTGCard::hasColor(int color){
return (colors[color]);
}
void MTGCard::setManaCost(string s){
ManaCost::parseManaCost(s, &manaCost);
for (int i = MTG_COLOR_GREEN; i <=MTG_COLOR_WHITE; i++){
if (manaCost.hasColor(i)){
setColor(i);
}
}
}
const char * MTGCard::colorToString(){
int color = getColor();
if (color>=0 && color <=5){
return Colors_To_Text[color];
}
return "Unknown";
}
void MTGCard::setMTGId(int id){
mtgid = id;
sprintf(image_name, "%d.jpg", mtgid);
}
int MTGCard::getMTGId(){
return mtgid;
}
int MTGCard::getId(){
return mtgid;
}
char MTGCard::getRarity(){
return rarity;
}
void MTGCard::setRarity(char _rarity){
rarity = _rarity;
}
void MTGCard::setType(const char * _type_text){
setSubtype(_type_text);
}
void MTGCard::addType(char * _type_text){
setSubtype(_type_text);
}
void MTGCard::setSubtype( string value){
string s = value;
while (s.size()){
unsigned int found = s.find(" ");
if (found != string::npos){
int id = Subtypes::subtypesList->Add(s.substr(0,found));
addType(id);
s = s.substr(found+1);
}else{
int id = Subtypes::subtypesList->Add(s);
addType(id);
s = "";
}
}
}
void MTGCard::addType(int id){
types[nb_types] = id;
nb_types++;
}
//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 MTGCard::removeType(string value, int removeAll){
int id = Subtypes::subtypesList->Add(value);
return removeType(id, removeAll);
}
int MTGCard::removeType(int id, int removeAll){
int result = 0;
for (int i = nb_types -1 ; i >=0; i--){
if (types[i] == id){
types[i] = types[nb_types -1];
nb_types--;
result++;
if (!removeAll) return result;
}
}
return result;
}
char * MTGCard::getImageName(){
return image_name;
}
void MTGCard::setText( string value){
text = value;
}
const char * MTGCard::getText(){
return text.c_str();
}
void MTGCard::addMagicText(string value){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
if (magicText.size()) magicText.append("\n");
magicText.append(value);
}
void MTGCard::setName( string value){
name = value;
}
const char * MTGCard::getName(){
return name.c_str();
}
ManaCost * MTGCard::getManaCost(){
return &manaCost;
}
int MTGCard::hasType(int _type){
int i;
for (i = 0; i<nb_types; i++){
if(types[i] == _type){
return 1;
}
}
return 0;
}
int MTGCard::hasSubtype(int _subtype){
return(hasType(_subtype));
}
int MTGCard::hasType(const char * _type){
int id = Subtypes::subtypesList->Add(_type);
return(hasType(id));
}
int MTGCard::hasSubtype(const char * _subtype){
int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id));
}
int MTGCard::hasSubtype(string _subtype){
int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id));
}
int MTGCard::has(int basicAbility){
return basicAbilities[basicAbility];
}
//---------------------------------------------
// Creature specific
//---------------------------------------------
void MTGCard::setPower(int _power){
power = _power;
}
int MTGCard::getPower(){
return power;
}
void MTGCard::setToughness(int _toughness){
toughness = _toughness;
}
int MTGCard::getToughness(){
return toughness;
}
//------------------------------------------------------
//MTGCard Class
//-------------------------------------------------
//TODO Fill BasicAbilities
#include "../include/debug.h"
#include "../include/MTGCard.h"
#include "../include/TexturesCache.h"
#include "../include/Subtypes.h"
#include <string>
#include <stdlib.h>
using std::string;
const char * const MTGCard::Colors_To_Text[] = {"Artifact", "Green", "Blue", "Red", "Black", "White", "Land"};
MTGCard::MTGCard(){
init();
mCache = NULL;
}
MTGCard::MTGCard(TexturesCache * cache, int set_id){
init();
mCache = cache;
setId = set_id;
}
const char * MTGCard::getSetName(){
return MtgSets::SetsList->values[setId].c_str();
}
MTGCard::MTGCard(MTGCard * source){
mCache = source->mCache;
for (int i = 0; i< NB_BASIC_ABILITIES; i++){
basicAbilities[i] = source->basicAbilities[i];
}
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
types[i] = source->types[i];
}
nb_types = source->nb_types;
for (int i = 0; i< MTG_NB_COLORS; i++){
colors[i] = source->colors[i];
}
manaCost.copy(source->getManaCost());
text = source->text;
name = source->name;
strcpy(image_name, source->image_name);
rarity = source->rarity;
power = source->power;
toughness = source->toughness;
mtgid = source->mtgid;
setId = source->setId;
formattedTextInit = 0;
magicText = source->magicText;
spellTargetType = source->spellTargetType;
alias = source->alias;
}
int MTGCard::init(){
nb_types = 0;
for (int i = 0; i< NB_BASIC_ABILITIES; i++){
basicAbilities[i] = 0;
}
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
types[i] = 0;
}
for (int i = 0; i< MTG_NB_COLORS; i++){
colors[i] = 0;
}
setId = 0;
formattedTextInit = 0;
magicText = "";
spellTargetType = "";
alias = 0;
return 1;
}
JQuad * MTGCard::getQuad(int type){
if (mCache == NULL){
return NULL;
}
return mCache->getQuad(this, type);
}
JQuad * MTGCard::getThumb(){
return getQuad(CACHE_THUMB);
}
JQuad * MTGCard::getQuad(TexturesCache * cache){
return cache->getQuad(this);
}
int MTGCard::isACreature(){
return (hasSubtype("creature"));
}
void MTGCard::setColor(int _color, int removeAllOthers){
if (removeAllOthers){
for (int i=0; i<MTG_NB_COLORS; i++){
colors[i] = 0;
}
}
colors[_color] = 1;
}
int MTGCard::getColor(){
int i = 0;
for (int i=0; i<MTG_NB_COLORS; i++){
if (colors[i]){
return i;
}
}
return 0;
}
int MTGCard::hasColor(int color){
return (colors[color]);
}
void MTGCard::setManaCost(string s){
ManaCost::parseManaCost(s, &manaCost);
for (int i = MTG_COLOR_GREEN; i <=MTG_COLOR_WHITE; i++){
if (manaCost.hasColor(i)){
setColor(i);
}
}
}
const char * MTGCard::colorToString(){
int color = getColor();
if (color>=0 && color <=5){
return Colors_To_Text[color];
}
return "Unknown";
}
void MTGCard::setMTGId(int id){
mtgid = id;
sprintf(image_name, "%d.jpg", mtgid);
}
int MTGCard::getMTGId(){
return mtgid;
}
int MTGCard::getId(){
return mtgid;
}
char MTGCard::getRarity(){
return rarity;
}
void MTGCard::setRarity(char _rarity){
rarity = _rarity;
}
void MTGCard::setType(const char * _type_text){
setSubtype(_type_text);
}
void MTGCard::addType(char * _type_text){
setSubtype(_type_text);
}
void MTGCard::setSubtype( string value){
string s = value;
while (s.size()){
unsigned int found = s.find(" ");
if (found != string::npos){
int id = Subtypes::subtypesList->Add(s.substr(0,found));
addType(id);
s = s.substr(found+1);
}else{
int id = Subtypes::subtypesList->Add(s);
addType(id);
s = "";
}
}
}
void MTGCard::addType(int id){
types[nb_types] = id;
nb_types++;
}
//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 MTGCard::removeType(string value, int removeAll){
int id = Subtypes::subtypesList->Add(value);
return removeType(id, removeAll);
}
int MTGCard::removeType(int id, int removeAll){
int result = 0;
for (int i = nb_types -1 ; i >=0; i--){
if (types[i] == id){
types[i] = types[nb_types -1];
nb_types--;
result++;
if (!removeAll) return result;
}
}
return result;
}
char * MTGCard::getImageName(){
return image_name;
}
void MTGCard::setText( string value){
text = value;
}
const char * MTGCard::getText(){
return text.c_str();
}
void MTGCard::addMagicText(string value){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
if (magicText.size()) magicText.append("\n");
magicText.append(value);
}
void MTGCard::setName( string value){
name = value;
}
const char * MTGCard::getName(){
return name.c_str();
}
ManaCost * MTGCard::getManaCost(){
return &manaCost;
}
int MTGCard::hasType(int _type){
int i;
for (i = 0; i<nb_types; i++){
if(types[i] == _type){
return 1;
}
}
return 0;
}
int MTGCard::hasSubtype(int _subtype){
return(hasType(_subtype));
}
int MTGCard::hasType(const char * _type){
int id = Subtypes::subtypesList->Add(_type);
return(hasType(id));
}
int MTGCard::hasSubtype(const char * _subtype){
int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id));
}
int MTGCard::hasSubtype(string _subtype){
int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id));
}
int MTGCard::has(int basicAbility){
return basicAbilities[basicAbility];
}
//---------------------------------------------
// Creature specific
//---------------------------------------------
void MTGCard::setPower(int _power){
power = _power;
}
int MTGCard::getPower(){
return power;
}
void MTGCard::setToughness(int _toughness){
toughness = _toughness;
}
int MTGCard::getToughness(){
return toughness;
}

View File

@@ -1,407 +1,407 @@
/*---------------------------------------------
Card Instance
Instance of a given MTGCard in the game
Although there is only one MTGCard of each type, there can be as much Instances of it as needed in the game
--------------------------------------------
*/
#include "../include/debug.h"
#include "../include/MTGCardInstance.h"
#include "../include/CardDescriptor.h"
#include "../include/Counters.h"
MTGCardInstance::MTGCardInstance(): MTGCard(), Damageable(0){
LOG("==Creating MTGCardInstance==");
initMTGCI();
LOG("==Creating MTGCardInstance Successful==");
}
MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to): MTGCard(card), Damageable(card->getToughness()){
LOG("==Creating MTGCardInstance==");
initMTGCI();
model = card;
lifeOrig = life;
belongs_to=_belongs_to;
initAttackersDefensers();
life=toughness;
LOG("==Creating MTGCardInstance Successful==");
}
MTGCardInstance::~MTGCardInstance(){
LOG("==Deleting MTGCardInstance==");
SAFE_DELETE(blockers);
SAFE_DELETE(counters);
LOG("==Deleting MTGCardInstance Succesfull==");
}
void MTGCardInstance::initMTGCI(){
model=NULL;
lifeOrig = 0;
doDamageTest = 0;
belongs_to=NULL;
tapped = 0;
blockers = NEW Blockers();
untapping = 0;
summoningSickness = 0;
target = NULL;
nbprotections = 0;
type_as_damageable = DAMAGEABLE_MTGCARDINSTANCE;
banding = NULL;
owner = NULL;
changedZoneRecently = 0;
counters = NEW Counters(this);
}
void MTGCardInstance::addType(int type){
types[nb_types] = type;
nb_types++;
}
Blockers * MTGCardInstance::getBlockers(){
return blockers;
}
int MTGCardInstance::isInPlay(){
GameObserver * game = GameObserver::GetInstance();
for (int i = 0 ; i < 2 ; i++){
MTGGameZone * zone = game->players[i]->game->inPlay;
if (zone->hasCard(this)) return 1;
}
return 0;
}
int MTGCardInstance::afterDamage(){
if (!doDamageTest) return 0;
#if defined (WIN32) || defined (LINUX)
char buf[4096], *p = buf;
sprintf(buf,"After Damage Test, life is %i for %s \n",life,model->getName());
OutputDebugString(buf);
#endif
doDamageTest = 0;
if (life <=0 && isInPlay()){
GameObserver * game = GameObserver::GetInstance();
game->mLayers->stackLayer()->addPutInGraveyard(this);
return 1;
}
return 0;
}
MTGGameZone * MTGCardInstance::getCurrentZone(){
GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2; i++){
MTGPlayerCards * g = game->players[i]->game;
MTGGameZone * zones[] = {g->inPlay,g->graveyard,g->hand, g->library};
for (int k = 0; k < 4; k++){
MTGGameZone * zone = zones[k];
if (zone->hasCard(this)) return zone;
}
}
return NULL;
}
JQuad * MTGCardInstance::getIcon(){
return getThumb();
}
int MTGCardInstance::has(int basicAbility){
return basicAbilities[basicAbility];
}
//Taps the card
void MTGCardInstance::tap(){
tapped = 1;
}
void MTGCardInstance::setUntapping(){
untapping = 1;
}
int MTGCardInstance::isUntapping(){
return untapping;
}
//Untaps the card
void MTGCardInstance::untap(){
if (untapping){
tapped = 0;
untapping = 0;
}
}
//Tells if the card is tapped or not
int MTGCardInstance::isTapped(){
return tapped;
}
void MTGCardInstance::resetAllDamage(){
//for (int i=0;i<nb_damages;i++){
// delete damages[i];
//}
nb_damages = 0;
}
void MTGCardInstance::regenerate(){
tapped = 1;
life = toughness;
initAttackersDefensers();
}
int MTGCardInstance::initAttackersDefensers(){
attacker = 0;
defenser = NULL;
banding = NULL;
return 1;
}
//Function to call to remove all damages, etc to a card (generally at the end of the turn)
int MTGCardInstance::cleanup(){
initAttackersDefensers();
life=toughness;
GameObserver * game = GameObserver::GetInstance();
if (!game || game->currentPlayer == controller()) summoningSickness = 0;
return 1;
}
/* Summoning Sickness
* 212.3f A creature<72>fs activated ability with the tap symbol or the untap symbol in its activation cost
* can<61>ft be played unless the creature has been under its controller<65>fs control since the start of his or
* her most recent turn. A creature can<61>ft attack unless it has been under its controller<65>fs control
* since the start of his or her most recent turn. This rule is informally called the <20>gsummoning
* sickness<73>h rule. Ignore this rule for creatures with haste (see rule 502.5).
*/
int MTGCardInstance::hasSummoningSickness(){
if (!summoningSickness) return 0;
if (basicAbilities[HASTE]) return 0;
if (!isACreature()) return 0;
return 1;
}
int MTGCardInstance::changeController(Player * newController){
Player * originalOwner = controller();
if (originalOwner == newController) return 0;
originalOwner->game->inPlay->removeCard(this);
newController->game->inPlay->addCard(this);
summoningSickness = 1;
return 1;
}
//Reset the card parameters
int MTGCardInstance::reset(){
cleanup();
tapped=0;
SAFE_DELETE(counters);
counters = NEW Counters(this);
return 1;
}
Player * MTGCardInstance::controller(){
GameObserver * game = GameObserver::GetInstance();
if (!game) return NULL;
for (int i = 0; i < 2; i++){
if (game->players[i]->game->inPlay->hasCard(this)) return game->players[i];
if (game->players[i]->game->stack->hasCard(this)) return game->players[i];
if (game->players[i]->game->graveyard->hasCard(this)) return game->players[i];
}
return NULL;
}
int MTGCardInstance::canAttack(){
if (!hasSummoningSickness() && !tapped && isACreature() && basicAbilities[DEFENSER] !=1)
return 1;
return 0;
}
int MTGCardInstance::addToToughness(int value){
toughness+=value;
life+=value;
doDamageTest = 1;
return 1;
}
int MTGCardInstance::setToughness(int value){
toughness=value;
life=value;
doDamageTest = 1;
return 1;
}
int MTGCardInstance::canBlock(){
if (!tapped && isACreature())return 1;
return 0;
}
int MTGCardInstance::canBlock(MTGCardInstance * opponent){
if (!canBlock()) return 0;
if (!opponent) return 1;
if (!opponent->isAttacker()) return 0;
// Comprehensive rule 502.7f : If a creature with protection attacks, it can't be blocked by creatures that have the stated quality.
if (opponent->protectedAgainst(this)) return 0;
if (opponent->basicAbilities[UNBLOCKABLE]) return 0;
if (opponent->basicAbilities[FEAR] && !(hasColor(MTG_COLOR_ARTIFACT) || hasColor(MTG_COLOR_BLACK))) return 0;
if (opponent->basicAbilities[FLYING] && !( basicAbilities[FLYING] || basicAbilities[REACH])) return 0;
// If opponent has shadow and a creature does not have either shadow or reachshadow it cannot be blocked
if (opponent->basicAbilities[SHADOW] && !( basicAbilities[SHADOW] || basicAbilities[REACHSHADOW])) return 0;
// If opponent does not have shadow and a creature has shadow it cannot be blocked
if (!opponent->basicAbilities[SHADOW] && basicAbilities[SHADOW]) return 0;
if (opponent->basicAbilities[SWAMPWALK] && controller()->game->inPlay->hasType("swamp")) return 0;
if (opponent->basicAbilities[FORESTWALK] && controller()->game->inPlay->hasType("forest")) return 0;
if (opponent->basicAbilities[ISLANDWALK] && controller()->game->inPlay->hasType("island")) return 0;
if (opponent->basicAbilities[MOUNTAINWALK] && controller()->game->inPlay->hasType("mountain")) return 0;
if (opponent->basicAbilities[PLAINSWALK] && controller()->game->inPlay->hasType("plains")) return 0;
return 1;
}
MTGCardInstance * MTGCardInstance::getNextPartner(){
MTGInPlay * inplay = controller()->game->inPlay;
MTGCardInstance * bandingPartner = inplay->getNextAttacker(banding);
while (bandingPartner){
if (basicAbilities[BANDING] || bandingPartner->basicAbilities[BANDING]) return bandingPartner;
bandingPartner = inplay->getNextAttacker(bandingPartner);
}
return NULL;
}
void MTGCardInstance::unband(){
if (!banding) return;
MTGCardInstance * _banding = banding;
banding = NULL;
MTGCardInstance * newbanding = NULL;
MTGInPlay * inplay = controller()->game->inPlay;
int nbpartners = inplay->nbPartners(this);
MTGCardInstance * card = inplay->getNextAttacker(NULL);
while(card){
if (card != this){
if (card->banding == _banding){
if (nbpartners == 1){
card->banding = NULL;
return;
}else{
if (!newbanding) newbanding = card;
card->banding = newbanding;
}
}
}
card = inplay->getNextAttacker(card);
}
return ;
}
int MTGCardInstance::toggleAttacker(){
//TODO more controls ?
if (canAttack()){
if (!attacker){
attacker = 1;
tapped = 1;
return 1;
}else{
MTGCardInstance * bandingPartner = getNextPartner();
if (bandingPartner){
if (banding) unband();
if (!bandingPartner->banding) bandingPartner->banding = bandingPartner;
banding = bandingPartner->banding;
return 1;
}else{
attacker = 0;
tapped = 0;
return 1;
}
}
}
return 0;
}
int MTGCardInstance::isAttacker(){
return attacker;
}
MTGCardInstance * MTGCardInstance::isDefenser(){
return defenser;
}
int MTGCardInstance::nbOpponents(){
int result= 0;
MTGCardInstance* opponent = getNextOpponent();
while (opponent){
result++;
opponent = getNextOpponent(opponent);
}
return result;
}
//Returns opponents to this card for this turn. This * should * take into account banding
MTGCardInstance * MTGCardInstance::getNextOpponent(MTGCardInstance * previous){
GameObserver * game = GameObserver::GetInstance();
int foundprevious = 0;
if (!previous) foundprevious = 1;
if (attacker && game->currentPlayer->game->inPlay->hasCard(this)){
MTGInPlay * inPlay = game->opponent()->game->inPlay;
for (int i = 0; i < inPlay->nb_cards; i ++){
MTGCardInstance * current = inPlay->cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious){
MTGCardInstance * defensersOpponent = current->isDefenser();
if (defensersOpponent && (defensersOpponent == this || (banding && defensersOpponent->banding == banding))){
return current;
}
}
}
}else if (defenser && game->opponent()->game->inPlay->hasCard(this)){
MTGInPlay * inPlay = game->currentPlayer->game->inPlay;
for (int i = 0; i < inPlay->nb_cards; i ++){
MTGCardInstance * current = inPlay->cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious){
if (defenser == current || (current->banding && defenser->banding == current->banding)){
return current;
}
}
}
}
return NULL;
}
int MTGCardInstance::toggleDefenser(MTGCardInstance * opponent){
if (canBlock()){
if (canBlock(opponent)){
defenser = opponent;
return 1;
}
}
return 0;
}
int MTGCardInstance::addProtection(CardDescriptor * cd){
protections[nbprotections] = cd;
nbprotections++;
return nbprotections;
}
int MTGCardInstance::removeProtection(CardDescriptor * cd, int erase){
for (int i = 0; i < nbprotections ; i++){
if (protections[i] == cd){
if (erase) delete (protections[i]);
protections[i] = protections[nbprotections -1];
protections[nbprotections -1] = NULL;
nbprotections--;
return 1;
}
}
return 0;
}
int MTGCardInstance::protectedAgainst(MTGCardInstance * card){
for (int i = 0; i < nbprotections ; i++){
if (protections[i]->match(card)) return 1;
}
return 0;
}
/*---------------------------------------------
Card Instance
Instance of a given MTGCard in the game
Although there is only one MTGCard of each type, there can be as much Instances of it as needed in the game
--------------------------------------------
*/
#include "../include/debug.h"
#include "../include/MTGCardInstance.h"
#include "../include/CardDescriptor.h"
#include "../include/Counters.h"
MTGCardInstance::MTGCardInstance(): MTGCard(), Damageable(0){
LOG("==Creating MTGCardInstance==");
initMTGCI();
LOG("==Creating MTGCardInstance Successful==");
}
MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to): MTGCard(card), Damageable(card->getToughness()){
LOG("==Creating MTGCardInstance==");
initMTGCI();
model = card;
lifeOrig = life;
belongs_to=_belongs_to;
initAttackersDefensers();
life=toughness;
LOG("==Creating MTGCardInstance Successful==");
}
MTGCardInstance::~MTGCardInstance(){
LOG("==Deleting MTGCardInstance==");
SAFE_DELETE(blockers);
SAFE_DELETE(counters);
LOG("==Deleting MTGCardInstance Succesfull==");
}
void MTGCardInstance::initMTGCI(){
model=NULL;
lifeOrig = 0;
doDamageTest = 0;
belongs_to=NULL;
tapped = 0;
blockers = NEW Blockers();
untapping = 0;
summoningSickness = 0;
target = NULL;
nbprotections = 0;
type_as_damageable = DAMAGEABLE_MTGCARDINSTANCE;
banding = NULL;
owner = NULL;
changedZoneRecently = 0;
counters = NEW Counters(this);
}
void MTGCardInstance::addType(int type){
types[nb_types] = type;
nb_types++;
}
Blockers * MTGCardInstance::getBlockers(){
return blockers;
}
int MTGCardInstance::isInPlay(){
GameObserver * game = GameObserver::GetInstance();
for (int i = 0 ; i < 2 ; i++){
MTGGameZone * zone = game->players[i]->game->inPlay;
if (zone->hasCard(this)) return 1;
}
return 0;
}
int MTGCardInstance::afterDamage(){
if (!doDamageTest) return 0;
#if defined (WIN32) || defined (LINUX)
char buf[4096], *p = buf;
sprintf(buf,"After Damage Test, life is %i for %s \n",life,model->getName());
OutputDebugString(buf);
#endif
doDamageTest = 0;
if (life <=0 && isInPlay()){
GameObserver * game = GameObserver::GetInstance();
game->mLayers->stackLayer()->addPutInGraveyard(this);
return 1;
}
return 0;
}
MTGGameZone * MTGCardInstance::getCurrentZone(){
GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2; i++){
MTGPlayerCards * g = game->players[i]->game;
MTGGameZone * zones[] = {g->inPlay,g->graveyard,g->hand, g->library};
for (int k = 0; k < 4; k++){
MTGGameZone * zone = zones[k];
if (zone->hasCard(this)) return zone;
}
}
return NULL;
}
JQuad * MTGCardInstance::getIcon(){
return getThumb();
}
int MTGCardInstance::has(int basicAbility){
return basicAbilities[basicAbility];
}
//Taps the card
void MTGCardInstance::tap(){
tapped = 1;
}
void MTGCardInstance::setUntapping(){
untapping = 1;
}
int MTGCardInstance::isUntapping(){
return untapping;
}
//Untaps the card
void MTGCardInstance::untap(){
if (untapping){
tapped = 0;
untapping = 0;
}
}
//Tells if the card is tapped or not
int MTGCardInstance::isTapped(){
return tapped;
}
void MTGCardInstance::resetAllDamage(){
//for (int i=0;i<nb_damages;i++){
// delete damages[i];
//}
nb_damages = 0;
}
void MTGCardInstance::regenerate(){
tapped = 1;
life = toughness;
initAttackersDefensers();
}
int MTGCardInstance::initAttackersDefensers(){
attacker = 0;
defenser = NULL;
banding = NULL;
return 1;
}
//Function to call to remove all damages, etc to a card (generally at the end of the turn)
int MTGCardInstance::cleanup(){
initAttackersDefensers();
life=toughness;
GameObserver * game = GameObserver::GetInstance();
if (!game || game->currentPlayer == controller()) summoningSickness = 0;
return 1;
}
/* Summoning Sickness
* 212.3f A creature<72>fs activated ability with the tap symbol or the untap symbol in its activation cost
* can<61>ft be played unless the creature has been under its controller<65>fs control since the start of his or
* her most recent turn. A creature can<61>ft attack unless it has been under its controller<65>fs control
* since the start of his or her most recent turn. This rule is informally called the <20>gsummoning
* sickness<73>h rule. Ignore this rule for creatures with haste (see rule 502.5).
*/
int MTGCardInstance::hasSummoningSickness(){
if (!summoningSickness) return 0;
if (basicAbilities[HASTE]) return 0;
if (!isACreature()) return 0;
return 1;
}
int MTGCardInstance::changeController(Player * newController){
Player * originalOwner = controller();
if (originalOwner == newController) return 0;
originalOwner->game->inPlay->removeCard(this);
newController->game->inPlay->addCard(this);
summoningSickness = 1;
return 1;
}
//Reset the card parameters
int MTGCardInstance::reset(){
cleanup();
tapped=0;
SAFE_DELETE(counters);
counters = NEW Counters(this);
return 1;
}
Player * MTGCardInstance::controller(){
GameObserver * game = GameObserver::GetInstance();
if (!game) return NULL;
for (int i = 0; i < 2; i++){
if (game->players[i]->game->inPlay->hasCard(this)) return game->players[i];
if (game->players[i]->game->stack->hasCard(this)) return game->players[i];
if (game->players[i]->game->graveyard->hasCard(this)) return game->players[i];
}
return NULL;
}
int MTGCardInstance::canAttack(){
if (!hasSummoningSickness() && !tapped && isACreature() && basicAbilities[DEFENSER] !=1)
return 1;
return 0;
}
int MTGCardInstance::addToToughness(int value){
toughness+=value;
life+=value;
doDamageTest = 1;
return 1;
}
int MTGCardInstance::setToughness(int value){
toughness=value;
life=value;
doDamageTest = 1;
return 1;
}
int MTGCardInstance::canBlock(){
if (!tapped && isACreature())return 1;
return 0;
}
int MTGCardInstance::canBlock(MTGCardInstance * opponent){
if (!canBlock()) return 0;
if (!opponent) return 1;
if (!opponent->isAttacker()) return 0;
// Comprehensive rule 502.7f : If a creature with protection attacks, it can't be blocked by creatures that have the stated quality.
if (opponent->protectedAgainst(this)) return 0;
if (opponent->basicAbilities[UNBLOCKABLE]) return 0;
if (opponent->basicAbilities[FEAR] && !(hasColor(MTG_COLOR_ARTIFACT) || hasColor(MTG_COLOR_BLACK))) return 0;
if (opponent->basicAbilities[FLYING] && !( basicAbilities[FLYING] || basicAbilities[REACH])) return 0;
// If opponent has shadow and a creature does not have either shadow or reachshadow it cannot be blocked
if (opponent->basicAbilities[SHADOW] && !( basicAbilities[SHADOW] || basicAbilities[REACHSHADOW])) return 0;
// If opponent does not have shadow and a creature has shadow it cannot be blocked
if (!opponent->basicAbilities[SHADOW] && basicAbilities[SHADOW]) return 0;
if (opponent->basicAbilities[SWAMPWALK] && controller()->game->inPlay->hasType("swamp")) return 0;
if (opponent->basicAbilities[FORESTWALK] && controller()->game->inPlay->hasType("forest")) return 0;
if (opponent->basicAbilities[ISLANDWALK] && controller()->game->inPlay->hasType("island")) return 0;
if (opponent->basicAbilities[MOUNTAINWALK] && controller()->game->inPlay->hasType("mountain")) return 0;
if (opponent->basicAbilities[PLAINSWALK] && controller()->game->inPlay->hasType("plains")) return 0;
return 1;
}
MTGCardInstance * MTGCardInstance::getNextPartner(){
MTGInPlay * inplay = controller()->game->inPlay;
MTGCardInstance * bandingPartner = inplay->getNextAttacker(banding);
while (bandingPartner){
if (basicAbilities[BANDING] || bandingPartner->basicAbilities[BANDING]) return bandingPartner;
bandingPartner = inplay->getNextAttacker(bandingPartner);
}
return NULL;
}
void MTGCardInstance::unband(){
if (!banding) return;
MTGCardInstance * _banding = banding;
banding = NULL;
MTGCardInstance * newbanding = NULL;
MTGInPlay * inplay = controller()->game->inPlay;
int nbpartners = inplay->nbPartners(this);
MTGCardInstance * card = inplay->getNextAttacker(NULL);
while(card){
if (card != this){
if (card->banding == _banding){
if (nbpartners == 1){
card->banding = NULL;
return;
}else{
if (!newbanding) newbanding = card;
card->banding = newbanding;
}
}
}
card = inplay->getNextAttacker(card);
}
return ;
}
int MTGCardInstance::toggleAttacker(){
//TODO more controls ?
if (canAttack()){
if (!attacker){
attacker = 1;
tapped = 1;
return 1;
}else{
MTGCardInstance * bandingPartner = getNextPartner();
if (bandingPartner){
if (banding) unband();
if (!bandingPartner->banding) bandingPartner->banding = bandingPartner;
banding = bandingPartner->banding;
return 1;
}else{
attacker = 0;
tapped = 0;
return 1;
}
}
}
return 0;
}
int MTGCardInstance::isAttacker(){
return attacker;
}
MTGCardInstance * MTGCardInstance::isDefenser(){
return defenser;
}
int MTGCardInstance::nbOpponents(){
int result= 0;
MTGCardInstance* opponent = getNextOpponent();
while (opponent){
result++;
opponent = getNextOpponent(opponent);
}
return result;
}
//Returns opponents to this card for this turn. This * should * take into account banding
MTGCardInstance * MTGCardInstance::getNextOpponent(MTGCardInstance * previous){
GameObserver * game = GameObserver::GetInstance();
int foundprevious = 0;
if (!previous) foundprevious = 1;
if (attacker && game->currentPlayer->game->inPlay->hasCard(this)){
MTGInPlay * inPlay = game->opponent()->game->inPlay;
for (int i = 0; i < inPlay->nb_cards; i ++){
MTGCardInstance * current = inPlay->cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious){
MTGCardInstance * defensersOpponent = current->isDefenser();
if (defensersOpponent && (defensersOpponent == this || (banding && defensersOpponent->banding == banding))){
return current;
}
}
}
}else if (defenser && game->opponent()->game->inPlay->hasCard(this)){
MTGInPlay * inPlay = game->currentPlayer->game->inPlay;
for (int i = 0; i < inPlay->nb_cards; i ++){
MTGCardInstance * current = inPlay->cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious){
if (defenser == current || (current->banding && defenser->banding == current->banding)){
return current;
}
}
}
}
return NULL;
}
int MTGCardInstance::toggleDefenser(MTGCardInstance * opponent){
if (canBlock()){
if (canBlock(opponent)){
defenser = opponent;
return 1;
}
}
return 0;
}
int MTGCardInstance::addProtection(CardDescriptor * cd){
protections[nbprotections] = cd;
nbprotections++;
return nbprotections;
}
int MTGCardInstance::removeProtection(CardDescriptor * cd, int erase){
for (int i = 0; i < nbprotections ; i++){
if (protections[i] == cd){
if (erase) delete (protections[i]);
protections[i] = protections[nbprotections -1];
protections[nbprotections -1] = NULL;
nbprotections--;
return 1;
}
}
return 0;
}
int MTGCardInstance::protectedAgainst(MTGCardInstance * card){
for (int i = 0; i < nbprotections ; i++){
if (protections[i]->match(card)) return 1;
}
return 0;
}

View File

@@ -1,385 +1,385 @@
#include "../include/debug.h"
#include "../include/MTGDeck.h"
#include "../include/utils.h"
#include <algorithm>
#include <string>
using std::string;
#include <JGE.h>
#if defined (WIN32) || defined (LINUX)
#include <time.h>
#endif
MtgSets * MtgSets::SetsList = NEW MtgSets();
MtgSets::MtgSets(){
nb_items = 0;
}
int MtgSets::Add(const char * name){
string value = name;
values[nb_items] = value;
nb_items++;
return nb_items - 1;
}
int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
string s = buffer;
unsigned int i = s.find_first_of("=");
if (i == string::npos) return 0;
string key = s.substr(0,i);
string value = s.substr(i+1);
if(key.compare( "auto")==0){
card->addMagicText(value);
}
else if(key.compare( "alias")==0){
card->alias=atoi(value.c_str());
}
else if(key.compare( "target")==0){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
card->spellTargetType=value;
}
else if(key.compare( "text")==0){
card->setText(value);
}else if (key.compare("abilities")==0){
//Specific Abilities
std::transform( value.begin(), value.end(), value.begin(),::tolower );
for (int j = 0; j < NB_BASIC_ABILITIES; j++){
unsigned int found = value.find(MTGBasicAbilities[j]);
if (found != string::npos){
card->basicAbilities[j] = 1;
}
}
}else if(key.compare("id")==0){
card->setMTGId(atoi(value.c_str()));
}else if(key.compare("name")==0){
card->setName(value);
}else if(key.compare("rarity")==0){
card->setRarity (value.c_str()[0]);
}else if(key.compare("mana")==0){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
card->setManaCost(value);
}else if(key.compare("type")==0){
switch(value.c_str()[0]){
case 'C':
card->setType( "Creature");
break;
case 'A':
card->setType( "Artifact");
card->setColor(MTG_COLOR_ARTIFACT);
if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C')
card->setSubtype("Creature");
break;
case 'E':
card->setType( "Enchantment");
break;
case 'S':
card->setType( "Sorcery");
break;
case 'B'://Basic Land
card->setColor(MTG_COLOR_LAND);
card->setType("Land");
break;
case 'L':
card->setColor(MTG_COLOR_LAND);
card->setType( "Land");
break;
case 'I':
card->setType( "Instant");
break;
default:
card->setType( "Error");
break;
}
}else if(key.compare("power")==0){
card->setPower (atoi(value.c_str()));
}else if(key.compare("subtype")==0){
card->setSubtype(value);
}else if(key.compare("toughness")==0){
card->setToughness(atoi(value.c_str()));
}else{
}
return i;
}
void MTGAllCards::initCounters(){
for (int i=0; i< MTG_NB_COLORS; i++){
colorsCount[i] = NULL;
}
}
void MTGAllCards::init(){
mCache = NULL;
total_cards = 0;
initCounters();
srand(time(0)); // initialize random
}
int MTGAllCards::load(const char * config_file, const char * set_name,int autoload){
conf_read_mode = 0;
int file_size = filesize(config_file);
conf_buffer = (char *) malloc(file_size);
read_cursor = 0;
// conf_fd = sceIoOpen(config_file, PSP_O_RDONLY, 0777);
read_file(config_file, conf_buffer, file_size );
int set_id = MtgSets::SetsList->Add(set_name);
if (autoload){
while(readConfLine(set_id)){};
}
return total_cards;
}
MTGAllCards::MTGAllCards(){
init();
}
MTGAllCards::~MTGAllCards(){
}
void MTGAllCards::destroyAllCards(){
for (int i= 0; i < total_cards; i++){
delete collection[i];
};
}
MTGAllCards::MTGAllCards(const char * config_file, const char * set_name){
MTGAllCards(config_file, set_name, NULL);
}
MTGAllCards::MTGAllCards(TexturesCache * cache){
init();
mCache = cache;
}
MTGAllCards::MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache){
init();
mCache = cache;
load(config_file,set_name, 0);
}
MTGCard * MTGAllCards::_(int i){
if (i < total_cards) return collection[i];
return NULL;
}
int MTGAllCards::randomCardId(){
int id = (rand() % total_cards);
return collection[id]->getMTGId();
}
int MTGAllCards::countBySet(int setId){
int result = 0;
for (int i=0; i< total_cards; i++){
if(collection[i]->setId == setId){
result++;
}
}
return result;
}
//TODO more efficient way ?
int MTGAllCards::countByType(const char * _type){
int result = 0;
for (int i=0; i< total_cards; i++){
if(collection[i]->hasType(_type)){
result++;
}
}
return result;
}
int MTGAllCards::countByColor(int color){
if (colorsCount[color] == 0){
for (int i=0; i< MTG_NB_COLORS; i++){
colorsCount[i] = 0;
}
for (int i=0; i< total_cards; i++){
int j = collection[i]->getColor();
colorsCount[j]++;
}
}
return colorsCount[color];
}
int MTGAllCards::totalCards(){
return (total_cards);
}
int MTGAllCards::readConfLine(int set_id){
char buffer[BUFSIZE];
read_cursor = readline(conf_buffer, buffer, read_cursor);
if (read_cursor){
switch(conf_read_mode) {
case 0:
conf_read_mode = 1;
collection[total_cards] = NEW MTGCard(mCache,set_id);
break;
case 1:
if (buffer[0] == '[' && buffer[1] == '/'){
conf_read_mode = 0;
total_cards++;
}else{
processConfLine(buffer, collection[total_cards]);
}
break;
default:
break;
}
}else{
free (conf_buffer);
}
return read_cursor;
}
MTGCard * MTGAllCards::getCardById(int id){
int i;
for (i=0; i<total_cards; i++){
int cardId = collection[i]->getMTGId();
if (cardId == id){
return collection[i];
}
}
return 0;
}
MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){
mCache = cache;
total_cards = 0;
allcards = _allcards;
filename = config_file;
std::ifstream file(config_file);
std::string s;
if(file){
while(std::getline(file,s)){
int cardnb = atoi(s.c_str());
if (cardnb) add(cardnb);
}
file.close();
}else{
//TODO Error management
}
}
int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _subtype){
int collectionTotal = allcards->totalCards();
if (!collectionTotal) return 0;
if (setId == -1 && rarity == -1 && !_subtype){
for (int i = 0; i < howmany; i++){
int id = (rand() % collectionTotal);
add(allcards->_(id));
}
return 1;
}
char subtype[4096];
if (_subtype)
sprintf(subtype, _subtype);
int subcollection[TOTAL_NUMBER_OF_CARDS];
int subtotal = 0;
for (int i = 0; i < collectionTotal; i++){
MTGCard * card = allcards->_(i);
if ((setId == -1 || card->setId == setId) &&
(rarity == -1 || card->getRarity()==rarity) &&
(!_subtype || card->hasSubtype(subtype))
){
subcollection[subtotal] = i;
subtotal++;
}
}
if (subtotal == 0) return 0;
for (int i = 0; i < howmany; i++){
int id = (rand() % subtotal);
add(allcards->_(subcollection[id]));
}
return 1;
}
int MTGDeck::add(int cardid){
MTGCard * card = allcards->getCardById(cardid);
add(card);
return total_cards;
}
int MTGDeck::add(MTGCard * card){
if (!card) return 0;
collection[total_cards] = card;
++total_cards;
initCounters();
return total_cards;
}
int MTGDeck::removeAll(){
total_cards = 0;
initCounters();
return 1;
}
int MTGDeck::remove(int cardid){
MTGCard * card = getCardById(cardid);
return remove(card);
}
int MTGDeck::remove(MTGCard * card){
for (int i = 0; i<total_cards; i++){
if (collection[i] == card){
collection[i] = collection[total_cards - 1];
total_cards--;
initCounters();
return 1;
}
}
return 0;
}
int MTGDeck::save(){
std::ofstream file(filename.c_str());
char writer[10];
if (file){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("saving");
#endif
for (int i = 0; i<total_cards; i++){
sprintf(writer,"%i\n", collection[i]->getMTGId());
file<<writer;
}
file.close();
}
return 1;
}
#include "../include/debug.h"
#include "../include/MTGDeck.h"
#include "../include/utils.h"
#include <algorithm>
#include <string>
using std::string;
#include <JGE.h>
#if defined (WIN32) || defined (LINUX)
#include <time.h>
#endif
MtgSets * MtgSets::SetsList = NEW MtgSets();
MtgSets::MtgSets(){
nb_items = 0;
}
int MtgSets::Add(const char * name){
string value = name;
values[nb_items] = value;
nb_items++;
return nb_items - 1;
}
int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
string s = buffer;
unsigned int i = s.find_first_of("=");
if (i == string::npos) return 0;
string key = s.substr(0,i);
string value = s.substr(i+1);
if(key.compare( "auto")==0){
card->addMagicText(value);
}
else if(key.compare( "alias")==0){
card->alias=atoi(value.c_str());
}
else if(key.compare( "target")==0){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
card->spellTargetType=value;
}
else if(key.compare( "text")==0){
card->setText(value);
}else if (key.compare("abilities")==0){
//Specific Abilities
std::transform( value.begin(), value.end(), value.begin(),::tolower );
for (int j = 0; j < NB_BASIC_ABILITIES; j++){
unsigned int found = value.find(MTGBasicAbilities[j]);
if (found != string::npos){
card->basicAbilities[j] = 1;
}
}
}else if(key.compare("id")==0){
card->setMTGId(atoi(value.c_str()));
}else if(key.compare("name")==0){
card->setName(value);
}else if(key.compare("rarity")==0){
card->setRarity (value.c_str()[0]);
}else if(key.compare("mana")==0){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
card->setManaCost(value);
}else if(key.compare("type")==0){
switch(value.c_str()[0]){
case 'C':
card->setType( "Creature");
break;
case 'A':
card->setType( "Artifact");
card->setColor(MTG_COLOR_ARTIFACT);
if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C')
card->setSubtype("Creature");
break;
case 'E':
card->setType( "Enchantment");
break;
case 'S':
card->setType( "Sorcery");
break;
case 'B'://Basic Land
card->setColor(MTG_COLOR_LAND);
card->setType("Land");
break;
case 'L':
card->setColor(MTG_COLOR_LAND);
card->setType( "Land");
break;
case 'I':
card->setType( "Instant");
break;
default:
card->setType( "Error");
break;
}
}else if(key.compare("power")==0){
card->setPower (atoi(value.c_str()));
}else if(key.compare("subtype")==0){
card->setSubtype(value);
}else if(key.compare("toughness")==0){
card->setToughness(atoi(value.c_str()));
}else{
}
return i;
}
void MTGAllCards::initCounters(){
for (int i=0; i< MTG_NB_COLORS; i++){
colorsCount[i] = NULL;
}
}
void MTGAllCards::init(){
mCache = NULL;
total_cards = 0;
initCounters();
srand(time(0)); // initialize random
}
int MTGAllCards::load(const char * config_file, const char * set_name,int autoload){
conf_read_mode = 0;
int file_size = filesize(config_file);
conf_buffer = (char *) malloc(file_size);
read_cursor = 0;
// conf_fd = sceIoOpen(config_file, PSP_O_RDONLY, 0777);
read_file(config_file, conf_buffer, file_size );
int set_id = MtgSets::SetsList->Add(set_name);
if (autoload){
while(readConfLine(set_id)){};
}
return total_cards;
}
MTGAllCards::MTGAllCards(){
init();
}
MTGAllCards::~MTGAllCards(){
}
void MTGAllCards::destroyAllCards(){
for (int i= 0; i < total_cards; i++){
delete collection[i];
};
}
MTGAllCards::MTGAllCards(const char * config_file, const char * set_name){
MTGAllCards(config_file, set_name, NULL);
}
MTGAllCards::MTGAllCards(TexturesCache * cache){
init();
mCache = cache;
}
MTGAllCards::MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache){
init();
mCache = cache;
load(config_file,set_name, 0);
}
MTGCard * MTGAllCards::_(int i){
if (i < total_cards) return collection[i];
return NULL;
}
int MTGAllCards::randomCardId(){
int id = (rand() % total_cards);
return collection[id]->getMTGId();
}
int MTGAllCards::countBySet(int setId){
int result = 0;
for (int i=0; i< total_cards; i++){
if(collection[i]->setId == setId){
result++;
}
}
return result;
}
//TODO more efficient way ?
int MTGAllCards::countByType(const char * _type){
int result = 0;
for (int i=0; i< total_cards; i++){
if(collection[i]->hasType(_type)){
result++;
}
}
return result;
}
int MTGAllCards::countByColor(int color){
if (colorsCount[color] == 0){
for (int i=0; i< MTG_NB_COLORS; i++){
colorsCount[i] = 0;
}
for (int i=0; i< total_cards; i++){
int j = collection[i]->getColor();
colorsCount[j]++;
}
}
return colorsCount[color];
}
int MTGAllCards::totalCards(){
return (total_cards);
}
int MTGAllCards::readConfLine(int set_id){
char buffer[BUFSIZE];
read_cursor = readline(conf_buffer, buffer, read_cursor);
if (read_cursor){
switch(conf_read_mode) {
case 0:
conf_read_mode = 1;
collection[total_cards] = NEW MTGCard(mCache,set_id);
break;
case 1:
if (buffer[0] == '[' && buffer[1] == '/'){
conf_read_mode = 0;
total_cards++;
}else{
processConfLine(buffer, collection[total_cards]);
}
break;
default:
break;
}
}else{
free (conf_buffer);
}
return read_cursor;
}
MTGCard * MTGAllCards::getCardById(int id){
int i;
for (i=0; i<total_cards; i++){
int cardId = collection[i]->getMTGId();
if (cardId == id){
return collection[i];
}
}
return 0;
}
MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){
mCache = cache;
total_cards = 0;
allcards = _allcards;
filename = config_file;
std::ifstream file(config_file);
std::string s;
if(file){
while(std::getline(file,s)){
int cardnb = atoi(s.c_str());
if (cardnb) add(cardnb);
}
file.close();
}else{
//TODO Error management
}
}
int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _subtype){
int collectionTotal = allcards->totalCards();
if (!collectionTotal) return 0;
if (setId == -1 && rarity == -1 && !_subtype){
for (int i = 0; i < howmany; i++){
int id = (rand() % collectionTotal);
add(allcards->_(id));
}
return 1;
}
char subtype[4096];
if (_subtype)
sprintf(subtype, _subtype);
int subcollection[TOTAL_NUMBER_OF_CARDS];
int subtotal = 0;
for (int i = 0; i < collectionTotal; i++){
MTGCard * card = allcards->_(i);
if ((setId == -1 || card->setId == setId) &&
(rarity == -1 || card->getRarity()==rarity) &&
(!_subtype || card->hasSubtype(subtype))
){
subcollection[subtotal] = i;
subtotal++;
}
}
if (subtotal == 0) return 0;
for (int i = 0; i < howmany; i++){
int id = (rand() % subtotal);
add(allcards->_(subcollection[id]));
}
return 1;
}
int MTGDeck::add(int cardid){
MTGCard * card = allcards->getCardById(cardid);
add(card);
return total_cards;
}
int MTGDeck::add(MTGCard * card){
if (!card) return 0;
collection[total_cards] = card;
++total_cards;
initCounters();
return total_cards;
}
int MTGDeck::removeAll(){
total_cards = 0;
initCounters();
return 1;
}
int MTGDeck::remove(int cardid){
MTGCard * card = getCardById(cardid);
return remove(card);
}
int MTGDeck::remove(MTGCard * card){
for (int i = 0; i<total_cards; i++){
if (collection[i] == card){
collection[i] = collection[total_cards - 1];
total_cards--;
initCounters();
return 1;
}
}
return 0;
}
int MTGDeck::save(){
std::ofstream file(filename.c_str());
char writer[10];
if (file){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("saving");
#endif
for (int i = 0; i<total_cards; i++){
sprintf(writer,"%i\n", collection[i]->getMTGId());
file<<writer;
}
file.close();
}
return 1;
}

View File

@@ -5,7 +5,7 @@
MTGGamePhase::MTGGamePhase(int id):ActionElement(id){
animation = 0;
currentState = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont= GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetBase(0); // using 2nd font
}
@@ -17,39 +17,39 @@ void MTGGamePhase::Render(){
void MTGGamePhase::Update(float dt){
int newState = GameObserver::GetInstance()->getCurrentGamePhase();
if (newState != currentState){
activeState = ACTIVE;
animation = 1;
currentState = newState;
int newState = GameObserver::GetInstance()->getCurrentGamePhase();
if (newState != currentState){
activeState = ACTIVE;
animation = 1;
currentState = newState;
switch (currentState){
switch (currentState){
default: break;
}
default: break;
}
}
}
if (animation > 0){
if (animation > 0){
fprintf(stderr, "animation = %f", animation);
animation -= dt *5 ;
}else{
activeState = INACTIVE;
activeState = INACTIVE;
animation = 0;
}
}
}
void MTGGamePhase::CheckUserInput(float dt){
GameObserver * game = GameObserver::GetInstance();
if (activeState == INACTIVE){
if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER) && game->currentActionPlayer == game->currentlyActing())
{
activeState = ACTIVE;
game->userRequestNextGamePhase();
}
}
GameObserver * game = GameObserver::GetInstance();
if (activeState == INACTIVE){
if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER) && game->currentActionPlayer == game->currentlyActing())
{
activeState = ACTIVE;
game->userRequestNextGamePhase();
}
}
}

View File

@@ -1,314 +1,314 @@
#include "../include/debug.h"
#include "../include/MTGGameZones.h"
#include "../include/Player.h"
#if defined (WIN32) || defined (LINUX)
#include <time.h>
#endif
//------------------------------
//Players Game
//------------------------------
MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize){
init();
int i;
collection = _collection;
for (i=0;i<idListSize;i++){
MTGCard * card = collection->getCardById(idList[i]);
if (card){
MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
library->addCard(newCard);
}
}
}
MTGPlayerCards::~MTGPlayerCards(){
if(library) delete library;
if(graveyard) delete graveyard;
if(hand) delete hand;
if(inPlay) delete inPlay;
if(stack) delete stack;
}
void MTGPlayerCards::setOwner(Player * player){
library->setOwner(player);
}
void MTGPlayerCards::initGame(int shuffle, int draw){
if (shuffle) library->shuffle();
if (draw){
for (int i=0;i<7;i++){
drawFromLibrary();
}
}
}
void MTGPlayerCards::drawFromLibrary(){
MTGCardInstance * drownCard = library->draw();
hand->addCard(drownCard);
}
void MTGPlayerCards::init(){
library = NEW MTGLibrary();
graveyard = NEW MTGGraveyard();
hand = NEW MTGHand();
inPlay = NEW MTGInPlay();
stack = NEW MTGStack();
}
void MTGPlayerCards::showHand(){
hand->debugPrint();
}
void MTGPlayerCards::putInPlay(MTGCardInstance * card){
hand->removeCard(card);
stack->removeCard(card); //Which one is it ???
inPlay->addCard(card);
card->summoningSickness = 1;
card->changedZoneRecently = 1.f;
}
void MTGPlayerCards::putInGraveyard(MTGCardInstance * card){
if (inPlay->hasCard(card)){
putInZone(card,inPlay, graveyard);
}else if (stack->hasCard(card)){
putInZone(card,stack, graveyard);
}else{
putInZone(card,hand, graveyard);
}
}
void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to){
if (from->removeCard(card)){
to->addCard(card);
card->changedZoneRecently = 1.f;
//if (to == graveyard){
card->reset();
//}
}
}
void MTGPlayerCards::discardRandom(MTGGameZone * from){
if (!from->nb_cards)
return;
int r = rand() % (from->nb_cards);
putInZone(from->cards[r],from, graveyard);
}
int MTGPlayerCards::isInPlay(MTGCardInstance * card){
if (inPlay->hasCard(card)){
return 1;
}
return 0;
}
//--------------------------------------
// Zones specific code
//--------------------------------------
MTGGameZone::MTGGameZone(){
nb_cards= 0;
lastCardDrawn = NULL;
}
MTGGameZone::~MTGGameZone(){
for (int i=0; i<nb_cards; i++) {
delete cards[i];
}
}
void MTGGameZone::setOwner(Player * player){
for (int i=0; i<nb_cards; i++) {
cards[i]->owner = player;
}
owner = player;
}
MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
int i;
cardsMap.erase(card);
for (i=0; i<(nb_cards); i++) {
if (cards[i] == card){
cards[i] = cards[nb_cards -1];
nb_cards--;
return card;
}
}
return NULL;
}
MTGCardInstance * MTGGameZone::hasCard(MTGCardInstance * card){
if (cardsMap.find(card) != cardsMap.end()) return card;
return NULL;
}
int MTGGameZone::countByType(const char * value){
int result = 0 ;
for (int i=0; i<(nb_cards); i++) {
if (cards[i]->hasType(value)){
result++;
}
}
return result;
}
int MTGGameZone::hasType(const char * value){
for (int i=0; i<(nb_cards); i++) {
if (cards[i]->hasType(value)){
return 1;
}
}
return 0;
}
void MTGGameZone::cleanupPhase(){
for (int i=0; i<(nb_cards); i++)
(cards[i])->cleanup();
}
void MTGGameZone::shuffle(){
int i;
for (i=0; i<(nb_cards); i++) {
int r = i + (rand() % (nb_cards-i)); // Random remaining position.
MTGCardInstance * temp = cards[i]; cards[i] = cards[r]; cards[r] = temp;
}
srand(time(0)); // initialize seed "randomly" TODO :improve
}
void MTGGameZone::addCard(MTGCardInstance * card){
if (!card) return;
cards[nb_cards] = card;
nb_cards++;
cardsMap[card] = 1;
}
MTGCardInstance * MTGGameZone::draw(){
if (!nb_cards) return NULL;
nb_cards--;
lastCardDrawn = cards[nb_cards];
cardsMap.erase(cards[nb_cards]);
return cards[nb_cards];
}
MTGCardInstance * MTGLibrary::draw(){
if (!nb_cards) {
GameObserver::GetInstance()->gameOver = this->owner;
}
return MTGGameZone::draw();
}
void MTGGameZone::debugPrint(){
int i;
for (i=0;i<nb_cards;i++){
MTGCard * card = cards[i]->model;
fprintf(stderr, "%s", card->getName());
}
}
//------------------------------
int MTGInPlay::nbDefensers( MTGCardInstance * attacker){
int result = 0;
MTGCardInstance * defenser = getNextDefenser(NULL, attacker);
while (defenser){
result++;
defenser = getNextDefenser(defenser, attacker);
}
return result;
}
//Return the number of creatures this card is banded with
//Number of creatures in the band is n+1 !!!
int MTGInPlay::nbPartners(MTGCardInstance * attacker){
int result = 0;
if (!attacker->banding) return 0;
for (int i = 0; i < nb_cards; i ++){
if (cards[i]->banding == attacker->banding) result++;
}
return result;
}
MTGCardInstance * MTGInPlay::getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker){
int foundprevious = 0;
if (previous == NULL){
foundprevious = 1;
}
for (int i = 0; i < nb_cards; i ++){
MTGCardInstance * current = cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious && current->isDefenser() == attacker){
return current;
}
}
return NULL;
}
MTGCardInstance * MTGInPlay::getNextAttacker(MTGCardInstance * previous){
int foundprevious = 0;
if (previous == NULL){
foundprevious = 1;
}
for (int i = 0; i < nb_cards; i ++){
MTGCardInstance * current = cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious && current->isAttacker()){
return current;
}
}
return NULL;
}
void MTGInPlay::untapAll(){
int i;
for (i = 0; i < nb_cards; i ++){
cards[i]->setUntapping();
if (cards[i]->getBlockers()->isEmpty()){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Can untap %s\n", cards[i]->getName());
OutputDebugString(buf);
#endif
cards[i]->untap();
}
}
}
//--------------------------
void MTGLibrary::shuffleTopToBottom(int nbcards){
if (nbcards>nb_cards) nbcards = nb_cards;
MTGCardInstance * _cards[MTG_MAX_PLAYER_CARDS];
for (int i= nb_cards-nbcards; i<(nb_cards); i++) {
int r = i + (rand() % (nbcards-i)); // Random remaining position.
MTGCardInstance * temp = cards[i]; cards[i] = cards[r]; cards[r] = temp;
}
for (int i= 0; i < nbcards; i++){
_cards[i] = cards[nb_cards - 1 - i];
}
for (int i = nbcards; i < nb_cards; i++){
_cards[i] = cards[i - nb_cards];
}
for (int i=0 ; i < nb_cards; i++){
cards[i] = _cards[i];
}
}
#include "../include/debug.h"
#include "../include/MTGGameZones.h"
#include "../include/Player.h"
#if defined (WIN32) || defined (LINUX)
#include <time.h>
#endif
//------------------------------
//Players Game
//------------------------------
MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize){
init();
int i;
collection = _collection;
for (i=0;i<idListSize;i++){
MTGCard * card = collection->getCardById(idList[i]);
if (card){
MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
library->addCard(newCard);
}
}
}
MTGPlayerCards::~MTGPlayerCards(){
if(library) delete library;
if(graveyard) delete graveyard;
if(hand) delete hand;
if(inPlay) delete inPlay;
if(stack) delete stack;
}
void MTGPlayerCards::setOwner(Player * player){
library->setOwner(player);
}
void MTGPlayerCards::initGame(int shuffle, int draw){
if (shuffle) library->shuffle();
if (draw){
for (int i=0;i<7;i++){
drawFromLibrary();
}
}
}
void MTGPlayerCards::drawFromLibrary(){
MTGCardInstance * drownCard = library->draw();
hand->addCard(drownCard);
}
void MTGPlayerCards::init(){
library = NEW MTGLibrary();
graveyard = NEW MTGGraveyard();
hand = NEW MTGHand();
inPlay = NEW MTGInPlay();
stack = NEW MTGStack();
}
void MTGPlayerCards::showHand(){
hand->debugPrint();
}
void MTGPlayerCards::putInPlay(MTGCardInstance * card){
hand->removeCard(card);
stack->removeCard(card); //Which one is it ???
inPlay->addCard(card);
card->summoningSickness = 1;
card->changedZoneRecently = 1.f;
}
void MTGPlayerCards::putInGraveyard(MTGCardInstance * card){
if (inPlay->hasCard(card)){
putInZone(card,inPlay, graveyard);
}else if (stack->hasCard(card)){
putInZone(card,stack, graveyard);
}else{
putInZone(card,hand, graveyard);
}
}
void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to){
if (from->removeCard(card)){
to->addCard(card);
card->changedZoneRecently = 1.f;
//if (to == graveyard){
card->reset();
//}
}
}
void MTGPlayerCards::discardRandom(MTGGameZone * from){
if (!from->nb_cards)
return;
int r = rand() % (from->nb_cards);
putInZone(from->cards[r],from, graveyard);
}
int MTGPlayerCards::isInPlay(MTGCardInstance * card){
if (inPlay->hasCard(card)){
return 1;
}
return 0;
}
//--------------------------------------
// Zones specific code
//--------------------------------------
MTGGameZone::MTGGameZone(){
nb_cards= 0;
lastCardDrawn = NULL;
}
MTGGameZone::~MTGGameZone(){
for (int i=0; i<nb_cards; i++) {
delete cards[i];
}
}
void MTGGameZone::setOwner(Player * player){
for (int i=0; i<nb_cards; i++) {
cards[i]->owner = player;
}
owner = player;
}
MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
int i;
cardsMap.erase(card);
for (i=0; i<(nb_cards); i++) {
if (cards[i] == card){
cards[i] = cards[nb_cards -1];
nb_cards--;
return card;
}
}
return NULL;
}
MTGCardInstance * MTGGameZone::hasCard(MTGCardInstance * card){
if (cardsMap.find(card) != cardsMap.end()) return card;
return NULL;
}
int MTGGameZone::countByType(const char * value){
int result = 0 ;
for (int i=0; i<(nb_cards); i++) {
if (cards[i]->hasType(value)){
result++;
}
}
return result;
}
int MTGGameZone::hasType(const char * value){
for (int i=0; i<(nb_cards); i++) {
if (cards[i]->hasType(value)){
return 1;
}
}
return 0;
}
void MTGGameZone::cleanupPhase(){
for (int i=0; i<(nb_cards); i++)
(cards[i])->cleanup();
}
void MTGGameZone::shuffle(){
int i;
for (i=0; i<(nb_cards); i++) {
int r = i + (rand() % (nb_cards-i)); // Random remaining position.
MTGCardInstance * temp = cards[i]; cards[i] = cards[r]; cards[r] = temp;
}
srand(time(0)); // initialize seed "randomly" TODO :improve
}
void MTGGameZone::addCard(MTGCardInstance * card){
if (!card) return;
cards[nb_cards] = card;
nb_cards++;
cardsMap[card] = 1;
}
MTGCardInstance * MTGGameZone::draw(){
if (!nb_cards) return NULL;
nb_cards--;
lastCardDrawn = cards[nb_cards];
cardsMap.erase(cards[nb_cards]);
return cards[nb_cards];
}
MTGCardInstance * MTGLibrary::draw(){
if (!nb_cards) {
GameObserver::GetInstance()->gameOver = this->owner;
}
return MTGGameZone::draw();
}
void MTGGameZone::debugPrint(){
int i;
for (i=0;i<nb_cards;i++){
MTGCard * card = cards[i]->model;
fprintf(stderr, "%s", card->getName());
}
}
//------------------------------
int MTGInPlay::nbDefensers( MTGCardInstance * attacker){
int result = 0;
MTGCardInstance * defenser = getNextDefenser(NULL, attacker);
while (defenser){
result++;
defenser = getNextDefenser(defenser, attacker);
}
return result;
}
//Return the number of creatures this card is banded with
//Number of creatures in the band is n+1 !!!
int MTGInPlay::nbPartners(MTGCardInstance * attacker){
int result = 0;
if (!attacker->banding) return 0;
for (int i = 0; i < nb_cards; i ++){
if (cards[i]->banding == attacker->banding) result++;
}
return result;
}
MTGCardInstance * MTGInPlay::getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker){
int foundprevious = 0;
if (previous == NULL){
foundprevious = 1;
}
for (int i = 0; i < nb_cards; i ++){
MTGCardInstance * current = cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious && current->isDefenser() == attacker){
return current;
}
}
return NULL;
}
MTGCardInstance * MTGInPlay::getNextAttacker(MTGCardInstance * previous){
int foundprevious = 0;
if (previous == NULL){
foundprevious = 1;
}
for (int i = 0; i < nb_cards; i ++){
MTGCardInstance * current = cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious && current->isAttacker()){
return current;
}
}
return NULL;
}
void MTGInPlay::untapAll(){
int i;
for (i = 0; i < nb_cards; i ++){
cards[i]->setUntapping();
if (cards[i]->getBlockers()->isEmpty()){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Can untap %s\n", cards[i]->getName());
OutputDebugString(buf);
#endif
cards[i]->untap();
}
}
}
//--------------------------
void MTGLibrary::shuffleTopToBottom(int nbcards){
if (nbcards>nb_cards) nbcards = nb_cards;
MTGCardInstance * _cards[MTG_MAX_PLAYER_CARDS];
for (int i= nb_cards-nbcards; i<(nb_cards); i++) {
int r = i + (rand() % (nbcards-i)); // Random remaining position.
MTGCardInstance * temp = cards[i]; cards[i] = cards[r]; cards[r] = temp;
}
for (int i= 0; i < nbcards; i++){
_cards[i] = cards[nb_cards - 1 - i];
}
for (int i = nbcards; i < nb_cards; i++){
_cards[i] = cards[i - nb_cards];
}
for (int i=0 ; i < nb_cards; i++){
cards[i] = _cards[i];
}
}

View File

@@ -7,26 +7,26 @@ MTGGuiHand::MTGGuiHand(int id, GameObserver * _game):GuiCardsController(id, _gam
mAnimState = 0;
currentPlayer = NULL;
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
for (int i = 0; i < 2; i++){
currentId[i] = 0;
}
for (int i = 0; i < 2; i++){
currentId[i] = 0;
}
}
void MTGGuiHand::updateCards(){
Player * player = GameObserver::GetInstance()->currentlyActing();
if (player->isAI()) player = GameObserver::GetInstance()->players[0];
Player * player = GameObserver::GetInstance()->currentlyActing();
if (player->isAI()) player = GameObserver::GetInstance()->players[0];
int nb_cards = player->game->hand->nb_cards;
if (mCount != nb_cards || player != currentPlayer ){ //if the number of cards has changed, then an update occured (is this test engouh ?)
resetObjects();
if (currentId[player->getId()] >= nb_cards) currentId[player->getId()] = nb_cards - 1;
for (int i = 0;i<nb_cards; i++){
CardGui * object = NEW CardGui(i, player->game->hand->cards[i],(float)40, (float)450 - (nb_cards-i) *35, SCREEN_HEIGHT_F - mAnimState*60, i == currentId[player->getId()]);
Add(object);
if ( i == currentId[player->getId()]) mCurr = i;
}
currentPlayer = player;
resetObjects();
if (currentId[player->getId()] >= nb_cards) currentId[player->getId()] = nb_cards - 1;
for (int i = 0;i<nb_cards; i++){
CardGui * object = NEW CardGui(i, player->game->hand->cards[i],(float)40, (float)450 - (nb_cards-i) *35, SCREEN_HEIGHT_F - mAnimState*60, i == currentId[player->getId()]);
Add(object);
if ( i == currentId[player->getId()]) mCurr = i;
}
currentPlayer = player;
}
@@ -35,14 +35,14 @@ void MTGGuiHand::updateCards(){
void MTGGuiHand::Update(float dt){
updateCards();
for (int i=0;i<mCount;i++){
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
((CardGui *)mObjects[i])->y= SCREEN_HEIGHT - mAnimState*60;
}
}
}
GuiCardsController::Update(dt);
currentId[game->currentlyActing()->getId()] = mCurr;
currentId[game->currentlyActing()->getId()] = mCurr;
}
@@ -72,7 +72,7 @@ void MTGGuiHand::CheckUserInput(float dt){
mShowHand = HAND_HIDE;
}
}
if (mShowHand == HAND_HIDE || currentPlayer->isAI()){
modal = 0;
}else{
@@ -85,17 +85,17 @@ void MTGGuiHand::CheckUserInput(float dt){
void MTGGuiHand::Render(){
if (mShowHand != HAND_HIDE){
// if (currentPlayer && !currentPlayer->isAI()){
RenderMessageBackground(440-mCount * 35 , SCREEN_HEIGHT - mAnimState*60 - 10, mCount * 35 + 20, 70);
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
}
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (showBigCards) ((CardGui *)mObjects[mCurr])->RenderBig(10);
}
}
if (mShowHand != HAND_HIDE){
// if (currentPlayer && !currentPlayer->isAI()){
RenderMessageBackground(440-mCount * 35 , SCREEN_HEIGHT - mAnimState*60 - 10, mCount * 35 + 20, 70);
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
}
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (showBigCards) ((CardGui *)mObjects[mCurr])->RenderBig(10);
}
}
}

View File

@@ -1,405 +1,405 @@
/* This class handles the display on the main game screen :
cards in play, graveyard, library, games phases, Players avatars
*/
#include "../include/debug.h"
#include "../include/MTGGuiPlay.h"
#include "../include/MTGCardInstance.h"
#include "../include/CardGui.h"
#include "../include/CardDisplay.h"
#define ZX_MAIN 100
#define ZY_MAIN 22
#define ZH_CREATURES 50
#define Z_CARDWIDTH 30
#define Z_CARDHEIGHT 40
#define Z_MAIN_NBCARDS 7
#define Z_SPELLS_NBCARDS 3
#define ZX_SPELL 450
#define ZY_SPELL 22
MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPlayer = NULL;
offset = 0;
mPhaseBarTexture = JRenderer::GetInstance()->LoadTexture("graphics/phasebar.png", TEX_TYPE_USE_VRAM);
for (int i=0; i < 12; i++){
phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28);
phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28);
}
mGlitter = NEW JQuad(mPhaseBarTexture, 392, 0, 5, 5);
mGlitter->SetHotSpot(2.5,2.5);
mGlitterAlpha = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetScale(0.75);
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
//load all the icon images
mIcons[MTG_COLOR_ARTIFACT] = NEW JQuad(mIconsTexture, 10 + 6*32, 32, 32, 32);
mIcons[MTG_COLOR_LAND] = NEW JQuad(mIconsTexture, 10 + 5*32, 32, 32, 32);
mIcons[MTG_COLOR_WHITE] = NEW JQuad(mIconsTexture, 10 + 4*32, 32, 32, 32);
mIcons[MTG_COLOR_RED] = NEW JQuad(mIconsTexture, 10 + 3*32, 32, 32, 32);
mIcons[MTG_COLOR_BLACK] = NEW JQuad(mIconsTexture, 10 + 2*32, 32, 32, 32);
mIcons[MTG_COLOR_BLUE] = NEW JQuad(mIconsTexture, 10 + 1*32, 32, 32, 32);
mIcons[MTG_COLOR_GREEN] = NEW JQuad(mIconsTexture, 10 + 0*32, 32, 32, 32);
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
mBgTex = JRenderer::GetInstance()->LoadTexture("graphics/background.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(mBgTex, 0, 0, 480, 272);
mBgTex2 = JRenderer::GetInstance()->LoadTexture("graphics/back.jpg", TEX_TYPE_USE_VRAM);
mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255);
for (int i= 0; i < 4; i++){
alphaBg[i] = 255;
}
alphaBg[0] = 0;
AddPlayersGuiInfo();
}
CardGui * MTGGuiPlay::getByCard(MTGCardInstance * card){
for (int i = offset; i < mCount; i++){
CardGui * cardg = (CardGui *)mObjects[i];
if(cardg && cardg->card == card){
return cardg;
}
}
return NULL;
}
void MTGGuiPlay::initCardsDisplay(){
for (int i = 0; i < SCREEN_WIDTH/5; i++){
for(int j=0; j < SCREEN_HEIGHT/5; j++){
cardsGrid[i][j] = NULL;
}
}
cards_x_limit = 12;
nb_creatures = 0;
nb_lands = 0;
nb_spells = 0;
}
void MTGGuiPlay::adjustCardPosition(CardGui * cardg){
int x5 = cardg->x / 5;
int y5 = cardg->y / 5;
while (cardsGrid[x5][y5] && x5 <SCREEN_WIDTH/5 && y5 < SCREEN_HEIGHT/5 ){
x5++;
y5++;
}
cardg->x = x5 * 5;
cardg->y = y5 * 5;
cardsGrid[x5][y5] = cardg->card;
}
void MTGGuiPlay::setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode){
MTGCardInstance * card = cardg->card;
if (card->target)
return;
if (spellMode && (card->isACreature() || card->hasType("land"))) return;
if (!spellMode && !card->isACreature() && !card->hasType("land")) return;
if (card->isACreature()){
int x_offset = nb_creatures % cards_x_limit;
int y_offset = nb_creatures / cards_x_limit;
cardg->x= ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + ZH_CREATURES + (Z_CARDHEIGHT * y_offset) + 100 * (1-player);
nb_creatures++;
if (playerTurn){
if (card->isAttacker()){
cardg->y=122 + 30 * (1-player);
}
}else{
if (card->isDefenser()){
CardGui * targetg = getByCard(card->isDefenser());
if (targetg) cardg->x = targetg->x;
cardg->y=122 + 30 * (1-player);
}
}
}else if(card->hasType("land")){
int x_offset = nb_lands % cards_x_limit;
int y_offset = nb_lands/ cards_x_limit;
cardg->x=ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + (Z_CARDHEIGHT * y_offset) + 200 * (1-player);
nb_lands++;
}else{
int y_offset = nb_spells % Z_SPELLS_NBCARDS;
int x_offset = nb_spells/ Z_SPELLS_NBCARDS;
cardg->x=ZX_SPELL - (Z_CARDWIDTH * x_offset);
cardg->y=ZY_SPELL + (Z_CARDHEIGHT * y_offset) + 125 * (1-player);
nb_spells++;
cards_x_limit = 12 - (nb_spells + 2)/ Z_SPELLS_NBCARDS;
}
adjustCardPosition(cardg);
}
void MTGGuiPlay::setTargettingCardPosition(CardGui * cardg, int player, int playerTurn){
MTGCardInstance * card = cardg->card;
MTGCardInstance * target = card->target;
if (!target)
return;
CardGui * targetg = getByCard(target);
if (targetg){
cardg->y=targetg->y + 5;
cardg->x=targetg->x + 5;
}
adjustCardPosition(cardg);
return;
}
void MTGGuiPlay::updateCards(){
GameObserver * game = GameObserver::GetInstance();
Player * player = game->players[0];
int player0Mode =(game->currentPlayer == player);
int nb_cards = player->game->inPlay->nb_cards;
MTGCardInstance * attackers[MAX_ATTACKERS];
for (int i = 0; i <MAX_ATTACKERS; i++){
attackers[i] = NULL;
}
offset = 6;
Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards;
if (mCount - offset != (nb_cards+opponent_cards) || game->currentPlayer != currentPlayer ){ //if the number of cards has changed, then an update occured (is this test engouh ?)
resetObjects();
AddPlayersGuiInfo();
offset = mCount;
bool hasFocus = player0Mode;
for (int i = 0;i<nb_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, player->game->inPlay->cards[i],40, i*35 + 10, 200, hasFocus);
Add(object);
hasFocus = false;
}
hasFocus = !player0Mode;
for (int i = 0;i<opponent_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, opponent->game->inPlay->cards[i],40, i*35 + 10, 10, hasFocus);
Add(object);
hasFocus = false;
}
currentPlayer = game->currentPlayer;
}
//This is just so that we display the cards of the current player first, so that blockers are correctly positionned
for (int j= 0; j < 2; j++){
initCardsDisplay();
if (j != player0Mode){
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 1);
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 0);
}
}else{
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,1);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,0);
}
}
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset ];
setTargettingCardPosition(cardGui, 0, player0Mode);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setTargettingCardPosition(cardGui, 1, !player0Mode);
}
}
void MTGGuiPlay::AddPlayersGuiInfo(){
//init with the players objects
if (mCount == 0){
Add(NEW GuiAvatar(-1,50,2,155,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiAvatar(-2,50,2,30,false,GameObserver::GetInstance()->players[1]));
Add(NEW GuiGraveyard(-3,30,40,150,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiLibrary(-4,30,40,180,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiGraveyard(-5,30,40,30,false, GameObserver::GetInstance()->players[1]));
Add(NEW GuiLibrary(-6,30,40,60,false, GameObserver::GetInstance()->players[1]));
}
}
void MTGGuiPlay::Update(float dt){
updateCards();
PlayGuiObjectController::Update(dt);
GameObserver * game = GameObserver::GetInstance();
}
void MTGGuiPlay::CheckUserInput(float dt){
for (int i = 2; i<6;i++){
GuiGameZone * zone = (GuiGameZone *)mObjects[i];
if (zone->showCards){
zone->cd->CheckUserInput(dt);
return;
}
}
PlayGuiObjectController::CheckUserInput(dt);
}
void MTGGuiPlay::RenderPlayerInfo(int playerid){
GameObserver * game = GameObserver::GetInstance();
JRenderer * r = JRenderer::GetInstance();
Player * player = GameObserver::GetInstance()->players[playerid];
int life = player->life;
//Avatar
GuiAvatar * avatar = (GuiAvatar *)mObjects[3*playerid];
avatar->Render();
//Mana
ManaCost * cost = player->getManaPool();
int nbicons = 0;
for (int j=0; j<6;j++){
int value = cost->getCost(j);
for (int i=0; i<value; i++){
float x = 10 + (nbicons %4) * 15;
float y = 90 + 125 * (1-playerid) + (15 * (nbicons / 4));
r->RenderQuad(mIcons[j],x,y,0,0.5, 0.5);
nbicons++;
}
}
}
void MTGGuiPlay::RenderPhaseBar(){
GameObserver * game = GameObserver::GetInstance();
JRenderer * renderer = JRenderer::GetInstance();
int currentPhase = game->getCurrentGamePhase();
for (int i=0; i < 12; i++){
int index = 2*i + 1 ;
if (i==currentPhase-1){
index-=1;
}
renderer->RenderQuad(phaseIcons[index], 200 + 14*i,0,0,0.5,0.5);
}
mFont->SetScale(0.70);
if (game->currentlyActing()->isAI()){
mFont->SetColor(ARGB(255,128,128,128));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
mFont->DrawString(MTGPhaseNames[currentPhase], 375, 0);
}
void MTGGuiPlay::Render(){
JRenderer * renderer = JRenderer::GetInstance();
//alphaBg[1] = 255;
//alphaBg[2]= 255;
//alphaBg[3] = 255;
//mBg2->SetColor(ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg2,0,17);
if (game->currentGamePhase >=MTG_PHASE_COMBATBEGIN && game->currentGamePhase < MTG_PHASE_COMBATEND){
if (alphaBg[0] < 50){
alphaBg[3]-=12;
alphaBg[2]-=12;
alphaBg[0]+=3;
}
alphaBg[1] = 255;
}else{
if (alphaBg[0]){
alphaBg[0]-=3;
alphaBg[3]+=12;
alphaBg[2]+=12;
}
alphaBg[1] = 255;
}
renderer->FillRect(0,0,480,272,ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg,0,0);
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
}
RenderPhaseBar();
RenderPlayerInfo(0);
RenderPlayerInfo(1);
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (hasFocus && mCurr >= offset && showBigCards)
((CardGui *)mObjects[mCurr])->RenderBig();
}
if (mGlitterAlpha < 0){
mGlitterAlpha = 510;
int position = rand() % 2;
if (position){
mGlitterX = 65 + rand() % (420);
mGlitterY = 17 + rand() % (5);
}else{
mGlitterX = 65 + rand() % (5);
mGlitterY = 15 + rand() % (250);
}
}
mGlitter->SetColor(ARGB((255-abs(255-mGlitterAlpha)),240,240,255));
renderer->RenderQuad(mGlitter,mGlitterX,mGlitterY, (float)(mGlitterAlpha)/(float)255, 1.2*float(mGlitterAlpha)/float(255),1.2*float(mGlitterAlpha)/float(255));
mGlitterAlpha-=10;
}
MTGGuiPlay::~MTGGuiPlay(){
LOG("==Destroying MTGGuiPlay==");
delete mBg;
delete mBgTex;
for (int i=0; i < 7; i++){
delete mIcons[i];
}
delete mIconsTexture;
delete mGlitter;
for (int i=0; i < 12; i++){
delete phaseIcons[2*i] ;
delete phaseIcons[2*i + 1];
}
delete mPhaseBarTexture;
SAFE_DELETE(mBg2);
SAFE_DELETE(mBgTex2);
LOG("==Destroying MTGGuiPlay Successful==");
}
/* This class handles the display on the main game screen :
cards in play, graveyard, library, games phases, Players avatars
*/
#include "../include/debug.h"
#include "../include/MTGGuiPlay.h"
#include "../include/MTGCardInstance.h"
#include "../include/CardGui.h"
#include "../include/CardDisplay.h"
#define ZX_MAIN 100
#define ZY_MAIN 22
#define ZH_CREATURES 50
#define Z_CARDWIDTH 30
#define Z_CARDHEIGHT 40
#define Z_MAIN_NBCARDS 7
#define Z_SPELLS_NBCARDS 3
#define ZX_SPELL 450
#define ZY_SPELL 22
MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPlayer = NULL;
offset = 0;
mPhaseBarTexture = JRenderer::GetInstance()->LoadTexture("graphics/phasebar.png", TEX_TYPE_USE_VRAM);
for (int i=0; i < 12; i++){
phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28);
phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28);
}
mGlitter = NEW JQuad(mPhaseBarTexture, 392, 0, 5, 5);
mGlitter->SetHotSpot(2.5,2.5);
mGlitterAlpha = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetScale(0.75);
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
//load all the icon images
mIcons[MTG_COLOR_ARTIFACT] = NEW JQuad(mIconsTexture, 10 + 6*32, 32, 32, 32);
mIcons[MTG_COLOR_LAND] = NEW JQuad(mIconsTexture, 10 + 5*32, 32, 32, 32);
mIcons[MTG_COLOR_WHITE] = NEW JQuad(mIconsTexture, 10 + 4*32, 32, 32, 32);
mIcons[MTG_COLOR_RED] = NEW JQuad(mIconsTexture, 10 + 3*32, 32, 32, 32);
mIcons[MTG_COLOR_BLACK] = NEW JQuad(mIconsTexture, 10 + 2*32, 32, 32, 32);
mIcons[MTG_COLOR_BLUE] = NEW JQuad(mIconsTexture, 10 + 1*32, 32, 32, 32);
mIcons[MTG_COLOR_GREEN] = NEW JQuad(mIconsTexture, 10 + 0*32, 32, 32, 32);
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
mBgTex = JRenderer::GetInstance()->LoadTexture("graphics/background.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(mBgTex, 0, 0, 480, 272);
mBgTex2 = JRenderer::GetInstance()->LoadTexture("graphics/back.jpg", TEX_TYPE_USE_VRAM);
mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255);
for (int i= 0; i < 4; i++){
alphaBg[i] = 255;
}
alphaBg[0] = 0;
AddPlayersGuiInfo();
}
CardGui * MTGGuiPlay::getByCard(MTGCardInstance * card){
for (int i = offset; i < mCount; i++){
CardGui * cardg = (CardGui *)mObjects[i];
if(cardg && cardg->card == card){
return cardg;
}
}
return NULL;
}
void MTGGuiPlay::initCardsDisplay(){
for (int i = 0; i < SCREEN_WIDTH/5; i++){
for(int j=0; j < SCREEN_HEIGHT/5; j++){
cardsGrid[i][j] = NULL;
}
}
cards_x_limit = 12;
nb_creatures = 0;
nb_lands = 0;
nb_spells = 0;
}
void MTGGuiPlay::adjustCardPosition(CardGui * cardg){
int x5 = cardg->x / 5;
int y5 = cardg->y / 5;
while (cardsGrid[x5][y5] && x5 <SCREEN_WIDTH/5 && y5 < SCREEN_HEIGHT/5 ){
x5++;
y5++;
}
cardg->x = x5 * 5;
cardg->y = y5 * 5;
cardsGrid[x5][y5] = cardg->card;
}
void MTGGuiPlay::setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode){
MTGCardInstance * card = cardg->card;
if (card->target)
return;
if (spellMode && (card->isACreature() || card->hasType("land"))) return;
if (!spellMode && !card->isACreature() && !card->hasType("land")) return;
if (card->isACreature()){
int x_offset = nb_creatures % cards_x_limit;
int y_offset = nb_creatures / cards_x_limit;
cardg->x= ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + ZH_CREATURES + (Z_CARDHEIGHT * y_offset) + 100 * (1-player);
nb_creatures++;
if (playerTurn){
if (card->isAttacker()){
cardg->y=122 + 30 * (1-player);
}
}else{
if (card->isDefenser()){
CardGui * targetg = getByCard(card->isDefenser());
if (targetg) cardg->x = targetg->x;
cardg->y=122 + 30 * (1-player);
}
}
}else if(card->hasType("land")){
int x_offset = nb_lands % cards_x_limit;
int y_offset = nb_lands/ cards_x_limit;
cardg->x=ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + (Z_CARDHEIGHT * y_offset) + 200 * (1-player);
nb_lands++;
}else{
int y_offset = nb_spells % Z_SPELLS_NBCARDS;
int x_offset = nb_spells/ Z_SPELLS_NBCARDS;
cardg->x=ZX_SPELL - (Z_CARDWIDTH * x_offset);
cardg->y=ZY_SPELL + (Z_CARDHEIGHT * y_offset) + 125 * (1-player);
nb_spells++;
cards_x_limit = 12 - (nb_spells + 2)/ Z_SPELLS_NBCARDS;
}
adjustCardPosition(cardg);
}
void MTGGuiPlay::setTargettingCardPosition(CardGui * cardg, int player, int playerTurn){
MTGCardInstance * card = cardg->card;
MTGCardInstance * target = card->target;
if (!target)
return;
CardGui * targetg = getByCard(target);
if (targetg){
cardg->y=targetg->y + 5;
cardg->x=targetg->x + 5;
}
adjustCardPosition(cardg);
return;
}
void MTGGuiPlay::updateCards(){
GameObserver * game = GameObserver::GetInstance();
Player * player = game->players[0];
int player0Mode =(game->currentPlayer == player);
int nb_cards = player->game->inPlay->nb_cards;
MTGCardInstance * attackers[MAX_ATTACKERS];
for (int i = 0; i <MAX_ATTACKERS; i++){
attackers[i] = NULL;
}
offset = 6;
Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards;
if (mCount - offset != (nb_cards+opponent_cards) || game->currentPlayer != currentPlayer ){ //if the number of cards has changed, then an update occured (is this test engouh ?)
resetObjects();
AddPlayersGuiInfo();
offset = mCount;
bool hasFocus = player0Mode;
for (int i = 0;i<nb_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, player->game->inPlay->cards[i],40, i*35 + 10, 200, hasFocus);
Add(object);
hasFocus = false;
}
hasFocus = !player0Mode;
for (int i = 0;i<opponent_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, opponent->game->inPlay->cards[i],40, i*35 + 10, 10, hasFocus);
Add(object);
hasFocus = false;
}
currentPlayer = game->currentPlayer;
}
//This is just so that we display the cards of the current player first, so that blockers are correctly positionned
for (int j= 0; j < 2; j++){
initCardsDisplay();
if (j != player0Mode){
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 1);
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 0);
}
}else{
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,1);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,0);
}
}
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset ];
setTargettingCardPosition(cardGui, 0, player0Mode);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setTargettingCardPosition(cardGui, 1, !player0Mode);
}
}
void MTGGuiPlay::AddPlayersGuiInfo(){
//init with the players objects
if (mCount == 0){
Add(NEW GuiAvatar(-1,50,2,155,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiAvatar(-2,50,2,30,false,GameObserver::GetInstance()->players[1]));
Add(NEW GuiGraveyard(-3,30,40,150,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiLibrary(-4,30,40,180,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiGraveyard(-5,30,40,30,false, GameObserver::GetInstance()->players[1]));
Add(NEW GuiLibrary(-6,30,40,60,false, GameObserver::GetInstance()->players[1]));
}
}
void MTGGuiPlay::Update(float dt){
updateCards();
PlayGuiObjectController::Update(dt);
GameObserver * game = GameObserver::GetInstance();
}
void MTGGuiPlay::CheckUserInput(float dt){
for (int i = 2; i<6;i++){
GuiGameZone * zone = (GuiGameZone *)mObjects[i];
if (zone->showCards){
zone->cd->CheckUserInput(dt);
return;
}
}
PlayGuiObjectController::CheckUserInput(dt);
}
void MTGGuiPlay::RenderPlayerInfo(int playerid){
GameObserver * game = GameObserver::GetInstance();
JRenderer * r = JRenderer::GetInstance();
Player * player = GameObserver::GetInstance()->players[playerid];
int life = player->life;
//Avatar
GuiAvatar * avatar = (GuiAvatar *)mObjects[3*playerid];
avatar->Render();
//Mana
ManaCost * cost = player->getManaPool();
int nbicons = 0;
for (int j=0; j<6;j++){
int value = cost->getCost(j);
for (int i=0; i<value; i++){
float x = 10 + (nbicons %4) * 15;
float y = 90 + 125 * (1-playerid) + (15 * (nbicons / 4));
r->RenderQuad(mIcons[j],x,y,0,0.5, 0.5);
nbicons++;
}
}
}
void MTGGuiPlay::RenderPhaseBar(){
GameObserver * game = GameObserver::GetInstance();
JRenderer * renderer = JRenderer::GetInstance();
int currentPhase = game->getCurrentGamePhase();
for (int i=0; i < 12; i++){
int index = 2*i + 1 ;
if (i==currentPhase-1){
index-=1;
}
renderer->RenderQuad(phaseIcons[index], 200 + 14*i,0,0,0.5,0.5);
}
mFont->SetScale(0.70);
if (game->currentlyActing()->isAI()){
mFont->SetColor(ARGB(255,128,128,128));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
mFont->DrawString(MTGPhaseNames[currentPhase], 375, 0);
}
void MTGGuiPlay::Render(){
JRenderer * renderer = JRenderer::GetInstance();
//alphaBg[1] = 255;
//alphaBg[2]= 255;
//alphaBg[3] = 255;
//mBg2->SetColor(ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg2,0,17);
if (game->currentGamePhase >=MTG_PHASE_COMBATBEGIN && game->currentGamePhase < MTG_PHASE_COMBATEND){
if (alphaBg[0] < 50){
alphaBg[3]-=12;
alphaBg[2]-=12;
alphaBg[0]+=3;
}
alphaBg[1] = 255;
}else{
if (alphaBg[0]){
alphaBg[0]-=3;
alphaBg[3]+=12;
alphaBg[2]+=12;
}
alphaBg[1] = 255;
}
renderer->FillRect(0,0,480,272,ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg,0,0);
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
}
RenderPhaseBar();
RenderPlayerInfo(0);
RenderPlayerInfo(1);
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (hasFocus && mCurr >= offset && showBigCards)
((CardGui *)mObjects[mCurr])->RenderBig();
}
if (mGlitterAlpha < 0){
mGlitterAlpha = 510;
int position = rand() % 2;
if (position){
mGlitterX = 65 + rand() % (420);
mGlitterY = 17 + rand() % (5);
}else{
mGlitterX = 65 + rand() % (5);
mGlitterY = 15 + rand() % (250);
}
}
mGlitter->SetColor(ARGB((255-abs(255-mGlitterAlpha)),240,240,255));
renderer->RenderQuad(mGlitter,mGlitterX,mGlitterY, (float)(mGlitterAlpha)/(float)255, 1.2*float(mGlitterAlpha)/float(255),1.2*float(mGlitterAlpha)/float(255));
mGlitterAlpha-=10;
}
MTGGuiPlay::~MTGGuiPlay(){
LOG("==Destroying MTGGuiPlay==");
delete mBg;
delete mBgTex;
for (int i=0; i < 7; i++){
delete mIcons[i];
}
delete mIconsTexture;
delete mGlitter;
for (int i=0; i < 12; i++){
delete phaseIcons[2*i] ;
delete phaseIcons[2*i + 1];
}
delete mPhaseBarTexture;
SAFE_DELETE(mBg2);
SAFE_DELETE(mBgTex2);
LOG("==Destroying MTGGuiPlay Successful==");
}

View File

@@ -1,60 +1,60 @@
#include "../include/debug.h"
#include "../include/MTGRules.h"
MTGAttackRule::MTGAttackRule(int _id):MTGAbility(_id,NULL){
}
int MTGAttackRule::isReactingToClick(MTGCardInstance * card){
if (currentPhase == MTG_PHASE_COMBATATTACKERS && card->controller() == game->currentPlayer && !card->isAttacker()){
if (card->canAttack()) return 1;
}
return 0;
}
int MTGAttackRule::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0;
card->attacker = 1;
if (!card->basicAbilities[VIGILANCE]) card->tapped = 1;
return 1;
}
//The Attack rule is never destroyed
int MTGAttackRule::testDestroy(){
return 0;
}
MTGBlockRule::MTGBlockRule(int _id):MTGAbility(_id,NULL){
}
int MTGBlockRule::isReactingToClick(MTGCardInstance * card){
if (currentPhase == MTG_PHASE_COMBATBLOCKERS && !game->isInterrupting && card->controller() == game->opponent()){
if (card->canBlock()) return 1;
}
return 0;
}
int MTGBlockRule::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0;
MTGCardInstance * currentOpponent = card->isDefenser();
bool result = false;
int candefend = 0;
while (!result){
currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf,"Defenser Toggle %s \n" ,card->model->getName());
OutputDebugString(buf);
#endif
candefend = card->toggleDefenser(currentOpponent);
result = (candefend || currentOpponent == NULL);
}
return 1;
}
//The Block rule is never destroyed
int MTGBlockRule::testDestroy(){
return 0;
}
#include "../include/debug.h"
#include "../include/MTGRules.h"
MTGAttackRule::MTGAttackRule(int _id):MTGAbility(_id,NULL){
}
int MTGAttackRule::isReactingToClick(MTGCardInstance * card){
if (currentPhase == MTG_PHASE_COMBATATTACKERS && card->controller() == game->currentPlayer && !card->isAttacker()){
if (card->canAttack()) return 1;
}
return 0;
}
int MTGAttackRule::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0;
card->attacker = 1;
if (!card->basicAbilities[VIGILANCE]) card->tapped = 1;
return 1;
}
//The Attack rule is never destroyed
int MTGAttackRule::testDestroy(){
return 0;
}
MTGBlockRule::MTGBlockRule(int _id):MTGAbility(_id,NULL){
}
int MTGBlockRule::isReactingToClick(MTGCardInstance * card){
if (currentPhase == MTG_PHASE_COMBATBLOCKERS && !game->isInterrupting && card->controller() == game->opponent()){
if (card->canBlock()) return 1;
}
return 0;
}
int MTGBlockRule::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0;
MTGCardInstance * currentOpponent = card->isDefenser();
bool result = false;
int candefend = 0;
while (!result){
currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf,"Defenser Toggle %s \n" ,card->model->getName());
OutputDebugString(buf);
#endif
candefend = card->toggleDefenser(currentOpponent);
result = (candefend || currentOpponent == NULL);
}
return 1;
}
//The Block rule is never destroyed
int MTGBlockRule::testDestroy(){
return 0;
}

View File

@@ -10,7 +10,7 @@ void MTGSpellStack::addSpell(Ability * ability){
}
int MTGSpellStack::resolve(){
if (cursor < 0)
if (cursor < 0)
return 0;
int result = cursor;
cursor--;

View File

@@ -1,320 +1,320 @@
#include "../include/debug.h"
#include "../include/Logger.h"
#include "../include/ManaCost.h"
#include "../include/ManaCostHybrid.h"
#if defined (WIN32)
#include <windows.h>
#endif
ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
#endif
ManaCost * manaCost;
if (_manaCost){
manaCost = _manaCost;
}else{
manaCost = NEW ManaCost();
}
int state = 0;
unsigned int start = 0;
unsigned int end = 0;
while (!s.empty() && state != -1){
switch(state){
case 0:
start = s.find_first_of("{");
if (start == string::npos){
return manaCost;
}else{
state = 1;
}
break;
case 1:
end = s.find_first_of("}");
if (end == string::npos){
state = -1;
}else{
string value = s.substr(start+1, end - 1 - start);
if (value == "u"){
manaCost->add(MTG_COLOR_BLUE, 1);
}else if (value == "b"){
manaCost->add(MTG_COLOR_BLACK, 1);
}else if (value == "w"){
manaCost->add(MTG_COLOR_WHITE, 1);
}else if (value == "g"){
manaCost->add(MTG_COLOR_GREEN, 1);
}else if (value == "r"){
manaCost->add(MTG_COLOR_RED, 1);
}else if (value == "x"){
manaCost->x();
}else if (value == "t"){
}else{
int intvalue = atoi(value.c_str());
int colors[2];
int values[2];
if (!intvalue && value.size() > 1){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Hybrid Mana ???\n");
#endif
for (int i = 0; i < 2; i++){
char c = value[i];
if (c >='0' && c <='9'){
colors[i] = MTG_COLOR_ARTIFACT;
values[i] = c - '0';
}else{
for (int j = 0; j < MTG_NB_COLORS; j++){
if (c == MTGColorChars[j]){
colors[i] = j;
values[i] = 1;
}
}
}
}
manaCost->addHybrid(colors[0], values[0], colors[1], values[1]);
}else{
manaCost->add(MTG_COLOR_ARTIFACT, intvalue);
}
}
s = s.substr(end + 1);
state = 0;
}
break;
default:
break;
}
}
return manaCost;
}
ManaCost::ManaCost(){
init();
}
ManaCost::ManaCost(int _cost[], int nb_elems){
init();
int i;
int total = nb_elems;
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Create New MAnaCost, total Colors : %i\n", total);
OutputDebugString(buf);
#endif
for (i = 0; i < total; i++){
cost[_cost[i*2]] = _cost[i*2 + 1];
}
}
ManaCost::ManaCost(ManaCost * _manaCost){
init();
int i;
for (i=0; i<= MTG_NB_COLORS; i++){
cost[i] = _manaCost->getCost(i);
}
}
ManaCost::~ManaCost(){
LOG("==Deleting ManaCost==");
for (int i = 0; i < nbhybrids ; i++){
SAFE_DELETE(hybrids[i]);
}
}
void ManaCost::x(){
cost[MTG_NB_COLORS] = 1;
}
void ManaCost::init(){
int i;
for (i=0; i<= MTG_NB_COLORS; i++){
cost[i] = 0;
}
nbhybrids = 0;
}
void ManaCost::copy(ManaCost * _manaCost){
for (int i=0; i<= MTG_NB_COLORS; i++){
cost[i] = _manaCost->getCost(i);
}
for (int i=0; i< _manaCost->nbhybrids; i++){
hybrids[i] = NEW ManaCostHybrid((*_manaCost->hybrids[i]));
}
nbhybrids = _manaCost->nbhybrids;
}
int ManaCost::getCost(int color){
return cost[color];
}
int ManaCost::getMainColor(){
for (int i=0; i< MTG_NB_COLORS; i++){
if (cost[i]) return i;
}
return 0;
}
int ManaCost::hasColor(int color){
if (cost[color]) return 1;
for (int i = 0; i < nbhybrids; i++){
if (hybrids[i]->hasColor(color)) return 1;
}
return 0;
}
int ManaCost::getConvertedCost(){
int result = 0;
for (int i=0; i< MTG_NB_COLORS; i++){
result += cost[i];
}
for (int i = 0; i < nbhybrids; i++){
result+= hybrids[i]->getConvertedCost();
}
return result;
}
int ManaCost::remove(int color, int value){
cost[color] -= value;
return 1;
}
int ManaCost::add(int color, int value){
cost[color] += value;
return 1;
}
int ManaCost::add(ManaCost * _cost){
for (int i=0; i< MTG_NB_COLORS; i++){
cost[i]+= _cost->getCost(i);
}
for (int i=0; i< _cost->nbhybrids; i++){
hybrids[nbhybrids] = NEW ManaCostHybrid((*_cost->hybrids[i]));
nbhybrids++;
}
return 1;
}
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);
hybrids[nbhybrids] = h;
nbhybrids++;
return nbhybrids;
}
int ManaCost::pay(ManaCost * _cost){
ManaCost * diff = Diff(_cost);
for (int i=0; i < MTG_NB_COLORS; i++){
cost[i] = diff->getCost(i);
}
delete diff;
return 1;
//TODO return 0 if can't afford the cost!
}
//return 1 if _cost can be paid with current data
int ManaCost::canAfford(ManaCost * _cost){
ManaCost * diff = Diff(_cost);
int positive = diff->isPositive();
delete diff;
if (positive){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("can afford\n");
#endif
return 1;
}
return 0;
}
int ManaCost::isPositive(){
for (int i=0; i < MTG_NB_COLORS; i++){
if (cost[i] < 0){
return 0;
}
}
return 1;
}
void ManaCost::randomDiffHybrids(ManaCost * _cost, int diff[]){
int _nbhybrids = _cost->nbhybrids;
for (int i = 0; i < _nbhybrids; i++){
ManaCostHybrid * h = _cost->hybrids[i];
diff[h->color1 * 2 +1]-= h->value1;
}
}
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;
}
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[(MTG_NB_COLORS + 1 )* 2];
diff[MTG_NB_COLORS * 2] = MTG_NB_COLORS;
for (int i=0; i < 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);
//Colorless mana, special case
int colorless_idx = MTG_COLOR_ARTIFACT * 2 + 1;
if (diff[colorless_idx] < 0){
#if defined (WIN32) || defined (LINUX)
//char buf[4096], *p = buf;
//sprintf(buf, "--Diff color TEST %i : %i\n", i, cost[i]);
OutputDebugString("Colorless mana not enough\n");
#endif
for (int i=0; i < 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;
}
}
}
}
//Cost X
if (_cost->getCost(MTG_NB_COLORS)){
diff[MTG_NB_COLORS * 2 + 1] = 0;
for (int i=0; i < MTG_NB_COLORS; i++){
if (diff[i*2 + 1] > 0){
diff[MTG_NB_COLORS * 2 + 1] += diff[i*2 + 1];
diff[i*2 + 1] = 0;
}
}
}
ManaCost * result = NEW ManaCost(diff, MTG_NB_COLORS +1);
return result;
}
#include "../include/debug.h"
#include "../include/Logger.h"
#include "../include/ManaCost.h"
#include "../include/ManaCostHybrid.h"
#if defined (WIN32)
#include <windows.h>
#endif
ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
#endif
ManaCost * manaCost;
if (_manaCost){
manaCost = _manaCost;
}else{
manaCost = NEW ManaCost();
}
int state = 0;
unsigned int start = 0;
unsigned int end = 0;
while (!s.empty() && state != -1){
switch(state){
case 0:
start = s.find_first_of("{");
if (start == string::npos){
return manaCost;
}else{
state = 1;
}
break;
case 1:
end = s.find_first_of("}");
if (end == string::npos){
state = -1;
}else{
string value = s.substr(start+1, end - 1 - start);
if (value == "u"){
manaCost->add(MTG_COLOR_BLUE, 1);
}else if (value == "b"){
manaCost->add(MTG_COLOR_BLACK, 1);
}else if (value == "w"){
manaCost->add(MTG_COLOR_WHITE, 1);
}else if (value == "g"){
manaCost->add(MTG_COLOR_GREEN, 1);
}else if (value == "r"){
manaCost->add(MTG_COLOR_RED, 1);
}else if (value == "x"){
manaCost->x();
}else if (value == "t"){
}else{
int intvalue = atoi(value.c_str());
int colors[2];
int values[2];
if (!intvalue && value.size() > 1){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Hybrid Mana ???\n");
#endif
for (int i = 0; i < 2; i++){
char c = value[i];
if (c >='0' && c <='9'){
colors[i] = MTG_COLOR_ARTIFACT;
values[i] = c - '0';
}else{
for (int j = 0; j < MTG_NB_COLORS; j++){
if (c == MTGColorChars[j]){
colors[i] = j;
values[i] = 1;
}
}
}
}
manaCost->addHybrid(colors[0], values[0], colors[1], values[1]);
}else{
manaCost->add(MTG_COLOR_ARTIFACT, intvalue);
}
}
s = s.substr(end + 1);
state = 0;
}
break;
default:
break;
}
}
return manaCost;
}
ManaCost::ManaCost(){
init();
}
ManaCost::ManaCost(int _cost[], int nb_elems){
init();
int i;
int total = nb_elems;
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Create New MAnaCost, total Colors : %i\n", total);
OutputDebugString(buf);
#endif
for (i = 0; i < total; i++){
cost[_cost[i*2]] = _cost[i*2 + 1];
}
}
ManaCost::ManaCost(ManaCost * _manaCost){
init();
int i;
for (i=0; i<= MTG_NB_COLORS; i++){
cost[i] = _manaCost->getCost(i);
}
}
ManaCost::~ManaCost(){
LOG("==Deleting ManaCost==");
for (int i = 0; i < nbhybrids ; i++){
SAFE_DELETE(hybrids[i]);
}
}
void ManaCost::x(){
cost[MTG_NB_COLORS] = 1;
}
void ManaCost::init(){
int i;
for (i=0; i<= MTG_NB_COLORS; i++){
cost[i] = 0;
}
nbhybrids = 0;
}
void ManaCost::copy(ManaCost * _manaCost){
for (int i=0; i<= MTG_NB_COLORS; i++){
cost[i] = _manaCost->getCost(i);
}
for (int i=0; i< _manaCost->nbhybrids; i++){
hybrids[i] = NEW ManaCostHybrid((*_manaCost->hybrids[i]));
}
nbhybrids = _manaCost->nbhybrids;
}
int ManaCost::getCost(int color){
return cost[color];
}
int ManaCost::getMainColor(){
for (int i=0; i< MTG_NB_COLORS; i++){
if (cost[i]) return i;
}
return 0;
}
int ManaCost::hasColor(int color){
if (cost[color]) return 1;
for (int i = 0; i < nbhybrids; i++){
if (hybrids[i]->hasColor(color)) return 1;
}
return 0;
}
int ManaCost::getConvertedCost(){
int result = 0;
for (int i=0; i< MTG_NB_COLORS; i++){
result += cost[i];
}
for (int i = 0; i < nbhybrids; i++){
result+= hybrids[i]->getConvertedCost();
}
return result;
}
int ManaCost::remove(int color, int value){
cost[color] -= value;
return 1;
}
int ManaCost::add(int color, int value){
cost[color] += value;
return 1;
}
int ManaCost::add(ManaCost * _cost){
for (int i=0; i< MTG_NB_COLORS; i++){
cost[i]+= _cost->getCost(i);
}
for (int i=0; i< _cost->nbhybrids; i++){
hybrids[nbhybrids] = NEW ManaCostHybrid((*_cost->hybrids[i]));
nbhybrids++;
}
return 1;
}
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);
hybrids[nbhybrids] = h;
nbhybrids++;
return nbhybrids;
}
int ManaCost::pay(ManaCost * _cost){
ManaCost * diff = Diff(_cost);
for (int i=0; i < MTG_NB_COLORS; i++){
cost[i] = diff->getCost(i);
}
delete diff;
return 1;
//TODO return 0 if can't afford the cost!
}
//return 1 if _cost can be paid with current data
int ManaCost::canAfford(ManaCost * _cost){
ManaCost * diff = Diff(_cost);
int positive = diff->isPositive();
delete diff;
if (positive){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("can afford\n");
#endif
return 1;
}
return 0;
}
int ManaCost::isPositive(){
for (int i=0; i < MTG_NB_COLORS; i++){
if (cost[i] < 0){
return 0;
}
}
return 1;
}
void ManaCost::randomDiffHybrids(ManaCost * _cost, int diff[]){
int _nbhybrids = _cost->nbhybrids;
for (int i = 0; i < _nbhybrids; i++){
ManaCostHybrid * h = _cost->hybrids[i];
diff[h->color1 * 2 +1]-= h->value1;
}
}
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;
}
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[(MTG_NB_COLORS + 1 )* 2];
diff[MTG_NB_COLORS * 2] = MTG_NB_COLORS;
for (int i=0; i < 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);
//Colorless mana, special case
int colorless_idx = MTG_COLOR_ARTIFACT * 2 + 1;
if (diff[colorless_idx] < 0){
#if defined (WIN32) || defined (LINUX)
//char buf[4096], *p = buf;
//sprintf(buf, "--Diff color TEST %i : %i\n", i, cost[i]);
OutputDebugString("Colorless mana not enough\n");
#endif
for (int i=0; i < 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;
}
}
}
}
//Cost X
if (_cost->getCost(MTG_NB_COLORS)){
diff[MTG_NB_COLORS * 2 + 1] = 0;
for (int i=0; i < MTG_NB_COLORS; i++){
if (diff[i*2 + 1] > 0){
diff[MTG_NB_COLORS * 2 + 1] += diff[i*2 + 1];
diff[i*2 + 1] = 0;
}
}
}
ManaCost * result = NEW ManaCost(diff, MTG_NB_COLORS +1);
return result;
}

View File

@@ -1,26 +1,26 @@
#include "../include/ManaCostHybrid.h"
ManaCostHybrid::ManaCostHybrid(){
init(0,0,0,0);
}
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){
color1 = c1;
color2 = c2;
value1 = v1;
value2 = v2;
}
int ManaCostHybrid::getConvertedCost(){
if (value2 > value1) return value2;
return value1;
}
int ManaCostHybrid::hasColor(int color){
if (((color1 == color) && value1) || ((color2 == color) && value2)) return 1;
return 0;
}
#include "../include/ManaCostHybrid.h"
ManaCostHybrid::ManaCostHybrid(){
init(0,0,0,0);
}
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){
color1 = c1;
color2 = c2;
value1 = v1;
value2 = v2;
}
int ManaCostHybrid::getConvertedCost(){
if (value2 > value1) return value2;
return value1;
}
int ManaCostHybrid::hasColor(int color){
if (((color1 == color) && value1) || ((color2 == color) && value2)) return 1;
return 0;
}

View File

@@ -1,113 +1,113 @@
#include "../include/debug.h"
#include "../include/MenuItem.h"
MenuItem::MenuItem(int id, JLBFont *font, const char* text, int x, int y, JQuad * _off, JQuad * _on, const char * particle, JQuad * particleTex, bool hasFocus): JGuiObject(id), mFont(font), mText(text), mX(x), mY(y)
{
updatedSinceLastRender = 1;
mParticleSys = NEW hgeParticleSystem(particle, particleTex);
mParticleSys->MoveTo(mX, mY);
mHasFocus = hasFocus;
lastDt = 0.001f;
mScale = 1.0f;
mTargetScale = 1.0f;
onQuad = _on;
offQuad = _off;
if (hasFocus)
Entering();
mFont->SetScale(1.2f);
}
void MenuItem::Render()
{
JRenderer * renderer = JRenderer::GetInstance();
if (mHasFocus)
{
if (!updatedSinceLastRender){
mParticleSys->Update(lastDt);
}
// set additive blending
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
mParticleSys->Render();
// set normal blending
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);
onQuad->SetColor(ARGB(255,255,255,255));
mFont->DrawString(mText, SCREEN_WIDTH/2, 3*SCREEN_HEIGHT/4, JGETEXT_CENTER);
renderer->RenderQuad(onQuad, mX , mY , 0,mScale,mScale);
}
else
{
renderer->RenderQuad(offQuad, mX , mY , 0,mScale,mScale);
}
updatedSinceLastRender= 0;
}
void MenuItem::Update(float dt)
{
updatedSinceLastRender = 1;
lastDt = 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;
}
if (mHasFocus){
mParticleSys->Update(dt);
}
}
void MenuItem::Entering()
{
mParticleSys->Fire();
mHasFocus = true;
mTargetScale = 1.3f;
}
bool MenuItem::Leaving(u32 key)
{
mParticleSys->Stop(true);
mHasFocus = false;
mTargetScale = 1.0f;
return true;
}
bool MenuItem::ButtonPressed()
{
return true;
}
MenuItem::~MenuItem(){
if (mParticleSys) delete mParticleSys;
}
#include "../include/debug.h"
#include "../include/MenuItem.h"
MenuItem::MenuItem(int id, JLBFont *font, const char* text, int x, int y, JQuad * _off, JQuad * _on, const char * particle, JQuad * particleTex, bool hasFocus): JGuiObject(id), mFont(font), mText(text), mX(x), mY(y)
{
updatedSinceLastRender = 1;
mParticleSys = NEW hgeParticleSystem(particle, particleTex);
mParticleSys->MoveTo(mX, mY);
mHasFocus = hasFocus;
lastDt = 0.001f;
mScale = 1.0f;
mTargetScale = 1.0f;
onQuad = _on;
offQuad = _off;
if (hasFocus)
Entering();
mFont->SetScale(1.2f);
}
void MenuItem::Render()
{
JRenderer * renderer = JRenderer::GetInstance();
if (mHasFocus)
{
if (!updatedSinceLastRender){
mParticleSys->Update(lastDt);
}
// set additive blending
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
mParticleSys->Render();
// set normal blending
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);
onQuad->SetColor(ARGB(255,255,255,255));
mFont->DrawString(mText, SCREEN_WIDTH/2, 3*SCREEN_HEIGHT/4, JGETEXT_CENTER);
renderer->RenderQuad(onQuad, mX , mY , 0,mScale,mScale);
}
else
{
renderer->RenderQuad(offQuad, mX , mY , 0,mScale,mScale);
}
updatedSinceLastRender= 0;
}
void MenuItem::Update(float dt)
{
updatedSinceLastRender = 1;
lastDt = 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;
}
if (mHasFocus){
mParticleSys->Update(dt);
}
}
void MenuItem::Entering()
{
mParticleSys->Fire();
mHasFocus = true;
mTargetScale = 1.3f;
}
bool MenuItem::Leaving(u32 key)
{
mParticleSys->Stop(true);
mHasFocus = false;
mTargetScale = 1.0f;
return true;
}
bool MenuItem::ButtonPressed()
{
return true;
}
MenuItem::~MenuItem(){
if (mParticleSys) delete mParticleSys;
}

Some files were not shown because too many files have changed in this diff Show More