Erwan
- Updated Parser mechanism. Right now this doesn't change functionalities much, but should be more readable, and make it easier to code some new abilities in the future - Fixed regenerate, broken with r532 - Death Ward now works - I think "&&" now works with all abilities, needs to be tested...
This commit is contained in:
@@ -22,10 +22,11 @@ class WEvent;
|
||||
class ActionElement: public JGuiObject{
|
||||
protected:
|
||||
int activeState;
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
int isClone;
|
||||
TargetChooser * tc;
|
||||
int currentPhase;
|
||||
int newPhase;
|
||||
@@ -46,6 +47,7 @@ class ActionElement: public JGuiObject{
|
||||
virtual int receiveEvent(WEvent * event){return 0;};
|
||||
virtual int reactToClick(MTGCardInstance * card){return 0;};
|
||||
virtual const char * getMenuText(){return "Ability";};
|
||||
virtual ActionElement * clone() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+897
-437
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@ class UntapBlocker : public MTGAbility {
|
||||
~UntapBlocker();
|
||||
virtual void Update(float dt);
|
||||
virtual int destroy();
|
||||
virtual UntapBlocker * clone() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class GuiLayer{
|
||||
int mCurr;
|
||||
vector<JGuiObject *>mObjects;
|
||||
void Add(JGuiObject * object);
|
||||
void Remove(JGuiObject * object);
|
||||
int Remove(JGuiObject * object);
|
||||
int modal;
|
||||
bool hasFocus;
|
||||
virtual void resetObjects();
|
||||
|
||||
@@ -19,15 +19,18 @@ class WEvent;
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <hge/hgeparticle.h>
|
||||
#include "../include/Damage.h"
|
||||
using std::string;
|
||||
using std::map;
|
||||
|
||||
|
||||
//Two stupid variables used to give a hint to the AI:
|
||||
//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
|
||||
#define BAKA_EFFECT_BAD -1
|
||||
#define BAKA_EFFECT_DONTKNOW 0
|
||||
#define MODE_PUTINTOPLAY 1
|
||||
#define MODE_ABILITY 2
|
||||
|
||||
#define COUNT_POWER 1
|
||||
|
||||
@@ -38,16 +41,17 @@ using std::map;
|
||||
class MTGAbility: public ActionElement{
|
||||
protected:
|
||||
char menuText[25];
|
||||
|
||||
|
||||
GameObserver * game;
|
||||
public:
|
||||
int oneShot;
|
||||
int forceDestroy;
|
||||
ManaCost * cost;
|
||||
Damageable * target;
|
||||
Targetable * target;
|
||||
int aType;
|
||||
MTGCardInstance * source;
|
||||
MTGAbility(int id, MTGCardInstance * card);
|
||||
MTGAbility(int id, MTGCardInstance * _source, Damageable * _target);
|
||||
MTGAbility(int id, MTGCardInstance * _source, Targetable * _target);
|
||||
virtual int testDestroy();
|
||||
virtual ~MTGAbility();
|
||||
virtual void Render(){};
|
||||
@@ -58,7 +62,10 @@ class MTGAbility: public ActionElement{
|
||||
virtual int fireAbility();
|
||||
virtual int stillInUse(MTGCardInstance * card){if (card==source) return 1; return 0;};
|
||||
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 */
|
||||
@@ -78,11 +85,12 @@ class MTGAbility: public ActionElement{
|
||||
class TriggeredAbility:public MTGAbility{
|
||||
public:
|
||||
TriggeredAbility(int id, MTGCardInstance * card);
|
||||
TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target);
|
||||
TriggeredAbility(int id, MTGCardInstance * _source, Targetable * _target);
|
||||
virtual void Update(float dt);
|
||||
virtual void Render(){};
|
||||
virtual int trigger()=0;
|
||||
virtual int resolve() = 0;
|
||||
virtual TriggeredAbility* clone() const = 0;
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
};
|
||||
|
||||
@@ -96,18 +104,24 @@ class ActivatedAbility:public MTGAbility{
|
||||
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:
|
||||
MTGAbility * ability;
|
||||
TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
|
||||
TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
|
||||
virtual void Update(float dt);
|
||||
virtual int reactToClick(MTGCardInstance * card);
|
||||
virtual int reactToTargetClick(Targetable * object);
|
||||
virtual 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{
|
||||
@@ -118,6 +132,7 @@ class InstantAbility:public MTGAbility{
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -125,26 +140,32 @@ class InstantAbility:public MTGAbility{
|
||||
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 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;
|
||||
};
|
||||
|
||||
/* An attempt to globalize triggered abilities as much as possible */
|
||||
class MTGAbilityBasicFeatures{
|
||||
public:
|
||||
Damageable * target;
|
||||
Targetable * target;
|
||||
GameObserver * game;
|
||||
MTGCardInstance * source;
|
||||
MTGAbilityBasicFeatures();
|
||||
MTGAbilityBasicFeatures(MTGCardInstance * _source, Damageable * _target = NULL);
|
||||
void init(MTGCardInstance * _source, Damageable * _target = NULL);
|
||||
MTGAbilityBasicFeatures(MTGCardInstance * _source, Targetable * _target = NULL);
|
||||
void init(MTGCardInstance * _source, Targetable * _target = NULL);
|
||||
};
|
||||
|
||||
class Trigger:public MTGAbilityBasicFeatures{
|
||||
@@ -176,7 +197,7 @@ class TriggerNextPhase:public TriggerAtPhase{
|
||||
class TriggeredEvent:public MTGAbilityBasicFeatures{
|
||||
public:
|
||||
TriggeredEvent();
|
||||
TriggeredEvent(MTGCardInstance * source, Damageable * target = NULL);
|
||||
TriggeredEvent(MTGCardInstance * source, Targetable * target = NULL);
|
||||
virtual int resolve()=0;
|
||||
};
|
||||
|
||||
@@ -213,21 +234,22 @@ class GenericTriggeredAbility:public TriggeredAbility{
|
||||
Trigger * t;
|
||||
TriggeredEvent * te;
|
||||
DestroyCondition * dc;
|
||||
GenericTriggeredAbility(int id, MTGCardInstance * _source, Trigger * _t, TriggeredEvent * _te, DestroyCondition * _dc = NULL, Damageable * _target = NULL);
|
||||
GenericTriggeredAbility(int id, MTGCardInstance * _source, Trigger * _t, TriggeredEvent * _te, DestroyCondition * _dc = NULL, Targetable * _target = NULL);
|
||||
virtual int trigger();
|
||||
virtual int resolve();
|
||||
virtual int testDestroy();
|
||||
virtual GenericTriggeredAbility* clone() const;
|
||||
~GenericTriggeredAbility();
|
||||
};
|
||||
|
||||
/* Ability Factory */
|
||||
class AbilityFactory{
|
||||
private:
|
||||
int countCards(TargetChooser * tc, Player * player = NULL, int option = 0);
|
||||
int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p);
|
||||
int countCards(TargetChooser * tc, Player * player = NULL, int option = 0);
|
||||
int parsePowerToughness(string s, int *power, int *toughness);
|
||||
Trigger * parseTrigger(string magicText);
|
||||
Damageable * parseCollateralTarget(MTGCardInstance * card, string s);
|
||||
MTGAbility * parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated = 0);
|
||||
int abilityEfficiency(MTGAbility * a, Player * p, int mode = MODE_ABILITY);
|
||||
public:
|
||||
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL);
|
||||
int destroyAllInPlay(TargetChooser * tc, int bury = 0);
|
||||
@@ -243,16 +265,16 @@ class AbilityFactory{
|
||||
class AManaProducer: public MTGAbility{
|
||||
protected:
|
||||
|
||||
ManaCost * cost;
|
||||
ManaCost * output;
|
||||
string menutext;
|
||||
float x0,y0,x1,y1,x,y;
|
||||
float animation;
|
||||
Player * controller;
|
||||
int tap;
|
||||
|
||||
|
||||
hgeParticleSystem * mParticleSys;
|
||||
public:
|
||||
int tap;
|
||||
static int currentlyTapping;
|
||||
AManaProducer(int id, MTGCardInstance * card, ManaCost * _output, ManaCost * _cost = NULL, int doTap = 1 );
|
||||
void Update(float dt);
|
||||
@@ -263,6 +285,7 @@ class AManaProducer: public MTGAbility{
|
||||
const char * getMenuText();
|
||||
int testDestroy();
|
||||
~AManaProducer();
|
||||
virtual AManaProducer * clone() const;
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class MTGGamePhase: public ActionElement {
|
||||
virtual void Render();
|
||||
virtual void Update(float dt);
|
||||
bool CheckUserInput(u32 key);
|
||||
virtual MTGGamePhase * clone() const;
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class MTGPutInPlayRule:public MTGAbility{
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
MTGPutInPlayRule(int _id);
|
||||
const char * getMenuText(){return "Put into play";}
|
||||
virtual MTGPutInPlayRule * clone() const;
|
||||
};
|
||||
|
||||
class MTGAttackRule:public MTGAbility{
|
||||
@@ -27,6 +28,7 @@ class MTGAttackRule:public MTGAbility{
|
||||
MTGAttackRule(int _id);
|
||||
const char * getMenuText(){return "Attacker";}
|
||||
void Update(float dt);
|
||||
virtual MTGAttackRule * clone() const;
|
||||
};
|
||||
|
||||
class MTGBlockRule:public MTGAbility{
|
||||
@@ -37,49 +39,18 @@ class MTGBlockRule:public MTGAbility{
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
MTGBlockRule(int _id);
|
||||
const char * getMenuText(){return "Blocker";}
|
||||
virtual MTGBlockRule * clone() const;
|
||||
};
|
||||
|
||||
|
||||
/* Persist Rule */
|
||||
class MTGPersistRule:public MTGAbility{
|
||||
public:
|
||||
MTGPersistRule(int _id):MTGAbility(_id,NULL){};
|
||||
|
||||
int receiveEvent(WEvent * event){
|
||||
if (event->type == WEvent::CHANGE_ZONE){
|
||||
WEventZoneChange * e = (WEventZoneChange *) event;
|
||||
MTGCardInstance * card = e->card->previous;
|
||||
if (card && card->basicAbilities[Constants::PERSIST] && !card->counters->hasCounter(-1,-1)){
|
||||
int ok = 0;
|
||||
for (int i = 0; i < 2 ; i++){
|
||||
Player * p = game->players[i];
|
||||
if (e->from == p->game->inPlay) ok = 1;
|
||||
}
|
||||
if (!ok) return 0;
|
||||
for (int i = 0; i < 2 ; i++){
|
||||
Player * p = game->players[i];
|
||||
if (e->to == p->game->graveyard){
|
||||
//p->game->putInZone(card, p->game->graveyard, card->owner->game->hand);
|
||||
MTGCardInstance * copy = p->game->putInZone(e->card, p->game->graveyard, e->card->owner->game->stack);
|
||||
Spell * spell = NEW Spell(copy);
|
||||
spell->resolve();
|
||||
spell->source->counters->addCounter(-1,-1);
|
||||
game->mLayers->playLayer()->forceUpdateCards();
|
||||
delete spell;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual ostream& toString(ostream& out) const
|
||||
{
|
||||
out << "MTGPersistRule ::: (";
|
||||
return MTGAbility::toString(out) << ")";
|
||||
}
|
||||
int testDestroy(){return 0;}
|
||||
MTGPersistRule(int _id);
|
||||
int receiveEvent(WEvent * event);
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
int testDestroy();
|
||||
virtual MTGPersistRule * clone() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -91,39 +62,13 @@ class MTGPersistRule:public MTGAbility{
|
||||
*/
|
||||
class MTGLegendRule:public ListMaintainerAbility{
|
||||
public:
|
||||
MTGLegendRule(int _id):ListMaintainerAbility(_id){};
|
||||
|
||||
int canBeInList(MTGCardInstance * card){
|
||||
if (card->basicAbilities[Constants::LEGENDARY] && game->isInPlay(card)){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int added(MTGCardInstance * card){
|
||||
map<MTGCardInstance *,bool>::iterator it;
|
||||
int destroy = 0;
|
||||
for ( it=cards.begin() ; it != cards.end(); it++ ){
|
||||
MTGCardInstance * comparison = (*it).first;
|
||||
if (comparison!= card && !strcmp(comparison->getName(), card->getName())){
|
||||
comparison->owner->game->putInGraveyard(comparison);
|
||||
destroy = 1;
|
||||
}
|
||||
}
|
||||
if (destroy){
|
||||
card->owner->game->putInGraveyard(card);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int removed(MTGCardInstance * card){return 0;}
|
||||
|
||||
int testDestroy(){return 0;}
|
||||
|
||||
virtual ostream& toString(ostream& out) const
|
||||
{
|
||||
return out << "MTGLegendRule :::";
|
||||
}
|
||||
MTGLegendRule(int _id);
|
||||
int canBeInList(MTGCardInstance * card);
|
||||
int added(MTGCardInstance * card);
|
||||
int removed(MTGCardInstance * card);
|
||||
int testDestroy();
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
virtual MTGLegendRule * clone() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -149,34 +94,22 @@ public:
|
||||
int reactToClick(MTGCardInstance * card, int id);
|
||||
const char * getMenuText(){return "Momir";}
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
virtual MTGMomirRule * clone() const;
|
||||
};
|
||||
|
||||
|
||||
/* LifeLink */
|
||||
class MTGLifelinkRule:public MTGAbility{
|
||||
public:
|
||||
MTGLifelinkRule(int _id):MTGAbility(_id,NULL){};
|
||||
MTGLifelinkRule(int _id);
|
||||
|
||||
int receiveEvent(WEvent * event){
|
||||
if (event->type == WEvent::DAMAGE){
|
||||
WEventDamage * e = (WEventDamage *) event;
|
||||
Damage * d = e->damage;
|
||||
MTGCardInstance * card = d->source;
|
||||
if (d->damage>0 && card && card->basicAbilities[Constants::LIFELINK]){
|
||||
card->controller()->life+= d->damage;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int receiveEvent(WEvent * event);
|
||||
|
||||
int testDestroy(){return 0;}
|
||||
int testDestroy();
|
||||
|
||||
virtual ostream& toString(ostream& out) const
|
||||
{
|
||||
out << "MTGLifelinkRule ::: (";
|
||||
return MTGAbility::toString(out) << ")";
|
||||
}
|
||||
virtual ostream& toString(ostream& out) const;
|
||||
|
||||
virtual MTGLifelinkRule * clone() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -205,6 +138,7 @@ public:
|
||||
void Render();
|
||||
HUDDisplay(int _id);
|
||||
~HUDDisplay();
|
||||
virtual HUDDisplay * clone() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class TargetsList{
|
||||
Interruptible * getNextInterruptible(Interruptible * previous, int type);
|
||||
Spell * getNextSpellTarget(Spell * previous = 0);
|
||||
Damage * getNextDamageTarget(Damage * previous = 0);
|
||||
Targetable * getNextTarget(Targetable * previous, int type);
|
||||
Targetable * getNextTarget(Targetable * previous = 0, int type = -1);
|
||||
void initTargets(){cursor = 0;};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user