-Fix for issue 583 (fireball crash)

-- converted an array into a vector to avoid weird edge cases
-- fixed bugs with array "backupTargets"
This commit is contained in:
wagic.the.homebrew
2011-05-26 12:27:44 +00:00
parent ffda1d0548
commit a84eb8dc22
10 changed files with 96 additions and 72 deletions
+6 -4
View File
@@ -217,10 +217,12 @@ Interruptible(id), tc(tc), cost(_cost), payResult(payResult)
mHeight = 40;
type = ACTION_SPELL;
from = _source->getCurrentZone();
for(int i = 0;i < MAX_TARGETS;i++)
_source->backupTargets.clear();
if (tc)
{
if(tc && tc->targets[i] != NULL)
_source->backupTargets[i] = tc->targets[i];
for(size_t i = 0;i < tc->targets.size();i++)
_source->backupTargets.push_back(tc->targets[i]);
}
// fill information on how the card came into this zone. Right now the quickest way is to do it here, based on how the mana was paid...
@@ -360,7 +362,7 @@ int Spell::getNbTargets()
{
if (!tc)
return 0;
return tc->cursor;
return (int) (tc->targets.size());
}
void Spell::Render()
+1 -3
View File
@@ -1762,9 +1762,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
found = s.find("wingame");
if (found != string::npos)
{
Damageable * d = NULL;
if (spell)
d = spell->getNextDamageableTarget();
Damageable * d = spell ? spell->getNextDamageableTarget() : NULL;
MTGAbility * a = NEW AAWinGame(id, card, d, NULL, who);
a->oneShot = 1;
return a;
+2 -2
View File
@@ -486,7 +486,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
size_t start = attribute.find("share!");
size_t end = attribute.rfind("!");
string CDtype = attribute.substr(start + 6,end - start);
if( card && card->isSpell() && card->backupTargets[0]->typeAsTarget() == TARGET_STACKACTION)
if( card && card->isSpell() && card->backupTargets.size() && card->backupTargets[0]->typeAsTarget() == TARGET_STACKACTION)
{
//spells always store their targets in :targets[]
//however they are all erased as the spell resolves
@@ -785,7 +785,7 @@ int TargetChooser::ForceTargetListReady()
int TargetChooser::targetsReadyCheck()
{
if (cursor <= 0)
if (!targets.size())
{
return TARGET_NOK;
}
+9 -15
View File
@@ -8,24 +8,19 @@
TargetsList::TargetsList()
{
cursor = 0;
}
TargetsList::TargetsList(Targetable * _targets[], int nbtargets)
{
for (int i = 0; i < nbtargets; i++)
{
targets[i] = _targets[i];
}
cursor = nbtargets;
targets.push_back(_targets[i]);
}
int TargetsList::addTarget(Targetable * target)
{
if (!alreadyHasTarget(target))
{
targets[cursor] = target;
cursor++;
targets.push_back(target);
return 1;
}
return 0;
@@ -34,7 +29,7 @@ int TargetsList::addTarget(Targetable * target)
int TargetsList::alreadyHasTarget(Targetable * target)
{
for (int i = 0; i < cursor; i++)
for (size_t i = 0; i < targets.size(); i++)
{
if (targets[i] == target) return 1;
}
@@ -43,13 +38,12 @@ int TargetsList::alreadyHasTarget(Targetable * target)
int TargetsList::removeTarget(Targetable * target)
{
for (int i = 0; i < cursor; i++)
for (size_t i = 0; i < targets.size(); i++)
{
if (targets[i] == target)
{
targets[i] = targets[cursor];
targets[cursor] = NULL;
cursor--;
targets.erase(targets.begin() + i);
return 1;
}
}
@@ -74,7 +68,7 @@ Targetable * TargetsList::getNextTarget(Targetable * previous, int type)
{
int found = 0;
if (!previous) found = 1;
for (int i = 0; i < cursor; i++)
for (size_t i = 0; i < targets.size(); i++)
{
if (found && (type == -1 || targets[i]->typeAsTarget() == type))
{
@@ -99,7 +93,7 @@ Interruptible * TargetsList::getNextInterruptible(Interruptible * previous, int
{
int found = 0;
if (!previous) found = 1;
for (int i = 0; i < cursor; i++)
for (size_t i = 0; i < targets.size(); i++)
{
if (found && targets[i]->typeAsTarget() == TARGET_STACKACTION)
{
@@ -131,7 +125,7 @@ Damageable * TargetsList::getNextDamageableTarget(Damageable * previous)
{
int found = 0;
if (!previous) found = 1;
for (int i = 0; i < cursor; i++)
for (size_t i = 0; i < targets.size(); i++)
{
if (targets[i]->typeAsTarget() == TARGET_PLAYER)