Files
wagic/projects/mtg/src/Counters.cpp
omegablast2002@yahoo.com 6399917d25 changes:
added abilities:
proliferate
ProliferateChooser:new targetchooser for cards with counter and poison counters "proliferation".

MenuAbility:new internal ability to create custom menus of abilities which can be activated in sequence one after another.

multikicker, syntax kicker=multi{b}
works with variable word "kicked", the amount of times it was kicked.

target=<number>tc,target=<upto:>tc,target=<anyamount>tc,target(<number>tc),target(<upto:>tc),target(<anynumber>tc);
multitarget is now supported with the exception of "devided any way you choose" which can not be supported becuase we allow detoggling of targeted cards with a "second" click....so you can not click the same card 2 times to add it to the targets list twice for example.
this is minor, as the bulk of multitarget is not "devided"
removed 's' parsing for multitarget, added a limit of 1000 to "unlimited" for easier handling; we currently can't handle activation of an ability on a 1000 cards very well on any platform(infact i don't suggest it)

Countershroud(counterstring), this MTGAbility allows you to denote that a card can not have counters of the type "counterstring" put on it.
"any" is for no counters allowed at all. this is a replacement effect. cards state that they can still be the targets of counter effects, however on resolve nothing is placed on them instead.

@counteradded(counterstring) from(target):,@counterremoved(counterstring) from(target):: these are triggers for cards which state "whenever you add a counter of "counterstring" to "target"; added counterEvents struct; 

other changes:
added support for ai handling of multitargeted spells.

changed a few of delete( into SAFE_DELETE(, safed up a couple areas where they did not seem safe to me;

added better handling of menus presented to ai, it will try to select the best based on eff returns.

added varible lastactioncontroller for ai use, it keeps it truely from ever tripping over itself and brings ai more inline with MTG rules.

converted TC into a protected member.
added "abilitybelongsto" string to tc, and set "owner" of the tc. a tc should never belong to "no one" it should always have a owner.
abilitybelongs to string is solely for easier debugging, i found it was a pain to never know what ability created a tc while i coded multitarget. the owner of the tc is the only one that should be using it, if an ability needs to declare the opponent as the owner (choose discard which is currently unsupported for example) this will allow us to better handle that situation by setting the tc owner in the ability which called it.

rewrote the logic of "checkonly" in ai choose targets, the only time it is "checkonly" is when it is trying to see if it had a target for a spell before it cast it, i now set this in the actual function call instead, the old method was far to error prone.

wrote logic for ai checking of menu objects presented to it,
ai will now make better choices when a menu is presented to it based on what it already knows. this changes it from it's old method of "just click the first option".

taught ai how to use multi-mana producers such as birds and duel lands by adding a method for it to find it's mana for a payment. it can effectively use cards like birds of paradise and sol ring(without locking up). It's primary method of pMana searching was maintain for performance(no need to deep search if we have it in pMana).

added a vector to actionlayer to store mana abilities for pMana. this provides us with a dramatic improvement when mana lords are present by reducing the amount of objects that need checking when ai checks pMana.
with 80 mana objects and a ton of lords one instance i checked went from 8000ish checks down to 80<===big difference.

added "tapped" green coloring(sorry i missed that!)...added red coloring to current actionLayers current action card (usually the source).

changed "type(" restrictions second amount from atoi into wparsedint for more flexiable coding.

add "&" parsing to CD targetchooser, removed "iscolorandcolor" variables and functions becuase they were a hack the real fix was this.
cretaure[dragon&black&blue] a creature that is a dragon, and black and also blue.

changed some of the ai computeactions and
removed unneeded gaurds in ai chooseblockers, they did more harm then good.
2011-09-01 20:03:26 +00:00

201 lines
5.6 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::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 = GameObserver::GetInstance();
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]->cancels(_power, _toughness) && !counters[i]->name.size() && counters[i]->nb > 0)
{
counters[i]->removed();
counters[i]->nb--;
WEvent * t = NEW WEventCounters(this,_name,_power*-1,_toughness*-1,false,true);
dynamic_cast<WEventCounters*>(t)->targetCard = this->target;
g->receiveEvent(t);
delete(e);
return mCount;
}
}
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++;
}
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 = GameObserver::GetInstance();
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 = game->GetInstance();
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;
}