- Minor refactor of a few files: removed some unnecessary calls, etc...

This commit is contained in:
wagic.the.homebrew
2011-09-22 10:07:05 +00:00
parent ee4c7e23bd
commit f649fee465
5 changed files with 231 additions and 361 deletions
+1 -1
View File
@@ -101,7 +101,7 @@ class AIPlayerBaka: public AIPlayer{
virtual bool payTheManaCost(ManaCost * cost, MTGCardInstance * card = NULL,vector<MTGAbility*> gotPayment = vector<MTGAbility*>()); virtual bool payTheManaCost(ManaCost * cost, MTGCardInstance * card = NULL,vector<MTGAbility*> gotPayment = vector<MTGAbility*>());
virtual int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0); virtual int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
virtual ManaCost * getPotentialMana(MTGCardInstance * card = NULL); virtual ManaCost * getPotentialMana(MTGCardInstance * card = NULL);
int selectAbility(); virtual int selectAbility();
public: public:
enum { enum {
+7 -2
View File
@@ -44,10 +44,17 @@ class MTGAbility : public ActionElement
{ {
private: private:
ManaCost* mCost; ManaCost* mCost;
protected: protected:
char menuText[50]; char menuText[50];
GameObserver * game; GameObserver * game;
// returns target itself if it is a player, or its controller if it is a card
static Player * getPlayerFromTarget(Targetable * target);
// returns target itself if it is a player, or its controller if it is a card
static Player * getPlayerFromDamageable(Damageable * target);
public: public:
enum enum
{ {
@@ -207,8 +214,6 @@ public:
COUNTERS = 30, COUNTERS = 30,
PUT_INTO_PLAY_WITH_KICKER = 31, PUT_INTO_PLAY_WITH_KICKER = 31,
STANDARD_FIZZLER = 32, STANDARD_FIZZLER = 32,
}; };
}; };
+3 -20
View File
@@ -1216,35 +1216,19 @@ int AIPlayerBaka::selectHintAbility()
int AIPlayerBaka::selectAbility() int AIPlayerBaka::selectAbility()
{ {
static bool findingAbility = false;
//this guard is put in place to prevent Ai from
//ever running selectAbility() function WHILE its already doing so.
// Break if this happens in debug mode. If this happens, it's actually a bug
assert(!findingAbility);
if (findingAbility)
{//is already looking kick me out of this function!
return 0;
}
findingAbility = true;//im looking now safely!
// Try Deck hints first // Try Deck hints first
if (selectHintAbility()) if (selectHintAbility())
{
findingAbility = false;//ok to start looking again.
return 1; return 1;
}
GameObserver * go = GameObserver::GetInstance(); GameObserver * go = GameObserver::GetInstance();
if(go->mLayers->stackLayer()->lastActionController == this) if(go->mLayers->stackLayer()->lastActionController == this)
{ {
//this is here for 2 reasons, MTG rules state that priority is passed with each action. //this is here for 2 reasons, MTG rules state that priority is passed with each action.
//without this ai is able to chain cast {t}:damage:1 target(creature) from everything it can all at once. //without this ai is able to chain cast {t}:damage:1 target(creature) from everything it can all at once.
//this not only is illegal but cause ai to waste abilities ei:all damage:1 on a single 1/1 creature. //this not only is illegal but cause ai to waste abilities ei:all damage:1 on a single 1/1 creature.
findingAbility = false;
return 1; return 1;
} }
RankingContainer ranking; RankingContainer ranking;
list<int>::iterator it; list<int>::iterator it;
GameObserver * g = GameObserver::GetInstance(); GameObserver * g = GameObserver::GetInstance();
@@ -1262,7 +1246,7 @@ int AIPlayerBaka::selectAbility()
for (int j = 0; j < game->inPlay->nb_cards; j++) for (int j = 0; j < game->inPlay->nb_cards; j++)
{ {
MTGCardInstance * card = game->inPlay->cards[j]; MTGCardInstance * card = game->inPlay->cards[j];
if(a->getCost() && !a->isReactingToClick(card, totalPotentialMana))//for preformence reason only look for specific mana if the payment couldnt be made with potential. if(a->getCost() && !a->isReactingToClick(card, totalPotentialMana))//for performance reason only look for specific mana if the payment couldnt be made with potential.
{ {
abilityPayment = vector<MTGAbility*>(); abilityPayment = vector<MTGAbility*>();
abilityPayment = canPayMana(card,a->getCost()); abilityPayment = canPayMana(card,a->getCost());
@@ -1323,7 +1307,6 @@ int AIPlayerBaka::selectAbility()
} }
} }
findingAbility = false;//ok to start looking again.
abilityPayment.clear(); abilityPayment.clear();
return 1; return 1;
} }
+92 -179
View File
@@ -64,8 +64,6 @@ int GenericActivatedAbility::testDestroy()
GenericActivatedAbility * GenericActivatedAbility::clone() const GenericActivatedAbility * GenericActivatedAbility::clone() const
{ {
GenericActivatedAbility * a = NEW GenericActivatedAbility(*this); GenericActivatedAbility * a = NEW GenericActivatedAbility(*this);
//a->getCost() = NEW ManaCost();
//a->getCost()->copy(cost);
a->ability = ability->clone(); a->ability = ability->clone();
return a; return a;
} }
@@ -184,20 +182,11 @@ AADepleter::AADepleter(int _id, MTGCardInstance * card, Targetable * _target,str
} }
int AADepleter::resolve() int AADepleter::resolve()
{ {
Player * player = getPlayerFromTarget(getTarget());
Targetable * _target = getTarget(); if (player)
Player * player;
if (_target)
{ {
WParsedInt numCards(nbcardsStr, NULL, source); WParsedInt numCards(nbcardsStr, NULL, source);
if (_target->typeAsTarget() == TARGET_CARD)
{
player = ((MTGCardInstance *) _target)->controller();
}
else
{
player = (Player *) _target;
}
MTGLibrary * library = player->game->library; MTGLibrary * library = player->game->library;
for (int i = 0; i < numCards.getValue(); i++) for (int i = 0; i < numCards.getValue(); i++)
{ {
@@ -378,7 +367,7 @@ AACounter * AACounter::clone() const
return NEW AACounter(*this); return NEW AACounter(*this);
} }
//sheild a card from a certain type of counter. //shield a card from a certain type of counter.
ACounterShroud::ACounterShroud(int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter) : ACounterShroud::ACounterShroud(int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter) :
MTGAbility(id, source),counter(counter),re(NULL) MTGAbility(id, source),counter(counter),re(NULL)
{ {
@@ -426,9 +415,8 @@ MTGAbility(id, source, target),scounter(scounter)
int ACounterTracker::addToGame() int ACounterTracker::addToGame()
{ {
MTGCardInstance * _target = (MTGCardInstance*)target; MTGCardInstance * _target = (MTGCardInstance*)target;
Counter * counter = NULL;
AbilityFactory af; AbilityFactory af;
counter = af.parseCounter(scounter, _target, NULL); //(Spell*)source); Counter * counter = af.parseCounter(scounter, _target, NULL); //(Spell*)source);
if (!counter) if (!counter)
{ {
return 0; return 0;
@@ -453,9 +441,8 @@ int ACounterTracker::addToGame()
int ACounterTracker::destroy() int ACounterTracker::destroy()
{ {
MTGCardInstance * _target = (MTGCardInstance*)target; MTGCardInstance * _target = (MTGCardInstance*)target;
Counter * counter = NULL;
AbilityFactory af; AbilityFactory af;
counter = af.parseCounter(scounter, _target, NULL); //(Spell*)source); Counter * counter = af.parseCounter(scounter, _target, NULL); //(Spell*)source);
if (!counter) if (!counter)
{ {
return 0; return 0;
@@ -500,10 +487,11 @@ AARemoveAllCounter::AARemoveAllCounter(int id, MTGCardInstance * source, MTGCard
menu = ""; menu = "";
} }
int AARemoveAllCounter::resolve() int AARemoveAllCounter::resolve()
{ {
if (target) if (!target)
{ return 0;
MTGCardInstance * _target = (MTGCardInstance *) target; MTGCardInstance * _target = (MTGCardInstance *) target;
if (all ) if (all )
{ {
@@ -521,18 +509,15 @@ AARemoveAllCounter::AARemoveAllCounter(int id, MTGCardInstance * source, MTGCard
nb = targetCounter->nb; nb = targetCounter->nb;
} }
if (nb > 0)
{
for (int i = 0; i < nb; i++) for (int i = 0; i < nb; i++)
{ {
while (_target->next) while (_target->next)
_target = _target->next; _target = _target->next;
_target->counters->removeCounter(name.c_str(), power, toughness); _target->counters->removeCounter(name.c_str(), power, toughness);
} }
}
return nb; return nb;
}
return 0;
} }
const char* AARemoveAllCounter::getMenuText() const char* AARemoveAllCounter::getMenuText()
@@ -562,8 +547,7 @@ const char* AARemoveAllCounter::getMenuText()
menu.append(buffer); menu.append(buffer);
} }
sprintf(menuText, "%s", menu.c_str()); return menu.c_str();
return menuText;
} }
AARemoveAllCounter * AARemoveAllCounter::clone() const AARemoveAllCounter * AARemoveAllCounter::clone() const
@@ -579,35 +563,34 @@ ActivatedAbility(id, source, cost, 0)
int AAProliferate::resolve() int AAProliferate::resolve()
{ {
if (target) if (!target)
{ return 0;
vector<MTGAbility*>pcounters = vector<MTGAbility*>();
vector<MTGAbility*>pcounters;
if(target->typeAsTarget() == TARGET_PLAYER && ((Player*)target)->poisonCount && target != source->controller()) if(target->typeAsTarget() == TARGET_PLAYER && ((Player*)target)->poisonCount && target != source->controller())
{ {
MTGAbility * a = NEW AAAlterPoison(game->mLayers->actionLayer()->getMaxId(), source,(Player*)target,1,NULL); MTGAbility * a = NEW AAAlterPoison(game->mLayers->actionLayer()->getMaxId(), source, target, 1, NULL);
a->target = (Player*)target;
a->oneShot = true; a->oneShot = true;
pcounters.push_back(a); pcounters.push_back(a);
} }
else if (target->typeAsTarget() == TARGET_CARD && ((MTGCardInstance*)target)->counters) else if (target->typeAsTarget() == TARGET_CARD && ((MTGCardInstance*)target)->counters)
{ {
for(unsigned int i = 0; i < ((MTGCardInstance*)target)->counters->counters.size();i++) Counters * counters = ((MTGCardInstance*)target)->counters;
for(size_t i = 0; i < counters->counters.size(); ++i)
{ {
MTGAbility * a = NEW AACounter(game->mLayers->actionLayer()->getMaxId(), source, (MTGCardInstance*)target,"", ((MTGCardInstance*)target)->counters->counters[i]->name.c_str(), ((MTGCardInstance*)target)->counters->counters[i]->power, ((MTGCardInstance*)target)->counters->counters[i]->toughness, 1,0); Counter * counter = counters->counters[i];
a->target = (MTGCardInstance*)target; MTGAbility * a = NEW AACounter(game->mLayers->actionLayer()->getMaxId(), source, (MTGCardInstance*)target,"", counter->name.c_str(), counter->power, counter->toughness, 1,0);
a->oneShot = true; a->oneShot = true;
pcounters.push_back(a); pcounters.push_back(a);
} }
} }
if(pcounters.size()) if(pcounters.size())
{ {
MTGAbility * a = NEW MenuAbility(/*int(game->mLayers->actionLayer()->getMaxId())*/this->GetId(),(MTGCardInstance*)target, source,false,pcounters); MTGAbility * a = NEW MenuAbility(this->GetId(), target, source,false,pcounters);
a->target = (MTGCardInstance*)target;
a->resolve(); a->resolve();
} }
return 1; return 1;
}
return 0;
} }
const char* AAProliferate::getMenuText() const char* AAProliferate::getMenuText()
@@ -664,7 +647,7 @@ int AAFizzler::resolve()
//the next section helps Ai correctly recieve its targets for this effect //the next section helps Ai correctly recieve its targets for this effect
if(!target && source->target) if(!target && source->target)
{ {
//ai is casting a spell from it's hand to fizzle. //ai is casting a spell from its hand to fizzle.
target = stack->getActionElementFromCard(source->target); target = stack->getActionElementFromCard(source->target);
} }
else if(target->typeAsTarget() == TARGET_CARD) else if(target->typeAsTarget() == TARGET_CARD)
@@ -820,19 +803,11 @@ AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCo
int AADrawer::resolve() int AADrawer::resolve()
{ {
Targetable * _target = getTarget(); Player * player = getPlayerFromTarget(getTarget());
Player * player;
if (_target) if (player)
{ {
WParsedInt numCards(nbcardsStr, NULL, source); WParsedInt numCards(nbcardsStr, NULL, source);
if (_target->typeAsTarget() == TARGET_CARD)
{
player = ((MTGCardInstance *) _target)->controller();
}
else
{
player = (Player *) _target;
}
game->mLayers->stackLayer()->addDraw(player, numCards.getValue()); game->mLayers->stackLayer()->addDraw(player, numCards.getValue());
game->mLayers->stackLayer()->resolve(); game->mLayers->stackLayer()->resolve();
GameObserver *g = GameObserver::GetInstance(); GameObserver *g = GameObserver::GetInstance();
@@ -1435,8 +1410,8 @@ const char * AADynamic::getMenuText()
default: default:
break; break;
} }
sprintf(menuText, "%s", menu.c_str());
return menuText; return menu.c_str();
} }
AADynamic * AADynamic::clone() const AADynamic * AADynamic::clone() const
@@ -1504,18 +1479,10 @@ AASetHand::AASetHand(int _id, MTGCardInstance * _source, Targetable * _target, i
int AASetHand::resolve() int AASetHand::resolve()
{ {
Damageable * _target = (Damageable *) getTarget(); Damageable * _target = (Damageable *) getTarget();
if (!_target) Player * p = getPlayerFromDamageable(_target);
return 0;
Player * p = NULL; if (!p)
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) return 0;
{
p = ((MTGCardInstance *) _target)->controller();
}
else
{
p = (Player*)_target;
}
p->handsize = hand; p->handsize = hand;
@@ -1542,18 +1509,10 @@ AALifeSet::AALifeSet(int _id, MTGCardInstance * _source, Targetable * _target, W
int AALifeSet::resolve() int AALifeSet::resolve()
{ {
Damageable * _target = (Damageable *) getTarget(); Damageable * _target = (Damageable *) getTarget();
if (!_target) Player * p = getPlayerFromDamageable(_target);
return 0;
Player * p = NULL; if (!p)
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) return 0;
{
p = ((MTGCardInstance *) _target)->controller();
}
else
{
p = (Player*)_target;
}
int lifeDiff = life->getValue() - p->life ; int lifeDiff = life->getValue() - p->life ;
p->gainOrLoseLife(lifeDiff); p->gainOrLoseLife(lifeDiff);
@@ -1595,25 +1554,19 @@ AACloner::AACloner(int _id, MTGCardInstance * _source, MTGCardInstance * _target
} }
int AACloner::resolve() int AACloner::resolve()
{ {
MTGCardInstance * _target = (MTGCardInstance *) target; MTGCardInstance * _target = (MTGCardInstance *) target;
if (_target) if (!_target)
{ return 0;
MTGCardInstance * myClone = NULL;
MTGCard* clone = (_target->isToken ? _target: MTGCollection()->getCardByName(_target->name)); MTGCard* clone = (_target->isToken ? _target: MTGCollection()->getCardByName(_target->name));
if (who != 1)
{ Player * targetPlayer = who == 1 ? source->controller()->opponent() : source->controller();
myClone = NEW MTGCardInstance(clone, source->controller()->game);
} MTGCardInstance * myClone = NEW MTGCardInstance(clone, targetPlayer->game);
if (who == 1) targetPlayer->game->temp->addCard(myClone);
{
myClone = NEW MTGCardInstance(clone, source->controller()->opponent()->game);
}
if (who != 1)
source->controller()->game->temp->addCard(myClone);
else
source->controller()->opponent()->game->temp->addCard(myClone);
Spell * spell = NEW Spell(myClone); Spell * spell = NEW Spell(myClone);
spell->resolve(); spell->resolve();
spell->source->isToken = 1; spell->source->isToken = 1;
@@ -1635,8 +1588,7 @@ AACloner::AACloner(int _id, MTGCardInstance * _source, MTGCardInstance * _target
} }
delete spell; delete spell;
return 1; return 1;
}
return 0;
} }
const char * AACloner::getMenuText() const char * AACloner::getMenuText()
@@ -1672,17 +1624,10 @@ ACastRestriction::ACastRestriction(int _id, MTGCardInstance * card, Targetable *
int ACastRestriction::addToGame() int ACastRestriction::addToGame()
{ {
Targetable * _target = getTarget(); Targetable * _target = getTarget();
targetPlayer = getPlayerFromTarget(_target);
if (!targetPlayer)
return 0;
if (_target)
{
if (_target->typeAsTarget() == TARGET_CARD)
{
targetPlayer = ((MTGCardInstance *) _target)->controller();
}
else
{
targetPlayer = (Player *) _target;
}
if (modifyExisting) if (modifyExisting)
{ {
//For now the only modifying rule is the one for lands, so this is hardcoded here. //For now the only modifying rule is the one for lands, so this is hardcoded here.
@@ -1700,8 +1645,7 @@ int ACastRestriction::addToGame()
} }
AbilityTP::addToGame(); AbilityTP::addToGame();
} return 1;
return 0;
} }
int ACastRestriction::destroy() int ACastRestriction::destroy()
@@ -1939,19 +1883,9 @@ AARandomDiscarder::AARandomDiscarder(int _id, MTGCardInstance * card, Targetable
int AARandomDiscarder::resolve() int AARandomDiscarder::resolve()
{ {
Targetable * _target = getTarget(); Targetable * _target = getTarget();
Player * player; Player * player = getPlayerFromTarget(_target);
if (_target) if (player)
{ {
if (_target->typeAsTarget() == TARGET_CARD)
{
player = ((MTGCardInstance *) _target)->controller();
}
else
{
player = (Player *) _target;
}
WParsedInt numCards(nbcardsStr, NULL, source); WParsedInt numCards(nbcardsStr, NULL, source);
for (int i = 0; i < numCards.intValue; i++) for (int i = 0; i < numCards.intValue; i++)
{ {
@@ -1980,18 +1914,9 @@ AAShuffle::AAShuffle(int _id, MTGCardInstance * card, Targetable * _target, Mana
int AAShuffle::resolve() int AAShuffle::resolve()
{ {
Targetable * _target = getTarget(); Player * player = getPlayerFromTarget(getTarget());
Player * player; if (player)
if (_target)
{ {
if (_target->typeAsTarget() == TARGET_CARD)
{
player = ((MTGCardInstance *) _target)->controller();
}
else
{
player = (Player *) _target;
}
MTGLibrary * library = player->game->library; MTGLibrary * library = player->game->library;
library->shuffle(); library->shuffle();
} }
@@ -2027,18 +1952,9 @@ AARemoveMana::AARemoveMana(int _id, MTGCardInstance * card, Targetable * _target
int AARemoveMana::resolve() int AARemoveMana::resolve()
{ {
Targetable * _target = getTarget(); Player * player = getPlayerFromTarget(getTarget());
Player * player; if (player)
if (_target)
{ {
if (_target->typeAsTarget() == TARGET_CARD)
{
player = ((MTGCardInstance *) _target)->controller();
}
else
{
player = (Player *) _target;
}
ManaPool * manaPool = player->getManaPool(); ManaPool * manaPool = player->getManaPool();
if (mRemoveAll) if (mRemoveAll)
{ {
@@ -2171,15 +2087,13 @@ AAWinGame::AAWinGame(int _id, MTGCardInstance * card, Targetable * _target, Mana
int AAWinGame::resolve() int AAWinGame::resolve()
{ {
Damageable * _target = (Damageable *) getTarget(); Player * p = getPlayerFromDamageable((Damageable *) getTarget());
if (_target) if (!p)
{ return 0;
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
{ bool canwin = true;
_target = ((MTGCardInstance *) _target)->controller();
} MTGGameZone * z = p->opponent()->game->inPlay;
int cantlosers = 0;
MTGGameZone * z = ((Player *) _target)->opponent()->game->inPlay;
int nbcards = z->nb_cards; int nbcards = z->nb_cards;
for (int i = 0; i < nbcards; i++) for (int i = 0; i < nbcards; i++)
@@ -2187,24 +2101,31 @@ int AAWinGame::resolve()
MTGCardInstance * c = z->cards[i]; MTGCardInstance * c = z->cards[i];
if (c->has(Constants::CANTLOSE)) if (c->has(Constants::CANTLOSE))
{ {
cantlosers++; canwin = false;
break;
} }
} }
MTGGameZone * k = ((Player *) _target)->game->inPlay;
if (canwin)
{
MTGGameZone * k = p->game->inPlay;
int onbcards = k->nb_cards; int onbcards = k->nb_cards;
for (int m = 0; m < onbcards; ++m) for (int m = 0; m < onbcards; ++m)
{ {
MTGCardInstance * e = k->cards[m]; MTGCardInstance * e = k->cards[m];
if (e->has(Constants::CANTWIN)) if (e->has(Constants::CANTWIN))
{ {
cantlosers++; canwin = false;
break;
} }
} }
if (cantlosers < 1) }
if (canwin)
{ {
game->gameOver = ((Player *) _target)->opponent(); game->gameOver = p->opponent();
}
} }
return 1; return 1;
} }
@@ -2499,8 +2420,7 @@ int MultiAbility::Add(MTGAbility * ability)
int MultiAbility::resolve() int MultiAbility::resolve()
{ {
Targetable * Phaseactiontarget = NULL; Targetable * Phaseactiontarget = NULL;
vector<int>::size_type sz = abilities.size(); for (size_t i = 0; i < abilities.size(); ++i)
for (unsigned int i = 0; i < sz; i++)
{ {
if (abilities[i] == NULL) if (abilities[i] == NULL)
continue; continue;
@@ -2521,7 +2441,7 @@ int MultiAbility::resolve()
int MultiAbility::addToGame() int MultiAbility::addToGame()
{ {
for (unsigned int i = 0; i < abilities.size(); i++) for (size_t i = 0; i < abilities.size(); ++i)
{ {
if (abilities[i] == NULL) if (abilities[i] == NULL)
continue; continue;
@@ -2557,8 +2477,7 @@ MultiAbility * MultiAbility::clone() const
{ {
MultiAbility * a = NEW MultiAbility(*this); MultiAbility * a = NEW MultiAbility(*this);
a->abilities.clear(); a->abilities.clear();
vector<int>::size_type sz = abilities.size(); for (size_t i = 0; i < abilities.size(); ++i)
for (size_t i = 0; i < sz; i++)
{ {
a->abilities.push_back(abilities[i]->clone()); a->abilities.push_back(abilities[i]->clone());
} }
@@ -2567,9 +2486,7 @@ MultiAbility * MultiAbility::clone() const
MultiAbility::~MultiAbility() MultiAbility::~MultiAbility()
{ {
for (size_t i = 0; i < abilities.size(); ++i)
vector<int>::size_type sz = abilities.size();
for (size_t i = 0; i < sz; i++)
{ {
SAFE_DELETE(abilities[i]); SAFE_DELETE(abilities[i]);
} }
@@ -2617,9 +2534,8 @@ int GenericTargetAbility::isReactingToClick(MTGCardInstance * card, ManaCost * m
limitPerTurn = 0; limitPerTurn = 0;
if(limit.size()) if(limit.size())
{ {
WParsedInt * value = NEW WParsedInt(limit.c_str(),NULL,source); WParsedInt value(limit.c_str(),NULL,source);
limitPerTurn = value->getValue(); limitPerTurn = value.getValue();
delete value;
} }
if (limitPerTurn && counters >= limitPerTurn) if (limitPerTurn && counters >= limitPerTurn)
return 0; return 0;
@@ -2677,7 +2593,6 @@ int AAlterCost::addToGame()
if(!_target->getIncreasedManaCost()->getConvertedCost()) if(!_target->getIncreasedManaCost()->getConvertedCost())
{ {
ManaCost * increased = NEW ManaCost(); ManaCost * increased = NEW ManaCost();
increased->init();
_target->getIncreasedManaCost()->copy(increased); _target->getIncreasedManaCost()->copy(increased);
delete increased; delete increased;
@@ -2689,7 +2604,6 @@ int AAlterCost::addToGame()
if(!_target->getReducedManaCost()->getConvertedCost()) if(!_target->getReducedManaCost()->getConvertedCost())
{ {
ManaCost * reduced = NEW ManaCost(); ManaCost * reduced = NEW ManaCost();
reduced->init();
_target->getReducedManaCost()->copy(reduced); _target->getReducedManaCost()->copy(reduced);
delete reduced; delete reduced;
} }
@@ -3253,20 +3167,19 @@ int ALoseAbilities::destroy()
MTGAbility * a = storedAbilities[i]; MTGAbility * a = storedAbilities[i];
//OneShot abilities are not supposed to stay in the game for long. //OneShot abilities are not supposed to stay in the game for long.
// If we copied one, something wrong probably happened // If we copied one, something wrong probably happened
ALoseAbilities * la = dynamic_cast<ALoseAbilities*> (a); if (a->oneShot)
if (a->oneShot||la)
{
if(la)
{
DebugTrace("Dangerous chance of infinate loop avoided!");
continue;
}
else
{ {
DebugTrace("ALLABILITIES: Ability should not be one shot"); DebugTrace("ALLABILITIES: Ability should not be one shot");
continue; continue;
} }
//Avoid inifinite loop of removing/putting back abilities
if (ALoseAbilities * la = dynamic_cast<ALoseAbilities*> (a))
{
DebugTrace("ALLABILITIES: loseability won't be put in the loseability list");
continue;
} }
a->addToGame(); a->addToGame();
} }
storedAbilities.clear(); storedAbilities.clear();
+42 -73
View File
@@ -2536,12 +2536,7 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
MTGCardInstance * target = card->target; MTGCardInstance * target = card->target;
if (!target) if (!target)
target = card; target = card;
//card->getManaCost()->copy(card->model->data->getManaCost());
//zeth:i added this originally for no reason really, however
//i didn't realize ai runs this function about a million times during a match.
//it litterally distroys any altering cost effects.
//if for some reason i added this becuase of some bug...we need to think of a more clever way
//to do this.
string magicText; string magicText;
if (dest) if (dest)
{ {
@@ -3290,25 +3285,13 @@ void AbilityFactory::addAbilities(int _id, Spell * spell)
game->addObserver(NEW AFlankerAbility(_id, card)); game->addObserver(NEW AFlankerAbility(_id, card));
} }
if (card->basicAbilities[(int)Constants::FORESTHOME]) const int HomeAbilities[] = {(int)Constants::FORESTHOME, (int)Constants::ISLANDHOME, (int)Constants::MOUNTAINHOME, (int)Constants::SWAMPHOME, (int)Constants::PLAINSHOME};
const char * HomeLands[] = {"forest", "island", "mountain", "swamp", "plains"};
for (int i = 0; i < sizeof(HomeAbilities)/sizeof(HomeAbilities[0]); ++i)
{ {
game->addObserver(NEW AStrongLandLinkCreature(_id, card, "forest")); if (card->basicAbilities[HomeAbilities[i]])
} game->addObserver(NEW AStrongLandLinkCreature(_id, card, HomeLands[i]));
if (card->basicAbilities[(int)Constants::ISLANDHOME])
{
game->addObserver(NEW AStrongLandLinkCreature(_id, card, "island"));
}
if (card->basicAbilities[(int)Constants::MOUNTAINHOME])
{
game->addObserver(NEW AStrongLandLinkCreature(_id, card, "mountain"));
}
if (card->basicAbilities[(int)Constants::SWAMPHOME])
{
game->addObserver(NEW AStrongLandLinkCreature(_id, card, "swamp"));
}
if (card->basicAbilities[(int)Constants::PLAINSHOME])
{
game->addObserver(NEW AStrongLandLinkCreature(_id, card, "plains"));
} }
if(card->previous && card->previous->previous && card->previous->previous->suspended) if(card->previous && card->previous->previous && card->previous->previous->suspended)
@@ -3340,39 +3323,19 @@ void AbilityFactory::addAbilities(int _id, Spell * spell)
MTGAbility * AbilityFactory::getManaReduxAbility(string s, int id, Spell *spell, MTGCardInstance *card, MTGCardInstance *target) MTGAbility * AbilityFactory::getManaReduxAbility(string s, int id, Spell *spell, MTGCardInstance *card, MTGCardInstance *target)
{ {
int color = -1; int color = -1;
string manaCost; string manaCost = s.substr(s.find(",") + 1);
size_t endIndex = manaCost.find(")");
if (s.find(Constants::kManaColorless) != string::npos) const string ColorStrings[] = { Constants::kManaColorless, Constants::kManaGreen, Constants::kManaBlue, Constants::kManaRed, Constants::kManaBlack, Constants::kManaWhite };
for (int i = 0; i < sizeof(ColorStrings)/sizeof(ColorStrings[0]); ++i)
{ {
manaCost = s.substr(s.find(",") + 1, endIndex); if (s.find(ColorStrings[i]) != string::npos)
color = Constants::MTG_COLOR_ARTIFACT;
}
else if (s.find(Constants::kManaGreen) != string::npos)
{ {
manaCost = s.substr(s.find(",") + 1, endIndex); color = i;
color = Constants::MTG_COLOR_GREEN; break;
} }
else if (s.find(Constants::kManaBlue) != string::npos)
{
manaCost = s.substr(s.find(",") + 1, endIndex);
color = Constants::MTG_COLOR_BLUE;
} }
else if (s.find(Constants::kManaRed) != string::npos) if (color == -1)
{
manaCost = s.substr(s.find(",") + 1, endIndex);
color = Constants::MTG_COLOR_RED;
}
else if (s.find(Constants::kManaBlack) != string::npos)
{
manaCost = s.substr(s.find(",") + 1, endIndex);
color = Constants::MTG_COLOR_BLACK;
}
else if (s.find(Constants::kManaWhite) != string::npos)
{
manaCost = s.substr(s.find(",") + 1, endIndex);
color = Constants::MTG_COLOR_WHITE;
}
else
{ {
DebugTrace("An error has happened in creating a Mana Redux Ability! " << s ); DebugTrace("An error has happened in creating a Mana Redux Ability! " << s );
return NULL; return NULL;
@@ -3518,6 +3481,30 @@ ostream& MTGAbility::toString(ostream& out) const
<< " ; mCost : " << mCost << " ; target : " << target << " ; aType : " << aType << " ; source : " << source; << " ; mCost : " << mCost << " ; target : " << target << " ; aType : " << aType << " ; source : " << source;
} }
Player * MTGAbility::getPlayerFromTarget(Targetable * target)
{
if (!target)
return NULL;
if (target->typeAsTarget() == TARGET_CARD)
return ((MTGCardInstance *) target)->controller();
return (Player *) target;
}
Player * MTGAbility::getPlayerFromDamageable(Damageable * target)
{
if (!target)
return NULL;
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
return ((MTGCardInstance *) target)->controller();
return (Player *) target;
}
//
NestedAbility::NestedAbility(MTGAbility * _ability) NestedAbility::NestedAbility(MTGAbility * _ability)
{ {
ability = _ability; ability = _ability;
@@ -4518,26 +4505,8 @@ const char * AManaProducer::getMenuText()
menutext.append(","); menutext.append(",");
sprintf(buffer, "%i ", value); sprintf(buffer, "%i ", value);
menutext.append(buffer); menutext.append(buffer);
switch (i) if (i >= Constants::MTG_COLOR_GREEN && i <= Constants::MTG_COLOR_WHITE)
{ menutext.append(_(Constants::MTGColorStrings[i]));
case Constants::MTG_COLOR_RED:
menutext.append(_("red"));
break;
case Constants::MTG_COLOR_BLUE:
menutext.append(_("blue"));
break;
case Constants::MTG_COLOR_GREEN:
menutext.append(_("green"));
break;
case Constants::MTG_COLOR_WHITE:
menutext.append(_("white"));
break;
case Constants::MTG_COLOR_BLACK:
menutext.append(_("black"));
break;
default:
break;
}
alreadyHasOne = 1; alreadyHasOne = 1;
} }
} }