From b6d749679826ca5fc19a43cd9139636c37019f5c Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Thu, 23 Sep 2010 13:06:49 +0000 Subject: [PATCH] Erwan - some code cleanup in Damage.cpp (the test suite passes) --- projects/mtg/include/AllAbilities.h | 2 + projects/mtg/src/Damage.cpp | 141 ++++++++++++---------------- projects/mtg/src/DamagerDamaged.cpp | 12 --- 3 files changed, 64 insertions(+), 91 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index de1c13fe1..045ee9b65 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -112,6 +112,8 @@ public: //Triggers // + +// Triggers When a card gets added to a zone (@movedTo) class TrCardAddedToZone:public TriggeredAbility{ public: TargetChooser * toTc; diff --git a/projects/mtg/src/Damage.cpp b/projects/mtg/src/Damage.cpp index c75aefde0..808f1b4f1 100644 --- a/projects/mtg/src/Damage.cpp +++ b/projects/mtg/src/Damage.cpp @@ -49,51 +49,49 @@ int Damage::resolve(){ //reserved for culmulitive absorb ability coding -//prevent next damage----------------------------- + //prevent next damage----------------------------- if((target)->preventable >= 1) { - int preventing =(target)->preventable; - for(int k = preventing; k > 0;k--){ -//the following keeps preventable from ADDING toughness/life if damage was less then preventable amount. - for (int i = damage; i >= 1; i--){ + int preventing =(target)->preventable; + for(int k = preventing; k > 0;k--){ + //the following keeps preventable from ADDING toughness/life if damage was less then preventable amount. + for (int i = damage; i >= 1; i--){ (target)->preventable -= 1; - damage -= 1; + damage -= 1; break;//does the redux of damage 1 time, breaks the loop to deincrement preventing and start the loop over. - } + } } } -//set prevent next damage back to 0 if it is equal to less then 0 + + //set prevent next damage back to 0 if it is equal to less then 0 if((target)->preventable < 0){ (target)->preventable = 0; } -//------------------------------------------------- + + //------------------------------------------------- if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE){ MTGCardInstance * _target = (MTGCardInstance *)target; if ((_target)->protectedAgainst(source)) damage = 0; - //rulings = 10/4/2004 The damage prevention ability works even if it has no counters, as long as some effect keeps its toughness above zero. - //these creature are essentially immune to damage. however 0/-1 effects applied through lords or counters can kill them. - if ((_target)->has(Constants::PHANTOM)) { - damage = 0; - (_target)->counters->removeCounter(1,1); - } - if ((_target)->has(Constants::ABSORB)) { - damage -= 1; - } - if ((_target)->has(Constants::WILTING)) { - for (int i = 0; i < damage; i++){ - for (int i = damage; i > 0; i--){ - (_target)->counters->addCounter(-1,-1); - } - damage = 0; - } - } - if ((_target)->has(Constants::VIGOR)){ - for (int i = 0; i < damage; i++){ - for (int i = damage; i > 0; i--){ - (_target)->counters->addCounter(1,1); - } - damage = 0; - } - } + //rulings = 10/4/2004 The damage prevention ability works even if it has no counters, as long as some effect keeps its toughness above zero. + //these creature are essentially immune to damage. however 0/-1 effects applied through lords or counters can kill them. + if ((_target)->has(Constants::PHANTOM)) { + damage = 0; + (_target)->counters->removeCounter(1,1); + } + if ((_target)->has(Constants::ABSORB)) { + damage -= 1; + } + if ((_target)->has(Constants::WILTING)) { + for (int j = damage; j > 0; j--){ + (_target)->counters->addCounter(-1,-1); + } + damage = 0; + } + if ((_target)->has(Constants::VIGOR)){ + for (int j = damage; j > 0; j--){ + (_target)->counters->addCounter(1,1); + } + damage = 0; + } if (!damage){ state = RESOLVED_NOK; delete (e); @@ -103,56 +101,41 @@ int Damage::resolve(){ } int a = damage; - // Damage for WITHER on creatures. This should probably go in replacement effects - if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE && source->has(Constants::WITHER)){ + + if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE && + (source->has(Constants::WITHER) || source->has(Constants::INFECT))){ + // Damage for WITHER or poison on creatures. This should probably go in replacement effects MTGCardInstance * _target = (MTGCardInstance *)target; for (int i = 0; i < damage; i++){ _target->counters->addCounter(-1, -1); } - }else{//infect damage--------------------------------------------- - while(target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE && source->has(Constants::INFECT)){ - MTGCardInstance * _target = (MTGCardInstance *)target; - for (int i = 0; i < damage; i++){ - _target->counters->addCounter(-1, -1); - }return a; - }while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::INFECT)){ - MTGCardInstance * _target = (MTGCardInstance *)target; - for (int i = 0; i < damage; i++){ - _target->poisonCount += 1;//this will be changed to poison counters. - }return a; - }//-------------------------------------------------- - //poison AND damage---------------------------------- - while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::POISONTOXIC)){ - MTGCardInstance * _target = (MTGCardInstance *)target; - for (int i = 0; i < damage; i++){ - a = target->dealDamage(1); - target->damageCount += 1; - } - _target->poisonCount += 1; - return a; - } - while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::POISONTWOTOXIC)){ - MTGCardInstance * _target = (MTGCardInstance *)target; - for (int i = 0; i < damage; i++){ - a = target->dealDamage(1); - target->damageCount += 1; - } - _target->poisonCount += 2; - return a; - } - while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::POISONTHREETOXIC)){ - MTGCardInstance * _target = (MTGCardInstance *)target; - for (int i = 0; i < damage; i++){ - a = target->dealDamage(1); - target->damageCount += 1; - } - _target->poisonCount += 3; - return a; - }//---------------------------------------------------------- - //return the left over amount after effects have been applied to them. + + } else if (target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::INFECT)) { + // Poison on player + Player * _target = (Player *)target; + _target->poisonCount += damage;//this will be changed to poison counters. + + } else if (target->type_as_damageable == DAMAGEABLE_PLAYER && + ( source->has(Constants::POISONTOXIC) || source->has(Constants::POISONTWOTOXIC) || source->has(Constants::POISONTHREETOXIC) )) { + //Damage + 1, 2, or 3 poison counters on player + Player * _target = (Player *)target; + a = target->dealDamage(damage); + target->damageCount += damage; + if (source->has(Constants::POISONTOXIC)) { + _target->poisonCount += 1; + }else if (source->has(Constants::POISONTWOTOXIC)) { + _target->poisonCount += 2; + } else { + _target->poisonCount += 3; + } + + } else { + // "Normal" case, + //return the left over amount after effects have been applied to them. a = target->dealDamage(damage); - target->damageCount += 1; + target->damageCount += 1; } + //Send (Damage/Replaced effect) event to listeners g->receiveEvent(e); return a; @@ -211,7 +194,7 @@ int DamageStack::resolve(){ } void DamageStack::Render(){ - int currenty = y; + float currenty = y; for (int i= 0; i < mCount; i++){ Damage * damage = (Damage*)mObjects[i]; if (damage->state == NOT_RESOLVED){ diff --git a/projects/mtg/src/DamagerDamaged.cpp b/projects/mtg/src/DamagerDamaged.cpp index d92a021d8..3a768dde3 100644 --- a/projects/mtg/src/DamagerDamaged.cpp +++ b/projects/mtg/src/DamagerDamaged.cpp @@ -69,21 +69,9 @@ void DamagerDamaged::Render(CombatStep mode) } char buf[6]; - // if (currentPlayer != damageSelecter){ - /* if (hasLethalDamage()){ - mFont->DrawString("X",x,y); - }*/ sprintf(buf, "%i", sumDamages()); mFont->DrawString(buf, actX - 14 * actZ + 5, actY - 14 * actZ); - /* - }else{ - mFont->SetColor(ARGB(255,0,0,255)); - sprintf(buf, "%i", damageToDeal); - mFont->DrawString(buf,x+5, y+5); - } - mFont->SetColor(ARGB(255,255,255,255)); - */ }