fixed a couple memleaks, also added human player targeting for blocking.

This commit is contained in:
omegablast2002@yahoo.com
2012-04-02 16:48:33 +00:00
parent b705158e13
commit 0b1327bf01
5 changed files with 81 additions and 32 deletions

View File

@@ -3483,6 +3483,7 @@ MTGCardInstance * OriginalSrc;
MTGCardInstance * storedTarget;
MTGAbility * storedAbility;
MTGAbility * clonedStored;
MTGAbility * mainAbility;
string menu;
AADynamic(GameObserver* observer, int id, MTGCardInstance * card, Damageable * _target,int type = 0,int effect = 0,int who = 0,int amountsource = 1,MTGAbility * storedAbility = NULL, ManaCost * _cost = NULL);

View File

@@ -243,15 +243,17 @@ public:
class MTGBlockRule: public PermanentAbility
{
public:
string blockmenu;
TargetChooser * tcb;
MTGAbility * blocker;
MTGAbility * blockAbility;
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card);
virtual ostream& toString(ostream& out) const;
MTGBlockRule(GameObserver* observer, int _id);
const char * getMenuText()
{
return "Blocker";
}
const char * getMenuText();
virtual MTGBlockRule * clone() const;
~MTGBlockRule();
};
/* Persist Rule */

View File

@@ -1758,6 +1758,7 @@ ActivatedAbility(observer, id, card, _cost, 0),type(type),effect(effect),who(who
menu = "";
OriginalSrc = source;
clonedStored = NULL;
mainAbility = NULL;
}
int AADynamic::resolve()
@@ -1934,58 +1935,58 @@ int AADynamic::resolve()
{
case DYNAMIC_ABILITY_EFFECT_STRIKE://deal damage
{
AADamager * a = NEW AADamager(game, this->GetId(), source,tosrc == true?(Targetable*)OriginalSrc:(Targetable*)_target,sourceamountstring);
activateMainAbility(a,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
mainAbility = NEW AADamager(game, this->GetId(), source,tosrc == true?(Targetable*)OriginalSrc:(Targetable*)_target,sourceamountstring);
activateMainAbility(mainAbility,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
if(eachother)
{
AADamager * a = NEW AADamager(game, this->GetId(), source,tosrc == true?(Targetable*)OriginalSrc:(Targetable*)_target,targetamountstring);
activateMainAbility(a,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
mainAbility = NEW AADamager(game, this->GetId(), source,tosrc == true?(Targetable*)OriginalSrc:(Targetable*)_target,targetamountstring);
activateMainAbility(mainAbility,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
}
return 1;
break;
}
case DYNAMIC_ABILITY_EFFECT_DRAW://draw cards
{
AADrawer * a = NEW AADrawer(game, this->GetId(), source,_target,NULL, sourceamountstring);
return activateMainAbility(a,source,_target);
mainAbility = NEW AADrawer(game, this->GetId(), source,_target,NULL, sourceamountstring);
return activateMainAbility(mainAbility,source,_target);
break;
}
case DYNAMIC_ABILITY_EFFECT_LIFEGAIN://gain life
{
AALifer * a = NEW AALifer(game, this->GetId(), source,_target, sourceamountstring);
return activateMainAbility(a,source,_target);
mainAbility = NEW AALifer(game, this->GetId(), source,_target, sourceamountstring);
return activateMainAbility(mainAbility,source,_target);
break;
}
case DYNAMIC_ABILITY_EFFECT_PUMPPOWER://pump power
{
PTInstant * a = NEW PTInstant(game, this->GetId(), source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target,NEW WParsedPT(sourceamount,0));
return activateMainAbility(a,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
mainAbility = NEW PTInstant(game, this->GetId(), source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target,NEW WParsedPT(sourceamount,0));
return activateMainAbility(mainAbility,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
break;
}
case DYNAMIC_ABILITY_EFFECT_PUMPTOUGHNESS://pump toughness
{
PTInstant * a = NEW PTInstant(game, this->GetId(), source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target,NEW WParsedPT(0,sourceamount));
return activateMainAbility(a,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
mainAbility = NEW PTInstant(game, this->GetId(), source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target,NEW WParsedPT(0,sourceamount));
return activateMainAbility(mainAbility,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
break;
}
case DYNAMIC_ABILITY_EFFECT_PUMPBOTH://pump both
{
PTInstant * a = NEW PTInstant(game, this->GetId(), source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target,NEW WParsedPT(sourceamount,sourceamount));
return activateMainAbility(a,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
mainAbility = NEW PTInstant(game, this->GetId(), source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target,NEW WParsedPT(sourceamount,sourceamount));
return activateMainAbility(mainAbility,source,tosrc == true?OriginalSrc:(MTGCardInstance*)_target);
break;
}
case DYNAMIC_ABILITY_EFFECT_LIFELOSS://lose life
{
string altered = "-";
altered.append(sourceamountstring);
AALifer * a = NEW AALifer(game, this->GetId(), source,_target, altered);
return activateMainAbility(a,source,_target);
mainAbility = NEW AALifer(game, this->GetId(), source,_target, altered);
return activateMainAbility(mainAbility,source,_target);
break;
}
case DYNAMIC_ABILITY_EFFECT_DEPLETE://deplete cards
{
AADepleter * a = NEW AADepleter(game, this->GetId(), source,_target, sourceamountstring);
return activateMainAbility(a,source,_target);
mainAbility = NEW AADepleter(game, this->GetId(), source,_target, sourceamountstring);
return activateMainAbility(mainAbility,source,_target);
break;
}
case DYNAMIC_ABILITY_EFFECT_COUNTERSONEONE:
@@ -2015,7 +2016,9 @@ int AADynamic::activateMainAbility(MTGAbility * toActivate,MTGCardInstance * sou
return 1;
}
toActivate->oneShot = true;
toActivate->forceDestroy = 1;
toActivate->resolve();
SAFE_DELETE(toActivate);
return 1;
}

View File

@@ -317,7 +317,7 @@ int MillCost::doPay()
MTGCardInstance * _target = (MTGCardInstance *) target;
if (target)
{
source->storedCard = target;
source->storedCard = (MTGCardInstance*)_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1];
_target->controller()->game->putInZone(
_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1],
_target->controller()->game->library, _target->controller()->game->graveyard);
@@ -339,7 +339,7 @@ MillExileCost::MillExileCost(TargetChooser *_tc)
int MillExileCost::doPay()
{
MTGCardInstance * _target = (MTGCardInstance *) target;
source->storedCard = target;
source->storedCard = (MTGCardInstance*)_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1];
if (target)
{
_target->controller()->game->putInZone(

View File

@@ -1494,6 +1494,9 @@ MTGBlockRule::MTGBlockRule(GameObserver* observer, int _id) :
PermanentAbility(observer, _id)
{
aType = MTGAbility::MTG_BLOCK_RULE;
tcb = NULL;
blocker = NULL;
blockAbility = NULL;
}
int MTGBlockRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
@@ -1503,7 +1506,13 @@ int MTGBlockRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
)
{
if (card->canBlock() && !card->isPhased)
{
if(card->isDefenser())
blockmenu = "Remove Blocker";
else
blockmenu = "Assign To Block";
return 1;
}
}
return 0;
}
@@ -1515,17 +1524,45 @@ int MTGBlockRule::reactToClick(MTGCardInstance * card)
MTGCardInstance * currentOpponent = card->isDefenser();
bool result = false;
int canDefend = 0;
while (!result)
if(card->controller()->isHuman())
{
currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent);
canDefend = card->toggleDefenser(currentOpponent);
if(!currentOpponent)
{
DebugTrace("Defenser Toggle: " << card->getName() << endl
<< "- canDefend: " << (canDefend == 0) << endl
<< "- currentOpponent: " << currentOpponent);
result = (canDefend || currentOpponent == NULL);
SAFE_DELETE(blockAbility);
TargetChooserFactory tf(card->getObserver());
tcb = tf.createTargetChooser("blockable",card);
tcb->targetter = NULL;
blocker = NEW AABlock(card->getObserver(),-1,card,NULL);
blocker->oneShot = true;
blocker->forceDestroy = 1;
blocker->canBeInterrupted = false;
blockAbility = NEW GenericTargetAbility(game, "choose attacker","blockers",-1, card,tcb, blocker);
blockAbility->oneShot = true;
blockAbility->forceDestroy = 1;
blockAbility->canBeInterrupted = false;
return blockAbility->reactToTargetClick(card);
}
else
card->toggleDefenser(NULL);
}
return 1;
else
while (!result)
{
currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent);
canDefend = card->toggleDefenser(currentOpponent);
DebugTrace("Defenser Toggle: " << card->getName() << endl
<< "- canDefend: " << (canDefend == 0) << endl
<< "- currentOpponent: " << currentOpponent);
result = (canDefend || currentOpponent == NULL);
}
return 1;
}
const char * MTGBlockRule::getMenuText()
{
return blockmenu.c_str();
}
ostream& MTGBlockRule::toString(ostream& out) const
@@ -1538,6 +1575,12 @@ MTGBlockRule * MTGBlockRule::clone() const
{
return NEW MTGBlockRule(*this);
}
MTGBlockRule::~MTGBlockRule()
{
SAFE_DELETE(blockAbility);
}
//
// Attacker chooses blockers order
//