* 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 * Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root * See LICENSE in the Folder's root
* http://wololo.net/wagic/ * http://wololo.net/wagic/
*/ */
#ifndef _IAPLAYER_H #ifndef _IAPLAYER_H
#define _IAPLAYER_H #define _IAPLAYER_H
@@ -17,40 +17,40 @@
class AIStats; class AIStats;
class AIPlayer: public Player{ class AIPlayer: public Player{
protected: protected:
MTGCardInstance * nextCardToPlay; MTGCardInstance * nextCardToPlay;
ManaCost * potentialMana; ManaCost * potentialMana;
void tapLandsForMana(ManaCost * potentialMana, ManaCost * cost); void tapLandsForMana(ManaCost * potentialMana, ManaCost * cost);
int checkInterrupt(); int checkInterrupt();
int combatDamages(); int combatDamages();
int chooseAttackers(); int chooseAttackers();
int chooseBlockers(); int chooseBlockers();
int effectBadOrGood(MTGCardInstance * card); int effectBadOrGood(MTGCardInstance * card);
int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0); int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
AIStats * getStats(); AIStats * getStats();
public: public:
virtual int displayStack(){return 0;} virtual int displayStack(){return 0;}
AIStats * stats; AIStats * stats;
ManaCost * getPotentialMana(); ManaCost * getPotentialMana();
AIPlayer(MTGPlayerCards * _deck, string deckFile); AIPlayer(MTGPlayerCards * _deck, string deckFile);
virtual ~AIPlayer(); virtual ~AIPlayer();
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0); virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
virtual int chooseTarget(TargetChooser * tc = NULL); virtual int chooseTarget(TargetChooser * tc = NULL);
virtual int Act(float dt); virtual int Act(float dt);
int isAI(){return 1;}; int isAI(){return 1;};
}; };
class AIPlayerBaka: public AIPlayer{ class AIPlayerBaka: public AIPlayer{
protected: protected:
int oldGamePhase; int oldGamePhase;
int timer; int timer;
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type); MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
public: public:
AIPlayerBaka(MTGPlayerCards * _deck, char * deckFile); AIPlayerBaka(MTGPlayerCards * _deck, char * deckFile);
virtual int Act(float dt); virtual int Act(float dt);
void initTimer(); void initTimer();
}; };
class AIPlayerFactory{ class AIPlayerFactory{
+18 -18
View File
@@ -14,29 +14,29 @@ class MTGCard;
class Damage; class Damage;
class AIStat{ class AIStat{
public: public:
int source; //MTGId of the card int source; //MTGId of the card
int value; int value;
int occurences; int occurences;
bool direct; bool direct;
AIStat(int _source, int _value, int _occurences, bool _direct):source(_source), value(_value),occurences(_occurences),direct(_direct){}; AIStat(int _source, int _value, int _occurences, bool _direct):source(_source), value(_value),occurences(_occurences),direct(_direct){};
}; };
class AIStats{ class AIStats{
public: public:
Player * player; Player * player;
string filename; string filename;
list<AIStat *> stats; list<AIStat *> stats;
AIStats(Player * _player, char * filename); AIStats(Player * _player, char * filename);
~AIStats(); ~AIStats();
void updateStats(); void updateStats();
void load(char * filename); void load(char * filename);
void save(); void save();
AIStat * find(MTGCard * card); AIStat * find(MTGCard * card);
bool isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue = true ); bool isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue = true );
void updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier = 1.0); void updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier = 1.0);
}; };
#endif #endif
+24 -24
View File
@@ -1,8 +1,8 @@
/* /*
* Wagic, The Homebrew ?! is licensed under the BSD license * Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root * See LICENSE in the Folder's root
* http://wololo.net/wagic/ * http://wololo.net/wagic/
*/ */
#ifndef _ACTIONELEMENT_H_ #ifndef _ACTIONELEMENT_H_
#define _ACTIONELEMENT_H_ #define _ACTIONELEMENT_H_
@@ -18,30 +18,30 @@ class Targetable;
class TargetChooser; class TargetChooser;
class ActionElement: public JGuiObject{ class ActionElement: public JGuiObject{
protected: protected:
int activeState; int activeState;
public: public:
TargetChooser * tc; TargetChooser * tc;
int currentPhase; int currentPhase;
int newPhase; int newPhase;
int modal; int modal;
int waitingForAnswer; int waitingForAnswer;
void RenderMessageBackground(float y0, int height); void RenderMessageBackground(float y0, int height);
int getActivity(); int getActivity();
virtual void Update(float dt){}; virtual void Update(float dt){};
virtual void Render(){}; virtual void Render(){};
virtual int testDestroy(){return 0;}; virtual int testDestroy(){return 0;};
virtual int destroy(){return 0;}; virtual int destroy(){return 0;};
virtual void CheckUserInput(float dt){}; virtual void CheckUserInput(float dt){};
ActionElement(int id); ActionElement(int id);
virtual int isReactingToTargetClick(Targetable * card); virtual int isReactingToTargetClick(Targetable * card);
virtual int reactToTargetClick(Targetable * card); virtual int reactToTargetClick(Targetable * card);
virtual int isReactingToClick(MTGCardInstance * card){return 0;}; virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;}; virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual const char * getMenuText(){return "Ability";}; virtual const char * getMenuText(){return "Ability";};
}; };
+20 -20
View File
@@ -1,8 +1,8 @@
/* /*
* Wagic, The Homebrew ?! is licensed under the BSD license * Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root * See LICENSE in the Folder's root
* http://wololo.net/wagic/ * http://wololo.net/wagic/
*/ */
#ifndef _ACTIONLAYER_H_ #ifndef _ACTIONLAYER_H_
#define _ACTIONLAYER_H_ #define _ACTIONLAYER_H_
@@ -16,22 +16,22 @@ class Targetable;
class ActionLayer: public GuiLayer, public JGuiListener{ class ActionLayer: public GuiLayer, public JGuiListener{
public: public:
Targetable * menuObject; Targetable * menuObject;
SimpleMenu * abilitiesMenu; SimpleMenu * abilitiesMenu;
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
int unstopableRenderInProgress(); int unstopableRenderInProgress();
void CheckUserInput(float dt); void CheckUserInput(float dt);
ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;}; ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;};
int isWaitingForAnswer(); int isWaitingForAnswer();
int isReactingToTargetClick(Targetable * card); int isReactingToTargetClick(Targetable * card);
int reactToTargetClick(Targetable * card); int reactToTargetClick(Targetable * card);
int isReactingToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card); int reactToClick(MTGCardInstance * card);
int isModal(); int isModal();
void setMenuObject(Targetable * object); void setMenuObject(Targetable * object);
void ButtonPressed(int controllerid, int controlid); void ButtonPressed(int controllerid, int controlid);
TargetChooser * getCurrentTargetChooser(); TargetChooser * getCurrentTargetChooser();
}; };
+79 -79
View File
@@ -1,8 +1,8 @@
/* /*
* Wagic, The Homebrew ?! is licensed under the BSD license * Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root * See LICENSE in the Folder's root
* http://wololo.net/wagic/ * http://wololo.net/wagic/
*/ */
#ifndef _SPELLSTACK_H_ #ifndef _SPELLSTACK_H_
#define _SPELLSTACK_H_ #define _SPELLSTACK_H_
@@ -43,105 +43,105 @@ class ManaCost;
#define ACTIONSTACK_TARGET 1 #define ACTIONSTACK_TARGET 1
class Interruptible: public PlayGuiObject, public Targetable{ class Interruptible: public PlayGuiObject, public Targetable{
public: public:
int state, display; int state, display;
MTGCardInstance * source; MTGCardInstance * source;
virtual void Entering(){mHasFocus = true;}; virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;}; virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;}; virtual bool ButtonPressed(){return true;};
virtual int resolve(){return 0;}; virtual int resolve(){return 0;};
virtual void Render(){}; virtual void Render(){};
int typeAsTarget(){return TARGET_STACKACTION;}; int typeAsTarget(){return TARGET_STACKACTION;};
Interruptible(int id,bool hasFocus = false):PlayGuiObject(id,40,x,y,hasFocus){state=NOT_RESOLVED;display=0;source=NULL;}; Interruptible(int id,bool hasFocus = false):PlayGuiObject(id,40,x,y,hasFocus){state=NOT_RESOLVED;display=0;source=NULL;};
}; };
class NextGamePhase: public Interruptible { class NextGamePhase: public Interruptible {
public: public:
int resolve(); int resolve();
void Render(); void Render();
NextGamePhase(int id); NextGamePhase(int id);
}; };
class Spell: public Interruptible, public TargetsList { class Spell: public Interruptible, public TargetsList {
protected: protected:
public: public:
ManaCost * cost; ManaCost * cost;
Spell(MTGCardInstance* _source); Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, Targetable * _targets[], int _nbtargets, ManaCost * _cost); Spell(int id, MTGCardInstance* _source, Targetable * _targets[], int _nbtargets, ManaCost * _cost);
~Spell(); ~Spell();
int resolve(); int resolve();
void Render(); void Render();
}; };
class StackAbility: public Interruptible { class StackAbility: public Interruptible {
public: public:
MTGAbility * ability; MTGAbility * ability;
int resolve(); int resolve();
void Render(); void Render();
StackAbility(int id, MTGAbility * _ability); StackAbility(int id, MTGAbility * _ability);
}; };
class PutInGraveyard: public Interruptible { class PutInGraveyard: public Interruptible {
public: public:
MTGCardInstance * card; MTGCardInstance * card;
int removeFromGame; int removeFromGame;
int resolve(); int resolve();
void Render(); void Render();
PutInGraveyard(int id, MTGCardInstance * _card); PutInGraveyard(int id, MTGCardInstance * _card);
}; };
class DrawAction: public Interruptible { class DrawAction: public Interruptible {
public: public:
int nbcards; int nbcards;
Player * player; Player * player;
int resolve(); int resolve();
void Render(); void Render();
DrawAction(int id, Player * _player, int _nbcards); DrawAction(int id, Player * _player, int _nbcards);
}; };
class ActionStack :public GuiLayer{ class ActionStack :public GuiLayer{
protected: protected:
int interruptDecision[2]; int interruptDecision[2];
int timer; int timer;
int currentState; int currentState;
int mode; int mode;
int checked; int checked;
void unpackDamageStacks(); void unpackDamageStacks();
void unpackDamageStack(DamageStack * ds); void unpackDamageStack(DamageStack * ds);
void repackDamageStacks(); void repackDamageStacks();
public: public:
int setIsInterrupting(Player * player); int setIsInterrupting(Player * player);
int count( int type = 0 , int state = 0 , int display = -1); int count( int type = 0 , int state = 0 , int display = -1);
Interruptible * getPrevious(Interruptible * next, 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); 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); 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); int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
void Fizzle(Interruptible * action); void Fizzle(Interruptible * action);
Interruptible * _(int id); Interruptible * _(int id);
void cancelInterruptOffer(int cancelMode = 1); void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption(); void endOfInterruption();
Interruptible * getLatest(int state); Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt; Player * askIfWishesToInterrupt;
int garbageCollect(); int garbageCollect();
int addAction(Interruptible * interruptible); int addAction(Interruptible * interruptible);
int addSpell(MTGCardInstance* card, Targetable * targets[], int nbtargets, ManaCost * mana); int addSpell(MTGCardInstance* card, Targetable * targets[], int nbtargets, ManaCost * mana);
int AddNextGamePhase(); int AddNextGamePhase();
int addPutInGraveyard(MTGCardInstance * card); int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1); int addDraw(Player * player, int nbcards = 1);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage); int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability); int addAbility(MTGAbility * ability);
void Update(float dt); void Update(float dt);
void CheckUserInput(float dt); void CheckUserInput(float dt);
virtual void Render(); virtual void Render();
ActionStack(int id, GameObserver* _game); ActionStack(int id, GameObserver* _game);
int resolve(); int resolve();
int CombatDamages(); int CombatDamages();
int CombatDamages(int firststrike); int CombatDamages(int firststrike);
int has(Interruptible * action); 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 MTGAbility;
class Blocker : public MTGAbility { class Blocker : public MTGAbility {
protected: protected:
ManaCost * manaCost; ManaCost * manaCost;
int currentPhase; int currentPhase;
void init(ManaCost * _cost); void init(ManaCost * _cost);
public: public:
virtual ManaCost * untapManaCost(){return manaCost;}; virtual ManaCost * untapManaCost(){return manaCost;};
virtual int unblock(){return 1;}; virtual int unblock(){return 1;};
Blocker(int id, MTGCardInstance * card, ManaCost * _cost); Blocker(int id, MTGCardInstance * card, ManaCost * _cost);
Blocker(int id, MTGCardInstance * card); Blocker(int id, MTGCardInstance * card);
Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost); Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost);
~Blocker(); ~Blocker();
virtual void Update(float dt); virtual void Update(float dt);
virtual int destroy(); virtual int destroy();
}; };
class Blockers { class Blockers {
protected: protected:
int cursor; int cursor;
int blockers[MAX_BLOCKERS]; int blockers[MAX_BLOCKERS];
GameObserver * game; GameObserver * game;
public: public:
Blockers(); Blockers();
~Blockers(); ~Blockers();
int Add (Blocker * ability); int Add (Blocker * ability);
int Remove (Blocker * ability); int Remove (Blocker * ability);
int init(); int init();
Blocker * next(); Blocker * next();
int rewind(); int rewind();
int isEmpty(); 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_ #ifndef _CARDDESCRIPTOR_H_
@@ -12,16 +12,16 @@ A Filter/Mask system for Card Instances to find cards matching specific settings
#define CD_AND 2 #define CD_AND 2
class CardDescriptor: public MTGCardInstance{ class CardDescriptor: public MTGCardInstance{
protected: protected:
MTGCardInstance * match_or(MTGCardInstance * card); MTGCardInstance * match_or(MTGCardInstance * card);
MTGCardInstance * match_and(MTGCardInstance * card); MTGCardInstance * match_and(MTGCardInstance * card);
public: public:
int mode; int mode;
int init(); int init();
CardDescriptor(); CardDescriptor();
MTGCardInstance * match(MTGCardInstance * card); MTGCardInstance * match(MTGCardInstance * card);
MTGCardInstance * match(MTGGameZone * zone); MTGCardInstance * match(MTGGameZone * zone);
MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous); MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous);
}; };
#endif #endif
+15 -15
View File
@@ -8,25 +8,25 @@ class MTGGameZone;
class MTGCardInstance; class MTGCardInstance;
class CardDisplay:public PlayGuiObjectController{ class CardDisplay:public PlayGuiObjectController{
public: public:
int x, y , start_item, nb_displayed_items; int x, y , start_item, nb_displayed_items;
TargetChooser * tc; TargetChooser * tc;
JGuiListener * listener; JGuiListener * listener;
CardDisplay(); CardDisplay();
CardDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc = NULL, int _nb_displayed_items = 7 ); CardDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc = NULL, int _nb_displayed_items = 7 );
void AddCard(MTGCardInstance * _card); void AddCard(MTGCardInstance * _card);
void rotateLeft(); void rotateLeft();
void rotateRight(); void rotateRight();
void CheckUserInput(float dt); void CheckUserInput(float dt);
void Render(); void Render();
void init(MTGGameZone * zone); void init(MTGGameZone * zone);
}; };
class DefaultTargetDisplay:CardDisplay{ class DefaultTargetDisplay:CardDisplay{
public: public:
DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, int _nb_displayed_items ); DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, int _nb_displayed_items );
~DefaultTargetDisplay(); ~DefaultTargetDisplay();
}; };
#endif #endif
+7 -7
View File
@@ -12,18 +12,18 @@ class MTGCardInstance;
class PlayGuiObject; class PlayGuiObject;
class CardGui: public PlayGuiObject{ class CardGui: public PlayGuiObject{
protected: protected:
hgeParticleSystem * mParticleSys; hgeParticleSystem * mParticleSys;
int alpha; int alpha;
public: public:
MTGCardInstance * card; MTGCardInstance * card;
CardGui(int id, MTGCardInstance * _card, float desiredHeight, float _x=0, float _y=0, bool hasFocus = false); CardGui(int id, MTGCardInstance * _card, float desiredHeight, float _x=0, float _y=0, bool hasFocus = false);
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
void RenderBig(float x=-1, float y = -1); 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); static void alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation= 0, float scale=1);
~CardGui(); ~CardGui();
}; };
+3 -3
View File
@@ -6,9 +6,9 @@
class ConstraintResolver { class ConstraintResolver {
protected: protected:
public: public:
static int untap(GameObserver * game, MTGCardInstance * card); static int untap(GameObserver * game, MTGCardInstance * card);
}; };
#endif #endif
+25 -25
View File
@@ -8,35 +8,35 @@ class MTGCardInstance;
/* One family of counters. Ex : +1/+1 */ /* One family of counters. Ex : +1/+1 */
class Counter{ class Counter{
public : public :
string name; string name;
int nb; int nb;
int power, toughness; int power, toughness;
MTGCardInstance * target; MTGCardInstance * target;
Counter(MTGCardInstance * _target, int _power, int _toughness); Counter(MTGCardInstance * _target, int _power, int _toughness);
Counter(MTGCardInstance * _target, const char * _name,int _power = 0 , int _toughness = 0 ); Counter(MTGCardInstance * _target, const char * _name,int _power = 0 , int _toughness = 0 );
int init(MTGCardInstance * _target,const char * _name, int _power, int _toughness); int init(MTGCardInstance * _target,const char * _name, int _power, int _toughness);
bool sameAs(const char * _name, int _power, int _toughness); bool sameAs(const char * _name, int _power, int _toughness);
bool cancels(int _power, int _toughness); bool cancels(int _power, int _toughness);
int added(); int added();
int removed(); int removed();
}; };
/* Various families of counters attached to an instance of a card */ /* Various families of counters attached to an instance of a card */
class Counters{ class Counters{
public: public:
int mCount; int mCount;
Counter * counters[10]; Counter * counters[10];
MTGCardInstance * target; MTGCardInstance * target;
Counters(MTGCardInstance * _target); Counters(MTGCardInstance * _target);
~Counters(); ~Counters();
int addCounter(const char * _name,int _power = 0, int _toughness = 0); int addCounter(const char * _name,int _power = 0, int _toughness = 0);
int addCounter(int _power, int _toughness); int addCounter(int _power, int _toughness);
int removeCounter(const char * _name,int _power = 0, int _toughness = 0); int removeCounter(const char * _name,int _power = 0, int _toughness = 0);
int removeCounter(int _power, int _toughness); int removeCounter(int _power, int _toughness);
Counter * hasCounter(const char * _name,int _power = 0, int _toughness = 0); Counter * hasCounter(const char * _name,int _power = 0, int _toughness = 0);
Counter * hasCounter(int _power, int _toughness); Counter * hasCounter(int _power, int _toughness);
Counter * getNext(Counter * previous = NULL); Counter * getNext(Counter * previous = NULL);
}; };
+27 -27
View File
@@ -14,43 +14,43 @@ class GameObserver;
#define DAMAGEABLE_PLAYER 1 #define DAMAGEABLE_PLAYER 1
class Damageable { class Damageable {
protected: protected:
public: public:
int life; int life;
int type_as_damageable; int type_as_damageable;
Damageable(int _life){life=_life;}; Damageable(int _life){life=_life;};
int getLife(){return life;}; int getLife(){return life;};
virtual int dealDamage(int damage){life-=damage;return life;}; virtual int dealDamage(int damage){life-=damage;return life;};
virtual int afterDamage(){return 0;} virtual int afterDamage(){return 0;}
virtual JQuad * getIcon(){return NULL;}; virtual JQuad * getIcon(){return NULL;};
}; };
class Damage: public Interruptible { class Damage: public Interruptible {
protected: protected:
void init(MTGCardInstance * _source, Damageable * _target, int _damage); void init(MTGCardInstance * _source, Damageable * _target, int _damage);
public: public:
Damageable * target; Damageable * target;
MTGCardInstance * source; MTGCardInstance * source;
int damage; int damage;
void Render(); void Render();
Damage(int id, MTGCardInstance* _source, Damageable * _target); Damage(int id, MTGCardInstance* _source, Damageable * _target);
Damage(int id, MTGCardInstance* _source, Damageable * _target, int _damage); Damage(int id, MTGCardInstance* _source, Damageable * _target, int _damage);
int resolve(); int resolve();
}; };
class DamageStack :public GuiLayer, public Interruptible{ class DamageStack :public GuiLayer, public Interruptible{
protected: protected:
int currentState; int currentState;
public: public:
int resolve(); int resolve();
void Render(); void Render();
int CombatDamages();//Deprecated ? int CombatDamages();//Deprecated ?
int CombatDamages(int strike); int CombatDamages(int strike);
DamageStack(int id, GameObserver* _game); DamageStack(int id, GameObserver* _game);
}; };
+24 -24
View File
@@ -8,31 +8,31 @@ class DamageStack;
class DamageResolverLayer:public PlayGuiObjectController{ class DamageResolverLayer:public PlayGuiObjectController{
protected: protected:
int trampleDamage(); int trampleDamage();
public: public:
int buttonOk; int buttonOk;
int currentPhase; int currentPhase;
int remainingDamageSteps; int remainingDamageSteps;
Player * currentChoosingPlayer; Player * currentChoosingPlayer;
DamageStack * damageStack; DamageStack * damageStack;
DamagerDamaged * currentSource; DamagerDamaged * currentSource;
DamageResolverLayer(int id, GameObserver* _game); DamageResolverLayer(int id, GameObserver* _game);
int init(); int init();
int initResolve(); int initResolve();
Player * whoSelectsDamagesDealtBy(MTGCardInstance * card); Player * whoSelectsDamagesDealtBy(MTGCardInstance * card);
int addAutoDamageToOpponents(MTGCardInstance * card); int addAutoDamageToOpponents(MTGCardInstance * card);
int addIfNotExists(MTGCardInstance * card, Player * selecter); int addIfNotExists(MTGCardInstance * card, Player * selecter);
int addDamager(MTGCardInstance * card, Player * selecter); int addDamager(MTGCardInstance * card, Player * selecter);
DamagerDamaged * findByCard(MTGCardInstance * card); DamagerDamaged * findByCard(MTGCardInstance * card);
int canStopDealDamages(); int canStopDealDamages();
int resolveDamages(); int resolveDamages();
int isOpponent(DamagerDamaged * a, DamagerDamaged * b); int isOpponent(DamagerDamaged * a, DamagerDamaged * b);
void nextPlayer(); void nextPlayer();
virtual void Update(float dt); virtual void Update(float dt);
virtual void CheckUserInput(float dt); virtual void CheckUserInput(float dt);
virtual void Render(); virtual void Render();
}; };
#endif #endif
+14 -14
View File
@@ -6,21 +6,21 @@
class Player; class Player;
class DamagerDamaged:public CardGui{ class DamagerDamaged:public CardGui{
public: public:
Player * damageSelecter; Player * damageSelecter;
int mCount; int mCount;
Damage * damages[10]; Damage * damages[10];
int damageToDeal; int damageToDeal;
int dealOneDamage(DamagerDamaged * target); int dealOneDamage(DamagerDamaged * target);
int addDamage(int damage, DamagerDamaged * source); int addDamage(int damage, DamagerDamaged * source);
int removeDamagesTo(DamagerDamaged * target); int removeDamagesTo(DamagerDamaged * target);
int removeDamagesFrom(DamagerDamaged * source); int removeDamagesFrom(DamagerDamaged * source);
int sumDamages(); int sumDamages();
int hasLethalDamage(); int hasLethalDamage();
DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus); DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus);
~DamagerDamaged(); ~DamagerDamaged();
void Render(Player * currentPlayer); void Render(Player * currentPlayer);
+26 -26
View File
@@ -12,37 +12,37 @@ class MTGDeck;
class Cmp1 { // compares cards by their name class Cmp1 { // compares cards by their name
public: public:
bool operator()(MTGCard * card1, MTGCard * card2) const { bool operator()(MTGCard * card1, MTGCard * card2) const {
if (!card2) return true; if (!card2) return true;
if (!card1) return false; if (!card1) return false;
string name1 = card1->name; string name1 = card1->name;
string name2 = card2->name; string name2 = card2->name;
int result = name1.compare(name2); int result = name1.compare(name2);
if (!result) return card1->getMTGId() < card2->getMTGId(); if (!result) return card1->getMTGId() < card2->getMTGId();
return ( result < 0); return ( result < 0);
} }
}; };
class DeckDataWrapper{ class DeckDataWrapper{
public: public:
int colors[MTG_NB_COLORS+1]; int colors[MTG_NB_COLORS+1];
int currentColor; int currentColor;
map<MTGCard *, int,Cmp1> cards; map<MTGCard *, int,Cmp1> cards;
int currentposition; int currentposition;
MTGDeck * parent; MTGDeck * parent;
DeckDataWrapper(MTGDeck * deck); DeckDataWrapper(MTGDeck * deck);
~DeckDataWrapper(); ~DeckDataWrapper();
int Add(MTGCard * card); int Add(MTGCard * card);
int Remove(MTGCard * card); int Remove(MTGCard * card);
MTGCard * getNext(MTGCard * previous = NULL, int color = -1); MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1); MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);
void updateCounts(MTGCard * card = NULL, int removed = 0); void updateCounts(MTGCard * card = NULL, int removed = 0);
void updateCurrentPosition(MTGCard * currentCard,int color = -1); void updateCurrentPosition(MTGCard * currentCard,int color = -1);
int getCount(int color = -1); int getCount(int color = -1);
void save(); void save();
}; };
#endif #endif
+7 -7
View File
@@ -12,13 +12,13 @@ class DamageResolverLayer;
class DuelLayers: public GuiLayers{ class DuelLayers: public GuiLayers{
public: public:
ActionLayer * actionLayer(); ActionLayer * actionLayer();
MTGGuiHand * handLayer(); MTGGuiHand * handLayer();
MTGGuiPlay * playLayer(); MTGGuiPlay * playLayer();
ActionStack * stackLayer(); ActionStack * stackLayer();
DamageResolverLayer * combatLayer(); DamageResolverLayer * combatLayer();
void init(); void init();
}; };
+20 -20
View File
@@ -1,8 +1,8 @@
/* /*
* Wagic, The Homebrew ?! is licensed under the BSD license * Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root * See LICENSE in the Folder's root
* http://wololo.net/wagic/ * http://wololo.net/wagic/
*/ */
@@ -51,7 +51,7 @@ class TexturesCache;
class GameApp: public JApp class GameApp: public JApp
{ {
private: private:
bool mShowDebugInfo; bool mShowDebugInfo;
int mScreenShotCount; int mScreenShotCount;
@@ -60,26 +60,26 @@ private:
GameState* mGameStates[MAX_STATE]; GameState* mGameStates[MAX_STATE];
public: public:
int players[2]; int players[2];
MTGAllCards * collection; MTGAllCards * collection;
TexturesCache * cache; TexturesCache * cache;
GameApp(); GameApp();
virtual ~GameApp(); virtual ~GameApp();
virtual void Create(); virtual void Create();
virtual void Destroy(); virtual void Destroy();
virtual void Update(); virtual void Update();
virtual void Render(); virtual void Render();
virtual void Pause(); virtual void Pause();
virtual void Resume(); virtual void Resume();
void LoadGameStates(); void LoadGameStates();
void SetNextState(int state); void SetNextState(int state);
static JResourceManager * CommonRes; static JResourceManager * CommonRes;
static hgeParticleSystem * Particles[6]; static hgeParticleSystem * Particles[6];
static int HasMusic; static int HasMusic;
}; };
+28 -28
View File
@@ -23,49 +23,49 @@ class TargetChooser;
class GameObserver{ class GameObserver{
protected: protected:
int reaction; int reaction;
static GameObserver * mInstance; static GameObserver * mInstance;
MTGCardInstance * cardWaitingForTargets; MTGCardInstance * cardWaitingForTargets;
int nbPlayers; int nbPlayers;
int currentPlayerId; int currentPlayerId;
int currentRound; int currentRound;
int targetListIsSet(MTGCardInstance * card); int targetListIsSet(MTGCardInstance * card);
public: public:
PhaseRing * phaseRing; PhaseRing * phaseRing;
int cancelCurrentAction(); int cancelCurrentAction();
int currentGamePhase; int currentGamePhase;
int oldGamePhase; int oldGamePhase;
TargetChooser * targetChooser; TargetChooser * targetChooser;
DuelLayers * mLayers; DuelLayers * mLayers;
Player * gameOver; Player * gameOver;
Player * players[2]; //created outside Player * players[2]; //created outside
MTGGamePhase * gamePhaseManager; //Created Outside ? MTGGamePhase * gamePhaseManager; //Created Outside ?
TargetChooser * getCurrentTargetChooser(); TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action); void stackObjectClicked(Interruptible * action);
void cardClick(MTGCardInstance * card,Targetable * _object = NULL ); void cardClick(MTGCardInstance * card,Targetable * _object = NULL );
int enteringPhase(int phase); int enteringPhase(int phase);
int getCurrentGamePhase(); int getCurrentGamePhase();
void userRequestNextGamePhase(); void userRequestNextGamePhase();
void nextGamePhase(); void nextGamePhase();
void cleanupPhase(); void cleanupPhase();
void nextPlayer(); void nextPlayer();
static void Init(Player * _players[], int _nbplayers); static void Init(Player * _players[], int _nbplayers);
static GameObserver * GetInstance(); static GameObserver * GetInstance();
static void EndInstance(); static void EndInstance();
Player * currentPlayer; Player * currentPlayer;
Player * currentActionPlayer; Player * currentActionPlayer;
Player * isInterrupting; Player * isInterrupting;
Player * opponent(); Player * opponent();
Player * currentlyActing(); Player * currentlyActing();
GameObserver(Player * _players[], int _nbplayers); GameObserver(Player * _players[], int _nbplayers);
~GameObserver(); ~GameObserver();
void setGamePhaseManager(MTGGamePhase * _phases); void setGamePhaseManager(MTGGamePhase * _phases);
void stateEffects(); void stateEffects();
void eventOccured(); void eventOccured();
void addObserver(MTGAbility * observer); void addObserver(MTGAbility * observer);
void removeObserver(ActionElement * observer); void removeObserver(ActionElement * observer);
@@ -73,7 +73,7 @@ class GameObserver{
void nextStep(); void nextStep();
void untapPhase(); void untapPhase();
void draw(); void draw();
int canPutInPlay(MTGCardInstance * card); int canPutInPlay(MTGCardInstance * card);
void putInPlay(MTGCardInstance * card); void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card); int isInPlay(MTGCardInstance * card);
int isACreature(MTGCardInstance * card); int isACreature(MTGCardInstance * card);
+10 -10
View File
@@ -7,17 +7,17 @@
#define OPTIONS_INTERRUPTATENDOFPHASE_OFFSET 1 #define OPTIONS_INTERRUPTATENDOFPHASE_OFFSET 1
#define OPTIONS_SAVEFILE "Res/settings/options.txt" #define OPTIONS_SAVEFILE "Res/settings/options.txt"
class GameOptions { class GameOptions {
public: public:
int values[MAX_OPTIONS]; int values[MAX_OPTIONS];
static GameOptions * GetInstance(); static GameOptions * GetInstance();
static void Destroy(); static void Destroy();
int save(); int save();
int load(); int load();
private: private:
GameOptions(); GameOptions();
~GameOptions(); ~GameOptions();
static GameOptions* mInstance; static GameOptions* mInstance;
}; };
+20 -20
View File
@@ -8,37 +8,37 @@ class JGE;
#include <JSoundSystem.h> #include <JSoundSystem.h>
enum _gameSates enum _gameSates
{ {
GAME_STATE_MENU, GAME_STATE_MENU,
GAME_STATE_DUEL, GAME_STATE_DUEL,
GAME_STATE_DECK_VIEWER, GAME_STATE_DECK_VIEWER,
GAME_STATE_SHOP, GAME_STATE_SHOP,
GAME_STATE_OPTIONS GAME_STATE_OPTIONS
}; };
class GameApp; class GameApp;
class GameState class GameState
{ {
protected: protected:
GameApp* mParent; GameApp* mParent;
JGE* mEngine; JGE* mEngine;
public: public:
static const char * const menuTexts[]; static const char * const menuTexts[];
GameState(GameApp* parent); GameState(GameApp* parent);
virtual ~GameState() {} virtual ~GameState() {}
virtual void Create() {} virtual void Create() {}
virtual void Destroy() {} virtual void Destroy() {}
virtual void Start() {} virtual void Start() {}
virtual void End() {} virtual void End() {}
virtual void Update(float dt) = 0; virtual void Update(float dt) = 0;
virtual void Render() = 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 class GameStateDuel: public GameState, public JGuiListener
{ {
private: private:
#ifdef TESTSUITE #ifdef TESTSUITE
TestSuite * testSuite; TestSuite * testSuite;
#endif #endif
int mGamePhase; int mGamePhase;
Player * mCurrentPlayer; Player * mCurrentPlayer;
Player * mPlayers[2]; Player * mPlayers[2];
MTGPlayerCards * deck[2]; MTGPlayerCards * deck[2];
GameObserver * game; GameObserver * game;
SimpleMenu * deckmenu; SimpleMenu * deckmenu;
SimpleMenu * menu; SimpleMenu * menu;
JLBFont* mFont; JLBFont* mFont;
void loadPlayer(int playerId, int decknb = 0); void loadPlayer(int playerId, int decknb = 0);
public: public:
GameStateDuel(GameApp* parent); GameStateDuel(GameApp* parent);
virtual ~GameStateDuel(); virtual ~GameStateDuel();
#ifdef TESTSUITE #ifdef TESTSUITE
void loadTestSuitePlayers(); void loadTestSuitePlayers();
#endif #endif
virtual void ButtonPressed(int ControllerId, int ControlId); virtual void ButtonPressed(int ControllerId, int ControlId);
virtual void Start(); virtual void Start();
virtual void End(); virtual void End();
virtual void Update(float dt); virtual void Update(float dt);
virtual void Render(); virtual void Render();
}; };
+389 -389
View File
@@ -25,404 +25,404 @@
class GameStateMenu: public GameState, public JGuiListener class GameStateMenu: public GameState, public JGuiListener
{ {
private: private:
JGuiController* mGuiController; JGuiController* mGuiController;
SimpleMenu* subMenuController; SimpleMenu* subMenuController;
JLBFont* mFont; JLBFont* mFont;
JQuad * mIcons[10]; JQuad * mIcons[10];
JTexture * mIconsTexture; JTexture * mIconsTexture;
JTexture * bgTexture; JTexture * bgTexture;
JQuad * mBg; JQuad * mBg;
float mCreditsYPos; float mCreditsYPos;
int currentState; int currentState;
JMusic * bgMusic; JMusic * bgMusic;
int mVolume; int mVolume;
char nbcardsStr[400]; char nbcardsStr[400];
DIR *mDip; DIR *mDip;
struct dirent *mDit; struct dirent *mDit;
char mCurrentSetName[10]; char mCurrentSetName[10];
char mCurrentSetFileName[512]; char mCurrentSetFileName[512];
int mReadConf; int mReadConf;
public: public:
GameStateMenu(GameApp* parent): GameState(parent) GameStateMenu(GameApp* parent): GameState(parent)
{ {
mGuiController = NULL; mGuiController = NULL;
subMenuController = NULL; subMenuController = NULL;
mIconsTexture = NULL; mIconsTexture = NULL;
bgMusic = 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;
} }
}
createUsersFirstDeck(setId);
virtual void Create() currentState = STATE_WARNING;
{ }else if (currentState == STATE_WARNING){
if (!ALPHA_WARNING){
mDip = NULL; currentState = STATE_MENU;
mReadConf = 0; }else{
mCurrentSetName[0] = 0; if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) currentState = STATE_MENU;
}
}else{
if (currentState == STATE_MENU && mGuiController!=NULL)
mGuiController->Update(dt);
if (currentState == STATE_SUBMENU){
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM); if( subMenuController != NULL){
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/menutitle.png", TEX_TYPE_USE_VRAM); subMenuController->Update(dt);
mBg = NEW JQuad(bgTexture, 10, 0, 220, 80); // Create background quad for rendering. }else{
mBg->SetHotSpot(105,32); subMenuController = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
//load all the icon images if (subMenuController){
int n = 0; subMenuController->Add(11,"1 Player");
for (int i=0;i<5;i++) subMenuController->Add(12, "2 Players");
{ subMenuController->Add(13,"Demo");
for (int j=0;j<2;j++) subMenuController->Add(14, "Cancel");
{
mIcons[n] = NEW JQuad(mIconsTexture, 10 + i*32, j*32, 32, 32);
mIcons[n]->SetHotSpot(16,16);
n++;
}
}
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
//mFont->SetBase(0); // using 2nd font
mGuiController = NEW JGuiController(100, this);
//mGuiController->SetShadingBackground(10, 45, 80, 100, ARGB(255,0,0,0));
if (mGuiController)
{
mGuiController->Add(NEW MenuItem(1, mFont, "Play", 80, SCREEN_HEIGHT/2, mIcons[8], mIcons[9],"graphics/particle1.psi",GameApp::CommonRes->GetQuad("particles"), true));
mGuiController->Add(NEW MenuItem(2, mFont, "Deck Editor", 160, SCREEN_HEIGHT/2, mIcons[2], mIcons[3],"graphics/particle2.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(3, mFont, "Shop", 240, SCREEN_HEIGHT/2, mIcons[0], mIcons[1],"graphics/particle3.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(4, mFont, "Options", 320, SCREEN_HEIGHT/2, mIcons[6], mIcons[7],"graphics/particle4.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(5, mFont, "Exit", 400, SCREEN_HEIGHT/2, mIcons[4], mIcons[5],"graphics/particle5.psi",GameApp::CommonRes->GetQuad("particles")));
}
currentState = STATE_LOADING_CARDS;
}
virtual void Destroy()
{
if (mGuiController)
delete mGuiController;
if (subMenuController)
delete subMenuController;
if (mIconsTexture)
delete mIconsTexture;
for (int i = 0; i < 10 ; i++){
delete mIcons[i];
}
if (mBg) delete mBg;
SAFE_DELETE (bgMusic);
}
virtual void Start(){
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
if (GameApp::HasMusic && !bgMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
bgMusic = JSoundSystem::GetInstance()->LoadMusic("sound/track0.mp3");
}
if (bgMusic){
mVolume = 0;
JSoundSystem::GetInstance()->SetVolume(mVolume);
JSoundSystem::GetInstance()->PlayMusic(bgMusic, true);
}
}
/* Retrieves the next set subfolder automatically
*/
int nextCardSet(){
int found = 0;
if (!mDip){
mDip = opendir("Res/sets/");
}
while (!found && (mDit = readdir(mDip))){
sprintf(mCurrentSetFileName, "Res/sets/%s/_cards.dat", mDit->d_name);
std::ifstream file(mCurrentSetFileName);
if(file){
sprintf(mCurrentSetName, "%s", mDit->d_name);
file.close();
found = 1;
}
}
if (!mDit) {
closedir(mDip);
mDip = NULL;
}
return found;
}
virtual void End()
{
//mEngine->EnableVSync(false);
if (bgMusic)
{
JSoundSystem::GetInstance()->StopMusic(bgMusic);
}
JRenderer::GetInstance()->EnableVSync(false);
}
virtual void Update(float dt)
{
if (bgMusic && mVolume < 2*GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME]){
mVolume++;
JSoundSystem::GetInstance()->SetVolume(mVolume/2);
}
if (currentState == STATE_LOADING_CARDS){
if (mReadConf){
mParent->collection->load(mCurrentSetFileName, mCurrentSetName);
}else{
mReadConf = 1;
}
if (!nextCardSet()){
//How many cards total ?
sprintf(nbcardsStr, "Database: %i cards", mParent->collection->totalCards());
//Check for first time comer
std::ifstream file("Res/player/collection.dat");
if(file){
file.close();
currentState = STATE_WARNING;
}else{
currentState = STATE_FIRST_TIME;
}
}
}else if (currentState == STATE_FIRST_TIME){
//Give the player cards from the set for which we have the most variety
int setId = 0;
int maxcards = 0;
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
int value = mParent->collection->countBySet(i);
if (value > maxcards){
maxcards = value;
setId = i;
}
}
createUsersFirstDeck(setId);
currentState = STATE_WARNING;
}else if (currentState == STATE_WARNING){
if (!ALPHA_WARNING){
currentState = STATE_MENU;
}else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) currentState = STATE_MENU;
}
}else{
if (currentState == STATE_MENU && mGuiController!=NULL)
mGuiController->Update(dt);
if (currentState == STATE_SUBMENU){
if( subMenuController != NULL){
subMenuController->Update(dt);
}else{
subMenuController = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
if (subMenuController){
subMenuController->Add(11,"1 Player");
subMenuController->Add(12, "2 Players");
subMenuController->Add(13,"Demo");
subMenuController->Add(14, "Cancel");
#ifdef TESTSUITE
subMenuController->Add(666, "Test Suite");
#endif
}
}
}
}
if (currentState == STATE_WARNING && !ALPHA_WARNING) currentState = STATE_MENU;
}
void createUsersFirstDeck(int setId){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "setID: %i", setId);
OutputDebugString(buf);
#endif
MTGDeck *mCollection = NEW MTGDeck("Res/player/collection.dat", mParent->cache, mParent->collection);
//10 lands of each
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Forest")){
mCollection->addRandomCards(10, -1,RARITY_L,"Forest");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Plains")){
mCollection->addRandomCards(10, -1,RARITY_L,"Plains");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Swamp")){
mCollection->addRandomCards(10, -1,RARITY_L,"Swamp");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Mountain")){
mCollection->addRandomCards(10, -1,RARITY_L,"Mountain");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Island")){
mCollection->addRandomCards(10, -1,RARITY_L,"Island");
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString("1\n");
#endif
//Starter Deck
mCollection->addRandomCards(3, setId,RARITY_R,NULL);
mCollection->addRandomCards(9, setId,RARITY_U,NULL);
mCollection->addRandomCards(48, setId,RARITY_C,NULL);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("2\n");
#endif
//Boosters
for (int i = 0; i< 2; i++){
mCollection->addRandomCards(1, setId,RARITY_R);
mCollection->addRandomCards(3, setId,RARITY_U);
mCollection->addRandomCards(11, setId,RARITY_C);
}
mCollection->save();
delete mCollection;
}
virtual void Render()
{
JRenderer * renderer = JRenderer::GetInstance();
renderer->ClearScreen(ARGB(0,0,0,0));
if (currentState == STATE_LOADING_CARDS){
char text[512];
sprintf(text, "LOADING SET: %s", mCurrentSetName);
mFont->DrawString(text,SCREEN_WIDTH/2,SCREEN_HEIGHT/2,JGETEXT_CENTER);
}else{
PIXEL_TYPE colors[] =
{
ARGB(255,17,17,17),
ARGB(255,17,17,17),
ARGB(255,62,62,62),
ARGB(255,62,62,62)
};
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,colors);
renderer->RenderQuad(mBg, SCREEN_WIDTH/2 , 50);
if (mGuiController!=NULL)
mGuiController->Render();
mFont->SetScale(0.7);
mFont->SetColor(ARGB(128,255,255,255));
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,SCREEN_HEIGHT-15,JGETEXT_RIGHT);
mFont->DrawString(nbcardsStr,10, SCREEN_HEIGHT-15);
mFont->SetScale(1.f);
mFont->SetColor(ARGB(255,255,255,255));
if (currentState == STATE_SUBMENU && subMenuController != NULL){
subMenuController->Render();
}
if (currentState == STATE_WARNING){
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(128,0,0,0));
mFont->DrawString("IMPORTANT NOTE" ,SCREEN_WIDTH/2,10,JGETEXT_CENTER);
mFont->DrawString("This is an alpha version with lots of bugs.",SCREEN_WIDTH/2,35,JGETEXT_CENTER);
mFont->DrawString("It WILL crash your psp" ,SCREEN_WIDTH/2,50,JGETEXT_CENTER);
mFont->DrawString("If you use it anyway, your feedback is welcome" ,SCREEN_WIDTH/2,65,JGETEXT_CENTER);
mFont->DrawString("This freeware game is NOT published or endorsed" ,SCREEN_WIDTH/2,110,JGETEXT_CENTER);
mFont->DrawString("by Wizard of the Coast, Inc." ,SCREEN_WIDTH/2,125,JGETEXT_CENTER);
mFont->DrawString("Infos & updates at http://wololo.net/wagic/" ,SCREEN_WIDTH/2,170,JGETEXT_CENTER);
mFont->DrawString("PRESS CIRCLE TO CONTINUE OR HOME TO QUIT" ,SCREEN_WIDTH/2,210,JGETEXT_CENTER);
}
}
}
virtual void ButtonPressed(int controllerId, int controlId)
{
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "cnotrollerId: %i", controllerId);
OutputDebugString(buf);
#endif
switch (controllerId){
case 101:
createUsersFirstDeck(controlId);
currentState = STATE_MENU;
SAFE_DELETE(subMenuController);
break;
default:
switch (controlId)
{
case 1:
currentState = STATE_SUBMENU;
break;
case 2:
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
break;
case 3:
mParent->SetNextState(GAME_STATE_SHOP);
break;
case 4:
mParent->SetNextState(GAME_STATE_OPTIONS);
break;
case 5:
mEngine->End();
break;
case 11:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 12:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_HUMAN;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 13:
mParent->players[0] = PLAYER_TYPE_CPU;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 14:
currentState = STATE_MENU;
delete subMenuController;
subMenuController = NULL;
break;
#ifdef TESTSUITE #ifdef TESTSUITE
case 666: subMenuController->Add(666, "Test Suite");
mParent->players[0] = PLAYER_TYPE_TESTSUITE;
mParent->players[1] = PLAYER_TYPE_TESTSUITE;
mParent->SetNextState(GAME_STATE_DUEL);
break;
#endif #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 class GameStateOptions: public GameState, public JGuiListener
{ {
public: public:
SimpleMenu * optionsMenu; SimpleMenu * optionsMenu;
int mState; int mState;
OptionsList * optionsList; OptionsList * optionsList;
GameStateOptions(GameApp* parent); GameStateOptions(GameApp* parent);
virtual ~GameStateOptions(); virtual ~GameStateOptions();
virtual void Start(); virtual void Start();
virtual void End(); virtual void End();
virtual void Update(float dt); virtual void Update(float dt);
virtual void Render(); virtual void Render();
void ButtonPressed(int controllerId, int ControlId); void ButtonPressed(int controllerId, int ControlId);
}; };
+21 -21
View File
@@ -14,30 +14,30 @@
class GameStateShop: public GameState, public JGuiListener class GameStateShop: public GameState, public JGuiListener
{ {
private: private:
ShopItems * shop; ShopItems * shop;
JLBFont * mFont; JLBFont * mFont;
JQuad * mBg; JQuad * mBg;
JTexture * bgTexture; JTexture * bgTexture;
JQuad * mBack; JQuad * mBack;
JTexture * backTexture; JTexture * backTexture;
SimpleMenu * menu; SimpleMenu * menu;
int mStage; int mStage;
char starterBuffer[128], boosterBuffer[128]; char starterBuffer[128], boosterBuffer[128];
int setId; int setId;
public: public:
GameStateShop(GameApp* parent); GameStateShop(GameApp* parent);
virtual ~GameStateShop(); virtual ~GameStateShop();
virtual void Start(); virtual void Start();
virtual void End(); virtual void End();
virtual void Create(); virtual void Create();
virtual void Destroy(); virtual void Destroy();
virtual void Update(float dt); virtual void Update(float dt);
virtual void Render(); virtual void Render();
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
}; };
+2 -2
View File
@@ -5,8 +5,8 @@
#include "PlayGuiObjectController.h" #include "PlayGuiObjectController.h"
class GuiCardsController : public PlayGuiObjectController{ class GuiCardsController : public PlayGuiObjectController{
public: public:
GuiCardsController(int id, GameObserver* _game):PlayGuiObjectController(id, _game){}; GuiCardsController(int id, GameObserver* _game):PlayGuiObjectController(id, _game){};
}; };
+7 -7
View File
@@ -20,9 +20,9 @@ class GuiLayer: public JGuiController{
GameObserver * game; GameObserver * game;
public: public:
virtual void resetObjects(); virtual void resetObjects();
int hasFocus; int hasFocus;
int getMaxId(); int getMaxId();
void RenderMessageBackground(float x0, float y0, float width, int height); void RenderMessageBackground(float x0, float y0, float width, int height);
void RenderMessageBackground(float y0, int height); void RenderMessageBackground(float y0, int height);
GuiLayer(int id, GameObserver* _game); GuiLayer(int id, GameObserver* _game);
virtual int isModal(); virtual int isModal();
@@ -34,10 +34,10 @@ class GuiLayer: public JGuiController{
int getIndexOf(JGuiObject * object); int getIndexOf(JGuiObject * object);
JGuiObject * getByIndex (int index); JGuiObject * getByIndex (int index);
virtual void Render(){JGuiController::Render();}; virtual void Render(){JGuiController::Render();};
int empty(){ int empty(){
if (mCount) return 0; if (mCount) return 0;
return 1; return 1;
}; };
}; };
class GuiLayers{ class GuiLayers{
+2 -2
View File
@@ -13,8 +13,8 @@
#define LOG_FILE "Res/debug.txt" #define LOG_FILE "Res/debug.txt"
class Logger{ class Logger{
public: public:
static void Log(char * text); static void Log(char * text);
}; };
#endif #endif
+51 -51
View File
@@ -24,18 +24,18 @@ using std::map;
#define BAKA_EFFECT_BAD 11 #define BAKA_EFFECT_BAD 11
class AbilityFactory{ class AbilityFactory{
private: private:
int destroyAllFromTypeInPlay(const char * type, MTGCardInstance * source, int bury = 0); int destroyAllFromTypeInPlay(const char * type, MTGCardInstance * source, int bury = 0);
int destroyAllFromColorInPlay(int color, MTGCardInstance * source, int bury = 0); int destroyAllFromColorInPlay(int color, MTGCardInstance * source, int bury = 0);
int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p); int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p);
public: 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); void addAbilities(int _id, Spell * spell);
}; };
class MTGAbility: public ActionElement{ class MTGAbility: public ActionElement{
protected: protected:
char menuText[25]; char menuText[25];
Damageable * target; Damageable * target;
GameObserver * game; GameObserver * game;
public: public:
@@ -45,72 +45,72 @@ class MTGAbility: public ActionElement{
virtual int testDestroy(); virtual int testDestroy();
virtual ~MTGAbility(); virtual ~MTGAbility();
virtual void Render(){}; virtual void Render(){};
virtual int isReactingToClick(MTGCardInstance * card){return 0;}; virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;}; virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual void Update(float dt){}; virtual void Update(float dt){};
virtual int fireAbility(); virtual int fireAbility();
virtual int resolve(){return 0;}; virtual int resolve(){return 0;};
}; };
class TriggeredAbility:public MTGAbility{ class TriggeredAbility:public MTGAbility{
public: public:
TriggeredAbility(int id, MTGCardInstance * card); TriggeredAbility(int id, MTGCardInstance * card);
TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target); TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target);
virtual void Update(float dt); virtual void Update(float dt);
virtual void Render(){}; virtual void Render(){};
virtual int trigger()=0; virtual int trigger()=0;
virtual int resolve() = 0; virtual int resolve() = 0;
}; };
class ActivatedAbility:public MTGAbility{ class ActivatedAbility:public MTGAbility{
public: public:
ManaCost * cost; ManaCost * cost;
int playerturnonly; int playerturnonly;
int needsTapping; int needsTapping;
ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual int reactToClick(MTGCardInstance * card); virtual int reactToClick(MTGCardInstance * card);
virtual int isReactingToClick(MTGCardInstance * card); virtual int isReactingToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object); virtual int reactToTargetClick(Targetable * object);
virtual int resolve() = 0; virtual int resolve() = 0;
virtual ~ActivatedAbility(); virtual ~ActivatedAbility();
}; };
class TargetAbility:public ActivatedAbility{ class TargetAbility:public ActivatedAbility{
public: public:
TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); 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); TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual void Update(float dt); virtual void Update(float dt);
virtual int reactToClick(MTGCardInstance * card); virtual int reactToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object); virtual int reactToTargetClick(Targetable * object);
virtual void Render(); virtual void Render();
}; };
class InstantAbility:public MTGAbility{ class InstantAbility:public MTGAbility{
public: public:
int init; int init;
virtual void Update(float dt); virtual void Update(float dt);
virtual int testDestroy(); virtual int testDestroy();
InstantAbility(int _id, MTGCardInstance * source); InstantAbility(int _id, MTGCardInstance * source);
InstantAbility(int _id, MTGCardInstance * source,Damageable * _target); InstantAbility(int _id, MTGCardInstance * source,Damageable * _target);
virtual int resolve(){return 0;}; 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 !!! */ /* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */
class ListMaintainerAbility:public MTGAbility{ class ListMaintainerAbility:public MTGAbility{
public: public:
map<MTGCardInstance *,bool> cards; map<MTGCardInstance *,bool> cards;
ListMaintainerAbility(int _id):MTGAbility(_id,NULL){}; ListMaintainerAbility(int _id):MTGAbility(_id,NULL){};
ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){}; ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){};
ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){}; ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){};
virtual void Update(float dt); virtual void Update(float dt);
virtual int canBeInList(MTGCardInstance * card) = 0; virtual int canBeInList(MTGCardInstance * card) = 0;
virtual int added(MTGCardInstance * card) = 0; virtual int added(MTGCardInstance * card) = 0;
virtual int removed(MTGCardInstance * card) = 0; virtual int removed(MTGCardInstance * card) = 0;
virtual int destroy(); virtual int destroy();
}; };
#include "MTGCardInstance.h" #include "MTGCardInstance.h"
+27 -27
View File
@@ -37,46 +37,46 @@ class MTGCard {
char image_name[MTGCARD_NAME_SIZE]; char image_name[MTGCARD_NAME_SIZE];
int init(); int init();
public: public:
string text; string text;
string name; string name;
int colors[MTG_NB_COLORS]; int colors[MTG_NB_COLORS];
int basicAbilities[NB_BASIC_ABILITIES]; int basicAbilities[NB_BASIC_ABILITIES];
vector<string> formattedText; vector<string> formattedText;
string magicText; string magicText;
int alias; int alias;
string spellTargetType; string spellTargetType;
int formattedTextInit; int formattedTextInit;
int power; int power;
int toughness; int toughness;
int setId; int setId;
static const char * const Colors_To_Text[]; static const char * const Colors_To_Text[];
int nb_types; int nb_types;
int types[MAX_TYPES_PER_CARD]; int types[MAX_TYPES_PER_CARD];
MTGCard(); MTGCard();
MTGCard(TexturesCache * cache, int set_id); MTGCard(TexturesCache * cache, int set_id);
MTGCard(MTGCard * source); MTGCard(MTGCard * source);
JQuad * getQuad(TexturesCache * cache); JQuad * getQuad(TexturesCache * cache);
JQuad * getQuad(int type=1); JQuad * getQuad(int type=1);
JQuad * getThumb(); JQuad * getThumb();
void setColor(int _color, int removeAllOthers = 0); void setColor(int _color, int removeAllOthers = 0);
int getColor(); int getColor();
int hasColor(int _color); int hasColor(int _color);
const char * colorToString(); const char * colorToString();
void setMTGId(int id); void setMTGId(int id);
int getMTGId(); int getMTGId();
int getId(); int getId();
int has(int ability); int has(int ability);
char getRarity(); char getRarity();
void setRarity(char _rarity); void setRarity(char _rarity);
const char * getSetName(); const char * getSetName();
//void setImageName( char * value); //void setImageName( char * value);
char * getImageName (); char * getImageName ();
@@ -84,31 +84,31 @@ class MTGCard {
void setText( string value); void setText( string value);
const char * getText(); const char * getText();
void addMagicText(string value); void addMagicText(string value);
void setName( string value); void setName( string value);
const char * getName(); const char * getName();
void addType(char * type_text); void addType(char * type_text);
void addType(int id); void addType(int id);
void setType(const char * type_text); void setType(const char * type_text);
void setSubtype( string value); void setSubtype( string value);
int removeType(string value, int removeAll = 0); int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0); int removeType(int value, int removeAll = 0);
int hasSubtype(int _subtype); int hasSubtype(int _subtype);
int hasSubtype(const char * _subtype); int hasSubtype(const char * _subtype);
int hasSubtype(string _subtype); int hasSubtype(string _subtype);
int hasType(int _type); int hasType(int _type);
int hasType(const char * type); int hasType(const char * type);
void setManaCost(string value); void setManaCost(string value);
ManaCost * getManaCost(); ManaCost * getManaCost();
int isACreature(); int isACreature();
void setPower(int _power); void setPower(int _power);
int getPower(); int getPower();
void setToughness(int _toughness); 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 { class MTGCardInstance: public MTGCard, public Damageable, public Targetable {
protected: protected:
int untapping; int untapping;
int nb_damages; int nb_damages;
int lifeOrig; int lifeOrig;
Blockers * blockers; Blockers * blockers;
MTGPlayerCards * belongs_to; MTGPlayerCards * belongs_to;
MTGAbility * UntapBlockers[10]; MTGAbility * UntapBlockers[10];
void unband(); void unband();
MTGCardInstance * getNextPartner(); MTGCardInstance * getNextPartner();
void initMTGCI(); void initMTGCI();
public: public:
MTGGameZone * getCurrentZone(); MTGGameZone * getCurrentZone();
int doDamageTest; int doDamageTest;
int summoningSickness; int summoningSickness;
// The recommended method to test for summoning Sickness ! // The recommended method to test for summoning Sickness !
int hasSummoningSickness(); int hasSummoningSickness();
int changeController(Player * newcontroller); int changeController(Player * newcontroller);
MTGCardInstance * defenser; MTGCardInstance * defenser;
float changedZoneRecently; float changedZoneRecently;
Player * owner; Player * owner;
Counters * counters; Counters * counters;
int typeAsTarget(){return TARGET_CARD;} int typeAsTarget(){return TARGET_CARD;}
int attacker; int attacker;
MTGCardInstance * banding; // If belongs to a band when attacking MTGCardInstance * banding; // If belongs to a band when attacking
MTGCardInstance * target; MTGCardInstance * target;
int tapped; int tapped;
void addType(int type); void addType(int type);
int canBlock(); int canBlock();
int canBlock(MTGCardInstance * opponent); int canBlock(MTGCardInstance * opponent);
int canAttack(); int canAttack();
int afterDamage(); int afterDamage();
void setUntapping(); void setUntapping();
int isUntapping(); int isUntapping();
int has(int ability); int has(int ability);
int cleanup(); int cleanup();
int reset(); int reset();
int isAttacker(); int isAttacker();
MTGCardInstance * isDefenser(); MTGCardInstance * isDefenser();
int toggleDefenser(MTGCardInstance * opponent); int toggleDefenser(MTGCardInstance * opponent);
int toggleAttacker(); int toggleAttacker();
MTGCard * model; MTGCard * model;
MTGCardInstance(); MTGCardInstance();
MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to); MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to);
Blockers * getBlockers(); Blockers * getBlockers();
void regenerate(); void regenerate();
Player * controller(); Player * controller();
JQuad * getIcon(); JQuad * getIcon();
int initAttackersDefensers(); int initAttackersDefensers();
MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL); MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL);
int nbOpponents(); int nbOpponents();
~MTGCardInstance(); ~MTGCardInstance();
int addToToughness(int value); int addToToughness(int value);
int setToughness(int value); int setToughness(int value);
CardDescriptor * protections[10]; CardDescriptor * protections[10];
int nbprotections; int nbprotections;
int addProtection(CardDescriptor * cd); int addProtection(CardDescriptor * cd);
int removeProtection(CardDescriptor *cd, int erase = 0); int removeProtection(CardDescriptor *cd, int erase = 0);
int protectedAgainst(MTGCardInstance * card); int protectedAgainst(MTGCardInstance * card);
// in game // in game
int isTapped(); int isTapped();
+33 -33
View File
@@ -24,15 +24,15 @@ class MTGCard;
class MtgSets{ class MtgSets{
protected: protected:
public: public:
int nb_items; int nb_items;
string values[MAX_SETS]; string values[MAX_SETS];
public: public:
static MtgSets * SetsList; static MtgSets * SetsList;
MtgSets(); MtgSets();
int Add(const char * subtype); int Add(const char * subtype);
}; };
@@ -43,27 +43,27 @@ class MTGAllCards {
int conf_fd; int conf_fd;
char * conf_buffer; char * conf_buffer;
int read_cursor; int read_cursor;
int colorsCount[MTG_NB_COLORS]; int colorsCount[MTG_NB_COLORS];
int total_cards; int total_cards;
GameApp * parent; GameApp * parent;
void init(); void init();
void initCounters(); void initCounters();
public: public:
TexturesCache * mCache; TexturesCache * mCache;
MTGCard * _(int i); MTGCard * _(int i);
MTGCard * collection[TOTAL_NUMBER_OF_CARDS]; MTGCard * collection[TOTAL_NUMBER_OF_CARDS];
MTGAllCards(); MTGAllCards();
~MTGAllCards(); ~MTGAllCards();
MTGAllCards(TexturesCache * cache); MTGAllCards(TexturesCache * cache);
void destroyAllCards(); void destroyAllCards();
MTGAllCards(const char * config_file, const char * set_name); MTGAllCards(const char * config_file, const char * set_name);
MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache); MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache);
MTGCard * getCardById(int id); MTGCard * getCardById(int id);
int load(const char * config_file, const char * setName, int autoload = 1); int load(const char * config_file, const char * setName, int autoload = 1);
int countByType(const char * _type); int countByType(const char * _type);
int countByColor(int color); int countByColor(int color);
int countBySet(int setId); int countBySet(int setId);
int readConfLine(int set_id); int readConfLine(int set_id);
int totalCards(); int totalCards();
int randomCardId(); int randomCardId();
@@ -73,18 +73,18 @@ class MTGAllCards {
class MTGDeck:public MTGAllCards{ class MTGDeck:public MTGAllCards{
protected: protected:
string filename; string filename;
MTGAllCards * allcards; MTGAllCards * allcards;
public: public:
MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards); MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards);
int addRandomCards(int howmany, int setId = -1, int rarity = -1, const char * subtype = NULL); int addRandomCards(int howmany, int setId = -1, int rarity = -1, const char * subtype = NULL);
int add(int cardid); int add(int cardid);
int remove(int cardid); int remove(int cardid);
int removeAll(); int removeAll();
int add(MTGCard * card); int add(MTGCard * card);
int remove(MTGCard * card); int remove(MTGCard * card);
int save(); 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 #define NB_BASIC_ABILITIES 38
static const char * MTGBasicAbilities[] = { static const char * MTGBasicAbilities[] = {
"trample", "trample",
"forestwalk", "forestwalk",
"islandwalk", "islandwalk",
"mountainwalk", "mountainwalk",
"swampwalk", "swampwalk",
"plainwalk", "plainwalk",
"flying", "flying",
"first strike", "first strike",
"double strike", "double strike",
"fear", "fear",
"flash", "flash",
"haste", "haste",
"lifelink", "lifelink",
"reach", "reach",
"shroud", "shroud",
"vigilance", "vigilance",
"defender", "defender",
"banding", "banding",
"protection from green", "protection from green",
"protection from blue", "protection from blue",
"protection from red", "protection from red",
"protection from black", "protection from black",
"protection from white", "protection from white",
"unblockable", "unblockable",
"wither", "wither",
"persist", "persist",
"retrace", "retrace",
"exalted", "exalted",
"legendary", "legendary",
"shadow", "shadow",
"reachshadow", "reachshadow",
"foresthome", "foresthome",
"islandhome", "islandhome",
"moutainhome", "moutainhome",
"swamphome", "swamphome",
"plainshome", "plainshome",
"flanking", "flanking",
"rampage", "rampage",
}; };
@@ -152,22 +152,22 @@ static const char * MTGBasicAbilities[] = {
static const char *MTGPhaseNames[] = static const char *MTGPhaseNames[] =
{ {
"---", "---",
"Untap", "Untap",
"Upkeep", "Upkeep",
"Draw", "Draw",
"Main phase 1", "Main phase 1",
"Combat begins", "Combat begins",
"Attackers", "Attackers",
"Blockers", "Blockers",
"Combat damage", "Combat damage",
"Combat ends", "Combat ends",
"Main phase 2", "Main phase 2",
"End of turn", "End of turn",
"cleanup", "cleanup",
"---" "---"
}; };
+2 -2
View File
@@ -14,10 +14,10 @@ class MTGGamePhase: public ActionElement {
int currentState; int currentState;
JLBFont * mFont; JLBFont * mFont;
public: public:
MTGGamePhase(int id); MTGGamePhase(int id);
virtual void Render(); virtual void Render();
virtual void Update(float dt); 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 { class MTGGameZone {
protected: protected:
Player * owner; Player * owner;
public: 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]; MTGCardInstance * cards[MTG_MAX_PLAYER_CARDS];
map<MTGCardInstance *,int> cardsMap; map<MTGCardInstance *,int> cardsMap;
int nb_cards; int nb_cards;
MTGGameZone(); MTGGameZone();
~MTGGameZone(); ~MTGGameZone();
void shuffle(); void shuffle();
virtual MTGCardInstance * draw(); virtual MTGCardInstance * draw();
void addCard(MTGCardInstance * card); void addCard(MTGCardInstance * card);
void debugPrint(); void debugPrint();
MTGCardInstance * removeCard(MTGCardInstance * card); MTGCardInstance * removeCard(MTGCardInstance * card);
MTGCardInstance * hasCard(MTGCardInstance * card); MTGCardInstance * hasCard(MTGCardInstance * card);
void cleanupPhase(); void cleanupPhase();
int countByType(const char * value); int countByType(const char * value);
int hasType(const char * value); int hasType(const char * value);
void setOwner(Player * player); void setOwner(Player * player);
MTGCardInstance * lastCardDrawn; MTGCardInstance * lastCardDrawn;
}; };
class MTGLibrary: public MTGGameZone { class MTGLibrary: public MTGGameZone {
public: public:
// MTGLibrary(); // MTGLibrary();
void shuffleTopToBottom(int nbcards); void shuffleTopToBottom(int nbcards);
MTGCardInstance * draw(); MTGCardInstance * draw();
}; };
class MTGGraveyard: public MTGGameZone { class MTGGraveyard: public MTGGameZone {
@@ -54,7 +54,7 @@ class MTGHand: public MTGGameZone {
class MTGStack: public MTGGameZone { class MTGStack: public MTGGameZone {
public: public:
}; };
class MTGInPlay: public MTGGameZone { class MTGInPlay: public MTGGameZone {
@@ -62,9 +62,9 @@ class MTGInPlay: public MTGGameZone {
//MTGInPlay(); //MTGInPlay();
void untapAll(); void untapAll();
MTGCardInstance * getNextAttacker(MTGCardInstance * previous); MTGCardInstance * getNextAttacker(MTGCardInstance * previous);
MTGCardInstance * getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker); MTGCardInstance * getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker);
int nbDefensers( MTGCardInstance * attacker); int nbDefensers( MTGCardInstance * attacker);
int nbPartners(MTGCardInstance * attacker); int nbPartners(MTGCardInstance * attacker);
}; };
@@ -77,18 +77,18 @@ class MTGPlayerCards {
MTGGraveyard * graveyard; MTGGraveyard * graveyard;
MTGHand * hand; MTGHand * hand;
MTGInPlay * inPlay; MTGInPlay * inPlay;
MTGStack * stack; MTGStack * stack;
MTGAllCards * collection; MTGAllCards * collection;
MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize); MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize);
~MTGPlayerCards(); ~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1); void initGame(int shuffle = 1, int draw = 1);
void setOwner(Player * player); void setOwner(Player * player);
void discardRandom(MTGGameZone * from); void discardRandom(MTGGameZone * from);
void drawFromLibrary(); void drawFromLibrary();
void showHand(); void showHand();
void putInGraveyard(MTGCardInstance * card); void putInGraveyard(MTGCardInstance * card);
void putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to); void putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
void putInPlay(MTGCardInstance * card); void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card); int isInPlay(MTGCardInstance * card);
+1 -1
View File
@@ -17,7 +17,7 @@ class GuiCardscontroller;
class MTGGuiHand: public GuiCardsController{ class MTGGuiHand: public GuiCardsController{
protected: protected:
int currentId[2]; int currentId[2];
Player * currentPlayer; Player * currentPlayer;
int mShowHand; int mShowHand;
float mAnimState; float mAnimState;
+33 -33
View File
@@ -11,42 +11,42 @@ class GameObserver;
class CardGui; class CardGui;
class MTGGuiPlay: public PlayGuiObjectController { class MTGGuiPlay: public PlayGuiObjectController {
protected: protected:
int offset; int offset;
Player * currentPlayer; Player * currentPlayer;
MTGCardInstance * cardsGrid[SCREEN_WIDTH/5][SCREEN_HEIGHT/5]; MTGCardInstance * cardsGrid[SCREEN_WIDTH/5][SCREEN_HEIGHT/5];
int nb_creatures; int nb_creatures;
int nb_spells; int nb_spells;
int nb_lands; int nb_lands;
int cards_x_limit; int cards_x_limit;
JQuad * phaseIcons[24]; JQuad * phaseIcons[24];
JQuad * mGlitter; JQuad * mGlitter;
int mGlitterAlpha; int mGlitterAlpha;
float mGlitterX, mGlitterY; float mGlitterX, mGlitterY;
JTexture * mPhaseBarTexture; JTexture * mPhaseBarTexture;
JQuad * mIcons[7]; JQuad * mIcons[7];
JTexture * mIconsTexture; JTexture * mIconsTexture;
JTexture * mBgTex; JTexture * mBgTex;
JQuad * mBg; JQuad * mBg;
JTexture * mBgTex2; JTexture * mBgTex2;
JQuad * mBg2; JQuad * mBg2;
int alphaBg[4]; int alphaBg[4];
void RenderPhaseBar(); void RenderPhaseBar();
void RenderPlayerInfo(int player); void RenderPlayerInfo(int player);
JLBFont* mFont; JLBFont* mFont;
void AddPlayersGuiInfo(); void AddPlayersGuiInfo();
void initCardsDisplay(); void initCardsDisplay();
void setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode); void setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode);
void setTargettingCardPosition(CardGui * cardg, int player, int playerTurn); void setTargettingCardPosition(CardGui * cardg, int player, int playerTurn);
void adjustCardPosition(CardGui * cardg); void adjustCardPosition(CardGui * cardg);
public: public:
CardGui * getByCard(MTGCardInstance * card); CardGui * getByCard(MTGCardInstance * card);
MTGGuiPlay(int id, GameObserver * game); MTGGuiPlay(int id, GameObserver * game);
~MTGGuiPlay(); ~MTGGuiPlay();
void Update(float dt); void Update(float dt);
void CheckUserInput(float dt); void CheckUserInput(float dt);
virtual void Render(); virtual void Render();
void updateCards(); void updateCards();
+70 -70
View File
@@ -1,5 +1,5 @@
/* Default observers/Abilities that are added to the game for a standard Magic Game /* Default observers/Abilities that are added to the game for a standard Magic Game
*/ */
#ifndef _MTGRULES_H_ #ifndef _MTGRULES_H_
#define _MTGRULES_H_ #define _MTGRULES_H_
@@ -9,72 +9,72 @@
class MTGAttackRule:public MTGAbility{ class MTGAttackRule:public MTGAbility{
public: public:
int isReactingToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card); int reactToClick(MTGCardInstance * card);
int testDestroy(); int testDestroy();
MTGAttackRule(int _id); MTGAttackRule(int _id);
const char * getMenuText(){return "Attacker";} const char * getMenuText(){return "Attacker";}
}; };
class MTGBlockRule:public MTGAbility{ class MTGBlockRule:public MTGAbility{
public: public:
int isReactingToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card); int reactToClick(MTGCardInstance * card);
int testDestroy(); int testDestroy();
MTGBlockRule(int _id); MTGBlockRule(int _id);
const char * getMenuText(){return "Blocker";} const char * getMenuText(){return "Blocker";}
}; };
/* Persist Rule */ /* Persist Rule */
class MTGPersistRule:public ListMaintainerAbility{ class MTGPersistRule:public ListMaintainerAbility{
public: public:
MTGPersistRule(int _id):ListMaintainerAbility(_id){}; MTGPersistRule(int _id):ListMaintainerAbility(_id){};
virtual void Update(float dt){ virtual void Update(float dt){
map<MTGCardInstance *,bool>::iterator it; map<MTGCardInstance *,bool>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){ for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * card = ((*it).first); MTGCardInstance * card = ((*it).first);
Player * p = card->controller(); Player * p = card->controller();
if (p->game->graveyard->hasCard(card)){ if (p->game->graveyard->hasCard(card)){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 1 !\n"); OutputDebugString("persist passed test 1 !\n");
#endif #endif
p->game->putInZone(card, p->game->graveyard, p->game->hand); p->game->putInZone(card, p->game->graveyard, p->game->hand);
Spell * spell = NEW Spell(card); Spell * spell = NEW Spell(card);
p->game->putInZone(card, p->game->hand, p->game->stack); p->game->putInZone(card, p->game->hand, p->game->stack);
spell->resolve(); spell->resolve();
delete spell; delete spell;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 2 !\n"); OutputDebugString("persist passed test 2 !\n");
#endif #endif
card->counters->addCounter(-1,-1); card->counters->addCounter(-1,-1);
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 3 !\n"); OutputDebugString("persist passed test 3 !\n");
#endif #endif
} }
} }
ListMaintainerAbility::Update(dt); ListMaintainerAbility::Update(dt);
} }
int canBeInList(MTGCardInstance * card){ int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[PERSIST] && !card->counters->hasCounter(-1,-1) ){ if (card->basicAbilities[PERSIST] && !card->counters->hasCounter(-1,-1) ){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("yay, persist !\n"); OutputDebugString("yay, persist !\n");
#endif #endif
return 1; return 1;
} }
return 0; 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 * 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 * owners' graveyards. This is called the "legend rule." If only one of those permanents is
* legendary, this rule doesn't apply. * legendary, this rule doesn't apply.
*/ */
class MTGLegendRule:public ListMaintainerAbility{ class MTGLegendRule:public ListMaintainerAbility{
public: public:
MTGLegendRule(int _id):ListMaintainerAbility(_id){}; MTGLegendRule(int _id):ListMaintainerAbility(_id){};
int canBeInList(MTGCardInstance * card){ int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[LEGENDARY]){ if (card->basicAbilities[LEGENDARY]){
return 1; return 1;
} }
return 0; return 0;
} }
int added(MTGCardInstance * card){ int added(MTGCardInstance * card){
map<MTGCardInstance *,bool>::iterator it; map<MTGCardInstance *,bool>::iterator it;
int destroy = 0; int destroy = 0;
for ( it=cards.begin() ; it != cards.end(); it++ ){ for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * comparison = (*it).first; MTGCardInstance * comparison = (*it).first;
if (comparison!= card && !strcmp(comparison->getName(), card->getName())){ if (comparison!= card && !strcmp(comparison->getName(), card->getName())){
comparison->owner->game->putInGraveyard(comparison); comparison->owner->game->putInGraveyard(comparison);
destroy = 1; destroy = 1;
} }
} }
if (destroy){ if (destroy){
card->owner->game->putInGraveyard(card); card->owner->game->putInGraveyard(card);
} }
return 1; return 1;
} }
int removed(MTGCardInstance * card){return 0;} int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;} int testDestroy(){return 0;}
}; };
#endif #endif
+15 -15
View File
@@ -10,29 +10,29 @@ class ManaCostHybrid;
class ManaCost{ class ManaCost{
protected: protected:
int cost[MTG_NB_COLORS+1]; int cost[MTG_NB_COLORS+1];
ManaCostHybrid * hybrids[10]; ManaCostHybrid * hybrids[10];
int nbhybrids; int nbhybrids;
public: public:
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL); static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL);
void init(); void init();
void x(); void x();
ManaCost(int _cost[], int nb_elems); ManaCost(int _cost[], int nb_elems);
ManaCost(); ManaCost();
~ManaCost(); ~ManaCost();
ManaCost(ManaCost * _manaCost); ManaCost(ManaCost * _manaCost);
void copy (ManaCost * _manaCost); void copy (ManaCost * _manaCost);
int getConvertedCost(); int getConvertedCost();
string toString(); string toString();
int getCost(int color); int getCost(int color);
int getMainColor(); int getMainColor();
int hasColor(int color); int hasColor(int color);
int remove (int color, int value); int remove (int color, int value);
int add(int color, int value); int add(int color, int value);
int addHybrid(int c1, int v1, int c2, int v2); int addHybrid(int c1, int v1, int c2, int v2);
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]); int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
void randomDiffHybrids(ManaCost * _cost, int diff[]); void randomDiffHybrids(ManaCost * _cost, int diff[]);
int add(ManaCost * _cost); int add(ManaCost * _cost);
int pay (ManaCost * _cost); int pay (ManaCost * _cost);
//return 1 if _cost can be paid with current data, 0 otherwise //return 1 if _cost can be paid with current data, 0 otherwise
int canAfford(ManaCost * _cost); int canAfford(ManaCost * _cost);
+10 -10
View File
@@ -2,16 +2,16 @@
#define _MANACOST_HYBRID_H_ #define _MANACOST_HYBRID_H_
class ManaCostHybrid{ class ManaCostHybrid{
public: public:
int color1; int color1;
int color2; int color2;
int value1; int value1;
int value2; int value2;
ManaCostHybrid(); ManaCostHybrid();
int hasColor(int color); int hasColor(int color);
ManaCostHybrid(int c1,int v1,int c2,int v2); ManaCostHybrid(int c1,int v1,int c2,int v2);
void init(int c1,int v1,int c2,int v2); void init(int c1,int v1,int c2,int v2);
int getConvertedCost(); int getConvertedCost();
}; };
#endif #endif
+21 -21
View File
@@ -12,31 +12,31 @@ class hgeParticleSystem;
class MenuItem: public JGuiObject class MenuItem: public JGuiObject
{ {
private: private:
bool mHasFocus; bool mHasFocus;
JLBFont *mFont; JLBFont *mFont;
const char* const mText; const char* const mText;
int mX; int mX;
int mY; int mY;
int updatedSinceLastRender; int updatedSinceLastRender;
float lastDt; float lastDt;
float mScale; float mScale;
float mTargetScale; float mTargetScale;
JQuad * onQuad; JQuad * onQuad;
JQuad * offQuad; JQuad * offQuad;
hgeParticleSystem* mParticleSys; hgeParticleSystem* mParticleSys;
public: 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(int id, JLBFont *font, const char* text, int x, int y, JQuad * _off, JQuad * _on, const char * particle, JQuad * particleQuad, bool hasFocus = false);
~MenuItem(); ~MenuItem();
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
virtual void Entering(); virtual void Entering();
virtual bool Leaving(u32 key); virtual bool Leaving(u32 key);
virtual bool ButtonPressed(); virtual bool ButtonPressed();
}; };
#endif #endif
+24 -24
View File
@@ -7,34 +7,34 @@
using std::string; using std::string;
class OptionItem:public JGuiObject{ class OptionItem:public JGuiObject{
public: public:
string displayValue; string displayValue;
int id, value; int id, value;
int hasFocus; int hasFocus;
int maxValue, increment; int maxValue, increment;
float x, y; float x, y;
OptionItem(int id, string _displayValue, int _maxValue = 1, int _increment = 1); OptionItem(int id, string _displayValue, int _maxValue = 1, int _increment = 1);
~OptionItem(); ~OptionItem();
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
virtual void Entering(); virtual void Entering();
virtual bool Leaving(); virtual bool Leaving();
void setData(); void setData();
virtual void updateValue(){value+=increment; if (value>maxValue) value=0;}; virtual void updateValue(){value+=increment; if (value>maxValue) value=0;};
}; };
class OptionsList{ class OptionsList{
public: public:
OptionItem * options[20]; OptionItem * options[20];
int nbitems; int nbitems;
int current; int current;
OptionsList(); OptionsList();
~OptionsList(); ~OptionsList();
void Render(); void Render();
void Update(float dt); void Update(float dt);
void Add(OptionItem * item); void Add(OptionItem * item);
void save(); void save();
}; };
#endif #endif
+16 -16
View File
@@ -5,30 +5,30 @@
using std::list; using std::list;
/* /*
The class that handles the phases of a turn The class that handles the phases of a turn
*/ */
class Player; class Player;
class Phase{ class Phase{
public: public:
int id; int id;
Player * player; Player * player;
Phase(int _id, Player * _player):id(_id),player(_player){}; Phase(int _id, Player * _player):id(_id),player(_player){};
}; };
class PhaseRing{ class PhaseRing{
public: public:
list<Phase *> ring; list<Phase *> ring;
list<Phase *>::iterator current; list<Phase *>::iterator current;
Phase * getCurrentPhase(); Phase * getCurrentPhase();
Phase * forward(); Phase * forward();
Phase * goToPhase(int id, Player * player); Phase * goToPhase(int id, Player * player);
PhaseRing(Player* players[], int nbPlayers=2); PhaseRing(Player* players[], int nbPlayers=2);
~PhaseRing(); ~PhaseRing();
int addPhase(Phase * phase); int addPhase(Phase * phase);
int addPhaseBefore(int id, Player* player,int after_id, Player * after_player, int allOccurences = 1); int addPhaseBefore(int id, Player* player,int after_id, Player * after_player, int allOccurences = 1);
int removePhase (int id, Player * player, int allOccurences = 1); int removePhase (int id, Player * player, int allOccurences = 1);
}; };
#endif #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_ #ifndef _PLAYGUIOBJECT_H_
@@ -23,55 +23,55 @@ class PlayGuiObject: public JGuiObject, public JGuiListener{
int wave; int wave;
float mHeight; float mHeight;
float defaultHeight; float defaultHeight;
bool mHasFocus; bool mHasFocus;
int x; int x;
int y; int y;
int type; int type;
virtual void Entering(){mHasFocus = true;}; virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;}; virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;}; virtual bool ButtonPressed(){return true;};
virtual void Render(){}; virtual void Render(){};
virtual void Update(float dt); virtual void Update(float dt);
PlayGuiObject(int id, float desiredHeight,float _x, float _y, bool hasFocus); PlayGuiObject(int id, float desiredHeight,float _x, float _y, bool hasFocus);
virtual void ButtonPressed(int controllerId, int controlId){}; virtual void ButtonPressed(int controllerId, int controlId){};
virtual ~PlayGuiObject(){}; virtual ~PlayGuiObject(){};
}; };
class GuiAvatar: public PlayGuiObject{ class GuiAvatar: public PlayGuiObject{
protected: protected:
int avatarRed; int avatarRed;
int currentLife; int currentLife;
public: public:
Player * player; Player * player;
virtual void Render(); virtual void Render();
GuiAvatar(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * _player); GuiAvatar(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * _player);
}; };
class GuiGameZone: public PlayGuiObject{ class GuiGameZone: public PlayGuiObject{
protected: protected:
MTGGameZone * zone; MTGGameZone * zone;
public: public:
CardDisplay * cd; CardDisplay * cd;
int showCards; int showCards;
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
GuiGameZone(int id, float desiredHeight,float _x, float _y, bool hasFocus,MTGGameZone * _zone); GuiGameZone(int id, float desiredHeight,float _x, float _y, bool hasFocus,MTGGameZone * _zone);
~GuiGameZone(); ~GuiGameZone();
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
void toggleDisplay(); void toggleDisplay();
}; };
class GuiGraveyard: public GuiGameZone{ class GuiGraveyard: public GuiGameZone{
public: public:
GuiGraveyard(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player); GuiGraveyard(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
}; };
class GuiLibrary: public GuiGameZone{ class GuiLibrary: public GuiGameZone{
public: public:
GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player); GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
}; };
@@ -8,11 +8,11 @@ class PlayGuiObjectController : public GuiLayer{
protected: protected:
int getClosestItem(int direction); int getClosestItem(int direction);
int getClosestItem(int direction, float tolerance); int getClosestItem(int direction, float tolerance);
static bool showBigCards; static bool showBigCards;
public: public:
virtual void Update(float dt); virtual void Update(float dt);
virtual void CheckUserInput(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();}; virtual void Render(){GuiLayer::Render();};
}; };
+13 -13
View File
@@ -15,27 +15,27 @@ class Player: public Damageable, public Targetable{
ManaCost * manaPool; ManaCost * manaPool;
public: public:
int typeAsTarget(){return TARGET_PLAYER;} int typeAsTarget(){return TARGET_PLAYER;}
virtual int displayStack(){return 1;} virtual int displayStack(){return 1;}
JTexture * mAvatarTex; JTexture * mAvatarTex;
JQuad * mAvatar; JQuad * mAvatar;
int canPutLandsIntoPlay; int canPutLandsIntoPlay;
MTGPlayerCards * game; MTGPlayerCards * game;
int testLife(); int testLife();
int afterDamage(); int afterDamage();
Player(MTGPlayerCards * _deck, string deckFile); Player(MTGPlayerCards * _deck, string deckFile);
virtual ~Player(); virtual ~Player();
void unTapPhase(); void unTapPhase();
MTGInPlay * inPlay(); MTGInPlay * inPlay();
ManaCost * getManaPool(); ManaCost * getManaPool();
int manaBurn(); int manaBurn();
void cleanupPhase(); void cleanupPhase();
virtual int Act(float dt){return 0;}; virtual int Act(float dt){return 0;};
virtual int isAI(){return 0;}; virtual int isAI(){return 0;};
Player * opponent(); Player * opponent();
int getId(); int getId();
JQuad * getIcon(); JQuad * getIcon();
string deckFile; string deckFile;
}; };
class HumanPlayer: public Player{ class HumanPlayer: public Player{
+7 -7
View File
@@ -6,13 +6,13 @@
#include "../include/MTGDeck.h" #include "../include/MTGDeck.h"
class PlayerData{ class PlayerData{
protected: protected:
public: public:
int credits; int credits;
MTGDeck * collection; MTGDeck * collection;
PlayerData(MTGAllCards * allcards); PlayerData(MTGAllCards * allcards);
~PlayerData(); ~PlayerData();
int save(); int save();
}; };
#endif #endif
+15 -15
View File
@@ -7,24 +7,24 @@
#include <stdio.h> #include <stdio.h>
class Price{ class Price{
public: public:
int cardid; int cardid;
int price; int price;
Price(int _cardid, int _price); Price(int _cardid, int _price);
}; };
class PriceList{ class PriceList{
private: private:
MTGAllCards * collection; MTGAllCards * collection;
string filename; string filename;
Price * prices[TOTAL_NUMBER_OF_CARDS]; Price * prices[TOTAL_NUMBER_OF_CARDS];
int nbprices; int nbprices;
public: public:
PriceList(const char * file, MTGAllCards * _collection); PriceList(const char * file, MTGAllCards * _collection);
~PriceList(); ~PriceList();
int save(); int save();
int getPrice(int cardId); int getPrice(int cardId);
int setPrice(int cardId, int price); int setPrice(int cardId, int price);
}; };
+46 -46
View File
@@ -13,59 +13,59 @@
using std::string; using std::string;
class ShopItem:public JGuiObject{ class ShopItem:public JGuiObject{
private: private:
bool mHasFocus; bool mHasFocus;
JLBFont *mFont; JLBFont *mFont;
string mText; string mText;
int mX; int mX;
int mY; int mY;
JQuad * quad; JQuad * quad;
JQuad * thumb; JQuad * thumb;
float mScale; float mScale;
float mTargetScale; float mTargetScale;
public: public:
int quantity; int quantity;
MTGCard * card; MTGCard * card;
int price; int price;
ShopItem(int id, JLBFont * font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, 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(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,int x, int y, bool hasFocus, int _price);
~ShopItem(); ~ShopItem();
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
virtual void Entering(); virtual void Entering();
virtual bool Leaving(u32 key); virtual bool Leaving(u32 key);
virtual bool ButtonPressed(); virtual bool ButtonPressed();
const char * getText(); const char * getText();
}; };
class ShopItems:public JGuiController,public JGuiListener{ class ShopItems:public JGuiController,public JGuiListener{
private: private:
PlayerData * playerdata; PlayerData * playerdata;
PriceList * pricelist; PriceList * pricelist;
int mX, mY, mHeight; int mX, mY, mHeight;
JLBFont* mFont; JLBFont* mFont;
MTGAllCards * collection; MTGAllCards * collection;
SimpleMenu * dialog; SimpleMenu * dialog;
int showPriceDialog; int showPriceDialog;
int setId; int setId;
MTGCardInstance * displayCards[100]; MTGCardInstance * displayCards[100];
CardDisplay * display; CardDisplay * display;
void safeDeleteDisplay(); void safeDeleteDisplay();
public: public:
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int setId); ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int setId);
~ShopItems(); ~ShopItems();
void Render(); void Render();
virtual void Update(float dt); virtual void Update(float dt);
void Add(int cardid); void Add(int cardid);
void Add(char * text, JQuad * quad, JQuad * thumb,int _price); void Add(char * text, JQuad * quad, JQuad * thumb,int _price);
void pricedialog(int id, int mode=1); void pricedialog(int id, int mode=1);
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
void savePriceList(); void savePriceList();
void saveAll(); void saveAll();
}; };
#endif #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_ #ifndef _SIMPLEMENU_H_
#define _SIMPLEMENU_H_ #define _SIMPLEMENU_H_
@@ -9,15 +9,15 @@ A class for very simple menus structure
#include <string> #include <string>
class SimpleMenu:public JGuiController{ class SimpleMenu:public JGuiController{
private: private:
int mHeight, mWidth, mX, mY; int mHeight, mWidth, mX, mY;
JLBFont* mFont; JLBFont* mFont;
std::string title; std::string title;
int displaytitle; int displaytitle;
public: public:
SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, int width, const char * _title = NULL); SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, int width, const char * _title = NULL);
void Render(); void Render();
void Add(int id, const char * Text); void Add(int id, const char * Text);
}; };
+15 -15
View File
@@ -10,27 +10,27 @@
class SimpleMenuItem: public JGuiObject class SimpleMenuItem: public JGuiObject
{ {
private: private:
bool mHasFocus; bool mHasFocus;
JLBFont *mFont; JLBFont *mFont;
const char* mText; const char* mText;
int mX; int mX;
int mY; int mY;
float mScale; float mScale;
float mTargetScale; float mTargetScale;
public: public:
SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus = false); SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus = false);
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
virtual void Entering(); virtual void Entering();
virtual bool Leaving(u32 key); virtual bool Leaving(u32 key);
virtual bool ButtonPressed(); virtual bool ButtonPressed();
}; };
#endif #endif
+10 -10
View File
@@ -8,17 +8,17 @@ using std::string;
using std::map; using std::map;
class Subtypes{ class Subtypes{
protected: protected:
int nb_items; int nb_items;
map<string,int> values; map<string,int> values;
public: public:
static Subtypes * subtypesList; static Subtypes * subtypesList;
Subtypes(); Subtypes();
int Add(const char * subtype); int Add(const char * subtype);
int find(const char * subtype); int find(const char * subtype);
int Add(string subtype); int Add(string subtype);
int find(string subtype); int find(string subtype);
}; };
+64 -64
View File
@@ -23,22 +23,22 @@ class CardDescriptor;
class TargetChooser: public TargetsList { class TargetChooser: public TargetsList {
protected: protected:
int forceTargetListReady; int forceTargetListReady;
public: public:
TargetChooser(MTGCardInstance * card = NULL, int _maxtargets = -1); TargetChooser(MTGCardInstance * card = NULL, int _maxtargets = -1);
MTGCardInstance * source; //Optionnal source, used for protection from... MTGCardInstance * source; //Optionnal source, used for protection from...
int maxtargets; //Set to -1 for "unlimited" int maxtargets; //Set to -1 for "unlimited"
int ForceTargetListReady(); int ForceTargetListReady();
int targetsReadyCheck(); int targetsReadyCheck();
virtual int addTarget(Targetable * target); virtual int addTarget(Targetable * target);
virtual int canTarget(Targetable * _target); virtual int canTarget(Targetable * _target);
virtual int full(){if (maxtargets != -1 && cursor>=maxtargets) {return 1;} else{return 0;}}; virtual int full(){if (maxtargets != -1 && cursor>=maxtargets) {return 1;} else{return 0;}};
virtual int ready(){return cursor;}; virtual int ready(){return cursor;};
int targetListSet(); int targetListSet();
}; };
@@ -46,94 +46,94 @@ public:
class TargetChooserFactory{ class TargetChooserFactory{
public: public:
TargetChooser * createTargetChooser(string s, MTGCardInstance * card); TargetChooser * createTargetChooser(string s, MTGCardInstance * card);
TargetChooser * createTargetChooser(MTGCardInstance * card); TargetChooser * createTargetChooser(MTGCardInstance * card);
}; };
class TargetZoneChooser:public TargetChooser{ class TargetZoneChooser:public TargetChooser{
public: public:
MTGGameZone * zones[6]; MTGGameZone * zones[6];
int nbzones; int nbzones;
int init(MTGGameZone ** _zones, int _nbzones); int init(MTGGameZone ** _zones, int _nbzones);
TargetZoneChooser(MTGCardInstance * card = NULL, int _maxtargets = 1); TargetZoneChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
TargetZoneChooser(MTGGameZone ** _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1); TargetZoneChooser(MTGGameZone ** _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card); virtual int canTarget(Targetable * _card);
}; };
class CreatureTargetChooser:public TargetZoneChooser{ class CreatureTargetChooser:public TargetZoneChooser{
public: public:
int maxpower; int maxpower;
int maxtoughness; int maxtoughness;
CreatureTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1); CreatureTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1);
CreatureTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1); CreatureTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card); virtual int canTarget(Targetable * _card);
}; };
class DamageableTargetChooser:public CreatureTargetChooser{ class DamageableTargetChooser:public CreatureTargetChooser{
public: public:
DamageableTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser( _zones,_nbzones, card, _maxtargets){}; 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){}; DamageableTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
}; };
class PlayerTargetChooser:public TargetChooser{ class PlayerTargetChooser:public TargetChooser{
public: public:
PlayerTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):TargetChooser(card, _maxtargets){}; PlayerTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):TargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
}; };
class TypeTargetChooser:public TargetZoneChooser{ class TypeTargetChooser:public TargetZoneChooser{
public: public:
int nbtypes; int nbtypes;
int types[10]; int types[10];
TypeTargetChooser(const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1); TypeTargetChooser(const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1);
TypeTargetChooser(const char * _type, MTGGameZone ** _zones, int nbzones, 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(int type);
void addType(const char * type); void addType(const char * type);
virtual int canTarget(Targetable * targe); virtual int canTarget(Targetable * targe);
}; };
class DescriptorTargetChooser:public TargetZoneChooser{ class DescriptorTargetChooser:public TargetZoneChooser{
public: public:
CardDescriptor * cd; CardDescriptor * cd;
DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1); DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1);
DescriptorTargetChooser(CardDescriptor * _cd, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1); DescriptorTargetChooser(CardDescriptor * _cd, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
}; };
class SpellTargetChooser:public TargetChooser{ class SpellTargetChooser:public TargetChooser{
public: public:
int color; int color;
SpellTargetChooser( MTGCardInstance * card = NULL,int _color = -1, int _maxtargets = 1 ); SpellTargetChooser( MTGCardInstance * card = NULL,int _color = -1, int _maxtargets = 1 );
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
}; };
class SpellOrPermanentTargetChooser:public TargetZoneChooser{ class SpellOrPermanentTargetChooser:public TargetZoneChooser{
public: public:
int color; int color;
SpellOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1); SpellOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
}; };
class DamageTargetChooser:public TargetChooser{ class DamageTargetChooser:public TargetChooser{
public: public:
int color; int color;
int state; int state;
DamageTargetChooser( MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1, int state = NOT_RESOLVED); DamageTargetChooser( MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1, int state = NOT_RESOLVED);
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
}; };
class DamageOrPermanentTargetChooser:public TargetZoneChooser{ class DamageOrPermanentTargetChooser:public TargetZoneChooser{
public: public:
int color; int color;
DamageOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1); DamageOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
}; };
#endif #endif
+2 -2
View File
@@ -6,8 +6,8 @@
#define TARGET_STACKACTION 3 #define TARGET_STACKACTION 3
class Targetable{ class Targetable{
public: public:
virtual int typeAsTarget() = 0; virtual int typeAsTarget() = 0;
}; };
#endif #endif
+16 -16
View File
@@ -12,23 +12,23 @@ class Interruptible;
class Damage; class Damage;
class TargetsList{ class TargetsList{
public: public:
int cursor; int cursor;
TargetsList(); TargetsList();
TargetsList(Targetable * _targets[], int nbtargets); TargetsList(Targetable * _targets[], int nbtargets);
Targetable* targets[MAX_TARGETS]; Targetable* targets[MAX_TARGETS];
int alreadyHasTarget(Targetable * target); int alreadyHasTarget(Targetable * target);
int removeTarget(Targetable * _card); int removeTarget(Targetable * _card);
int toggleTarget(Targetable * _card); int toggleTarget(Targetable * _card);
virtual int addTarget(Targetable * _target); virtual int addTarget(Targetable * _target);
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0); MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0); Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0); Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type); Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0); Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0); Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous, int type); Targetable * getNextTarget(Targetable * previous, int type);
void initTargets(){cursor = 0;}; void initTargets(){cursor = 0;};
}; };
#endif #endif
+52 -52
View File
@@ -7,76 +7,76 @@
#include "../include/AIPlayer.h" #include "../include/AIPlayer.h"
class TestSuiteActions{ class TestSuiteActions{
public: public:
int nbitems; int nbitems;
string actions[MAX_TESTSUITE_ACTIONS]; string actions[MAX_TESTSUITE_ACTIONS];
void add(string action); void add(string action);
TestSuiteActions(); TestSuiteActions();
void cleanup(); void cleanup();
}; };
class TestSuitePlayerZone{ class TestSuitePlayerZone{
public: public:
int cards[MAX_TESTUITE_CARDS]; int cards[MAX_TESTUITE_CARDS];
int nbitems; int nbitems;
void add(int cardid); void add(int cardid);
TestSuitePlayerZone(); TestSuitePlayerZone();
void cleanup(); void cleanup();
}; };
class TestSuitePlayerData{ class TestSuitePlayerData{
public: public:
int life; int life;
ManaCost * manapool; ManaCost * manapool;
TestSuitePlayerZone zones[5]; TestSuitePlayerZone zones[5];
TestSuitePlayerData(); TestSuitePlayerData();
~TestSuitePlayerData(); ~TestSuitePlayerData();
void cleanup(); void cleanup();
}; };
class TestSuiteState{ class TestSuiteState{
public: public:
int phase; int phase;
void parsePlayerState(int playerId, string s); void parsePlayerState(int playerId, string s);
TestSuiteState(); TestSuiteState();
TestSuitePlayerData playerData[2]; TestSuitePlayerData playerData[2];
void cleanup(); void cleanup();
}; };
class TestSuite{ class TestSuite{
public: public:
float timerLimit; float timerLimit;
int currentAction; int currentAction;
TestSuiteState initState; TestSuiteState initState;
TestSuiteState endState; TestSuiteState endState;
TestSuiteActions actions; TestSuiteActions actions;
string files[128]; string files[128];
int nbfiles; int nbfiles;
int currentfile; int currentfile;
void load(const char * filename); void load(const char * filename);
TestSuite(const char * filename); TestSuite(const char * filename);
void initGame(); void initGame();
int assertGame(); int assertGame();
MTGPlayerCards * buildDeck(MTGAllCards * collection, int playerId); MTGPlayerCards * buildDeck(MTGAllCards * collection, int playerId);
string getNextAction(); string getNextAction();
int phaseStrToInt(string s); int phaseStrToInt(string s);
MTGCardInstance * getCardByMTGId(int mtgid); MTGCardInstance * getCardByMTGId(int mtgid);
Interruptible * getActionByMTGId(int mtgid); Interruptible * getActionByMTGId(int mtgid);
int loadNext(); int loadNext();
void cleanup(); void cleanup();
int Log(const char * text); int Log(const char * text);
}; };
class TestSuiteAI:public AIPlayer{ class TestSuiteAI:public AIPlayer{
public: public:
TestSuite * suite; TestSuite * suite;
float timer; float timer;
TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId); TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId);
virtual int Act(float dt); virtual int Act(float dt);
virtual int displayStack(){return 1;} virtual int displayStack(){return 1;}
}; };
+9 -9
View File
@@ -22,9 +22,9 @@ class CardTexture{
JTexture* tex; JTexture* tex;
JQuad* quad; JQuad* quad;
public: public:
int lastTime; int lastTime;
int type; int type;
int nbpixels; int nbpixels;
int getId(); int getId();
JQuad * getQuad(); JQuad * getQuad();
@@ -39,18 +39,18 @@ class TexturesCache{
int lastTime; int lastTime;
int nb_textures; int nb_textures;
int delete_previous; int delete_previous;
int totalsize; int totalsize;
CardTexture * cache[MAX_CACHE_OBJECTS]; CardTexture * cache[MAX_CACHE_OBJECTS];
public: public:
int isInCache(MTGCard * card, int type=CACHE_CARD); int isInCache(MTGCard * card, int type=CACHE_CARD);
TexturesCache(); TexturesCache();
~TexturesCache(); ~TexturesCache();
int getOldestQuad(); int getOldestQuad();
void removeQuad(int id); void removeQuad(int id);
int cleanup(); int cleanup();
int getCacheById(int id, int type=CACHE_CARD); int getCacheById(int id, int type=CACHE_CARD);
JQuad * getQuad(MTGCard * card, 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 #endif
#ifdef LINUX #ifdef LINUX
#ifdef _DEBUG #ifdef _DEBUG
#define OutputDebugString(val) (std::cerr << val); #define OutputDebugString(val) (std::cerr << val);
#else #else
#define OutputDebugString(val) {} #define OutputDebugString(val) {}
#endif #endif
#endif #endif
#endif #endif
+1 -1
View File
@@ -33,7 +33,7 @@
using std::string; using std::string;
template <typename T, size_t N> template <typename T, size_t N>
char ( &_ArraySizeHelper( T (&array)[N] ))[N]; char ( &_ArraySizeHelper( T (&array)[N] ))[N];
#define countof( array ) (sizeof( _ArraySizeHelper( array ) )) #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" #include "../include/MTGCardInstance.h"
bool compare_aistats(AIStat * first, AIStat * second){ bool compare_aistats(AIStat * first, AIStat * second){
float damage1 = first->value / first->occurences; float damage1 = first->value / first->occurences;
float damage2 = second->value/ second->occurences; float damage2 = second->value/ second->occurences;
return (damage1 > damage2); return (damage1 > damage2);
} }
AIStats::AIStats(Player * _player, char * _filename){ AIStats::AIStats(Player * _player, char * _filename){
filename = _filename; filename = _filename;
load(_filename); load(_filename);
player = _player; player = _player;
} }
AIStats::~AIStats(){ AIStats::~AIStats(){
list<AIStat *>::iterator it; list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){ for ( it=stats.begin() ; it != stats.end(); it++ ){
AIStat * stat = *it; AIStat * stat = *it;
delete stat; delete stat;
} }
} }
void AIStats::updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier){ void AIStats::updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier){
MTGCard * card = cardInstance->model; MTGCard * card = cardInstance->model;
AIStat * stat = find(card); AIStat * stat = find(card);
if (!stat){ if (!stat){
stat = NEW AIStat(card->getMTGId(),0,1,0); stat = NEW AIStat(card->getMTGId(),0,1,0);
stats.push_back(stat); stats.push_back(stat);
} }
if (damage->target == player){ if (damage->target == player){
stat->value+= multiplier * STATS_PLAYER_MULTIPLIER * damage->damage; stat->value+= multiplier * STATS_PLAYER_MULTIPLIER * damage->damage;
}else if (damage->target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){ }else if (damage->target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){
MTGCardInstance * target = (MTGCardInstance *)damage->target; MTGCardInstance * target = (MTGCardInstance *)damage->target;
if (target->controller() == player && !target->isInPlay()){ if (target->controller() == player && !target->isInPlay()){
//One of my creatures got lethal damage... //One of my creatures got lethal damage...
stat->value+= multiplier * STATS_CREATURE_MULTIPLIER * damage->damage; stat->value+= multiplier * STATS_CREATURE_MULTIPLIER * damage->damage;
} }
} }
} }
void AIStats::updateStats(){ void AIStats::updateStats(){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
ActionStack * as = game->mLayers->stackLayer(); ActionStack * as = game->mLayers->stackLayer();
Damage * damage = ((Damage * )as->getNext(NULL,ACTION_DAMAGE, RESOLVED_OK)); Damage * damage = ((Damage * )as->getNext(NULL,ACTION_DAMAGE, RESOLVED_OK));
MTGGameZone * opponentZone = player->opponent()->game->inPlay; MTGGameZone * opponentZone = player->opponent()->game->inPlay;
while(damage){ while(damage){
MTGCardInstance * card = damage->source; MTGCardInstance * card = damage->source;
updateStatsCard(card,damage); updateStatsCard(card,damage);
//Auras on damage source can be the cause //Auras on damage source can be the cause
for (int i=0; i < opponentZone->nb_cards; i++){ for (int i=0; i < opponentZone->nb_cards; i++){
MTGCardInstance * aura = opponentZone->cards[i]; MTGCardInstance * aura = opponentZone->cards[i];
if (aura->target == card){ if (aura->target == card){
updateStatsCard(aura,damage, STATS_AURA_MULTIPLIER); updateStatsCard(aura,damage, STATS_AURA_MULTIPLIER);
} }
} }
damage = ((Damage * )as->getNext(damage,ACTION_DAMAGE, RESOLVED_OK)); damage = ((Damage * )as->getNext(damage,ACTION_DAMAGE, RESOLVED_OK));
} }
stats.sort(compare_aistats); stats.sort(compare_aistats);
save(); save();
} }
bool AIStats::isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue ){ bool AIStats::isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue ){
if (stats.size()<max) return tooSmallCountsForTrue; if (stats.size()<max) return tooSmallCountsForTrue;
unsigned int n = 0; unsigned int n = 0;
MTGCard * source = card->model; MTGCard * source = card->model;
int id = source->getMTGId(); int id = source->getMTGId();
list<AIStat *>::iterator it; list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){ for ( it=stats.begin() ; it != stats.end(); it++ ){
if (n >= max) return false; if (n >= max) return false;
AIStat * stat = *it; AIStat * stat = *it;
if (stat->source == id){ if (stat->source == id){
if (stat->value>=0) return true; if (stat->value>=0) return true;
return false; return false;
} }
n++; n++;
} }
return false; return false;
} }
AIStat * AIStats::find(MTGCard * source){ AIStat * AIStats::find(MTGCard * source){
int id = source->getMTGId(); int id = source->getMTGId();
list<AIStat *>::iterator it; list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){ for ( it=stats.begin() ; it != stats.end(); it++ ){
AIStat * stat = *it; AIStat * stat = *it;
if (stat->source == id) return stat; if (stat->source == id) return stat;
} }
return NULL; return NULL;
} }
void AIStats::load(char * filename){ void AIStats::load(char * filename){
std::ifstream file(filename); std::ifstream file(filename);
std::string s; std::string s;
if(file){ if(file){
while(std::getline(file,s)){ while(std::getline(file,s)){
int cardid = atoi(s.c_str()); int cardid = atoi(s.c_str());
std::getline(file,s); std::getline(file,s);
int value = atoi(s.c_str()); int value = atoi(s.c_str());
std::getline(file,s); std::getline(file,s);
int direct = atoi(s.c_str()); int direct = atoi(s.c_str());
AIStat * stat = NEW AIStat(cardid,value,1,direct); AIStat * stat = NEW AIStat(cardid,value,1,direct);
stats.push_back(stat); stats.push_back(stat);
} }
file.close(); file.close();
}else{ }else{
//TODO Error management //TODO Error management
} }
} }
void AIStats::save(){ void AIStats::save(){
std::ofstream file(filename.c_str()); std::ofstream file(filename.c_str());
char writer[128]; char writer[128];
if (file){ if (file){
list<AIStat *>::iterator it; list<AIStat *>::iterator it;
for ( it=stats.begin() ; it != stats.end(); it++ ){ for ( it=stats.begin() ; it != stats.end(); it++ ){
AIStat * stat = *it; AIStat * stat = *it;
if (stat->value > 0){ if (stat->value > 0){
sprintf(writer,"%i\n%i\n%i\n", stat->source,stat->value/2,stat->direct); sprintf(writer,"%i\n%i\n%i\n", stat->source,stat->value/2,stat->direct);
file<<writer; file<<writer;
} }
} }
file.close(); file.close();
} }
} }
+27 -27
View File
@@ -4,52 +4,52 @@
#include "../include/TargetChooser.h" #include "../include/TargetChooser.h"
ActionElement::ActionElement(int id):JGuiObject(id){ ActionElement::ActionElement(int id):JGuiObject(id){
activeState = INACTIVE; activeState = INACTIVE;
modal = 0; modal = 0;
waitingForAnswer = 0; waitingForAnswer = 0;
currentPhase = -1; currentPhase = -1;
newPhase = -1; newPhase = -1;
tc = NULL; tc = NULL;
} }
/* /*
void ActionElement::RenderMessageBackground(float y0, int _height){ void ActionElement::RenderMessageBackground(float y0, int _height){
float height = _height; float height = _height;
PIXEL_TYPE colors_up[] = PIXEL_TYPE colors_up[] =
{ {
ARGB(0,255,255,255), ARGB(0,255,255,255),
ARGB(0,255,255,255), ARGB(0,255,255,255),
ARGB(128,255,255,255), ARGB(128,255,255,255),
ARGB(128,255,255,255) ARGB(128,255,255,255)
}; };
PIXEL_TYPE colors_down[] = PIXEL_TYPE colors_down[] =
{ {
ARGB(128,255,255,255), ARGB(128,255,255,255),
ARGB(128,255,255,255), ARGB(128,255,255,255),
ARGB(0,255,255,255), ARGB(0,255,255,255),
ARGB(0,255,255,255) ARGB(0,255,255,255)
}; };
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRect(0,y0,SCREEN_WIDTH,height/2,colors_up); renderer->FillRect(0,y0,SCREEN_WIDTH,height/2,colors_up);
renderer->FillRect(0,y0+height/2,SCREEN_WIDTH,height/2,colors_down); 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,SCREEN_WIDTH,y0,ARGB(128,255,255,255));
// mEngine->DrawLine(0,y0+height,SCREEN_WIDTH,y0+height,ARGB(128,255,255,255)); // mEngine->DrawLine(0,y0+height,SCREEN_WIDTH,y0+height,ARGB(128,255,255,255));
}*/ }*/
int ActionElement::getActivity(){ int ActionElement::getActivity(){
return activeState; return activeState;
} }
int ActionElement::isReactingToTargetClick(Targetable * object){ int ActionElement::isReactingToTargetClick(Targetable * object){
if (object && object->typeAsTarget() == TARGET_CARD) return isReactingToClick((MTGCardInstance *)object); if (object && object->typeAsTarget() == TARGET_CARD) return isReactingToClick((MTGCardInstance *)object);
return 0; return 0;
} }
int ActionElement::reactToTargetClick(Targetable * object){ int ActionElement::reactToTargetClick(Targetable * object){
if (object->typeAsTarget() == TARGET_CARD) return reactToClick((MTGCardInstance *)object); if (object->typeAsTarget() == TARGET_CARD) return reactToClick((MTGCardInstance *)object);
return 0; return 0;
} }
+132 -132
View File
@@ -5,195 +5,195 @@
int ActionLayer::unstopableRenderInProgress(){ int ActionLayer::unstopableRenderInProgress(){
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){ if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->getActivity() > 0){ if (currentAction->getActivity() > 0){
return 1; return 1;
} }
} }
} }
return 0; return 0;
} }
void ActionLayer::CheckUserInput(float dt){ void ActionLayer::CheckUserInput(float dt){
if (menuObject){ if (menuObject){
abilitiesMenu->Update(dt); abilitiesMenu->Update(dt);
return; return;
} }
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){ if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
currentAction->CheckUserInput(dt); currentAction->CheckUserInput(dt);
} }
} }
} }
void ActionLayer::Update(float dt){ void ActionLayer::Update(float dt){
if (menuObject){ if (menuObject){
return; return;
} }
modal = 0; modal = 0;
for (int i=mCount -1 ;i>=0;i--){ for (int i=mCount -1 ;i>=0;i--){
if (mObjects[i]!= NULL){ if (mObjects[i]!= NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->testDestroy()){ if (currentAction->testDestroy()){
currentAction->destroy(); currentAction->destroy();
Remove(currentAction); Remove(currentAction);
} }
} }
} }
int newPhase = GameObserver::GetInstance()->getCurrentGamePhase(); int newPhase = GameObserver::GetInstance()->getCurrentGamePhase();
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){ if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
currentAction->newPhase = newPhase; currentAction->newPhase = newPhase;
currentAction->Update(dt); currentAction->Update(dt);
currentAction->currentPhase = newPhase; currentAction->currentPhase = newPhase;
} }
} }
} }
void ActionLayer::Render (){ void ActionLayer::Render (){
if (menuObject){ if (menuObject){
abilitiesMenu->Render(); abilitiesMenu->Render();
return; return;
} }
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){ if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
//if (currentAction->getActivity() > 0){ //if (currentAction->getActivity() > 0){
currentAction->Render(); currentAction->Render();
//return; //return;
//} //}
} }
} }
} }
TargetChooser * ActionLayer::getCurrentTargetChooser(){ TargetChooser * ActionLayer::getCurrentTargetChooser(){
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return currentAction->tc; if(currentAction->waitingForAnswer) return currentAction->tc;
} }
return NULL; return NULL;
} }
int ActionLayer::isWaitingForAnswer(){ int ActionLayer::isWaitingForAnswer(){
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return 1; if(currentAction->waitingForAnswer) return 1;
} }
return 0; return 0;
} }
int ActionLayer::isReactingToTargetClick(Targetable * card){ 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++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToTargetClick(card); result += currentAction->isReactingToTargetClick(card);
} }
return result; return result;
} }
int ActionLayer::reactToTargetClick(Targetable * card){ int ActionLayer::reactToTargetClick(Targetable * card){
int result = 0; int result = 0;
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){ if(currentAction->waitingForAnswer){
return currentAction->reactToTargetClick(card); return currentAction->reactToTargetClick(card);
} }
} }
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->reactToTargetClick(card); result += currentAction->reactToTargetClick(card);
} }
return result; return result;
} }
//TODO Simplify with only object !!! //TODO Simplify with only object !!!
int ActionLayer::isReactingToClick(MTGCardInstance * card){ int ActionLayer::isReactingToClick(MTGCardInstance * card){
int result = 0; int result = 0;
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return -1; if(currentAction->waitingForAnswer) return -1;
} }
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToClick(card); result += currentAction->isReactingToClick(card);
} }
return result; return result;
} }
int ActionLayer::reactToClick(MTGCardInstance * card){ int ActionLayer::reactToClick(MTGCardInstance * card){
int result = 0; int result = 0;
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){ if(currentAction->waitingForAnswer){
return currentAction->reactToClick(card); return currentAction->reactToClick(card);
} }
} }
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->reactToClick(card); result += currentAction->reactToClick(card);
} }
return result; return result;
} }
int ActionLayer::isModal(){ int ActionLayer::isModal(){
if (modal) return 1; if (modal) return 1;
if (menuObject) return 1; if (menuObject) return 1;
for (int i=0; i<mCount; i++){ for (int i=0; i<mCount; i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->modal) return 1; if (currentAction->modal) return 1;
} }
return 0; return 0;
} }
void ActionLayer::setMenuObject(Targetable * object){ void ActionLayer::setMenuObject(Targetable * object){
menuObject = object; menuObject = object;
if (abilitiesMenu){ if (abilitiesMenu){
delete abilitiesMenu; delete abilitiesMenu;
} }
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT); JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
abilitiesMenu = NEW SimpleMenu(10, this, mFont, 100, 100, 200); abilitiesMenu = NEW SimpleMenu(10, this, mFont, 100, 100, 200);
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->isReactingToTargetClick(object)){ if (currentAction->isReactingToTargetClick(object)){
abilitiesMenu->Add(i,currentAction->getMenuText()); abilitiesMenu->Add(i,currentAction->getMenuText());
} }
} }
abilitiesMenu->Add(-1, "Cancel"); abilitiesMenu->Add(-1, "Cancel");
modal = 1; modal = 1;
} }
void ActionLayer::ButtonPressed(int controllerid, int controlid){ void ActionLayer::ButtonPressed(int controllerid, int controlid){
if (controlid == -1){ if (controlid == -1){
}else{ }else{
ActionElement * currentAction = (ActionElement *)mObjects[controlid]; ActionElement * currentAction = (ActionElement *)mObjects[controlid];
currentAction->reactToTargetClick(menuObject); currentAction->reactToTargetClick(menuObject);
} }
menuObject = 0; menuObject = 0;
} }
File diff suppressed because it is too large Load Diff
+60 -60
View File
@@ -2,114 +2,114 @@
#include "../include/Blocker.h" #include "../include/Blocker.h"
Blocker::Blocker(int id, MTGCardInstance * card):MTGAbility(id, card){ 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){ 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){ Blocker::Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost):MTGAbility(id, card,_target){
init(_cost); init(_cost);
} }
Blocker::~Blocker(){ Blocker::~Blocker(){
delete manaCost; delete manaCost;
} }
void Blocker::init(ManaCost * _cost){ void Blocker::init(ManaCost * _cost){
currentPhase = -1; currentPhase = -1;
manaCost = _cost; manaCost = _cost;
} }
//Default behaviour for blockers : they block the card they're attached to //Default behaviour for blockers : they block the card they're attached to
void Blocker::Update(float dt){ void Blocker::Update(float dt){
game = GameObserver::GetInstance(); game = GameObserver::GetInstance();
int newPhase = game->getCurrentGamePhase(); int newPhase = game->getCurrentGamePhase();
if (newPhase != currentPhase){ if (newPhase != currentPhase){
MTGCardInstance * _target; MTGCardInstance * _target;
if (target){ if (target){
_target = (MTGCardInstance *) target; _target = (MTGCardInstance *) target;
}else{ }else{
_target = source; _target = source;
} }
_target->getBlockers()->Add(this); _target->getBlockers()->Add(this);
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "Adding Blocker to %s \n", _target->model->getName()); sprintf(buf, "Adding Blocker to %s \n", _target->model->getName());
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
} }
currentPhase = newPhase; currentPhase = newPhase;
} }
int Blocker::destroy(){ int Blocker::destroy(){
MTGCardInstance * _target; MTGCardInstance * _target;
if (target){ if (target){
_target = (MTGCardInstance *) target; _target = (MTGCardInstance *) target;
}else{ }else{
_target = source; _target = source;
} }
_target->getBlockers()->Remove(this); _target->getBlockers()->Remove(this);
return 1; return 1;
} }
Blockers::Blockers(){ Blockers::Blockers(){
init(); init();
} }
int Blockers::init(){ int Blockers::init(){
cursor = -1; cursor = -1;
for (int i=0; i< MAX_BLOCKERS ; i++){ for (int i=0; i< MAX_BLOCKERS ; i++){
blockers[i] = 0; blockers[i] = 0;
} }
return 1; return 1;
} }
int Blockers::Add (Blocker * ability){ int Blockers::Add (Blocker * ability){
game = GameObserver::GetInstance(); game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability); int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 1; blockers[index] = 1;
return index; return index;
} }
int Blockers::Remove (Blocker * ability){ int Blockers::Remove (Blocker * ability){
game = GameObserver::GetInstance(); game = GameObserver::GetInstance();
int index = game->mLayers->actionLayer()->getIndexOf(ability); int index = game->mLayers->actionLayer()->getIndexOf(ability);
blockers[index] = 0; blockers[index] = 0;
return index; return index;
} }
int Blockers::rewind(){ int Blockers::rewind(){
cursor = -1; cursor = -1;
return 1; return 1;
} }
Blocker * Blockers::next(){ Blocker * Blockers::next(){
cursor++; cursor++;
game = GameObserver::GetInstance(); game = GameObserver::GetInstance();
while (blockers[cursor] == 0){ while (blockers[cursor] == 0){
cursor ++; cursor ++;
if (cursor == MAX_BLOCKERS){ if (cursor == MAX_BLOCKERS){
cursor = -1; cursor = -1;
return NULL; return NULL;
} }
} }
return (Blocker *) (game->mLayers->actionLayer()->getByIndex(cursor)); return (Blocker *) (game->mLayers->actionLayer()->getByIndex(cursor));
} }
int Blockers::isEmpty(){ int Blockers::isEmpty(){
for (int i=0; i< MAX_BLOCKERS ; i++){ for (int i=0; i< MAX_BLOCKERS ; i++){
if (blockers[i]) if (blockers[i])
return 0; return 0;
} }
return 1; return 1;
} }
Blockers::~Blockers(){ Blockers::~Blockers(){
+91 -91
View File
@@ -2,130 +2,130 @@
#include "../include/CardDescriptor.h" #include "../include/CardDescriptor.h"
CardDescriptor::CardDescriptor(): MTGCardInstance(){ CardDescriptor::CardDescriptor(): MTGCardInstance(){
init(); init();
mode = CD_AND; mode = CD_AND;
} }
int CardDescriptor::init(){ int CardDescriptor::init(){
return MTGCardInstance::init(); return MTGCardInstance::init();
} }
MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){ MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
int found = 1; int found = 1;
for (int i = 0; i< nb_types; i++){ for (int i = 0; i< nb_types; i++){
found = 0; found = 0;
if (card->hasSubtype(types[i])){ if (card->hasSubtype(types[i])){
found = 1; found = 1;
break; break;
} }
} }
if (!found) return NULL; if (!found) return NULL;
for (int i = 0; i< MTG_NB_COLORS; i++){ for (int i = 0; i< MTG_NB_COLORS; i++){
found = 0; found = 0;
if (colors[i] == 1 && card->hasColor(i)){ if (colors[i] == 1 && card->hasColor(i)){
found = 1; found = 1;
break; break;
} }
} }
if (!found) return NULL; if (!found) return NULL;
return card; return card;
} }
MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){ MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){
#ifdef WIN32 #ifdef WIN32
OutputDebugString("Match AND\n"); OutputDebugString("Match AND\n");
#endif #endif
MTGCardInstance * match = card; MTGCardInstance * match = card;
for (int i = 0; i< nb_types; i++){ for (int i = 0; i< nb_types; i++){
if (!card->hasSubtype(types[i])){ if (!card->hasSubtype(types[i])){
#ifdef WIN32 #ifdef WIN32
OutputDebugString(card->name.c_str()); OutputDebugString(card->name.c_str());
OutputDebugString("Subtype No Match\n"); OutputDebugString("Subtype No Match\n");
#endif #endif
match = NULL; match = NULL;
} }
} }
for (int i = 0; i< MTG_NB_COLORS; i++){ for (int i = 0; i< MTG_NB_COLORS; i++){
if ((colors[i] == 1 && !card->hasColor(i))||(colors[i] == -1 && card->hasColor(i))){ if ((colors[i] == 1 && !card->hasColor(i))||(colors[i] == -1 && card->hasColor(i))){
match = NULL; match = NULL;
#ifdef WIN32 #ifdef WIN32
OutputDebugString(card->name.c_str()); OutputDebugString(card->name.c_str());
OutputDebugString("Color No Match\n"); OutputDebugString("Color No Match\n");
#endif #endif
} }
} }
return match; return match;
} }
MTGCardInstance * CardDescriptor::match(MTGCardInstance * card){ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card){
MTGCardInstance * match = card; MTGCardInstance * match = card;
if (mode == CD_AND){ if (mode == CD_AND){
match = match_and(card); match = match_and(card);
}else{ }else{
match=match_or(card); match=match_or(card);
} }
//Abilities //Abilities
for (int j = 0; j < NB_BASIC_ABILITIES; j++){ for (int j = 0; j < NB_BASIC_ABILITIES; j++){
if ((basicAbilities[j] == 1 && !card->basicAbilities[j]) || (basicAbilities[j] == -1 && card->basicAbilities[j])){ if ((basicAbilities[j] == 1 && !card->basicAbilities[j]) || (basicAbilities[j] == -1 && card->basicAbilities[j])){
match = NULL; match = NULL;
} }
} }
if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped())){ if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped())){
match = NULL; match = NULL;
} }
if (attacker == 1){ if (attacker == 1){
if ((int)defenser == 1){ if ((int)defenser == 1){
if (!card->attacker && !card->defenser) match = NULL; if (!card->attacker && !card->defenser) match = NULL;
}else{ }else{
if (!card->attacker) match = NULL; if (!card->attacker) match = NULL;
} }
}else if (attacker == -1){ }else if (attacker == -1){
if ((int)defenser == -1){ if ((int)defenser == -1){
if (card->attacker || card->defenser) match = NULL; if (card->attacker || card->defenser) match = NULL;
}else{ }else{
if (card->attacker) match = NULL; if (card->attacker) match = NULL;
} }
}else{ }else{
if ((int)defenser == -1){ if ((int)defenser == -1){
if (card->defenser) match = NULL; if (card->defenser) match = NULL;
}else if ((int)defenser == 1){ }else if ((int)defenser == 1){
if (!card->defenser) match = NULL; if (!card->defenser) match = NULL;
}else{ }else{
// we don't care about the attack/blocker state // we don't care about the attack/blocker state
} }
} }
return match; return match;
} }
MTGCardInstance * CardDescriptor::match(MTGGameZone * zone){ MTGCardInstance * CardDescriptor::match(MTGGameZone * zone){
return (nextmatch(zone, NULL)); return (nextmatch(zone, NULL));
} }
MTGCardInstance * CardDescriptor::nextmatch(MTGGameZone * zone, MTGCardInstance * previous){ MTGCardInstance * CardDescriptor::nextmatch(MTGGameZone * zone, MTGCardInstance * previous){
int found = 0; int found = 0;
if (NULL == previous) found = 1; if (NULL == previous) found = 1;
for(int i=0; i < zone->nb_cards; i++){ for(int i=0; i < zone->nb_cards; i++){
if(found && match(zone->cards[i])){ if(found && match(zone->cards[i])){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf,"Card Descriptor MATCH!: %s \n" ,(zone->cards[i])->getName()); sprintf(buf,"Card Descriptor MATCH!: %s \n" ,(zone->cards[i])->getName());
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
return zone->cards[i]; return zone->cards[i];
} }
if (zone->cards[i] == previous){ if (zone->cards[i] == previous){
found = 1; found = 1;
} }
} }
return NULL; return NULL;
} }
+104 -104
View File
@@ -5,152 +5,152 @@
#include "../include/MTGGameZones.h" #include "../include/MTGGameZones.h"
CardDisplay::CardDisplay():PlayGuiObjectController(0, GameObserver::GetInstance()){ CardDisplay::CardDisplay():PlayGuiObjectController(0, GameObserver::GetInstance()){
tc= NULL; tc= NULL;
listener = NULL; listener = NULL;
nb_displayed_items = 7; nb_displayed_items = 7;
start_item = 0; start_item = 0;
x= 0; x= 0;
y= 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){ 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; tc= _tc;
listener = _listener; listener = _listener;
nb_displayed_items = _nb_displayed_items; nb_displayed_items = _nb_displayed_items;
start_item = 0; start_item = 0;
} }
void CardDisplay::AddCard(MTGCardInstance * _card){ void CardDisplay::AddCard(MTGCardInstance * _card){
CardGui * card = NEW CardGui(mCount, _card, 40, x + 5 + (mCount - start_item) * 30, y + 5, (mCount == 0)); CardGui * card = NEW CardGui(mCount, _card, 40, x + 5 + (mCount - start_item) * 30, y + 5, (mCount == 0));
Add(card); Add(card);
} }
void CardDisplay::init(MTGGameZone * zone){ void CardDisplay::init(MTGGameZone * zone){
resetObjects(); resetObjects();
start_item = 0; start_item = 0;
for (int i= 0; i< zone->nb_cards; i++){ for (int i= 0; i< zone->nb_cards; i++){
AddCard(zone->cards[i]); AddCard(zone->cards[i]);
} }
} }
void CardDisplay::rotateLeft(){ void CardDisplay::rotateLeft(){
if (start_item==0) return; if (start_item==0) return;
for (int i= 0; i<mCount; i++){ for (int i= 0; i<mCount; i++){
CardGui * cardg = (CardGui *)mObjects[i]; CardGui * cardg = (CardGui *)mObjects[i];
cardg->x+=30; cardg->x+=30;
} }
start_item --; start_item --;
} }
void CardDisplay::rotateRight(){ void CardDisplay::rotateRight(){
if (start_item==mCount-1) return; if (start_item==mCount-1) return;
for (int i= 0; i<mCount; i++){ for (int i= 0; i<mCount; i++){
CardGui * cardg = (CardGui *)mObjects[i]; CardGui * cardg = (CardGui *)mObjects[i];
cardg->x-=30; cardg->x-=30;
} }
start_item ++; start_item ++;
} }
void CardDisplay::CheckUserInput(float dt){ 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) if (!mCount)
return; 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()){ int n = mCurr;
CardGui * cardg = (CardGui *)mObjects[mCurr]; n--;
if (tc) if (n<start_item){
{ if (n< 0){n = 0;}
tc->toggleTarget(cardg->card); else{ rotateLeft();}
return; }
}else{ if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_LEFT)){
if (game) game->ButtonPressed(mId, cardg); mCurr = n;
return; mObjects[mCurr]->Entering();
} }
}
} }
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT))
if (mEngine->GetButtonState(PSP_CTRL_LEFT)) {
if (KeyRepeated(PSP_CTRL_RIGHT, dt))
{ {
if (KeyRepeated(PSP_CTRL_LEFT, dt)) int n = mCurr;
{ n++;
int n = mCurr; if (n>= mCount){n = mCount-1;}
n--; if (n>= start_item + nb_displayed_items){
if (n<start_item){ rotateRight();
if (n< 0){n = 0;} }
else{ rotateLeft();} if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_RIGHT)){
} mCurr = n;
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_LEFT)){ mObjects[mCurr]->Entering();
mCurr = n; }
mObjects[mCurr]->Entering();
}
}
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT))
{
if (KeyRepeated(PSP_CTRL_RIGHT, dt))
{
int n = mCurr;
n++;
if (n>= mCount){n = mCount-1;}
if (n>= start_item + nb_displayed_items){
rotateRight();
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_RIGHT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
}
} }
}
else{ else{
mLastKey = 0; mLastKey = 0;
} }
} }
void CardDisplay::Render(){ void CardDisplay::Render(){
JRenderer * r = JRenderer::GetInstance(); JRenderer * r = JRenderer::GetInstance();
r->DrawRect(x,y,nb_displayed_items * 30 + 20, 50, ARGB(255,255,255,255)); r->DrawRect(x,y,nb_displayed_items * 30 + 20, 50, ARGB(255,255,255,255));
if (!mCount) return; if (!mCount) return;
for (int i = start_item; i< start_item + nb_displayed_items && i < mCount; i++){ for (int i = start_item; i< start_item + nb_displayed_items && i < mCount; i++){
if (mObjects[i]){ if (mObjects[i]){
mObjects[i]->Render(); mObjects[i]->Render();
if (tc){ if (tc){
CardGui * cardg = (CardGui *)mObjects[i]; CardGui * cardg = (CardGui *)mObjects[i];
if( tc->alreadyHasTarget(cardg->card)){ if( tc->alreadyHasTarget(cardg->card)){
r->DrawCircle(cardg->x + 5, cardg->y+5,5, ARGB(255,255,0,0)); r->DrawCircle(cardg->x + 5, cardg->y+5,5, ARGB(255,255,0,0));
}else if (!tc->canTarget(cardg->card)){ }else if (!tc->canTarget(cardg->card)){
r->FillRect(cardg->x,cardg->y,30,40,ARGB(200,0,0,0)); r->FillRect(cardg->x,cardg->y,30,40,ARGB(200,0,0,0));
}
}
}
}
if (mObjects[mCurr]){
mObjects[mCurr]->Render();
} }
}
}
}
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 ){ 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(){ DefaultTargetDisplay::~DefaultTargetDisplay(){
SAFE_DELETE(tc); SAFE_DELETE(tc);
} }
+255 -255
View File
@@ -3,315 +3,315 @@
#include <Vector2D.h> #include <Vector2D.h>
void CardGui::alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation, float scale){ void CardGui::alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation, float scale){
JQuad * mIcons[7]; JQuad * mIcons[7];
if (!manaIcons){ if (!manaIcons){
mIcons[MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact"); mIcons[MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact");
mIcons[MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land"); mIcons[MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land");
mIcons[MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white"); mIcons[MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white");
mIcons[MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red"); mIcons[MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red");
mIcons[MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black"); mIcons[MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black");
mIcons[MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue"); mIcons[MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue");
mIcons[MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green"); mIcons[MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i=0; i < 7; i++){ for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16); mIcons[i]->SetHotSpot(16,16);
} }
manaIcons = mIcons; manaIcons = mIcons;
} }
Vector2D v; Vector2D v;
Vector2D points[4]; Vector2D points[4];
PIXEL_TYPE bgcolor = ARGB(255,128,128,128); PIXEL_TYPE bgcolor = ARGB(255,128,128,128);
PIXEL_TYPE bgcolor2 = ARGB(255,80,80,80); PIXEL_TYPE bgcolor2 = ARGB(255,80,80,80);
char buf[25]; char buf[25];
int width = 200; int width = 200;
int height = 285; int height = 285;
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
mFont->SetRotation(rotation); mFont->SetRotation(rotation);
mFont->SetScale(scale); mFont->SetScale(scale);
int color = card->getColor(); int color = card->getColor();
points[0].x = -width/2; points[0].x = -width/2;
points[0].y = -height/2 ; points[0].y = -height/2 ;
points[1].x = width/2; points[1].x = width/2;
points[1].y = -height/2; points[1].y = -height/2;
points[2].x = width/2; points[2].x = width/2;
points[2].y = height/2; points[2].y = height/2;
points[3].x = -width/2; points[3].x = -width/2;
points[3].y = height/2; points[3].y = height/2;
for (int i=0; i < 4; i++){ for (int i=0; i < 4; i++){
points[i].x *= scale; points[i].x *= scale;
points[i].y *= scale; points[i].y *= scale;
points[i].Rotate(rotation); points[i].Rotate(rotation);
} }
if (rotation == 0){ 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->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); 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{ }else{
for (int i=0; i < 4; i++){ s = "";
renderer->DrawLine(x + points[i].x,y + points[i].y,x + points[(i+1)%4].x,y + points[(i+1)%4].y,bgcolor);
}
} }
}else{
int newcut = cut;
ManaCost * manacost = card->getManaCost(); while (newcut < len && newcut != -1){
int nbicons = 0; cut = newcut;
for (int i = 1; i < MTG_NB_COLORS - 1; i++){ newcut = s.find_first_of("., \t)", newcut + 1);
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); card->formattedText.push_back(s.substr(0,cut+1));
if (cost !=0){ if ((signed int)s.length() > cut+1){
v.x = (width/2 - 20 - 16*nbicons)*scale; s = s.substr(cut+1,s.length()- cut - 1);
v.y = ((-height/2) + 14) * scale; }else{
v.Rotate(rotation); s = "";
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->formattedTextInit = 1;
}
for (unsigned int i=0; i < card->formattedText.size(); i++){ for (unsigned int i=0; i < card->formattedText.size(); i++){
sprintf(buf, "%s", card->formattedText[i].c_str()); sprintf(buf, "%s", card->formattedText[i].c_str());
v.x = (-width/2 + 12 )*scale; v.x = (-width/2 + 12 )*scale;
v.y = ((-height/2) + 50 + 16*i) * scale; v.y = ((-height/2) + 50 + 16*i) * scale;
v.Rotate(rotation); v.Rotate(rotation);
mFont->DrawString(buf,x+v.x,y+v.y); mFont->DrawString(buf,x+v.x,y+v.y);
} }
v.x = ((-width/2)+10) * scale; v.x = ((-width/2)+10) * scale;
v.y = ((-height/2) + 25) * scale; v.y = ((-height/2) + 25) * scale;
v.Rotate(rotation); v.Rotate(rotation);
int over = strlen(card->getName()) - 23; int over = strlen(card->getName()) - 23;
float multiply = 1.4; float multiply = 1.4;
if (over > 0){ if (over > 0){
multiply = 1.1; multiply = 1.1;
} }
mFont->SetScale(scale * multiply); mFont->SetScale(scale * multiply);
mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color])); mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color]));
mFont->DrawString(card->getName(),x+v.x,y+v.y); mFont->DrawString(card->getName(),x+v.x,y+v.y);
mFont->SetScale(scale); mFont->SetScale(scale);
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
if (card->isACreature()){ if (card->isACreature()){
v.x = (width/2-40) * scale; v.x = (width/2-40) * scale;
v.y = (height/2-30) * scale; v.y = (height/2-30) * scale;
v.Rotate(rotation); v.Rotate(rotation);
sprintf(buf,"%i/%i",card->power,card->toughness); sprintf(buf,"%i/%i",card->power,card->toughness);
mFont->DrawString(buf,x+v.x,y+v.y); 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){ 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("==Creating NEW CardGui Object. CardName:");
LOG(_card->getName()); LOG(_card->getName());
card = _card; card = _card;
type = GUI_CARD; type = GUI_CARD;
alpha = 255; alpha = 255;
mParticleSys = NULL; mParticleSys = NULL;
if (card->hasColor(MTG_COLOR_RED)){ if (card->hasColor(MTG_COLOR_RED)){
mParticleSys = GameApp::Particles[3]; mParticleSys = GameApp::Particles[3];
}else if (card->hasColor(MTG_COLOR_BLUE)){ }else if (card->hasColor(MTG_COLOR_BLUE)){
mParticleSys = GameApp::Particles[1]; mParticleSys = GameApp::Particles[1];
}else if (card->hasColor(MTG_COLOR_GREEN)){ }else if (card->hasColor(MTG_COLOR_GREEN)){
mParticleSys = GameApp::Particles[2]; mParticleSys = GameApp::Particles[2];
}else if (card->hasColor(MTG_COLOR_BLACK)){ }else if (card->hasColor(MTG_COLOR_BLACK)){
mParticleSys = GameApp::Particles[4]; mParticleSys = GameApp::Particles[4];
}else if (card->hasColor(MTG_COLOR_WHITE)){ }else if (card->hasColor(MTG_COLOR_WHITE)){
mParticleSys = GameApp::Particles[0]; mParticleSys = GameApp::Particles[0];
}else{ }else{
mParticleSys = GameApp::Particles[5]; mParticleSys = GameApp::Particles[5];
} }
LOG("==CardGui Object Creation Succesfull"); LOG("==CardGui Object Creation Succesfull");
} }
void CardGui::Update(float dt){ void CardGui::Update(float dt){
alpha = 255; alpha = 255;
if (card->changedZoneRecently > 0) alpha = 255.f - 255.f * card->changedZoneRecently; if (card->changedZoneRecently > 0) alpha = 255.f - 255.f * card->changedZoneRecently;
if (mParticleSys && card->changedZoneRecently == 1.f){ if (mParticleSys && card->changedZoneRecently == 1.f){
mParticleSys->MoveTo(x+15, y+2*mHeight/3); mParticleSys->MoveTo(x+15, y+2*mHeight/3);
mParticleSys->Fire(); mParticleSys->Fire();
} }
if (card->changedZoneRecently){ if (card->changedZoneRecently){
if (mParticleSys) mParticleSys->Update(dt); if (mParticleSys) mParticleSys->Update(dt);
card->changedZoneRecently-= (5 *dt); card->changedZoneRecently-= (5 *dt);
if (card->changedZoneRecently < 0){ if (card->changedZoneRecently < 0){
if (mParticleSys) mParticleSys->Stop(); if (mParticleSys) mParticleSys->Stop();
} }
if (card->changedZoneRecently < -3){ if (card->changedZoneRecently < -3){
card->changedZoneRecently = 0; card->changedZoneRecently = 0;
mParticleSys = NULL; mParticleSys = NULL;
} }
} }
PlayGuiObject::Update(dt); PlayGuiObject::Update(dt);
} }
void CardGui::RenderBig(float xpos, float ypos){ void CardGui::RenderBig(float xpos, float ypos){
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getQuad(); JQuad * quad = card->getQuad();
if (xpos == -1){ if (xpos == -1){
xpos = 300; xpos = 300;
if (x > SCREEN_WIDTH / 2) if (x > SCREEN_WIDTH / 2)
xpos = 10; xpos = 10;
} }
if(ypos == -1) if(ypos == -1)
ypos = 20; ypos = 20;
if (quad){ if (quad){
quad->SetColor(ARGB(220,255,255,255)); quad->SetColor(ARGB(220,255,255,255));
renderer->RenderQuad(quad, xpos , ypos , 0.0f,0.9f,0.9f); renderer->RenderQuad(quad, xpos , ypos , 0.0f,0.9f,0.9f);
}else{ }else{
MTGCard * mtgcard = card->model; MTGCard * mtgcard = card->model;
JLBFont * font = GameApp::CommonRes->GetJLBFont("graphics/magic"); JLBFont * font = GameApp::CommonRes->GetJLBFont("graphics/magic");
CardGui::alternateRender(mtgcard, font, NULL, xpos + 90 , ypos + 130, 0.0f,0.9f); CardGui::alternateRender(mtgcard, font, NULL, xpos + 90 , ypos + 130, 0.0f,0.9f);
} }
} }
void CardGui::Render(){ void CardGui::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT); JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getThumb(); JQuad * quad = card->getThumb();
if (!quad || quad->mHeight * 2 < mHeight){ if (!quad || quad->mHeight * 2 < mHeight){
JQuad * quad2 = card->getQuad(); JQuad * quad2 = card->getQuad();
if (quad2) if (quad2)
quad = quad2; quad = quad2;
} }
float tap = (float)(card->isTapped()); float tap = (float)(card->isTapped());
float rotation = M_PI_2 * tap; float rotation = M_PI_2 * tap;
if (quad){ if (quad){
float mScale = mHeight / quad->mHeight; float mScale = mHeight / quad->mHeight;
float myX = x + (quad->mHeight/2 * tap * mScale); float myX = x + (quad->mHeight/2 * tap * mScale);
float myY = y+(quad->mWidth/2 * tap * mScale); float myY = y+(quad->mWidth/2 * tap * mScale);
if (mHeight-defaultHeight){ if (mHeight-defaultHeight){
if (card->isTapped()){ 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)); 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{ }else{
renderer->FillRect(myX + 1*(mHeight-defaultHeight) , myY + 1*(mHeight-defaultHeight) , quad->mWidth * mScale, quad->mHeight * mScale, ARGB(128,0,0,0)); 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)); quad->SetColor(ARGB( alpha,255,255,255));
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
TargetChooser * tc = NULL; TargetChooser * tc = NULL;
if (game) tc = game->getCurrentTargetChooser(); if (game) tc = game->getCurrentTargetChooser();
if (tc){ if (tc){
if (!tc->canTarget(card)){ if (!tc->canTarget(card)){
quad->SetColor(ARGB( alpha,50,50,50)); quad->SetColor(ARGB( alpha,50,50,50));
} }
} }
renderer->RenderQuad(quad, myX , myY , rotation,mScale,mScale); renderer->RenderQuad(quad, myX , myY , rotation,mScale,mScale);
if (tc && tc->alreadyHasTarget(card)){ if (tc && tc->alreadyHasTarget(card)){
if (card->isTapped()){ if (card->isTapped()){
renderer->FillRect(myX- quad->mHeight * mScale , myY , quad->mHeight * mScale, quad->mWidth * mScale, ARGB(128,255,0,0)); renderer->FillRect(myX- quad->mHeight * mScale , myY , quad->mHeight * mScale, quad->mWidth * mScale, ARGB(128,255,0,0));
}else{ }else{
renderer->FillRect(myX , myY , quad->mWidth * mScale, quad->mHeight * mScale, ARGB(128,255,0,0)); renderer->FillRect(myX , myY , quad->mWidth * mScale, quad->mHeight * mScale, ARGB(128,255,0,0));
} }
} }
quad->SetColor(ARGB( alpha,255,255,255)); quad->SetColor(ARGB( alpha,255,255,255));
}else{ }else{
int color = card->getColor(); int color = card->getColor();
float mScale = mHeight / 64; float mScale = mHeight / 64;
float myX = x + (32 * tap * mScale); float myX = x + (32 * tap * mScale);
float myY = y+(20 * tap * mScale); float myY = y+(20 * tap * mScale);
char buffer[200]; char buffer[200];
sprintf(buffer, "%s",card->getName()); sprintf(buffer, "%s",card->getName());
mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color])); mFont->SetColor(ARGB(255,_r[color],_g[color],_b[color]));
if (card->isTapped()){ if (card->isTapped()){
renderer->FillRect(myX - 64 * mScale , myY , 64 * mScale, 40 * mScale, ARGB(255,0,0,0)); 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])); renderer->DrawRect(myX - 64 * mScale , myY , 64 * mScale, 40 * mScale, ARGB(255,_r[color],_g[color],_b[color]));
mFont->SetScale(0.20); mFont->SetScale(0.20);
mFont->DrawString(buffer,myX - (64 * mScale)+4,myY + 1); mFont->DrawString(buffer,myX - (64 * mScale)+4,myY + 1);
}else{ }else{
renderer->FillRect(myX , myY , 40 * mScale, 64 * mScale, ARGB(255,0,0,0)); 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])); renderer->DrawRect(myX , myY , 40 * mScale, 64 * mScale, ARGB(255,_r[color],_g[color],_b[color]));
mFont->SetScale(0.40); mFont->SetScale(0.40);
mFont->DrawString(buffer,myX+4,myY + 1); mFont->DrawString(buffer,myX+4,myY + 1);
} }
mFont->SetScale(1.0); mFont->SetScale(1.0);
} }
if (card->isACreature()){ if (card->isACreature()){
mFont->SetScale(0.75); mFont->SetScale(0.75);
char buffer[200]; char buffer[200];
sprintf(buffer, "%i/%i",card->power,card->life); sprintf(buffer, "%i/%i",card->power,card->life);
renderer->FillRect(x+2,y + mHeight - 12, 25 , 12 ,ARGB(128,0,0,0)); renderer->FillRect(x+2,y + mHeight - 12, 25 , 12 ,ARGB(128,0,0,0));
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buffer,x+4,y + mHeight - 10); mFont->DrawString(buffer,x+4,y + mHeight - 10);
} }
if (mParticleSys && card->changedZoneRecently > 0){ if (mParticleSys && card->changedZoneRecently > 0){
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE); renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
mParticleSys->Render(); mParticleSys->Render();
// set normal blending // set normal blending
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
} }
} }
CardGui::~CardGui(){ CardGui::~CardGui(){
LOG("==Destroying CardGui object"); LOG("==Destroying CardGui object");
LOG(this->card->getName()); LOG(this->card->getName());
LOG("==CardGui object destruction Successful"); LOG("==CardGui object destruction Successful");
} }
+32 -32
View File
@@ -3,39 +3,39 @@
int ConstraintResolver::untap(GameObserver * game, MTGCardInstance * card){ int ConstraintResolver::untap(GameObserver * game, MTGCardInstance * card){
if (!card->isUntapping()){ if (!card->isUntapping()){
return 0; return 0;
} }
int ok = 1; int ok = 1;
ManaCost * untapManaCost = NEW ManaCost(); ManaCost * untapManaCost = NEW ManaCost();
Blockers * blockers = card->getBlockers(); Blockers * blockers = card->getBlockers();
Blocker * blocker; Blocker * blocker;
blockers->rewind(); blockers->rewind();
Player * player = game->currentPlayer; Player * player = game->currentPlayer;
while ((blocker = blockers->next())){ while ((blocker = blockers->next())){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "next\n"); sprintf(buf, "next\n");
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
untapManaCost->add(blocker->untapManaCost()); untapManaCost->add(blocker->untapManaCost());
} }
if (player->getManaPool()->canAfford(untapManaCost)){ if (player->getManaPool()->canAfford(untapManaCost)){
blockers->rewind(); blockers->rewind();
while ((blocker = blockers->next())){ while ((blocker = blockers->next())){
if (!blocker->unblock()){ if (!blocker->unblock()){
ok = 0; ok = 0;
break; break;
} }
} }
}else{ }else{
ok = 0; ok = 0;
} }
if (ok) { if (ok) {
player->getManaPool()->pay(untapManaCost); player->getManaPool()->pay(untapManaCost);
card->untap(); card->untap();
} }
delete untapManaCost; delete untapManaCost;
return ok; return ok;
} }
+97 -97
View File
@@ -3,118 +3,118 @@
#include "../include/MTGCardInstance.h" #include "../include/MTGCardInstance.h"
Counter::Counter(MTGCardInstance * _target, int _power, int _toughness){ 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 ){ 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){ int Counter::init(MTGCardInstance * _target,const char * _name, int _power, int _toughness){
target = _target; target = _target;
name = _name; name = _name;
power = _power; power = _power;
toughness = _toughness; toughness = _toughness;
nb = 1; nb = 1;
return 1; return 1;
} }
bool Counter::sameAs(const char * _name, int _power, int _toughness){ bool Counter::sameAs(const char * _name, int _power, int _toughness){
if (power == 0 && toughness == 0) return (name.compare(_name) == 0); if (power == 0 && toughness == 0) return (name.compare(_name) == 0);
return (power == _power && toughness == _toughness); return (power == _power && toughness == _toughness);
} }
bool Counter::cancels(int _power, int _toughness){ bool Counter::cancels(int _power, int _toughness){
if (power == 0 && toughness == 0) return false; if (power == 0 && toughness == 0) return false;
return (power == -_power && toughness == -_toughness); return (power == -_power && toughness == -_toughness);
} }
int Counter::added(){ int Counter::added(){
if (power != 0 || toughness != 0){ if (power != 0 || toughness != 0){
target->power+= power; target->power+= power;
target->addToToughness(toughness); target->addToToughness(toughness);
} }
return 1; return 1;
} }
int Counter::removed(){ int Counter::removed(){
if (power != 0 || toughness != 0){ if (power != 0 || toughness != 0){
target->power-= power; target->power-= power;
target->addToToughness(-toughness); target->addToToughness(-toughness);
} }
return 1; return 1;
} }
Counters::Counters(MTGCardInstance * _target):target(_target){ Counters::Counters(MTGCardInstance * _target):target(_target){
mCount = 0; mCount = 0;
} }
Counters::~Counters(){ Counters::~Counters(){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
delete counters[i]; delete counters[i];
} }
} }
int Counters::addCounter(const char * _name,int _power, int _toughness){ int Counters::addCounter(const char * _name,int _power, int _toughness){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
if (counters[i]->cancels( _power,_toughness) && counters[i]->nb > 0){ if (counters[i]->cancels( _power,_toughness) && counters[i]->nb > 0){
counters[i]->removed(); counters[i]->removed();
counters[i]->nb--; counters[i]->nb--;
return mCount; return mCount;
} }
} }
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
if (counters[i]->sameAs(_name, _power,_toughness)){ if (counters[i]->sameAs(_name, _power,_toughness)){
counters[i]->added(); counters[i]->added();
counters[i]->nb++; counters[i]->nb++;
return mCount; return mCount;
} }
} }
Counter * counter = NEW Counter(target,_name, _power, _toughness); Counter * counter = NEW Counter(target,_name, _power, _toughness);
counters[mCount] = counter; counters[mCount] = counter;
counter->added(); counter->added();
mCount++; mCount++;
return mCount; return mCount;
} }
int Counters::addCounter(int _power, int _toughness){ int Counters::addCounter(int _power, int _toughness){
return addCounter("",_power, _toughness); return addCounter("",_power, _toughness);
} }
int Counters::removeCounter(const char * _name,int _power, int _toughness){ int Counters::removeCounter(const char * _name,int _power, int _toughness){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
if (counters[i]->sameAs(_name, _power,_toughness)){ if (counters[i]->sameAs(_name, _power,_toughness)){
if (counters[i]->nb < 1) return 0; if (counters[i]->nb < 1) return 0;
counters[i]->removed(); counters[i]->removed();
counters[i]->nb--; counters[i]->nb--;
return mCount; return mCount;
} }
} }
return 0; return 0;
} }
int Counters::removeCounter(int _power, int _toughness){ int Counters::removeCounter(int _power, int _toughness){
return removeCounter("",_power, _toughness); return removeCounter("",_power, _toughness);
} }
Counter * Counters::hasCounter(const char * _name,int _power, int _toughness){ Counter * Counters::hasCounter(const char * _name,int _power, int _toughness){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
if (counters[i]->sameAs(_name, _power,_toughness)){ if (counters[i]->sameAs(_name, _power,_toughness)){
if (counters[i]->nb > 0) return counters[i]; if (counters[i]->nb > 0) return counters[i];
} }
} }
return NULL; return NULL;
} }
Counter * Counters::hasCounter(int _power , int _toughness ){ Counter * Counters::hasCounter(int _power , int _toughness ){
return hasCounter("",_power, _toughness); return hasCounter("",_power, _toughness);
} }
Counter * Counters::getNext(Counter * previous){ Counter * Counters::getNext(Counter * previous){
int found = 0; int found = 0;
for (int i = 0; i < mCount ; i++){ for (int i = 0; i < mCount ; i++){
if (found && counters[i]->nb > 0) return counters[i]; if (found && counters[i]->nb > 0) return counters[i];
if (counters[i] == previous) found = 1; if (counters[i] == previous) found = 1;
} }
return NULL; return NULL;
} }
+98 -98
View File
@@ -4,139 +4,139 @@
#include "../include/Counters.h" #include "../include/Counters.h"
Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target): Interruptible(id){ 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){ 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){ void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage){
target = _target; target = _target;
source = _source; source = _source;
if (_damage < 0) _damage = 0; //Negative damages cannot happen if (_damage < 0) _damage = 0; //Negative damages cannot happen
damage = _damage; damage = _damage;
mHeight = 40; mHeight = 40;
type = ACTION_DAMAGE; type = ACTION_DAMAGE;
} }
int Damage::resolve(){ int Damage::resolve(){
if (damage <0) damage = 0; //Negative damages cannot happen if (damage <0) damage = 0; //Negative damages cannot happen
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){ if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){
MTGCardInstance * _target = (MTGCardInstance *)target; MTGCardInstance * _target = (MTGCardInstance *)target;
if ((_target)->protectedAgainst(source)) return 0; if ((_target)->protectedAgainst(source)) return 0;
// Damage for WITHER on creatures // Damage for WITHER on creatures
if (source->has(WITHER)){ if (source->has(WITHER)){
for (int i = 0; i < damage; i++){ for (int i = 0; i < damage; i++){
_target->counters->addCounter(-1, -1); _target->counters->addCounter(-1, -1);
} }
return 1; return 1;
} }
_target->doDamageTest = 1; _target->doDamageTest = 1;
} }
int a = target->dealDamage(damage); int a = target->dealDamage(damage);
return a; return a;
} }
void Damage::Render(){ void Damage::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT); JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0); mFont->SetBase(0);
mFont->SetScale(0.75); mFont->SetScale(0.75);
char buffer[200]; char buffer[200];
sprintf(buffer, "Does %i damage to", damage); sprintf(buffer, "Does %i damage to", damage);
mFont->DrawString(buffer, x + 20 , y, JGETEXT_LEFT); mFont->DrawString(buffer, x + 20 , y, JGETEXT_LEFT);
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = source->getThumb(); JQuad * quad = source->getThumb();
if (quad){ if (quad){
float scale = 30 / quad->mHeight; float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x , y , 0,scale,scale); renderer->RenderQuad(quad, x , y , 0,scale,scale);
}else{ }else{
//TODO //TODO
} }
quad = target->getIcon(); quad = target->getIcon();
if (quad){ if (quad){
float scale = 30 / quad->mHeight; float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x + 150 , y , 0,scale,scale); renderer->RenderQuad(quad, x + 150 , y , 0,scale,scale);
}else{ }else{
//TODO //TODO
} }
} }
DamageStack::DamageStack(int id, GameObserver * _game):GuiLayer(id, _game), Interruptible(id){ DamageStack::DamageStack(int id, GameObserver * _game):GuiLayer(id, _game), Interruptible(id){
currentState = -1; currentState = -1;
type = ACTION_DAMAGES; type = ACTION_DAMAGES;
} }
int DamageStack::CombatDamages(){ int DamageStack::CombatDamages(){
CombatDamages(1); CombatDamages(1);
CombatDamages(0); CombatDamages(0);
return 1; return 1;
} }
int DamageStack::CombatDamages(int strike){ int DamageStack::CombatDamages(int strike){
mHeight = 0; mHeight = 0;
MTGInPlay * attackers = game->currentPlayer->game->inPlay; MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGInPlay * defensers = game->opponent()->game->inPlay; MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * attacker = attackers->getNextAttacker(NULL); MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){ while (attacker != NULL){
int nbdefensers = defensers->nbDefensers(attacker); int nbdefensers = defensers->nbDefensers(attacker);
if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){ if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){
if (nbdefensers == 0){ if (nbdefensers == 0){
Damage * damage = NEW Damage (mCount, attacker, game->opponent()); Damage * damage = NEW Damage (mCount, attacker, game->opponent());
Add(damage); Add(damage);
}else if (nbdefensers == 1){ }else if (nbdefensers == 1){
Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker)); Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker));
Add(damage); Add(damage);
}else{ }else{
//TODO Fetch list of defensers and allow user to choose targets //TODO Fetch list of defensers and allow user to choose targets
Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker)); Damage * damage = NEW Damage (mCount, attacker, defensers->getNextDefenser(NULL, attacker));
Add(damage); Add(damage);
} }
} }
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker); MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker);
while (defenser != NULL){ while (defenser != NULL){
if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){ if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){
Damage * damage = NEW Damage (mCount,defenser, attacker); Damage * damage = NEW Damage (mCount,defenser, attacker);
Add(damage); Add(damage);
} }
defenser = defensers->getNextDefenser(defenser, attacker); defenser = defensers->getNextDefenser(defenser, attacker);
} }
attacker = attackers->getNextAttacker(attacker); attacker = attackers->getNextAttacker(attacker);
} }
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
Damage * damage = (Damage*)mObjects[i]; Damage * damage = (Damage*)mObjects[i];
mHeight += damage->mHeight; mHeight += damage->mHeight;
} }
return mCount; return mCount;
} }
int DamageStack::resolve(){ int DamageStack::resolve(){
for (int i = mCount-1; i>= 0; i--){ for (int i = mCount-1; i>= 0; i--){
Damage * damage = (Damage*)mObjects[i]; Damage * damage = (Damage*)mObjects[i];
damage->resolve(); damage->resolve();
} }
for (int i = mCount-1; i>= 0; i--){ for (int i = mCount-1; i>= 0; i--){
Damage * damage = (Damage*)mObjects[i]; Damage * damage = (Damage*)mObjects[i];
damage->target->afterDamage(); damage->target->afterDamage();
} }
return 1; return 1;
} }
void DamageStack::Render(){ void DamageStack::Render(){
int currenty = y; int currenty = y;
for (int i= 0; i < mCount; i++){ for (int i= 0; i < mCount; i++){
Damage * damage = (Damage*)mObjects[i]; Damage * damage = (Damage*)mObjects[i];
damage->x = x; damage->x = x;
damage->y = currenty; damage->y = currenty;
currenty += damage->mHeight; currenty += damage->mHeight;
damage->Render(); damage->Render();
} }
} }
+278 -278
View File
@@ -6,354 +6,354 @@
#include "../include/Damage.h" #include "../include/Damage.h"
DamageResolverLayer::DamageResolverLayer(int id, GameObserver * _game):PlayGuiObjectController(id, _game){ DamageResolverLayer::DamageResolverLayer(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPhase = -1; currentPhase = -1;
remainingDamageSteps = 0; remainingDamageSteps = 0;
damageStack = NULL; damageStack = NULL;
currentSource = NULL; currentSource = NULL;
buttonOk = 0; buttonOk = 0;
currentChoosingPlayer = NULL; currentChoosingPlayer = NULL;
} }
void DamageResolverLayer::Update(float dt){ void DamageResolverLayer::Update(float dt){
int newPhase = game->getCurrentGamePhase(); int newPhase = game->getCurrentGamePhase();
if (newPhase == MTG_PHASE_COMBATDAMAGE){ if (newPhase == MTG_PHASE_COMBATDAMAGE){
if (!game->mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)){ if (!game->mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)){
if (newPhase != currentPhase){ if (newPhase != currentPhase){
init(); init();
} }
if (remainingDamageSteps && empty()){ if (remainingDamageSteps && empty()){
initResolve(); initResolve();
} }
} }
}else{ }else{
remainingDamageSteps = 0; remainingDamageSteps = 0;
} }
currentPhase = newPhase; currentPhase = newPhase;
PlayGuiObjectController::Update(dt); PlayGuiObjectController::Update(dt);
} }
Player * DamageResolverLayer::whoSelectsDamagesDealtBy(MTGCardInstance * card){ Player * DamageResolverLayer::whoSelectsDamagesDealtBy(MTGCardInstance * card){
if (card->controller() == game->currentPlayer){ //Attacker if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay; MTGInPlay * defensers = game->opponent()->game->inPlay;
int nbdefensers = defensers->nbDefensers(card); int nbdefensers = defensers->nbDefensers(card);
if (nbdefensers == 0) return NULL; if (nbdefensers == 0) return NULL;
if(nbdefensers == 1 && !card->has(TRAMPLE)) return NULL; if(nbdefensers == 1 && !card->has(TRAMPLE)) return NULL;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card); MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){ while (defenser != NULL){
if (defenser->has(BANDING)) return game->opponent(); if (defenser->has(BANDING)) return game->opponent();
defenser = defensers->getNextDefenser(defenser, card); defenser = defensers->getNextDefenser(defenser, card);
} }
return game->currentPlayer; return game->currentPlayer;
}else{ //Defenser }else{ //Defenser
MTGInPlay * attackers = game->currentPlayer->game->inPlay; MTGInPlay * attackers = game->currentPlayer->game->inPlay;
int nbattackers = attackers->nbPartners(card->isDefenser()); int nbattackers = attackers->nbPartners(card->isDefenser());
if(nbattackers <= 1) return NULL; if(nbattackers <= 1) return NULL;
if (card->isDefenser()->banding) return game->currentPlayer; if (card->isDefenser()->banding) return game->currentPlayer;
return game->opponent(); return game->opponent();
} }
} }
int DamageResolverLayer::addAutoDamageToOpponents(MTGCardInstance * card){ int DamageResolverLayer::addAutoDamageToOpponents(MTGCardInstance * card){
if (card->controller() == game->currentPlayer){ //Attacker if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay; MTGInPlay * defensers = game->opponent()->game->inPlay;
int nbdefensers = defensers->nbDefensers(card); int nbdefensers = defensers->nbDefensers(card);
if (nbdefensers == 0){ if (nbdefensers == 0){
Damage * damage = NEW Damage (0, card, game->opponent()); Damage * damage = NEW Damage (0, card, game->opponent());
damageStack->Add(damage); damageStack->Add(damage);
}else if (nbdefensers == 1){ }else if (nbdefensers == 1){
Damage * damage = NEW Damage (0, card, defensers->getNextDefenser(NULL, card)); Damage * damage = NEW Damage (0, card, defensers->getNextDefenser(NULL, card));
damageStack->Add(damage); damageStack->Add(damage);
}else{ }else{
//SHOULDN'T HAPPEN ! //SHOULDN'T HAPPEN !
} }
}else{ //Defenser }else{ //Defenser
Damage * damage = NEW Damage (mCount,card, card->isDefenser()); Damage * damage = NEW Damage (mCount,card, card->isDefenser());
damageStack->Add(damage); damageStack->Add(damage);
} }
return 1; return 1;
} }
int DamageResolverLayer::addIfNotExists(MTGCardInstance * card, Player * selecter){ int DamageResolverLayer::addIfNotExists(MTGCardInstance * card, Player * selecter){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
DamagerDamaged * item = (DamagerDamaged *)mObjects[i]; DamagerDamaged * item = (DamagerDamaged *)mObjects[i];
if (item->card == card) return 0; if (item->card == card) return 0;
} }
CardGui * cardg = game->mLayers->playLayer()->getByCard(card); CardGui * cardg = game->mLayers->playLayer()->getByCard(card);
DamagerDamaged * item = NEW DamagerDamaged(cardg, selecter, mCount == 0); DamagerDamaged * item = NEW DamagerDamaged(cardg, selecter, mCount == 0);
Add(item); Add(item);
mCurr = 0; mCurr = 0;
return 1; return 1;
} }
//Adds a card and all its opponents to the Damagers' list //Adds a card and all its opponents to the Damagers' list
int DamageResolverLayer::addDamager(MTGCardInstance * card, Player * selecter){ int DamageResolverLayer::addDamager(MTGCardInstance * card, Player * selecter){
addIfNotExists(card, selecter); addIfNotExists(card, selecter);
if (card->controller() == game->currentPlayer){ //Attacker if (card->controller() == game->currentPlayer){ //Attacker
MTGInPlay * defensers = game->opponent()->game->inPlay; MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card); MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){ while (defenser != NULL){
addIfNotExists(defenser, whoSelectsDamagesDealtBy(defenser)); addIfNotExists(defenser, whoSelectsDamagesDealtBy(defenser));
defenser = defensers->getNextDefenser(defenser, card); defenser = defensers->getNextDefenser(defenser, card);
} }
}else{ //Defenser }else{ //Defenser
MTGInPlay * attackers = game->currentPlayer->game->inPlay; MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGCardInstance * attacker = card->isDefenser(); MTGCardInstance * attacker = card->isDefenser();
addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker)); addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker));
MTGCardInstance * banding = attacker->banding; MTGCardInstance * banding = attacker->banding;
if (banding){ if (banding){
attacker = attackers->getNextAttacker(NULL); attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){ while (attacker != NULL){
if (attacker->banding == banding){ if (attacker->banding == banding){
addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker)); addIfNotExists(attacker,whoSelectsDamagesDealtBy(attacker));
}
attacker = attackers->getNextAttacker(attacker);
}
}
} }
return 1; attacker = attackers->getNextAttacker(attacker);
}
}
}
return 1;
} }
int DamageResolverLayer::initResolve(){ int DamageResolverLayer::initResolve(){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "starting resolve, remainingDamagesStep = %i\n", remainingDamageSteps); sprintf(buf, "starting resolve, remainingDamagesStep = %i\n", remainingDamageSteps);
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
if (damageStack) return 0; if (damageStack) return 0;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
sprintf(buf, "damageStack is NULL, we can resolve \n"); sprintf(buf, "damageStack is NULL, we can resolve \n");
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
currentSource = NULL; currentSource = NULL;
currentChoosingPlayer = game->currentPlayer; currentChoosingPlayer = game->currentPlayer;
damageStack = NEW DamageStack(mCount,game); damageStack = NEW DamageStack(mCount,game);
int strike = 0; int strike = 0;
if (remainingDamageSteps == 2) strike = 1; if (remainingDamageSteps == 2) strike = 1;
MTGInPlay * attackers = game->currentPlayer->game->inPlay; MTGInPlay * attackers = game->currentPlayer->game->inPlay;
MTGInPlay * defensers = game->opponent()->game->inPlay; MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * attacker = attackers->getNextAttacker(NULL); MTGCardInstance * attacker = attackers->getNextAttacker(NULL);
while (attacker != NULL){ while (attacker != NULL){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
sprintf(buf, "attacker : %s \n", attacker->getName()); sprintf(buf, "attacker : %s \n", attacker->getName());
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){ if ((!strike && !attacker->has(FIRSTSTRIKE)) || (strike && attacker->has(FIRSTSTRIKE)) || attacker->has(DOUBLESTRIKE)){
Player * selecter = whoSelectsDamagesDealtBy(attacker); Player * selecter = whoSelectsDamagesDealtBy(attacker);
if (!selecter){ if (!selecter){
addAutoDamageToOpponents(attacker); addAutoDamageToOpponents(attacker);
}else{ }else{
addDamager(attacker, selecter); addDamager(attacker, selecter);
} }
} }
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker); MTGCardInstance * defenser = defensers->getNextDefenser(NULL, attacker);
while (defenser != NULL){ while (defenser != NULL){
if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){ if ((!strike && !defenser->has(FIRSTSTRIKE)) || (strike && defenser->has(FIRSTSTRIKE)) || defenser->has(DOUBLESTRIKE)){
Player * selecterb = whoSelectsDamagesDealtBy(defenser); Player * selecterb = whoSelectsDamagesDealtBy(defenser);
if (!selecterb){ if (!selecterb){
addAutoDamageToOpponents(defenser); addAutoDamageToOpponents(defenser);
}else{
addDamager(defenser, selecterb);
}
}
defenser = defensers->getNextDefenser(defenser, attacker);
}
attacker = attackers->getNextAttacker(attacker);
}
if (empty()){
if (!damageStack->empty()){
game->mLayers->stackLayer()->addAction(damageStack);
}else{
SAFE_DELETE(damageStack);
}
remainingDamageSteps--;
damageStack = NULL;
modal = remainingDamageSteps;
}else{ }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(){ int DamageResolverLayer::init(){
modal = 1; modal = 1;
remainingDamageSteps = 2; remainingDamageSteps = 2;
return 1; return 1;
} }
DamagerDamaged * DamageResolverLayer::findByCard(MTGCardInstance * card){ DamagerDamaged * DamageResolverLayer::findByCard(MTGCardInstance * card){
for (int i =0; i < mCount; i++){ for (int i =0; i < mCount; i++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i]; DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->card == card) return current; if (current->card == card) return current;
} }
return NULL; return NULL;
} }
//Returns 1 if all "compulsory" damages have been assigned for current player //Returns 1 if all "compulsory" damages have been assigned for current player
int DamageResolverLayer::canStopDealDamages(){ int DamageResolverLayer::canStopDealDamages(){
for (int i = 0; i < mCount ; i ++){ for (int i = 0; i < mCount ; i ++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i]; DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->damageSelecter==currentChoosingPlayer && current->damageToDeal > 0){ if (current->damageSelecter==currentChoosingPlayer && current->damageToDeal > 0){
MTGCardInstance * card = current->card; MTGCardInstance * card = current->card;
if (card->controller() == game->currentPlayer){ //Attacker if (card->controller() == game->currentPlayer){ //Attacker
if (card->has(TRAMPLE)){ if (card->has(TRAMPLE)){
MTGInPlay * defensers = game->opponent()->game->inPlay; MTGInPlay * defensers = game->opponent()->game->inPlay;
MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card); MTGCardInstance * defenser = defensers->getNextDefenser(NULL, card);
while (defenser != NULL){ while (defenser != NULL){
DamagerDamaged * _defenser = findByCard(defenser); DamagerDamaged * _defenser = findByCard(defenser);
if (!_defenser->hasLethalDamage()) return 0; if (!_defenser->hasLethalDamage()) return 0;
defenser = defensers->getNextDefenser(defenser, card); defenser = defensers->getNextDefenser(defenser, card);
} }
}else{ }else{
return 0; return 0;
}
}else{ //Defenser
return 0;
}
}
} }
return 1; }else{ //Defenser
return 0;
}
}
}
return 1;
} }
int DamageResolverLayer::trampleDamage(){ int DamageResolverLayer::trampleDamage(){
for (int i = 0; i < mCount ; i ++){ for (int i = 0; i < mCount ; i ++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i]; DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
if (current->damageToDeal > 0){ if (current->damageToDeal > 0){
MTGCardInstance * card = current->card; MTGCardInstance * card = current->card;
if (card->controller() == game->currentPlayer){ //Attacker if (card->controller() == game->currentPlayer){ //Attacker
if (card->has(TRAMPLE)){ if (card->has(TRAMPLE)){
Damage * damage = NEW Damage(0, card, game->opponent(), current->damageToDeal); Damage * damage = NEW Damage(0, card, game->opponent(), current->damageToDeal);
damageStack->Add(damage); damageStack->Add(damage);
}
}
}
} }
return 1; }
}
}
return 1;
} }
int DamageResolverLayer::resolveDamages(){ int DamageResolverLayer::resolveDamages(){
trampleDamage(); trampleDamage();
for (int i = 0; i < mCount ; i++){ for (int i = 0; i < mCount ; i++){
DamagerDamaged * current = (DamagerDamaged *) mObjects[i]; DamagerDamaged * current = (DamagerDamaged *) mObjects[i];
for (int j =0; j < current->mCount ; j++){ 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); Damage * damage = NEW Damage(0, current->damages[j]->source, current->damages[j]->target, current->damages[j]->damage);
damageStack->Add(damage); damageStack->Add(damage);
} }
} }
game->mLayers->stackLayer()->addAction(damageStack); game->mLayers->stackLayer()->addAction(damageStack);
remainingDamageSteps--; remainingDamageSteps--;
resetObjects(); resetObjects();
damageStack = NULL; damageStack = NULL;
modal = remainingDamageSteps; modal = remainingDamageSteps;
return 1; return 1;
} }
//a and b are opponents if b is blocking a band in which a belongs or blocking directly a //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){ int DamageResolverLayer::isOpponent(DamagerDamaged * a, DamagerDamaged * b){
MTGCardInstance * carda = a->card; MTGCardInstance * carda = a->card;
MTGCardInstance * cardb = b->card; MTGCardInstance * cardb = b->card;
if (cardb->controller() == game->currentPlayer) {//if b is the attacker switch the cards if (cardb->controller() == game->currentPlayer) {//if b is the attacker switch the cards
carda = cardb; carda = cardb;
cardb = a->card; cardb = a->card;
} }
if (cardb->controller() == game->currentPlayer || carda->controller() == game->opponent()) return 0; //Same team, idiot ! if (cardb->controller() == game->currentPlayer || carda->controller() == game->opponent()) return 0; //Same team, idiot !
if (!carda->banding){ if (!carda->banding){
if (cardb->isDefenser() == carda) return 1; if (cardb->isDefenser() == carda) return 1;
return 0; return 0;
} }
if (cardb->isDefenser() && cardb->isDefenser()->banding == carda->banding) return 1; if (cardb->isDefenser() && cardb->isDefenser()->banding == carda->banding) return 1;
return 0; return 0;
} }
void DamageResolverLayer::nextPlayer(){ void DamageResolverLayer::nextPlayer(){
if (currentChoosingPlayer == game->currentPlayer){ if (currentChoosingPlayer == game->currentPlayer){
currentChoosingPlayer = game->opponent(); currentChoosingPlayer = game->opponent();
if (canStopDealDamages()) resolveDamages(); if (canStopDealDamages()) resolveDamages();
}else{ }else{
resolveDamages(); resolveDamages();
} }
} }
void DamageResolverLayer::CheckUserInput(float dt){ void DamageResolverLayer::CheckUserInput(float dt){
if (!mCount) return; if (!mCount) return;
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){ if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){ if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr]; DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr];
if (!currentSource || !isOpponent(current,currentSource)){ if (!currentSource || !isOpponent(current,currentSource)){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
DamagerDamaged * _current = (DamagerDamaged *) mObjects[i]; DamagerDamaged * _current = (DamagerDamaged *) mObjects[i];
if (isOpponent(current,_current)){ if (isOpponent(current,_current)){
currentSource = _current; currentSource = _current;
break; break;
} }
} }
} }
if (currentSource){ if (currentSource){
if (currentSource->damageSelecter == currentChoosingPlayer){ if (currentSource->damageSelecter == currentChoosingPlayer){
if (isOpponent(current,currentSource)){ if (isOpponent(current,currentSource)){
if (!currentSource->dealOneDamage(current)){ if (!currentSource->dealOneDamage(current)){
currentSource->removeDamagesTo(current); currentSource->removeDamagesTo(current);
} }
} }
} }
}else{ }else{
if (current->damageSelecter == currentChoosingPlayer){ if (current->damageSelecter == currentChoosingPlayer){
currentSource = current; currentSource = current;
} }
} }
buttonOk = 0; buttonOk = 0;
if (canStopDealDamages()) buttonOk = 1; if (canStopDealDamages()) buttonOk = 1;
} }
}else if (mEngine->GetButtonClick(PSP_CTRL_CROSS)){ }else if (mEngine->GetButtonClick(PSP_CTRL_CROSS)){
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){ if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr]; DamagerDamaged * current = (DamagerDamaged *) mObjects[mCurr];
if (current->damageSelecter == currentChoosingPlayer){ if (current->damageSelecter == currentChoosingPlayer){
currentSource = current; currentSource = current;
} }
} }
}else if (mEngine->GetButtonClick(PSP_CTRL_SQUARE)){ }else if (mEngine->GetButtonClick(PSP_CTRL_SQUARE)){
if (canStopDealDamages()){ if (canStopDealDamages()){
nextPlayer(); nextPlayer();
//switch to next player or end of selection //switch to next player or end of selection
} }
}else{ }else{
PlayGuiObjectController::CheckUserInput(dt); PlayGuiObjectController::CheckUserInput(dt);
} }
} }
void DamageResolverLayer::Render(){ void DamageResolverLayer::Render(){
if (!mCount) return; if (!mCount) return;
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT); JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0); mFont->SetBase(0);
mFont->SetScale(0.75); mFont->SetScale(0.75);
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRect(0 ,0 , SCREEN_WIDTH , SCREEN_HEIGHT , ARGB(200,0,0,0)); renderer->FillRect(0 ,0 , SCREEN_WIDTH , SCREEN_HEIGHT , ARGB(200,0,0,0));
if (currentChoosingPlayer == game->currentPlayer){ if (currentChoosingPlayer == game->currentPlayer){
mFont->DrawString("Player 1", 0,0); mFont->DrawString("Player 1", 0,0);
}else{ }else{
mFont->DrawString("Player 2", 0,0); mFont->DrawString("Player 2", 0,0);
} }
if (currentSource){ if (currentSource){
currentSource->RenderBig(10, 20); currentSource->RenderBig(10, 20);
mFont->DrawString("Current Damager:", 10, 5); mFont->DrawString("Current Damager:", 10, 5);
} }
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
((DamagerDamaged *)mObjects[i])->Render(currentChoosingPlayer); ((DamagerDamaged *)mObjects[i])->Render(currentChoosingPlayer);
} }
if (mObjects[mCurr]){ if (mObjects[mCurr]){
((DamagerDamaged *)mObjects[mCurr])->Render(currentChoosingPlayer); ((DamagerDamaged *)mObjects[mCurr])->Render(currentChoosingPlayer);
} }
if (buttonOk){ if (buttonOk){
mFont->DrawString("Damages Assigned, Click Square to Continue", 250, 5); 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){ DamagerDamaged::DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus):CardGui(0, cardg->card,cardg->defaultHeight,cardg->x,cardg->y, _hasFocus){
mCount = 0; mCount = 0;
damageSelecter = _damageSelecter; damageSelecter = _damageSelecter;
damageToDeal = card->power; damageToDeal = card->power;
} }
DamagerDamaged::~DamagerDamaged(){ DamagerDamaged::~DamagerDamaged(){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
delete damages[i]; delete damages[i];
damages[i] = NULL; damages[i] = NULL;
} }
} }
int DamagerDamaged::sumDamages(){ int DamagerDamaged::sumDamages(){
int total = 0; int total = 0;
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
total += damages[i]->damage; total += damages[i]->damage;
} }
return total; return total;
} }
int DamagerDamaged::hasLethalDamage(){ int DamagerDamaged::hasLethalDamage(){
if (sumDamages() >= card->toughness) return 1; if (sumDamages() >= card->toughness) return 1;
return 0; return 0;
} }
int DamagerDamaged::dealOneDamage(DamagerDamaged * target){ int DamagerDamaged::dealOneDamage(DamagerDamaged * target){
if (!damageToDeal) return 0; if (!damageToDeal) return 0;
damageToDeal--; damageToDeal--;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "==========\n%s can still deal %i damages\n=============\n", card->getName(), damageToDeal); sprintf(buf, "==========\n%s can still deal %i damages\n=============\n", card->getName(), damageToDeal);
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
return target->addDamage(1, this); return target->addDamage(1, this);
} }
int DamagerDamaged::addDamage(int damage, DamagerDamaged * source){ int DamagerDamaged::addDamage(int damage, DamagerDamaged * source){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
if (damages[i]->source == source->card){ if (damages[i]->source == source->card){
damages[i]->damage+= damage; damages[i]->damage+= damage;
return damage; return damage;
} }
} }
damages[mCount] = NEW Damage(mCount, source->card, this->card,damage); damages[mCount] = NEW Damage(mCount, source->card, this->card,damage);
mCount++; mCount++;
return damage; return damage;
} }
int DamagerDamaged::removeDamagesTo(DamagerDamaged * target){ int DamagerDamaged::removeDamagesTo(DamagerDamaged * target){
damageToDeal+= target->removeDamagesFrom(this); damageToDeal+= target->removeDamagesFrom(this);
return 1; return 1;
} }
int DamagerDamaged::removeDamagesFrom(DamagerDamaged * source){ int DamagerDamaged::removeDamagesFrom(DamagerDamaged * source){
for (int i = 0; i < mCount; i++){ for (int i = 0; i < mCount; i++){
if (damages[i]->source == source->card){ if (damages[i]->source == source->card){
int damage = damages[i]->damage; int damage = damages[i]->damage;
delete(damages[i]); delete(damages[i]);
damages[i] = NULL; damages[i] = NULL;
damages[i] = damages[mCount-1]; damages[i] = damages[mCount-1];
mCount--; mCount--;
return damage; return damage;
} }
} }
return 0; return 0;
} }
void DamagerDamaged::Render(Player * currentPlayer){ void DamagerDamaged::Render(Player * currentPlayer){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT); JLBFont * mFont = GameApp::CommonRes->GetJLBFont(MAIN_FONT);
mFont->SetBase(0); mFont->SetBase(0);
mFont->SetScale(0.75); mFont->SetScale(0.75);
CardGui::Render(); CardGui::Render();
char buf[4096]; char buf[4096];
if (currentPlayer != damageSelecter){ if (currentPlayer != damageSelecter){
if (hasLethalDamage()){ if (hasLethalDamage()){
mFont->DrawString("X",x,y); mFont->DrawString("X",x,y);
} }
mFont->SetColor(ARGB(255,255,0,0)); mFont->SetColor(ARGB(255,255,0,0));
sprintf(buf, "%i", sumDamages()); sprintf(buf, "%i", sumDamages());
mFont->DrawString(buf,x+5, y+5); mFont->DrawString(buf,x+5, y+5);
}else{ }else{
mFont->SetColor(ARGB(255,0,0,255)); mFont->SetColor(ARGB(255,0,0,255));
sprintf(buf, "%i", damageToDeal); sprintf(buf, "%i", damageToDeal);
mFont->DrawString(buf,x+5, y+5); mFont->DrawString(buf,x+5, y+5);
} }
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
} }
+95 -95
View File
@@ -2,130 +2,130 @@
#include "../include/MTGDeck.h" #include "../include/MTGDeck.h"
DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){ DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
parent = deck; parent = deck;
for (int i = 0; i <= MTG_NB_COLORS; i++){ for (int i = 0; i <= MTG_NB_COLORS; i++){
colors[i] = 0; colors[i] = 0;
} }
for (int i = 0; i < deck->totalCards(); i++){ for (int i = 0; i < deck->totalCards(); i++){
MTGCard * card = deck->_(i); MTGCard * card = deck->_(i);
Add(card); Add(card);
} }
currentposition = 0; currentposition = 0;
currentColor = -1; currentColor = -1;
} }
void DeckDataWrapper::save(){ void DeckDataWrapper::save(){
parent->removeAll(); parent->removeAll();
map<MTGCard *,int,Cmp1>::iterator it; map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){ for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first; MTGCard * current = (*it).first;
for (int i = 0; i < (*it).second; i++){ for (int i = 0; i < (*it).second; i++){
parent->add(current); parent->add(current);
} }
} }
parent->save(); parent->save();
} }
DeckDataWrapper::~DeckDataWrapper(){ DeckDataWrapper::~DeckDataWrapper(){
SAFE_DELETE(parent); SAFE_DELETE(parent);
} }
void DeckDataWrapper::updateCounts(MTGCard * card, int removed){ void DeckDataWrapper::updateCounts(MTGCard * card, int removed){
if (!card){ if (!card){
for (int i = 0; i < MTG_NB_COLORS+1; i++){ for (int i = 0; i < MTG_NB_COLORS+1; i++){
colors[i] = 0; colors[i] = 0;
} }
map<MTGCard *,int,Cmp1>::iterator it; map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){ for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first; MTGCard * current = (*it).first;
colors[MTG_NB_COLORS] += (*it).second; colors[MTG_NB_COLORS] += (*it).second;
for (int i = 0; i < MTG_NB_COLORS; i++){ for (int i = 0; i < MTG_NB_COLORS; i++){
if (current->hasColor(i)) colors[i]+=(*it).second; if (current->hasColor(i)) colors[i]+=(*it).second;
} }
} }
}else{ }else{
int increment = 1; int increment = 1;
if (removed) increment = -1; if (removed) increment = -1;
colors[MTG_NB_COLORS] += increment; colors[MTG_NB_COLORS] += increment;
for (int i = 0; i < MTG_NB_COLORS; i++){ for (int i = 0; i < MTG_NB_COLORS; i++){
if (card->hasColor(i)) colors[i]+=increment; if (card->hasColor(i)) colors[i]+=increment;
} }
} }
} }
int DeckDataWrapper::Add(MTGCard * card){ int DeckDataWrapper::Add(MTGCard * card){
if(cards.find(card) == cards.end()){ if(cards.find(card) == cards.end()){
cards[card] = 1; cards[card] = 1;
}else{ }else{
cards[card]++; cards[card]++;
} }
updateCounts(card); updateCounts(card);
return cards[card]; return cards[card];
} }
int DeckDataWrapper::Remove(MTGCard * card){ int DeckDataWrapper::Remove(MTGCard * card){
if(cards.find(card) == cards.end() || cards[card] == 0) return 0; if(cards.find(card) == cards.end() || cards[card] == 0) return 0;
cards[card]--; cards[card]--;
updateCounts(card,1); updateCounts(card,1);
return 1; return 1;
} }
MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){ MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){
map<MTGCard *,int,Cmp1>::iterator it; map<MTGCard *,int,Cmp1>::iterator it;
it = cards.find(previous); it = cards.find(previous);
int found = 0; int found = 0;
while(1){ while(1){
if (it == cards.end()){ if (it == cards.end()){
it = cards.begin(); it = cards.begin();
}else{ }else{
it++; it++;
} }
if (it == cards.end()) return NULL; if (it == cards.end()) return NULL;
MTGCard * card = (*it).first; MTGCard * card = (*it).first;
if (card == previous) return NULL; if (card == previous) return NULL;
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){ if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
return card; return card;
} }
} }
} }
MTGCard * DeckDataWrapper::getPrevious(MTGCard * next, int color){ MTGCard * DeckDataWrapper::getPrevious(MTGCard * next, int color){
map<MTGCard *,int,Cmp1>::iterator it; map<MTGCard *,int,Cmp1>::iterator it;
it = cards.find(next); it = cards.find(next);
int found = 0; int found = 0;
while(1){ while(1){
if (it == cards.begin()){ if (it == cards.begin()){
it = cards.end(); it = cards.end();
}else{ }else{
it--; it--;
} }
if (it == cards.end()) return NULL; if (it == cards.end()) return NULL;
MTGCard * card = (*it).first; MTGCard * card = (*it).first;
if (card == next) return NULL; if (card == next) return NULL;
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){ if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
return card; return card;
} }
} }
} }
void DeckDataWrapper::updateCurrentPosition(MTGCard * currentCard, int color){ void DeckDataWrapper::updateCurrentPosition(MTGCard * currentCard, int color){
currentposition = 0; currentposition = 0;
MTGCard * next = getNext(NULL,color); MTGCard * next = getNext(NULL,color);
while (next){ while (next){
currentposition+=cards[next]; currentposition+=cards[next];
if (next == currentCard){ if (next == currentCard){
next = NULL; next = NULL;
}else{ }else{
next = getNext(next,color); next = getNext(next,color);
} }
} }
} }
int DeckDataWrapper::getCount(int color){ int DeckDataWrapper::getCount(int color){
if (color == -1) return colors[MTG_NB_COLORS]; if (color == -1) return colors[MTG_NB_COLORS];
return colors[color]; return colors[color];
} }
+27 -27
View File
@@ -8,55 +8,55 @@
void DuelLayers::init(){ void DuelLayers::init(){
//0 Stack Layer //0 Stack Layer
ActionStack * mActionStack = NEW ActionStack(0, GameObserver::GetInstance()); ActionStack * mActionStack = NEW ActionStack(0, GameObserver::GetInstance());
//Damage Resolver //Damage Resolver
DamageResolverLayer * mDamageResolver = NEW DamageResolverLayer(1, GameObserver::GetInstance()); DamageResolverLayer * mDamageResolver = NEW DamageResolverLayer(1, GameObserver::GetInstance());
//1 Action Layer //1 Action Layer
GuiLayer * actionLayer = NEW ActionLayer(2, GameObserver::GetInstance()); GuiLayer * actionLayer = NEW ActionLayer(2, GameObserver::GetInstance());
MTGGamePhase * phaseManager = NEW MTGGamePhase(actionLayer->getMaxId()); MTGGamePhase * phaseManager = NEW MTGGamePhase(actionLayer->getMaxId());
actionLayer->Add(phaseManager); actionLayer->Add(phaseManager);
//Add Magic Specific Rules //Add Magic Specific Rules
actionLayer->Add(NEW MTGAttackRule(-1)); actionLayer->Add(NEW MTGAttackRule(-1));
actionLayer->Add(NEW MTGBlockRule(-1)); actionLayer->Add(NEW MTGBlockRule(-1));
actionLayer->Add(NEW MTGLegendRule(-1)); actionLayer->Add(NEW MTGLegendRule(-1));
actionLayer->Add(NEW MTGPersistRule(-1)); actionLayer->Add(NEW MTGPersistRule(-1));
//2 Hand Layer //2 Hand Layer
MTGGuiHand * mGuiHand = NEW MTGGuiHand(3, GameObserver::GetInstance()); MTGGuiHand * mGuiHand = NEW MTGGuiHand(3, GameObserver::GetInstance());
//3 Game //3 Game
MTGGuiPlay * play = NEW MTGGuiPlay(4, GameObserver::GetInstance()); MTGGuiPlay * play = NEW MTGGuiPlay(4, GameObserver::GetInstance());
Add(mActionStack); Add(mActionStack);
Add(mDamageResolver); Add(mDamageResolver);
Add(actionLayer); Add(actionLayer);
Add(mGuiHand); Add(mGuiHand);
Add(play); Add(play);
} }
ActionStack * DuelLayers::stackLayer(){ ActionStack * DuelLayers::stackLayer(){
return ((ActionStack *) (objects[0])); return ((ActionStack *) (objects[0]));
} }
DamageResolverLayer * DuelLayers::combatLayer(){ DamageResolverLayer * DuelLayers::combatLayer(){
return ((DamageResolverLayer *) (objects[1])); return ((DamageResolverLayer *) (objects[1]));
} }
ActionLayer * DuelLayers::actionLayer(){ ActionLayer * DuelLayers::actionLayer(){
return ((ActionLayer *) (objects[2])); return ((ActionLayer *) (objects[2]));
} }
MTGGuiHand * DuelLayers::handLayer(){ MTGGuiHand * DuelLayers::handLayer(){
return ((MTGGuiHand *) (objects[3])); return ((MTGGuiHand *) (objects[3]));
} }
MTGGuiPlay * DuelLayers::playLayer(){ 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) GameState::GameState(GameApp* parent): mParent(parent)
{ {
mEngine = JGE::GetInstance(); mEngine = JGE::GetInstance();
} }
GameApp::GameApp(): JApp() GameApp::GameApp(): JApp()
{ {
mScreenShotCount = 0; mScreenShotCount = 0;
for (int i=0; i < MAX_STATE ; i++) for (int i=0; i < MAX_STATE ; i++)
mGameStates[i] = NULL; mGameStates[i] = NULL;
mShowDebugInfo = false; mShowDebugInfo = false;
players[0] = 0; players[0] = 0;
players[1] = 0; players[1] = 0;
@@ -53,88 +53,88 @@ GameApp::~GameApp()
void GameApp::Create() void GameApp::Create()
{ {
#if defined (WIN32) #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) #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 #endif
//_CrtSetBreakAlloc(368); //_CrtSetBreakAlloc(368);
LOG("starting Game"); LOG("starting Game");
//Test for Music files presence //Test for Music files presence
std::ifstream file("Res/sound/Track0.mp3"); std::ifstream file("Res/sound/Track0.mp3");
if(file){ if(file){
file.close(); file.close();
}else{ }else{
HasMusic = 0; HasMusic = 0;
} }
std::ifstream file2("Res/sound/Track1.mp3"); std::ifstream file2("Res/sound/Track1.mp3");
if(file2){ if(file2){
file2.close(); file2.close();
}else{ }else{
HasMusic = 0; HasMusic = 0;
} }
CommonRes->CreateTexture("graphics/menuicons.png"); 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 //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_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_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_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_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_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_white", "graphics/menuicons.png", 10 + 4*32, 32, 32, 32);
CommonRes->CreateQuad("c_land", "graphics/menuicons.png", 10 + 5*32, 32, 32, 32); CommonRes->CreateQuad("c_land", "graphics/menuicons.png", 10 + 5*32, 32, 32, 32);
CommonRes->CreateTexture("sets/back.jpg"); CommonRes->CreateTexture("sets/back.jpg");
CommonRes->CreateQuad("back", "sets/back.jpg", 0, 0, 200, 285); CommonRes->CreateQuad("back", "sets/back.jpg", 0, 0, 200, 285);
CommonRes->CreateTexture("sets/back_thumb.jpg"); CommonRes->CreateTexture("sets/back_thumb.jpg");
CommonRes->CreateQuad("back_thumb", "sets/back_thumb.jpg", 0, 0, 45, 64); CommonRes->CreateQuad("back_thumb", "sets/back_thumb.jpg", 0, 0, 45, 64);
CommonRes->CreateTexture("graphics/particles.png"); CommonRes->CreateTexture("graphics/particles.png");
CommonRes->CreateQuad("particles", "graphics/particles.png", 0, 0, 32, 32); CommonRes->CreateQuad("particles", "graphics/particles.png", 0, 0, 32, 32);
CommonRes->GetQuad("particles")->SetHotSpot(16,16); CommonRes->GetQuad("particles")->SetHotSpot(16,16);
CommonRes->LoadJLBFont("graphics/f3",16); CommonRes->LoadJLBFont("graphics/f3",16);
CommonRes->LoadJLBFont("graphics/magic",16); CommonRes->LoadJLBFont("graphics/magic",16);
//CommonRes->CreateTexture("graphics/interrupt.png"); //CommonRes->CreateTexture("graphics/interrupt.png");
//CommonRes->CreateQuad("interrupt", "graphics/interrupt.png", 0, 0, 256, 128); //CommonRes->CreateQuad("interrupt", "graphics/interrupt.png", 0, 0, 256, 128);
cache = NEW TexturesCache(); cache = NEW TexturesCache();
collection = NEW MTGAllCards(cache); collection = NEW MTGAllCards(cache);
Particles[0] = NEW hgeParticleSystem("graphics/particle1.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[1] = NEW hgeParticleSystem("graphics/particle2.psi", CommonRes->GetQuad("particles"));
Particles[2] = NEW hgeParticleSystem("graphics/particle3.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[3] = NEW hgeParticleSystem("graphics/particle4.psi", CommonRes->GetQuad("particles"));
Particles[4] = NEW hgeParticleSystem("graphics/particle5.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[5] = NEW hgeParticleSystem("graphics/particle7.psi", CommonRes->GetQuad("particles"));
mGameStates[GAME_STATE_DECK_VIEWER] = NEW GameStateDeckViewer(this); mGameStates[GAME_STATE_DECK_VIEWER] = NEW GameStateDeckViewer(this);
mGameStates[GAME_STATE_DECK_VIEWER]->Create(); mGameStates[GAME_STATE_DECK_VIEWER]->Create();
mGameStates[GAME_STATE_MENU] = NEW GameStateMenu(this); mGameStates[GAME_STATE_MENU] = NEW GameStateMenu(this);
mGameStates[GAME_STATE_MENU]->Create(); mGameStates[GAME_STATE_MENU]->Create();
mGameStates[GAME_STATE_DUEL] = NEW GameStateDuel(this); mGameStates[GAME_STATE_DUEL] = NEW GameStateDuel(this);
mGameStates[GAME_STATE_DUEL]->Create(); mGameStates[GAME_STATE_DUEL]->Create();
mGameStates[GAME_STATE_SHOP] = NEW GameStateShop(this); mGameStates[GAME_STATE_SHOP] = NEW GameStateShop(this);
mGameStates[GAME_STATE_SHOP]->Create(); mGameStates[GAME_STATE_SHOP]->Create();
mGameStates[GAME_STATE_OPTIONS] = NEW GameStateOptions(this); mGameStates[GAME_STATE_OPTIONS] = NEW GameStateOptions(this);
mGameStates[GAME_STATE_OPTIONS]->Create(); mGameStates[GAME_STATE_OPTIONS]->Create();
//mGameStates[GAME_STATE_GAME] = NEW GameStateGAME(this); //mGameStates[GAME_STATE_GAME] = NEW GameStateGAME(this);
mCurrentState = NULL; mCurrentState = NULL;
mNextState = mGameStates[GAME_STATE_MENU]; mNextState = mGameStates[GAME_STATE_MENU];
@@ -152,32 +152,32 @@ void GameApp::LoadGameStates()
void GameApp::Destroy() void GameApp::Destroy()
{ {
LOG("==Destroying GameApp=="); LOG("==Destroying GameApp==");
for (int i=GAME_STATE_MENU;i<=MAX_STATE-1;i++) for (int i=GAME_STATE_MENU;i<=MAX_STATE-1;i++)
{ {
if (mGameStates[i]){ if (mGameStates[i]){
mGameStates[i]->Destroy(); mGameStates[i]->Destroy();
delete mGameStates[i]; delete mGameStates[i];
} }
} }
for (int i= 0; i < 6; i++){ for (int i= 0; i < 6; i++){
delete Particles[i]; delete Particles[i];
} }
if (collection){ if (collection){
collection->destroyAllCards(); collection->destroyAllCards();
delete collection; delete collection;
} }
if (cache) delete cache; if (cache) delete cache;
if (CommonRes) delete CommonRes; if (CommonRes) delete CommonRes;
GameOptions::Destroy(); GameOptions::Destroy();
if (Subtypes::subtypesList) delete Subtypes::subtypesList; if (Subtypes::subtypesList) delete Subtypes::subtypesList;
if (MtgSets::SetsList) delete MtgSets::SetsList; if (MtgSets::SetsList) delete MtgSets::SetsList;
LOG("==Destroying GameApp Successful=="); LOG("==Destroying GameApp Successful==");
} }
@@ -186,38 +186,38 @@ void GameApp::Destroy()
void GameApp::Update() void GameApp::Update()
{ {
JGE* mEngine = JGE::GetInstance(); JGE* mEngine = JGE::GetInstance();
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE)) if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE))
{ {
char s[80]; char s[80];
sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++); sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++);
JRenderer::GetInstance()->ScreenShot(s); JRenderer::GetInstance()->ScreenShot(s);
} }
//Exit when START and X ARE PRESSED SIMULTANEOUSLY //Exit when START and X ARE PRESSED SIMULTANEOUSLY
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_CROSS)){ if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_CROSS)){
mEngine->End(); mEngine->End();
return; return;
} }
float dt = mEngine->GetDelta(); float dt = mEngine->GetDelta();
if (dt > 35.0f) // min 30 FPS ;) if (dt > 35.0f) // min 30 FPS ;)
dt = 35.0f; dt = 35.0f;
if (mCurrentState != NULL) if (mCurrentState != NULL)
mCurrentState->Update(dt); mCurrentState->Update(dt);
if (mNextState != NULL) if (mNextState != NULL)
{ {
if (mCurrentState != NULL) if (mCurrentState != NULL)
mCurrentState->End(); mCurrentState->End();
mCurrentState = mNextState; mCurrentState = mNextState;
mCurrentState->Start(); mCurrentState->Start();
mNextState = NULL; mNextState = NULL;
} }
@@ -227,17 +227,17 @@ void GameApp::Update()
void GameApp::Render() void GameApp::Render()
{ {
if (mCurrentState != NULL) if (mCurrentState != NULL)
{ {
mCurrentState->Render(); mCurrentState->Render();
} }
} }
void GameApp::SetNextState(int state) void GameApp::SetNextState(int state)
{ {
mNextState = mGameStates[state]; mNextState = mGameStates[state];
} }
void GameApp::Pause(){ void GameApp::Pause(){
+9 -9
View File
@@ -16,15 +16,15 @@
class GameApp: public JApp class GameApp: public JApp
{ {
public: public:
GameApp(); GameApp();
virtual ~GameApp(); virtual ~GameApp();
virtual void Create(); virtual void Create();
virtual void Destroy(); virtual void Destroy();
virtual void Update(); virtual void Update();
virtual void Render(); virtual void Render();
virtual void Pause(); virtual void Pause();
virtual void Resume(); virtual void Resume();
}; };
+3 -3
View File
@@ -17,20 +17,20 @@
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
JApp* JGameLauncher::GetGameApp() JApp* JGameLauncher::GetGameApp()
{ {
return NEW GameApp(); return NEW GameApp();
}; };
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
char *JGameLauncher::GetName() char *JGameLauncher::GetName()
{ {
return strdup("Wagic"); return strdup("Wagic");
} }
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
u32 JGameLauncher::GetInitFlags() 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() GameObserver* GameObserver::GetInstance()
{ {
return mInstance; return mInstance;
} }
void GameObserver::EndInstance() void GameObserver::EndInstance()
{ {
SAFE_DELETE(mInstance); SAFE_DELETE(mInstance);
} }
void GameObserver::Init(Player * _players[], int _nbplayers){ void GameObserver::Init(Player * _players[], int _nbplayers){
mInstance = NEW GameObserver(_players, _nbplayers); mInstance = NEW GameObserver(_players, _nbplayers);
mInstance->mLayers = NEW DuelLayers(); mInstance->mLayers = NEW DuelLayers();
mInstance->mLayers->init(); mInstance->mLayers->init();
} }
@@ -38,17 +38,17 @@ GameObserver::GameObserver(Player * _players[], int _nb_players){
players[i] = _players[i]; players[i] = _players[i];
} }
currentPlayer = players[0]; currentPlayer = players[0];
currentActionPlayer = currentPlayer; currentActionPlayer = currentPlayer;
isInterrupting = NULL; isInterrupting = NULL;
currentPlayerId = 0; currentPlayerId = 0;
nbPlayers = _nb_players; nbPlayers = _nb_players;
currentRound = 1; currentRound = 1;
currentGamePhase = -1; currentGamePhase = -1;
targetChooser = NULL; targetChooser = NULL;
cardWaitingForTargets = NULL; cardWaitingForTargets = NULL;
reaction = 0; reaction = 0;
gameOver = NULL; gameOver = NULL;
phaseRing = NEW PhaseRing(_players,_nb_players); phaseRing = NEW PhaseRing(_players,_nb_players);
} }
void GameObserver::setGamePhaseManager(MTGGamePhase * _phases){ void GameObserver::setGamePhaseManager(MTGGamePhase * _phases){
@@ -61,83 +61,83 @@ int GameObserver::getCurrentGamePhase(){
Player * GameObserver::opponent(){ Player * GameObserver::opponent(){
int index = (currentPlayerId+1)%nbPlayers; int index = (currentPlayerId+1)%nbPlayers;
return players[index]; return players[index];
} }
int GameObserver::enteringPhase(int phase){ int GameObserver::enteringPhase(int phase){
//TODO //TODO
return 0; return 0;
} }
void GameObserver::nextPlayer(){ void GameObserver::nextPlayer(){
currentPlayerId = (currentPlayerId+1)%nbPlayers; currentPlayerId = (currentPlayerId+1)%nbPlayers;
currentPlayer = players[currentPlayerId]; currentPlayer = players[currentPlayerId];
currentActionPlayer = currentPlayer; currentActionPlayer = currentPlayer;
} }
void GameObserver::nextGamePhase(){ void GameObserver::nextGamePhase(){
phaseRing->forward(); phaseRing->forward();
Phase * cPhase = phaseRing->getCurrentPhase(); Phase * cPhase = phaseRing->getCurrentPhase();
currentGamePhase = cPhase->id; currentGamePhase = cPhase->id;
if (currentPlayer != cPhase->player) nextPlayer(); if (currentPlayer != cPhase->player) nextPlayer();
//init begin of turn //init begin of turn
if (currentGamePhase == MTG_PHASE_BEFORE_BEGIN){ if (currentGamePhase == MTG_PHASE_BEFORE_BEGIN){
cleanupPhase(); cleanupPhase();
currentPlayer->canPutLandsIntoPlay = 1; currentPlayer->canPutLandsIntoPlay = 1;
mLayers->actionLayer()->Update(0); mLayers->actionLayer()->Update(0);
return nextGamePhase(); return nextGamePhase();
} }
//manaBurn //manaBurn
if (currentGamePhase == MTG_PHASE_UNTAP || if (currentGamePhase == MTG_PHASE_UNTAP ||
currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_FIRSTMAIN ||
currentGamePhase == MTG_PHASE_COMBATBEGIN || currentGamePhase == MTG_PHASE_COMBATBEGIN ||
currentGamePhase == MTG_PHASE_SECONDMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN ||
currentGamePhase == MTG_PHASE_ENDOFTURN currentGamePhase == MTG_PHASE_ENDOFTURN
){ ){
currentPlayer->manaBurn(); currentPlayer->manaBurn();
} }
//After End of turn //After End of turn
if (currentGamePhase == MTG_PHASE_AFTER_EOT){ if (currentGamePhase == MTG_PHASE_AFTER_EOT){
//Auto Hand cleaning, in case the player didn't do it himself //Auto Hand cleaning, in case the player didn't do it himself
while(currentPlayer->game->hand->nb_cards > 7){ while(currentPlayer->game->hand->nb_cards > 7){
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]); currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
} }
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn; mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
mLayers->actionLayer()->Update(0); mLayers->actionLayer()->Update(0);
return nextGamePhase(); return nextGamePhase();
} }
//Phase Specific actions //Phase Specific actions
switch(currentGamePhase){ switch(currentGamePhase){
case MTG_PHASE_UNTAP: case MTG_PHASE_UNTAP:
untapPhase(); untapPhase();
break; break;
case MTG_PHASE_DRAW: case MTG_PHASE_DRAW:
mLayers->stackLayer()->addDraw(currentPlayer,1); mLayers->stackLayer()->addDraw(currentPlayer,1);
break; break;
default: default:
break; break;
} }
} }
int GameObserver::cancelCurrentAction(){ int GameObserver::cancelCurrentAction(){
SAFE_DELETE(targetChooser); SAFE_DELETE(targetChooser);
return 1; return 1;
} }
void GameObserver::userRequestNextGamePhase(){ void GameObserver::userRequestNextGamePhase(){
if (mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)) return; if (mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)) return;
if (getCurrentTargetChooser()) return; if (getCurrentTargetChooser()) return;
if (mLayers->combatLayer()->remainingDamageSteps) return; if (mLayers->combatLayer()->remainingDamageSteps) return;
//TODO CHECK POSSIBILITY //TODO CHECK POSSIBILITY
if (opponent()->isAI() || GameOptions::GetInstance()->values[OPTIONS_INTERRUPTATENDOFPHASE_OFFSET+currentGamePhase]){ if (opponent()->isAI() || GameOptions::GetInstance()->values[OPTIONS_INTERRUPTATENDOFPHASE_OFFSET+currentGamePhase]){
mLayers->stackLayer()->AddNextGamePhase(); mLayers->stackLayer()->AddNextGamePhase();
}else{ }else{
nextGamePhase(); nextGamePhase();
} }
} }
@@ -147,8 +147,8 @@ void GameObserver::startGame(int shuffle, int draw){
for (i=0; i<nbPlayers; i++){ for (i=0; i<nbPlayers; i++){
players[i]->game->initGame(shuffle, draw); players[i]->game->initGame(shuffle, draw);
} }
phaseRing->goToPhase(MTG_PHASE_FIRSTMAIN, players[0]); phaseRing->goToPhase(MTG_PHASE_FIRSTMAIN, players[0]);
currentGamePhase = MTG_PHASE_FIRSTMAIN; currentGamePhase = MTG_PHASE_FIRSTMAIN;
} }
void GameObserver::addObserver(MTGAbility * observer){ void GameObserver::addObserver(MTGAbility * observer){
@@ -157,62 +157,62 @@ void GameObserver::addObserver(MTGAbility * observer){
void GameObserver::removeObserver(ActionElement * observer){ void GameObserver::removeObserver(ActionElement * observer){
if (observer){ if (observer){
observer->destroy(); observer->destroy();
}else{ }else{
//TODO log error //TODO log error
} }
mLayers->actionLayer()->Remove(observer); mLayers->actionLayer()->Remove(observer);
} }
GameObserver::~GameObserver(){ GameObserver::~GameObserver(){
LOG("==Destroying GameObserver=="); LOG("==Destroying GameObserver==");
SAFE_DELETE(targetChooser); SAFE_DELETE(targetChooser);
SAFE_DELETE(mLayers); SAFE_DELETE(mLayers);
SAFE_DELETE(phaseRing); SAFE_DELETE(phaseRing);
LOG("==GameObserver Destroyed=="); LOG("==GameObserver Destroyed==");
} }
void GameObserver::Update(float dt){ void GameObserver::Update(float dt){
Player * player = currentPlayer; Player * player = currentPlayer;
if (currentGamePhase == MTG_PHASE_COMBATBLOCKERS){ if (currentGamePhase == MTG_PHASE_COMBATBLOCKERS){
player = opponent(); player = opponent();
}else if (currentGamePhase == MTG_PHASE_COMBATDAMAGE){ }else if (currentGamePhase == MTG_PHASE_COMBATDAMAGE){
DamageResolverLayer * drl = mLayers->combatLayer(); DamageResolverLayer * drl = mLayers->combatLayer();
if (drl->currentChoosingPlayer && drl->mCount) player = drl->currentChoosingPlayer; if (drl->currentChoosingPlayer && drl->mCount) player = drl->currentChoosingPlayer;
} }
currentActionPlayer = player; currentActionPlayer = player;
if (isInterrupting) player = isInterrupting; if (isInterrupting) player = isInterrupting;
mLayers->Update(dt,player); mLayers->Update(dt,player);
stateEffects(); stateEffects();
oldGamePhase = currentGamePhase; oldGamePhase = currentGamePhase;
} }
//applies damage to creatures after updates //applies damage to creatures after updates
//Players life test //Players life test
void GameObserver::stateEffects(){ void GameObserver::stateEffects(){
for (int i =0; i < 2; i++){ for (int i =0; i < 2; i++){
MTGGameZone * zone = players[i]->game->inPlay; MTGGameZone * zone = players[i]->game->inPlay;
for (int j = zone->nb_cards-1 ; j>=0; j--){ for (int j = zone->nb_cards-1 ; j>=0; j--){
MTGCardInstance * card = zone->cards[j]; MTGCardInstance * card = zone->cards[j];
card->afterDamage(); card->afterDamage();
} }
} }
for (int i =0; i < 2; i++){ for (int i =0; i < 2; i++){
if (players[i]->life <= 0) gameOver = players[i]; if (players[i]->life <= 0) gameOver = players[i];
} }
} }
void GameObserver::Render(){ void GameObserver::Render(){
mLayers->Render(); mLayers->Render();
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()){ if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()){
JRenderer::GetInstance()->DrawRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(255,255,0,0)); JRenderer::GetInstance()->DrawRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(255,255,0,0));
} }
} }
@@ -225,202 +225,202 @@ void GameObserver::nextStep(){
void GameObserver::ButtonPressed (int controllerId, PlayGuiObject * _object){ 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) #if defined (WIN32) || defined (LINUX)
OutputDebugString("Click Player !\n"); OutputDebugString("Click\n");
#endif #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){ void GameObserver::stackObjectClicked(Interruptible * action){
if (targetChooser != NULL){ if (targetChooser != NULL){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser ok \n"); OutputDebugString("target chooser ok \n");
#endif #endif
int result = targetChooser->toggleTarget(action); int result = targetChooser->toggleTarget(action);
if (result == TARGET_OK_FULL){ if (result == TARGET_OK_FULL){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("target chooser Full \n"); OutputDebugString("target chooser Full \n");
#endif #endif
cardClick(cardWaitingForTargets); cardClick(cardWaitingForTargets);
}else{ }else{
return; return;
} }
}else{ }else{
reaction = mLayers->actionLayer()->isReactingToTargetClick(action); reaction = mLayers->actionLayer()->isReactingToTargetClick(action);
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(action); if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(action);
} }
} }
void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
LOG("==GameObserver::cardClick"); LOG("==GameObserver::cardClick");
if (card) {LOG(card->getName())}; if (card) {LOG(card->getName())};
Player * clickedPlayer = NULL; Player * clickedPlayer = NULL;
if (!card) clickedPlayer = ((Player *)object); if (!card) clickedPlayer = ((Player *)object);
if (targetChooser != NULL){ if (targetChooser != NULL){
int result; int result;
if (card) { if (card) {
if (card == cardWaitingForTargets){ if (card == cardWaitingForTargets){
LOG("attempt to close targetting"); LOG("attempt to close targetting");
int _result = targetChooser->ForceTargetListReady(); int _result = targetChooser->ForceTargetListReady();
if (_result){ if (_result){
result = TARGET_OK_FULL; result = TARGET_OK_FULL;
}else{ }else{
LOG("...but we cant!\n"); LOG("...but we cant!\n");
result = targetChooser->targetsReadyCheck(); result = targetChooser->targetsReadyCheck();
} }
}else{ }else{
result = targetChooser->toggleTarget(card); result = targetChooser->toggleTarget(card);
} }
}else{ }else{
result = targetChooser->toggleTarget(clickedPlayer); result = targetChooser->toggleTarget(clickedPlayer);
} }
if (result == TARGET_OK_FULL){ if (result == TARGET_OK_FULL){
card = cardWaitingForTargets; card = cardWaitingForTargets;
}else{ }else{
return; return;
} }
} }
if (card){ if (card){
reaction = mLayers->actionLayer()->isReactingToClick(card); reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction == -1) mLayers->actionLayer()->reactToClick(card); if (reaction == -1) mLayers->actionLayer()->reactToClick(card);
}else{ }else{
reaction = mLayers->actionLayer()->isReactingToTargetClick(object); reaction = mLayers->actionLayer()->isReactingToTargetClick(object);
if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(object); if (reaction == -1) mLayers->actionLayer()->reactToTargetClick(object);
} }
if (reaction != -1){ if (reaction != -1){
if (!card) return; if (!card) return;
if (currentlyActing()->game->hand->hasCard(card)){ if (currentlyActing()->game->hand->hasCard(card)){
//Current player's hand //Current player's hand
if (canPutInPlay(card)){ if (canPutInPlay(card)){
putInPlay(card); putInPlay(card);
if (card->hasType("land")){ if (card->hasType("land")){
currentPlayer->canPutLandsIntoPlay--; currentPlayer->canPutLandsIntoPlay--;
} }
}else if (currentPlayer->game->hand->hasCard(card)){ //Current player's hand }else if (currentPlayer->game->hand->hasCard(card)){ //Current player's hand
if (currentGamePhase == MTG_PHASE_CLEANUP && currentPlayer->game->hand->nb_cards > 7){ if (currentGamePhase == MTG_PHASE_CLEANUP && currentPlayer->game->hand->nb_cards > 7){
currentPlayer->game->putInGraveyard(card); currentPlayer->game->putInGraveyard(card);
} }
} }
}else if (reaction){ }else if (reaction){
if (reaction == 1){ if (reaction == 1){
mLayers->actionLayer()->reactToClick(card); mLayers->actionLayer()->reactToClick(card);
}else{ }else{
mLayers->actionLayer()->setMenuObject(object); mLayers->actionLayer()->setMenuObject(object);
} }
}else if (card->isTapped() && card->controller() == currentPlayer){ }else if (card->isTapped() && card->controller() == currentPlayer){
int a = ConstraintResolver::untap(this, card); int a = ConstraintResolver::untap(this, card);
} }
} }
} }
TargetChooser * GameObserver::getCurrentTargetChooser(){ TargetChooser * GameObserver::getCurrentTargetChooser(){
TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser(); TargetChooser * _tc = mLayers->actionLayer()->getCurrentTargetChooser();
if (_tc) return _tc; if (_tc) return _tc;
return targetChooser; return targetChooser;
} }
//Check if it is possible to put a card into play //Check if it is possible to put a card into play
//TODO : improve according to spells in game... //TODO : improve according to spells in game...
int GameObserver::canPutInPlay(MTGCardInstance * card){ int GameObserver::canPutInPlay(MTGCardInstance * card){
Player * player = currentlyActing(); Player * player = currentlyActing();
LOG("CANPUTINPLAY- check if card belongs to current player\n"); LOG("CANPUTINPLAY- check if card belongs to current player\n");
if (!player->game->hand->hasCard(card)) return 0; if (!player->game->hand->hasCard(card)) return 0;
LOG("CANPUTINPLAY- check if card is land or can be played\n"); LOG("CANPUTINPLAY- check if card is land or can be played\n");
if (card->hasType("land")){ if (card->hasType("land")){
LOG("CANPUTINPLAY- card is land - check if can be played\n"); LOG("CANPUTINPLAY- card is land - check if can be played\n");
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN)){ if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN)){
LOG("CANPUTINPLAY- Land, ok\n"); LOG("CANPUTINPLAY- Land, ok\n");
return 1; return 1;
} }
}else if ((card->hasType("instant")) || card->has(FLASH) || (player == currentPlayer && (currentGamePhase == MTG_PHASE_FIRSTMAIN || currentGamePhase == MTG_PHASE_SECONDMAIN))){ }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"); LOG("CANPUTINPLAY- correct time to play\n");
if (checkManaCost(card)){ if (checkManaCost(card)){
LOG("CANPUTINPLAY- ManaCost ok\n"); LOG("CANPUTINPLAY- ManaCost ok\n");
if (targetListIsSet(card)){ if (targetListIsSet(card)){
#ifdef LOG #ifdef LOG
LOG("CANPUTINPLAY- Targets chosen -> OK\n"); LOG("CANPUTINPLAY- Targets chosen -> OK\n");
#endif #endif
return 1; return 1;
}else{ }else{
#ifdef LOG #ifdef LOG
LOG("CANPUTINPLAY- Targets not chosen yet\n"); LOG("CANPUTINPLAY- Targets not chosen yet\n");
#endif #endif
return 0;
}
}
}
return 0; return 0;
}
}
}
return 0;
} }
void GameObserver::putInPlay(MTGCardInstance * card){ void GameObserver::putInPlay(MTGCardInstance * card){
Player * player = currentlyActing(); Player * player = currentlyActing();
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool()); ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
player->getManaPool()->pay(card->getManaCost()); player->getManaPool()->pay(card->getManaCost());
ManaCost * spellCost = previousManaPool->Diff(player->getManaPool()); ManaCost * spellCost = previousManaPool->Diff(player->getManaPool());
delete previousManaPool; delete previousManaPool;
if (card->hasType("land")){ if (card->hasType("land")){
Spell * spell = NEW Spell(card); Spell * spell = NEW Spell(card);
player->game->putInZone(card, player->game->hand, player->game->stack); player->game->putInZone(card, player->game->hand, player->game->stack);
spell->resolve(); spell->resolve();
delete spellCost; delete spellCost;
delete spell; delete spell;
}else{ }else{
if (targetChooser){ if (targetChooser){
mLayers->stackLayer()->addSpell(card,targetChooser->targets,targetChooser->cursor, spellCost); mLayers->stackLayer()->addSpell(card,targetChooser->targets,targetChooser->cursor, spellCost);
delete targetChooser; delete targetChooser;
targetChooser = NULL; targetChooser = NULL;
}else{ }else{
mLayers->stackLayer()->addSpell(card,NULL,0, spellCost); mLayers->stackLayer()->addSpell(card,NULL,0, spellCost);
} }
player->game->putInZone(card, player->game->hand, player->game->stack); player->game->putInZone(card, player->game->hand, player->game->stack);
} }
} }
/* Returns true if the card is in one of the player's play zone */ /* Returns true if the card is in one of the player's play zone */
int GameObserver::isInPlay(MTGCardInstance * card){ int GameObserver::isInPlay(MTGCardInstance * card){
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
if (players[i]->game->isInPlay(card)) return 1; if (players[i]->game->isInPlay(card)) return 1;
} }
return 0; return 0;
} }
void GameObserver::draw(){ void GameObserver::draw(){
//TODO checks to allow multiple draw, or no draw, etc... //TODO checks to allow multiple draw, or no draw, etc...
currentPlayer->game->drawFromLibrary(); currentPlayer->game->drawFromLibrary();
} }
void GameObserver::cleanupPhase(){ void GameObserver::cleanupPhase(){
currentPlayer->cleanupPhase(); currentPlayer->cleanupPhase();
opponent()->cleanupPhase(); opponent()->cleanupPhase();
} }
void GameObserver::untapPhase(){ void GameObserver::untapPhase(){
currentPlayer->inPlay()->untapAll(); currentPlayer->inPlay()->untapAll();
} }
@@ -430,44 +430,44 @@ int GameObserver::isACreature(MTGCardInstance * card){
Player * GameObserver::currentlyActing(){ Player * GameObserver::currentlyActing(){
if (isInterrupting) return isInterrupting; if (isInterrupting) return isInterrupting;
return currentActionPlayer; return currentActionPlayer;
} }
int GameObserver::tryToTapOrUntap(MTGCardInstance * card){ int GameObserver::tryToTapOrUntap(MTGCardInstance * card){
int reaction = mLayers->actionLayer()->isReactingToClick(card); int reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction){ if (reaction){
if (reaction == 1){ if (reaction == 1){
mLayers->actionLayer()->reactToClick(card); mLayers->actionLayer()->reactToClick(card);
}else{ }else{
//TODO, what happens when several abilities react to the click ? //TODO, what happens when several abilities react to the click ?
} }
return reaction; return reaction;
}else{ }else{
if (card->isTapped() && card->controller() == currentPlayer){ if (card->isTapped() && card->controller() == currentPlayer){
int a = ConstraintResolver::untap(this, card); int a = ConstraintResolver::untap(this, card);
return a; return a;
}else{ }else{
//TODO Check Spells //TODO Check Spells
//card->tap(); //card->tap();
return 0; return 0;
} }
return 0; return 0;
} }
} }
//TODO CORRECT THIS MESS //TODO CORRECT THIS MESS
int GameObserver::targetListIsSet(MTGCardInstance * card){ int GameObserver::targetListIsSet(MTGCardInstance * card){
if (targetChooser == NULL){ if (targetChooser == NULL){
TargetChooserFactory tcf; TargetChooserFactory tcf;
targetChooser = tcf.createTargetChooser(card); targetChooser = tcf.createTargetChooser(card);
cardWaitingForTargets = card; cardWaitingForTargets = card;
if (targetChooser == NULL){ if (targetChooser == NULL){
return 1; return 1;
} }
} }
return (targetChooser->targetListSet()); return (targetChooser->targetListSet());
} }
+34 -34
View File
@@ -8,45 +8,45 @@
GameOptions* GameOptions::mInstance = NULL; GameOptions* GameOptions::mInstance = NULL;
GameOptions * GameOptions::GetInstance(){ GameOptions * GameOptions::GetInstance(){
if (mInstance == NULL) if (mInstance == NULL)
mInstance = NEW GameOptions(); mInstance = NEW GameOptions();
return mInstance; return mInstance;
} }
GameOptions::GameOptions(){ GameOptions::GameOptions(){
for(int i = 0; i < MAX_OPTIONS; i++){ for(int i = 0; i < MAX_OPTIONS; i++){
values[i] = 0; values[i] = 0;
} }
load(); load();
} }
int GameOptions::load(){ int GameOptions::load(){
std::ifstream file(OPTIONS_SAVEFILE); std::ifstream file(OPTIONS_SAVEFILE);
std::string s; std::string s;
if(file){ if(file){
for (int i = 0; i < MAX_OPTIONS; i++){ for (int i = 0; i < MAX_OPTIONS; i++){
if(std::getline(file,s)){ if(std::getline(file,s)){
values[i] = atoi(s.c_str()); values[i] = atoi(s.c_str());
}else{ }else{
//TODO error management //TODO error management
} }
} }
file.close(); file.close();
} }
return 1; return 1;
} }
int GameOptions::save(){ int GameOptions::save(){
std::ofstream file(OPTIONS_SAVEFILE); std::ofstream file(OPTIONS_SAVEFILE);
char writer[10]; char writer[10];
if (file){ if (file){
for (int i = 0; i < MAX_OPTIONS; i++){ for (int i = 0; i < MAX_OPTIONS; i++){
sprintf(writer,"%i\n", values[i]); sprintf(writer,"%i\n", values[i]);
file<<writer; file<<writer;
} }
file.close(); file.close();
} }
return 1; return 1;
} }
@@ -54,8 +54,8 @@ GameOptions::~GameOptions(){
} }
void GameOptions::Destroy(){ void GameOptions::Destroy(){
if (mInstance){ if (mInstance){
delete mInstance; delete mInstance;
mInstance = NULL; mInstance = NULL;
} }
} }
+209 -209
View File
@@ -5,74 +5,74 @@
#include "../include/PlayerData.h" #include "../include/PlayerData.h"
#ifdef TESTSUITE #ifdef TESTSUITE
#include "../include/TestSuiteAI.h" #include "../include/TestSuiteAI.h"
#endif #endif
GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) { GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) {
for (int i = 0; i<2; i ++){ for (int i = 0; i<2; i ++){
deck[i]=NULL; deck[i]=NULL;
mPlayers[i]=NULL; mPlayers[i]=NULL;
} }
game = NULL; game = NULL;
deckmenu = NULL; deckmenu = NULL;
menu = NULL; menu = NULL;
#ifdef TESTSUITE #ifdef TESTSUITE
testSuite = NULL; testSuite = NULL;
#endif #endif
} }
GameStateDuel::~GameStateDuel() { GameStateDuel::~GameStateDuel() {
End(); End();
} }
void GameStateDuel::Start() void GameStateDuel::Start()
{ {
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
renderer->ResetPrivateVRAM(); renderer->ResetPrivateVRAM();
renderer->EnableVSync(true); renderer->EnableVSync(true);
#ifdef TESTSUITE #ifdef TESTSUITE
if (testSuite) delete testSuite; if (testSuite) delete testSuite;
testSuite = NEW TestSuite("Res/test/_tests.txt"); testSuite = NEW TestSuite("Res/test/_tests.txt");
#endif #endif
mGamePhase = DUEL_CHOOSE_DECK1; mGamePhase = DUEL_CHOOSE_DECK1;
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetBase(0); // using 2nd font mFont->SetBase(0); // using 2nd font
menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200); menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200);
menu->Add(12,"Back to main menu"); menu->Add(12,"Back to main menu");
menu->Add(13, "Cancel"); menu->Add(13, "Cancel");
int decksneeded = 0; int decksneeded = 0;
for (int i = 0; i<2; i ++){ for (int i = 0; i<2; i ++){
if (mParent->players[i] == PLAYER_TYPE_HUMAN){ if (mParent->players[i] == PLAYER_TYPE_HUMAN){
if (!deckmenu){ if (!deckmenu){
decksneeded = 1; decksneeded = 1;
deckmenu = NEW SimpleMenu(1,this,mFont, 10 , 10, 100, "Choose a Deck"); deckmenu = NEW SimpleMenu(1,this,mFont, 10 , 10, 100, "Choose a Deck");
char buffer[100]; char buffer[100];
for (int j=1; j<6; j++){ for (int j=1; j<6; j++){
sprintf(buffer, "Res/player/deck%i.txt",j); sprintf(buffer, "Res/player/deck%i.txt",j);
std::ifstream file(buffer); std::ifstream file(buffer);
if(file){ if(file){
deckmenu->Add(j, GameState::menuTexts[j]); deckmenu->Add(j, GameState::menuTexts[j]);
file.close(); file.close();
decksneeded = 0; decksneeded = 0;
} }
}
}
}
} }
}
}
}
if (decksneeded) if (decksneeded)
mGamePhase = ERROR_NO_DECK; mGamePhase = ERROR_NO_DECK;
@@ -80,152 +80,152 @@ testSuite = NEW TestSuite("Res/test/_tests.txt");
void GameStateDuel::loadPlayer(int playerId, int decknb){ void GameStateDuel::loadPlayer(int playerId, int decknb){
if (decknb){ //Human Player if (decknb){ //Human Player
char deckFile[255]; char deckFile[255];
sprintf(deckFile, "Res/player/deck%i.txt",decknb); sprintf(deckFile, "Res/player/deck%i.txt",decknb);
char deckFileSmall[255]; char deckFileSmall[255];
sprintf(deckFileSmall, "player_deck%i",decknb); sprintf(deckFileSmall, "player_deck%i",decknb);
int deck_cards_ids[100]; int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids); int nb_elements = readfile_to_ints(deckFile, deck_cards_ids);
deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements); deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements);
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall); mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall);
}else{ }else{
AIPlayerFactory playerCreator; AIPlayerFactory playerCreator;
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,NULL); mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,NULL);
deck[playerId] = mPlayers[playerId]->game; deck[playerId] = mPlayers[playerId]->game;
} }
} }
#ifdef TESTSUITE #ifdef TESTSUITE
void GameStateDuel::loadTestSuitePlayers(){ void GameStateDuel::loadTestSuitePlayers(){
OutputDebugString ("loading suite 1\n"); OutputDebugString ("loading suite 1\n");
if (!testSuite) return; if (!testSuite) return;
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
if (mPlayers[i]){ if (mPlayers[i]){
delete mPlayers[i]; delete mPlayers[i];
} }
mPlayers[i] = NEW TestSuiteAI(mParent->collection,testSuite, i); mPlayers[i] = NEW TestSuiteAI(mParent->collection,testSuite, i);
OutputDebugString ("loading suite 2\n"); OutputDebugString ("loading suite 2\n");
deck[i] = mPlayers[i]->game; deck[i] = mPlayers[i]->game;
} }
if (game) delete game; if (game) delete game;
game = NULL; game = NULL;
if (!game){ if (!game){
GameObserver::Init(mPlayers, 2); GameObserver::Init(mPlayers, 2);
OutputDebugString ("loading suite 3\n"); OutputDebugString ("loading suite 3\n");
game = GameObserver::GetInstance(); game = GameObserver::GetInstance();
OutputDebugString ("loading suite 4\n"); OutputDebugString ("loading suite 4\n");
game->startGame(0,0); game->startGame(0,0);
OutputDebugString ("loading suite 5\n"); OutputDebugString ("loading suite 5\n");
} }
} }
#endif #endif
void GameStateDuel::End() void GameStateDuel::End()
{ {
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("Ending GamestateDuel\n"); OutputDebugString("Ending GamestateDuel\n");
#endif #endif
GameObserver::EndInstance(); GameObserver::EndInstance();
game = NULL; game = NULL;
SAFE_DELETE(deckmenu); SAFE_DELETE(deckmenu);
JRenderer::GetInstance()->EnableVSync(false); JRenderer::GetInstance()->EnableVSync(false);
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
SAFE_DELETE(mPlayers[i]); SAFE_DELETE(mPlayers[i]);
SAFE_DELETE(deck[i]); SAFE_DELETE(deck[i]);
} }
SAFE_DELETE(menu); SAFE_DELETE(menu);
#ifdef TESTSUITE #ifdef TESTSUITE
SAFE_DELETE(testSuite); SAFE_DELETE(testSuite);
#endif #endif
} }
void GameStateDuel::Update(float dt) void GameStateDuel::Update(float dt)
{ {
if (mGamePhase == ERROR_NO_DECK){ if (mGamePhase == ERROR_NO_DECK){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){ if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){
mParent->SetNextState(GAME_STATE_DECK_VIEWER); mParent->SetNextState(GAME_STATE_DECK_VIEWER);
} }
}else if (mGamePhase == DUEL_CHOOSE_DECK1){ }else if (mGamePhase == DUEL_CHOOSE_DECK1){
if (mParent->players[0] == PLAYER_TYPE_HUMAN){ if (mParent->players[0] == PLAYER_TYPE_HUMAN){
deckmenu->Update(dt); deckmenu->Update(dt);
} }
#ifdef TESTSUITE #ifdef TESTSUITE
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){ else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite && testSuite->loadNext()){ if (testSuite && testSuite->loadNext()){
loadTestSuitePlayers(); loadTestSuitePlayers();
mGamePhase = DUEL_PLAY; mGamePhase = DUEL_PLAY;
testSuite->initGame(); testSuite->initGame();
char buf[4096]; char buf[4096];
sprintf(buf, "nb cards in player2's graveyard : %i\n",mPlayers[1]->game->graveyard->nb_cards); sprintf(buf, "nb cards in player2's graveyard : %i\n",mPlayers[1]->game->graveyard->nb_cards);
LOG(buf); LOG(buf);
}else{ }else{
mGamePhase = DUEL_END; mGamePhase = DUEL_END;
} }
} }
#endif #endif
else{ else{
loadPlayer(0); loadPlayer(0);
mGamePhase = DUEL_CHOOSE_DECK2; mGamePhase = DUEL_CHOOSE_DECK2;
} }
}else if(mGamePhase == DUEL_CHOOSE_DECK2){ }else if(mGamePhase == DUEL_CHOOSE_DECK2){
if (mParent->players[1] == PLAYER_TYPE_HUMAN){ if (mParent->players[1] == PLAYER_TYPE_HUMAN){
deckmenu->Update(dt); deckmenu->Update(dt);
} }
else{ else{
loadPlayer(1); loadPlayer(1);
mGamePhase = DUEL_PLAY; mGamePhase = DUEL_PLAY;
} }
}else if (mGamePhase == DUEL_PLAY){ }else if (mGamePhase == DUEL_PLAY){
if (!game){ if (!game){
GameObserver::Init(mPlayers, 2); GameObserver::Init(mPlayers, 2);
game = GameObserver::GetInstance(); game = GameObserver::GetInstance();
game->startGame(); game->startGame();
} }
game->Update(dt); game->Update(dt);
if (game->gameOver){ if (game->gameOver){
if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() && mPlayers[0]!= game->gameOver){ if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() && mPlayers[0]!= game->gameOver){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "%p - %p", mPlayers[0], game->gameOver); sprintf(buf, "%p - %p", mPlayers[0], game->gameOver);
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
PlayerData * playerdata = NEW PlayerData(mParent->collection); PlayerData * playerdata = NEW PlayerData(mParent->collection);
playerdata->credits+= 500; playerdata->credits+= 500;
playerdata->save(); playerdata->save();
delete playerdata; delete playerdata;
} }
mGamePhase = DUEL_END; mGamePhase = DUEL_END;
#ifdef TESTSUITE #ifdef TESTSUITE
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){ if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite->loadNext()){ if (testSuite->loadNext()){
loadTestSuitePlayers(); loadTestSuitePlayers();
mGamePhase = DUEL_PLAY; mGamePhase = DUEL_PLAY;
testSuite->initGame(); testSuite->initGame();
}else{
mGamePhase = DUEL_END;
}
}else if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
End();
Start();
}
#endif
mFont->SetColor(ARGB(255,255,255,255));
}
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mGamePhase = DUEL_MENU;
}
}else if (mGamePhase == DUEL_MENU){
menu->Update(dt);
}else{ }else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)){ mGamePhase = DUEL_END;
mParent->SetNextState(GAME_STATE_MENU);
}
} }
}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)); JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
if (game) if (game)
game->Render(); game->Render();
if (mGamePhase == DUEL_END){ if (mGamePhase == DUEL_END){
JRenderer::GetInstance()->ClearScreen(ARGB(200,0,0,0)); JRenderer::GetInstance()->ClearScreen(ARGB(200,0,0,0));
char buffer[50]; char buffer[50];
int p0life = mPlayers[0]->life; int p0life = mPlayers[0]->life;
if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() ){ if (!mPlayers[0]->isAI() && mPlayers[1]->isAI() ){
if (game->gameOver !=mPlayers[0]){ if (game->gameOver !=mPlayers[0]){
sprintf (buffer, "Victory! Congratulations, You earn 500 credits"); sprintf (buffer, "Victory! Congratulations, You earn 500 credits");
}else{ }else{
sprintf (buffer, "You have been defeated"); sprintf (buffer, "You have been defeated");
} }
}else{ }else{
int winner = 2; int winner = 2;
if (game->gameOver !=mPlayers[0]){ if (game->gameOver !=mPlayers[0]){
winner = 1; winner = 1;
} }
sprintf(buffer, "Player %i wins (%i)", winner, p0life ); sprintf(buffer, "Player %i wins (%i)", winner, p0life );
} }
mFont->DrawString(buffer, 10, 150); mFont->DrawString(buffer, 10, 150);
}else if (mGamePhase == DUEL_CHOOSE_DECK1 || mGamePhase == DUEL_CHOOSE_DECK2){ }else if (mGamePhase == DUEL_CHOOSE_DECK1 || mGamePhase == DUEL_CHOOSE_DECK2){
if (deckmenu) if (deckmenu)
deckmenu->Render(); deckmenu->Render();
}else if (mGamePhase == ERROR_NO_DECK){ }else if (mGamePhase == ERROR_NO_DECK){
mFont->DrawString("NO DECK AVAILABLE,",0,SCREEN_HEIGHT/2); mFont->DrawString("NO DECK AVAILABLE,",0,SCREEN_HEIGHT/2);
mFont->DrawString("PRESS CIRCLE TO GO TO THE DECK EDITOR!",0,SCREEN_HEIGHT/2 + 20); mFont->DrawString("PRESS CIRCLE TO GO TO THE DECK EDITOR!",0,SCREEN_HEIGHT/2 + 20);
}else if (mGamePhase == DUEL_MENU){ }else if (mGamePhase == DUEL_MENU){
menu->Render(); menu->Render();
} }
} }
void GameStateDuel::ButtonPressed(int controllerId, int controlId) void GameStateDuel::ButtonPressed(int controllerId, int controlId)
{ {
switch (controlId) switch (controlId)
{ {
case 1: case 1:
case 2: case 2:
case 3: case 3:
case 4: case 4:
case 5: case 5:
{ {
if (mGamePhase == DUEL_CHOOSE_DECK1){ if (mGamePhase == DUEL_CHOOSE_DECK1){
loadPlayer(0,controlId); loadPlayer(0,controlId);
mGamePhase = DUEL_CHOOSE_DECK2; mGamePhase = DUEL_CHOOSE_DECK2;
}else{ }else{
loadPlayer(1,controlId); loadPlayer(1,controlId);
mGamePhase = DUEL_PLAY; mGamePhase = DUEL_PLAY;
} }
break; break;
} }
case 12: case 12:
mParent->SetNextState(GAME_STATE_MENU); mParent->SetNextState(GAME_STATE_MENU);
break; break;
case 13: case 13:
mGamePhase = DUEL_PLAY; mGamePhase = DUEL_PLAY;
break; break;
} }
} }
+62 -62
View File
@@ -6,8 +6,8 @@
#include "../include/GameOptions.h" #include "../include/GameOptions.h"
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) { GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) {
optionsList = NULL; optionsList = NULL;
optionsMenu = NULL; optionsMenu = NULL;
} }
@@ -17,39 +17,39 @@ GameStateOptions::~GameStateOptions() {
void GameStateOptions::Start() void GameStateOptions::Start()
{ {
mState = SHOW_OPTIONS; mState = SHOW_OPTIONS;
JRenderer::GetInstance()->ResetPrivateVRAM(); JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true); JRenderer::GetInstance()->EnableVSync(true);
optionsList = NEW OptionsList(); optionsList = NEW OptionsList();
if (GameApp::HasMusic) optionsList->Add(NEW OptionItem(OPTIONS_MUSICVOLUME, "Music volume", 100, 10)); if (GameApp::HasMusic) optionsList->Add(NEW OptionItem(OPTIONS_MUSICVOLUME, "Music volume", 100, 10));
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120); optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
optionsMenu->Add(1, "Save & Back to Main Menu"); optionsMenu->Add(1, "Save & Back to Main Menu");
optionsMenu->Add(2, "Back to Main Menu"); optionsMenu->Add(2, "Back to Main Menu");
optionsMenu->Add(3, "Cancel"); optionsMenu->Add(3, "Cancel");
} }
void GameStateOptions::End() void GameStateOptions::End()
{ {
JRenderer::GetInstance()->EnableVSync(false); JRenderer::GetInstance()->EnableVSync(false);
SAFE_DELETE(optionsList); SAFE_DELETE(optionsList);
} }
void GameStateOptions::Update(float dt) void GameStateOptions::Update(float dt)
{ {
if (mState == SHOW_OPTIONS){ if (mState == SHOW_OPTIONS){
if (mEngine->GetButtonClick(PSP_CTRL_START)){ if (mEngine->GetButtonClick(PSP_CTRL_START)){
mState = SHOW_OPTIONS_MENU; mState = SHOW_OPTIONS_MENU;
} }
optionsList->Update(dt); optionsList->Update(dt);
}else{ }else{
optionsMenu->Update(dt); optionsMenu->Update(dt);
} }
} }
@@ -59,60 +59,60 @@ void GameStateOptions::Render()
{ {
//Erase //Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
optionsList->Render(); optionsList->Render();
const char * const CreditsText[] = { const char * const CreditsText[] = {
"Wagic, The Homebrew ?! by WilLoW", "Wagic, The Homebrew ?! by WilLoW",
"This is a work in progress and it contains bugs, deal with it", "This is a work in progress and it contains bugs, deal with it",
"updates on http://www.wololo.net/wagic", "updates on http://www.wololo.net/wagic",
"", "",
"Developped with the JGE++ Library", "Developped with the JGE++ Library",
"http://jge.khors.com", "http://jge.khors.com",
"", "",
"this freeware app is not endorsed by Wizards of the Coast, Inc", "this freeware app is not endorsed by Wizards of the Coast, Inc",
}; };
const char * const MusicText[] = { const char * const MusicText[] = {
"", "",
"Music by Celestial Aeon Project, under Creative Commons License", "Music by Celestial Aeon Project, under Creative Commons License",
"Their music can be downloaded at http://www.jamendo.com" "Their music can be downloaded at http://www.jamendo.com"
}; };
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetColor(ARGB(255,200,200,200)); mFont->SetColor(ARGB(255,200,200,200));
mFont->SetScale(0.80); mFont->SetScale(0.80);
for (int i = 0; i < 8; i++){ for (int i = 0; i < 8; i++){
mFont->DrawString(CreditsText[i],SCREEN_WIDTH/2, 40 +18*i,JGETEXT_CENTER); mFont->DrawString(CreditsText[i],SCREEN_WIDTH/2, 40 +18*i,JGETEXT_CENTER);
} }
if (GameApp::HasMusic){ if (GameApp::HasMusic){
for (int i = 0; i < 3; i++){ for (int i = 0; i < 3; i++){
mFont->DrawString(MusicText[i],SCREEN_WIDTH/2, 40 +18*(8+i),JGETEXT_CENTER); mFont->DrawString(MusicText[i],SCREEN_WIDTH/2, 40 +18*(8+i),JGETEXT_CENTER);
} }
} }
mFont->SetScale(1.f); mFont->SetScale(1.f);
if (mState == SHOW_OPTIONS_MENU){ if (mState == SHOW_OPTIONS_MENU){
optionsMenu->Render(); optionsMenu->Render();
} }
} }
void GameStateOptions::ButtonPressed(int controllerId, int controlId) void GameStateOptions::ButtonPressed(int controllerId, int controlId)
{ {
switch (controlId){ switch (controlId){
case 1: case 1:
optionsList->save(); optionsList->save();
case 2: case 2:
mParent->SetNextState(GAME_STATE_MENU); mParent->SetNextState(GAME_STATE_MENU);
break; break;
case 3: case 3:
mState = SHOW_OPTIONS; mState = SHOW_OPTIONS;
break; 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 "../include/debug.h"
#include <JRenderer.h> #include <JRenderer.h>
@@ -12,7 +12,7 @@ GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {}
GameStateShop::~GameStateShop() { GameStateShop::~GameStateShop() {
//End(); TODO FIX THAT //End(); TODO FIX THAT
} }
void GameStateShop::Create(){ void GameStateShop::Create(){
@@ -24,54 +24,54 @@ void GameStateShop::Create(){
void GameStateShop::Start() void GameStateShop::Start()
{ {
menu = NULL; menu = NULL;
mFont = GameApp::CommonRes->GetJLBFont("graphics/magic"); mFont = GameApp::CommonRes->GetJLBFont("graphics/magic");
mStage = STAGE_SHOP_SHOP; mStage = STAGE_SHOP_SHOP;
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/shop.jpg", TEX_TYPE_USE_VRAM); bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/shop.jpg", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 0, 0, 400, 280); // Create background quad for rendering. mBg = NEW JQuad(bgTexture, 0, 0, 400, 280); // Create background quad for rendering.
backTexture = JRenderer::GetInstance()->LoadTexture("sets/back.jpg", TEX_TYPE_USE_VRAM); backTexture = JRenderer::GetInstance()->LoadTexture("sets/back.jpg", TEX_TYPE_USE_VRAM);
mBack = NEW JQuad(backTexture, 0, 0, 200, 285); // Create background quad for rendering. mBack = NEW JQuad(backTexture, 0, 0, 200, 285); // Create background quad for rendering.
JRenderer::GetInstance()->ResetPrivateVRAM(); JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true); JRenderer::GetInstance()->EnableVSync(true);
int sets[500]; int sets[500];
int nbsets = 0; int nbsets = 0;
for (int i = 0; i < MtgSets::SetsList->nb_items; i++){ 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 if (mParent->collection->countBySet(i) > 100){ //Only sets with more than 100 cards can get boosters and starters
sets[nbsets] = i; sets[nbsets] = i;
nbsets++; nbsets++;
} }
} }
if (nbsets){ if (nbsets){
setId = sets[(rand() % nbsets)]; setId = sets[(rand() % nbsets)];
}else{ }else{
setId = (rand() % MtgSets::SetsList->nb_items); setId = (rand() % MtgSets::SetsList->nb_items);
} }
JQuad * mBackThumb = GameApp::CommonRes->GetQuad("back_thumb"); JQuad * mBackThumb = GameApp::CommonRes->GetQuad("back_thumb");
shop = NEW ShopItems(10, this, mFont, 10, 10, mParent->collection, setId); shop = NEW ShopItems(10, this, mFont, 10, 10, mParent->collection, setId);
sprintf(starterBuffer, "%s Starter (60 cards)",MtgSets::SetsList->values[setId].c_str()); sprintf(starterBuffer, "%s Starter (60 cards)",MtgSets::SetsList->values[setId].c_str());
sprintf(boosterBuffer, "%s Booster (15 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(starterBuffer,mBack,mBackThumb, 6000);
shop->Add(boosterBuffer,mBack,mBackThumb, 1900); shop->Add(boosterBuffer,mBack,mBackThumb, 1900);
for (int i = 0; i < 4; i++){ for (int i = 0; i < 4; i++){
shop->Add(mParent->collection->randomCardId()); shop->Add(mParent->collection->randomCardId());
} }
} }
void GameStateShop::End() void GameStateShop::End()
{ {
JRenderer::GetInstance()->EnableVSync(false); JRenderer::GetInstance()->EnableVSync(false);
if (shop) if (shop)
SAFE_DELETE(shop); SAFE_DELETE(shop);
SAFE_DELETE(mBack); SAFE_DELETE(mBack);
if(bgTexture) if(bgTexture)
SAFE_DELETE(bgTexture); SAFE_DELETE(bgTexture);
if(mBg) if(mBg)
SAFE_DELETE(mBg); SAFE_DELETE(mBg);
if(menu) if(menu)
SAFE_DELETE(menu); SAFE_DELETE(menu);
} }
@@ -80,21 +80,21 @@ void GameStateShop::Destroy(){
void GameStateShop::Update(float dt) void GameStateShop::Update(float dt)
{ {
if (mStage == STAGE_SHOP_MENU){ if (mStage == STAGE_SHOP_MENU){
if (menu){ if (menu){
menu->Update(dt); menu->Update(dt);
}else{ }else{
menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200); menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200);
menu->Add(12,"Save & Back to main menu"); menu->Add(12,"Save & Back to main menu");
menu->Add(13, "Cancel"); menu->Add(13, "Cancel");
} }
}else{ }else{
if (mEngine->GetButtonClick(PSP_CTRL_START)){ if (mEngine->GetButtonClick(PSP_CTRL_START)){
mStage = STAGE_SHOP_MENU; mStage = STAGE_SHOP_MENU;
} }
if (shop) if (shop)
shop->Update(dt); shop->Update(dt);
} }
} }
@@ -102,30 +102,30 @@ void GameStateShop::Render()
{ {
//Erase //Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); 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) if (shop)
shop->Render(); shop->Render();
if (mStage == STAGE_SHOP_MENU && menu){ if (mStage == STAGE_SHOP_MENU && menu){
menu->Render(); menu->Render();
} }
} }
void GameStateShop::ButtonPressed(int controllerId, int controlId) void GameStateShop::ButtonPressed(int controllerId, int controlId)
{ {
switch (controllerId){ switch (controllerId){
case 10: case 10:
shop->pricedialog(controlId); shop->pricedialog(controlId);
break; break;
case 11: case 11:
if (controlId == 12){ if (controlId == 12){
shop->saveAll(); shop->saveAll();
mParent->SetNextState(GAME_STATE_MENU); mParent->SetNextState(GAME_STATE_MENU);
}else{ }else{
mStage = STAGE_SHOP_SHOP; mStage = STAGE_SHOP_SHOP;
} }
break; break;
} }
} }
+30 -30
View File
@@ -5,7 +5,7 @@
GuiLayer::GuiLayer(int id, GameObserver* _game):JGuiController(id, NULL){ GuiLayer::GuiLayer(int id, GameObserver* _game):JGuiController(id, NULL){
game = _game; game = _game;
modal = 0; modal = 0;
hasFocus = 0; hasFocus = 0;
} }
GuiLayer::~GuiLayer(){ GuiLayer::~GuiLayer(){
@@ -13,7 +13,7 @@ GuiLayer::~GuiLayer(){
} }
int GuiLayer::getMaxId(){ int GuiLayer::getMaxId(){
return mCount; return mCount;
} }
void GuiLayer::Update(float dt){ void GuiLayer::Update(float dt){
@@ -24,16 +24,16 @@ void GuiLayer::Update(float dt){
void GuiLayer::resetObjects(){ void GuiLayer::resetObjects(){
for (int i=0;i<mCount;i++) for (int i=0;i<mCount;i++)
if (mObjects[i]) if (mObjects[i])
delete mObjects[i]; delete mObjects[i];
mCount = 0; mCount = 0;
mCurr = 0; mCurr = 0;
} }
void GuiLayer::RenderMessageBackground(float x0, float y0, float width, int height){ 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),
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){ 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){ int GuiLayer::getIndexOf(JGuiObject * object){
for (int i=0; i<mCount; i++){ for (int i=0; i<mCount; i++){
if (mObjects[i] == object) if (mObjects[i] == object)
return i; return i;
} }
return -1; return -1;
} }
JGuiObject * GuiLayer::getByIndex(int index){ JGuiObject * GuiLayer::getByIndex(int index){
return mObjects[index]; return mObjects[index];
} }
@@ -89,27 +89,27 @@ GuiLayers::GuiLayers(){
} }
GuiLayers::~GuiLayers(){ GuiLayers::~GuiLayers(){
LOG("==Destroying GuiLayers=="); LOG("==Destroying GuiLayers==");
for (int i=0; i<nbitems; i++){ for (int i=0; i<nbitems; i++){
delete objects[i]; delete objects[i];
} }
LOG("==Destroying GuiLayers Successful=="); LOG("==Destroying GuiLayers Successful==");
} }
int GuiLayers::unstopableRenderInProgress(){ int GuiLayers::unstopableRenderInProgress(){
for (int i=0; i<nbitems; i++){ for (int i=0; i<nbitems; i++){
if (objects[i]->unstopableRenderInProgress()) if (objects[i]->unstopableRenderInProgress())
return 1; return 1;
} }
return 0; return 0;
} }
void GuiLayers::Add(GuiLayer * layer){ void GuiLayers::Add(GuiLayer * layer){
if (nbitems >=MAX_GUI_LAYERS || nbitems < 0){ if (nbitems >=MAX_GUI_LAYERS || nbitems < 0){
LOG("OUT OF BOUND IN GuiLayers Add !!!"); LOG("OUT OF BOUND IN GuiLayers Add !!!");
return; return;
} }
objects[nbitems] = layer; objects[nbitems] = layer;
nbitems++; nbitems++;
} }
@@ -121,23 +121,23 @@ void GuiLayers::Remove(){
void GuiLayers::Update(float dt, Player * currentPlayer){ void GuiLayers::Update(float dt, Player * currentPlayer){
int i; int i;
int modal = 0; int modal = 0;
int isAI = currentPlayer->isAI(); int isAI = currentPlayer->isAI();
for (i=0; i<nbitems; i++){ for (i=0; i<nbitems; i++){
objects[i]->hasFocus = 0; objects[i]->hasFocus = 0;
objects[i]->Update(dt); objects[i]->Update(dt);
if (!isAI && !modal){ if (!isAI && !modal){
objects[i]->hasFocus = 1; objects[i]->hasFocus = 1;
objects[i]->CheckUserInput(dt); objects[i]->CheckUserInput(dt);
modal = objects[i]->isModal(); modal = objects[i]->isModal();
} }
} }
if (isAI){ if (isAI){
currentPlayer->Act(dt); currentPlayer->Act(dt);
} }
} }
void GuiLayers::Render(){ void GuiLayers::Render(){
for (int i=nbitems-1; i>=0; i--){ 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(){ 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)
{ {
if (mListener != NULL) mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
{ return;
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--;
int n = mCurr; if (n<0)
n--; {
if (n<0) if ((mStyle&JGUI_STYLE_WRAPPING))
{ n = mCount-1;
if ((mStyle&JGUI_STYLE_WRAPPING)) else
n = mCount-1; n = 0;
else }
n = 0;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_UP)) if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_UP))
{ {
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); 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++;
int n = mCurr; if (n>mCount-1)
n++; {
if (n>mCount-1) if ((mStyle&JGUI_STYLE_WRAPPING))
{ n = 0;
if ((mStyle&JGUI_STYLE_WRAPPING)) else
n = 0; n = mCount-1;
else }
n = mCount-1;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN)) if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN))
{ {
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
} }
}
} }
else }
mLastKey = 0; else
mLastKey = 0;
} }
+9 -9
View File
@@ -5,19 +5,19 @@
using namespace std; using namespace std;
#if defined (WIN32) #if defined (WIN32)
#include <windows.h> #include <windows.h>
#endif #endif
void Logger::Log(char * text){ void Logger::Log(char * text){
ofstream file (LOG_FILE,ios_base::app); ofstream file (LOG_FILE,ios_base::app);
if (file){ if (file){
file << text; file << text;
file << "\n"; file << "\n";
file.close(); file.close();
} }
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString(text); OutputDebugString(text);
OutputDebugString("\n"); OutputDebugString("\n");
#endif #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){ MTGCard::MTGCard(TexturesCache * cache, int set_id){
init(); init();
mCache = cache; mCache = cache;
setId = set_id; setId = set_id;
} }
const char * MTGCard::getSetName(){ const char * MTGCard::getSetName(){
return MtgSets::SetsList->values[setId].c_str(); return MtgSets::SetsList->values[setId].c_str();
} }
MTGCard::MTGCard(MTGCard * source){ MTGCard::MTGCard(MTGCard * source){
mCache = source->mCache; mCache = source->mCache;
for (int i = 0; i< NB_BASIC_ABILITIES; i++){ for (int i = 0; i< NB_BASIC_ABILITIES; i++){
basicAbilities[i] = source->basicAbilities[i]; basicAbilities[i] = source->basicAbilities[i];
} }
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){ for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
types[i] = source->types[i]; types[i] = source->types[i];
} }
nb_types = source->nb_types; nb_types = source->nb_types;
for (int i = 0; i< MTG_NB_COLORS; i++){ for (int i = 0; i< MTG_NB_COLORS; i++){
colors[i] = source->colors[i]; colors[i] = source->colors[i];
} }
manaCost.copy(source->getManaCost()); manaCost.copy(source->getManaCost());
text = source->text; text = source->text;
name = source->name; name = source->name;
strcpy(image_name, source->image_name); strcpy(image_name, source->image_name);
rarity = source->rarity; rarity = source->rarity;
power = source->power; power = source->power;
toughness = source->toughness; toughness = source->toughness;
mtgid = source->mtgid; mtgid = source->mtgid;
setId = source->setId; setId = source->setId;
formattedTextInit = 0; formattedTextInit = 0;
magicText = source->magicText; magicText = source->magicText;
spellTargetType = source->spellTargetType; spellTargetType = source->spellTargetType;
alias = source->alias; alias = source->alias;
} }
int MTGCard::init(){ int MTGCard::init(){
nb_types = 0; nb_types = 0;
for (int i = 0; i< NB_BASIC_ABILITIES; i++){ for (int i = 0; i< NB_BASIC_ABILITIES; i++){
basicAbilities[i] = 0; basicAbilities[i] = 0;
} }
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){ for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
types[i] = 0; types[i] = 0;
} }
for (int i = 0; i< MTG_NB_COLORS; i++){ for (int i = 0; i< MTG_NB_COLORS; i++){
colors[i] = 0; colors[i] = 0;
} }
setId = 0; setId = 0;
formattedTextInit = 0; formattedTextInit = 0;
magicText = ""; magicText = "";
spellTargetType = ""; spellTargetType = "";
alias = 0; alias = 0;
return 1; return 1;
} }
JQuad * MTGCard::getQuad(int type){ JQuad * MTGCard::getQuad(int type){
@@ -103,42 +103,42 @@ int MTGCard::isACreature(){
} }
void MTGCard::setColor(int _color, int removeAllOthers){ void MTGCard::setColor(int _color, int removeAllOthers){
if (removeAllOthers){ if (removeAllOthers){
for (int i=0; i<MTG_NB_COLORS; i++){ for (int i=0; i<MTG_NB_COLORS; i++){
colors[i] = 0; colors[i] = 0;
} }
} }
colors[_color] = 1; colors[_color] = 1;
} }
int MTGCard::getColor(){ int MTGCard::getColor(){
int i = 0; int i = 0;
for (int i=0; i<MTG_NB_COLORS; i++){ for (int i=0; i<MTG_NB_COLORS; i++){
if (colors[i]){ if (colors[i]){
return i; return i;
} }
} }
return 0; return 0;
} }
int MTGCard::hasColor(int color){ int MTGCard::hasColor(int color){
return (colors[color]); return (colors[color]);
} }
void MTGCard::setManaCost(string s){ void MTGCard::setManaCost(string s){
ManaCost::parseManaCost(s, &manaCost); ManaCost::parseManaCost(s, &manaCost);
for (int i = MTG_COLOR_GREEN; i <=MTG_COLOR_WHITE; i++){ for (int i = MTG_COLOR_GREEN; i <=MTG_COLOR_WHITE; i++){
if (manaCost.hasColor(i)){ if (manaCost.hasColor(i)){
setColor(i); setColor(i);
} }
} }
} }
const char * MTGCard::colorToString(){ const char * MTGCard::colorToString(){
int color = getColor(); int color = getColor();
if (color>=0 && color <=5){ if (color>=0 && color <=5){
return Colors_To_Text[color]; return Colors_To_Text[color];
} }
@@ -159,7 +159,7 @@ int MTGCard::getId(){
} }
char MTGCard::getRarity(){ char MTGCard::getRarity(){
return rarity; return rarity;
} }
void MTGCard::setRarity(char _rarity){ void MTGCard::setRarity(char _rarity){
@@ -167,27 +167,27 @@ void MTGCard::setRarity(char _rarity){
} }
void MTGCard::setType(const char * _type_text){ void MTGCard::setType(const char * _type_text){
setSubtype(_type_text); setSubtype(_type_text);
} }
void MTGCard::addType(char * _type_text){ void MTGCard::addType(char * _type_text){
setSubtype(_type_text); setSubtype(_type_text);
} }
void MTGCard::setSubtype( string value){ void MTGCard::setSubtype( string value){
string s = value; string s = value;
while (s.size()){ while (s.size()){
unsigned int found = s.find(" "); unsigned int found = s.find(" ");
if (found != string::npos){ if (found != string::npos){
int id = Subtypes::subtypesList->Add(s.substr(0,found)); int id = Subtypes::subtypesList->Add(s.substr(0,found));
addType(id); addType(id);
s = s.substr(found+1); s = s.substr(found+1);
}else{ }else{
int id = Subtypes::subtypesList->Add(s); int id = Subtypes::subtypesList->Add(s);
addType(id); addType(id);
s = ""; s = "";
} }
} }
} }
void MTGCard::addType(int id){ 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 //If removeAll is true, removes all occurences of this type, otherwise only removes the first occurence
int MTGCard::removeType(string value, int removeAll){ int MTGCard::removeType(string value, int removeAll){
int id = Subtypes::subtypesList->Add(value); int id = Subtypes::subtypesList->Add(value);
return removeType(id, removeAll); return removeType(id, removeAll);
} }
int MTGCard::removeType(int id, int removeAll){ int MTGCard::removeType(int id, int removeAll){
int result = 0; int result = 0;
for (int i = nb_types -1 ; i >=0; i--){ for (int i = nb_types -1 ; i >=0; i--){
if (types[i] == id){ if (types[i] == id){
types[i] = types[nb_types -1]; types[i] = types[nb_types -1];
nb_types--; nb_types--;
result++; result++;
if (!removeAll) return result; if (!removeAll) return result;
} }
} }
return result; return result;
} }
@@ -224,7 +224,7 @@ char * MTGCard::getImageName(){
void MTGCard::setText( string value){ void MTGCard::setText( string value){
text = value; text = value;
} }
const char * MTGCard::getText(){ const char * MTGCard::getText(){
@@ -232,13 +232,13 @@ const char * MTGCard::getText(){
} }
void MTGCard::addMagicText(string value){ void MTGCard::addMagicText(string value){
std::transform( value.begin(), value.end(), value.begin(),::tolower ); std::transform( value.begin(), value.end(), value.begin(),::tolower );
if (magicText.size()) magicText.append("\n"); if (magicText.size()) magicText.append("\n");
magicText.append(value); magicText.append(value);
} }
void MTGCard::setName( string value){ void MTGCard::setName( string value){
name = value; name = value;
} }
const char * MTGCard::getName(){ const char * MTGCard::getName(){
@@ -266,28 +266,28 @@ int MTGCard::hasType(int _type){
} }
int MTGCard::hasSubtype(int _subtype){ int MTGCard::hasSubtype(int _subtype){
return(hasType(_subtype)); return(hasType(_subtype));
} }
int MTGCard::hasType(const char * _type){ int MTGCard::hasType(const char * _type){
int id = Subtypes::subtypesList->Add(_type); int id = Subtypes::subtypesList->Add(_type);
return(hasType(id)); return(hasType(id));
} }
int MTGCard::hasSubtype(const char * _subtype){ int MTGCard::hasSubtype(const char * _subtype){
int id = Subtypes::subtypesList->Add(_subtype); int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id)); return(hasType(id));
} }
int MTGCard::hasSubtype(string _subtype){ int MTGCard::hasSubtype(string _subtype){
int id = Subtypes::subtypesList->Add(_subtype); int id = Subtypes::subtypesList->Add(_subtype);
return(hasType(id)); return(hasType(id));
} }
int MTGCard::has(int basicAbility){ int MTGCard::has(int basicAbility){
return basicAbilities[basicAbility]; return basicAbilities[basicAbility];
} }
//--------------------------------------------- //---------------------------------------------
@@ -298,7 +298,7 @@ void MTGCard::setPower(int _power){
} }
int MTGCard::getPower(){ int MTGCard::getPower(){
return power; return power;
} }
void MTGCard::setToughness(int _toughness){ void MTGCard::setToughness(int _toughness){
@@ -306,5 +306,5 @@ void MTGCard::setToughness(int _toughness){
} }
int MTGCard::getToughness(){ int MTGCard::getToughness(){
return toughness; return toughness;
} }
+248 -248
View File
@@ -1,8 +1,8 @@
/*--------------------------------------------- /*---------------------------------------------
Card Instance Card Instance
Instance of a given MTGCard in the game 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 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/debug.h"
#include "../include/MTGCardInstance.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" #include "../include/Counters.h"
MTGCardInstance::MTGCardInstance(): MTGCard(), Damageable(0){ MTGCardInstance::MTGCardInstance(): MTGCard(), Damageable(0){
LOG("==Creating MTGCardInstance=="); LOG("==Creating MTGCardInstance==");
initMTGCI(); initMTGCI();
LOG("==Creating MTGCardInstance Successful=="); LOG("==Creating MTGCardInstance Successful==");
} }
MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to): MTGCard(card), Damageable(card->getToughness()){ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to): MTGCard(card), Damageable(card->getToughness()){
LOG("==Creating MTGCardInstance=="); LOG("==Creating MTGCardInstance==");
initMTGCI(); initMTGCI();
model = card; model = card;
lifeOrig = life; lifeOrig = life;
belongs_to=_belongs_to; belongs_to=_belongs_to;
initAttackersDefensers(); initAttackersDefensers();
life=toughness; life=toughness;
LOG("==Creating MTGCardInstance Successful=="); LOG("==Creating MTGCardInstance Successful==");
} }
MTGCardInstance::~MTGCardInstance(){ MTGCardInstance::~MTGCardInstance(){
LOG("==Deleting MTGCardInstance=="); LOG("==Deleting MTGCardInstance==");
SAFE_DELETE(blockers); SAFE_DELETE(blockers);
SAFE_DELETE(counters); SAFE_DELETE(counters);
LOG("==Deleting MTGCardInstance Succesfull=="); LOG("==Deleting MTGCardInstance Succesfull==");
} }
void MTGCardInstance::initMTGCI(){ void MTGCardInstance::initMTGCI(){
model=NULL; model=NULL;
lifeOrig = 0; lifeOrig = 0;
doDamageTest = 0; doDamageTest = 0;
belongs_to=NULL; belongs_to=NULL;
tapped = 0; tapped = 0;
blockers = NEW Blockers(); blockers = NEW Blockers();
untapping = 0; untapping = 0;
summoningSickness = 0; summoningSickness = 0;
target = NULL; target = NULL;
nbprotections = 0; nbprotections = 0;
type_as_damageable = DAMAGEABLE_MTGCARDINSTANCE; type_as_damageable = DAMAGEABLE_MTGCARDINSTANCE;
banding = NULL; banding = NULL;
owner = NULL; owner = NULL;
changedZoneRecently = 0; changedZoneRecently = 0;
counters = NEW Counters(this); counters = NEW Counters(this);
} }
void MTGCardInstance::addType(int type){ void MTGCardInstance::addType(int type){
types[nb_types] = type; types[nb_types] = type;
nb_types++; nb_types++;
} }
Blockers * MTGCardInstance::getBlockers(){ Blockers * MTGCardInstance::getBlockers(){
return blockers; return blockers;
} }
int MTGCardInstance::isInPlay(){ int MTGCardInstance::isInPlay(){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
for (int i = 0 ; i < 2 ; i++){ for (int i = 0 ; i < 2 ; i++){
MTGGameZone * zone = game->players[i]->game->inPlay; MTGGameZone * zone = game->players[i]->game->inPlay;
if (zone->hasCard(this)) return 1; if (zone->hasCard(this)) return 1;
} }
return 0; return 0;
} }
int MTGCardInstance::afterDamage(){ int MTGCardInstance::afterDamage(){
if (!doDamageTest) return 0; if (!doDamageTest) return 0;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096], *p = buf; char buf[4096], *p = buf;
sprintf(buf,"After Damage Test, life is %i for %s \n",life,model->getName()); sprintf(buf,"After Damage Test, life is %i for %s \n",life,model->getName());
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
doDamageTest = 0; doDamageTest = 0;
if (life <=0 && isInPlay()){ if (life <=0 && isInPlay()){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
game->mLayers->stackLayer()->addPutInGraveyard(this); game->mLayers->stackLayer()->addPutInGraveyard(this);
return 1; return 1;
} }
return 0; return 0;
} }
MTGGameZone * MTGCardInstance::getCurrentZone(){ MTGGameZone * MTGCardInstance::getCurrentZone(){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
MTGPlayerCards * g = game->players[i]->game; MTGPlayerCards * g = game->players[i]->game;
MTGGameZone * zones[] = {g->inPlay,g->graveyard,g->hand, g->library}; MTGGameZone * zones[] = {g->inPlay,g->graveyard,g->hand, g->library};
for (int k = 0; k < 4; k++){ for (int k = 0; k < 4; k++){
MTGGameZone * zone = zones[k]; MTGGameZone * zone = zones[k];
if (zone->hasCard(this)) return zone; if (zone->hasCard(this)) return zone;
} }
} }
return NULL; return NULL;
} }
JQuad * MTGCardInstance::getIcon(){ JQuad * MTGCardInstance::getIcon(){
return getThumb(); return getThumb();
} }
int MTGCardInstance::has(int basicAbility){ int MTGCardInstance::has(int basicAbility){
return basicAbilities[basicAbility]; return basicAbilities[basicAbility];
} }
@@ -117,54 +117,54 @@ void MTGCardInstance::tap(){
} }
void MTGCardInstance::setUntapping(){ void MTGCardInstance::setUntapping(){
untapping = 1; untapping = 1;
} }
int MTGCardInstance::isUntapping(){ int MTGCardInstance::isUntapping(){
return untapping; return untapping;
} }
//Untaps the card //Untaps the card
void MTGCardInstance::untap(){ void MTGCardInstance::untap(){
if (untapping){ if (untapping){
tapped = 0; tapped = 0;
untapping = 0; untapping = 0;
} }
} }
//Tells if the card is tapped or not //Tells if the card is tapped or not
int MTGCardInstance::isTapped(){ int MTGCardInstance::isTapped(){
return tapped; return tapped;
} }
void MTGCardInstance::resetAllDamage(){ void MTGCardInstance::resetAllDamage(){
//for (int i=0;i<nb_damages;i++){ //for (int i=0;i<nb_damages;i++){
// delete damages[i]; // delete damages[i];
//} //}
nb_damages = 0; nb_damages = 0;
} }
void MTGCardInstance::regenerate(){ void MTGCardInstance::regenerate(){
tapped = 1; tapped = 1;
life = toughness; life = toughness;
initAttackersDefensers(); initAttackersDefensers();
} }
int MTGCardInstance::initAttackersDefensers(){ int MTGCardInstance::initAttackersDefensers(){
attacker = 0; attacker = 0;
defenser = NULL; defenser = NULL;
banding = NULL; banding = NULL;
return 1; return 1;
} }
//Function to call to remove all damages, etc to a card (generally at the end of the turn) //Function to call to remove all damages, etc to a card (generally at the end of the turn)
int MTGCardInstance::cleanup(){ int MTGCardInstance::cleanup(){
initAttackersDefensers(); initAttackersDefensers();
life=toughness; life=toughness;
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
if (!game || game->currentPlayer == controller()) summoningSickness = 0; if (!game || game->currentPlayer == controller()) summoningSickness = 0;
return 1; return 1;
} }
/* Summoning Sickness /* Summoning Sickness
@@ -175,233 +175,233 @@ int MTGCardInstance::cleanup(){
* sicknessh rule. Ignore this rule for creatures with haste (see rule 502.5). * sicknessh rule. Ignore this rule for creatures with haste (see rule 502.5).
*/ */
int MTGCardInstance::hasSummoningSickness(){ int MTGCardInstance::hasSummoningSickness(){
if (!summoningSickness) return 0; if (!summoningSickness) return 0;
if (basicAbilities[HASTE]) return 0; if (basicAbilities[HASTE]) return 0;
if (!isACreature()) return 0; if (!isACreature()) return 0;
return 1; return 1;
} }
int MTGCardInstance::changeController(Player * newController){ int MTGCardInstance::changeController(Player * newController){
Player * originalOwner = controller(); Player * originalOwner = controller();
if (originalOwner == newController) return 0; if (originalOwner == newController) return 0;
originalOwner->game->inPlay->removeCard(this); originalOwner->game->inPlay->removeCard(this);
newController->game->inPlay->addCard(this); newController->game->inPlay->addCard(this);
summoningSickness = 1; summoningSickness = 1;
return 1; return 1;
} }
//Reset the card parameters //Reset the card parameters
int MTGCardInstance::reset(){ int MTGCardInstance::reset(){
cleanup(); cleanup();
tapped=0; tapped=0;
SAFE_DELETE(counters); SAFE_DELETE(counters);
counters = NEW Counters(this); counters = NEW Counters(this);
return 1; return 1;
} }
Player * MTGCardInstance::controller(){ Player * MTGCardInstance::controller(){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
if (!game) return NULL; if (!game) return NULL;
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
if (game->players[i]->game->inPlay->hasCard(this)) return game->players[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->stack->hasCard(this)) return game->players[i];
if (game->players[i]->game->graveyard->hasCard(this)) return game->players[i]; if (game->players[i]->game->graveyard->hasCard(this)) return game->players[i];
} }
return NULL; return NULL;
} }
int MTGCardInstance::canAttack(){ int MTGCardInstance::canAttack(){
if (!hasSummoningSickness() && !tapped && isACreature() && basicAbilities[DEFENSER] !=1) if (!hasSummoningSickness() && !tapped && isACreature() && basicAbilities[DEFENSER] !=1)
return 1; return 1;
return 0; return 0;
} }
int MTGCardInstance::addToToughness(int value){ int MTGCardInstance::addToToughness(int value){
toughness+=value; toughness+=value;
life+=value; life+=value;
doDamageTest = 1; doDamageTest = 1;
return 1; return 1;
} }
int MTGCardInstance::setToughness(int value){ int MTGCardInstance::setToughness(int value){
toughness=value; toughness=value;
life=value; life=value;
doDamageTest = 1; doDamageTest = 1;
return 1; return 1;
} }
int MTGCardInstance::canBlock(){ int MTGCardInstance::canBlock(){
if (!tapped && isACreature())return 1; if (!tapped && isACreature())return 1;
return 0; return 0;
} }
int MTGCardInstance::canBlock(MTGCardInstance * opponent){ int MTGCardInstance::canBlock(MTGCardInstance * opponent){
if (!canBlock()) return 0; if (!canBlock()) return 0;
if (!opponent) return 1; if (!opponent) return 1;
if (!opponent->isAttacker()) return 0; 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. // 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->protectedAgainst(this)) return 0;
if (opponent->basicAbilities[UNBLOCKABLE]) 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[FEAR] && !(hasColor(MTG_COLOR_ARTIFACT) || hasColor(MTG_COLOR_BLACK))) return 0;
if (opponent->basicAbilities[FLYING] && !( basicAbilities[FLYING] || basicAbilities[REACH])) 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 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->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 does not have shadow and a creature has shadow it cannot be blocked
if (!opponent->basicAbilities[SHADOW] && basicAbilities[SHADOW]) return 0; if (!opponent->basicAbilities[SHADOW] && basicAbilities[SHADOW]) return 0;
if (opponent->basicAbilities[SWAMPWALK] && controller()->game->inPlay->hasType("swamp")) 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[FORESTWALK] && controller()->game->inPlay->hasType("forest")) return 0;
if (opponent->basicAbilities[ISLANDWALK] && controller()->game->inPlay->hasType("island")) 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[MOUNTAINWALK] && controller()->game->inPlay->hasType("mountain")) return 0;
if (opponent->basicAbilities[PLAINSWALK] && controller()->game->inPlay->hasType("plains")) return 0; if (opponent->basicAbilities[PLAINSWALK] && controller()->game->inPlay->hasType("plains")) return 0;
return 1; return 1;
} }
MTGCardInstance * MTGCardInstance::getNextPartner(){ MTGCardInstance * MTGCardInstance::getNextPartner(){
MTGInPlay * inplay = controller()->game->inPlay; MTGInPlay * inplay = controller()->game->inPlay;
MTGCardInstance * bandingPartner = inplay->getNextAttacker(banding); MTGCardInstance * bandingPartner = inplay->getNextAttacker(banding);
while (bandingPartner){ while (bandingPartner){
if (basicAbilities[BANDING] || bandingPartner->basicAbilities[BANDING]) return bandingPartner; if (basicAbilities[BANDING] || bandingPartner->basicAbilities[BANDING]) return bandingPartner;
bandingPartner = inplay->getNextAttacker(bandingPartner); bandingPartner = inplay->getNextAttacker(bandingPartner);
} }
return NULL; return NULL;
} }
void MTGCardInstance::unband(){ void MTGCardInstance::unband(){
if (!banding) return; if (!banding) return;
MTGCardInstance * _banding = banding; MTGCardInstance * _banding = banding;
banding = NULL; banding = NULL;
MTGCardInstance * newbanding = NULL; MTGCardInstance * newbanding = NULL;
MTGInPlay * inplay = controller()->game->inPlay; MTGInPlay * inplay = controller()->game->inPlay;
int nbpartners = inplay->nbPartners(this); int nbpartners = inplay->nbPartners(this);
MTGCardInstance * card = inplay->getNextAttacker(NULL); MTGCardInstance * card = inplay->getNextAttacker(NULL);
while(card){ while(card){
if (card != this){ if (card != this){
if (card->banding == _banding){ if (card->banding == _banding){
if (nbpartners == 1){ if (nbpartners == 1){
card->banding = NULL; card->banding = NULL;
return; return;
}else{ }else{
if (!newbanding) newbanding = card; if (!newbanding) newbanding = card;
card->banding = newbanding; card->banding = newbanding;
}
}
}
card = inplay->getNextAttacker(card);
} }
return ; }
}
card = inplay->getNextAttacker(card);
}
return ;
} }
int MTGCardInstance::toggleAttacker(){ int MTGCardInstance::toggleAttacker(){
//TODO more controls ? //TODO more controls ?
if (canAttack()){ if (canAttack()){
if (!attacker){ if (!attacker){
attacker = 1; attacker = 1;
tapped = 1; tapped = 1;
return 1; return 1;
}else{ }else{
MTGCardInstance * bandingPartner = getNextPartner(); MTGCardInstance * bandingPartner = getNextPartner();
if (bandingPartner){ if (bandingPartner){
if (banding) unband(); if (banding) unband();
if (!bandingPartner->banding) bandingPartner->banding = bandingPartner; if (!bandingPartner->banding) bandingPartner->banding = bandingPartner;
banding = bandingPartner->banding; banding = bandingPartner->banding;
return 1; return 1;
}else{ }else{
attacker = 0; attacker = 0;
tapped = 0; tapped = 0;
return 1; return 1;
} }
} }
} }
return 0; return 0;
} }
int MTGCardInstance::isAttacker(){ int MTGCardInstance::isAttacker(){
return attacker; return attacker;
} }
MTGCardInstance * MTGCardInstance::isDefenser(){ MTGCardInstance * MTGCardInstance::isDefenser(){
return defenser; return defenser;
} }
int MTGCardInstance::nbOpponents(){ int MTGCardInstance::nbOpponents(){
int result= 0; int result= 0;
MTGCardInstance* opponent = getNextOpponent(); MTGCardInstance* opponent = getNextOpponent();
while (opponent){ while (opponent){
result++; result++;
opponent = getNextOpponent(opponent); opponent = getNextOpponent(opponent);
} }
return result; return result;
} }
//Returns opponents to this card for this turn. This * should * take into account banding //Returns opponents to this card for this turn. This * should * take into account banding
MTGCardInstance * MTGCardInstance::getNextOpponent(MTGCardInstance * previous){ MTGCardInstance * MTGCardInstance::getNextOpponent(MTGCardInstance * previous){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
int foundprevious = 0; int foundprevious = 0;
if (!previous) foundprevious = 1; if (!previous) foundprevious = 1;
if (attacker && game->currentPlayer->game->inPlay->hasCard(this)){ if (attacker && game->currentPlayer->game->inPlay->hasCard(this)){
MTGInPlay * inPlay = game->opponent()->game->inPlay; MTGInPlay * inPlay = game->opponent()->game->inPlay;
for (int i = 0; i < inPlay->nb_cards; i ++){ for (int i = 0; i < inPlay->nb_cards; i ++){
MTGCardInstance * current = inPlay->cards[i]; MTGCardInstance * current = inPlay->cards[i];
if (current == previous){ if (current == previous){
foundprevious = 1; foundprevious = 1;
}else if (foundprevious){ }else if (foundprevious){
MTGCardInstance * defensersOpponent = current->isDefenser(); MTGCardInstance * defensersOpponent = current->isDefenser();
if (defensersOpponent && (defensersOpponent == this || (banding && defensersOpponent->banding == banding))){ if (defensersOpponent && (defensersOpponent == this || (banding && defensersOpponent->banding == banding))){
return current; return current;
}
}
}
}else if (defenser && game->opponent()->game->inPlay->hasCard(this)){
MTGInPlay * inPlay = game->currentPlayer->game->inPlay;
for (int i = 0; i < inPlay->nb_cards; i ++){
MTGCardInstance * current = inPlay->cards[i];
if (current == previous){
foundprevious = 1;
}else if (foundprevious){
if (defenser == current || (current->banding && defenser->banding == current->banding)){
return current;
}
}
}
} }
return NULL; }
}
}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){ int MTGCardInstance::toggleDefenser(MTGCardInstance * opponent){
if (canBlock()){ if (canBlock()){
if (canBlock(opponent)){ if (canBlock(opponent)){
defenser = opponent; defenser = opponent;
return 1; return 1;
} }
} }
return 0; return 0;
} }
int MTGCardInstance::addProtection(CardDescriptor * cd){ int MTGCardInstance::addProtection(CardDescriptor * cd){
protections[nbprotections] = cd; protections[nbprotections] = cd;
nbprotections++; nbprotections++;
return nbprotections; return nbprotections;
} }
int MTGCardInstance::removeProtection(CardDescriptor * cd, int erase){ int MTGCardInstance::removeProtection(CardDescriptor * cd, int erase){
for (int i = 0; i < nbprotections ; i++){ for (int i = 0; i < nbprotections ; i++){
if (protections[i] == cd){ if (protections[i] == cd){
if (erase) delete (protections[i]); if (erase) delete (protections[i]);
protections[i] = protections[nbprotections -1]; protections[i] = protections[nbprotections -1];
protections[nbprotections -1] = NULL; protections[nbprotections -1] = NULL;
nbprotections--; nbprotections--;
return 1; return 1;
} }
} }
return 0; return 0;
} }
int MTGCardInstance::protectedAgainst(MTGCardInstance * card){ int MTGCardInstance::protectedAgainst(MTGCardInstance * card){
for (int i = 0; i < nbprotections ; i++){ for (int i = 0; i < nbprotections ; i++){
if (protections[i]->match(card)) return 1; if (protections[i]->match(card)) return 1;
} }
return 0; return 0;
} }
+156 -156
View File
@@ -20,45 +20,45 @@ MtgSets * MtgSets::SetsList = NEW MtgSets();
MtgSets::MtgSets(){ MtgSets::MtgSets(){
nb_items = 0; nb_items = 0;
} }
int MtgSets::Add(const char * name){ int MtgSets::Add(const char * name){
string value = name; string value = name;
values[nb_items] = value; values[nb_items] = value;
nb_items++; nb_items++;
return nb_items - 1; return nb_items - 1;
} }
int MTGAllCards::processConfLine(char *buffer, MTGCard *card){ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
string s = buffer; string s = buffer;
unsigned int i = s.find_first_of("="); unsigned int i = s.find_first_of("=");
if (i == string::npos) return 0; if (i == string::npos) return 0;
string key = s.substr(0,i); string key = s.substr(0,i);
string value = s.substr(i+1); string value = s.substr(i+1);
if(key.compare( "auto")==0){ if(key.compare( "auto")==0){
card->addMagicText(value); card->addMagicText(value);
} }
else if(key.compare( "alias")==0){ else if(key.compare( "alias")==0){
card->alias=atoi(value.c_str()); card->alias=atoi(value.c_str());
} }
else if(key.compare( "target")==0){ 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; card->spellTargetType=value;
} }
else if(key.compare( "text")==0){ else if(key.compare( "text")==0){
card->setText(value); card->setText(value);
}else if (key.compare("abilities")==0){ }else if (key.compare("abilities")==0){
//Specific Abilities //Specific Abilities
std::transform( value.begin(), value.end(), value.begin(),::tolower ); std::transform( value.begin(), value.end(), value.begin(),::tolower );
for (int j = 0; j < NB_BASIC_ABILITIES; j++){ for (int j = 0; j < NB_BASIC_ABILITIES; j++){
unsigned int found = value.find(MTGBasicAbilities[j]); unsigned int found = value.find(MTGBasicAbilities[j]);
if (found != string::npos){ if (found != string::npos){
card->basicAbilities[j] = 1; card->basicAbilities[j] = 1;
} }
} }
}else if(key.compare("id")==0){ }else if(key.compare("id")==0){
card->setMTGId(atoi(value.c_str())); card->setMTGId(atoi(value.c_str()));
}else if(key.compare("name")==0){ }else if(key.compare("name")==0){
@@ -66,7 +66,7 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
}else if(key.compare("rarity")==0){ }else if(key.compare("rarity")==0){
card->setRarity (value.c_str()[0]); card->setRarity (value.c_str()[0]);
}else if(key.compare("mana")==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); card->setManaCost(value);
}else if(key.compare("type")==0){ }else if(key.compare("type")==0){
switch(value.c_str()[0]){ switch(value.c_str()[0]){
@@ -75,9 +75,9 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
break; break;
case 'A': case 'A':
card->setType( "Artifact"); card->setType( "Artifact");
card->setColor(MTG_COLOR_ARTIFACT); card->setColor(MTG_COLOR_ARTIFACT);
if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C') if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C')
card->setSubtype("Creature"); card->setSubtype("Creature");
break; break;
case 'E': case 'E':
card->setType( "Enchantment"); card->setType( "Enchantment");
@@ -86,11 +86,11 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
card->setType( "Sorcery"); card->setType( "Sorcery");
break; break;
case 'B'://Basic Land case 'B'://Basic Land
card->setColor(MTG_COLOR_LAND); card->setColor(MTG_COLOR_LAND);
card->setType("Land"); card->setType("Land");
break; break;
case 'L': case 'L':
card->setColor(MTG_COLOR_LAND); card->setColor(MTG_COLOR_LAND);
card->setType( "Land"); card->setType( "Land");
break; break;
case 'I': case 'I':
@@ -108,7 +108,7 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
}else if(key.compare("toughness")==0){ }else if(key.compare("toughness")==0){
card->setToughness(atoi(value.c_str())); card->setToughness(atoi(value.c_str()));
}else{ }else{
} }
return i; return i;
@@ -116,45 +116,45 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
} }
void MTGAllCards::initCounters(){ void MTGAllCards::initCounters(){
for (int i=0; i< MTG_NB_COLORS; i++){ for (int i=0; i< MTG_NB_COLORS; i++){
colorsCount[i] = NULL; colorsCount[i] = NULL;
} }
} }
void MTGAllCards::init(){ void MTGAllCards::init(){
mCache = NULL; mCache = NULL;
total_cards = 0; total_cards = 0;
initCounters(); initCounters();
srand(time(0)); // initialize random srand(time(0)); // initialize random
} }
int MTGAllCards::load(const char * config_file, const char * set_name,int autoload){ 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); int file_size = filesize(config_file);
conf_buffer = (char *) malloc(file_size); conf_buffer = (char *) malloc(file_size);
read_cursor = 0; read_cursor = 0;
// conf_fd = sceIoOpen(config_file, PSP_O_RDONLY, 0777); // conf_fd = sceIoOpen(config_file, PSP_O_RDONLY, 0777);
read_file(config_file, conf_buffer, file_size ); read_file(config_file, conf_buffer, file_size );
int set_id = MtgSets::SetsList->Add(set_name); int set_id = MtgSets::SetsList->Add(set_name);
if (autoload){ if (autoload){
while(readConfLine(set_id)){}; while(readConfLine(set_id)){};
} }
return total_cards; return total_cards;
} }
MTGAllCards::MTGAllCards(){ MTGAllCards::MTGAllCards(){
init(); init();
} }
MTGAllCards::~MTGAllCards(){ MTGAllCards::~MTGAllCards(){
} }
void MTGAllCards::destroyAllCards(){ void MTGAllCards::destroyAllCards(){
for (int i= 0; i < total_cards; i++){ for (int i= 0; i < total_cards; i++){
delete collection[i]; delete collection[i];
}; };
} }
@@ -163,64 +163,64 @@ MTGAllCards::MTGAllCards(const char * config_file, const char * set_name){
} }
MTGAllCards::MTGAllCards(TexturesCache * cache){ MTGAllCards::MTGAllCards(TexturesCache * cache){
init(); init();
mCache = cache; mCache = cache;
} }
MTGAllCards::MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache){ MTGAllCards::MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache){
init(); init();
mCache = cache; mCache = cache;
load(config_file,set_name, 0); load(config_file,set_name, 0);
} }
MTGCard * MTGAllCards::_(int i){ MTGCard * MTGAllCards::_(int i){
if (i < total_cards) return collection[i]; if (i < total_cards) return collection[i];
return NULL; return NULL;
} }
int MTGAllCards::randomCardId(){ int MTGAllCards::randomCardId(){
int id = (rand() % total_cards); int id = (rand() % total_cards);
return collection[id]->getMTGId(); return collection[id]->getMTGId();
} }
int MTGAllCards::countBySet(int setId){ int MTGAllCards::countBySet(int setId){
int result = 0; int result = 0;
for (int i=0; i< total_cards; i++){ for (int i=0; i< total_cards; i++){
if(collection[i]->setId == setId){ if(collection[i]->setId == setId){
result++; result++;
} }
} }
return result; return result;
} }
//TODO more efficient way ? //TODO more efficient way ?
int MTGAllCards::countByType(const char * _type){ int MTGAllCards::countByType(const char * _type){
int result = 0; int result = 0;
for (int i=0; i< total_cards; i++){ for (int i=0; i< total_cards; i++){
if(collection[i]->hasType(_type)){ if(collection[i]->hasType(_type)){
result++; result++;
} }
} }
return result; return result;
} }
int MTGAllCards::countByColor(int color){ int MTGAllCards::countByColor(int color){
if (colorsCount[color] == 0){ if (colorsCount[color] == 0){
for (int i=0; i< MTG_NB_COLORS; i++){ for (int i=0; i< MTG_NB_COLORS; i++){
colorsCount[i] = 0; colorsCount[i] = 0;
} }
for (int i=0; i< total_cards; i++){ for (int i=0; i< total_cards; i++){
int j = collection[i]->getColor(); int j = collection[i]->getColor();
colorsCount[j]++; colorsCount[j]++;
} }
} }
return colorsCount[color]; return colorsCount[color];
} }
int MTGAllCards::totalCards(){ int MTGAllCards::totalCards(){
@@ -274,20 +274,20 @@ MTGCard * MTGAllCards::getCardById(int id){
MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){ MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){
mCache = cache; mCache = cache;
total_cards = 0; total_cards = 0;
allcards = _allcards; allcards = _allcards;
filename = config_file; filename = config_file;
std::ifstream file(config_file); std::ifstream file(config_file);
std::string s; std::string s;
if(file){ if(file){
while(std::getline(file,s)){ while(std::getline(file,s)){
int cardnb = atoi(s.c_str()); int cardnb = atoi(s.c_str());
if (cardnb) add(cardnb); if (cardnb) add(cardnb);
} }
file.close(); file.close();
}else{ }else{
//TODO Error management //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 MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _subtype){
int collectionTotal = allcards->totalCards(); int collectionTotal = allcards->totalCards();
if (!collectionTotal) return 0; if (!collectionTotal) return 0;
if (setId == -1 && rarity == -1 && !_subtype){ if (setId == -1 && rarity == -1 && !_subtype){
for (int i = 0; i < howmany; i++){ for (int i = 0; i < howmany; i++){
int id = (rand() % collectionTotal); int id = (rand() % collectionTotal);
add(allcards->_(id)); add(allcards->_(id));
} }
return 1; return 1;
} }
char subtype[4096]; char subtype[4096];
if (_subtype) if (_subtype)
sprintf(subtype, _subtype); sprintf(subtype, _subtype);
int subcollection[TOTAL_NUMBER_OF_CARDS]; int subcollection[TOTAL_NUMBER_OF_CARDS];
int subtotal = 0; int subtotal = 0;
for (int i = 0; i < collectionTotal; i++){ for (int i = 0; i < collectionTotal; i++){
MTGCard * card = allcards->_(i); MTGCard * card = allcards->_(i);
if ((setId == -1 || card->setId == setId) && if ((setId == -1 || card->setId == setId) &&
(rarity == -1 || card->getRarity()==rarity) && (rarity == -1 || card->getRarity()==rarity) &&
(!_subtype || card->hasSubtype(subtype)) (!_subtype || card->hasSubtype(subtype))
){ ){
subcollection[subtotal] = i; subcollection[subtotal] = i;
subtotal++; subtotal++;
} }
} }
if (subtotal == 0) return 0; if (subtotal == 0) return 0;
for (int i = 0; i < howmany; i++){ for (int i = 0; i < howmany; i++){
int id = (rand() % subtotal); int id = (rand() % subtotal);
add(allcards->_(subcollection[id])); add(allcards->_(subcollection[id]));
} }
return 1; return 1;
} }
int MTGDeck::add(int cardid){ int MTGDeck::add(int cardid){
MTGCard * card = allcards->getCardById(cardid); MTGCard * card = allcards->getCardById(cardid);
add(card); add(card);
return total_cards; return total_cards;
} }
int MTGDeck::add(MTGCard * card){ int MTGDeck::add(MTGCard * card){
if (!card) return 0; if (!card) return 0;
collection[total_cards] = card; collection[total_cards] = card;
++total_cards; ++total_cards;
initCounters(); initCounters();
return total_cards; return total_cards;
} }
int MTGDeck::removeAll(){ int MTGDeck::removeAll(){
total_cards = 0; total_cards = 0;
initCounters(); initCounters();
return 1; return 1;
} }
int MTGDeck::remove(int cardid){ int MTGDeck::remove(int cardid){
MTGCard * card = getCardById(cardid); MTGCard * card = getCardById(cardid);
return remove(card); return remove(card);
} }
int MTGDeck::remove(MTGCard * card){ int MTGDeck::remove(MTGCard * card){
for (int i = 0; i<total_cards; i++){ for (int i = 0; i<total_cards; i++){
if (collection[i] == card){ if (collection[i] == card){
collection[i] = collection[total_cards - 1]; collection[i] = collection[total_cards - 1];
total_cards--; total_cards--;
initCounters(); initCounters();
return 1; return 1;
} }
} }
return 0; return 0;
} }
int MTGDeck::save(){ int MTGDeck::save(){
std::ofstream file(filename.c_str()); std::ofstream file(filename.c_str());
char writer[10]; char writer[10];
if (file){ if (file){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("saving"); OutputDebugString("saving");
#endif #endif
for (int i = 0; i<total_cards; i++){ for (int i = 0; i<total_cards; i++){
sprintf(writer,"%i\n", collection[i]->getMTGId()); sprintf(writer,"%i\n", collection[i]->getMTGId());
file<<writer; file<<writer;
} }
file.close(); file.close();
} }
return 1; return 1;
} }
+21 -21
View File
@@ -5,7 +5,7 @@
MTGGamePhase::MTGGamePhase(int id):ActionElement(id){ MTGGamePhase::MTGGamePhase(int id):ActionElement(id){
animation = 0; animation = 0;
currentState = -1; currentState = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/f3"); mFont= GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetBase(0); // using 2nd font mFont->SetBase(0); // using 2nd font
} }
@@ -17,39 +17,39 @@ void MTGGamePhase::Render(){
void MTGGamePhase::Update(float dt){ void MTGGamePhase::Update(float dt){
int newState = GameObserver::GetInstance()->getCurrentGamePhase(); int newState = GameObserver::GetInstance()->getCurrentGamePhase();
if (newState != currentState){ if (newState != currentState){
activeState = ACTIVE; activeState = ACTIVE;
animation = 1; animation = 1;
currentState = newState; currentState = newState;
switch (currentState){ switch (currentState){
default: break; default: break;
} }
} }
if (animation > 0){ if (animation > 0){
fprintf(stderr, "animation = %f", animation); fprintf(stderr, "animation = %f", animation);
animation -= dt *5 ; animation -= dt *5 ;
}else{ }else{
activeState = INACTIVE; activeState = INACTIVE;
animation = 0; animation = 0;
} }
} }
void MTGGamePhase::CheckUserInput(float dt){ void MTGGamePhase::CheckUserInput(float dt){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
if (activeState == INACTIVE){ if (activeState == INACTIVE){
if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER) && game->currentActionPlayer == game->currentlyActing()) if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER) && game->currentActionPlayer == game->currentlyActing())
{ {
activeState = ACTIVE; activeState = ACTIVE;
game->userRequestNextGamePhase(); game->userRequestNextGamePhase();
} }
} }
} }
+113 -113
View File
@@ -17,34 +17,34 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi
collection = _collection; collection = _collection;
for (i=0;i<idListSize;i++){ for (i=0;i<idListSize;i++){
MTGCard * card = collection->getCardById(idList[i]); MTGCard * card = collection->getCardById(idList[i]);
if (card){ if (card){
MTGCardInstance * newCard = NEW MTGCardInstance(card, this); MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
library->addCard(newCard); library->addCard(newCard);
} }
} }
} }
MTGPlayerCards::~MTGPlayerCards(){ MTGPlayerCards::~MTGPlayerCards(){
if(library) delete library; if(library) delete library;
if(graveyard) delete graveyard; if(graveyard) delete graveyard;
if(hand) delete hand; if(hand) delete hand;
if(inPlay) delete inPlay; if(inPlay) delete inPlay;
if(stack) delete stack; if(stack) delete stack;
} }
void MTGPlayerCards::setOwner(Player * player){ void MTGPlayerCards::setOwner(Player * player){
library->setOwner(player); library->setOwner(player);
} }
void MTGPlayerCards::initGame(int shuffle, int draw){ void MTGPlayerCards::initGame(int shuffle, int draw){
if (shuffle) library->shuffle(); if (shuffle) library->shuffle();
if (draw){ if (draw){
for (int i=0;i<7;i++){ for (int i=0;i<7;i++){
drawFromLibrary(); drawFromLibrary();
} }
} }
} }
void MTGPlayerCards::drawFromLibrary(){ void MTGPlayerCards::drawFromLibrary(){
@@ -57,7 +57,7 @@ void MTGPlayerCards::init(){
graveyard = NEW MTGGraveyard(); graveyard = NEW MTGGraveyard();
hand = NEW MTGHand(); hand = NEW MTGHand();
inPlay = NEW MTGInPlay(); inPlay = NEW MTGInPlay();
stack = NEW MTGStack(); stack = NEW MTGStack();
} }
@@ -68,39 +68,39 @@ void MTGPlayerCards::showHand(){
void MTGPlayerCards::putInPlay(MTGCardInstance * card){ void MTGPlayerCards::putInPlay(MTGCardInstance * card){
hand->removeCard(card); hand->removeCard(card);
stack->removeCard(card); //Which one is it ??? stack->removeCard(card); //Which one is it ???
inPlay->addCard(card); inPlay->addCard(card);
card->summoningSickness = 1; card->summoningSickness = 1;
card->changedZoneRecently = 1.f; card->changedZoneRecently = 1.f;
} }
void MTGPlayerCards::putInGraveyard(MTGCardInstance * card){ void MTGPlayerCards::putInGraveyard(MTGCardInstance * card){
if (inPlay->hasCard(card)){ if (inPlay->hasCard(card)){
putInZone(card,inPlay, graveyard); putInZone(card,inPlay, graveyard);
}else if (stack->hasCard(card)){ }else if (stack->hasCard(card)){
putInZone(card,stack, graveyard); putInZone(card,stack, graveyard);
}else{ }else{
putInZone(card,hand, graveyard); putInZone(card,hand, graveyard);
} }
} }
void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to){ void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to){
if (from->removeCard(card)){ if (from->removeCard(card)){
to->addCard(card); to->addCard(card);
card->changedZoneRecently = 1.f; card->changedZoneRecently = 1.f;
//if (to == graveyard){ //if (to == graveyard){
card->reset(); card->reset();
//} //}
} }
} }
void MTGPlayerCards::discardRandom(MTGGameZone * from){ void MTGPlayerCards::discardRandom(MTGGameZone * from){
if (!from->nb_cards) if (!from->nb_cards)
return; return;
int r = rand() % (from->nb_cards); int r = rand() % (from->nb_cards);
putInZone(from->cards[r],from, graveyard); putInZone(from->cards[r],from, graveyard);
} }
int MTGPlayerCards::isInPlay(MTGCardInstance * card){ int MTGPlayerCards::isInPlay(MTGCardInstance * card){
@@ -116,25 +116,25 @@ int MTGPlayerCards::isInPlay(MTGCardInstance * card){
MTGGameZone::MTGGameZone(){ MTGGameZone::MTGGameZone(){
nb_cards= 0; nb_cards= 0;
lastCardDrawn = NULL; lastCardDrawn = NULL;
} }
MTGGameZone::~MTGGameZone(){ MTGGameZone::~MTGGameZone(){
for (int i=0; i<nb_cards; i++) { for (int i=0; i<nb_cards; i++) {
delete cards[i]; delete cards[i];
} }
} }
void MTGGameZone::setOwner(Player * player){ void MTGGameZone::setOwner(Player * player){
for (int i=0; i<nb_cards; i++) { 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){ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
int i; int i;
cardsMap.erase(card); cardsMap.erase(card);
for (i=0; i<(nb_cards); i++) { for (i=0; i<(nb_cards); i++) {
if (cards[i] == card){ if (cards[i] == card){
cards[i] = cards[nb_cards -1]; cards[i] = cards[nb_cards -1];
@@ -147,7 +147,7 @@ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
} }
MTGCardInstance * MTGGameZone::hasCard(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; return NULL;
} }
@@ -174,8 +174,8 @@ int MTGGameZone::hasType(const char * value){
void MTGGameZone::cleanupPhase(){ void MTGGameZone::cleanupPhase(){
for (int i=0; i<(nb_cards); i++) for (int i=0; i<(nb_cards); i++)
(cards[i])->cleanup(); (cards[i])->cleanup();
} }
void MTGGameZone::shuffle(){ void MTGGameZone::shuffle(){
@@ -184,32 +184,32 @@ void MTGGameZone::shuffle(){
int r = i + (rand() % (nb_cards-i)); // Random remaining position. int r = i + (rand() % (nb_cards-i)); // Random remaining position.
MTGCardInstance * temp = cards[i]; cards[i] = cards[r]; cards[r] = temp; 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){ void MTGGameZone::addCard(MTGCardInstance * card){
if (!card) return; if (!card) return;
cards[nb_cards] = card; cards[nb_cards] = card;
nb_cards++; nb_cards++;
cardsMap[card] = 1; cardsMap[card] = 1;
} }
MTGCardInstance * MTGGameZone::draw(){ MTGCardInstance * MTGGameZone::draw(){
if (!nb_cards) return NULL; if (!nb_cards) return NULL;
nb_cards--; nb_cards--;
lastCardDrawn = cards[nb_cards]; lastCardDrawn = cards[nb_cards];
cardsMap.erase(cards[nb_cards]); cardsMap.erase(cards[nb_cards]);
return cards[nb_cards]; return cards[nb_cards];
} }
MTGCardInstance * MTGLibrary::draw(){ MTGCardInstance * MTGLibrary::draw(){
if (!nb_cards) { if (!nb_cards) {
GameObserver::GetInstance()->gameOver = this->owner; GameObserver::GetInstance()->gameOver = this->owner;
} }
return MTGGameZone::draw(); return MTGGameZone::draw();
} }
void MTGGameZone::debugPrint(){ void MTGGameZone::debugPrint(){
@@ -226,89 +226,89 @@ void MTGGameZone::debugPrint(){
//------------------------------ //------------------------------
int MTGInPlay::nbDefensers( MTGCardInstance * attacker){ int MTGInPlay::nbDefensers( MTGCardInstance * attacker){
int result = 0; int result = 0;
MTGCardInstance * defenser = getNextDefenser(NULL, attacker); MTGCardInstance * defenser = getNextDefenser(NULL, attacker);
while (defenser){ while (defenser){
result++; result++;
defenser = getNextDefenser(defenser, attacker); defenser = getNextDefenser(defenser, attacker);
} }
return result; return result;
} }
//Return the number of creatures this card is banded with //Return the number of creatures this card is banded with
//Number of creatures in the band is n+1 !!! //Number of creatures in the band is n+1 !!!
int MTGInPlay::nbPartners(MTGCardInstance * attacker){ int MTGInPlay::nbPartners(MTGCardInstance * attacker){
int result = 0; int result = 0;
if (!attacker->banding) return 0; if (!attacker->banding) return 0;
for (int i = 0; i < nb_cards; i ++){ for (int i = 0; i < nb_cards; i ++){
if (cards[i]->banding == attacker->banding) result++; if (cards[i]->banding == attacker->banding) result++;
} }
return result; return result;
} }
MTGCardInstance * MTGInPlay::getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker){ MTGCardInstance * MTGInPlay::getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker){
int foundprevious = 0; int foundprevious = 0;
if (previous == NULL){ if (previous == NULL){
foundprevious = 1; foundprevious = 1;
} }
for (int i = 0; i < nb_cards; i ++){ for (int i = 0; i < nb_cards; i ++){
MTGCardInstance * current = cards[i]; MTGCardInstance * current = cards[i];
if (current == previous){ if (current == previous){
foundprevious = 1; foundprevious = 1;
}else if (foundprevious && current->isDefenser() == attacker){ }else if (foundprevious && current->isDefenser() == attacker){
return current; return current;
} }
} }
return NULL; return NULL;
} }
MTGCardInstance * MTGInPlay::getNextAttacker(MTGCardInstance * previous){ MTGCardInstance * MTGInPlay::getNextAttacker(MTGCardInstance * previous){
int foundprevious = 0; int foundprevious = 0;
if (previous == NULL){ if (previous == NULL){
foundprevious = 1; foundprevious = 1;
} }
for (int i = 0; i < nb_cards; i ++){ for (int i = 0; i < nb_cards; i ++){
MTGCardInstance * current = cards[i]; MTGCardInstance * current = cards[i];
if (current == previous){ if (current == previous){
foundprevious = 1; foundprevious = 1;
}else if (foundprevious && current->isAttacker()){ }else if (foundprevious && current->isAttacker()){
return current; return current;
} }
} }
return NULL; return NULL;
} }
void MTGInPlay::untapAll(){ void MTGInPlay::untapAll(){
int i; int i;
for (i = 0; i < nb_cards; i ++){ for (i = 0; i < nb_cards; i ++){
cards[i]->setUntapping(); cards[i]->setUntapping();
if (cards[i]->getBlockers()->isEmpty()){ if (cards[i]->getBlockers()->isEmpty()){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "Can untap %s\n", cards[i]->getName()); sprintf(buf, "Can untap %s\n", cards[i]->getName());
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
cards[i]->untap(); cards[i]->untap();
} }
} }
} }
//-------------------------- //--------------------------
void MTGLibrary::shuffleTopToBottom(int nbcards){ void MTGLibrary::shuffleTopToBottom(int nbcards){
if (nbcards>nb_cards) nbcards = nb_cards; if (nbcards>nb_cards) nbcards = nb_cards;
MTGCardInstance * _cards[MTG_MAX_PLAYER_CARDS]; MTGCardInstance * _cards[MTG_MAX_PLAYER_CARDS];
for (int i= nb_cards-nbcards; i<(nb_cards); i++) { for (int i= nb_cards-nbcards; i<(nb_cards); i++) {
int r = i + (rand() % (nbcards-i)); // Random remaining position. int r = i + (rand() % (nbcards-i)); // Random remaining position.
MTGCardInstance * temp = cards[i]; cards[i] = cards[r]; cards[r] = temp; MTGCardInstance * temp = cards[i]; cards[i] = cards[r]; cards[r] = temp;
} }
for (int i= 0; i < nbcards; i++){ for (int i= 0; i < nbcards; i++){
_cards[i] = cards[nb_cards - 1 - i]; _cards[i] = cards[nb_cards - 1 - i];
} }
for (int i = nbcards; i < nb_cards; i++){ for (int i = nbcards; i < nb_cards; i++){
_cards[i] = cards[i - nb_cards]; _cards[i] = cards[i - nb_cards];
} }
for (int i=0 ; i < nb_cards; i++){ for (int i=0 ; i < nb_cards; i++){
cards[i] = _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; mAnimState = 0;
currentPlayer = NULL; currentPlayer = NULL;
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
currentId[i] = 0; currentId[i] = 0;
} }
} }
void MTGGuiHand::updateCards(){ void MTGGuiHand::updateCards(){
Player * player = GameObserver::GetInstance()->currentlyActing(); Player * player = GameObserver::GetInstance()->currentlyActing();
if (player->isAI()) player = GameObserver::GetInstance()->players[0]; if (player->isAI()) player = GameObserver::GetInstance()->players[0];
int nb_cards = player->game->hand->nb_cards; 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 ?) if (mCount != nb_cards || player != currentPlayer ){ //if the number of cards has changed, then an update occured (is this test engouh ?)
resetObjects(); resetObjects();
if (currentId[player->getId()] >= nb_cards) currentId[player->getId()] = nb_cards - 1; if (currentId[player->getId()] >= nb_cards) currentId[player->getId()] = nb_cards - 1;
for (int i = 0;i<nb_cards; i++){ 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()]); 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); Add(object);
if ( i == currentId[player->getId()]) mCurr = i; if ( i == currentId[player->getId()]) mCurr = i;
} }
currentPlayer = player; currentPlayer = player;
} }
@@ -35,14 +35,14 @@ void MTGGuiHand::updateCards(){
void MTGGuiHand::Update(float dt){ void MTGGuiHand::Update(float dt){
updateCards(); updateCards();
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){ if (mObjects[i]!=NULL){
((CardGui *)mObjects[i])->y= SCREEN_HEIGHT - mAnimState*60; ((CardGui *)mObjects[i])->y= SCREEN_HEIGHT - mAnimState*60;
} }
} }
GuiCardsController::Update(dt); 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(){ void MTGGuiHand::Render(){
if (mShowHand != HAND_HIDE){ if (mShowHand != HAND_HIDE){
// if (currentPlayer && !currentPlayer->isAI()){ // if (currentPlayer && !currentPlayer->isAI()){
RenderMessageBackground(440-mCount * 35 , SCREEN_HEIGHT - mAnimState*60 - 10, mCount * 35 + 20, 70); RenderMessageBackground(440-mCount * 35 , SCREEN_HEIGHT - mAnimState*60 - 10, mCount * 35 + 20, 70);
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){ if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render(); mObjects[i]->Render();
} }
} }
if (mCount && mObjects[mCurr] != NULL){ if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render(); mObjects[mCurr]->Render();
if (showBigCards) ((CardGui *)mObjects[mCurr])->RenderBig(10); 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 : /* 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" #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){ MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPlayer = NULL; currentPlayer = NULL;
offset = 0; offset = 0;
mPhaseBarTexture = JRenderer::GetInstance()->LoadTexture("graphics/phasebar.png", TEX_TYPE_USE_VRAM); mPhaseBarTexture = JRenderer::GetInstance()->LoadTexture("graphics/phasebar.png", TEX_TYPE_USE_VRAM);
for (int i=0; i < 12; i++){ for (int i=0; i < 12; i++){
phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28); phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28);
phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28); phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28);
} }
mGlitter = NEW JQuad(mPhaseBarTexture, 392, 0, 5, 5); mGlitter = NEW JQuad(mPhaseBarTexture, 392, 0, 5, 5);
mGlitter->SetHotSpot(2.5,2.5); mGlitter->SetHotSpot(2.5,2.5);
mGlitterAlpha = -1; mGlitterAlpha = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/f3"); mFont= GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetScale(0.75); mFont->SetScale(0.75);
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM); mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
//load all the icon images //load all the icon images
mIcons[MTG_COLOR_ARTIFACT] = NEW JQuad(mIconsTexture, 10 + 6*32, 32, 32, 32); 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_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_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_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_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_BLUE] = NEW JQuad(mIconsTexture, 10 + 1*32, 32, 32, 32);
mIcons[MTG_COLOR_GREEN] = NEW JQuad(mIconsTexture, 10 + 0*32, 32, 32, 32); mIcons[MTG_COLOR_GREEN] = NEW JQuad(mIconsTexture, 10 + 0*32, 32, 32, 32);
for (int i=0; i < 7; i++){ for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16); mIcons[i]->SetHotSpot(16,16);
} }
mBgTex = JRenderer::GetInstance()->LoadTexture("graphics/background.png", TEX_TYPE_USE_VRAM); mBgTex = JRenderer::GetInstance()->LoadTexture("graphics/background.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(mBgTex, 0, 0, 480, 272); mBg = NEW JQuad(mBgTex, 0, 0, 480, 272);
mBgTex2 = JRenderer::GetInstance()->LoadTexture("graphics/back.jpg", TEX_TYPE_USE_VRAM); mBgTex2 = JRenderer::GetInstance()->LoadTexture("graphics/back.jpg", TEX_TYPE_USE_VRAM);
mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255); mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255);
for (int i= 0; i < 4; i++){ for (int i= 0; i < 4; i++){
alphaBg[i] = 255; alphaBg[i] = 255;
} }
alphaBg[0] = 0; alphaBg[0] = 0;
AddPlayersGuiInfo(); AddPlayersGuiInfo();
} }
CardGui * MTGGuiPlay::getByCard(MTGCardInstance * card){ CardGui * MTGGuiPlay::getByCard(MTGCardInstance * card){
for (int i = offset; i < mCount; i++){ for (int i = offset; i < mCount; i++){
CardGui * cardg = (CardGui *)mObjects[i]; CardGui * cardg = (CardGui *)mObjects[i];
if(cardg && cardg->card == card){ if(cardg && cardg->card == card){
return cardg; return cardg;
} }
} }
return NULL; return NULL;
} }
void MTGGuiPlay::initCardsDisplay(){ void MTGGuiPlay::initCardsDisplay(){
for (int i = 0; i < SCREEN_WIDTH/5; i++){ for (int i = 0; i < SCREEN_WIDTH/5; i++){
for(int j=0; j < SCREEN_HEIGHT/5; j++){ for(int j=0; j < SCREEN_HEIGHT/5; j++){
cardsGrid[i][j] = NULL; cardsGrid[i][j] = NULL;
} }
} }
cards_x_limit = 12; cards_x_limit = 12;
nb_creatures = 0; nb_creatures = 0;
nb_lands = 0; nb_lands = 0;
nb_spells = 0; nb_spells = 0;
} }
void MTGGuiPlay::adjustCardPosition(CardGui * cardg){ void MTGGuiPlay::adjustCardPosition(CardGui * cardg){
int x5 = cardg->x / 5; int x5 = cardg->x / 5;
int y5 = cardg->y / 5; int y5 = cardg->y / 5;
while (cardsGrid[x5][y5] && x5 <SCREEN_WIDTH/5 && y5 < SCREEN_HEIGHT/5 ){ while (cardsGrid[x5][y5] && x5 <SCREEN_WIDTH/5 && y5 < SCREEN_HEIGHT/5 ){
x5++; x5++;
y5++; y5++;
} }
cardg->x = x5 * 5; cardg->x = x5 * 5;
cardg->y = y5 * 5; cardg->y = y5 * 5;
cardsGrid[x5][y5] = cardg->card; cardsGrid[x5][y5] = cardg->card;
} }
void MTGGuiPlay::setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode){ void MTGGuiPlay::setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode){
MTGCardInstance * card = cardg->card; MTGCardInstance * card = cardg->card;
if (card->target) if (card->target)
return; return;
if (spellMode && (card->isACreature() || card->hasType("land"))) return; if (spellMode && (card->isACreature() || card->hasType("land"))) return;
if (!spellMode && !card->isACreature() && !card->hasType("land")) return; if (!spellMode && !card->isACreature() && !card->hasType("land")) return;
if (card->isACreature()){ if (card->isACreature()){
int x_offset = nb_creatures % cards_x_limit; int x_offset = nb_creatures % cards_x_limit;
int y_offset = nb_creatures / cards_x_limit; int y_offset = nb_creatures / cards_x_limit;
cardg->x= ZX_MAIN + (Z_CARDWIDTH * x_offset); cardg->x= ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + ZH_CREATURES + (Z_CARDHEIGHT * y_offset) + 100 * (1-player); cardg->y=ZY_MAIN + ZH_CREATURES + (Z_CARDHEIGHT * y_offset) + 100 * (1-player);
nb_creatures++; nb_creatures++;
if (playerTurn){ if (playerTurn){
if (card->isAttacker()){ if (card->isAttacker()){
cardg->y=122 + 30 * (1-player); cardg->y=122 + 30 * (1-player);
} }
}else{ }else{
if (card->isDefenser()){ if (card->isDefenser()){
CardGui * targetg = getByCard(card->isDefenser()); CardGui * targetg = getByCard(card->isDefenser());
if (targetg) cardg->x = targetg->x; if (targetg) cardg->x = targetg->x;
cardg->y=122 + 30 * (1-player); cardg->y=122 + 30 * (1-player);
} }
} }
}else if(card->hasType("land")){ }else if(card->hasType("land")){
int x_offset = nb_lands % cards_x_limit; int x_offset = nb_lands % cards_x_limit;
int y_offset = nb_lands/ cards_x_limit; int y_offset = nb_lands/ cards_x_limit;
cardg->x=ZX_MAIN + (Z_CARDWIDTH * x_offset); cardg->x=ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + (Z_CARDHEIGHT * y_offset) + 200 * (1-player); cardg->y=ZY_MAIN + (Z_CARDHEIGHT * y_offset) + 200 * (1-player);
nb_lands++; nb_lands++;
}else{ }else{
int y_offset = nb_spells % Z_SPELLS_NBCARDS; int y_offset = nb_spells % Z_SPELLS_NBCARDS;
int x_offset = nb_spells/ Z_SPELLS_NBCARDS; int x_offset = nb_spells/ Z_SPELLS_NBCARDS;
cardg->x=ZX_SPELL - (Z_CARDWIDTH * x_offset); cardg->x=ZX_SPELL - (Z_CARDWIDTH * x_offset);
cardg->y=ZY_SPELL + (Z_CARDHEIGHT * y_offset) + 125 * (1-player); cardg->y=ZY_SPELL + (Z_CARDHEIGHT * y_offset) + 125 * (1-player);
nb_spells++; nb_spells++;
cards_x_limit = 12 - (nb_spells + 2)/ Z_SPELLS_NBCARDS; cards_x_limit = 12 - (nb_spells + 2)/ Z_SPELLS_NBCARDS;
} }
adjustCardPosition(cardg); adjustCardPosition(cardg);
} }
void MTGGuiPlay::setTargettingCardPosition(CardGui * cardg, int player, int playerTurn){ void MTGGuiPlay::setTargettingCardPosition(CardGui * cardg, int player, int playerTurn){
MTGCardInstance * card = cardg->card; MTGCardInstance * card = cardg->card;
MTGCardInstance * target = card->target; MTGCardInstance * target = card->target;
if (!target) if (!target)
return; return;
CardGui * targetg = getByCard(target); CardGui * targetg = getByCard(target);
if (targetg){ if (targetg){
cardg->y=targetg->y + 5; cardg->y=targetg->y + 5;
cardg->x=targetg->x + 5; cardg->x=targetg->x + 5;
} }
adjustCardPosition(cardg); adjustCardPosition(cardg);
return; return;
} }
void MTGGuiPlay::updateCards(){ void MTGGuiPlay::updateCards(){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
Player * player = game->players[0]; Player * player = game->players[0];
int player0Mode =(game->currentPlayer == player); int player0Mode =(game->currentPlayer == player);
int nb_cards = player->game->inPlay->nb_cards; int nb_cards = player->game->inPlay->nb_cards;
MTGCardInstance * attackers[MAX_ATTACKERS]; MTGCardInstance * attackers[MAX_ATTACKERS];
for (int i = 0; i <MAX_ATTACKERS; i++){ for (int i = 0; i <MAX_ATTACKERS; i++){
attackers[i] = NULL; attackers[i] = NULL;
} }
offset = 6; offset = 6;
Player * opponent = game->players[1]; Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards; 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 ?) 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(); resetObjects();
AddPlayersGuiInfo(); AddPlayersGuiInfo();
offset = mCount; offset = mCount;
bool hasFocus = player0Mode; bool hasFocus = player0Mode;
for (int i = 0;i<nb_cards; i++){ for (int i = 0;i<nb_cards; i++){
if (hasFocus) mCurr = mCount ; if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, player->game->inPlay->cards[i],40, i*35 + 10, 200, hasFocus); CardGui * object = NEW CardGui(mCount, player->game->inPlay->cards[i],40, i*35 + 10, 200, hasFocus);
Add(object); Add(object);
hasFocus = false; hasFocus = false;
} }
hasFocus = !player0Mode; hasFocus = !player0Mode;
for (int i = 0;i<opponent_cards; i++){ for (int i = 0;i<opponent_cards; i++){
if (hasFocus) mCurr = mCount ; if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, opponent->game->inPlay->cards[i],40, i*35 + 10, 10, hasFocus); CardGui * object = NEW CardGui(mCount, opponent->game->inPlay->cards[i],40, i*35 + 10, 10, hasFocus);
Add(object); Add(object);
hasFocus = false; 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 //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++){ for (int j= 0; j < 2; j++){
initCardsDisplay(); initCardsDisplay();
if (j != player0Mode){ if (j != player0Mode){
for (int i =0; i<nb_cards; i++){ for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset]; CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 1); setCardPosition(cardGui, 0, player0Mode, 1);
} }
for (int i =0; i<nb_cards; i++){ for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset]; CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 0); setCardPosition(cardGui, 0, player0Mode, 0);
} }
}else{ }else{
for (int i =0; i<opponent_cards; i++){ for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset]; CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,1); setCardPosition(cardGui, 1, !player0Mode,1);
} }
for (int i =0; i<opponent_cards; i++){ for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset]; CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,0); setCardPosition(cardGui, 1, !player0Mode,0);
} }
} }
} }
for (int i =0; i<nb_cards; i++){ for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset ]; CardGui * cardGui = (CardGui *)mObjects[i + offset ];
setTargettingCardPosition(cardGui, 0, player0Mode); setTargettingCardPosition(cardGui, 0, player0Mode);
} }
for (int i =0; i<opponent_cards; i++){ for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset]; CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setTargettingCardPosition(cardGui, 1, !player0Mode); setTargettingCardPosition(cardGui, 1, !player0Mode);
} }
@@ -237,36 +237,36 @@ void MTGGuiPlay::updateCards(){
void MTGGuiPlay::AddPlayersGuiInfo(){ void MTGGuiPlay::AddPlayersGuiInfo(){
//init with the players objects //init with the players objects
if (mCount == 0){ if (mCount == 0){
Add(NEW GuiAvatar(-1,50,2,155,false, GameObserver::GetInstance()->players[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 GuiAvatar(-2,50,2,30,false,GameObserver::GetInstance()->players[1]));
Add(NEW GuiGraveyard(-3,30,40,150,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 GuiLibrary(-4,30,40,180,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiGraveyard(-5,30,40,30,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])); Add(NEW GuiLibrary(-6,30,40,60,false, GameObserver::GetInstance()->players[1]));
} }
} }
void MTGGuiPlay::Update(float dt){ void MTGGuiPlay::Update(float dt){
updateCards(); updateCards();
PlayGuiObjectController::Update(dt); PlayGuiObjectController::Update(dt);
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
} }
void MTGGuiPlay::CheckUserInput(float dt){ void MTGGuiPlay::CheckUserInput(float dt){
for (int i = 2; i<6;i++){ for (int i = 2; i<6;i++){
GuiGameZone * zone = (GuiGameZone *)mObjects[i]; GuiGameZone * zone = (GuiGameZone *)mObjects[i];
if (zone->showCards){ if (zone->showCards){
zone->cd->CheckUserInput(dt); zone->cd->CheckUserInput(dt);
return; return;
} }
} }
PlayGuiObjectController::CheckUserInput(dt); PlayGuiObjectController::CheckUserInput(dt);
@@ -274,132 +274,132 @@ void MTGGuiPlay::CheckUserInput(float dt){
void MTGGuiPlay::RenderPlayerInfo(int playerid){ void MTGGuiPlay::RenderPlayerInfo(int playerid){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
JRenderer * r = JRenderer::GetInstance(); JRenderer * r = JRenderer::GetInstance();
Player * player = GameObserver::GetInstance()->players[playerid]; Player * player = GameObserver::GetInstance()->players[playerid];
int life = player->life; int life = player->life;
//Avatar //Avatar
GuiAvatar * avatar = (GuiAvatar *)mObjects[3*playerid]; GuiAvatar * avatar = (GuiAvatar *)mObjects[3*playerid];
avatar->Render(); avatar->Render();
//Mana //Mana
ManaCost * cost = player->getManaPool(); ManaCost * cost = player->getManaPool();
int nbicons = 0; int nbicons = 0;
for (int j=0; j<6;j++){ for (int j=0; j<6;j++){
int value = cost->getCost(j); int value = cost->getCost(j);
for (int i=0; i<value; i++){ for (int i=0; i<value; i++){
float x = 10 + (nbicons %4) * 15; float x = 10 + (nbicons %4) * 15;
float y = 90 + 125 * (1-playerid) + (15 * (nbicons / 4)); float y = 90 + 125 * (1-playerid) + (15 * (nbicons / 4));
r->RenderQuad(mIcons[j],x,y,0,0.5, 0.5); r->RenderQuad(mIcons[j],x,y,0,0.5, 0.5);
nbicons++; nbicons++;
} }
} }
} }
void MTGGuiPlay::RenderPhaseBar(){ void MTGGuiPlay::RenderPhaseBar(){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
int currentPhase = game->getCurrentGamePhase(); int currentPhase = game->getCurrentGamePhase();
for (int i=0; i < 12; i++){ for (int i=0; i < 12; i++){
int index = 2*i + 1 ; int index = 2*i + 1 ;
if (i==currentPhase-1){ if (i==currentPhase-1){
index-=1; index-=1;
} }
renderer->RenderQuad(phaseIcons[index], 200 + 14*i,0,0,0.5,0.5); renderer->RenderQuad(phaseIcons[index], 200 + 14*i,0,0,0.5,0.5);
} }
mFont->SetScale(0.70); mFont->SetScale(0.70);
if (game->currentlyActing()->isAI()){ if (game->currentlyActing()->isAI()){
mFont->SetColor(ARGB(255,128,128,128)); mFont->SetColor(ARGB(255,128,128,128));
}else{ }else{
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
} }
mFont->DrawString(MTGPhaseNames[currentPhase], 375, 0); mFont->DrawString(MTGPhaseNames[currentPhase], 375, 0);
} }
void MTGGuiPlay::Render(){ void MTGGuiPlay::Render(){
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
//alphaBg[1] = 255; //alphaBg[1] = 255;
//alphaBg[2]= 255; //alphaBg[2]= 255;
//alphaBg[3] = 255; //alphaBg[3] = 255;
//mBg2->SetColor(ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3])); //mBg2->SetColor(ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg2,0,17); renderer->RenderQuad(mBg2,0,17);
if (game->currentGamePhase >=MTG_PHASE_COMBATBEGIN && game->currentGamePhase < MTG_PHASE_COMBATEND){ if (game->currentGamePhase >=MTG_PHASE_COMBATBEGIN && game->currentGamePhase < MTG_PHASE_COMBATEND){
if (alphaBg[0] < 50){ if (alphaBg[0] < 50){
alphaBg[3]-=12; alphaBg[3]-=12;
alphaBg[2]-=12; alphaBg[2]-=12;
alphaBg[0]+=3; alphaBg[0]+=3;
} }
alphaBg[1] = 255; alphaBg[1] = 255;
}else{ }else{
if (alphaBg[0]){ if (alphaBg[0]){
alphaBg[0]-=3; alphaBg[0]-=3;
alphaBg[3]+=12; alphaBg[3]+=12;
alphaBg[2]+=12; alphaBg[2]+=12;
} }
alphaBg[1] = 255; alphaBg[1] = 255;
} }
renderer->FillRect(0,0,480,272,ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3])); 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++){ for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){ if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render(); mObjects[i]->Render();
} }
} }
RenderPhaseBar(); RenderPhaseBar();
RenderPlayerInfo(0); RenderPlayerInfo(0);
RenderPlayerInfo(1); RenderPlayerInfo(1);
if (mCount && mObjects[mCurr] != NULL){ if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render(); mObjects[mCurr]->Render();
if (hasFocus && mCurr >= offset && showBigCards) if (hasFocus && mCurr >= offset && showBigCards)
((CardGui *)mObjects[mCurr])->RenderBig(); ((CardGui *)mObjects[mCurr])->RenderBig();
} }
if (mGlitterAlpha < 0){ if (mGlitterAlpha < 0){
mGlitterAlpha = 510; mGlitterAlpha = 510;
int position = rand() % 2; int position = rand() % 2;
if (position){ if (position){
mGlitterX = 65 + rand() % (420); mGlitterX = 65 + rand() % (420);
mGlitterY = 17 + rand() % (5); mGlitterY = 17 + rand() % (5);
}else{ }else{
mGlitterX = 65 + rand() % (5); mGlitterX = 65 + rand() % (5);
mGlitterY = 15 + rand() % (250); mGlitterY = 15 + rand() % (250);
} }
} }
mGlitter->SetColor(ARGB((255-abs(255-mGlitterAlpha)),240,240,255)); 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)); renderer->RenderQuad(mGlitter,mGlitterX,mGlitterY, (float)(mGlitterAlpha)/(float)255, 1.2*float(mGlitterAlpha)/float(255),1.2*float(mGlitterAlpha)/float(255));
mGlitterAlpha-=10; mGlitterAlpha-=10;
} }
MTGGuiPlay::~MTGGuiPlay(){ MTGGuiPlay::~MTGGuiPlay(){
LOG("==Destroying MTGGuiPlay=="); LOG("==Destroying MTGGuiPlay==");
delete mBg; delete mBg;
delete mBgTex; delete mBgTex;
for (int i=0; i < 7; i++){ for (int i=0; i < 7; i++){
delete mIcons[i]; delete mIcons[i];
} }
delete mIconsTexture; delete mIconsTexture;
delete mGlitter; delete mGlitter;
for (int i=0; i < 12; i++){ for (int i=0; i < 12; i++){
delete phaseIcons[2*i] ; delete phaseIcons[2*i] ;
delete phaseIcons[2*i + 1]; delete phaseIcons[2*i + 1];
} }
delete mPhaseBarTexture; delete mPhaseBarTexture;
SAFE_DELETE(mBg2); SAFE_DELETE(mBg2);
SAFE_DELETE(mBgTex2); 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){ int MTGAttackRule::isReactingToClick(MTGCardInstance * card){
if (currentPhase == MTG_PHASE_COMBATATTACKERS && card->controller() == game->currentPlayer && !card->isAttacker()){ if (currentPhase == MTG_PHASE_COMBATATTACKERS && card->controller() == game->currentPlayer && !card->isAttacker()){
if (card->canAttack()) return 1; if (card->canAttack()) return 1;
} }
return 0; return 0;
} }
int MTGAttackRule::reactToClick(MTGCardInstance * card){ int MTGAttackRule::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0; if (!isReactingToClick(card)) return 0;
card->attacker = 1; card->attacker = 1;
if (!card->basicAbilities[VIGILANCE]) card->tapped = 1; if (!card->basicAbilities[VIGILANCE]) card->tapped = 1;
return 1; return 1;
} }
//The Attack rule is never destroyed //The Attack rule is never destroyed
int MTGAttackRule::testDestroy(){ int MTGAttackRule::testDestroy(){
return 0; return 0;
} }
@@ -29,32 +29,32 @@ MTGBlockRule::MTGBlockRule(int _id):MTGAbility(_id,NULL){
} }
int MTGBlockRule::isReactingToClick(MTGCardInstance * card){ int MTGBlockRule::isReactingToClick(MTGCardInstance * card){
if (currentPhase == MTG_PHASE_COMBATBLOCKERS && !game->isInterrupting && card->controller() == game->opponent()){ if (currentPhase == MTG_PHASE_COMBATBLOCKERS && !game->isInterrupting && card->controller() == game->opponent()){
if (card->canBlock()) return 1; if (card->canBlock()) return 1;
} }
return 0; return 0;
} }
int MTGBlockRule::reactToClick(MTGCardInstance * card){ int MTGBlockRule::reactToClick(MTGCardInstance * card){
if (!isReactingToClick(card)) return 0; if (!isReactingToClick(card)) return 0;
MTGCardInstance * currentOpponent = card->isDefenser(); MTGCardInstance * currentOpponent = card->isDefenser();
bool result = false; bool result = false;
int candefend = 0; int candefend = 0;
while (!result){ while (!result){
currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent); currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent);
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf,"Defenser Toggle %s \n" ,card->model->getName()); sprintf(buf,"Defenser Toggle %s \n" ,card->model->getName());
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
candefend = card->toggleDefenser(currentOpponent); candefend = card->toggleDefenser(currentOpponent);
result = (candefend || currentOpponent == NULL); result = (candefend || currentOpponent == NULL);
} }
return 1; return 1;
} }
//The Block rule is never destroyed //The Block rule is never destroyed
int MTGBlockRule::testDestroy(){ int MTGBlockRule::testDestroy(){
return 0; return 0;
} }
+117 -117
View File
@@ -5,20 +5,20 @@
#if defined (WIN32) #if defined (WIN32)
#include <windows.h> #include <windows.h>
#endif #endif
ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost){ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
#endif #endif
ManaCost * manaCost; ManaCost * manaCost;
if (_manaCost){ if (_manaCost){
manaCost = _manaCost; manaCost = _manaCost;
}else{ }else{
manaCost = NEW ManaCost(); manaCost = NEW ManaCost();
} }
int state = 0; int state = 0;
unsigned int start = 0; unsigned int start = 0;
unsigned int end = 0; unsigned int end = 0;
while (!s.empty() && state != -1){ while (!s.empty() && state != -1){
@@ -26,15 +26,15 @@ char buf[4096];
case 0: case 0:
start = s.find_first_of("{"); start = s.find_first_of("{");
if (start == string::npos){ if (start == string::npos){
return manaCost; return manaCost;
}else{ }else{
state = 1; state = 1;
} }
break; break;
case 1: case 1:
end = s.find_first_of("}"); end = s.find_first_of("}");
if (end == string::npos){ if (end == string::npos){
state = -1; state = -1;
}else{ }else{
string value = s.substr(start+1, end - 1 - start); string value = s.substr(start+1, end - 1 - start);
if (value == "u"){ if (value == "u"){
@@ -52,30 +52,30 @@ char buf[4096];
}else if (value == "t"){ }else if (value == "t"){
}else{ }else{
int intvalue = atoi(value.c_str()); int intvalue = atoi(value.c_str());
int colors[2]; int colors[2];
int values[2]; int values[2];
if (!intvalue && value.size() > 1){ if (!intvalue && value.size() > 1){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("Hybrid Mana ???\n"); OutputDebugString("Hybrid Mana ???\n");
#endif #endif
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
char c = value[i]; char c = value[i];
if (c >='0' && c <='9'){ if (c >='0' && c <='9'){
colors[i] = MTG_COLOR_ARTIFACT; colors[i] = MTG_COLOR_ARTIFACT;
values[i] = c - '0'; values[i] = c - '0';
}else{ }else{
for (int j = 0; j < MTG_NB_COLORS; j++){ for (int j = 0; j < MTG_NB_COLORS; j++){
if (c == MTGColorChars[j]){ if (c == MTGColorChars[j]){
colors[i] = j; colors[i] = j;
values[i] = 1; values[i] = 1;
} }
}
}
}
manaCost->addHybrid(colors[0], values[0], colors[1], values[1]);
}else{
manaCost->add(MTG_COLOR_ARTIFACT, intvalue);
} }
}
}
manaCost->addHybrid(colors[0], values[0], colors[1], values[1]);
}else{
manaCost->add(MTG_COLOR_ARTIFACT, intvalue);
}
} }
s = s.substr(end + 1); s = s.substr(end + 1);
state = 0; state = 0;
@@ -85,7 +85,7 @@ OutputDebugString("Hybrid Mana ???\n");
break; break;
} }
} }
return manaCost; return manaCost;
} }
ManaCost::ManaCost(){ ManaCost::ManaCost(){
@@ -96,9 +96,9 @@ ManaCost::ManaCost(int _cost[], int nb_elems){
int i; int i;
int total = nb_elems; int total = nb_elems;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "Create New MAnaCost, total Colors : %i\n", total); sprintf(buf, "Create New MAnaCost, total Colors : %i\n", total);
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
for (i = 0; i < total; i++){ for (i = 0; i < total; i++){
cost[_cost[i*2]] = _cost[i*2 + 1]; cost[_cost[i*2]] = _cost[i*2 + 1];
@@ -115,14 +115,14 @@ ManaCost::ManaCost(ManaCost * _manaCost){
} }
ManaCost::~ManaCost(){ ManaCost::~ManaCost(){
LOG("==Deleting ManaCost=="); LOG("==Deleting ManaCost==");
for (int i = 0; i < nbhybrids ; i++){ for (int i = 0; i < nbhybrids ; i++){
SAFE_DELETE(hybrids[i]); SAFE_DELETE(hybrids[i]);
} }
} }
void ManaCost::x(){ void ManaCost::x(){
cost[MTG_NB_COLORS] = 1; cost[MTG_NB_COLORS] = 1;
} }
void ManaCost::init(){ void ManaCost::init(){
@@ -130,7 +130,7 @@ void ManaCost::init(){
for (i=0; i<= MTG_NB_COLORS; i++){ for (i=0; i<= MTG_NB_COLORS; i++){
cost[i] = 0; cost[i] = 0;
} }
nbhybrids = 0; nbhybrids = 0;
} }
@@ -141,7 +141,7 @@ void ManaCost::copy(ManaCost * _manaCost){
for (int i=0; i< _manaCost->nbhybrids; i++){ for (int i=0; i< _manaCost->nbhybrids; i++){
hybrids[i] = NEW ManaCostHybrid((*_manaCost->hybrids[i])); hybrids[i] = NEW ManaCostHybrid((*_manaCost->hybrids[i]));
} }
nbhybrids = _manaCost->nbhybrids; nbhybrids = _manaCost->nbhybrids;
} }
int ManaCost::getCost(int color){ int ManaCost::getCost(int color){
@@ -152,31 +152,31 @@ int ManaCost::getMainColor(){
for (int i=0; i< MTG_NB_COLORS; i++){ for (int i=0; i< MTG_NB_COLORS; i++){
if (cost[i]) return i; if (cost[i]) return i;
} }
return 0; return 0;
} }
int ManaCost::hasColor(int color){ int ManaCost::hasColor(int color){
if (cost[color]) return 1; if (cost[color]) return 1;
for (int i = 0; i < nbhybrids; i++){ for (int i = 0; i < nbhybrids; i++){
if (hybrids[i]->hasColor(color)) return 1; if (hybrids[i]->hasColor(color)) return 1;
} }
return 0; return 0;
} }
int ManaCost::getConvertedCost(){ int ManaCost::getConvertedCost(){
int result = 0; int result = 0;
for (int i=0; i< MTG_NB_COLORS; i++){ for (int i=0; i< MTG_NB_COLORS; i++){
result += cost[i]; result += cost[i];
} }
for (int i = 0; i < nbhybrids; i++){ for (int i = 0; i < nbhybrids; i++){
result+= hybrids[i]->getConvertedCost(); result+= hybrids[i]->getConvertedCost();
} }
return result; return result;
} }
int ManaCost::remove(int color, int value){ int ManaCost::remove(int color, int value){
cost[color] -= value; cost[color] -= value;
return 1; return 1;
} }
int ManaCost::add(int color, int value){ int ManaCost::add(int color, int value){
@@ -185,14 +185,14 @@ int ManaCost::add(int color, int value){
} }
int ManaCost::add(ManaCost * _cost){ int ManaCost::add(ManaCost * _cost){
for (int i=0; i< MTG_NB_COLORS; i++){ for (int i=0; i< MTG_NB_COLORS; i++){
cost[i]+= _cost->getCost(i); cost[i]+= _cost->getCost(i);
}
for (int i=0; i< _cost->nbhybrids; i++){
hybrids[nbhybrids] = NEW ManaCostHybrid((*_cost->hybrids[i]));
nbhybrids++;
} }
return 1; for (int i=0; i< _cost->nbhybrids; i++){
hybrids[nbhybrids] = NEW ManaCostHybrid((*_cost->hybrids[i]));
nbhybrids++;
}
return 1;
} }
string ManaCost::toString(){ string ManaCost::toString(){
@@ -201,30 +201,30 @@ string ManaCost::toString(){
int ManaCost::addHybrid(int c1, int v1, int c2, int v2){ int ManaCost::addHybrid(int c1, int v1, int c2, int v2){
ManaCostHybrid * h = NEW ManaCostHybrid(c1,v1,c2,v2); ManaCostHybrid * h = NEW ManaCostHybrid(c1,v1,c2,v2);
hybrids[nbhybrids] = h; hybrids[nbhybrids] = h;
nbhybrids++; nbhybrids++;
return nbhybrids; return nbhybrids;
} }
int ManaCost::pay(ManaCost * _cost){ int ManaCost::pay(ManaCost * _cost){
ManaCost * diff = Diff(_cost); ManaCost * diff = Diff(_cost);
for (int i=0; i < MTG_NB_COLORS; i++){ for (int i=0; i < MTG_NB_COLORS; i++){
cost[i] = diff->getCost(i); cost[i] = diff->getCost(i);
} }
delete diff; delete diff;
return 1; return 1;
//TODO return 0 if can't afford the cost! //TODO return 0 if can't afford the cost!
} }
//return 1 if _cost can be paid with current data //return 1 if _cost can be paid with current data
int ManaCost::canAfford(ManaCost * _cost){ int ManaCost::canAfford(ManaCost * _cost){
ManaCost * diff = Diff(_cost); ManaCost * diff = Diff(_cost);
int positive = diff->isPositive(); int positive = diff->isPositive();
delete diff; delete diff;
if (positive){ if (positive){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
OutputDebugString("can afford\n"); OutputDebugString("can afford\n");
#endif #endif
return 1; return 1;
} }
@@ -244,50 +244,50 @@ int ManaCost::isPositive(){
void ManaCost::randomDiffHybrids(ManaCost * _cost, int diff[]){ void ManaCost::randomDiffHybrids(ManaCost * _cost, int diff[]){
int _nbhybrids = _cost->nbhybrids; int _nbhybrids = _cost->nbhybrids;
for (int i = 0; i < _nbhybrids; i++){ for (int i = 0; i < _nbhybrids; i++){
ManaCostHybrid * h = _cost->hybrids[i]; ManaCostHybrid * h = _cost->hybrids[i];
diff[h->color1 * 2 +1]-= h->value1; diff[h->color1 * 2 +1]-= h->value1;
} }
} }
int ManaCost::tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]){ int ManaCost::tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]){
if (!_nbhybrids) return 1; if (!_nbhybrids) return 1;
int result = 0; int result = 0;
ManaCostHybrid * h = _hybrids[_nbhybrids -1]; ManaCostHybrid * h = _hybrids[_nbhybrids -1];
if (diff[h->color1 * 2 +1] >= h->value1){ if (diff[h->color1 * 2 +1] >= h->value1){
diff[h->color1 * 2 +1]-= h->value1; diff[h->color1 * 2 +1]-= h->value1;
result = tryToPayHybrids(_hybrids,_nbhybrids -1, diff); result = tryToPayHybrids(_hybrids,_nbhybrids -1, diff);
if (result) return 1; if (result) return 1;
diff[h->color1 * 2 +1]+= h->value1; diff[h->color1 * 2 +1]+= h->value1;
} }
if (diff[h->color2 * 2 +1] >= h->value2){ if (diff[h->color2 * 2 +1] >= h->value2){
diff[h->color2 * 2 +1]-= h->value2; diff[h->color2 * 2 +1]-= h->value2;
result = tryToPayHybrids(_hybrids,_nbhybrids -1, diff); result = tryToPayHybrids(_hybrids,_nbhybrids -1, diff);
if (result) return 1; if (result) return 1;
diff[h->color2 * 2 +1]+= h->value2; diff[h->color2 * 2 +1]+= h->value2;
} }
return 0; return 0;
} }
//compute the difference between two mana costs //compute the difference between two mana costs
ManaCost * ManaCost::Diff(ManaCost * _cost){ ManaCost * ManaCost::Diff(ManaCost * _cost){
int diff[(MTG_NB_COLORS + 1 )* 2]; 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++){ for (int i=0; i < MTG_NB_COLORS; i++){
diff[i*2] = i; diff[i*2] = i;
diff[i*2 +1] = cost[i] - _cost->getCost(i); diff[i*2 +1] = cost[i] - _cost->getCost(i);
} }
int hybridResult = tryToPayHybrids(_cost->hybrids, _cost->nbhybrids, diff); int hybridResult = tryToPayHybrids(_cost->hybrids, _cost->nbhybrids, diff);
if (!hybridResult) randomDiffHybrids(_cost,diff); if (!hybridResult) randomDiffHybrids(_cost,diff);
//Colorless mana, special case //Colorless mana, special case
int colorless_idx = MTG_COLOR_ARTIFACT * 2 + 1; int colorless_idx = MTG_COLOR_ARTIFACT * 2 + 1;
if (diff[colorless_idx] < 0){ if (diff[colorless_idx] < 0){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
//char buf[4096], *p = buf; //char buf[4096], *p = buf;
//sprintf(buf, "--Diff color TEST %i : %i\n", i, cost[i]); //sprintf(buf, "--Diff color TEST %i : %i\n", i, cost[i]);
OutputDebugString("Colorless mana not enough\n"); OutputDebugString("Colorless mana not enough\n");
#endif #endif
for (int i=0; i < MTG_NB_COLORS; i++){ for (int i=0; i < MTG_NB_COLORS; i++){
if (diff[i*2 + 1] > 0){ if (diff[i*2 + 1] > 0){
@@ -303,16 +303,16 @@ OutputDebugString("Colorless mana not enough\n");
} }
} }
//Cost X //Cost X
if (_cost->getCost(MTG_NB_COLORS)){ if (_cost->getCost(MTG_NB_COLORS)){
diff[MTG_NB_COLORS * 2 + 1] = 0; diff[MTG_NB_COLORS * 2 + 1] = 0;
for (int i=0; i < MTG_NB_COLORS; i++){ for (int i=0; i < MTG_NB_COLORS; i++){
if (diff[i*2 + 1] > 0){ if (diff[i*2 + 1] > 0){
diff[MTG_NB_COLORS * 2 + 1] += diff[i*2 + 1]; diff[MTG_NB_COLORS * 2 + 1] += diff[i*2 + 1];
diff[i*2 + 1] = 0; diff[i*2 + 1] = 0;
} }
} }
} }
ManaCost * result = NEW ManaCost(diff, MTG_NB_COLORS +1); ManaCost * result = NEW ManaCost(diff, MTG_NB_COLORS +1);
return result; return result;
+10 -10
View File
@@ -1,26 +1,26 @@
#include "../include/ManaCostHybrid.h" #include "../include/ManaCostHybrid.h"
ManaCostHybrid::ManaCostHybrid(){ ManaCostHybrid::ManaCostHybrid(){
init(0,0,0,0); init(0,0,0,0);
} }
ManaCostHybrid::ManaCostHybrid(int c1,int v1,int c2,int v2){ 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){ void ManaCostHybrid::init(int c1,int v1,int c2,int v2){
color1 = c1; color1 = c1;
color2 = c2; color2 = c2;
value1 = v1; value1 = v1;
value2 = v2; value2 = v2;
} }
int ManaCostHybrid::getConvertedCost(){ int ManaCostHybrid::getConvertedCost(){
if (value2 > value1) return value2; if (value2 > value1) return value2;
return value1; return value1;
} }
int ManaCostHybrid::hasColor(int color){ int ManaCostHybrid::hasColor(int color){
if (((color1 == color) && value1) || ((color2 == color) && value2)) return 1; if (((color1 == color) && value1) || ((color2 == color) && value2)) return 1;
return 0; 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; updatedSinceLastRender = 1;
mParticleSys = NEW hgeParticleSystem(particle, particleTex); mParticleSys = NEW hgeParticleSystem(particle, particleTex);
mParticleSys->MoveTo(mX, mY); mParticleSys->MoveTo(mX, mY);
mHasFocus = hasFocus; mHasFocus = hasFocus;
lastDt = 0.001f; lastDt = 0.001f;
mScale = 1.0f; mScale = 1.0f;
mTargetScale = 1.0f; mTargetScale = 1.0f;
onQuad = _on; onQuad = _on;
offQuad = _off; offQuad = _off;
if (hasFocus) if (hasFocus)
Entering(); Entering();
mFont->SetScale(1.2f); 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() void MenuItem::Render()
{ {
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
if (mHasFocus) if (mHasFocus)
{ {
if (!updatedSinceLastRender){ if (!updatedSinceLastRender){
mParticleSys->Update(lastDt); mParticleSys->Update(lastDt);
} }
// set additive blending // set additive blending
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE); renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
mParticleSys->Render(); mParticleSys->Render();
// set normal blending // set normal blending
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
onQuad->SetColor(ARGB(70,255,255,255)); onQuad->SetColor(ARGB(70,255,255,255));
renderer->RenderQuad(onQuad, SCREEN_WIDTH , SCREEN_HEIGHT/2 , 0,8,8); renderer->RenderQuad(onQuad, SCREEN_WIDTH , SCREEN_HEIGHT/2 , 0,8,8);
onQuad->SetColor(ARGB(255,255,255,255)); onQuad->SetColor(ARGB(255,255,255,255));
mFont->DrawString(mText, SCREEN_WIDTH/2, 3*SCREEN_HEIGHT/4, JGETEXT_CENTER); mFont->DrawString(mText, SCREEN_WIDTH/2, 3*SCREEN_HEIGHT/4, JGETEXT_CENTER);
renderer->RenderQuad(onQuad, mX , mY , 0,mScale,mScale); renderer->RenderQuad(onQuad, mX , mY , 0,mScale,mScale);
} }
else else
{ {
renderer->RenderQuad(offQuad, mX , mY , 0,mScale,mScale); renderer->RenderQuad(offQuad, mX , mY , 0,mScale,mScale);
} }
updatedSinceLastRender= 0; updatedSinceLastRender= 0;
} }
void MenuItem::Update(float dt) void MenuItem::Update(float dt)
{ {
updatedSinceLastRender = 1; updatedSinceLastRender = 1;
lastDt = dt; lastDt = dt;
if (mScale < mTargetScale) if (mScale < mTargetScale)
{ {
mScale += 8.0f*dt; mScale += 8.0f*dt;
if (mScale > mTargetScale) if (mScale > mTargetScale)
mScale = mTargetScale; mScale = mTargetScale;
} }
else if (mScale > mTargetScale) else if (mScale > mTargetScale)
{ {
mScale -= 8.0f*dt; mScale -= 8.0f*dt;
if (mScale < mTargetScale) if (mScale < mTargetScale)
mScale = mTargetScale; mScale = mTargetScale;
} }
if (mHasFocus){ if (mHasFocus){
mParticleSys->Update(dt); mParticleSys->Update(dt);
} }
} }
@@ -87,27 +87,27 @@ void MenuItem::Update(float dt)
void MenuItem::Entering() void MenuItem::Entering()
{ {
mParticleSys->Fire(); mParticleSys->Fire();
mHasFocus = true; mHasFocus = true;
mTargetScale = 1.3f; mTargetScale = 1.3f;
} }
bool MenuItem::Leaving(u32 key) bool MenuItem::Leaving(u32 key)
{ {
mParticleSys->Stop(true); mParticleSys->Stop(true);
mHasFocus = false; mHasFocus = false;
mTargetScale = 1.0f; mTargetScale = 1.0f;
return true; return true;
} }
bool MenuItem::ButtonPressed() bool MenuItem::ButtonPressed()
{ {
return true; return true;
} }
MenuItem::~MenuItem(){ MenuItem::~MenuItem(){
if (mParticleSys) delete mParticleSys; if (mParticleSys) delete mParticleSys;
} }
+113 -113
View File
@@ -4,117 +4,117 @@
#include "../include/GameOptions.h" #include "../include/GameOptions.h"
OptionItem::OptionItem(int _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){ OptionItem::OptionItem(int _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){
id = _id; id = _id;
maxValue = _maxValue; maxValue = _maxValue;
increment = _increment; increment = _increment;
displayValue = _displayValue; displayValue = _displayValue;
value = GameOptions::GetInstance()->values[id]; value = GameOptions::GetInstance()->values[id];
hasFocus = 0; hasFocus = 0;
x = 0; x = 0;
y = 0; y = 0;
} }
OptionItem::~OptionItem(){ OptionItem::~OptionItem(){
//TODO //TODO
} }
void OptionItem::setData(){ void OptionItem::setData(){
GameOptions::GetInstance()->values[id] = value; GameOptions::GetInstance()->values[id] = value;
} }
void OptionItem::Render(){ void OptionItem::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
if (hasFocus){ if (hasFocus){
mFont->SetColor(ARGB(255,255,255,0)); mFont->SetColor(ARGB(255,255,255,0));
}else{ }else{
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
} }
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
mFont->DrawString(displayValue.c_str(),x,y); mFont->DrawString(displayValue.c_str(),x,y);
char buf[512]; char buf[512];
sprintf(buf, "%i", value); sprintf(buf, "%i", value);
mFont->DrawString(buf,SCREEN_WIDTH -10 ,y,JGETEXT_RIGHT); mFont->DrawString(buf,SCREEN_WIDTH -10 ,y,JGETEXT_RIGHT);
} }
void OptionItem::Update(float dt){ void OptionItem::Update(float dt){
JGE * mEngine = JGE::GetInstance(); JGE * mEngine = JGE::GetInstance();
if (hasFocus){ if (hasFocus){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue(); if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue();
} }
} }
void OptionItem::Entering(){ void OptionItem::Entering(){
hasFocus = true; hasFocus = true;
} }
bool OptionItem::Leaving(){ bool OptionItem::Leaving(){
hasFocus = false; hasFocus = false;
return true; return true;
} }
OptionItem * options[20]; OptionItem * options[20];
int nbitems; int nbitems;
OptionsList::OptionsList(){ OptionsList::OptionsList(){
nbitems = 0; nbitems = 0;
current = -1; current = -1;
} }
OptionsList::~OptionsList(){ OptionsList::~OptionsList(){
for (int i = 0 ; i < nbitems; i++){ for (int i = 0 ; i < nbitems; i++){
SAFE_DELETE(options[i]); SAFE_DELETE(options[i]);
} }
} }
void OptionsList::Add(OptionItem * item){ void OptionsList::Add(OptionItem * item){
if (nbitems < 20){ if (nbitems < 20){
options[nbitems] = item; options[nbitems] = item;
item->x = 10; item->x = 10;
item->y = 20 + 30*nbitems; item->y = 20 + 30*nbitems;
nbitems++; nbitems++;
if (current < 0){ if (current < 0){
current = 0; current = 0;
options[0]->Entering(); options[0]->Entering();
} }
} }
} }
void OptionsList::Render(){ void OptionsList::Render(){
if (!nbitems){ if (!nbitems){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->DrawString("NO OPTIONS AVAILABLE",SCREEN_WIDTH/2, 5, JGETEXT_RIGHT); mFont->DrawString("NO OPTIONS AVAILABLE",SCREEN_WIDTH/2, 5, JGETEXT_RIGHT);
} }
for (int i = 0 ; i < nbitems; i++){ for (int i = 0 ; i < nbitems; i++){
options[i]->Render(); options[i]->Render();
} }
} }
void OptionsList::save(){ void OptionsList::save(){
for (int i = 0; i < nbitems; i++){ for (int i = 0; i < nbitems; i++){
options[i]->setData(); options[i]->setData();
} }
GameOptions::GetInstance()->save(); GameOptions::GetInstance()->save();
} }
void OptionsList::Update(float dt){ void OptionsList::Update(float dt){
JGE * mEngine = JGE::GetInstance(); JGE * mEngine = JGE::GetInstance();
if (mEngine->GetButtonClick(PSP_CTRL_UP)) if (mEngine->GetButtonClick(PSP_CTRL_UP))
{ {
if (current > 0){ if (current > 0){
options[current]->Leaving(); options[current]->Leaving();
current--; current--;
options[current]->Entering(); options[current]->Entering();
} }
} }
else if (mEngine->GetButtonClick(PSP_CTRL_DOWN)) else if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
{ {
if (current < nbitems -1){ if (current < nbitems -1){
options[current]->Leaving(); options[current]->Leaving();
current++; current++;
options[current]->Entering(); options[current]->Entering();
} }
} }
for (int i = 0 ; i < nbitems; i++){ for (int i = 0 ; i < nbitems; i++){
options[i]->Update(dt); options[i]->Update(dt);
} }
} }

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