Browse Source

[programming challenge] Added callback method battleEstimateSpellDamage.

Michał W. Urbańczyk 14 years ago
parent
commit
4bf1c40211
2 changed files with 10 additions and 0 deletions
  1. 7 0
      lib/IGameCallback.cpp
  2. 3 0
      lib/IGameCallback.h

+ 7 - 0
lib/IGameCallback.cpp

@@ -376,6 +376,13 @@ const CGHeroInstance * CBattleInfoCallback::battleGetFightingHero(ui8 side) cons
 	return gs->curB->heroes[side];
 }
 
+int CBattleInfoCallback::battleEstimateSpellDamage(const CGHeroInstance *caster, const CSpell * spell, const CStack *destination /*= NULL*/)
+{
+	if(!caster)
+		return 0;
+	return gs->curB->calculateSpellDmg(spell, caster, destination, caster->getSpellSchoolLevel(spell), caster->getPrimSkillLevel(2));
+}
+
 CGameState *const CPrivilagedInfoCallback::gameState ()
 { 
 	return gs;

+ 3 - 0
lib/IGameCallback.h

@@ -136,6 +136,9 @@ public:
 ///	 determines if given spell can be casted (and returns problem description)
 	SpellCasting::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell); 
 
+	///estimates how much damage a spell will inflict upon a destination stack. If it's NULL a base damage value will be returned. If spell is not a plain offensive spell, 0 will be returned. The function doesn't check, if hero can cast given spell.
+	int battleEstimateSpellDamage(const CGHeroInstance *caster, const CSpell * spell, const CStack *destination = NULL); 
+
 ///	 returns true if caller can flee from the battle
 	bool battleCanFlee();