Replace defines in Damage.h with enums.

This commit is contained in:
Tobias Loose
2013-11-17 17:12:58 +01:00
parent 146872797b
commit 3ca2f1c1ed
12 changed files with 53 additions and 46 deletions

View File

@@ -873,8 +873,8 @@ public:
return 0; return 0;
if (!tc->canTarget(e->damage->target)) return 0; if (!tc->canTarget(e->damage->target)) return 0;
if (fromTc && !fromTc->canTarget(e->damage->source)) return 0; if (fromTc && !fromTc->canTarget(e->damage->source)) return 0;
if (type == 1 && e->damage->typeOfDamage != DAMAGE_COMBAT) return 0; if (type == 1 && e->damage->typeOfDamage != Damage::DAMAGE_COMBAT) return 0;
if (type == 2 && e->damage->typeOfDamage == DAMAGE_COMBAT) return 0; if (type == 2 && e->damage->typeOfDamage == Damage::DAMAGE_COMBAT) return 0;
e->damage->target->thatmuch = e->damage->damage; e->damage->target->thatmuch = e->damage->damage;
e->damage->source->thatmuch = e->damage->damage; e->damage->source->thatmuch = e->damage->damage;
this->source->thatmuch = e->damage->damage; this->source->thatmuch = e->damage->damage;
@@ -2577,7 +2577,7 @@ public:
} }
else else
{ {
if (d->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (d->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
a->source = (MTGCardInstance *) d; a->source = (MTGCardInstance *) d;
} }
@@ -2725,7 +2725,7 @@ public:
} }
else else
{ {
if (d->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (d->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
a->source = (MTGCardInstance *) d; a->source = (MTGCardInstance *) d;
} }
@@ -5549,7 +5549,7 @@ public:
{ {
WEventDamage * e = (WEventDamage *) event; WEventDamage * e = (WEventDamage *) event;
Damage * d = e->damage; Damage * d = e->damage;
if (combatonly && e->damage->typeOfDamage != DAMAGE_COMBAT) if (combatonly && e->damage->typeOfDamage != Damage::DAMAGE_COMBAT)
return 0; return 0;
MTGCardInstance * card = d->source; MTGCardInstance * card = d->source;
if (d->damage > 0 && card && (card == source || card == source->target)) if (d->damage > 0 && card && (card == source || card == source->target))

View File

@@ -11,17 +11,15 @@ class JGuiObject;
class MTGCardInstance; class MTGCardInstance;
class GameObserver; class GameObserver;
#define DAMAGEABLE_MTGCARDINSTANCE 0
#define DAMAGEABLE_PLAYER 1
#define DAMAGE_ALL_TYPES 0
#define DAMAGE_COMBAT 1
#define DAMAGE_OTHER 2
class Damageable:public Targetable class Damageable:public Targetable
{ {
protected: protected:
public: public:
enum DamageableType{
DAMAGEABLE_MTGCARDINSTANCE = 0,
DAMAGEABLE_PLAYER
};
int life; int life;
int handsize; int handsize;
int poisonCount; int poisonCount;
@@ -29,12 +27,14 @@ public:
int preventable; int preventable;
int thatmuch; int thatmuch;
int lifeLostThisTurn; int lifeLostThisTurn;
int type_as_damageable; DamageableType type_as_damageable;
Damageable(GameObserver* observer, int _life) Damageable(GameObserver* observer, int _life)
: Targetable(observer) : Targetable(observer), life(_life), handsize(0),
{life=_life;lifeLostThisTurn = 0;}; poisonCount(0), damageCount(0), preventable(0), thatmuch(0),
int getLife(){return life;}; lifeLostThisTurn(0), type_as_damageable(DAMAGEABLE_MTGCARDINSTANCE)
virtual int dealDamage(int damage){life-=damage;return life;}; {}
int getLife(){return life;}
virtual int dealDamage(int damage){life-=damage;return life;}
virtual int afterDamage(){return 0;} virtual int afterDamage(){return 0;}
virtual int poisoned(){return 0;} virtual int poisoned(){return 0;}
virtual int prevented(){return 0;} virtual int prevented(){return 0;}
@@ -47,17 +47,23 @@ public:
class Damage: public Interruptible class Damage: public Interruptible
{ {
protected:
void init(MTGCardInstance * source, Damageable * target, int damage, int typeOfDamage);
public: public:
enum DamageType{
DAMAGE_ALL_TYPES = 0,
DAMAGE_COMBAT,
DAMAGE_OTHER
};
Damageable * target; Damageable * target;
int typeOfDamage; DamageType typeOfDamage;
int damage; int damage;
void Render(); void Render();
Damage(GameObserver* observer, MTGCardInstance* source, Damageable * target); Damage(GameObserver* observer, MTGCardInstance* source, Damageable * target);
Damage(GameObserver* observer, MTGCardInstance* source, Damageable * target, int damage, int typeOfDamage = DAMAGE_OTHER); Damage(GameObserver* observer, MTGCardInstance* source, Damageable * target, int damage, DamageType typeOfDamage = DAMAGE_OTHER);
int resolve(); int resolve();
virtual ostream& toString(ostream& out) const; virtual ostream& toString(ostream& out) const;
protected:
void init(MTGCardInstance * source, Damageable * target, int damage, DamageType typeOfDamage);
}; };
class DamageStack : public GuiLayer, public Interruptible class DamageStack : public GuiLayer, public Interruptible

View File

@@ -29,9 +29,10 @@ protected:
TargetChooser * tcTarget; TargetChooser * tcTarget;
int damage; int damage;
bool oneShot; bool oneShot;
int typeOfDamage; Damage::DamageType typeOfDamage;
public: public:
REDamagePrevention(MTGAbility * _source, TargetChooser *_tcSource = NULL, TargetChooser *_tcTarget = NULL, int _damage = -1, bool _oneShot = true, int typeOfDamage = DAMAGE_ALL_TYPES); REDamagePrevention(MTGAbility * _source, TargetChooser *_tcSource = NULL, TargetChooser *_tcTarget = NULL,
int _damage = -1, bool _oneShot = true, Damage::DamageType typeOfDamage = Damage::DAMAGE_ALL_TYPES);
WEvent * replace(WEvent *e); WEvent * replace(WEvent *e);
~REDamagePrevention(); ~REDamagePrevention();
}; };

View File

@@ -47,7 +47,7 @@ void AIStats::updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, f
{ {
stat->value += static_cast<int>(multiplier * STATS_PLAYER_MULTIPLIER * damage->damage); stat->value += static_cast<int>(multiplier * STATS_PLAYER_MULTIPLIER * damage->damage);
} }
else if (damage->target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) else if (damage->target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
MTGCardInstance * target = (MTGCardInstance *) damage->target; MTGCardInstance * target = (MTGCardInstance *) damage->target;
if (target->controller() == player && !target->isInPlay(player->getObserver())) if (target->controller() == player && !target->isInPlay(player->getObserver()))

View File

@@ -161,7 +161,7 @@ void StackAbility::Render()
if (target) if (target)
{ {
quad = target->getIcon(); quad = target->getIcon();
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
alt2 = ((MTGCardInstance *) target)->name; alt2 = ((MTGCardInstance *) target)->name;
} }
@@ -400,7 +400,7 @@ void Spell::Render()
if (target) if (target)
{ {
quad = target->getIcon(); quad = target->getIcon();
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
alt2 = ((MTGCardInstance *) target)->name; alt2 = ((MTGCardInstance *) target)->name;
} }

View File

@@ -2351,7 +2351,7 @@ int AALifer::resolve()
return 0; return 0;
WParsedInt life(life_s, NULL, source); WParsedInt life(life_s, NULL, source);
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (_target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
_target = ((MTGCardInstance *) _target)->controller(); _target = ((MTGCardInstance *) _target)->controller();
} }
@@ -4380,7 +4380,7 @@ int AAExchangeLife::resolve()
int oldlife = player->getLife(); int oldlife = player->getLife();
int targetOldLife = _target->getLife(); int targetOldLife = _target->getLife();
int modifier = oldlife > targetOldLife? oldlife - targetOldLife:targetOldLife - oldlife; int modifier = oldlife > targetOldLife? oldlife - targetOldLife:targetOldLife - oldlife;
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (_target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
int increaser = 0; int increaser = 0;
MTGCardInstance * card = ((MTGCardInstance*)_target); MTGCardInstance * card = ((MTGCardInstance*)_target);
@@ -4597,15 +4597,15 @@ int APreventDamageTypes::addToGame()
fromTc->targetter = NULL; fromTc->targetter = NULL;
if (type != 1 && type != 2) if (type != 1 && type != 2)
{//not adding this creates a memory leak. {//not adding this creates a memory leak.
re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, DAMAGE_COMBAT); re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, Damage::DAMAGE_COMBAT);
} }
else if (type == 1) else if (type == 1)
{ {
re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, DAMAGE_ALL_TYPES); re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, Damage::DAMAGE_ALL_TYPES);
} }
else if (type == 2) else if (type == 2)
{ {
re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, DAMAGE_OTHER); re = NEW REDamagePrevention(this, fromTc, toTc, -1, false, Damage::DAMAGE_OTHER);
} }
game->replacementEffects->add(re); game->replacementEffects->add(re);
return MTGAbility::addToGame(); return MTGAbility::addToGame();

View File

@@ -14,13 +14,13 @@ Damage::Damage(GameObserver* observer, MTGCardInstance * source, Damageable * ta
init(source, target, source->getPower(), DAMAGE_OTHER); init(source, target, source->getPower(), DAMAGE_OTHER);
} }
Damage::Damage(GameObserver* observer, MTGCardInstance * source, Damageable * target, int damage, int _typeOfDamage) Damage::Damage(GameObserver* observer, MTGCardInstance * source, Damageable * target, int damage, DamageType _typeOfDamage)
: Interruptible(observer) : Interruptible(observer)
{ {
init(source, target, damage, _typeOfDamage); init(source, target, damage, _typeOfDamage);
} }
void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage, int _typeOfDamage) void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage, DamageType _typeOfDamage)
{ {
typeOfDamage = _typeOfDamage; typeOfDamage = _typeOfDamage;
target = _target; target = _target;
@@ -69,7 +69,7 @@ int Damage::resolve()
} }
//------------------------------------------------- //-------------------------------------------------
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
{ {
MTGCardInstance * _target = (MTGCardInstance *) target; MTGCardInstance * _target = (MTGCardInstance *) target;
if ((_target)->protectedAgainst(source)) if ((_target)->protectedAgainst(source))
@@ -122,7 +122,7 @@ int Damage::resolve()
int a = damage; int a = damage;
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE && (source->has(Constants::WITHER) || source->has( if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE && (source->has(Constants::WITHER) || source->has(
Constants::INFECT))) Constants::INFECT)))
{ {
// Damage for WITHER or poison on creatures. This should probably go in replacement effects // Damage for WITHER or poison on creatures. This should probably go in replacement effects
@@ -134,7 +134,7 @@ int Damage::resolve()
if(_target->toughness <= 0 && _target->has(Constants::INDESTRUCTIBLE)) if(_target->toughness <= 0 && _target->has(Constants::INDESTRUCTIBLE))
_target->controller()->game->putInGraveyard(_target); _target->controller()->game->putInGraveyard(_target);
} }
else if (target->type_as_damageable == DAMAGEABLE_PLAYER && (source->has(Constants::INFECT)||source->has(Constants::POISONDAMAGER))) else if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER && (source->has(Constants::INFECT)||source->has(Constants::POISONDAMAGER)))
{ {
// Poison on player // Poison on player
Player * _target = (Player *) target; Player * _target = (Player *) target;
@@ -151,7 +151,7 @@ int Damage::resolve()
} }
} }
} }
else if (target->type_as_damageable == DAMAGEABLE_PLAYER && (source->has(Constants::POISONTOXIC) || else if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER && (source->has(Constants::POISONTOXIC) ||
source->has(Constants::POISONTWOTOXIC) || source->has(Constants::POISONTHREETOXIC))) source->has(Constants::POISONTWOTOXIC) || source->has(Constants::POISONTHREETOXIC)))
{ {
//Damage + 1, 2, or 3 poison counters on player //Damage + 1, 2, or 3 poison counters on player
@@ -190,9 +190,9 @@ int Damage::resolve()
//return the left over amount after effects have been applied to them. //return the left over amount after effects have been applied to them.
a = target->dealDamage(damage); a = target->dealDamage(damage);
target->damageCount += damage;//the amount must be the actual damage so i changed this from 1 to damage, this fixes pdcount and odcount target->damageCount += damage;//the amount must be the actual damage so i changed this from 1 to damage, this fixes pdcount and odcount
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
((MTGCardInstance*)target)->wasDealtDamage = true; ((MTGCardInstance*)target)->wasDealtDamage = true;
if (target->type_as_damageable == DAMAGEABLE_PLAYER) if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER)
{ {
if(target == source->controller()) if(target == source->controller())
{ {
@@ -248,7 +248,7 @@ void Damage::Render()
} }
else else
{ {
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
mFont->DrawString(_(((MTGCardInstance *) target)->getName()).c_str(), x + 120, y); mFont->DrawString(_(((MTGCardInstance *) target)->getName()).c_str(), x + 120, y);
} }

View File

@@ -43,7 +43,7 @@ void DamagerDamaged::addDamage(int damage, DamagerDamaged* source)
return; return;
} }
if (0 < damage) if (0 < damage)
damages.push_back(Damage(card->getObserver(), source->card, card, damage, DAMAGE_COMBAT)); damages.push_back(Damage(card->getObserver(), source->card, card, damage, Damage::DAMAGE_COMBAT));
return; return;
} }

View File

@@ -526,7 +526,7 @@ int GuiCombat::resolve() // Returns the number of damage objects dealt this turn
} }
if (dmg > 0 && ((!attacker->isBlocked()) || attacker->has(Constants::TRAMPLE))) if (dmg > 0 && ((!attacker->isBlocked()) || attacker->has(Constants::TRAMPLE)))
stack->Add(NEW Damage(observer, (*it)->card, (Damageable*)attacker->isAttacking?(Damageable*)attacker->isAttacking:observer->opponent(), dmg, DAMAGE_COMBAT)); stack->Add(NEW Damage(observer, (*it)->card, (Damageable*)attacker->isAttacking?(Damageable*)attacker->isAttacking:observer->opponent(), dmg, Damage::DAMAGE_COMBAT));
for (vector<Damage>::iterator d = (*it)->damages.begin(); d != (*it)->damages.end(); ++d) for (vector<Damage>::iterator d = (*it)->damages.begin(); d != (*it)->damages.end(); ++d)
stack->Add(NEW Damage(*d)); stack->Add(NEW Damage(*d));

View File

@@ -4477,7 +4477,7 @@ Player * MTGAbility::getPlayerFromDamageable(Damageable * target)
if (!target) if (!target)
return NULL; return NULL;
if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
return ((MTGCardInstance *) target)->controller(); return ((MTGCardInstance *) target)->controller();
return (Player *) target; return (Player *) target;

View File

@@ -2700,7 +2700,7 @@ int MTGDeathtouchRule::receiveEvent(WEvent * event)
if (!card) if (!card)
return 0; return 0;
if (d->target->type_as_damageable != DAMAGEABLE_MTGCARDINSTANCE) if (d->target->type_as_damageable != Damageable::DAMAGEABLE_MTGCARDINSTANCE)
return 0; return 0;
MTGCardInstance * _target = (MTGCardInstance *) (d->target); MTGCardInstance * _target = (MTGCardInstance *) (d->target);

View File

@@ -6,7 +6,7 @@
#include "AllAbilities.h" #include "AllAbilities.h"
REDamagePrevention::REDamagePrevention(MTGAbility * source, TargetChooser *tcSource, TargetChooser *tcTarget, int damage, REDamagePrevention::REDamagePrevention(MTGAbility * source, TargetChooser *tcSource, TargetChooser *tcTarget, int damage,
bool oneShot, int typeOfDamage) : bool oneShot, Damage::DamageType typeOfDamage) :
source(source), tcSource(tcSource), tcTarget(tcTarget), damage(damage), oneShot(oneShot), typeOfDamage(typeOfDamage) source(source), tcSource(tcSource), tcTarget(tcTarget), damage(damage), oneShot(oneShot), typeOfDamage(typeOfDamage)
{ {
} }
@@ -18,7 +18,7 @@ WEvent * REDamagePrevention::replace(WEvent *event)
WEventDamage * e = dynamic_cast<WEventDamage*> (event); WEventDamage * e = dynamic_cast<WEventDamage*> (event);
if (!e) return event; if (!e) return event;
Damage *d = e->damage; Damage *d = e->damage;
if (d->typeOfDamage != typeOfDamage && typeOfDamage != DAMAGE_ALL_TYPES) return event; if (d->typeOfDamage != typeOfDamage && typeOfDamage != Damage::DAMAGE_ALL_TYPES) return event;
if ((!tcSource || tcSource->canTarget(d->source)) && (!tcTarget || tcTarget->canTarget(d->target))) if ((!tcSource || tcSource->canTarget(d->source)) && (!tcTarget || tcTarget->canTarget(d->target)))
{ {
if (damage == -1) if (damage == -1)