Files
wagic/projects/mtg/src/Counters.cpp
omegablast2002@yahoo.com fbebcd681e added a new aihint #HINT:dontattackwith(targetchooser)
which tells the ai not to use the targetible cards as attackers, this can be card names, and CD modes.

modified the way ai handles multikicker. it will not be casting 1/1 joragas anymore :D

made WParsedInt ignore "+" signs....

added a new affinity ability...autohand=affinity(creature[vampire]|mygraveyard) ....
this is essentially affinity for creatures in your grave.

added supkeyword to clone clone addtype(zombie)....it adds the type listed to the cards types on clone...

reparse PT bonus on resolve.

reworked bushido, it should now work correctly...aside from that it now excepts word variables...fumiko is now bushido(type:creature[attacking]:battlefield/type:creature[attacking]:battlefield)

added a keyword to access acontrolsteal..the keyword is "steal"
auto=ueot steal target(creature) 

reworked persist to handle undying..added the new counter handling rules intruduced by wotc in ISD


added a vector cardsAbilities to mtgcardinstance...this keeps the abilities added to the game for a card to use stored where we can easly alter or remove them.

added an automatic increase to geteff return if the ability is a putinplay ability.

finished coding support for flip and double sided cards, though viewing the "other side" is still not possible yet.
the ability follows the mtg rules.
the ability syntax is flip(card name)...a card can flip into any other card by name...even flip into itself.

added a "canPay() call for Ninja cost...to prevent it from coming up in a menu unless you're in blockers....

added 3 new restriction types that work very similar to type(
thisturn(tc)~morethan~2
lastturn(tc)~lessthan~thisturn(tc)
compare(wordvarible)~equalto~compare(wordvarible)

these are pretty self explanitory.

moved "&&" ability parsing below "this(" allowing "this(" to grant abilities now which contain &&...enclave egologist bug is fixed by this.

fixed an issue with combatspirit link for some reason the way i was doing the bool was not always working.

took care of the todo for AProtectionFrom...you can now give a protection from(blah) in a instant or ueot ability.

added altho very limited right now a "targetedplayer" tc word. i hope to increase this with time.

as always my sidekick doc already has some cards coded for this and test will follow the addition of the cards.
2012-01-31 14:07:40 +00:00

205 lines
5.7 KiB
C++

#include "PrecompiledHeader.h"
#include "Counters.h"
#include "MTGCardInstance.h"
Counter::Counter(MTGCardInstance * _target, int _power, int _toughness)
{
init(_target, "", _power, _toughness);
}
Counter::Counter(MTGCardInstance * _target, const char * _name, int _power, int _toughness)
{
init(_target, _name, _power, _toughness);
}
int Counter::init(MTGCardInstance * _target, const char * _name, int _power, int _toughness)
{
target = _target;
name = _name;
power = _power;
toughness = _toughness;
nb = 1;
return 1;
}
bool Counter::sameAs(const char * _name, int _power, int _toughness)
{
if (power == 0 && toughness == 0)
return (name.compare(_name) == 0);
return (power == _power && toughness == _toughness);
}
bool Counter::cancels(int _power, int _toughness)
{
if (power == 0 && toughness == 0)
return false;
return (power == -_power && toughness == -_toughness);
}
int Counter::cancelCounter(int power, int toughness)
{
while(this->target->counters->hasCounter(power,toughness) && this->target->counters->hasCounter(power*-1,toughness*-1))
{
GameObserver *g = this->target->getObserver();
this->removed();
this->nb--;
WEvent * t = NEW WEventCounters(NULL,"",power*-1,toughness*-1,false,true);
dynamic_cast<WEventCounters*>(t)->targetCard = this->target;
g->receiveEvent(t);
this->target->counters->removeCounter(power,toughness);
}
return 1;
}
int Counter::added()
{
if (power != 0 || toughness != 0)
{
target->power += power;
target->addToToughness(toughness);
}
return 1;
}
int Counter::removed()
{
if (power != 0 || toughness != 0)
{
target->power -= power;
target->addToToughness(-toughness);
}
return 1;
}
Counters::Counters(MTGCardInstance * _target) :
target(_target)
{
mCount = 0;
}
Counters::~Counters()
{
for (int i = 0; i < mCount; i++)
{
SAFE_DELETE(counters[i]);
}
}
int Counters::addCounter(const char * _name, int _power, int _toughness)
{
/*420.5n If a permanent has both a +1/+1 counter and a -1/-1 counter on it, N +1/+1 and N -1/-1 counters are removed from it, where N is the smaller of the number of +1/+1 and -1/-1 counters on it.*/
GameObserver *g = target->getObserver();
WEvent * e = NEW WEventCounters(this,_name,_power,_toughness);
dynamic_cast<WEventCounters*>(e)->targetCard = this->target;
if (e == g->replacementEffects->replace(e))
{
for (int i = 0; i < mCount; i++)
{
if (counters[i]->sameAs(_name, _power, _toughness))
{
counters[i]->added();
counters[i]->nb++;
WEvent * j = NEW WEventCounters(this,_name,_power,_toughness,true,false);
dynamic_cast<WEventCounters*>(j)->targetCard = this->target;
g->receiveEvent(j);
delete(e);
return mCount;
}
}
Counter * counter = NEW Counter(target, _name, _power, _toughness);
counters.push_back(counter);
counter->added();
WEvent * w = NEW WEventCounters(this,_name,_power,_toughness,true,false);
dynamic_cast<WEventCounters*>(w)->targetCard = this->target;
g->receiveEvent(w);
mCount++;
this->target->doDamageTest = 1;
this->target->afterDamage();
}
delete(e);
return mCount;
}
int Counters::addCounter(int _power, int _toughness)
{
return addCounter("", _power, _toughness);
}
int Counters::init()
{
for (int i = mCount - 1; i >= 0; i--)
{
while (counters[i]->nb >= 1)
{
counters[i]->removed();
counters[i]->nb--;
}
}
return 1;
}
int Counters::removeCounter(const char * _name, int _power, int _toughness)
{
for (int i = 0; i < mCount; i++)
{
if (counters[i]->sameAs(_name, _power, _toughness))
{
if (counters[i]->nb < 1)
return 0;
counters[i]->removed();
counters[i]->nb--;
GameObserver *g = target->getObserver();
WEvent * e = NEW WEventCounters(this,_name,_power,_toughness,false,true);
dynamic_cast<WEventCounters*>(e)->targetCard = this->target;
g->receiveEvent(e);
//special case:if a card is suspended and no longer has a time counter when the last is removed, the card is cast.
if (target->suspended && !target->counters->hasCounter("time",0,0))
{
GameObserver * game = target->getObserver();
MTGCardInstance * copy = target->controller()->game->putInZone(target, target->currentZone, target->controller()->game->stack);
game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, NULL,1, 0);
game->targetChooser = NULL;
}
return mCount;
}
}
return 0;
}
int Counters::removeCounter(int _power, int _toughness)
{
return removeCounter("", _power, _toughness);
}
Counter * Counters::hasCounter(const char * _name, int _power, int _toughness)
{
for (int i = 0; i < mCount; i++)
{
if (counters[i]->sameAs(_name, _power, _toughness))
{
if (counters[i]->nb > 0)
return counters[i];
}
}
return NULL;
}
Counter * Counters::hasCounter(int _power, int _toughness)
{
return hasCounter("", _power, _toughness);
}
Counter * Counters::getNext(Counter * previous)
{
int found = 0;
for (int i = 0; i < mCount; i++)
{
if (found && counters[i]->nb > 0)
return counters[i];
if (counters[i] == previous)
found = 1;
}
return NULL;
}