* 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
+33 -33
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 _IAPLAYER_H
#define _IAPLAYER_H
@@ -17,40 +17,40 @@
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;};
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();
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{
+18 -18
View File
@@ -14,29 +14,29 @@ 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){};
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);
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
+24 -24
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";};
};
+20 -20
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();
};
+79 -79
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 _SPELLSTACK_H_
#define _SPELLSTACK_H_
@@ -43,105 +43,105 @@ class ManaCost;
#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;};
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);
public:
int resolve();
void Render();
NextGamePhase(int id);
};
class Spell: public Interruptible, public TargetsList {
protected:
protected:
public:
ManaCost * cost;
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, Targetable * _targets[], int _nbtargets, ManaCost * _cost);
~Spell();
int resolve();
void Render();
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);
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);
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);
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;
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 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);
ActionStack(int id, GameObserver* _game);
int resolve();
int CombatDamages();
int CombatDamages(int firststrike);
int has(Interruptible * action);
};
File diff suppressed because it is too large Load Diff
+26 -26
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();
};
+11 -11
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
+15 -15
View File
@@ -8,25 +8,25 @@ 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);
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();
public:
DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, int _nb_displayed_items );
~DefaultTargetDisplay();
};
#endif
+7 -7
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();
};
+3 -3
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
+25 -25
View File
@@ -8,35 +8,35 @@ 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();
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);
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);
};
+27 -27
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);
};
+24 -24
View File
@@ -8,31 +8,31 @@ class DamageStack;
class DamageResolverLayer:public PlayGuiObjectController{
protected:
int trampleDamage();
public:
int buttonOk;
int currentPhase;
int remainingDamageSteps;
Player * currentChoosingPlayer;
DamageStack * damageStack;
DamagerDamaged * currentSource;
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();
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
+14 -14
View File
@@ -6,21 +6,21 @@
class Player;
class DamagerDamaged:public CardGui{
public:
Player * damageSelecter;
int mCount;
Damage * damages[10];
int damageToDeal;
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);
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);
+26 -26
View File
@@ -12,37 +12,37 @@ 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);
}
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;
public:
int colors[MTG_NB_COLORS+1];
int currentColor;
map<MTGCard *, int,Cmp1> cards;
int currentposition;
MTGDeck * parent;
DeckDataWrapper(MTGDeck * deck);
~DeckDataWrapper();
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();
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
+7 -7
View File
@@ -12,13 +12,13 @@ class DamageResolverLayer;
class DuelLayers: public GuiLayers{
public:
ActionLayer * actionLayer();
MTGGuiHand * handLayer();
MTGGuiPlay * playLayer();
ActionStack * stackLayer();
DamageResolverLayer * combatLayer();
void init();
public:
ActionLayer * actionLayer();
MTGGuiHand * handLayer();
MTGGuiPlay * playLayer();
ActionStack * stackLayer();
DamageResolverLayer * combatLayer();
void init();
};
+20 -20
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/
*/
@@ -51,7 +51,7 @@ class TexturesCache;
class GameApp: public JApp
{
private:
private:
bool mShowDebugInfo;
int mScreenShotCount;
@@ -60,26 +60,26 @@ private:
GameState* mGameStates[MAX_STATE];
public:
int players[2];
public:
int players[2];
MTGAllCards * collection;
TexturesCache * cache;
GameApp();
virtual ~GameApp();
GameApp();
virtual ~GameApp();
virtual void Create();
virtual void Destroy();
virtual void Update();
virtual void Render();
virtual void Pause();
virtual void Resume();
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;
void LoadGameStates();
void SetNextState(int state);
static JResourceManager * CommonRes;
static hgeParticleSystem * Particles[6];
static int HasMusic;
};
+28 -28
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);
+10 -10
View File
@@ -7,17 +7,17 @@
#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();
public:
int values[MAX_OPTIONS];
static GameOptions * GetInstance();
static void Destroy();
int save();
int load();
private:
GameOptions();
~GameOptions();
static GameOptions* mInstance;
private:
GameOptions();
~GameOptions();
static GameOptions* mInstance;
};
+20 -20
View File
@@ -8,37 +8,37 @@ class JGE;
#include <JSoundSystem.h>
enum _gameSates
{
GAME_STATE_MENU,
GAME_STATE_DUEL,
GAME_STATE_DECK_VIEWER,
GAME_STATE_SHOP,
GAME_STATE_OPTIONS
};
{
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;
protected:
GameApp* mParent;
JGE* mEngine;
public:
public:
static const char * const menuTexts[];
GameState(GameApp* parent);
virtual ~GameState() {}
static const char * const menuTexts[];
GameState(GameApp* parent);
virtual ~GameState() {}
virtual void Create() {}
virtual void Destroy() {}
virtual void Create() {}
virtual void Destroy() {}
virtual void Start() {}
virtual void End() {}
virtual void Start() {}
virtual void End() {}
virtual void Update(float dt) = 0;
virtual void Render() = 0;
virtual void Update(float dt) = 0;
virtual void Render() = 0;
};
File diff suppressed because it is too large Load Diff
+19 -19
View File
@@ -22,31 +22,31 @@ class TestSuite;
class GameStateDuel: public GameState, public JGuiListener
{
private:
private:
#ifdef TESTSUITE
TestSuite * testSuite;
TestSuite * testSuite;
#endif
int mGamePhase;
Player * mCurrentPlayer;
Player * mPlayers[2];
MTGPlayerCards * deck[2];
GameObserver * game;
SimpleMenu * deckmenu;
SimpleMenu * menu;
JLBFont* mFont;
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();
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();
virtual void ButtonPressed(int ControllerId, int ControlId);
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
};
+389 -389
View File
@@ -25,404 +25,404 @@
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];
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];
DIR *mDip;
struct dirent *mDit;
char mCurrentSetName[10];
char mCurrentSetFileName[512];
int mReadConf;
int mReadConf;
public:
GameStateMenu(GameApp* parent): GameState(parent)
{
mGuiController = NULL;
subMenuController = NULL;
mIconsTexture = NULL;
bgMusic = NULL;
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;
}
virtual ~GameStateMenu()
{
}
}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;
}
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;
}
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
case 666:
mParent->players[0] = PLAYER_TYPE_TESTSUITE;
mParent->players[1] = PLAYER_TYPE_TESTSUITE;
mParent->SetNextState(GAME_STATE_DUEL);
break;
subMenuController->Add(666, "Test Suite");
#endif
}
break;
}
}
}
}
}
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;
}
}
};
+11 -11
View File
@@ -14,18 +14,18 @@ class SimpleMenu;
class GameStateOptions: public GameState, public JGuiListener
{
public:
SimpleMenu * optionsMenu;
int mState;
OptionsList * optionsList;
GameStateOptions(GameApp* parent);
virtual ~GameStateOptions();
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);
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
void ButtonPressed(int controllerId, int ControlId);
};
+21 -21
View File
@@ -14,30 +14,30 @@
class GameStateShop: public GameState, public JGuiListener
{
private:
private:
ShopItems * shop;
JLBFont * mFont;
JQuad * mBg;
JTexture * bgTexture;
JQuad * mBack;
JTexture * backTexture;
SimpleMenu * menu;
int mStage;
char starterBuffer[128], boosterBuffer[128];
int setId;
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();
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);
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);
};
+2 -2
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){};
};
+7 -7
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{
+2 -2
View File
@@ -13,8 +13,8 @@
#define LOG_FILE "Res/debug.txt"
class Logger{
public:
static void Log(char * text);
public:
static void Log(char * text);
};
#endif
+51 -51
View File
@@ -24,18 +24,18 @@ using std::map;
#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);
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);
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL);
void addAbilities(int _id, Spell * spell);
};
class MTGAbility: public ActionElement{
protected:
char menuText[25];
char menuText[25];
Damageable * target;
GameObserver * game;
public:
@@ -45,72 +45,72 @@ class MTGAbility: public ActionElement{
virtual int testDestroy();
virtual ~MTGAbility();
virtual void Render(){};
virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
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;};
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;
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();
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();
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;};
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();
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"
+27 -27
View File
@@ -37,46 +37,46 @@ class MTGCard {
char image_name[MTGCARD_NAME_SIZE];
int init();
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 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;
int setId;
static const char * const Colors_To_Text[];
int nb_types;
int nb_types;
int types[MAX_TYPES_PER_CARD];
MTGCard();
MTGCard();
MTGCard(TexturesCache * cache, int set_id);
MTGCard(MTGCard * source);
MTGCard(MTGCard * source);
JQuad * getQuad(TexturesCache * cache);
JQuad * getQuad(int type=1);
JQuad * getThumb();
JQuad * getThumb();
void setColor(int _color, int removeAllOthers = 0);
int getColor();
int hasColor(int _color);
int hasColor(int _color);
const char * colorToString();
void setMTGId(int id);
int getMTGId();
int getId();
int has(int ability);
int has(int ability);
char getRarity();
char getRarity();
void setRarity(char _rarity);
const char * getSetName();
const char * getSetName();
//void setImageName( char * value);
char * getImageName ();
@@ -84,31 +84,31 @@ class MTGCard {
void setText( string value);
const char * getText();
void addMagicText(string value);
void addMagicText(string value);
void setName( string value);
const char * getName();
void addType(char * type_text);
void addType(int id);
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 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 hasSubtype(const char * _subtype);
int hasSubtype(string _subtype);
int hasType(int _type);
int hasType(const char * type);
int hasType(const char * type);
void setManaCost(string value);
ManaCost * getManaCost();
int isACreature();
void setPower(int _power);
int getPower();
int getPower();
void setToughness(int _toughness);
int getToughness();
int getToughness();
};
+48 -48
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();
+33 -33
View File
@@ -24,15 +24,15 @@ class MTGCard;
class MtgSets{
protected:
public:
int nb_items;
string values[MAX_SETS];
protected:
public:
int nb_items;
string values[MAX_SETS];
public:
static MtgSets * SetsList;
MtgSets();
int Add(const char * subtype);
public:
static MtgSets * SetsList;
MtgSets();
int Add(const char * subtype);
};
@@ -43,27 +43,27 @@ class MTGAllCards {
int conf_fd;
char * conf_buffer;
int read_cursor;
int colorsCount[MTG_NB_COLORS];
int colorsCount[MTG_NB_COLORS];
int total_cards;
GameApp * parent;
void init();
void initCounters();
void init();
void initCounters();
public:
TexturesCache * mCache;
MTGCard * _(int i);
TexturesCache * mCache;
MTGCard * _(int i);
MTGCard * collection[TOTAL_NUMBER_OF_CARDS];
MTGAllCards();
~MTGAllCards();
MTGAllCards(TexturesCache * cache);
void destroyAllCards();
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 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();
@@ -73,18 +73,18 @@ class MTGAllCards {
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();
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();
};
+54 -54
View File
@@ -99,44 +99,44 @@ static int _b[7] = {20, 0, 140,15, 50,255,128};
#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",
"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",
};
@@ -152,22 +152,22 @@ static const char * MTGBasicAbilities[] = {
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",
"---"
};
{
"---",
"Untap",
"Upkeep",
"Draw",
"Main phase 1",
"Combat begins",
"Attackers",
"Blockers",
"Combat damage",
"Combat ends",
"Main phase 2",
"End of turn",
"cleanup",
"---"
};
+2 -2
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);
};
+22 -22
View File
@@ -15,32 +15,32 @@ class Player;
class MTGGameZone {
protected:
Player * owner;
Player * owner;
public:
//Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array
//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;
map<MTGCardInstance *,int> cardsMap;
int nb_cards;
MTGGameZone();
~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;
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();
void shuffleTopToBottom(int nbcards);
MTGCardInstance * draw();
};
class MTGGraveyard: public MTGGameZone {
@@ -54,7 +54,7 @@ class MTGHand: public MTGGameZone {
class MTGStack: public MTGGameZone {
public:
public:
};
class MTGInPlay: public MTGGameZone {
@@ -62,9 +62,9 @@ class MTGInPlay: public MTGGameZone {
//MTGInPlay();
void untapAll();
MTGCardInstance * getNextAttacker(MTGCardInstance * previous);
MTGCardInstance * getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker);
int nbDefensers( MTGCardInstance * attacker);
int nbPartners(MTGCardInstance * attacker);
MTGCardInstance * getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker);
int nbDefensers( MTGCardInstance * attacker);
int nbPartners(MTGCardInstance * attacker);
};
@@ -77,18 +77,18 @@ class MTGPlayerCards {
MTGGraveyard * graveyard;
MTGHand * hand;
MTGInPlay * inPlay;
MTGStack * stack;
MTGAllCards * collection;
MTGStack * stack;
MTGAllCards * collection;
MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize);
~MTGPlayerCards();
~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1);
void setOwner(Player * player);
void discardRandom(MTGGameZone * from);
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 putInGraveyard(MTGCardInstance * card);
void putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card);
+1 -1
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;
+33 -33
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();
+70 -70
View File
@@ -1,5 +1,5 @@
/* Default observers/Abilities that are added to the game for a standard Magic Game
*/
*/
#ifndef _MTGRULES_H_
#define _MTGRULES_H_
@@ -9,72 +9,72 @@
class MTGAttackRule:public MTGAbility{
public:
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int testDestroy();
MTGAttackRule(int _id);
const char * getMenuText(){return "Attacker";}
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";}
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){};
public:
MTGPersistRule(int _id):ListMaintainerAbility(_id){};
virtual void Update(float dt){
map<MTGCardInstance *,bool>::iterator it;
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)){
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");
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;
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");
OutputDebugString("persist passed test 2 !\n");
#endif
card->counters->addCounter(-1,-1);
card->counters->addCounter(-1,-1);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 3 !\n");
OutputDebugString("persist passed test 3 !\n");
#endif
}
}
ListMaintainerAbility::Update(dt);
}
}
}
ListMaintainerAbility::Update(dt);
}
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[PERSIST] && !card->counters->hasCounter(-1,-1) ){
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[PERSIST] && !card->counters->hasCounter(-1,-1) ){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("yay, persist !\n");
OutputDebugString("yay, persist !\n");
#endif
return 1;
}
return 0;
}
return 1;
}
return 0;
}
int added(MTGCardInstance * card){return 1;}
int added(MTGCardInstance * card){return 1;}
int removed(MTGCardInstance * card){return 0;}
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
int testDestroy(){return 0;}
};
@@ -84,37 +84,37 @@ public:
* 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){};
public:
MTGLegendRule(int _id):ListMaintainerAbility(_id){};
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[LEGENDARY]){
return 1;
}
return 0;
}
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 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 removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
int testDestroy(){return 0;}
};
#endif
+15 -15
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);
+10 -10
View File
@@ -2,16 +2,16 @@
#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();
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
+21 -21
View File
@@ -12,31 +12,31 @@ class hgeParticleSystem;
class MenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* const mText;
int mX;
int mY;
int updatedSinceLastRender;
float lastDt;
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;
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);
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();
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif
+24 -24
View File
@@ -7,34 +7,34 @@
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);
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;};
~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();
public:
OptionItem * options[20];
int nbitems;
int current;
OptionsList();
~OptionsList();
void Render();
void Update(float dt);
void Add(OptionItem * item);
void save();
};
#endif
+16 -16
View File
@@ -5,30 +5,30 @@
using std::list;
/*
The class that handles the phases of a turn
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){};
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);
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
+34 -34
View File
@@ -1,5 +1,5 @@
/*
A class for all interactive objects in the play area (cards, avatars, etc...)
A class for all interactive objects in the play area (cards, avatars, etc...)
*/
#ifndef _PLAYGUIOBJECT_H_
@@ -23,55 +23,55 @@ class PlayGuiObject: public JGuiObject, public JGuiListener{
int wave;
float mHeight;
float defaultHeight;
bool mHasFocus;
int x;
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(){};
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:
protected:
int avatarRed;
int currentLife;
public:
Player * player;
virtual void Render();
GuiAvatar(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * _player);
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;
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();
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);
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);
public:
GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
};
@@ -8,11 +8,11 @@ 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();};
};
+13 -13
View File
@@ -15,27 +15,27 @@ 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();
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{
+7 -7
View File
@@ -6,13 +6,13 @@
#include "../include/MTGDeck.h"
class PlayerData{
protected:
public:
int credits;
MTGDeck * collection;
PlayerData(MTGAllCards * allcards);
~PlayerData();
int save();
protected:
public:
int credits;
MTGDeck * collection;
PlayerData(MTGAllCards * allcards);
~PlayerData();
int save();
};
#endif
+15 -15
View File
@@ -7,24 +7,24 @@
#include <stdio.h>
class Price{
public:
int cardid;
int price;
Price(int _cardid, int _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);
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);
};
+46 -46
View File
@@ -13,59 +13,59 @@
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;
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();
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 Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
const char * getText();
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();
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
+10 -10
View File
@@ -1,5 +1,5 @@
/*
A class for very simple menus structure
A class for very simple menus structure
*/
#ifndef _SIMPLEMENU_H_
#define _SIMPLEMENU_H_
@@ -9,15 +9,15 @@ A class for very simple menus structure
#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);
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);
};
+15 -15
View File
@@ -10,27 +10,27 @@
class SimpleMenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* mText;
int mX;
int mY;
private:
bool mHasFocus;
JLBFont *mFont;
const char* mText;
int mX;
int mY;
float mScale;
float mTargetScale;
float mScale;
float mTargetScale;
public:
SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus = false);
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 Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif
+10 -10
View File
@@ -8,17 +8,17 @@ using std::string;
using std::map;
class Subtypes{
protected:
int nb_items;
map<string,int> values;
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);
public:
static Subtypes * subtypesList;
Subtypes();
int Add(const char * subtype);
int find(const char * subtype);
int Add(string subtype);
int find(string subtype);
};
+64 -64
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
+2 -2
View File
@@ -6,8 +6,8 @@
#define TARGET_STACKACTION 3
class Targetable{
public:
virtual int typeAsTarget() = 0;
public:
virtual int typeAsTarget() = 0;
};
#endif
+16 -16
View File
@@ -12,23 +12,23 @@ 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);
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;};
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous, int type);
void initTargets(){cursor = 0;};
};
#endif
+52 -52
View File
@@ -7,76 +7,76 @@
#include "../include/AIPlayer.h"
class TestSuiteActions{
public:
int nbitems;
string actions[MAX_TESTSUITE_ACTIONS];
void add(string action);
TestSuiteActions();
void cleanup();
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();
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();
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();
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);
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;}
public:
TestSuite * suite;
float timer;
TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId);
virtual int Act(float dt);
virtual int displayStack(){return 1;}
};
+9 -9
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);};
};
+5 -5
View File
@@ -12,11 +12,11 @@
#endif
#ifdef LINUX
#ifdef _DEBUG
#define OutputDebugString(val) (std::cerr << val);
#else
#define OutputDebugString(val) {}
#endif
#ifdef _DEBUG
#define OutputDebugString(val) (std::cerr << val);
#else
#define OutputDebugString(val) {}
#endif
#endif
#endif
+1 -1
View File
@@ -33,7 +33,7 @@
using std::string;
template <typename T, size_t N>
char ( &_ArraySizeHelper( T (&array)[N] ))[N];
char ( &_ArraySizeHelper( T (&array)[N] ))[N];
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
File diff suppressed because it is too large Load Diff
+93 -93
View File
@@ -5,125 +5,125 @@
#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);
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;
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;
}
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;
}
}
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);
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();
//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;
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;
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;
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::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
}
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();
}
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();
}
}
+27 -27
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;
}
+132 -132
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);
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;
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
+60 -60
View File
@@ -2,114 +2,114 @@
#include "../include/Blocker.h"
Blocker::Blocker(int id, MTGCardInstance * card):MTGAbility(id, card){
init ( NEW ManaCost());
init ( NEW ManaCost());
}
Blocker::Blocker(int id, MTGCardInstance * card, ManaCost * _cost):MTGAbility(id, card){
init(_cost);
init(_cost);
}
Blocker::Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost):MTGAbility(id, card,_target){
init(_cost);
init(_cost);
}
Blocker::~Blocker(){
delete manaCost;
delete manaCost;
}
void Blocker::init(ManaCost * _cost){
currentPhase = -1;
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);
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);
char buf[4096];
sprintf(buf, "Adding Blocker to %s \n", _target->model->getName());
OutputDebugString(buf);
#endif
}
currentPhase = newPhase;
}
currentPhase = newPhase;
}
int Blocker::destroy(){
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getBlockers()->Remove(this);
return 1;
MTGCardInstance * _target;
if (target){
_target = (MTGCardInstance *) target;
}else{
_target = source;
}
_target->getBlockers()->Remove(this);
return 1;
}
Blockers::Blockers(){
init();
init();
}
int Blockers::init(){
cursor = -1;
cursor = -1;
for (int i=0; i< MAX_BLOCKERS ; i++){
blockers[i] = 0;
}
for (int i=0; i< MAX_BLOCKERS ; i++){
blockers[i] = 0;
}
return 1;
return 1;
}
int Blockers::Add (Blocker * ability){
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 1;
return index;
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;
game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 0;
return index;
}
int Blockers::rewind(){
cursor = -1;
return 1;
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));
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;
for (int i=0; i< MAX_BLOCKERS ; i++){
if (blockers[i])
return 0;
}
return 1;
}
Blockers::~Blockers(){
+91 -91
View File
@@ -2,130 +2,130 @@
#include "../include/CardDescriptor.h"
CardDescriptor::CardDescriptor(): MTGCardInstance(){
init();
mode = CD_AND;
init();
mode = CD_AND;
}
int CardDescriptor::init(){
return MTGCardInstance::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;
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;
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");
OutputDebugString("Match AND\n");
#endif
MTGCardInstance * match = card;
for (int i = 0; i< nb_types; i++){
MTGCardInstance * match = card;
for (int i = 0; i< nb_types; i++){
if (!card->hasSubtype(types[i])){
if (!card->hasSubtype(types[i])){
#ifdef WIN32
OutputDebugString(card->name.c_str());
OutputDebugString("Subtype No Match\n");
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;
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");
OutputDebugString(card->name.c_str());
OutputDebugString("Color No Match\n");
#endif
}
}
return match;
}
}
return match;
}
MTGCardInstance * CardDescriptor::match(MTGCardInstance * card){
MTGCardInstance * match = card;
MTGCardInstance * match = card;
if (mode == CD_AND){
match = match_and(card);
}else{
match=match_or(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;
}
}
//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 ((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
}
}
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;
return match;
}
MTGCardInstance * CardDescriptor::match(MTGGameZone * zone){
return (nextmatch(zone, NULL));
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);
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;
return zone->cards[i];
}
if (zone->cards[i] == previous){
found = 1;
}
}
return NULL;
}
+104 -104
View File
@@ -5,152 +5,152 @@
#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;
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;
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);
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]);
}
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 --;
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 ++;
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 (mEngine->GetButtonClick(PSP_CTRL_CROSS))
{
if (listener != NULL)
{
if (listener != NULL)
{
listener->ButtonPressed(mId, 0);
return;
}
listener->ButtonPressed(mId, 0);
return;
}
}
if (!mCount)
return;
if (!mCount)
return;
if (mEngine->GetButtonClick(mActionButton))
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))
{
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;
}
}
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();
}
}
if (mEngine->GetButtonState(PSP_CTRL_LEFT))
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT))
{
if (KeyRepeated(PSP_CTRL_RIGHT, dt))
{
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();
}
}
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;
}
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();
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();
tc = NEW TargetChooser();
}
DefaultTargetDisplay::~DefaultTargetDisplay(){
SAFE_DELETE(tc);
SAFE_DELETE(tc);
}
+255 -255
View File
@@ -3,315 +3,315 @@
#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;
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);
JRenderer * renderer = JRenderer::GetInstance();
mFont->SetRotation(rotation);
mFont->SetScale(scale);
int color = card->getColor();
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;
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);
}
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);
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{
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);
}
s = "";
}
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++;
}
}else{
int newcut = cut;
while (newcut < len && newcut != -1){
cut = newcut;
newcut = s.find_first_of("., \t)", newcut + 1);
}
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;
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);
}
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));
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);
}
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());
LOG("==Creating NEW CardGui Object. CardName:");
LOG(_card->getName());
card = _card;
type = GUI_CARD;
card = _card;
type = GUI_CARD;
alpha = 255;
mParticleSys = NULL;
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];
}
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");
LOG("==CardGui Object Creation Succesfull");
}
void CardGui::Update(float dt){
alpha = 255;
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);
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);
}
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);
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;
}
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));
}
}
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);
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);
}
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);
}
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);
}
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");
LOG("==Destroying CardGui object");
LOG(this->card->getName());
LOG("==CardGui object destruction Successful");
}
+32 -32
View File
@@ -3,39 +3,39 @@
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 (!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);
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;
}
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;
if (ok) {
player->getManaPool()->pay(untapManaCost);
card->untap();
}
delete untapManaCost;
return ok;
}
+97 -97
View File
@@ -3,118 +3,118 @@
#include "../include/MTGCardInstance.h"
Counter::Counter(MTGCardInstance * _target, int _power, int _toughness){
init(_target,"",_power, _toughness);
init(_target,"",_power, _toughness);
}
Counter::Counter(MTGCardInstance * _target, const char * _name,int _power, int _toughness ){
init(_target,_name,_power, _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;
}
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::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);
}
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::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;
}
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];
}
}
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;
}
}
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;
}
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::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(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);
}
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(const char * _name,int _power, int _toughness){
for (int i = 0; i < mCount; i++){
if (counters[i]->sameAs(_name, _power,_toughness)){
if (counters[i]->nb > 0) return counters[i];
}
}
return NULL;
}
Counter * Counters::hasCounter(int _power , int _toughness ){
return hasCounter("",_power, _toughness);
}
Counter * Counters::hasCounter(int _power , int _toughness ){
return hasCounter("",_power, _toughness);
}
Counter * Counters::getNext(Counter * previous){
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;
}
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;
}
+98 -98
View File
@@ -4,139 +4,139 @@
#include "../include/Counters.h"
Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target): Interruptible(id){
init(_source, _target, _source->getPower());
init(_source, _target, _source->getPower());
}
Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target, int _damage): Interruptible(id){
init(_source, _target, _damage);
init(_source, _target, _damage);
}
void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage){
target = _target;
source = _source;
target = _target;
source = _source;
if (_damage < 0) _damage = 0; //Negative damages cannot happen
damage = _damage;
mHeight = 40;
type = ACTION_DAMAGE;
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;
}
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;
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();
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
}
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
}
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;
currentState = -1;
type = ACTION_DAMAGES;
}
int DamageStack::CombatDamages(){
CombatDamages(1);
CombatDamages(0);
return 1;
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;
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);
}
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;
}
for (int i = 0; i < mCount; i++){
Damage * damage = (Damage*)mObjects[i];
mHeight += damage->mHeight;
}
return mCount;
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;
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();
}
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();
}
}
+278 -278
View File
@@ -6,354 +6,354 @@
#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;
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)){
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);
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();
}
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;
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;
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);
}
}
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));
}
return 1;
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);
char buf[4096];
sprintf(buf, "starting resolve, remainingDamagesStep = %i\n", remainingDamageSteps);
OutputDebugString(buf);
#endif
if (damageStack) return 0;
if (damageStack) return 0;
#if defined (WIN32) || defined (LINUX)
sprintf(buf, "damageStack is NULL, we can resolve \n");
OutputDebugString(buf);
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;
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;
MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){
#if defined (WIN32) || defined (LINUX)
sprintf(buf, "attacker : %s \n", attacker->getName());
OutputDebugString(buf);
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;
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{
if (canStopDealDamages()) currentChoosingPlayer = game->opponent();
addDamager(defenser, selecterb);
}
return 1;
}
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;
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;
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;
}
}
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;
}
return 1;
}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);
}
}
}
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;
}
}
}
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;
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 !
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 (!carda->banding){
if (cardb->isDefenser() == carda) return 1;
return 0;
}
if (cardb->isDefenser() && cardb->isDefenser()->banding == carda->banding) 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();
}
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);
}
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);
if (!mCount) return;
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
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 (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);
}
if (buttonOk){
mFont->DrawString("Damages Assigned, Click Square to Continue", 250, 5);
}
}
+78 -78
View File
@@ -4,92 +4,92 @@
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(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;
}
}
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::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::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);
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);
}
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::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::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;
}
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);
void DamagerDamaged::Render(Player * currentPlayer){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(0.75);
CardGui::Render();
char buf[4096];
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));
}
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));
}
+95 -95
View File
@@ -2,130 +2,130 @@
#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;
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();
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);
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;
}
}
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];
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;
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;
map<MTGCard *,int,Cmp1>::iterator it;
it = cards.find(previous);
int found = 0;
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;
}
}
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;
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;
}
}
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);
}
}
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];
if (color == -1) return colors[MTG_NB_COLORS];
return colors[color];
}
+27 -27
View File
@@ -8,55 +8,55 @@
void DuelLayers::init(){
//0 Stack Layer
ActionStack * mActionStack = NEW ActionStack(0, GameObserver::GetInstance());
//0 Stack Layer
ActionStack * mActionStack = NEW ActionStack(0, GameObserver::GetInstance());
//Damage Resolver
DamageResolverLayer * mDamageResolver = NEW DamageResolverLayer(1, 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));
//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());
//2 Hand Layer
MTGGuiHand * mGuiHand = NEW MTGGuiHand(3, GameObserver::GetInstance());
//3 Game
MTGGuiPlay * play = NEW MTGGuiPlay(4, GameObserver::GetInstance());
//3 Game
MTGGuiPlay * play = NEW MTGGuiPlay(4, GameObserver::GetInstance());
Add(mActionStack);
Add(mDamageResolver);
Add(actionLayer);
Add(mGuiHand);
Add(play);
Add(mActionStack);
Add(mDamageResolver);
Add(actionLayer);
Add(mGuiHand);
Add(play);
}
ActionStack * DuelLayers::stackLayer(){
return ((ActionStack *) (objects[0]));
return ((ActionStack *) (objects[0]));
}
DamageResolverLayer * DuelLayers::combatLayer(){
return ((DamageResolverLayer *) (objects[1]));
return ((DamageResolverLayer *) (objects[1]));
}
ActionLayer * DuelLayers::actionLayer(){
return ((ActionLayer *) (objects[2]));
return ((ActionLayer *) (objects[2]));
}
MTGGuiHand * DuelLayers::handLayer(){
return ((MTGGuiHand *) (objects[3]));
return ((MTGGuiHand *) (objects[3]));
}
MTGGuiPlay * DuelLayers::playLayer(){
return ((MTGGuiPlay *) (objects[4]));
return ((MTGGuiPlay *) (objects[4]));
}
+114 -114
View File
@@ -24,20 +24,20 @@ int GameApp::HasMusic = 1;
GameState::GameState(GameApp* parent): mParent(parent)
{
mEngine = JGE::GetInstance();
mEngine = JGE::GetInstance();
}
GameApp::GameApp(): JApp()
{
mScreenShotCount = 0;
mScreenShotCount = 0;
for (int i=0; i < MAX_STATE ; i++)
mGameStates[i] = NULL;
for (int i=0; i < MAX_STATE ; i++)
mGameStates[i] = NULL;
mShowDebugInfo = false;
players[0] = 0;
players[1] = 0;
mShowDebugInfo = false;
players[0] = 0;
players[1] = 0;
@@ -53,88 +53,88 @@ GameApp::~GameApp()
void GameApp::Create()
{
#if defined (WIN32)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_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
pspfpu_set_enable(0); //disable FPU Exceptions until we find where the FPU errors come from
#endif
//_CrtSetBreakAlloc(368);
LOG("starting Game");
//_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;
}
//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("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("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->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->LoadJLBFont("graphics/f3",16);
CommonRes->LoadJLBFont("graphics/magic",16);
//CommonRes->CreateTexture("graphics/interrupt.png");
//CommonRes->CreateQuad("interrupt", "graphics/interrupt.png", 0, 0, 256, 128);
//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"));
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_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_MENU] = NEW GameStateMenu(this);
mGameStates[GAME_STATE_MENU]->Create();
mGameStates[GAME_STATE_DUEL] = NEW GameStateDuel(this);
mGameStates[GAME_STATE_DUEL]->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_SHOP] = NEW GameStateShop(this);
mGameStates[GAME_STATE_SHOP]->Create();
mGameStates[GAME_STATE_OPTIONS] = NEW GameStateOptions(this);
mGameStates[GAME_STATE_OPTIONS]->Create();
mGameStates[GAME_STATE_OPTIONS] = NEW GameStateOptions(this);
mGameStates[GAME_STATE_OPTIONS]->Create();
//mGameStates[GAME_STATE_GAME] = NEW GameStateGAME(this);
//mGameStates[GAME_STATE_GAME] = NEW GameStateGAME(this);
mCurrentState = NULL;
mNextState = mGameStates[GAME_STATE_MENU];
mCurrentState = NULL;
mNextState = mGameStates[GAME_STATE_MENU];
@@ -152,32 +152,32 @@ void GameApp::LoadGameStates()
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];
}
}
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];
}
for (int i= 0; i < 6; i++){
delete Particles[i];
}
if (collection){
collection->destroyAllCards();
delete collection;
}
if (cache) delete cache;
if (collection){
collection->destroyAllCards();
delete collection;
}
if (cache) delete cache;
if (CommonRes) delete CommonRes;
if (CommonRes) delete CommonRes;
GameOptions::Destroy();
GameOptions::Destroy();
if (Subtypes::subtypesList) delete Subtypes::subtypesList;
if (MtgSets::SetsList) delete MtgSets::SetsList;
LOG("==Destroying GameApp Successful==");
if (Subtypes::subtypesList) delete Subtypes::subtypesList;
if (MtgSets::SetsList) delete MtgSets::SetsList;
LOG("==Destroying GameApp Successful==");
}
@@ -186,38 +186,38 @@ void GameApp::Destroy()
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;
}
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;
float dt = mEngine->GetDelta();
if (dt > 35.0f) // min 30 FPS ;)
dt = 35.0f;
if (mCurrentState != NULL)
mCurrentState->Update(dt);
if (mCurrentState != NULL)
mCurrentState->Update(dt);
if (mNextState != NULL)
{
if (mCurrentState != NULL)
mCurrentState->End();
if (mNextState != NULL)
{
if (mCurrentState != NULL)
mCurrentState->End();
mCurrentState = mNextState;
mCurrentState->Start();
mCurrentState = mNextState;
mCurrentState->Start();
mNextState = NULL;
}
mNextState = NULL;
}
@@ -227,17 +227,17 @@ void GameApp::Update()
void GameApp::Render()
{
if (mCurrentState != NULL)
{
mCurrentState->Render();
}
if (mCurrentState != NULL)
{
mCurrentState->Render();
}
}
void GameApp::SetNextState(int state)
{
mNextState = mGameStates[state];
mNextState = mGameStates[state];
}
void GameApp::Pause(){
+9 -9
View File
@@ -16,15 +16,15 @@
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();
public:
GameApp();
virtual ~GameApp();
virtual void Create();
virtual void Destroy();
virtual void Update();
virtual void Render();
virtual void Pause();
virtual void Resume();
};
+3 -3
View File
@@ -17,20 +17,20 @@
//-------------------------------------------------------------------------------------
JApp* JGameLauncher::GetGameApp()
{
return NEW GameApp();
return NEW GameApp();
};
//-------------------------------------------------------------------------------------
char *JGameLauncher::GetName()
{
return strdup("Wagic");
return strdup("Wagic");
}
//-------------------------------------------------------------------------------------
u32 JGameLauncher::GetInitFlags()
{
return JINIT_FLAG_NORMAL;
return JINIT_FLAG_NORMAL;
}
+284 -284
View File
@@ -15,19 +15,19 @@ GameObserver * GameObserver::mInstance = NULL;
GameObserver* GameObserver::GetInstance()
{
return mInstance;
return mInstance;
}
void GameObserver::EndInstance()
{
SAFE_DELETE(mInstance);
SAFE_DELETE(mInstance);
}
void GameObserver::Init(Player * _players[], int _nbplayers){
mInstance = NEW GameObserver(_players, _nbplayers);
mInstance->mLayers = NEW DuelLayers();
mInstance->mLayers->init();
mInstance = NEW GameObserver(_players, _nbplayers);
mInstance->mLayers = NEW DuelLayers();
mInstance->mLayers->init();
}
@@ -38,17 +38,17 @@ GameObserver::GameObserver(Player * _players[], int _nb_players){
players[i] = _players[i];
}
currentPlayer = players[0];
currentActionPlayer = currentPlayer;
isInterrupting = NULL;
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);
targetChooser = NULL;
cardWaitingForTargets = NULL;
reaction = 0;
gameOver = NULL;
phaseRing = NEW PhaseRing(_players,_nb_players);
}
void GameObserver::setGamePhaseManager(MTGGamePhase * _phases){
@@ -61,83 +61,83 @@ int GameObserver::getCurrentGamePhase(){
Player * GameObserver::opponent(){
int index = (currentPlayerId+1)%nbPlayers;
return players[index];
int index = (currentPlayerId+1)%nbPlayers;
return players[index];
}
int GameObserver::enteringPhase(int phase){
//TODO
return 0;
//TODO
return 0;
}
void GameObserver::nextPlayer(){
currentPlayerId = (currentPlayerId+1)%nbPlayers;
currentPlayer = players[currentPlayerId];
currentActionPlayer = currentPlayer;
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();
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();
}
//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();
}
//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;
}
//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;
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();
}
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();
}
}
@@ -147,8 +147,8 @@ void GameObserver::startGame(int shuffle, int draw){
for (i=0; i<nbPlayers; i++){
players[i]->game->initGame(shuffle, draw);
}
phaseRing->goToPhase(MTG_PHASE_FIRSTMAIN, players[0]);
currentGamePhase = MTG_PHASE_FIRSTMAIN;
phaseRing->goToPhase(MTG_PHASE_FIRSTMAIN, players[0]);
currentGamePhase = MTG_PHASE_FIRSTMAIN;
}
void GameObserver::addObserver(MTGAbility * observer){
@@ -157,62 +157,62 @@ void GameObserver::addObserver(MTGAbility * observer){
void GameObserver::removeObserver(ActionElement * observer){
if (observer){
observer->destroy();
}else{
//TODO log error
}
mLayers->actionLayer()->Remove(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==");
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;
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++){
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];
}
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));
}
mLayers->Render();
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()){
JRenderer::GetInstance()->DrawRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(255,255,0,0));
}
}
@@ -225,202 +225,202 @@ 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");
OutputDebugString("Click\n");
#endif
cardClick(NULL, ((GuiAvatar *)_object)->player);
}
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 (targetChooser != NULL){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser ok \n");
OutputDebugString("target chooser ok \n");
#endif
int result = targetChooser->toggleTarget(action);
if (result == TARGET_OK_FULL){
int result = targetChooser->toggleTarget(action);
if (result == TARGET_OK_FULL){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser Full \n");
OutputDebugString("target chooser Full \n");
#endif
cardClick(cardWaitingForTargets);
}else{
return;
}
}else{
reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(action);
}
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("==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;
}
}
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 (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);
}
}
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;
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)){
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");
LOG("CANPUTINPLAY- Targets chosen -> OK\n");
#endif
return 1;
}else{
return 1;
}else{
#ifdef LOG
LOG("CANPUTINPLAY- Targets not chosen yet\n");
LOG("CANPUTINPLAY- Targets not chosen yet\n");
#endif
return 0;
}
}
}
return 0;
}
}
}
return 0;
}
void GameObserver::putInPlay(MTGCardInstance * card){
Player * player = currentlyActing();
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
player->getManaPool()->pay(card->getManaCost());
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);
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;
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();
//TODO checks to allow multiple draw, or no draw, etc...
currentPlayer->game->drawFromLibrary();
}
void GameObserver::cleanupPhase(){
currentPlayer->cleanupPhase();
opponent()->cleanupPhase();
currentPlayer->cleanupPhase();
opponent()->cleanupPhase();
}
void GameObserver::untapPhase(){
currentPlayer->inPlay()->untapAll();
currentPlayer->inPlay()->untapAll();
}
@@ -430,44 +430,44 @@ int GameObserver::isACreature(MTGCardInstance * card){
Player * GameObserver::currentlyActing(){
if (isInterrupting) return isInterrupting;
return currentActionPlayer;
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;
}
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());
if (targetChooser == NULL){
TargetChooserFactory tcf;
targetChooser = tcf.createTargetChooser(card);
cardWaitingForTargets = card;
if (targetChooser == NULL){
return 1;
}
}
return (targetChooser->targetListSet());
}
+34 -34
View File
@@ -8,45 +8,45 @@
GameOptions* GameOptions::mInstance = NULL;
GameOptions * GameOptions::GetInstance(){
if (mInstance == NULL)
mInstance = NEW GameOptions();
return mInstance;
if (mInstance == NULL)
mInstance = NEW GameOptions();
return mInstance;
}
GameOptions::GameOptions(){
for(int i = 0; i < MAX_OPTIONS; i++){
values[i] = 0;
}
load();
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;
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;
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;
}
@@ -54,8 +54,8 @@ GameOptions::~GameOptions(){
}
void GameOptions::Destroy(){
if (mInstance){
delete mInstance;
mInstance = NULL;
}
if (mInstance){
delete mInstance;
mInstance = NULL;
}
}
+209 -209
View File
@@ -5,74 +5,74 @@
#include "../include/PlayerData.h"
#ifdef TESTSUITE
#include "../include/TestSuiteAI.h"
#include "../include/TestSuiteAI.h"
#endif
GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) {
for (int i = 0; i<2; i ++){
deck[i]=NULL;
mPlayers[i]=NULL;
}
for (int i = 0; i<2; i ++){
deck[i]=NULL;
mPlayers[i]=NULL;
}
game = NULL;
deckmenu = NULL;
menu = NULL;
game = NULL;
deckmenu = NULL;
menu = NULL;
#ifdef TESTSUITE
testSuite = NULL;
testSuite = NULL;
#endif
}
GameStateDuel::~GameStateDuel() {
End();
End();
}
void GameStateDuel::Start()
{
JRenderer * renderer = JRenderer::GetInstance();
JRenderer * renderer = JRenderer::GetInstance();
renderer->ResetPrivateVRAM();
renderer->EnableVSync(true);
#ifdef TESTSUITE
if (testSuite) delete testSuite;
testSuite = NEW TestSuite("Res/test/_tests.txt");
if (testSuite) delete testSuite;
testSuite = NEW TestSuite("Res/test/_tests.txt");
#endif
mGamePhase = DUEL_CHOOSE_DECK1;
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
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");
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;
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;
}
}
}
}
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;
if (decksneeded)
mGamePhase = ERROR_NO_DECK;
@@ -80,152 +80,152 @@ testSuite = NEW TestSuite("Res/test/_tests.txt");
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;
}
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;
}
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");
}
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");
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);
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);
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);
}
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;
}
}
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(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{
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){
}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);
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;
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);
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite->loadNext()){
loadTestSuitePlayers();
mGamePhase = DUEL_PLAY;
testSuite->initGame();
}else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
mParent->SetNextState(GAME_STATE_MENU);
}
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);
}
}
}
@@ -237,64 +237,64 @@ void GameStateDuel::Render()
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();
}
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;
}
{
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;
}
}
+62 -62
View File
@@ -6,8 +6,8 @@
#include "../include/GameOptions.h"
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) {
optionsList = NULL;
optionsMenu = NULL;
optionsList = NULL;
optionsMenu = NULL;
}
@@ -17,39 +17,39 @@ GameStateOptions::~GameStateOptions() {
void GameStateOptions::Start()
{
mState = SHOW_OPTIONS;
mState = SHOW_OPTIONS;
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
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");
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);
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;
}
if (mState == SHOW_OPTIONS){
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mState = SHOW_OPTIONS_MENU;
}
optionsList->Update(dt);
}else{
optionsMenu->Update(dt);
}
optionsList->Update(dt);
}else{
optionsMenu->Update(dt);
}
}
@@ -59,60 +59,60 @@ void GameStateOptions::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
optionsList->Render();
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 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"
};
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);
}
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 (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();
}
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;
}
{
switch (controlId){
case 1:
optionsList->save();
case 2:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 3:
mState = SHOW_OPTIONS;
break;
}
};
+73 -73
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,54 +24,54 @@ 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);
}
@@ -80,21 +80,21 @@ 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);
}
}
@@ -102,30 +102,30 @@ 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;
}
}
+30 -30
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),
@@ -58,7 +58,7 @@ void GuiLayer::RenderMessageBackground(float x0, float y0, float width, int heig
}
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();
}
}
+47 -47
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 (mEngine->GetButtonState(PSP_CTRL_LEFT) || mEngine->GetButtonState(PSP_CTRL_UP) || mEngine->GetAnalogY()<64)
{
if (KeyRepeated(PSP_CTRL_UP, dt))
{
if (KeyRepeated(PSP_CTRL_UP, dt))
{
int n = mCurr;
n--;
if (n<0)
{
if ((mStyle&JGUI_STYLE_WRAPPING))
n = mCount-1;
else
n = 0;
}
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();
}
}
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)
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT) || mEngine->GetButtonState(PSP_CTRL_DOWN) || mEngine->GetAnalogY()>192)
{
if (KeyRepeated(PSP_CTRL_DOWN, 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>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();
}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
}
else
mLastKey = 0;
}
else
mLastKey = 0;
}
+9 -9
View File
@@ -5,19 +5,19 @@
using namespace std;
#if defined (WIN32)
#include <windows.h>
#include <windows.h>
#endif
void Logger::Log(char * text){
ofstream file (LOG_FILE,ios_base::app);
if (file){
file << text;
file << "\n";
file.close();
}
ofstream file (LOG_FILE,ios_base::app);
if (file){
file << text;
file << "\n";
file.close();
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString(text);
OutputDebugString("\n");
OutputDebugString(text);
OutputDebugString("\n");
#endif
}
File diff suppressed because it is too large Load Diff
+100 -100
View File
@@ -24,59 +24,59 @@ MTGCard::MTGCard(){
MTGCard::MTGCard(TexturesCache * cache, int set_id){
init();
mCache = cache;
setId = set_id;
setId = set_id;
}
const char * MTGCard::getSetName(){
return MtgSets::SetsList->values[setId].c_str();
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());
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;
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;
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;
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){
@@ -103,42 +103,42 @@ int MTGCard::isACreature(){
}
void MTGCard::setColor(int _color, int removeAllOthers){
if (removeAllOthers){
for (int i=0; i<MTG_NB_COLORS; i++){
colors[i] = 0;
}
}
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 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]);
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);
}
}
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();
int color = getColor();
if (color>=0 && color <=5){
return Colors_To_Text[color];
}
@@ -159,7 +159,7 @@ int MTGCard::getId(){
}
char MTGCard::getRarity(){
return rarity;
return rarity;
}
void MTGCard::setRarity(char _rarity){
@@ -167,27 +167,27 @@ void MTGCard::setRarity(char _rarity){
}
void MTGCard::setType(const char * _type_text){
setSubtype(_type_text);
setSubtype(_type_text);
}
void MTGCard::addType(char * _type_text){
setSubtype(_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 = "";
}
}
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){
@@ -200,20 +200,20 @@ void MTGCard::addType(int id){
//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 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;
}
}
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;
}
@@ -224,7 +224,7 @@ char * MTGCard::getImageName(){
void MTGCard::setText( string value){
text = value;
text = value;
}
const char * MTGCard::getText(){
@@ -232,13 +232,13 @@ const char * MTGCard::getText(){
}
void MTGCard::addMagicText(string value){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
if (magicText.size()) magicText.append("\n");
magicText.append(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;
name = value;
}
const char * MTGCard::getName(){
@@ -266,28 +266,28 @@ int MTGCard::hasType(int _type){
}
int MTGCard::hasSubtype(int _subtype){
return(hasType(_subtype));
return(hasType(_subtype));
}
int MTGCard::hasType(const char * _type){
int id = Subtypes::subtypesList->Add(_type);
return(hasType(id));
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 id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id));
}
int MTGCard::hasSubtype(string _subtype){
int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id));
int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id));
}
int MTGCard::has(int basicAbility){
return basicAbilities[basicAbility];
return basicAbilities[basicAbility];
}
//---------------------------------------------
@@ -298,7 +298,7 @@ void MTGCard::setPower(int _power){
}
int MTGCard::getPower(){
return power;
return power;
}
void MTGCard::setToughness(int _toughness){
@@ -306,5 +306,5 @@ void MTGCard::setToughness(int _toughness){
}
int MTGCard::getToughness(){
return toughness;
return toughness;
}
+248 -248
View File
@@ -1,8 +1,8 @@
/*---------------------------------------------
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
--------------------------------------------
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"
@@ -10,101 +10,101 @@ Although there is only one MTGCard of each type, there can be as much Instances
#include "../include/Counters.h"
MTGCardInstance::MTGCardInstance(): MTGCard(), Damageable(0){
LOG("==Creating MTGCardInstance==");
initMTGCI();
LOG("==Creating MTGCardInstance Successful==");
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;
LOG("==Creating MTGCardInstance==");
initMTGCI();
model = card;
lifeOrig = life;
belongs_to=_belongs_to;
initAttackersDefensers();
life=toughness;
LOG("==Creating MTGCardInstance Successful==");
initAttackersDefensers();
life=toughness;
LOG("==Creating MTGCardInstance Successful==");
}
MTGCardInstance::~MTGCardInstance(){
LOG("==Deleting MTGCardInstance==");
SAFE_DELETE(blockers);
SAFE_DELETE(counters);
LOG("==Deleting MTGCardInstance Succesfull==");
LOG("==Deleting MTGCardInstance==");
SAFE_DELETE(blockers);
SAFE_DELETE(counters);
LOG("==Deleting MTGCardInstance Succesfull==");
}
void MTGCardInstance::initMTGCI(){
model=NULL;
lifeOrig = 0;
doDamageTest = 0;
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);
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++;
types[nb_types] = type;
nb_types++;
}
Blockers * MTGCardInstance::getBlockers(){
return blockers;
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;
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);
#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;
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;
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();
return getThumb();
}
int MTGCardInstance::has(int basicAbility){
return basicAbilities[basicAbility];
return basicAbilities[basicAbility];
}
@@ -117,54 +117,54 @@ void MTGCardInstance::tap(){
}
void MTGCardInstance::setUntapping(){
untapping = 1;
untapping = 1;
}
int MTGCardInstance::isUntapping(){
return untapping;
return untapping;
}
//Untaps the card
void MTGCardInstance::untap(){
if (untapping){
tapped = 0;
untapping = 0;
}
if (untapping){
tapped = 0;
untapping = 0;
}
}
//Tells if the card is tapped or not
int MTGCardInstance::isTapped(){
return tapped;
return tapped;
}
void MTGCardInstance::resetAllDamage(){
//for (int i=0;i<nb_damages;i++){
// delete damages[i];
// delete damages[i];
//}
nb_damages = 0;
}
void MTGCardInstance::regenerate(){
tapped = 1;
life = toughness;
initAttackersDefensers();
tapped = 1;
life = toughness;
initAttackersDefensers();
}
int MTGCardInstance::initAttackersDefensers(){
attacker = 0;
defenser = NULL;
banding = NULL;
return 1;
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;
initAttackersDefensers();
life=toughness;
GameObserver * game = GameObserver::GetInstance();
if (!game || game->currentPlayer == controller()) summoningSickness = 0;
return 1;
}
/* Summoning Sickness
@@ -175,233 +175,233 @@ int MTGCardInstance::cleanup(){
* sicknessh 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;
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;
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;
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;
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;
if (!hasSummoningSickness() && !tapped && isACreature() && basicAbilities[DEFENSER] !=1)
return 1;
return 0;
}
int MTGCardInstance::addToToughness(int value){
toughness+=value;
life+=value;
doDamageTest = 1;
return 1;
toughness+=value;
life+=value;
doDamageTest = 1;
return 1;
}
int MTGCardInstance::setToughness(int value){
toughness=value;
life=value;
doDamageTest = 1;
return 1;
toughness=value;
life=value;
doDamageTest = 1;
return 1;
}
int MTGCardInstance::canBlock(){
if (!tapped && isACreature())return 1;
return 0;
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;
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;
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;
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);
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;
}
return ;
}
}
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;
//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;
return attacker;
}
MTGCardInstance * MTGCardInstance::isDefenser(){
return defenser;
return defenser;
}
int MTGCardInstance::nbOpponents(){
int result= 0;
MTGCardInstance* opponent = getNextOpponent();
while (opponent){
result++;
opponent = getNextOpponent(opponent);
}
return result;
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;
}
}
}
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;
}
return NULL;
}
}
}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;
if (canBlock()){
if (canBlock(opponent)){
defenser = opponent;
return 1;
}
}
return 0;
}
int MTGCardInstance::addProtection(CardDescriptor * cd){
protections[nbprotections] = cd;
nbprotections++;
return nbprotections;
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;
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;
for (int i = 0; i < nbprotections ; i++){
if (protections[i]->match(card)) return 1;
}
return 0;
}
+156 -156
View File
@@ -20,45 +20,45 @@ MtgSets * MtgSets::SetsList = NEW MtgSets();
MtgSets::MtgSets(){
nb_items = 0;
nb_items = 0;
}
int MtgSets::Add(const char * name){
string value = name;
values[nb_items] = value;
nb_items++;
return nb_items - 1;
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);
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);
}
card->addMagicText(value);
}
else if(key.compare( "alias")==0){
card->alias=atoi(value.c_str());
}
card->alias=atoi(value.c_str());
}
else if(key.compare( "target")==0){
std::transform( value.begin(), value.end(), value.begin(),::tolower );
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("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){
@@ -66,7 +66,7 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
}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 );
std::transform( value.begin(), value.end(), value.begin(),::tolower );
card->setManaCost(value);
}else if(key.compare("type")==0){
switch(value.c_str()[0]){
@@ -75,9 +75,9 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
break;
case 'A':
card->setType( "Artifact");
card->setColor(MTG_COLOR_ARTIFACT);
if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C')
card->setSubtype("Creature");
card->setColor(MTG_COLOR_ARTIFACT);
if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C')
card->setSubtype("Creature");
break;
case 'E':
card->setType( "Enchantment");
@@ -86,11 +86,11 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
card->setType( "Sorcery");
break;
case 'B'://Basic Land
card->setColor(MTG_COLOR_LAND);
card->setColor(MTG_COLOR_LAND);
card->setType("Land");
break;
case 'L':
card->setColor(MTG_COLOR_LAND);
card->setColor(MTG_COLOR_LAND);
card->setType( "Land");
break;
case 'I':
@@ -108,7 +108,7 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
}else if(key.compare("toughness")==0){
card->setToughness(atoi(value.c_str()));
}else{
}
}
return i;
@@ -116,45 +116,45 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
}
void MTGAllCards::initCounters(){
for (int i=0; i< MTG_NB_COLORS; i++){
colorsCount[i] = NULL;
}
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
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;
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;
int set_id = MtgSets::SetsList->Add(set_name);
if (autoload){
while(readConfLine(set_id)){};
}
return total_cards;
}
MTGAllCards::MTGAllCards(){
init();
init();
}
MTGAllCards::~MTGAllCards(){
}
void MTGAllCards::destroyAllCards(){
for (int i= 0; i < total_cards; i++){
delete collection[i];
};
for (int i= 0; i < total_cards; i++){
delete collection[i];
};
}
@@ -163,64 +163,64 @@ MTGAllCards::MTGAllCards(const char * config_file, const char * set_name){
}
MTGAllCards::MTGAllCards(TexturesCache * cache){
init();
mCache = 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);
init();
mCache = cache;
load(config_file,set_name, 0);
}
MTGCard * MTGAllCards::_(int i){
if (i < total_cards) return collection[i];
return NULL;
return NULL;
}
int MTGAllCards::randomCardId(){
int id = (rand() % total_cards);
return collection[id]->getMTGId();
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;
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 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();
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];
colorsCount[j]++;
}
}
return colorsCount[color];
}
int MTGAllCards::totalCards(){
@@ -274,20 +274,20 @@ MTGCard * MTGAllCards::getCardById(int id){
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);
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
}
if(file){
while(std::getline(file,s)){
int cardnb = atoi(s.c_str());
if (cardnb) add(cardnb);
}
file.close();
}else{
//TODO Error management
}
}
@@ -295,91 +295,91 @@ MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards *
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 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 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;
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;
if (!card) return 0;
collection[total_cards] = card;
++total_cards;
initCounters();
return total_cards;
}
int MTGDeck::removeAll(){
total_cards = 0;
initCounters();
return 1;
total_cards = 0;
initCounters();
return 1;
}
int MTGDeck::remove(int cardid){
MTGCard * card = getCardById(cardid);
return remove(card);
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;
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){
std::ofstream file(filename.c_str());
char writer[10];
if (file){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("saving");
OutputDebugString("saving");
#endif
for (int i = 0; i<total_cards; i++){
sprintf(writer,"%i\n", collection[i]->getMTGId());
file<<writer;
}
file.close();
}
for (int i = 0; i<total_cards; i++){
sprintf(writer,"%i\n", collection[i]->getMTGId());
file<<writer;
}
file.close();
}
return 1;
return 1;
}
+21 -21
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();
}
}
}
+113 -113
View File
@@ -17,34 +17,34 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi
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);
}
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;
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);
library->setOwner(player);
}
void MTGPlayerCards::initGame(int shuffle, int draw){
if (shuffle) library->shuffle();
if (draw){
for (int i=0;i<7;i++){
drawFromLibrary();
}
}
if (draw){
for (int i=0;i<7;i++){
drawFromLibrary();
}
}
}
void MTGPlayerCards::drawFromLibrary(){
@@ -57,7 +57,7 @@ void MTGPlayerCards::init(){
graveyard = NEW MTGGraveyard();
hand = NEW MTGHand();
inPlay = NEW MTGInPlay();
stack = NEW MTGStack();
stack = NEW MTGStack();
}
@@ -68,39 +68,39 @@ void MTGPlayerCards::showHand(){
void MTGPlayerCards::putInPlay(MTGCardInstance * card){
hand->removeCard(card);
stack->removeCard(card); //Which one is it ???
stack->removeCard(card); //Which one is it ???
inPlay->addCard(card);
card->summoningSickness = 1;
card->changedZoneRecently = 1.f;
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);
}
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();
//}
}
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);
if (!from->nb_cards)
return;
int r = rand() % (from->nb_cards);
putInZone(from->cards[r],from, graveyard);
}
int MTGPlayerCards::isInPlay(MTGCardInstance * card){
@@ -116,25 +116,25 @@ int MTGPlayerCards::isInPlay(MTGCardInstance * card){
MTGGameZone::MTGGameZone(){
nb_cards= 0;
lastCardDrawn = NULL;
lastCardDrawn = NULL;
}
MTGGameZone::~MTGGameZone(){
for (int i=0; i<nb_cards; i++) {
delete cards[i];
}
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;
cards[i]->owner = player;
}
owner = player;
owner = player;
}
MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
int i;
cardsMap.erase(card);
cardsMap.erase(card);
for (i=0; i<(nb_cards); i++) {
if (cards[i] == card){
cards[i] = cards[nb_cards -1];
@@ -147,7 +147,7 @@ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
}
MTGCardInstance * MTGGameZone::hasCard(MTGCardInstance * card){
if (cardsMap.find(card) != cardsMap.end()) return card;
if (cardsMap.find(card) != cardsMap.end()) return card;
return NULL;
}
@@ -174,8 +174,8 @@ int MTGGameZone::hasType(const char * value){
void MTGGameZone::cleanupPhase(){
for (int i=0; i<(nb_cards); i++)
(cards[i])->cleanup();
for (int i=0; i<(nb_cards); i++)
(cards[i])->cleanup();
}
void MTGGameZone::shuffle(){
@@ -184,32 +184,32 @@ void MTGGameZone::shuffle(){
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
srand(time(0)); // initialize seed "randomly" TODO :improve
}
void MTGGameZone::addCard(MTGCardInstance * card){
if (!card) return;
if (!card) return;
cards[nb_cards] = card;
nb_cards++;
cardsMap[card] = 1;
cardsMap[card] = 1;
}
MTGCardInstance * MTGGameZone::draw(){
if (!nb_cards) return NULL;
if (!nb_cards) return NULL;
nb_cards--;
lastCardDrawn = cards[nb_cards];
cardsMap.erase(cards[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();
if (!nb_cards) {
GameObserver::GetInstance()->gameOver = this->owner;
}
return MTGGameZone::draw();
}
void MTGGameZone::debugPrint(){
@@ -226,89 +226,89 @@ void MTGGameZone::debugPrint(){
//------------------------------
int MTGInPlay::nbDefensers( MTGCardInstance * attacker){
int result = 0;
MTGCardInstance * defenser = getNextDefenser(NULL, attacker);
while (defenser){
result++;
defenser = getNextDefenser(defenser, attacker);
}
return result;
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;
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;
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;
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 (cards[i]->getBlockers()->isEmpty()){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "Can untap %s\n", cards[i]->getName());
OutputDebugString(buf);
char buf[4096];
sprintf(buf, "Can untap %s\n", cards[i]->getName());
OutputDebugString(buf);
#endif
cards[i]->untap();
}
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++) {
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];
}
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];
}
}
+28 -28
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;
}
@@ -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);
}
}
}
+283 -283
View File
@@ -1,5 +1,5 @@
/* This class handles the display on the main game screen :
cards in play, graveyard, library, games phases, Players avatars
cards in play, graveyard, library, games phases, Players avatars
*/
#include "../include/debug.h"
@@ -23,213 +23,213 @@ cards in play, graveyard, library, games phases, Players avatars
MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPlayer = NULL;
offset = 0;
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);
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);
}
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);
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();
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;
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;
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;
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;
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++;
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);
}
}
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);
}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;
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);
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;
}
MTGCardInstance * attackers[MAX_ATTACKERS];
for (int i = 0; i <MAX_ATTACKERS; i++){
attackers[i] = NULL;
}
offset = 6;
offset = 6;
Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards;
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;
resetObjects();
AddPlayersGuiInfo();
offset = mCount;
bool hasFocus = player0Mode;
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;
}
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;
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);
}
}
}
//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<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);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setTargettingCardPosition(cardGui, 1, !player0Mode);
}
@@ -237,36 +237,36 @@ void MTGGuiPlay::updateCards(){
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]));
//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(-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]));
}
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();
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;
}
}
for (int i = 2; i<6;i++){
GuiGameZone * zone = (GuiGameZone *)mObjects[i];
if (zone->showCards){
zone->cd->CheckUserInput(dt);
return;
}
}
PlayGuiObjectController::CheckUserInput(dt);
@@ -274,132 +274,132 @@ void MTGGuiPlay::CheckUserInput(float dt){
void MTGGuiPlay::RenderPlayerInfo(int playerid){
GameObserver * game = GameObserver::GetInstance();
JRenderer * r = JRenderer::GetInstance();
Player * player = GameObserver::GetInstance()->players[playerid];
int life = player->life;
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();
//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++;
}
}
//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);
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();
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);
//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;
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]));
}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);
renderer->RenderQuad(mBg,0,0);
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
}
RenderPhaseBar();
RenderPlayerInfo(0);
RenderPlayerInfo(1);
RenderPhaseBar();
RenderPlayerInfo(0);
RenderPlayerInfo(1);
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (hasFocus && mCurr >= offset && showBigCards)
((CardGui *)mObjects[mCurr])->RenderBig();
}
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;
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;
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);
SAFE_DELETE(mBg2);
SAFE_DELETE(mBgTex2);
LOG("==Destroying MTGGuiPlay Successful==");
LOG("==Destroying MTGGuiPlay Successful==");
}
+29 -29
View File
@@ -5,22 +5,22 @@ 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;
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;
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;
return 0;
}
@@ -29,32 +29,32 @@ 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;
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();
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;
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;
return 0;
}
+117 -117
View File
@@ -5,20 +5,20 @@
#if defined (WIN32)
#include <windows.h>
#include <windows.h>
#endif
ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
char buf[4096];
#endif
ManaCost * manaCost;
if (_manaCost){
manaCost = _manaCost;
}else{
manaCost = NEW ManaCost();
}
int state = 0;
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){
@@ -26,15 +26,15 @@ char buf[4096];
case 0:
start = s.find_first_of("{");
if (start == string::npos){
return manaCost;
return manaCost;
}else{
state = 1;
state = 1;
}
break;
case 1:
end = s.find_first_of("}");
if (end == string::npos){
state = -1;
state = -1;
}else{
string value = s.substr(start+1, end - 1 - start);
if (value == "u"){
@@ -52,30 +52,30 @@ char buf[4096];
}else if (value == "t"){
}else{
int intvalue = atoi(value.c_str());
int colors[2];
int values[2];
if (!intvalue && value.size() > 1){
int colors[2];
int values[2];
if (!intvalue && value.size() > 1){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Hybrid Mana ???\n");
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);
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;
@@ -85,7 +85,7 @@ OutputDebugString("Hybrid Mana ???\n");
break;
}
}
return manaCost;
return manaCost;
}
ManaCost::ManaCost(){
@@ -96,9 +96,9 @@ ManaCost::ManaCost(int _cost[], int nb_elems){
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);
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];
@@ -115,14 +115,14 @@ ManaCost::ManaCost(ManaCost * _manaCost){
}
ManaCost::~ManaCost(){
LOG("==Deleting ManaCost==");
for (int i = 0; i < nbhybrids ; i++){
SAFE_DELETE(hybrids[i]);
}
LOG("==Deleting ManaCost==");
for (int i = 0; i < nbhybrids ; i++){
SAFE_DELETE(hybrids[i]);
}
}
void ManaCost::x(){
cost[MTG_NB_COLORS] = 1;
cost[MTG_NB_COLORS] = 1;
}
void ManaCost::init(){
@@ -130,7 +130,7 @@ void ManaCost::init(){
for (i=0; i<= MTG_NB_COLORS; i++){
cost[i] = 0;
}
nbhybrids = 0;
nbhybrids = 0;
}
@@ -141,7 +141,7 @@ void ManaCost::copy(ManaCost * _manaCost){
for (int i=0; i< _manaCost->nbhybrids; i++){
hybrids[i] = NEW ManaCostHybrid((*_manaCost->hybrids[i]));
}
nbhybrids = _manaCost->nbhybrids;
nbhybrids = _manaCost->nbhybrids;
}
int ManaCost::getCost(int color){
@@ -152,31 +152,31 @@ int ManaCost::getMainColor(){
for (int i=0; i< MTG_NB_COLORS; i++){
if (cost[i]) return i;
}
return 0;
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;
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 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;
cost[color] -= value;
return 1;
}
int ManaCost::add(int color, int value){
@@ -185,14 +185,14 @@ int ManaCost::add(int color, int value){
}
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++;
for (int i=0; i< MTG_NB_COLORS; i++){
cost[i]+= _cost->getCost(i);
}
return 1;
for (int i=0; i< _cost->nbhybrids; i++){
hybrids[nbhybrids] = NEW ManaCostHybrid((*_cost->hybrids[i]));
nbhybrids++;
}
return 1;
}
string ManaCost::toString(){
@@ -201,30 +201,30 @@ string ManaCost::toString(){
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;
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!
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;
delete diff;
if (positive){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("can afford\n");
OutputDebugString("can afford\n");
#endif
return 1;
}
@@ -244,50 +244,50 @@ int ManaCost::isPositive(){
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 _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;
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;
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);
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");
//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){
@@ -303,16 +303,16 @@ OutputDebugString("Colorless mana not enough\n");
}
}
//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;
}
}
}
//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;
+10 -10
View File
@@ -1,26 +1,26 @@
#include "../include/ManaCostHybrid.h"
ManaCostHybrid::ManaCostHybrid(){
init(0,0,0,0);
init(0,0,0,0);
}
ManaCostHybrid::ManaCostHybrid(int c1,int v1,int c2,int v2){
init(c1,v1,c2,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;
color1 = c1;
color2 = c2;
value1 = v1;
value2 = v2;
}
int ManaCostHybrid::getConvertedCost(){
if (value2 > value1) return value2;
return value1;
if (value2 > value1) return value2;
return value1;
}
int ManaCostHybrid::hasColor(int color){
if (((color1 == color) && value1) || ((color2 == color) && value2)) return 1;
return 0;
if (((color1 == color) && value1) || ((color2 == color) && value2)) return 1;
return 0;
}
+60 -60
View File
@@ -7,22 +7,22 @@ MenuItem::MenuItem(int id, JLBFont *font, const char* text, int x, int y, JQuad
updatedSinceLastRender = 1;
mParticleSys = NEW hgeParticleSystem(particle, particleTex);
mParticleSys->MoveTo(mX, mY);
updatedSinceLastRender = 1;
mParticleSys = NEW hgeParticleSystem(particle, particleTex);
mParticleSys->MoveTo(mX, mY);
mHasFocus = hasFocus;
lastDt = 0.001f;
mScale = 1.0f;
mTargetScale = 1.0f;
mHasFocus = hasFocus;
lastDt = 0.001f;
mScale = 1.0f;
mTargetScale = 1.0f;
onQuad = _on;
offQuad = _off;
onQuad = _on;
offQuad = _off;
if (hasFocus)
Entering();
mFont->SetScale(1.2f);
if (hasFocus)
Entering();
mFont->SetScale(1.2f);
}
@@ -30,54 +30,54 @@ MenuItem::MenuItem(int id, JLBFont *font, const char* text, int x, int y, JQuad
void MenuItem::Render()
{
JRenderer * renderer = JRenderer::GetInstance();
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);
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;
}
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;
}
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);
}
mParticleSys->Update(dt);
}
}
@@ -87,27 +87,27 @@ void MenuItem::Update(float dt)
void MenuItem::Entering()
{
mParticleSys->Fire();
mHasFocus = true;
mTargetScale = 1.3f;
mParticleSys->Fire();
mHasFocus = true;
mTargetScale = 1.3f;
}
bool MenuItem::Leaving(u32 key)
{
mParticleSys->Stop(true);
mHasFocus = false;
mTargetScale = 1.0f;
return true;
mParticleSys->Stop(true);
mHasFocus = false;
mTargetScale = 1.0f;
return true;
}
bool MenuItem::ButtonPressed()
{
return true;
return true;
}
MenuItem::~MenuItem(){
if (mParticleSys) delete mParticleSys;
if (mParticleSys) delete mParticleSys;
}
+113 -113
View File
@@ -4,117 +4,117 @@
#include "../include/GameOptions.h"
OptionItem::OptionItem(int _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){
id = _id;
maxValue = _maxValue;
increment = _increment;
displayValue = _displayValue;
value = GameOptions::GetInstance()->values[id];
hasFocus = 0;
x = 0;
y = 0;
}
OptionItem::~OptionItem(){
//TODO
}
void OptionItem::setData(){
GameOptions::GetInstance()->values[id] = value;
}
void OptionItem::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
if (hasFocus){
mFont->SetColor(ARGB(255,255,255,0));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
JRenderer * renderer = JRenderer::GetInstance();
mFont->DrawString(displayValue.c_str(),x,y);
char buf[512];
sprintf(buf, "%i", value);
mFont->DrawString(buf,SCREEN_WIDTH -10 ,y,JGETEXT_RIGHT);
}
void OptionItem::Update(float dt){
JGE * mEngine = JGE::GetInstance();
if (hasFocus){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue();
}
}
void OptionItem::Entering(){
hasFocus = true;
}
bool OptionItem::Leaving(){
hasFocus = false;
return true;
}
OptionItem * options[20];
int nbitems;
OptionsList::OptionsList(){
nbitems = 0;
current = -1;
}
OptionsList::~OptionsList(){
for (int i = 0 ; i < nbitems; i++){
SAFE_DELETE(options[i]);
}
}
void OptionsList::Add(OptionItem * item){
if (nbitems < 20){
options[nbitems] = item;
item->x = 10;
item->y = 20 + 30*nbitems;
nbitems++;
if (current < 0){
current = 0;
options[0]->Entering();
}
}
}
void OptionsList::Render(){
if (!nbitems){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->DrawString("NO OPTIONS AVAILABLE",SCREEN_WIDTH/2, 5, JGETEXT_RIGHT);
}
for (int i = 0 ; i < nbitems; i++){
options[i]->Render();
}
}
void OptionsList::save(){
for (int i = 0; i < nbitems; i++){
options[i]->setData();
}
GameOptions::GetInstance()->save();
}
void OptionsList::Update(float dt){
JGE * mEngine = JGE::GetInstance();
if (mEngine->GetButtonClick(PSP_CTRL_UP))
{
if (current > 0){
options[current]->Leaving();
current--;
options[current]->Entering();
}
}
else if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
{
if (current < nbitems -1){
options[current]->Leaving();
current++;
options[current]->Entering();
}
}
for (int i = 0 ; i < nbitems; i++){
options[i]->Update(dt);
}
OptionItem::OptionItem(int _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){
id = _id;
maxValue = _maxValue;
increment = _increment;
displayValue = _displayValue;
value = GameOptions::GetInstance()->values[id];
hasFocus = 0;
x = 0;
y = 0;
}
OptionItem::~OptionItem(){
//TODO
}
void OptionItem::setData(){
GameOptions::GetInstance()->values[id] = value;
}
void OptionItem::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
if (hasFocus){
mFont->SetColor(ARGB(255,255,255,0));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
JRenderer * renderer = JRenderer::GetInstance();
mFont->DrawString(displayValue.c_str(),x,y);
char buf[512];
sprintf(buf, "%i", value);
mFont->DrawString(buf,SCREEN_WIDTH -10 ,y,JGETEXT_RIGHT);
}
void OptionItem::Update(float dt){
JGE * mEngine = JGE::GetInstance();
if (hasFocus){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue();
}
}
void OptionItem::Entering(){
hasFocus = true;
}
bool OptionItem::Leaving(){
hasFocus = false;
return true;
}
OptionItem * options[20];
int nbitems;
OptionsList::OptionsList(){
nbitems = 0;
current = -1;
}
OptionsList::~OptionsList(){
for (int i = 0 ; i < nbitems; i++){
SAFE_DELETE(options[i]);
}
}
void OptionsList::Add(OptionItem * item){
if (nbitems < 20){
options[nbitems] = item;
item->x = 10;
item->y = 20 + 30*nbitems;
nbitems++;
if (current < 0){
current = 0;
options[0]->Entering();
}
}
}
void OptionsList::Render(){
if (!nbitems){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->DrawString("NO OPTIONS AVAILABLE",SCREEN_WIDTH/2, 5, JGETEXT_RIGHT);
}
for (int i = 0 ; i < nbitems; i++){
options[i]->Render();
}
}
void OptionsList::save(){
for (int i = 0; i < nbitems; i++){
options[i]->setData();
}
GameOptions::GetInstance()->save();
}
void OptionsList::Update(float dt){
JGE * mEngine = JGE::GetInstance();
if (mEngine->GetButtonClick(PSP_CTRL_UP))
{
if (current > 0){
options[current]->Leaving();
current--;
options[current]->Entering();
}
}
else if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
{
if (current < nbitems -1){
options[current]->Leaving();
current++;
options[current]->Entering();
}
}
for (int i = 0 ; i < nbitems; i++){
options[i]->Update(dt);
}
}

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