AlexVinS 9 年之前
父節點
當前提交
750c114648

+ 2 - 1
client/battle/CBattleInterface.h

@@ -116,7 +116,8 @@ class CBattleInterface : public CIntObject
 		MOVE_STACK, ATTACK, WALK_AND_ATTACK, ATTACK_AND_RETURN, SHOOT, //OPEN_GATE, //we can open castle gate during siege
 		NO_LOCATION, ANY_LOCATION, FRIENDLY_CREATURE_SPELL, HOSTILE_CREATURE_SPELL, RISING_SPELL, ANY_CREATURE, OBSTACLE, TELEPORT, SACRIFICE, RANDOM_GENIE_SPELL,
 		FREE_LOCATION, //used with Force Field and Fire Wall - all tiles affected by spell must be free
-		CATAPULT, HEAL, RISE_DEMONS
+		CATAPULT, HEAL, RISE_DEMONS,
+		AIMED_SPELL
 	};
 private:
 	SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes;

+ 7 - 0
lib/spells/CDefaultSpellMechanics.cpp

@@ -747,6 +747,13 @@ ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCast(const CBat
 	return ESpellCastProblem::OK;
 }
 
+ESpellCastProblem DefaultSpellMechanics::canBeCast(const SpellTargetingContext & ctx) const
+{
+	//no problems by default, this method is for spell-specific problems
+	//common problems handled by CSpell
+	return ESpellCastProblem::OK;
+}
+
 ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const
 {
 	//by default use general algorithm

+ 1 - 0
lib/spells/CDefaultSpellMechanics.h

@@ -41,6 +41,7 @@ public:
 	std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const override;
 
 	ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const override;
+	ESpellCastProblem::ESpellCastProblem canBeCast(const SpellTargetingContext & ctx) const override;
 
 	ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const override;
 

+ 11 - 0
lib/spells/CSpellHandler.cpp

@@ -305,6 +305,17 @@ void CSpell::getEffects(std::vector<Bonus> & lst, const int level) const
 	}
 }
 
+ESpellCastProblem::ESpellCastProblem CSpell::canBeCastAt(const CBattleInfoCallback * cb, const ISpellCaster * caster, ECastingMode::ECastingMode mode, BattleHex destination) const
+{
+
+	//todo: CSpell::canBeCastAt check common problems
+
+	SpellTargetingContext ctx(this, cb, mode, caster, , destination);
+
+	return mechanics->canBeCast(cb, caster, mode, destination);
+}
+
+
 ESpellCastProblem::ESpellCastProblem CSpell::isImmuneAt(const CBattleInfoCallback * cb, const ISpellCaster * caster, ECastingMode::ECastingMode mode, BattleHex destination) const
 {
 	// Get all stacks at destination hex. only alive if not rising spell

+ 3 - 0
lib/spells/CSpellHandler.h

@@ -270,6 +270,9 @@ public:
 	ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const;
 
 	///checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into account general problems such as not having spellbook or mana points etc.
+	ESpellCastProblem::ESpellCastProblem canBeCastAt(const CBattleInfoCallback * cb, const ISpellCaster * caster, ECastingMode::ECastingMode mode, BattleHex destination) const;
+
+	///checks for creature immunity *at given hex*.
 	ESpellCastProblem::ESpellCastProblem isImmuneAt(const CBattleInfoCallback * cb, const ISpellCaster * caster, ECastingMode::ECastingMode mode, BattleHex destination) const;
 
 	///checks for creature immunity / anything that prevent casting *at given target* - doesn't take into account general problems such as not having spellbook or mana points etc.

+ 2 - 0
lib/spells/ISpellMechanics.h

@@ -108,6 +108,8 @@ public:
 
 	virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const = 0;
 
+	virtual ESpellCastProblem::ESpellCastProblem canBeCast(const SpellTargetingContext & ctx) const = 0;
+
 	virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0;
 
 	virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;