im forced to do this commit in whole instead of parts as originally planned, and before my beta test period of the changes is complete BECAUSE there are people doing "clean up" and the MASSIVE amount of conflicts i have to resolve from it is WAY too much for me to take on after nearly 200 hours of coding this patch. i cant seem to get enough respect to have people hold off on "clean up" so this brings me to being forced to do a full commit before playtest period is done, so they can go ahead with there *super important* clean up.

ok i WAS going to write a full change log with code exsamples ect, but since im rushed you will get the short version of this log.

first bug fixes, and there were many, 
indestructible creature bug fixed
halimar execavator *embearessing youtube video" bug is fixed

token text now displays source name and tokens abilities

fixed a card view null pointer in an iterator when code used combinations of foreach and aslongas with CD.

epic struggle bug fixed, aslongas was only parsing one space to the right of the operator.

extra cost containing targetting fixed, cards can now have multiple extra cost in all mana...this includes giving a card 2 targeted sacrifices as its main cost.

angelic chorus bug fixed, the card will be soft coded now.

and many other minor bugs fixed, hard to remember all which were fixed.

now, new abilities = words
"legendarylandwalk",
"desertlandwalk",
"snowforestlandwalk",
"snowplainslandwalk",
"snowmountainlandwalk",
"snowislandlandwalk",
"snowswamplandwalk",
"snowlandwalk",
"nonbasiclandwalk",
"strong",//cant be blocked by creature with less power
"weak",//cant block creatures with more power
"phasing",

all true landwalks will now be supported.

new cost types:
morph which is coded as follows
[card]
name=Bloodstoke Howler
facedown={3}
autofacedown={6}{R}:morph
autofaceup=3/0 all(beast|mybattlefield))
text=Morph {6}{R} (You may cast this face down as a 2/2 creature for {3}. Turn it face up any time for its morph cost.) -- When Bloodstoke Howler is turned 
face up, Beast creatures you control get +3/+0 until end of turn.
mana={5}{R}
type=Creature
subtype=Beast
power=3
toughness=4
[/card]

you will notice new auto lines autofaceup and autofacedown
these are abilities the cards will have when theyre in that state.
the cost is coded as
facedown={cost}
when a card is faced up it gains auto= lines also.
tho is played normally it will NOT gain autofaceup=lines

card restrictions:
cards can now have restrictions placed on them the restrictions are.
all previous restrictions usable in activated abilities
with the follow additions
control two or more vampires
control less creatures
control snow land
casted a spell
one of a kind
fourth turn
before battle damage
after battle
during battle

[card]
name=Blood Frenzy
target=creature[attacking;blocking]
restriction=before battle damage
auto=4/0
auto=treason
text=Cast Blood Frenzy only before the combat damage step. -- Target attacking or blocking creature gets +4/+0 until end of turn. Destroy that creature 
at the beginning of the next end step.
mana={1}{R}
type=Instant
[/card]

other cost now can have specail restrictions also:
otherrestriction=mytypemin:1 type(swamp),opponenttypemin:1 opponenttype(plains)
these are minimums required inplay of a type
it can be just you, or you and opponent or just opponent
you can also use the words "more" and "less" and * to compare the 2 players fields.

[card]
name=Cho-Arrim Legate
abilities=protection from black
other={0}
otherrestriction=mytypemin:1 type(swamp) , opponenttypemin:1 opponenttype(plains)
text=Protection from black -- If an opponent controls a Swamp and you control a Plains, you may cast Cho-Arrim Legate without paying its mana cost.
mana={2}{W}
type=Creature
subtype=Human Soldier
power=1
toughness=2
[/card]

activated ability gained a new restriction "opponentturnonly"

variables will now be recalculated during the resolve of the major abilities to produce the most current number.
{x}:draw:x <----
new number variables words:
using draw as an exsample
draw:auras <--auras on a creature

draw:type:ally <---counts the allys in your field. self explanitory

draw:thatmuch <--mostly a triggered effects number.
when you take damage draw that much

draw:lifelost
draw:oplifelost
these return the value of the life lost that turn.

new TRIGGER restricitions
sourcenottap
sourceTap
foelostthree<--card cycle uses opponent lost life
foelosttwo<--same as above
once<--this trigger will only ever trigger one time and never again.

new card discriptor words
[multicolor]
[leveler]
[enchanted]
[blackandgreen]
[blackandwhite]
[redandblue]
[blueandgreen]
[redandwhite]
CD will now recalculate the number again on resolve
meaning {x}:target(CreatureTargetChooser[manacost <=x]) will work, with an added bonus {x}:target(CreatureTargetChooser[manacost <=any word variable])

new this(:
this(tapped)<--for strange case cards.
this(untapped)
this(auras)

new MTGAbility keywords
(blink)
(blink)forsrc <--stay blinked while source inplay
hand(blink <---adding hand to the front makes it target hand.

livingweapon
this is an extension of token, simple attach the words "livingweapon" to the front of token( and it will autoamtically token that and attach the card to it.

token( gained:
"targetcontroller" targetting.
"battleready" if put in the tokens abilities it will be a attacker and tapped as it is entering play.


phaseout <--self explanitory

spiritlink <--stacking lifelink style effect that benifits the OWNER of the card.
combatspiritlink same as above.

stacking flanking, requires 2 abilities unfortunately

[card]
name=Agility
target=creature
auto=teach(creature) flanker
auto=teach(creature) flanking
text=Enchant creature -- Enchanted creature gets +1/+1 and has flanking. (Whenever a creature without flanking blocks this creature, the blocking 
creature gets -1/-1 until end of turn.)
mana={1}{R}
type=Enchantment
subtype=Aura
[/card]

removeallcounters(number/number,name)
removes all counters of the type from a card, can all be
"all"
vampire hexmage effect.

added new tools for transforms
,setpower=number
,settoughness=number
removetypes

morph
autofacedown={0}:morph

eradicate <---same as the card name.

cumulativeupcost[ <--self explanitory

upcostmulti[ <--an upcost that will resolve with a && ability

phaseaction[ phase name ] ability

an ability that will trigger on the stated phase name.
also support for phaseactionmulti[

new triggers added:
@vampired( <--sengir vampire effect
@targeted( 
@lifeloss(
@lifed(

add a special ability builder called dynamicability
it acts alot like a choose your own adventure book

dynamicability<! variable 1, variable 2, variable 3,variable 4!> optional ability targetting the original target.

variable list 1:
this is the primary amount source
source
mytgt
myself
myfoe
variable list 2:
this is the variable we're after, or the amount
power
toughness
manacost
colors
age
charge
oneonecounters
thatmuch
variable list 3:
this is the main effect
strike
draw
lifeloss
lifegain
pumppow
pumptough
pumpboth
deplete
countersoneone
variable list 4:
how it will do this effect to.
itself
eachother
targetcontroller
targetopponent
tosrc
srccontroller
srcopponent

the best way to explain its usage is to look at cards coded with this ability. or experiment with combinations.

new gameoption
First turn player:player, opponent, random
who takes the first turn

added poisoned status, tho not complete since MBS hasnt spoiled enough cards to see where this variable will be used.

taught ai how to counter spell
improved ai, it will now cast instants during interupts and during your turn.
previously ai treated instant cards the same as it treated sorceries, which was not fair to the ai.

im sure there is some messed items, but the rev directly before this one had formatting in the code that created hundreds of conflicts with this one, so i had to dig this info out of red and green sections.

cards and test are coming soon, i ask PLEASE do not alter these new additions until the test are commited.
im commiting without the test because instead of allowing me to proceed with my beta test period, there are some that wish to rush me into a commit. if you do not like this commit revert it, i absolutely on no grounds give permission to recommit afterwards. and i will not recommit if a revert is called.
This commit is contained in:
omegablast2002@yahoo.com
2011-01-21 20:18:56 +00:00
parent b836c97a1b
commit 473abd9814
46 changed files with 6161 additions and 2317 deletions
+39 -54
View File
@@ -18,6 +18,7 @@ using std::queue;
#define INFO_CREATURESTOUGHNESS 3
#define INFO_CREATURESATTACKINGPOWER 4
class AIStats;
class AIAction
@@ -33,26 +34,23 @@ public:
bool checked;
MTGCardInstance * click;
MTGCardInstance * target; // TODO Improve
AIAction(MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL) :
efficiency(-1), ability(a), player(NULL), click(c), target(t)
AIAction(MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
: efficiency(-1), ability(a), player(NULL), click(c), target(t)
{
id = currentId++;
}
;
};
AIAction(MTGCardInstance * c, MTGCardInstance * t = NULL) :
efficiency(-1), ability(NULL), player(NULL), click(c), target(t)
AIAction(MTGCardInstance * c, MTGCardInstance * t = NULL)
: efficiency(-1), ability(NULL), player(NULL), click(c), target(t)
{
id = currentId++;
}
;
AIAction(Player * p) :
efficiency(-1), ability(NULL), player(p), click(NULL), target(NULL)
};
AIAction(Player * p)
: efficiency(-1), ability(NULL), player(p), click(NULL), target(NULL)
{
}
;
};
int getEfficiency();
int Act();
@@ -60,24 +58,22 @@ public:
// compares Abilities efficiency
class CmpAbilities
{
{
public:
bool operator()(const AIAction& a1, const AIAction& a2) const
{
AIAction* a1Ptr = const_cast<AIAction*> (&a1);
AIAction* a2Ptr = const_cast<AIAction*> (&a2);
AIAction* a1Ptr = const_cast<AIAction*>(&a1);
AIAction* a2Ptr = const_cast<AIAction*>(&a2);
int e1 = a1Ptr->getEfficiency();
int e2 = a2Ptr->getEfficiency();
if (e1 == e2)
return a1Ptr->id < a2Ptr->id;
if (e1 == e2) return a1Ptr->id < a2Ptr->id;
return (e1 > e2);
}
};
typedef std::map<AIAction, int, CmpAbilities> RankingContainer;
class AIPlayer: public Player
{
class AIPlayer: public Player{
protected:
//Variables used by Test suite
MTGCardInstance * nextCardToPlay;
@@ -90,40 +86,29 @@ protected:
int chooseBlockers();
int canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy);
int effectBadOrGood(MTGCardInstance * card, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL);
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();
// returns 1 if the AI algorithm supports a given cost (ex:simple mana cost), 0 otherwise (ex: cost involves Sacrificing a target)
int CanHandleCost(ManaCost * cost);
int CanHandleCost(ManaCost * cost);
public:
AIStats * stats;
int agressivity;
bool Checked;
bool forceBestAbilityUse;
void End()
{
}
;
virtual int displayStack()
{
return 0;
}
;
void End(){};
virtual int displayStack() {return 0;};
int receiveEvent(WEvent * event);
void Render();
ManaCost * getPotentialMana(MTGCardInstance * card = NULL);
AIPlayer(MTGDeck * deck, string deckFile, string deckFileSmall);
virtual ~AIPlayer();
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget = NULL);
virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL,MTGCardInstance * Choosencard = NULL);
virtual int Act(float dt);
virtual int affectCombatDamages(CombatStep);
int isAI()
{
return 1;
}
;
int isAI(){return 1;};
int canHandleCost(MTGAbility * ability);
int selectAbility();
int createAbilityTargets(MTGAbility * a, MTGCardInstance * c, RankingContainer& ranking);
@@ -132,24 +117,24 @@ public:
};
class AIPlayerBaka: public AIPlayer
{
protected:
int oldGamePhase;
float timer;
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
public:
int deckId;
AIPlayerBaka(MTGDeck * deck, string deckFile, string deckfileSmall, string avatarFile);
virtual int Act(float dt);
void initTimer();
virtual int computeActions();
class AIPlayerBaka: public AIPlayer{
protected:
int oldGamePhase;
float timer;
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
public:
int deckId;
AIPlayerBaka(MTGDeck * deck, string deckFile, string deckfileSmall, string avatarFile);
virtual int Act(float dt);
void initTimer();
virtual int computeActions();
};
class AIPlayerFactory
{
public:
AIPlayer * createAIPlayer(MTGAllCards * collection, Player * opponent, int deckid = 0);
class AIPlayerFactory{
public:
AIPlayer * createAIPlayer(MTGAllCards * collection, Player * opponent, int deckid = 0);
};
#endif
+140 -164
View File
@@ -9,6 +9,7 @@
#define MAX_SPELL_TARGETS 10
#define ACTION_SPELL 10
#define ACTION_DAMAGE 11
#define ACTION_DAMAGES 12
@@ -38,197 +39,172 @@ class DamageStack;
class ManaCost;
class TargetChooser;
#define ACTIONSTACK_STANDARD 0
#define ACTIONSTACK_TARGET 1
class Interruptible: public PlayGuiObject, public Targetable
{
public:
//TODO : remove these when they are back in PlayGuiObject
float x, y;
class Interruptible: public PlayGuiObject, public Targetable{
public:
//TODO : remove these when they are back in PlayGuiObject
float x, y;
int state, display;
MTGCardInstance * source;
virtual void Entering()
{
mHasFocus = true;
}
;
virtual bool Leaving(JButton key)
{
mHasFocus = false;
return true;
}
;
virtual bool ButtonPressed()
{
return true;
}
;
virtual int resolve()
{
return 0;
}
;
virtual void Render()
{
}
;
int typeAsTarget()
{
return TARGET_STACKACTION;
}
;
Interruptible(bool hasFocus = false) :
PlayGuiObject(40, x, y, hasFocus)
{
state = NOT_RESOLVED;
display = 0;
source = NULL;
}
;
virtual const string getDisplayName() const;
void Render(MTGCardInstance * source, JQuad * targetQuad, string alt1, string alt2, string action, bool bigQuad = false);
virtual int receiveEvent(WEvent * event)
{
return 0;
}
;
int state, display;
MTGCardInstance * source;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(JButton key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual int resolve(){return 0;};
virtual void Render(){};
int typeAsTarget(){return TARGET_STACKACTION;};
Interruptible(bool hasFocus = false):PlayGuiObject(40,x,y,hasFocus){state=NOT_RESOLVED;display=0;source=NULL;};
virtual const string getDisplayName() const;
void Render(MTGCardInstance * source, JQuad * targetQuad, string alt1, string alt2, string action, bool bigQuad = false);
virtual int receiveEvent(WEvent * event) {return 0;};
#if defined (WIN32) || defined (LINUX) || defined (IOS)
virtual void Dump();
virtual void Dump();
#endif
protected:
float GetVerticalTextOffset() const;
float GetVerticalTextOffset() const;
};
class NextGamePhase: public Interruptible
{
public:
int resolve();
bool extraDamagePhase();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
NextGamePhase(int id);
class NextGamePhase: public Interruptible {
public:
int resolve();
bool extraDamagePhase();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
NextGamePhase(int id);
};
class Spell: public Interruptible
{
protected:
class Spell: public Interruptible {
protected:
public:
MTGGameZone * from;
TargetChooser * tc;
ManaCost * cost;
int payResult;
int computeX(MTGCardInstance * card);
int computeXX(MTGCardInstance * card);
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, TargetChooser *_tc, ManaCost * _cost, int payResult);
~Spell();
int resolve();
void Render();
bool FullfilledAlternateCost(const int &costType);
const string getDisplayName() const;
virtual ostream& toString(ostream& out) const;
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous = 0, int type = -1);
int getNbTargets();
public:
MTGGameZone * from;
TargetChooser * tc;
ManaCost * cost;
int payResult;
int computeX(MTGCardInstance * card);
int computeXX(MTGCardInstance * card);
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, TargetChooser *_tc, ManaCost * _cost, int payResult);
~Spell();
int resolve();
void Render();
bool FullfilledAlternateCost(const int &costType);
const string getDisplayName() const;
virtual ostream& toString(ostream& out) const;
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous = 0, int type = -1);
int getNbTargets();
};
class StackAbility: public Interruptible
{
public:
MTGAbility * ability;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
StackAbility(int id, MTGAbility * _ability);
class StackAbility: public Interruptible {
public:
MTGAbility * ability;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
StackAbility(int id, MTGAbility * _ability);
};
class PutInGraveyard: public Interruptible
{
public:
MTGCardInstance * card;
int removeFromGame;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
PutInGraveyard(int id, MTGCardInstance * _card);
class PutInGraveyard: public Interruptible {
public:
MTGCardInstance * card;
int removeFromGame;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
PutInGraveyard(int id, MTGCardInstance * _card);
};
class DrawAction: public Interruptible
{
public:
int nbcards;
Player * player;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
DrawAction(int id, Player * _player, int _nbcards);
class DrawAction: public Interruptible {
public:
int nbcards;
Player * player;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
DrawAction(int id, Player * _player, int _nbcards);
};
class ActionStack: public GuiLayer
{
protected:
JQuad * pspIcons[8];
GameObserver* game;
int interruptDecision[2];
float timer;
int currentState;
int mode;
int checked;
class LifeAction: public Interruptible {
public:
int amount;
Damageable * target;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
LifeAction(int id, Damageable * _target, int amount);
};
public:
class ActionStack :public GuiLayer{
protected:
JQuad * pspIcons[8];
GameObserver* game;
int interruptDecision[2];
float timer;
int currentState;
int mode;
int checked;
enum
{
NOT_DECIDED = 0,
INTERRUPT = -1,
DONT_INTERRUPT = 1,
DONT_INTERRUPT_ALL = 2,
};
public:
int setIsInterrupting(Player * player);
int count(int type = 0, int state = 0, int display = -1);
Interruptible * getPrevious(Interruptible * next, int type = 0, int state = 0, int display = -1);
int getPreviousIndex(Interruptible * next, int type = 0, int state = 0, int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int state = 0, int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state = 0, int display = -1);
void Fizzle(Interruptible * action);
Interruptible * getAt(int id);
void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption();
Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt;
int garbageCollect();
int addAction(Interruptible * interruptible);
Spell * addSpell(MTGCardInstance* card, TargetChooser * tc, ManaCost * mana, int payResult, int storm);
int AddNextGamePhase();
int AddNextCombatStep();
int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability);
void Update(float dt);
bool CheckUserInput(JButton key);
virtual void Render();
ActionStack(GameObserver* game);
int resolve();
int has(Interruptible * action);
int has(MTGAbility * ability);
int receiveEventPlus(WEvent * event);
enum
{
NOT_DECIDED = 0,
INTERRUPT = -1,
DONT_INTERRUPT = 1,
DONT_INTERRUPT_ALL = 2,
};
int setIsInterrupting(Player * player);
int count( int type = 0 , int state = 0 , int display = -1);
Interruptible * getPrevious(Interruptible * next, int type = 0, int state = 0 , int display = -1);
int getPreviousIndex(Interruptible * next, int type = 0, int state = 0 , int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
void Fizzle(Interruptible * action);
Interruptible * getAt(int id);
void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption();
Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt;
int garbageCollect();
int addAction(Interruptible * interruptible);
Spell * addSpell(MTGCardInstance* card, TargetChooser * tc, ManaCost * mana, int payResult, int storm);
int AddNextGamePhase();
int AddNextCombatStep();
int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1);
int addLife(Damageable * _target,int amount = 0);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability);
void Update(float dt);
bool CheckUserInput(JButton key);
virtual void Render();
ActionStack(GameObserver* game);
int resolve();
int has(Interruptible * action);
int has(MTGAbility * ability);
int receiveEventPlus(WEvent * event);
#if defined (WIN32) || defined (LINUX) || defined (IOS)
void Dump();
void Dump();
#endif
};
#endif
File diff suppressed because it is too large Load Diff
+37 -31
View File
@@ -1,6 +1,6 @@
/*
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_
#define _CARDDESCRIPTOR_H_
@@ -13,42 +13,48 @@
#define CD_AND 2
enum ENUM_COMPARISON_MODES
{
COMPARISON_NONE = 0, // Needs to remain 0 for quick if(comparison_mode) checks
{
COMPARISON_NONE = 0, // Needs to remain 0 for quick if(comparison_mode) checks
COMPARISON_AT_MOST,
COMPARISON_AT_LEAST,
COMPARISON_EQUAL,
COMPARISON_GREATER,
COMPARISON_LESS,
COMPARISON_UNEQUAL
};
};
class CardDescriptor: public MTGCardInstance
{
protected:
MTGCardInstance * match_or(MTGCardInstance * card);
MTGCardInstance * match_and(MTGCardInstance * card);
bool valueInRange(int comparisonMode, int value, int criterion);
public:
int mode;
int powerComparisonMode;
int toughnessComparisonMode;
int manacostComparisonMode;
int counterComparisonMode;
int convertedManacost; // might fit better into MTGCardInstance?
int anyCounter;
int init();
CardDescriptor();
void unsecureSetTapped(int i);
void unsecuresetfresh(int k);
void setNegativeSubtype(string value);
int counterPower;
int counterToughness;
int counterNB;
string counterName;
MTGCardInstance * match(MTGCardInstance * card);
MTGCardInstance * match(MTGGameZone * zone);
MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous);
class CardDescriptor: public MTGCardInstance{
protected:
MTGCardInstance * match_or(MTGCardInstance * card);
MTGCardInstance * match_and(MTGCardInstance * card);
bool valueInRange(int comparisonMode, int value, int criterion);
public:
int mode;
int powerComparisonMode;
int toughnessComparisonMode;
int manacostComparisonMode;
int counterComparisonMode;
int convertedManacost; // might fit better into MTGCardInstance?
int anyCounter;
int init();
CardDescriptor();
void unsecureSetTapped(int i);
void unsecuresetfresh(int k);
void setisMultiColored(int w);
void setisBlackAndWhite(int w);
void setisRedAndBlue(int w);
void setisBlackAndGreen(int w);
void setisBlueAndGreen(int w);
void setisRedAndWhite(int w);
void setNegativeSubtype( string value);
int counterPower;
int counterToughness;
int counterNB;
string counterName;
MTGCardInstance * match(MTGCardInstance * card);
MTGCardInstance * match(MTGGameZone * zone);
MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous);
};
#endif
+129 -56
View File
@@ -1,6 +1,7 @@
#ifndef _CARDPRIMITIVE_H_
#define _CARDPRIMITIVE_H_
#include <string>
#include <vector>
#include <map>
@@ -9,72 +10,144 @@
using namespace std;
class CardPrimitive
{
protected:
vector<string> ftdText;
string lcname;
ManaCost manaCost;
class CardPrimitive {
protected:
vector<string> ftdText;
string lcname;
ManaCost manaCost;
public:
string text;
string name;
int init();
public:
enum {
NO_RESTRICTION = 0,
PLAYER_TURN_ONLY = 1,
AS_SORCERY = 2,
MY_BEFORE_BEGIN = 3,
MY_UNTAP = 4,
MY_UPKEEP = 5,
MY_DRAW = 6,
MY_FIRSTMAIN = 7,
MY_COMBATBEGIN = 8,
MY_COMBATATTACKERS = 9,
MY_COMBATBLOCKERS = 10,
MY_COMBATDAMAGE = 11,
MY_COMBATEND = 12,
MY_SECONDMAIN = 13,
MY_ENDOFTURN = 14,
MY_EOT = 15,
MY_CLEANUP = 16,
MY_AFTER_EOT = 17,
int colors[Constants::MTG_NB_COLORS];
map<int, int> basicAbilities;
map<string, string> magicTexts;
string magicText;
int alias;
string spellTargetType;
int power;
int toughness;
vector<int> types;
CardPrimitive();
CardPrimitive(CardPrimitive * source);
OPPONENT_BEFORE_BEGIN = 23,
OPPONENT_UNTAP = 24,
OPPONENT_UPKEEP = 25,
OPPONENT_DRAW = 26,
OPPONENT_FIRSTMAIN = 27,
OPPONENT_COMBATBEGIN = 28,
OPPONENT_COMBATATTACKERS = 29,
OPPONENT_COMBATBLOCKERS = 30,
OPPONENT_COMBATDAMAGE = 31,
OPPONENT_COMBATEND = 32,
OPPONENT_SECONDMAIN = 33,
OPPONENT_ENDOFTURN = 34,
OPPONENT_EOT = 35,
OPPONENT_CLEANUP = 36,
OPPONENT_AFTER_EOT = 37,
void setColor(int _color, int removeAllOthers = 0);
void setColor(string _color, int removeAllOthers = 0);
void removeColor(int color);
int getColor();
int hasColor(int _color);
int countColors();
BEFORE_BEGIN = 43,
UNTAP = 44,
UPKEEP = 45,
DRAW = 46,
FIRSTMAIN = 47,
COMBATBEGIN = 48,
COMBATATTACKERS = 49,
COMBATBLOCKERS = 50,
COMBATDAMAGE = 51,
COMBATEND = 52,
SECONDMAIN = 53,
ENDOFTURN = 54,
EOT = 55,
CLEANUP = 56,
AFTER_EOT = 57,
VAMPIRES = 60,
LESS_CREATURES = 61,
SNOW_LAND_INPLAY =62,
CASTED_A_SPELL = 63,
ONE_OF_AKIND = 64,
FOURTHTURN = 65,
BEFORECOMBATDAMAGE = 66,
AFTERCOMBAT = 67,
DURINGCOMBAT = 68,
OPPONENT_TURN_ONLY = 69,
};
string text;
string name;
int init();
int has(int ability);
int colors[Constants::MTG_NB_COLORS];
map<int,int> basicAbilities;
map<string,string> magicTexts;
string magicText;
int alias;
string spellTargetType;
int power;
int toughness;
bool hasRestriction;
int restriction;
string otherrestriction;
void setText(const string& value);
const char * getText();
vector<int>types;
CardPrimitive();
CardPrimitive(CardPrimitive * source);
void addMagicText(string value);
void addMagicText(string value, string zone);
void setColor(int _color, int removeAllOthers = 0);
void setColor(string _color, int removeAllOthers = 0);
void removeColor(int color);
int getColor();
int hasColor(int _color);
int countColors();
void setName(const string& value);
const string& getName() const;
const string& getLCName() const;
int has(int ability);
void addType(char * type_text);
void addType(int id);
void setType(const string& type_text);
void setSubtype(const string& value);
int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0);
bool hasSubtype(int _subtype);
bool hasSubtype(const char * _subtype);
bool hasSubtype(string _subtype);
bool hasType(int _type);
bool hasType(const char * type);
void setText(const string& value);
const char * getText();
void setManaCost(string value);
ManaCost * getManaCost();
bool isCreature();
bool isLand();
bool isSpell();
void addMagicText(string value);
void addMagicText(string value, string zone);
void setPower(int _power);
int getPower();
void setToughness(int _toughness);
int getToughness();
const vector<string>& formattedText();
void setName(const string& value);
const string& getName() const;
const string& getLCName() const;
void addType(char * type_text);
void addType(int id);
void setType(const string& type_text);
void setSubtype(const string& value);
int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0);
bool hasSubtype(int _subtype);
bool hasSubtype(const char * _subtype);
bool hasSubtype(string _subtype);
bool hasType(int _type);
bool hasType(const char * type);
void setManaCost(string value);
ManaCost * getManaCost();
bool isCreature();
bool isLand();
bool isSpell();
void setPower(int _power);
int getPower();
void setToughness(int _toughness);
int getToughness();
void setRestrictions(int _restriction);
int getRestrictions();
void setOtherRestrictions(string _restriction);
void getOtherRestrictions();
const vector<string>& formattedText();
};
#endif
+33 -59
View File
@@ -17,77 +17,51 @@ class GameObserver;
#define DAMAGE_COMBAT 1
#define DAMAGE_OTHER 2
class Damageable: public Targetable
{
class Damageable:public Targetable {
protected:
public:
int life;
int poisonCount;
int damageCount;
int preventable;
int thatmuch;
int lifeLostThisTurn;
int type_as_damageable;
Damageable(int _life)
{
life = _life;
}
;
int getLife()
{
return life;
}
;
virtual int dealDamage(int damage)
{
life -= damage;
return life;
}
;
virtual int afterDamage()
{
return 0;
}
virtual int poisoned()
{
return 0;
}
virtual int prevented()
{
return 0;
}
virtual JQuad * getIcon()
{
return NULL;
}
;
Damageable(int _life){life=_life;lifeLostThisTurn = 0;};
int getLife(){return life;};
virtual int dealDamage(int damage){life-=damage;return life;};
virtual int afterDamage(){return 0;}
virtual int poisoned(){return 0;}
virtual int prevented(){return 0;}
virtual JQuad * getIcon(){return NULL;};
};
class Damage: public Interruptible
{
protected:
void init(MTGCardInstance * source, Damageable * target, int damage, int typeOfDamage);
public:
Damageable * target;
int typeOfDamage;
int damage;
void Render();
Damage(MTGCardInstance* source, Damageable * target);
Damage(MTGCardInstance* source, Damageable * target, int damage, int typeOfDamage = DAMAGE_OTHER);
int resolve();
virtual ostream& toString(ostream& out) const;
class Damage: public Interruptible {
protected:
void init(MTGCardInstance * source, Damageable * target, int damage, int typeOfDamage);
public:
Damageable * target;
int typeOfDamage;
int damage;
void Render();
Damage(MTGCardInstance* source, Damageable * target);
Damage(MTGCardInstance* source, Damageable * target, int damage, int typeOfDamage = DAMAGE_OTHER);
int resolve();
virtual ostream& toString(ostream& out) const;
};
class DamageStack: public GuiLayer, public Interruptible
{
protected:
int currentState;
GameObserver* game;
public:
int receiveEvent(WEvent * event);
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
DamageStack();
class DamageStack : public GuiLayer, public Interruptible{
protected:
int currentState;
GameObserver* game;
public:
int receiveEvent(WEvent * event);
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
DamageStack();
};
#endif
+84 -102
View File
@@ -9,163 +9,145 @@ class TargetChooser;
class MTGCardInstance;
class MTGAbility;
class ExtraCost
{
class ExtraCost{
public:
TargetChooser * tc;
MTGCardInstance * source;
MTGCardInstance * target;
std::string mCostRenderString;
TargetChooser * tc;
MTGCardInstance * source;
MTGCardInstance * target;
MTGCardInstance * targets[20];
std::string mCostRenderString;
ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc = NULL);
virtual ~ExtraCost();
virtual int setPayment(MTGCardInstance * card);
virtual int isPaymentSet()
{
return (target != NULL);
}
virtual int canPay()
{
return 1;
}
virtual int doPay() = 0;
virtual void Render();
virtual int setSource(MTGCardInstance * _source);
virtual ExtraCost* clone() const = 0;
ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc = NULL);
virtual ~ExtraCost();
virtual int setPayment(MTGCardInstance * card);
virtual int isPaymentSet() { return (target != NULL && targets != NULL); }
virtual int canPay() { return 1; }
virtual int doPay() = 0;
virtual void Render();
virtual int setSource(MTGCardInstance * _source);
virtual ExtraCost* clone() const = 0;
};
class ExtraCosts
{
class ExtraCosts{
public:
vector<ExtraCost *> costs;
MTGCardInstance * source;
MTGAbility * action;
ExtraCosts();
~ExtraCosts();
void Render();
int tryToSetPayment(MTGCardInstance * card);
int isPaymentSet();
int canPay();
int doPay();
int reset();
int setAction(MTGAbility * _action, MTGCardInstance * _source);
void Dump();
ExtraCosts * clone() const;
vector<ExtraCost *>costs;
MTGCardInstance * source;
MTGAbility * action;
ExtraCosts();
~ExtraCosts();
void Render();
int tryToSetPayment(MTGCardInstance * card);
int isPaymentSet();
int canPay();
int doPay();
int reset();
int setAction(MTGAbility * _action, MTGCardInstance * _source);
void Dump();
ExtraCosts * clone() const;
};
class SacrificeCost: public ExtraCost
{
class SacrificeCost: public ExtraCost{
public:
SacrificeCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual SacrificeCost * clone() const;
SacrificeCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual SacrificeCost * clone() const;
};
//life cost
class LifeCost: public ExtraCost
{
class LifeCost: public ExtraCost{
public:
LifeCost(TargetChooser *_tc = NULL);
LifeCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual LifeCost * clone() const;
virtual int doPay();
virtual LifeCost * clone() const;
};
//Discard a random card cost
class DiscardRandomCost: public ExtraCost
{
class DiscardRandomCost: public ExtraCost{
public:
DiscardRandomCost(TargetChooser *_tc = NULL);
virtual int canPay();
virtual int doPay();
virtual DiscardRandomCost * clone() const;
DiscardRandomCost(TargetChooser *_tc = NULL);
virtual int canPay();
virtual int doPay();
virtual DiscardRandomCost * clone() const;
};
//a choosen discard
class DiscardCost: public ExtraCost
{
class DiscardCost: public ExtraCost{
public:
DiscardCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual DiscardCost * clone() const;
DiscardCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual DiscardCost * clone() const;
};
//tolibrary cost
class ToLibraryCost: public ExtraCost
{
class ToLibraryCost: public ExtraCost{
public:
ToLibraryCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual ToLibraryCost * clone() const;
ToLibraryCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual ToLibraryCost * clone() const;
};
//Millyourself cost
class MillCost: public ExtraCost
{
class MillCost: public ExtraCost{
public:
MillCost(TargetChooser *_tc = NULL);
virtual int canPay();
virtual int doPay();
virtual MillCost * clone() const;
MillCost(TargetChooser *_tc = NULL);
virtual int canPay();
virtual int doPay();
virtual MillCost * clone() const;
};
//Mill to exile yourself cost
class MillExileCost: public MillCost
{
class MillExileCost: public MillCost{
public:
MillExileCost(TargetChooser *_tc = NULL);
virtual int doPay();
MillExileCost(TargetChooser *_tc = NULL);
virtual int doPay();
};
//tap other cost
class TapTargetCost: public ExtraCost
{
class TapTargetCost: public ExtraCost{
public:
TapTargetCost(TargetChooser *_tc = NULL);
virtual int isPaymentSet();
virtual int doPay();
virtual TapTargetCost * clone() const;
};
//exile as cost
class ExileTargetCost: public ExtraCost
{
class ExileTargetCost: public ExtraCost{
public:
ExileTargetCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual ExileTargetCost * clone() const;
ExileTargetCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual ExileTargetCost * clone() const;
};
//bounce cost
class BounceTargetCost: public ExtraCost
{
class BounceTargetCost: public ExtraCost{
public:
BounceTargetCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual BounceTargetCost * clone() const;
BounceTargetCost(TargetChooser *_tc = NULL);
virtual int doPay();
virtual BounceTargetCost * clone() const;
};
//bounce cost
class Ninja: public ExtraCost
{
class Ninja: public ExtraCost{
public:
Ninja(TargetChooser *_tc = NULL);
virtual int isPaymentSet();
virtual int doPay();
virtual Ninja * clone() const;
Ninja(TargetChooser *_tc = NULL);
virtual int isPaymentSet();
virtual int doPay();
virtual Ninja * clone() const;
};
class CounterCost: public ExtraCost
{
class CounterCost: public ExtraCost{
public:
Counter * counter;
int hasCounters;
CounterCost(Counter * _counter, TargetChooser *_tc = NULL);
~CounterCost();
virtual int setPayment(MTGCardInstance * card);
virtual int isPaymentSet();
virtual int canPay();
virtual int doPay();
virtual CounterCost * clone() const;
Counter * counter;
int hasCounters;
CounterCost(Counter * _counter,TargetChooser *_tc = NULL);
~CounterCost();
virtual int setPayment(MTGCardInstance * card);
virtual int isPaymentSet();
virtual int canPay();
virtual int doPay();
virtual CounterCost * clone() const;
};
#endif
+60 -59
View File
@@ -22,70 +22,71 @@ class TargetChooser;
class Rules;
using namespace std;
class GameObserver
{
protected:
static GameObserver * mInstance;
MTGCardInstance * cardWaitingForTargets;
queue<WEvent *> eventsQueue;
class GameObserver{
protected:
static GameObserver * mInstance;
MTGCardInstance * cardWaitingForTargets;
queue<WEvent *> eventsQueue;
int nbPlayers;
int untap(MTGCardInstance * card);
bool WaitForExtraPayment(MTGCardInstance* card);
int nbPlayers;
int untap(MTGCardInstance * card);
bool WaitForExtraPayment(MTGCardInstance* card);
public:
int currentPlayerId;
CombatStep combatStep;
int turn;
int forceShuffleLibraries();
int targetListIsSet(MTGCardInstance * card);
PhaseRing * phaseRing;
int cancelCurrentAction();
int currentGamePhase;
ExtraCosts * mExtraPayment;
int oldGamePhase;
TargetChooser * targetChooser;
DuelLayers * mLayers;
ReplacementEffects *replacementEffects;
Player * gameOver;
Player * players[2]; //created outside
time_t startedAt;
Rules * mRules;
public:
int currentPlayerId;
CombatStep combatStep;
int turn;
int forceShuffleLibraries();
int targetListIsSet(MTGCardInstance * card);
PhaseRing * phaseRing;
int cancelCurrentAction();
int currentGamePhase;
ExtraCosts * mExtraPayment;
int oldGamePhase;
TargetChooser * targetChooser;
DuelLayers * mLayers;
ReplacementEffects *replacementEffects;
Player * gameOver;
Player * players[2]; //created outside
time_t startedAt;
Rules * mRules;
TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action);
TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action);
int cardClick(MTGCardInstance * card, Targetable * _object = NULL);
int getCurrentGamePhase();
void nextCombatStep();
void userRequestNextGamePhase();
void nextGamePhase();
void cleanupPhase();
void nextPlayer();
static void Init(Player * _players[], int _nbplayers);
static GameObserver * GetInstance();
static void EndInstance();
Player * currentPlayer;
Player * currentActionPlayer;
Player * isInterrupting;
Player * opponent();
Player * currentlyActing();
GameObserver(Player * _players[], int _nbplayers);
~GameObserver();
void gameStateBasedEffects();
void eventOccured();
void addObserver(MTGAbility * observer);
void removeObserver(ActionElement * observer);
void startGame(Rules * rules);
void untapPhase();
void draw();
int isInPlay(MTGCardInstance * card);
int cardClick(MTGCardInstance * card,Targetable * _object = NULL );
int getCurrentGamePhase();
void nextCombatStep();
void userRequestNextGamePhase();
void nextGamePhase();
void cleanupPhase();
void nextPlayer();
static void Init(Player * _players[], int _nbplayers);
static GameObserver * GetInstance();
static void EndInstance();
Player * currentPlayer;
Player * currentActionPlayer;
Player * isInterrupting;
Player * opponent();
Player * currentlyActing();
GameObserver(Player * _players[], int _nbplayers);
~GameObserver();
void gameStateBasedEffects();
void enchantmentStatus();
void eventOccured();
void addObserver(MTGAbility * observer);
void removeObserver(ActionElement * observer);
void startGame(Rules * rules);
void untapPhase();
void draw();
int isInPlay(MTGCardInstance * card);
int isInGrave(MTGCardInstance * card);
int isInExile(MTGCardInstance * card);
void Update(float dt);
void Render();
void ButtonPressed(PlayGuiObject*);
void Update(float dt);
void Render();
void ButtonPressed(PlayGuiObject*);
int receiveEvent(WEvent * event);
int receiveEvent(WEvent * event);
};
#endif
+202 -281
View File
@@ -23,339 +23,260 @@ class WStyle;
class StyleManager;
class Player;
class Options
{
class Options {
public:
friend class GameSettings;
enum
{
//Global settings
ACTIVE_PROFILE,
LANG,
LAST_GLOBAL = LANG, //This must be the value above, to keep ordering.
//Values /must/ match ordering in optionNames, or everything loads wrong.
//Profile settings
ACTIVE_THEME,
ACTIVE_MODE,
MUSICVOLUME,
SFXVOLUME,
DIFFICULTY,
CHEATMODE,
OPTIMIZE_HAND,
CHEATMODEAIDECK,
OSD,
CLOSEDHAND,
HANDDIRECTION,
MANADISPLAY,
REVERSETRIGGERS,
DISABLECARDS,
MAX_GRADE,
ASPHASES,
ECON_DIFFICULTY,
TRANSITIONS,
GUI_STYLE,
INTERRUPT_SECONDS,
KEY_BINDINGS,
AIDECKS_UNLOCKED,
//My interrupts
INTERRUPTMYSPELLS,
INTERRUPTMYABILITIES,
//Other interrupts
INTERRUPT_BEFOREBEGIN,
INTERRUPT_UNTAP,
INTERRUPT_UPKEEP,
INTERRUPT_DRAW,
INTERRUPT_FIRSTMAIN,
INTERRUPT_BEGINCOMBAT,
INTERRUPT_ATTACKERS,
INTERRUPT_BLOCKERS,
INTERRUPT_DAMAGE,
INTERRUPT_ENDCOMBAT,
INTERRUPT_SECONDMAIN,
INTERRUPT_ENDTURN,
INTERRUPT_CLEANUP,
INTERRUPT_AFTEREND,
BEGIN_AWARDS, //Options after this use the GameOptionAward struct, which includes a timestamp.
DIFFICULTY_MODE_UNLOCKED = BEGIN_AWARDS,
MOMIR_MODE_UNLOCKED,
EVILTWIN_MODE_UNLOCKED,
RANDOMDECK_MODE_UNLOCKED,
AWARD_COLLECTOR,
LAST_NAMED, //Any option after this does not look up in optionNames.
SET_UNLOCKS = LAST_NAMED + 1,
//For sets.
friend class GameSettings;
enum {
//Global settings
ACTIVE_PROFILE,
LANG,
LAST_GLOBAL = LANG, //This must be the value above, to keep ordering.
//Values /must/ match ordering in optionNames, or everything loads wrong.
//Profile settings
ACTIVE_THEME,
ACTIVE_MODE,
MUSICVOLUME,
SFXVOLUME,
DIFFICULTY,
CHEATMODE,
OPTIMIZE_HAND,
CHEATMODEAIDECK,
OSD,
CLOSEDHAND,
HANDDIRECTION,
MANADISPLAY,
REVERSETRIGGERS,
DISABLECARDS,
MAX_GRADE,
ASPHASES,
FIRSTPLAYER,
ECON_DIFFICULTY,
TRANSITIONS,
GUI_STYLE,
INTERRUPT_SECONDS,
KEY_BINDINGS,
AIDECKS_UNLOCKED,
//My interrupts
INTERRUPTMYSPELLS,
INTERRUPTMYABILITIES,
//Other interrupts
INTERRUPT_BEFOREBEGIN,
INTERRUPT_UNTAP,
INTERRUPT_UPKEEP,
INTERRUPT_DRAW,
INTERRUPT_FIRSTMAIN,
INTERRUPT_BEGINCOMBAT,
INTERRUPT_ATTACKERS,
INTERRUPT_BLOCKERS,
INTERRUPT_DAMAGE,
INTERRUPT_ENDCOMBAT,
INTERRUPT_SECONDMAIN,
INTERRUPT_ENDTURN,
INTERRUPT_CLEANUP,
INTERRUPT_AFTEREND,
BEGIN_AWARDS, //Options after this use the GameOptionAward struct, which includes a timestamp.
DIFFICULTY_MODE_UNLOCKED = BEGIN_AWARDS,
MOMIR_MODE_UNLOCKED,
EVILTWIN_MODE_UNLOCKED,
RANDOMDECK_MODE_UNLOCKED,
AWARD_COLLECTOR,
LAST_NAMED, //Any option after this does not look up in optionNames.
SET_UNLOCKS = LAST_NAMED + 1, //For sets.
};
};
static int optionSet(int setID);
static int optionInterrupt(int gamePhase);
static int optionSet(int setID);
static int optionInterrupt(int gamePhase);
static int getID(string name);
static string getName(int option);
static int getID(string name);
static string getName(int option);
private:
static const string optionNames[];
static const string optionNames[];
};
class GameOption
{
class GameOption {
public:
virtual ~GameOption()
{
}
;
int number;
string str;
//All calls to asColor should include a fallback color for people without a theme.
PIXEL_TYPE asColor(PIXEL_TYPE fallback = ARGB(255,255,255,255));
virtual ~GameOption() {};
int number;
string str;
//All calls to asColor should include a fallback color for people without a theme.
PIXEL_TYPE asColor(PIXEL_TYPE fallback = ARGB(255,255,255,255));
virtual bool isDefault(); //Returns true when number is 0 and string is "" or "Default"
virtual string menuStr(); //The string we'll use for GameStateOptions.
virtual bool write(std::ofstream * file, string name);
virtual bool read(string input);
virtual bool isDefault(); //Returns true when number is 0 and string is "" or "Default"
virtual string menuStr(); //The string we'll use for GameStateOptions.
virtual bool write(std::ofstream * file, string name);
virtual bool read(string input);
GameOption(int value = 0);
GameOption(string);
GameOption(int, string);
GameOption(int value = 0);
GameOption(string);
GameOption(int, string);
};
struct EnumDefinition
{
int findIndex(int value);
struct EnumDefinition {
int findIndex(int value);
typedef pair<int, string> assoc;
vector<assoc> values;
typedef pair<int, string> assoc;
vector<assoc> values;
};
class GameOptionEnum: public GameOption
{
class GameOptionEnum: public GameOption {
public:
virtual string menuStr();
virtual bool write(std::ofstream * file, string name);
virtual bool read(string input);
EnumDefinition * def;
virtual string menuStr();
virtual bool write(std::ofstream * file, string name);
virtual bool read(string input);
EnumDefinition * def;
};
class GameOptionAward: public GameOption
{
class GameOptionAward: public GameOption {
public:
GameOptionAward();
virtual string menuStr();
virtual bool write(std::ofstream * file, string name);
virtual bool read(string input);
virtual bool giveAward(); //Returns false if already awarded
virtual bool isViewed();
virtual void setViewed(bool v = true)
{
viewed = v;
}
;
GameOptionAward();
virtual string menuStr();
virtual bool write(std::ofstream * file, string name);
virtual bool read(string input);
virtual bool giveAward(); //Returns false if already awarded
virtual bool isViewed();
virtual void setViewed(bool v = true) {viewed = v;};
private:
time_t achieved; //When was it awarded?
bool viewed; //Flag it as "New!" or not.
time_t achieved; //When was it awarded?
bool viewed; //Flag it as "New!" or not.
};
class GameOptionKeyBindings: public GameOption
{
virtual bool read(string input);
virtual bool write(std::ofstream*, string);
class GameOptionKeyBindings : public GameOption {
virtual bool read(string input);
virtual bool write(std::ofstream*, string);
};
class OptionVolume: public EnumDefinition
{
class OptionVolume: public EnumDefinition{
public:
enum
{
MUTE = 0, MAX = 100
};
static EnumDefinition * getInstance()
{
return &mDef;
}
;
enum { MUTE = 0, MAX = 100 };
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionVolume();
static OptionVolume mDef;
OptionVolume();
static OptionVolume mDef;
};
class OptionClosedHand: public EnumDefinition
{
class OptionClosedHand: public EnumDefinition {
public:
enum
{
INVISIBLE = 0, VISIBLE = 1
};
static EnumDefinition * getInstance()
{
return &mDef;
}
;
private:
OptionClosedHand();
static OptionClosedHand mDef;
enum { INVISIBLE = 0, VISIBLE = 1 };
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionClosedHand();
static OptionClosedHand mDef;
};
class OptionHandDirection: public EnumDefinition
{
class OptionHandDirection: public EnumDefinition {
public:
enum
{
VERTICAL = 0, HORIZONTAL = 1
};
static EnumDefinition * getInstance()
{
return &mDef;
}
;
enum { VERTICAL = 0, HORIZONTAL = 1};
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionHandDirection();
static OptionHandDirection mDef;
OptionHandDirection();
static OptionHandDirection mDef;
};
class OptionManaDisplay: public EnumDefinition
{
class OptionManaDisplay: public EnumDefinition {
public:
enum
{
DYNAMIC = 0, STATIC = 1, NOSTARSDYNAMIC = 2, BOTH = 3
};
static EnumDefinition * getInstance()
{
return &mDef;
}
;
enum { DYNAMIC = 0, STATIC = 1, NOSTARSDYNAMIC = 2, BOTH = 3};
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionManaDisplay();
static OptionManaDisplay mDef;
OptionManaDisplay();
static OptionManaDisplay mDef;
};
class OptionMaxGrade: public EnumDefinition
{
class OptionMaxGrade: public EnumDefinition {
public:
static EnumDefinition * getInstance()
{
return &mDef;
}
;
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionMaxGrade();
static OptionMaxGrade mDef;
OptionMaxGrade();
static OptionMaxGrade mDef;
};
class OptionASkipPhase: public EnumDefinition
{
class OptionASkipPhase: public EnumDefinition {
public:
static EnumDefinition * getInstance()
{
return &mDef;
}
;
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionASkipPhase();
static OptionASkipPhase mDef;
OptionASkipPhase();
static OptionASkipPhase mDef;
};
class OptionEconDifficulty: public EnumDefinition
{
class OptionWhosFirst: public EnumDefinition {
public:
static EnumDefinition * getInstance()
{
return &mDef;
}
;
enum { WHO_P = 0, WHO_O = 1, WHO_R = 2};
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionEconDifficulty();
static OptionEconDifficulty mDef;
OptionWhosFirst();
static OptionWhosFirst mDef;
};
class OptionDifficulty: public EnumDefinition
{
class OptionEconDifficulty: public EnumDefinition {
public:
enum
{
NORMAL = 0, HARD = 1, HARDER = 2, EVIL = 3
};
static EnumDefinition * getInstance()
{
return &mDef;
}
;
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionDifficulty();
static OptionDifficulty mDef;
OptionEconDifficulty();
static OptionEconDifficulty mDef;
};
class OptionDifficulty: public EnumDefinition {
public:
enum { NORMAL = 0, HARD = 1, HARDER = 2, EVIL = 3};
static EnumDefinition * getInstance() {return &mDef;};
private:
OptionDifficulty();
static OptionDifficulty mDef;
};
class GameOptions
{
public:
string mFilename;
int save();
int load();
class GameOptions {
public:
string mFilename;
int save();
int load();
GameOption * get(int);
GameOption& operator[](int);
GameOptions(string filename);
~GameOptions();
GameOption * get(int);
GameOption& operator[](int);
GameOptions(string filename);
~GameOptions();
private:
vector<GameOption*> values;
vector<string> unknown;
};
class GameSettings{
public:
friend class GameApp;
GameSettings();
~GameSettings();
int save();
SimplePad * keypadStart(string input, string * _dest = NULL, bool _cancel=true, bool _numpad=false, int _x = SCREEN_WIDTH/2, int _y = SCREEN_HEIGHT/2);
string keypadFinish();
void keypadShutdown();
void keypadTitle(string set);
bool keypadActive() {if(keypad) return keypad->isActive(); return false;};
void keypadUpdate(float dt) {if(keypad) keypad->Update(dt);};
void keypadRender() {if(keypad) keypad->Render();};
bool newAward();
//These return a filepath accurate to the current mode/profile/theme, and can
//optionally fallback to a file within a certain directory.
//The sanity=false option returns the adjusted path even if the file doesn't exist.
string profileFile(string filename="", string fallback="", bool sanity=false,bool relative=false);
void reloadProfile(); //Reloads profile using current options[ACTIVE_PROFILE]
void checkProfile(); //Confirms that a profile is loaded and contains a collection.
void createUsersFirstDeck(int setId);
GameOption * get(int);
GameOption& operator[](int);
GameOptions* profileOptions;
GameOptions* globalOptions;
static GameOption invalid_option;
WStyle * getStyle();
StyleManager * getStyleMan();
void automaticStyle(Player * p1, Player * p2);
private:
vector<GameOption*> values;
vector<string> unknown;
};
class GameSettings
{
public:
friend class GameApp;
GameSettings();
~GameSettings();
int save();
SimplePad * keypadStart(string input, string * _dest = NULL, bool _cancel = true, bool _numpad = false, int _x = SCREEN_WIDTH
/ 2, int _y = SCREEN_HEIGHT / 2);
string keypadFinish();
void keypadShutdown();
void keypadTitle(string set);
bool keypadActive()
{
if (keypad)
return keypad->isActive();
return false;
}
;
void keypadUpdate(float dt)
{
if (keypad)
keypad->Update(dt);
}
;
void keypadRender()
{
if (keypad)
keypad->Render();
}
;
bool newAward();
//These return a filepath accurate to the current mode/profile/theme, and can
//optionally fallback to a file within a certain directory.
//The sanity=false option returns the adjusted path even if the file doesn't exist.
string profileFile(string filename = "", string fallback = "", bool sanity = false, bool relative = false);
void reloadProfile(); //Reloads profile using current options[ACTIVE_PROFILE]
void checkProfile(); //Confirms that a profile is loaded and contains a collection.
void createUsersFirstDeck(int setId);
GameOption * get(int);
GameOption& operator[](int);
GameOptions* profileOptions;
GameOptions* globalOptions;
static GameOption invalid_option;
WStyle * getStyle();
StyleManager * getStyleMan();
void automaticStyle(Player * p1, Player * p2);
private:
GameApp * theGame;
SimplePad * keypad;
StyleManager * styleMan;
GameApp * theGame;
SimplePad * keypad;
StyleManager * styleMan;
};
extern GameSettings options;
+343 -328
View File
@@ -1,6 +1,8 @@
#ifndef _MTGABILITY_H_
#define _MTGABILITY_H_
class MTGCardInstance;
class Spell;
class Damageable;
@@ -22,6 +24,7 @@ class Counter;
using std::string;
using std::map;
//stupid variables used to give a hint to the AI:
// Should I cast a spell on an enemy or friendly unit ?
#define BAKA_EFFECT_GOOD 1
@@ -37,374 +40,386 @@ using std::map;
#define PARSER_FOREACH 2
#define PARSER_ASLONGAS 3
class MTGAbility: public ActionElement
{
protected:
char menuText[50];
class MTGAbility: public ActionElement{
protected:
char menuText[50];
GameObserver * game;
public:
enum {
NO_RESTRICTION = 0,
PLAYER_TURN_ONLY = 1,
AS_SORCERY = 2,
MY_BEFORE_BEGIN = 3,
MY_UNTAP = 4,
MY_UPKEEP = 5,
MY_DRAW = 6,
MY_FIRSTMAIN = 7,
MY_COMBATBEGIN = 8,
MY_COMBATATTACKERS = 9,
MY_COMBATBLOCKERS = 10,
MY_COMBATDAMAGE = 11,
MY_COMBATEND = 12,
MY_SECONDMAIN = 13,
MY_ENDOFTURN = 14,
MY_EOT = 15,
MY_CLEANUP = 16,
MY_AFTER_EOT = 17,
GameObserver* game;
public:
int oneShot;
int forceDestroy;
ManaCost* cost;
ManaCost* alternative;
ManaCost* BuyBack;
ManaCost* FlashBack;
ManaCost* Retrace;
OPPONENT_BEFORE_BEGIN = 23,
OPPONENT_UNTAP = 24,
OPPONENT_UPKEEP = 25,
OPPONENT_DRAW = 26,
OPPONENT_FIRSTMAIN = 27,
OPPONENT_COMBATBEGIN = 28,
OPPONENT_COMBATATTACKERS = 29,
OPPONENT_COMBATBLOCKERS = 30,
OPPONENT_COMBATDAMAGE = 31,
OPPONENT_COMBATEND = 32,
OPPONENT_SECONDMAIN = 33,
OPPONENT_ENDOFTURN = 34,
OPPONENT_EOT = 35,
OPPONENT_CLEANUP = 36,
OPPONENT_AFTER_EOT = 37,
Targetable* target;
int aType;
int naType;
int abilitygranted;
int nbcardAmount;
MTGCardInstance* source;
MTGAbility(int id, MTGCardInstance* card);
MTGAbility(int id, MTGCardInstance* _source, Targetable* _target);
virtual int testDestroy();
virtual ~MTGAbility();
virtual void Render() {}
virtual int isReactingToClick(MTGCardInstance* card, ManaCost* mana = NULL)
{
return 0;
}
;
virtual int reactToClick(MTGCardInstance* card)
{
return 0;
}
;
virtual int receiveEvent(WEvent* event)
{
return 0;
}
;
virtual void Update(float dt) {};
virtual int fireAbility();
virtual int stillInUse(MTGCardInstance* card);
virtual int resolve()
{
return 0;
}
;
virtual MTGAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
virtual int addToGame();
virtual int removeFromGame();
BEFORE_BEGIN = 43,
UNTAP = 44,
UPKEEP = 45,
DRAW = 46,
FIRSTMAIN = 47,
COMBATBEGIN = 48,
COMBATATTACKERS = 49,
COMBATBLOCKERS = 50,
COMBATDAMAGE = 51,
COMBATEND = 52,
SECONDMAIN = 53,
ENDOFTURN = 54,
EOT = 55,
CLEANUP = 56,
AFTER_EOT = 57,
VAMPIRES = 60,
LESS_CREATURES = 61,
SNOW_LAND_INPLAY =62,
CASTED_A_SPELL = 63,
ONE_OF_AKIND = 64,
FOURTHTURN = 65,
BEFORECOMBATDAMAGE = 66,
AFTERCOMBAT = 67,
DURINGCOMBAT = 68,
OPPONENT_TURN_ONLY = 69,
};
int allowedToCast(MTGCardInstance * card,Player * player);
int allowedToAltCast(MTGCardInstance * card,Player * player);
int oneShot;
int forceDestroy;
ManaCost * cost;
ManaCost * alternative;
ManaCost * BuyBack;
ManaCost * FlashBack;
ManaCost * Retrace;
ManaCost * morph;
/*Poor man's casting */
/* Todo replace that crap with dynamic casting */
enum
{
UNKNOWN = 0,
MANA_PRODUCER = 1,
MTG_ATTACK_RULE = 2,
DAMAGER = 3,
STANDARD_REGENERATE = 4,
PUT_INTO_PLAY = 5,
MOMIR = 6,
MTG_BLOCK_RULE = 7,
ALTERNATIVE_COST = 8,
BUYBACK_COST = 9,
FLASHBACK_COST = 10,
RETRACE_COST = 11,
MTG_COMBATTRIGGERS_RULE = 12,
STANDARD_PREVENT = 13,
STANDARD_EQUIP = 14,
STANDARD_LEVELUP = 15,
FOREACH = 16,
STANDARD_DRAW = 17,
STANDARD_PUMP = 18,
STANDARD_BECOMES = 19,
UPCOST = 20,
STANDARDABILITYGRANT = 21,
UNTAPPER = 22,
TAPPER = 23,
LIFER = 24,
CLONING = 25,
};
Targetable * target;
int aType;
int naType;
int abilitygranted;
int nbcardAmount;
MTGCardInstance * source;
MTGAbility(int id, MTGCardInstance * card);
MTGAbility(int id, MTGCardInstance * _source, Targetable * _target);
virtual int testDestroy();
virtual ~MTGAbility();
virtual void Render(){};
virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual int receiveEvent(WEvent * event){return 0;};
virtual void Update(float dt){};
virtual int fireAbility();
virtual int stillInUse(MTGCardInstance * card);
virtual int resolve(){return 0;};
virtual MTGAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
virtual int addToGame();
virtual int removeFromGame();
/*Poor man's casting */
/* Todo replace that crap with dynamic casting */
enum {
UNKNOWN = 0,
MANA_PRODUCER = 1,
MTG_ATTACK_RULE = 2,
DAMAGER = 3,
STANDARD_REGENERATE = 4,
PUT_INTO_PLAY = 5,
MOMIR = 6,
MTG_BLOCK_RULE = 7,
ALTERNATIVE_COST = 8,
BUYBACK_COST = 9,
FLASHBACK_COST = 10,
RETRACE_COST = 11,
MTG_COMBATTRIGGERS_RULE = 12,
STANDARD_PREVENT = 13,
STANDARD_EQUIP = 14,
STANDARD_LEVELUP = 15,
FOREACH = 16,
STANDARD_DRAW = 17,
STANDARD_PUMP = 18,
STANDARD_BECOMES = 19,
UPCOST = 20,
STANDARDABILITYGRANT = 21,
UNTAPPER = 22,
TAPPER = 23,
LIFER = 24,
CLONING = 25,
STANDARD_TEACH = 26,
STANDARD_TOKENCREATOR = 27,
MORPH_COST = 28,
};
};
class NestedAbility
{
public:
MTGAbility* ability;
NestedAbility(MTGAbility* _ability);
class NestedAbility{
public:
MTGAbility * ability;
NestedAbility(MTGAbility * _ability);
};
class TriggeredAbility: public MTGAbility
{
public:
TriggeredAbility(int id, MTGCardInstance* card);
TriggeredAbility(int id, MTGCardInstance* _source, Targetable* _target);
virtual void Update(float dt);
virtual void Render() {}
;
virtual int trigger()
{
return 0;
}
;
virtual int triggerOnEvent(WEvent* e)
{
return 0;
}
;
int receiveEvent(WEvent* e);
virtual int resolve() = 0;
virtual TriggeredAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
class TriggeredAbility:public MTGAbility{
public:
TriggeredAbility(int id, MTGCardInstance * card);
TriggeredAbility(int id, MTGCardInstance * _source, Targetable * _target);
virtual void Update(float dt);
virtual void Render(){};
virtual int trigger(){return 0;};
virtual int triggerOnEvent(WEvent * e){return 0;};
int receiveEvent(WEvent * e);
virtual int resolve() = 0;
virtual TriggeredAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
};
class ActivatedAbility: public MTGAbility
{
public:
enum
{
NO_RESTRICTION = 0,
PLAYER_TURN_ONLY = 1,
AS_SORCERY = 2,
MY_BEFORE_BEGIN = 3,
MY_UNTAP = 4,
MY_UPKEEP = 5,
MY_DRAW = 6,
MY_FIRSTMAIN = 7,
MY_COMBATBEGIN = 8,
MY_COMBATATTACKERS = 9,
MY_COMBATBLOCKERS = 10,
MY_COMBATDAMAGE = 11,
MY_COMBATEND = 12,
MY_SECONDMAIN = 13,
MY_ENDOFTURN = 14,
MY_EOT = 15,
MY_CLEANUP = 16,
MY_AFTER_EOT = 17,
OPPONENT_BEFORE_BEGIN = 23,
OPPONENT_UNTAP = 24,
OPPONENT_UPKEEP = 25,
OPPONENT_DRAW = 26,
OPPONENT_FIRSTMAIN = 27,
OPPONENT_COMBATBEGIN = 28,
OPPONENT_COMBATATTACKERS = 29,
OPPONENT_COMBATBLOCKERS = 30,
OPPONENT_COMBATDAMAGE = 31,
OPPONENT_COMBATEND = 32,
OPPONENT_SECONDMAIN = 33,
OPPONENT_ENDOFTURN = 34,
OPPONENT_EOT = 35,
OPPONENT_CLEANUP = 36,
OPPONENT_AFTER_EOT = 37,
class ActivatedAbility:public MTGAbility{
public:
enum {
NO_RESTRICTION = 0,
PLAYER_TURN_ONLY = 1,
AS_SORCERY = 2,
MY_BEFORE_BEGIN = 3,
MY_UNTAP = 4,
MY_UPKEEP = 5,
MY_DRAW = 6,
MY_FIRSTMAIN = 7,
MY_COMBATBEGIN = 8,
MY_COMBATATTACKERS = 9,
MY_COMBATBLOCKERS = 10,
MY_COMBATDAMAGE = 11,
MY_COMBATEND = 12,
MY_SECONDMAIN = 13,
MY_ENDOFTURN = 14,
MY_EOT = 15,
MY_CLEANUP = 16,
MY_AFTER_EOT = 17,
BEFORE_BEGIN = 43,
UNTAP = 44,
UPKEEP = 45,
DRAW = 46,
FIRSTMAIN = 47,
COMBATBEGIN = 48,
COMBATATTACKERS = 49,
COMBATBLOCKERS = 50,
COMBATDAMAGE = 51,
COMBATEND = 52,
SECONDMAIN = 53,
ENDOFTURN = 54,
EOT = 55,
CLEANUP = 56,
AFTER_EOT = 57,
};
ManaCost* abilityCost;
int restrictions;
int needsTapping;
ActivatedAbility(int id, MTGCardInstance* card, ManaCost* _cost = NULL, int _restrictions = NO_RESTRICTION, int tap = 1);
virtual ~ActivatedAbility();
virtual int reactToClick(MTGCardInstance* card);
virtual int isReactingToClick(MTGCardInstance* card, ManaCost* mana = NULL);
virtual int reactToTargetClick(Targetable* object);
virtual int resolve() = 0;
virtual ActivatedAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
OPPONENT_BEFORE_BEGIN = 23,
OPPONENT_UNTAP = 24,
OPPONENT_UPKEEP = 25,
OPPONENT_DRAW = 26,
OPPONENT_FIRSTMAIN = 27,
OPPONENT_COMBATBEGIN = 28,
OPPONENT_COMBATATTACKERS = 29,
OPPONENT_COMBATBLOCKERS = 30,
OPPONENT_COMBATDAMAGE = 31,
OPPONENT_COMBATEND = 32,
OPPONENT_SECONDMAIN = 33,
OPPONENT_ENDOFTURN = 34,
OPPONENT_EOT = 35,
OPPONENT_CLEANUP = 36,
OPPONENT_AFTER_EOT = 37,
BEFORE_BEGIN = 43,
UNTAP = 44,
UPKEEP = 45,
DRAW = 46,
FIRSTMAIN = 47,
COMBATBEGIN = 48,
COMBATATTACKERS = 49,
COMBATBLOCKERS = 50,
COMBATDAMAGE = 51,
COMBATEND = 52,
SECONDMAIN = 53,
ENDOFTURN = 54,
EOT = 55,
CLEANUP = 56,
AFTER_EOT = 57,
OPPONENT_TURN_ONLY = 69,
};
ManaCost * abilityCost;
int restrictions;
int needsTapping;
ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _restrictions = NO_RESTRICTION,int tap = 1);
virtual ~ActivatedAbility();
virtual int reactToClick(MTGCardInstance * card);
virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
virtual int reactToTargetClick(Targetable * object);
virtual int resolve() = 0;
virtual ActivatedAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
};
class TargetAbility: public ActivatedAbility, public NestedAbility
{
public:
TargetAbility(int id, MTGCardInstance* card, TargetChooser* _tc, ManaCost* _cost = NULL, int _playerturnonly = 0, int tap = 1);
TargetAbility(int id, MTGCardInstance* card, ManaCost* _cost = NULL, int _playerturnonly = 0, int tap = 1);
virtual int reactToClick(MTGCardInstance* card);
virtual int reactToTargetClick(Targetable* object);
virtual TargetAbility* clone() const = 0;
virtual void Render();
virtual int resolve();
virtual const char* getMenuText();
virtual ostream& toString(ostream& out) const;
~TargetAbility();
class TargetAbility:public ActivatedAbility, public NestedAbility{
public:
TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual int reactToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual TargetAbility* clone() const = 0;
virtual void Render();
virtual int resolve();
virtual const char * getMenuText();
virtual ostream& toString(ostream& out) const;
~TargetAbility();
};
class InstantAbility: public MTGAbility
{
public:
int init;
virtual void Update(float dt);
virtual int testDestroy();
InstantAbility(int _id, MTGCardInstance* source);
InstantAbility(int _id, MTGCardInstance* source, Damageable* _target);
virtual int resolve()
{
return 0;
}
;
virtual InstantAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
class InstantAbility:public MTGAbility{
public:
int init;
virtual void Update(float dt);
virtual int testDestroy();
InstantAbility(int _id, MTGCardInstance * source);
InstantAbility(int _id, MTGCardInstance * source,Damageable * _target);
virtual int resolve(){return 0;};
virtual InstantAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
};
/* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */
class ListMaintainerAbility: public MTGAbility
{
public:
map<MTGCardInstance *, bool> cards;
map<Player *, bool> players;
ListMaintainerAbility(int _id) : MTGAbility(_id, NULL)
{
}
;
ListMaintainerAbility(int _id, MTGCardInstance *_source) : MTGAbility(_id, _source)
{
}
;
ListMaintainerAbility(int _id, MTGCardInstance *_source, Damageable* _target) : MTGAbility(_id, _source, _target)
{
}
;
virtual void Update(float dt);
void updateTargets();
virtual bool canTarget(MTGGameZone* zone);
virtual int canBeInList(MTGCardInstance* card) = 0;
virtual int added(MTGCardInstance* card) = 0;
virtual int removed(MTGCardInstance* card) = 0;
virtual int canBeInList(Player* p)
{
return 0;
}
;
virtual int added(Player* p)
{
return 0;
}
;
virtual int removed(Player* p)
{
return 0;
}
;
virtual int destroy();
virtual ListMaintainerAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
class ListMaintainerAbility:public MTGAbility{
public:
map<MTGCardInstance *,bool> cards;
map<Player *,bool> players;
ListMaintainerAbility(int _id):MTGAbility(_id,NULL){};
ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){};
ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){};
virtual void Update(float dt);
void updateTargets();
virtual bool canTarget(MTGGameZone * zone);
virtual int canBeInList(MTGCardInstance * card) = 0;
virtual int added(MTGCardInstance * card) = 0;
virtual int removed(MTGCardInstance * card) = 0;
virtual int canBeInList(Player * p){return 0;};
virtual int added(Player * p){return 0;};
virtual int removed(Player * p){return 0;};
virtual int destroy();
virtual ListMaintainerAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const;
};
class TriggerAtPhase: public TriggeredAbility
{
public:
int phaseId;
int who;
TriggerAtPhase(int id, MTGCardInstance* source, Targetable* target, int _phaseId, int who = 0);
virtual int trigger();
int resolve()
{
return 0;
}
;
virtual TriggerAtPhase* clone() const;
class TriggerAtPhase:public TriggeredAbility{
public:
int phaseId;
int who;
bool sourceUntapped;
bool sourceTap;
bool lifelost;
int lifeamount;
TriggerAtPhase(int id, MTGCardInstance * source, Targetable * target,int _phaseId, int who = 0,bool sourceUntapped = false,bool sourceTap = false,bool lifelost = false, int lifeamount = 0);
virtual int trigger();
int resolve(){return 0;};
virtual TriggerAtPhase* clone() const;
};
class TriggerNextPhase: public TriggerAtPhase
{
public:
int destroyActivated;
TriggerNextPhase(int id, MTGCardInstance* source, Targetable* target, int _phaseId, int who = 0);
virtual TriggerNextPhase* clone() const;
virtual int testDestroy();
class TriggerNextPhase:public TriggerAtPhase{
public:
int destroyActivated;
bool sourceUntapped;
bool sourceTap;
TriggerNextPhase(int id, MTGCardInstance * source, Targetable * target,int _phaseId, int who = 0,bool sourceUntapped = false,bool sourceTap = false);
virtual TriggerNextPhase* clone() const;
virtual int testDestroy();
};
class GenericTriggeredAbility: public TriggeredAbility, public NestedAbility
{
public:
TriggeredAbility* t;
queue<Targetable *> targets;
MTGAbility* destroyCondition;
GenericTriggeredAbility(int id, MTGCardInstance* _source, TriggeredAbility* _t, MTGAbility* a, MTGAbility* dc = NULL,
Targetable* _target = NULL);
virtual int trigger();
virtual int triggerOnEvent(WEvent* e);
virtual int resolve();
virtual int testDestroy();
Targetable* getTriggerTarget(WEvent* e, MTGAbility* a);
void setTriggerTargets(Targetable* ta, MTGAbility* a);
class GenericTriggeredAbility:public TriggeredAbility, public NestedAbility{
public:
TriggeredAbility * t;
queue<Targetable *> targets;
MTGAbility * destroyCondition;
GenericTriggeredAbility(int id, MTGCardInstance * _source, TriggeredAbility * _t, MTGAbility * a,MTGAbility * dc = NULL, Targetable * _target = NULL);
virtual int trigger();
virtual int triggerOnEvent(WEvent * e);
virtual int resolve();
virtual int testDestroy();
void Update(float dt);
virtual GenericTriggeredAbility* clone() const;
const char* getMenuText();
~GenericTriggeredAbility();
Targetable * getTriggerTarget(WEvent * e, MTGAbility * a);
void setTriggerTargets(Targetable * ta, MTGAbility * a);
void Update(float dt);
virtual GenericTriggeredAbility* clone() const;
const char * getMenuText();
~GenericTriggeredAbility();
};
/* Ability Factory */
class AbilityFactory
{
private:
int countCards(TargetChooser* tc, Player* player = NULL, int option = 0);
TriggeredAbility* parseTrigger(string s, string magicText, int id, Spell* spell, MTGCardInstance *card, Targetable* target);
int parseRestriction(string s);
MTGAbility* getAlternateCost(string s, int id, Spell *spell, MTGCardInstance *card);
MTGAbility* getManaReduxAbility(string s, int id, Spell *spell, MTGCardInstance *card, MTGCardInstance *target);
class AbilityFactory{
private:
int countCards(TargetChooser * tc, Player * player = NULL, int option = 0);
TriggeredAbility * parseTrigger(string s, string magicText, int id, Spell * spell, MTGCardInstance *card, Targetable * target);
int parseRestriction(string s);
MTGAbility * getAlternateCost( string s, int id, Spell *spell, MTGCardInstance *card );
MTGAbility * getManaReduxAbility(string s, int id, Spell *spell, MTGCardInstance *card, MTGCardInstance *target);
public:
Counter* parseCounter(string s, MTGCardInstance* target, Spell* spell = NULL);
int parsePowerToughness(string s, int* power, int* toughness);
int getAbilities(vector<MTGAbility *>* v, Spell* spell, MTGCardInstance* card = NULL, int id = 0, MTGGameZone* dest = NULL);
MTGAbility* parseMagicLine(string s, int id, Spell* spell, MTGCardInstance *card, int activated = 0, int forceUEOT = 0,
int oneShot = 0, int forceForever = 0, MTGGameZone* dest = NULL);
Counter * parseCounter(string s, MTGCardInstance * target, Spell * spell = NULL);
int parsePowerToughness(string s, int *power, int *toughness);
int getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCardInstance * card = NULL, int id = 0,MTGGameZone * dest = NULL);
MTGAbility * parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated = 0, int forceUEOT = 0,int oneShot = 0,int forceForever = 0, MTGGameZone * dest = NULL);
int abilityEfficiency(MTGAbility* a, Player* p, int mode = MODE_ABILITY, TargetChooser* tc = NULL);
int magicText(int id, Spell* spell, MTGCardInstance* card = NULL, int mode = MODE_PUTINTOPLAY, TargetChooser* tc = NULL,
MTGGameZone* dest = NULL);
static int computeX(Spell* spell, MTGCardInstance* card);
static int computeXX(Spell* spell, MTGCardInstance* card);
static MTGAbility* getCoreAbility(MTGAbility* a);
int destroyAllInPlay(TargetChooser* tc, int bury = 0);
int moveAll(TargetChooser* tc, string destinationZone);
int damageAll(TargetChooser* tc, int damage);
int TapAll(TargetChooser* tc);
int UntapAll(TargetChooser* tc);
void addAbilities(int _id, Spell* spell);
int abilityEfficiency(MTGAbility * a, Player * p, int mode = MODE_ABILITY, TargetChooser * tc = NULL);
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL, MTGGameZone * dest = NULL);
static int computeX(Spell * spell, MTGCardInstance * card);
static int computeXX(Spell * spell, MTGCardInstance * card);
static MTGAbility * getCoreAbility(MTGAbility * a);
int destroyAllInPlay(TargetChooser * tc, int bury = 0);
int moveAll(TargetChooser * tc, string destinationZone);
int damageAll(TargetChooser * tc, int damage);
int TapAll(TargetChooser * tc);
int UntapAll(TargetChooser * tc);
void addAbilities(int _id, Spell * spell);
};
class ActivatedAbilityTP: public ActivatedAbility
{
class ActivatedAbilityTP:public ActivatedAbility{
public:
int who;
ActivatedAbilityTP(int id, MTGCardInstance* card, Targetable* _target = NULL, ManaCost* cost = NULL, int doTap = 0, int who =
TargetChooser::UNSET);
Targetable* getTarget();
int who;
ActivatedAbilityTP(int id, MTGCardInstance * card, Targetable * _target = NULL, ManaCost * cost=NULL, int doTap = 0, int who = TargetChooser::UNSET);
Targetable * getTarget();
};
class AManaProducer: public ActivatedAbilityTP
{
protected:
class AManaProducer: public ActivatedAbilityTP{
protected:
string menutext;
Player* controller;
string menutext;
Player * controller;
public:
ManaCost* output;
int tap;
AManaProducer(int id, MTGCardInstance* card, Targetable* t, ManaCost* _output, ManaCost* _cost = NULL, int doTap = 1, int who = TargetChooser::UNSET);
int isReactingToClick(MTGCardInstance* _card, ManaCost* mana = NULL);
int resolve();
int reactToClick(MTGCardInstance* _card);
const char* getMenuText();
~AManaProducer();
virtual AManaProducer* clone() const;
public:
ManaCost * output;
int tap;
AManaProducer(int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost = NULL, int doTap = 1, int who = TargetChooser::UNSET );
int isReactingToClick(MTGCardInstance * _card, ManaCost * mana = NULL);
int resolve();
int reactToClick(MTGCardInstance * _card);
const char * getMenuText();
~AManaProducer();
virtual AManaProducer * clone() const;
};
#include "MTGCardInstance.h"
#endif
+147 -124
View File
@@ -10,6 +10,7 @@
#include "Damage.h"
#include "Targetable.h"
class MTGCardInstance;
class MTGPlayerCards;
class MTGAbility;
@@ -23,150 +24,172 @@ struct Pos;
#include <list>
using namespace std;
class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable
{
protected:
int untapping;
int nb_damages;
string sample;
int tapped;
int lifeOrig;
MTGPlayerCards * belongs_to;
MTGCardInstance * getNextPartner();
void initMTGCI();
class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable {
protected:
int untapping;
int nb_damages;
string sample;
int tapped;
int lifeOrig;
MTGPlayerCards * belongs_to;
MTGCardInstance * getNextPartner();
void initMTGCI();
int addBlocker(MTGCardInstance * c);
int removeBlocker(MTGCardInstance * c);
int init();
public:
int setAttacker(int value);
int setDefenser(MTGCardInstance * c);
int addBlocker(MTGCardInstance * c);
int removeBlocker(MTGCardInstance * c);
int init();
public:
int setAttacker(int value);
MTGGameZone * currentZone;
Pos* view;
int X;
int XX;
int alternateCostPaid[ManaCost::MANA_PAID_WITH_RETRACE + 1];
int paymenttype;
int frozen;
int sunburst;
int equipment;
int reduxamount;
int flanked;
int regenerateTokens;
int isToken;
int stillInUse();
int didattacked;
int didblocked;
int notblocked;
int fresh;
int MaxLevelUp;
Player * lastController;
MTGGameZone * getCurrentZone();
MTGGameZone * previousZone;
MTGCardInstance * previous;
MTGCardInstance * next;
int doDamageTest;
int summoningSickness;
// The recommended method to test for summoning Sickness !
int hasSummoningSickness();
MTGCardInstance * changeController(Player * newcontroller);
Player * owner;
Counters * counters;
int typeAsTarget()
{
return TARGET_CARD;
}
const string getDisplayName() const;
MTGCardInstance * target;
MTGGameZone * currentZone;
Pos* view;
int X;
int XX;
int alternateCostPaid[ManaCost::MANA_PAID_WITH_RETRACE + 1];
int paymenttype;
int frozen;
int sunburst;
int equipment;
int auras;
int reduxamount;
int flanked;
int regenerateTokens;
int isToken;
int origpower;
int origtoughness;
int isMultiColored;
int isBlackAndWhite;
int isRedAndBlue;
int isBlackAndGreen;
int isBlueAndGreen;
int isRedAndWhite;
int isLeveler;
bool enchanted;
int CDenchanted;
bool blinked;
bool isExtraCostTarget;
bool morphed;
bool turningOver;
bool isMorphed;
bool isPhased;
bool isTempPhased;
int phasedTurn;
bool graveEffects;
bool exileEffects;
int stillInUse();
int didattacked;
int didblocked;
int notblocked;
int fresh;
int MaxLevelUp;
Player * lastController;
MTGGameZone * getCurrentZone();
MTGGameZone * previousZone;
MTGCardInstance * previous;
MTGCardInstance * next;
int doDamageTest;
int summoningSickness;
// The recommended method to test for summoning Sickness !
int hasSummoningSickness();
MTGCardInstance * changeController(Player * newcontroller);
Player * owner;
Counters * counters;
int typeAsTarget(){return TARGET_CARD;}
const string getDisplayName() const;
MTGCardInstance * target;
MTGCardInstance * imprint;
//types
void addType(char * type_text);
virtual void addType(int id);
void setType(const char * type_text);
void setSubtype(string value);
int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0);
//dangerranking is a hint to Ai which creatures are the ones it should be targetting for effects.
int DangerRanking();
//Combat
bool blocked; //Blocked this turn or not?
MTGCardInstance * defenser;
list<MTGCardInstance *> blockers;
int attacker;
int toggleDefenser(MTGCardInstance * opponent);
int raiseBlockerRankOrder(MTGCardInstance * blocker);
//types
void addType(char * type_text);
virtual void addType(int id);
void setType(const char * type_text);
void setSubtype( string value);
int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0);
//Returns rank of the card in blockers if it is a blocker of this (starting at 1), 0 otherwise
int getDefenserRank(MTGCardInstance * blocker);
int toggleAttacker();
MTGCardInstance * banding; // If belongs to a band when attacking
int canBlock();
int canBlock(MTGCardInstance * opponent);
int canAttack();
int isAttacker();
MTGCardInstance * isDefenser();
int initAttackersDefensers();
MTGCardInstance * getNextOpponent(MTGCardInstance * previous = NULL);
int nbOpponents();
int stepPower(CombatStep step);
int afterDamage();
int has(int ability);
int cleanup();
//dangerranking is a hint to Ai which creatures are the ones it should be targetting for effects.
int DangerRanking();
//Combat
bool blocked; //Blocked this turn or not?
MTGCardInstance * defenser;
list<MTGCardInstance *>blockers;
int attacker;
int toggleDefenser(MTGCardInstance * opponent);
int raiseBlockerRankOrder(MTGCardInstance * blocker);
MTGCard * model;
MTGCardInstance();
MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to);
int regenerate();
int triggerRegenerate();
Player * controller();
//Returns rank of the card in blockers if it is a blocker of this (starting at 1), 0 otherwise
int getDefenserRank(MTGCardInstance * blocker);
int toggleAttacker();
MTGCardInstance * banding; // If belongs to a band when attacking
int canBlock();
int canBlock(MTGCardInstance * opponent);
int canAttack();
int isAttacker();
MTGCardInstance * isDefenser();
int initAttackersDefensers();
MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL);
int nbOpponents();
int stepPower(CombatStep step);
int afterDamage();
int has(int ability);
int cleanup();
virtual ~MTGCardInstance();
int bury();
int destroy();
MTGCard * model;
MTGCardInstance();
MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to);
int regenerate();
int triggerRegenerate();
Player * controller();
int addToToughness(int value);
int setToughness(int value);
virtual ~MTGCardInstance();
int bury();
int destroy();
vector<TargetChooser *> protections;
int addProtection(TargetChooser * tc);
int removeProtection(TargetChooser *tc, int erase = 0);
int protectedAgainst(MTGCardInstance * card);
vector<TargetChooser *> cantBeBlockedBys;
int addCantBeBlockedBy(TargetChooser * tc);
int removeCantBeBlockedBy(TargetChooser *tc, int erase = 0);
int cantBeBlockedBy(MTGCardInstance * card);
int addToToughness(int value);
int setToughness(int value);
void copy(MTGCardInstance * card);
vector<TargetChooser *>protections;
int addProtection(TargetChooser * tc);
int removeProtection(TargetChooser *tc, int erase = 0);
int protectedAgainst(MTGCardInstance * card);
void setUntapping();
int isUntapping();
int isTapped();
void untap();
void tap();
void attemptUntap();
vector<TargetChooser *>cantBeBlockedBys;
int addCantBeBlockedBy(TargetChooser * tc);
int removeCantBeBlockedBy(TargetChooser *tc, int erase = 0);
int cantBeBlockedBy(MTGCardInstance * card);
void eventattacked();
void eventattackedAlone();
void eventattackednotblocked();
void eventattackedblocked();
void eventblocked();
void copy(MTGCardInstance * card);
int isInPlay();
JSample * getSample();
void setUntapping();
int isUntapping();
int isTapped();
void untap();
void tap();
void attemptUntap();
JQuad * getIcon();
void eventattacked();
void eventattackedAlone();
void eventattackednotblocked();
void eventattackedblocked();
void eventblocked();
ostream& toString(ostream&) const;
int isInPlay();
JSample * getSample();
static MTGCardInstance AnyCard;
static MTGCardInstance NoCard;
JQuad * getIcon();
static MTGCardInstance ExtraRules[2];
ostream& toString(ostream&) const;
static MTGCardInstance AnyCard;
static MTGCardInstance NoCard;
static MTGCardInstance ExtraRules[2];
};
ostream& operator<<(ostream&, const MTGCardInstance&);
#endif
+211 -189
View File
@@ -9,217 +9,239 @@ const float DEFAULT_TEXT_FONT_SCALE = 1.0f;
using std::string;
class Constants
{
public:
// Exception Codes
public:
// Exception Codes
/* Exception codes */
const static int PARSER_FAILED_INSTANTIATION = 1000;
const static int PARSER_KEYWORD_NOT_MATCHED = 2000;
const static int PARSER_INVALID_KEYWORD = 3000;
/* Exception codes */
const static int PARSER_FAILED_INSTANTIATION = 1000;
const static int PARSER_KEYWORD_NOT_MATCHED = 2000;
const static int PARSER_INVALID_KEYWORD = 3000;
// color constants
static const string kManaColorless;
static const string kManaGreen;
static const string kManaBlue;
static const string kManaRed;
static const string kManaBlack;
static const string kManaWhite;
// alternative costs constants
// color constants
static const string kManaColorless;
static const string kManaGreen;
static const string kManaBlue;
static const string kManaRed;
static const string kManaBlack;
static const string kManaWhite;
static const string kAlternativeKeyword;
static const string kBuyBackKeyword;
static const string kFlashBackKeyword;
static const string kRetraceKeyword;
static const string kKickerKeyword;
// alternative costs constants
// used for deck statistics
static const int STATS_FOR_TURNS = 8;
static const int STATS_MAX_MANA_COST = 9;
static const string kAlternativeKeyword;
static const string kBuyBackKeyword;
static const string kFlashBackKeyword;
static const string kRetraceKeyword;
static const string kKickerKeyword;
static const string kMorphKeyword;
enum
{
MTG_COLOR_ARTIFACT = 0,
MTG_COLOR_GREEN = 1,
MTG_COLOR_BLUE = 2,
MTG_COLOR_RED = 3,
MTG_COLOR_BLACK = 4,
MTG_COLOR_WHITE = 5,
MTG_COLOR_LAND = 6,
// used for deck statistics
static const int STATS_FOR_TURNS = 8;
static const int STATS_MAX_MANA_COST = 9;
enum
{
MTG_COLOR_ARTIFACT = 0,
MTG_COLOR_GREEN = 1,
MTG_COLOR_BLUE = 2,
MTG_COLOR_RED = 3,
MTG_COLOR_BLACK = 4,
MTG_COLOR_WHITE = 5,
MTG_COLOR_LAND = 6,
MTG_NB_COLORS = 7,
MTG_NB_COLORS = 7,
MTG_UNCOLORED = 0,
MTG_FOREST = 1,
MTG_ISLAND = 2,
MTG_MOUNTAIN = 3,
MTG_SWAMP = 4,
MTG_PLAIN = 5,
MTG_TYPE_CREATURE = 10,
MTG_TYPE_ARTIFACT = 11,
MTG_TYPE_ENCHANTMENT = 12,
MTG_TYPE_SORCERY = 13,
MTG_TYPE_LAND = 14,
MTG_TYPE_INSTANT = 15,
MTG_UNCOLORED = 0,
MTG_FOREST = 1,
MTG_ISLAND = 2,
MTG_MOUNTAIN = 3,
MTG_SWAMP = 4,
MTG_PLAIN = 5,
MTG_PHASE_BEFORE_BEGIN = 0,
MTG_PHASE_UNTAP = 1,
MTG_PHASE_UPKEEP = 2,
MTG_PHASE_DRAW = 3,
MTG_PHASE_FIRSTMAIN = 4,
MTG_PHASE_COMBATBEGIN = 5,
MTG_PHASE_COMBATATTACKERS = 6,
MTG_PHASE_COMBATBLOCKERS = 7,
MTG_PHASE_COMBATDAMAGE = 8,
MTG_PHASE_COMBATEND = 9,
MTG_PHASE_SECONDMAIN = 10,
MTG_PHASE_ENDOFTURN = 11,
MTG_PHASE_EOT = 11,
MTG_PHASE_CLEANUP = 12,
MTG_PHASE_AFTER_EOT = 13,
NB_MTG_PHASES = 14,
TRAMPLE = 0,
FORESTWALK = 1,
ISLANDWALK = 2,
MOUNTAINWALK = 3,
SWAMPWALK = 4,
PLAINSWALK = 5,
FLYING = 6,
FIRSTSTRIKE = 7,
DOUBLESTRIKE = 8,
FEAR = 9,
FLASH = 10,
HASTE = 11,
LIFELINK = 12,
REACH = 13,
SHROUD = 14,
VIGILANCE = 15,
DEFENSER = 16,
DEFENDER = 16,
BANDING = 17,
PROTECTIONGREEN = 18,
PROTECTIONBLUE = 19,
PROTECTIONRED = 20,
PROTECTIONBLACK = 21,
PROTECTIONWHITE = 22,
UNBLOCKABLE = 23,
WITHER = 24,
PERSIST = 25,
RETRACE = 26,
EXALTED = 27,
NOFIZZLE = 28,
SHADOW = 29,
REACHSHADOW = 30,
FORESTHOME = 31,
ISLANDHOME = 32,
MOUNTAINHOME = 33,
SWAMPHOME = 34,
PLAINSHOME = 35,
CLOUD = 36,
CANTATTACK = 37,
MUSTATTACK = 38,
CANTBLOCK = 39,
DOESNOTUNTAP = 40,
OPPONENTSHROUD = 41,
INDESTRUCTIBLE = 42,
INTIMIDATE = 43,
DEATHTOUCH = 44,
HORSEMANSHIP = 45,
CANTREGEN = 46,
ONEBLOCKER = 47,
INFECT = 48,
POISONTOXIC = 49,
POISONTWOTOXIC = 50,
POISONTHREETOXIC = 51,
PHANTOM = 52,
WILTING = 53,
VIGOR = 54,
CHANGELING = 55,
ABSORB = 56,//this need to be coded for players too "If a source would deal damage"
TREASON = 57,
UNEARTH = 58,
CANTLOSE = 59,
CANTLIFELOSE = 60,
CANTMILLLOSE = 61,
CANTCASTCREATURE = 62,
CANTCAST = 63,
CANTCASTTWO = 64,
STORM = 65,
BOTHCANTCAST = 66,
BOTHNOCREATURE = 67,
ONLYONEBOTH = 68,
AFFINITYARTIFACTS = 69,
AFFINITYPLAINS = 70,
AFFINITYFOREST = 71,
AFFINITYISLAND = 72,
AFFINITYMOUNTAIN = 73,
AFFINITYSWAMP = 74,
AFFINITYGREENCREATURES = 75,
CANTWIN = 76,
NOMAXHAND = 77,
LEYLINE = 78,
PLAYERSHROUD = 79,
CONTROLLERSHROUD = 80,
SUNBURST = 81,
FLANKING = 82,
EXILEDEATH = 83,
MTG_TYPE_CREATURE = 10,
MTG_TYPE_ARTIFACT = 11,
MTG_TYPE_ENCHANTMENT = 12,
MTG_TYPE_SORCERY = 13,
MTG_TYPE_LAND = 14,
MTG_TYPE_INSTANT = 15,
NB_BASIC_ABILITIES = 84,
RARITY_S = 'S', //Special Rarity
RARITY_M = 'M', //Mythics
RARITY_R = 'R', //Rares
RARITY_U = 'U', //Uncommons
RARITY_C = 'C', //Commons
RARITY_L = 'L', //Lands
RARITY_T = 'T', //Tokens
MTG_PHASE_BEFORE_BEGIN = 0,
MTG_PHASE_UNTAP = 1,
MTG_PHASE_UPKEEP = 2,
MTG_PHASE_DRAW = 3,
MTG_PHASE_FIRSTMAIN = 4,
MTG_PHASE_COMBATBEGIN = 5,
MTG_PHASE_COMBATATTACKERS = 6,
MTG_PHASE_COMBATBLOCKERS = 7,
MTG_PHASE_COMBATDAMAGE = 8,
MTG_PHASE_COMBATEND = 9,
MTG_PHASE_SECONDMAIN = 10,
MTG_PHASE_ENDOFTURN = 11,
MTG_PHASE_CLEANUP = 12,
MTG_PHASE_AFTER_EOT = 13,
NB_MTG_PHASES = 14,
ECON_NORMAL = 0, //Options default to 0.
ECON_HARD = 1,
ECON_LUCK = 2,
ECON_EASY = 3,
TRAMPLE = 0,
FORESTWALK = 1,
ISLANDWALK = 2,
MOUNTAINWALK = 3,
SWAMPWALK = 4,
PLAINSWALK = 5,
FLYING = 6,
FIRSTSTRIKE = 7,
DOUBLESTRIKE = 8,
FEAR = 9,
FLASH = 10,
HASTE = 11,
LIFELINK = 12,
REACH = 13,
SHROUD = 14,
VIGILANCE = 15,
DEFENSER = 16,
DEFENDER = 16,
BANDING = 17,
PROTECTIONGREEN = 18,
PROTECTIONBLUE = 19,
PROTECTIONRED = 20,
PROTECTIONBLACK = 21,
PROTECTIONWHITE = 22,
UNBLOCKABLE = 23,
WITHER = 24,
PERSIST = 25,
RETRACE = 26,
EXALTED = 27,
NOFIZZLE = 28,
SHADOW = 29,
REACHSHADOW = 30,
FORESTHOME = 31,
ISLANDHOME = 32,
MOUNTAINHOME = 33,
SWAMPHOME = 34,
PLAINSHOME = 35,
CLOUD = 36,
CANTATTACK = 37,
MUSTATTACK = 38,
CANTBLOCK = 39,
DOESNOTUNTAP = 40,
OPPONENTSHROUD = 41,
INDESTRUCTIBLE = 42,
INTIMIDATE = 43,
DEATHTOUCH = 44,
HORSEMANSHIP = 45,
CANTREGEN = 46,
ONEBLOCKER = 47,
INFECT = 48,
POISONTOXIC = 49,
POISONTWOTOXIC = 50,
POISONTHREETOXIC = 51,
PHANTOM = 52,
WILTING = 53,
VIGOR = 54,
CHANGELING = 55,
ABSORB = 56,//this need to be coded for players too "If a source would deal damage"
TREASON = 57,
UNEARTH = 58,
CANTLOSE = 59,
CANTLIFELOSE = 60,
CANTMILLLOSE = 61,
CANTCASTCREATURE = 62,
CANTCAST = 63,
CANTCASTTWO = 64,
STORM = 65,
BOTHCANTCAST = 66,
BOTHNOCREATURE = 67,
ONLYONEBOTH = 68,
AFFINITYARTIFACTS = 69,
AFFINITYPLAINS = 70,
AFFINITYFOREST = 71,
AFFINITYISLAND = 72,
AFFINITYMOUNTAIN = 73,
AFFINITYSWAMP = 74,
AFFINITYGREENCREATURES = 75,
CANTWIN = 76,
NOMAXHAND = 77,
LEYLINE = 78,
PLAYERSHROUD = 79,
CONTROLLERSHROUD = 80,
SUNBURST = 81,
FLANKING = 82,
EXILEDEATH = 83,
LEGENDARYWALK = 84,
DESERTWALK = 85,
SNOWFORESTWALK = 86,
SNOWPLAINSWALK = 87,
SNOWMOUNTAINWALK = 88,
SNOWISLANDWALK = 89,
SNOWSWAMPWALK = 90,
SNOWWALK = 91,
NONBASICWALK = 92,
STRONG = 93,
WEAK = 94,
PHASING = 95,
//Price for singles
PRICE_1M = 3000,
PRICE_1R = 500,
PRICE_1S = 200,
PRICE_1U = 100,
PRICE_1C = 20,
PRICE_1L = 5,
NB_BASIC_ABILITIES = 96,
//Price in booster
PRICE_BOOSTER = 700,
PRICE_MIXED_BOOSTER = 800,
CHANCE_CUSTOM_PACK = 15,
CHANCE_PURE_OVERRIDE = 50,
CHANCE_MIXED_OVERRIDE = 25,
GRADE_SUPPORTED = 0,
GRADE_BORDERLINE = 1,
GRADE_UNOFFICIAL = 2,
GRADE_CRAPPY = 3,
GRADE_UNSUPPORTED = 4,
GRADE_DANGEROUS = 5,
RARITY_S = 'S', //Special Rarity
RARITY_M = 'M', //Mythics
RARITY_R = 'R', //Rares
RARITY_U = 'U', //Uncommons
RARITY_C = 'C', //Commons
RARITY_L = 'L', //Lands
RARITY_T = 'T', //Tokens
ASKIP_NONE = 0,
ASKIP_SAFE = 1,
ASKIP_FULL = 2,
};
ECON_NORMAL = 0, //Options default to 0.
ECON_HARD = 1,
ECON_LUCK = 2,
ECON_EASY = 3,
static char MTGColorChars[];
static const char* MTGColorStrings[];
static int _r[], _g[], _b[];
//Price for singles
PRICE_1M = 3000,
PRICE_1R = 500,
PRICE_1S = 200,
PRICE_1U = 100,
PRICE_1C = 20,
PRICE_1L = 5,
static map<string, int> MTGBasicAbilitiesMap;
static const char* MTGBasicAbilities[];
static const char* MTGPhaseNames[];
static const char* MTGPhaseCodeNames[];
//Price in booster
PRICE_BOOSTER = 700,
PRICE_MIXED_BOOSTER = 800,
CHANCE_CUSTOM_PACK = 15,
CHANCE_PURE_OVERRIDE = 50,
CHANCE_MIXED_OVERRIDE = 25,
static int GetBasicAbilityIndex(string mtgAbility);
static int GetColorStringIndex(string mtgColor);
GRADE_SUPPORTED = 0,
GRADE_BORDERLINE = 1,
GRADE_UNOFFICIAL = 2,
GRADE_CRAPPY = 3,
GRADE_UNSUPPORTED = 4,
GRADE_DANGEROUS = 5,
ASKIP_NONE=0,
ASKIP_SAFE=1,
ASKIP_FULL=2,
WHO_P=0,
WHO_O=1,
WHO_R=2,
};
static char MTGColorChars[];
static const char* MTGColorStrings[];
static int _r[], _g[], _b[];
static map<string,int> MTGBasicAbilitiesMap;
static const char* MTGBasicAbilities[];
static const char* MTGPhaseNames[];
static const char* MTGPhaseCodeNames[];
static int GetBasicAbilityIndex(string mtgAbility);
static int GetColorStringIndex(string mtgColor);
};
#endif
+135 -158
View File
@@ -14,191 +14,168 @@ class MTGDeck;
class MTGCardInstance;
class Player;
class MTGGameZone
{
protected:
class MTGGameZone {
protected:
public:
public:
enum
{
ALL_ZONES = -1,
enum{
ALL_ZONES = -1,
MY_GRAVEYARD = 11,
OPPONENT_GRAVEYARD = 12,
TARGET_OWNER_GRAVEYARD = 13,
TARGET_CONTROLLER_GRAVEYARD = 14,
GRAVEYARD = 15,
OWNER_GRAVEYARD = 16,
MY_GRAVEYARD = 11,
OPPONENT_GRAVEYARD = 12,
TARGET_OWNER_GRAVEYARD = 13,
TARGET_CONTROLLER_GRAVEYARD = 14,
GRAVEYARD = 15,
OWNER_GRAVEYARD = 16,
MY_BATTLEFIELD = 21,
OPPONENT_BATTLEFIELD = 22,
TARGET_OWNER_BATTLEFIELD = 23,
TARGET_CONTROLLER_BATTLEFIELD = 24,
BATTLEFIELD = 25,
OWNER_BATTLEFIELD = 26,
MY_BATTLEFIELD = 21,
OPPONENT_BATTLEFIELD = 22,
TARGET_OWNER_BATTLEFIELD = 23,
TARGET_CONTROLLER_BATTLEFIELD = 24,
BATTLEFIELD = 25,
OWNER_BATTLEFIELD = 26,
MY_HAND = 31,
OPPONENT_HAND = 32,
TARGET_OWNER_HAND = 33,
TARGET_CONTROLLER_HAND = 34,
HAND = 35,
OWNER_HAND = 36,
MY_HAND = 31,
OPPONENT_HAND = 32,
TARGET_OWNER_HAND = 33,
TARGET_CONTROLLER_HAND = 34,
HAND = 35,
OWNER_HAND = 36,
MY_EXILE = 41,
OPPONENT_EXILE = 42,
TARGET_OWNER_EXILE = 43,
TARGET_CONTROLLER_EXILE = 44,
EXILE = 45,
OWNER_EXILE = 46,
MY_EXILE = 41,
OPPONENT_EXILE = 42,
TARGET_OWNER_EXILE = 43,
TARGET_CONTROLLER_EXILE = 44,
EXILE = 45,
OWNER_EXILE = 46,
MY_LIBRARY = 51,
OPPONENT_LIBRARY = 52,
TARGET_OWNER_LIBRARY = 53,
TARGET_CONTROLLER_LIBRARY = 54,
LIBRARY = 55,
OWNER_LIBRARY = 56,
MY_LIBRARY = 51,
OPPONENT_LIBRARY = 52,
TARGET_OWNER_LIBRARY = 53,
TARGET_CONTROLLER_LIBRARY = 54,
LIBRARY = 55,
OWNER_LIBRARY = 56,
MY_STACK = 61,
OPPONENT_STACK = 62,
TARGET_OWNER_STACK = 63,
TARGET_CONTROLLER_STACK = 64,
STACK = 65,
OWNER_STACK = 66,
MY_STACK = 61,
OPPONENT_STACK = 62,
TARGET_OWNER_STACK = 63,
TARGET_CONTROLLER_STACK = 64,
STACK = 65,
OWNER_STACK = 66,
};
};
Player * owner;
//Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array
vector<MTGCardInstance *> cards; //[MTG_MAX_PLAYER_CARDS];
map<MTGCardInstance *, int> cardsMap;
int nb_cards;
MTGGameZone();
~MTGGameZone();
void shuffle();
void addCard(MTGCardInstance * card);
void debugPrint();
MTGCardInstance * removeCard(MTGCardInstance * card, int createCopy = 1);
MTGCardInstance * hasCard(MTGCardInstance * card);
void cleanupPhase();
int countByType(const char * value);
MTGCardInstance * findByName(string name);
int hasAbility(int ability); //returns 1 if one of the cards in the zone has the ability, 0 otherwise
int hasType(const char * value); //returns 1 if one of the cards in the zone has the type, 0 otherwise
int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise
int hasX();
void setOwner(Player * player);
MTGCardInstance * lastCardDrawn;
static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target);
static int zoneStringToId(string zoneName);
static MTGGameZone *intToZone(int zoneId, MTGCardInstance * source = NULL, MTGCardInstance * target = NULL);
bool needShuffle;
virtual const char * getName()
{
return "zone";
}
;
virtual ostream& toString(ostream&) const;
Player * owner;
//Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array
vector<MTGCardInstance *> cards; //[MTG_MAX_PLAYER_CARDS];
map<MTGCardInstance *,int> cardsMap;
int nb_cards;
MTGGameZone();
~MTGGameZone();
void shuffle();
void addCard(MTGCardInstance * card);
void debugPrint();
MTGCardInstance * removeCard(MTGCardInstance * card, int createCopy = 1);
MTGCardInstance * hasCard(MTGCardInstance * card);
void cleanupPhase();
int countByType(const char * value);
MTGCardInstance * findByName(string name);
int hasAbility(int ability); //returns 1 if one of the cards in the zone has the ability, 0 otherwise
int hasType(const char * value); //returns 1 if one of the cards in the zone has the type, 0 otherwise
int hasSpecificType(const char * value,const char * secondvalue); //returns 1 if one of the cards in the zone has the type, 0 otherwise
int hasPrimaryType(const char * value,const char * secondvalue); //returns 1 if one of the cards in the zone has the type, 0 otherwise
int hasTypeButNotType(const char * value,const char * secondvalue); //returns 1 if one of the cards in the zone has the type, 0 otherwise
int hasName(string value);
int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise
int hasX();
void setOwner(Player * player);
MTGCardInstance * lastCardDrawn;
static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target);
static int zoneStringToId(string zoneName);
static MTGGameZone *intToZone(int zoneId, MTGCardInstance * source = NULL,MTGCardInstance * target = NULL);
bool needShuffle;
virtual const char * getName(){return "zone";};
virtual ostream& toString(ostream&) const;
};
class MTGLibrary: public MTGGameZone
{
public:
void shuffleTopToBottom(int nbcards);
virtual ostream& toString(ostream&) const;
const char * getName()
{
return "library";
}
class MTGLibrary: public MTGGameZone {
public:
void shuffleTopToBottom(int nbcards);
virtual ostream& toString(ostream&) const;
const char * getName(){return "library";}
};
class MTGGraveyard: public MTGGameZone
{
public:
virtual ostream& toString(ostream&) const;
const char * getName()
{
return "graveyard";
}
class MTGGraveyard: public MTGGameZone {
public:
virtual ostream& toString(ostream&) const;
const char * getName(){return "graveyard";}
};
class MTGHand: public MTGGameZone
{
public:
virtual ostream& toString(ostream&) const;
const char * getName()
{
return "hand";
}
class MTGHand: public MTGGameZone {
public:
virtual ostream& toString(ostream&) const;
const char * getName(){return "hand";}
};
class MTGRemovedFromGame: public MTGGameZone
{
public:
virtual ostream& toString(ostream&) const;
const char * getName()
{
return "exile";
}
class MTGRemovedFromGame: public MTGGameZone {
public:
virtual ostream& toString(ostream&) const;
const char * getName(){return "exile";}
};
class MTGStack: public MTGGameZone
{
public:
virtual ostream& toString(ostream&) const;
const char * getName()
{
return "stack";
}
class MTGStack: public MTGGameZone {
public:
virtual ostream& toString(ostream&) const;
const char * getName(){return "stack";}
};
class MTGInPlay: public MTGGameZone
{
public:
void untapAll();
MTGCardInstance * getNextAttacker(MTGCardInstance * previous);
virtual ostream& toString(ostream&) const;
const char * getName()
{
return "battlefield";
}
class MTGInPlay: public MTGGameZone {
public:
void untapAll();
MTGCardInstance * getNextAttacker(MTGCardInstance * previous);
virtual ostream& toString(ostream&) const;
const char * getName(){return "battlefield";}
};
class MTGPlayerCards
{
protected:
void init();
public:
MTGLibrary * library;
MTGGraveyard * graveyard;
MTGHand * hand;
MTGInPlay * inPlay;
MTGInPlay * battlefield; //alias to inPlay
class MTGPlayerCards {
protected:
void init();
MTGStack * stack;
MTGRemovedFromGame * removedFromGame;
MTGRemovedFromGame * exile; //alias to removedFromZone
MTGGameZone * garbage;
MTGGameZone * temp;
public:
MTGLibrary * library;
MTGGraveyard * graveyard;
MTGHand * hand;
MTGInPlay * inPlay;
MTGInPlay * battlefield; //alias to inPlay
MTGPlayerCards(int * idList, int idListSize);
MTGPlayerCards(MTGDeck * deck);
~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1);
void OptimizedHand(Player * who, int amount = 7, int lands = 3, int creatures = 0, int othercards = 4);
void setOwner(Player * player);
void discardRandom(MTGGameZone * from, MTGCardInstance * source);
void drawFromLibrary();
void showHand();
void resetLibrary();
void initDeck(MTGDeck * deck);
MTGCardInstance * putInGraveyard(MTGCardInstance * card);
MTGCardInstance * putInExile(MTGCardInstance * card);
MTGCardInstance * putInLibrary(MTGCardInstance * card);
MTGCardInstance * putInHand(MTGCardInstance * card);
MTGCardInstance * putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
int isInPlay(MTGCardInstance * card);
MTGStack * stack;
MTGRemovedFromGame * removedFromGame;
MTGRemovedFromGame * exile; //alias to removedFromZone
MTGGameZone * garbage;
MTGGameZone * temp;
MTGPlayerCards(int * idList, int idListSize);
MTGPlayerCards(MTGDeck * deck);
~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1);
void OptimizedHand(Player * who,int amount = 7,int lands = 3,int creatures = 0,int othercards = 4);
void setOwner(Player * player);
void discardRandom(MTGGameZone * from,MTGCardInstance * source);
void drawFromLibrary();
void showHand();
void resetLibrary();
void initDeck(MTGDeck * deck);
MTGCardInstance * putInGraveyard(MTGCardInstance * card);
MTGCardInstance * putInExile(MTGCardInstance * card);
MTGCardInstance * putInLibrary(MTGCardInstance * card);
MTGCardInstance * putInHand(MTGCardInstance * card);
MTGCardInstance * putInBattlefield(MTGCardInstance * card);
MTGCardInstance * putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
int isInPlay(MTGCardInstance * card);
int isInGrave(MTGCardInstance * card);
int isInZone(MTGCardInstance * card,MTGGameZone * zone);
};
ostream& operator<<(ostream&, const MTGGameZone&);
+20 -2
View File
@@ -18,7 +18,6 @@ public:
OtherAbilitiesEventReceiver(int _id);
OtherAbilitiesEventReceiver * clone() const;
};
class MTGPutInPlayRule: public MTGAbility
{
public:
@@ -37,10 +36,11 @@ public:
class MTGAlternativeCostRule: public MTGAbility
{
public:
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int isReactingToClick(MTGCardInstance * card, ManaCost * mana, ManaCost *alternateManaCost);
int reactToClick(MTGCardInstance * card, ManaCost * alternateManaCost, MTGGameZone * originatingZone, int paymentType = ManaCost::MANA_PAID);
int reactToClick(MTGCardInstance * card, ManaCost * alternateManaCost, int paymentType = ManaCost::MANA_PAID);
int reactToClick(MTGCardInstance * card);
int testDestroy();
@@ -71,6 +71,7 @@ public:
class MTGFlashBackRule: public MTGAlternativeCostRule
{
public:
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card);
int testDestroy();
@@ -98,9 +99,26 @@ public:
virtual MTGRetraceRule * clone() const;
};
class MTGMorphCostRule: public MTGAbility
{
public:
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card);
int testDestroy();
virtual ostream& toString(ostream& out) const;
MTGMorphCostRule(int _id);
const char * getMenuText()
{
return "Play Morphed";
}
virtual MTGMorphCostRule * clone() const;
};
class MTGAttackRule: public MTGAbility, public Limitor
{
public:
virtual bool select(Target*);
virtual bool greyout(Target*);
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
+71 -71
View File
@@ -4,6 +4,7 @@
#include "utils.h"
#include "MTGDefinitions.h"
class ManaCostHybrid;
class ExtraCosts;
class ExtraCost;
@@ -11,90 +12,89 @@ class MTGAbility;
class MTGCardInstance;
class Player;
class ManaCost
{
protected:
int cost[Constants::MTG_NB_COLORS + 1];
ManaCostHybrid * hybrids[10];
unsigned int nbhybrids;
int extraCostsIsCopy;
class ManaCost{
protected:
int cost[Constants::MTG_NB_COLORS+1];
ManaCostHybrid * hybrids[10];
unsigned int nbhybrids;
int extraCostsIsCopy;
public:
enum{
MANA_UNPAID = 0,
MANA_PAID = 1,
MANA_PAID_WITH_KICKER = 2,
MANA_PAID_WITH_ALTERNATIVE = 3,
MANA_PAID_WITH_BUYBACK = 4,
MANA_PAID_WITH_FLASHBACK = 5,
MANA_PAID_WITH_RETRACE = 6,
MANA_PAID_WITH_MORPH = 7
public:
enum
{
MANA_UNPAID = 0,
MANA_PAID = 1,
MANA_PAID_WITH_KICKER = 2,
MANA_PAID_WITH_ALTERNATIVE = 3,
MANA_PAID_WITH_BUYBACK = 4,
MANA_PAID_WITH_FLASHBACK = 5,
MANA_PAID_WITH_RETRACE = 6
};
ExtraCosts * extraCosts;
ManaCost * kicker;
ManaCost * alternative;
ManaCost * BuyBack;
ManaCost * FlashBack;
ManaCost * Retrace;
ManaCost * morph;
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL, MTGCardInstance * c = NULL);
virtual void init();
void x();
int hasX();
ManaCost(int _cost[], int nb_elems = 1);
ManaCost();
~ManaCost();
ManaCost(ManaCost * _manaCost);
void copy (ManaCost * _manaCost);
int isNull();
int getConvertedCost();
string toString();
int getCost(int color);
//Returns NULL if i is greater than nbhybrids
ManaCostHybrid * getHybridCost(unsigned int i);
int hasColor(int color);
int remove (int color, int value);
int add(int color, int value);
};
ExtraCosts * extraCosts;
ManaCost * kicker;
ManaCost * alternative;
ManaCost * BuyBack;
ManaCost * FlashBack;
ManaCost * Retrace;
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL, MTGCardInstance * c = NULL);
virtual void init();
void x();
int hasX();
ManaCost(int _cost[], int nb_elems = 1);
ManaCost();
~ManaCost();
ManaCost(ManaCost * _manaCost);
void copy(ManaCost * _manaCost);
int isNull();
int getConvertedCost();
string toString();
int getCost(int color);
//Returns NULL if i is greater than nbhybrids
ManaCostHybrid * getHybridCost(unsigned int i);
int hasColor(int color);
int remove(int color, int value);
int add(int color, int value);
//
// Extra Costs (sacrifice,counters...)
//
int addExtraCost(ExtraCost * _cost);
int setExtraCostsAction(MTGAbility * action, MTGCardInstance * card);
int isExtraPaymentSet();
int canPayExtra();
int doPayExtra();
//
// Extra Costs (sacrifice,counters...)
//
int addExtraCost(ExtraCost * _cost);
int setExtraCostsAction(MTGAbility * action, MTGCardInstance * card);
int isExtraPaymentSet();
int canPayExtra();
int doPayExtra();
int addHybrid(int c1, int v1, int c2, int v2);
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
void randomDiffHybrids(ManaCost * _cost, int diff[]);
int add(ManaCost * _cost);
int pay (ManaCost * _cost);
int addHybrid(int c1, int v1, int c2, int v2);
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
void randomDiffHybrids(ManaCost * _cost, int diff[]);
int add(ManaCost * _cost);
int pay(ManaCost * _cost);
//return 1 if _cost can be paid with current data, 0 otherwise
int canAfford(ManaCost * _cost);
//return 1 if _cost can be paid with current data, 0 otherwise
int canAfford(ManaCost * _cost);
int isPositive();
ManaCost * Diff(ManaCost * _cost);
int isPositive();
ManaCost * Diff(ManaCost * _cost);
#ifdef WIN32
void Dump();
void Dump();
#endif
};
std::ostream& operator<<(std::ostream& out, const ManaCost& m);
class ManaPool: public ManaCost
{
class ManaPool:public ManaCost{
protected:
Player * player;
Player * player;
public:
void init();
ManaPool(Player * player);
ManaPool(ManaCost * _manaCost, Player * player);
int remove(int color, int value);
int add(int color, int value, MTGCardInstance * source = NULL);
int add(ManaCost * _cost, MTGCardInstance * source = NULL);
int pay(ManaCost * _cost);
void init();
ManaPool(Player * player);
ManaPool(ManaCost * _manaCost, Player * player);
int remove (int color, int value);
int add(int color, int value, MTGCardInstance * source = NULL);
int add(ManaCost * _cost, MTGCardInstance * source = NULL);
int pay (ManaCost * _cost);
};
#endif
+1
View File
@@ -41,6 +41,7 @@ public:
bool onlyoneboth;
bool bothrestrictedspell;
bool bothrestrictedcreature;
bool isPoisoned;
MTGPlayerCards * game;
string deckFile;
string deckFileSmall;
+82 -65
View File
@@ -1,6 +1,6 @@
/*
Filter-like system for determining if a card meats certain criteria, for this and thisforeach autos
*/
Filter-like system for determining if a card meats certain criteria, for this and thisforeach autos
*/
#ifndef _THISDESCRIPTOR_H_
#define _THISDESCRIPTOR_H_
@@ -10,102 +10,119 @@
#include "MTGCardInstance.h"
#include "CardDescriptor.h"
class ThisDescriptor
{
public:
int comparisonMode;
int comparisonCriterion;
virtual int match(MTGCardInstance * card) = 0;
int matchValue(int value);
virtual ~ThisDescriptor();
class ThisDescriptor{
public:
int comparisonMode;
int comparisonCriterion;
virtual int match(MTGCardInstance * card) = 0;
int matchValue(int value);
virtual ~ThisDescriptor();
};
class ThisDescriptorFactory
{
class ThisDescriptorFactory{
public:
ThisDescriptor * createThisDescriptor(string s);
ThisDescriptor * createThisDescriptor(string s);
};
class ThisCounter: public ThisDescriptor
{
public:
Counter * counter;
class ThisCounter:public ThisDescriptor{
public:
Counter * counter;
virtual int match(MTGCardInstance * card);
ThisCounter(Counter * _counter);
ThisCounter(int power, int toughness, int nb, const char * name);
~ThisCounter();
};
class ThisCounterAny:public ThisDescriptor{
public:
virtual int match(MTGCardInstance *card);
ThisCounterAny(int nb);
};
class ThisControllerlife:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisCounter(Counter * _counter);
ThisCounter(int power, int toughness, int nb, const char * name);
~ThisCounter();
};
class ThisCounterAny: public ThisDescriptor
{
public:
virtual int match(MTGCardInstance *card);
ThisCounterAny(int nb);
};
class ThisControllerlife: public ThisDescriptor
{
public:
virtual int match(MTGCardInstance * card);
ThisControllerlife(int life);
};
class ThisOpponentlife: public ThisDescriptor
{
public:
class ThisOpponentlife:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisOpponentlife(int olife);
};
class ThisEquip: public ThisDescriptor
{
public:
class ThisEquip:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisEquip(int equipment);
};
class ThisAttacked: public ThisDescriptor
{
public:
class ThisAuras:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisAttacked(int attack);
ThisAuras(int auras);
};
class ThisNotBlocked: public ThisDescriptor
{
public:
class ThisOpponentDamageAmount:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisNotBlocked(int unblocked);
ThisOpponentDamageAmount(int damagecount);
};
class ThisPower: public ThisDescriptor
{
public:
class ThisUntapped:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisUntapped(int untapped);
};
class ThisTapped:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisTapped(int tapped);
};
class ThisAttacked:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisAttacked(int attack);
};
class ThisNotBlocked:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisNotBlocked(int unblocked);
};
class ThisPower:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisPower(int power);
};
class ThisToughness: public ThisDescriptor
{
public:
class ThisToughness:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisToughness(int toughness);
};
class ThisX: public ThisDescriptor
{
public:
class ThisX:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisX(int x);
};
#endif
#endif
+126 -130
View File
@@ -26,217 +26,213 @@ public:
TARGET_FROM,
};
int type; //Deprecated, use dynamic casting instead
WEvent(int type = NOT_SPECIFIED);
virtual ~WEvent() {};
virtual std::ostream& toString(std::ostream& out) const;
virtual int getValue()
{
return 0;
}
;
virtual Targetable * getTarget(int target)
{
return 0;
}
;
WEvent(int type = NOT_SPECIFIED);
virtual ~WEvent() {};
virtual std::ostream& toString(std::ostream& out) const;
virtual int getValue() {return 0;};
virtual Targetable * getTarget(int target) {return 0;};
};
struct WEventZoneChange: public WEvent
{
MTGCardInstance * card;
MTGGameZone * from;
MTGGameZone * to;
WEventZoneChange(MTGCardInstance * card, MTGGameZone * from, MTGGameZone *to);
virtual ~WEventZoneChange() {};
virtual std::ostream& toString(std::ostream& out) const;
struct WEventZoneChange : public WEvent {
MTGCardInstance * card;
MTGGameZone * from;
MTGGameZone * to;
WEventZoneChange(MTGCardInstance * card, MTGGameZone * from, MTGGameZone *to);
virtual ~WEventZoneChange() {};
virtual std::ostream& toString(std::ostream& out) const;
virtual Targetable * getTarget(int target);
};
struct WEventDamage : public WEvent {
Damage * damage;
WEventDamage(Damage * damage);
virtual std::ostream& toString(std::ostream& out) const;
virtual int getValue();
virtual Targetable * getTarget(int target);
};
struct WEventLife : public WEvent {
Player * player;
int amount;
int Ltype;
WEventLife(Player * player,int amount,int Ltype = 0);
virtual Targetable * getTarget(int target);
};
struct WEventDamage: public WEvent
{
Damage * damage;
WEventDamage(Damage * damage);
virtual std::ostream& toString(std::ostream& out) const;
virtual int getValue();
virtual Targetable * getTarget(int target);
struct WEventDamageStackResolved : public WEvent {
WEventDamageStackResolved();
};
struct WEventDamageStackResolved: public WEvent
{
WEventDamageStackResolved();
struct WEventPhaseChange : public WEvent {
Phase * from;
Phase * to;
WEventPhaseChange(Phase * from, Phase * to);
};
struct WEventPhaseChange: public WEvent
{
Phase * from;
Phase * to;
WEventPhaseChange(Phase * from, Phase * to);
};
//Abstract class of event when a card's status changes
struct WEventCardUpdate: public WEvent
{
MTGCardInstance * card;
WEventCardUpdate(MTGCardInstance * card);
struct WEventCardUpdate : public WEvent {
MTGCardInstance * card;
WEventCardUpdate(MTGCardInstance * card);
};
//creature damaged was killed, triggers effects targetter
struct WEventVampire : public WEventCardUpdate {
MTGCardInstance * card;
MTGCardInstance * source;
MTGCardInstance * victem;
WEventVampire(MTGCardInstance * card,MTGCardInstance * source,MTGCardInstance * victem);
virtual Targetable * getTarget(int target);
};
//creature became the target of a spell or ability
struct WEventTarget : public WEventCardUpdate {
MTGCardInstance * card;
MTGCardInstance * source;
WEventTarget(MTGCardInstance * card,MTGCardInstance * source);
virtual Targetable * getTarget(int target);
};
//Event when a card gains/looses types
struct WEventCardChangeType: public WEventCardUpdate
{
int type;
bool before;
bool after;
WEventCardChangeType(MTGCardInstance * card, int type, bool before, bool after);
struct WEventCardChangeType : public WEventCardUpdate {
int type;
bool before;
bool after;
WEventCardChangeType(MTGCardInstance * card, int type, bool before, bool after);
};
//Event when a card is tapped/untapped
struct WEventCardTap: public WEventCardUpdate
{
bool before;
bool after;
WEventCardTap(MTGCardInstance * card, bool before, bool after);
virtual Targetable * getTarget(int target);
struct WEventCardTap : public WEventCardUpdate {
bool before;
bool after;
WEventCardTap(MTGCardInstance * card, bool before, bool after);
virtual Targetable * getTarget(int target);
};
struct WEventCardTappedForMana: public WEventCardUpdate
{
bool before;
bool after;
WEventCardTappedForMana(MTGCardInstance * card, bool before, bool after);
virtual Targetable * getTarget(int target);
struct WEventCardTappedForMana : public WEventCardUpdate {
bool before;
bool after;
WEventCardTappedForMana(MTGCardInstance * card, bool before, bool after);
virtual Targetable * getTarget(int target);
};
//Event when a card's "attacker" status changes
//before:Player/Planeswalker that card was attacking previously
//after: Player/Planeswalker that card is attacking now
struct WEventCreatureAttacker: public WEventCardUpdate
{
Targetable * before;
Targetable * after;
WEventCreatureAttacker(MTGCardInstance * card, Targetable * from, Targetable * to);
struct WEventCreatureAttacker : public WEventCardUpdate {
Targetable * before;
Targetable * after;
WEventCreatureAttacker(MTGCardInstance * card, Targetable * from, Targetable * to);
};
//event when card attacks.
struct WEventCardAttacked: public WEventCardUpdate
{
WEventCardAttacked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
struct WEventCardAttacked : public WEventCardUpdate {
WEventCardAttacked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//event when card attacks alone.
struct WEventCardAttackedAlone: public WEventCardUpdate
{
WEventCardAttackedAlone(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
struct WEventCardAttackedAlone : public WEventCardUpdate {
WEventCardAttackedAlone(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//event when card attacks but is not blocked.
struct WEventCardAttackedNotBlocked: public WEventCardUpdate
{
WEventCardAttackedNotBlocked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
struct WEventCardAttackedNotBlocked : public WEventCardUpdate {
WEventCardAttackedNotBlocked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//event when card attacks but is blocked.
struct WEventCardAttackedBlocked: public WEventCardUpdate
{
WEventCardAttackedBlocked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
struct WEventCardAttackedBlocked : public WEventCardUpdate {
WEventCardAttackedBlocked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//event when card blocked.
struct WEventCardBlocked: public WEventCardUpdate
{
WEventCardBlocked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
struct WEventCardBlocked : public WEventCardUpdate {
WEventCardBlocked(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//event when card is sacrificed.
struct WEventCardSacrifice: public WEventCardUpdate
{
WEventCardSacrifice(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
struct WEventCardSacrifice : public WEventCardUpdate {
WEventCardSacrifice(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//event when card is discarded.
struct WEventCardDiscard: public WEventCardUpdate
{
WEventCardDiscard(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
struct WEventCardDiscard : public WEventCardUpdate {
WEventCardDiscard(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//Event when a card's "defenser" status changes
//before : attacker that card was blocking previously
//after: attacker that card is blocking now
struct WEventCreatureBlocker: public WEventCardUpdate
{
MTGCardInstance * before;
MTGCardInstance * after;
WEventCreatureBlocker(MTGCardInstance * card, MTGCardInstance * from, MTGCardInstance * to);
struct WEventCreatureBlocker : public WEventCardUpdate {
MTGCardInstance * before;
MTGCardInstance * after;
WEventCreatureBlocker(MTGCardInstance * card,MTGCardInstance * from,MTGCardInstance * to);
};
//Event sent when attackers have been chosen and they
//cannot be changed any more.
struct WEventAttackersChosen: public WEvent
{
struct WEventAttackersChosen : public WEvent {
};
//Event sent when blockers have been chosen and they
//cannot be changed any more.
struct WEventBlockersChosen: public WEvent
{
struct WEventBlockersChosen : public WEvent {
};
struct WEventcardDraw: public WEvent
{
WEventcardDraw(Player * player, int nb_cards);
Player * player;
int nb_cards;
virtual Targetable * getTarget(Player * player);
struct WEventcardDraw : public WEvent {
WEventcardDraw(Player * player,int nb_cards);
Player * player;
int nb_cards;
virtual Targetable * getTarget(Player * player);
};
//Event when a blocker is reordered
//exchangeWith: exchange card's position with exchangeWith's position
//attacker:both card and exchangeWith *should* be in attacker's "blockers" list.
struct WEventCreatureBlockerRank: public WEventCardUpdate
{
MTGCardInstance * exchangeWith;
MTGCardInstance * attacker;
WEventCreatureBlockerRank(MTGCardInstance * card, MTGCardInstance * exchangeWith, MTGCardInstance * attacker);
struct WEventCreatureBlockerRank : public WEventCardUpdate {
MTGCardInstance * exchangeWith;
MTGCardInstance * attacker;
WEventCreatureBlockerRank(MTGCardInstance * card,MTGCardInstance * exchangeWith, MTGCardInstance * attacker);
};
//Event when a combat phase step ends
struct WEventCombatStepChange: public WEvent
struct WEventCombatStepChange : public WEvent
{
CombatStep step;
WEventCombatStepChange(CombatStep);
CombatStep step;
WEventCombatStepChange(CombatStep);
};
//Event when a mana is engaged
//color : color
struct WEventEngageMana: public WEvent
{
int color;
MTGCardInstance* card;
ManaPool * destination;
WEventEngageMana(int color, MTGCardInstance* card, ManaPool * destination);
struct WEventEngageMana : public WEvent {
int color;
MTGCardInstance* card;
ManaPool * destination;
WEventEngageMana(int color, MTGCardInstance* card, ManaPool * destination);
};
//Event when a mana is consumed
//color : color
struct WEventConsumeMana: public WEvent
{
int color;
ManaPool * source;
WEventConsumeMana(int color, ManaPool * source);
struct WEventConsumeMana : public WEvent {
int color;
ManaPool * source;
WEventConsumeMana(int color, ManaPool * source);
};
//Event when a manapool is emptied
//color : color
struct WEventEmptyManaPool: public WEvent
{
ManaPool * source;
WEventEmptyManaPool(ManaPool * source);
struct WEventEmptyManaPool : public WEvent {
ManaPool * source;
WEventEmptyManaPool(ManaPool * source);
};
std::ostream& operator<<(std::ostream&, const WEvent&);
+177 -105
View File
@@ -150,7 +150,7 @@ ManaCost * AIPlayer::getPotentialMana(MTGCardInstance * target)
MTGCardInstance * card = amp->source;
if (card == target)
used[card] = true; //http://code.google.com/p/wagic/issues/detail?id=76
if (!used[card] && amp->isReactingToClick(card) && amp->output->getConvertedCost() == 1)
if (!used[card] && amp->isReactingToClick(card) && amp->output->getConvertedCost() >= 1)
{
result->add(amp->output);
used[card] = true;
@@ -771,7 +771,7 @@ int AIPlayer::effectBadOrGood(MTGCardInstance * card, int mode, TargetChooser *
return BAKA_EFFECT_DONTKNOW;
}
int AIPlayer::chooseTarget(TargetChooser * _tc, Player * forceTarget)
int AIPlayer::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCardInstance * Choosencard)
{
vector<Targetable *> potentialTargets;
TargetChooser * tc = _tc;
@@ -780,11 +780,13 @@ int AIPlayer::chooseTarget(TargetChooser * _tc, Player * forceTarget)
int checkOnly = 0;
if (tc)
{
if(!Choosencard)
checkOnly = 1;
}
else
{
tc = gameObs->getCurrentTargetChooser();
tc = gameObs->getCurrentTargetChooser();
}
if (!tc)
return 0;
@@ -845,6 +847,35 @@ int AIPlayer::chooseTarget(TargetChooser * _tc, Player * forceTarget)
}
}
}
//targetting the stack
zone = playerZones->stack;
for (int k = 0; k < zone->nb_cards; k++)
{
MTGCardInstance* card = zone->cards[k];
if (!tc->alreadyHasTarget(card) && tc->canTarget(card) && nbtargets < 50)
{
if (checkOnly)
return 1;
int multiplier = 1;
if (getStats() && getStats()->isInTop(card, 10))
{
multiplier++;
if (getStats()->isInTop(card, 5))
{
multiplier++;
if (getStats()->isInTop(card, 3))
{
multiplier++;
}
}
}
for (int l = 0; l < multiplier; l++)
{
potentialTargets.push_back(card);
nbtargets++;
}
}
}
}
if (nbtargets)
{
@@ -853,26 +884,28 @@ int AIPlayer::chooseTarget(TargetChooser * _tc, Player * forceTarget)
switch (type)
{
case TARGET_CARD:
{
MTGCardInstance * card = ((MTGCardInstance *) potentialTargets[i]);
clickstream.push(NEW AIAction(card));
return 1;
break;
}
{
MTGCardInstance * card = ((MTGCardInstance *) potentialTargets[i]);
clickstream.push(NEW AIAction(card));
return 1;
break;
}
case TARGET_PLAYER:
{
Player * player = ((Player *) potentialTargets[i]);
clickstream.push(NEW AIAction(player));
return 1;
break;
}
{
Player * player = ((Player *) potentialTargets[i]);
clickstream.push(NEW AIAction(player));
return 1;
break;
}
}
}
//Couldn't find any valid target,
//usually that's because we played a card that has bad side effects (ex: when X comes into play, return target land you own to your hand)
//so we try again to choose a target in the other player's field...
if (checkOnly)
{
return 0;
}
int cancel = gameObs->cancelCurrentAction();
if (!cancel && !forceTarget)
return chooseTarget(_tc, target->opponent());
@@ -1180,6 +1213,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
if (tc)
{
int hasTarget = (chooseTarget(tc));
if(tc)
delete tc;
if (!hasTarget)
continue;
@@ -1241,7 +1275,6 @@ void AIPlayerBaka::initTimer()
{
timer = 0.1f;
}
int AIPlayerBaka::computeActions()
{
GameObserver * g = GameObserver::GetInstance();
@@ -1256,121 +1289,160 @@ int AIPlayerBaka::computeActions()
if (chooseTarget())
return 1;
int currentGamePhase = g->getCurrentGamePhase();
if (g->isInterrupting == this)
{ // interrupting
selectAbility();
return 1;
static bool findingCard = false;
//this guard is put in place to prevent Ai from
//ever running computeActions() function WHILE its already doing so.
// Break if this happens in debug mode. If this happens, it's actually a bug
assert(!findingCard);
if (findingCard)
{//is already looking kick me out of this function!
return 0;
}
if (p != this && (Player*)g->isInterrupting == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 1)
{
findingCard = true;
CardDescriptor cd;
ManaCost * currentMana = getPotentialMana();
bool potential = false;
if (currentMana->getConvertedCost())
{
//if theres mana i can use there then potential is true.
potential = true;
}
//look for an instant of ability to interupt with
if((castrestrictedspell == false && nospellinstant == false)&&
(onlyonecast == false || castcount < 2) && (onlyoneinstant == false || castcount < 2))
{
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "instant");
}
if (!nextCardToPlay)
{
selectAbility();
}
}
if (currentMana != NULL)
delete (currentMana);
if (nextCardToPlay)
{
if (potential)
{
tapLandsForMana(nextCardToPlay->getManaCost());
}
AIAction * a = NEW AIAction(nextCardToPlay);
clickstream.push(a);
findingCard = false;
nextCardToPlay = NULL;
return 1;
}
nextCardToPlay = NULL;
findingCard = false;
return 0;
}
else if (p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0)
else if(p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0)
{ //standard actions
CardDescriptor cd;
switch (currentGamePhase)
{
case Constants::MTG_PHASE_FIRSTMAIN:
case Constants::MTG_PHASE_SECONDMAIN:
{
bool potential = false;
ManaCost * currentMana = getPotentialMana();
if (currentMana->getConvertedCost())
{
//if theres mana i can use there then potential is true.
potential = true;
}
nextCardToPlay = FindCardToPlay(currentMana, "land");
selectAbility();
//look for the most expensive creature we can afford
if (castrestrictedspell == false && nospellinstant == false)
{
if (onlyonecast == false || castcount < 2)
ManaCost * currentMana = getPotentialMana();
bool potential = false;
if (currentMana->getConvertedCost())
{
if (onlyoneinstant == false || castcount < 2)
//if theres mana i can use there then potential is true.
potential = true;
}
nextCardToPlay = FindCardToPlay(currentMana, "land");
selectAbility();
//look for the most expensive creature we can afford
if((castrestrictedspell == false && nospellinstant == false)&&
(onlyonecast == false || castcount < 2)&&(onlyoneinstant == false || castcount < 2))
{
if (castrestrictedcreature == false && nocreatureinstant == false)
{
if (castrestrictedcreature == false && nocreatureinstant == false)
{
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "creature");
}
}
//Let's Try an enchantment maybe ?
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "enchantment");
}
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "artifact");
}
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "sorcery");
}
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "instant");
}
if (!nextCardToPlay)
{
selectAbility();
nextCardToPlay = FindCardToPlay(currentMana, "creature");
}
}
}
}
if (currentMana != NULL)
delete (currentMana);
if (nextCardToPlay)
{
if (potential)
{
/////////////////////////
//had to force this on Ai other wise it would pay nothing but 1 color for a sunburst card.
//this does not teach it to use manaproducer more effectively, it simply allow it to use the manaproducers it does understand better on sunburst by force.
if (nextCardToPlay->has(Constants::SUNBURST))
//Let's Try an enchantment maybe ?
if (!nextCardToPlay)
{
ManaCost * SunCheck = manaPool;
SunCheck = getPotentialMana();
for (int i = Constants::MTG_NB_COLORS - 1; i > 0; i--)
nextCardToPlay = FindCardToPlay(currentMana, "enchantment");
}
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "artifact");
}
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "sorcery");
}
if (!nextCardToPlay)
{
nextCardToPlay = FindCardToPlay(currentMana, "instant");
}
if (!nextCardToPlay)
{
selectAbility();
}
}
if (currentMana != NULL)
delete (currentMana);
if (nextCardToPlay)
{
if (potential)
{
/////////////////////////
//had to force this on Ai other wise it would pay nothing but 1 color for a sunburst card.
//this does not teach it to use manaproducer more effectively, it simply allow it to use the manaproducers it does understand better on sunburst by force.
if (nextCardToPlay->has(Constants::SUNBURST))
{
//sunburst for Ai
if (SunCheck->hasColor(i))
ManaCost * SunCheck = manaPool;
SunCheck = getPotentialMana();
for (int i = Constants::MTG_NB_COLORS - 1; i > 0; i--)
{
if (nextCardToPlay->getManaCost()->hasColor(i) > 0)
{//do nothing if the card already has this color.
}
else
//sunburst for Ai
if (SunCheck->hasColor(i))
{
if (nextCardToPlay->sunburst < nextCardToPlay->getManaCost()->getConvertedCost())
if (nextCardToPlay->getManaCost()->hasColor(i) > 0)
{//do nothing if the card already has this color.
}
else
{
nextCardToPlay->getManaCost()->add(i, 1);
nextCardToPlay->getManaCost()->remove(0, 1);
nextCardToPlay->sunburst += 1;
if (nextCardToPlay->sunburst < nextCardToPlay->getManaCost()->getConvertedCost())
{
nextCardToPlay->getManaCost()->add(i, 1);
nextCardToPlay->getManaCost()->remove(0, 1);
nextCardToPlay->sunburst += 1;
}
}
}
}
delete (SunCheck);
}
delete (SunCheck);
/////////////////////////
tapLandsForMana(nextCardToPlay->getManaCost());
}
/////////////////////////
tapLandsForMana(nextCardToPlay->getManaCost());
AIAction * a = NEW AIAction(nextCardToPlay);
clickstream.push(a);
return 1;
}
AIAction * a = NEW AIAction(nextCardToPlay);
clickstream.push(a);
return 1;
else
{
selectAbility();
}
if (p->getManaPool()->getConvertedCost() > 0 && Checked == false)//not the best thing ever, but allows the Ai a chance to double check if its mana pool has something before moving on, atleast one time.
{
Checked = true;
computeActions();
}
break;
}
else
{
selectAbility();
}
if (p->getManaPool()->getConvertedCost() > 0 && Checked == false)//not the best thing ever, but allows the Ai a chance to double check if its mana pool has something before moving on, atleast one time.
{
Checked = true;
computeActions();
}
break;
}
case Constants::MTG_PHASE_COMBATATTACKERS:
chooseAttackers();
break;
+46 -2
View File
@@ -214,7 +214,8 @@ Interruptible(id), tc(tc), cost(_cost), payResult(payResult)
int Spell::computeX(MTGCardInstance * card)
{
ManaCost * c = cost->Diff(card->getManaCost());
int x = c->getCost(Constants::MTG_NB_COLORS);
int x = 0;
x = c->getCost(Constants::MTG_NB_COLORS);
delete c;
return x;
}
@@ -222,7 +223,8 @@ int Spell::computeX(MTGCardInstance * card)
int Spell::computeXX(MTGCardInstance * card)
{
ManaCost * c = cost->Diff(card->getManaCost());
int xx = c->getCost(Constants::MTG_NB_COLORS) / 2;
int xx = 0;
xx = c->getCost(Constants::MTG_NB_COLORS) / 2;
delete c;
return xx;
}
@@ -451,7 +453,39 @@ ostream& DrawAction::toString(ostream& out) const
out << "DrawAction ::: nbcards : " << nbcards << " ; player : " << player;
return out;
}
//////
LifeAction::LifeAction(int id, Damageable * _target, int amount) :
Interruptible(id), amount(amount),target(_target)
{
}
int LifeAction::resolve()
{
target->life += amount;
return 1;
}
void LifeAction::Render()
{
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
char buffer[200];
if(amount >= 0)
sprintf(buffer, _("Player gains %i life").c_str(), amount);
else if(amount >= 0)
sprintf(buffer, _("Player loses %i life").c_str(), amount);
else
sprintf(buffer, _("Nothing happened").c_str(), amount);
mFont->DrawString(buffer, x + 20, y, JGETEXT_LEFT);
}
ostream& LifeAction::toString(ostream& out) const
{
out << "LifeAction ::: amount : " << amount << " ; target : " << target;
return out;
}
/* The Action Stack itself */
int ActionStack::addPutInGraveyard(MTGCardInstance * card)
{
PutInGraveyard * death = NEW PutInGraveyard(mCount, card);
@@ -482,10 +516,20 @@ int ActionStack::addDraw(Player * player, int nb_cards)
return 1;
}
int ActionStack::addLife(Damageable * _target, int amount)
{
LifeAction * life = NEW LifeAction(mCount, _target, amount);
addAction(life);
return 1;
}
int ActionStack::addDamage(MTGCardInstance * _source, Damageable * _target, int _damage)
{
Damage * damage = NEW Damage(_source, _target, _damage);
addAction(damage);
_source->thatmuch = _damage;
_target->thatmuch = _damage;
_target->lifeLostThisTurn += _damage;
return 1;
}
File diff suppressed because it is too large Load Diff
+59 -1
View File
@@ -42,6 +42,32 @@ void CardDescriptor::unsecuresetfresh(int k)
fresh = k;
}
void CardDescriptor::setisMultiColored(int w)
{
isMultiColored = w;
}
void CardDescriptor::setisBlackAndWhite(int w)
{
isBlackAndWhite = w;
}
void CardDescriptor::setisRedAndBlue(int w)
{
isRedAndBlue = w;
}
void CardDescriptor::setisBlackAndGreen(int w)
{
isBlackAndGreen = w;
}
void CardDescriptor::setisBlueAndGreen(int w)
{
isBlueAndGreen = w;
}
void CardDescriptor::setisRedAndWhite(int w)
{
isRedAndWhite = w;
}
void CardDescriptor::setNegativeSubtype(string value)
{
int id = Subtypes::subtypesList->find(value);
@@ -203,10 +229,42 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card)
match = NULL;
}
if ((isToken == -1 && card->isToken) || (isToken == 1 && !card->isToken))
if ((isMultiColored == -1 && card->isMultiColored) || (isMultiColored == 1 && !card->isMultiColored))
{
match = NULL;
}
if ((isBlackAndWhite == -1 && card->isBlackAndWhite) || (isBlackAndWhite == 1 && !card->isBlackAndWhite))
{
match = NULL;
}
if ((isRedAndBlue == -1 && card->isRedAndBlue) || (isRedAndBlue == 1 && !card->isRedAndBlue))
{
match = NULL;
}
if ((isBlackAndGreen == -1 && card->isBlackAndGreen) || (isBlackAndGreen == 1 && !card->isBlackAndGreen))
{
match = NULL;
}
if ((isBlueAndGreen == -1 && card->isBlueAndGreen) || (isBlueAndGreen == 1 && !card->isBlueAndGreen))
{
match = NULL;
}
if ((isRedAndWhite == -1 && card->isRedAndWhite) || (isRedAndWhite == 1 && !card->isRedAndWhite))
{
match = NULL;
}
if ((isLeveler == -1 && card->isLeveler) || (isLeveler == 1 && !card->isLeveler))
{
match = NULL;
}
if ((CDenchanted == -1 && card->enchanted) || (CDenchanted == 1 && !card->enchanted))
{
match = NULL;
}
if ((isToken == -1 && card->isToken) || (isToken == 1 && !card->isToken))
{
match = NULL;
}
if (attacker == 1)
{
if (defenser == &AnyCard)
+18 -3
View File
@@ -141,6 +141,7 @@ void CardGui::Render()
bool alternate = true;
JQuad * quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
#if defined (WIN32) || defined (LINUX)
//On pcs we render the big image if the thumbnail is not available
if (!quad) quad = WResourceManager::Instance()->RetrieveCard(card);
@@ -160,7 +161,13 @@ void CardGui::Render()
shadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,255,255,255));
renderer->RenderQuad(shadow, actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
}
JQuad* extracostshadow = NULL;
if(card->isExtraCostTarget == true)
{
extracostshadow = WResourceManager::Instance()->GetQuad("extracostshadow");
extracostshadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,100,0,0));
renderer->RenderQuad(extracostshadow, actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
}
if (quad)
{
quad->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
@@ -185,7 +192,7 @@ void CardGui::Render()
icon = WResourceManager::Instance()->GetQuad("c_red");
else if (card->hasSubtype("island"))
icon = WResourceManager::Instance()->GetQuad("c_blue");
if (icon)
{
icon->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
@@ -194,6 +201,14 @@ void CardGui::Render()
}
}
JQuad * mor = NULL;
if(card->isMorphed && !alternate)
{
mor = WResourceManager::Instance()->GetQuad("morph");
mor->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(mor, actX, actY, actT,scale, scale);
}
//draws the numbers power/toughness
if (card->isCreature())
{
@@ -236,7 +251,6 @@ void CardGui::Render()
shadow->SetColor(ARGB(200,255,255,255));
renderer->RenderQuad(shadow, actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16);
}
PlayGuiObject::Render();
}
@@ -552,6 +566,7 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
break;
}
}
if (q && q->mTex)
{
q->SetHotSpot(static_cast<float> (q->mTex->mWidth / 2), static_cast<float> (q->mTex->mHeight / 2));
+21
View File
@@ -29,6 +29,8 @@ CardPrimitive::CardPrimitive(CardPrimitive * source)
power = source->power;
toughness = source->toughness;
restriction = source->restriction;
otherrestriction = source->otherrestriction;
magicText = source->magicText;
for (map<string, string>::const_iterator it = source->magicTexts.begin(); it != source->magicTexts.end(); ++it)
@@ -50,6 +52,7 @@ int CardPrimitive::init()
magicTexts.clear();
spellTargetType = "";
alias = 0;
bool hasRestriction = false;
return 1;
}
@@ -83,6 +86,24 @@ bool CardPrimitive::isSpell()
return (!isCreature() && !isLand());
}
void CardPrimitive::setRestrictions(int _restriction)
{
restriction = _restriction;
}
int CardPrimitive::getRestrictions()
{
return restriction;
}
void CardPrimitive::setOtherRestrictions(string _restriction)
{
otherrestriction = _restriction;
}
void CardPrimitive::getOtherRestrictions()
{
otherrestriction;
}
void CardPrimitive::setColor(string _color, int removeAllOthers)
{
if (_color.compare("blue") == 0)
+5 -1
View File
@@ -94,7 +94,9 @@ int Damage::resolve()
}
if ((_target)->has(Constants::ABSORB))
{
damage -= 1;
damage -= (_target)->basicAbilities[Constants::ABSORB];
if(damage < 0)
damage = 0;
}
if ((_target)->has(Constants::WILTING))
{
@@ -132,6 +134,8 @@ int Damage::resolve()
{
_target->counters->addCounter(-1, -1);
}
if(_target->toughness <= 0 && _target->has(Constants::INDESTRUCTIBLE))
_target->controller()->game->putInGraveyard(_target);
}
else if (target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::INFECT))
+1 -1
View File
@@ -39,7 +39,7 @@ void DuelLayers::init()
action->Add(NEW MTGLifelinkRule(-1));
action->Add(NEW MTGDeathtouchRule(-1));
action->Add(NEW OtherAbilitiesEventReceiver(-1));
action->Add(NEW MTGMorphCostRule(-1));
//Other display elements
action->Add(NEW HUDDisplay(-1));
+38 -2
View File
@@ -79,7 +79,13 @@ int LifeCost::doPay()
MTGCardInstance * _target = (MTGCardInstance *) target;
if (target)
{
_target->controller()->thatmuch = 1;
WEvent * lifed = NULL;
lifed = NEW WEventLife(_target->controller(),-1,1);
GameObserver * game = GameObserver::GetInstance();
game->receiveEvent(lifed);
_target->controller()->life -= 1;
_target->controller()->lifeLostThisTurn += 1;
target = NULL;
if (tc)
tc->initTargets();
@@ -263,6 +269,20 @@ TapTargetCost::TapTargetCost(TargetChooser *_tc) :
{
}
int TapTargetCost::isPaymentSet()
{
if (target && target->isTapped())
{
tc->removeTarget(target);
target->isExtraCostTarget = false;
target = NULL;
return 0;
}
if (target)
return 1;
return 0;
}
int TapTargetCost::doPay()
{
MTGCardInstance * _target = (MTGCardInstance *) target;
@@ -563,8 +583,19 @@ int ExtraCosts::tryToSetPayment(MTGCardInstance * card)
{
for (size_t i = 0; i < costs.size(); i++)
{
if (int result = costs[i]->setPayment(card))
return result;
if(!costs[i]->isPaymentSet())
{
for(size_t k = 0; k < costs.size(); k++)
{
if(card == costs[k]->target)
return 0;
}
if (int result = costs[i]->setPayment(card))
{
card->isExtraCostTarget = true;
return result;
}
}
}
return 0;
}
@@ -584,7 +615,10 @@ int ExtraCosts::canPay()
for (size_t i = 0; i < costs.size(); i++)
{
if (!costs[i]->canPay())
{
costs[i]->target->isExtraCostTarget = false;
return 0;
}
}
return 1;
}
@@ -594,6 +628,8 @@ int ExtraCosts::doPay()
int result = 0;
for (size_t i = 0; i < costs.size(); i++)
{
if(costs[i]->target)
costs[i]->target->isExtraCostTarget = false;
result += costs[i]->doPay();
}
return result;
+8
View File
@@ -191,6 +191,8 @@ void GameApp::Create()
WResourceManager::Instance()->RetrieveTexture("BattleIcon.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("DefenderIcon.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("shadow.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("extracostshadow.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("morph.jpg", RETRIEVE_MANAGE);
jq = WResourceManager::Instance()->RetrieveQuad("BattleIcon.png", 0, 0, 25, 25, "BattleIcon", RETRIEVE_MANAGE);
if (jq)
@@ -201,6 +203,12 @@ void GameApp::Create()
jq = WResourceManager::Instance()->RetrieveQuad("shadow.png", 0, 0, 16, 16, "shadow", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(8, 8);
jq = WResourceManager::Instance()->RetrieveQuad("extracostshadow.png", 0, 0, 16, 16, "extracostshadow", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(8, 8);
jq = WResourceManager::Instance()->RetrieveQuad("morph.jpg", 0, 0, MTG_MINIIMAGE_WIDTH, MTG_MINIIMAGE_HEIGHT, "morph", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(static_cast<float> (jq->mTex->mWidth / 2), static_cast<float> (jq->mTex->mHeight / 2));
jq = WResourceManager::Instance()->RetrieveQuad("phasebar.png", 0, 0, 0, 0, "phasebar", RETRIEVE_MANAGE);
LOG("Init Collection");
+195 -27
View File
@@ -118,6 +118,7 @@ void GameObserver::nextGamePhase()
currentPlayer->onlyoneinstant = false;
currentPlayer->damageCount = 0;
currentPlayer->preventable = 0;
currentPlayer->isPoisoned = false;
mLayers->actionLayer()->cleanGarbage(); //clean abilities history for this turn;
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
mLayers->actionLayer()->Update(0);
@@ -140,6 +141,8 @@ void GameObserver::nextGamePhase()
while (currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize == false)
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
mLayers->actionLayer()->Update(0);
currentPlayer->lifeLostThisTurn = 0;
currentPlayer->opponent()->lifeLostThisTurn = 0;
return nextGamePhase();
}
@@ -382,6 +385,14 @@ void GameObserver::gameStateBasedEffects()
{
players[i]->canPutLandsIntoPlay = true;
}
if(players[i]->poisonCount > 0)
{
players[i]->isPoisoned = true;
}
else
{
players[i]->isPoisoned = false;
}
}
if (mLayers->stackLayer()->count(0, NOT_RESOLVED) != 0)
return;
@@ -401,12 +412,77 @@ void GameObserver::gameStateBasedEffects()
{
MTGCardInstance * card = zone->cards[j];
card->afterDamage();
//Remove auras that don't have a valid target anymore
///////////////////////////////////////////////////////
//Remove auras that don't have a valid target anymore//
///////////////////////////////////////////////////////
if (card->target && !isInPlay(card->target) && !card->hasType("equipment"))
{
players[i]->game->putInGraveyard(card);
}
card->enchanted = false;
if (card->target && isInPlay(card->target) && !card->hasType("equipment") && card->hasSubtype("aura"))
{
card->target->enchanted = true;
}
///////////////////////////
//reset extracost shadows//
///////////////////////////
card->isExtraCostTarget = false;
if(mExtraPayment != NULL)
{
for(unsigned int ec = 0;ec < mExtraPayment->costs.size();ec++)
{
if( mExtraPayment->costs[ec]->target)
mExtraPayment->costs[ec]->target->isExtraCostTarget = true;
}
}
//////////////////////
//reset morph hiding//
//////////////////////
if((card->previous && card->previous->morphed && !card->turningOver) || (card->morphed && !card->turningOver))
{
card->morphed = true;
card->isMorphed = true;
}
else
{
card->isMorphed = false;
card->morphed = false;
}
//////////////////////////
//handles phasing events//
//////////////////////////
if((card->has(Constants::PHASING)&& currentGamePhase == Constants::MTG_PHASE_UNTAP && currentPlayer == card->controller() && card->phasedTurn != turn && !card->isPhased) || (card->isTempPhased && !card->isPhased))
{
card->isPhased = true;
card->phasedTurn = turn;
if(card->view)
card->view->alpha = 50;
card->initAttackersDefensers();
}
else if((card->has(Constants::PHASING) || card->isTempPhased)&& currentGamePhase == Constants::MTG_PHASE_UNTAP && currentPlayer == card->controller() && card->phasedTurn != turn)
{
card->isPhased = false;
card->phasedTurn = turn;
if(card->view)
card->view->alpha = 255;
card->isTempPhased = false;
}
if (card->target && isInPlay(card->target) && (card->hasSubtype("equipment") || card->hasSubtype("aura")))
{
card->isPhased = card->target->isPhased;
card->phasedTurn = card->target->phasedTurn;
if(card->view && card->target->view)
card->view->alpha = card->target->view->alpha;
}
//////////////////////////
//forceDestroy over ride//
//////////////////////////
if(card->isInPlay())
{
card->graveEffects = false;
card->exileEffects = false;
}
}
}
//-------------------------------------
@@ -524,22 +600,22 @@ void GameObserver::gameStateBasedEffects()
}
//------------------------------------
if (players[0]->bothrestrictedcreature)
players[1]->castrestrictedcreature = true;
players[1]->castrestrictedcreature = true;
//------------------------------------
if (players[0]->bothrestrictedspell)
players[1]->castrestrictedspell = true;
players[1]->castrestrictedspell = true;
//------------------------------------
if (players[0]->onlyoneboth)
players[1]->onlyoneboth = true;
players[1]->onlyoneboth = true;
//------------------------------------
if (players[1]->bothrestrictedcreature)
players[0]->castrestrictedcreature = true;
players[0]->castrestrictedcreature = true;
//------------------------------------
if (players[1]->bothrestrictedspell)
players[0]->castrestrictedspell = true;
players[0]->castrestrictedspell = true;
//------------------------------------
if (players[1]->onlyoneboth)
players[0]->onlyoneboth = true;
players[0]->onlyoneboth = true;
//------------------------------------
/////////////////////////////////////////////////
//handle end of turn effects while we're at it.//
@@ -552,7 +628,10 @@ void GameObserver::gameStateBasedEffects()
if(!c)break;
while (c->flanked)
{//undoes the flanking on a card
{
/////////////////////////////////
//undoes the flanking on a card//
/////////////////////////////////
c->power += 1;
c->addToToughness(1);
c->flanked -= 1;
@@ -582,14 +661,13 @@ void GameObserver::gameStateBasedEffects()
p->game->putInExile(c);
}
if(nbcards > z->nb_cards)
{
t = 0;
nbcards = z->nb_cards;
}
if(nbcards > z->nb_cards)
{
t = 0;
nbcards = z->nb_cards;
}
}
MTGGameZone * f = p->game->graveyard;
for (int k = 0; k < f->nb_cards; k++)
{
@@ -601,11 +679,55 @@ void GameObserver::gameStateBasedEffects()
{
p->nomaxhandsize = false;
if (!p->bothrestrictedcreature && !p->opponent()->bothrestrictedcreature)
p->castrestrictedcreature = false;
p->castrestrictedcreature = false;
if (!p->bothrestrictedspell && !p->opponent()->bothrestrictedspell)
p->castrestrictedspell = false;
p->castrestrictedspell = false;
p->onlyonecast = false;
}
//////////////////////////
// Check auras on a card//
//////////////////////////
enchantmentStatus();
/////////////////////////////////////
// Check colored statuses on cards //
/////////////////////////////////////
for(int w = 0;w < z->nb_cards;w++)
{
int colored = 0;
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; ++i)
{
if (z->cards[w]->hasColor(i))
++colored;
}
if(colored > 1)
{
z->cards[w]->isMultiColored = 1;
}
else
{
z->cards[w]->isMultiColored = 0;
}
if(z->cards[w]->hasColor(Constants::MTG_COLOR_WHITE) && z->cards[w]->hasColor(Constants::MTG_COLOR_BLACK))
z->cards[w]->isBlackAndWhite = 1;
else
z->cards[w]->isBlackAndWhite = 0;
if(z->cards[w]->hasColor(Constants::MTG_COLOR_RED) && z->cards[w]->hasColor(Constants::MTG_COLOR_BLUE))
z->cards[w]->isRedAndBlue = 1;
else
z->cards[w]->isRedAndBlue = 0;
if(z->cards[w]->hasColor(Constants::MTG_COLOR_GREEN) && z->cards[w]->hasColor(Constants::MTG_COLOR_BLACK))
z->cards[w]->isBlackAndGreen = 1;
else
z->cards[w]->isBlackAndGreen = 0;
if(z->cards[w]->hasColor(Constants::MTG_COLOR_BLUE) && z->cards[w]->hasColor(Constants::MTG_COLOR_GREEN))
z->cards[w]->isBlueAndGreen = 1;
else
z->cards[w]->isBlueAndGreen = 0;
if(z->cards[w]->hasColor(Constants::MTG_COLOR_RED) && z->cards[w]->hasColor(Constants::MTG_COLOR_WHITE))
z->cards[w]->isRedAndWhite = 1;
else
z->cards[w]->isRedAndWhite = 0;
}
}
///////////////////////////////////
//phase based state effects------//
@@ -613,33 +735,58 @@ void GameObserver::gameStateBasedEffects()
if (combatStep == TRIGGERS)
{
if (!mLayers->stackLayer()->getNext(NULL, 0, NOT_RESOLVED) && !targetChooser
&& !mLayers->actionLayer()->isWaitingForAnswer())
mLayers->stackLayer()->AddNextCombatStep();
&& !mLayers->actionLayer()->isWaitingForAnswer())
mLayers->stackLayer()->AddNextCombatStep();
}
//Auto skip Phases
GameObserver * game = game->GetInstance();
int skipLevel = (game->currentPlayer->playMode == Player::MODE_TEST_SUITE) ? Constants::ASKIP_NONE
: options[Options::ASPHASES].number;
: options[Options::ASPHASES].number;
int nrCreatures = currentPlayer->game->inPlay->countByType("Creature");
if (skipLevel == Constants::ASKIP_SAFE || skipLevel == Constants::ASKIP_FULL)
{
if ((opponent()->isAI() && !(isInterrupting)) && ((currentGamePhase == Constants::MTG_PHASE_UNTAP)
|| (currentGamePhase == Constants::MTG_PHASE_DRAW) || (currentGamePhase == Constants::MTG_PHASE_COMBATBEGIN)
|| ((currentGamePhase == Constants::MTG_PHASE_COMBATATTACKERS) && (nrCreatures == 0))
|| currentGamePhase == Constants::MTG_PHASE_COMBATEND || currentGamePhase == Constants::MTG_PHASE_ENDOFTURN
|| ((currentGamePhase == Constants::MTG_PHASE_CLEANUP) && (currentPlayer->game->hand->nb_cards < 8))))
userRequestNextGamePhase();
|| (currentGamePhase == Constants::MTG_PHASE_DRAW) || (currentGamePhase == Constants::MTG_PHASE_COMBATBEGIN)
|| ((currentGamePhase == Constants::MTG_PHASE_COMBATATTACKERS) && (nrCreatures == 0))
|| currentGamePhase == Constants::MTG_PHASE_COMBATEND || currentGamePhase == Constants::MTG_PHASE_ENDOFTURN
|| ((currentGamePhase == Constants::MTG_PHASE_CLEANUP) && (currentPlayer->game->hand->nb_cards < 8))))
userRequestNextGamePhase();
}
if (skipLevel == Constants::ASKIP_FULL)
{
if ((opponent()->isAI() && !(isInterrupting)) && (currentGamePhase == Constants::MTG_PHASE_UPKEEP
|| currentGamePhase == Constants::MTG_PHASE_COMBATDAMAGE))
userRequestNextGamePhase();
|| currentGamePhase == Constants::MTG_PHASE_COMBATDAMAGE))
userRequestNextGamePhase();
}
}
void GameObserver::enchantmentStatus()
{
for (int i = 0; i < 2; i++)
{
MTGGameZone * zone = players[i]->game->inPlay;
for (int k = zone->nb_cards - 1; k >= 0; k--)
{
MTGCardInstance * card = zone->cards[k];
if (card && !card->hasType("equipment") && !card->hasSubtype("aura"))
{
card->enchanted = false;
card->auras = 0;
}
}
for (int j = zone->nb_cards - 1; j >= 0; j--)
{
MTGCardInstance * card = zone->cards[j];
if (card->target && isInPlay(card->target) && !card->hasType("equipment") && card->hasSubtype("aura"))
{
card->target->enchanted = true;
card->target->auras += 1;
}
}
}
}
void GameObserver::Render()
{
mLayers->Render();
@@ -883,7 +1030,28 @@ int GameObserver::isInPlay(MTGCardInstance * card)
}
return 0;
}
int GameObserver::isInGrave(MTGCardInstance * card)
{
for (int i = 0; i < 2; i++)
{
MTGGameZone * graveyard = players[i]->game->graveyard;
if (players[i]->game->isInZone(card,graveyard))
return 1;
}
return 0;
}
int GameObserver::isInExile(MTGCardInstance * card)
{
for (int i = 0; i < 2; i++)
{
MTGGameZone * exile = players[i]->game->exile;
if (players[i]->game->isInZone(card,exile))
return 1;
}
return 0;
}
void GameObserver::draw()
{
currentPlayer->game->drawFromLibrary();
+16
View File
@@ -28,6 +28,7 @@ const string Options::optionNames[] = {
"disable_cards",
"maxGrade",
"ASPhases",
"FirstPlayer",
"economic_difficulty",
"transitions",
"bgStyle",
@@ -441,6 +442,11 @@ GameOption * GameOptions::get(int optionID)
goEnum->def = OptionASkipPhase::getInstance();
go = goEnum;
break;
case Options::FIRSTPLAYER:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionWhosFirst::getInstance();
go = goEnum;
break;
case Options::KEY_BINDINGS:
go = NEW GameOptionKeyBindings();
break;
@@ -870,6 +876,16 @@ OptionASkipPhase::OptionASkipPhase()
mDef.values.push_back(EnumDefinition::assoc(Constants::ASKIP_FULL, "Full"));
}
;
OptionWhosFirst OptionWhosFirst::mDef;
OptionWhosFirst::OptionWhosFirst()
{
mDef.values.push_back(EnumDefinition::assoc(Constants::WHO_P, "Player"));
mDef.values.push_back(EnumDefinition::assoc(Constants::WHO_O, "Opponent"));
mDef.values.push_back(EnumDefinition::assoc(Constants::WHO_R, "Random"));
}
;
OptionClosedHand OptionClosedHand::mDef;
OptionClosedHand::OptionClosedHand()
{
+4
View File
@@ -103,6 +103,10 @@ void GameStateOptions::Start()
optionsList->Add(oASPhases);
optionsTabs->Add(optionsList);
WDecoEnum * oFirstPlayer = NEW WDecoEnum(NEW OptionInteger(Options::FIRSTPLAYER, "First Turn Player", Constants::WHO_R, 1,
Constants::WHO_P, "", Constants::WHO_P));
optionsList->Add(oFirstPlayer);
optionsList = NEW WGuiKeyBinder("Key Bindings", this);
optionsTabs->Add(optionsList);
+5 -2
View File
@@ -44,8 +44,11 @@ GuiHand::GuiHand(MTGHand* hand) :
GuiHand::~GuiHand()
{
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
delete (*it);
if(cards.size())
{
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
delete (*it);
}
}
void GuiHand::Update(float dt)
File diff suppressed because it is too large Load Diff
+72 -4
View File
@@ -31,6 +31,8 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
model = card;
attacker = 0;
lifeOrig = life;
origpower = power;
origtoughness = toughness;
belongs_to = arg_belongs_to;
owner = NULL;
if (arg_belongs_to)
@@ -69,7 +71,6 @@ void MTGCardInstance::copy(MTGCardInstance * card)
toughness = data->toughness;
life = toughness;
lifeOrig = life;
magicText = data->magicText;
spellTargetType = data->spellTargetType;
alias = data->alias;
@@ -109,6 +110,7 @@ void MTGCardInstance::initMTGCI()
{
sample = "";
model = NULL;
imprint = NULL;
isToken = false;
lifeOrig = 0;
doDamageTest = 1;
@@ -117,11 +119,29 @@ void MTGCardInstance::initMTGCI()
untapping = 0;
frozen = 0;
fresh = 0;
isMultiColored = 0;
isBlackAndWhite = 0;
isRedAndBlue = 0;
isBlackAndGreen = 0;
isBlueAndGreen = 0;
isRedAndWhite = 0;
isLeveler = 0;
enchanted = false;
CDenchanted = NULL;
blinked = false;
isExtraCostTarget = false;
morphed = false;
turningOver = false;
isMorphed = false;
isPhased = false;
isTempPhased = false;
phasedTurn = -1;
didattacked = 0;
didblocked = 0;
notblocked = 0;
sunburst = NULL;
equipment = NULL;
equipment = 0;
auras = 0;
for (int i = 0; i < ManaCost::MANA_PAID_WITH_RETRACE +1; i++)
alternateCostPaid[i] = 0;
@@ -161,13 +181,39 @@ void MTGCardInstance::initMTGCI()
s == "Dismiss" || s == "Equipment" || s == "Everglades" || s == "Grasslands" || s == "Lair" ||
s == "Level" || s == "Levelup" || s == "Mine" || s == "Oasis" || s == "World" || s == "Aura"
)
continue;
continue;
addType(i);
}
}
}
int colored = 0;
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; ++i)
{
if (this->hasColor(i))
++colored;
}
if(colored > 1)
{
isMultiColored = 1;
}
if(this->hasColor(Constants::MTG_COLOR_WHITE) && this->hasColor(Constants::MTG_COLOR_BLACK))
isBlackAndWhite = 1;
if(this->hasColor(Constants::MTG_COLOR_RED) && this->hasColor(Constants::MTG_COLOR_BLUE))
isRedAndBlue = 1;
if(this->hasColor(Constants::MTG_COLOR_GREEN) && this->hasColor(Constants::MTG_COLOR_BLACK))
isBlackAndGreen = 1;
if(this->hasColor(Constants::MTG_COLOR_BLUE) && this->hasColor(Constants::MTG_COLOR_GREEN))
isBlueAndGreen = 1;
if(this->hasColor(Constants::MTG_COLOR_RED) && this->hasColor(Constants::MTG_COLOR_WHITE))
isRedAndWhite = 1;
if(previous && previous->morphed == true && !turningOver)
{
morphed = true;
isMorphed = true;
}
}
const string MTGCardInstance::getDisplayName() const
@@ -529,6 +575,10 @@ int MTGCardInstance::canBlock(MTGCardInstance * opponent)
return 0;
if (opponent->basicAbilities[Constants::ONEBLOCKER] && opponent->blocked)
return 0;
if(opponent->basicAbilities[Constants::STRONG] && power < opponent->power)
return 0;
if(has(basicAbilities[Constants::WEAK]) && power < opponent->power)
return 0;
if (opponent->basicAbilities[Constants::FEAR] && !(hasType(Subtypes::TYPE_ARTIFACT) || hasColor(Constants::MTG_COLOR_BLACK)))
return 0;
@@ -572,6 +622,24 @@ int MTGCardInstance::canBlock(MTGCardInstance * opponent)
return 0;
if (opponent->basicAbilities[Constants::PLAINSWALK] && controller()->game->inPlay->hasType("plains"))
return 0;
if (opponent->basicAbilities[Constants::LEGENDARYWALK] && controller()->game->inPlay->hasPrimaryType("legendary","land"))
return 0;
if (opponent->basicAbilities[Constants::DESERTWALK] && controller()->game->inPlay->hasSpecificType("land","desert"))
return 0;
if (opponent->basicAbilities[Constants::SNOWSWAMPWALK] && controller()->game->inPlay->hasSpecificType("snow","swamp"))
return 0;
if (opponent->basicAbilities[Constants::SNOWFORESTWALK] && controller()->game->inPlay->hasSpecificType("snow","forest"))
return 0;
if (opponent->basicAbilities[Constants::SNOWISLANDWALK] && controller()->game->inPlay->hasSpecificType("snow","island"))
return 0;
if (opponent->basicAbilities[Constants::SNOWMOUNTAINWALK] && controller()->game->inPlay->hasSpecificType("snow","mountain"))
return 0;
if (opponent->basicAbilities[Constants::SNOWPLAINSWALK] && controller()->game->inPlay->hasSpecificType("snow","plains"))
return 0;
if (opponent->basicAbilities[Constants::SNOWWALK] && controller()->game->inPlay->hasPrimaryType("snow","land"))
return 0;
if (opponent->basicAbilities[Constants::NONBASICWALK] && controller()->game->inPlay->hasTypeButNotType("land","basic"))
return 0;
return 1;
}
+82 -9
View File
@@ -138,12 +138,21 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
case 'o': //othercost
if (!primitive) primitive = NEW CardPrimitive();
if(key[5] == 'r')//otherrestrictions
{
string value = val;
primitive->setOtherRestrictions(value);
}
else
{
if (ManaCost * cost = primitive->getManaCost())
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->alternative = ManaCost::parseManaCost(value);
}
}
break;
case 'b': //buyback
@@ -155,16 +164,26 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
cost->BuyBack = ManaCost::parseManaCost(value);
}
break;
case 'f': //flashback
if (!primitive) primitive = NEW CardPrimitive();
if (ManaCost * cost = primitive->getManaCost())
case 'f': //flashback//morph
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->FlashBack = ManaCost::parseManaCost(value);
if (!primitive) primitive = NEW CardPrimitive();
if(ManaCost * cost = primitive->getManaCost())
{
if( s.find("facedown") != string::npos)//morph
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->morph = ManaCost::parseManaCost(value);
}
else
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->FlashBack = ManaCost::parseManaCost(value);
}
}
break;
}
break;
case 'i': //id
if (!card) card = NEW MTGCard();
card->setMTGId(atoi(val));
@@ -200,7 +219,61 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
break;
case 'r': //retrace/rarity
if ('e' == key[1])
if('s' == key[2])//restrictions
{
if (!primitive) primitive = NEW CardPrimitive();
string value = val;
primitive->setRestrictions(CardPrimitive::NO_RESTRICTION);
primitive->hasRestriction = false;
if (value.find("control two or more vampires") != string::npos)
primitive->setRestrictions(CardPrimitive::VAMPIRES);
if (value.find("control less creatures") != string::npos)
primitive->setRestrictions(CardPrimitive::LESS_CREATURES);
if (value.find("control snow land") != string::npos)
primitive->setRestrictions(CardPrimitive::SNOW_LAND_INPLAY);
if (value.find("casted a spell") != string::npos)
primitive->setRestrictions(CardPrimitive::CASTED_A_SPELL);
if (value.find("one of a kind") != string::npos)
primitive->setRestrictions(CardPrimitive::ONE_OF_AKIND);
if (value.find("fourth turn") != string::npos)
primitive->setRestrictions(CardPrimitive::FOURTHTURN);
if (value.find("before battle damage") != string::npos)
primitive->setRestrictions(CardPrimitive::BEFORECOMBATDAMAGE);
if (value.find("after battle") != string::npos)
primitive->setRestrictions(CardPrimitive::AFTERCOMBAT);
if (value.find("during battle") != string::npos)
primitive->setRestrictions(CardPrimitive::DURINGCOMBAT);
if (value.find("myturnonly") != string::npos)
primitive->setRestrictions(CardPrimitive::PLAYER_TURN_ONLY);
if (value.find("opponentturnonly") != string::npos)
primitive->setRestrictions(CardPrimitive::OPPONENT_TURN_ONLY);
if (value.find("assorcery") != string::npos)
primitive->setRestrictions(CardPrimitive::AS_SORCERY);
string types[] = { "my", "opponent", "" };
int starts[] = { CardPrimitive::MY_BEFORE_BEGIN, CardPrimitive::OPPONENT_BEFORE_BEGIN, CardPrimitive::BEFORE_BEGIN };
for (int j = 0; j < 3; ++j)
{
size_t found = value.find(types[j]);
if (found != string::npos)
{
for (int i = 0; i < Constants::NB_MTG_PHASES; i++)
{
string toFind = types[j];
toFind.append(Constants::MTGPhaseCodeNames[i]).append("only");
found = value.find(toFind);
if (found != string::npos)
{
if(primitive->hasRestriction == false)
{
primitive->setRestrictions(starts[j] + i);
primitive->hasRestriction = true;
}
}
}
}
}
}
else if ('e' == key[1])
{ //retrace
if (!primitive) primitive = NEW CardPrimitive();
if (ManaCost * cost = primitive->getManaCost())
+13
View File
@@ -24,6 +24,7 @@ const string Constants::kBuyBackKeyword = "buyback";
const string Constants::kFlashBackKeyword = "flashback";
const string Constants::kRetraceKeyword = "retrace";
const string Constants::kKickerKeyword = "kicker";
const string Constants::kMorphKeyword = "facedown";
const char* Constants::MTGBasicAbilities[] = {
"trample",
@@ -110,6 +111,18 @@ const char* Constants::MTGBasicAbilities[] = {
"sunburst",
"flanking",
"exiledeath",
"legendarylandwalk",
"desertlandwalk",
"snowforestlandwalk",
"snowplainslandwalk",
"snowmountainlandwalk",
"snowislandlandwalk",
"snowswamplandwalk",
"snowlandwalk",
"nonbasiclandwalk",
"strong",//cant be blocked by creature with less power
"weak",//cant block creatures with more power
"phasing",
};
map<string,int> Constants::MTGBasicAbilitiesMap;
+91 -1
View File
@@ -275,6 +275,10 @@ MTGCardInstance * MTGPlayerCards::putInExile(MTGCardInstance * card)
{
copy = putInZone(card, stack, exile);
}
else if (hand->hasCard(card))
{
copy = putInZone(card, hand, exile);
}
else if (graveyard->hasCard(card))
{
copy = putInZone(card, graveyard, exile);
@@ -325,6 +329,10 @@ MTGCardInstance * MTGPlayerCards::putInHand(MTGCardInstance * card)
{
copy = putInZone(card, graveyard, hand);
}
else if (exile->hasCard(card))
{
copy = putInZone(card, exile, hand);
}
else
{
copy = putInZone(card, hand, hand);
@@ -332,6 +340,33 @@ MTGCardInstance * MTGPlayerCards::putInHand(MTGCardInstance * card)
return copy;
}
MTGCardInstance * MTGPlayerCards::putInBattlefield(MTGCardInstance * card)
{
MTGCardInstance * copy = NULL;
MTGInPlay * InPlay = card->owner->game->battlefield;
if (inPlay->hasCard(card))
{
copy = putInZone(card, inPlay, InPlay);
}
else if (stack->hasCard(card))
{
copy = putInZone(card, stack, InPlay);
}
else if (graveyard->hasCard(card))
{
copy = putInZone(card, graveyard, InPlay);
}
else if (exile->hasCard(card))
{
copy = putInZone(card, exile, InPlay);
}
else
{
copy = putInZone(card, InPlay, InPlay);
}
return copy;
}
MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to)
{
MTGCardInstance * copy = NULL;
@@ -420,7 +455,14 @@ int MTGPlayerCards::isInPlay(MTGCardInstance * card)
}
return 0;
}
int MTGPlayerCards::isInZone(MTGCardInstance * card,MTGGameZone * zone)
{
if (zone->hasCard(card))
{
return 1;
}
return 0;
}
//--------------------------------------
// Zones specific code
//--------------------------------------
@@ -537,6 +579,54 @@ int MTGGameZone::hasType(const char * value)
return 0;
}
int MTGGameZone::hasPrimaryType(const char * value,const char * secondvalue)
{
for (int i = 0; i < (nb_cards); i++)
{
if (cards[i]->hasType(value) && cards[i]->hasType(secondvalue))
{
return 1;
}
}
return 0;
}
int MTGGameZone::hasSpecificType(const char * value,const char * secondvalue)
{
for (int i = 0; i < (nb_cards); i++)
{
if (cards[i]->hasType(value) && cards[i]->hasSubtype(secondvalue))
{
return 1;
}
}
return 0;
}
int MTGGameZone::hasTypeButNotType(const char * value,const char * secondvalue)
{
for (int i = 0; i < (nb_cards); i++)
{
if (cards[i]->hasType(value) && cards[i]->hasSubtype(value) && !cards[i]->hasType(secondvalue) && !cards[i]->hasSubtype(secondvalue))
{
return 1;
}
}
return 0;
}
int MTGGameZone::hasName(string value)
{
for (int i = 0; i < (nb_cards); i++)
{
if (cards[i]->name == value)
{
return 1;
}
}
return 0;
}
int MTGGameZone::hasColor(int value)
{
for (int i = 0; i < (nb_cards); i++)
+190 -6
View File
@@ -35,6 +35,8 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
}
return 1;
}
if(!allowedToCast(card,player))
return 0;
if (card->hasType("land"))
{
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay
@@ -44,7 +46,7 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
return 1;
}
}
else if ((card->hasType("instant")) || card->has(Constants::FLASH)
else if ((card->hasType("instant")) || card->basicAbilities[Constants::FLASH]
|| (player == currentPlayer && !game->isInterrupting
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))
@@ -250,6 +252,11 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
if (!alternateManaCost)
return 0;
if(!allowedToCast(card,player))
return 0;
if(!allowedToAltCast(card,player))
return 0;
if (card->hasType("land"))
{
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay
@@ -356,7 +363,7 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter
if (card->hasType("land"))
{
MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->temp);
MTGCardInstance * copy = player->game->putInZone(card, card->currentZone, player->game->temp);
spell = NEW Spell(copy);
copy->alternateCostPaid[alternateCostType] = 1;
spell->resolve();
@@ -368,7 +375,7 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter
else
{
ManaCost *spellCost = previousManaPool->Diff(player->getManaPool());
MTGCardInstance * copy = player->game->putInZone(card, originatingZone, player->game->stack);
MTGCardInstance * copy = player->game->putInZone(card, card->currentZone, player->game->stack);
copy->alternateCostPaid[alternateCostType] = 1;
spell = game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, spellCost, payResult, 0);
game->targetChooser = NULL;
@@ -431,6 +438,8 @@ MTGAlternativeCostRule(_id)
int MTGBuyBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{
Player * player = game->currentlyActing();
if(!allowedToCast(card,player))
return 0;
if (!player->game->hand->hasCard(card))
return 0;
return MTGAlternativeCostRule::isReactingToClick( card, mana, card->getManaCost()->BuyBack );
@@ -584,13 +593,179 @@ MTGRetraceRule * MTGRetraceRule::clone() const
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-----------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
MTGMorphCostRule::MTGMorphCostRule(int _id) :
MTGAbility(_id, NULL)
{
aType = MTGAbility::MORPH_COST;
}
int MTGMorphCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{
int cardsinhand = game->players[0]->game->hand->nb_cards;
Player * player = game->currentlyActing();
Player * currentPlayer = game->currentPlayer;
if (!player->game->hand->hasCard(card))
return 0;
if (!card->getManaCost()->morph)
return 0;
if(!allowedToCast(card,player))
return 0;
if(!allowedToAltCast(card,player))
return 0;
//note lands can morph too, this is different from other cost types.
if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer
&& !game->isInterrupting
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))
)
{
ManaCost * playerMana = player->getManaPool();
ManaCost * cost = card->getManaCost();
ManaCost * morph = card->getManaCost()->morph;
#ifdef WIN32
cost->Dump();
#endif
if (player->castrestrictedspell == true && !card->hasType("land"))
{
return 0;
}
if (player->onlyonecast == true && player->castcount >= 1)
{
return 0;
}
if (player->nospellinstant == true)
{
return 0;
}
if (player->onlyoneinstant == true)
{
if (player->castcount >= 1)
{
return 0;
}
}
if (player->nocreatureinstant == true && card->hasType("creature"))
{
return 0;
}
if (player->castrestrictedcreature == true && card->hasType("creature"))
{
return 0;
}
//cost of card.
if (morph && playerMana->canAfford(morph))
{
return 1;
}
}
return 0;//dont play if you cant afford it.
}
int MTGMorphCostRule::reactToClick(MTGCardInstance * card)
{
//morphs reactToClick is extremely different then the other cost.
if (!isReactingToClick(card))
return 0;
Player * player = game->currentlyActing();
ManaCost * cost = card->getManaCost();
ManaCost * morph = card->getManaCost()->morph;
ManaCost * playerMana = player->getManaPool();
//this handles extra cost payments at the moment a card is played.
if (playerMana->canAfford(morph))
{
if (cost->morph->isExtraPaymentSet())
{
card->paymenttype = MTGAbility::MORPH_COST;
if (!game->targetListIsSet(card))
{
return 0;
}
}
else
{
cost->morph->setExtraCostsAction(this, card);
game->mExtraPayment = cost->morph->extraCosts;
card->paymenttype = MTGAbility::MORPH_COST;
return 0;
}
}
//------------------------------------------------------------------------
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
int payResult = player->getManaPool()->pay(card->getManaCost()->morph);
card->getManaCost()->morph->doPayExtra();
payResult = ManaCost::MANA_PAID_WITH_MORPH;
//if morph has a extra payment thats set, this code pays it.the if statement is 100% needed as it would cause a crash on cards that dont have the morph cost.
if (morph)
{
card->getManaCost()->morph->doPayExtra();
}
//---------------------------------------------------------------------------
ManaCost * spellCost = previousManaPool->Diff(player->getManaPool());
delete previousManaPool;
card->morphed = true;
card->isMorphed = true;
MTGCardInstance * copy = player->game->putInZone(card, card->currentZone, player->game->stack);
Spell * spell = NULL;
spell = game->mLayers->stackLayer()->addSpell(copy, NULL, spellCost, payResult, 0);
spell->source->morphed = true;
spell->source->isMorphed = true;
spell->source->name = "";
spell->source->power = 2;
spell->source->toughness = 2;
copy->morphed = true;
copy->isMorphed = true;
copy->power = 2;
copy->toughness = 2;
player->castedspellsthisturn += 1;
player->opponent()->castedspellsthisturn += 1;
if (player->onlyonecast == true || player->onlyoneinstant == true)
{
player->castcount += 1;
}
if (!card->has(Constants::STORM))
{
copy->X = spell->computeX(copy);
copy->XX = spell->computeXX(copy);
}
return 1;
}
//The morph rule is never destroyed
int MTGMorphCostRule::testDestroy()
{
return 0;
}
ostream& MTGMorphCostRule::toString(ostream& out) const
{
out << "MTGMorphCostRule ::: (";
return MTGAbility::toString(out) << ")";
}
MTGMorphCostRule * MTGMorphCostRule::clone() const
{
MTGMorphCostRule * a = NEW MTGMorphCostRule(*this);
a->isClone = 1;
return a;
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
bool MTGAttackRule::select(Target* t)
{
if (CardView* c = dynamic_cast<CardView*>(t))
{
MTGCardInstance * card = c->getCard();
if (card->canAttack())
if (card->canAttack() && !card->isPhased)
return true;
}
return false;
@@ -610,6 +785,8 @@ int MTGAttackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
{
if (currentPhase == Constants::MTG_PHASE_COMBATATTACKERS && card->controller() == game->currentPlayer)
{
if(card->isPhased)
return 0;
if (card->isAttacker())
return 1;
if (card->canAttack())
@@ -845,7 +1022,7 @@ int MTGBlockRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
&& card->controller() == game->currentlyActing()
)
{
if (card->canBlock())
if (card->canBlock() && !card->isPhased)
return 1;
}
return 0;
@@ -1620,6 +1797,8 @@ ListMaintainerAbility(_id)
int MTGLegendRule::canBeInList(MTGCardInstance * card)
{
if(card->isPhased)
return 0;
if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->isInPlay(card))
{
return 1;
@@ -1684,6 +1863,11 @@ int MTGLifelinkRule::receiveEvent(WEvent * event)
MTGCardInstance * card = d->source;
if (d->damage > 0 && card && card->basicAbilities[Constants::LIFELINK])
{
card->controller()->thatmuch = d->damage;
WEvent * lifed = NULL;
lifed = NEW WEventLife(card->controller(),d->damage);
GameObserver * game = GameObserver::GetInstance();
game->receiveEvent(lifed);
card->controller()->life += d->damage;
return 1;
}
+8 -1
View File
@@ -251,13 +251,13 @@ ManaCost::~ManaCost()
{
SAFE_DELETE(hybrids[i]);
}
SAFE_DELETE(extraCosts);
SAFE_DELETE(kicker);
SAFE_DELETE(alternative);
SAFE_DELETE(BuyBack);
SAFE_DELETE(FlashBack);
SAFE_DELETE(Retrace);
SAFE_DELETE(morph);
}
void ManaCost::x()
@@ -285,6 +285,7 @@ void ManaCost::init()
BuyBack = NULL;
FlashBack = NULL;
Retrace = NULL;
morph = NULL;
}
void ManaCost::copy(ManaCost * _manaCost)
@@ -341,6 +342,12 @@ void ManaCost::copy(ManaCost * _manaCost)
Retrace = NEW ManaCost();
Retrace->copy(_manaCost->Retrace);
}
SAFE_DELETE(morph);
if (_manaCost->morph)
{
morph = NEW ManaCost();
morph->copy(_manaCost->morph);
}
}
int ManaCost::getCost(int color)
+11 -1
View File
@@ -166,7 +166,7 @@ void RulesState::parsePlayerState(int playerId, string s)
void Rules::addExtraRules()
{
GameObserver * g = GameObserver::GetInstance();
int id = g->mLayers->actionLayer()->getMaxId();
for (int i = 0; i < 2; ++i)
{
@@ -378,6 +378,16 @@ void Rules::initGame()
DebugTrace("RULES Init Game\n");
//Set the current player/phase
if (g->currentPlayer->playMode
!= Player::MODE_TEST_SUITE && /*g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
!= GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 &&*/ g->mRules->gamemode
!= GAME_TYPE_STORY)
{
if(OptionWhosFirst::WHO_R == options[Options::FIRSTPLAYER].number)
initState.player = WRand() % 2;
if(OptionWhosFirst::WHO_O == options[Options::FIRSTPLAYER].number)
initState.player = 1;
}
g->currentPlayer = g->players[initState.player];
g->currentActionPlayer = g->currentPlayer;
g->currentPlayerId = initState.player;
+137 -8
View File
@@ -7,6 +7,7 @@
#include "Subtypes.h"
#include "Counters.h"
#include "WEvent.h"
#include "AllAbilities.h"
TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInstance * card, MTGAbility * ability)
{
@@ -153,8 +154,23 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
TargetChooser * tc = NULL;
int maxtargets = 1;
CardDescriptor * cd = NULL;
//max targets allowed
size_t limit = s1.find('<');
if (limit != string::npos)
{
size_t end = s1.find(">", limit);
string howmany;
if (end != string::npos)
{
howmany = s1.substr(limit + 1, end - limit - 1);
WParsedInt * howmuch = NEW WParsedInt(howmany, NULL, card);
maxtargets = howmuch->getValue();
delete howmuch;
s1 = s1.substr(end + 1);
}
}
while (s1.size())
while (s1.size())
{
found = s1.find(",");
string typeName;
@@ -206,8 +222,11 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
size_t operatorPosition = attribute.find("=", 1);
if (operatorPosition != string::npos)
{
comparisonCriterion = atoi(
attribute.substr(operatorPosition + 1, attribute.size() - operatorPosition - 1).c_str());
string numberCD = attribute.substr(operatorPosition + 1, attribute.size() - operatorPosition - 1);
WParsedInt * val = NEW WParsedInt(numberCD,NULL, card);
comparisonCriterion = val->getValue();
/*atoi(attribute.substr(operatorPosition + 1, attribute.size() - operatorPosition - 1).c_str());*/
delete val;
switch (attribute[operatorPosition - 1])
{
case '<':
@@ -305,10 +324,112 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{
cd->unsecuresetfresh(1);
}
//Power restrictions
}
//creature is a level up creature
else if (attribute.find("leveler") != string::npos)
{
if (minus)
{
cd->isLeveler = -1;
}
else
{
cd->isLeveler = 1;
}
}
//creature is a level up creature
else if (attribute.find("enchanted") != string::npos)
{
if (minus)
{
cd->CDenchanted = -1;
}
else
{
cd->CDenchanted = 1;
}
}
else if (attribute.find("multicolor") != string::npos)
{
//card is multicolored?
if (minus)
{
cd->setisMultiColored(-1);
}
else
{
cd->setisMultiColored(1);
}
}
else if (attribute.find("blackandgreen") != string::npos)
{
//card is both colors?
if (minus)
{
cd->setisBlackAndGreen(-1);
}
else
{
cd->setisBlackAndGreen(1);
}
}
else if (attribute.find("blackandwhite") != string::npos)
{
//card is both colors?
if (minus)
{
cd->setisBlackAndWhite(-1);
}
else
{
cd->setisBlackAndWhite(1);
}
}
else if (attribute.find("redandblue") != string::npos)
{
//card is both colors?
if (minus)
{
cd->setisRedAndBlue(-1);
}
else
{
cd->setisRedAndBlue(1);
}
}
else if (attribute.find("blueandgreen") != string::npos)
{
//card is both colors?
if (minus)
{
cd->setisBlueAndGreen(-1);
}
else
{
cd->setisBlueAndGreen(1);
}
}
else if (attribute.find("redandwhite") != string::npos)
{
//card is both colors?
if (minus)
{
cd->setisRedAndWhite(-1);
}
else
{
cd->setisRedAndWhite(1);
}
}
else if (attribute.find("power") != string::npos)
{
//Power restrictions
cd->setPower(comparisonCriterion);
cd->powerComparisonMode = comparisonMode;
//Toughness restrictions
@@ -462,6 +583,8 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
TargetChooser * TargetChooserFactory::createTargetChooser(MTGCardInstance * card)
{
if(!card)
return NULL;
int id = card->getId();
string s = card->spellTargetType;
if (card->alias)
@@ -540,6 +663,11 @@ bool TargetChooser::canTarget(Targetable * target)
tempcard = tempcard->previous;
}
}
if(source && ((source->hasSubtype("aura") || source->hasSubtype("equipment")) && source->target && source->target == card && source->target->isPhased && targetter->target == card))
return true;
//this is kinda cheating but by defualt we let auras and equipments always contenue to target a phased creature.
else if(card->isPhased)
return false;
if (source && targetter && card->isInPlay())
{
if (card->has(Constants::SHROUD)) return false;
@@ -574,7 +702,7 @@ int TargetChooser::ForceTargetListReady()
int TargetChooser::targetsReadyCheck()
{
if (cursor == 0)
if (cursor <= 0)
{
return TARGET_NOK;
}
@@ -605,8 +733,8 @@ bool TargetChooser::validTargetsExist()
{
Player *p = GameObserver::GetInstance()->players[i];
if (canTarget(p)) return true;
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library };
for (int k = 0; k < 4; k++)
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->exile };
for (int k = 0; k < 5; k++)
{
MTGGameZone * z = zones[k];
if (targetsZone(z))
@@ -764,7 +892,8 @@ bool DescriptorTargetChooser::canTarget(Targetable * target)
if (target->typeAsTarget() == TARGET_CARD)
{
MTGCardInstance * _target = (MTGCardInstance *) target;
if (cd->match(_target)) return true;
if (cd->match(_target))
return true;
}
else if (target->typeAsTarget() == TARGET_STACKACTION)
{
+36 -5
View File
@@ -135,13 +135,44 @@ int TestSuiteAI::Act(float dt)
playMode = MODE_AI;
return 1;
}
else if (action.compare("next") == 0)
else if (action.compare("next") == 0 || action.find("goto") != string::npos)
{
GuiCombat * gc = g->mLayers->combatLayer();
if (ORDER == g->combatStep || DAMAGE == g->combatStep)
gc->clickOK();
if(action.find("goto ")!= string::npos)
{
size_t found = action.find("goto ");
string phase = action.substr(found + 5);
int phaseToGo = 0;
for (int i = 0; i < Constants::NB_MTG_PHASES; i++)
{
if (phase.find(Constants::MTGPhaseCodeNames[i]) != string::npos)
{
phaseToGo = i;
}
}
if(g->currentGamePhase != phaseToGo)
suite->currentAction--;
else
{
return 1;
}
GuiCombat * gc = g->mLayers->combatLayer();
if (ORDER == g->combatStep || DAMAGE == g->combatStep)
{
gc->clickOK();
}
else
{
g->userRequestNextGamePhase();
}
}
else
g->userRequestNextGamePhase();
{
GuiCombat * gc = g->mLayers->combatLayer();
if (ORDER == g->combatStep || DAMAGE == g->combatStep)
gc->clickOK();
else
g->userRequestNextGamePhase();
}
}
else if (action.compare("yes") == 0)
g->mLayers->stackLayer()->setIsInterrupting(this);
+83 -2
View File
@@ -144,7 +144,7 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s)
return NULL;
}
//equips
//equips and auras
found = s.find("gear");//still same meaning, better wording to word conflict with MTGAbility equip.
if (found != string::npos)
{
@@ -156,7 +156,52 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s)
}
return NULL;
}
found = s.find("auras");
if (found != string::npos)
{
ThisAuras * td = NEW ThisAuras(criterion);
if (td)
{
td->comparisonMode = mode;
return td;
}
return NULL;
}
// opponent damage count
found = s.find("opponentdamagecount");
if (found != string::npos)
{
ThisOpponentDamageAmount * td = NEW ThisOpponentDamageAmount(criterion);
if (td)
{
td->comparisonMode = mode;
return td;
}
return NULL;
}
//untapped status
found = s.find("untapped");
if (found != string::npos)
{
ThisUntapped * td = NEW ThisUntapped(criterion);
if (td)
{
td->comparisonMode = mode;
return td;
}
return NULL;
}
found = s.find("tapped");
if (found != string::npos)
{
ThisTapped * td = NEW ThisTapped(criterion);
if (td)
{
td->comparisonMode = mode;
return td;
}
return NULL;
}
//whenever this creature attacks do effect
found = s.find("attacking");
if (found != string::npos)
@@ -338,6 +383,42 @@ int ThisEquip::match(MTGCardInstance * card)
return matchValue(card->equipment);
}
ThisAuras::ThisAuras(int auras)
{
comparisonCriterion = auras;
}
int ThisAuras::match(MTGCardInstance * card)
{
return matchValue(card->auras);
}
ThisOpponentDamageAmount::ThisOpponentDamageAmount(int damagecount)
{
comparisonCriterion = damagecount;
}
int ThisOpponentDamageAmount::match(MTGCardInstance * card)
{
return matchValue(card->controller()->opponent()->damageCount);
}
ThisUntapped::ThisUntapped(int untapped)
{
comparisonCriterion = untapped;
}
int ThisUntapped::match(MTGCardInstance * card)
{
return matchValue(!card->isTapped());
}
ThisTapped::ThisTapped(int tapped)
{
comparisonCriterion = tapped;
}
int ThisTapped::match(MTGCardInstance * card)
{
return matchValue(card->isTapped());
}
ThisAttacked::ThisAttacked(int attack)
{
+2
View File
@@ -11,6 +11,8 @@ Token::Token(string _name, MTGCardInstance * source, int _power, int _toughness)
toughness = _toughness;
life = toughness;
lifeOrig = life;
origpower = _power;
origtoughness = _toughness;
rarity = Constants::RARITY_T;
name = _name;
if (name.size() && name[0] >= 97 && name[0] <= 122) name[0] -= 32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
+5 -1
View File
@@ -103,7 +103,11 @@ bool WCachedTexture::isLocked()
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it++)
{
if ((*it)->isLocked()) return true;
if ((*it) && (*it)->isLocked()) return true;
//null case
//tokens that were using workarounds such as mixes of aslongas with CD checks
//and thisforeach would call to cache the tokens image, but since the effect never resolved it was NULL
//when it came time to check if it was locked, it would trigger a break point here.
}
return false;
+51
View File
@@ -21,6 +21,11 @@ WEventDamage::WEventDamage(Damage *damage) :
{
}
WEventLife::WEventLife(Player * player,int amount,int Ltype) :
WEvent(), player(player),amount(amount), Ltype(Ltype)
{
}
WEventDamageStackResolved::WEventDamageStackResolved() :
WEvent()
{
@@ -87,6 +92,16 @@ WEventCardDiscard::WEventCardDiscard(MTGCardInstance * card) :
{
}
WEventVampire::WEventVampire(MTGCardInstance * card,MTGCardInstance * source,MTGCardInstance * victem) :
WEventCardUpdate(card),source(source),victem(victem)
{
}
WEventTarget::WEventTarget(MTGCardInstance * card,MTGCardInstance * source) :
WEventCardUpdate(card),card(card),source(source)
{
}
WEventCardChangeType::WEventCardChangeType(MTGCardInstance * card, int type, bool before, bool after) :
WEventCardUpdate(card), type(type), before(before), after(after)
{
@@ -144,6 +159,42 @@ int WEventDamage::getValue()
return damage->damage;
}
Targetable * WEventLife::getTarget(int target)
{
switch (target)
{
case TARGET_TO:
return player;
case TARGET_FROM:
return player;
}
return NULL;
}
Targetable * WEventVampire::getTarget(int target)
{
switch (target)
{
case TARGET_TO:
return victem->next;
case TARGET_FROM:
return source;
}
return NULL;
}
Targetable * WEventTarget::getTarget(int target)
{
switch (target)
{
case TARGET_TO:
return card;
case TARGET_FROM:
return source;
}
return NULL;
}
Targetable * WEventZoneChange::getTarget(int target)
{
if (target) return card;