1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Cleaned some code.

This commit is contained in:
DjWarmonger 2011-11-13 09:29:22 +00:00
parent 364a207f71
commit 2e0ca6d162
3 changed files with 118 additions and 115 deletions

View File

@ -3164,12 +3164,12 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
switch(sc->id) switch(sc->id)
{ {
case 15: //magic arrow case Spells::MAGIC_ARROW:
{ {
//initialization of anims //initialization of anims
anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF"); anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF");
} }
case 16: //ice bolt case Spells::ICE_BOLT:
{ {
if(anims.size() == 0) //initialization of anims if(anims.size() == 0) //initialization of anims
{ {
@ -3218,23 +3218,26 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
break; //for 15 and 16 cases break; //for 15 and 16 cases
} }
case 17: //lightning bolt case Spells::LIGHTNING_BOLT:
case 57: //Titan's Thunder case Spells::TITANS_LIGHTNING_BOLT:
case 77: //thunderbolt case Spells::THUNDERBOLT:
displayEffect(1, sc->tile); displayEffect(1, sc->tile);
displayEffect(spell.mainEffectAnim, sc->tile); displayEffect(spell.mainEffectAnim, sc->tile);
break; break;
case 35: //dispel case Spells::DISPEL:
case 37: //cure case Spells::CURE:
case 38: //resurrection case Spells::RESURRECTION:
case 39: //animate dead case Spells::ANIMATE_DEAD:
case 78: //Dispell beneficial spells case Spells::DISPEL_HELPFUL_SPELLS:
for(std::set<ui32>::const_iterator it = sc->affectedCres.begin(); it != sc->affectedCres.end(); ++it) for(std::set<ui32>::const_iterator it = sc->affectedCres.begin(); it != sc->affectedCres.end(); ++it)
{ {
displayEffect(spell.mainEffectAnim, curInt->cb->battleGetStackByID(*it, false)->position); displayEffect(spell.mainEffectAnim, curInt->cb->battleGetStackByID(*it, false)->position);
} }
break; break;
case 66: case 67: case 68: case 69: //summon elemental case Spells::SUMMON_FIRE_ELEMENTAL:
case Spells::SUMMON_EARTH_ELEMENTAL:
case Spells::SUMMON_WATER_ELEMENTAL:
case Spells::SUMMON_AIR_ELEMENTAL:
addNewAnim(new CDummyAnim(this, 2)); addNewAnim(new CDummyAnim(this, 2));
break; break;
} //switch(sc->id) } //switch(sc->id)
@ -3263,32 +3266,32 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
{ {
switch(sc->id) switch(sc->id)
{ {
case 70: //Stone Gaze case Spells::STONE_GAZE:
customSpell = true; customSpell = true;
plural = true; plural = true;
textID = 558; textID = 558;
break; break;
case 71: //Poison case Spells::POISON:
customSpell = true; customSpell = true;
plural = true; plural = true;
textID = 561; textID = 561;
break; break;
case 72: //Bind case Spells::BIND:
customSpell = true; customSpell = true;
text = CGI->generaltexth->allTexts[560]; text = CGI->generaltexth->allTexts[560];
boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin(), false)->getCreature()->namePl ); boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin(), false)->getCreature()->namePl );
break; //Roots and vines bind the %s to the ground! break; //Roots and vines bind the %s to the ground!
case 73: //Disease case Spells::DISEASE:
customSpell = true; customSpell = true;
plural = true; plural = true;
textID = 553; textID = 553;
break; break;
case 74: //Paralyze case Spells::PARALYZE:
customSpell = true; customSpell = true;
plural = true; plural = true;
textID = 563; textID = 563;
break; break;
case 75: // Aging case Spells::AGE:
{ {
customSpell = true; customSpell = true;
if (curInt->cb->battleGetStackByID(*sc->affectedCres.begin())->count > 1) if (curInt->cb->battleGetStackByID(*sc->affectedCres.begin())->count > 1)
@ -3307,7 +3310,7 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bl->totalValue()/2)); boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bl->totalValue()/2));
} }
break; break;
case 77: //Thunderbolt case Spells::THUNDERBOLT:
text = CGI->generaltexth->allTexts[367]; text = CGI->generaltexth->allTexts[367];
boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin())->type->namePl); boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin())->type->namePl);
console->addText(text); console->addText(text);
@ -3317,12 +3320,12 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
customSpell = true; customSpell = true;
text = ""; //yeah, it's a terrible mess text = ""; //yeah, it's a terrible mess
break; break;
case 78: //Dispell helpful spells case Spells::DISPEL_HELPFUL_SPELLS:
text = CGI->generaltexth->allTexts[555]; text = CGI->generaltexth->allTexts[555];
boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin())->type->namePl); boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin())->type->namePl);
customSpell = true; customSpell = true;
break; break;
case 79: // Death Stare case Spells::DEATH_STARE:
customSpell = true; customSpell = true;
if (sc->dmgToDisplay) if (sc->dmgToDisplay)
{ {

View File

@ -1962,8 +1962,8 @@ TSpell BattleInfo::getRandomBeneficialSpell(const CStack * subject) const
continue; continue;
switch (i) switch (i)
{ {
case 27: //shield case Spells::SHIELD:
case 29: //fire shield - not if all enemy units are shooters case Spells::FIRE_SHIELD: // not if all enemy units are shooters
{ {
bool walkerPresent = false; bool walkerPresent = false;
BOOST_FOREACH (CStack * stack, stacks) BOOST_FOREACH (CStack * stack, stacks)
@ -1978,7 +1978,7 @@ TSpell BattleInfo::getRandomBeneficialSpell(const CStack * subject) const
continue; continue;
} }
break; break;
case 28: //air shield - only against active shooters case Spells::AIR_SHIELD: //only against active shooters
{ {
bool shooterPresent = false; bool shooterPresent = false;
BOOST_FOREACH (CStack * stack, stacks) BOOST_FOREACH (CStack * stack, stacks)
@ -1993,32 +1993,32 @@ TSpell BattleInfo::getRandomBeneficialSpell(const CStack * subject) const
continue; continue;
break; break;
} }
case 34: //anti-magic case Spells::ANTI_MAGIC:
case 36: //magic mirror case Spells::MAGIC_MIRROR:
{ {
if (!heroes[whatSide(theOtherPlayer(subject->owner))]) //only if there is enemy hero if (!heroes[whatSide(theOtherPlayer(subject->owner))]) //only if there is enemy hero
continue; continue;
} }
break; break;
case 37: //Cure - only damaged units - what about affected by curse? case Spells::CURE: //only damaged units - what about affected by curse?
{ {
if (subject->firstHPleft >= subject->MaxHealth()) if (subject->firstHPleft >= subject->MaxHealth())
continue; continue;
} }
break; break;
case 43: //bloodlust case Spells::BLOODLUST:
{ {
if (subject->shots) //if can shoot - only if enemy uits are adjacent if (subject->shots) //if can shoot - only if enemy uits are adjacent
continue; continue;
} }
break; break;
case 44: //precision case Spells::PRECISION:
{ {
if (!(subject->hasBonusOfType(Bonus::SHOOTER) && subject->shots)) if (!(subject->hasBonusOfType(Bonus::SHOOTER) && subject->shots))
continue; continue;
} }
break; break;
case 55: //slayer - only if monsters are present case Spells::SLAYER://only if monsters are present
{ {
bool monsterPresent = false; bool monsterPresent = false;
BOOST_FOREACH (CStack * stack, stacks) BOOST_FOREACH (CStack * stack, stacks)
@ -2034,7 +2034,7 @@ TSpell BattleInfo::getRandomBeneficialSpell(const CStack * subject) const
continue; continue;
} }
break; break;
case 65: //clone - not allowed case Spells::CLONE: //not allowed
continue; continue;
break; break;
} }
@ -2108,30 +2108,30 @@ SpellCasting::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance
switch (spell->id) //TODO: more general logic for new spells? switch (spell->id) //TODO: more general logic for new spells?
{ {
case 25: //Destroy Undead case Spells::DESTROY_UNDEAD:
if (!subject->hasBonusOfType(Bonus::UNDEAD)) if (!subject->hasBonusOfType(Bonus::UNDEAD))
return SpellCasting::STACK_IMMUNE_TO_SPELL; return SpellCasting::STACK_IMMUNE_TO_SPELL;
break; break;
case 24: // Death Ripple case Spells::DEATH_RIPPLE:
if (subject->hasBonusOfType(Bonus::SIEGE_WEAPON)) if (subject->hasBonusOfType(Bonus::SIEGE_WEAPON))
return SpellCasting::STACK_IMMUNE_TO_SPELL; //don't break here - undeads and war machines are immune, non-living are not return SpellCasting::STACK_IMMUNE_TO_SPELL; //don't break here - undeads and war machines are immune, non-living are not
case 41: case Spells::BLESS:
case 42: //undeads are immune to bless & curse case Spells::CURSE: //undeads are immune to bless & curse
if (subject->hasBonusOfType(Bonus::UNDEAD)) if (subject->hasBonusOfType(Bonus::UNDEAD))
return SpellCasting::STACK_IMMUNE_TO_SPELL; return SpellCasting::STACK_IMMUNE_TO_SPELL;
break; break;
case 53: //haste case Spells::HASTE:
case 54: //slow case Spells::SLOW:
case 63: //teleport case Spells::TELEPORT:
case 65: //clone case Spells::CLONE:
if (subject->hasBonusOfType(Bonus::SIEGE_WEAPON)) if (subject->hasBonusOfType(Bonus::SIEGE_WEAPON))
return SpellCasting::STACK_IMMUNE_TO_SPELL; //war machines are mmune to some spells than involve movement return SpellCasting::STACK_IMMUNE_TO_SPELL; //war machines are mmune to some spells than involve movement
break; break;
case 61: //Forgetfulness case Spells::FORGETFULNESS:
if (!subject->hasBonusOfType(Bonus::SHOOTER)) if (!subject->hasBonusOfType(Bonus::SHOOTER))
return SpellCasting::STACK_IMMUNE_TO_SPELL; return SpellCasting::STACK_IMMUNE_TO_SPELL;
break; break;
case 78: //dispel helpful spells case Spells::DISPEL_HELPFUL_SPELLS:
{ {
TBonusListPtr spellBon = subject->getSpellBonuses(); TBonusListPtr spellBon = subject->getSpellBonuses();
bool hasPositiveSpell = false; bool hasPositiveSpell = false;

View File

@ -3551,30 +3551,30 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
continue; continue;
sc.dmgToDisplay += gs->curB->calculateSpellDmg(spell, caster, *it, spellLvl, usedSpellPower); sc.dmgToDisplay += gs->curB->calculateSpellDmg(spell, caster, *it, spellLvl, usedSpellPower);
} }
if (spellID == 79 || spellID == 81) // Death stare or Acid Breath if (spellID == Spells::DEATH_STARE || spellID == Spells::ACID_BREATH_DAMAGE)
{ {
sc.dmgToDisplay = usedSpellPower; sc.dmgToDisplay = usedSpellPower;
if (spellID == 79) if (spellID == Spells::DEATH_STARE)
amin(sc.dmgToDisplay, (*attackedCres.begin())->count); //stack is already reduced after attack amin(sc.dmgToDisplay, (*attackedCres.begin())->count); //stack is already reduced after attack
} }
StacksInjured si; StacksInjured si;
//applying effects //applying effects
switch(spellID) switch (spellID)
{ { //damage spells
case 15: //magic arrow case Spells::MAGIC_ARROW:
case 16: //ice bolt case Spells::ICE_BOLT:
case 17: //lightning bolt case Spells::LIGHTNING_BOLT:
case 18: //implosion case Spells::IMPLOSION:
case 20: //frost ring case Spells::FROST_RING:
case 21: //fireball case Spells::FIREBALL:
case 22: //inferno case Spells::INFERNO:
case 23: //meteor shower case Spells::METEOR_SHOWER:
case 24: //death ripple case Spells::DEATH_RIPPLE:
case 25: //destroy undead case Spells::DESTROY_UNDEAD:
case 26: //armageddon case Spells::ARMAGEDDON:
case 57: //Titan's Lightning bolt case Spells::TITANS_LIGHTNING_BOLT:
case 77: //Thunderbolt (thunderbirds) case Spells::THUNDERBOLT: //(thunderbirds)
{ {
int spellDamage = 0; int spellDamage = 0;
if (stack && mode != SpellCasting::MAGIC_MIRROR) if (stack && mode != SpellCasting::MAGIC_MIRROR)
@ -3613,44 +3613,44 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
} }
break; break;
} }
// permanent effects // permanent effects
case 27: //shield case Spells::SHIELD:
case 28: //air shield case Spells::AIR_SHIELD:
case 29: //fire shield case Spells::FIRE_SHIELD:
case 30: //protection from air case Spells::PROTECTION_FROM_AIR:
case 31: //protection from fire case Spells::PROTECTION_FROM_FIRE:
case 32: //protection from water case Spells::PROTECTION_FROM_WATER:
case 33: //protection from earth case Spells::PROTECTION_FROM_EARTH:
case 34: //anti-magic case Spells::ANTI_MAGIC:
case 36: //magic mirror case Spells::MAGIC_MIRROR:
case 41: //bless case Spells::BLESS:
case 42: //curse case Spells::CURSE:
case 43: //bloodlust case Spells::BLOODLUST:
case 44: //precision case Spells::PRECISION:
case 45: //weakness case Spells::WEAKNESS:
case 46: //stone skin case Spells::STONE_SKIN:
case 47: //disrupting ray case Spells::DISRUPTING_RAY:
case 48: //prayer case Spells::PRAYER:
case 49: //mirth case Spells::MIRTH:
case 50: //sorrow case Spells::SORROW:
case 51: //fortune case Spells::FORTUNE:
case 52: //misfortune case Spells::MISFORTUNE:
case 53: //haste case Spells::HASTE:
case 54: //slow case Spells::SLOW:
case 55: //slayer case Spells::SLAYER:
case 56: //frenzy case Spells::FRENZY:
case 58: //counterstrike case Spells::COUNTERSTRIKE:
case 59: //berserk case Spells::BERSERK:
case 60: //hypnotize case Spells::HYPNOTIZE:
case 61: //forgetfulness case Spells::FORGETFULNESS:
case 62: //blind case Spells::BLIND:
case 70: //Stone Gaze case Spells::STONE_GAZE:
case 71: //Poison case Spells::POISON:
case 72: //Bind case Spells::BIND:
case 73: //Disease case Spells::DISEASE:
case 74: //Paralyze case Spells::PARALYZE:
case 75: //Aging case Spells::AGE:
case 80: //Acid Breath defense reduction case Spells::ACID_BREATH_DEFENSE:
{ {
int stackSpellPower = 0; int stackSpellPower = 0;
if (stack && mode != SpellCasting::MAGIC_MIRROR) if (stack && mode != SpellCasting::MAGIC_MIRROR)
@ -3730,7 +3730,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
sendAndApply(&sse); sendAndApply(&sse);
break; break;
} }
case 63: //teleport case Spells::TELEPORT:
{ {
BattleStackMoved bsm; BattleStackMoved bsm;
bsm.distance = -1; bsm.distance = -1;
@ -3742,9 +3742,9 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
sendAndApply(&bsm); sendAndApply(&bsm);
break; break;
} }
case 37: //cure case Spells::CURE:
case 38: //resurrection case Spells::RESURRECTION:
case 39: //animate dead case Spells::ANIMATE_DEAD:
{ {
int hpGained = 0; int hpGained = 0;
if (stack) if (stack)
@ -3761,7 +3761,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it) for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it)
{ {
if(vstd::contains(sc.resisted, (*it)->ID) //this creature resisted the spell if(vstd::contains(sc.resisted, (*it)->ID) //this creature resisted the spell
|| (spellID == 39 && !(*it)->hasBonusOfType(Bonus::UNDEAD)) //we try to cast animate dead on living stack || (spellID == Spells::ANIMATE_DEAD && !(*it)->hasBonusOfType(Bonus::UNDEAD)) //we try to cast animate dead on living stack
) )
continue; continue;
StacksHealedOrResurrected::HealInfo hi; StacksHealedOrResurrected::HealInfo hi;
@ -3784,25 +3784,25 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
sendAndApply(&shr); sendAndApply(&shr);
break; break;
} }
case 66: case Spells::SUMMON_FIRE_ELEMENTAL:
case 67: case Spells::SUMMON_EARTH_ELEMENTAL:
case 68: case Spells::SUMMON_WATER_ELEMENTAL:
case 69: case Spells::SUMMON_AIR_ELEMENTAL:
{ //elemental summoning { //elemental summoning
int creID; int creID;
switch(spellID) switch(spellID)
{ {
case 66: case Spells::SUMMON_FIRE_ELEMENTAL:
creID = 114; //fire elemental creID = 114;
break; break;
case 67: case Spells::SUMMON_EARTH_ELEMENTAL:
creID = 113; //earth elemental creID = 113;
break; break;
case 68: case Spells::SUMMON_WATER_ELEMENTAL:
creID = 115; //water elemental creID = 115;
break; break;
case 69: case Spells::SUMMON_AIR_ELEMENTAL:
creID = 112; //air elemental creID = 112;
break; break;
} }
@ -3819,7 +3819,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
sendAndApply(&bsa); sendAndApply(&bsa);
} }
break; break;
case 64: //remove obstacle case Spells::REMOVE_OBSTACLE:
{ {
ObstaclesRemoved obr; ObstaclesRemoved obr;
for(int g=0; g<gs->curB->obstacles.size(); ++g) for(int g=0; g<gs->curB->obstacles.size(); ++g)
@ -3836,7 +3836,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
break; break;
} }
break; break;
case 79: //Death stare - handled in a bit different way case Spells::DEATH_STARE: //handled in a bit different way
{ {
for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it) for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it)
{ {
@ -3857,7 +3857,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
} }
} }
break; break;
case 81: //Acid breath damage - new effect, separate from acid breath defense reduction case Spells::ACID_BREATH_DAMAGE: //new effect, separate from acid breath defense reduction
{ {
for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it) //no immunities for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it) //no immunities
{ {