- fixed a few memory leaks (but Wagic still crashes on the PSP after a few games :( )
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-04-12 12:39:44 +00:00
parent e9cb57dbb1
commit e7678522ee
11 changed files with 361 additions and 272 deletions
+20
View File
@@ -0,0 +1,20 @@
PSPSDK=$(shell psp-config --pspsdk-path)
PSPDIR=$(shell psp-config --psp-prefix)
TARGET_LIB = libhgetools.a
OBJS = src/hge/hgecolor.o src/hge/hgeparticle.o \
src/hge/hgerect.o src/hge/hgevector.o \
src/hge/hgedistort.o src/hge/hgefont.o
INCDIR = include/psp include/psp/freetype2
LIBDIR = lib/psp
CFLAGS = -O2 -G0 -Wall
LIBS = -lgif -lfreetype -ljpeg -lpng -lz -lmikmod -lpsppower -lpspmpeg -lpspaudiocodec -lpspaudiolib -lpspaudio -lpspgum -lpspgu -lpsprtc -lm -lstdc++ -ljge300
include $(PSPSDK)/lib/build.mak
install: $(TARGET_LIB)
@cp libhgetools.a lib/psp
@echo "Done"
+4 -6
View File
@@ -843,6 +843,10 @@ class AProtectionFrom:public MTGAbility{
return 1; return 1;
} }
~AProtectionFrom(){
delete(cd);
}
}; };
//Aura Enchantments that provide controller of target life or damages at a given phase of their turn //Aura Enchantments that provide controller of target life or damages at a given phase of their turn
@@ -979,7 +983,6 @@ class AConvertLandToCreatures:public ListMaintainerAbility{
//Lords (Merfolk lord...) give power and toughness to OTHER creatures of their type, they can give them special abilities, regeneration //Lords (Merfolk lord...) give power and toughness to OTHER creatures of their type, they can give them special abilities, regeneration
class ALord:public ListMaintainerAbility{ class ALord:public ListMaintainerAbility{
public: public:
TargetChooser * tc;
int power, toughness; int power, toughness;
int ability; int ability;
int modifier; int modifier;
@@ -1035,7 +1038,6 @@ class ALord:public ListMaintainerAbility{
//Foreach (plague rats...) //Foreach (plague rats...)
class AForeach:public ListMaintainerAbility{ class AForeach:public ListMaintainerAbility{
public: public:
TargetChooser * tc;
int power, toughness; int power, toughness;
int includeSelf; int includeSelf;
AForeach(int _id, MTGCardInstance * card,MTGCardInstance * _target, TargetChooser * _tc, int _includeSelf, int _power = 0 , int _toughness = 0):ListMaintainerAbility(_id,card,_target){ AForeach(int _id, MTGCardInstance * card,MTGCardInstance * _target, TargetChooser * _tc, int _includeSelf, int _power = 0 , int _toughness = 0):ListMaintainerAbility(_id,card,_target){
@@ -2780,7 +2782,6 @@ class AMinionofLeshrac: public TargetAbility{
//Generic Kird Ape //Generic Kird Ape
class AKirdApe:public ListMaintainerAbility{ class AKirdApe:public ListMaintainerAbility{
public: public:
TargetChooser * tc;
int power; int power;
int toughness; int toughness;
int ability; int ability;
@@ -2822,9 +2823,6 @@ class AKirdApe:public ListMaintainerAbility{
return 0; return 0;
} }
~AKirdApe(){
delete tc;
}
}; };
-1
View File
@@ -95,7 +95,6 @@ class ActivatedAbility:public MTGAbility{
virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
virtual int reactToTargetClick(Targetable * object); virtual int reactToTargetClick(Targetable * object);
virtual int resolve() = 0; virtual int resolve() = 0;
virtual ~ActivatedAbility();
}; };
class TargetAbility:public ActivatedAbility{ class TargetAbility:public ActivatedAbility{
+2
View File
@@ -38,6 +38,7 @@ class TargetChooser: public TargetsList {
virtual int canTarget(Targetable * _target); virtual int canTarget(Targetable * _target);
virtual int full(){if (maxtargets != -1 && cursor>=maxtargets) {return 1;} else{return 0;}}; virtual int full(){if (maxtargets != -1 && cursor>=maxtargets) {return 1;} else{return 0;}};
virtual int ready(){return cursor;}; virtual int ready(){return cursor;};
virtual ~TargetChooser(){};
int targetListSet(); int targetListSet();
@@ -103,6 +104,7 @@ class DescriptorTargetChooser:public TargetZoneChooser{
DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1); DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1);
DescriptorTargetChooser(CardDescriptor * _cd, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1); DescriptorTargetChooser(CardDescriptor * _cd, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * target); virtual int canTarget(Targetable * target);
~DescriptorTargetChooser();
}; };
+1
View File
@@ -39,6 +39,7 @@ AIPlayer::~AIPlayer(){
stats->save(); stats->save();
SAFE_DELETE(stats); SAFE_DELETE(stats);
} }
//TODO delete clickstream!
} }
MTGCardInstance * AIPlayer::chooseCard(TargetChooser * tc, MTGCardInstance * source, int random){ MTGCardInstance * AIPlayer::chooseCard(TargetChooser * tc, MTGCardInstance * source, int random){
for (int i = 0; i < game->hand->nb_cards; i++){ for (int i = 0; i < game->hand->nb_cards; i++){
+1 -1
View File
@@ -66,7 +66,7 @@ void GameStateDuel::Start()
#ifdef TESTSUITE #ifdef TESTSUITE
if (testSuite) delete testSuite; SAFE_DELETE(testSuite);
testSuite = NEW TestSuite(RESPATH"/test/_tests.txt",mParent->collection); testSuite = NEW TestSuite(RESPATH"/test/_tests.txt",mParent->collection);
#endif #endif
+118 -36
View File
@@ -102,6 +102,9 @@ Trigger * AbilityFactory::parseTrigger(string magicText){
return NULL; return NULL;
} }
//Some basic functionalities that can be added automatically in the text file //Some basic functionalities that can be added automatically in the text file
/* /*
* Several objects are computed from the text string, and have a direct influence on what action we should take * Several objects are computed from the text string, and have a direct influence on what action we should take
@@ -114,6 +117,9 @@ Trigger * AbilityFactory::parseTrigger(string magicText){
int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
int dryMode = 0; int dryMode = 0;
if (!spell) dryMode = 1; if (!spell) dryMode = 1;
int dryModeResultSet = 0;
int dryModeResult = 0;
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
if (!card) card = spell->source; if (!card) card = spell->source;
MTGCardInstance * target = card->target; MTGCardInstance * target = card->target;
@@ -165,6 +171,9 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Tap in the cost ? //Tap in the cost ?
if (line.find("{t}") != string::npos) doTap = 1; if (line.find("{t}") != string::npos) doTap = 1;
TargetChooser * tc;
TargetChooser * lordTargets;
Trigger * trigger;
while (line.size()){ while (line.size()){
string s; string s;
found = line.find("&&"); found = line.find("&&");
@@ -173,8 +182,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
line = line.substr(found+2); line = line.substr(found+2);
if (!multi){ if (!multi){
OutputDebugString("Multi initializing\n"); OutputDebugString("Multi initializing\n");
if (!dryMode) {
multi = NEW MultiAbility(id, card, cost,doTap); multi = NEW MultiAbility(id, card, cost,doTap);
game->addObserver(multi); game->addObserver(multi);
}
OutputDebugString("Multi initialized\n"); OutputDebugString("Multi initialized\n");
} }
}else{ }else{
@@ -182,14 +193,13 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
line = ""; line = "";
} }
TargetChooser * tc = NULL; tc = NULL;
lordTargets = NULL;
TargetChooser * lordTargets = NULL;
int lordIncludeSelf = 1; int lordIncludeSelf = 1;
int lordType = 0; int lordType = 0;
string lordTargetsString; string lordTargetsString;
Trigger * trigger = parseTrigger(s); trigger = parseTrigger(s);
//Dirty way to remove the trigger text (could get in the way) //Dirty way to remove the trigger text (could get in the way)
if (trigger){ if (trigger){
found = s.find(":"); found = s.find(":");
@@ -210,7 +220,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Lord //Lord
found = s.find("lord("); found = s.find("lord(");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) {
dryModeResult = BAKA_EFFECT_GOOD;
dryModeResultSet = 1;
break;
}
unsigned int end = s.find(")", found+5); unsigned int end = s.find(")", found+5);
if (end != string::npos){ if (end != string::npos){
lordTargetsString = s.substr(found+5,end-found-5).c_str(); lordTargetsString = s.substr(found+5,end-found-5).c_str();
@@ -219,7 +233,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
} }
found = s.find("foreach("); found = s.find("foreach(");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) {
dryModeResult = BAKA_EFFECT_GOOD;
dryModeResultSet = 1;
break;
}
unsigned int end = s.find(")", found+8); unsigned int end = s.find(")", found+8);
if (end != string::npos){ if (end != string::npos){
lordTargetsString = s.substr(found+8,end-found-8).c_str(); lordTargetsString = s.substr(found+8,end-found-8).c_str();
@@ -228,7 +246,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
} }
found = s.find("aslongas("); found = s.find("aslongas(");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) {
dryModeResult = BAKA_EFFECT_GOOD;
dryModeResultSet = 1;
break;
}
unsigned int end = s.find(")", found+9); unsigned int end = s.find(")", found+9);
if (end != string::npos){ if (end != string::npos){
lordTargetsString = s.substr(found+9,end-found-9).c_str(); lordTargetsString = s.substr(found+9,end-found-9).c_str();
@@ -245,7 +267,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Untapper (Ley Druid...) //Untapper (Ley Druid...)
found = s.find("untap"); found = s.find("untap");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) {
dryModeResult = BAKA_EFFECT_GOOD;
dryModeResultSet = 1;
break;
}
if (tc){ if (tc){
game->addObserver(NEW AUntaper(id, card, cost, tc)); game->addObserver(NEW AUntaper(id, card, cost, tc));
}else{ }else{
@@ -259,7 +285,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Regeneration //Regeneration
found = s.find("}:regenerate"); found = s.find("}:regenerate");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) {
dryModeResult = BAKA_EFFECT_GOOD;
dryModeResultSet = 1;
break;
}
if (lordTargets){ if (lordTargets){
game->addObserver(NEW ALord(id,card,lordTargets,lordIncludeSelf,0,0,-1,cost)); game->addObserver(NEW ALord(id,card,lordTargets,lordIncludeSelf,0,0,-1,cost));
@@ -279,7 +309,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Token creator. Name, type, p/t, abilities //Token creator. Name, type, p/t, abilities
found = s.find("token("); found = s.find("token(");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode) {
dryModeResult = BAKA_EFFECT_GOOD;
dryModeResultSet = 1;
break;
}
int end = s.find(",", found); int end = s.find(",", found);
string sname = s.substr(found + 6,end - found - 6); string sname = s.substr(found + 6,end - found - 6);
int previous = end+1; int previous = end+1;
@@ -310,7 +344,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//MoveTo Move a card from a zone to another //MoveTo Move a card from a zone to another
found = s.find("moveto("); found = s.find("moveto(");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_BAD; //TODO : depends on where from, where to... if (dryMode) {
dryModeResult = BAKA_EFFECT_BAD;
dryModeResultSet = 1;
break;
} //TODO : depends on where from, where to...
int end = s.find(")",found+1); int end = s.find(")",found+1);
string szone = s.substr(found + 7,end - found - 7); string szone = s.substr(found + 7,end - found - 7);
if (tc){ if (tc){
@@ -343,7 +381,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Copy a target //Copy a target
found = s.find("copy "); found = s.find("copy ");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; //TODO : if (dryMode) {
dryModeResult = BAKA_EFFECT_GOOD;
dryModeResultSet = 1;
break;
} //TODO :
if (tc){ if (tc){
ACopier * a = NEW ACopier(id,card,tc,cost); ACopier * a = NEW ACopier(id,card,tc,cost);
if (may){ if (may){
@@ -363,7 +405,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
found = s.find("bury"); found = s.find("bury");
if (found != string::npos){ if (found != string::npos){
if (trigger){ if (trigger){
if (dryMode) return BAKA_EFFECT_BAD; if (dryMode) {
dryModeResult = BAKA_EFFECT_BAD;
dryModeResultSet = 1;
break;
}
BuryEvent * action = NEW BuryEvent(); BuryEvent * action = NEW BuryEvent();
game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action)); game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action));
}else{ }else{
@@ -379,8 +425,9 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER); int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER);
int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER); int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER);
delete targetAll; delete targetAll;
if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD; if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) dryModeResult = BAKA_EFFECT_GOOD;
return BAKA_EFFECT_BAD; else dryModeResult = BAKA_EFFECT_BAD;
break;
}else{ }else{
if (cost){ if (cost){
game->addObserver(NEW AAllDestroyer(id, card,targetAll,1,cost,doTap)); game->addObserver(NEW AAllDestroyer(id, card,targetAll,1,cost,doTap));
@@ -390,7 +437,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
} }
} }
}else{ }else{
if (dryMode) return BAKA_EFFECT_BAD; if (dryMode){
dryModeResult = BAKA_EFFECT_BAD;
break;
}
if (tc){ if (tc){
game->addObserver(NEW ABurier(id, card,tc)); game->addObserver(NEW ABurier(id, card,tc));
}else{ }else{
@@ -418,8 +468,9 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER); int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER);
int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER); int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER);
delete targetAll; delete targetAll;
if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD; if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) dryModeResult = BAKA_EFFECT_GOOD;
return BAKA_EFFECT_BAD; else dryModeResult = BAKA_EFFECT_BAD;
break;
}else{ }else{
if (cost){ if (cost){
game->addObserver(NEW AAllDestroyer(id, card,targetAll,0,cost,doTap)); game->addObserver(NEW AAllDestroyer(id, card,targetAll,0,cost,doTap));
@@ -429,7 +480,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
} }
} }
}else{ }else{
if (dryMode) return BAKA_EFFECT_BAD; if (dryMode){
dryModeResult = BAKA_EFFECT_BAD;
break;
}
if (tc){ if (tc){
game->addObserver(NEW ADestroyer(id, card,tc,0,cost)); game->addObserver(NEW ADestroyer(id, card,tc,0,cost));
}else{ }else{
@@ -452,7 +506,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
}else{ }else{
damage = atoi(s.substr(start+1).c_str()); damage = atoi(s.substr(start+1).c_str());
} }
if (dryMode) return BAKA_EFFECT_BAD; if (dryMode){
dryModeResult = BAKA_EFFECT_BAD;
break;
}
if (tc){ if (tc){
MTGAbility * a = NEW ADamager(id, card, cost, damage, tc,doTap); MTGAbility * a = NEW ADamager(id, card, cost, damage, tc,doTap);
if (multi){ if (multi){
@@ -485,7 +542,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
}else{ }else{
life = atoi(s.substr(start+1).c_str()); life = atoi(s.substr(start+1).c_str());
} }
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode){
dryModeResult = BAKA_EFFECT_GOOD;
break;
}
if (tc){ if (tc){
//TODO ? //TODO ?
}else{ }else{
@@ -510,7 +570,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
}else{ }else{
nbcards = atoi(s.substr(start+1).c_str()); nbcards = atoi(s.substr(start+1).c_str());
} }
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode){
dryModeResult = BAKA_EFFECT_GOOD;
break;
}
if (trigger){ if (trigger){
DrawEvent * action = NEW DrawEvent(card->controller(),nbcards); DrawEvent * action = NEW DrawEvent(card->controller(),nbcards);
game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action)); game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action));
@@ -533,8 +596,12 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
int power, toughness; int power, toughness;
if ( parsePowerToughness(s,&power, &toughness)){ if ( parsePowerToughness(s,&power, &toughness)){
if (dryMode){ if (dryMode){
if (power >=0 && toughness >= 0 ) return BAKA_EFFECT_GOOD; if (power >=0 && toughness >= 0 ) {
return BAKA_EFFECT_BAD; dryModeResult = BAKA_EFFECT_GOOD;
}else{
dryModeResult = BAKA_EFFECT_BAD;
}
break;
} }
int limit = 0; int limit = 0;
unsigned int limit_str = s.find("limit:"); unsigned int limit_str = s.find("limit:");
@@ -573,7 +640,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Mana Producer //Mana Producer
found = s.find("add"); found = s.find("add");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode){
dryModeResult = BAKA_EFFECT_GOOD;
break;
}
ManaCost * input = ManaCost::parseManaCost(s.substr(0,found)); ManaCost * input = ManaCost::parseManaCost(s.substr(0,found));
ManaCost * output = ManaCost::parseManaCost(s.substr(found)); ManaCost * output = ManaCost::parseManaCost(s.substr(found));
if (!input->isNull() || doTap){ if (!input->isNull() || doTap){
@@ -604,14 +674,15 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
if (found > 0 && s[found-1] == '-') modifier = 0; if (found > 0 && s[found-1] == '-') modifier = 0;
if (dryMode){ if (dryMode){
if (j == Constants::DEFENDER){ if (j == Constants::DEFENDER){
if (modifier == 1) return BAKA_EFFECT_BAD; if (modifier == 1) dryModeResult = BAKA_EFFECT_BAD;
return BAKA_EFFECT_GOOD; else dryModeResult = BAKA_EFFECT_GOOD;
}else{ }else{
if (modifier == 1) return BAKA_EFFECT_GOOD; if (modifier == 1) dryModeResult = BAKA_EFFECT_GOOD;
return BAKA_EFFECT_BAD; else dryModeResult = BAKA_EFFECT_BAD;
} }
} dryModeResultSet = 1;
break;
}else{
if (lordType == PARSER_LORD){ if (lordType == PARSER_LORD){
game->addObserver(NEW ALord(id,card,lordTargets,lordIncludeSelf,0,0,j,0,modifier)); game->addObserver(NEW ALord(id,card,lordTargets,lordIncludeSelf,0,0,j,0,modifier));
}else if (lordType == PARSER_ASLONGAS){ }else if (lordType == PARSER_ASLONGAS){
@@ -635,11 +706,16 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
continue; continue;
} }
} }
}
if (dryModeResultSet) break;
//Tapper (icy manipulator) //Tapper (icy manipulator)
found = s.find("tap"); found = s.find("tap");
if (found != string::npos){ if (found != string::npos){
if (dryMode) return BAKA_EFFECT_GOOD; if (dryMode){
dryModeResult = BAKA_EFFECT_GOOD;
break;
}
if (tc){ if (tc){
game->addObserver(NEW ATapper(id, card, cost, tc)); game->addObserver(NEW ATapper(id, card, cost, tc));
}else{ }else{
@@ -654,7 +730,16 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
} }
if (dryMode){
SAFE_DELETE(tc);
SAFE_DELETE(lordTargets);
SAFE_DELETE(multi);
SAFE_DELETE(cost);
SAFE_DELETE(trigger);
return dryModeResult;
} }
}
return result; return result;
} }
@@ -1597,7 +1682,7 @@ MTGAbility::MTGAbility(int id, MTGCardInstance * _source,Damageable * _target ):
} }
MTGAbility::~MTGAbility(){ MTGAbility::~MTGAbility(){
SAFE_DELETE(cost);
} }
//returns 1 if this ability needs to be removed from the list of active abilities //returns 1 if this ability needs to be removed from the list of active abilities
@@ -1687,9 +1772,6 @@ int ActivatedAbility::reactToTargetClick(Targetable * object){
} }
ActivatedAbility::~ActivatedAbility(){
if (cost) delete cost;
}
//The whole targetAbility mechanism is messed up, mainly because of its interactions with //The whole targetAbility mechanism is messed up, mainly because of its interactions with
// the ActionLayer, GameObserver, and parent class ActivatedAbility. // the ActionLayer, GameObserver, and parent class ActivatedAbility.
+2 -1
View File
@@ -87,7 +87,7 @@ void MTGCardInstance::initMTGCI(){
doDamageTest = 1; doDamageTest = 1;
belongs_to=NULL; belongs_to=NULL;
tapped = 0; tapped = 0;
blockers = NEW Blockers(); blockers = NULL;
untapping = 0; untapping = 0;
summoningSickness = 0; summoningSickness = 0;
target = NULL; target = NULL;
@@ -110,6 +110,7 @@ void MTGCardInstance::addType(int type){
} }
Blockers * MTGCardInstance::getBlockers(){ Blockers * MTGCardInstance::getBlockers(){
if (!blockers) blockers = NEW Blockers();
return blockers; return blockers;
} }
+10 -24
View File
@@ -8,24 +8,23 @@
TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInstance * card){ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInstance * card){
if (!s.size()) return NULL;
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
MTGGameZone * zones[10]; MTGGameZone * zones[10];
int nbzones = 0; int nbzones = 0;
int size = s.size();
if (size != 0){
unsigned int found; unsigned int found;
found = s.find("player"); found = s.find("player");
if (found != string::npos){ if (found != string::npos){
int maxtargets = 1; int maxtargets = 1;
unsigned int several = s.find_first_of('s',5); unsigned int several = s.find_first_of('s',5);
if (several != string::npos) maxtargets = -1; if (several != string::npos) maxtargets = -1;
found = s.find("creature"); found = s.find("creature");
if (found != string::npos){ if (found != string::npos) return NEW DamageableTargetChooser(card,maxtargets); //Any Damageable target (player, creature)
return NEW DamageableTargetChooser(card,maxtargets); //Any Damageable target (player, creature)
}else{
return NEW PlayerTargetChooser(card,maxtargets); //Any player return NEW PlayerTargetChooser(card,maxtargets); //Any player
} }
}else{
string s1; string s1;
found = s.find("|"); found = s.find("|");
if (found != string::npos){ if (found != string::npos){
@@ -125,7 +124,6 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
}else{ }else{
cd->attacker = 1; cd->attacker = 1;
} }
//Blocker //Blocker
}else if (attribute.find("blocking") != string::npos){ }else if (attribute.find("blocking") != string::npos){
if (minus){ if (minus){
@@ -133,7 +131,6 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
}else{ }else{
cd->defenser = (MTGCardInstance *)1; cd->defenser = (MTGCardInstance *)1;
} }
//Tapped, untapped //Tapped, untapped
}else if (attribute.find("tapped") != string::npos){ }else if (attribute.find("tapped") != string::npos){
if (minus){ if (minus){
@@ -151,9 +148,6 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
cd->colors[cid] = -1; cd->colors[cid] = -1;
}else{ }else{
cd->colors[cid] = 1; cd->colors[cid] = 1;
#ifdef WIN32
OutputDebugString("COLOR FOUND !!!");
#endif
} }
} }
} }
@@ -181,12 +175,7 @@ OutputDebugString("COLOR FOUND !!!");
} }
} }
} }
if (nbminuses == 0){ if (nbminuses == 0) cd->mode = CD_OR;
#ifdef WIN32
OutputDebugString("Switching to OR\n");
#endif
cd->mode = CD_OR;
}
typeName = typeName.substr(0,found); typeName = typeName.substr(0,found);
} }
//X targets allowed ? //X targets allowed ?
@@ -199,10 +188,8 @@ OutputDebugString("COLOR FOUND !!!");
if (typeName.compare("*")!=0) cd->setSubtype(typeName); if (typeName.compare("*")!=0) cd->setSubtype(typeName);
tc = NEW DescriptorTargetChooser(cd,zones,nbzones,card,maxtargets); tc = NEW DescriptorTargetChooser(cd,zones,nbzones,card,maxtargets);
#ifdef WIN32
OutputDebugString("Advanced Attributes 2 \n");
#endif
}else{ }else{
delete(cd);
return NULL; return NULL;
} }
}else{ }else{
@@ -219,9 +206,6 @@ OutputDebugString("COLOR FOUND !!!");
} }
} }
return tc; return tc;
}
}
return NULL;
} }
TargetChooser * TargetChooserFactory::createTargetChooser(MTGCardInstance * card){ TargetChooser * TargetChooserFactory::createTargetChooser(MTGCardInstance * card){
@@ -421,7 +405,9 @@ int DescriptorTargetChooser::canTarget(Targetable * target){
return 0; return 0;
} }
DescriptorTargetChooser::~DescriptorTargetChooser(){
SAFE_DELETE(cd);
}
/** /**
Choose a creature Choose a creature